counterparts 0.3.49 → 0.3.52

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 (95) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +18 -10
  3. package/docs/QUICKSTART.md +46 -12
  4. package/docs/manual.md +2 -1
  5. package/docs/module-map.md +3 -0
  6. package/package.json +3 -2
  7. package/src/adapters/claude-code/NOTES.md +43 -0
  8. package/src/adapters/claude-code/child.ts +23 -2
  9. package/src/adapters/claude-code/doctor-growth.ts +269 -0
  10. package/src/adapters/claude-code/doctor-host.ts +19 -1
  11. package/src/adapters/claude-code/doctor-recall-steps.ts +84 -0
  12. package/src/adapters/claude-code/doctor.ts +26 -3
  13. package/src/adapters/claude-code/hooks.ts +7 -1
  14. package/src/adapters/cli/INTERFACE-GAPS.md +18 -0
  15. package/src/adapters/cli/NOTES.md +24 -0
  16. package/src/adapters/cli/commands-dashboard.ts +9 -1
  17. package/src/adapters/cli/commands-project.ts +2 -1
  18. package/src/adapters/cli/commands-readings.ts +19 -8
  19. package/src/adapters/cli/commands-verify.ts +1 -1
  20. package/src/adapters/cli/commands.ts +4 -2
  21. package/src/adapters/cli/export.ts +2 -1
  22. package/src/adapters/cli/install.ts +14 -6
  23. package/src/adapters/cli/mechanisms.ts +1 -1
  24. package/src/adapters/cli/wire.ts +22 -6
  25. package/src/adapters/dashboard/activity.ts +6 -3
  26. package/src/adapters/dashboard/registries.ts +11 -0
  27. package/src/adapters/dashboard/web/flow.ts +3 -0
  28. package/src/adapters/dashboard/web/lanes.ts +4 -0
  29. package/src/adapters/dashboard/web/narrate.ts +23 -0
  30. package/src/adapters/dashboard/web/views/activity.ts +4 -2
  31. package/src/adapters/dashboard/web/views/flow-view.ts +6 -0
  32. package/src/adapters/dashboard/web/views/memory.ts +13 -0
  33. package/src/adapters/dashboard/web/views/shared.ts +2 -1
  34. package/src/adapters/fired.ts +113 -11
  35. package/src/adapters/host-wiring.ts +3 -1
  36. package/src/adapters/lifecycle.ts +36 -9
  37. package/src/adapters/mcp/CONTRACT.md +22 -1
  38. package/src/adapters/mcp/server-args.ts +51 -0
  39. package/src/adapters/mcp/server-session-end.ts +8 -2
  40. package/src/adapters/mcp/server-words.ts +14 -1
  41. package/src/adapters/mcp/server.ts +117 -7
  42. package/src/adapters/mcp/tools.ts +4 -3
  43. package/src/adapters/plugin.ts +1 -0
  44. package/src/adapters/presence.ts +74 -0
  45. package/src/adapters/runtime.ts +258 -8
  46. package/src/adapters/scopes.ts +3 -2
  47. package/src/adapters/spawn.ts +3 -0
  48. package/src/adapters/update-check.ts +1 -1
  49. package/src/adapters/windows-shims.mjs +102 -0
  50. package/src/core/close-hint.ts +297 -0
  51. package/src/core/counterpart-boundary.ts +15 -0
  52. package/src/core/counterpart-deposit.ts +24 -3
  53. package/src/core/counterpart-events.ts +14 -0
  54. package/src/core/counterpart-types.ts +6 -0
  55. package/src/core/counterpart-wake-shape.ts +88 -19
  56. package/src/core/counterpart.ts +143 -7
  57. package/src/core/dream/index.ts +1 -1
  58. package/src/core/dream/reflect.ts +54 -34
  59. package/src/core/encode/NOTES.md +55 -0
  60. package/src/core/encode/secrets.ts +477 -3
  61. package/src/core/event-rollup.ts +175 -0
  62. package/src/core/handoff/CONTRACT.md +7 -0
  63. package/src/core/interference.ts +496 -0
  64. package/src/core/open-close.ts +583 -0
  65. package/src/core/prospective/CONTRACT.md +24 -0
  66. package/src/core/prospective/derive.ts +22 -1
  67. package/src/core/prospective/index.ts +115 -1
  68. package/src/core/recall/CONTRACT.md +9 -2
  69. package/src/core/recall/NOTES.md +99 -0
  70. package/src/core/recall/activate.ts +83 -6
  71. package/src/core/recall/index.ts +75 -5
  72. package/src/core/recall/probe.ts +134 -0
  73. package/src/core/recall/steps.ts +84 -0
  74. package/src/core/recall/tunables.ts +11 -0
  75. package/src/core/reconsolidation.ts +14 -4
  76. package/src/core/remember/CONTRACT.md +2 -1
  77. package/src/core/remember/NOTES.md +15 -0
  78. package/src/core/remember/spans.ts +44 -6
  79. package/src/core/self/NOTES.md +21 -0
  80. package/src/core/self/work.ts +9 -5
  81. package/src/core/sleep/CONTRACT.md +36 -2
  82. package/src/core/sleep/NOTES.md +35 -0
  83. package/src/core/sleep/close.ts +77 -0
  84. package/src/core/sleep/cycle.ts +44 -0
  85. package/src/core/sleep/index.ts +4 -0
  86. package/src/core/sleep/interfere.ts +73 -0
  87. package/src/core/sleep/log.ts +27 -2
  88. package/src/core/sleep/tunables.ts +19 -0
  89. package/src/core/sleep/types.ts +20 -0
  90. package/src/core/store/index.ts +157 -10
  91. package/src/core/store/operational.ts +22 -0
  92. package/src/core/store/owner-op-seam.ts +16 -0
  93. package/src/core/store/reads-history.ts +173 -7
  94. package/src/core/store/reads-memories.ts +253 -4
  95. package/src/core/store/shapes.ts +8 -0
