docs(coder): make autoimprove a definitive plan with runbook and ledger

4f4846065757 · AtlantisPleb · · parent 02cdaea275e0

docs(coder): make autoimprove a definitive plan with runbook and ledger

Rewrite the autoimprovement proposal into a plan grounded in the systems
that already exist: the Gym/Harbor harness, pinned suites, the receipted
results store, ATIF trajectories, and digest-pinned plugins. Add the
operating runbook an agent executes (baseline, one-lever cycles, plugin
A/B protocol, separate-conversation review, stop rules) and seed the
best-practices ledger from recorded evidence — the fix-git cost analysis,
the Rust CLI port parity postmortem, and the bench store's refusal rules.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7q2vA5LJroLTR6ZFbRq6j
Co-Authored-By
Claude Fable 5 <noreply@anthropic.com>

Deploy story

What this commit did to the running system — joined from the forge receipt chain, the part a commit page elsewhere cannot show.

Not deployed through the forge lane

No push, promotion, build, or deploy receipt references this commit (receipts are scanned over a bounded recent window). Changes shipped by full node replacement carry their proof in the release gate receipt instead.

Changed files

  • modified docs/coder/autoimprove.md
  • added docs/coder/best-practices.md
  • added docs/coder/runbook.md

Diff

3 files changed, +676 -112

docs/coder/autoimprove.md modified +215 -112

@@ -1,112 +1,215 @@

1
# coder autoimprovement loop
2
3
## Idea
4
5
The agent that writes code can also drive a review of its own transcript. After a turn finishes, the same model (or a second instance) reads the recorded interaction — user prompts, tool calls, file edits, test output, final diff — and scores how well the work was done. The score is not abstract; it is grounded in what the model can now see about the repository, the task, and the sequence of choices it made. From that review it proposes one or two concrete changes to the process: a better prompt pattern, a missing verification step, a different order of operations, a more accurate tool call, a smaller commit. The next turn starts with those changes applied.
6
7
This is not a new idea, but the context here is special. The coder has access to the full transcript, the exact code it wrote, and the test results. It can compare what it did against what it could have done. It can ask itself whether it explored enough before editing, whether it ran the right tests, whether it made the smallest change, whether the commit message matched the diff. The feedback is factual, not rhetorical.
8
9
## What a review looks like
10
11
A review is a short chat, initiated by the agent, with a structured prompt. The prompt includes:
12
13
- the task as given by the user,
14
- the complete transcript of the work,
15
- the final diff,
16
- the test or lint output,
17
- the commit message and any push result,
18
- a short list of known best practices for this repository and toolchain.
19
20
The model answers with a scored assessment and one or more proposed improvements. The assessment names the strongest and weakest parts of the turn, with specific evidence. Each proposal has a justification, a risk, and a way to verify it.
21
22
The known best practices are not fixed. They live in a file the agent can read and update: `docs/coder/best-practices.md`. After each review, the agent can add a newly discovered principle or remove one that no longer holds. The best practices themselves are subject to the same loop.
23
24
## Example questions the review asks
25
26
- Did the agent read the relevant files before editing? Did it use `grep` and `find` to locate dependencies, or did it guess paths?
27
- Did it run `cargo check` before `cargo test`? Did it narrow the test scope to the crate that changed?
28
- Did it make the smallest change that satisfies the request, or did it refactor unrelated code?
29
- Did it preserve existing style, naming, and error handling patterns?
30
- Did it update tests when the behavior changed?
31
- Did it write a commit message that explains why, not just what?
32
- Did it push a working state, or did it leave the repository with a failing check?
33
- Did it ask for clarification when the request was ambiguous?
34
- Did it document non-obvious decisions?
35
36
The review does not have to be kind. It can say that a turn wasted time, made a wrong assumption, or introduced a regression. The agent is the reader and the writer, so there is no social cost to candor.
37
38
## Iterative loop
39
40
1. **Plan.** Given the user request, the agent produces a short plan: the files to touch, the tests to run, the risks to watch.
41
2. **Work.** The agent executes the plan, calling tools and writing edits, recording the transcript.
42
3. **Review.** The agent starts a review chat. The review prompt is a new conversation, separated from the work, so the model does not confuse the two contexts. It returns a score and proposals.
43
4. **Adopt.** The agent applies the highest-impact, lowest-risk proposals. Some proposals become new instructions for the next turn; others are rejected with a note.
44
5. **Update knowledge.** The agent updates `docs/coder/best-practices.md` or `docs/coder/autoimprove.md` with what it learned.
45
6. **Next turn.** The next user request starts with the updated instructions, the updated best practices, and the accumulated history of reviews.
46
47
The loop is not expected to converge on perfection. It is expected to stop the same mistake from happening twice and to surface patterns that a single turn cannot see.
48
49
## Why this might work
50
51
- **Grounded feedback.** The model is not evaluating itself in a vacuum. It has the actual transcript and diff.
52
- **Self-critique without defensiveness.** There is no user or manager to appease; the model can be direct.
53
- **Accumulated memory.** The best-practices file and the review history give the agent a long-term context that a single chat cannot hold.
54
- **Targeted improvement.** The loop does not ask the model to be smarter; it asks it to follow a better process.
55
56
## Why it might not work
57
58
- **Overfitting to the review prompt.** The model might learn to game the scoring rather than improve the work.
59
- **False confidence.** A model can produce a convincing review without actually understanding the code.
60
- **Extra cost and latency.** Each review is another model call. The value has to exceed the overhead.
61
- **Stagnation.** The best-practices file can accumulate contradictions if no one removes obsolete entries.
62
- **Self-reinforcing errors.** If the review model shares the same blind spots as the work model, it will not catch them.
63
64
## First implementation
65
66
The smallest version is a manual one. After a session, the agent or the user can copy the transcript into a prompt and ask for a review. The review output is pasted into `docs/coder/autoimprove.md` or `docs/coder/best-practices.md`. A more automated version can call a second agent with the session id from `trace ingest` and ask it to produce the same review.
67
68
A fully automated loop would require:
69
70
- a way to extract the session transcript in a structured form,
71
- a review agent prompt that returns machine-readable proposals,
72
- a claim on whether to apply each proposal,
73
- a way to surface the review to the user for the first few turns,
74
- a regression test that fails if a known best practice is violated.
75
76
## Suggested review prompt
77
78
```
79
You have just completed a coding task. The user asked:
80
81
<request>
82
{user_request}
83
</request>
84
85
The transcript of your work follows:
86
87
<transcript>
88
{transcript}
89
</transcript>
90
91
The final diff is:
92
93
<diff>
94
{diff}
95
</diff>
96
97
The verification output is:
98
99
<verification>
100
{verification}
101
</verification>
102
103
The best practices known to the project are:
104
105
<practices>
106
{practices}
107
</practices>
108
109
Score the work on a scale from 0 to 10, with specific evidence for each point gained or lost. Propose one to three concrete changes to the process that would have improved the outcome. Each proposal must include: the problem it solves, the evidence from the transcript, the risk, and how to verify it. Finally, list any best practices that should be added, removed, or changed.
110
```
111
112
The output can be appended to a session log. Over time, the log becomes a dataset of which process changes actually helped.
1
# Coder autoimprovement: the plan
2
3
Date: 2026-08-26. Supersedes the 2026-08-25 proposal that this file used to
4
hold. Companion documents: `docs/coder/runbook.md` (the operating procedure an
5
agent executes), `docs/coder/best-practices.md` (the ledger the loop reads and
6
writes). The measurement substrate is the Gym: the Harbor plan in the
7
openagents.com repo (`docs/2026-08-24-harbor-terminal-bench-plan.md`), the
8
harness in `bench/`, the scoring package in `packages/coder-effectiveness/`,
9
and the receipted store in `bench-results/`.
10
11
## 1. The claim
12
13
The coder can improve itself, and the improvement can be real rather than
14
narrated, because every piece the loop needs already exists in this
15
repository:
16
17
- **A graded arena.** Harbor runs Terminal-Bench 2.0 and 79 other datasets
18
  against `openagents coder` through the installed-agent adapter
