@jaybeeuu/agent-cortex 2.7.0 → 2.8.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 (56) hide show
  1. package/CHANGELOG.md +239 -0
  2. package/README.md +61 -5
  3. package/agents/README.md +2 -2
  4. package/agents/ralph/agent.md +17 -16
  5. package/agents/ralph/claude/wake.md +4 -4
  6. package/agents/ralph/pi/wake.md +15 -20
  7. package/bin/agent-cortex.mjs +20 -1
  8. package/extensions/post-merge-watch/README.md +133 -0
  9. package/extensions/post-merge-watch/index.test.ts +247 -0
  10. package/extensions/post-merge-watch/index.ts +123 -0
  11. package/extensions/post-merge-watch/package.json +16 -0
  12. package/extensions/post-merge-watch/watch.test.ts +469 -0
  13. package/extensions/post-merge-watch/watch.ts +431 -0
  14. package/extensions/session-clear/README.md +74 -0
  15. package/extensions/session-clear/index.test.ts +524 -0
  16. package/extensions/session-clear/index.ts +159 -0
  17. package/extensions/session-clear/package.json +16 -0
  18. package/lib/cli.mjs +42 -1
  19. package/lib/self-update.mjs +553 -0
  20. package/package.json +1 -1
  21. package/skills/engineering/implement-task/SKILL.md +124 -0
  22. package/skills/engineering/tdd/SKILL.md +2 -0
  23. package/skills/planning/create-task/REFERENCE.md +15 -6
  24. package/skills/planning/create-task/SKILL.md +1 -1
  25. package/skills/planning/create-task/pipeline.json +8 -0
  26. package/skills/planning/create-task/scripts/create-chores.mjs +27 -18
  27. package/skills/planning/create-task/templates/code.md +8 -3
  28. package/skills/planning/create-task/templates/document.md +8 -3
  29. package/skills/planning/create-task/templates/fix.md +8 -3
  30. package/skills/planning/create-task/templates/housekeeping.md +8 -4
  31. package/skills/planning/create-task/templates/post-merge.md +67 -0
  32. package/skills/planning/create-task/templates/review.md +8 -3
  33. package/skills/planning/create-task/templates/verify.md +8 -3
  34. package/skills/productivity/bd-tool/SKILL.md +55 -0
  35. package/skills/review/review-defects/EXAMPLES.md +122 -0
  36. package/skills/review/review-defects/SKILL.md +91 -0
  37. package/skills/style/style-tests/EXAMPLES.md +30 -0
  38. package/skills/style/style-tests/SKILL.md +10 -6
  39. package/skills/workflow/plan/SKILL.md +14 -3
  40. package/skills/workflow/ralph/REFERENCE.md +124 -27
  41. package/skills/workflow/ralph/SKILL.md +24 -15
  42. package/skills/workflow/ralph/scripts/post-merge-check.mjs +651 -0
  43. package/skills/workflow/run-pipeline-stage/SKILL.md +37 -22
  44. package/skills/workflow/run-pipeline-stage/playbooks/code.md +14 -8
  45. package/skills/workflow/run-pipeline-stage/playbooks/document.md +2 -2
  46. package/skills/workflow/run-pipeline-stage/playbooks/fix.md +2 -2
  47. package/skills/workflow/run-pipeline-stage/playbooks/housekeeping.md +1 -1
  48. package/skills/workflow/run-pipeline-stage/playbooks/post-merge.md +54 -0
  49. package/skills/workflow/run-pipeline-stage/playbooks/review.md +34 -3
  50. package/skills/workflow/run-pipeline-stage/playbooks/verify.md +2 -2
  51. package/skills/workflow/run-pipeline-stage/prompts/stage-runner.md +55 -11
  52. package/skills/workflow/run-pipeline-stage/scripts/recover-brief.mjs +805 -0
  53. package/skills/workflow/run-pipeline-stage/scripts/trail-entry.mjs +702 -0
  54. package/skills/workflow/using-agent-skills/SKILL.md +15 -7
  55. package/token-map.README.md +27 -0
  56. package/token-map.json +10 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,244 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 683808c: State the bead-state rule in `bd-tool` and `AGENTS.md`: operational state (progress, what a stage
8
+ learned, the decisions taken, branch/PR/commit/worktree refs) lives in bead fields, while durable
9
+ committable documents stay files, and `handoff.md` plus the working-docs artefact directory are
10
+ unchanged. The built-in statuses carry the working state — `bd statuses` lists all seven, so no
11
+ state label is added. What happened goes in the trail with `bd note`, which appends. The text names
12
+ `stage=` as forbidden for state, with the reason: `bd set-state` removes the existing label for the
13
+ dimension it sets, so it would rewrite a chore's route. Ship this in the same release as the
14
+ removal of the `ralph-*.log` and `progress.md` writer sites (`agnt-ctx-ul91.1`): a published
15
+ version that states the rule while a skill still writes progress files would contradict itself.
16
+ - 87ebb46: Give the pipeline one shared writer for the bead trail, and stop the file-based progress logs.
17
+
18
+ `skills/workflow/run-pipeline-stage/scripts/trail-entry.mjs` appends one checkpoint to a bead's
19
+ notes with `bd note` and records the refs the caller names as provenance events. Every entry
20
+ carries the three mandatory fields — Outcome (`done`/`blocked`/`partial`), Evidence (a test or lint
21
+ result, the commit, command output), and What is left — so a fresh session resumes from
22
+ `bd show <id>` alone.
23
+
24
+ A `--commit` ref is resolved through `git rev-parse` to the full 40-character lowercase SHA before
25
+ recording, because `bd provenance record --ref-kind git-sha` refuses an abbreviated one; a ref that
26
+ does not resolve records nothing. Transient database failures — `failed to open database ...
27
+ context canceled`, the shape two concurrent writers produce on embeddeddolt — are retried with
28
+ bounded backoff, each retry re-reads the bead first so a write that landed before its call reported
29
+ failure is never duplicated, and no call holds the database across a long operation. Recording is
30
+ idempotent for one writer: the entry carries a fingerprint of its own content, so a repeated fire
31
+ appends nothing. Two concurrent fires of one transition can each append — `bd note` has no
32
+ conditional append — so the pipeline fires each transition from one worker.
33
+
34
+ `run-pipeline-stage` and `ralph` now call that script at every stage transition, and no shipped
35
+ skill, agent, or stage template writes a per-parent log file or a rendered progress view any more.
36
+ Ralph's log polling, its `state.json` `logLine` bookmark, and both wake sections' log-flush
37
+ procedure go with them: progress is read from the bead (`bd show`, `bd provenance log`), which is
38
+ the record the worker writes directly.
39
+
40
+ - 4e1bcc5: Add `implement-task`, the skill that owns the task around the loop: criteria, scope, and proof.
41
+
42
+ `tdd` owns the red-green loop and the `style-*` skills own the standards, but nothing owned the task
43
+ — reading the acceptance criteria, proving each one, staying in scope, and taking only pragmatic
44
+ boy-scout fixes. `implement-task` fills that gap with four load-bearing sections: the criteria →
45
+ evidence table, written before code and filled with observable evidence at Finish; the scope rule,
46
+ where an out-of-scope finding becomes a bead instead of an edit; the boy-scout rule, which allows a
47
+ fix only inside a file the task already touches and only where it serves the task; and the mutation
48
+ check, inherited from `style-tests` and applied to every test that claims a behaviour. A criterion
49
+ with no named check is a blocker, not a guess.
50
+
51
+ The `code` stage playbook now invokes `implement-task` as its first step and routes through it to
52
+ `tdd` and the style skills, `tdd` links to it for criteria and scope rather than carrying those
53
+ rules itself, and `using-agent-skills` routes a task-implementation request to it while leaving a
54
+ bare "write a test for X" on `tdd`.
55
+
56
+ - 27b513b: Fork the planner ↔ ralph peer channel per harness instead of describing it as PI-only. The channel
57
+ now renders through `token-map.json`: `{{TOOL:peer_send}}` and `{{TOOL:peer_list}}` become
58
+ `peer_send` and `peer_list` in a pi install, and Claude Code's built-in `SendMessage` and
59
+ `ListAgents` in a claude install. Both harnesses carry the same seven message kinds and the same
60
+ acknowledgement rule — the kinds table and the reply rule are byte-identical between the two
61
+ renders, and only the `### Transport` subsection differs.
62
+
63
+ Claude Code's cross-session messaging is built in from v2.1.224 (v2.1.234 on native Windows):
64
+ `ListAgents` returns the peers a session can reach with the address of each, and `SendMessage`
65
+ delivers to that address, so a named peer session is addressable and no manual-handoff-only fork is
66
+ needed. `pi-peer`'s `peer_get` and `peer_await` have no Claude Code counterpart, so they are named
67
+ only inside the harness-labelled `pi-peer` runbook: a null mapping would drop the token and leave
68
+ the sentence that named it broken.
69
+
70
+ `test/skill-transport-render.test.mjs` stages both installs and asserts the per-harness rendered
71
+ text, so a harness that loses its mechanism fails the suite rather than silently degrading.
72
+
73
+ - 49b34d7: Document the planner ↔ ralph message convention on top of `@cryptolibertus/pi-peer`. The `ralph`
74
+ skill now publishes its peer identity at start (`PI_PEER_ID=ralph`), answers inbound `handoff`,
75
+ `get` and `ask` messages, and reports `update`/`done`/`blocked`/`failed` to the planner as work
76
+ dispatches, finishes, parks on a human gate or fails. The `plan` skill sends a `handoff` message
77
+ naming the handoff bead once it exists, treats ralph's `blocked` messages as its pending-human
78
+ surface, and keeps the manual instruction as the handoff path for a session with no reachable
79
+ receiver.
80
+
81
+ The shared convention — the kind-to-intent table, the acknowledgement rule, the two-entry
82
+ `.pi/peers.json` requirement and the one-way discovery failure a single entry causes, the
83
+ `.pi/peers.json` and `.pi/peer-*` paths to gitignore, and the rule to send through `peer_send` rather than typing into a
84
+ busy session — lives once in `skills/workflow/ralph/REFERENCE.md` and is cross-referenced from
85
+ `plan`. pi-peer keeps ownership of discovery, delivery, idle wake and the ledger; no registry,
86
+ inbox, watcher or transport is implemented here. The tools are named through `{{TOOL:...}}` tokens so
87
+ one skill text serves both harnesses; the per-harness fork is its own changeset.
88
+
89
+ - 2610b78: Add the `post-merge` pipeline stage and the deterministic check it runs.
90
+ `skills/workflow/ralph/scripts/post-merge-check.mjs` reads `gh run list` for the base branch's merge
91
+ commit and exits `0` passed, `1` failed, `2` inconclusive — no model, no tokens, zero runtime
92
+ dependencies, async only. A failing run files exactly one P1 escalation bead carrying the run URL
93
+ and the failing job name; the `post-merge-run:<id>` marker in its description makes a second run
94
+ file nothing. It never retries, never re-runs the workflow, never reopens the parent, and is
95
+ GitHub-only in v1 (a repository `gh` cannot resolve to a GitHub host, or a commit with no run, is
96
+ inconclusive and files nothing). `create-chores.mjs` pre-creates the chore labelled
97
+ `lifecycle:post-merge`, blocked behind the `lifecycle:feature-pr` gate rather than behind a stage,
98
+ so it becomes ready only once a human merges and closes the gate; a re-run still creates nothing.
99
+ The script reads the repository slug and base branch from `gh repo view`, so no slug or branch is
100
+ baked in. `housekeeping` and `post-merge` are siblings on the gate and neither waits on the other,
101
+ because an inconclusive check must not strand the worktree reclamation.
102
+ - 241ab8f: Add the `post-merge-watch` pi extension: poll the post-merge check and wake an idle session with
103
+ the verdict.
104
+
105
+ `pi --post-merge-watch <bead>` polls
106
+ `skills/workflow/ralph/scripts/post-merge-check.mjs` every 15 s (up to 40 checks) and, when the
107
+ script reports a verdict, sends one message with
108
+ `pi.sendMessage(..., { deliverAs: "followUp", triggerTurn: true })`, so a session that is idle
109
+ starts a turn with the result. The message names the bead, the verdict, the exit code, the reason,
110
+ the run URL, the project, and the number of checks; the same fields ride along as message
111
+ `details`.
112
+
113
+ The extension owns no verdict logic: the check's exit code is the verdict (`0` passed, `1` failed,
114
+ anything else inconclusive, including a timeout kill), and the run URL is forwarded from the
115
+ script's JSON report. It makes no model call, imports pi as types only, registers its CLI flag in
116
+ the extension factory, and spawns no process or writes no state when the flag is absent. Each
117
+ invocation passes `--wait 0`, so the poll interval and the bound live in the extension and a
118
+ stopped watch never blocks on a child process.
119
+
120
+ State lives under `~/.pi/agent-cortex/post-merge-watch/`, one file per project path and bead (the
121
+ name carries a digest of both, so two projects watching one bead never collide), and is removed
122
+ when the watch settles or the session shuts down. The pending timer is unref'd and cancelled on
123
+ shutdown, so an abandoned watch leaves no orphan timer and no state file. The default check script
124
+ is resolved relative to the extension file, so the staged pi package (`extensions/` beside
125
+ `skills/`) needs no hardcoded absolute path; `AGENT_CORTEX_POST_MERGE_CHECK` overrides it. PI only:
126
+ Claude Code uses its own watch tools.
127
+
128
+ - ee5d09f: Fork the post-merge stage's watch per harness instead of leaving a long run unwatched. The stage
129
+ playbook now carries a `## Watch transport` section whose single mechanism name renders through
130
+ `token-map.json`: `{{TOOL:post_merge_watch}}` becomes `post-merge-watch` — this package's own
131
+ extension, which re-runs the check on a timer and wakes an idle session with the verdict — in a pi
132
+ install, and Claude Code's built-in `ScheduleWakeup` tool in a claude install. The stage
133
+ instructions, the three verdicts, the never-retry rule, the escalation rule and the close rule stay
134
+ one authored copy: the two renders differ on exactly one line.
135
+
136
+ The Claude capability is established from the installed binary (2.1.294), not assumed.
137
+ `ScheduleWakeup` is a registered tool whose own description names the case in point — "when actively
138
+ polling external state the harness can't notify you about (a CI run, a deploy, a remote queue), pick
139
+ the delay from how fast that state actually changes" — it takes `delaySeconds` clamped to
140
+ 60–3600, `prompt`, `reason`, `noop` and `stop`, and a built-in system reminder says "If polling in a
141
+ loop, use ScheduleWakeup instead of retrying". A live probe was impossible: `claude -p` in this
142
+ environment reports "Not logged in · Please run /login". Because availability is a property of the
143
+ session rather than of the tool's existence, the section also states the fallback in prose — one run
144
+ with `--wait 1800` — so no harness is assumed to have a watcher and neither render loses a name.
145
+
146
+ `test/post-merge-transport-render.test.mjs` stages both installs and asserts the per-harness rendered
147
+ playbook, the byte-identical remainder, and the no-watcher fallback, so a harness that loses its
148
+ mechanism fails the suite rather than silently degrading.
149
+
150
+ - b698f2d: Read a half-finished bead in one bounded command, without opening the transcript.
151
+
152
+ `skills/workflow/run-pipeline-stage/scripts/recover-brief.mjs` is the read side of the bead trail
153
+ that `trail-entry.mjs` writes. One invocation prints what a session needs to continue: status and
154
+ state labels, the newest trail entries with their Evidence and What is left, the provenance refs,
155
+ the blocking dependencies, and the acceptance criteria.
156
+
157
+ The bound is enforced, not promised. `bd show` returns the whole note — no option asks it for the
158
+ last few entries — and it prints 89 lines and about 6.5 KB for a bare bead carrying 20 entries,
159
+ about 120 lines and about 8 KB for a realistic one with acceptance criteria, a blocker, provenance
160
+ refs and a description. The brief prints the newest `--trail` entries (default 3), summarises the
161
+ rest by count, clips any single field, and
162
+ holds its whole output to a line budget (default 40) even when the requested window is wider than
163
+ that: it shrinks the window, names what it left out, and never prints more lines than `--max-lines`.
164
+
165
+ It reads only. Every `bd` call is one of the read subcommands and carries `--readonly`, and a call
166
+ that is not on the allow-list is refused before it reaches the binary, so the brief cannot write a
167
+ note, a status or a provenance event. Each section states plainly when a bead has no trail, no
168
+ refs, no acceptance criteria or no blockers, instead of printing an empty heading.
169
+
170
+ The note is one text blob, so the brief splits it itself: a writer header starts a stamped entry
171
+ whose body runs only over the writer's `Field: value` lines, and any other text is an entry of its
172
+ own. A note appended by hand therefore prints wherever it lands — before a stamped entry, between
173
+ two of them, or after the last one — and the trail count includes it. `next:` claims "no trail
174
+ entry" only when the bead carries no trail, and says the entries record no next step when they
175
+ exist without a `What is left` field.
176
+
177
+ `run-pipeline-stage`, `ralph` and the stage-runner prompt now document the brief as the first read of
178
+ a bead's trail, with `bd show` and `bd provenance log` reserved for the history the window left out.
179
+
180
+ - 1e97223: Rejections now carry data. A review that rejects a bead applies exactly one `defect:<class>` label
181
+ from a closed list of eight classes — `test-unproven`, `test-cannot-fail`, `criteria-unmet`,
182
+ `scope-creep`, `style-violation`, `missing-proof`, `regression`, `docs-drift` — plus the specific
183
+ reason in the rejection text.
184
+
185
+ The new `review-defects` skill defines the vocabulary, with one worked example per class in
186
+ `EXAMPLES.md`. The review playbook instructs one label per rejection, states that a class outside
187
+ the list is a review defect in itself, and says the review that confirms a fix removes the label and
188
+ records the removal in its trail entry. The label classifies the defect; the bead's status still
189
+ says where the work is, so no state label is added. Because the rejected chore is normally already
190
+ closed, the two queries that read the vocabulary pass `--all`: one class with
191
+ `bd list -l defect:<class> --all`, and every defect with `bd list --label-pattern 'defect:*' --all`.
192
+ `bd-tool` indexes the label and points at `review-defects` for the vocabulary and the queries.
193
+
194
+ - 7ce04e0: Add `agent-cortex self-update` (and its `ctx` / `cortex` aliases): update the globally installed CLI
195
+ through the manager that owns the install, then refresh the harness installs with the newly
196
+ installed binary. The owner is inferred from the running entry point's real path — pnpm's
197
+ `global/<v>` and `store/<v>/links` layouts, or npm's `lib/node_modules` — then confirmed by asking
198
+ that manager for its own global listing and matching this package's name and version, so a manager
199
+ on `PATH` is never used in place of the real owner: an unidentified or unconfirmed owner prints the
200
+ exact command and exits non-zero. It reports the installed version (read from the manifest beside
201
+ the entry point), the published version (from the confirmed manager's `view`), the owner, and the
202
+ command, and `--check` stops after the report writing nothing. A registry error is a distinct
203
+ failure that offers no update, and a failed install reports the manager's stderr and runs nothing
204
+ after it. Every process is spawned with an argv array (`execFile` / `spawn`), never a shell string.
205
+ - 2624dce: `self-update` now reports the version boundary and only refreshes when the CLI changed. After a
206
+ successful install it reads the version the newly installed binary reports and prints
207
+ `cli <before> → <after>`, then hands the terminal to that binary's `update -a` and exits with
208
+ the refresh's own exit code, so a failed refresh is visible to the caller. The refresh is skipped in
209
+ three cases: `--check`, a failed update, and an install already at the published version (which now
210
+ also installs nothing and points at `agent-cortex update -a` instead). A refresh that cannot start
211
+ prints the reason and the exact command to run by hand instead of exiting 1 silently. The README,
212
+ `docs/dev-loop.md` and `--help` document the act-by-default behaviour, `--check`, the owner
213
+ detection rule, and the re-exec chain with its failure output.
214
+ - 8925019: Add the `session-clear` extension, which registers `/clear` in pi: keep the session display name,
215
+ model, thinking level, and active agent, and drop the transcript context. It captures the identity
216
+ as plain data, replaces the session with `ctx.newSession({ parentSession })` so the cleared session
217
+ stays the parent in `/tree` and `/resume`, then the replacement instance re-applies the name and
218
+ restores the model and thinking level only when they differ from the replacement's own values. It
219
+ appends a `session-clear` provenance entry, reports the clear in one line, never prompts, never
220
+ summarises, and never deletes the cleared session file. PI-only: Claude Code already ships `/clear`,
221
+ so the audit in `docs/claude-hooks.md` records no hook port.
222
+ - 0936de5: Make a test's name an assertion contract, and require a mutation check before a test is done.
223
+
224
+ `style-tests` now states that every clause of a test name must be an assertion: a count in the name
225
+ asserts a count, a state asserts that state, and a "not" asserts the absence. The Workflow gains the
226
+ mutation check — disable the claimed behaviour and confirm each named test fails — and Red Flags
227
+ names the case that motivated it, a test named "one notice" proven only by `toBeDefined()`. The
228
+ worked pair lives in `EXAMPLES.md` under _A test name is a claim_. The review playbook now requires
229
+ the reviewer to map each clause of a changed test's name to the assertion that proves it, to reject a
230
+ test whose name outruns its assertions, and to block a test change that carries no evidence the
231
+ mutation check ran.
232
+
233
+ ### Patch Changes
234
+
235
+ - 82dbed0: A stop that needs a human decision becomes a bead, not a label: `bd-tool` and `AGENTS.md` now say
236
+ to create an `execution:hitl` task carrying the question, then make the waiting bead depend on it
237
+ with `bd dep add <waiting> <decision>`. The waiting bead leaves `bd ready` while the decision
238
+ becomes work a human can take, so one answer releases work that is already scoped. `--status
239
+ blocked` is kept for a stop no bead can carry, such as a fix-round cap, and `bd note` records the
240
+ stop and its reason.
241
+
3
242
  ## 2.7.0
4
243
 
5
244
  ### Minor Changes
package/README.md CHANGED
@@ -81,7 +81,8 @@ temp-dir install plus structural checks:
81
81
  the whole plugin — every skill and agent in it — with that one field. Hand-authored
82
82
  extras — `.mcp.json` and `scripts/` — are copied into every install from the `claude-extras/`
83
83
  dir, which is their canonical store. See `docs/claude-hooks.md` for the
84
- extension→hook mapping and the rejections (auto-name, agent-guardrails, skill-stats, subagent, agent-modes).
84
+ extension→hook mapping and the rejections (auto-name, agent-guardrails, skill-stats, subagent, agent-modes,
85
+ session-clear, post-merge-watch).
85
86
 
86
87
  Edit the sources (`agents/<name>/` composable dirs, `skills/**`,
87
88
  `hooks/claude/`, `claude-extras/`, `package.json`), never anything under the materialised
@@ -457,7 +458,8 @@ extension→hook audit.
457
458
  #### Not ported / follow-ups
458
459
 
459
460
  - Only `session-start` and `notify` had Claude equivalents (both ported to hooks); the other
460
- pi `extensions/` (auto-name, agent-guardrails, skill-stats, subagent, agent-modes) have none — `output-style`
461
+ pi `extensions/` (auto-name, agent-guardrails, skill-stats, subagent, agent-modes,
462
+ post-merge-watch) have none — `output-style`
461
463
  reaches Claude through the managed `CLAUDE.md` section instead; the audit and
462
464
  rejection rationale live in `docs/claude-hooks.md`.
463
465
  - Ralph follow-ups: multi-feature epic branches, and a GitHub-trigger routine to auto-resume
@@ -504,6 +506,61 @@ Only plain release versions are compared, so a prerelease on either side also re
504
506
  The command is read-only: it stats and reads those manifests, and never installs, writes, or
505
507
  reaches the network.
506
508
 
509
+ ## Updating the CLI itself (`agent-cortex self-update`)
510
+
511
+ `agent-cortex self-update` updates the globally installed CLI through the manager that installed it,
512
+ then refreshes the harness installs with the newly installed binary.
513
+
514
+ ```sh
515
+ agent-cortex self-update # report, update, then refresh the harness installs
516
+ agent-cortex self-update --check # report the versions and the command, write nothing
517
+ ```
518
+
519
+ The owning manager is inferred from the running entry point's real path, then confirmed — never
520
+ assumed. A pnpm install lives under `<prefix>/global/<v>/…` (and the store link that path resolves
521
+ into), an npm install under `<prefix>/lib/node_modules/…`, and the manager binary is taken from that
522
+ `<prefix>` rather than from `PATH`. That matters because two managers can be installed and only one
523
+ of them owns this copy: running the manager on `PATH` would update the wrong store or fail. The
524
+ confirmation asks the inferred manager for its own global listing and matches this package's name
525
+ and version. An owner that cannot be inferred or confirmed prints the exact command and exits
526
+ non-zero — both managers' commands when it cannot even infer the layout, because that choice is
527
+ the user's. The CLI never falls back to a manager found on `PATH`.
528
+
529
+ The report gives the installed version (read from the manifest beside the entry point, so even a
530
+ stale process reports what is on disk), the published version (from the confirmed manager's `view`),
531
+ the owner, and the command it would run. A registry error is its own failure: it prints the
532
+ manager's error, offers no update, and exits non-zero. A failed install reports the manager's stderr
533
+ and runs nothing after it. Once the install succeeds, the command reports the CLI version before and
534
+ after (`cli 1.2.3 → 1.4.0`, read from the binary the update just installed, because the
535
+ running process is still the old code), then hands the terminal to the new binary's `update -a`. One
536
+ command brings the CLI and the harness installs to the same version, and the exit code is the
537
+ refresh's.
538
+
539
+ The refresh spawns `<prefix>/bin/agent-cortex` from that same inferred prefix with an argv array and
540
+ inherits the terminal, so the refresh's own output is what the user reads. It is skipped in three
541
+ cases: `--check`, a failed update, and an install already at the published version (where
542
+ `agent-cortex update -a` is the refresh that is left). A refresh that cannot start — the path is
543
+ POSIX-shaped, while native Windows pnpm and npm write `.cmd` shims it does not match, and Node cannot
544
+ start a `.cmd` without a shell — prints the reason and the exact command to run by hand, and exits
545
+ non-zero. The CLI update has already succeeded by then, so `agent-cortex update -a` finishes the job.
546
+
547
+ ```sh
548
+ # what it reports, for a copy installed by a pnpm that is not the one on PATH
549
+ agent-cortex self-update --check
550
+ # installed 1.2.3
551
+ # published 1.4.0
552
+ # owner pnpm (/opt/pnpm-home/bin/pnpm)
553
+ # status update available: 1.2.3 → 1.4.0
554
+ # command /opt/pnpm-home/bin/pnpm add -g @jaybeeuu/agent-cortex@latest
555
+
556
+ # what a bare run adds after that report
557
+ agent-cortex self-update
558
+ # ✓ /opt/pnpm-home/bin/pnpm add -g @jaybeeuu/agent-cortex@latest
559
+ # cli 1.2.3 → 1.4.0
560
+ # → refreshing installed harnesses with /opt/pnpm-home/bin/agent-cortex update -a
561
+ # …the new binary's own update report…
562
+ ```
563
+
507
564
  ## Refreshing installed harnesses (`agent-cortex update`)
508
565
 
509
566
  `agent-cortex update` re-runs a harness installer and reports what changed. It installs nothing
@@ -536,9 +593,8 @@ the installer wrote; harnesses already at the CLI version are listed as skipped.
536
593
  version is read back from the manifest its installer wrote, so a refresh that failed to
537
594
  materialise reports `unknown` rather than claiming the CLI version.
538
595
 
539
- This refreshes the installs, not the CLI. Bump the global package first
540
- (`pnpm add -g @jaybeeuu/agent-cortex@latest`), then update the harnesses — see
541
- [`docs/dev-loop.md`](docs/dev-loop.md).
596
+ This refreshes the installs, not the CLI. `agent-cortex self-update` does both in one step; the
597
+ [`docs/dev-loop.md`](docs/dev-loop.md) page records what a global reinstall has to fix.
542
598
 
543
599
  ## Migrating a beads workspace
544
600
 
package/agents/README.md CHANGED
@@ -44,13 +44,13 @@ agents/ralph/
44
44
  `{{SECTION:wake}}` is the one seam where harness differences belong: the shared `agent.md`
45
45
  names no harness and no harness-specific tool, and every one of those facts lives in a
46
46
  `wake.md` that states its mechanism in one sentence, then covers **spawn** (tool and argument
47
- shape), **completion arrival**, **id tracking**, **log flush**, and **stop** behaviour.
47
+ shape), **completion arrival**, **id tracking**, **trail reading**, and **stop** behaviour.
48
48
  `token-map.json`'s `wake.mechanism` table records the same fact machine-readably.
49
49
 
50
50
  | Harness | `wake.mechanism` | Completion arrives via | Id tracking | Stop means |
51
51
  |---------|------------------|------------------------|-------------|------------|
52
52
  | `pi` | `blocking-wait` | `wait_for_agents` returns as soon as a worker finishes, result inline | `agentId` only | stop calling `wait_for_agents` — nothing to kill |
53
- | `claude` | `event-driven` | harness re-invokes ralph with the result inline | task ID only, no `logLine` | simply stop — nothing to kill |
53
+ | `claude` | `event-driven` | harness re-invokes ralph with the result inline | task ID only | simply stop — nothing to kill |
54
54
 
55
55
  ### Example: plan agent (no per-harness sections)
56
56
 
@@ -14,14 +14,14 @@ Harness-agnostic rules (tool names and completion detection differ per harness
14
14
  - ALWAYS set the subagent's working directory to the feature worktree path when running stage chores.
15
15
  - ALWAYS keep the returned agent/task id in memory so you can read the result later.
16
16
 
17
- Each pipeline stage is a separate **chore bead**, pre-created by `create-chores.mjs` from the `create-task` skill's `pipeline.json` when the task is expanded, with `blocks` deps that encode the stage order. Ralph never creates a stage chore — dispatch is always "claim what `bd ready -l execution:afk` returns". Stage tags (`stage:*`) live on chore beads, not on the parent feature bead. Loop counts are derived by querying chore children of the parent, not stored in state. Orchestration state is derived entirely from beads — the only local state is `state.json` (worker-ID-to-bead mapping plus whatever wake-loop handle the wake section tracks) and per-parent log files.
17
+ Each pipeline stage is a separate **chore bead**, pre-created by `create-chores.mjs` from the `create-task` skill's `pipeline.json` when the task is expanded, with `blocks` deps that encode the stage order. Ralph never creates a stage chore — dispatch is always "claim what `bd ready -l execution:afk` returns". Stage tags (`stage:*`) live on chore beads, not on the parent feature bead. Loop counts are derived by querying chore children of the parent, not stored in state. Orchestration state is derived entirely from beads — the only local state is `state.json`, holding the worker-ID-to-bead mapping plus whatever wake-loop handle the wake section tracks. Progress lives in the bead trail the workers write, never in a file Ralph tails.
18
18
 
19
19
  ## Branching model
20
20
 
21
21
  - **Single-feature epics** (epic has exactly one feature task child): skip the epic branch entirely. The feature branch (`feature/<parent-id>`) is based directly from `origin/main`. The HITL PR targets `main` directly. No epic PR is required.
22
22
  - **Multi-feature epics** (epic has two or more feature task children): each epic runs on `epic/<epic-id>` (base: `origin/main`, never local `main`). Each feature branch is based from its epic branch. Completed features PR into `epic/<epic-id>`; the completed epic PRs into `main`.
23
23
  - Each parent feature task runs on `feature/<parent-id>` in `.agent-cortex/worktrees/<parent-id>`.
24
- - Each implemented bead owns a child HITL PR-gate task bead (`lifecycle:feature-pr`, blocked by its own `document` chore) for PR review/merge, plus a `stage:housekeeping` chore blocked behind that gate.
24
+ - Each implemented bead owns a child HITL PR-gate task bead (`lifecycle:feature-pr`, blocked by its own `document` chore) for PR review/merge, plus a `stage:post-merge` chore and a `stage:housekeeping` chore, each blocked behind that gate.
25
25
  - Completed features must be reviewed by PR merge from the agent branch (`feature/<parent-id>`) into its base (epic branch for multi-feature epics, `main` for single-feature epics), then the HITL PR task bead must be closed by a human before Ralph continues feature scheduling.
26
26
  - Completed multi-feature epics must be reviewed by PR merge into `main`.
27
27
 
@@ -63,7 +63,7 @@ A ready `execution:afk` bead of type `feature` with **no** children is not dispa
63
63
  2. Dispatch a **decomposition worker** in the feature worktree (`.agent-cortex/worktrees/<feature-id>`) whose whole job is to run the `create-task` hierarchy flow (`prd-to-tasks` → `create-task`) for that one **existing** feature — its planning bead and impl children only, never a second feature bead — and report the IDs it created. The worker builds one `execution:hitl` planning bead (`--parent <feature-id>`) plus `execution:afk` implementation task children (`--parent <feature-id>`, `--no-inherit-labels`), each wired with `bd dep add <impl-child> <planning-bead>` so the dependency — not an extra label — is the readiness gate. `create-task`'s feature path (its `SKILL.md` steps 5–6) is the authority for this shape.
64
64
  3. Record the worker in `inflight` as a **decomposition** entry — it holds no chore, so `choreId` is `null`:
65
65
  ```json
66
- { "kind": "decompose", "choreId": null, "parentId": "<feature-id>", "title": "<feature title>", "agentId": "<agent-id>", "logLine": 1 }
66
+ { "kind": "decompose", "choreId": null, "parentId": "<feature-id>", "title": "<feature title>", "agentId": "<agent-id>" }
67
67
  ```
68
68
  4. On completion, confirm the children exist (`bd children <feature-id> --json`) rather than trusting the report, and surface the created IDs in chat. An empty list means the decomposition failed: record the feature for the shutdown summary and continue — do **not** re-dispatch.
69
69
  5. **Never re-dispatch a decomposition.** The bead creation it runs is not idempotent, so a second run duplicates the planning bead and every implementation child beside the first.
@@ -90,16 +90,18 @@ A ready `execution:afk` task bead with no `stage:*` chore children has nothing t
90
90
  The command is idempotent: it adopts an existing child by its `stage:<id>` or `lifecycle:feature-pr` label, creates only what is missing, skips deps that are already wired, and prints the resolved mapping either way. Re-running it is the recovery path for a failed expansion.
91
91
  3. Record the worker in `inflight` as an **expansion** entry — it has no chore to key on, so `choreId` is `null`:
92
92
  ```json
93
- { "kind": "expand", "choreId": null, "parentId": "<parent-id>", "title": "<parent title>", "agentId": "<agent-id>", "logLine": 1 }
93
+ { "kind": "expand", "choreId": null, "parentId": "<parent-id>", "title": "<parent title>", "agentId": "<agent-id>" }
94
94
  ```
95
95
  That entry is what keeps it in the wait set and makes its completion attributable to the parent.
96
- 4. The worker reports the returned mapping — `code`, `verify`, `review`, `document`, `housekeeping`, `featurePrReview` — and closes nothing. It emits **no** `---REPORT---` block and owns no bead, so there is nothing to parse and no close to confirm.
96
+ 4. The worker reports the returned mapping — `code`, `verify`, `review`, `document`, `post-merge`, `housekeeping`, `featurePrReview` — and closes nothing. It emits **no** `---REPORT---` block and owns no bead, so there is nothing to parse and no close to confirm.
97
97
  5. Its completion means the parent now has a `stage:*` chain: the event loop's next `bd ready -l execution:afk` pass picks up the `stage:code` chore (event loop step 7).
98
98
 
99
99
  **Expansion completion contract.** An expansion worker is dispatched like a stage worker but is not one: no chore claim, no `---REPORT---`, no leaf-bead close. Handle its completion with the expansion branch in event-loop step 3, which confirms the chain exists (`bd children <parent-id> --json | grep -c '"stage:'` prints one match per stage chore — the gate carries `lifecycle:feature-pr` and is not counted) and dispatches the ready `stage:code` chore. A count below the stage total in `pipeline.json` is a partial chain, whose missing stages never arrive, so re-dispatch the expansion instead of dispatching on. If the parent still has no `stage:*` children the expansion failed: surface the worker's output in chat, record the parent for the shutdown summary, and re-dispatch the expansion — `create-chores.mjs` is idempotent, so a second run adopts the chores that exist, creates only the missing ones, and reports the whole mapping. Either way, create nothing and close nothing yourself.
100
100
 
101
101
  **Housekeeping chore.** One stage runs outside the pipeline's ordering: `stage:housekeeping`, labelled `lifecycle:housekeeping` and blocked behind the PR gate bead, so it becomes ready only after a human merges the PR and closes the gate. Dispatch it with the **main checkout** as cwd — not the feature worktree — because the worktree it removes can be the parent's own. The worker runs `prune-worktrees.mjs`, retries once on a non-zero exit (exit `1` is normal: an open bead counts as survival), and then decides from the per-worktree report. It fails the chore and leaves it **open** when a `closed-bead` worktree is still `refused`; a `kept` or `refused` entry for an open bead is a normal report. Never close a chore over a worktree the script did not remove.
102
102
 
103
+ **Post-merge check.** The `stage:post-merge` chore, labelled `lifecycle:post-merge`, is the other stage blocked behind the PR gate, so it too becomes ready only after a human merges and closes the gate. Dispatch it with the **main checkout** as cwd: the commit it reads landed on the base branch. The worker runs `post-merge-check.mjs` once and reports the exit status — `0` passed, `1` failed, `2` inconclusive. Exit `1` has already filed one P1 escalation bead (`lifecycle:post-merge-escalation`, carrying the run URL and the failing job); the worker leaves its chore **open** and closes nothing else. Exit `2` also leaves the chore open, with nothing filed. The stage never retries, never re-runs the workflow, never reverts the merge, never reopens the parent, and builds no `stage:fix` chain — no fix round repairs a commit that already merged. It and `stage:housekeeping` are siblings on the gate: neither waits on the other, because an inconclusive check must not block the worktree reclamation.
104
+
103
105
  **Never expand an existing bead by running `create-task`** (or any other command that creates a bead). `create-task` creates a bead first and expands second, so running it for an existing bead leaves a **second parent** beside the original, which stays chore-less and never gets dispatched. `create-chores.mjs` expands a bead that already exists; it never creates parents.
104
106
 
105
107
  ---
@@ -108,11 +110,11 @@ A ready `execution:afk` task bead with no `stage:*` chore children has nothing t
108
110
 
109
111
  Chores already exist and their deps already encode the order, so dispatch is claim-and-spawn — claim the ready chore (`bd update <chore-id> --claim`) and skip to the prompt.
110
112
 
111
- Load the universal stage runner prompt from the `run-pipeline-stage` skill's `prompts/stage-runner.md`, fill in all placeholders (including `<stage>` from the bead label, parent task description from `bd show <parent-id>`, prior SUMMARY/FILES_CHANGED from the last REPORT, chore bead ID, log path `.agent-cortex/ralph/ralph-<parent-id>.log`), and spawn a subagent in **background** mode using the spawning mechanism described in the wake section, running from the feature worktree. Stage-specific policy comes from that skill's `playbooks/<stage>.md`. The prompt's lifecycle, remediation, and REPORT sections are the worker's contract — pass them through verbatim, never restate or trim them.
113
+ Load the universal stage runner prompt from the `run-pipeline-stage` skill's `prompts/stage-runner.md`, fill in all placeholders (including `<stage>` from the bead label, parent task description from `bd show <parent-id>`, prior SUMMARY/FILES_CHANGED from the last REPORT, chore bead ID, and the trail writer's path `<run-pipeline-stage-scripts>/trail-entry.mjs`), and spawn a subagent in **background** mode using the spawning mechanism described in the wake section, running from the feature worktree. Stage-specific policy comes from that skill's `playbooks/<stage>.md`. The prompt's lifecycle, remediation, and REPORT sections are the worker's contract — pass them through verbatim, never restate or trim them.
112
114
 
113
115
  Add the entry to `inflight` in `state.json`:
114
116
  ```json
115
- { "kind": "stage", "choreId": "<chore-id>", "parentId": "<parent-id>", "title": "<parent title>", "agentId": "<agent-id>", "logLine": 1 }
117
+ { "kind": "stage", "choreId": "<chore-id>", "parentId": "<parent-id>", "title": "<parent title>", "agentId": "<agent-id>" }
116
118
  ```
117
119
 
118
120
  ---
@@ -130,16 +132,16 @@ bd show <id> # full detail, including the worker's notes
130
132
  Report status in chat from those commands. The only files Ralph owns are:
131
133
 
132
134
  - **`.agent-cortex/ralph/state.json`** — runtime bookkeeping only (worker-ID→bead mapping plus the wake loop's own handle).
133
- - **`.agent-cortex/ralph/ralph-*.log`** — per-parent log files written by subagents (e.g. `.agent-cortex/ralph/ralph-abc-123.log`). Keyed by **parent** bead ID so all chore stages for a feature share one log.
135
+ - **The bead trail** — not a file Ralph writes: each worker appends its own entries with `trail-entry.mjs`, and Ralph reads them from `bd show` and `bd provenance log`.
134
136
 
135
137
  All orchestration state is derived from beads:
136
138
 
137
139
  ```json
138
140
  {
139
141
  "inflight": [
140
- { "kind": "stage", "choreId": "xyz-456", "parentId": "abc-123", "title": "Add auth", "agentId": "agent-xyz-456", "logLine": 4 },
141
- { "kind": "stage", "choreId": "def-789", "parentId": "ghi-101", "title": "Fix cache", "agentId": "agent-def-789", "logLine": 7 },
142
- { "kind": "expand", "choreId": null, "parentId": "jkl-202", "title": "Expand billing", "agentId": "agent-jkl-202", "logLine": 1 }
142
+ { "kind": "stage", "choreId": "xyz-456", "parentId": "abc-123", "title": "Add auth", "agentId": "agent-xyz-456" },
143
+ { "kind": "stage", "choreId": "def-789", "parentId": "ghi-101", "title": "Fix cache", "agentId": "agent-def-789" },
144
+ { "kind": "expand", "choreId": null, "parentId": "jkl-202", "title": "Expand billing", "agentId": "agent-jkl-202" }
143
145
  ]
144
146
  }
145
147
  ```
@@ -147,8 +149,7 @@ All orchestration state is derived from beads:
147
149
  - **inflight[].kind**: `"stage"` for a dispatched stage chore (the only shape that carries a `choreId`), `"decompose"` for a feature-decomposition worker and `"expand"` for an expansion worker (both no chore — `choreId` is `null`). Every dispatched agent has an entry; anything missing from `inflight` is invisible to the wait set and to the HITL-pause check.
148
150
  - **inflight[].agentId**: the worker id the spawn call returned — the key every completion is correlated to its bead against, and the identifier the wake section's read/wait path takes (see that section).
149
151
  - **inflight[].choreId**: the chore bead currently being worked by the subagent.
150
- - **inflight[].parentId**: the parent feature task bead. Log file is `.agent-cortex/ralph/ralph-<parentId>.log`.
151
- - **inflight[].logLine**: the next line number to read from the parent's log file (1-based; start at 1). Updated after every poll.
152
+ - **inflight[].parentId**: the parent feature task bead — the id every trail entry is read under (`bd show <parentId>`, `bd children <parentId>`).
152
153
  - **Loop counts are not stored here** — derive them from beads:
153
154
  - Fix round count = number of `stage:fix` chore children of `<parentId>` (closed ones count)
154
155
 
@@ -166,7 +167,7 @@ After initialization, Ralph waits for background agents to complete. Completions
166
167
 
167
168
  ### If a background agent completed
168
169
 
169
- 1. **Flush** that bead's log using the procedure in the wake section to pick up any final lines for the chat summary (a mechanism that delivers the log with the completion needs no flush).
170
+ 1. **Read the worker's bead trail** — `bd show <chore-id>` for its entries and `bd provenance log <chore-id>` for the refs — and use it for the chat summary. There is no log file to flush.
170
171
  2. **Read** the completed agent's full output the way the wake section describes.
171
172
  3. **Re-read** `.agent-cortex/ralph/state.json` to identify the entry for that agent ID, then branch on its `kind`:
172
173
  - **`kind: "expand"` — expansion completion branch.** The worker claimed no chore, emits no `---REPORT---`, and owns no bead to confirm, so steps 4-6 **do not apply**: remove the entry from `inflight`, confirm the parent now has `stage:*` chore children (`bd children <parent-id> --json | grep -c '"stage:'`) and surface the reported mapping in chat, then go straight to step 7 — the new `stage:code` chore is ready to dispatch. If the count is `0` — or below the stage total, which is a partial chain whose later stages never arrive — the expansion failed: surface the worker's output, record the parent for the shutdown summary, remove the entry, and re-dispatch the expansion — re-running `create-chores.mjs` is idempotent and is the recovery path, so it repairs the tree instead of duplicating it. Never create or close a bead for an expansion.
@@ -175,9 +176,9 @@ After initialization, Ralph waits for background agents to complete. Completions
175
176
  4. **Parse** the agent's `---REPORT---` block (see report format in the `run-pipeline-stage` skill).
176
177
  5. **Confirm** the worker closed its own leaf execution bead: `bd show <chore-id>` should read `closed`. If it is still open the worker died mid-stage — read its notes and re-dispatch. Never close it yourself.
177
178
  6. **Advance** the parent using the routing guidance in the `run-pipeline-stage` skill:
178
- - **Success paths** (code → verify, verify SUCCESS → review, review SUCCESS → document): create nothing — closing the chore already unblocked the next stage of the pre-created chain. Point the parent's inflight entry at that newly ready `stage:*` chore and dispatch it (see _Dispatching a stage chore_ above), resetting logLine to 1.
179
+ - **Success paths** (code → verify, verify SUCCESS → review, review SUCCESS → document): create nothing — closing the chore already unblocked the next stage of the pre-created chain. Point the parent's inflight entry at that newly ready `stage:*` chore and dispatch it (see _Dispatching a stage chore_ above).
179
180
  - **Documenting → done**: close the parent feature bead (`bd close <parent-id>`), remove it from inflight, open/update the feature PR immediately (agent-branch → feature branch), report the PR URL in chat, then update the HITL PR gate bead with the PR URL.
180
- - **Failure paths** (`OUTCOME: BLOCKED` from any stage): create nothing. The worker already closed its failed chore and built its own remediation — a `stage:fix` chore plus a fresh instance of the failed stage blocked on it. Run the cap backstop (see below); if the parent is at `maxFixRounds`, block the parent instead and record it for shutdown. Remove the inflight entry for this chore; the worker's beads appear in `bd ready` and are picked up in step 7.
181
+ - **Failure paths** (`OUTCOME: BLOCKED` from any stage): create nothing. The worker already closed its failed chore and built its own remediation — a `stage:fix` chore plus a fresh instance of the failed stage blocked on it. Run the cap backstop (see below); if the parent is at `maxFixRounds`, block the parent instead and record it for shutdown. Remove the inflight entry for this chore; the worker's beads appear in `bd ready` and are picked up in step 7. `post-merge` and `housekeeping` are the exceptions: neither builds a chain, and each leaves its chore **open**, so remove the inflight entry and hand the chore to a human — never re-dispatch it, and for `post-merge` report the escalation bead the check filed.
181
182
  7. **Check for newly ready beads**: run `bd ready -l execution:afk`. For each bead not yet tracked:
182
183
  - **Chore bead with `stage:*` label** (a worker-built remediation chore or a pre-created stage): find its parent via `bd show <chore-id>` (follow the `parent-child` dep). Run the cap backstop (see below). If under cap: dispatch it via _Dispatching a stage chore_. If at cap: block the parent (`bd update <parent-id> --status blocked --append-notes "<cap> reached"`) and record it for shutdown — create nothing.
183
184
  - **Childless `feature` bead, in-flight count < 5, no pending human action**: dispatch a decomposition worker (see _Feature decomposition_ above). Check `pendingHumanAction` with `node skills/workflow/ralph/scripts/pending-gates.mjs` — an unblocked `lifecycle:feature-pr` gate means a feature is awaiting a human merge, so hold new parent features. Gates still blocked behind their own pipeline are parked and do not count.
@@ -1,6 +1,6 @@
1
1
  ## Wake mechanism (Claude Code — event-driven)
2
2
 
3
- **Mechanism: event-driven — the harness re-invokes you automatically when a background worker completes and delivers that worker's result inline, so there is no poll timer, no sleep, and no log flush.**
3
+ **Mechanism: event-driven — the harness re-invokes you automatically when a background worker completes and delivers that worker's result inline, so there is no poll timer and no sleep.**
4
4
 
5
5
  ### Spawn
6
6
 
@@ -29,11 +29,11 @@ A completion is **delivered, not observed**: Claude Code re-invokes you automati
29
29
  Initialize `.agent-cortex/ralph/state.json` as `{ "inflight": [] }` — there is no timer handle to track.
30
30
 
31
31
  - **inflight[].agentId** — the task ID `Task` returned for that worker; it is the key the delivered completion is correlated to its bead, and the equivalent of `TaskGet`'s identifier when you need to inspect one worker.
32
- - **inflight[].logLine** — not used on Claude; leave it at `1`. Progress lines (`.agent-cortex/ralph/ralph-<parentId>.log`) are written by the workers themselves and surfaced by the harness with the completion.
32
+ - **No trail bookmark** — nothing to track. Progress is read from the bead itself (`bd show <chore-id>`, `bd provenance log <chore-id>`): the worker writes it, so the harness delivers the completion with the result already in hand.
33
33
 
34
- ### Log flush
34
+ ### Trail reading
35
35
 
36
- None. There is **no log tailing on Claude**: the completion is delivered with the result already in hand, so there is nothing to flush and nothing to poll. Produce the shared chat summaries from the delivered result instead.
36
+ None beyond the completion itself. There is **nothing to tail and nothing to flush** on Claude: read the completed worker's bead once for its entries and refs, and produce the shared chat summary from the delivered result.
37
37
 
38
38
  ### Stop
39
39
 
@@ -46,30 +46,25 @@ Initialize `.agent-cortex/ralph/state.json` as `{ "timerShellId": null, "infligh
46
46
  - **inflight[].agentId** — the ID `task` returned for that worker; it is the argument `wait_for_agents` takes, the identifier for a `read_agent` fallback, and the key the completion is correlated to its bead.
47
47
  - **timerShellId** — stays `null` on PI forever: the blocking wait replaces a poll timer, so nothing is ever recorded there.
48
48
 
49
- ### Log flush
50
-
51
- Flush new log lines as part of handling each wait result — that is when the loop wakes, and a worker's final lines arrive with the completion. Run this procedure each time `wait_for_agents` returns (or whenever a new agent is dispatched):
52
-
53
- 1. **Query in-flight beads**: read `inflight` from `state.json`. Each entry has a `parentId` and `logLine`.
54
- 2. For each in-flight entry, read new lines from its log file:
55
- ```bash
56
- tail -n +<logLine> .agent-cortex/ralph/ralph-<parentId>.log 2>/dev/null
57
- ```
58
- 3. For each entry that has new lines:
59
- - **Post a chat summary** of new key events (stage transitions and notable events — not every line verbatim). Format:
60
- ```
61
- 📋 [parent-id] <title>
62
- coding → verifying (or whatever transition)
63
- Tests: 12 passed, 0 failed
64
- ```
65
- - Update `logLine` in `state.json` for that entry.
66
- 4. If no entry had new lines, post nothing — do not spam the chat with empty polls.
49
+ ### Reading the trail
50
+
51
+ There is no log file and nothing to flush. A worker appends its own checkpoints to its bead with
52
+ `trail-entry.mjs`, so progress is read from the bead itself when a wait returns:
53
+
54
+ ```bash
55
+ bd show <chore-id> # entries: Outcome, Evidence, What is left
56
+ bd provenance log <chore-id> # refs: git-sha, branch, pr, work-id
57
+ ```
58
+
59
+ Read each completed worker's bead once, post a chat summary of what is new — the stage transition,
60
+ the test and lint results, the close reason — and post nothing when nothing new arrived. Nothing in
61
+ `state.json` needs a bookmark, because the trail is not a stream to follow.
67
62
 
68
63
  ### Wait loop lifecycle
69
64
 
70
65
  - **Dispatch-and-wait** — during initialization, dispatch up to 5 AFK chore subagents with `task` (or an expansion worker for a chore-less AFK bead) and hold their agent IDs (recorded in `state.json`'s `inflight` list; expansion entries carry `kind: "expand"` and `choreId: null`).
71
66
  - **Wait** — call `wait_for_agents` with the agent IDs of every in-flight agent, stage worker or expansion worker (`timeout` defaults to 120s). The tool blocks until at least one finishes. For each completed agent:
72
- 1. Flush its log tail if it has new lines (see _Log flush_ above) to surface progress to chat.
67
+ 1. Read its bead trail (see _Reading the trail_ above) to surface progress to chat.
73
68
  2. Apply the shared completion handling described under _Completion arrival_ above.
74
69
  3. Drop the completed agent ID from the wait set.
75
70
  - **Repeat** — dispatch replacements for completed work (up to 5 in flight), add their new IDs to the wait set, and call `wait_for_agents` again with the remaining + new IDs. A completed expansion leaves a slot to fill with its parent's newly ready `stage:code` chore.
@@ -86,4 +81,4 @@ Nothing to kill: stopping means simply **stop calling `wait_for_agents`**. There
86
81
  - **Always** keep a `wait_for_agents` call outstanding while agents are in-flight — stage workers and expansion workers alike. Never let running agent work stall without a wait active.
87
82
  - **Never** re-dispatch an agent that is merely STILL RUNNING — wait again on the same ID.
88
83
  - **Never** start `sleep` / background timer loops for completion detection on PI — `wait_for_agents` replaces them, and there is nothing to kill on HITL Pause.
89
- - **Never** post empty poll updates to chat — only surface new log content.
84
+ - **Never** post empty poll updates to chat — only surface what a bead actually reports.
@@ -19,7 +19,8 @@ import {
19
19
  } from "../lib/harness-update.mjs";
20
20
  import { join, dirname } from "node:path";
21
21
  import { fileURLToPath } from "node:url";
22
- import { readFile } from "node:fs/promises";
22
+ import { readFile, realpath } from "node:fs/promises";
23
+ import { runSelfUpdate } from "../lib/self-update.mjs";
23
24
  import { installPi, registerPi, sweepLegacyPiUserDirs } from "./installers/pi.mjs";
24
25
 
25
26
  /** @typedef {import("./installers/pi.mjs").InstallPiResult} InstallPiResult */
@@ -279,6 +280,24 @@ function printPiSweep({ removed }) {
279
280
  }
280
281
  }
281
282
 
283
+ if (parsed.command === "self-update") {
284
+ if (parsed.optionError) {
285
+ process.stderr.write(`${parsed.optionError}\n`);
286
+ process.exit(1);
287
+ }
288
+ try {
289
+ // The real path follows the global bin shim into the layout of the manager
290
+ // that installed this copy, which is what identifies the owner. Taking it
291
+ // from this file's own URL keeps detection on the running entry point, not
292
+ // on the cwd or on PATH.
293
+ const entryPoint = await realpath(fileURLToPath(import.meta.url));
294
+ process.exitCode = await runSelfUpdate({ entryPoint, programName, check: parsed.check ?? false });
295
+ } catch (err) {
296
+ process.stderr.write(`${/** @type {Error} */ (err).message}\n`);
297
+ process.exit(1);
298
+ }
299
+ }
300
+
282
301
  if (parsed.command === "migrate") {
283
302
  if (parsed.optionError) {
284
303
  process.stderr.write(`${parsed.optionError}\n`);