@hviana/sema 0.8.3 → 0.8.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 (85) hide show
  1. package/AGENTS.md +11 -10
  2. package/README.md +17 -38
  3. package/dist/example/demo.js +85 -34
  4. package/dist/src/geometry.d.ts +0 -10
  5. package/dist/src/geometry.js +0 -12
  6. package/dist/src/meter.d.ts +11 -0
  7. package/dist/src/meter.js +11 -0
  8. package/dist/src/mind/articulation.js +1 -1
  9. package/dist/src/mind/attention.js +2 -1
  10. package/dist/src/mind/derivation.d.ts +201 -0
  11. package/dist/src/mind/derivation.js +327 -0
  12. package/dist/src/mind/graph-search.d.ts +2 -1
  13. package/dist/src/mind/graph-search.js +37 -15
  14. package/dist/src/mind/match.d.ts +2 -0
  15. package/dist/src/mind/match.js +2 -0
  16. package/dist/src/mind/mechanisms/alu.js +0 -2
  17. package/dist/src/mind/mechanisms/cast.d.ts +1 -5
  18. package/dist/src/mind/mechanisms/cast.js +15 -18
  19. package/dist/src/mind/mechanisms/confluence.d.ts +0 -3
  20. package/dist/src/mind/mechanisms/confluence.js +3 -9
  21. package/dist/src/mind/mechanisms/cover.js +17 -20
  22. package/dist/src/mind/mechanisms/extraction.d.ts +0 -1
  23. package/dist/src/mind/mechanisms/extraction.js +13 -8
  24. package/dist/src/mind/mechanisms/prefix-completion.js +0 -1
  25. package/dist/src/mind/mechanisms/recall.d.ts +0 -1
  26. package/dist/src/mind/mechanisms/recall.js +8 -9
  27. package/dist/src/mind/mechanisms/reference.js +3 -4
  28. package/dist/src/mind/pipeline-mechanism.d.ts +1 -4
  29. package/dist/src/mind/pipeline.js +106 -41
  30. package/dist/src/mind/rationale.d.ts +0 -11
  31. package/dist/src/mind/rationale.js +6 -32
  32. package/dist/src/mind/reasoning.d.ts +4 -30
  33. package/dist/src/mind/reasoning.js +183 -151
  34. package/dist/src/mind/types.js +6 -3
  35. package/docs/INDEX.md +23 -24
  36. package/docs/INVARIANTS.md +16 -17
  37. package/docs/architecture/bounded-reads.md +4 -4
  38. package/docs/architecture/closure.md +65 -0
  39. package/docs/architecture/commonality.md +27 -18
  40. package/docs/architecture/cost-model.md +5 -5
  41. package/docs/architecture/exact-vs-approximate.md +4 -4
  42. package/docs/architecture/factored-machinery.md +14 -14
  43. package/docs/architecture/mechanism-market.md +9 -9
  44. package/docs/architecture/meter.md +4 -5
  45. package/docs/architecture/store.md +2 -2
  46. package/docs/architecture/thresholds.md +1 -1
  47. package/docs/failures/tempting-but-wrong.md +11 -1
  48. package/docs/harness/gates.md +6 -6
  49. package/docs/mechanisms/cover.md +2 -2
  50. package/example/demo.ts +90 -37
  51. package/jsr.json +1 -1
  52. package/package.json +1 -1
  53. package/src/geometry.ts +0 -13
  54. package/src/meter.ts +11 -0
  55. package/src/mind/articulation.ts +0 -1
  56. package/src/mind/attention.ts +2 -1
  57. package/src/mind/derivation.ts +473 -0
  58. package/src/mind/graph-search.ts +37 -20
  59. package/src/mind/match.ts +2 -0
  60. package/src/mind/mechanisms/alu.ts +0 -2
  61. package/src/mind/mechanisms/cast.ts +17 -21
  62. package/src/mind/mechanisms/confluence.ts +3 -13
  63. package/src/mind/mechanisms/cover.ts +17 -20
  64. package/src/mind/mechanisms/extraction.ts +13 -9
  65. package/src/mind/mechanisms/prefix-completion.ts +0 -1
  66. package/src/mind/mechanisms/recall.ts +7 -9
  67. package/src/mind/mechanisms/reference.ts +2 -3
  68. package/src/mind/pipeline-mechanism.ts +1 -4
  69. package/src/mind/pipeline.ts +121 -46
  70. package/src/mind/rationale.ts +6 -36
  71. package/src/mind/reasoning.ts +208 -178
  72. package/src/mind/types.ts +5 -2
  73. package/test/133-the-decision-point-renders-the-state.test.mjs +204 -0
  74. package/test/134-the-law-explains-the-engines-own-refusal.test.mjs +237 -0
  75. package/test/135-one-law-any-producer.test.mjs +289 -0
  76. package/test/136-the-two-named-limits.test.mjs +205 -0
  77. package/test/137-the-law-lives-once-and-below.test.mjs +400 -0
  78. package/test/138-the-remainder-drains-only-what-a-move-declares.test.mjs +62 -0
  79. package/test/139-the-witness-is-engagement-not-explanation.test.mjs +51 -0
  80. package/test/140-irrelevant-supply-does-not-change-an-answer.test.mjs +48 -0
  81. package/test/141-the-question-is-paid-at-construction.test.mjs +98 -0
  82. package/test/36-already-answered-fusion.test.mjs +20 -2
  83. package/test/37-cluster-dispersion-fusion.test.mjs +30 -3
  84. package/test/38-reason-restate-guard.test.mjs +22 -2
  85. package/test/55-cost-meter.test.mjs +4 -1
