@hviana/sema 0.5.2 → 0.5.3

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 (41) hide show
  1. package/AGENTS.md +114 -52
  2. package/HOW_IT_WORKS.md +275 -184
  3. package/dist/src/mind/bridge.d.ts +5 -7
  4. package/dist/src/mind/bridge.js +6 -97
  5. package/dist/src/mind/match.d.ts +159 -0
  6. package/dist/src/mind/match.js +300 -7
  7. package/dist/src/mind/mechanisms/prefix-completion.d.ts +22 -0
  8. package/dist/src/mind/{prefix-completion.js → mechanisms/prefix-completion.js} +64 -91
  9. package/dist/src/mind/mechanisms/recall.js +10 -108
  10. package/dist/src/mind/mechanisms/reference.d.ts +6 -0
  11. package/dist/src/mind/mechanisms/reference.js +296 -0
  12. package/dist/src/mind/mind.d.ts +1 -1
  13. package/dist/src/mind/pipeline-mechanism.d.ts +56 -1
  14. package/dist/src/mind/pipeline-mechanism.js +104 -3
  15. package/dist/src/mind/pipeline.d.ts +1 -1
  16. package/dist/src/mind/pipeline.js +13 -1
  17. package/dist/src/mind/traverse.d.ts +38 -0
  18. package/dist/src/mind/traverse.js +91 -1
  19. package/dist/src/store.d.ts +4 -4
  20. package/jsr.json +6 -0
  21. package/package.json +1 -1
  22. package/src/mind/bridge.ts +10 -104
  23. package/src/mind/match.ts +416 -7
  24. package/src/mind/{prefix-completion.ts → mechanisms/prefix-completion.ts} +66 -92
  25. package/src/mind/mechanisms/recall.ts +9 -126
  26. package/src/mind/mechanisms/reference.ts +343 -0
  27. package/src/mind/mind.ts +12 -8
  28. package/src/mind/pipeline-mechanism.ts +120 -3
  29. package/src/mind/pipeline.ts +16 -2
  30. package/src/mind/traverse.ts +92 -1
  31. package/src/store.ts +13 -4
  32. package/test/33-multi-candidate.test.mjs +21 -11
  33. package/test/70-prefix-completion.test.mjs +1 -1
  34. package/test/72-prefix-candidate-supply.test.mjs +7 -9
  35. package/test/74-prefix-trap-not-sprung-early.test.mjs +1 -1
  36. package/test/76-reference-binding.test.mjs +471 -0
  37. package/dist/src/mind/frame-filler.d.ts +0 -15
  38. package/dist/src/mind/frame-filler.js +0 -535
  39. package/dist/src/mind/prefix-completion.d.ts +0 -59
  40. package/src/mind/frame-filler.ts +0 -604
  41. package/test/69-frame-filler.test.mjs +0 -115
package/AGENTS.md CHANGED
@@ -41,11 +41,12 @@ The mental model, top to bottom:
41
41
 
