counterparts 0.3.12 → 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 (116) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/docs/module-map.md +1 -1
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/CONTRACT.md +36 -10
  5. package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
  6. package/src/adapters/claude-code/NOTES.md +131 -0
  7. package/src/adapters/claude-code/bin/hook.ts +35 -2
  8. package/src/adapters/claude-code/doctor.ts +155 -21
  9. package/src/adapters/claude-code/hooks.ts +49 -7
  10. package/src/adapters/claude-code/index.ts +11 -0
  11. package/src/adapters/claude-code/night-run.ts +133 -12
  12. package/src/adapters/claude-code/transcript.ts +268 -1
  13. package/src/adapters/cli/CONTRACT.md +5 -0
  14. package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
  15. package/src/adapters/cli/NOTES.md +111 -0
  16. package/src/adapters/cli/commands.ts +65 -14
  17. package/src/adapters/cli/dream-core.ts +57 -42
  18. package/src/adapters/cli/export.ts +320 -21
  19. package/src/adapters/cli/index.ts +1 -0
  20. package/src/adapters/cli/install.ts +39 -7
  21. package/src/adapters/cli/mechanisms.ts +7 -1
  22. package/src/adapters/cli/uninstall.ts +13 -5
  23. package/src/adapters/cli/wire.ts +189 -63
  24. package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
  25. package/src/adapters/dashboard/NOTES.md +79 -0
  26. package/src/adapters/dashboard/registries.ts +10 -2
  27. package/src/adapters/dashboard/web/README.md +19 -14
  28. package/src/adapters/dashboard/web/actions.ts +23 -1
  29. package/src/adapters/dashboard/web/flow.ts +4 -1
  30. package/src/adapters/dashboard/web/lanes.ts +3 -0
  31. package/src/adapters/dashboard/web/narrate.ts +30 -2
  32. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
  33. package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
  34. package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
  35. package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
  36. package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
  37. package/src/adapters/dashboard/web/server.ts +0 -5
  38. package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
  39. package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
  40. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
  41. package/src/adapters/dashboard/web/views/health.ts +1 -1
  42. package/src/adapters/dashboard/web/views/search.ts +4 -45
  43. package/src/adapters/dashboard/web/views.ts +2 -2
  44. package/src/adapters/fired.ts +410 -25
  45. package/src/adapters/host-wiring.ts +300 -0
  46. package/src/adapters/lifecycle.ts +14 -0
  47. package/src/adapters/log/index.ts +2 -0
  48. package/src/adapters/mcp/CONTRACT.md +33 -3
  49. package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
  50. package/src/adapters/mcp/NOTES.md +136 -0
  51. package/src/adapters/mcp/bin/serve.ts +30 -0
  52. package/src/adapters/mcp/facts.ts +13 -1
  53. package/src/adapters/mcp/meaning.ts +208 -13
  54. package/src/adapters/mcp/server.ts +87 -15
  55. package/src/adapters/mcp/stdio.ts +3 -1
  56. package/src/adapters/mcp/stood-down.ts +51 -0
  57. package/src/adapters/mcp/tools.ts +27 -7
  58. package/src/adapters/plugin-run.sh +133 -0
  59. package/src/adapters/plugin.ts +329 -0
  60. package/src/core/associate/CONTRACT.md +2 -1
  61. package/src/core/associate/INTERFACE-GAPS.md +6 -1
  62. package/src/core/associate/NOTES.md +45 -0
  63. package/src/core/briefing.ts +12 -3
  64. package/src/core/contradictions.ts +184 -0
  65. package/src/core/counterpart.ts +451 -18
  66. package/src/core/dream/CONTRACT.md +5 -2
  67. package/src/core/dream/INTERFACE-GAPS.md +29 -6
  68. package/src/core/dream/NOTES.md +21 -0
  69. package/src/core/dream/index.ts +33 -1
  70. package/src/core/dream/reflect.ts +20 -5
  71. package/src/core/encode/INTERFACE-GAPS.md +3 -1
  72. package/src/core/fit/INTERFACE-GAPS.md +8 -2
  73. package/src/core/fit/NOTES.md +5 -2
  74. package/src/core/fit/index.ts +4 -1
  75. package/src/core/handoff/CONTRACT.md +37 -2
  76. package/src/core/handoff/INTERFACE-GAPS.md +10 -0
  77. package/src/core/handoff/NOTES.md +66 -0
  78. package/src/core/handoff/index.ts +214 -12
  79. package/src/core/mint.ts +8 -2
  80. package/src/core/physics/CONTRACT.md +11 -1
  81. package/src/core/physics/NOTES.md +30 -0
  82. package/src/core/physics/index.ts +26 -4
  83. package/src/core/prospective/CONTRACT.md +45 -6
  84. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  85. package/src/core/prospective/NOTES.md +138 -0
  86. package/src/core/prospective/derive.ts +33 -5
  87. package/src/core/prospective/index.ts +90 -5
  88. package/src/core/prospective/windows.ts +72 -1
  89. package/src/core/recall/CONTRACT.md +6 -2
  90. package/src/core/recall/INTERFACE-GAPS.md +28 -4
  91. package/src/core/recall/NOTES.md +57 -1
  92. package/src/core/recall/probe.ts +58 -0
  93. package/src/core/recall/session.ts +27 -3
  94. package/src/core/recall/time-ask.ts +116 -18
  95. package/src/core/remember/CONTRACT.md +4 -1
  96. package/src/core/remember/INTERFACE-GAPS.md +9 -1
  97. package/src/core/remember/proposals.ts +38 -5
  98. package/src/core/revision.ts +5 -0
  99. package/src/core/schemas/CONTRACT.md +13 -1
  100. package/src/core/schemas/INTERFACE-GAPS.md +20 -2
  101. package/src/core/schemas/NOTES.md +127 -0
  102. package/src/core/schemas/types.ts +2 -0
  103. package/src/core/self/CONTRACT.md +15 -4
  104. package/src/core/self/INTERFACE-GAPS.md +7 -2
  105. package/src/core/self/NOTES.md +49 -0
  106. package/src/core/self/briefing.ts +12 -2
  107. package/src/core/self/index.ts +82 -8
  108. package/src/core/self/page.ts +88 -0
  109. package/src/core/sleep/INTERFACE-GAPS.md +22 -3
  110. package/src/core/sleep/NOTES.md +11 -0
  111. package/src/core/sleep/prune.ts +6 -2
  112. package/src/core/store/NOTES.md +14 -0
  113. package/src/core/store/index.ts +107 -0
  114. package/src/core/time.ts +152 -0
  115. package/tools/install-loop/run.sh +48 -12
  116. 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`).
@@ -104,8 +104,10 @@ import type { Band, Kind } from "../../core/types.js";
104
104
  // so the direction stays one-way.
105
105
  import { deliberateRecall, embedQuestion } from "../mcp/deliberate.js";
106
106
  // A question at the console is answered in FACTS MODE, the MCP `recall`'s own
107
- // path (2026-10-03), for the same reason.
107
+ // path (2026-10-03), for the same reason — and in MEANING MODE, its other path,
108
+ // when `--mode meaning` asks for it (2026-10-09).
108
109
  import { factsRecall, renderFacts } from "../mcp/facts.js";
110
+ import { meaningRecall, renderMeaning } from "../mcp/meaning.js";
109
111
  // The ONE rule for "which host configuration": the console resolves it with the
110
112
  // same function the hook, the worker and the MCP server do.
111
113
  import {
@@ -185,7 +187,7 @@ import {
185
187
  configObject,
186
188
  resolveEmbedderBlock,
187
189
  hookCommand,
188
- hostConfigBase,
190
+ hostSettingsDir,
189
191
  installLayout,
190
192
  parkedSiblings,
191
193
  throwawayDefaultRefusal,
@@ -686,8 +688,8 @@ export const COMMAND_FLAGS: Record<Command, readonly string[]> = {
686
688
  note: ["kind", "title", "salience", "config"],
687
689
  // Two names, ONE row each and the same one: a flag that worked under `recall`
688
690
  // and not under `ask` would be the rename leaking into behaviour.
689
- ask: ["id", "json", "full", "page", "config", "voiced"],
690
- recall: ["id", "json", "full", "page", "config", "voiced"],
691
+ ask: ["id", "json", "full", "page", "mode", "config", "voiced"],
692
+ recall: ["id", "json", "full", "page", "mode", "config", "voiced"],
691
693
  export: [
692
694
  "out",
693
695
  "passphrase",
@@ -798,7 +800,7 @@ export const COMMAND_BLURB: Record<Command, string> = {
798
800
  "Put back beliefs and current-state rows the nightly dedup pass archived as duplicates of an ordinary memory. Dry run unless --apply. --apply requires --dir.",
799
801
  rebrief: "Re-render and republish the wake bundle NOW, through the boundary's own renderer.",
800
802
  "probe-oq4":
801
- "The OQ4 probe: footnotes delivered vs. later expanded, by calendar date, from recall.decision and recall.credit rows. Read-only.",
803
+ "The OQ4 probe: footnotes delivered vs. later expanded, by calendar date, from recall.decision and recall.credit rows, then recall's hit rate — of what it showed, how much a reply expanded or quoted, loud, footnoted and pointer. Read-only.",
802
804
  mechanisms:
803
805
  "Is each memory mechanism working? One line per mechanism, with a light (● working this week, ◐ built but not firing, ○ not built yet) and the count from the store behind it, then the plumbing in one line that names only what is failing. --all prints the full report: every part, silent first, when it last fired, how often in the last 7 days, what it turned away, and why the store cannot tell for the ones nothing records. Read-only.",
804
806
  fired:
@@ -892,18 +894,21 @@ const FLAG_HELP: Record<string, string> = {
892
894
  salience: "0..1 — how much this one matters",
893
895
  id: "one memory, by id, instead of a question",
894
896
  full: "the whole facts answer, as the model reads it: a count header and every result's labeled lines (who said it, its status, when it happened and was learned, whether it still holds) — not just the top five, one line each",
895
- page: "which page of the answer (ten results a page), with --full or --json",
897
+ page: "which page of the answer (ten results a page; in meaning mode, eight entries of the arc), with --full or --json",
898
+ mode: "facts (the default): every memory that answers the question, counted and paged — or meaning: what a person, a project or a feeling has been over time, the chapters that hold it in time order",
896
899
  // TWO COMMANDS, ONE SENTENCE (`recall --json` is the MCP tool's payload,
897
900
  // `doctor --json` is the findings): the table is keyed by flag NAME, so the
898
901
  // sentence has to be true of both.
899
902
  json: "machine-readable output — the structured payload rather than the console's rendering",
900
903
  voiced:
901
- "the question is already in the counterpart's own voice (the dashboard's rewrite); accepted, and read by no facts answer since 2026-10-03 — feelings are meaning mode's",
904
+ "the question is already in the counterpart's own voice (the dashboard's rewrite): in meaning mode its \"I\" is the counterpart, so a question about feeling asks about the counterpart's feelings; a facts answer reads no feelings and is the same either way",
902
905
  out: "the directory to write into",
903
906
  passphrase: "encrypt the export with this secret",
904
907
  plaintext: "do not encrypt the export (said on purpose, never by default)",
905
- markdown: "export the readable markdown tree instead of the database file",
906
- "include-confidential": "include confidential memories in the markdown tree (they are omitted, and counted, by default)",
908
+ markdown:
909
+ "export the readable markdown tree instead of the database file: memories, the journal, the self page, and a file per dream and per reflection (its README says what is where)",
910
+ "include-confidential":
911
+ "include confidential memories in the markdown tree, and the dreams and reflections that rest on one (they are omitted, and counted, by default)",
907
912
  // NOT `--versions`: `self-page` takes both `--versions` and `--version`, and
908
913
  // the help-page totality test reads flags as substrings — an `export
