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.reference_index

Requirements index · View definition

evidence Valid

Requirement

The harness MUST expose a references tool with this interface:

references({ selection: String?, roles: Array<"impl" | "cite" | "test">? }) -> ReferenceIndex

ReferenceIndex {
    definitions: Array<DefinitionName>,
    sites: Array<ReferenceSite>,
}

DefinitionName { name: String, kind: "requirement" | "example" }

ReferenceSite {
    name: String,
    role: "impl" | "cite" | "test",
    file: String,
    item: String?,
}

selection MUST be a definition selection. Without selection, the tool MUST return the full name and kind of every requirement and named example in full-name order, with empty sites. With selection, it MUST return the selected definitions in full-name order and one flattened sites array containing every valid reference to any match whose role is in roles, defaulting to ["impl", "cite", "test"], under cite requirements.references.discovery, each naming the definition it references, ordered by name, file, and position in the file, without line numbers. Roles MUST be treated as a set: repeating a permitted role MUST NOT duplicate sites or change the result. An anchor under cite requirements.references.anchors whose role is selected by roles MUST be reported as a site for its anchored file, with the anchored node’s selector as item when it names one and no item when it names the whole file. Every other site MUST give as item the selector of its smallest enclosing outline node under cite requirements.references.outline_comments. Only sources reference discovery considers under cite requirements.references.discovery MUST contribute sites. If reading such a source fails, the tool MUST return an explanatory tool error naming the source. An invalid selection or one matching no definition MUST return an explanatory tool error.

An empty roles array MUST return no sites while preserving the selected definitions’ names and kinds. An unknown role or a value other than an array of permitted role strings MUST return an explanatory tool error. Without selection, roles MUST NOT change the definition-name listing.

Results MUST contain no requirement text, example text, reference commentary, or source text. Like directory listings, they MUST NOT become evidence inputs; the model requests the sources it relies on with the habeas tool. For example, references({selection: "requirements.cli.status", roles: ["impl"]}) MUST locate only that subject’s implementation references and anchors, without supplying their source or recording evidence inputs.

Rationale

The reviewed tests cover every obligation in requirements.authoring.reference_index. I did not request implementation source, because the supplied test text was enough to judge each obligation.

  • Interface. references_tool_is_advertised_with_an_optional_selection in src/authoring/tools.rs asserts the exact parameter schema. The schema has an optional string selection, a roles array limited to the enum impl, cite and test with that three-role default, and additionalProperties set to false. It also checks the description phrases.
  • No selection. references_list_names_and_flattened_sites_without_recording_inputs asserts the exact result of references({}). It lists every requirement and named example with its kind, in full-name order (case, other, ready), with empty sites. The source order is different (ready, other, case), so the test shows the sorting. The {definition} word is excluded. The test also asserts that roles: ["impl"] does not change the listing.
  • With selection.
    • A full name and a glob (requirements.*) are both exercised.
    • Definitions come back in full-name order.
    • Sites are flattened into one array and each names its definition.
    • Sites are ordered by name, then file, then position in the file. md/requirements.md comes before src/lib.rs, and fn[zeta] comes before fn[work], which is position order rather than alphabetical order. requirements.other sorts before requirements.ready.
    • Default roles return all three roles.
    • Filtering to impl returns only impl sites.
    • Repeated roles (["impl","impl"]) give the same result with no duplicates.
    • An empty roles array gives the same definitions and sites: [].
    • Exact JSON equality means no line numbers, no text and no commentary appear.
  • Anchors. references_report_anchors_as_file_or_node_sites checks that an :impl: anchor with a selector reports item: "section[Skill]". It checks that a whole-file :test: anchor reports item: null. It also checks that role filtering applies to anchors, and that an anchor to a disallowed path (private/notes.md) contributes no site.
  • Enclosing item.
    • A comment inside fn work gives fn[work].
    • A comment run before a function gives that function.
    • A reference in Markdown gives a section@… item.
    • A fenced reference in a comment run attaches to the next function.
    • A {fixme} and an unclosed fence contribute no sites.
  • Considered sources only. references_report_only_sites_in_considered_sources uses a Git worktree. It has a tracked file, a file removed from the index, and a file under a disallowed path. Only the tracked file is returned.
  • Read failure. references_name_a_considered_source_that_cannot_be_read uses a chmod 000 file. It asserts an error that names src/locked.rs. It returns early if the user can read the file anyway, such as root.
  • Invalid selection. The test asserts errors for a missing name, a vocabulary term, a malformed name, an empty string, a non-string selection (with a message check), and an unknown parameter.
  • Invalid roles. null, a bare string, ["fixme"] and [1] each return an error that mentions “role”.
  • No inputs recorded. The tests assert inputs.is_empty() on every response. implementation_discovery_has_no_text_or_evidence_until_the_model_requests_a_read in tests/authoring_cli.rs checks end to end that the impl-only locate result has no requirement text, source text or input fields. It also checks that evidence is recorded only after the explicit habeas read.
  • Paging. reference_results_page_definitions_then_sites covers large results, with definitions before sites and no inputs. It is also tested under requirements.authoring.result_pages.

