create-lathe 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +135 -2
  3. package/bin/create-lathe.js +80 -0
  4. package/dist/framework.lock +113 -0
  5. package/dist/package/crates/instrument/Cargo.lock +415 -0
  6. package/dist/package/crates/instrument/Cargo.toml +27 -0
  7. package/dist/package/crates/instrument/examples/instrument.rs +73 -0
  8. package/dist/package/crates/instrument/src/client.rs +128 -0
  9. package/dist/package/crates/instrument/src/lib.rs +32 -0
  10. package/dist/package/crates/instrument/src/logging.rs +109 -0
  11. package/dist/package/crates/instrument/src/protocol.rs +49 -0
  12. package/dist/package/crates/instrument/src/registry.rs +166 -0
  13. package/dist/package/crates/instrument/src/selftest.rs +314 -0
  14. package/dist/package/crates/instrument/src/server.rs +303 -0
  15. package/dist/package/crates/instrument/tests/command_log.rs +60 -0
  16. package/dist/package/crates/instrument/tests/round_trip.rs +134 -0
  17. package/dist/package/crates/instrument/tests/selftest_fail.rs +25 -0
  18. package/dist/package/crates/instrument/tests/selftest_pass.rs +24 -0
  19. package/dist/package/crates/instrument/tests/support/mod.rs +38 -0
  20. package/dist/package/pi/context/journal-de-lot.md +24 -0
  21. package/dist/package/pi/context/tech-skill.md +19 -0
  22. package/dist/package/pi/context/ticket-closed.md +18 -0
  23. package/dist/package/scripts/framework.py +1314 -0
  24. package/dist/package/scripts/gates.py +1134 -0
  25. package/dist/package/scripts/setup.py +195 -0
  26. package/dist/package/skills/bootstrap/SKILL.md +110 -0
  27. package/dist/package/skills/documentation/SKILL.md +110 -0
  28. package/dist/package/skills/documentation/references/agents-md.md +70 -0
  29. package/dist/package/skills/documentation/references/corpus.md +112 -0
  30. package/dist/package/skills/journal/SKILL.md +81 -0
  31. package/dist/package/skills/journal/references/entry.md +172 -0
  32. package/dist/package/skills/lathe/SKILL.md +168 -0
  33. package/dist/package/skills/lathe/evals/routing.md +196 -0
  34. package/dist/package/skills/lathe/references/install.md +128 -0
  35. package/dist/package/skills/lathe/references/invariants.md +31 -0
  36. package/dist/package/skills/mutants/SKILL.md +85 -0
  37. package/dist/package/skills/mutants/references/cargo-mutants.md +176 -0
  38. package/dist/package/skills/mutants/references/triage.md +88 -0
  39. package/dist/package/skills/optimize/SKILL.md +87 -0
  40. package/dist/package/skills/optimize/references/codspeed.md +126 -0
  41. package/dist/package/skills/probe/SKILL.md +82 -0
  42. package/dist/package/skills/probe/references/wait-and-read.md +53 -0
  43. package/dist/package/skills/replicate-ui/SKILL.md +64 -0
  44. package/dist/package/skills/rust/SKILL.md +147 -0
  45. package/dist/package/skills/rust/references/errors.md +63 -0
  46. package/dist/package/skills/rust/references/unsafe.md +65 -0
  47. package/dist/package/skills/scaffold/SKILL.md +78 -0
  48. package/dist/package/skills/scaffold/profiles/rust-cli/.cargo/config.toml +2 -0
  49. package/dist/package/skills/scaffold/profiles/rust-cli/AGENTS.md +22 -0
  50. package/dist/package/skills/scaffold/profiles/rust-cli/Cargo.lock +7 -0
  51. package/dist/package/skills/scaffold/profiles/rust-cli/Cargo.toml +17 -0
  52. package/dist/package/skills/scaffold/profiles/rust-cli/README.md +15 -0
  53. package/dist/package/skills/scaffold/profiles/rust-cli/deny.toml +14 -0
  54. package/dist/package/skills/scaffold/profiles/rust-cli/rustfmt.toml +2 -0
  55. package/dist/package/skills/scaffold/profiles/rust-cli/src/main.rs +38 -0
  56. package/dist/package/skills/scaffold/profiles/rust-cli/tests/cli.rs +27 -0
  57. package/dist/package/skills/scaffold/profiles/rust-library/.cargo/config.toml +2 -0
  58. package/dist/package/skills/scaffold/profiles/rust-library/AGENTS.md +21 -0
  59. package/dist/package/skills/scaffold/profiles/rust-library/Cargo.lock +7 -0
  60. package/dist/package/skills/scaffold/profiles/rust-library/Cargo.toml +18 -0
  61. package/dist/package/skills/scaffold/profiles/rust-library/README.md +15 -0
  62. package/dist/package/skills/scaffold/profiles/rust-library/deny.toml +14 -0
  63. package/dist/package/skills/scaffold/profiles/rust-library/rustfmt.toml +2 -0
  64. package/dist/package/skills/scaffold/profiles/rust-library/src/lib.rs +25 -0
  65. package/dist/package/skills/scaffold/profiles/rust-native-desktop/.cargo/config.toml +2 -0
  66. package/dist/package/skills/scaffold/profiles/rust-native-desktop/AGENTS.md +23 -0
  67. package/dist/package/skills/scaffold/profiles/rust-native-desktop/Cargo.lock +9252 -0
  68. package/dist/package/skills/scaffold/profiles/rust-native-desktop/Cargo.toml +24 -0
  69. package/dist/package/skills/scaffold/profiles/rust-native-desktop/README.md +15 -0
  70. package/dist/package/skills/scaffold/profiles/rust-native-desktop/deny.toml +35 -0
  71. package/dist/package/skills/scaffold/profiles/rust-native-desktop/rustfmt.toml +2 -0
  72. package/dist/package/skills/scaffold/profiles/rust-native-desktop/src/main.rs +74 -0
  73. package/dist/package/skills/scaffold/references/gates.md +29 -0
  74. package/dist/package/skills/scaffold/references/profiles.md +36 -0
  75. package/dist/package/skills/update/SKILL.md +115 -0
  76. package/dist/package/skills/verify-visual/SKILL.md +82 -0
  77. package/dist/package/skills/verify-visual/references/baseline.md +46 -0
  78. package/dist/package/skills/visual-loop/SKILL.md +72 -0
  79. package/dist/package/workflows/batch-to-review.md +41 -0
  80. package/dist/package/workflows/framework-improvement.md +38 -0
  81. package/dist/package/workflows/hard-bug.md +37 -0
  82. package/dist/package/workflows/new-rust-cli.md +33 -0
  83. package/dist/package/workflows/new-rust-desktop-app.md +41 -0
  84. package/dist/package/workflows/new-rust-library.md +34 -0
  85. package/dist/package/workflows/performance-work.md +41 -0
  86. package/dist/package/workflows/ui-change.md +40 -0
  87. package/package.json +33 -4
