counterparts 0.2.0 → 0.3.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 (96) hide show
  1. package/README.md +87 -367
  2. package/docs/QUICKSTART.md +83 -1584
  3. package/docs/README.md +86 -0
  4. package/docs/module-map.md +1 -0
  5. package/package.json +5 -2
  6. package/src/adapters/claude-code/CONTRACT.md +151 -18
  7. package/src/adapters/claude-code/INTERFACE-GAPS.md +138 -2
  8. package/src/adapters/claude-code/NOTES.md +452 -0
  9. package/src/adapters/claude-code/bin/hook.ts +221 -49
  10. package/src/adapters/claude-code/bin/runner.ts +220 -101
  11. package/src/adapters/claude-code/config.ts +202 -279
  12. package/src/adapters/claude-code/doctor.ts +713 -421
  13. package/src/adapters/claude-code/embed-client.ts +165 -557
  14. package/src/adapters/claude-code/hooks.ts +409 -116
  15. package/src/adapters/claude-code/index.ts +7 -59
  16. package/src/adapters/claude-code/page-writer.ts +24 -4
  17. package/src/adapters/claude-code/spawn.ts +6 -7
  18. package/src/adapters/claude-code/transcript.ts +204 -10
  19. package/src/adapters/claude-code/vectors.ts +108 -24
  20. package/src/adapters/cli/CONTRACT.md +123 -3
  21. package/src/adapters/cli/INTERFACE-GAPS.md +45 -2
  22. package/src/adapters/cli/NOTES.md +265 -1
  23. package/src/adapters/cli/bin/counterparts.ts +9 -9
  24. package/src/adapters/cli/commands.ts +494 -436
  25. package/src/adapters/cli/help.ts +22 -27
  26. package/src/adapters/cli/index.ts +0 -2
  27. package/src/adapters/cli/install.ts +102 -89
  28. package/src/adapters/cli/removal.ts +1 -1
  29. package/src/adapters/cli/report.ts +25 -2
  30. package/src/adapters/cli/uninstall.ts +182 -34
  31. package/src/adapters/cli/wire.ts +232 -35
  32. package/src/adapters/dashboard/INTERFACE-GAPS.md +14 -2
  33. package/src/adapters/dashboard/activity.ts +4 -1
  34. package/src/adapters/dashboard/bin/dashboard.ts +1 -1
  35. package/src/adapters/dashboard/registries.ts +16 -1
  36. package/src/adapters/dashboard/resolve.ts +4 -4
  37. package/src/adapters/dashboard/source.ts +8 -2
  38. package/src/adapters/dashboard/web/flow.ts +6 -0
  39. package/src/adapters/dashboard/web/narrate.ts +66 -14
  40. package/src/adapters/dashboard/web/reveal.ts +6 -6
  41. package/src/adapters/dashboard/web/views.ts +12 -4
  42. package/src/adapters/fired.ts +20 -5
  43. package/src/adapters/mcp/CONTRACT.md +73 -1
  44. package/src/adapters/mcp/INTERFACE-GAPS.md +51 -1
  45. package/src/adapters/mcp/NOTES.md +389 -0
  46. package/src/adapters/mcp/bin/serve.ts +24 -35
  47. package/src/adapters/mcp/deliberate.ts +22 -0
  48. package/src/adapters/mcp/index.ts +26 -2
  49. package/src/adapters/mcp/server.ts +425 -49
  50. package/src/adapters/mcp/tools.ts +32 -7
  51. package/src/adapters/mcp/write-up.ts +454 -0
  52. package/src/adapters/sessions.ts +1353 -0
  53. package/src/core/counterpart.ts +32 -8
  54. package/src/core/embed/CONTRACT.md +85 -0
  55. package/src/core/embed/NOTES.md +93 -0
  56. package/src/core/embed/static.ts +622 -0
  57. package/src/core/encode/INTERFACE-GAPS.md +17 -0
  58. package/src/core/encode/NOTES.md +78 -0
  59. package/src/core/encode/secrets.ts +309 -9
  60. package/src/core/handoff/INTERFACE-GAPS.md +13 -1
  61. package/src/core/recall/CONTRACT.md +15 -3
  62. package/src/core/recall/INTERFACE-GAPS.md +94 -0
  63. package/src/core/recall/NOTES.md +49 -0
  64. package/src/core/recall/activate.ts +37 -3
  65. package/src/core/recall/index.ts +22 -1
  66. package/src/core/recall/session.ts +32 -0
  67. package/src/core/recall/tunables.ts +99 -2
  68. package/src/core/remember/CONTRACT.md +51 -7
  69. package/src/core/remember/INTERFACE-GAPS.md +111 -1
  70. package/src/core/remember/NOTES.md +221 -1
  71. package/src/core/remember/index.ts +28 -0
  72. package/src/core/remember/owes.ts +532 -0
  73. package/src/core/remember/owner-strike-seam.ts +34 -2
  74. package/src/core/remember/proposals.ts +25 -6
  75. package/src/core/remember/retention.ts +154 -0
  76. package/src/core/remember/spans.ts +53 -12
  77. package/src/core/remember/tunables.ts +8 -0
  78. package/src/core/remember/write-up-seam.ts +104 -0
  79. package/src/core/self/CONTRACT.md +16 -13
  80. package/src/core/self/INTERFACE-GAPS.md +8 -1
  81. package/src/core/self/NOTES.md +123 -1
  82. package/src/core/self/calendar.ts +81 -0
  83. package/src/core/self/episodes.ts +158 -36
  84. package/src/core/self/identity.ts +2 -2
  85. package/src/core/self/index.ts +88 -20
  86. package/src/core/self/tunables.ts +18 -46
  87. package/src/core/self/writer.ts +58 -9
  88. package/src/core/store/CONTRACT.md +16 -1
  89. package/src/core/store/NOTES.md +293 -0
  90. package/src/core/store/cache.ts +585 -27
  91. package/src/core/store/db.ts +97 -0
  92. package/src/core/store/index.ts +570 -13
  93. package/tools/install-loop/run.sh +52 -71
  94. package/src/adapters/claude-code/credentials.ts +0 -199
  95. package/src/adapters/claude-code/interpret-client.ts +0 -395
  96. package/src/adapters/cli/keys.ts +0 -503
