@hviana/sema 0.9.3 → 0.9.5

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 (46) hide show
  1. package/AGENTS.md +16 -7
  2. package/dist/src/mind/learning.js +11 -12
  3. package/dist/src/mind/mind.js +4 -4
  4. package/dist/src/mind/types.d.ts +10 -15
  5. package/dist/src/store.d.ts +10 -10
  6. package/dist/src/store.js +5 -5
  7. package/docs/INDEX.md +62 -59
  8. package/docs/INVARIANTS.md +36 -18
  9. package/docs/PHILOSOPHY.md +317 -0
  10. package/docs/architecture/bounded-reads.md +31 -71
  11. package/docs/architecture/caches.md +61 -81
  12. package/docs/architecture/closure.md +88 -107
  13. package/docs/architecture/commonality.md +47 -38
  14. package/docs/architecture/cost-model.md +57 -79
  15. package/docs/architecture/determinism.md +43 -55
  16. package/docs/architecture/evidence.md +158 -235
  17. package/docs/architecture/exact-vs-approximate.md +41 -35
  18. package/docs/architecture/factored-machinery.md +34 -20
  19. package/docs/architecture/fold-contract.md +110 -118
  20. package/docs/architecture/halo-sketch.md +105 -96
  21. package/docs/architecture/match-project.md +51 -42
  22. package/docs/architecture/mechanism-market.md +87 -91
  23. package/docs/architecture/memoization.md +60 -74
  24. package/docs/architecture/meter.md +37 -47
  25. package/docs/architecture/saturation.md +75 -101
  26. package/docs/architecture/store.md +118 -99
  27. package/docs/architecture/thresholds.md +66 -73
  28. package/docs/failures/tempting-but-wrong.md +139 -165
  29. package/docs/harness/gates.md +27 -32
  30. package/docs/mechanisms/alu.md +22 -69
  31. package/docs/mechanisms/cast.md +76 -71
  32. package/docs/mechanisms/confluence.md +22 -29
  33. package/docs/mechanisms/cover.md +58 -66
  34. package/docs/mechanisms/extraction.md +33 -37
  35. package/docs/mechanisms/prefix-completion.md +36 -39
  36. package/docs/mechanisms/recall.md +60 -53
  37. package/docs/mechanisms/reference.md +63 -49
  38. package/jsr.json +1 -1
  39. package/package.json +1 -1
  40. package/src/alu/README.md +90 -298
  41. package/src/derive/README.md +94 -256
  42. package/src/mind/learning.ts +11 -12
  43. package/src/mind/mind.ts +4 -4
  44. package/src/mind/types.ts +10 -15
  45. package/src/rabitq-ivf/README.md +11 -8
  46. package/src/store.ts +5 -5
package/AGENTS.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # AGENTS.md — the Sema development manual
2
2
 
3
- The working manual for anyone (human or AI agent) changing Sema. For pattern
4
- detail, see `docs/INDEX.md` → `docs/architecture/*.md`. You should be able to
5
- develop against this document and docs/ alone; read `docs/architecture/` for why
6
- a pattern holds.
3
+ The working manual for anyone (human or AI agent) changing Sema. Read
4
+ `docs/PHILOSOPHY.md` first: it follows information from deposit to answer and
5
+ says why the parts fit. Then `docs/INDEX.md` routes each task to the law it
6
+ touches in `docs/architecture/`. You should be able to develop against this
7
+ document and `docs/` alone.
7
8
 
8
9
  ## 1. Orientation
9
10
 
