@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
@@ -22,171 +22,145 @@ discovering bugs:**
22
22
  breaker; it can cause truncation and is not necessarily a budget-related
23
23
  measure. Therefore, it must be used wisely.
24
24
 
25
- ### 1. `score >= threshold` decides identity
26
-
27
- - **WRONG:** Treat a RaBitQ cosine above a cutoff as proof the bytes are the
28
- same node.
29
- - **WHY:** Scores are estimates that rank and gate; they never decide identity
30
- (`AGENTS §2` Invariant 3 — Exact decides / approximate proposes).
31
- - **CORRECT:** Gate with the score, decide with
32
- `resolve`/`findLeaf`/`canonResolve` and re-fold verification. Pinned by
33
- `test/51-structural-resonance-ladder.test.mjs` and
34
- `test/56-bridge-identity-admission.test.mjs`.
35
-
36
- ### 2. `Math.random()` / `Date.now()` on a behavioural path
37
-
38
- - **WRONG:** Sample randomness or wall-clock time in grounding, indexing, or
39
- tie-breaking.
40
- - **WHY:** Determinism is the product: same seed + deposit order + query ⇒
41
- identical bytes (`AGENTS §2` Invariant 1).
42
- - **CORRECT:** Derive all randomness from `MindConfig.seed` via `rng`/`Prng`;
43
- keep `example/train_base` as the only non-library exception. Pinned by
44
- `test/20-stability.test.mjs` and
45
- `test/42-recognise-trace-idempotence.test.mjs`.
46
-
47
- ### 3. Last-inserted tie-break
48
-
49
- - **WRONG:** Break equal-rank ties by picking the most recently inserted
50
- edge/node.
51
- - **WHY:** Tie-breaks must be corpus-determined and stable; last-inserted is
52
- recency-dependent (`AGENTS §2` Invariant 1 — first-inserted fallback).
53
- - **CORRECT:** `guidedFirst`/`chooseNext`/`chooseAmong`: rank then
54
- first-inserted (lowest node id / `LIMIT 1` insertion order). Pinned by
55
- `test/03-recall.test.mjs` determinism suites.
56
-
57
- ### 4. Tunable threshold in `config.ts`
58
-
59
- - **WRONG:** Add a new `threshold: number` to `src/config.ts` and tune it.
60
- - **WHY:** Every cutoff is a formula over `D`, `W`, or `N` in `src/geometry.ts`;
61
- config holds only capacities/budgets (`AGENTS §2` Invariant 2 — Derived
62
- thresholds).
63
- - **CORRECT:** Add `mergeThreshold`/`identityBar`/`significanceBar` etc.
64
- derivation in `geometry.ts`; `traverse.ts:hubBound` for scale caps. Pinned by
65
- `test/64-two-ended-thresholds.test.mjs` and
66
- `test/40-choosenext-scale-guard.test.mjs`.
67
-
68
- ### 5. Tuning `PASS` to encode policy
69
-
70
- - **WRONG:** Raise/lower `PASS` (1000/byte) so "computation always wins" or
71
- another preference falls out of pricing.
72
- - **WHY:** The ladder's order `MICRO < STEP < CONCEPT < PASS` is the contract;
73
- policy is enforced by masking, not pricing (`AGENTS §2` Invariant 4 — One cost
74
- currency; `docs/architecture/cost-model.md` § Policy is not cost).
75
- - **CORRECT:** Keep `PASS` dominating; enforce precedence in the caller (e.g.
76
- `cover.ts` masks recognised sites overlapped by `ComputedResult`). Pinned by
77
- `test/04-think.test.mjs` and `test/55-cost-meter.test.mjs`.
78
-
79
- ### 6. Reimplementing `locate`/`align` inside a mechanism
80
-
81
- - **WRONG:** Copy-paste matching logic into `mind/mechanisms/*.ts` with a
82
- private gate.
83
- - **WHY:** Match/project/gate is factored once in `mind/match.ts` (`AGENTS §2`
84
- Cross-cutting contracts; `AGENTS §3` — Where things live).
85
- - **CORRECT:** Configure the shared family:
86
- `locate`/`alignRuns`/`alignGraded`/`frameSlots` + `follow`/`reverseContext` +
87
- `isSpanShaped`/`carriesFillers` with a `geometry.ts` gate. Pinned by
88
- `test/50-cast-analog-consensus-floor.test.mjs`.
89
-
90
- ### 7. Putting voicing gates in `frameSlots`
91
-
92
- - **WRONG:** Make `frameSlots` refuse pairings that fail `carriesFillers` or
93
- reference's four voicing conditions.
94
- - **WHY:** `frameSlots` reports (contracted gaps tagged
95
- substitution/insertion/deletion); `carriesFillers` judges;
96
- `Precomputed.frames` inventories — elects nothing (`AGENTS §2` Cross-cutting
97
- contracts — `docs/architecture/match-project.md` § Frame reading).
98
- - **CORRECT:** Report everything in the shared layer; apply
99
- `substituteAll(contA, fillersA→fillersB)==contB` and
100
- frame-dominance/`W`-reach/distinctness in the consumer (reference). Pinned by
101
- `test/47-cast-comparison-coverage.test.mjs`.
102
-
103
- ### 8. Swapping corpus-global and weave-local commonality
104
-
105
- - **WRONG:** Use `reachOf`/`dominates(reach,N)` to decide CAST's frame, or
106
- `depth[i]`/`dominates(depth, aligned)` to decide climb/IDF.
107
- - **WHY:** They measure different things: global reach (minority discriminates,
108
- powers climb/pooling) vs weave-local depth with `MIN_WEAVE=2` (what the local
109
- cohort shares, powers CAST) (`docs/architecture/commonality.md`).
110
- - **CORRECT:** Climb/attention uses corpus-global;
111
- `frame(i) ⇔ depth[i]>MIN_WEAVE ∧ dominates(depth[i],aligned)` for CAST. Pinned
112
- by `test/50-cast-analog-consensus-floor.test.mjs` and
113
- `test/67-climb-anchor-breadth.test.mjs`.
114
-
115
- ### 9. Materialise-then-slice instead of `LIMIT ?`
116
-
117
- - **WRONG:** `store.next(id).slice(0, k)` or `parents(id).length` to cap a
118
- fan-out.
119
- - **WHY:** Per-query reads must not grow with `N`; caps are enforced in SQL as
120
- `LIMIT ?` / `EXISTS` probes (`AGENTS §2` Invariant 5 — Bounded reads).
121
- - **CORRECT:** `nextFirst`/`parentsFirst`/`containersSlice` with `hubBound`
122
- (`ceil(sqrt(N))`), `hasNext`/`hasParents`/`hasHalo` probes,
123
- `bytesPrefix`/`contentLen` caps, `chainRun` CTE. Pinned by
124
- `test/14-scaling.test.mjs` and `test/90-connector-read-cap.test.mjs`.
125
-
126
- ### 10. Bypassing `recogniseMemo` under trace
127
-
128
- - **WRONG:** Skip `recogniseMemo`/`perceiveMemo`/`climbMemo` when
129
- `ctx.trace !== null` to "emit more steps."
130
- - **WHY:** Only `guidedNext`/`sharedReachMemo` are trace-bypassed; bypassing
131
- recognition re-runs `recogniseImpl` with a warm cache and changes site count —
132
- 31→5 observed (`AGENTS §2` Cross-cutting — `Precomputed` owns memoization;
133
- `docs/architecture/memoization.md`).
134
- - **CORRECT:** Always consult `recogniseMemo`; `foldTree` already descends fully
135
- when `visit` is present. Pinned by
136
- `test/42-recognise-trace-idempotence.test.mjs`.
137
-
138
- ### 11. Stopping junction ascent when one cone is exhausted
139
-
140
- - **WRONG:** Terminate the `junction.ts` walk as soon as parents or containers
141
- run out.
142
- - **WHY:** Junction ascent climbs both cones within a bounded `√N·W` walk via
143
- `WalkCache`; exhausting one cone does not imply the other is exhausted —
144
- stopping early misses the shared ancestor (`AGENTS §2` Cross-cutting contracts
145
- — `junction.ts` is the shared ascent; `AGENTS §3` — `WalkCache`).
146
- - **CORRECT:** Continue the live cone until the walk budget is spent or a
147
- meeting point is found; cap reads with `hubBound`. Pinned by
148
- `test/34-cross-region.test.mjs` and
149
- `test/52-climb-consensus-instrumentation.test.mjs`.
150
-
151
- ### 12. Imposing turn boundaries on `fold`
152
-
153
- - **WRONG:** Cut the byte stream at conversation turn edges before folding, so
154
- deposits and queries fold differently.
155
- - **WHY:** Perception is a pure function of the bytes; deposit and inference
156
- must compute the same tree for the same input (`AGENTS §1` Orientation — Hard
157
- facts).
158
- - **CORRECT:** Fold content-defined cuts (`contentLevels` in `geometry.ts` +
159
- `twoEndedSeat`); turns are API state in `mind/mind.ts`, not segmentation.
160
- Pinned by `test/59-fold-invariance.test.mjs` and
161
- `test/63-fold-invariants.test.mjs`.
25
+ Each trap below was tried, looked like an improvement, and was measured wrong.
26
+ The laws themselves live in `docs/architecture/`; this file keeps only the
27
+ shortcuts that pass review and fail the evidence.
28
+
29
+ ### 1. Telling the fold where the boundaries are
30
+
31
+ - **Tempting:** cut a conversation at its turns before folding, or stamp a
32
+ deposit as "the next turn" so its prefix is reused.
33
+ - **Refuted:** a cut the question cannot reproduce from its own bytes splits one
34
+ identity in two. Alignment went quadratic (5.2M cells against 0), and turns
35
+ asked verbatim stopped resolving. Reusing a `prev` that was not a
36
+ byte-identical prefix gave a wrong tree on 336 of 400 streams.
37
+ - **Instead:** the content decides every cut, and reuse is keyed by the prefix
38
+ bytes (`fold-contract.md`; `test/59`, `test/63`, `test/152`).
39
+
40
+ ### 2. Asking the vector index whether two branches are the same
41
+
42
+ - **Tempting:** at intern, probe the ANN index for a near-duplicate to merge.
43
+ - **Refuted:** it was the dominant training cost, and the 1-bit code ranked a
44
+ byte-distinct branch as nearest, so two different subtrees collapsed onto one
45
+ id.
46
+ - **Instead:** exact dedup, then same-bytes reuse, then a near merge against the
47
+ write buffer only, decided by bytes (`store.md`; `test/02`).
48
+
49
+ ### 3. Reading one population's cut with another population's measure
50
+
51
+ - **Tempting:** "common" is common, so corpus reach can decide CAST's frame,
52
+ weight can stand for distinct structures, and a window's containers can stand
53
+ for the contexts it reaches.
54
+ - **Refuted:**
55
+ - corpus reach for the cohort's frame failed the reorder probe (`test/17`);
56
+ - counting weight instead of distinct structures gave 29/42 against 6/42;
57
+ - container fan-out read as a hub called `fran` saturated, though it sits in 4
58
+ containers and reaches only 2 contexts (`test/49`).
59
+ - **Instead:** name the population; three measures, never substituted
60
+ (`commonality.md`, `saturation.md`).
61
+
62
+ ### 4. Inventing a bar, or reusing one for a different quantity
63
+
64
+ - **Tempting:** a new number fitted to the case at hand, or a derived bar reused
65
+ elsewhere because it is derived.
66
+ - **Refuted:** `consensusFloor` is priced for pooled votes, and gating a single
67
+ fact's support with it refused clear corroboration at N≈325K. A fixed identity
68
+ cosine tolerates four foreign windows on a long span.
69
+ - **Instead:** a bar is never a new number. Derive it from `D`, `W` and `N` for
70
+ the quantity it gates (`thresholds.md`; `test/40`, `test/64`).
71
+
72
+ ### 5. Stopping a junction walk early
73
+
74
+ - **Tempting:** stop when one side's upward cone is exhausted, or borrow
75
+ `edgeAncestors`' lateral-cone limit.
76
+ - **Refuted:** a junction can be reachable from one side only (`cold or hot`
77
+ from `cold`, while the cone of `hot` is empty), and the lateral limit
78
+ discarded half of the successful junctions.
79
+ - **Instead:** per-node hub guards, plus the shared `bound·W` net
80
+ (`saturation.md`; `test/16`, `test/34`).
81
+
82
+ ### 6. Reading company by token
83
+
84
+ - **Tempting:** a halo of whole-partner signatures; or a sketch of depth 1; or
85
+ one that stops at the first unit seen twice; or one that includes byte atoms.
86
+ - **Refuted:** in turn, these gave synonyms at 0.146 against a 0.516 bar; no
87
+ signal (0.0319 against a 0.0416 control); pairs that never met (0.0165 against
88
+ 0.0375); and CAST's analogy gate silenced (0.3636 to 0.2004).
89
+ - **Instead:** a bottom-k sketch of constituents at every depth, keyed by
90
+ identity, with hubs and atoms excluded (`halo-sketch.md`;
91
+ `test/76-type-level-company`).
92
+
93
+ ### 7. Letting a fragment speak
94
+
95
+ - **Tempting:** a recognised form with continuations is evidence wherever it
96
+ appears.
97
+ - **Refuted:** a fragment inherits the edges of every whole it sits in.
98
+ Witnessing `born?` named nine strangers' birthplaces, the fragment `director`
99
+ cancelled the argument `Man at Bath`, and `ong)?` voiced a stranger's
100
+ birthplace.
101
+ - **Instead:** only deposited contexts establish anything, and a fragment that
102
+ answers other questions leads somewhere only when the question names one of
103
+ its continuations (`evidence.md`; `test/154`).
104
+
105
+ ### 8. Making scaffolding free
106
+
107
+ - **Tempting:** scaffolding is nobody's evidence, so charge nothing for it in
108
+ the market.
109
+ - **Refuted:** dialogue answers changed (`How are you today?`), because for a
110
+ question made only of scaffolding, covering those bytes is the evidence.
111
+ - **Instead:** scaffolding is nobody's debt in the derivation, while the price
112
+ still charges every unexplained byte (`evidence.md`).
113
+
114
+ ### 9. Giving a new reading its own analysis
115
+
116
+ - **Tempting:** a new tier climbs, resonates or aligns for itself.
117
+ - **Refuted:** the co-instance tier's private climb added 16% climb visits and
118
+ named nothing. Reading the shared climb's points named the same things for
119
+ free.
120
+ - **Instead:** read `Precomputed`, and add an analysis there only if none exists
121
+ (`memoization.md`).
122
+
123
+ ### 10. Putting a consumer's gate in the shared matcher
124
+
125
+ - **Tempting:** `frameSlots` refuses what `reference` would refuse anyway.
126
+ - **Refuted:** the shared reading became shaped like `reference` and hid three
127
+ of four real pairings from every other consumer.
128
+ - **Instead:** the matcher reports, the consumer judges (`match-project.md`;
129
+ `test/47`).
130
+
131
+ ### 11. Dropping weak evidence, or crediting it as strong
132
+
133
+ - **Tempting:** remove regions shorter than one window from the climb, or count
134
+ them as exact because their bytes resolve.
135
+ - **Refuted:** dropping them took the suite from 441 to 406. Crediting them as
136
+ exact let the 3-byte `of` lift a junk root past `consensusFloor`.
137
+ - **Instead:** they vote on their gist and pay the margin that approximate
138
+ evidence pays, scaled by how much of them is not stored (`attention.ts`).
139
+
140
+ ### 12. Trying the exact supply first, then the approximate
141
+
142
+ - **Tempting:** a chain of `exact ?? approximate` supplies.
143
+ - **Refuted:** the approximate tier then overrides an ambiguity the exact one
144
+ found. For prefix completion, two forms opened by the index must refuse,
145
+ whatever resonance ranks first.
146
+ - **Instead:** one union, decided once by the guards (`prefix-completion.md`;
147
+ `test/72`).
162
148
 