package/docs/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # What is in `docs/`
2
+
3
+ This folder is the project's working record, kept in the open: the workshop with the lights
4
+ on. Most of it was written during the build, by the author and the AI sessions that build
5
+ Counterparts with him, for each other. It is dated, candid, and often superseded by a later
6
+ page. **Nothing here has standing authority.** [`CONSTITUTION.md`](../CONSTITUTION.md) alone
7
+ has it; every other page is a working default or a record of what happened.
8
+
9
+ ## If you came to use it
10
+
11
+ - [`QUICKSTART.md`](QUICKSTART.md) — the install path.
12
+ - [`ELI5.md`](ELI5.md) — the whole system in plain words, on one page.
13
+ - [`module-map.md`](module-map.md) — the technical map, module by module.
14
+ - [`../CONTRIBUTING.md`](../CONTRIBUTING.md) — how to run the suite and send a change.
15
+
16
+ ## Where the work is going
17
+
18
+ - [`ROADMAP.md`](ROADMAP.md) — the plan for the current round.
19
+ - [`HANDOFF.md`](HANDOFF.md) — the note one session leaves for the next. The newest section is
20
+ on top; everything below it is history.
21
+ - [`IMPROVEMENTS.md`](IMPROVEMENTS.md) — things noticed while living on it, as opposed to
22
+ building it.
23
+ - [`new-user-findings.md`](new-user-findings.md) — what the first install from npm was like.
24
+
25
+ ## Module documents (in `src/`)
26
+
27
+ Each module under `src/` carries its own pages. `CONTRACT.md` says what the module keeps (with
28
+ its lineage), what it drops, and what it guarantees. `NOTES.md` records what the build
29
+ learned. `INTERFACE-GAPS.md` lists what the module still owes. [`SEAMS.md`](SEAMS.md) holds the
30
+ wiring obligations between modules, and [`observer-mode.md`](observer-mode.md) describes one
31
+ mode of the core API.
32
+
33
+ ## Status records
34
+
35
+ Dated snapshots, kept as history rather than current state:
36
+ [`BUILD-STATUS.md`](BUILD-STATUS.md) (feature-complete, 2026-08-25),
37
+ [`LAUNCH-STATUS.md`](LAUNCH-STATUS.md) (the launch scoreboard, from 2026-09-04),
38
+ [`PARALLEL-RUN-STATUS.md`](PARALLEL-RUN-STATUS.md) (the weeks v1 and this version ran side by
39
+ side), and [`live-verify-2026-08-25.md`](live-verify-2026-08-25.md).
40
+
41
+ ## Specs and plans
42
+
43
+ [`storage-spec-2026-09-16.md`](storage-spec-2026-09-16.md) and its
44
+ [`-ideas`](storage-spec-2026-09-16-ideas.md) companion,
45
+ [`plan-step3-the-floor-2026-09-17.md`](plan-step3-the-floor-2026-09-17.md), and
46
+ [`plan-parallel-rebuild-2026-09-18.md`](plan-parallel-rebuild-2026-09-18.md). A plan is a
47
+ recommendation as of its date. The code and the `CONTRACT.md` files say what was built.
48
+
49
+ ## Adversarial reviews
50
+
51
+ `adversarial-review-*.md`. Before a risky change merged, a second agent was briefed to break
52
+ it, worked read-only against temporary stores, and wrote down what it found. A file ending in
53
+ `b` or `c` is the next pass, reviewing the builder's fixes. Some later reviews live as comments
54
+ on their pull requests instead.
55
+
56
+ ## Diagnoses, audits and measurements
57
+
58
+ [`finding-12-diagnosis-2026-09-17.md`](finding-12-diagnosis-2026-09-17.md),
59
+ [`promotion-diagnosis-2026-09-17.md`](promotion-diagnosis-2026-09-17.md),
60
+ [`recall-surfacing-diagnosis-2026-09-18.md`](recall-surfacing-diagnosis-2026-09-18.md),
61
+ [`mechanism-inventory-2026-09-17.md`](mechanism-inventory-2026-09-17.md),
62
+ [`contract-audit-2026-09-16.md`](contract-audit-2026-09-16.md),
63
+ [`contracts-sweep-trial-physics-2026-09-17.md`](contracts-sweep-trial-physics-2026-09-17.md),
64
+ and [`replay-review-2026-08-26.md`](replay-review-2026-08-26.md). Several of them read the
65
+ author's own store, read-only, and report counts from it.
66
+
67
+ ## Folders
68
+
69
+ - [`harvest/`](harvest/README.md) — what v1 taught, distilled on 2026-08-25: a behavioral spec,
70
+ a scar list, a test triage and more. [`harvest/SYNTHESIS.md`](harvest/SYNTHESIS.md) is the
71
+ entry point. It cites v1's own documents, which are not in this repository.
72
+ - [`research/`](research/) — research reports, such as local embeddings without an API key.
73
+ - [`launch/`](launch/) — the plan for making this repository public and the checklist it
74
+ follows.
75
+ - [`images/`](images/) — the dashboard screenshots the README shows.
76
+
77
+ ## Reading notes
78
+
79
+ - "The owner" is the author. "The assistant" or "the counterpart" is the AI whose memory this
80
+ is.
81
+ - `~/.counterparts` is the author's live store. `~/bansai` and `~/.bansai` are v1's code and
82
+ v1's store on his machine. v1's repository is private, so a mention of it is lineage, not a
83
+ link.
84
+ - Session ids, run ids and commit ids are cited as the evidence behind a number.
85
+ - A dated record may name a file that has since left the tree. Two prompt files were removed
86
+ on 2026-09-23; git history keeps them.
@@ -16,6 +16,7 @@ code and the `NOTES.md` / `INTERFACE-GAPS.md` next to it.*
16
16
  | `remember/` | hippocampal encoding | The authorship contract: the experiencer's end-of-session dump (content, salience tags, `updates:` marks), in-the-moment jots, crash-fallback ingestion. |
