counterparts 0.3.26 → 0.3.28

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 (103) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/docs/QUICKSTART.md +6 -0
  3. package/docs/README.md +3 -1
  4. package/package.json +1 -1
  5. package/src/adapters/claude-code/CONTRACT.md +21 -3
  6. package/src/adapters/claude-code/bin/hook.ts +2 -0
  7. package/src/adapters/claude-code/bin/runner.ts +46 -1
  8. package/src/adapters/claude-code/doctor-feedback.ts +104 -0
  9. package/src/adapters/claude-code/doctor.ts +19 -4
  10. package/src/adapters/claude-code/embed-client.ts +16 -1
  11. package/src/adapters/claude-code/hooks.ts +25 -6
  12. package/src/adapters/claude-code/night-run.ts +8 -0
  13. package/src/adapters/claude-code/transcript.ts +28 -1
  14. package/src/adapters/claude-code/vectors.ts +6 -0
  15. package/src/adapters/cli/CONTRACT.md +7 -0
  16. package/src/adapters/cli/commands-note.ts +8 -0
  17. package/src/adapters/cli/commands-readings.ts +1 -1
  18. package/src/adapters/cli/commands-self.ts +53 -1
  19. package/src/adapters/cli/commands.ts +18 -0
  20. package/src/adapters/cli/dream-core.ts +16 -6
  21. package/src/adapters/cli/help.ts +5 -1
  22. package/src/adapters/dashboard/CONTRACT.md +5 -2
  23. package/src/adapters/dashboard/registries.ts +3 -3
  24. package/src/adapters/dashboard/web/narrate.ts +4 -0
  25. package/src/adapters/fired.ts +7 -2
  26. package/src/adapters/lifecycle.ts +104 -9
  27. package/src/adapters/mcp/CONTRACT.md +44 -2
  28. package/src/adapters/mcp/NOTES.md +42 -0
  29. package/src/adapters/mcp/deliberate.ts +25 -1
  30. package/src/adapters/mcp/facts.ts +209 -14
  31. package/src/adapters/mcp/nights.ts +283 -0
  32. package/src/adapters/mcp/server-args.ts +42 -2
  33. package/src/adapters/mcp/server-self-tools.ts +35 -9
  34. package/src/adapters/mcp/server-session-end.ts +13 -6
  35. package/src/adapters/mcp/server-words.ts +12 -3
  36. package/src/adapters/mcp/server.ts +90 -13
  37. package/src/adapters/mcp/tools.ts +49 -28
  38. package/src/adapters/snapshots.ts +101 -2
  39. package/src/adapters/store-id.ts +68 -1
  40. package/src/core/associate/CONTRACT.md +20 -0
  41. package/src/core/associate/at-write.ts +4 -0
  42. package/src/core/associate/index.ts +60 -0
  43. package/src/core/associate/tunables.ts +46 -2
  44. package/src/core/briefing.ts +19 -1
  45. package/src/core/counterpart-boundary.ts +4 -0
  46. package/src/core/counterpart-deposit.ts +83 -2
  47. package/src/core/counterpart-events.ts +46 -2
  48. package/src/core/counterpart-types.ts +73 -1
  49. package/src/core/counterpart.ts +729 -111
  50. package/src/core/dream/CONTRACT.md +71 -4
  51. package/src/core/dream/NOTES.md +119 -0
  52. package/src/core/dream/core-ask.ts +134 -0
  53. package/src/core/dream/day.ts +199 -0
  54. package/src/core/dream/index.ts +76 -5
  55. package/src/core/dream/reflect.ts +493 -65
  56. package/src/core/dream/tunables.ts +31 -0
  57. package/src/core/embed/static.ts +27 -0
  58. package/src/core/handoff/CONTRACT.md +28 -1
  59. package/src/core/handoff/NOTES.md +86 -0
  60. package/src/core/handoff/last-here.ts +267 -59
  61. package/src/core/mint.ts +11 -0
  62. package/src/core/onboarding.ts +2 -1
  63. package/src/core/physics/CONTRACT.md +28 -2
  64. package/src/core/physics/index.ts +92 -8
  65. package/src/core/prospective/CONTRACT.md +11 -2
  66. package/src/core/prospective/NOTES.md +64 -0
  67. package/src/core/prospective/index.ts +143 -4
  68. package/src/core/recall/CONTRACT.md +109 -8
  69. package/src/core/recall/NOTES.md +53 -0
  70. package/src/core/recall/activate.ts +197 -8
  71. package/src/core/recall/cues.ts +94 -21
  72. package/src/core/recall/gate.ts +114 -16
  73. package/src/core/recall/habituation.ts +150 -0
  74. package/src/core/recall/index.ts +203 -22
  75. package/src/core/recall/prime.ts +450 -0
  76. package/src/core/recall/probe.ts +5 -4
  77. package/src/core/recall/rated.ts +172 -9
  78. package/src/core/recall/session.ts +93 -7
  79. package/src/core/recall/time-ask.ts +36 -6
  80. package/src/core/recall/tunables.ts +125 -1
  81. package/src/core/reconsolidation.ts +21 -6
  82. package/src/core/retrieval.ts +9 -0
  83. package/src/core/schemas/NOTES.md +2 -1
  84. package/src/core/self/CONTRACT.md +31 -4
  85. package/src/core/self/NOTES.md +113 -0
  86. package/src/core/self/briefing-delivery.ts +49 -0
  87. package/src/core/self/briefing.ts +20 -3
  88. package/src/core/self/identity.ts +23 -4
  89. package/src/core/self/index.ts +252 -5
  90. package/src/core/self/tunables.ts +24 -0
  91. package/src/core/self/writer.ts +20 -8
  92. package/src/core/sleep/CONTRACT.md +7 -1
  93. package/src/core/sleep/consolidate.ts +20 -5
  94. package/src/core/sleep/core-standing.ts +50 -3
  95. package/src/core/sleep/index.ts +1 -1
  96. package/src/core/sleep/tunables.ts +13 -0
  97. package/src/core/store/CONTRACT.md +20 -0
  98. package/src/core/store/NOTES.md +4 -1
  99. package/src/core/store/cache.ts +181 -5
  100. package/src/core/store/index.ts +208 -23
  101. package/src/core/store/reads-memories.ts +92 -2
  102. package/src/core/store/shapes.ts +8 -0
  103. package/src/core/store/stem.ts +166 -0
