requirements.authoring.citation_prompt
Requirements index · View definition
Requirement
A citation review under
MUST use the same tools and exactly-once submission rule as other assessments and this prompt, replacing
{{item_file}},{{item_selector}}(with<root>for the root node),{{citations}}(the item’s{cite}references as JSON with role, name, and commentary),{{habeas_background}}and{{reference_roles}}under,
{{judgment_rules}}under, and
{{mandatory_inputs}}, the first block as its system prompt and the second as its subject message under:
# Task Review one source item's citations. Your determination should be the one any careful reviewer would reach from the same text and sources. # Background: Habeas terms {{habeas_background}} {{reference_roles}} # Your task The mandatory inputs at the end contain the source item and the declarations or fixed built-in text of its citations. Assess each listed citation using the rules below. For citations of project requirements and examples, decide whether the item implements part of a cited requirement, not whether it does so correctly. Do not look for requirements or examples the item does not cite, except as needed to assess a built-in's stated citation criteria. 1. For citations of project requirements and examples, apply the reference procedure in order: if the item is a test designed to verify the cited requirement or example, it calls for {test}; otherwise, if it is a root of the cited definition's implementation as the reference roles describe, it calls for {impl}; otherwise the citation is right if a change to the cited text could require changing the item, as when the item relies on behavior the text specifies or must agree with a form or value it defines; read the item's callers only when the item's own code does not settle this. A citation for which this calls for a different role, or for no reference at all, is a gap. 2. A citation of a requirement or example the item also references with {impl} or {test} is redundant and is a gap. 3. Treat commentary as context. For a built-in citation, check its permitted reference roles and forms and assess any citation-review criteria stated in its fixed text using the source and commentary. Read other sources when a stated reason relies on them. Record a gap when the stated criteria are not met. # How to judge {{judgment_rules}} # Submitting Choose true when your task finds no gap, and false otherwise. A citation review MUST NOT submit a FIXME determination. You MUST end by calling submit_judgment with determination and rationale until one submission is accepted. A rejected submission does not complete the assessment. A judgment written in your reply text is not accepted.# Subject Item under review: {{item_file}} {{item_selector}} Citations to check: {{citations}} Judge against: the declarations or fixed built-in text it cites. # Mandatory inputs {{mandatory_inputs}}
Rationale
Obligations derived from requirements.authoring.citation_prompt
- A citation review uses the same tools and the exactly-once submission rule as other assessments.
- The prompt template has these placeholders replaced:
{{item_file}}and{{item_selector}}, with<root>for the root node.{{citations}}, as JSON with role, name and commentary.{{habeas_background}}and{{reference_roles}}.{{judgment_rules}}.{{mandatory_inputs}}.
- The first block is the system prompt and the second is the subject message. The system prompt is the same for every citation review.
- The prompt text tells the reviewer not to submit a FIXME determination.
Test coverage
src/authoring/mod.rs#mod[tests]/fn[citation_reviews_use_their_prompt_and_record_the_item_and_citations]covers most of these.- Tools: it asserts that the tool names sent to the provider equal
tool_definitions_with("submit_judgment", false). - Exactly-once rule: a scripted provider submits twice, and the test asserts the error contains “exactly once”.
- Item and selector: the prompt contains “Item under review: src/lib.rs fn[helper]”. For a
notes.txtitem that has no selector, it contains “Item under review: notes.txt”. AuthoringSubject::parseofcitations:notes.txtis also checked to name the root. - Citations: the payload after “Citations to check: “ in the user message is parsed and compared to the exact JSON of role, name and commentary. The commentary comes from a built-in
habeas:utilcitation. - Background and rules: the prompt contains the approved
habeas_backgroundblocks 0 and 1 and the approvedjudgment_rulesblock, and no{{remains. - Mandatory inputs: the prompt contains the first input’s hash, the requirement text, and the built-in text.
- Task text: the prompt contains “Review one source item’s citations.”
- Record: it checks the recorded file, item, citations and determination, and that validation accepts the record.
- Tools: it asserts that the tool names sent to the provider equal
src/authoring/mod.rs#mod[tests]/fn[subjects_of_one_kind_share_a_byte_identical_system_prompt]covers the system/subject split.- Both blocks of the approved
citation_prompttemplate are matched literally, and only declared placeholders may expand. - The test runs on two different citation subjects,
fn[cites_one]andfn[cites_two]. - It asserts the system prompts are identical, the subject messages differ, and the subject message starts with “# Subject”. The system prompt does not contain the subject name.
- The request is built as a system message followed by one user message.
- Both blocks of the approved
src/authoring/mod.rs#mod[tests]/fn[coverage_explanations_use_standard_citation_authoring_and_freshness]checks that the rendered prompt contains “For a built-in citation” and “MUST NOT submit a FIXME”. It also checks that the prompt carries the commentary and that the record’s inputs exclude built-ins.src/authoring/inputs.rs#impl[AssessmentSources]/fn[prepare_citation]setshas_applicable_fixmeto false for a citation review. The citation tests assert this false value, and the tool set they check is built without FIXME (tool_definitions_with("submit_judgment", false)).src/authoring/tools.rs#mod[tests]/fn[model_inputs_reads_searches_and_citation_prompts_are_redacted]checks that the citation prompt and mandatory inputs are redacted, which is consistent with the requirement.
Remaining limits
- The tool comparison checks names only, not the submit schema. The no-FIXME rule is checked through the prompt text and the
has_applicable_fixmeflag. This is not an obligation-level gap. - The requirement’s clauses on the same tools and the exactly-once rule, the placeholders, and the system/subject block split are each asserted. I found no plausible violating behavior that the reviewed tests would accept.
Inputs
Implementation
Input 10: outline src/authoring/inputs.rs impl[AssessmentSources]/fn[prepare_citation]
- File:
src/authoring/inputs.rs - Selector:
impl[AssessmentSources]/fn[prepare_citation] - Kind:
fn src/authoring/inputs.rs:298–391
/// Prepares a citation review of one source item outside the book. Its
/// mandatory inputs are the item's outline node, each cited declaration
/// or built-in text, and the terminology they use; the citations and
/// their commentary are supplied in the prompt.
// {impl}`requirements.authoring.citation_prompt`
// {impl}`requirements.authoring.mandatory_inputs`
pub(crate) fn prepare_citation(root: &Path, file: &str, item: &str) -> io::Result<Self> {
let root = fs::canonicalize(root)?;
let access = SourceAccess::load(&root)?;
let definitions = load_definitions(&root)?;
let outlines = OutlineCache::default();
let mut errors = Vec::new();
let references = collect_references(&root, &mut errors);
if !errors.is_empty() {
return Err(io::Error::other(errors.join("\n")));
}
let subject_name = crate::citations::subject_label(file, item);
let citation = crate::citations::citation_items(
&root,
&definitions,
&references,
&outlines,
)
.remove(&(file.to_owned(), item.to_owned()))
.ok_or_else(|| {
io::Error::other(format!(
"{subject_name}: no source item outside the book with {{cite}} references matches"
))
})?;
let mut mandatory = vec![source_input(
&root,
&access,
&definitions,
&outlines,
&InputSelector::Outline {
file: file.to_owned(),
item: item.to_owned(),
},
)?];
let mut builtins = Vec::new();
let mut selectors = Vec::new();
for cited in &citation.citations {
if crate::builtins::builtin(&cited.name).is_some() {
if !builtins.contains(&cited.name) {
builtins.push(cited.name.clone());
}
} else {
insert_selector(
&mut selectors,
InputSelector::Requirements {
requirements: cited.name.clone(),
},
);
}
}
for selector in selectors {
mandatory.push(source_input(
&root,
&access,
&definitions,
&outlines,
&selector,
)?);
}
for input in definition_inputs(&root, &access, &definitions, &outlines, &mandatory, None)? {
if !mandatory.contains(&input) {
mandatory.push(input);
}
}
mandatory.extend(builtins.iter().map(|name| builtin_input(name)));
let github = GithubIssues::from_env(&root);
let issue_states = crate::github::input_issue_states(
&root,
&github,
&references,
&definitions,
&mandatory,
);
Ok(Self {
root,
access,
subject_name,
subject_kind: AssessmentKind::Citation(citation),
has_applicable_fixme: false,
subject_text: String::new(),
outlines,
reference_set: String::new(),
acknowledgments: Vec::new(),
mandatory,
issue_states,
github,
recorded: Vec::new(),
})
}
Tests
Input 6: outline src/authoring/mod.rs mod[tests]/fn[coverage_explanations_use_standard_citation_authoring_and_freshness]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[coverage_explanations_use_standard_citation_authoring_and_freshness] - Kind:
fn src/authoring/mod.rs:4170–4259
// {test}`requirements.test-coverage.check.exceptions.author`
// {test}`requirements.references.citation_review`
// {test}`requirements.authoring.citation_prompt`
#[tokio::test]
async fn coverage_explanations_use_standard_citation_authoring_and_freshness() {
let project = inputs::tests::project();
let source = "// :::{cite} habeas:coverage\n// Defensive invariant abort, inaccessible through the API.\n// :::\nfn helper() {}\n";
fs::write(project.path().join("src/lib.rs"), source).unwrap();
let subject = AuthoringSubject::parse("citations:src/lib.rs#fn[helper]");
let mut sources = subject.sources(project.path()).unwrap();
let mandatory = sources.mandatory_inputs().to_vec();
assert_eq!(mandatory[0]["item"], "fn[helper]");
assert!(
mandatory[0]["text"].to_string().contains("fn helper() {}"),
"{mandatory:?}"
);
assert!(
mandatory[0]["hash"]
.as_str()
.is_some_and(|hash| hash.len() == 64),
"{mandatory:?}"
);
assert!(mandatory.iter().any(|input| {
input["builtin"] == "habeas:coverage"
&& input["text"][0]
.as_str()
.unwrap()
.contains("difficulty alone")
}));
let prompt = initial_prompt(&sources).unwrap().joined();
assert!(prompt.contains("Defensive invariant abort"));
assert!(prompt.contains("For a built-in citation"));
assert!(prompt.contains("MUST NOT submit a FIXME"));
let state = tempfile::tempdir().unwrap();
let mut usage = UsageLog::start(state.path(), project.path(), &subject.label()).unwrap();
let provider = RecordingProvider::new(vec![judgment(
json!(true),
"The supplied source and explanation support the citation.",
)]);
let (_, record) = assess(&provider, &mut sources, &mut usage).await.unwrap();
assert_eq!(record["determination"], true);
assert_eq!(record["citations"][0]["name"], "habeas:coverage");
assert!(
record["inputs"]
.as_array()
.unwrap()
.iter()
.any(|input| input["file"] == "src/lib.rs"
&& input["item"] == "fn[helper]"
&& input["hash"] == mandatory[0]["hash"]),
"{record:?}"
);
assert!(
record["inputs"]
.as_array()
.unwrap()
.iter()
.all(|input| input.get("builtin").is_none())
);
let path = subject.evidence_path(project.path());
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, serde_json::to_vec(&record).unwrap()).unwrap();
fs::write(
project.path().join("src/lib.rs"),
source.replace("inaccessible", "reachable"),
)
.unwrap();
let definitions = crate::evidence::load_definitions(project.path()).unwrap();
let mut errors = Vec::new();
let references = crate::evidence::collect_references(project.path(), &mut errors);
let outlines = crate::inputs::OutlineCache::default();
let item =
crate::citations::citation_items(project.path(), &definitions, &references, &outlines)
.remove(&("src/lib.rs".into(), "fn[helper]".into()))
.unwrap();
crate::citations::validate_review(
project.path(),
&item.review_path(),
&item,
&definitions,
&outlines,
&mut errors,
);
assert!(
errors
.iter()
.any(|error| error.contains("citations changed")),
"{errors:?}"
);
}
Input 7: outline src/authoring/mod.rs mod[tests]/fn[citation_reviews_use_their_prompt_and_record_the_item_and_citations]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[citation_reviews_use_their_prompt_and_record_the_item_and_citations] - Kind:
fn src/authoring/mod.rs:4261–4416
// {test}`requirements.authoring.citation_prompt`
// {test}`requirements.references.citation_review`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.habeas_background`
// {test}`requirements.authoring.judgment_rules`
// {test}`requirements.authoring.adaptive`
#[tokio::test]
async fn citation_reviews_use_their_prompt_and_record_the_item_and_citations() {
let project = inputs::tests::project();
let cite = "{cite}`requirements.ready`";
fs::write(
project.path().join("src/lib.rs"),
format!(
"// {cite}\n// :::{{cite}} habeas:util\n// Formats output for the caller.\n// :::\nfn helper() {{}}\n"
),
)
.unwrap();
let subject = AuthoringSubject::parse("citations:src/lib.rs#fn[helper]");
assert_eq!(
subject.evidence_path(project.path()),
project
.path()
.join("evidence/citations/src/lib.rs/fn[helper].json")
);
let mut sources = subject.sources(project.path()).unwrap();
assert!(!sources.has_applicable_fixme);
let mandatory = sources.mandatory_inputs().to_vec();
assert_eq!(mandatory[0]["file"], "src/lib.rs");
assert_eq!(mandatory[0]["item"], "fn[helper]");
assert_eq!(mandatory[1]["requirements"], "requirements.ready");
assert_eq!(mandatory[2]["builtin"], "habeas:util");
assert!(
mandatory[2]["text"][0]
.as_str()
.unwrap()
.starts_with("Cite this on an item that serves")
);
let state = tempfile::tempdir().unwrap();
let mut usage = UsageLog::start(state.path(), project.path(), &subject.label()).unwrap();
let provider = RecordingProvider::new(vec![judgment(json!(true), "Both are sensible.")]);
let (_, record) = assess(&provider, &mut sources, &mut usage).await.unwrap();
let prompts = provider.prompts();
let expected: Vec<_> = tool_definitions_with("submit_judgment", false)
.unwrap()
.into_iter()
.map(|tool| tool.name)
.collect();
assert_eq!(prompts[0].1, expected);
let duplicate = json!({"determination":true,"rationale":"Both are sensible."});
let duplicate_provider = ScriptedProvider {
turns: vec![vec![
("submit_judgment", duplicate.clone()),
("submit_judgment", duplicate),
]],
requests: RefCell::default(),
};
let mut duplicate_sources = subject.sources(project.path()).unwrap();
assert!(
assess(&duplicate_provider, &mut duplicate_sources, &mut usage)
.await
.unwrap_err()
.to_string()
.contains("exactly once")
);
let prompt = &prompts[0].0;
assert!(
prompt.contains("Review one source item's citations."),
"{prompt}"
);
assert!(
prompt.contains("Item under review: src/lib.rs fn[helper]"),
"{prompt}"
);
assert!(
prompt.contains("Formats output for the caller."),
"{prompt}"
);
// The initial request carries the complete mandatory set.
assert!(
prompt.contains(mandatory[0]["hash"].as_str().unwrap()),
"{prompt}"
);
assert!(prompt.contains("The project MUST be ready."), "{prompt}");
assert!(
prompt.contains("Cite this on an item that serves"),
"{prompt}"
);
// Prompts are recorded as serialized requests.
for background in [
approved_text("habeas_background", 0),
approved_text("habeas_background", 1),
approved_text("judgment_rules", 0),
] {
let background = serde_json::to_string(background).unwrap();
assert!(prompt.contains(background.trim_matches('"')), "{prompt}");
}
assert!(!prompt.contains("{{"), "{prompt}");
let citations = json!([
{"role": "cite", "name": "requirements.ready", "commentary": ""},
{"role": "cite", "name": "habeas:util", "commentary": "Formats output for the caller."}
]);
let request: Value = serde_json::from_str(prompt).unwrap();
// Compare the actual placeholder payload, rather than text which
// could also appear independently in the mandatory source inputs.
let user = request["chat_history"]
.as_array()
.unwrap()
.iter()
.find(|message| message["role"] == "user")
.unwrap();
let subject_text = user["content"][0]["text"].as_str().unwrap();
let payload = subject_text
.lines()
.find_map(|line| line.strip_prefix("Citations to check: "))
.unwrap();
assert_eq!(serde_json::from_str::<Value>(payload).unwrap(), citations);
assert_eq!(record["file"], "src/lib.rs");
assert_eq!(record["item"], "fn[helper]");
assert_eq!(record["citations"], citations);
assert_eq!(record["determination"], true);
let inputs = record["inputs"].as_array().unwrap();
assert!(inputs.iter().all(|input| input.get("builtin").is_none()));
assert_eq!(inputs.len(), 2, "{inputs:#?}");
// The recorded review satisfies validation for its item.
let path = subject.evidence_path(project.path());
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(&path, record.to_string()).unwrap();
let errors = crate::validate_repository(project.path()).unwrap().errors;
assert!(
!errors
.iter()
.any(|error| error.starts_with("evidence/citations/")),
"{errors:#?}"
);
// A name without a selector reviews the file's root node.
assert!(matches!(
AuthoringSubject::parse("citations:notes.txt"),
AuthoringSubject::Citation { file, item } if file == "notes.txt" && item.is_empty()
));
// The root node's selector is shown as `<root>` in the prompt.
fs::write(project.path().join("notes.txt"), format!("Notes. {cite}\n")).unwrap();
let sources = AuthoringSubject::parse("citations:notes.txt")
.sources(project.path())
.unwrap();
let prompt = initial_prompt(&sources).unwrap().joined();
assert!(
prompt.contains("Item under review: notes.txt <root>"),
"{prompt}"
);
assert!(!prompt.contains("{{"), "{prompt}");
}
Input 8: outline src/authoring/mod.rs mod[tests]/fn[subjects_of_one_kind_share_a_byte_identical_system_prompt]
- File:
src/authoring/mod.rs - Selector:
mod[tests]/fn[subjects_of_one_kind_share_a_byte_identical_system_prompt] - Kind:
fn src/authoring/mod.rs:4464–4571
/// Every system prompt is the same for two subjects of its kind, and
/// every subject-dependent value is in the subject message.
// {test}`requirements.authoring.prompt_parts`
// {test}`requirements.authoring.initial_prompt`
// {test}`requirements.authoring.citation_prompt`
// {test}`requirements.authoring.site_prompt`
// {test}`requirements.authoring.verifier_prompt`
#[test]
fn subjects_of_one_kind_share_a_byte_identical_system_prompt() {
// Check every literal segment of the selected approved blocks, allowing
// only declared placeholders to expand, then check the opening message roles.
fn assert_opening(prompt: &Prompt, template: &str) {
let placeholders = regex::Regex::new(r"\{\{[^}]+\}\}").unwrap();
for (index, actual) in [&prompt.system, &prompt.subject].into_iter().enumerate() {
let expected = approved_text(template, index);
let mut pattern = String::from(r"\A");
let mut end = 0;
for placeholder in placeholders.find_iter(expected) {
pattern.push_str(®ex::escape(&expected[end..placeholder.start()]));
pattern.push_str("(?s:.*?)");
end = placeholder.end();
}
pattern.push_str(®ex::escape(&expected[end..]));
pattern.push_str(r"\z");
assert!(
regex::Regex::new(&pattern).unwrap().is_match(actual),
"{template} block {index}: {actual}"
);
assert!(!actual.contains("{{"), "{actual}");
}
let request = Prompt {
system: prompt.system.clone(),
subject: prompt.subject.clone(),
}
.request();
assert_eq!(
request.chat_history,
vec![
Message::system(prompt.system.clone()),
Message::user(prompt.subject.clone())
]
);
}
let project =
crate::sites::tests::project(crate::sites::tests::RULE, crate::sites::tests::SOURCE);
let requirements = project.path().join("md/requirements.md");
let mut book = fs::read_to_string(&requirements).unwrap();
let cite = "{cite}`requirements.rule`";
book.push_str(&format!(
"\n:::{{req}} other\nThe project MUST also work.\n:::\n\n:::{{req}} second\nThe project MUST keep working.\n:::\n\n:::{{example}} first_case\nA case. {cite}\n:::\n\n:::{{example}} second_case\nAnother case. {cite}\n:::\n"
));
fs::write(&requirements, book).unwrap();
let source = project.path().join("src/lib.rs");
let mut text = fs::read_to_string(&source).unwrap();
text.push_str(&format!(
"\n// {cite}\nfn cites_one() {{}}\n\n// {cite}\n// :::{{cite}} habeas:util\n// Formats output.\n// :::\nfn cites_two() {{}}\n"
));
fs::write(&source, text).unwrap();
for (first, second, template) in [
(
"requirements.other",
"requirements.second",
"initial_prompt",
),
(
"requirements.first_case",
"requirements.second_case",
"initial_prompt",
),
(
"citations:src/lib.rs#fn[cites_one]",
"citations:src/lib.rs#fn[cites_two]",
"citation_prompt",
),
(
"sites:requirements.rule/src/lib.rs#fn[check_one]",
"sites:requirements.rule/src/lib.rs#fn[check_two]",
"site_prompt",
),
] {
let sources = |subject: &str| {
AuthoringSubject::parse(subject)
.sources(project.path())
.unwrap()
};
let (first, second) = (sources(first), sources(second));
let (one, two) = (
initial_prompt(&first).unwrap(),
initial_prompt(&second).unwrap(),
);
assert_opening(&one, template);
assert_opening(&two, template);
assert_eq!(one.system, two.system, "{}", first.subject_name);
assert_ne!(one.subject, two.subject);
assert!(one.subject.starts_with("# Subject\n\n"), "{}", one.subject);
assert!(!one.system.contains(&first.subject_name));
let (one, two) = (
verification_prompt(&first, &Judgment::False, "One gap.").unwrap(),
verification_prompt(&second, &Judgment::Fixme(vec!["#2".into()]), "Two gaps.")
.unwrap(),
);
assert_opening(&one, "verifier_prompt");
assert_opening(&two, "verifier_prompt");
assert_eq!(one.system, two.system, "verifier of {}", first.subject_name);
assert!(one.subject.contains("One gap."));
assert!(!one.system.contains("One gap."));
}
}
Input 9: outline src/authoring/tools.rs mod[tests]/fn[model_inputs_reads_searches_and_citation_prompts_are_redacted]
- File:
src/authoring/tools.rs - Selector:
mod[tests]/fn[model_inputs_reads_searches_and_citation_prompts_are_redacted] - Kind:
fn src/authoring/tools.rs:1696–1774
// {test}`requirements.authoring.redaction`
// {test}`requirements.authoring.credentials`
// {test}`requirements.authoring.source_tools`
// {test}`requirements.authoring.text_search`
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.citation_prompt`
// {test}`requirements.authoring.fixme_inputs`
#[test]
fn model_inputs_reads_searches_and_citation_prompts_are_redacted() {
let root = project();
let token = crate::redaction::tests::github_token();
fs::write(
root.path().join("habeas.toml"),
"version = 1\n[authoring.configs.local]\nbackend = 'ollama'\nmodel = 'm'\napi_key = 'plain ollama key'\n",
)
.unwrap();
fs::write(
root.path().join("src/lib.rs"),
format!(
"// {}\nfn client() -> &'static str {{\n \"{token}\"\n}}\n\n// :::{} requirements.ready\n// Defaults to {token}.\n// :::\nfn helper() {{}}\n\n// :::{{fixme}} requirements.ready\n// Missing check for {token}.\n// :::\nfn gap() {{}}\n",
role("test", "requirements.ready"),
"{cite}"
),
)
.unwrap();
git(root.path(), &["init", "--quiet"]);
git(root.path(), &["add", "."]);
let leaks = |value: &Value| {
let text = value.to_string();
text.contains(&token) || text.contains("plain ollama key")
};
// Mandatory inputs, and so the initial and verification prompts.
let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
let mandatory = Value::Array(sources.mandatory_inputs().to_vec());
assert!(!leaks(&mandatory), "{mandatory:#}");
assert!(mandatory.to_string().contains("[REDACTED:GitHub Token]"));
let prompt = super::super::initial_prompt(&sources).unwrap().joined();
assert!(!prompt.contains(&token), "{prompt}");
assert!(
prompt.contains("Missing check for [REDACTED:GitHub Token]."),
"{prompt}"
);
assert!(!prompt.contains("fn gap()"), "{prompt}");
// A habeas read of the configuration file and a line range.
let read = dispatch(&sources, "habeas", &json!({"file":"habeas.toml","item":""})).unwrap();
assert!(!leaks(&read.result), "{:#}", read.result);
assert!(
read.result["input"]["text"]
.as_array()
.unwrap()
.contains(&json!("api_key = '[REDACTED:api_key]'"))
);
let lines = dispatch(
&sources,
"habeas",
&json!({"file":"src/lib.rs","line_start":1}),
)
.unwrap();
assert!(!leaks(&lines.result), "{:#}", lines.result);
// Search results, even for a pattern matching the credential itself.
for pattern in ["ollama", "gh[p]_", "Defaults"] {
let search = dispatch(&sources, "ripgrep", &json!({"pattern": pattern})).unwrap();
assert!(
!search.result["matches"].as_array().unwrap().is_empty(),
"{pattern}"
);
assert!(!leaks(&search.result), "{pattern}: {:#}", search.result);
}
// A citation review's inputs and its commentary in the prompt.
let citation =
AssessmentSources::prepare_citation(root.path(), "src/lib.rs", "fn[helper]").unwrap();
assert!(!leaks(&Value::Array(citation.mandatory_inputs().to_vec())));
let prompt = super::super::initial_prompt(&citation).unwrap().joined();
assert!(!prompt.contains(&token), "{prompt}");
assert!(
prompt.contains("Defaults to [REDACTED:GitHub Token]."),
"{prompt}"
);
}
Referenced definitions
Input 2: requirements selection requirements.references.citation_review
requirements.references.citation_review:md/requirements/references.md:146–174
:::{req} citation_review
Every source item outside the book that carries at least one `{cite}` reference
other than a citation of `habeas:util` under {cite}`requirements.references.util`
MUST have a citation review: an assessment of that item's citations, recorded at
`evidence/citations/<file>/<selector>.json`, where `<file>` is the item's
project-relative path, `<selector>` is its outline selector with every `/` and
`%` percent-encoded, and the root node uses `_root`. The review MUST use the
prompt defined by {cite}`requirements.authoring.citation_prompt`. For citations
of project requirements and examples, the reviewer MUST assess whether the item
should be re-checked or kept in sync when the cited definition changes, and
whether the reference procedure of
{cite}`requirements.references.procedure` calls for `{impl}` or `{test}` instead.
For citations of built-ins, the reviewer MUST check the permitted reference
roles and forms and any citation-review criteria stated in the built-in's fixed
text, using the item's source and commentary. A permitted citation role alone
MUST NOT suffice when the fixed text states additional criteria. Mandatory inputs,
under {cite}`requirements.authoring.mandatory_inputs`, MUST be the item's outline
node, each cited declaration or built-in text, and the citations' commentary. The record MUST contain the item's file and selector,
its citations by role, name, and commentary, `determination`, `rationale`, and
`inputs`, with determinations under {cite}`requirements.ci.outcomes`. Validation
MUST require a current, accepted review for every such item and report stale,
missing, or orphaned reviews; a review MUST become stale when the item's hash,
a cited declaration, or its citations or their commentary change. Authoring with
`--all` MUST include citation reviews, and `habeas author citations:<file>#<selector>`
MUST author the review of the one item it names, under
{cite}`requirements.authoring.refresh`, where omitting `#<selector>`
names the file's root node. A citation in a requirement or example
declaration is reviewed as part of that definition's own assessment instead.
:::
Input 3: requirements selection requirements.authoring.habeas_background
requirements.authoring.habeas_background:md/requirements/authoring.md:195–267
:::{req} habeas_background
Every assessment prompt MUST replace `{{habeas_background}}` with the first text
below. The requirement, citation, and verifier prompts MUST replace
`{{reference_roles}}` with the second, except that a verifier checking a site
review MUST replace it with nothing. The site prompt, the distributed task, and a
verifier checking a site review MUST replace `{{distributed_background}}` with
the third. So all assessments share the same account of Habeas's terms:
```text
Habeas traces a project's requirements, written in its mdBook, to the source
code and tests that implement and verify them.
- A requirement is a {req} directive in the book that states obligations with
MUST, MUST NOT, SHOULD, and MAY. A named example is an {example} directive
describing a concrete case of one or more requirements. Both have
dot-separated full names, such as requirements.cli.status. A vocabulary
definition, a {definition} directive, defines a term that other text uses with
{term}; it is never the target of a reference.
- Source code marks the requirements and examples it implements, tests, or
relies on with {impl}, {test}, and {cite} references, such as
{impl}`requirements.cli.status`, and acknowledges known gaps in them with
{fixme} references.
- Sources are identified by outline nodes: a file's functions, types, sections,
and similar items, named by selectors such as fn[run] or impl[Thing]/fn[run].
<root> is the whole file.
```
```text
The reference roles:
- {impl}: the source implements part of the requirement or example. Source code
implements part of one when it makes a decision, performs a check, produces an
output, or handles a case it specifies, or when it constrains a type's fields,
variants, serialized form, or validation. Calling code that implements it, or
producing a value a caller uses to meet it, does not by itself count. A check
counts only if the text states it, or the item could not meet one of the
text's obligations without it; then returning its outcome counts even when a
caller acts on it. Code that checks it is consistent with a requirement, such
as recognizing a form the requirement defines in order to decide whether to
run other behavior, relies on that requirement ({cite}) rather than
implementing it. A requirement stating a convention for every output of a
kind, such as every validation error, is implemented by the code that carries
out the convention as a whole, not by each item that produces one such output.
Only a root needs the reference: an item that no other item marked {impl}
for the same requirement reaches. Code a reviewer reaches by following a
marked item, through what it calls, the types it uses, or the implementations
of trait methods it calls, needs none; nor does a test helper reached from a
test marked {test}. A site of a
distributed requirement needs no reference to it for being a site.
- {test}: the source is a test or test helper designed to verify behavior the
requirement or example specifies.
- {cite}: the source relies on or refers to the requirement or example, and
should be re-checked or kept in sync when it changes, without implementing or
testing it. A {cite} needs no coverage; each item with citations has its own
citation review.
- {fixme}: the source acknowledges a known gap in fulfilling the requirement or
example. It is always fenced; its body describes the gap and may begin with
lines such as :github: rust-lang/rust#123 naming issues that track it.
A declaration can also name a whole file or one outline node it is implemented
or tested by, with an :impl: or :test: option line directly after its opening
fence; that counts as an {impl} or {test} reference from that source. A
reference written as a fence, :::{role} name, then commentary, then :::,
attaches commentary.
```
```text
A distributed requirement states obligations that each of many sites upholds on
its own. It contains site queries, which select its sites, and violation
queries, which select constructs likely to break those obligations. Each site is
the innermost outline node containing a site-query match.
```
:::
Input 4: requirements selection requirements.authoring.judgment_rules
requirements.authoring.judgment_rules:md/requirements/authoring.md:269–328
:::{req} judgment_rules
Every assessment prompt MUST replace `{{judgment_rules}}` with this text, so all
assessments judge by the same rules:
```text
- Derive obligations from the supplied subject and contextual text. Base
conclusions about tests or other source behavior only on source code you have
received: mandatory inputs, items read with the habeas tool, or snippets
returned by ripgrep or ast_grep. Close every delivered search with
finish_search, recording the tags whose snippets you relied on without an
additional source read. Supplied acknowledgments establish what a {fixme}
reference says and which issues it names; they do not establish that its
claimed gap is real. outline, list_files, and references only locate items;
read any item whose code your conclusion relies on unless a search snippet
provides the information you need. Comments state intent; check behavior and
assertions in the code itself.
- Judge only against the text your task names. Report a gap only where your task
or these rules define one, naming the obligation and the relevant sources you
have reviewed. For a missing test, identify the obligation or scenario after
looking where your task directs; do not invent a source item for absent code.
Do not report other bugs or issues you notice; edge cases the text does not name are
not gaps.
- A SHOULD imposes an obligation unless the text or a source comment gives a
reason it does not apply. In a test-adequacy assessment, apply the testing
criteria to each applicable SHOULD, and explain any exception in your rationale.
MAY imposes nothing to check. Examples and sample output inside the text
illustrate the obligations its prose states; they bind their exact form only
where the text says the output takes that form.
- If the text admits two readings that its wording supports equally, not merely
one it fails to exclude, and they lead to different conclusions, such as
whether code conforms or which role a citation calls for, that ambiguity is a
gap. Name the readings in your rationale.
- These are not gaps: style, performance, logging, how helpers are factored,
robustness the text does not require, and silently ignoring input the text
does not mention.
- A gap is acknowledged only by a {fixme} reference, in the supplied
acknowledgments, in the inputs, or in a source you read, to the requirement
or example your task judges against, or,
in a site review, to the distributed requirement within the site, whose body
describes that same gap, and whose named issues are open; a {fixme} naming a
closed issue no longer acknowledges its gap. A plain FIXME or TODO comment is
not an acknowledgment. Judge an acknowledgment only within your task's scope.
An acknowledgment of an implementation bug alone does not establish a
test-adequacy gap or acknowledge a different missing-test or assertion gap.
Do not inspect implementation correctness merely to validate an out-of-scope
acknowledgment. In a FIXME determination or an acknowledgments list,
give each distinct issue its :github: option names once, such as
"rust-lang/rust#123", and, for a {fixme} naming no issue, its body's words
joined by single spaces. A {fixme} describing a gap that your review establishes
no longer exists within its task's scope is itself a gap.
- Explain your judgment in a Markdown rationale with source locations, including
any acknowledged gaps.
- Give a source location as its file and outline selector, the address the
habeas and outline tools use, in backticks: `src/config.rs#fn[load]`, or
`src/config.rs` for a whole file. Name requirements, examples, and
definitions by full name in backticks. Name functions, types, and tests in
backticks exactly as they are written. Do not give line numbers: they change
whenever nearby code changes, while a selector stays correct.
```
:::
Input 5: requirements selection requirements.authoring.prompt_parts
requirements.authoring.prompt_parts:md/requirements/authoring.md:1868–1876
:::{req} prompt_parts
Each assessment conversation MUST send its prompt as a system prompt followed by
one user message, the subject message, filled from the first and second text
blocks of the prompt requirement for the assessment's kind. The kinds are
requirement, example, citation review, site review, and a verifier of each of
those. A system prompt MUST be the same for every assessment of its kind, so
every placeholder whose value depends on the subject MUST be in the subject
message.
:::
Other sources
Input 1: requirements selection requirements.authoring.citation_prompt
requirements.authoring.citation_prompt:md/requirements/authoring.md:330–406
:::{req} citation_prompt
A citation review under {cite}`requirements.references.citation_review` MUST use
the same tools and exactly-once submission rule as other assessments and this
prompt, replacing `{{item_file}}`, `{{item_selector}}` (with `<root>` for the
root node), `{{citations}}` (the item's `{cite}` references as JSON with role,
name, and commentary), `{{habeas_background}}` and `{{reference_roles}}` under
{cite}`requirements.authoring.habeas_background`, `{{judgment_rules}}` under
{cite}`requirements.authoring.judgment_rules`, and `{{mandatory_inputs}}`, the
first block as its system prompt and the second as its subject message under
{cite}`requirements.authoring.prompt_parts`:
```text
# Task
Review one source item's citations. Your determination should be the one any
careful reviewer would reach from the same text and sources.
# Background: Habeas terms
{{habeas_background}}
{{reference_roles}}
# Your task
The mandatory inputs at the end contain the source item and the declarations
or fixed built-in text of its citations.
Assess each listed citation using the rules below. For citations of project
requirements and examples, decide whether the item implements part of a cited
requirement, not whether it does so correctly. Do not look for requirements or
examples the item does not cite, except as needed to assess a built-in's stated
citation criteria.
1. For citations of project requirements and examples, apply the reference
procedure in order: if the item is a
test designed to verify the cited requirement or example, it calls for
{test}; otherwise, if it is a root of the cited definition's
implementation as the reference roles describe, it calls for {impl};
otherwise the citation is right if a change to the cited text could
require changing the item, as when the item relies on behavior the text
specifies or must agree with a form or value it defines; read the item's
callers only when the item's own code does not settle this. A citation for
which this calls for a different role, or for no reference at all, is a gap.
2. A citation of a requirement or example the item also references with {impl}
or {test} is redundant and is a gap.
3. Treat commentary as context. For a built-in citation, check its permitted
reference roles and forms and assess any citation-review criteria stated in
its fixed text using the source and commentary.
Read other sources when a stated reason relies on them.
Record a gap when the stated criteria are not met.
# How to judge
{{judgment_rules}}
# Submitting
Choose true when your task finds no gap, and false otherwise. A citation review
MUST NOT submit a FIXME determination. You MUST end by calling submit_judgment
with determination and rationale until one submission is accepted.
A rejected submission does not complete the assessment. A judgment written in your
reply text is not accepted.
```
```text
# Subject
Item under review: {{item_file}} {{item_selector}}
Citations to check: {{citations}}
Judge against: the declarations or fixed built-in text it cites.
# Mandatory inputs
{{mandatory_inputs}}
```
:::