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

Requirements index · View definition

evidence Valid

Requirement

The habeas-refactor skill MUST direct agents to make the move with their own edits, keeping it separate from any change to the moved code or text; to run habeas refactor --dry-run under cite requirements.refactor.dry_run with a mapping for every moved file, node, and definition name under cite requirements.refactor.mappings; to review its report, including records it would leave unchanged and the rationale spans it lists under cite requirements.refactor.rationale.untouched; to run it without --dry-run; to confirm with habeas status that only the reported records are stale; and to commit the move and evidence update before changing behavior, then reassess stale records with habeas author under the habeas-evidence skill.

Rationale

The habeas-refactor skill (assets/skills/habeas-refactor/SKILL.md) directs each obligation in its Workflow, and tests/authoring_cli.rs#fn[the_refactor_skill_moves_first_then_updates_evidence_with_habeas_refactor] checks them in order.

ObligationWhere the skill carries it out
Make the move with the agent’s own edits, kept separate from any change to the moved code or textStep 1 says “Make the move with your own edits … Change nothing else in this step” and to keep the moved text exactly as it was. Step 7 says to commit “before any change to behavior or text”. The Gotchas section repeats “Move first, run the command, commit, then edit.”
Run habeas refactor --dry-run with a mapping for every moved file, node, and definition nameStep 3 asks for one --map <old>=<new> for every moved file or directory, node, and definition name. It shows the three forms of requirements.refactor.mappings: path, file#selector, and definition name with its descendants.
Review the report, including records left unchanged and the rationale spans it listsStep 4 covers “Would rewrite”, “Would change” (records updated, with each code span in their rationales that still mentions an old path), and “Would leave … unchanged” (records a mapping affects that fail a check).
Run it without --dry-runStep 5.
Confirm with habeas status that only the reported records are staleStep 6.
Commit the move and evidence update before changing behaviorStep 7.
Then reassess stale records with habeas author under the habeas-evidence skillStep 8 says “Next, reassess what remains stale with habeas author --all, following the habeas-evidence skill”.

Test. The test uses assert_in_order on the bundled skill text. That text is whitespace-collapsed, so phrases that wrap across lines in the markdown still match. The asserted phrases follow the skill’s step order and correspond to each row above, including the unchanged-records and rationale-span review phrases. The test carries the {test} reference to the subject.

Unspecified behavior. Step 2 (stage the move in the Git index) and the --force hint in step 4 are extra advice. They support the required commands and add no behavior the requirement leaves out, so I did not count them as gaps. The requirement’s cited parts (requirements.refactor.dry_run, requirements.refactor.mappings, requirements.refactor.rationale.untouched) are reflected in the skill’s instructions.

I found no gaps.

Inputs

Implementation

Input 6: 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 5: outline tests/authoring_cli.rs fn[the_refactor_skill_moves_first_then_updates_evidence_with_habeas_refactor]
// {test}`requirements.cli.refactor_skill.workflow`
#[test]
fn the_refactor_skill_moves_first_then_updates_evidence_with_habeas_refactor() {
    assert_in_order(
        "habeas-refactor",
        &[
            "Make the move with your own edits",
            "Change nothing else in this step",
            "`habeas refactor --dry-run` with one `--map <old>=<new>` for every moved file or directory, node, and definition name",
            "Review the report",
            "lists the records it updates, with each code span in their rationales that still mentions an old path",
            "lists records a mapping affects that fail a check",
            "Run the same command without `--dry-run`",
            "`habeas status`. Only the records the report left unchanged",
            "Commit the move, the rewritten references, and the `evidence/` changes together, before any change to behavior or text",
            "Next, reassess what remains stale with `habeas author --all`, following the habeas-evidence skill",
        ],
    );
}

Referenced definitions

Input 2: requirements selection requirements.refactor.dry_run
:::{req} dry_run
With `--dry-run`, `habeas refactor` MUST report every change it would make,
in the same form as {cite}`requirements.refactor.command`, and MUST write
nothing.
:::
Input 3: requirements selection requirements.refactor.mappings
:::{req} mappings
Each `--map` MUST have one of these forms:

- a file or directory path, which maps that file, or every file under that
  directory, to the same relative path under the new side;
- `<file>#<selector>`, which maps one outline node, and its outline
  descendants, to the node at the new file and selector;
- a definition name, which maps that full name, and every full name beginning
  with it followed by `.`, to the same suffix under the new name.

A mapping whose old side names a recorded definition, or a prefix of one
followed by `.`, MUST be a definition-name mapping.
:::
Input 4: requirements selection requirements.refactor.rationale.untouched
:::{req} rationale.untouched
`habeas refactor` MUST NOT change rationale text other than the spans
{cite}`requirements.refactor.rationale.names`,
{cite}`requirements.refactor.rationale.paths`, and
{cite}`requirements.refactor.rationale.addresses` cover. For each changed
record, it MUST list the other code spans in the rationale that contain an old
side of a path or node mapping, so the user can review them.
:::

Other sources

Input 1: requirements selection requirements.cli.refactor_skill.workflow
:::{req} refactor_skill.workflow
The `habeas-refactor` skill MUST direct agents to make the move with their own
edits, keeping it separate from any change to the moved code or text; to run
`habeas refactor --dry-run` under {cite}`requirements.refactor.dry_run` with a
mapping for every moved file, node, and definition name under
{cite}`requirements.refactor.mappings`; to review its report, including
records it would leave unchanged and the rationale spans it lists under
{cite}`requirements.refactor.rationale.untouched`; to run it without
`--dry-run`; to confirm with `habeas status` that only the reported records
are stale; and to commit the move and evidence update before changing
behavior, then reassess stale records with `habeas author` under the
habeas-evidence skill.
:::