@@ -94,7 +94,16 @@ test("fuseAttention: a root whose continuation is already answered in the query
94
94
  }),
95
95
  guide,
96
96
  };
97
- const out = dec(await fuseAttention(m, q, primary, pre));
97
+ // fusion consumes and returns the derivation STATE; these cases exercise the
98
+ // mechanism's own gates, so the state is the minimum one for them.
99
+ const out = dec(
100
+ (await fuseAttention(m, q, {
101
+ product: primary,
102
+ accounted: [],
103
+ remainder: [],
104
+ cost: 0,
105
+ }, pre)).product,
106
+ );
98
107
  assert.ok(
99
108
  !out.includes("reply-greet"),
100
109
  `a root whose continuation is already answered in the query must not fuse in, got "${out}"`,
@@ -126,7 +135,16 @@ test("fuseAttention: ordinary multi-topic fusion (no embedded answers) is comple
126
135
  }),
127
136
  guide,
128
137
  };
129
- const out = dec(await fuseAttention(m, q, primary, pre));
138
+ // fusion consumes and returns the derivation STATE; these cases exercise the
139
+ // mechanism's own gates, so the state is the minimum one for them.
140
+ const out = dec(
141
+ (await fuseAttention(m, q, {
142
+ product: primary,
143
+ accounted: [],
144
+ remainder: [],
145
+ cost: 0,
146
+ }, pre)).product,
147
+ );
130
148
  assert.ok(
131
149
  out.includes("answer alpha"),
132
150
  `an ordinary further topic must still fuse in, got "${out}"`,
@@ -127,7 +127,16 @@ test("fuseAttention: 2 clusters, low breadth — dispersion alone is enough (gap
127
127
  }),
128
128
  guide,
129
129
  };
130
- const out = dec(await fuseAttention(m, q, primary, pre));
130
+ // fusion consumes and returns the derivation STATE; these cases exercise the
131
+ // mechanism's own gates, so the state is the minimum one for them.
132
+ const out = dec(
133
+ (await fuseAttention(m, q, {
134
+ product: primary,
135
+ accounted: [],
136
+ remainder: [],
137
+ cost: 0,
138
+ }, pre)).product,
139
+ );
131
140
  assert.equal(
132
141
  out,
133
142
  "answer alpha" + dec(primary),
@@ -154,7 +163,16 @@ test("fuseAttention: 1 cluster, dominant breadth — dominance alone is enough (
154
163
  }),
155
164
  guide,
156
165
  };
