@e4779/pi-fabric 0.92.42-fork.7 → 0.96.4-fork.9

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 (296) 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/recovery-watchdog.d.ts +12 -0
  201. package/dist/worker/recovery-watchdog.d.ts.map +1 -0
  202. package/dist/worker/recovery-watchdog.js +41 -0
  203. package/dist/worker/recovery-watchdog.js.map +7 -0
  204. package/dist/worker.js +70 -20
  205. package/dist/worker.js.map +2 -2
  206. package/docs/agents.md +20 -14
  207. package/docs/architecture.md +1 -1
  208. package/docs/background-tasks.md +140 -0
  209. package/docs/compaction.md +91 -28
  210. package/docs/components.md +5 -1
  211. package/docs/configuration.md +6 -6
  212. package/docs/foreman.md +4 -4
  213. package/docs/harnesses.md +95 -0
  214. package/docs/interface.md +7 -0
  215. package/docs/jev.md +59 -52
  216. package/docs/kernels.md +2 -2
  217. package/docs/licenses/bend-apache-2.0.txt +202 -0
  218. package/docs/memory-recall.md +1 -1
  219. package/docs/programmatic-compaction.md +13 -2
  220. package/docs/provider-capabilities.md +197 -0
  221. package/docs/shell-middleware.md +3 -3
  222. package/docs/skills.md +1 -1
  223. package/docs/verified-kernels.md +278 -0
  224. package/package.json +14 -4
  225. package/proofs/abi.json +308 -0
  226. package/proofs/authority-abi.json +7 -0
  227. package/proofs/authority-kernel.bend +23 -0
  228. package/proofs/authority-proof.bend +74 -0
  229. package/proofs/authority-spec.bend +30 -0
  230. package/proofs/authority-state.bend +43 -0
  231. package/proofs/authority-types.d.ts +3 -0
  232. package/proofs/kernel.bend +139 -0
  233. package/proofs/lifecycle-abi.json +3 -0
  234. package/proofs/lifecycle-kernel.bend +11 -0
  235. package/proofs/lifecycle-proof.bend +249 -0
  236. package/proofs/lifecycle-spec.bend +261 -0
  237. package/proofs/lifecycle-types.d.ts +4 -0
  238. package/proofs/lifecycle.bend +119 -0
  239. package/proofs/provider-abi.json +4 -0
  240. package/proofs/provider-kernel.bend +14 -0
  241. package/proofs/provider-plans.bend +28 -0
  242. package/proofs/provider-spec.bend +14 -0
  243. package/proofs/provider-types.d.ts +5 -0
  244. package/proofs/resource-proof.bend +633 -0
  245. package/proofs/resource-spec.bend +133 -0
  246. package/proofs/resources.bend +160 -0
  247. package/proofs/state-kernel.bend +17 -0
  248. package/proofs/state-plans.bend +40 -0
  249. package/proofs/state-proof.bend +42 -0
  250. package/proofs/state-spec.bend +26 -0
  251. package/proofs/storage-abi.json +3 -0
  252. package/proofs/storage-kernel.bend +11 -0
  253. package/proofs/storage-plans.bend +100 -0
  254. package/proofs/storage-proof.bend +176 -0
  255. package/proofs/storage-spec.bend +70 -0
  256. package/proofs/storage-types.d.ts +8 -0
  257. package/proofs/types.d.ts +7 -0
  258. package/scripts/test-verified-kernels.mjs +107 -0
  259. package/scripts/verified-kernels.mjs +136 -0
  260. package/skillsets/python/fabric-jev/SKILL.md +13 -9
  261. package/skillsets/typescript/fabric-exec/SKILL.md +4 -2
  262. package/skillsets/typescript/fabric-jev/SKILL.md +13 -9
  263. package/dist/chunks/chunk-3H7SDWZI.js.map +0 -7
  264. package/dist/chunks/chunk-3TXOQ5MG.js.map +0 -7
  265. package/dist/chunks/chunk-4NUTVNS2.js.map +0 -7
  266. package/dist/chunks/chunk-77PDIBK2.js +0 -129
  267. package/dist/chunks/chunk-77PDIBK2.js.map +0 -7
  268. package/dist/chunks/chunk-7A6NVHB5.js.map +0 -7
  269. package/dist/chunks/chunk-FLKGJPCN.js.map +0 -7
  270. package/dist/chunks/chunk-G4LADAYY.js.map +0 -7
  271. package/dist/chunks/chunk-IK6PPFWG.js.map +0 -7
  272. package/dist/chunks/chunk-MQG5QKGI.js.map +0 -7
  273. package/dist/chunks/chunk-PSNXUZMY.js.map +0 -7
  274. package/dist/chunks/chunk-Q4XJ4PYL.js.map +0 -7
  275. package/dist/chunks/chunk-RTXZHKMS.js.map +0 -7
  276. package/dist/chunks/chunk-U5FYOMG5.js.map +0 -7
  277. package/dist/chunks/chunk-UQ4LTUH4.js.map +0 -7
  278. package/dist/chunks/chunk-XT4346N7.js.map +0 -7
  279. package/dist/jev/browser.d.ts +0 -37
  280. package/dist/jev/browser.d.ts.map +0 -1
  281. package/dist/jev/browser.js +0 -13
  282. package/dist/jev/browser.js.map +0 -7
  283. /package/dist/chunks/{chunk-IUCVOZRX.js.map → chunk-3SIXBW6A.js.map} +0 -0
  284. /package/dist/chunks/{chunk-2SWRVIYJ.js.map → chunk-754HA6KO.js.map} +0 -0
  285. /package/dist/chunks/{chunk-K6DHXXF5.js.map → chunk-B2IVWASP.js.map} +0 -0
  286. /package/dist/chunks/{chunk-ZDNGXLEC.js.map → chunk-B4HECUJI.js.map} +0 -0
  287. /package/dist/chunks/{chunk-H6DDV6E2.js.map → chunk-CSJSHBAT.js.map} +0 -0
  288. /package/dist/chunks/{chunk-MW5VI7IW.js.map → chunk-D4B4CCTA.js.map} +0 -0
  289. /package/dist/chunks/{chunk-EDL4JDW7.js.map → chunk-EBWMC3OO.js.map} +0 -0
  290. /package/dist/chunks/{chunk-W3FRE4VI.js.map → chunk-FDIEQEXS.js.map} +0 -0
  291. /package/dist/chunks/{chunk-3WIGAX56.js.map → chunk-JCV54SSP.js.map} +0 -0
  292. /package/dist/chunks/{chunk-7VAZ4N43.js.map → chunk-V3PIO7QL.js.map} +0 -0
  293. /package/dist/chunks/{chunk-MGDLRV2R.js.map → chunk-VQGO4P7C.js.map} +0 -0
  294. /package/dist/chunks/{chunk-D5WKZONW.js.map → chunk-X3IRR7CV.js.map} +0 -0
  295. /package/dist/chunks/{chunk-RKRVOBVO.js.map → chunk-YC3QQDZ3.js.map} +0 -0
  296. /package/dist/chunks/{chunk-36B4AIRT.js.map → chunk-ZTXZ6JDO.js.map} +0 -0
@@ -1,44 +1,306 @@
1
1
  import {
2
2
  formatFabricEffectConflict
3
3
  } from "./chunk-LMAVZN7J.js";
4
- import {
5
- runAbortable,
6
- settleWithin
7
- } from "./chunk-7TB7NXSL.js";
8
4
  import {
9
5
  MAX_AUDIT_VALUE_CHARS,
10
- activeQuarantinedRefNames,
11
- applyActiveActionName,
12
- applyActiveArgRepairs,
13
6
  boundedPreviewValue,
14
7
  boundedResult,
15
- effectiveInputSchema,
16
8
  failedResultError,
17
9
  failedResultOutcome,
18
- getActiveRepairCompiler,
19
- isActiveQuarantine,
20
- normalizeActiveArguments,
21
10
  previewArgs,
22
11
  previewResult,
23
12
  repairCatalogInput,
24
13
  validateCatalogArgs,
25
14
  validationMessage
26
- } from "./chunk-PSNXUZMY.js";
15
+ } from "./chunk-G2F2RDZI.js";
16
+ import {
17
+ runAbortable,
18
+ settleWithin,
19
+ throwIfAborted
20
+ } from "./chunk-7TB7NXSL.js";
21
+ import {
22
+ activeQuarantinedRefNames,
23
+ applyActiveActionName,
24
+ applyActiveArgRepairs,
25
+ effectiveInputSchema,
26
+ getActiveRepairCompiler,
27
+ isActiveQuarantine,
28
+ normalizeActiveArguments
29
+ } from "./chunk-KS44WKJJ.js";
27
30
  import {
28
31
  FABRIC_NESTED_TOOL_CALL_ID_PREFIX
29
- } from "./chunk-IJL3QK3J.js";
32
+ } from "./chunk-Y57UHPIK.js";
30
33
  import {
31
34
  FabricResolutionError,
32
35
  FabricTraceSafeError,
33
36
  executionOutcomeFromError
34
- } from "./chunk-D5WKZONW.js";
37
+ } from "./chunk-X3IRR7CV.js";
38
+ import {
39
+ BEND_NAT_MAX,
40
+ Ge,
41
+ Re,
42
+ boundedEffectResources,
43
+ encodeResourceEffects,
44
+ ke,
45
+ qe
46
+ } from "./chunk-4E63LJDD.js";
35
47
  import {
36
48
  stableJsonHash
37
49
  } from "./chunk-3YZUQESG.js";
38
50
 
