counterparts 0.3.11 → 0.3.13

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 (150) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/docs/QUICKSTART.md +5 -0
  3. package/docs/README.md +2 -2
  4. package/docs/module-map.md +3 -3
  5. package/package.json +1 -1
  6. package/src/adapters/claude-code/CONTRACT.md +36 -10
  7. package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
  8. package/src/adapters/claude-code/NOTES.md +182 -0
  9. package/src/adapters/claude-code/bin/hook.ts +46 -12
  10. package/src/adapters/claude-code/bin/runner.ts +7 -1
  11. package/src/adapters/claude-code/doctor.ts +632 -18
  12. package/src/adapters/claude-code/hooks.ts +61 -16
  13. package/src/adapters/claude-code/index.ts +11 -0
  14. package/src/adapters/claude-code/night-run.ts +150 -14
  15. package/src/adapters/claude-code/transcript.ts +268 -1
  16. package/src/adapters/cli/CONTRACT.md +5 -0
  17. package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
  18. package/src/adapters/cli/NOTES.md +111 -0
  19. package/src/adapters/cli/commands.ts +134 -92
  20. package/src/adapters/cli/dream-core.ts +57 -42
  21. package/src/adapters/cli/export.ts +320 -21
  22. package/src/adapters/cli/help.ts +2 -1
  23. package/src/adapters/cli/index.ts +1 -0
  24. package/src/adapters/cli/install.ts +39 -7
  25. package/src/adapters/cli/mechanisms.ts +7 -1
  26. package/src/adapters/cli/uninstall.ts +13 -5
  27. package/src/adapters/cli/wire.ts +189 -63
  28. package/src/adapters/config.ts +2 -0
  29. package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
  30. package/src/adapters/dashboard/NOTES.md +79 -0
  31. package/src/adapters/dashboard/registries.ts +34 -2
  32. package/src/adapters/dashboard/web/README.md +19 -14
  33. package/src/adapters/dashboard/web/actions.ts +23 -1
  34. package/src/adapters/dashboard/web/flow.ts +14 -0
  35. package/src/adapters/dashboard/web/lanes.ts +10 -0
  36. package/src/adapters/dashboard/web/narrate.ts +88 -2
  37. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
  38. package/src/adapters/dashboard/web/pages/health/sections/checks.js +2 -0
  39. package/src/adapters/dashboard/web/pages/health/sections/wake.js +3 -1
  40. package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
  41. package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
  42. package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
  43. package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
  44. package/src/adapters/dashboard/web/server.ts +0 -5
  45. package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
  46. package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
  47. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
  48. package/src/adapters/dashboard/web/views/health.ts +21 -3
  49. package/src/adapters/dashboard/web/views/search.ts +4 -45
  50. package/src/adapters/dashboard/web/views.ts +2 -2
  51. package/src/adapters/fired.ts +430 -28
  52. package/src/adapters/host-wiring.ts +300 -0
  53. package/src/adapters/hosts.ts +11 -0
  54. package/src/adapters/lifecycle.ts +42 -2
  55. package/src/adapters/log/index.ts +9 -0
  56. package/src/adapters/mcp/CONTRACT.md +151 -11
  57. package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
  58. package/src/adapters/mcp/NOTES.md +313 -1
  59. package/src/adapters/mcp/bin/serve.ts +74 -1
  60. package/src/adapters/mcp/deliberate.ts +169 -651
  61. package/src/adapters/mcp/facts.ts +1094 -0
  62. package/src/adapters/mcp/index.ts +25 -7
  63. package/src/adapters/mcp/meaning.ts +1610 -0
  64. package/src/adapters/mcp/server.ts +835 -150
  65. package/src/adapters/mcp/stdio.ts +3 -1
  66. package/src/adapters/mcp/stood-down.ts +51 -0
  67. package/src/adapters/mcp/tools.ts +167 -41
  68. package/src/adapters/plugin-run.sh +133 -0
  69. package/src/adapters/plugin.ts +329 -0
  70. package/src/adapters/sessions.ts +18 -4
  71. package/src/core/associate/CONTRACT.md +2 -1
  72. package/src/core/associate/INTERFACE-GAPS.md +6 -1
  73. package/src/core/associate/NOTES.md +45 -0
  74. package/src/core/briefing.ts +12 -3
  75. package/src/core/contradictions.ts +184 -0
  76. package/src/core/counterpart.ts +797 -51
  77. package/src/core/dream/CONTRACT.md +36 -4
  78. package/src/core/dream/INTERFACE-GAPS.md +29 -6
  79. package/src/core/dream/NOTES.md +107 -0
  80. package/src/core/dream/feeling-weeks.ts +198 -0
  81. package/src/core/dream/index.ts +109 -18
  82. package/src/core/dream/reflect.ts +346 -87
  83. package/src/core/dream/tunables.ts +24 -4
  84. package/src/core/encode/INTERFACE-GAPS.md +3 -1
  85. package/src/core/encode/NOTES.md +7 -0
  86. package/src/core/encode/words.ts +45 -0
  87. package/src/core/fit/INTERFACE-GAPS.md +8 -2
  88. package/src/core/fit/NOTES.md +39 -1
  89. package/src/core/fit/index.ts +40 -0
  90. package/src/core/handoff/CONTRACT.md +37 -2
  91. package/src/core/handoff/INTERFACE-GAPS.md +10 -0
  92. package/src/core/handoff/NOTES.md +72 -0
  93. package/src/core/handoff/index.ts +214 -12
  94. package/src/core/handoff/last-here.ts +6 -4
  95. package/src/core/mint.ts +12 -2
  96. package/src/core/physics/CONTRACT.md +14 -2
  97. package/src/core/physics/NOTES.md +33 -1
  98. package/src/core/physics/index.ts +28 -5
  99. package/src/core/prospective/CONTRACT.md +45 -6
  100. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  101. package/src/core/prospective/NOTES.md +138 -0
  102. package/src/core/prospective/derive.ts +33 -5
  103. package/src/core/prospective/index.ts +90 -5
  104. package/src/core/prospective/windows.ts +72 -1
  105. package/src/core/recall/CONTRACT.md +31 -12
  106. package/src/core/recall/INTERFACE-GAPS.md +28 -4
  107. package/src/core/recall/NOTES.md +70 -1
  108. package/src/core/recall/feeling-ask.ts +10 -1
  109. package/src/core/recall/index.ts +3 -1
  110. package/src/core/recall/probe.ts +58 -0
  111. package/src/core/recall/session.ts +46 -2
  112. package/src/core/recall/time-ask.ts +487 -0
  113. package/src/core/remember/CONTRACT.md +4 -1
  114. package/src/core/remember/INTERFACE-GAPS.md +9 -1
  115. package/src/core/remember/NOTES.md +8 -0
  116. package/src/core/remember/proposals.ts +47 -5
  117. package/src/core/revision.ts +18 -1
  118. package/src/core/schemas/CONTRACT.md +21 -1
  119. package/src/core/schemas/INTERFACE-GAPS.md +20 -2
  120. package/src/core/schemas/NOTES.md +144 -0
  121. package/src/core/schemas/aliases.ts +55 -5
  122. package/src/core/schemas/index.ts +93 -1
  123. package/src/core/schemas/types.ts +2 -0
  124. package/src/core/self/CONTRACT.md +32 -5
  125. package/src/core/self/INTERFACE-GAPS.md +7 -2
  126. package/src/core/self/NOTES.md +102 -1
  127. package/src/core/self/behind.ts +43 -3
  128. package/src/core/self/briefing.ts +12 -2
  129. package/src/core/self/chapter-address.ts +254 -0
  130. package/src/core/self/episodes.ts +27 -0
  131. package/src/core/self/index.ts +83 -8
  132. package/src/core/self/page.ts +88 -0
  133. package/src/core/self/tunables.ts +5 -0
  134. package/src/core/self/work.ts +35 -2
  135. package/src/core/self/writer.ts +30 -0
  136. package/src/core/sleep/INTERFACE-GAPS.md +22 -3
  137. package/src/core/sleep/NOTES.md +20 -1
  138. package/src/core/sleep/consolidate.ts +59 -7
  139. package/src/core/sleep/index.ts +3 -0
  140. package/src/core/sleep/prune.ts +6 -2
  141. package/src/core/sleep/types.ts +7 -0
  142. package/src/core/store/CONTRACT.md +16 -0
  143. package/src/core/store/NOTES.md +66 -0
  144. package/src/core/store/feelings.ts +14 -1
  145. package/src/core/store/index.ts +483 -16
  146. package/src/core/store/operational.ts +95 -2
  147. package/src/core/store/owner-op-seam.ts +23 -0
  148. package/src/core/time.ts +152 -0
  149. package/tools/install-loop/run.sh +48 -12
  150. package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