I found no plausible requirement-violating behavior that these tests would accept.

Inputs

Tests

Input 5: outline src/authoring/pages.rs mod[tests]/fn[reference_results_page_definitions_then_sites]
    // {test}`requirements.authoring.result_pages`
    // {test}`requirements.authoring.reference_index`
    #[test]
    fn reference_results_page_definitions_then_sites() {
        let root = project();
        let mut book = String::new();
        for index in 0..400 {
            book.push_str(&format!(
                ":::{{req}} requirement_with_a_long_name_{index:03}\nThe project MUST do {index}.\n:::\n\n"
            ));
        }
        fs::write(root.path().join("md/requirements.md"), book).unwrap();
        let mut source = String::new();
        for index in 0..400 {
            source.push_str(&format!(
                "// {}\nfn site_{index}() {{}}\n\n",
                role(
                    "impl",
                    &format!("requirements.requirement_with_a_long_name_{index:03}")
                )
            ));
        }
        fs::write(root.path().join("src/lib.rs"), source).unwrap();
        let sources = AssessmentSources::prepare(
            root.path(),
            "requirements.requirement_with_a_long_name_000",
        )
        .unwrap();
        let mut pages = ResultPages::default();
        let first = dispatch_paged(
            &sources,
            &mut pages,
            "references",
            &json!({"selection": "requirements.*"}),
        )
        .unwrap();
        let delivered = all_pages(&mut pages, first);
        let (mut definitions, mut sites) = (Vec::new(), Vec::new());
        for page in &delivered {
            assert!(page.result.to_string().len() <= PAGE_LIMIT);
            assert!(page.inputs.is_empty());
            let held = page.result["definitions"].as_array().unwrap();
            let found = page.result["sites"].as_array().unwrap();
            assert_eq!(
                page.result["page"]["returned_entries"],
                (held.len() + found.len()) as u64
            );
            // Sites follow every definition.
            assert!(found.is_empty() || definitions.len() + held.len() == 400);
            definitions.extend(held.iter().map(|entry| entry["name"].clone()));
            sites.extend(found.iter().map(|entry| entry["name"].clone()));
        }
        assert_eq!(definitions.len(), 400);
        assert_eq!(sites.len(), 400);
        assert_eq!(
            delivered[0].result["page"]["total_entries"], 800,
            "{}",
            delivered[0].result["page"]
        );
    }