163
149
  ### 13. Capping a combinatorial explosion instead of budgeting it
164
150
 
165
- - **WRONG:** Answer a combinatorial explosion with a geometry-derived limit — a
166
- cap on the pairs a sweep enumerates, the continuations a hop may offer, the
167
- candidates a scan probes. A derived limit is the right cutoff for a DECISION;
168
- used as the answer to explosion it is a short-circuit.
169
- - **WHY:** It stops the computation silently. Reach is lost, the capability that
170
- depended on it goes with it, and no test fails, because the tests were written
171
- against the capped behaviour. Capping and removing the cap are both wrong:
172
- capping truncates, removing lets the cost run, and the two failure modes hide
173
- each other.
174
- - **CORRECT:** BUDGET it. The work is charged in the one currency
175
- (`MICRO`/`STEP`/`CONCEPT`/`PASS`; `weight = moves + PASS·unaccounted`, see
176
- `docs/architecture/cost-model.md`), the charge is visible in the meter and the
177
- rationale, and the SEARCH decides whether the work is worth paying — so
178
- inference is never locked by a limit and nothing is truncated in silence.
179
- Where the work is mechanical rather than evidential — enumeration, scans,
180
- sweeps — the answer is an algorithm whose cost is structural in the bytes it
181
- is given, not a smaller cap.
182
- - **THE IDEAL:** a universal **closure engine** — one law of closure, stated in
183
- the quantities the machine already has (`leadsSomewhere`, the
184
- exact-then-canonical identity, `accounted` bytes, the ladder, `hubBound`),
185
- from which the reach of a gap, the offer of a hop, the depth of a join and the
186
- scope of a substitution are CONSEQUENCES, not four separate decisions. Where
187
- the repository stands against it — the engine (`closeOver`), which of the four
188
- follow from the law, and the one that does not, with the reason — is stated in
189
- `docs/architecture/closure.md`, and nowhere else.
190
- - **THE STANDARD A CHANGE MUST MEET:** state which consequence it is, and show
191
- it following from the law. A change that cannot be stated that way is not
192
- ready.
151
+ - **Tempting:** answer an explosion with a derived limit: a cap on the pairs a
152
+ sweep enumerates, the continuations a hop offers, the candidates a scan
153
+ probes.
154
+ - **Refuted:** a cap stops the computation silently. Reach is lost, the
155
+ capability that depended on it goes with it, and no test fails, because the
156
+ tests were written against the capped behaviour. Capping truncates; removing
157
+ the cap lets the cost run; each failure hides the other.
158
+ - **Instead:** budget it. Charge the work in the one currency, make it visible
159
+ in the meter and the rationale, and let the search decide whether it is worth
160
+ paying (`cost-model.md`). Where the work is mechanical (enumeration, scans,
161
+ sweeps), the answer is an algorithm whose cost is structural in its input, not
162
+ a smaller cap. The ideal is one closure law from which the reach of a gap, the
163
+ offer of a hop, the depth of a join and the scope of a substitution follow as
164
+ consequences. Where the repository stands against that ideal is stated in
165
+ `closure.md`, and nowhere else. A change must state which consequence it is,
166
+ and show that it follows from the law.
@@ -1,58 +1,53 @@
1
1
  # Gates
