counterparts 0.3.40 → 0.3.42

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 (90) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/package.json +1 -1
  3. package/src/adapters/claude-code/CONTRACT.md +20 -1
  4. package/src/adapters/claude-code/NOTES.md +119 -0
  5. package/src/adapters/claude-code/bin/runner.ts +85 -0
  6. package/src/adapters/claude-code/doctor-write-ups.ts +66 -4
  7. package/src/adapters/claude-code/doctor.ts +4 -2
  8. package/src/adapters/claude-code/hooks.ts +12 -2
  9. package/src/adapters/claude-code/night-catch-up.ts +40 -17
  10. package/src/adapters/claude-code/night-run.ts +25 -13
  11. package/src/adapters/cli/catch-up.ts +13 -1
  12. package/src/adapters/cli/commands-readings.ts +3 -2
  13. package/src/adapters/cli/commands-verify.ts +2 -1
  14. package/src/adapters/cli/commands.ts +23 -2
  15. package/src/adapters/cli/coverage.ts +28 -21
  16. package/src/adapters/cli/mechanisms.ts +4 -20
  17. package/src/adapters/dashboard/registries.ts +7 -2
  18. package/src/adapters/dashboard/web/README.md +7 -0
  19. package/src/adapters/dashboard/web/flow.ts +3 -0
  20. package/src/adapters/dashboard/web/lanes.ts +2 -0
  21. package/src/adapters/dashboard/web/narrate.ts +41 -0
  22. package/src/adapters/dashboard/web/views/memory.ts +35 -0
  23. package/src/adapters/dashboard/web/views/mind.ts +3 -0
  24. package/src/adapters/dashboard/web/views.ts +1 -1
  25. package/src/adapters/fired.ts +3 -2
  26. package/src/adapters/lifecycle.ts +21 -1
  27. package/src/adapters/log/CONTRACT.md +1 -1
  28. package/src/adapters/log/NOTES.md +5 -0
  29. package/src/adapters/log/index.ts +2 -0
  30. package/src/adapters/mcp/NOTES.md +59 -0
  31. package/src/adapters/mcp/deliberate.ts +7 -1
  32. package/src/adapters/mcp/facts.ts +3 -1
  33. package/src/adapters/mcp/meaning.ts +3 -1
  34. package/src/adapters/mcp/nights.ts +5 -1
  35. package/src/adapters/mcp/server-self-tools.ts +15 -1
  36. package/src/adapters/mcp/server-words.ts +1 -1
  37. package/src/adapters/mcp/server.ts +118 -22
  38. package/src/adapters/mcp/tools.ts +32 -9
  39. package/src/adapters/remote/NOTES.md +2 -1
  40. package/src/adapters/scopes.ts +45 -1
  41. package/src/adapters/sessions.ts +38 -9
  42. package/src/adapters/sidebar-status.ts +7 -5
  43. package/src/adapters/update-check.ts +1 -1
  44. package/src/core/counterpart-boundary.ts +76 -5
  45. package/src/core/counterpart-events.ts +22 -5
  46. package/src/core/counterpart-types.ts +10 -0
  47. package/src/core/counterpart.ts +425 -237
  48. package/src/core/dream/CONTRACT.md +40 -1
  49. package/src/core/dream/NOTES.md +106 -0
  50. package/src/core/dream/index.ts +105 -10
  51. package/src/core/dream/mind.ts +3 -1
  52. package/src/core/dream/reflect.ts +110 -1
  53. package/src/core/dream/slices.ts +182 -1
  54. package/src/core/dream/tags.ts +13 -8
  55. package/src/core/dream/tunables.ts +1 -1
  56. package/src/core/handoff/CONTRACT.md +23 -10
  57. package/src/core/handoff/NOTES.md +32 -0
  58. package/src/core/handoff/index.ts +529 -234
  59. package/src/core/handoff/last-exchange.ts +7 -29
  60. package/src/core/handoff/last-here.ts +35 -108
  61. package/src/core/onboarding.ts +35 -7
  62. package/src/core/recall/CONTRACT.md +43 -13
  63. package/src/core/recall/INTERFACE-GAPS.md +2 -1
  64. package/src/core/recall/NOTES.md +187 -0
  65. package/src/core/recall/activate.ts +201 -31
  66. package/src/core/recall/gate.ts +14 -2
  67. package/src/core/recall/index.ts +120 -46
  68. package/src/core/recall/prime.ts +7 -1
  69. package/src/core/recall/rated.ts +4 -1
  70. package/src/core/recall/render.ts +15 -2
  71. package/src/core/recall/session.ts +11 -7
  72. package/src/core/recall/tunables.ts +37 -4
  73. package/src/core/schemas/NOTES.md +8 -0
  74. package/src/core/schemas/aliases.ts +54 -11
  75. package/src/core/schemas/tags.ts +5 -2
  76. package/src/core/schemas/tunables.ts +6 -1
  77. package/src/core/self/CONTRACT.md +9 -5
  78. package/src/core/self/NOTES.md +31 -1
  79. package/src/core/self/briefing-delivery.ts +12 -1
  80. package/src/core/self/briefing.ts +97 -37
  81. package/src/core/self/identity.ts +5 -0
  82. package/src/core/self/index.ts +140 -11
  83. package/src/core/self/tunables.ts +37 -0
  84. package/src/core/self/work.ts +20 -0
  85. package/src/core/store/NOTES.md +31 -0
  86. package/src/core/store/cache.ts +50 -4
  87. package/src/core/store/index.ts +20 -2
  88. package/src/core/store/owner-op-seam.ts +20 -5
  89. package/src/core/store/tag-reads.ts +16 -7
  90. package/tools/install-loop/run.sh +37 -13
