counterparts 0.3.2 → 0.3.4

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 (153) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/docs/module-map.md +3 -2
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/NOTES.md +28 -0
  5. package/src/adapters/claude-code/bin/hook.ts +85 -22
  6. package/src/adapters/claude-code/config.ts +7 -0
  7. package/src/adapters/claude-code/doctor.ts +166 -4
  8. package/src/adapters/claude-code/hooks.ts +185 -6
  9. package/src/adapters/claude-code/index.ts +3 -0
  10. package/src/adapters/claude-code/transcript.ts +7 -0
  11. package/src/adapters/cli/CONTRACT.md +11 -0
  12. package/src/adapters/cli/INTERFACE-GAPS.md +16 -0
  13. package/src/adapters/cli/NOTES.md +25 -0
  14. package/src/adapters/cli/commands.ts +184 -4
  15. package/src/adapters/cli/dream-core.ts +126 -0
  16. package/src/adapters/cli/help.ts +17 -0
  17. package/src/adapters/cli/mechanisms.ts +199 -106
  18. package/src/adapters/dashboard/CONTRACT.md +5 -0
  19. package/src/adapters/dashboard/INTERFACE-GAPS.md +12 -0
  20. package/src/adapters/dashboard/NOTES.md +38 -0
  21. package/src/adapters/dashboard/registries.ts +35 -1
  22. package/src/adapters/dashboard/web/README.md +63 -26
  23. package/src/adapters/dashboard/web/app.html +2 -0
  24. package/src/adapters/dashboard/web/flow.ts +14 -0
  25. package/src/adapters/dashboard/web/lanes.ts +141 -0
  26. package/src/adapters/dashboard/web/mechanisms/association/index.js +1 -2
  27. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +8 -5
  28. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +7 -7
  29. package/src/adapters/dashboard/web/mechanisms/decay/index.js +1 -2
  30. package/src/adapters/dashboard/web/mechanisms/dreaming/index.js +19 -0
  31. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +9 -6
  32. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +4 -5
  33. package/src/adapters/dashboard/web/mechanisms/index.js +5 -3
  34. package/src/adapters/dashboard/web/mechanisms/interference/index.js +1 -2
  35. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +7 -5
  36. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +1 -2
  37. package/src/adapters/dashboard/web/mechanisms/regions.js +1 -1
  38. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +1 -2
  39. package/src/adapters/dashboard/web/mechanisms/salience/index.js +1 -2
  40. package/src/adapters/dashboard/web/mechanisms/schema/index.js +1 -2
  41. package/src/adapters/dashboard/web/narrate.ts +76 -13
  42. package/src/adapters/dashboard/web/pages/health/sections/checks.js +17 -1
  43. package/src/adapters/dashboard/web/pages/home/home.css +29 -13
  44. package/src/adapters/dashboard/web/pages/home/index.js +2 -0
  45. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +22 -7
  46. package/src/adapters/dashboard/web/pages/home/sections/hero.js +15 -3
  47. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +15 -9
  48. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +6 -2
  49. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +35 -18
  50. package/src/adapters/dashboard/web/pages/memories/index.js +30 -36
  51. package/src/adapters/dashboard/web/pages/memories/memories.css +97 -72
  52. package/src/adapters/dashboard/web/pages/memories/row.js +51 -0
  53. package/src/adapters/dashboard/web/pages/memories/sections/feel.js +176 -0
  54. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +67 -0
  55. package/src/adapters/dashboard/web/pages/memories/sections/list.js +65 -43
  56. package/src/adapters/dashboard/web/pages/memories/sections/search.js +26 -23
  57. package/src/adapters/dashboard/web/pages/memories/state.js +12 -5
  58. package/src/adapters/dashboard/web/pages/self/index.js +57 -16
  59. package/src/adapters/dashboard/web/pages/self/sections/dreams.js +76 -0
  60. package/src/adapters/dashboard/web/pages/self/sections/journal.js +75 -19
  61. package/src/adapters/dashboard/web/pages/self/sections/page.js +108 -65
  62. package/src/adapters/dashboard/web/pages/self/sections/settling.js +129 -104
  63. package/src/adapters/dashboard/web/pages/self/sections/wake.js +31 -15
  64. package/src/adapters/dashboard/web/pages/self/self.css +122 -59
  65. package/src/adapters/dashboard/web/pages/self/state.js +21 -0
  66. package/src/adapters/dashboard/web/server.ts +9 -0
  67. package/src/adapters/dashboard/web/shared/memory-marks.css +17 -0
  68. package/src/adapters/dashboard/web/shared/memory-marks.js +81 -0
  69. package/src/adapters/dashboard/web/shared/memory-modal.js +240 -53
  70. package/src/adapters/dashboard/web/shared/modal.css +67 -0
  71. package/src/adapters/dashboard/web/shared/tip.js +1 -1
  72. package/src/adapters/dashboard/web/shared/widgets/feed.css +4 -0
  73. package/src/adapters/dashboard/web/shared/widgets/feed.js +56 -14
  74. package/src/adapters/dashboard/web/shared/widgets/light.css +1 -0
  75. package/src/adapters/dashboard/web/shared/widgets/light.js +7 -5
  76. package/src/adapters/dashboard/web/shared/widgets/tips.css +19 -0
  77. package/src/adapters/dashboard/web/shared/widgets/tips.js +56 -0
  78. package/src/adapters/dashboard/web/views/activity.ts +18 -2
  79. package/src/adapters/dashboard/web/views/archive-words.ts +27 -10
  80. package/src/adapters/dashboard/web/views/dreams.ts +199 -0
  81. package/src/adapters/dashboard/web/views/mechanism-panel.ts +116 -35
  82. package/src/adapters/dashboard/web/views/mechanisms.ts +81 -255
  83. package/src/adapters/dashboard/web/views/memories.ts +245 -43
  84. package/src/adapters/dashboard/web/views/memory-words.ts +133 -0
  85. package/src/adapters/dashboard/web/views/memory.ts +226 -4
  86. package/src/adapters/dashboard/web/views/mind.ts +261 -61
  87. package/src/adapters/dashboard/web/views/overview.ts +80 -42
  88. package/src/adapters/dashboard/web/views/search.ts +35 -1
  89. package/src/adapters/dashboard/web/views/shared.ts +14 -0
  90. package/src/adapters/dashboard/web/views.ts +2 -0
  91. package/src/adapters/feelings-line.ts +74 -0
  92. package/src/adapters/fired.ts +163 -23
  93. package/src/adapters/mcp/CONTRACT.md +8 -0
  94. package/src/adapters/mcp/NOTES.md +56 -0
  95. package/src/adapters/mcp/server.ts +254 -6
  96. package/src/adapters/mcp/tools.ts +180 -5
  97. package/src/adapters/mechanism-evidence.ts +465 -0
  98. package/src/core/bridge.ts +21 -16
  99. package/src/core/counterpart.ts +422 -10
  100. package/src/core/dream/CONTRACT.md +143 -0
  101. package/src/core/dream/INTERFACE-GAPS.md +24 -0
  102. package/src/core/dream/NOTES.md +84 -0
  103. package/src/core/dream/index.ts +1067 -0
  104. package/src/core/dream/mark.ts +14 -0
  105. package/src/core/dream/tunables.ts +56 -0
  106. package/src/core/encode/CONTRACT.md +7 -1
  107. package/src/core/feelings-wheel.ts +171 -13
  108. package/src/core/mint.ts +9 -0
  109. package/src/core/physics/CONTRACT.md +132 -21
  110. package/src/core/physics/NOTES.md +233 -0
  111. package/src/core/physics/index.ts +419 -50
  112. package/src/core/prospective/CONTRACT.md +35 -6
  113. package/src/core/prospective/INTERFACE-GAPS.md +10 -5
  114. package/src/core/prospective/NOTES.md +175 -4
  115. package/src/core/prospective/derive.ts +32 -3
  116. package/src/core/prospective/index.ts +362 -39
  117. package/src/core/prospective/tunables.ts +18 -1
  118. package/src/core/prospective/windows.ts +104 -46
  119. package/src/core/recall/CONTRACT.md +28 -0
  120. package/src/core/recall/NOTES.md +55 -0
  121. package/src/core/recall/activate.ts +32 -5
  122. package/src/core/recall/gate.ts +7 -1
  123. package/src/core/recall/index.ts +28 -2
  124. package/src/core/recall/mood.ts +106 -0
  125. package/src/core/recall/tunables.ts +26 -0
  126. package/src/core/remember/CONTRACT.md +5 -0
  127. package/src/core/remember/index.ts +1 -0
  128. package/src/core/remember/proposals.ts +86 -3
  129. package/src/core/remember/spans.ts +11 -1
  130. package/src/core/self/CONTRACT.md +3 -0
  131. package/src/core/self/INTERFACE-GAPS.md +7 -0
  132. package/src/core/self/NOTES.md +30 -0
  133. package/src/core/self/identity.ts +115 -6
  134. package/src/core/self/index.ts +17 -0
  135. package/src/core/self/tunables.ts +17 -0
  136. package/src/core/sleep/CONTRACT.md +17 -1
  137. package/src/core/sleep/INTERFACE-GAPS.md +19 -0
  138. package/src/core/sleep/NOTES.md +36 -0
  139. package/src/core/sleep/consolidate.ts +149 -96
  140. package/src/core/sleep/decay.ts +11 -0
  141. package/src/core/sleep/index.ts +4 -1
  142. package/src/core/sleep/tunables.ts +9 -0
  143. package/src/core/sleep/types.ts +17 -0
  144. package/src/core/sleep/upgrade.ts +168 -0
  145. package/src/core/store/CONTRACT.md +21 -2
  146. package/src/core/store/NOTES.md +68 -0
  147. package/src/core/store/feelings.ts +23 -6
  148. package/src/core/store/index.ts +716 -17
  149. package/src/core/store/operational.ts +329 -4
  150. package/src/core/store/owner-op-seam.ts +79 -1
  151. package/src/core/types.ts +37 -0
  152. package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +0 -178
  153. package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +0 -42