2
2
 
3
- Four executable gates. Each: run the command, check what it guards, follow its
4
- §.
3
+ There are four executable gates. The laws in `docs/architecture/` are enforced
4
+ by these and by the pins each law lists.
5
5
 
6
- ## 1 — Correctness (all suites)
6
+ ## 1. Correctness — every suite
7
7
 
8
8
  ```bash
9
- npm test
9
+ npm test # tsc, then node --test over test/**/*.test.mjs against dist/
10
10
  ```
11
11
 
12
- Guards honest silence, determinism, and every pinned contract. Silence:
13
- unrelated queries ground to nothing (`test/28`, `50`, `56`, `67`, `76`, `84`).
14
- Determinism: same seed + deposit order + query gives byte-identical answer
15
- (`test/20`). Every invariant is pinned, the closure law included
16
- (`test/133`–`151`). §14–25 (pipeline), §64 (derived thresholds), AGENTS.md §2
17
- invariants 1–5.
12
+ This gate guards every pinned contract, and two in particular:
18
13
 
19
- ## 2 — Work accounting (profiler)
14
+ - **Honest silence.** An unrelated question grounds to nothing (`test/28`,
15
+ `test/50`, `test/56`, `test/67`, `test/76`, `test/84`).
16
+ - **Determinism.** The same seed, deposit order and question give a
17
+ byte-identical answer (`test/20`).
18
+
19
+ The closure law is pinned in `test/133`–`151`, and the docs themselves are read
20
+ by `test/137`: an export that only the docs describe counts as documented.
21
+
22
+ ## 2. Work accounting — the profiler
20
23
 