package/CHANGELOG.md CHANGED
@@ -1,5 +1,110 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.42 — 2026-10-30
4
+
5
+ The wake is cleaner: it no longer lists bare ids, "Might be relevant" is gone once a store has its page, and where this folder stands is one block, led by the newest handoff. Yesterday's day summary shows again when a late write-up of another day used to hide it. Turns are faster on a large store and a late one is shown rather than lost. A folder set off, paused or to observe now stays out of the night and the catch-up, and a folder setting file that won't read stops the night and says so instead of thinning the page. No store-format change (store v15, cache v7), and nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. The first background run after updating builds recall's new index by itself, about half a second, no migration, and the cache file grows by about 15 MB. Going back to 0.3.41 needs no store restore: `counterparts disconnect`, 0.3.41's install, then `counterparts connect`.
6
+
7
+ - **The work after each turn takes about a third of the time.** On a store of about 5,000 memories
8
+ the background process each turn starts took 3.4 s and now takes about 1 s, mostly from no longer
9
+ opening 60 full memory cards to write the sidebar's file. The file says the same. `counterparts
10
+ log` now shows where each of those runs spent its time (`runner.steps`).
11
+ - **Turning a folder off now reaches the sessions already captured there.** The night's catch-up,
12
+ `counterparts catch-up` and the write-up pointer used to take every owed session whatever its
13
+ folder's setting, so a later night could write memories from a folder you had since set off. A
14
+ session in a folder that is off, observer or paused (a subfolder of one included) is now left out,
15
+ isn't counted as owed in doctor or by the night, and shows as such in `counterparts coverage`. A paused
16
+ folder you resume is owed again until its text ages out. Memories already written stay as they are.
17
+ While `scopes.json` won't read, write-ups stop, and doctor, `counterparts coverage`, `counterparts catch-up`
18
+ and the session-start line all say so and name the file.
19
+ - **`counterparts verify --rebuild --keep-vectors` no longer reports a false mismatch.** It counted
20
+ archived and superseded rows as unaccounted for and exited with an error; no row was ever missing.
21
+ - **The wake says where this folder stands in one place.** The last chapter here, the last
22
+ thing said here and the handoffs are now one block, grouped by session. The newest handoff
23
+ leads, up to five lines and always with what it says comes next, with a newer chapter named
24
+ under it, and the next two handoffs get a line each.
25
+ - **The wake no longer lists bare ids, and "Might be relevant" has left it.** A count points
26
+ at a recall that lists the items by title: `still open` now also lists what's coming up,
27
+ and a new `handoffs here` lists this folder's handoffs to expand or retire. Coming up shows
28
+ the oldest overdue items by title and how long ago they were due. Recall already offers
29
+ what might be relevant on every turn, with ratings. A new store keeps the lane until it has
30
+ its first self page, since that is all its wake has of its memories.
31
+ - **Recall stops throwing away finished answers.** About one turn in twenty showed no memories because
32
+ recall had passed its time limit, even though the answer was already done and showing it cost about
33
+ 5 ms. Those turns now show it, and the record says how late they ran.
34
+ - **Recall is faster on a large store, with the same results.** On about 5,000 memories, recall itself
35
+ went from about 415 ms to about 110 ms when the store hasn't been read for a minute or so, and the
36
+ whole step before your message is sent from about 725 ms to about 400 ms. The first background run
37
+ after updating builds an index for this, about half a second, and the cache file grows by about 15 MB.
38
+ - **Yesterday's summary isn't hidden by a late write-up of another day.** A session's write-up filed
39
+ days later, from a folder since set off, used to make every wake that morning fall back to the
40
+ chapter list. The summary now holds back only for what day's end is handed: that day's chapters
41
+ and memories, and what it cites, from a folder set off, paused or to observe. When it
42
+ does hold back, it leaves a row saying what kind of thing held it, with no words and no folder.
43
+ - **The night no longer reads a folder set off, paused or to observe.** Day's end, the dream, the
44
+ reflection and the tagging aren't shown its memories or chapters, can't find them through recall, and
45
+ can't merge them, so what's closed stays out of the page, the day's summary and new merges. What's
46
+ already stored stays stored, and your own sessions' recall hasn't changed.
47
+ - **A folder setting file that won't read now stops the night instead of thinning it.** With `scopes.json`
48
+ broken, the night would have read almost nothing and could have rewritten your page from that. It now holds:
49
+ no page, dream or reflection, doctor goes red and names the file, and it runs again once the file is fixed.
50
+ - **A reflection sent back to rewrite part of its work still can't read a folder set off, paused or to
51
+ observe.** When a session ran its own reflection, those folders opened to its recall at the first
52
+ finish, even with a page or share still to send again. They now stay closed until the part lands or the
53
+ session has been quiet for half an hour. A reflection with nothing sent back gives the session its
54
+ normal recall at once.
55
+ - **The night can leave one line of its own.** After the reflection revises the page, it may add one
56
+ or two sentences for whoever wakes tomorrow: what stays from the night that the page doesn't say,
57
+ told as what happened. `recall "last night"` shows it; the wake doesn't yet. It's never cut: past
58
+ 300 bytes it's asked for once more, then left empty, and an empty line is fine.
59
+ - **Chapter summaries about work fade sooner.** A new summary of an unmarked or work chapter starts
60
+ at 0.25 instead of 0.4, so one nobody ever uses stops turning up in ambient recall after about 3
61
+ lived days instead of about 24. A chapter marked about you, the two of you or the assistant keeps
62
+ 0.4. Replaying the last 15 days loses no day a memory was used. Summaries already written keep what
63
+ they have, and the dream, the reflection and the wake's chapter lines read summaries by chapter, so
64
+ they see the same ones. On a store with no self page yet, "Might be relevant" no longer lists an
65
+ unmarked or work summary.
66
+ - **The log says more about what recall and the wake decided.** Each recall turn names up to three
67
+ memories that almost showed, and what each shown memory's words, meaning and bar came to. A session
68
+ start records the bytes of each wake section and how much of the page it printed. Wake renders list
69
+ the ids each section kept, and `refresh` renders no longer carry the list of trimmed ids. Ratings
70
+ and reflections count why a return was refused, and a dream's opening row says how far down the
71
+ queue the night reached. Ids and numbers only, on rows that were already being written.
72
+ - **A memory the dream folds or merges keeps the memory ids its parts pointed to.** A note that named
73
+ another memory by id would lose that pointer when the night folded it, so the memory it pointed to stopped
74
+ coming along. New folds and merges now keep those ids on a last line, up to four, and it comes along as
75
+ `See also` again. What's already folded stays as it is.
76
+ - **A memory that names another by id no longer brings along one from a folder set off, paused or to
77
+ observe**, unless you're working in that folder. Your own recall of it hasn't changed.
78
+
79
+ ## 0.3.41 — 2026-10-30
80
+
81
+ A memory that names another memory by its id now brings that one along: when a note about a rule comes to mind, the rule shows beside it as a `See also:` line (at most two a turn, and the first lines to go when room is tight). Recall no longer lifts a memory just for being near the session's recent talk, so there should be fewer loosely related footnotes. In the first meeting, a question step sent without an answer is no longer shown as failed, and the meeting's last step is now called `origin`. The night sorts up to 30 cards into people, projects, places and topics, up from 10. No store-format change (store v15, cache v7), and nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. Going back to 0.3.40 needs no store restore: `counterparts disconnect`, 0.3.40's install, then `counterparts connect`.
82
+
83
+ - **A memory that names another by its id brings it along.** When a memory that comes to mind
84
+ mentions another memory's id (a note about a rule, say, that names the rule), that memory
85
+ shows beside it as one `See also:` line, if nothing else keeps it back. Used, it learns the
86
+ words that brought it, so next time it can come back on its own. At most two a turn, kept
87
+ short, and the first lines to go when room is tight.
88
+ - **Recall no longer lifts a memory just for being near the session's recent talk.** The "train of
89
+ thought" head start is off: memories it lifted were rated the least useful of any group. Memories
90
+ linked to what the session used, wrote or has open here, and those sharing its tags, still get
91
+ their head start.
92
+ - **In the first meeting, a question step sent without an answer no longer shows as "Failed".** It now comes back as
93
+ a plain note that nothing was stored, and that starting the meeting needs no call, instead of an error.
94
+ - **The first meeting's last question no longer looks like "the meeting has started".** Its step is now called
95
+ `origin` (the old name `started` still works with an answer), the script says that choosing "Now" needs no call, and
96
+ a bare call to it gets plain words saying the meeting begins with `meet` and no step.
97
+ - **The night sorts three times as many cards.** Each night's tagging step now asks which kind
98
+ (person, project, place or topic) up to 30 cards are, up from 10, so the cards waiting for a kind
99
+ stop piling up.
100
+ - **The wake's project line leaves a record.** Each session start in a project's folder now records
101
+ whether that line showed, and if not why (no belief strong enough yet, or no room), with its size
102
+ and which beliefs it showed. Ids and counts only, never the text.
103
+ - **On claude.ai and Claude Desktop, Memory status is no longer marked read-only.** A status call there that names its
104
+ conversation updates that conversation's record, so the read-only label wasn't true; in Claude Code it still is.
105
+ - **Hosted: a sign-in or account page left open across a server update still works.** The forms' key now comes from
106
+ the server's cookie keys, so an update no longer answers "This form expired"; only a deliberate key rotation does.
107
+
3
108
  ## 0.3.40 — 2026-10-29
4
109
 
5
110
  Open items nobody has touched for two weeks are now parked: they leave the wake's "Still open", which says how many are parked (`· 12 parked`), and nothing is deleted or closed. `recall "still open"` still lists every one (the parked last, marked), a question about one still finds it, and using one again brings it back. Items with a date still to come, a `settlesWhen`, or `status: "asked"` (a question or request still waiting) are never parked. The first wake after upgrading may count a lot of parked items at once on a store that has gathered many; that's the backlog of two-week-old threads, all still there. `counterparts doctor` has an Open items line. No store-format change (store v15, cache v7), and nothing to run after upgrading beyond the usual restart of the dashboard and every Claude Code session. Going back to 0.3.39 needs no store restore: `counterparts disconnect`, 0.3.39's install, then `counterparts connect`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "counterparts",
3
- "version": "0.3.40",
3
+ "version": "0.3.42",
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": {
@@ -58,7 +58,10 @@ credential — belongs here, discovered at runtime, never assumed by the core.
58
58
  ## 3. Keeps
59
59
 
60
60
  - **Hooks return in microseconds; heavy work runs detached under a watchdog.** [engram E4,
61
- v1] The foreground path never blocks on a model call.
61
+ v1] The foreground path never blocks on a model call. The worker says where its own time
62
+ went: one `runner.steps` row per run in the process log (`adapters/log/`), wall ms per step,
63
+ with CPU for the longer ones, its boot, its whole CPU and its largest resident size
64
+ (2026-10-30, NOTES).
62
65
  - **Every session-ending path is a boundary** — normal stop, session end, and
63
66
  pre-compaction. [v1] behavioral-spec §2 G5 — compaction destroying the transcript must
64
67
  not destroy the day. This is the compaction-amnesia backstop.
@@ -961,6 +964,22 @@ directory. Under dreaming `auto` the SessionStart write-up pointer is retired
961
964
  (`lifecycle.ts#writeUpPointerRetired`); under `ask` or `off` no night runs and the pointer
