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,151 @@
1
+ # `encode/` — CONTRACT
2
+
3
+ ## 1. Purpose
4
+
5
+ What gets in: the gate battery every proposal passes, the salience tags it carries, and
6
+ the computed novelty that makes prediction error a number.
7
+
8
+ ## 2. Brain analog
9
+
10
+ Attention selecting what is worth encoding, plus amygdala tagging that marks emotional
11
+ material for preferential consolidation. **Named deviation** (constitution line 12): the
12
+ secrets gate has no biological analog — the brain has no interlock that refuses to encode
13
+ a credential. It is a deliberate, non-ablatable addition.
14
+
15
+ ## 3. Keeps
16
+
17
+ - **The gate battery, all five checks, engine-side, no model in the loop.** [v1]
18
+ behavioral-spec §3: **secrets** (redact; empty after redaction ⇒ reject), **precision**
19
+ (auto-hedge dates, years, and quoted strings not in the source — softening, never
20
+ dropping), **aliases** (must occur verbatim in the source, *and then pass their own
21
+ secrets scan*), **emotion** (stated-only: a cited quote the span contains plus a named
22
+ subject; the quote is stripped before the feeling becomes durable), **content floor**
23
+ (empty / stub token matched exactly after normalization / under a minimum length ⇒
24
+ refused as degenerate).
25
+ - **The content floor as a named earned mechanism.** [v1] earned-mechanism #3 — v1's
26
+ model-bake-off minted a literal `"placeholder"` trace that passed every other gate.
27
+ v1 calibration: 20 characters / 3 words, set at about half the shortest real memory in
28
+ its own fixtures. TUNABLE.
29
+ - **A fully-gated chunk moves NO durable state** — not strength, not `uses`, not a
30
+ revision, not an entity mention. [v1] §3 G2, earned-mechanism #15.
31
+ - **Gates run on proposals, before anything is durable** — never as a post-hoc sweep.
32
+ [v1] §3 G3.
33
+ - **A refused proposal is not a failed batch.** Rejection is data. [v1] §3 G6.
34
+ - **The emotion exemption cannot widen**: exactly one recognized provenance — the author
35
+ stating its own feeling about its own span. A claim about someone else's interior always
36
+ takes the ordinary path, where a transcript exists to check it against. [v1] §3 G5.
37
+ - **Ops carry their own rules**: a secret in a *name* rejects the whole operation ("a
38
+ credential must never become an entity the store indexes"); a matching key that never
39
+ persists is exempt from hedging ("a name is not a claim"). [v1] §3.
40
+ - **Four-dimensional salience tagged at write time.** [v0] `{novelty, relevance,
41
+ emotional, predictive}`, each 0–1, scored once, fixed at birth.
42
+ - **Novelty is prediction error against schema expectations** — computable, not a model
43
+ opinion. [v0 dimension, v1 mechanism] §8; the number and its inputs live in
44
+ `physics/` §5.2.
45
+ - **Encode-time preselection, two channels UNIONED.** [v1] §8, earned-mechanism #1: a
46
+ precise lexical channel (name or alias, **as a whole word**) that never gives ground,
47
+ plus a semantic channel that only ever *adds*. Whole-word matching has **one definition,
48
+ shared with entity birth**.
49
+ - **Blindness is measured, not assumed.** [v1] §8 G5, scar §2.9 — every chunk shown zero
50
+ schemas is counted, with per-channel attribution by id, not by count.
51
+ - **Beliefs and current state render verbatim; identity core renders compressed.** [v1]
52
+ §8 G7 — "a paraphrase of a belief cannot be honestly confirmed or contradicted."
53
+ - **Emotion is typed, attributed, and absent-means-null, never neutral. Retro-typing
54
+ emotion is forbidden.** [v1] §4.2 G5.
55
+ - **Task-state is not memory**, discriminated at encode time by one question: *would this
56
+ still be a true memory worth holding after the date passes?* [v1] §4.2 G10.
57
+
58
+ ## 4. Drops / simplifies
59
+
60
+ - **The interpreter's closed operation vocabulary shrinks to what the experiencer can
61
+ actually declare**: content, salience, kind, scope, feeling, aliases, handles,
62
+ `updates:`, `unresolved`. Belief-supersede, protected-add, thread-open/close, and
63
+ schema-create leave the vocabulary — revision is `updates:` (owner decision, settled),
64
+ entities are born by mention (owner decision, settled), and loops are ordinary memories
65
+ with an `unresolved` flag (v1's own recorded v2 direction, §6.3).
66
+ - **The self-store tool's salience clamp survives; the tool does not.** The v1 self-store
67
+ is **superseded by** experiencer authorship — self-writing became the primary path, not
68
+ a channel the model must remember to call. The clamp (a claimed salience is a floor,
69
+ mechanized) moves to `physics/` §5.2, where it now governs *every* memory rather than
70
+ one tool's output.
71
+ - **Substring name matching is gone** (v1 measured the cost: the self schema is *named*
72
+ "self", so 21% of its matches came from the English inside "myself" and
73
+ "self-contained"). Whole-word only, one definition. Settled by measurement.
74
+ - **Emotion classification does not ship enabled.** It re-earns its ≥0.80 fired-cue
75
+ precision bar against a held-out reference set before the channel turns on (§17.3: "do
76
+ not enable a channel on a rewrite's promise").
77
+
78
+ ## 5. Contract
79
+
80
+ **Inputs** — a proposal (content, author-claimed salience, kind, scope, optional feeling
81
+ with its quote and subject, optional aliases, optional `updates:`), the source span, the
82
+ schema slice the proposal was encoded against, the lived day.
83
+ **Outputs** — an accepted-and-possibly-redacted proposal, or a refusal with a reason;
84
+ computed novelty or an explicit null; per-channel preselection attribution; gate
85
+ telemetry by reference.
86
+
87
+ **Guarantees** — **[M]** mechanized, **[A]** advisory:
88
+
89
+ 1. **[M] The secrets gate is not ablatable.** No off switch, no A/B arm, no bypass —
90
+ enforced by a universality test that source-scans every caller of the paths where text
91
+ becomes canonical, including every outpost. *A prompt is not exempt from the gate.*
92
+ 2. **[M] All five checks run on every proposal**, in one battery, before anything durable.
93
+ 3. **[M] A fully-gated proposal moves zero durable state**, asserted per state kind, not
94
+ per happy path.
95
+ 4. **[M] Aliases pass their own secrets scan** after the verbatim-in-source check.
96
+ 5. **[M] The emotion exemption is set per proposal by the engine that minted it**,
97
+ evaluated against that proposal's own span, only when the subject is the author itself
98
+ and the feeling is non-empty.
99
+ 6. **[M] Every stated privilege is mechanized or is not stated.** v1's plain "remember
100
+ this" note claimed a high-salience floor **only in its prompt**, with no engine
101
+ backstop — the one place a stated guarantee had no enforcement (§4.1 known gap). Here
102
+ the floor is the clamp in `physics/` §5.2, and the prompt states nothing the engine does
103
+ not enforce.
104
+ 7. **[M] Preselection happens once per chunk**, so the prompt builder and the blind-rate
105
+ counter can never disagree about what the author saw.
106
+ 8. **[M] The semantic channel is degradable by construction**: no embedder, no cached
107
+ vectors, or an embedding failure yields an empty semantic set and a **loud skip** —
108
+ never a thrown chunk. Worst case is exactly lexical-only. *Deliberately off is silence;
109
+ a failure is a skip*, and the two are distinguishable in telemetry.
110
+ 9. **[M] Zero-context encoding is counted and its output is measured**, not invisible.
111
+ v1's residual blind rate was ~a fifth to a quarter of chunks and 7 blind chunks minted
112
+ 16 real memories.
113
+ 10. **[M] Every gate firing is content-by-reference**: gate name, kind, hashes. Never the
114
+ secret, the quote, or the body.
115
+ 11. **[M] Three distinct records per gate**: "rejected", "refused by design", and "never
116
+ invoked" — the by-design case flagged structurally **at the refusal site**, never
117
+ inferred later by pattern-matching a message (scar §2.4).
118
+ 12. **[A] Hedge phrasings, the stub vocabulary, and the floor's exact minimums are
119
+ preferences.** That the floor *exists* is mechanized.
120
+ 13. **[M] Every threshold here ships with a recorded calibration against a real corpus and
121
+ a fixture-bounded window naming what breaks on each side, or ships disabled**
122
+ (scar §2.8).
123
+
124
+ ## 6. Scars honored
125
+
126
+ **E1** (the preselection semantic channel degrades to empty, never throws) · **§2.6**
127
+ (mechanize invariants; instruct only preferences — guarantee 6 is this scar's direct
128
+ descendant) · **§2.7** (a gate covers every ingestion path *and every side-channel*) ·
129
+ **§2.8** (no threshold ships unmeasured) · **§2.9** (the encoder must see what its output
130
+ can affect, and context assembly logs what it showed, by id and by channel) · **§2.14**
131
+ (a degenerate-but-well-formed proposal is rejected by the content floor) · **§2.16**
132
+ (every model-facing operation carries an admission test and a named negative example) ·
133
+ **§2.20** (content-by-reference at the gate boundary).
134
+
135
+ ## 7. Open questions
136
+
137
+ 1. **The `encode`/`remember` boundary — one of the module map's three standing check-in
138
+ questions.** With the experiencer's end-of-session write as the primary path, span
139
+ capture survives mainly as crash-fallback input. Does `encode` shrink to
140
+ gates-and-tagging *inside* `remember`'s pipeline, leaving no separate module? The
141
+ argument for keeping it separate is that the gate battery is the one thing every
142
+ entrance must traverse (scar §2.7), and a module boundary is the cheapest way to make
143
+ "every entrance" checkable. The argument against is constitution line 10: one brain
144
+ function per module, and attention-plus-tagging is arguably part of encoding, not
145
+ beside it. **Left open deliberately.**
146
+ 2. **Does the semantic preselection floor need recalibrating for a different text
147
+ length?** v1's 0.60 floor was calibrated on trace-length text and applied to
148
+ chunk-length text; the harvest names the dilution risk and never resolved it.
149
+ 3. **Is precision-hedging still the right shape** when the author is the mind that lived
150
+ the session rather than a sweep reading a transcript? Hedging is a confabulation brake,
151
+ and the confabulation risk is lower in-the-moment — but not zero.
@@ -0,0 +1,135 @@
1
+ # `encode/` — interface gaps for the coordinator
2
+
3
+ *What `encode/` needed from another module and could not have, and what another
4
+ module will need from `encode/` before the wiring can be right. Nothing here is
5
+ implemented in `encode/` — the whole point is that these are decisions for the
6
+ seam, not for one side of it.*
7
+
8
+ ## 0. Nothing was stubbed
9
+
10
+ `physics/` and `store/prose.ts` covered every arithmetic and content-address need:
11
+ `clampSalienceAtSeam`, `novelty`, `cosine`, `sal`, and `hashText` were all present
12
+ and all sufficient. **No local stub of a store or physics API exists in this
13
+ module**, and encode imports exactly one symbol from `store/` (`hashText`, from
14
+ `store/prose.js`) — a test asserts that is the only one.
15
+
16
+ ## 1. `remember/`'s `GateFn` seam does not carry enough to keep encode's guarantees
17
+
18
+ `remember/proposals.ts` declares the injected `GateFn` it will call, and
19
+ `remember/INTERFACE-GAPS.md` §2 names it as the wiring point. Its shape and
20
+ encode's do not line up, and **four of the mismatches are load-bearing** — a
21
+ straight adapter over the current `GateInput`/`GateVerdict` would silently drop a
22
+ mechanized guarantee. Listed worst first.
23
+
24
+ ### (a) BLOCKING — the chunk-level guarantee has no chunk
25
+
26
+ `GateFn` is per proposal. **"A fully-gated chunk moves NO durable state" (encode
27
+ §5 G3, scar §7b) is a CHUNK-level property**: it is scoped to *all-rejected*, and
28
+ it is what closes the element-level side channel — prediction checks, entity
29
+ mentions, and warmth updates from a chunk whose proposals were all refused.
30
+
31
+ A per-proposal gate cannot express it. Either:
32
+
33
+ - **preferred** — `remember/` calls `encodeChunk()` once per chunk and honors
34
+ `result.effects` / `result.predictionChecks` (both empty when `fullyGated`); or
35
+ - `remember/` keeps `GateFn` for the per-proposal battery **and** takes on the
36
+ all-rejected rule itself, in which case that rule needs its own test on
37
+ `remember/`'s side and the scar is now guarded in two places.
38
+
39
+ The first is what encode is shaped for: `encodeChunk` is the module's one
40
+ chokepoint, and it already returns the per-proposal verdicts `remember/` wants.
41
+
42
+ ### (b) BLOCKING — the emotion exemption cannot be set
43
+
44
+ Encode §5 G5: the exemption is **set per proposal by the engine that minted it**,
45
+ and encode never infers it. `GateInput` has no field for it. As written, every
46
+ self-authored feeling with no citable quote comes back `quote-missing` and the
47
+ feeling is dropped — the doctrine survives, the channel starves.
48
+
49
+ **Add to `GateInput`:** `selfAuthored?: boolean`. (`source: "jot" | "session-end"`
50
+ is not a substitute: an end-of-session dump can carry a feeling about the *owner*,
51
+ which must take the ordinary path.)
52
+
53
+ ### (c) The claimed-salience floor is not reachable through this seam
54
+
55
+ Encode §5 G6 exists because v1's "remember this" note claimed a salience floor
56
+ **only in its prompt**, with no engine backstop. The clamp lives at the
57
+ proposal→memory seam (`tagSalience` → `physics.clampSalienceAtSeam`) and emits
58
+ `salience.lifted` on any lift.
59
+
60
+ `GateInput` carries no `claimedSalience` and no dimensions, and `GateVerdict`
61
+ carries no salience back — so through this seam the floor is once again stated
62
+ somewhere and enforced nowhere. **Add `claimedSalience?: number | null` and
63
+ `dimensions?: {relevance, emotional, predictive}` to `GateInput`, and `salience`
64
+ to the `ok` verdict** — or route through `encodeChunk`, which already does it.
65
+
66
+ ### (d) The ops rule has no input
67
+
68
+ Encode refuses the whole proposal when a *name or handle* carries a credential
69
+ ("a credential must never become an entity the store indexes"). `GateInput` has no
70
+ `handles` field, so that refusal can never fire through this seam. **Add
71
+ `handles?: readonly string[]`.**
72
+
73
+ ### (e) Lossy telemetry on refusal
74
+
75
+ `GateVerdict`'s failure arm is `{ ok: false; gate: string; reason: string }` — one
76
+ gate, one reason. Encode returns `blockedBy` (every blocking reason) plus one
77
+ `GateRecord` per gate, always, including the `not-invoked` / `refused-by-design` /
78
+ `rejected` distinction that guarantee 11 and scar §2.4 exist for. Collapsing that
79
+ to a single string throws away the by-design flag *at the refusal site*, which is
80
+ precisely the thing §5 G11 says must never be re-derived by pattern-matching a
81
+ message later.
82
+
83
+ **Suggest:** `{ ok: false; gate: string; reason: string; blockedBy: string[];
84
+ records: GateRecord[] }`. Additive; the existing two fields keep their meaning
85
+ (`gate`/`reason` = the first blocker).
86
+
87
+ ### (f) `span: null` is a silent capability loss, not an error
88
+
89
+ Encode checks aliases *verbatim in the source* and quotes *contained in the span*.
90
+ With `span: null`, every alias is dropped (`alias-not-verbatim-in-source`) and
91
+ every non-exempt feeling is refused (`quote-not-in-span`). That is the correct
92
+ conservative behavior, but it should be a **named, counted** condition at the
93
+ wiring site rather than a surprise in the alias-drop rate. Recommend the adapter
94
+ log a `gate.no-span` event when it passes a null span.
95
+
96
+ ### (g) Cosmetic
97
+
98
+ `GateInput.feeling` spells the type word `feeling`; encode's `Feeling` spells it
99
+ `type` (with `quote`, `subject`). `GateInput` has no proposal handle; encode's
100
+ `Proposal.ref` needs one — the span hash or the buffer index will do. Both are
101
+ adapter-local renames.
102
+
103
+ ## 2. `schemas/` must import encode's whole-word matcher, not write its own
104
+
105
+ behavioral-spec §8 G3 requires **one** whole-word definition, shared between
106
+ preselection and entity birth: "Birth must test a proposed name by *exactly* the
107
+ rule preselection uses, or the two drift and a name that 'was in the span' for one
108
+ is not for the other."
109
+
110
+ That definition is `encode/words.ts`, exported as `occursAsWholeWord`,
111
+ `wholeWordRegex`, `countWholeWord`, and `escapeRegExp`. **`schemas/` should import
112
+ them from `encode/`** rather than re-deriving the boundary rule. The rule is
113
+ subtle in exactly one way that matters: hyphens and apostrophes count as word
114
+ characters, which is what makes `self` fail to match `self-contained` — v1's
115
+ measured 21% false-positive rate on the self schema.
116
+
117
+ If the coordinator would rather this live in a neutral place, the file has no
118
+ dependencies and moves cleanly; what must not happen is two copies.
119
+
120
+ ## 3. Not a gap, but the coordinator owns it: the caller-side universality test
121
+
122
+ Encode §5 G1's full form source-scans **every caller** of the paths where text
123
+ becomes canonical, "including every outpost". Encode's own suite proves the half
124
+ that does not need callers (no disable flag exists; every text-returning export
125
+ redacts its output; an invented bypass option throws). The other half — enumerate
126
+ every entrance (steady state, migration, import, repair, replay harness, each
127
+ adapter) and assert each traverses the battery — is a **suite-level test that
128
+ belongs to the coordinator**, once there are entrances to enumerate. It is the
129
+ test that would have caught v1's ungated migration path and its three live keys.
130
+
131
+ ## 4. `store/` LAYOUT — already filed by `remember/`
132
+
133
+ `remember/INTERFACE-GAPS.md` §1 asks `store/paths.ts` to classify `spans/`.
134
+ `encode/` does not touch the data dir and has no stake in the outcome; noted only
135
+ so the coordinator does not read two lists and count it twice.
@@ -0,0 +1,146 @@
1
+ # `encode/` — NOTES
2
+
3
+ Working notes beside the contract. **`CONTRACT.md` is the spec; this file never
4
+ edits it.** Where the contract was silent, or where two readings were available,
5
+ the choice made in the code is recorded here so the next reader does not have to
6
+ re-derive it — and so the owner can overrule any of it cheaply (constitution
7
+ line 13: decisions are defaults).
8
+
9
+ *(First build, 2026-08-25.)*
10
+
11
+ ## Ambiguities resolved — simplest reading, recorded
12
+
13
+ 1. **Encode returns INTENTS; it never writes.** The contract says a fully-gated
14
+ proposal moves zero durable state, but never says who moves state on the happy
15
+ path. Simplest reading: encode is pure, and its entire output surface for
16
+ durable change is `DurableEffect[]`, which `remember/` applies. That makes
17
+ guarantee 3 structural — encode holds no store handle, so "moves zero durable
18
+ state" is not a discipline anyone has to keep — and it makes the enumeration
19
+ scar §7 asks for cheap: the effect union names every state kind a chunk could
20
+ move, so the test asserts per state kind rather than per happy path.
21
+
22
+ 2. **The universality test is a two-part promise, and only one part can exist
23
+ yet.** Guarantee 1's full form source-scans *every caller* of the paths where
24
+ text becomes canonical, "including every outpost". `remember/`, the adapters,
25
+ and any import path do not exist yet, so that half is **deferred to the
26
+ coordinator** — it is a suite-level test, not an `encode/` test. What ships
27
+ here instead is the half that does not depend on callers: **every
28
+ text-returning export of this module runs its output through `redactSecrets`
29
+ before returning**, whatever order a caller invoked things in. A caller that
30
+ reaches past the battery still cannot get an unredacted string out.
31
+
32
+ 3. **Non-ablatability is enforced four ways, none of them a comment.** (a) No
33
+ function in `secrets.ts` takes an options object, so there is nowhere to put a
34
+ flag; (b) `SecretsGateStatus` excludes `"stood-down"`, so the disabled state
35
+ is not representable in telemetry; (c) `assertNoSecretsBypass()` refuses at
36
+ runtime any option key matching `/secret|redact|credential/i`, which stops an
37
+ untyped JavaScript caller too; (d) the output-side redaction of (2).
38
+
39
+ 4. **"All five checks run" is literal — no short-circuit on refusal.** The
40
+ battery runs precision, aliases, emotion, and the floor even after secrets has
41
+ already rejected the proposal. A short-circuit would report one reason and hide
42
+ three, and "all five ran" would stop being checkable from the records. Cost:
43
+ a few microseconds on a proposal that is going to die anyway.
44
+
45
+ 5. **Refusal reasons collect like physics' verdicts.** `blockedBy` carries every
46
+ blocking reason and `reason` is the first — the same shape as
47
+ `promotionEligibility()` and `pruneVerdict()`. An all-secret proposal reports
48
+ BOTH `empty-after-redaction` and `content-empty`, because both are true.
49
+
50
+ 6. **A secret is never hashed.** The contract's telemetry vocabulary says "gate
51
+ name, kind, hashes", but `hashText()` of a low-entropy credential is
52
+ reversible — the store already names this hazard (§16 G9, `RemovalNote`
53
+ carries no content hash for exactly this reason). Findings therefore carry
54
+ **family + count + site**, and the only hash logged is the hash of the
55
+ REDACTED content.
56
+
57
+ 7. **Whole-word matching is case-insensitive, with no option.** "Verbatim in the
58
+ source" is a claim about the words, not about the shift key. An option is how
59
+ two callers drift apart, and §8 G3 requires *one* definition shared with schema
60
+ birth — so `occursAsWholeWord()` takes no flags. `schemas/` must import it
61
+ rather than write its own.
62
+
63
+ 8. **Hyphens and apostrophes are word characters.** This is what makes "self" fail
64
+ to match "self-contained" — v1's measured false positive, worth 21% of the self
65
+ schema's matches. It also means a hyphenated name ("claude-code") matches as
66
+ one word, which is the behavior you want anyway.
67
+
68
+ 9. **A secret in an alias DROPS THE ALIAS; a secret in a name REJECTS THE
69
+ PROPOSAL.** Both come from §3, and the asymmetry is deliberate: an alias is a
70
+ retrieval handle, so losing it costs a retrieval, while a *name* becomes an
71
+ entity the store indexes, and "a credential must never become an entity the
72
+ store indexes" is the ops rule. Aliases and handles are both exempt from
73
+ *hedging* ("a name is not a claim") and neither is exempt from the secrets scan.
74
+
75
+ 10. **Precision hedging runs in ONE pass over the original content.** A second
76
+ pass turns "mid-July 2026" into "mid-July around 2026". Alternation order is
77
+ therefore load-bearing: a quoted region is consumed whole before anything
78
+ inside it is considered, and a month+year is consumed before the bare year
79
+ inside it can be hedged separately.
80
+
81
+ 11. **Month+year is consumed but not changed.** Month-level *is* the hedge
82
+ granularity v1 chose ("mid-July"), so "July 2026" is already at the target
83
+ precision. It is matched only so the `2026` inside it cannot be separately
84
+ hedged to "around 2026".
85
+
86
+ 12. **The floor measures redaction-stripped text.** `[REDACTED:google-api-key]` is
87
+ 26 characters of nothing; counting it would let a proposal that was entirely
88
+ a credential clear a length floor. Stripping first is also what makes an
89
+ all-secret proposal report both of its true reasons (note 5).
90
+
91
+ 13. **The emotion exemption waives the quote requirement, nothing else.** §5 G5
92
+ says the exemption is evaluated "against that proposal's own span, only when
93
+ the subject is the author itself and the feeling is non-empty". Reading: when
94
+ the span *is* the author stating its own feeling, requiring a citation from
95
+ the span is circular, so the citation is waived — the type and subject
96
+ requirements are not. A flag set on a claim about someone else's interior is
97
+ `exemption-not-available`, refused at the refusal site.
98
+
99
+ 14. **No emotion classifier is built.** §4 says the channel does not ship enabled
100
+ until it re-earns a ≥0.80 fired-cue precision bar. Building it disabled would
101
+ be machinery in anticipation of a failure (Amendment 15), so it does not
102
+ exist — and because it does not exist, `emotionClassifierRecord(true)` reports
103
+ `skipped`, not `ran`. Asking for a channel that is not there is loud; leaving
104
+ it off is silence.
105
+
106
+ 15. **Novelty is computed against the SHOWN slice, not against every schema.**
107
+ Prediction error is error against what the author could actually see; a schema
108
+ preselection never showed cannot have been predicted from. A consequence worth
109
+ naming: a blind chunk has a null novelty *by construction*, so the blind rate
110
+ and the null-novelty rate are the same measurement, which is the property
111
+ §5 G7 wants (the prompt builder and the counter cannot disagree).
112
+
113
+ 16. **Task-state discrimination is not a battery gate.** §3 keeps "task-state is
114
+ not memory, discriminated at encode time by one question: would this still be
115
+ a true memory worth holding after the date passes?" That question is answered
116
+ by the *author*, not by an engine-side check — there is no computable test for
117
+ it — so it belongs to `remember/`'s authorship ask and `prospective/`'s
118
+ arming, not to a gate that runs with no model in the loop. Named here so the
119
+ omission is a decision rather than an oversight.
120
+
121
+ 17. **Observer suppresses effects but still computes.** Encode holds nothing
122
+ durable, so there is no store seam here to refuse at; the honest v2 shape is
123
+ that an instrument may *measure* the gates and emits no intents. The
124
+ stand-down is logged (`encode.observer.standdown`), so a stood-down instrument
125
+ stays distinguishable from a broken hook (scar E7, observer-mode G5/G6).
126
+
127
+ ## Calibration status (scar §2.8, guarantee 13)
128
+
129
+ Every threshold in `tunables.ts` carries the v1 measurement it inherits and a
130
+ window naming what breaks on each side. Two carry a **standing warning**:
131
+
132
+ - `SEMANTIC_FLOOR = 0.60` was calibrated on **trace-length** text and is applied
133
+ here to **chunk-length** text. This is contract open question 2 and v1's own
134
+ live watch. It must be recalibrated on the text length v2 actually sees before
135
+ anyone trusts the number.
136
+ - `FLOOR_MIN_CHARS / FLOOR_MIN_WORDS` inherit v1's fixture calibration, not a
137
+ measurement against v2's corpus, which does not exist yet. Re-measure at replay.
138
+
139
+ ## Open, for the coordinator
140
+
141
+ - The `encode` / `remember` boundary (contract open question 1, module map's third
142
+ standing check-in question) is **untouched by this build**: encode is a separate
143
+ module with one chokepoint, which is the argument *for* separateness. Nothing
144
+ here forecloses folding it into `remember/`'s pipeline later.
145
+ - The cross-module half of the universality test (note 2) belongs to the suite,
146
+ once there are callers to enumerate.
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The alias gate.
3
+ *
4
+ * Every proposed retrieval alias must occur VERBATIM in the source — as a whole
5
+ * word, by the one shared definition (words.ts) that schema birth also uses —
6
+ * **and then pass its own secrets scan** (§3, §5 G4). The second half is not
7
+ * belt-and-braces: an alias is as durable as body text, it is indexed, and a
8
+ * verbatim-in-source alias can itself be a credential. `AKIA...` occurring in the
9
+ * span is exactly the case the ordering catches.
10
+ *
11
+ * A dropped alias does NOT refuse the proposal. Losing a retrieval handle costs a
12
+ * retrieval; refusing the memory costs the memory. The drop is recorded as
13
+ * `refused-by-design` at the refusal site (§5 G11) — never inferred later from a
14
+ * message.
15
+ */
16
+
17
+ import { scanSecrets } from "./secrets.js";
18
+ import { TUNABLES } from "./tunables.js";
19
+ import { occursAsWholeWord } from "./words.js";
20
+ import type { SecretFinding } from "./types.js";
21
+
22
+ export type AliasDropReason =
23
+ | "alias-empty"
24
+ | "alias-too-short"
25
+ | "alias-not-verbatim-in-source"
26
+ | "alias-is-secret";
27
+
28
+ export interface AliasGateResult {
29
+ kept: string[];
30
+ /** By INDEX, never by text: an alias is author content (§5 G10). */
31
+ dropped: { index: number; reason: AliasDropReason }[];
32
+ /** Rolled into the secrets gate's record by the battery. */
33
+ secretFindings: SecretFinding[];
34
+ declared: number;
35
+ }
36
+
37
+ export function gateAliases(
38
+ aliases: readonly string[] | undefined,
39
+ source: string,
40
+ ): AliasGateResult {
41
+ const declared = aliases?.length ?? 0;
42
+ const kept: string[] = [];
43
+ const dropped: { index: number; reason: AliasDropReason }[] = [];
44
+ const secretFindings: SecretFinding[] = [];
45
+
46
+ (aliases ?? []).forEach((raw, index) => {
47
+ const alias = raw.trim();
48
+ if (alias.length === 0) {
49
+ dropped.push({ index, reason: "alias-empty" });
50
+ return;
51
+ }
52
+ if (alias.length < TUNABLES.ALIAS_MIN_CHARS) {
53
+ dropped.push({ index, reason: "alias-too-short" });
54
+ return;
55
+ }
56
+ if (!occursAsWholeWord(source, alias)) {
57
+ dropped.push({ index, reason: "alias-not-verbatim-in-source" });
58
+ return;
59
+ }
60
+ // Verbatim-in-source and STILL scanned. The order is the guarantee.
61
+ const scan = scanSecrets(alias, "alias");
62
+ if (scan.fired) {
63
+ secretFindings.push(...scan.findings);
64
+ dropped.push({ index, reason: "alias-is-secret" });
65
+ return;
66
+ }
67
+ kept.push(alias);
68
+ });
69
+
70
+ return { kept, dropped, secretFindings, declared };
71
+ }