@@ -133,7 +133,7 @@ import { OBSERVER_ENV, observerFromEnv, unreadableStanceLine } from "../stance-e
133
133
  import { STATE_MEANING, STATE_ORDER, firedReport } from "../fired.js";
134
134
  import type { FiredReport, FiredState } from "../fired.js";
135
135
  // The short view over the same reading: one line per memory mechanism.
136
- import { mechanismsLines } from "./mechanisms.js";
136
+ import { consoleVerdicts, mechanismsLines } from "./mechanisms.js";
137
137
  // The two snapshot readers `status` shares with doctor: the DIRECTORY is what
138
138
  // says how many copies you have, and a row only says what a run once wrote.
139
139
  import { readSnapshotsDir, resolveSnapshotsDir } from "../snapshots.js";
@@ -197,6 +197,7 @@ import type { RemovalPlan } from "./removal.js";
197
197
  import { repairDates } from "./repair-dates.js";
198
198
  import type { Confidence } from "./repair-dates.js";
199
199
  import { NO_PAGE_LINES, bodyFrom, pageLines, versionLines, writeLines } from "./self-page.js";
200
+ import { coreListLines, dreamListLines, dreamShowLines } from "./dream-core.js";
200
201
  // The console's shared manners (2026-09-21): is there a person here, ask them,