157
- const out = dec(await fuseAttention(m, q, primary, pre));
166
+ // fusion consumes and returns the derivation STATE; these cases exercise the
167
+ // mechanism's own gates, so the state is the minimum one for them.
168
+ const out = dec(
169
+ (await fuseAttention(m, q, {
170
+ product: primary,
171
+ accounted: [],
172
+ remainder: [],
173
+ cost: 0,
174
+ }, pre)).product,
175
+ );
158
176
  assert.equal(
159
177
  out,
160
178
  "answer alpha" + dec(primary),
@@ -180,7 +198,16 @@ test("fuseAttention: 1 cluster, low breadth — neither measure saves it (the li
180
198
  }),
181
199
  guide,
182
200
  };
183
- const out = dec(await fuseAttention(m, q, primary, pre));
201
+ // fusion consumes and returns the derivation STATE; these cases exercise the
202
+ // mechanism's own gates, so the state is the minimum one for them.
203
+ const out = dec(
204
+ (await fuseAttention(m, q, {
205
+ product: primary,
206
+ accounted: [],
207
+ remainder: [],
208
+ cost: 0,
209
+ }, pre)).product,
210
+ );
184
211
  assert.equal(
185
212
  out,
186
213
  dec(primary),
@@ -60,7 +60,17 @@ test("reason(): a forward hop landing on bytes already present in the query is r
60
60
  // `reason()` reports the WHOLE extension (bytes + what it carried + how many
61
61
  // steps) so a caller can price it; these assertions measure the bytes, and
62
62
  // that is all this change touches — the law they pin is untouched.
63
- const out = (await reason(m, query, answer, new Set(), pre)).bytes;
63
+ // `reason()` now consumes and returns the derivation STATE; with no remainder
64
+ // the derivation is CLOSED, so the law admits any contained continuation —
65
+ // which is exactly what these two cases exercise. The assertions below are
66
+ // untouched.
67
+ const state = {
68
+ product: answer,
69
+ accounted: [],
70
+ remainder: [],
71
+ cost: 0,
72
+ };
73
+ const out = (await reason(m, query, state, new Set(), pre)).product;
64
74
  assert.equal(
65
75
  dec(out),
66
76
  "bridge context",
@@ -88,7 +98,17 @@ test("reason(): an ordinary forward hop onto genuinely new content is unaffected
88
98
  // `reason()` reports the WHOLE extension (bytes + what it carried + how many
89
99
  // steps) so a caller can price it; these assertions measure the bytes, and
90
100
  // that is all this change touches — the law they pin is untouched.
91
- const out = (await reason(m, query, answer, new Set(), pre)).bytes;
101
+ // `reason()` now consumes and returns the derivation STATE; with no remainder
102
+ // the derivation is CLOSED, so the law admits any contained continuation —
103
+ // which is exactly what these two cases exercise. The assertions below are
104
+ // untouched.
105
+ const state = {
106
+ product: answer,
107
+ accounted: [],
108
+ remainder: [],
109
+ cost: 0,
110
+ };
111
+ const out = (await reason(m, query, state, new Set(), pre)).product;
92
112
  assert.equal(
93
113
  dec(out),
94
114
  "a wholly new fact never mentioned in any query",
@@ -949,8 +949,11 @@ test("21. the price's second term has one definition, and it is the complement",
949
949
  // Since the value did NOT change, the lot is only pinned if something would
950
950
  // fail when the helper sums the wrong thing — so this test uses an input where
951
951
  // the two candidate readings DIFFER.
952
+ // PATH ONLY: the span algebra moved to the closure law's home
953
+ // (src/mind/derivation.ts) when the law was extracted; the assertions below
954
+ // are untouched and still pin the same contract.
952
955
  const { unexplainedSpans, unaccountedBytes } = await import(
953
- "../dist/src/mind/rationale.js"
956
+ "../dist/src/mind/derivation.js"
954
957
  );
955
958
  // Empty accounted ⇒ the whole query is unaccounted.
956
959
  assert.equal(unaccountedBytes(unexplainedSpans(10, [])), 10);