21
24
  ```js
22
- const mind = new Mind({ profile: true }); // meter attached per response
23
- await mind.respondText(q); // then read mind.lastCost
25
+ const mind = new Mind({ profile: true });
26
+ await mind.respondText(q);
24
27
  console.log(formatReport(mind.lastCost)); // sumReports() over several
25
28
  ```
26
29
 
27
- The public path is the harness (`AGENTS.md` §6); there is no separate bench
28
- script. Guards without trace: counters exact and diffable between COLD runs;
29
- phases nest (not disjoint — each phase is charged by its own layer); shared
30
- analyses charged to themselves, not to the first toucher; millisecond fields are
31
- non-deterministic hints only. With an `inspectRationale` callback attached,
32
- recognition idempotence still holds (`test/42`). `src/meter.ts`,
33
- `docs/architecture/meter.md`, §55, `AGENTS.md` §6.
30
+ The public path is the harness: there is no separate bench script (`AGENTS.md`
31
+ §6, `meter.md`). Compare cold runs by their counters. Attaching an
32
+ `inspectRationale` callback must not change the answer (`test/42`).
34
33
 
35
- ## 3 — Dependency footprint
34
+ ## 3. Dependency footprint
36
35
 
37
36
  ```bash
38
37
  node --test test/88-dependency-footprint.test.mjs
39
38
  ```
