counterparts 0.3.12 → 0.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/docs/module-map.md +1 -1
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/CONTRACT.md +36 -10
  5. package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
  6. package/src/adapters/claude-code/NOTES.md +131 -0
  7. package/src/adapters/claude-code/bin/hook.ts +35 -2
  8. package/src/adapters/claude-code/doctor.ts +155 -21
  9. package/src/adapters/claude-code/hooks.ts +49 -7
  10. package/src/adapters/claude-code/index.ts +11 -0
  11. package/src/adapters/claude-code/night-run.ts +133 -12
  12. package/src/adapters/claude-code/transcript.ts +268 -1
  13. package/src/adapters/cli/CONTRACT.md +5 -0
  14. package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
  15. package/src/adapters/cli/NOTES.md +111 -0
  16. package/src/adapters/cli/commands.ts +65 -14
  17. package/src/adapters/cli/dream-core.ts +57 -42
  18. package/src/adapters/cli/export.ts +320 -21
  19. package/src/adapters/cli/index.ts +1 -0
  20. package/src/adapters/cli/install.ts +39 -7
  21. package/src/adapters/cli/mechanisms.ts +7 -1
  22. package/src/adapters/cli/uninstall.ts +13 -5
  23. package/src/adapters/cli/wire.ts +189 -63
  24. package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
  25. package/src/adapters/dashboard/NOTES.md +79 -0
  26. package/src/adapters/dashboard/registries.ts +10 -2
  27. package/src/adapters/dashboard/web/README.md +19 -14
  28. package/src/adapters/dashboard/web/actions.ts +23 -1
  29. package/src/adapters/dashboard/web/flow.ts +4 -1
  30. package/src/adapters/dashboard/web/lanes.ts +3 -0
  31. package/src/adapters/dashboard/web/narrate.ts +30 -2
  32. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
  33. package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
  34. package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
  35. package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
  36. package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
  37. package/src/adapters/dashboard/web/server.ts +0 -5
  38. package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
  39. package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
  40. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
  41. package/src/adapters/dashboard/web/views/health.ts +1 -1
  42. package/src/adapters/dashboard/web/views/search.ts +4 -45
  43. package/src/adapters/dashboard/web/views.ts +2 -2
  44. package/src/adapters/fired.ts +410 -25
  45. package/src/adapters/host-wiring.ts +300 -0
  46. package/src/adapters/lifecycle.ts +14 -0
  47. package/src/adapters/log/index.ts +2 -0
  48. package/src/adapters/mcp/CONTRACT.md +33 -3
  49. package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
  50. package/src/adapters/mcp/NOTES.md +136 -0
  51. package/src/adapters/mcp/bin/serve.ts +30 -0
  52. package/src/adapters/mcp/facts.ts +13 -1
  53. package/src/adapters/mcp/meaning.ts +208 -13
  54. package/src/adapters/mcp/server.ts +87 -15
  55. package/src/adapters/mcp/stdio.ts +3 -1
  56. package/src/adapters/mcp/stood-down.ts +51 -0
  57. package/src/adapters/mcp/tools.ts +27 -7
  58. package/src/adapters/plugin-run.sh +133 -0
  59. package/src/adapters/plugin.ts +329 -0
  60. package/src/core/associate/CONTRACT.md +2 -1
  61. package/src/core/associate/INTERFACE-GAPS.md +6 -1
  62. package/src/core/associate/NOTES.md +45 -0
  63. package/src/core/briefing.ts +12 -3
  64. package/src/core/contradictions.ts +184 -0
  65. package/src/core/counterpart.ts +451 -18
  66. package/src/core/dream/CONTRACT.md +5 -2
  67. package/src/core/dream/INTERFACE-GAPS.md +29 -6
  68. package/src/core/dream/NOTES.md +21 -0
  69. package/src/core/dream/index.ts +33 -1
  70. package/src/core/dream/reflect.ts +20 -5
  71. package/src/core/encode/INTERFACE-GAPS.md +3 -1
  72. package/src/core/fit/INTERFACE-GAPS.md +8 -2
  73. package/src/core/fit/NOTES.md +5 -2
  74. package/src/core/fit/index.ts +4 -1
  75. package/src/core/handoff/CONTRACT.md +37 -2
  76. package/src/core/handoff/INTERFACE-GAPS.md +10 -0
  77. package/src/core/handoff/NOTES.md +66 -0
  78. package/src/core/handoff/index.ts +214 -12
  79. package/src/core/mint.ts +8 -2
  80. package/src/core/physics/CONTRACT.md +11 -1
  81. package/src/core/physics/NOTES.md +30 -0
  82. package/src/core/physics/index.ts +26 -4
  83. package/src/core/prospective/CONTRACT.md +45 -6
  84. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  85. package/src/core/prospective/NOTES.md +138 -0
  86. package/src/core/prospective/derive.ts +33 -5
  87. package/src/core/prospective/index.ts +90 -5
  88. package/src/core/prospective/windows.ts +72 -1
  89. package/src/core/recall/CONTRACT.md +6 -2
  90. package/src/core/recall/INTERFACE-GAPS.md +28 -4
  91. package/src/core/recall/NOTES.md +57 -1
  92. package/src/core/recall/probe.ts +58 -0
  93. package/src/core/recall/session.ts +27 -3
  94. package/src/core/recall/time-ask.ts +116 -18
  95. package/src/core/remember/CONTRACT.md +4 -1
  96. package/src/core/remember/INTERFACE-GAPS.md +9 -1
  97. package/src/core/remember/proposals.ts +38 -5
  98. package/src/core/revision.ts +5 -0
  99. package/src/core/schemas/CONTRACT.md +13 -1
  100. package/src/core/schemas/INTERFACE-GAPS.md +20 -2
  101. package/src/core/schemas/NOTES.md +127 -0
  102. package/src/core/schemas/types.ts +2 -0
  103. package/src/core/self/CONTRACT.md +15 -4
  104. package/src/core/self/INTERFACE-GAPS.md +7 -2
  105. package/src/core/self/NOTES.md +49 -0
  106. package/src/core/self/briefing.ts +12 -2
  107. package/src/core/self/index.ts +82 -8
  108. package/src/core/self/page.ts +88 -0
  109. package/src/core/sleep/INTERFACE-GAPS.md +22 -3
  110. package/src/core/sleep/NOTES.md +11 -0
  111. package/src/core/sleep/prune.ts +6 -2
  112. package/src/core/store/NOTES.md +14 -0
  113. package/src/core/store/index.ts +107 -0
  114. package/src/core/time.ts +152 -0
  115. package/tools/install-loop/run.sh +48 -12
  116. package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
