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.cli.bootstrap_skill

Requirements index · View definition

evidence Valid

Requirement

Habeas MUST bundle a skill for deriving initial requirements from an existing codebase. The skill MUST direct agents to read the code and tests, map every first-party test to at least one requirement or example, identify and map every source unit implementing end-user-visible functionality or interactions to a requirement, and report gaps rather than claim complete coverage without an independent inventory review.

Rationale

The requirement requirements.cli.bootstrap_skill is a content requirement on a bundled skill. It has one test, tests/authoring_cli.rs#fn[bootstrap_skill_is_bundled_and_directs_complete_inventories]. It checks the skill text through bundled_skill, assert_phrases and assert_text_in_order. These helpers read assets/skills/habeas-bootstrap-requirements/SKILL.md through skill_files, which uses include_str!. They panic with the missing phrase if it is absent.

Obligations and how the test covers them:

  • Bundle the skill. SKILLS.contains("habeas-bootstrap-requirements") is asserted, and the skill description must start with “Use when adopting Habeas in an existing codebase”. The same skill text is read via include_str!, so the file must exist in assets/skills. tests/authoring_cli.rs#fn[bundled_skills_are_five_skill_directories_each_home_to_its_topics] separately checks that assets/skills is published and that the skill directories match SKILLS. It is marked for requirements.cli.skill_structure, so it is context here and I did not reassess it.
  • Read the code and tests. The test asserts “Read the existing requirements, documentation, public entry points, implementation, and tests” and “Follow behavior through the code”. Both are present in workflow step 2 of the skill.
  • Map every first-party test to a requirement or example. The test asserts “every first-party runnable test or test case”, “Record the behavior each test checks…”, “Every test must end up with a {test} reference to a requirement or example”, and “Give every inventoried test and each requirement’s roots their references”. The Inventories and Tagging sections of the skill contain these phrases.
  • Identify and map every source unit that implements end-user-visible behavior. The test asserts “every function, method, struct, enum, and union, listed from the source rather than from the coverage warnings”. It also asserts the observable-surface list (“public APIs, commands, handlers, UI actions, configuration, outputs, errors, and distinct observable branches”) and “A tagged entry point doesn’t mean every observable branch beneath it has a requirement”.
  • Report gaps and do not claim completeness without an independent inventory review. assert_in_order checks this sequence in the skill: “recount both inventories from the source and tests without your lists”, then the gap-list report format, then “Claim 100% only when both inventories have no unmapped items”, then “Don’t silently exclude difficult cases”. I read the skill. These phrases sit in workflow step 8 and the Report section. The recount is a fresh-subagent step, and the 100% claim is conditioned on the independent recount agreeing.

For a requirement about the contents of a text asset, asserting these directive phrases is the appropriate check. I found no plausible way for the skill to violate the requirement while passing these assertions. Removing the tests-mapping, source-unit mapping, gap-reporting or independent-recount directive would each break a specific assertion. Reordering the recount, gap format and completeness condition would break the ordered check. I found no acknowledged gaps and no gaps of my own.

Inputs

Implementation

Input 4: outline assets/skills/habeas-bootstrap-requirements/SKILL.md (whole file)
---
name: habeas-bootstrap-requirements
description: Use when adopting Habeas in an existing codebase, when `habeas status --coverage` warns about uncovered items across most of a project's code, or when the user asks for a requirements coverage audit. Inventories tests, Rust items, and user-visible behavior; proposes an initial requirement set for the user's approval; tags every test and each requirement's root items; and drives `habeas author` and validation to full coverage. For a few uncovered items, use habeas-evidence.
---

# Bootstrap requirements

Habeas traces requirements, written in a project's mdBook, to the code and tests
that implement and verify them. Bootstrapping derives requirements from code
that already exists, so every requirement starts as a proposal: observed
behavior may be intended, a bug, or incidental.

Follow the habeas skill's "Testing and coverage artifacts": default to
`habeas coverage` for unit, integration and focused runs through `cargo nextest`;
run doctests separately with `cargo test --doc --workspace`, and never stage or
commit disposable coverage artifacts in the Cargo target directory.

## Workflow

Steps 1 to 3 run once. Repeat steps 4 to 7 for each area, such as one command
or module, then do steps 8 and 9. In a large codebase, give each area's reading
to a subagent to keep it out of your context.