@@ -0,0 +1,128 @@
1
+ # Install Lathe
2
+
3
+ Lathe installs an engineering workflow into one Rust project: one entry point, twelve steps, gates
4
+ that prove each step, and a mutation campaign that proves the tests could fail. The workflow itself is
5
+ Matt Pocock's; the performance skills are CodSpeed's. Lathe adds the guarantees.
6
+
7
+ This page is written for an agent. It is also the npm package page, so a user who only pastes a link
8
+ is enough.
9
+
10
+ ## Paste this to your agent
11
+
12
+ ```text
13
+ Install Lathe in this repository: read https://www.npmjs.com/package/create-lathe and follow it.
14
+ ```
15
+
16
+ The agent needs no other context: the command, the preconditions, the expected output and the failure
17
+ table are below.
18
+
19
+ ## Preconditions
20
+
21
+ | Needs | Check | If it is missing |
22
+ | --- | --- | --- |
23
+ | node 18+ (ships `npx`) | `npx --version` | install node, then retry |
24
+ | python 3.9+ | `python3 --version` | install python, then retry |
25
+ | a Rust project | `ls Cargo.toml` | nothing: Lathe runs on an empty directory too, and the first step scaffolds |
26
+ | a git repository | `git rev-parse --verify HEAD` | `git init && git add -A && git commit -m init` |
27
+
28
+ `cargo` is not needed to install. Gates that need a tool report `MISSING` until it is there.
29
+
30
+ ## The command
31
+
32
+ ```bash
33
+ npx create-lathe
34
+ ```
35
+
36
+ Run it at the project root. It writes only inside that directory.
37
+
38
+ ## What it does, in order
39
+
40
+ 1. **Prerequisites.** Stops at the first missing one, naming it and nothing else.
41
+ 2. **Upstream skills.** Installs `mattpocock/skills` (39 skills) and `CodSpeedHQ/codspeed`
42
+ (3 skills) with their own CLI, into `.agents/skills/`. An upstream already present is left alone;
43
+ if what it holds differs from what this package pins, that is printed, never corrected.
44
+ 3. **The framework.** Runs `framework.py bootstrap`, which refuses a global Lathe skill, a missing
45
+ upstream, or a missing Pi extension before copying anything; then copies the trees and records
46
+ them in `.framework/installed.json`.
47
+ 4. **Verdict.** Runs `framework.py doctor`. `CLEAN` and exit `0` is the only success.
48
+ 5. **Next step.** Prints `/skill:lathe`.
49
+
50
+ Five destinations land in your project:
51
+
52
+ | Path | What it is |
53
+ | --- | --- |
54
+ | `.agents/skills/` | the entry point `lathe` and the twelve steps it routes to |
55
+ | `.agents/workflows/` | eight full paths (new library, new CLI, new app, hard bug, performance, UI change, batch to review, framework improvement) |
56
+ | `.agents/scripts/` | `gates.py`, `framework.py`, `setup.py` — the delivery carries its own tooling |
57
+ | `.pi/context/` | three conditional rules, injected when the matching gesture happens |
58
+ | `crates/instrument/` | the instrumentation crate |
59
+
60
+ If a destination file already exists with different content, the install writes **nothing** and names
61
+ each conflicting path. Re-run with `--force` to overwrite them, or move them aside first.
62
+
63
+ ## Expected output
64
+
65
+ ```text
66
+ [4] verdict
67
+ installed 0.4.0 (<commit>, <digest8>)
68
+ upstream mattpocock/skills @ <commit>: present 39/39
69
+ upstream CodSpeedHQ/codspeed @ <commit>: present 3/3
70
+ global <home>/.agents/skills — no Lathe skill installed globally
71
+ CLEAN
72
+
73
+ next: in Pi, type /skill:lathe — or just tell your agent "use Lathe"
74
+ ```
75
+
76
+ The version, the commits and the digest differ; `CLEAN` and `39/39` and `3/3` do not.
77
+
78
+ ## If it fails
79
+
80
+ | Message | What it means | What to do |
81
+ | --- | --- | --- |
82
+ | `refusing: <skill> installed globally in ~/.agents/skills` | a Lathe skill is installed machine-wide, so every project would read it | `rm -rf` the path it printed, then retry |
83
+ | `refusing: N of 39 … skills are missing` | the upstream install did not run or failed | run the command it printed, then retry |
84
+ | `refusing: no-more-agents-dot-md is not installed` | the Pi extension that injects the three rules is absent | `pi install git:github.com/TheophileBaudouin/No-More-Agents-Dot-MD` |
85
+ | `not current: re-run the install commands above, then build-lock` | the upstream moved since this package pinned it | the package is stale: use the newest version, or pin it |
86
+ | `error: npx is required` | node is absent or too old | install node 18+, then retry |
87
+ | exit `2` | usage error, including a project path that is not a directory | check the path |
88
+
89
+ ## Without npm
90
+
91
+ The same four commands, in order:
92
+
93
+ ```bash
94
+ npx skills add mattpocock/skills
95
+ npx skills add https://github.com/CodSpeedHQ/codspeed --skill codspeed-setup-harness --skill codspeed-write-benchmarks --skill codspeed-optimize
96
+ python3 <package>/scripts/framework.py bootstrap --project .
97
+ python3 <package>/scripts/framework.py doctor --project .
98
+ ```
99
+
100
+ `<package>` is this delivery, unpacked. `setup.py` is those four commands with the refusals ordered.
101
+
102
+ ## After installing
103
+
104
+ Two ways in, both measured: type `/skill:lathe` in Pi, or tell your agent "use Lathe". Either one reads
105
+ the project and names one step with a `/skill:<step>` line. You never pick a step yourself, and you
106
+ never have to remember one.
107
+
108
+ A `/lathe` prompt template was written for this package and dropped: measured in `pi --print` on a
109
+ fresh project, it was not expanded into a command, and shipping a shortcut that does nothing is worse
110
+ than shipping one fewer shortcut. The skill command is registered by Pi itself.
111
+
112
+ ## Update, uninstall
113
+
114
+ - **Update:** run `npx create-lathe@latest`; it moves to the newer lock and writes only the files that
115
+ changed. A file you edited is a conflict: it is named, nothing is written, and `--force` is what
116
+ replaces it.
117
+ - **Uninstall:** `rm -rf .agents/skills/lathe .agents/workflows .agents/scripts .framework .pi/context`
118
+ and the upstream skills you no longer want. Nothing was installed outside the project, so nothing
119
+ else has to be cleaned.
120
+
121
+ ## What this never does
122
+
123
+ - **Never installs globally.** A framework installed in `~/.agents/skills` serves projects that never
124
+ asked for it, so it is refused, not warned about.
125
+ - **Never updates an upstream silently.** Upstream pins move when you say so.
126
+ - **Never writes outside the project** — no `~` path, no system directory.
127
+ - **Never claims a measurement it did not take.** `CLEAN` comes from `doctor`'s exit code, not from
128
+ this text.
@@ -0,0 +1,31 @@
1
+ # The invariants
2
+
3
+ Six rules bind every run. Each one names the file that enforces it, so a claim about the framework can
4
+ be checked instead of believed.
5
+
6
+ 1. **Proof has a label.** Every claim is an `Axiome`, a `Fait vérifié` (source + date), or an
7
+ `Hypothèse`. An `Hypothèse` is never a hard constraint. Enforced by: `EVIDENCE.md`, `R-080`–`R-083`.
8
+ 2. **The gate verdict is the exit code.** `!= 0` is failure, and a missing tool is `MISSING`, which
9
+ fails unless `--allow-missing` was passed explicitly. Enforced by: `.agents/scripts/gates.py`.
10
+ 3. **One writer per path.** Two agents writing the same file produce a tree that does not compile and
11
+ a report that says it does. Enforced by: `docs/execution/SKILL-CONTRACT.md` §6.
12
+ 4. **A stage ends with a line.** `/skill:<stage>` is the route; naming the stage in prose is not.
13
+ Enforced by: `.agents/skills/lathe/SKILL.md`, `scripts/eval_routing.py`.
14
+ 5. **Hand off, do not absorb.** A stage that performs the next stage's work has silently deleted a
15
+ gate. Enforced by: the `Non-négociables` section of every skill.
16
+ 6. **Cross-OS is claimed per OS.** `conçu` / `exécuté` / `vérifié` are recorded per platform, and
17
+ nothing is `vérifié` on an OS where no command ran. Enforced by: `E-17`, `R-090`–`R-093`.
18
+
19
+ ## How to use this file
20
+
21
+ Read it when the user asks what Lathe is, which rule governs the work in front of them, or whether a
22
+ claim is allowed. Name the invariant and the file that enforces it — not the whole repository.
23
+
24
+ ## What is not enforced
25
+
26
+ Invariant 6 is a documented convention, not a script: nothing mechanically blocks a cross-OS claim.
27
+ This weakness is known and uncorrected. Do not cite the invariant as evidence that the claim was
28
+ checked.
29
+
30
+ Do not invent a seventh invariant. If the work needs a rule that is not above, the rule is missing from
31
+ `CHARTER.md` — say so.
@@ -0,0 +1,85 @@
1
+ ---
2
+ name: mutants
3
+ description: Run the mutation campaign that closes a batch of tickets, before code review. Use when a batch's last ticket is done, when someone asks whether the tests would actually catch a bug, or before reviewing a batch.
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ # Mutation campaign
8
+
9
+ A test that went red then green proves it ran. It does not prove it would fail if the code were wrong.
10
+ The campaign answers that, once per batch: it plants bugs in a copy of the code and reports every one
11
+ the suite fails to notice. `tdd` owns the red → green loop; this step is the proof at the end.
12
+
13
+ Run it after the last ticket and before the review. Per ticket it costs more than the ticket.
14
+
15
+ ## Non-negotiables
16
+
17
+ - **A batch, never a ticket.** Looking for survivors is a seal on finished work; run it while a ticket
18
+ is open and the verdict is about a tree nobody reviewed.
19
+ - **Three refusals before the first mutant.** Output git does not see, a dirty tree, a missing base.
20
+ Fix the precondition; never the flag.
21
+ - **A survivor is killed or justified in writing.** `.lathe/justified.txt`, with a reason a reader can
22
+ check. An equivalent mutant is a documented exception, not a majority.
23
+ - **The verdict is the file, not the memory.** `.lathe/mutants/verdict` names the commit it certified:
24
+ a green review of a different `HEAD` is a green about another tree.
25
+
26
+ ## The one command
27
+
28
+ ```bash
29
+ .agents/scripts/gates.py mutants --project . --start # once, before the batch's first ticket
30
+ .agents/scripts/gates.py mutants --project . # once, after the last ticket is committed
31
+ ```
32
+
33
+ `--start` records the base commit and the ignore line; without it the gate refuses and says so.
34
+ Everything the campaign writes has one fixed place:
35
+
36
+ | What | Where |
37
+ | --- | --- |
38
+ | the report | `.lathe/mutants/mutants.out/` |
39
+ | the batch's diff | `.lathe/mutants/lot.diff` |
40
+ | the base commit | `.lathe/mutants/base` |
41
+ | the certified verdict | `.lathe/mutants/verdict` |
42
+ | accepted survivors | `.lathe/justified.txt` (committed; the rest is not) |
43
+
44
+ The gate runs the campaign, refuses impossible starting states, and reads the result. Calling
45
+ `cargo mutants` directly in a batch produces a report in another place, on another scope, with no
46
+ record of what was accepted.
47
+
48
+ ## Procedure
49
+
50
+ 1. **Open the batch.** Run `--start`, then commit `.lathe/mutants/base` and `.lathe/.gitignore`.
51
+ Done when `--start` printed a commit hash and both files are in the commit.
52
+ 2. **During the batch, nothing.** Each ticket ends with `gates.py verify`; mutation is not a ticket gate.
53
+ 3. **Close the batch, tree committed.** Run `gates.py mutants`. Done when it printed a verdict; a dirty
54
+ tree is refused before the run, because a report nobody can reproduce is not evidence.
55
+ 4. **Read the report in this order** — `outcomes.json` for the counts, `diff/` for the patch of each
56
+ survivor, `log/` for the test run that failed to notice it. Done when every survivor has an entry
57
+ from `references/triage.md`: missing test, equivalent mutant, flaky test, timeout, or unviable.
58
+ 5. **Kill or justify.** Add the missing test through `tdd`, or record the equivalence with its reason.
59
+ Done when each survivor has a test or a line in `.lathe/justified.txt`.
60
+ 6. **Re-run until green.** Each round is cheaper with `-F` on the function you just covered; the
61
+ reference says how. Done when `missed.txt` is empty or fully accounted for.
62
+ 7. **Hand to `code-review`.** The review cites the campaign; a review opened before it reviews tests
63
+ nobody has doubted.
64
+
65
+ ## Reading the verdict
66
+
67
+ `gates.py mutants` exits `0` when every check is green or legitimately skipped, `1` for survivors, a
68
+ refused precondition, a missing tool, or a campaign that proved nothing, `2` for a usage error.
69
+
70
+ The campaign itself explains a failure in its note: survivors are named with `path:line:col`, a
71
+ timeout says how many mutants hung, a red baseline says the suite fails before any mutation. The
72
+ meaning of the tool's own exit codes `3` to `6`, and what to do with each, is in the reference.
73
+
74
+ ## Done when
75
+
76
+ - `gates.py mutants --project .` exits `0` and printed `VERDICT: tout vert`.
77
+ - `.lathe/mutants/mutants.out/missed.txt` is empty, or every line in it appears in
78
+ `.lathe/justified.txt` with a reason a reader can check.
79
+ - `.lathe/justified.txt` is committed; `.lathe/mutants/` is not.
80
+
81
+ ## Reference
82
+
83
+ - `references/cargo-mutants.md` — the whole surface of v27.1.0: filtering, exit codes, timeouts,
84
+ sharding, nextest, config keys, attributes, performance, limitations. Read it before choosing a flag.
85
+ - `references/triage.md` — what each survivor is telling you, and what to write for each kind.
@@ -0,0 +1,176 @@
1
+ # cargo-mutants v27.1.0, the whole surface
2
+
3
+ Every fact below is settled by one of three sources, all version-exact: `cargo mutants --help` on this
4
+ machine, `cargo mutants --emit-schema config` (the schema is generated from the struct the binary
5
+ parses), and the book shipped inside the crate `cargo-mutants-27.1.0/book/`.
6
+
7
+ ## What it does
8
+
9
+ It edits a copy of the tree, one mutation at a time, and runs the test suite. A mutation the tests do
10
+ not notice is a **survivor** — a bug the suite would ship.
11
+
12
+ The default is the safe mode: a copy per job, and only `mutants.out` is written. `--in-place` edits
13
+ the real tree, cannot be combined with `--jobs`, and after an interruption can leave mutations behind,
14
+ marked `/* ~ changed by cargo-mutants ~ */`. In-place is attractive for one reason — it reuses an
15
+ existing `target/` — and a batch does not need that.
16
+
17
+ The book's own first caution is not about the tree: mutated code can activate destructive paths the
18
+ tests already contain (a cleanup that becomes `rm -rf`), so run against a backup and never with
19
+ production credentials.
20
+
21
+ ## The report
22
+
23
+ `-o DIR` creates `DIR/mutants.out/`, always with that inner name. An existing `mutants.out` becomes
24
+ `mutants.out.old` and the previous `.old` is deleted.
25
+
26
+ ```text
27
+ mutants.out/
28
+ lock.json version, start time, host, user — and the run lock itself
29
+ mutants.json every generated mutant, with its diff (written before testing)
30
+ outcomes.json outcomes[] plus totals: missed, caught, timeout, unviable
31
+ caught.txt missed.txt timeout.txt unviable.txt one name per line, appended live
32
+ previously_caught.txt only with --iterate
33
+ diff/<file>_line_<L>_col_<C>.diff the patch of each mutation
34
+ log/baseline.log, log/<same stem>.log full cargo output per scenario
35
+ debug.log
36
+ ```
37
+
38
+ Read it in this order: `outcomes.json` for the counts, `diff/` for what the mutation did, `log/` for
39
+ the test run that missed it. Lines in `missed.txt` are `path:line:col: description` — the `MISSED `
40
+ you see on the console is a stdout prefix and is not in the file.
41
+
42
+ The book says `logs/`; the directory is `log/`. Formats are explicitly unstable across releases.
43
+
44
+ ## Exit codes
45
+
46
+ | code | meaning |
47
+ | --- | --- |
48
+ | `0` | every viable mutant was caught — **also**: nothing to test (`--list`, empty diff, a diff touching only test code) |
49
+ | `1` | usage error, including an unknown key in `mutants.toml` |
50
+ | `2` | some mutants were missed |
51
+ | `3` | some tests timed out |
52
+ | `4` | the unmutated baseline is already failing or hanging — nothing was tested |
53
+ | `5` | `--in-diff`: the new side of the diff does not match the text in the tree |
54
+ | `6` | `--in-diff`: the file is not a valid diff |
55
+ | `70` | internal error |
56
+
57
+ For a completed campaign the codes aggregate `4` > `3` > `2` > `0`, so a run with both a hang and a
58
+ survivor exits `3`, not `2`. Read the report rather than trusting one number.
59
+
60
+ ## Generating and filtering
61
+
62
+ Nine mutation genres: replace a function body with `0`, `1`, `-1` or an error; binary operator
63
+ replacement; unary operator deletion; delete a match arm (when a wildcard exists); force a match guard
64
+ to `true`/`false`; delete a struct-literal field (when a base expression exists). `=` is never turned
65
+ into `<`, and `&=`/`|=` never into `^=` — too many false positives.
66
+
67
+ Always skipped: functions under `#[cfg(test)]`, anything with an attribute whose path ends in `test`
68
+ (`#[test]`, `#[tokio::test]`, …), `#[mutants::skip]`, and `unsafe` functions.
69
+
70
+ `#[mutants::skip]` is the durable way to declare a function untouchable — an equivalent mutant, a
71
+ hang-prone routine. It lives next to the code and survives lines moving. A `cfg_attr`-nested
72
+ `mutants::skip` is honoured regardless of its condition, which is a known quirk: do not expect the
73
+ condition to gate it.
74
+
75
+ | Flag | Behaviour |
76
+ | --- | --- |
77
+ | `-f/--file GLOB`, `-e/--exclude GLOB` | file globs; `--file` applies first, then `--exclude`. A glob **with** a path separator matches from the tree root; without one it matches file and directory *names* — so `-f network` catches `src/network/mod.rs` and misses `src/network.rs` |
78
+ | `-F/--re RE`, `-E/--exclude-re RE` | regexes on the mutant's full name, applied after file filters. `--re` then `--exclude-re`; `^`/`$` anchor the whole name |
79
+ | `-D/--in-diff FILE` | keep only mutants overlapping the diff. Applied last |
80
+ | `--skip-calls NAME`, `--skip-calls-defaults=false` | do not mutate inside the arguments of these calls. The default list is `with_capacity`; matching is on the last path component, so `Vec::<String>::with_capacity` matches |
81
+ | `--error EXPR` | add an `Err(EXPR)` mutant to `Result`-returning functions; the wrapper is added for you |
82
+
83
+ Filter merge with `mutants.toml`: regexes **combine** with their config counterparts; `--file` and
84
+ `--exclude` **replace** the matching config glob (an `exclude_globs` still applies when `--file` is
85
+ given). Measured on 27.1.0, and the changelog overstates it.
86
+
87
+ `--in-diff` matches code under test only. A diff that touches just tests, docs or non-Rust files
88
+ produces zero mutants and exits `0` — legitimately. A diff that no longer matches the tree exits `5`.
89
+
90
+ ## Scope
91
+
92
+ Default: the package containing the current directory (a virtual workspace uses `default-members`, or
93
+ all packages). `-p/--package` and `--workspace` widen it.
94
+
95
+ `--test-package` adds packages whose tests run for every mutant; `--test-workspace=true` runs the whole
96
+ workspace's tests and overrides `--test-package`. Both take the `=true` form.
97
+
98
+ ## Timeouts
99
+
100
+ A test timeout is resolved in this order:
101
+
102
+ 1. `-t/--timeout SECS` — always wins;
103
+ 2. otherwise `max(minimum_test_timeout, baseline_test_time × timeout_multiplier)`, where
104
+ `timeout_multiplier` defaults to `5` and `minimum_test_timeout` to `20 s`;
105
+ 3. otherwise — no baseline — a fixed **300 s** fallback with a warning.
106
+
107
+ So `--baseline=skip` does not remove the timeout: it replaces the auto-set value with 300 s and prints
108
+ a warning, and a `--timeout-multiplier` then has no baseline to multiply. On a fast suite 300 s is
109
+ generous; on a slow one it cuts a legitimate test short.
110
+
111
+ Build timeouts are off by default (`--build-timeout`, `--build-timeout-multiplier`); a build timeout is
112
+ worth setting only with `--cap-lints`, which disables rustc's long-const-eval protection.
113
+
114
+ ## Running many
115
+
116
+ | Flag | Behaviour |
117
+ | --- | --- |
118
+ | `-j/--jobs N` | **default 1**. One copy and one `target/` per job. Above 8 the tool warns; the book suggests `-j2`/`-j3` and sharding over giant `-j` |
119
+ | `--jobserver` | on by default; caps *builds* across children. The test harness does not speak the protocol, so it does not cap tests |
120
+ | `--shard K/N` | run shard `K`, 0-based, of `N`. `--sharding slice` (default, consecutive, better incremental builds) or `round-robin` (even runtimes). Every shard needs identical filters and the same `N` |
121
+ | `--shuffle` / `--no-shuffle` | **no shuffle is the default since 26.0.0**; the book still says the opposite. Randomisation happens after sharding |
122
+ | `--iterate` | skip mutants caught or unviable in the previous run, via `previously_caught.txt`. Keyed on `file:line:col`, so any inserted line re-tests. A heuristic for the inner loop, never the final run |
123
+ | `--check` | run `cargo check` on each mutant, no tests. A debugging aid, not a campaign |
124
+
125
+ Fail-fast: leave it on (do not pass `--no-fail-fast`). On recent nightlies,
126
+ `-- -- -Zunstable-options --fail-fast` passes it to the test binary.
127
+
128
+ ## nextest
129
+
130
+ `--test-tool nextest` (config `test_tool`). Per-test isolation and early exit help trees that only pass
131
+ under nextest. Two consequences to plan for: nextest does not run doctests, so behaviour covered only
132
+ by a doctest reports as **missed**; and nextest lets stragglers finish, so on trees with fast unit tests
133
+ and slow integration tests it can be slower. Pass a nextest profile with `-C --profile=mutants`.
134
+
135
+ ## Output flags
136
+
137
+ | Flag | Use |
138
+ | --- | --- |
139
+ | `--list`, `--list-files` | what would be tested, seconds instead of minutes. The preflight for a filter you are unsure about |
140
+ | `--json` | **only with `--list`**; alone it runs the campaign and prints no JSON |
141
+ | `--diff`, `--line-col` | with `--list`: append each patch, drop positions. JSON always carries the diff |
142
+ | `-v/--caught`, `-V/--unviable` | print caught and unviable mutants too (stdout; missed goes to stderr) |
143
+ | `--no-times` | deterministic output — and it hides the `Auto-set test timeout` line, which is exactly what you want when debugging a timeout |
144
+ | `-L debug` | print the resolved config and options. The fastest way to learn what a file plus flags actually configured |
145
+ | `--annotations auto\|none\|github` | `::warning file=…,line=…` lines, on by default in GitHub Actions |
146
+
147
+ ## Configuration
148
+
149
+ `.cargo/mutants.toml` at the source-tree root, or `--config FILE`, or `--no-config`. **Unknown keys are
150
+ a hard error** (`deny_unknown_fields`), exit `1`, so a typo fails loudly.
151
+
152
+ 25 keys: `additional_cargo_args`, `additional_cargo_test_args`, `all_features`, `build_timeout_multiplier`,
153
+ `cap_lints`, `copy_target`, `copy_vcs`, `error_values`, `examine_globs`, `examine_re`, `exclude_globs`,
154
+ `exclude_re`, `features`, `gitignore`, `minimum_test_timeout`, `no_default_features`, `output`, `profile`,
155
+ `sharding`, `skip_calls`, `skip_calls_defaults`, `test_package`, `test_tool`, `test_workspace`,
156
+ `timeout_multiplier`.
157
+
158
+ `in_place`, `timeout`, `baseline`, `jobs`, `iterate`, `shuffle` are **not** keys; writing one is the
159
+ error above. In-place has no configuration form on purpose.
160
+
161
+ ## Performance, as the book frames it
162
+
163
+ Cost is one incremental build plus one full test run per viable mutant. What moves it: a cheap profile
164
+ (`[profile.mutants] inherits = "test"` with `debug = "none"`), `TMPDIR` on a ramdisk (important under
165
+ `-j`), a faster linker, skipping doctests (`-- --all-targets`), `--in-diff` for PR-scoped runs, and
166
+ sharding with at least ten mutants per shard.
167
+
168
+ ## What it cannot tell you
169
+
170
+ - It needs hermetic, non-flaky tests; with flaky ones the results "are meaningless".
171
+ - It sees the syntax tree, not types: unviable mutants are normal and are not a failure.
172
+ - Equivalent mutants exist; the tool's remedy is `#[mutants::skip]`, yours may be a written justification.
173
+ - `#[cfg(...)]` is not evaluated: code for another platform is mutated and reported missed here.
174
+ - Macros are not mutated, and macro-heavy crates produce few mutants.
175
+ - It does not read `.cargo/config.toml` rustflags; only `RUSTFLAGS`/`CARGO_ENCODED_RUSTFLAGS`.
176
+ - A passing campaign does not mean the code is good — only that the tests check it.
@@ -0,0 +1,88 @@
1
+ # Triage: what a survivor is telling you
2
+
3
+ `missed.txt` lines all look alike — `path:line:col: replace X with Y` — and they are five different
4
+ things. Decide which before writing anything.
5
+
6
+ ## 1. A missing test
7
+
8
+ The common case: the mutation changes behaviour nothing asserts.
9
+
10
+ ```text
11
+ src/selftest.rs:44:36: replace + with * in run
12
+ ```
13
+
14
+ Write the test the mutation names: assert the behaviour that separates `+` from `*` there, through
15
+ `tdd` (red first). A test written after the mutation, aimed at the mutation, tends to assert the shape
16
+ of the implementation rather than its behaviour — the tautology `tdd` warns about.
17
+
18
+ ## 2. An equivalent mutant
19
+
20
+ The mutated program behaves identically. No test can kill it, and none should try.
21
+
22
+ ```rust
23
+ pub fn clamp_low(n: i32) -> i32 {
24
+ if n < 0 { 0 } else { n }
25
+ }
26
+ ```
27
+
28
+ `replace < with <=` survives, and it is not a gap: `n < 0` and `n == 0` both return `0`, `n > 0` both
29
+ return `n`. Same function.
30
+
31
+ Two ways to answer, and the first is better when it applies:
32
+
33
+ - `#[mutants::skip]` on the item, when the whole item is untouchable. It lives with the code, survives
34
+ lines moving, and never needs re-justifying.
35
+ - One line in `.lathe/justified.txt`, when only one mutation is equivalent. Matching is by prefix or
36
+ substring of the survivor line:
37
+
38
+ ```text
39
+ # Équivalence vérifiée sur les trois cas : n < 0 → 0 ; n == 0 → 0 ; n > 0 → n.
40
+ src/lib.rs:10:10: replace < with <=
41
+ ```
42
+
43
+ A justification keyed on `path:line:col` breaks the day code is inserted above it — the gate goes red
44
+ for a reason nobody can see. Prefer the attribute for anything durable; keep the file for one-offs.
45
+
46
+ ## 3. A flaky test
47
+
48
+ Same tree, two runs, different verdicts. Measured on the `instrument` crate: 31 survivors, then 33, the
49
+ two that flipped both in an `io::ErrorKind::WouldBlock` guard caught only when the timing landed.
50
+
51
+ A flip is a bug report against the test: its verdict depends on scheduling, so it will fail in CI at the
52
+ worst moment. Fix the test before trusting any survivor measured through it. Two runs and
53
+ `diff` of the two `missed.txt` files is enough to see one.
54
+
55
+ ## 4. A timeout
56
+
57
+ The mutant hung: `timeout.txt`, and the campaign exits `3`. A hang is usually **caused by the mutation**
58
+ — a loop that no longer terminates — not by a slow test.
59
+
60
+ Decide which:
61
+
62
+ - the code is genuinely slow → raise `--mutant-timeout`, or `minimum_test_timeout` for every mutant;
63
+ - the mutation makes the code hang on purpose (retry loop, wait) → `#[mutants::skip]` on the item, with
64
+ the reason in a comment;
65
+ - the timeout is too tight for the suite → `--mutant-timeout` above the slowest test, measured.
66
+
67
+ Never leave a timeout unclassified: it is neither killed nor surviving, and the gate is right to refuse it.
68
+
69
+ ## 5. Unviable
70
+
71
+ The mutation does not compile, so it was never tested. `unviable.txt` is not a failure list. It matters
72
+ only as a pattern: a file whose mutants are nearly all unviable is often code that never runs.
73
+
74
+ ## Order of work
75
+
76
+ 1. Fix flaky tests — every survivor measured through them is untrustworthy.
77
+ 2. Kill the missing-test survivors, cheapest behaviour first.
78
+ 3. Skip or justify the equivalent ones.
79
+ 4. Re-run; a survivor you removed by narrowing a filter is still a survivor.
80
+
81
+ ## Narrowing a round
82
+
83
+ A full campaign per iteration is wasteful. `-F clamp_low` re-tests one function, `--iterate` skips what
84
+ was already caught, and `-f src/lib.rs` narrows to a file. The batch's verdict comes from the unfiltered
85
+ run; filters are for the loops in between.
86
+
87
+ A flag that excludes the file whose mutants survive removes the question, not the bug. Excluding is for
88
+ generated code.
@@ -0,0 +1,87 @@
1
+ ---
2
+ name: optimize
3
+ description: Make Rust code faster on measured evidence. Use when the user asks to speed something up, cut allocations, reduce latency, or asks where the time actually goes.
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ # Optimize
8
+
9
+ A performance change is a claim, so it needs a number and a source. This step runs the claim: a harness,
10
+ a baseline, one change at a time, a comparison, and a decision that survives the session as a file.
11
+
12
+ The measurement expertise is upstream and stays there: `codspeed-setup-harness` builds the harness,
13
+ `codspeed-write-benchmarks` keeps it valid, `codspeed-optimize` runs the measure → profile → change loop.
14
+ This step supplies what they leave out: the install, the recorded command, the correctness gates, the
15
+ git revert, and a stop rule with numbers in it.
16
+
17
+ ## Preflight: what can be measured here
18
+
19
+ ```bash
20
+ codspeed status # auth, tools, system: one command, three answers
21
+ cargo codspeed --version # the Rust build path
22
+ ```
23
+
24
+ | `codspeed status` says | What is possible |
25
+ | --- | --- |
26
+ | logged in, walltime executor ready | walltime runs on this machine |
27
+ | logged in, simulation wanted | simulation needs Linux + valgrind; elsewhere use walltime |
28
+ | not logged in | `codspeed auth login`, or run the same commands in CI |
29
+ | no `codspeed` binary | `curl -fsSL https://codspeed.io/install.sh \| sh` then `cargo install cargo-codspeed` |
30
+
31
+ Measured on macOS: the CLI installs and walltime runs; the instruments are supported on Linux
32
+ (Ubuntu/Debian). An unauthenticated run still builds and tests, then stops at the upload.
33
+
34
+ If neither CodSpeed nor a harness can run, **say the goal is unmeasurable and stop**. A guessed
35
+ percentage, a single `time` output or a `cargo bench` mean quoted as a gain is worse than no number: it
36
+ survives the session and steers the next decision.
37
+
38
+ ## The loop
39
+
40
+ 1. **Harness first.** Look for `benches/`, a `[[bench]]` target, `codspeed.yml`. If there is none, run
41
+ `codspeed-setup-harness`, then `codspeed-write-benchmarks` to validate what it built. Done when one
42
+ command builds and runs the suite, and it is written down in `.lathe/perf/harness.md` with its mode
43
+ and the machine.
44
+ 2. **Baseline.** Run that command, keep the run id. Done when the id is in the evidence file.
45
+ 3. **Profile before touching code.** Ask `query_flamegraph` for self time and rank the top three
46
+ functions. Done when you can name the bottleneck and its share of the total; if the time is spread
47
+ evenly, there is nothing to fix — stop here and say so.
48
+ 4. **One change, then correctness.** Apply a single change, then `gates.py fast --project .`. Done when
49
+ fmt, clippy and tests pass *with* the change; a change that breaks them is reverted, not repaired.
50
+ 5. **Re-measure and compare.** `compare_runs` with the baseline and the new run. Done when you have the
51
+ delta on the target **and** on the other benchmarks — shared code moves them too.
52
+ 6. **Decide, and write the decision.**
53
+
54
+ | Measured on the target | Elsewhere | Verdict |
55
+ | --- | --- | --- |
56
+ | > 5 % | no regression > 2 % | keep, commit alone, with the number in the message |
57
+ | 2 – 5 % | no regression | keep only if it also removes code; otherwise revert |
58
+ | < 2 % | anything | revert: a phantom gain costs complexity forever |
59
+ | any | regression > 2 % | revert |
60
+
61
+ 7. **Journal it.** One entry per lot: the bottleneck, the change, before → after, the verdict. Numbers
62
+ live in the evidence file; the journal names it.
63
+ 8. **Stop.** Stop at the first of: two consecutive changes under 2 %, two failed attempts on the same
64
+ bottleneck, five kept changes, or the user satisfied. Report what remains and what it would cost.
65
+
66
+ ## Non-negotiable
67
+
68
+ - **Correctness outranks speed.** Every kept change passes `gates.py fast`; before the review, `verify`.
69
+ - **The tests are not the variable.** No test is deleted, weakened or skipped to make a benchmark pass.
70
+ The batch's mutation campaign still runs, and still decides whether the suite can fail.
71
+ - **No benchmark-shaped special case.** Code that detects the benchmark input is a defect: name it and
72
+ revert it.
73
+ - **One change, one commit.** Two optimisations in one commit make the number unreadable, and the revert
74
+ impossible.
75
+
76
+ ## Done when
77
+
78
+ - `.lathe/perf/<lot>.md` holds the harness command, the mode, the baseline and final run ids, and one
79
+ line per change with its verdict.
80
+ - Every kept change is its own commit, with the measured gain in the message.
81
+ - `gates.py verify --project .` exits `0`, and the journal entry names the evidence file.
82
+
83
+ ## Reference
84
+
85
+ `references/codspeed.md` — the local surface measured on this machine: install, `status`, modes,
86
+ the harness compat crates, the `codspeed.yml` exec harness, auth, MCP, CI, and the places where the
87
+ upstream skills assume something the tool does not do.