@@ -0,0 +1,269 @@
1
+ /**
2
+ * GROWTH — every growing table has a named exit, and one line here each (FD1
3
+ * step 2, 2026-11-07, Mike's "wherever something is growing, consider fading
4
+ * more"; lightly held, re-read ~3 lived days after install: CHECK-AFTER).
5
+ *
6
+ * One finding per growing thing: how full it is, what came in and what left
7
+ * over the last `GROWTH_WINDOW_DAYS` lived days, and which is faster. The
8
+ * association edges are counted on the `Association` line (`doctor.ts`), not
9
+ * twice. Every line is GREEN: a ratio alone is not a fault (guards loose
10
+ * first), and the numbers are for the person who re-reads them.
11
+ *
12
+ * Not in the session-start reading: the memories line walks every live row.
13
+ */
14
+ import { SHORT_RETENTION_NAMES, EVENTS_ROLLED_EVENT } from "../../core/store/index.js";
15
+ import type { Store } from "../../core/store/index.js";
16
+ import { SLEEP_CYCLE_EVENT } from "../../core/counterpart-events.js";
17
+ import { LOG_SWEEP_EVENT, TUNABLES as SLEEP_TUNABLES } from "../../core/sleep/index.js";
18
+ import { TUNABLES as ASSOCIATE_TUNABLES } from "../../core/associate/index.js";
19
+ import { TUNABLES as PHYSICS_TUNABLES } from "../../core/physics/index.js";
20
+ import { finding, num, payloadOf } from "./doctor-finding.js";
21
+ import type { Finding } from "./doctor-finding.js";
22
+
23
+ /** The window every Growth line reads, in lived days. */
24
+ export const GROWTH_WINDOW_DAYS = 7;
25
+ /** Rows of one name a Growth line reads in its window; a full read is a floor. */
26
+ const GROWTH_ROWS = 5_000;
27
+
28
+ export interface GrowthWindow {
29
+ readonly day: number;
30
+ readonly since: number;
31
+ /** The moment lived day `since` began, or null when the log holds nothing that recent. */
32
+ readonly sinceAt: number | null;
33
+ }
34
+
35
+ export function growthWindow(store: Store): GrowthWindow {
36
+ const day = store.livedDay();
37
+ const since = Math.max(0, day - GROWTH_WINDOW_DAYS + 1);
38
+ return { day, since, sinceAt: store.livedDayStartAt(since) };
39
+ }
40
+
41
+ /** "growing faster than it leaves (+12)", "leaving faster than it grows (−3)", "steady". */
42
+ export function pace(cameIn: number, left: number): string {
43
+ if (cameIn > left) return `growing faster than it leaves (+${String(cameIn - left)})`;
44
+ if (left > cameIn) return `leaving faster than it grows (−${String(left - cameIn)})`;
45
+ return "steady";
46
+ }
47
+
48
+ function n(x: number): string {
49
+ return x.toLocaleString("en-US");
50
+ }
51
+
52
+ function windowWords(): string {
53
+ return `last ${String(GROWTH_WINDOW_DAYS)} lived days`;
54
+ }
55
+
56
+ export function growthFindings(store: Store): Finding[] {
57
+ let w: GrowthWindow;
58
+ try {
59
+ w = growthWindow(store);
60
+ } catch {
61
+ return [];
62
+ }
63
+ const out: Finding[] = [];
64
+ for (const read of [memoriesLine, eventsLine, cuesLine, queueLine]) {
65
+ try {
66
+ const f = read(store, w);
67
+ if (f !== null) out.push(f);
68
+ } catch {
69
+ // One line that will not read costs only itself.
70
+ }
71
+ }
72
+ return out;
73
+ }
74
+
75
+ /** The newest-first rows of `name` in the window. */
76
+ function rowsIn(store: Store, name: string, w: GrowthWindow): ReturnType<Store["eventLog"]> {
77
+ return store.eventLog({ name, sinceDay: w.since, order: "desc", limit: GROWTH_ROWS });
78
+ }
79
+
80
+ // ── memories ────────────────────────────────────────────────────────────────
81
+
82
+ /**
83
+ * Exits: the night's prune (archived after 14 lived days under `PHI_PRUNE`), a
84
+ * merge, a revision's old words, a card's fade. The prune walks a budget of
85
+ * rows a night with a cursor (`sleep/prune.ts`), so a lap of the store takes
86
+ * several nights; the line says how many. Rows the prune never examines are
87
+ * counted apart, each with its own exit: the journal has none, by contract
88
+ * (`sleep/CONTRACT.md` guarantee 15).
89
+ */
90
+ function memoriesLine(store: Store, w: GrowthWindow): Finding {
91
+ const c = store.reachCensus();
92
+ const flow = w.sinceAt === null ? { born: 0, archived: 0 } : store.memoryFlow(w.since, w.sinceAt);
93
+ let pruned = 0;
94
+ let merged = 0;
95
+ let faded = 0;
96
+ let lastPrune: { exhausted: boolean; left: number } | null = null;
97
+ for (const row of rowsIn(store, SLEEP_CYCLE_EVENT, w)) {
98
+ const p = payloadOf(row);
99
+ pruned += num(p, "pruned") ?? 0;
100
+ merged += num(p, "merged") ?? 0;
101
+ faded += num(p, "faded") ?? 0;
102
+ if (lastPrune !== null || !Array.isArray(p["phases"])) continue;
103
+ for (const ph of p["phases"] as unknown[]) {
104
+ if (ph === null || typeof ph !== "object") continue;
105
+ const e = ph as Record<string, unknown>;
106
+ if (e["phase"] !== "prune" || typeof e["budgetExhausted"] !== "boolean") continue;
107
+ lastPrune = { exhausted: e["budgetExhausted"], left: num(e, "skippedForBudget") ?? 0 };
108
+ }
109
+ }
110
+ const budget = SLEEP_TUNABLES.BUDGETS.prune;
111
+ const lap = lastPrune === null ? null : Math.max(1, Math.ceil((budget + lastPrune.left) / budget));
112
+ const pruneSaid =
113
+ lastPrune === null
114
+ ? "the prune has not run in the window"
115
+ : lastPrune.exhausted
116
+ ? `the prune's last pass used its whole budget (${n(budget)} rows) and left ${n(lastPrune.left)} unexamined: one lap of the store takes ~${String(lap)} nights`
117
+ : `the prune's last pass reached every row (budget ${n(budget)})`;
118
+ const x = c.exempt;
119
+ const detail =
120
+ `${n(c.live)} live: ${n(c.inReach)} in reach, ${n(c.belowReach)} below reach, of them ${n(c.underFloor)} under the prune floor (they wait ${String(PHYSICS_TUNABLES.D_FLOOR_DAYS)} lived days there, then the prune may take them)` +
121
+ (c.unranked > 0 ? `; ${n(c.unranked)} not ranked yet` : "") +
122
+ `. ${windowWords()}: ${n(flow.born)} born, ${n(flow.archived)} left (night: ${n(pruned)} pruned, ${n(merged)} merged, ${n(faded)} cards faded), ${pace(flow.born, flow.archived)}; ${pruneSaid}` +
123
+ `. Not the prune's: journal ${n(x.journal)} (no exit, by contract), chapter copies ${n(x.chapterCopies)} (replaced when a chapter is re-minted), handoffs ${n(x.handoffs)} (cleared or expired), cards ${n(x.cards)} (fade, not before their calendar floor)` +
124
+ (x.selfPage > 0 ? `, self page ${n(x.selfPage)}` : "");
125
+ return finding("growth-memories", "green", "Growth: memories", detail, "", {
126
+ live: c.live,
127
+ inReach: c.inReach,
128
+ belowReach: c.belowReach,
129
+ underFloor: c.underFloor,
130
+ unranked: c.unranked,
131
+ born: flow.born,
132
+ left: flow.archived,
133
+ pruned,
134
+ merged,
135
+ faded,
136
+ pruneBudgetExhausted: lastPrune?.exhausted ?? null,
137
+ pruneUnexamined: lastPrune?.left ?? null,
138
+ pruneLapNights: lap,
139
+ journal: x.journal,
140
+ chapterCopies: x.chapterCopies,
141
+ handoffs: x.handoffs,
142
+ cards: x.cards,
143
+ selfPage: x.selfPage,
144
+ floor: PHYSICS_TUNABLES.PHI_PRUNE,
145
+ });
146
+ }
147
+
148
+ // ── the event log ───────────────────────────────────────────────────────────
149
+
150
+ /**
151
+ * Exit: the night's log sweep (`sleep/log.ts`), oldest first, capped. The
152
+ * per-turn names (`SHORT_RETENTION_NAMES`) keep the short window and are
153
+ * rolled into one latched `events.rolled` row a lived day first; every other
154
+ * unlatched row keeps the store's `retentionDays`. Latched records (prunes,
155
+ * promotions, merges, the roll-ups) are kept at any age, by design.
156
+ */
157
+ function eventsLine(store: Store, w: GrowthWindow): Finding {
158
+ const census = store.eventLogCensus();
159
+ const sizes = store.eventLogBytes();
160
+ const all = store.eventCounts();
161
+ const recent = store.eventCounts({ sinceDay: w.since });
162
+ const cameIn = recent.filter((c) => c.name !== EVENTS_ROLLED_EVENT).reduce((s, c) => s + c.count, 0);
163
+ let left = 0;
164
+ let remaining: number | null = null;
165
+ let rolled = 0;
166
+ for (const row of rowsIn(store, LOG_SWEEP_EVENT, w)) {
167
+ const p = payloadOf(row);
168
+ left += num(p, "count") ?? 0;
169
+ rolled += num(p, "rolled") ?? 0;
170
+ remaining ??= num(p, "remaining");
171
+ }
172
+ const top = [...all].sort((a, b) => b.count - a.count).slice(0, 5);
173
+ const short = new Set(SHORT_RETENTION_NAMES);
174
+ const shortRows = all.filter((c) => short.has(c.name)).reduce((s, c) => s + c.count, 0);
175
+ const mb = (sizes.bytes / 1_048_576).toFixed(1);
176
+ const detail =
177
+ `${n(census.rows)} rows, ${sizes.exact ? "" : "~"}${mb} MB (${n(census.latched)} latched records, kept at any age); ` +
178
+ `per-turn rows (${SHORT_RETENTION_NAMES.join(", ")}: ${n(shortRows)}) keep ${String(census.shortRetentionDays)} lived days and are rolled into one row a day first, the rest ${String(census.retentionDays)}` +
179
+ (census.oldestDay === null ? "" : `; oldest lived day ${String(census.oldestDay)}`) +
180
+ `. ${windowWords()}: ${n(cameIn)} written, ${n(left)} swept` +
181
+ (rolled > 0 ? `, ${n(rolled)} days rolled up` : "") +
182
+ `, ${pace(cameIn, left)}` +
183
+ (census.eligible > 0 ? `; ${n(census.eligible)} past the window wait for the next pass` : "") +
184
+ (top.length === 0 ? "" : `. Largest: ${top.map((c) => `${c.name} ${n(c.count)}`).join(", ")}`);
185
+ const data: Record<string, string | number | boolean | null> = {
186
+ rows: census.rows,
187
+ bytes: sizes.bytes,
188
+ bytesExact: sizes.exact,
189
+ latched: census.latched,
190
+ retentionDays: census.retentionDays,
191
+ shortRetentionDays: census.shortRetentionDays,
192
+ shortRows,
193
+ written: cameIn,
194
+ swept: left,
195
+ rolledDays: rolled,
196
+ eligible: census.eligible,
197
+ lastRemaining: remaining,
198
+ };
199
+ for (const c of all) if (short.has(c.name) || c.name === EVENTS_ROLLED_EVENT) data[`count:${c.name}`] = c.count;
200
+ return finding("growth-events", "green", "Growth: event log", detail, "", data);
201
+ }
202
+
203
+ // ── cue pairs ───────────────────────────────────────────────────────────────
204
+
205
+ /**
206
+ * Exit: each pair fades (`S_CUE` lived days, exponential) and the flush's
207
+ * sweep drops one under `CUE_FLOOR`, or one whose memory left. No count cap,
208
+ * by design: a word's pairs scale down together past `CUE_MAX_OUT` (weight,
209
+ * not a cut). Silent on a store without the table.
210
+ */
211
+ function cuesLine(store: Store, w: GrowthWindow): Finding | null {
212
+ const counts = store.growthCounts(w.sinceAt ?? Number.MAX_SAFE_INTEGER).cues;
213
+ if (counts === null) return null;
214
+ let swept = 0;
215
+ for (const row of rowsIn(store, "associate.flush", w)) swept += num(payloadOf(row), "cueSwept") ?? 0;
216
+ const t = ASSOCIATE_TUNABLES;
217
+ const life = Math.round(t.S_CUE * Math.log(t.CUE_W_CAP / t.CUE_FLOOR));
218
+ const detail =
219
+ `${n(counts.rows)} word-to-memory pairs. ${windowWords()}: ${n(counts.recent)} new, ${n(swept)} swept, ${pace(counts.recent, swept)}` +
220
+ `; an unused pair fades over ${String(t.S_CUE)} lived days and goes under the floor in at most ~${String(life)}, or when its memory leaves`;
221
+ return finding("growth-cues", "green", "Growth: cue pairs", detail, "", {
222
+ rows: counts.rows,
223
+ recent: counts.recent,
224
+ swept,
225
+ fadeDays: t.S_CUE,
226
+ longestLifeDays: life,
227
+ });
228
+ }
229
+
230
+ // ── the dream queue ─────────────────────────────────────────────────────────
231
+
232
+ /**
233
+ * Exit: a queued memory leaves when a dream that stands is shown it, or when
234
+ * its own curve takes it below reach (`agedOut`); the queue and forgetting
235
+ * share one clock (`dream/tunables.ts`). Read from the `dream.begun` rows.
236
+ */
237
+ function queueLine(store: Store, w: GrowthWindow): Finding | null {
238
+ const rows = rowsIn(store, "dream.begun", w).filter((r) => payloadOf(r)["resumed"] !== true);
239
+ if (rows.length === 0) return null;
240
+ const newest = payloadOf(rows[0]);
241
+ const oldest = payloadOf(rows[rows.length - 1]);
242
+ const queue = num(newest, "queue") ?? 0;
243
+ let shown = 0;
244
+ let agedOut = 0;
245
+ for (const r of rows) {
246
+ const p = payloadOf(r);
247
+ shown += num(p, "shown") ?? 0;
248
+ agedOut += num(p, "agedOut") ?? 0;
249
+ }
250
+ // BETWEEN THE OLDEST NIGHT READ AND THE NEWEST: each row's `queue` is the
251
+ // length as that dream began; what it was shown leaves after it, and
252
+ // `agedOut` counts what fell below reach since the dream before it. So what
253
+ // left between the two lengths is every night's shown but the newest's,
254
+ // plus every night's agedOut but the oldest's, and what came in is the
255
+ // change in length plus that.
256
+ const leftAfterFirst = shown - (num(newest, "shown") ?? 0) + agedOut - (num(oldest, "agedOut") ?? 0);
257
+ const cameIn = Math.max(0, queue - (num(oldest, "queue") ?? queue) + leftAfterFirst);
258
+ const detail =
259
+ `${n(queue)} memories wait to be dreamed (${n(num(newest, "waiting") ?? 0)} not shown last night). ${windowWords()}, ${String(rows.length)} ${rows.length === 1 ? "night" : "nights"}: ${n(shown)} shown to a dream, ${n(agedOut)} fell below reach undreamed` +
260
+ (rows.length > 1 ? `, ${pace(cameIn, leftAfterFirst)}` : "");
261
+ return finding("growth-queue", "green", "Growth: dream queue", detail, "", {
262
+ queue,
263
+ waiting: num(newest, "waiting"),
264
+ nights: rows.length,
265
+ shown,
266
+ agedOut,
267
+ cameIn: rows.length > 1 ? cameIn : null,
268
+ });
269
+ }
@@ -145,7 +145,7 @@ function byUse(a: string, b: string): number {
145
145
  * want) as the fix, since it rewrites the commands with the runtime running it.
