@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
@@ -1,115 +0,0 @@
1
- // 69-frame-filler.test.mjs — the frame-filler tier must not fire without its
2
- // evidence, and must refuse an ambiguous subject.
3
- //
4
- // WHAT THE MECHANISM DOES (src/mind/frame-filler.ts): when every other tier has
5
- // declined, take the query's described span, put a corroborated filler from a
6
- // trained context in its place, and require the STORE to already hold that key
7
- // byte-exactly. "We invent a lookup KEY, never an answer" — the answer is the
8
- // trained continuation of a form the store verifiably has.
9
- //
10
- // THE WIN IS REAL-STORE EVIDENCE, NOT A FIXTURE. On the 15.7M-node trained
11
- // store, `What is the capital of the country where the Eiffel Tower is?` goes
12
- // from silence to "The capital of France is Paris." (provenance `recall`), taking
13
- // analyze_training.ts's section G from 33.3% to 66.7% and the battery from 73.8%
14
- // to 76.2% with `0 weak` intact. A/B on warm caches: +50 ms on that query,
15
- // +16 ms on a refusing query that runs 480 probes, and +0 ms on
16
- // `What is the capital of Zamunda?` (guard 1 exits before probing) and on every
17
- // query that answers earlier.
18
- //
19
- // WHY NO POSITIVE FIXTURE TEST EXISTS — measured, not assumed. The mechanism
20
- // keys on corpus RARITY (container counts, the same reading the bridge's anchor
21
- // picking uses). At fixture scale that signal is absent and even inverted: in a
22
- // 21-deposit store `capital` reports 1 container and `landmark` reports 9, while
23
- // on the trained store `Eiffel` is 54 against `What` at 1,586. So a fixture
24
- // cannot make the query's rarest word land inside the description, which guard 1
25
- // requires — three fixture shapes were tried (bare, 21-deposit, and one with an
26
- // attested long word in the description) and none reached the positive path.
27
- // What a fixture CAN pin is the refusal side, which is what this file does.
28
-
29
- import { test } from "node:test";
30
- import assert from "node:assert/strict";
31
- import { Mind } from "../dist/src/index.js";
32
- import { SQliteStore } from "../dist/src/store-sqlite.js";
33
- import { frameFillerSubstitution } from "../dist/src/mind/frame-filler.js";
34
-
35
- const enc = (s) => new TextEncoder().encode(s);
36
- const FRAME = [
37
- ["What is the capital of France?", "Paris is the capital of France."],
38
- ["What is the capital of Spain?", "Madrid is the capital of Spain."],
39
- ["What is the capital of Italy?", "Rome is the capital of Italy."],
40
- ["What is the capital of Japan?", "Tokyo is the capital of Japan."],
41
- ];
42
- const LINK = [
43
- "What is the most famous landmark in France?",
44
- "The most famous landmark in France is the Eiffel Tower.",
45
- ];
46
- const LINK2 = [
47
- "What is the tallest structure in Spain?",
48
- "The tallest structure in Spain is the Eiffel Tower.",
49
- ];
50
- const Q = "What is the capital of the country where the Eiffel Tower is?";
51
-
52
- async function fixture(train) {
53
- const mind = new Mind({
54
- seed: 1,
55
- store: new SQliteStore({ path: ":memory:" }),
56
- });
57
- await mind.ingest(train);
58
- return mind;
59
- }
60
- /** Call the tier the way recall does: the query plus recall's ranked hit ids. */
61
- async function tier(mind, q) {
62
- const hits = await mind.store.resonate(mind.perceive(q).v, 24);
63
- return frameFillerSubstitution(mind, enc(q), hits.map((h) => h.id));
64
- }
65
-
66
- test("1. no linking evidence — the tier does not fire", async () => {
67
- // The frame is attested, but nothing in the store ties the description's
68
- // content to any filler. Guard 1 has nothing to qualify.
69
- const m = await fixture(FRAME);
70
- assert.equal(await tier(m, Q), null);
71
- await m.store.close();
72
- });
73
-
74
- test("2. an AMBIGUOUS subject is refused", async () => {
75
- // Two trained contexts hold the description's content and each proposes a
76
- // different filler. Guard 4: neither is licensed.
77
- const m = await fixture([...FRAME, LINK, LINK2]);
78
- assert.equal(await tier(m, Q), null);
79
- await m.store.close();
80
- });
81
-
82
- test("3. an unrelated query never grounds a frame neighbour", async () => {
83
- // The fabrication shape: a fictional filler in an attested frame. On the real
84
- // store this query resolves 24 keys (Chile, India, Japan, Italy …) once the
85
- // guards are weakened, so it is the case that most needs pinning.
86
- const m = await fixture([...FRAME, LINK]);
87
- for (
88
- const q of [
89
- "What is the capital of Zamunda?",
90
- "xyzzy plugh quux baz?",
91
- "qq8f3kz9 vv2m1x7w?",
92
- ]
93
- ) {
94
- assert.equal(await tier(m, q), null, `expected refusal for ${q}`);
95
- }
96
- await m.store.close();
97
- });
98
-
99
- test("4. the tier is deterministic and side-effect free", async () => {
100
- const m = await fixture([...FRAME, LINK]);
101
- const a = await tier(m, Q);
102
- const b = await tier(m, Q);
103
- assert.deepEqual(a, b);
104
- // Running it must not disturb the answers of forms that ground normally.
105
- assert.match(await m.respondText("What is the capital of France?"), /Paris/);
106
- await m.store.close();
107
- });
108
-
109
- test("5. end to end, the fixture's own trained forms still answer", async () => {
110
- const m = await fixture([...FRAME, LINK]);
111
- assert.match(await m.respondText("What is the capital of Spain?"), /Madrid/);
112
- assert.match(await m.respondText("What is the capital of Japan?"), /Tokyo/);
113
- assert.equal(await m.respondText("qq8f3kz9 vv2m1x7w?"), "");
114
- await m.store.close();
115
- });