Input 6: outline src/authoring/tools.rs mod[tests]/fn[references_list_names_and_flattened_sites_without_recording_inputs]
    // {test}`requirements.authoring.reference_index`
    // {test}`requirements.references.definition_globs`
    // {test}`requirements.authoring.no_line_numbers`
    // {test}`requirements.authoring.read_denial`
    #[test]
    // {test}`requirements.references.authoring_inputs`
    // {test}`requirements.authoring.read_denial`
    fn references_list_names_and_flattened_sites_without_recording_inputs() {
        let root = project();
        fs::write(
            root.path().join("md/requirements.md"),
            format!(
                ":::{{req}} ready\nThe project MUST be ready.\n:::\n\n:::{{req}} other\nOther MUST hold.\n:::\n\n:::{{example}} case\nA ready case. {}\n:::\n\n:::{{definition}} word\n:phrase: word\n:impl: src/lib.rs#fn[work]\nA vocabulary term.\n:::\n",
                role("cite", "requirements.ready")
            ),
        )
        .unwrap();
        fs::write(
            root.path().join("src/lib.rs"),
            format!(
                "// {}\nfn zeta() {{}}\n\n// {}\nfn work() {{\n    // {}\n    // {}\n}}\n",
                role("test", "requirements.ready"),
                role("impl", "requirements.ready"),
                role("cite", "requirements.other"),
                role("term", "requirements.word"),
            ),
        )
        .unwrap();
        fs::create_dir_all(root.path().join("private")).unwrap();
        fs::write(
            root.path().join("private/notes.md"),
            format!("{}\n", role("cite", "requirements.ready")),
        )
        .unwrap();
        fs::write(
            root.path().join("habeas.toml"),
            "version = 1\n\n[evidence]\ndisallow = [\"private\"]\n",
        )
        .unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();

        let all = dispatch(&sources, "references", &json!({})).unwrap();
        assert_eq!(
            all.result,
            json!({"definitions": [
                {"name": "requirements.case", "kind": "example"},
                {"name": "requirements.other", "kind": "requirement"},
                {"name": "requirements.ready", "kind": "requirement"},
            ], "sites": []})
        );
        assert!(all.inputs.is_empty());

        let ready = dispatch(
            &sources,
            "references",
            &json!({"selection": "requirements.ready"}),
        )
        .unwrap();
        let mut result = ready.result.clone();
        let markdown = result["sites"][0]["item"].take();
        assert!(
            markdown.as_str().unwrap().starts_with("section@"),
            "{markdown}"
        );
        assert_eq!(
            result,
            json!({"definitions": [{"name": "requirements.ready", "kind": "requirement"}], "sites": [
                {"name": "requirements.ready", "role": "cite", "file": "md/requirements.md", "item": null},
                {"name": "requirements.ready", "role": "test", "file": "src/lib.rs", "item": "fn[zeta]"},
                {"name": "requirements.ready", "role": "impl", "file": "src/lib.rs", "item": "fn[work]"},
            ]})
        );
        assert!(ready.inputs.is_empty());
        let implementations = dispatch(
            &sources,
            "references",
            &json!({"selection":"requirements.ready", "roles":["impl", "impl"]}),
        )
        .unwrap();
        assert_eq!(
            implementations.result,
            json!({"definitions":[{"name":"requirements.ready","kind":"requirement"}],
                "sites":[{"name":"requirements.ready","role":"impl","file":"src/lib.rs","item":"fn[work]"}]})
        );
        assert!(implementations.inputs.is_empty());
        let names = dispatch(
            &sources,
            "references",
            &json!({"selection":"requirements.ready", "roles":[]}),
        )
        .unwrap();
        assert_eq!(names.result["definitions"], ready.result["definitions"]);
        assert_eq!(names.result["sites"], json!([]));
        assert!(names.inputs.is_empty());
        assert_eq!(
            dispatch(&sources, "references", &json!({"roles":["impl"]}))
                .unwrap()
                .result,
            all.result
        );
        for roles in [json!(null), json!("impl"), json!(["fixme"]), json!([1])] {
            let error = dispatch(&sources, "references", &json!({"roles":roles}))
                .err()
                .unwrap();
            assert!(error.to_string().contains("role"), "{roles}: {error}");
        }

        let flattened = dispatch(
            &sources,
            "references",
            &json!({"selection": "requirements.*"}),
        )
        .unwrap();
        let sites = flattened.result["sites"].as_array().unwrap();
        assert_eq!(flattened.result["definitions"], all.result["definitions"]);
        assert_eq!(sites.len(), 4);
        assert_eq!(sites[0]["name"], "requirements.other");
        assert_eq!(sites[0]["item"], "fn[work]");
        assert!(flattened.inputs.is_empty());

        // A fenced reference in a comment run is a site of the node the run
        // belongs to; a `{fixme}` is not a site, nor is a fence that never
        // closes.
        fs::write(
            root.path().join("src/fenced.rs"),
            format!(
                "// :::{} requirements.other\n// Commentary.\n// :::\nfn fenced() {{}}\n\n// :::{} requirements.other\n// Tracked by example/queue#1.\n// :::\nfn gap() {{}}\n\n// :::{} requirements.other\n// never closed\n\nfn open() {{}}\n",
                "{impl}", "{fixme}", "{cite}"
            ),
        )
        .unwrap();
        let other = dispatch(
            &sources,
            "references",
            &json!({"selection": "requirements.other"}),
        )
        .unwrap();
        assert_eq!(
            other.result["sites"],
            json!([
                {"name": "requirements.other", "role": "impl", "file": "src/fenced.rs", "item": "fn[fenced]"},
                {"name": "requirements.other", "role": "cite", "file": "src/lib.rs", "item": "fn[work]"},
            ])
        );
        fs::remove_file(root.path().join("src/fenced.rs")).unwrap();

        for selection in ["requirements.missing", "requirements.word", "bad name", ""] {
            assert!(
                dispatch(&sources, "references", &json!({"selection": selection})).is_err(),
                "accepted {selection:?}"
            );
        }
        let error = dispatch(&sources, "references", &json!({"selection": 1}))
            .err()
            .unwrap();
        assert!(
            error.to_string().contains("selection must be a string"),
            "{error}"
        );
        assert!(
            dispatch(
                &sources,
                "references",
                &json!({"name": "requirements.ready"})
            )
            .is_err()
        );
    }