146
146
  * Quiet when nothing of ours is configured: the Claude Code line says that.
147
147
  */
148
- export function runtimeFindings(reading: HostReading): Finding[] {
148
+ export function runtimeFindings(reading: HostReading, platform: string = process.platform): Finding[] {
149
149
  const rows = reading.runtimes ?? [];
150
150
  if (rows.length === 0) return [];
151
151
  const said = rows
@@ -185,6 +185,24 @@ export function runtimeFindings(reading: HostReading): Finding[] {
185
185
  ),
186
186
  ];
187
187
  }
188
+ // WINDOWS (W1 review): a hook line naming Node by a path that needs quotes
189
+ // runs in only one of Claude Code's two shells there; amber, so a later Git
190
+ // for Windows install or removal that breaks every hook has a line to point at.
191
+ if (missing.length === 0 && platform === "win32") {
192
+ const oneShell = rows.find((r) => !r.used.every((u) => u === "desktop") && r.kind !== "binary" && /[^A-Za-z0-9_.:/+\\-]/.test(r.exe));
193
+ if (oneShell !== undefined) {
194
+ return [
195
+ finding(
196
+ "runtime",
197
+ "amber",
198
+ "Runtime",
199
+ `${said}${console_}; the hooks name Node by a path that needs quotes (\`node\` on PATH is another file, such as a version manager's shim), so their line runs in only one of Git Bash and PowerShell — the one Claude Code used when they were written. Installing or removing Git for Windows since then stops every hook.`,
200
+ "Put the Node you want first on PATH, then run: counterparts connect. Then restart Claude Code.",
201
+ data,
202
+ ),
203
+ ];
204
+ }
205
+ }
188
206
  if (missing.length === 0) return [finding("runtime", "green", "Runtime", `${said}${console_}`, "", data)];
