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
@@ -47,7 +47,7 @@ import { UNRESOLVED_META_KEY, mintProposal } from "./mint.js";
47
47
  import type { MintResult } from "./mint.js";
48
48
  import { isObserver } from "./observer.js";
49
49
  import type { Stance } from "./observer.js";
50
- import { Prospective, DATE_LINEAGE_MAX, DATE_MOVED_TO_META, cueModeOf } from "./prospective/index.js";
50
+ import { Prospective, DATE_LINEAGE_MAX, DATE_MOVED_TO_META, cueModeOf, recurrenceOf } from "./prospective/index.js";
51
51
  import type { PlainDue } from "./prospective/index.js";
52
52
  import {
53
53
  ASKED_KIND,
@@ -55,8 +55,10 @@ import {
55
55
  askedTurn,
56
56
  Recall,
57
57
  isConfidential,
58
+ judgedThrough,
58
59
  loadGateState,
59
60
  loadSessionSemantic,
61
+ markJudged,
60
62
  saveSessionSemantic,
61
63
  } from "./recall/index.js";
62
64
  import { resolveReferences } from "./recall/reference.js";
@@ -64,6 +66,7 @@ import type { ReferenceCandidate } from "./recall/reference.js";
64
66
  import type {
65
67
  CandidateVerdict,
66
68
  CreditResult,
69
+ GateState,
67
70
  RecallDecision,
68
71
  Turn as RecallTurn,
69
72
  RecallResult,
@@ -115,8 +118,15 @@ import type {
115
118
  import { recallTurn } from "./retrieval.js";
116
119
  import { applyRevision } from "./revision.js";
117
120
  import type { RevisionApplication } from "./revision.js";
118
- import { settle as settleContradiction, undo as undoContradiction, writeNeighbours } from "./contradictions.js";
119
- import type { Neighbour, SettleInput, SettleOutcome, UndoOutcome } from "./contradictions.js";
121
+ import {
122
+ CONTRADICTION_HELD_EVENT,
123
+ heldView,
124
+ settle as settleContradiction,
125
+ undo as undoContradiction,
126
+ updateRelatedness,
127
+ writeNeighbours,
128
+ } from "./contradictions.js";
129
+ import type { HeldUpdate, Neighbour, SettleInput, SettleOutcome, UndoOutcome } from "./contradictions.js";
120
130
  import { Schemas } from "./schemas/index.js";
121
131
  import {
122
132
  HANDOFF_CLEARED_EVENT,
@@ -133,7 +143,8 @@ import { CLAIM_CHAPTER, askFromStretch, chapterClaims, claimUnwritten, sessionSt
133
143
  import { LAST_HERE_LIFE_DAYS, LAST_HERE_NOROOM_EVENT, chaptersBySession, chaptersHere, chaptersOn, elsewhereLine, lastHereLadder, yesterdayLine } from "./handoff/last-here.js";
134
144
  import type { ChapterHere, LastHere } from "./handoff/last-here.js";
135
145
  import { addDays, isDay, localStamp, localStampAfter } from "./time.js";
136
- import { leftAs } from "./leaving.js";
146
+ import type { Recurrence } from "./time.js";
147
+ import { EPISODE_REGROWN_REASON, leftAs } from "./leaving.js";
137
148
  import type { LeftAs } from "./leaving.js";
138
149
  import {
139
150
  BRIEFING_KEY,
@@ -148,6 +159,7 @@ import {
148
159
  noteWakeBuild,
149
160
  noteWakeCaught,
150
161
  settledOver,
162
+ threadsShown,
151
163
  spliceBeforeSentinel,
152
164
  wakeBehind,
153
165
  wakeFromOtherBuild,
@@ -179,7 +191,7 @@ import type {
179
191
  WakeTrigger,
180
192
  WriterInput,
181
193
  } from "./self/index.js";
182
- import { cyclePartial, runCycle } from "./sleep/index.js";
194
+ import { cyclePartial, ownerNames, runCycle } from "./sleep/index.js";
183
195
  import type { CyclePartial, CycleReport, Phase } from "./sleep/index.js";
184
196
  import { CORE_ABOUT_MARKS, Store, assertSafeDataDir, hashText, indexTextOf, occurredOnOf, saidByOf, statusOf } from "./store/index.js";
185
197
  import type {
@@ -526,6 +538,9 @@ export const ASSOCIATE_FLUSH_EVENT = "associate.flush";
526
538
  export const CONTIGUITY_CURSOR_META = "associateContiguityCursor";
527
539
  /** Meta key: the v12 subject backfill's record (latch + what it linked, for doctor). */
528
540
  export const SUBJECTS_BACKFILL_META = "subjects.v12.backfill";
541
+ /** Meta key: the one-time carry of the links regrown chapter copies were left
542
+ * holding (2026-10-09) — its latch, and what it carried. */
543
+ export const REGROWN_RELINK_META = "associate.regrown.relink";
529
544
 
530
545
  /** What one boundary's temporal contiguity pass did. Counts only. */
531
546
  export interface ContiguityPass {
@@ -648,6 +663,18 @@ export const MCP_RECALL_EVENT = "mcp.recall";
648
663
  */
649
664
  export const MCP_PART_EVENT = "mcp.part";
650
665
  export const MCP_OVERSIZE_EVENT = "mcp.result.oversize";
666
+ /**
667
+ * …AND WHAT THE HOST DID AFTER (2026-10-09, U14 item 3). The two rows above
668
+ * are the server's view: what it handed, what it cut. Neither can see the host
669
+ * cut a result the server sized under the ceiling — a remote flag can lower
670
+ * Claude Code's line below it. The nightly run reads its own child's
671
+ * transcript once the child exits (`claude-code/transcript.ts#readToolSpills`)
672
+ * and writes one `mcp.result.spilled` row per result of ours the host showed
673
+ * only as a preview: the run, the tool, the phase, the marker's shape and the
674
+ * size the host said. Never the saved file's path, never the text. No
675
+ * `dedupKey`: a run is read once.
676
+ */
677
+ export const MCP_SPILLED_EVENT = "mcp.result.spilled";
651
678
 
652
679
  /**
653
680
  * WHAT A DELIVERY COULD NOT CARRY (durable since 2026-10-02; ring-only
@@ -762,6 +789,26 @@ export interface CreditSummary {
762
789
  * shown are on each turn's `recall.decision` (`spread.pointersShown`);
763
790
  * this is the other half: whether they get used. */
764
791
  readonly pointersExpanded: number;
792
+ /** The ambient showings this boundary scored (2026-10-09): what recall showed
793
+ * this session since the last boundary that judged, by lane. Measurement
794
+ * only — nothing is strengthened, weakened or re-ranked by it. */
795
+ readonly shown: ShownLanes;
796
+ /** Of those, how many the replies neither expanded nor quoted, by lane. */
797
+ readonly unused: ShownLanes;
798
+ /** Their ids, oldest showing first: with `recall.decision`'s rows, a hit rate
799
+ * per memory and per lane. */
800
+ readonly shownNotUsed: string[];
801
+ /** The recall turn the scored stretch ends at (the session's `judged` mark
802
+ * after this pass); 0 when the session has shown nothing yet. */
803
+ readonly judgedThrough: number;
804
+ }
805
+
806
+ /** Ambient showings by lane: shown loud, footnoted on the turn's own cues, or
807
+ * footnoted as a quiet pointer (reached only through links). */
808
+ export interface ShownLanes {
809
+ readonly loud: number;
810
+ readonly footnotes: number;
811
+ readonly pointers: number;
765
812
  }
766
813
 
767
814
  /**
@@ -810,6 +857,7 @@ export type AdapterDurableEventName =
810
857
  | typeof MCP_RECALL_EVENT
811
858
  | typeof MCP_PART_EVENT
812
859
  | typeof MCP_OVERSIZE_EVENT
860
+ | typeof MCP_SPILLED_EVENT
813
861
  | DeliveryWarningName
814
862
  | typeof CHECKOUT_EVENT
815
863
  | typeof SNAPSHOT_TAKEN_EVENT
@@ -1063,6 +1111,14 @@ export interface DepositResult {
1063
1111
  * settled, or why it was not. Absent when nothing was declared.
1064
1112
  */
1065
1113
  readonly revision?: RevisionApplication;
1114
+ /**
1115
+ * The declared `updates:` this deposit HELD (2026-10-09, the update guard):
1116
+ * a `changed` or `corrected` at a memory that looked unrelated to the new
1117
+ * one, so the new memory landed unlinked and the old one was not settled
1118
+ * (`Counterpart#guardUpdate`). The old memory's title and text ride out, so
1119
+ * the writer can settle it itself if it meant to. Absent otherwise.
1120
+ */
1121
+ readonly held?: HeldUpdate;
1066
1122
  /**
1067
1123
  * The open thread this deposit CLOSED (2026-10-01, lane 8): the memory it
1068
1124
  * revises was flagged `unresolved` and the author sent `unresolved` — false
@@ -1092,8 +1148,13 @@ export interface DepositReminder {
1092
1148
  /** The date the new memory carries, or null when the revision dropped it. */
1093
1149
  readonly eventDate: string | null;
1094
1150
  readonly remind: "plain" | "quiet" | null;
1151
+ /** How often the carried date comes round (2026-10-09), or null: once. */
1152
+ readonly recurring: Recurrence | null;
1153
+ /** A repeat — sent or carried — that the new date cannot take (only a day
1154
+ * repeats), so it was dropped: said in the answer, never silently lost. */
1155
+ readonly recurringDropped?: boolean;
1095
1156
  /** Which fields came from `from` because the author left them out. */
1096
- readonly inherited: readonly ("eventDate" | "remind")[];
1157
+ readonly inherited: readonly ("eventDate" | "remind" | "recurring")[];
1097
1158
  /** False only when clearing `from`'s date failed (evented). */
1098
1159
  readonly moved: boolean;
1099
1160
  }
@@ -1103,7 +1164,8 @@ interface ReminderCarryPlan {
1103
1164
  readonly proposal: Proposal;
1104
1165
  /** The dated memory being revised, or null when there is nothing to carry. */
1105
1166
  readonly from: string | null;
1106
- readonly inherited: readonly ("eventDate" | "remind")[];
1167
+ readonly inherited: readonly ("eventDate" | "remind" | "recurring")[];
1168
+ readonly recurringDropped?: boolean;
1107
1169
  }
1108
1170
 
1109
1171
  export interface SweepEntry {
@@ -1776,6 +1838,9 @@ export class Counterpart {
1776
1838
  // through the same one. Then, once per store, the memories written before.
1777
1839
  this.store.findSubjectsWith((text) => this.schemas.subjectsIn(text));
1778
1840
  if (!this.observer) this.backfillSubjects();
1841
+ // Once per store, the links regrown chapter copies were left holding
1842
+ // before a regrowth carried them (2026-10-09).
1843
+ if (!this.observer) this.relinkRegrownCopies();
1779
1844
  // SEAMS H: the REAL battery, so `self/`'s refusing default is unreachable.
1780
1845
  this.self = new Self({
1781
1846
  store: this.store,
@@ -1790,6 +1855,11 @@ export class Counterpart {
1790
1855
  this.relay("self", e);
1791
1856
  },
1792
1857
  onMemoryMinted: (m) => this.creditNamedIn(m.title, m.body, m.day, m.id, "episode"),
1858
+ // SEAMS E once more: a regrown chapter copy inherits its archived copy's
1859
+ // links, as a revision's successor and a dream merge's memory do.
1860
+ retarget: (oldId, newId, day) => {
1861
+ this.associate.retargetOnSupersede(oldId, newId, day);
1862
+ },
1793
1863
  now: this.nowFn,
1794
1864
  ...(opts.selfTunables === undefined ? {} : { tunables: opts.selfTunables }),
1795
1865
  });
@@ -1814,6 +1884,13 @@ export class Counterpart {
1814
1884
  observer: this.observer,
1815
1885
  onEvent: (e) => this.relay("handoff", e),
1816
1886
  now: this.nowFn,
1887
+ // The "since" line beside the pointer (2026-10-09): a confidential
1888
+ // memory named to the owner only, and nothing a later one settled over.
1889
+ owner: this.owner,
1890
+ settled: () => settledOver(this.store),
1891
+ // …and nothing the published wake already lists under "Still open:"
1892
+ // (review of #332): one place for an open question.
1893
+ listed: () => threadsShown(this.store),
1817
1894
  });
1818
1895
  this.spans = new SpanBuffer({
1819
1896
  dir: this.store.dir,
@@ -2074,6 +2151,7 @@ export class Counterpart {
2074
2151
  bytes: i === 0 ? cost - others : own(i),
2075
2152
  session: here?.session ?? null,
2076
2153
  among: rung.live,
2154
+ ...(i === 0 ? { plans: rung.plans.length } : {}),
2077
2155
  });
2078
2156
  });
2079
2157
  } else if (newest !== undefined) {
@@ -2085,7 +2163,11 @@ export class Counterpart {
2085
2163
  // The handoff was carried and the line above it was not.
2086
2164
  this.noteLastHereNoRoom(lastHereId, { budget, was: result.bytes, besideHandoff: true });
2087
2165
  }
2088
- return this.withWorkHere(result, block, work, budget, scope);
2166
+ // A memory the "since" line names is not named again in the work lines
2167
+ // above it (2026-10-09).
2168
+ const named = rung?.plans ?? [];
2169
+ const lines = work.lines.filter((l) => !named.some((id) => l.endsWith(`(${id})`)));
2170
+ return this.withWorkHere(result, block, { lines, found: work.found - (work.lines.length - lines.length) }, budget, scope);
2089
2171
  }
2090
2172
  if (newest !== undefined) this.noteHandoffNoRoom(newest.handoff, smallest?.bytes ?? result.bytes, budget, result.bytes);
2091
2173
  if (lastHere.length > 0) this.noteLastHereNoRoom(lastHereId, { budget, was: result.bytes, besideHandoff: false });
@@ -2683,19 +2765,50 @@ export class Counterpart {
2683
2765
  for (const a of arrived) {
2684
2766
  if (!shown.has(a.memoryId)) continue;
2685
2767
  try {
2686
- this.prospective.fire({
2768
+ const first = this.prospective.occurrenceUndelivered(a.memoryId, a.windowKey);
2769
+ const fired = this.prospective.fire({
2687
2770
  memoryId: a.memoryId,
2688
2771
  windowKey: a.windowKey,
2689
2772
  at,
2690
2773
  day: decision.day,
2691
2774
  sessionId: decision.sessionId,
2692
2775
  });
2776
+ if (fired.fired && first) this.creditOccurrence(a.memoryId, a.windowKey, decision.day, "quiet");
2693
2777
  } catch (err) {
2694
2778
  this.emit("counterpart.prospective.fire.failed", a.memoryId, { code: errCode(err) });
2695
2779
  }
2696
2780
  }
2697
2781
  }
2698
2782
 
2783
+ /**
2784
+ * A REPEAT IS KEPT ALIVE BY COMING ROUND (owner decision 2026-10-09, held
2785
+ * lightly). The first delivery of each occurrence of a repeating date — a
2786
+ * quiet fire the gate admitted, or a plain line the host claimed — counts as
2787
+ * one use of the memory, the way rehearsal keeps a memory: `store.reinforce`,
2788
+ * the seam recall's credit ends in, at the `surfaced` tier. Surfaced and not
2789
+ * referenced: it was shown, nothing says the reply used it, and a schedule
2790
+ * earns no RETURN (`physics#creditReturn` refuses `not-referenced`), so a
2791
+ * daily repeat never walks the core's slow lane on the calendar alone. Once
2792
+ * per occurrence (`Prospective.occurrenceUndelivered`, asked before the
2793
+ * delivery); a one-off date, or a repeat whose `recurring` was dropped, is
2794
+ * never credited here. Physics keeps its own refusals (birth day, already
2795
+ * credited today). Never throws into the turn.
2796
+ */
2797
+ private creditOccurrence(memoryId: string, windowKey: string, day: number, via: "quiet" | "plain"): void {
2798
+ try {
2799
+ const out = this.store.reinforce(memoryId, day, "surfaced");
2800
+ this.emit("counterpart.prospective.occurrence.credited", memoryId, {
2801
+ window: windowKey,
2802
+ via,
2803
+ credited: out.credited,
2804
+ reason: out.reason,
2805
+ day,
2806
+ });
2807
+ } catch (err) {
2808
+ this.emit("counterpart.prospective.occurrence.failed", memoryId, { window: windowKey, code: errCode(err) });
2809
+ }
2810
+ }
2811
+
2699
2812
  /**
2700
2813
  * PLAIN REMINDERS DUE TODAY, NOT YET CLAIMED — a read. The owner-decided
2701
2814
  * exception to "a cue, not a command" (prospective CONTRACT §3): an item its
@@ -2746,10 +2859,12 @@ export class Counterpart {
2746
2859
  claimPlainReminder(reminder: PlainDue, input: { at: string; day?: number }): boolean {
2747
2860
  if (this.observer) return false;
2748
2861
  try {
2749
- return this.prospective.claimPlain(reminder, {
2750
- at: input.at,
2751
- ...(input.day === undefined ? {} : { day: input.day }),
2752
- });
2862
+ const day = input.day ?? this.store.livedDay();
2863
+ // Asked BEFORE the claim, which is itself what would make it false.
2864
+ const first = this.prospective.occurrenceUndelivered(reminder.memoryId, reminder.windowKey);
2865
+ const claimed = this.prospective.claimPlain(reminder, { at: input.at, day });
2866
+ if (claimed && first) this.creditOccurrence(reminder.memoryId, reminder.windowKey, day, "plain");
2867
+ return claimed;
2753
2868
  } catch (err) {
2754
2869
  this.emit("counterpart.prospective.plain.failed", reminder.memoryId, { code: errCode(err) });
2755
2870
  return false;
@@ -2990,6 +3105,16 @@ export class Counterpart {
2990
3105
  ...(input.deadline === undefined ? {} : { deadline: input.deadline }),
2991
3106
  ...(input.now === undefined ? {} : { now: input.now }),
2992
3107
  });
3108
+ // SHOWN, AND NOT USED (2026-10-09). Recall predicts on every turn that what
3109
+ // it shows will help the reply, and until now a miss left no record per
3110
+ // memory. The ambient showings since the last boundary that judged are
3111
+ // scored once, here: used when a reply expanded or quoted them (whether or
3112
+ // not credit then landed), otherwise listed. Measurement only. A boundary
3113
+ // whose slice holds no reply and no expansion judges nothing (review of
3114
+ // #329): a capture that failed or found nothing new is not a reply that
3115
+ // ignored what it was shown.
3116
+ const replied = input.assistantTurns.length > 0 || input.expansions.length > 0;
3117
+ const showings = this.scoreShowings(sessionId, state, refs.uses, day, replied);
2993
3118
  // An expansion is an ADDRESS the assistant typed into a tool call, and a
2994
3119
  // well-shaped address can still name nothing: a typo, or a memory removed
2995
3120
  // since it was footnoted. Physics would throw on it (`requireRow`) and take
@@ -3092,6 +3217,10 @@ export class Counterpart {
3092
3217
  refused,
3093
3218
  ids,
3094
3219
  linkedDespite,
3220
+ shown: showings.shown,
3221
+ unused: showings.unused,
3222
+ shownNotUsed: showings.shownNotUsed,
3223
+ judgedThrough: showings.judgedThrough,
3095
3224
  };
3096
3225
  this.emit("counterpart.credit", sessionId, {
3097
3226
  reason,
@@ -3102,10 +3231,70 @@ export class Counterpart {
3102
3231
  credited,
3103
3232
  linkedDespite,
3104
3233
  pointersExpanded,
3234
+ shown: showings.shown.loud + showings.shown.footnotes + showings.shown.pointers,
3235
+ shownNotUsed: showings.shownNotUsed.length,
3105
3236
  });
3106
3237
  return summary;
3107
3238
  }
3108
3239
 
3240
+ /**
3241
+ * One boundary's score of recall's ambient showings (2026-10-09; Hawkins
3242
+ * "2a", measurement only). The stretch is every memory this session's gate
3243
+ * state records as shown after the session's `judged` mark — loud,
3244
+ * footnoted, or footnoted as a quiet pointer — and the mark then moves to the
3245
+ * session's newest recall turn, so the next boundary scores only what came
3246
+ * after. A showing used at a later boundary than its own is still counted
3247
+ * once as not used here, and then as used there (`expandedIds`, or a quote):
3248
+ * the score is of the reply it was shown for. A deliberate answer's memories
3249
+ * (`asked`) are not ambient and are not in the gate state's `surfaced`.
3250
+ *
3251
+ * Never throws: a mark that cannot be read scores from the session's start,
3252
+ * one that cannot be written is re-scored next time — both say more misses,
3253
+ * never fewer, and neither costs the boundary its credit. Under observer the
3254
+ * mark is not written (an instrument deposits nothing).
3255
+ *
3256
+ * `replied` false (the slice held no reply and no expansion): nothing is
3257
+ * scored and the mark stays, so the showings wait for the first boundary
3258
+ * that read a reply (review of #329).
3259
+ */
3260
+ private scoreShowings(
3261
+ sessionId: string,
3262
+ state: GateState,
3263
+ uses: readonly { memoryId: string }[],
3264
+ day: number,
3265
+ replied: boolean,
3266
+ ): { shown: ShownLanes; unused: ShownLanes; shownNotUsed: string[]; judgedThrough: number } {
3267
+ let from = 0;
3268
+ try {
3269
+ from = judgedThrough(this.store, sessionId);
3270
+ } catch {
3271
+ from = 0;
3272
+ }
3273
+ const used = new Set(uses.map((u) => u.memoryId));
3274
+ const shown = { loud: 0, footnotes: 0, pointers: 0 };
3275
+ const unused = { loud: 0, footnotes: 0, pointers: 0 };
3276
+ const shownNotUsed: { id: string; turn: number }[] = [];
3277
+ if (!replied) return { shown, unused, shownNotUsed: [], judgedThrough: from };
3278
+ for (const [id, rec] of Object.entries(state.surfaced)) {
3279
+ if (rec.turn <= from) continue;
3280
+ const lane = rec.tier === "surfaced" ? "loud" : rec.via === "link" ? "pointers" : "footnotes";
3281
+ shown[lane] += 1;
3282
+ if (used.has(id)) continue;
3283
+ unused[lane] += 1;
3284
+ shownNotUsed.push({ id, turn: rec.turn });
3285
+ }
3286
+ shownNotUsed.sort((a, b) => a.turn - b.turn || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
3287
+ const through = Math.max(from, state.turn);
3288
+ if (through > from && !this.observer) {
3289
+ try {
3290
+ markJudged(this.store, sessionId, through, day);
3291
+ } catch (err) {
3292
+ this.emit("counterpart.credit.judged.failed", sessionId, { code: errCode(err) });
3293
+ }
3294
+ }
3295
+ return { shown, unused, shownNotUsed: shownNotUsed.map((s) => s.id), judgedThrough: through };
3296
+ }
3297
+
3109
3298
  /**
3110
3299
  * THE HEBBIAN HALF OF THE CREDIT PASS — buffered here, written down elsewhere.
3111
3300
  *
@@ -5402,7 +5591,12 @@ export class Counterpart {
5402
5591
  return { ...none(reason, result.gate), malformed: result.malformed };
5403
5592
  }
5404
5593
 
5405
- const carry = this.carryReminder(result.proposal);
5594
+ // THE UPDATE GUARD (2026-10-09), before anything reads the address: a
5595
+ // `changed` or `corrected` at a memory that looks unrelated is HELD. The
5596
+ // proposal goes on without its `updates`, so nothing is linked, carried
5597
+ // over, closed or settled; the hold is recorded and handed back.
5598
+ const held = await this.guardUpdate(result.proposal, ctx);
5599
+ const carry = this.carryReminder(held === null ? result.proposal : withoutUpdates(result.proposal));
5406
5600
  // v12: the writer's three fields, a revision's carried over where unsent.
5407
5601
  const facts = this.carryFacts(carry.proposal, ctx.facts);
5408
5602
  const proposal: Proposal = facts === null ? carry.proposal : { ...carry.proposal, facts: { ...(facts.occurredOn === null ? {} : { occurredOn: facts.occurredOn }), ...(facts.saidBy === null ? {} : { saidBy: facts.saidBy }), ...(facts.status === null ? {} : { status: facts.status }) } };
@@ -5440,6 +5634,7 @@ export class Counterpart {
5440
5634
  // settled at once, and the wake dropped what the deposit said was open.
5441
5635
  const keepOpen = thread?.refused === "confidential" || thread?.refused === "other-directory";
5442
5636
  const revision = this.applyDeclaredRevision(keepOpen ? withoutHow(proposal) : proposal, mint, source, ctx.session);
5637
+ if (held !== null) this.recordHold(held, mint.id, source, ctx, proposal.day);
5443
5638
  return {
5444
5639
  deposited: true,
5445
5640
  reason: "minted",
@@ -5450,11 +5645,143 @@ export class Counterpart {
5450
5645
  covers: proposal.covers,
5451
5646
  ...(reminder === null ? {} : { reminder }),
5452
5647
  ...(revision === null ? {} : { revision }),
5648
+ ...(held === null ? {} : { held }),
5453
5649
  ...(thread === null ? {} : { thread }),
5454
5650
  ...(facts === null ? {} : { facts }),
5455
5651
  };
5456
5652
  }
5457
5653
 
5654
+ /**
5655
+ * THE UPDATE GUARD (2026-10-09): is the memory this write says it changes
5656
+ * or corrects the one it is about? The engine fades or archives on the
5657
+ * writer's word, and a weaker writer points at the wrong one (a 10-02
5658
+ * benchmark read: a Haiku writer, about two thirds of 149 pairs; on the
5659
+ * owner's store, Opus, all 10 checked were right). The pair is read by
5660
+ * `contradictions.ts#updateRelatedness` — by meaning through the local
5661
+ * embedder, by shared content words when there is none — and an unrelated
5662
+ * one comes back as a hold. Null: the declaration goes on as written.
5663
+ *
5664
+ * Only where the write would move the old memory on its word alone:
5665
+ *
5666
+ * - an AUTHOR's `how` of `changed` (said or defaulted) or `corrected` —
5667
+ * `open` moves nothing and stays as it was, and a sweep sends no `how`;
5668
+ * - at an address the author DECLARED and the store resolved — a content
5669
+ * match is the engine's own reading, already held to a score floor and a
5670
+ * margin (`remember/updates.ts`);
5671
+ * - and not a CLOSE or a REDATE (`closesOrRedates`), which acts on that
5672
+ * exact memory by id, usually right after recall showed it, and whose
5673
+ * words ("done") need not share anything with what they close.
5674
+ *
5675
+ * Every door that deposits reaches this, the write-up door and the nightly
5676
+ * catch-up's included: a batch writer has nobody to read the reply, so a
5677
+ * hold there stays a hold, which is the safe side. Never throws: a guard
5678
+ * that cannot read the pair lets the declaration through, as before.
5679
+ */
5680
+ private async guardUpdate(p: Proposal, ctx: DepositContext): Promise<HeldUpdate | null> {
5681
+ const how = p.how;
5682
+ if (how !== "changed" && how !== "corrected") return null;
5683
+ const target = p.updates?.method === "declared" ? p.updates.resolved : null;
5684
+ if (target === null) return null;
5685
+ let row: MemoryRow | undefined;
5686
+ try {
5687
+ row = this.store.row(target);
5688
+ if (row === undefined || this.closesOrRedates(p, target, row, ctx.facts)) return null;
5689
+ } catch {
5690
+ return null;
5691
+ }
5692
+ let overVec: number[] | null = null;
5693
+ let textVec: number[] | null = null;
5694
+ if (this.vectors !== undefined) {
5695
+ try {
5696
+ // The new memory's vector is the gate's, already in the cache; the old
5697
+ // one's is computed here rather than read from box 3, which a backfill
5698
+ // may not have reached and which may hold another model's vectors.
5699
+ textVec = await this.vectors.vector(p.title, p.content);
5700
+ overVec = await this.vectors.vector(row.title, row.body);
5701
+ } catch {
5702
+ textVec = null;
5703
+ overVec = null;
5704
+ }
5705
+ }
5706
+ let ignoreNames: string[] = [];
5707
+ try {
5708
+ // The owner's names: half the store says them, so sharing one says nothing.
5709
+ ignoreNames = ownerNames(this.store);
5710
+ } catch {
5711
+ // No names to set aside: the words read as they are.
5712
+ }
5713
+ const read = updateRelatedness({
5714
+ over: `${row.title ?? ""}\n${row.body}`,
5715
+ text: `${p.title ?? ""}\n${p.content}`,
5716
+ overVec,
5717
+ textVec,
5718
+ ignoreNames,
5719
+ });
5720
+ this.emit("counterpart.update.read", target, {
5721
+ related: read.related,
5722
+ by: read.by,
5723
+ cosine: read.cosine,
5724
+ shared: read.shared.length,
5725
+ how,
5726
+ });
5727
+ if (read.related) return null;
5728
+ const owner = ctx.owner === undefined ? this.owner : ctx.owner && !this.observer;
5729
+ return { over: target, ...heldView(row, owner), how, by: read.by, cosine: read.cosine, shared: read.shared.length };
5730
+ }
5731
+
5732
+ /**
5733
+ * A CLOSE OR A REDATE goes straight through the update guard (2026-10-09):
5734
+ * the write acts on something the memory it names HOLDS, so it is that
5735
+ * memory the writer means.
5736
+ *
5737
+ * - The memory is an OPEN THREAD. Both roads the tools document close one
5738
+ * — `unresolved: false`, or `how: changed` with the answer — and an
5739
+ * answer rarely repeats its question ("which cache?" / "Redis").
5740
+ * - The write sends a reminder field (`eventDate`, a date or null, or
5741
+ * `remind`) and the memory holds a date: a reschedule or a "done".
5742
+ * - The write sends a `status` and the memory has a different one
5743
+ * (planned, now done).
5744
+ *
5745
+ * A field the memory has nothing for — a date on an undated memory, a
5746
+ * status where it had none — dates or describes the NEW memory, and the
5747
+ * guard reads the pair as it would any other.
5748
+ */
5749
+ private closesOrRedates(p: Proposal, target: string, row: MemoryRow, sent: SentFacts | undefined): boolean {
5750
+ try {
5751
+ if (this.store.readProse(target).meta[UNRESOLVED_META_KEY] === true) return true;
5752
+ } catch {
5753
+ // Unreadable prose: no thread this can see.
5754
+ }
5755
+ const intent = p.dateIntent;
5756
+ if (intent !== undefined && (intent.eventDate !== "absent" || intent.remind !== null) && this.reminderHolder(target) !== null) return true;
5757
+ const now = sent?.status ?? null;
5758
+ const was = statusOf(row.status ?? null);
5759
+ return now !== null && was !== null && now !== was;
5760
+ }
5761
+
5762
+ /** The hold's durable row and its in-process event. Telemetry never breaks the door. */
5763
+ private recordHold(held: HeldUpdate, holds: string, source: ProposalSource, ctx: SessionEndDepositContext, day: number): void {
5764
+ const payload = {
5765
+ holds,
5766
+ over: held.over,
5767
+ how: held.how,
5768
+ by: held.by,
5769
+ cosine: held.cosine,
5770
+ shared: held.shared,
5771
+ source,
5772
+ writeUp: ctx.writeUp !== undefined,
5773
+ actor: "session",
5774
+ actorId: ctx.session,
5775
+ day,
5776
+ };
5777
+ this.emit("counterpart.update.held", holds, { over: held.over, how: held.how, by: held.by, cosine: held.cosine, shared: held.shared, source });
5778
+ try {
5779
+ this.store.appendEvent({ name: CONTRADICTION_HELD_EVENT, day, ref: holds, payload });
5780
+ } catch (err) {
5781
+ this.emit("counterpart.update.held.record.failed", holds, { error: errCode(err) });
5782
+ }
5783
+ }
5784
+
5458
5785
  /**
5459
5786
  * THE WRITER'S THREE FIELDS FOR A NEW MEMORY (v12, 2026-10-03): what the
5460
5787
  * writer sent, field by field, and — for a revision of a memory the author
@@ -5574,18 +5901,34 @@ export class Counterpart {
5574
5901
  const priorDate = this.store.row(from)?.event_date ?? null;
5575
5902
  if (priorDate === null) return none;
5576
5903
  let priorMode: "plain" | "quiet" = "quiet";
5904
+ let priorRule: Recurrence | null = null;
5577
5905
  try {
5578
- priorMode = cueModeOf(this.store.readProse(from));
5906
+ const prior = this.store.readProse(from);
5907
+ priorMode = cueModeOf(prior);
5908
+ priorRule = recurrenceOf(prior);
5579
5909
  } catch {
5580
- // Unreadable prose: the date still carries, at the default mode.
5910
+ // Unreadable prose: the date still carries, at the default mode, once.
5581
5911
  }
5582
5912
  const eventDate =
5583
5913
  intent.eventDate === "set" ? p.eventDate : intent.eventDate === "cleared" ? null : priorDate;
5584
5914
  const remind = eventDate === null ? null : intent.remind ?? priorMode;
5585
- const inherited: ("eventDate" | "remind")[] = [];
5915
+ // HOW OFTEN, field by field like the rest (2026-10-09): what the author
5916
+ // sent, `null` for "no longer repeats", else the revised memory's. Only a
5917
+ // day repeats, so a revision that moves the date to a month or a range
5918
+ // leaves it once — the same occurrence keys are what `lineage` counts.
5919
+ const sentRule = intent.recurring ?? null;
5920
+ const wanted = eventDate === null || sentRule === "cleared" ? null : sentRule ?? priorRule;
5921
+ const recurring = wanted !== null && isDay(eventDate) ? wanted : null;
5922
+ const inherited: ("eventDate" | "remind" | "recurring")[] = [];
5586
5923
  if (eventDate !== null && intent.eventDate === "absent") inherited.push("eventDate");
5587
5924
  if (eventDate !== null && intent.remind === null) inherited.push("remind");
5588
- return { proposal: { ...p, eventDate, remind, reminderFrom: from }, from, inherited };
5925
+ if (recurring !== null && sentRule === null) inherited.push("recurring");
5926
+ return {
5927
+ proposal: { ...p, eventDate, remind, recurring, reminderFrom: from },
5928
+ from,
5929
+ inherited,
5930
+ ...(wanted !== null && recurring === null ? { recurringDropped: true } : {}),
5931
+ };
5589
5932
  }
5590
5933
 
5591
5934
  /**
@@ -5642,12 +5985,15 @@ export class Counterpart {
5642
5985
  moved,
5643
5986
  eventDate: carry.proposal.eventDate,
5644
5987
  remind: carry.proposal.remind,
5988
+ recurring: carry.proposal.recurring ?? null,
5645
5989
  inherited: carry.inherited.join(",") || null,
5646
5990
  });
5647
5991
  return {
5648
5992
  from,
5649
5993
  eventDate: carry.proposal.eventDate,
5650
5994
  remind: carry.proposal.remind,
5995
+ recurring: carry.proposal.recurring ?? null,
5996
+ ...(carry.recurringDropped === true ? { recurringDropped: true } : {}),
5651
5997
  inherited: carry.inherited,
5652
5998
  moved,
5653
5999
  };
@@ -6051,6 +6397,88 @@ export class Counterpart {
6051
6397
  }
6052
6398
  }
6053
6399
 
6400
+ /**
6401
+ * THE LINKS REGROWN COPIES WERE LEFT HOLDING, carried once (2026-10-09).
6402
+ * Until then a chapter copy archived `episode-regrown` kept every link it
6403
+ * had learned, and an archived row conducts nothing: the owner's store held
6404
+ * 260 of its 1,200 edge rows on such copies on 10-02. Each copy's links go
6405
+ * to its chapter's live copy (`origin_ref`, the chapter's id) by the rule a
6406
+ * regrowth now uses at the time — `associate.retargetOnSupersede`: the
6407
+ * weight as it stands today, `max`, both ways — so a link that has faded
6408
+ * below the floor since carries nothing. Read from the edge table, so the
6409
+ * pass is as long as the links are, not as long as the store. Latched like
6410
+ * the v12 backfill (its record in meta, read first); idempotent if cut
6411
+ * short; writer-only; fail-open, tried again next open.
6412
+ *
6413
+ * Review of #329: a copy a removal has taken dark carries nothing (its rows
6414
+ * wait for the chase, and must not outlive it on the live copy), and the
6415
+ * reads are one per kind, not one per row: `origin_ref` has no index, and a
6416
+ * `list({ originRef })` per chapter cost 2.3 s of a 2.8 s pass on a
6417
+ * 15k-row store (`store.copiesOf` is the one-scan read the wake uses).
6418
+ */
6419
+ private relinkRegrownCopies(): void {
6420
+ try {
6421
+ if (this.store.getMeta(REGROWN_RELINK_META) !== undefined) return;
6422
+ const started = this.nowFn();
6423
+ const day = this.store.livedDay();
6424
+ const denied = new Set(this.store.deniedIds());
6425
+ const archived = new Set(this.store.list({ type: "memory", archived: true }));
6426
+ let removed = 0;
6427
+ const stale: { id: string; episode: string | null }[] = [];
6428
+ for (const src of new Set(this.store.allEdges().map((e) => e.src))) {
6429
+ if (!archived.has(src)) continue;
6430
+ const row = this.store.row(src);
6431
+ if (row === undefined || row.archived !== 1 || row.archived_reason !== EPISODE_REGROWN_REASON) continue;
6432
+ if (denied.has(src)) {
6433
+ removed += 1;
6434
+ continue;
6435
+ }
6436
+ stale.push({ id: src, episode: row.origin_ref });
6437
+ }
6438
+ // Each chapter's live copy. There is one, unless the chapter's copy was
6439
+ // itself taken out since; were there two, the latest written.
6440
+ const episodes = stale.flatMap((s) => (s.episode === null ? [] : [s.episode]));
6441
+ const held = episodes.length === 0 ? new Map<string, { id: string }[]>() : this.store.copiesOf(episodes);
6442
+ const liveCopy = new Map<string, string | null>();
6443
+ for (const [episode, found] of held) {
6444
+ const ids = found.map((f) => f.id).filter((id) => !denied.has(id));
6445
+ liveCopy.set(
6446
+ episode,
6447
+ ids.length === 0 ? null : ids.reduce((a, b) => ((this.store.row(b)?.created_at ?? 0) > (this.store.row(a)?.created_at ?? 0) ? b : a)),
6448
+ );
6449
+ }
6450
+ let copies = 0;
6451
+ let edges = 0;
6452
+ let noLiveCopy = 0;
6453
+ let failed = 0;
6454
+ for (const { id: src, episode } of stale) {
6455
+ const to = episode === null ? null : (liveCopy.get(episode) ?? null);
6456
+ if (to === null) {
6457
+ noLiveCopy += 1;
6458
+ continue;
6459
+ }
6460
+ const out = this.associate.retargetOnSupersede(src, to, day);
6461
+ // The edge module answers a failed write rather than throwing it.
6462
+ if (out.reason === "failed") {
6463
+ failed += 1;
6464
+ continue;
6465
+ }
6466
+ copies += 1;
6467
+ edges += out.pairs;
6468
+ }
6469
+ this.emit("counterpart.regrown.relink", undefined, { copies, edges, noLiveCopy, removed, failed, day });
6470
+ // A pass a failed write cut short is NOT latched, so the next open tries
6471
+ // again (`max` makes the second carry of what did land a no-op).
6472
+ if (failed > 0) return;
6473
+ this.store.setMeta(
6474
+ REGROWN_RELINK_META,
6475
+ JSON.stringify({ at: this.nowFn(), ms: this.nowFn() - started, day, copies, edges, noLiveCopy, removed }),
6476
+ );
6477
+ } catch (err) {
6478
+ this.emit("counterpart.regrown.relink.failed", undefined, { code: errCode(err) });
6479
+ }
6480
+ }
6481
+
6054
6482
  private emit(
6055
6483
  name: string,
6056
6484
  ref?: string,
@@ -6075,3 +6503,8 @@ function withoutHow(p: Proposal): Proposal {
6075
6503
  void _how;
6076
6504
  return rest as Proposal;
6077
6505
  }
6506
+
6507
+ /** A proposal without its `updates` (a held one, `Counterpart#guardUpdate`): a new memory, linked to nothing. */
6508
+ function withoutUpdates(p: Proposal): Proposal {
6509
+ return { ...withoutHow(p), updates: null };
6510
+ }