subharness 0.0.7 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/README.md +40 -9
  2. package/dist/adapters/claude-events.d.ts +71 -0
  3. package/dist/adapters/claude-events.js +860 -0
  4. package/dist/adapters/claude-events.js.map +1 -0
  5. package/dist/adapters/claude-worker-client.d.ts +11 -0
  6. package/dist/adapters/claude-worker-client.js +219 -5
  7. package/dist/adapters/claude-worker-client.js.map +1 -1
  8. package/dist/adapters/claude-worker-protocol.d.ts +58 -0
  9. package/dist/adapters/claude-worker-protocol.js.map +1 -1
  10. package/dist/adapters/claude-worker.js +48 -3
  11. package/dist/adapters/claude-worker.js.map +1 -1
  12. package/dist/adapters/claude.d.ts +5 -1
  13. package/dist/adapters/claude.js +14 -2
  14. package/dist/adapters/claude.js.map +1 -1
  15. package/dist/adapters/codex-events.d.ts +52 -0
  16. package/dist/adapters/codex-events.js +672 -0
  17. package/dist/adapters/codex-events.js.map +1 -0
  18. package/dist/adapters/codex-turn-failure.d.ts +2 -0
  19. package/dist/adapters/codex-turn-failure.js +116 -0
  20. package/dist/adapters/codex-turn-failure.js.map +1 -0
  21. package/dist/adapters/codex.js +44 -7
  22. package/dist/adapters/codex.js.map +1 -1
  23. package/dist/adapters/copilot-events.d.ts +68 -0
  24. package/dist/adapters/copilot-events.js +650 -0
  25. package/dist/adapters/copilot-events.js.map +1 -0
  26. package/dist/adapters/copilot.js +24 -4
  27. package/dist/adapters/copilot.js.map +1 -1
  28. package/dist/adapters/cursor-acp-events.d.ts +36 -0
  29. package/dist/adapters/cursor-acp-events.js +251 -0
  30. package/dist/adapters/cursor-acp-events.js.map +1 -0
  31. package/dist/adapters/cursor-cli-session.d.ts +1 -0
  32. package/dist/adapters/cursor-cli-session.js +26 -5
  33. package/dist/adapters/cursor-cli-session.js.map +1 -1
  34. package/dist/adapters/cursor-cli.js +5 -0
  35. package/dist/adapters/cursor-cli.js.map +1 -1
  36. package/dist/adapters/cursor-sdk-events.d.ts +30 -0
  37. package/dist/adapters/cursor-sdk-events.js +233 -0
  38. package/dist/adapters/cursor-sdk-events.js.map +1 -0
  39. package/dist/adapters/cursor-session.js +56 -7
  40. package/dist/adapters/cursor-session.js.map +1 -1
  41. package/dist/adapters/cursor-startup.js +8 -2
  42. package/dist/adapters/cursor-startup.js.map +1 -1
  43. package/dist/adapters/event-normalizer.d.ts +57 -0
  44. package/dist/adapters/event-normalizer.js +143 -0
  45. package/dist/adapters/event-normalizer.js.map +1 -0
  46. package/dist/adapters/event-secrets.d.ts +17 -0
  47. package/dist/adapters/event-secrets.js +28 -0
  48. package/dist/adapters/event-secrets.js.map +1 -0
  49. package/dist/adapters/event-types.d.ts +58 -0
  50. package/dist/adapters/event-types.js +2 -0
  51. package/dist/adapters/event-types.js.map +1 -0
  52. package/dist/adapters/fx-events.d.ts +37 -0
  53. package/dist/adapters/fx-events.js +393 -0
  54. package/dist/adapters/fx-events.js.map +1 -0
  55. package/dist/adapters/fx-rpc.d.ts +2 -0
  56. package/dist/adapters/fx-rpc.js +11 -5
  57. package/dist/adapters/fx-rpc.js.map +1 -1
  58. package/dist/adapters/fx.js +73 -8
  59. package/dist/adapters/fx.js.map +1 -1
  60. package/dist/adapters/opencode-events.d.ts +58 -0
  61. package/dist/adapters/opencode-events.js +653 -0
  62. package/dist/adapters/opencode-events.js.map +1 -0
  63. package/dist/adapters/opencode-http.d.ts +1 -0
  64. package/dist/adapters/opencode-http.js +8 -7
  65. package/dist/adapters/opencode-http.js.map +1 -1
  66. package/dist/adapters/opencode.js +50 -9
  67. package/dist/adapters/opencode.js.map +1 -1
  68. package/dist/adapters/rpc.d.ts +2 -0
  69. package/dist/adapters/rpc.js +11 -5
  70. package/dist/adapters/rpc.js.map +1 -1
  71. package/dist/adapters/types.d.ts +2 -0
  72. package/dist/adapters/types.js.map +1 -1
  73. package/dist/cli/args.d.ts +6 -1
  74. package/dist/cli/args.js +63 -5
  75. package/dist/cli/args.js.map +1 -1
  76. package/dist/cli/catalog-worker.js +3 -2
  77. package/dist/cli/catalog-worker.js.map +1 -1
  78. package/dist/cli/dashboard-client.d.ts +1 -0
  79. package/dist/cli/dashboard-client.js +13 -1
  80. package/dist/cli/dashboard-client.js.map +1 -1
  81. package/dist/cli/dashboard-controller.js +6 -7
  82. package/dist/cli/dashboard-controller.js.map +1 -1
  83. package/dist/cli/dashboard-detail-view.d.ts +14 -8
  84. package/dist/cli/dashboard-detail-view.js +15 -44
  85. package/dist/cli/dashboard-detail-view.js.map +1 -1
  86. package/dist/cli/dashboard-history-view.d.ts +3 -12
  87. package/dist/cli/dashboard-history-view.js +18 -82
  88. package/dist/cli/dashboard-history-view.js.map +1 -1
  89. package/dist/cli/dashboard-live.d.ts +32 -0
  90. package/dist/cli/dashboard-live.js +177 -0
  91. package/dist/cli/dashboard-live.js.map +1 -0
  92. package/dist/cli/dashboard-renderer.d.ts +21 -1
  93. package/dist/cli/dashboard-renderer.js +85 -21
  94. package/dist/cli/dashboard-renderer.js.map +1 -1
  95. package/dist/cli/dashboard-steps.d.ts +53 -0
  96. package/dist/cli/dashboard-steps.js +157 -0
  97. package/dist/cli/dashboard-steps.js.map +1 -0
  98. package/dist/cli/dashboard-task-format.d.ts +15 -0
  99. package/dist/cli/dashboard-task-format.js +119 -0
  100. package/dist/cli/dashboard-task-format.js.map +1 -0
  101. package/dist/cli/dashboard-task-view.d.ts +66 -0
  102. package/dist/cli/dashboard-task-view.js +325 -0
  103. package/dist/cli/dashboard-task-view.js.map +1 -0
  104. package/dist/cli/dashboard.d.ts +2 -0
  105. package/dist/cli/dashboard.js +71 -6
  106. package/dist/cli/dashboard.js.map +1 -1
  107. package/dist/cli/extensions-client.d.ts +23 -0
  108. package/dist/cli/extensions-client.js +147 -0
  109. package/dist/cli/extensions-client.js.map +1 -0
  110. package/dist/cli/extensions.d.ts +15 -0
  111. package/dist/cli/extensions.js +187 -0
  112. package/dist/cli/extensions.js.map +1 -0
  113. package/dist/cli/help.d.ts +1 -0
  114. package/dist/cli/help.js +34 -6
  115. package/dist/cli/help.js.map +1 -1
  116. package/dist/cli/main.js +100 -10
  117. package/dist/cli/main.js.map +1 -1
  118. package/dist/cli/output.js +5 -1
  119. package/dist/cli/output.js.map +1 -1
  120. package/dist/config/access.d.ts +2 -1
  121. package/dist/config/access.js +18 -7
  122. package/dist/config/access.js.map +1 -1
  123. package/dist/config/loader.d.ts +2 -0
  124. package/dist/config/loader.js +20 -6
  125. package/dist/config/loader.js.map +1 -1
  126. package/dist/config/project-context.d.ts +9 -0
  127. package/dist/config/project-context.js +41 -0
  128. package/dist/config/project-context.js.map +1 -0
  129. package/dist/config/resolve-access.d.ts +2 -1
  130. package/dist/config/resolve-access.js +5 -2
  131. package/dist/config/resolve-access.js.map +1 -1
  132. package/dist/events/content.d.ts +43 -0
  133. package/dist/events/content.js +249 -0
  134. package/dist/events/content.js.map +1 -0
  135. package/dist/events/queue.d.ts +59 -0
  136. package/dist/events/queue.js +144 -0
  137. package/dist/events/queue.js.map +1 -0
  138. package/dist/events/validate.d.ts +22 -0
  139. package/dist/events/validate.js +542 -0
  140. package/dist/events/validate.js.map +1 -0
  141. package/dist/extensions/catalog.d.ts +34 -0
  142. package/dist/extensions/catalog.js +103 -0
  143. package/dist/extensions/catalog.js.map +1 -0
  144. package/dist/extensions/child-protocol.d.ts +38 -0
  145. package/dist/extensions/child-protocol.js +2 -0
  146. package/dist/extensions/child-protocol.js.map +1 -0
  147. package/dist/extensions/child.d.ts +1 -0
  148. package/dist/extensions/child.js +125 -0
  149. package/dist/extensions/child.js.map +1 -0
  150. package/dist/extensions/consent.d.ts +13 -0
  151. package/dist/extensions/consent.js +204 -0
  152. package/dist/extensions/consent.js.map +1 -0
  153. package/dist/extensions/environment.d.ts +1 -0
  154. package/dist/extensions/environment.js +12 -0
  155. package/dist/extensions/environment.js.map +1 -0
  156. package/dist/extensions/identity.d.ts +9 -0
  157. package/dist/extensions/identity.js +28 -0
  158. package/dist/extensions/identity.js.map +1 -0
  159. package/dist/extensions/log.d.ts +5 -0
  160. package/dist/extensions/log.js +80 -0
  161. package/dist/extensions/log.js.map +1 -0
  162. package/dist/extensions/manifest.d.ts +7 -0
  163. package/dist/extensions/manifest.js +213 -0
  164. package/dist/extensions/manifest.js.map +1 -0
  165. package/dist/extensions/types.d.ts +24 -0
  166. package/dist/extensions/types.js +2 -0
  167. package/dist/extensions/types.js.map +1 -0
  168. package/dist/extensions.d.ts +5 -0
  169. package/dist/extensions.js +2 -0
  170. package/dist/extensions.js.map +1 -0
  171. package/dist/index.d.ts +1 -0
  172. package/dist/index.js.map +1 -1
  173. package/dist/runtime/approval-registry.d.ts +6 -2
  174. package/dist/runtime/approval-registry.js +31 -3
  175. package/dist/runtime/approval-registry.js.map +1 -1
  176. package/dist/runtime/capture.d.ts +4 -4
  177. package/dist/runtime/capture.js +59 -15
  178. package/dist/runtime/capture.js.map +1 -1
  179. package/dist/runtime/catalog.d.ts +6 -1
  180. package/dist/runtime/catalog.js +1 -1
  181. package/dist/runtime/catalog.js.map +1 -1
  182. package/dist/runtime/coordinator.d.ts +9 -4
  183. package/dist/runtime/coordinator.js +130 -27
  184. package/dist/runtime/coordinator.js.map +1 -1
  185. package/dist/runtime/daemon.js +9 -1
  186. package/dist/runtime/daemon.js.map +1 -1
  187. package/dist/runtime/dashboard.d.ts +4 -0
  188. package/dist/runtime/dashboard.js +8 -0
  189. package/dist/runtime/dashboard.js.map +1 -1
  190. package/dist/runtime/definition.d.ts +1 -1
  191. package/dist/runtime/definition.js +2 -2
  192. package/dist/runtime/definition.js.map +1 -1
  193. package/dist/runtime/event-operation.d.ts +41 -0
  194. package/dist/runtime/event-operation.js +290 -0
  195. package/dist/runtime/event-operation.js.map +1 -0
  196. package/dist/runtime/event-owner.d.ts +94 -0
  197. package/dist/runtime/event-owner.js +429 -0
  198. package/dist/runtime/event-owner.js.map +1 -0
  199. package/dist/runtime/event-source.d.ts +39 -0
  200. package/dist/runtime/event-source.js +344 -0
  201. package/dist/runtime/event-source.js.map +1 -0
  202. package/dist/runtime/extension-instance.d.ts +61 -0
  203. package/dist/runtime/extension-instance.js +356 -0
  204. package/dist/runtime/extension-instance.js.map +1 -0
  205. package/dist/runtime/extension-protocol.d.ts +47 -0
  206. package/dist/runtime/extension-protocol.js +33 -0
  207. package/dist/runtime/extension-protocol.js.map +1 -0
  208. package/dist/runtime/extension-service.d.ts +10 -0
  209. package/dist/runtime/extension-service.js +35 -0
  210. package/dist/runtime/extension-service.js.map +1 -0
  211. package/dist/runtime/extension-supervisor.d.ts +33 -0
  212. package/dist/runtime/extension-supervisor.js +254 -0
  213. package/dist/runtime/extension-supervisor.js.map +1 -0
  214. package/dist/runtime/select-native.d.ts +3 -1
  215. package/dist/runtime/select-native.js +32 -5
  216. package/dist/runtime/select-native.js.map +1 -1
  217. package/dist/runtime/service.d.ts +5 -0
  218. package/dist/runtime/service.js +113 -15
  219. package/dist/runtime/service.js.map +1 -1
  220. package/dist/runtime/session-event-wire.d.ts +29 -0
  221. package/dist/runtime/session-event-wire.js +2 -0
  222. package/dist/runtime/session-event-wire.js.map +1 -0
  223. package/dist/runtime/session-events-service.d.ts +8 -0
  224. package/dist/runtime/session-events-service.js +124 -0
  225. package/dist/runtime/session-events-service.js.map +1 -0
  226. package/dist/runtime/session-events-transport.d.ts +8 -0
  227. package/dist/runtime/session-events-transport.js +142 -0
  228. package/dist/runtime/session-events-transport.js.map +1 -0
  229. package/dist/runtime/startup-lock.d.ts +2 -0
  230. package/dist/runtime/startup-lock.js +49 -5
  231. package/dist/runtime/startup-lock.js.map +1 -1
  232. package/dist/runtime/state.d.ts +2 -1
  233. package/dist/runtime/state.js +4 -0
  234. package/dist/runtime/state.js.map +1 -1
  235. package/dist/runtime/transport.d.ts +1 -0
  236. package/dist/runtime/transport.js +2 -0
  237. package/dist/runtime/transport.js.map +1 -1
  238. package/dist/runtime/types.d.ts +24 -0
  239. package/dist/runtime/types.js.map +1 -1
  240. package/dist/runtime/worker-client.js +42 -13
  241. package/dist/runtime/worker-client.js.map +1 -1
  242. package/dist/runtime/worker-event-channel.d.ts +30 -0
  243. package/dist/runtime/worker-event-channel.js +141 -0
  244. package/dist/runtime/worker-event-channel.js.map +1 -0
  245. package/dist/runtime/worker-event-protocol.d.ts +88 -0
  246. package/dist/runtime/worker-event-protocol.js +114 -0
  247. package/dist/runtime/worker-event-protocol.js.map +1 -0
  248. package/dist/runtime/worker-events.d.ts +73 -0
  249. package/dist/runtime/worker-events.js +704 -0
  250. package/dist/runtime/worker-events.js.map +1 -0
  251. package/dist/runtime/worker-server.d.ts +3 -1
  252. package/dist/runtime/worker-server.js +64 -9
  253. package/dist/runtime/worker-server.js.map +1 -1
  254. package/dist/sdk/connected-events.d.ts +3 -0
  255. package/dist/sdk/connected-events.js +259 -0
  256. package/dist/sdk/connected-events.js.map +1 -0
  257. package/dist/sdk/connected-types.d.ts +2 -0
  258. package/dist/sdk/connected-types.js.map +1 -1
  259. package/dist/sdk/connected.js +3 -0
  260. package/dist/sdk/connected.js.map +1 -1
  261. package/dist/sdk/event-types.d.ts +182 -0
  262. package/dist/sdk/event-types.js +2 -0
  263. package/dist/sdk/event-types.js.map +1 -0
  264. package/dist/sdk/execution-driver.js +1 -1
  265. package/dist/sdk/execution-driver.js.map +1 -1
  266. package/dist/sdk/execution-types.d.ts +2 -0
  267. package/dist/sdk/execution-types.js.map +1 -1
  268. package/dist/sdk/runner.js +2 -0
  269. package/dist/sdk/runner.js.map +1 -1
  270. package/package.json +5 -1
  271. package/sdk/access-config.md +9 -7
  272. package/sdk/adapter-contract.md +25 -3
  273. package/sdk/agent-skill.md +8 -5
  274. package/sdk/cli/dashboard-design.md +37 -9
  275. package/sdk/cli/dashboard-inspection.md +14 -6
  276. package/sdk/cli/extensions.md +44 -0
  277. package/sdk/cli/index.md +53 -14
  278. package/sdk/cli/output.md +14 -2
  279. package/sdk/completion-notifications.md +2 -2
  280. package/sdk/config.md +65 -11
  281. package/sdk/copilot.md +1 -1
  282. package/sdk/cursor.md +2 -2
  283. package/sdk/diagnostics.md +68 -0
  284. package/sdk/distribution.md +13 -3
  285. package/sdk/events.md +339 -0
  286. package/sdk/execution.md +32 -10
  287. package/sdk/extensions.md +189 -0
  288. package/sdk/fx.md +4 -2
  289. package/sdk/harnesses.md +1 -1
  290. package/sdk/index.md +4 -0
  291. package/sdk/message-delivery.md +2 -0
  292. package/sdk/opencode.md +1 -1
  293. package/sdk/plugins/sub-agents.md +3 -1
  294. package/sdk/project-root.md +97 -0
  295. package/sdk/project-team.md +10 -4
  296. package/sdk/sessions.md +4 -0
  297. package/sdk/v1-runtime.md +22 -8