40
39
 
41
- Guards `dist/src` imports only `node:` + relative paths, and `package.json`
42
- declares no `dependencies` (examples use `devDependencies` lazily). The
43
- near-zero footprint is a product feature. AGENTS.md §7, §3 (store has one
44
- runtime dep: `node:sqlite`).
40
+ `dist/src` may import only `node:` builtins and relative paths, and
41
+ `package.json` declares no `dependencies` (`AGENTS.md` §7).
45
42
 
46
- ## 4 — Fold invariance and sublinear scaling
43
+ ## 4. Fold invariance and sublinear scaling
47
44
 
48
45
  ```bash
49
46
  node --test test/59-fold-invariance.test.mjs test/63-fold-invariants.test.mjs
50
47
  node --test test/14-scaling.test.mjs
51
48
  ```
52
49
 
53
- Guards: `59+63` — segmentation is content-defined (`contentBoundaries`), not
54
- positional; grid regression (14.3% survival) cannot pass. `14` — inference cost
55
- is sublinear in corpus size (power-law exponent ≪ 1) and constant-rate in input
56
- length; measured on independent disjoint corpora via log–log slope.
57
- `src/geometry.ts` (`contentLevels`), `docs/architecture/fold-contract.md` +
58
- `bounded-reads.md`, §59, §63.
50
+ - `test/59` and `test/63`: segmentation is content-defined, so the grid's 14.3%
51
+ shift survival cannot pass (`fold-contract.md`).
52
+ - `test/14`: inference is sublinear in corpus size, measured as a log–log slope
53
+ over independent corpora, and linear in input length (`bounded-reads.md`).
@@ -1,81 +1,34 @@
1
1
  # ALU — Computation as an Extension