189
207
  return [
190
208
  finding(
@@ -0,0 +1,84 @@
1
+ /**
2
+ * `doctor`'s `Recall steps` line (LT2 part 1, 2026-11-09): the week's median
3
+ * ms for each step of a recall pass, largest first, read off the `steps` the
4
+ * `recall.decision` rows carry (`core/recall/steps.ts`). The 11-07 read saw the
5
+ * pass's p50 double in six lived days with candidates flat; this line is how
6
+ * the growing step gets named. One bounded event read; informational, green.
7
+ */
8
+ import { STEP_NAMES } from "../../core/recall/index.js";
9
+ import type { Store } from "../../core/store/index.js";
10
+ import { finding, num, payloadOf } from "./doctor-finding.js";
11
+ import type { Finding } from "./doctor-finding.js";
12
+
13
+ /** How far back the line reads turns, in lived days. */
14
+ export const RECALL_STEPS_WINDOW_DAYS = 7;
15
+ /** The newest turns read at most; past it the medians are of these. */
16
+ const RECALL_STEPS_ROWS = 5_000;
17
+ /** Steps named on the line, largest median first; all of them go in `--json`. */
18
+ const RECALL_STEPS_SHOWN = 8;
19
+
20
+ /** The median, the lower middle of an even count; NaN for none. */
21
+ function p50(xs: number[]): number {
22
+ if (xs.length === 0) return Number.NaN;
23
+ const sorted = [...xs].sort((a, b) => a - b);
24
+ return sorted[Math.ceil(sorted.length / 2) - 1] as number;
25
+ }
26
+
27
+ function ms(x: number): string {
28
+ return x >= 10 ? String(Math.round(x)) : x.toFixed(1);
29
+ }
30
+
31
+ export function recallStepFindings(store: Store): Finding[] {
32
+ const byStep = new Map<string, number[]>();
33
+ const builds: number[] = [];
34
+ let turns = 0;
35
+ let unread = false;
36
+ try {
37
+ const since = Math.max(0, store.livedDay() - RECALL_STEPS_WINDOW_DAYS);
38
+ const rows = store.eventLog({ name: "recall.decision", sinceDay: since, order: "desc", limit: RECALL_STEPS_ROWS });
39
+ unread = rows.length >= RECALL_STEPS_ROWS;
40
+ for (const row of rows) {
41
+ const p = payloadOf(row);
42
+ const steps = p["steps"];
43
+ if (steps === null || typeof steps !== "object") continue;
44
+ turns += 1;
45
+ const elapsed = num(p, "elapsedMs");
46
+ if (elapsed !== null) builds.push(elapsed);
47
+ for (const [name, v] of Object.entries(steps as Record<string, unknown>)) {
48
+ if (typeof v !== "number" || !Number.isFinite(v)) continue;
49
+ const list = byStep.get(name);
50
+ if (list === undefined) byStep.set(name, [v]);
51
+ else list.push(v);
52
+ }
53
+ }
54
+ } catch {
55
+ return [];
56
+ }
57
+ const window = `last ${String(RECALL_STEPS_WINDOW_DAYS)} lived days`;
58
+ if (turns === 0) {
59
+ return [finding("recall-steps", "green", "Recall steps", `${window}: no timed recall turns yet`, "", { turns: 0 })];
60
+ }
61
+ // Known steps in the pass's order, then anything a newer build named.
62
+ const known = new Set<string>(STEP_NAMES);
63
+ const names = [...STEP_NAMES.filter((n) => byStep.has(n)), ...[...byStep.keys()].filter((n) => !known.has(n)).sort()];
64
+ const medians = names.map((name) => ({ name, p50: p50(byStep.get(name) ?? []) }));
65
+ const largest = [...medians].sort((a, b) => b.p50 - a.p50 || names.indexOf(a.name) - names.indexOf(b.name)).slice(0, RECALL_STEPS_SHOWN);
66
+ const build = p50(builds);
67
+ const data: Record<string, string | number | boolean | null> = { turns, unread };
68
+ if (builds.length > 0) data["elapsedMsP50"] = build;
69
+ for (const m of medians) data[`p50.${m.name}`] = m.p50;
70
+ return [
71
+ finding(
72
+ "recall-steps",
73
+ "green",
74
+ "Recall steps",
75
+ `${window}, ${String(turns)} timed ${turns === 1 ? "turn" : "turns"}` +
76
+ (builds.length > 0 ? `, whole build p50 ${ms(build)} ms` : "") +
77
+ ` — p50 ms by step, largest first: ${largest.map((m) => `${m.name} ${ms(m.p50)}`).join(", ")}` +
78
+ " (embed and the other steps before the build, and record after it, are outside the build's time)" +
79
+ (unread ? `. Only the newest ${String(RECALL_STEPS_ROWS)} turns were read` : ""),
80
+ "",
81
+ data,
82
+ ),
83
+ ];
84
+ }
@@ -92,6 +92,7 @@ import type { AskReason } from "../../core/self/episodes.js";
92
92
  // dashboard's health panel so the three cannot disagree about what "silent"
93
93
  // means (constitution 16, the same rule this module already keeps for "healthy").
94
94
  import { STATE_MEANING, daysBetween, firedReport } from "../fired.js";
95
+ import { PLAIN_CROSS_AFTER_LIVED_DAYS } from "../../core/prospective/index.js";
95
96
  // The one name the "no configuration was read" line needs, from the module that
96
97
  // owns it — so the sentence here and the refusal it replaced name the same var.
97
98
  import { CONFIG_ENV } from "../config-path.js";
@@ -165,10 +166,12 @@ import {
165
166
  } from "./doctor-self-page.js";
166
167
  import { denyFindings, hostFindings, runtimeFindings, desktopFindings } from "./doctor-host.js";
167
168
  import { modesFindings } from "./doctor-modes.js";
169
+ import { recallStepFindings } from "./doctor-recall-steps.js";
168
170
  import type { HostReading, DesktopReading } from "./doctor-host.js";
169
171
  import { owedFolders, readOwed, crashWriteUpFindings, nightHeldFindings, overdueWords } from "./doctor-write-ups.js";
170
172
  import type { OwedSource, OwedReading } from "./doctor-write-ups.js";
171
173
  import { worstFirst } from "./doctor-report.js";
174
+ import { growthFindings } from "./doctor-growth.js";
172
175
  import { feedbackLoopFindings } from "./doctor-feedback.js";
173
176
  import { starterNotes } from "../../core/told.js";
174
177
 
@@ -1715,6 +1718,12 @@ function firedFindings(input: DoctorInput, store: Store): Finding[] {
1715
1718
  report.heldBack === 0 || report.missedOccasion.length > 0
1716
1719
  ? ""
1717
1720
  : ` ${report.heldBack === 1 ? "1 plain reminder is" : `${String(report.heldBack)} plain reminders are`} held back, ${report.heldBack === 1 ? "its folder" : "their folders"} not on: said if turned on within a week of the day, and not after.`;
1721
+ // DUE WHILE ITS FOLDER HAD NO SESSION (SO1 step 3 fix round): info, not a fault.
1722
+ // It is said in its folder, or elsewhere once, two lived days past its day.
1723
+ const homeless =
1724
+ (report.homelessPlain ?? 0) === 0
1725
+ ? ""
1726
+ : ` ${report.homelessPlain === 1 ? "1 plain reminder was" : `${String(report.homelessPlain)} plain reminders were`} due while ${report.homelessPlain === 1 ? "its folder" : "their folders"} had no session: said there, or in the next session elsewhere ${String(PLAIN_CROSS_AFTER_LIVED_DAYS)} lived days after.`;
1718
1727
  // TOO NEW TO GRADE (2026-09-20, finding 2). On a store younger than a lived
1719
1728
  // day or two, "28 have never fired" is a true sentence that reads like a
1720
1729
  // broken install — nothing has fired because nothing has happened yet. One
@@ -1744,7 +1753,7 @@ function firedFindings(input: DoctorInput, store: Store): Finding[] {
1744
1753
  "fired",
1745
1754
  "green",
1746
1755
  "Fired",
1747
- `${roll}. Nothing that fired last week has fallen silent this week.${held}`,
1756
+ `${roll}. Nothing that fired last week has fallen silent this week.${held}${homeless}`,
1748
1757
  "",
1749
1758
  data,
1750
1759
  ),
@@ -1766,7 +1775,7 @@ function firedFindings(input: DoctorInput, store: Store): Finding[] {
1766
1775
  "fired",
1767
1776
  "amber",
1768
1777
  "Fired",
1769
- `${roll}. ${changed.join(". ")}${held === "" ? "" : `.${held}`}`,
1778
+ `${roll}. ${changed.join(". ")}${held === "" ? "" : `.${held}`}${homeless === "" ? "" : `.${homeless}`}`,
1770
1779
  report.wentBlocked.length > 0
1771
1780
  ? `Run: counterparts mechanisms --all — ${STATE_MEANING.blocked}, and the reason on the row names what to fix.`
1772
1781
  : report.missedOccasion.length > 0
@@ -3215,6 +3224,8 @@ export function associationFindings(store: Store): Finding[] {
3215
3224
  let contiguityExcluded = 0;
3216
3225
  let contiguityLost = 0;
3217
3226
  let contiguityFailed = 0;
3227
+ let edgesSwept = 0;
3228
+ let edgesRecent = 0;
3218
3229
  const census = { total: 0, conducting: 0, gist: 0, dream: 0, hebbian: 0 };
3219
3230
  try {
3220
3231
  const rows = store.eventLog({ name: "recall.decision", sinceDay: since, order: "desc", limit: ASSOCIATION_ROWS });
@@ -3245,6 +3256,8 @@ export function associationFindings(store: Store): Finding[] {
3245
3256
  // at the nodes it touched, those nodes scaled back — from their own
3246
3257
  // `associate.flush` rows (review of #281, findings 2 and 9).
3247
3258
  for (const row of store.eventLog({ name: "associate.flush", sinceDay: since, order: "desc", limit: ASSOCIATION_ROWS })) {
3259
+ // FD1 step 2: the edges' exit, the flush's sweep (faded under the floor, or an end gone for good).
3260
+ edgesSwept += num(payloadOf(row), "swept") ?? 0;
3248
3261
  const c = payloadOf(row)["contiguity"];
3249
3262
  if (c === null || typeof c !== "object") continue;
3250
3263
  const cr = c as Record<string, unknown>;
@@ -3265,6 +3278,8 @@ export function associationFindings(store: Store): Finding[] {
3265
3278
  if (c.action === "link" && c.ref2 !== null) dreamPairs.add(pairKey(c.ref, c.ref2));
3266
3279
  }
3267
3280
  }
3281
+ const sinceAt = store.livedDayStartAt(since);
3282
+ if (sinceAt !== null) edgesRecent = store.edgeGrowth(sinceAt).recent;
3268
3283
  for (const e of store.allEdges()) {
3269
3284
  census.total += 1;
3270
3285
  if (!isDead({ src: e.src, dst: e.dst, weight: e.weight, lastDay: e.last_day }, day, ASSOCIATE_TUNABLES)) census.conducting += 1;
@@ -3285,7 +3300,7 @@ export function associationFindings(store: Store): Finding[] {
3285
3300
  "association",
3286
3301
  "green",
3287
3302
  "Association",
3288
- `${spreadSaid}. Edges: ${String(census.total)} rows, ${String(census.conducting)} conducting — ${String(census.hebbian)} learned from use or contiguity, ${String(census.dream)} dream links, ${String(census.gist)} gist ties (derived: a row touching a dream's gist is a gist tie, a pair a dream linked is a dream link, the rest were learned from use or from memories made next to each other)` +
3303
+ `${spreadSaid}. Edges: ${String(census.total)} rows, ${String(census.conducting)} conducting — ${String(census.hebbian)} learned from use or contiguity, ${String(census.dream)} dream links, ${String(census.gist)} gist ties (derived: a row touching a dream's gist is a gist tie, a pair a dream linked is a dream link, the rest were learned from use or from memories made next to each other); this window ${String(edgesRecent)} new, ${String(edgesSwept)} swept (an unused edge fades over ${String(ASSOCIATE_TUNABLES.S_EDGE)} lived days; a memory holds at most ${String(ASSOCIATE_TUNABLES.MAX_EDGES_PER_NODE)})` +
3289
3304
  `. Temporal contiguity buffered ${String(contiguityPairs)} ${contiguityPairs === 1 ? "pair" : "pairs"} of neighbouring memories at the boundaries, ${String(contiguityLanded)} landed as links; it pushed out ${String(contiguityEvictedOther)} other ${contiguityEvictedOther === 1 ? "link" : "links"} and scaled back ${String(contiguityScaled)} ${contiguityScaled === 1 ? "memory's" : "memories'"} links at full memories; ${String(contiguityExcluded)} ${contiguityExcluded === 1 ? "memory" : "memories"} the nightly run wrote left out` +
3290
3305
  (contiguityFailed > 0 ? `; the pass failed at ${String(contiguityFailed)} ${contiguityFailed === 1 ? "boundary" : "boundaries"}` : "") +
3291
3306
  (contiguityLost > 0 ? `; ${String(contiguityLost)} planned ${contiguityLost === 1 ? "pair was" : "pairs were"} lost before a flush recorded them` : "") +
@@ -3314,6 +3329,8 @@ export function associationFindings(store: Store): Finding[] {
3314
3329
  hebbian: census.hebbian,
3315
3330
  dreamLinks: census.dream,
3316
3331
  gistTies: census.gist,
3332
+ edgesRecent,
3333
+ edgesSwept,
3317
3334
  floor: unread,
3318
3335
  },
3319
3336
  ),
@@ -3664,8 +3681,14 @@ export function doctorFindings(input: DoctorInput): Finding[] {
3664
3681
  ["claim", () => claimFindings(store, input.host?.plugin ?? null)],
3665
3682
  // Association build 1 (2026-09-28): what spreading did, and the edges.
3666
3683
  ["association", () => associationFindings(store)],
3684
+ // LT2 part 1 (2026-11-09): the week's p50 per recall step. One bounded
3685
+ // event read, never red: not at session start.
3686
+ ...(input.budgetMs !== undefined ? [] : [["recall-steps", (): Finding[] => recallStepFindings(store)] as const]),
3667
3687
  // The feedback loop (2026-10-19, an experiment): ratings as use, co-use links, habituation.
3668
3688
  ["feedback-loop", () => feedbackLoopFindings(store)],
3689
+ // FD1 step 2 (2026-11-07): every growing table, how full, in against out.
3690
+ // Not in the session-start reading: the memories line walks every live row.
3691
+ ...(input.budgetMs !== undefined ? [] : [["growth", (): Finding[] => growthFindings(store)] as const]),
3669
3692
  // LAST, and deliberately: it is the widest read here — the whole event log,
3670
3693
  // plus a pass over the ids for the table probes — so when the console's
3671
3694
  // reading is cut short this is the group that goes, and the `Budget` finding
@@ -76,6 +76,7 @@ import type { LifecycleOptions, PlainLines, SessionInput } from "../lifecycle.js
76
76
 
77
77
  import { localDate } from "../../core/time.js";
78
78
  import { openThread } from "../../core/self/identity.js";
79
+ import { isDirectoryScope, projectFolder } from "../../core/self/work.js";
79
80
  import { TUNABLES } from "../config.js";
80
81
  import { TUNABLES as RECALL_TUNABLES } from "../../core/recall/tunables.js";
81
82
  import { SESSION_NOTICE_BUDGET_MS, checkoutIsGraded, doctorFindings, noticeMessage, readCheckout, wakeMeaningLine } from "./doctor.js";
@@ -761,7 +762,8 @@ export class ClaudeCodeAdapter extends Lifecycle {
761
762
  // reminders and both asks. What actually gave way is recorded by the
762
763
  // delivery (`noteGaveWay`) and by each ask's own deferral.
763
764
  const watched = watchedAtStart(input);
764
- const plain = watched ? this.plainFor(input) : NO_PLAIN;
765
+ // A session start is where an unsaid folder's reminder may cross (SO1 step 3), never a prompt.
766
+ const plain = watched ? this.plainFor(input, { cross: true }) : NO_PLAIN;
765
767
  // DESKTOP'S CODE TAB (2026-10-01): one line, right under the clock,
766
768
  // naming this session's id — there the counterparts tools the model sees
767
769
  // are Claude Desktop's server, which serves a call as this session only
@@ -858,6 +860,10 @@ export class ClaudeCodeAdapter extends Lifecycle {
858
860
  // Not `watched`: the fired report marks a session unattended for good
859
861
  // on any start that says so, and a person's session compacts too.
860
862
  interactive: isInteractive(input) && input.nightRun !== true,
863
+ // THE FOLDER IT STARTED IN (SO1 step 3, round 3 of #780): doctor's "was its
864
+ // folder there" and the crossing's lived days read this row, not the session
865
+ // registry, which prunes a week after a session ends. Null for a host's name scope.
866
+ folder: isDirectoryScope(input.scope) ? projectFolder(input.scope) : null,
861
867
  // A resume's short wake (2026-10-11): `bytes` is the line, not a bundle.
862
868
  resumed,
863
869
  // How many items it listed as a line (#489 C): doctor's Lookups line
@@ -431,3 +431,21 @@ really closes; a hook turn measured the same before and after. `store/NOTES.md`,
431
431
  Claude Code session once the hosted connector is added (a RUNBOOK §7 step at deploy).
432
432
  - **A plugin-only install gets no deny entry and no doctor line for it.** The plugin wires
433
433
  nothing in `settings.json`, and its `connect` would wire the host a second time.
434
+
435
+ ## Windows, left after W1 (2026-11-09)
436
+
437
+ The npm door works on native Windows (CI's `windows` workflow). What the audit found and W1 did not fix, none of it on
438
+ the install → connect → wake → recall → night path:
439
+
440
+ - **No process look.** `realProcessLister` runs `ps`, which Windows doesn't have, so `uninstall`, `start-fresh` and
441
+ `connect`'s server census see `NO_LOOK` ("could not check"). A `Get-CimInstance Win32_Process` lister would bring it
442
+ back.
443
+ - **Renaming an open store.** SQLite on Windows holds its files without share-delete, so `claim.ts`'s park,
444
+ `rollback`, `start-fresh`, `uninstall --park` can fail with EBUSY/EPERM while a session, the worker or an MCP server
445
+ has the store open. They should say "quit Claude Code first" and treat EBUSY as "something is still running".
446
+ - **Path prefix checks with `/`.** `plugin.ts` (plugin-route detection), `wire.ts#inPlugin`, `host-wiring.ts` (the
447
+ plugin stand-down's path test), `core/counterpart-projects.ts` (the folder-is-the-store refusal) and
448
+ `core/dream/project-ask.ts` test `${dir}/` prefixes, which a `C:\…` path never has. The plugin route is not the
449
+ Windows front door; the projects refusal fails open.
450
+ - **Drive-letter case.** `realpathSync` keeps `c:` vs `C:`, so one folder typed two ways can be two scopes.
451
+ - **`~` shortening** in display text only knows `/`; Windows shows full paths.
@@ -2117,3 +2117,27 @@ door the plugin's `/counterparts:uninstall` drives.
2117
2117
  umask, and so are our own children (`spawn.ts`, the plugin's first run, the plugin
2118
2118
  console's hand-off), which set 077 themselves: before, the night's `claude -p` inherited
2119
2119
  077 from a hook and wrote Claude Code's own files 0600.
2120
+
2121
+ ## 2026-11-09 — Windows: the console from PowerShell, and `claude.cmd` (W1)
2122
+
2123
+ - **The four commands didn't start from PowerShell or cmd.** npm's Windows launchers are written from the bin's first
2124
+ line, `#!/bin/sh` for our polyglot bins, so `counterparts.cmd`/`.ps1` ran `/bin/sh`. The first line can't name Node:
2125
+ macOS and Linux read the same line, and a Bun-only machine would lose the console. So `package.json#scripts.postinstall`
2126
+ runs `src/adapters/windows-shims.mjs`, which on win32 only rewrites the `.cmd` and `.ps1` npm wrote for THIS package's
2127
+ four bins to run `node`, and nothing else (it returns at once elsewhere, and never fails the install). Only for a
2128
+ GLOBAL install (`npm_config_global`), only in the global prefix, and only a file with npm's exact shim target line
2129
+ (`read-cmd-shim`'s regex) naming this package's bin for that name: the review of #787 found the first version would
2130
+ rewrite a project's own `counterparts.cmd` on a local `npm i counterparts`. npm links bins
2131
+ before `postinstall` (arborist `rebuild.js`). This is the package's first install script; it touches only npm's own
2132
+ launchers for our bins, never a host's settings. With `--ignore-scripts` it doesn't run, and the commands still work
2133
+ from Git Bash.
2134
+ - **`claude mcp add` from `connect`.** An npm install of Claude Code is `claude.cmd`, which Node won't spawn without a
2135
+ shell (EINVAL since 20.12), and a shell would re-read the store path. `realSpawner` asks `runtime.ts#windowsLaunch`,
2136
+ which reads the shim's target and spawns that (`.exe`) or `node <target>` (`.js`), arguments kept one each. A native
2137
+ `claude.exe` is spawned as is.
2138
+ - `claudeOnPath` (doctor's hint) checks PATHEXT on win32 rather than an exec bit Windows doesn't have.
2139
+ - A project argument `C:\…` or `dir\sub` names a folder (`looksLikeFolder`); the dashboard opens with `explorer.exe`.
2140
+ - What isn't done on Windows yet: `ps` doesn't exist, so the "is something still running" look before `uninstall` or
2141
+ `start-fresh` is a look that didn't happen (`NO_LOOK`, as it always handled); and renaming a store a running server has
2142
+ open can fail there (EBUSY), where macOS lets it; nothing yet turns that error into "quit Claude Code first"
2143
+ (open in `INTERFACE-GAPS.md`).
@@ -250,13 +250,21 @@ function realDashboard(env: Record<string, string | undefined>): DashboardSeam {
250
250
  * the screen, and a person who can read it can paste it.
251
251
  */
252
252
  function openInBrowser(url: string, env: Record<string, string | undefined>): void {
253
+ // Windows: `explorer.exe <url>` opens the default browser, no shell needed (W1).
253
254
  const opener =
254
- process.platform === "darwin" ? "open" : process.platform === "linux" ? "xdg-open" : null;
255
+ process.platform === "darwin"
256
+ ? "open"
257
+ : process.platform === "linux"
258
+ ? "xdg-open"
259
+ : process.platform === "win32"
260
+ ? "explorer.exe"
261
+ : null;
255
262
  if (opener === null) return;
256
263
  try {
257
264
  const child = withHostUmask(() =>
258
265
  spawn(opener, [url], {
259
266
  detached: true,
267
+ windowsHide: true,
260
268
  stdio: "ignore",
261
269
  env: env as NodeJS.ProcessEnv,
262
270
  }),
@@ -18,7 +18,8 @@ import type { Io, Parsed } from "./commands-shared.js";
18
18
 
19
19
  /** A typed project argument that names a folder rather than a project by name. */
20
20
  function looksLikeFolder(word: string): boolean {
21
- return word.startsWith("/") || word.startsWith("~") || word.startsWith(".") || word.includes("/");
21
+ // `C:\…` and `dir\sub` on Windows (W1).
22
+ return word.startsWith("/") || word.startsWith("~") || word.startsWith(".") || word.includes("/") || /^[A-Za-z]:[\\/]/.test(word) || word.includes("\\");
22
23
  }
23
24
 
24
25
  /** The folder as the hooks record it: resolved, real, no trailing slash. */