962
965
  stays.
963
966
 
967
+ **[M] Only from a folder that is on now (2026-10-30, a fix; coordinator's brief, marked for
968
+ Mike's review).** "Everything owed" stops at the folder setting. A session any of whose
969
+ directories, or the one it is filed under, is now `off`, `observer` or `paused`
970
+ (`sessions.ts#folderSetAside`, the hook's most restrictive rule; a subfolder inherits, longest
971
+ prefix first) is not planned, not granted, not counted in the run's `left` or `partsLeft`, starts
972
+ no night, is not named by the pointer, holds no small debt back from it, and is not in doctor's
973
+ `Catch-up` count. The setting is read afresh for each batch, beside the configuration the
974
+ process read (`scopes.ts#foldersOn`): a folder turned off while a child runs is left out from the
975
+ next batch, and a child already granted it finishes. A file that will not read takes nothing,
976
+ and says so: doctor and `coverage` go on counting the debts, doctor's `Catch-up` goes amber naming
977
+ the file, `counterparts catch-up` exits 3 naming it, and the session-start line says write-ups have
978
+ stopped. A store named with `--dir`, with no configuration, reads no setting. **What is left out is not
979
+ touched.** No mark, no progress, and `coverage/`'s ledger and `remember/owes.ts` are unchanged, so
980
+ its text goes on the ordinary clocks (at most 14 days from its last activity) and a paused folder
981
+ resumed before then is owed again.
982
+
964
983
  **[M] The night also starts when write-ups are owed (2026-10-11).** Under `auto`, a prompt
965
984
  whose dream is not due for `too-little-new` or `first-day` — the day unclaimed, no run under
966
985
  way (`Dreams#catchUpOffer`) — starts the night anyway when sessions from an earlier calendar
@@ -567,6 +567,21 @@ when it could not be read), so one loss shows as one amber line. The owed readin
567
567
  every scope's words, so it is read once per doctor run, shared by both lines, and skipped
