counterparts 0.1.0

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 (195) hide show
  1. package/CONSTITUTION.md +68 -0
  2. package/LICENSE +21 -0
  3. package/README.md +348 -0
  4. package/docs/ELI5.md +84 -0
  5. package/docs/QUICKSTART.md +1258 -0
  6. package/docs/module-map.md +81 -0
  7. package/package.json +63 -0
  8. package/src/adapters/claude-code/CONTRACT.md +606 -0
  9. package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
  10. package/src/adapters/claude-code/NOTES.md +1055 -0
  11. package/src/adapters/claude-code/bin/hook.ts +820 -0
  12. package/src/adapters/claude-code/bin/runner.ts +522 -0
  13. package/src/adapters/claude-code/config.ts +778 -0
  14. package/src/adapters/claude-code/credentials.ts +199 -0
  15. package/src/adapters/claude-code/doctor.ts +2557 -0
  16. package/src/adapters/claude-code/embed-client.ts +617 -0
  17. package/src/adapters/claude-code/hooks.ts +2240 -0
  18. package/src/adapters/claude-code/index.ts +224 -0
  19. package/src/adapters/claude-code/interpret-client.ts +395 -0
  20. package/src/adapters/claude-code/page-writer.ts +462 -0
  21. package/src/adapters/claude-code/primacy.ts +162 -0
  22. package/src/adapters/claude-code/spawn.ts +241 -0
  23. package/src/adapters/claude-code/standdown.ts +536 -0
  24. package/src/adapters/claude-code/transcript.ts +661 -0
  25. package/src/adapters/claude-code/vectors.ts +415 -0
  26. package/src/adapters/cli/CONTRACT.md +255 -0
  27. package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
  28. package/src/adapters/cli/NOTES.md +936 -0
  29. package/src/adapters/cli/bin/counterparts.ts +74 -0
  30. package/src/adapters/cli/commands.ts +6095 -0
  31. package/src/adapters/cli/export.ts +766 -0
  32. package/src/adapters/cli/index.ts +103 -0
  33. package/src/adapters/cli/install.ts +670 -0
  34. package/src/adapters/cli/removal.ts +1186 -0
  35. package/src/adapters/cli/repair-dates.ts +659 -0
  36. package/src/adapters/cli/self-page.ts +229 -0
  37. package/src/adapters/cli/snapshot.ts +279 -0
  38. package/src/adapters/cli/start-fresh.ts +1228 -0
  39. package/src/adapters/config-path.ts +342 -0
  40. package/src/adapters/dashboard/CONTRACT.md +67 -0
  41. package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
  42. package/src/adapters/dashboard/NOTES.md +474 -0
  43. package/src/adapters/dashboard/activity.ts +121 -0
  44. package/src/adapters/dashboard/ansi.ts +82 -0
  45. package/src/adapters/dashboard/bin/dashboard.ts +479 -0
  46. package/src/adapters/dashboard/browse.ts +298 -0
  47. package/src/adapters/dashboard/identity.ts +182 -0
  48. package/src/adapters/dashboard/index.ts +183 -0
  49. package/src/adapters/dashboard/layout.ts +149 -0
  50. package/src/adapters/dashboard/registries.ts +291 -0
  51. package/src/adapters/dashboard/resolve.ts +206 -0
  52. package/src/adapters/dashboard/source.ts +48 -0
  53. package/src/adapters/dashboard/status.ts +327 -0
  54. package/src/adapters/dashboard/stories.ts +194 -0
  55. package/src/adapters/dashboard/web/app.html +1731 -0
  56. package/src/adapters/dashboard/web/brain.html +463 -0
  57. package/src/adapters/dashboard/web/fired.ts +31 -0
  58. package/src/adapters/dashboard/web/flow.ts +457 -0
  59. package/src/adapters/dashboard/web/narrate.ts +1042 -0
  60. package/src/adapters/dashboard/web/reveal.ts +135 -0
  61. package/src/adapters/dashboard/web/server.ts +287 -0
  62. package/src/adapters/dashboard/web/views.ts +1744 -0
  63. package/src/adapters/expansions.ts +569 -0
  64. package/src/adapters/fired.ts +1580 -0
  65. package/src/adapters/mcp/CONTRACT.md +240 -0
  66. package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
  67. package/src/adapters/mcp/NOTES.md +205 -0
  68. package/src/adapters/mcp/bin/serve.ts +349 -0
  69. package/src/adapters/mcp/deliberate.ts +619 -0
  70. package/src/adapters/mcp/index.ts +101 -0
  71. package/src/adapters/mcp/protocol.ts +170 -0
  72. package/src/adapters/mcp/server.ts +1740 -0
  73. package/src/adapters/mcp/stdio.ts +56 -0
  74. package/src/adapters/mcp/tools.ts +779 -0
  75. package/src/adapters/scopes.ts +657 -0
  76. package/src/adapters/sessions.ts +402 -0
  77. package/src/adapters/snapshots.ts +1069 -0
  78. package/src/adapters/stance-env.ts +137 -0
  79. package/src/core/associate/CONTRACT.md +118 -0
  80. package/src/core/associate/INTERFACE-GAPS.md +173 -0
  81. package/src/core/associate/NOTES.md +194 -0
  82. package/src/core/associate/buffer.ts +66 -0
  83. package/src/core/associate/edges.ts +188 -0
  84. package/src/core/associate/index.ts +570 -0
  85. package/src/core/associate/pending.ts +383 -0
  86. package/src/core/associate/spread.ts +149 -0
  87. package/src/core/associate/tunables.ts +123 -0
  88. package/src/core/bridge.ts +272 -0
  89. package/src/core/briefing.ts +67 -0
  90. package/src/core/counterpart.ts +3855 -0
  91. package/src/core/encode/CONTRACT.md +151 -0
  92. package/src/core/encode/INTERFACE-GAPS.md +135 -0
  93. package/src/core/encode/NOTES.md +146 -0
  94. package/src/core/encode/aliases.ts +71 -0
  95. package/src/core/encode/battery.ts +284 -0
  96. package/src/core/encode/chunk.ts +265 -0
  97. package/src/core/encode/emotion.ts +119 -0
  98. package/src/core/encode/floor.ts +76 -0
  99. package/src/core/encode/index.ts +100 -0
  100. package/src/core/encode/precision.ts +162 -0
  101. package/src/core/encode/preselect.ts +269 -0
  102. package/src/core/encode/salience.ts +108 -0
  103. package/src/core/encode/secrets.ts +265 -0
  104. package/src/core/encode/tunables.ts +99 -0
  105. package/src/core/encode/types.ts +286 -0
  106. package/src/core/encode/words.ts +75 -0
  107. package/src/core/handoff/CONTRACT.md +199 -0
  108. package/src/core/handoff/INTERFACE-GAPS.md +166 -0
  109. package/src/core/handoff/NOTES.md +206 -0
  110. package/src/core/handoff/index.ts +957 -0
  111. package/src/core/mint.ts +279 -0
  112. package/src/core/observer.ts +28 -0
  113. package/src/core/physics/CONTRACT.md +341 -0
  114. package/src/core/physics/NOTES.md +155 -0
  115. package/src/core/physics/clock.ts +51 -0
  116. package/src/core/physics/index.ts +1054 -0
  117. package/src/core/prospective/CONTRACT.md +137 -0
  118. package/src/core/prospective/INTERFACE-GAPS.md +112 -0
  119. package/src/core/prospective/NOTES.md +160 -0
  120. package/src/core/prospective/derive.ts +188 -0
  121. package/src/core/prospective/index.ts +1030 -0
  122. package/src/core/prospective/tunables.ts +72 -0
  123. package/src/core/prospective/windows.ts +187 -0
  124. package/src/core/recall/CONTRACT.md +326 -0
  125. package/src/core/recall/INTERFACE-GAPS.md +163 -0
  126. package/src/core/recall/NOTES.md +472 -0
  127. package/src/core/recall/activate.ts +521 -0
  128. package/src/core/recall/cues.ts +275 -0
  129. package/src/core/recall/gate.ts +441 -0
  130. package/src/core/recall/index.ts +692 -0
  131. package/src/core/recall/probe.ts +239 -0
  132. package/src/core/recall/reference.ts +201 -0
  133. package/src/core/recall/render.ts +285 -0
  134. package/src/core/recall/session.ts +403 -0
  135. package/src/core/recall/tunables.ts +329 -0
  136. package/src/core/remember/CONTRACT.md +293 -0
  137. package/src/core/remember/INTERFACE-GAPS.md +189 -0
  138. package/src/core/remember/NOTES.md +373 -0
  139. package/src/core/remember/fallback.ts +452 -0
  140. package/src/core/remember/index.ts +103 -0
  141. package/src/core/remember/owner-strike-seam.ts +479 -0
  142. package/src/core/remember/proposals.ts +609 -0
  143. package/src/core/remember/spans.ts +1310 -0
  144. package/src/core/remember/tunables.ts +111 -0
  145. package/src/core/remember/updates.ts +198 -0
  146. package/src/core/retrieval.ts +96 -0
  147. package/src/core/revision.ts +441 -0
  148. package/src/core/schemas/CONTRACT.md +190 -0
  149. package/src/core/schemas/INTERFACE-GAPS.md +172 -0
  150. package/src/core/schemas/NOTES.md +260 -0
  151. package/src/core/schemas/aliases.ts +160 -0
  152. package/src/core/schemas/index.ts +1459 -0
  153. package/src/core/schemas/tunables.ts +44 -0
  154. package/src/core/schemas/types.ts +387 -0
  155. package/src/core/self/CONTRACT.md +459 -0
  156. package/src/core/self/INTERFACE-GAPS.md +284 -0
  157. package/src/core/self/NOTES.md +1057 -0
  158. package/src/core/self/briefing.ts +980 -0
  159. package/src/core/self/episodes.ts +483 -0
  160. package/src/core/self/freeze.ts +103 -0
  161. package/src/core/self/identity.ts +604 -0
  162. package/src/core/self/index.ts +2130 -0
  163. package/src/core/self/journal-file.ts +760 -0
  164. package/src/core/self/page.ts +404 -0
  165. package/src/core/self/tunables.ts +244 -0
  166. package/src/core/self/writer.ts +714 -0
  167. package/src/core/sleep/CONTRACT.md +298 -0
  168. package/src/core/sleep/INTERFACE-GAPS.md +262 -0
  169. package/src/core/sleep/NOTES.md +770 -0
  170. package/src/core/sleep/briefing.ts +86 -0
  171. package/src/core/sleep/consolidate.ts +241 -0
  172. package/src/core/sleep/cycle.ts +598 -0
  173. package/src/core/sleep/decay.ts +237 -0
  174. package/src/core/sleep/dedup.ts +373 -0
  175. package/src/core/sleep/index.ts +112 -0
  176. package/src/core/sleep/log.ts +116 -0
  177. package/src/core/sleep/markers.ts +164 -0
  178. package/src/core/sleep/prune.ts +170 -0
  179. package/src/core/sleep/strength-cache.ts +176 -0
  180. package/src/core/sleep/tunables.ts +135 -0
  181. package/src/core/sleep/types.ts +542 -0
  182. package/src/core/store/CONTRACT.md +446 -0
  183. package/src/core/store/NOTES.md +1068 -0
  184. package/src/core/store/cache.ts +709 -0
  185. package/src/core/store/db.ts +275 -0
  186. package/src/core/store/errors.ts +134 -0
  187. package/src/core/store/index.ts +2450 -0
  188. package/src/core/store/operational.ts +610 -0
  189. package/src/core/store/owner-op-seam.ts +428 -0
  190. package/src/core/store/paths.ts +494 -0
  191. package/src/core/store/prose.ts +165 -0
  192. package/src/core/store/render.ts +87 -0
  193. package/src/core/store/walk-seam.ts +78 -0
  194. package/src/core/types.ts +68 -0
  195. package/tools/install-loop/run.sh +1063 -0
