plan: 0100 rename the stage1-* family to the r-family

Five ordered tasks: aura-cli source + include_str-coupled fixtures, the
cli_run suite, engine e2e git-mvs + doc-refs, dead-ordinal prose across
rustdoc/CLAUDE.md/glossary/ledger live lines, and a workspace grep gate.
Substitutions are ordered longest-token-first; every task carries its own
verification gate.

refs #174
This commit is contained in:
2026-07-02 10:49:55 +02:00
parent f029c35374
commit e1b04439c0
@@ -0,0 +1,411 @@
# Rename the stage1-* family to the r-family — Implementation Plan
> **Parent spec:** `docs/specs/0100-rename-stage1-family-to-r-family.md`
>
> **For agentic workers:** REQUIRED SUB-SKILL: use the
> `implement` skill to run this plan. Steps use `- [ ]`
> checkboxes for tracking.
**Goal:** Eliminate the dead `stage1`/`stage2` ordinal from every live
identifier and user-facing string, renaming the family to `r-sma` /
`r-breakout` / `r-meanrev` per the spec's normative token mapping.
**Architecture:** A vocabulary-only rename in five ordered surfaces: (1) the
aura-cli binary + its persisted-identity fixtures (one compilation unit — the
test block `include_str!`s the fixtures, so file renames and source renames
are inseparable), (2) the cli_run integration suite, (3) the engine e2e files
+ doc-references, (4) dead-ordinal prose across docs and rustdoc, (5) a
workspace-wide verification with a grep gate. Substitutions are ORDERED —
longest/most-specific token first — because several old tokens are substrings
of each other (`Stage1RGrid``Stage1R`; `STAGE1_R_SMA_FAST``STAGE1_R_`;
`wrap_stage1r``stage1r`).
**Tech Stack:** Rust workspace (cargo), sed for mechanical substitution, git mv
for file renames, two `#[ignore]` fixture-regenerator tests.
---
**Files this plan creates or modifies:**
- Modify: `crates/aura-cli/src/main.rs` (276 hits: enums :1523-1525/:3601,
Display :1556-1558, parse :4021/:4126-4128, `Stage1RGrid` :1069, fns
:1049/:1117/:1131/:1241/:1254/:1359/:1425/:2494/:2517/:2583/:2613/:2794/:3268/:3368/:3480,
consts :2447-2464, usage/help strings
:1604/:3805/:3830-3834/:3842/:3893/:3935/:3938/:4012/:4040-4041/:4067/:4346/:4424/:4503,
test block :5390-5912 incl. regenerators :5783/:5793 and `include_str!`
:5487/:5494/:5501, prose banners :2046/:2445/:2512/:2561/:2606/:2789/:3358)
- Rename: `crates/aura-cli/tests/fixtures/stage1_signal.json``sma_signal.json` (then regenerated)
- Rename: `crates/aura-cli/tests/fixtures/stage1_signal_open.json``sma_signal_open.json` (then regenerated)
- Modify: `crates/aura-cli/tests/fixtures/unknown_node.json` (hand-edit `"name"`)
- Modify: `crates/aura-cli/tests/cli_run.rs` (227 hits: selector literals, axis
keys, test fn names, goldens incl. list-axes :3848, temp-cwd literals, prose :3001)
- Rename: `crates/aura-engine/tests/stage1_r_e2e.rs``r_sma_e2e.rs` (content hits :1/:97/:127)
- Rename: `crates/aura-engine/tests/stage1_breakout_e2e.rs``r_breakout_e2e.rs` (body token-free)
- Rename: `crates/aura-engine/tests/stage1_meanrev_e2e.rs``r_meanrev_e2e.rs` (doc-ref :6)
- Modify: `crates/aura-engine/tests/streaming_reduction_equivalence.rs:2` (doc-ref)
- Modify: `crates/aura-cli/tests/graph_construct.rs:237` (doc-ref)
- Modify: `crates/aura-std/src/sizer.rs:1-8`, `crates/aura-std/src/position_management.rs:1,:149,:160,:278`
- Modify: `crates/aura-analysis/src/lib.rs:74,:82,:132,:327,:378,:1111`
- Modify: `crates/aura-composites/src/lib.rs:1,:38`, `crates/aura-composites/tests/risk_executor.rs:1,:5,:17,:103,:130,:151,:249`
- Modify: `crates/aura-cli/Cargo.toml:15-16`, `crates/aura-engine/Cargo.toml:25`
- Modify: `CLAUDE.md:98-99,:106`
- Modify: `docs/glossary.md:96,:252`
- Modify: `docs/design/INDEX.md` live lines only (:740, :931, :932, :940, :943,
:957, :958, :1330, :1890, :1898-1959); history sections (:297, :617, :672-906) untouched
- NOT touched (survivors): `crates/aura-engine/src/harness.rs:1898`,
`fieldtests/**`, `docs/specs/fieldtest-milestone-world-c21-blueprint-data-families.md`,
ledger history sections, the glossary "Stage 1 / Stage 2" entry heading/body
(only its :252 tail clause and the :96 forward-reference are edited)
---
### Task 1: aura-cli source + persisted-identity fixtures
The binary source and the fixture files are one unit: the test block
`include_str!`s the fixtures (main.rs :5487/:5494/:5501), so the path rename
and the file rename must land together or the crate does not compile.
**Files:**
- Modify: `crates/aura-cli/src/main.rs`
- Rename + regenerate: `crates/aura-cli/tests/fixtures/stage1_signal.json`, `stage1_signal_open.json`
- Modify: `crates/aura-cli/tests/fixtures/unknown_node.json`
- [ ] **Step 1: Ordered identifier/const/type substitutions in main.rs**
Run (exactly this order — earlier patterns are supersets of later ones):
```bash
cd /home/brummel/dev/aura
sed -i 's/STAGE1_R_SMA_FAST/R_SMA_FAST/g;
s/STAGE1_R_SMA_SLOW/R_SMA_SLOW/g' crates/aura-cli/src/main.rs
sed -i 's/STAGE1_R_/R_SMA_/g' crates/aura-cli/src/main.rs
sed -i 's/Stage1RGrid/RGrid/g' crates/aura-cli/src/main.rs
sed -i 's/Stage1R/RSma/g;
s/Stage1Breakout/RBreakout/g;
s/Stage1MeanRev/RMeanRev/g' crates/aura-cli/src/main.rs
sed -i 's/wrap_stage1r/wrap_r/g;
s/run_signal_stage1r/run_signal_r/g' crates/aura-cli/src/main.rs
sed -i 's/stage1_signal/sma_signal/g' crates/aura-cli/src/main.rs
sed -i 's/stage1_r/r_sma/g;
s/stage1_breakout/r_breakout/g;
s/stage1_meanrev/r_meanrev/g' crates/aura-cli/src/main.rs
sed -i 's/stage1-r/r-sma/g;
s/stage1-breakout/r-breakout/g;
s/stage1-meanrev/r-meanrev/g' crates/aura-cli/src/main.rs
```
(`s/stage1_r/r_sma/g` intentionally also converts `run_stage1_r`
`run_r_sma` and doc-mentions of `stage1_r_e2e.rs``r_sma_e2e.rs`.)
- [ ] **Step 2: Prose-form ordinal substitutions in main.rs**
The 7 prose lines the token rules miss (verified exhaustive by
`git grep -inE 'stage[- ]1|stage[- ]2' crates/aura-cli/src/main.rs | grep -ivE 'stage1[-_r]|stage1r'`):
```bash
sed -i 's/Stage-1 R harness/r-sma harness/g;
s/The Stage-1 signal leg/The r-sma signal leg/;
s/Wrap a Stage-1 `signal` composite/Wrap a `signal` composite/;
s/in the Stage-1 R run/in the R run/;
s/Stage-1-R scaffolding/R scaffolding/;
s/The Stage-1 EWMA/The EWMA/;
s/Stage-1 (no costs)/gross R (no costs)/' crates/aura-cli/src/main.rs
```
(`Stage-1 R harness` covers both :2445 and :2561.)
- [ ] **Step 3: Verify main.rs is ordinal-free**
Run: `git grep -icE 'stage[- ]?1|stage[- ]?2' -- crates/aura-cli/src/main.rs || echo CLEAN`
Expected: `CLEAN` (zero matching lines; non-zero output = a missed site, fix
it with the mapping table in the spec before proceeding)
- [ ] **Step 4: git mv the two regenerable fixtures**
```bash
git mv crates/aura-cli/tests/fixtures/stage1_signal.json crates/aura-cli/tests/fixtures/sma_signal.json
git mv crates/aura-cli/tests/fixtures/stage1_signal_open.json crates/aura-cli/tests/fixtures/sma_signal_open.json
```
(Contents are stale — still naming `stage1_signal` inside — until Step 6
regenerates them; the mv keeps the renamed `include_str!` paths resolving.)
- [ ] **Step 5: Build gate**
Run: `cargo build -p aura-cli`
Expected: 0 errors (warnings about nothing; a compile error here means an
`include_str!` path and a fixture name diverged — recheck Steps 1+4)
- [ ] **Step 6: Regenerate the two fixtures with the renamed composite**
Run: `cargo test -p aura-cli --bin aura -- --ignored emit_demo_signal`
Expected: `test result: ok. 2 passed` (fns `emit_demo_signal_fixture` :5783,
`emit_demo_signal_open_fixture` :5793 — they rewrite both JSONs, which now
serialize `"sma_signal"`)
- [ ] **Step 7: Hand-edit the regenerator-less fixture**
Run: `sed -i 's/stage1_signal/sma_signal/g' crates/aura-cli/tests/fixtures/unknown_node.json`
(unknown_node.json is hand-authored — no regenerator exists; it pins the
unknown-node rejection, the name is incidental identity.)
- [ ] **Step 8: Verify fixtures are ordinal-free and regenerated**
Run: `grep -rc 'stage1' crates/aura-cli/tests/fixtures/ || echo CLEAN`
Expected: `CLEAN`
Run: `grep -l 'sma_signal' crates/aura-cli/tests/fixtures/*.json`
Expected: all three JSONs listed
- [ ] **Step 9: Unit-test gate (bin target only — cli_run is Task 2's gate)**
Run: `cargo test -p aura-cli --bin aura`
Expected: PASS, 0 failed (the fixture-roundtrip unit tests recompile against
the regenerated bytes)
### Task 2: cli_run integration suite
**Files:**
- Modify: `crates/aura-cli/tests/cli_run.rs`
- [ ] **Step 1: Ordered substitutions in cli_run.rs**
```bash
sed -i 's/stage1_signal/sma_signal/g' crates/aura-cli/tests/cli_run.rs
sed -i 's/stage1_r/r_sma/g;
s/stage1_breakout/r_breakout/g;
s/stage1_meanrev/r_meanrev/g' crates/aura-cli/tests/cli_run.rs
sed -i 's/stage1-r/r-sma/g;
s/stage1-breakout/r-breakout/g;
s/stage1-meanrev/r-meanrev/g' crates/aura-cli/tests/cli_run.rs
sed -i 's/wf-stage1r/wf-r-sma/g;
s/mc_stage1r_boot/mc_r_sma_boot/g;
s/mc_stage1r_block/mc_r_sma_block/g;
s/mc_stage1r_clamp/mc_r_sma_clamp/g' crates/aura-cli/tests/cli_run.rs
sed -i 's/stage1r/r_sma/g' crates/aura-cli/tests/cli_run.rs
sed -i 's/Frictionless Stage-1/Frictionless gross R/' crates/aura-cli/tests/cli_run.rs
```
(The 5th command converts the remaining `stage1r` in fn names — e.g.
`generalize_refuses_a_non_stage1r_strategy``..._non_r_sma_strategy` — and
must run AFTER the temp-cwd literal command. Fixture paths `stage1_signal.json`
etc. are covered by the first command. The goldens' numeric bytes are NOT
touched — only rename substrings inside expectation strings change, per the
spec's byte-discipline.)
- [ ] **Step 2: Verify cli_run.rs is ordinal-free**
Run: `git grep -icE 'stage[- ]?1|stage[- ]?2' -- crates/aura-cli/tests/cli_run.rs || echo CLEAN`
Expected: `CLEAN`
- [ ] **Step 3: Integration gate**
Run: `cargo test -p aura-cli --test cli_run`
Expected: PASS, 0 failed. This is the load-bearing gate of the whole rename:
selector goldens (`single_run_output_golden`), net-R cost goldens
(`flat_cost_net_expectancy_r_golden`), dual-yardstick
(`carries_both_pip_and_r_yardsticks`), the list-axes byte-golden (now
`sma_signal.fast.length:I64\nsma_signal.slow.length:I64`), sweep/mc/
walkforward/generalize families, and the fixture-loading blueprint tests all
run the real binary end-to-end. A failure whose diff shows anything but a
renamed token is a STOP: report, do not improvise.
- [ ] **Step 4: graph_construct gate (fixture consumers outside cli_run)**
Run: `cargo test -p aura-cli --test graph_construct`
Expected: PASS, 0 failed (op-script vs builder content-id comparisons shift on
BOTH sides with the composite rename, so equality assertions hold)
### Task 3: engine e2e files + doc-references
**Files:**
- Rename: `crates/aura-engine/tests/stage1_r_e2e.rs``r_sma_e2e.rs`
- Rename: `crates/aura-engine/tests/stage1_breakout_e2e.rs``r_breakout_e2e.rs`
- Rename: `crates/aura-engine/tests/stage1_meanrev_e2e.rs``r_meanrev_e2e.rs`
- Modify: `crates/aura-engine/tests/streaming_reduction_equivalence.rs:2`
- Modify: `crates/aura-cli/tests/graph_construct.rs:237`
- [ ] **Step 1: git mv + content substitutions**
```bash
git mv crates/aura-engine/tests/stage1_r_e2e.rs crates/aura-engine/tests/r_sma_e2e.rs
git mv crates/aura-engine/tests/stage1_breakout_e2e.rs crates/aura-engine/tests/r_breakout_e2e.rs
git mv crates/aura-engine/tests/stage1_meanrev_e2e.rs crates/aura-engine/tests/r_meanrev_e2e.rs
sed -i 's/stage1_r/r_sma/g; s/stage1-r/r-sma/g' crates/aura-engine/tests/r_sma_e2e.rs
sed -i 's/stage1_breakout_e2e/r_breakout_e2e/' crates/aura-engine/tests/r_meanrev_e2e.rs
sed -i 's/stage1_r_e2e/r_sma_e2e/' crates/aura-engine/tests/streaming_reduction_equivalence.rs
sed -i 's/stage1_signal/sma_signal/' crates/aura-cli/tests/graph_construct.rs
```
- [ ] **Step 2: Verify the five files are ordinal-free**
Run: `git grep -icE 'stage[- ]?1|stage[- ]?2' -- crates/aura-engine/tests/ crates/aura-cli/tests/graph_construct.rs || echo CLEAN`
Expected: `CLEAN`
- [ ] **Step 3: e2e gates (one target per invocation)**
Run: `cargo test -p aura-engine --test r_sma_e2e`
Expected: PASS (e.g. `clean_stop_folds_to_exactly_minus_one_r`,
`net_r_equity_final_sample_agrees`)
Run: `cargo test -p aura-engine --test r_breakout_e2e`
Expected: PASS (e.g. `breakout_is_causal_and_holds_pm1_direction`)
Run: `cargo test -p aura-engine --test r_meanrev_e2e`
Expected: PASS (e.g. `meanrev_fades_against_the_move_and_holds_the_latch`)
Run: `cargo test -p aura-engine --test streaming_reduction_equivalence`
Expected: PASS
### Task 4: dead-ordinal prose across rustdoc, Cargo.tomls, CLAUDE.md, glossary, ledger
**Files:**
- Modify: `crates/aura-std/src/sizer.rs`, `crates/aura-std/src/position_management.rs`,
`crates/aura-analysis/src/lib.rs`, `crates/aura-composites/src/lib.rs`,
`crates/aura-composites/tests/risk_executor.rs`, `crates/aura-cli/Cargo.toml`,
`crates/aura-engine/Cargo.toml`, `CLAUDE.md`, `docs/glossary.md`, `docs/design/INDEX.md`
- [ ] **Step 1: sizer.rs — replace the module note (lines 1-8) verbatim**
Old (exact current bytes, lines 1-8):
```rust
//! `Sizer` — the flat-1R sizing seam (C10 Stage-1). Turns a protective-stop distance
//! into a position `size = risk_budget / stop_distance`: with `risk_budget = 1.0` this is
//! true flat-1R (one risk unit per trade) and `size` is inversely proportional to the
//! stop — NOT a constant. The `bias` input gates firing (a size is only meaningful when a
//! strategy is taking a position) and is the Stage-2 seam: fixed-fractional sizing swaps
//! `risk_budget` for `risk_fraction · equity` (an added equity input), same node shape.
//! R is computed SIZE-INVARIANTLY downstream, so the Sizer never contaminates signal
//! quality — it only scales the (Stage-2) currency exposure.
```
New:
```rust
//! `Sizer` — the flat-1R sizing seam (C10). Turns a protective-stop distance
//! into a position `size = risk_budget / stop_distance`: with `risk_budget = 1.0` this is
//! true flat-1R (one risk unit per trade) and `size` is inversely proportional to the
//! stop — NOT a constant. The `bias` input gates firing (a size is only meaningful when a
//! strategy is taking a position) and is the live/deploy-edge seam: fixed-fractional
//! sizing swaps `risk_budget` for `risk_fraction · equity` (an added equity input), same
//! node shape. R is computed SIZE-INVARIANTLY downstream, so the Sizer never contaminates
//! signal quality — it only scales the (deploy-edge) currency exposure.
```
- [ ] **Step 2: remaining rustdoc/comment sites — exact substitutions**
```bash
sed -i 's/Optional Stage-1 R metrics block\./Optional R metrics block./;
s/R-based signal-quality metrics (Stage-1), reduced/R-based signal-quality metrics, reduced/;
s/stage1_r_e2e\.rs/r_sma_e2e.rs/;
s/the Stage-1 cost = 0 invariant/the cost = 0 invariant/;
s/(Stage-1 frictionless)/(frictionless)/;
s/(frictionless Stage-1)/(frictionless)/' crates/aura-analysis/src/lib.rs
sed -i 's/reusable Stage-1 composite-builders/reusable composite-builders for the feed-forward R loop/;
s/stage1_r_graph/r_sma_graph/' crates/aura-composites/src/lib.rs
sed -i 's/the stateful heart of Stage-1 risk-based execution/the stateful heart of feed-forward risk-based execution/;
s/(Stage-1 feed-forward)/(feed-forward)/g;
s/the property that keeps Stage 1/the property that keeps the research loop/' crates/aura-std/src/position_management.rs
sed -i 's/(Stage-1, #128)/(#128)/;
s/(Stage-1 feed-forward)/(feed-forward)/g;
s/stage1_r_e2e\.rs/r_sma_e2e.rs/;
s/the Stage-1 on-disk back-compat contract/the on-disk back-compat contract/;
s/stage1-r/r-sma/g' crates/aura-composites/tests/risk_executor.rs
sed -i 's/the Stage-1 RiskExecutor/the RiskExecutor/;
s/stage1-r harness/r-sma harness/' crates/aura-cli/Cargo.toml
sed -i 's/stage1_r_e2e/r_sma_e2e/' crates/aura-engine/Cargo.toml
```
- [ ] **Step 3: CLAUDE.md invariant 7 — two exact replacements**
Old (lines 98-99):
```text
instrument-agnostic yardstick — **Stage 1**: flat-1R sizing, feed-forward, no
equity feedback, the primary research loop. **Currency P&L is Stage 2** (deploy
```
New:
```text
instrument-agnostic yardstick — the **research loop**: flat-1R sizing,
feed-forward, no equity feedback. **Currency P&L is the live/deploy edge** (deploy
```
Old (line 106): `` position_id, instrument_id, volume`) remains the **decoupled, derived** Stage-2 ``
New: `` position_id, instrument_id, volume`) remains the **decoupled, derived** deploy-edge ``
- [ ] **Step 4: glossary — record the rename (record-reality write)**
Line 96, old clause: `… persist in pre-reframe code until the Stage-1 rename.`
New: `… persisted in pre-reframe code until the r-family rename (#174).`
Line 252, old tail: `**"Stage-1"** now survives only as a historical cycle / identifier name for the shipped feed-forward R chain, not one half of a two-stage gate.`
New: `**"Stage-1"** now survives only as a historical cycle name — the shipped feed-forward R chain's identifier family was renamed to the r-family (`r-sma` / `r-breakout` / `r-meanrev`, #174) — not one half of a two-stage gate.`
(The entry heading `### Stage 1 / Stage 2` and the rest of the entry stay: it
IS the historical record the spec's acceptance permits.)
- [ ] **Step 5: ledger INDEX.md — live lines only**
Apply to `docs/design/INDEX.md` ONLY on the live lines
(:740, :931, :932, :940, :943, :957, :958, :1330, :1890, :1898-1959 — every
hit OUTSIDE the history sections :297, :617, :672-906):
```bash
sed -i '907,$ s/stage1_r_sweep_family/r_sma_sweep_family/g;
907,$ s/stage1_r_graph/r_sma_graph/g;
907,$ s/run_stage1_r/run_r_sma/g;
907,$ s/wrap_stage1r/wrap_r/g;
907,$ s/stage1-r/r-sma/g;
907,$ s/Stage-1-R scaffolding/r-sma scaffolding/;
907,$ s/Stage-1-R run/r-sma run/;
907,$ s/Stage-1 sweep family/r-sma sweep family/' docs/design/INDEX.md
sed -i '700,760 s/stage1_r_graph/r_sma_graph/g' docs/design/INDEX.md
```
Then verify no live hit remains: `git grep -inE '(stage[- ]?1|stage[- ]?2)' -- docs/design/INDEX.md`
Expected: hits ONLY at lines within :297, :617, and :672-906 (the history
sections). Any hit outside those ranges: apply the same token mapping to it.
- [ ] **Step 6: Build + residual gates**
Run: `cargo build --workspace`
Expected: 0 errors
Run: `git grep -icE 'stage[- ]?1|stage[- ]?2' -- crates/aura-std crates/aura-analysis crates/aura-composites crates/aura-cli/Cargo.toml crates/aura-engine/Cargo.toml CLAUDE.md || echo CLEAN`
Expected: `CLEAN`
### Task 5: workspace verification + grep gate
**Files:** none (verification only)
- [ ] **Step 1: full suite**
Run: `cargo test --workspace`
Expected: all targets PASS, 0 failed, 0 new ignored
- [ ] **Step 2: lint + docs**
Run: `cargo clippy --workspace --all-targets -- -D warnings`
Expected: clean
Run: `cargo doc --workspace --no-deps 2>&1 | tail -3`
Expected: no warnings/errors
- [ ] **Step 3: the acceptance grep gate (spec §Testing strategy)**
Run: `git grep -inE '(stage[- ]?1|stage[- ]?2)' -- crates/ CLAUDE.md README.md`
Expected output, exactly one line:
`crates/aura-engine/src/harness.rs:1898:...` (the resampling-stage false positive)
Run: `git grep -ilE '(stage[- ]?1|stage[- ]?2)' -- docs/ ':!docs/specs' ':!docs/plans'`
Expected: `docs/design/INDEX.md` and `docs/glossary.md` only — with INDEX.md
hits confined to the history sections (verified in Task 4 Step 5) and
glossary hits confined to the historical entry (:250-252 region; :96 now
references the rename without a bare ordinal — its "r-family rename (#174)"
wording carries no stage token).
- [ ] **Step 4: behavioural smoke (new vocabulary end-to-end)**
Run: `cargo run -q -p aura-cli -- run --harness r-sma 2>&1 | head -3`
Expected: the normal run output (an R block; no usage error)
Run: `cargo run -q -p aura-cli -- run --harness stage1-r; echo "exit=$?"`
Expected: the usage line naming `<sma|macd|r-sma>` on stderr, then `exit=2`
(old token is a usage error — no silent alias survives, per acceptance box 1;
no pipe before the `echo`, so `$?` is the CLI's exit status, not a filter's)