@evalops/maestro 0.10.8 → 0.10.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 (1001) hide show
  1. package/README.md +3 -1
  2. package/dist/agent/action-approval.d.ts +6 -0
  3. package/dist/agent/action-approval.d.ts.map +1 -1
  4. package/dist/agent/action-approval.js.map +1 -1
  5. package/dist/agent/agent.d.ts +13 -1
  6. package/dist/agent/agent.d.ts.map +1 -1
  7. package/dist/agent/agent.js +368 -1
  8. package/dist/agent/agent.js.map +1 -1
  9. package/dist/agent/auto-compaction.d.ts +4 -4
  10. package/dist/agent/auto-compaction.d.ts.map +1 -1
  11. package/dist/agent/auto-compaction.js.map +1 -1
  12. package/dist/agent/compaction-cleanup.d.ts +2 -0
  13. package/dist/agent/compaction-cleanup.d.ts.map +1 -1
  14. package/dist/agent/compaction-cleanup.js +17 -2
  15. package/dist/agent/compaction-cleanup.js.map +1 -1
  16. package/dist/agent/compaction.d.ts +3 -1
  17. package/dist/agent/compaction.d.ts.map +1 -1
  18. package/dist/agent/compaction.js +10 -2
  19. package/dist/agent/compaction.js.map +1 -1
  20. package/dist/agent/context-manager.d.ts +4 -0
  21. package/dist/agent/context-manager.d.ts.map +1 -1
  22. package/dist/agent/context-manager.js +8 -0
  23. package/dist/agent/context-manager.js.map +1 -1
  24. package/dist/agent/context-providers.d.ts +2 -0
  25. package/dist/agent/context-providers.d.ts.map +1 -1
  26. package/dist/agent/context-providers.js +3 -2
  27. package/dist/agent/context-providers.js.map +1 -1
  28. package/dist/agent/providers/google-gemini-cli.js +17 -5
  29. package/dist/agent/providers/google.js +174 -144
  30. package/dist/agent/providers/openai-codex-responses.d.ts +4 -0
  31. package/dist/agent/providers/openai-codex-responses.d.ts.map +1 -0
  32. package/dist/agent/providers/openai-codex-responses.js +637 -0
  33. package/dist/agent/providers/openai-codex-responses.js.map +1 -0
  34. package/dist/agent/providers/openai-codex-session.d.ts +18 -0
  35. package/dist/agent/providers/openai-codex-session.d.ts.map +1 -0
  36. package/dist/agent/providers/openai-codex-session.js +53 -0
  37. package/dist/agent/providers/openai-codex-session.js.map +1 -0
  38. package/dist/agent/providers/openai-responses-sdk.d.ts.map +1 -1
  39. package/dist/agent/providers/openai-responses-sdk.js +16 -6
  40. package/dist/agent/providers/openai-responses-sdk.js.map +1 -1
  41. package/dist/agent/providers/openai-shared.d.ts +12 -5
  42. package/dist/agent/providers/openai-shared.d.ts.map +1 -1
  43. package/dist/agent/providers/openai-shared.js +291 -2
  44. package/dist/agent/providers/openai-shared.js.map +1 -1
  45. package/dist/agent/providers/openai.d.ts +1 -1
  46. package/dist/agent/providers/openai.d.ts.map +1 -1
  47. package/dist/agent/providers/openai.js +48 -20
  48. package/dist/agent/providers/openai.js.map +1 -1
  49. package/dist/agent/providers/vertex.js +7 -0
  50. package/dist/agent/tracing.d.ts +16 -5
  51. package/dist/agent/tracing.d.ts.map +1 -1
  52. package/dist/agent/tracing.js +44 -2
  53. package/dist/agent/tracing.js.map +1 -1
  54. package/dist/agent/transport/create-provider-stream.d.ts.map +1 -1
  55. package/dist/agent/transport/create-provider-stream.js +9 -0
  56. package/dist/agent/transport/create-provider-stream.js.map +1 -1
  57. package/dist/agent/transport/tool-execution-bridge.d.ts +86 -0
  58. package/dist/agent/transport/tool-execution-bridge.d.ts.map +1 -0
  59. package/dist/agent/transport/tool-execution-bridge.js +665 -0
  60. package/dist/agent/transport/tool-execution-bridge.js.map +1 -0
  61. package/dist/agent/transport/tool-execution.d.ts +3 -0
  62. package/dist/agent/transport/tool-execution.d.ts.map +1 -1
  63. package/dist/agent/transport/tool-execution.js +16 -1
  64. package/dist/agent/transport/tool-execution.js.map +1 -1
  65. package/dist/agent/transport/tool-safety-pipeline.d.ts +7 -1
  66. package/dist/agent/transport/tool-safety-pipeline.d.ts.map +1 -1
  67. package/dist/agent/transport/tool-safety-pipeline.js +207 -40
  68. package/dist/agent/transport/tool-safety-pipeline.js.map +1 -1
  69. package/dist/agent/transport/tool-update-queue.d.ts +2 -0
  70. package/dist/agent/transport/tool-update-queue.d.ts.map +1 -1
  71. package/dist/agent/transport/tool-update-queue.js.map +1 -1
  72. package/dist/agent/transport.d.ts +3 -0
  73. package/dist/agent/transport.d.ts.map +1 -1
  74. package/dist/agent/transport.js +96 -16
  75. package/dist/agent/transport.js.map +1 -1
  76. package/dist/agent/types.d.ts +50 -2
  77. package/dist/agent/types.d.ts.map +1 -1
  78. package/dist/agent/types.js.map +1 -1
  79. package/dist/approvals/platform-action-approval.d.ts +32 -0
  80. package/dist/approvals/platform-action-approval.d.ts.map +1 -0
  81. package/dist/approvals/platform-action-approval.js +210 -0
  82. package/dist/approvals/platform-action-approval.js.map +1 -0
  83. package/dist/approvals/service-client.d.ts +56 -0
  84. package/dist/approvals/service-client.d.ts.map +1 -0
  85. package/dist/approvals/service-client.js +316 -0
  86. package/dist/approvals/service-client.js.map +1 -0
  87. package/dist/audit/logger.d.ts +4 -4
  88. package/dist/bootstrap/auth-setup.d.ts +2 -2
  89. package/dist/bootstrap/auth-setup.d.ts.map +1 -1
  90. package/dist/bootstrap/auth-setup.js +4 -7
  91. package/dist/bootstrap/auth-setup.js.map +1 -1
  92. package/dist/cli/args.d.ts +2 -0
  93. package/dist/cli/args.d.ts.map +1 -1
  94. package/dist/cli/args.js +28 -0
  95. package/dist/cli/args.js.map +1 -1
  96. package/dist/cli/commands/codex.d.ts +2 -0
  97. package/dist/cli/commands/codex.d.ts.map +1 -0
  98. package/dist/cli/commands/codex.js +65 -0
  99. package/dist/cli/commands/codex.js.map +1 -0
  100. package/dist/cli/commands/config.js +1 -1
  101. package/dist/cli/commands/config.js.map +1 -1
  102. package/dist/cli/commands/evalops.d.ts +2 -0
  103. package/dist/cli/commands/evalops.d.ts.map +1 -0
  104. package/dist/cli/commands/evalops.js +69 -0
  105. package/dist/cli/commands/evalops.js.map +1 -0
  106. package/dist/cli/commands/hosted-runner.d.ts +23 -0
  107. package/dist/cli/commands/hosted-runner.d.ts.map +1 -0
  108. package/dist/cli/commands/hosted-runner.js +241 -0
  109. package/dist/cli/commands/hosted-runner.js.map +1 -0
  110. package/dist/cli/commands/memory.d.ts.map +1 -1
  111. package/dist/cli/commands/memory.js +23 -30
  112. package/dist/cli/commands/memory.js.map +1 -1
  113. package/dist/cli/commands/remote.d.ts +3 -0
  114. package/dist/cli/commands/remote.d.ts.map +1 -0
  115. package/dist/cli/commands/remote.js +631 -0
  116. package/dist/cli/commands/remote.js.map +1 -0
  117. package/dist/cli/commands/stats.d.ts +7 -0
  118. package/dist/cli/commands/stats.d.ts.map +1 -0
  119. package/dist/cli/commands/stats.js +167 -0
  120. package/dist/cli/commands/stats.js.map +1 -0
  121. package/dist/cli/headless-protocol.d.ts +16 -1
  122. package/dist/cli/headless-protocol.d.ts.map +1 -1
  123. package/dist/cli/headless-protocol.js +60 -4
  124. package/dist/cli/headless-protocol.js.map +1 -1
  125. package/dist/cli/headless.d.ts.map +1 -1
  126. package/dist/cli/headless.js +1 -0
  127. package/dist/cli/headless.js.map +1 -1
  128. package/dist/cli/help.d.ts.map +1 -1
  129. package/dist/cli/help.js +36 -1
  130. package/dist/cli/help.js.map +1 -1
  131. package/dist/cli/jsonl-writer.d.ts.map +1 -1
  132. package/dist/cli/jsonl-writer.js +19 -6
  133. package/dist/cli/jsonl-writer.js.map +1 -1
  134. package/dist/cli-tui/client-tools/client-tool-controller.d.ts.map +1 -1
  135. package/dist/cli-tui/client-tools/client-tool-controller.js +17 -1
  136. package/dist/cli-tui/client-tools/client-tool-controller.js.map +1 -1
  137. package/dist/cli-tui/commands/access-command.js +1 -1
  138. package/dist/cli-tui/commands/access-command.js.map +1 -1
  139. package/dist/cli-tui/commands/audit-command.js +1 -1
  140. package/dist/cli-tui/commands/audit-command.js.map +1 -1
  141. package/dist/cli-tui/commands/command-catalog.d.ts +29 -0
  142. package/dist/cli-tui/commands/command-catalog.d.ts.map +1 -0
  143. package/dist/cli-tui/commands/command-catalog.js +645 -0
  144. package/dist/cli-tui/commands/command-catalog.js.map +1 -0
  145. package/dist/cli-tui/commands/command-registry-adapter.d.ts +12 -0
  146. package/dist/cli-tui/commands/command-registry-adapter.d.ts.map +1 -0
  147. package/dist/cli-tui/commands/command-registry-adapter.js +120 -0
  148. package/dist/cli-tui/commands/command-registry-adapter.js.map +1 -0
  149. package/dist/cli-tui/commands/command-suite-catalog.d.ts +14 -0
  150. package/dist/cli-tui/commands/command-suite-catalog.d.ts.map +1 -0
  151. package/dist/cli-tui/commands/command-suite-catalog.js +147 -0
  152. package/dist/cli-tui/commands/command-suite-catalog.js.map +1 -0
  153. package/dist/cli-tui/commands/{grouped-command-handlers.d.ts → command-suite-handlers.d.ts} +27 -26
  154. package/dist/cli-tui/commands/command-suite-handlers.d.ts.map +1 -0
  155. package/dist/cli-tui/commands/command-suite-handlers.js +110 -0
  156. package/dist/cli-tui/commands/command-suite-handlers.js.map +1 -0
  157. package/dist/cli-tui/commands/hotkeys-command.d.ts +1 -1
  158. package/dist/cli-tui/commands/hotkeys-command.d.ts.map +1 -1
  159. package/dist/cli-tui/commands/hotkeys-command.js +2 -2
  160. package/dist/cli-tui/commands/hotkeys-command.js.map +1 -1
  161. package/dist/cli-tui/commands/limits-command.js +1 -1
  162. package/dist/cli-tui/commands/limits-command.js.map +1 -1
  163. package/dist/cli-tui/commands/pii-command.js +1 -1
  164. package/dist/cli-tui/commands/pii-command.js.map +1 -1
  165. package/dist/cli-tui/commands/registry.d.ts +1 -1
  166. package/dist/cli-tui/commands/registry.d.ts.map +1 -1
  167. package/dist/cli-tui/commands/registry.js +29 -921
  168. package/dist/cli-tui/commands/registry.js.map +1 -1
  169. package/dist/cli-tui/commands/{grouped → subcommands}/auth-commands.d.ts +2 -1
  170. package/dist/cli-tui/commands/subcommands/auth-commands.d.ts.map +1 -0
  171. package/dist/cli-tui/commands/{grouped → subcommands}/auth-commands.js +22 -6
  172. package/dist/cli-tui/commands/subcommands/auth-commands.js.map +1 -0
  173. package/dist/cli-tui/commands/{grouped → subcommands}/config-commands.d.ts +0 -1
  174. package/dist/cli-tui/commands/subcommands/config-commands.d.ts.map +1 -0
  175. package/dist/cli-tui/commands/{grouped → subcommands}/config-commands.js +2 -2
  176. package/dist/cli-tui/commands/subcommands/config-commands.js.map +1 -0
  177. package/dist/cli-tui/commands/{grouped → subcommands}/diag-commands.d.ts +1 -2
  178. package/dist/cli-tui/commands/subcommands/diag-commands.d.ts.map +1 -0
  179. package/dist/cli-tui/commands/{grouped → subcommands}/diag-commands.js +5 -7
  180. package/dist/cli-tui/commands/subcommands/diag-commands.js.map +1 -0
  181. package/dist/cli-tui/commands/{grouped → subcommands}/git-commands.d.ts +0 -2
  182. package/dist/cli-tui/commands/subcommands/git-commands.d.ts.map +1 -0
  183. package/dist/cli-tui/commands/{grouped → subcommands}/git-commands.js +2 -2
  184. package/dist/cli-tui/commands/subcommands/git-commands.js.map +1 -0
  185. package/dist/cli-tui/commands/{grouped → subcommands}/index.d.ts +2 -2
  186. package/dist/cli-tui/commands/subcommands/index.d.ts.map +1 -0
  187. package/dist/cli-tui/commands/{grouped → subcommands}/index.js +2 -2
  188. package/dist/cli-tui/commands/subcommands/index.js.map +1 -0
  189. package/dist/cli-tui/commands/{grouped → subcommands}/safety-commands.d.ts +0 -1
  190. package/dist/cli-tui/commands/subcommands/safety-commands.d.ts.map +1 -0
  191. package/dist/cli-tui/commands/{grouped → subcommands}/safety-commands.js +12 -12
  192. package/dist/cli-tui/commands/subcommands/safety-commands.js.map +1 -0
  193. package/dist/cli-tui/commands/{grouped → subcommands}/session-commands.d.ts +1 -2
  194. package/dist/cli-tui/commands/subcommands/session-commands.d.ts.map +1 -0
  195. package/dist/cli-tui/commands/{grouped → subcommands}/session-commands.js +3 -3
  196. package/dist/cli-tui/commands/subcommands/session-commands.js.map +1 -0
  197. package/dist/cli-tui/commands/{grouped → subcommands}/tools-commands.d.ts +0 -1
  198. package/dist/cli-tui/commands/subcommands/tools-commands.d.ts.map +1 -0
  199. package/dist/cli-tui/commands/{grouped → subcommands}/tools-commands.js +2 -2
  200. package/dist/cli-tui/commands/subcommands/tools-commands.js.map +1 -0
  201. package/dist/cli-tui/commands/{grouped → subcommands}/ui-commands.d.ts +0 -1
  202. package/dist/cli-tui/commands/subcommands/ui-commands.d.ts.map +1 -0
  203. package/dist/cli-tui/commands/{grouped → subcommands}/ui-commands.js +5 -5
  204. package/dist/cli-tui/commands/subcommands/ui-commands.js.map +1 -0
  205. package/dist/cli-tui/commands/{grouped → subcommands}/undo-commands.d.ts +1 -2
  206. package/dist/cli-tui/commands/subcommands/undo-commands.d.ts.map +1 -0
  207. package/dist/cli-tui/commands/{grouped → subcommands}/undo-commands.js +6 -6
  208. package/dist/cli-tui/commands/subcommands/undo-commands.js.map +1 -0
  209. package/dist/cli-tui/commands/subcommands/usage-commands.d.ts.map +1 -0
  210. package/dist/cli-tui/commands/{grouped → subcommands}/usage-commands.js +2 -2
  211. package/dist/cli-tui/commands/subcommands/usage-commands.js.map +1 -0
  212. package/dist/cli-tui/commands/{grouped → subcommands}/utils.d.ts +15 -15
  213. package/dist/cli-tui/commands/subcommands/utils.d.ts.map +1 -0
  214. package/dist/cli-tui/commands/{grouped → subcommands}/utils.js +13 -8
  215. package/dist/cli-tui/commands/subcommands/utils.js.map +1 -0
  216. package/dist/cli-tui/commands/types.d.ts +3 -3
  217. package/dist/cli-tui/commands/types.d.ts.map +1 -1
  218. package/dist/cli-tui/commands/types.js.map +1 -1
  219. package/dist/cli-tui/editor-view.d.ts +1 -1
  220. package/dist/cli-tui/editor-view.d.ts.map +1 -1
  221. package/dist/cli-tui/editor-view.js +1 -1
  222. package/dist/cli-tui/editor-view.js.map +1 -1
  223. package/dist/cli-tui/oauth/oauth-flow-controller.d.ts +4 -0
  224. package/dist/cli-tui/oauth/oauth-flow-controller.d.ts.map +1 -1
  225. package/dist/cli-tui/oauth/oauth-flow-controller.js +76 -5
  226. package/dist/cli-tui/oauth/oauth-flow-controller.js.map +1 -1
  227. package/dist/cli-tui/run/run-controller.d.ts +2 -2
  228. package/dist/cli-tui/run/run-controller.d.ts.map +1 -1
  229. package/dist/cli-tui/run/run-controller.js +3 -2
  230. package/dist/cli-tui/run/run-controller.js.map +1 -1
  231. package/dist/cli-tui/run/run-shell-command.d.ts.map +1 -1
  232. package/dist/cli-tui/run/run-shell-command.js +11 -3
  233. package/dist/cli-tui/run/run-shell-command.js.map +1 -1
  234. package/dist/cli-tui/run/streaming-shell-command.d.ts.map +1 -1
  235. package/dist/cli-tui/run/streaming-shell-command.js +11 -3
  236. package/dist/cli-tui/run/streaming-shell-command.js.map +1 -1
  237. package/dist/cli-tui/selectors/model-selector.d.ts.map +1 -1
  238. package/dist/cli-tui/selectors/model-selector.js +1 -0
  239. package/dist/cli-tui/selectors/model-selector.js.map +1 -1
  240. package/dist/cli-tui/tui-renderer/agent-event-bridge.d.ts +8 -0
  241. package/dist/cli-tui/tui-renderer/agent-event-bridge.d.ts.map +1 -1
  242. package/dist/cli-tui/tui-renderer/agent-event-bridge.js +23 -2
  243. package/dist/cli-tui/tui-renderer/agent-event-bridge.js.map +1 -1
  244. package/dist/cli-tui/tui-renderer/command-registry-options.d.ts +3 -3
  245. package/dist/cli-tui/tui-renderer/command-registry-options.d.ts.map +1 -1
  246. package/dist/cli-tui/tui-renderer/command-registry-options.js +12 -2
  247. package/dist/cli-tui/tui-renderer/command-registry-options.js.map +1 -1
  248. package/dist/cli-tui/tui-renderer/command-suite-wiring.d.ts +32 -0
  249. package/dist/cli-tui/tui-renderer/command-suite-wiring.d.ts.map +1 -0
  250. package/dist/cli-tui/tui-renderer/command-suite-wiring.js +108 -0
  251. package/dist/cli-tui/tui-renderer/command-suite-wiring.js.map +1 -0
  252. package/dist/cli-tui/tui-renderer/input-controller.d.ts +2 -2
  253. package/dist/cli-tui/tui-renderer/input-controller.d.ts.map +1 -1
  254. package/dist/cli-tui/tui-renderer/input-controller.js +2 -2
  255. package/dist/cli-tui/tui-renderer/input-controller.js.map +1 -1
  256. package/dist/cli-tui/tui-renderer/ui-state-controller.d.ts +1 -1
  257. package/dist/cli-tui/tui-renderer/ui-state-controller.js +1 -1
  258. package/dist/cli-tui/tui-renderer/ui-state-controller.js.map +1 -1
  259. package/dist/cli-tui/tui-renderer.d.ts +1 -3
  260. package/dist/cli-tui/tui-renderer.d.ts.map +1 -1
  261. package/dist/cli-tui/tui-renderer.js +37 -83
  262. package/dist/cli-tui/tui-renderer.js.map +1 -1
  263. package/dist/cli-tui/utils/runtime-badges.d.ts +8 -0
  264. package/dist/cli-tui/utils/runtime-badges.d.ts.map +1 -1
  265. package/dist/cli-tui/utils/runtime-badges.js +58 -0
  266. package/dist/cli-tui/utils/runtime-badges.js.map +1 -1
  267. package/dist/cli.js +41771 -22892
  268. package/dist/cli.js.map +1 -1
  269. package/dist/config/env-vars.d.ts +4 -0
  270. package/dist/config/env-vars.d.ts.map +1 -1
  271. package/dist/config/env-vars.js +4 -0
  272. package/dist/config/env-vars.js.map +1 -1
  273. package/dist/config/feature-flags.d.ts +44 -0
  274. package/dist/config/feature-flags.d.ts.map +1 -1
  275. package/dist/config/feature-flags.js +214 -0
  276. package/dist/config/feature-flags.js.map +1 -1
  277. package/dist/connectors/service-client.d.ts +98 -0
  278. package/dist/connectors/service-client.d.ts.map +1 -0
  279. package/dist/connectors/service-client.js +459 -0
  280. package/dist/connectors/service-client.js.map +1 -0
  281. package/dist/conversation/render-model.d.ts.map +1 -1
  282. package/dist/conversation/render-model.js +53 -3
  283. package/dist/conversation/render-model.js.map +1 -1
  284. package/dist/db/health.d.ts +8 -0
  285. package/dist/db/health.d.ts.map +1 -0
  286. package/dist/db/health.js +64 -0
  287. package/dist/db/health.js.map +1 -0
  288. package/dist/db/migrate.d.ts +301 -0
  289. package/dist/db/migrate.d.ts.map +1 -1
  290. package/dist/db/migrate.js +186 -0
  291. package/dist/db/migrate.js.map +1 -1
  292. package/dist/db/migrations/0000_initial.sql +308 -0
  293. package/dist/db/migrations/0001_shared_sessions.sql +18 -0
  294. package/dist/db/migrations/0002_usage_metrics.sql +28 -0
  295. package/dist/db/migrations/0003_execution_traces.sql +18 -0
  296. package/dist/db/migrations/0004_workspace_config.sql +11 -0
  297. package/dist/db/migrations/0005_revenue_attribution.sql +31 -0
  298. package/dist/db/migrations/0006_hosted_session_storage.sql +51 -0
  299. package/dist/db/migrations/0007_reconcile_legacy_audit_hash_cache.sql +24 -0
  300. package/dist/db/migrations/0008_reconcile_legacy_webhook_deliveries.sql +290 -0
  301. package/dist/db/migrations/meta/0000_snapshot.json +2438 -0
  302. package/dist/db/migrations/meta/_journal.json +69 -0
  303. package/dist/db/schema.d.ts +2232 -844
  304. package/dist/db/schema.d.ts.map +1 -1
  305. package/dist/db/schema.js +187 -1
  306. package/dist/db/schema.js.map +1 -1
  307. package/dist/export-html.d.ts.map +1 -1
  308. package/dist/export-html.js +7 -4
  309. package/dist/export-html.js.map +1 -1
  310. package/dist/headless/utility-command-manager.d.ts +2 -1
  311. package/dist/headless/utility-command-manager.d.ts.map +1 -1
  312. package/dist/headless/utility-command-manager.js +12 -6
  313. package/dist/headless/utility-command-manager.js.map +1 -1
  314. package/dist/headless/utility-file-read.d.ts +1 -0
  315. package/dist/headless/utility-file-read.d.ts.map +1 -1
  316. package/dist/headless/utility-file-read.js +5 -1
  317. package/dist/headless/utility-file-read.js.map +1 -1
  318. package/dist/headless/utility-file-search.d.ts +1 -0
  319. package/dist/headless/utility-file-search.d.ts.map +1 -1
  320. package/dist/headless/utility-file-search.js +4 -1
  321. package/dist/headless/utility-file-search.js.map +1 -1
  322. package/dist/headless/utility-file-watch-manager.d.ts +2 -1
  323. package/dist/headless/utility-file-watch-manager.d.ts.map +1 -1
  324. package/dist/headless/utility-file-watch-manager.js +6 -2
  325. package/dist/headless/utility-file-watch-manager.js.map +1 -1
  326. package/dist/headless/workspace-root.d.ts +8 -0
  327. package/dist/headless/workspace-root.d.ts.map +1 -0
  328. package/dist/headless/workspace-root.js +74 -0
  329. package/dist/headless/workspace-root.js.map +1 -0
  330. package/dist/hooks/notification-hooks.d.ts +5 -0
  331. package/dist/hooks/notification-hooks.d.ts.map +1 -1
  332. package/dist/hooks/notification-hooks.js +4 -0
  333. package/dist/hooks/notification-hooks.js.map +1 -1
  334. package/dist/lsp/diagnostic-deltas.d.ts +20 -0
  335. package/dist/lsp/diagnostic-deltas.d.ts.map +1 -0
  336. package/dist/lsp/diagnostic-deltas.js +92 -0
  337. package/dist/lsp/diagnostic-deltas.js.map +1 -0
  338. package/dist/lsp/diagnostic-repair.d.ts +48 -0
  339. package/dist/lsp/diagnostic-repair.d.ts.map +1 -0
  340. package/dist/lsp/diagnostic-repair.js +143 -0
  341. package/dist/lsp/diagnostic-repair.js.map +1 -0
  342. package/dist/main.d.ts.map +1 -1
  343. package/dist/main.js +122 -37
  344. package/dist/main.js.map +1 -1
  345. package/dist/mcp/config.d.ts +4 -2
  346. package/dist/mcp/config.d.ts.map +1 -1
  347. package/dist/mcp/config.js +58 -14
  348. package/dist/mcp/config.js.map +1 -1
  349. package/dist/mcp/index.d.ts +1 -0
  350. package/dist/mcp/index.d.ts.map +1 -1
  351. package/dist/mcp/index.js +1 -0
  352. package/dist/mcp/index.js.map +1 -1
  353. package/dist/mcp/manager.d.ts +1 -0
  354. package/dist/mcp/manager.d.ts.map +1 -1
  355. package/dist/mcp/manager.js +1 -0
  356. package/dist/mcp/manager.js.map +1 -1
  357. package/dist/mcp/platform-plugin.d.ts +3 -0
  358. package/dist/mcp/platform-plugin.d.ts.map +1 -0
  359. package/dist/mcp/platform-plugin.js +83 -0
  360. package/dist/mcp/platform-plugin.js.map +1 -0
  361. package/dist/mcp/tool-bridge.d.ts +15 -0
  362. package/dist/mcp/tool-bridge.d.ts.map +1 -1
  363. package/dist/mcp/tool-bridge.js +194 -6
  364. package/dist/mcp/tool-bridge.js.map +1 -1
  365. package/dist/memory/platform-memory-client.d.ts +130 -0
  366. package/dist/memory/platform-memory-client.d.ts.map +1 -0
  367. package/dist/memory/platform-memory-client.js +330 -0
  368. package/dist/memory/platform-memory-client.js.map +1 -0
  369. package/dist/memory/service-client.d.ts.map +1 -1
  370. package/dist/memory/service-client.js +1 -2
  371. package/dist/memory/service-client.js.map +1 -1
  372. package/dist/models/builtin.d.ts.map +1 -1
  373. package/dist/models/builtin.js +137 -0
  374. package/dist/models/builtin.js.map +1 -1
  375. package/dist/models/config-loader.d.ts +10 -10
  376. package/dist/models/config-loader.d.ts.map +1 -1
  377. package/dist/models/config-loader.js +1 -0
  378. package/dist/models/config-loader.js.map +1 -1
  379. package/dist/models/registry.d.ts +1 -0
  380. package/dist/models/registry.d.ts.map +1 -1
  381. package/dist/models/registry.js +1 -0
  382. package/dist/models/registry.js.map +1 -1
  383. package/dist/oauth/connectors.d.ts +25 -0
  384. package/dist/oauth/connectors.d.ts.map +1 -0
  385. package/dist/oauth/connectors.js +253 -0
  386. package/dist/oauth/connectors.js.map +1 -0
  387. package/dist/oauth/device-identity.d.ts +18 -0
  388. package/dist/oauth/device-identity.d.ts.map +1 -0
  389. package/dist/oauth/device-identity.js +193 -0
  390. package/dist/oauth/device-identity.js.map +1 -0
  391. package/dist/oauth/evalops.d.ts.map +1 -1
  392. package/dist/oauth/evalops.js +73 -14
  393. package/dist/oauth/evalops.js.map +1 -1
  394. package/dist/oauth/index.d.ts +1 -1
  395. package/dist/oauth/index.d.ts.map +1 -1
  396. package/dist/oauth/index.js +31 -1
  397. package/dist/oauth/index.js.map +1 -1
  398. package/dist/oauth/openai-codex.d.ts +16 -0
  399. package/dist/oauth/openai-codex.d.ts.map +1 -0
  400. package/dist/oauth/openai-codex.js +300 -0
  401. package/dist/oauth/openai-codex.js.map +1 -0
  402. package/dist/opentelemetry.d.ts.map +1 -1
  403. package/dist/opentelemetry.js +9 -2
  404. package/dist/opentelemetry.js.map +1 -1
  405. package/dist/platform/agent-runtime-client.d.ts +279 -0
  406. package/dist/platform/agent-runtime-client.d.ts.map +1 -0
  407. package/dist/platform/agent-runtime-client.js +515 -0
  408. package/dist/platform/agent-runtime-client.js.map +1 -0
  409. package/dist/platform/cerebro-facts-client.d.ts +56 -0
  410. package/dist/platform/cerebro-facts-client.d.ts.map +1 -0
  411. package/dist/platform/cerebro-facts-client.js +297 -0
  412. package/dist/platform/cerebro-facts-client.js.map +1 -0
  413. package/dist/platform/client.d.ts +2 -1
  414. package/dist/platform/client.d.ts.map +1 -1
  415. package/dist/platform/client.js +9 -26
  416. package/dist/platform/client.js.map +1 -1
  417. package/dist/platform/core-services.d.ts +128 -0
  418. package/dist/platform/core-services.d.ts.map +1 -1
  419. package/dist/platform/core-services.js +128 -0
  420. package/dist/platform/core-services.js.map +1 -1
  421. package/dist/platform/maestro-timeline-client.d.ts +22 -0
  422. package/dist/platform/maestro-timeline-client.d.ts.map +1 -0
  423. package/dist/platform/maestro-timeline-client.js +373 -0
  424. package/dist/platform/maestro-timeline-client.js.map +1 -0
  425. package/dist/platform/tool-execution-client.d.ts +104 -0
  426. package/dist/platform/tool-execution-client.d.ts.map +1 -0
  427. package/dist/platform/tool-execution-client.js +284 -0
  428. package/dist/platform/tool-execution-client.js.map +1 -0
  429. package/dist/prompts/service-client.d.ts.map +1 -1
  430. package/dist/prompts/service-client.js +5 -2
  431. package/dist/prompts/service-client.js.map +1 -1
  432. package/dist/providers/anthropic-auth.d.ts.map +1 -1
  433. package/dist/providers/anthropic-auth.js +8 -6
  434. package/dist/providers/anthropic-auth.js.map +1 -1
  435. package/dist/providers/api-keys.d.ts +1 -0
  436. package/dist/providers/api-keys.d.ts.map +1 -1
  437. package/dist/providers/api-keys.js +5 -0
  438. package/dist/providers/api-keys.js.map +1 -1
  439. package/dist/providers/auth.d.ts +2 -1
  440. package/dist/providers/auth.d.ts.map +1 -1
  441. package/dist/providers/auth.js +26 -3
  442. package/dist/providers/auth.js.map +1 -1
  443. package/dist/remote-runner/attach-client.d.ts +41 -0
  444. package/dist/remote-runner/attach-client.d.ts.map +1 -0
  445. package/dist/remote-runner/attach-client.js +692 -0
  446. package/dist/remote-runner/attach-client.js.map +1 -0
  447. package/dist/remote-runner/client.d.ts +205 -0
  448. package/dist/remote-runner/client.d.ts.map +1 -0
  449. package/dist/remote-runner/client.js +633 -0
  450. package/dist/remote-runner/client.js.map +1 -0
  451. package/dist/safety/action-firewall.d.ts +6 -1
  452. package/dist/safety/action-firewall.d.ts.map +1 -1
  453. package/dist/safety/action-firewall.js +62 -26
  454. package/dist/safety/action-firewall.js.map +1 -1
  455. package/dist/safety/governance-service-client.d.ts +36 -0
  456. package/dist/safety/governance-service-client.d.ts.map +1 -0
  457. package/dist/safety/governance-service-client.js +279 -0
  458. package/dist/safety/governance-service-client.js.map +1 -0
  459. package/dist/safety/policy.d.ts +13 -2
  460. package/dist/safety/policy.d.ts.map +1 -1
  461. package/dist/safety/policy.js +474 -52
  462. package/dist/safety/policy.js.map +1 -1
  463. package/dist/sdk-tools.d.ts +21 -0
  464. package/dist/sdk-tools.d.ts.map +1 -1
  465. package/dist/sdk-tools.js +16 -0
  466. package/dist/sdk-tools.js.map +1 -1
  467. package/dist/server/app-context.d.ts +25 -0
  468. package/dist/server/app-context.d.ts.map +1 -1
  469. package/dist/server/app-context.js.map +1 -1
  470. package/dist/server/approval-service.d.ts +7 -8
  471. package/dist/server/approval-service.d.ts.map +1 -1
  472. package/dist/server/approval-service.js +12 -24
  473. package/dist/server/approval-service.js.map +1 -1
  474. package/dist/server/authz.d.ts +23 -2
  475. package/dist/server/authz.d.ts.map +1 -1
  476. package/dist/server/authz.js +153 -17
  477. package/dist/server/authz.js.map +1 -1
  478. package/dist/server/handlers/approvals.d.ts.map +1 -1
  479. package/dist/server/handlers/approvals.js +3 -10
  480. package/dist/server/handlers/approvals.js.map +1 -1
  481. package/dist/server/handlers/branch.d.ts.map +1 -1
  482. package/dist/server/handlers/branch.js +29 -20
  483. package/dist/server/handlers/branch.js.map +1 -1
  484. package/dist/server/handlers/bridge.d.ts.map +1 -1
  485. package/dist/server/handlers/bridge.js +3 -2
  486. package/dist/server/handlers/bridge.js.map +1 -1
  487. package/dist/server/handlers/chat-ws.d.ts.map +1 -1
  488. package/dist/server/handlers/chat-ws.js +23 -31
  489. package/dist/server/handlers/chat-ws.js.map +1 -1
  490. package/dist/server/handlers/chat.d.ts.map +1 -1
  491. package/dist/server/handlers/chat.js +105 -46
  492. package/dist/server/handlers/chat.js.map +1 -1
  493. package/dist/server/handlers/compliance.d.ts +3 -0
  494. package/dist/server/handlers/compliance.d.ts.map +1 -0
  495. package/dist/server/handlers/compliance.js +53 -0
  496. package/dist/server/handlers/compliance.js.map +1 -0
  497. package/dist/server/handlers/context.d.ts.map +1 -1
  498. package/dist/server/handlers/context.js +3 -8
  499. package/dist/server/handlers/context.js.map +1 -1
  500. package/dist/server/handlers/fleet.d.ts +4 -0
  501. package/dist/server/handlers/fleet.d.ts.map +1 -0
  502. package/dist/server/handlers/fleet.js +9 -0
  503. package/dist/server/handlers/fleet.js.map +1 -0
  504. package/dist/server/handlers/headless-sessions.d.ts +4 -0
  505. package/dist/server/handlers/headless-sessions.d.ts.map +1 -1
  506. package/dist/server/handlers/headless-sessions.js +168 -3
  507. package/dist/server/handlers/headless-sessions.js.map +1 -1
  508. package/dist/server/handlers/health.d.ts +31 -2
  509. package/dist/server/handlers/health.d.ts.map +1 -1
  510. package/dist/server/handlers/health.js +82 -8
  511. package/dist/server/handlers/health.js.map +1 -1
  512. package/dist/server/handlers/hosted-runner-drain.d.ts +128 -0
  513. package/dist/server/handlers/hosted-runner-drain.d.ts.map +1 -0
  514. package/dist/server/handlers/hosted-runner-drain.js +373 -0
  515. package/dist/server/handlers/hosted-runner-drain.js.map +1 -0
  516. package/dist/server/handlers/hosted-runner-identity.d.ts +17 -0
  517. package/dist/server/handlers/hosted-runner-identity.d.ts.map +1 -0
  518. package/dist/server/handlers/hosted-runner-identity.js +39 -0
  519. package/dist/server/handlers/hosted-runner-identity.js.map +1 -0
  520. package/dist/server/handlers/intelligent-router.d.ts +3 -0
  521. package/dist/server/handlers/intelligent-router.d.ts.map +1 -0
  522. package/dist/server/handlers/intelligent-router.js +141 -0
  523. package/dist/server/handlers/intelligent-router.js.map +1 -0
  524. package/dist/server/handlers/models.d.ts.map +1 -1
  525. package/dist/server/handlers/models.js +14 -0
  526. package/dist/server/handlers/models.js.map +1 -1
  527. package/dist/server/handlers/pending-requests.d.ts +8 -0
  528. package/dist/server/handlers/pending-requests.d.ts.map +1 -0
  529. package/dist/server/handlers/pending-requests.js +149 -0
  530. package/dist/server/handlers/pending-requests.js.map +1 -0
  531. package/dist/server/handlers/revenue-attribution.d.ts +3 -0
  532. package/dist/server/handlers/revenue-attribution.d.ts.map +1 -0
  533. package/dist/server/handlers/revenue-attribution.js +45 -0
  534. package/dist/server/handlers/revenue-attribution.js.map +1 -0
  535. package/dist/server/handlers/runtime-app-server-ws.d.ts +10 -0
  536. package/dist/server/handlers/runtime-app-server-ws.d.ts.map +1 -0
  537. package/dist/server/handlers/runtime-app-server-ws.js +206 -0
  538. package/dist/server/handlers/runtime-app-server-ws.js.map +1 -0
  539. package/dist/server/handlers/session-artifacts.js +2 -2
  540. package/dist/server/handlers/session-artifacts.js.map +1 -1
  541. package/dist/server/handlers/session-attachments.js +3 -3
  542. package/dist/server/handlers/session-attachments.js.map +1 -1
  543. package/dist/server/handlers/session-timeline.d.ts +11 -0
  544. package/dist/server/handlers/session-timeline.d.ts.map +1 -0
  545. package/dist/server/handlers/session-timeline.js +77 -0
  546. package/dist/server/handlers/session-timeline.js.map +1 -0
  547. package/dist/server/handlers/sessions.d.ts +11 -0
  548. package/dist/server/handlers/sessions.d.ts.map +1 -1
  549. package/dist/server/handlers/sessions.js +68 -100
  550. package/dist/server/handlers/sessions.js.map +1 -1
  551. package/dist/server/handlers/traces.d.ts +3 -0
  552. package/dist/server/handlers/traces.d.ts.map +1 -0
  553. package/dist/server/handlers/traces.js +60 -0
  554. package/dist/server/handlers/traces.js.map +1 -0
  555. package/dist/server/handlers/usage-analytics.d.ts +3 -0
  556. package/dist/server/handlers/usage-analytics.d.ts.map +1 -0
  557. package/dist/server/handlers/usage-analytics.js +40 -0
  558. package/dist/server/handlers/usage-analytics.js.map +1 -0
  559. package/dist/server/handlers/workspace-config.d.ts +3 -0
  560. package/dist/server/handlers/workspace-config.d.ts.map +1 -0
  561. package/dist/server/handlers/workspace-config.js +62 -0
  562. package/dist/server/handlers/workspace-config.js.map +1 -0
  563. package/dist/server/headless-in-process-host.d.ts +8 -1
  564. package/dist/server/headless-in-process-host.d.ts.map +1 -1
  565. package/dist/server/headless-in-process-host.js +6 -0
  566. package/dist/server/headless-in-process-host.js.map +1 -1
  567. package/dist/server/headless-runtime-service.d.ts +99 -1
  568. package/dist/server/headless-runtime-service.d.ts.map +1 -1
  569. package/dist/server/headless-runtime-service.js +286 -23
  570. package/dist/server/headless-runtime-service.js.map +1 -1
  571. package/dist/server/hosted-session-manager.d.ts +103 -0
  572. package/dist/server/hosted-session-manager.d.ts.map +1 -0
  573. package/dist/server/hosted-session-manager.js +629 -0
  574. package/dist/server/hosted-session-manager.js.map +1 -0
  575. package/dist/server/pending-request-payload.d.ts +4 -0
  576. package/dist/server/pending-request-payload.d.ts.map +1 -0
  577. package/dist/server/pending-request-payload.js +107 -0
  578. package/dist/server/pending-request-payload.js.map +1 -0
  579. package/dist/server/request-context.d.ts +4 -0
  580. package/dist/server/request-context.d.ts.map +1 -1
  581. package/dist/server/request-context.js +9 -0
  582. package/dist/server/request-context.js.map +1 -1
  583. package/dist/server/routes.d.ts.map +1 -1
  584. package/dist/server/routes.js +149 -1
  585. package/dist/server/routes.js.map +1 -1
  586. package/dist/server/runtime-ws-access.d.ts +16 -0
  587. package/dist/server/runtime-ws-access.d.ts.map +1 -0
  588. package/dist/server/runtime-ws-access.js +21 -0
  589. package/dist/server/runtime-ws-access.js.map +1 -0
  590. package/dist/server/server-middlewares.d.ts +1 -1
  591. package/dist/server/server-middlewares.d.ts.map +1 -1
  592. package/dist/server/server-middlewares.js +35 -27
  593. package/dist/server/server-middlewares.js.map +1 -1
  594. package/dist/server/server-request-manager.d.ts +8 -27
  595. package/dist/server/server-request-manager.d.ts.map +1 -1
  596. package/dist/server/server-request-manager.js +7 -0
  597. package/dist/server/server-request-manager.js.map +1 -1
  598. package/dist/server/server-utils.d.ts +2 -1
  599. package/dist/server/server-utils.d.ts.map +1 -1
  600. package/dist/server/server-utils.js +11 -1
  601. package/dist/server/server-utils.js.map +1 -1
  602. package/dist/server/session-event-env.d.ts +2 -0
  603. package/dist/server/session-event-env.d.ts.map +1 -0
  604. package/dist/server/session-event-env.js +8 -0
  605. package/dist/server/session-event-env.js.map +1 -0
  606. package/dist/server/session-initialization.d.ts +25 -4
  607. package/dist/server/session-initialization.d.ts.map +1 -1
  608. package/dist/server/session-initialization.js +22 -5
  609. package/dist/server/session-initialization.js.map +1 -1
  610. package/dist/server/session-scope.d.ts +4 -0
  611. package/dist/server/session-scope.d.ts.map +1 -1
  612. package/dist/server/session-scope.js +44 -4
  613. package/dist/server/session-scope.js.map +1 -1
  614. package/dist/server/session-timeline.d.ts +13 -0
  615. package/dist/server/session-timeline.d.ts.map +1 -0
  616. package/dist/server/session-timeline.js +566 -0
  617. package/dist/server/session-timeline.js.map +1 -0
  618. package/dist/services/compliance/controls.d.ts +6 -0
  619. package/dist/services/compliance/controls.d.ts.map +1 -0
  620. package/dist/services/compliance/controls.js +113 -0
  621. package/dist/services/compliance/controls.js.map +1 -0
  622. package/dist/services/compliance/index.d.ts +6 -0
  623. package/dist/services/compliance/index.d.ts.map +1 -0
  624. package/dist/services/compliance/index.js +5 -0
  625. package/dist/services/compliance/index.js.map +1 -0
  626. package/dist/services/compliance/normalize.d.ts +23 -0
  627. package/dist/services/compliance/normalize.d.ts.map +1 -0
  628. package/dist/services/compliance/normalize.js +226 -0
  629. package/dist/services/compliance/normalize.js.map +1 -0
  630. package/dist/services/compliance/recorder.d.ts +22 -0
  631. package/dist/services/compliance/recorder.d.ts.map +1 -0
  632. package/dist/services/compliance/recorder.js +89 -0
  633. package/dist/services/compliance/recorder.js.map +1 -0
  634. package/dist/services/compliance/service.d.ts +24 -0
  635. package/dist/services/compliance/service.d.ts.map +1 -0
  636. package/dist/services/compliance/service.js +426 -0
  637. package/dist/services/compliance/service.js.map +1 -0
  638. package/dist/services/compliance/types.d.ts +185 -0
  639. package/dist/services/compliance/types.d.ts.map +1 -0
  640. package/dist/services/compliance/types.js +2 -0
  641. package/dist/services/compliance/types.js.map +1 -0
  642. package/dist/services/intelligent-router/index.d.ts +5 -0
  643. package/dist/services/intelligent-router/index.d.ts.map +1 -0
  644. package/dist/services/intelligent-router/index.js +5 -0
  645. package/dist/services/intelligent-router/index.js.map +1 -0
  646. package/dist/services/intelligent-router/normalize.d.ts +9 -0
  647. package/dist/services/intelligent-router/normalize.d.ts.map +1 -0
  648. package/dist/services/intelligent-router/normalize.js +169 -0
  649. package/dist/services/intelligent-router/normalize.js.map +1 -0
  650. package/dist/services/intelligent-router/recorder.d.ts +24 -0
  651. package/dist/services/intelligent-router/recorder.d.ts.map +1 -0
  652. package/dist/services/intelligent-router/recorder.js +98 -0
  653. package/dist/services/intelligent-router/recorder.js.map +1 -0
  654. package/dist/services/intelligent-router/service.d.ts +22 -0
  655. package/dist/services/intelligent-router/service.d.ts.map +1 -0
  656. package/dist/services/intelligent-router/service.js +328 -0
  657. package/dist/services/intelligent-router/service.js.map +1 -0
  658. package/dist/services/intelligent-router/types.d.ts +98 -0
  659. package/dist/services/intelligent-router/types.d.ts.map +1 -0
  660. package/dist/services/intelligent-router/types.js +7 -0
  661. package/dist/services/intelligent-router/types.js.map +1 -0
  662. package/dist/services/revenue-attribution/index.d.ts +4 -0
  663. package/dist/services/revenue-attribution/index.d.ts.map +1 -0
  664. package/dist/services/revenue-attribution/index.js +4 -0
  665. package/dist/services/revenue-attribution/index.js.map +1 -0
  666. package/dist/services/revenue-attribution/normalize.d.ts +13 -0
  667. package/dist/services/revenue-attribution/normalize.d.ts.map +1 -0
  668. package/dist/services/revenue-attribution/normalize.js +155 -0
  669. package/dist/services/revenue-attribution/normalize.js.map +1 -0
  670. package/dist/services/revenue-attribution/service.d.ts +21 -0
  671. package/dist/services/revenue-attribution/service.d.ts.map +1 -0
  672. package/dist/services/revenue-attribution/service.js +248 -0
  673. package/dist/services/revenue-attribution/service.js.map +1 -0
  674. package/dist/services/revenue-attribution/types.d.ts +96 -0
  675. package/dist/services/revenue-attribution/types.d.ts.map +1 -0
  676. package/dist/services/revenue-attribution/types.js +7 -0
  677. package/dist/services/revenue-attribution/types.js.map +1 -0
  678. package/dist/services/traces/index.d.ts +5 -0
  679. package/dist/services/traces/index.d.ts.map +1 -0
  680. package/dist/services/traces/index.js +4 -0
  681. package/dist/services/traces/index.js.map +1 -0
  682. package/dist/services/traces/normalize.d.ts +20 -0
  683. package/dist/services/traces/normalize.d.ts.map +1 -0
  684. package/dist/services/traces/normalize.js +261 -0
  685. package/dist/services/traces/normalize.js.map +1 -0
  686. package/dist/services/traces/otel.d.ts +3 -0
  687. package/dist/services/traces/otel.d.ts.map +1 -0
  688. package/dist/services/traces/otel.js +173 -0
  689. package/dist/services/traces/otel.js.map +1 -0
  690. package/dist/services/traces/service.d.ts +17 -0
  691. package/dist/services/traces/service.d.ts.map +1 -0
  692. package/dist/services/traces/service.js +197 -0
  693. package/dist/services/traces/service.js.map +1 -0
  694. package/dist/services/traces/types.d.ts +130 -0
  695. package/dist/services/traces/types.d.ts.map +1 -0
  696. package/dist/services/traces/types.js +8 -0
  697. package/dist/services/traces/types.js.map +1 -0
  698. package/dist/services/usage-analytics/aggregation.d.ts +18 -0
  699. package/dist/services/usage-analytics/aggregation.d.ts.map +1 -0
  700. package/dist/services/usage-analytics/aggregation.js +130 -0
  701. package/dist/services/usage-analytics/aggregation.js.map +1 -0
  702. package/dist/services/usage-analytics/index.d.ts +5 -0
  703. package/dist/services/usage-analytics/index.d.ts.map +1 -0
  704. package/dist/services/usage-analytics/index.js +4 -0
  705. package/dist/services/usage-analytics/index.js.map +1 -0
  706. package/dist/services/usage-analytics/recorder.d.ts +16 -0
  707. package/dist/services/usage-analytics/recorder.d.ts.map +1 -0
  708. package/dist/services/usage-analytics/recorder.js +128 -0
  709. package/dist/services/usage-analytics/recorder.js.map +1 -0
  710. package/dist/services/usage-analytics/service.d.ts +15 -0
  711. package/dist/services/usage-analytics/service.d.ts.map +1 -0
  712. package/dist/services/usage-analytics/service.js +210 -0
  713. package/dist/services/usage-analytics/service.js.map +1 -0
  714. package/dist/services/usage-analytics/types.d.ts +80 -0
  715. package/dist/services/usage-analytics/types.d.ts.map +1 -0
  716. package/dist/services/usage-analytics/types.js +2 -0
  717. package/dist/services/usage-analytics/types.js.map +1 -0
  718. package/dist/services/workspace-config/index.d.ts +6 -0
  719. package/dist/services/workspace-config/index.d.ts.map +1 -0
  720. package/dist/services/workspace-config/index.js +5 -0
  721. package/dist/services/workspace-config/index.js.map +1 -0
  722. package/dist/services/workspace-config/middleware.d.ts +5 -0
  723. package/dist/services/workspace-config/middleware.d.ts.map +1 -0
  724. package/dist/services/workspace-config/middleware.js +98 -0
  725. package/dist/services/workspace-config/middleware.js.map +1 -0
  726. package/dist/services/workspace-config/normalize.d.ts +17 -0
  727. package/dist/services/workspace-config/normalize.d.ts.map +1 -0
  728. package/dist/services/workspace-config/normalize.js +148 -0
  729. package/dist/services/workspace-config/normalize.js.map +1 -0
  730. package/dist/services/workspace-config/policy.d.ts +16 -0
  731. package/dist/services/workspace-config/policy.d.ts.map +1 -0
  732. package/dist/services/workspace-config/policy.js +77 -0
  733. package/dist/services/workspace-config/policy.js.map +1 -0
  734. package/dist/services/workspace-config/service.d.ts +20 -0
  735. package/dist/services/workspace-config/service.d.ts.map +1 -0
  736. package/dist/services/workspace-config/service.js +162 -0
  737. package/dist/services/workspace-config/service.js.map +1 -0
  738. package/dist/services/workspace-config/types.d.ts +71 -0
  739. package/dist/services/workspace-config/types.d.ts.map +1 -0
  740. package/dist/services/workspace-config/types.js +2 -0
  741. package/dist/services/workspace-config/types.js.map +1 -0
  742. package/dist/session/manager.d.ts.map +1 -1
  743. package/dist/session/manager.js +10 -0
  744. package/dist/session/manager.js.map +1 -1
  745. package/dist/session/migration.d.ts.map +1 -1
  746. package/dist/session/migration.js +2 -1
  747. package/dist/session/migration.js.map +1 -1
  748. package/dist/session/session-memory.d.ts.map +1 -1
  749. package/dist/session/session-memory.js +7 -1
  750. package/dist/session/session-memory.js.map +1 -1
  751. package/dist/session/types.d.ts +1 -2
  752. package/dist/session/types.d.ts.map +1 -1
  753. package/dist/session/types.js +1 -22
  754. package/dist/session/types.js.map +1 -1
  755. package/dist/session/wire-format.d.ts +7 -0
  756. package/dist/session/wire-format.d.ts.map +1 -0
  757. package/dist/session/wire-format.generated.d.ts +95 -0
  758. package/dist/session/wire-format.generated.d.ts.map +1 -0
  759. package/dist/session/wire-format.generated.js +111 -0
  760. package/dist/session/wire-format.generated.js.map +1 -0
  761. package/dist/session/wire-format.js +145 -0
  762. package/dist/session/wire-format.js.map +1 -0
  763. package/dist/shared-memory/client.d.ts.map +1 -1
  764. package/dist/shared-memory/client.js +22 -22
  765. package/dist/shared-memory/client.js.map +1 -1
  766. package/dist/skills/artifact-metadata.d.ts +16 -0
  767. package/dist/skills/artifact-metadata.d.ts.map +1 -0
  768. package/dist/skills/artifact-metadata.js +86 -0
  769. package/dist/skills/artifact-metadata.js.map +1 -0
  770. package/dist/skills/loader.d.ts +2 -2
  771. package/dist/skills/loader.d.ts.map +1 -1
  772. package/dist/skills/loader.js +1 -0
  773. package/dist/skills/loader.js.map +1 -1
  774. package/dist/skills/service-client.d.ts +42 -0
  775. package/dist/skills/service-client.d.ts.map +1 -0
  776. package/dist/skills/service-client.js +258 -0
  777. package/dist/skills/service-client.js.map +1 -0
  778. package/dist/skills/tool.d.ts +3 -0
  779. package/dist/skills/tool.d.ts.map +1 -1
  780. package/dist/skills/tool.js +67 -5
  781. package/dist/skills/tool.js.map +1 -1
  782. package/dist/telemetry/index.d.ts +4 -0
  783. package/dist/telemetry/index.d.ts.map +1 -1
  784. package/dist/telemetry/index.js +5 -0
  785. package/dist/telemetry/index.js.map +1 -1
  786. package/dist/telemetry/maestro-event-bus.d.ts +440 -0
  787. package/dist/telemetry/maestro-event-bus.d.ts.map +1 -0
  788. package/dist/telemetry/maestro-event-bus.js +784 -0
  789. package/dist/telemetry/maestro-event-bus.js.map +1 -0
  790. package/dist/telemetry/maestro-event-catalog.d.ts +48 -0
  791. package/dist/telemetry/maestro-event-catalog.d.ts.map +1 -0
  792. package/dist/telemetry/maestro-event-catalog.js +69 -0
  793. package/dist/telemetry/maestro-event-catalog.js.map +1 -0
  794. package/dist/telemetry/maestro-platform-replay-fixture.d.ts +24 -0
  795. package/dist/telemetry/maestro-platform-replay-fixture.d.ts.map +1 -0
  796. package/dist/telemetry/maestro-platform-replay-fixture.js +400 -0
  797. package/dist/telemetry/maestro-platform-replay-fixture.js.map +1 -0
  798. package/dist/telemetry/maestro-publisher-conformance-fixture.d.ts +29 -0
  799. package/dist/telemetry/maestro-publisher-conformance-fixture.d.ts.map +1 -0
  800. package/dist/telemetry/maestro-publisher-conformance-fixture.js +240 -0
  801. package/dist/telemetry/maestro-publisher-conformance-fixture.js.map +1 -0
  802. package/dist/telemetry/meter-service-client.d.ts +0 -33
  803. package/dist/telemetry/meter-service-client.d.ts.map +1 -1
  804. package/dist/telemetry/meter-service-client.js +22 -50
  805. package/dist/telemetry/meter-service-client.js.map +1 -1
  806. package/dist/telemetry/turn-tracker.d.ts.map +1 -1
  807. package/dist/telemetry/turn-tracker.js +5 -5
  808. package/dist/telemetry/turn-tracker.js.map +1 -1
  809. package/dist/telemetry/wide-events.d.ts +8 -0
  810. package/dist/telemetry/wide-events.d.ts.map +1 -1
  811. package/dist/telemetry/wide-events.js +28 -0
  812. package/dist/telemetry/wide-events.js.map +1 -1
  813. package/dist/telemetry.d.ts +1 -1
  814. package/dist/telemetry.d.ts.map +1 -1
  815. package/dist/telemetry.js +14 -4
  816. package/dist/telemetry.js.map +1 -1
  817. package/dist/timeline/redaction.d.ts +5 -0
  818. package/dist/timeline/redaction.d.ts.map +1 -0
  819. package/dist/timeline/redaction.js +119 -0
  820. package/dist/timeline/redaction.js.map +1 -0
  821. package/dist/tools/ask-user.d.ts +26 -0
  822. package/dist/tools/ask-user.d.ts.map +1 -1
  823. package/dist/tools/ask-user.js +33 -1
  824. package/dist/tools/ask-user.js.map +1 -1
  825. package/dist/tools/background/task-types.d.ts +1 -1
  826. package/dist/tools/edit.d.ts +2 -0
  827. package/dist/tools/edit.d.ts.map +1 -1
  828. package/dist/tools/edit.js +27 -7
  829. package/dist/tools/edit.js.map +1 -1
  830. package/dist/tools/index.d.ts +9 -0
  831. package/dist/tools/index.d.ts.map +1 -1
  832. package/dist/tools/pipeline.d.ts.map +1 -1
  833. package/dist/tools/pipeline.js +16 -7
  834. package/dist/tools/pipeline.js.map +1 -1
  835. package/dist/tools/write.d.ts +2 -0
  836. package/dist/tools/write.d.ts.map +1 -1
  837. package/dist/tools/write.js +24 -6
  838. package/dist/tools/write.js.map +1 -1
  839. package/dist/tracking/cost-tracker.d.ts +15 -12
  840. package/dist/tracking/cost-tracker.d.ts.map +1 -1
  841. package/dist/tracking/cost-tracker.js +29 -40
  842. package/dist/tracking/cost-tracker.js.map +1 -1
  843. package/dist/utils/checkpoint-profiler.d.ts +29 -0
  844. package/dist/utils/checkpoint-profiler.d.ts.map +1 -0
  845. package/dist/utils/checkpoint-profiler.js +118 -0
  846. package/dist/utils/checkpoint-profiler.js.map +1 -0
  847. package/dist/utils/downstream-http.d.ts +21 -0
  848. package/dist/utils/downstream-http.d.ts.map +1 -0
  849. package/dist/utils/downstream-http.js +151 -0
  850. package/dist/utils/downstream-http.js.map +1 -0
  851. package/dist/utils/downstream.d.ts +18 -0
  852. package/dist/utils/downstream.d.ts.map +1 -0
  853. package/dist/utils/downstream.js +47 -0
  854. package/dist/utils/downstream.js.map +1 -0
  855. package/dist/utils/logger.d.ts +3 -1
  856. package/dist/utils/logger.d.ts.map +1 -1
  857. package/dist/utils/logger.js +12 -1
  858. package/dist/utils/logger.js.map +1 -1
  859. package/dist/utils/oauth-http.d.ts +8 -0
  860. package/dist/utils/oauth-http.d.ts.map +1 -0
  861. package/dist/utils/oauth-http.js +41 -0
  862. package/dist/utils/oauth-http.js.map +1 -0
  863. package/dist/utils/path-utils.d.ts +2 -0
  864. package/dist/utils/path-utils.d.ts.map +1 -0
  865. package/dist/utils/path-utils.js +12 -0
  866. package/dist/utils/path-utils.js.map +1 -0
  867. package/dist/utils/path-validation.d.ts +1 -1
  868. package/dist/utils/path-validation.d.ts.map +1 -1
  869. package/dist/utils/path-validation.js +3 -3
  870. package/dist/utils/path-validation.js.map +1 -1
  871. package/dist/version.json +2 -2
  872. package/dist/web-server.d.ts +7 -1
  873. package/dist/web-server.d.ts.map +1 -1
  874. package/dist/web-server.js +117 -15
  875. package/dist/web-server.js.map +1 -1
  876. package/dist/webhooks/delivery.d.ts.map +1 -1
  877. package/dist/webhooks/delivery.js +9 -12
  878. package/dist/webhooks/delivery.js.map +1 -1
  879. package/node_modules/@bufbuild/protobuf/dist/cjs/descriptors.d.ts +12 -5
  880. package/node_modules/@bufbuild/protobuf/dist/cjs/from-binary.js +7 -7
  881. package/node_modules/@bufbuild/protobuf/dist/cjs/from-json.d.ts +1 -1
  882. package/node_modules/@bufbuild/protobuf/dist/cjs/from-json.js +1 -1
  883. package/node_modules/@bufbuild/protobuf/dist/cjs/reflect/path.d.ts +1 -1
  884. package/node_modules/@bufbuild/protobuf/dist/cjs/registry.js +24 -1
  885. package/node_modules/@bufbuild/protobuf/dist/cjs/to-json.d.ts +1 -1
  886. package/node_modules/@bufbuild/protobuf/dist/cjs/to-json.js +9 -10
  887. package/node_modules/@bufbuild/protobuf/dist/cjs/types.d.ts +1 -1
  888. package/node_modules/@bufbuild/protobuf/dist/cjs/wire/binary-encoding.d.ts +9 -7
  889. package/node_modules/@bufbuild/protobuf/dist/cjs/wire/binary-encoding.js +18 -8
  890. package/node_modules/@bufbuild/protobuf/dist/cjs/wire/text-encoding.d.ts +4 -2
  891. package/node_modules/@bufbuild/protobuf/dist/cjs/wire/text-encoding.js +8 -1
  892. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/api_pb.d.ts +1 -1
  893. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +2 -2
  894. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +37 -23
  895. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.js +1 -1
  896. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.d.ts +32 -36
  897. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/go_features_pb.d.ts +65 -0
  898. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/go_features_pb.js +38 -2
  899. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.d.ts +5 -5
  900. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/gen/google/protobuf/type_pb.d.ts +3 -3
  901. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/wrappers.d.ts +10 -0
  902. package/node_modules/@bufbuild/protobuf/dist/cjs/wkt/wrappers.js +24 -0
  903. package/node_modules/@bufbuild/protobuf/dist/esm/descriptors.d.ts +12 -5
  904. package/node_modules/@bufbuild/protobuf/dist/esm/from-binary.js +7 -7
  905. package/node_modules/@bufbuild/protobuf/dist/esm/from-json.d.ts +1 -1
  906. package/node_modules/@bufbuild/protobuf/dist/esm/from-json.js +2 -2
  907. package/node_modules/@bufbuild/protobuf/dist/esm/reflect/path.d.ts +1 -1
  908. package/node_modules/@bufbuild/protobuf/dist/esm/registry.js +24 -1
  909. package/node_modules/@bufbuild/protobuf/dist/esm/to-json.d.ts +1 -1
  910. package/node_modules/@bufbuild/protobuf/dist/esm/to-json.js +10 -11
  911. package/node_modules/@bufbuild/protobuf/dist/esm/types.d.ts +1 -1
  912. package/node_modules/@bufbuild/protobuf/dist/esm/wire/binary-encoding.d.ts +9 -7
  913. package/node_modules/@bufbuild/protobuf/dist/esm/wire/binary-encoding.js +18 -8
  914. package/node_modules/@bufbuild/protobuf/dist/esm/wire/text-encoding.d.ts +4 -2
  915. package/node_modules/@bufbuild/protobuf/dist/esm/wire/text-encoding.js +8 -1
  916. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/api_pb.d.ts +1 -1
  917. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +2 -2
  918. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +37 -23
  919. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +1 -1
  920. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/field_mask_pb.d.ts +32 -36
  921. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/go_features_pb.d.ts +65 -0
  922. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/go_features_pb.js +37 -1
  923. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/timestamp_pb.d.ts +5 -5
  924. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/type_pb.d.ts +3 -3
  925. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/wrappers.d.ts +10 -0
  926. package/node_modules/@bufbuild/protobuf/dist/esm/wkt/wrappers.js +23 -0
  927. package/node_modules/@bufbuild/protobuf/package.json +1 -1
  928. package/node_modules/@evalops/contracts/dist/headless-protocol-schemas.generated.d.ts +305 -2
  929. package/node_modules/@evalops/contracts/dist/headless-protocol-schemas.generated.d.ts.map +1 -1
  930. package/node_modules/@evalops/contracts/dist/headless-protocol-schemas.generated.js +34 -4
  931. package/node_modules/@evalops/contracts/dist/headless-protocol-schemas.generated.js.map +1 -1
  932. package/node_modules/@evalops/contracts/dist/index.d.ts +88 -0
  933. package/node_modules/@evalops/contracts/dist/index.d.ts.map +1 -1
  934. package/node_modules/@evalops/contracts/dist/index.js +2 -0
  935. package/node_modules/@evalops/contracts/dist/index.js.map +1 -1
  936. package/node_modules/@evalops/contracts/dist/proto/maestro/v1/headless_pb.d.ts +77 -77
  937. package/node_modules/@evalops/contracts/dist/proto/maestro/v1/headless_pb.d.ts.map +1 -1
  938. package/node_modules/@evalops/contracts/dist/proto/maestro/v1/headless_pb.js +1 -1
  939. package/node_modules/@evalops/contracts/dist/proto/maestro/v1/headless_pb.js.map +1 -1
  940. package/node_modules/@evalops/contracts/dist/runtime-app-server.d.ts +182 -0
  941. package/node_modules/@evalops/contracts/dist/runtime-app-server.d.ts.map +1 -0
  942. package/node_modules/@evalops/contracts/dist/runtime-app-server.js +83 -0
  943. package/node_modules/@evalops/contracts/dist/runtime-app-server.js.map +1 -0
  944. package/node_modules/@evalops/contracts/dist/runtime-server-request.d.ts +133 -0
  945. package/node_modules/@evalops/contracts/dist/runtime-server-request.d.ts.map +1 -0
  946. package/node_modules/@evalops/contracts/dist/runtime-server-request.js +68 -0
  947. package/node_modules/@evalops/contracts/dist/runtime-server-request.js.map +1 -0
  948. package/node_modules/@evalops/contracts/dist/schemas.d.ts +178 -0
  949. package/node_modules/@evalops/contracts/dist/schemas.d.ts.map +1 -1
  950. package/node_modules/@evalops/contracts/dist/schemas.js +165 -0
  951. package/node_modules/@evalops/contracts/dist/schemas.js.map +1 -1
  952. package/node_modules/@evalops/contracts/dist/typebox-utils.d.ts +2 -0
  953. package/node_modules/@evalops/contracts/dist/typebox-utils.d.ts.map +1 -0
  954. package/node_modules/@evalops/contracts/dist/typebox-utils.js +5 -0
  955. package/node_modules/@evalops/contracts/dist/typebox-utils.js.map +1 -0
  956. package/node_modules/@evalops/contracts/dist/validators.d.ts +4 -1
  957. package/node_modules/@evalops/contracts/dist/validators.d.ts.map +1 -1
  958. package/node_modules/@evalops/contracts/dist/validators.js +4 -1
  959. package/node_modules/@evalops/contracts/dist/validators.js.map +1 -1
  960. package/node_modules/@evalops/contracts/package.json +1 -1
  961. package/node_modules/@evalops/tui/package.json +1 -1
  962. package/node_modules/string-width/index.js +93 -9
  963. package/node_modules/string-width/package.json +1 -1
  964. package/package.json +32 -25
  965. package/dist/cli-tui/commands/grouped/auth-commands.d.ts.map +0 -1
  966. package/dist/cli-tui/commands/grouped/auth-commands.js.map +0 -1
  967. package/dist/cli-tui/commands/grouped/config-commands.d.ts.map +0 -1
  968. package/dist/cli-tui/commands/grouped/config-commands.js.map +0 -1
  969. package/dist/cli-tui/commands/grouped/diag-commands.d.ts.map +0 -1
  970. package/dist/cli-tui/commands/grouped/diag-commands.js.map +0 -1
  971. package/dist/cli-tui/commands/grouped/git-commands.d.ts.map +0 -1
  972. package/dist/cli-tui/commands/grouped/git-commands.js.map +0 -1
  973. package/dist/cli-tui/commands/grouped/index.d.ts.map +0 -1
  974. package/dist/cli-tui/commands/grouped/index.js.map +0 -1
  975. package/dist/cli-tui/commands/grouped/safety-commands.d.ts.map +0 -1
  976. package/dist/cli-tui/commands/grouped/safety-commands.js.map +0 -1
  977. package/dist/cli-tui/commands/grouped/session-commands.d.ts.map +0 -1
  978. package/dist/cli-tui/commands/grouped/session-commands.js.map +0 -1
  979. package/dist/cli-tui/commands/grouped/tools-commands.d.ts.map +0 -1
  980. package/dist/cli-tui/commands/grouped/tools-commands.js.map +0 -1
  981. package/dist/cli-tui/commands/grouped/ui-commands.d.ts.map +0 -1
  982. package/dist/cli-tui/commands/grouped/ui-commands.js.map +0 -1
  983. package/dist/cli-tui/commands/grouped/undo-commands.d.ts.map +0 -1
  984. package/dist/cli-tui/commands/grouped/undo-commands.js.map +0 -1
  985. package/dist/cli-tui/commands/grouped/usage-commands.d.ts.map +0 -1
  986. package/dist/cli-tui/commands/grouped/usage-commands.js.map +0 -1
  987. package/dist/cli-tui/commands/grouped/utils.d.ts.map +0 -1
  988. package/dist/cli-tui/commands/grouped/utils.js.map +0 -1
  989. package/dist/cli-tui/commands/grouped-command-handlers.d.ts.map +0 -1
  990. package/dist/cli-tui/commands/grouped-command-handlers.js +0 -135
  991. package/dist/cli-tui/commands/grouped-command-handlers.js.map +0 -1
  992. package/dist/cli-tui/tui-renderer/grouped-handlers-wiring.d.ts +0 -78
  993. package/dist/cli-tui/tui-renderer/grouped-handlers-wiring.d.ts.map +0 -1
  994. package/dist/cli-tui/tui-renderer/grouped-handlers-wiring.js +0 -129
  995. package/dist/cli-tui/tui-renderer/grouped-handlers-wiring.js.map +0 -1
  996. package/node_modules/@evalops/memory/dist/client.d.ts +0 -94
  997. package/node_modules/@evalops/memory/dist/client.js +0 -503
  998. package/node_modules/@evalops/memory/gen/proto/dist/memory/v1/memory_pb.d.ts +0 -608
  999. package/node_modules/@evalops/memory/gen/proto/dist/memory/v1/memory_pb.js +0 -187
  1000. package/node_modules/@evalops/memory/package.json +0 -26
  1001. /package/dist/cli-tui/commands/{grouped → subcommands}/usage-commands.d.ts +0 -0