Input 7: outline src/authoring/tools.rs mod[tests]/fn[references_report_anchors_as_file_or_node_sites]
    // {test}`requirements.authoring.reference_index`
    // {test}`requirements.references.anchors`
    #[test]
    fn references_report_anchors_as_file_or_node_sites() {
        let root = project();
        fs::create_dir_all(root.path().join("skills")).unwrap();
        fs::write(root.path().join("skills/ready.md"), "# Skill\n").unwrap();
        fs::create_dir_all(root.path().join("private")).unwrap();
        fs::write(root.path().join("private/notes.md"), "hidden\n").unwrap();
        fs::write(
            root.path().join("md/requirements.md"),
            format!(
                ":::{{req}} ready\n:impl: skills/ready.md#section[Skill]\nThe project MUST be ready.\n:::\n\n:::{{example}} case\n:test: skills/ready.md\n:test: private/notes.md\nA ready case. {}\n:::\n",
                role("cite", "requirements.ready")
            ),
        )
        .unwrap();
        fs::write(
            root.path().join("habeas.toml"),
            "version = 1\n\n[evidence]\ndisallow = [\"private\"]\n",
        )
        .unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let result = dispatch(
            &sources,
            "references",
            &json!({"selection": "requirements.*"}),
        )
        .unwrap();
        let mut sites = result.result["sites"].clone();
        assert!(
            sites[1]["item"]
                .take()
                .as_str()
                .unwrap()
                .starts_with("section@")
        );
        assert_eq!(
            sites,
            json!([
                {"name": "requirements.case", "role": "test", "file": "skills/ready.md", "item": null},
                {"name": "requirements.ready", "role": "cite", "file": "md/requirements.md", "item": null},
                {"name": "requirements.ready", "role": "impl", "file": "skills/ready.md", "item": "section[Skill]"},
            ])
        );
        assert!(result.inputs.is_empty());
        let filtered = dispatch(
            &sources,
            "references",
            &json!({"selection":"requirements.*", "roles":["impl"]}),
        )
        .unwrap();
        assert_eq!(
            filtered.result["sites"],
            json!([{"name":"requirements.ready","role":"impl","file":"skills/ready.md","item":"section[Skill]"}])
        );
        assert!(filtered.inputs.is_empty());
    }