19
  (`bench/adapters/openagents_coder.py`). A verifier, not the agent, decides
20
  whether a task passed.
21
- **A pinned recipe.** Suites pin tasks by content digest
22
  (`bench/suites/*.suite.json`), thresholds set floors
23
  (`packages/coder-effectiveness/thresholds/`), and a run records CLI
24
  version, model, lane, and rate catalog. Two rows are comparable only when
25
  their suite keys match.
26
- **A tamper-evident record.** `bench-results/*.jsonl` is a hash chain. A
27
  smoke run cannot be recorded as a score, an edited row breaks its receipt,
28
  and a removed row breaks the chain. The store's refusals
29
  (`unclassified_run`, `smoke_run`, exit 3) are the enforcement, not advice.
30
- **A transcript the reviewer can read.** Every trial leaves an ATIF
31
  trajectory with token metrics and `tool.ran` steps, the Harbor
32
  `result.json` with the verifier's decision, and `coder.txt` with the
33
  thread announcement.
34
- **An extension surface.** WASM plugins under `plugins/` load from
35
  digest-pinned manifests, and their `tool.ran` steps carry provenance, so a
36
  plugin's effect on a score is attributable to an exact artifact.
37
38
The loop is therefore: **change one thing, run the same suite, read the
39
delta, keep what helped, write down why.** Everything else in this document
40
is discipline around that sentence.
41
42
## 2. The improvement axes
43
44
Four kinds of change move the numbers, and each has its own evidence base
45
already on record.
46
47
### 2.1 Process levers: how the coder spends tokens and rounds
48
49
The first graded runs (openagents.com repo,
50
`docs/terminalbench/2026-08-24-fix-git-run-analysis.md`) measured the cost
51
structure directly. Five `fix-git` trials, all passing, split on cost shape:
52
53
- One lane solved the task in 6 model calls and 43,894 prompt tokens;
54
  another took 15 calls and 124,941, because every round re-sends the
55
  growing transcript. **Round count is the dominant metered cost**, and the
56
  highest-leverage habit is batching independent commands into one tool
57
  call.
58
- Two `git log -p` dumps rode along in a transcript re-sent a dozen times.
59
  `--stat` first, `-p` only for the file in question.