@@ -0,0 +1,137 @@
1
+ # `prospective/` — CONTRACT
2
+
3
+ ## 1. Purpose
4
+
5
+ Know that the remembered future has arrived, and be *inclined* rather than *reminded*.
6
+
7
+ ## 2. Brain analog
8
+
9
+ Time-based prospective memory — the intention that resurfaces on its own when the moment
10
+ comes, rather than a queue you check. **Named deviation** (constitution line 12): human
11
+ prospective memory fails toward *forgetting*; this fails toward *tact* — a system that
12
+ surfaces every stored commitment at first retrievability is a task queue wearing memory's
13
+ clothes. **Hold debts, lose deadlines.**
14
+
15
+ ## 3. Keeps
16
+
17
+ - **The tact principle, which is the spec.** [v1] behavioral-spec §12 — the question for
18
+ every fire is *is this the moment it MEANS something, or merely the first moment it's
19
+ retrievable?*
20
+ - **Arrival is a cue, not a command. There is no bypass lane.** [v1] §12 G1 — the calendar
21
+ turning to June is treated exactly like the user saying "Portland": one more cue into the
22
+ same activation → gate → tier competition, under the same floors, refractory, dedup, and
23
+ footnote-first tiering as everything else.
24
+ - **Prospectivity is DERIVED, never stored.** [v1] §12 G2 — eligibility is a predicate over
25
+ the event date, the encode date, salience, and flags, so the property expires by itself
26
+ when the window passes: no cleanup pass, no second source of truth, nothing for decay to
27
+ special-case. Afterwards it is simply an ordinary dated memory.
28
+ - **Eligibility excludes what can never tactfully arrive**: task-state (structurally),
29
+ archived memories, skill memories, undated "someday" references, year-only precision,
30
+ and — a v2 addition, 2026-09-04 — **the journal**. A chapter's content date is the day
31
+ it was LIVED, so "arriving" is a category error about it and no label repairs that; the
32
+ refusal is `DerivableMemory.journal` in the predicate rather than at any one of
33
+ `derive`'s seven call sites. Found by adversarial review when a dated chapter rendered
34
+ in the wake's horizon lane as a thing about to happen.
35
+ **A missing encode date fails conservatively.** [v1] §12 G3.
36
+ - **Precision is carried by the date's own format**, never rounded, and the ramp differs by
37
+ precision — a stated month *means* early month more than the 29th. [v1] §12 G4.
38
+ - **A temporal cue alone reaches the footnote tier at most.** [v1] §12 G5.
39
+ - **Once-ness has four independent brakes**: one ambient fire per occasion per lived day;
40
+ a cap per window; session dedup; and — decisive — **once the assistant is observed to
41
+ have used the memory, zero further fires this window.** *Remembering completes by being
42
+ lived, not by acknowledgment UI.* [v1] §12 G6.
43
+ - **Crisis deference.** [v1] §12 G7 — arrival cues are suppressed during a refractory
44
+ period, and the horizon beat is suppressed wholesale after a high-affect previous
45
+ session. A window is days wide; deferring past someone's hard week costs nothing. *A
46
+ friend doesn't pivot from the ashes to "so, June!"*
47
+ - **A rescheduled plan is correctable through a gated compare-and-swap** — the correction
48
+ names the exact current value, carries a reason, and archives the old. [v1] §12 G8.
49
+ - **The firing key is the window itself**, which buys two properties free: a clock repair
50
+ can never re-arm an already-fired window, and a reschedule opens a fresh window that owes
51
+ nothing to the old one's spent budget. [v1] §12 G9.
52
+ - **No decay exemption before arrival.** [v1] §12 G10 — a future-dated memory that decays
53
+ into insignificance before its window was an occasion that didn't matter; forgetting it
54
+ is memory working.
55
+ - **Firing state is not canonical memory**, and the write budget is set by that cost:
56
+ losing it risks one extra polite mention, never a memory, so contended writers skip the
57
+ update loudly rather than stall a host-facing path. [v1] §12 G12.
58
+ - **Three dates, kept distinct** — when it happened, when it was learned, which lived day
59
+ it was born on. [v1] §4.2. A July-4 event encoded July-6 must not be invisible to
60
+ as-of-July-5 reasoning, and eligibility reads all three.
61
+ - **The mechanism earned its place by human rating**, not by argument: 23 of 23 fires rated
62
+ apt by the owner. [v1] earned-mechanism #21 — the journal's cleanest human-graded result.
63
+
64
+ ## 4. Drops / simplifies
65
+
66
+ - **The hand-serialized prospective ledger file is gone.** Firing state lives as rows in
67
+ the operational database (owner rescope 1, settled). v1's `mutateProspectiveLedger` had
68
+ three unsynchronized writers — a hook, a pre-spawn boundary call, and a lock-holding
69
+ horizon computation — each serializing the whole map, so a stale writer clobbered
70
+ unrelated entries too (scar §2.1). Transactions close the class.
71
+ - **Recurrence stays absent.** [v1's recorded punt, kept] Annual re-arm is scheduling
72
+ physics, and scheduling physics is where task-queue behavior creeps back in.
73
+ - **v1's knob set is not inherited as defaults.** Salience floor, lead days, grace days, cue
74
+ strength, fires per window, horizon lines per wake: each ships with a recorded
75
+ calibration and a fixture-bounded window, or ships disabled (scar §2.8). v1's values are
76
+ recorded in §12 as the starting point.
77
+ - **The gate record that must pass before this channel turns on is kept, not dropped.**
78
+ PR-A through PR-F are restated as v2 gates by `tools/replay/`; the discipline — commit
79
+ the bar *before* the mechanism is allowed on — is the harvest, and the numbers are
80
+ calibration.
81
+
82
+ ## 5. Contract
83
+
84
+ **Inputs** — memories carrying an event date at a stated precision; the lived-day clock;
85
+ the cue and gate machinery of `recall/`; per-occasion firing history; the previous
86
+ session's affect summary; the observer predicate.
87
+ **Outputs** — at most a line or two on the session's horizon, framed *"remembered, not
88
+ tasks"*, and/or a temporal cue fed into the ordinary turn-time pass; firing-state
89
+ transitions; telemetry by reference.
90
+
91
+ **Guarantees** — **[M]** mechanized, **[A]** advisory:
92
+
93
+ 1. **[M] There is no bypass lane.** A temporal cue enters `recall/` through the same
94
+ activation and gate path as any other cue; a test asserts no second injection path
95
+ exists.
96
+ 2. **[M] Eligibility is a pure predicate, computed at read time.** Nothing stores
97
+ "prospective"; nothing has to clean it up.
98
+ 3. **[M] A missing or year-only encode date fails closed.**
99
+ 4. **[M] A temporal cue alone cannot reach the loud tier.**
100
+ 5. **[M] All four once-ness brakes are independently enforced**, and referenced-stop is the
101
+ decisive one.
102
+ 6. **[M] Arrival cues are suppressed during refractory, and the horizon beat is suppressed
103
+ wholesale after a high-affect previous session.**
104
+ 7. **[M] Rescheduling is a compare-and-swap that names the current value**, so a stale
105
+ proposal cannot clobber a fresher date; the old value is archived with a reason.
106
+ 8. **[M] The firing key is the window.** A clock repair cannot re-arm a spent window.
107
+ 9. **[M] Firing state never advances under observer** — an evaluation must not consume the
108
+ real store's fire budget (scar E7).
109
+ 10. **[M] Out-of-window fires and fires during refractory are hard-zero criteria**, scored
110
+ by an **independent** scorer that implements its own window arithmetic rather than
111
+ calling the code under test — *a shared bug must not grade itself* (§17.2).
112
+ 11. **[A] The horizon line's exact wording and whether a post-window grace beat is warm or
113
+ creepy are open probe questions, deliberately.** *The words are load-bearing for tact,
114
+ and that is an honest thing for a spec to say.*
115
+ 12. **[M] Every dated memory names its exit** — fired, expired, superseded by a
116
+ reschedule, or faded — and the counts are reported (scar §2.17).
117
+
118
+ ## 6. Scars honored
119
+
120
+ **E7** (no firing-state advance under observer) · **E8** (windows, ramps, and once-per-day
121
+ brakes run on lived days) · **§2.1** (firing state is transactional rows, not a
122
+ hand-serialized map with three writers) · **§2.4** (a suppressed fire is a distinct record
123
+ from a fire that never became eligible) · **§2.8** (every ramp constant ships measured or
124
+ disabled) · **§2.16** (the "would this still be true after the date passes?" test is the
125
+ admission criterion, with a named negative example) · **§2.17** (exit paths are counted).
126
+
127
+ ## 7. Open questions
128
+
129
+ 1. **Is the post-window grace beat — "how did the move go?" — warm or creepy?** v1 shipped
130
+ this as an explicit lived-probe question and never answered it. Carried forward as open,
131
+ deliberately.
132
+ 2. **Does the horizon belong in the wake briefing at all**, now that the briefing is
133
+ ranked by strength rather than assembled from lanes? A dated memory near its window has
134
+ a real claim on attention; expressing that as a strength modifier instead of a separate
135
+ lane would be simpler and more brain-faithful.
136
+ 3. **What replaces `session dedup` if `recall/`'s per-session gate state is not persisted?**
137
+ One of the four brakes depends on it — see `recall/` open question 1.
@@ -0,0 +1,112 @@
1
+ # `prospective/` — interface gaps
2
+
3
+ Things this module needs from a neighbour and worked around instead of editing. Each
4
+ entry names the owner, the workaround now in the code, and what the real fix looks like.
5
+
6
+ ## 1. The wiring into `recall/` — and the `arrival` NAME COLLISION
7
+
8
+ **Owner:** the coordinator (a seam pass), not this module and not `recall/`.
9
+ **Needed:** contract §5 G1 — "a temporal cue enters `recall/` through the same activation
10
+ and gate path as any other cue; a test asserts no second injection path exists."
11
+ **Have:** `Prospective.arrivals()` returns `Arrival[]`. Each one carries `memoryId`,
12
+ `cueWeight` (= `CUE_STRENGTH x ramp`) and `maxTier: "footnoted"`. Nothing else. There is
13
+ no render, no injection, no text of any kind in this module, and `test/prospective.test.ts`
14
+ enumerates the exports and asserts that.
15
+
16
+ **READ THIS BEFORE WIRING — the two "arrival"s are not the same thing.**
17
+
18
+ | | `recall/`'s `arrival` | `prospective/`'s `Arrival` |
19
+ |---|---|---|
20
+ | what it is | base-level activation: `ARRIVAL_WEIGHT x strength` | a temporal cue: the calendar reached a remembered window |
21
+ | what it can do | MODULATE a candidate the conversation already reached | be one more cue, like the user typing "Portland" |
22
+ | can it create a candidate? | **no** — hard gate (a), an uncued memory is dark | **yes** — that is what a cue is |
23
+
24
+ They collide only in the word. Wiring a temporal arrival into `recall/`'s
25
+ `ARRIVAL_WEIGHT` would be a category error: it would silently make a *recency* multiplier
26
+ into an *admission* channel and break hard gate (a) for every dated memory.
27
+
28
+ **Real fix:** `ActivationInput` grows an optional
29
+ `temporal?: readonly { id: string; weight: number }[]`, folded into `cueScore` alongside
30
+ the token postings — the same map, so the candidate competes on one activation number
31
+ against the same background bar. Two constraints that must ride along:
32
+
33
+ 1. `cueFraction` must count temporal weight as CUE, not as arrival, or hard gate (c)
34
+ silently changes meaning.
35
+ 2. A candidate whose ONLY cue is temporal must be capped at the footnote tier (§12 G5).
36
+ `recall/`'s gate has no such per-candidate ceiling today; the cap belongs there, next
37
+ to the other tier rules, not here.
38
+
39
+ Until that lands there is no wiring at all — which is the safe direction: the module
40
+ computes arrivals and nothing consumes them.
41
+
42
+ ## 2. `ProseDoc` has no future-event date, and no enumeration of dated memories
43
+
44
+ **Owner:** `store/`.
45
+ **Needed:** (a) somewhere canonical for "the date this memory is ABOUT, in the future";
46
+ (b) a way to ask which memories have one, without reading every memory.
47
+ **Have:** `ProseDoc.happenedOn` — stated precision, never rounded, exactly the right
48
+ shape, and past-tense by name — plus the free-form `meta` bag.
49
+ **Workaround:** `contentDates(doc)` reads `happenedOn` plus a meta convention this module
50
+ declares (`eventDate: string`, `eventDates: string[]`), and `ArrivalInput.extraDates`
51
+ lets a caller supply dates it extracted itself. `arrivals()` and `exitReport()` then scan
52
+ `store.list()` and read every live memory — O(store) per call.
53
+ **Real fix:** either rename/widen `happenedOn` to a neutral `datedOn` with a documented
54
+ future case, or add a `happened_on` index plus `Store.datedMemories(fromDate, toDate)`.
55
+ The column already exists on the memories table; only the query is missing.
56
+
57
+ ## 3. Session dedup is in-process — brake 3 of four does not survive a restart
58
+
59
+ **Owner:** `recall/` (contract open question 3: "what replaces session dedup if
60
+ `recall/`'s per-session gate state is not persisted?" — it IS persisted, in `gate_session`
61
+ via meta).
62
+ **Have:** `Prospective` keeps `sessionId -> Set<windowKey>`, bounded by
63
+ `MAX_SESSION_WINDOWS`, in memory.
64
+ **Workaround cost:** two processes in one session, or a restart mid-session, each get a
65
+ fresh set. The other three brakes still hold (once per lived day, the per-window cap, and
66
+ referenced-stop), so the failure mode is one extra polite mention — exactly the budget
67
+ §12 G12 sets for firing state.
68
+ **Real fix:** the window keys offered this session belong in `recall/`'s persisted gate
69
+ state, next to `surfaced` and `credited`, and this module reads them through the same
70
+ seam it will use for the wiring in gap #1.
71
+
72
+ ## 4. `store.revise` cannot patch `happenedOn`, so a reschedule cannot complete here
73
+
74
+ **Owner:** `store/`.
75
+ **Needed:** §12 G8 — the correction "names the exact current value, carries a reason, and
76
+ archives the old."
77
+ **Have:** `Store.revise(id, { body?, title?, meta?, reason? })`. It archives the prior
78
+ version with a reason (the "archives the old" half, exactly right), but `happenedOn` is
79
+ not in the patch shape, so the stated date cannot be corrected through the seam.
80
+ **Workaround:** `Prospective.reschedule()` does the FIRING-STATE half only — it validates
81
+ the compare-and-swap against the memory's currently derived windows, retires the old
82
+ window (kept, state `expired`, never deleted) and arms the fresh key. The caller then
83
+ revises the memory's own date (`store.revise` with the `eventDate` meta of gap #2). Until
84
+ that second step lands, derivation still points at the old date and the fresh window
85
+ simply never fires — the fail-safe direction: the system stays quiet rather than speaking
86
+ about something that is not happening.
87
+ **Real fix:** `happenedOn?: string` in the revise patch, so the whole correction is one
88
+ transaction and cannot half-land.
89
+
90
+ ## 5. The prospective row cannot record WHY a window was suppressed
91
+
92
+ **Owner:** `store/`.
93
+ **Needed:** scar §2.4 — "a suppressed fire is a distinct record from a fire that never
94
+ became eligible", durably.
95
+ **Have:** `prospective(memory_id, window_key, event_date, precision, state, fires,
96
+ last_fired_day)`, with `state` drawn from four values and no reason column.
97
+ **Workaround:** the four states are spent carefully so the distinctions that MATTER
98
+ survive without a reason column — `suppressed` is written by referenced-stop and nothing
99
+ else, `expired` by a closed or superseded window, and `over-fired` is readable as
100
+ `fires >= FIRES_PER_WINDOW`. What does not survive a restart is the finer detail
101
+ (which reschedule retired a window, whether an expiry was a close or a swap); that rides
102
+ in telemetry only.
103
+ **Real fix:** a `reason TEXT` column, or a `state` vocabulary that includes `referenced`.
104
+ Neither is urgent: losing this costs analytics, never a brake.
105
+
106
+ ## 6. The observer predicate lives in `store/`
107
+
108
+ Not a defect, and recorded so nobody "fixes" it: `Prospective.observer` reads
109
+ `store.observer` and never re-derives the predicate (`docs/observer-mode.md` G7, and
110
+ `recall/`'s INTERFACE-GAPS #4 says the same). If the predicate moves to
111
+ `src/core/observer.ts` (SEAMS #4), this module follows the move without changing
112
+ behavior.
@@ -0,0 +1,160 @@
1
+ # `prospective/` — implementation notes
2
+
3
+ Choices the CONTRACT does not make, recorded here rather than left to be re-discovered
4
+ from the code. None of these is a guarantee; each is the smallest brain-faithful rule
5
+ that could work (constitution line 15), and each names what would have to fail before
6
+ machinery is added.
7
+
8
+ ## 1. Calendar days for windows, lived days for brakes
9
+
10
+ Scar E8 says windows, ramps and once-per-day brakes run on lived days. That is
11
+ implemented as a SPLIT, deliberately:
12
+
13
+ - **Window bounds and the ramp are calendar arithmetic** on the event date. "Three days
14
+ before September 4th" is not computable in lived days, because nobody has lived the
15
+ days between here and there yet — the lived-day clock only counts backwards over days
16
+ that happened.
17
+ - **The once-per-occasion brake is lived days.** `last_fired_day` is the store's
18
+ lived-day integer, and `fire()` compares against a lived day the caller passes (or
19
+ `store.livedDay()`). A week away therefore cannot spend a week of fire budget.
20
+
21
+ The scar's intent survives intact: the thing that must not be inflated by absence is the
22
+ FIRING RATE, and firing rate is on the lived clock.
23
+
24
+ ## 2. Nothing in this module reads a clock
25
+
26
+ `at` (a `YYYY-MM-DD` calendar key) and `day` (a lived-day integer) are arguments
27
+ everywhere, following `recall/`'s injectable-clock pattern. Two payoffs: as-of questions
28
+ ("was this arriving on July 5th?") are the same code path as today's, which §4.2's
29
+ three-dates rule requires; and every test is hermetic without sleeping or freezing time.
30
+
31
+ ## 3. `task-state` is excluded by the type system, not by a refusal code
32
+
33
+ §12 G3 excludes task-state "structurally". In v2 that is literally true: `Kind` is
34
+ `self | person | entity | skill | place | fact` and there is no task member, so a
35
+ task-state memory cannot be constructed to be refused. `EXCLUDED_KINDS` therefore lists
36
+ only `skill`. Minting a `task-state` refusal code that can never fire would be a number
37
+ in a log that is not a monitor (scar §2.4) — the opposite of the point.
38
+
39
+ ## 4. The salience floor reads `sal()`, never `strength()`
40
+
41
+ §12 G2 names the predicate's inputs: event date, encode date, salience, flags. Salience
42
+ is fixed at encoding, so the floor is stable and a memory cannot become prospective by
43
+ being used. Reading decayed strength here would ALSO quietly contradict §12 G10 (no decay
44
+ exemption before arrival) by turning decay into an eligibility input on the arrival path.
45
+ Strength appears in an `Arrival` for ORDERING only, and `recall/`'s ordinary gate is
46
+ where a faded memory actually loses — which is the whole "no bypass lane" claim.
47
+
48
+ `sal()` is imported from `physics/`. A local mean would be a second implementation of the
49
+ one arithmetic rule, which is exactly the divergence v1's "two clocks" produced.
50
+
51
+ ## 5. Ramp shape: linear, two anchors, both CAL
52
+
53
+ `RAMP_OPEN = 0.4` rising to 1 at the peak, then falling to `RAMP_CLOSE = 0.2` at the last
54
+ grace day. Linear, because there is no measurement to justify a curve: v1 recorded lead
55
+ DAYS and grace DAYS and never a shape at all, so any curve here would be invented
56
+ precision (scar §2.8). The month case falls out of the same two anchors — a month window
57
+ peaks on the 1st and decays across the whole month plus grace, which is §12 G4's "a
58
+ stated month *means* early month more than the 29th" as arithmetic rather than as a
59
+ rounded date.
60
+
61
+ Replace this with a measured shape when `tools/replay` has one; until then it is two
62
+ numbers in the TUNABLE table where they can be audited.
63
+
64
+ ## 6. A fire is a surfacing that HAPPENED, not an offer that was made
65
+
66
+ `arrivals()` writes nothing; `fire()` is a separate call the caller makes after
67
+ `recall/`'s gate actually admitted the memory. This mirrors `recall/`'s build/record
68
+ split and it is what makes "arrival is a cue, not a command" structural: nothing in this
69
+ module can cause the surfacing whose budget it counts, and a session that computes
70
+ arrivals and then decides to stay quiet has spent nothing.
71
+
72
+ The brakes therefore run TWICE — advisory in `arrivals()` (do not offer a cue for a spent
73
+ window) and authoritative in `fire()`. They are one function, `brakeFor`, so the two
74
+ paths cannot disagree about what a spent window is.
75
+
76
+ ## 7. The four store states, and why `expired` is both written and derived
77
+
78
+ | state | meaning | who writes it |
79
+ |---|---|---|
80
+ | `armed` | a derived window, no fires spent | `arm()`, `reschedule()` |
81
+ | `fired` | >= 1 ambient fire spent; budget may remain | `fire()` |
82
+ | `suppressed` | TERMINAL by referenced-stop — the decisive brake | `reference()` only |
83
+ | `expired` | TERMINAL: the window closed, or a reschedule replaced it | `expire()`, `reschedule()` |
84
+
85
+ `expired` is also what a row with NO stamp reads as once its window passes, because
86
+ `phaseOf()` says so. That is §12 G2 doing its job: the property expires by itself and
87
+ nothing has to sweep. `expire()` exists for the explicit case (a reschedule retiring a
88
+ window), never as a cleanup pass.
89
+
90
+ Terminal states are never resurrected. `arm()` on a spent key keeps the spent state — the
91
+ firing key is the window (§12 G9), so a clock repair, a replayed hook, or a stale caller
92
+ cannot re-arm what is done.
93
+
94
+ **arm records, fire judges.** `arm()` accepts any well-formed key without re-deriving,
95
+ where `fire()` re-derives every time. The asymmetry is deliberate and cheap: an arm is a
96
+ note-to-self about a window, and a wrong one is inert — `fire()` refuses it as
97
+ `window-not-derived`, `arrivals()` never offers it, and `exitReport()` classifies it as a
98
+ window that passed. Nothing downstream trusts a row, so nothing is gained by making the
99
+ cheap write expensive.
100
+
101
+ ## 8. The `faded` exit is defined here, not in the contract
102
+
103
+ §5 G12 names four exits — fired, expired, superseded by a reschedule, faded — without
104
+ saying what separates the last two. The rule implemented: a window that closed with zero
105
+ fires exits **faded** when the memory is archived, or when its decayed strength is at or
106
+ below `FADED_STRENGTH` (defaulting to physics' `PHI_PRUNE`); otherwise **expired**. The
107
+ distinction is worth having because it answers different questions: `expired` means the
108
+ occasion passed unremarked, `faded` means the memory itself stopped mattering first,
109
+ which is §12 G10 working rather than a miss.
110
+
111
+ `referenced` and `open` are counted alongside the contract's four. A window that ended
112
+ because the memory was actually USED is the best exit there is, and folding it into
113
+ `fired` would hide it.
114
+
115
+ ## 9. Recurrence stays absent, and so does anything that could grow into it
116
+
117
+ No re-arm, no next-occurrence, no "annual" flag, no date arithmetic that produces a date
118
+ the author never stated. The recorded punt (CONTRACT §4) is not a to-do: annual re-arm is
119
+ scheduling physics, and scheduling physics is where task-queue behavior creeps back in.
120
+ A birthday that matters will be remembered again, by being lived again.
121
+
122
+ ## 10. Open, deliberately
123
+
124
+ CONTRACT §7's three open questions are untouched by this implementation:
125
+
126
+ 1. Whether the post-window grace beat ("how did the move go?") is warm or creepy. The
127
+ grace days exist and the ramp tails through them; whether anything is ever *said*
128
+ there is not this module's call, and the wording — which is load-bearing for tact —
129
+ does not exist anywhere in this directory.
130
+ 2. Whether the horizon belongs in the wake briefing at all, or should be a strength
131
+ modifier. `horizon()` returns records, not lines, so either answer stays reachable.
132
+ 3. Session dedup's home — INTERFACE-GAPS #3.
133
+
134
+ ## 11. Two durable rows, added 2026-09-20 (E2)
135
+
136
+ Until today this module wrote no event at all — the 2026-09-17 mechanism inventory found
137
+ "zero `appendEvent` in the module" and marked both prospective rows RING-ONLY. `fires` is
138
+ a counter and `last_fired_day` is one day, so the store could say a window had ever fired
139
+ and never *when*, never how often, and never why one did not. The owner's fourteen windows
140
+ carried counters from a v1 import with `last_fired_day` null on every one, and nothing
141
+ could tell that from a mechanism working quietly.
142
+
143
+ **Two names, not one with an `outcome`.** `prospective.fire` for a fire,
144
+ `prospective.fire.refused` for a brake that held. A refusal counted as a firing is exactly
145
+ the bug the fired view exists to catch, and two names keep them apart in every reader by
146
+ construction — the same split `snapshot.taken` / `snapshot.failed` makes for the same
147
+ reason.
148
+
149
+ **The refusal is latched per memory, window, reason and lived day.** Eligibility is
150
+ re-derived every turn (§12 G2), so an unlatched row would write once a turn forever for a
151
+ window whose date has passed. Latched, it says "this window was stopped by this, on this
152
+ day", which is the smallest fact that answers the question.
153
+
154
+ The ring emits are untouched: they are the live debugging channel and they die with the
155
+ process. What is new is the half that outlives it.
156
+
157
+ **Still true, and worth saying:** `fire()` has one caller in the whole tree
158
+ (`tools/demo/seed.ts`), so on the live store these rows will read `never` until something
159
+ arms and fires a window in earnest. That is inventory §3 S4, not a fault in this row — and
160
+ now it is a silence the view can finally tell apart from a mechanism nobody watched.
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Derivation — **prospectivity is DERIVED, never stored** (§12 G2).
3
+ *
4
+ * There is no `isProspective` flag anywhere in this module, no column that says
5
+ * so, and no author who can set one. Eligibility is a pure predicate over the
6
+ * event date, the encode date, salience and flags, recomputed every time it is
7
+ * asked. Three consequences, all of them the point:
8
+ *
9
+ * - the property EXPIRES BY ITSELF when the window passes — no cleanup pass;
10
+ * - there is no second source of truth to drift from the memory;
11
+ * - decay has nothing to special-case (§12 G10: no decay exemption before
12
+ * arrival — a future-dated memory that faded before its window was an
13
+ * occasion that didn't matter).
14
+ *
15
+ * The dates come from the CALLER. This module does no NLP: it reads the shape of
16
+ * a date string and nothing else (`windows.ts`). Whoever extracted "September"
17
+ * from a sentence owns that judgment; the deriver owns only what follows from it.
18
+ *
19
+ * Every refusal has a NAME. "Not prospective" is not a verdict a log can act on,
20
+ * and a memory excluded because it is a skill and one excluded because its window
21
+ * already passed are different systems (scar §2.4).
22
+ */
23
+ import type { Kind, Salience } from "../types.js";
24
+ import { sal } from "../physics/index.js";
25
+ import type { ProspectiveTunables } from "./tunables.js";
26
+ import { phaseOf, precisionOf, windowFor } from "./windows.js";
27
+ import type { Phase, Window } from "./windows.js";
28
+
29
+ export type DeriveReason =
30
+ | "eligible"
31
+ /** The memory carries no date at all — the undated "someday" reference. */
32
+ | "no-event-date"
33
+ /** A date string this module cannot read. Refused, never guessed. */
34
+ | "malformed-date"
35
+ /** Year-only precision can never tactfully arrive (§12 G3). */
36
+ | "year-only-precision"
37
+ /** A missing or unreadable encode date FAILS CONSERVATIVELY (§12 G3). */
38
+ | "missing-encode-date"
39
+ /** Archived memory never arrives; the id stays resolvable, it simply stays quiet. */
40
+ | "archived"
41
+ /** Skill memories are excluded by kind (§12 G3). */
42
+ | "excluded-kind"
43
+ /** A journal chapter. Its date is a day that was LIVED, never one arriving. */
44
+ | "journal"
45
+ | "below-salience-floor"
46
+ /** Every derived window is behind us — the property expiring by itself. */
47
+ | "window-passed";
48
+
49
+ /** Kinds that can never tactfully arrive. `task-state` is excluded STRUCTURALLY:
50
+ * v2's `Kind` has no such member, so it is a type error, not a runtime refusal
51
+ * (NOTES.md §3). */
52
+ export const EXCLUDED_KINDS: readonly Kind[] = ["skill"];
53
+
54
+ /**
55
+ * What the deriver needs to know about a memory. Deliberately a plain shape and
56
+ * not the store's row: derivation is a predicate, and a predicate that can only
57
+ * be evaluated against a database is a query.
58
+ */
59
+ export interface DerivableMemory {
60
+ readonly id: string;
61
+ readonly kind: Kind;
62
+ readonly salience: Salience;
63
+ readonly archived: boolean;
64
+ /** The encode date (`ProseDoc.learnedOn`). Null / blank / unreadable fails closed. */
65
+ readonly learnedOn: string | null;
66
+ /**
67
+ * A journal chapter (`ProseDoc.type === "episode"`, the field
68
+ * `sleep/types.ts#isJournal` reads off the row).
69
+ *
70
+ * FOUND 2026-09-04 by the adversarial review of PR #70, and it is not a
71
+ * labelling miss — it is a CATEGORY ERROR. A chapter's content date is the day
72
+ * it was LIVED; "Arriving" is false of it no matter what word sits in front of
73
+ * the line. Nothing on this path filtered by type — `Prospective.arrivals`
74
+ * walks `list({ archived: false })` and the only kind excluded was `skill` —
75
+ * so a dated chapter rendered in the wake's horizon lane as a thing about to
76
+ * happen. Reproduced end to end: `at` on the chapter's own date returned it
77
+ * `armed`, and the published briefing read
78
+ * `Arriving: - 2026-09-05 (of 2026-09-10) · ## the lighthouse conversation`.
79
+ *
80
+ * Reachable on the owner's store: 224 migrated episodes are live, carrying
81
+ * `happenedOn`, `learnedOn`, `kind: "self"` and a claimed salience floor.
82
+ *
83
+ * It is refused HERE, in the predicate, rather than at one caller — `derive`
84
+ * has seven call sites in `prospective/index.ts` and a filter at one of them
85
+ * is a rule that holds where somebody remembered it.
86
+ */
87
+ readonly journal: boolean;
88
+ }
89
+
90
+ /** A content-date the CALLER extracted. Its precision is its own shape (§12 G4). */
91
+ export interface ExtractedDate {
92
+ readonly date: string;
93
+ }
94
+
95
+ export interface DerivedWindow extends Window {
96
+ readonly phase: Phase;
97
+ }
98
+
99
+ export interface Prospectivity {
100
+ readonly memoryId: string;
101
+ readonly eligible: boolean;
102
+ /** The first blocking reason, or "eligible". */
103
+ readonly reason: DeriveReason;
104
+ /** EVERY blocking reason — a memory can fail several ways at once. */
105
+ readonly blockedBy: DeriveReason[];
106
+ /** Windows from the dates that survived, oldest first. Present even when the
107
+ * memory is INELIGIBLE — a window is a derived fact about a date, and the exit
108
+ * accounting (§5 G12) needs to see the windows of memories that never fired.
109
+ * Eligibility is the verdict; `windows` is never one. */
110
+ readonly windows: DerivedWindow[];
111
+ /** Dates that did not become windows, each with the reason it did not. */
112
+ readonly rejectedDates: { date: string; reason: DeriveReason }[];
113
+ /** sal(m) as physics computes it — never a local re-derivation. */
114
+ readonly salience: number;
115
+ }
116
+
117
+ function encodeDateOk(learnedOn: string | null): boolean {
118
+ if (learnedOn === null) return false;
119
+ const p = precisionOf(learnedOn);
120
+ // The encode date is a real instant, so only a full day counts. A memory whose
121
+ // encode date is "2026" cannot be reasoned about as-of anything, and the fail
122
+ // direction is conservative: excluded, not admitted (§12 G3).
123
+ return p === "day";
124
+ }
125
+
126
+ /**
127
+ * The predicate. Pure, and cheap enough to run at read time — which is what makes
128
+ * "derived, never stored" affordable rather than aspirational.
129
+ *
130
+ * `at` is the calendar day being asked about (a `YYYY-MM-DD` key). It is an
131
+ * ARGUMENT: nothing here reads a clock, so an as-of question ("was this arriving
132
+ * on July 5th?") is the same code path as today's.
133
+ */
134
+ export function derive(
135
+ memory: DerivableMemory,
136
+ dates: readonly ExtractedDate[],
137
+ at: string,
138
+ t: ProspectiveTunables,
139
+ ): Prospectivity {
140
+ const blockedBy: DeriveReason[] = [];
141
+ const s = sal(memory.salience);
142
+
143
+ if (memory.archived) blockedBy.push("archived");
144
+ if (memory.journal) blockedBy.push("journal");
145
+ if (EXCLUDED_KINDS.includes(memory.kind)) blockedBy.push("excluded-kind");
146
+ if (!encodeDateOk(memory.learnedOn)) blockedBy.push("missing-encode-date");
147
+ if (s < t.SALIENCE_FLOOR) blockedBy.push("below-salience-floor");
148
+
149
+ const windows: DerivedWindow[] = [];
150
+ const rejectedDates: { date: string; reason: DeriveReason }[] = [];
151
+ const seen = new Set<string>();
152
+ for (const d of dates) {
153
+ const precision = precisionOf(d.date);
154
+ if (precision === null) {
155
+ rejectedDates.push({ date: d.date, reason: "malformed-date" });
156
+ continue;
157
+ }
158
+ if (precision === "year") {
159
+ rejectedDates.push({ date: d.date, reason: "year-only-precision" });
160
+ continue;
161
+ }
162
+ const w = windowFor(d.date, precision, t);
163
+ if (w === null) {
164
+ rejectedDates.push({ date: d.date, reason: "malformed-date" });
165
+ continue;
166
+ }
167
+ if (seen.has(w.key)) continue;
168
+ seen.add(w.key);
169
+ windows.push({ ...w, phase: phaseOf(w, at) });
170
+ }
171
+ windows.sort((a, b) => (a.opensOn < b.opensOn ? -1 : a.opensOn > b.opensOn ? 1 : 0));
172
+
173
+ if (windows.length === 0) {
174
+ blockedBy.push(rejectedDates[0]?.reason ?? "no-event-date");
175
+ } else if (windows.every((w) => w.phase === "passed")) {
176
+ blockedBy.push("window-passed");
177
+ }
178
+
179
+ return {
180
+ memoryId: memory.id,
181
+ eligible: blockedBy.length === 0,
182
+ reason: blockedBy[0] ?? "eligible",
183
+ blockedBy,
184
+ windows,
185
+ rejectedDates,
186
+ salience: s,
187
+ };
188
+ }