@@ -77,7 +77,10 @@
77
77
  * The file also holds the WAKE-ARRIVAL READER (bottom of this file), which reads
78
78
  * the same transcript for a different question and keeps its own, bounded, pass:
79
79
  * capture wants conversation and skips attachments (queued prompts aside),
80
- * delivery wants exactly the hook's attachment and skips conversation.
80
+ * delivery wants exactly the hook's attachment and skips conversation. And,
81
+ * below that, the SPILL READER (2026-10-09): the nightly run asks its own
82
+ * child's transcript whether the host cut any of our tool results to a preview
83
+ * — tool results being exactly what capture refuses to read.
81
84
  */
82
85
  import {
83
86
  closeSync,
@@ -85,10 +88,14 @@ import {
85
88
  existsSync,
86
89
  fstatSync,
87
90
  openSync,
91
+ readdirSync,
88
92
  readFileSync,
89
93
  readSync,
94
+ realpathSync,
90
95
  statSync,
91
96
  } from "node:fs";
97
+ import { homedir } from "node:os";
98
+ import { join } from "node:path";
92
99
 
93
100
  import { carriesDreamMark } from "../../core/dream/mark.js";
94
101
  import type { Turn, TurnSource } from "../../core/remember/index.js";
@@ -933,3 +940,263 @@ export function readWakeArrival(
933
940
  }
934
941
  return { ...NO_ARRIVAL, reason: "read", linesRead, bytesRead: head.bytes, corrupt };
935
942
  }
