counterparts 0.3.11 → 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 (150) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/docs/QUICKSTART.md +5 -0
  3. package/docs/README.md +2 -2
  4. package/docs/module-map.md +3 -3
  5. package/package.json +1 -1
  6. package/src/adapters/claude-code/CONTRACT.md +36 -10
  7. package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
  8. package/src/adapters/claude-code/NOTES.md +182 -0
  9. package/src/adapters/claude-code/bin/hook.ts +46 -12
  10. package/src/adapters/claude-code/bin/runner.ts +7 -1
  11. package/src/adapters/claude-code/doctor.ts +632 -18
  12. package/src/adapters/claude-code/hooks.ts +61 -16
  13. package/src/adapters/claude-code/index.ts +11 -0
  14. package/src/adapters/claude-code/night-run.ts +150 -14
  15. package/src/adapters/claude-code/transcript.ts +268 -1
  16. package/src/adapters/cli/CONTRACT.md +5 -0
  17. package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
  18. package/src/adapters/cli/NOTES.md +111 -0
  19. package/src/adapters/cli/commands.ts +134 -92
  20. package/src/adapters/cli/dream-core.ts +57 -42
  21. package/src/adapters/cli/export.ts +320 -21
  22. package/src/adapters/cli/help.ts +2 -1
  23. package/src/adapters/cli/index.ts +1 -0
  24. package/src/adapters/cli/install.ts +39 -7
  25. package/src/adapters/cli/mechanisms.ts +7 -1
  26. package/src/adapters/cli/uninstall.ts +13 -5
  27. package/src/adapters/cli/wire.ts +189 -63
  28. package/src/adapters/config.ts +2 -0
  29. package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
  30. package/src/adapters/dashboard/NOTES.md +79 -0
  31. package/src/adapters/dashboard/registries.ts +34 -2
  32. package/src/adapters/dashboard/web/README.md +19 -14
  33. package/src/adapters/dashboard/web/actions.ts +23 -1
  34. package/src/adapters/dashboard/web/flow.ts +14 -0
  35. package/src/adapters/dashboard/web/lanes.ts +10 -0
  36. package/src/adapters/dashboard/web/narrate.ts +88 -2
  37. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
  38. package/src/adapters/dashboard/web/pages/health/sections/checks.js +2 -0
  39. package/src/adapters/dashboard/web/pages/health/sections/wake.js +3 -1
  40. package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
  41. package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
  42. package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
  43. package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
  44. package/src/adapters/dashboard/web/server.ts +0 -5
  45. package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
  46. package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
  47. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
  48. package/src/adapters/dashboard/web/views/health.ts +21 -3
  49. package/src/adapters/dashboard/web/views/search.ts +4 -45
  50. package/src/adapters/dashboard/web/views.ts +2 -2
  51. package/src/adapters/fired.ts +430 -28
  52. package/src/adapters/host-wiring.ts +300 -0
  53. package/src/adapters/hosts.ts +11 -0
  54. package/src/adapters/lifecycle.ts +42 -2
  55. package/src/adapters/log/index.ts +9 -0
  56. package/src/adapters/mcp/CONTRACT.md +151 -11
  57. package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
  58. package/src/adapters/mcp/NOTES.md +313 -1
  59. package/src/adapters/mcp/bin/serve.ts +74 -1
  60. package/src/adapters/mcp/deliberate.ts +169 -651
  61. package/src/adapters/mcp/facts.ts +1094 -0
  62. package/src/adapters/mcp/index.ts +25 -7
  63. package/src/adapters/mcp/meaning.ts +1610 -0
  64. package/src/adapters/mcp/server.ts +835 -150
  65. package/src/adapters/mcp/stdio.ts +3 -1
  66. package/src/adapters/mcp/stood-down.ts +51 -0
  67. package/src/adapters/mcp/tools.ts +167 -41
  68. package/src/adapters/plugin-run.sh +133 -0
  69. package/src/adapters/plugin.ts +329 -0
  70. package/src/adapters/sessions.ts +18 -4
  71. package/src/core/associate/CONTRACT.md +2 -1
  72. package/src/core/associate/INTERFACE-GAPS.md +6 -1
  73. package/src/core/associate/NOTES.md +45 -0
  74. package/src/core/briefing.ts +12 -3
  75. package/src/core/contradictions.ts +184 -0
  76. package/src/core/counterpart.ts +797 -51
  77. package/src/core/dream/CONTRACT.md +36 -4
  78. package/src/core/dream/INTERFACE-GAPS.md +29 -6
  79. package/src/core/dream/NOTES.md +107 -0
  80. package/src/core/dream/feeling-weeks.ts +198 -0
  81. package/src/core/dream/index.ts +109 -18
  82. package/src/core/dream/reflect.ts +346 -87
  83. package/src/core/dream/tunables.ts +24 -4
  84. package/src/core/encode/INTERFACE-GAPS.md +3 -1
  85. package/src/core/encode/NOTES.md +7 -0
  86. package/src/core/encode/words.ts +45 -0
  87. package/src/core/fit/INTERFACE-GAPS.md +8 -2
  88. package/src/core/fit/NOTES.md +39 -1
  89. package/src/core/fit/index.ts +40 -0
  90. package/src/core/handoff/CONTRACT.md +37 -2
  91. package/src/core/handoff/INTERFACE-GAPS.md +10 -0
  92. package/src/core/handoff/NOTES.md +72 -0
  93. package/src/core/handoff/index.ts +214 -12
  94. package/src/core/handoff/last-here.ts +6 -4
  95. package/src/core/mint.ts +12 -2
  96. package/src/core/physics/CONTRACT.md +14 -2
  97. package/src/core/physics/NOTES.md +33 -1
  98. package/src/core/physics/index.ts +28 -5
  99. package/src/core/prospective/CONTRACT.md +45 -6
  100. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  101. package/src/core/prospective/NOTES.md +138 -0
  102. package/src/core/prospective/derive.ts +33 -5
  103. package/src/core/prospective/index.ts +90 -5
  104. package/src/core/prospective/windows.ts +72 -1
  105. package/src/core/recall/CONTRACT.md +31 -12
  106. package/src/core/recall/INTERFACE-GAPS.md +28 -4
  107. package/src/core/recall/NOTES.md +70 -1
  108. package/src/core/recall/feeling-ask.ts +10 -1
  109. package/src/core/recall/index.ts +3 -1
  110. package/src/core/recall/probe.ts +58 -0
  111. package/src/core/recall/session.ts +46 -2
  112. package/src/core/recall/time-ask.ts +487 -0
  113. package/src/core/remember/CONTRACT.md +4 -1
  114. package/src/core/remember/INTERFACE-GAPS.md +9 -1
  115. package/src/core/remember/NOTES.md +8 -0
  116. package/src/core/remember/proposals.ts +47 -5
  117. package/src/core/revision.ts +18 -1
  118. package/src/core/schemas/CONTRACT.md +21 -1
  119. package/src/core/schemas/INTERFACE-GAPS.md +20 -2
  120. package/src/core/schemas/NOTES.md +144 -0
  121. package/src/core/schemas/aliases.ts +55 -5
  122. package/src/core/schemas/index.ts +93 -1
  123. package/src/core/schemas/types.ts +2 -0
  124. package/src/core/self/CONTRACT.md +32 -5
  125. package/src/core/self/INTERFACE-GAPS.md +7 -2
  126. package/src/core/self/NOTES.md +102 -1
  127. package/src/core/self/behind.ts +43 -3
  128. package/src/core/self/briefing.ts +12 -2
  129. package/src/core/self/chapter-address.ts +254 -0
  130. package/src/core/self/episodes.ts +27 -0
  131. package/src/core/self/index.ts +83 -8
  132. package/src/core/self/page.ts +88 -0
  133. package/src/core/self/tunables.ts +5 -0
  134. package/src/core/self/work.ts +35 -2
  135. package/src/core/self/writer.ts +30 -0
  136. package/src/core/sleep/INTERFACE-GAPS.md +22 -3
  137. package/src/core/sleep/NOTES.md +20 -1
  138. package/src/core/sleep/consolidate.ts +59 -7
  139. package/src/core/sleep/index.ts +3 -0
  140. package/src/core/sleep/prune.ts +6 -2
  141. package/src/core/sleep/types.ts +7 -0
  142. package/src/core/store/CONTRACT.md +16 -0
  143. package/src/core/store/NOTES.md +66 -0
  144. package/src/core/store/feelings.ts +14 -1
  145. package/src/core/store/index.ts +483 -16
  146. package/src/core/store/operational.ts +95 -2
  147. package/src/core/store/owner-op-seam.ts +23 -0
  148. package/src/core/time.ts +152 -0
  149. package/tools/install-loop/run.sh +48 -12
  150. package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
