counterparts 0.3.13 → 0.3.15

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 (106) hide show
  1. package/CHANGELOG.md +264 -0
  2. package/docs/QUICKSTART.md +22 -0
  3. package/docs/README.md +1 -0
  4. package/package.json +1 -1
  5. package/src/adapters/claude-code/CONTRACT.md +48 -0
  6. package/src/adapters/claude-code/NOTES.md +148 -0
  7. package/src/adapters/claude-code/bin/hook.mjs +4 -2
  8. package/src/adapters/claude-code/bin/hook.ts +61 -7
  9. package/src/adapters/claude-code/bin/nightly.ts +5 -1
  10. package/src/adapters/claude-code/bin/runner.ts +11 -3
  11. package/src/adapters/claude-code/claim.ts +319 -0
  12. package/src/adapters/claude-code/doctor.ts +170 -16
  13. package/src/adapters/claude-code/embed-client.ts +3 -0
  14. package/src/adapters/cli/CONTRACT.md +5 -0
  15. package/src/adapters/cli/NOTES.md +25 -0
  16. package/src/adapters/cli/bin/counterparts.mjs +4 -2
  17. package/src/adapters/cli/bin/counterparts.ts +49 -3
  18. package/src/adapters/cli/commands.ts +169 -32
  19. package/src/adapters/cli/desktop.ts +112 -7
  20. package/src/adapters/cli/help.ts +10 -0
  21. package/src/adapters/cli/index.ts +1 -0
  22. package/src/adapters/cli/install.ts +94 -14
  23. package/src/adapters/cli/self-page.ts +5 -8
  24. package/src/adapters/cli/settle.ts +39 -2
  25. package/src/adapters/cli/wire.ts +18 -1
  26. package/src/adapters/config.ts +29 -1
  27. package/src/adapters/dashboard/NOTES.md +33 -0
  28. package/src/adapters/dashboard/bin/dashboard.mjs +4 -2
  29. package/src/adapters/dashboard/bin/dashboard.ts +11 -3
  30. package/src/adapters/dashboard/index.ts +14 -0
  31. package/src/adapters/dashboard/registries.ts +3 -0
  32. package/src/adapters/dashboard/source.ts +0 -8
  33. package/src/adapters/dashboard/web/fired.ts +8 -0
  34. package/src/adapters/dashboard/web/flow.ts +1 -0
  35. package/src/adapters/dashboard/web/lanes.ts +1 -0
  36. package/src/adapters/dashboard/web/narrate.ts +11 -0
  37. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -1
  38. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +7 -10
  39. package/src/adapters/dashboard/web/pages/memories/memories.css +3 -0
  40. package/src/adapters/dashboard/web/pages/memories/row.js +5 -2
  41. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +2 -1
  42. package/src/adapters/dashboard/web/pages/memories/sections/search.js +19 -3
  43. package/src/adapters/dashboard/web/server.ts +16 -4
  44. package/src/adapters/dashboard/web/shared/dates.js +6 -16
  45. package/src/adapters/dashboard/web/shared/memory-modal.js +21 -8
  46. package/src/adapters/dashboard/web/views/health.ts +19 -5
  47. package/src/adapters/dashboard/web/views/mechanism-panel.ts +8 -5
  48. package/src/adapters/dashboard/web/views/memories.ts +26 -7
  49. package/src/adapters/dashboard/web/views/memory-words.ts +16 -0
  50. package/src/adapters/dashboard/web/views/memory.ts +51 -2
  51. package/src/adapters/dashboard/web/views/mind.ts +38 -6
  52. package/src/adapters/empty-bunfig.toml +5 -0
  53. package/src/adapters/fired.ts +16 -2
  54. package/src/adapters/host-wiring.ts +112 -17
  55. package/src/adapters/log/index.ts +2 -2
  56. package/src/adapters/mcp/CONTRACT.md +17 -2
  57. package/src/adapters/mcp/INTERFACE-GAPS.md +15 -1
  58. package/src/adapters/mcp/NOTES.md +269 -0
  59. package/src/adapters/mcp/bin/serve.mjs +4 -2
  60. package/src/adapters/mcp/bin/serve.ts +17 -6
  61. package/src/adapters/mcp/facts.ts +72 -4
  62. package/src/adapters/mcp/meaning.ts +218 -15
  63. package/src/adapters/mcp/server.ts +21 -6
  64. package/src/adapters/mcp/tools.ts +86 -61
  65. package/src/adapters/plugin-run.sh +413 -34
  66. package/src/adapters/plugin.ts +141 -17
  67. package/src/adapters/runtime.ts +192 -17
  68. package/src/adapters/sessions.ts +2 -2
  69. package/src/core/associate/NOTES.md +10 -0
  70. package/src/core/bridge.ts +1 -1
  71. package/src/core/briefing.ts +20 -3
  72. package/src/core/contradictions.ts +56 -20
  73. package/src/core/counterpart.ts +72 -23
  74. package/src/core/dream/CONTRACT.md +6 -14
  75. package/src/core/dream/INTERFACE-GAPS.md +3 -2
  76. package/src/core/dream/NOTES.md +10 -0
  77. package/src/core/dream/index.ts +11 -53
  78. package/src/core/dream/reflect.ts +11 -2
  79. package/src/core/embed/static.ts +5 -1
  80. package/src/core/encode/INTERFACE-GAPS.md +2 -1
  81. package/src/core/encode/NOTES.md +12 -0
  82. package/src/core/encode/chunk.ts +6 -30
  83. package/src/core/encode/index.ts +0 -1
  84. package/src/core/encode/types.ts +1 -13
  85. package/src/core/handoff/INTERFACE-GAPS.md +1 -1
  86. package/src/core/handoff/index.ts +2 -1
  87. package/src/core/handoff/last-here.ts +18 -2
  88. package/src/core/physics/CONTRACT.md +6 -0
  89. package/src/core/physics/NOTES.md +33 -2
  90. package/src/core/physics/index.ts +22 -7
  91. package/src/core/prospective/CONTRACT.md +3 -1
  92. package/src/core/prospective/NOTES.md +15 -0
  93. package/src/core/recall/activate.ts +1 -1
  94. package/src/core/recall/time-ask.ts +173 -19
  95. package/src/core/self/CONTRACT.md +56 -19
  96. package/src/core/self/NOTES.md +172 -0
  97. package/src/core/self/behind.ts +6 -3
  98. package/src/core/self/briefing.ts +384 -28
  99. package/src/core/self/index.ts +105 -44
  100. package/src/core/self/page.ts +12 -85
  101. package/src/core/self/tunables.ts +16 -19
  102. package/src/core/self/writer.ts +31 -4
  103. package/src/core/sleep/NOTES.md +32 -0
  104. package/src/core/store/NOTES.md +21 -2
  105. package/src/core/store/index.ts +2 -1
  106. package/src/core/time.ts +15 -0
