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

Requirements index · View definition

evidence Valid

Requirement

Habeas MUST bundle a habeas-refactor skill whose description tells agents to use it when a change moves code, tests, or requirements to another file, chapter, or outline node, including splitting or merging modules or chapters, or renames a requirement, so that evidence whose content is unchanged is not invalidated.

Rationale

The requirement has no gap.

Bundling. assets/skills/habeas-refactor/SKILL.md exists and is the requirement’s :impl: anchor in md/requirements/cli.md. It sits under assets/skills, the skills source path in Cargo.toml (package.metadata.symposium.skills), so it is bundled with the other skills.

Description content. The front-matter description of habeas-refactor covers each part of the requirement:

  • “Use when a change moves code, tests, or requirements in a Habeas project to another file, chapter, or outline node” matches the move trigger.
  • “splitting or merging modules or chapters” matches the splitting and merging clause.
  • “moving or renaming a requirement” matches the rename clause.
  • “so that evidence whose content is unchanged is not invalidated” matches the purpose.

Tests. The test the_refactor_skill_is_used_for_moves_and_requirement_renames in tests/authoring_cli.rs carries {test} for requirements.cli.refactor_skill. It reads the skill’s description through the description helper and asserts that all four phrases above are present. The test shows the skill is bundled, because the helper fails if the skill or its description is missing.

Unspecified behavior. The description also adds “Covers making the move and running habeas refactor…” and “Not for changing what code or requirements say; use habeas-requirements”. Both stay within the skill’s purpose and are not extra observable behavior.

Inputs

Implementation

Input 3: outline assets/skills/habeas-refactor/SKILL.md (whole file)
---
name: habeas-refactor
description: Use when a change moves code, tests, or requirements in a Habeas project to another file, chapter, or outline node, such as moving a function to another module, renaming or splitting a file, splitting or merging modules or chapters, or moving or renaming a requirement, so that evidence whose content is unchanged is not invalidated. Covers making the move and running `habeas refactor` to update evidence, references, and anchors. Not for changing what code or requirements say; use habeas-requirements.
---

# Habeas refactor

Evidence records where it read code and requirements: files, outline selectors
such as `fn[load]`, and full definition names. A move changes those addresses
without changing what was reviewed. `habeas refactor` rewrites the addresses,
so the evidence stays current without a model reassessing it.

## Workflow

Run commands from the project root, the directory with `book.toml` and
`Cargo.toml`.

- [ ] 1. Make the move with your own edits: move the file, cut and paste the
      function, or move the `{req}` directive to its new chapter. Change
      nothing else in this step. Keep the moved code's text, including doc
      comments, and the moved requirement's text exactly as they were. Leave
      `{impl}`, `{test}`, `{cite}`, `{fixme}`, and `{term}` references to a
      moved definition, and `:impl:` and `:test:` anchors to a moved file,
      as they are; the command rewrites them.
- [ ] 2. Record the move in the Git index: `git mv` for a moved file, or
      `git add -A` on both the old and new paths. Reference discovery reads
      only files in the Git index, so a stale old path still counts.
- [ ] 3. `habeas refactor --dry-run` with one `--map <old>=<new>` for every
      moved file or directory, node, and definition name:
      - a file or directory: `--map src/config.rs=src/settings.rs`, which also
        covers every file under a directory;
      - a node: `--map 'src/config.rs#fn[load]=src/config/load.rs#fn[load]'`,
        which also covers the nodes inside it (quote it for the shell);
      - a definition: `--map requirements.cli.check=requirements.core.check`,
        which also covers the names beneath it, such as
        `requirements.cli.check.case`.

      To find a node's selector, `habeas info <name>` lists the inputs of a
      requirement that reads it.
- [ ] 4. Review the report:
      - "Would rewrite" lists the sources whose references or anchors change;
      - "Would change" lists the records it updates, with each code span in
        their rationales that still mentions an old path. The command leaves
        rationale prose alone; show these spans to the user, and if they ask
        for a record to be reassessed, run `habeas author --force <full-name>`
        after step 7;
      - "Would leave ... unchanged" lists records a mapping affects that fail a
        check, with the reason. An unexpected one usually means the moved text
        changed, or a mapping is missing; fix that and run the dry run again.
- [ ] 5. Run the same command without `--dry-run`.
- [ ] 6. `habeas status`. Only the records the report left unchanged, and any
      that were stale before, should need attention.
- [ ] 7. Commit the move, the rewritten references, and the `evidence/` changes
      together, before any change to behavior or text.
- [ ] 8. Next, reassess what remains stale with `habeas author --all`,
      following the habeas-evidence skill, and if assessments disagree, its
      "Disagreeing assessments"; then make any behavior or text changes as separate commits under
      the habeas-requirements skill.

## Gotchas

- Never edit evidence files by hand to follow a move; `habeas refactor` updates
  them only where it can check that nothing reviewed changed.
- A rename is not a move. Renaming a function, type, or other item changes its
  code, and so its structural hash: its evidence needs reassessment with
  habeas-evidence. Renaming a requirement's ID is a definition mapping, and
  works when its text is otherwise unchanged.
- Editing moved code or text in the same step leaves every record that read it
  stale. Move first, run the command, commit, then edit.
- A requirements input that selects a glob, such as `requirements.cli.*`, stays
  stale when a definition moves out of it or into it: what it matches changed.

Tests

Input 2: outline tests/authoring_cli.rs fn[the_refactor_skill_is_used_for_moves_and_requirement_renames]
// {test}`requirements.cli.refactor_skill`
#[test]
fn the_refactor_skill_is_used_for_moves_and_requirement_renames() {
    let description = description("habeas-refactor");
    for phrase in [
        "Use when a change moves code, tests, or requirements in a Habeas project to another file, chapter, or outline node",
        "splitting or merging modules or chapters",
        "moving or renaming a requirement",
        "so that evidence whose content is unchanged is not invalidated",
    ] {
        assert!(description.contains(phrase), "{phrase}");
    }
}

Other sources

Input 1: requirements selection requirements.cli.refactor_skill
:::{req} refactor_skill
Habeas MUST bundle a `habeas-refactor` skill whose description tells agents to
use it when a change moves code, tests, or requirements to another file,
chapter, or outline node, including splitting or merging modules or chapters,
or renames a requirement, so that evidence whose content is unchanged is not
invalidated.
:::
Input 4: outline tests/authoring_cli.rs fn[description]
/// A bundled skill's front-matter description.
// {cite}`habeas:util`
fn description(name: &str) -> &'static str {
    skill_md(name)
        .lines()
        .find_map(|line| line.strip_prefix("description: "))
        .unwrap_or_else(|| panic!("{name} has no description"))
}