@e4779/pi-fabric 0.92.41-fork.6 → 0.96.4-fork.10

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 (300) hide show
  1. package/LAWS.bend +502 -0
  2. package/PROOF.bend +452 -0
  3. package/README.md +5 -1
  4. package/THIRD_PARTY_NOTICES.md +9 -0
  5. package/dist/agents/handoff.d.ts +2 -1
  6. package/dist/agents/handoff.d.ts.map +1 -1
  7. package/dist/agents/manager.d.ts +2 -0
  8. package/dist/agents/manager.d.ts.map +1 -1
  9. package/dist/agents.js +6 -5
  10. package/dist/agents.js.map +1 -1
  11. package/dist/chunks/{chunk-3TXOQ5MG.js → chunk-3CJETB4S.js} +828 -204
  12. package/dist/chunks/chunk-3CJETB4S.js.map +7 -0
  13. package/dist/chunks/{chunk-IUCVOZRX.js → chunk-3SIXBW6A.js} +2 -2
  14. package/dist/chunks/chunk-4E63LJDD.js +468 -0
  15. package/dist/chunks/chunk-4E63LJDD.js.map +7 -0
  16. package/dist/chunks/{chunk-AAHHYDTO.js → chunk-4NF3S3NM.js} +1 -1
  17. package/dist/chunks/{chunk-AAHHYDTO.js.map → chunk-4NF3S3NM.js.map} +2 -2
  18. package/dist/chunks/{chunk-2SWRVIYJ.js → chunk-754HA6KO.js} +2 -2
  19. package/dist/chunks/{chunk-K6DHXXF5.js → chunk-B2IVWASP.js} +2 -2
  20. package/dist/chunks/{chunk-ZDNGXLEC.js → chunk-B4HECUJI.js} +2 -2
  21. package/dist/chunks/{chunk-H6DDV6E2.js → chunk-CSJSHBAT.js} +5 -5
  22. package/dist/chunks/{chunk-MW5VI7IW.js → chunk-D4B4CCTA.js} +2 -2
  23. package/dist/chunks/{chunk-EDL4JDW7.js → chunk-EBWMC3OO.js} +2 -2
  24. package/dist/chunks/{chunk-4NUTVNS2.js → chunk-F72MAIQY.js} +31 -368
  25. package/dist/chunks/chunk-F72MAIQY.js.map +7 -0
  26. package/dist/chunks/{chunk-W3FRE4VI.js → chunk-FDIEQEXS.js} +2 -2
  27. package/dist/chunks/{chunk-7A6NVHB5.js → chunk-FJSHRHOR.js} +7 -4
  28. package/dist/chunks/chunk-FJSHRHOR.js.map +7 -0
  29. package/dist/chunks/{chunk-PSNXUZMY.js → chunk-G2F2RDZI.js} +5 -47
  30. package/dist/chunks/chunk-G2F2RDZI.js.map +7 -0
  31. package/dist/chunks/{chunk-3WIGAX56.js → chunk-JCV54SSP.js} +2 -2
  32. package/dist/chunks/chunk-KS44WKJJ.js +51 -0
  33. package/dist/chunks/chunk-KS44WKJJ.js.map +7 -0
  34. package/dist/chunks/{chunk-3H7SDWZI.js → chunk-LNLQ2LX3.js} +22 -1
  35. package/dist/chunks/chunk-LNLQ2LX3.js.map +7 -0
  36. package/dist/chunks/{chunk-G4LADAYY.js → chunk-OINADFEF.js} +8 -3
  37. package/dist/chunks/chunk-OINADFEF.js.map +7 -0
  38. package/dist/chunks/{chunk-UQ4LTUH4.js → chunk-OUAC6O5C.js} +36 -9
  39. package/dist/chunks/chunk-OUAC6O5C.js.map +7 -0
  40. package/dist/chunks/{chunk-MQG5QKGI.js → chunk-Q5BMTL6A.js} +217 -95
  41. package/dist/chunks/chunk-Q5BMTL6A.js.map +7 -0
  42. package/dist/chunks/{chunk-IK6PPFWG.js → chunk-QFKHAAZA.js} +11 -11
  43. package/dist/chunks/chunk-QFKHAAZA.js.map +7 -0
  44. package/dist/chunks/{chunk-RTXZHKMS.js → chunk-QNMQJNXE.js} +7 -3
  45. package/dist/chunks/chunk-QNMQJNXE.js.map +7 -0
  46. package/dist/chunks/{chunk-U5FYOMG5.js → chunk-UBPFGMDQ.js} +6 -2
  47. package/dist/chunks/chunk-UBPFGMDQ.js.map +7 -0
  48. package/dist/chunks/{chunk-FLKGJPCN.js → chunk-ULQFHZJE.js} +4 -1
  49. package/dist/chunks/chunk-ULQFHZJE.js.map +7 -0
  50. package/dist/chunks/{chunk-7VAZ4N43.js → chunk-V3PIO7QL.js} +2 -2
  51. package/dist/chunks/{chunk-MGDLRV2R.js → chunk-VQGO4P7C.js} +2 -2
  52. package/dist/chunks/{chunk-XT4346N7.js → chunk-WXSELMFV.js} +9 -3
  53. package/dist/chunks/chunk-WXSELMFV.js.map +7 -0
  54. package/dist/chunks/{chunk-D5WKZONW.js → chunk-X3IRR7CV.js} +2 -2
  55. package/dist/chunks/{chunk-IJL3QK3J.js → chunk-Y57UHPIK.js} +1 -1
  56. package/dist/chunks/{chunk-IJL3QK3J.js.map → chunk-Y57UHPIK.js.map} +1 -1
  57. package/dist/chunks/{chunk-RKRVOBVO.js → chunk-YC3QQDZ3.js} +2 -2
  58. package/dist/chunks/{chunk-Q4XJ4PYL.js → chunk-ZRI433JP.js} +299 -83
  59. package/dist/chunks/chunk-ZRI433JP.js.map +7 -0
  60. package/dist/chunks/{chunk-36B4AIRT.js → chunk-ZTXZ6JDO.js} +2 -2
  61. package/dist/commands/fabric.d.ts.map +1 -1
  62. package/dist/compaction/bounds.d.ts +4 -0
  63. package/dist/compaction/bounds.d.ts.map +1 -1
  64. package/dist/compaction/branch-summary.d.ts.map +1 -1
  65. package/dist/compaction/dialogue.d.ts +24 -0
  66. package/dist/compaction/dialogue.d.ts.map +1 -0
  67. package/dist/compaction/hook.d.ts +6 -2
  68. package/dist/compaction/hook.d.ts.map +1 -1
  69. package/dist/compaction/hook.js +6 -5
  70. package/dist/compaction/instructions.d.ts +1 -0
  71. package/dist/compaction/instructions.d.ts.map +1 -1
  72. package/dist/compaction/projections.d.ts +3 -3
  73. package/dist/compaction/projections.d.ts.map +1 -1
  74. package/dist/compaction/qa.d.ts.map +1 -1
  75. package/dist/compaction/render.d.ts +11 -0
  76. package/dist/compaction/render.d.ts.map +1 -1
  77. package/dist/components/configuration.js +2 -3
  78. package/dist/components/effect-policy.d.ts +2 -0
  79. package/dist/components/effect-policy.d.ts.map +1 -1
  80. package/dist/components/effect-scope.d.ts.map +1 -1
  81. package/dist/components/supervisor.d.ts +1 -1
  82. package/dist/components/supervisor.d.ts.map +1 -1
  83. package/dist/core/action-registry.d.ts +14 -2
  84. package/dist/core/action-registry.d.ts.map +1 -1
  85. package/dist/core/action-registry.js +7 -5
  86. package/dist/core/provider-bindings.d.ts +8 -2
  87. package/dist/core/provider-bindings.d.ts.map +1 -1
  88. package/dist/core/provider-operations.d.ts +28 -0
  89. package/dist/core/provider-operations.d.ts.map +1 -0
  90. package/dist/core/provider-operations.js +201 -0
  91. package/dist/core/provider-operations.js.map +7 -0
  92. package/dist/core/shell-inbox.d.ts +13 -0
  93. package/dist/core/shell-inbox.d.ts.map +1 -0
  94. package/dist/core/shell-jobs.d.ts +51 -7
  95. package/dist/core/shell-jobs.d.ts.map +1 -1
  96. package/dist/core/shell-limits.d.ts +3 -0
  97. package/dist/core/shell-limits.d.ts.map +1 -0
  98. package/dist/core/shell-monitor.d.ts +51 -0
  99. package/dist/core/shell-monitor.d.ts.map +1 -0
  100. package/dist/entropy/index.js +8 -7
  101. package/dist/entropy/normal-form.d.ts.map +1 -1
  102. package/dist/execution-service.d.ts +1 -1
  103. package/dist/execution-service.d.ts.map +1 -1
  104. package/dist/fabric-runtime-state.d.ts +1 -1
  105. package/dist/fabric-runtime-state.d.ts.map +1 -1
  106. package/dist/fabric-runtime-state.js +1124 -325
  107. package/dist/fabric-runtime-state.js.map +4 -4
  108. package/dist/index.js +155 -44
  109. package/dist/index.js.map +3 -3
  110. package/dist/jev/observation.js +5 -3
  111. package/dist/jev.d.ts +0 -1
  112. package/dist/jev.d.ts.map +1 -1
  113. package/dist/jev.js +9 -13
  114. package/dist/memory/digest.d.ts.map +1 -1
  115. package/dist/memory/digest.js +2 -1
  116. package/dist/memory/discovery.js +6 -5
  117. package/dist/memory/expand-service.d.ts.map +1 -1
  118. package/dist/memory/file-worker.js +9 -8
  119. package/dist/memory/file-worker.js.map +1 -1
  120. package/dist/memory/index.d.ts.map +1 -1
  121. package/dist/memory/normalize.d.ts.map +1 -1
  122. package/dist/memory/normalize.js +5 -4
  123. package/dist/memory/search.js +7 -6
  124. package/dist/memory/worker-provider.js +10 -9
  125. package/dist/memory.js +9 -8
  126. package/dist/memory.js.map +1 -1
  127. package/dist/mesh/store.d.ts.map +1 -1
  128. package/dist/prewalk/handoff.d.ts +1 -1
  129. package/dist/prewalk/handoff.d.ts.map +1 -1
  130. package/dist/protocol.d.ts +2 -0
  131. package/dist/protocol.d.ts.map +1 -1
  132. package/dist/protocol.js +1 -1
  133. package/dist/providers/jev-provider.d.ts +1 -1
  134. package/dist/providers/jev-provider.d.ts.map +1 -1
  135. package/dist/providers/jev-provider.js +9 -7
  136. package/dist/providers/memory-provider.js +9 -8
  137. package/dist/providers/pi-tools-provider.d.ts.map +1 -1
  138. package/dist/providers/tasks-provider.d.ts +12 -0
  139. package/dist/providers/tasks-provider.d.ts.map +1 -0
  140. package/dist/residency/host.js +10 -9
  141. package/dist/residency/pi-entry.js +10 -9
  142. package/dist/residency/pi-entry.js.map +1 -1
  143. package/dist/runtime/core-override-guest-types.js +2 -2
  144. package/dist/runtime/guest-types.d.ts +1 -1
  145. package/dist/runtime/guest-types.d.ts.map +1 -1
  146. package/dist/runtime/guest-types.js +1 -1
  147. package/dist/runtime/monty-runtime.js +1 -2
  148. package/dist/runtime/monty-runtime.js.map +1 -1
  149. package/dist/runtime/typescript-kernel.js +2 -2
  150. package/dist/runtime-state-builtins.d.ts +1 -1
  151. package/dist/runtime-state-builtins.d.ts.map +1 -1
  152. package/dist/schema/controller.d.ts.map +1 -1
  153. package/dist/state/store.d.ts.map +1 -1
  154. package/dist/ui/controller.d.ts +1 -0
  155. package/dist/ui/controller.d.ts.map +1 -1
  156. package/dist/ui/conversation-targets.js +2 -2
  157. package/dist/ui/conversation.js +7 -7
  158. package/dist/ui/dashboard.js +9 -9
  159. package/dist/ui/highlight.d.ts.map +1 -1
  160. package/dist/ui/languages/bend.d.ts +4 -0
  161. package/dist/ui/languages/bend.d.ts.map +1 -0
  162. package/dist/ui/languages/bend.js +73 -0
  163. package/dist/ui/languages/bend.js.map +7 -0
  164. package/dist/ui/settings.js +1 -2
  165. package/dist/ui/settings.js.map +1 -1
  166. package/dist/ui/shell-hang-keys.d.ts.map +1 -1
  167. package/dist/ui/shell-tasks.d.ts +22 -0
  168. package/dist/ui/shell-tasks.d.ts.map +1 -0
  169. package/dist/ui/shell-tasks.js +161 -0
  170. package/dist/ui/shell-tasks.js.map +7 -0
  171. package/dist/ui/shiki-catalog.d.ts +2 -1
  172. package/dist/ui/shiki-catalog.d.ts.map +1 -1
  173. package/dist/ui/snapshot.d.ts.map +1 -1
  174. package/dist/ui/types.d.ts +1 -0
  175. package/dist/ui/types.d.ts.map +1 -1
  176. package/dist/ui/widget.d.ts.map +1 -1
  177. package/dist/verified/authority.d.ts +17 -0
  178. package/dist/verified/authority.d.ts.map +1 -0
  179. package/dist/verified/generated/authority-kernel.d.ts +10 -0
  180. package/dist/verified/generated/authority-kernel.js +116 -0
  181. package/dist/verified/generated/kernel.d.ts +31 -0
  182. package/dist/verified/generated/kernel.js +351 -0
  183. package/dist/verified/generated/lifecycle-kernel.d.ts +7 -0
  184. package/dist/verified/generated/lifecycle-kernel.js +155 -0
  185. package/dist/verified/generated/manifest.json +54 -0
  186. package/dist/verified/generated/provider-kernel.d.ts +9 -0
  187. package/dist/verified/generated/provider-kernel.js +80 -0
  188. package/dist/verified/generated/storage-kernel.d.ts +11 -0
  189. package/dist/verified/generated/storage-kernel.js +98 -0
  190. package/dist/verified/memory.d.ts +11 -0
  191. package/dist/verified/memory.d.ts.map +1 -0
  192. package/dist/verified/nat.d.ts +2 -0
  193. package/dist/verified/nat.d.ts.map +1 -0
  194. package/dist/verified/policy.d.ts +37 -0
  195. package/dist/verified/policy.d.ts.map +1 -0
  196. package/dist/verified/resources.d.ts +14 -0
  197. package/dist/verified/resources.d.ts.map +1 -0
  198. package/dist/verified/storage.d.ts +32 -0
  199. package/dist/verified/storage.d.ts.map +1 -0
  200. package/dist/worker/event-projection.d.ts +6 -0
  201. package/dist/worker/event-projection.d.ts.map +1 -0
  202. package/dist/worker/event-projection.js +99 -0
  203. package/dist/worker/event-projection.js.map +7 -0
  204. package/dist/worker/recovery-watchdog.d.ts +12 -0
  205. package/dist/worker/recovery-watchdog.d.ts.map +1 -0
  206. package/dist/worker/recovery-watchdog.js +41 -0
  207. package/dist/worker/recovery-watchdog.js.map +7 -0
  208. package/dist/worker.js +80 -22
  209. package/dist/worker.js.map +2 -2
  210. package/docs/agents.md +26 -14
  211. package/docs/architecture.md +1 -1
  212. package/docs/background-tasks.md +140 -0
  213. package/docs/compaction.md +91 -28
  214. package/docs/components.md +5 -1
  215. package/docs/configuration.md +6 -6
  216. package/docs/foreman.md +4 -4
  217. package/docs/harnesses.md +95 -0
  218. package/docs/interface.md +7 -0
  219. package/docs/jev.md +59 -52
  220. package/docs/kernels.md +2 -2
  221. package/docs/licenses/bend-apache-2.0.txt +202 -0
  222. package/docs/memory-recall.md +1 -1
  223. package/docs/programmatic-compaction.md +13 -2
  224. package/docs/provider-capabilities.md +197 -0
  225. package/docs/shell-middleware.md +3 -3
  226. package/docs/skills.md +1 -1
  227. package/docs/verified-kernels.md +278 -0
  228. package/package.json +14 -4
  229. package/proofs/abi.json +308 -0
  230. package/proofs/authority-abi.json +7 -0
  231. package/proofs/authority-kernel.bend +23 -0
  232. package/proofs/authority-proof.bend +74 -0
  233. package/proofs/authority-spec.bend +30 -0
  234. package/proofs/authority-state.bend +43 -0
  235. package/proofs/authority-types.d.ts +3 -0
  236. package/proofs/kernel.bend +139 -0
  237. package/proofs/lifecycle-abi.json +3 -0
  238. package/proofs/lifecycle-kernel.bend +11 -0
  239. package/proofs/lifecycle-proof.bend +249 -0
  240. package/proofs/lifecycle-spec.bend +261 -0
  241. package/proofs/lifecycle-types.d.ts +4 -0
  242. package/proofs/lifecycle.bend +119 -0
  243. package/proofs/provider-abi.json +4 -0
  244. package/proofs/provider-kernel.bend +14 -0
  245. package/proofs/provider-plans.bend +28 -0
  246. package/proofs/provider-spec.bend +14 -0
  247. package/proofs/provider-types.d.ts +5 -0
  248. package/proofs/resource-proof.bend +633 -0
  249. package/proofs/resource-spec.bend +133 -0
  250. package/proofs/resources.bend +160 -0
  251. package/proofs/state-kernel.bend +17 -0
  252. package/proofs/state-plans.bend +40 -0
  253. package/proofs/state-proof.bend +42 -0
  254. package/proofs/state-spec.bend +26 -0
  255. package/proofs/storage-abi.json +3 -0
  256. package/proofs/storage-kernel.bend +11 -0
  257. package/proofs/storage-plans.bend +100 -0
  258. package/proofs/storage-proof.bend +176 -0
  259. package/proofs/storage-spec.bend +70 -0
  260. package/proofs/storage-types.d.ts +8 -0
  261. package/proofs/types.d.ts +7 -0
  262. package/scripts/test-verified-kernels.mjs +107 -0
  263. package/scripts/verified-kernels.mjs +136 -0
  264. package/skillsets/python/fabric-jev/SKILL.md +13 -9
  265. package/skillsets/typescript/fabric-exec/SKILL.md +4 -2
  266. package/skillsets/typescript/fabric-jev/SKILL.md +13 -9
  267. package/dist/chunks/chunk-3H7SDWZI.js.map +0 -7
  268. package/dist/chunks/chunk-3TXOQ5MG.js.map +0 -7
  269. package/dist/chunks/chunk-4NUTVNS2.js.map +0 -7
  270. package/dist/chunks/chunk-77PDIBK2.js +0 -129
  271. package/dist/chunks/chunk-77PDIBK2.js.map +0 -7
  272. package/dist/chunks/chunk-7A6NVHB5.js.map +0 -7
  273. package/dist/chunks/chunk-FLKGJPCN.js.map +0 -7
  274. package/dist/chunks/chunk-G4LADAYY.js.map +0 -7
  275. package/dist/chunks/chunk-IK6PPFWG.js.map +0 -7
  276. package/dist/chunks/chunk-MQG5QKGI.js.map +0 -7
  277. package/dist/chunks/chunk-PSNXUZMY.js.map +0 -7
  278. package/dist/chunks/chunk-Q4XJ4PYL.js.map +0 -7
  279. package/dist/chunks/chunk-RTXZHKMS.js.map +0 -7
  280. package/dist/chunks/chunk-U5FYOMG5.js.map +0 -7
  281. package/dist/chunks/chunk-UQ4LTUH4.js.map +0 -7
  282. package/dist/chunks/chunk-XT4346N7.js.map +0 -7
  283. package/dist/jev/browser.d.ts +0 -37
  284. package/dist/jev/browser.d.ts.map +0 -1
  285. package/dist/jev/browser.js +0 -13
  286. package/dist/jev/browser.js.map +0 -7
  287. /package/dist/chunks/{chunk-IUCVOZRX.js.map → chunk-3SIXBW6A.js.map} +0 -0
  288. /package/dist/chunks/{chunk-2SWRVIYJ.js.map → chunk-754HA6KO.js.map} +0 -0
  289. /package/dist/chunks/{chunk-K6DHXXF5.js.map → chunk-B2IVWASP.js.map} +0 -0
  290. /package/dist/chunks/{chunk-ZDNGXLEC.js.map → chunk-B4HECUJI.js.map} +0 -0
  291. /package/dist/chunks/{chunk-H6DDV6E2.js.map → chunk-CSJSHBAT.js.map} +0 -0
  292. /package/dist/chunks/{chunk-MW5VI7IW.js.map → chunk-D4B4CCTA.js.map} +0 -0
  293. /package/dist/chunks/{chunk-EDL4JDW7.js.map → chunk-EBWMC3OO.js.map} +0 -0
  294. /package/dist/chunks/{chunk-W3FRE4VI.js.map → chunk-FDIEQEXS.js.map} +0 -0
  295. /package/dist/chunks/{chunk-3WIGAX56.js.map → chunk-JCV54SSP.js.map} +0 -0
  296. /package/dist/chunks/{chunk-7VAZ4N43.js.map → chunk-V3PIO7QL.js.map} +0 -0
  297. /package/dist/chunks/{chunk-MGDLRV2R.js.map → chunk-VQGO4P7C.js.map} +0 -0
  298. /package/dist/chunks/{chunk-D5WKZONW.js.map → chunk-X3IRR7CV.js.map} +0 -0
  299. /package/dist/chunks/{chunk-RKRVOBVO.js.map → chunk-YC3QQDZ3.js.map} +0 -0
  300. /package/dist/chunks/{chunk-36B4AIRT.js.map → chunk-ZTXZ6JDO.js.map} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  MAX_NORMAL_FORM_PLANS,