943
+
944
+ // ── the host's cut, on our own tool results ─────────────────────────────────
945
+ //
946
+ // A THIRD PASS (2026-10-09, U14 item 3), for the nightly run: did the host cut
947
+ // any of THIS package's tool results before the model read them?
948
+ //
949
+ // Claude Code saves a tool result past its line (50,000 characters today, and
950
+ // lower whenever a remote flag says so) to a file and hands the model a 2 KB
951
+ // preview in its place. The headless run cannot open that file. 0.3.12 keeps
952
+ // every result under 40,000 (`fit/TOOL_RESULT_CEILING`), but a lowered line
953
+ // would put the night back to reading through a keyhole with every count
954
+ // green — the MCP server cannot see what the host did after it answered. The
955
+ // host's record of the session can: the transcript holds each tool result as
956
+ // the model saw it, preview and all.
957
+ //
958
+ // THE MARKERS, read from Claude Code 2.1.295's own code (2026-10-09). Each is
959
+ // what the host puts IN PLACE of a result, so each is matched where the host
960
+ // puts it — at the start of the result (the first three) or at its very end
961
+ // (the last) — and only on a `tool_result` block whose call was ours:
962
+ //
963
+ // - `persisted`: `<persisted-output>`, then "Output too large (51.5KB). Full
964
+ // output saved to: …" (or "Output exceeded the … persist limit; only the
965
+ // first … were saved to: …"), then "Preview (first 2KB):" and the preview,
966
+ // then `</persisted-output>`. The one the nights of 10-01 to 10-07 met.
967
+ // - `unsaved`: `<truncated-output>`, then "Output too large (…). It could
968
+ // not be saved, so only the first … are shown" — the same line, when the
969
+ // save failed.
970
+ // - `tokens`: "Error: result (51,306 characters) exceeds maximum allowed
971
+ // tokens. Output has been saved to …" (or "Failed to save output to
972
+ // file: …") — an MCP result past `MAX_MCP_OUTPUT_TOKENS`.
973
+ // - `token-cut`: the result cut short, with "[OUTPUT TRUNCATED - exceeded
974
+ // 25000 token limit]" and "The tool output was truncated. …" after it —
975
+ // the same line, when the host keeps no files.
976
+ //
977
+ // A SECOND PLACE THE HOST CUTS (review of #330): besides each result's own
978
+ // line, 2.1.295 has a budget for ALL the results answering one assistant turn
979
+ // (200,000 characters, behind a remote flag). Past it, the largest are swapped
980
+ // for the same `<persisted-output>` preview — but at request time: the
981
+ // result's own line in the transcript stays WHOLE, and the swap is written as
982
+ // a line of its own, `{"type":"content-replacement","replacements":[{"kind":
983
+ // "tool-result","toolUseId":…,"replacement":…}]}`, which resume replays. So
984
+ // those lines are read too, the replacement judged by the same anchors, and
985
+ // such a cut is shaped `turn-budget`: several results at once, not one too
986
+ // long. Each call is counted once, however many lines speak of it.
987
+ //
988
+ // ANCHORED, NEVER A SUBSTRING (the morning of 2026-10-09): a search of a
989
+ // night's transcript for "Output too large" found two hits that were memories
990
+ // QUOTING that very check, inside our own result. A memory's words sit inside
991
+ // the result's JSON, never at its start or its end; and a quote in the model's
992
+ // own text, or in another tool's result, is not one of our results at all.
993
+
994
+ /** How the host cut a result, by the marker it left (see above). */
995
+ export type SpillShape = "persisted" | "unsaved" | "tokens" | "token-cut" | "turn-budget";
996
+
997
+ /** One of our results the host cut. Names, a shape and a size — never the saved file's path, never a byte of the result. */
998
+ export interface Spill {
999
+ /** The tool as the host names it (`mcp__counterparts__dream`). */
1000
+ readonly tool: string;
1001
+ /** The call's `phase` argument, when it had one (`begin`, `part`). */
1002
+ readonly phase: string | null;
1003
+ readonly shape: SpillShape;
1004
+ /** The size the host said ("51.5KB", "51,306 characters"), when it said one. */
1005
+ readonly said: string | null;
1006
+ }
1007
+
1008
+ /** What one transcript says about the host's cut. Counts and the spills; nothing else. */
1009
+ export interface ToolSpills {
1010
+ readonly reason: "read" | "absent" | "unreadable";
1011
+ /** Our tool results the pass found, cut or not. */
1012
+ readonly results: number;
1013
+ readonly spills: readonly Spill[];
1014
+ /** Lines that were not JSON. Counted, never silently swallowed. */
1015
+ readonly corrupt: number;
1016
+ /** True when the file was longer than the pass reads: the counts are a floor. */
1017
+ readonly short: boolean;
1018
+ }
1019
+
1020
+ /** THIS package's tools, as the host names them. */
1021
+ export const COUNTERPARTS_TOOL = /^mcp__counterparts__/;
1022
+
1023
+ /**
1024
+ * **CAL.** How much of a transcript the pass reads. A night's run is a few
1025
+ * bundles of under 40,000 characters each, each recorded more than once — a
1026
+ * megabyte or two. 64 MiB is far past any night and still a bound.
1027
+ */
1028
+ export const SPILL_MAX_BYTES = 64 * 1024 * 1024;
1029
+
1030
+ const PERSISTED = /^<persisted-output>[ \t]*\r?\n(?:Output too large \(([^)\n]{1,40})\)\. Full output saved to: |Output exceeded the [^\n]{1,40} persist limit; only the first )/;
1031
+ const UNSAVED = /^<truncated-output>[ \t]*\r?\nOutput too large \(([^)\n]{1,40})\)\. It could not be saved, so only the first /;
1032
+ /** The count is the host's `toLocaleString()`: "51,306", "51.306" or "51 306" by the machine's locale. */
1033
+ const TOKENS = /^Error: result \((\d[\d.,'   ]{0,19} characters)[^)\n]{0,80}\) exceeds maximum allowed tokens\. (?:Output has been saved to |Failed to save output to file: )/;
1034
+ /**
1035
+ * The `token-cut` trailer, at the very end, with the REAL line breaks the host
1036
+ * writes around its bracket: inside our result's JSON a quoted line break is
1037
+ * the two characters `\n`, so no memory quoting the trailer can match it.
1038
+ */
1039
+ const TOKEN_CUT = /\n[ \t]*\[OUTPUT TRUNCATED - exceeded \d{1,9} token limit\][ \t]*\r?\n\s*The tool output was truncated\.[^\n]{0,400}$/;
1040
+ /** How near the end the `token-cut` trailer must start: it is about 300 characters long. */
1041
+ const TOKEN_CUT_TAIL = 800;
1042
+
1043
+ /**
1044
+ * THE HOST'S MARKER on one `tool_result`'s content, or null. The content is a
1045
+ * string or a list of blocks; the start-anchored markers are read off the
1046
+ * first text, the end-anchored one off the last.
1047
+ */
1048
+ export function spillOf(content: unknown): { shape: SpillShape; said: string | null } | null {
1049
+ const texts: string[] =
1050
+ typeof content === "string"
1051
+ ? [content]
1052
+ : Array.isArray(content)
1053
+ ? (content as unknown[]).flatMap((b) => (isEntry(b) && b["type"] === "text" && typeof b["text"] === "string" ? [b["text"]] : []))
1054
+ : [];
1055
+ const first = texts[0];
1056
+ const last = texts[texts.length - 1];
1057
+ if (first === undefined || last === undefined) return null;
1058
+ const head = first.trimStart();
1059
+ let m = PERSISTED.exec(head);
1060
+ if (m !== null) return { shape: "persisted", said: m[1] ?? null };
1061
+ m = UNSAVED.exec(head);
1062
+ if (m !== null) return { shape: "unsaved", said: m[1] ?? null };
1063
+ m = TOKENS.exec(head);
1064
+ if (m !== null) return { shape: "tokens", said: m[1] ?? null };
1065
+ if (TOKEN_CUT.test(last.slice(-TOKEN_CUT_TAIL))) return { shape: "token-cut", said: null };
1066
+ return null;
1067
+ }
1068
+
1069
+ /**
1070
+ * THE PASS, on a transcript's text: every assistant `tool_use` of ours, by id,
1071
+ * then every `tool_result` answering one, judged by `spillOf` — and every
1072
+ * `content-replacement` line's swap of one (the per-turn budget, above).
1073
+ * One result and at most one spill per call id. Exported so the rule is
1074
+ * testable without a file. Never throws.
1075
+ */
1076
+ export function parseToolSpills(raw: string, opts: { readonly tool?: RegExp } = {}): { results: number; spills: Spill[]; corrupt: number } {
1077
+ const ours = opts.tool ?? COUNTERPARTS_TOOL;
1078
+ const calls = new Map<string, { tool: string; phase: string | null }>();
1079
+ const answered = new Set<string>();
1080
+ const cutIds = new Set<string>();
1081
+ const spills: Spill[] = [];
1082
+ let corrupt = 0;
1083
+ const judge = (id: string, content: unknown, budget: boolean): void => {
1084
+ const call = calls.get(id);
1085
+ if (call === undefined) return;
1086
+ answered.add(id);
1087
+ if (cutIds.has(id)) return;
1088
+ const cut = spillOf(content);
1089
+ if (cut === null) return;
1090
+ cutIds.add(id);
1091
+ spills.push({ tool: call.tool, phase: call.phase, shape: budget ? "turn-budget" : cut.shape, said: cut.said });
1092
+ };
1093
+ for (const line of raw.split("\n")) {
1094
+ if (line.trim().length === 0) continue;
1095
+ let entry: unknown;
1096
+ try {
1097
+ entry = JSON.parse(line);
1098
+ } catch {
1099
+ corrupt += 1;
1100
+ continue;
1101
+ }
1102
+ if (!isEntry(entry)) {
1103
+ corrupt += 1;
1104
+ continue;
1105
+ }
1106
+ // The per-turn budget's swap, on a line of its own (see above).
1107
+ if (entry["type"] === "content-replacement") {
1108
+ const swaps = entry["replacements"];
1109
+ for (const r of Array.isArray(swaps) ? (swaps as unknown[]) : []) {
1110
+ if (isEntry(r) && r["kind"] === "tool-result" && typeof r["toolUseId"] === "string") judge(r["toolUseId"], r["replacement"], true);
1111
+ }
1112
+ continue;
1113
+ }
1114
+ const message = entry["message"];
1115
+ const content = isEntry(message) ? message["content"] : undefined;
1116
+ if (!Array.isArray(content)) continue;
1117
+ for (const block of content as unknown[]) {
1118
+ if (!isEntry(block)) continue;
1119
+ const id = block["id"];
1120
+ const name = block["name"];
1121
+ if (block["type"] === "tool_use" && typeof id === "string" && typeof name === "string" && ours.test(name)) {
1122
+ const input = block["input"];
1123
+ calls.set(id, { tool: name, phase: isEntry(input) && typeof input["phase"] === "string" ? input["phase"] : null });
1124
+ continue;
1125
+ }
1126
+ const answers = block["tool_use_id"];
1127
+ if (block["type"] !== "tool_result" || typeof answers !== "string") continue;
1128
+ judge(answers, block["content"], false);
1129
+ }
1130
+ }
1131
+ return { results: answered.size, spills, corrupt };
1132
+ }
1133
+
1134
+ /** Read one transcript and judge it. `absent` and `unreadable` are said apart from a clean read. Never throws. */
1135
+ export function readToolSpills(path: string | null | undefined, opts: { readonly maxBytes?: number; readonly tool?: RegExp } = {}): ToolSpills {
1136
+ const none = { results: 0, spills: [], corrupt: 0, short: false };
1137
+ if (path === null || path === undefined || path.trim().length === 0 || !existsSync(path)) return { reason: "absent", ...none };
1138
+ const maxBytes = opts.maxBytes ?? SPILL_MAX_BYTES;
1139
+ let size: number;
1140
+ try {
1141
+ size = statSync(path).size;
1142
+ } catch {
1143
+ return { reason: "unreadable", ...none };
1144
+ }
1145
+ const short = size > maxBytes;
1146
+ const head = readHead(path, Math.max(1, Math.min(maxBytes, size)));
1147
+ if (head === null) return { reason: "unreadable", ...none };
1148
+ // A short read is cut mid-line by construction: its last line is dropped.
1149
+ const text = short ? head.text.slice(0, Math.max(0, head.text.lastIndexOf("\n"))) : head.text;
1150
+ return { reason: "read", ...parseToolSpills(text, opts.tool === undefined ? {} : { tool: opts.tool }), short };
1151
+ }
1152
+
1153
+ // ── where the host keeps a session's transcript ─────────────────────────────
1154
+
1155
+ /** The host's own directory: `CLAUDE_CONFIG_DIR` when set, else `~/.claude`. */
1156
+ export function hostConfigDir(env: Readonly<Record<string, string | undefined>>): string {
1157
+ const moved = (env["CLAUDE_CONFIG_DIR"] ?? "").trim();
1158
+ return moved.length > 0 ? moved : join(homedir(), ".claude");
1159
+ }
1160
+
1161
+ /** **CAL.** Project directories the lookup asks before it gives up. */
1162
+ export const TRANSCRIPT_DIRS_MAX = 5_000;
1163
+
1164
+ /**
1165
+ * WHERE THE HOST WROTE A SESSION WHOSE ID WE CHOSE (`claude --session-id`):
1166
+ * `<config>/projects/<its directory, spelled as a name>/<id>.jsonl`. The
1167
+ * host's spelling turns every character but a letter or a digit into "-" —
1168
+ * read from 2.1.295, which also shortens a long one with a hash of its own and
1169
+ * may start from a git worktree's root — so that spelling is tried first (the
1170
+ * directory as given, then with its links resolved), and failing it every
1171
+ * project directory is asked for the file by name. The id is a fresh UUID, so
1172
+ * only one file can answer. Null when none does. Never throws.
1173
+ */
1174
+ export function hostTranscriptPath(input: { readonly configDir: string; readonly id: string; readonly cwd?: string }): string | null {
1175
+ const projects = join(input.configDir, "projects");
1176
+ const file = `${input.id}.jsonl`;
1177
+ const spell = (dir: string): string => dir.replace(/[^a-zA-Z0-9]/g, "-");
1178
+ const guesses: string[] = [];
1179
+ if (input.cwd !== undefined && input.cwd.length > 0) {
1180
+ guesses.push(spell(input.cwd));
1181
+ try {
1182
+ guesses.push(spell(realpathSync(input.cwd)));
1183
+ } catch {
1184
+ /* a directory gone since: the guess as given stands */
1185
+ }
1186
+ }
1187
+ for (const g of new Set(guesses)) {
1188
+ const p = join(projects, g, file);
1189
+ if (existsSync(p)) return p;
1190
+ }
1191
+ let dirs: string[];
1192
+ try {
1193
+ dirs = readdirSync(projects);
1194
+ } catch {
1195
+ return null;
1196
+ }
1197
+ for (const d of dirs.slice(0, TRANSCRIPT_DIRS_MAX)) {
1198
+ const p = join(projects, d, file);
1199
+ if (existsSync(p)) return p;
1200
+ }
1201
+ return null;
1202
+ }
@@ -185,6 +185,11 @@ snapshots and exports; the removal record; telemetry by reference.
185
185
  *`export` is NOT on `OWNER_OPS` (2026-09-20): an export reads the store and writes
186
186
  outside it, so under `--observer` the copy is made, the durable row is not, and the
187
187
  report says which.*
188
+ *Extended 2026-10-09.* The tree also holds one file per dream (`dreams/`: its journal
189
+ and its changes) and per reflection (`reflections/`: what it was asked, its entry, its
190
+ morning share and what became of it), dated like the journal. A dream or reflection
191
+ that was shown, changed or cites a memory that is confidential now is left out unless
192
+ `--include-confidential`, and counted apart from memory rows, at zero as well.
188
193
  8. **[M] Backups never leave the machine and never throw** — a backup problem must not
189
194
  block a consolidation cycle.
190
195
  9. **[M] Reads are pure.** Inspecting the protected list or the census writes nothing and
@@ -403,11 +403,15 @@ on every turn.
403
403
  count rows, not payloads; the lane is on each `band.promoted` row's payload and a
404
404
  dream's change count is on `dream.changed`'s. The builder is moving the lights into
405
405
  the shared `adapters/mechanism-evidence.ts` (master ef37eb1); that is where the
406
- Consolidation / Dreaming / Gist lines belong.
406
+ Consolidation / Dreaming / Gist lines belong. *(Half CLOSED 2026-09-26 by #251
407
+ (`197e1ca`), noted 2026-10-09: the Dreaming line counts a week's dreams and their
408
+ changes, and since #262 its core suggestions apart. The lane is still not said: Consolidation reads only
409
+ "N memories became core".)*
407
410
  - **A dream's journal cannot be removed from the console.** `remove` takes memory ids,
408
411
  and a journal is not a memory (it lives in the `dreams` table). An owner who wants a
409
412
  journal gone has `dream --undo`, which keeps it marked undone. A `dream --forget <id>`
410
413
  would need a store write that blanks the journal text; not built.
411
- - **`export --markdown` does not carry the dreams table** (the journals, the change
412
- logs): it walks memories. The database export and `backup` copy the whole file, so
413
- they do.
414
+ - ~~**`export --markdown` does not carry the dreams table**~~ — CLOSED 2026-10-09: it
415
+ writes `dreams/` (each journal and its change log) and `reflections/` (each entry and
416
+ morning share) beside the memories. What a dream was shown and what undoing it needs
417
+ stay in the database, which the database export and `backup` copy whole.
@@ -1886,3 +1886,114 @@ words only and prints nothing about it — doctor and the backfill name a missin
1886
1886
  `counterparts mechanisms` (no mechanism line of its own: traits feed nothing), so it
1887
1887
  shows in the plumbing count and in `mechanisms --all`. No doctor line: nothing there
1888
1888
  fits without forcing it.
1889
+
1890
+ ## 2026-10-09 — dreams and reflections in `export --markdown`; `connect`'s count
1891
+
1892
+ - **The readable tree carries the nights** (dream INTERFACE-GAPS §4 and §7). One file per
1893
+ dream under `dreams/<year>/<date>-<id>.md` and per reflection under `reflections/…`, the
1894
+ journal's own layout. A dream's file is its journal, then its changes in `dream --show`'s
1895
+ words (`dream-core.ts#dreamChangeWords`, now shared), then the reflections after it; a
1896
+ reflection's is what it was asked, its entry, what that rests on, and its morning share
1897
+ with what became of it. The front matter has the memory files' fence and `key: value`
1898
+ lines but **no `payload:` line** — that line is how a future importer reads a memory
1899
+ back, and a dream's journal is kept out of `memories` so it is never taken for something
1900
+ lived. The database export needed nothing: it already carries both tables whole. There is
1901
+ no JSON export.
1902
+ - **A night that rests on a confidential memory is left out unless
1903
+ `--include-confidential`**, counted apart from memory rows (terminal, manifest, and the
1904
+ `store.export` row's `omittedDreams` / `omittedReflections`). "Rests on" is: shown it,
1905
+ changed it, cites it, or its entry is it — asked of the memories as they are now. Since
1906
+ #318 a dream's bundle is read as a guest (`BUNDLE_OWNER`), so a night is not shown a
1907
+ confidential memory in the first place; what this catches is a memory marked
1908
+ confidential after the night that saw it. A removed memory does not count: the removal
1909
+ already redacted every night that was shown it. Expected to fire rarely.
1910
+ - **`connect`'s count said "N sessions are running the previous version's memory server"
1911
+ over every memory server in the process table**, comparing nothing — the 0.3.12 release
1912
+ run got 11, the owner's own open sessions and the one it was typed into among them. Each
1913
+ server leaves `sessions/mcp-server@<pid>.json` in its store with its build and its
1914
+ parent (`sessions.ts#recordServerLaunch`), so the count now sorts them
1915
+ (`wire.ts#serverCensus`): another build (its version named), this build, or no record in
1916
+ this store (another store's, a directory where memory is off, or a build from before
1917
+ servers recorded themselves — "not known here"). `ps` now also gives the parent column,
1918
+ so the session the command was typed into is the one whose server's parent is one of
1919
+ this process's ancestors, and it is named in whichever group it is in. Without that
1920
+ column, and run from inside Claude Code (`hosts.ts#claudeCodeEnvMarker`), the line says
1921
+ it cannot tell which one is this session's rather than guess. Claude Desktop's server, if
1922
+ it is running, is counted as an open session, as before.
1923
+ - **Review of #331.** The night files are decided in two passes, so a reflection whose
1924
+ dream was left out says so instead of naming a path that is not in the tree (and the
1925
+ other way round). `ps` is asked `-axwwo`: procps on Linux cuts `command` at `$COLUMNS`
1926
+ when that is exported, even into a pipe, and the cut can fall before the
1927
+ `mcp/bin/serve` segment `processMark` reads; master had the same exposure. A server
1928
+ whose record went stale is "no current record", not "no record". The one way a
1929
+ journal can still carry a confidential memory's words past the id rule — an in-session
1930
+ dream on the owner's server, using `recall` freely — is upstream of the export (the
1931
+ dashboard shows that journal too), and is left as a question for the owner.
1932
+
1933
+ ## 2026-10-09 — `ask --mode meaning`
1934
+
1935
+ The dashboard's "by meaning" went through `ask`, and `ask` answered every question in
1936
+ facts mode, so there was no door to meaning mode from the console at all. `--mode`
1937
+ takes `facts` (the default; saying it changes nothing) or `meaning`, the MCP tool's two
1938
+ words. Meaning has no short list: its rendering is already short, so without `--json`
1939
+ the console prints `renderMeaning` under the `Store:` line. A mode that is neither is
1940
+ refused before the store opens. `--voiced` is read again here: a question typed at the
1941
+ console is the owner's, so its "I" is his (`asker: "owner"`); one the dashboard turned
1942
+ into my voice is mine.
1943
+
1944
+ ## 2026-10-09 — `waiting` and `done` in `mechanisms --all`; the host's directory under `CLAUDE_CONFIG_DIR`
1945
+
1946
+ - **Two new states in the `fired` report** (`adapters/fired.ts#Cadence`), printed by
1947
+ `mechanisms --all` and the dashboard's what-fired panel without change to either
1948
+ (both iterate `STATE_ORDER`): `waiting`, for a row that fires only on an occasion that
1949
+ has not come, and `done`, for a one-time job that ran. They sort after `new`, with
1950
+ the states that are not silence. Classified only where the row's own description
1951
+ makes it obvious:
1952
+ - **one-time:** `upgrade-census`.
1953
+ - **occasion, the owner's action:** `export`, `removal`, `unmerge`, `core-demote`,
1954
+ `protection` (blind anyway once a memory is protected), `accommodation`.
1955
+ - **occasion, a failure:** `worker-trouble`, `snapshot-trouble`. A failure that fired
1956
+ last week and not this week used to count as "went quiet", amber on good news.
1957
+ - **occasion, something that happens to memories:** `prospective-plain` (checked:
1958
+ `plain-due`), `prospective-fired`, `revision`, `contradictions`, `result-cut`,
1959
+ `dedup`.
1960
+ - **Left alone on purpose:** the rare-but-arithmetic rows (`promotion`, `prune`,
1961
+ `fade`, `gist`) and the ones whose occasion is not plain from the label
1962
+ (`sweep-wake`, `chunk-gate`: both fire only when the crash fallback reads a
1963
+ transcript, and `sweep.gate`'s `SWEPT` count could become their check; also
1964
+ `prospective-dated`, `embed`). Each is a one-line `cadence` away.
1965
+ - **`memory.merged` has never fired on the owner's store, and the wiring is sound.** The
1966
+ night's dedup runs every cycle, but no similarity source is handed to it
1967
+ (`counterpart.ts` calls `runCycle` without `candidates`), so it only merges
1968
+ byte-identical bodies, and the door already refuses an identical deposit in the same
1969
+ directory (`DUPLICATE_CONTENT`). Reproduced on the seeded demo store: 30 cycles ran the
1970
+ phase (29 `ran-nothing-found`, 1 `ran`, merging the seed's planted copy). A second
1971
+ deposit of the same words was refused from the same directory, landed from another
1972
+ one, and was merged that night (`identical-content-hash`). The dream's merges of near
1973
+ copies are `dream.changed` rows, read by `dream-changes` and by the short view's
1974
+ Consolidation line; folding them into `dedup` would count one merge twice. So `dedup`
1975
+ is an occasion row now, with the label "an exact copy of a memory is merged into the
1976
+ one it copies, overnight". Handing the night a cosine source is a separate decision
1977
+ (the "ambiguous near-duplicates are left alone" ruling in `sleep/dedup.ts`).
1978
+ - **The short view's Prospective line** reads `occasionMissed` from the `prospective-plain`
1979
+ row, so a week with a plain reminder due and not said never reads "nothing due".
1980
+ - **`CLAUDE_CONFIG_DIR` is the host's directory, not a home.** The user settings file was
1981
+ `hostConfigBase` + `.claude/settings.json`, which is `$CLAUDE_CONFIG_DIR/.claude/settings.json`
1982
+ when the variable is set. The host's documentation (env-vars, settings, the
1983
+ `.claude` directory page, read 2026-10-09) says the variable replaces `~/.claude`, so
1984
+ its settings are `$CLAUDE_CONFIG_DIR/settings.json`. `connect` wrote the wrong file,
1985
+ doctor read the same wrong file and went green, and the host ran nothing.
1986
+ `install.ts#hostSettingsDir` is the one place that knows now: `readHost`,
1987
+ `wire.ts#userSettingsPath`, and `install`'s "is Claude Code here" check
1988
+ (`commands.ts#claudeCodeHere`, which looked for a `.claude` inside the variable) all ask
1989
+ it. The MCP file is unchanged (`$CLAUDE_CONFIG_DIR/.claude.json` under the variable):
1990
+ `~/.claude.json` is not a `~/.claude` path, so the docs' sentence does not move it.
1991
+ Confirmed against the 2.1.295 binary in review: the global config file is
1992
+ `join(process.env.CLAUDE_CONFIG_DIR || homedir(), ".claude.json")`, unless a legacy
1993
+ `.config.json` exists inside the configuration directory, which then wins (not handled
1994
+ here, before or after this change); user settings are `join(<configuration directory>,
1995
+ "settings.json")`, the directory being `CLAUDE_CONFIG_DIR` or `~/.claude`.
1996
+ - **`uninstall`'s guard against parking the host's own directory** named `~/.claude`
1997
+ only; in review it learned `hostSettingsDir` too, so with
1998
+ `CLAUDE_CONFIG_DIR=~/.claude-work` an `--config` inside that directory is refused the
1999
+ same way (`configDirRefusal`'s optional `env`, passed through `planUninstall`).