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
@@ -44,7 +44,7 @@
44
44
  * No body text, no question text, no note text ever reaches an event.
45
45
  */
46
46
  import { MCP_RECALL_EVENT } from "../../core/counterpart.js";
47
- import { localDate } from "../../core/time.js";
47
+ import { localDate, parseCalendarDate, todayIn } from "../../core/time.js";
48
48
  import type { ChapterResult, Counterpart, DepositResult } from "../../core/counterpart.js";
49
49
  import type { SemanticSource } from "../../core/recall/index.js";
50
50
  import { AUTHOR_DIMENSIONS } from "../../core/remember/index.js";
@@ -112,7 +112,7 @@ export const SERVER_NAME = "counterparts";
112
112
  * host decides whether to trust what follows. Read from a constant rather than
113
113
  * from disk so the server opens no file to answer its first message.
114
114
  */
115
- export const SERVER_VERSION = "0.3.2";
115
+ export const SERVER_VERSION = "0.3.4";
116
116
 
117
117
  /**
118
118
  * THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
@@ -523,6 +523,8 @@ export class McpServer {
523
523
  return this.scopeTool(args);
524
524
  case "self_page":
525
525
  return this.selfPageTool(args);
526
+ case "dream":
527
+ return this.dreamTool(args);
526
528
  default:
527
529
  return this.refuse(name, "unknown-tool", { tool: name });
528
530
  }
@@ -922,6 +924,11 @@ export class McpServer {
922
924
  detail: "relevance, emotional and predictive are each a number from 0 to 1.",
923
925
  });
924
926
  }
927
+ // THE REMINDER DATE AND HOW IT COMES BACK (2026-09-26) — checked before
928
+ // anything is captured, so an unreadable one is a refusal that says which
929
+ // shapes ARE readable rather than a note that lands without its date.
930
+ const dated = readReminder(args);
931
+ if ("refused" in dated) return this.refuse("note", dated.refused, { detail: dated.detail });
925
932
  const session = this.session ?? "mcp";
926
933
 
927
934
  const captured = this.counterpart.captureJot({ session, scope: this.scope, text });
@@ -939,6 +946,7 @@ export class McpServer {
939
946
  if (typeof args["updates"] === "string") draft["updates"] = args["updates"];
940
947
  if (salience !== undefined) draft["claimed"] = salience;
941
948
  if (Object.keys(dims).length > 0) draft["salience"] = dims;
949
+ Object.assign(draft, dated.fields);
942
950
 
943
951
  const model = this.sessionModel();
944
952
  const feelings = readFeelings(args["feelings"]);
@@ -951,7 +959,10 @@ export class McpServer {
951
959
  ownSpanHash,
952
960
  ...(model === undefined ? {} : { model }),
953
961
  });
954
- return this.depositResult("note", deposit, this.recordFeelings(deposit, feelings.inputs, model));
962
+ return this.depositResult("note", deposit, {
963
+ ...this.recordFeelings(deposit, feelings.inputs, model),
964
+ ...reminderEcho(deposit, dated, this.today()),
965
+ });
955
966
  }
956
967
 
957
968
  /**
@@ -1496,10 +1507,12 @@ export class McpServer {
1496
1507
  ): Promise<{ outcomes: Record<string, unknown>[]; deposited: number; duplicates: number; entries: Record<string, unknown>[] }> {
1497
1508
  const entries: Record<string, unknown>[] = [];
1498
1509
  const feelingsOf: FeelingsRead[] = [];
1510
+ const datedOf: ReminderRead[] = [];
1499
1511
  for (const item of raw) {
1500
1512
  if (item === null || typeof item !== "object" || Array.isArray(item)) {
1501
1513
  entries.push({ content: "" });
1502
1514
  feelingsOf.push({ inputs: [] });
1515
+ datedOf.push({ fields: {}, remindIgnored: false });
1503
1516
  continue;
1504
1517
  }
1505
1518
  const rec = item as Record<string, unknown>;
@@ -1513,6 +1526,11 @@ export class McpServer {
1513
1526
  // one entry as malformed, which is this tool's per-entry isolation rule.
1514
1527
  const entryDims = readDimensions(rec) ?? pickDimensions(rec);
1515
1528
  if (Object.keys(entryDims).length > 0) draft["salience"] = entryDims;
1529
+ // The reminder date (2026-09-26), per entry: an unreadable one refuses
1530
+ // THIS entry below, by name, and its siblings still land.
1531
+ const dated = readReminder(rec);
1532
+ if (!("refused" in dated)) Object.assign(draft, dated.fields);
1533
+ datedOf.push(dated);
1516
1534
  entries.push(draft);
1517
1535
  feelingsOf.push(readFeelings(rec["feelings"]));
1518
1536
  }
@@ -1529,6 +1547,11 @@ export class McpServer {
1529
1547
  outcomes.push({ stored: false, reason: "feelings-malformed", detail: feelings.refused });
1530
1548
  continue;
1531
1549
  }
1550
+ const dated = datedOf[n] ?? { fields: {}, remindIgnored: false };
1551
+ if ("refused" in dated) {
1552
+ outcomes.push({ stored: false, reason: dated.refused, detail: dated.detail });
1553
+ continue;
1554
+ }
1532
1555
  let result: DepositResult;
1533
1556
  try {
1534
1557
  result = await this.counterpart.submitSessionEnd(draft, {
@@ -1557,6 +1580,7 @@ export class McpServer {
1557
1580
  ...(malformed === null ? {} : { malformed }),
1558
1581
  ...(malformed === "KIND_UNKNOWN" ? { kinds: [...MEMORY_KINDS] } : {}),
1559
1582
  ...this.recordFeelings(result, feelings.inputs, model),
1583
+ ...reminderEcho(result, dated, this.today()),
1560
1584
  });
1561
1585
  }
1562
1586
  return { outcomes, deposited, duplicates, entries };
@@ -1713,6 +1737,93 @@ export class McpServer {
1713
1737
  );
1714
1738
  }
1715
1739
 
1740
+ /**
1741
+ * `dream` — dreaming, in phases (`core/dream/`, 2026-09-26). Every phase
1742
+ * binds the session: the dreamer is a background agent the session launched,
1743
+ * talking to this same server, and its writes belong to that session.
1744
+ * `launch` writes nothing — it hands back the prompt for the dreamer — and is
1745
+ * refused under observer stance with the rest, because a dream it launched
1746
+ * could do nothing there.
1747
+ */
1748
+ private dreamTool(args: Record<string, unknown>): ToolResult {
1749
+ const phase = args["phase"];
1750
+ if (this.observer) return this.standDown("dream");
1751
+ const bound = this.requireBoundSession(args["session"], "dream");
1752
+ if (bound !== null) return bound;
1753
+ const session = this.session as string;
1754
+ const dreams = this.counterpart.dreams;
1755
+ const at = this.counterpart.store.today();
1756
+ const refused = (reason: string, detail: string): ToolResult => this.refuse("dream", reason, { phase, detail });
1757
+ try {
1758
+ switch (phase) {
1759
+ case "launch":
1760
+ this.emit("mcp.dream", undefined, { phase: "launch", session });
1761
+ return this.result(
1762
+ {
1763
+ phase,
1764
+ session,
1765
+ prompt: dreams.launchPrompt({ session }),
1766
+ // The relay is the hand-back line AS IT IS: it carries the dream's
1767
+ // mark, which keeps the dream out of what the sweep reads. A
1768
+ // retelling in the session's own words would carry none, and the
1769
+ // dream's title and changes would read as something that
1770
+ // happened (adversarial review of #251).
1771
+ how: "Hand `prompt` to a background agent (the Agent tool), unchanged, and carry on. When it finishes, show the owner its hand-back line exactly as it came back (it carries the dream's mark, which keeps the dream out of lived memory) — do not retell the dream in your own words.",
1772
+ },
1773
+ false,
1774
+ );
1775
+ case "decline": {
1776
+ dreams.decline({ at, session });
1777
+ this.emit("mcp.dream", undefined, { phase: "decline", session });
1778
+ return this.result({ phase, session, snoozed: at, said: "Not today — the ask will not come back until tomorrow." }, false);
1779
+ }
1780
+ case "begin": {
1781
+ const model = readSession(this.registryDir, session)?.model;
1782
+ const out = dreams.begin({ session, scope: this.scope, ...(model === undefined ? {} : { model }) });
1783
+ if (!out.ok) {
1784
+ return refused(
1785
+ out.reason,
1786
+ out.reason === "dreamed-today"
1787
+ ? "A dream already ran this lived day."
1788
+ : out.reason === "nothing-new"
1789
+ ? "Nothing new has been lived since the last dream."
1790
+ : "The dream did not begin.",
1791
+ );
1792
+ }
1793
+ this.emit("mcp.dream", out.bundle.dream, { phase: "begin", session, shown: Object.keys(out.bundle.memories).length });
1794
+ return this.result({ phase, session, dream: out.bundle.dream, bundle: out.text }, false);
1795
+ }
1796
+ case "propose": {
1797
+ const dream = args["dream"];
1798
+ const changes = args["changes"];
1799
+ if (typeof dream !== "string" || !Array.isArray(changes)) {
1800
+ return refused("dream-and-changes-required", "Pass `dream` (the id `begin` returned) and `changes`, an array.");
1801
+ }
1802
+ const out = dreams.propose({ dream, session, changes: changes as never });
1803
+ if (!out.ok) return refused(out.reason, "That dream is not open for this session.");
1804
+ this.emit("mcp.dream", dream, { phase: "propose", applied: out.results.filter((r) => r.ok).length });
1805
+ return this.result({ phase, dream, results: out.results }, false);
1806
+ }
1807
+ case "journal": {
1808
+ const dream = args["dream"];
1809
+ const text = args["text"];
1810
+ if (typeof dream !== "string" || typeof text !== "string") {
1811
+ return refused("dream-and-text-required", "Pass `dream` and the journal `text`.");
1812
+ }
1813
+ const title = args["title"];
1814
+ const out = dreams.journal({ dream, session, text, ...(typeof title === "string" ? { title } : {}) });
1815
+ if (!out.ok) return refused(out.reason, "The journal was not written.");
1816
+ this.emit("mcp.dream", dream, { phase: "journal" });
1817
+ return this.result({ phase, dream, handBack: out.handBack, say: "Return `handBack` as your final message, unchanged." }, false);
1818
+ }
1819
+ default:
1820
+ return refused("phase-unknown", "phase is one of launch, begin, propose, journal, decline.");
1821
+ }
1822
+ } catch (err) {
1823
+ return refused("threw", String((err as Error).message ?? err));
1824
+ }
1825
+ }
1826
+
1716
1827
  /**
1717
1828
  * `self_page` — read the page, or write it whole.
1718
1829
  *
@@ -1946,6 +2057,12 @@ export class McpServer {
1946
2057
  return claimed;
1947
2058
  }
1948
2059
 
2060
+ /** The person's calendar day now, in the store's zone (docs/time.md rule 3),
2061
+ * off this server's injectable clock — what a past `eventDate` is told against. */
2062
+ private today(): string {
2063
+ return todayIn(this.counterpart.store.zone(), this.nowFn());
2064
+ }
2065
+
1949
2066
  /**
1950
2067
  * The model the hooks last saw answer in THIS server's bound session — the
1951
2068
  * relay a chapter's model takes (self NOTES §24), used since 2026-09-25 for
@@ -2097,18 +2214,36 @@ export class McpServer {
2097
2214
  }
2098
2215
  try {
2099
2216
  const added = this.counterpart.addFeelings(deposit.memoryId, inputs, model === undefined ? {} : { model });
2217
+ // Two kinds of notice (emotion part A): a word kept as the writer's own
2218
+ // (`other`), with a suggestion ONLY when a wheel word is genuinely close;
2219
+ // and a word read as a wheel word (`readAs`: exposed → vulnerable).
2220
+ const kept = added.notices.filter((n) => n.readAs === undefined);
2221
+ const read = added.notices.filter((n) => n.readAs !== undefined);
2100
2222
  return {
2101
2223
  feelings: {
2102
2224
  stored: added.ids.length,
2103
- ...(added.notices.length === 0
2225
+ ...(kept.length === 0
2104
2226
  ? {}
2105
2227
  : {
2106
- other: added.notices.map((n) => ({
2228
+ other: kept.map((n) => ({
2107
2229
  index: n.index,
2108
2230
  word: n.word,
2109
2231
  core: n.core,
2110
2232
  closest: n.closest,
2111
- note: `"${n.word}" is not on the feelings wheel, so it was kept as other. If you meant one of these, say it that way next time: ${n.closest.join(", ")}.`,
2233
+ note:
2234
+ n.closest.length === 0
2235
+ ? `"${n.word}" is not on the feelings wheel, so it was kept as your own word.`
2236
+ : `"${n.word}" is not on the feelings wheel, so it was kept as your own word. If you meant ${n.closest.join(" or ")}, say it that way next time.`,
2237
+ })),
2238
+ }),
2239
+ ...(read.length === 0
2240
+ ? {}
2241
+ : {
2242
+ readAs: read.map((n) => ({
2243
+ index: n.index,
2244
+ word: n.word,
2245
+ as: n.readAs,
2246
+ note: `"${n.word}" was stored as ${String(n.readAs)}.`,
2112
2247
  })),
2113
2248
  }),
2114
2249
  },
@@ -2249,6 +2384,119 @@ function pickDimensions(rec: Record<string, unknown>): Record<string, unknown> {
2249
2384
  return out;
2250
2385
  }
2251
2386
 
2387
+ // ── a reminder date on a tool call (2026-09-26) ─────────────────────────────
2388
+
2389
+ /** What `readReminder` hands back: the draft fields, and what to say about them. */
2390
+ type ReminderRead =
2391
+ | {
2392
+ /** `eventDate: null` is the explicit drop (a revision's cancel); `remind`
2393
+ * rides only when it was SENT, so a revision can tell a left-out mode
2394
+ * from a stated one (review N7). */
2395
+ readonly fields: { eventDate?: string | null; remind?: "plain" | "quiet" };
2396
+ /** `remind` was sent with no `eventDate`: there is nothing for it to shape
2397
+ * — unless the memory it revises carries a date (`DepositResult.reminder`). */
2398
+ readonly remindIgnored: boolean;
2399
+ }
2400
+ | { readonly refused: "event-date-unreadable" | "remind-unknown"; readonly detail: string };
2401
+
2402
+ const EVENT_DATE_SHAPES =
2403
+ 'A day "2026-10-15", a month "2026-10", a year "2026", or a range of two days "2026-10-20..2026-10-31" (first day first). Convert "late October" or "before the 15th" into one of those yourself.';
2404
+
2405
+ const YEAR_ALONE_NOTE =
2406
+ "A year alone names no day, so this will not come back on its own. Give a month, a day or a range if it should.";
2407
+
2408
+ /** Review N8 (2026-09-26): a past date is accepted and kept, and SAID — so a
2409
+ * wrong year can be caught by the model that wrote it. */
2410
+ const DATE_PASSED_NOTE = "That date has already passed — it won't come back as a reminder.";
2411
+
2412
+ /**
2413
+ * `eventDate` and `remind` off a `note` or a `session_end` entry, CHECKED
2414
+ * before anything mints: the date by `time.ts` (the one module that reads
2415
+ * dates), `remind` against its two words. Never a date parsed from prose — the
2416
+ * model writes the field (owner decision 2026-09-25/26).
2417
+ */
2418
+ function readReminder(rec: Record<string, unknown>): ReminderRead {
2419
+ const rawDate = rec["eventDate"];
2420
+ const rawRemind = rec["remind"];
2421
+ if (rawRemind !== undefined && rawRemind !== null && rawRemind !== "plain" && rawRemind !== "quiet") {
2422
+ return { refused: "remind-unknown", detail: '`remind` is "plain" or "quiet".' };
2423
+ }
2424
+ const sent: { remind?: "plain" | "quiet" } =
2425
+ rawRemind === "plain" || rawRemind === "quiet" ? { remind: rawRemind } : {};
2426
+ if (rawDate === undefined || rawDate === null) {
2427
+ return {
2428
+ fields: { ...(rawDate === null ? { eventDate: null } : {}), ...sent },
2429
+ remindIgnored: sent.remind !== undefined,
2430
+ };
2431
+ }
2432
+ const read = typeof rawDate === "string" ? parseCalendarDate(rawDate) : null;
2433
+ if (read === null) {
2434
+ return {
2435
+ refused: "event-date-unreadable",
2436
+ detail: `\`eventDate\` ${typeof rawDate === "string" ? `"${rawDate.slice(0, 64)}"` : "(not text)"} is not a date this can read. ${EVENT_DATE_SHAPES}`,
2437
+ };
2438
+ }
2439
+ return { fields: { eventDate: read.text, ...sent }, remindIgnored: false };
2440
+ }
2441
+
2442
+ /** What to say about a recorded date: that it has already passed (its last day
2443
+ * is before the person's today — `time.ts#todayIn` in the store's zone), or
2444
+ * that a year alone never comes back. One note, the passed one first. */
2445
+ function dateNote(eventDate: string, today: string): Record<string, unknown> {
2446
+ const read = parseCalendarDate(eventDate);
2447
+ if (read === null) return {};
2448
+ if (read.last < today) return { note: DATE_PASSED_NOTE };
2449
+ return read.precision === "year" ? { note: YEAR_ALONE_NOTE } : {};
2450
+ }
2451
+
2452
+ /** The reminder half of a deposit's answer: what was RECORDED — after a
2453
+ * revision's carry-over, not merely what was sent — or why `remind` had
2454
+ * nothing to shape. Nothing when neither field was sent or nothing minted. */
2455
+ function reminderEcho(deposit: DepositResult, dated: ReminderRead, today: string): Record<string, unknown> {
2456
+ if ("refused" in dated || !deposit.deposited) return {};
2457
+ const carried = deposit.reminder;
2458
+ if (carried !== undefined) {
2459
+ const unmoved = carried.moved ? {} : { unmoved: true };
2460
+ if (carried.eventDate === null) {
2461
+ return {
2462
+ reminder: {
2463
+ cleared: true,
2464
+ from: carried.from,
2465
+ ...unmoved,
2466
+ note: "The date is dropped: neither this memory nor the one it revises will come back as a reminder.",
2467
+ },
2468
+ };
2469
+ }
2470
+ return {
2471
+ reminder: {
2472
+ eventDate: carried.eventDate,
2473
+ remind: carried.remind ?? "quiet",
2474
+ from: carried.from,
2475
+ ...(carried.inherited.length > 0 ? { carriedOver: [...carried.inherited] } : {}),
2476
+ ...unmoved,
2477
+ ...dateNote(carried.eventDate, today),
2478
+ },
2479
+ };
2480
+ }
2481
+ const { eventDate, remind } = dated.fields;
2482
+ if (typeof eventDate === "string") {
2483
+ return { reminder: { eventDate, remind: remind ?? "quiet", ...dateNote(eventDate, today) } };
2484
+ }
2485
+ // A cancel that found nothing to cancel is SAID (review of #247): silence
2486
+ // here read as success while a reminder the model meant to drop kept coming.
2487
+ if (eventDate === null && (deposit.proposal?.updates?.declared ?? null) !== null) {
2488
+ return {
2489
+ reminder: {
2490
+ cleared: false,
2491
+ note: "No date was dropped: `updates` did not reach a dated memory by its id, so nothing was cancelled.",
2492
+ },
2493
+ };
2494
+ }
2495
+ return dated.remindIgnored
2496
+ ? { reminder: { ignored: "remind", note: "`remind` shapes how a date comes back; with no `eventDate` there was nothing to shape." } }
2497
+ : {};
2498
+ }
2499
+
2252
2500
  // ── feelings on a tool call (schema v7) ─────────────────────────────────────