Input 8: outline src/authoring/tools.rs mod[tests]/fn[references_report_only_sites_in_considered_sources]
    // {test}`requirements.authoring.reference_index`
    // {test}`requirements.references.discovery`
    #[test]
    fn references_report_only_sites_in_considered_sources() {
        let root = project();
        let reference = format!(
            "// {}\nfn site() {{}}\n",
            role("impl", "requirements.ready")
        );
        for file in ["src/tracked.rs", "src/untracked.rs", "private/tracked.rs"] {
            let path = root.path().join(file);
            fs::create_dir_all(path.parent().unwrap()).unwrap();
            fs::write(path, &reference).unwrap();
        }
        fs::write(
            root.path().join("habeas.toml"),
            "version = 1\n\n[evidence]\ndisallow = [\"private\"]\n",
        )
        .unwrap();
        git(root.path(), &["init", "--quiet"]);
        git(root.path(), &["add", "."]);
        git(
            root.path(),
            &["rm", "--cached", "--quiet", "src/untracked.rs"],
        );
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        let result = dispatch(
            &sources,
            "references",
            &json!({"selection": "requirements.ready"}),
        )
        .unwrap();
        let files: Vec<_> = result.result["sites"]
            .as_array()
            .unwrap()
            .iter()
            .map(|site| site["file"].as_str().unwrap().to_owned())
            .collect();
        assert_eq!(files, ["src/tracked.rs"]);
    }
Input 9: outline src/authoring/tools.rs mod[tests]/fn[references_name_a_considered_source_that_cannot_be_read]
    // {test}`requirements.authoring.reference_index`
    #[cfg(unix)]
    #[test]
    fn references_name_a_considered_source_that_cannot_be_read() {
        use std::os::unix::fs::PermissionsExt;
        let root = project();
        let locked = root.path().join("src/locked.rs");
        fs::write(&locked, "fn locked() {}\n").unwrap();
        let sources = AssessmentSources::prepare(root.path(), "requirements.ready").unwrap();
        fs::set_permissions(&locked, fs::Permissions::from_mode(0o000)).unwrap();
        if fs::read(&locked).is_ok() {
            // Permissions do not restrict this user, such as root.
            return;
        }
        let error = dispatch(
            &sources,
            "references",
            &json!({"selection": "requirements.ready"}),
        )
        .err()
        .unwrap();
        fs::set_permissions(&locked, fs::Permissions::from_mode(0o644)).unwrap();
        let message = error.to_string();
        assert!(message.contains("src/locked.rs"), "{message}");
        assert!(
            message.contains("cannot read reference source"),
            "{message}"
        );
        assert!(message.contains("reference discovery failed"), "{message}");
    }
Input 10: outline src/authoring/tools.rs mod[tests]/fn[references_tool_is_advertised_with_an_optional_selection]
    // {test}`requirements.authoring.reference_index`
    // {test}`requirements.authoring.tool_descriptions.common_case`
    #[test]
    fn references_tool_is_advertised_with_an_optional_selection() {
        let definitions = definitions();
        let references = definitions
            .iter()
            .find(|definition| definition["name"] == "references")
            .expect("references tool is advertised");
        assert_eq!(
            references["parameters"],
            json!({
                "type": "object",
                "properties": {
                    "selection": {"type": "string"},
                    "roles": {"type":"array","items":{"type":"string","enum":["impl","cite","test"]},"default":["impl","cite","test"]}
                },
                "additionalProperties": false
            })
        );
        let description = references["description"].as_str().unwrap();
        for phrase in [
            "{impl}",
            "{cite}",
            "{test}",
            "glob",
            ":impl:",
            "null",
            "Without selection, return every requirement and named example name with its kind and empty sites",
            "a full name or a glob where * matches any characters including dots",
            "roles filters sites and anchors by impl, cite, or test (default all three)",
            "Locate definitions and reference sites without reading their text",
            "[] returns names/kinds only",
            "{impl} marks implementations, {cite} related sources, and {test} tests",
            r#"{"selection":"requirements.cli.status","roles":["impl"]}"#,
            "Request needed source with habeas",
        ] {
            assert!(description.contains(phrase), "{phrase}: {description}");
        }
    }
Input 11: outline tests/authoring_cli.rs fn[implementation_discovery_has_no_text_or_evidence_until_the_model_requests_a_read]
  • File: tests/authoring_cli.rs
  • Selector: fn[implementation_discovery_has_no_text_or_evidence_until_the_model_requests_a_read]
  • Kind: fn
  • tests/authoring_cli.rs:292–364