51
+ // src/verified/generated/authority-kernel.js
52
+ function d(t, e) {
53
+ return { $: t < e ? "LT" : t === e ? "EQ" : "GT" };
54
+ }
55
+ function n(t, e) {
56
+ return { $: "$JMP", f: t, x: e };
57
+ }
58
+ function $(t) {
59
+ for (; t !== null && typeof t == "object" && t.$ === "$JMP"; )
60
+ t = t.f(...t.x);
61
+ return t;
62
+ }
63
+ function o(t, e) {
64
+ return (...r) => r.length < e ? o((...u2) => t(...r, ...u2), e - r.length) : $(t(...r));
65
+ }
66
+ function v(t) {
67
+ return n(m, [t]);
68
+ }
69
+ function y(t) {
70
+ return n(p, [t]);
71
+ }
72
+ function g(t, e) {
73
+ return n(b, [t, e]);
74
+ }
75
+ function R(t, e) {
76
+ return n(w, [t, e]);
77
+ }
78
+ function N(t) {
79
+ return n(A, [t]);
80
+ }
81
+ function m(t) {
82
+ return { $: "Active", grants: t };
83
+ }
84
+ function p(t) {
85
+ if (t.$ === "Released")
86
+ return false;
87
+ {
88
+ let e = t.grants;
89
+ return true;
90
+ }
91
+ }
92
+ function b(t, e) {
93
+ if (t.$ === "Released")
94
+ return false;
95
+ {
96
+ let r = t.grants;
97
+ return n(l, [r, e, false]);
98
+ }
99
+ }
100
+ function w(t, e) {
101
+ if (t.$ === "Released")
102
+ return { $: "Released" };
103
+ {
104
+ let r = t.grants;
105
+ return n(L, [$(f(e, r, true)), e]);
106
+ }
107
+ }
108
+ function A(t) {
109
+ return { $: "Released" };
110
+ }
111
+ function l(t, e, r) {
112
+ if (t.$ === "Nil")
113
+ return r;
114
+ {
115
+ let u2 = t.head, i2 = t.tail, a2 = $(s(e, u2, true));
116
+ return n(l, [i2, e, r || a2]);
117
+ }
118
+ }
119
+ function L(t, e) {
120
+ return t ? { $: "Active", grants: e } : { $: "Released" };
121
+ }
122
+ function f(t, e, r) {
123
+ if (t.$ === "Nil")
124
+ return r;
125
+ {
126
+ let u2 = t.head, i2 = t.tail;
127
+ return n(f, [i2, e, $(c(r, $(l(e, u2, false))))]);
128
+ }
129
+ }
130
+ function s(t, e, r) {
131
+ if (t.$ === "Nil") {
132
+ if (e.$ === "Nil")
133
+ return r;
134
+ {
135
+ let u2 = e.head, i2 = e.tail;
136
+ return false;
137
+ }
138
+ } else {
139
+ let u2 = t.head, i2 = t.tail;
140
+ if (e.$ === "Nil")
141
+ return false;
142
+ {
143
+ let a2 = e.head, h2 = e.tail;
144
+ return n(s, [i2, h2, $(c(r, $(E(u2, a2))))]);
145
+ }
146
+ }
147
+ }
148
+ function c(t, e) {
149
+ return t ? e : false;
150
+ }
151
+ function E(t, e) {
152
+ return n(T, [d(t, e)]);
153
+ }
154
+ function T(t) {
155
+ return t.$ === "LT" ? false : t.$ === "EQ";
156
+ }
157
+ var j = /* @__PURE__ */ o(v, 1);
158
+ var q = /* @__PURE__ */ o(y, 1);
159
+ var D = /* @__PURE__ */ o(g, 2);
160
+ var I = /* @__PURE__ */ o(R, 2);
161
+ var J = /* @__PURE__ */ o(N, 1);
162
+
163
+ // src/verified/authority.ts
164
+ var encodeGrant = (grant) => {
165
+ const text = JSON.stringify([
166
+ grant.ref,
167
+ grant.provider,
168
+ grant.providerBindingId,
169
+ grant.generation,
170
+ grant.descriptorHash
171
+ ]);
172
+ let encoded = { $: "Nil" };
173
+ for (let i2 = text.length - 1; i2 >= 0; i2--) {
174
+ encoded = { $: "Con", head: BigInt(text.charCodeAt(i2)), tail: encoded };
175
+ }
176
+ return encoded;
177
+ };
178
+ var encodeGrants = (grants) => {
179
+ let encoded = { $: "Nil" };
180
+ for (let i2 = grants.length - 1; i2 >= 0; i2--) {
181
+ encoded = { $: "Con", head: encodeGrant(grants[i2]), tail: encoded };
182
+ }
183
+ return encoded;
184
+ };
185
+ var CapabilityAuthority = class _CapabilityAuthority {
186
+ #state;
187
+ #grants;
188
+ constructor(grants, parent) {
189
+ const canonical = grants.map((grant) => Object.freeze({ ...grant }));
190
+ this.#grants = new Map(canonical.map((grant) => [grant.ref, grant]));
191
+ const encoded = encodeGrants(canonical);
192
+ this.#state = parent ? I(parent.#state, encoded) : j(encoded);
193
+ }
194
+ static issue(grants) {
195
+ return new _CapabilityAuthority(grants);
196
+ }
197
+ derive(grants) {
198
+ return new _CapabilityAuthority(grants, this);
199
+ }
200
+ get active() {
201
+ return q(this.#state);
202
+ }
203
+ release() {
204
+ this.#state = J(this.#state);
205
+ }
206
+ resolve(ref) {
207
+ const grant = this.#grants.get(ref);
208
+ return grant && D(this.#state, encodeGrant(grant)) ? { ...grant } : void 0;
209
+ }
210
+ bindings() {
211
+ return this.active ? [...this.#grants.values()].map((grant) => ({ ...grant })) : [];
212
+ }
213
+ };
214
+
39
215
  // src/core/action-registry.ts
40
216
  import { randomUUID as randomUUID2 } from "node:crypto";
41
217
 
218
+ // src/components/effect-policy.ts
219
+ var FabricComponentIndependenceError = class extends Error {
220
+ constructor(message) {
221
+ super(message);
222
+ this.name = "FabricComponentIndependenceError";
223
+ }
224
+ };
225
+ var normalizeResources = boundedEffectResources;
226
+ var trackedRegistration = (registration, fallbackLabel) => {
227
+ if (typeof registration === "string") return { label: registration };
228
+ return { label: fallbackLabel, ...registration };
229
+ };
230
+ var registrationEffect = (registration) => ({
231
+ label: registration.label?.trim().slice(0, 256) || "anonymous",
232
+ kind: registration.kind ?? "transactional",
233
+ resources: normalizeResources(registration.resources),
234
+ ordering: registration.ordering ?? "unknown"
235
+ });
236
+ var actionEffect = (action) => {
237
+ if (!action.effect || action.effect.kind === "none") return void 0;
238
+ return {
239
+ label: action.ref,
240
+ kind: action.effect.kind,
241
+ resources: normalizeResources(action.effect.resources),
242
+ ordering: action.effect.ordering ?? "unknown"
243
+ };
244
+ };
245
+ var summarizeEffects = (effects) => {
246
+ const resourceNoncommutative = /* @__PURE__ */ new Map();
247
+ let hasNoncommutative = false;
248
+ let hasUnknown = false;
249
+ let hasUnknownNoncommutative = false;
250
+ let effectful = 0;
251
+ for (const effect of effects) {
252
+ if (effect.kind === "none") continue;
253
+ effectful++;
254
+ const noncommutative = effect.ordering !== "commutative";
255
+ hasNoncommutative ||= noncommutative;
256
+ for (const resource of effect.resources) {
257
+ if (resource === "*") {
258
+ hasUnknown = true;
259
+ hasUnknownNoncommutative ||= noncommutative;
260
+ } else {
261
+ resourceNoncommutative.set(
262
+ resource,
263
+ (resourceNoncommutative.get(resource) ?? false) || noncommutative
264
+ );
265
+ }
266
+ }
267
+ }
268
+ return {
269
+ declarations: encodeResourceEffects(effects),
270
+ hasEffects: effectful > 0,
271
+ hasNoncommutative,
272
+ hasUnknown,
273
+ hasUnknownNoncommutative,
274
+ resourceNoncommutative
275
+ };
276
+ };
277
+ var effectConflictsBetween = (left, right) => {
278
+ if (!Re(left.declarations, right.declarations)) return [];
279
+ const conflicts = [];
280
+ if (ke(
281
+ left.hasUnknown,
282
+ left.hasUnknownNoncommutative,
283
+ left.hasNoncommutative,
284
+ right.hasUnknown,
285
+ right.hasUnknownNoncommutative,
286
+ right.hasNoncommutative
287
+ )) {
288
+ conflicts.push({ resources: ["*"], reason: "unknown_resource" });
289
+ }
290
+ const overlap = [...left.resourceNoncommutative.keys()].filter(
291
+ (resource) => Ge(
292
+ right.resourceNoncommutative.has(resource),
293
+ left.resourceNoncommutative.get(resource) ?? false,
294
+ right.resourceNoncommutative.get(resource) ?? false
295
+ )
296
+ ).sort();
297
+ if (overlap.length > 0) {
298
+ conflicts.push({ resources: overlap, reason: "shared_resource" });
299
+ }
300
+ return conflicts.length > 0 ? conflicts : [{ resources: ["*"], reason: "unknown_resource" }];
301
+ };
302
+ var compareEffectInfo = (left, right) => left.label.localeCompare(right.label) || left.kind.localeCompare(right.kind) || left.ordering.localeCompare(right.ordering) || left.resources.join("\0").localeCompare(right.resources.join("\0"));
303
+
42
304
  // src/core/action-repair.ts
43
305
  var ACTION_SYNONYM_CLASSES = [
44
306
  // memory.recall and its spilled search verbs.
@@ -91,14 +353,14 @@ var levenshtein = (left, right) => {
91
353
  if (right.length === 0) return left.length;
92
354
  let previous = new Array(right.length + 1);
93
355
  let current = new Array(right.length + 1);
94
- for (let j = 0; j <= right.length; j++) previous[j] = j;
95
- for (let i = 1; i <= left.length; i++) {
96
- current[0] = i;
97
- for (let j = 1; j <= right.length; j++) {
98
- current[j] = Math.min(
99
- previous[j] + 1,
100
- current[j - 1] + 1,
101
- previous[j - 1] + (left[i - 1] === right[j - 1] ? 0 : 1)
356
+ for (let j2 = 0; j2 <= right.length; j2++) previous[j2] = j2;
357
+ for (let i2 = 1; i2 <= left.length; i2++) {
358
+ current[0] = i2;
359
+ for (let j2 = 1; j2 <= right.length; j2++) {
360
+ current[j2] = Math.min(
361
+ previous[j2] + 1,
362
+ current[j2 - 1] + 1,
363
+ previous[j2 - 1] + (left[i2 - 1] === right[j2 - 1] ? 0 : 1)
102
364
  );
103
365
  }
104
366
  const swap = previous;
@@ -191,15 +453,180 @@ var formatUnknownActionMessage = (ref, suggestions) => suggestions.length > 0 ?
191
453
 
192
454
  // src/core/provider-bindings.ts
193
455
  import { randomUUID } from "node:crypto";
456
+
457
+ // src/verified/generated/lifecycle-kernel.js
458
+ function h(o2) {
459
+ if (o2 > 281474976710655n)
460
+ throw "bend: a Nat past the largest immediate 2^48-1";
461
+ return o2;
462
+ }
463
+ function c2(o2, e) {
464
+ return { $: "$JMP", f: o2, x: e };
465
+ }
466
+ function a(o2) {
467
+ for (; o2 !== null && typeof o2 == "object" && o2.$ === "$JMP"; )
468
+ o2 = o2.f(...o2.x);
469
+ return o2;
470
+ }
471
+ function u(o2, e) {
472
+ return (...s2) => s2.length < e ? u((...n2) => o2(...s2, ...n2), e - s2.length) : a(o2(...s2));
473
+ }
474
+ function k(o2, e) {
475
+ return c2(v2, [o2, e]);
476
+ }
477
+ function v2(o2, e) {
478
+ return c2(w2, [e, o2]);
479
+ }
480
+ function w2(o2, e) {
481
+ if (o2.$ === "Inspect") {
482
+ let s2 = e.phase, n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
483
+ return c2(p2, [a($2(s2, d2, false)), { $: "Life", phase: s2, owner: n2, holds: l2, calls: r, revoked: d2 }]);
484
+ } else if (o2.$ === "Activate") {
485
+ let s2 = e.phase;
486
+ if (s2.$ === "Staged") {
487
+ let n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
488
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Active" }, owner: n2, holds: l2, calls: r, revoked: d2 }, command: { $: "Granted" } };
489
+ } else if (s2.$ === "Active") {
490
+ let n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
491
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Active" }, owner: n2, holds: l2, calls: r, revoked: d2 }, command: { $: "Granted" } };
492
+ } else {
493
+ let n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
494
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: l2, calls: r, revoked: d2 }, command: { $: "Denied" } };
495
+ }
496
+ } else if (o2.$ === "Retire") {
497
+ let s2 = e.phase, n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
498
+ return { $: "Outcome", next: { $: "Life", phase: a(m2(s2)), owner: n2, holds: l2, calls: r, revoked: d2 }, command: { $: "Granted" } };
499
+ } else if (o2.$ === "DropOwner") {
500
+ let s2 = e.phase, n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
501
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: false, holds: l2, calls: r, revoked: d2 }, command: { $: "Granted" } };
502
+ } else if (o2.$ === "Revoke") {
503
+ let s2 = e.phase, n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
504
+ return { $: "Outcome", next: { $: "Life", phase: a(m2(s2)), owner: false, holds: l2, calls: r, revoked: true }, command: { $: "Granted" } };
505
+ } else if (o2.$ === "Retain") {
506
+ let s2 = o2.cleanup, n2 = e.phase, l2 = e.owner, r = e.holds, d2 = e.calls, t = e.revoked;
507
+ return c2(x, [a($2(n2, t, s2)), { $: "Life", phase: n2, owner: l2, holds: r, calls: d2, revoked: t }]);
508
+ } else if (o2.$ === "Release") {
509
+ let s2 = e.phase, n2 = e.owner, l2 = e.holds;
510
+ if (l2 === 0n) {
511
+ let r = e.calls, d2 = e.revoked;
512
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: 0n, calls: r, revoked: d2 }, command: { $: "Denied" } };
513
+ } else {
514
+ let r = l2 - 1n, d2 = e.calls, t = e.revoked;
515
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: r, calls: d2, revoked: t }, command: { $: "Granted" } };
516
+ }
517
+ } else if (o2.$ === "Begin") {
518
+ let s2 = o2.cleanup, n2 = e.phase, l2 = e.owner, r = e.holds, d2 = e.calls, t = e.revoked;
519
+ return c2(O, [a($2(n2, t, s2)), { $: "Life", phase: n2, owner: l2, holds: r, calls: d2, revoked: t }]);
520
+ } else if (o2.$ === "End") {
521
+ let s2 = e.phase, n2 = e.owner, l2 = e.holds, r = e.calls;
522
+ if (r === 0n) {
523
+ let d2 = e.revoked;
524
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: l2, calls: 0n, revoked: d2 }, command: { $: "Denied" } };
525
+ } else {
526
+ let d2 = r - 1n, t = e.revoked;
527
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: l2, calls: d2, revoked: t }, command: { $: "Granted" } };
528
+ }
529
+ } else if (o2.$ === "Close") {
530
+ let s2 = e.phase;
531
+ if (s2.$ === "Retiring") {
532
+ let n2 = e.owner;
533
+ if (n2) {
534
+ let l2 = e.holds, r = e.calls, d2 = e.revoked;
535
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Retiring" }, owner: n2, holds: l2, calls: r, revoked: d2 }, command: { $: "Denied" } };
536
+ } else {
537
+ let l2 = e.holds;
538
+ if (l2 === 0n) {
539
+ let r = e.calls;
540
+ if (r === 0n) {
541
+ let d2 = e.revoked;
542
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Closing" }, owner: false, holds: 0n, calls: 0n, revoked: d2 }, command: { $: "StartClose" } };
543
+ } else {
544
+ let d2 = r - 0n, t = e.revoked;
545
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Retiring" }, owner: false, holds: 0n, calls: d2, revoked: t }, command: { $: "Denied" } };
546
+ }
547
+ } else {
548
+ let r = l2 - 0n, d2 = e.calls, t = e.revoked;
549
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Retiring" }, owner: false, holds: r, calls: d2, revoked: t }, command: { $: "Denied" } };
550
+ }
551
+ }
552
+ } else {
553
+ let n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
554
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: l2, calls: r, revoked: d2 }, command: { $: "Denied" } };
555
+ }
556
+ } else if (o2.$ === "Complete") {
557
+ let s2 = e.phase;
558
+ if (s2.$ === "Closing") {
559
+ let n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
560
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Closed" }, owner: n2, holds: l2, calls: r, revoked: d2 }, command: { $: "Granted" } };
561
+ } else {
562
+ let n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
563
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: l2, calls: r, revoked: d2 }, command: { $: "Denied" } };
564
+ }
565
+ } else if (e.phase.$ === "Closed") {
566
+ let s2 = e.owner, n2 = e.holds, l2 = e.calls, r = e.revoked;
567
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Closed" }, owner: s2, holds: n2, calls: l2, revoked: r }, command: { $: "Denied" } };
568
+ } else {
569
+ let s2 = e.owner, n2 = e.holds, l2 = e.calls, r = e.revoked;
570
+ return { $: "Outcome", next: { $: "Life", phase: { $: "Failed" }, owner: false, holds: n2, calls: l2, revoked: true }, command: { $: "Granted" } };
571
+ }
572
+ }
573
+ function p2(o2, e) {
574
+ return o2 ? { $: "Outcome", next: e, command: { $: "Granted" } } : { $: "Outcome", next: e, command: { $: "Denied" } };
575
+ }
576
+ function $2(o2, e, s2) {
577
+ if (o2.$ === "Closing" || o2.$ === "Closed")
578
+ return false;
579
+ if (o2.$ === "Failed")
580
+ return s2;
581
+ {
582
+ let n2 = a(L2(e));
583
+ return s2 || n2;
584
+ }
585
+ }
586
+ function m2(o2) {
587
+ return o2.$ === "Staged" ? { $: "Retiring" } : o2.$ === "Active" ? { $: "Retiring" } : o2;
588
+ }
589
+ function x(o2, e) {
590
+ if (o2) {
591
+ let s2 = e.phase, n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
592
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: h(l2 + 1n), calls: r, revoked: d2 }, command: { $: "Granted" } };
593
+ } else
594
+ return { $: "Outcome", next: e, command: { $: "Denied" } };
595
+ }
596
+ function O(o2, e) {
597
+ if (o2) {
598
+ let s2 = e.phase, n2 = e.owner, l2 = e.holds, r = e.calls, d2 = e.revoked;
599
+ return { $: "Outcome", next: { $: "Life", phase: s2, owner: n2, holds: l2, calls: h(r + 1n), revoked: d2 }, command: { $: "Granted" } };
600
+ } else
601
+ return { $: "Outcome", next: e, command: { $: "Denied" } };
602
+ }
603
+ function L2(o2) {
604
+ return !o2;
605
+ }
606
+ var i = /* @__PURE__ */ u(k, 2);
607
+
608
+ // src/core/provider-bindings.ts
194
609
  var snapshot = (binding) => ({
195
610
  ...binding,
196
611
  ...binding.closeTask ? { closeTask: binding.closeTask } : {}
197
612
  });