7
7
  isNormalFormPlan,
8
8
  provesNormalFormPlan
9
- } from "./chunk-G4LADAYY.js";
9
+ } from "./chunk-OINADFEF.js";
10
10
  import {
11
11
  stableJsonHash
12
12
  } from "./chunk-3YZUQESG.js";
@@ -641,4 +641,4 @@ export {
641
641
  saveCompiledSurface,
642
642
  saveCompiledSurfaceAsync
643
643
  };
644
- //# sourceMappingURL=chunk-3WIGAX56.js.map
644
+ //# sourceMappingURL=chunk-JCV54SSP.js.map
@@ -0,0 +1,51 @@
1
+ import {
2
+ applyNormalFormPlan,
3
+ deriveNormalFormPlan
4
+ } from "./chunk-OINADFEF.js";
5
+
6
+ // src/entropy/active.ts
7
+ var active;
8
+ var enabled = false;
9
+ var setActiveCompiledSurface = (file, enable = file !== void 0) => {
10
+ active = file;
11
+ enabled = enable;
12
+ };
13
+ var clearActiveCompiledSurface = () => {
14
+ active = void 0;
15
+ enabled = false;
16
+ };
17
+ var effectiveInputSchema = (_ref, liveSchema) => liveSchema;
18
+ var activeQuarantinedRefNames = () => /* @__PURE__ */ new Set();
19
+ var isActiveQuarantine = (_provider, _actionName, _liveSchema) => false;
20
+ var normalizeActiveArguments = (ref, schema, args) => {
21
+ if (!enabled) return { args };
22
+ const stored = active?.version === 2 ? active.normalizations?.find((plan) => plan.ref === ref) : void 0;
23
+ return applyNormalFormPlan(ref, schema, args, stored ?? deriveNormalFormPlan(ref, schema));
24
+ };
25
+
26
+ // src/repairs/active.ts
27
+ var active2;
28
+ var setActiveRepairCompiler = (compiler) => {
29
+ active2 = compiler;
30
+ };
31
+ var clearActiveRepairCompiler = (compiler) => {
32
+ if (compiler && active2 === compiler) active2 = void 0;
33
+ };
34
+ var getActiveRepairCompiler = () => active2;
35
+ var applyActiveArgRepairs = (ref, args, schema) => active2?.applyArgs(ref, args, schema) ?? args;
36
+ var applyActiveActionName = (provider, actionName, declared) => active2?.applyActionName(provider, actionName, declared) ?? actionName;
37
+
38
+ export {
39
+ setActiveCompiledSurface,
40
+ clearActiveCompiledSurface,
41
+ effectiveInputSchema,
42
+ activeQuarantinedRefNames,
43
+ isActiveQuarantine,
44
+ normalizeActiveArguments,
45
+ setActiveRepairCompiler,
46
+ clearActiveRepairCompiler,
47
+ getActiveRepairCompiler,
48
+ applyActiveArgRepairs,
49
+ applyActiveActionName
50
+ };
51
+ //# sourceMappingURL=chunk-KS44WKJJ.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/entropy/active.ts", "../../src/repairs/active.ts"],
4
+ "sourcesContent": ["// Runtime-only compatibility policy. No schema or discovery entry changes.\nimport type { CompiledSurfaceFile } from \"./compiled-surface.js\";\nimport { applyNormalFormPlan, deriveNormalFormPlan, type NormalFormResult } from \"./normal-form.js\";\n\nlet active: CompiledSurfaceFile | undefined;\nlet enabled = false;\nexport const setActiveCompiledSurface = (file: CompiledSurfaceFile | undefined, enable = file !== undefined): void => {\n active = file;\n enabled = enable;\n};\nexport const clearActiveCompiledSurface = (): void => { active = undefined; enabled = false; };\nexport const effectiveInputSchema = (_ref: string, liveSchema: unknown): unknown => liveSchema;\nexport const activeQuarantinedRefNames = (): ReadonlySet<string> => new Set();\nexport const isActiveQuarantine = (_provider: string, _actionName: string, _liveSchema: unknown): boolean => false;\n\nexport const normalizeActiveArguments = (ref: string, schema: unknown, args: Record<string, unknown>): NormalFormResult => {\n if (!enabled) return { args };\n const stored = active?.version === 2 ? active.normalizations?.find((plan) => plan.ref === ref) : undefined;\n // New actions gain the same statically proven rules on their first call,\n // without waiting for session evidence or a background persistence tick.\n // A stored stale/forged plan is refused, never silently substituted.\n return applyNormalFormPlan(ref, schema, args, stored ?? deriveNormalFormPlan(ref, schema));\n};\n", "import type { RepairCompiler } from \"./compiler.js\";\n\nlet active: RepairCompiler | undefined;\n\nexport const setActiveRepairCompiler = (compiler: RepairCompiler | undefined): void => {\n active = compiler;\n};\n\nexport const clearActiveRepairCompiler = (compiler: RepairCompiler | undefined): void => {\n if (compiler && active === compiler) active = undefined;\n};\n\nexport const getActiveRepairCompiler = (): RepairCompiler | undefined => active;\n\nexport const applyActiveArgRepairs = (\n ref: string,\n args: Record<string, unknown>,\n schema: Record<string, unknown>,\n): Record<string, unknown> => active?.applyArgs(ref, args, schema) ?? args;\n\nexport const applyActiveActionName = (\n provider: string,\n actionName: string,\n declared: readonly string[],\n): string => active?.applyActionName(provider, actionName, declared) ?? actionName;\n"],
5
+ "mappings": ";;;;;;AAIA,IAAI;AACJ,IAAI,UAAU;AACP,IAAM,2BAA2B,CAAC,MAAuC,SAAS,SAAS,WAAoB;AACpH,WAAS;AACT,YAAU;AACZ;AACO,IAAM,6BAA6B,MAAY;AAAE,WAAS;AAAW,YAAU;AAAO;AACtF,IAAM,uBAAuB,CAAC,MAAc,eAAiC;AAC7E,IAAM,4BAA4B,MAA2B,oBAAI,IAAI;AACrE,IAAM,qBAAqB,CAAC,WAAmB,aAAqB,gBAAkC;AAEtG,IAAM,2BAA2B,CAAC,KAAa,QAAiB,SAAoD;AACzH,MAAI,CAAC,QAAS,QAAO,EAAE,KAAK;AAC5B,QAAM,SAAS,QAAQ,YAAY,IAAI,OAAO,gBAAgB,KAAK,CAAC,SAAS,KAAK,QAAQ,GAAG,IAAI;AAIjG,SAAO,oBAAoB,KAAK,QAAQ,MAAM,UAAU,qBAAqB,KAAK,MAAM,CAAC;AAC3F;;;ACpBA,IAAIA;AAEG,IAAM,0BAA0B,CAAC,aAA+C;AACrF,EAAAA,UAAS;AACX;AAEO,IAAM,4BAA4B,CAAC,aAA+C;AACvF,MAAI,YAAYA,YAAW,SAAU,CAAAA,UAAS;AAChD;AAEO,IAAM,0BAA0B,MAAkCA;AAElE,IAAM,wBAAwB,CACnC,KACA,MACA,WAC4BA,SAAQ,UAAU,KAAK,MAAM,MAAM,KAAK;AAE/D,IAAM,wBAAwB,CACnC,UACA,YACA,aACWA,SAAQ,gBAAgB,UAAU,YAAY,QAAQ,KAAK;",
6
+ "names": ["active"]
7
+ }
@@ -1,3 +1,7 @@
1
+ import {
2
+ acceptSampleAccounting
3
+ } from "./chunk-4E63LJDD.js";
4
+
1
5
  // src/compaction/bounds.ts
