counterparts 0.3.0 → 0.3.2

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 (207) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/docs/module-map.md +2 -0
  3. package/package.json +2 -1
  4. package/src/adapters/claude-code/CONTRACT.md +2 -1
  5. package/src/adapters/claude-code/NOTES.md +90 -2
  6. package/src/adapters/claude-code/bin/hook.ts +17 -2
  7. package/src/adapters/claude-code/bin/runner.ts +4 -1
  8. package/src/adapters/claude-code/config.ts +23 -0
  9. package/src/adapters/claude-code/doctor.ts +148 -26
  10. package/src/adapters/claude-code/hooks.ts +37 -12
  11. package/src/adapters/claude-code/index.ts +2 -0
  12. package/src/adapters/claude-code/standdown.ts +12 -1
  13. package/src/adapters/claude-code/transcript.ts +79 -6
  14. package/src/adapters/cli/INTERFACE-GAPS.md +4 -0
  15. package/src/adapters/cli/commands.ts +209 -61
  16. package/src/adapters/cli/export.ts +27 -3
  17. package/src/adapters/cli/help.ts +22 -8
  18. package/src/adapters/cli/install.ts +3 -5
  19. package/src/adapters/cli/mechanisms.ts +295 -0
  20. package/src/adapters/cli/repair-dates.ts +3 -1
  21. package/src/adapters/cli/snapshot.ts +4 -27
  22. package/src/adapters/dashboard/CONTRACT.md +13 -9
  23. package/src/adapters/dashboard/INTERFACE-GAPS.md +4 -0
  24. package/src/adapters/dashboard/NOTES.md +3 -2
  25. package/src/adapters/dashboard/activity.ts +2 -1
  26. package/src/adapters/dashboard/bin/dashboard.ts +18 -3
  27. package/src/adapters/dashboard/upgrade.ts +23 -0
  28. package/src/adapters/dashboard/web/README.md +153 -0
  29. package/src/adapters/dashboard/web/actions.ts +631 -0
  30. package/src/adapters/dashboard/web/app.html +40 -1703
  31. package/src/adapters/dashboard/web/app.js +55 -0
  32. package/src/adapters/dashboard/web/mechanisms/association/index.js +15 -0
  33. package/src/adapters/dashboard/web/mechanisms/association/panel.js +17 -0
  34. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +15 -0
  35. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +23 -0
  36. package/src/adapters/dashboard/web/mechanisms/decay/index.js +15 -0
  37. package/src/adapters/dashboard/web/mechanisms/decay/panel.js +45 -0
  38. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +15 -0
  39. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +15 -0
  40. package/src/adapters/dashboard/web/mechanisms/index.js +60 -0
  41. package/src/adapters/dashboard/web/mechanisms/interference/index.js +15 -0
  42. package/src/adapters/dashboard/web/mechanisms/picture.js +28 -0
  43. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +15 -0
  44. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +15 -0
  45. package/src/adapters/dashboard/web/mechanisms/reconsolidation/panel.js +15 -0
  46. package/src/adapters/dashboard/web/mechanisms/regions.js +30 -0
  47. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +15 -0
  48. package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +20 -0
  49. package/src/adapters/dashboard/web/mechanisms/salience/index.js +15 -0
  50. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +14 -0
  51. package/src/adapters/dashboard/web/mechanisms/schema/index.js +15 -0
  52. package/src/adapters/dashboard/web/narrate.ts +10 -10
  53. package/src/adapters/dashboard/web/pages/flow/flow.css +38 -0
  54. package/src/adapters/dashboard/web/pages/flow/index.js +117 -0
  55. package/src/adapters/dashboard/web/pages/flow/sections/blind.js +12 -0
  56. package/src/adapters/dashboard/web/pages/flow/sections/detail.js +45 -0
  57. package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +291 -0
  58. package/src/adapters/dashboard/web/pages/flow/sections/feed.js +11 -0
  59. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +41 -0
  60. package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +25 -0
  61. package/src/adapters/dashboard/web/pages/flow/sections/records.js +24 -0
  62. package/src/adapters/dashboard/web/pages/flow/sections/symmetry.js +17 -0
  63. package/src/adapters/dashboard/web/pages/flow/state.js +3 -0
  64. package/src/adapters/dashboard/web/pages/health/health.css +93 -0
  65. package/src/adapters/dashboard/web/pages/health/index.js +41 -0
  66. package/src/adapters/dashboard/web/pages/health/sections/archive.js +84 -0
  67. package/src/adapters/dashboard/web/pages/health/sections/checks.js +172 -0
  68. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +37 -0
  69. package/src/adapters/dashboard/web/pages/health/sections/verify.js +54 -0
  70. package/src/adapters/dashboard/web/pages/home/brain.js +375 -0
  71. package/src/adapters/dashboard/web/pages/home/home.css +134 -0
  72. package/src/adapters/dashboard/web/pages/home/index.js +84 -0
  73. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +206 -0
  74. package/src/adapters/dashboard/web/pages/home/sections/hero.js +22 -0
  75. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +25 -0
  76. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +13 -0
  77. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +52 -0
  78. package/src/adapters/dashboard/web/pages/memories/index.js +75 -0
  79. package/src/adapters/dashboard/web/pages/memories/memories.css +143 -0
  80. package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +178 -0
  81. package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +42 -0
  82. package/src/adapters/dashboard/web/pages/memories/sections/list.js +114 -0
  83. package/src/adapters/dashboard/web/pages/memories/sections/search.js +102 -0
  84. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +155 -0
  85. package/src/adapters/dashboard/web/pages/memories/state.js +22 -0
  86. package/src/adapters/dashboard/web/pages/self/diff.js +79 -0
  87. package/src/adapters/dashboard/web/pages/self/index.js +43 -0
  88. package/src/adapters/dashboard/web/pages/self/markdown.js +61 -0
  89. package/src/adapters/dashboard/web/pages/self/sections/journal.js +32 -0
  90. package/src/adapters/dashboard/web/pages/self/sections/page.js +149 -0
  91. package/src/adapters/dashboard/web/pages/self/sections/settling.js +150 -0
  92. package/src/adapters/dashboard/web/pages/self/sections/stories.js +47 -0
  93. package/src/adapters/dashboard/web/pages/self/sections/wake.js +74 -0
  94. package/src/adapters/dashboard/web/pages/self/self.css +182 -0
  95. package/src/adapters/dashboard/web/server.ts +305 -28
  96. package/src/adapters/dashboard/web/shared/absence.js +14 -0
  97. package/src/adapters/dashboard/web/shared/actions.js +48 -0
  98. package/src/adapters/dashboard/web/shared/api.js +17 -0
  99. package/src/adapters/dashboard/web/shared/base.css +34 -0
  100. package/src/adapters/dashboard/web/shared/canvas.js +68 -0
  101. package/src/adapters/dashboard/web/shared/colors.js +6 -0
  102. package/src/adapters/dashboard/web/shared/dom.js +4 -0
  103. package/src/adapters/dashboard/web/shared/event-modal.js +25 -0
  104. package/src/adapters/dashboard/web/shared/fonts/OFL-courier-prime.txt +93 -0
  105. package/src/adapters/dashboard/web/shared/fonts/OFL-outfit.txt +93 -0
  106. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-400.woff2 +0 -0
  107. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-700.woff2 +0 -0
  108. package/src/adapters/dashboard/web/shared/fonts/outfit-latin-wght.woff2 +0 -0
  109. package/src/adapters/dashboard/web/shared/format.js +31 -0
  110. package/src/adapters/dashboard/web/shared/layout.css +32 -0
  111. package/src/adapters/dashboard/web/shared/memory-modal.js +124 -0
  112. package/src/adapters/dashboard/web/shared/modal.css +24 -0
  113. package/src/adapters/dashboard/web/shared/modal.js +22 -0
  114. package/src/adapters/dashboard/web/shared/state.js +12 -0
  115. package/src/adapters/dashboard/web/shared/tip.css +4 -0
  116. package/src/adapters/dashboard/web/shared/tip.js +12 -0
  117. package/src/adapters/dashboard/web/shared/tokens.css +50 -0
  118. package/src/adapters/dashboard/web/shared/type.css +52 -0
  119. package/src/adapters/dashboard/web/shared/utilities.css +5 -0
  120. package/src/adapters/dashboard/web/shared/vendor/MIT-three.txt +21 -0
  121. package/src/adapters/dashboard/web/shared/vendor/three.module.min.js +6 -0
  122. package/src/adapters/dashboard/web/shared/widgets/bar.css +9 -0
  123. package/src/adapters/dashboard/web/shared/widgets/card.css +6 -0
  124. package/src/adapters/dashboard/web/shared/widgets/chapters.js +15 -0
  125. package/src/adapters/dashboard/web/shared/widgets/chart.css +4 -0
  126. package/src/adapters/dashboard/web/shared/widgets/confirm.css +31 -0
  127. package/src/adapters/dashboard/web/shared/widgets/confirm.js +52 -0
  128. package/src/adapters/dashboard/web/shared/widgets/feed.css +13 -0
  129. package/src/adapters/dashboard/web/shared/widgets/feed.js +41 -0
  130. package/src/adapters/dashboard/web/shared/widgets/light.css +4 -0
  131. package/src/adapters/dashboard/web/shared/widgets/light.js +15 -0
  132. package/src/adapters/dashboard/web/shared/widgets/rows.css +7 -0
  133. package/src/adapters/dashboard/web/shared/widgets/table.css +17 -0
  134. package/src/adapters/dashboard/web/shared/widgets/tiles.css +14 -0
  135. package/src/adapters/dashboard/web/shell/pages.js +15 -0
  136. package/src/adapters/dashboard/web/shell/pulse.js +86 -0
  137. package/src/adapters/dashboard/web/shell/tabs.js +49 -0
  138. package/src/adapters/dashboard/web/static.ts +76 -0
  139. package/src/adapters/dashboard/web/views/activity.ts +80 -0
  140. package/src/adapters/dashboard/web/views/archive-words.ts +57 -0
  141. package/src/adapters/dashboard/web/views/flow-view.ts +217 -0
  142. package/src/adapters/dashboard/web/views/health.ts +328 -0
  143. package/src/adapters/dashboard/web/views/mechanism-panel.ts +370 -0
  144. package/src/adapters/dashboard/web/views/mechanisms.ts +302 -0
  145. package/src/adapters/dashboard/web/views/memories.ts +342 -0
  146. package/src/adapters/dashboard/web/views/memory.ts +210 -0
  147. package/src/adapters/dashboard/web/views/meta.ts +64 -0
  148. package/src/adapters/dashboard/web/views/mind.ts +729 -0
  149. package/src/adapters/dashboard/web/views/overview.ts +282 -0
  150. package/src/adapters/dashboard/web/views/pulse.ts +19 -0
  151. package/src/adapters/dashboard/web/views/rows.ts +207 -0
  152. package/src/adapters/dashboard/web/views/search.ts +62 -0
  153. package/src/adapters/dashboard/web/views/shared.ts +161 -0
  154. package/src/adapters/dashboard/web/views.ts +34 -1724
  155. package/src/adapters/fired.ts +138 -31
  156. package/src/adapters/mcp/INTERFACE-GAPS.md +4 -1
  157. package/src/adapters/mcp/NOTES.md +43 -0
  158. package/src/adapters/mcp/bin/serve.ts +9 -1
  159. package/src/adapters/mcp/index.ts +7 -0
  160. package/src/adapters/mcp/server.ts +167 -6
  161. package/src/adapters/mcp/tools.ts +42 -0
  162. package/src/adapters/mcp/write-up.ts +1 -1
  163. package/src/adapters/sessions.ts +18 -1
  164. package/src/adapters/snapshots.ts +71 -39
  165. package/src/core/associate/INTERFACE-GAPS.md +8 -0
  166. package/src/core/counterpart.ts +86 -7
  167. package/src/core/encode/INTERFACE-GAPS.md +12 -0
  168. package/src/core/feelings-wheel.ts +218 -0
  169. package/src/core/handoff/INTERFACE-GAPS.md +2 -0
  170. package/src/core/mint.ts +14 -2
  171. package/src/core/prospective/INTERFACE-GAPS.md +14 -0
  172. package/src/core/prospective/windows.ts +10 -48
  173. package/src/core/recall/INTERFACE-GAPS.md +6 -0
  174. package/src/core/remember/INTERFACE-GAPS.md +10 -0
  175. package/src/core/schemas/INTERFACE-GAPS.md +8 -0
  176. package/src/core/schemas/NOTES.md +118 -1
  177. package/src/core/schemas/index.ts +330 -40
  178. package/src/core/schemas/tunables.ts +23 -0
  179. package/src/core/schemas/types.ts +64 -1
  180. package/src/core/self/CONTRACT.md +3 -0
  181. package/src/core/self/INTERFACE-GAPS.md +10 -0
  182. package/src/core/self/NOTES.md +33 -2
  183. package/src/core/self/calendar.ts +7 -78
  184. package/src/core/self/episodes.ts +52 -12
  185. package/src/core/self/index.ts +40 -12
  186. package/src/core/self/writer.ts +22 -22
  187. package/src/core/sleep/NOTES.md +36 -0
  188. package/src/core/sleep/cycle.ts +38 -3
  189. package/src/core/sleep/fade.ts +76 -0
  190. package/src/core/sleep/index.ts +4 -1
  191. package/src/core/sleep/prune.ts +8 -1
  192. package/src/core/sleep/tunables.ts +5 -0
  193. package/src/core/sleep/types.ts +24 -0
  194. package/src/core/store/CONTRACT.md +36 -7
  195. package/src/core/store/NOTES.md +197 -0
  196. package/src/core/store/errors.ts +22 -0
  197. package/src/core/store/feelings.ts +182 -0
  198. package/src/core/store/index.ts +339 -45
  199. package/src/core/store/operational.ts +240 -22
  200. package/src/core/store/owner-op-seam.ts +13 -3
  201. package/src/core/store/paths.ts +15 -1
  202. package/src/core/store/pre-migration.ts +258 -0
  203. package/src/core/store/prose.ts +8 -1
  204. package/src/core/store/render.ts +3 -0
  205. package/src/core/time.ts +374 -0
  206. package/src/core/types.ts +13 -0
  207. package/src/adapters/dashboard/web/brain.html +0 -463