@@ -50,7 +50,14 @@ store read (`aliasesFor(token)` or `ambiguousHandles()`) that recall consults it
50
50
  Until then a caller that forgets the map silently loses the safety half — which is
51
51
  exactly the scar §2.6 shape, so this gap is the one to close first.
52
52
 
53
- ## 3. No document-frequency statistics on the cache — idf is approximated by probing
53
+ **The borrowed map, closed 2026-08-25 (noted 2026-10-09):** the composition root supplies
54
+ it. `core/retrieval.ts#composeTurn` sets `aliases` from `schemas.aliasMap()` (`d88f957`,
55
+ the wave-3 seam pass; schemas INTERFACE-GAPS §3), and `Counterpart`'s turn goes through
56
+ `recallTurn`, so that caller cannot forget it; `test/seams.test.ts` proves the composed
57
+ turn refuses the credit. The real fix above, a box-2 alias table recall reads itself, is
58
+ not built.
59
+
60
+ ## 3. No document-frequency statistics on the cache — idf is approximated by probing — CLOSED 2026-09-04 (noted 2026-10-09)
54
61
 
55
62
  **Owner:** `store/` (box 3).
56
63
  **Needed:** rarity weighting (§9 G4) needs `df(token)` over the index.
@@ -69,6 +76,11 @@ joined box 3 (cache schema v3) and `Store.search(cue, limit, norm)` takes the no
69
76
  constants, so the cue channel no longer has to pretend every document is the same size. The
