Skip to main content

redact

Function redact 

Source
pub fn redact(body: ReasoningBody) -> (ReasoningBody, Vec<String>)
Expand description

Remove every secret shape from every string of a body; the shapes that fired.

Every string field is first stripped of control characters and then passed through the crate’s secret redaction; the names of the shapes that fired come back once each, in canonical order, for the record’s redacted field. A body without secrets comes back unchanged with no shapes.

use majordomus_cli::reasoning::record::{AssessmentInput, ReasoningBody};
use majordomus_cli::reasoning::store::redact;

// assembled at run time, so that no committed file carries a credential's shape
let key = format!("{}{}", "sk-ant-", "b".repeat(24));
let body = ReasoningBody::Assessment(AssessmentInput {
    subject: format!("the key {key} leaks"),
    ..Default::default()
});
let (body, kinds) = redact(body);
let ReasoningBody::Assessment(a) = body else { panic!("the kind is kept") };
assert!(!a.subject.contains("sk-ant-"));
assert_eq!(kinds, ["anthropic-key"]);