Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

requirements.authoring.redaction_notice

Requirements index · View definition

evidence Valid

Requirement

A tool result containing text the harness redacted under cite requirements.authoring.redaction MUST include a note saying that [REDACTED:<kind>] replaces credential-shaped text and that the original is not available. A result with no redacted text MUST NOT include the note.

Rationale

The reviewed test adequately checks requirements.authoring.redaction_notice. The test is src/authoring/tools.rs#mod[tests]/fn[only_results_with_redacted_text_carry_the_redaction_note].

Obligations

  1. A tool result that contains redacted text MUST carry a note saying [REDACTED:<kind>] replaces credential-shaped text and the original is not available.
  2. A result with no redacted text MUST NOT carry the note.

Positive cases (note present)

  • A habeas file/item read of fn[client], whose source contains a GitHub token. The test asserts the result contains [REDACTED: and that note == REDACTION_NOTE.
  • A ripgrep search that matches the redacted file. The test asserts note == REDACTION_NOTE.
  • A habeas requirements read and a habeas definition read, where the declaration text contains the token. The test asserts the token is absent, [REDACTED: is present, and the note is present.

Negative cases (note absent)

  • A read of fn[plain] in the same file. The test asserts there is no note.
  • A read of a file that literally contains [REDACTED:kind] in its original source and so was not redacted. The test asserts the marker text is present and there is no note.
  • A requirement whose text literally contains the marker. The test asserts there is no note.

The two literal-marker cases are boundary cases for the “MUST NOT include” clause. A naive substring check would wrongly add the note there.

Note wording REDACTION_NOTE reads “[REDACTED:] replaces credential-shaped text in this result; the original text is not available.” That matches the required content. The test compares against the constant rather than asserting the wording independently. This is the only weakness I found. I do not treat it as a gap, because the constant is the single definition of the note and its text satisfies the requirement.

Other tools ast_grep also returns source text, but every tool goes through dispatch_paged and with_redaction_note. That path decides on the result content through needs_redaction_note. It has no per-tool branch that tests would need to cover separately.

I found no gaps and no acknowledgments apply.

Inputs

Implementation

Input 5: outline src/authoring/tools.rs fn[with_redaction_note]
/// Adds the redaction note to a result that contains redacted text, and only
/// to such a result. A line showing the marker is redacted unless it appears
/// verbatim in its file's original source, where the marker is literal text.
// {impl}`requirements.authoring.redaction_notice`
// {impl}`requirements.authoring.tool_descriptions.special_cases`
fn with_redaction_note(sources: &AssessmentSources, mut delivery: ToolDelivery) -> ToolDelivery {
    if needs_redaction_note(sources, &delivery.result)
        && let Some(object) = delivery.result.as_object_mut()
    {
        object.insert("note".to_owned(), json!(REDACTION_NOTE));
    }
    delivery
}
Input 6: outline src/authoring/tools.rs fn[needs_redaction_note]
/// Whether a result contains text the harness redacted.
// {impl}`requirements.authoring.redaction_notice`
pub(crate) fn needs_redaction_note(sources: &AssessmentSources, result: &Value) -> bool {
    if !result.to_string().contains("[REDACTED:") {
        return false;
    }
    let mut redacted = false;
    // Requirement and definition text carries no file; its lines come from
    // the book's raw declarations.
    let declarations = std::cell::OnceCell::new();
    marked_lines(result, None, &mut |file, line| {
        let literal = match file {
            Some(file) => {
                let parsed = sources.outlines.parse(&sources.root, file);
                parsed
                    .as_ref()
                    .as_ref()
                    .is_ok_and(|parsed| parsed.source.lines().any(|source| source == line))
            }
            None => declarations
                .get_or_init(|| {
                    crate::evidence::load_definitions(&sources.root).unwrap_or_default()
                })
                .values()
                .any(|declaration| declaration.raw_lines.iter().any(|raw| raw == line)),
        };
        redacted |= !literal;
    });
    redacted
}

Tests

Input 3: outline src/authoring/tools.rs mod[tests]/fn[only_results_with_redacted_text_carry_the_redaction_note]
    // {test}`requirements.authoring.redaction_notice`
    // {test}`requirements.authoring.tool_descriptions.special_cases`
    #[test]
    fn only_results_with_redacted_text_carry_the_redaction_note() {
        let root = project();
        let token = crate::redaction::tests::github_token();
        fs::write(
            root.path().join("src/lib.rs"),
            format!("fn client() -> &'static str {{\n    \"{token}\"\n}}\n\nfn plain() {{}}\n"),
        )
        .unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let mut pages = ResultPages::default();
        let mut read = |arguments: Value| {
            dispatch_paged(&sources, &mut pages, "habeas", &arguments)
                .unwrap()
                .result
        };
        let redacted = read(json!({"file": "src/lib.rs", "item": "fn[client]"}));
        assert!(redacted.to_string().contains("[REDACTED:"), "{redacted}");
        assert_eq!(redacted["note"], REDACTION_NOTE);
        let plain = read(json!({"file": "src/lib.rs", "item": "fn[plain]"}));
        assert!(plain.get("note").is_none(), "{plain}");
        let search = dispatch_paged(
            &sources,
            &mut pages,
            "ripgrep",
            &json!({"pattern": "client", "path": "src/lib.rs"}),
        )
        .unwrap()
        .result;
        assert_eq!(search["note"], REDACTION_NOTE, "{search}");
        // Source that itself contains the marker text was not redacted.
        fs::write(
            root.path().join("src/notes.rs"),
            "// Secrets show as [REDACTED:kind] in tool output.\nfn notes() {}\n",
        )
        .unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let literal = dispatch_paged(
            &sources,
            &mut ResultPages::default(),
            "habeas",
            &json!({"file": "src/notes.rs", "item": "fn[notes]"}),
        )
        .unwrap()
        .result;
        assert!(literal.to_string().contains("[REDACTED:kind]"), "{literal}");
        assert!(literal.get("note").is_none(), "{literal}");
        // So is requirement text that contains it, which names no file.
        fs::write(
            root.path().join("md/requirements.md"),
            ":::{req} ready\nSecrets MUST read [REDACTED:kind].\n:::\n",
        )
        .unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let requirement = dispatch_paged(
            &sources,
            &mut ResultPages::default(),
            "habeas",
            &json!({"requirements": "requirements.ready"}),
        )
        .unwrap()
        .result;
        assert!(
            requirement.to_string().contains("[REDACTED:kind]"),
            "{requirement}"
        );
        assert!(requirement.get("note").is_none(), "{requirement}");
        fs::write(
            root.path().join("md/requirements.md"),
            format!(":::{{req}} ready\nThe credential {token} MUST be private.\n:::\n"),
        )
        .unwrap();
        fs::write(
            root.path().join("md/terms.md"),
            format!(":::{{definition}} secret\n:phrase: secret\nA credential {token}.\n:::\n"),
        )
        .unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        for args in [
            json!({"requirements":"requirements.ready"}),
            json!({"definition":"terms.secret"}),
        ] {
            let result = dispatch(&sources, "habeas", &args).unwrap().result;
            assert!(!result.to_string().contains(&token));
            assert!(result.to_string().contains("[REDACTED:"));
            assert_eq!(result["note"], REDACTION_NOTE);
        }
    }

Referenced definitions

Input 2: requirements selection requirements.authoring.redaction
:::{req} redaction
Every source text the harness supplies to a model, including mandatory inputs,
`habeas` reads, and `ripgrep` results, and every source text Habeas displays in
the book or `habeas info`, MUST be redacted:

1. In a workspace `habeas.toml` or user configuration file, the value of every
   explicit credential field defined by {cite}`requirements.authoring.credentials`
   MUST be replaced. Such a file that is not valid TOML MUST be replaced whole,
   with `configuration` as the kind, because its fields cannot be located.
2. In every source, each match of a built-in rule of the `secretshape` crate MUST
   be replaced. The replaced region MUST be extended through each adjacent region
   that the crate's entropy heuristic flags and that only whitespace separates
   from the region, repeating until no flagged region is adjacent. The heuristic
   MUST NOT cause redaction on its own.

A replacement MUST read `[REDACTED:<kind>]`, where `<kind>` is the credential
field or the rule's name, and MUST keep every line break within the replaced
text, so line numbers are unchanged. Outlines MUST be built from the original
source, and the structural hash MUST hash each text piece that overlaps a
redacted region in its redacted form, so evidence never depends on a credential's
value and redaction never changes or breaks a file's outline. The `secretshape` version MUST be pinned exactly; upgrading
it MAY change redaction and hashes and MUST be treated as a deliberate change.
:::

Other sources

Input 1: requirements selection requirements.authoring.redaction_notice
:::{req} redaction_notice
A tool result containing text the harness redacted under
{cite}`requirements.authoring.redaction` MUST include a note saying that
`[REDACTED:<kind>]` replaces credential-shaped text and that the original is not
available. A result with no redacted text MUST NOT include the note.
:::
Input 4: outline src/authoring/tools.rs const[REDACTION_NOTE]
/// What a result containing redacted text tells the model, since tool
/// descriptions do not explain redaction.
pub(crate) const REDACTION_NOTE: &str = "[REDACTED:<kind>] replaces credential-shaped text in this result; the original text is not available.";
Input 7: outline src/authoring/tools.rs fn[dispatch_paged]
// {impl}`requirements.authoring.file_discovery`
// {impl}`requirements.authoring.structural_search`
// {impl}`requirements.authoring.outline_tool`
// {impl}`requirements.authoring.reference_index`
// {impl}`requirements.authoring.github_reads`
pub(crate) fn dispatch_paged(
    sources: &AssessmentSources,
    pages: &mut ResultPages,
    name: &str,
    arguments: &Value,
) -> io::Result<ToolDelivery> {
    let arguments = arguments
        .as_object()
        .ok_or_else(|| io::Error::other("tool arguments must be an object"))?;
    let mut deliver = |listing: io::Result<Listing>| pages.deliver(sources, listing?);
    match name {
        "habeas" => read(sources, arguments).and_then(|read| match read {
            Ok(delivery) => Ok(delivery),
            Err(listing) => deliver(Ok(listing)),
        }),
        "list_files" => {
            deliver(list_files(sources, arguments).and_then(|listing| {
                with_not_listed(sources, arguments, NotListed::Children, listing)
            }))
        }
        "outline" => deliver(outline(sources, arguments)),
        "ripgrep" => deliver(search(sources, arguments).and_then(|listing| {
            let pattern = regex::Regex::new(string(arguments, "pattern")?).ok();
            with_not_listed(sources, arguments, NotListed::Text(pattern), listing)
        })),
        "ast_grep" => deliver(structural(sources, arguments).and_then(|listing| {
            let rule = arguments
                .get("language")
                .and_then(Value::as_str)
                .zip(arguments.get("rule").and_then(Value::as_object))
                .and_then(|(language, rule)| StructuralRule::compile(language, rule).ok());
            with_not_listed(sources, arguments, NotListed::Rule(rule), listing)
        })),
        "references" => deliver(references(sources, arguments)),
        "next_page" => check_keys(arguments, &["token"])
            .and_then(|()| pages.next_page(string(arguments, "token")?)),
        "finish_search" => pages.finish_search(&Value::Object(arguments.clone())),
        // GitHub reads are not evidence inputs.
        "github" => crate::github::tool(&sources.github, &Value::Object(arguments.clone()))
            .map(|result| ToolDelivery {
                result,
                inputs: Vec::new(),
            })
            .map_err(io::Error::other),
        _ => Err(io::Error::other(format!("unknown read tool {name:?}"))),
    }
    .map(|delivery| with_redaction_note(sources, delivery))
    .map_err(super::access::recoverable_os_denial)
    .map_err(super::access::recoverable_outside_request)
}