70
77
  `df` half above is unchanged.
71
78
 
79
+ **The `df` half, closed 2026-09-04 (noted 2026-10-09):** `Store.docFrequency(tokens)` is
80
+ the single `GROUP BY token` over `doc_tokens` (`store/cache.ts#docFrequency`), and
81
+ `activate.ts` asks it for rarity before it probes for postings (`9991dec`, #28). The
82
+ workaround above is gone.
83
+
72
84
  ## 3a. `doc_tokens` outlives the memory — removed rows still count in `df` and `avgLen`
73
85
 
74
86
  **Closed 2026-09-24** — `store/cache.ts#deindexDoc` drops `doc_tokens` and `doc_lens` at archive and supersede; a removal rebuilds the cache (`cli/removal.ts`). A dead row's vector is a separate note (`recall/NOTES.md` §13).
@@ -85,6 +97,10 @@ where the deny-list entry is already written.
85
97
 
86
98
  ## 4. The observer predicate lives in `store/`
87
99
 
100
+ **Closed 2026-08-25 (noted 2026-10-09)** — the predicate lives in `src/core/observer.ts`
101
+ (hoisted in the wave-3 seam pass, `d88f957`), and `Recall.observer` still reads
102
+ `store.observer`, as below. Associate §8 closed the same way.
103
+
88
104
  Not a defect, and recorded so nobody "fixes" it: `Recall.observer` reads
89
105
  `store.observer` and never re-derives the predicate. `docs/observer-mode.md` G7 says a
90
106
  second definition is a leak waiting to happen — v1 shipped exactly that. If a second core
@@ -98,7 +114,7 @@ the store seam. Deciding which memories the reply actually used — assistant tu
98
114
  no model, no file reads, precision over recall — is §9.2's rule and was not implemented
99
115
  anywhere. **Closed:** `recall/reference.ts` decides (pure; expansions from recall tool
100
116
  calls, verbatim eight-word windows against what surfaced loud), `Counterpart.creditReferences`
101
- applies it through `resolveUses`, and `adapters/claude-code/hooks.ts#creditAtBoundary` calls
117
+ applies it through `resolveUses`, and `adapters/lifecycle.ts#creditAtBoundary` calls
102
118
  it on the slice capture just took, at every session-ending hook. Measured before the close
103
119
  (IMPROVEMENTS U10): 1,374 memories minted since launch, all at `uses = 0`. Proof:
104
120
  `test/lifecycle.test.ts` — the lifecycle through the adapter, the two fixtures (ids named
@@ -148,7 +164,8 @@ lagged cue itself (the hook does not embed the turn — `hooks.ts`'s to change,
148
164
  0.03 ms it now could). The MCP server's `note` no longer writes vectorless under the
149
165
  static table: `openServer` now hands the server's store the embedder's sync face and
150
166
  identity (mcp INTERFACE-GAPS §7's option 1, taken in #190 — that page still describes
151
- the gap as open and is its owner's to close).
167
+ the gap as open and is its owner's to close). *(Noted 2026-10-09: mcp §7 has read
168
+ CLOSED 2026-09-23 (#190) since #195.)*
152
169
 
153
170
  ## 7. Box 3 is 278 MB and 65% of it is JSON punctuation — NAMED, not fixed here
154
171
 
@@ -260,7 +277,10 @@ slips, lexical 10/10). Every number, the grid and the confirmation run:
260
277
  - One synthetic persona and builder-written queries; a lag embedded from the question
261
278
  alone; one topic-change partner per query.
262
279
  - The MCP `recall` tool builds rather than records, so its pair rides `BuildOutput.semantic`
263
- but reaches no telemetry ring until `server.ts` logs it.
280
+ but reaches no telemetry ring until `server.ts` logs it. *(Noted 2026-10-09: the premise
281
+ is gone. Since #323 (2026-10-03) a question goes to facts or meaning mode, neither of
282
+ which calls `Recall.build()`; the `mcp.recall` row names the semantic source, not the
283
+ floor and weight.)*
264
284
 
265
285
  ## 9. Whether a quiet pointer was USED is measured on one host only — OPEN 2026-09-28
266
286
 
@@ -272,6 +292,10 @@ pass shows pointers and never says whether they were used. Also: a pointer the m
272
292
  reads by title (a handle) counts only if the handle log translated it (G50), as for any
273
293
  expansion.
274
294
 
295
+ Since 2026-10-09 the same row scores every ambient showing, used or not, by lane (NOTES
296
+ §28), so recall's hit rate has the same reach: recorded where the credit pass runs, and
297
+ nowhere else.
298
+
275
299
  ## 10. Standing labels reach recall and ask, not the wake's lanes — CLOSED 2026-09-29
276
300
 
277
301
  `standing.ts` labels the ambient injection and the deliberate path (MCP `recall`, the
@@ -695,6 +695,7 @@ titled chapter against an untitled copy can fall under `NEAR_DUPLICATE` anyway.
695
695
  - **The dashboard**: its ask view had folded the pair the other way since round 3 (the
696
696
  memory, with a "from chapter …" link). It now receives the chapter alone and shows it as
697
697
  a journal row; `pages/memories/fold.js` still links a copy whose chapter was not shown.
698
+ (2026-10-09: `fold.js` and `/api/chapters` are gone; facts mode folds the pair itself.)
698
699
 
699
700
  ## 22. Recall by feeling, deliberate only — 2026-09-30 (U13 items 1 and 2)
700
701
 
@@ -754,7 +755,11 @@ never says it.
754
755
  feelings for, so it ranks nothing. Wrong-core repairs kept the writer's word but not the
755
756
  core they named, and an alias kept the wheel word (`touched` → `moved`) — both answer
756
757
  through the alias table, not the original input. No stemming (a light one since §25).
757
- Item 3 (a feeling's journey over time) is still open.
758
+ Item 3 (a feeling's journey over time) is still open. *(2026-10-09: item 3 is answered
759
+ by meaning mode, #322, merged 2026-10-03, in 0.3.12 — outside this module, at the MCP
760
+ layer (`mcp/meaning.ts`, mcp CONTRACT §6e): a person's, a project's or a feeling's
761
+ chapters in time order, each with its feelings by whose, and page 1 keeps the turns
762
+ where a feeling's valence changes sign.)*
758
763
 
759
764
  ## 23. The wheel v2 in recall — 2026-09-30
760
765
 
@@ -986,3 +991,67 @@ session.
986
991
  not a stretch (#307's reverted attempt: an idle tab opened early covered a sibling's
987
992
  note), so a first turn's note, before the session's first turn-end, stays unidentified
988
993
  on an old row; the write-time match is what fixes that going forward.
994
+
995
+ ## 27. An alias in a question reads as its wheel word (2026-10-02, lane B)
996
+
997
+ - `feelingWord` reads a wheel ALIAS as the word it stands for, and the question keeps the
998
+ word asked too: "fear" names `afraid`, so "when did the owner feel fear?" reaches a stamp
999
+ of scared or frightened (they answer to their group's word), not only an `afraid` stamp
1000
+ — the 0.3.10 release check's follow-up. The same for thankful → grateful, touched →
1001
+ moved, anger → angry. No frame is needed, as for any wheel word.
1002
+
1003
+
1004
+ ## Confidentiality, frozen (2026-10-02, owner)
1005
+
1006
+ The confidential class (`store/index.ts#confidentialByMeta`, CONTRACT §9) has no way in. No tool or entrance marks a memory confidential. Only a dream or reflection inheriting it from a source that is already confidential sets it. The owner's live store held 0 of 823 on 2026-10-02. The owner's ruling: freeze it. Keep the gates as they are, add no new plumbing for it, and don't treat it as a reason to block a review. The plan is to review it and remove it later. Privacy that matters is handled elsewhere today: directories opted out of Counterparts entirely, and the gate battery's credential redaction.
1007
+
1008
+ ## 28. Shown, and not used (2026-10-09)
1009
+
1010
+ Recall predicts on every turn that what it shows will help the reply, and a miss left no
1011
+ record per memory: the `recall.credit` row named what was credited (`ids`) and expanded
1012
+ (`expandedIds`), not what was quoted but refused, or shown and ignored. The association
1013
+ diagnosis of 10-02 could say the Hebbian path was nearly dark (`quoted` 0 and `expanded`
1014
+ 62 over the store's whole life), but not for which memories or which lane.
1015
+
1016
+ - **What is scored.** `Counterpart#creditReferences` takes every memory the session's gate
1017
+ state records as shown (loud, footnoted, or footnoted as a quiet pointer) after the
1018
+ session's `judged` mark. One is used when a reply this boundary expanded or quoted it:
1019
+ the resolver's uses before any refusal, because the prediction is "this will help",
1020
+ not "this will earn credit". The rest are shown and not used. The mark then moves to the
1021
+ session's newest recall turn, so each showing is scored once.
1022
+ - **The mark** is its own gate kind (`judged`, ref `credit`, `session.ts`), written only by
1023
+ the credit pass. `setGateRecords` upserts row by row, so recall's save, which names its
1024
+ own rows, cannot drop it; `loadGateState` skips it as it skips `asked`. Not written
1025
+ under observer.
1026
+ - **The row** carries `shownLoud`, `shownFootnotes`, `shownPointers`, `unusedLoud`,
1027
+ `unusedFootnotes`, `unusedPointers`, `shownNotUsed` (up to 64 ids, oldest showing first),
1028
+ `shownNotUsedTotal` and `judgedThrough`. Footnotes are the cued ones; a pointer counts
1029
+ as a pointer only. `probe-oq4` sums the lanes into a hit rate over the rows that carry
1030
+ them. A per-memory read (`shownNotUsed` joined to the session's `recall.decision` rows,
1031
+ which carry each showing's lane and turn) is left for a later reader; doctor does not
1032
+ read any of it yet.
1033
+ - **Measurement only.** No strength, threshold or ranking reads it.
1034
+ - *Choices and residuals:*
1035
+ - A showing is scored at the first boundary after it. One opened at a later boundary is
1036
+ counted once as not used (its own) and once as used (the later row's `expandedIds`):
1037
+ the score is of the reply it was shown for.
1038
+ - A boundary whose slice holds no reply and no expansion scores nothing and leaves the
1039
+ mark (review of #329): a capture that failed or found nothing new is not a reply
1040
+ that ignored what it was shown. Its showings wait for the next boundary that read a
1041
+ reply.
1042
+ - A session already open when this build arrived has no mark, so its first boundary
1043
+ scores everything that session showed (at most `MAX_SESSION_RECORDS`, at most 64 ids
1044
+ on the row). One over-count, toward more misses.
1045
+ - A mark that cannot be read scores from the session's start; one that cannot be
1046
+ written is scored again next time. Both over-count misses, never under-count.
1047
+ - On a `budget-exceeded` row a quote may have gone unchecked; a reader should leave
1048
+ those rows out.
1049
+ - After a gate reset (`recall.gate.reset`, an unreadable scalar row) the session's turn
1050
+ count starts again at 1 while the mark may sit higher, so its showings go unscored
1051
+ until the turns pass the mark: left out of the rate, not counted as hits. Rare, and
1052
+ the reset is evented.
1053
+ - A footnote can be used only by an expansion: it showed a title, and a title is not
1054
+ quotable (§9.2). The lane split keeps that from reading as a worse prediction.
1055
+ - Ambient recall only. A deliberate answer's memories (`asked`) are not in the gate
1056
+ state's `surfaced`, and are not scored.
1057
+ - Recorded only where the credit pass runs (INTERFACE-GAPS §9).
@@ -25,7 +25,8 @@
25
25
  * sad memory into a conversation nobody asked it into. A deliberate question is
26
26
  * the experiencer asking on purpose. Nothing here is read by `detectAffect`,
27
27
  * and `Recall.build` runs the lane only when the turn carries a `feeling` ask,
28
- * which only `mcp/deliberate.ts#answerQuestion` sets.
28
+ * which only a deliberate caller sets (the old question path until 2026-10-03;
29
+ * meaning mode's now, `mcp/meaning.ts`, when it asks).
29
30
  *
30
31
  * **Whose.** The table holds two: `owner` and `self`. First person means the
31
32
  * ASKER (the counterpart, through its `recall` tool; the owner, through the
@@ -163,6 +164,14 @@ export function feelingWord(
163
164
  w: string,
164
165
  stored: ReadonlySet<string> = new Set(),
165
166
  ): { word: string; superlative: boolean; via: "wheel" | "everyday" | "stem" } | null {
167
+ // AN ALIAS READS AS ITS WHEEL WORD (2026-10-02, lane B; 0.3.10's follow-up):
168
+ // "fear" is an alias of afraid, and read as itself it reached only a stamp
169
+ // of afraid — never scared or frightened, which answer to their group's
170
+ // word ("afraid"), not to its aliases. The question keeps the word asked too.
171
+ if (w.length >= 3 && Object.hasOwn(ALIASES, w)) {
172
+ const to = wheelEntry(ALIASES[w] as string)?.word;
173
+ if (to !== undefined) return { word: to, superlative: false, via: "wheel" };
174
+ }
166
175
  if (w.length >= 3 && (WHEEL_VOCABULARY.has(w) || stored.has(w))) return { word: w, superlative: false, via: "wheel" };
167
176
  if (Object.hasOwn(EVERYDAY_TO_WHEEL, w)) return { word: EVERYDAY_TO_WHEEL[w] as string, superlative: false, via: "everyday" };
168
177
  const known = (x: string): string | null => (STEMMABLE.has(x) ? x : null);
@@ -54,6 +54,7 @@ export * from "./render.js";
54
54
  export * from "./session.js";
55
55
  export * from "./standing.js";
56
56
  export * from "./recency-ask.js";
57
+ export * from "./time-ask.js";
57
58
  export * from "./tunables.js";
58
59
  export { activate, isConfidential, isHandoff, isSelfPage, gatedSal, recordedIdentity, salienceRank } from "./activate.js";
59
60
  export type { FeelingLane, SpreadFn, SpreadStats } from "./activate.js";
@@ -133,7 +134,8 @@ export interface Turn {
133
134
  /**
134
135
  * A DELIBERATE question, which may be about feeling (2026-09-30, U13): who is
135
136
  * asking, and the owner's names. Set only by the deliberate ask
136
- * (`mcp/deliberate.ts#answerQuestion`); absent on every ambient turn, so the
137
+ * (the old `mcp/deliberate.ts#answerQuestion` until 2026-10-03; meaning
138
+ * mode's now, when it asks); absent on every ambient turn, so the
137
139
  * feeling lane (`activate.ts`, `feeling-ask.ts`) never runs there and the
138
140
  * ambient affect gates (§9 G10/G11) are untouched.
139
141
  */
@@ -24,6 +24,13 @@
24
24
  * recorded what was expanded, so nothing is known. Zero and unknown never
25
25
  * share a glyph.
26
26
  *
27
+ * THE HIT RATE (2026-10-09) rides the same rows: a `recall.credit` row now
28
+ * scores the ambient showings since the session's last boundary that judged —
29
+ * loud, footnoted and pointer, and how many of each no reply expanded or
30
+ * quoted (`shownNotUsed` holds their ids, for a per-memory read later). The
31
+ * probe sums the lanes over the rows that carry the counts. Rows from before
32
+ * carry none and are left out, so the line says how many boundaries it rests on.
33
+ *
27
34
  * What this does NOT claim: causation. A session that expanded nothing may
28
35
  * have had nothing worth expanding. The probe answers "did the behaviour move
29
36
  * when the string moved", which is the question OQ4 asks, and leaves the
@@ -86,6 +93,24 @@ export interface ProbeReport {
86
93
  };
87
94
  /** Days with decision rows and no credit row, and the footnotes they delivered. */
88
95
  readonly unmeasured: { readonly days: number; readonly footnotesDelivered: number };
96
+ /**
97
+ * RECALL'S HIT RATE (2026-10-09): what the boundaries that score their
98
+ * showings say — each ambient showing scored once, at the first boundary
99
+ * after it, as used (expanded or quoted) or not, by lane. Credit rows from
100
+ * before carry no score and are not counted here: `boundaries` 0 is unknown,
101
+ * not a rate of zero.
102
+ */
103
+ readonly hits: {
104
+ readonly boundaries: number;
105
+ readonly shown: { readonly loud: number; readonly footnotes: number; readonly pointers: number };
106
+ readonly unused: { readonly loud: number; readonly footnotes: number; readonly pointers: number };
107
+ };
108
+ }
109
+
110
+ /** A finite count off a payload, or null when the row does not carry it. */
111
+ function count(p: Record<string, unknown>, key: string): number | null {
112
+ const v = p[key];
113
+ return typeof v === "number" && Number.isFinite(v) ? v : null;
89
114
  }
90
115
 
91
116
  interface Acc {
@@ -115,6 +140,9 @@ export function probeOQ4(rows: readonly ProbeRow[]): ProbeReport {
115
140
  let decisions = 0;
116
141
  let credits = 0;
117
142
  let unparseable = 0;
143
+ let scored = 0;
144
+ const shown = { loud: 0, footnotes: 0, pointers: 0 };
145
+ const unused = { loud: 0, footnotes: 0, pointers: 0 };
118
146
  const get = (session: string, date: string | null): Acc => {
119
147
  let a = acc.get(session);
120
148
  if (a === undefined) {
@@ -150,6 +178,20 @@ export function probeOQ4(rows: readonly ProbeRow[]): ProbeReport {
150
178
  credits += 1;
151
179
  a.credits += 1;
152
180
  for (const id of ids(p["expandedIds"])) a.expanded.add(id);
181
+ // A row scores its showings only when it carries all six counts.
182
+ const lanes = [
183
+ ["loud", "shownLoud", "unusedLoud"],
184
+ ["footnotes", "shownFootnotes", "unusedFootnotes"],
185
+ ["pointers", "shownPointers", "unusedPointers"],
186
+ ] as const;
187
+ const got = lanes.map(([, s, u]) => [count(p, s), count(p, u)] as const);
188
+ if (got.every(([s, u]) => s !== null && u !== null)) {
189
+ scored += 1;
190
+ lanes.forEach(([lane], i) => {
191
+ shown[lane] += got[i]?.[0] ?? 0;
192
+ unused[lane] += got[i]?.[1] ?? 0;
193
+ });
194
+ }
153
195
  }
154
196
  }
155
197
 
@@ -210,6 +252,7 @@ export function probeOQ4(rows: readonly ProbeRow[]): ProbeReport {
210
252
  days: unmeasuredDays.length,
211
253
  footnotesDelivered: unmeasuredDays.reduce((n, d) => n + d.footnotesDelivered, 0),
212
254
  },
255
+ hits: { boundaries: scored, shown, unused },
213
256
  };
214
257
  }
215
258
 
@@ -235,5 +278,20 @@ export function renderProbe(report: ProbeReport): string[] {
235
278
  `unmeasured: ${report.unmeasured.days} day(s) with no recall.credit row, ${report.unmeasured.footnotesDelivered} footnotes delivered — "-" is unknown, not zero`,
236
279
  );
237
280
  }
281
+ lines.push("");
282
+ const h = report.hits;
283
+ if (h.boundaries === 0) {
284
+ lines.push("hit rate: - (no recall.credit row scores what recall showed yet)");
285
+ } else {
286
+ const lane = (name: string, s: number, u: number): string =>
287
+ `${name} ${s - u} of ${s} used${s === 0 ? "" : ` (${(((s - u) / s) * 100).toFixed(1)}%)`}`;
288
+ lines.push(
289
+ `hit rate, over ${h.boundaries} boundar${h.boundaries === 1 ? "y" : "ies"} that scored what recall showed: ${[
290
+ lane("loud", h.shown.loud, h.unused.loud),
291
+ lane("footnotes", h.shown.footnotes, h.unused.footnotes),
292
+ lane("pointers", h.shown.pointers, h.unused.pointers),
293
+ ].join(", ")}`,
294
+ );
295
+ }
238
296
  return lines;
239
297
  }
@@ -47,7 +47,47 @@ export const GATE_STATE_VERSION = 1;
47
47
 
48
48
  /** The `gate_session.kind` vocabulary this module owns. `window` is
49
49
  * `prospective/`'s (INTERFACE-GAPS.md §3) and is deliberately not read here. */
50
- export const GATE_KINDS = ["surfaced", "credited", "scalar", "semantic"] as const;
50
+ export const GATE_KINDS = ["surfaced", "credited", "scalar", "semantic", "asked", "judged"] as const;
51
+ /**
52
+ * `asked` (Release B, 2026-10-03): a memory a deliberate QUESTION's answer
53
+ * showed with its words, for this session — quotable at the boundary
54
+ * (`Counterpart#creditReferences`), as a loud surfacing is. Its own kind, so
55
+ * the ambient gate never reads it: `loadGateState` takes `surfaced` and
56
+ * `credited` only, and a deliberate answer must not dedup or train the
57
+ * ambient turn. `turn` holds the moment it was shown, in seconds, so the
58
+ * newest come first; `ASKED_MAX` of them are read.
59
+ */
60
+ export const ASKED_KIND = "asked";
61
+ /** How many `asked` records the boundary reads, newest first. */
62
+ export const ASKED_MAX = 200;
63
+
64
+ /** An `asked` record's `turn`: the moment, in whole seconds (ms do not fit the column's meaning). */
65
+ export function askedTurn(nowMs: number): number {
66
+ return Math.floor(nowMs / 1000);
67
+ }
68
+ /**
69
+ * `judged` (2026-10-09): how far the boundary's credit pass has scored this
70
+ * session's ambient showings. One row (`ref` `JUDGED_REF`) whose `turn` is the
71
+ * last recall turn a boundary judged, so each showing is scored once, at the
72
+ * first boundary after it: used (expanded or quoted) or shown and not used, on
73
+ * that boundary's `recall.credit` row. Measurement only. Its own kind, written
74
+ * only by the credit pass: recall's save names its own rows and cannot drop
75
+ * this one, and the ambient gate never reads it.
76
+ */
77
+ export const JUDGED_KIND = "judged";
78
+ export const JUDGED_REF = "credit";
79
+
80
+ /** The last recall turn a boundary judged for this session; 0 when none has
81
+ * (including a session older than the row). */
82
+ export function judgedThrough(store: Store, sessionId: string): number {
83
+ return store.gateRecords(sessionId, JUDGED_KIND).find((r) => r.ref === JUDGED_REF)?.turn ?? 0;
84
+ }
85
+
86
+ /** Move the session's `judged` mark to `turn`. A gate write like any other, so
87
+ * an observer's store refuses it; the caller moves it forward only. */
88
+ export function markJudged(store: Store, sessionId: string, turn: number, day: number): void {
89
+ store.setGateRecords([{ sessionId, kind: JUDGED_KIND, ref: JUDGED_REF, turn, lastDay: day }]);
90
+ }
51
91
  /** The one `scalar` row: the fields that are not per-memory. */
52
92
  export const SCALAR_REF = "state";
53
93
  /** The one `semantic` row: last turn's embedding cue, resolved to neighbours. */
@@ -125,7 +165,11 @@ interface ScalarPayload {
125
165
  }
126
166
 
127
167
  export function loadGateState(store: Store, sessionId: string, max = Infinity): LoadResult {
128
- const rows = store.gateRecords(sessionId);
168
+ // `asked` rows (a deliberate answer's, 2026-10-03) are not the ambient
169
+ // gate's: a session whose only rows are those has no gate state yet, and
170
+ // must read `absent`, not `unreadable`. The credit pass's `judged` mark
171
+ // (2026-10-09) is not the gate's either.
172
+ const rows = store.gateRecords(sessionId).filter((r) => r.kind !== ASKED_KIND && r.kind !== JUDGED_KIND);
129
173
  if (rows.length === 0) return { state: freshGateState(sessionId), status: "absent" };
130
174
 
131
175
  const scalarRow = rows.find((r) => r.kind === "scalar" && r.ref === SCALAR_REF);