open-multi-agent-kit 1.0.0 → 1.2.2

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 (622) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/README.md +2 -2
  3. package/dist/approval-api.d.ts +5 -0
  4. package/dist/approval-api.d.ts.map +1 -0
  5. package/dist/approval-api.js +5 -0
  6. package/dist/approval-api.js.map +1 -0
  7. package/dist/cli/help.d.ts.map +1 -1
  8. package/dist/cli/help.js +1 -0
  9. package/dist/cli/help.js.map +1 -1
  10. package/dist/cli/session-picker.d.ts +2 -2
  11. package/dist/cli/session-picker.d.ts.map +1 -1
  12. package/dist/cli/session-picker.js.map +1 -1
  13. package/dist/commands/verified-run-cli.d.ts.map +1 -1
  14. package/dist/commands/verified-run-cli.js +69 -22
  15. package/dist/commands/verified-run-cli.js.map +1 -1
  16. package/dist/commands/verified-run-signal.d.ts +3 -0
  17. package/dist/commands/verified-run-signal.d.ts.map +1 -0
  18. package/dist/commands/verified-run-signal.js +15 -0
  19. package/dist/commands/verified-run-signal.js.map +1 -0
  20. package/dist/coordination/awareness.d.ts +32 -0
  21. package/dist/coordination/awareness.d.ts.map +1 -0
  22. package/dist/coordination/awareness.js +55 -0
  23. package/dist/coordination/awareness.js.map +1 -0
  24. package/dist/coordination/broker.d.ts +79 -0
  25. package/dist/coordination/broker.d.ts.map +1 -0
  26. package/dist/coordination/broker.js +202 -0
  27. package/dist/coordination/broker.js.map +1 -0
  28. package/dist/coordination/index.d.ts +16 -0
  29. package/dist/coordination/index.d.ts.map +1 -0
  30. package/dist/coordination/index.js +16 -0
  31. package/dist/coordination/index.js.map +1 -0
  32. package/dist/coordination/integration.d.ts +59 -0
  33. package/dist/coordination/integration.d.ts.map +1 -0
  34. package/dist/coordination/integration.js +126 -0
  35. package/dist/coordination/integration.js.map +1 -0
  36. package/dist/coordination/operation.d.ts +107 -0
  37. package/dist/coordination/operation.d.ts.map +1 -0
  38. package/dist/coordination/operation.js +231 -0
  39. package/dist/coordination/operation.js.map +1 -0
  40. package/dist/coordination/resource.d.ts +33 -0
  41. package/dist/coordination/resource.d.ts.map +1 -0
  42. package/dist/coordination/resource.js +95 -0
  43. package/dist/coordination/resource.js.map +1 -0
  44. package/dist/coordination/session.d.ts +74 -0
  45. package/dist/coordination/session.d.ts.map +1 -0
  46. package/dist/coordination/session.js +143 -0
  47. package/dist/coordination/session.js.map +1 -0
  48. package/dist/coordination/types.d.ts +68 -0
  49. package/dist/coordination/types.d.ts.map +1 -0
  50. package/dist/coordination/types.js +26 -0
  51. package/dist/coordination/types.js.map +1 -0
  52. package/dist/core/adaptorch-bridge.d.ts +1 -1
  53. package/dist/core/adaptorch-bridge.d.ts.map +1 -1
  54. package/dist/core/adaptorch-bridge.js +1 -1
  55. package/dist/core/adaptorch-bridge.js.map +1 -1
  56. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  57. package/dist/core/agent-session-runtime.js +16 -16
  58. package/dist/core/agent-session-runtime.js.map +1 -1
  59. package/dist/core/agent-session.d.ts.map +1 -1
  60. package/dist/core/agent-session.js +35 -15
  61. package/dist/core/agent-session.js.map +1 -1
  62. package/dist/core/canonical-json.d.ts +3 -0
  63. package/dist/core/canonical-json.d.ts.map +1 -0
  64. package/dist/core/canonical-json.js +20 -0
  65. package/dist/core/canonical-json.js.map +1 -0
  66. package/dist/core/compaction/compaction.d.ts +7 -3
  67. package/dist/core/compaction/compaction.d.ts.map +1 -1
  68. package/dist/core/compaction/compaction.js +14 -29
  69. package/dist/core/compaction/compaction.js.map +1 -1
  70. package/dist/core/compaction/control-state.d.ts +41 -0
  71. package/dist/core/compaction/control-state.d.ts.map +1 -0
  72. package/dist/core/compaction/control-state.js +85 -0
  73. package/dist/core/compaction/control-state.js.map +1 -0
  74. package/dist/core/compaction/fallback.d.ts +71 -0
  75. package/dist/core/compaction/fallback.d.ts.map +1 -0
  76. package/dist/core/compaction/fallback.js +118 -0
  77. package/dist/core/compaction/fallback.js.map +1 -0
  78. package/dist/core/compaction/index.d.ts +2 -0
  79. package/dist/core/compaction/index.d.ts.map +1 -1
  80. package/dist/core/compaction/index.js +2 -0
  81. package/dist/core/compaction/index.js.map +1 -1
  82. package/dist/core/compaction/model-failover.d.ts +21 -0
  83. package/dist/core/compaction/model-failover.d.ts.map +1 -0
  84. package/dist/core/compaction/model-failover.js +46 -0
  85. package/dist/core/compaction/model-failover.js.map +1 -0
  86. package/dist/core/compaction/session-summary.d.ts +21 -0
  87. package/dist/core/compaction/session-summary.d.ts.map +1 -0
  88. package/dist/core/compaction/session-summary.js +27 -0
  89. package/dist/core/compaction/session-summary.js.map +1 -0
  90. package/dist/core/context-budget-headroom-candidates.d.ts +16 -1
  91. package/dist/core/context-budget-headroom-candidates.d.ts.map +1 -1
  92. package/dist/core/context-budget-headroom-candidates.js +31 -13
  93. package/dist/core/context-budget-headroom-candidates.js.map +1 -1
  94. package/dist/core/context-budget-headroom-types.d.ts +7 -1
  95. package/dist/core/context-budget-headroom-types.d.ts.map +1 -1
  96. package/dist/core/context-budget-headroom-types.js +0 -1
  97. package/dist/core/context-budget-headroom-types.js.map +1 -1
  98. package/dist/core/context-budget-headroom.d.ts +10 -0
  99. package/dist/core/context-budget-headroom.d.ts.map +1 -1
  100. package/dist/core/context-budget-headroom.js +11 -2
  101. package/dist/core/context-budget-headroom.js.map +1 -1
  102. package/dist/core/context-budget-v2-global-pass.d.ts +21 -0
  103. package/dist/core/context-budget-v2-global-pass.d.ts.map +1 -0
  104. package/dist/core/context-budget-v2-global-pass.js +203 -0
  105. package/dist/core/context-budget-v2-global-pass.js.map +1 -0
  106. package/dist/core/context-budget-v2-planned-items.d.ts +12 -0
  107. package/dist/core/context-budget-v2-planned-items.d.ts.map +1 -1
  108. package/dist/core/context-budget-v2-planned-items.js +21 -2
  109. package/dist/core/context-budget-v2-planned-items.js.map +1 -1
  110. package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
  111. package/dist/core/context-budget-v2-planner.js +18 -19
  112. package/dist/core/context-budget-v2-planner.js.map +1 -1
  113. package/dist/core/context-budget-v2-scoring.d.ts +7 -1
  114. package/dist/core/context-budget-v2-scoring.d.ts.map +1 -1
  115. package/dist/core/context-budget-v2-scoring.js.map +1 -1
  116. package/dist/core/context-budget-v2-selection.d.ts +3 -0
  117. package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
  118. package/dist/core/context-budget-v2-selection.js +6 -2
  119. package/dist/core/context-budget-v2-selection.js.map +1 -1
  120. package/dist/core/context-budget-v2-types.d.ts +6 -1
  121. package/dist/core/context-budget-v2-types.d.ts.map +1 -1
  122. package/dist/core/context-budget-v2-types.js +6 -1
  123. package/dist/core/context-budget-v2-types.js.map +1 -1
  124. package/dist/core/export-html/template.js +14 -0
  125. package/dist/core/extensions/index.d.ts +1 -1
  126. package/dist/core/extensions/index.d.ts.map +1 -1
  127. package/dist/core/extensions/index.js.map +1 -1
  128. package/dist/core/extensions/session-lifecycle-types.d.ts +14 -0
  129. package/dist/core/extensions/session-lifecycle-types.d.ts.map +1 -0
  130. package/dist/core/extensions/session-lifecycle-types.js +2 -0
  131. package/dist/core/extensions/session-lifecycle-types.js.map +1 -0
  132. package/dist/core/extensions/types.d.ts +4 -9
  133. package/dist/core/extensions/types.d.ts.map +1 -1
  134. package/dist/core/extensions/types.js.map +1 -1
  135. package/dist/core/http-dispatcher.d.ts.map +1 -1
  136. package/dist/core/http-dispatcher.js +10 -1
  137. package/dist/core/http-dispatcher.js.map +1 -1
  138. package/dist/core/keybindings.d.ts.map +1 -1
  139. package/dist/core/keybindings.js +3 -6
  140. package/dist/core/keybindings.js.map +1 -1
  141. package/dist/core/legacy-resource-policy.d.ts +7 -0
  142. package/dist/core/legacy-resource-policy.d.ts.map +1 -0
  143. package/dist/core/legacy-resource-policy.js +9 -0
  144. package/dist/core/legacy-resource-policy.js.map +1 -0
  145. package/dist/core/mcp/config.d.ts.map +1 -1
  146. package/dist/core/mcp/config.js +17 -3
  147. package/dist/core/mcp/config.js.map +1 -1
  148. package/dist/core/mcp/connection-queue.d.ts +12 -0
  149. package/dist/core/mcp/connection-queue.d.ts.map +1 -0
  150. package/dist/core/mcp/connection-queue.js +46 -0
  151. package/dist/core/mcp/connection-queue.js.map +1 -0
  152. package/dist/core/mcp/manager-runtime.d.ts +55 -0
  153. package/dist/core/mcp/manager-runtime.d.ts.map +1 -0
  154. package/dist/core/mcp/manager-runtime.js +66 -0
  155. package/dist/core/mcp/manager-runtime.js.map +1 -0
  156. package/dist/core/mcp/manager.d.ts +12 -68
  157. package/dist/core/mcp/manager.d.ts.map +1 -1
  158. package/dist/core/mcp/manager.js +33 -113
  159. package/dist/core/mcp/manager.js.map +1 -1
  160. package/dist/core/mcp/protocol.d.ts.map +1 -1
  161. package/dist/core/mcp/protocol.js +70 -40
  162. package/dist/core/mcp/protocol.js.map +1 -1
  163. package/dist/core/package-manager.d.ts +4 -0
  164. package/dist/core/package-manager.d.ts.map +1 -1
  165. package/dist/core/package-manager.js +59 -129
  166. package/dist/core/package-manager.js.map +1 -1
  167. package/dist/core/package-resource-patterns.d.ts +7 -0
  168. package/dist/core/package-resource-patterns.d.ts.map +1 -0
  169. package/dist/core/package-resource-patterns.js +99 -0
  170. package/dist/core/package-resource-patterns.js.map +1 -0
  171. package/dist/core/provider-default-models.d.ts +1 -0
  172. package/dist/core/provider-default-models.d.ts.map +1 -1
  173. package/dist/core/provider-default-models.js +1 -0
  174. package/dist/core/provider-default-models.js.map +1 -1
  175. package/dist/core/provider-display-names.d.ts.map +1 -1
  176. package/dist/core/provider-display-names.js +1 -0
  177. package/dist/core/provider-display-names.js.map +1 -1
  178. package/dist/core/provider-resilience.d.ts +9 -0
  179. package/dist/core/provider-resilience.d.ts.map +1 -1
  180. package/dist/core/provider-resilience.js +15 -0
  181. package/dist/core/provider-resilience.js.map +1 -1
  182. package/dist/core/reasoning-router-resolver.d.ts +7 -0
  183. package/dist/core/reasoning-router-resolver.d.ts.map +1 -1
  184. package/dist/core/reasoning-router-resolver.js +21 -3
  185. package/dist/core/reasoning-router-resolver.js.map +1 -1
  186. package/dist/core/reasoning-router-v4.d.ts +13 -7
  187. package/dist/core/reasoning-router-v4.d.ts.map +1 -1
  188. package/dist/core/reasoning-router-v4.js +8 -5
  189. package/dist/core/reasoning-router-v4.js.map +1 -1
  190. package/dist/core/resource-loader.d.ts.map +1 -1
  191. package/dist/core/resource-loader.js +4 -8
  192. package/dist/core/resource-loader.js.map +1 -1
  193. package/dist/core/run-execution-api.d.ts +8 -1
  194. package/dist/core/run-execution-api.d.ts.map +1 -1
  195. package/dist/core/run-execution-api.js +4 -0
  196. package/dist/core/run-execution-api.js.map +1 -1
  197. package/dist/core/run-journal.d.ts +1 -2
  198. package/dist/core/run-journal.d.ts.map +1 -1
  199. package/dist/core/run-journal.js +2 -19
  200. package/dist/core/run-journal.js.map +1 -1
  201. package/dist/core/session-compaction-service.d.ts +15 -0
  202. package/dist/core/session-compaction-service.d.ts.map +1 -1
  203. package/dist/core/session-compaction-service.js +17 -4
  204. package/dist/core/session-compaction-service.js.map +1 -1
  205. package/dist/core/session-listing.d.ts +51 -0
  206. package/dist/core/session-listing.d.ts.map +1 -0
  207. package/dist/core/session-listing.js +111 -0
  208. package/dist/core/session-listing.js.map +1 -0
  209. package/dist/core/session-manager.d.ts +12 -37
  210. package/dist/core/session-manager.d.ts.map +1 -1
  211. package/dist/core/session-manager.js +12 -118
  212. package/dist/core/session-manager.js.map +1 -1
  213. package/dist/core/session-message-text.d.ts +5 -0
  214. package/dist/core/session-message-text.d.ts.map +1 -0
  215. package/dist/core/session-message-text.js +9 -0
  216. package/dist/core/session-message-text.js.map +1 -0
  217. package/dist/core/skills-catalog-cache.d.ts +2 -0
  218. package/dist/core/skills-catalog-cache.d.ts.map +1 -1
  219. package/dist/core/skills-catalog-cache.js +71 -17
  220. package/dist/core/skills-catalog-cache.js.map +1 -1
  221. package/dist/core/todo-runtime-state.d.ts +12 -0
  222. package/dist/core/todo-runtime-state.d.ts.map +1 -1
  223. package/dist/core/todo-runtime-state.js +23 -0
  224. package/dist/core/todo-runtime-state.js.map +1 -1
  225. package/dist/core/tools/read.d.ts.map +1 -1
  226. package/dist/core/tools/read.js +1 -1
  227. package/dist/core/tools/read.js.map +1 -1
  228. package/dist/core/verified-run/authority-clock.d.ts +3 -0
  229. package/dist/core/verified-run/authority-clock.d.ts.map +1 -0
  230. package/dist/core/verified-run/authority-clock.js +25 -0
  231. package/dist/core/verified-run/authority-clock.js.map +1 -0
  232. package/dist/core/verified-run/authority-errors.d.ts +10 -0
  233. package/dist/core/verified-run/authority-errors.d.ts.map +1 -0
  234. package/dist/core/verified-run/authority-errors.js +17 -0
  235. package/dist/core/verified-run/authority-errors.js.map +1 -0
  236. package/dist/core/verified-run/authority-events.d.ts +126 -0
  237. package/dist/core/verified-run/authority-events.d.ts.map +1 -0
  238. package/dist/core/verified-run/authority-events.js +482 -0
  239. package/dist/core/verified-run/authority-events.js.map +1 -0
  240. package/dist/core/verified-run/authority-journal.d.ts +27 -0
  241. package/dist/core/verified-run/authority-journal.d.ts.map +1 -0
  242. package/dist/core/verified-run/authority-journal.js +83 -0
  243. package/dist/core/verified-run/authority-journal.js.map +1 -0
  244. package/dist/core/verified-run/authority-meaning.d.ts +13 -0
  245. package/dist/core/verified-run/authority-meaning.d.ts.map +1 -0
  246. package/dist/core/verified-run/authority-meaning.js +40 -0
  247. package/dist/core/verified-run/authority-meaning.js.map +1 -0
  248. package/dist/core/verified-run/authority-runtime.d.ts +82 -0
  249. package/dist/core/verified-run/authority-runtime.d.ts.map +1 -0
  250. package/dist/core/verified-run/authority-runtime.js +169 -0
  251. package/dist/core/verified-run/authority-runtime.js.map +1 -0
  252. package/dist/core/verified-run/authority-store.d.ts +204 -0
  253. package/dist/core/verified-run/authority-store.d.ts.map +1 -0
  254. package/dist/core/verified-run/authority-store.js +852 -0
  255. package/dist/core/verified-run/authority-store.js.map +1 -0
  256. package/dist/core/verified-run/broker.d.ts +8 -1
  257. package/dist/core/verified-run/broker.d.ts.map +1 -1
  258. package/dist/core/verified-run/broker.js +94 -90
  259. package/dist/core/verified-run/broker.js.map +1 -1
  260. package/dist/core/verified-run/candidate-policy.d.ts +10 -0
  261. package/dist/core/verified-run/candidate-policy.d.ts.map +1 -0
  262. package/dist/core/verified-run/candidate-policy.js +33 -0
  263. package/dist/core/verified-run/candidate-policy.js.map +1 -0
  264. package/dist/core/verified-run/candidate.d.ts.map +1 -1
  265. package/dist/core/verified-run/candidate.js +5 -10
  266. package/dist/core/verified-run/candidate.js.map +1 -1
  267. package/dist/core/verified-run/coordinator.d.ts +35 -17
  268. package/dist/core/verified-run/coordinator.d.ts.map +1 -1
  269. package/dist/core/verified-run/coordinator.js +111 -57
  270. package/dist/core/verified-run/coordinator.js.map +1 -1
  271. package/dist/core/verified-run/dag-phase.d.ts.map +1 -1
  272. package/dist/core/verified-run/dag-phase.js +1 -1
  273. package/dist/core/verified-run/dag-phase.js.map +1 -1
  274. package/dist/core/verified-run/dag-recovery.d.ts +5 -1
  275. package/dist/core/verified-run/dag-recovery.d.ts.map +1 -1
  276. package/dist/core/verified-run/dag-recovery.js +10 -4
  277. package/dist/core/verified-run/dag-recovery.js.map +1 -1
  278. package/dist/core/verified-run/event-parser.d.ts.map +1 -1
  279. package/dist/core/verified-run/event-parser.js +33 -0
  280. package/dist/core/verified-run/event-parser.js.map +1 -1
  281. package/dist/core/verified-run/evidence-read-projection.d.ts +4 -0
  282. package/dist/core/verified-run/evidence-read-projection.d.ts.map +1 -0
  283. package/dist/core/verified-run/evidence-read-projection.js +27 -0
  284. package/dist/core/verified-run/evidence-read-projection.js.map +1 -0
  285. package/dist/core/verified-run/evidence.d.ts +12 -1
  286. package/dist/core/verified-run/evidence.d.ts.map +1 -1
  287. package/dist/core/verified-run/evidence.js +51 -2
  288. package/dist/core/verified-run/evidence.js.map +1 -1
  289. package/dist/core/verified-run/git-candidate-preflight.d.ts +4 -0
  290. package/dist/core/verified-run/git-candidate-preflight.d.ts.map +1 -0
  291. package/dist/core/verified-run/git-candidate-preflight.js +34 -0
  292. package/dist/core/verified-run/git-candidate-preflight.js.map +1 -0
  293. package/dist/core/verified-run/git-effect-supervisor.d.ts +24 -0
  294. package/dist/core/verified-run/git-effect-supervisor.d.ts.map +1 -0
  295. package/dist/core/verified-run/git-effect-supervisor.js +174 -0
  296. package/dist/core/verified-run/git-effect-supervisor.js.map +1 -0
  297. package/dist/core/verified-run/git-execution.d.ts +27 -0
  298. package/dist/core/verified-run/git-execution.d.ts.map +1 -0
  299. package/dist/core/verified-run/git-execution.js +118 -0
  300. package/dist/core/verified-run/git-execution.js.map +1 -0
  301. package/dist/core/verified-run/git-plumbing.d.ts +37 -0
  302. package/dist/core/verified-run/git-plumbing.d.ts.map +1 -0
  303. package/dist/core/verified-run/git-plumbing.js +171 -0
  304. package/dist/core/verified-run/git-plumbing.js.map +1 -0
  305. package/dist/core/verified-run/git-publication-worker.d.ts +2 -0
  306. package/dist/core/verified-run/git-publication-worker.d.ts.map +1 -0
  307. package/dist/core/verified-run/git-publication-worker.js +54 -0
  308. package/dist/core/verified-run/git-publication-worker.js.map +1 -0
  309. package/dist/core/verified-run/git-sandbox-layout.d.ts +4 -0
  310. package/dist/core/verified-run/git-sandbox-layout.d.ts.map +1 -0
  311. package/dist/core/verified-run/git-sandbox-layout.js +29 -0
  312. package/dist/core/verified-run/git-sandbox-layout.js.map +1 -0
  313. package/dist/core/verified-run/git-worker-protocol.d.ts +19 -0
  314. package/dist/core/verified-run/git-worker-protocol.d.ts.map +1 -0
  315. package/dist/core/verified-run/git-worker-protocol.js +109 -0
  316. package/dist/core/verified-run/git-worker-protocol.js.map +1 -0
  317. package/dist/core/verified-run/git-worker-runtime.d.ts +19 -0
  318. package/dist/core/verified-run/git-worker-runtime.d.ts.map +1 -0
  319. package/dist/core/verified-run/git-worker-runtime.js +74 -0
  320. package/dist/core/verified-run/git-worker-runtime.js.map +1 -0
  321. package/dist/core/verified-run/journal.d.ts +2 -3
  322. package/dist/core/verified-run/journal.d.ts.map +1 -1
  323. package/dist/core/verified-run/journal.js.map +1 -1
  324. package/dist/core/verified-run/namespace-identity.d.ts.map +1 -1
  325. package/dist/core/verified-run/namespace-identity.js +1 -1
  326. package/dist/core/verified-run/namespace-identity.js.map +1 -1
  327. package/dist/core/verified-run/owned-execution.d.ts +10 -1
  328. package/dist/core/verified-run/owned-execution.d.ts.map +1 -1
  329. package/dist/core/verified-run/owned-execution.js +124 -31
  330. package/dist/core/verified-run/owned-execution.js.map +1 -1
  331. package/dist/core/verified-run/phase-context.d.ts +2 -0
  332. package/dist/core/verified-run/phase-context.d.ts.map +1 -1
  333. package/dist/core/verified-run/phase-context.js.map +1 -1
  334. package/dist/core/verified-run/projection.d.ts.map +1 -1
  335. package/dist/core/verified-run/projection.js +51 -1
  336. package/dist/core/verified-run/projection.js.map +1 -1
  337. package/dist/core/verified-run/publish-preflight.d.ts +12 -0
  338. package/dist/core/verified-run/publish-preflight.d.ts.map +1 -0
  339. package/dist/core/verified-run/publish-preflight.js +38 -0
  340. package/dist/core/verified-run/publish-preflight.js.map +1 -0
  341. package/dist/core/verified-run/publish-start.d.ts +5 -0
  342. package/dist/core/verified-run/publish-start.d.ts.map +1 -0
  343. package/dist/core/verified-run/publish-start.js +7 -0
  344. package/dist/core/verified-run/publish-start.js.map +1 -0
  345. package/dist/core/verified-run/recovery-projection.d.ts.map +1 -1
  346. package/dist/core/verified-run/recovery-projection.js +5 -0
  347. package/dist/core/verified-run/recovery-projection.js.map +1 -1
  348. package/dist/core/verified-run/recovery.d.ts +5 -1
  349. package/dist/core/verified-run/recovery.d.ts.map +1 -1
  350. package/dist/core/verified-run/recovery.js +10 -4
  351. package/dist/core/verified-run/recovery.js.map +1 -1
  352. package/dist/core/verified-run/run-plan.d.ts +17 -0
  353. package/dist/core/verified-run/run-plan.d.ts.map +1 -0
  354. package/dist/core/verified-run/run-plan.js +18 -0
  355. package/dist/core/verified-run/run-plan.js.map +1 -0
  356. package/dist/core/verified-run/run-publish-owned.d.ts +6 -0
  357. package/dist/core/verified-run/run-publish-owned.d.ts.map +1 -0
  358. package/dist/core/verified-run/run-publish-owned.js +199 -0
  359. package/dist/core/verified-run/run-publish-owned.js.map +1 -0
  360. package/dist/core/verified-run/run-publish.d.ts +19 -0
  361. package/dist/core/verified-run/run-publish.d.ts.map +1 -0
  362. package/dist/core/verified-run/run-publish.js +210 -0
  363. package/dist/core/verified-run/run-publish.js.map +1 -0
  364. package/dist/core/verified-run/run-status-owned.d.ts +4 -0
  365. package/dist/core/verified-run/run-status-owned.d.ts.map +1 -0
  366. package/dist/core/verified-run/run-status-owned.js +14 -0
  367. package/dist/core/verified-run/run-status-owned.js.map +1 -0
  368. package/dist/core/verified-run/run-status.d.ts +133 -0
  369. package/dist/core/verified-run/run-status.d.ts.map +1 -0
  370. package/dist/core/verified-run/run-status.js +193 -0
  371. package/dist/core/verified-run/run-status.js.map +1 -0
  372. package/dist/core/verified-run/run-types.d.ts +31 -0
  373. package/dist/core/verified-run/run-types.d.ts.map +1 -1
  374. package/dist/core/verified-run/run-types.js.map +1 -1
  375. package/dist/core/verified-run/storage.d.ts.map +1 -1
  376. package/dist/core/verified-run/storage.js +1 -1
  377. package/dist/core/verified-run/storage.js.map +1 -1
  378. package/dist/core/verified-run/supervisor-adapter.d.ts +77 -0
  379. package/dist/core/verified-run/supervisor-adapter.d.ts.map +1 -0
  380. package/dist/core/verified-run/supervisor-adapter.js +164 -0
  381. package/dist/core/verified-run/supervisor-adapter.js.map +1 -0
  382. package/dist/core/verified-run/verification-phase.d.ts.map +1 -1
  383. package/dist/core/verified-run/verification-phase.js +1 -1
  384. package/dist/core/verified-run/verification-phase.js.map +1 -1
  385. package/dist/core/verified-run/writer-phase.d.ts.map +1 -1
  386. package/dist/core/verified-run/writer-phase.js +1 -0
  387. package/dist/core/verified-run/writer-phase.js.map +1 -1
  388. package/dist/core/verified-run/writer-recovery.d.ts +2 -0
  389. package/dist/core/verified-run/writer-recovery.d.ts.map +1 -1
  390. package/dist/core/verified-run/writer-recovery.js +1 -0
  391. package/dist/core/verified-run/writer-recovery.js.map +1 -1
  392. package/dist/core/workload-shard-execution-types.d.ts +4 -1
  393. package/dist/core/workload-shard-execution-types.d.ts.map +1 -1
  394. package/dist/core/workload-shard-execution-types.js.map +1 -1
  395. package/dist/core/workload-shard-executor.d.ts +2 -2
  396. package/dist/core/workload-shard-executor.d.ts.map +1 -1
  397. package/dist/core/workload-shard-executor.js +16 -37
  398. package/dist/core/workload-shard-executor.js.map +1 -1
  399. package/dist/core/workload-shard-frontier.d.ts +5 -0
  400. package/dist/core/workload-shard-frontier.d.ts.map +1 -0
  401. package/dist/core/workload-shard-frontier.js +47 -0
  402. package/dist/core/workload-shard-frontier.js.map +1 -0
  403. package/dist/core/workload-shard-runner.d.ts.map +1 -1
  404. package/dist/core/workload-shard-runner.js +28 -17
  405. package/dist/core/workload-shard-runner.js.map +1 -1
  406. package/dist/index.d.ts +4 -5
  407. package/dist/index.d.ts.map +1 -1
  408. package/dist/index.js +3 -4
  409. package/dist/index.js.map +1 -1
  410. package/dist/main.d.ts.map +1 -1
  411. package/dist/main.js +2 -1
  412. package/dist/main.js.map +1 -1
  413. package/dist/metacognition/bridge-result.d.ts +148 -0
  414. package/dist/metacognition/bridge-result.d.ts.map +1 -0
  415. package/dist/metacognition/bridge-result.js +46 -0
  416. package/dist/metacognition/bridge-result.js.map +1 -0
  417. package/dist/metacognition/calibration-selective.d.ts +78 -0
  418. package/dist/metacognition/calibration-selective.d.ts.map +1 -0
  419. package/dist/metacognition/calibration-selective.js +167 -0
  420. package/dist/metacognition/calibration-selective.js.map +1 -0
  421. package/dist/metacognition/calibration.d.ts +62 -0
  422. package/dist/metacognition/calibration.d.ts.map +1 -0
  423. package/dist/metacognition/calibration.js +122 -0
  424. package/dist/metacognition/calibration.js.map +1 -0
  425. package/dist/metacognition/checkpoint.d.ts +60 -0
  426. package/dist/metacognition/checkpoint.d.ts.map +1 -0
  427. package/dist/metacognition/checkpoint.js +57 -0
  428. package/dist/metacognition/checkpoint.js.map +1 -0
  429. package/dist/metacognition/context7.d.ts +48 -0
  430. package/dist/metacognition/context7.d.ts.map +1 -0
  431. package/dist/metacognition/context7.js +154 -0
  432. package/dist/metacognition/context7.js.map +1 -0
  433. package/dist/metacognition/decision.d.ts +44 -0
  434. package/dist/metacognition/decision.d.ts.map +1 -0
  435. package/dist/metacognition/decision.js +111 -0
  436. package/dist/metacognition/decision.js.map +1 -0
  437. package/dist/metacognition/evaluation.d.ts +73 -0
  438. package/dist/metacognition/evaluation.d.ts.map +1 -0
  439. package/dist/metacognition/evaluation.js +97 -0
  440. package/dist/metacognition/evaluation.js.map +1 -0
  441. package/dist/metacognition/index.d.ts +32 -0
  442. package/dist/metacognition/index.d.ts.map +1 -0
  443. package/dist/metacognition/index.js +32 -0
  444. package/dist/metacognition/index.js.map +1 -0
  445. package/dist/metacognition/knowledge-action.d.ts +43 -0
  446. package/dist/metacognition/knowledge-action.d.ts.map +1 -0
  447. package/dist/metacognition/knowledge-action.js +60 -0
  448. package/dist/metacognition/knowledge-action.js.map +1 -0
  449. package/dist/metacognition/knowledge.d.ts +84 -0
  450. package/dist/metacognition/knowledge.d.ts.map +1 -0
  451. package/dist/metacognition/knowledge.js +165 -0
  452. package/dist/metacognition/knowledge.js.map +1 -0
  453. package/dist/metacognition/obligations.d.ts +82 -0
  454. package/dist/metacognition/obligations.d.ts.map +1 -0
  455. package/dist/metacognition/obligations.js +139 -0
  456. package/dist/metacognition/obligations.js.map +1 -0
  457. package/dist/metacognition/observation-validity.d.ts +83 -0
  458. package/dist/metacognition/observation-validity.d.ts.map +1 -0
  459. package/dist/metacognition/observation-validity.js +118 -0
  460. package/dist/metacognition/observation-validity.js.map +1 -0
  461. package/dist/metacognition/observe.d.ts +45 -0
  462. package/dist/metacognition/observe.d.ts.map +1 -0
  463. package/dist/metacognition/observe.js +59 -0
  464. package/dist/metacognition/observe.js.map +1 -0
  465. package/dist/metacognition/policy.d.ts +53 -0
  466. package/dist/metacognition/policy.d.ts.map +1 -0
  467. package/dist/metacognition/policy.js +155 -0
  468. package/dist/metacognition/policy.js.map +1 -0
  469. package/dist/metacognition/predictions.d.ts +78 -0
  470. package/dist/metacognition/predictions.d.ts.map +1 -0
  471. package/dist/metacognition/predictions.js +181 -0
  472. package/dist/metacognition/predictions.js.map +1 -0
  473. package/dist/metacognition/retrieval.d.ts +53 -0
  474. package/dist/metacognition/retrieval.d.ts.map +1 -0
  475. package/dist/metacognition/retrieval.js +170 -0
  476. package/dist/metacognition/retrieval.js.map +1 -0
  477. package/dist/metacognition/risk.d.ts +48 -0
  478. package/dist/metacognition/risk.d.ts.map +1 -0
  479. package/dist/metacognition/risk.js +179 -0
  480. package/dist/metacognition/risk.js.map +1 -0
  481. package/dist/metacognition/route-economics.d.ts +95 -0
  482. package/dist/metacognition/route-economics.d.ts.map +1 -0
  483. package/dist/metacognition/route-economics.js +110 -0
  484. package/dist/metacognition/route-economics.js.map +1 -0
  485. package/dist/metacognition/runtime-bridge.d.ts +81 -0
  486. package/dist/metacognition/runtime-bridge.d.ts.map +1 -0
  487. package/dist/metacognition/runtime-bridge.js +458 -0
  488. package/dist/metacognition/runtime-bridge.js.map +1 -0
  489. package/dist/metacognition/skills.d.ts +42 -0
  490. package/dist/metacognition/skills.d.ts.map +1 -0
  491. package/dist/metacognition/skills.js +220 -0
  492. package/dist/metacognition/skills.js.map +1 -0
  493. package/dist/metacognition/state.d.ts +110 -0
  494. package/dist/metacognition/state.d.ts.map +1 -0
  495. package/dist/metacognition/state.js +52 -0
  496. package/dist/metacognition/state.js.map +1 -0
  497. package/dist/metacognition/validation.d.ts +19 -0
  498. package/dist/metacognition/validation.d.ts.map +1 -0
  499. package/dist/metacognition/validation.js +58 -0
  500. package/dist/metacognition/validation.js.map +1 -0
  501. package/dist/metacognition/verification.d.ts +93 -0
  502. package/dist/metacognition/verification.d.ts.map +1 -0
  503. package/dist/metacognition/verification.js +132 -0
  504. package/dist/metacognition/verification.js.map +1 -0
  505. package/dist/metacognition/verifier.d.ts +49 -0
  506. package/dist/metacognition/verifier.d.ts.map +1 -0
  507. package/dist/metacognition/verifier.js +88 -0
  508. package/dist/metacognition/verifier.js.map +1 -0
  509. package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
  510. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  511. package/dist/modes/interactive/components/assistant-message.js +42 -26
  512. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  513. package/dist/modes/interactive/components/chat-container.d.ts +7 -0
  514. package/dist/modes/interactive/components/chat-container.d.ts.map +1 -0
  515. package/dist/modes/interactive/components/chat-container.js +14 -0
  516. package/dist/modes/interactive/components/chat-container.js.map +1 -0
  517. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  518. package/dist/modes/interactive/components/dynamic-border.js +4 -2
  519. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  520. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  521. package/dist/modes/interactive/components/login-dialog.js +0 -1
  522. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  523. package/dist/modes/interactive/components/session-selector-async-search.d.ts +33 -0
  524. package/dist/modes/interactive/components/session-selector-async-search.d.ts.map +1 -0
  525. package/dist/modes/interactive/components/session-selector-async-search.js +109 -0
  526. package/dist/modes/interactive/components/session-selector-async-search.js.map +1 -0
  527. package/dist/modes/interactive/components/session-selector-loaders.d.ts +6 -0
  528. package/dist/modes/interactive/components/session-selector-loaders.d.ts.map +1 -0
  529. package/dist/modes/interactive/components/session-selector-loaders.js +9 -0
  530. package/dist/modes/interactive/components/session-selector-loaders.js.map +1 -0
  531. package/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
  532. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  533. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  534. package/dist/modes/interactive/components/session-selector-tree.d.ts +16 -0
  535. package/dist/modes/interactive/components/session-selector-tree.d.ts.map +1 -0
  536. package/dist/modes/interactive/components/session-selector-tree.js +46 -0
  537. package/dist/modes/interactive/components/session-selector-tree.js.map +1 -0
  538. package/dist/modes/interactive/components/session-selector.d.ts +6 -1
  539. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  540. package/dist/modes/interactive/components/session-selector.js +36 -76
  541. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  542. package/dist/modes/interactive/components/tool-execution-images.d.ts +32 -0
  543. package/dist/modes/interactive/components/tool-execution-images.d.ts.map +1 -0
  544. package/dist/modes/interactive/components/tool-execution-images.js +144 -0
  545. package/dist/modes/interactive/components/tool-execution-images.js.map +1 -0
  546. package/dist/modes/interactive/components/tool-execution.d.ts +3 -4
  547. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  548. package/dist/modes/interactive/components/tool-execution.js +22 -71
  549. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  550. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  551. package/dist/modes/interactive/interactive-mode.js +7 -9
  552. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  553. package/dist/modes/interactive/tui-diagnostics.d.ts +8 -4
  554. package/dist/modes/interactive/tui-diagnostics.d.ts.map +1 -1
  555. package/dist/modes/interactive/tui-diagnostics.js +35 -1
  556. package/dist/modes/interactive/tui-diagnostics.js.map +1 -1
  557. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  558. package/dist/modes/rpc/rpc-mode.js +14 -17
  559. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  560. package/dist/modes/rpc/rpc-response.d.ts +5 -0
  561. package/dist/modes/rpc/rpc-response.d.ts.map +1 -0
  562. package/dist/modes/rpc/rpc-response.js +17 -0
  563. package/dist/modes/rpc/rpc-response.js.map +1 -0
  564. package/dist/observation/identity.d.ts +14 -0
  565. package/dist/observation/identity.d.ts.map +1 -0
  566. package/dist/observation/identity.js +29 -0
  567. package/dist/observation/identity.js.map +1 -0
  568. package/dist/observation/index.d.ts +13 -0
  569. package/dist/observation/index.d.ts.map +1 -0
  570. package/dist/observation/index.js +13 -0
  571. package/dist/observation/index.js.map +1 -0
  572. package/dist/observation/observe-mode.d.ts +46 -0
  573. package/dist/observation/observe-mode.d.ts.map +1 -0
  574. package/dist/observation/observe-mode.js +83 -0
  575. package/dist/observation/observe-mode.js.map +1 -0
  576. package/dist/observation/store.d.ts +53 -0
  577. package/dist/observation/store.d.ts.map +1 -0
  578. package/dist/observation/store.js +126 -0
  579. package/dist/observation/store.js.map +1 -0
  580. package/dist/observation/types.d.ts +72 -0
  581. package/dist/observation/types.d.ts.map +1 -0
  582. package/dist/observation/types.js +9 -0
  583. package/dist/observation/types.js.map +1 -0
  584. package/dist/observation/view.d.ts +39 -0
  585. package/dist/observation/view.d.ts.map +1 -0
  586. package/dist/observation/view.js +173 -0
  587. package/dist/observation/view.js.map +1 -0
  588. package/dist/utils/exif-orientation.d.ts.map +1 -1
  589. package/dist/utils/exif-orientation.js +2 -3
  590. package/dist/utils/exif-orientation.js.map +1 -1
  591. package/dist/utils/tools-manager.d.ts.map +1 -1
  592. package/dist/utils/tools-manager.js +3 -5
  593. package/dist/utils/tools-manager.js.map +1 -1
  594. package/docs/adaptorch-preview-spec.md +7 -7
  595. package/docs/atomic-commit-planning.md +69 -0
  596. package/docs/compaction.md +26 -1
  597. package/docs/extensions.md +14 -0
  598. package/docs/mcp.md +22 -0
  599. package/docs/metacognition.md +130 -0
  600. package/docs/model-catalog-refresh.md +218 -1
  601. package/docs/models.md +1 -1
  602. package/docs/providers.md +53 -0
  603. package/docs/runtime-algorithms.md +156 -7
  604. package/docs/session-format.md +8 -0
  605. package/docs/sessions.md +19 -0
  606. package/docs/skills.md +19 -0
  607. package/docs/terminal-setup.md +15 -0
  608. package/docs/tui.md +41 -0
  609. package/docs/verified-run-safety.md +75 -0
  610. package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
  611. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  612. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  613. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  614. package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
  615. package/examples/extensions/gondolin/package-lock.json +2 -2
  616. package/examples/extensions/gondolin/package.json +1 -1
  617. package/examples/extensions/sandbox/package-lock.json +2 -2
  618. package/examples/extensions/sandbox/package.json +1 -1
  619. package/examples/extensions/with-deps/package-lock.json +2 -2
  620. package/examples/extensions/with-deps/package.json +1 -1
  621. package/npm-shrinkwrap.json +18 -18
  622. package/package.json +6 -8
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority-store.js","sourceRoot":"","sources":["../../../src/core/verified-run/authority-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,SAAS,EACT,UAAU,EACV,SAAS,IAAI,WAAW,EACxB,SAAS,EACT,SAAS,EACT,aAAa,EACb,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACN,cAAc,EACd,iBAAiB,EAEjB,YAAY,GACZ,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAmB,qBAAqB,EAAiB,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC9G,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EACN,0BAA0B,EAC1B,kCAAkC,EAElC,wBAAwB,EACxB,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM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;YAAE,OAAO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAAA,CACrB;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport {\n\tcloseSync,\n\texistsSync,\n\tconstants as fsConstants,\n\tfstatSync,\n\tfsyncSync,\n\tftruncateSync,\n\tmkdirSync,\n\topenSync,\n\treadFileSync,\n\trenameSync,\n\tunlinkSync,\n\twriteSync,\n} from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport {\n\tcanonicalClaim,\n\tclaimSetsConflict,\n\ttype ResourceClaimInput,\n\tsameClaimSet,\n} from \"../../coordination/resource.ts\";\nimport { type GrantToken, SETTLED_EFFECT_STATES, type Sequence, sequence } from \"../../coordination/types.ts\";\nimport { atomicRewriteFileSync } from \"../atomic-session-file.ts\";\nimport {\n\tacquireDurableFileLockSync,\n\tacquireDurableFileMutationLockSync,\n\ttype DurableFileLock,\n\tDurableFileLockBusyError,\n\tinspectDurableFileLockSync,\n} from \"../durable-file-identity.ts\";\nimport { fsyncDirectorySync, writeExclusiveFileDurablySync } from \"../durable-file-io.ts\";\nimport { canonicalJson } from \"../run-journal.ts\";\nimport { createAuthorityClock } from \"./authority-clock.ts\";\nimport { AuthorityLeaseHeldError, AuthorityStoreError } from \"./authority-errors.ts\";\nimport {\n\ttype AuthorityEvent,\n\ttype AuthorityGrantRecord,\n\ttype AuthorityProjection,\n\tapplyAuthorityEvents,\n\tauthorityPendingReconcile,\n\tparseAuthorityEvent,\n\tsnapshotFromProjection,\n} from \"./authority-events.ts\";\nimport {\n\ttype AuthorityRecord,\n\tGENESIS_PREVIOUS,\n\tmaterializeRecord,\n\ttype ParsedAuthority,\n\tparseCommitted,\n\trecordLine,\n} from \"./authority-journal.ts\";\nimport { assertSameCommandMeaning, authorizationStillOpen, expiryEvents, sameGrantToken } from \"./authority-meaning.ts\";\n\nexport type { AuthorityRecord } from \"./authority-journal.ts\";\n\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { readRunClock } from \"./recovery-clock.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { probeOwnedNamespace } from \"./supervisor-adapter.ts\";\n\n/**\n * Durable authority store (WP03): the single-writer boundary for supervisor\n * authorization state.\n *\n * Storage is a head-sidecar pair — `authority.events.jsonl` plus\n * `authority.events.jsonl.head` — mirroring `ReplayLedgerStore`: the committed\n * head is the transaction boundary, bytes after `head.size` are uncommitted\n * and get quarantined then truncated on the next open, and every append is an\n * expected-head CAS inside the `\"mutation\"` lock critical section. Cross-process\n * exclusion is the `\"authority\"` scope durable-file lease held for the store's\n * lifetime; its owner record (pid+host+token) is the writer identity, and dead\n * owners are reclaimed by the existing reclaim protocol.\n *\n * Authority epoch durability: `open` appends `authority-epoch-advanced` inside\n * the lease critical section — never the in-memory default \"1\" — and leaves the\n * epoch unreconciled. Only `reconcile()` (termination-witness probes per\n * quarantined effect, then `authority-reconciled`) reopens admission. A crash\n * between the epoch event and reconciliation leaves `pendingReconcile` set;\n * the next open adopts that epoch instead of advancing again.\n */\n\nexport { AuthorityLeaseHeldError, AuthorityStoreError } from \"./authority-errors.ts\";\n\nconst AUTHORITY_SCOPE = \"authority\";\n\nexport const authorityStorePath = (root: string): string => join(root, \"authority.events.jsonl\");\n\nexport interface AuthorityHead {\n\treadonly fileIdentity: { readonly dev: string; readonly ino: string } | null;\n\treadonly size: number;\n\treadonly lastSeq: number;\n\treadonly lastHash: string;\n}\n\nconst EMPTY_AUTHORITY_HEAD: AuthorityHead = Object.freeze({\n\tfileIdentity: null,\n\tsize: 0,\n\tlastSeq: 0,\n\tlastHash: GENESIS_PREVIOUS,\n});\n\ninterface CommittedView {\n\treadonly head: AuthorityHead;\n\treadonly parsed: ParsedAuthority;\n}\n\nfunction authorityHeadsEqual(left: AuthorityHead, right: AuthorityHead): boolean {\n\treturn (\n\t\tleft.size === right.size &&\n\t\tleft.lastSeq === right.lastSeq &&\n\t\tleft.lastHash === right.lastHash &&\n\t\t(left.fileIdentity === null\n\t\t\t? right.fileIdentity === null\n\t\t\t: right.fileIdentity !== null &&\n\t\t\t\tleft.fileIdentity.dev === right.fileIdentity.dev &&\n\t\t\t\tleft.fileIdentity.ino === right.fileIdentity.ino)\n\t);\n}\n\nfunction parseHead(raw: unknown): AuthorityHead {\n\tif (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) throw new AuthorityStoreError(\"corrupt\");\n\tconst value = raw as Record<string, unknown>;\n\tif (Object.keys(value).sort().join(\",\") !== \"fileIdentity,lastHash,lastSeq,size\")\n\t\tthrow new AuthorityStoreError(\"corrupt\");\n\tlet fileIdentity: AuthorityHead[\"fileIdentity\"] = null;\n\tif (value.fileIdentity !== null) {\n\t\tif (typeof value.fileIdentity !== \"object\" || Array.isArray(value.fileIdentity))\n\t\t\tthrow new AuthorityStoreError(\"corrupt\");\n\t\tconst identity = value.fileIdentity as Record<string, unknown>;\n\t\tif (\n\t\t\tObject.keys(identity).sort().join(\",\") !== \"dev,ino\" ||\n\t\t\ttypeof identity.dev !== \"string\" ||\n\t\t\t!/^\\d+$/.test(identity.dev) ||\n\t\t\ttypeof identity.ino !== \"string\" ||\n\t\t\t!/^\\d+$/.test(identity.ino)\n\t\t)\n\t\t\tthrow new AuthorityStoreError(\"corrupt\");\n\t\tfileIdentity = Object.freeze({ dev: identity.dev, ino: identity.ino });\n\t}\n\tif (\n\t\t!Number.isSafeInteger(value.size) ||\n\t\t(value.size as number) < 0 ||\n\t\t!Number.isSafeInteger(value.lastSeq) ||\n\t\t(value.lastSeq as number) < 0 ||\n\t\ttypeof value.lastHash !== \"string\" ||\n\t\t(value.lastSeq === 0 ? value.lastHash !== GENESIS_PREVIOUS : !/^[0-9a-f]{64}$/.test(value.lastHash))\n\t)\n\t\tthrow new AuthorityStoreError(\"corrupt\");\n\treturn Object.freeze({\n\t\tfileIdentity,\n\t\tsize: value.size as number,\n\t\tlastSeq: value.lastSeq as number,\n\t\tlastHash: value.lastHash,\n\t});\n}\n\nfunction fileIdentityOf(stat: {\n\tdev: number | bigint;\n\tino: number | bigint;\n}): NonNullable<AuthorityHead[\"fileIdentity\"]> {\n\treturn Object.freeze({ dev: String(stat.dev), ino: String(stat.ino) });\n}\n\nfunction sameFileIdentity(left: AuthorityHead[\"fileIdentity\"], right: AuthorityHead[\"fileIdentity\"]): boolean {\n\treturn left === null ? right === null : right !== null && left.dev === right.dev && left.ino === right.ino;\n}\n\nfunction writeAll(fd: number, bytes: Uint8Array): void {\n\tlet offset = 0;\n\twhile (offset < bytes.byteLength) offset += writeSync(fd, bytes, offset, bytes.byteLength - offset);\n}\n\nfunction appendDurably(path: string, bytes: Uint8Array): void {\n\tconst fd = openSync(path, fsConstants.O_CREAT | fsConstants.O_APPEND | fsConstants.O_WRONLY, 0o600);\n\ttry {\n\t\twriteAll(fd, bytes);\n\t\tfsyncSync(fd);\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nexport interface AuthorityStoreHooks {\n\t/** Fires after the events file is fsynced but before the head publishes — the commit crash window. */\n\treadonly afterLedgerFsync?: () => void;\n\t/** Fires before a quarantine artifact is fsynced. */\n\treadonly beforeQuarantineFsync?: () => void;\n\t/** Fires after GC's atomic rewrite lands but before the new head publishes — the GC crash window. */\n\treadonly afterAtomicRewrite?: () => void;\n\t/** Test seam replacing the durable record append. */\n\treadonly persistRecord?: (path: string, bytes: Uint8Array) => void;\n}\n\nexport type AuthorityProbe = (grant: AuthorityGrantRecord) => \"terminated\" | \"alive\" | \"unknown\";\n\nexport interface OpenAuthorityStoreOptions {\n\t/** Total admissible weight of concurrently active grants (broker parity). */\n\treadonly capacity: number;\n\treadonly hooks?: AuthorityStoreHooks;\n\treadonly probe?: AuthorityProbe;\n\t/** Trusted host clock; never supplied by a serialized command. */\n\treadonly clock?: () => number;\n\t/** Disable only the parsing cache; disk integrity and durability checks always run. */\n\treadonly incrementalReplay?: boolean;\n}\n\nexport interface AuthorityAcquireInput {\n\treadonly sessionId: string;\n\treadonly incarnation: Sequence | string;\n\t/** Idempotency key; unique across grants and tombstones (I08/I31). */\n\treadonly commandId: string;\n\treadonly intentDigest: string;\n\treadonly claims: readonly ResourceClaimInput[];\n\treadonly now: number;\n\treadonly ttl: number;\n\treadonly weight?: number;\n}\n\nexport type AuthorityAcquireResult =\n\t| { readonly status: \"granted\"; readonly token: GrantToken; readonly duplicate: boolean }\n\t| { readonly status: \"blocked\" }\n\t| { readonly status: \"result\"; readonly resultDigest: string; readonly token: GrantToken }\n\t| { readonly status: \"result-expired\" };\n\nexport type AuthorityLookup =\n\t| { readonly status: \"pending\"; readonly token: GrantToken }\n\t| { readonly status: \"result\"; readonly resultDigest: string; readonly token: GrantToken }\n\t| { readonly status: \"result-expired\"; readonly token: GrantToken }\n\t| { readonly status: \"unknown\" };\n\n/** Committed projection plus the hashed records it was replayed from. */\nexport interface AuthorityJournalInspection {\n\treadonly state: AuthorityProjection;\n\treadonly records: readonly AuthorityRecord[];\n\treadonly head: AuthorityHead;\n}\n\ninterface StoreContext {\n\treadonly path: string;\n\treadonly headPath: string;\n\treadonly hooks: AuthorityStoreHooks;\n}\n\nfunction publishHead(context: StoreContext, head: AuthorityHead): void {\n\tconst temp = `${context.headPath}.${randomUUID()}.tmp`;\n\tconst fd = openSync(temp, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_WRONLY, 0o600);\n\ttry {\n\t\twriteAll(fd, Buffer.from(`${JSON.stringify(head)}\\n`, \"utf8\"));\n\t\tfsyncSync(fd);\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n\ttry {\n\t\trenameSync(temp, context.headPath);\n\t\tfsyncDirectorySync(dirname(context.headPath));\n\t} catch (error) {\n\t\tif (existsSync(temp)) unlinkSync(temp);\n\t\tthrow error;\n\t}\n}\n\nfunction quarantineSuffix(context: StoreContext, bytes: Buffer): void {\n\tcontext.hooks.beforeQuarantineFsync?.();\n\twriteExclusiveFileDurablySync(`${context.path}.quarantine-${randomUUID()}`, bytes);\n}\n\n/**\n * Load committed state. With `repair`, an uncommitted suffix is quarantined\n * and truncated; a file whose identity no longer matches its head is accepted\n * only when it begins with exactly the GC snapshot continuation of that head\n * (the GC rename-landed/head-publish-crashed window), otherwise the store is\n * tampered and opens refuse. Without `repair` the suffix is left untouched\n * and simply not part of committed state.\n */\nfunction loadCommitted(context: StoreContext, repair: boolean, cached?: CommittedView): CommittedView {\n\tconst fileExists = existsSync(context.path);\n\tconst headExists = existsSync(context.headPath);\n\tconst empty: CommittedView = {\n\t\thead: EMPTY_AUTHORITY_HEAD,\n\t\tparsed: parseCommitted(Buffer.alloc(0)),\n\t};\n\tif (!fileExists && !headExists) return empty;\n\tif (fileExists && !headExists) {\n\t\tconst fd = openSync(context.path, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));\n\t\ttry {\n\t\t\tconst stat = fstatSync(fd);\n\t\t\tif (!stat.isFile() || stat.size !== 0) throw new AuthorityStoreError(\"corrupt\");\n\t\t} finally {\n\t\t\tcloseSync(fd);\n\t\t}\n\t\tif (!repair) return empty;\n\t\tunlinkSync(context.path);\n\t\tfsyncDirectorySync(dirname(context.path));\n\t\treturn empty;\n\t}\n\tif (!fileExists) throw new AuthorityStoreError(\"corrupt\");\n\tlet head: AuthorityHead;\n\ttry {\n\t\thead = parseHead(JSON.parse(readFileSync(context.headPath, \"utf8\")));\n\t} catch (error) {\n\t\tif (error instanceof AuthorityStoreError || error instanceof VerifiedRunError) throw error;\n\t\tthrow new AuthorityStoreError(\"corrupt\");\n\t}\n\tconst fd = openSync(context.path, fsConstants.O_RDWR | (fsConstants.O_NOFOLLOW ?? 0));\n\ttry {\n\t\tconst before = fstatSync(fd);\n\t\tconst bytes = readFileSync(fd);\n\t\tconst after = fstatSync(fd);\n\t\tif (\n\t\t\t!before.isFile() ||\n\t\t\t!after.isFile() ||\n\t\t\tbefore.size !== after.size ||\n\t\t\tbefore.ctimeMs !== after.ctimeMs ||\n\t\t\tafter.size !== bytes.byteLength\n\t\t)\n\t\t\tthrow new AuthorityStoreError(\"tampered\");\n\t\tconst actual = fileIdentityOf(after);\n\t\tif (!sameFileIdentity(head.fileIdentity, actual)) {\n\t\t\thead = healGarbageCollect(context, head, bytes, actual, repair);\n\t\t}\n\t\tif (head.size > after.size) throw new AuthorityStoreError(\"tampered\");\n\t\tconst committed = Buffer.from(bytes.subarray(0, head.size));\n\t\tconst prefix =\n\t\t\tcached &&\n\t\t\tsameFileIdentity(cached.head.fileIdentity, actual) &&\n\t\t\thead.size >= cached.head.size &&\n\t\t\thead.lastSeq >= cached.head.lastSeq\n\t\t\t\t? cached.parsed\n\t\t\t\t: undefined;\n\t\tconst parsed = parseCommitted(committed, prefix);\n\t\tif (parsed.lastSeq !== head.lastSeq || parsed.lastHash !== head.lastHash)\n\t\t\tthrow new AuthorityStoreError(\"tampered\");\n\t\tif (head.size < after.size && repair) {\n\t\t\tquarantineSuffix(context, bytes.subarray(head.size));\n\t\t\tftruncateSync(fd, head.size);\n\t\t\tfsyncSync(fd);\n\t\t\tfsyncDirectorySync(dirname(context.path));\n\t\t}\n\t\treturn { head, parsed };\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\n/**\n * The only legal file whose identity differs from its head: an atomic GC\n * rewrite that landed but whose head publish never committed. Its first\n * record must be exactly the snapshot continuing `head`; the healed head\n * covers just that record, and any bytes after it are uncommitted suffix.\n */\nfunction healGarbageCollect(\n\tcontext: StoreContext,\n\thead: AuthorityHead,\n\tbytes: Buffer,\n\tactual: NonNullable<AuthorityHead[\"fileIdentity\"]>,\n\trepair: boolean,\n): AuthorityHead {\n\tif (!repair) throw new AuthorityStoreError(\"tampered\");\n\tlet healed: AuthorityHead | null = null;\n\ttry {\n\t\tconst newline = bytes.indexOf(10);\n\t\tif (newline > 0) {\n\t\t\tconst first = bytes.subarray(0, newline + 1);\n\t\t\tconst raw: unknown = JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(first).slice(0, -1));\n\t\t\tconst event =\n\t\t\t\ttypeof raw === \"object\" && raw !== null && \"event\" in raw\n\t\t\t\t\t? parseAuthorityEvent((raw as { event: unknown }).event)\n\t\t\t\t\t: null;\n\t\t\tif (event?.kind === \"authority-snapshot\") {\n\t\t\t\tconst record = materializeRecord(event.archivedThroughSequence + 1, event.continuesHash, event);\n\t\t\t\t// Only the snapshot line itself must be proven: any bytes after it\n\t\t\t\t// (including a torn tail) are uncommitted suffix and go to quarantine.\n\t\t\t\tif (\n\t\t\t\t\tcanonicalJson(raw) === canonicalJson(record) &&\n\t\t\t\t\tevent.archivedThroughSequence === head.lastSeq &&\n\t\t\t\t\tevent.continuesHash === head.lastHash\n\t\t\t\t) {\n\t\t\t\t\thealed = Object.freeze({\n\t\t\t\t\t\tfileIdentity: actual,\n\t\t\t\t\t\tsize: first.byteLength,\n\t\t\t\t\t\tlastSeq: record.seq,\n\t\t\t\t\t\tlastHash: record.hash,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tif (!(error instanceof AuthorityStoreError || error instanceof VerifiedRunError)) throw error;\n\t}\n\tif (!healed) throw new AuthorityStoreError(\"tampered\");\n\tpublishHead(context, healed);\n\treturn healed;\n}\n\nfunction defaultProbe(grant: AuthorityGrantRecord): \"terminated\" | \"alive\" | \"unknown\" {\n\tif (!grant.identity) return \"unknown\";\n\treturn probeOwnedNamespace(grant.identity);\n}\n\nfunction nextSequenceValue(value: Sequence): Sequence {\n\treturn sequence(String(BigInt(value) + 1n));\n}\n\nfunction assertNonNegativeInteger(value: number, label: string): void {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0)\n\t\tthrow new TypeError(`${label} must be a nonnegative safe integer`);\n}\n\n/** The durable single-writer authority boundary. */\nexport class AuthorityStore {\n\tprivate readonly context: StoreContext;\n\tprivate readonly capacity: number;\n\tprivate readonly probe: AuthorityProbe;\n\tprivate readonly lease: DurableFileLock;\n\tprivate accepted: CommittedView;\n\tprivate released = false;\n\tprivate readonly now: () => number;\n\tprivate readonly incrementalReplay: boolean;\n\n\tprivate constructor(\n\t\tcontext: StoreContext,\n\t\tlease: DurableFileLock,\n\t\taccepted: CommittedView,\n\t\toptions: OpenAuthorityStoreOptions,\n\t) {\n\t\tthis.context = context;\n\t\tthis.lease = lease;\n\t\tthis.accepted = accepted;\n\t\tthis.capacity = options.capacity;\n\t\tthis.probe = options.probe ?? defaultProbe;\n\t\tthis.now = createAuthorityClock(options.clock);\n\t\tthis.incrementalReplay = options.incrementalReplay !== false;\n\t}\n\n\t/**\n\t * Take the `\"authority\"` scope lease and advance the persisted epoch.\n\t * When the previous epoch never reconciled, this restart adopts it — the\n\t * pending reconciliation must finish before new admission, and the epoch\n\t * is not bumped again (review §5 fault row).\n\t */\n\tstatic open(path: string, options: OpenAuthorityStoreOptions): AuthorityStore {\n\t\tassertNonNegativeInteger(options.capacity, \"capacity\");\n\t\tmkdirSync(dirname(path), { recursive: true });\n\t\tconst context: StoreContext = { path, headPath: `${path}.head`, hooks: options.hooks ?? {} };\n\t\tconst mutation = acquireDurableFileMutationLockSync(path);\n\t\tlet lease: DurableFileLock;\n\t\ttry {\n\t\t\tlease = acquireDurableFileLockSync(path, AUTHORITY_SCOPE, { timeoutMs: 0 });\n\t\t} catch (error) {\n\t\t\tconst failure =\n\t\t\t\terror instanceof DurableFileLockBusyError\n\t\t\t\t\t? new AuthorityLeaseHeldError(inspectDurableFileLockSync(path, AUTHORITY_SCOPE))\n\t\t\t\t\t: error;\n\t\t\ttry {\n\t\t\t\tmutation.release();\n\t\t\t} catch (cleanupError) {\n\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t[failure, cleanupError instanceof Error ? cleanupError : new Error(String(cleanupError))],\n\t\t\t\t\t\"Authority lease acquisition cleanup failed\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow failure;\n\t\t}\n\t\tlet store: AuthorityStore;\n\t\ttry {\n\t\t\tstore = new AuthorityStore(context, lease, loadCommitted(context, true), options);\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tlease.release();\n\t\t\t} catch (releaseError) {\n\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t[error, releaseError instanceof Error ? releaseError : new Error(String(releaseError))],\n\t\t\t\t\t\"Authority store open cleanup failed\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tmutation.release();\n\t\t}\n\t\ttry {\n\t\t\tif (store.state.epoch === null || !authorityPendingReconcile(store.state)) {\n\t\t\t\t// Fresh store or fully reconciled previous epoch: this restart\n\t\t\t\t// durably advances the epoch. A pending epoch is adopted, not bumped.\n\t\t\t\tstore.commitEpochAdvance();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tstore.release();\n\t\t\t} catch (releaseError) {\n\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t[error, releaseError instanceof Error ? releaseError : new Error(String(releaseError))],\n\t\t\t\t\t\"Authority store open cleanup failed\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\treturn store;\n\t}\n\n\t/** Read-only committed projection; performs no repair and writes nothing. */\n\tstatic inspect(path: string): AuthorityProjection {\n\t\tconst context: StoreContext = { path, headPath: `${path}.head`, hooks: {} };\n\t\treturn loadCommitted(context, false).parsed.state;\n\t}\n\n\t/**\n\t * Read-only committed journal: projection plus the hashed records it was\n\t * replayed from, so callers can see transition causes (cancel-requested vs\n\t * authorization-expired vs epoch restart) and termination witnesses — the\n\t * projection alone intentionally does not restate them.\n\t */\n\tstatic inspectJournal(path: string): AuthorityJournalInspection {\n\t\tconst context: StoreContext = { path, headPath: `${path}.head`, hooks: {} };\n\t\tconst committed = loadCommitted(context, false);\n\t\treturn Object.freeze({\n\t\t\tstate: committed.parsed.state,\n\t\t\trecords: committed.parsed.records,\n\t\t\thead: committed.head,\n\t\t});\n\t}\n\n\tget path(): string {\n\t\treturn this.context.path;\n\t}\n\n\tget head(): AuthorityHead {\n\t\treturn this.accepted.head;\n\t}\n\n\tget state(): AuthorityProjection {\n\t\treturn structuredClone(this.accepted.parsed.state);\n\t}\n\n\tget lastReplay(): ParsedAuthority[\"replay\"] {\n\t\treturn this.accepted.parsed.replay;\n\t}\n\n\tget pendingReconcile(): boolean {\n\t\treturn authorityPendingReconcile(this.state);\n\t}\n\n\tprivate writerId(): string {\n\t\ttry {\n\t\t\treturn `${readRunClock().bootId}:${process.pid}`;\n\t\t} catch {\n\t\t\treturn `unknown:${process.pid}`;\n\t\t}\n\t}\n\n\t/**\n\t * Commit events as one transaction: mutation lock → committed-head CAS →\n\t * reducer pre-validation → append+fsync → head publish → re-read\n\t * verification. The head CAS is the fencing boundary — a store whose lease\n\t * was reclaimed and taken by another writer sees a changed head and fails\n\t * closed instead of authorizing. Persist failures never mint in-memory\n\t * state (docs/04: no memory-only authorization after storage failure).\n\t */\n\tprivate commit(events: readonly AuthorityEvent[]): void {\n\t\tif (this.released) throw new AuthorityStoreError(\"stale_owner\");\n\t\tconst mutation = acquireDurableFileMutationLockSync(this.context.path);\n\t\ttry {\n\t\t\tconst current = loadCommitted(this.context, true, this.incrementalReplay ? this.accepted : undefined);\n\t\t\tif (!authorityHeadsEqual(current.head, this.accepted.head)) throw new AuthorityStoreError(\"stale_head\");\n\t\t\tif (events.length === 0) {\n\t\t\t\tthis.accepted = current;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Every event must be accepted by the deterministic reducer before a\n\t\t\t// single byte reaches disk.\n\t\t\tapplyAuthorityEvents(current.parsed.state, events);\n\t\t\tconst lines: string[] = [];\n\t\t\tlet seq = current.parsed.lastSeq;\n\t\t\tlet previous = current.parsed.lastHash;\n\t\t\tfor (const event of events) {\n\t\t\t\tseq += 1;\n\t\t\t\tconst record = materializeRecord(seq, previous, event);\n\t\t\t\tlines.push(recordLine(record));\n\t\t\t\tprevious = record.hash;\n\t\t\t}\n\t\t\tconst payload = Buffer.from(lines.join(\"\"), \"utf8\");\n\t\t\t(this.context.hooks.persistRecord ?? appendDurably)(this.context.path, payload);\n\t\t\tconst fd = openSync(this.context.path, fsConstants.O_RDWR | (fsConstants.O_NOFOLLOW ?? 0));\n\t\t\tlet head: AuthorityHead;\n\t\t\ttry {\n\t\t\t\tconst stat = fstatSync(fd);\n\t\t\t\t// CAS on the file itself: for an established store the inode must be\n\t\t\t\t// the one the committed head names; for genesis the append must have\n\t\t\t\t// produced exactly the expected size. Anything else is a replaced or\n\t\t\t\t// foreign file and commits must not bless it.\n\t\t\t\tif (\n\t\t\t\t\tstat.size !== current.head.size + payload.byteLength ||\n\t\t\t\t\t(current.head.fileIdentity !== null &&\n\t\t\t\t\t\t!sameFileIdentity(current.head.fileIdentity, fileIdentityOf(stat)))\n\t\t\t\t)\n\t\t\t\t\tthrow new AuthorityStoreError(\"stale_head\");\n\t\t\t\thead = Object.freeze({\n\t\t\t\t\tfileIdentity: fileIdentityOf(stat),\n\t\t\t\t\tsize: stat.size,\n\t\t\t\t\tlastSeq: seq,\n\t\t\t\t\tlastHash: previous,\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\tcloseSync(fd);\n\t\t\t}\n\t\t\tthis.context.hooks.afterLedgerFsync?.();\n\t\t\tpublishHead(this.context, head);\n\t\t\tconst verified = loadCommitted(this.context, false, this.incrementalReplay ? current : undefined);\n\t\t\tif (verified.parsed.lastSeq !== head.lastSeq || verified.parsed.lastHash !== head.lastHash)\n\t\t\t\tthrow new AuthorityStoreError(\"corrupt\");\n\t\t\tthis.accepted = verified;\n\t\t} finally {\n\t\t\tmutation.release();\n\t\t}\n\t}\n\n\tprivate commitEpochAdvance(): void {\n\t\tconst state = this.state;\n\t\tconst epoch = nextSequenceValue(state.epoch ?? sequence(\"0\"));\n\t\tconst transitions = [...state.grants.values()]\n\t\t\t.filter((grant) => !SETTLED_EFFECT_STATES.has(grant.state))\n\t\t\t.map((grant) =>\n\t\t\t\tObject.freeze({\n\t\t\t\t\tgrantSequence: grant.token.grantSequence,\n\t\t\t\t\toutcome: grant.effectLive ? (\"quarantined\" as const) : (\"cancelled\" as const),\n\t\t\t\t}),\n\t\t\t);\n\t\tthis.commit([\n\t\t\t{ kind: \"authority-epoch-advanced\", authorityEpoch: epoch, writerId: this.writerId(), transitions },\n\t\t]);\n\t}\n\n\t/** Announce a session incarnation (S2); the counter survives restarts durably. */\n\tregister(sessionId: string): Sequence {\n\t\tif (typeof sessionId !== \"string\" || sessionId.length === 0)\n\t\t\tthrow new TypeError(\"sessionId must be a non-empty string\");\n\t\tconst current = this.state.incarnations.get(sessionId) ?? sequence(\"0\");\n\t\tconst incarnation = nextSequenceValue(current);\n\t\tthis.commit([{ kind: \"session-registered\", sessionId, incarnation }]);\n\t\treturn incarnation;\n\t}\n\n\t/**\n\t * Admit an authorization: claim-overlap check, capacity check, idempotency\n\t * replay, and the `grant-reserved` record in one lease/mutation-locked\n\t * critical section — the check and the record are one transaction (docs/04).\n\t * The lease is held for the store's lifetime, so committed state cannot\n\t * move between the check and the append; the head CAS in commit() is the\n\t * backstop if it ever could.\n\t */\n\tacquire(input: AuthorityAcquireInput): AuthorityAcquireResult {\n\t\tassertNonNegativeInteger(input.now, \"now\");\n\t\tconst weight = input.weight ?? 1;\n\t\tassertNonNegativeInteger(weight, \"weight\");\n\t\tif (!Number.isSafeInteger(input.ttl) || input.ttl <= 0)\n\t\t\tthrow new TypeError(\"ttl must be a positive safe integer\");\n\t\tconst authorizationDeadline = input.now + input.ttl;\n\t\tif (!Number.isSafeInteger(authorizationDeadline)) throw new RangeError(\"authorization deadline overflow\");\n\t\tconst incarnation = sequence(input.incarnation);\n\t\tif (this.state.incarnations.get(input.sessionId) !== incarnation)\n\t\t\tthrow new AuthorityStoreError(\"stale_incarnation\");\n\t\tif (!/^[a-f0-9]{64}$/.test(input.intentDigest)) throw new TypeError(\"intentDigest must be a sha256 hex digest\");\n\t\tif (!Array.isArray(input.claims) || input.claims.length === 0)\n\t\t\tthrow new TypeError(\"an unknown scope must not be admitted as an empty scope\");\n\t\tconst claims = Object.freeze(Array.from(input.claims, (claim) => canonicalClaim(claim)));\n\n\t\t// Idempotency (I08): replayed commands return their recorded disposition\n\t\t// without re-executing. A live tombstone returns the result; an expired\n\t\t// one reports expiry; an in-flight grant is a duplicate only when the\n\t\t// full intent matches — otherwise it is an ID collision (I09/I20).\n\t\tconst tombstone = this.state.tombstones.get(input.commandId);\n\t\tif (tombstone) {\n\t\t\tconst grant = this.state.grants.get(tombstone.grantSequence);\n\t\t\tif (!grant) throw new AuthorityStoreError(\"corrupt\");\n\t\t\tassertSameCommandMeaning(grant, {\n\t\t\t\tintentDigest: input.intentDigest,\n\t\t\t\tsessionId: input.sessionId,\n\t\t\t\tincarnation,\n\t\t\t\tclaims,\n\t\t\t\tweight,\n\t\t\t});\n\t\t\tif (tombstone.expiresAtMs <= input.now) return { status: \"result-expired\" };\n\t\t\treturn { status: \"result\", resultDigest: tombstone.resultDigest, token: grant.token };\n\t\t}\n\t\tfor (const grant of this.state.grants.values()) {\n\t\t\tif (grant.commandId !== input.commandId) continue;\n\t\t\tassertSameCommandMeaning(grant, {\n\t\t\t\tintentDigest: input.intentDigest,\n\t\t\t\tsessionId: input.sessionId,\n\t\t\t\tincarnation,\n\t\t\t\tclaims,\n\t\t\t\tweight,\n\t\t\t});\n\t\t\treturn { status: \"granted\", token: grant.token, duplicate: true };\n\t\t}\n\n\t\tif (this.pendingReconcile) throw new AuthorityStoreError(\"reconcile_pending\");\n\t\tconst epoch = this.state.epoch;\n\t\tif (epoch === null) throw new AuthorityStoreError(\"corrupt\");\n\n\t\tconst expired = expiryEvents(this.state, input.now, epoch);\n\t\tconst settledState = expired.length ? applyAuthorityEvents(this.state, expired) : this.state;\n\t\tconst active = [...settledState.grants.values()].filter((grant) => !SETTLED_EFFECT_STATES.has(grant.state));\n\t\tconst used = active.reduce((sum, grant) => sum + grant.weight, 0);\n\t\tif (weight > this.capacity - used) return { status: \"blocked\" };\n\t\tif (active.some((grant) => claimSetsConflict([...claims], [...grant.claims]))) return { status: \"blocked\" };\n\n\t\tconst grantSequence = nextSequenceValue(this.state.grantCounter);\n\t\tconst grant: AuthorityGrantRecord = Object.freeze({\n\t\t\ttoken: Object.freeze({\n\t\t\t\tauthorityEpoch: epoch,\n\t\t\t\tgrantSequence,\n\t\t\t\tsessionId: input.sessionId,\n\t\t\t\tsessionIncarnation: incarnation,\n\t\t\t\tauthorizationDeadline,\n\t\t\t}),\n\t\t\tcommandId: input.commandId,\n\t\t\tintentDigest: input.intentDigest,\n\t\t\tclaims,\n\t\t\tweight,\n\t\t\tstate: \"reserved\",\n\t\t\teffectLive: false,\n\t\t\tdispatchId: null,\n\t\t\tactualClaims: null,\n\t\t\tidentity: null,\n\t\t});\n\t\tthis.commit([...expired, { kind: \"grant-reserved\", grant }]);\n\t\treturn { status: \"granted\", token: grant.token, duplicate: false };\n\t}\n\n\tprivate resolveToken(token: GrantToken, authoritative: boolean): AuthorityGrantRecord | undefined {\n\t\tconst grant = this.state.grants.get(token.grantSequence);\n\t\tif (!grant || !sameGrantToken(grant.token, token)) return undefined;\n\t\tif (authoritative) {\n\t\t\tif (this.released) return undefined;\n\t\t\tif (\n\t\t\t\ttoken.authorityEpoch !== this.state.epoch ||\n\t\t\t\tthis.state.incarnations.get(token.sessionId) !== token.sessionIncarnation ||\n\t\t\t\tSETTLED_EFFECT_STATES.has(grant.state)\n\t\t\t)\n\t\t\t\treturn undefined;\n\t\t} else if (SETTLED_EFFECT_STATES.has(grant.state)) return undefined;\n\t\treturn grant;\n\t}\n\n\t/**\n\t * Persisted dispatch intent. A committed intent whose spawn was never\n\t * witnessed cannot be assumed un-run; on restart it quarantines like any\n\t * other possibly-live effect (I01/I02).\n\t */\n\tdispatchIntent(token: GrantToken, dispatchId: string, now = this.now()): boolean {\n\t\tif (!/^[A-Za-z0-9_-]{1,128}$/.test(dispatchId)) throw new TypeError(\"dispatchId is invalid\");\n\t\tconst grant = this.resolveToken(token, true);\n\t\tif (!grant || grant.state !== \"reserved\") return false;\n\t\tconst epoch = this.state.epoch;\n\t\tif (epoch === null) return false;\n\t\tif (!authorizationStillOpen(now, grant.token.authorizationDeadline)) {\n\t\t\tthis.expire(now);\n\t\t\treturn false;\n\t\t}\n\t\tthis.commit([\n\t\t\t{ kind: \"dispatch-intent\", grantSequence: grant.token.grantSequence, authorityEpoch: epoch, dispatchId },\n\t\t]);\n\t\treturn true;\n\t}\n\n\t/** Bind an effect to its reservation; actual claims must equal the reserved set exactly. */\n\teffectStarted(\n\t\ttoken: GrantToken,\n\t\tactualClaims: readonly ResourceClaimInput[],\n\t\tidentity?: NamespaceIdentity,\n\t\tnow = this.now(),\n\t): boolean {\n\t\tconst grant = this.resolveToken(token, true);\n\t\tif (!grant || (grant.state !== \"reserved\" && grant.state !== \"starting\")) return false;\n\t\tif (!authorizationStillOpen(now, grant.token.authorizationDeadline)) {\n\t\t\tthis.expire(now);\n\t\t\treturn false;\n\t\t}\n\t\tif (!Array.isArray(actualClaims)) throw new TypeError(\"actualClaims must be an array\");\n\t\tconst claims = Object.freeze(Array.from(actualClaims, (entry) => canonicalClaim(entry)));\n\t\tif (!sameClaimSet([...claims], [...grant.claims])) return false;\n\t\tconst epoch = this.state.epoch;\n\t\tif (epoch === null) return false;\n\t\tthis.commit([\n\t\t\t{\n\t\t\t\tkind: \"effect-started\",\n\t\t\t\tgrantSequence: grant.token.grantSequence,\n\t\t\t\tauthorityEpoch: epoch,\n\t\t\t\tactualClaims: claims,\n\t\t\t\t...(identity ? { identity } : {}),\n\t\t\t},\n\t\t]);\n\t\treturn true;\n\t}\n\n\t/** Revalidate a running effect before its next irreversible boundary, without starting it again. */\n\teffectAuthorized(token: GrantToken, actualClaims: readonly ResourceClaimInput[]): boolean {\n\t\tif (this.released) return false;\n\t\tthis.commit([]);\n\t\tconst now = this.now();\n\t\tconst grant = this.resolveToken(token, true);\n\t\tif (!grant || grant.state !== \"running\") return false;\n\t\tif (!authorizationStillOpen(now, token.authorizationDeadline)) {\n\t\t\tthis.expire(now);\n\t\t\treturn false;\n\t\t}\n\t\treturn sameClaimSet(\n\t\t\tArray.from(actualClaims, (claim) => canonicalClaim(claim)),\n\t\t\tgrant.claims,\n\t\t);\n\t}\n\n\t/** Requested cancellation is not observed termination; live effects quarantine. */\n\tcancel(token: GrantToken): boolean {\n\t\tconst grant = this.resolveToken(token, false);\n\t\tif (!grant) return false;\n\t\tconst epoch = this.state.epoch;\n\t\tif (epoch === null) return false;\n\t\tthis.commit([\n\t\t\t{\n\t\t\t\tkind: \"cancel-requested\",\n\t\t\t\tgrantSequence: grant.token.grantSequence,\n\t\t\t\tauthorityEpoch: epoch,\n\t\t\t\toutcome: grant.effectLive ? \"quarantined\" : \"cancelled\",\n\t\t\t},\n\t\t]);\n\t\treturn true;\n\t}\n\n\t/** Settle lapsed authorizations; never evicts a live effect. */\n\texpire(now: number): void {\n\t\tassertNonNegativeInteger(now, \"now\");\n\t\tconst epoch = this.state.epoch;\n\t\tif (epoch === null) return;\n\t\tconst events = expiryEvents(this.state, now, epoch);\n\t\tif (events.length) this.commit(events);\n\t}\n\n\t/**\n\t * Trusted supervisor witness: this exact effect is gone. Accepted across\n\t * superseded epochs so a restarted authority can settle what the previous\n\t * one started, never to authorize new work.\n\t */\n\tconfirmTerminated(token: GrantToken): boolean {\n\t\tconst grant = this.resolveToken(token, false);\n\t\tif (!grant) return false;\n\t\tconst epoch = this.state.epoch;\n\t\tif (epoch === null) return false;\n\t\tthis.commit([{ kind: \"termination-observed\", grantSequence: grant.token.grantSequence, authorityEpoch: epoch }]);\n\t\treturn true;\n\t}\n\n\t/** Retain the final result as an idempotency tombstone (S3, docs/04). */\n\tretainResult(commandId: string, resultDigest: string, now: number, retentionMs: number): void {\n\t\tassertNonNegativeInteger(now, \"now\");\n\t\tif (!Number.isSafeInteger(retentionMs) || retentionMs <= 0)\n\t\t\tthrow new TypeError(\"retentionMs must be a positive safe integer\");\n\t\tif (!/^[a-f0-9]{64}$/.test(resultDigest)) throw new TypeError(\"resultDigest must be a sha256 hex digest\");\n\t\tconst grant = [...this.state.grants.values()].find((entry) => entry.commandId === commandId);\n\t\tif (!grant) throw new AuthorityStoreError(\"unknown_command\");\n\t\tif (!SETTLED_EFFECT_STATES.has(grant.state)) throw new AuthorityStoreError(\"unsettled\");\n\t\tif (this.state.tombstones.has(commandId)) throw new AuthorityStoreError(\"duplicate\");\n\t\tthis.commit([\n\t\t\t{\n\t\t\t\tkind: \"result-retained\",\n\t\t\t\tcommandId,\n\t\t\t\tgrantSequence: grant.token.grantSequence,\n\t\t\t\tresultDigest,\n\t\t\t\tretainedAtMs: now,\n\t\t\t\texpiresAtMs: now + retentionMs,\n\t\t\t},\n\t\t]);\n\t}\n\n\t/** Command disposition without re-execution (I08/I31). */\n\tlookup(commandId: string, now: number): AuthorityLookup {\n\t\tassertNonNegativeInteger(now, \"now\");\n\t\tconst tombstone = this.state.tombstones.get(commandId);\n\t\tif (tombstone) {\n\t\t\tconst grant = this.state.grants.get(tombstone.grantSequence);\n\t\t\tif (!grant) throw new AuthorityStoreError(\"corrupt\");\n\t\t\treturn tombstone.expiresAtMs <= now\n\t\t\t\t? { status: \"result-expired\", token: grant.token }\n\t\t\t\t: { status: \"result\", resultDigest: tombstone.resultDigest, token: grant.token };\n\t\t}\n\t\tfor (const grant of this.state.grants.values())\n\t\t\tif (grant.commandId === commandId) return { status: \"pending\", token: grant.token };\n\t\treturn { status: \"unknown\" };\n\t}\n\n\t/**\n\t * Finish the restart reconciliation: every quarantined effect is compared\n\t * against the real execution boundary — only an observed termination\n\t * settles it (\"gone\"); \"alive\"/\"unknown\" stay quarantined and keep their\n\t * claims (docs/04, review §6). Ends with `authority-reconciled` for the\n\t * current epoch; the reconciled scope only then admits new work.\n\t */\n\treconcile(probe?: AuthorityProbe): void {\n\t\tconst state = this.state;\n\t\tconst epoch = state.epoch;\n\t\tif (epoch === null) throw new AuthorityStoreError(\"corrupt\");\n\t\tif (!authorityPendingReconcile(state)) return;\n\t\tconst check = probe ?? this.probe;\n\t\tconst events: AuthorityEvent[] = [];\n\t\tfor (const grant of state.grants.values()) {\n\t\t\tif (grant.state !== \"quarantined\") continue;\n\t\t\tif (check(grant) === \"terminated\") {\n\t\t\t\tevents.push({\n\t\t\t\t\tkind: \"termination-observed\",\n\t\t\t\t\tgrantSequence: grant.token.grantSequence,\n\t\t\t\t\tauthorityEpoch: epoch,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tevents.push({ kind: \"authority-reconciled\", authorityEpoch: epoch });\n\t\tthis.commit(events);\n\t}\n\n\t/**\n\t * GC (review §7): fold droppable state into an `authority-snapshot` and\n\t * atomically rewrite the log to that snapshot. Retained: the epoch pair,\n\t * incarnation counters, the grant counter (I31 — sequences never reissue),\n\t * every unsettled grant, every settled grant still referenced by an\n\t * unexpired tombstone, and the unexpired tombstones themselves. A crash\n\t * between the atomic rewrite and head publish self-heals on next open via\n\t * the snapshot continuation check.\n\t */\n\tcompact(now: number): { readonly dropped: number } {\n\t\tassertNonNegativeInteger(now, \"now\");\n\t\tif (this.released) throw new AuthorityStoreError(\"stale_owner\");\n\t\tconst mutation = acquireDurableFileMutationLockSync(this.context.path);\n\t\ttry {\n\t\t\tconst current = loadCommitted(this.context, true);\n\t\t\tif (!authorityHeadsEqual(current.head, this.accepted.head)) throw new AuthorityStoreError(\"stale_head\");\n\t\t\tconst state = current.parsed.state;\n\t\t\tif (state.epoch === null) return { dropped: 0 };\n\t\t\tconst keepGrant = new Set<Sequence>();\n\t\t\tconst keepTombstone = new Set<string>();\n\t\t\tfor (const tombstone of state.tombstones.values()) {\n\t\t\t\tif (tombstone.expiresAtMs > now) {\n\t\t\t\t\tkeepTombstone.add(tombstone.commandId);\n\t\t\t\t\tkeepGrant.add(tombstone.grantSequence);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst grants = [...state.grants.values()].filter(\n\t\t\t\t(grant) => !SETTLED_EFFECT_STATES.has(grant.state) || keepGrant.has(grant.token.grantSequence),\n\t\t\t);\n\t\t\tconst tombstones = [...state.tombstones.values()].filter((stone) => keepTombstone.has(stone.commandId));\n\t\t\tconst dropped = state.grants.size - grants.length + (state.tombstones.size - tombstones.length);\n\t\t\tif (dropped === 0) return { dropped: 0 };\n\t\t\tconst snapshot = snapshotFromProjection({\n\t\t\t\t...state,\n\t\t\t\tgrants: new Map(grants.map((grant) => [grant.token.grantSequence, grant])),\n\t\t\t\ttombstones: new Map(tombstones.map((stone) => [stone.commandId, stone])),\n\t\t\t});\n\t\t\tconst record = materializeRecord(current.parsed.lastSeq + 1, current.parsed.lastHash, {\n\t\t\t\tkind: \"authority-snapshot\",\n\t\t\t\tarchivedThroughSequence: current.parsed.lastSeq,\n\t\t\t\tcontinuesHash: current.parsed.lastHash,\n\t\t\t\tstate: snapshot,\n\t\t\t});\n\t\t\tatomicRewriteFileSync(this.context.path, recordLine(record));\n\t\t\tthis.context.hooks.afterAtomicRewrite?.();\n\t\t\tconst fd = openSync(this.context.path, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));\n\t\t\tlet head: AuthorityHead;\n\t\t\ttry {\n\t\t\t\tconst stat = fstatSync(fd);\n\t\t\t\thead = Object.freeze({\n\t\t\t\t\tfileIdentity: fileIdentityOf(stat),\n\t\t\t\t\tsize: stat.size,\n\t\t\t\t\tlastSeq: record.seq,\n\t\t\t\t\tlastHash: record.hash,\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\tcloseSync(fd);\n\t\t\t}\n\t\t\tpublishHead(this.context, head);\n\t\t\tthis.accepted = loadCommitted(this.context, false);\n\t\t\treturn { dropped };\n\t\t} finally {\n\t\t\tmutation.release();\n\t\t}\n\t}\n\n\t/** Release the authority lease; further commits fail closed. */\n\trelease(): void {\n\t\tif (this.released) return;\n\t\tthis.released = true;\n\t\tthis.lease.release();\n\t}\n}\n"]}
@@ -9,6 +9,8 @@ export interface SandboxExecution {
9
9
  readonly maxOutputBytes: number;
10
10
  readonly signal?: AbortSignal;
11
11
  readonly onReady?: (identity: NamespaceIdentity) => void | Promise<void>;
12
+ /** Trusted built-in publisher only: readonly worktree, writable .git, readonly current Node executable. */
13
+ readonly gitPublication?: true;
12
14
  }