909
914
  // --versions` puts the string `--version` on export's page, where it names a
@@ -1183,6 +1188,7 @@ const VALUED_FLAGS: readonly string[] = [
1183
1188
  "version",
1184
1189
  "restore",
1185
1190
  "if-version",
1191
+ "mode",
1186
1192
  "show",
1187
1193
  "demote",
1188
1194
  "pair",
@@ -1330,6 +1336,8 @@ export function parse(argv: readonly string[]): Parsed {
1330
1336
  full: { type: "boolean" },
1331
1337
  // `ask`'s page of a facts answer (2026-10-03).
1332
1338
  page: { type: "string" },
1339
+ // `ask`'s mode: facts (the default) or meaning (2026-10-09).
1340
+ mode: { type: "string" },
1333
1341
  // `ask`'s: the question is already in the counterpart's voice (U13).
1334
1342
  voiced: { type: "boolean" },
1335
1343
  apply: { type: "boolean" },
@@ -2715,6 +2723,11 @@ export function firedLines(report: FiredReport, all = false): string[] {
2715
2723
  if (report.wentBlocked.length > 0) {
2716
2724
  lines.push(`Fired last week and STOPPED this week: ${report.wentBlocked.join("; ")}`, "");
2717
2725
  }
2726
+ // An occasion that came and was not answered (2026-10-09): the one silence
2727
+ // among the `waiting` rows that is still a fault, said before the groups.
2728
+ if (report.missedOccasion.length > 0) {
2729
+ lines.push(`Its occasion came this week and it did not fire: ${report.missedOccasion.join("; ")}`, "");
2730
+ }
2718
2731
  if (report.wentQuiet.length > 0) {
2719
2732
  lines.push(`Fired last week and not once this week: ${report.wentQuiet.join("; ")}`, "");
2720
2733
  }
@@ -3889,8 +3902,9 @@ async function installConversation(
3889
3902
  *
3890
3903
  * Two questions, and either one answering yes is enough, because they fail in
3891
3904
  * opposite directions. The DIRECTORY is what a person who has ever run Claude
3892
- * Code has — `CLAUDE_CONFIG_DIR` moves it, and `install.ts#hostConfigBase` is
3893
- * the one place that knows so. The BINARY on PATH is what a fresh install has
3905
+ * Code has — `CLAUDE_CONFIG_DIR` moves it (and IS it, when set: not a
3906
+ * `.claude` inside it, 2026-10-09), and `install.ts#hostSettingsDir` is the one
3907
+ * place that knows so. The BINARY on PATH is what a fresh install has
3894
3908
  * before it has been run, and the reason `install.ts`'s own docstring exists: a
3895
3909
  * process's PATH is not a login shell's, so a `claude` we cannot see may still
3896
3910
  * be there for the person.
@@ -3905,7 +3919,7 @@ function claudeCodeHere(
3905
3919
  env: Record<string, string | undefined>,
3906
3920
  spawner: Spawner,
3907
3921
  ): boolean {
3908
- if (existsSync(join(hostConfigBase(home, env), ".claude"))) return true;
3922
+ if (existsSync(hostSettingsDir(home, env))) return true;
3909
3923
  return !spawner(["--version"]).missing;
3910
3924
  }
3911
3925
 
@@ -4227,7 +4241,7 @@ async function hostWiringCommand(
4227
4241
  result.outcome === "ok" &&
4228
4242
  (result.hooks !== "already" || result.mcp !== "already")
4229
4243
  ) {
4230
- sessionsNote(ui(io, env), lister);
4244
+ sessionsNote(ui(io, env), lister, { dataDir: store, env });
4231
4245
  }
4232
4246
  return exitFor(result.outcome);
4233
4247
  }
@@ -5722,6 +5736,15 @@ async function recallCommand(
5722
5736
  io.err("refused: a question and --id are two different asks. Send one.");
5723
5737
  return EXIT.usage;
5724
5738
  }
5739
+ // THE MODE, as the MCP `recall` takes it (2026-10-09): facts unless meaning
5740
+ // is asked for by name. Read before the store opens, so a mistyped mode is a
5741
+ // refusal rather than a facts answer to a question meant for the arc. With
5742
+ // `--id` there is no question to answer in a mode, and it is not read.
5743
+ const modeFlag = parsed.flags["mode"];
5744
+ if (modeFlag !== undefined && modeFlag !== "facts" && modeFlag !== "meaning") {
5745
+ io.err(`refused: --mode is facts or meaning, not ${typeof modeFlag === "string" ? JSON.stringify(modeFlag) : "empty"}.`);
5746
+ return EXIT.usage;
5747
+ }
5725
5748
  if (!storeExists(dir)) {
5726
5749
  io.err(`no store at ${dir}. Run 'counterparts install' first.`);
5727
5750
  return EXIT.failed;
@@ -5752,10 +5775,32 @@ async function recallCommand(
5752
5775
  // same call the MCP `recall` makes (`mcp/deliberate.ts#embedQuestion`).
5753
5776
  if (idFlag.length === 0) {
5754
5777
  const embedded = await embedQuestion(embedder, question);
5778
+ const page = typeof parsed.flags["page"] === "string" && /^[1-9]\d*$/.test(parsed.flags["page"]) ? { page: Number(parsed.flags["page"]) } : {};
5779
+ // MEANING MODE: the arc, the MCP `recall`'s `mode: "meaning"` path. Whose
5780
+ // "I" a question about feeling means is the one thing the console adds:
5781
+ // a question typed here is the owner's, so his; one the dashboard turned
5782
+ // into my voice (`--voiced`) is mine. Its rendering is already short, so
5783
+ // there is no list form: `--json` is the payload, anything else the answer.
5784
+ if (modeFlag === "meaning") {
5785
+ const meaning = meaningRecall(
5786
+ {
5787
+ counterpart,
5788
+ sessionId: "console",
5789
+ owner: true,
5790
+ vector: embedded.vector,
5791
+ semantic: embedded.semantic,
5792
+ asker: parsed.flags["voiced"] === true ? "self" : "owner",
5793
+ },
5794
+ question,
5795
+ page,
5796
+ );
5797
+ io.out(parsed.flags["json"] === true ? JSON.stringify(meaning, null, 2) : renderMeaning(meaning));
5798
+ return EXIT.ok;
5799
+ }
5755
5800
  const facts = factsRecall(
5756
5801
  { counterpart, sessionId: "console", owner: true, vector: embedded.vector, semantic: embedded.semantic },
5757
5802
  question,
5758
- typeof parsed.flags["page"] === "string" && /^[1-9]\d*$/.test(parsed.flags["page"]) ? { page: Number(parsed.flags["page"]) } : {},
5803
+ page,
5759
5804
  );
5760
5805
  if (parsed.flags["json"] === true) {
5761
5806
  io.out(JSON.stringify(facts, null, 2));
@@ -7081,6 +7126,12 @@ function exportCommand(
7081
7126
  omittedConfidential: report.omittedConfidential,
7082
7127
  versions: flags["with-versions"] === true,
7083
7128
  notRendered: report.notRendered.length,
7129
+ // The nights, counted apart from `rows` (2026-10-09): the
7130
+ // dashboard reads `rows` as memories.
7131
+ dreams: report.dreams,
7132
+ reflections: report.reflections,
7133
+ omittedDreams: report.omittedDreams,
7134
+ omittedReflections: report.omittedReflections,
7084
7135
  },
7085
7136
  });
7086
7137
  } catch {