- [ ] 1. Read the habeas skill for directive syntax, and the habeas-requirements
      skill: its steps 3 to 5 review, agree, and commit requirements, and its "Choosing
      references" and "What the review checks" sections govern tagging. Aim for
      accurate references, not a coverage number. If the project has no
      `tests/habeas.rs` calling `habeas::validate()`, Habeas is not set up: ask
      before running `habeas setup`. Before bootstrapping evidence, check coverage readiness with `habeas status`: the validation test also checks the saved `.config/nextest.toml` collector and default-profile rules. Use `habeas setup` to establish or repair the integration under the existing setup authorization. Report conflicting nextest settings for review; preserve project-specific settings. If a requirement already exists, confirm
      authoring works with `habeas author --stdout <full-name>`, which always
      assesses and writes no evidence. If it fails, read the habeas-evidence
      skill's `references/authoring-failures.md`.
- [ ] 2. Read the existing requirements, documentation, public entry points,
      implementation, and tests. Follow behavior through the code rather than
      relying on test names or top-level dispatch.
- [ ] 3. Build the inventories and the gap list (below).
- [ ] 4. Propose requirements for the area (below), reusing existing ones by
      full name and proposing any changes to their text. Write them as
      uncommitted edits to the area's chapter, one file per area, such as
      `md/requirements/cli.md` for `requirements.cli.*`; for a new chapter, add
      it to `SUMMARY.md` and `git add -N` it so reviewers see it.
- [ ] 5. Review, agree, and commit them through habeas-requirements steps 3 to
      5; a general request to bootstrap is not agreement to specific text.
      **Gate:** don't commit a requirement or tag code against it until the user
      agrees to its text. Remove drafts the user rejects, defers, or has not
      decided from the chapter, and keep them on the gap list.
- [ ] 6. Tag the area's tests and root items (below). In the first area, if step 1
      had no requirement to try, run `habeas author <full-name>` on one of the
      area's requirements to confirm authoring works before going on.
- [ ] 7. Validate and author the area:
      - [ ] a. Run `habeas coverage`, which makes no model calls, and fix
            the reference errors in this area's files. Leave uncovered items for
            now: assessments that read reached code cover them, and none have
            run yet. Items in areas not yet bootstrapped wait for their own
            pass; never give them placeholder references.
      - [ ] b. Tell the user how many definitions `habeas status` says need
            authoring.
      - [ ] c. Follow the habeas-evidence workflow for this area's definitions,
            running `habeas author <full-name>` for each, and
            `habeas author sites:<full-name>` for each distributed requirement,
            until each passes or is on the gap list with a reason. Citation
            reviews are authored only by `habeas author --all`, which also
            authors other areas' definitions: run it once the area's own
            definitions pass, then check that this area's items are covered.
            Full validation can pass only after the last area.
- [ ] 8. Have a fresh subagent recount both inventories from the source and tests
      without your lists, and reconcile any differences.
- [ ] 9. Run `habeas test` for full-workspace collection and post-suite coverage
      checking. Include remaining execution-coverage gaps in the report,
      separately from unmapped items and evidence findings. Recommend separate
      successful collection and `habeas coverage-check` steps in project CI,
      using the Habeas [CI example](../habeas/references/ci.md). Collection alone
      does not enforce the coverage policy. Report (below). Next: for gap-list items the user decides, follow the
      habeas-requirements skill.
      {impl}`requirements.test-coverage.check.guidance`

## Inventories

Keep the inventories and the gap list in the conversation or in a file outside
the repository; a staged file listing names in role syntax would add
references.

- **Tests:** every first-party runnable test or test case, including integration
  tests and parameterized cases. Record the behavior each test checks; fill in
  requirement names once they are installed.
- **Items and behavior:** in Rust projects, every function, method, struct,
  enum, and union, listed from the source rather than from the coverage
  warnings, since an assessment's read can cover an item whose
  behavior no requirement states. Add by hand the observable surface: public
  APIs, commands, handlers, UI actions, configuration, outputs, errors, and
  distinct observable branches. A tagged entry point doesn't mean every observable branch beneath
  it has a requirement.
- **Gap list:** each item or behavior you cannot yet map, with its location, the
  reason, and the open question.

Exclude third-party and checked-in generated code. Rust item coverage already
skips the project-root `vendor` directory; for any other such path, add it to
`[evidence] disallow` in `habeas.toml` with the user's agreement, which also
hides it from authoring.

## Proposing requirements

Write one requirement per obligation a user could rely on; the
habeas-requirements review (step 3) splits compound ones. For tests of internal
invariants, write a requirement for the invariant they check rather than
inventing a user-facing promise. Label each proposal and act on the label:

- **Intended:** state the observed behavior.
- **Possible bug:** ask the user what behavior is intended and write the
  requirement for that. Don't change the code during bootstrap unless the user
  asks; the resulting false judgment stays on the gap list, or gets a
  `{fixme}` reference if the user defers it (the habeas-evidence skill's
  `references/fixme.md`).