568
568
  by the budgeted session-start reading.
569
569
 
570
+ ## A bad scopes entry fails open; a bad file fails closed (2026-10-30, restating #92's ruling)
571
+
572
+ `parseRegistry` refuses an entry it can't read, by name, and that folder reads `unset`, which is on.
573
+ A file that won't read at all closes every folder for a background writer (`scopes.ts#foldersOn`:
574
+ the catch-up, the night's fence), while a hook still fails towards on. So a typo in one entry of an
575
+ off folder opens that folder to the night until the file is fixed. That is the #92 ruling, kept on
576
+ purpose: the file's own trouble is reported at every door. Noted so it isn't lost.
577
+ The night holds on a file that won't read, not on a bad entry (2026-10-30, review of #688): `runNight` ends
578
+ `could-not-start`, reason `folder-setting`, no child asked, and doctor's `night-held` is red until it's fixed.
579
+
580
+ What won't read is `parseRegistry`'s whole-file list, and it's wider than junk: a file with no `version`, a
581
+ `version` this copy doesn't read (a rollback past a future bump), and a BOM all hold the night, as they already
582
+ stopped the catch-up. A wrong permission or a directory in its place does too. Absent doesn't, and neither does
583
+ `{}` (2026-10-30): an empty object names nothing, so it's the empty registry, for the hook and the catch-up too.
584
+
570
585
  ## What an adversarial read of the scope registry found (2026-09-15, PR #92 review)
571
586
 
572
587
  Five findings, and four of them are one mistake wearing different clothes: the
@@ -2823,3 +2838,107 @@ all use it).
2823
2838
  `known_marketplaces.json` carries `autoUpdate` at the default; which marketplace the
2824
2839
  directory listing lands in (`claude-community` and `@synced` are both handled off the copy's
2825
2840
  own path).