2
2
 
3
- The ALU is a self-contained sublibrary (`src/alu/`) that knows nothing about the
4
- pipeline. `aluToMechanism` (`src/mind/mechanisms/alu.ts`) wraps it as an
5
- ordinary `PipelineMechanism`; cover owns masking.
3
+ The ALU is a self-contained sublibrary (`src/alu/`, its own README) that knows
4
+ nothing about the pipeline. `aluToMechanism` (`src/mind/mechanisms/alu.ts`)
5
+ wraps it as an ordinary `PipelineMechanism`. It is the one way Sema produces
6
+ bytes that no deposit or asker supplied, and those bytes are authoritative.
6
7
 
7
- ## How it joins search
8
+ ## How it joins the market
8
9
 
9
- Every mechanism may implement `parse(query) → ComputedSpan[]` (`{i,j,bytes}`).
10
- `think` (`src/mind/pipeline.ts`) collects all parses before the grounding loop.
11
- `pre.computed` holds the authoritative spans. Each becomes a candidate at `STEP`
12
- (1) with `accounted: [[i,j]]`:
10
+ Every mechanism may implement `parse(query) → ComputedSpan[]`. `think` collects
11
+ every parse into `pre.computed` before any `floor` runs. Each computed span is a
12
+ candidate at `STEP`, with `accounted = [[i, j]]`. The floor is `0` when there
13
+ are computed spans, and `null` otherwise.
13
14
 
14
- ```ts
15
- // src/mind/mechanisms/alu.ts — run()
16
- { bytes: u.bytes, accounted: [[u.i, u.j]], moves: STEP }
17
- ```
15
+ ## Computation always wins — by masking, not by price
18
16
 