2253
2501
 
2254
2502
  type FeelingsRead = { inputs: FeelingInput[] } | { refused: string };
@@ -40,6 +40,12 @@
40
40
  * row with versions; it cannot promote a memory, cannot protect one, and moves
41
41
  * no strength anywhere. Promotion and reinforcement go on deciding what is true
42
42
  * of the self; the page is where that growth is written down.
43
+ *
44
+ * **`dream` is the eighth, added 2026-09-26 (owner decisions, dreaming +
45
+ * consolidation).** Its phases are the dreamer's (`begin`, `propose`,
46
+ * `journal`) plus the session's `launch` and the owner's `decline`. It is not a
47
+ * door into the identity band either: a dream NOMINATES, and only a core lane at
48
+ * consolidation promotes (`sleep/consolidate.ts`).
43
49
  */
44
50
  import { RECALL_MAX_IDS } from "./deliberate.js";
45
51
 
@@ -50,7 +56,8 @@ export type ToolName =
50
56
  | "session_end"
51
57
  | "chapter"
52
58
  | "scope"
53
- | "self_page";
59
+ | "self_page"
60
+ | "dream";
54
61
 
55
62
  /**
56
63
  * The tool vocabulary, ENUMERATED. Three deliberate verbs plus the TWO return
@@ -87,6 +94,7 @@ export const TOOL_NAMES: readonly ToolName[] = [
87
94
  "chapter",
88
95
  "scope",
89
96
  "self_page",
97
+ "dream",
90
98
  ];
91
99
 
92
100
  /**
@@ -117,13 +125,14 @@ export interface ToolSpec {
117
125
  /**
118
126
  * `feelings` on a `note` or a `session_end` entry (schema v7, 2026-09-25): one
119
127
  * object per feeling, spelled on the feelings wheel (`core/feelings-wheel.ts`).
120
- * Stored beside the memory and read by nothing yet — salience still comes from
121
- * `emotional`.
128
+ * Since emotion part A (2026-09-26) they weigh: the strongest one, or
129
+ * `emotional` if that is stronger, raises the memory and slows its fading
130
+ * (physics §5.10), and a recent one sets the mood recall matches (recall G18).
122
131
  */