17
17
  | `store/` | the substrate | Two boxes since the floor (schema v6, 2026-09-20): one small canonical transactional SQLite (`counterparts.sqlite` — the memories' words, their archived versions, and every structured field), one rebuildable cache (embeddings/FTS, never backed up). The third box — one markdown file per memory — is gone. Markdown is an export (`render.ts`), plus a derived, write-only file copy of the journal under `journal/` — classified in the layout, deliberately NOT in the backup set, regenerated from its rows if deleted. |
18
18
  | `recall/` | retrieval + priming | Cues → activation → surfacing gate → bounded injection; footnote tier; reinforcement on real use. |
19
+ | `embed/` | — (a gist, not a reading) | Text in, vector out, on this machine, for nothing: the static embedding table (`static.ts`, potion-base-8M) that gives recall's semantic channel a source with no key. Zero code dependencies; its weights ship as the data-only package `counterparts-model-potion`, the one runtime dependency. The only embedder since 2026-09-24, when the paid Voyage seat was removed. **Added 2026-09-23 (roadmap C1).** |
19
20
  | `associate/` | Hebbian linking | Co-activation strengthens links; spreading activation at recall. **RESOLVED (owner, 2026-08-25): stays a module** — edge-level arithmetic keeps `physics/` one page; Hebbian plasticity/contiguity is its own mechanism in the field guide. |
20
21
  | `schemas/` | semantic memory | Entities and beliefs; birth by mention, death by decay; strength-weighted revision with row history. |
21
22
  | `self/` | autobiographical self | Identity documents, episodes, the wake briefing (v0's briefing, grown up). Governed: frozen self-reinforcement rules. |
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "counterparts",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "description": "Memory that turns AI tools into counterparts - a local-first, human-memory-modeled memory layer for AI.",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/mlapeter/counterparts.git"
9
9
  },
10
- "homepage": "https://github.com/mlapeter/counterparts#readme",
10
+ "homepage": "https://counterparts.ai",
11
11
  "bugs": {
12
12
  "url": "https://github.com/mlapeter/counterparts/issues"
13
13
  },
@@ -51,6 +51,9 @@
51
51
  "README.md",
52
52
  "LICENSE"
53
53
  ],
54
+ "dependencies": {
55
+ "counterparts-model-potion": "^0.1.0"
56
+ },
54
57
  "devDependencies": {
55
58
  "@types/bun": "^1.1.0",
56
59
  "playwright": "1.62.1",
@@ -7,7 +7,25 @@ detection — everything host-specific, so the core stays host-agnostic. Session
7
7
  where this adapter delivers a wake; it is no longer the only place one is read, because
8
8
  since 2026-09-17 the core composes a read-only one into the crash fallback's prompt — the
9
9
  same composer, minus the prospective lane and minus anything protected or confidential —
10
- and this adapter's interpret client is what puts that prompt on the wire.
10
+ and this adapter's interpret client put that prompt on the wire until 2026-09-24 (see
11
+ §1a: the sweep no longer interprets here).
12
+
13
+ ## 1a. Keyless (owner, 2026-09-24)
14
+
15
+ The package reads no API key and calls no model API of its own. Removed that day: the
16
+ Anthropic write-up of crashed sessions (`interpret-client.ts`, the `crashWriteUp: "api"`
17
+ opt-in, the worker's `sweepAware`), the Voyage embedder (the paid half of
18
+ `embed-client.ts`, `embedder.kind: "voyage"`, the `models` seats), the credentials file
19
+ (`credentials.ts`, `credentialsFile`) and the `credential` capability row. Why: the owner
20
+ wants to say "no keys; nothing leaves your machine except through Claude Code" without an
21
+ asterisk, and essentially no install had a key. The page writer's `pageWriter.command`
22
+ went at the same time — a configuration that could name the program the worker starts —
23
+ and the tests now inject it through code (`PageWriterPlanInput.command`).
24
+
25
+ A configuration that still names any of these is read, not refused: the setting is
26
+ ignored and listed in `AdapterConfig.retired`, which doctor prints as one green `Old
27
+ settings` note. `kind: "voyage"` reads as the local table. The paragraphs below that
28
+ describe the removed paths are kept as history and say so where it matters.
11
29
 
12
30
  ## 2. Brain analog
13
31
 
@@ -73,8 +91,9 @@ credential — belongs here, discovered at runtime, never assumed by the core.
73
91
  backfill and the whole sleep cycle — and froze the day's ask cap with them. Each step now
74
92
  asks its own question and records its own answer by name (`sweep.gate` with
75
93
  `reason: "no-credential"`; `no-credentials` / `embedder-off` on the vector steps).