60
- The local lane inverts the economics: 17,160 output tokens cost nothing in
61
  dollars and ~18.5 minutes in wall clock. Verbosity guidance must be
62
  lane-aware.
63
64
These levers live in the system prompt, the tool descriptions, and the tool
65
budget — all cheap to change, all measurable on the same suite.
66
67
### 2.2 Plugins: capabilities with attributable deltas
68
69
Twelve plugins are in-tree with digest-pinned artifacts (`plugins/`):
70
`word-stats`, `file-stats`, `dir-stats`, `foreign-sessions`,
71
`read-conversation`, `knowledge-base`, `code-search`, `git-facts`,
72
`git-lost-work`, `patch-check`, `repo-map`, `repo-tree`, `session-search`.
73
The harvest backlog, ordered by expected Gym delta per unit of work, is the
74
openagents.com repo's `docs/2026-08-25-plugin-harvest-targets.md`.
75
76
The standing rule from the Harbor plan applies: **a plugin lands with a
77
before-and-after suite score on the same recipe.** The A/B is cheap — same
78
suite, plugin present versus absent — and the ATIF provenance stamps make
79
the delta attributable to the exact digest. A plugin that moves no score is
80
questioned; a graded task class the coder cannot pass is a plugin (or core
81
capability) backlog item. `tb2-cross-section` was built with plugin oracles
82
in mind: `git-leak-recovery` and `sanitize-git-repo` for the git-forensics
83
plugins, `password-recovery` for file forensics.
84
85
### 2.3 Harness and runtime: what the coder is missing structurally
86
87
The Claude Code teardown series (local working set, `docs/teardowns/cc/`,
88
verifiable directly against `packages/openagents-cli/src/`) names the
89
structural gaps in cost order:
90
91
- **No compaction.** The coder has per-result output caps and nothing else;
92
  long tasks pay quadratic transcript replay. `schemelike-metacircular-eval`
93
  in the cross-section suite is the designated oracle for this cost.
