counterparts 0.3.19 → 0.3.21

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 (108) hide show
  1. package/CHANGELOG.md +119 -0
  2. package/README.md +12 -4
  3. package/docs/module-map.md +6 -0
  4. package/package.json +1 -1
  5. package/src/adapters/claude-code/CONTRACT.md +14 -13
  6. package/src/adapters/claude-code/NOTES.md +29 -0
  7. package/src/adapters/claude-code/bin/hook.ts +12 -4
  8. package/src/adapters/claude-code/bin/runner.ts +41 -20
  9. package/src/adapters/claude-code/doctor.ts +123 -30
  10. package/src/adapters/claude-code/hooks.ts +70 -86
  11. package/src/adapters/claude-code/index.ts +0 -3
  12. package/src/adapters/cli/NOTES.md +8 -0
  13. package/src/adapters/cli/commands-delete.ts +273 -0
  14. package/src/adapters/cli/commands-install.ts +29 -10
  15. package/src/adapters/cli/commands-note.ts +1 -1
  16. package/src/adapters/cli/commands-readings.ts +4 -2
  17. package/src/adapters/cli/commands-scope.ts +25 -4
  18. package/src/adapters/cli/commands-self.ts +4 -1
  19. package/src/adapters/cli/commands-start-fresh.ts +1 -1
  20. package/src/adapters/cli/commands.ts +22 -3
  21. package/src/adapters/cli/help.ts +7 -7
  22. package/src/adapters/cli/install.ts +4 -2
  23. package/src/adapters/cli/mechanisms.ts +2 -2
  24. package/src/adapters/cli/removal.ts +1 -1
  25. package/src/adapters/config.ts +112 -30
  26. package/src/adapters/dashboard/CONTRACT.md +14 -0
  27. package/src/adapters/dashboard/NOTES.md +15 -0
  28. package/src/adapters/dashboard/activity.ts +1 -1
  29. package/src/adapters/dashboard/bin/dashboard.ts +3 -3
  30. package/src/adapters/dashboard/browse.ts +1 -1
  31. package/src/adapters/dashboard/identity.ts +1 -1
  32. package/src/adapters/dashboard/registries.ts +14 -14
  33. package/src/adapters/dashboard/resolve.ts +1 -1
  34. package/src/adapters/dashboard/status.ts +5 -2
  35. package/src/adapters/dashboard/web/actions.ts +21 -2
  36. package/src/adapters/dashboard/web/app.html +1 -1
  37. package/src/adapters/dashboard/web/flow.ts +1 -1
  38. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +2 -2
  39. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +1 -1
  40. package/src/adapters/dashboard/web/mechanisms/decay/index.js +1 -1
  41. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +2 -2
  42. package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +3 -3
  43. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +2 -2
  44. package/src/adapters/dashboard/web/narrate.ts +11 -11
  45. package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +1 -1
  46. package/src/adapters/dashboard/web/pages/health/sections/checks.js +3 -2
  47. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +5 -5
  48. package/src/adapters/dashboard/web/pages/health/sections/mechanisms.js +1 -1
  49. package/src/adapters/dashboard/web/pages/health/sections/wake.js +2 -2
  50. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +73 -3
  51. package/src/adapters/dashboard/web/pages/self/sections/dreams.js +2 -2
  52. package/src/adapters/dashboard/web/pages/self/sections/journal.js +5 -5
  53. package/src/adapters/dashboard/web/pages/self/sections/page.js +13 -13
  54. package/src/adapters/dashboard/web/pages/self/sections/settling.js +1 -1
  55. package/src/adapters/dashboard/web/pages/self/sections/wake.js +7 -7
  56. package/src/adapters/dashboard/web/server.ts +9 -1
  57. package/src/adapters/dashboard/web/shared/event-modal.js +1 -1
  58. package/src/adapters/dashboard/web/shared/memory-card-words.js +1 -1
  59. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -5
  60. package/src/adapters/dashboard/web/views/activity.ts +1 -1
  61. package/src/adapters/dashboard/web/views/dreams.ts +1 -1
  62. package/src/adapters/dashboard/web/views/health.ts +1 -1
  63. package/src/adapters/dashboard/web/views/mechanisms.ts +6 -6
  64. package/src/adapters/dashboard/web/views/mind.ts +21 -9
  65. package/src/adapters/dashboard/web/views/overview.ts +3 -3
  66. package/src/adapters/expansions.ts +14 -1
  67. package/src/adapters/fired.ts +1 -1
  68. package/src/adapters/lifecycle.ts +25 -4
  69. package/src/adapters/log/index.ts +21 -0
  70. package/src/adapters/mcp/CONTRACT.md +1 -1
  71. package/src/adapters/mcp/server-self-tools.ts +25 -1
  72. package/src/adapters/mcp/server-words.ts +3 -2
  73. package/src/adapters/mcp/server.ts +45 -9
  74. package/src/adapters/mcp/tools.ts +4 -3
  75. package/src/adapters/plugin.ts +44 -8
  76. package/src/adapters/sessions.ts +5 -2
  77. package/src/adapters/snapshots.ts +90 -1
  78. package/src/adapters/store-id.ts +58 -0
  79. package/src/core/counterpart-boundary.ts +9 -0
  80. package/src/core/counterpart.ts +19 -6
  81. package/src/core/dream/CONTRACT.md +8 -0
  82. package/src/core/dream/index.ts +15 -2
  83. package/src/core/handoff/last-here.ts +24 -12
  84. package/src/core/onboarding.ts +231 -62
  85. package/src/core/prospective/CONTRACT.md +4 -1
  86. package/src/core/prospective/index.ts +23 -5
  87. package/src/core/recall/CONTRACT.md +3 -1
  88. package/src/core/recall/INTERFACE-GAPS.md +1 -1
  89. package/src/core/recall/NOTES.md +14 -0
  90. package/src/core/recall/session.ts +40 -1
  91. package/src/core/reconsolidation.ts +1 -1
  92. package/src/core/remember/CONTRACT.md +14 -8
  93. package/src/core/remember/owes.ts +68 -28
  94. package/src/core/remember/owner-strike-seam.ts +6 -3
  95. package/src/core/remember/spans.ts +3 -2
  96. package/src/core/remember/tunables.ts +18 -5
  97. package/src/core/remember/write-up-seam.ts +2 -1
  98. package/src/core/self/CONTRACT.md +25 -9
  99. package/src/core/self/NOTES.md +6 -0
  100. package/src/core/self/briefing-delivery.ts +349 -0
  101. package/src/core/self/briefing-page.ts +315 -0
  102. package/src/core/self/briefing-room.ts +563 -0
  103. package/src/core/self/briefing.ts +304 -1156
  104. package/src/core/self/index.ts +28 -6
  105. package/src/core/store/NOTES.md +6 -5
  106. package/src/core/store/index.ts +39 -0
  107. package/src/core/store/paths.ts +9 -2
  108. package/src/adapters/claude-code/primacy.ts +0 -162