76
- - **The credential comes from the environment first and, where the host gives a process
77
- none, from the ONE file this package's own config names (`credentialsFile`).** [v1's
94
+ - *(Removed 2026-09-24 with the keys — §1a.)* **The credential comes from the environment
95
+ first and, where the host gives a process none, from the ONE file this package's own
96
+ config names (`credentialsFile`).** [v1's
78
97
  `.env` fallback, ported as a scar rather than as code] Measured day 0 of the parallel
79
98
  run: this host's hook processes carry neither documented name even with both exported in
80
99
  the owner's shell rc. A file the config NAMES is "one configured source the package
@@ -137,11 +156,30 @@ owner's (measured 2026-09-04, `fix/transcript-peer-speakers`):
137
156
  classified `injected` as the conservative reading of a shape not yet measured.
138
157
  - **`Stop hook feedback: …`** — the host returning a blocking Stop hook's stderr to the
139
158
  model. It carries **this adapter's own asks**, so it is `ritual` and enters nothing
140
- (G11). One carrying a v1 marker is still `foreign`: foreign is checked first.
159
+ (G11). One carrying a v1 marker is still `foreign`: foreign is checked first. A
160
+ user-role line whose metadata says the HOST wrote it (below) and that opens with the
161
+ ask's own first words, bare or behind any `<Event> hook <word>:` frame
162
+ (`transcript.ts#OWN_ASK`), is `ritual` too — the JSON shape's return frame is
163
+ unmeasured, and this keeps it out of capture either way. Never a line with no metadata
164
+ (it may be the person) and never the assistant's own text.
165
+
166
+ **And who wrote a user-role line is read from the entry's own metadata first** (B1,
167
+ 2026-09-23; shapes measured on 2.1.28x, table in `NOTES.md`): `origin.kind: "human"` is the
168
+ person — typed, queued, or pasted; `isMeta`, `isCompactSummary`, and any other
169
+ `origin.kind` (`peer` for a subagent's hand-back, `task-notification`) are the host, and
170
+ are `injected` — kept in capture, out of pacing. The new text markers (anchored at the
171
+ start of the block) decide only for a USER-role entry that carries no metadata; the
172
+ assistant's text is never reclassified by a marker, and `classifyBlock` — the rule both
173
+ roles share — is unchanged. The two refusals (`foreign`, `ritual`) come before the
174
+ metadata, so hook feedback on an `isMeta` entry is still refused, not merely unpaced. An
175
+ assistant line the host synthesised (`isApiErrorMessage`, `model: "<synthetic>"`) is
176
+ `injected` as well; the assistant's real replies pace, as they always have. **Known gap**
177
+ (`INTERFACE-GAPS.md` §14): a prompt the person types while the model is working is
178
+ written as an `attachment` (`queued_command`), which this reader does not read.
141
179
  **Outputs** — an injected context block or the empty string; appended spans; the
142
180
  end-of-session ask; a detached worker spawn; capability reports (injection ceiling,
143
- execution ceiling, socket lifetime, credential availability AND which source answered —
144
- `env` or `file`, name-level only); delivery and stand-down telemetry.
181
+ execution ceiling, socket lifetime); delivery and stand-down telemetry. (A `credential`
182
+ row, saying which source answered, existed until the keys were removed — §1a.)
145
183
 
146
184
  **Guarantees** — **[M]** mechanized, **[A]** advisory:
147
185
 
@@ -228,6 +266,13 @@ execution ceiling, socket lifetime, credential availability AND which source ans
228
266
  half fired, the model got neither an id nor a tool name. The ask's text is the same
229
267
  text G11 refuses when the host hands it back — delivered by the hook, recorded by
230
268
  `adapter.ask`, never by its transcript copy.
269
+ **Amended 2026-09-23 (B1, owner's decision):** the ask still names the session id and
270
+ both tools, now in TWO lines, with two clauses about whether to write (`handoff` only
271
+ if work here is unfinished; nothing worth keeping is a real answer, `memories: []`).
272
+ `updates`-is-a-field and salience-is-a-floor moved to the `session_end` tool
273
+ description, where the model reads them while filling the fields
274
+ (`test/stop-ask-quiet.test.ts` asserts they are there). The PERSON reads one line of
275
+ their own, `hooks.ts#STOP_HUMAN_LINE`; both texts are pinned word for word.
231
276
  15. **[M] The prompt path opens no socket, and the semantic cue is LAGGED.** The
232
277
  embedding a turn's recall consults is computed by the detached worker AFTER the
233
278
  previous turn and read out of per-session gate state on the next one — the same
@@ -257,26 +302,26 @@ execution ceiling, socket lifetime, credential availability AND which source ans
257
302
  wired; this is the GUARANTEED path, because a memory that predates the embedder, or
258
303
  arrived by migration, has nothing and no future deposit comes back for it.
259
304
  17. **[M] The deliberate ask MAY embed in line, and says which channel answered.** The
260
- MCP entry point loads the same 0600 credentials file the hook entry point names and
261
- hands the server an opened embedder or null; the server never sees a key. A missing
262
- one degrades the ask to lexical-only and the result carries `semantic:
305
+ MCP entry point reads the same configuration the hook entry point does and hands the
306
+ server an opened embedder (the local table) or null. None degrades the ask to
307
+ lexical-only and the result carries `semantic:
263
308
  "embedder-off" | "embed-failed"` rather than a quietly narrower answer.
264
309
 
265
310
  18. **[M] ONE ask, on ONE pacer, capped per SESSION PER DAY, and the re-fire advances
266
- nothing.** The pacer is `self/`'s and nothing else: first ask on the first real
267
- substance (`FIRST_ASK_*`, or `SOLO_ASK_BYTES` alone so a one-prompt agentic session
268
- still journals), re-ask on `REASK_TURNS` **and** `REASK_BYTES` since the last ask —
269
- a conjunction, the way v1 re-asked, where v2 shipped a disjunction whose byte half
270
- was a third of v1's. The cap is `MAX_ASKS_PER_SESSION` and each session spends only
311
+ nothing.** The pacer is `self/`'s and nothing else: first ask on `FIRST_ASK_TURNS`
312
+ turns the person typed OR `FIRST_ASK_TEXT_BYTES` of conversation text from both roles
313
+ (so a one-prompt agentic session still journals), re-ask on `REASK_TURNS` OR
314
+ `REASK_TEXT_BYTES` since the last ask. The assistant's text adds bytes and never
315
+ turns (`hooks.ts#substanceOf`), so its own writing cannot pace the ask turn by turn.
316
+ The cap is `MAX_ASKS_PER_SESSION` and each session spends only
271
317
  its own, and only for the day it is spending: this host opens a session per
272
318
  invocation, and a cap of four shared across every session a calendar day held refused
273
319
  196 of 264 Stops while the crash-fallback sweep wrote 888 memories to the author's 193
274
320
  (2026-09-17) — while spent over a session's whole life the same six starved a session
275
321
  that worked through a day and into the evening, whose handoff was never offered the
276
322
  pen (2026-09-18, the day the allowance started resetting with the store's calendar
277
- date). The conjunction holds the cadence — six asks in one day is roughly 46 real
278
- turns — so the count is a backstop, and a session that has done no real work is still
279
- refused, on substance.
323
+ date). The pacer holds the cadence, so the count is a backstop, and a session that has
324
+ done no real work is still refused, on substance.
280
325
  The coverage read stays, as a RECORD of the unaskable tail and never as a second