19
- `floor` returns `0` when `pre.computed` is non-empty, else `null`.
20
-
21
- ## Masking — computation always wins
22
-
23
- `cover` (`src/mind/mechanisms/cover.ts`) masks any recognised site whose bytes
24
- overlap a computed span. A learned `2+2 → 5` is dropped; the computed `4` is the
25
- sole cover there. Masking is the only precedence — a computed span and a learned
26
- edge both cost `STEP`.
27
-
28
- A computed span and an unrelated rewrite still compose (`"ice 2+2" → "cold 4"`).
29
-
30
- ## Registry — `derive` composes ops
31
-
32
- `OperationRegistry` (`src/alu/src/operation.ts`) holds every op indexed by
33
- canonical name and surface form. `prim` registers irreducible roots; `derive`
34
- registers a rewrite over existing ops via `ctx.apply`:
35
-
36
- ```ts
37
- registry.derive(
38
- "hypot",
39
- 2,
40
- ["hypot"],
41
- (args, ctx) =>
42
- ctx.apply("sqrt", [ctx.apply("add", [
43
- ctx.apply("multiply", [args[0], args[0]]),
44
- ctx.apply("multiply", [args[1], args[1]]),
45
- ])]),
46
- );
47
- ```
48
-
49
- `derive(name, arity, surfaceForms, body)` — name it, list forms, write the body
50
- in terms of existing ops. No kernel or graph-search edit.
51
-
52
- ## Broadcast — scalar ops over n-d
53
-
54
- One place (`OperationRegistry.context`): a non-structural op applied to `nd`
55
- lists lifts element-wise, recursing into nested `nd`. Structural ops (`nd`,
56
- `length`, `at`, `reduce`, …) are broadcast-exempt — they consume the list whole.
57
- So `add([1,2,3], 10) = [11,12,13]` without matrix code.
58
-
59
- ## Resonance — meaning pre-resolved
60
-
61
- Operand meanings are pre-resolved before the synchronous kernel runs
62
- (`AluResonance` / `prefetchResonance` in `src/alu/src/resonance.ts`):
63
- `recogniseOp` maps a span to its operation concept, `opposite` finds the
64
- resonant inverse of a symbol for the polymorphic `inverse`. Literal surface
65
- forms need no host; meaning-based paths do.
17
+ `cover` masks any recognised site that overlaps a computed span, so a learnt
18
+ `2+2 → 5` is dropped and the computed `4` is the only cover there. A computed
19
+ span and a learnt edge both cost `STEP`: precedence is policy, enforced by
20
+ masking (`cost-model.md`). A computed span still composes with an unrelated
21
+ rewrite: `ice 2+2` → `cold 4`.
66
22
 
67
23
  ## Provenance
68
24
 
69
- `cover`. A computation is grounded by cover: this adapter's `parse` puts the
70
- authoritative span into `pre.computed`, cover masks it, and cover's derivation
71
- carries the answer out (measured: 9 of 9 computed probes report `cover` —
72
- `137*24`, `1000 - 421`, `15 * 7`, `3+3`, `5*5`). The adapter therefore declares
73
- `cover` — a mechanism may not invent a label outside the pipeline's `Provenance`
74
- vocabulary, because post-grounding gates on it (see `pipeline-mechanism.ts`).
75
- The ALU's own act is named in the TRACE (`evalComputation`/`computeExtensions`),
76
- not in the provenance.
25
+ `cover`. Cover's derivation carries the computed answer out: 9 of 9 computed
26
+ probes, such as `137*24` and `1000 - 421`, report `cover`. A mechanism may not
27
+ invent a label outside the pipeline's `Provenance` vocabulary, because
28
+ post-grounding gates on it. The ALU's own act is named in the trace
29
+ (`evalComputation`, `computeExtensions`).
77
30
 
78
31
  ## Pins
79
32
 
80
- - `test/18-alu.test.mjs` — arithmetic, masking, and resonance-gated ops
81
- - `test/19-nd.test.mjs` — `nd` lists, broadcast, and higher-order ops
33
+ - `test/18` — arithmetic, masking, and operations gated by resonance.
34
+ - `test/19` — `nd` lists, broadcast, and higher-order operations.