2841
+
2842
+ ## 2026-10-30 — what a worker did after `runner.done` (W1)
2843
+
2844
+ The process log said 75% of a per-turn worker's wall time came after its last row (10-29: 209
2845
+ workers, median 1.5 s of work, then 4.8 s with no row). `runner.coverage`, `runner.snapshot` and
2846
+ `runner.sidebar` are emitted and never reach the file because `LOGGED` leaves them out, so nothing
2847
+ said where it went. Measured through the Stop hook on a copy of the 10-30 corpus, plus a same-shape
2848
+ scrubbed copy of the live `spans/` and `sessions/` (the corpus carries neither, and the sweep gate
2849
+ and the coverage ledger read them), six turns, first discarded, `nice -n 15`:
2850
+
2851
+ | Step | Before, ms wall (CPU) | After, ms wall (CPU) |
2852
+ |---|---|---|
2853
+ | boot, embedder, open, lag, backfill | 139 | 140 |
2854
+ | cycle (before `runner.done`) | 785 (840) | 270 (317) |
2855
+ | wake, not re-rendered (73% of turns) | 0 | 0 |
2856
+ | coverage | 58 (78) | 55 (74) |
2857
+ | retention, carries, snapshot, close | 15 | 15 |
2858
+ | sidebar | 2,455 (2,515) | 536 (587) |
2859
+ | `process.end` | 3,385 | 957 |
2860
+ | after `runner.done` | 2,530 | 606 |
2861
+ | the whole process, as the OS saw it | 3.5 s, 550 MB | 1.0 s, 418 MB |
2862
+ | with the wake re-rendered (27% of turns): wake step, whole `process.end` | 1,465, 4,885 | 999, 1,995 |
2863
+
2864
+ Exit is at most about 60 ms; bun's boot about 65 ms. The real log's worker figures start at
2865
+ `openLog`, so they leave both out.
2866
+
2867
+ **Where the sidebar's time went.** `buildSidebarStatus` called `memoryDetail` for each of its 60
2868
+ memories and kept five fields. Each card also read up to `LOG_CEILING` `recall.credit` rows
2869
+ (`useDaysOf`) and walked every archived row (`timelineOf`): 31 ms a card, 1.85 s a turn.
2870
+ `memoryWords` reads the head, the words, the kind and the day and nothing else. On the same copy
2871
+ the `memories` and `panels` of the file come out identical before and after. The guarantee is
2872
+ unchanged: the file is still written after every boundary.
2873
+
2874
+ **Where the cycle's time went** (before the done row, found by the same profile, and it was the
2875
+ next-largest thing left). `workReserveBytes` asks for each folder's work lines, and each asked
2876
+ `settledOver`, a store-wide walk of every settled pair: 35 folders × 766 pairs, 540 ms. It now asks
2877
+ once and passes the answer down. The set can't change during that loop.
2878
+
2879
+ **Left, on purpose:**
2880
+ - The rest of the sidebar's 536 ms: the first `census` (240; every later one reads warm, so
2881
+ dropping this one only moves it to the first panel that needs it), `mechanismsView` (170), panels
2882
+ (100). All view functions shared with the dashboard, doing what the panels need.
2883
+ - The reserve is still computed at every boundary although the briefing phase uses it once a lived
2884
+ day. About 200 ms now; making it lazy reaches into `sleep/cycle.ts`, not worth it for that.
2885
+ - The wake re-render, about 1 s on 27% of turns: `pageCovers` (390) and `scanActive` (200) inside a
2886
+ real render. This is the largest cost left on those turns, and the highest resident peak (540 to
2887
+ 720 MB).
2888
+ - Resident size. 400 MB, of which the JS heap is 46 and the embedding table 30: the rest is native
2889
+ and a full GC doesn't return it. `--smol` changes nothing. Not chased further here.
2890
+
2891
+ **Overlap: no guard.** 10-29: 20 of 209 workers started during another, 7 of those in the same
2892
+ session; two or more at once for 120 s of the day, at most three. The steps that must not run twice
2893
+ already say so (the cycle's lease, the snapshot's day claim, retention's latch). A later worker
2894
+ that left its work to an earlier one would lose what is its alone: its session's lagged cue, which
2895
+ expires after one turn, and a sidebar file that includes the earlier worker's own rows. At a third
2896
+ of the duration, the same starts give about 26 s of overlap. 10-29's numbers don't ask for one.
2897
+ 10-30's might, and it was a partial day when this was written (to about 15:00 UTC): 108 workers,
2898
+ two or more at once for 809 s, at most four, 655 s of it in one stretch, 12:50 to 13:10 UTC. The
2899
+ week's read in `docs/CHECK-AFTER.md` decides.
2900
+
2901
+ **The watchdog doesn't bound this.** That same stretch had 10 workers over 100 s and two past the
2902
+ 5-minute `COUNTERPARTS_WATCHDOG_MS`: `process.end` at 380 s (`runner.done` at 8.5 s) and 367 s
2903
+ (`runner.done` at 37 s). The watchdog only aborts a signal, its timer can't fire during a synchronous
2904
+ step, and the sidebar's write is synchronous. Nothing recorded which step those runs were in. The
2905
+ sidebar is the likely one for the time after done, on its share of every other run, but it isn't the
2906
+ whole story: in the same stretch four workers reached `runner.done` only after 80 to 110 s, so the
2907
+ cycle went long as well. That looks like the machine, not one step. Left as is: the sidebar's step
2908
+ is now a fifth of the size, and a thrashing machine is a thing this file can't fix. If the rows show
2909
+ long gaps again, `runner.steps` will say which step.
2910
+
2911
+ ## 2026-10-30 — the catch-up and a folder that is off (NC1)
2912
+
2913
+ **What was found.** On the live store, three memories were written three days after their folder had
2914
+ been set `off`, each a write-up of that folder's earlier sessions, with an `adapter.night.writeup` row
2915
+ two minutes later. Confirmed on a throwaway store through `runNight` and the real door: a session
2916
+ captured in an on folder, the folder then set `off`, `observer` or `paused`, a subfolder of it too, and
2917
+ the night planned, granted and wrote all of them. `night-catch-up.ts` read no folder setting at all. G19's
2918
+ "no output, no write" was true of a session in the folder and had never been asked of a later process
2919
+ reading what the folder's sessions left behind.
2920
+
2921
+ **The pointer was nearly safe already.** It asks only for the asking session's own directory, and an off
2922
+ folder's hook returns before an adapter exists, so a pointer never ran there. Two gaps: a session with
2923
+ words in two folders could be named from the on one, and a full debt in an off folder stood in the
2924
+ store-wide `fullFirst` test, holding small debts in on folders back for up to 14 days of use.
2925
+
2926
+ **The filter is `pointable`'s, not the plan's.** `catchUpOwing`, `owedBefore`, `owedParts`, the row's `left`,
2927
+ doctor's reading and `coverage` all read it, and filtering in `planCatchUp` alone would have left the
2928
+ session counted as owed on every other surface, for ever. `folders` is an optional argument so a caller
2929
+ with no configuration (a store named with `--dir`) keeps what it had.
2930
+
2931
+ **A folder resumed the same day** waits for the next day's `owedBefore`, if `NOTHING_OWED_BEFORE_KEY` was
2932
+ already set that day, unless a night was due anyway. Loose on purpose.
2933
+
2934
+ **A setting that won't read went round in a circle (review of #689).** Take-nothing is the direction, and the
2935
+ text is on a clock, so silence there loses memories. As first built, doctor said overdue and "run counterparts
2936
+ catch-up", the command said "every ended session is written up", and `coverage` filed an on folder's session under
2937
+ "folder off". Now all three, and the session-start line, name the file. Not touched: the dream's and the
2938
+ reflection's bundles read every folder's memories and chapters (`Dreams#begin` has no `folderOn`), so a dream can
2939
+ still merge an off folder's memories into a new row filed where the night ran. Older than this, and a change in `core/`.
2940
+
2941
+ **Beside it: `verify --rebuild --keep-vectors` read every archived row as a mismatch.** Its arm of
2942
+ `verifyRebuild` left `skippedArchived` out of what it counted; the plain arm has counted it since I13. On
2943
+ a copy of the live store the difference was exactly the archived rows (621; superseded rows are all archived
2944
+ too). A miscount in the check, and no row was unaccounted for.
@@ -64,6 +64,9 @@
64
64
  * run says so where tomorrow can read it, and the others still run.
65
65
  *
66
66
  * It exits 0 on every path. Nothing about a failed run may reach the host.
67
+ *
68
+ * **IT SAYS WHERE ITS TIME WENT** (2026-10-30, `stepClock`): one `runner.steps`
69
+ * row in the process log, last before the end.
67
70
  */
68
71
  import { readFileSync } from "node:fs";
69
72
  import { homedir } from "node:os";
@@ -158,6 +161,9 @@ export interface RunReport {
158
161
  /** The word index's re-stem (v7 cache, 2026-10-19, an experiment), when this
159
162
  * run did any: absent on an index that was already stemmed. */
160
163
  readonly terms?: { readonly ready: boolean; readonly examined: number; readonly changed: number; readonly ms: number };
164
+ /** The covering index on the word index (LT1, 2026-10-30), when this run built
165
+ * it: absent on every run but the one. */
166
+ readonly postings?: { readonly ms: number };
161
167
  /** The sidebar's status file (`adapters/sidebar-status.ts`), written after the
162
168
  * store closed; absent when the run was not asked to (no configuration path). */
163
169
  readonly sidebar?: SidebarWrite;
@@ -314,6 +320,45 @@ export function retentionJob(input: {
314
320
  }
315
321
  }
316
322
 
323
+ /** A step's CPU goes on the row only when the step took this long: the row stays short. */
324
+ const STEP_CPU_FROM_MS = 5;
325
+
326
+ /**
327
+ * THE WORKER'S OWN CLOCK (2026-10-30). Wall ms per step, CPU ms for the steps
328
+ * long enough to ask about, and the process's whole CPU and its largest resident
329
+ * size seen at a lap: one `runner.steps` row per run in the process log, so the
330
+ * next read of "what does a worker spend its time on" needs nobody to measure it.
331
+ * Wall alone can't tell work from waiting: a step whose wall is far above its
332
+ * CPU was queued behind something else.
333
+ */
334
+ export function stepClock(): {
335
+ lap: (step: string) => void;
336
+ row: () => Record<string, number>;
337
+ } {
338
+ const out: Record<string, number> = {};
339
+ let wallAt = performance.now();
340
+ let cpuAt = process.cpuUsage();
341
+ let peak = 0;
342
+ return {
343
+ lap(step: string): void {
344
+ const wall = performance.now();
345
+ const cpu = process.cpuUsage();
346
+ const ms = Math.round(wall - wallAt);
347
+ out[step] = ms;
348
+ if (ms >= STEP_CPU_FROM_MS) {
349
+ out[`cpu.${step}`] = Math.round((cpu.user - cpuAt.user + cpu.system - cpuAt.system) / 1000);
350
+ }
351
+ peak = Math.max(peak, process.memoryUsage().rss);
352
+ wallAt = wall;
353
+ cpuAt = cpu;
354
+ },
355
+ row(): Record<string, number> {
356
+ const cpu = process.cpuUsage();
357
+ return { ...out, cpu: Math.round((cpu.user + cpu.system) / 1000), rssMb: Math.round(peak / 1_048_576) };
358
+ },
359
+ };
360
+ }
361
+
317
362
  /**
318
363
  * One run. Exported and injectable so the whole worker is testable without a
319
364
  * process, a socket, or a real data directory.
@@ -346,10 +391,13 @@ export async function runOnce(input: {
346
391
  /** Claude Code keeps this plugin updated itself: no request. */
347
392
  readonly autoUpdate?: boolean;
348
393
  };
394
+ /** How long this process took to reach `main()`, for the `runner.steps` row. */
395
+ bootMs?: number;
349
396
  onEvent?: (name: string, data: Record<string, string | number | boolean | null>) => void;
350
397
  }): Promise<RunReport> {
351
398
  const { config } = input;
352
399
  const emit = input.onEvent ?? ((): void => {});
400
+ const steps = stepClock();
353
401
  if (config.dataDir === undefined || config.dataDir.trim().length === 0) {
354
402
  emit("runner.refused", { reason: "no-data-dir" });
355
403
  return { ran: false, reason: "no-data-dir", swept: 0, minted: 0, code: null, lag: null, backfill: null, snapshot: null, retention: null };
@@ -365,6 +413,7 @@ export async function runOnce(input: {
365
413
  // so an embedder wired only into `openAdapter` would be one the memories
366
414
  // never meet.
367
415
  const embedder = input.embedder !== undefined ? input.embedder : openEmbedder(config, { onEvent: emit });
416
+ steps.lap("embedder");
368
417
 
369
418
  const counterpart = Counterpart.open({
370
419
  dir: config.dataDir,
@@ -388,6 +437,7 @@ export async function runOnce(input: {
388
437
  // (it needs no store, and holds none open across its network wait).
389
438
  // Fail closed: a store that will not say whether the person said stop is read as stop.
390
439
  const updatesAsked = input.updateCheck === undefined ? false : askedOff(counterpart.store, { failClosed: true });
440
+ steps.lap("open");
391
441
 
392
442
  let lag: LagReport | null = null;
393
443
  let backfill: BackfillReport | null = null;
@@ -411,6 +461,7 @@ export async function runOnce(input: {
411
461
  onEvent: emit,
412
462
  });
413
463
  }
464
+ steps.lap("lag");
414
465
  // 0b. One bounded batch, before the variable-length sweep, so a long sweep
415
466
  // (or the watchdog that ends one) cannot starve the store's blind memories.
416
467
  backfill = await backfillVectors({ counterpart, embedder, onEvent: emit });
@@ -423,6 +474,7 @@ export async function runOnce(input: {
423
474
  // stdio is ignored on this path by construction.
424
475
  noteFailure(counterpart, emit, code, "vectors", today);
425
476
  }
477
+ steps.lap("backfill");
426
478
 
427
479
  // 0c. THE WORD INDEX RE-STEM (v7 cache, 2026-10-19, an experiment; check
428
480
  // ~10-22). A cache migrated from v6 holds surface words until this step
@@ -439,6 +491,22 @@ export async function runOnce(input: {
439
491
  } catch (err) {
440
492
  noteFailure(counterpart, emit, err instanceof Error ? err.name : "UNKNOWN", "terms", today);
441
493
  }
494
+ steps.lap("terms");
495
+
496
+ // 0d. THE COVERING INDEX ON THE WORD INDEX (LT1, 2026-10-30). Once, in one
497
+ // transaction, never at open: a hook cannot pay for it. A lock it loses is the
498
+ // next run's to try.
499
+ let postings: RunReport["postings"];
500
+ try {
501
+ const r = counterpart.store.coverPostingsIndex();
502
+ if (r.built) {
503
+ postings = { ms: r.ms };
504
+ emit("runner.postings", { ms: r.ms });
505
+ }
506
+ } catch (err) {
507
+ noteFailure(counterpart, emit, err instanceof Error ? err.name : "UNKNOWN", "postings", today);
508
+ }
509
+ steps.lap("postings");
442
510
 
443
511
  // Step 4's answer, filled in the `finally` below and joined to whichever of
444
512
  // the two results the boundary produced. A `let` rather than a fourth return
@@ -457,6 +525,7 @@ export async function runOnce(input: {
457
525
  // Whose boundary this is, for the `associate.flush` rows (2026-10-11).
458
526
  ...(input.session === undefined ? {} : { session: input.session }),
459
527
  });
528
+ steps.lap("cycle");
460
529
  const swept = report.sweeps.reduce((n, s) => n + s.spansSwept, 0);
461
530
  const minted = report.sweeps.reduce((n, s) => n + s.proposals, 0);
462
531
  emit("runner.done", {
@@ -485,6 +554,7 @@ export async function runOnce(input: {
485
554
  } catch {
486
555
  /* the held page stays on its refusal row for the next boundary */
487
556
  }
557
+ steps.lap("held");
488
558
  // NOT WHEN THE CYCLE STOOD ASIDE (`sleep/lease.ts`, review of #581): the
489
559
  // cycle holding the store renders the wake, and this worker's refresh
490
560
  // would render it a second time beside it.
@@ -498,6 +568,7 @@ export async function runOnce(input: {
498
568
  } else {
499
569
  emit("runner.wake", { reason: "held-elsewhere", triggers: "", bytes: 0 });
500
570
  }
571
+ steps.lap("wake");
501
572
  result = {
502
573
  ran: true,
503
574
  reason: "ran",
@@ -509,6 +580,7 @@ export async function runOnce(input: {
509
580
  snapshot: null,
510
581
  retention: null,
511
582
  ...(terms === undefined ? {} : { terms }),
583
+ ...(postings === undefined ? {} : { postings }),
512
584
  };
513
585
  } catch (err) {
514
586
  const code =
@@ -521,6 +593,9 @@ export async function runOnce(input: {
521
593
  // tomorrow, and this process's stderr goes nowhere (I32).
522
594
  noteFailure(counterpart, emit, code, "sessionEnd", today);
523
595
  result = { ran: false, reason: "failed", swept: 0, minted: 0, code, lag, backfill, snapshot: null, retention: null };
596
+ // The boundary that threw is the step that took this time, or the first lap
597
+ // in the `finally` would carry it under `coverage`.
598
+ steps.lap("cycle");
524
599
  } finally {
525
600
  // 3b. WHAT IS NOT WRITTEN UP (2026-09-30, `core/coverage/`): one row per
526
601
  // stretch per state — owed, written up, lapsed — at every turn-end, keyless.
@@ -537,6 +612,7 @@ export async function runOnce(input: {
537
612
  } catch (err) {
538
613
  emit("coverage.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
539
614
  }
615
+ steps.lap("coverage");
540
616
  // 3c. RETENTION — on the failed path as well as the good one (a day whose
541
617
  // sweep broke still ages the text of sessions that owe nothing), with the
542
618
  // configuration's clocks. Its own try: a retention pass may not cost the
@@ -549,6 +625,7 @@ export async function runOnce(input: {
549
625
  } catch (err) {
550
626
  emit("retention.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
551
627
  }
628
+ steps.lap("retention");
552
629
  // 3d. TYPED WORDS LEAVE QUIET SESSIONS (2026-10-13): recall's carried cue
553
630
  // tokens are emptied in every session idle past the same ceiling, so a
554
631
  // session that ended or was killed does not keep them, and the copy below
@@ -560,6 +637,7 @@ export async function runOnce(input: {
560
637
  } catch (err) {
561
638
  emit("carries.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
562
639
  }
640
+ steps.lap("carries");
563
641
  // 4. THE DAY'S COPY OF THE STORE — after everything above has written, on
564
642
  // the failed path as well as the good one, and before the store is closed.
565
643
  // It never throws by construction (`adapters/snapshots.ts`); the try is
@@ -583,7 +661,9 @@ export async function runOnce(input: {
583
661
  } catch (err) {
584
662
  emit("snapshot.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
585
663
  }
664
+ steps.lap("snapshot");
586
665
  counterpart.close();
666
+ steps.lap("close");
587
667
  }
588
668
  // 5. THE SIDEBAR'S STATUS FILE (2026-10-14), last: what the Claude Code
589
669
  // sidebar shows, from what every step above left, through a handle of its
@@ -598,6 +678,7 @@ export async function runOnce(input: {
598
678
  });
599
679
  emit("runner.sidebar", { written: sidebar.written, reason: sidebar.reason, bytes: sidebar.bytes, ms: sidebar.ms });
600
680
  }
681
+ steps.lap("sidebar");
601
682
  // 6. THE DAILY UPDATE CHECK (U1b, 2026-10-28), after the store closed and
602
683
  // beside the sidebar's file: at most one GET of npm's `/latest` a day,
603
684
  // carrying nothing about the person (`adapters/update-check.ts`). It never
@@ -616,6 +697,8 @@ export async function runOnce(input: {
616
697
  });
617
698
  emit("runner.updates", { reason: updates.reason, switch: updates.switch, code: updates.code ?? null, latest: updates.latest ?? null });
618
699
  }
700
+ steps.lap("updates");
701
+ emit("runner.steps", { ...(input.bootMs === undefined ? {} : { boot: input.bootMs }), ...steps.row() });
619
702
  return {
620
703
  ...result,
621
704
  snapshot: snapshotReport,
@@ -726,6 +809,7 @@ export function runnerConfig(
726
809
  }
727
810
 
728
811
  async function main(): Promise<void> {
812
+ const bootMs = Math.round(process.uptime() * 1000);
729
813
  const choice = runnerConfigChoice();
730
814
  // The second refusal is the explicit-dir guard (`config-path.ts#implicitConfigRefusal`):
731
815
  // armed, an UNNAMED configuration stands the worker down too, because the
@@ -777,6 +861,7 @@ async function main(): Promise<void> {
777
861
  try {
778
862
  const report = await runOnce({
779
863
  config,
864
+ bootMs,
780
865
  signal: controller.signal,
781
866
  ...(pinnedSession() === null ? {} : { session: pinnedSession() as string }),
782
867
  ...(pinnedScope() === null ? {} : { scope: pinnedScope() as string }),