13
15
  export interface SandboxOutcome {
14
16
  readonly stdout: Buffer;
@@ -21,6 +23,11 @@ export interface SandboxOutcome {
21
23
  }
22
24
  export declare function commandEnvironmentDigest(contract: RunContract, driver?: "legacy" | "gated-v1"): string;
23
25
  export declare function probeVerifiedSandbox(): void;
24
- /** The only process dispatch port; close means the PID namespace and its inherited pipes have drained. */
26
+ /**
27
+ * The only process dispatch port. Resolution requires two witnesses: the
28
+ * child's `close` (namespace init exited, inherited pipes drained) followed
29
+ * by an empty-member scan of the recorded PID namespace. A platform without
30
+ * the supervised namespace backend is refused, never degraded to best effort.
31
+ */
25
32
  export declare function executeSandbox(request: SandboxExecution): Promise<SandboxOutcome>;
26
33
  //# sourceMappingURL=broker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/broker.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAsCjE,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzE;AACD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,GAAE,QAAQ,GAAG,UAAqB,GAAG,MAAM,CA0ChH;AAED,wBAAgB,oBAAoB,IAAI,IAAI,CAS3C;AAED,0GAA0G;AAC1G,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CA8GvF","sourcesContent":["import { spawn, spawnSync } from \"node:child_process\";\nimport { existsSync, readFileSync, realpathSync } from \"node:fs\";\nimport { release } from \"node:os\";\nimport { performance } from \"node:perf_hooks\";\nimport type { RunContract } from \"omk-protocol\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { identityFromSandboxInfo, PROCESS_GATE_ARGV } from \"./process-gate.ts\";\nimport { digestBytes, digestObject, VerifiedRunError } from \"./storage.ts\";\n\nconst BWRAP = \"/usr/bin/bwrap\";\nconst SYSTEM_ARGS = [\n\t\"--unshare-all\",\n\t\"--die-with-parent\",\n\t\"--new-session\",\n\t\"--cap-drop\",\n\t\"ALL\",\n\t\"--clearenv\",\n\t\"--ro-bind\",\n\t\"/usr\",\n\t\"/usr\",\n\t\"--symlink\",\n\t\"usr/bin\",\n\t\"/bin\",\n\t\"--symlink\",\n\t\"usr/lib\",\n\t\"/lib\",\n\t\"--symlink\",\n\t\"usr/lib64\",\n\t\"/lib64\",\n\t\"--proc\",\n\t\"/proc\",\n\t\"--dev\",\n\t\"/dev\",\n\t\"--tmpfs\",\n\t\"/tmp\",\n\t\"--setenv\",\n\t\"PATH\",\n\t\"/usr/bin:/bin\",\n\t\"--setenv\",\n\t\"LANG\",\n\t\"C.UTF-8\",\n] as const;\n\nexport interface SandboxExecution {\n\treadonly workspace: string;\n\treadonly argv: readonly string[];\n\treadonly writable: boolean;\n\treadonly timeoutMs: number;\n\treadonly cleanupMs: number;\n\treadonly maxOutputBytes: number;\n\treadonly signal?: AbortSignal;\n\treadonly onReady?: (identity: NamespaceIdentity) => void | Promise<void>;\n}\nexport interface SandboxOutcome {\n\treadonly stdout: Buffer;\n\treadonly stderr: Buffer;\n\treadonly exitCode: number | null;\n\treadonly failure: string | null;\n\treadonly startedAt: string;\n\treadonly finishedAt: string;\n\treadonly durationMs: number;\n}\n\nexport function commandEnvironmentDigest(contract: RunContract, driver: \"legacy\" | \"gated-v1\" = \"legacy\"): string {\n\tif (process.platform !== \"linux\" || !existsSync(BWRAP)) throw new VerifiedRunError(\"unsupported\");\n\tlet writers: readonly (readonly string[])[];\n\tswitch (contract.profile) {\n\t\tcase \"linux-command-v1\":\n\t\t\twriters = [contract.writer];\n\t\t\tbreak;\n\t\tcase \"linux-scripted-agent-v1\":\n\t\t\twriters = contract.writer.steps;\n\t\t\tbreak;\n\t\tcase \"linux-command-dag-v1\":\n\t\t\twriters = contract.writer.tasks.flatMap((task) => task.attempts);\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = contract;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tconst binaries = [\n\t\t...new Set([\n\t\t\tBWRAP,\n\t\t\t...writers.map((argv) => argv[0]),\n\t\t\t...contract.checks.map((check) => check.argv[0]),\n\t\t\t...(driver === \"gated-v1\" ? [PROCESS_GATE_ARGV[0]] : []),\n\t\t]),\n\t];\n\tconst materials = binaries.map((binary) => {\n\t\tif (!binary || (!binary.startsWith(\"/usr/bin/\") && !binary.startsWith(\"/bin/\")))\n\t\t\tthrow new VerifiedRunError(\"unsupported_executable\");\n\t\tconst path = realpathSync(binary);\n\t\tif (!path.startsWith(\"/usr/\")) throw new VerifiedRunError(\"unsupported_executable\");\n\t\treturn { path, digest: digestBytes(readFileSync(path)) };\n\t});\n\treturn digestObject({\n\t\tprofile: contract.profile,\n\t\tplatform: process.platform,\n\t\tarchitecture: process.arch,\n\t\tkernel: release(),\n\t\tsandbox: SYSTEM_ARGS,\n\t\t...(driver === \"gated-v1\" ? { gate: PROCESS_GATE_ARGV, infoFd: 3 } : {}),\n\t\tbinaries: materials,\n\t});\n}\n\nexport function probeVerifiedSandbox(): void {\n\tif (process.platform !== \"linux\" || !existsSync(BWRAP)) throw new VerifiedRunError(\"unsupported\");\n\tconst probe = spawnSync(BWRAP, [...SYSTEM_ARGS, \"--\", \"/bin/true\"], {\n\t\tenv: {},\n\t\ttimeout: 3000,\n\t\tmaxBuffer: 4096,\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t});\n\tif (probe.error || probe.status !== 0) throw new VerifiedRunError(\"unsupported\");\n}\n\n/** The only process dispatch port; close means the PID namespace and its inherited pipes have drained. */\nexport async function executeSandbox(request: SandboxExecution): Promise<SandboxOutcome> {\n\tif (request.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tif (request.timeoutMs <= 0) throw new VerifiedRunError(\"deadline\");\n\tconst started = performance.now();\n\tconst startedAt = new Date().toISOString();\n\tconst argv = [\n\t\t...SYSTEM_ARGS,\n\t\trequest.writable ? \"--bind\" : \"--ro-bind\",\n\t\trequest.workspace,\n\t\t\"/workspace\",\n\t\t\"--chdir\",\n\t\t\"/workspace\",\n\t\t...(request.onReady ? [\"--info-fd\", \"3\", \"--\", ...PROCESS_GATE_ARGV] : [\"--\"]),\n\t\t...request.argv,\n\t];\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = request.onReady\n\t\t\t? spawn(BWRAP, argv, { env: {}, stdio: [\"pipe\", \"pipe\", \"pipe\", \"pipe\"] })\n\t\t\t: spawn(BWRAP, argv, { env: {}, stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n\t\tlet gateFailed = false;\n\t\tlet gateError: unknown;\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet size = 0;\n\t\tlet failure: string | null = null;\n\t\tlet cleanup: ReturnType<typeof setTimeout> | undefined;\n\t\tlet finished = false;\n\t\tconst stop = (reason: string): void => {\n\t\t\tif (finished || failure) return;\n\t\t\tfailure = reason;\n\t\t\tchild.kill(\"SIGKILL\");\n\t\t\t// When the gate already failed, surface its real cause rather than a\n\t\t\t// generic unsettled — the close handler may still arrive first, and\n\t\t\t// either path must report the same error.\n\t\t\tcleanup = setTimeout(\n\t\t\t\t() =>\n\t\t\t\t\treject(\n\t\t\t\t\t\tgateFailed ? (gateError ?? new VerifiedRunError(\"unsettled\")) : new VerifiedRunError(\"unsettled\"),\n\t\t\t\t\t),\n\t\t\t\trequest.cleanupMs,\n\t\t\t);\n\t\t};\n\t\tconst deadline = setTimeout(() => stop(\"deadline\"), request.timeoutMs);\n\t\tconst abort = (): void => stop(\"cancelled\");\n\t\trequest.signal?.addEventListener(\"abort\", abort, { once: true });\n\t\tif (request.signal?.aborted) abort();\n\t\tconst collect = (target: Buffer[], chunk: Buffer): void => {\n\t\t\tif (failure) return;\n\t\t\tsize += chunk.length;\n\t\t\tif (size > request.maxOutputBytes) {\n\t\t\t\tstop(\"output_limit\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttarget.push(chunk);\n\t\t};\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => collect(stdout, chunk));\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => collect(stderr, chunk));\n\t\tif (request.onReady) {\n\t\t\tconst info = child.stdio[3];\n\t\t\tlet metadata = \"\";\n\t\t\tif (!info || !child.stdin) {\n\t\t\t\tgateFailed = true;\n\t\t\t\tgateError = new VerifiedRunError(\"process_identity\");\n\t\t\t\tstop(\"process_identity\");\n\t\t\t} else {\n\t\t\t\tchild.stdin.on(\"error\", () => stop(\"execution_failed\"));\n\t\t\t\tinfo.on(\"data\", (chunk: Buffer) => {\n\t\t\t\t\tmetadata += chunk.toString(\"utf8\");\n\t\t\t\t\tif (metadata.length > 4096) stop(\"process_identity\");\n\t\t\t\t});\n\t\t\t\tinfo.once(\"end\", async () => {\n\t\t\t\t\tif (finished || failure) return;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait request.onReady?.(identityFromSandboxInfo(metadata));\n\t\t\t\t\t\tif (performance.now() - started >= request.timeoutMs || request.signal?.aborted)\n\t\t\t\t\t\t\tstop(request.signal?.aborted ? \"cancelled\" : \"deadline\");\n\t\t\t\t\t\tif (!finished && !failure) child.stdin?.end(\"go\\n\");\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tgateFailed = true;\n\t\t\t\t\t\tgateError = error;\n\t\t\t\t\t\tstop(\"process_identity\");\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tchild.once(\"error\", () => {\n\t\t\tfailure = \"execution_failed\";\n\t\t});\n\t\tchild.once(\"close\", (exitCode) => {\n\t\t\tfinished = true;\n\t\t\tclearTimeout(deadline);\n\t\t\tclearTimeout(cleanup);\n\t\t\trequest.signal?.removeEventListener(\"abort\", abort);\n\t\t\tif (gateFailed) {\n\t\t\t\treject(gateError);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst durationMs = Math.max(0, Math.round(performance.now() - started));\n\t\t\tresolve({\n\t\t\t\tstdout: Buffer.concat(stdout),\n\t\t\t\tstderr: Buffer.concat(stderr),\n\t\t\t\texitCode,\n\t\t\t\tfailure: failure ?? (exitCode === 0 ? null : \"execution_failed\"),\n\t\t\t\tstartedAt,\n\t\t\t\t// Project the finish instant from the start's wall reference and monotonic elapsed time.\n\t\t\t\tfinishedAt: new Date(Date.parse(startedAt) + durationMs).toISOString(),\n\t\t\t\tdurationMs,\n\t\t\t});\n\t\t});\n\t});\n}\n"]}
1
+ {"version":3,"file":"bro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;;GAKG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CA6IvF","sourcesContent":["import { spawn, spawnSync } from \"node:child_process\";\nimport { existsSync, readFileSync, realpathSync } from \"node:fs\";\nimport { release } from \"node:os\";\nimport { performance } from \"node:perf_hooks\";\nimport type { RunContract } from \"omk-protocol\";\nimport { ownedGitMounts } from \"./git-sandbox-layout.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { identityFromSandboxInfo, PROCESS_GATE_ARGV } from \"./process-gate.ts\";\nimport { digestBytes, digestObject, VerifiedRunError } from \"./storage.ts\";\nimport {\n\tawaitBoundaryDrained,\n\tescalateTermination,\n\tloadSupervisorBackend,\n\tSUPERVISOR_BINARY,\n\tSUPERVISOR_SYSTEM_ARGS,\n} from \"./supervisor-adapter.ts\";\n\nexport interface SandboxExecution {\n\treadonly workspace: string;\n\treadonly argv: readonly string[];\n\treadonly writable: boolean;\n\treadonly timeoutMs: number;\n\treadonly cleanupMs: number;\n\treadonly maxOutputBytes: number;\n\treadonly signal?: AbortSignal;\n\treadonly onReady?: (identity: NamespaceIdentity) => void | Promise<void>;\n\t/** Trusted built-in publisher only: readonly worktree, writable .git, readonly current Node executable. */\n\treadonly gitPublication?: true;\n}\nexport interface SandboxOutcome {\n\treadonly stdout: Buffer;\n\treadonly stderr: Buffer;\n\treadonly exitCode: number | null;\n\treadonly failure: string | null;\n\treadonly startedAt: string;\n\treadonly finishedAt: string;\n\treadonly durationMs: number;\n}\n\nexport function commandEnvironmentDigest(contract: RunContract, driver: \"legacy\" | \"gated-v1\" = \"legacy\"): string {\n\tif (process.platform !== \"linux\" || !existsSync(SUPERVISOR_BINARY)) throw new VerifiedRunError(\"unsupported\");\n\tlet writers: readonly (readonly string[])[];\n\tswitch (contract.profile) {\n\t\tcase \"linux-command-v1\":\n\t\t\twriters = [contract.writer];\n\t\t\tbreak;\n\t\tcase \"linux-scripted-agent-v1\":\n\t\t\twriters = contract.writer.steps;\n\t\t\tbreak;\n\t\tcase \"linux-command-dag-v1\":\n\t\t\twriters = contract.writer.tasks.flatMap((task) => task.attempts);\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = contract;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tconst binaries = [\n\t\t...new Set([\n\t\t\tSUPERVISOR_BINARY,\n\t\t\t...writers.map((argv) => argv[0]),\n\t\t\t...contract.checks.map((check) => check.argv[0]),\n\t\t\t...(driver === \"gated-v1\" ? [PROCESS_GATE_ARGV[0]] : []),\n\t\t]),\n\t];\n\tconst materials = binaries.map((binary) => {\n\t\tif (!binary || (!binary.startsWith(\"/usr/bin/\") && !binary.startsWith(\"/bin/\")))\n\t\t\tthrow new VerifiedRunError(\"unsupported_executable\");\n\t\tconst path = realpathSync(binary);\n\t\tif (!path.startsWith(\"/usr/\")) throw new VerifiedRunError(\"unsupported_executable\");\n\t\treturn { path, digest: digestBytes(readFileSync(path)) };\n\t});\n\treturn digestObject({\n\t\tprofile: contract.profile,\n\t\tplatform: process.platform,\n\t\tarchitecture: process.arch,\n\t\tkernel: release(),\n\t\tsandbox: SUPERVISOR_SYSTEM_ARGS,\n\t\t...(driver === \"gated-v1\" ? { gate: PROCESS_GATE_ARGV, infoFd: 3 } : {}),\n\t\tbinaries: materials,\n\t});\n}\n\nexport function probeVerifiedSandbox(): void {\n\tif (process.platform !== \"linux\" || !existsSync(SUPERVISOR_BINARY)) throw new VerifiedRunError(\"unsupported\");\n\tconst probe = spawnSync(SUPERVISOR_BINARY, [...SUPERVISOR_SYSTEM_ARGS, \"--\", \"/bin/true\"], {\n\t\tenv: {},\n\t\ttimeout: 3000,\n\t\tmaxBuffer: 4096,\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t});\n\tif (probe.error || probe.status !== 0) throw new VerifiedRunError(\"unsupported\");\n}\n\n/**\n * The only process dispatch port. Resolution requires two witnesses: the\n * child's `close` (namespace init exited, inherited pipes drained) followed\n * by an empty-member scan of the recorded PID namespace. A platform without\n * the supervised namespace backend is refused, never degraded to best effort.\n */\nexport async function executeSandbox(request: SandboxExecution): Promise<SandboxOutcome> {\n\tif (request.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tif (request.timeoutMs <= 0) throw new VerifiedRunError(\"deadline\");\n\t// Dispatch is only defined inside a supervised namespace boundary whose\n\t// identity is committed before candidate code runs; there is no ungated lane.\n\tif (!request.onReady) throw new VerifiedRunError(\"unsupported_boundary\");\n\tconst backend = loadSupervisorBackend();\n\tif (request.gitPublication && request.writable) throw new VerifiedRunError(\"unsupported_boundary\");\n\tconst started = performance.now();\n\tconst startedAt = new Date().toISOString();\n\tconst argv = [\n\t\t...backend.args,\n\t\trequest.writable ? \"--bind\" : \"--ro-bind\",\n\t\trequest.workspace,\n\t\t\"/workspace\",\n\t\t...(request.gitPublication ? ownedGitMounts(request.workspace) : []),\n\t\t\"--chdir\",\n\t\t\"/workspace\",\n\t\t\"--info-fd\",\n\t\t\"3\",\n\t\t\"--\",\n\t\t...PROCESS_GATE_ARGV,\n\t\t...request.argv,\n\t];\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(backend.binary, argv, { env: {}, stdio: [\"pipe\", \"pipe\", \"pipe\", \"pipe\"] });\n\t\tlet identity: NamespaceIdentity | undefined;\n\t\tlet gateFailed = false;\n\t\tlet gateError: unknown;\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet size = 0;\n\t\tlet failure: string | null = null;\n\t\tlet cleanup: ReturnType<typeof setTimeout> | undefined;\n\t\tlet finished = false;\n\t\tconst stop = (reason: string): void => {\n\t\t\tif (finished || failure) return;\n\t\t\tfailure = reason;\n\t\t\tescalateTermination(child);\n\t\t\t// When the gate already failed, surface its real cause rather than a\n\t\t\t// generic unsettled — the close handler may still arrive first, and\n\t\t\t// either path must report the same error.\n\t\t\tcleanup = setTimeout(\n\t\t\t\t() =>\n\t\t\t\t\treject(\n\t\t\t\t\t\tgateFailed ? (gateError ?? new VerifiedRunError(\"unsettled\")) : new VerifiedRunError(\"unsettled\"),\n\t\t\t\t\t),\n\t\t\t\trequest.cleanupMs,\n\t\t\t);\n\t\t};\n\t\tconst deadline = setTimeout(() => stop(\"deadline\"), request.timeoutMs);\n\t\tconst abort = (): void => stop(\"cancelled\");\n\t\trequest.signal?.addEventListener(\"abort\", abort, { once: true });\n\t\tif (request.signal?.aborted) abort();\n\t\tconst collect = (target: Buffer[], chunk: Buffer): void => {\n\t\t\tif (failure) return;\n\t\t\tsize += chunk.length;\n\t\t\tif (size > request.maxOutputBytes) {\n\t\t\t\tstop(\"output_limit\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttarget.push(chunk);\n\t\t};\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => collect(stdout, chunk));\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => collect(stderr, chunk));\n\t\tconst info = child.stdio[3];\n\t\tlet metadata = \"\";\n\t\tif (!info || !child.stdin) {\n\t\t\tgateFailed = true;\n\t\t\tgateError = new VerifiedRunError(\"process_identity\");\n\t\t\tstop(\"process_identity\");\n\t\t} else {\n\t\t\tchild.stdin.on(\"error\", () => stop(\"execution_failed\"));\n\t\t\tinfo.on(\"data\", (chunk: Buffer) => {\n\t\t\t\tmetadata += chunk.toString(\"utf8\");\n\t\t\t\tif (metadata.length > 4096) stop(\"process_identity\");\n\t\t\t});\n\t\t\tinfo.once(\"end\", async () => {\n\t\t\t\tif (finished || failure) return;\n\t\t\t\ttry {\n\t\t\t\t\tidentity = identityFromSandboxInfo(metadata);\n\t\t\t\t\tawait request.onReady?.(identity);\n\t\t\t\t\tif (performance.now() - started >= request.timeoutMs || request.signal?.aborted)\n\t\t\t\t\t\tstop(request.signal?.aborted ? \"cancelled\" : \"deadline\");\n\t\t\t\t\tif (!finished && !failure) child.stdin?.end(\"go\\n\");\n\t\t\t\t} catch (error) {\n\t\t\t\t\tgateFailed = true;\n\t\t\t\t\tgateError = error;\n\t\t\t\t\tstop(\"process_identity\");\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tchild.once(\"error\", () => {\n\t\t\tfailure = \"execution_failed\";\n\t\t});\n\t\tchild.once(\"close\", (exitCode) => {\n\t\t\tfinished = true;\n\t\t\tclearTimeout(deadline);\n\t\t\tclearTimeout(cleanup);\n\t\t\trequest.signal?.removeEventListener(\"abort\", abort);\n\t\t\t// `close` proves only the direct child exited and pipes drained. The\n\t\t\t// termination witness is the recorded namespace reporting no members;\n\t\t\t// until it does, this execution cannot settle and claims stay held.\n\t\t\tconst settle = (drained: \"drained\" | \"populated\" | \"unknown\"): void => {\n\t\t\t\tif (gateFailed) {\n\t\t\t\t\treject(gateError);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (drained === \"populated\") {\n\t\t\t\t\treject(new VerifiedRunError(\"descendant_escape\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (drained === \"unknown\") {\n\t\t\t\t\treject(new VerifiedRunError(\"termination_unverified\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst durationMs = Math.max(0, Math.round(performance.now() - started));\n\t\t\t\tresolve({\n\t\t\t\t\tstdout: Buffer.concat(stdout),\n\t\t\t\t\tstderr: Buffer.concat(stderr),\n\t\t\t\t\texitCode,\n\t\t\t\t\tfailure: failure ?? (exitCode === 0 ? null : \"execution_failed\"),\n\t\t\t\t\tstartedAt,\n\t\t\t\t\t// Project the finish instant from the start's wall reference and monotonic elapsed time.\n\t\t\t\t\tfinishedAt: new Date(Date.parse(startedAt) + durationMs).toISOString(),\n\t\t\t\t\tdurationMs,\n\t\t\t\t});\n\t\t\t};\n\t\t\tif (!identity) {\n\t\t\t\t// The gate never reported an identity: either the spawn itself failed\n\t\t\t\t// or no supervised namespace was recorded. Nothing provably ran, so\n\t\t\t\t// there is nothing to drain — settle on the child outcome alone.\n\t\t\t\tsettle(\"drained\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawaitBoundaryDrained(identity, request.cleanupMs).then(\n\t\t\t\t(drained) => settle(drained),\n\t\t\t\t() => settle(\"unknown\"),\n\t\t\t);\n\t\t});\n\t});\n}\n"]}
@@ -2,43 +2,12 @@ import { spawn, spawnSync } from "node:child_process";
2
2
  import { existsSync, readFileSync, realpathSync } from "node:fs";
3
3
  import { release } from "node:os";
4
4
  import { performance } from "node:perf_hooks";
5
+ import { ownedGitMounts } from "./git-sandbox-layout.js";
5
6
  import { identityFromSandboxInfo, PROCESS_GATE_ARGV } from "./process-gate.js";
6
7
  import { digestBytes, digestObject, VerifiedRunError } from "./storage.js";
7
- const BWRAP = "/usr/bin/bwrap";
8
- const SYSTEM_ARGS = [
9
- "--unshare-all",
10
- "--die-with-parent",
11
- "--new-session",
12
- "--cap-drop",
13
- "ALL",
14
- "--clearenv",
15
- "--ro-bind",
16
- "/usr",
17
- "/usr",
18
- "--symlink",
19
- "usr/bin",
20
- "/bin",
21
- "--symlink",
22
- "usr/lib",
23
- "/lib",
24
- "--symlink",
25
- "usr/lib64",
26
- "/lib64",
27
- "--proc",
28
- "/proc",
29
- "--dev",
30
- "/dev",
31
- "--tmpfs",
32
- "/tmp",
33
- "--setenv",
34
- "PATH",
35
- "/usr/bin:/bin",
36
- "--setenv",
37
- "LANG",
38
- "C.UTF-8",
39
- ];
8
+ import { awaitBoundaryDrained, escalateTermination, loadSupervisorBackend, SUPERVISOR_BINARY, SUPERVISOR_SYSTEM_ARGS, } from "./supervisor-adapter.js";
40
9
  export function commandEnvironmentDigest(contract, driver = "legacy") {
41
- if (process.platform !== "linux" || !existsSync(BWRAP))
10
+ if (process.platform !== "linux" || !existsSync(SUPERVISOR_BINARY))
42
11
  throw new VerifiedRunError("unsupported");
43
12
  let writers;
44
13
  switch (contract.profile) {
@@ -58,7 +27,7 @@ export function commandEnvironmentDigest(contract, driver = "legacy") {
58
27
  }
59
28
  const binaries = [
60
29
  ...new Set([
61
- BWRAP,
30
+ SUPERVISOR_BINARY,
62
31
  ...writers.map((argv) => argv[0]),
63
32
  ...contract.checks.map((check) => check.argv[0]),
64
33
  ...(driver === "gated-v1" ? [PROCESS_GATE_ARGV[0]] : []),
@@ -77,15 +46,15 @@ export function commandEnvironmentDigest(contract, driver = "legacy") {
77
46
  platform: process.platform,
78
47
  architecture: process.arch,
79
48
  kernel: release(),
80
- sandbox: SYSTEM_ARGS,
49
+ sandbox: SUPERVISOR_SYSTEM_ARGS,
81
50
  ...(driver === "gated-v1" ? { gate: PROCESS_GATE_ARGV, infoFd: 3 } : {}),
82
51
  binaries: materials,
83
52
  });
84
53
  }
85
54
  export function probeVerifiedSandbox() {
86
- if (process.platform !== "linux" || !existsSync(BWRAP))
55
+ if (process.platform !== "linux" || !existsSync(SUPERVISOR_BINARY))
87
56
  throw new VerifiedRunError("unsupported");
88
- const probe = spawnSync(BWRAP, [...SYSTEM_ARGS, "--", "/bin/true"], {
57
+ const probe = spawnSync(SUPERVISOR_BINARY, [...SUPERVISOR_SYSTEM_ARGS, "--", "/bin/true"], {
89
58
  env: {},
90
59
  timeout: 3000,
91
60
  maxBuffer: 4096,
@@ -94,28 +63,43 @@ export function probeVerifiedSandbox() {
94
63
  if (probe.error || probe.status !== 0)
95
64
  throw new VerifiedRunError("unsupported");
96
65
  }
97
- /** The only process dispatch port; close means the PID namespace and its inherited pipes have drained. */
66
+ /**
67
+ * The only process dispatch port. Resolution requires two witnesses: the
68
+ * child's `close` (namespace init exited, inherited pipes drained) followed
69
+ * by an empty-member scan of the recorded PID namespace. A platform without
70
+ * the supervised namespace backend is refused, never degraded to best effort.
71
+ */
98
72
  export async function executeSandbox(request) {
99
73
  if (request.signal?.aborted)
100
74
  throw new VerifiedRunError("cancelled");
101
75
  if (request.timeoutMs <= 0)
102
76
  throw new VerifiedRunError("deadline");
77
+ // Dispatch is only defined inside a supervised namespace boundary whose
78
+ // identity is committed before candidate code runs; there is no ungated lane.
79
+ if (!request.onReady)
80
+ throw new VerifiedRunError("unsupported_boundary");
81
+ const backend = loadSupervisorBackend();
82
+ if (request.gitPublication && request.writable)
83
+ throw new VerifiedRunError("unsupported_boundary");
103
84
  const started = performance.now();
104
85
  const startedAt = new Date().toISOString();
105
86
  const argv = [
106
- ...SYSTEM_ARGS,
87
+ ...backend.args,
107
88
  request.writable ? "--bind" : "--ro-bind",
108
89
  request.workspace,
109
90
  "/workspace",
91
+ ...(request.gitPublication ? ownedGitMounts(request.workspace) : []),
110
92
  "--chdir",
111
93
  "/workspace",
112
- ...(request.onReady ? ["--info-fd", "3", "--", ...PROCESS_GATE_ARGV] : ["--"]),
94
+ "--info-fd",
95
+ "3",
96
+ "--",
97
+ ...PROCESS_GATE_ARGV,
113
98
  ...request.argv,
114
99
  ];
115
100
  return new Promise((resolve, reject) => {
116
- const child = request.onReady
117
- ? spawn(BWRAP, argv, { env: {}, stdio: ["pipe", "pipe", "pipe", "pipe"] })
118
- : spawn(BWRAP, argv, { env: {}, stdio: ["ignore", "pipe", "pipe"] });
101
+ const child = spawn(backend.binary, argv, { env: {}, stdio: ["pipe", "pipe", "pipe", "pipe"] });
102
+ let identity;
119
103
  let gateFailed = false;
120
104
  let gateError;
121
105
  const stdout = [];
@@ -128,7 +112,7 @@ export async function executeSandbox(request) {
128
112
  if (finished || failure)
129
113
  return;
130
114
  failure = reason;
131
- child.kill("SIGKILL");
115
+ escalateTermination(child);
132
116
  // When the gate already failed, surface its real cause rather than a
133
117
  // generic unsettled — the close handler may still arrive first, and
134
118
  // either path must report the same error.
@@ -151,38 +135,37 @@ export async function executeSandbox(request) {
151
135
  };
152
136
  child.stdout?.on("data", (chunk) => collect(stdout, chunk));
153
137
  child.stderr?.on("data", (chunk) => collect(stderr, chunk));
154
- if (request.onReady) {
155
- const info = child.stdio[3];
156
- let metadata = "";
157
- if (!info || !child.stdin) {
158
- gateFailed = true;
159
- gateError = new VerifiedRunError("process_identity");
160
- stop("process_identity");
161
- }
162
- else {
163
- child.stdin.on("error", () => stop("execution_failed"));
164
- info.on("data", (chunk) => {
165
- metadata += chunk.toString("utf8");
166
- if (metadata.length > 4096)
167
- stop("process_identity");
168
- });
169
- info.once("end", async () => {
170
- if (finished || failure)
171
- return;
172
- try {
173
- await request.onReady?.(identityFromSandboxInfo(metadata));
174
- if (performance.now() - started >= request.timeoutMs || request.signal?.aborted)
175
- stop(request.signal?.aborted ? "cancelled" : "deadline");
176
- if (!finished && !failure)
177
- child.stdin?.end("go\n");
178
- }
179
- catch (error) {
180
- gateFailed = true;
181
- gateError = error;
182
- stop("process_identity");
183
- }
184
- });
185
- }
138
+ const info = child.stdio[3];
139
+ let metadata = "";
140
+ if (!info || !child.stdin) {
141
+ gateFailed = true;
142
+ gateError = new VerifiedRunError("process_identity");
143
+ stop("process_identity");
144
+ }
145
+ else {
146
+ child.stdin.on("error", () => stop("execution_failed"));
147
+ info.on("data", (chunk) => {
148
+ metadata += chunk.toString("utf8");
149
+ if (metadata.length > 4096)
150
+ stop("process_identity");
151
+ });
152
+ info.once("end", async () => {
153
+ if (finished || failure)
154
+ return;
155
+ try {
156
+ identity = identityFromSandboxInfo(metadata);
157
+ await request.onReady?.(identity);
158
+ if (performance.now() - started >= request.timeoutMs || request.signal?.aborted)
159
+ stop(request.signal?.aborted ? "cancelled" : "deadline");
160
+ if (!finished && !failure)
161
+ child.stdin?.end("go\n");
162
+ }
163
+ catch (error) {
164
+ gateFailed = true;
165
+ gateError = error;
166
+ stop("process_identity");
167
+ }
168
+ });
186
169
  }
187
170
  child.once("error", () => {
188
171
  failure = "execution_failed";
@@ -192,21 +175,42 @@ export async function executeSandbox(request) {
192
175
  clearTimeout(deadline);
193
176
  clearTimeout(cleanup);
194
177
  request.signal?.removeEventListener("abort", abort);
195
- if (gateFailed) {
196
- reject(gateError);
178
+ // `close` proves only the direct child exited and pipes drained. The
179
+ // termination witness is the recorded namespace reporting no members;
180
+ // until it does, this execution cannot settle and claims stay held.
181
+ const settle = (drained) => {
182
+ if (gateFailed) {
183
+ reject(gateError);
184
+ return;
185
+ }
186
+ if (drained === "populated") {
187
+ reject(new VerifiedRunError("descendant_escape"));
188
+ return;
189
+ }
190
+ if (drained === "unknown") {
191
+ reject(new VerifiedRunError("termination_unverified"));
192
+ return;
193
+ }
194
+ const durationMs = Math.max(0, Math.round(performance.now() - started));
195
+ resolve({
196
+ stdout: Buffer.concat(stdout),
197
+ stderr: Buffer.concat(stderr),
198
+ exitCode,
199
+ failure: failure ?? (exitCode === 0 ? null : "execution_failed"),
200
+ startedAt,
201
+ // Project the finish instant from the start's wall reference and monotonic elapsed time.
202
+ finishedAt: new Date(Date.parse(startedAt) + durationMs).toISOString(),
203
+ durationMs,
204
+ });
205
+ };
206
+ if (!identity) {
207
+ // The gate never reported an identity: either the spawn itself failed
208
+ // or no supervised namespace was recorded. Nothing provably ran, so
209
+ // there is nothing to drain — settle on the child outcome alone.
210
+ settle("drained");
197
211
  return;
198
212
  }
199
- const durationMs = Math.max(0, Math.round(performance.now() - started));
200
- resolve({
201
- stdout: Buffer.concat(stdout),
202
- stderr: Buffer.concat(stderr),
203
- exitCode,
204
- failure: failure ?? (exitCode === 0 ? null : "execution_failed"),
205
- startedAt,
206
- // Project the finish instant from the start's wall reference and monotonic elapsed time.
207
- finishedAt: new Date(Date.parse(startedAt) + durationMs).toISOString(),
208
- durationMs,
209
- });
213
+ awaitBoundaryDrained(identity, request.cleanupMs).then((drained) => settle(drained), () => settle("unknown"));
210
214
  });
211
215
  });
212
216
  }
@@ -1 +1 @@
1
- {"version":3,"file":"broker.js","sourceRoot":"","sources":["../../../src/core/verified-run/broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,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;IAAA,CACH,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { spawn, spawnSync } from \"node:child_process\";\nimport { existsSync, readFileSync, realpathSync } from \"node:fs\";\nimport { release } from \"node:os\";\nimport { performance } from \"node:perf_hooks\";\nimport type { RunContract } from \"omk-protocol\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { identityFromSandboxInfo, PROCESS_GATE_ARGV } from \"./process-gate.ts\";\nimport { digestBytes, digestObject, VerifiedRunError } from \"./storage.ts\";\n\nconst BWRAP = \"/usr/bin/bwrap\";\nconst SYSTEM_ARGS = [\n\t\"--unshare-all\",\n\t\"--die-with-parent\",\n\t\"--new-session\",\n\t\"--cap-drop\",\n\t\"ALL\",\n\t\"--clearenv\",\n\t\"--ro-bind\",\n\t\"/usr\",\n\t\"/usr\",\n\t\"--symlink\",\n\t\"usr/bin\",\n\t\"/bin\",\n\t\"--symlink\",\n\t\"usr/lib\",\n\t\"/lib\",\n\t\"--symlink\",\n\t\"usr/lib64\",\n\t\"/lib64\",\n\t\"--proc\",\n\t\"/proc\",\n\t\"--dev\",\n\t\"/dev\",\n\t\"--tmpfs\",\n\t\"/tmp\",\n\t\"--setenv\",\n\t\"PATH\",\n\t\"/usr/bin:/bin\",\n\t\"--setenv\",\n\t\"LANG\",\n\t\"C.UTF-8\",\n] as const;\n\nexport interface SandboxExecution {\n\treadonly workspace: string;\n\treadonly argv: readonly string[];\n\treadonly writable: boolean;\n\treadonly timeoutMs: number;\n\treadonly cleanupMs: number;\n\treadonly maxOutputBytes: number;\n\treadonly signal?: AbortSignal;\n\treadonly onReady?: (identity: NamespaceIdentity) => void | Promise<void>;\n}\nexport interface SandboxOutcome {\n\treadonly stdout: Buffer;\n\treadonly stderr: Buffer;\n\treadonly exitCode: number | null;\n\treadonly failure: string | null;\n\treadonly startedAt: string;\n\treadonly finishedAt: string;\n\treadonly durationMs: number;\n}\n\nexport function commandEnvironmentDigest(contract: RunContract, driver: \"legacy\" | \"gated-v1\" = \"legacy\"): string {\n\tif (process.platform !== \"linux\" || !existsSync(BWRAP)) throw new VerifiedRunError(\"unsupported\");\n\tlet writers: readonly (readonly string[])[];\n\tswitch (contract.profile) {\n\t\tcase \"linux-command-v1\":\n\t\t\twriters = [contract.writer];\n\t\t\tbreak;\n\t\tcase \"linux-scripted-agent-v1\":\n\t\t\twriters = contract.writer.steps;\n\t\t\tbreak;\n\t\tcase \"linux-command-dag-v1\":\n\t\t\twriters = contract.writer.tasks.flatMap((task) => task.attempts);\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = contract;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tconst binaries = [\n\t\t...new Set([\n\t\t\tBWRAP,\n\t\t\t...writers.map((argv) => argv[0]),\n\t\t\t...contract.checks.map((check) => check.argv[0]),\n\t\t\t...(driver === \"gated-v1\" ? [PROCESS_GATE_ARGV[0]] : []),\n\t\t]),\n\t];\n\tconst materials = binaries.map((binary) => {\n\t\tif (!binary || (!binary.startsWith(\"/usr/bin/\") && !binary.startsWith(\"/bin/\")))\n\t\t\tthrow new VerifiedRunError(\"unsupported_executable\");\n\t\tconst path = realpathSync(binary);\n\t\tif (!path.startsWith(\"/usr/\")) throw new VerifiedRunError(\"unsupported_executable\");\n\t\treturn { path, digest: digestBytes(readFileSync(path)) };\n\t});\n\treturn digestObject({\n\t\tprofile: contract.profile,\n\t\tplatform: process.platform,\n\t\tarchitecture: process.arch,\n\t\tkernel: release(),\n\t\tsandbox: SYSTEM_ARGS,\n\t\t...(driver === \"gated-v1\" ? { gate: PROCESS_GATE_ARGV, infoFd: 3 } : {}),\n\t\tbinaries: materials,\n\t});\n}\n\nexport function probeVerifiedSandbox(): void {\n\tif (process.platform !== \"linux\" || !existsSync(BWRAP)) throw new VerifiedRunError(\"unsupported\");\n\tconst probe = spawnSync(BWRAP, [...SYSTEM_ARGS, \"--\", \"/bin/true\"], {\n\t\tenv: {},\n\t\ttimeout: 3000,\n\t\tmaxBuffer: 4096,\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t});\n\tif (probe.error || probe.status !== 0) throw new VerifiedRunError(\"unsupported\");\n}\n\n/** The only process dispatch port; close means the PID namespace and its inherited pipes have drained. */\nexport async function executeSandbox(request: SandboxExecution): Promise<SandboxOutcome> {\n\tif (request.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tif (request.timeoutMs <= 0) throw new VerifiedRunError(\"deadline\");\n\tconst started = performance.now();\n\tconst startedAt = new Date().toISOString();\n\tconst argv = [\n\t\t...SYSTEM_ARGS,\n\t\trequest.writable ? \"--bind\" : \"--ro-bind\",\n\t\trequest.workspace,\n\t\t\"/workspace\",\n\t\t\"--chdir\",\n\t\t\"/workspace\",\n\t\t...(request.onReady ? [\"--info-fd\", \"3\", \"--\", ...PROCESS_GATE_ARGV] : [\"--\"]),\n\t\t...request.argv,\n\t];\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = request.onReady\n\t\t\t? spawn(BWRAP, argv, { env: {}, stdio: [\"pipe\", \"pipe\", \"pipe\", \"pipe\"] })\n\t\t\t: spawn(BWRAP, argv, { env: {}, stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n\t\tlet gateFailed = false;\n\t\tlet gateError: unknown;\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet size = 0;\n\t\tlet failure: string | null = null;\n\t\tlet cleanup: ReturnType<typeof setTimeout> | undefined;\n\t\tlet finished = false;\n\t\tconst stop = (reason: string): void => {\n\t\t\tif (finished || failure) return;\n\t\t\tfailure = reason;\n\t\t\tchild.kill(\"SIGKILL\");\n\t\t\t// When the gate already failed, surface its real cause rather than a\n\t\t\t// generic unsettled — the close handler may still arrive first, and\n\t\t\t// either path must report the same error.\n\t\t\tcleanup = setTimeout(\n\t\t\t\t() =>\n\t\t\t\t\treject(\n\t\t\t\t\t\tgateFailed ? (gateError ?? new VerifiedRunError(\"unsettled\")) : new VerifiedRunError(\"unsettled\"),\n\t\t\t\t\t),\n\t\t\t\trequest.cleanupMs,\n\t\t\t);\n\t\t};\n\t\tconst deadline = setTimeout(() => stop(\"deadline\"), request.timeoutMs);\n\t\tconst abort = (): void => stop(\"cancelled\");\n\t\trequest.signal?.addEventListener(\"abort\", abort, { once: true });\n\t\tif (request.signal?.aborted) abort();\n\t\tconst collect = (target: Buffer[], chunk: Buffer): void => {\n\t\t\tif (failure) return;\n\t\t\tsize += chunk.length;\n\t\t\tif (size > request.maxOutputBytes) {\n\t\t\t\tstop(\"output_limit\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttarget.push(chunk);\n\t\t};\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => collect(stdout, chunk));\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => collect(stderr, chunk));\n\t\tif (request.onReady) {\n\t\t\tconst info = child.stdio[3];\n\t\t\tlet metadata = \"\";\n\t\t\tif (!info || !child.stdin) {\n\t\t\t\tgateFailed = true;\n\t\t\t\tgateError = new VerifiedRunError(\"process_identity\");\n\t\t\t\tstop(\"process_identity\");\n\t\t\t} else {\n\t\t\t\tchild.stdin.on(\"error\", () => stop(\"execution_failed\"));\n\t\t\t\tinfo.on(\"data\", (chunk: Buffer) => {\n\t\t\t\t\tmetadata += chunk.toString(\"utf8\");\n\t\t\t\t\tif (metadata.length > 4096) stop(\"process_identity\");\n\t\t\t\t});\n\t\t\t\tinfo.once(\"end\", async () => {\n\t\t\t\t\tif (finished || failure) return;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait request.onReady?.(identityFromSandboxInfo(metadata));\n\t\t\t\t\t\tif (performance.now() - started >= request.timeoutMs || request.signal?.aborted)\n\t\t\t\t\t\t\tstop(request.signal?.aborted ? \"cancelled\" : \"deadline\");\n\t\t\t\t\t\tif (!finished && !failure) child.stdin?.end(\"go\\n\");\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tgateFailed = true;\n\t\t\t\t\t\tgateError = error;\n\t\t\t\t\t\tstop(\"process_identity\");\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tchild.once(\"error\", () => {\n\t\t\tfailure = \"execution_failed\";\n\t\t});\n\t\tchild.once(\"close\", (exitCode) => {\n\t\t\tfinished = true;\n\t\t\tclearTimeout(deadline);\n\t\t\tclearTimeout(cleanup);\n\t\t\trequest.signal?.removeEventListener(\"abort\", abort);\n\t\t\tif (gateFailed) {\n\t\t\t\treject(gateError);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst durationMs = Math.max(0, Math.round(performance.now() - started));\n\t\t\tresolve({\n\t\t\t\tstdout: Buffer.concat(stdout),\n\t\t\t\tstderr: Buffer.concat(stderr),\n\t\t\t\texitCode,\n\t\t\t\tfailure: failure ?? (exitCode === 0 ? null : \"execution_failed\"),\n\t\t\t\tstartedAt,\n\t\t\t\t// Project the finish instant from the start's wall reference and monotonic elapsed time.\n\t\t\t\tfinishedAt: new Date(Date.parse(startedAt) + durationMs).toISOString(),\n\t\t\t\tdurationMs,\n\t\t\t});\n\t\t});\n\t});\n}\n"]}
1
+ {"version":3,"file":"broker.js","sourceRoot":"","sources":["../../../src/core/verified-run/broker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EACN,oBAAoB,EACpB,mBAAmB,EACnB,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AC;YACF,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACf,sEAAsE;gBACtE,oEAAoE;gBACpE,mEAAiE;gBACjE,MAAM,CAAC,SAAS,CAAC,CAAC;gBAClB,OAAO;YACR,CAAC;YACD,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CACrD,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAC5B,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CACvB,CAAC;QAAA,CACF,CAAC,CAAC;IAAA,CACH,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { spawn, spawnSync } from \"node:child_process\";\nimport { existsSync, readFileSync, realpathSync } from \"node:fs\";\nimport { release } from \"node:os\";\nimport { performance } from \"node:perf_hooks\";\nimport type { RunContract } from \"omk-protocol\";\nimport { ownedGitMounts } from \"./git-sandbox-layout.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { identityFromSandboxInfo, PROCESS_GATE_ARGV } from \"./process-gate.ts\";\nimport { digestBytes, digestObject, VerifiedRunError } from \"./storage.ts\";\nimport {\n\tawaitBoundaryDrained,\n\tescalateTermination,\n\tloadSupervisorBackend,\n\tSUPERVISOR_BINARY,\n\tSUPERVISOR_SYSTEM_ARGS,\n} from \"./supervisor-adapter.ts\";\n\nexport interface SandboxExecution {\n\treadonly workspace: string;\n\treadonly argv: readonly string[];\n\treadonly writable: boolean;\n\treadonly timeoutMs: number;\n\treadonly cleanupMs: number;\n\treadonly maxOutputBytes: number;\n\treadonly signal?: AbortSignal;\n\treadonly onReady?: (identity: NamespaceIdentity) => void | Promise<void>;\n\t/** Trusted built-in publisher only: readonly worktree, writable .git, readonly current Node executable. */\n\treadonly gitPublication?: true;\n}\nexport interface SandboxOutcome {\n\treadonly stdout: Buffer;\n\treadonly stderr: Buffer;\n\treadonly exitCode: number | null;\n\treadonly failure: string | null;\n\treadonly startedAt: string;\n\treadonly finishedAt: string;\n\treadonly durationMs: number;\n}\n\nexport function commandEnvironmentDigest(contract: RunContract, driver: \"legacy\" | \"gated-v1\" = \"legacy\"): string {\n\tif (process.platform !== \"linux\" || !existsSync(SUPERVISOR_BINARY)) throw new VerifiedRunError(\"unsupported\");\n\tlet writers: readonly (readonly string[])[];\n\tswitch (contract.profile) {\n\t\tcase \"linux-command-v1\":\n\t\t\twriters = [contract.writer];\n\t\t\tbreak;\n\t\tcase \"linux-scripted-agent-v1\":\n\t\t\twriters = contract.writer.steps;\n\t\t\tbreak;\n\t\tcase \"linux-command-dag-v1\":\n\t\t\twriters = contract.writer.tasks.flatMap((task) => task.attempts);\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = contract;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tconst binaries = [\n\t\t...new Set([\n\t\t\tSUPERVISOR_BINARY,\n\t\t\t...writers.map((argv) => argv[0]),\n\t\t\t...contract.checks.map((check) => check.argv[0]),\n\t\t\t...(driver === \"gated-v1\" ? [PROCESS_GATE_ARGV[0]] : []),\n\t\t]),\n\t];\n\tconst materials = binaries.map((binary) => {\n\t\tif (!binary || (!binary.startsWith(\"/usr/bin/\") && !binary.startsWith(\"/bin/\")))\n\t\t\tthrow new VerifiedRunError(\"unsupported_executable\");\n\t\tconst path = realpathSync(binary);\n\t\tif (!path.startsWith(\"/usr/\")) throw new VerifiedRunError(\"unsupported_executable\");\n\t\treturn { path, digest: digestBytes(readFileSync(path)) };\n\t});\n\treturn digestObject({\n\t\tprofile: contract.profile,\n\t\tplatform: process.platform,\n\t\tarchitecture: process.arch,\n\t\tkernel: release(),\n\t\tsandbox: SUPERVISOR_SYSTEM_ARGS,\n\t\t...(driver === \"gated-v1\" ? { gate: PROCESS_GATE_ARGV, infoFd: 3 } : {}),\n\t\tbinaries: materials,\n\t});\n}\n\nexport function probeVerifiedSandbox(): void {\n\tif (process.platform !== \"linux\" || !existsSync(SUPERVISOR_BINARY)) throw new VerifiedRunError(\"unsupported\");\n\tconst probe = spawnSync(SUPERVISOR_BINARY, [...SUPERVISOR_SYSTEM_ARGS, \"--\", \"/bin/true\"], {\n\t\tenv: {},\n\t\ttimeout: 3000,\n\t\tmaxBuffer: 4096,\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t});\n\tif (probe.error || probe.status !== 0) throw new VerifiedRunError(\"unsupported\");\n}\n\n/**\n * The only process dispatch port. Resolution requires two witnesses: the\n * child's `close` (namespace init exited, inherited pipes drained) followed\n * by an empty-member scan of the recorded PID namespace. A platform without\n * the supervised namespace backend is refused, never degraded to best effort.\n */\nexport async function executeSandbox(request: SandboxExecution): Promise<SandboxOutcome> {\n\tif (request.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tif (request.timeoutMs <= 0) throw new VerifiedRunError(\"deadline\");\n\t// Dispatch is only defined inside a supervised namespace boundary whose\n\t// identity is committed before candidate code runs; there is no ungated lane.\n\tif (!request.onReady) throw new VerifiedRunError(\"unsupported_boundary\");\n\tconst backend = loadSupervisorBackend();\n\tif (request.gitPublication && request.writable) throw new VerifiedRunError(\"unsupported_boundary\");\n\tconst started = performance.now();\n\tconst startedAt = new Date().toISOString();\n\tconst argv = [\n\t\t...backend.args,\n\t\trequest.writable ? \"--bind\" : \"--ro-bind\",\n\t\trequest.workspace,\n\t\t\"/workspace\",\n\t\t...(request.gitPublication ? ownedGitMounts(request.workspace) : []),\n\t\t\"--chdir\",\n\t\t\"/workspace\",\n\t\t\"--info-fd\",\n\t\t\"3\",\n\t\t\"--\",\n\t\t...PROCESS_GATE_ARGV,\n\t\t...request.argv,\n\t];\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(backend.binary, argv, { env: {}, stdio: [\"pipe\", \"pipe\", \"pipe\", \"pipe\"] });\n\t\tlet identity: NamespaceIdentity | undefined;\n\t\tlet gateFailed = false;\n\t\tlet gateError: unknown;\n\t\tconst stdout: Buffer[] = [];\n\t\tconst stderr: Buffer[] = [];\n\t\tlet size = 0;\n\t\tlet failure: string | null = null;\n\t\tlet cleanup: ReturnType<typeof setTimeout> | undefined;\n\t\tlet finished = false;\n\t\tconst stop = (reason: string): void => {\n\t\t\tif (finished || failure) return;\n\t\t\tfailure = reason;\n\t\t\tescalateTermination(child);\n\t\t\t// When the gate already failed, surface its real cause rather than a\n\t\t\t// generic unsettled — the close handler may still arrive first, and\n\t\t\t// either path must report the same error.\n\t\t\tcleanup = setTimeout(\n\t\t\t\t() =>\n\t\t\t\t\treject(\n\t\t\t\t\t\tgateFailed ? (gateError ?? new VerifiedRunError(\"unsettled\")) : new VerifiedRunError(\"unsettled\"),\n\t\t\t\t\t),\n\t\t\t\trequest.cleanupMs,\n\t\t\t);\n\t\t};\n\t\tconst deadline = setTimeout(() => stop(\"deadline\"), request.timeoutMs);\n\t\tconst abort = (): void => stop(\"cancelled\");\n\t\trequest.signal?.addEventListener(\"abort\", abort, { once: true });\n\t\tif (request.signal?.aborted) abort();\n\t\tconst collect = (target: Buffer[], chunk: Buffer): void => {\n\t\t\tif (failure) return;\n\t\t\tsize += chunk.length;\n\t\t\tif (size > request.maxOutputBytes) {\n\t\t\t\tstop(\"output_limit\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttarget.push(chunk);\n\t\t};\n\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => collect(stdout, chunk));\n\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => collect(stderr, chunk));\n\t\tconst info = child.stdio[3];\n\t\tlet metadata = \"\";\n\t\tif (!info || !child.stdin) {\n\t\t\tgateFailed = true;\n\t\t\tgateError = new VerifiedRunError(\"process_identity\");\n\t\t\tstop(\"process_identity\");\n\t\t} else {\n\t\t\tchild.stdin.on(\"error\", () => stop(\"execution_failed\"));\n\t\t\tinfo.on(\"data\", (chunk: Buffer) => {\n\t\t\t\tmetadata += chunk.toString(\"utf8\");\n\t\t\t\tif (metadata.length > 4096) stop(\"process_identity\");\n\t\t\t});\n\t\t\tinfo.once(\"end\", async () => {\n\t\t\t\tif (finished || failure) return;\n\t\t\t\ttry {\n\t\t\t\t\tidentity = identityFromSandboxInfo(metadata);\n\t\t\t\t\tawait request.onReady?.(identity);\n\t\t\t\t\tif (performance.now() - started >= request.timeoutMs || request.signal?.aborted)\n\t\t\t\t\t\tstop(request.signal?.aborted ? \"cancelled\" : \"deadline\");\n\t\t\t\t\tif (!finished && !failure) child.stdin?.end(\"go\\n\");\n\t\t\t\t} catch (error) {\n\t\t\t\t\tgateFailed = true;\n\t\t\t\t\tgateError = error;\n\t\t\t\t\tstop(\"process_identity\");\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tchild.once(\"error\", () => {\n\t\t\tfailure = \"execution_failed\";\n\t\t});\n\t\tchild.once(\"close\", (exitCode) => {\n\t\t\tfinished = true;\n\t\t\tclearTimeout(deadline);\n\t\t\tclearTimeout(cleanup);\n\t\t\trequest.signal?.removeEventListener(\"abort\", abort);\n\t\t\t// `close` proves only the direct child exited and pipes drained. The\n\t\t\t// termination witness is the recorded namespace reporting no members;\n\t\t\t// until it does, this execution cannot settle and claims stay held.\n\t\t\tconst settle = (drained: \"drained\" | \"populated\" | \"unknown\"): void => {\n\t\t\t\tif (gateFailed) {\n\t\t\t\t\treject(gateError);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (drained === \"populated\") {\n\t\t\t\t\treject(new VerifiedRunError(\"descendant_escape\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (drained === \"unknown\") {\n\t\t\t\t\treject(new VerifiedRunError(\"termination_unverified\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst durationMs = Math.max(0, Math.round(performance.now() - started));\n\t\t\t\tresolve({\n\t\t\t\t\tstdout: Buffer.concat(stdout),\n\t\t\t\t\tstderr: Buffer.concat(stderr),\n\t\t\t\t\texitCode,\n\t\t\t\t\tfailure: failure ?? (exitCode === 0 ? null : \"execution_failed\"),\n\t\t\t\t\tstartedAt,\n\t\t\t\t\t// Project the finish instant from the start's wall reference and monotonic elapsed time.\n\t\t\t\t\tfinishedAt: new Date(Date.parse(startedAt) + durationMs).toISOString(),\n\t\t\t\t\tdurationMs,\n\t\t\t\t});\n\t\t\t};\n\t\t\tif (!identity) {\n\t\t\t\t// The gate never reported an identity: either the spawn itself failed\n\t\t\t\t// or no supervised namespace was recorded. Nothing provably ran, so\n\t\t\t\t// there is nothing to drain — settle on the child outcome alone.\n\t\t\t\tsettle(\"drained\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawaitBoundaryDrained(identity, request.cleanupMs).then(\n\t\t\t\t(drained) => settle(drained),\n\t\t\t\t() => settle(\"unknown\"),\n\t\t\t);\n\t\t});\n\t});\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /** Whole-tree inclusion, with explicit metadata exclusions and sensitive-name rejection. */
2
+ export declare const CANDIDATE_POLICY: Readonly<{
3
+ version: "whole-tree-sensitive-names-v1";
4
+ excludedRoots: readonly string[];
5
+ deniedNames: readonly string[];
6
+ deniedSuffixes: readonly string[];
7
+ }>;
8
+ export declare function safeCandidatePath(path: string): void;
9
+ export declare function assertPublishablePath(path: string): void;
10
+ //# sourceMappingURL=candidate-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"candidate-policy.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/candidate-policy.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB;;;;;EAgB3B,CAAC;AAGH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAQpD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAIxD","sourcesContent":["import { VerifiedRunError } from \"./storage.ts\";\n\n/** Whole-tree inclusion, with explicit metadata exclusions and sensitive-name rejection. */\nexport const CANDIDATE_POLICY = Object.freeze({\n\tversion: \"whole-tree-sensitive-names-v1\",\n\texcludedRoots: Object.freeze([\".git\", \".omk\"]),\n\tdeniedNames: Object.freeze([\n\t\t\".env\",\n\t\t\".env.local\",\n\t\t\".env.production\",\n\t\t\".env.development\",\n\t\t\".npmrc\",\n\t\t\".netrc\",\n\t\t\".pypirc\",\n\t\t\"credentials.json\",\n\t\t\"id_rsa\",\n\t\t\"id_ed25519\",\n\t]),\n\tdeniedSuffixes: Object.freeze([\".pem\", \".key\"]),\n});\nconst denied = new Set(CANDIDATE_POLICY.deniedNames);\n\nexport function safeCandidatePath(path: string): void {\n\tif (\n\t\t!path ||\n\t\tBuffer.from(path, \"utf8\").toString(\"utf8\") !== path ||\n\t\t/[\\\\\\u0000-\\u001f\\u007f]/.test(path) ||\n\t\tpath.split(\"/\").some((part) => [\"\", \".\", \"..\", \".git\", \".omk\"].includes(part))\n\t)\n\t\tthrow new VerifiedRunError(\"file_type\");\n}\n\nexport function assertPublishablePath(path: string): void {\n\tconst name = path.slice(path.lastIndexOf(\"/\") + 1);\n\tif (denied.has(name) || CANDIDATE_POLICY.deniedSuffixes.some((suffix) => name.endsWith(suffix)))\n\t\tthrow new VerifiedRunError(\"secret_path\");\n}\n"]}