// {test}`requirements.authoring.mandatory_inputs`
// {test}`requirements.authoring.reference_index`
// {test}`requirements.authoring.delivered_inputs`
// {test}`requirements.authoring.fixme_inputs`
// {test}`requirements.authoring.complete_initial_bundle`
#[test]
fn implementation_discovery_has_no_text_or_evidence_until_the_model_requests_a_read() {
    let server = Server::start(vec![
        reply(vec![call(
            "locate",
            "references",
            json!({"selection": SUBJECT, "roles": ["impl"]}),
        )]),
        reply(vec![call(
            "read",
            "habeas",
            json!({"file": "src/lib.rs", "item": "fn[ready]"}),
        )]),
        reply(vec![call(
            "submit",
            "submit_judgment",
            json!({"determination": true, "rationale": "The tests check the requirement."}),
        )]),
    ]);
    let fixture = Fixture::new(&server.endpoint);
    let output = fixture.run(&["author", SUBJECT]);
    assert!(output.status.success(), "{output:?}");
    let requests = server.finish();
    assert_eq!(requests.len(), 3);
    let prompt = prompt_text(&requests[0].body);
    assert!(prompt.contains("fn ready_test()"));
    assert!(prompt.contains("One acknowledged gap."));
    assert!(!prompt.contains("pub fn ready()"));
    let tool_result = |request: &Request| -> Value {
        let message = request.body["messages"]
            .as_array()
            .unwrap()
            .iter()
            .rev()
            .find(|message| message["role"] == "tool")
            .unwrap();
        serde_json::from_str(message["content"].as_str().unwrap()).unwrap()
    };
    let locations = tool_result(&requests[1]);
    assert!(locations.to_string().contains("fn[ready]"), "{locations:#}");
    for text in [
        REQUIREMENT,
        "One acknowledged gap.",
        "pub fn ready()",
        "\"input\"",
        "\"inputs\"",
    ] {
        assert!(!locations.to_string().contains(text), "{locations:#}");
    }
    let read = tool_result(&requests[2]);
    assert!(read["input"]["text"].to_string().contains("pub fn ready()"));
    assert_eq!(read["input"]["file"], "src/lib.rs");
    assert_eq!(read["input"]["item"], "fn[ready]");
    assert_eq!(
        read["input"]["hash"],
        habeas::outline_input(&fixture.project, "src/lib.rs", "fn[ready]").unwrap()["hash"]
    );
    let record: Value = serde_json::from_slice(&fs::read(&fixture.evidence).unwrap()).unwrap();
    let inputs = record["inputs"].as_array().unwrap();
    assert_eq!(
        inputs
            .iter()
            .filter(|input| input["file"] == "src/lib.rs" && input["item"] == "fn[ready]")
            .count(),
        1
    );
    assert!(!fixture.usage()["inputs"].to_string().contains("references"));
}

Referenced definitions

Input 2: requirements selection requirements.references.discovery
:::{req} discovery
Habeas MUST find the references of {cite}`requirements.references.roles`
in project source files, where {cite}`requirements.references.reference_contexts`
says they count, and MUST fail with the source file and line if a
name has no matching `{req}` or `{example}` definition. In Markdown, escaped
roles and roles in code examples MUST remain literal. Reference discovery MUST
consider exactly the project sources that source-access policy permits under
{cite}`requirements.authoring.source_tools`: in a Git worktree, files present in
the Git index, including staged new files; outside Git, all project files; in
both cases excluding the project-root `book` and `evidence` directories, `.git`
and `target` directories at any depth, and paths disallowed by
{cite}`requirements.configuration.evidence_paths`. Evidence snapshots and
generated build output MUST therefore not be counted as source references.
:::
Input 3: requirements selection requirements.references.anchors
:::{req} anchors
A `{req}` declaration MAY list `:impl:` and `:test:` options, and an `{example}`
declaration MAY list `:test:` options, immediately after its opening fence and
before its body, one per option line, naming a project file path or
`path#selector` for one outline node under
{cite}`requirements.references.outline_selectors`. Each anchor MUST be an `{impl}` or `{test}` edge, under
{cite}`requirements.references.roles`, from the definition to the anchored file or
node, for files that cannot or should not carry a reference themselves.
Paths MUST follow the path rules in {cite}`requirements.ci.schema`. Option lines
MUST NOT form part of the definition's text for evidence comparison or for
requirements inputs, and MUST NOT render as body text.