613
+ var useOnce = () => {
614
+ let active = true;
615
+ return () => {
616
+ const next = qe(active);
617
+ active = next.snd;
618
+ return next.fst;
619
+ };
620
+ };
198
621
  var FabricProviderBindings = class {
622
+ #lifecycles = /* @__PURE__ */ new Map();
199
623
  #current = /* @__PURE__ */ new Map();
200
624
  #staged = /* @__PURE__ */ new Map();
201
625
  #all = /* @__PURE__ */ new Map();
202
626
  #generations = /* @__PURE__ */ new Map();
627
+ #pending = /* @__PURE__ */ new Set();
628
+ #excluded = /* @__PURE__ */ new Set();
629
+ #signals = /* @__PURE__ */ new Map();
203
630
  #listeners = /* @__PURE__ */ new Set();
204
631
  subscribe(listener) {
205
632
  this.#listeners.add(listener);
@@ -210,7 +637,8 @@ var FabricProviderBindings = class {
210
637
  }
211
638
  binding(id) {
212
639
  const binding = this.#all.get(id);
213
- return binding?.state === "closed" ? void 0 : binding;
640
+ const life = this.#lifecycles.get(id);
641
+ return binding && life && i(life, { $: "Inspect" }).command.$ === "Granted" ? binding : void 0;
214
642
  }
215
643
  has(name) {
216
644
  return this.#current.has(name);
@@ -222,6 +650,9 @@ var FabricProviderBindings = class {
222
650
  return [...this.#all.values()].filter((binding) => binding.state !== "closed");
223
651
  }
224
652
  mount(provider, options = {}) {
653
+ if ([...this.#all.values()].some((binding2) => binding2.provider === provider && binding2.closeTask)) {
654
+ throw new Error("Cannot mount a provider instance whose close has begun");
655
+ }
225
656
  const current = this.#current.get(provider.name);
226
657
  const staged = this.#staged.get(provider.name);
227
658
  if ((current || staged) && !options.overwrite) {
@@ -229,6 +660,7 @@ var FabricProviderBindings = class {
229
660
  }
230
661
  if (staged && options.overwrite) this.retire(staged.id);
231
662
  const generation = (this.#generations.get(provider.name) ?? 0) + 1;
663
+ if (!Number.isSafeInteger(generation)) throw new Error("Provider generation overflow");
232
664
  this.#generations.set(provider.name, generation);
233
665
  const binding = {
234
666
  id: randomUUID(),
@@ -247,6 +679,8 @@ var FabricProviderBindings = class {
247
679
  );
248
680
  }
249
681
  this.#all.set(binding.id, binding);
682
+ this.#lifecycles.set(binding.id, { $: "Life", phase: { $: options.staged ? "Staged" : "Active" }, owner: true, holds: 0n, calls: 0n, revoked: false });
683
+ this.#signals.set(binding.id, new AbortController());
250
684
  if (options.staged) {
251
685
  this.#staged.set(binding.name, binding);
252
686
  this.#emit({ type: "staged", binding: snapshot(binding) });
@@ -254,7 +688,7 @@ var FabricProviderBindings = class {
254
688
  const replaced = this.#activateOne(binding);
255
689
  if (replaced && options.overwrite) void this.releaseOwner(replaced.id).catch(() => void 0);
256
690
  }
257
- let released = false;
691
+ const takeRelease = useOnce();
258
692
  return {
259
693
  bindingId: binding.id,
260
694
  name: binding.name,
@@ -264,8 +698,7 @@ var FabricProviderBindings = class {
264
698
  },
265
699
  retire: () => this.retire(binding.id),
266
700
  release: async () => {
267
- if (released) return binding.closeTask;
268
- released = true;
701
+ if (!takeRelease()) return binding.closeTask;
269
702
  return this.releaseOwner(binding.id);
270
703
  }
271
704
  };
@@ -273,7 +706,7 @@ var FabricProviderBindings = class {
273
706
  activate(bindingIds) {
274
707
  const bindings = bindingIds.map((id) => {
275
708
  const binding = this.#all.get(id);
276
- if (!binding || binding.state === "closed") {
709
+ if (!binding || binding.state === "closed" || binding.closeTask) {
277
710
  throw new Error(`Unknown Fabric provider binding: ${id}`);
278
711
  }
279
712
  if (binding.state !== "staged" && binding.state !== "active") {
@@ -311,52 +744,97 @@ var FabricProviderBindings = class {
311
744
  }
312
745
  retire(id) {
313
746
  const binding = this.#all.get(id);
314
- if (!binding || binding.state === "retiring" || binding.state === "closed") return;
747
+ if (!binding) return;
748
+ const withdrawing = this.#current.get(binding.name)?.id === id || this.#staged.get(binding.name)?.id === id;
315
749
  if (this.#current.get(binding.name)?.id === id) this.#current.delete(binding.name);
316
750
  if (this.#staged.get(binding.name)?.id === id) this.#staged.delete(binding.name);
317
- binding.state = "retiring";
318
- this.#emit({ type: "retiring", binding: snapshot(binding) });
751
+ this.#step(binding, { $: "Retire" });
752
+ if (withdrawing) this.#emit({ type: "retiring", binding: snapshot(binding) });
319
753
  void this.#maybeClose(binding).catch(() => void 0);
320
754
  }
321
- retain(ids) {
755
+ retain(ids, cleanup = false) {
322
756
  const retained = [];
323
757
  try {
324
758
  for (const id of new Set(ids)) {
325
759
  const binding = this.#all.get(id);
326
- if (!binding || binding.state === "closed") {
760
+ if (!binding || this.#step(binding, { $: "Retain", cleanup }) !== "Granted") {
327
761
  throw new Error(`Unknown Fabric provider binding: ${id}`);
328
762
  }
329
- binding.retainers++;
330
763
  retained.push(binding);
331
764
  }
332
765
  } catch (error) {
333
- for (const binding of retained) binding.retainers--;
766
+ for (const binding of retained) this.#step(binding, { $: "Release" });
334
767
  throw error;
335
768
  }
336
- let released = false;
769
+ const takeRelease = useOnce();
337
770
  return async () => {
338
- if (released) return;
339
- released = true;
771
+ if (!takeRelease()) return;
340
772
  await Promise.all(retained.map(async (binding) => {
341
- binding.retainers = Math.max(0, binding.retainers - 1);
773
+ this.#step(binding, { $: "Release" });
342
774
  await this.#maybeClose(binding);
343
775
  }));
344
776
  };
345
777
  }
346
- beginInvocation(id) {
778
+ beginInvocation(id, cleanup = false) {
347
779
  const binding = this.#all.get(id);
348
- if (!binding || binding.state === "closed") {
780
+ if (!binding || this.#step(binding, { $: "Begin", cleanup }) !== "Granted") {
349
781
  throw new Error(`Unknown Fabric provider binding: ${id}`);
350
782
  }
351
- binding.inFlight++;
352
- let ended = false;
783
+ const takeEnd = useOnce();
353
784
  return async () => {
354
- if (ended) return;
355
- ended = true;
356
- binding.inFlight = Math.max(0, binding.inFlight - 1);
785
+ if (!takeEnd()) return;
786
+ this.#step(binding, { $: "End" });
357
787
  await this.#maybeClose(binding);
358
788
  };
359
789
  }
790
+ signal(id) {
791
+ const controller = this.#signals.get(id);
792
+ if (!controller) throw new Error("Unknown provider authority");
793
+ return controller.signal;
794
+ }
795
+ revoke(id) {
796
+ const binding = this.#all.get(id);
797
+ if (!binding) return;
798
+ this.#step(binding, { $: "Revoke" });
799
+ this.#signals.get(id)?.abort(new Error("Fabric provider authority revoked"));
800
+ this.retire(id);
801
+ void this.#maybeClose(binding).catch(() => void 0);
802
+ }
803
+ quarantine(id, error) {
804
+ const binding = this.#all.get(id);
805
+ if (!binding) return;
806
+ binding.closeError = error instanceof Error ? error.message : String(error);
807
+ this.#step(binding, { $: "Fail" });
808
+ this.revoke(id);
809
+ }
810
+ /** Hold the real operation, not the caller's cancellation race. */
811
+ track(id, operation, cleanup = false) {
812
+ if (!cleanup && !this.binding(id)) return Promise.reject(new Error("Fabric provider authority revoked or unavailable"));
813
+ let end;
814
+ try {
815
+ end = this.beginInvocation(id, cleanup);
816
+ } catch (error) {
817
+ return Promise.reject(error);
818
+ }
819
+ let actual;
820
+ try {
821
+ actual = Promise.resolve(operation());
822
+ } catch (error) {
823
+ actual = Promise.reject(error);
824
+ }
825
+ this.#pending.add(actual);
826
+ const settled = () => {
827
+ this.#pending.delete(actual);
828
+ return end();
829
+ };
830
+ void actual.then(settled, settled).catch(() => void 0);
831
+ return actual;
832
+ }
833
+ trackProvider(provider, operation, cleanup = false) {
834
+ const binding = [...this.#all.values()].find((item) => item.provider === provider && this.#canBegin(item.id, cleanup));
835
+ if (!binding) return Promise.reject(new Error("Fabric provider binding is unavailable"));
836
+ return this.track(binding.id, operation, cleanup);
837
+ }
360
838
  notifyCatalogChanged(provider) {
361
839
  if (this.#current.has(provider)) this.#emit({ type: "catalog", provider });
362
840
  }
@@ -364,20 +842,13 @@ var FabricProviderBindings = class {
364
842
  const tasks = [];
365
843
  for (const binding of this.#all.values()) {
366
844
  if (binding.state === "closed") continue;
367
- if (excludedProviderNames.has(binding.name)) {
368
- if (this.#current.get(binding.name)?.id === binding.id) this.#current.delete(binding.name);
369
- binding.unsubscribeCatalog?.();
370
- delete binding.unsubscribeCatalog;
371
- binding.state = "closed";
372
- this.#all.delete(binding.id);
373
- continue;
374
- }
375
- this.retire(binding.id);
376
- binding.ownerRetained = false;
377
- binding.retainers = 0;
845
+ if (excludedProviderNames.has(binding.name)) this.#excluded.add(binding.id);
846
+ this.revoke(binding.id);
378
847
  tasks.push(this.#maybeClose(binding));
379
848
  }
380
- await Promise.allSettled(tasks);
849
+ const deadline = Date.now() + 1e3;
850
+ await settleWithin([...tasks, ...this.#pending], 1e3);
851
+ await settleWithin([...this.#all.values()].flatMap((binding) => binding.closeTask ? [binding.closeTask] : []), Math.max(0, deadline - Date.now()));
381
852
  this.#current.clear();
382
853
  this.#staged.clear();
383
854
  }
@@ -386,7 +857,7 @@ var FabricProviderBindings = class {
386
857
  if (current?.id === binding.id && binding.state === "active") return current;
387
858
  if (current && current.id !== binding.id) this.retire(current.id);
388
859
  if (this.#staged.get(binding.name)?.id === binding.id) this.#staged.delete(binding.name);
389
- binding.state = "active";
860
+ if (this.#step(binding, { $: "Activate" }) !== "Granted") throw new Error("Provider binding cannot be activated");
390
861
  this.#current.set(binding.name, binding);
391
862
  this.#emit({ type: "activated", binding: snapshot(binding) });
392
863
  return current;
@@ -395,30 +866,55 @@ var FabricProviderBindings = class {
395
866
  const binding = this.#all.get(id);
396
867
  if (!binding) return;
397
868
  this.retire(id);
398
- binding.ownerRetained = false;
869
+ this.#step(binding, { $: "DropOwner" });
399
870
  await this.#maybeClose(binding);
400
871
  }
401
872
  async #maybeClose(binding) {
402
- if (binding.state !== "retiring" || binding.ownerRetained || binding.retainers > 0 || binding.inFlight > 0) {
403
- return;
404
- }
405
873
  if (binding.closeTask) return binding.closeTask;
406
- binding.closeTask = (async () => {
407
- binding.unsubscribeCatalog?.();
408
- delete binding.unsubscribeCatalog;
874
+ if (this.#step(binding, { $: "Close" }) !== "StartClose") return;
875
+ binding.closeTask = Promise.resolve().then(async () => {
409
876
  try {
410
- await binding.provider.close?.();
877
+ const unsubscribe = binding.unsubscribeCatalog;
878
+ delete binding.unsubscribeCatalog;
879
+ await unsubscribe?.();
880
+ const shared = [...this.#all.values()].some((other) => other.id !== binding.id && other.provider === binding.provider && other.state !== "closed");
881
+ if (!shared && !this.#excluded.has(binding.id)) await binding.provider.close?.();
411
882
  } catch (error) {
412
- binding.closeError = error instanceof Error ? error.message : String(error);
883
+ this.quarantine(binding.id, error);
413
884
  throw error;
414
- } finally {
415
- binding.state = "closed";
416
- this.#all.delete(binding.id);
417
- this.#emit({ type: "closed", binding: snapshot(binding) });
418
885
  }
419
- })();
886
+ if (this.#step(binding, { $: "Complete" }) !== "Granted") {
887
+ throw new Error(binding.closeError ?? "Provider close completion refused");
888
+ }
889
+ this.#all.delete(binding.id);
890
+ this.#lifecycles.delete(binding.id);
891
+ this.#signals.delete(binding.id);
892
+ this.#excluded.delete(binding.id);
893
+ this.#emit({ type: "closed", binding: snapshot(binding) });
894
+ });
420
895
  return binding.closeTask;
421
896
  }
897
+ #canBegin(id, cleanup) {
898
+ const life = this.#lifecycles.get(id);
899
+ return !!life && life.calls < BigInt(BEND_NAT_MAX) && i(life, { $: "Begin", cleanup }).command.$ === "Granted";
900
+ }
901
+ #step(binding, event) {
902
+ const life = this.#lifecycles.get(binding.id);
903
+ if (!life) return "Denied";
904
+ if (event.$ === "Begin" && life.calls >= BigInt(BEND_NAT_MAX) || event.$ === "Retain" && life.holds >= BigInt(BEND_NAT_MAX)) {
905
+ throw new Error("Provider lifecycle accounting overflow");
906
+ }
907
+ const outcome = i(life, event);
908
+ if (outcome.next.holds > BigInt(BEND_NAT_MAX) || outcome.next.calls > BigInt(BEND_NAT_MAX)) {
909
+ throw new Error("Provider lifecycle accounting overflow");
910
+ }
911
+ this.#lifecycles.set(binding.id, outcome.next);
912
+ binding.state = { Staged: "staged", Active: "active", Retiring: "retiring", Closing: "retiring", Closed: "closed", Failed: "retiring" }[outcome.next.phase.$];
913
+ binding.ownerRetained = outcome.next.owner;
914
+ binding.retainers = Number(outcome.next.holds);
915
+ binding.inFlight = Number(outcome.next.calls);
916
+ return outcome.command.$;
917
+ }
422
918
  #emit(event) {
423
919
  for (const listener of [...this.#listeners]) {
424
920
  try {
@@ -433,6 +929,34 @@ var FabricProviderBindings = class {
433
929
  var fabricActionListLimit = (limit) => Math.max(1, Math.min(limit ?? 100, 1e3));
434
930
  var NESTED_TOOL_CALL_ID_PREFIX = FABRIC_NESTED_TOOL_CALL_ID_PREFIX;
435
931
  var providerNamePattern = /^[a-z][a-z0-9_-]*$/;
932
+ var snapshotArguments = (args) => {
933
+ const snapshot2 = structuredClone(args);
934
+ const pending = [snapshot2];
935
+ const seen = /* @__PURE__ */ new WeakSet();
936
+ while (pending.length > 0) {
937
+ const value = pending.pop();
938
+ if (value === null || typeof value !== "object" || seen.has(value)) continue;
939
+ seen.add(value);
940
+ if (typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer) {
941
+ throw new FabricTraceSafeError("Fabric argument snapshots cannot contain shared memory");
942
+ }
943
+ if (Object.prototype.toString.call(value) === "[object WebAssembly.Memory]") {
944
+ pending.push(value.buffer);
945
+ continue;
946
+ }
947
+ if (ArrayBuffer.isView(value)) {
948
+ pending.push(value.buffer);
949
+ continue;
950
+ }
951
+ if (value instanceof Map) for (const [key, entry] of value) pending.push(key, entry);
952
+ if (value instanceof Set) for (const entry of value) pending.push(entry);
953
+ for (const key of Reflect.ownKeys(value)) {
954
+ const property = Object.getOwnPropertyDescriptor(value, key);
955
+ if (property && "value" in property) pending.push(property.value);
956
+ }
957
+ }
958
+ return snapshot2;
959
+ };
436
960
  var resolveDescriptor = (provider, descriptor) => ({
437
961
  ...descriptor,
438
962
  effect: descriptor.effect ?? (descriptor.risk === "read" ? { kind: "none", ordering: "commutative" } : { kind: "emission", ordering: "unknown" }),
@@ -495,27 +1019,19 @@ var scoreActionSearch = (query, action, providerDescription = "") => {
495
1019
  return score;
496
1020
  };
497
1021
  var conflictBetween = (left, right) => {
498
- if (left.kind === "none" || right.kind === "none") return void 0;
499
- const resources = (effect) => [...new Set((effect.resources ?? []).filter(
500
- (resource) => typeof resource === "string" && resource.length > 0
501
- ).map((resource) => resource.slice(0, 256)))].slice(0, 64);
502
- const leftResources = resources(left);
503
- const rightResources = resources(right);
504
- if (leftResources.length === 0 || rightResources.length === 0) {
505
- if (left.ordering === "commutative" && right.ordering === "commutative") return void 0;
506
- return { resources: ["*"], reason: "unknown_resource" };
507
- }
508
- const rightSet = new Set(rightResources);
509
- const overlap = leftResources.filter((resource) => rightSet.has(resource)).sort();
510
- if (overlap.length === 0) return void 0;
511
- if (left.ordering === "commutative" && right.ordering === "commutative") return void 0;
512
- return { resources: overlap, reason: "shared_resource" };
1022
+ return effectConflictsBetween(
1023
+ summarizeEffects([registrationEffect({ label: "left", ...left })]),
1024
+ summarizeEffects([registrationEffect({ label: "right", ...right })])
1025
+ )[0];
513
1026
  };
514
1027
  var ActionRegistry = class {
515
1028
  constructor(toolResultProxy) {
516
1029
  this.toolResultProxy = toolResultProxy;
517
1030
  this.#providerBindings.subscribe(() => this.#speculation?.reset?.());
518
1031
  }
1032
+ #shutdown = new AbortController();
1033
+ #views = /* @__PURE__ */ new WeakMap();
1034
+ #operations;
519
1035
  #providerBindings = new FabricProviderBindings();
520
1036
  #activeEffects = /* @__PURE__ */ new Map();
521
1037
  #unavailable = /* @__PURE__ */ new Map();
@@ -535,6 +1051,7 @@ var ActionRegistry = class {
535
1051
  this.mount(provider, options);
536
1052
  }
537
1053
  mount(provider, options = {}) {
1054
+ if (this.#shutdown.signal.aborted) throw new Error("Fabric registry is closed");
538
1055
  if (!providerNamePattern.test(provider.name)) {
539
1056
  throw new Error(`Invalid Fabric provider name: ${provider.name}`);
540
1057
  }
@@ -572,8 +1089,10 @@ var ActionRegistry = class {
572
1089
  unregister(name) {
573
1090
  return this.#providerBindings.unregister(name);
574
1091
  }
575
- providers() {
576
- return this.#providerBindings.providers().map((provider) => ({ name: provider.name, description: provider.description })).sort((left, right) => left.name.localeCompare(right.name));
1092
+ providers(context) {
1093
+ if (context) this.#scopeContext(context);
1094
+ const visible = context?.capabilityView ? [...new Set(this.#viewAuthority(context.capabilityView).bindings().map((value) => this.#providerBindings.binding(value.providerBindingId)?.provider).filter((provider) => Boolean(provider)))] : this.#providerBindings.providers();
1095
+ return visible.map((provider) => ({ name: provider.name, description: provider.description })).sort((left, right) => left.name.localeCompare(right.name));
577
1096
  }
578
1097
  async inspectCapabilities(requirements, context) {
579
1098
  return this.#resolveCapabilities(requirements, context, false);
@@ -591,6 +1110,7 @@ var ActionRegistry = class {
591
1110
  * the loose declarations stand for that execution.
592
1111
  */
593
1112
  async guestTypeSources(context) {
1113
+ context = this.#scopeContext(context);
594
1114
  const sources = {};
595
1115
  if (context.capabilityView) {
596
1116
  const actions = await this.list({ limit: 1e3 }, context);
@@ -670,8 +1190,9 @@ var ActionRegistry = class {
670
1190
  // declared everywhere (see describe): committed views pin declared
671
1191
  // digests, and a surface activation must never invalidate them.
672
1192
  async listDetailed(request, context) {
1193
+ context = this.#scopeContext(context);
673
1194
  if (context.capabilityView) {
674
- const refs = Object.keys(context.capabilityView.bindings).filter((ref) => !request.provider || ref.startsWith(`${request.provider}.`)).filter((ref) => request.declared || !activeQuarantinedRefNames().has(ref)).sort();
1195
+ const refs = this.#viewAuthority(context.capabilityView).bindings().map((binding) => binding.ref).filter((ref) => !request.provider || ref.startsWith(`${request.provider}.`)).filter((ref) => request.declared || !activeQuarantinedRefNames().has(ref)).sort();
675
1196
  const actions = await Promise.all(refs.map((ref) => this.describe(ref, context)));
676
1197
  const query = request.query?.normalize("NFKC").trim().toLowerCase();
677
1198
  const filtered = actions.filter((action) => !request.namespace || action.namespace === request.namespace).filter(
@@ -683,7 +1204,7 @@ var ActionRegistry = class {
683
1204
  const providers = request.provider ? [this.#requireProvider(request.provider)] : this.#providerBindings.providers();
684
1205
  const lists = await Promise.all(
685
1206
  providers.map(async (provider) => {
686
- const descriptors = await provider.list(request, context);
1207
+ const descriptors = await runAbortable(context.signal, () => this.#providerBindings.trackProvider(provider, () => provider.list(request, context)));
687
1208
  return descriptors.filter(
688
1209
  (descriptor) => request.declared || !activeQuarantinedRefNames().has(`${provider.name}.${descriptor.name}`)
689
1210
  ).map((descriptor) => {
@@ -707,8 +1228,9 @@ var ActionRegistry = class {
707
1228
  return actions;
708
1229
  }
709
1230
  async catalog(context, options = {}) {
1231
+ context = this.#scopeContext(context);
710
1232
  const providers = (context.capabilityView ? [...new Map(
711
- Object.values(context.capabilityView.bindings).flatMap((pinned) => {
1233
+ this.#viewAuthority(context.capabilityView).bindings().flatMap((pinned) => {
712
1234
  const binding = this.#providerBindings.binding(pinned.providerBindingId);
713
1235
  return binding ? [[binding.name, binding.provider]] : [];
714
1236
  })
@@ -716,7 +1238,7 @@ var ActionRegistry = class {
716
1238
  const lists = await Promise.all(
717
1239
  providers.map(async (provider) => ({
718
1240
  provider,
719
- actions: context.capabilityView ? await this.list({ provider: provider.name, limit: 1e3 }, context) : (await provider.list({}, context)).filter(
1241
+ actions: context.capabilityView ? await this.list({ provider: provider.name, limit: 1e3 }, context) : (await runAbortable(context.signal, () => this.#providerBindings.trackProvider(provider, () => provider.list({}, context)))).filter(
720
1242
  (descriptor) => !activeQuarantinedRefNames().has(`${provider.name}.${descriptor.name}`)
721
1243
  ).map((descriptor) => resolveDescriptor(provider, descriptor))
722
1244
  }))
@@ -783,6 +1305,7 @@ var ActionRegistry = class {
783
1305
  ).slice(0, Math.max(1, Math.min(limit, 100))).map((entry) => entry.action);
784
1306
  }
785
1307
  async describe(ref, context) {
1308
+ context = this.#scopeContext(context);
786
1309
  if (ref.includes(".")) {
787
1310
  const { provider, actionName, expectedDescriptorHash } = this.#parseRef(
788
1311
  ref,
@@ -805,7 +1328,7 @@ var ActionRegistry = class {
805
1328
  }
806
1329
  if (context.capabilityView) {
807
1330
  const pinned = await Promise.all(
808
- Object.keys(context.capabilityView.bindings).map(
1331
+ this.#viewAuthority(context.capabilityView).bindings().map((binding) => binding.ref).map(
809
1332
  (candidate) => this.describe(candidate, context)
810
1333
  )
811
1334
  );
@@ -823,7 +1346,7 @@ var ActionRegistry = class {
823
1346
  for (const provider of this.#providerBindings.providers()) {
824
1347
  let descriptors;
825
1348
  try {
826
- descriptors = await provider.list({}, context);
1349
+ descriptors = await runAbortable(context.signal, () => this.#providerBindings.trackProvider(provider, () => provider.list({}, context)));
827
1350
  } catch {
828
1351
  continue;
829
1352
  }
@@ -841,14 +1364,16 @@ var ActionRegistry = class {
841
1364
  const repair = repairActionName(declaredNames, ref);
842
1365
  throw new FabricResolutionError(formatUnknownActionMessage(ref, repair.suggestions));
843
1366
  }
844
- async acquireScoped(ref, args, context) {
1367
+ async acquireScoped(ref, args, context, adopt) {
1368
+ context = this.#scopeContext(context);
1369
+ args = snapshotArguments(args);
845
1370
  const { binding, provider, actionName, expectedDescriptorHash } = this.#parseRef(
846
1371
  ref,
847
1372
  context.capabilityView
848
1373
  );
1374
+ context = this.#bindingContext(binding, context);
849
1375
  const endInvocation = this.#providerBindings.beginInvocation(binding.id);
850
1376
  const releaseBinding = this.#providerBindings.retain([binding.id]);
851
- let retentionTransferred = false;
852
1377
  try {
853
1378
  const resolved = await this.#resolveActionDescriptor(
854
1379
  provider,
@@ -861,6 +1386,7 @@ var ActionRegistry = class {
861
1386
  }
862
1387
  const action = resolved.action;
863
1388
  const providerActionName = resolved.repairedFrom === void 0 ? actionName : action.name;
1389
+ const authority = { ref: action.ref, descriptor: actionDescriptorHash(action) };
864
1390
  if (expectedDescriptorHash && actionDescriptorHash(action) !== expectedDescriptorHash) {
865
1391
  throw new FabricResolutionError(`Fabric capability descriptor changed: ${ref}`);
866
1392
  }
@@ -870,6 +1396,9 @@ var ActionRegistry = class {
870
1396
  if (!provider.acquire) {
871
1397
  throw new Error(`Fabric provider does not implement scoped acquisition: ${provider.name}`);
872
1398
  }
1399
+ if (context.authorize) {
1400
+ await runAbortable(context.signal, () => context.authorize(structuredClone(action)));
1401
+ }
873
1402
  const effectiveSchema = effectiveInputSchema(
874
1403
  action.ref,
875
1404
  action.inputSchema
@@ -877,7 +1406,7 @@ var ActionRegistry = class {
877
1406
  const catalogInput = repairCatalogInput(action.ref, effectiveSchema, args);
878
1407
  const preparedArgs = provider.prepareArguments ? await runAbortable(
879
1408
  context.signal,
880
- () => provider.prepareArguments(providerActionName, catalogInput.args, context)
1409
+ () => this.#providerBindings.trackProvider(provider, () => provider.prepareArguments(providerActionName, catalogInput.args, context))
881
1410
  ) : catalogInput.args;
882
1411
  if (typeof preparedArgs !== "object" || preparedArgs === null || Array.isArray(preparedArgs)) {
883
1412
  throw new Error(`Argument preparation for ${ref} did not return an object`);
@@ -885,39 +1414,33 @@ var ActionRegistry = class {
885
1414
  const catalog = validateCatalogArgs(
886
1415
  action.ref,
887
1416
  effectiveSchema,
888
- preparedArgs,
1417
+ // Preparation may return provider-held nested references. Detach before
1418
+ // validation and never expose this validated snapshot to policy hooks.
1419
+ snapshotArguments(preparedArgs),
889
1420
  catalogInput.observedUnexpected
890
1421
  );
891
1422
  if (catalog.invalid) throw new Error(`Invalid arguments for ${ref}: ${catalog.invalid}`);
1423
+ if (context.approve) {
1424
+ await runAbortable(context.signal, () => context.approve(structuredClone(action), snapshotArguments(catalog.args)));
1425
+ }
892
1426
  const acquired = await runAbortable(
893
1427
  context.signal,
894
- () => provider.acquire(providerActionName, catalog.args, context)
1428
+ () => this.#runPlanned(binding, providerActionName, authority, "acquire", catalog.args, context, void 0, adopt)
895
1429
  );
1430
+ throwIfAborted(context.signal);
896
1431
  if (!acquired || typeof acquired.dispose !== "function") {
897
1432
  throw new Error(`Scoped acquisition ${ref} did not return a disposer`);
898
1433
  }
899
- let disposal;
900
- retentionTransferred = true;
901
- return {
902
- value: acquired.value,
903
- dispose: () => {
904
- disposal ??= (async () => {
905
- try {
906
- await acquired.dispose();
907
- } finally {
908
- await releaseBinding();
909
- }
910
- })();
911
- return disposal;
912
- }
913
- };
1434
+ return { value: acquired.value, dispose: acquired.dispose };
914
1435
  } finally {
915
- await endInvocation().catch(() => void 0);
916
- if (!retentionTransferred) await releaseBinding().catch(() => void 0);
1436
+ void endInvocation().catch(() => void 0);
1437
+ void releaseBinding().catch(() => void 0);
917
1438
  }
918
1439
  }
919
1440
  async invoke(ref, args, context) {
920
- const traceOperation = context.traceOperation ?? context.trace?.issueCall(ref, args);
1441
+ context = this.#scopeContext(context);
1442
+ args = snapshotArguments(args);
1443
+ const traceOperation = context.traceOperation ?? context.trace?.issueCall(ref, snapshotArguments(args));
921
1444
  let failureStage = "resolve";
922
1445
  let audit;
923
1446
  let invocationActive = false;
@@ -927,6 +1450,7 @@ var ActionRegistry = class {
927
1450
  ref,
928
1451
  context.capabilityView
929
1452
  );
1453
+ context = this.#bindingContext(binding, context);
930
1454
  endBindingInvocation = this.#providerBindings.beginInvocation(binding.id);
931
1455
  const resolved = await this.#resolveActionDescriptor(
932
1456
  provider,
@@ -939,6 +1463,7 @@ var ActionRegistry = class {
939
1463
  }
940
1464
  const action = resolved.action;
941
1465
  const providerActionName = resolved.repairedFrom === void 0 ? actionName : action.name;
1466
+ const authority = { ref: action.ref, descriptor: actionDescriptorHash(action) };
942
1467
  if (expectedDescriptorHash && actionDescriptorHash(action) !== expectedDescriptorHash) {
943
1468
  throw new FabricResolutionError(`Fabric capability descriptor changed: ${ref}`);
944
1469
  }
@@ -950,7 +1475,7 @@ var ActionRegistry = class {
950
1475
  );
951
1476
  }
952
1477
  if (context.authorize) {
953
- await runAbortable(context.signal, () => context.authorize(action));
1478
+ await runAbortable(context.signal, () => context.authorize(structuredClone(action)));
954
1479
  }
955
1480
  failureStage = "prepare";
956
1481
  const effectiveSchema = effectiveInputSchema(
@@ -960,7 +1485,7 @@ var ActionRegistry = class {
960
1485
  const catalogInput = repairCatalogInput(action.ref, effectiveSchema, args);
961
1486
  const preparedArgs = provider.prepareArguments ? await runAbortable(
962
1487
  context.signal,
963
- () => provider.prepareArguments(providerActionName, catalogInput.args, context)
1488
+ () => this.#providerBindings.trackProvider(provider, () => provider.prepareArguments(providerActionName, catalogInput.args, context))
964
1489
  ) : catalogInput.args;
965
1490
  if (typeof preparedArgs !== "object" || preparedArgs === null || Array.isArray(preparedArgs)) {
966
1491
  throw new FabricTraceSafeError(`Argument preparation for ${ref} did not return an object`);
@@ -969,11 +1494,13 @@ var ActionRegistry = class {
969
1494
  const catalog = validateCatalogArgs(
970
1495
  action.ref,
971
1496
  effectiveSchema,
972
- preparedArgs,
1497
+ // Preparation may return provider-held nested references. Detach before
1498
+ // validation and never expose this validated snapshot to policy hooks.
1499
+ snapshotArguments(preparedArgs),
973
1500
  catalogInput.observedUnexpected
974
1501
  );
975
- traceOperation?.prepared(catalog.args);
976
- if (catalog.normalization) traceOperation?.normalized(catalog.normalization);
1502
+ traceOperation?.prepared(snapshotArguments(catalog.args));
1503
+ if (catalog.normalization) traceOperation?.normalized(structuredClone(catalog.normalization));
977
1504
  if (catalog.invalid) {
978
1505
  const declaredSchema = action.inputSchema;
979
1506
  const declaredProperties = typeof declaredSchema === "object" && declaredSchema !== null && !Array.isArray(declaredSchema) && typeof declaredSchema.properties === "object" && declaredSchema.properties !== null ? declaredSchema.properties : void 0;
@@ -1007,7 +1534,7 @@ var ActionRegistry = class {
1007
1534
  throw new FabricTraceSafeError(`Invalid arguments for ${ref}: ${catalog.invalid}`);
1008
1535
  }
1009
1536
  failureStage = "approve";
1010
- await runAbortable(context.signal, () => context.approve(action, catalog.args));
1537
+ await runAbortable(context.signal, () => context.approve(structuredClone(action), snapshotArguments(catalog.args)));
1011
1538
  failureStage = "invoke";
1012
1539
  const nestedToolCallId = `${NESTED_TOOL_CALL_ID_PREFIX}${randomUUID2()}`;
1013
1540
  const effect = action.effect;
@@ -1052,39 +1579,39 @@ var ActionRegistry = class {
1052
1579
  this.#activeEffects.set(nestedToolCallId, { ref, effect });
1053
1580
  let servedFromSpeculation = false;
1054
1581
  let providerValue;
1055
- if (this.#speculation && effect.kind === "none") {
1056
- const served = await runAbortable(context.signal, () => this.#speculation.tryServe(context.parentToolCallId, ref, catalog.args, binding.id));
1057
- if (served.hit) {
1058
- servedFromSpeculation = true;
1059
- activeAudit.speculated = true;
1060
- providerValue = served.value;
1061
- if (served.replay.updatedArgs !== void 0) {
1062
- const replayedPreview = previewArgs(ref, served.replay.updatedArgs);
1063
- activeAudit.args = boundedPreviewValue(
1064
- replayedPreview,
1065
- MAX_AUDIT_VALUE_CHARS
1066
- );
1067
- traceOperation?.prepared(served.replay.updatedArgs);
1068
- context.observeInvocation?.({
1069
- type: "call_args",
1070
- callId: nestedToolCallId,
1071
- args: replayedPreview
1072
- });
1073
- }
1074
- if (served.replay.media?.length) {
1075
- activeAudit.media = [...activeAudit.media ?? [], ...served.replay.media];
1076
- if (served.replay.mediaNote) activeAudit.mediaNote = served.replay.mediaNote;
1077
- }
1078
- if (served.replay.preview !== void 0) activeAudit.preview = served.replay.preview;
1079
- }
1080
- }
1081
1582
  let providerInvoked = false;
1082
1583
  try {
1584
+ if (this.#speculation && action.risk === "read" && effect.kind === "none") {
1585
+ const served = await runAbortable(context.signal, () => this.#speculation.tryServe(context.parentToolCallId, ref, snapshotArguments(catalog.args), JSON.stringify([binding.id, authority.descriptor, context.capabilityView?.id ?? null])));
1586
+ if (served.hit) {
1587
+ providerValue = await runAbortable(context.signal, () => this.#runPlanned(binding, providerActionName, authority, "replay", catalog.args, context, served.value));
1588
+ servedFromSpeculation = true;
1589
+ activeAudit.speculated = true;
1590
+ if (served.replay.updatedArgs !== void 0) {
1591
+ const replayedPreview = previewArgs(ref, served.replay.updatedArgs);
1592
+ activeAudit.args = boundedPreviewValue(
1593
+ replayedPreview,
1594
+ MAX_AUDIT_VALUE_CHARS
1595
+ );
1596
+ traceOperation?.prepared(snapshotArguments(served.replay.updatedArgs));
1597
+ context.observeInvocation?.({
1598
+ type: "call_args",
1599
+ callId: nestedToolCallId,
1600
+ args: replayedPreview
1601
+ });
1602
+ }
1603
+ if (served.replay.media?.length) {
1604
+ activeAudit.media = [...activeAudit.media ?? [], ...served.replay.media];
1605
+ if (served.replay.mediaNote) activeAudit.mediaNote = served.replay.mediaNote;
1606
+ }
1607
+ if (served.replay.preview !== void 0) activeAudit.preview = served.replay.preview;
1608
+ }
1609
+ }
1083
1610
  if (!servedFromSpeculation) {
1084
1611
  providerInvoked = true;
1085
1612
  providerValue = await runAbortable(
1086
1613
  context.signal,
1087
- () => provider.invoke(providerActionName, catalog.args, {
1614
+ () => this.#runPlanned(binding, providerActionName, authority, "invoke", catalog.args, {
1088
1615
  ...context,
1089
1616
  nestedToolCallId,
1090
1617
  update(message) {
@@ -1118,7 +1645,7 @@ var ActionRegistry = class {
1118
1645
  updatedPreview,
1119
1646
  MAX_AUDIT_VALUE_CHARS
1120
1647
  );
1121
- traceOperation?.prepared(updatedArgs);
1648
+ traceOperation?.prepared(snapshotArguments(updatedArgs));
1122
1649
  context.observeInvocation?.({
1123
1650
  type: "call_args",
1124
1651
  callId: nestedToolCallId,
@@ -1129,16 +1656,18 @@ var ActionRegistry = class {
1129
1656
  if (!invocationActive) return;
1130
1657
  activeAudit.preview = preview;
1131
1658
  }
1659
+ }).finally(() => {
1660
+ if (effect.kind !== "none") this.#speculation?.bumpEpoch();
1661
+ this.#activeEffects.delete(nestedToolCallId);
1132
1662
  })
1133
1663
  );
1134
1664
  }
1135
1665
  } finally {
1136
- if (providerInvoked && effect.kind !== "none") this.#speculation?.bumpEpoch();
1137
- this.#activeEffects.delete(nestedToolCallId);
1666
+ if (!providerInvoked) this.#activeEffects.delete(nestedToolCallId);
1138
1667
  }
1139
1668
  const value = this.toolResultProxy ? await runAbortable(context.signal, () => this.toolResultProxy.proxy({
1140
1669
  action,
1141
- args: catalog.args,
1670
+ args: snapshotArguments(catalog.args),
1142
1671
  toolCallId: nestedToolCallId,
1143
1672
  value: providerValue,
1144
1673
  ...context.signal ? { signal: context.signal } : {}
@@ -1167,6 +1696,7 @@ var ActionRegistry = class {
1167
1696
  } else {
1168
1697
  traceOperation?.succeed(bounded.value, { resultTruncated: bounded.truncated });
1169
1698
  }
1699
+ throwIfAborted(context.signal);
1170
1700
  return bounded.value;
1171
1701
  } catch (error) {
1172
1702
  const message = error instanceof Error ? error.message : String(error);
@@ -1186,7 +1716,7 @@ var ActionRegistry = class {
1186
1716
  } finally {
1187
1717
  invocationActive = false;
1188
1718
  if (audit) audit.endedAt ??= Date.now();
1189
- await endBindingInvocation?.().catch(() => void 0);
1719
+ void endBindingInvocation?.().catch(() => void 0);
1190
1720
  }
1191
1721
  }
1192
1722
  /**
@@ -1205,11 +1735,14 @@ var ActionRegistry = class {
1205
1735
  async speculate(ref, args, context, replay) {
1206
1736
  if (!this.#speculationEligibility) return void 0;
1207
1737
  try {
1738
+ context = this.#scopeContext(context);
1739
+ args = snapshotArguments(args);
1208
1740
  const { binding, provider, actionName, expectedDescriptorHash } = this.#parseRef(
1209
1741
  ref,
1210
1742
  context.capabilityView
1211
1743
  );
1212
- const descriptor = await runAbortable(context.signal, () => provider.describe(actionName, context));
1744
+ context = this.#bindingContext(binding, context);
1745
+ const descriptor = await runAbortable(context.signal, () => this.#providerBindings.trackProvider(provider, () => provider.describe(actionName, context)));
1213
1746
  if (!descriptor) return void 0;
1214
1747
  const action = resolveDescriptor(provider, descriptor);
1215
1748
  if (expectedDescriptorHash && actionDescriptorHash(action) !== expectedDescriptorHash) {
@@ -1218,54 +1751,52 @@ var ActionRegistry = class {
1218
1751
  if (isActiveQuarantine(provider.name, actionName, descriptor.inputSchema)) {
1219
1752
  return void 0;
1220
1753
  }
1221
- if (!this.#speculationEligibility(action)) return void 0;
1754
+ const authority = { ref: action.ref, descriptor: actionDescriptorHash(action) };
1755
+ if (action.risk !== "read" || action.effect?.kind !== "none" || !this.#speculationEligibility(structuredClone(action))) return void 0;
1222
1756
  const effectiveSchema = effectiveInputSchema(
1223
1757
  action.ref,
1224
1758
  action.inputSchema
1225
1759
  );
1226
1760
  const catalogInput = applyActiveArgRepairs(action.ref, args, effectiveSchema);
1227
- const preparedArgs = provider.prepareArguments ? await runAbortable(context.signal, () => provider.prepareArguments(actionName, catalogInput, context)) : catalogInput;
1761
+ const preparedArgs = provider.prepareArguments ? await runAbortable(context.signal, () => this.#providerBindings.trackProvider(provider, () => provider.prepareArguments(action.name, catalogInput, context))) : catalogInput;
1228
1762
  if (typeof preparedArgs !== "object" || preparedArgs === null || Array.isArray(preparedArgs)) {
1229
1763
  return void 0;
1230
1764
  }
1231
1765
  const repairedArgs = normalizeActiveArguments(
1232
1766
  action.ref,
1233
1767
  effectiveSchema,
1234
- applyActiveArgRepairs(action.ref, preparedArgs, effectiveSchema)
1768
+ applyActiveArgRepairs(action.ref, snapshotArguments(preparedArgs), effectiveSchema)
1235
1769
  ).args;
1236
1770
  if (validationMessage(effectiveSchema, repairedArgs)) return void 0;
1237
1771
  const nestedToolCallId = `${NESTED_TOOL_CALL_ID_PREFIX}spec-${randomUUID2()}`;
1772
+ const execute = await this.#preparePlanned(binding, action.name, authority, "speculate", repairedArgs, this.#bindingContext(binding, {
1773
+ ...context,
1774
+ nestedToolCallId,
1775
+ update() {
1776
+ },
1777
+ activity() {
1778
+ },
1779
+ attachMedia(blocks, note) {
1780
+ replay.media = [...replay.media ?? [], ...blocks];
1781
+ if (note) replay.mediaNote = note;
1782
+ },
1783
+ updateArguments(updatedArgs) {
1784
+ replay.updatedArgs = updatedArgs;
1785
+ },
1786
+ attachPreview(preview) {
1787
+ replay.preview = preview;
1788
+ }
1789
+ }));
1238
1790
  return {
1239
- preparedArgs: repairedArgs,
1240
- bindingToken: binding.id,
1791
+ get preparedArgs() {
1792
+ return snapshotArguments(repairedArgs);
1793
+ },
1794
+ bindingToken: JSON.stringify([binding.id, authority.descriptor, context.capabilityView?.id ?? null]),
1241
1795
  execute: async (signal) => {
1242
- const endBindingInvocation = this.#providerBindings.beginInvocation(binding.id);
1243
- try {
1244
- return await runAbortable(
1245
- signal,
1246
- () => provider.invoke(actionName, repairedArgs, {
1247
- ...context,
1248
- signal,
1249
- nestedToolCallId,
1250
- update() {
1251
- },
1252
- activity() {
1253
- },
1254
- attachMedia(blocks, note) {
1255
- replay.media = [...replay.media ?? [], ...blocks];
1256
- if (note) replay.mediaNote = note;
1257
- },
1258
- updateArguments(updatedArgs) {
1259
- replay.updatedArgs = updatedArgs;
1260
- },
1261
- attachPreview(preview) {
1262
- replay.preview = preview;
1263
- }
1264
- })
1265
- );
1266
- } finally {
1267
- await endBindingInvocation().catch(() => void 0);
1268
- }
1796
+ const combined = AbortSignal.any([context.signal, ...signal ? [signal] : []]);
1797
+ const actual = execute(combined);
1798
+ void actual.catch(() => void 0);
1799
+ return runAbortable(combined, () => actual);
1269
1800
  }
1270
1801
  };
1271
1802
  } catch {
@@ -1278,14 +1809,36 @@ var ActionRegistry = class {
1278
1809
  this.#providerBindings.entries().map((binding) => binding.provider)
1279
1810
  );
1280
1811
  const finalizers = [...providers].flatMap(
1281
- (provider) => provider.invocationEnded ? [Promise.resolve().then(() => provider.invocationEnded(parentToolCallId))] : []
1812
+ (provider) => provider.invocationEnded ? [this.#providerBindings.trackProvider(provider, () => provider.invocationEnded(parentToolCallId), true)] : []
1282
1813
  );
1283
1814
  await settleWithin(finalizers, timeoutMs);
1284
1815
  }
1816
+ /** Revocation is distinct from rolling withdrawal: pinned old generations may
1817
+ * survive retirement, but revoked bindings admit no further work. */
1818
+ revokeProvider(name) {
1819
+ const binding = this.#providerBindings.current(name);
1820
+ if (binding) this.#providerBindings.revoke(binding.id);
1821
+ }
1822
+ providerStatus() {
1823
+ return this.#providerBindings.entries().map((binding) => ({
1824
+ name: binding.name,
1825
+ generation: binding.generation,
1826
+ state: binding.state,
1827
+ inFlight: binding.inFlight,
1828
+ revoked: this.#providerBindings.signal(binding.id).aborted,
1829
+ ...binding.closeError ? { error: binding.closeError } : {}
1830
+ }));
1831
+ }
1285
1832
  async close(excludedProviderNames = /* @__PURE__ */ new Set()) {
1286
- await this.#providerBindings.close(excludedProviderNames);
1833
+ this.#shutdown.abort(new Error("Fabric registry closed"));
1834
+ try {
1835
+ if (this.#operations) await (await this.#operations).close();
1836
+ } finally {
1837
+ await this.#providerBindings.close(excludedProviderNames);
1838
+ }
1287
1839
  }
1288
1840
  async #resolveCapabilities(requirements, context, retain) {
1841
+ context = this.#scopeContext(context);
1289
1842
  const normalized = /* @__PURE__ */ new Map();
1290
1843
  for (const requirement of requirements) {
1291
1844
  const ref = (typeof requirement === "string" ? requirement : requirement.ref).trim();
@@ -1305,15 +1858,16 @@ var ActionRegistry = class {
1305
1858
  ([left], [right]) => left.localeCompare(right)
1306
1859
  )) {
1307
1860
  try {
1308
- const { binding, provider, actionName } = this.#parseRef(ref);
1861
+ const { binding, provider, actionName, expectedDescriptorHash } = this.#parseRef(ref, context.capabilityView);
1309
1862
  const release = this.#providerBindings.retain([binding.id]);
1310
1863
  temporaryReleases.push(release);
1311
1864
  const descriptor = await runAbortable(
1312
1865
  context.signal,
1313
- () => provider.describe(actionName, context)
1866
+ () => this.#providerBindings.trackProvider(provider, () => provider.describe(actionName, context))
1314
1867
  );
1315
1868
  if (!descriptor) throw new FabricResolutionError(`Unknown Fabric action: ${ref}`);
1316
1869
  const action = resolveDescriptor(provider, descriptor);
1870
+ if (expectedDescriptorHash && actionDescriptorHash(action) !== expectedDescriptorHash) throw new FabricResolutionError(`Committed capability drifted: ${ref}`);
1317
1871
  resolved.set(ref, {
1318
1872
  ref,
1319
1873
  provider: provider.name,
@@ -1328,12 +1882,16 @@ var ActionRegistry = class {
1328
1882
  }
1329
1883
  let view;
1330
1884
  if (missing.length === 0) {
1331
- const bindings = Object.fromEntries(resolved);
1885
+ throwIfAborted(context.signal);
1332
1886
  const values = [...resolved.values()];
1887
+ const authority = context.capabilityView ? this.#viewAuthority(context.capabilityView).derive(values) : CapabilityAuthority.issue(values);
1888
+ if (!authority.active) throw new FabricResolutionError("Fabric capability view is unissued, released, or revoked");
1889
+ const bindings = Object.fromEntries(authority.bindings().map((value) => [value.ref, value]));
1333
1890
  if (retain) permanentRelease = this.#providerBindings.retain(
1334
1891
  values.map((binding) => binding.providerBindingId)
1335
1892
  );
1336
- view = {
1893
+ for (const value of Object.values(bindings)) Object.freeze(value);
1894
+ view = Object.freeze({
1337
1895
  id: randomUUID2(),
1338
1896
  digest: descriptorHash(values),
1339
1897
  semanticDigest: descriptorHash(
@@ -1343,8 +1901,20 @@ var ActionRegistry = class {
1343
1901
  descriptorHash: hash
1344
1902
  }))
1345
1903
  ),
1346
- bindings
1904
+ bindings: Object.freeze(bindings)
1905
+ });
1906
+ const controller = new AbortController();
1907
+ const parent = context.capabilityView ? this.#requireView(context.capabilityView) : void 0;
1908
+ const signal = AbortSignal.any([this.#shutdown.signal, controller.signal, ...parent ? [parent] : []]);
1909
+ this.#views.set(view, { controller, signal, authority });
1910
+ const revoked = () => {
1911
+ authority.release();
1912
+ const release = permanentRelease;
1913
+ permanentRelease = void 0;
1914
+ void release?.().catch(() => void 0);
1347
1915
  };
1916
+ signal.addEventListener("abort", revoked, { once: true });
1917
+ if (signal.aborted) revoked();
1348
1918
  }
1349
1919
  return {
1350
1920
  satisfied: missing.length === 0,
@@ -1354,6 +1924,7 @@ var ActionRegistry = class {
1354
1924
  release: async () => {
1355
1925
  const release = permanentRelease;
1356
1926
  permanentRelease = void 0;
1927
+ if (view) this.#views.get(view)?.controller.abort(new Error("Fabric capability view released"));
1357
1928
  await release?.();
1358
1929
  }
1359
1930
  };
@@ -1363,7 +1934,7 @@ var ActionRegistry = class {
1363
1934
  }
1364
1935
  async #declaredActionNames(provider, context) {
1365
1936
  try {
1366
- const descriptors = await runAbortable(context.signal, () => provider.list({}, context));
1937
+ const descriptors = await runAbortable(context.signal, () => this.#providerBindings.trackProvider(provider, () => provider.list({}, context)));
1367
1938
  return descriptors.map((descriptor) => descriptor.name);
1368
1939
  } catch {
1369
1940
  return [];
@@ -1376,12 +1947,13 @@ var ActionRegistry = class {
1376
1947
  async #resolveActionDescriptor(provider, actionName, context, allowRepair) {
1377
1948
  const descriptor = await runAbortable(
1378
1949
  context.signal,
1379
- () => provider.describe(actionName, context)
1950
+ () => this.#providerBindings.trackProvider(provider, () => provider.describe(actionName, context))
1380
1951
  );
1381
1952
  if (descriptor && !isActiveQuarantine(provider.name, actionName, descriptor.inputSchema)) {
1382
1953
  return {
1383
1954
  action: resolveDescriptor(provider, descriptor),
1384
- suggestions: []
1955
+ suggestions: [],
1956
+ ...descriptor.name !== actionName ? { repairedFrom: actionName } : {}
1385
1957
  };
1386
1958
  }
1387
1959
  if (!allowRepair) return { suggestions: [] };
@@ -1392,7 +1964,7 @@ var ActionRegistry = class {
1392
1964
  if (catalogName !== actionName) {
1393
1965
  const catalogDescriptor = await runAbortable(
1394
1966
  context.signal,
1395
- () => provider.describe(catalogName, context)
1967
+ () => this.#providerBindings.trackProvider(provider, () => provider.describe(catalogName, context))
1396
1968
  );
1397
1969
  if (catalogDescriptor) {
1398
1970
  return {
@@ -1410,7 +1982,7 @@ var ActionRegistry = class {
1410
1982
  });
1411
1983
  const repairedDescriptor = await runAbortable(
1412
1984
  context.signal,
1413
- () => provider.describe(repair.repaired, context)
1985
+ () => this.#providerBindings.trackProvider(provider, () => provider.describe(repair.repaired, context))
1414
1986
  );
1415
1987
  if (repairedDescriptor) {
1416
1988
  return {
@@ -1428,17 +2000,18 @@ var ActionRegistry = class {
1428
2000
  };
1429
2001
  }
1430
2002
  #parseRef(ref, view) {
2003
+ if (view) this.#requireView(view);
1431
2004
  const separator = ref.indexOf(".");
1432
2005
  if (separator <= 0 || separator === ref.length - 1) {
1433
2006
  throw new Error(`Fabric action references must use provider.action: ${ref}`);
1434
2007
  }
1435
2008
  const providerName = ref.slice(0, separator);
1436
- const pinned = view?.bindings[ref];
2009
+ const pinned = view ? this.#viewAuthority(view).resolve(ref) : void 0;
1437
2010
  if (view && !pinned) {
1438
2011
  throw new FabricResolutionError(`Fabric capability is outside the committed view: ${ref}`);
1439
2012
  }
1440
2013
  const binding = pinned ? this.#providerBindings.binding(pinned.providerBindingId) : this.#providerBindings.current(providerName);
1441
- if (!binding || binding.name !== providerName) {
2014
+ if (!binding || binding.name !== providerName || pinned && (pinned.generation !== binding.generation || pinned.provider !== providerName || pinned.ref !== ref)) {
1442
2015
  if (pinned) {
1443
2016
  throw new FabricResolutionError(
1444
2017
  `Fabric capability binding is no longer available: ${ref} (${pinned.providerBindingId})`
@@ -1454,6 +2027,50 @@ var ActionRegistry = class {
1454
2027
  ...pinned ? { expectedDescriptorHash: pinned.descriptorHash } : {}
1455
2028
  };
1456
2029
  }
2030
+ #requireView(view) {
2031
+ const owned = this.#views.get(view);
2032
+ if (!owned || owned.signal.aborted || !owned.authority.active) throw new FabricResolutionError("Fabric capability view is unissued, released, or revoked");
2033
+ return owned.signal;
2034
+ }
2035
+ #viewAuthority(view) {
2036
+ this.#requireView(view);
2037
+ return this.#views.get(view).authority;
2038
+ }
2039
+ #scopeContext(context) {
2040
+ const view = context.capabilityView ? this.#requireView(context.capabilityView) : void 0;
2041
+ throwIfAborted(context.signal);
2042
+ if (this.#shutdown.signal.aborted) throw new FabricResolutionError("Fabric registry is closed");
2043
+ return { ...context, signal: AbortSignal.any([this.#shutdown.signal, ...context.signal ? [context.signal] : [], ...view ? [view] : []]) };
2044
+ }
2045
+ #bindingContext(binding, context) {
2046
+ return { ...context, signal: AbortSignal.any([this.#providerBindings.signal(binding.id), ...context.signal ? [context.signal] : []]) };
2047
+ }
2048
+ async #preparePlanned(binding, actionName, authority, mode, args, context, replayValue, adopt) {
2049
+ const payload = snapshotArguments(args);
2050
+ this.#operations ??= import("../core/provider-operations.js").then(({ ProviderOperations }) => new ProviderOperations(this.#providerBindings));
2051
+ return (await this.#operations).prepare({
2052
+ binding,
2053
+ action: actionName,
2054
+ ...authority,
2055
+ mode,
2056
+ args: payload,
2057
+ context,
2058
+ replayValue,
2059
+ ...adopt ? { adopt } : {},
2060
+ observe: async (observedContext) => {
2061
+ const descriptor = await binding.provider.describe(actionName, observedContext);
2062
+ if (!descriptor) return { ref: "", descriptor: "" };
2063
+ const action = resolveDescriptor(binding.provider, descriptor);
2064
+ return { ref: action.ref, descriptor: actionDescriptorHash(action) };
2065
+ }
2066
+ });
2067
+ }
2068
+ #runPlanned(binding, actionName, authority, mode, args, context, replayValue, adopt) {
2069
+ return this.#providerBindings.track(binding.id, async () => {
2070
+ const execute = await this.#preparePlanned(binding, actionName, authority, mode, args, context, replayValue, adopt);
2071
+ return execute();
2072
+ });
2073
+ }
1457
2074
  #requireProvider(name) {
1458
2075
  const provider = this.#providerBindings.current(name)?.provider;
1459
2076
  if (provider) return provider;
@@ -1471,10 +2088,17 @@ var ActionRegistry = class {
1471
2088
  };
1472
2089
 
1473
2090
  export {
2091
+ FabricComponentIndependenceError,
2092
+ trackedRegistration,
2093
+ registrationEffect,
2094
+ actionEffect,
2095
+ summarizeEffects,
2096
+ effectConflictsBetween,
2097
+ compareEffectInfo,
1474
2098
  repairActionName,
1475
2099
  fabricActionListLimit,
1476
2100
  NESTED_TOOL_CALL_ID_PREFIX,
1477
2101
  scoreActionSearch,
1478
2102
  ActionRegistry
1479
2103
  };
1480
- //# sourceMappingURL=chunk-3TXOQ5MG.js.map
2104
+ //# sourceMappingURL=chunk-3CJETB4S.js.map