- **Incidental:** the user chooses between a requirement, often with MAY, and
  removing the behavior. For example, a command that also accepts an
  undocumented alias.

When a convention applies on its own at many sites, such as how every
validation function continues after a failed check, propose a distributed
requirement instead of marking each site `{impl}`; read the habeas skill's
`references/distributed-requirements.md`.

## Tagging

Give every inventoried test and each requirement's roots their references by
"Choosing references" in the habeas-requirements skill: `{test}` on tests and `{impl}`
on roots; code a root or test reaches needs none. Map each other inventoried
item to the requirement whose root reaches it. Every test must end up with a `{test}` reference to a requirement or example,
attached to the test as the habeas-requirements skill describes; a test whose behavior no agreed requirement states goes on the gap
list, never `habeas:util`. For a parameterized test, put the reference on the
case source or the generating declaration; one file-level tag must not stand in
for unrelated tests. Where one behavior follows from several requirements,
mark each with `{impl}` where it applies and explain how they combine, as the
habeas-requirements skill describes. An item that neither carries out a
requirement nor serves other code goes on the gap list: it needs a requirement
or is not needed.

## Report

```text
Tests mapped: <mapped>/<total>
Items mapped: <referenced or reached from a mapped root>/<total>  (covered only by reads: <count>)
Independent recount: <agrees | differences and how reconciled>
Gaps:
- <item or behavior> (<file>:<line>): <reason>; <open question>
```

Claim 100% only when both inventories have no unmapped items, the independent
recount agrees, and every observable branch has been reviewed. Don't silently
exclude difficult cases.

## Gotchas

- Never write evidence yourself or ask another agent to, even over a long
  session (habeas-evidence explains why).
- When assessments of the same subject disagree, follow "Disagreeing
  assessments" in the habeas-evidence skill.

Tests

Input 2: outline tests/authoring_cli.rs fn[bootstrap_skill_is_bundled_and_directs_complete_inventories]
// {test}`requirements.cli.bootstrap_skill`
#[test]
fn bootstrap_skill_is_bundled_and_directs_complete_inventories() {
    assert!(SKILLS.contains(&"habeas-bootstrap-requirements"));
    assert!(
        description("habeas-bootstrap-requirements")
            .starts_with("Use when adopting Habeas in an existing codebase"),
    );
    assert_phrases(
        "habeas-bootstrap-requirements",
        &[
            // Read the code and tests.
            "Read the existing requirements, documentation, public entry points, implementation, and tests",
            "Follow behavior through the code",
            // Map every first-party test.
            "every first-party runnable test or test case",
            "Record the behavior each test checks; fill in requirement names once they are installed",
            "Every test must end up with a `{test}` reference to a requirement or example",
            // Map every end-user-visible source unit.
            "every function, method, struct, enum, and union, listed from the source rather than from the coverage warnings",
            "public APIs, commands, handlers, UI actions, configuration, outputs, errors, and distinct observable branches",
            "A tagged entry point doesn't mean every observable branch beneath it has a requirement",
            "Give every inventoried test and each requirement's roots their references",
        ],
    );
    // Report gaps; no claim of completeness before an independent recount.
    assert_in_order(
        "habeas-bootstrap-requirements",
        &[
            "recount both inventories from the source and tests without your lists",
            "- <item or behavior> (<file>:<line>): <reason>; <open question>",
            "Claim 100% only when both inventories have no unmapped items",
            "Don't silently exclude difficult cases",
        ],
    );
}

Other sources