For each `:test:` anchor, the harness MUST include the selected file or node's
source text in the initial model request under
{cite}`requirements.authoring.mandatory_inputs` and MUST record that selection
as an evidence input under {cite}`requirements.references.evidence_coverage`,
so changing that source makes the evidence stale.
A `:impl:` anchor alone MUST NOT require an input selecting its source. A path or selector that
does not resolve to a readable, permitted file or node MUST be a validation error naming the
definition and the path; authoring MUST report it before inference. Any other option line in a `{req}` or
`{example}` declaration MUST be a validation error.
:::
Input 4: requirements selection requirements.references.outline_comments
:::{req} outline_comments
Each documented profile defines which grammar nodes are comments; the Markdown
profile's comments are HTML comment blocks, so an inline HTML comment within a
paragraph is text of its section. In every supported language, comments on consecutive lines with no other source
between them MUST form one comment run. A comment that follows other source on
the same line, including another comment, MUST form a run by itself and MUST belong to the innermost outline node
containing that line. Any other run MUST belong to the next outline node that
starts after it within the smallest node containing it; when that container has
no such node, the run MUST belong to the container, which is the root node at top
level. A profile MAY bind a comment kind to its container
instead: such a run MUST belong to the smallest node containing it. The Rust
profile MUST bind inner doc comments (`//!`, `/*!`) to their container, so a
file-level inner doc comment belongs to the root node. A reference in a comment MUST count for the node its run belongs to under
{cite}`requirements.references.rust_item_coverage` and
{cite}`requirements.references.authoring_inputs`.
:::
Input 12: definition requirements.references.definition_selection
:::{definition} definition_selection
:phrase: definition selection

A full requirement or example name, or a definition glob, identifying the
requirements and named examples it matches under
{cite}`requirements.references.definition_globs`. A name without `*` selects
exactly that definition.
:::

Other sources

Input 1: requirements selection requirements.authoring.reference_index
:::{req} reference_index
The harness MUST expose a `references` tool with this interface:

```text
references({ selection: String?, roles: Array<"impl" | "cite" | "test">? }) -> ReferenceIndex

ReferenceIndex {
    definitions: Array<DefinitionName>,
    sites: Array<ReferenceSite>,
}

DefinitionName { name: String, kind: "requirement" | "example" }

ReferenceSite {
    name: String,
    role: "impl" | "cite" | "test",
    file: String,
    item: String?,
}
```

`selection` MUST be a {term}`requirements.references.definition_selection`.
Without `selection`, the tool MUST return
the full name and kind of every requirement and named example in full-name
order, with empty `sites`. With `selection`, it MUST return the selected definitions
in full-name order and one flattened `sites` array containing every valid
reference to any match whose role is in `roles`, defaulting to
`["impl", "cite", "test"]`, under
{cite}`requirements.references.discovery`, each naming the definition it
references, ordered by name, file, and position in the file, without line
numbers. Roles MUST be treated as a set: repeating a permitted role MUST NOT
duplicate sites or change the result.
An anchor under {cite}`requirements.references.anchors` whose role is selected
by `roles` MUST be
reported as a site for its anchored file, with the anchored node's selector as
`item` when it names one and no `item` when it names the whole file. Every
other site MUST give as `item` the selector of its smallest enclosing outline
node under {cite}`requirements.references.outline_comments`. Only sources reference discovery considers under
{cite}`requirements.references.discovery` MUST contribute sites. If reading such a
source fails, the tool MUST return an explanatory tool error naming the source.
An invalid selection or one matching no definition MUST return an explanatory tool
error.

An empty `roles` array MUST return no sites while preserving the selected
definitions' names and kinds. An unknown role or a value other than an array of
permitted role strings MUST return an explanatory tool error. Without `selection`,
`roles` MUST NOT change the definition-name listing.

Results MUST contain no requirement text, example text, reference commentary,
or source text. Like directory listings, they MUST
NOT become evidence inputs; the model requests the sources it relies on with the
`habeas` tool. For example,
`references({selection: "requirements.cli.status", roles: ["impl"]})` MUST
locate only that subject's implementation references and anchors, without
supplying their source or recording evidence inputs.
:::