2
6
  var MAX_SUMMARY_BYTES = 32 * 1024;
3
7
  var MAX_REQUEST_SOURCE_BYTES = 8 * 1024;
@@ -19,6 +23,17 @@ var clipUtf8 = (text, maxBytes, suffix = "\u2026") => {
19
23
  }
20
24
  return `${output}${suffix}`;
21
25
  };
26
+ var boundedExcerpt = (text, maxBytes) => {
27
+ const sourceBytes = utf8Bytes(text);
28
+ if (sourceBytes <= maxBytes) return { text, omittedBytes: 0 };
29
+ const prefix = clipUtf8(text, Math.max(0, maxBytes - 64), "");
30
+ const omittedBytes = sourceBytes - utf8Bytes(prefix);
31
+ return {
32
+ text: clipUtf8(`${prefix}
33
+ [omitted ${omittedBytes} UTF-8 bytes]`, maxBytes, ""),
34
+ omittedBytes
35
+ };
36
+ };
22
37
  var canonicalizeText = (input, maxBytes = MAX_REQUEST_SOURCE_BYTES) => {
23
38
  const canonical = input.trim().split(/\s+/u).filter(Boolean).join(" ");
24
39
  const sourceBytes = utf8Bytes(canonical);
@@ -34,9 +49,11 @@ var sampleAddressedFrom = (source, maxValues) => {
34
49
  const earliest = [];
35
50
  const latest = [];
36
51
  let omitted = 0;
52
+ let total = 0;
37
53
  let omittedFirstEntryId;
38
54
  let omittedLastEntryId;
39
55
  for (const value of source) {
56
+ total++;
40
57
  if (earliest.length < earliestLimit) {
41
58
  earliest.push(value);
42
59
  continue;
@@ -48,6 +65,9 @@ var sampleAddressedFrom = (source, maxValues) => {
48
65
  omittedFirstEntryId ??= displaced.entryId;
49
66
  omittedLastEntryId = displaced.entryId;
50
67
  }
68
+ if (!acceptSampleAccounting(total, earliest.length + latest.length, omitted, maxValues)) {
69
+ throw new Error("Addressed sample failed conservation/bound verification");
70
+ }
51
71
  return {
52
72
  values: [...earliest, ...latest],
53
73
  omitted,
@@ -454,6 +474,7 @@ export {
454
474
  MAX_SUMMARY_BYTES,
455
475
  utf8Bytes,
456
476
  clipUtf8,
477
+ boundedExcerpt,
457
478
  sampleAddressedFrom,
458
479
  sampleAddressed,
459
480
  omissionLine,
@@ -464,4 +485,4 @@ export {
464
485
  encodeCompactionRequest,
465
486
  decodeCompactionInstructions
466
487
  };
467
- //# sourceMappingURL=chunk-3H7SDWZI.js.map
488
+ //# sourceMappingURL=chunk-LNLQ2LX3.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/compaction/bounds.ts", "../../src/compaction/instructions.ts"],
4
+ "sourcesContent": ["import { acceptSampleAccounting } from \"../verified/policy.js\";\n\nexport const MAX_SUMMARY_BYTES = 32 * 1024;\nconst MAX_REQUEST_SOURCE_BYTES = 8 * 1024;\n\nconst encoder = new TextEncoder();\n\nexport const utf8Bytes = (text: string): number => encoder.encode(text).byteLength;\n\nexport const clipUtf8 = (text: string, maxBytes: number, suffix = \"\u2026\"): string => {\n if (maxBytes <= 0) return \"\";\n if (utf8Bytes(text) <= maxBytes) return text;\n const suffixBytes = utf8Bytes(suffix);\n if (suffixBytes >= maxBytes) return \"\";\n let output = \"\";\n let used = 0;\n const available = maxBytes - suffixBytes;\n for (const character of text) {\n const bytes = utf8Bytes(character);\n if (used + bytes > available) break;\n output += character;\n used += bytes;\n }\n return `${output}${suffix}`;\n};\n\n// Preserve complete multiline text when it fits, and make byte loss explicit.\nexport const boundedExcerpt = (text: string, maxBytes: number): { text: string; omittedBytes: number } => {\n const sourceBytes = utf8Bytes(text);\n if (sourceBytes <= maxBytes) return { text, omittedBytes: 0 };\n const prefix = clipUtf8(text, Math.max(0, maxBytes - 64), \"\");\n const omittedBytes = sourceBytes - utf8Bytes(prefix);\n return {\n text: clipUtf8(`${prefix}\\n[omitted ${omittedBytes} UTF-8 bytes]`, maxBytes, \"\"),\n omittedBytes,\n };\n};\n\nexport interface CanonicalText {\n text: string;\n truncated: boolean;\n sourceBytes: number;\n}\n\nexport const canonicalizeText = (input: string, maxBytes = MAX_REQUEST_SOURCE_BYTES): CanonicalText => {\n const canonical = input.trim().split(/\\s+/u).filter(Boolean).join(\" \");\n const sourceBytes = utf8Bytes(canonical);\n return {\n text: clipUtf8(canonical, maxBytes),\n truncated: sourceBytes > maxBytes,\n sourceBytes,\n };\n};\n\nexport interface AddressedValue {\n entryId: string;\n}\n\nexport interface AddressedSample<T extends AddressedValue> {\n values: T[];\n omitted: number;\n omittedFirstEntryId?: string;\n omittedLastEntryId?: string;\n splitIndex: number;\n}\n\nexport const sampleAddressedFrom = <T extends AddressedValue>(\n source: Iterable<T>,\n maxValues: number,\n): AddressedSample<T> => {\n const earliestLimit = Math.ceil(maxValues / 2);\n const latestLimit = Math.floor(maxValues / 2);\n const earliest: T[] = [];\n const latest: T[] = [];\n let omitted = 0;\n let total = 0;\n let omittedFirstEntryId: string | undefined;\n let omittedLastEntryId: string | undefined;\n\n for (const value of source) {\n total++;\n if (earliest.length < earliestLimit) {\n earliest.push(value);\n continue;\n }\n latest.push(value);\n if (latest.length <= latestLimit) continue;\n const displaced = latest.shift()!;\n omitted += 1;\n omittedFirstEntryId ??= displaced.entryId;\n omittedLastEntryId = displaced.entryId;\n }\n\n if (!acceptSampleAccounting(total, earliest.length + latest.length, omitted, maxValues)) {\n throw new Error(\"Addressed sample failed conservation/bound verification\");\n }\n return {\n values: [...earliest, ...latest],\n omitted,\n ...(omittedFirstEntryId !== undefined ? { omittedFirstEntryId } : {}),\n ...(omittedLastEntryId !== undefined ? { omittedLastEntryId } : {}),\n splitIndex: earliest.length,\n };\n};\n\nexport const sampleAddressed = <T extends AddressedValue>(\n values: readonly T[],\n maxValues: number,\n): AddressedSample<T> => sampleAddressedFrom(values, maxValues);\n\nexport const omissionLine = (\n count: number,\n firstEntryId: string | undefined,\n lastEntryId: string | undefined,\n noun: string,\n): string => {\n const range = firstEntryId || lastEntryId\n ? `${firstEntryId || \"(start)\"} \u2192 ${lastEntryId || \"(end)\"}`\n : \"(unknown range)\";\n return `\u2026 omitted ${count} ${noun}; source entries ${range}`;\n};\n", "import { canonicalizeText, utf8Bytes } from \"./bounds.js\";\n\nexport const FABRIC_COMPACTION_REQUEST_PREFIX = \"__pi_fabric_compact_request_v1__:\";\nexport const MAX_COMPACTION_INSTRUCTIONS_CHARS = 8 * 1024;\nconst MAX_COMPACTION_INSTRUCTIONS_BYTES = 8 * 1024;\nexport const MAX_PRESERVE_ITEMS = 16;\nexport const MAX_PRESERVE_ITEM_CHARS = 2 * 1024;\nconst MAX_PRESERVE_ITEM_BYTES = 2 * 1024;\nexport const MAX_TYPED_COMPACTION_SOURCE_BYTES = 16 * 1024;\n\nexport interface TypedCompactionRequest {\n version: 1;\n instructions?: string;\n preserve?: string[];\n}\n\nexport interface CompactionInstructionPolicy {\n mode: \"none\" | \"plain\" | \"typed-v1\";\n canonicalized: boolean;\n sourceBytes: number;\n truncated: boolean;\n preserveCount: number;\n omittedPreserveCount: number;\n renderedOmittedBytes?: number;\n}\n\ntype CompactionInstructionErrorCode =\n | \"encoded-source-too-large\"\n | \"malformed-json\"\n | \"duplicate-field\"\n | \"invalid-unicode\"\n | \"structure-too-complex\"\n | \"invalid-object\"\n | \"unknown-field\"\n | \"unsupported-version\"\n | \"invalid-type\"\n | \"instructions-too-large\"\n | \"preserve-too-many\"\n | \"preserve-item-too-large\";\n\nexport interface CompactionInstructionDecodeError {\n code: CompactionInstructionErrorCode;\n message: string;\n sourceBytes: number;\n}\n\nexport type DecodedCompactionInstructions =\n | {\n ok: true;\n requestLines: string[];\n policy: CompactionInstructionPolicy;\n }\n | {\n ok: false;\n requestLines: [];\n error: CompactionInstructionDecodeError;\n };\n\nconst rejection = (\n code: CompactionInstructionErrorCode,\n message: string,\n sourceBytes: number,\n): DecodedCompactionInstructions => ({\n ok: false,\n requestLines: [],\n error: { code, message, sourceBytes },\n});\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === \"object\" && !Array.isArray(value);\n\nconst hasPairedSurrogates = (value: string): boolean => {\n for (let index = 0; index < value.length; index++) {\n const unit = value.charCodeAt(index);\n if (unit >= 0xd800 && unit <= 0xdbff) {\n const next = value.charCodeAt(index + 1);\n if (!(next >= 0xdc00 && next <= 0xdfff)) return false;\n index += 1;\n } else if (unit >= 0xdc00 && unit <= 0xdfff) {\n return false;\n }\n }\n return true;\n};\n\nexport const compactionRequestBoundsError = (\n request: Omit<TypedCompactionRequest, \"version\">,\n): Omit<CompactionInstructionDecodeError, \"sourceBytes\"> | undefined => {\n if (request.instructions !== undefined) {\n if (!hasPairedSurrogates(request.instructions)) {\n return {\n code: \"invalid-unicode\",\n message: \"typed compaction instructions contain an unpaired UTF-16 surrogate\",\n };\n }\n if (request.instructions.length > MAX_COMPACTION_INSTRUCTIONS_CHARS\n || utf8Bytes(request.instructions) > MAX_COMPACTION_INSTRUCTIONS_BYTES) {\n return {\n code: \"instructions-too-large\",\n message: `typed compaction instructions exceed ${MAX_COMPACTION_INSTRUCTIONS_CHARS} characters or ${MAX_COMPACTION_INSTRUCTIONS_BYTES} UTF-8 bytes`,\n };\n }\n }\n if (request.preserve !== undefined) {\n if (request.preserve.length > MAX_PRESERVE_ITEMS) {\n return {\n code: \"preserve-too-many\",\n message: `typed compaction preserve exceeds ${MAX_PRESERVE_ITEMS} items`,\n };\n }\n for (const item of request.preserve) {\n if (!hasPairedSurrogates(item)) {\n return {\n code: \"invalid-unicode\",\n message: \"typed compaction preserve item contains an unpaired UTF-16 surrogate\",\n };\n }\n if (item.length > MAX_PRESERVE_ITEM_CHARS || utf8Bytes(item) > MAX_PRESERVE_ITEM_BYTES) {\n return {\n code: \"preserve-item-too-large\",\n message: `typed compaction preserve item exceeds ${MAX_PRESERVE_ITEM_CHARS} characters or ${MAX_PRESERVE_ITEM_BYTES} UTF-8 bytes`,\n };\n }\n }\n }\n return undefined;\n};\n\nexport const encodeCompactionRequest = (request: Omit<TypedCompactionRequest, \"version\">): string => {\n const boundsError = compactionRequestBoundsError(request);\n if (boundsError) throw new Error(boundsError.message);\n const payload: TypedCompactionRequest = {\n version: 1,\n ...(request.instructions !== undefined ? { instructions: request.instructions } : {}),\n ...(request.preserve !== undefined ? { preserve: request.preserve } : {}),\n };\n const encoded = `${FABRIC_COMPACTION_REQUEST_PREFIX}${JSON.stringify(payload)}`;\n if (utf8Bytes(encoded) > MAX_TYPED_COMPACTION_SOURCE_BYTES) {\n throw new Error(`typed compaction request exceeds ${MAX_TYPED_COMPACTION_SOURCE_BYTES} encoded UTF-8 bytes`);\n }\n return encoded;\n};\n\nconst plainInstructions = (source: string): DecodedCompactionInstructions => {\n const canonical = canonicalizeText(source);\n return {\n ok: true,\n requestLines: canonical.text ? [canonical.text] : [],\n policy: {\n mode: \"plain\",\n canonicalized: canonical.text !== source,\n sourceBytes: canonical.sourceBytes,\n truncated: canonical.truncated,\n preserveCount: 0,\n omittedPreserveCount: 0,\n },\n };\n};\n\nclass StrictJsonError extends Error {\n constructor(\n readonly code: \"malformed-json\" | \"duplicate-field\" | \"invalid-unicode\" | \"structure-too-complex\",\n message: string,\n ) {\n super(message);\n }\n}\n\nconst MAX_TYPED_JSON_DEPTH = 32;\nconst MAX_TYPED_JSON_NODES = 4096;\n\nclass StrictJsonParser {\n private index = 0;\n private nodes = 0;\n\n constructor(private readonly source: string) {}\n\n parse(): unknown {\n this.skipWhitespace();\n const value = this.parseValue(0);\n this.skipWhitespace();\n if (this.index !== this.source.length) this.malformed();\n return value;\n }\n\n private parseValue(depth: number): unknown {\n if (depth > MAX_TYPED_JSON_DEPTH) {\n throw new StrictJsonError(\"structure-too-complex\", \"typed compaction JSON exceeds the structural depth limit\");\n }\n this.nodes += 1;\n if (this.nodes > MAX_TYPED_JSON_NODES) {\n throw new StrictJsonError(\"structure-too-complex\", \"typed compaction JSON exceeds the structural node limit\");\n }\n const character = this.source[this.index];\n if (character === \"{\") return this.parseObject(depth + 1);\n if (character === \"[\") return this.parseArray(depth + 1);\n if (character === \"\\\"\") return this.parseString();\n if (character === \"t\") return this.parseLiteral(\"true\", true);\n if (character === \"f\") return this.parseLiteral(\"false\", false);\n if (character === \"n\") return this.parseLiteral(\"null\", null);\n if (character === \"-\" || (character !== undefined && character >= \"0\" && character <= \"9\")) {\n return this.parseNumber();\n }\n return this.malformed();\n }\n\n private parseObject(depth: number): Record<string, unknown> {\n this.index += 1;\n this.skipWhitespace();\n const output = Object.create(null) as Record<string, unknown>;\n const keys = new Set<string>();\n if (this.source[this.index] === \"}\") {\n this.index += 1;\n return output;\n }\n while (this.index < this.source.length) {\n if (this.source[this.index] !== \"\\\"\") this.malformed();\n const key = this.parseString();\n if (keys.has(key)) {\n throw new StrictJsonError(\"duplicate-field\", `typed compaction request contains duplicate field ${JSON.stringify(key)}`);\n }\n keys.add(key);\n this.skipWhitespace();\n if (this.source[this.index] !== \":\") this.malformed();\n this.index += 1;\n this.skipWhitespace();\n output[key] = this.parseValue(depth);\n this.skipWhitespace();\n const delimiter = this.source[this.index];\n if (delimiter === \"}\") {\n this.index += 1;\n return output;\n }\n if (delimiter !== \",\") this.malformed();\n this.index += 1;\n this.skipWhitespace();\n }\n return this.malformed();\n }\n\n private parseArray(depth: number): unknown[] {\n this.index += 1;\n this.skipWhitespace();\n const output: unknown[] = [];\n if (this.source[this.index] === \"]\") {\n this.index += 1;\n return output;\n }\n while (this.index < this.source.length) {\n output.push(this.parseValue(depth));\n this.skipWhitespace();\n const delimiter = this.source[this.index];\n if (delimiter === \"]\") {\n this.index += 1;\n return output;\n }\n if (delimiter !== \",\") this.malformed();\n this.index += 1;\n this.skipWhitespace();\n }\n return this.malformed();\n }\n\n private parseString(): string {\n this.index += 1;\n let output = \"\";\n while (this.index < this.source.length) {\n const unit = this.source.charCodeAt(this.index);\n if (unit === 0x22) {\n this.index += 1;\n if (!hasPairedSurrogates(output)) {\n throw new StrictJsonError(\"invalid-unicode\", \"typed compaction JSON string contains an unpaired UTF-16 surrogate\");\n }\n return output;\n }\n if (unit <= 0x1f) this.malformed();\n if (unit !== 0x5c) {\n output += this.source[this.index]!;\n this.index += 1;\n continue;\n }\n this.index += 1;\n const escape = this.source[this.index];\n this.index += 1;\n if (escape === \"\\\"\" || escape === \"\\\\\" || escape === \"/\") output += escape;\n else if (escape === \"b\") output += \"\\b\";\n else if (escape === \"f\") output += \"\\f\";\n else if (escape === \"n\") output += \"\\n\";\n else if (escape === \"r\") output += \"\\r\";\n else if (escape === \"t\") output += \"\\t\";\n else if (escape === \"u\") {\n let value = 0;\n for (let offset = 0; offset < 4; offset++) {\n const digit = this.hexValue(this.source.charCodeAt(this.index + offset));\n if (digit < 0) this.malformed();\n value = value * 16 + digit;\n }\n this.index += 4;\n output += String.fromCharCode(value);\n } else {\n this.malformed();\n }\n }\n return this.malformed();\n }\n\n private parseNumber(): number {\n const start = this.index;\n if (this.source[this.index] === \"-\") this.index += 1;\n if (this.source[this.index] === \"0\") {\n this.index += 1;\n if (this.isDigit(this.source.charCodeAt(this.index))) this.malformed();\n } else {\n if (!this.isDigitOneToNine(this.source.charCodeAt(this.index))) this.malformed();\n while (this.isDigit(this.source.charCodeAt(this.index))) this.index += 1;\n }\n if (this.source[this.index] === \".\") {\n this.index += 1;\n if (!this.isDigit(this.source.charCodeAt(this.index))) this.malformed();\n while (this.isDigit(this.source.charCodeAt(this.index))) this.index += 1;\n }\n const exponent = this.source[this.index];\n if (exponent === \"e\" || exponent === \"E\") {\n this.index += 1;\n const sign = this.source[this.index];\n if (sign === \"+\" || sign === \"-\") this.index += 1;\n if (!this.isDigit(this.source.charCodeAt(this.index))) this.malformed();\n while (this.isDigit(this.source.charCodeAt(this.index))) this.index += 1;\n }\n const value = Number(this.source.slice(start, this.index));\n if (!Number.isFinite(value)) this.malformed();\n return value;\n }\n\n private parseLiteral<T>(literal: string, value: T): T {\n if (!this.source.startsWith(literal, this.index)) this.malformed();\n this.index += literal.length;\n return value;\n }\n\n private skipWhitespace(): void {\n while (this.index < this.source.length) {\n const unit = this.source.charCodeAt(this.index);\n if (unit !== 0x20 && unit !== 0x09 && unit !== 0x0a && unit !== 0x0d) return;\n this.index += 1;\n }\n }\n\n private hexValue(unit: number): number {\n if (unit >= 0x30 && unit <= 0x39) return unit - 0x30;\n if (unit >= 0x41 && unit <= 0x46) return unit - 0x41 + 10;\n if (unit >= 0x61 && unit <= 0x66) return unit - 0x61 + 10;\n return -1;\n }\n\n private isDigit(unit: number): boolean {\n return unit >= 0x30 && unit <= 0x39;\n }\n\n private isDigitOneToNine(unit: number): boolean {\n return unit >= 0x31 && unit <= 0x39;\n }\n\n private malformed(): never {\n throw new StrictJsonError(\"malformed-json\", \"typed compaction request contains malformed JSON\");\n }\n}\n\nexport const decodeCompactionInstructions = (\n source: string | undefined,\n): DecodedCompactionInstructions => {\n if (source === undefined || source === \"\") {\n return {\n ok: true,\n requestLines: [],\n policy: {\n mode: \"none\",\n canonicalized: false,\n sourceBytes: 0,\n truncated: false,\n preserveCount: 0,\n omittedPreserveCount: 0,\n },\n };\n }\n if (!source.startsWith(FABRIC_COMPACTION_REQUEST_PREFIX)) return plainInstructions(source);\n\n const encodedSourceBytes = utf8Bytes(source);\n if (encodedSourceBytes > MAX_TYPED_COMPACTION_SOURCE_BYTES) {\n return rejection(\n \"encoded-source-too-large\",\n `typed compaction request exceeds ${MAX_TYPED_COMPACTION_SOURCE_BYTES} encoded UTF-8 bytes`,\n encodedSourceBytes,\n );\n }\n\n let parsed: unknown;\n try {\n parsed = new StrictJsonParser(source.slice(FABRIC_COMPACTION_REQUEST_PREFIX.length)).parse();\n } catch (error) {\n if (error instanceof StrictJsonError) {\n return rejection(error.code, error.message, encodedSourceBytes);\n }\n return rejection(\"malformed-json\", \"typed compaction request contains malformed JSON\", encodedSourceBytes);\n }\n if (!isRecord(parsed)) {\n return rejection(\"invalid-object\", \"typed compaction request must be a JSON object\", encodedSourceBytes);\n }\n\n const keys = Object.keys(parsed);\n const unknownField = keys.find((key) => key !== \"version\" && key !== \"instructions\" && key !== \"preserve\");\n if (unknownField !== undefined) {\n return rejection(\"unknown-field\", `typed compaction request contains unknown field ${JSON.stringify(unknownField)}`, encodedSourceBytes);\n }\n if (parsed.version !== 1) {\n return rejection(\"unsupported-version\", \"typed compaction request version must be 1\", encodedSourceBytes);\n }\n if (parsed.instructions !== undefined && typeof parsed.instructions !== \"string\") {\n return rejection(\"invalid-type\", \"typed compaction request instructions must be a string\", encodedSourceBytes);\n }\n if (parsed.preserve !== undefined && !Array.isArray(parsed.preserve)) {\n return rejection(\"invalid-type\", \"typed compaction request preserve must be an array\", encodedSourceBytes);\n }\n\n const preserve = parsed.preserve as unknown[] | undefined;\n if (preserve !== undefined && preserve.length > MAX_PRESERVE_ITEMS) {\n return rejection(\n \"preserve-too-many\",\n `typed compaction preserve exceeds ${MAX_PRESERVE_ITEMS} items`,\n encodedSourceBytes,\n );\n }\n if (preserve !== undefined && !preserve.every((item) => typeof item === \"string\")) {\n return rejection(\"invalid-type\", \"typed compaction preserve items must be strings\", encodedSourceBytes);\n }\n\n const request: Omit<TypedCompactionRequest, \"version\"> = {\n ...(parsed.instructions !== undefined ? { instructions: parsed.instructions } : {}),\n ...(preserve !== undefined ? { preserve: preserve as string[] } : {}),\n };\n const boundsError = compactionRequestBoundsError(request);\n if (boundsError) return rejection(boundsError.code, boundsError.message, encodedSourceBytes);\n\n const requestLines: string[] = [];\n let valueSourceBytes = 0;\n let truncated = false;\n let canonicalized = false;\n if (request.instructions !== undefined) {\n const instructions = canonicalizeText(request.instructions, MAX_COMPACTION_INSTRUCTIONS_BYTES);\n valueSourceBytes += instructions.sourceBytes;\n truncated ||= instructions.truncated;\n canonicalized ||= instructions.text !== request.instructions;\n if (instructions.text) requestLines.push(instructions.text);\n }\n\n for (let index = 0; index < (request.preserve?.length ?? 0); index++) {\n const sourceItem = request.preserve![index]!;\n const item = canonicalizeText(sourceItem, MAX_PRESERVE_ITEM_BYTES);\n valueSourceBytes += item.sourceBytes;\n truncated ||= item.truncated;\n canonicalized ||= item.text !== sourceItem;\n if (item.text) requestLines.push(`- ${item.text} [preserve:${index}]`);\n }\n\n return {\n ok: true,\n requestLines,\n policy: {\n mode: \"typed-v1\",\n canonicalized,\n sourceBytes: valueSourceBytes,\n truncated,\n preserveCount: request.preserve?.length ?? 0,\n omittedPreserveCount: 0,\n },\n };\n};\n"],
5
+ "mappings": ";;;;;AAEO,IAAM,oBAAoB,KAAK;AACtC,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MAAI,YAAY;AAChB,MAAI,gBAAgB;AACpB,MAAI,QAAQ,iBAAiB,QAAW;AACtC,UAAM,eAAe,iBAAiB,QAAQ,cAAc,iCAAiC;AAC7F,wBAAoB,aAAa;AACjC,kBAAc,aAAa;AAC3B,sBAAkB,aAAa,SAAS,QAAQ;AAChD,QAAI,aAAa,KAAM,cAAa,KAAK,aAAa,IAAI;AAAA,EAC5D;AAEA,WAAS,QAAQ,GAAG,SAAS,QAAQ,UAAU,UAAU,IAAI,SAAS;AACpE,UAAM,aAAa,QAAQ,SAAU,KAAK;AAC1C,UAAM,OAAO,iBAAiB,YAAY,uBAAuB;AACjE,wBAAoB,KAAK;AACzB,kBAAc,KAAK;AACnB,sBAAkB,KAAK,SAAS;AAChC,QAAI,KAAK,KAAM,cAAa,KAAK,KAAK,KAAK,IAAI,cAAc,KAAK,GAAG;AAAA,EACvE;AAEA,SAAO;AAAA,IACL,IAAI;AAAA,IACJ;AAAA,IACA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN;AAAA,MACA,aAAa;AAAA,MACb;AAAA,MACA,eAAe,QAAQ,UAAU,UAAU;AAAA,MAC3C,sBAAsB;AAAA,IACxB;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -1,3 +1,6 @@
1
+ import {
2
+ Pe
3
+ } from "./chunk-4E63LJDD.js";
1
4
  import {
2
5
  stableJsonHash
3
6
  } from "./chunk-3YZUQESG.js";
@@ -212,7 +215,9 @@ var provesNormalFormPlan = (plan, schema) => {
212
215
  };
213
216
  var applyNormalFormPlan = (ref, schema, args, plan) => {
214
217
  const unchanged = { args };
215
- if (!plan || plan.ref !== ref || accepts(schema, args) || !provesNormalFormPlan(plan, schema)) return unchanged;
218
+ const canonical = accepts(schema, args);
219
+ const proven = !canonical && plan !== void 0 && plan.ref === ref && provesNormalFormPlan(plan, schema);
220
+ if (!Pe(canonical, proven, true, true) || !plan) return unchanged;
216
221
  const properties = schema.properties;
217
222
  const candidate = { ...args };
218
223
  const applied = [];
@@ -253,7 +258,7 @@ var applyNormalFormPlan = (ref, schema, args, plan) => {
253
258
  }
254
259
  }
255
260
  }
256
- if (applied.length === 0 || !accepts(schema, candidate)) return unchanged;
261
+ if (!Pe(canonical, proven, applied.length > 0, accepts(schema, candidate))) return unchanged;
257
262
  return {
258
263
  args: candidate,
259
264
  witness: {
@@ -284,4 +289,4 @@ export {
284
289
  provesNormalFormPlan,
285
290
  applyNormalFormPlan
286
291
  };
287
- //# sourceMappingURL=chunk-G4LADAYY.js.map
292
+ //# sourceMappingURL=chunk-OINADFEF.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/entropy/fingerprint.ts", "../../src/entropy/normal-form.ts"],
4
+ "sourcesContent": ["// Deterministic fingerprints for the entropy meter: canonical call-shape\n// signatures, signature distance (retry churn), Shannon entropy in bits, and\n// the static freedom score of a JSON Schema. Everything here is a pure\n// function of its inputs; the same value always yields the same fingerprint.\n\nimport type { EntropyTrend } from \"./types.js\";\n\nconst SIGNATURE_MAX_KEYS = 32;\nconst SIGNATURE_MAX_DEPTH = 3;\n// Enum cardinality whose freedom saturates at 1.0 (log2 of 64 values).\nconst ENUM_SATURATION_BITS = 6;\n\nconst isPlainRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n// Fixed rounding for every reported metric value. Same inputs, same floats,\n// same six decimal places \u2014 report JSON is byte-stable. Negative zero\n// collapses to zero so single-class entropies compare equal to zero.\nexport const roundMetric = (value: number): number => {\n const rounded = Math.round(value * 1e6) / 1e6;\n return rounded === 0 ? 0 : rounded;\n};\n\n// Code-unit string comparison: locale-independent, so ordering never varies\n// with the host's ICU data.\nexport const compareCodeUnits = (left: string, right: string): number =>\n left < right ? -1 : left > right ? 1 : 0;\n\nconst typeTag = (value: unknown, depth: number): string => {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"arr\";\n switch (typeof value) {\n case \"string\":\n return \"str\";\n case \"number\":\n return \"num\";\n case \"boolean\":\n return \"bool\";\n case \"object\": {\n if (depth >= SIGNATURE_MAX_DEPTH) return \"obj\";\n try {\n const record = value as Record<string, unknown>;\n const keys = Object.keys(record).sort();\n const head = keys\n .slice(0, SIGNATURE_MAX_KEYS)\n .map((key) => `${key}:${typeTag(record[key], depth + 1)}`);\n if (keys.length > SIGNATURE_MAX_KEYS) {\n head.push(`\u2026+${keys.length - SIGNATURE_MAX_KEYS}`);\n }\n return `{${head.join(\",\")}}`;\n } catch {\n return \"obj\";\n }\n }\n default:\n return \"other\";\n }\n};\n\n// Canonical argument-shape signature: sorted parameter names with a bounded\n// value-type tag each. Key order and value contents never matter \u2014 only the\n// shape the model chose.\nexport const shapeSignature = (args: Record<string, unknown>): string => {\n const keys = Object.keys(args).sort();\n const head = keys\n .slice(0, SIGNATURE_MAX_KEYS)\n .map((key) => `${key}:${typeTag(args[key], 1)}`);\n if (keys.length > SIGNATURE_MAX_KEYS) {\n head.push(`\u2026+${keys.length - SIGNATURE_MAX_KEYS}`);\n }\n return `(${head.join(\",\")})`;\n};\n\n// Normalized Levenshtein distance between two signatures, in [0, 1]. Retry\n// churn is the distance between a failed call's shape and the next attempt's.\nexport const signatureDistance = (left: string, right: string): number => {\n if (left === right) return 0;\n const bound = Math.max(left.length, right.length);\n if (bound === 0) return 0;\n let previous: number[] = [];\n for (let index = 0; index <= right.length; index++) {\n previous.push(index);\n }\n for (let index = 1; index <= left.length; index++) {\n const current: number[] = [index];\n for (let inner = 1; inner <= right.length; inner++) {\n const substitution = previous[inner - 1]! + (left[index - 1] === right[inner - 1] ? 0 : 1);\n const insertion = current[inner - 1]! + 1;\n const deletion = previous[inner]! + 1;\n current.push(Math.min(substitution, insertion, deletion));\n }\n previous = current;\n }\n return roundMetric(previous[right.length]! / bound);\n};\n\n// Shannon entropy in bits over a count distribution, rounded to 1e-6.\n// A single class is zero bits; a uniform split over k classes is log2(k).\nexport const shannonEntropyBits = (counts: readonly number[]): number => {\n const total = counts.reduce((sum, value) => sum + value, 0);\n if (total <= 0) return 0;\n let bits = 0;\n for (const count of counts) {\n if (count <= 0) continue;\n const probability = count / total;\n bits += probability * Math.log2(probability);\n }\n return roundMetric(-bits);\n};\n\nconst schemaFreedom = (schema: unknown, depth: number): number => {\n if (depth > SIGNATURE_MAX_DEPTH) return 0.5;\n if (!isPlainRecord(schema)) return 0.5;\n const union = Array.isArray(schema.anyOf)\n ? schema.anyOf\n : Array.isArray(schema.oneOf)\n ? schema.oneOf\n : undefined;\n if (union) {\n const scores = union.map((branch) => schemaFreedom(branch, depth + 1));\n const widest = scores.length > 0 ? Math.max(...scores) : 0;\n return roundMetric(widest + 0.1 * Math.max(0, union.length - 1));\n }\n if (Array.isArray(schema.enum)) {\n return roundMetric(\n Math.min(1, Math.log2(Math.max(1, schema.enum.length)) / ENUM_SATURATION_BITS),\n );\n }\n if (\"const\" in schema) return 0;\n const type = schema.type;\n if (typeof type !== \"string\") return 0.75;\n if (type === \"boolean\") return 0.1;\n if (type === \"number\" || type === \"integer\") return 0.5;\n if (type === \"string\") return 1;\n if (type === \"array\") return roundMetric(0.5 + 0.5 * schemaFreedom(schema.items, depth + 1));\n if (type === \"object\") {\n const properties = schema.properties;\n if (!isPlainRecord(properties)) return 1;\n const keys = Object.keys(properties).sort();\n if (keys.length === 0) return 1;\n const required = Array.isArray(schema.required)\n ? schema.required.filter((entry): entry is string => typeof entry === \"string\")\n : [];\n let score = 0;\n for (const key of keys) {\n score += schemaFreedom(properties[key], depth + 1);\n if (!required.includes(key)) score += 0.25;\n }\n if (schema.additionalProperties !== false) score += 0.5;\n return roundMetric(score);\n }\n return 0.75;\n};\n\n// Static freedom of one action's input schema: free strings dominate, enums\n// shrink with log2 cardinality, literals cost nothing, and optional or\n// open-ended parameters add tax. Computable with an empty corpus, which is\n// what lets the compiler score candidate surfaces before deployment.\nexport const staticFreedomFromSchema = (schema: unknown): number => schemaFreedom(schema, 0);\n\n// Least-squares slope of a score sequence, oldest to newest. The on-demand\n// session trend feeds this per-session scores; a flat or negative slope is\n// the ratchet holding.\nexport const trendFromScores = (scores: readonly number[]): EntropyTrend => {\n const count = scores.length;\n const first = count > 0 ? scores[0] : undefined;\n const last = count > 0 ? scores[count - 1] : undefined;\n let slope = 0;\n if (count >= 2) {\n const meanX = (count - 1) / 2;\n const meanY = scores.reduce((sum, value) => sum + value, 0) / count;\n let numerator = 0;\n let denominator = 0;\n for (let index = 0; index < count; index++) {\n numerator += (index - meanX) * (scores[index]! - meanY);\n denominator += (index - meanX) ** 2;\n }\n slope = denominator > 0 ? numerator / denominator : 0;\n }\n return {\n count,\n ...(first !== undefined ? { first: roundMetric(first) } : {}),\n ...(last !== undefined ? { last: roundMetric(last) } : {}),\n slopePerStep: roundMetric(slope),\n };\n};\n", "// Internal compatibility plans. The declared schema is never rewritten.\n// A proof is a re-derivation from a bounded rule language, not a claim made\n// by an imported artifact. No observation can authorize a new semantic map.\nimport { Value } from \"typebox/value\";\nimport { useNormalized } from \"../verified/policy.js\";\nimport { stableJsonHash } from \"../core/stable-hash.js\";\nimport { shapeSignature } from \"./fingerprint.js\";\n\nexport interface NormalFormEvidenceSummary {\n normalizedCalls: number;\n rulesApplied: number;\n succeeded: number;\n subsequentFailures: number;\n}\n\n// Witness counts are observations, not manufactured task successes. A call\n// can be normalized and still fail authorization, approval, or execution.\nexport const normalFormEvidenceSummary = (\n traces: readonly import(\"./types.js\").EntropyTraceInput[],\n): NormalFormEvidenceSummary => {\n const summary = { normalizedCalls: 0, rulesApplied: 0, succeeded: 0, subsequentFailures: 0 };\n for (const trace of traces) for (const operation of trace.operations) {\n if (!operation.normalization || !isNormalFormWitness(operation.normalization)) continue;\n summary.normalizedCalls++;\n summary.rulesApplied += operation.normalization.rules.length;\n if (operation.outcome === \"succeeded\") summary.succeeded++;\n else summary.subsequentFailures++;\n }\n return summary;\n};\n\nexport const NORMAL_FORM_VERSION = 1 as const;\nexport const MAX_NORMAL_FORM_RULES = 128;\nexport const MAX_NORMAL_FORM_PLANS = 1_000;\nconst RULE_KINDS = [\"key-form\", \"enum-form\", \"numeric-string\", \"optional-null\"] as const;\nexport type NormalFormRuleKind = typeof RULE_KINDS[number];\nexport interface NormalFormRule { kind: NormalFormRuleKind; key: string }\nexport interface NormalFormPlan {\n version: typeof NORMAL_FORM_VERSION;\n ref: string;\n baseSchemaDigest: string;\n rules: NormalFormRule[];\n}\nexport interface NormalFormWitness {\n version: typeof NORMAL_FORM_VERSION;\n baseSchemaDigest: string;\n beforeShape: string;\n afterShape: string;\n rules: NormalFormRule[];\n}\nexport interface NormalFormResult {\n args: Record<string, unknown>;\n witness?: NormalFormWitness;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\nconst safeKey = (key: string): boolean => key.length <= 128 &&\n ![\"__proto__\", \"prototype\", \"constructor\"].includes(key);\nconst form = (value: string): string | undefined =>\n /^[a-zA-Z][a-zA-Z0-9 _-]*$/.test(value) ? value.toLowerCase().replace(/[ _-]/g, \"\") : undefined;\nconst accepts = (schema: unknown, args: unknown): boolean => {\n try { return isRecord(schema) && Value.Check(schema, args); } catch { return false; }\n};\nconst uniqueForms = (values: readonly string[]): Map<string, string> => {\n const groups = new Map<string, string[]>();\n for (const value of values) {\n const key = form(value);\n if (!key) continue;\n const group = groups.get(key) ?? [];\n group.push(value);\n groups.set(key, group);\n }\n return new Map([...groups].filter(([, group]) => group.length === 1).map(([key, group]) => [key, group[0]!]));\n};\n\n// These four conventions are host-authored compatibility semantics:\n// spelling-only key/enum forms, lossless numeric encoding, and omission of\n// non-nullable optional fields. Open objects and schema combinators are not\n// grounds for inventing an interpretation. Unsupported schemas pass through.\nexport const deriveNormalFormPlan = (ref: string, schema: unknown): NormalFormPlan | undefined => {\n if (!ref || ref.length > 1_024 || !isRecord(schema) || schema.type !== \"object\" ||\n schema.additionalProperties !== false || !isRecord(schema.properties) ||\n [\"patternProperties\", \"oneOf\", \"anyOf\", \"allOf\", \"$ref\", \"if\", \"not\"].some((key) => Object.hasOwn(schema, key))) return undefined;\n const keys = Object.keys(schema.properties).sort();\n if (keys.length > MAX_NORMAL_FORM_RULES || !keys.every(safeKey)) return undefined;\n const required = new Set(Array.isArray(schema.required) ? schema.required : []);\n const forms = new Set(uniqueForms(keys).values());\n const rules: NormalFormRule[] = [];\n for (const key of keys) {\n const property = schema.properties[key];\n if (!isRecord(property)) continue;\n if (forms.has(key)) rules.push({ kind: \"key-form\", key });\n if (!required.has(key) && !accepts(property, null)) rules.push({ kind: \"optional-null\", key });\n if (property.type === \"number\" || property.type === \"integer\") rules.push({ kind: \"numeric-string\", key });\n if (property.type === \"string\" && Array.isArray(property.enum) &&\n property.enum.every((value) => typeof value === \"string\") &&\n uniqueForms(property.enum).size > 0) rules.push({ kind: \"enum-form\", key });\n }\n if (rules.length === 0) return undefined;\n return { version: NORMAL_FORM_VERSION, ref, baseSchemaDigest: stableJsonHash(schema), rules: rules.slice(0, MAX_NORMAL_FORM_RULES) };\n};\n\nconst isRule = (value: unknown): value is NormalFormRule => isRecord(value) &&\n Object.keys(value).length === 2 && typeof value.key === \"string\" && safeKey(value.key) &&\n RULE_KINDS.includes(value.kind as NormalFormRuleKind);\nconst isDigest = (value: unknown): value is string => typeof value === \"string\" && /^[a-f0-9]{64}$/.test(value);\nexport const isNormalFormPlan = (value: unknown): value is NormalFormPlan => isRecord(value) &&\n Object.keys(value).length === 4 && value.version === NORMAL_FORM_VERSION &&\n typeof value.ref === \"string\" && value.ref.length > 0 && value.ref.length <= 1_024 &&\n isDigest(value.baseSchemaDigest) && Array.isArray(value.rules) &&\n value.rules.length > 0 && value.rules.length <= MAX_NORMAL_FORM_RULES && value.rules.every(isRule);\nexport const isNormalFormWitness = (value: unknown): value is NormalFormWitness => isRecord(value) &&\n Object.keys(value).length === 5 && value.version === NORMAL_FORM_VERSION &&\n isDigest(value.baseSchemaDigest) && isDigest(value.beforeShape) && isDigest(value.afterShape) &&\n Array.isArray(value.rules) && value.rules.length > 0 && value.rules.length <= MAX_NORMAL_FORM_RULES && value.rules.every(isRule);\n\nexport const provesNormalFormPlan = (plan: NormalFormPlan, schema: unknown): boolean => {\n if (!isNormalFormPlan(plan)) return false;\n try {\n const derived = deriveNormalFormPlan(plan.ref, schema);\n return derived !== undefined && stableJsonHash(derived) === stableJsonHash(plan);\n } catch { return false; }\n};\n\nexport const applyNormalFormPlan = (\n ref: string,\n schema: unknown,\n args: Record<string, unknown>,\n plan?: NormalFormPlan,\n): NormalFormResult => {\n const unchanged = { args };\n // This early identity law protects every canonical capability, including\n // rare enum members and nullable values. Successful candidates satisfy it\n // too, which establishes idempotence without a corpus-dependent gate.\n const canonical = accepts(schema, args);\n const proven = !canonical && plan !== undefined && plan.ref === ref && provesNormalFormPlan(plan, schema);\n if (!useNormalized(canonical, proven, true, true) || !plan) return unchanged;\n const properties = (schema as { properties: Record<string, Record<string, unknown>> }).properties;\n const candidate = { ...args };\n const applied: NormalFormRule[] = [];\n const keyRules = plan.rules.filter((rule) => rule.kind === \"key-form\");\n const forms = uniqueForms(keyRules.map((rule) => rule.key));\n const targets = new Set<string>();\n for (const key of Object.keys(args).sort()) {\n if (Object.hasOwn(properties, key)) continue;\n const normalized = form(key);\n const target = normalized ? forms.get(normalized) : undefined;\n if (!target) continue;\n // Never discard a competing canonical value or choose between aliases.\n if (Object.hasOwn(args, target) || targets.has(target)) return unchanged;\n targets.add(target);\n Object.defineProperty(candidate, target, { value: args[key], enumerable: true, configurable: true, writable: true });\n delete candidate[key];\n applied.push({ kind: \"key-form\", key: target });\n }\n for (const rule of plan.rules) {\n if (rule.kind === \"key-form\" || !Object.hasOwn(candidate, rule.key)) continue;\n const value = candidate[rule.key];\n const property = properties[rule.key]!;\n if (accepts(property, value)) continue;\n if (rule.kind === \"optional-null\" && (value === null || value === undefined)) {\n delete candidate[rule.key];\n applied.push(rule);\n } else if (rule.kind === \"numeric-string\" && typeof value === \"string\") {\n const number = Number(value);\n if (Number.isFinite(number) && String(number) === value && accepts(property, number)) {\n candidate[rule.key] = number;\n applied.push(rule);\n }\n } else if (rule.kind === \"enum-form\" && typeof value === \"string\") {\n const normalized = form(value);\n const target = normalized ? uniqueForms(property.enum as string[]).get(normalized) : undefined;\n if (target !== undefined && accepts(property, target)) {\n candidate[rule.key] = target;\n applied.push(rule);\n }\n }\n }\n // A partial repair is not a successful correction. Return original input\n // on every refusal so authoritative validation reports the real failure.\n if (!useNormalized(canonical, proven, applied.length > 0, accepts(schema, candidate))) return unchanged;\n return {\n args: candidate,\n witness: {\n version: NORMAL_FORM_VERSION,\n baseSchemaDigest: plan.baseSchemaDigest,\n beforeShape: stableJsonHash(shapeSignature(args)),\n afterShape: stableJsonHash(shapeSignature(candidate)),\n rules: applied,\n },\n };\n};\n"],
5
+ "mappings": ";;;;;;;;AAOA,IAAM,qBAAqB;AAC3B,IAAM,sBAAsB;AAE5B,IAAM,uBAAuB;AAE7B,IAAM,gBAAgB,CAAC,UACrB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAK9D,IAAM,cAAc,CAAC,UAA0B;AACpD,QAAM,UAAU,KAAK,MAAM,QAAQ,GAAG,IAAI;AAC1C,SAAO,YAAY,IAAI,IAAI;AAC7B;AAIO,IAAM,mBAAmB,CAAC,MAAc,UAC7C,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAEzC,IAAM,UAAU,CAAC,OAAgB,UAA0B;AACzD,MAAI,UAAU,KAAM,QAAO;AAC3B,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO;AACjC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK,UAAU;AACb,UAAI,SAAS,oBAAqB,QAAO;AACzC,UAAI;AACF,cAAM,SAAS;AACf,cAAM,OAAO,OAAO,KAAK,MAAM,EAAE,KAAK;AACtC,cAAM,OAAO,KACV,MAAM,GAAG,kBAA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K;AAAA,MACvB,aAAa,eAAe,eAAe,IAAI,CAAC;AAAA,MAChD,YAAY,eAAe,eAAe,SAAS,CAAC;AAAA,MACpD,OAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -14,27 +14,31 @@ import {
14
14
  reconstructSessionLineage,
15
15
  searchMemoryIndex,
16
16
  shardPolicy
17
- } from "./chunk-7A6NVHB5.js";
17
+ } from "./chunk-FJSHRHOR.js";
18
18
  import {
19
19
  compareLexical,
20
20
  foldSessionDigest,
21
21
  normalizeMemoryPhrase,
22
22
  tokenizeLexical
23
- } from "./chunk-U5FYOMG5.js";
23
+ } from "./chunk-UBPFGMDQ.js";
24
24
  import {
25
25
  AmbiguousSessionError,
26
26
  enumerateAllSessions,
27
27
  resolveScope,
28
28
  resolveSessionTarget
29
- } from "./chunk-MGDLRV2R.js";
29
+ } from "./chunk-VQGO4P7C.js";
30
30
  import {
31
31
  expandSessionEntriesChecked,
32
32
  normalizeRecords,
33
33
  normalizeSession
34
- } from "./chunk-XT4346N7.js";
34
+ } from "./chunk-WXSELMFV.js";
35
35
  import {
36
36
  actionArgNormalizer
37
37
  } from "./chunk-NQOEHX62.js";
38
+ import {
39
+ acceptMemoryChunk,
40
+ ge
41
+ } from "./chunk-4E63LJDD.js";
38
42
 
39
43
  // src/memory/context.ts
40
44
  var RECALL_DEFAULT_PAGE_SIZE = 10;
@@ -1129,6 +1133,25 @@ async function processMemoryRecall(args, invocationContext, context, cache) {
1129
1133
  return response;
1130
1134
  }
1131
1135
 
1136
+ // src/verified/memory.ts
1137
+ var acceptsExpansionPage = (records, source, entryOffset, textOffset, cursor) => {
1138
+ if (![entryOffset, textOffset, cursor.position, cursor.textOffset].every((n) => Number.isSafeInteger(n) && n >= 0)) return false;
1139
+ let position = entryOffset;
1140
+ let offset = textOffset;
1141
+ for (const record of records) {
1142
+ const entry = source[position];
1143
+ const range = record.textRange;
1144
+ if (!entry || record.index !== entry.index || typeof record.text !== "string" || !range || !acceptMemoryChunk(range, record.text.length, offset, entry.text.length) || record.text !== entry.text.slice(range.start, range.end)) return false;
1145
+ if (range.complete) {
1146
+ position++;
1147
+ offset = 0;
1148
+ } else {
1149
+ offset = range.end;
1150
+ }
1151
+ }
1152
+ return position === cursor.position && offset === cursor.textOffset && (records.length > 0 || position === source.length);
1153
+ };
1154
+
1132
1155
  // src/memory/expand-service.ts
1133
1156
  async function processMemoryExpand(args, context, cache, signal) {
1134
1157
  const session = typeof args.session === "string" ? args.session : "";
@@ -1196,7 +1219,7 @@ async function processMemoryExpand(args, context, cache, signal) {
1196
1219
  if (snapshot) {
1197
1220
  const sourceChanged = expectedSourceHash !== void 0 && snapshot.sourceHash !== expectedSourceHash;
1198
1221
  const lineageChanged = expectedLineageFingerprint !== void 0 && snapshot.lineageFingerprint !== expectedLineageFingerprint;
1199
- if (sourceChanged || lineageChanged) {
1222
+ if (!ge(!sourceChanged, !lineageChanged)) {
1200
1223
  return {
1201
1224
  session: ref.file,
1202
1225
  branches,
@@ -1223,7 +1246,7 @@ async function processMemoryExpand(args, context, cache, signal) {
1223
1246
  const initialLineage = access.lineage(branches);
1224
1247
  const sourceChanged = expectedSourceHash !== void 0 && initialState.sourceHash !== expectedSourceHash;
1225
1248
  const lineageChanged = expectedLineageFingerprint !== void 0 && initialLineage.fingerprint !== expectedLineageFingerprint;
1226
- if (sourceChanged || lineageChanged) {
1249
+ if (!ge(!sourceChanged, !lineageChanged)) {
1227
1250
  return {
1228
1251
  session: ref.file,
1229
1252
  branches,
@@ -1259,7 +1282,7 @@ async function processMemoryExpand(args, context, cache, signal) {
1259
1282
  const finalState2 = access.state();
1260
1283
  const finalLineage2 = access.lineage(branches);
1261
1284
  const finalObservation = access.observe(branches);
1262
- if (!finalState2 || !finalObservation || finalState2.sourceHash !== initialState.sourceHash || finalLineage2.fingerprint !== initialLineage.fingerprint) {
1285
+ if (!finalState2 || !finalObservation || !ge(finalState2.sourceHash === initialState.sourceHash, finalLineage2.fingerprint === initialLineage.fingerprint)) {
1263
1286
  return {
1264
1287
  session: ref.file,
1265
1288
  error: stalePointerError(
@@ -1545,12 +1568,16 @@ async function processMemoryExpand(args, context, cache, signal) {
1545
1568
  response = responseAt(output, cursor);
1546
1569
  }
1547
1570
  }
1571
+ if (!acceptsExpansionPage(output, selected, entryOffset, textOffset, cursor)) {
1572
+ cache.forgetExpansionSnapshot(snapshot);
1573
+ return { session: ref.file, entries: [], error: { code: "invalid_expansion", message: "Expansion failed source-bound chunk verification" } };
1574
+ }
1548
1575
  const endingObservation = access.observe(branches);
1549
1576
  if (!endingObservation || !sameSourceObservation(snapshot.observation, endingObservation)) {
1550
1577
  cache.forgetExpansionSnapshot(snapshot);
1551
1578
  const actualState = access.state();
1552
1579
  const actualLineage = access.lineage(branches);
1553
- if (!actualState || !endingObservation || actualState.sourceHash !== snapshot.sourceHash || actualLineage.fingerprint !== snapshot.lineageFingerprint) {
1580
+ if (!actualState || !endingObservation || !ge(actualState.sourceHash === snapshot.sourceHash, actualLineage.fingerprint === snapshot.lineageFingerprint)) {
1554
1581
  return {
1555
1582
  session: ref.file,
1556
1583
  error: stalePointerError(
@@ -2178,4 +2205,4 @@ export {
2178
2205
  memoryActionSchemas,
2179
2206
  MemoryProvider
2180
2207
  };
2181
- //# sourceMappingURL=chunk-UQ4LTUH4.js.map
2208
+ //# sourceMappingURL=chunk-OUAC6O5C.js.map