@@ -3,6 +3,12 @@
3
3
  */
4
4
  import { type IncomingMessage, type ServerResponse } from "node:http";
5
5
  import type { RegisteredModel } from "./models/registry.js";
6
+ import type { HostedRunnerContext } from "./server/app-context.js";
7
+ interface StartWebServerOptions {
8
+ host?: string;
9
+ hostedRunner?: HostedRunnerContext;
10
+ skipStartupMigration?: boolean;
11
+ }
6
12
  export { SseSession } from "./server/sse-session.js";
7
13
  export declare const __modelSelectionStore: {
8
14
  set: (model: RegisteredModel) => void;
@@ -12,5 +18,5 @@ export declare const __modelSelectionStore: {
12
18
  modelId: string;
13
19
  } | null;
14
20
  };
15
- export declare function startWebServer(port?: number): Promise<import("http").Server<typeof IncomingMessage, typeof ServerResponse>>;
21
+ export declare function startWebServer(port?: number, options?: StartWebServerOptions): Promise<import("http").Server<typeof IncomingMessage, typeof ServerResponse>>;
16
22
  //# sourceMappingURL=web-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-server.d.ts","sourceRoot":"","sources":["../src/web-server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,cAAc,EAEnB,MAAM,WAAW,CAAC;AAqCnB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA4G5D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAwLrD,eAAO,MAAM,qBAAqB;iBACpB,eAAe;;;kBAbT,MAAM;iBAAW,MAAM;;CAgB1C,CAAC;AAwXF,wBAAsB,cAAc,CAAC,IAAI,SAAO,iFAkM/C"}