201
202
  // and say one marked line back.
202
203
  import { ask, confirm, isInteractive, isPromptAborted, paint, typed, ui } from "./ui.js";
@@ -239,6 +240,7 @@ import type {
239
240
  import { humanBytes as humanDiskBytes, uninstall } from "./uninstall.js";
240
241
  import { NO_PAGE_VERSION } from "../../core/self/index.js";
241
242
  import { snapshot, snapshotName } from "./snapshot.js";
243
+ import { feelingsLine } from "../feelings-line.js";
242
244
  // The console's map and the paragraphs the old `usage()` carried. One
243
245
  // direction only: `help.ts` imports nothing but types back from this file.
244
246
  import { COMMAND_DETAIL, CONSOLE_FOOTER, advancedHelp, shortHelp } from "./help.js";
@@ -298,6 +300,12 @@ export const COMMANDS = [
298
300
  // The written page the wake leads with: read it, write it whole, and read
299
301
  // back what it used to say (2026-09-18, S1).
300
302
  "self-page",
303
+ // Dreaming + consolidation (2026-09-26): what each dream did, and its undo;
304
+ // what the core holds, and the owner's door out of it. Like `self-page`,
305
+ // each both reads and writes, so neither is on `OWNER_OPS`: reading works
306
+ // under observer, and the write refuses at the core's own seam.
307
+ "dream",
308
+ "core",
301
309
  // The owner's window, started on the store the CONFIGURATION names — no
302
310
  // `--dir` to get wrong, and the browser opened for you (2026-09-22, item 4).
303
311
  // `counterparts-dashboard serve` is still there and still refuses an unnamed
@@ -708,6 +716,8 @@ export const COMMAND_FLAGS: Record<Command, readonly string[]> = {
708
716
  // line is a page in shell history, and prose that is injected into every
709
717
  // session does not belong there.
710
718
  "self-page": ["write", "file", "stdin", "reason", "versions", "version", "restore", "clear", "if-version"],
719
+ dream: ["list", "show", "undo"],
720
+ core: ["list", "demote", "reason"],
711
721
  // `--config` because the store it opens is the one the CONFIGURATION names —
712
722
  // that is the whole point of the command over `counterparts-dashboard serve`,
713
723
  // which refuses until you name a store. `--dir` still parses (it is common)
@@ -771,6 +781,10 @@ export const COMMAND_BLURB: Record<Command, string> = {
771
781
  "Which directories this memory is for: on, observer, off, or paused until you resume it. It writes the host's own registry beside claude-code.json, opens no store, and needs no --dir. A subdirectory inherits its nearest ancestor's entry. On this one command --observer names the MODE, not the console's stance.",
772
782
  "self-page":
773
783
  "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; --versions lists those and --version <seq> prints one. Reading works under observer; writing refuses there.",
784
+ dream:
785
+ "What each dream did, and its undo. With no flags (or --list), the recent dreams: date, state, title and what changed; --show <id> prints one dream's journal and every change it made; --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. Reading works under observer; --undo refuses there.",
786
+ core:
787
+ "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, and what you sent back; --demote <id> --reason \"...\" sends one back to ordinary fading from today, records why, and keeps the lanes from promoting it again. Reading works under observer; --demote refuses there.",
774
788
  dashboard:
775
789
  "Open the dashboard in your browser: the web view of the store your configuration names, served on 127.0.0.1 and nowhere else. Ctrl-C stops it. Looking is read-only — it strengthens nothing and deposits nothing. What you do there on purpose (write a note, remove a memory, back up, …) runs through these same commands, and a removal asks you to type the id back.",
776
790
  version: "The version of Counterparts you have. It opens nothing.",
@@ -794,6 +808,8 @@ const COMMAND_ARGS: Partial<Record<Command, string>> = {
794
808
  connect: " [claude-code]",
795
809
  disconnect: " [claude-code]",
796
810
  help: " [advanced | <command>]",
811
+ dream: " [--show <id> | --undo <id>]",
812
+ core: " [--demote <id> --reason \"...\"]",
797
813
  };
798
814
 
799
815
  /**
@@ -1001,6 +1017,20 @@ const START_FRESH_FLAG_HELP: Record<string, string> = {
1001
1017
  * and it is the one the hooks and the memory tools open. Printing the shared
1002
1018
  * sentence would describe a resolution this command does not use.
1003
1019
  */
1020
+ /** `dream`'s own three: `--list` and `--undo` mean something else on other pages. */
1021
+ const DREAM_FLAG_HELP: Record<string, string> = {
1022
+ list: "the recent dreams, newest first — the default",
1023
+ show: "one dream, by id: its journal and every change it made",
1024
+ undo: "reverse one dream's whole batch, by id (the id follows the flag); its journal is kept, marked undone",
1025
+ };
1026
+
1027
+ /** `core`'s own three. */
1028
+ const CORE_FLAG_HELP: Record<string, string> = {
1029
+ list: "what the core holds, with lanes, nominations and demotions — the default",
1030
+ demote: "send one core memory back to ordinary fading from today, by id; needs --reason",
1031
+ reason: "why — recorded with the demotion, and shown by --list",
1032
+ };
1033
+
1004
1034
  const DASHBOARD_FLAG_HELP: Record<string, string> = {
1005
1035
  dir: "a store to look at instead of the one your configuration names",
1006
1036
  };
@@ -1034,7 +1064,11 @@ export function commandHelp(command: Command): string {
1034
1064
  ? DASHBOARD_FLAG_HELP
1035
1065
  : command === "connect" || command === "disconnect" || command === "uninstall"
1036
1066
  ? HOST_FLAG_HELP
1037
- : {};
1067
+ : command === "dream"
1068
+ ? DREAM_FLAG_HELP
1069
+ : command === "core"
1070
+ ? CORE_FLAG_HELP
1071
+ : {};
1038
1072
  const flagLine = (name: string): string => {
1039
1073
  const shown = `--${name}${VALUED_FLAGS.includes(name) ? " <value>" : ""}`;
1040
1074
  return ` ${shown.padEnd(20)} ${override[name] ?? FLAG_HELP[name] ?? "(undocumented)"}`;
@@ -1091,6 +1125,8 @@ const VALUED_FLAGS: readonly string[] = [
1091
1125
  "version",
1092
1126
  "restore",
1093
1127
  "if-version",
1128
+ "show",
1129
+ "demote",
1094
1130
  ];
1095
1131
 
1096
1132
  /** Levenshtein, small and local. Only ever used to say "did you mean". */
@@ -1280,6 +1316,11 @@ export function parse(argv: readonly string[]): Parsed {
1280
1316
  restore: { type: "string" },
1281
1317
  clear: { type: "boolean" },
1282
1318
  "if-version": { type: "string" },
1319
+ // `dream --show <id>` and `core --demote <id>`: strings, so a trailing
1320
+ // flag is a refusal rather than a `true` read as "no id named". `dream
1321
+ // --undo` reuses `start-fresh`'s boolean and takes the id positionally.
1322
+ show: { type: "string" },
1323
+ demote: { type: "string" },
1283
1324
  observer: { type: "boolean" },
1284
1325
  help: { type: "boolean" },
1285
1326
  // `scope`'s five. Declared as booleans for the same reason `rebuild` is:
@@ -1737,6 +1778,10 @@ export async function run(argv: readonly string[], opts: RunOptions): Promise<nu
1737
1778
  typeof parsed.flags["dir"] === "string",
1738
1779
  opts.stdin,
1739
1780
  );
1781
+ case "dream":
1782
+ return dreamCommand(dir, io, parsed, observer, typeof parsed.flags["dir"] === "string");
1783
+ case "core":
1784
+ return coreCommand(dir, io, parsed, observer, typeof parsed.flags["dir"] === "string");
1740
1785
  }
1741
1786
  } catch (err) {
1742
1787
  io.err(upgradePending(err) ?? `${command} failed: ${describeDirRefusal(err)}`);
@@ -1928,14 +1973,139 @@ function firedCommand(
1928
1973
  return EXIT.failed;
1929
1974
  }
1930
1975
  try {
1931
- const report = firedReport(store, localDate(now(), store.zone()));
1932
- for (const line of all ? firedLines(report, true) : mechanismsLines(report)) io.out(line);
1976
+ const today = localDate(now(), store.zone());
1977
+ const report = firedReport(store, today);
1978
+ for (const line of all ? firedLines(report, true) : mechanismsLines(report, consoleVerdicts(store, today))) io.out(line);
1933
1979
  return EXIT.ok;
1934
1980
  } finally {
1935
1981
  store.close();
1936
1982
  }
1937
1983
  }
1938
1984
 
1985
+ /**
1986
+ * `dream` — what each dream did, and its undo (2026-09-26). The rules are the
1987
+ * core's (`core/dream/`); this picks one of three modes and prints lines
1988
+ * (`dream-core.ts`). Reading opens the store as an instrument; `--undo` opens
1989
+ * it in the console's stance and the core refuses it under observer.
1990
+ */
1991
+ function dreamCommand(dir: string, io: Io, parsed: Parsed, observer: boolean, namedDir: boolean): number {
1992
+ if (!storeExists(dir)) {
1993
+ io.err(`No store at ${dir}. Run 'counterparts init${namedDir ? ` --dir ${dir}` : ""}' to create one.`);
1994
+ return EXIT.usage;
1995
+ }
1996
+ const show = parsed.flags["show"];
1997
+ const undo = parsed.flags["undo"] === true;
1998
+ const undoId = typeof parsed.flags["undo"] === "string" ? parsed.flags["undo"] : parsed.positional[0];
1999
+ if (typeof show === "string" && undo) {
2000
+ io.err("refused: --show and --undo are two different things to do. Pass one.");
2001
+ return EXIT.usage;
2002
+ }
2003
+ if (undo) {
2004
+ if (undoId === undefined || undoId.length === 0) {
2005
+ io.err("refused: --undo needs the dream's id after it (counterparts dream --list shows them).");
2006
+ return EXIT.usage;
2007
+ }
2008
+ const counterpart = openCounterpart(dir, observer);
2009
+ try {
2010
+ if (counterpart.store.dream(undoId) === undefined) {
2011
+ io.err(`refused: no dream ${undoId} in this store. counterparts dream --list shows them.`);
2012
+ return EXIT.refused;
2013
+ }
2014
+ const out = counterpart.dreams.undo(undoId);
2015
+ if (!out.ok) {
2016
+ io.err(
2017
+ out.reason === "observer"
2018
+ ? "refused: this console is an observer; it reads and changes nothing. Nothing was undone."
2019
+ : `refused: ${out.reason}. Nothing was undone.`,
2020
+ );
2021
+ return EXIT.refused;
2022
+ }
2023
+ io.out(
2024
+ out.reversed === 0
2025
+ ? `Dream ${undoId} had nothing left to reverse; it is marked undone.`
2026
+ : `Undid dream ${undoId}: ${String(out.reversed)} ${out.reversed === 1 ? "change" : "changes"} reversed.`,
2027
+ );
2028
+ io.out(" Merged memories are back as they were, its links and gists are gone, and its replays and nominations were taken back.");
2029
+ if (out.kept > 0) {
2030
+ io.out(
2031
+ ` ${String(out.kept)} ${out.kept === 1 ? "merge was" : "merges were"} left as ${out.kept === 1 ? "it is" : "they are"}: the merged memory has changed since (revised, merged again, or removed), and bringing its originals back would duplicate it.`,
2032
+ );
2033
+ }
2034
+ io.out(" Its journal is kept, marked undone: counterparts dream --show " + undoId);
2035
+ return EXIT.ok;
2036
+ } finally {
2037
+ counterpart.close();
2038
+ }
2039
+ }
2040
+ const counterpart = openCounterpart(dir, true);
2041
+ try {
2042
+ if (typeof show === "string") {
2043
+ const lines = dreamShowLines(counterpart, show);
2044
+ if (lines === null) {
2045
+ io.err(`refused: no dream ${show} in this store. counterparts dream --list shows them.`);
2046
+ return EXIT.refused;
2047
+ }
2048
+ for (const line of lines) io.out(line);
2049
+ return EXIT.ok;
2050
+ }
2051
+ for (const line of dreamListLines(counterpart)) io.out(line);
2052
+ return EXIT.ok;
2053
+ } finally {
2054
+ counterpart.close();
2055
+ }
2056
+ }
2057
+
2058
+ /**
2059
+ * `core` — what the core holds, and the owner's door out of it (2026-09-26).
2060
+ * `--demote` opens the store in the console's stance; `Counterpart.demoteCore`
2061
+ * decides everything and refuses under observer.
2062
+ */
2063
+ function coreCommand(dir: string, io: Io, parsed: Parsed, observer: boolean, namedDir: boolean): number {
2064
+ if (!storeExists(dir)) {
2065
+ io.err(`No store at ${dir}. Run 'counterparts init${namedDir ? ` --dir ${dir}` : ""}' to create one.`);
2066
+ return EXIT.usage;
2067
+ }
2068
+ const demote = parsed.flags["demote"];
2069
+ const reason = parsed.flags["reason"];
2070
+ if (reason !== undefined && typeof demote !== "string") {
2071
+ io.err("refused: --reason goes with a --demote. Pass one, or leave it out.");
2072
+ return EXIT.usage;
2073
+ }
2074
+ if (typeof demote === "string") {
2075
+ if (typeof reason !== "string" || reason.trim().length === 0) {
2076
+ io.err('refused: a demotion needs a reason — --reason "why" — and it is kept with the record.');
2077
+ return EXIT.usage;
2078
+ }
2079
+ const counterpart = openCounterpart(dir, observer);
2080
+ try {
2081
+ const out = counterpart.demoteCore(demote, { reason, actor: "owner" });
2082
+ if (!out.ok) {
2083
+ const why: Record<string, string> = {
2084
+ observer: "this console is an observer; it reads and changes nothing",
2085
+ "unknown-id": `no memory ${demote} in this store`,
2086
+ "not-core": `${demote} is not in the core (counterparts core --list shows what is)`,
2087
+ "reason-required": "a demotion needs a reason",
2088
+ };
2089
+ io.err(`refused: ${why[out.reason] ?? out.reason}. Nothing was changed.`);
2090
+ return EXIT.refused;
2091
+ }
2092
+ io.out(`Sent ${demote} back to ordinary fading, from today.`);
2093
+ io.out(` Why, as recorded: ${reason.trim()}`);
2094
+ io.out(" It fades like any other memory now, and the core's lanes will not promote it again.");
2095
+ return EXIT.ok;
2096
+ } finally {
2097
+ counterpart.close();
2098
+ }
2099
+ }
2100
+ const counterpart = openCounterpart(dir, true);
2101
+ try {
2102
+ for (const line of coreListLines(counterpart)) io.out(line);
2103
+ return EXIT.ok;
2104
+ } finally {
2105
+ counterpart.close();
2106
+ }
2107
+ }
2108
+
1939
2109
  /**
1940
2110
  * `self-page` — the owner's door to the written page (2026-09-18, S1).
1941
2111
  *
@@ -5193,6 +5363,16 @@ async function recallCommand(
5193
5363
  const journal = m.journal ? "[journal] " : "";
5194
5364
  io.out(` ${m.id} [${m.tier}] ${journal}${m.kind}${m.title === null ? "" : ` — ${m.title}`}`);
5195
5365
  for (const line of m.body.split("\n")) io.out(` ${line}`);
5366
+ // The feelings on it, `you: … · me: …` (emotion part A). Read-only, and
5367
+ // a store that cannot answer simply shows none.
5368
+ let felt = "";
5369
+ try {
5370
+ const born = counterpart.store.physicsOf(m.id).birthDay;
5371
+ felt = feelingsLine(counterpart.store.feelingsFor(m.id), counterpart.store.livedDay() - born);
5372
+ } catch {
5373
+ felt = "";
5374
+ }
5375
+ if (felt !== "") io.out(` feelings — ${felt}`);
5196
5376
  }
5197
5377
  // THE TIER LEGEND, and it is not decoration. `answered` means the question
5198
5378
  // reached something, never that the something is right, and the loudest
@@ -0,0 +1,126 @@
1
+ /**
2
+ * `dream` and `core` — the owner's two windows onto the dreaming +
3
+ * consolidation mechanism (2026-09-26), rendered as plain lines.
4
+ *
5
+ * The console decides nothing here. What a dream did, how to undo it, what the
6
+ * core holds and how a memory leaves it are the core's (`core/dream/`,
7
+ * `Counterpart.coreList` / `demoteCore`); this file only turns their answers
8
+ * into lines a person reads. Pure over its inputs, like `self-page.ts`, so the
9
+ * tests can check the words without a store.
10
+ */
11
+ import type { Counterpart } from "../../core/counterpart.js";
12
+
13
+ /** How a memory id reads in a list: its first line, or why it is not shown. */
14
+ export function memoryWords(counterpart: Counterpart, id: string | null, max = 80): string {
15
+ if (id === null) return "(removed by the owner)";
16
+ const row = counterpart.store.row(id);
17
+ if (row === undefined) return "(no such memory)";
18
+ if (row.confidential === 1) return "[confidential]";
19
+ if (row.body === "") return "(removed by the owner)";
20
+ const line = ((row.title ?? "").trim() || (row.body.split("\n").find((l) => l.trim().length > 0) ?? "")).replace(/\s+/g, " ").trim();
21
+ const said = line.length > max ? `${line.slice(0, max - 1)}…` : line;
22
+ return row.archived === 1 ? `${said} (archived: ${row.archived_reason ?? "archived"})` : said;
23
+ }
24
+
25
+ function countsLine(counts: Readonly<Record<string, number>>): string {
26
+ const parts = Object.entries(counts)
27
+ .filter(([, n]) => n > 0)
28
+ .map(([k, n]) => `${String(n)} ${k}`);
29
+ return parts.length === 0 ? "no changes" : parts.join(", ");
30
+ }
31
+
32
+ /** `counterparts dream --list`: newest first, one line each. */
33
+ export function dreamListLines(counterpart: Counterpart, limit = 20): string[] {
34
+ const dreams = counterpart.dreams.list(limit);
35
+ if (dreams.length === 0) {
36
+ return [
37
+ "No dreams yet.",
38
+ "A session is asked, at most once a day, whether it may dream; the owner says yes or not today.",
39
+ ];
40
+ }
41
+ const out = [`Dreams — newest first (${String(dreams.length)} shown)`, ""];
42
+ for (const { dream, counts } of dreams) {
43
+ const when = dream.date ?? `lived day ${String(dream.day)}`;
44
+ const title = dream.title === null || dream.title.length === 0 ? "(no journal)" : `"${dream.title}"`;
45
+ out.push(`${dream.id} ${when} ${dream.state.padEnd(9)} ${title} — ${countsLine(counts)}`);
46
+ }
47
+ out.push("", "Read one: counterparts dream --show <id> Reverse one: counterparts dream --undo <id>");
48
+ return out;
49
+ }
50
+
51
+ /** `counterparts dream --show <id>`: the journal, then every change, undone ones marked. */
52
+ export function dreamShowLines(counterpart: Counterpart, id: string): string[] | null {
53
+ const shown = counterpart.dreams.show(id);
54
+ if (shown === null) return null;
55
+ const { dream, changes } = shown;
56
+ const out = [
57
+ `Dream ${dream.id} — ${dream.date ?? `lived day ${String(dream.day)}`}, ${dream.state}`,
58
+ ...(dream.session === null ? [] : [` for session ${dream.session}`]),
59
+ "",
60
+ dream.title === null ? "Journal: (not written)" : `Journal: "${dream.title}"`,
61
+ ];
62
+ if (dream.journal !== null && dream.journal.length > 0) {
63
+ for (const line of dream.journal.split("\n")) out.push(` ${line}`);
64
+ }
65
+ out.push("", changes.length === 0 ? "Changes: none." : `Changes (${String(changes.length)}):`);
66
+ for (const c of changes) {
67
+ const mark = c.undone === 1 ? " [undone] " : " ";
68
+ const a = c.ref === null ? null : c.ref;
69
+ const b = c.ref2;
70
+ const words = (x: string | null): string => (x === null ? "(removed by the owner)" : `${x} "${memoryWords(counterpart, x)}"`);
71
+ switch (c.action) {
72
+ case "link":
73
+ case "contradiction":
74
+ out.push(`${mark}${c.action}: ${words(a)} ↔ ${words(b)}`);
75
+ break;
76
+ case "merge": {
77
+ let from: string[] = [];
78
+ try {
79
+ const d = JSON.parse(c.detail) as { from?: unknown };
80
+ if (Array.isArray(d.from)) from = d.from.filter((x): x is string => typeof x === "string");
81
+ } catch {
82
+ from = [];
83
+ }
84
+ out.push(`${mark}merge into ${words(a)}`);
85
+ for (const f of from) out.push(`${mark} from ${words(f)}`);
86
+ break;
87
+ }
88
+ default:
89
+ out.push(`${mark}${c.action}: ${words(a)}`);
90
+ }
91
+ }
92
+ if (dream.state !== "undone") out.push("", `Reverse all of it: counterparts dream --undo ${dream.id}`);
93
+ return out;
94
+ }
95
+
96
+ /** `counterparts core --list`: the core with lanes, then nominations and demotions. */
97
+ export function coreListLines(counterpart: Counterpart): string[] {
98
+ const { core, nominated, demoted } = counterpart.coreList();
99
+ const out = [
100
+ core.length === 0
101
+ ? "The core is empty: nothing has become part of who I am yet."
102
+ : `The core — ${String(core.length)} ${core.length === 1 ? "memory" : "memories"} that do not fade`,
103
+ ];
104
+ for (const m of core) {
105
+ const how = m.lane === null ? "(before lanes, or by revision)" : `${m.lane} lane${m.day === null ? "" : `, lived day ${String(m.day)}`}`;
106
+ const said = m.confidential ? "[confidential]" : (m.body ?? "(unreadable)");
107
+ out.push(` ${m.id} ${m.kind.padEnd(6)} ${how} — ${said}`);
108
+ }
109
+ out.push(
110
+ "",
111
+ "Only a memory about me or about us becomes core: strongly felt and back after a gap (fast lane),",
112
+ "or back on several separate days over weeks (slow lane). At most a few a night.",
113
+ );
114
+ if (nominated.length > 0) {
115
+ out.push("", "Nominated by a dream (a lane still has to promote it):");
116
+ for (const n of nominated.slice(0, 20)) {
117
+ out.push(` ${n.id} lived day ${String(n.day)}${n.reason === null ? "" : ` — ${n.reason}`}${n.dream === null ? "" : ` (${n.dream})`}`);
118
+ }
119
+ }
120
+ if (demoted.length > 0) {
121
+ out.push("", "Sent back to ordinary fading by you:");
122
+ for (const d of demoted.slice(0, 20)) out.push(` ${d.id} lived day ${String(d.day)}${d.reason === null ? "" : ` — ${d.reason}`}`);
123
+ }
124
+ if (core.length > 0) out.push("", 'Send one back: counterparts core --demote <id> --reason "..."');
125
+ return out;
126
+ }
@@ -130,6 +130,8 @@ export const SHORT: Record<string, string | readonly string[]> = {
130
130
  // installed the package.
131
131
  note: "Remember something on purpose, right now",
132
132
  mechanisms: "Which parts of memory are working, one line each",
133
+ dream: "What each dream did — and undo one",
134
+ core: "What became part of who I am — and send one back",
133
135
  init: "Make a second, separate memory store — a scratch one",
134
136
  "start-fresh": "Set this memory aside and start blank; --undo brings it back",
135
137
  verify: "Count the search index against what is actually stored",
@@ -176,6 +178,8 @@ export const GROUPS: readonly HelpGroup[] = [
176
178
  export const ADVANCED: readonly string[] = [
177
179
  "note",
178
180
  "mechanisms",
181
+ "dream",
182
+ "core",
179
183
  "init",
180
184
  "start-fresh",
181
185
  "verify",
@@ -355,6 +359,19 @@ export const COMMAND_DETAIL: Record<string, readonly string[]> = {
355
359
  "many times in the last 7 days, what it turned away, and — for the ones",
356
360
  "nothing durable records — which row would fix that.",
357
361
  ],
362
+ dream: [
363
+ "A session is asked, at most once a day, whether it may dream for a few",
364
+ "minutes; the owner says yes or not today. A dream runs as a background",
365
+ "agent and every change it makes is recorded under its id, so --undo can",
366
+ "reverse the whole batch. Its journal lives with the dream, never as a",
367
+ "memory.",
368
+ ],
369
+ core: [
370
+ "The core does not fade. Only a memory about me or about us gets there: by",
371
+ "the fast lane (strongly felt, and it came back after a gap) or the slow",
372
+ "lane (it came back on several separate days over weeks), at most a few a",
373
+ "night. A dream can nominate one; only a lane promotes it.",
374
+ ],
358
375
  fired: [
359
376
  "`counterparts mechanisms` is the same command, and it is the listed",
360
377
  "spelling; this one stays so scripts that call it keep working.",