@@ -82,6 +82,8 @@ import { sessionsHere } from "../../core/coverage/index.js";
82
82
  import { chaptersOf } from "../../core/handoff/last-here.js";
83
83
 
84
84
  import {
85
+ OPEN_END,
86
+ OPEN_START,
85
87
  informativeness,
86
88
  localKey,
87
89
  readTimeAsk,
@@ -1031,7 +1033,17 @@ function renderAt(r: FactsResult, today: string, excerpt: number): string {
1031
1033
  lines.push(head.join(" · "));
1032
1034
  if (r.time !== null) {
1033
1035
  const t = r.time;
1034
- const span = (w: DayWindow | null): string => (w === null ? "" : w.from === w.to ? shortDate(w.from, today) : `${shortDate(w.from, today)}..${shortDate(w.to, today)}`);
1036
+ // An open end ("before 7/22", "after 7/22") reads as a cutoff, not as year 1 or 9999.
1037
+ const span = (w: DayWindow | null): string =>
1038
+ w === null
1039
+ ? ""
1040
+ : w.from === OPEN_START
1041
+ ? `through ${shortDate(w.to, today)}`
1042
+ : w.to === OPEN_END
1043
+ ? `${shortDate(w.from, today)} onward`
1044
+ : w.from === w.to
1045
+ ? shortDate(w.from, today)
1046
+ : `${shortDate(w.from, today)}..${shortDate(w.to, today)}`;
1035
1047
  const out = t.outside > 0 ? ` · ${String(t.outside)} more match outside it` : "";
1036
1048
  if (t.anchor !== undefined && t.anchor.date === null) {
1037
1049
  lines.push(
@@ -33,7 +33,11 @@
33
33
  *
34
34
  * **The subject.** The question's names, read through the alias index
35
35
  * (`Schemas#subjectsIn`), reach their cards' memories (`memory_subjects`,
36
- * v12); the card holding the most is the arc, the rest are one-liners. "us"
36
+ * v12); the card the question is ABOUT is the arc — read off its grammar and
37
+ * the order of its names, counts only breaking a tie (`subjectOf`, since
38
+ * 2026-10-09; it was the card holding the most) — and the rest are
39
+ * one-liners. The owner's "I" asked about ("what have you been like", in the
40
+ * counterpart's voice) is his own card. "us"
37
41
  * is the memories marked `about: us`. A question about feeling
38
42
  * (`recall/feeling-ask.ts#readFeelingAsk`, ranked) with no card is answered
39
43
  * by the stamps that match it — word, core, whose — and, when it names a
@@ -65,11 +69,11 @@ import { softenedFeeling, strength } from "../../core/physics/index.js";
65
69
  import type { MemoryPhysics } from "../../core/physics/index.js";
66
70
  import { askedNames, feelingTokens, isFeelingFrameWord, readFeelingAsk, semanticTuning, stampCores } from "../../core/recall/index.js";
67
71
  import type { FeelingWhose, SemanticSource } from "../../core/recall/index.js";
68
- import { chapterAddress, chapterAt, chapterTimesOf, identityCoreName } from "../../core/self/index.js";
72
+ import { chapterAddress, chapterAt, chapterTimesOf, findIdentityCore, identityCoreName } from "../../core/self/index.js";
69
73
  import type { ChapterTimes } from "../../core/self/index.js";
70
- import { feelingValence, tokenize } from "../../core/store/index.js";
74
+ import { RECURRING_META, feelingValence, tokenize } from "../../core/store/index.js";
71
75
  import type { FeelingRow, MemoryRow } from "../../core/store/index.js";
72
- import { calendarOverlaps, daysBetween, localDate } from "../../core/time.js";
76
+ import { calendarOverlaps, daysBetween, isDay, isRecurrence, localDate, occurrenceOnOrAfter, readableRecurrence } from "../../core/time.js";
73
77
  import { RECALL_RESULT_CHARS, hasFaded } from "./deliberate.js";
74
78
 
75
79
  // ── the numbers (working defaults, 2026-10-03; tune at the revisit) ──────────
@@ -198,6 +202,9 @@ export interface MeaningOpen {
198
202
  /** `open` — an unresolved thread; `dated` — a reminder on or after today. */
199
203
  readonly why: "open" | "dated";
200
204
  readonly date: string | null;
205
+ /** A repeating reminder (2026-10-09): how often, in words — `date` is then
206
+ * its next occurrence. Absent on a date that happens once. */
207
+ readonly every?: string;
201
208
  }
202
209
 
203
210
  export interface MeaningPattern {
@@ -279,6 +286,39 @@ const FEELING_FRAME_MORE = new Set([
279
286
  /** Words that make "us" the subject: the two of them together. Not "we" or "our", which a question uses for joint work. */
280
287
  const US_WORDS = new Set(["us", "ourselves", "together"]);
281
288
 
289
+ /**
290
+ * Just before a name, words that make it what the question is ABOUT: "what has
291
+ * X been", "how has X changed", "who was X", "how did X take it", "tell me
292
+ * about X", "my arc with X", "between X and Y" (and "between you and X").
293
+ */
294
+ const ABOUT_BEFORE: readonly RegExp[] = [
295
+ /\b(?:what|who|how)\s+(?:has|have|had|is|are|was|were)\s+$/i,
296
+ /\bhow\s+did\s+$/i,
297
+ /\babout\s+$/i,
298
+ /\b(?:my|our|your)\s+(?:arc|history|story|relationship|time|work|things)\s+with\s+$/i,
299
+ /\bbetween\s+$/i,
300
+ /\bbetween\s+(?:you|me|him|her|them)\s+and\s+$/i,
301
+ ];
302
+ /**
303
+ * Just before a name, words that make it an ASIDE: who the subject matters to
304
+ * ("been to Y", "meant for Y"), or when ("since Y arrived", "after Y left").
305
+ * Not a bare "to": "what happened to X" asks about X.
306
+ */
307
+ const ASIDE_BEFORE = /\b(?:(?:be|been|is|was|are|were|mean|means|meant|matter|matters|mattered)\s+(?:to|for)|since|after|before|until|than)\s+$/i;
308
+ /** What lies between two names asked about alike: "X and Y", "X, Y", "X or Y". */
309
+ const JOINED = /^(?:\s*,\s*(?:(?:and|or)\s+)?|\s+(?:and|or|&)\s+)$/i;
310
+ /** The owner's "I" when the asker is the counterpart (`asker: "self"`): "you". Not "your", which owns a topic ("your garden plan"). */
311
+ const OWNER_AS_YOU = /\b(?:you|yourself)\b(?!['’])/gi;
312
+ /** The owner's "I" when the asker is the owner. Not "my", for the same reason. */
313
+ const OWNER_AS_I = /\b(?:i|me|myself)\b(?!['’])/gi;
314
+
315
+ /** A card the question names, and its memories the asker may see. */
316
+ interface NamedCard {
317
+ readonly id: string;
318
+ readonly name: string;
319
+ readonly ids: readonly string[];
320
+ }
321
+
282
322
  interface Held {
283
323
  readonly row: MemoryRow;
284
324
  /** How strongly this memory holds the subject (1 for a card's; a stamp's value; a word/meaning score). */
@@ -384,13 +424,14 @@ export function meaningRecall(ctx: MeaningContext, question: string, opts: { pag
384
424
  });
385
425
  }
386
426
 
427
+ const cardOf = (id: string): NamedCard | null => {
428
+ const name = safe(() => c.schemas.entity(id)?.name ?? null, null);
429
+ if (name === null) return null;
430
+ return { id, name, ids: safe(() => store.memoriesNaming(id), [] as string[]).filter((m) => usable(m) !== null) };
431
+ };
387
432
  const cards = safe(() => c.schemas.subjectsIn(question), [] as string[])
388
- .map((id) => {
389
- const name = safe(() => c.schemas.entity(id)?.name ?? null, null);
390
- const ids = safe(() => store.memoriesNaming(id), [] as string[]).filter((m) => usable(m) !== null);
391
- return { id, name, ids };
392
- })
393
- .filter((x): x is { id: string; name: string; ids: string[] } => x.name !== null)
433
+ .map(cardOf)
434
+ .filter((x): x is NamedCard => x !== null)
394
435
  .sort((a, b) => b.ids.length - a.ids.length || a.name.localeCompare(b.name));
395
436
  const usAsked = tokenize(question).some((w) => US_WORDS.has(w)) || /\bbetween\s+(you\s+and\s+me|me\s+and\s+you)\b/i.test(question);
396
437
  const usIds = usAsked
@@ -414,7 +455,23 @@ export function meaningRecall(ctx: MeaningContext, question: string, opts: { pag
414
455
  let lineMatch: readonly RegExp[] = [];
415
456
  const others: { name: string; memories: number }[] = [];
416
457
  const notes: string[] = [];
417
- const bestCard = cards.find((x) => x.ids.length > 0) ?? null;
458
+ // THE SUBJECT IS THE CARD THE QUESTION IS ABOUT (2026-10-09), read off its
459
+ // grammar and the order of its names; memory counts only break a tie. The
460
+ // owner's "I" — "you" in my voice — asked about is his own card
461
+ // (`subjectOf`). It was the card with the most memories, which on a real
462
+ // store is usually the owner's: "what has Ilya been to Mike" answered
463
+ // about Mike.
464
+ const ownerCard = safe(() => findIdentityCore(store), null);
465
+ const subject = subjectOf(question, cards, {
466
+ terms: (id) => cardTerms(c, id),
467
+ ownerCard,
468
+ ownerPronoun: feelingAsked || usAsked ? null : asker === "self" ? OWNER_AS_YOU : OWNER_AS_I,
469
+ ownerCardOf: () => (ownerCard === null ? null : cardOf(ownerCard)),
470
+ });
471
+ const bestCard = subject.card;
472
+ if (bestCard !== null && subject.alike.length > 0) {
473
+ notes.push(`it asks about ${andList([bestCard.name, ...subject.alike])} alike: this follows ${bestCard.name}, named first`);
474
+ }
418
475
 
419
476
  if (bestCard !== null) {
420
477
  lens = { kind: "card", id: bestCard.id, name: bestCard.name };
@@ -430,7 +487,7 @@ export function meaningRecall(ctx: MeaningContext, question: string, opts: { pag
430
487
  return Math.min(n, 4) * 0.5;
431
488
  };
432
489
  }
433
- for (const x of cards) if (x !== bestCard) others.push({ name: x.name, memories: x.ids.length });
490
+ for (const x of cards) if (x.id !== bestCard.id) others.push({ name: x.name, memories: x.ids.length });
434
491
  if (usIds.length > 0) others.push({ name: usName, memories: usIds.length });
435
492
  } else if (usIds.length > 0) {
436
493
  lens = { kind: "us", name: usName };
@@ -943,6 +1000,17 @@ function openFor(
943
1000
  const r = usable(id);
944
1001
  if (r === null) continue;
945
1002
  const title = clip(oneLine(r.title ?? firstLine(r.body)), TITLE_CHARS);
1003
+ // A REPEATING reminder (2026-10-09) is dated by its next occurrence — a
1004
+ // birthday stated in 1990 is still coming — and says how often.
1005
+ const meta = r.event_date !== null && isDay(r.event_date) ? parseMeta(r.meta) : null;
1006
+ const rule = meta === null ? null : meta[RECURRING_META];
1007
+ if (r.event_date !== null && isRecurrence(rule)) {
1008
+ const next = occurrenceOnOrAfter(r.event_date, rule, today);
1009
+ if (next !== null) {
1010
+ dated.push({ id, title, why: "dated", date: next.date, every: readableRecurrence(r.event_date, rule), sort: next.date });
1011
+ continue;
1012
+ }
1013
+ }
946
1014
  if (r.event_date !== null && calendarOverlaps(r.event_date, today, "9999-12-31")) {
947
1015
  dated.push({ id, title, why: "dated", date: r.event_date, sort: r.event_date });
948
1016
  continue;
@@ -1165,7 +1233,7 @@ export function renderMeaning(r: MeaningResult): string {
1165
1233
  if (r.open.length > 0) {
1166
1234
  out.push("");
1167
1235
  out.push(`STILL OPEN (${String(r.counts.open)})`);
1168
- for (const o of r.open) out.push(` ${o.id} ${o.title} · ${o.why === "dated" ? `dated ${o.date ?? "?"}` : `open since ${o.date === null ? "?" : short(o.date)}`}`);
1236
+ for (const o of r.open) out.push(` ${o.id} ${o.title} · ${o.why === "dated" ? `dated ${o.date ?? "?"}${o.every === undefined ? "" : `, ${o.every}`}` : `open since ${o.date === null ? "?" : short(o.date)}`}`);
1169
1237
  }
1170
1238
  if (r.patterns.subjects.length > 0 || r.patterns.feelings.length > 0) {
1171
1239
  out.push("");
@@ -1221,6 +1289,133 @@ function cardTerms(c: Counterpart, id: string): string[] {
1221
1289
  }
1222
1290
  }
1223
1291
 
1292
+ /** Where a name sits in the question: what it is about, a plain mention, or an aside. */
1293
+ type Slot = "about" | "plain" | "aside";
1294
+ const SLOT_RANK: Readonly<Record<Slot, number>> = { about: 2, plain: 1, aside: 0 };
1295
+
1296
+ /**
1297
+ * How strongly one mention says the question is about its card (review of
1298
+ * #334). A name: twice its place's rank, plus one when it is typed as its card
1299
+ * writes it — so "will" for a card named Will, or "hope" for Hope, sits a step
1300
+ * under a name in the same place typed with its capital ("how will Driftwood
1301
+ * go" is Driftwood's, not Will's); in a question typed all in lower case every
1302
+ * name loses the same step and the grammar still decides. The owner's
1303
+ * pronoun asked about: under every name in a plain or about place (2 and up),
1304
+ * over every aside (1 at most) — "what have I done on Driftwood" is
1305
+ * Driftwood's, "how have I been since Driftwood" is his.
1306
+ */
1307
+ function mentionRank(m: { readonly slot: Slot; readonly pronoun: boolean; readonly lowered: boolean }): number {
1308
+ if (m.pronoun) return 1.5;
1309
+ return SLOT_RANK[m.slot] * 2 + (m.lowered ? 0 : 1);
1310
+ }
1311
+
1312
+ /**
1313
+ * WHICH CARD THE QUESTION IS ABOUT (2026-10-09). Deterministic; no model.
1314
+ *
1315
+ * 1. Each name the question gives a card is read in place: ABOUT when the
1316
+ * words just before it ask about it ("what has X been", "how has X
1317
+ * changed", "about X", `ABOUT_BEFORE`), an ASIDE when they say who it
1318
+ * matters to or since when ("been to Y", "since Y arrived"), plain
1319
+ * otherwise. A name joined to the one before it ("X and Y", "X, Y")
1320
+ * takes that one's place. A name typed in lower case where its card
1321
+ * writes a capital ("will" for Will) is a step under the same place
1322
+ * (`mentionRank`). A card's place is its best mention's.
1323
+ * 2. Of the cards with memories, those in the best place are the field. The
1324
+ * owner's own card leaves a field it shares — every memory here is his,
1325
+ * so the other one says more ("Rosalind's arc with Ilya").
1326
+ * 3. The first named wins the field; a longer name at the same spot, then
1327
+ * more memories, then the name, break a tie. More than one left in the
1328
+ * field is asked about alike, and `alike` names the rest so the answer
1329
+ * can say so.
1330
+ *
1331
+ * The owner's "I" — "you" in the counterpart's voice, as `feeling-ask.ts`
1332
+ * reads whose — names his card (by its id, not his name) where it sits in an
1333
+ * about place: "what have you been like", "how have I changed", "how have you
1334
+ * and Ilya been". It ranks under any card named in a plain or about place and
1335
+ * over an aside, so "what have I done on Driftwood" is still Driftwood's (as
1336
+ * it was before the pronoun counted) and "how have I been since Driftwood" is
1337
+ * his. Anywhere else a pronoun names nothing, so "do you remember
1338
+ * the budget" is still read by its words. Off (`ownerPronoun` null) for a
1339
+ * question about feeling, where the pronoun says whose feeling, and for "us".
1340
+ */
1341
+ function subjectOf(
1342
+ question: string,
1343
+ cards: readonly NamedCard[],
1344
+ o: {
1345
+ readonly terms: (id: string) => readonly string[];
1346
+ readonly ownerCard: string | null;
1347
+ readonly ownerPronoun: RegExp | null;
1348
+ readonly ownerCardOf: () => NamedCard | null;
1349
+ },
1350
+ ): { card: NamedCard | null; alike: readonly string[] } {
1351
+ const live = cards.filter((x) => x.ids.length > 0);
1352
+ // Every mention of every card, in the order they are named.
1353
+ const mentions: { card: NamedCard; at: number; end: number; slot: Slot; pronoun: boolean; lowered: boolean }[] = [];
1354
+ for (const card of live) {
1355
+ for (const term of o.terms(card.id)) {
1356
+ // Typed in lower case where the card writes a capital: "will" for Will.
1357
+ const capital = term !== term.toLowerCase();
1358
+ for (const m of question.matchAll(nameRegex(term, "giu"))) {
1359
+ const lowered = capital && m[0] === m[0].toLowerCase();
1360
+ mentions.push({ card, at: m.index, end: m.index + m[0].length, slot: slotAt(question, m.index), pronoun: false, lowered });
1361
+ }
1362
+ }
1363
+ }
1364
+ if (o.ownerCard !== null && o.ownerPronoun !== null) {
1365
+ const asked = [...question.matchAll(o.ownerPronoun)].filter((m) => slotAt(question, m.index) === "about");
1366
+ const own = asked.length === 0 ? null : (live.find((x) => x.id === o.ownerCard) ?? o.ownerCardOf());
1367
+ if (own !== null && own.ids.length > 0) {
1368
+ if (!live.includes(own)) live.push(own);
1369
+ for (const m of asked) {
1370
+ mentions.push({ card: own, at: m.index, end: m.index + m[0].length, slot: "about", pronoun: true, lowered: false });
1371
+ }
1372
+ }
1373
+ }
1374
+ if (live.length === 0) return { card: null, alike: [] };
1375
+ mentions.sort((a, b) => a.at - b.at || b.end - a.end);
1376
+ const kept: typeof mentions = [];
1377
+ for (const m of mentions) {
1378
+ const prev = kept[kept.length - 1];
1379
+ // A name inside a longer one ("Han" in "Han Seo") is not a mention of its own.
1380
+ if (prev !== undefined && m.at < prev.end) continue;
1381
+ // Joined to the owner's pronoun ("how have you and Ilya been"), a name
1382
+ // takes the place the grammar gives, not the pronoun's lower rank.
1383
+ if (prev !== undefined && JOINED.test(question.slice(prev.end, m.at))) m.slot = prev.slot;
1384
+ kept.push(m);
1385
+ }
1386
+ const place = new Map<string, { rank: number; at: number; length: number }>();
1387
+ for (const m of kept) {
1388
+ const had = place.get(m.card.id);
1389
+ const rank = mentionRank(m);
1390
+ if (had === undefined || rank > had.rank) place.set(m.card.id, { rank, at: m.at, length: m.end - m.at });
1391
+ }
1392
+ // A card named only inside another's longer name: the least of them.
1393
+ const placeOf = (x: NamedCard) => place.get(x.id) ?? { rank: -1, at: Number.POSITIVE_INFINITY, length: 0 };
1394
+ const best = Math.max(...live.map((x) => placeOf(x).rank));
1395
+ let field = live.filter((x) => placeOf(x).rank === best);
1396
+ if (field.length > 1 && o.ownerCard !== null) field = field.filter((x) => x.id !== o.ownerCard);
1397
+ field.sort((a, b) => {
1398
+ const pa = placeOf(a);
1399
+ const pb = placeOf(b);
1400
+ return pa.at - pb.at || pb.length - pa.length || b.ids.length - a.ids.length || a.name.localeCompare(b.name);
1401
+ });
1402
+ const [card, ...rest] = field;
1403
+ return { card: card ?? null, alike: rest.map((x) => x.name) };
1404
+ }
1405
+
1406
+ /** The place a name at `index` sits in: about, aside, or plain. */
1407
+ function slotAt(question: string, index: number): Slot {
1408
+ const before = question.slice(0, index);
1409
+ if (ABOUT_BEFORE.some((re) => re.test(before))) return "about";
1410
+ return ASIDE_BEFORE.test(before) ? "aside" : "plain";
1411
+ }
1412
+
1413
+ /** "A", "A and B", "A, B and C". */
1414
+ function andList(names: readonly string[]): string {
1415
+ if (names.length <= 1) return names.join("");
1416
+ return `${names.slice(0, -1).join(", ")} and ${names[names.length - 1] as string}`;
1417
+ }
1418
+
1224
1419
  /**
1225
1420
  * The question's words a topic is read by. `words` are lower-case tokens;
1226
1421
  * `names` maps the ones the asker CAPITALISED mid-sentence (a name or a
@@ -56,9 +56,10 @@
56
56
  */
57
57
  import { CLAIM_NOTHING_NEW, claimUnwritten } from "../../core/coverage/index.js";
58
58
  import { MCP_OVERSIZE_EVENT, MCP_PART_EVENT, MCP_RECALL_EVENT } from "../../core/counterpart.js";
59
- import { CONTRADICTION_TUNABLES, NEIGHBOURS_HINT } from "../../core/contradictions.js";
59
+ import { CONTRADICTION_TUNABLES, HELD_HINT, NEIGHBOURS_HINT } from "../../core/contradictions.js";
60
60
  import type { Neighbour } from "../../core/contradictions.js";
61
- import { localDate, parseCalendarDate, todayIn } from "../../core/time.js";
61
+ import { isRecurrence, localDate, occurrenceOnOrAfter, parseCalendarDate, readableRecurrence, todayIn } from "../../core/time.js";
62
+ import type { Recurrence } from "../../core/time.js";
62
63
  import type { ChapterResult, Counterpart, DepositResult, SentFacts } from "../../core/counterpart.js";
63
64
  import { loadGateState } from "../../core/recall/index.js";
64
65
  import type { SemanticSource } from "../../core/recall/index.js";
@@ -152,7 +153,7 @@ export const SERVER_NAME = "counterparts";
152
153
  * host decides whether to trust what follows. Read from a constant rather than
153
154
  * from disk so the server opens no file to answer its first message.
154
155
  */
155
- export const SERVER_VERSION = "0.3.12";
156
+ export const SERVER_VERSION = "0.3.13";
156
157
 
157
158
  /**
158
159
  * THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
@@ -1802,6 +1803,25 @@ export class McpServer {
1802
1803
  * declared.
1803
1804
  */
1804
1805
  private settledOf(deposit: DepositResult, sentHow: boolean): Record<string, unknown> {
1806
+ // HELD (2026-10-09, the update guard): the memory named in `updates`
1807
+ // looked unrelated, so nothing was settled or linked. Its own words come
1808
+ // back with the ask the neighbours carry, and the two ids to settle with.
1809
+ const h = deposit.held;
1810
+ if (h !== undefined) {
1811
+ return {
1812
+ settled: {
1813
+ ok: false,
1814
+ held: true,
1815
+ reason: "looks-unrelated",
1816
+ how: h.how,
1817
+ holds: deposit.memoryId,
1818
+ over: h.over,
1819
+ ...(h.title === null ? {} : { title: h.title }),
1820
+ ...(h.text === null ? {} : { text: h.text }),
1821
+ detail: HELD_HINT,
1822
+ },
1823
+ };
1824
+ }
1805
1825
  const r = deposit.revision;
1806
1826
  if (r === undefined) return {};
1807
1827
  const o = r.settle;
@@ -1845,7 +1865,8 @@ export class McpServer {
1845
1865
  if (!deposit.deposited || deposit.memoryId === null || room <= 0) return [];
1846
1866
  // Not the memory it updates, and not a sibling written by the same call
1847
1867
  // (review of #284, M1): those are this writer's own words, not existing ones.
1848
- const exclude = [deposit.revision?.targetId, deposit.mint?.updates, ...siblings].filter((x): x is string => typeof x === "string");
1868
+ // A held one (2026-10-09) is already shown whole, beside its own ask.
1869
+ const exclude = [deposit.revision?.targetId, deposit.mint?.updates, deposit.held?.over, ...siblings].filter((x): x is string => typeof x === "string");
1849
1870
  return this.counterpart.writeNeighbours(deposit.memoryId, { exclude, owner: this.owner }).slice(0, room);
1850
1871
  }
1851
1872
 
@@ -4447,12 +4468,18 @@ type ReminderRead =
4447
4468
  /** `eventDate: null` is the explicit drop (a revision's cancel); `remind`
4448
4469
  * rides only when it was SENT, so a revision can tell a left-out mode
4449
4470
  * from a stated one (review N7). */
4450
- readonly fields: { eventDate?: string | null; remind?: "plain" | "quiet" };
4471
+ readonly fields: { eventDate?: string | null; remind?: "plain" | "quiet"; recurring?: Recurrence | null };
4451
4472
  /** `remind` was sent with no `eventDate`: there is nothing for it to shape
4452
4473
  * — unless the memory it revises carries a date (`DepositResult.reminder`). */
4453
4474
  readonly remindIgnored: boolean;
4475
+ /** `recurring` was sent with no `eventDate` (2026-10-09): nothing to repeat
4476
+ * — unless the memory it revises carries a date. */
4477
+ readonly recurringIgnored?: boolean;
4454
4478
  }
4455
- | { readonly refused: "event-date-unreadable" | "remind-unknown"; readonly detail: string };
4479
+ | {
4480
+ readonly refused: "event-date-unreadable" | "remind-unknown" | "recurring-unknown" | "recurring-needs-day";
4481
+ readonly detail: string;
4482
+ };
4456
4483
 
4457
4484
  const EVENT_DATE_SHAPES =
4458
4485
  '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.';
@@ -4473,15 +4500,24 @@ const DATE_PASSED_NOTE = "That date has already passed — it won't come back as
4473
4500
  function readReminder(rec: Record<string, unknown>): ReminderRead {
4474
4501
  const rawDate = rec["eventDate"];
4475
4502
  const rawRemind = rec["remind"];
4503
+ const rawRule = rec["recurring"];
4476
4504
  if (rawRemind !== undefined && rawRemind !== null && rawRemind !== "plain" && rawRemind !== "quiet") {
4477
4505
  return { refused: "remind-unknown", detail: '`remind` is "plain" or "quiet".' };
4478
4506
  }
4479
- const sent: { remind?: "plain" | "quiet" } =
4480
- rawRemind === "plain" || rawRemind === "quiet" ? { remind: rawRemind } : {};
4507
+ // HOW OFTEN (2026-10-09): one of four words, refused by name like a date.
4508
+ if (rawRule !== undefined && rawRule !== null && !isRecurrence(rawRule)) {
4509
+ return { refused: "recurring-unknown", detail: RECURRING_WORDS };
4510
+ }
4511
+ const sent: { remind?: "plain" | "quiet"; recurring?: Recurrence | null } = {
4512
+ ...(rawRemind === "plain" || rawRemind === "quiet" ? { remind: rawRemind } : {}),
4513
+ // `null` rides as sent: a revision's "it no longer repeats".
4514
+ ...(isRecurrence(rawRule) ? { recurring: rawRule } : rawRule === null ? { recurring: null } : {}),
4515
+ };
4481
4516
  if (rawDate === undefined || rawDate === null) {
4482
4517
  return {
4483
4518
  fields: { ...(rawDate === null ? { eventDate: null } : {}), ...sent },
4484
4519
  remindIgnored: sent.remind !== undefined,
4520
+ recurringIgnored: isRecurrence(sent.recurring),
4485
4521
  };
4486
4522
  }
4487
4523
  const read = typeof rawDate === "string" ? parseCalendarDate(rawDate) : null;
@@ -4491,13 +4527,33 @@ function readReminder(rec: Record<string, unknown>): ReminderRead {
4491
4527
  detail: `\`eventDate\` ${typeof rawDate === "string" ? `"${rawDate.slice(0, 64)}"` : "(not text)"} is not a date this can read. ${EVENT_DATE_SHAPES}`,
4492
4528
  };
4493
4529
  }
4530
+ if (isRecurrence(sent.recurring) && read.precision !== "day") {
4531
+ return { refused: "recurring-needs-day", detail: RECURRING_NEEDS_DAY };
4532
+ }
4494
4533
  return { fields: { eventDate: read.text, ...sent }, remindIgnored: false };
4495
4534
  }
4496
4535
 
4536
+ const RECURRING_WORDS =
4537
+ '`recurring` is "daily", "weekly", "monthly" or "yearly", anchored on eventDate. Every other week, "the first Monday" and the like are not kept: leave it out.';
4538
+
4539
+ const RECURRING_NEEDS_DAY =
4540
+ '`recurring` repeats one day, so eventDate must be a day: the first one ("1990-05-14" for a birthday, any Monday for "every Monday").';
4541
+
4542
+ const RECURRING_IGNORED_NOTE = "`recurring` repeats a date; with no `eventDate` there was nothing to repeat.";
4543
+
4544
+ const RECURRING_DROPPED_NOTE = "Not repeating any more: only a day repeats, and this date is not one, so it comes once.";
4545
+
4497
4546
  /** What to say about a recorded date: that it has already passed (its last day
4498
4547
  * is before the person's today — `time.ts#todayIn` in the store's zone), or
4499
4548
  * that a year alone never comes back. One note, the passed one first. */
4500
- function dateNote(eventDate: string, today: string): Record<string, unknown> {
4549
+ function dateNote(eventDate: string, today: string, recurring: Recurrence | null = null): Record<string, unknown> {
4550
+ // A REPEATING date never "has passed" (2026-10-09): a birthday anchored in
4551
+ // 1990 comes round every year. Said instead: how often, and when next.
4552
+ if (recurring !== null) {
4553
+ const every = readableRecurrence(eventDate, recurring);
4554
+ const next = occurrenceOnOrAfter(eventDate, recurring, today);
4555
+ return { ...(every === "" ? {} : { every }), ...(next === null ? {} : { next: next.date }) };
4556
+ }
4501
4557
  const read = parseCalendarDate(eventDate);
4502
4558
  if (read === null) return {};
4503
4559
  if (read.last < today) return { note: DATE_PASSED_NOTE };
@@ -4522,20 +4578,33 @@ function reminderEcho(deposit: DepositResult, dated: ReminderRead, today: string
4522
4578
  },
4523
4579
  };
4524
4580
  }
4581
+ // A repeat — sent or carried — that the new date cannot take (a month or a
4582
+ // range does not repeat) is SAID, never silently lost.
4583
+ const ruleDropped = carried.recurringDropped === true;
4525
4584
  return {
4526
4585
  reminder: {
4527
4586
  eventDate: carried.eventDate,
4528
4587
  remind: carried.remind ?? "quiet",
4588
+ ...(carried.recurring === null ? {} : { recurring: carried.recurring }),
4529
4589
  from: carried.from,
4530
4590
  ...(carried.inherited.length > 0 ? { carriedOver: [...carried.inherited] } : {}),
4531
4591
  ...unmoved,
4532
- ...dateNote(carried.eventDate, today),
4592
+ ...dateNote(carried.eventDate, today, carried.recurring),
4593
+ ...(ruleDropped ? { note: RECURRING_DROPPED_NOTE } : {}),
4533
4594
  },
4534
4595
  };
4535
4596
  }
4536
- const { eventDate, remind } = dated.fields;
4597
+ const { eventDate, remind, recurring } = dated.fields;
4537
4598
  if (typeof eventDate === "string") {
4538
- return { reminder: { eventDate, remind: remind ?? "quiet", ...dateNote(eventDate, today) } };
4599
+ const rule = isRecurrence(recurring) ? recurring : null;
4600
+ return {
4601
+ reminder: {
4602
+ eventDate,
4603
+ remind: remind ?? "quiet",
4604
+ ...(rule === null ? {} : { recurring: rule }),
4605
+ ...dateNote(eventDate, today, rule),
4606
+ },
4607
+ };
4539
4608
  }
4540
4609
  // A cancel that found nothing to cancel is SAID (review of #247): silence
4541
4610
  // here read as success while a reminder the model meant to drop kept coming.
@@ -4547,9 +4616,12 @@ function reminderEcho(deposit: DepositResult, dated: ReminderRead, today: string
4547
4616
  },
4548
4617
  };
4549
4618
  }
4550
- return dated.remindIgnored
4551
- ? { reminder: { ignored: "remind", note: "`remind` shapes how a date comes back; with no `eventDate` there was nothing to shape." } }
4552
- : {};
4619
+ const remindNote = "`remind` shapes how a date comes back; with no `eventDate` there was nothing to shape.";
4620
+ if (dated.remindIgnored && dated.recurringIgnored === true) {
4621
+ return { reminder: { ignored: "remind, recurring", note: `${remindNote} ${RECURRING_IGNORED_NOTE}` } };
4622
+ }
4623
+ if (dated.recurringIgnored === true) return { reminder: { ignored: "recurring", note: RECURRING_IGNORED_NOTE } };
4624
+ return dated.remindIgnored ? { reminder: { ignored: "remind", note: remindNote } } : {};
4553
4625
  }
4554
4626
 
4555
4627
  // ── feelings on a tool call (schema v7) ─────────────────────────────────────
@@ -22,7 +22,9 @@ export interface StdioOptions {
22
22
  }
23
23
 
24
24
  export async function serveStdio(
25
- server: McpServer,
25
+ // Only `handle` is used, so a stand-in that answers the protocol and nothing
26
+ // else (`stood-down.ts`) is served by the same pump.
27
+ server: Pick<McpServer, "handle">,
26
28
  input: AsyncIterable<string | Uint8Array>,
27
29
  opts: StdioOptions,
28
30
  ): Promise<void> {
@@ -0,0 +1,51 @@
1
+ /**
2
+ * A SERVER THAT IS THERE AND OFFERS NOTHING — the plugin's MCP server when the
3
+ * npm install's own `counterparts` server is already registered in this host
4
+ * (`adapters/plugin.ts#mcpGate`).
5
+ *
6
+ * Why not just exit: Claude Code reports a server that exited at start-up as
7
+ * "failed", which is a broken tool rather than a deliberate stand-down (scar
8
+ * §2.4: a stood-down tool must be distinguishable from a broken one). So it
9
+ * answers `initialize` with no tool capability worth having, lists no tools,
10
+ * and puts the reason in `instructions` — the one field of a server with no
11
+ * tools that a model, and `/mcp`, will show.
12
+ *
13
+ * It opens no store, reads no configuration and writes nothing: a stood-down
14
+ * server that touched the memory would be the double-write this exists to
15
+ * prevent.
16
+ */
17
+ import { ERROR_CODES, failure, negotiateVersion, success } from "./protocol.js";
18
+ import type { Request, Response } from "./protocol.js";
19
+ import { SERVER_NAME, SERVER_VERSION } from "./server.js";
20
+
21
+ export interface StoodDownServer {
22
+ handle(request: Request): Promise<Response | null>;
23
+ }
24
+
25
+ export function stoodDownServer(instructions: string): StoodDownServer {
26
+ return {
27
+ handle(request: Request): Promise<Response | null> {
28
+ const id = request.id;
29
+ // A notification is answered with nothing, ever (`protocol.ts`).
30
+ if (id === undefined) return Promise.resolve(null);
31
+ const params = request.params ?? {};
32
+ switch (request.method) {
33
+ case "initialize":
34
+ return Promise.resolve(
35
+ success(id, {
36
+ protocolVersion: negotiateVersion(params["protocolVersion"]),
37
+ capabilities: { tools: { listChanged: false } },
38
+ serverInfo: { name: SERVER_NAME, version: SERVER_VERSION },
39
+ instructions,
40
+ }),
41
+ );
42
+ case "tools/list":
43
+ return Promise.resolve(success(id, { tools: [] }));
44
+ case "ping":
45
+ return Promise.resolve(success(id, {}));
46
+ default:
47
+ return Promise.resolve(failure(id, ERROR_CODES.METHOD_NOT_FOUND, `${request.method}: this server is standing down. ${instructions}`));
48
+ }
49
+ },
50
+ };
51
+ }