42
42
  ```
43
43
  mind/pipeline.ts the grounding decider: mechanisms compete on one cost scale
44
- mind/mechanisms/* cover · cast · confluence · extraction · recall · alu
44
+ mind/mechanisms/* cover · cast · confluence · extraction · reference ·
45
+ recall · prefix-completion · alu
45
46
  mind/* shared machinery: match/project, attention, recognition,
46
47
  junction ascent, graph search, learning, rationale;
47
- recall's refusal-path tiers (bridge, prefix-completion,
48
- frame-filler) live beside them, not inside recall.ts
48
+ the substitution bridge lives beside them, not inside
49
+ recall.ts
49
50
  store.ts AbstractStore: ALL domain logic of the DAG store
50
51
  store-sqlite.ts the one concrete backend (thin SQL wrappers)
51
52
  geometry.ts + vec/alphabet/sema/canon
@@ -174,14 +175,16 @@ policy in callers, the engine neutral.
174
175
  ### 2.5 One factored machinery: match → project, under a gate
175
176
 
176
177
  `mind/match.ts` is the shared family every generalising mechanism configures:
177
- matchers (`locate`, `alignRuns`, `alignGraded`, `bestHaloMate`, `haloSiblings`,
178
- `analogyStrength` and its structural tier `sharedFrameStrength`, `spanHalo`,
179
- `spanSynonymStrength`), projections (`follow`, `reverseContext`, `project`,
180
- `conceptHop`), and the span-shape family (`skillExemplar`, `isSpanShaped`,
181
- `containsSpan`). `mind/traverse.ts` owns the graph readings (`edgeAncestors`,
178
+ matchers (`locate`, `alignRuns`, `alignGraded`, `alignAround`/`frameSlots`,
179
+ `bestHaloMate`, `haloSiblings`, `analogyStrength` and its structural tier
180
+ `sharedFrameStrength`, `spanHalo`, `spanSynonymStrength`), projections
181
+ (`follow`, `reverseContext`, `project`, `conceptHop`), the span-shape family
182
+ (`skillExemplar`, `isSpanShaped`, `containsSpan`), and the two STRUCTURAL gates
183
+ that are byte predicates rather than derived thresholds (`isSpanShaped`,
184
+ `carriesFillers`). `mind/traverse.ts` owns the graph readings (`edgeAncestors`,
182
185
  `reachOf`, `chooseNext`/`chooseAmong`, `guidedFirst`, `leadsSomewhere`,
183
- `allWindowsAreScaffolding`) and the corpus scale (`corpusN`, `hubBound`,
184
- `hubCap`, `atomReach`).
186
+ `allWindowsAreScaffolding`, `formsOpenedBy`) and the corpus scale (`corpusN`,
187
+ `hubBound`, `hubCap`, `atomReach`).
185
188
 
186
189
  _Follow it:_ before writing a new generalising mechanism, express it as a
187
190
  (matcher, direction, gate) triple. If those already exist, the mechanism is a
@@ -195,9 +198,62 @@ A shared analysis must not live inside a mechanism. If `pipeline-mechanism.ts`
195
198
  (the shared contract and `Precomputed`) or a post-grounding stage has to import
196
199
  _out of_ `mechanisms/`, the dependency is inverted and the market's decoupling
197
200
  (2.6) is broken — deleting that mechanism would break the shared container. The
198
- span-shape family (`isSpanShaped` / `containsSpan` / `skillExemplar`) was
199
- exactly this and now lives in `match.ts`, where its two consumers can reach it
200
- without knowing extraction exists.
201
+ span-shape family (`isSpanShaped` / `containsSpan` / `skillExemplar`) lives in
202
+ `match.ts` for exactly this reason: its two consumers reach it without knowing
203
+ extraction exists. `alignAround` is there on the same grounds — the substitution
204
+ bridge and the frame reading both need the same gaps, and ask opposite questions
205
+ of them (the bridge EXPANDS a gap until the query side attests, because a
206
+ substitution claims equivalence; the frame reading CONTRACTS it to its varying
207
+ core, because a reference claims only position). Neither reading derives the
208
+ other, and one aligner serves both. `formsOpenedBy` (`traverse.ts`) is the
209
+ retrieval counterpart: "which trained forms does this byte run open?" is a
210
+ question about the STORE, so it sits with the graph readings rather than inside
211
+ the mechanism that first needed it.
212
+
213
+ The **frame reading** (`alignAround` / `contractGap` / `frameSlots` /
214
+ `carriesFillers`, plus `Precomputed.frames`) is the worked example of this
215
+ pattern at full length. Sema is otherwise fully GROUND — nothing anywhere
216
+ represents a position whose occupant comes from the context rather than the
217
+ corpus — so without it no mechanism can tell "the corpus does not explain these
218
+ bytes" (PASS, refuse) from "these bytes occupy a place the corpus keeps open"
219
+ (bind). Split along the §2.5 triple the notion lands in three places, each at
220
+ its own altitude:
221
+
222
+ - the **matcher** (`frameSlots`) REPORTS and does not judge: every place a
223
+ pairing varies, contracted to its varying core, tagged
224
+ substitution/insertion/deletion, plus how much the two share. It rejects
225
+ nothing, so a consumer can apply its own reading to a pairing another consumer
226
+ would throw away.
227
+ - the **gate** (`carriesFillers`) is the much stronger claim that a slot may be
228
+ VOICED through, so it is deliberately not folded into the matcher: a consumer
229
+ taking the matcher's answer as permission to voice would be making exactly the
230
+ claim the licence withholds.
231
+ - the **inventory** (`Precomputed.frames`) elects no frame, because a slot is a
232
+ property of a PAIRING, not of the query. Election is each consumer's own —
233
+ `reference.ts` keeps the modal slot signature, and a consumer wanting another
234
+ reading is not fighting that one.
235
+
236
+ **Voicing gates belong to the consumer that voices, never to the matcher.** The
237
+ four reference applies — the frame must dominate the query, each slot must reach
238
+ one window on both sides, an insertion or deletion disqualifies the pairing,
239
+ fillers must be pairwise distinct — are all requirements for substituting and
240
+ SPEAKING, not for knowing where a pairing varies. Inside `frameSlots` they make
241
+ the shared reading useless to anyone else: measured over four real pairings,
242
+ only reference's own survives, while a definite description standing where a
243
+ proper noun stands, a pure insertion and a sub-window difference all come back
244
+ as NOTHING. Nothing fails to compile and no test notices.
245
+
246
+ _Follow it:_ a shared analysis with exactly ONE consumer is unproven, whatever
247
+ its address. Before declaring machinery shared, run a second consumer's real
248
+ case through it and check the answer is not `null`. If every gate you wrote
249
+ happens to be one your own mechanism needs, they are not the matcher's gates.
250
+
251
+ Making a notion available is not the same as imposing it, and two mechanisms
252
+ deliberately do **not** consume this one: the substitution bridge (its
253
+ substitution asserts equivalence, and it grounds through its candidate's
254
+ continuation UNSUBSTITUTED, so admitting a slot-gap there voices the corpus's
255
+ filler for the asker's referent) and CAST (its frame gate is weave-local while a
256
+ slot is cohort-local — §2.7 again).
201
257
 
202
258
  Related single-definition contracts (define once, import everywhere):
203
259
 
@@ -208,7 +264,7 @@ Related single-definition contracts (define once, import everywhere):
208
264
  - `canonical.ts` — the write/read contract for canonical segmentation
209
265
  (`canonicalWindows`, `chainReach`, `leafIdRun`, `leafIdPrefix`, `windowIds`).
210
266
  Learning writes through it; recognition, attention, confluence, the bridge and
211
- prefix-completion read through it. Changing one side means changing this file
267
+ prefix completion read through it. Changing one side means changing this file
212
268
  — drift between sides breaks canonical recognition with **no type error**.
213
269
  - `junction.ts` — the content-addressed "which learnt whole contains these two
214
270
  forms?" ascent, shared by the bridge and cross-region attention, with its
@@ -237,8 +293,8 @@ the same interface, `PipelineMechanism` (`mind/pipeline-mechanism.ts`): optional
237
293
  (an admissible lower bound, or `null` when the mechanism structurally cannot
238
294
  fire), and `run` (candidate answers). The decider in `mind/pipeline.ts`
239
295
  (`think`) holds a plain list (`defaultMechanisms`: cover, cast, confluence,
240
- extraction, recall, plus the ALU and any user mechanisms) and never branches on
241
- which mechanism it is holding.
296
+ extraction, reference, recall, prefix-completion, plus the ALU and any user
297
+ mechanisms) and never branches on which mechanism it is holding.
242
298
 
243
299
  Four constraints make the market honest — verify all four for anything you add:
244
300
 
@@ -305,9 +361,8 @@ using the wrong one is a semantic bug the type system cannot catch:
305
361
  store?"
306
362
  - **Weave-local** — reference set: the structures aligned with _this query_.
307
363
  Tooling: the `depth[]` array built in `computeWeave` + `MIN_WEAVE` +
308
- `dominates`. Used by CAST's frame gate and by the frame filler's constituency
309
- reading. Answers "does this discriminate among the structures this query
310
- activates?"
364
+ `dominates`. Used by CAST's frame gate. Answers "does this discriminate among
365
+ the structures this query activates?"
311
366
 
312
367
  `depth[]` counts **distinct covering structures**, not accumulated alignment
313
368
  weight: the frame test compares it against a COUNT of aligned points, so
@@ -399,11 +454,14 @@ Asking never writes, which is the only reason per-response memos are sound.
399
454
  `Precomputed` (`pipeline-mechanism.ts`) is the shared response-scoped container:
400
455
  eager fields (recognition, computed spans, guide, the evidence-breadth constant
401
456
  `k`) plus **lazily-cached methods** for expensive analyses (`attention()` — the
402
- consensus climb, `weave()`, `spanShapedOf`/`spanShapedAll`, `queryWindows`,
403
- `queryResolved`, `windowsOf`, `reachMemo`)each computed at most once, shared
404
- by mechanisms and post-grounding stages, and never computed if nobody asks. The
405
- async ones are cached **by promise**, so a second caller awaits the first
406
- computation rather than starting another.
457
+ consensus climb, `weave()`, `resonance()` — the response's ONE top-k
458
+ content-index read, `wideResonance()` — the one WIDE candidate list every
459
+ past-the-top-k mechanism reads, `frames()` the frame/slot inventory,
460
+ `spanShapedOf`/`spanShapedAll`, `queryWindows`, `queryResolved`, `windowsOf`,
461
+ `reachMemo`) each computed at most once, shared by mechanisms and
462
+ post-grounding stages, and never computed if nobody asks. The async ones are
463
+ cached **by promise**, so a second caller awaits the first computation rather
464
+ than starting another.
407
465
 
408
466
  Mind-level memos (`climbMemo`, `recogniseMemo`, `perceiveMemo`, `canonMemo`,
409
467
  `_resolvedSubtrees`, `_edgeChoice`, `_gistCache`) are created in
@@ -554,32 +612,32 @@ story of the fix.
554
612
 
555
613
  ## 3. Where things live
556
614
 
557
- | Concept | File(s) |
558
- | :-------------------------------------------------- | :-------------------------------------------------------------------------------- |
559
- | Public surface / assembly | `src/index.ts`, `src/mind/mind.ts` |
560
- | Conversation API (turns, state, answered spans) | `src/mind/mind.ts` |
561
- | Config (capacities, budgets, seed) | `src/config.ts` |
562
- | Derived thresholds, the fold, Hilbert | `src/geometry.ts` |
563
- | Content canonicalizer (injected, modality-specific) | `src/canon.ts` |
564
- | Vector primitives, alphabet, node/fold types, seats | `src/vec.ts`, `src/alphabet.ts`, `src/sema.ts` |
565
- | Perceive / resolve / read primitives | `src/mind/primitives.ts` |
566
- | Store domain logic / SQLite adapter | `src/store.ts`, `src/store-sqlite.ts` |
567
- | Mechanism contract + shared `Precomputed` | `src/mind/pipeline-mechanism.ts` |
568
- | The grounding decider (`think`) | `src/mind/pipeline.ts` |
569
- | Grounding mechanisms (one file each) | `src/mind/mechanisms/{cover,cast,confluence,extraction,recall,alu}.ts` |
570
- | Weighted deduction system + cost ladder | `src/mind/graph-search.ts` (engine in `src/derive/`) |
571
- | Match/project family | `src/mind/match.ts` |
572
- | Graph traversal, corpus scale, disambiguators | `src/mind/traverse.ts` |
573
- | Consensus climb + cross-region attention | `src/mind/attention.ts` |
574
- | Recall's refusal-path tiers | `src/mind/bridge.ts`, `src/mind/prefix-completion.ts`, `src/mind/frame-filler.ts` |
575
- | Recognition / canonical contract | `src/mind/recognition.ts`, `src/mind/canonical.ts` |
576
- | Junction ascent (bridge + attention share) | `src/mind/junction.ts`, `src/mind/resonance.ts` |
577
- | Learning / ingestion / training cache | `src/mind/learning.ts`, `src/ingest-cache.ts` |
578
- | Post-grounding (reason, fuse, articulate) | `src/mind/reasoning.ts`, `src/mind/articulation.ts` |
579
- | Rationale / trace | `src/mind/rationale.ts`, `src/mind/trace.ts` |
580
- | Computational-usage meter | `src/meter.ts` (harness: `bench/profile-inference.mjs`) |
581
- | Extension host types | `src/extension.ts` |
582
- | Sublibraries (own READMEs, own tests) | `src/derive/`, `src/alu/`, `src/rabitq-ivf/` |
615
+ | Concept | File(s) |
616
+ | :-------------------------------------------------- | :------------------------------------------------------------------------------------------------- |
617
+ | Public surface / assembly | `src/index.ts`, `src/mind/mind.ts` |
618
+ | Conversation API (turns, state, answered spans) | `src/mind/mind.ts` |
619
+ | Config (capacities, budgets, seed) | `src/config.ts` |
620
+ | Derived thresholds, the fold, Hilbert | `src/geometry.ts` |
621
+ | Content canonicalizer (injected, modality-specific) | `src/canon.ts` |
622
+ | Vector primitives, alphabet, node/fold types, seats | `src/vec.ts`, `src/alphabet.ts`, `src/sema.ts` |
623
+ | Perceive / resolve / read primitives | `src/mind/primitives.ts` |
624
+ | Store domain logic / SQLite adapter | `src/store.ts`, `src/store-sqlite.ts` |
625
+ | Mechanism contract + shared `Precomputed` | `src/mind/pipeline-mechanism.ts` |
626
+ | The grounding decider (`think`) | `src/mind/pipeline.ts` |
627
+ | Grounding mechanisms (one file each) | `src/mind/mechanisms/{cover,cast,confluence,extraction,reference,recall,prefix-completion,alu}.ts` |
628
+ | Weighted deduction system + cost ladder | `src/mind/graph-search.ts` (engine in `src/derive/`) |
629
+ | Match/project family | `src/mind/match.ts` |
630
+ | Graph traversal, corpus scale, disambiguators | `src/mind/traverse.ts` |
631
+ | Consensus climb + cross-region attention | `src/mind/attention.ts` |
632
+ | Recall's refusal-path tier (substitution bridge) | `src/mind/bridge.ts` |
633
+ | Recognition / canonical contract | `src/mind/recognition.ts`, `src/mind/canonical.ts` |
634
+ | Junction ascent (bridge + attention share) | `src/mind/junction.ts`, `src/mind/resonance.ts` |
635
+ | Learning / ingestion / training cache | `src/mind/learning.ts`, `src/ingest-cache.ts` |
636
+ | Post-grounding (reason, fuse, articulate) | `src/mind/reasoning.ts`, `src/mind/articulation.ts` |
637
+ | Rationale / trace | `src/mind/rationale.ts`, `src/mind/trace.ts` |
638
+ | Computational-usage meter | `src/meter.ts` (harness: `bench/profile-inference.mjs`) |
639
+ | Extension host types | `src/extension.ts` |
640
+ | Sublibraries (own READMEs, own tests) | `src/derive/`, `src/alu/`, `src/rabitq-ivf/` |
583
641
 
584
642
  Mind functions are **free functions over `MindContext`** (`mind/types.ts`), not
585
643
  methods — `mind.ts` is a thin assembly that implements the context and
@@ -666,13 +724,17 @@ into the response-scoped slots for the turn's duration.
666
724
  const r = await mind.respond(query, (rationale) => {
667
725
  console.dir(rationale, { depth: null }); // every step, cost, data-flow edge
668
726
  });
669
- console.log(r.provenance); // cast | join | cover | extract | recall | recall-echo
727
+ console.log(r.provenance); // cast | join | cover | extract | reference | recall | recall-echo | prefix
670
728
  ```
671
729
 
672
730
  Read top-down: which mechanism fired (and why the others abstained), what
673
731
  recognition found, how the climb voted, which edges were followed
674
732
  (`disambiguate` steps carry the evidence). `recall-echo` means "nearest stored
675
- form, not a derived fact".
733
+ form, not a derived fact". `reference` means "part of this answer is bytes the
734
+ ASKER supplied, voiced through a slot the corpus attests as a carriage" — read
735
+ its `bindReferent` step for the referents and the instances, and
736
+ `referenceLicence` for why a binding was refused. `prefix` means "the query is
737
+ the literal opening of exactly one trained form, which this voiced whole".
676
738
 
677
739
  Three steps carry **structured data**, so tooling need not parse notes:
678
740
  `decideGrounding` (every candidate's provenance, exact weight, discrete grade,