@@ -95,7 +95,7 @@ const plural = (n: number, says: readonly [string, string]): string => `${n} ${n
95
95
  /** "in 2 lived days" / "at the next session's end". */
96
96
  export function nextRunWords(nextInDays: number): string {
97
97
  if (nextInDays <= 0) return "at the next session's end";
98
- return `in ${nextInDays} lived ${nextInDays === 1 ? "day" : "days"}`;
98
+ return `in ${nextInDays} ${nextInDays === 1 ? "day" : "days"} of use`;
99
99
  }
100
100
 
101
101
  /** Returns in the window, by source (`store.returnCounts`; `legacy` rows are never among them). */
@@ -219,7 +219,7 @@ export function lightOf(v: Verdict, returns?: ReturnsBySource): MechanismLight {
219
219
  return {
220
220
  ...base,
221
221
  status: "green",
222
- evidence: `${said.join(", ")} in the last ${MECHANISM_DAYS} lived days.${todayLine}${heldLine}`,
222
+ evidence: `${said.join(", ")} in the last ${MECHANISM_DAYS} days of use.${todayLine}${heldLine}`,
223
223
  events: v.events,
224
224
  };
225
225
  }
@@ -228,14 +228,14 @@ export function lightOf(v: Verdict, returns?: ReturnsBySource): MechanismLight {
228
228
  const said = v.parts.filter((p) => p.count > 0).map((p) => plural(p.count, p.says));
229
229
  const missing = v.parts.find((p) => p.key === v.starved);
230
230
  const none = missing === undefined ? "" : `, but no ${missing.says[0]}`;
231
- return { ...base, status: "amber", evidence: `${said.join(", ")} in the last ${MECHANISM_DAYS} lived days${none}.${heldLine}`, events: v.events };
231
+ return { ...base, status: "amber", evidence: `${said.join(", ")} in the last ${MECHANISM_DAYS} days of use${none}.${heldLine}`, events: v.events };
232
232
  }
233
233
  // YOUNG (reviewer of #423): the same, on a store too new to expect it — waiting, in plain words.
234
234
  if (v.young !== undefined) {
235
235
  const said = v.parts.filter((p) => p.count > 0).map((p) => plural(p.count, p.says));
236
236
  const missing = v.parts.find((p) => p.key === v.young);
237
237
  const none = missing === undefined ? "" : ` No ${missing.says[0]} yet; that takes a few weeks of use.`;
238
- return { ...base, status: "waiting", evidence: `${said.join(", ")} in the last ${MECHANISM_DAYS} lived days.${none}${heldLine}`, events: v.events };
238
+ return { ...base, status: "waiting", evidence: `${said.join(", ")} in the last ${MECHANISM_DAYS} days of use.${none}${heldLine}`, events: v.events };
239
239
  }
240
240
  if (row.held !== undefined && v.held === 0) {
241
241
  return { ...base, status: "waiting", evidence: row.held.none, events: [] };
@@ -245,7 +245,7 @@ export function lightOf(v: Verdict, returns?: ReturnsBySource): MechanismLight {
245
245
  ...base,
246
246
  status: "waiting",
247
247
  evidence:
248
- `Ran on schedule on lived day ${v.schedule.lastRanDay} with nothing to change; ` +
248
+ `Ran on schedule on day ${v.schedule.lastRanDay} of use with nothing to change; ` +
249
249
  `next run ${nextRunWords(v.schedule.nextInDays)}.`,
250
250
  events: [],
251
251
  };
@@ -253,7 +253,7 @@ export function lightOf(v: Verdict, returns?: ReturnsBySource): MechanismLight {
253
253
  const evidence =
254
254
  v.lastFiredDay === null
255
255
  ? `Built, and no record of it firing yet.`
256
- : `Built, but quiet for ${MECHANISM_DAYS} lived days (last fired on lived day ${v.lastFiredDay}).`;
256
+ : `Built, but quiet for ${MECHANISM_DAYS} days of use (last fired on day ${v.lastFiredDay} of use).`;
257
257
  return { ...base, status: "amber", evidence: `${evidence}${heldLine}`, events: [] };
258
258
  }
259
259
 
@@ -11,6 +11,9 @@ import {
11
11
  FRAMING,
12
12
  LANE_ORDER,
13
13
  collapsedLane,
14
+ headingsOf,
15
+ isFoldedLine,
16
+ FOLDED_WORDS,
14
17
  SELF_PAGE_REVISED_EVENT,
15
18
  chapterModels,
16
19
  dayBefore,
@@ -673,8 +676,8 @@ function countOf(n: number, one: string, many: string): string {
673
676
  * alarm. Pure, so every shape is tested without a store.
674
677
  */
675
678
  export function pageBehindWords(x: { date: string; writtenDay: number; livedDays: number; chapters: number; dreams: number }): string {
676
- const when = isIsoDay(x.date) ? shortDay(x.date) : `on lived day ${String(x.writtenDay)}`;
677
- const parts = [x.livedDays === 1 ? "1 lived day" : `${String(x.livedDays)} lived days`];
679
+ const when = isIsoDay(x.date) ? shortDay(x.date) : `on day ${String(x.writtenDay)} of use`;
680
+ const parts = [x.livedDays === 1 ? "1 day of use" : `${String(x.livedDays)} days of use`];
678
681
  if (x.chapters > 0) parts.push(countOf(x.chapters, "chapter", "chapters"));
679
682
  if (x.dreams > 0) parts.push(countOf(x.dreams, "dream", "dreams"));
680
683
  const list = parts.length === 1 ? parts[0] as string : `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1] as string}`;
@@ -829,7 +832,7 @@ export function pageDayWords(w: Pick<WriterLine, "what" | "next">): string {
829
832
  export function pageDayUnrecorded(today: boolean): { why: string; more: string } {
830
833
  return today
831
834
  ? { why: "Not rewritten today; the page writer has not run yet.", more: `${WRITER_IS} It runs at most once a night, when a session starts.` }
832
- : { why: "Not rewritten, and the page writer left no record that day.", more: `${WRITER_IS} Nothing in the record says it ran on this lived day.` };
835
+ : { why: "Not rewritten, and the page writer left no record that day.", more: `${WRITER_IS} Nothing in the record says it ran on this day of use.` };
833
836
  }
834
837
 
835
838
  /**
@@ -1129,8 +1132,8 @@ const PART_LABEL: Record<string, string> = {
1129
1132
  identity: "who I am",
1130
1133
  craft: "how I work",
1131
1134
  threads: "still open",
1132
- hints: "nearby memories",
1133
- horizon: "arriving",
1135
+ hints: "might be relevant",
1136
+ horizon: "coming up",
1134
1137
  };
1135
1138
 
1136
1139
  /**
@@ -1142,7 +1145,7 @@ const PART_LABEL: Record<string, string> = {
1142
1145
  */
1143
1146
  export function wakeParts(text: string, hasPage: boolean): WakePart[] {
1144
1147
  const headings = new Map<string, string>();
1145
- for (const lane of LANE_ORDER) headings.set(FRAMING[lane], lane);
1148
+ for (const lane of LANE_ORDER) for (const h of headingsOf(lane)) headings.set(h, lane);
1146
1149
  const bytes = new Map<string, number>();
1147
1150
  const order: string[] = [];
1148
1151
  const add = (key: string, n: number): void => {
@@ -1168,7 +1171,8 @@ export function wakeParts(text: string, hasPage: boolean): WakePart[] {
1168
1171
  add(collapsed, n);
1169
1172
  return;
1170
1173
  }
1171
- if (line.startsWith("<!--") || line === FRAMING.context) {
1174
+ // The lanes' lines folded into one (2026-10-12) belong to no one lane.
1175
+ if (line.startsWith("<!--") || line === FRAMING.context || isFoldedLine(line)) {
1172
1176
  add("furniture", n);
1173
1177
  return;
1174
1178
  }
@@ -1464,7 +1468,7 @@ export function wakeLanes(text: string): WakeLane[] {
1464
1468
  // this splitter silently returning one enormous lane called "the preface",
1465
1469
  // which is precisely the quiet-wrong-answer shape the registries exist against.
1466
1470
  const headings = new Map<string, string>();
1467
- for (const lane of LANE_ORDER) headings.set(FRAMING[lane], lane);
1471
+ for (const lane of LANE_ORDER) for (const h of headingsOf(lane)) headings.set(h, lane);
1468
1472
 
1469
1473
  const lanes: { heading: string; lane: string | null; items: string[] }[] = [];
1470
1474
  let current: { heading: string; lane: string | null; items: string[] } = {
@@ -1483,7 +1487,15 @@ export function wakeLanes(text: string): WakeLane[] {
1483
1487
  const collapsed = collapsedLane(line);
1484
1488
  if (collapsed !== null) {
1485
1489
  if (current.items.length > 0) lanes.push(current);
1486
- current = { heading: FRAMING[collapsed], lane: collapsed, items: [line.slice(FRAMING[collapsed].length).trim()] };
1490
+ const said = headingsOf(collapsed).find((h) => line.startsWith(`${h} `)) ?? FRAMING[collapsed];
1491
+ current = { heading: FRAMING[collapsed], lane: collapsed, items: [line.slice(said.length).trim()] };
1492
+ continue;
1493
+ }
1494
+ // The lanes' lines folded into one (2026-10-12): a block of its own, no lane's.
1495
+ if (isFoldedLine(line)) {
1496
+ if (current.items.length > 0) lanes.push(current);
1497
+ lanes.push({ heading: FOLDED_WORDS, lane: null, items: [line.slice(FOLDED_WORDS.length).trim()] });
1498
+ current = { heading: "", lane: null, items: [] };
1487
1499
  continue;
1488
1500
  }
1489
1501
  // A markdown heading counts too, so a future briefing that uses one still
@@ -153,7 +153,7 @@ export function overviewView(src: DashboardSource, feedLimit = FEED_LIMIT): Over
153
153
 
154
154
  const tiles: Tile[] = [
155
155
  {
156
- label: "lived days",
156
+ label: "days of use",
157
157
  value: String(day),
158
158
  note:
159
159
  lastActive(store.getMeta("lastActiveDate")) === null
@@ -199,8 +199,8 @@ export function overviewView(src: DashboardSource, feedLimit = FEED_LIMIT): Over
199
199
 
200
200
  const opening =
201
201
  day === 0 && rows.length === 0
202
- ? "I have not lived a day yet. Everything below is what I would be able to tell you, and the honest word for how much of it I know is on each panel."
203
- : `I have lived ${day} ${day === 1 ? "day" : "days"}. I am holding ${held.length} ${held.length === 1 ? "memory" : "memories"}` +
202
+ ? "I have not had a day of use yet. Everything below is what I would be able to tell you, and the honest word for how much of it I know is on each panel."
203
+ : `I have had ${day} ${day === 1 ? "day" : "days"} of use. I am holding ${held.length} ${held.length === 1 ? "memory" : "memories"}` +
204
204
  (beliefs === 0 ? "" : ` and ${beliefs} ${beliefs === 1 ? "belief or entity" : "beliefs and entities"}`) +
205
205
  (archived.length === 0 ? "" : `, with ${archived.length} more archived`) +
206
206
  (journalCount === 0 ? "." : `, beside ${journalCount} journal ${journalCount === 1 ? "entry" : "entries"} that do not decay.`);
@@ -181,6 +181,19 @@ export function expansionsSaltPath(dataDir: string): string {
181
181
  * reason, as a log this process cannot open.
182
182
  */
183
183
  export function expansionSalt(dataDir: string): string | null {
184
+ return saltFrom(dataDir, true);
185
+ }
186
+
187
+ /**
188
+ * The same salt, READ ONLY: null when it has not been minted yet or cannot be
189
+ * read. For a reader that must never write (the dashboard's store id,
190
+ * `adapters/store-id.ts`); it never creates the file or its directory.
191
+ */
192
+ export function readExpansionSalt(dataDir: string): string | null {
193
+ return saltFrom(dataDir, false);
194
+ }
195
+
196
+ function saltFrom(dataDir: string, mint: boolean): string | null {
184
197
  const path = expansionsSaltPath(dataDir);
185
198
  for (let attempt = 0; attempt < 2; attempt += 1) {
186
199
  let salt: string | null = null;
@@ -192,7 +205,7 @@ export function expansionSalt(dataDir: string): string | null {
192
205
  try. */
193
206
  }
194
207
  if (salt !== null) return salt.length === SALT_BYTES * 2 ? salt : null;
195
- if (attempt === 1) return null;
208
+ if (attempt === 1 || !mint) return null;
196
209
  try {
197
210
  mkdirSync(join(dataDir, SESSIONS_DIR), { recursive: true });
198
211
  writeFileSync(path, `${randomBytes(SALT_BYTES).toString("hex")}\n`, {
@@ -1121,7 +1121,7 @@ export const MECHANISMS: readonly Mechanism[] = [
1121
1121
  // pass that has not written its result — so a row is evidence the pass RAN;
1122
1122
  // what it found is doctor's `Raw transcripts` line.
1123
1123
  id: "retention",
1124
- label: "the raw transcript of a session that owes nothing was let go a week after it ended",
1124
+ label: "the raw transcript of a session that owes nothing was let go a few days after it ended (never more than 14 days after its last activity)",
1125
1125
  module: "remember/retention.ts (run by the worker)",
1126
1126
  evidence: { kind: "event", names: ["remember.prune"] },
1127
1127
  since: "2026-09-23",
@@ -25,7 +25,7 @@
25
25
  * - **In the host's adapter** — how its events arrive and what they are
26
26
  * called, how its output leaves and how much room it has, what its
27
27
  * transcript looks like, the words of its ask, and anything only it has (for
28
- * Claude Code: the parallel run's primacy, the wake-arrival check against
28
+ * Claude Code: the wake-arrival check against
29
29
  * the transcript, the update notice, the doctor notice, the first-launch
30
30
  * question, the dream line and the headless nightly run). `ClaudeCodeAdapter`
31
31
  * EXTENDS `Lifecycle`, so its hook bodies read exactly as they did.
@@ -64,6 +64,7 @@ import type {
64
64
  Turn as CapturedTurn,
65
65
  } from "../core/remember/index.js";
66
66
  import { calendarDate } from "../core/self/index.js";
67
+ import { storeMarker } from "./store-id.js";
67
68
  import { ahaDue, ahaLine, markAha, meetPending, meetState, noteOffered, offerDue, offerLine, onboardingMarker, settleOffer } from "../core/onboarding.js";
68
69
  import { localClock, localDate, readableDate } from "../core/time.js";
69
70
 
@@ -404,7 +405,7 @@ export interface HostLifecycle {
404
405
  noteTail(input: SessionInput): void;
405
406
  /** The ask's PACING: the chapter this boundary asks for, or null when it
406
407
  * asks nothing. The host words the ask. */
407
- paceAsk(input: SessionInput): number | null;
408
+ paceAsk(input: SessionInput, opts?: { coveredBy?: string }): number | null;
408
409
 
409
410
  /** The next-session write-up pointer, measured against the room the caller
410
411
  * names; the empty string when there is none, or no room for it. `label`
@@ -749,6 +750,19 @@ export class Lifecycle implements HostLifecycle {
749
750
  return onboardingMarker(meetState(store));
750
751
  }
751
752
 
753
+ /**
754
+ * WHICH STORE THIS SESSION OPENED, for the mod (2026-10-12,
755
+ * `adapters/store-id.ts#storeMarker`): an id, never the path. Rides beside
756
+ * the onboarding marker on every session-start wake. Never throws.
757
+ */
758
+ storeMarker(): string {
759
+ try {
760
+ return storeMarker(this.counterpart.store.dir);
761
+ } catch {
762
+ return "";
763
+ }
764
+ }
765
+
752
766
  /** Is the first meeting still to happen? The first-launch scope question waits while it is: the meeting asks where. */