1
+ {"version":3,"file":"web-server.d.ts","sourceRoot":"","sources":["../src/web-server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,cAAc,EAEnB,MAAM,WAAW,CAAC;AAqCnB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAe5D,OAAO,KAAK,EACX,mBAAmB,EAEnB,MAAM,yBAAyB,CAAC;AAqBjC,UAAU,qBAAqB;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,mBAAmB,CAAC;IACnC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAuFD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAiMrD,eAAO,MAAM,qBAAqB;iBACpB,eAAe;;;kBAbT,MAAM;iBAAW,MAAM;;CAgB1C,CAAC;AA6XF,wBAAsB,cAAc,CACnC,IAAI,SAAO,EACX,OAAO,GAAE,qBAA0B,iFAyRnC"}
@@ -26,6 +26,8 @@ import { getEnvVarsForProvider } from "./providers/api-keys.js";
26
26
  import { createAuthResolver, } from "./providers/auth.js";
27
27
  import { registerBackgroundTaskShutdownHooks } from "./runtime/background-task-hooks.js";
28
28
  import { configureSafeMode } from "./safety/safe-mode.js";
29
+ import { HostedRunnerDrainReasonValue, HostedRunnerDrainStatusValue, drainHostedRunnerForShutdown, } from "./server/handlers/hosted-runner-drain.js";
30
+ import { createWorkspaceConfigMiddleware } from "./services/workspace-config/middleware.js";
29
31
  import { recordApiRequest } from "./telemetry.js";
30
32
  import { artifactsClientTool } from "./tools/artifacts-client.js";
31
33
  import { askUserClientTool } from "./tools/ask-user-client.js";
@@ -61,10 +63,12 @@ const getDbModule = (() => {
61
63
  };
62
64
  })();