@@ -1 +1 @@
1
- {"version":3,"file":"approval-registry.js","sourceRoot":"","sources":["../../src/runtime/approval-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAuBzF,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,iBAAiB,EAAC,qDAAqD,CAAC,CAAC;AAC9G,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,iBAAiB,EAAC,wDAAwD,CAAC,CAAC;AACjH,MAAM,QAAQ,GAAG,CAAC,OAAwB,EAAmB,EAAE,CAAC,CAAC;IAC/D,SAAS,EAAC,OAAO,CAAC,SAAS,EAAC,MAAM,EAAC,OAAO,CAAC,MAAM,EAAC,SAAS,EAAC,OAAO,CAAC,SAAS;CAC9E,CAAC,CAAC;AAEH,iFAAiF;AACjF,MAAM,OAAO,gBAAgB;IAGE,OAAO;IAF5B,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC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AC,IAAI,CAAC;QAAE,OAAO,EAAC,QAAQ,EAAC,MAAM,EAAC,KAAK,EAAC,MAAM,EAAC,CAAC;IACpG,aAAa,EAAE,CAAC;AAClB,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAqB,EAAC,MAAsB;IACrE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACjD,MAAM,KAAK,GAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;IACrC,IAAI,KAAK,EAAE,IAAI,KAAK,OAAO;QAAE,OAAO,MAAM,CAAC;IAC3C,MAAM,KAAK,GAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAA,EAAE,CAAA,CAAC,EAAC,KAAK,EAAC,KAAK,EAAC,KAAK,EAAC,KAAK,EAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAA,EAAE,CAAA,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7H,MAAM,QAAQ,GAAC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,EAAC,GAAG,MAAM,EAAC,MAAM,EAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAA,EAAE,CAAA,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAC,CAAC;AACrE,CAAC","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { isDeepStrictEqual } from 'node:util';\nimport { AgentError } from '../errors.js';\nimport { validateApprovalContent, validateApprovalSchema } from '../approvals/schema.js';\nimport type { ApprovalContent, ApprovalSchema, NativeApprovalRequest } from '../approvals/types.js';\nimport type { ApprovalRequest } from './types.js';\nimport type { ApprovalAction, ApprovalResponse, SdkApprovalRequest } from './task-data.js';\n\ntype RequestIdentity = Pick<ApprovalRequest,'requestId'|'taskId'|'sessionId'>;\ninterface Continuation {\n resolve(content: ApprovalContent): void;\n reject(error: AgentError): void;\n cleanup(): void;\n}\ninterface PendingEntry {\n outcome: 'pending';\n request: ApprovalRequest;\n continuation: Continuation;\n sdk: SdkApprovalRequest | AgentError;\n actions: Map<string, ActionMapping>;\n}\ninterface AnsweredEntry { outcome: 'answered'; identity: RequestIdentity; answer: ApprovalContent; schema: ApprovalSchema; actions: Map<string, ActionMapping> }\ninterface WithdrawnEntry { outcome: 'withdrawn'; identity: RequestIdentity }\ntype SettledEntry = AnsweredEntry | WithdrawnEntry;\ninterface ActionMapping { action: ApprovalAction; native: ApprovalContent; grants?: readonly string[] }\n\nconst MAX_SETTLED_REQUESTS = 1_024;\nconst expired = () => new AgentError('REQUEST_EXPIRED','The native permission request is no longer pending.');\nconst unknown = () => new AgentError('UNKNOWN_REQUEST','Permission request is unavailable in this coordinator.');\nconst identity = (request: ApprovalRequest): RequestIdentity => ({\n requestId:request.requestId,taskId:request.taskId,sessionId:request.sessionId,\n});\n\n/** Retains pending requests and a bounded settlement-ordered outcome history. */\nexport class ApprovalRegistry {\n private pending = new Map<string,PendingEntry>();\n private settled = new Map<string,SettledEntry>();\n constructor(private readonly changed: (taskId: string) => void) {}\n\n async register(taskId: string, sessionId: string, request: NativeApprovalRequest, signal: AbortSignal): Promise<ApprovalContent> {\n if (signal.aborted) throw expired();\n if (this.pendingFor(taskId).length >= 32)\n throw new AgentError('INPUT_REQUIRED','A task cannot wait on more than 32 permission requests.');\n let copy: NativeApprovalRequest;\n try {\n const serialized = JSON.stringify(request);\n if (Buffer.byteLength(serialized) > 64 * 1024) throw new Error();\n copy = JSON.parse(serialized) as NativeApprovalRequest;\n } catch { throw new AgentError('INPUT_REQUIRED','The native permission request cannot be represented within 64 KiB.'); }\n if (copy.kind !== 'permission' || !['codex','claudeCode','fx','opencode','copilot','cursor'].includes(copy.harness) || typeof copy.message !== 'string')\n throw new AgentError('INPUT_REQUIRED','The native permission request cannot be represented.');\n validateApprovalSchema(copy.requestedSchema);\n const requestId = `req_${randomUUID()}`;\n const snapshot: ApprovalRequest = {...copy,requestId,taskId,sessionId};\n if (Buffer.byteLength(JSON.stringify(snapshot)) > 64 * 1024)\n throw new AgentError('INPUT_REQUIRED','The native permission request cannot be represented within 64 KiB.');\n let sdk:SdkApprovalRequest|AgentError;\n let actions:Map<string,ActionMapping>;\n try { const normalized=normalize(snapshot); sdk=normalized.request; actions=normalized.actions; }\n catch(error) {\n if (!(error instanceof AgentError) || error.code !== 'INPUT_REQUIRED') throw error;\n sdk=error; actions=new Map();\n }\n const answer = new Promise<ApprovalContent>((resolve,reject) => {\n const abort = () => this.retire(requestId);\n this.pending.set(requestId,{outcome:'pending',request:snapshot,sdk,actions,\n continuation:{resolve,reject,cleanup:() => signal.removeEventListener('abort',abort)}});\n signal.addEventListener('abort',abort,{once:true});\n });\n this.changed(taskId);\n return answer;\n }\n\n request(id: string): RequestIdentity {\n const pending = this.pending.get(id);\n if (pending) return identity(pending.request);\n const settled = this.settled.get(id);\n if (!settled) throw unknown();\n return {...settled.identity};\n }\n\n respond(id: string, content: unknown) {\n const pending = this.pending.get(id);\n if (!pending) {\n const settled = this.settled.get(id);\n if (!settled) throw unknown();\n if (settled.outcome === 'withdrawn') throw expired();\n this.validateBoundedContent(content);\n let answer:ApprovalContent;\n try { answer=canonicalBySchema(settled.schema,validateApprovalContent(settled.schema,content)); }\n catch { invalidResponse(); }\n if (!isDeepStrictEqual(settled.answer,answer))\n throw new AgentError('INVALID_APPROVAL_RESPONSE','This permission request already has a different answer.');\n return this.receipt(settled.identity);\n }\n this.validateBoundedContent(content);\n const answer = canonicalBySchema(pending.request.requestedSchema,validateApprovalContent(pending.request.requestedSchema,content));\n const requestIdentity = identity(pending.request);\n this.pending.delete(id);\n pending.continuation.cleanup();\n this.retain({outcome:'answered',identity:requestIdentity,answer:structuredClone(answer),\n schema:structuredClone(pending.request.requestedSchema),actions:pending.actions});\n pending.continuation.resolve(answer);\n this.changed(requestIdentity.taskId);\n return this.receipt(requestIdentity);\n }\n\n pendingFor(taskId: string): ApprovalRequest[] {\n return [...this.pending.values()].filter(entry => entry.request.taskId === taskId)\n .map(entry => structuredClone(entry.request));\n }\n\n sdkPendingFor(taskId: string): SdkApprovalRequest[] {\n return [...this.pending.values()].filter(entry => entry.request.taskId === taskId)\n .map(entry => {\n if (entry.sdk instanceof AgentError) throw new AgentError(entry.sdk.code,entry.sdk.message);\n return structuredClone(entry.sdk);\n });\n }\n\n respondSdk(id: string, response: unknown) {\n const entry = this.pending.get(id) ?? this.settled.get(id);\n if (!entry) throw unknown();\n if (entry.outcome === 'withdrawn') throw expired();\n this.validateBoundedContent(response);\n if (!plain(response) || Reflect.ownKeys(response).some(key => typeof key !== 'string' || !['actionId','grants'].includes(key))\n || typeof response.actionId !== 'string') invalidResponse();\n const mapping = entry.actions.get(response.actionId);\n if (!mapping) invalidResponse();\n const submitted = response as unknown as ApprovalResponse;\n let native = structuredClone(mapping.native);\n if (mapping.grants) {\n if (mapping.action.decision !== 'allow' || !Array.isArray(submitted.grants)\n || submitted.grants.some(value => typeof value !== 'string') || new Set(submitted.grants).size !== submitted.grants.length\n || submitted.grants.some(value => !mapping.grants!.includes(value))) invalidResponse();\n const selected = new Set(submitted.grants);\n native = {...native, grants: mapping.grants.filter(id => selected.has(id))};\n } else if (Object.hasOwn(response,'grants')) invalidResponse();\n return this.respond(id,native);\n }\n\n retireTask(taskId: string) {\n for (const [id,entry] of this.pending) if (entry.request.taskId === taskId) this.retire(id);\n }\n\n close() { for (const id of [...this.pending.keys()]) this.retire(id); }\n\n private retire(id: string) {\n const entry = this.pending.get(id);\n if (!entry) return;\n const requestIdentity = identity(entry.request);\n this.pending.delete(id);\n entry.continuation.cleanup();\n this.retain({outcome:'withdrawn',identity:requestIdentity});\n entry.continuation.reject(expired());\n this.changed(requestIdentity.taskId);\n }\n\n private retain(entry: SettledEntry) {\n this.settled.set(entry.identity.requestId,entry);\n while (this.settled.size > MAX_SETTLED_REQUESTS) {\n const oldest = this.settled.keys().next().value;\n if (oldest !== undefined) this.settled.delete(oldest);\n }\n }\n\n private validateBoundedContent(content: unknown) {\n let serialized: string | undefined;\n try { serialized = JSON.stringify(content); } catch { /* Report no submitted data. */ }\n if (!serialized || Buffer.byteLength(serialized) > 16 * 1024)\n throw new AgentError('INVALID_APPROVAL_RESPONSE','Approval content must be a JSON object within 16 KiB.');\n }\n\n private receipt(request: RequestIdentity) {\n return {version:1 as const,type:'approval_answered' as const,requestId:request.requestId,\n taskId:request.taskId,sessionId:request.sessionId};\n }\n}\n\nfunction invalidResponse(): never {\n throw new AgentError('INVALID_APPROVAL_RESPONSE','The approval response does not match the requested actions.');\n}\n\nfunction plain(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n && [Object.prototype,null].includes(Object.getPrototypeOf(value));\n}\n\nfunction normalize(request: ApprovalRequest): {request: SdkApprovalRequest; actions: Map<string,ActionMapping>} {\n const actions = new Map<string,ActionMapping>();\n const grantsField = request.requestedSchema.properties.grants;\n const scopeField = request.requestedSchema.properties.scope;\n let grants: {id:string;label:string}[] | undefined;\n if (grantsField?.type === 'array' && grantsField.items.anyOf && scopeField?.type === 'string' && scopeField.oneOf) {\n grants = grantsField.items.anyOf.map(choice => ({id:choice.const,label:choice.title}));\n for (const choice of scopeField.oneOf) {\n const scope = choice.const === 'session' ? 'session' : 'turn';\n const action: ApprovalAction = {id:`act_${randomUUID()}`,label:`Allow for this ${scope}`,decision:'allow',scope};\n actions.set(action.id,{action,native:{scope:choice.const},grants:grants.map(grant=>grant.id)});\n }\n } else {\n const decision = request.requestedSchema.properties.decision;\n const choices=decision?.type === 'string'\n ? (decision.oneOf ?? decision.enum?.map(value=>({const:value,title:value}))) : undefined;\n if (!choices?.length) invalidNative();\n for (const choice of choices) {\n const metadata = decisionMetadata(request,choice.const);\n const action: ApprovalAction = metadata.decision === 'cancel'\n ? {id:`act_${randomUUID()}`,label:choice.title,decision:'cancel'}\n : {id:`act_${randomUUID()}`,label:choice.title,decision:metadata.decision,scope:metadata.scope,\n ...(metadata.scope === 'session' ? {description:'Applies to this native conversation.'} : {})};\n actions.set(action.id,{action,native:{decision:choice.const}});\n }\n }\n if (!actions.size) invalidNative();\n const groups=new Map<string,ActionMapping[]>();\n for (const mapping of actions.values()) {\n const key=mapping.action.decision === 'cancel' ? 'cancel' : `${mapping.action.decision}:${mapping.action.scope}`;\n const group=groups.get(key) ?? []; group.push(mapping); groups.set(key,group);\n }\n for (const group of groups.values()) if (group.length > 1) for (const mapping of group) {\n const native=typeof mapping.native.decision === 'string' ? mapping.native.decision : String(mapping.native.scope);\n mapping.action={...mapping.action,description:[mapping.action.description,`Native option: ${native}`].filter(Boolean).join(' ')};\n }\n return {request:{id:request.requestId,taskId:request.taskId,sessionId:request.sessionId,harness:request.harness,\n message:request.message,actions:[...actions.values()].map(value=>value.action),\n ...(grants ? {grants} : {}),...(request.context ? {context:structuredClone(request.context)} : {})},actions};\n}\n\nfunction invalidNative(): never {\n throw new AgentError('INPUT_REQUIRED','The native permission request cannot be represented.');\n}\n\nfunction decisionMetadata(request: ApprovalRequest, value: string): {decision:'allow'|'deny';scope:'once'|'session'} | {decision:'cancel'} {\n const options = Array.isArray(request.context?.options) ? request.context.options : [];\n const offered = options.find(option => plain(option) && (option.optionId === value));\n const kind = plain(offered) && typeof offered.kind === 'string' ? offered.kind : value;\n if (kind === 'cancel') return {decision:'cancel'};\n if (['acceptForSession','allow_session','allow_always'].includes(kind)) return {decision:'allow',scope:'session'};\n if (kind === 'reject_always') return {decision:'deny',scope:'session'};\n if (['accept','allow','allow_once','once','approve-once'].includes(kind)) return {decision:'allow',scope:'once'};\n if (['decline','deny','reject','reject_once'].includes(kind)) return {decision:'deny',scope:'once'};\n invalidNative();\n}\n\nfunction canonicalBySchema(schema:ApprovalSchema,answer:ApprovalContent):ApprovalContent {\n if (!Array.isArray(answer.grants)) return answer;\n const field=schema.properties.grants;\n if (field?.type !== 'array') return answer;\n const order=(field.items.anyOf ?? field.items.enum?.map(value=>({const:value,title:value})) ?? []).map(choice=>choice.const);\n const selected=new Set(answer.grants);\n return {...answer,grants:order.filter(value=>selected.has(value))};\n}\n"]}
1
+ {"version":3,"file":"approval-registry.js","sourceRoot":"","sources":["../../src/runtime/approval-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AA0BzF,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,iBAAiB,EAAC,qDAAqD,CAAC,CAAC;AAC9G,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,UAAU,CAAC,iBAAiB,EAAC,wDAAwD,CAAC,CAAC;AACjH,MAAM,QAAQ,GAAG,CAAC,OAAwB,EAAmB,EAAE,CAAC,CAAC;IAC/D,SAAS,EAAC,OAAO,CAAC,SAAS,EAAC,MAAM,EAAC,OAAO,CAAC,MAAM,EAAC,SAAS,EAAC,OAAO,CAAC,SAAS;CAC9E,CAAC,CAAC;AAEH,iFAAiF;AACjF,MAAM,OAAO,gBAAgB;IAGE,OAAO;IACjB,SAAS;IAHpB,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzC,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IACjD,YAA6B,OAAiC,EAC3C,SAAS,GAA6C,GAAG,EAAE,GAAE,CAAC;uBADpD,OAAO;yBACjB,SAAS;IAAwD,CAAC;IAErF,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,SAAiB,EAAE,OAA8B,EAAE,MAAmB,EACnG,OAA0B;QAC1B,IAAI,MAAM,CAAC,OAAO;YAAE,MAAM,OAA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AC;IAC3C,MAAM,KAAK,GAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAA,EAAE,CAAA,CAAC,EAAC,KAAK,EAAC,KAAK,EAAC,KAAK,EAAC,KAAK,EAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAA,EAAE,CAAA,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7H,MAAM,QAAQ,GAAC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,EAAC,GAAG,MAAM,EAAC,MAAM,EAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAA,EAAE,CAAA,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAC,CAAC;AACrE,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAmB,EAAE,MAAuB;IACpE,KAAK,MAAM,CAAC,QAAQ,EAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAC/C,IAAI,QAAQ,GAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;YAAE,QAAQ,GAAC,EAAC,GAAG,QAAQ,EAAC,MAAM,EAAC,MAAM,CAAC,MAAM,EAAC,CAAC;QAChG,IAAI,iBAAiB,CAAC,QAAQ,EAAC,MAAM,CAAC;YAAE,OAAO,QAAQ,CAAC;IAC1D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { isDeepStrictEqual } from 'node:util';\nimport { AgentError } from '../errors.js';\nimport { validateApprovalContent, validateApprovalSchema } from '../approvals/schema.js';\nimport type { ApprovalContent, ApprovalSchema, NativeApprovalRequest } from '../approvals/types.js';\nimport type { ApprovalRequest } from './types.js';\nimport type { ApprovalAction, ApprovalResponse, SdkApprovalRequest } from './task-data.js';\nimport type { OwnerTurnBinding } from './event-operation.js';\nimport type { OwnerApprovalLifecycle } from './event-owner.js';\n\ntype RequestIdentity = Pick<ApprovalRequest,'requestId'|'taskId'|'sessionId'>;\ninterface Continuation {\n resolve(content: ApprovalContent): void;\n reject(error: AgentError): void;\n cleanup(): void;\n}\ninterface PendingEntry {\n outcome: 'pending';\n request: ApprovalRequest;\n continuation: Continuation;\n sdk: SdkApprovalRequest | AgentError;\n actions: Map<string, ActionMapping>;\n binding?: OwnerTurnBinding;\n}\ninterface AnsweredEntry { outcome: 'answered'; identity: RequestIdentity; answer: ApprovalContent; schema: ApprovalSchema; actions: Map<string, ActionMapping> }\ninterface WithdrawnEntry { outcome: 'withdrawn'; identity: RequestIdentity }\ntype SettledEntry = AnsweredEntry | WithdrawnEntry;\ninterface ActionMapping { action: ApprovalAction; native: ApprovalContent; grants?: readonly string[] }\n\nconst MAX_SETTLED_REQUESTS = 1_024;\nconst expired = () => new AgentError('REQUEST_EXPIRED','The native permission request is no longer pending.');\nconst unknown = () => new AgentError('UNKNOWN_REQUEST','Permission request is unavailable in this coordinator.');\nconst identity = (request: ApprovalRequest): RequestIdentity => ({\n requestId:request.requestId,taskId:request.taskId,sessionId:request.sessionId,\n});\n\n/** Retains pending requests and a bounded settlement-ordered outcome history. */\nexport class ApprovalRegistry {\n private pending = new Map<string,PendingEntry>();\n private settled = new Map<string,SettledEntry>();\n constructor(private readonly changed: (taskId: string) => void,\n private readonly lifecycle: (change: OwnerApprovalLifecycle) => void = () => {}) {}\n\n async register(taskId: string, sessionId: string, request: NativeApprovalRequest, signal: AbortSignal,\n binding?: OwnerTurnBinding): Promise<ApprovalContent> {\n if (signal.aborted) throw expired();\n if (this.pendingFor(taskId).length >= 32)\n throw new AgentError('INPUT_REQUIRED','A task cannot wait on more than 32 permission requests.');\n let copy: NativeApprovalRequest;\n try {\n const serialized = JSON.stringify(request);\n if (Buffer.byteLength(serialized) > 64 * 1024) throw new Error();\n copy = JSON.parse(serialized) as NativeApprovalRequest;\n } catch { throw new AgentError('INPUT_REQUIRED','The native permission request cannot be represented within 64 KiB.'); }\n if (copy.kind !== 'permission' || !['codex','claudeCode','fx','opencode','copilot','cursor'].includes(copy.harness) || typeof copy.message !== 'string')\n throw new AgentError('INPUT_REQUIRED','The native permission request cannot be represented.');\n validateApprovalSchema(copy.requestedSchema);\n const requestId = `req_${randomUUID()}`;\n const snapshot: ApprovalRequest = {...copy,requestId,taskId,sessionId};\n if (Buffer.byteLength(JSON.stringify(snapshot)) > 64 * 1024)\n throw new AgentError('INPUT_REQUIRED','The native permission request cannot be represented within 64 KiB.');\n let sdk:SdkApprovalRequest|AgentError;\n let actions:Map<string,ActionMapping>;\n try { const normalized=normalize(snapshot); sdk=normalized.request; actions=normalized.actions; }\n catch(error) {\n if (!(error instanceof AgentError) || error.code !== 'INPUT_REQUIRED') throw error;\n sdk=error; actions=new Map();\n }\n const answer = new Promise<ApprovalContent>((resolve,reject) => {\n const abort = () => this.retire(requestId);\n this.pending.set(requestId,{outcome:'pending',request:snapshot,sdk,actions,...(binding ? {binding} : {}),\n continuation:{resolve,reject,cleanup:() => signal.removeEventListener('abort',abort)}});\n signal.addEventListener('abort',abort,{once:true});\n });\n if (!(sdk instanceof AgentError) && binding) this.notifyLifecycle({transition:'requested',binding,request:structuredClone(sdk)});\n this.changed(taskId);\n return answer;\n }\n\n request(id: string): RequestIdentity {\n const pending = this.pending.get(id);\n if (pending) return identity(pending.request);\n const settled = this.settled.get(id);\n if (!settled) throw unknown();\n return {...settled.identity};\n }\n\n respond(id: string, content: unknown) {\n const pending = this.pending.get(id);\n if (!pending) {\n const settled = this.settled.get(id);\n if (!settled) throw unknown();\n if (settled.outcome === 'withdrawn') throw expired();\n this.validateBoundedContent(content);\n let answer:ApprovalContent;\n try { answer=canonicalBySchema(settled.schema,validateApprovalContent(settled.schema,content)); }\n catch { invalidResponse(); }\n if (!isDeepStrictEqual(settled.answer,answer))\n throw new AgentError('INVALID_APPROVAL_RESPONSE','This permission request already has a different answer.');\n return this.receipt(settled.identity);\n }\n this.validateBoundedContent(content);\n const answer = canonicalBySchema(pending.request.requestedSchema,validateApprovalContent(pending.request.requestedSchema,content));\n const requestIdentity = identity(pending.request);\n this.pending.delete(id);\n pending.continuation.cleanup();\n this.retain({outcome:'answered',identity:requestIdentity,answer:structuredClone(answer),\n schema:structuredClone(pending.request.requestedSchema),actions:pending.actions});\n pending.continuation.resolve(answer);\n if (pending.binding && !(pending.sdk instanceof AgentError)) {\n const actionId=matchingActionId(pending,answer);\n this.notifyLifecycle({transition:'answered',binding:pending.binding,requestId:id,...(actionId ? {actionId} : {})});\n }\n this.changed(requestIdentity.taskId);\n return this.receipt(requestIdentity);\n }\n\n pendingFor(taskId: string): ApprovalRequest[] {\n return [...this.pending.values()].filter(entry => entry.request.taskId === taskId)\n .map(entry => structuredClone(entry.request));\n }\n\n sdkPendingFor(taskId: string): SdkApprovalRequest[] {\n return [...this.pending.values()].filter(entry => entry.request.taskId === taskId)\n .map(entry => {\n if (entry.sdk instanceof AgentError) throw new AgentError(entry.sdk.code,entry.sdk.message);\n return structuredClone(entry.sdk);\n });\n }\n\n respondSdk(id: string, response: unknown) {\n const entry = this.pending.get(id) ?? this.settled.get(id);\n if (!entry) throw unknown();\n if (entry.outcome === 'withdrawn') throw expired();\n this.validateBoundedContent(response);\n if (!plain(response) || Reflect.ownKeys(response).some(key => typeof key !== 'string' || !['actionId','grants'].includes(key))\n || typeof response.actionId !== 'string') invalidResponse();\n const mapping = entry.actions.get(response.actionId);\n if (!mapping) invalidResponse();\n const submitted = response as unknown as ApprovalResponse;\n let native = structuredClone(mapping.native);\n if (mapping.grants) {\n if (mapping.action.decision !== 'allow' || !Array.isArray(submitted.grants)\n || submitted.grants.some(value => typeof value !== 'string') || new Set(submitted.grants).size !== submitted.grants.length\n || submitted.grants.some(value => !mapping.grants!.includes(value))) invalidResponse();\n const selected = new Set(submitted.grants);\n native = {...native, grants: mapping.grants.filter(id => selected.has(id))};\n } else if (Object.hasOwn(response,'grants')) invalidResponse();\n return this.respond(id,native);\n }\n\n retireTask(taskId: string) {\n for (const [id,entry] of this.pending) if (entry.request.taskId === taskId) this.retire(id);\n }\n\n close() { for (const id of [...this.pending.keys()]) this.retire(id); }\n\n private retire(id: string) {\n const entry = this.pending.get(id);\n if (!entry) return;\n const requestIdentity = identity(entry.request);\n this.pending.delete(id);\n entry.continuation.cleanup();\n this.retain({outcome:'withdrawn',identity:requestIdentity});\n entry.continuation.reject(expired());\n if (entry.binding && !(entry.sdk instanceof AgentError)) this.notifyLifecycle({\n transition:'withdrawn',binding:entry.binding,requestId:id,\n });\n this.changed(requestIdentity.taskId);\n }\n\n private retain(entry: SettledEntry) {\n this.settled.set(entry.identity.requestId,entry);\n while (this.settled.size > MAX_SETTLED_REQUESTS) {\n const oldest = this.settled.keys().next().value;\n if (oldest !== undefined) this.settled.delete(oldest);\n }\n }\n\n private validateBoundedContent(content: unknown) {\n let serialized: string | undefined;\n try { serialized = JSON.stringify(content); } catch { /* Report no submitted data. */ }\n if (!serialized || Buffer.byteLength(serialized) > 16 * 1024)\n throw new AgentError('INVALID_APPROVAL_RESPONSE','Approval content must be a JSON object within 16 KiB.');\n }\n\n private notifyLifecycle(change: OwnerApprovalLifecycle) {\n try { this.lifecycle(change); } catch { /* Observation cannot change approval execution. */ }\n }\n\n private receipt(request: RequestIdentity) {\n return {version:1 as const,type:'approval_answered' as const,requestId:request.requestId,\n taskId:request.taskId,sessionId:request.sessionId};\n }\n}\n\nfunction invalidResponse(): never {\n throw new AgentError('INVALID_APPROVAL_RESPONSE','The approval response does not match the requested actions.');\n}\n\nfunction plain(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n && [Object.prototype,null].includes(Object.getPrototypeOf(value));\n}\n\nfunction normalize(request: ApprovalRequest): {request: SdkApprovalRequest; actions: Map<string,ActionMapping>} {\n const actions = new Map<string,ActionMapping>();\n const grantsField = request.requestedSchema.properties.grants;\n const scopeField = request.requestedSchema.properties.scope;\n let grants: {id:string;label:string}[] | undefined;\n if (grantsField?.type === 'array' && grantsField.items.anyOf && scopeField?.type === 'string' && scopeField.oneOf) {\n grants = grantsField.items.anyOf.map(choice => ({id:choice.const,label:choice.title}));\n for (const choice of scopeField.oneOf) {\n const scope = choice.const === 'session' ? 'session' : 'turn';\n const action: ApprovalAction = {id:`act_${randomUUID()}`,label:`Allow for this ${scope}`,decision:'allow',scope};\n actions.set(action.id,{action,native:{scope:choice.const},grants:grants.map(grant=>grant.id)});\n }\n } else {\n const decision = request.requestedSchema.properties.decision;\n const choices=decision?.type === 'string'\n ? (decision.oneOf ?? decision.enum?.map(value=>({const:value,title:value}))) : undefined;\n if (!choices?.length) invalidNative();\n for (const choice of choices) {\n const metadata = decisionMetadata(request,choice.const);\n const action: ApprovalAction = metadata.decision === 'cancel'\n ? {id:`act_${randomUUID()}`,label:choice.title,decision:'cancel'}\n : {id:`act_${randomUUID()}`,label:choice.title,decision:metadata.decision,scope:metadata.scope,\n ...(metadata.scope === 'session' ? {description:'Applies to this native conversation.'} : {})};\n actions.set(action.id,{action,native:{decision:choice.const}});\n }\n }\n if (!actions.size) invalidNative();\n const groups=new Map<string,ActionMapping[]>();\n for (const mapping of actions.values()) {\n const key=mapping.action.decision === 'cancel' ? 'cancel' : `${mapping.action.decision}:${mapping.action.scope}`;\n const group=groups.get(key) ?? []; group.push(mapping); groups.set(key,group);\n }\n for (const group of groups.values()) if (group.length > 1) for (const mapping of group) {\n const native=typeof mapping.native.decision === 'string' ? mapping.native.decision : String(mapping.native.scope);\n mapping.action={...mapping.action,description:[mapping.action.description,`Native option: ${native}`].filter(Boolean).join(' ')};\n }\n return {request:{id:request.requestId,taskId:request.taskId,sessionId:request.sessionId,harness:request.harness,\n message:request.message,actions:[...actions.values()].map(value=>value.action),\n ...(grants ? {grants} : {}),...(request.context ? {context:structuredClone(request.context)} : {})},actions};\n}\n\nfunction invalidNative(): never {\n throw new AgentError('INPUT_REQUIRED','The native permission request cannot be represented.');\n}\n\nfunction decisionMetadata(request: ApprovalRequest, value: string): {decision:'allow'|'deny';scope:'once'|'session'} | {decision:'cancel'} {\n const options = Array.isArray(request.context?.options) ? request.context.options : [];\n const offered = options.find(option => plain(option) && (option.optionId === value));\n const kind = plain(offered) && typeof offered.kind === 'string' ? offered.kind : value;\n if (kind === 'cancel') return {decision:'cancel'};\n if (['acceptForSession','allow_session','allow_always'].includes(kind)) return {decision:'allow',scope:'session'};\n if (kind === 'reject_always') return {decision:'deny',scope:'session'};\n if (['accept','allow','allow_once','once','approve-once'].includes(kind)) return {decision:'allow',scope:'once'};\n if (['decline','deny','reject','reject_once'].includes(kind)) return {decision:'deny',scope:'once'};\n invalidNative();\n}\n\nfunction canonicalBySchema(schema:ApprovalSchema,answer:ApprovalContent):ApprovalContent {\n if (!Array.isArray(answer.grants)) return answer;\n const field=schema.properties.grants;\n if (field?.type !== 'array') return answer;\n const order=(field.items.anyOf ?? field.items.enum?.map(value=>({const:value,title:value})) ?? []).map(choice=>choice.const);\n const selected=new Set(answer.grants);\n return {...answer,grants:order.filter(value=>selected.has(value))};\n}\n\nfunction matchingActionId(entry: PendingEntry, answer: ApprovalContent): string | undefined {\n for (const [actionId,mapping] of entry.actions) {\n let expected=structuredClone(mapping.native);\n if (mapping.grants && Array.isArray(answer.grants)) expected={...expected,grants:answer.grants};\n if (isDeepStrictEqual(expected,answer)) return actionId;\n }\n return undefined;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { HarnessConfig } from '../sdk/types.js';
2
- import type { CatalogEnvironment } from './catalog.js';
2
+ import type { ExecutionEnvironment } from './catalog.js';
3
3
  import type { ExecutionReference, PreparedExecution } from './types.js';
4
4
  export interface CapturedChild {
5
5
  readonly name: string;
@@ -15,8 +15,8 @@ interface CaptureOptions {
15
15
  workerModule?: URL;
16
16
  shutdownTimeoutMs?: number;
17
17
  }
18
- export declare function captureExecution(agent: string | HarnessConfig, input: CatalogEnvironment, options?: CaptureOptions): Promise<CapturedExecution>;
18
+ export declare function captureExecution(agent: string | HarnessConfig, input: ExecutionEnvironment, options?: CaptureOptions): Promise<CapturedExecution>;
19
19
  /** Captures an already resolved private CLI reference without applying public connected validation. */
20
- export declare function captureReference(reference: ExecutionReference, input: CatalogEnvironment, options?: CaptureOptions): Promise<CapturedExecution>;
21
- export declare function checkCapturedExecution(captured: CapturedExecution, input: CatalogEnvironment): Promise<void>;
20
+ export declare function captureReference(reference: ExecutionReference, input: ExecutionEnvironment, options?: CaptureOptions): Promise<CapturedExecution>;
21
+ export declare function checkCapturedExecution(captured: CapturedExecution, input: ExecutionEnvironment): Promise<void>;
22
22
  export {};
@@ -1,9 +1,11 @@
1
1
  import { fork } from 'node:child_process';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { randomUUID } from 'node:crypto';
4
+ import { isAbsolute } from 'node:path';
4
5
  import { AgentError, errorInfo } from '../errors.js';
5
6
  import { createSessionLauncher } from './session-launcher.js';
6
7
  import { processExitDescription } from '../process-diagnostics.js';
8
+ import { WorkerEventClient } from './worker-events.js';
7
9
  const shutdownTimeoutMs = 1_000;
8
10
  class GraphConnection {
9
11
  child;
@@ -17,17 +19,21 @@ class GraphConnection {
17
19
  abandonedLeases = new Set();
18
20
  observedExit = '';
19
21
  processExit;
22
+ workerEvents;
20
23
  markExited;
21
24
  constructor(child, timeout) {
22
25
  this.child = child;
23
26
  this.timeout = timeout;
24
27
  this.processExit = new Promise(resolve => { this.markExited = resolve; });
28
+ this.workerEvents = new WorkerEventClient(child.stdio[4], (method, data) => this.request(method, data));
25
29
  child.once('error', () => this.exit(undefined, undefined, true));
26
30
  child.once('exit', (code, signal) => this.exit(code, signal));
27
31
  child.on('message', (message) => this.message(message));
28
32
  }
29
33
  setApprovalHandler(leaseId, handler) { this.handlers.set(leaseId, handler); }
30
34
  deleteApprovalHandler(leaseId) { this.handlers.delete(leaseId); }
35
+ setEventPort(leaseId, port) { this.workerEvents.attach(leaseId, port); }
36
+ deleteEventPort(leaseId) { this.workerEvents.detach(leaseId); }
31
37
  retainLease(leaseId) { this.leases.add(leaseId); }
32
38
  async releaseLease(leaseId) {
33
39
  this.leases.delete(leaseId);
@@ -73,7 +79,11 @@ class GraphConnection {
73
79
  return;
74
80
  }
75
81
  const id = this.nextId++;
76
- this.pending.set(id, { operation: method, resolve, reject });
82
+ const observationOperationId = typeof extra.observation === 'object' && extra.observation !== null
83
+ && typeof extra.observation.operationId === 'string'
84
+ ? extra.observation.operationId : undefined;
85
+ this.pending.set(id, { operation: method, leaseId: typeof extra.leaseId === 'number' ? extra.leaseId : undefined,
86
+ observationOperationId, resolve, reject });
77
87
  this.child.send({ id, method, ...extra }, error => {
78
88
  if (!error)
79
89
  return;
@@ -88,6 +98,8 @@ class GraphConnection {
88
98
  });
89
99
  }
90
100
  message(message) {
101
+ if (this.workerEvents.acceptControl(message))
102
+ return;
91
103
  if ('event' in message) {
92
104
  const key = `${message.leaseId}:${message.requestId}`;
93
105
  if (message.event === 'approval.withdraw') {
@@ -114,10 +126,16 @@ class GraphConnection {
114
126
  if (!waiting)
115
127
  return;
116
128
  this.pending.delete(message.id);
117
- if (message.error)
118
- waiting.reject(new AgentError(message.error.code, message.error.message));
129
+ const operationError = message.error ? new AgentError(message.error.code, message.error.message) : undefined;
130
+ void this.workerEvents.complete(waiting.leaseId, message.observation, waiting.observationOperationId).then(() => {
131
+ if (operationError)
132
+ waiting.reject(operationError);
133
+ else
134
+ waiting.resolve(message.result);
135
+ }, () => { if (operationError)
136
+ waiting.reject(operationError);
119
137
  else
120
- waiting.resolve(message.result);
138
+ waiting.resolve(message.result); });
121
139
  }
122
140
  exit(code, signal, spawnFailure = false) {
123
141
  if (this.exited)
@@ -127,6 +145,7 @@ class GraphConnection {
127
145
  for (const controller of this.approvals.values())
128
146
  controller.abort();
129
147
  this.approvals.clear();
148
+ this.workerEvents.close();
130
149
  this.markExited();
131
150
  for (const waiting of this.pending.values())
132
151
  waiting.reject(new AgentError('HARNESS_FAILED', spawnFailure
@@ -151,6 +170,13 @@ class GraphConnection {
151
170
  if (!await this.waitWithin(this.timeout))
152
171
  throw new AgentError('HARNESS_FAILED', 'The captured definition worker did not confirm termination.');
153
172
  }
173
+ run(leaseId, method, extra = {}) {
174
+ const observation = this.workerEvents.begin(leaseId);
175
+ return this.request(method, { leaseId, ...extra, ...(observation ? { observation } : {}) });
176
+ }
177
+ selected(leaseId, opened) {
178
+ this.workerEvents.metadata(leaseId, opened);
179
+ }
154
180
  waitWithin(timeout) {
155
181
  return new Promise(resolve => {
156
182
  const timer = setTimeout(() => resolve(false), timeout);
@@ -169,19 +195,19 @@ class CaptureLease {
169
195
  released = false;
170
196
  closing = false;
171
197
  opening;
172
- constructor(graph, leaseId, reference, children) {
198
+ constructor(graph, leaseId, reference, children, agentName) {
173
199
  this.graph = graph;
174
200
  this.leaseId = leaseId;
175
201
  this.reference = reference;
176
202
  this.graph.retainLease(leaseId);
177
203
  this.children = Object.freeze(children.map(child => Object.freeze({ ...child })));
178
- this.prepared = { open: input => this.open(input), close: () => this.close() };
204
+ this.prepared = { display: { agentName }, open: input => this.open(input), close: () => this.close() };
179
205
  }
180
206
  async child(name) {
181
207
  if (this.released)
182
208
  throw new AgentError('INVALID_PARENT', 'The captured parent context is closed.');
183
209
  const result = await this.graph.request('child', { leaseId: this.leaseId, name });
184
- return new CaptureLease(this.graph, result.leaseId, result.reference, result.children);
210
+ return new CaptureLease(this.graph, result.leaseId, result.reference, result.children, result.name);
185
211
  }
186
212
  async open(input) {
187
213
  if (this.released || this.closing || this.opening)
@@ -201,15 +227,19 @@ class CaptureLease {
201
227
  this.launcher = undefined;
202
228
  throw new AgentError('COORDINATOR_UNAVAILABLE', 'The captured session closed during startup.');
203
229
  }
204
- const { onApproval, ...serializedInput } = input;
230
+ const { onApproval, events, ...serializedInput } = input;
205
231
  let selectedHarness;
206
232
  try {
207
233
  this.graph.setApprovalHandler(this.leaseId, onApproval);
208
- selectedHarness = await this.graph.request('open', { leaseId: this.leaseId, input: serializedInput,
234
+ this.graph.setEventPort(this.leaseId, events);
235
+ const opened = await this.graph.request('open', { leaseId: this.leaseId, input: serializedInput,
209
236
  handlesApprovals: !!onApproval, launcherPath: launcher.path });
237
+ selectedHarness = opened.selectedHarness;
238
+ this.graph.selected(this.leaseId, opened);
210
239
  }
211
240
  catch (error) {
212
241
  this.graph.deleteApprovalHandler(this.leaseId);
242
+ this.graph.deleteEventPort(this.leaseId);
213
243
  this.launcher = undefined;
214
244
  await launcher.close();
215
245
  throw error;
@@ -217,16 +247,17 @@ class CaptureLease {
217
247
  const request = (method, extra = {}) => this.graph.request(method, { leaseId: this.leaseId, ...extra });
218
248
  return {
219
249
  selectedHarness,
220
- turn: prompt => request('turn', { prompt }),
250
+ turn: prompt => this.graph.run(this.leaseId, 'turn', { prompt }),
221
251
  steer: async (prompt) => { await request('steer', { prompt }); },
222
252
  interrupt: async () => { await request('interrupt'); },
223
- resume: () => request('resume'),
253
+ resume: () => this.graph.run(this.leaseId, 'resume'),
224
254
  close: async () => {
225
255
  if (this.nativeClosed)
226
256
  return;
227
257
  await request('native.close');
228
258
  this.nativeClosed = true;
229
259
  this.graph.deleteApprovalHandler(this.leaseId);
260
+ this.graph.deleteEventPort(this.leaseId);
230
261
  },
231
262
  };
232
263
  }
@@ -237,6 +268,7 @@ class CaptureLease {
237
268
  this.released = true;
238
269
  this.nativeClosed = true;
239
270
  this.graph.deleteApprovalHandler(this.leaseId);
271
+ this.graph.deleteEventPort(this.leaseId);
240
272
  }
241
273
  await this.opening?.catch(() => undefined);
242
274
  if (this.launcher) {
@@ -250,6 +282,7 @@ class CaptureLease {
250
282
  this.released = true;
251
283
  this.nativeClosed = true;
252
284
  this.graph.deleteApprovalHandler(this.leaseId);
285
+ this.graph.deleteEventPort(this.leaseId);
253
286
  await this.opening?.catch(() => undefined);
254
287
  if (this.launcher) {
255
288
  await this.launcher.close().catch(() => { });
@@ -259,7 +292,7 @@ class CaptureLease {
259
292
  }
260
293
  }
261
294
  export async function captureExecution(agent, input, options = {}) {
262
- return captureRequest(input, options, { method: 'capture', agent });
295
+ return captureRequest(input, options, { method: 'capture', agent, projectRoot: input.project?.root });
263
296
  }
264
297
  /** Captures an already resolved private CLI reference without applying public connected validation. */
265
298
  export async function captureReference(reference, input, options = {}) {
@@ -273,7 +306,7 @@ async function captureRequest(input, options, request) {
273
306
  const extension = workerModule.pathname.endsWith('.ts') ? 'ts' : 'js';
274
307
  let child;
275
308
  try {
276
- child = fork(fileURLToPath(workerModule), [], { cwd: input.cwd, env: environment, stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
309
+ child = fork(fileURLToPath(workerModule), [], { cwd: input.cwd, env: environment, stdio: ['ignore', 'ignore', 'ignore', 'ipc', 'pipe'],
277
310
  execArgv: extension === 'ts' ? ['--import', import.meta.resolve('tsx')] : [] });
278
311
  }
279
312
  catch {
@@ -283,7 +316,7 @@ async function captureRequest(input, options, request) {
283
316
  try {
284
317
  const { method, ...data } = request;
285
318
  const result = await graph.request(method, data);
286
- return new CaptureLease(graph, result.leaseId, result.reference, result.children);
319
+ return new CaptureLease(graph, result.leaseId, result.reference, result.children, result.name);
287
320
  }
288
321
  catch (error) {
289
322
  await graph.stop().catch(() => { });
@@ -294,8 +327,10 @@ export async function checkCapturedExecution(captured, input) {
294
327
  let native;
295
328
  let failure;
296
329
  try {
330
+ const project = retainedProject(input.project);
297
331
  native = await captured.prepared.open({ reference: captured.reference, cwd: input.cwd, env: input.env,
298
- token: randomUUID(), sessionId: `check_${randomUUID()}` });
332
+ token: randomUUID(), sessionId: `check_${randomUUID()}`,
333
+ ...(project ? { project } : {}) });
299
334
  await native.close();
300
335
  }
301
336
  catch (error) {
@@ -317,4 +352,13 @@ export async function checkCapturedExecution(captured, input) {
317
352
  if (failure)
318
353
  throw failure;
319
354
  }
355
+ function retainedProject(project) {
356
+ if (project === undefined)
357
+ return undefined;
358
+ if (!project || typeof project !== 'object' || Array.isArray(project)
359
+ || typeof project.root !== 'string' || !isAbsolute(project.root)
360
+ || typeof project.accessRoot !== 'string' || !isAbsolute(project.accessRoot))
361
+ throw new AgentError('INVALID_ARGUMENT', 'Retained project context must include absolute project and access roots.');
362
+ return project;
363
+ }
320
364
  //# sourceMappingURL=capture.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"capture.js","sourceRoot":"","sources":["../../src/runtime/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAqB,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAkB,MAAM,cAAc,CAAC;AAMrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAkBnE,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC,MAAM,eAAe;IAYU,KAAK;IAA+B,OAAO;IAXhE,MAAM,GAAC,CAAC,CAAC;IACT,OAAO,GAAC,IAAI,GAAG,EAAkF,CAAC;IAClG,SAAS,GAAC,IAAI,GAAG,EAA0B,CAAC;IAC5C,QAAQ,GAAC,IAAI,GAAG,EAAoC,CAAC;IACrD,MAAM,GAAC,KAAK,CAAC;IACb,MAAM,GAAC,IAAI,GAAG,EAAU,CAAC;IACzB,eAAe,GAAC,IAAI,GAAG,EAAU,CAAC;IAClC,YAAY,GAAC,EAAE,CAAC;IACP,WAAW,CAAe;IACnC,UAAU,CAAW;IAE7B,YAA6B,KAAkB,EAAkB,OAAc;qBAAlD,KAAK;uBAA+B,OAAO;QACtE,IAAI,CAAC,WAAW,GAAC,IAAI,OAAO,CAAC,OAAO,CAAA,EAAE,GAAC,IAAI,CAAC,UAAU,GAAC,OAAO,CAAC,CAAA,CAAC,CAAC,CAAC;QAClE,KAAK,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AA0B,EAAC,KAAwB;IAC9F,IAAI,MAAqC,CAAC;IAC1C,IAAI,OAAe,CAAC;IACpB,IAAG,CAAC;QACF,MAAM,GAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAC,SAAS,EAAC,QAAQ,CAAC,SAAS,EAAC,GAAG,EAAC,KAAK,CAAC,GAAG,EAAC,GAAG,EAAC,KAAK,CAAC,GAAG;YAC3F,KAAK,EAAC,UAAU,EAAE,EAAC,SAAS,EAAC,SAAS,UAAU,EAAE,EAAE,EAAC,CAAC,CAAC;QACzD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAAA,OAAM,KAAK,EAAC,CAAC;QAAA,OAAO,GAAC,KAAK,CAAC;IAAA,CAAC;IAC7B,IAAG,CAAC;QAAA,MAAM,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAAA,CAAC;IAAA,OAAM,KAAK,EAAC,CAAC;QAChD,OAAO,KAAG,KAAK,CAAC;QAChB,IAAG,CAAC;YAAA,MAAM,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAAA,CAAC;QACrC,MAAK,CAAC;YAAA,IAAG,QAAQ,YAAY,YAAY;gBAAC,MAAM,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QAAA,CAAC;IACjF,CAAC;IACD,IAAG,OAAO;QAAC,MAAM,OAAO,CAAC;AAC3B,CAAC","sourcesContent":["import { fork, type ChildProcess } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { randomUUID } from 'node:crypto';\nimport { AgentError, errorInfo, type ErrorInfo } from '../errors.js';\nimport type { ApprovalHandler } from '../approvals/types.js';\nimport type { HarnessConfig, HarnessKind } from '../sdk/types.js';\nimport type { CatalogEnvironment } from './catalog.js';\nimport type { DriverInput, ExecutionReference, ManagedNativeSession, PreparedExecution } from './types.js';\nimport type { ApprovalEvent } from './worker-approvals.js';\nimport { createSessionLauncher } from './session-launcher.js';\nimport { processExitDescription } from '../process-diagnostics.js';\n\nexport interface CapturedChild {\n readonly name: string;\n readonly description: string;\n}\n\nexport interface CapturedExecution {\n readonly reference: ExecutionReference;\n readonly prepared: PreparedExecution;\n readonly children: readonly CapturedChild[];\n child(name: string): Promise<CapturedExecution>;\n}\n\ninterface CaptureOptions { workerModule?: URL; shutdownTimeoutMs?: number }\ninterface CaptureResult {leaseId:number;reference:ExecutionReference;children:CapturedChild[]}\ntype WorkerReply = ApprovalEvent & {leaseId:number} | {id:number;result?:unknown;error?:ErrorInfo};\n\nconst shutdownTimeoutMs = 1_000;\n\nclass GraphConnection {\n private nextId=1;\n private pending=new Map<number,{operation:string;resolve(value:unknown):void;reject(error:Error):void}>();\n private approvals=new Map<string,AbortController>();\n private handlers=new Map<number,ApprovalHandler|undefined>();\n private exited=false;\n private leases=new Set<number>();\n private abandonedLeases=new Set<number>();\n private observedExit='';\n private readonly processExit:Promise<void>;\n private markExited!:()=>void;\n\n constructor(private readonly child:ChildProcess,private readonly timeout:number) {\n this.processExit=new Promise(resolve=>{this.markExited=resolve;});\n child.once('error',()=>this.exit(undefined,undefined,true));\n child.once('exit',(code,signal)=>this.exit(code,signal));\n child.on('message',(message:WorkerReply)=>this.message(message));\n }\n\n setApprovalHandler(leaseId:number,handler:ApprovalHandler|undefined) { this.handlers.set(leaseId,handler); }\n deleteApprovalHandler(leaseId:number) { this.handlers.delete(leaseId); }\n retainLease(leaseId:number) { this.leases.add(leaseId); }\n async releaseLease(leaseId:number) {\n this.leases.delete(leaseId);\n await this.retryAbandonedLeases();\n const retained=[...this.leases].filter(id=>!this.abandonedLeases.has(id));\n if(retained.length!==0)return;\n if(this.abandonedLeases.size){this.abandonedLeases.clear();this.leases.clear();await this.stop();return;}\n if(await this.waitWithin(this.timeout))return;\n await this.stop();\n }\n async abandonLease(leaseId:number) {\n if(!this.leases.has(leaseId))return;\n const siblings=[...this.leases].filter(id=>id!==leaseId&&!this.abandonedLeases.has(id));\n if(siblings.length){this.abandonedLeases.add(leaseId);return;}\n this.leases.delete(leaseId);\n await this.stop();\n }\n\n private async retryAbandonedLeases() {\n for(const leaseId of [...this.abandonedLeases]){\n try{\n await this.request('lease.close',{leaseId});\n this.abandonedLeases.delete(leaseId);this.leases.delete(leaseId);\n }catch{/* Retain ownership until the remaining graph leases close. */}\n }\n }\n\n request(method:string,extra:Record<string,unknown>={}):Promise<unknown> {\n return new Promise((resolve,reject)=>{\n if(this.exited){reject(new AgentError('HARNESS_FAILED',`The captured definition worker is unavailable while ${method} was pending${this.observedExit}.`));return;}\n const id=this.nextId++;\n this.pending.set(id,{operation:method,resolve,reject});\n this.child.send({id,method,...extra},error=>{\n if(!error)return;\n setImmediate(()=>{\n const waiting=this.pending.get(id);\n if(!waiting||this.exited)return;\n this.pending.delete(id);\n waiting.reject(new AgentError('HARNESS_FAILED',`Cannot reach the captured definition worker while ${method} was pending.`));\n });\n });\n });\n }\n\n private message(message:WorkerReply) {\n if('event' in message){\n const key=`${message.leaseId}:${message.requestId}`;\n if(message.event==='approval.withdraw'){\n this.approvals.get(key)?.abort();this.approvals.delete(key);return;\n }\n const controller=new AbortController();\n this.approvals.set(key,controller);\n void Promise.resolve().then(()=>{\n const handler=this.handlers.get(message.leaseId);\n if(!handler)throw new AgentError('INPUT_REQUIRED','Native tool approval requires an observing caller.');\n return handler(message.request,controller.signal);\n }).then(\n content=>{if(!controller.signal.aborted&&!this.exited)return this.request('approval.respond',{leaseId:message.leaseId,requestId:message.requestId,content});},\n error=>{if(!controller.signal.aborted&&!this.exited)return this.request('approval.respond',{leaseId:message.leaseId,requestId:message.requestId,error:errorInfo(error)});},\n ).catch(error=>{\n if(!controller.signal.aborted&&!this.exited)\n return this.request('approval.respond',{leaseId:message.leaseId,requestId:message.requestId,error:errorInfo(error)}).catch(()=>{});\n }).finally(()=>this.approvals.delete(key));\n return;\n }\n const waiting=this.pending.get(message.id);\n if(!waiting)return;\n this.pending.delete(message.id);\n if(message.error)waiting.reject(new AgentError(message.error.code,message.error.message));\n else waiting.resolve(message.result);\n }\n\n private exit(code:unknown,signal:unknown,spawnFailure=false) {\n if(this.exited)return;\n this.exited=true;\n this.observedExit=spawnFailure?'':processExitDescription(code,signal);\n for(const controller of this.approvals.values())controller.abort();\n this.approvals.clear();this.markExited();\n for(const waiting of this.pending.values())waiting.reject(new AgentError('HARNESS_FAILED',spawnFailure\n ?`The captured definition worker process failed while ${waiting.operation} was pending.`\n :`The captured definition worker exited while ${waiting.operation} was pending${this.observedExit}.`));\n this.pending.clear();\n }\n\n async stop() {\n if(this.exited)return;\n if(this.child.connected)try{this.child.disconnect();}catch{}\n if(await this.waitWithin(this.timeout))return;\n this.child.kill('SIGTERM');\n if(await this.waitWithin(this.timeout))return;\n this.child.kill('SIGKILL');\n if(!await this.waitWithin(this.timeout))throw new AgentError('HARNESS_FAILED','The captured definition worker did not confirm termination.');\n }\n\n private waitWithin(timeout:number):Promise<boolean>{\n return new Promise(resolve=>{\n const timer=setTimeout(()=>resolve(false),timeout);\n this.processExit.then(()=>{clearTimeout(timer);resolve(true);});\n });\n }\n}\n\nclass CaptureLease implements CapturedExecution {\n readonly prepared:PreparedExecution;\n readonly children:readonly CapturedChild[];\n private launcher?:Awaited<ReturnType<typeof createSessionLauncher>>;\n private nativeClosed=false;\n private released=false;\n private closing=false;\n private opening?:Promise<ManagedNativeSession>;\n\n constructor(\n private readonly graph:GraphConnection,\n private readonly leaseId:number,\n readonly reference:ExecutionReference,\n children:readonly CapturedChild[],\n ) {\n this.graph.retainLease(leaseId);\n this.children=Object.freeze(children.map(child=>Object.freeze({...child})));\n this.prepared={open:input=>this.open(input),close:()=>this.close()};\n }\n\n async child(name:string):Promise<CapturedExecution>{\n if(this.released)throw new AgentError('INVALID_PARENT','The captured parent context is closed.');\n const result=await this.graph.request('child',{leaseId:this.leaseId,name}) as CaptureResult;\n return new CaptureLease(this.graph,result.leaseId,result.reference,result.children);\n }\n\n private async open(input:DriverInput):Promise<ManagedNativeSession>{\n if(this.released||this.closing||this.opening)throw new AgentError('HARNESS_FAILED','Native session startup is unavailable.');\n const opening=this.startOpen(input);\n this.opening=opening;\n return opening;\n }\n\n private async startOpen(input:DriverInput):Promise<ManagedNativeSession>{\n const state=input.env.AGENT_STATE_DIR;\n if(typeof state!=='string'||!state)throw new AgentError('INVALID_CONFIG','AGENT_STATE_DIR must select the coordinator state directory.');\n const launcher=await createSessionLauncher(state,input.token);\n this.launcher=launcher;\n if(this.closing){\n await launcher.close();this.launcher=undefined;\n throw new AgentError('COORDINATOR_UNAVAILABLE','The captured session closed during startup.');\n }\n const {onApproval,...serializedInput}=input;\n let selectedHarness:HarnessKind|undefined;\n try{\n this.graph.setApprovalHandler(this.leaseId,onApproval);\n selectedHarness=await this.graph.request('open',{leaseId:this.leaseId,input:serializedInput,\n handlesApprovals:!!onApproval,launcherPath:launcher.path}) as HarnessKind;\n }catch(error){\n this.graph.deleteApprovalHandler(this.leaseId);\n this.launcher=undefined;\n await launcher.close();\n throw error;\n }\n const request=(method:string,extra:Record<string,unknown>={})=>this.graph.request(method,{leaseId:this.leaseId,...extra});\n return {\n selectedHarness,\n turn:prompt=>request('turn',{prompt}) as Promise<string>,\n steer:async prompt=>{await request('steer',{prompt});},\n interrupt:async()=>{await request('interrupt');},\n resume:()=>request('resume') as Promise<string>,\n close:async()=>{\n if(this.nativeClosed)return;\n await request('native.close');\n this.nativeClosed=true;\n this.graph.deleteApprovalHandler(this.leaseId);\n },\n };\n }\n\n private async close():Promise<void>{\n this.closing=true;\n if(!this.released){\n await this.graph.request('lease.close',{leaseId:this.leaseId});\n this.released=true;\n this.nativeClosed=true;\n this.graph.deleteApprovalHandler(this.leaseId);\n }\n await this.opening?.catch(()=>undefined);\n if(this.launcher){await this.launcher.close();this.launcher=undefined;}\n await this.graph.releaseLease(this.leaseId);\n }\n\n async abandonFailedCheck():Promise<void>{\n this.closing=true;this.released=true;this.nativeClosed=true;\n this.graph.deleteApprovalHandler(this.leaseId);\n await this.opening?.catch(()=>undefined);\n if(this.launcher){await this.launcher.close().catch(()=>{});this.launcher=undefined;}\n await this.graph.abandonLease(this.leaseId);\n }\n}\n\nexport async function captureExecution(\n agent:string|HarnessConfig,\n input:CatalogEnvironment,\n options:CaptureOptions={},\n):Promise<CapturedExecution>{\n return captureRequest(input,options,{method:'capture',agent});\n}\n\n/** Captures an already resolved private CLI reference without applying public connected validation. */\nexport async function captureReference(\n reference:ExecutionReference,\n input:CatalogEnvironment,\n options:CaptureOptions={},\n):Promise<CapturedExecution>{\n if('kind' in reference&&reference.kind==='inline')\n throw new AgentError('INVALID_DEFINITION','Inline agent definitions cannot be loaded by native CLI workers.');\n return captureRequest(input,options,{method:'capture.reference',reference});\n}\n\nasync function captureRequest(\n input:CatalogEnvironment,\n options:CaptureOptions,\n request:{method:'capture';agent:string|HarnessConfig}|{method:'capture.reference';reference:ExecutionReference},\n):Promise<CapturedExecution>{\n const {AGENT_PARENT_TOKEN:_parent,AGENT_CLI_PATH:_launcher,...environment}=input.env;\n const workerModule=options.workerModule??new URL(`./worker.${import.meta.url.endsWith('.ts')?'ts':'js'}`,import.meta.url);\n const extension=workerModule.pathname.endsWith('.ts')?'ts':'js';\n let child:ChildProcess;\n try{\n child=fork(fileURLToPath(workerModule),[],{cwd:input.cwd,env:environment,stdio:['ignore','ignore','ignore','ipc'],\n execArgv:extension==='ts'?['--import',import.meta.resolve('tsx')]:[]});\n }catch{throw new AgentError('INVALID_DEFINITION','The captured definition worker could not be spawned.');}\n const graph=new GraphConnection(child,options.shutdownTimeoutMs??shutdownTimeoutMs);\n try{\n const {method,...data}=request;\n const result=await graph.request(method,data) as CaptureResult;\n return new CaptureLease(graph,result.leaseId,result.reference,result.children);\n }catch(error){await graph.stop().catch(()=>{});throw error;}\n}\n\nexport async function checkCapturedExecution(captured:CapturedExecution,input:CatalogEnvironment):Promise<void>{\n let native:ManagedNativeSession|undefined;\n let failure:unknown;\n try{\n native=await captured.prepared.open({reference:captured.reference,cwd:input.cwd,env:input.env,\n token:randomUUID(),sessionId:`check_${randomUUID()}`});\n await native.close();\n }catch(error){failure=error;}\n try{await captured.prepared.close();}catch(error){\n failure??=error;\n try{await captured.prepared.close();}\n catch{if(captured instanceof CaptureLease)await captured.abandonFailedCheck();}\n }\n if(failure)throw failure;\n}\n"]}
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../../src/runtime/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAqB,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAkB,MAAM,cAAc,CAAC;AAOrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAqBvD,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC,MAAM,eAAe;IAcU,KAAK;IAA+B,OAAO;IAbhE,MAAM,GAAC,CAAC,CAAC;IACT,OAAO,GAAC,IAAI,GAAG,EACmC,CAAC;IACnD,SAAS,GAAC,IAAI,GAAG,EAA0B,CAAC;IAC5C,QAAQ,GAAC,IAAI,GAAG,EAAoC,CAAC;IACrD,MAAM,GAAC,KAAK,CAAC;IACb,MAAM,GAAC,IAAI,GAAG,EAAU,CAAC;IACzB,eAAe,GAAC,IAAI,GAAG,EAAU,CAAC;IAClC,YAAY,GAAC,EAAE,CAAC;IACP,WAAW,CAAe;IAC1B,YAAY,CAAmB;IACxC,UAAU,CAAW;IAE7B,YAA6B,KAAkB,EAAkB,OAAc;qBAAlD,KAAK;uBAA+B,OAAO;QACtE,IAAI,CAAC,WAAW,GAAC,IAAI,OAAO,CAAC,OAAO,CAAA,EAAE,GAAC,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,SAAS,eAAe,CAAC,OAAiC;IACxD,IAAG,OAAO,KAAG,SAAS;QAAC,OAAO,SAAS,CAAC;IACxC,IAAG,CAAC,OAAO,IAAE,OAAO,OAAO,KAAG,QAAQ,IAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;WAC1D,OAAO,OAAO,CAAC,IAAI,KAAG,QAAQ,IAAE,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC;WACzD,OAAO,OAAO,CAAC,UAAU,KAAG,QAAQ,IAAE,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC;QACvE,MAAM,IAAI,UAAU,CAAC,kBAAkB,EAAC,0EAA0E,CAAC,CAAC;IACtH,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { fork, type ChildProcess } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { randomUUID } from 'node:crypto';\nimport { isAbsolute } from 'node:path';\nimport { AgentError, errorInfo, type ErrorInfo } from '../errors.js';\nimport type { ApprovalHandler } from '../approvals/types.js';\nimport type { HarnessConfig, HarnessKind } from '../sdk/types.js';\nimport type { ExecutionEnvironment } from './catalog.js';\nimport type { SelectedProject } from '../config/project-context.js';\nimport type { DriverInput, ExecutionReference, ManagedNativeSession, PreparedExecution } from './types.js';\nimport type { ApprovalEvent } from './worker-approvals.js';\nimport { createSessionLauncher } from './session-launcher.js';\nimport { processExitDescription } from '../process-diagnostics.js';\nimport { WorkerEventClient } from './worker-events.js';\nimport type { Readable } from 'node:stream';\nimport type { WorkerObservationCompletion, WorkerOpenResult } from './worker-event-protocol.js';\n\nexport interface CapturedChild {\n readonly name: string;\n readonly description: string;\n}\n\nexport interface CapturedExecution {\n readonly reference: ExecutionReference;\n readonly prepared: PreparedExecution;\n readonly children: readonly CapturedChild[];\n child(name: string): Promise<CapturedExecution>;\n}\n\ninterface CaptureOptions { workerModule?: URL; shutdownTimeoutMs?: number }\ninterface CaptureResult {leaseId:number;reference:ExecutionReference;name:string;children:CapturedChild[]}\ntype WorkerReply = ApprovalEvent & {leaseId:number} | {id:number;result?:unknown;error?:ErrorInfo;\n observation?:WorkerObservationCompletion};\n\nconst shutdownTimeoutMs = 1_000;\n\nclass GraphConnection {\n private nextId=1;\n private pending=new Map<number,{operation:string;leaseId?:number;observationOperationId?:string;\n resolve(value:unknown):void;reject(error:Error):void}>();\n private approvals=new Map<string,AbortController>();\n private handlers=new Map<number,ApprovalHandler|undefined>();\n private exited=false;\n private leases=new Set<number>();\n private abandonedLeases=new Set<number>();\n private observedExit='';\n private readonly processExit:Promise<void>;\n private readonly workerEvents:WorkerEventClient;\n private markExited!:()=>void;\n\n constructor(private readonly child:ChildProcess,private readonly timeout:number) {\n this.processExit=new Promise(resolve=>{this.markExited=resolve;});\n this.workerEvents=new WorkerEventClient(child.stdio[4] as Readable,(method,data)=>this.request(method,data));\n child.once('error',()=>this.exit(undefined,undefined,true));\n child.once('exit',(code,signal)=>this.exit(code,signal));\n child.on('message',(message:WorkerReply)=>this.message(message));\n }\n\n setApprovalHandler(leaseId:number,handler:ApprovalHandler|undefined) { this.handlers.set(leaseId,handler); }\n deleteApprovalHandler(leaseId:number) { this.handlers.delete(leaseId); }\n setEventPort(leaseId:number,port:DriverInput['events']) { this.workerEvents.attach(leaseId,port); }\n deleteEventPort(leaseId:number) { this.workerEvents.detach(leaseId); }\n retainLease(leaseId:number) { this.leases.add(leaseId); }\n async releaseLease(leaseId:number) {\n this.leases.delete(leaseId);\n await this.retryAbandonedLeases();\n const retained=[...this.leases].filter(id=>!this.abandonedLeases.has(id));\n if(retained.length!==0)return;\n if(this.abandonedLeases.size){this.abandonedLeases.clear();this.leases.clear();await this.stop();return;}\n if(await this.waitWithin(this.timeout))return;\n await this.stop();\n }\n async abandonLease(leaseId:number) {\n if(!this.leases.has(leaseId))return;\n const siblings=[...this.leases].filter(id=>id!==leaseId&&!this.abandonedLeases.has(id));\n if(siblings.length){this.abandonedLeases.add(leaseId);return;}\n this.leases.delete(leaseId);\n await this.stop();\n }\n\n private async retryAbandonedLeases() {\n for(const leaseId of [...this.abandonedLeases]){\n try{\n await this.request('lease.close',{leaseId});\n this.abandonedLeases.delete(leaseId);this.leases.delete(leaseId);\n }catch{/* Retain ownership until the remaining graph leases close. */}\n }\n }\n\n request(method:string,extra:Record<string,unknown>={}):Promise<unknown> {\n return new Promise((resolve,reject)=>{\n if(this.exited){reject(new AgentError('HARNESS_FAILED',`The captured definition worker is unavailable while ${method} was pending${this.observedExit}.`));return;}\n const id=this.nextId++;\n const observationOperationId=typeof extra.observation==='object'&&extra.observation!==null\n &&typeof (extra.observation as {operationId?:unknown}).operationId==='string'\n ?(extra.observation as {operationId:string}).operationId:undefined;\n this.pending.set(id,{operation:method,leaseId:typeof extra.leaseId==='number'?extra.leaseId:undefined,\n observationOperationId,resolve,reject});\n this.child.send({id,method,...extra},error=>{\n if(!error)return;\n setImmediate(()=>{\n const waiting=this.pending.get(id);\n if(!waiting||this.exited)return;\n this.pending.delete(id);\n waiting.reject(new AgentError('HARNESS_FAILED',`Cannot reach the captured definition worker while ${method} was pending.`));\n });\n });\n });\n }\n\n private message(message:WorkerReply) {\n if(this.workerEvents.acceptControl(message))return;\n if('event' in message){\n const key=`${message.leaseId}:${message.requestId}`;\n if(message.event==='approval.withdraw'){\n this.approvals.get(key)?.abort();this.approvals.delete(key);return;\n }\n const controller=new AbortController();\n this.approvals.set(key,controller);\n void Promise.resolve().then(()=>{\n const handler=this.handlers.get(message.leaseId);\n if(!handler)throw new AgentError('INPUT_REQUIRED','Native tool approval requires an observing caller.');\n return handler(message.request,controller.signal);\n }).then(\n content=>{if(!controller.signal.aborted&&!this.exited)return this.request('approval.respond',{leaseId:message.leaseId,requestId:message.requestId,content});},\n error=>{if(!controller.signal.aborted&&!this.exited)return this.request('approval.respond',{leaseId:message.leaseId,requestId:message.requestId,error:errorInfo(error)});},\n ).catch(error=>{\n if(!controller.signal.aborted&&!this.exited)\n return this.request('approval.respond',{leaseId:message.leaseId,requestId:message.requestId,error:errorInfo(error)}).catch(()=>{});\n }).finally(()=>this.approvals.delete(key));\n return;\n }\n const waiting=this.pending.get(message.id);\n if(!waiting)return;\n this.pending.delete(message.id);\n const operationError=message.error?new AgentError(message.error.code,message.error.message):undefined;\n void this.workerEvents.complete(waiting.leaseId!,message.observation,waiting.observationOperationId).then(()=>{\n if(operationError)waiting.reject(operationError);else waiting.resolve(message.result);\n },()=>{if(operationError)waiting.reject(operationError);else waiting.resolve(message.result);});\n }\n\n private exit(code:unknown,signal:unknown,spawnFailure=false) {\n if(this.exited)return;\n this.exited=true;\n this.observedExit=spawnFailure?'':processExitDescription(code,signal);\n for(const controller of this.approvals.values())controller.abort();\n this.approvals.clear();this.workerEvents.close();this.markExited();\n for(const waiting of this.pending.values())waiting.reject(new AgentError('HARNESS_FAILED',spawnFailure\n ?`The captured definition worker process failed while ${waiting.operation} was pending.`\n :`The captured definition worker exited while ${waiting.operation} was pending${this.observedExit}.`));\n this.pending.clear();\n }\n\n async stop() {\n if(this.exited)return;\n if(this.child.connected)try{this.child.disconnect();}catch{}\n if(await this.waitWithin(this.timeout))return;\n this.child.kill('SIGTERM');\n if(await this.waitWithin(this.timeout))return;\n this.child.kill('SIGKILL');\n if(!await this.waitWithin(this.timeout))throw new AgentError('HARNESS_FAILED','The captured definition worker did not confirm termination.');\n }\n\n run(leaseId:number,method:'turn'|'resume',extra:Record<string,unknown>={}):Promise<unknown>{\n const observation=this.workerEvents.begin(leaseId);\n return this.request(method,{leaseId,...extra,...(observation?{observation}:{})});\n }\n\n selected(leaseId:number,opened:WorkerOpenResult):void{\n this.workerEvents.metadata(leaseId,opened);\n }\n\n private waitWithin(timeout:number):Promise<boolean>{\n return new Promise(resolve=>{\n const timer=setTimeout(()=>resolve(false),timeout);\n this.processExit.then(()=>{clearTimeout(timer);resolve(true);});\n });\n }\n}\n\nclass CaptureLease implements CapturedExecution {\n readonly prepared:PreparedExecution;\n readonly children:readonly CapturedChild[];\n private launcher?:Awaited<ReturnType<typeof createSessionLauncher>>;\n private nativeClosed=false;\n private released=false;\n private closing=false;\n private opening?:Promise<ManagedNativeSession>;\n\n constructor(\n private readonly graph:GraphConnection,\n private readonly leaseId:number,\n readonly reference:ExecutionReference,\n children:readonly CapturedChild[],\n agentName:string,\n ) {\n this.graph.retainLease(leaseId);\n this.children=Object.freeze(children.map(child=>Object.freeze({...child})));\n this.prepared={display:{agentName},open:input=>this.open(input),close:()=>this.close()};\n }\n\n async child(name:string):Promise<CapturedExecution>{\n if(this.released)throw new AgentError('INVALID_PARENT','The captured parent context is closed.');\n const result=await this.graph.request('child',{leaseId:this.leaseId,name}) as CaptureResult;\n return new CaptureLease(this.graph,result.leaseId,result.reference,result.children,result.name);\n }\n\n private async open(input:DriverInput):Promise<ManagedNativeSession>{\n if(this.released||this.closing||this.opening)throw new AgentError('HARNESS_FAILED','Native session startup is unavailable.');\n const opening=this.startOpen(input);\n this.opening=opening;\n return opening;\n }\n\n private async startOpen(input:DriverInput):Promise<ManagedNativeSession>{\n const state=input.env.AGENT_STATE_DIR;\n if(typeof state!=='string'||!state)throw new AgentError('INVALID_CONFIG','AGENT_STATE_DIR must select the coordinator state directory.');\n const launcher=await createSessionLauncher(state,input.token);\n this.launcher=launcher;\n if(this.closing){\n await launcher.close();this.launcher=undefined;\n throw new AgentError('COORDINATOR_UNAVAILABLE','The captured session closed during startup.');\n }\n const {onApproval,events,...serializedInput}=input;\n let selectedHarness:HarnessKind|undefined;\n try{\n this.graph.setApprovalHandler(this.leaseId,onApproval);\n this.graph.setEventPort(this.leaseId,events);\n const opened=await this.graph.request('open',{leaseId:this.leaseId,input:serializedInput,\n handlesApprovals:!!onApproval,launcherPath:launcher.path}) as WorkerOpenResult;\n selectedHarness=opened.selectedHarness;\n this.graph.selected(this.leaseId,opened);\n }catch(error){\n this.graph.deleteApprovalHandler(this.leaseId);\n this.graph.deleteEventPort(this.leaseId);\n this.launcher=undefined;\n await launcher.close();\n throw error;\n }\n const request=(method:string,extra:Record<string,unknown>={})=>this.graph.request(method,{leaseId:this.leaseId,...extra});\n return {\n selectedHarness,\n turn:prompt=>this.graph.run(this.leaseId,'turn',{prompt}) as Promise<string>,\n steer:async prompt=>{await request('steer',{prompt});},\n interrupt:async()=>{await request('interrupt');},\n resume:()=>this.graph.run(this.leaseId,'resume') as Promise<string>,\n close:async()=>{\n if(this.nativeClosed)return;\n await request('native.close');\n this.nativeClosed=true;\n this.graph.deleteApprovalHandler(this.leaseId);\n this.graph.deleteEventPort(this.leaseId);\n },\n };\n }\n\n private async close():Promise<void>{\n this.closing=true;\n if(!this.released){\n await this.graph.request('lease.close',{leaseId:this.leaseId});\n this.released=true;\n this.nativeClosed=true;\n this.graph.deleteApprovalHandler(this.leaseId);\n this.graph.deleteEventPort(this.leaseId);\n }\n await this.opening?.catch(()=>undefined);\n if(this.launcher){await this.launcher.close();this.launcher=undefined;}\n await this.graph.releaseLease(this.leaseId);\n }\n\n async abandonFailedCheck():Promise<void>{\n this.closing=true;this.released=true;this.nativeClosed=true;\n this.graph.deleteApprovalHandler(this.leaseId);\n this.graph.deleteEventPort(this.leaseId);\n await this.opening?.catch(()=>undefined);\n if(this.launcher){await this.launcher.close().catch(()=>{});this.launcher=undefined;}\n await this.graph.abandonLease(this.leaseId);\n }\n}\n\nexport async function captureExecution(\n agent:string|HarnessConfig,\n input:ExecutionEnvironment,\n options:CaptureOptions={},\n):Promise<CapturedExecution>{\n return captureRequest(input,options,{method:'capture',agent,projectRoot:input.project?.root});\n}\n\n/** Captures an already resolved private CLI reference without applying public connected validation. */\nexport async function captureReference(\n reference:ExecutionReference,\n input:ExecutionEnvironment,\n options:CaptureOptions={},\n):Promise<CapturedExecution>{\n if('kind' in reference&&reference.kind==='inline')\n throw new AgentError('INVALID_DEFINITION','Inline agent definitions cannot be loaded by native CLI workers.');\n return captureRequest(input,options,{method:'capture.reference',reference});\n}\n\nasync function captureRequest(\n input:ExecutionEnvironment,\n options:CaptureOptions,\n request:{method:'capture';agent:string|HarnessConfig;projectRoot?:string}|{method:'capture.reference';reference:ExecutionReference},\n):Promise<CapturedExecution>{\n const {AGENT_PARENT_TOKEN:_parent,AGENT_CLI_PATH:_launcher,...environment}=input.env;\n const workerModule=options.workerModule??new URL(`./worker.${import.meta.url.endsWith('.ts')?'ts':'js'}`,import.meta.url);\n const extension=workerModule.pathname.endsWith('.ts')?'ts':'js';\n let child:ChildProcess;\n try{\n child=fork(fileURLToPath(workerModule),[],{cwd:input.cwd,env:environment,stdio:['ignore','ignore','ignore','ipc','pipe'],\n execArgv:extension==='ts'?['--import',import.meta.resolve('tsx')]:[]});\n }catch{throw new AgentError('INVALID_DEFINITION','The captured definition worker could not be spawned.');}\n const graph=new GraphConnection(child,options.shutdownTimeoutMs??shutdownTimeoutMs);\n try{\n const {method,...data}=request;\n const result=await graph.request(method,data) as CaptureResult;\n return new CaptureLease(graph,result.leaseId,result.reference,result.children,result.name);\n }catch(error){await graph.stop().catch(()=>{});throw error;}\n}\n\nexport async function checkCapturedExecution(captured:CapturedExecution,input:ExecutionEnvironment):Promise<void>{\n let native:ManagedNativeSession|undefined;\n let failure:unknown;\n try{\n const project=retainedProject(input.project);\n native=await captured.prepared.open({reference:captured.reference,cwd:input.cwd,env:input.env,\n token:randomUUID(),sessionId:`check_${randomUUID()}`,\n ...(project ? {project} : {})});\n await native.close();\n }catch(error){failure=error;}\n try{await captured.prepared.close();}catch(error){\n failure??=error;\n try{await captured.prepared.close();}\n catch{if(captured instanceof CaptureLease)await captured.abandonFailedCheck();}\n }\n if(failure)throw failure;\n}\n\nfunction retainedProject(project:SelectedProject|undefined):SelectedProject|undefined {\n if(project===undefined)return undefined;\n if(!project||typeof project!=='object'||Array.isArray(project)\n ||typeof project.root!=='string'||!isAbsolute(project.root)\n ||typeof project.accessRoot!=='string'||!isAbsolute(project.accessRoot))\n throw new AgentError('INVALID_ARGUMENT','Retained project context must include absolute project and access roots.');\n return project;\n}\n"]}
@@ -1,9 +1,14 @@
1
1
  import { type ErrorInfo } from '../errors.js';
2
2
  import type { HarnessConfig } from '../sdk/types.js';
3
3
  import type { ExecutionReference } from './types.js';
4
+ import type { ProjectSelection, SelectedProject } from '../config/project-context.js';
4
5
  export interface CatalogEnvironment {
5
6
  readonly cwd: string;
6
7
  readonly env: NodeJS.ProcessEnv;
8
+ readonly project?: ProjectSelection;
9
+ }
10
+ export interface ExecutionEnvironment extends Omit<CatalogEnvironment, 'project'> {
11
+ readonly project?: SelectedProject;
7
12
  }
8
13
  export interface CatalogAgent {
9
14
  readonly id: string;
@@ -35,5 +40,5 @@ export declare function listAgents(input: CatalogEnvironment): Promise<{
35
40
  readonly items: readonly CatalogAgent[];
36
41
  }>;
37
42
  export declare function resolveAgent(agent: string | HarnessConfig, input: CatalogEnvironment): Promise<ExecutionReference>;
38
- export declare function checkAgent(agent: string | HarnessConfig, input: CatalogEnvironment): Promise<void>;
43
+ export declare function checkAgent(agent: string | HarnessConfig, input: ExecutionEnvironment): Promise<void>;
39
44
  export declare function loadCatalogSnapshot(input: CatalogEnvironment, parent?: ExecutionReference, discover?: boolean): Promise<CatalogSnapshot>;
@@ -75,7 +75,7 @@ export function loadCatalogSnapshot(input, parent, discover = true) {
75
75
  child.send({ received: true }, error => { if (error)
76
76
  child.kill(); });
77
77
  });
78
- child.send({ cwd: input.cwd, parent, discover }, error => { if (error) {
78
+ child.send({ cwd: input.cwd, parent, discover, projectRoot: input.project?.root }, error => { if (error) {
79
79
  child.kill();
80
80
  fail();
81
81
  } });