@@ -32,7 +33,7 @@ Mental model, top to bottom:
32
33
  ```
33
34
  mind/pipeline.ts grounding decider: mechanisms compete on one cost scale
34
35
  mind/mechanisms/* cover · cast · confluence · extraction · reference · recall · prefix-completion · alu
35
- mind/* match/project, attention, recognition, junction ascent, graph search, learning, rationale
36
+ mind/* recognition, attention, match/project, evidence, closure, graph search, learning, rationale
36
37
  store.ts AbstractStore: ALL DAG store domain logic
37
38
  store-sqlite.ts the one concrete backend (thin SQL wrappers)
38
39
  geometry.ts + vec/alphabet/sema/canon vectors, fold, every derived threshold, canonicalizer
@@ -82,6 +83,10 @@ corpus-determined, not interchangeable (`determinism.md`).
82
83
  | Weighted deduction + cost ladder | `src/mind/graph-search.ts` (engine in `src/derive/`) |
83
84
  | Match/project family | `src/mind/match.ts` |
84
85
  | Graph traversal, corpus scale | `src/mind/traverse.ts` |
86
+ | Witnessed evidence (`witness`) | `src/mind/evidence.ts` |
87
+ | Closure law and engine (`closeOver`) | `src/mind/derivation.ts` |
88
+ | Post-grounding walk and fusion | `src/mind/reasoning.ts` |
89
+ | Canonical windows | `src/mind/canonical.ts` |
85
90
  | Consensus climb + attention | `src/mind/attention.ts` |
86
91
  | Substitution bridge (recall tier) | `src/mind/bridge.ts` |
87
92
  | Recognition / junction / resonance | `src/mind/recognition.ts`, `src/mind/junction.ts`, `src/mind/resonance.ts` |
@@ -132,8 +137,12 @@ against built `dist/` (`npm test`; one suite:
132
137
  numbered suite. Many tests pin contracts that look like implementation details
133
138
  (ladder order, span-shape readings, `MechanismResult.complete`, fold invariance,
134
139
  recognition idempotence, honest silence). A simplification that fails an
135
- existing test is wrong until the test is proven wrong. Sublibraries test
136
- themselves in `src/{alu,derive,rabitq-ivf}/test/` with zero Sema dependency.
140
+ existing test is wrong until the test is proven wrong; read
141
+ `docs/failures/tempting-but-wrong.md` before trying one. `src/alu/` and
142
+ `src/derive/` test themselves in their own `test/` with zero Sema dependency;
143
+ `rabitq-ivf` is pinned by `test/35-ivf`. `test/137` also reads `docs/`: an
144
+ export only the docs describe counts as documented, so deleting its mention can
145
+ fail the dead-export guard.
137
146
 
138
147
  ## 6. Instrumentation — the meter and the rationale ARE the dev surface
139
148
 
@@ -109,18 +109,17 @@ export async function indexSubSpans(ctx, tree, ids) {
109
109
  * root id, id map, and the changed (new) subtrees for halo reinforcement. */
110
110
  export async function deposit(ctx, input, track, conversational = false) {
111
111
  const bytes = inputBytes(ctx, input);
112
- // Deposit-shaped perception: stable-prefix tree SEEDING (see
113
- // perceiveDeposit) — an accumulated context re-folds only its new suffix,
114
- // O(turn) instead of O(context) per conversation turn. Cache-only here
115
- // (no store-probe fallback): a knownPrefixLength scan on every novel fact
116
- // would cost O(n²) hashing, while conversation replays are always warm —
117
- // re-deposition replays from the first turn, rebuilding the cache as it
118
- // goes. `conversational` scopes the STABLE-PREFIX variant (turn-boundary
119
- // folding, matching query-time perception) to ingestPair's own growing
120
- // context argument — a bare ingestOne deposit whose bytes merely happen
121
- // to extend an earlier UNRELATED deposit (no conversational relationship)
122
- // must keep the plain fold, or two coincidentally-prefix-sharing facts
123
- // would stop sharing structure with each other.
112
+ // Deposit-shaped perception (perceiveDeposit): the plain content fold, the
113
+ // same tree inference computes for these bytes. An accumulated context
114
+ // reuses the already-folded segments of its cached prefix
115
+ // (contentFoldIncremental), so it re-folds only its new suffix — O(turn)
116
+ // instead of O(context) per conversation turn. The reuse is transparent:
117
+ // a hit saves time and never changes the tree. Cache-only here (no
118
+ // store-probe fallback): conversation replays are always warm, because
119
+ // re-deposition replays from the first turn and rebuilds the cache as it
120
+ // goes. `conversational` only decides which deposits WRITE the cache —
121
+ // ingestPair's growing context, not every unrelated fact — a budget
122
+ // choice, not a correctness one (fold-contract.md).
124
123
  const tree = perceiveDeposit(ctx, bytes, conversational);
125
124
  const ids = new Map();
126
125
  const rootId = await internTreeIds(ctx, tree, ids);
@@ -685,10 +685,10 @@ export class Mind {
685
685
  // No recognise-memo pre-seeding here: that used to be necessary because
686
686
  // the flat/positional fold lost visibility into an earlier turn's own
687
687
  // structure once later bytes shifted its position (foldTree no longer
688
- // visited the turn's root node). The STABLE-PREFIX fold (see {@link
689
- // ConversationData}) makes every turn's subtree independent of what
690
- // follows it by construction, so recognise() finds it correctly on its
691
- // own, first-touch, exactly once per turn.
688
+ // visited the turn's root node). The content-defined fold (see {@link
689
+ // ConversationData}) cuts by the bytes, never by position, so an earlier
690
+ // turn's structure is the same whatever follows it, and recognise() finds
691
+ // it on its own, first-touch, exactly once per turn.
692
692
  this.beginResponse(inspectRationale, this._canonFor(typeof turn === "string" ? textCanon : null), data);
693
693
  try {
694
694
  const response = await this._groundAndVoice(newContext, "respondTurn");
@@ -356,9 +356,8 @@ export interface MindContext extends GraphSearchHost {
356
356
  * with `bytesToTree` on every turn, so every key was fresh and this cache
357
357
  * could not hit even once — the O(suffix) claim above described an
358
358
  * intention rather than the code. It now grows the context through
359
- * {@link stablePrefixFoldIncremental}, which reuses each already-folded
360
- * segment: measured over four turns, turn 4 shared 69 of its 95 nodes with
361
- * turn 3 (26 new ≈ the new turn's own size). */
359
+ * contentFoldIncremental, which reuses each already-folded segment as the
360
+ * same object (~92% of nodes reused by identity across turns). */
362
361
  _resolvedSubtrees: WeakMap<Sema, {
363
362
  id: number;
364
363
  len: number;
@@ -396,18 +395,14 @@ export interface MindContext extends GraphSearchHost {
396
395
  * never a correctness risk. */
397
396
  _gistCache: BoundedMap<number, Vec>;
398
397
  /** DEPOSIT-path perception cache: content key (latin1) of a deposited
399
- * input → its accumulated turn BOUNDARIES plus reusable fold state. A
400
- * deposit whose content extends a cached entry IS a conversation context
401
- * grown by one turn — the cached length is the new boundary — so it
402
- * folds with the SAME stable-prefix fold query-time perception uses
403
- * (structural train/inference agreement, load-bearing for recall),
404
- * reusing every already-folded segment via `stable` (see StableFold) —
405
- * O(turn) per deposit instead of O(context). A first-seen input takes the
406
- * same fold with no boundaries at all, and caches the segments it produced
407
- * so a later turn of the same conversation reuses them. Purely a
408
- * performance cache for the FOLD STATE; the boundaries are semantic but
409
- * derived only from the deposit sequence itself (an evicted chain falls
410
- * back to plain-fold behavior, exactly the pre-boundary shape). */
398
+ * input → its reusable content-fold state ({@link DepositCacheEntry}). A
399
+ * deposit whose bytes extend a cached entry reuses that entry's
400
+ * already-folded segments (contentFoldIncremental) — O(turn) per deposit
401
+ * instead of O(context) — and gets exactly the tree a cold fold would
402
+ * give, the same one query-time perception computes. It holds no turn
403
+ * boundaries: the fold imposes none (fold-contract.md). Written only by
404
+ * conversational deposits, so the 8-entry budget keeps the live chains;
405
+ * an evicted chain costs a re-fold, never a different tree. */
411
406
  _depositTrees: BoundedMap<string, DepositCacheEntry>;
412
407
  /** The byte lengths present in {@link _depositTrees} — the candidate
413
408
  * prefix lengths probed (longest first). Drifts on eviction (a stale
@@ -44,11 +44,11 @@ export declare class BoundedMap<K, V> {
44
44
  /** How a HIT records recency.
45
45
  *
46
46
  * `"reorder"` (default) promotes the entry to most-recent by
47
- * `m.delete(k); m.set(k, v)` — exact LRU, and the only policy that is
48
- * safe for a cache whose CONTENTS are load-bearing rather than merely
49
- * warm. `_depositTrees` (8 entries, feeds stablePrefixFoldIncremental)
50
- * is exactly that: which of its entries survives changes how the next
51
- * turn FOLDS, so test/13 D1 flips answer when the victim changes.
47
+ * `m.delete(k); m.set(k, v)` — exact LRU, the policy for any cache whose
48
+ * choice of victim must follow use exactly. `_depositTrees` (8 entries,
49
+ * feeds contentFoldIncremental) keeps it so the live conversation chains
50
+ * stay warm; its reuse is transparent, so a wrong victim costs a re-fold,
51
+ * never a different tree (fold-contract.md).
52
52
  *
53
53
  * `"clock"` records recency as a BIT instead of as position, spent by
54
54
  * the eviction sweep (see `nextOldest`). Correct only for a TRANSPARENT
@@ -64,11 +64,11 @@ export declare class BoundedMap<K, V> {
64
64
  /** How a HIT records recency.
65
65
  *
66
66
  * `"reorder"` (default) promotes the entry to most-recent by
67
- * `m.delete(k); m.set(k, v)` — exact LRU, and the only policy that is
68
- * safe for a cache whose CONTENTS are load-bearing rather than merely
69
- * warm. `_depositTrees` (8 entries, feeds stablePrefixFoldIncremental)
70
- * is exactly that: which of its entries survives changes how the next
71
- * turn FOLDS, so test/13 D1 flips answer when the victim changes.
67
+ * `m.delete(k); m.set(k, v)` — exact LRU, the policy for any cache whose
68
+ * choice of victim must follow use exactly. `_depositTrees` (8 entries,
69
+ * feeds contentFoldIncremental) keeps it so the live conversation chains
70
+ * stay warm; its reuse is transparent, so a wrong victim costs a re-fold,
71
+ * never a different tree (fold-contract.md).
72
72
  *
73
73
  * `"clock"` records recency as a BIT instead of as position, spent by
74
74
  * the eviction sweep (see `nextOldest`). Correct only for a TRANSPARENT
package/dist/src/store.js CHANGED
@@ -95,11 +95,11 @@ export class BoundedMap {
95
95
  /** How a HIT records recency.
96
96
  *
97
97
  * `"reorder"` (default) promotes the entry to most-recent by
98
- * `m.delete(k); m.set(k, v)` — exact LRU, and the only policy that is
99
- * safe for a cache whose CONTENTS are load-bearing rather than merely
100
- * warm. `_depositTrees` (8 entries, feeds stablePrefixFoldIncremental)
101
- * is exactly that: which of its entries survives changes how the next
102
- * turn FOLDS, so test/13 D1 flips answer when the victim changes.
98
+ * `m.delete(k); m.set(k, v)` — exact LRU, the policy for any cache whose
99
+ * choice of victim must follow use exactly. `_depositTrees` (8 entries,
100
+ * feeds contentFoldIncremental) keeps it so the live conversation chains
101
+ * stay warm; its reuse is transparent, so a wrong victim costs a re-fold,
102
+ * never a different tree (fold-contract.md).
103
103
  *
104
104
  * `"clock"` records recency as a BIT instead of as position, spent by
105
105
  * the eviction sweep (see `nextOldest`). Correct only for a TRANSPARENT
package/docs/INDEX.md CHANGED
@@ -1,71 +1,74 @@
1
1
  # Sema Documentation Index
2
2
 
3
- Sema is a single system stated three ways: the law lives in `docs/architecture/`
4
- (what holds), the prescription in `AGENTS.md` (what to do and where), and the
5
- proof in `test/` (pins that fail when the law is broken).
3
+ Sema is one system, stated four ways:
6
4
 
7
- ## Routing — what to read for each task
5
+ | Where | It says |
6
+ | -------------------- | ----------------------------------------------------------------------------------------- |
7
+ | `docs/PHILOSOPHY.md` | the path of information from deposit to answer, and why it holds together. Read it first. |
8
+ | `docs/architecture/` | the laws: what holds and why, measured |
9
+ | `AGENTS.md` | the prescription: what to do, and where |
10
+ | `test/` | the proof: pins that fail when a law is broken |
8
11
 
9
- | Task | Read | Why |
10
- | --------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
11
- | Add a mechanism | `docs/architecture/mechanism-market.md` + `docs/mechanisms/*.md` | Market contract: the four constraints |
12
- | Add a threshold | `docs/architecture/thresholds.md` | All cutoffs are formulas over D/W/N; `config.ts` holds budgets only |
13
- | Debug an answer | `docs/architecture/cost-model.md` + `src/meter.ts` | One ladder decides every grounding choice |
14
- | Understand the fold | `docs/architecture/fold-contract.md` | Deposit and inference compute the same tree |
15
- | Add a store backend | `docs/architecture/store.md` + `docs/architecture/bounded-reads.md` | `AbstractStore` owns domain logic; backends are thin wrappers with capped reads |
16
- | Add an ALU operation | `src/alu/README.md` | One `registry.derive` per op composing existing ops; no new `derive` needed |
17
- | Add a matcher or projection | `docs/architecture/match-project.md` | Mechanisms are `(matcher, direction, gate)` configs over the shared `match.ts` family |
18
- | Add a deduction rule | `docs/architecture/cost-model.md` + `docs/architecture/determinism.md` | Place cost on the ladder, keep heuristic admissible, extend `classifyMove` |
19
- | Change vector search | `docs/architecture/exact-vs-approximate.md` + `docs/architecture/bounded-reads.md` | Scores propose, bytes dispose; ANN is bounded by `hubBound` |
20
- | Profile or bound work | `docs/architecture/meter.md` + `docs/architecture/bounded-reads.md` | `meter.ts` is write-only; counters are product, phases are hints |
12
+ `docs/INVARIANTS.md` routes every law to its code and its pins.
21
13
 
22
- ## Architecture laws (15)
14
+ ## What to read for each task
23
15
 
24
- | Law | File | Summary | Pins |
25
- | --- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- |
26
- | 1 | `docs/architecture/determinism.md` | No `Math.random`/`Date.now` in behaviour; seed-derived randomness; corpus-determined tie-breaks | `test/20` |
27
- | 2 | `docs/architecture/thresholds.md` | Every decision cutoff derived in `geometry.ts` over D/W/N; no tunable knobs | `test/40`, `test/64` |
28
- | 3 | `docs/architecture/exact-vs-approximate.md` | Vector scores rank only; identity via content-addressed lookup; six graded ladders | `test/51` |
29
- | 4 | `docs/architecture/cost-model.md` | Single ladder `MICRO`/`STEP`/`CONCEPT`/`PASS`; weight `moves + PASS·unaccounted`; `STEP`-grade compare | `test/04`, `test/55` |
30
- | 5 | `docs/architecture/match-project.md` | Shared `match.ts` family (`locate`/`alignGraded`/`frameSlots`/`project`); voicing gates belong to consumers | `test/24`, `test/76` |
31
- | 6 | `docs/architecture/mechanism-market.md` | `PipelineMechanism` (`floor`/`run`/`parse`); admissible-floor pruning, investment discipline, run-ahead bounds | `test/01`, `test/04`, `test/153` |
32
- | 7 | `docs/architecture/commonality.md` | Three: global (`reachOf`+`dominates`), weave-local (`depth[]`), window rarity | `test/17`, `test/34` |
33
- | 8 | `docs/architecture/bounded-reads.md` | No per-query read grows with N; `hubBound=√N` enforced at store via LIMIT/probe/prefix caps | `test/77`, `test/90` |
34
- | 9 | `docs/architecture/store.md` | `AbstractStore` owns dedup/indexing/batch; `store-sqlite.ts` is thin wrappers; canon index optional | `test/08` |
35
- | 10 | `docs/architecture/fold-contract.md` | `perceiveDeposit` and `perceive` agree; the read side names a branch as `intern` does; `contentLevels` is single boundary rule; no W/offset dependence | `test/59`, `test/63`, `test/148`, `test/152` |
36
- | 11 | `docs/architecture/memoization.md` | `Precomputed` is per-response lazy cache (promise-cached async); `beginResponse`/`endResponse` lifecycle | `test/42` |
37
- | 12 | `docs/architecture/saturation.md` | Every walk names a deciding saturation beside its cap; cap is safety net, not decision | `test/27`, `test/16` |
38
- | 13 | `docs/architecture/meter.md` | `meter.ts` is write-only work accounting; counts are exact, phases nest | `test/55` |
39
- | 14 | `docs/architecture/closure.md` | A derivation is closed when its structure accounts for the question's remainder; every transition asks that law, one engine walks the layers | `test/133`–`151` |
40
- | 15 | `docs/architecture/evidence.md` | A stored form is identified when the material at hand (question ∪ the node a derivation stands on) witnesses every byte of it, order-free; the question NAMES a continuation through its establishing context, or through another instance of its frame (a co-instance, never voiced as the answer); a step it did not name pays from what is still owed | `test/154`, `test/155` |
16
+ | Task | Read |
17
+ | ------------------------------ | --------------------------------------------------------------- |
18
+ | Understand the whole | `PHILOSOPHY.md` |
19
+ | Change perception or identity | `fold-contract.md`, `store.md`, `exact-vs-approximate.md` |
20
+ | Add a store backend | `store.md`, `bounded-reads.md` |
21
+ | Add or change a threshold | `thresholds.md` |
22
+ | Add a mechanism | `mechanism-market.md`, `match-project.md`, `docs/mechanisms/` |
23
+ | Add a deduction rule | `cost-model.md`, `closure.md`, `determinism.md` |
24
+ | Change what counts as evidence | `evidence.md`, `commonality.md` |
25
+ | Change vector search | `exact-vs-approximate.md`, `halo-sketch.md`, `bounded-reads.md` |
26
+ | Add a walk or a fan-out | `bounded-reads.md`, `saturation.md` |
27
+ | Profile or bound work | `meter.md`, `memoization.md`, `caches.md` |
28
+ | Add an ALU operation | `src/alu/README.md` |
29
+ | Simplify something | `docs/failures/tempting-but-wrong.md` first |
41
30
 
42
- ## Mechanisms (8)
31
+ ## The laws (`docs/architecture/`)
43
32
 
44
- | Mechanism | File | Role |
45
- | ----------------- | -------------------------------------- | --------------------------------------------------------- |
46
- | cover | `docs/mechanisms/cover.md` | Exact/computed-span covering via `GraphSearch` |
47
- | cast | `docs/mechanisms/cast.md` | Weave-local analogy via `depth[]` frame gate |
48
- | confluence | `docs/mechanisms/confluence.md` | Corpus-global filler/scaffolding gate over climb |
49
- | extraction | `docs/mechanisms/extraction.md` | Located-frame read-out with anchored span accounting |
50
- | reference | `docs/mechanisms/reference.md` | Slot-bound voicing of asker-supplied referents |
51
- | recall | `docs/mechanisms/recall.md` | Nearest stored form; echo tier via substitution bridge |
52
- | prefix-completion | `docs/mechanisms/prefix-completion.md` | Literal prefix of exactly one trained form |
53
- | alu | `docs/mechanisms/alu.md` | Authoritative computed spans (`parse` → `aluToMechanism`) |
33
+ | # | Doc | Law |
34
+ | -- | ------------------------- | ------------------------------------------------------------------------------------------------------------------ |
35
+ | 1 | `determinism.md` | the same seed, deposits and question give the same bytes; ties are broken by the corpus, never by chance |
36
+ | 2 | `thresholds.md` | every cutoff is a formula over `D`, `W`, `N`; `config.ts` holds budgets only |
37
+ | 3 | `exact-vs-approximate.md` | scores propose, bytes dispose; every graded ladder is exact first |
38
+ | 4 | `cost-model.md` | one currency: `MICRO < STEP < CONCEPT < PASS`, and the price is the unexplained question |
39
+ | 5 | `match-project.md` | a mechanism is `(matcher, direction, gate)` over one family; the gate belongs to the consumer |
40
+ | 6 | `mechanism-market.md` | one interface, one price; never compute what cannot change the decision |
41
+ | 7 | `commonality.md` | frame against filler is read over a named population: corpus, cohort or places, never substituted |
42
+ | 8 | `bounded-reads.md` | no per-query read grows with `N`; the store enforces `hubBound = ⌈√N⌉` |
43
+ | 9 | `store.md` | a node is named by its content; `AbstractStore` owns every domain decision |
44
+ | 10 | `fold-contract.md` | deposit and question fold the same bytes into the same tree and the same node; nothing outside the bytes shapes it |
45
+ | 11 | `memoization.md` | asking never writes; shared analyses are computed once per response, and tracing changes no answer |
46
+ | 12 | `saturation.md` | every walk names the stop that decides it; the cap is only a net |
47
+ | 13 | `meter.md` | the meter is write-only; counters are exact, milliseconds are hints |
48
+ | 14 | `closure.md` | a step is admitted only when it closes, moves to unconsumed structure, or carries what is owed |
49
+ | 15 | `evidence.md` | the question names the step; another instance of its frame says what the relation is, never what it asks about |
54
50
 
55
- ## Supporting docs
51
+ Supporting docs: `halo-sketch.md` (distributional memory), `caches.md` (every
52
+ acceleration is a budget), `factored-machinery.md` (one definition, many
53
+ consumers).
56
54
 
57
- | Doc | Role |
58
- | ----------------------------------------- | ------------------------------------------------------------------------------- |
59
- | `docs/architecture/caches.md` | Every acceleration is a `BoundedMap`; miss re-derives; budgets in `StoreConfig` |
60
- | `docs/architecture/halo-sketch.md` | Halo & sketch — distributional memory, quantization, bottom-k profiles |
61
- | `docs/architecture/factored-machinery.md` | Single-definition contracts table — one owner per shared symbol |
55
+ ## Mechanisms (`docs/mechanisms/`)
62
56
 
63
- ## Cross-cutting
57
+ | Mechanism | Answers by |
58
+ | ------------------- | ----------------------------------------------------------------------------- |
59
+ | `cover` | composing the question from its recognised sites, by graph search |
60
+ | `cast` | carrying structure between woven forms: substitution, redirection, comparison |
61
+ | `confluence` | intersecting what independent conditions reach |
62
+ | `extraction` | reading a span between frames located in the question |
63
+ | `reference` | voicing a learnt frame's slot with the asker's own bytes |
64
+ | `recall` | the nearest stored form, or honest silence |
65
+ | `prefix-completion` | completing a known beginning of exactly one form |
66
+ | `alu` | computation, which is authoritative |
64
67
 
65
- - `docs/INVARIANTS.md` — the five invariants (determinism, derived thresholds,
66
- exact-decides, one cost currency, bounded reads) with file-level routing.
67
- - `docs/failures/tempting-but-wrong.md` — refuted simplifications that passed
68
- review but failed pins.
69
- - `docs/harness/gates.md` — how `AGENTS.md` recipes, the meter's public path
70
- (`profile: true` → `mind.lastCost`), and `test/*.test.mjs` enforce the laws.
71
- - `docs/architecture/` — per-law derivation: each file says why, not how.
68
+ ## Elsewhere
69
+
70
+ - `docs/failures/tempting-but-wrong.md` — shortcuts that passed review and
71
+ failed the evidence.
72
+ - `docs/harness/gates.md` — the four executable gates.
73
+ - `src/derive/`, `src/alu/`, `src/rabitq-ivf/` — firewalled sublibraries, each
74
+ with its own README and tests.
@@ -1,19 +1,37 @@
1
- # INVARIANTS — Laws, Proofs, Derivations
1
+ # INVARIANTS — Where Each Law Lives and What Pins It
2
2
 
3
- | # | Law | Defined in | Pins | Doc |
4
- | -- | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------- |
5
- | 1 | Determinism | `src/config.ts:seed` `src/alphabet.ts:Alphabet` `src/mind/traverse.ts:guidedFirst` | `test/20` `test/42` | `determinism.md` |
6
- | 2 | Derived thresholds | `src/geometry.ts:mergeThreshold,identityBar,reachThreshold,significanceBar,consensusFloor,dominates` | `test/64` `test/40` | `thresholds.md` |
7
- | 3 | Exact decides / approximate proposes | `src/mind/primitives.ts:resolve` `src/mind/match.ts:locate,alignGraded` `src/mind/resonance.ts:bridge` | `test/51` | `exact-vs-approximate.md` |
8
- | 4 | One cost currency | `src/mind/graph-search.ts:MICRO,STEP,CONCEPT,PASS` `src/derive:lightestDerivation` (min,+) `src/mind/attention.ts:poolVotes` (+,+) | `test/55` `test/04` | `cost-model.md` |
9
- | 5 | Bounded reads | `src/store.ts:AbstractStore:nextFirst,parentsFirst,containersSlice,hasNext,bytesPrefix` `src/mind/traverse.ts:hubBound,hubCap` | `test/90` `test/14` | `bounded-reads.md` |
10
- | 6 | Fold contract | `src/geometry.ts:contentLevels,contentIdentity` `src/mind/primitives.ts:branchNaming` `src/mind/canonical.ts:canonicalWindows,chainReach` `src/canon.ts:canonicalizer` | `test/59` `test/63` `test/152` | `fold-contract.md` |
11
- | 7 | Mechanism market | `src/mind/pipeline-mechanism.ts:PipelineMechanism,Precomputed` `src/mind/pipeline.ts:think,worthRunning` | `test/01` `test/04` `test/153` | `mechanism-market.md` |
12
- | 8 | Two commonality measures | `src/mind/traverse.ts:reachOf,dominates,corpusN` (global) `cast.ts:depth[],MIN_WEAVE` (weave-local) | `test/17` `test/34` | `commonality.md` |
13
- | 9 | Memoization idempotence | `src/mind/pipeline-mechanism.ts:Precomputed` `src/mind/mind.ts:beginResponse,endResponse,_resolvedSubtrees` | `test/42` | `memoization.md` |
14
- | 10 | Caches as budgets | `src/store.ts:BoundedMap` `src/config.ts:StoreConfig:bytesCacheMax,recCacheBytes,haloCacheBytes` | `test/96` `test/91` | `caches.md` |
15
- | 11 | Honest degradation | `src/mind/pipeline.ts:weight=moves+PASS*unaccounted` `src/store.ts:BoundedMap:miss→re-derive` | `test/28` `test/84` | `store.md`+`caches.md` |
16
- | 12 | Meter contracts | `src/meter.ts:Meter,PhaseCost,time` `src/mind/pipeline-mechanism.ts:Precomputed.shared` | `test/55` | `meter.md` |
17
- | 13 | Saturation | `traverse.ts:edgeAncestors,types.ts:SaturationReason` `src/mind/junction.ts:junctionContainersFrom` `src/mind/resonance.ts:pivotInto` | `test/27` `test/16` | `saturation.md` |
18
- | 14 | Closure | `src/mind/derivation.ts:admissible,advance,closeOver` | `test/133`–`151` | `closure.md` |
19
- | 15 | Witnessed evidence | `src/mind/evidence.ts:witness,windowIndex` `src/mind/traverse.ts:chooseNext,askedEvidence,namedContinuations,answersOtherQuestions,coInstanceFiller,scaffoldExtents` | `test/154`, `test/155` | `evidence.md` |
3
+ `AGENTS.md` §2 names the five invariants that every change must keep. This table
4
+ routes all fifteen laws (numbered as in `INDEX.md`) to the code that defines
5
+ them and the tests that fail when they break.
6
+
7
+ | # | Law | Defined in | Pins |
8
+ | -- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------- |
9
+ | 1 | Determinism | `config.ts` (`seed`), `alphabet.ts`, `traverse.ts` (`guidedFirst`, `chooseNext`) | `test/20`, `test/42` |
10
+ | 2 | Derived thresholds | `geometry.ts`, `traverse.ts` (`corpusN`, `hubBound`, `atomReach`), `canonical.ts` (`chainReach`) | `test/40`, `test/64`, `test/78` |
11
+ | 3 | Exact decides | `mind/primitives.ts` (`resolve`, `exactNode`), `match.ts` (`locate`, `alignGraded`), `resonance.ts` (`bridge`), `attention.ts` | `test/51`, `test/56` |
12
+ | 4 | One cost currency | `graph-search.ts` (`MICRO`, `STEP`, `CONCEPT`, `PASS`), `src/derive` (min, +), `attention.ts` (`poolVotes`, +, +), `pipeline.ts` (`weigh`) | `test/04`, `test/55`, `test/151` |
13
+ | 5 | Match → project → gate | `match.ts` | `test/24`, `test/47`, `test/76` |
14
+ | 6 | Mechanism market | `pipeline-mechanism.ts` (`PipelineMechanism`, `Precomputed`), `pipeline.ts` (`think`, `worthRunning`) | `test/01`, `test/04`, `test/153` |
15
+ | 7 | Commonality | `traverse.ts` (`reachOf`, `dominates`, `hubWindows`), `cast.ts` (`depth[]`, `MIN_WEAVE`), `bridge.ts` (rarity) | `test/17`, `test/34`, `test/73` |
16
+ | 8 | Bounded reads | `store.ts` (`*First`, `containersSlice`, `has*`, `bytesPrefix`, `chainRun`), `traverse.ts` (`hubBound`, `hubCap`) | `test/14`, `test/89`, `test/90`, `test/119` |
17
+ | 9 | Store | `store.ts` (`AbstractStore`, `intern`), `store-sqlite.ts` | `test/02`, `test/08`, `test/36-bloom` |
18
+ | 10 | Fold contract | `geometry.ts` (`contentLevels`, `contentIdentity`), `primitives.ts` (`branchNaming`), `canonical.ts`, `canon.ts` | `test/59`, `test/63`, `test/148`, `test/152` |
19
+ | 11 | Memoization | `pipeline-mechanism.ts` (`Precomputed`), `mind.ts` (`beginResponse`, `endResponse`) | `test/42`, `test/155.4` |
20
+ | 12 | Saturation | `traverse.ts` (`edgeAncestors`), `junction.ts` (`junctionContainersFrom`), `resonance.ts` (`pivotInto`), `types.ts` (`SaturationStop`) | `test/16`, `test/27`, `test/34`, `test/49` |
21
+ | 13 | Meter | `meter.ts`, `Precomputed.shared` | `test/55` |
22
+ | 14 | Closure | `derivation.ts` (`admissible`, `advance`, `closeOver`) | `test/133`–`151` |
23
+ | 15 | Witnessed evidence | `evidence.ts` (`witness`, `windowIndex`), `traverse.ts` (`chooseNext`, `answersOtherQuestions`, `coInstanceFiller`, `scaffoldExtents`) | `test/154`, `test/155`, `test/76` |
24
+
25
+ Caches (`caches.md`: every acceleration is a `BoundedMap`, and a miss
26
+ re-derives) are pinned by `test/91` and `test/96`.
27
+
28
+ ## Honest silence
29
+
30
+ Every law above serves one contract the code cites by this file's name: **when
31
+ the evidence does not decide, say less, never something invented.** A budget
32
+ that runs out abstains and is counted (`junctionBudgetExhausted`). A cache miss
33
+ re-derives, never approximates. A question whose every window is scaffolding is
34
+ not bridged. When nothing accounts for the question, the price makes silence the
35
+ lightest answer, and an answer that is only near says so. A gap is honest; an
36
+ assembly carrying content the evidence did not license is a fabrication. Pinned
37
+ by `test/28`, `test/73` and `test/84`.