63
65
  import { WebActionApprovalService } from "./server/approval-service.js";
64
- import { checkApiAuth } from "./server/authz.js";
66
+ import { checkApiAuth, getAuthSubject } from "./server/authz.js";
65
67
  import { startAutomationScheduler } from "./server/automations/scheduler.js";
66
68
  import { clientToolService } from "./server/client-tools-service.js";
67
69
  import { handleChatWebSocket } from "./server/handlers/chat-ws.js";
70
+ import { handleRuntimeAppServerWebSocket } from "./server/handlers/runtime-app-server-ws.js";
71
+ import { sessionIdPattern, verifySessionOwnership, } from "./server/handlers/sessions.js";
68
72
  import { HeadlessRuntimeService } from "./server/headless-runtime-service.js";
69
73
  import { logError, logRequest, logStartup, startStatsCollection, stopStatsCollection, } from "./server/logger.js";
70
74
  import { compose } from "./server/middleware.js";
@@ -74,8 +78,10 @@ import { parseTraceParent, requestContextStorage, } from "./server/request-conte
74
78
  import { requestTracker } from "./server/request-tracker.js";
75
79
  import { createRequestHandler } from "./server/router.js";
76
80
  import { createRoutes } from "./server/routes.js";
81
+ import { authorizeRuntimeWebSocketSession } from "./server/runtime-ws-access.js";
77
82
  import { createAuthMiddleware, createCorsMiddleware, createCsrfMiddleware, createLoadSheddingMiddleware, createRouterMiddleware, createTieredRateLimitMiddleware, } from "./server/server-middlewares.js";
78
83
  import { ApiError, createCorsHeaders, sendJson, } from "./server/server-utils.js";
84
+ import { createWebSessionManagerForRequest } from "./server/session-scope.js";
79
85
  import { serveStatic } from "./server/static-server.js";
80
86
  import { resolveWebRoot } from "./server/web-root.js";
81
87
  // Re-export for existing test imports
@@ -97,6 +103,17 @@ function registerCrashHandlers() {
97
103
  process.exit(1);
98
104
  });
99
105
  }