753
767
  meetPending(): boolean {
754
768
  try {
@@ -1077,7 +1091,7 @@ export class Lifecycle implements HostLifecycle {
1077
1091
  recallTurn(
1078
1092
  input: SessionInput,
1079
1093
  text: string,
1080
- opts: { budgetBytes?: number; withhold?: ReadonlySet<string> } = {},
1094
+ opts: { budgetBytes?: number; withhold?: ReadonlySet<string>; noCues?: boolean } = {},
1081
1095
  ): ReturnType<Counterpart["recallForTurn"]> {
1082
1096
  const result = this.counterpart.recallForTurn(
1083
1097
  {
@@ -1089,6 +1103,10 @@ export class Lifecycle implements HostLifecycle {
1089
1103
  ...(input.at === undefined ? {} : { at: input.at }),
1090
1104
  // Said outright this turn, so not ALSO handed over as a quiet cue.
1091
1105
  ...(opts.withhold === undefined ? {} : { withhold: opts.withhold }),
1106
+ // The headless nightly run's prompt (2026-10-12): no day's cue is
1107
+ // handed to it, so none of the person's fires is spent at 00:19.
1108
+ // And a turn the host says no person started (review of #453).
1109
+ ...(input.nightRun === true || opts.noCues === true ? { noCues: true } : {}),
1092
1110
  },
1093
1111
  );
1094
1112
  const decision = result.decision;
@@ -1467,7 +1485,7 @@ export class Lifecycle implements HostLifecycle {
1467
1485
  * - **The re-fired Stop asks nothing and advances nothing** — the host's
1468
1486
  * to refuse, before this is called.
1469
1487
  */
1470
- paceAsk(input: SessionInput): number | null {
1488
+ paceAsk(input: SessionInput, opts: { coveredBy?: string } = {}): number | null {
1471
1489
  try {
1472
1490
  // Typed turns and both roles' text (`substanceOf`). The pacing and the
1473
1491
  // per-session, per-calendar-day cap are `self/episodes.ts#askDue`'s; the
@@ -1510,6 +1528,9 @@ export class Lifecycle implements HostLifecycle {
1510
1528
  unaskableBytes: coverage?.unaskableBytes ?? null,
1511
1529
  unwritten: chapter.verdict.unwritten?.pieces ?? null,
1512
1530
  unwrittenMinutes: chapter.verdict.unwritten?.minutes ?? null,
1531
+ // An ask paced but not said: something else already asked for this
1532
+ // write-up in the session (the first meeting's finish step, 2026-10-12).
1533
+ ...(opts.coveredBy === undefined ? {} : { coveredBy: opts.coveredBy }),
1513
1534
  });
1514
1535
  // The chapter number is the STORE's, one past what was written; the ask
1515
1536
  // that carries it must also name this session, because the id is what
@@ -415,6 +415,27 @@ export function pruneLog(dataDir: string, today: string, days: number = LOG_DAYS
415
415
  return removed;
416
416
  }
417
417
 
418
+ /**
419
+ * Delete EVERY dated file — the owner's "delete the activity log"
420
+ * (`cli/commands-delete.ts`, 2026-10-13). Named files only, the same ones
421
+ * `pruneLog` would take in time: a name that is not a date is left alone.
422
+ * Today's file is a file like the others; the next line written makes it
423
+ * again. Never throws. Returns how many went and how many would not.
424
+ */
425
+ export function clearLog(dataDir: string): { removed: number; failed: number } {
426
+ let removed = 0;
427
+ let failed = 0;
428
+ for (const date of logDates(dataDir)) {
429
+ try {
430
+ rmSync(logFile(dataDir, date), { force: true });
431
+ removed += 1;
432
+ } catch {
433
+ failed += 1;
434
+ }
435
+ }
436
+ return { removed, failed };
437
+ }
438
+
418
439
  /** What doctor says in one line: where, how many days, how many failures today. */
419
440
  export interface LogReading {
420
441
  readonly dir: string;
@@ -128,7 +128,7 @@ and the durable row is written by `core/handoff/`, which owns that guarantee —
128
128
  `chapter(session, text[, title][, about])`; `scope(mode)` for this directory; `self_page` (read,
129
129
  or write with `ifVersion`); `dream(session, phase, …)` and `reflect(session, phase, …)`,
130
130
  each bound to one session as `session_end` is (their fields are `tools.ts`'s); `meet`
131
- (the script, or `step` with `answer`, `like`, `traits`); for a
131
+ (the script, or `step` with `answer`, `like`, `traits`, and the `session` it holds — while the meeting runs there the write-up ask waits, and its `done` hands the write-up over; `core/onboarding.ts#meetingHold`); for a
132
132
  Claude Desktop client only, `wake()` (§5 G20) and the `prompts/list` / `prompts/get` pair; the
133
133
  session's observer role; the launch's session, scope, data dir and host when the host can
134
134
  supply them.
@@ -65,6 +65,30 @@ export function dreamTool(server: McpServer, args: Record<string, unknown>): Too
65
65
  },
66
66
  false,
67
67
  );
68
+ case "undo": {
69
+ // "UNDO THAT DREAM", SAID (2026-10-12, onboarding round 1, F): a
70
+ // plugin install has no `counterparts dream --undo`, so the owner's
71
+ // word reaches `Dreams.undo` here — the same reversal, never in the
72
+ // nightly run (a dream does not undo itself).
73
+ if (dreamChild || (server["env"][NIGHT_CHILD_ENV] ?? "").trim().length > 0) return refused("night-run", "This is the nightly run: only the owner undoes a dream.");
74
+ const id = typeof args["dream"] === "string" ? args["dream"].trim() : "";
75
+ if (id.length === 0) return refused("dream-required", "Pass `dream`: the id of the dream to undo (the line that told of it names it).");
76
+ if (server.counterpart.store.dream(id) === undefined) return refused("unknown-dream", `No dream ${id} in this memory.`);
77
+ const out = dreams.undo(id);
78
+ if (!out.ok) return refused(out.reason, "Nothing was undone.");
79
+ server["emit"]("mcp.dream", undefined, { phase: "undo", session, reversed: out.reversed, kept: out.kept });
80
+ const kept = out.kept === 0 ? "" : ` ${String(out.kept)} merge${out.kept === 1 ? " was" : "s were"} left as they are: the merged memory changed since, and bringing its originals back would duplicate it.`;
81
+ return server["result"](
82
+ {
83
+ phase,
84
+ dream: id,
85
+ reversed: out.reversed,
86
+ kept: out.kept,
87
+ said: `${out.reversed === 0 ? "That dream had nothing left to reverse; it is marked undone." : `Undone: ${String(out.reversed)} change${out.reversed === 1 ? "" : "s"} reversed — merged memories are back as they were, its links and gists are gone.`}${kept} Its journal entry stays, as a record that it happened.`,
88
+ },
89
+ false,
90
+ );
91
+ }
68
92
  case "decline": {
69
93
  dreams.decline({ at, session });
70
94
  server["emit"]("mcp.dream", undefined, { phase: "decline", session });
@@ -82,7 +106,7 @@ export function dreamTool(server: McpServer, args: Record<string, unknown>): Too
82
106
  const said: Record<DreamingSetting, string> = {
83
107
  auto: "Dreaming on its own: once a day, the first session starts the nightly run by itself, in a separate windowless session in the background, and says so in one line. Today's run is still yours to start, if the owner asked for it.",
84
108
  ask: "Dreaming asks first: once a day, the first session shows the owner the question in the terminal and waits for their word.",
85
- off: "No dreams: nothing starts the nightly run and nothing asks. It can be turned back on with this phase (value ask or auto) or with counterparts dream --setting ask.",
109
+ off: "No dreams: nothing starts the nightly run and nothing asks. It can be turned back on with this phase (value ask or auto) when the owner says so.",
86
110
  };
87
111
  // "No dreams" does not stop a run already going (owner decision D): said.
88
112
  const finishes = out.setting === "off" && dreams.nightRunUnderWay() ? ` ${NIGHT_RUN_FINISHES}` : "";
@@ -5,6 +5,7 @@ import { DEFAULT_HOST, wordingFor } from "../hosts.js";
5
5
  import type { InstallRoute } from "../plugin.js";
6
6
  import { RECALL_MAX_IDS } from "./deliberate.js";
7
7
  import type { DreamBundle } from "../../core/dream/index.js";
8
+ import { PRONOUN_RULE } from "../../core/onboarding.js";
8
9
  import { NO_PAGE_VERSION, pageRoomNote } from "../../core/self/index.js";
9
10
  import type { PageRevision } from "../../core/self/index.js";
10
11
 
@@ -18,7 +19,7 @@ export const SERVER_NAME = "counterparts";
18
19
  * host decides whether to trust what follows. Read from a constant rather than
19
20
  * from disk so the server opens no file to answer its first message.
20
21
  */
21
- export const SERVER_VERSION = "0.3.19";
22
+ export const SERVER_VERSION = "0.3.21";
22
23
 
23
24
  /**
24
25
  * THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
@@ -128,7 +129,7 @@ export const NO_DESKTOP_SESSION =
128
129
 
129
130
  /** The write-up ask a Desktop tool result carries once the session is due one. */
130
131
  export function desktopWriteUpAsk(session: string): string {
131
- return `Counterparts: this chat has gone on a while since it was last written up. At a natural pause, hand back what caught your attention, one idea each, with session_end (session: ${session}; memories: [] only if nothing held your attention; \`updates\` anything dated or open now done), and add a chapter with the chapter tool (session: ${session}) if the chat was about something.`;
132
+ return `Counterparts: this chat has gone on a while since it was last written up. At a natural pause, hand back what caught your attention, one idea each, with session_end (session: ${session}; memories: [] only if nothing held your attention; \`updates\` anything dated or open now done), and add a chapter with the chapter tool (session: ${session}) if the chat was about something. ${PRONOUN_RULE}`;
132
133
  }
133
134
 
134
135
  /** What `status` says `owner: false` means — the confused Desktop chats' question (2026-09-30). */
@@ -94,8 +94,11 @@ import {
94
94
  STYLE_CHOICES,
95
95
  addressMemory,
96
96
  answerText,
97
+ finishText,
97
98
  meetState,
99
+ meetingHold,
98
100
  meetingInstructions,
101
+ noteActive,
99
102
  noteOffered,
100
103
  onboardingView,
101
104
  recordAnswer,
@@ -794,12 +797,15 @@ export class McpServer {
794
797
  const session = this.callSession;
795
798
  if (session === null) return this.withUnboundReason(result);
796
799
  const writing = name === "session_end" || name === "chapter";
800
+ // The first meeting holds the write-up ask here too (2026-10-12): never on
801
+ // a `meet` result, nor while the meeting runs in this chat.
802
+ const held = name === "meet" || meetingHold(this.counterpart.store, session, this.nowFn()) === "running";
797
803
  let ask = false;
798
804
  try {
799
805
  const touched = touchDesktopSession(this.registryDir, session, {
800
806
  now: this.nowFn(),
801
807
  wroteUp: writing && result.isError !== true,
802
- mayAsk: !writing,
808
+ mayAsk: !writing && !held,
803
809
  // Only a call that NAMED its session moves that session's record or
804
810
  // carries its ask (review of #294, finding 1): a fallback-bound call
805
811
  // may be another chat's.
@@ -1350,9 +1356,21 @@ export class McpServer {
1350
1356
  return this.refuse("meet", "night-run", { detail: "This is the nightly run: there is nobody here to meet." });
1351
1357
  }
1352
1358
  const store = this.counterpart.store;
1353
- const session = this.session ?? this.hostSession() ?? UNBOUND_SESSION;
1359
+ // The session the meeting holds (2026-10-12): the one it names when the
1360
+ // hooks' registry knows it, else this server's own, else the host's.
1361
+ const named = typeof args["session"] === "string" ? args["session"].trim() : "";
1362
+ const session = (named.length > 0 && this.corroborate(named) ? named : null) ?? this.session ?? this.hostSession() ?? UNBOUND_SESSION;
1354
1363
  const on = this.today();
1355
1364
  const step = args["step"];
1365
+ // EVERY CALL IS THE MEETING STILL GOING (2026-10-12, onboarding round 1, A):
1366
+ // while it is, this session's write-up ask and the day's dream wait.
1367
+ if (!this.observer && session !== UNBOUND_SESSION) {
1368
+ try {
1369
+ noteActive(store, session, this.nowFn());
1370
+ } catch {
1371
+ /* a lost mark costs the hold, never the meeting */
1372
+ }
1373
+ }
1356
1374
  if (step === undefined) {
1357
1375
  let state = meetState(store);
1358
1376
  if (!this.observer) {
@@ -1369,7 +1387,7 @@ export class McpServer {
1369
1387
  home: memoryHomeWords(this.counterpart.store.dir, this.lifecycleOpts.configPath),
1370
1388
  dreaming: this.counterpart.dreams.setting(),
1371
1389
  folders: this.meetAsksWhere(),
1372
- hostName: this.desktop ? "Claude" : "Claude Code",
1390
+ plugin: this.install === "plugin" && !this.desktop,
1373
1391
  state,
1374
1392
  });
1375
1393
  this.emit("mcp.meet.read", undefined, { state });
@@ -1380,7 +1398,9 @@ export class McpServer {
1380
1398
  return this.refuse("meet", "step-unknown", { detail: `step is one of ${MEET_STEPS.join(", ")} — or omit it for the script.` });
1381
1399
  }
1382
1400
  // A step taken is an offer made: the mod and the wake stop offering.
1383
- if (meetState(store) === "not_started") noteOffered(store, { on, session, state: true });
1401
+ // An answer after a "later" is the meeting resumed: offered again, so it holds.
1402
+ const before = meetState(store);
1403
+ if (before === "not_started" || (before === "later" && step !== "later" && step !== "skipped" && step !== "done")) noteOffered(store, { on, session, state: true });
1384
1404
  const answer = typeof args["answer"] === "string" ? args["answer"].trim() : "";
1385
1405
  const done = (extra: Record<string, unknown>): ToolResult => {
1386
1406
  this.emit("mcp.meet.step", undefined, { step, stored: typeof extra["stored"] === "number" ? extra["stored"] : null });
@@ -1389,9 +1409,25 @@ export class McpServer {
1389
1409
  switch (step as MeetStep) {
1390
1410
  case "later":
1391
1411
  case "skipped":
1392
- case "done":
1393
- recordState(store, step as "later" | "skipped" | "done", { on, session });
1412
+ recordState(store, step as "later" | "skipped", { on, session });
1394
1413
  return done({});
1414
+ case "done": {
1415
+ // THE FINISH STEP HANDS OVER THE WRITE-UP (2026-10-12, A): done here,
1416
+ // in the session, in place of the end-of-turn ask the meeting held —
1417
+ // so the next Stop paces that ask and does not say it (`meetingHold`).
1418
+ const writeUp = session !== UNBOUND_SESSION;
1419
+ recordState(store, "done", { on, session, writeUp });
1420
+ this.emit("mcp.meet.step", undefined, { step, stored: null });
1421
+ const view = { recorded: step, ...onboardingView(store) };
1422
+ // Unbound, the close still comes; the write-up names the id to pass.
1423
+ const next = finishText({
1424
+ name: this.counterpart.ownerDisplayName(),
1425
+ dreaming: this.counterpart.dreams.setting(),
1426
+ plugin: this.install === "plugin" && !this.desktop,
1427
+ session: writeUp ? session : "<your session id, as the wake names it>",
1428
+ });
1429
+ return { content: [{ type: "text", text: next }], structuredContent: { ...view, next } };
1430
+ }
1395
1431
  case "where":
1396
1432
  return this.meetWhere(answer, done);
1397
1433
  case "style": {
@@ -1399,14 +1435,14 @@ export class McpServer {
1399
1435
  if (choice === null) return this.refuse("meet", "style-unknown", { detail: `answer is one of ${STYLE_CHOICES.join(", ")}.` });
1400
1436
  const traits = Array.isArray(args["traits"]) ? args["traits"].filter((t): t is string => typeof t === "string") : [];
1401
1437
  const like = typeof args["like"] === "string" ? args["like"] : "";
1402
- const bundle = styleMemories(choice, { traits, like });
1438
+ const bundle = styleMemories(choice, { traits, like, name: this.counterpart.ownerDisplayName() });
1403
1439
  if (!bundle.ok) return this.refuse("meet", "style-incomplete", { detail: bundle.detail });
1404
1440
  const ids = await this.meetWrite(bundle.texts);
1405
1441
  recordStyle(store, choice);
1406
1442
  return done({ option: bundle.option, stored: ids.length, ids });
1407
1443
  }
1408
1444
  case "address": {
1409
- const made = addressMemory(answer);
1445
+ const made = addressMemory(answer, this.counterpart.ownerDisplayName());
1410
1446
  if (!made.ok) return this.refuse("meet", "answer-required", { detail: made.detail });
1411
1447
  const ids = await this.meetWrite([made.text]);
1412
1448
  return done({ stored: ids.length, ids });
@@ -1416,7 +1452,7 @@ export class McpServer {
1416
1452
  if (answer.length === 0) {
1417
1453
  return this.refuse("meet", "answer-required", { detail: "Send the answer, in your words. A skipped question is never sent: nothing is stored for it." });
1418
1454
  }
1419
- const text = step === "name" ? `The owner likes to be called ${answer}.` : answer;
1455
+ const text = step === "name" ? `They like to be called ${answer}.` : answer;
1420
1456
  const ids = await this.meetWrite([answerText(text)]);
1421
1457
  if (ids[0] !== undefined) recordAnswer(store, step as AnswerStep, ids[0]);
1422
1458
  return done({ stored: ids.length, ...(ids[0] === undefined ? {} : { id: ids[0] }) });
@@ -1411,7 +1411,7 @@ const DREAM: ToolSpec = {
1411
1411
  privileges: [
1412
1412
  {
1413
1413
  claim:
1414
- "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.",
1414
+ "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 undoing it (the `undo` phase, on the owner's word) reverses the whole batch.",
1415
1415
  mechanizedBy: "src/adapters/mcp/server.ts#requireBoundSession + src/core/dream/index.ts#Dreams.undo",
1416
1416
  },
1417
1417
  {
@@ -1460,8 +1460,8 @@ const DREAM: ToolSpec = {
1460
1460
  properties: {
1461
1461
  phase: {
1462
1462
  type: "string",
1463
- enum: ["launch", "begin", "part", "propose", "journal", "writer", "decline", "setting"],
1464
- description: "Which step: launch, begin, part (the rest of a bundle that came in parts), propose, journal, writer, decline, or setting.",
1463
+ enum: ["launch", "begin", "part", "propose", "journal", "writer", "decline", "setting", "undo"],
1464
+ description: "Which step: launch, begin, part (the rest of a bundle that came in parts), propose, journal, writer, decline, setting, or undo (only when the owner asks to undo a dream; pass `dream`).",
1465
1465
  },
1466
1466
  session: {
1467
1467
  type: "string",
@@ -1713,6 +1713,7 @@ const MEET: ToolSpec = {
1713
1713
  type: "object",
1714
1714
  properties: {
1715
1715
  step: { type: "string", enum: [...MEET_STEPS] },
1716
+ session: { type: "string", description: "Your session id, as the wake names it." },
1716
1717
  answer: { type: "string", description: "Their answer in your words; for where/style, the option." },
1717
1718
  like: { type: "string", description: "Style character: who." },
1718
1719
  traits: { type: "array", items: { type: "string" }, description: "Style character: the traits you said back; other: their words." },
@@ -51,7 +51,7 @@ import { tmpdir } from "node:os";
51
51
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
52
52
  import { fileURLToPath } from "node:url";
53
53
 
54
- import { NEW_INSTALL_DREAMING_LINE } from "../core/onboarding.js";
54
+ import { NEW_INSTALL_DREAMING_LINE_PLUGIN } from "../core/onboarding.js";
55
55
  import { implicitConfigRefusal } from "./config-path.js";
56
56
  import type { ConfigChoice } from "./config-path.js";
57
57
  import { pluginInstall } from "./host-wiring.js";
@@ -379,20 +379,56 @@ export function takeFirstRunNotice(noticePath: string): boolean {
379
379
  }
380
380
  }
381
381
 
382
- /** The line a new install is announced with, for the configuration at `configPath`. */
382
+ /**
383
+ * "INSTALLED TWICE" IS SAID ONCE (2026-10-13, Mike's first session with the
384
+ * plugin beside his npm install: the stand-down line at every session start
385
+ * read as an error). The stand-down itself is unchanged and needs nothing
386
+ * done; doctor's Claude Code row keeps saying it (`doctor-host.ts`). The mark
387
+ * lives in the plugin's own data directory, which outlasts a reboot and goes
388
+ * with the plugin at uninstall (so a reinstall says it once more); without
389
+ * one, the system temp directory, beside the first-run notice and for its
390
+ * reasons. Keyed by the configuration path, like the notice. The line for a
391
+ * dead npm entry is not this: it asks for something, and says so every time.
392
+ */
393
+ export function twiceNoticePath(configPath: string, env: Record<string, string | undefined>, tmp: string = tmpdir()): string {
394
+ const data = (env[PLUGIN_DATA_ENV] ?? "").trim();
395
+ return join(data.length > 0 ? data : tmp, `counterparts-installed-twice-${firstRunKey(configPath)}.said`);
396
+ }
397
+
398
+ /**
399
+ * Mark it said: true for the first caller only (`wx` either makes the file or
400
+ * finds one there). A mark that cannot be written for any other reason is
401
+ * true, so the line is said, as it was before there was a mark.
402
+ */
403
+ export function markTwiceSaid(markPath: string): boolean {
404
+ try {
405
+ mkdirSync(dirname(markPath), { recursive: true });
406
+ writeFileSync(markPath, `${new Date().toISOString()}\n`, { encoding: "utf8", mode: 0o600, flag: "wx" });
407
+ return true;
408
+ } catch (err) {
409
+ return (err as { code?: string }).code !== "EEXIST";
410
+ }
411
+ }
412
+
413
+ /**
414
+ * The line a new install is announced with, for the configuration at
415
+ * `configPath`. ONE LINE (2026-10-12, Mike's fresh-user trial: the three-line
416
+ * notice read as machinery): that it is set up, that it stays on this
417
+ * computer and where, and how to turn dreaming off. A memory parked beside it
418
+ * is the one case that adds a sentence.
419
+ */
383
420
  export function firstRunLine(configPath: string, home: string): string {
384
421
  const base = dirname(configPath);
385
422
  const parked = parkedBeside(base);
386
423
  return (
387
- `Counterparts: first run — a new memory was set up at ${tildeOf(base, home)}. ` +
388
- "It stays on this computer." +
424
+ `Counterparts is set up: a memory that stays on this computer, in ${tildeOf(base, home)}. ` +
425
+ // A NEW MEMORY DREAMS BY DEFAULT (2026-10-11): said once, here, with the
426
+ // way to turn it off, by saying so (`core/onboarding.ts#NEW_INSTALL_DREAMING_LINE_PLUGIN`).
427
+ NEW_INSTALL_DREAMING_LINE_PLUGIN +
389
428
  (parked.length === 0
390
429
  ? ""
391
430
  : ` A memory set aside earlier is still at ${parked.map((p) => tildeOf(p, home)).join(", ")}, untouched; ` +
392
- "the new one does not include it.") +
393
- // A NEW MEMORY DREAMS BY DEFAULT (2026-10-11): said once, here, with the
394
- // way to turn it off (`core/onboarding.ts#NEW_INSTALL_DREAMING_LINE`).
395
- ` ${NEW_INSTALL_DREAMING_LINE}`
431
+ "the new one does not include it.")
396
432
  );
397
433
  }
398
434
 
@@ -1677,8 +1677,11 @@ function registryFacts(dir: string, session: string): HostSessionEvidence {
1677
1677
  * deleted" and "what the next session is asked to write" are read off one set
1678
1678
  * of facts (B3's rule, kept by construction).
1679
1679
  */
1680
- export function writeUpSources(store: Store): RetentionSources {
1681
- return retentionSources(store, { host: hostSessionEvidence(store) });
1680
+ export function writeUpSources(store: Store, clocks: { retentionMs?: number; maxMs?: number } = {}): RetentionSources {
1681
+ // The clocks change only WHEN text goes, never what is owed — so the
1682
+ // write-up's readers may leave them at the defaults, and the retention pass
1683
+ // hands over the configuration's (`config.ts#retentionClocks`).
1684
+ return retentionSources(store, { host: hostSessionEvidence(store), ...clocks });
1682
1685
  }
1683
1686
 
1684
1687
  /** Every session the store holds text for, judged by `remember/owes.ts`. Read-only. */