281
326
  condition. Exactly ONE durable row per Stop (`adapter.ask`) carries the outcome —
282
327
  `asked` | `paced` | `capped` — and its date, so "how often was it asked today" is a
@@ -291,6 +336,21 @@ execution ceiling, socket lifetime, credential availability AND which source ans
291
336
  handoffs filed as memories. The text's length bound moved 1,050 -> 1,300 with it; the
292
337
  properties the bound defends — one screen, at most four numbered items, the session id
293
338
  exactly twice — are asserted on their own.
339
+ **B1 (2026-09-23) shortened it without adding a pacer:** two numbered lines, bound 450,
340
+ the handoff a clause on line 1. **Emission is ONE shape since 2026-09-24**
341
+ (`bin/hook.ts#hostDelivery`): exit 0 and
342
+ `{"systemMessage":<the person's line>,"hookSpecificOutput":{"hookEventName":"Stop","additionalContext":<ask>}}`
343
+ — the host's documented non-error route, which continues the turn under the same loop
344
+ protections as a block; the re-fire is refused as before. B1's
345
+ two shapes (`decision: "block"` JSON, and stderr + exit 2) both showed the person
346
+ `Stop hook error:`; the `stopAskShape` switch that chose between them is read and
347
+ ignored (`config.ts`, doctor's "Old settings"). Record in `NOTES.md`. Pacing is unchanged — thresholds, cap, the one pacer — except that what it
348
+ counts is now what the person typed and the assistant's replies, and no longer what
349
+ the host wrote on the user side (§5 Inputs, above). A `session_end` with
350
+ `memories: []` is an answer whatever happened to a handoff sent with it: accepted,
351
+ minting nothing, recorded as `nothingNewAt` on the session's registry record, the
352
+ handoff's own outcome beside it; it cannot cause a re-ask, because the pacer advanced
353
+ when the ask went out.
294
354
 
295
355
  **AND THE WAKE GAINED A THIRD DELIVERY-TIME FACT.** `sessionStart` passes the session's
296
356
  directory and id to `counterpart.wake(budget, delivery, here)`, beside the date it
@@ -392,7 +452,10 @@ execution ceiling, socket lifetime, credential availability AND which source ans
392
452
  `describeScopeTrouble` puts one line on the hook's stderr at **SessionStart
393
453
  only** — after the `off` return, so an off directory's silence stays
394
454
  byte-for-byte — with `scopeRegistry: "unreadable" | "partial" | null` on the
395
- session-start row for the day after. Both writers refuse rather than dropping
455
+ session-start row for the day after. **Since I40 (2026-09-23) the same line also rides
456
+ the SessionStart `systemMessage`**, because stderr at exit 0 reaches only the host's
457
+ debug log — AFTER the doctor notice and only if it still fits the envelope, since the
458
+ doctor notice has no other route and this line keeps its stderr copy. Both writers refuse rather than dropping
396
459
  an entry they could not read: the console unless `--force`, the MCP tool always.
397
460
  24. **[M] A stand-down that is a FAULT reaches the owner's terminal; one that is
398
461
  DELIBERATE stays as quiet as it was.** G2 is why every failure is swallowed;
@@ -556,6 +619,76 @@ Everything above about host mode is proved against a stub executable. What a rea
556
619
  has to answer is keychain access from a background process (`claude setup-token` is the
557
620
  documented route, spec §16), which is why `session` is the default.
558
621
 
622
+ ### The next-session write-up (C2, 2026-09-23 — true for now)
623
+
624
+ **[M] A session that ended owing a write-up is written up by the next session that starts
625
+ in its project.** "Owes" is B3's predicate (`remember/owes.ts#owesWriteUp`, read across
626
+ every scope through `adapters/sessions.ts#writeUpPlan`, the retention pass's own sources),
627
+ narrowed by one shared eligibility (`sessions.ts#waitingForWriteUp`) that the pointer, the
628
+ door and doctor all read:
629
+ - **ended** means a registry end, or silence past `WRITE_UP_SILENCE_MS` — the sweep's
630
+ 12-hour `CRASH_STALE_MS`, never the bind's 4-hour window (PR #192 review, MAJOR 3) — or no
631
+ record at all (the registry forgets one a week after its last write; a debt outlives
632
+ that);
633
+ - a session the registry still holds OPEN that ANSWERED its last ask is never pointed at:
634
+ B3 counts it as owing (no normal end), but while its record stands it is most likely a
635
+ terminal nobody has closed (MAJOR 3). **Known, and accepted as the default:** words it
636
+ captured AFTER that answer, at a later Stop that asked nothing, wait with it — invisible
637
+ to the pointer and to doctor's count — until the registry forgets the record, up to a
638
+ week after its last write; then it is pointed at and the fetch carries them
639
+ (INTERFACE-GAPS §17);
640
+ - with the API sweep on, a crashed session whose words the sweep will still read is the
641
+ sweep's (`sweepOwns`); one whose only words left are in quarantine is not (MAJOR 5);
642
+ - **in its project** means the session holds words filed under this project's scope. A
643
+ session that left words under two projects is written up in each by a session there,
644
+ and neither is served the other's (MAJOR 6).
645
+
646
+ Sessions never pointed at go first, then the least recently pointed at or fetched, oldest
647
+ first among equals, so one session nobody writes up cannot stand in front of the rest.
648
+
649
+ **[M] SessionStart carries a POINTER, not the words** (owner's choice of 2026-09-23,
650
+ INTERFACE-GAPS §15 option (b)). In `HookResult.ask`, after whichever other ask took the
651
+ field, it says how many sessions here are waiting, the oldest one's date, size and "part k
652
+ of N", and the call that fetches it, naming the ended session once and this session once:
653
+ **411–428 bytes with the host's 36-character ids** (measured). The words come back from the
654
+ MCP door (`mcp/CONTRACT` guarantee 16), at most `WRITE_UP_PART_BYTES` (~24 KB) per
655
+ session, because an MCP result is not under the host's 10,000-character cap on a hook's
656
+ output and the wake is. The pointer is measured against that cap as PLAIN stdout
657
+ (`WRITE_UP_HOST_OUTPUT_CHARS` = 10,000; bytes ≥ characters): with no owner notice
658
+ `bin/hook.ts#hostDelivery` prints plain text, and with one it drops the notice before it
659
+ lets the JSON envelope pass `ENVELOPE_MAX_CHARS`. It is NOT held to the reported budget,
660
+ which is what the wake is composed to; a 9,038-byte wake leaves room (tested with host
661
+ ids). Past the cap it DEFERS, claims nothing, and records the deferral DURABLY
662
+ (`sessions.ts#WRITE_UP_POINTER_KEY`, one meta row: outcome, need, room), which doctor
663
+ reads.
664
+
665
+ **[M] Once per session, and the day's allowance.** A compaction re-firing SessionStart
666
+ points at nothing (`writeUpPointer` on the session's registry record, which is also the
667
+ door's evidence that this session may fetch that session's words at all). At most
668
+ `WRITE_UP_ASKS_PER_DAY` (2, the page writer's number) pointers per calendar day in local
669
+ time. Before the pointer is handed over, the part size, count and hand-over time go into
670
+ one meta key (`adapter.writeup.progress`, per ended session and project, removed when the
671
+ session is marked), then the registry mark, then the day's count and the outcome row; a
672
+ mark that will not land hands nothing over. Never under observer; never in a directory set
673
+ `off` (the entry point returns before anything opens). The whole body is fail-open: a
674
+ throw costs the pointer and never the wake or the other ask (asserted byte for byte).
675
+
676
+ **[M] No sweep interprets (2026-09-24).** The opt-in API sweep (`crashWriteUp: "api"` and
677
+ the key) was removed with its key (§1a), and with it the pointer's deference to it
678
+ (`sessions.ts#sweepOwns`) and the worker's `sweepAware` mark `by: "api"`. The worker hands
679
+ the sweep no interpreter; its gate row says `not-opted-in` and `runner.done` says `sweep:
680
+ next-session`. A crashed session is pointed at like any other. An old `crashWriteUp` value
681
+ is ignored and named in `retired`.
682
+
683
+ **[M] Doctor: `Crash write-up`, and the `Sweep` line.** `Crash write-up`: `next session`
684
+ green; amber when a session is finished in one project and waiting on words it left in
685
+ another, naming that project (re-review m-C); amber when the newest pointer outcome is a
686
+ DEFERRAL and sessions are waiting — saying the wake was too full, by how many bytes, and to lower
687
+ `injectionBudgetBytes` by that much (never "open a session", which would defer again);
688
+ amber when a session has waited past `WRITE_UP_WAIT_DAYS` (3). Counted with the pointer's
689
+ own eligibility. Never red; not in the session-start reading. `Sweep`: `not-opted-in` —
690
+ and an older build's `no-credential` — is green `next session`.
691
+
559
692
  ## 6. Scars honored
560
693
 
561
694
  **E3** (streaming, with the host's socket ceiling proven here rather than assumed by the
@@ -268,13 +268,16 @@ this change did to them.
268
268
 
269
269
  ## 8. The embedder: what it closed, and the four things it deliberately did not
270
270
 
271
+ *(History. The Voyage client this section describes was removed on 2026-09-24 with the
272
+ API keys — CONTRACT §1a; the local table is the only embedder now.)*
273
+
271
274
  Written 2026-08-29 alongside `embed-client.ts` — the first embedder this package
272
275
  has ever had. `Store.open({ embed })` held the socket from the day it was
273
276
  written and nothing constructed one, so every memory in the store recorded
274
277
  `novelty: null`, reason `no-chunk-vector` (replay review F4/F5).
275
278
 
276
279
  **Closed.** A Voyage client on bare `fetch`, chunked with per-chunk failure
277
- isolation (E1), credential from `VOYAGE_API_KEY` alone with a named pre-flight
280
+ isolation (E1), credential from the Voyage key alone with a named pre-flight
278
281
  refusal (§2.18), its own pinned seat with an expiring placeholder (§2.15), and
279
282
  egress behind an explicit `embedder.enabled` knob that defaults OFF. Both
280
283
  composition roots build it: `openAdapter` and `bin/runner.ts` — the second
@@ -631,7 +634,21 @@ Filed here rather than guessed at: the exact steps the owner has to run by hand
631
634
  PR that landed this, and until one of those runs happens, `session` mode is the one that is
632
635
  known to work.
633
636
 
634
- ## 13. The "nightly" writer is not nightly anywhere west of UTC (2026-09-20, S2 review)
637
+ ## 13. The "nightly" writer is not nightly anywhere west of UTC (2026-09-20, S2 review) — CLOSED for the mechanism 2026-09-23 (#189)
638
+
639
+ **Closed for the mechanism by #189 (roadmap B3, the owner's ruling of 2026-09-23).** The
640
+ writer's night is now decided on the machine's LOCAL calendar — `core/self/calendar.ts`
641
+ and `self/writer.ts#pageWriterNight`, one function shared by `Self`, host mode and
642
+ doctor's Page writer line — so from US Pacific the night rolls over at local midnight,
643
+ not at 5 p.m. East of UTC the night waits for its UTC date to close
644
+ (`pageWriterAbout`: `min(local yesterday, UTC yesterday)`), because of what remains below.
645
+
646
+ **What remains:** `learned_on` — the provenance date the writer selects a day's memories
647
+ by — is still stamped in UTC by `store/`, like every other provenance date
648
+ (`store/index.ts#dateOf`). So the night a person lives and the date its memories are filed
649
+ under can still differ by the hours between local and UTC midnight. The fix, if the owner
650
+ wants one, is the same as below: one per-owner zone, read wherever a day is decided — not
651
+ a second clock. The text below is the gap as filed.
635
652
 
636
653
  `store.today()` is `new Date().toISOString().slice(0, 10)` — UTC, like every other date in
637
654
  this store, by the decision `store/index.ts#dateOf` records. The page writer keys its night
@@ -653,3 +670,122 @@ The real fix, if the owner wants one, is the one `self/INTERFACE-GAPS` §9's nei
653
670
  for: a per-owner zone read wherever a day is decided — one clock, moved once — and not a
654
671
  second clock bolted onto this mechanism. Until then it belongs on the findings list for the
655
672
  first blank-store trial, where it is a thing to notice rather than a thing to fix.
673
+
674
+ ## 14. A prompt typed while the model is working never reaches the transcript reader (2026-09-23, B1 review M3)
675
+
676
+ **Pre-existing; found by the adversarial review of PR #186, measured on the owner's
677
+ machine (shapes only).** When the person types while the model is still working, Claude
678
+ Code writes the prompt as an ATTACHMENT, not a user entry:
679
+
680
+ - `type: "attachment"`, `attachment.type: "queued_command"`, `attachment.commandMode:
681
+ "prompt"`, `attachment.origin.kind: "human"`, the text in `attachment.prompt` (a string,
682
+ or an object when an image was pasted), plus `source_uuid` and sometimes `humanTurn`,
683
+ with `rendered` / `renderedInHumanTurn` on the entry;
684
+ - 76 seen. **58 appear nowhere else in their file**; 18 are later written again as an
685
+ ordinary user entry.
686
+
687
+ `parseTranscript` reads only entries with a `message.role`, so those 58 are the person's
688
+ own words missing from BOTH pacing and capture — about 6% of typed turns on this machine.
689
+ (The same attachment type also carries `commandMode: "task-notification"` and `peer`
690
+ prompts; those are host-written and are correctly not the person.)
691
+
692
+ **Why it was not fixed in B1.** Reading them means inserting new turns into the list, and
693
+ the per-session capture cursor indexes into that list: a session that spans the deploy
694
+ would have its uncaptured tail re-sliced, the failure `transcript.ts`'s header names. It
695
+ also needs a dedupe against the later user entry for the 18 that are written twice —
696
+ by uuid (`source_uuid` → the later entry, if the link holds; unmeasured) or by exact text.
697
+
698
+ **What a fix needs:** (1) a cursor that survives turns being inserted before it (an
699
+ entry-uuid cursor rather than an index, which is `remember/`'s to offer); (2) the dedupe
700
+ rule, measured; (3) a fixture with one queued prompt that is later duplicated and one that
701
+ is not, pacing as one and two turns respectively.
702
+
703
+ ## 15. On a mature store there is no room at SessionStart for the write-up's words — or the page writer's (2026-09-23, C2)
704
+
705
+ **Measured, not guessed.** Beside the wake, the words of an ended session must fit both
706
+ the reported budget and the host's 10,000-character cap on a hook's whole output
707
+ (the first build kept 500 characters of margin for JSON escaping; the pointer, below, is
708
+ held to the plain 10,000). With ~800 bytes of block
709
+ furniture, under the 9,000-byte budget `install` writes:
710
+
711
+ | wake | words per start |
712
+ |---|---|
713
+ | ~470 B (fresh store) | ~7.7 KB |
714
+ | 3 KB | ~5.2 KB |
715
+ | 6 KB | ~2.2 KB |
716
+ | ≥ ~7.2 KB | none |
717
+
718
+ The owner's measured wakes run 8.8–9.0 KB.
719
+
720
+ **Option (b), taken by the owner 2026-09-23:** SessionStart carries a POINTER — 411–428
721
+ bytes with the host's 36-character ids, naming the ended session once — measured against
722
+ the host's plain-stdout cap (10,000) and not the reported budget, and the MCP door serves
723
+ the words: `session_end` with `writeUp` and no memories returns the next part, up to
724
+ ~24 KB, because an MCP result is not under the hook cap. Built in C2; with host ids it
725
+ reaches a 9,038-byte wake (tested) and defers only past a ~9,570-byte one. A deferral is a
726
+ durable meta row (`adapter.writeup.pointer`) that doctor's `Crash write-up` line reads and
727
+ explains in bytes.
728
+
729
+ **Option (a), still filed as the alternative, and still the page writer's problem:** the
730
+ wake reserves room for the session-start asks (`core/`'s composition budget). The page
731
+ writer's block carries its day's memories inline and is held to the reported budget, so
732
+ on the owner's store it defers every morning by the same arithmetic.
733
+
734
+ **Named cost of (b):** on a red morning with a wake of roughly 8.4–8.95 KB, the pointer
735
+ can push the envelope past `ENVELOPE_MAX_CHARS` and the doctor notice is the part dropped
736
+ (the wake wins, as always; `adapter.notice.dropped` records it). At a full 9 KB wake the
737
+ notice is dropped with or without it. Bounded: at most two starts a day carry a pointer,
738
+ and the notice returns at the next start.
739
+
740
+ **Residual cost (PR #192 review, n1):** the eligibility plan (`writeUpPlan`: every
741
+ scope's span files and up to 90 days of `adapter.ask` rows) runs at EVERY session start
742
+ whose allowance is not spent — and when nothing is owed, the allowance is never spent.
743
+ Measured by the review on 400 held sessions (1.6 MB of spans, 20k ask rows): ~43 ms per
744
+ start, 2 ms with the allowance spent. Acceptable now; it scales with the store. The cheap
745
+ fix, not built: skip the scan when nothing has changed since the last plan (a meta stamp
746
+ of the newest boundary/write-up/answer time the plan saw, compared before scanning), and
747
+ treat a plan that found nothing owed as spending the day's check.
748
+
749
+ ## 16. For C3: the opt-in is `crashWriteUp: "api"` (2026-09-23, C2) — CLOSED 2026-09-24 by removal
750
+
751
+ *The API sweep, the key and `credentials set` were removed on 2026-09-24 (CONTRACT §1a);
752
+ an old `crashWriteUp` value is ignored and named in `retired`. Kept as history:*
753
+
754
+ `credentials set` for the Anthropic key should offer to write `"crashWriteUp": "api"` into
755
+ `claude-code.json` (strict: `"api"` or `"next-session"`, anything else stands the config
756
+ down to observer; absent is `next-session`). The API sweep runs only with both the knob
757
+ and the key (`config.ts#apiSweepOn`). Doctor's two lines — `Crash write-up` and `Sweep` —
758
+ are C2's and already read the knob (`not-opted-in` on the gate row, core's second skip
759
+ reason); nothing there is owed to C3.
760
+
761
+ ## 17. An open-and-answered session's later words wait up to a week (2026-09-23, C2 re-review m-E)
762
+
763
+ **What happens.** A session answers its Stop ask (memories, a chapter, a handoff, or
764
+ "nothing new"), then captures more words at a later Stop that asks nothing, then goes
765
+ silent with no SessionEnd. B3 judges `answered` against the last ASK, so its facts are
766
+ `answered: true, endedNormally: false` — it owes. The write-up's open-and-answered rule
767
+ (`sessions.ts#openAndAnswered`, the coordinator's default for MAJOR 3) declines it while
768
+ the registry holds its record open: not pointed at, and not in doctor's count. The record
769
+ is pruned 7 days after its last write; from then on it is pointed at, and the fetch
770
+ carries every word it left (those an answer covered marked `[already written up]`).
771
+ Nothing is lost — B3 keeps it (`kept-live`, then `kept-owed`) — but it is invisible for up
772
+ to a week.
773
+
774
+ **Why it is not fixed here.** The right rule is "open and answered, AND nothing captured
775
+ after the last answer". That needs the time of the last answer, which B3 computes and
776
+ does not expose: `owes.ts#planRetention` reads accepted `session_end` proposal times,
777
+ handoff rows and the "nothing new" mark — and a chapter answer, which has no time at all
778
+ (`episodeFacts` gives `appendedAtAsk`, not when). `HeldSession` carries `facts` and
779
+ `clockFrom` only. Re-deriving the answer times in `sessions.ts` would be a second
780
+ definition of "answered", which is the drift B3's one-predicate rule exists to prevent.
781
+
782
+ **Ask (remember, `INTERFACE-GAPS` §16):** `HeldSession` gains `lastCaptureAt` and
783
+ `lastAnswerAt` (for a chapter-only answer, the last ask's time — the chapter is written
784
+ after it, so it is a lower bound). Then the rule is one predicate in
785
+ `sessions.ts#openAndAnswered`: `answered && lastCaptureAt <= lastAnswerAt`.
786
+
787
+ **And the owner's hand (re-review m-C):** a share finished in one project and waiting on
788
+ words the session left in another (`written-up-here`) owes until a session opens there.
789
+ Doctor's `Crash write-up` line names that project. A directory set `off` never opens
790
+ one; closing such a session by hand needs a console command that marks `by: "owner"`
791
+ (`WRITE_UP_BY` has the word; nothing may import the seam to use it) — filed, not built.