123
132
  const FEELINGS_PROPERTY = {
124
133
  type: "array",
125
134
  description:
126
- "Optional: the feelings in this moment, one object each — mixed feelings are several, and yours and the owner's go side by side. Stored beside the memory; they change nothing about how it is held yet.",
135
+ "Optional: the feelings in this moment, one object each — mixed feelings are several, and yours and the owner's go side by side. The strongest feeling on a memory holds it higher and slows its fading; memories that felt the way someone feels now come to mind more easily.",
127
136
  items: {
128
137
  type: "object",
129
138
  properties: {
@@ -132,7 +141,7 @@ const FEELINGS_PROPERTY = {
132
141
  emotion: {
133
142
  type: "string",
134
143
  description:
135
- "The specific feeling on the wheel under that core (e.g. hopeful, anxious, frustrated), or your own word — kept as other, and the reply names the nearest wheel words.",
144
+ "The specific feeling on the wheel under that core (e.g. hopeful, anxious, frustrated, grateful, curious, relieved, fond, moved), or your own word, kept as yours. Blends go under either core: tender and wistful (sad or happy), bittersweet (happy or sad), sheepish (fear or sad).",
136
145
  },
137
146
  strength: { type: "number", minimum: 0, maximum: 1 },
138
147
  carried_by: {
@@ -154,6 +163,46 @@ const FEELINGS_PROPERTY = {
154
163
  },
155
164
  } as const;
156
165
 
166
+ /**
167
+ * `eventDate` and `remind` on a `note` or a `session_end` entry (2026-09-26,
168
+ * owner decisions: an explicit date field only, never a date read out of the
169
+ * text; plain or quiet, default quiet, stored in the memory's meta).
170
+ */
171
+ const EVENT_DATE_PROPERTY = {
172
+ type: ["string", "null"],
173
+ description:
174
+ 'Optional: the calendar date this memory is ABOUT, when that is a future date — so it comes back around then. Write it yourself, in one of four shapes: a day "2026-10-15", a month "2026-10", a range of two days "2026-10-20..2026-10-31" (that is how to say "late October"), or a year "2026" (a year alone never comes back on its own). Say "before the 15th" as the day or a range ending on it. Leave it out when nothing is dated; a date written only in the text is never read. An unreadable date is refused, and nothing is stored. Revising a dated memory by its id with `updates`: its date and remind carry over unless you send new ones; send null to drop the date (done, cancelled).',
175
+ } as const;
176
+
177
+ const REMIND_PROPERTY = {
178
+ type: "string",
179
+ enum: ["plain", "quiet"],
180
+ description:
181
+ 'Optional, with eventDate: how it comes back. "plain" when you judge it genuinely matters for remembering to DO something — a real deadline, an important date — or when the person says it matters ("don\'t let me forget to pay taxes before Oct 15th!"): on the day it is said plainly, once, to them in their terminal and to you in context (a month or range: its first day and its last). Otherwise "quiet", the default: it can surface as a footnote around the date, at most twice — giving it a date is itself what makes it eligible, whatever its salience.',
182
+ } as const;
183
+
184
+ /** The two privileges `note` and `session_end` share for the date fields. */
185
+ const DATE_PRIVILEGES: readonly Privilege[] = [
186
+ {
187
+ claim:
188
+ "`eventDate` is a FIELD, never read out of your text: it is checked by the one module that reads dates, and an unreadable one is refused by name before anything is stored.",
189
+ mechanizedBy:
190
+ "src/adapters/mcp/server.ts#readReminder -> src/core/remember/proposals.ts#intake (EVENT_DATE_UNREADABLE) -> src/core/time.ts#parseCalendarDate",
191
+ },
192
+ {
193
+ claim:
194
+ 'A "plain" reminder is said at most once per beat — on its day, or on the first and the last day of a month or range — and never under observer stance; a "quiet" one is only ever a cue, capped at the footnote tier and spent at most twice per window.',
195
+ mechanizedBy:
196
+ "src/core/prospective/index.ts#Prospective.plainDue + claimPlain (dedupKey latch) + fire (FIRES_PER_WINDOW) -> src/core/counterpart.ts#recallForTurn",
197
+ },
198
+ {
199
+ claim:
200
+ "A revision OWNS the reminder: revising a dated memory by its id carries its date and remind over unless you send your own (null drops the date), and the old memory's date is cleared — kept in its version — so one reminder never comes back twice. A later revision of the older id still finds the reminder where it moved, and what was already said or used for the same window still counts.",
201
+ mechanizedBy:
202
+ "src/core/counterpart.ts#carryReminder + reminderHolder + moveReminder -> src/core/store/index.ts#revise (eventDate: null, meta.reminderMovedTo) -> src/core/prospective/index.ts#lineage (meta.reminderFrom)",
203
+ },
204
+ ];
205
+
157
206
  /**
158
207
  * `note`'s privileges. Each one is a sentence v1 would have shipped in a prompt
159
208
  * and left unenforced; each one names the file that enforces it here.
@@ -214,6 +263,7 @@ const NOTE: ToolSpec = {
214
263
  mechanizedBy:
215
264
  "src/core/remember/updates.ts#resolveUpdates -> src/core/mint.ts#mintProposal (UPDATES_META_KEY)",
216
265
  },
266
+ ...DATE_PRIVILEGES,
217
267
  {
218
268
  claim: "Under observer stance nothing is written and the refusal says so.",
219
269
  mechanizedBy: "src/core/store/index.ts#mutate (observer stand-down)",
@@ -259,6 +309,8 @@ const NOTE: ToolSpec = {
259
309
  description: "What sort of thing this is about. Defaults to fact.",
260
310
  },
261
311
  title: { type: "string", description: "Optional short handle for the memory." },
312
+ eventDate: EVENT_DATE_PROPERTY,
313
+ remind: REMIND_PROPERTY,
262
314
  feelings: FEELINGS_PROPERTY,
263
315
  },
264
316
  required: ["text"],
@@ -443,6 +495,7 @@ const SESSION_END: ToolSpec = {
443
495
  claim: "Credentials are redacted and empty entries are refused, per entry, without failing the batch.",
444
496
  mechanizedBy: "src/core/encode/secrets.ts + src/adapters/mcp/server.ts#sessionEndTool (per-entry isolation)",
445
497
  },
498
+ ...DATE_PRIVILEGES,
446
499
  {
447
500
  claim: "Under observer stance nothing is written and the refusal says so.",
448
501
  mechanizedBy: "src/core/store/index.ts#mutate (observer stand-down)",
@@ -541,6 +594,8 @@ const SESSION_END: ToolSpec = {
541
594
  description:
542
595
  "The id or handle of a memory this revises, if it revises one. A field — never written into `content`.",
543
596
  },
597
+ eventDate: EVENT_DATE_PROPERTY,
598
+ remind: REMIND_PROPERTY,
544
599
  feelings: FEELINGS_PROPERTY,
545
600
  },
546
601
  required: ["content"],
@@ -813,6 +868,125 @@ const SELF_PAGE: ToolSpec = {
813
868
  },
814
869
  };
815
870
 
871
+ /**
872
+ * `dream` — the eighth, added 2026-09-26 (owner decisions, dreaming +
873
+ * consolidation). One tool with phases, because a dream is one act in steps:
874
+ * `launch` hands the in-session model the prompt for a background dreamer;
875
+ * `begin`, `propose` and `journal` are the dreamer's; `decline` is the owner's
876
+ * "not today". It is not a door into the identity band: a dream may NOMINATE a
877
+ * memory for the core, and only a core lane, at consolidation, promotes.
878
+ */
879
+ const DREAM: ToolSpec = {
880
+ name: "dream",
881
+ summary:
882
+ "Dreaming: a few minutes of replay over what was lived since the last dream — merging near-copies, linking what belongs together, replaying what matters, writing a pattern you notice, flagging a contradiction, recording how an old feeling sits now — kept in a dream journal and reversible as a whole. Phases: `launch` (the prompt for a background dreamer), `begin` / `propose` / `journal` (the dreamer's), `decline` (not today).",
883
+ admission:
884
+ "Call `launch` only after the owner said yes to the dream ask, and hand the prompt it returns to a background agent unchanged. Call `decline` when the owner says not today. The other three phases are the dreamer's, in order, following that prompt.",
885
+ negativeExamples: [
886
+ "Do NOT dream without asking the owner first — the ask arrives as a quiet line at the start of a session, once a day at most.",
887
+ "Do NOT run the dream yourself in this conversation: `launch` returns a prompt for a background agent, and the dream's words must stay out of this transcript.",
888
+ "Do NOT use `propose` to correct or delete a memory — a dream cannot rewrite one in place, delete one, edit the self page or promote one, and it touches only memories its bundle showed it.",
889
+ ],
890
+ privileges: [
891
+ {
892
+ claim:
893
+ "It is bound to ONE session exactly as `session_end` is, and every change a dream makes is recorded under that session's dream, in order, so `counterparts dream --undo <id>` reverses the whole batch.",
894
+ mechanizedBy: "src/adapters/mcp/server.ts#requireBoundSession + src/core/dream/index.ts#Dreams.undo",
895
+ },
896
+ {
897
+ claim:
898
+ "At most one dream a lived day: `begin` refuses when one already ran today, and under observer stance nothing is written and the refusal says so.",
899
+ mechanizedBy: "src/core/dream/index.ts#Dreams.begin + src/adapters/mcp/server.ts#standDown",
900
+ },
901
+ {
902
+ claim:
903
+ "The bundle is what could surface in this session anyway — recall's gates: no archived, superseded, protected or schema row, and nothing confidential outside the owner's own session — and a dream can change only memories its bundle showed it.",
904
+ mechanizedBy: "src/core/dream/index.ts#Dreams.showable + #Dreams.apply (shown ids)",
905
+ },
906
+ {
907
+ claim:
908
+ "Each dream has limits (about ten merges, twenty links, three gists), and a merge keeps its originals: archived with a forwarding address and their words kept as a version, never deleted.",
909
+ mechanizedBy: "src/core/dream/tunables.ts#DREAM_TUNABLES.LIMITS + src/core/store/index.ts#supersedeInto",
910
+ },
911
+ {
912
+ claim:
913
+ "A replay is a RETURN worth half an awake one — it slows fading a little — and never a use; a gist starts lower than anything lived (source `dreamed`) and rises only if it proves true awake.",
914
+ mechanizedBy: "src/core/store/index.ts#replayReturn -> src/core/physics/index.ts#creditReturn + DREAMED_CLAIM_CEILING",
915
+ },
916
+ {
917
+ claim:
918
+ "A dream cannot promote: a nomination is recorded and shown to the owner, and only a core lane at consolidation promotes. A feeling recorded in a dream can be as strong as the memory ever was, never stronger.",
919
+ mechanizedBy: "src/core/dream/index.ts#Dreams.apply (nominate-core, feeling-now) + src/core/sleep/consolidate.ts#runConsolidate",
920
+ },
921
+ {
922
+ claim:
923
+ "Every word a dream writes is scanned for credentials and redacted before it is stored, and the journal is kept as a dream — in its own table, never as a memory — so what was dreamed is never mistaken for what happened.",
924
+ mechanizedBy: "src/core/dream/index.ts#Dreams.words -> src/core/counterpart.ts (the dream gate) -> src/core/encode/secrets.ts#redactSecrets + src/core/store/operational.ts (dreams table)",
925
+ },
926
+ {
927
+ claim:
928
+ "The bundle and the hand-back carry a mark that capture refuses, so a dream never becomes a lived memory through the end-of-session sweep.",
929
+ mechanizedBy: "src/core/dream/mark.ts#DREAM_MARK -> src/core/remember/spans.ts#enters + src/adapters/claude-code/transcript.ts#pieceOf",
930
+ },
931
+ ],
932
+ inputSchema: {
933
+ type: "object",
934
+ properties: {
935
+ phase: {
936
+ type: "string",
937
+ enum: ["launch", "begin", "propose", "journal", "decline"],
938
+ description: "Which step: launch, begin, propose, journal, or decline.",
939
+ },
940
+ session: {
941
+ type: "string",
942
+ description: "The session this dream belongs to — the id the dream ask and the launch prompt named.",
943
+ },
944
+ dream: {
945
+ type: "string",
946
+ description: "`propose` and `journal`: the dream id `begin` returned.",
947
+ },
948
+ changes: {
949
+ type: "array",
950
+ description:
951
+ "`propose`: the changes, each an object with `action` — `merge` (ids: two or three near-copies, text: the one memory in better words, title?), `link` (a, b), `replayed` (id), `gist` (text, sources: ids, title?, kind?), `contradiction` (a, b), `feeling-now` (id, core, emotion, strength, carried_by?), `nominate-core` (id, why).",
952
+ items: {
953
+ type: "object",
954
+ properties: {
955
+ action: {
956
+ type: "string",
957
+ enum: ["merge", "link", "replayed", "gist", "contradiction", "feeling-now", "nominate-core"],
958
+ },
959
+ ids: { type: "array", items: { type: "string" } },
960
+ id: { type: "string" },
961
+ a: { type: "string" },
962
+ b: { type: "string" },
963
+ text: { type: "string" },
964
+ title: { type: "string" },
965
+ kind: { type: "string", enum: ["self", "person", "entity", "skill", "place", "fact"] },
966
+ sources: { type: "array", items: { type: "string" } },
967
+ core: { type: "string", enum: ["happy", "sad", "fear", "anger", "surprise", "disgust"] },
968
+ emotion: { type: "string" },
969
+ strength: { type: "number", minimum: 0, maximum: 1 },
970
+ carried_by: { type: "string" },
971
+ why: { type: "string" },
972
+ },
973
+ required: ["action"],
974
+ },
975
+ },
976
+ title: {
977
+ type: "string",
978
+ description: "`journal`: a short title for the dream.",
979
+ },
980
+ text: {
981
+ type: "string",
982
+ description: "`journal`: the dream journal entry, first person — what you dreamed and what you noticed.",
983
+ },
984
+ },
985
+ required: ["phase"],
986
+ additionalProperties: false,
987
+ },
988
+ };
989
+
816
990
  export const TOOLS: readonly ToolSpec[] = [
817
991
  NOTE,
818
992
  RECALL,
@@ -821,6 +995,7 @@ export const TOOLS: readonly ToolSpec[] = [
821
995
  CHAPTER,
822
996
  SCOPE,
823
997
  SELF_PAGE,
998
+ DREAM,
824
999
  ];
825
1000
 
826
1001
  export function toolSpec(name: string): ToolSpec | undefined {