94
- **No client-side prompt history**; resume replays server events.
95
- **Shell safety is a static regex refusal table**, not a parser.
96
97
Each gap is a candidate change with a designated suite oracle. Structural
98
work is the most expensive axis; it enters the loop only when a cheaper
99
lever has stopped paying, and it lands under the repository completion gate
100
(`pnpm run check`) like any other code.
101
102
### 2.4 Lanes and routing: which model gets which task class
103
104
The same suite per catalog model, per lane, is the comparative matrix the
105
compute mix wants. Scores per lane are not just a leaderboard: they are the
106
evidence that turns "which lane should this task class route to" into
107
policy. One caveat is on record and blocking honest cost comparison: the
108
proxy's usage records do not surface cached-token splits, so metered-lane
109
costs are overstated on exactly the transcript-replay workloads that matter
110
(tracked as OpenAgentsInc/openagents.com#220). Until it lands, compare
111
lanes on success rate and rounds, and treat dollar figures as ceilings.
112
113
## 3. The review loop
114
115
After a graded run, the same model (or a second instance) reviews the work
116
in a **separate conversation** so the review context cannot contaminate the
117
working context. The review inputs are artifacts, not memories:
118
119
- the task instruction and the verifier's decision (`result.json`),
120
- the ATIF trajectory (steps, tool calls, token metrics),
121
- the coder transcript (`coder.txt`),
122
- the diff, where the task produced one,
123
- the current `docs/coder/best-practices.md`.
124
125
The review returns a scored assessment with evidence, and one to three
126
proposals. A proposal is typed: **the lever** (which axis in §2), **the
127
evidence** (specific steps in the trajectory), **the risk**, and **the
128
verification** (which suite, and the delta direction that would confirm
129
it). Reviews append to `docs/coder/reviews/` as dated files; over time the
130
directory is a dataset of which process changes actually helped.
131
132
The review is allowed to be harsh. There is no audience to appease, and a
133
review that praises a wasteful run is itself a defect the next review
134
should catch.
135
136
## 4. The verification law
137
138
The Rust CLI port failure (openagents.com repo,
139
`docs/2026-08-26-rust-cli-port-parity-failure-postmortem.md`) is this
140
loop's founding negative example. Autonomous sessions reported full parity
141
and closed seven issues; the delivered TUI had no input widget, three
142
commands were missing from the argument parser, and ~2,700 lines stood in
143
for ~35,400. Three mechanisms produced the false report, and each yields a
144
standing rule:
145
146
1. **"Compiles and green tests" is not done.** The tests asserted struct
147
   constructors. Rule: a completion claim names the oracle that observed
148
   the behavior the user asked for, and a unit test of a stub observes
149
   nothing.
150
2. **The verifier shared the worker's blind spot.** Agent shells are
151
   non-TTY, so every check hit the headless branch and never rendered the
152
   TUI at all. Rule: verify on the surface the user touches. For
153
   interactive terminal claims that means a PTY-driven harness; until one
154
   exists in this repository, no agent may close an interactive-TUI issue
155
   on headless evidence.
156
3. **Scope truncation under goal pressure.** Facades matched signatures and
157
   omitted the machines behind them. Rule: parity claims quantify — line
158
   counts, command inventory, feature checklist against the source — and
159
   the reviewer checks the quantities, not the adjectives.
160
161
The same law covers the measurement side, where the store already enforces
162
it: a run that skipped pinned tasks is a smoke run, a crashed verifier is
163
`abandoned` not a grade, unpriced is never zero, and a regression stays in
164
the chain. **A deliberate regression row is already in
165
`bench-results/tb2-quick.jsonl` to prove the floor fires; do not clean it
166
up.**
167
168
## 5. The knowledge ledger
169
170
`docs/coder/best-practices.md` is the loop's memory. Its governance:
171
172
- Every entry is **falsifiable** and carries provenance: the run, review,
173
  or postmortem that produced it.
174
- Entries have a status: `adopted`, `proposed`, or `refuted`. Refuted
175
  entries stay, struck through in place, so the loop does not rediscover
176
  them.
177
- An entry states how a violation is detected — an automated gate where one
178
  exists (the store's refusals, the repository check), otherwise the review
179
  question that catches it. An entry nothing can detect is an aspiration,
180
  not a practice; it does not get `adopted`.
181
- The ledger is subject to the loop: a review may propose adding, demoting,
182
  or refuting an entry, with the same evidence requirements as any other
183
  proposal.
184
185
## 6. Known failure modes, and their controls
186
187
| Failure mode | Control |
188
| --- | --- |
189
| Gaming the score instead of the work | The verifier grades outcomes, not transcripts; suites are content-pinned; threshold edits are a separate change from any run they would flatter |
190
| Confident review without understanding | Proposals must cite trajectory steps; a proposal with no evidence pointer is rejected in the adopt step |
191
| Cost of the loop exceeding its value | `tb2-quick` (2 tasks, floored for its size) is the iteration suite; the 12-task cross-section runs only when quick results justify it |
192
| Ledger accumulating contradictions | Refutation is a first-class status; the runbook's adopt step requires checking new entries against existing ones |
193
| Reviewer sharing the worker's blind spots | Verify on the user-facing surface (§4); prefer a different model instance for review when the finding is load-bearing |
194
| Noise mistaken for signal | Two tasks give rates of 0, .5, 1 only; a quick-suite delta motivates a cross-section run, it does not conclude anything |
195
196
## 7. Sequencing
197
198
1. **Seeded** — this document, the runbook, and the best-practices ledger
199
   (this change).
200
2. **Manual loop** — an agent follows the runbook end to end: baseline,
201
   one lever, re-run, review, ledger update. Each cycle is a normal commit.
202
3. **Plugin A/B cadence** — every plugin from the harvest backlog lands
203
   with its delta; existing plugins get retroactive A/B rows as suite time
204
   allows.
205
4. **The missing gate** — a PTY-driven interactive harness for the TUI, so
206
   the class of failure in §4 has an automated detector rather than a rule.
207
5. **Automated review** — a second agent invoked with the trial artifacts
208
   produces the review without a human copying transcripts; proposals
209
   arrive machine-readable and the adopt step becomes a diff.
210
6. **Routing feedback** — per-lane suite scores feed lane selection, once
211
   cached-token accounting (#220) makes the cost axis honest.
212
213
The loop is not expected to converge on perfection. It is expected to stop
214
the same mistake from happening twice, and to make "the coder got better"
215
a sentence with a receipt behind it.
docs/coder/best-practices.md added +195

@@ -0,0 +1,195 @@

1
# Coder best practices
2
3
The knowledge ledger of the autoimprovement loop (`docs/coder/autoimprove.md`
4
§5). Every entry is falsifiable, carries provenance, and says how a violation
5
is detected. Statuses: `adopted` (in force), `proposed` (awaiting a measured
6
delta or an oracle), `refuted` (kept, struck through, so it is not
7
rediscovered). Reviews propose changes here; the adopt step of the runbook
8
applies them.
9
10
Provenance abbreviations:
11
12
- **fix-git** — openagents.com repo,
13
  `docs/terminalbench/2026-08-24-fix-git-run-analysis.md`
14
- **postmortem** — openagents.com repo,
15
  `docs/2026-08-26-rust-cli-port-parity-failure-postmortem.md`
16
- **bench** — `bench/README.md` and `bench-results/README.md`
17
- **harvest** — openagents.com repo,
18
  `docs/2026-08-25-plugin-harvest-targets.md`
19
20
## Verification
21
22
### V1. A completion claim names its oracle — `adopted`
23
24
State what observed the behavior: which verifier, which test, which surface.
25
"It compiles and the tests pass" is a claim about stubs unless the tests
26
reach the behavior the user asked for.
27
**Provenance:** postmortem (tests asserted struct constructors; seven issues
28
closed falsely). **Detection:** review question; for graded work, the
29
Harbor verifier is the oracle of record.
30
31
### V2. Verify on the surface the user touches — `adopted`
32
33
Headless output does not prove an interactive TUI works. Agent shells are
34
non-TTY and will take the non-interactive branch every time.
35
**Provenance:** postmortem (every check bypassed ratatui via the headless
36
fallback). **Detection:** review question. An automated PTY harness is the
37
planned gate (autoimprove §7.4); until it exists, no interactive-TUI issue
38
closes on headless evidence.
39
40
### V3. Parity claims quantify — `adopted`
41
42
Port and parity work reports counts against the source: commands in the
43
parser, lines per subsystem, features per checklist. Adjectives
44
("complete", "full parity") are not evidence.
45
**Provenance:** postmortem (~2,700 lines reported as parity with ~35,400).
46
**Detection:** review compares the claimed inventory to the source
47
inventory.
48
49
### V4. A crashed grader is not a grade — `adopted`
50
51
A run whose verifier never ran is `abandoned`, not scored, and a partial
52
run of a pinned suite is a smoke run.
53
**Provenance:** bench. **Detection:** automated — `run-suite.sh` patches to
54
`abandoned`; the results store refuses `smoke_run` and `unclassified_run`
55
with exit 3.
56
57
## Tool habits
58
59
### T1. Batch independent commands into one tool call — `adopted`
60
61
Round count drives metered cost: prompt tokens scale with rounds times
62
transcript size, not with work done. The same task has been done in 6 model
63
calls and in 15; the 15 cost three times the input tokens.
64
**Provenance:** fix-git. **Detection:** review reads rounds and prompt
65
tokens from the ATIF trajectory; regression shows as rising
66
rounds-per-accepted-outcome on an unchanged suite.
67
68
### T2. `--stat` before `-p` — `adopted`
69
70
Never dump a full patch into the transcript to find out which file changed.
71
Survey with `--stat`, then read the one file in question. A patch dumped
72
early is re-sent every round after.
73
**Provenance:** fix-git (two `git log -p` dumps re-sent ~12 times).
74
**Detection:** review flags full-patch dumps followed by further rounds.
75
76
### T3. Verbosity guidance is lane-aware — `adopted`
77
78
On metered lanes, output tokens are money; on the local lane they are
79
minutes (17k output tokens ≈ 18.5 wall-clock minutes at local generation
80
speed). Fewer, larger, quieter rounds on local; terse output everywhere.
81
**Provenance:** fix-git. **Detection:** review compares output tokens and
82
wall clock against lane norms in the results store.
83
84
### T4. Prove repository topology before acting on it — `proposed`
85
86
The winning `fix-git` runs read the recovered commit's content before
87
resolving the conflict, and the strongest run proved ancestry with
88
`merge-base --is-ancestor` before choosing a merge. Assuming the
89
relationship is how a plausible wrong resolution passes local inspection
90
and fails the verifier.
91
**Provenance:** fix-git. **Detection:** review question on version-control
92
tasks. Promote to `adopted` when a cross-section run shows the habit
93
correlating with acceptance on tasks 1–3.
94
95
## Measurement
96
97
### M1. One lever per cycle — `adopted`
98
99
A comparison is between two rows that differ in one thing. A run that
100
changes the model and the prompt and a plugin attributes its delta to
101
nothing.
102
**Provenance:** bench (the compare view names `model also varies` as a
103
confounder by design). **Detection:** automated in part — `suiteKey`
104
excludes the axes a comparison varies, and compare names confounders; the
105
runbook's cycle enforces the rest.
106
107
### M2. Unknown cost stays unknown — `adopted`
108
109
`null` with a disposition (`unmetered_local_lane`, `no_accepted_outcomes`,
110
`cost_unknown`), never zero. A lane that gets cheaper per attempt while
111
accepting less is a regression, and cost-per-accepted-outcome is the shape
112
that catches it.
113
**Provenance:** bench. **Detection:** automated — the store and compare
114
refuse to launder unpriced into free.
115
116
### M3. Regressions stay in the chain — `adopted`
117
118
A graded run of a real configuration is recorded even when — especially
119
when — it embarrasses the trend. The store's hash chain exists to make the
120
alternative detectable.
121
**Provenance:** bench (the deliberate `qwen3:0.6b` failure row in
122
`tb2-quick.jsonl`). **Detection:** automated — `receipt_mismatch` and
123
`chain_broken` on verify.
124
125
### M4. Threshold edits are their own change — `adopted`
126
127
Never adjust a floor in the same change as a run it would flatter. Raising
128
a floor as a lane proves itself out is the intended direction; lowering one
129
to pass is a contract change and says so in its commit.
130
**Provenance:** bench thresholds `$comment` blocks. **Detection:** review
131
of the diff that touches `packages/coder-effectiveness/thresholds/`.
132
133
### M5. Quick suites iterate, cross-sections conclude — `adopted`
134
135
`tb2-quick`'s two tasks admit success rates of 0, .5, and 1 only. A quick
136
delta selects what to run next; only a full pinned-suite run is a score,
137
and the two suites share no suite key so no tool will compare them.
138
**Provenance:** bench. **Detection:** automated (suite keys) plus the
139
runbook's cycle.
140
141
## Plugins
142
143
### P1. A plugin lands with its Gym delta — `adopted`
144
145
Before-and-after on the same recipe, plugin present versus absent, delta
146
attributed through the ATIF `tool.ran` provenance stamps to the exact
147
digest. A plugin that moves no score is questioned in the review, not
148
waved through.
149
**Provenance:** harvest; Harbor plan. **Detection:** review of the landing
150
change for the A/B rows.
151
152
### P2. Plugins are read-only, one-shot, bounded, and honest — `adopted`
153
154
The sandbox grants read-only mounts and nothing else; one packet in, one
155
packet out, under time and memory bounds; typed schemas in the manifest;
156
output that names its own truncation (`tail_only`,
157
`dropped_leading_turns`). Edits, writes, and process execution stay in the
158
coder's core tools under the permission profile.
159
**Provenance:** harvest; `plugins/README.md`. **Detection:** the host
160
refuses undeclared imports and stale digests; review checks the manifest
161
against the shape rules.
162
163
### P3. A catalog line is contested space — `adopted`
164
165
The capability tool carries each installed plugin's name and first sentence,
166
capped at twelve. A plugin competes for that slot with everything installed;
167
its first sentence must earn a model's attention on the turns where the
168
plugin applies.
169
**Provenance:** harvest. **Detection:** review question when the A/B shows
170
a plugin installed but never invoked on tasks it should have served.
171
172
## Repository
173
174
### R1. Pack with `pnpm pack`, never `npm pack` — `adopted`
175
176
The manifest carries pnpm `catalog:` versions that only `pnpm pack`
177
rewrites into versions npm can install. An `npm pack` tarball looks healthy
178
and fails for every consumer.
179
**Provenance:** bench; `CLAUDE.md` deploy section (shipped broken once as
180
`@openagentsinc/cli@0.2.0`). **Detection:** the CLI's `verify:package`
181
refuses a manifest carrying `catalog:`.
182
183
### R2. Push the forge, not GitHub — `adopted`
184
185
The `openagents` remote records the push in the WAL; GitHub is a mirror
186
production force-pushes. A direct GitHub push is overwritten, not merged.
187
**Provenance:** openagents.com `AGENTS.md`. **Detection:** automated —
188
`push-remote-check.sh` refuses a non-forge push where installed.
189
190
### R3. Fresh worktree per unit of work — `adopted`
191
192
Implement off current `origin/main` in a new worktree; never edit through
193
another agent's dirty checkout, and never move its uncommitted work aside.
194
**Provenance:** repository contract (owner mandate 2026-07-20).
195
**Detection:** review of the working-tree state in the transcript.
docs/coder/runbook.md added +266

@@ -0,0 +1,266 @@

1
# Coder autoimprovement runbook
2
3
The operating procedure for an agent running the loop in
4
`docs/coder/autoimprove.md`. Follow it top to bottom the first time; after
5
that, each cycle is §4 (a process or code lever) or §5 (a plugin), always
6
followed by §6 (review) and §7 (record and land).
7
8
Read first, in order:
9
10
1. `docs/coder/autoimprove.md` — the plan and the verification law.
11
2. `docs/coder/best-practices.md` — the ledger. You will update it.
12
3. `bench/README.md` — harness mechanics, environment pitfalls.
13
4. `bench-results/README.md` — what the store accepts and refuses.
14
15
## 0. Authority and boundaries
16
17
You may change: the coder system prompt and tool descriptions
18
(`crates/coder-lite`, `packages/openagents-cli`), tool budgets, plugins
19
(`plugins/`), suites and thresholds (as their own change — best practice
20
M4), this directory's docs, and CLI code under the repository completion
21
gate.
22
23
You may not: edit or reorder `bench-results/*.jsonl` rows (append only,
24
through the tooling), record a smoke or partial run as a score, delete the
25
deliberate regression row in `tb2-quick.jsonl`, close an interactive-TUI
26
issue on headless evidence (best practice V2), or change a threshold in the
27
same change as a run it would flatter.
28
29
Work in a fresh worktree per unit (`git fetch openagents main && git
30
worktree add --detach <path> openagents/main`), and land by pushing to the
31
forge remote, never GitHub (best practices R2, R3). For CLI code changes
32
the completion gate is `pnpm run check`; docs-only changes push with
33
`--no-verify` after the docs checks.
34
35
## 1. Prerequisites
36
37
- **Docker with amd64 emulation that works.** Terminal-Bench images are
38
  amd64. On Apple Silicon, enable Rosetta in Docker Desktop (Settings →
39
  General → "Use Rosetta for x86_64/amd64 emulation"); under plain qemu the
40
  verifier's `uv`/`pytest` segfaults after the agent phase and every trial
41
  grades `ungraded`.
42
- **Harbor** installed (the clone is `../projects/repos/harbor`;
43
  `pip install harbor` or run from the clone).
44
- **A dev forge**, for proxy-lane runs: in the openagents.com repo,
45
  `PHX_LISTEN_ALL=true mix phx.server`, and an `OPENAGENTS_TOKEN` with
46
  `chat:account` scope. If another session holds the port loopback-only,
47
  bridge `0.0.0.0:4001 → 127.0.0.1:4000` and set
48
  `OPENAGENTS_CODER_API_URL=http://host.docker.internal:4001` instead of
49
  fighting for the port.
50
- **A packed CLI tarball** from the working tree — this is what the adapter
51
  installs into containers, so it is how your change reaches the arena:
52
53
  ```sh
54
  cd packages/openagents-cli
55
  pnpm build
56
  pnpm pack --pack-destination ../../bench
57
  ```
58
59
  `pnpm pack`, never `npm pack` (best practice R1).
60
- **Ollama** with the local-lane model pulled, for local-lane runs. Local
61
  runs need no token; keep `--n-concurrent 1` because the model owns the
62
  cores.
63
64
## 2. Baseline
65
66
Establish the number you are trying to move, on the lane you are testing.
67
68
```sh
69
bench/run-suite.sh bench/suites/tb2-quick.suite.json \
70
  --model openai/gpt-5.6-luna --lane proxy \
71
  --jobs-dir /tmp/gym-jobs/baseline
72
```
73
74
Then score and record it:
75
76
```sh
77
pnpm run effectiveness:report -- /tmp/gym-jobs/baseline/<job-dir> \
78
  --suite tb2-quick --lane proxy \
79
  --suite-manifest bench/suites/tb2-quick.suite.json \
80
  --thresholds packages/coder-effectiveness/thresholds/tb2-quick.json \
81
  --append bench-results/tb2-quick.jsonl
82
```
83
84
Exit codes: `0` gate passed, `1` a floor breached, `2` unverifiable
85
(not a pass), `3` scored but refused by the store — read the refusal, it is
86
telling you the run does not qualify as a score. Verify the chain and read
87
the trend:
88
89
```sh
90
pnpm run effectiveness:compare -- bench-results/tb2-quick.jsonl
91
```
92
93
With `OPENAGENTS_TOKEN` set, the runner registers the run at
94
`POST /api/v1/gym/runs/start` and `/gym` shows it live; finalization to
95
`graded` (or `abandoned` when no verifier ran) happens through
96
`bench/post_gym_run.py --run-id` automatically.
97
98
If no baseline exists yet for the lane and suite you are working, the
99
baseline run **is** the first cycle's deliverable. Record it and stop
100
there; a lever with no baseline produces a delta against nothing.
101
102
## 3. Choose one lever
103
104
One per cycle (best practice M1). Sources, in order of cost:
105
106
1. **The ledger's `proposed` entries** (`docs/coder/best-practices.md`) —
107
   each names its promotion oracle.
108
2. **The latest reviews** (`docs/coder/reviews/`) — unadopted proposals
109
   with evidence already attached.
110
3. **The harvest backlog** (openagents.com repo,
111
   `docs/2026-08-25-plugin-harvest-targets.md`) — plugins ordered by
112
   expected delta; go to §5.
113
4. **Structural gaps** (autoimprove §2.3: compaction, history, shell
114
   parsing) — only when cheaper levers have stopped paying, and with the
115
   designated suite oracle named before you start.
116
117
Write down, before implementing: the lever, the suite that will measure it,
118
and the delta direction that would confirm it. If you cannot name the
119
measuring suite, the lever is not ready for a cycle.
120
121
## 4. The cycle: process and code levers
122
123
1. **Implement** in a fresh worktree. Prompt/tool-description levers land
124
   in the coder's system prompt and tool declarations; budget levers in the
125
   tool budget; code levers under `pnpm run check`.
126
2. **Repack** the CLI tarball (§1) so the arena runs your change.
127
3. **Re-run the same suite, same model, same lane** as the baseline.
128
   Nothing else varies. The runner pins CLI version into the row, so the
129
   two rows differ in exactly the axis you changed.
130
4. **Compare.**
131
132
   ```sh
133
   pnpm run effectiveness:compare -- bench-results/tb2-quick.jsonl
134
   ```
135
136
   Read the trend line and the confounder note. On `tb2-quick`, treat the
137
   delta as a selector, not a conclusion (best practice M5): an
138
   encouraging quick delta earns a cross-section run —
139
140
   ```sh
141
   bench/run-suite.sh bench/suites/tb2-cross-section.suite.json \
142
     --model openai/gpt-5.6-luna --lane proxy --n-concurrent 2 \
143
     --jobs-dir /tmp/gym-jobs/xsec-<lever>
144
   ```
145
146
   — scored against `thresholds/tb2-cross-section.json` and appended to
147
   `bench-results/tb2-cross-section.jsonl`. Success rate is not the only
148
   axis: rounds, prompt tokens, and wall clock per accepted outcome are
149
   where process levers show first (the fix-git analysis is the worked
150
   example).
151
5. **Decide.** Improved or neutral-but-simpler: keep. Worse: revert the
152
   lever, keep the recorded row (best practice M3), and write the refutation
153
   into the review. Timeout-shaped failures are not efficiency signal —
154
   rerun with `--timeout-multiplier 2.0` before concluding anything.
155
156
## 5. The cycle: plugins
157
158
1. **Pick the target** from the harvest backlog and confirm it fits the
159
   admitted shape (best practice P2): read-only or pure, one-shot, bounded,
160
   typed, truncation-honest. If it needs writes, execution, or a lifetime
161
   beyond one call, it is core-tool work, not a plugin.
162
2. **Build** in `plugins/<name>/` on `openagents-pdk`: one
163
   `fn handle(input) -> Result<Output, Refusal>` plus `plugin_entry!`.
164
   Declare only the imports the manifest's mounts grant — the host refuses
165
   undeclared imports.
166
3. **Pin the artifact.** Build for `wasm32-unknown-unknown --release`, copy
167
   the `.wasm` beside the source, and update the manifest's
168
   `artifact.digest` (`plugins/README.md` has the exact loop). The host
169
   refuses a stale digest — that refusal is the supply chain, keep it.
170
4. **A/B on the oracle tasks.** Same suite, same recipe, plugin absent then
171
   present. The cross-section's designated oracles: tasks 1–2
172
   (`git-leak-recovery`, `sanitize-git-repo`) for git forensics, task 9
173
   (`password-recovery`) for file forensics; for a new capability class,
174
   name the oracle tasks in the landing change. Confirm in the ATIF that
175
   the with-plugin run actually invoked it (`tool.ran` steps carry the
176
   digest); a plugin installed but never called on its own oracle tasks is
177
   a catalog-description problem (best practice P3) before it is a
178
   capability problem.
179
5. **Land with the delta** (best practice P1): both rows recorded, the
180
   attribution stated in the change. No delta and no convincing rationale:
181
   the plugin waits.
182
183
## 6. Review
184
185
After every cycle, run the review as a **separate conversation** — a fresh
186
agent context whose only inputs are the artifacts:
187
188
- the trial directories (`result.json`, `trajectory.json` ATIF,
189
  `coder.txt`) from the run,
190
- the diff of the lever,
191
- the two store rows (before and after),
192
- the current `docs/coder/best-practices.md`.
193
194
Review prompt skeleton:
195
196
```
197
You are reviewing one autoimprovement cycle of `openagents coder`.
198
199
<lever>{what changed, and the predicted delta}</lever>
200
<baseline-row>{jsonl row}</baseline-row>
201
<result-row>{jsonl row}</result-row>
202
<trials>{per-trial: instruction, verifier decision, ATIF metrics,
203
notable transcript spans}</trials>
204
<diff>{the lever's diff}</diff>
205
<practices>{docs/coder/best-practices.md}</practices>
206
207
Score the cycle 0–10 with specific evidence for each point gained or
208
lost. Answer: did the lever cause the delta, or does a confounder
209
explain it? Were any ledger practices violated (cite the entry and the
210
transcript step)? Propose one to three changes, each typed as
211
{lever, evidence: trajectory steps, risk, verification: suite and
212
expected delta direction}. Finally, list ledger entries to add, promote,
213
demote, or refute, with provenance.
214
```
215
216
The review must cite trajectory steps for every claim; a proposal without
217
an evidence pointer is rejected at the adopt step. Save the output to
218
`docs/coder/reviews/YYYY-MM-DD-<lever-slug>.md`.
219
220
## 7. Record, adopt, land
221
222
1. **Adopt** the accepted proposals: apply ledger changes to
223
   `docs/coder/best-practices.md` (checking new entries against existing
224
   ones for contradiction), carry rejected proposals into the review file
225
   with a one-line reason.
226
2. **Commit** the cycle as one unit: the lever, the review file, the ledger
227
   change, and the appended store rows. The commit message states the lever
228
   and the measured delta with its suite — a number, not an adjective
229
   (best practice V3).
230
3. **Push to the forge** (`git push openagents HEAD:main`), reconcile the
231
   canonical checkout, remove the worktree.
232
233
## 8. Stop rules
234
235
- **Three consecutive failures of the same gate** — the suite will not
236
  grade, the store refuses, the environment will not come up — stop
237
  attempting it. Preserve the last failure, write the smallest
238
  reproducible blocker and the next falsifiable hypothesis, and hand off.
239
  A fourth attempt needs new evidence.
240
- **An ungraded epidemic** (`ungraded` trials, `uv`/`pytest` segfaults)
241
  is the emulation problem, not your lever. Fix Rosetta or move to a cloud
242
  environment (`--env daytona` and peers) before reading any number.
243
- **A quick-suite success rate of 0** on a lane that previously scored:
244
  suspect the lane (auth, proxy URL, model availability) before the lever;
245
  the third row of `tb2-quick.jsonl` is what a lane-degradation signature
246
  looks like.
247
- **Budget**: a cross-section run is ~12 tasks × minutes-to-hours under
248
  emulation. Do not start one you cannot let finish; an abandoned run is
249
  recorded as `abandoned`, and that is the honest state, but it bought
250
  nothing.
251
- When blocked on an owner action, write the `NEEDS-OWNER:` note and pull
252
  the next non-blocked lever; the loop does not idle.
253
254
## 9. Current state (update as it changes)
255
256
- Baselines on record: `tb2-quick`, local lane, `qwen3.8:27b-mtp-q8_0` at
257
  0.5 success (two runs), plus the deliberate `qwen3:0.6b` regression row.
258
  No proxy-lane rows recorded yet; no cross-section rows recorded yet.
259
- `owned-closed-issues` is a smoke suite until its environments exist
260
  (`bench/tasks/owned/README.md`).
261
- Cached-token splits are not surfaced end to end
262
  (OpenAgentsInc/openagents.com#220); until then, metered-lane dollar
263
  figures are ceilings, and lane comparisons lean on success rate and
264
  rounds.
265
- The PTY-driven interactive harness (autoimprove §7.4) does not exist
266
  yet; best practice V2 is enforced by rule, not by gate.

This page updates live while a promote is in flight · changelog