@@ -76,10 +76,13 @@ import type {
76
76
  EntityView,
77
77
  FadeReason,
78
78
  FadeReport,
79
+ FadeSweepOptions,
79
80
  FadeVerdict,
80
81
  LifecycleRow,
81
82
  LineageStep,
82
83
  MentionInput,
84
+ NamedInTextInput,
85
+ NamedInTextReport,
83
86
  PlacementOutcome,
84
87
  PlacementReason,
85
88
  PressureIncrement,
@@ -107,6 +110,7 @@ export { TUNABLES } from "./tunables.js";
107
110
  export const PUBLIC_SURFACE = [
108
111
  // writes
109
112
  "mention",
113
+ "creditNamedIn",
110
114
  "addAliases",
111
115
  "addBelief",
112
116
  "addCurrentState",
@@ -164,6 +168,8 @@ const ZERO_DIMS: DimensionsInput = { relevance: 0, emotional: 0, predictive: 0 }
164
168
  export class Schemas {
165
169
  readonly store: Store;
166
170
  private readonly index = new AliasIndex();
171
+ /** Cards the fade archived, by their handles, so a saved memory naming one can bring it back (NOTES §15). */
172
+ private readonly faded = new AliasIndex();
167
173
  private readonly meta = new Map<string, MetaRecord>();
168
174
  private readonly byEntity = new Map<string, Set<string>>();
169
175
  private readonly birthsPerChunk = new Map<string, number>();
@@ -224,6 +230,8 @@ export class Schemas {
224
230
  this.remember(id, rec);
225
231
  if (rec.role === "entity" && row.archived === 0) {
226
232
  this.index.register(id, rec.name ?? "", rec.aliases ?? []);
233
+ } else if (rec.role === "entity" && row.archived_reason === TUNABLES.FADE_REASON) {
234
+ this.faded.register(id, rec.name ?? "", rec.aliases ?? []);
227
235
  }
228
236
  }
229
237
  }
@@ -289,24 +297,7 @@ export class Schemas {
289
297
  aliasesDeclared: input.aliases?.length ?? 0,
290
298
  });
291
299
 
292
- const refuse = (reason: BirthReason, collidedWith: string[] = []): BirthOutcome => {
293
- this.emit("schema.birth.refused", input.chunkRef, {
294
- nameHash,
295
- kind: input.kind,
296
- reason,
297
- collided: collidedWith.length,
298
- });
299
- return {
300
- ok: false,
301
- reason,
302
- id: null,
303
- born: false,
304
- collidedWith,
305
- droppedAliases: [],
306
- keptAliases: [],
307
- reinforced: false,
308
- };
309
- };
300
+ const refuse = (reason: BirthReason): BirthOutcome => this.refuseBirth(input, nameHash, reason);
310
301
 
311
302
  // Layer 1 of "never a second self", checked FIRST and independently of every
312
303
  // other ground: one identity core, and a second is a category error no
@@ -319,47 +310,229 @@ export class Schemas {
319
310
  // The ONE whole-word rule, the same call preselection makes (SEAMS §7).
320
311
  if (!occursAsWholeWord(input.source, name)) return refuse("name-not-in-source");
321
312
 
322
- const exact = this.index.lookup(name).filter((id) => this.meta.get(id)?.role === "entity");
323
- if (exact.length > 1) return refuse("ambiguous-existing-name", exact);
313
+ return this.settle(name, input.kind, input, nameHash, true);
314
+ }
315
+
316
+ /**
317
+ * What a mention does once its name is admitted: the existing card, a
318
+ * refusal, or a birth. Shared by the title path and a body mention of a
319
+ * faded card, so both bring a card back the same way. A revival skips the
320
+ * per-chunk cap — it brings back a card that existed rather than inventing one.
321
+ */
322
+ private settle(
323
+ name: string,
324
+ kind: BirthKind,
325
+ input: MentionInput,
326
+ nameHash: string,
327
+ capped: boolean,
328
+ ): BirthOutcome {
329
+ const exact = this.liveHolders(name);
330
+ if (exact.length > 1) return this.refuseBirth(input, nameHash, "ambiguous-existing-name", exact);
324
331
  const hit = exact[0];
325
332
  if (hit !== undefined) {
326
333
  const row = this.store.row(hit);
327
334
  // Layer 2: a name that resolves to the identity core is not a birth site,
328
335
  // whatever kind the mention claimed.
329
- if (row?.kind === "self") return refuse("second-self-refused", [hit]);
330
- if (row !== undefined && row.kind !== input.kind) {
331
- return refuse("collision-exact-different-kind", [hit]);
336
+ if (row?.kind === "self") return this.refuseBirth(input, nameHash, "second-self-refused", [hit]);
337
+ if (row !== undefined && row.kind !== kind) {
338
+ return this.refuseBirth(input, nameHash, "collision-exact-different-kind", [hit]);
332
339
  }
333
340
  return this.reMention(hit, input, nameHash);
334
341
  }
335
342
 
336
343
  const near = this.nearCollisions(name);
337
- if (near.length > 0) return refuse("collision-near", near);
344
+ if (near.length > 0) return this.refuseBirth(input, nameHash, "collision-near", near);
338
345
 
339
346
  const used = this.birthsPerChunk.get(input.chunkRef) ?? 0;
340
- if (used >= TUNABLES.MAX_BIRTHS_PER_CHUNK) return refuse("birth-cap-per-chunk");
347
+ if (capped && used >= TUNABLES.MAX_BIRTHS_PER_CHUNK) {
348
+ return this.refuseBirth(input, nameHash, "birth-cap-per-chunk");
349
+ }
350
+
351
+ return this.birth(name, kind, input, nameHash);
352
+ }
353
+
354
+ private refuseBirth(
355
+ input: MentionInput,
356
+ nameHash: string,
357
+ reason: BirthReason,
358
+ collidedWith: string[] = [],
359
+ ): BirthOutcome {
360
+ this.emit("schema.birth.refused", input.chunkRef, {
361
+ nameHash,
362
+ kind: input.kind,
363
+ reason,
364
+ collided: collidedWith.length,
365
+ });
366
+ return {
367
+ ok: false,
368
+ reason,
369
+ id: null,
370
+ born: false,
371
+ collidedWith,
372
+ droppedAliases: [],
373
+ keptAliases: [],
374
+ reinforced: false,
375
+ };
376
+ }
377
+
378
+ /**
379
+ * The live cards a handle resolves to. More than one is an ambiguous handle,
380
+ * and both callers credit none of them.
381
+ */
382
+ private liveHolders(term: string): string[] {
383
+ return this.index
384
+ .lookup(term)
385
+ .filter((id) => this.meta.get(id)?.role === "entity" && !this.fadedElsewhere(id));
386
+ }
387
+
388
+ /**
389
+ * A saved memory that names a card in its title or body counts as that card
390
+ * being used (NOTES §15). A live card is credited; a card the fade archived
391
+ * comes back the way a title mention brings it back — a fresh birth tagged
392
+ * `schema.birth.after-fade` — carrying its old name and aliases. Nothing that
393
+ * never existed is born, and a card pruned or removed stays gone. A handle
394
+ * held by two cards, live or faded, credits and revives neither; the identity
395
+ * core is left alone. Physics' once-per-lived-day rule applies as for any use.
396
+ */
397
+ creditNamedIn(input: NamedInTextInput): NamedInTextReport {
398
+ const report: NamedInTextReport = { credited: [], refused: [], revived: [], ambiguous: 0 };
399
+ if (input.text.trim().length === 0) return report;
400
+ const except = new Set(input.except ?? []);
401
+ // Live terms first: a card faded by another process moves to `faded` on its
402
+ // first lookup, so the faded pass below can see it.
403
+ const terms = new Map<string, string>();
404
+ for (const hit of this.index.matchesIn(input.text)) {
405
+ this.liveHolders(hit.term);
406
+ terms.set(handleKey(hit.term), hit.term);
407
+ }
408
+ for (const hit of this.faded.matchesIn(input.text)) terms.set(handleKey(hit.term), hit.term);
409
+
410
+ const named = new Set<string>();
411
+ const fading = new Set<string>();
412
+ let denied: Set<string> | undefined;
413
+ const removedIds = (): Set<string> => (denied ??= new Set(this.store.deniedIds()));
414
+ for (const [key, term] of terms) {
415
+ if (key.length < TUNABLES.NAME_MIN_CHARS) continue;
416
+ const live = this.liveHolders(term);
417
+ const faded = this.fadedHolders(term, removedIds);
418
+ if (live.length + faded.length > 1) {
419
+ report.ambiguous += 1;
420
+ continue;
421
+ }
422
+ if (live[0] !== undefined) named.add(live[0]);
423
+ if (faded[0] !== undefined) fading.add(faded[0]);
424
+ }
425
+
426
+ for (const id of [...named].sort()) {
427
+ if (except.has(id) || this.store.row(id)?.kind === "self") continue;
428
+ const credit = this.store.reinforce(id, input.day, TUNABLES.MENTION_TIER);
429
+ (credit.credited ? report.credited : report.refused).push(id);
430
+ this.emit("schema.mention.named", id, {
431
+ day: input.day,
432
+ ref: input.ref,
433
+ credited: credit.credited,
434
+ creditReason: credit.reason,
435
+ });
436
+ }
437
+ for (const priorId of [...fading].sort()) {
438
+ const out = this.revive(priorId, input);
439
+ if (out === null) continue;
440
+ if (out.born) report.revived.push(out.id as string);
441
+ else if (out.reason === "existing") (out.reinforced ? report.credited : report.refused).push(out.id as string);
442
+ }
443
+ return report;
444
+ }
445
+
446
+ /**
447
+ * The faded cards a handle names, one per name. A faded card whose name a
448
+ * live card now holds is that card's past life, not a second holder. Of
449
+ * several faded cards with one name, the latest-born speaks for them.
450
+ */
451
+ private fadedHolders(term: string, removedIds: () => Set<string>): string[] {
452
+ const ids = this.faded.lookup(term);
453
+ if (ids.length === 0) return [];
454
+ const denied = removedIds();
455
+ const byName = new Map<string, { id: string; birth: number }>();
456
+ for (const id of ids) {
457
+ const rec = this.meta.get(id);
458
+ const row = this.store.row(id);
459
+ if (rec === undefined || row === undefined || row.archived !== 1 || this.removed(id, row, denied)) {
460
+ this.faded.unregister(id);
461
+ continue;
462
+ }
463
+ const key = handleKey(rec.name ?? "");
464
+ if (this.liveHolders(rec.name ?? "").some((l) => handleKey(this.meta.get(l)?.name ?? "") === key)) continue;
465
+ const prev = byName.get(key);
466
+ if (prev === undefined || row.birth_day > prev.birth || (row.birth_day === prev.birth && id > prev.id)) {
467
+ byName.set(key, { id, birth: row.birth_day });
468
+ }
469
+ }
470
+ return [...byName.values()].map((v) => v.id).sort();
471
+ }
341
472
 
342
- return this.birth(name, input.kind, input, nameHash);
473
+ /**
474
+ * Bring a faded card back through the title path's own birth. Its old aliases
475
+ * come along: they passed the gate when declared, so the old card's handles
476
+ * are the source they are checked against here.
477
+ */
478
+ private revive(priorId: string, input: NamedInTextInput): BirthOutcome | null {
479
+ const rec = this.meta.get(priorId);
480
+ const kind = this.store.row(priorId)?.kind;
481
+ if (rec === undefined || kind === undefined || !isBirthKind(kind)) return null;
482
+ const name = rec.name ?? "";
483
+ const aliases = rec.aliases ?? [];
484
+ const out = this.settle(
485
+ name,
486
+ kind,
487
+ { name, kind, source: [name, ...aliases].join("\n"), chunkRef: input.ref, aliases, day: input.day },
488
+ hashText(handleKey(name)),
489
+ false,
490
+ );
491
+ this.emit("schema.mention.revived", out.id ?? priorId, {
492
+ day: input.day,
493
+ ref: input.ref,
494
+ priorId,
495
+ reason: out.reason,
496
+ });
497
+ return out;
343
498
  }
344
499
 
345
- /** An archived entity that held this exact name before it faded, if any. */
500
+ /** An entity archived by the fade (not pruned) that held this exact name, if any. */
346
501
  private fadedNamed(name: string, except: string): string | undefined {
347
502
  const key = handleKey(name);
348
503
  for (const [id, rec] of this.meta) {
349
504
  if (id === except || rec.role !== "entity") continue;
350
505
  if (handleKey(rec.name ?? "") !== key) continue;
351
- if (this.store.row(id)?.archived === 1) return id;
506
+ const row = this.store.row(id);
507
+ if (row?.archived === 1 && row.archived_reason === TUNABLES.FADE_REASON) return id;
352
508
  }
353
509
  return undefined;
354
510
  }
355
511
 
512
+ /**
513
+ * An indexed card whose row is archived — faded (or pruned) by a sleep cycle
514
+ * in ANOTHER process, which this long-lived index could not hear about. It is
515
+ * dropped from the index here, so a mention of the name is a fresh birth
516
+ * rather than a reinforcement of a card nothing surfaces (NOTES §14).
517
+ */
518
+ private fadedElsewhere(id: string): boolean {
519
+ const row = this.store.row(id);
520
+ if (row?.archived !== 1) return false;
521
+ this.index.unregister(id);
522
+ const rec = this.meta.get(id);
523
+ if (rec !== undefined && row.archived_reason === TUNABLES.FADE_REASON) {
524
+ this.faded.register(id, rec.name ?? "", rec.aliases ?? []);
525
+ }
526
+ return true;
527
+ }
528
+
356
529
  private nearCollisions(name: string): string[] {
357
530
  const out: string[] = [];
358
531
  for (const [id, rec] of this.meta) {
359
532
  if (rec.role !== "entity") continue;
360
533
  if (!this.index.has(id)) continue;
361
534
  const terms = [rec.name ?? "", ...(rec.aliases ?? [])];
362
- if (terms.some((t) => collision(name, t) === "near")) out.push(id);
535
+ if (terms.some((t) => collision(name, t) === "near") && !this.fadedElsewhere(id)) out.push(id);
363
536
  }
364
537
  return out.sort();
365
538
  }
@@ -1032,11 +1205,13 @@ export class Schemas {
1032
1205
 
1033
1206
  /**
1034
1207
  * Would this entity fade today, and if not, why not — EVERY reason, not the
1035
- * first (§5 G7). Death is decay: physics decides, and this module adds one
1036
- * blocker of its own, because an entity with live beliefs or live status is a
1037
- * place memories are still attached to (open question 1; NOTES §5).
1208
+ * first (§5 G7). Death is decay: physics must say prunable, and this module
1209
+ * adds blockers of its own — an entity with live beliefs or live status is a
1210
+ * place memories are still attached to (open question 1; NOTES §5), and a card
1211
+ * fades gently: a calendar floor, and longer floors for people (NOTES §14).
1212
+ * `date` is the calendar day the floors are counted to.
1038
1213
  */
1039
- fadeVerdict(id: string, day: number): FadeVerdict {
1214
+ fadeVerdict(id: string, day: number, date: string = this.store.today()): FadeVerdict {
1040
1215
  const row = this.store.row(id);
1041
1216
  const rec = this.meta.get(id);
1042
1217
  if (row === undefined || rec === undefined || rec.role !== "entity") {
@@ -1050,9 +1225,15 @@ export class Schemas {
1050
1225
  band: "episodic",
1051
1226
  dwellDays: 0,
1052
1227
  attached: 0,
1228
+ livedFloorDays: 0,
1229
+ calendarDays: 0,
1230
+ calendarSource: "lived-days",
1231
+ calendarFloorDays: 0,
1053
1232
  };
1054
1233
  }
1055
1234
  const p = this.store.physicsOf(id);
1235
+ const floors = fadeFloors(row.kind);
1236
+ const calendar = this.calendarDaysSinceUse(id, row, p, day, date);
1056
1237
  if (row.archived === 1) {
1057
1238
  return {
1058
1239
  fade: false,
@@ -1062,6 +1243,10 @@ export class Schemas {
1062
1243
  band: bandOfPhysics(p, day),
1063
1244
  dwellDays: day - p.lastUsedDay,
1064
1245
  attached: this.liveElementIds(id).length,
1246
+ livedFloorDays: floors.lived,
1247
+ calendarDays: calendar.days,
1248
+ calendarSource: calendar.source,
1249
+ calendarFloorDays: floors.calendar,
1065
1250
  };
1066
1251
  }
1067
1252
  const v = pruneVerdict(p, day, { inLiveRevisionChain: false });
@@ -1072,6 +1257,13 @@ export class Schemas {
1072
1257
  (r): r is Exclude<typeof r, "prunable"> => r !== "prunable",
1073
1258
  );
1074
1259
  if (attached > 0) blockedBy.push("has-live-attached-elements");
1260
+ if (row.kind === "self") blockedBy.push("identity-core");
1261
+ // Gentle fading (NOTES §14): physics' verdict is necessary, not sufficient.
1262
+ // A kind can ask for more lived quiet, and every card needs calendar quiet.
1263
+ if (v.dwellDays >= PHYSICS_TUNABLES.D_FLOOR_DAYS && v.dwellDays < floors.lived) {
1264
+ blockedBy.push("kind-dwell-too-short");
1265
+ }
1266
+ if (calendar.days < floors.calendar) blockedBy.push("calendar-floor-not-passed");
1075
1267
  return {
1076
1268
  fade: blockedBy.length === 0,
1077
1269
  reason: blockedBy[0] ?? "faded",
@@ -1080,37 +1272,118 @@ export class Schemas {
1080
1272
  band: v.band,
1081
1273
  dwellDays: v.dwellDays,
1082
1274
  attached,
1275
+ livedFloorDays: floors.lived,
1276
+ calendarDays: calendar.days,
1277
+ calendarSource: calendar.source,
1278
+ calendarFloorDays: floors.calendar,
1279
+ };
1280
+ }
1281
+
1282
+ /**
1283
+ * Calendar days since this card was last used, as a LOWER BOUND.
1284
+ *
1285
+ * The store keeps last use as a LIVED day only, so the calendar side is
1286
+ * rebuilt from three facts, each of which can only undercount:
1287
+ * - the lived-day gap itself — every lived day is a distinct date;
1288
+ * - the birth date (`learned_on`), when birth was the last use;
1289
+ * - the sweep's anchor, `{ day, date }`, when the card has not been used
1290
+ * since that lived day (an anchor older than the last use is ignored).
1291
+ * The largest wins. Undercounting only ever makes a card fade LATER.
1292
+ */
1293
+ private calendarDaysSinceUse(
1294
+ id: string,
1295
+ row: MemoryRow,
1296
+ p: MemoryPhysics,
1297
+ day: number,
1298
+ date: string,
1299
+ ): { days: number; source: FadeVerdict["calendarSource"] } {
1300
+ let best: { days: number; source: FadeVerdict["calendarSource"] } = {
1301
+ days: Math.max(0, day - p.lastUsedDay),
1302
+ source: "lived-days",
1303
+ };
1304
+ const consider = (from: string, source: FadeVerdict["calendarSource"]): void => {
1305
+ const d = calendarDaysBetween(from, date);
1306
+ if (d !== null && d > best.days) best = { days: d, source };
1083
1307
  };
1308
+ if (p.lastUsedDay === row.birth_day) consider(row.learned_on, "birth-date");
1309
+ const anchor = this.fadeAnchor(id);
1310
+ if (anchor !== null && anchor.day >= p.lastUsedDay) consider(anchor.date, "anchor");
1311
+ return best;
1312
+ }
1313
+
1314
+ private fadeAnchor(id: string): { day: number; date: string } | null {
1315
+ const raw = this.store.getMeta(`${TUNABLES.FADE_ANCHOR_PREFIX}${id}`);
1316
+ if (raw === undefined) return null;
1317
+ try {
1318
+ const v = JSON.parse(raw) as { day?: unknown; date?: unknown };
1319
+ if (typeof v.day !== "number" || typeof v.date !== "string") return null;
1320
+ return { day: v.day, date: v.date };
1321
+ } catch {
1322
+ return null;
1323
+ }
1084
1324
  }
1085
1325
 
1086
1326
  /**
1087
1327
  * The sweep. Archive is a STATE, not a deletion: a faded entity keeps its id,
1088
1328
  * stays resolvable, and simply stops surfacing (§4.2 G3). No model, on any
1089
- * path, holds this power — it is arithmetic on a lived day.
1329
+ * path, holds this power — it is arithmetic on a lived day and a date.
1330
+ *
1331
+ * `sleep/` calls it on its own cadence (INTERFACE-GAPS §6). Along the way it
1332
+ * writes a calendar anchor for every live card that has none, or has been used
1333
+ * since its last one — that is how "calendar days since last use" becomes
1334
+ * knowable without a column for it (NOTES §14). A dry run writes nothing.
1090
1335
  */
1091
- fadeSweep(day: number): FadeReport {
1336
+ fadeSweep(day: number, opts: FadeSweepOptions = {}): FadeReport {
1337
+ const date = opts.date ?? this.store.today();
1338
+ const dryRun = opts.dryRun === true;
1339
+ const limit = opts.limit ?? Number.POSITIVE_INFINITY;
1092
1340
  const faded: string[] = [];
1341
+ const blocked: Record<string, number> = {};
1342
+ const anchors: [string, string][] = [];
1093
1343
  let examined = 0;
1344
+ let skippedForLimit = 0;
1094
1345
  for (const [id, rec] of this.meta) {
1095
1346
  if (rec.role !== "entity") continue;
1096
1347
  const row = this.store.row(id);
1097
1348
  if (row === undefined || row.archived === 1) continue;
1349
+ if (examined >= limit) {
1350
+ skippedForLimit += 1;
1351
+ continue;
1352
+ }
1098
1353
  examined += 1;
1099
- const v = this.fadeVerdict(id, day);
1100
- if (!v.fade) continue;
1354
+ const v = this.fadeVerdict(id, day, date);
1355
+ if (!v.fade) {
1356
+ for (const r of v.blockedBy) blocked[r] = (blocked[r] ?? 0) + 1;
1357
+ const anchor = this.fadeAnchor(id);
1358
+ if (anchor === null || anchor.day < row.last_used_day) {
1359
+ anchors.push([`${TUNABLES.FADE_ANCHOR_PREFIX}${id}`, JSON.stringify({ day, date })]);
1360
+ }
1361
+ continue;
1362
+ }
1363
+ faded.push(id);
1364
+ if (dryRun) continue;
1101
1365
  this.store.archive(id, TUNABLES.FADE_REASON);
1102
1366
  this.index.unregister(id);
1103
- faded.push(id);
1367
+ this.faded.register(id, rec.name ?? "", rec.aliases ?? []);
1104
1368
  this.emit("schema.faded", id, {
1105
1369
  day,
1106
1370
  kind: row.kind,
1107
1371
  strength: v.strength,
1108
1372
  dwellDays: v.dwellDays,
1373
+ calendarDays: v.calendarDays,
1109
1374
  birthDay: row.birth_day,
1110
1375
  });
1111
1376
  }
1112
- this.emit("schema.fade.sweep", undefined, { day, examined, faded: faded.length });
1113
- return { day, examined, faded };
1377
+ if (!dryRun && anchors.length > 0) this.store.setMetaMany(anchors);
1378
+ const anchored = dryRun ? 0 : anchors.length;
1379
+ this.emit("schema.fade.sweep", undefined, {
1380
+ day,
1381
+ examined,
1382
+ faded: faded.length,
1383
+ anchored,
1384
+ dryRun,
1385
+ });
1386
+ return { day, date, dryRun, examined, faded, blocked, anchored, skippedForLimit };
1114
1387
  }
1115
1388
 
1116
1389
  // ── reads ──────────────────────────────────────────────────────────────────
@@ -1457,3 +1730,20 @@ function toMetaRecord(meta: Record<string, unknown>): MetaRecord | null {
1457
1730
  if (typeof meta["statedOnDay"] === "number") rec.statedOnDay = meta["statedOnDay"];
1458
1731
  return rec;
1459
1732
  }
1733
+
1734
+ /** The lived and calendar floors a card of this kind must pass to fade (NOTES §14). */
1735
+ function fadeFloors(kind: Kind): { lived: number; calendar: number } {
1736
+ const factor = TUNABLES.FADE.LIVED_DWELL_FACTOR_BY_KIND[kind] ?? 1;
1737
+ return {
1738
+ lived: Math.ceil(PHYSICS_TUNABLES.D_FLOOR_DAYS * factor),
1739
+ calendar: TUNABLES.FADE.CALENDAR_FLOOR_DAYS_BY_KIND[kind] ?? TUNABLES.FADE.CALENDAR_FLOOR_DAYS,
1740
+ };
1741
+ }
1742
+
1743
+ /** Whole calendar days from one `YYYY-MM-DD` to another; null when either is unreadable. */
1744
+ function calendarDaysBetween(from: string, to: string): number | null {
1745
+ const a = Date.parse(`${from.slice(0, 10)}T00:00:00Z`);
1746
+ const b = Date.parse(`${to.slice(0, 10)}T00:00:00Z`);
1747
+ if (!Number.isFinite(a) || !Number.isFinite(b)) return null;
1748
+ return Math.round((b - a) / 86_400_000);
1749
+ }
@@ -7,6 +7,8 @@
7
7
  * from intuition and was inert because arbitrary same-corpus pairs already sat
8
8
  * at 0.576).
9
9
  */
10
+ import type { Kind } from "../types.js";
11
+
10
12
  export const TUNABLES = {
11
13
  /**
12
14
  * CAL. Near collision is TOKEN CONTAINMENT: "Mike" against "Mike Chen".
@@ -33,6 +35,27 @@ export const TUNABLES = {
33
35
  /** Why an entity's archive row says it left. One string, one meaning. */
34
36
  FADE_REASON: "faded-by-decay" as const,
35
37
 
38
+ /**
39
+ * How gently an entity card fades (owner, 2026-09-24: "don't fade people away
40
+ * too quickly"). A card fades only when physics says the row is prunable AND
41
+ * these floors have passed too. Experimental defaults, not measured; NOTES §14.
42
+ */
43
+ FADE: {
44
+ /** Calendar days since the card was last used before it may fade. Lived days
45
+ * alone are too fast for someone who uses the tool every day. */
46
+ CALENDAR_FLOOR_DAYS: 180,
47
+ /** Per-kind calendar floor, where a kind wants a slower one. A person you
48
+ * have not talked about in half a year is still someone you know. */
49
+ CALENDAR_FLOOR_DAYS_BY_KIND: { person: 365 } as Readonly<Partial<Record<Kind, number>>>,
50
+ /** Multiplies physics' lived-day dwell (`D_FLOOR_DAYS`) per kind. People get
51
+ * twice the lived quiet a project does before they can fade. */
52
+ LIVED_DWELL_FACTOR_BY_KIND: { person: 2 } as Readonly<Partial<Record<Kind, number>>>,
53
+ },
54
+
55
+ /** Box-2 meta key prefix for a card's calendar anchor (`{ day, date }`): a
56
+ * lived day and the calendar date the fade sweep saw it on. NOTES §14. */
57
+ FADE_ANCHOR_PREFIX: "schemas.fade.anchor." as const,
58
+
36
59
  /** What the versions row says when a belief fell to accumulated pressure. */
37
60
  REVISED_REASON: "revised-by-pressure" as const,
38
61
 
@@ -110,6 +110,32 @@ export interface BirthOutcome {
110
110
 
111
111
  // ---------------------------------------------------------------------------
112
112
  // Beliefs and current state
113
+ /**
114
+ * A saved memory's text, checked for the names of live cards (NOTES §15). It
115
+ * refreshes cards that already exist and never births one.
116
+ */
117
+ export interface NamedInTextInput {
118
+ /** The memory's title and body. */
119
+ text: string;
120
+ /** The lived day of the save. */
121
+ day: number;
122
+ /** The memory the text came from, for the event trail. */
123
+ ref: string;
124
+ /** Cards not to credit here — the title path already had its turn with them. */
125
+ except?: readonly string[];
126
+ }
127
+
128
+ export interface NamedInTextReport {
129
+ /** Cards named in the text and credited with a use. */
130
+ credited: string[];
131
+ /** Cards named but not credited: physics refused (birth day, already used today). */
132
+ refused: string[];
133
+ /** New cards born for faded cards the text named: each one's return. */
134
+ revived: string[];
135
+ /** Handles in the text held by more than one card, live or faded; none of those is credited or revived. */
136
+ ambiguous: number;
137
+ }
138
+
113
139
  // ---------------------------------------------------------------------------
114
140
 
115
141
  export interface DimensionsInput {
@@ -275,7 +301,13 @@ export type FadeReason =
275
301
  | "band-not-episodic"
276
302
  | "protected"
277
303
  | "in-live-revision-chain"
278
- | "has-live-attached-elements";
304
+ | "has-live-attached-elements"
305
+ /** The identity core is not a card that fades. */
306
+ | "identity-core"
307
+ /** Past physics' dwell, not yet past this kind's longer one (`FADE.LIVED_DWELL_FACTOR_BY_KIND`). */
308
+ | "kind-dwell-too-short"
309
+ /** Not enough calendar days since last use (`FADE.CALENDAR_FLOOR_DAYS*`). */
310
+ | "calendar-floor-not-passed";
279
311
 
280
312
  export interface FadeVerdict {
281
313
  fade: boolean;
@@ -286,12 +318,43 @@ export interface FadeVerdict {
286
318
  band: Band;
287
319
  dwellDays: number;
288
320
  attached: number;
321
+ /** Lived days of quiet this card's kind needs (physics' dwell × the kind's factor). */
322
+ livedFloorDays: number;
323
+ /**
324
+ * Calendar days since last use, as a LOWER BOUND — never a guess that could
325
+ * run long: the largest of the lived-day gap (each lived day is a distinct
326
+ * date), the birth date when birth was the last use, and a sweep anchor no
327
+ * older than the last use (NOTES §14).
328
+ */
329
+ calendarDays: number;
330
+ /** Which of the three set `calendarDays`. */
331
+ calendarSource: "lived-days" | "birth-date" | "anchor";
332
+ calendarFloorDays: number;
333
+ }
334
+
335
+ export interface FadeSweepOptions {
336
+ /** The sweep's calendar date. Defaults to `store.today()`. */
337
+ date?: string;
338
+ /** Compute every verdict and write nothing — no archive, no anchor. The observer's report. */
339
+ dryRun?: boolean;
340
+ /** Examine at most this many live cards. There is no cursor, so the same cards
341
+ * come first every sweep; sleep's budget is sized so a personal store never hits it. */
342
+ limit?: number;
289
343
  }
290
344
 
291
345
  export interface FadeReport {
292
346
  day: number;
347
+ date: string;
348
+ dryRun: boolean;
293
349
  examined: number;
350
+ /** Faded this sweep — or, on a dry run, would have. Ids only. */
294
351
  faded: string[];
352
+ /** Every blocker, counted, across the cards that did not fade. */
353
+ blocked: Record<string, number>;
354
+ /** Calendar anchors written: cards seen for the first time, or used since the last anchor. */
355
+ anchored: number;
356
+ /** Live cards not examined because `limit` ran out. */
357
+ skippedForLimit: number;
295
358
  }
296
359
 
297
360
  // ---------------------------------------------------------------------------
@@ -262,6 +262,9 @@ proposals and their archive; render and delivery telemetry.
262
262
  continues the chapter it is part of — appending in the moment is the doctrine's headline
263
263
  case (§13 G2), not an edge. Measured 2026-09-04: with the ask advancing the chapter
264
264
  count, the hook's number reached 7 in a session whose episode held nothing.
265
+ A chapter's heading carries the calendar date it was written on and, when the
266
+ caller knows it, the model that wrote it; the episode's meta keeps `sessionId`,
267
+ `chapters`, and `models` (chapter number → model id) (NOTES §24).
265
268
 
266
269
  15. **[M]** **The self page is one row, written through one seam, and outside sleep's
267
270
  reach** (2026-09-18, owner rulings 8 and 9). `revisePage(body, { reason, by, session?,