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.
- package/LICENSE +21 -0
- package/README.md +135 -2
- package/bin/create-lathe.js +80 -0
- package/dist/framework.lock +113 -0
- package/dist/package/crates/instrument/Cargo.lock +415 -0
- package/dist/package/crates/instrument/Cargo.toml +27 -0
- package/dist/package/crates/instrument/examples/instrument.rs +73 -0
- package/dist/package/crates/instrument/src/client.rs +128 -0
- package/dist/package/crates/instrument/src/lib.rs +32 -0
- package/dist/package/crates/instrument/src/logging.rs +109 -0
- package/dist/package/crates/instrument/src/protocol.rs +49 -0
- package/dist/package/crates/instrument/src/registry.rs +166 -0
- package/dist/package/crates/instrument/src/selftest.rs +314 -0
- package/dist/package/crates/instrument/src/server.rs +303 -0
- package/dist/package/crates/instrument/tests/command_log.rs +60 -0
- package/dist/package/crates/instrument/tests/round_trip.rs +134 -0
- package/dist/package/crates/instrument/tests/selftest_fail.rs +25 -0
- package/dist/package/crates/instrument/tests/selftest_pass.rs +24 -0
- package/dist/package/crates/instrument/tests/support/mod.rs +38 -0
- package/dist/package/pi/context/journal-de-lot.md +24 -0
- package/dist/package/pi/context/tech-skill.md +19 -0
- package/dist/package/pi/context/ticket-closed.md +18 -0
- package/dist/package/scripts/framework.py +1314 -0
- package/dist/package/scripts/gates.py +1134 -0
- package/dist/package/scripts/setup.py +195 -0
- package/dist/package/skills/bootstrap/SKILL.md +110 -0
- package/dist/package/skills/documentation/SKILL.md +110 -0
- package/dist/package/skills/documentation/references/agents-md.md +70 -0
- package/dist/package/skills/documentation/references/corpus.md +112 -0
- package/dist/package/skills/journal/SKILL.md +81 -0
- package/dist/package/skills/journal/references/entry.md +172 -0
- package/dist/package/skills/lathe/SKILL.md +168 -0
- package/dist/package/skills/lathe/evals/routing.md +196 -0
- package/dist/package/skills/lathe/references/install.md +128 -0
- package/dist/package/skills/lathe/references/invariants.md +31 -0
- package/dist/package/skills/mutants/SKILL.md +85 -0
- package/dist/package/skills/mutants/references/cargo-mutants.md +176 -0
- package/dist/package/skills/mutants/references/triage.md +88 -0
- package/dist/package/skills/optimize/SKILL.md +87 -0
- package/dist/package/skills/optimize/references/codspeed.md +126 -0
- package/dist/package/skills/probe/SKILL.md +82 -0
- package/dist/package/skills/probe/references/wait-and-read.md +53 -0
- package/dist/package/skills/replicate-ui/SKILL.md +64 -0
- package/dist/package/skills/rust/SKILL.md +147 -0
- package/dist/package/skills/rust/references/errors.md +63 -0
- package/dist/package/skills/rust/references/unsafe.md +65 -0
- package/dist/package/skills/scaffold/SKILL.md +78 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/.cargo/config.toml +2 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/AGENTS.md +22 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/Cargo.lock +7 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/Cargo.toml +17 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/README.md +15 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/deny.toml +14 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/rustfmt.toml +2 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/src/main.rs +38 -0
- package/dist/package/skills/scaffold/profiles/rust-cli/tests/cli.rs +27 -0
- package/dist/package/skills/scaffold/profiles/rust-library/.cargo/config.toml +2 -0
- package/dist/package/skills/scaffold/profiles/rust-library/AGENTS.md +21 -0
- package/dist/package/skills/scaffold/profiles/rust-library/Cargo.lock +7 -0
- package/dist/package/skills/scaffold/profiles/rust-library/Cargo.toml +18 -0
- package/dist/package/skills/scaffold/profiles/rust-library/README.md +15 -0
- package/dist/package/skills/scaffold/profiles/rust-library/deny.toml +14 -0
- package/dist/package/skills/scaffold/profiles/rust-library/rustfmt.toml +2 -0
- package/dist/package/skills/scaffold/profiles/rust-library/src/lib.rs +25 -0
- package/dist/package/skills/scaffold/profiles/rust-native-desktop/.cargo/config.toml +2 -0
- package/dist/package/skills/scaffold/profiles/rust-native-desktop/AGENTS.md +23 -0
- package/dist/package/skills/scaffold/profiles/rust-native-desktop/Cargo.lock +9252 -0
- package/dist/package/skills/scaffold/profiles/rust-native-desktop/Cargo.toml +24 -0
- package/dist/package/skills/scaffold/profiles/rust-native-desktop/README.md +15 -0
- package/dist/package/skills/scaffold/profiles/rust-native-desktop/deny.toml +35 -0
- package/dist/package/skills/scaffold/profiles/rust-native-desktop/rustfmt.toml +2 -0
- package/dist/package/skills/scaffold/profiles/rust-native-desktop/src/main.rs +74 -0
- package/dist/package/skills/scaffold/references/gates.md +29 -0
- package/dist/package/skills/scaffold/references/profiles.md +36 -0
- package/dist/package/skills/update/SKILL.md +115 -0
- package/dist/package/skills/verify-visual/SKILL.md +82 -0
- package/dist/package/skills/verify-visual/references/baseline.md +46 -0
- package/dist/package/skills/visual-loop/SKILL.md +72 -0
- package/dist/package/workflows/batch-to-review.md +41 -0
- package/dist/package/workflows/framework-improvement.md +38 -0
- package/dist/package/workflows/hard-bug.md +37 -0
- package/dist/package/workflows/new-rust-cli.md +33 -0
- package/dist/package/workflows/new-rust-desktop-app.md +41 -0
- package/dist/package/workflows/new-rust-library.md +34 -0
- package/dist/package/workflows/performance-work.md +41 -0
- package/dist/package/workflows/ui-change.md +40 -0
- package/package.json +33 -4
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# CodSpeed, the local surface
|
|
2
|
+
|
|
3
|
+
Measured on this machine (macOS arm64, 2026-11-29) unless marked **unverified**.
|
|
4
|
+
|
|
5
|
+
## Versions
|
|
6
|
+
|
|
7
|
+
| Piece | Version | How it was established |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `codspeed` CLI | 5.8.0 | installed from `https://codspeed.io/install.sh`, `codspeed --version` |
|
|
10
|
+
| `cargo-codspeed` | 6.1.0 | crates.io API |
|
|
11
|
+
| `codspeed-{divan,criterion,bencher}-compat` | 6.1.0 | crates.io search |
|
|
12
|
+
|
|
13
|
+
The installer ships `codspeed-runner-aarch64-apple-darwin` and `…-x86_64-unknown-linux-musl-static`:
|
|
14
|
+
the binary exists for macOS. The **instruments** (simulation) are supported on Ubuntu 22.04/24.04/26.04
|
|
15
|
+
and Debian 12, which is why simulation is a Linux affair.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
curl -fsSL https://codspeed.io/install.sh | sh # add /v5.8.0/ to pin
|
|
21
|
+
cargo install cargo-codspeed # the Rust build path
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`CODSPEED_RUNNER_UNMANAGED_INSTALL=/tmp/dir` installs into a prefix without touching `PATH` — the way to
|
|
25
|
+
try it without changing the machine.
|
|
26
|
+
|
|
27
|
+
## State, in one command
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
$ codspeed status
|
|
31
|
+
Authentication (profile: default)
|
|
32
|
+
✗ Not logged in (run codspeed auth login to authenticate)
|
|
33
|
+
Repository
|
|
34
|
+
Not inside a git repository
|
|
35
|
+
Tools
|
|
36
|
+
✓ walltime executor: No tool to install
|
|
37
|
+
System
|
|
38
|
+
codspeed 5.8.0
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`codspeed status` is the preflight: it answers auth, repository linkage, executor availability and
|
|
42
|
+
version. `codspeed auth login` is the only way to upload; without it a run builds, executes and then
|
|
43
|
+
stops at the upload with `Your session has expired` — the message says "expired" even when you never
|
|
44
|
+
logged in.
|
|
45
|
+
|
|
46
|
+
## Modes
|
|
47
|
+
|
|
48
|
+
| Mode | What it measures | Where | Use |
|
|
49
|
+
| --- | --- | --- | --- |
|
|
50
|
+
| `walltime` | real elapsed time | the machine you run on | final validation, syscall/IO work |
|
|
51
|
+
| `simulation` | instruction counts under valgrind, cache misses modelled | Linux + valgrind | fast iteration, comparisons stable across runs |
|
|
52
|
+
| `memory` | allocations and bytes | Linux | allocation work |
|
|
53
|
+
|
|
54
|
+
`-m <mode>` is accepted as an alias of `--mode`; `codspeed use <mode>` sets it for the shell session and
|
|
55
|
+
`codspeed show` reads it back. With no mode and no session mode: `No runner mode specified`.
|
|
56
|
+
|
|
57
|
+
Simulation does not measure syscalls, and the docs claim consistency across runs, never bit-exact
|
|
58
|
+
reproducibility. A gain there can still vanish on hardware — branch prediction and out-of-order
|
|
59
|
+
execution — which is why the loop iterates in simulation and validates in walltime. `cargo codspeed`
|
|
60
|
+
defaults to `simulation`; the CLI's own default for `codspeed exec` is `walltime`, and Go's is walltime.
|
|
61
|
+
|
|
62
|
+
## Rust harness
|
|
63
|
+
|
|
64
|
+
The integration renames the compat crate over the harness, so existing `use divan::…` /
|
|
65
|
+
`use criterion::…` lines keep working:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
cargo add --dev divan
|
|
69
|
+
cargo add --dev codspeed-divan-compat --rename divan
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`[[bench]] name = "my_bench"` with `harness = false` in `Cargo.toml`, then:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
cargo codspeed build -m simulation --bench my_bench
|
|
76
|
+
codspeed run -m simulation -- cargo codspeed run --bench my_bench
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Three harnesses are supported: **divan** (recommended), **criterion**, **bencher**
|
|
80
|
+
(`codspeed-bencher-compat` exists on crates.io; the upstream setup skill names bencher but gives no
|
|
81
|
+
recipe). A `benches/` file needs `divan::main()` or `criterion_main!`.
|
|
82
|
+
|
|
83
|
+
## Exec harness, any language
|
|
84
|
+
|
|
85
|
+
`codspeed exec -m walltime -- ./target/release/my_bin --input small.txt`, or a `codspeed.yml` at the
|
|
86
|
+
repository root:
|
|
87
|
+
|
|
88
|
+
```yaml
|
|
89
|
+
options:
|
|
90
|
+
warmup-time: "1s"
|
|
91
|
+
max-time: 5s
|
|
92
|
+
benchmarks:
|
|
93
|
+
- name: "My program - small input"
|
|
94
|
+
exec: ./my_binary --input small.txt
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Reading results
|
|
98
|
+
|
|
99
|
+
Every run uploads and returns a report URL. The optimize loop reads runs through the **hosted MCP
|
|
100
|
+
server** `https://mcp.codspeed.io/mcp` (`compare_runs`, `query_flamegraph`, `list_runs`). No MCP, no
|
|
101
|
+
flamegraph: the loop's analysis step cannot be done from terminal output, and the upstream skill says so
|
|
102
|
+
three times. In Pi, add the server to the MCP configuration and authenticate before the loop.
|
|
103
|
+
|
|
104
|
+
CI: `CodSpeedHQ/action`, released in step with the CLI (v5.8.0 at the time of writing); pin it by tag
|
|
105
|
+
rather than `@main`. **Not run here** — no CI campaign was made, so the action's behaviour in this
|
|
106
|
+
project is unverified.
|
|
107
|
+
|
|
108
|
+
## Where the upstream skills stop, and this package starts
|
|
109
|
+
|
|
110
|
+
| Gap in `codspeed-*` | What Lathe adds |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| no install step for the CLI or `cargo-codspeed` | `SKILL.md` preflight names both commands |
|
|
113
|
+
| no record of the bench command between setup and optimize | `.lathe/perf/harness.md` |
|
|
114
|
+
| no git: "revert" is an unqualified instruction | the change/commit/revert rules in `SKILL.md` |
|
|
115
|
+
| stop rule is qualitative, the 2–5 % band is undefined | the decision table in `SKILL.md` |
|
|
116
|
+
| "run existing tests" names no gate | `gates.py fast`, then `verify` |
|
|
117
|
+
| correctness of the *suite* is out of scope | the batch's mutation campaign still decides |
|
|
118
|
+
|
|
119
|
+
## Limits worth remembering
|
|
120
|
+
|
|
121
|
+
- No auth, no run: the upload is the run.
|
|
122
|
+
- Simulation and memory need Linux and valgrind.
|
|
123
|
+
- macOS is contradictory upstream: an `aarch64-apple-darwin` build exists and walltime reports ready
|
|
124
|
+
here, while the FAQ limits local runs to Ubuntu/Debian. Treat local macOS numbers as local.
|
|
125
|
+
- `cargo bench` outside CodSpeed is explicitly out of bounds for the skills' numbers.
|
|
126
|
+
- A benchmark whose result is dropped or not `black_box`ed measures the optimiser, not the code.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: probe
|
|
3
|
+
description: Drive a running desktop app and read back what it actually did. Use when an interaction must be proven to have taken effect, when the app misbehaves only once launched, or when a report names a screen but not a cause.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Probe
|
|
8
|
+
|
|
9
|
+
Turn one intention into one named command against the app already running, then read a state back —
|
|
10
|
+
an accessibility label, a `bounds()` rectangle, a store row — to decide whether that command took
|
|
11
|
+
effect. This step answers "what did the app do", never "what does it look like": a capture that
|
|
12
|
+
differs is `verify-visual`, a failure with no reproduction is `diagnosing-bugs`.
|
|
13
|
+
|
|
14
|
+
Platform state, verified 2026-11-28 on macOS arm64: the `rust-native-desktop` profile ships,
|
|
15
|
+
`cargo check --all-targets` exits 0, one headless interaction test passes, and `gates.py fast`
|
|
16
|
+
is green. Verified nowhere on Linux or Windows. Probe reads state rather than pixels, so the
|
|
17
|
+
Windows gap that stops `verify-visual` does not apply. Entries `E-17` to `E-24` are `EVIDENCE.md`;
|
|
18
|
+
`Axiome` marks a rule this project imposes on itself.
|
|
19
|
+
|
|
20
|
+
## Non-negotiables
|
|
21
|
+
|
|
22
|
+
- **No capture decides success, no assertion touches rendered text.** A screenshot proves what was
|
|
23
|
+
painted, not what the command did; readable are accessibility labels, `bounds()` and declared
|
|
24
|
+
actions — never a sentence, never a positive "enabled" state (`E-19`).
|
|
25
|
+
- **Wait for a state, never sleep.** A poll on a named observable with a deadline replaces every
|
|
26
|
+
fixed delay, even one that works: a delay is a bet on the machine (`Axiome`).
|
|
27
|
+
- **One command, one idempotent effect.** Sending it twice leaves the same state; an impossible
|
|
28
|
+
command returns an explicit error and a non-zero exit, never a silent no-op (`Axiome`).
|
|
29
|
+
- **Never the user's data.** Every probe opens a throwaway store under a temporary directory; a
|
|
30
|
+
probe that cannot prove which store it opened stops (`Axiome`).
|
|
31
|
+
- **Read the tree in-process.** AccessKit pushes its tree by function call inside the app; a third
|
|
32
|
+
process sees UIA, NSAccessibility or AT-SPI, never AccessKit (`E-24`).
|
|
33
|
+
|
|
34
|
+
## 1. Read the declared surface
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cargo run -p <app> -- --help # the app's own subcommands
|
|
38
|
+
cargo run -p <app> -- --selftest # exit code only, no state
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
There is no probe binary: the toolkit ships no companion CLI (`E-18`). Driving comes from the app's
|
|
42
|
+
own surface — subcommands, `--selftest`, the JSON bridge — plus tests built with `test-support`. A
|
|
43
|
+
command the app does not declare is not a command: name it and stop.
|
|
44
|
+
|
|
45
|
+
## 2. Start on a throwaway store
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
store="$(mktemp -d)"; cargo run -p <app> -- --store "$store" & pid=$!
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The temp path is passed explicitly, never defaulted. Register the kill and the `rm -rf "$store"` on
|
|
52
|
+
every exit path before sending anything.
|
|
53
|
+
|
|
54
|
+
## 3. Send one named command
|
|
55
|
+
|
|
56
|
+
One verb, one effect. Record the envelope — verb, arguments, timestamp — verbatim, because it goes
|
|
57
|
+
into the report. A command that would change unrelated state is two commands; split it.
|
|
58
|
+
|
|
59
|
+
## 4. Wait on the observable
|
|
60
|
+
|
|
61
|
+
Poll the state the command is supposed to change, up to a deadline (5 s by default, 30 s when it
|
|
62
|
+
triggers a build). On deadline, report the last observed state and the timeout itself; "it did not
|
|
63
|
+
work" is not an observation. Loop and failure shapes: `references/wait-and-read.md`.
|
|
64
|
+
|
|
65
|
+
## 5. Verify in the tree, not on the screen
|
|
66
|
+
|
|
67
|
+
Readable: `NodeId`, `Role`, `label`/`description`/`value`, `bounds`, declared `Action`s (`E-24`). A
|
|
68
|
+
check names the node by role and label and asserts a geometric delta or the arrival of a new node —
|
|
69
|
+
never a sentence, never that something is enabled (`E-19`). Read through the bridge, in the same
|
|
70
|
+
process: an external inspector is a different technology (`E-24`).
|
|
71
|
+
|
|
72
|
+
## 6. Report and clean up
|
|
73
|
+
|
|
74
|
+
Three facts: the command envelope, the state before and after, the deadline in milliseconds and
|
|
75
|
+
whether it was hit. Then kill the process, delete the store, show the user's store with the mtime
|
|
76
|
+
it had at start.
|
|
77
|
+
|
|
78
|
+
## Done when
|
|
79
|
+
|
|
80
|
+
- The report names one command, the state before, the state after, and the deadline that bounded it.
|
|
81
|
+
- No image file was produced; the temp store and the process are gone.
|
|
82
|
+
- The user's store mtime is unchanged from the pre-read.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Wait and read
|
|
2
|
+
|
|
3
|
+
The deep half of `probe`: what a wait is made of, what the tree gives back, and how a probe fails.
|
|
4
|
+
|
|
5
|
+
## The wait
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
send(verb, args) # step 3, once
|
|
9
|
+
deadline = now() + budget
|
|
10
|
+
loop:
|
|
11
|
+
state = read(selector) # one tree read, no render
|
|
12
|
+
if state satisfies predicate: return state
|
|
13
|
+
if now() > deadline: return TIMEOUT with last state
|
|
14
|
+
sleep(poll_interval) # 20-50 ms, yield, never a batch sleep
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
A fixed delay is a bet on the machine. It loses on a cold build, on an image decode, on a lazy
|
|
18
|
+
layout pass, and it wins silently when the state was already true — which is why the defect survives
|
|
19
|
+
review (`Axiome`). The poll interval is a cost knob, not a correctness knob: the predicate and the
|
|
20
|
+
deadline decide.
|
|
21
|
+
|
|
22
|
+
## The predicate
|
|
23
|
+
|
|
24
|
+
Write it as one clause over the tree, before sending the command:
|
|
25
|
+
|
|
26
|
+
- a node appears: role `button`, label `Save changes`, previously absent;
|
|
27
|
+
- a geometry moves: the same node's `bounds` changes by more than 0 in height;
|
|
28
|
+
- a value changes: `value` of the node carrying role `text_input` differs from the pre-read.
|
|
29
|
+
|
|
30
|
+
A predicate that needs two clauses is usually two commands. A predicate that can be read before the
|
|
31
|
+
command is the pre-read: take it, so the report shows a delta rather than a state.
|
|
32
|
+
|
|
33
|
+
## The tree
|
|
34
|
+
|
|
35
|
+
AccessKit's schema carries `NodeId`, `Role`, `label`/`description`/`value`, `bounds`, and declared
|
|
36
|
+
`Action`s (`EVIDENCE.md` `E-24`). What it does not carry is the rendered text: there is no query for
|
|
37
|
+
"the screen says", and no positive assertion for "this control is enabled" (`E-19`). Text content is
|
|
38
|
+
checked where it is stored, or by the code that stores it — not here.
|
|
39
|
+
|
|
40
|
+
The tree is pushed in-process by function call (`E-24`). A probe that shells out to an accessibility
|
|
41
|
+
inspector is reading UIA, NSAccessibility or AT-SPI: same user, different tree, one render behind.
|
|
42
|
+
Read through the app's bridge.
|
|
43
|
+
|
|
44
|
+
## Three failure shapes
|
|
45
|
+
|
|
46
|
+
| Shape | What it means | What to report |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| timeout | the state never arrived within the budget | last observed state, budget, command |
|
|
49
|
+
| ambiguity | two nodes match role and label | both ids, and stop: never pick the first |
|
|
50
|
+
| stale id | the node id is gone after a re-render | the id, the read that lost it |
|
|
51
|
+
|
|
52
|
+
Ambiguity is a failure, not a coin flip: a selector that matches twice is a selector to tighten
|
|
53
|
+
(`Axiome`).
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: replicate-ui
|
|
3
|
+
description: Rebuild one screen from screenshots of another application. Use when the user hands over captures and asks for that screen, or when a "make it look like this app" request has no measurement yet.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Replicate UI
|
|
8
|
+
|
|
9
|
+
Turn captures of another application into one screen of ours, by measuring the picture before the
|
|
10
|
+
first line of layout exists. A capture is an input to measure, not a target to diff: this step
|
|
11
|
+
extracts numbers, then the normal chain builds from them. Judging the result against the capture is
|
|
12
|
+
`verify-visual`; deciding what the screen should be is `gpui-kit-design-guides` upstream.
|
|
13
|
+
|
|
14
|
+
## Non-negotiables
|
|
15
|
+
|
|
16
|
+
- **Measure before coding.** No layout line before the capture has yielded numbers: box sizes,
|
|
17
|
+
paddings, gaps, radii, font sizes, colours. A guessed value is a defect with a friendly name.
|
|
18
|
+
- **One pass per capture.** The capture is measured once, and the numbers are written where the
|
|
19
|
+
build reads them. Reopening the PNG to "check again" replaces measurement with memory.
|
|
20
|
+
- **Never compare two captures against each other.** Capture vs capture answers nothing: the only
|
|
21
|
+
comparison is our running window against the capture, and it belongs to `verify-visual`.
|
|
22
|
+
- **No pixel-perfect claim without a measurement.** "Looks identical" is not a sentence about
|
|
23
|
+
software; a value, its unit and its origin are.
|
|
24
|
+
- **Structure and metrics travel, identity does not.** No logo, no icon, no copy, no product name
|
|
25
|
+
from the other app.
|
|
26
|
+
- **No capture, no step.** A screen asked for from memory stops here: ask for the capture, name
|
|
27
|
+
what is missing, never invent the target.
|
|
28
|
+
|
|
29
|
+
## 1. Inventory what you were given
|
|
30
|
+
|
|
31
|
+
Name each capture. Note its scale (a 2x capture read as 1x doubles every number), and what it
|
|
32
|
+
covers: one state, or several states of the same screen. Write the list down and repeat it in the
|
|
33
|
+
report, so a missing state is visible before the build starts.
|
|
34
|
+
|
|
35
|
+
## 2. Measure, one pass, into a table
|
|
36
|
+
|
|
37
|
+
Per region: geometry as a share of the window, then padding, gap, corner radius, border width, type
|
|
38
|
+
size and weight, and colours sampled from the PNG. Convert to our scale and give the unit. A value
|
|
39
|
+
you cannot source stays empty and becomes a question — an invented number survives review and fails
|
|
40
|
+
in the window.
|
|
41
|
+
|
|
42
|
+
## 3. Say what the capture cannot show
|
|
43
|
+
|
|
44
|
+
Hover, focus, disabled, error, empty, resize and dark mode are usually absent from a static image.
|
|
45
|
+
List them as open questions, take the default from `gpui-kit-design-guides`, and record which
|
|
46
|
+
default you took.
|
|
47
|
+
|
|
48
|
+
## 4. Build from the table
|
|
49
|
+
|
|
50
|
+
Only now. Layout from the measured numbers, GPUI Kit components first and a custom `canvas` last.
|
|
51
|
+
Keep the mapping row -> line, so a reviewer checks a measurement without opening the image.
|
|
52
|
+
|
|
53
|
+
## 5. Hand the proof over
|
|
54
|
+
|
|
55
|
+
A rebuilt screen is finished when it has been captured and compared: that is `verify-visual`, and it
|
|
56
|
+
fails on a difference rather than a feeling. Never call the screen final because it resembles the
|
|
57
|
+
picture.
|
|
58
|
+
|
|
59
|
+
## Done when
|
|
60
|
+
|
|
61
|
+
- A measurement table exists for every capture in scope, every value traceable to the capture.
|
|
62
|
+
- The screen renders from those numbers, and each layout decision points at a row.
|
|
63
|
+
- The states the capture cannot show are listed, with the default taken and its source.
|
|
64
|
+
- `verify-visual` is named as the next step, not performed here.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rust
|
|
3
|
+
description: Decide ownership, errors, unsafe boundaries and public API in Rust before the code is written. Use when shaping a function signature, choosing between borrowing, cloning and Arc, picking thiserror or anyhow, writing an unsafe block, choosing threads or async, or adding a dependency.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Rust
|
|
7
|
+
|
|
8
|
+
This step settles what the compiler makes expensive to change afterwards: who owns each
|
|
9
|
+
value, which error type each layer returns, where `unsafe` may start, what the public
|
|
10
|
+
surface promises, and which crates enter the build. It runs before the first function
|
|
11
|
+
body, so the body gets written once.
|
|
12
|
+
|
|
13
|
+
The long form lives in `references/`: `errors.md` for the library/application error split
|
|
14
|
+
and `unsafe.md` for the shape of a block that can be justified. This skill states the floor
|
|
15
|
+
and the decisions, not the tutorial. The body is written by `implement`, which runs `tdd` at
|
|
16
|
+
the agreed seams; reviewing it is `code-review`, and a failure with no reproduction belongs
|
|
17
|
+
to `diagnosing-bugs` first.
|
|
18
|
+
|
|
19
|
+
Sources are tagged inline — `Book`, `Ref`, `API`, `Nomicon`, `AsyncBook`, `std`, `anyhow`
|
|
20
|
+
— and resolved in `## Sources`. `Axiome` marks a choice this project makes on its own;
|
|
21
|
+
`Hypothèse` marks a rule no documentation backs.
|
|
22
|
+
|
|
23
|
+
## Non-negotiables
|
|
24
|
+
|
|
25
|
+
- **Borrow before clone.** A parameter is `&T` unless the function stores the value,
|
|
26
|
+
mutates it, or consumes it.
|
|
27
|
+
- **One error vocabulary per crate.** A library returns its own `thiserror` enum, an
|
|
28
|
+
application returns `anyhow::Result`; both in one `Cargo.toml` is a defect. `Axiome`
|
|
29
|
+
- **Every `unsafe` block opens with `// SAFETY:`** naming the invariant and who
|
|
30
|
+
guarantees it.
|
|
31
|
+
- **Every public type implements `Debug`** (`API` C-DEBUG), and every public enum that can
|
|
32
|
+
grow carries `#[non_exhaustive]` (`Ref`, `non_exhaustive`).
|
|
33
|
+
- **Every dependency pays one written line** saying what it does that `std` cannot.
|
|
34
|
+
`Axiome`
|
|
35
|
+
- **Async carries a written reason.** Threads stay the default until a measurement or an
|
|
36
|
+
IO fan-out asks otherwise. `Axiome`
|
|
37
|
+
|
|
38
|
+
## 1. Fix ownership in the signature
|
|
39
|
+
|
|
40
|
+
Ownership is fixed by the language: one owner, dropped when it leaves scope (`Book` §4.1).
|
|
41
|
+
What is left to decide is what the callee takes.
|
|
42
|
+
|
|
43
|
+
| The function | Signature |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| only reads the value | `&T` |
|
|
46
|
+
| reads text or a sequence | `&str`, `&[T]` — `Book` §4.3 shows `&str` accepting both |
|
|
47
|
+
| writes | `&mut T` |
|
|
48
|
+
| keeps the value after it returns | `T` by value |
|
|
49
|
+
| shares one value across threads | `Arc<T>` |
|
|
50
|
+
|
|
51
|
+
One input reference: elision hands the output that lifetime. Two inputs plus an output
|
|
52
|
+
reference: the lifetime gets written out, because nothing infers it (`Ref`, lifetime
|
|
53
|
+
elision). A signature that keeps needing a lifetime parameter is a candidate for owning
|
|
54
|
+
its return value instead of borrowing one. `Hypothèse`
|
|
55
|
+
|
|
56
|
+
## 2. Clone where the value must live on
|
|
57
|
+
|
|
58
|
+
Clone when the clone is the design: handing the caller an independent value, storing what
|
|
59
|
+
was lent, moving data into a thread. `Axiome` Sharing is cheaper than copying —
|
|
60
|
+
`Arc::clone` creates "another pointer to the same allocation, increasing the strong
|
|
61
|
+
reference count" (`std`, `Arc` → `Clone`). Clone in the constructor, borrow in the loop;
|
|
62
|
+
a clone on a hot path turns a borrow problem into an allocation problem. `Hypothèse`
|
|
63
|
+
|
|
64
|
+
## 3. Place the error type
|
|
65
|
+
|
|
66
|
+
| Where the error surfaces | Type |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| a library crate | an enum deriving `thiserror::Error` |
|
|
69
|
+
| an application crate | `anyhow::Result<T>`, with `.context("...")` on each fallible call |
|
|
70
|
+
| a library forced to return one opaque error | `Box<dyn std::error::Error + Send + Sync>` |
|
|
71
|
+
|
|
72
|
+
anyhow states the split itself: it suits code that does not care which type it returns,
|
|
73
|
+
"common in application code", while a library "wants to design your own dedicated error
|
|
74
|
+
type(s)" (`anyhow` README, *Comparison to thiserror*). An error type stays meaningful and
|
|
75
|
+
well-behaved — `Display` for humans, `source()` for the chain, `std::error::Error` for
|
|
76
|
+
callers (`API` C-GOOD-ERR). Shapes and one example per side: `references/errors.md`.
|
|
77
|
+
|
|
78
|
+
## 4. Write the invariant before the unsafe block
|
|
79
|
+
|
|
80
|
+
Soundness is non-local: the correctness of an unsafe operation "necessarily depends on the
|
|
81
|
+
state established by otherwise 'safe' operations" (`Nomicon`, *Working with Unsafe*). So
|
|
82
|
+
the invariant is written where the safe code that could break it can read it, and the
|
|
83
|
+
block states why its preconditions hold. An `unsafe fn` is public API: its docs carry a
|
|
84
|
+
`# Safety` section listing every invariant the caller must uphold (`API` C-FAILURE). The
|
|
85
|
+
form is in `references/unsafe.md`.
|
|
86
|
+
|
|
87
|
+
## 5. Promise only what you can keep
|
|
88
|
+
|
|
89
|
+
- The common traits where they mean something: `Copy`, `Clone`, `Eq`, `PartialEq`, `Ord`,
|
|
90
|
+
`PartialOrd`, `Hash`, `Display`, `Default` (`API` C-COMMON-TRAITS), plus `From` and
|
|
91
|
+
`AsRef` for conversions (`API` C-CONV-TRAITS). A `Debug` representation is never empty
|
|
92
|
+
(`API` C-DEBUG-NONEMPTY).
|
|
93
|
+
- `#[non_exhaustive]` on a public struct, enum or variant that may grow fields later; it
|
|
94
|
+
has no effect inside the defining crate (`Ref`, `non_exhaustive`).
|
|
95
|
+
- A trait only this crate may implement is sealed behind a private supertrait
|
|
96
|
+
(`API` C-SEALED).
|
|
97
|
+
- Private fields and a fallible constructor, so the invariant is established in one place
|
|
98
|
+
(`API` C-STRUCT-PRIVATE, C-VALIDATE).
|
|
99
|
+
- `#[must_use]` on a return the caller must act on: a result, a guard, a builder
|
|
100
|
+
(`Ref`, `must_use`).
|
|
101
|
+
|
|
102
|
+
## 6. Pick the concurrency model once
|
|
103
|
+
|
|
104
|
+
Threads reuse synchronous code and suit "a small number of tasks"; async pays off
|
|
105
|
+
"especially for workloads with a large amount of IO-bound tasks" (`AsyncBook`, *Why Async →
|
|
106
|
+
Async vs threads in Rust*). Moving between the two is "major refactoring work", public
|
|
107
|
+
interface included (`AsyncBook`, same page), so the choice is made here and then kept.
|
|
108
|
+
CPU-bound work wants threads. A library exposes its synchronous core; the binary owns the
|
|
109
|
+
runtime and its entry attribute. `Axiome`
|
|
110
|
+
|
|
111
|
+
## 7. Justify each dependency
|
|
112
|
+
|
|
113
|
+
One line per crate, written before it enters `Cargo.toml`: what it does that `std` cannot,
|
|
114
|
+
or it does not enter. `Axiome` The line lives in the decision block below, where review
|
|
115
|
+
reads it.
|
|
116
|
+
|
|
117
|
+
## Write the decision block
|
|
118
|
+
|
|
119
|
+
```markdown
|
|
120
|
+
## Decisions (module `config`)
|
|
121
|
+
- Ownership: `Config::parse(&str) -> Result<Config>`; `Runtime` holds `Arc<Config>`.
|
|
122
|
+
- Errors: library enum `ConfigError`, `thiserror`, `#[non_exhaustive]`.
|
|
123
|
+
- Concurrency: 4 threads, no async runtime.
|
|
124
|
+
- Unsafe: one block in `ring.rs`, invariant `head <= len`.
|
|
125
|
+
- Dependencies: `thiserror` — derives `Display` and `source()`; `std` cannot.
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
This block is the artifact of the step: it goes in the ticket, or at the top of the module
|
|
129
|
+
documentation when there is no ticket.
|
|
130
|
+
|
|
131
|
+
## Sources
|
|
132
|
+
|
|
133
|
+
- `Book` — The Rust Book, https://doc.rust-lang.org/book/ — consulted 2026-11-28
|
|
134
|
+
- `Ref` — The Rust Reference, https://doc.rust-lang.org/reference/ — consulted 2026-11-28
|
|
135
|
+
- `API` — Rust API Guidelines, https://rust-lang.github.io/api-guidelines/ — consulted 2026-11-28
|
|
136
|
+
- `Nomicon` — The Rustonomicon, https://doc.rust-lang.org/nomicon/ — consulted 2026-11-28
|
|
137
|
+
- `AsyncBook` — Asynchronous Programming in Rust, https://rust-lang.github.io/async-book/ — consulted 2026-11-28
|
|
138
|
+
- `std` — std documentation, https://doc.rust-lang.org/std/ — consulted 2026-11-28
|
|
139
|
+
- `anyhow` — anyhow README, https://docs.rs/anyhow — consulted 2026-11-28
|
|
140
|
+
|
|
141
|
+
## Done when
|
|
142
|
+
|
|
143
|
+
- The decision block names ownership for each new signature, the error type, the
|
|
144
|
+
concurrency model, every `unsafe` block with its invariant, and one line per dependency.
|
|
145
|
+
- `grep -rn -B1 'unsafe {' src` shows a `// SAFETY:` line above every block.
|
|
146
|
+
- Every new public type derives `Debug`; every new public enum that can grow carries
|
|
147
|
+
`#[non_exhaustive]`.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Errors on both sides of the boundary
|
|
2
|
+
|
|
3
|
+
An error type is a contract, and it sits on one side of the crate boundary or the other. A
|
|
4
|
+
library hands back exactly the information it chose; an application wants the failure to
|
|
5
|
+
surface with context. `Fait vérifié` (anyhow README, *Comparison to thiserror*, consulted
|
|
6
|
+
2026-11-28): « Use Anyhow if you don't care what error type your functions return […] This
|
|
7
|
+
is common in application code. » and « Use thiserror if you are a library that wants to
|
|
8
|
+
design your own dedicated error type(s) so that on failures the caller gets exactly the
|
|
9
|
+
information that you choose. » The split below is that advice turned into a project rule.
|
|
10
|
+
`Axiome`
|
|
11
|
+
|
|
12
|
+
## Library side — `thiserror`
|
|
13
|
+
|
|
14
|
+
```rust
|
|
15
|
+
// crates/config/src/error.rs
|
|
16
|
+
#[derive(Debug, thiserror::Error)]
|
|
17
|
+
#[non_exhaustive]
|
|
18
|
+
pub enum ConfigError {
|
|
19
|
+
#[error("config file {} is not readable", path.display())]
|
|
20
|
+
Read {
|
|
21
|
+
path: std::path::PathBuf,
|
|
22
|
+
#[source]
|
|
23
|
+
source: std::io::Error,
|
|
24
|
+
},
|
|
25
|
+
#[error("unknown key `{0}`")]
|
|
26
|
+
UnknownKey(String),
|
|
27
|
+
#[error(transparent)]
|
|
28
|
+
Yaml(#[from] serde_yaml::Error),
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- `#[error("...")]` generates `Display`; `#[from]` generates `From` and implies `#[source]`
|
|
33
|
+
on that field; `#[error(transparent)]` forwards both `Display` and the chain (thiserror
|
|
34
|
+
README). `#[from]` is what lets `?` convert at the call site.
|
|
35
|
+
- `#[non_exhaustive]` keeps a new variant an additive change: the attribute "indicates that a
|
|
36
|
+
type or variant may have more fields or variants added in the future" (`Ref`).
|
|
37
|
+
- The derive also implements `std::error::Error`, which is what "error types are meaningful
|
|
38
|
+
and well-behaved" asks for (`API` C-GOOD-ERR).
|
|
39
|
+
- No `anyhow` in this crate's `Cargo.toml`. `Axiome`
|
|
40
|
+
|
|
41
|
+
## Application side — `anyhow`
|
|
42
|
+
|
|
43
|
+
```rust
|
|
44
|
+
// crates/app/src/main.rs
|
|
45
|
+
use anyhow::Context;
|
|
46
|
+
|
|
47
|
+
fn main() -> anyhow::Result<()> {
|
|
48
|
+
let cfg = Config::parse(&path).with_context(|| format!("loading {}", path.display()))?;
|
|
49
|
+
run(cfg).context("running the collector")?;
|
|
50
|
+
Ok(())
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- `.context(...)` records what the code was doing without erasing the source; the printed
|
|
55
|
+
chain keeps the message and the underlying error.
|
|
56
|
+
- `?` across distinct library error types works because each converts into `anyhow::Error`
|
|
57
|
+
at that boundary.
|
|
58
|
+
- `main() -> anyhow::Result<()>` is the whole policy: no catch-all `match`, no `.unwrap()`
|
|
59
|
+
on a failure path; exit codes are decided at the outermost command only.
|
|
60
|
+
- No `thiserror` derive in this crate. `Axiome`
|
|
61
|
+
|
|
62
|
+
One crate, one style: the library owns the enum, the application owns the `anyhow::Result`,
|
|
63
|
+
and the boundary between them is a single `?`.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# A justifiable unsafe block
|
|
2
|
+
|
|
3
|
+
Safe Rust is the guarantee that no safe code causes undefined behaviour. An unsafe
|
|
4
|
+
operation receives that guarantee from the state set up by the surrounding safe code, and
|
|
5
|
+
that dependence is non-local: the Nomicon's own example makes a function unsound by
|
|
6
|
+
changing `<` to `<=` in code that contains no `unsafe`. Its conclusion, verbatim: "the
|
|
7
|
+
soundness of our unsafe operations necessarily depends on the state established by
|
|
8
|
+
otherwise 'safe' operations" (`Nomicon`, *Working with Unsafe*).
|
|
9
|
+
|
|
10
|
+
Two consequences, and they are the whole file: the invariant is written down, and the block
|
|
11
|
+
says why it holds here.
|
|
12
|
+
|
|
13
|
+
## Shape
|
|
14
|
+
|
|
15
|
+
```rust
|
|
16
|
+
/// Writes `value` into the free slot at `head`.
|
|
17
|
+
///
|
|
18
|
+
/// # Safety
|
|
19
|
+
///
|
|
20
|
+
/// `head < slots.len()`, and the slot at `head` holds no live value.
|
|
21
|
+
pub unsafe fn push_unchecked(&mut self, value: T) {
|
|
22
|
+
// SAFETY: the caller guarantees `head < slots.len()`, and `slots` is a
|
|
23
|
+
// fixed-size array owned by `self`, so its length never changes.
|
|
24
|
+
*self.slots.get_unchecked_mut(self.head).as_mut_ptr() = value;
|
|
25
|
+
|
|
26
|
+
self.head += 1;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Four things are present, and review checks each one:
|
|
31
|
+
|
|
32
|
+
1. `// SAFETY:` directly above the block, not above the function.
|
|
33
|
+
2. The **invariant**: the one statement that must be true for the operation to be sound.
|
|
34
|
+
3. **Who guarantees it**: the caller's documented contract, the type's own fields, or a
|
|
35
|
+
check on the line above.
|
|
36
|
+
4. The **public `# Safety` doc section** on an `unsafe fn`, listing what the caller must
|
|
37
|
+
uphold: "Unsafe functions should be documented with a 'Safety' section that explains all
|
|
38
|
+
invariants that the caller is responsible for upholding to use the function correctly"
|
|
39
|
+
(`API` C-FAILURE).
|
|
40
|
+
|
|
41
|
+
## Deciding whether the block is justified
|
|
42
|
+
|
|
43
|
+
Write the invariant as a sentence first. If the sentence needs "and then the caller must
|
|
44
|
+
remember", the invariant belongs in a type or a check instead of a comment. A block whose
|
|
45
|
+
invariant cannot be stated in one sentence is a block to replace with a safe formulation.
|
|
46
|
+
`Axiome`
|
|
47
|
+
|
|
48
|
+
State what the block assumes but does not prove, even when the assumption is obvious:
|
|
49
|
+
`get_unchecked_mut` is sound here only because `slots` has a fixed length. An unproven
|
|
50
|
+
assumption that is not written is the failure mode the Nomicon describes. `Axiome`
|
|
51
|
+
|
|
52
|
+
## Scope
|
|
53
|
+
|
|
54
|
+
Keep one block per operation. A single `unsafe` block wrapping a whole function body hides
|
|
55
|
+
which operation needed the permission and gives the next reader a wider unsafe area to
|
|
56
|
+
reason about. `Axiome`
|
|
57
|
+
|
|
58
|
+
`deny(unsafe_code)` at the crate root, with `#[allow(unsafe_code)]` on the one module that
|
|
59
|
+
needs it, keeps the unsafe surface greppable. `Axiome`
|
|
60
|
+
|
|
61
|
+
Do not write `forbid(unsafe_code)` if any module needs an exemption: `forbid` cannot be
|
|
62
|
+
undone by `allow` (rustc E0453), so the crate would not compile. The shipped profiles use
|
|
63
|
+
`forbid` on purpose — a project that turns out to need `unsafe` relaxes the manifest to
|
|
64
|
+
`deny` in the same commit that adds the block, and says so. `Fait vérifié` (rustc E0453,
|
|
65
|
+
2026-11-28).
|