@@ -713,6 +713,14 @@ export async function runNight(input: NightRunInput): Promise<NightRun> {
713
713
  // usually rendered the morning's wake before the writer wrote. The
714
714
  // host's budget came with the store (`openNightCounterpart`); without
715
715
  // one the render refuses, as everywhere. Its own try: never the record.
716
+ // First, A PAGE HELD TO THE ROOM AND NOT SENT AGAIN IS KEPT (2026-10-20,
717
+ // `Self#keepHeldPage`), so the night never loses its rewrite to the hold.
718
+ // Bounded by this run's start, not the date: a run may cross midnight.
719
+ try {
720
+ c.self.keepHeldPage({ sinceAt: startedAt });
721
+ } catch {
722
+ /* the held page stays on its refusal row */
723
+ }
716
724
  try {
717
725
  c.refreshWake({ at: c.store.today(), trigger: "run-end" });
718
726
  } catch {
@@ -422,6 +422,17 @@ export interface TranscriptRead {
422
422
  /** `message.model` of the last assistant entry the model wrote (not a host
423
423
  * stand-in, not a sidechain). Absent when none carried one. */
424
424
  readonly model?: string;
425
+ /**
426
+ * WHEN THIS CONVERSATION LAST COMPACTED (2026-10-19, feedback-loop part C),
427
+ * epoch ms: the `timestamp` of the newest `compact_boundary` system line the
428
+ * host wrote (measured on a 10-16 transcript: `{"type":"system","subtype":
429
+ * "compact_boundary","timestamp":…,"compactMetadata":{…}}`, the summary
430
+ * line just after it). Memories born before it may have left the model's
431
+ * context; ambient recall's echo skip counts only what was born since
432
+ * (`counterpart.ts#recallForTurn`). Absent: never compacted, or no line
433
+ * with a readable time. A sidechain's line is not this conversation's.
434
+ */
435
+ readonly compactedAt?: number;
425
436
  }
426
437
 
427
438
  /**
@@ -472,6 +483,7 @@ export function parseTranscript(raw: string): TranscriptRead {
472
483
  // one or the person sends anything else.
473
484
  let pending: string[] = [];
474
485
  let model: string | undefined;
486
+ let compactedAt: number | undefined;
475
487
  for (const line of raw.split("\n")) {
476
488
  if (line.trim().length === 0) continue;
477
489
  let entry: Record<string, unknown>;
@@ -489,6 +501,13 @@ export function parseTranscript(raw: string): TranscriptRead {
489
501
  corrupt += 1;
490
502
  continue;
491
503
  }
504
+ // A COMPACTION'S MARK (part C, 2026-10-19): the newest one wins. Not a
505
+ // turn; nothing else is read off it.
506
+ if (entry["type"] === "system" && entry["subtype"] === "compact_boundary" && entry["isSidechain"] !== true) {
507
+ const when = typeof entry["timestamp"] === "string" ? Date.parse(entry["timestamp"]) : Number.NaN;
508
+ if (Number.isFinite(when) && (compactedAt === undefined || when > compactedAt)) compactedAt = when;
509
+ continue;
510
+ }
492
511
  // A prompt typed while the model worked: a turn of its own, where it
493
512
  // stands in the file. A twin written later is skipped below, so the first
494
513
  // appearance is the one kept and the list only grows.
@@ -543,7 +562,15 @@ export function parseTranscript(raw: string): TranscriptRead {
543
562
  turns.push({ role, text: piece.text, source: piece.source, entry: ordinal });
544
563
  }
545
564
  }
546
- return { turns, ok: true, reason: "read", corrupt, expansions, ...(model === undefined ? {} : { model }) };
565
+ return {
566
+ turns,
567
+ ok: true,
568
+ reason: "read",
569
+ corrupt,
570
+ expansions,
571
+ ...(model === undefined ? {} : { model }),
572
+ ...(compactedAt === undefined ? {} : { compactedAt }),
573
+ };
547
574
  }
548
575
 
549
576
  /**
@@ -29,6 +29,12 @@
29
29
  * the one that cannot be raced against a 1200 ms synchronous budget. Ranking
30
30
  * stays in the worker for that reason alone.
31
31
  *
32
+ * **Amended 2026-10-19.** With the local table only, a turn the lag never
33
+ * reached — a session's first prompt, or a stale row — now embeds and ranks in
34
+ * line (`recall/session.ts#inLineSemantic`): measured ~18 ms cold on the live
35
+ * store's 2,207 vectors (~/counterparts-notes/2026-10-19-first-prompt-recall-diagnosis.md).
36
+ * This worker's lagged cue is unchanged for every turn it does reach.
37
+ *
32
38
  * Handing the hot path a vector
33
39
  * would have moved the network call off it and left that scan on it — the same
34
40
  * abort one layer down. So this file embeds AND ranks, and stores the top-M
@@ -613,6 +613,13 @@ The standalone verb does not ask either: typing it is the yes.*
613
613
  again. Neither command is on `OWNER_OPS`: like `self-page`, reading works from an
614
614
  instrument, and the write refuses at the core's own seam under observer. Confidential
615
615
  rows print as `[confidential]`.
616
+ *Extended 2026-10-20.* `counterparts night` prints the same lines with no write at all:
617
+ the recent dreams and reflections, `last` (the newest dream and the reflection after
618
+ it), `last-reflection`, or one by id (`show <id>` means the same). It always opens the
619
+ store as an observer, so a session can run it to review the night with the owner — a
620
+ host's safety check refuses `dream`, which also undoes. `--undo` stays on `dream`.
621
+ A reflection's entry whose memory is marked confidential prints as `[confidential]`,
622
+ like any confidential row (review of #538), here and under `dream --show`.
616
623
 
617
624
  ## 6. Scars honored
618
625
 
@@ -22,6 +22,7 @@ import { withEmbedderDefault } from "../config.js";
22
22
  import { openEmbedder } from "../claude-code/embed-client.js";
23
23
  import type { LiveEmbedder } from "../claude-code/embed-client.js";
24
24
  import { exportStore } from "./export.js";
25
+ import { dreamShowLines } from "./dream-core.js";
25
26
  import { BIN } from "./install.js";
26
27
  // The console's shared manners (2026-09-21): is there a person here, ask them,
27
28
  // and say one marked line back.
@@ -369,6 +370,13 @@ export async function recallCommand(
369
370
  // number, and `status` prints the split.
370
371
  `${result.storeSize} live rows · returned ${result.memories.length}`,
371
372
  );
373
+ // A NIGHT BY ITS ID (2026-10-20): the console's own words for it, the
374
+ // ones `counterparts night` prints (read-only, like this whole path).
375
+ if (result.nights !== undefined && result.nights.length > 0) {
376
+ io.out("");
377
+ for (const line of dreamShowLines(counterpart, idFlag) ?? []) io.out(line);
378
+ return EXIT.ok;
379
+ }
372
380
  if (result.memories.length === 0) {
373
381
  io.out("");
374
382
  // NOTHING CAME, said as a sentence rather than as an absence. A blank
@@ -118,7 +118,7 @@ export function probeCommand(dir: string, io: Io, namedDir: boolean): number {
118
118
  const credits = store.eventLog({ name: RECALL_CREDIT_EVENT, order: "desc", limit: PROBE_ROW_CEILING }).reverse();
119
119
  const rows = [...decisions, ...credits].map((r) => ({ name: r.name, day: r.day, payload: r.payload }));
120
120
  for (const line of renderProbe(probeOQ4(rows))) io.out(line);
121
- // THE RATINGS (2026-10-14; Mike's call, tracking only): what sessions
121
+ // THE RATINGS (2026-10-14; Mike's call; counted as use since 2026-10-19): what sessions
122
122
  // scored of what they were shown, beside the hit rate above.
123
123
  const ratings = store.eventLog({ name: RECALL_RATED_EVENT, order: "desc", limit: PROBE_ROW_CEILING }).reverse();
124
124
  const lookups = store.eventLog({ name: MCP_RECALL_EVENT, order: "desc", limit: PROBE_ROW_CEILING }).reverse();
@@ -123,6 +123,52 @@ export function dreamCommand(dir: string, io: Io, parsed: Parsed, observer: bool
123
123
  }
124
124
  }
125
125
 
126
+ /**
127
+ * `night` — last night, read-only (2026-10-20). The same lines `dream`
128
+ * prints (`dream-core.ts`), behind a command with no write at all, so a
129
+ * session can run it to review the night with the owner: `dream` also undoes,
130
+ * and a host's safety check refuses a command that can change shared data.
131
+ * It always opens the store as an observer, so `--observer` changes nothing
132
+ * here. `last` is the newest dream (and the reflection after it); with no
133
+ * dream yet, the newest reflection. `last-reflection` is the newest reflection.
134
+ */
135
+ export function nightCommand(dir: string, io: Io, parsed: Parsed, namedDir: boolean): number {
136
+ if (!storeExists(dir)) {
137
+ io.err(`No store at ${dir}. Run 'counterparts init${namedDir ? ` --dir ${dir}` : ""}' to create one.`);
138
+ return EXIT.usage;
139
+ }
140
+ const words = parsed.positional[0] === "show" || parsed.positional[0] === "list" ? parsed.positional.slice(1) : parsed.positional;
141
+ const listing = parsed.positional[0] === "list" || words.length === 0;
142
+ if (parsed.positional[0] === "show" && words.length === 0) {
143
+ io.err("refused: show needs an id (drm_… or rfl_…) or last. counterparts night lists them.");
144
+ return EXIT.usage;
145
+ }
146
+ const counterpart = openCounterpart(dir, true);
147
+ try {
148
+ if (listing) {
149
+ for (const line of dreamListLines(counterpart, parsed.flags["all"] === true ? "all" : undefined, "night")) io.out(line);
150
+ return EXIT.ok;
151
+ }
152
+ const asked = (words[0] ?? "").trim();
153
+ let id: string | null = asked;
154
+ if (asked === "last") id = counterpart.dreams.list(1)[0]?.dream.id ?? counterpart.reflections.list(1)[0]?.id ?? null;
155
+ else if (asked === "last-reflection") id = counterpart.reflections.list(1)[0]?.id ?? null;
156
+ if (id === null) {
157
+ io.out(asked === "last-reflection" ? "No reflections yet." : "No dreams yet.");
158
+ return EXIT.ok;
159
+ }
160
+ const lines = id.startsWith("drm_") || id.startsWith("rfl_") ? dreamShowLines(counterpart, id) : null;
161
+ if (lines === null) {
162
+ io.err(`refused: no dream or reflection ${id} in this store. counterparts night lists them.`);
163
+ return EXIT.refused;
164
+ }
165
+ for (const line of lines) io.out(line);
166
+ return EXIT.ok;
167
+ } finally {
168
+ counterpart.close();
169
+ }
170
+ }
171
+
126
172
  /**
127
173
  * `settle` — contradictions, the owner's door (2026-09-29). The list reads
128
174
  * under any stance; a settle and an undo go through `Counterpart
@@ -368,7 +414,7 @@ export function coreCommand(dir: string, io: Io, parsed: Parsed, observer: boole
368
414
  io.err(`refused: ${why[out.reason] ?? out.reason}. Nothing was changed.`);
369
415
  return EXIT.refused;
370
416
  }
371
- io.out(`Kept ${keep} in the core.`);
417
+ io.out(out.reason === "restored" ? `Put ${keep} back in the core: it had been retired.` : `Kept ${keep} in the core.`);
372
418
  io.out(` Why, as recorded: ${reason.trim()}`);
373
419
  io.out(" It is no longer being reconsidered, and it is not flagged again for what it is — only if it stops coming back.");
374
420
  return EXIT.ok;
@@ -394,6 +440,12 @@ export function coreCommand(dir: string, io: Io, parsed: Parsed, observer: boole
394
440
  io.err(`refused: ${why[out.reason] ?? out.reason}. Nothing was changed.`);
395
441
  return EXIT.refused;
396
442
  }
443
+ if (out.reason === "confirmed") {
444
+ io.out(`A reflection had already retired ${demote}; it is now recorded as your retire.`);
445
+ io.out(` Why, as recorded: ${reason.trim()}`);
446
+ io.out(" It keeps fading, and no session can put it back in the core — only you can (counterparts core --reaffirm).");
447
+ return EXIT.ok;
448
+ }
397
449
  io.out(`Sent ${demote} back to ordinary fading, from today.`);
398
450
  io.out(` Why, as recorded: ${reason.trim()}`);
399
451
  io.out(" It fades like any other memory now, and the core's lanes will not promote it again.");
@@ -111,6 +111,7 @@ import {
111
111
  catchUpEntry,
112
112
  selfPageCommand,
113
113
  dreamCommand,
114
+ nightCommand,
114
115
  coreCommand,
115
116
  claimsEraCommand,
116
117
  settleCommand,
@@ -222,6 +223,10 @@ export const COMMANDS = [
222
223
  // each both reads and writes, so neither is on `OWNER_OPS`: reading works
223
224
  // under observer, and the write refuses at the core's own seam.
224
225
  "dream",
226
+ // Last night, read-only (2026-10-20): a dream or a reflection by id, or the
227
+ // newest. It has no write at all — `dream --undo` stays on `dream` — so a
228
+ // session can run it to review the night with the owner.
229
+ "night",
225
230
  "core",
226
231
  // Contradictions (2026-09-29): what is unsettled and what was settled, and
227
232
  // the owner's settle and undo. Reads and writes, like `dream`; the write
@@ -574,6 +579,7 @@ export const COMMAND_FLAGS: Record<Command, readonly string[]> = {
574
579
  // session does not belong there.
575
580
  "self-page": ["write", "file", "stdin", "short", "reason", "versions", "version", "restore", "clear", "if-version"],
576
581
  dream: ["list", "show", "undo", "all", "setting"],
582
+ night: ["all"],
577
583
  core: ["list", "demote", "reaffirm", "reason", "reflected-feeling"],
578
584
  settle: ["list", "pair", "holds", "against", "how", "why", "undo"],
579
585
  about: ["why"],
@@ -653,6 +659,8 @@ export const COMMAND_BLURB: Record<Command, string> = {
653
659
  "The written page the wake opens with. With no flags it prints the page, its date and its size; --write --file <path> or --write --stdin replaces it whole, keeping every earlier version; --short <file> beside them gives a page past its room the short version sessions read on a day the wake has no room for it whole (alone, with --write, it is added to the page as it stands); --versions lists those and --version <seq> prints one. Reading works under observer; writing refuses there.",
654
660
  dream:
655
661
  "What each dream did, and its undo — and what the waking self made of it. With no flags (or --list), the newest 20 dreams (--list --all for every one): date, state, title and what changed, then the recent reflections; --show <id> prints one dream's journal, every change it made and the reflection after it (--show <rfl_…> prints one reflection: its questions, entry, what it rests on and its morning share); --undo <id> reverses that dream's whole batch (merges come apart, links and gists go, replays and nominations are taken back) and keeps its journal, marked undone — a reflection is lived and stays. Reading works under observer; --undo refuses there.",
662
+ night:
663
+ "Last night, read-only: what a dream did and what the waking self made of it. It changes nothing — it opens the store as an observer, so it runs the same under --observer. With nothing after it (or list), the recent dreams and reflections, newest first (--all for every dream); last prints the newest dream — its journal, every change it made, and the reflection after it (last-reflection: the newest reflection); an id (drm_… or rfl_…) prints that one, and show <id|last> means the same. Undoing a dream stays on `counterparts dream`, the owner's door.",
656
664
  core:
657
665
  "The core — the memories about me and about us that do not fade. With no flags (or --list), what it holds and which lane carried each one there, what dreams have nominated, what is being reconsidered, and what was sent back; --demote <id> --reason \"...\" sends one back to ordinary fading from today, records why, and keeps the lanes from promoting it again; --reaffirm <id> --reason \"...\" keeps one that is being reconsidered (it is not flagged again for what it is); --reflected-feeling on|off opens or closes the core to reflection alone. On (the default): a feeling a reflection records later and a reflection citing a memory both count toward the fast lane, and a reflection may re-label what a memory is about either way — each re-label is recorded with its reason, and one into me, us or the owner is told in the next morning share. Off: nothing reaches the core on a reflection alone — the fast lane needs a feeling felt at the time (not one a reflection recorded later) and an ordinary use after a gap (not a reflection citing it), and a reflection may only move what a memory is about toward work or world. Reading works under observer; the changes refuse there.",
658
666
  settle:
@@ -688,6 +696,7 @@ const COMMAND_ARGS: Partial<Record<Command, string>> = {
688
696
  disconnect: " [claude-code]",
689
697
  help: " [advanced | <command>]",
690
698
  dream: " [--list [--all] | --show <id> | --undo <id>]",
699
+ night: " [list [--all] | last | last-reflection | [show] <drm_…|rfl_…>]",
691
700
  core: " [--demote <id> --reason \"...\" | --reaffirm <id> --reason \"...\" | --reflected-feeling on|off]",
692
701
  settle: " [--list | --pair <id> --holds <id> --how changed|corrected|open --why \"...\" | --undo <pair>]",
693
702
  about: " <id> [me|us|owner|work|world] [--why \"...\"]",
@@ -922,6 +931,11 @@ const DREAM_FLAG_HELP: Record<string, string> = {
922
931
  "auto, ask or off — the nightly run (page writer, dream, reflection). ask (the default): the first session of a day shows you the question in the terminal and waits for you to say \"dream\" (or \"dream on your own\", which turns on auto); auto: the first session of a day starts it by itself, in a separate windowless claude -p in the background, and says so in one line; off: no dreams. `counterparts dream` prints the setting.",
923
932
  };
924
933
 
934
+ /** `night`'s one flag (2026-10-20): `--all` means something else on other pages. */
935
+ const NIGHT_FLAG_HELP: Record<string, string> = {
936
+ all: "with the list: every dream the store holds, not only the newest 20",
937
+ };
938
+
925
939
  /** `settle`'s own seven (2026-09-29): `--list` and `--undo` mean something else on other pages. */
926
940
  const SETTLE_FLAG_HELP: Record<string, string> = {
927
941
  list: "what is unsettled, and what was settled lately — the default",
@@ -1015,6 +1029,8 @@ export function commandHelp(command: Command): string {
1015
1029
  ? HOST_FLAG_HELP
1016
1030
  : command === "dream"
1017
1031
  ? DREAM_FLAG_HELP
1032
+ : command === "night"
1033
+ ? NIGHT_FLAG_HELP
1018
1034
  : command === "core"
1019
1035
  ? CORE_FLAG_HELP
1020
1036
  : command === "claims-era"
@@ -1679,6 +1695,8 @@ export async function run(argv: readonly string[], opts: RunOptions): Promise<nu
1679
1695
  );
1680
1696
  case "dream":
1681
1697
  return dreamCommand(dir, io, parsed, observer, typeof parsed.flags["dir"] === "string");
1698
+ case "night":
1699
+ return nightCommand(dir, io, parsed, typeof parsed.flags["dir"] === "string");
1682
1700
  case "core":
1683
1701
  return coreCommand(dir, io, parsed, observer, typeof parsed.flags["dir"] === "string");
1684
1702
  case "claims-era":
@@ -67,7 +67,7 @@ export const DREAM_LIST_LIMIT = 20;
67
67
  * (`limit: "all"`). The header says how many of how many, so a list that stops
68
68
  * is never read as all there is.
69
69
  */
70
- export function dreamListLines(counterpart: Counterpart, limit: number | "all" = DREAM_LIST_LIMIT): string[] {
70
+ export function dreamListLines(counterpart: Counterpart, limit: number | "all" = DREAM_LIST_LIMIT, via: "dream" | "night" = "dream"): string[] {
71
71
  const total = counterpart.store.dreamCount();
72
72
  const dreams = counterpart.dreams.list(limit === "all" ? Math.max(1, total) : limit);
73
73
  const setting = counterpart.dreams.setting();
@@ -79,7 +79,7 @@ export function dreamListLines(counterpart: Counterpart, limit: number | "all" =
79
79
  const out = [
80
80
  ...head,
81
81
  dreams.length < total
82
- ? `Dreams — newest first (${String(dreams.length)} of ${String(total)} shown; every one: counterparts dream --list --all)`
82
+ ? `Dreams — newest first (${String(dreams.length)} of ${String(total)} shown; every one: counterparts ${via === "night" ? "night --all" : "dream --list --all"})`
83
83
  : `Dreams — newest first (all ${String(dreams.length)})`,
84
84
  "",
85
85
  ];
@@ -88,12 +88,18 @@ export function dreamListLines(counterpart: Counterpart, limit: number | "all" =
88
88
  const title = dream.title === null || dream.title.length === 0 ? "(no journal)" : `"${dream.title}"`;
89
89
  out.push(`${dream.id} ${when} ${dream.state.padEnd(9)} ${title} — ${countsLine(counts)}`);
90
90
  }
91
- out.push("", "Read one: counterparts dream --show <id> Reverse one: counterparts dream --undo <id>");
91
+ // From `night` (2026-10-20), the read-only door, the pointer stays on it.
92
+ out.push(
93
+ "",
94
+ via === "night"
95
+ ? "Read one: counterparts night <id> (or last) Undo one (the owner's): counterparts dream --undo <id>"
96
+ : "Read one: counterparts dream --show <id> Reverse one: counterparts dream --undo <id>",
97
+ );
92
98
  const reflections = counterpart.reflections.list(10);
93
99
  if (reflections.length > 0) {
94
100
  out.push("", `Reflections — the waking self, newest first (${String(reflections.length)} shown)`, "");
95
101
  for (const r of reflections) out.push(`${r.id} ${r.date ?? `lived day ${String(r.day)}`} ${reflectionSummary(r)}`);
96
- out.push("", "Read one: counterparts dream --show <rfl_…>");
102
+ out.push("", via === "night" ? "Read one: counterparts night <rfl_…>" : "Read one: counterparts dream --show <rfl_…>");
97
103
  }
98
104
  return out;
99
105
  }
@@ -177,7 +183,11 @@ export function reflectionShowLines(counterpart: Counterpart, id: string): strin
177
183
  "",
178
184
  r.entry === null ? "Entry: (not written)" : "Entry:",
179
185
  ];
180
- if (r.entry !== null) for (const line of r.entry.split("\n")) out.push(` ${line}`);
186
+ // The entry is the body of the memory it became: marked confidential since,
187
+ // it prints as that row does (review of #538 — `night` is run by sessions).
188
+ const entryHidden = r.entry_id !== null && counterpart.store.row(r.entry_id)?.confidential === 1;
189
+ if (r.entry !== null && entryHidden) out.push(" [confidential]");
190
+ else if (r.entry !== null) for (const line of r.entry.split("\n")) out.push(` ${line}`);
181
191
  if (r.entry_id !== null) out.push(` (kept as memory ${r.entry_id})`);
182
192
  const cites = parseIdList(r.cites);
183
193
  if (cites.length > 0) {
@@ -236,7 +246,7 @@ export function coreListLines(counterpart: Counterpart): string[] {
236
246
  : `The core — ${String(core.length)} ${core.length === 1 ? "memory" : "memories"} that do not fade`,
237
247
  ];
238
248
  for (const m of core) {
239
- const how = m.lane === null ? "(before lanes, or by revision)" : `${m.lane} lane${m.day === null ? "" : `, lived day ${String(m.day)}`}`;
249
+ const how = m.lane === null ? "(before lanes, or by revision)" : m.lane === "restored" ? `restored after it was retired${m.day === null ? "" : `, lived day ${String(m.day)}`}` : `${m.lane} lane${m.day === null ? "" : `, lived day ${String(m.day)}`}`;
240
250
  const said = m.confidential ? "[confidential]" : (m.body ?? "(unreadable)");
241
251
  out.push(` ${m.id} ${m.kind.padEnd(6)} ${how} — ${said}`);
242
252
  }
@@ -130,6 +130,7 @@ export const SHORT: Record<string, string | readonly string[]> = {
130
130
  mechanisms: "Which parts of memory are working, one line each",
131
131
  log: "What happened today, in order, one line each (kept 7 days)",
132
132
  dream: "What each dream did — and undo one",
133
+ night: "Last night's dream and reflection, read-only",
133
134
  core: "What became part of who I am — and send one back",
134
135
  settle: "Two memories that disagree: which holds — and undo one",
135
136
  about: "What a memory is about — and change it",
@@ -185,6 +186,7 @@ export const ADVANCED: readonly string[] = [
185
186
  "mechanisms",
186
187
  "log",
187
188
  "dream",
189
+ "night",
188
190
  "core",
189
191
  "settle",
190
192
  "about",
@@ -379,7 +381,9 @@ export const COMMAND_DETAIL: Record<string, readonly string[]> = {
379
381
  "(recall/render.ts).",
380
382
  "",
381
383
  "Then the ratings: what sessions scored, 0 to 3, of what they were shown, by",
382
- "date and lane, beside drewOn and the hit rate. Tracking only.",
384
+ "date and lane, beside drewOn and the hit rate. Since 2026-10-19 (an",
385
+ "experiment) the scores also count as use; doctor's Feedback loop line says",
386
+ "what they did.",
383
387
  ],
384
388
  mechanisms: [
385
389
  "One line per memory mechanism: ● working this week, ◐ built but not firing,",
@@ -72,8 +72,11 @@ it; `version` is `package.json#version`, or null when unreadable. `/api/onboardi
72
72
  the same `store` field. The dashboard only reads the salt (E7): `store` is null until a
73
73
  session-start wake has minted it. The id is stable across opens, differs between stores,
74
74
  and never carries the path; a store moved to another path reads as another store.
75
- **[M]** The session-start wake of a Claude Code hook carries the same id on the line under
76
- the onboarding marker: `<!-- counterparts:store id=st_… -->`. The sidebar mod compares the
75
+ **[M]** The session-start wake of a Claude Code hook carries the same id: since 2026-10-20 as
76
+ the `store=st_…` field of the wake's head tag (`<!-- counterparts:wake meet=… store=st_…
77
+ elements=… bytes=… -->`, or `<!-- counterparts:session … -->` before a wake with no head tag;
78
+ `adapters/store-id.ts#ONE_TAG`), before that as `<!-- counterparts:store id=st_… -->` beside
79
+ the onboarding marker. The sidebar mod reads every form, compares the
77
80
  two and trusts a dashboard only when they match. Nothing about which port is chosen changed.
78
81
 
79
82
  ## 6. Scars honored
@@ -337,8 +337,8 @@ export const DURABLE_EVENTS = {
337
337
  // Durable since 2026-10-02: "Work here" had more lines than the wake carried.
338
338
  "self.work.overflow": "a session start had more \"Work here\" lines for its project than it carried — more than the wake shows, so they rotate, or fewer fitted the room (how many, how many shown)",
339
339
  "recall.credit": "a boundary decided which memories the replies actually used, and credited them",
340
- // Ratings (2026-10-14; Mike's call, tracking only): recorded, acted on by nothing.
341
- "recall.rated": "a session scored the memories it was shown, 0 to 3 (by lane, whether each was also drawn on, and how many of the footnotes since its last rating it scored) — tracking only, nothing changes",
340
+ // Ratings (2026-10-14; Mike's call). Since 2026-10-19 an experiment counts them as use.
341
+ "recall.rated": "a session scored the memories it was shown, 0 to 3 (by lane, whether each was also drawn on, and how many of the footnotes since its last rating it scored) — and, an experiment since 2026-10-19, what the scores credited and linked",
342
342
  // Learned association had no line in the log at all: an edge is its own
343
343
  // record, so a flush that never happened read exactly like a credit pass with
344
344
  // nothing to wire (2026-09-17, mechanism inventory §3 S3).
@@ -384,7 +384,7 @@ export const DURABLE_EVENTS = {
384
384
  // The update guard (2026-10-09). Ids, the reading and its numbers; no text.
385
385
  "contradiction.held": "a new memory said it changed or corrected one that looked unrelated to it, so the old one was left as it was and the two were not linked (the writer was shown it and asked to settle it if it meant to)",
386
386
  // The slot detector (2026-10-11, Group 2). Ids, the rule and the cosine; no text.
387
- "contradiction.proposed": "a new memory read as the newer state of the same thing as an older one (status moved on, or very close in meaning), so the older was marked possibly out of date and faded a little, until the writer or the dream confirms it or says they are two things",
387
+ "contradiction.proposed": "a new memory read as the newer state of the same thing as an older one (status moved on, or very close in meaning), so the older was marked possibly out of date (faded a little before 2026-10-19; a flag only since, as an experiment), until the writer or the dream confirms it or says they are two things",
388
388
  // What is not written up (2026-09-30). Ids and counts only; one row per stretch per state.
389
389
  "coverage.owed": "a session left a stretch that is not written up — three pieces or more over a quarter of an hour — and is no longer at work, so it owes a write-up (how many pieces, over how long)",
390
390
  "coverage.written": "a stretch of a session was written up (how many pieces, and by whom: the session itself, a \"nothing new\", a chapter, or the next session)",
@@ -942,6 +942,10 @@ export const NARRATORS = {
942
942
  : ` ${String(total)} more ${total === 1 ? "was" : "were"} kept out (most often ${worst[0]}).`;
943
943
  if (s(t, "path") === "handle") {
944
944
  const opened = n(t, "expanded") ?? 0;
945
+ const nights = n(t, "nights") ?? 0;
946
+ if (opened === 0 && nights > 0) {
947
+ return calm(`${nights === 1 ? "A dream or a reflection was" : `${String(nights)} dreams or reflections were`} read back by id.${stopped}`);
948
+ }
945
949
  return calm(
946
950
  opened === 0
947
951
  ? `Something was asked for by name and I had nothing at that address.${stopped}`
@@ -525,9 +525,11 @@ export const MECHANISMS: readonly Mechanism[] = [
525
525
  evidence: { kind: "event", names: ["recall.credit"] },
526
526
  },
527
527
  {
528
- // Mike's call, 2026-10-14: tracking only. Nothing reads the rows to act.
528
+ // Mike's call, 2026-10-14. Since 2026-10-19 an experiment (check ~10-22)
529
+ // counts the scores as use, links what was co-used, and habituates a
530
+ // memory rated 0 twice (`core/recall/rated.ts`, `habituation.ts`).
529
531
  id: "rated",
530
- label: "a session scored the memories it was shown, 0 to 3 — recorded only, nothing changes",
532
+ label: "a session scored the memories it was shown, 0 to 3, and the scores count as use (an experiment since 2026-10-19)",
531
533
  module: "recall/rated.ts, mcp/server-session-end.ts",
532
534
  evidence: { kind: "event", names: ["recall.rated"] },
533
535
  since: "2026-10-14",
@@ -2276,6 +2278,9 @@ function readProbes(store: ReadOnlyStore, w: Window): Probed {
2276
2278
  // doctor's Reflection line splits the week's returns by source.
2277
2279
  for (const r of store.returnsOf(id)) {
2278
2280
  if (r.source === "legacy") continue;
2281
+ // A glimpse or a rating of 1 (2026-10-19, an experiment) is a partial
2282
+ // return, not a memory that came back: not counted as one here.
2283
+ if (r.source === "shown" || r.source === "ontopic") continue;
2279
2284
  bump(r.source === "dream" ? "returns.dream" : "returns.awake", { at: r.at });
2280
2285
  }
2281
2286
  if (row !== undefined && row.archived === 0 && row.source === "dreamed") {