@provos/ironcurtain 0.9.1 → 0.11.0

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 (502) hide show
  1. package/README.md +69 -10
  2. package/dist/auth/oauth-provider.js +1 -4
  3. package/dist/auth/oauth-provider.js.map +1 -1
  4. package/dist/cli.js +40 -2
  5. package/dist/cli.js.map +1 -1
  6. package/dist/config/config-command.js +174 -10
  7. package/dist/config/config-command.js.map +1 -1
  8. package/dist/config/first-start.js +61 -0
  9. package/dist/config/first-start.js.map +1 -1
  10. package/dist/config/generated/compiled-policy.json +528 -161
  11. package/dist/config/generated/test-scenarios.json +4810 -170
  12. package/dist/config/generated/tool-annotations.json +34 -47
  13. package/dist/config/index.d.ts +58 -0
  14. package/dist/config/index.js +97 -15
  15. package/dist/config/index.js.map +1 -1
  16. package/dist/config/mcp-servers.json +2 -2
  17. package/dist/config/model-provider.d.ts +8 -2
  18. package/dist/config/model-provider.js +52 -9
  19. package/dist/config/model-provider.js.map +1 -1
  20. package/dist/config/paths.d.ts +181 -0
  21. package/dist/config/paths.js +326 -23
  22. package/dist/config/paths.js.map +1 -1
  23. package/dist/config/types.d.ts +7 -1
  24. package/dist/config/user-config.d.ts +61 -4
  25. package/dist/config/user-config.js +108 -21
  26. package/dist/config/user-config.js.map +1 -1
  27. package/dist/config/validate-policy-dir.d.ts +10 -0
  28. package/dist/config/validate-policy-dir.js +59 -0
  29. package/dist/config/validate-policy-dir.js.map +1 -0
  30. package/dist/cron/compile-task-policy.js +1 -0
  31. package/dist/cron/compile-task-policy.js.map +1 -1
  32. package/dist/cron/job-commands.js +22 -2
  33. package/dist/cron/job-commands.js.map +1 -1
  34. package/dist/cron/types.d.ts +16 -2
  35. package/dist/cron/types.js +1 -3
  36. package/dist/cron/types.js.map +1 -1
  37. package/dist/daemon/daemon-command.js +16 -2
  38. package/dist/daemon/daemon-command.js.map +1 -1
  39. package/dist/daemon/ironcurtain-daemon.d.ts +44 -1
  40. package/dist/daemon/ironcurtain-daemon.js +210 -8
  41. package/dist/daemon/ironcurtain-daemon.js.map +1 -1
  42. package/dist/docker/adapters/claude-code.d.ts +2 -1
  43. package/dist/docker/adapters/claude-code.js +320 -131
  44. package/dist/docker/adapters/claude-code.js.map +1 -1
  45. package/dist/docker/adapters/goose.d.ts +12 -11
  46. package/dist/docker/adapters/goose.js +80 -27
  47. package/dist/docker/adapters/goose.js.map +1 -1
  48. package/dist/docker/agent-adapter.d.ts +178 -4
  49. package/dist/docker/agent-adapter.js +14 -0
  50. package/dist/docker/agent-adapter.js.map +1 -1
  51. package/dist/docker/agent-registry.js +3 -2
  52. package/dist/docker/agent-registry.js.map +1 -1
  53. package/dist/docker/code-mode-proxy.d.ts +27 -0
  54. package/dist/docker/code-mode-proxy.js +3 -0
  55. package/dist/docker/code-mode-proxy.js.map +1 -1
  56. package/dist/docker/container-lifecycle.d.ts +15 -0
  57. package/dist/docker/container-lifecycle.js +32 -0
  58. package/dist/docker/container-lifecycle.js.map +1 -0
  59. package/dist/docker/docker-agent-session.d.ts +113 -62
  60. package/dist/docker/docker-agent-session.js +241 -300
  61. package/dist/docker/docker-agent-session.js.map +1 -1
  62. package/dist/docker/docker-infrastructure.d.ts +256 -21
  63. package/dist/docker/docker-infrastructure.js +585 -30
  64. package/dist/docker/docker-infrastructure.js.map +1 -1
  65. package/dist/docker/docker-manager.d.ts +36 -1
  66. package/dist/docker/docker-manager.js +168 -26
  67. package/dist/docker/docker-manager.js.map +1 -1
  68. package/dist/docker/docker-progress-sink.d.ts +43 -0
  69. package/dist/docker/docker-progress-sink.js +299 -0
  70. package/dist/docker/docker-progress-sink.js.map +1 -0
  71. package/dist/docker/mitm-proxy.d.ts +90 -1
  72. package/dist/docker/mitm-proxy.js +720 -40
  73. package/dist/docker/mitm-proxy.js.map +1 -1
  74. package/dist/docker/oauth-credentials.d.ts +46 -3
  75. package/dist/docker/oauth-credentials.js +56 -14
  76. package/dist/docker/oauth-credentials.js.map +1 -1
  77. package/dist/docker/oauth-token-manager.js +2 -2
  78. package/dist/docker/oauth-token-manager.js.map +1 -1
  79. package/dist/docker/orientation.d.ts +1 -1
  80. package/dist/docker/provider-config.d.ts +81 -2
  81. package/dist/docker/provider-config.js +222 -28
  82. package/dist/docker/provider-config.js.map +1 -1
  83. package/dist/docker/proxy-tools.d.ts +0 -2
  84. package/dist/docker/proxy-tools.js +2 -7
  85. package/dist/docker/proxy-tools.js.map +1 -1
  86. package/dist/docker/pty-session.d.ts +49 -1
  87. package/dist/docker/pty-session.js +212 -90
  88. package/dist/docker/pty-session.js.map +1 -1
  89. package/dist/docker/pty-types.d.ts +0 -2
  90. package/dist/docker/pty-types.js +0 -2
  91. package/dist/docker/pty-types.js.map +1 -1
  92. package/dist/docker/resource-limits.d.ts +125 -0
  93. package/dist/docker/resource-limits.js +200 -0
  94. package/dist/docker/resource-limits.js.map +1 -0
  95. package/dist/docker/spawn-with-idle-timeout.d.ts +39 -0
  96. package/dist/docker/spawn-with-idle-timeout.js +152 -0
  97. package/dist/docker/spawn-with-idle-timeout.js.map +1 -0
  98. package/dist/docker/sse-extractor.d.ts +51 -0
  99. package/dist/docker/sse-extractor.js +303 -0
  100. package/dist/docker/sse-extractor.js.map +1 -0
  101. package/dist/docker/token-stream-bus.d.ts +83 -0
  102. package/dist/docker/token-stream-bus.js +98 -0
  103. package/dist/docker/token-stream-bus.js.map +1 -0
  104. package/dist/docker/token-stream-types.d.ts +71 -0
  105. package/dist/docker/token-stream-types.js +8 -0
  106. package/dist/docker/token-stream-types.js.map +1 -0
  107. package/dist/docker/types.d.ts +61 -6
  108. package/dist/doctor/checks.d.ts +138 -0
  109. package/dist/doctor/checks.js +511 -0
  110. package/dist/doctor/checks.js.map +1 -0
  111. package/dist/doctor/doctor-command.d.ts +29 -0
  112. package/dist/doctor/doctor-command.js +160 -0
  113. package/dist/doctor/doctor-command.js.map +1 -0
  114. package/dist/doctor/mcp-liveness.d.ts +28 -0
  115. package/dist/doctor/mcp-liveness.js +84 -0
  116. package/dist/doctor/mcp-liveness.js.map +1 -0
  117. package/dist/doctor/oauth-checks.d.ts +23 -0
  118. package/dist/doctor/oauth-checks.js +157 -0
  119. package/dist/doctor/oauth-checks.js.map +1 -0
  120. package/dist/doctor/output.d.ts +26 -0
  121. package/dist/doctor/output.js +82 -0
  122. package/dist/doctor/output.js.map +1 -0
  123. package/dist/escalation/listener-command.js +0 -3
  124. package/dist/escalation/listener-command.js.map +1 -1
  125. package/dist/event-bus/typed-event-bus.d.ts +26 -0
  126. package/dist/event-bus/typed-event-bus.js +35 -0
  127. package/dist/event-bus/typed-event-bus.js.map +1 -0
  128. package/dist/index.js +32 -9
  129. package/dist/index.js.map +1 -1
  130. package/dist/logger.js +31 -2
  131. package/dist/logger.js.map +1 -1
  132. package/dist/memory/auto-save.d.ts +18 -4
  133. package/dist/memory/auto-save.js +46 -6
  134. package/dist/memory/auto-save.js.map +1 -1
  135. package/dist/memory/memory-policy.d.ts +41 -0
  136. package/dist/memory/memory-policy.js +36 -0
  137. package/dist/memory/memory-policy.js.map +1 -0
  138. package/dist/mux/mux-app.d.ts +2 -0
  139. package/dist/mux/mux-app.js +30 -34
  140. package/dist/mux/mux-app.js.map +1 -1
  141. package/dist/mux/mux-command.d.ts +10 -1
  142. package/dist/mux/mux-command.js +62 -35
  143. package/dist/mux/mux-command.js.map +1 -1
  144. package/dist/mux/mux-renderer.js +22 -17
  145. package/dist/mux/mux-renderer.js.map +1 -1
  146. package/dist/mux/pty-bridge.d.ts +2 -0
  147. package/dist/mux/pty-bridge.js +3 -0
  148. package/dist/mux/pty-bridge.js.map +1 -1
  149. package/dist/mux/session-scanner.d.ts +7 -0
  150. package/dist/mux/session-scanner.js +21 -2
  151. package/dist/mux/session-scanner.js.map +1 -1
  152. package/dist/mux/types.d.ts +0 -4
  153. package/dist/mux/types.js.map +1 -1
  154. package/dist/{pipeline → observability}/llm-logger.d.ts +9 -3
  155. package/dist/{pipeline → observability}/llm-logger.js +16 -4
  156. package/dist/observability/llm-logger.js.map +1 -0
  157. package/dist/observe/observe-command.d.ts +12 -0
  158. package/dist/observe/observe-command.js +298 -0
  159. package/dist/observe/observe-command.js.map +1 -0
  160. package/dist/observe/observe-renderer.d.ts +24 -0
  161. package/dist/observe/observe-renderer.js +87 -0
  162. package/dist/observe/observe-renderer.js.map +1 -0
  163. package/dist/observe/observe-tui-rain.d.ts +42 -0
  164. package/dist/observe/observe-tui-rain.js +531 -0
  165. package/dist/observe/observe-tui-rain.js.map +1 -0
  166. package/dist/observe/observe-tui-text-panel.d.ts +46 -0
  167. package/dist/observe/observe-tui-text-panel.js +525 -0
  168. package/dist/observe/observe-tui-text-panel.js.map +1 -0
  169. package/dist/observe/observe-tui-types.d.ts +270 -0
  170. package/dist/observe/observe-tui-types.js +200 -0
  171. package/dist/observe/observe-tui-types.js.map +1 -0
  172. package/dist/observe/observe-tui-word-scorer.d.ts +143 -0
  173. package/dist/observe/observe-tui-word-scorer.js +572 -0
  174. package/dist/observe/observe-tui-word-scorer.js.map +1 -0
  175. package/dist/observe/observe-tui.d.ts +59 -0
  176. package/dist/observe/observe-tui.js +592 -0
  177. package/dist/observe/observe-tui.js.map +1 -0
  178. package/dist/persona/compile-persona-policy.js +1 -0
  179. package/dist/persona/compile-persona-policy.js.map +1 -1
  180. package/dist/persona/memory-gate.d.ts +19 -0
  181. package/dist/persona/memory-gate.js +33 -0
  182. package/dist/persona/memory-gate.js.map +1 -0
  183. package/dist/persona/persona-command.js +41 -6
  184. package/dist/persona/persona-command.js.map +1 -1
  185. package/dist/persona/resolve.d.ts +22 -0
  186. package/dist/persona/resolve.js +45 -2
  187. package/dist/persona/resolve.js.map +1 -1
  188. package/dist/persona/types.d.ts +16 -0
  189. package/dist/pipeline/annotate.d.ts +7 -1
  190. package/dist/pipeline/annotate.js +92 -2
  191. package/dist/pipeline/annotate.js.map +1 -1
  192. package/dist/pipeline/compile.js +2 -0
  193. package/dist/pipeline/compile.js.map +1 -1
  194. package/dist/pipeline/constitution-compiler.d.ts +25 -14
  195. package/dist/pipeline/constitution-compiler.js +107 -38
  196. package/dist/pipeline/constitution-compiler.js.map +1 -1
  197. package/dist/pipeline/dynamic-list-types.d.ts +3 -6
  198. package/dist/pipeline/dynamic-list-types.js +3 -16
  199. package/dist/pipeline/dynamic-list-types.js.map +1 -1
  200. package/dist/pipeline/parallel-progress.d.ts +59 -0
  201. package/dist/pipeline/parallel-progress.js +263 -0
  202. package/dist/pipeline/parallel-progress.js.map +1 -0
  203. package/dist/pipeline/pipeline-runner.d.ts +49 -8
  204. package/dist/pipeline/pipeline-runner.js +419 -231
  205. package/dist/pipeline/pipeline-runner.js.map +1 -1
  206. package/dist/pipeline/pipeline-shared.d.ts +59 -1
  207. package/dist/pipeline/pipeline-shared.js +127 -12
  208. package/dist/pipeline/pipeline-shared.js.map +1 -1
  209. package/dist/pipeline/policy-verifier.js +16 -3
  210. package/dist/pipeline/policy-verifier.js.map +1 -1
  211. package/dist/pipeline/proxy-mcp-connections.js +17 -2
  212. package/dist/pipeline/proxy-mcp-connections.js.map +1 -1
  213. package/dist/pipeline/scenario-generator.d.ts +4 -8
  214. package/dist/pipeline/scenario-generator.js +13 -46
  215. package/dist/pipeline/scenario-generator.js.map +1 -1
  216. package/dist/pipeline/server-prefilter.d.ts +31 -0
  217. package/dist/pipeline/server-prefilter.js +115 -0
  218. package/dist/pipeline/server-prefilter.js.map +1 -0
  219. package/dist/pipeline/types.d.ts +5 -0
  220. package/dist/sandbox/index.d.ts +14 -0
  221. package/dist/sandbox/index.js +335 -116
  222. package/dist/sandbox/index.js.map +1 -1
  223. package/dist/sandbox/ironcurtain-protocol.d.ts +52 -0
  224. package/dist/sandbox/ironcurtain-protocol.js +185 -0
  225. package/dist/sandbox/ironcurtain-protocol.js.map +1 -0
  226. package/dist/session/agent-session.d.ts +6 -0
  227. package/dist/session/agent-session.js +16 -5
  228. package/dist/session/agent-session.js.map +1 -1
  229. package/dist/session/cli-transport.js +0 -6
  230. package/dist/session/cli-transport.js.map +1 -1
  231. package/dist/session/index.d.ts +35 -14
  232. package/dist/session/index.js +324 -130
  233. package/dist/session/index.js.map +1 -1
  234. package/dist/session/preflight.d.ts +50 -13
  235. package/dist/session/preflight.js +252 -80
  236. package/dist/session/preflight.js.map +1 -1
  237. package/dist/session/prompts.d.ts +2 -5
  238. package/dist/session/prompts.js.map +1 -1
  239. package/dist/session/session-manager.d.ts +61 -6
  240. package/dist/session/session-manager.js +72 -10
  241. package/dist/session/session-manager.js.map +1 -1
  242. package/dist/session/session-metadata.d.ts +21 -5
  243. package/dist/session/session-metadata.js +34 -12
  244. package/dist/session/session-metadata.js.map +1 -1
  245. package/dist/session/types.d.ts +311 -5
  246. package/dist/session/types.js +57 -1
  247. package/dist/session/types.js.map +1 -1
  248. package/dist/signal/setup-signal.js +13 -21
  249. package/dist/signal/setup-signal.js.map +1 -1
  250. package/dist/signal/signal-bot-daemon.d.ts +16 -1
  251. package/dist/signal/signal-bot-daemon.js +39 -27
  252. package/dist/signal/signal-bot-daemon.js.map +1 -1
  253. package/dist/signal/signal-container.js +7 -1
  254. package/dist/signal/signal-container.js.map +1 -1
  255. package/dist/skills/discovery.d.ts +77 -0
  256. package/dist/skills/discovery.js +206 -0
  257. package/dist/skills/discovery.js.map +1 -0
  258. package/dist/skills/index.d.ts +4 -0
  259. package/dist/skills/index.js +3 -0
  260. package/dist/skills/index.js.map +1 -0
  261. package/dist/skills/staging.d.ts +28 -0
  262. package/dist/skills/staging.js +68 -0
  263. package/dist/skills/staging.js.map +1 -0
  264. package/dist/skills/types.d.ts +46 -0
  265. package/dist/skills/types.js +2 -0
  266. package/dist/skills/types.js.map +1 -0
  267. package/dist/trusted-process/approval-whitelist.d.ts +0 -2
  268. package/dist/trusted-process/approval-whitelist.js +17 -17
  269. package/dist/trusted-process/approval-whitelist.js.map +1 -1
  270. package/dist/trusted-process/async-mutex.d.ts +32 -0
  271. package/dist/trusted-process/async-mutex.js +50 -0
  272. package/dist/trusted-process/async-mutex.js.map +1 -0
  273. package/dist/trusted-process/audit-log.d.ts +38 -1
  274. package/dist/trusted-process/audit-log.js +82 -13
  275. package/dist/trusted-process/audit-log.js.map +1 -1
  276. package/dist/trusted-process/call-circuit-breaker.js +2 -1
  277. package/dist/trusted-process/call-circuit-breaker.js.map +1 -1
  278. package/dist/trusted-process/control-server.d.ts +101 -0
  279. package/dist/trusted-process/control-server.js +282 -0
  280. package/dist/trusted-process/control-server.js.map +1 -0
  281. package/dist/trusted-process/domain-utils.d.ts +6 -6
  282. package/dist/trusted-process/domain-utils.js +7 -23
  283. package/dist/trusted-process/domain-utils.js.map +1 -1
  284. package/dist/trusted-process/error-prefixes.d.ts +16 -0
  285. package/dist/trusted-process/error-prefixes.js +17 -0
  286. package/dist/trusted-process/error-prefixes.js.map +1 -0
  287. package/dist/trusted-process/index.d.ts +40 -23
  288. package/dist/trusted-process/index.js +131 -225
  289. package/dist/trusted-process/index.js.map +1 -1
  290. package/dist/trusted-process/list-matcher.d.ts +17 -0
  291. package/dist/trusted-process/list-matcher.js +31 -0
  292. package/dist/trusted-process/list-matcher.js.map +1 -0
  293. package/dist/trusted-process/mcp-client-manager.d.ts +35 -6
  294. package/dist/trusted-process/mcp-client-manager.js +40 -45
  295. package/dist/trusted-process/mcp-client-manager.js.map +1 -1
  296. package/dist/trusted-process/mcp-proxy-server.d.ts +31 -120
  297. package/dist/trusted-process/mcp-proxy-server.js +166 -657
  298. package/dist/trusted-process/mcp-proxy-server.js.map +1 -1
  299. package/dist/trusted-process/policy-engine.d.ts +16 -4
  300. package/dist/trusted-process/policy-engine.js +90 -45
  301. package/dist/trusted-process/policy-engine.js.map +1 -1
  302. package/dist/trusted-process/policy-roots.d.ts +6 -0
  303. package/dist/trusted-process/policy-roots.js +20 -0
  304. package/dist/trusted-process/policy-roots.js.map +1 -1
  305. package/dist/trusted-process/sandbox-integration.d.ts +12 -0
  306. package/dist/trusted-process/sandbox-integration.js +26 -0
  307. package/dist/trusted-process/sandbox-integration.js.map +1 -1
  308. package/dist/trusted-process/tool-call-coordinator.d.ts +269 -0
  309. package/dist/trusted-process/tool-call-coordinator.js +508 -0
  310. package/dist/trusted-process/tool-call-coordinator.js.map +1 -0
  311. package/dist/trusted-process/tool-call-pipeline.d.ts +205 -0
  312. package/dist/trusted-process/tool-call-pipeline.js +798 -0
  313. package/dist/trusted-process/tool-call-pipeline.js.map +1 -0
  314. package/dist/trusted-process/tool-description-hints.d.ts +1 -1
  315. package/dist/types/argument-roles.d.ts +1 -1
  316. package/dist/types/argument-roles.js +14 -1
  317. package/dist/types/argument-roles.js.map +1 -1
  318. package/dist/types/audit.d.ts +9 -0
  319. package/dist/{session → types}/errors.d.ts +8 -2
  320. package/dist/{session → types}/errors.js +8 -2
  321. package/dist/types/errors.js.map +1 -0
  322. package/dist/types/reserved-servers.d.ts +11 -0
  323. package/dist/types/reserved-servers.js +12 -0
  324. package/dist/types/reserved-servers.js.map +1 -0
  325. package/dist/types/server-listing.d.ts +14 -0
  326. package/dist/types/server-listing.js +2 -0
  327. package/dist/types/server-listing.js.map +1 -0
  328. package/dist/types/slug.d.ts +2 -0
  329. package/dist/types/slug.js +2 -0
  330. package/dist/types/slug.js.map +1 -1
  331. package/dist/types/url-normalize.d.ts +16 -0
  332. package/dist/types/url-normalize.js +33 -0
  333. package/dist/types/url-normalize.js.map +1 -0
  334. package/dist/utils/error-message.d.ts +8 -0
  335. package/dist/utils/error-message.js +11 -0
  336. package/dist/utils/error-message.js.map +1 -0
  337. package/dist/utils/exec-error.d.ts +19 -0
  338. package/dist/utils/exec-error.js +16 -0
  339. package/dist/utils/exec-error.js.map +1 -0
  340. package/dist/utils/is-plain-object.d.ts +7 -0
  341. package/dist/utils/is-plain-object.js +12 -0
  342. package/dist/utils/is-plain-object.js.map +1 -0
  343. package/dist/utils/preflight-checks.d.ts +16 -0
  344. package/dist/utils/preflight-checks.js +178 -0
  345. package/dist/utils/preflight-checks.js.map +1 -0
  346. package/dist/web-ui/__tests__/json-rpc-dispatch.test.d.ts +7 -0
  347. package/dist/web-ui/__tests__/json-rpc-dispatch.test.js +725 -0
  348. package/dist/web-ui/__tests__/json-rpc-dispatch.test.js.map +1 -0
  349. package/dist/web-ui/dispatch/escalation-dispatch.d.ts +7 -0
  350. package/dist/web-ui/dispatch/escalation-dispatch.js +52 -0
  351. package/dist/web-ui/dispatch/escalation-dispatch.js.map +1 -0
  352. package/dist/web-ui/dispatch/job-dispatch.d.ts +8 -0
  353. package/dist/web-ui/dispatch/job-dispatch.js +83 -0
  354. package/dist/web-ui/dispatch/job-dispatch.js.map +1 -0
  355. package/dist/web-ui/dispatch/persona-dispatch.d.ts +6 -0
  356. package/dist/web-ui/dispatch/persona-dispatch.js +116 -0
  357. package/dist/web-ui/dispatch/persona-dispatch.js.map +1 -0
  358. package/dist/web-ui/dispatch/session-dispatch.d.ts +9 -0
  359. package/dist/web-ui/dispatch/session-dispatch.js +201 -0
  360. package/dist/web-ui/dispatch/session-dispatch.js.map +1 -0
  361. package/dist/web-ui/dispatch/token-stream-dispatch.d.ts +15 -0
  362. package/dist/web-ui/dispatch/token-stream-dispatch.js +55 -0
  363. package/dist/web-ui/dispatch/token-stream-dispatch.js.map +1 -0
  364. package/dist/web-ui/dispatch/types.d.ts +31 -0
  365. package/dist/web-ui/dispatch/types.js +68 -0
  366. package/dist/web-ui/dispatch/types.js.map +1 -0
  367. package/dist/web-ui/dispatch/workflow-dispatch.d.ts +103 -0
  368. package/dist/web-ui/dispatch/workflow-dispatch.js +925 -0
  369. package/dist/web-ui/dispatch/workflow-dispatch.js.map +1 -0
  370. package/dist/web-ui/json-rpc-dispatch.d.ts +12 -0
  371. package/dist/web-ui/json-rpc-dispatch.js +34 -0
  372. package/dist/web-ui/json-rpc-dispatch.js.map +1 -0
  373. package/dist/web-ui/state-graph.d.ts +13 -0
  374. package/dist/web-ui/state-graph.js +82 -0
  375. package/dist/web-ui/state-graph.js.map +1 -0
  376. package/dist/web-ui/token-stream-bridge.d.ts +76 -0
  377. package/dist/web-ui/token-stream-bridge.js +265 -0
  378. package/dist/web-ui/token-stream-bridge.js.map +1 -0
  379. package/dist/web-ui/web-event-bus.d.ts +152 -0
  380. package/dist/web-ui/web-event-bus.js +19 -0
  381. package/dist/web-ui/web-event-bus.js.map +1 -0
  382. package/dist/web-ui/web-session-transport.d.ts +31 -0
  383. package/dist/web-ui/web-session-transport.js +109 -0
  384. package/dist/web-ui/web-session-transport.js.map +1 -0
  385. package/dist/web-ui/web-ui-server.d.ts +76 -0
  386. package/dist/web-ui/web-ui-server.js +461 -0
  387. package/dist/web-ui/web-ui-server.js.map +1 -0
  388. package/dist/web-ui/web-ui-types.d.ts +290 -0
  389. package/dist/web-ui/web-ui-types.js +32 -0
  390. package/dist/web-ui/web-ui-types.js.map +1 -0
  391. package/dist/web-ui/ws-utils.d.ts +5 -0
  392. package/dist/web-ui/ws-utils.js +12 -0
  393. package/dist/web-ui/ws-utils.js.map +1 -0
  394. package/dist/web-ui-static/assets/index-BFO5z1js.js +76 -0
  395. package/dist/web-ui-static/assets/index-CCUwrkIL.css +1 -0
  396. package/dist/web-ui-static/assets/orbitron-latin-700-normal-4jsRXGGJ.woff2 +0 -0
  397. package/dist/web-ui-static/assets/orbitron-latin-700-normal-DmYOh-W9.woff +0 -0
  398. package/dist/web-ui-static/index.html +14 -0
  399. package/dist/workflow/artifacts.d.ts +59 -0
  400. package/dist/workflow/artifacts.js +188 -0
  401. package/dist/workflow/artifacts.js.map +1 -0
  402. package/dist/workflow/checkpoint-selection.d.ts +34 -0
  403. package/dist/workflow/checkpoint-selection.js +48 -0
  404. package/dist/workflow/checkpoint-selection.js.map +1 -0
  405. package/dist/workflow/checkpoint.d.ts +35 -0
  406. package/dist/workflow/checkpoint.js +84 -0
  407. package/dist/workflow/checkpoint.js.map +1 -0
  408. package/dist/workflow/cli-support.d.ts +92 -0
  409. package/dist/workflow/cli-support.js +423 -0
  410. package/dist/workflow/cli-support.js.map +1 -0
  411. package/dist/workflow/definition-loader.d.ts +32 -0
  412. package/dist/workflow/definition-loader.js +56 -0
  413. package/dist/workflow/definition-loader.js.map +1 -0
  414. package/dist/workflow/discovery.d.ts +78 -0
  415. package/dist/workflow/discovery.js +203 -0
  416. package/dist/workflow/discovery.js.map +1 -0
  417. package/dist/workflow/errors.d.ts +66 -0
  418. package/dist/workflow/errors.js +49 -0
  419. package/dist/workflow/errors.js.map +1 -0
  420. package/dist/workflow/guards.d.ts +8 -0
  421. package/dist/workflow/guards.js +38 -0
  422. package/dist/workflow/guards.js.map +1 -0
  423. package/dist/workflow/lint-integration.d.ts +64 -0
  424. package/dist/workflow/lint-integration.js +56 -0
  425. package/dist/workflow/lint-integration.js.map +1 -0
  426. package/dist/workflow/lint.d.ts +66 -0
  427. package/dist/workflow/lint.js +410 -0
  428. package/dist/workflow/lint.js.map +1 -0
  429. package/dist/workflow/machine-builder.d.ts +90 -0
  430. package/dist/workflow/machine-builder.js +485 -0
  431. package/dist/workflow/machine-builder.js.map +1 -0
  432. package/dist/workflow/message-log.d.ts +85 -0
  433. package/dist/workflow/message-log.js +40 -0
  434. package/dist/workflow/message-log.js.map +1 -0
  435. package/dist/workflow/orchestrator.d.ts +450 -0
  436. package/dist/workflow/orchestrator.js +1941 -0
  437. package/dist/workflow/orchestrator.js.map +1 -0
  438. package/dist/workflow/prompt-builder.d.ts +39 -0
  439. package/dist/workflow/prompt-builder.js +242 -0
  440. package/dist/workflow/prompt-builder.js.map +1 -0
  441. package/dist/workflow/run-state-command.d.ts +9 -0
  442. package/dist/workflow/run-state-command.js +414 -0
  443. package/dist/workflow/run-state-command.js.map +1 -0
  444. package/dist/workflow/run-state-debug-capture.d.ts +40 -0
  445. package/dist/workflow/run-state-debug-capture.js +101 -0
  446. package/dist/workflow/run-state-debug-capture.js.map +1 -0
  447. package/dist/workflow/status-parser.d.ts +68 -0
  448. package/dist/workflow/status-parser.js +259 -0
  449. package/dist/workflow/status-parser.js.map +1 -0
  450. package/dist/workflow/types.d.ts +498 -0
  451. package/dist/workflow/types.js +83 -0
  452. package/dist/workflow/types.js.map +1 -0
  453. package/dist/workflow/validate.d.ts +58 -0
  454. package/dist/workflow/validate.js +499 -0
  455. package/dist/workflow/validate.js.map +1 -0
  456. package/dist/workflow/workflow-command.d.ts +26 -0
  457. package/dist/workflow/workflow-command.js +648 -0
  458. package/dist/workflow/workflow-command.js.map +1 -0
  459. package/dist/workflow/workflow-discovery.d.ts +25 -0
  460. package/dist/workflow/workflow-discovery.js +100 -0
  461. package/dist/workflow/workflow-discovery.js.map +1 -0
  462. package/dist/workflow/workflow-manager.d.ts +122 -0
  463. package/dist/workflow/workflow-manager.js +308 -0
  464. package/dist/workflow/workflow-manager.js.map +1 -0
  465. package/dist/workflow/workflows/design-and-code/workflow.yaml +169 -0
  466. package/dist/workflow/workflows/test-email-summary/skills/email-formatting/SKILL.md +55 -0
  467. package/dist/workflow/workflows/test-email-summary/skills/gmail-query-syntax/SKILL.md +63 -0
  468. package/dist/workflow/workflows/test-email-summary/skills/json-schema-emails/SKILL.md +41 -0
  469. package/dist/workflow/workflows/test-email-summary/skills/json-schema-emails/schema.json +34 -0
  470. package/dist/workflow/workflows/test-email-summary/skills/summary-style-guide/SKILL.md +51 -0
  471. package/dist/workflow/workflows/test-email-summary/workflow.yaml +89 -0
  472. package/dist/workflow/workflows/vuln-discovery/skills/harness-design-fuzzing/SKILL.md +201 -0
  473. package/dist/workflow/workflows/vuln-discovery/skills/memory-safety-c-cpp/SKILL.md +166 -0
  474. package/dist/workflow/workflows/vuln-discovery/skills/vulnerability-triage/SKILL.md +185 -0
  475. package/dist/workflow/workflows/vuln-discovery/workflow.yaml +920 -0
  476. package/dist/workflow/worktree.d.ts +43 -0
  477. package/dist/workflow/worktree.js +106 -0
  478. package/dist/workflow/worktree.js.map +1 -0
  479. package/docker/Dockerfile.base +12 -1
  480. package/docker/Dockerfile.base.arm64 +17 -1
  481. package/docker/entrypoint-claude-code.sh +46 -0
  482. package/docker/entrypoint-goose.sh +25 -0
  483. package/package.json +22 -8
  484. package/packages/web-ui/README.md +113 -0
  485. package/packages/web-ui/docs/workflow-state-machine.png +0 -0
  486. package/src/config/generated/compiled-policy.json +528 -161
  487. package/src/config/generated/test-scenarios.json +4810 -170
  488. package/src/config/generated/tool-annotations.json +34 -47
  489. package/src/config/mcp-servers.json +2 -2
  490. package/src/workflow/workflows/design-and-code/workflow.yaml +169 -0
  491. package/src/workflow/workflows/test-email-summary/skills/email-formatting/SKILL.md +55 -0
  492. package/src/workflow/workflows/test-email-summary/skills/gmail-query-syntax/SKILL.md +63 -0
  493. package/src/workflow/workflows/test-email-summary/skills/json-schema-emails/SKILL.md +41 -0
  494. package/src/workflow/workflows/test-email-summary/skills/json-schema-emails/schema.json +34 -0
  495. package/src/workflow/workflows/test-email-summary/skills/summary-style-guide/SKILL.md +51 -0
  496. package/src/workflow/workflows/test-email-summary/workflow.yaml +89 -0
  497. package/src/workflow/workflows/vuln-discovery/skills/harness-design-fuzzing/SKILL.md +201 -0
  498. package/src/workflow/workflows/vuln-discovery/skills/memory-safety-c-cpp/SKILL.md +166 -0
  499. package/src/workflow/workflows/vuln-discovery/skills/vulnerability-triage/SKILL.md +185 -0
  500. package/src/workflow/workflows/vuln-discovery/workflow.yaml +920 -0
  501. package/dist/pipeline/llm-logger.js.map +0 -1
  502. package/dist/session/errors.js.map +0 -1
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Shared CLI helpers for the workflow system.
3
+ *
4
+ * Extracted from examples/workflow-real-spike.ts so both the CLI
5
+ * command and the spike script can reuse the same logic.
6
+ *
7
+ * Output convention: all functions use process.stdout.write() and
8
+ * process.stderr.write() — never console.log/warn/error. After
9
+ * logger.setup() hijacks console.*, those writes are redirected
10
+ * to the session log file and never reach the terminal.
11
+ */
12
+ import { createInterface } from 'node:readline/promises';
13
+ import type { Session, SessionOptions } from '../session/types.js';
14
+ import { type WorkflowId, type WorkflowCheckpoint, type HumanGateRequest, type HumanGateEventType } from './types.js';
15
+ import type { WorkflowOrchestrator, WorkflowLifecycleEvent, WorkflowTabHandle } from './orchestrator.js';
16
+ import { FileCheckpointStore, isCheckpointResumable } from './checkpoint.js';
17
+ export { isCheckpointResumable };
18
+ export declare const RESET = "\u001B[0m";
19
+ export declare const BOLD = "\u001B[1m";
20
+ export declare const DIM = "\u001B[2m";
21
+ export declare const GREEN = "\u001B[32m";
22
+ export declare const YELLOW = "\u001B[33m";
23
+ export declare const BLUE = "\u001B[34m";
24
+ export declare const MAGENTA = "\u001B[35m";
25
+ export declare const CYAN = "\u001B[36m";
26
+ export declare const RED = "\u001B[31m";
27
+ export declare const WHITE = "\u001B[37m";
28
+ export declare const BG_YELLOW = "\u001B[43m";
29
+ export declare const BLACK = "\u001B[30m";
30
+ export declare function writeStdout(msg: string): void;
31
+ export declare function writeStderr(msg: string): void;
32
+ /**
33
+ * Creates a session factory that loads config once and routes model
34
+ * selection through:
35
+ *
36
+ * `--model` CLI flag > per-call `agentModelOverride` > user config
37
+ *
38
+ * Resolution happens per call so per-state `SessionOptions.agentModelOverride`
39
+ * values are honored on each invocation.
40
+ *
41
+ * Persona `"global"` (GLOBAL_PERSONA) is stripped to undefined (uses global
42
+ * policy); any other value passes through for per-persona policy/memory.
43
+ */
44
+ export declare function createWorkflowSessionFactory(modelOverride?: string): (opts: SessionOptions) => Promise<Session>;
45
+ /** Creates a WorkflowTabHandle that writes to stdout. */
46
+ export declare function createConsoleTab(label: string): WorkflowTabHandle;
47
+ export interface GateHandler {
48
+ raiseGate: (gate: HumanGateRequest) => void;
49
+ dismissGate: (workflowId: string, gateId: string) => void;
50
+ waitForGate: () => Promise<HumanGateRequest>;
51
+ }
52
+ /** Creates a gate promise queue for interactive gate handling. */
53
+ export declare function createGateHandler(): GateHandler;
54
+ /** Prompts the user to resolve a human gate via readline. */
55
+ export declare function promptGateInteractive(gate: HumanGateRequest, rl: ReturnType<typeof createInterface>): Promise<{
56
+ type: HumanGateEventType;
57
+ prompt?: string;
58
+ }>;
59
+ /** Prints a workflow lifecycle event to stdout/stderr. */
60
+ export declare function printLifecycleEvent(event: WorkflowLifecycleEvent): void;
61
+ /** Prints end-of-workflow summary with phase, artifacts, and artifact dir. */
62
+ export declare function printSummary(orchestrator: WorkflowOrchestrator, workflowId: WorkflowId, artifactDir: string): void;
63
+ /** Prints checkpoint details before resume. */
64
+ export declare function printResumeInfo(baseDir: string, workflowId: WorkflowId, checkpoint: WorkflowCheckpoint): void;
65
+ /**
66
+ * Picks the most-recent resumable workflow from a checkpoint store.
67
+ *
68
+ * Delegates enumeration + filtering + sorting to
69
+ * {@link findResumableCheckpoints} (single source of truth shared with the
70
+ * daemon). Adds the CLI-specific banner that lists every candidate when
71
+ * more than one is present.
72
+ *
73
+ * Exits with code 1 if no resumable workflows are found.
74
+ */
75
+ export declare function selectResumableWorkflow(checkpointStore: FileCheckpointStore, baseDir: string): {
76
+ workflowId: WorkflowId;
77
+ checkpoint: WorkflowCheckpoint;
78
+ };
79
+ /**
80
+ * Synthesizes a checkpoint for a workflow that ran before checkpointing.
81
+ * Discovers the workflow ID from the directory structure, reads the task
82
+ * from the task artifact, builds minimal context, and writes a checkpoint.
83
+ */
84
+ export declare function synthesizeCheckpoint(baseDir: string, stateName: string, definitionPath: string, checkpointStore: FileCheckpointStore): {
85
+ workflowId: WorkflowId;
86
+ checkpoint: WorkflowCheckpoint;
87
+ };
88
+ /**
89
+ * Polls orchestrator status and dispatches gate prompts.
90
+ * Exits when the workflow reaches a terminal phase or the signal is aborted.
91
+ */
92
+ export declare function runEventLoop(orchestrator: WorkflowOrchestrator, workflowId: WorkflowId, rl: ReturnType<typeof createInterface>, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,423 @@
1
+ /**
2
+ * Shared CLI helpers for the workflow system.
3
+ *
4
+ * Extracted from examples/workflow-real-spike.ts so both the CLI
5
+ * command and the spike script can reuse the same logic.
6
+ *
7
+ * Output convention: all functions use process.stdout.write() and
8
+ * process.stderr.write() — never console.log/warn/error. After
9
+ * logger.setup() hijacks console.*, those writes are redirected
10
+ * to the session log file and never reach the terminal.
11
+ */
12
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
13
+ import { resolve } from 'node:path';
14
+ import { loadConfig } from '../config/index.js';
15
+ import { createSession } from '../session/index.js';
16
+ import { GLOBAL_PERSONA, } from './types.js';
17
+ import { isCheckpointResumable } from './checkpoint.js';
18
+ import { findResumableCheckpoints } from './checkpoint-selection.js';
19
+ // Re-export for backward compatibility — the canonical location is now
20
+ // `./checkpoint.js`, but external callers (e.g. `workflow-manager.ts`,
21
+ // the test suite) historically imported it from here.
22
+ export { isCheckpointResumable };
23
+ // ---------------------------------------------------------------------------
24
+ // ANSI colors
25
+ // ---------------------------------------------------------------------------
26
+ export const RESET = '\x1b[0m';
27
+ export const BOLD = '\x1b[1m';
28
+ export const DIM = '\x1b[2m';
29
+ export const GREEN = '\x1b[32m';
30
+ export const YELLOW = '\x1b[33m';
31
+ export const BLUE = '\x1b[34m';
32
+ export const MAGENTA = '\x1b[35m';
33
+ export const CYAN = '\x1b[36m';
34
+ export const RED = '\x1b[31m';
35
+ export const WHITE = '\x1b[37m';
36
+ export const BG_YELLOW = '\x1b[43m';
37
+ export const BLACK = '\x1b[30m';
38
+ // ---------------------------------------------------------------------------
39
+ // Safe output primitives
40
+ // ---------------------------------------------------------------------------
41
+ export function writeStdout(msg) {
42
+ process.stdout.write(`${msg}\n`);
43
+ }
44
+ export function writeStderr(msg) {
45
+ process.stderr.write(`${msg}\n`);
46
+ }
47
+ // ---------------------------------------------------------------------------
48
+ // Session factory
49
+ // ---------------------------------------------------------------------------
50
+ /**
51
+ * Creates a session factory that loads config once and routes model
52
+ * selection through:
53
+ *
54
+ * `--model` CLI flag > per-call `agentModelOverride` > user config
55
+ *
56
+ * Resolution happens per call so per-state `SessionOptions.agentModelOverride`
57
+ * values are honored on each invocation.
58
+ *
59
+ * Persona `"global"` (GLOBAL_PERSONA) is stripped to undefined (uses global
60
+ * policy); any other value passes through for per-persona policy/memory.
61
+ */
62
+ export function createWorkflowSessionFactory(modelOverride) {
63
+ const baseConfig = loadConfig();
64
+ return async (opts) => {
65
+ const persona = opts.persona;
66
+ const personaStripped = persona === GLOBAL_PERSONA ? undefined : persona;
67
+ // Only rebuild the config when a model override is actually in play.
68
+ // The common case (no per-state and no --model) passes the base config
69
+ // through unchanged.
70
+ const override = modelOverride ?? opts.agentModelOverride;
71
+ const effectiveOpts = override
72
+ ? {
73
+ ...opts,
74
+ config: {
75
+ ...baseConfig,
76
+ agentModelId: override,
77
+ userConfig: { ...baseConfig.userConfig, agentModelId: override },
78
+ },
79
+ agentModelOverride: override,
80
+ persona: personaStripped,
81
+ }
82
+ : { ...opts, config: baseConfig, persona: personaStripped };
83
+ try {
84
+ // Narrow the options union for the typed overloads: the orchestrator
85
+ // supplies `agentConversationId` for every Docker invocation (see
86
+ // `executeAgentState` in orchestrator.ts), so the Docker branch is
87
+ // safe. Builtin mode ignores the field whether set or not.
88
+ if (effectiveOpts.mode?.kind === 'docker') {
89
+ if (!effectiveOpts.agentConversationId) {
90
+ throw new Error('workflow orchestrator must supply agentConversationId for docker sessions');
91
+ }
92
+ return await createSession({
93
+ ...effectiveOpts,
94
+ mode: effectiveOpts.mode,
95
+ agentConversationId: effectiveOpts.agentConversationId,
96
+ });
97
+ }
98
+ return await createSession({ ...effectiveOpts, mode: effectiveOpts.mode });
99
+ }
100
+ catch (err) {
101
+ const msg = err instanceof Error ? err.message : String(err);
102
+ writeStderr(`${RED}${BOLD}[session-factory] Failed to create session for "${persona ?? 'unknown'}":${RESET}`);
103
+ writeStderr(`${RED} ${msg}${RESET}`);
104
+ throw err;
105
+ }
106
+ };
107
+ }
108
+ // ---------------------------------------------------------------------------
109
+ // Console tab handle
110
+ // ---------------------------------------------------------------------------
111
+ /** Creates a WorkflowTabHandle that writes to stdout. */
112
+ export function createConsoleTab(label) {
113
+ return {
114
+ write(text) {
115
+ writeStdout(`${DIM}[${label}]${RESET} ${text}`);
116
+ },
117
+ setLabel(newLabel) {
118
+ writeStdout(`${DIM}[tab] label: ${newLabel}${RESET}`);
119
+ },
120
+ close() {
121
+ writeStdout(`${DIM}[tab] ${label} closed${RESET}`);
122
+ },
123
+ };
124
+ }
125
+ /** Creates a gate promise queue for interactive gate handling. */
126
+ export function createGateHandler() {
127
+ const gatePromises = [];
128
+ let pendingGate;
129
+ function raiseGate(gate) {
130
+ pendingGate = gate;
131
+ const waiter = gatePromises.shift();
132
+ if (waiter)
133
+ waiter.resolve(gate);
134
+ }
135
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
136
+ function dismissGate(_workflowId, _gateId) {
137
+ pendingGate = undefined;
138
+ }
139
+ async function waitForGate() {
140
+ if (pendingGate)
141
+ return pendingGate;
142
+ return new Promise((resolve) => {
143
+ gatePromises.push({ resolve });
144
+ });
145
+ }
146
+ return { raiseGate, dismissGate, waitForGate };
147
+ }
148
+ // ---------------------------------------------------------------------------
149
+ // Interactive gate prompt
150
+ // ---------------------------------------------------------------------------
151
+ /** Prompts the user to resolve a human gate via readline. */
152
+ export async function promptGateInteractive(gate, rl) {
153
+ const bar = '='.repeat(50);
154
+ const presented = [...gate.presentedArtifacts.keys()].join(', ') || 'none';
155
+ writeStdout('');
156
+ writeStdout(`${BOLD}${YELLOW}${bar}${RESET}`);
157
+ writeStdout(`${BOLD}${BG_YELLOW}${BLACK} HUMAN GATE: ${gate.stateName} ${RESET}`);
158
+ if (gate.summary.includes('(error:')) {
159
+ const errorMatch = /\(error: (.+)\)$/.exec(gate.summary);
160
+ if (errorMatch) {
161
+ writeStderr(`${RED}${BOLD}ERROR: ${errorMatch[1]}${RESET}`);
162
+ }
163
+ }
164
+ writeStdout(`${DIM}${gate.summary}${RESET}`);
165
+ writeStdout(`${DIM}Presented artifacts: ${presented}${RESET}`);
166
+ writeStdout('');
167
+ writeStdout(`${WHITE}Options:${RESET}`);
168
+ const eventMap = new Map();
169
+ for (const evt of gate.acceptedEvents) {
170
+ switch (evt) {
171
+ case 'APPROVE':
172
+ writeStdout(` ${GREEN}[a]${RESET} APPROVE`);
173
+ eventMap.set('a', 'APPROVE');
174
+ break;
175
+ case 'FORCE_REVISION':
176
+ writeStdout(` ${YELLOW}[f]${RESET} FORCE_REVISION`);
177
+ eventMap.set('f', 'FORCE_REVISION');
178
+ break;
179
+ case 'REPLAN':
180
+ writeStdout(` ${MAGENTA}[r]${RESET} REPLAN`);
181
+ eventMap.set('r', 'REPLAN');
182
+ break;
183
+ case 'ABORT':
184
+ writeStdout(` ${RED}[x]${RESET} ABORT`);
185
+ eventMap.set('x', 'ABORT');
186
+ break;
187
+ }
188
+ }
189
+ writeStdout('');
190
+ const validKeys = [...eventMap.keys()].join('/');
191
+ for (;;) {
192
+ const answer = await rl.question(`${BOLD}Your choice (${validKeys}): ${RESET}`);
193
+ const key = answer.trim().toLowerCase();
194
+ const eventType = eventMap.get(key);
195
+ if (!eventType) {
196
+ writeStdout(`${RED}Invalid choice. Please enter one of: ${validKeys}${RESET}`);
197
+ continue;
198
+ }
199
+ if (eventType === 'FORCE_REVISION' || eventType === 'REPLAN') {
200
+ const feedback = await promptRequiredFeedback(rl, eventType);
201
+ return { type: eventType, prompt: feedback };
202
+ }
203
+ return { type: eventType };
204
+ }
205
+ }
206
+ /**
207
+ * FORCE_REVISION and REPLAN route the workflow back to an earlier state
208
+ * and the next agent's prompt references the feedback directly, so empty
209
+ * feedback would produce an incoherent re-entry prompt. When stdin is
210
+ * closed (piped invocation, EOF) we abort instead of spinning.
211
+ */
212
+ async function promptRequiredFeedback(rl, eventType) {
213
+ for (;;) {
214
+ if (process.stdin.readableEnded) {
215
+ throw new Error(`Feedback is required for ${eventType} but stdin was closed before a response was provided.`);
216
+ }
217
+ const answer = await rl.question(`${CYAN}Feedback: ${RESET}`);
218
+ const trimmed = answer.trim();
219
+ if (trimmed.length > 0) {
220
+ return trimmed;
221
+ }
222
+ writeStdout(`${RED}Feedback is required for ${eventType}. Please enter a non-empty response.${RESET}`);
223
+ }
224
+ }
225
+ // ---------------------------------------------------------------------------
226
+ // Lifecycle event printer
227
+ // ---------------------------------------------------------------------------
228
+ /** Prints a workflow lifecycle event to stdout/stderr. */
229
+ export function printLifecycleEvent(event) {
230
+ switch (event.kind) {
231
+ case 'state_entered':
232
+ writeStdout(`${BLUE}>>>${RESET} ${BOLD}State:${RESET} ${CYAN}${event.state}${RESET}`);
233
+ break;
234
+ case 'gate_raised':
235
+ writeStdout(`${YELLOW}>>>${RESET} ${BOLD}Gate raised:${RESET} ${event.gate.stateName}`);
236
+ break;
237
+ case 'gate_dismissed':
238
+ writeStdout(`${GREEN}[gate dismissed]${RESET} ${event.gateId}`);
239
+ break;
240
+ case 'completed':
241
+ writeStdout(`${GREEN}${BOLD}Workflow completed!${RESET}`);
242
+ break;
243
+ case 'failed': {
244
+ const errorBar = '-'.repeat(50);
245
+ writeStderr(`${RED}${errorBar}${RESET}`);
246
+ writeStderr(`${RED}${BOLD}WORKFLOW ERROR:${RESET} ${event.error}`);
247
+ writeStderr(`${RED}${errorBar}${RESET}`);
248
+ break;
249
+ }
250
+ }
251
+ }
252
+ // ---------------------------------------------------------------------------
253
+ // Summary printer
254
+ // ---------------------------------------------------------------------------
255
+ /** Prints end-of-workflow summary with phase, artifacts, and artifact dir. */
256
+ export function printSummary(orchestrator, workflowId, artifactDir) {
257
+ const status = orchestrator.getStatus(workflowId);
258
+ const bar = '='.repeat(50);
259
+ writeStdout('');
260
+ writeStdout(`${BOLD}${bar}${RESET}`);
261
+ writeStdout(`${BOLD}WORKFLOW SUMMARY${RESET}`);
262
+ writeStdout(bar);
263
+ if (!status) {
264
+ writeStdout(`${RED}No status available${RESET}`);
265
+ return;
266
+ }
267
+ writeStdout(`Phase: ${BOLD}${status.phase}${RESET}`);
268
+ if (status.phase === 'completed') {
269
+ writeStdout(`Final artifacts: ${Object.keys(status.result.finalArtifacts).join(', ') || 'none'}`);
270
+ }
271
+ else if (status.phase === 'aborted') {
272
+ writeStdout(`Reason: ${status.reason}`);
273
+ }
274
+ else if (status.phase === 'failed') {
275
+ writeStdout(`Error: ${status.error}`);
276
+ }
277
+ writeStdout(`Artifact directory: ${artifactDir}`);
278
+ if (existsSync(artifactDir)) {
279
+ const entries = readdirSync(artifactDir);
280
+ writeStdout(`Contents: ${entries.join(', ') || '(empty)'}`);
281
+ }
282
+ writeStdout(bar);
283
+ }
284
+ // ---------------------------------------------------------------------------
285
+ // Resume helpers
286
+ // ---------------------------------------------------------------------------
287
+ /** Prints checkpoint details before resume. */
288
+ export function printResumeInfo(baseDir, workflowId, checkpoint) {
289
+ const workspacePath = checkpoint.workspacePath ?? resolve(baseDir, workflowId, 'workspace');
290
+ const artifactDir = resolve(workspacePath, '.workflow');
291
+ const artifacts = existsSync(artifactDir) ? readdirSync(artifactDir).join(', ') : 'none';
292
+ const errorInfo = checkpoint.context.lastError ?? 'none';
293
+ writeStdout(`${BOLD}${CYAN}Resuming workflow from:${RESET} ${baseDir}`);
294
+ writeStdout(`${DIM}Workflow ID: ${workflowId}${RESET}`);
295
+ writeStdout(`${DIM}Last state: ${String(checkpoint.machineState)}${RESET}`);
296
+ writeStdout(`${DIM}Error: ${errorInfo}${RESET}`);
297
+ writeStdout(`${DIM}Checkpointed at: ${checkpoint.timestamp}${RESET}`);
298
+ writeStdout(`${DIM}Artifacts present: ${artifacts}${RESET}`);
299
+ writeStdout('');
300
+ }
301
+ /**
302
+ * Picks the most-recent resumable workflow from a checkpoint store.
303
+ *
304
+ * Delegates enumeration + filtering + sorting to
305
+ * {@link findResumableCheckpoints} (single source of truth shared with the
306
+ * daemon). Adds the CLI-specific banner that lists every candidate when
307
+ * more than one is present.
308
+ *
309
+ * Exits with code 1 if no resumable workflows are found.
310
+ */
311
+ export function selectResumableWorkflow(checkpointStore, baseDir) {
312
+ const candidates = findResumableCheckpoints(baseDir, checkpointStore);
313
+ if (candidates.length === 0) {
314
+ writeStderr(`${RED}No resumable workflows found in this directory.${RESET}`);
315
+ writeStderr(`${DIM}Expected checkpoint files at: <baseDir>/<workflowId>/checkpoint.json${RESET}`);
316
+ process.exit(1);
317
+ }
318
+ if (candidates.length === 1) {
319
+ return { workflowId: candidates[0].workflowId, checkpoint: candidates[0].checkpoint };
320
+ }
321
+ writeStdout(`${YELLOW}Found ${candidates.length} resumable workflows. Using most recent:${RESET}`);
322
+ for (const { workflowId, checkpoint } of candidates) {
323
+ const marker = workflowId === candidates[0].workflowId ? `${GREEN}>>` : `${DIM} `;
324
+ writeStdout(`${marker} ${workflowId} — state: ${String(checkpoint.machineState)}, saved: ${checkpoint.timestamp}${RESET}`);
325
+ }
326
+ writeStdout('');
327
+ return { workflowId: candidates[0].workflowId, checkpoint: candidates[0].checkpoint };
328
+ }
329
+ /**
330
+ * Synthesizes a checkpoint for a workflow that ran before checkpointing.
331
+ * Discovers the workflow ID from the directory structure, reads the task
332
+ * from the task artifact, builds minimal context, and writes a checkpoint.
333
+ */
334
+ export function synthesizeCheckpoint(baseDir, stateName, definitionPath, checkpointStore) {
335
+ const entries = readdirSync(baseDir).filter((e) => {
336
+ const full = resolve(baseDir, e);
337
+ return existsSync(resolve(full, 'workspace', '.workflow')) || existsSync(resolve(full, 'artifacts'));
338
+ });
339
+ if (entries.length === 0) {
340
+ writeStderr(`${RED}No workflow directory found in ${baseDir}${RESET}`);
341
+ process.exit(1);
342
+ }
343
+ const workflowId = entries[0];
344
+ const workspacePath = resolve(baseDir, workflowId, 'workspace');
345
+ const artifactDir = existsSync(resolve(workspacePath, '.workflow'))
346
+ ? resolve(workspacePath, '.workflow')
347
+ : resolve(baseDir, workflowId, 'artifacts');
348
+ let taskDescription = 'Unknown task (synthesized checkpoint)';
349
+ const taskDir = resolve(artifactDir, 'task');
350
+ if (existsSync(taskDir)) {
351
+ const taskFiles = readdirSync(taskDir).filter((f) => f.endsWith('.md'));
352
+ if (taskFiles.length > 0) {
353
+ taskDescription = readFileSync(resolve(taskDir, taskFiles[0]), 'utf-8').trim();
354
+ }
355
+ }
356
+ const artifacts = {};
357
+ for (const name of readdirSync(artifactDir)) {
358
+ const full = resolve(artifactDir, name);
359
+ if (existsSync(full)) {
360
+ artifacts[name] = full;
361
+ }
362
+ }
363
+ const context = {
364
+ taskDescription,
365
+ artifacts,
366
+ round: 0,
367
+ maxRounds: 3,
368
+ previousOutputHashes: {},
369
+ previousTestCount: null,
370
+ humanPrompt: null,
371
+ reviewHistory: [],
372
+ parallelResults: {},
373
+ worktreeBranches: [],
374
+ totalTokens: 0,
375
+ lastError: null,
376
+ agentConversationsByState: {},
377
+ previousAgentOutput: null,
378
+ previousAgentNotes: null,
379
+ previousStateName: null,
380
+ visitCounts: {},
381
+ };
382
+ const checkpoint = {
383
+ machineState: stateName,
384
+ context,
385
+ timestamp: new Date().toISOString(),
386
+ transitionHistory: [],
387
+ definitionPath,
388
+ workspacePath,
389
+ };
390
+ checkpointStore.save(workflowId, checkpoint);
391
+ writeStdout(`${YELLOW}Synthesized checkpoint at state "${stateName}" for workflow ${workflowId}${RESET}`);
392
+ writeStdout(`${DIM}Artifacts found: ${Object.keys(artifacts).join(', ')}${RESET}`);
393
+ writeStdout(`${DIM}Task: ${taskDescription.slice(0, 80)}...${RESET}`);
394
+ writeStdout('');
395
+ return { workflowId, checkpoint };
396
+ }
397
+ // ---------------------------------------------------------------------------
398
+ // Event loop
399
+ // ---------------------------------------------------------------------------
400
+ /**
401
+ * Polls orchestrator status and dispatches gate prompts.
402
+ * Exits when the workflow reaches a terminal phase or the signal is aborted.
403
+ */
404
+ export async function runEventLoop(orchestrator, workflowId, rl, signal) {
405
+ for (;;) {
406
+ if (signal?.aborted)
407
+ break;
408
+ const status = orchestrator.getStatus(workflowId);
409
+ if (!status)
410
+ break;
411
+ if (status.phase === 'completed' || status.phase === 'failed' || status.phase === 'aborted')
412
+ break;
413
+ if (status.phase === 'waiting_human') {
414
+ const gate = status.gate;
415
+ const event = await promptGateInteractive(gate, rl);
416
+ orchestrator.resolveGate(workflowId, event);
417
+ await new Promise((r) => setTimeout(r, 100));
418
+ continue;
419
+ }
420
+ await new Promise((r) => setTimeout(r, 200));
421
+ }
422
+ }
423
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W,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YAC5C,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YAC7C,SAAS;QACX,CAAC;QAED,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Centralized loader for workflow definition files.
3
+ *
4
+ * Both the CLI (`workflow start` / `workflow resume` / `workflow lint`) and
5
+ * the daemon (`workflows.start` JSON-RPC and the past-run loader) need the
6
+ * same parse + validate pipeline. This module is the single source of truth.
7
+ *
8
+ * The function never throws: callers receive a discriminated result so they
9
+ * can map errors to their own surface (stderr + `process.exit(1)` for the
10
+ * CLI; `RpcError('INVALID_PARAMS')` for the daemon; `'corrupted'` for the
11
+ * past-run loader).
12
+ */
13
+ import type { WorkflowDefinition } from './types.js';
14
+ export type DefinitionLoadResult = {
15
+ ok: true;
16
+ definition: WorkflowDefinition;
17
+ } | {
18
+ ok: false;
19
+ kind: 'parse' | 'validate';
20
+ message: string;
21
+ issues?: readonly string[];
22
+ };
23
+ /**
24
+ * Reads, parses, and validates a workflow definition file.
25
+ *
26
+ * - `kind: 'parse'` covers any failure before structural validation
27
+ * (file read errors, YAML/JSON syntax errors, alias-bomb rejection).
28
+ * - `kind: 'validate'` covers `WorkflowValidationError` from `validateDefinition`
29
+ * and any other unexpected error during validation. The `issues` array is
30
+ * populated only for the `WorkflowValidationError` path.
31
+ */
32
+ export declare function loadDefinition(path: string): DefinitionLoadResult;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Centralized loader for workflow definition files.
3
+ *
4
+ * Both the CLI (`workflow start` / `workflow resume` / `workflow lint`) and
5
+ * the daemon (`workflows.start` JSON-RPC and the past-run loader) need the
6
+ * same parse + validate pipeline. This module is the single source of truth.
7
+ *
8
+ * The function never throws: callers receive a discriminated result so they
9
+ * can map errors to their own surface (stderr + `process.exit(1)` for the
10
+ * CLI; `RpcError('INVALID_PARAMS')` for the daemon; `'corrupted'` for the
11
+ * past-run loader).
12
+ */
13
+ import { parseDefinitionFile } from './discovery.js';
14
+ import { validateDefinition, WorkflowValidationError } from './validate.js';
15
+ /**
16
+ * Reads, parses, and validates a workflow definition file.
17
+ *
18
+ * - `kind: 'parse'` covers any failure before structural validation
19
+ * (file read errors, YAML/JSON syntax errors, alias-bomb rejection).
20
+ * - `kind: 'validate'` covers `WorkflowValidationError` from `validateDefinition`
21
+ * and any other unexpected error during validation. The `issues` array is
22
+ * populated only for the `WorkflowValidationError` path.
23
+ */
24
+ export function loadDefinition(path) {
25
+ let raw;
26
+ try {
27
+ raw = parseDefinitionFile(path);
28
+ }
29
+ catch (err) {
30
+ return {
31
+ ok: false,
32
+ kind: 'parse',
33
+ message: err instanceof Error ? err.message : String(err),
34
+ };
35
+ }
36
+ try {
37
+ const definition = validateDefinition(raw);
38
+ return { ok: true, definition };
39
+ }
40
+ catch (err) {
41
+ if (err instanceof WorkflowValidationError) {
42
+ return {
43
+ ok: false,
44
+ kind: 'validate',
45
+ message: `Workflow validation failed: ${err.issues.join('; ')}`,
46
+ issues: err.issues,
47
+ };
48
+ }
49
+ return {
50
+ ok: false,
51
+ kind: 'validate',
52
+ message: err instanceof Error ? err.message : String(err),
53
+ };
54
+ }
55
+ }
56
+ //# sourceMappingURL=definition-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition-loader.js","sourceRoot":"","sources":["../../src/workflow/definition-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAO5E;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,IA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