106
+ async function validateRuntimeSessionAccess(req, sessionId) {
107
+ if (!sessionIdPattern.test(sessionId)) {
108
+ return false;
109
+ }
110
+ const sessionManager = createWebSessionManagerForRequest(req, false);
111
+ const session = await sessionManager.loadSession(sessionId);
112
+ if (!session) {
113
+ return false;
114
+ }
115
+ return verifySessionOwnership(session, getAuthSubject(req));
116
+ }
100
117
  function normalizeAuthMode(value) {
101
118
  const normalized = value?.trim().toLowerCase();
102
119
  if (normalized === "auto" ||
@@ -135,9 +152,6 @@ const STATIC_MAX_AGE = Number.parseInt(process.env.MAESTRO_STATIC_MAX_AGE ||
135
152
  const MAX_SSE_CONNECTIONS = Number.parseInt(process.env.MAESTRO_MAX_SSE_CONNECTIONS || "100", 10) || 100;
136
153
  const REQUEST_TIMEOUT_MS = Number.parseInt(process.env.MAESTRO_REQUEST_TIMEOUT_MS || "60000", 10) ||
137
154
  60000;
138
- if (process.env.CODEX_API_KEY) {
139
- logger.warn("CODEX_API_KEY detected but Codex subscriptions are not supported. The value will be ignored.");
140
- }
141
155
  // Harden defaults for hosted deployments.
142
156
  process.env.MAESTRO_WEB_SERVER = "1";
143
157
  if (!process.env.MAESTRO_SAFE_MODE)
@@ -262,6 +276,7 @@ function getCurrentSelection() {
262
276
  return { provider: DEFAULT_PROVIDER, modelId: DEFAULT_MODEL_ID };
263
277
  }
264
278
  async function createAgent(registeredModel, thinkingLevel = "off", approvalMode = DEFAULT_APPROVAL_MODE, options) {
279
+ const cwd = options?.cwd ?? process.cwd();
265
280
  const sessionTokenCounter = async (sessionId) => {
266
281
  try {
267
282
  const { isDatabaseConfigured } = await getDbModule();
@@ -291,6 +306,7 @@ async function createAgent(registeredModel, thinkingLevel = "off", approvalMode
291
306
  };
292
307
  const transport = new ProviderTransport({
293
308
  getAuthContext: async (provider) => authResolver(provider),
309
+ cwd,
294
310
  approvalService: options?.approvalService ?? new WebActionApprovalService(approvalMode),
295
311
  toolRetryService: options?.toolRetryService,
296
312
  clientToolService: options?.clientToolService ??
@@ -336,22 +352,22 @@ async function createAgent(registeredModel, thinkingLevel = "off", approvalMode
336
352
  new TodoContextSource(),
337
353
  new BackgroundTaskContextSource(),
338
354
  new CurrentDateContextSource(),
339
- new GitSnapshotContextSource(process.cwd()),
340
- new LspContextSource(),
355
+ new GitSnapshotContextSource(cwd),
356
+ new LspContextSource(cwd),
341
357
  new FrameworkPreferenceContextSource(),
342
- new TeamMemoryContextSource(process.cwd()),
358
+ new TeamMemoryContextSource(cwd),
343
359
  new IDEContextSource(),
344
360
  ],
345
361
  });
346
362
  // Initialize composer manager for this agent (enables sub-agents/composers)
347
- composerManager.initialize(agent, systemPrompt, tools, process.cwd());
363
+ composerManager.initialize(agent, systemPrompt, tools, cwd);
348
364
  return agent;
349
365
  }
350
366
  async function createBackgroundAgent(registeredModel, options) {
351
367
  return createBackgroundTextAgent({
352
368
  model: registeredModel,
353
369
  systemPrompt: options?.systemPrompt ?? getMemoryExtractionSystemPrompt(),
354
- cwd: process.cwd(),
370
+ cwd: options?.cwd ?? process.cwd(),
355
371
  getAuthContext: async (provider) => authResolver(provider),
356
372
  });
357
373
  }
@@ -489,6 +505,7 @@ async function handleRequest(req, res) {
489
505
  createCorsMiddleware(CORS_HEADERS),
490
506
  createAuthMiddleware(WEB_API_KEY, CORS_HEADERS, REQUIRE_WEB_API_KEY),
491
507
  createCsrfMiddleware(CSRF_TOKEN, CORS_HEADERS, REQUIRE_CSRF),
508
+ createWorkspaceConfigMiddleware(CORS_HEADERS),
492
509
  createRouterMiddleware(router),
493
510
  ]);
494
511
  try {
@@ -511,8 +528,18 @@ async function handleRequest(req, res) {
511
528
  }
512
529
  });
513
530
  }
514
- export async function startWebServer(port = 8080) {
531
+ export async function startWebServer(port = 8080, options = {}) {
532
+ if (options.hostedRunner) {
533
+ context.hostedRunner = options.hostedRunner;
534
+ }
515
535
  registerCrashHandlers();
536
+ if (!options.skipStartupMigration) {
537
+ const { migrate } = await import("./db/migrate.js");
538
+ const applied = await migrate();
539
+ if (applied > 0) {
540
+ logger.info("Startup database migrations completed", { count: applied });
541
+ }
542
+ }
516
543
  await reloadModelConfig();
517
544
  await initLifecycle();
518
545
  startAutomationScheduler(context);
@@ -594,7 +621,7 @@ export async function startWebServer(port = 8080) {
594
621
  });
595
622
  server.on("upgrade", async (req, socket, head) => {
596
623
  const url = new URL(req.url || "/", `http://${req.headers.host || "localhost"}`);
597
- if (url.pathname !== "/api/chat/ws") {
624
+ if (url.pathname !== "/api/chat/ws" && url.pathname !== "/api/runtime/ws") {
598
625
  socket.destroy();
599
626
  return;
600
627
  }
@@ -611,22 +638,91 @@ export async function startWebServer(port = 8080) {
611
638
  socket.destroy();
612
639
  return;
613
640
  }
641
+ let runtimeSessionId;
642
+ if (url.pathname === "/api/runtime/ws") {
643
+ const authorization = await authorizeRuntimeWebSocketSession({
644
+ req,
645
+ socket,
646
+ requestedSessionId: url.searchParams.get("sessionId"),
647
+ validateSessionAccess: validateRuntimeSessionAccess,
648
+ logAccessError: logError,
649
+ });
650
+ if (authorization === null) {
651
+ return;
652
+ }
653
+ runtimeSessionId = authorization;
654
+ }
614
655
  wsServer.handleUpgrade(req, socket, head, (ws) => {
656
+ if (url.pathname === "/api/runtime/ws") {
657
+ handleRuntimeAppServerWebSocket(ws, {
658
+ sessionId: runtimeSessionId,
659
+ validateSessionAccess: (sessionId) => validateRuntimeSessionAccess(req, sessionId),
660
+ });
661
+ return;
662
+ }
615
663
  handleChatWebSocket(ws, req, context);
616
664
  });
617
665
  });
618
- server.listen(port, () => {
666
+ const onListening = () => {
619
667
  logStartup(port);
668
+ if (context.hostedRunner) {
669
+ logger.info("Hosted runner mode enabled", {
670
+ runnerSessionId: context.hostedRunner.runnerSessionId,
671
+ workspaceRoot: context.hostedRunner.workspaceRoot,
672
+ snapshotRoot: context.hostedRunner.snapshotRoot,
673
+ workspaceId: context.hostedRunner.workspaceId,
674
+ agentRunId: context.hostedRunner.agentRunId,
675
+ listenHost: options.host,
676
+ listenPort: port,
677
+ });
678
+ }
620
679
  startStatsCollection();
621
- });
680
+ };
681
+ if (options.host) {
682
+ server.listen(port, options.host, onListening);
683
+ }
684
+ else {
685
+ server.listen(port, onListening);
686
+ }
622
687
  // Don't register signal handlers in test mode - vitest manages process lifecycle
623
688
  const isTestMode = process.env.VITEST === "true" || process.env.NODE_ENV === "test";
624
689
  if (!isTestMode) {
625
- process.on("SIGINT", async () => {
690
+ const beginShutdown = async (signal) => {
626
691
  if (shuttingDown)
627
692
  return;
628
693
  shuttingDown = true;
629
- logger.info("SIGINT received. Starting graceful shutdown...");
694
+ if (context.hostedRunner) {
695
+ if (context.hostedRunner.draining) {
696
+ logger.info("Hosted runner already draining before shutdown", {
697
+ runnerSessionId: context.hostedRunner.runnerSessionId,
698
+ });
699
+ }
700
+ else {
701
+ try {
702
+ const drainResult = await drainHostedRunnerForShutdown(context, {
703
+ reason: HostedRunnerDrainReasonValue.ProcessShutdown,
704
+ });
705
+ if (drainResult) {
706
+ const log = drainResult.status === HostedRunnerDrainStatusValue.Interrupted
707
+ ? logger.warn.bind(logger)
708
+ : logger.info.bind(logger);
709
+ log("Hosted runner drained during graceful shutdown", {
710
+ runnerSessionId: drainResult.runner_session_id,
711
+ status: drainResult.status,
712
+ manifestPath: drainResult.manifest_path,
713
+ });
714
+ }
715
+ }
716
+ catch (error) {
717
+ context.hostedRunner.draining = true;
718
+ logger.warn("Hosted runner shutdown drain failed", {
719
+ runnerSessionId: context.hostedRunner.runnerSessionId,
720
+ error: error instanceof Error ? error.message : String(error),
721
+ });
722
+ }
723
+ }
724
+ }
725
+ logger.info(`${signal} received. Starting graceful shutdown...`);
630
726
  stopStatsCollection();
631
727
  disposeCheckpointService();
632
728
  // End enterprise session if initialized
@@ -666,6 +762,12 @@ export async function startWebServer(port = 8080) {
666
762
  logger.info("No active requests. Exiting.");
667
763
  process.exit(0);
668
764
  }
765
+ };
766
+ process.on("SIGINT", () => {
767
+ void beginShutdown("SIGINT");
768
+ });
769
+ process.on("SIGTERM", () => {
770
+ void beginShutdown("SIGTERM");
669
771
  });
670
772
  }
671
773
  return server;
@@ -1 +1 @@
1
- {"version":3,"file":"web-server.js","sourceRoot":"","sources":["../src/web-server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAGN,YAAY,GACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAKrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EACN,2BAA2B,EAC3B,wBAAwB,EACxB,gCAAgC,EAChC,wBAAwB,EACxB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,OAAO,EACN,wBAAwB,EACxB,qBAAqB,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,+BAA+B,EAAE,MAAM,6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es, randomUUID } from \"node:crypto\";\nimport {\n\ttype IncomingMessage,\n\ttype ServerResponse,\n\tcreateServer,\n} from \"node:http\";\nimport type { Socket } from \"node:net\";\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath, parse } from \"node:url\";\nimport { WebSocketServer } from \"ws\";\nimport type {\n\tActionApprovalService,\n\tApprovalMode,\n} from \"./agent/action-approval.js\";\nimport { createBackgroundTextAgent } from \"./agent/background-agent.js\";\nimport {\n\tBackgroundTaskContextSource,\n\tCurrentDateContextSource,\n\tFrameworkPreferenceContextSource,\n\tGitSnapshotContextSource,\n\tIDEContextSource,\n\tLspContextSource,\n\tTeamMemoryContextSource,\n\tTodoContextSource,\n} from \"./agent/context-providers.js\";\nimport { Agent, ProviderTransport } from \"./agent/index.js\";\nimport type { ToolRetryService } from \"./agent/tool-retry.js\";\nimport type { ClientToolExecutionService } from \"./agent/transport.js\";\nimport type { AgentTool, ThinkingLevel } from \"./agent/types.js\";\nimport {\n\tdisposeCheckpointService,\n\tinitCheckpointService,\n} from \"./checkpoints/index.js\";\nimport { composerManager } from \"./composers/index.js\";\nimport { resolveDefaultApprovalMode } from \"./config/default-approval-mode.js\";\nimport { initLifecycle, shutdownLifecycle } from \"./lifecycle.js\";\nimport { loadEnv } from \"./load-env.js\";\nimport { bootstrapLsp } from \"./lsp/bootstrap.js\";\nimport { loadMcpConfig, mcpManager } from \"./mcp/index.js\";\nimport { prefetchOfficialMcpRegistry } from \"./mcp/official-registry.js\";\nimport { getAllMcpTools } from \"./mcp/tool-bridge.js\";\nimport { getMemoryExtractionSystemPrompt } from \"./memory/auto-extraction.js\";\nimport type { RegisteredModel } from \"./models/registry.js\";\nimport {\n\tgetFactoryDefaultModelSelection,\n\treloadModelConfig,\n} from \"./models/registry.js\";\nimport { initOpenTelemetry } from \"./opentelemetry.js\";\nimport { resolveMaestroSystemPrompt } from \"./prompts/system-prompt.js\";\nimport { getEnvVarsForProvider } from \"./providers/api-keys.js\";\nimport {\n\ttype AuthCredential,\n\ttype AuthMode,\n\tcreateAuthResolver,\n} from \"./providers/auth.js\";\nimport { registerBackgroundTaskShutdownHooks } from \"./runtime/background-task-hooks.js\";\nimport { configureSafeMode } from \"./safety/safe-mode.js\";\nimport type { WebServerContext } from \"./server/app-context.js\";\nimport { recordApiRequest } from \"./telemetry.js\";\nimport { artifactsClientTool } from \"./tools/artifacts-client.js\";\nimport { askUserClientTool } from \"./tools/ask-user-client.js\";\nimport {\n\tcodingTools,\n\tconductorClientTools,\n\tjetbrainsTools,\n\tvscodeTools,\n} from \"./tools/index.js\";\nimport { javascriptReplClientTool } from \"./tools/javascript-repl-client.js\";\nimport { createLogger } from \"./utils/logger.js\";\n\nconst logger = createLogger(\"web-server\");\n\nconst getAuditModule = (() => {\n\tlet promise: Promise<\n\t\ttypeof import(\"./enterprise/audit-integration.js\")\n\t> | null = null;\n\treturn () => {\n\t\tif (!promise) {\n\t\t\tpromise = import(\"./enterprise/audit-integration.js\");\n\t\t}\n\t\treturn promise;\n\t};\n})();\n\nconst getBillingModule = (() => {\n\tlet promise: Promise<typeof import(\"./billing/token-tracker.js\")> | null =\n\t\tnull;\n\treturn () => {\n\t\tif (!promise) {\n\t\t\tpromise = import(\"./billing/token-tracker.js\");\n\t\t}\n\t\treturn promise;\n\t};\n})();\n\nconst getDbModule = (() => {\n\tlet promise: Promise<typeof import(\"./db/client.js\")> | null = null;\n\treturn () => {\n\t\tif (!promise) {\n\t\t\tpromise = import(\"./db/client.js\");\n\t\t}\n\t\treturn promise;\n\t};\n})();\nimport { WebActionApprovalService } from \"./server/approval-service.js\";\nimport { checkApiAuth } from \"./server/authz.js\";\nimport { startAutomationScheduler } from \"./server/automations/scheduler.js\";\nimport { clientToolService } from \"./server/client-tools-service.js\";\nimport { handleChatWebSocket } from \"./server/handlers/chat-ws.js\";\nimport { HeadlessRuntimeService } from \"./server/headless-runtime-service.js\";\nimport {\n\tisOverloaded,\n\tlogError,\n\tlogRequest,\n\tlogStartup,\n\tstartStatsCollection,\n\tstopStatsCollection,\n} from \"./server/logger.js\";\nimport { compose } from \"./server/middleware.js\";\nimport {\n\tdetermineModelSelection,\n\tgetRegisteredModelOrThrow,\n} from \"./server/model-selection.js\";\nimport { TieredRateLimiter } from \"./server/rate-limiter.js\";\nimport {\n\ttype RequestContext,\n\tparseTraceParent,\n\trequestContextStorage,\n} from \"./server/request-context.js\";\nimport { requestTracker } from \"./server/request-tracker.js\";\nimport { createRequestHandler } from \"./server/router.js\";\nimport { createRoutes } from \"./server/routes.js\";\nimport {\n\tcreateAuthMiddleware,\n\tcreateCorsMiddleware,\n\tcreateCsrfMiddleware,\n\tcreateLoadSheddingMiddleware,\n\tcreateRouterMiddleware,\n\tcreateTieredRateLimitMiddleware,\n} from \"./server/server-middlewares.js\";\nimport {\n\tApiError,\n\tauthenticateRequest,\n\tcreateCorsHeaders,\n\tsendJson,\n} from \"./server/server-utils.js\";\nimport { serveStatic } from \"./server/static-server.js\";\nimport { resolveWebRoot } from \"./server/web-root.js\";\n\n// Re-export for existing test imports\nexport { SseSession } from \"./server/sse-session.js\";\n\nloadEnv();\nvoid initOpenTelemetry(\"composer-web-server\");\n\n// Global crash handlers\nfunction registerCrashHandlers() {\n\tprocess.on(\"uncaughtException\", (error) => {\n\t\tlogError(error);\n\t\tlogger.error(\"FATAL: Uncaught Exception. Exiting...\");\n\t\tprocess.exit(1);\n\t});\n\n\tprocess.on(\"unhandledRejection\", (reason) => {\n\t\tlogError(\n\t\t\treason instanceof Error\n\t\t\t\t? reason\n\t\t\t\t: new Error(`Unhandled Rejection: ${String(reason)}`),\n\t\t);\n\t\tlogger.error(\"FATAL: Unhandled Rejection. Exiting...\");\n\t\tprocess.exit(1);\n\t});\n}\n\nfunction normalizeAuthMode(value?: string | null): AuthMode {\n\tconst normalized = value?.trim().toLowerCase();\n\tif (\n\t\tnormalized === \"auto\" ||\n\t\tnormalized === \"api-key\" ||\n\t\tnormalized === \"claude\"\n\t) {\n\t\treturn normalized;\n\t}\n\treturn \"auto\";\n}\n\nconst PROFILE = (\n\tprocess.env.MAESTRO_PROFILE ||\n\tprocess.env.MAESTRO_WEB_PROFILE ||\n\t\"\"\n)\n\t.trim()\n\t.toLowerCase();\nconst PROD_PROFILE =\n\tPROFILE === \"prod\" ||\n\tPROFILE === \"production\" ||\n\tPROFILE === \"secure\" ||\n\tPROFILE === \"hardened\";\n\nconst DEFAULT_APPROVAL_MODE = resolveDefaultApprovalMode({\n\tprofile: PROFILE,\n\texplicitApprovalMode: process.env.MAESTRO_APPROVAL_MODE,\n});\nconst AUTH_MODE = normalizeAuthMode(process.env.MAESTRO_AUTH_MODE);\nconst WEB_API_KEY = process.env.MAESTRO_WEB_API_KEY?.trim() || null;\nconst requireKeyEnv = process.env.MAESTRO_WEB_REQUIRE_KEY;\nconst requireRedisEnv = process.env.MAESTRO_WEB_REQUIRE_REDIS;\nconst CSRF_TOKEN = process.env.MAESTRO_WEB_CSRF_TOKEN?.trim() || null;\nconst REQUIRE_CSRF =\n\t(PROD_PROFILE && process.env.MAESTRO_WEB_REQUIRE_CSRF !== \"0\") ||\n\tBoolean(process.env.MAESTRO_WEB_CSRF_TOKEN);\n// Default: require in normal runtime, but don't break tests unless explicitly opted in.\nconst REQUIRE_WEB_API_KEY =\n\t(requireKeyEnv ?? (process.env.NODE_ENV === \"test\" ? \"0\" : \"1\")) !== \"0\";\nconst REQUIRE_REDIS =\n\t(requireRedisEnv ?? (process.env.NODE_ENV === \"test\" ? \"0\" : \"1\")) !== \"0\";\nconst DEFAULT_WEB_ORIGIN =\n\tprocess.env.MAESTRO_WEB_ORIGIN?.trim() || \"http://localhost:4173\";\nconst STATIC_MAX_AGE =\n\tNumber.parseInt(\n\t\tprocess.env.MAESTRO_STATIC_MAX_AGE ||\n\t\t\t(process.env.NODE_ENV === \"production\" ? \"86400\" : \"60\"),\n\t\t10,\n\t) || 60;\nconst MAX_SSE_CONNECTIONS =\n\tNumber.parseInt(process.env.MAESTRO_MAX_SSE_CONNECTIONS || \"100\", 10) || 100;\nconst REQUEST_TIMEOUT_MS =\n\tNumber.parseInt(process.env.MAESTRO_REQUEST_TIMEOUT_MS || \"60000\", 10) ||\n\t60000;\n\nif (process.env.CODEX_API_KEY) {\n\tlogger.warn(\n\t\t\"CODEX_API_KEY detected but Codex subscriptions are not supported. The value will be ignored.\",\n\t);\n}\n\n// Harden defaults for hosted deployments.\nprocess.env.MAESTRO_WEB_SERVER = \"1\";\nif (!process.env.MAESTRO_SAFE_MODE) process.env.MAESTRO_SAFE_MODE = \"1\";\nif (!process.env.MAESTRO_SAFE_REQUIRE_PLAN)\n\tprocess.env.MAESTRO_SAFE_REQUIRE_PLAN = \"1\";\nif (PROD_PROFILE && !process.env.MAESTRO_FAIL_UNTAGGED_EGRESS) {\n\tprocess.env.MAESTRO_FAIL_UNTAGGED_EGRESS = \"1\";\n}\nif (PROD_PROFILE && !process.env.MAESTRO_BACKGROUND_SHELL_DISABLE) {\n\tprocess.env.MAESTRO_BACKGROUND_SHELL_DISABLE = \"1\";\n}\nif (REQUIRE_CSRF && !CSRF_TOKEN) {\n\tthrow new Error(\n\t\t\"MAESTRO_WEB_CSRF_TOKEN is required when CSRF enforcement is enabled (MAESTRO_PROFILE=prod or MAESTRO_WEB_REQUIRE_CSRF=1).\",\n\t);\n}\n\n// Parse and validate TRUST_PROXY setting\n// WARNING: Only enable if behind a trusted reverse proxy that sets X-Forwarded-For\nconst trustProxyEnv = process.env.MAESTRO_TRUST_PROXY?.toLowerCase();\nconst TRUST_PROXY = trustProxyEnv === \"true\";\n\n// Number of trusted proxy hops (default 1). Use this to extract the correct client IP\n// when behind multiple proxies (e.g., CDN -> nginx -> app). The IP is read from the\n// right side of X-Forwarded-For, skipping this many trusted proxy IPs.\nconst rawProxyHops = Number.parseInt(\n\tprocess.env.MAESTRO_TRUST_PROXY_HOPS || \"1\",\n\t10,\n);\nconst TRUST_PROXY_HOPS =\n\tNumber.isNaN(rawProxyHops) || rawProxyHops < 1 ? 1 : rawProxyHops;\n\nif (\n\tprocess.env.MAESTRO_TRUST_PROXY_HOPS &&\n\t(Number.isNaN(rawProxyHops) || rawProxyHops < 1)\n) {\n\tlogger.warn(\n\t\t\"Invalid MAESTRO_TRUST_PROXY_HOPS value. Must be a positive integer. Defaulting to 1.\",\n\t\t{ value: process.env.MAESTRO_TRUST_PROXY_HOPS },\n\t);\n}\n\nif (trustProxyEnv && trustProxyEnv !== \"true\" && trustProxyEnv !== \"false\") {\n\tlogger.warn(\n\t\t\"Invalid MAESTRO_TRUST_PROXY value. Must be 'true' or 'false'. Defaulting to false.\",\n\t\t{ value: process.env.MAESTRO_TRUST_PROXY },\n\t);\n}\n\nif (TRUST_PROXY) {\n\tlogger.warn(\n\t\t\"MAESTRO_TRUST_PROXY is enabled. Ensure this server is behind a trusted reverse proxy.\",\n\t);\n}\n\nconst sseLimiter = {\n\tactive: 0,\n\tmax: MAX_SSE_CONNECTIONS,\n\ttryAcquire(): symbol | null {\n\t\tif (this.active >= this.max) return null;\n\t\tthis.active += 1;\n\t\treturn Symbol(\"sse-lease\");\n\t},\n\trelease(token: symbol | null) {\n\t\tif (!token) return;\n\t\tif (this.active > 0) this.active -= 1;\n\t},\n};\n\nconst authResolver = createAuthResolver({\n\tmode: AUTH_MODE,\n});\n\nconst DEFAULT_PROVIDER = \"anthropic\";\nconst DEFAULT_MODEL_ID = \"claude-sonnet-4-5\";\n\n/**\n * Process-local selection store (keeps last chosen model for convenience only).\n * This avoids cross-request mutations elsewhere and can be replaced with\n * per-session selection later without blocking concurrent requests.\n */\nconst modelSelectionStore = {\n\tcurrentKey: null as string | null,\n\tset(model: RegisteredModel) {\n\t\tthis.currentKey = `${model.provider}/${model.id}`;\n\t},\n\tget(): { provider: string; modelId: string } | null {\n\t\tif (!this.currentKey) return null;\n\t\tconst [provider, ...modelParts] = this.currentKey.split(\"/\");\n\t\tconst modelId = modelParts.join(\"/\");\n\t\treturn provider && modelId ? { provider, modelId } : null;\n\t},\n\treset() {\n\t\tthis.currentKey = null;\n\t},\n};\n\n// Exposed for testing/internal use only\nexport const __modelSelectionStore = {\n\tset: (model: RegisteredModel) => modelSelectionStore.set(model),\n\treset: () => modelSelectionStore.reset(),\n\tget: () => modelSelectionStore.get(),\n};\n\nfunction logMissingCredentialHints(provider: string): void {\n\tconst envVars = getEnvVarsForProvider(provider);\n\tconst hints: string[] = [`Missing credentials for provider \"${provider}\".`];\n\tif (envVars.length > 0) {\n\t\thints.push(\n\t\t\t`Populate ${envVars.join(\" or \")} or configure a custom provider secret before retrying.`,\n\t\t);\n\t}\n\tif (provider === \"anthropic\") {\n\t\thints.push(\"Run `maestro anthropic login` to provision OAuth credentials.\");\n\t} else if (provider === \"openai\") {\n\t\thints.push(\"Set OPENAI_API_KEY or run `maestro openai login`.\");\n\t}\n\tlogger.warn(hints.join(\" \"), { provider });\n}\n\nfunction buildMissingCredentialMessage(provider: string): string {\n\tlogMissingCredentialHints(provider);\n\treturn `Credentials are required for provider \"${provider}\".`;\n}\n\nasync function ensureCredential(provider: string): Promise<AuthCredential> {\n\tconst credential = await authResolver(provider);\n\tif (credential) {\n\t\treturn credential;\n\t}\n\tthrow new ApiError(401, buildMissingCredentialMessage(provider));\n}\n\nasync function getRegisteredModel(input: string | null | undefined) {\n\tconst selection = determineModelSelection(\n\t\tinput,\n\t\tDEFAULT_PROVIDER,\n\t\tDEFAULT_MODEL_ID,\n\t);\n\tconst registeredModel = getRegisteredModelOrThrow(selection);\n\tawait ensureCredential(registeredModel.provider);\n\tmodelSelectionStore.set(registeredModel);\n\treturn registeredModel;\n}\n\nfunction getCurrentSelection(): { provider: string; modelId: string } {\n\tconst stored = modelSelectionStore.get();\n\tif (stored) return stored;\n\tconst factoryDefault = getFactoryDefaultModelSelection();\n\tif (factoryDefault) return factoryDefault;\n\treturn { provider: DEFAULT_PROVIDER, modelId: DEFAULT_MODEL_ID };\n}\n\nasync function createAgent(\n\tregisteredModel: RegisteredModel,\n\tthinkingLevel: ThinkingLevel = \"off\",\n\tapprovalMode: ApprovalMode = DEFAULT_APPROVAL_MODE,\n\toptions?: {\n\t\tenableClientTools?: boolean;\n\t\tuseClientAskUser?: boolean;\n\t\tincludeVscodeTools?: boolean;\n\t\tincludeJetBrainsTools?: boolean;\n\t\tincludeConductorTools?: boolean;\n\t\tapprovalService?: ActionApprovalService;\n\t\tclientToolService?: ClientToolExecutionService;\n\t\ttoolRetryService?: ToolRetryService;\n\t},\n): Promise<Agent> {\n\tconst sessionTokenCounter = async (sessionId: string) => {\n\t\ttry {\n\t\t\tconst { isDatabaseConfigured } = await getDbModule();\n\t\t\tif (!isDatabaseConfigured()) return null;\n\t\t\tconst { getSessionTokenCount } = await getBillingModule();\n\t\t\treturn await getSessionTokenCount(sessionId);\n\t\t} catch (error) {\n\t\t\tlogger.warn(\"Failed to get session token count\", {\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t\treturn null;\n\t\t}\n\t};\n\n\tconst auditLogger = async (entry: {\n\t\ttoolName: string;\n\t\targs: Record<string, unknown>;\n\t\tstatus: \"success\" | \"failure\" | \"denied\";\n\t\tdurationMs: number;\n\t\terror?: string;\n\t}) => {\n\t\ttry {\n\t\t\tconst { logSensitiveToolExecution } = await getAuditModule();\n\t\t\tawait logSensitiveToolExecution(\n\t\t\t\tentry.toolName,\n\t\t\t\tentry.args,\n\t\t\t\tentry.status,\n\t\t\t\tentry.durationMs,\n\t\t\t\tentry.error,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlogger.warn(\"Failed to log tool execution\", {\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\ttoolName: entry.toolName,\n\t\t\t});\n\t\t}\n\t};\n\n\tconst transport = new ProviderTransport({\n\t\tgetAuthContext: async (provider: string) => authResolver(provider),\n\t\tapprovalService:\n\t\t\toptions?.approvalService ?? new WebActionApprovalService(approvalMode),\n\t\ttoolRetryService: options?.toolRetryService,\n\t\tclientToolService:\n\t\t\toptions?.clientToolService ??\n\t\t\t(options?.enableClientTools || options?.useClientAskUser\n\t\t\t\t? clientToolService\n\t\t\t\t: undefined),\n\t\tsessionTokenCounter,\n\t\tauditLogger,\n\t});\n\n\tconst { systemPrompt, promptMetadata } = await resolveMaestroSystemPrompt();\n\n\t// Only include IDE client tools when a compatible client is connected.\n\t// Without a connected client, these tools will hang waiting for responses.\n\tconst mcpTools = getAllMcpTools();\n\tconst baseTools = options?.useClientAskUser\n\t\t? codingTools.map((tool) =>\n\t\t\t\ttool.name === \"ask_user\" ? askUserClientTool : tool,\n\t\t\t)\n\t\t: codingTools;\n\tconst tools: AgentTool[] = [...baseTools, ...mcpTools];\n\tif (options?.includeVscodeTools) {\n\t\ttools.push(...vscodeTools);\n\t}\n\tif (options?.includeJetBrainsTools) {\n\t\ttools.push(...jetbrainsTools);\n\t}\n\tif (options?.enableClientTools) {\n\t\ttools.push(artifactsClientTool);\n\t\ttools.push(javascriptReplClientTool);\n\t\tif (options?.includeConductorTools) {\n\t\t\ttools.push(...conductorClientTools);\n\t\t}\n\t}\n\n\tconst agent = new Agent({\n\t\ttransport,\n\t\tinitialState: {\n\t\t\tsystemPrompt,\n\t\t\tpromptMetadata,\n\t\t\tmodel: registeredModel,\n\t\t\tthinkingLevel,\n\t\t\ttools,\n\t\t\tsandboxMode: process.env.MAESTRO_SANDBOX ?? null,\n\t\t\tsandboxEnabled: Boolean(process.env.MAESTRO_SANDBOX),\n\t\t},\n\t\tcontextSources: [\n\t\t\tnew TodoContextSource(),\n\t\t\tnew BackgroundTaskContextSource(),\n\t\t\tnew CurrentDateContextSource(),\n\t\t\tnew GitSnapshotContextSource(process.cwd()),\n\t\t\tnew LspContextSource(),\n\t\t\tnew FrameworkPreferenceContextSource(),\n\t\t\tnew TeamMemoryContextSource(process.cwd()),\n\t\t\tnew IDEContextSource(),\n\t\t],\n\t});\n\n\t// Initialize composer manager for this agent (enables sub-agents/composers)\n\tcomposerManager.initialize(agent, systemPrompt, tools, process.cwd());\n\n\treturn agent;\n}\n\nasync function createBackgroundAgent(\n\tregisteredModel: RegisteredModel,\n\toptions?: {\n\t\tsystemPrompt?: string;\n\t},\n): Promise<Agent> {\n\treturn createBackgroundTextAgent({\n\t\tmodel: registeredModel,\n\t\tsystemPrompt: options?.systemPrompt ?? getMemoryExtractionSystemPrompt(),\n\t\tcwd: process.cwd(),\n\t\tgetAuthContext: async (provider: string) => authResolver(provider),\n\t});\n}\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst WEB_ROOT = resolveWebRoot({ baseDir: __dirname });\nconst ALLOWED_ORIGIN = DEFAULT_WEB_ORIGIN;\nconst CORS_HEADERS = createCorsHeaders(ALLOWED_ORIGIN);\nconst SECURITY_HEADERS: Record<string, string> =\n\tPROD_PROFILE || process.env.MAESTRO_WEB_CSP?.trim()\n\t\t? {\n\t\t\t\t\"Content-Security-Policy\":\n\t\t\t\t\tprocess.env.MAESTRO_WEB_CSP ||\n\t\t\t\t\t[\n\t\t\t\t\t\t\"default-src 'none'\",\n\t\t\t\t\t\t`connect-src 'self' ${ALLOWED_ORIGIN}`,\n\t\t\t\t\t\t\"img-src 'self' data:\",\n\t\t\t\t\t\t\"style-src 'self' 'unsafe-inline'\",\n\t\t\t\t\t\t\"script-src 'self'\",\n\t\t\t\t\t\t\"font-src 'self' data:\",\n\t\t\t\t\t\t\"frame-ancestors 'none'\",\n\t\t\t\t\t\t\"base-uri 'self'\",\n\t\t\t\t\t\t\"form-action 'self'\",\n\t\t\t\t\t].join(\"; \"),\n\t\t\t\t\"Referrer-Policy\": \"no-referrer\",\n\t\t\t\t\"X-Content-Type-Options\": \"nosniff\",\n\t\t\t\t\"Permissions-Policy\": \"geolocation=(), microphone=(self), camera=()\",\n\t\t\t}\n\t\t: {};\n\nconst headlessRuntimeService = new HeadlessRuntimeService();\n\nconst context: WebServerContext = {\n\tcorsHeaders: CORS_HEADERS,\n\tstaticMaxAge: STATIC_MAX_AGE,\n\tdefaultApprovalMode: DEFAULT_APPROVAL_MODE,\n\tdefaultProvider: DEFAULT_PROVIDER,\n\tdefaultModelId: DEFAULT_MODEL_ID,\n\tcreateAgent,\n\tcreateBackgroundAgent,\n\tgetRegisteredModel,\n\tgetCurrentSelection,\n\tensureCredential,\n\tsetModelSelection: (model) => modelSelectionStore.set(model),\n\tacquireSse: () => sseLimiter.tryAcquire(),\n\treleaseSse: (token) => sseLimiter.release(token),\n\theadlessRuntimeService,\n};\n\nconst routes = createRoutes(context);\n\nconst router = createRequestHandler(\n\troutes,\n\t(req, res, pathname) => {\n\t\tif (pathname.startsWith(\"/api\")) {\n\t\t\tsendJson(res, 404, { error: \"Not found\" }, CORS_HEADERS, req);\n\t\t\treturn;\n\t\t}\n\t\tserveStatic(pathname, req, res, {\n\t\t\twebRoot: WEB_ROOT,\n\t\t\tcorsHeaders: CORS_HEADERS,\n\t\t\tmaxAgeSeconds: STATIC_MAX_AGE,\n\t\t\tsecurityHeaders: SECURITY_HEADERS,\n\t\t\tspaFallback: true,\n\t\t});\n\t},\n\tCORS_HEADERS,\n);\n\n// Active request tracking for graceful shutdown and debugging\n// Tiered rate limiter with per-endpoint limits\n// Global: 1000/min, with stricter limits for expensive endpoints\nconst rateLimiter = new TieredRateLimiter();\n\nasync function handleRequest(req: IncomingMessage, res: ServerResponse) {\n\tconst start = performance.now();\n\tconst parsedUrl = parse(req.url || \"/\", true);\n\tconst pathname = parsedUrl.pathname || \"/\";\n\tconst requestId = randomUUID();\n\n\t// Parse W3C Trace Context\n\t// traceparent: 00-traceid-spanid-flags\n\tconst traceParent = req.headers.traceparent as string | undefined;\n\tconst { traceId, parentSpanId } = parseTraceParent(traceParent);\n\tconst spanId = randomBytes(8).toString(\"hex\"); // New span for this service\n\tconst responseTraceParent = `00-${traceId}-${spanId}-01`;\n\tres.setHeader(\"traceparent\", responseTraceParent);\n\tres.setHeader(\"server-timing\", `traceparent;desc=\"${responseTraceParent}\"`);\n\n\t// Attach request to response for easy access in helpers\n\t(res as ServerResponse & { req?: IncomingMessage }).req = req;\n\n\tconst context: RequestContext = {\n\t\trequestId,\n\t\ttraceId,\n\t\tspanId,\n\t\tstartTime: start,\n\t\tmethod: req.method || \"GET\",\n\t\turl: pathname,\n\t};\n\n\t// Set a hard timeout for processing\n\t// Skip for SSE endpoints which are meant to be long-lived\n\tif (!pathname.startsWith(\"/api/chat\")) {\n\t\tconst timeout = setTimeout(() => {\n\t\t\tif (!res.headersSent && !res.writableEnded) {\n\t\t\t\trequestContextStorage.run(context, () => {\n\t\t\t\t\tlogError(`Request timeout for ${pathname} [${requestId}]`);\n\t\t\t\t\tconst duration = performance.now() - start;\n\t\t\t\t\trecordApiRequest(req.method || \"UNKNOWN\", pathname, 504, duration, {\n\t\t\t\t\t\trequestId,\n\t\t\t\t\t\ttraceId,\n\t\t\t\t\t\tspanId,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tres.writeHead(504, {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t...CORS_HEADERS,\n\t\t\t\t});\n\t\t\t\tres.end(JSON.stringify({ error: \"Gateway Timeout\" }));\n\t\t\t}\n\t\t}, REQUEST_TIMEOUT_MS);\n\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timeout);\n\t\t};\n\n\t\tres.on(\"finish\", cleanup);\n\t\tres.on(\"close\", cleanup);\n\t}\n\n\t// Track request for introspection (Channelz) and graceful shutdown\n\trequestTracker.track(req, {\n\t\tid: requestId,\n\t\tmethod: req.method || \"GET\",\n\t\turl: pathname,\n\t\tstartTime: start,\n\t\tuserAgent: req.headers[\"user-agent\"],\n\t});\n\n\tres.on(\"close\", () => {\n\t\trequestTracker.untrack(req);\n\t});\n\n\t// Await the context storage run to prevent unhandled promise rejections\n\tawait requestContextStorage.run(context, async () => {\n\t\t// Setup logging listener inside context to capture trace/span IDs in closure\n\t\tres.on(\"finish\", () => {\n\t\t\tconst duration = performance.now() - start;\n\t\t\tlogRequest(req, res.statusCode, start);\n\t\t\trecordApiRequest(\n\t\t\t\treq.method || \"UNKNOWN\",\n\t\t\t\tpathname,\n\t\t\t\tres.statusCode,\n\t\t\t\tduration,\n\t\t\t\t{ requestId, traceId, spanId },\n\t\t\t);\n\t\t});\n\n\t\tconst app = compose([\n\t\t\tcreateLoadSheddingMiddleware(CORS_HEADERS),\n\t\t\tcreateTieredRateLimitMiddleware(\n\t\t\t\trateLimiter,\n\t\t\t\tCORS_HEADERS,\n\t\t\t\tTRUST_PROXY,\n\t\t\t\tTRUST_PROXY_HOPS,\n\t\t\t),\n\t\t\tcreateCorsMiddleware(CORS_HEADERS),\n\t\t\tcreateAuthMiddleware(WEB_API_KEY, CORS_HEADERS, REQUIRE_WEB_API_KEY),\n\t\t\tcreateCsrfMiddleware(CSRF_TOKEN, CORS_HEADERS, REQUIRE_CSRF),\n\t\t\tcreateRouterMiddleware(router),\n\t\t]);\n\n\t\ttry {\n\t\t\tawait app(req, res, () => {\n\t\t\t\t// This fallback should rarely be reached as the router handles 404s\n\t\t\t\tif (!res.headersSent && !res.writableEnded) {\n\t\t\t\t\tsendJson(res, 404, { error: \"Not found\" }, CORS_HEADERS, req);\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tlogError(error instanceof Error ? error : new Error(String(error)));\n\t\t\tif (!res.headersSent && !res.writableEnded) {\n\t\t\t\tres.writeHead(500, {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t...CORS_HEADERS,\n\t\t\t\t});\n\t\t\t\tres.end(JSON.stringify({ error: \"Internal server error\" }));\n\t\t\t}\n\t\t}\n\t});\n}\n\nexport async function startWebServer(port = 8080) {\n\tregisterCrashHandlers();\n\tawait reloadModelConfig();\n\tawait initLifecycle();\n\tstartAutomationScheduler(context);\n\n\t// Initialize enterprise context for user/org tracking (optional, only if enterprise features enabled)\n\tconst { enterpriseContext } = await import(\"./enterprise/context.js\");\n\tawait enterpriseContext.initialize();\n\n\t// Initialize audit integration if enterprise features are available\n\tif (enterpriseContext.isEnterprise()) {\n\t\tconst { initializeAuditIntegration } = await import(\n\t\t\t\"./enterprise/audit-integration.js\"\n\t\t);\n\t\tinitializeAuditIntegration();\n\t}\n\n\t// Initialize enterprise features (RBAC, permissions, default roles) if database is configured\n\tconst { isDatabaseConfigured } = await import(\"./db/client.js\");\n\tif (isDatabaseConfigured()) {\n\t\ttry {\n\t\t\tconst { initializeEnterpriseFeatures } = await import(\n\t\t\t\t\"./api/enterprise-routes.js\"\n\t\t\t);\n\t\t\tawait initializeEnterpriseFeatures();\n\t\t\tlogger.info(\"Enterprise features initialized\");\n\t\t} catch (error) {\n\t\t\tlogger.warn(\"Failed to initialize enterprise features\", {\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t}\n\t}\n\n\t// Configure safe mode settings (e.g., disabling certain tools in sandboxed environments)\n\tconfigureSafeMode(true);\n\n\t// Register shutdown hooks for background tasks to ensure clean cleanup\n\tregisterBackgroundTaskShutdownHooks();\n\n\t// Bootstrap LSP for IDE integration (enables diagnostics, hover, etc.)\n\tawait bootstrapLsp();\n\n\t// Initialize checkpoint service for undo/redo functionality\n\tinitCheckpointService(process.cwd());\n\n\t// Initialize MCP servers\n\ttry {\n\t\tconst mcpConfig = loadMcpConfig(process.cwd(), { includeEnvLimits: true });\n\t\tif (mcpConfig.servers.length > 0) {\n\t\t\tlogger.info(\"Initializing MCP servers...\");\n\t\t\tif (\n\t\t\t\tmcpConfig.servers.some(\n\t\t\t\t\t(server) => server.transport === \"http\" || server.transport === \"sse\",\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tvoid prefetchOfficialMcpRegistry();\n\t\t\t}\n\n\t\t\t// Listen for connection events\n\t\t\tmcpManager.on(\"connected\", (event) => {\n\t\t\t\tlogger.info(`MCP server connected: ${event.name}`);\n\t\t\t});\n\n\t\t\tmcpManager.on(\"disconnected\", (event) => {\n\t\t\t\tlogger.info(`MCP server disconnected: ${event.name}`);\n\t\t\t});\n\n\t\t\tawait mcpManager.configure(mcpConfig);\n\t\t}\n\t} catch (error) {\n\t\tlogger.warn(\"Failed to initialize MCP servers\", {\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t});\n\t}\n\n\tif (REQUIRE_WEB_API_KEY && !WEB_API_KEY) {\n\t\tthrow new Error(\n\t\t\t\"MAESTRO_WEB_API_KEY is required. Set MAESTRO_WEB_REQUIRE_KEY=0 to allow unauthenticated APIs for local-only testing.\",\n\t\t);\n\t}\n\n\tif (REQUIRE_REDIS && !process.env.MAESTRO_REDIS_URL) {\n\t\tthrow new Error(\n\t\t\t\"MAESTRO_REDIS_URL must be set for shared rate limiting. Set MAESTRO_WEB_REQUIRE_REDIS=0 to bypass in single-node dev only.\",\n\t\t);\n\t}\n\n\tconst server = createServer(handleRequest);\n\tconst wsMaxPayload =\n\t\tNumber.parseInt(process.env.MAESTRO_WS_MAX_PAYLOAD || \"1048576\", 10) ||\n\t\t1048576;\n\tconst wsServer = new WebSocketServer({\n\t\tnoServer: true,\n\t\tmaxPayload: wsMaxPayload,\n\t});\n\tconst sockets = new Set<Socket>();\n\tlet shuttingDown = false;\n\tlet drainTimeout: NodeJS.Timeout | null = null;\n\tlet drainInterval: NodeJS.Timeout | null = null;\n\n\tserver.on(\"connection\", (socket) => {\n\t\tsockets.add(socket);\n\t\tsocket.on(\"close\", () => {\n\t\t\tsockets.delete(socket);\n\t\t});\n\t});\n\n\tserver.on(\"upgrade\", async (req, socket, head) => {\n\t\tconst url = new URL(\n\t\t\treq.url || \"/\",\n\t\t\t`http://${req.headers.host || \"localhost\"}`,\n\t\t);\n\t\tif (url.pathname !== \"/api/chat/ws\") {\n\t\t\tsocket.destroy();\n\t\t\treturn;\n\t\t}\n\n\t\tif (ALLOWED_ORIGIN !== \"*\" && req.headers.origin) {\n\t\t\tif (req.headers.origin !== ALLOWED_ORIGIN) {\n\t\t\t\tsocket.write(\"HTTP/1.1 403 Forbidden\\r\\n\\r\\n\");\n\t\t\t\tsocket.destroy();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst auth = await checkApiAuth(req);\n\t\tif (!auth.ok) {\n\t\t\tsocket.write(\"HTTP/1.1 401 Unauthorized\\r\\n\\r\\n\");\n\t\t\tsocket.destroy();\n\t\t\treturn;\n\t\t}\n\n\t\twsServer.handleUpgrade(req, socket, head, (ws) => {\n\t\t\thandleChatWebSocket(ws, req, context);\n\t\t});\n\t});\n\n\tserver.listen(port, () => {\n\t\tlogStartup(port);\n\t\tstartStatsCollection();\n\t});\n\n\t// Don't register signal handlers in test mode - vitest manages process lifecycle\n\tconst isTestMode =\n\t\tprocess.env.VITEST === \"true\" || process.env.NODE_ENV === \"test\";\n\tif (!isTestMode) {\n\t\tprocess.on(\"SIGINT\", async () => {\n\t\t\tif (shuttingDown) return;\n\t\t\tshuttingDown = true;\n\t\t\tlogger.info(\"SIGINT received. Starting graceful shutdown...\");\n\t\t\tstopStatsCollection();\n\t\t\tdisposeCheckpointService();\n\t\t\t// End enterprise session if initialized\n\t\t\tconst { enterpriseContext } = await import(\"./enterprise/context.js\");\n\t\t\tif (enterpriseContext.isEnterprise()) {\n\t\t\t\tenterpriseContext.endSession();\n\t\t\t}\n\t\t\tawait shutdownLifecycle();\n\n\t\t\t// Stop accepting new connections\n\t\t\tserver.close();\n\n\t\t\t// Drain existing requests\n\t\t\tconst activeCount = requestTracker.getCount();\n\t\t\tif (activeCount > 0) {\n\t\t\t\tlogger.info(\"Waiting for active requests to complete...\", {\n\t\t\t\t\tactiveCount,\n\t\t\t\t});\n\t\t\t\tdrainTimeout = setTimeout(() => {\n\t\t\t\t\tlogger.warn(\"Drain timeout reached. Forcing shutdown...\");\n\t\t\t\t\tfor (const socket of sockets) {\n\t\t\t\t\t\tsocket.destroy();\n\t\t\t\t\t}\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}, 10000); // 10s drain timeout\n\n\t\t\t\t// Poll for drain\n\t\t\t\tdrainInterval = setInterval(() => {\n\t\t\t\t\tif (requestTracker.getCount() === 0) {\n\t\t\t\t\t\tif (drainInterval) clearInterval(drainInterval);\n\t\t\t\t\t\tif (drainTimeout) clearTimeout(drainTimeout);\n\t\t\t\t\t\tlogger.info(\"All requests completed. Exiting.\");\n\t\t\t\t\t\tprocess.exit(0);\n\t\t\t\t\t}\n\t\t\t\t}, 100);\n\t\t\t} else {\n\t\t\t\tlogger.info(\"No active requests. Exiting.\");\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t});\n\t}\n\n\treturn server;\n}\n\n// Run if called directly\nif (process.argv[1] && __filename === resolve(process.argv[1])) {\n\tconst port = Number.parseInt(process.env.PORT || \"8080\", 10);\n\tstartWebServer(port);\n}\n"]}
1
+ {"version":3,"file":"web-server.js","sourceRoot":"","sources":["../src/web-server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAGN,YAAY,GACZ,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAKrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EACN,2BAA2B,EAC3B,wBAAwB,EACxB,gCAAgC,EAChC,wBAAwB,EACxB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,OAAO,EACN,wBAAwB,EACxB,qBAAqB,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MA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,CAAC,QAAQ,EAAE,GAAG,EAAE;YACzB,KAAK,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;YAC1B,KAAK,aAAa,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAED,yBAAyB;AACzB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,UAAU,KAAK,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC;IAC7D,cAAc,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC","sourcesContent":["/**\n * Web server for Composer - HTTP/SSE API used by the web UI\n */\n\nimport { randomBytes, randomUUID } from \"node:crypto\";\nimport {\n\ttype IncomingMessage,\n\ttype ServerResponse,\n\tcreateServer,\n} from \"node:http\";\nimport type { Socket } from \"node:net\";\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath, parse } from \"node:url\";\nimport { WebSocketServer } from \"ws\";\nimport type {\n\tActionApprovalService,\n\tApprovalMode,\n} from \"./agent/action-approval.js\";\nimport { createBackgroundTextAgent } from \"./agent/background-agent.js\";\nimport {\n\tBackgroundTaskContextSource,\n\tCurrentDateContextSource,\n\tFrameworkPreferenceContextSource,\n\tGitSnapshotContextSource,\n\tIDEContextSource,\n\tLspContextSource,\n\tTeamMemoryContextSource,\n\tTodoContextSource,\n} from \"./agent/context-providers.js\";\nimport { Agent, ProviderTransport } from \"./agent/index.js\";\nimport type { ToolRetryService } from \"./agent/tool-retry.js\";\nimport type { ClientToolExecutionService } from \"./agent/transport.js\";\nimport type { AgentTool, ThinkingLevel } from \"./agent/types.js\";\nimport {\n\tdisposeCheckpointService,\n\tinitCheckpointService,\n} from \"./checkpoints/index.js\";\nimport { composerManager } from \"./composers/index.js\";\nimport { resolveDefaultApprovalMode } from \"./config/default-approval-mode.js\";\nimport { initLifecycle, shutdownLifecycle } from \"./lifecycle.js\";\nimport { loadEnv } from \"./load-env.js\";\nimport { bootstrapLsp } from \"./lsp/bootstrap.js\";\nimport { loadMcpConfig, mcpManager } from \"./mcp/index.js\";\nimport { prefetchOfficialMcpRegistry } from \"./mcp/official-registry.js\";\nimport { getAllMcpTools } from \"./mcp/tool-bridge.js\";\nimport { getMemoryExtractionSystemPrompt } from \"./memory/auto-extraction.js\";\nimport type { RegisteredModel } from \"./models/registry.js\";\nimport {\n\tgetFactoryDefaultModelSelection,\n\treloadModelConfig,\n} from \"./models/registry.js\";\nimport { initOpenTelemetry } from \"./opentelemetry.js\";\nimport { resolveMaestroSystemPrompt } from \"./prompts/system-prompt.js\";\nimport { getEnvVarsForProvider } from \"./providers/api-keys.js\";\nimport {\n\ttype AuthCredential,\n\ttype AuthMode,\n\tcreateAuthResolver,\n} from \"./providers/auth.js\";\nimport { registerBackgroundTaskShutdownHooks } from \"./runtime/background-task-hooks.js\";\nimport { configureSafeMode } from \"./safety/safe-mode.js\";\nimport type {\n\tHostedRunnerContext,\n\tWebServerContext,\n} from \"./server/app-context.js\";\nimport {\n\tHostedRunnerDrainReasonValue,\n\tHostedRunnerDrainStatusValue,\n\tdrainHostedRunnerForShutdown,\n} from \"./server/handlers/hosted-runner-drain.js\";\nimport { createWorkspaceConfigMiddleware } from \"./services/workspace-config/middleware.js\";\nimport { recordApiRequest } from \"./telemetry.js\";\nimport { artifactsClientTool } from \"./tools/artifacts-client.js\";\nimport { askUserClientTool } from \"./tools/ask-user-client.js\";\nimport {\n\tcodingTools,\n\tconductorClientTools,\n\tjetbrainsTools,\n\tvscodeTools,\n} from \"./tools/index.js\";\nimport { javascriptReplClientTool } from \"./tools/javascript-repl-client.js\";\nimport { createLogger } from \"./utils/logger.js\";\n\nconst logger = createLogger(\"web-server\");\n\ninterface StartWebServerOptions {\n\thost?: string;\n\thostedRunner?: HostedRunnerContext;\n\tskipStartupMigration?: boolean;\n}\n\nconst getAuditModule = (() => {\n\tlet promise: Promise<\n\t\ttypeof import(\"./enterprise/audit-integration.js\")\n\t> | null = null;\n\treturn () => {\n\t\tif (!promise) {\n\t\t\tpromise = import(\"./enterprise/audit-integration.js\");\n\t\t}\n\t\treturn promise;\n\t};\n})();\n\nconst getBillingModule = (() => {\n\tlet promise: Promise<typeof import(\"./billing/token-tracker.js\")> | null =\n\t\tnull;\n\treturn () => {\n\t\tif (!promise) {\n\t\t\tpromise = import(\"./billing/token-tracker.js\");\n\t\t}\n\t\treturn promise;\n\t};\n})();\n\nconst getDbModule = (() => {\n\tlet promise: Promise<typeof import(\"./db/client.js\")> | null = null;\n\treturn () => {\n\t\tif (!promise) {\n\t\t\tpromise = import(\"./db/client.js\");\n\t\t}\n\t\treturn promise;\n\t};\n})();\nimport { WebActionApprovalService } from \"./server/approval-service.js\";\nimport { checkApiAuth, getAuthSubject } from \"./server/authz.js\";\nimport { startAutomationScheduler } from \"./server/automations/scheduler.js\";\nimport { clientToolService } from \"./server/client-tools-service.js\";\nimport { handleChatWebSocket } from \"./server/handlers/chat-ws.js\";\nimport { handleRuntimeAppServerWebSocket } from \"./server/handlers/runtime-app-server-ws.js\";\nimport {\n\tsessionIdPattern,\n\tverifySessionOwnership,\n} from \"./server/handlers/sessions.js\";\nimport { HeadlessRuntimeService } from \"./server/headless-runtime-service.js\";\nimport {\n\tisOverloaded,\n\tlogError,\n\tlogRequest,\n\tlogStartup,\n\tstartStatsCollection,\n\tstopStatsCollection,\n} from \"./server/logger.js\";\nimport { compose } from \"./server/middleware.js\";\nimport {\n\tdetermineModelSelection,\n\tgetRegisteredModelOrThrow,\n} from \"./server/model-selection.js\";\nimport { TieredRateLimiter } from \"./server/rate-limiter.js\";\nimport {\n\ttype RequestContext,\n\tparseTraceParent,\n\trequestContextStorage,\n} from \"./server/request-context.js\";\nimport { requestTracker } from \"./server/request-tracker.js\";\nimport { createRequestHandler } from \"./server/router.js\";\nimport { createRoutes } from \"./server/routes.js\";\nimport { authorizeRuntimeWebSocketSession } from \"./server/runtime-ws-access.js\";\nimport {\n\tcreateAuthMiddleware,\n\tcreateCorsMiddleware,\n\tcreateCsrfMiddleware,\n\tcreateLoadSheddingMiddleware,\n\tcreateRouterMiddleware,\n\tcreateTieredRateLimitMiddleware,\n} from \"./server/server-middlewares.js\";\nimport {\n\tApiError,\n\tauthenticateRequest,\n\tcreateCorsHeaders,\n\tsendJson,\n} from \"./server/server-utils.js\";\nimport { createWebSessionManagerForRequest } from \"./server/session-scope.js\";\nimport { serveStatic } from \"./server/static-server.js\";\nimport { resolveWebRoot } from \"./server/web-root.js\";\n\n// Re-export for existing test imports\nexport { SseSession } from \"./server/sse-session.js\";\n\nloadEnv();\nvoid initOpenTelemetry(\"composer-web-server\");\n\n// Global crash handlers\nfunction registerCrashHandlers() {\n\tprocess.on(\"uncaughtException\", (error) => {\n\t\tlogError(error);\n\t\tlogger.error(\"FATAL: Uncaught Exception. Exiting...\");\n\t\tprocess.exit(1);\n\t});\n\n\tprocess.on(\"unhandledRejection\", (reason) => {\n\t\tlogError(\n\t\t\treason instanceof Error\n\t\t\t\t? reason\n\t\t\t\t: new Error(`Unhandled Rejection: ${String(reason)}`),\n\t\t);\n\t\tlogger.error(\"FATAL: Unhandled Rejection. Exiting...\");\n\t\tprocess.exit(1);\n\t});\n}\n\nasync function validateRuntimeSessionAccess(\n\treq: IncomingMessage,\n\tsessionId: string,\n): Promise<boolean> {\n\tif (!sessionIdPattern.test(sessionId)) {\n\t\treturn false;\n\t}\n\tconst sessionManager = createWebSessionManagerForRequest(req, false);\n\tconst session = await sessionManager.loadSession(sessionId);\n\tif (!session) {\n\t\treturn false;\n\t}\n\treturn verifySessionOwnership(session, getAuthSubject(req));\n}\n\nfunction normalizeAuthMode(value?: string | null): AuthMode {\n\tconst normalized = value?.trim().toLowerCase();\n\tif (\n\t\tnormalized === \"auto\" ||\n\t\tnormalized === \"api-key\" ||\n\t\tnormalized === \"claude\"\n\t) {\n\t\treturn normalized;\n\t}\n\treturn \"auto\";\n}\n\nconst PROFILE = (\n\tprocess.env.MAESTRO_PROFILE ||\n\tprocess.env.MAESTRO_WEB_PROFILE ||\n\t\"\"\n)\n\t.trim()\n\t.toLowerCase();\nconst PROD_PROFILE =\n\tPROFILE === \"prod\" ||\n\tPROFILE === \"production\" ||\n\tPROFILE === \"secure\" ||\n\tPROFILE === \"hardened\";\n\nconst DEFAULT_APPROVAL_MODE = resolveDefaultApprovalMode({\n\tprofile: PROFILE,\n\texplicitApprovalMode: process.env.MAESTRO_APPROVAL_MODE,\n});\nconst AUTH_MODE = normalizeAuthMode(process.env.MAESTRO_AUTH_MODE);\nconst WEB_API_KEY = process.env.MAESTRO_WEB_API_KEY?.trim() || null;\nconst requireKeyEnv = process.env.MAESTRO_WEB_REQUIRE_KEY;\nconst requireRedisEnv = process.env.MAESTRO_WEB_REQUIRE_REDIS;\nconst CSRF_TOKEN = process.env.MAESTRO_WEB_CSRF_TOKEN?.trim() || null;\nconst REQUIRE_CSRF =\n\t(PROD_PROFILE && process.env.MAESTRO_WEB_REQUIRE_CSRF !== \"0\") ||\n\tBoolean(process.env.MAESTRO_WEB_CSRF_TOKEN);\n// Default: require in normal runtime, but don't break tests unless explicitly opted in.\nconst REQUIRE_WEB_API_KEY =\n\t(requireKeyEnv ?? (process.env.NODE_ENV === \"test\" ? \"0\" : \"1\")) !== \"0\";\nconst REQUIRE_REDIS =\n\t(requireRedisEnv ?? (process.env.NODE_ENV === \"test\" ? \"0\" : \"1\")) !== \"0\";\nconst DEFAULT_WEB_ORIGIN =\n\tprocess.env.MAESTRO_WEB_ORIGIN?.trim() || \"http://localhost:4173\";\nconst STATIC_MAX_AGE =\n\tNumber.parseInt(\n\t\tprocess.env.MAESTRO_STATIC_MAX_AGE ||\n\t\t\t(process.env.NODE_ENV === \"production\" ? \"86400\" : \"60\"),\n\t\t10,\n\t) || 60;\nconst MAX_SSE_CONNECTIONS =\n\tNumber.parseInt(process.env.MAESTRO_MAX_SSE_CONNECTIONS || \"100\", 10) || 100;\nconst REQUEST_TIMEOUT_MS =\n\tNumber.parseInt(process.env.MAESTRO_REQUEST_TIMEOUT_MS || \"60000\", 10) ||\n\t60000;\n\n// Harden defaults for hosted deployments.\nprocess.env.MAESTRO_WEB_SERVER = \"1\";\nif (!process.env.MAESTRO_SAFE_MODE) process.env.MAESTRO_SAFE_MODE = \"1\";\nif (!process.env.MAESTRO_SAFE_REQUIRE_PLAN)\n\tprocess.env.MAESTRO_SAFE_REQUIRE_PLAN = \"1\";\nif (PROD_PROFILE && !process.env.MAESTRO_FAIL_UNTAGGED_EGRESS) {\n\tprocess.env.MAESTRO_FAIL_UNTAGGED_EGRESS = \"1\";\n}\nif (PROD_PROFILE && !process.env.MAESTRO_BACKGROUND_SHELL_DISABLE) {\n\tprocess.env.MAESTRO_BACKGROUND_SHELL_DISABLE = \"1\";\n}\nif (REQUIRE_CSRF && !CSRF_TOKEN) {\n\tthrow new Error(\n\t\t\"MAESTRO_WEB_CSRF_TOKEN is required when CSRF enforcement is enabled (MAESTRO_PROFILE=prod or MAESTRO_WEB_REQUIRE_CSRF=1).\",\n\t);\n}\n\n// Parse and validate TRUST_PROXY setting\n// WARNING: Only enable if behind a trusted reverse proxy that sets X-Forwarded-For\nconst trustProxyEnv = process.env.MAESTRO_TRUST_PROXY?.toLowerCase();\nconst TRUST_PROXY = trustProxyEnv === \"true\";\n\n// Number of trusted proxy hops (default 1). Use this to extract the correct client IP\n// when behind multiple proxies (e.g., CDN -> nginx -> app). The IP is read from the\n// right side of X-Forwarded-For, skipping this many trusted proxy IPs.\nconst rawProxyHops = Number.parseInt(\n\tprocess.env.MAESTRO_TRUST_PROXY_HOPS || \"1\",\n\t10,\n);\nconst TRUST_PROXY_HOPS =\n\tNumber.isNaN(rawProxyHops) || rawProxyHops < 1 ? 1 : rawProxyHops;\n\nif (\n\tprocess.env.MAESTRO_TRUST_PROXY_HOPS &&\n\t(Number.isNaN(rawProxyHops) || rawProxyHops < 1)\n) {\n\tlogger.warn(\n\t\t\"Invalid MAESTRO_TRUST_PROXY_HOPS value. Must be a positive integer. Defaulting to 1.\",\n\t\t{ value: process.env.MAESTRO_TRUST_PROXY_HOPS },\n\t);\n}\n\nif (trustProxyEnv && trustProxyEnv !== \"true\" && trustProxyEnv !== \"false\") {\n\tlogger.warn(\n\t\t\"Invalid MAESTRO_TRUST_PROXY value. Must be 'true' or 'false'. Defaulting to false.\",\n\t\t{ value: process.env.MAESTRO_TRUST_PROXY },\n\t);\n}\n\nif (TRUST_PROXY) {\n\tlogger.warn(\n\t\t\"MAESTRO_TRUST_PROXY is enabled. Ensure this server is behind a trusted reverse proxy.\",\n\t);\n}\n\nconst sseLimiter = {\n\tactive: 0,\n\tmax: MAX_SSE_CONNECTIONS,\n\ttryAcquire(): symbol | null {\n\t\tif (this.active >= this.max) return null;\n\t\tthis.active += 1;\n\t\treturn Symbol(\"sse-lease\");\n\t},\n\trelease(token: symbol | null) {\n\t\tif (!token) return;\n\t\tif (this.active > 0) this.active -= 1;\n\t},\n};\n\nconst authResolver = createAuthResolver({\n\tmode: AUTH_MODE,\n});\n\nconst DEFAULT_PROVIDER = \"anthropic\";\nconst DEFAULT_MODEL_ID = \"claude-sonnet-4-5\";\n\n/**\n * Process-local selection store (keeps last chosen model for convenience only).\n * This avoids cross-request mutations elsewhere and can be replaced with\n * per-session selection later without blocking concurrent requests.\n */\nconst modelSelectionStore = {\n\tcurrentKey: null as string | null,\n\tset(model: RegisteredModel) {\n\t\tthis.currentKey = `${model.provider}/${model.id}`;\n\t},\n\tget(): { provider: string; modelId: string } | null {\n\t\tif (!this.currentKey) return null;\n\t\tconst [provider, ...modelParts] = this.currentKey.split(\"/\");\n\t\tconst modelId = modelParts.join(\"/\");\n\t\treturn provider && modelId ? { provider, modelId } : null;\n\t},\n\treset() {\n\t\tthis.currentKey = null;\n\t},\n};\n\n// Exposed for testing/internal use only\nexport const __modelSelectionStore = {\n\tset: (model: RegisteredModel) => modelSelectionStore.set(model),\n\treset: () => modelSelectionStore.reset(),\n\tget: () => modelSelectionStore.get(),\n};\n\nfunction logMissingCredentialHints(provider: string): void {\n\tconst envVars = getEnvVarsForProvider(provider);\n\tconst hints: string[] = [`Missing credentials for provider \"${provider}\".`];\n\tif (envVars.length > 0) {\n\t\thints.push(\n\t\t\t`Populate ${envVars.join(\" or \")} or configure a custom provider secret before retrying.`,\n\t\t);\n\t}\n\tif (provider === \"anthropic\") {\n\t\thints.push(\"Run `maestro anthropic login` to provision OAuth credentials.\");\n\t} else if (provider === \"openai\") {\n\t\thints.push(\"Set OPENAI_API_KEY or run `maestro openai login`.\");\n\t}\n\tlogger.warn(hints.join(\" \"), { provider });\n}\n\nfunction buildMissingCredentialMessage(provider: string): string {\n\tlogMissingCredentialHints(provider);\n\treturn `Credentials are required for provider \"${provider}\".`;\n}\n\nasync function ensureCredential(provider: string): Promise<AuthCredential> {\n\tconst credential = await authResolver(provider);\n\tif (credential) {\n\t\treturn credential;\n\t}\n\tthrow new ApiError(401, buildMissingCredentialMessage(provider));\n}\n\nasync function getRegisteredModel(input: string | null | undefined) {\n\tconst selection = determineModelSelection(\n\t\tinput,\n\t\tDEFAULT_PROVIDER,\n\t\tDEFAULT_MODEL_ID,\n\t);\n\tconst registeredModel = getRegisteredModelOrThrow(selection);\n\tawait ensureCredential(registeredModel.provider);\n\tmodelSelectionStore.set(registeredModel);\n\treturn registeredModel;\n}\n\nfunction getCurrentSelection(): { provider: string; modelId: string } {\n\tconst stored = modelSelectionStore.get();\n\tif (stored) return stored;\n\tconst factoryDefault = getFactoryDefaultModelSelection();\n\tif (factoryDefault) return factoryDefault;\n\treturn { provider: DEFAULT_PROVIDER, modelId: DEFAULT_MODEL_ID };\n}\n\nasync function createAgent(\n\tregisteredModel: RegisteredModel,\n\tthinkingLevel: ThinkingLevel = \"off\",\n\tapprovalMode: ApprovalMode = DEFAULT_APPROVAL_MODE,\n\toptions?: {\n\t\tcwd?: string;\n\t\tenableClientTools?: boolean;\n\t\tuseClientAskUser?: boolean;\n\t\tincludeVscodeTools?: boolean;\n\t\tincludeJetBrainsTools?: boolean;\n\t\tincludeConductorTools?: boolean;\n\t\tapprovalService?: ActionApprovalService;\n\t\tclientToolService?: ClientToolExecutionService;\n\t\ttoolRetryService?: ToolRetryService;\n\t},\n): Promise<Agent> {\n\tconst cwd = options?.cwd ?? process.cwd();\n\tconst sessionTokenCounter = async (sessionId: string) => {\n\t\ttry {\n\t\t\tconst { isDatabaseConfigured } = await getDbModule();\n\t\t\tif (!isDatabaseConfigured()) return null;\n\t\t\tconst { getSessionTokenCount } = await getBillingModule();\n\t\t\treturn await getSessionTokenCount(sessionId);\n\t\t} catch (error) {\n\t\t\tlogger.warn(\"Failed to get session token count\", {\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t\treturn null;\n\t\t}\n\t};\n\n\tconst auditLogger = async (entry: {\n\t\ttoolName: string;\n\t\targs: Record<string, unknown>;\n\t\tstatus: \"success\" | \"failure\" | \"denied\";\n\t\tdurationMs: number;\n\t\terror?: string;\n\t}) => {\n\t\ttry {\n\t\t\tconst { logSensitiveToolExecution } = await getAuditModule();\n\t\t\tawait logSensitiveToolExecution(\n\t\t\t\tentry.toolName,\n\t\t\t\tentry.args,\n\t\t\t\tentry.status,\n\t\t\t\tentry.durationMs,\n\t\t\t\tentry.error,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tlogger.warn(\"Failed to log tool execution\", {\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\ttoolName: entry.toolName,\n\t\t\t});\n\t\t}\n\t};\n\n\tconst transport = new ProviderTransport({\n\t\tgetAuthContext: async (provider: string) => authResolver(provider),\n\t\tcwd,\n\t\tapprovalService:\n\t\t\toptions?.approvalService ?? new WebActionApprovalService(approvalMode),\n\t\ttoolRetryService: options?.toolRetryService,\n\t\tclientToolService:\n\t\t\toptions?.clientToolService ??\n\t\t\t(options?.enableClientTools || options?.useClientAskUser\n\t\t\t\t? clientToolService\n\t\t\t\t: undefined),\n\t\tsessionTokenCounter,\n\t\tauditLogger,\n\t});\n\n\tconst { systemPrompt, promptMetadata } = await resolveMaestroSystemPrompt();\n\n\t// Only include IDE client tools when a compatible client is connected.\n\t// Without a connected client, these tools will hang waiting for responses.\n\tconst mcpTools = getAllMcpTools();\n\tconst baseTools = options?.useClientAskUser\n\t\t? codingTools.map((tool) =>\n\t\t\t\ttool.name === \"ask_user\" ? askUserClientTool : tool,\n\t\t\t)\n\t\t: codingTools;\n\tconst tools: AgentTool[] = [...baseTools, ...mcpTools];\n\tif (options?.includeVscodeTools) {\n\t\ttools.push(...vscodeTools);\n\t}\n\tif (options?.includeJetBrainsTools) {\n\t\ttools.push(...jetbrainsTools);\n\t}\n\tif (options?.enableClientTools) {\n\t\ttools.push(artifactsClientTool);\n\t\ttools.push(javascriptReplClientTool);\n\t\tif (options?.includeConductorTools) {\n\t\t\ttools.push(...conductorClientTools);\n\t\t}\n\t}\n\n\tconst agent = new Agent({\n\t\ttransport,\n\t\tinitialState: {\n\t\t\tsystemPrompt,\n\t\t\tpromptMetadata,\n\t\t\tmodel: registeredModel,\n\t\t\tthinkingLevel,\n\t\t\ttools,\n\t\t\tsandboxMode: process.env.MAESTRO_SANDBOX ?? null,\n\t\t\tsandboxEnabled: Boolean(process.env.MAESTRO_SANDBOX),\n\t\t},\n\t\tcontextSources: [\n\t\t\tnew TodoContextSource(),\n\t\t\tnew BackgroundTaskContextSource(),\n\t\t\tnew CurrentDateContextSource(),\n\t\t\tnew GitSnapshotContextSource(cwd),\n\t\t\tnew LspContextSource(cwd),\n\t\t\tnew FrameworkPreferenceContextSource(),\n\t\t\tnew TeamMemoryContextSource(cwd),\n\t\t\tnew IDEContextSource(),\n\t\t],\n\t});\n\n\t// Initialize composer manager for this agent (enables sub-agents/composers)\n\tcomposerManager.initialize(agent, systemPrompt, tools, cwd);\n\n\treturn agent;\n}\n\nasync function createBackgroundAgent(\n\tregisteredModel: RegisteredModel,\n\toptions?: {\n\t\tcwd?: string;\n\t\tsystemPrompt?: string;\n\t},\n): Promise<Agent> {\n\treturn createBackgroundTextAgent({\n\t\tmodel: registeredModel,\n\t\tsystemPrompt: options?.systemPrompt ?? getMemoryExtractionSystemPrompt(),\n\t\tcwd: options?.cwd ?? process.cwd(),\n\t\tgetAuthContext: async (provider: string) => authResolver(provider),\n\t});\n}\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\nconst WEB_ROOT = resolveWebRoot({ baseDir: __dirname });\nconst ALLOWED_ORIGIN = DEFAULT_WEB_ORIGIN;\nconst CORS_HEADERS = createCorsHeaders(ALLOWED_ORIGIN);\nconst SECURITY_HEADERS: Record<string, string> =\n\tPROD_PROFILE || process.env.MAESTRO_WEB_CSP?.trim()\n\t\t? {\n\t\t\t\t\"Content-Security-Policy\":\n\t\t\t\t\tprocess.env.MAESTRO_WEB_CSP ||\n\t\t\t\t\t[\n\t\t\t\t\t\t\"default-src 'none'\",\n\t\t\t\t\t\t`connect-src 'self' ${ALLOWED_ORIGIN}`,\n\t\t\t\t\t\t\"img-src 'self' data:\",\n\t\t\t\t\t\t\"style-src 'self' 'unsafe-inline'\",\n\t\t\t\t\t\t\"script-src 'self'\",\n\t\t\t\t\t\t\"font-src 'self' data:\",\n\t\t\t\t\t\t\"frame-ancestors 'none'\",\n\t\t\t\t\t\t\"base-uri 'self'\",\n\t\t\t\t\t\t\"form-action 'self'\",\n\t\t\t\t\t].join(\"; \"),\n\t\t\t\t\"Referrer-Policy\": \"no-referrer\",\n\t\t\t\t\"X-Content-Type-Options\": \"nosniff\",\n\t\t\t\t\"Permissions-Policy\": \"geolocation=(), microphone=(self), camera=()\",\n\t\t\t}\n\t\t: {};\n\nconst headlessRuntimeService = new HeadlessRuntimeService();\n\nconst context: WebServerContext = {\n\tcorsHeaders: CORS_HEADERS,\n\tstaticMaxAge: STATIC_MAX_AGE,\n\tdefaultApprovalMode: DEFAULT_APPROVAL_MODE,\n\tdefaultProvider: DEFAULT_PROVIDER,\n\tdefaultModelId: DEFAULT_MODEL_ID,\n\tcreateAgent,\n\tcreateBackgroundAgent,\n\tgetRegisteredModel,\n\tgetCurrentSelection,\n\tensureCredential,\n\tsetModelSelection: (model) => modelSelectionStore.set(model),\n\tacquireSse: () => sseLimiter.tryAcquire(),\n\treleaseSse: (token) => sseLimiter.release(token),\n\theadlessRuntimeService,\n};\n\nconst routes = createRoutes(context);\n\nconst router = createRequestHandler(\n\troutes,\n\t(req, res, pathname) => {\n\t\tif (pathname.startsWith(\"/api\")) {\n\t\t\tsendJson(res, 404, { error: \"Not found\" }, CORS_HEADERS, req);\n\t\t\treturn;\n\t\t}\n\t\tserveStatic(pathname, req, res, {\n\t\t\twebRoot: WEB_ROOT,\n\t\t\tcorsHeaders: CORS_HEADERS,\n\t\t\tmaxAgeSeconds: STATIC_MAX_AGE,\n\t\t\tsecurityHeaders: SECURITY_HEADERS,\n\t\t\tspaFallback: true,\n\t\t});\n\t},\n\tCORS_HEADERS,\n);\n\n// Active request tracking for graceful shutdown and debugging\n// Tiered rate limiter with per-endpoint limits\n// Global: 1000/min, with stricter limits for expensive endpoints\nconst rateLimiter = new TieredRateLimiter();\n\nasync function handleRequest(req: IncomingMessage, res: ServerResponse) {\n\tconst start = performance.now();\n\tconst parsedUrl = parse(req.url || \"/\", true);\n\tconst pathname = parsedUrl.pathname || \"/\";\n\tconst requestId = randomUUID();\n\n\t// Parse W3C Trace Context\n\t// traceparent: 00-traceid-spanid-flags\n\tconst traceParent = req.headers.traceparent as string | undefined;\n\tconst { traceId, parentSpanId } = parseTraceParent(traceParent);\n\tconst spanId = randomBytes(8).toString(\"hex\"); // New span for this service\n\tconst responseTraceParent = `00-${traceId}-${spanId}-01`;\n\tres.setHeader(\"traceparent\", responseTraceParent);\n\tres.setHeader(\"server-timing\", `traceparent;desc=\"${responseTraceParent}\"`);\n\n\t// Attach request to response for easy access in helpers\n\t(res as ServerResponse & { req?: IncomingMessage }).req = req;\n\n\tconst context: RequestContext = {\n\t\trequestId,\n\t\ttraceId,\n\t\tspanId,\n\t\tstartTime: start,\n\t\tmethod: req.method || \"GET\",\n\t\turl: pathname,\n\t};\n\n\t// Set a hard timeout for processing\n\t// Skip for SSE endpoints which are meant to be long-lived\n\tif (!pathname.startsWith(\"/api/chat\")) {\n\t\tconst timeout = setTimeout(() => {\n\t\t\tif (!res.headersSent && !res.writableEnded) {\n\t\t\t\trequestContextStorage.run(context, () => {\n\t\t\t\t\tlogError(`Request timeout for ${pathname} [${requestId}]`);\n\t\t\t\t\tconst duration = performance.now() - start;\n\t\t\t\t\trecordApiRequest(req.method || \"UNKNOWN\", pathname, 504, duration, {\n\t\t\t\t\t\trequestId,\n\t\t\t\t\t\ttraceId,\n\t\t\t\t\t\tspanId,\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tres.writeHead(504, {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t...CORS_HEADERS,\n\t\t\t\t});\n\t\t\t\tres.end(JSON.stringify({ error: \"Gateway Timeout\" }));\n\t\t\t}\n\t\t}, REQUEST_TIMEOUT_MS);\n\n\t\tconst cleanup = () => {\n\t\t\tclearTimeout(timeout);\n\t\t};\n\n\t\tres.on(\"finish\", cleanup);\n\t\tres.on(\"close\", cleanup);\n\t}\n\n\t// Track request for introspection (Channelz) and graceful shutdown\n\trequestTracker.track(req, {\n\t\tid: requestId,\n\t\tmethod: req.method || \"GET\",\n\t\turl: pathname,\n\t\tstartTime: start,\n\t\tuserAgent: req.headers[\"user-agent\"],\n\t});\n\n\tres.on(\"close\", () => {\n\t\trequestTracker.untrack(req);\n\t});\n\n\t// Await the context storage run to prevent unhandled promise rejections\n\tawait requestContextStorage.run(context, async () => {\n\t\t// Setup logging listener inside context to capture trace/span IDs in closure\n\t\tres.on(\"finish\", () => {\n\t\t\tconst duration = performance.now() - start;\n\t\t\tlogRequest(req, res.statusCode, start);\n\t\t\trecordApiRequest(\n\t\t\t\treq.method || \"UNKNOWN\",\n\t\t\t\tpathname,\n\t\t\t\tres.statusCode,\n\t\t\t\tduration,\n\t\t\t\t{ requestId, traceId, spanId },\n\t\t\t);\n\t\t});\n\n\t\tconst app = compose([\n\t\t\tcreateLoadSheddingMiddleware(CORS_HEADERS),\n\t\t\tcreateTieredRateLimitMiddleware(\n\t\t\t\trateLimiter,\n\t\t\t\tCORS_HEADERS,\n\t\t\t\tTRUST_PROXY,\n\t\t\t\tTRUST_PROXY_HOPS,\n\t\t\t),\n\t\t\tcreateCorsMiddleware(CORS_HEADERS),\n\t\t\tcreateAuthMiddleware(WEB_API_KEY, CORS_HEADERS, REQUIRE_WEB_API_KEY),\n\t\t\tcreateCsrfMiddleware(CSRF_TOKEN, CORS_HEADERS, REQUIRE_CSRF),\n\t\t\tcreateWorkspaceConfigMiddleware(CORS_HEADERS),\n\t\t\tcreateRouterMiddleware(router),\n\t\t]);\n\n\t\ttry {\n\t\t\tawait app(req, res, () => {\n\t\t\t\t// This fallback should rarely be reached as the router handles 404s\n\t\t\t\tif (!res.headersSent && !res.writableEnded) {\n\t\t\t\t\tsendJson(res, 404, { error: \"Not found\" }, CORS_HEADERS, req);\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tlogError(error instanceof Error ? error : new Error(String(error)));\n\t\t\tif (!res.headersSent && !res.writableEnded) {\n\t\t\t\tres.writeHead(500, {\n\t\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\t...CORS_HEADERS,\n\t\t\t\t});\n\t\t\t\tres.end(JSON.stringify({ error: \"Internal server error\" }));\n\t\t\t}\n\t\t}\n\t});\n}\n\nexport async function startWebServer(\n\tport = 8080,\n\toptions: StartWebServerOptions = {},\n) {\n\tif (options.hostedRunner) {\n\t\tcontext.hostedRunner = options.hostedRunner;\n\t}\n\n\tregisterCrashHandlers();\n\tif (!options.skipStartupMigration) {\n\t\tconst { migrate } = await import(\"./db/migrate.js\");\n\t\tconst applied = await migrate();\n\t\tif (applied > 0) {\n\t\t\tlogger.info(\"Startup database migrations completed\", { count: applied });\n\t\t}\n\t}\n\tawait reloadModelConfig();\n\tawait initLifecycle();\n\tstartAutomationScheduler(context);\n\n\t// Initialize enterprise context for user/org tracking (optional, only if enterprise features enabled)\n\tconst { enterpriseContext } = await import(\"./enterprise/context.js\");\n\tawait enterpriseContext.initialize();\n\n\t// Initialize audit integration if enterprise features are available\n\tif (enterpriseContext.isEnterprise()) {\n\t\tconst { initializeAuditIntegration } = await import(\n\t\t\t\"./enterprise/audit-integration.js\"\n\t\t);\n\t\tinitializeAuditIntegration();\n\t}\n\n\t// Initialize enterprise features (RBAC, permissions, default roles) if database is configured\n\tconst { isDatabaseConfigured } = await import(\"./db/client.js\");\n\tif (isDatabaseConfigured()) {\n\t\ttry {\n\t\t\tconst { initializeEnterpriseFeatures } = await import(\n\t\t\t\t\"./api/enterprise-routes.js\"\n\t\t\t);\n\t\t\tawait initializeEnterpriseFeatures();\n\t\t\tlogger.info(\"Enterprise features initialized\");\n\t\t} catch (error) {\n\t\t\tlogger.warn(\"Failed to initialize enterprise features\", {\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t}\n\t}\n\n\t// Configure safe mode settings (e.g., disabling certain tools in sandboxed environments)\n\tconfigureSafeMode(true);\n\n\t// Register shutdown hooks for background tasks to ensure clean cleanup\n\tregisterBackgroundTaskShutdownHooks();\n\n\t// Bootstrap LSP for IDE integration (enables diagnostics, hover, etc.)\n\tawait bootstrapLsp();\n\n\t// Initialize checkpoint service for undo/redo functionality\n\tinitCheckpointService(process.cwd());\n\n\t// Initialize MCP servers\n\ttry {\n\t\tconst mcpConfig = loadMcpConfig(process.cwd(), { includeEnvLimits: true });\n\t\tif (mcpConfig.servers.length > 0) {\n\t\t\tlogger.info(\"Initializing MCP servers...\");\n\t\t\tif (\n\t\t\t\tmcpConfig.servers.some(\n\t\t\t\t\t(server) => server.transport === \"http\" || server.transport === \"sse\",\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tvoid prefetchOfficialMcpRegistry();\n\t\t\t}\n\n\t\t\t// Listen for connection events\n\t\t\tmcpManager.on(\"connected\", (event) => {\n\t\t\t\tlogger.info(`MCP server connected: ${event.name}`);\n\t\t\t});\n\n\t\t\tmcpManager.on(\"disconnected\", (event) => {\n\t\t\t\tlogger.info(`MCP server disconnected: ${event.name}`);\n\t\t\t});\n\n\t\t\tawait mcpManager.configure(mcpConfig);\n\t\t}\n\t} catch (error) {\n\t\tlogger.warn(\"Failed to initialize MCP servers\", {\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t});\n\t}\n\n\tif (REQUIRE_WEB_API_KEY && !WEB_API_KEY) {\n\t\tthrow new Error(\n\t\t\t\"MAESTRO_WEB_API_KEY is required. Set MAESTRO_WEB_REQUIRE_KEY=0 to allow unauthenticated APIs for local-only testing.\",\n\t\t);\n\t}\n\n\tif (REQUIRE_REDIS && !process.env.MAESTRO_REDIS_URL) {\n\t\tthrow new Error(\n\t\t\t\"MAESTRO_REDIS_URL must be set for shared rate limiting. Set MAESTRO_WEB_REQUIRE_REDIS=0 to bypass in single-node dev only.\",\n\t\t);\n\t}\n\n\tconst server = createServer(handleRequest);\n\tconst wsMaxPayload =\n\t\tNumber.parseInt(process.env.MAESTRO_WS_MAX_PAYLOAD || \"1048576\", 10) ||\n\t\t1048576;\n\tconst wsServer = new WebSocketServer({\n\t\tnoServer: true,\n\t\tmaxPayload: wsMaxPayload,\n\t});\n\tconst sockets = new Set<Socket>();\n\tlet shuttingDown = false;\n\tlet drainTimeout: NodeJS.Timeout | null = null;\n\tlet drainInterval: NodeJS.Timeout | null = null;\n\n\tserver.on(\"connection\", (socket) => {\n\t\tsockets.add(socket);\n\t\tsocket.on(\"close\", () => {\n\t\t\tsockets.delete(socket);\n\t\t});\n\t});\n\n\tserver.on(\"upgrade\", async (req, socket, head) => {\n\t\tconst url = new URL(\n\t\t\treq.url || \"/\",\n\t\t\t`http://${req.headers.host || \"localhost\"}`,\n\t\t);\n\t\tif (url.pathname !== \"/api/chat/ws\" && url.pathname !== \"/api/runtime/ws\") {\n\t\t\tsocket.destroy();\n\t\t\treturn;\n\t\t}\n\n\t\tif (ALLOWED_ORIGIN !== \"*\" && req.headers.origin) {\n\t\t\tif (req.headers.origin !== ALLOWED_ORIGIN) {\n\t\t\t\tsocket.write(\"HTTP/1.1 403 Forbidden\\r\\n\\r\\n\");\n\t\t\t\tsocket.destroy();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst auth = await checkApiAuth(req);\n\t\tif (!auth.ok) {\n\t\t\tsocket.write(\"HTTP/1.1 401 Unauthorized\\r\\n\\r\\n\");\n\t\t\tsocket.destroy();\n\t\t\treturn;\n\t\t}\n\n\t\tlet runtimeSessionId: string | undefined;\n\t\tif (url.pathname === \"/api/runtime/ws\") {\n\t\t\tconst authorization = await authorizeRuntimeWebSocketSession({\n\t\t\t\treq,\n\t\t\t\tsocket,\n\t\t\t\trequestedSessionId: url.searchParams.get(\"sessionId\"),\n\t\t\t\tvalidateSessionAccess: validateRuntimeSessionAccess,\n\t\t\t\tlogAccessError: logError,\n\t\t\t});\n\t\t\tif (authorization === null) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\truntimeSessionId = authorization;\n\t\t}\n\n\t\twsServer.handleUpgrade(req, socket, head, (ws) => {\n\t\t\tif (url.pathname === \"/api/runtime/ws\") {\n\t\t\t\thandleRuntimeAppServerWebSocket(ws, {\n\t\t\t\t\tsessionId: runtimeSessionId,\n\t\t\t\t\tvalidateSessionAccess: (sessionId) =>\n\t\t\t\t\t\tvalidateRuntimeSessionAccess(req, sessionId),\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\thandleChatWebSocket(ws, req, context);\n\t\t});\n\t});\n\n\tconst onListening = () => {\n\t\tlogStartup(port);\n\t\tif (context.hostedRunner) {\n\t\t\tlogger.info(\"Hosted runner mode enabled\", {\n\t\t\t\trunnerSessionId: context.hostedRunner.runnerSessionId,\n\t\t\t\tworkspaceRoot: context.hostedRunner.workspaceRoot,\n\t\t\t\tsnapshotRoot: context.hostedRunner.snapshotRoot,\n\t\t\t\tworkspaceId: context.hostedRunner.workspaceId,\n\t\t\t\tagentRunId: context.hostedRunner.agentRunId,\n\t\t\t\tlistenHost: options.host,\n\t\t\t\tlistenPort: port,\n\t\t\t});\n\t\t}\n\t\tstartStatsCollection();\n\t};\n\tif (options.host) {\n\t\tserver.listen(port, options.host, onListening);\n\t} else {\n\t\tserver.listen(port, onListening);\n\t}\n\n\t// Don't register signal handlers in test mode - vitest manages process lifecycle\n\tconst isTestMode =\n\t\tprocess.env.VITEST === \"true\" || process.env.NODE_ENV === \"test\";\n\tif (!isTestMode) {\n\t\tconst beginShutdown = async (signal: NodeJS.Signals) => {\n\t\t\tif (shuttingDown) return;\n\t\t\tshuttingDown = true;\n\t\t\tif (context.hostedRunner) {\n\t\t\t\tif (context.hostedRunner.draining) {\n\t\t\t\t\tlogger.info(\"Hosted runner already draining before shutdown\", {\n\t\t\t\t\t\trunnerSessionId: context.hostedRunner.runnerSessionId,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst drainResult = await drainHostedRunnerForShutdown(context, {\n\t\t\t\t\t\t\treason: HostedRunnerDrainReasonValue.ProcessShutdown,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (drainResult) {\n\t\t\t\t\t\t\tconst log =\n\t\t\t\t\t\t\t\tdrainResult.status === HostedRunnerDrainStatusValue.Interrupted\n\t\t\t\t\t\t\t\t\t? logger.warn.bind(logger)\n\t\t\t\t\t\t\t\t\t: logger.info.bind(logger);\n\t\t\t\t\t\t\tlog(\"Hosted runner drained during graceful shutdown\", {\n\t\t\t\t\t\t\t\trunnerSessionId: drainResult.runner_session_id,\n\t\t\t\t\t\t\t\tstatus: drainResult.status,\n\t\t\t\t\t\t\t\tmanifestPath: drainResult.manifest_path,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tcontext.hostedRunner.draining = true;\n\t\t\t\t\t\tlogger.warn(\"Hosted runner shutdown drain failed\", {\n\t\t\t\t\t\t\trunnerSessionId: context.hostedRunner.runnerSessionId,\n\t\t\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tlogger.info(`${signal} received. Starting graceful shutdown...`);\n\t\t\tstopStatsCollection();\n\t\t\tdisposeCheckpointService();\n\t\t\t// End enterprise session if initialized\n\t\t\tconst { enterpriseContext } = await import(\"./enterprise/context.js\");\n\t\t\tif (enterpriseContext.isEnterprise()) {\n\t\t\t\tenterpriseContext.endSession();\n\t\t\t}\n\t\t\tawait shutdownLifecycle();\n\n\t\t\t// Stop accepting new connections\n\t\t\tserver.close();\n\n\t\t\t// Drain existing requests\n\t\t\tconst activeCount = requestTracker.getCount();\n\t\t\tif (activeCount > 0) {\n\t\t\t\tlogger.info(\"Waiting for active requests to complete...\", {\n\t\t\t\t\tactiveCount,\n\t\t\t\t});\n\t\t\t\tdrainTimeout = setTimeout(() => {\n\t\t\t\t\tlogger.warn(\"Drain timeout reached. Forcing shutdown...\");\n\t\t\t\t\tfor (const socket of sockets) {\n\t\t\t\t\t\tsocket.destroy();\n\t\t\t\t\t}\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}, 10000); // 10s drain timeout\n\n\t\t\t\t// Poll for drain\n\t\t\t\tdrainInterval = setInterval(() => {\n\t\t\t\t\tif (requestTracker.getCount() === 0) {\n\t\t\t\t\t\tif (drainInterval) clearInterval(drainInterval);\n\t\t\t\t\t\tif (drainTimeout) clearTimeout(drainTimeout);\n\t\t\t\t\t\tlogger.info(\"All requests completed. Exiting.\");\n\t\t\t\t\t\tprocess.exit(0);\n\t\t\t\t\t}\n\t\t\t\t}, 100);\n\t\t\t} else {\n\t\t\t\tlogger.info(\"No active requests. Exiting.\");\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t};\n\t\tprocess.on(\"SIGINT\", () => {\n\t\t\tvoid beginShutdown(\"SIGINT\");\n\t\t});\n\t\tprocess.on(\"SIGTERM\", () => {\n\t\t\tvoid beginShutdown(\"SIGTERM\");\n\t\t});\n\t}\n\n\treturn server;\n}\n\n// Run if called directly\nif (process.argv[1] && __filename === resolve(process.argv[1])) {\n\tconst port = Number.parseInt(process.env.PORT || \"8080\", 10);\n\tstartWebServer(port);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"delivery.d.ts","sourceRoot":"","sources":["../../src/webhooks/delivery.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH,MAAM,WAAW,cAAc;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,sBAAsB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,2BAA2B,CAC1C,SAAS,CAAC,EAAE,MAAM,GAChB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAaxB;AAMD,gFAAgF;AAChF,wBAAgB,WAAW,CAC1B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,SAAS,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SAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAqC5E;AAMD,wBAAsB,iBAAiB,CACtC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE;IACN,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,GACC,OAAO,CAAC,IAAI,CAAC,CAuDf;AASD,wBAAgB,qBAAqB,CAAC,UAAU,SAAS,GAAG,IAAI,CAkC/D;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAY1D;AAMD,MAAM,WAAW,mBAAmB;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAuC3E"}
@@ -12,10 +12,12 @@ import { and, count, eq, isNull, lt, lte, or } from "drizzle-orm";
12
12
  import { getDb, isDbAvailable } from "../db/client.js";
13
13
  import { distributedLocks, organizations, webhookDeliveries, } from "../db/schema.js";
14
14
  import { decryptOrgSettings } from "../db/settings-encryption.js";
15
+ import { fetchDownstream } from "../utils/downstream-http.js";
15
16
  import { createLogger } from "../utils/logger.js";
16
17
  // Unique identifier for this process instance
17
18
  const INSTANCE_ID = `${process.pid}-${crypto.randomUUID().slice(0, 8)}`;
18
19
  const logger = createLogger("webhooks:delivery");
20
+ const WEBHOOK_DOWNSTREAM_MAX_ATTEMPTS = 1;
19
21
  export function buildWebhookDeliveryHeaders(signature) {
20
22
  const headers = {
21
23
  "Content-Type": "application/json",
@@ -86,15 +88,17 @@ async function deliverHttp(url, payload, signature, timeoutMs = 30_000) {
86
88
  const startTime = Date.now();
87
89
  const headers = buildWebhookDeliveryHeaders(signature);
88
90
  try {
89
- const controller = new AbortController();
90
- const timeout = setTimeout(() => controller.abort(), timeoutMs);
91
- const response = await fetch(url, {
91
+ const response = await fetchDownstream(url, {
92
92
  method: "POST",
93
93
  headers,
94
94
  body: payload,
95
- signal: controller.signal,
95
+ }, {
96
+ serviceName: "webhook endpoint",
97
+ failureMode: "optional",
98
+ timeoutMs,
99
+ // The database queue owns webhook retry accounting.
100
+ maxAttempts: WEBHOOK_DOWNSTREAM_MAX_ATTEMPTS,
96
101
  });
97
- clearTimeout(timeout);
98
102
  const responseTimeMs = Date.now() - startTime;
99
103
  if (response.ok) {
100
104
  return {
@@ -112,13 +116,6 @@ async function deliverHttp(url, payload, signature, timeoutMs = 30_000) {
112
116
  }
113
117
  catch (error) {
114
118
  const responseTimeMs = Date.now() - startTime;
115
- if (error instanceof Error && error.name === "AbortError") {
116
- return {
117
- success: false,
118
- responseTimeMs,
119
- error: "Request timeout",
120
- };
121
- }
122
119
  return {
123
120
  success: false,
124
121
  responseTimeMs,