counterparts 0.1.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 (195) hide show
  1. package/CONSTITUTION.md +68 -0
  2. package/LICENSE +21 -0
  3. package/README.md +348 -0
  4. package/docs/ELI5.md +84 -0
  5. package/docs/QUICKSTART.md +1258 -0
  6. package/docs/module-map.md +81 -0
  7. package/package.json +63 -0
  8. package/src/adapters/claude-code/CONTRACT.md +606 -0
  9. package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
  10. package/src/adapters/claude-code/NOTES.md +1055 -0
  11. package/src/adapters/claude-code/bin/hook.ts +820 -0
  12. package/src/adapters/claude-code/bin/runner.ts +522 -0
  13. package/src/adapters/claude-code/config.ts +778 -0
  14. package/src/adapters/claude-code/credentials.ts +199 -0
  15. package/src/adapters/claude-code/doctor.ts +2557 -0
  16. package/src/adapters/claude-code/embed-client.ts +617 -0
  17. package/src/adapters/claude-code/hooks.ts +2240 -0
  18. package/src/adapters/claude-code/index.ts +224 -0
  19. package/src/adapters/claude-code/interpret-client.ts +395 -0
  20. package/src/adapters/claude-code/page-writer.ts +462 -0
  21. package/src/adapters/claude-code/primacy.ts +162 -0
  22. package/src/adapters/claude-code/spawn.ts +241 -0
  23. package/src/adapters/claude-code/standdown.ts +536 -0
  24. package/src/adapters/claude-code/transcript.ts +661 -0
  25. package/src/adapters/claude-code/vectors.ts +415 -0
  26. package/src/adapters/cli/CONTRACT.md +255 -0
  27. package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
  28. package/src/adapters/cli/NOTES.md +936 -0
  29. package/src/adapters/cli/bin/counterparts.ts +74 -0
  30. package/src/adapters/cli/commands.ts +6095 -0
  31. package/src/adapters/cli/export.ts +766 -0
  32. package/src/adapters/cli/index.ts +103 -0
  33. package/src/adapters/cli/install.ts +670 -0
  34. package/src/adapters/cli/removal.ts +1186 -0
  35. package/src/adapters/cli/repair-dates.ts +659 -0
  36. package/src/adapters/cli/self-page.ts +229 -0
  37. package/src/adapters/cli/snapshot.ts +279 -0
  38. package/src/adapters/cli/start-fresh.ts +1228 -0
  39. package/src/adapters/config-path.ts +342 -0
  40. package/src/adapters/dashboard/CONTRACT.md +67 -0
  41. package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
  42. package/src/adapters/dashboard/NOTES.md +474 -0
  43. package/src/adapters/dashboard/activity.ts +121 -0
  44. package/src/adapters/dashboard/ansi.ts +82 -0
  45. package/src/adapters/dashboard/bin/dashboard.ts +479 -0
  46. package/src/adapters/dashboard/browse.ts +298 -0
  47. package/src/adapters/dashboard/identity.ts +182 -0
  48. package/src/adapters/dashboard/index.ts +183 -0
  49. package/src/adapters/dashboard/layout.ts +149 -0
  50. package/src/adapters/dashboard/registries.ts +291 -0
  51. package/src/adapters/dashboard/resolve.ts +206 -0
  52. package/src/adapters/dashboard/source.ts +48 -0
  53. package/src/adapters/dashboard/status.ts +327 -0
  54. package/src/adapters/dashboard/stories.ts +194 -0
  55. package/src/adapters/dashboard/web/app.html +1731 -0
  56. package/src/adapters/dashboard/web/brain.html +463 -0
  57. package/src/adapters/dashboard/web/fired.ts +31 -0
  58. package/src/adapters/dashboard/web/flow.ts +457 -0
  59. package/src/adapters/dashboard/web/narrate.ts +1042 -0
  60. package/src/adapters/dashboard/web/reveal.ts +135 -0
  61. package/src/adapters/dashboard/web/server.ts +287 -0
  62. package/src/adapters/dashboard/web/views.ts +1744 -0
  63. package/src/adapters/expansions.ts +569 -0
  64. package/src/adapters/fired.ts +1580 -0
  65. package/src/adapters/mcp/CONTRACT.md +240 -0
  66. package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
  67. package/src/adapters/mcp/NOTES.md +205 -0
  68. package/src/adapters/mcp/bin/serve.ts +349 -0
  69. package/src/adapters/mcp/deliberate.ts +619 -0
  70. package/src/adapters/mcp/index.ts +101 -0
  71. package/src/adapters/mcp/protocol.ts +170 -0
  72. package/src/adapters/mcp/server.ts +1740 -0
  73. package/src/adapters/mcp/stdio.ts +56 -0
  74. package/src/adapters/mcp/tools.ts +779 -0
  75. package/src/adapters/scopes.ts +657 -0
  76. package/src/adapters/sessions.ts +402 -0
  77. package/src/adapters/snapshots.ts +1069 -0
  78. package/src/adapters/stance-env.ts +137 -0
  79. package/src/core/associate/CONTRACT.md +118 -0
  80. package/src/core/associate/INTERFACE-GAPS.md +173 -0
  81. package/src/core/associate/NOTES.md +194 -0
  82. package/src/core/associate/buffer.ts +66 -0
  83. package/src/core/associate/edges.ts +188 -0
  84. package/src/core/associate/index.ts +570 -0
  85. package/src/core/associate/pending.ts +383 -0
  86. package/src/core/associate/spread.ts +149 -0
  87. package/src/core/associate/tunables.ts +123 -0
  88. package/src/core/bridge.ts +272 -0
  89. package/src/core/briefing.ts +67 -0
  90. package/src/core/counterpart.ts +3855 -0
  91. package/src/core/encode/CONTRACT.md +151 -0
  92. package/src/core/encode/INTERFACE-GAPS.md +135 -0
  93. package/src/core/encode/NOTES.md +146 -0
  94. package/src/core/encode/aliases.ts +71 -0
  95. package/src/core/encode/battery.ts +284 -0
  96. package/src/core/encode/chunk.ts +265 -0
  97. package/src/core/encode/emotion.ts +119 -0
  98. package/src/core/encode/floor.ts +76 -0
  99. package/src/core/encode/index.ts +100 -0
  100. package/src/core/encode/precision.ts +162 -0
  101. package/src/core/encode/preselect.ts +269 -0
  102. package/src/core/encode/salience.ts +108 -0
  103. package/src/core/encode/secrets.ts +265 -0
  104. package/src/core/encode/tunables.ts +99 -0
  105. package/src/core/encode/types.ts +286 -0
  106. package/src/core/encode/words.ts +75 -0
  107. package/src/core/handoff/CONTRACT.md +199 -0
  108. package/src/core/handoff/INTERFACE-GAPS.md +166 -0
  109. package/src/core/handoff/NOTES.md +206 -0
  110. package/src/core/handoff/index.ts +957 -0
  111. package/src/core/mint.ts +279 -0
  112. package/src/core/observer.ts +28 -0
  113. package/src/core/physics/CONTRACT.md +341 -0
  114. package/src/core/physics/NOTES.md +155 -0
  115. package/src/core/physics/clock.ts +51 -0
  116. package/src/core/physics/index.ts +1054 -0
  117. package/src/core/prospective/CONTRACT.md +137 -0
  118. package/src/core/prospective/INTERFACE-GAPS.md +112 -0
  119. package/src/core/prospective/NOTES.md +160 -0
  120. package/src/core/prospective/derive.ts +188 -0
  121. package/src/core/prospective/index.ts +1030 -0
  122. package/src/core/prospective/tunables.ts +72 -0
  123. package/src/core/prospective/windows.ts +187 -0
  124. package/src/core/recall/CONTRACT.md +326 -0
  125. package/src/core/recall/INTERFACE-GAPS.md +163 -0
  126. package/src/core/recall/NOTES.md +472 -0
  127. package/src/core/recall/activate.ts +521 -0
  128. package/src/core/recall/cues.ts +275 -0
  129. package/src/core/recall/gate.ts +441 -0
  130. package/src/core/recall/index.ts +692 -0
  131. package/src/core/recall/probe.ts +239 -0
  132. package/src/core/recall/reference.ts +201 -0
  133. package/src/core/recall/render.ts +285 -0
  134. package/src/core/recall/session.ts +403 -0
  135. package/src/core/recall/tunables.ts +329 -0
  136. package/src/core/remember/CONTRACT.md +293 -0
  137. package/src/core/remember/INTERFACE-GAPS.md +189 -0
  138. package/src/core/remember/NOTES.md +373 -0
  139. package/src/core/remember/fallback.ts +452 -0
  140. package/src/core/remember/index.ts +103 -0
  141. package/src/core/remember/owner-strike-seam.ts +479 -0
  142. package/src/core/remember/proposals.ts +609 -0
  143. package/src/core/remember/spans.ts +1310 -0
  144. package/src/core/remember/tunables.ts +111 -0
  145. package/src/core/remember/updates.ts +198 -0
  146. package/src/core/retrieval.ts +96 -0
  147. package/src/core/revision.ts +441 -0
  148. package/src/core/schemas/CONTRACT.md +190 -0
  149. package/src/core/schemas/INTERFACE-GAPS.md +172 -0
  150. package/src/core/schemas/NOTES.md +260 -0
  151. package/src/core/schemas/aliases.ts +160 -0
  152. package/src/core/schemas/index.ts +1459 -0
  153. package/src/core/schemas/tunables.ts +44 -0
  154. package/src/core/schemas/types.ts +387 -0
  155. package/src/core/self/CONTRACT.md +459 -0
  156. package/src/core/self/INTERFACE-GAPS.md +284 -0
  157. package/src/core/self/NOTES.md +1057 -0
  158. package/src/core/self/briefing.ts +980 -0
  159. package/src/core/self/episodes.ts +483 -0
  160. package/src/core/self/freeze.ts +103 -0
  161. package/src/core/self/identity.ts +604 -0
  162. package/src/core/self/index.ts +2130 -0
  163. package/src/core/self/journal-file.ts +760 -0
  164. package/src/core/self/page.ts +404 -0
  165. package/src/core/self/tunables.ts +244 -0
  166. package/src/core/self/writer.ts +714 -0
  167. package/src/core/sleep/CONTRACT.md +298 -0
  168. package/src/core/sleep/INTERFACE-GAPS.md +262 -0
  169. package/src/core/sleep/NOTES.md +770 -0
  170. package/src/core/sleep/briefing.ts +86 -0
  171. package/src/core/sleep/consolidate.ts +241 -0
  172. package/src/core/sleep/cycle.ts +598 -0
  173. package/src/core/sleep/decay.ts +237 -0
  174. package/src/core/sleep/dedup.ts +373 -0
  175. package/src/core/sleep/index.ts +112 -0
  176. package/src/core/sleep/log.ts +116 -0
  177. package/src/core/sleep/markers.ts +164 -0
  178. package/src/core/sleep/prune.ts +170 -0
  179. package/src/core/sleep/strength-cache.ts +176 -0
  180. package/src/core/sleep/tunables.ts +135 -0
  181. package/src/core/sleep/types.ts +542 -0
  182. package/src/core/store/CONTRACT.md +446 -0
  183. package/src/core/store/NOTES.md +1068 -0
  184. package/src/core/store/cache.ts +709 -0
  185. package/src/core/store/db.ts +275 -0
  186. package/src/core/store/errors.ts +134 -0
  187. package/src/core/store/index.ts +2450 -0
  188. package/src/core/store/operational.ts +610 -0
  189. package/src/core/store/owner-op-seam.ts +428 -0
  190. package/src/core/store/paths.ts +494 -0
  191. package/src/core/store/prose.ts +165 -0
  192. package/src/core/store/render.ts +87 -0
  193. package/src/core/store/walk-seam.ts +78 -0
  194. package/src/core/types.ts +68 -0
  195. package/tools/install-loop/run.sh +1063 -0