Input 1: requirements selection requirements.cli.bootstrap_skill
:::{req} bootstrap_skill
Habeas MUST bundle a skill for deriving initial requirements from an existing codebase. The skill MUST direct agents to read the code and tests, map every first-party test to at least one requirement or example, identify and map every source unit implementing end-user-visible functionality or interactions to a requirement, and report gaps rather than claim complete coverage without an independent inventory review.
:::
Input 3: outline tests/authoring_cli.rs fn[skill_files]
/// The files of a bundled skill, by path relative to its directory: its
/// `SKILL.md` first, then every file under its `references/` directory.
// {cite}`habeas:util`
fn skill_files(name: &str) -> &'static [(&'static str, &'static str)] {
    match name {
        "habeas" => &[
            ("SKILL.md", include_str!("../assets/skills/habeas/SKILL.md")),
            (
                "references/ci.md",
                include_str!("../assets/skills/habeas/references/ci.md"),
            ),
            (
                "references/distributed-requirements.md",
                include_str!("../assets/skills/habeas/references/distributed-requirements.md"),
            ),
            (
                "references/syntax-details.md",
                include_str!("../assets/skills/habeas/references/syntax-details.md"),
            ),
        ],
        "habeas-requirements" => &[
            (
                "SKILL.md",
                include_str!("../assets/skills/habeas-requirements/SKILL.md"),
            ),
            (
                "references/review-prompt.md",
                include_str!("../assets/skills/habeas-requirements/references/review-prompt.md"),
            ),
        ],
        "habeas-evidence" => &[
            (
                "SKILL.md",
                include_str!("../assets/skills/habeas-evidence/SKILL.md"),
            ),
            (
                "references/authoring-failures.md",
                include_str!("../assets/skills/habeas-evidence/references/authoring-failures.md"),
            ),
            (
                "references/fixme.md",
                include_str!("../assets/skills/habeas-evidence/references/fixme.md"),
            ),
            (
                "references/reviews.md",
                include_str!("../assets/skills/habeas-evidence/references/reviews.md"),
            ),
        ],
        "habeas-bootstrap-requirements" => &[(
            "SKILL.md",
            include_str!("../assets/skills/habeas-bootstrap-requirements/SKILL.md"),
        )],
        "habeas-refactor" => &[(
            "SKILL.md",
            include_str!("../assets/skills/habeas-refactor/SKILL.md"),
        )],
        _ => panic!("unknown skill {name}"),
    }
}
Input 5: outline tests/authoring_cli.rs fn[skill_md]
/// A bundled skill's raw `SKILL.md`.
// {cite}`habeas:util`
fn skill_md(name: &str) -> &'static str {
    skill_files(name)[0].1
}
Input 6: outline tests/authoring_cli.rs fn[bundled_skill]
/// A bundled skill: its `SKILL.md` together with its reference files,
/// collapsed.
// {cite}`habeas:util`
fn bundled_skill(name: &str) -> String {
    let files = skill_files(name)
        .iter()
        .map(|(_, text)| *text)
        .collect::<Vec<_>>();
    collapse(&files.join("\n"))
}
Input 7: outline tests/authoring_cli.rs fn[assert_text]
// {cite}`habeas:util`
fn assert_text(label: &str, text: &str, phrases: &[&str]) {
    for phrase in phrases {
        assert!(text.contains(phrase), "{label} lacks {phrase:?}");
    }
}
Input 8: outline tests/authoring_cli.rs fn[assert_text_in_order]
/// Asserts that the text contains each phrase, each after the previous one.
// {cite}`habeas:util`
fn assert_text_in_order(label: &str, text: &str, phrases: &[&str]) {
    let mut from = 0;
    for phrase in phrases {
        let at = text[from..]
            .find(phrase)
            .unwrap_or_else(|| panic!("{label} lacks {phrase:?} after byte {from}"));
        from += at + phrase.len();
    }
}
Input 9: outline tests/authoring_cli.rs fn[bundled_skills_are_five_skill_directories_each_home_to_its_topics]
// {test}`requirements.cli.skill_structure`
#[test]
fn bundled_skills_are_five_skill_directories_each_home_to_its_topics() {
    // Symposium publishes every skill under assets/skills.
    let manifest: toml::Value =
        toml::from_str(include_str!("../Cargo.toml")).expect("Cargo.toml parses");
    let published = manifest["package"]["metadata"]["symposium"]["skills"]
        .as_array()
        .unwrap();
    assert!(
        published
            .iter()
            .any(|skill| skill["source"]["path"].as_str() == Some("assets/skills")),
        "{published:?}"
    );
    // A skill is its SKILL.md and the files under its references/ directory;
    // the files these tests read are exactly those.
    let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("assets/skills");
    let mut dirs = fs::read_dir(&root)
        .unwrap()
        .map(|entry| entry.unwrap().file_name().into_string().unwrap())
        .collect::<Vec<_>>();
    dirs.sort();
    let mut expected = SKILLS.map(String::from).to_vec();
    expected.sort();
    assert_eq!(dirs, expected);
    for name in SKILLS {
        assert!(
            skill_md(name).starts_with(&format!("---\nname: {name}\ndescription: ")),
            "{name} front matter"
        );
        let mut on_disk = vec!["SKILL.md".to_owned()];
        if let Ok(entries) = fs::read_dir(root.join(name).join("references")) {
            for entry in entries {
                let file = entry.unwrap().file_name().into_string().unwrap();
                on_disk.push(format!("references/{file}"));
            }
        }
        on_disk.sort();
        let mut listed = skill_files(name)
            .iter()
            .map(|(path, _)| path.to_string())
            .collect::<Vec<_>>();
        listed.sort();
        assert_eq!(on_disk, listed, "{name}");
    }
    // Each topic is stated in full in exactly one skill.
    for home in SKILLS {
        assert_home(home);
    }
}