@@ -37,7 +37,14 @@
37
37
  * the order of its names, counts only breaking a tie (`subjectOf`, since
38
38
  * 2026-10-09; it was the card holding the most) — and the rest are
39
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"
40
+ * counterpart's voice) is his own card. A name asked about that has NO card
41
+ * (2026-10-09) is never passed over in silence for another card: when every
42
+ * card the question names sits in an aside ("what has Han been to Mike"),
43
+ * the answer is the moments that mention it, as typed, and its first line
44
+ * says so ("No card for Han yet; here is what mentions Han"); beside a card
45
+ * asked about or named plainly, the card leads as before and the first line
46
+ * says the name has none (`MeaningResult.noCard`). Naming no card, the
47
+ * question's words and meaning answer it, as before. "us"
41
48
  * is the memories marked `about: us`. A question about feeling
42
49
  * (`recall/feeling-ask.ts#readFeelingAsk`, ranked) with no card is answered
43
50
  * by the stamps that match it — word, core, whose — and, when it names a
@@ -218,6 +225,14 @@ export interface MeaningResult {
218
225
  readonly mode: "meaning";
219
226
  readonly reason: "answered" | "nothing-came";
220
227
  readonly semantic: SemanticSource;
228
+ /**
229
+ * A name the question asks about that has no card, said plainly — the
230
+ * answer's FIRST line (2026-10-09): "No card for Han yet; here is what
231
+ * mentions Han" when the answer follows the name (a `words` lens on it),
232
+ * "… yet; this follows Ilya" when a card asked about alongside it leads.
233
+ * Null when every name asked about has a card.
234
+ */
235
+ readonly noCard: string | null;
221
236
  readonly lens: MeaningLens | null;
222
237
  /** The other subjects the question named, as one-liners to ask for. */
223
238
  readonly others: readonly { readonly name: string; readonly memories: number }[];
@@ -462,16 +477,39 @@ export function meaningRecall(ctx: MeaningContext, question: string, opts: { pag
462
477
  // store is usually the owner's: "what has Ilya been to Mike" answered
463
478
  // about Mike.
464
479
  const ownerCard = safe(() => findIdentityCore(store), null);
480
+ /** Each word of a live card's name or alias, lower case → the cards it is a word of (read once, when asked). */
481
+ let cardWords: Map<string, string[]> | null = null;
482
+ const cardWord = (word: string): boolean => {
483
+ if (cardWords === null) {
484
+ const index = new Map<string, string[]>();
485
+ for (const e of safe(() => c.schemas.entities(), [] as ReturnType<typeof c.schemas.entities>)) {
486
+ for (const w of new Set([e.name, ...e.aliases].flatMap((t) => tokenize(t)))) index.set(w, [...(index.get(w) ?? []), e.id]);
487
+ }
488
+ cardWords = index;
489
+ }
490
+ // Only a card the asker may see something of: one that holds nothing for
491
+ // him reads as no card, as everywhere else here.
492
+ return (cardWords.get(word) ?? []).some((id) => (cardOf(id)?.ids.length ?? 0) > 0);
493
+ };
465
494
  const subject = subjectOf(question, cards, {
466
495
  terms: (id) => cardTerms(c, id),
467
496
  ownerCard,
468
497
  ownerPronoun: feelingAsked || usAsked ? null : asker === "self" ? OWNER_AS_YOU : OWNER_AS_I,
469
498
  ownerCardOf: () => (ownerCard === null ? null : cardOf(ownerCard)),
499
+ ownerNames: new Set(ownerNamesLower(c).flatMap((n) => tokenize(n))),
500
+ cardWord,
470
501
  });
471
502
  const bestCard = subject.card;
472
503
  if (bestCard !== null && subject.alike.length > 0) {
473
504
  notes.push(`it asks about ${andList([bestCard.name, ...subject.alike])} alike: this follows ${bestCard.name}, named first`);
474
505
  }
506
+ // A NAME WITH NO CARD, said first (2026-10-09): asked about alongside a
507
+ // card, the card leads; asked about above every card, what mentions it is
508
+ // the answer (below). Never an answer about another card in silence.
509
+ let noCard: string | null =
510
+ bestCard !== null && subject.bareAlike.length > 0 ? `No card for ${andList(subject.bareAlike)} yet; this follows ${bestCard.name}` : null;
511
+ /** The name with no card the answer follows, when it follows one. */
512
+ const bareName = bestCard === null && !feelingAsked ? subject.bare : null;
475
513
 
476
514
  if (bestCard !== null) {
477
515
  lens = { kind: "card", id: bestCard.id, name: bestCard.name };
@@ -489,6 +527,18 @@ export function meaningRecall(ctx: MeaningContext, question: string, opts: { pag
489
527
  }
490
528
  for (const x of cards) if (x.id !== bestCard.id) others.push({ name: x.name, memories: x.ids.length });
491
529
  if (usIds.length > 0) others.push({ name: usName, memories: usIds.length });
530
+ } else if (bareName !== null) {
531
+ // What mentions the name, as typed ("Han", not "han"): its words only.
532
+ // The question's meaning is left out — its vector carries the other
533
+ // names too, and would bring "Mike" back in for "what has Han been to
534
+ // Mike". The cards it named are one-liners to ask for.
535
+ lens = { kind: "words", name: `"${bareName}"` };
536
+ const byWords = holdByWords(store, nameTopic(bareName), usable, hold);
537
+ textMatch = byWords.textMatch;
538
+ lineMatch = byWords.lineMatch;
539
+ notes.push("matched by the name as written, not by meaning");
540
+ for (const x of cards) others.push({ name: x.name, memories: x.ids.length });
541
+ if (usIds.length > 0) others.push({ name: usName, memories: usIds.length });
492
542
  } else if (usIds.length > 0) {
493
543
  lens = { kind: "us", name: usName };
494
544
  for (const id of usIds) hold(id, 1);
@@ -506,13 +556,19 @@ export function meaningRecall(ctx: MeaningContext, question: string, opts: { pag
506
556
  const asked = question.replace(/\bsince\b[^?.!;]*/gi, " ");
507
557
  const proper = safe(() => askedNames(asked), new Set<string>());
508
558
  const owners = new Set(ownerNamesLower(c).flatMap((n) => tokenize(n)));
509
- const topic = contentWords(
510
- c,
511
- asked,
512
- minLen,
513
- ask.named,
514
- (w) => isFeelingFrameWord(w, stored, proper) || owners.has(w) || FEELING_FRAME_MORE.has(w),
515
- );
559
+ // A name with no card that leads (`subjectOf`'s `bare`) is the topic, as
560
+ // typed: the question's other words include the card it outranked, and
561
+ // "no card names" would then name that card too (review of #347).
562
+ const topic =
563
+ subject.bare !== null
564
+ ? nameTopic(subject.bare)
565
+ : contentWords(
566
+ c,
567
+ asked,
568
+ minLen,
569
+ ask.named,
570
+ (w) => isFeelingFrameWord(w, stored, proper) || owners.has(w) || FEELING_FRAME_MORE.has(w),
571
+ );
516
572
  const reached = new Map<string, number>();
517
573
  if (topic.words.length > 0) {
518
574
  holdByWords(store, topic, usable, (id) => {
@@ -790,10 +846,17 @@ export function meaningRecall(ctx: MeaningContext, question: string, opts: { pag
790
846
  if (!feltAny) notes.push("no feelings recorded");
791
847
  }
792
848
 
849
+ const nothing = lens === null || (all.length === 0 && faded.length === 0 && readingsAll.length === 0 && openAll.length === 0);
850
+ if (bareName !== null) {
851
+ noCard = nothing
852
+ ? `No card for ${bareName} yet, and nothing in memory mentions ${bareName}`
853
+ : `No card for ${bareName} yet; here is what mentions ${bareName}`;
854
+ }
793
855
  const result: MeaningResult = {
794
856
  mode: "meaning",
795
- reason: lens === null || (all.length === 0 && faded.length === 0 && readingsAll.length === 0 && openAll.length === 0) ? "nothing-came" : "answered",
857
+ reason: nothing ? "nothing-came" : "answered",
796
858
  semantic,
859
+ noCard,
797
860
  lens,
798
861
  others: others.filter((o) => o.memories > 0),
799
862
  feeling: feelingAsked && ask !== null ? { words: [...ask.named], whose: ask.whose === null ? null : whose[ask.whose] } : null,
@@ -1162,6 +1225,8 @@ function refold(arc: readonly MeaningArcLine[], address: string): MeaningArcLine
1162
1225
  */
1163
1226
  export function renderMeaning(r: MeaningResult): string {
1164
1227
  const out: string[] = [];
1228
+ // Said first, before anything about another subject (2026-10-09).
1229
+ if (r.noCard !== null) out.push(`${r.noCard}.`);
1165
1230
  if (r.lens === null) {
1166
1231
  out.push("Nothing came: the question names no card, asks about no feeling, and none of its words reach a memory.");
1167
1232
  out.push("Try a person's or project's name, or facts mode for a single fact.");
@@ -1337,6 +1402,22 @@ function mentionRank(m: { readonly slot: Slot; readonly pronoun: boolean; readon
1337
1402
  * his. Anywhere else a pronoun names nothing, so "do you remember
1338
1403
  * the budget" is still read by its words. Off (`ownerPronoun` null) for a
1339
1404
  * question about feeling, where the pronoun says whose feeling, and for "us".
1405
+ *
1406
+ * A NAME WITH NO CARD (2026-10-09, the 0.3.13 release check): "what has Han
1407
+ * been to Mike", on a store whose one card is Mike's, answered with Mike's
1408
+ * arc and no word about Han. A name the asker capitalised mid-sentence
1409
+ * (`askedNames`) that no card with memories covers — not the owner's, not a
1410
+ * month or a weekday, not a word of a card's longer name, not an acronym — is
1411
+ * read in place like a card's, typed as written, when the question names a
1412
+ * card too (with none named, nothing is answered in its place, and the
1413
+ * question's words and meaning follow it as before). In
1414
+ * an aside it is passed over. When EVERY card the question names sits in an
1415
+ * aside ("been to Mike", "since Driftwood"), it is `bare`: the answer is what
1416
+ * mentions it, said so first. A card asked about or named plainly leads, as
1417
+ * it did before (review of #347: "what did Teodoro say about Postgres" is
1418
+ * Teodoro's, "how did I feel about Han at Driftwood" is Driftwood's), and
1419
+ * `bareAlike` names each such name ranked as high as that card, so the
1420
+ * answer can say it has no card.
1340
1421
  */
1341
1422
  function subjectOf(
1342
1423
  question: string,
@@ -1346,8 +1427,16 @@ function subjectOf(
1346
1427
  readonly ownerCard: string | null;
1347
1428
  readonly ownerPronoun: RegExp | null;
1348
1429
  readonly ownerCardOf: () => NamedCard | null;
1430
+ /** The owner's names, lower case, word by word: never a name without a card. */
1431
+ readonly ownerNames: ReadonlySet<string>;
1432
+ /**
1433
+ * Is this word (lower case) part of the name or an alias of a card the
1434
+ * asker may see — "Marguerite" of Marguerite Solberg? Never a name
1435
+ * without a card, though `subjectsIn` does not read it as that card.
1436
+ */
1437
+ readonly cardWord: (word: string) => boolean;
1349
1438
  },
1350
- ): { card: NamedCard | null; alike: readonly string[] } {
1439
+ ): { card: NamedCard | null; alike: readonly string[]; bare: string | null; bareAlike: readonly string[] } {
1351
1440
  const live = cards.filter((x) => x.ids.length > 0);
1352
1441
  // Every mention of every card, in the order they are named.
1353
1442
  const mentions: { card: NamedCard; at: number; end: number; slot: Slot; pronoun: boolean; lowered: boolean }[] = [];
@@ -1371,18 +1460,37 @@ function subjectOf(
1371
1460
  }
1372
1461
  }
1373
1462
  }
1374
- if (live.length === 0) return { card: null, alike: [] };
1375
1463
  mentions.sort((a, b) => a.at - b.at || b.end - a.end);
1376
1464
  const kept: typeof mentions = [];
1377
1465
  for (const m of mentions) {
1378
1466
  const prev = kept[kept.length - 1];
1379
1467
  // A name inside a longer one ("Han" in "Han Seo") is not a mention of its own.
1380
1468
  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
1469
  kept.push(m);
1385
1470
  }
1471
+ // The names no card covers, between and around the cards' own.
1472
+ const uncarded = uncardedNames(question, kept, o.ownerNames, o.cardWord);
1473
+ // Joined to the name before it ("X and Y", "X, Y"), a name takes that one's
1474
+ // place — and joined to the owner's pronoun ("how have you and Ilya been"),
1475
+ // the place the grammar gives, not the pronoun's lower rank. Cards and
1476
+ // names with no card alike: "how have Han and Ilya been" asks about both.
1477
+ const inOrder: { at: number; end: number; slot: Slot }[] = [...kept, ...uncarded].sort((a, b) => a.at - b.at);
1478
+ for (let i = 1; i < inOrder.length; i += 1) {
1479
+ const prev = inOrder[i - 1] as { at: number; end: number; slot: Slot };
1480
+ const m = inOrder[i] as { at: number; end: number; slot: Slot };
1481
+ if (JOINED.test(question.slice(prev.end, m.at))) m.slot = prev.slot;
1482
+ }
1483
+ // In an aside a name with no card is passed over; the first named breaks a tie.
1484
+ // With no card named at all, none is: nothing would be answered in its
1485
+ // place, and the question's own words and meaning already follow it — "what
1486
+ // did I learn about Postgres indexing" stays a question about indexing too
1487
+ // (review of #347).
1488
+ const bare = (kept.length === 0 ? [] : uncarded)
1489
+ .map((b) => ({ ...b, rank: mentionRank({ slot: b.slot, pronoun: false, lowered: false }) }))
1490
+ .filter((b) => b.slot !== "aside");
1491
+ const bareBest = bare.reduce((r, b) => Math.max(r, b.rank), Number.NEGATIVE_INFINITY);
1492
+ const bareFirst = bare.find((b) => b.rank === bareBest)?.name ?? null;
1493
+ if (live.length === 0) return { card: null, alike: [], bare: bareFirst, bareAlike: [] };
1386
1494
  const place = new Map<string, { rank: number; at: number; length: number }>();
1387
1495
  for (const m of kept) {
1388
1496
  const had = place.get(m.card.id);
@@ -1393,6 +1501,12 @@ function subjectOf(
1393
1501
  const placeOf = (x: NamedCard) => place.get(x.id) ?? { rank: -1, at: Number.POSITIVE_INFINITY, length: 0 };
1394
1502
  const best = Math.max(...live.map((x) => placeOf(x).rank));
1395
1503
  let field = live.filter((x) => placeOf(x).rank === best);
1504
+ // A name with no card leads only when every card named sits in an aside
1505
+ // ("what has Han been to Mike"). A card asked about or named plainly leads
1506
+ // as before, and the name is said to have none (review of #347).
1507
+ if (bareFirst !== null && kept.every((m) => m.slot === "aside")) {
1508
+ return { card: null, alike: [], bare: bareFirst, bareAlike: [] };
1509
+ }
1396
1510
  if (field.length > 1 && o.ownerCard !== null) field = field.filter((x) => x.id !== o.ownerCard);
1397
1511
  field.sort((a, b) => {
1398
1512
  const pa = placeOf(a);
@@ -1400,7 +1514,96 @@ function subjectOf(
1400
1514
  return pa.at - pb.at || pb.length - pa.length || b.ids.length - a.ids.length || a.name.localeCompare(b.name);
1401
1515
  });
1402
1516
  const [card, ...rest] = field;
1403
- return { card: card ?? null, alike: rest.map((x) => x.name) };
1517
+ return {
1518
+ card: card ?? null,
1519
+ alike: rest.map((x) => x.name),
1520
+ bare: null,
1521
+ // Each name with no card asked about as high as the card that leads, or higher.
1522
+ bareAlike: bare.filter((b) => b.rank >= best).map((b) => b.name),
1523
+ };
1524
+ }
1525
+
1526
+ /** Month and weekday names: capitalised, and a time, never a subject. */
1527
+ const CALENDAR_NAMES = new Set([
1528
+ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december",
1529
+ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday",
1530
+ ]);
1531
+
1532
+ /**
1533
+ * Words a question is built from, never a name: one of them capitalised
1534
+ * mid-sentence means the question was typed in Title Case ("What Has Changed
1535
+ * Since Monday"), which capitalises nothing in particular (review of #347).
1536
+ * Not "will", "may" or "can", which are names too.
1537
+ */
1538
+ const TITLE_CASE_TELLS = new Set([
1539
+ "has", "have", "had", "is", "are", "was", "were", "been", "did", "does",
1540
+ "the", "of", "to", "in", "on", "at", "for", "with", "about", "from", "into", "than", "and", "or", "since",
1541
+ "what", "how", "when", "why", "where", "who", "this", "that", "it", "you", "your", "we", "our",
1542
+ "they", "their", "his", "her", "him", "them",
1543
+ ]);
1544
+
1545
+ /**
1546
+ * The names the asker capitalised mid-sentence (`askedNames`) that no kept
1547
+ * card mention covers — "Han", or "Han Seo" for two in a row — with where
1548
+ * each sits. Not the owner's name, not a month or a weekday ("since March"
1549
+ * is a time), and not a word of a card's longer name ("Marguerite" when
1550
+ * Marguerite Solberg has a card: there IS a card). Not an acronym or a word
1551
+ * with a digit ("API", "Q3"): a thing's label, not a name. Nothing in a
1552
+ * question typed in Title Case. A possessive is dropped ("Han's" names Han).
1553
+ */
1554
+ function uncardedNames(
1555
+ question: string,
1556
+ taken: readonly { readonly at: number; readonly end: number }[],
1557
+ ownerNames: ReadonlySet<string>,
1558
+ cardWord: (word: string) => boolean,
1559
+ ): { name: string; at: number; end: number; slot: Slot }[] {
1560
+ const proper = safe(() => askedNames(question), new Set<string>());
1561
+ if (proper.size === 0) return [];
1562
+ if ([...proper].some((w) => TITLE_CASE_TELLS.has(w))) return [];
1563
+ const out: { name: string; at: number; end: number; slot: Slot }[] = [];
1564
+ let run: { at: number; end: number; parts: string[]; closed: boolean } | null = null;
1565
+ const flush = (): void => {
1566
+ const r = run as { at: number; end: number; parts: string[]; closed: boolean } | null;
1567
+ if (r !== null) out.push({ name: r.parts.join(" "), at: r.at, end: r.end, slot: slotAt(question, r.at) });
1568
+ run = null;
1569
+ };
1570
+ for (const m of question.matchAll(/[A-Za-z0-9][A-Za-z0-9'’]*/g)) {
1571
+ const tok = m[0];
1572
+ const at = m.index;
1573
+ const end = at + tok.length;
1574
+ const word = tok.replace(/['’]s?$/, "");
1575
+ const low = word.toLowerCase();
1576
+ const isName =
1577
+ /^[A-Z]/.test(tok) &&
1578
+ proper.has(tok.toLowerCase().replace(/['’]/g, "")) &&
1579
+ !/\d/.test(word) &&
1580
+ !/^[A-Z][A-Z]/.test(word) &&
1581
+ !CALENDAR_NAMES.has(low) &&
1582
+ !ownerNames.has(low) &&
1583
+ !taken.some((t) => at < t.end && end > t.at) &&
1584
+ !tokenize(word).some((w) => cardWord(w));
1585
+ const current = run as { at: number; end: number; parts: string[]; closed: boolean } | null;
1586
+ if (isName && current !== null && !current.closed && /^[ \t]+$/.test(question.slice(current.end, at))) {
1587
+ current.parts.push(word);
1588
+ current.end = end;
1589
+ current.closed = word !== tok;
1590
+ continue;
1591
+ }
1592
+ flush();
1593
+ if (isName) run = { at, end, parts: [word], closed: word !== tok };
1594
+ }
1595
+ flush();
1596
+ return out;
1597
+ }
1598
+
1599
+ /** A name with no card as a topic, as typed ("Han", not "han"): its words only. */
1600
+ function nameTopic(name: string): TopicWords {
1601
+ const typed = name.split(/\s+/).filter((w) => w.length > 0);
1602
+ return {
1603
+ words: typed.map((w) => w.toLowerCase()),
1604
+ names: new Map(typed.map((w) => [w.toLowerCase(), nameRegex(w, "gu")])),
1605
+ shown: [name],
1606
+ };
1404
1607
  }
1405
1608
 
1406
1609
  /** The place a name at `index` sits in: about, aside, or plain. */
@@ -137,7 +137,7 @@ import { DREAMING_SETTINGS, NIGHT_RUN_FINISHES, nightNext, nightOrder } from "..
137
137
  import type { DreamBundle, DreamingSetting, NightPart } from "../../core/dream/index.js";
138
138
  import { TOOL_RESULT_CEILING, clipWire, noteLookups, wireChars } from "../../core/fit/index.js";
139
139
  import type { FitMechanism } from "../../core/fit/index.js";
140
- import { NIGHT_WRITER_TOOL, NO_PAGE_VERSION, WAKE_BUILD_KEY, pageSections } from "../../core/self/index.js";
140
+ import { NIGHT_WRITER_TOOL, NO_PAGE_VERSION, WAKE_BUILD_KEY, pageSections, pageTooLargeDetail } from "../../core/self/index.js";
141
141
  import type { PageWriterMode } from "../../core/self/index.js";
142
142
  import { toolDefinitions, toolSpec } from "./tools.js";
143
143
  import { writeUpDoor } from "./write-up.js";
@@ -153,7 +153,7 @@ export const SERVER_NAME = "counterparts";
153
153
  * host decides whether to trust what follows. Read from a constant rather than
154
154
  * from disk so the server opens no file to answer its first message.
155
155
  */
156
- export const SERVER_VERSION = "0.3.13";
156
+ export const SERVER_VERSION = "0.3.15";
157
157
 
158
158
  /**
159
159
  * THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
@@ -486,7 +486,7 @@ export type ScopeSource = "flag" | "project" | "cwd" | "store" | "host";
486
486
  const PAGE_REFUSAL_DETAIL: Record<string, string> = {
487
487
  empty: "A page has to say something. Nothing worth writing is a real answer — leave the page alone instead.",
488
488
  "too-large":
489
- "That page is past the hard limit, so it was refused rather than cut: what gets cut at write time is the only copy. Say the same thing shorter and send it again.",
489
+ "That page is past its limit (`limit` bytes, UTF-8; `bytes` is what was sent, `over` how much to take out) — the most the wake prints whole, so a page is never cut there. It was refused rather than cut: what gets cut at write time is the only copy. Say the same thing shorter — tighten, merge or drop what no longer holds, do not just chop the end — and send the whole page again.",
490
490
  "gate-refused":
491
491
  "The gate battery turned it away — most often because what was sent was nothing but a credential, or too short to be a page. Nothing was written.",
492
492
  "forged-markers":
@@ -3390,7 +3390,11 @@ export class McpServer {
3390
3390
  about: out.about,
3391
3391
  ifVersion: out.version ?? NO_PAGE_VERSION,
3392
3392
  read: out.text,
3393
- how: `Read the block. If something about who you are moved on ${out.about}, call the self_page tool with the WHOLE page, reason, ifVersion: ${String(out.version ?? NO_PAGE_VERSION)} and session: ${session}; if nothing moved, write nothing — that is an answer too.`,
3393
+ // THE RETRY, IN THE SAME RUN (review of #358): a page refused
3394
+ // for length is the writer still trying, and the run is an agent
3395
+ // that reads the refusal — so it is told to tighten and send it
3396
+ // again before it goes on, rather than leave the night unwritten.
3397
+ how: `Read the block. If something about who you are moved on ${out.about}, call the self_page tool with the WHOLE page, reason, ifVersion: ${String(out.version ?? NO_PAGE_VERSION)} and session: ${session}; if nothing moved, write nothing — that is an answer too. If self_page refuses the page as too-large, its answer says how many bytes over the limit it is: tighten it (merge, drop what no longer holds — do not just cut the end) and send the whole page again before you go on.`,
3394
3398
  ...(next === null ? {} : { next: `Then: ${next}` }),
3395
3399
  },
3396
3400
  false,
@@ -3679,7 +3683,14 @@ export class McpServer {
3679
3683
  about: writerFor.about,
3680
3684
  mode: writerFor.mode,
3681
3685
  outcome: written.written ? "revised" : "refused",
3682
- detail: written.written ? "" : written.reason,
3686
+ // A refusal for length carries its numbers (review of #358), so the
3687
+ // row — and the night's close, if the run moves on without a
3688
+ // shorter page — says how far over it was.
3689
+ detail: written.written
3690
+ ? ""
3691
+ : written.reason === "too-large"
3692
+ ? pageTooLargeDetail(written.bytes, this.counterpart.self.tunables.PAGE_MAX_BYTES)
3693
+ : written.reason,
3683
3694
  bytesAfter: written.written ? written.bytes : 0,
3684
3695
  });
3685
3696
  } catch {
@@ -3687,8 +3698,13 @@ export class McpServer {
3687
3698
  }
3688
3699
  }
3689
3700
  if (!written.written) {
3701
+ // THE LIMIT, IN NUMBERS (2026-10-09): a writer told only "past the
3702
+ // limit" guesses how much to take out; told both numbers, it tightens
3703
+ // once and sends the page again.
3704
+ const limit = this.counterpart.self.tunables.PAGE_MAX_BYTES;
3690
3705
  return this.refuse("self_page", written.reason, {
3691
3706
  bytes: written.bytes,
3707
+ ...(written.reason === "too-large" ? { limit, over: written.bytes - limit } : {}),
3692
3708
  ...(written.gate === null ? {} : { gate: written.gate }),
3693
3709
  // On a stale write, hand back what is actually there so the session can
3694
3710
  // merge rather than guess — the whole point of the check.
@@ -3715,7 +3731,6 @@ export class McpServer {
3715
3731
  redactedBy: written.redacted.gate,
3716
3732
  bytesBeforeRedaction: written.redacted.bytesBefore,
3717
3733
  }),
3718
- ...(written.warning === null ? {} : { warning: written.warning }),
3719
3734
  // WHEN IT WILL BE READ, precisely. The bundle every session wakes with
3720
3735
  // is composed by a worker and served unchanged until the next render,
3721
3736
  // so "it is live now" would be false for as long as this session lasts.