@@ -0,0 +1,1055 @@
1
+ # `adapters/claude-code/` — NOTES
2
+
3
+ *Implementation choices the CONTRACT left open, and the reasoning behind them.
4
+ Gaps and obligations live in `INTERFACE-GAPS.md`; this file is the "why it looks
5
+ like this" record.*
6
+
7
+ ## 1. One entry script, not five
8
+
9
+ `bin/hook.ts` dispatches on the host's `hook_event_name` rather than shipping a
10
+ script per hook. Host hook names, wiring and settings-file mechanics are
11
+ advisory (CONTRACT §5 G9), and one executable means one place where the payload
12
+ is parsed, one place that always exits 0, and one place that closes the store.
13
+ `HOOKS` and `SESSION_ENDING` are the enumerations a test walks; the dispatch is
14
+ `ClaudeCodeAdapter.hook()`, which is total over `HookName` by the compiler.
15
+
16
+ Suggested wiring (host trivia, not a contract):
17
+
18
+ ```json
19
+ { "hooks": { "SessionStart": [{ "hooks": [{ "type": "command",
20
+ "command": "~/.bun/bin/bun run <repo>/src/adapters/claude-code/bin/hook.ts" }] }] } }
21
+ ```
22
+
23
+ …and the same command for `UserPromptSubmit`, `Stop`, `SessionEnd`, `PreCompact`.
24
+
25
+ ## 2. The pure/impure split in `spawn.ts`
26
+
27
+ `planSpawn` is pure and returns a checkable `SpawnPlan`; `spawnDetached` is the
28
+ six lines that start a process. Everything worth asserting — the watchdog
29
+ validated against `remember/`'s staleness window, the credential precondition,
30
+ the environment assembled with `COUNTERPARTS_DATA_DIR` written LAST, the observer
31
+ refusal, the escalation counter — is in the pure half, so the tests prove the
32
+ properties without ever forking. `Spawner` is injected for the same reason.
33
+
34
+ ## 3. Why the adapter holds a `Counterpart` rather than the modules
35
+
36
+ Every hook needs two or three modules at once (recall needs schemas, prospective
37
+ and associate; the boundary needs spans and self). Assembling them here would be
38
+ a second composition root, and the one thing SEAMS exists to prevent is a caller
39
+ who forgets a channel and silently loses the safety half riding with it. The
40
+ adapter takes the assembled brain and adds nothing but host translation.
41
+
42
+ ## 4. Delivery telemetry rides on the NEXT hook
43
+
44
+ `sessionStart` records the sentinel it rendered; the session's first
45
+ `userPromptSubmit` reports what the host actually placed in context. That
46
+ ordering is forced: nothing inside the session-start hook can know what the host
47
+ did with its return value. It is also exactly scar §2.3's shape — v1 shipped
48
+ eleven days of truncated wakes because only the render was instrumented — so the
49
+ two records are deliberately separate events (`adapter.wake.injected` vs
50
+ `adapter.wake.delivered`), not one event with a flag.
51
+
52
+ The "next hook" half of that was written and then left unwired for the whole
53
+ parallel run; what closed it, and what the wiring cost, is the 2026-09-17 section
54
+ near the end of this file.
55
+
56
+ ## 5. The anti-loop guard is per (hook, session), in process
57
+
58
+ A hook's own injection lands in the transcript, and a host that re-fires on
59
+ injected text would recall on its own render forever. The guard is a set of
60
+ `hook:sessionId` keys held for the duration of the call — in-process on purpose,
61
+ because the failure it prevents is re-entrancy within one hook invocation, not a
62
+ race between two processes. Recall has its own, stronger protection at the cue
63
+ layer (`STRIPPERS`' `counterparts-injection` entry), so this is the second of two
64
+ independent defences rather than the only one.
65
+
66
+ ## 6. `substanceOf` is one function on purpose
67
+
68
+ Spec §2 G10 (conversational text only) and §2 G11 (injected context is kept in
69
+ capture, excluded from pacing) are two halves of one decision about the same turn
70
+ list. They are computed a few lines apart, from the same input, so they cannot
71
+ drift: `captureSpans` receives every turn and lets `remember/`'s `enters()` drop
72
+ the blind spot; `substanceOf` counts only `source === "conversation"`.
73
+
74
+ ## 7. The interpreter prompt asks for `remember/`'s vocabulary and trusts none of it
75
+
76
+ `SYSTEM_PROMPT` names exactly the fields `ProposalDraft` accepts. That is a
77
+ convenience for the model, not a security boundary: `intake()` re-validates every
78
+ field, unknown keys are dropped and counted, and a privileged operation has
79
+ nowhere to live because `Proposal` has no field for one (§4.1 G7). The prompt
80
+ could be wrong or ignored and nothing downstream would weaken.
81
+
82
+ ## 8. Why the response is parsed rather than schema-pinned
83
+
84
+ Structured outputs (`output_config.format`) would pin the shape server-side and
85
+ is the better answer. It is not used here because this build cannot exercise the
86
+ live endpoint — every test fakes `fetch` — and shipping an unverified request
87
+ shape into the one network call in the package would be exactly the kind of
88
+ "verified merged, not verified live" claim the constitution's line 11 rejects.
89
+ What ships instead is a string/escape-aware scanner (`extractJson`) that never
90
+ slices between the first brace and the last (scar §2.14), with `intake()` as the
91
+ validator. Pinning the shape is a follow-up for the first session with a real
92
+ credential; `InterpretClientOptions` is where the knob would go.
93
+
94
+ ## 9. The model seat: one knob, pinned, and a placeholder that expires
95
+
96
+ `DEFAULT_INTERPRET_MODEL` is a pinned identifier held in configuration, and there
97
+ is exactly one seat because there is exactly one model call in the package. The
98
+ `placeholder` / `expires` machinery exists anyway, unused by the default, because
99
+ scar §2.15's third clause is about the shape of the config rather than about
100
+ today's value: an undecided default must be able to expire, or "never decided"
101
+ becomes "decided" by silence. `seatStatus` refuses a placeholder with no expiry
102
+ outright, which is the case v1 actually shipped.
103
+
104
+ ## 10. `readTranscript` tags the blind spot rather than dropping it
105
+
106
+ Tool results, images and documents come back as zero-length turns tagged `tool` /
107
+ `image` / `file`, and `remember/`'s `enters()` is what drops them. One rule, one
108
+ place. The alternative — filtering here — would put a second copy of the
109
+ conversational-text-only rule in a file that changes with the host.
110
+
111
+ ## 11. One config rule, and what the hook does instead of printing (2026-09-05)
112
+
113
+ `bin/hook.ts` and `bin/runner.ts` each hard-coded
114
+ `join(homedir(), ".counterparts", "claude-code.json")` and took no flag, as did
115
+ `mcp/bin/serve.ts`. That was filed as LAUNCH-STATUS G1, and its cost was not
116
+ theoretical: the clean-room install loop could redirect every entry point but the
117
+ hook, so "the hook honours the configuration it was given" was a step nobody
118
+ could write, and a reviewer on a machine with an existing install could not run
119
+ the hook at all without moving a whole `HOME`.
120
+
121
+ The rule is now one sentence, in `adapters/config-path.ts` and nowhere else:
122
+ `--config <absolute path>`, else `COUNTERPARTS_CONFIG`, else the default. The
123
+ default did not move — the live host passes neither, and a test asserts that the
124
+ no-flag no-env case resolves exactly the old constant, at the module level and in
125
+ a real hook process.
126
+
127
+ Three decisions worth keeping:
128
+
129
+ **A named configuration that cannot be honoured refuses; it never falls back.**
130
+ A `--config` that is relative, or absolute and not there, or not a JSON object,
131
+ is a stand-down: one line on stderr, exit 0, nothing injected. Falling back to
132
+ the default would mean a scratch run writing into the live store, which is the
133
+ accident the whole rule is a reaction to. The refusal direction costs nothing on
134
+ the live host, which never names a configuration.
135
+
136
+ The MISSING-FILE arm was not in the first version, and the review of PR #72
137
+ (2026-09-05) reproduced what that cost: `--config /definitely/not/here.json`
138
+ exited 0, printed a wake and minted a store. The read error is swallowed into
139
+ `loadConfig(undefined)` — the observer default, which is the right fail direction
140
+ for a config nobody named — and the data dir then falls through to `dataDir()`.
141
+ So a typo in the one flag that says WHICH MEMORY landed on the live store, which
142
+ is the same shape as the `--dirr` finding the console already refuses. The check
143
+ is `namedConfigRefusal`, a separate function rather than a line inside
144
+ `configRefusal`, because `install --config <path>` resolves through the same rule
145
+ and its file does not exist yet: writing it is the command. An absent DEFAULT
146
+ stays ordinary — a fresh machine has none and the hook must still stand up.
147
+
148
+ Two arms followed from that one. **The pin and the refusal collided**: `spawn.ts`
149
+ pins the parent's resolved path onto EVERY worker, the default included, so on a
150
+ machine with no config the worker would have seen a "named" file that is not
151
+ there and stood down — nothing would ever sweep or sleep there. `isNamed` is the
152
+ fix, and it is the same test `install` uses to decide whether to print a flag:
153
+ the PATH, not how it arrived. **And `unreadable` is not `absent`**: `loadConfig`
154
+ reports it for a file that parses but whose fields do not typecheck, and resolves
155
+ it to `{ observer: true }`, whose store then falls through to `dataDir()`. For a
156
+ file somebody NAMED that is a stand-down nobody asked for at a store nobody
157
+ named, so the three entry points carry the loader's verdict out
158
+ (`namedUnreadableRefusal`). An unreadable DEFAULT is unchanged: observer, as
159
+ observer-mode G5 requires.
160
+
161
+ **The hook RECORDS rather than prints, and the record is the session file.** A
162
+ hook's stdout is the model's context and its stderr is a host log nobody reads,
163
+ so `<dataDir>/sessions/<id>.json` gains a `config` field — host state, no
164
+ content, beside the id and the scope it already carried. A new *durable event*
165
+ name would have been the other option and was rejected: `AdapterDurableEventName`
166
+ lives in `core/counterpart.ts`, and this is not worth a core change. The ring
167
+ event (`adapter.config.file`) is there too, mirroring `adapter.credentials.file`,
168
+ for anything reading the ring in-process.
169
+
170
+ **The worker is PINNED, not re-resolved.** `spawn.ts` writes
171
+ `COUNTERPARTS_CONFIG` onto the child last, beside `COUNTERPARTS_DATA_DIR` and for
172
+ the same reason (scar §2.13): a hook driven by `--config` that spawned a worker
173
+ which then resolved the default file would sweep and sleep against a store nobody
174
+ named.
175
+
176
+ ---
177
+
178
+ ## 12. Per-directory scope, and the four things that decided its shape (2026-09-10)
179
+
180
+ *Owner asks G41–G43, closing host gaps 6, 7 and 8 in `INTERFACE-GAPS.md`.*
181
+
182
+ **The registry sits beside the CONFIGURATION, not inside the store.** A store is
183
+ memory; this is host state about which directories memory is *for*, and — the
184
+ load-bearing half — the hook has to decide `off` **before** anything opens. A
185
+ registry inside the store could not answer that question without opening the
186
+ thing it was about to refuse to touch. Beside `claude-code.json` also means
187
+ `--config` and `COUNTERPARTS_CONFIG` move the two together for free, so a scratch
188
+ install's scopes are that install's own, which is the property the whole
189
+ config-path rule exists for.
190
+
191
+ **`unset` means ON, and that is the choice to argue with.** Every directory the
192
+ parallel run touches is unset, so a registry that defaulted to `observer` would
193
+ have muted the live run on the day it shipped — a feature about consent that
194
+ takes memory away without being asked is the same mistake in the other
195
+ direction. The honest cost is that the first session in a genuinely new
196
+ directory still records that session before anyone is asked; the ask goes out in
197
+ that same session's wake, and the answer governs from the next one. The
198
+ alternative — observer-until-answered — is one line (`stanceOfMode`'s default
199
+ arm) and is named in the PR for the owner to take.
200
+
201
+ **`off` is silent, and it is the one place this package chooses silence.**
202
+ Everything else here is built on "a stand-down that says nothing is
203
+ indistinguishable from a broken tool" (scar §2.4, observer-mode G6). Two facts
204
+ overrode it: there is no ring to write to without opening a store, which is the
205
+ thing `off` promises not to do; and `UserPromptSubmit` fires every turn, so one
206
+ stderr line per event is a permanent noise floor in the host's log — in the one
207
+ directory whose owner said *leave this alone*. The distinguishing record is the
208
+ registry, which is a file a person wrote on purpose and which `counterparts
209
+ scope <path>` reads back. The MCP server, which has an operator-facing stderr at
210
+ LAUNCH and not per call, still prints its one line there.
211
+
212
+ **The first-launch ask rides `HookResult.ask`, not the injection.** The obvious
213
+ implementation — append the question to the wake text — was written first and
214
+ broke three things at once: `bytes` no longer described the injection, the
215
+ sentinel's stated byte count became a lie, and the sentinel stopped being the
216
+ last line, which is exactly the truncation detector scar §2.3 paid for. `ask` is
217
+ the field the host delivery already appends after the injection, so the question
218
+ lands where it was asked to land and the bundle's own accounting is untouched.
219
+ It is delivered only if it FITS the reported ceiling; when it does not, the
220
+ session record is left unmarked and the next session asks. On this host today
221
+ the wake is 8,859 bytes of a 9,000-byte ceiling and the block is 402, so the
222
+ question DEFERS on every unset directory the owner has until the bundle has room.
223
+ That is the honest answer to a ceiling and the event says so, but it means the
224
+ headline behaviour is dormant here: the two other levers are a bounded overbudget
225
+ (the ceiling is already an event rather than a truncation, `adapter.injection.
226
+ overbudget`) and a shorter block, and even a terse one is ~170 bytes against 141
227
+ of headroom. Named in the PR for the owner rather than left in a comment.
228
+
229
+ **`counterparts scope --observer` is a MODE, not this console's stance.** The
230
+ owner asked for those four words by name, and `--observer` was already a common
231
+ flag meaning "stand this console down" — the two cannot share one flag on one
232
+ command line. On `scope` alone the flag names the mode, the stance comes from
233
+ `COUNTERPARTS_OBSERVER`, and the write half refuses under it in the same sentence
234
+ an owner op refuses in. The help page prints a different sentence for that flag
235
+ (`SCOPE_FLAG_HELP`) rather than the shared one, because a page that printed the
236
+ shared sentence there would be printing something false. `scope` is deliberately
237
+ NOT on `OWNER_OPS`: that list refuses a command whole, and an instrument must
238
+ still be able to read the registry — "why did this session record nothing" has
239
+ to be answerable from a stood-down console.
240
+
241
+ **Paths are canonicalised deeper than `sessions.ts` needs.** `canonicalScope`
242
+ realpaths a path that exists and resolves one that does not, which is right for
243
+ comparing two live session directories. A PREFIX rule needs more: a key written
244
+ from `/tmp/x` becomes `/private/tmp/x` on this host, while a query for a
245
+ subdirectory that does not exist yet stays under `/tmp` — an ancestor that
246
+ governs the parent and not the child. `canonicalScopePath` realpaths the deepest
247
+ existing ancestor and appends the rest, and `setScope` replaces every key that
248
+ canonicalises to the same directory, so a hand-edited spelling cannot leave two
249
+ entries for one directory with `lookupScope` honouring whichever sorted first.
250
+
251
+ ---
252
+
253
+ ## The week the worker never started (I32, 2026-09-11)
254
+
255
+ A forced `install --force` on 2026-09-04 replaced `credentials.env` with the
256
+ template — a file with zero non-comment lines. `planSpawn` refused
257
+ `NO_CREDENTIAL` at every boundary for the seven days that followed, and nothing
258
+ that happened next was visible from any surface a person looks at.
259
+
260
+ **What the refusal actually cost.** The worker carries five jobs. Exactly one of
261
+ them — the crash-fallback sweep — needs a model call. The other four are the
262
+ lagged semantic cue, the embedding backfill, the Hebbian flush, and the sleep
263
+ cycle (decay, prune, dedup, consolidate, briefing). The sleep cycle is also the
264
+ only thing that advances the lived-day clock. So a missing key stopped the clock
265
+ at 185; `self.episode.day.185 = 4` was the day's ask cap, spent on 09-04 and
266
+ never reset, so all 39 Stops between the restore and the finding read
267
+ `capped: day-chapter-cap` and the model was never asked for a chapter again;
268
+ live memories without a vector rose from 219 to 229; and every turn's recall
269
+ read `semantic: none`.
270
+
271
+ Meanwhile the wake delivered, recall rendered, spans captured, `verify` was
272
+ clean and the daily graded the day ACTIVE. **The foreground was healthy and the
273
+ background had been dead for a week.**
274
+
275
+ **Three repairs, and the third is the general one.**
276
+
277
+ 1. *Degrade, do not refuse.* The credential is no longer a spawn precondition.
278
+ `runner.ts` asks its own question at the one step that needs an answer and
279
+ passes `sweep: { skipped: "no-credential" }`, which still writes the gate row.
280
+ A guard that protects one job by stopping five is a single point of failure
281
+ with a name on it.
282
+ 2. *Durable refusals.* `spawn.refused` / `spawn.escalated` were ring-only, and a
283
+ hook process's ring lives for one turn. Scar §2.4 says the door that failed
284
+ must not look like the door nobody opened; at this seam it did. The refusal
285
+ now writes `adapter.spawn.refused`, latched one row per reason per calendar
286
+ date.
287
+ 3. *Persisted escalation.* `spawnFailures` was a `Map` on an adapter instance.
288
+ Every hook is a fresh process, so "consecutive refusals" was always 1 and
289
+ scar E4's widening — a repeated refusal reaches a human — was inert from the
290
+ day it shipped. The counter is in box 2's meta now
291
+ (`adapter.spawn.refusals.<reason>`), cleared when a spawn starts.
292
+
293
+ **What is deliberately NOT here.** The refusal row's `count` is the counter at
294
+ the moment the row was written, which for the first refusal of a date is 1. The
295
+ row is evidence that it happened; `spawnRefusals()` and the meta counter are the
296
+ evidence of how deep it got. A row per boundary would be three hundred rows a day
297
+ saying the same thing, which is a different way of being unreadable.
298
+
299
+ ## Head-of-line, and why isolation units matter (I33, 2026-09-11)
300
+
301
+ Two migrated memories carried a lone UTF-16 surrogate in their title. Voyage
302
+ answers HTTP 400 for the whole chunk; `BACKFILL_LIMIT` (64) is smaller than the
303
+ client's batch size, so the chunk WAS the batch; `missingVectors` returns a
304
+ stable order, so the same head-64 was re-asked at every boundary for a week while
305
+ 165 blind memories queued behind it. Thirty-two consecutive `adapter.embed.backfill`
306
+ rows read `0 embedded / 64 failed / reason: ran` — a row with no code on it, so
307
+ it read as a flaky provider rather than as two bad bytes.
308
+
309
+ Three changes, each needed on its own:
310
+
311
+ - **Sanitize the request body.** `toWellFormed()`, in `callOnce`, and nowhere
312
+ else. The cache key and everything `store.embedOne` compares stay on the
313
+ ORIGINAL string: sanitizing before the cache write would file the vector under
314
+ a key the store never asks for, and the backfill would become a paid-for no-op
315
+ that reports success — the failure the file's own header warns about.
316
+ - **Bisect a 400.** Only a 400: the provider read the body and refused it, so the
317
+ poison is in there. A 429 or a 500 says nothing about which input is bad, and
318
+ splitting a 429 multiplies the rate that caused it.
319
+ - **Give up after three, but only on the item's own failures.** Sanitizing fixes
320
+ THIS poison; the skip list is what keeps the NEXT one from holding the queue.
321
+ `embed.failed.<id>` in meta, excluded from `missingVectors`, named by
322
+ `skippedVectorIds()` and printed by `verify` — a give-up nobody can read is
323
+ indistinguishable from a coverage number that has stopped meaning anything.
324
+ The counter climbs ONLY when the fill blamed one input (a 400 the bisector
325
+ narrowed to a single item). The first cut counted every failure, and that made
326
+ the watchdog's own abort — which fails the whole window, every time — retire
327
+ sixty-four healthy rows after three bad boundaries while `unembeddedCount`
328
+ read COMPLETE: I33 inverted, and the coverage watch failing upward, which is
329
+ the one direction it may never fail in.
330
+ - **A skip needs a way out that a skip cannot close.** The counter is cleared by
331
+ a run that lands, and a skipped id is never offered to a run — so
332
+ `verify --retry-skipped` is the door: it clears every counter, names the ids,
333
+ and writes nothing else. `rebuildCache` is not that door; it has no embedder
334
+ and never touches meta.
335
+
336
+ ## The warning reaches the terminal, and one command repairs it (I32's close, 2026-09-14)
337
+
338
+ The owner's ruling on 2026-09-11 was one sentence: **the warning must reach the
339
+ USER's terminal.** #95 made the spawn refusals durable and persisted the
340
+ escalation counter; the evidence existed, and nothing said it out loud. This is
341
+ the half that does.
342
+
343
+ **The channel, measured and then documented.** The owner ran a probe on
344
+ 2026-09-11: a SessionStart hook that exits 0 and prints JSON with a top-level
345
+ `systemMessage` gets that text DISPLAYED in the terminal (`SessionStart:startup
346
+ says: …`), non-blocking, while `additionalContext` and stderr do not show. The
347
+ current hooks reference — https://code.claude.com/docs/en/hooks (the old
348
+ docs.claude.com path 301s there) — says the same thing and adds the rule that
349
+ decides the shape: **when a hook's stdout parses as JSON, the raw stdout is NOT
350
+ also added to context; only the JSON's fields are.** The exact names, verbatim
351
+ from that page: `systemMessage` ("A message shown to Claude in the UI. For most
352
+ events, this is added as a system message in the conversation."), and for
353
+ SessionStart `hookSpecificOutput: { hookEventName: "SessionStart",
354
+ additionalContext: "string to add to Claude's context" }`, with plain-text stdout
355
+ added as context for `UserPromptSubmit`, `UserPromptExpansion`, `SessionStart`
356
+ and `PostModelSwitch` and only those.
357
+
358
+ So: the wake rides ENTIRELY in `additionalContext`, byte for byte what plain
359
+ stdout would have carried, and **a day with nothing red prints the plain form it
360
+ has printed since day 0**. The JSON wrapper is a transport that has been measured
361
+ once, on one host, by one probe; a healthy session does not get to be the place
362
+ it is tried again. `hostDelivery` stays pure, takes the notice as an argument,
363
+ and a test holds the two forms to each other.
364
+
365
+ **Red only, and only at SessionStart.** Amber is `doctor`'s to print; a notice
366
+ that fired on one un-embedded memory is a notice people learn to scroll past, and
367
+ the owner asked for a warning, not a nag. Nothing at all on
368
+ `user-prompt-submit` — that hook fires every turn.
369
+
370
+ **The reading is bounded and cannot fail the wake.** `doctor.ts` is one library,
371
+ called by the console and by `ClaudeCodeAdapter#notice`, so the two cannot
372
+ disagree about what red means. At session start it runs under a 150 ms budget
373
+ (the credit seam's number, for the same reason), checked BETWEEN finding groups —
374
+ config, credentials and the checkout first, because those carry I32's own
375
+ signature — and what the budget cut off is a finding rather than an omission.
376
+ Every failure returns null and leaves one `adapter.doctor.failed` ring row; an
377
+ observer returns null before any read.
378
+
379
+ **The one thing the console does differently from the hook, and it is the whole
380
+ point.** The console loads the credentials file against a SCRATCH environment, so
381
+ what it reports is what the FILE holds. Counting its own shell would have read
382
+ green all week on the owner's machine — his `~/.zshrc` exports both names, and
383
+ hook processes inherit neither (measured day 0). What the shell has and the file
384
+ lacks is reported as its own clause instead. The hook hands in its own load,
385
+ whose `skippedPresent` names what ITS environment answered, because there the
386
+ environment is the environment the worker will be spawned with.
387
+
388
+ **`credentials set` writes the value nowhere it can be read back.** Not argv
389
+ (argv is shell history, and a key in shell history is a key on disk in plaintext
390
+ forever), not stdout, not an error. stdin, or one named environment variable, and
391
+ the console says `set <NAME> in <path>`. The mode is set twice — `writeFileSync`'s
392
+ `mode` applies only on create, so `chmodSync` is what actually holds the 0600
393
+ promise on a file that was already there.
394
+
395
+ ## Which checkout is live (2026-09-14)
396
+
397
+ The hooks are invoked BY ABSOLUTE PATH out of `~/.claude/settings.json`, so the
398
+ install tree's working state is the memory layer the owner is using. Twice in one
399
+ day that mattered: a peer session developed a branch in that tree and it was live
400
+ for seven minutes, and after a merge the tree sat DETACHED at an older sha for
401
+ thirty minutes while "it's merged" was true of the remote and false of the
402
+ machine.
403
+
404
+ So `doctor` grades the checkout, and the grade is against the local
405
+ `refs/remotes/origin/master` as last fetched — never the local `master` branch,
406
+ and never by fetching (a network call on a foreground hook is the one thing the
407
+ wake's contract forbids). HEAD IS origin/master, branch or detached, is GREEN:
408
+ detached at origin/master is the deploy state, not a fault. An ancestor of it is
409
+ AMBER (`behind`, with the count) — old code, but merged code. Anything else is
410
+ RED, and tracked modifications are RED wherever HEAD sits. `--untracked-files=no`
411
+ on purpose: the shared tree carries untracked files by design, and they change
412
+ nothing about what runs.
413
+
414
+ The root comes from the RUNNING CODE's own path (`import.meta.url` up to the
415
+ package root) and from no configuration value — that is what makes the hook grade
416
+ the install tree and a console run from a worktree grade the worktree, each
417
+ correctly. Every git call is `spawnSync` and never throws; a git that will not
418
+ answer, and a repository with no `origin/master`, are neutral and leave no row.
419
+
420
+ **The reading has its OWN budget, and that is the correction the review forced.**
421
+ `readCheckout` runs before `doctorFindings`, whose deadline starts when it is
422
+ entered — so seven `spawnSync` calls at `CHECKOUT_TIMEOUT_MS` (2 s) each sat
423
+ outside every budget this adapter had. Measured against a git shim that sleeps
424
+ 1.2 s: **7.81 s of foreground session start.** `CHECKOUT_BUDGET_MS` (1,000 ms) now
425
+ bounds the whole reading, each call gets what is left of it, and past it the
426
+ reading is `unreadable` with `timedOut` — a `timeout` ring row, and no durable
427
+ row, because "we ran out of time" is not a state of the checkout. It is its own
428
+ budget rather than a slice of the notice's 150 ms because five process spawns on
429
+ a cold machine can exceed 150 ms on their own, and a grade that timed out every
430
+ morning would be missing on exactly the mornings the tree HAS wandered.
431
+
432
+ One durable `adapter.checkout` row per session start — reason, branch, short sha,
433
+ tracked-modification count, `behindBy`, `originMaster`, date — latched per
434
+ date+head+dirty+**reason**, so a day on master leaves one row and a day that
435
+ wandered leaves one per state it wandered into. The reason belongs in the latch
436
+ because the other three do not move when the grade does: a `git fetch` in the
437
+ shared tree moves origin/master under the same clean head, so the morning's
438
+ `master` becomes the afternoon's `behind` — and without it the day's record still
439
+ said master. The daily's split is `adapter.checkout:off-master` (every reason but
440
+ `master`), so "what code produced this day's numbers" is answerable from the
441
+ record instead of from memory.
442
+
443
+ ## The notice is capped, and the wake outranks it (2026-09-14)
444
+
445
+ The host caps every hook output string at 10,000 characters and replaces anything
446
+ longer with a preview and a file path (code.claude.com/docs/en/hooks: "Hook output
447
+ strings, including `additionalContext`, `systemMessage`, and plain stdout, are
448
+ capped at 10,000 characters"). For PLAIN stdout that is survivable. For the JSON
449
+ envelope it is fatal: replace the printed object with a preview and the stdout no
450
+ longer parses, `additionalContext` is never read, and the whole wake is gone.
451
+
452
+ The envelope is bigger than what it carries — JSON escaping costs a character per
453
+ newline — and the measured case is close: a 9,038-byte wake plus a 352-character
454
+ notice is **9,618 characters** of stdout. So two limits, both named:
455
+
456
+ - `NOTICE_MAX_CHARS` (400) caps the notice itself, truncating with `…` and always
457
+ keeping the trailing `run: counterparts doctor` — what is cut is the
458
+ explanation, never the way to read all of it.
459
+ - `ENVELOPE_MAX_CHARS` (9,500, in `bin/hook.ts`) decides the FORM. Over it, the
460
+ hook prints the plain wake and drops the notice, leaving an
461
+ `adapter.notice.dropped` ring row with both lengths.
462
+
463
+ **The trade, stated plainly:** on a red day with a full wake the terminal may see
464
+ nothing, and the warning lives only in `counterparts doctor` — which the notice's
465
+ own last line is telling the owner to run anyway. The alternative is a session
466
+ that starts with no memory at all, and memory is the thing the session cannot be
467
+ had without.
468
+
469
+ ## "Newest row" can be unknown, and says so (2026-09-14)
470
+
471
+ `Store.eventLog` is `ORDER BY seq ASC LIMIT` (the missing DESC read is filed in
472
+ `cli/INTERFACE-GAPS` §10), so `doctor` finds the newest row of a name by widening
473
+ a day-window ladder and trusting only a window that came back SHORTER than the
474
+ limit. The unbounded window at the end of the ladder was exempt from that rule —
475
+ so a name holding more than `NEWEST_LIMIT` (4,000) rows, all older than the widest
476
+ window, was read off the 4,000th-OLDEST row and graded on it. A store that swept
477
+ 4,000 sleep cycles could be reported RED about a night long past. A full unbounded
478
+ window is now UNKNOWN: a neutral finding that names what was not read and claims
479
+ nothing about the store, because a confident wrong answer is the one thing a
480
+ diagnostic may not produce.
481
+
482
+ ## The scope followed the shell, and everything but the deposits went with it (2026-09-17)
483
+
484
+ `hookScope` preferred the hook payload's `cwd` on a measurement from 2026-09-04 that
485
+ read it as "the project directory". It is not: the host documents it as "current
486
+ working directory (follows Claude into worktrees)", and every piece of work in this
487
+ repository happens in a worktree. So a session's spans, boundaries and coverage reads
488
+ moved with the shell while the MCP server's scope stayed fixed at launch — and a
489
+ deposit only covers spans in its own scope. One session on 2026-09-17 filed spans in
490
+ four directories and deposits in one; two worktree scopes on the owner's store hold 298
491
+ fallback memories and zero authored ones, because everything the session wrote
492
+ elsewhere stayed uncovered until the crash fallback rewrote it twelve hours later.
493
+
494
+ Three things the repair turned on, none of them obvious from the outside:
495
+
496
+ **The session registry was already the right answer, and nobody was reading it.**
497
+ `recordSession` has refused to rewrite a scope after a start since the day it shipped
498
+ ("`start` owns the scope, so a hook firing from a git worktree cannot rewrite the scope
499
+ the server matched against"). The record held the correct directory the whole time; the
500
+ hooks simply never read it back. `sessionScope` does, and the one string it returns is
501
+ the same one `requireBoundSession` matches a deposit against.
502
+
503
+ **A compaction fires SessionStart.** `source` is `startup`, `resume`, `clear`, `fork`
504
+ or `compact`, and only the first four open a session. Treating all five as a start would
505
+ have re-anchored a long session's scope at every compaction — the same bug through a
506
+ different door — so an unrecognised or absent `source` deliberately does NOT re-anchor a
507
+ session that already has a record.
508
+
509
+ **`CLAUDE_PROJECT_DIR` reaches the MCP server too**, which is what makes the two
510
+ adapters agree by construction rather than by both happening to have the same working
511
+ directory. What the server's spawn cwd actually is, the host documents nowhere; it was
512
+ measured once with `lsof`. The variable is documented, stable across `cd`, `/add-dir`
513
+ and worktrees, and exported to hooks and stdio servers alike.
514
+
515
+ And the scope had to become CANONICAL on both sides: span streams, cursors and coverage
516
+ files are named from a hash of the exact string, so `/tmp/x` and `/private/tmp/x` are
517
+ two memories of one directory. `sameScope` had been canonicalising for the BIND since
518
+ the beginning; the filing had not.
519
+
520
+ ## One week of who did the writing, in the doctor (2026-09-17)
521
+
522
+ Finding 12 measured the crash fallback out-writing the session itself 4.5 : 1 over the
523
+ run, and every visible surface read healthy while it happened. The two facts that would
524
+ have shown it were already in the store and were simply never read out: how often the
525
+ session was OFFERED the pen (`adapter.ask` by `outcome`), and how much of the week's
526
+ memory it wrote (`memories.source`). The `Authorship` section reads seven CALENDAR days
527
+ of both — calendar, because the lived-day clock is advanced by the worker and has run
528
+ seven lived days across fifteen calendar ones on this very store, so a lived-day window
529
+ would have hidden exactly the weeks the worker was stuck.
530
+
531
+ It counts `outcome` and not `reason` on purpose: `outcome` is a three-word closed
532
+ vocabulary and `reason` is a finer one that is being renamed elsewhere. A diagnostic
533
+ keyed on a string in motion is a diagnostic that reads zero one morning and nobody
534
+ notices.
535
+
536
+ Amber on two comparisons — the day's cap refusing more asks than it raises, the fallback
537
+ out-writing the author — and never red: this is a balance, not a fault.
538
+
539
+ ## What an adversarial read of the scope registry found (2026-09-15, PR #92 review)
540
+
541
+ Five findings, and four of them are one mistake wearing different clothes: the
542
+ fail direction of every unknown in this feature is `unset`, and `unset` is **on**.
543
+ Anything the registry cannot answer therefore resolves toward recording, which is
544
+ the direction that cannot be taken back.
545
+
546
+ **The retroactive capture (F1).** A session under `off` writes nothing at all —
547
+ that is G19, and it is the point. But "nothing" includes the span cursor, so when
548
+ the directory came back on mid-session the next boundary sliced the transcript
549
+ from 0 and deposited the entire off conversation. Measured: six marker hits. The
550
+ seal (`hooks.ts#sealJoinedLate`) moves the cursor without depositing, and the
551
+ only adapter-reachable way to do that today is `captureSpans` with placeholder
552
+ turns whose source `enters()` refuses — the ALL_EXCLUDED arm advances the cursor
553
+ and appends nothing. **The core ask this leaves open:** a `SpanBuffer.sealCursor
554
+ (scope, session, turns)` would say what this means instead of arranging for it.
555
+ The order — cursor first, session record only if it moved — is what stops a
556
+ half-done seal from making the NEXT boundary treat the session as ordinary.
557
+
558
+ **Two silences that are not the same silence (F2).** `off` is silent because the
559
+ owner said leave this alone. A registry that could not be READ has said nothing,
560
+ and its `unset` fail direction turns every `off` in it back on. Whole-file-fail
561
+ made that worse rather than better: one typo'd mode turned every correctly typed
562
+ `off` beside it on, to protect the bad one — which the hook could not honour
563
+ anyway. Per-entry now, refused by name, with one stderr line — the same sentence
564
+ in the hook and in the server at launch, where the inline version covered only a
565
+ whole-file failure — at SessionStart
566
+ (after the `off` return, so an off directory stays byte-silent) and
567
+ `scopeRegistry` on the wake's durable row. Both writers refuse to drop an entry
568
+ they could not read, because every write rewrites the whole file.
569
+
570
+ **Two writers, no compare-and-swap (F3), and a tie-break that could resolve
571
+ toward `on` (F4).** The console and the MCP tool both read-modify-rename; the
572
+ second rename deleted the first's entry. `writeScopes` now re-reads the bytes
573
+ immediately before the rename and re-applies the caller's change once against
574
+ what is actually there. A call WITHOUT that argument is still a plain overwrite —
575
+ it is what `--force` needs — so a new caller that read the file first owes it.
576
+ The duplicate-key tie (one directory, two spellings, only possible by hand) now
577
+ goes to the more restrictive mode.
578
+
579
+ **And one that is only about trust (F5):** `--note ""` cleared on the console and
580
+ carried on the tool. Two doors to one setting have to mean the same thing by the
581
+ same words, or the setting is not one thing.
582
+
583
+ ## The credit seam translates a handle before it judges it (2026-09-15, G50)
584
+
585
+ `creditAtBoundary` takes its expansions from the transcript, raw: whatever the
586
+ model put in the recall call's `ids` / `handle`. `recall/reference.ts` credits
587
+ literal `mem_…` addresses out of that list and resolves nothing — deliberately —
588
+ so a session that expanded a memory by its exact TITLE, read the whole body, and
589
+ answered from it left a row saying `expanded: 0, unresolvedHandles: 1`.
590
+
591
+ The resolution belongs to whoever performed it, which is the MCP tool, so the
592
+ tool records it (`adapters/expansions.ts`) and this hook translates the
593
+ transcript's own handle with it on the way in. **What the transcript decides is
594
+ untouched**: which handles the session used, and in which slice. The row gained
595
+ `resolvedHandles` beside `unresolvedHandles`: the pair is what proves the seam
596
+ live in a daily — and `expansionsRead` beside them, because a zero that cannot
597
+ say whether the table was idle, absent, unreadable or corrupt is exactly the
598
+ shape I32 hid in. Its values are `ok`, `absent`, `unreadable`, `corrupt`, and
599
+ `not-read` for a slice that carried nothing to translate (the file is not opened
600
+ then).
601
+
602
+ **"The fix cannot widen credit" was the claim, and it was wrong** — it is written
603
+ down here because the correction is the whole lesson. The transcript says which
604
+ handle and when; what it cannot say is whose ANSWER resolved that handle, and the
605
+ log is one table shared by every session on the machine. Three askings get no
606
+ answer at all and therefore leave no shadow behind them (a call that never
607
+ reached `expandHandle`; a `{ handle, question }` refused as `both-arguments`
608
+ before the handle path exists; a refusal whose write failed), and each of the
609
+ three still leaves the title in the transcript for a boundary to translate —
610
+ through the only line in the log, which may be the owner's resolution of a
611
+ confidential memory.
612
+
613
+ **The refusals are still recorded, and the SCOPE is what makes them a boundary.**
614
+ Every handle-path outcome leaves a line, a refusal leaving `null` — a shadow that
615
+ translates nothing and, being the newest answer, overrides the earlier resolution
616
+ of the same handle. On top of that, every line carries the project the resolving
617
+ server was serving, and this hook asks for only the lines matching `input.scope`.
618
+ A resolution from another project cannot answer this project's handle, which
619
+ covers all three shadowless routes at once; it also retires the opposite race the
620
+ first draft accepted, because a stranger's shadow now carries the stranger's
621
+ scope and never reaches the owner's boundary.
622
+
623
+ The comparison is `sessions.ts#canonicalScope`, the same one the MCP server
624
+ trusts to bind a session, and a disagreement between the two sides costs a
625
+ translation — under-credit, the direction this seam may err in. A line with no
626
+ scope is dropped for the same reason.
627
+
628
+ **And a floor, because a project is a place and not a conversation.** One
629
+ directory's table holds Monday's session and Tuesday's, so the scope alone still
630
+ lets last week's resolution answer a title this session merely typed. This hook
631
+ reads the asking session's own `startedAt` out of the registry it writes itself
632
+ and translates only records stamped at or after it. A session whose first hook
633
+ event is this Stop has no record yet — `claim()` runs before
634
+ `noteSession("boundary")` — and so gets no floor; two sessions running at once in
635
+ one directory still share the table inside the overlap. Both are recorded in
636
+ `mcp/INTERFACE-GAPS` §9 rather than papered over.
637
+
638
+ Two limits, recorded rather than hidden. The log is read only when the slice
639
+ carries an expansion at all, so an ordinary Stop still opens no extra file. And
640
+ compaction racing an append can still lose a line, though the window is now two
641
+ syscalls wide rather than a whole file write: `compactExpansions` keeps the byte
642
+ length it read and splices whatever arrived back onto the temp file immediately
643
+ before the rename. That matters more than it first looked — a lost line is only
644
+ "under-credit" when it is a RESOLUTION. A lost SHADOW puts the resolution it was
645
+ overriding back, which is the leak, not a cost. Closing the window entirely
646
+ would take a lock two long-lived processes share, in the hot path of a tool that
647
+ may not fail, which is why it is narrowed rather than closed.
648
+
649
+ ## The wake's arrival was checked against nothing (2026-09-17, S2)
650
+
651
+ `adapter.wake.delivered` has 0 rows on the live store since 2026-09-03. Two
652
+ faults, and the second is the interesting one.
653
+
654
+ **The field nobody set.** The check sat behind `input.sentinelSeen !== undefined`
655
+ and `sentinelSeen` was declared on `HookInput` and populated by no caller;
656
+ `toHookInput` — the only live constructor of a hook input — never mentioned it,
657
+ and neither did anything else in the repository. It was an interface waiting for
658
+ a host that was never asked for it.
659
+
660
+ **The map that could not survive its own process.** The expectation it would have
661
+ compared against lived in `this.expected`, a `Map` on the adapter instance. Every
662
+ hook is a fresh process. Even a populated field would have met `expected = null`
663
+ at every turn of every session — the same shape as I32's refusal counter, which
664
+ also counted "consecutive" inside a process that lives for one turn. This
665
+ repository has now shipped that mistake twice, which is worth writing down: **a
666
+ value read in a later hook than the one that wrote it has to be on disk.** The
667
+ adapter has exactly one place for that, the session registry record, and it now
668
+ carries the wake's sentinel beside the configuration path and the scope-ask mark.
669
+
670
+ **What it reads.** The host records a SessionStart hook's output in the
671
+ transcript as its own entry: `type: "attachment"`, with `attachment.type:
672
+ "hook_success"`, the hook's command line, what it printed (`stdout`) and what the
673
+ host says it injected (`content`). Measured 2026-09-17 on Claude Code 2.1.274,
674
+ that entry is line 3 of a fresh session's file, before the first user message,
675
+ and both sentinels stand inside it. `parseTranscript` skips attachments on
676
+ purpose — injected context is not conversation — so the check has its own small
677
+ reader (`transcript.ts#readWakeArrival`) that skips everything else.
678
+
679
+ **Bounded, because the file is not.** 256 KiB and 40 lines from the front, one
680
+ `read` at offset 0. The answer is always in the first handful of entries and a
681
+ long session's file reaches megabytes. Measured on a 5.4 MB transcript: 0.06 ms
682
+ median, 0.62 ms worst of 300 runs, against a wake of 8,908 bytes found four lines
683
+ in. It runs ONCE per session — the flag that says so is in the same record — so
684
+ the ongoing per-turn cost is the registry read alone, ~0.008 ms. And it opens
685
+ REGULAR FILES ONLY (stat, `O_NONBLOCK`, fstat): the path comes from the host's
686
+ payload, and opening a FIFO blocks until somebody opens the other end, which
687
+ would hang the prompt until the host's own hook timeout.
688
+
689
+ **The verdict comes from the tail sentinel alone**, which is what the sentinel is
690
+ for: "verify arrival from the last line". The head sentinel, the printed copies
691
+ and the measured lengths ride on the row as evidence. Six answers: `delivered`,
692
+ `truncated` (the tail is not in what the host injected), `mismatch` (a wake
693
+ arrived and it is not this session's — what a resumed session whose record was
694
+ pruned produces, because the head of its file holds the original run's
695
+ attachment), `printed-unverified`, `not-found`, and `no-wake-expected` (a cold
696
+ start's bootstrap line states no sentinel, so nothing checkable was handed over;
697
+ the file is not even opened).
698
+
699
+ `printed-unverified` is the sixth, added by the review of this work
700
+ (2026-09-17). `content` is a field of the host's private format, measured once;
701
+ the first draft read its absence as an empty injection and therefore answered
702
+ `truncated` — the one word in the vocabulary that means v1's eleven-day
703
+ silent-loss bug is back — for every session on any build that stops recording
704
+ it. When the field is absent the printed copy answers instead, and the row
705
+ carries `contentRecorded: false` so the two cases stay apart.
706
+
707
+ **The search is linear and the matched text never leaves the reader.** The
708
+ sentinel patterns used to run against the whole attachment with a leading
709
+ `[^>]*`, which backtracks: 680 ms at 200 KB on a body holding thousands of
710
+ unterminated sentinel prefixes, four times per attachment, on the prompt path.
711
+ The prefix is now located with `indexOf` and the anchored pattern runs on one
712
+ bounded slice. And the sighting carries numbers and flags only — the expectation
713
+ is compared inside the reader, because a sentinel is found INSIDE a bundle of
714
+ memories and the characters around it are the owner's.
715
+
716
+ **Two things it deliberately does not do.** It never creates a session record: a
717
+ boundary that finds none is how the retroactive-capture guard recognises the
718
+ `off → on` flip (#92 review, F1), and a record written from the prompt path would
719
+ take that evidence away. And it writes the durable row BEFORE the flag, so a
720
+ failure duplicates a row rather than closing the question with nothing recorded.
721
+
722
+ ## The daily copy is beside the store, and it is the only thing that deletes (2026-09-18, F2)
723
+
724
+ The owner's memory had no automatic protection at all against a corrupt or wiped
725
+ database: `counterparts backup` existed, nothing ran it, and — the part that
726
+ matters for a project whose whole absence discipline is about telling "never
727
+ happened" from "gone" — **nothing said so**. A store copied every night and a
728
+ store never copied once were the same silence.
729
+
730
+ Four choices this took, and why:
731
+
732
+ **The step is in the worker, not in the cycle.** `bin/runner.ts` runs it fourth,
733
+ after `sessionEnd` returns and inside the `finally`, so the copy happens on the
734
+ failed path too — the day the worker breaks is the day a backup is worth most —
735
+ and so the store is still open when it is taken. It is not a `core/sleep/` phase
736
+ on purpose: sleep must not learn that the floor is changing.
737
+
738
+ **Rotation lives in an adapter because rotation deletes.** The store exports no
739
+ delete of any kind (store §5 G2), and every rule about what may go is in one file
740
+ a person can read start to finish. The refusals are the design: a directory
741
+ inside the store, a directory containing the store, a filesystem root, the home
742
+ directory, v1's live stores, a symlink whose TARGET is any of those. Both sides
743
+ are `realpath`ed before they are compared — `resolve` does not follow links, and
744
+ on macOS `$TMPDIR` is itself one, so a check comparing a realpathed side against a
745
+ merely resolved one says "no" to the same directory. A path that does not exist
746
+ yet is normal on a fresh install, so the deepest existing ancestor is realpathed
747
+ and the rest put back on.
748
+
749
+ **The partial name is the real protection against the watchdog.**
750
+ `cli/snapshot.ts#snapshot` is fully synchronous — `copyFileSync` per file — so the
751
+ `AbortController` this process arms cannot interrupt it — and, corrected by the F2
752
+ review (N-1), **nothing kills the worker either**: `spawn.ts` spawns it
753
+ `detached: true` and never calls `.kill()`, and the worker's own watchdog only
754
+ `abort()`s a signal on an unref'd timer. An overrunning copy runs to completion.
755
+ The partial name is still the right protection, but for the reasons that actually
756
+ apply — machine sleep, a shutdown, a `kill -9` by hand (the reviewer proved that
757
+ last one on a 12,000-file store: signal 9 mid-copy left exactly one entry,
758
+ `.partial-…`, which a later run swept while taking a real copy in the same pass).
759
+ So the copy goes to `.partial-<instant>-<pid>` and is RENAMED
760
+ into place: a process killed at any instant leaves either a complete snapshot or
761
+ something that is not a snapshot by name, and there is no state in between. A
762
+ partial is swept by a later run only once it is older than `PARTIAL_STALE_MS`,
763
+ comfortably past the watchdog, because deleting a fresh one would be this module
764
+ destroying a concurrent run's copy.
765
+
766
+ Measured on a synthetic store larger than the owner's — 18,800 files, 78 MB —
767
+ **one copy takes about 2.3 seconds** against a 300,000 ms watchdog
768
+ (`TUNABLES.WATCHDOG_MS`). It collapses to a handful of files on the rows-only
769
+ floor. The cost is not a concern; the retry cost was, which is why a failing copy
770
+ is tried at most three times a calendar day rather than at every boundary.
771
+
772
+ **Which skips leave a row.** `already-today` and `attempts-exhausted` write
773
+ nothing — today's `snapshot.taken` row and the failures they counted already are
774
+ the record, and a row per boundary is a flood rather than a fact. `no-default-dir`
775
+ writes nothing either: it is a configuration fact that will not change on its own,
776
+ so doctor's Snapshot line says it in words. Everything that stopped a copy that
777
+ should have happened is a `snapshot.failed` row with its `reason` and `step`, and
778
+ the directory refusals are deduped per calendar date.
779
+
780
+ **No lock between two workers, on purpose.** Two runs that overlap on the same
781
+ UTC day both see no snapshot for today, both copy into their own pid-stamped
782
+ partial, and both rename — so a day can end with two copies and two
783
+ `snapshot.taken` rows. Both rotations may also report deleting the same
784
+ directory, because `rmSync(..., { force: true })` swallows the second. Every part
785
+ of that is the safe direction (an extra copy, a duplicated record), and a lock
786
+ file would be a new thing that can go stale and refuse a backup on the day it
787
+ matters. If the duplicates ever become noise, the gate is the place to tighten,
788
+ not the copy.
789
+
790
+ **What the adversarial review changed (2026-09-18).** Four things, and the first
791
+ is the one worth remembering.
792
+
793
+ *The live-store refusal ran on the name, not on the path.* `assertRotatableDir`
794
+ called `assertSafeDataDir` and *then* realpathed — and `assertSafeDataDir` is pure
795
+ string math that follows no links. So a `snapshots.dir` that was a symlink into
796
+ `~/.bansai` cleared the one guard this repository's first safety rule is about,
797
+ and the directory came back as rotatable. The copy was refused further down, but
798
+ `cleanPartials` runs before that. It is checked on both spellings now, and the
799
+ check is injectable for one reason: `os.homedir()` cannot be moved under bun, so
800
+ the forbidden roots cannot be relocated into a temp tree, and a stand-in is the
801
+ only honest way to prove the ORDER without pointing a test at the owner's real
802
+ v1 memory.
803
+
804
+ *A typo in an optional backup setting stopped memory.* `"keep": 0` — or `"14"`
805
+ with quotes — made `loadConfig` return the observer config with `dataDir` gone, so
806
+ from the next hook on nothing was captured and nothing recalled, with one stderr
807
+ line that goes nowhere. This one block is read leniently now: each bad field falls
808
+ back to its default, the parse records which and why, and doctor says it. It is
809
+ the only lenient block in the file, and it should stay that way — the strict rule
810
+ is right for a knob whose wrong answer makes the adapter ACT (an egress switch, a
811
+ path this package opens). A backup preference is not worth memory.
812
+
813
+ *Doctor counted the row, not the directory.* Deleting every copy from disk left
814
+ the line reading green, "1 kept", for a full day. It counts the directory now and
815
+ says so when a row claims a copy that is not there.
816
+
817
+ *Nobody was told how to restore.* A snapshot opens and reads perfectly and
818
+ `search()` returns nothing until `verify --rebuild`, because `cache/` is
819
+ classified out of the backup set on purpose. The steps are in CONTRACT §5 G25 and
820
+ are printed as doctor's remedy on every Snapshot finding that is not green.
821
+
822
+ Smaller, same pass: a watchdog abort no longer spends one of the day's three copy
823
+ attempts (`step: "aborted"`, not `"copy"`); a failure window too full to read now
824
+ leaves one row rather than stopping backups in silence; the finished copy is
825
+ opened and `PRAGMA quick_check`ed before the rename makes it a snapshot; a
826
+ rotation candidate must hold something the store's LAYOUT classifies, so the
827
+ delete rule is "a directory this package wrote" rather than "a directory whose
828
+ name looks like one"; the sweep matches the whole partial shape rather than the
829
+ prefix; `snapshots.dir` and `mirror` must be absolute and non-blank; and the
830
+ snapshot's name now takes its DATE from the run's date, so a boundary straddling
831
+ UTC midnight cannot file today's copy under tomorrow.
832
+
833
+ **One thing deliberately not fixed:** a future-dated directory (a laptop waking
834
+ with a bad RTC) sorts newest and holds a `keep` slot forever, so the owner keeps
835
+ thirteen days of history instead of fourteen. Deleting it would mean destroying
836
+ bytes on the strength of a guess that a name is wrong. It is counted instead — on
837
+ the `snapshot.rotated` row and on the doctor line — so the "silently" is gone.
838
+
839
+ **Land F1 (WAL + busy timeout) before or with this.** `vacuumInto` opens a second
840
+ connection on the canonical database at every boundary, which under today's
841
+ `journal_mode=DELETE` is a new `SQLITE_BUSY` surface at exactly the moment I38
842
+ ("database is locked after a Stop") is about — and three busy boundaries would
843
+ spend the day's whole copy budget. The existing `cli.test.ts` case holds an open
844
+ write transaction across the copy and passes, so the common case is fine; this is
845
+ an ordering preference, not a defect. Re-measure after F1 lands.
846
+
847
+ **What the SECOND adversarial read changed (2026-09-18).** One finding, and it is
848
+ the same shape as the first review's: new code in the one decision that deletes
849
+ had gained a way to stop deleting without saying so. The LAYOUT rule added for
850
+ MINOR-7 — a rotation candidate must hold something the store's layout classifies
851
+ — dropped a rejected candidate from the directory read entirely, so it was
852
+ invisible to rotation, to "today's exists", to `kept`, to `oldest`, to doctor and
853
+ to every row. `LAYOUT` is read at runtime, so the rule can change underneath
854
+ copies that already exist. The rule is unchanged; rejections are now counted and
855
+ named, on the rows and on the doctor line.
856
+
857
+ Also from that read: the mirrored copy is verified before its rename, exactly as
858
+ the primary is (a `cpSync` that returns having written a truncated tree would
859
+ otherwise be renamed into place and rotate a good copy out of the mirror); a
860
+ mirror equal to, inside, or containing the primary directory is refused in words
861
+ rather than dying on a raw `ENOTEMPTY` — a second location inside the first dies
862
+ with the same disk and doubles local storage while nothing says there are two
863
+ trees; `verifyCopy`'s `finally` swallows a close failure, so "it never throws" is
864
+ structural rather than true only because the runner catches; a run `date` that is
865
+ not a calendar date falls back to the clock and says so, because it would
866
+ otherwise build a name matching neither pattern — a full copy at every boundary,
867
+ never rotated, never swept; the `ignored` phrases are stripped of control
868
+ characters and bounded before they reach a terminal; "future" is compared as
869
+ calendar dates so doctor and rotation cannot disagree by a day; and a partial
870
+ whose mtime is in the future is swept rather than kept forever by a negative age.
871
+
872
+ **Two facts about the copy are now pinned by a test, and they are a cross-PR
873
+ coupling.** `VACUUM INTO` writes a ROLLBACK-mode database even from a WAL source,
874
+ and `verifyCopy` does not convert it — F1 makes WAL conversion opt-in and
875
+ `verifyCopy` calls `openDb` with no options. Both were measured by the reviewer
876
+ rather than asserted anywhere, and a WAL-mode database cannot be opened on
877
+ read-only media, which is exactly where archived backups end up. Adding
878
+ `{ wal: true }` to that one call would convert every snapshot at verification
879
+ time. The test reads the header bytes and checks for sidecars, and it holds on
880
+ either floor.
881
+ ## The quiet hook now says when it is a fault (H1, 2026-09-18)
882
+
883
+ "A failed hook is a quiet hook, never a failed session" (§5 G2) has been right
884
+ since day 0, and the quiet was the part that hurt. The stand-down line goes to
885
+ stderr, and on this host a hook's stderr goes nowhere the owner looks. Three
886
+ reviews in one day hit the same wall from three directions: fully removing a
887
+ belief left a row that made `Counterpart.open` throw at every session start; a
888
+ missing prose file on ANY schema row does the same thing today; and a `--config`
889
+ typo stood the adapter down just as invisibly. Each of them costs no wake, no
890
+ recall and no capture in EVERY session, for as long as it lasts, with every
891
+ visible surface green — which is I32's shape again, and the constitution's own
892
+ sentence about silence not masquerading as health.
893
+
894
+ **What is new is a classification, not a channel.** The channel is the one I32's
895
+ close already measured and the red notice already rides: a top-level `systemMessage`, which
896
+ this host DISPLAYS, non-blocking, on SessionStart and UserPromptSubmit. What
897
+ `bin/hook.ts` could not do before was tell its two kinds of stand-down apart, so
898
+ `standdown.ts` is where that judgement lives and where its vocabulary is kept:
899
+
900
+ - **Deliberate, and unchanged.** A directory scoped `off` (G19, silent on both
901
+ channels, and the `off` return still comes first so its silence stays
902
+ byte-for-byte); an observer with no store to read (`STORE_UNINITIALIZED`); the
903
+ explicit-dir guard's two refusals. The guard is the interesting one: in a real
904
+ session it is a fault from the owner's point of view, and it is also the normal
905
+ state of every agent and test shell in this project, all of which export
906
+ `COUNTERPARTS_REQUIRE_EXPLICIT_DIR=1`. `describeGuardRefusal` already gives it
907
+ a sentence with the entry point's own remedy; a red line in every hermetic
908
+ shell is how a warning becomes wallpaper, so its treatment is kept.
909
+ - **A fault, and said once.** Everything else, including the two refusals of a
910
+ configuration somebody NAMED. One `systemMessage`, exit 0, and nothing else in
911
+ the object: no wake, no `additionalContext`. The stderr line stays.
912
+
913
+ **Once per session, and the marker cannot live in the store.** The store is what
914
+ failed, and UserPromptSubmit fires every turn, so the mark is a file beside the
915
+ session records — `<dataDir>/sessions/<id>.standdown.json`, the directory
916
+ `sessions.ts` and `expansions.ts` already use, which needs no database. Host
917
+ state, never memory: an id, a time, an event name and a code. SessionStart always
918
+ says it (a compaction re-fires it, and the owner has just had his terminal
919
+ rewritten); UserPromptSubmit says it only while the session has not been told.
920
+ Two stand-downs leave NO mark and therefore say it every turn: a named
921
+ configuration that could not be read (nothing has named a store yet, so there is
922
+ nowhere to keep one) and one that did not typecheck (`hostConfig` has by then
923
+ resolved `dataDir` to the DEFAULT store, and not touching that store's host state
924
+ is the whole reason that stand-down exists). A mark that cannot be written is
925
+ swallowed and the message is shown anyway: repeating is noise, and silence is the
926
+ incident.
927
+
928
+ **One ordering rule that is not obvious.** Nothing may be printed after the wake.
929
+ The host reads stdout as JSON only when the WHOLE of it parses, so an object
930
+ printed after a plain-text wake would turn the wake into ordinary text and inject
931
+ the warning into the model's context instead of showing it to the owner. The
932
+ `Said` record carries `wroteStdout` for exactly that, and a fault thrown after
933
+ the wake went out stays on stderr alone.
934
+
935
+ **And `doctor` reads the open.** Its `Store` finding reads the DIRECTORY, so it
936
+ could print GREEN Store while `Counterpart.open` threw at every session start —
937
+ which is what happened. `readCounterpartOpen` does an OBSERVER open of the
938
+ counterpart the way a hook's read path does it, including the `Schemas` index
939
+ scan that reads every schema row's prose, closes immediately, and reports in the
940
+ hook's own words. `STORE_UNINITIALIZED` there is AMBER rather than red: an
941
+ instrument may not write at open, and the next hook running as owner initializes
942
+ or migrates the same store — red would make the console lie for the window
943
+ between a deploy and the first hook after it.
944
+
945
+ **A fault is PERSISTENT or TRANSIENT, and the difference is what keeps this from
946
+ becoming wallpaper.** The first draft said "memory is OFF for this session" about
947
+ everything, and then measured what that would mean. I38 — `database is locked`
948
+ when a hook meets a store another process holds — is a stand-down like any other
949
+ and it reaches UserPromptSubmit: over 15 scripted sessions on a fresh store,
950
+ 2026-09-18, **5 of 45 prompt events on `origin/master` (039cd5d) and 3 of 45 on
951
+ the first draft of this branch** wrote the stderr line. Roughly one prompt in ten
952
+ on a HEALTHY store. Saying "OFF for this session" about it is untrue — the turn
953
+ was skipped, the next one is fine — and at that rate it is a line people learn to
954
+ scroll past, which is the failure mode this whole entry is about arriving by the
955
+ other door.
956
+
957
+ So `describeFault` asks `db.ts#isLocked` — the same predicate F1's WAL conversion
958
+ swallows its own contention with, imported rather than mirrored — and a busy
959
+ database gets its own wording and its own rule:
960
+
961
+ - **At a prompt**, the first one is counted in the mark and stays on stderr; from
962
+ the second it says `Counterparts skipped this turn: the memory database was
963
+ busy (database is locked). If this keeps happening, run: counterparts doctor`,
964
+ once per session. One blip is noise; a repeat inside one session is a signal.
965
+ - **At SessionStart** it says it the first time, in its own words —
966
+ `Counterparts could not load memory at session start: the memory database was
967
+ busy. This session has no wake; recall will work once the database is free.` —
968
+ because a lock there costs the whole session's wake and that event does not
969
+ come round again.
970
+ - **The two counters are apart**, so a session that met a busy database still
971
+ hears about a store that will not open.
972
+
973
+ **And after F1 the noise is gone.** Re-measured on the merged branch with the same
974
+ harness, 2026-09-18: **0 of 90 prompt events over 30 sessions**, and 0 on
975
+ `origin/master` (03297c6) over 15 — down from 5 of 45. WAL is what did it; the
976
+ second-occurrence rule costs nothing now and is the floor under the next time a
977
+ store is contended for some other reason.
978
+
979
+ **What could not be tested with a process.** The transient DISPLAY path. A
980
+ contended database is a race, and under WAL a reader is not blocked by a writer
981
+ at all, so there is no way to schedule one from a test. The rule is proved
982
+ exhaustively over `decideSay`, which is pure; the wiring either side of it — the
983
+ hook reading this session's mark and writing back what the rule decided, whole,
984
+ transient counters included — is proved by a real process.
985
+
986
+ ## Three things the adversarial review found, and what they taught (2026-09-18)
987
+
988
+ **A flag doing two jobs came apart on the event that fires every turn.**
989
+ `wroteStdout` was an ORDERING guard — nothing may follow the wake — and the first
990
+ draft also leaned on it as a DID-THE-WORK-HAPPEN guard. On SessionStart the two
991
+ coincide, because SessionStart always writes stdout. On UserPromptSubmit they do
992
+ not: an ordinary prompt with nothing to inject writes nothing. So a throw from
993
+ the `close()` in the `finally` — which is I38's own shape, the one close-time
994
+ failure this project has on record — told the owner *Counterparts skipped this
995
+ turn* about a turn where recall, capture and the session record had all just
996
+ succeeded. The fix is a second flag, `didWork`, set the moment `adapter.hook`
997
+ returns; the general lesson is that two guards that agree on one code path are
998
+ still two guards. A close-time throw cannot be induced hermetically, so the rule
999
+ is pinned as an exported predicate (`reachesTheOwner`) rather than left to a
1000
+ process test that cannot reach it.
1001
+
1002
+ **A new writer met an old wall from the wrong side.** `said.dataDir` is whatever
1003
+ the configuration named, and it is set BEFORE `Store.open` has had the chance to
1004
+ refuse it — so a config naming `~/.bansai/anything` got a `mkdir -p` and a marker
1005
+ file through the guard that exists so nothing here can touch v1's live memory.
1006
+ It never fires on the owner's deployment; it fires for agents, reviewers and
1007
+ replay tooling, which is exactly the population the guard was built for. Both
1008
+ doors of the mark now ask `assertSafeDataDir` inside their own `try`, so a
1009
+ forbidden root reads as "no mark" like any other unwritable one — and the message
1010
+ is still shown, because the message never depended on the mark landing.
1011
+
1012
+ **A new escape hatch has to keep the old file's promises.** `sessions.ts` states
1013
+ its writes are atomic and do not follow symlinks; the marker, a new file in the
1014
+ same directory, was a bare `writeFileSync` and a planted symlink sent it through
1015
+ to a file outside the store. It is now `lstat`-then-tmp-then-rename: anything but
1016
+ a regular file at the path is refused, and a rename replaces a symlink rather
1017
+ than writing through it.
1018
+
1019
+ **And one deliberate non-change.** Catching the fault inside `main` let a Stop's
1020
+ `exitCode = 2` survive a later throw, where master's top-level handler always
1021
+ exited 0 — so the ask would have been delivered instead of dropped. That is
1022
+ plausibly an improvement and it is not this change's to make: the one thing that
1023
+ moves on this branch is that two displayed events gain a `systemMessage`. The
1024
+ catch sets `process.exitCode = 0` and a test pins it.
1025
+
1026
+ ## 2026-09-20 — `adapter.spawn.started`, and a red that was crying wolf
1027
+
1028
+ **The other half of I32.** Every spawn REFUSAL has been durable since 2026-09-11, and a
1029
+ healthy start still wrote nothing — so a worker dead all week and a week with nothing to
1030
+ do left the same nothing, and `fired` could only call the mechanism blind (inventory §2
1031
+ row 23). Scar §2.4 is symmetrical: a door that opened and a door nobody opened must not be
1032
+ the same absence either.
1033
+
1034
+ One row per calendar date, latched at the store exactly like the refusals beside it. A
1035
+ boundary is a hot path and a healthy machine reaches many of them; three hundred identical
1036
+ rows a day would drown the log the view reads. The day's running count lives in two fixed
1037
+ meta keys — two, not one per date, because nothing mows meta and the only question the row
1038
+ asks of it is "how many today".
1039
+
1040
+ **The keyless red (new-user finding 1).** README says no API keys are required and
1041
+ QUICKSTART §6 says the worker still runs the day without one. `doctor` printed RED and
1042
+ exited 1 on a brand-new keyless store, and the same sentence arrived in the terminal at
1043
+ every session start. All three could not be true; a careful reader concluded their fresh
1044
+ install was broken and a trusting one went and bought a key.
1045
+
1046
+ The red is kept for the case it was written for — a key that was HERE and has gone — and
1047
+ the discriminator is the STORE'S OWN EVIDENCE rather than a marker file, because the thing
1048
+ that would write a marker is the thing that is missing. One `gate.chunk` row ever proves
1049
+ the interpreter worked here: the crash sweep is the only interpreted write path. Two
1050
+ bounded reads, one of them a single indexed row, so it stays inside the session-start
1051
+ budget.
1052
+
1053
+ The `SessionStart` notice goes quiet with it, because a notice needs a red. That closes
1054
+ finding 8 (the truncated fix sentence) sideways rather than by shortening it — the sentence
1055
+ would still truncate on a store that HAS lost its key, which is worth fixing on its own.