@andorra-labs/code 0.0.0-stage → 0.1.4

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 (1847) hide show
  1. package/LICENSE.md +38 -0
  2. package/README.md +231 -3
  3. package/THIRD_PARTY_NOTICES.md +56 -0
  4. package/dist/src/account-presentation.d.ts +53 -0
  5. package/dist/src/account-presentation.js +99 -0
  6. package/dist/src/activity.d.ts +41 -0
  7. package/dist/src/activity.js +79 -0
  8. package/dist/src/agent-definitions.d.ts +61 -0
  9. package/dist/src/agent-definitions.js +303 -0
  10. package/dist/src/agent-execution.d.ts +4 -0
  11. package/dist/src/agent-execution.js +1198 -0
  12. package/dist/src/agent-mcp.d.ts +105 -0
  13. package/dist/src/agent-mcp.js +859 -0
  14. package/dist/src/agent-modifiers.d.ts +8 -0
  15. package/dist/src/agent-modifiers.js +333 -0
  16. package/dist/src/analytics.d.ts +81 -0
  17. package/dist/src/analytics.js +81 -0
  18. package/dist/src/anthropic-console-auth.d.ts +68 -0
  19. package/dist/src/anthropic-console-auth.js +318 -0
  20. package/dist/src/anthropic-credentials.d.ts +41 -0
  21. package/dist/src/anthropic-credentials.js +107 -0
  22. package/dist/src/app-server/protocol.d.ts +500 -0
  23. package/dist/src/app-server/protocol.js +106 -0
  24. package/dist/src/app-server/reasoning.d.ts +43 -0
  25. package/dist/src/app-server/reasoning.js +173 -0
  26. package/dist/src/app-server/terminal.d.ts +77 -0
  27. package/dist/src/app-server/terminal.js +177 -0
  28. package/dist/src/app-server/workspace.d.ts +247 -0
  29. package/dist/src/app-server/workspace.js +1098 -0
  30. package/dist/src/app-server.d.ts +1039 -0
  31. package/dist/src/app-server.js +6594 -0
  32. package/dist/src/artifacts.d.ts +27 -0
  33. package/dist/src/artifacts.js +103 -0
  34. package/dist/src/attachments.d.ts +158 -0
  35. package/dist/src/attachments.js +466 -0
  36. package/dist/src/auth/AuthManager.d.ts +110 -0
  37. package/dist/src/auth/AuthManager.js +435 -0
  38. package/dist/src/auth/callback.d.ts +10 -0
  39. package/dist/src/auth/callback.js +96 -0
  40. package/dist/src/auth/deployment.d.ts +18 -0
  41. package/dist/src/auth/deployment.js +18 -0
  42. package/dist/src/auth/index.d.ts +31 -0
  43. package/dist/src/auth/index.js +27 -0
  44. package/dist/src/auth/lock.d.ts +2 -0
  45. package/dist/src/auth/lock.js +29 -0
  46. package/dist/src/auth/store.d.ts +20 -0
  47. package/dist/src/auth/store.js +93 -0
  48. package/dist/src/auth/types.d.ts +24 -0
  49. package/dist/src/auth/types.js +8 -0
  50. package/dist/src/auth-commands.d.ts +5 -0
  51. package/dist/src/auth-commands.js +28 -0
  52. package/dist/src/automation-runner.d.ts +7 -0
  53. package/dist/src/automation-runner.js +113 -0
  54. package/dist/src/automation-service.d.ts +28 -0
  55. package/dist/src/automation-service.js +299 -0
  56. package/dist/src/automation-tool.d.ts +2 -0
  57. package/dist/src/automation-tool.js +49 -0
  58. package/dist/src/automation-worker-shutdown.d.ts +3 -0
  59. package/dist/src/automation-worker-shutdown.js +13 -0
  60. package/dist/src/automations.d.ts +63 -0
  61. package/dist/src/automations.js +265 -0
  62. package/dist/src/boot-trace.d.ts +15 -0
  63. package/dist/src/boot-trace.js +25 -0
  64. package/dist/src/browser-activity.d.ts +4 -0
  65. package/dist/src/browser-activity.js +18 -0
  66. package/dist/src/browser-bridge.d.ts +56 -0
  67. package/dist/src/browser-bridge.js +372 -0
  68. package/dist/src/browser-observation.d.ts +24 -0
  69. package/dist/src/browser-observation.js +104 -0
  70. package/dist/src/browser-panel-tool.d.ts +39 -0
  71. package/dist/src/browser-panel-tool.js +227 -0
  72. package/dist/src/browser-runner.d.ts +16 -0
  73. package/dist/src/browser-runner.js +302 -0
  74. package/dist/src/browser-server.d.ts +31 -0
  75. package/dist/src/browser-server.js +1189 -0
  76. package/dist/src/browser-session.d.ts +19 -0
  77. package/dist/src/browser-session.js +649 -0
  78. package/dist/src/browser-ui/andorra-logo.png +0 -0
  79. package/dist/src/browser-ui/app.js +419 -0
  80. package/dist/src/browser-ui/index.html +13 -0
  81. package/dist/src/browser-ui/style.css +243 -0
  82. package/dist/src/browser-view.d.ts +348 -0
  83. package/dist/src/browser-view.js +1487 -0
  84. package/dist/src/capabilities.d.ts +9 -0
  85. package/dist/src/capabilities.js +135 -0
  86. package/dist/src/clarification-ui.d.ts +23 -0
  87. package/dist/src/clarification-ui.js +59 -0
  88. package/dist/src/claude-executable.d.ts +6 -0
  89. package/dist/src/claude-executable.js +56 -0
  90. package/dist/src/claude-provider.d.ts +35 -0
  91. package/dist/src/claude-provider.js +391 -0
  92. package/dist/src/cli.d.ts +85 -0
  93. package/dist/src/cli.js +2564 -0
  94. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +108 -0
  95. package/dist/src/code-intelligence/CodeIntelligenceManager.js +616 -0
  96. package/dist/src/code-intelligence/ContextLedger.d.ts +32 -0
  97. package/dist/src/code-intelligence/ContextLedger.js +77 -0
  98. package/dist/src/code-intelligence/ContextRouter.d.ts +8 -0
  99. package/dist/src/code-intelligence/ContextRouter.js +18 -0
  100. package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.d.ts +82 -0
  101. package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.js +444 -0
  102. package/dist/src/code-intelligence/codegraph/CodeGraphProvider.d.ts +40 -0
  103. package/dist/src/code-intelligence/codegraph/CodeGraphProvider.js +84 -0
  104. package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.d.ts +22 -0
  105. package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.js +71 -0
  106. package/dist/src/code-intelligence/codegraph/repoExploreTool.d.ts +9 -0
  107. package/dist/src/code-intelligence/codegraph/repoExploreTool.js +26 -0
  108. package/dist/src/code-intelligence/repository.d.ts +13 -0
  109. package/dist/src/code-intelligence/repository.js +48 -0
  110. package/dist/src/code-intelligence/types.d.ts +78 -0
  111. package/dist/src/code-intelligence/types.js +3 -0
  112. package/dist/src/codex-auth.d.ts +83 -0
  113. package/dist/src/codex-auth.js +168 -0
  114. package/dist/src/codex-browser-auth.d.ts +74 -0
  115. package/dist/src/codex-browser-auth.js +429 -0
  116. package/dist/src/codex-errors.d.ts +3 -0
  117. package/dist/src/codex-errors.js +50 -0
  118. package/dist/src/codex-executable.d.ts +12 -0
  119. package/dist/src/codex-executable.js +154 -0
  120. package/dist/src/codex-provider.d.ts +25 -0
  121. package/dist/src/codex-provider.js +211 -0
  122. package/dist/src/codex-rpc.d.ts +43 -0
  123. package/dist/src/codex-rpc.js +136 -0
  124. package/dist/src/coding-tools.d.ts +19 -0
  125. package/dist/src/coding-tools.js +875 -0
  126. package/dist/src/command-metrics.d.ts +17 -0
  127. package/dist/src/command-metrics.js +34 -0
  128. package/dist/src/command-screens.d.ts +44 -0
  129. package/dist/src/command-screens.js +601 -0
  130. package/dist/src/commands.d.ts +111 -0
  131. package/dist/src/commands.js +550 -0
  132. package/dist/src/completion.d.ts +45 -0
  133. package/dist/src/completion.js +195 -0
  134. package/dist/src/config.d.ts +163 -0
  135. package/dist/src/config.js +663 -0
  136. package/dist/src/context-budget.d.ts +32 -0
  137. package/dist/src/context-budget.js +151 -0
  138. package/dist/src/context-compaction.d.ts +43 -0
  139. package/dist/src/context-compaction.js +269 -0
  140. package/dist/src/context-selection.d.ts +65 -0
  141. package/dist/src/context-selection.js +130 -0
  142. package/dist/src/dashboard-view.d.ts +37 -0
  143. package/dist/src/dashboard-view.js +254 -0
  144. package/dist/src/dashboard.d.ts +41 -0
  145. package/dist/src/dashboard.js +160 -0
  146. package/dist/src/deadline.d.ts +55 -0
  147. package/dist/src/deadline.js +164 -0
  148. package/dist/src/decision/ContinuationAdapter.d.ts +6 -0
  149. package/dist/src/decision/ContinuationAdapter.js +11 -0
  150. package/dist/src/decision/DecisionEngine.d.ts +23 -0
  151. package/dist/src/decision/DecisionEngine.js +1 -0
  152. package/dist/src/decision/DecisionManager.d.ts +47 -0
  153. package/dist/src/decision/DecisionManager.js +280 -0
  154. package/dist/src/decision/DecisionPolicy.d.ts +8 -0
  155. package/dist/src/decision/DecisionPolicy.js +54 -0
  156. package/dist/src/decision/FactContinuations.d.ts +147 -0
  157. package/dist/src/decision/FactContinuations.js +472 -0
  158. package/dist/src/decision/FactServiceGate.d.ts +12 -0
  159. package/dist/src/decision/FactServiceGate.js +37 -0
  160. package/dist/src/decision/PreparedSteps.d.ts +51 -0
  161. package/dist/src/decision/PreparedSteps.js +147 -0
  162. package/dist/src/decision/applyToolMenu.d.ts +3 -0
  163. package/dist/src/decision/applyToolMenu.js +61 -0
  164. package/dist/src/decision/checks.d.ts +13 -0
  165. package/dist/src/decision/checks.js +104 -0
  166. package/dist/src/decision/facts.d.ts +64 -0
  167. package/dist/src/decision/facts.js +90 -0
  168. package/dist/src/decision/guidancePolicy.d.ts +3 -0
  169. package/dist/src/decision/guidancePolicy.js +10 -0
  170. package/dist/src/decision/hostedPolicy.d.ts +14 -0
  171. package/dist/src/decision/hostedPolicy.js +21 -0
  172. package/dist/src/decision/index.d.ts +6 -0
  173. package/dist/src/decision/index.js +6 -0
  174. package/dist/src/decision/optimizationPolicy.d.ts +26 -0
  175. package/dist/src/decision/optimizationPolicy.js +38 -0
  176. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +17 -0
  177. package/dist/src/decision/providers/AndorraDecisionProvider.js +251 -0
  178. package/dist/src/decision/providers/HttpDecisionProvider.d.ts +16 -0
  179. package/dist/src/decision/providers/HttpDecisionProvider.js +105 -0
  180. package/dist/src/decision/providers/NoOpDecisionProvider.d.ts +4 -0
  181. package/dist/src/decision/providers/NoOpDecisionProvider.js +3 -0
  182. package/dist/src/decision/providers/index.d.ts +3 -0
  183. package/dist/src/decision/providers/index.js +13 -0
  184. package/dist/src/decision/providers/questions.d.ts +3 -0
  185. package/dist/src/decision/providers/questions.js +31 -0
  186. package/dist/src/decision/routeTools.d.ts +59 -0
  187. package/dist/src/decision/routeTools.js +131 -0
  188. package/dist/src/decision/toolFamilies.d.ts +7 -0
  189. package/dist/src/decision/toolFamilies.js +55 -0
  190. package/dist/src/decision/toolMenu.d.ts +35 -0
  191. package/dist/src/decision/toolMenu.js +73 -0
  192. package/dist/src/decision/types.d.ts +99 -0
  193. package/dist/src/decision/types.js +1 -0
  194. package/dist/src/diff-preview.d.ts +6 -0
  195. package/dist/src/diff-preview.js +120 -0
  196. package/dist/src/duration.d.ts +44 -0
  197. package/dist/src/duration.js +72 -0
  198. package/dist/src/efficiency.d.ts +101 -0
  199. package/dist/src/efficiency.js +104 -0
  200. package/dist/src/engine/protocol.d.ts +11 -0
  201. package/dist/src/engine/protocol.js +51 -0
  202. package/dist/src/extensions.d.ts +46 -0
  203. package/dist/src/extensions.js +846 -0
  204. package/dist/src/favicons.d.ts +37 -0
  205. package/dist/src/favicons.js +216 -0
  206. package/dist/src/file-read-state.d.ts +8 -0
  207. package/dist/src/file-read-state.js +31 -0
  208. package/dist/src/git-summary.d.ts +67 -0
  209. package/dist/src/git-summary.js +461 -0
  210. package/dist/src/goal-completion-verification.d.ts +18 -0
  211. package/dist/src/goal-completion-verification.js +43 -0
  212. package/dist/src/graph-account.d.ts +31 -0
  213. package/dist/src/graph-account.js +57 -0
  214. package/dist/src/graph-editor-session.d.ts +15 -0
  215. package/dist/src/graph-editor-session.js +70 -0
  216. package/dist/src/graph-health.d.ts +88 -0
  217. package/dist/src/graph-health.js +243 -0
  218. package/dist/src/graph-provider-portability.d.ts +30 -0
  219. package/dist/src/graph-provider-portability.js +197 -0
  220. package/dist/src/graph-quota.d.ts +55 -0
  221. package/dist/src/graph-quota.js +131 -0
  222. package/dist/src/graph-runner.d.ts +4 -0
  223. package/dist/src/graph-runner.js +1356 -0
  224. package/dist/src/graph-selection.d.ts +17 -0
  225. package/dist/src/graph-selection.js +31 -0
  226. package/dist/src/graph-server.d.ts +13 -0
  227. package/dist/src/graph-server.js +483 -0
  228. package/dist/src/graph-studio-features.d.ts +61 -0
  229. package/dist/src/graph-studio-features.js +348 -0
  230. package/dist/src/graph-sync.d.ts +76 -0
  231. package/dist/src/graph-sync.js +619 -0
  232. package/dist/src/graph-ui/andorra-logo.png +0 -0
  233. package/dist/src/graph-ui/app.js +1803 -0
  234. package/dist/src/graph-ui/compat.js +43 -0
  235. package/dist/src/graph-ui/controls.css +190 -0
  236. package/dist/src/graph-ui/controls.js +567 -0
  237. package/dist/src/graph-ui/edge-router.js +117 -0
  238. package/dist/src/graph-ui/embed.js +324 -0
  239. package/dist/src/graph-ui/fonts/geist-mono-latin-400-normal.woff2 +0 -0
  240. package/dist/src/graph-ui/fonts/geist-sans-latin-400-normal.woff2 +0 -0
  241. package/dist/src/graph-ui/fonts/geist-sans-latin-500-normal.woff2 +0 -0
  242. package/dist/src/graph-ui/icons.js +117 -0
  243. package/dist/src/graph-ui/index.html +7 -0
  244. package/dist/src/graph-ui/library.css +26 -0
  245. package/dist/src/graph-ui/sidebar.js +61 -0
  246. package/dist/src/graph-ui/studio-canvas.js +454 -0
  247. package/dist/src/graph-ui/studio.css +110 -0
  248. package/dist/src/graph-ui/studio.js +720 -0
  249. package/dist/src/graph-ui/style.css +477 -0
  250. package/dist/src/graph-ui/theme.js +92 -0
  251. package/dist/src/graph-ui/tokens.css +187 -0
  252. package/dist/src/graphs.d.ts +270 -0
  253. package/dist/src/graphs.js +1102 -0
  254. package/dist/src/grep-regex-worker.d.ts +1 -0
  255. package/dist/src/grep-regex-worker.js +20 -0
  256. package/dist/src/grep-regex.d.ts +11 -0
  257. package/dist/src/grep-regex.js +64 -0
  258. package/dist/src/handoffs.d.ts +34 -0
  259. package/dist/src/handoffs.js +229 -0
  260. package/dist/src/hardened-runtime.d.ts +14 -0
  261. package/dist/src/hardened-runtime.js +264 -0
  262. package/dist/src/limits.d.ts +77 -0
  263. package/dist/src/limits.js +88 -0
  264. package/dist/src/markdown.d.ts +31 -0
  265. package/dist/src/markdown.js +553 -0
  266. package/dist/src/mcp.d.ts +11 -0
  267. package/dist/src/mcp.js +175 -0
  268. package/dist/src/membership-errors.d.ts +4 -0
  269. package/dist/src/membership-errors.js +4 -0
  270. package/dist/src/membership.d.ts +81 -0
  271. package/dist/src/membership.js +247 -0
  272. package/dist/src/memory/LocalToolMemory.d.ts +20 -0
  273. package/dist/src/memory/LocalToolMemory.js +114 -0
  274. package/dist/src/memory/MemoryDistiller.d.ts +35 -0
  275. package/dist/src/memory/MemoryDistiller.js +216 -0
  276. package/dist/src/memory/MemoryManager.d.ts +76 -0
  277. package/dist/src/memory/MemoryManager.js +386 -0
  278. package/dist/src/memory/MemoryPolicy.d.ts +30 -0
  279. package/dist/src/memory/MemoryPolicy.js +96 -0
  280. package/dist/src/memory/MemoryProvider.d.ts +18 -0
  281. package/dist/src/memory/MemoryProvider.js +1 -0
  282. package/dist/src/memory/MemoryRetriever.d.ts +27 -0
  283. package/dist/src/memory/MemoryRetriever.js +149 -0
  284. package/dist/src/memory/PermissionMemoryProvider.d.ts +22 -0
  285. package/dist/src/memory/PermissionMemoryProvider.js +50 -0
  286. package/dist/src/memory/ToolFailureLessons.d.ts +39 -0
  287. package/dist/src/memory/ToolFailureLessons.js +167 -0
  288. package/dist/src/memory/index.d.ts +12 -0
  289. package/dist/src/memory/index.js +11 -0
  290. package/dist/src/memory/providers/NoOpMemoryProvider.d.ts +13 -0
  291. package/dist/src/memory/providers/NoOpMemoryProvider.js +15 -0
  292. package/dist/src/memory/providers/graphiti/GraphitiClient.d.ts +27 -0
  293. package/dist/src/memory/providers/graphiti/GraphitiClient.js +76 -0
  294. package/dist/src/memory/providers/graphiti/GraphitiMapper.d.ts +6 -0
  295. package/dist/src/memory/providers/graphiti/GraphitiMapper.js +116 -0
  296. package/dist/src/memory/providers/graphiti/GraphitiMemoryProvider.d.ts +27 -0
  297. package/dist/src/memory/providers/graphiti/GraphitiMemoryProvider.js +137 -0
  298. package/dist/src/memory/providers/graphiti/GraphitiTypes.d.ts +57 -0
  299. package/dist/src/memory/providers/graphiti/GraphitiTypes.js +2 -0
  300. package/dist/src/memory/redaction.d.ts +11 -0
  301. package/dist/src/memory/redaction.js +58 -0
  302. package/dist/src/memory/repository.d.ts +11 -0
  303. package/dist/src/memory/repository.js +74 -0
  304. package/dist/src/memory/tools/memorySearchTool.d.ts +4 -0
  305. package/dist/src/memory/tools/memorySearchTool.js +77 -0
  306. package/dist/src/memory/types.d.ts +112 -0
  307. package/dist/src/memory/types.js +7 -0
  308. package/dist/src/model-metadata.d.ts +28 -0
  309. package/dist/src/model-metadata.js +274 -0
  310. package/dist/src/model-override.d.ts +60 -0
  311. package/dist/src/model-override.js +146 -0
  312. package/dist/src/model-tiers.d.ts +61 -0
  313. package/dist/src/model-tiers.js +109 -0
  314. package/dist/src/opencode-catalog.d.ts +16 -0
  315. package/dist/src/opencode-catalog.js +135 -0
  316. package/dist/src/opencode-provider.d.ts +10 -0
  317. package/dist/src/opencode-provider.js +525 -0
  318. package/dist/src/paged-transcript.d.ts +58 -0
  319. package/dist/src/paged-transcript.js +205 -0
  320. package/dist/src/palette.d.ts +61 -0
  321. package/dist/src/palette.js +63 -0
  322. package/dist/src/permissions.d.ts +36 -0
  323. package/dist/src/permissions.js +93 -0
  324. package/dist/src/powershell-pool.d.ts +26 -0
  325. package/dist/src/powershell-pool.js +235 -0
  326. package/dist/src/profile.d.ts +80 -0
  327. package/dist/src/profile.js +200 -0
  328. package/dist/src/provider-connection.d.ts +36 -0
  329. package/dist/src/provider-connection.js +222 -0
  330. package/dist/src/provider-engine.d.ts +37 -0
  331. package/dist/src/provider-engine.js +401 -0
  332. package/dist/src/provider-import.d.ts +68 -0
  333. package/dist/src/provider-import.js +355 -0
  334. package/dist/src/provider-settings.d.ts +8 -0
  335. package/dist/src/provider-settings.js +451 -0
  336. package/dist/src/providers.d.ts +219 -0
  337. package/dist/src/providers.js +1230 -0
  338. package/dist/src/pull-requests.d.ts +195 -0
  339. package/dist/src/pull-requests.js +514 -0
  340. package/dist/src/qa/api/http-runner.d.ts +3 -0
  341. package/dist/src/qa/api/http-runner.js +47 -0
  342. package/dist/src/qa/browser/PlaywrightRunner.d.ts +21 -0
  343. package/dist/src/qa/browser/PlaywrightRunner.js +190 -0
  344. package/dist/src/qa/command-policy.d.ts +28 -0
  345. package/dist/src/qa/command-policy.js +122 -0
  346. package/dist/src/qa/git/ChangeDetector.d.ts +26 -0
  347. package/dist/src/qa/git/ChangeDetector.js +177 -0
  348. package/dist/src/qa/git/DiffReviewer.d.ts +28 -0
  349. package/dist/src/qa/git/DiffReviewer.js +115 -0
  350. package/dist/src/qa/index.d.ts +11 -0
  351. package/dist/src/qa/index.js +19 -0
  352. package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +14 -0
  353. package/dist/src/qa/orchestrator/ChangeClassifier.js +28 -0
  354. package/dist/src/qa/orchestrator/MergeGate.d.ts +14 -0
  355. package/dist/src/qa/orchestrator/MergeGate.js +40 -0
  356. package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +79 -0
  357. package/dist/src/qa/orchestrator/QaOrchestrator.js +373 -0
  358. package/dist/src/qa/profile/ProjectInspector.d.ts +9 -0
  359. package/dist/src/qa/profile/ProjectInspector.js +295 -0
  360. package/dist/src/qa/profile/QaConfigLoader.d.ts +43 -0
  361. package/dist/src/qa/profile/QaConfigLoader.js +261 -0
  362. package/dist/src/qa/profile/QaProfile.d.ts +17 -0
  363. package/dist/src/qa/profile/QaProfile.js +15 -0
  364. package/dist/src/qa/profile/yaml.d.ts +12 -0
  365. package/dist/src/qa/profile/yaml.js +203 -0
  366. package/dist/src/qa/qa-authorize.d.ts +25 -0
  367. package/dist/src/qa/qa-authorize.js +82 -0
  368. package/dist/src/qa/runners/CommandRunner.d.ts +22 -0
  369. package/dist/src/qa/runners/CommandRunner.js +96 -0
  370. package/dist/src/qa/runners/TestRunner.d.ts +21 -0
  371. package/dist/src/qa/runners/TestRunner.js +66 -0
  372. package/dist/src/qa/runtime/ProcessManager.d.ts +53 -0
  373. package/dist/src/qa/runtime/ProcessManager.js +225 -0
  374. package/dist/src/qa/runtime/PtyManager.d.ts +57 -0
  375. package/dist/src/qa/runtime/PtyManager.js +338 -0
  376. package/dist/src/qa/runtime/RuntimeSmoke.d.ts +11 -0
  377. package/dist/src/qa/runtime/RuntimeSmoke.js +78 -0
  378. package/dist/src/qa/runtime-detect.d.ts +10 -0
  379. package/dist/src/qa/runtime-detect.js +72 -0
  380. package/dist/src/qa/security/DependencyScanner.d.ts +19 -0
  381. package/dist/src/qa/security/DependencyScanner.js +167 -0
  382. package/dist/src/qa/security/SecretScanner.d.ts +3 -0
  383. package/dist/src/qa/security/SecretScanner.js +55 -0
  384. package/dist/src/qa/tools.d.ts +3 -0
  385. package/dist/src/qa/tools.js +301 -0
  386. package/dist/src/qa/types.d.ts +134 -0
  387. package/dist/src/qa/types.js +3 -0
  388. package/dist/src/react-runtime.d.ts +53 -0
  389. package/dist/src/react-runtime.js +1753 -0
  390. package/dist/src/remote/cert.d.ts +29 -0
  391. package/dist/src/remote/cert.js +136 -0
  392. package/dist/src/remote/client.d.ts +189 -0
  393. package/dist/src/remote/client.js +659 -0
  394. package/dist/src/remote/command.d.ts +4 -0
  395. package/dist/src/remote/command.js +211 -0
  396. package/dist/src/remote/engine-pool.d.ts +230 -0
  397. package/dist/src/remote/engine-pool.js +1160 -0
  398. package/dist/src/remote/errors.d.ts +26 -0
  399. package/dist/src/remote/errors.js +21 -0
  400. package/dist/src/remote/network.d.ts +48 -0
  401. package/dist/src/remote/network.js +135 -0
  402. package/dist/src/remote/pairing.d.ts +98 -0
  403. package/dist/src/remote/pairing.js +306 -0
  404. package/dist/src/remote/roots.d.ts +29 -0
  405. package/dist/src/remote/roots.js +44 -0
  406. package/dist/src/remote/serve.d.ts +115 -0
  407. package/dist/src/remote/serve.js +274 -0
  408. package/dist/src/remote/server.d.ts +35 -0
  409. package/dist/src/remote/server.js +484 -0
  410. package/dist/src/remote/types.d.ts +86 -0
  411. package/dist/src/remote/types.js +11 -0
  412. package/dist/src/run-control.d.ts +17 -0
  413. package/dist/src/run-control.js +52 -0
  414. package/dist/src/run-progress.d.ts +226 -0
  415. package/dist/src/run-progress.js +724 -0
  416. package/dist/src/run-records.d.ts +500 -0
  417. package/dist/src/run-records.js +1678 -0
  418. package/dist/src/runtime.d.ts +418 -0
  419. package/dist/src/runtime.js +247 -0
  420. package/dist/src/sandbox-child.d.ts +1 -0
  421. package/dist/src/sandbox-child.js +14 -0
  422. package/dist/src/save-lock.d.ts +9 -0
  423. package/dist/src/save-lock.js +186 -0
  424. package/dist/src/session-monitor.d.ts +98 -0
  425. package/dist/src/session-monitor.js +323 -0
  426. package/dist/src/session-reaper.d.ts +23 -0
  427. package/dist/src/session-reaper.js +33 -0
  428. package/dist/src/session-summary.d.ts +27 -0
  429. package/dist/src/session-summary.js +66 -0
  430. package/dist/src/session-title.d.ts +18 -0
  431. package/dist/src/session-title.js +54 -0
  432. package/dist/src/sessions.d.ts +211 -0
  433. package/dist/src/sessions.js +620 -0
  434. package/dist/src/shell.d.ts +40 -0
  435. package/dist/src/shell.js +504 -0
  436. package/dist/src/side-panel.d.ts +144 -0
  437. package/dist/src/side-panel.js +366 -0
  438. package/dist/src/skill-commands.d.ts +1 -0
  439. package/dist/src/skill-commands.js +11 -0
  440. package/dist/src/skills/bundled/ai-elements/SKILL.md +155 -0
  441. package/dist/src/skills/bundled/ai-elements/references/agent.md +138 -0
  442. package/dist/src/skills/bundled/ai-elements/references/artifact.md +91 -0
  443. package/dist/src/skills/bundled/ai-elements/references/attachments.md +197 -0
  444. package/dist/src/skills/bundled/ai-elements/references/audio-player.md +141 -0
  445. package/dist/src/skills/bundled/ai-elements/references/canvas.md +39 -0
  446. package/dist/src/skills/bundled/ai-elements/references/chain-of-thought.md +88 -0
  447. package/dist/src/skills/bundled/ai-elements/references/checkpoint.md +171 -0
  448. package/dist/src/skills/bundled/ai-elements/references/code-block.md +177 -0
  449. package/dist/src/skills/bundled/ai-elements/references/commit.md +184 -0
  450. package/dist/src/skills/bundled/ai-elements/references/confirmation.md +268 -0
  451. package/dist/src/skills/bundled/ai-elements/references/connection.md +39 -0
  452. package/dist/src/skills/bundled/ai-elements/references/context.md +133 -0
  453. package/dist/src/skills/bundled/ai-elements/references/controls.md +37 -0
  454. package/dist/src/skills/bundled/ai-elements/references/conversation.md +224 -0
  455. package/dist/src/skills/bundled/ai-elements/references/edge.md +57 -0
  456. package/dist/src/skills/bundled/ai-elements/references/environment-variables.md +109 -0
  457. package/dist/src/skills/bundled/ai-elements/references/file-tree.md +79 -0
  458. package/dist/src/skills/bundled/ai-elements/references/image.md +150 -0
  459. package/dist/src/skills/bundled/ai-elements/references/inline-citation.md +300 -0
  460. package/dist/src/skills/bundled/ai-elements/references/jsx-preview.md +108 -0
  461. package/dist/src/skills/bundled/ai-elements/references/message.md +231 -0
  462. package/dist/src/skills/bundled/ai-elements/references/mic-selector.md +193 -0
  463. package/dist/src/skills/bundled/ai-elements/references/model-selector.md +119 -0
  464. package/dist/src/skills/bundled/ai-elements/references/node.md +78 -0
  465. package/dist/src/skills/bundled/ai-elements/references/open-in-chat.md +74 -0
  466. package/dist/src/skills/bundled/ai-elements/references/package-info.md +102 -0
  467. package/dist/src/skills/bundled/ai-elements/references/panel.md +38 -0
  468. package/dist/src/skills/bundled/ai-elements/references/persona.md +173 -0
  469. package/dist/src/skills/bundled/ai-elements/references/plan.md +86 -0
  470. package/dist/src/skills/bundled/ai-elements/references/prompt-input.md +572 -0
  471. package/dist/src/skills/bundled/ai-elements/references/queue.md +179 -0
  472. package/dist/src/skills/bundled/ai-elements/references/reasoning.md +226 -0
  473. package/dist/src/skills/bundled/ai-elements/references/sandbox.md +133 -0
  474. package/dist/src/skills/bundled/ai-elements/references/schema-display.md +109 -0
  475. package/dist/src/skills/bundled/ai-elements/references/shimmer.md +55 -0
  476. package/dist/src/skills/bundled/ai-elements/references/snippet.md +71 -0
  477. package/dist/src/skills/bundled/ai-elements/references/sources.md +200 -0
  478. package/dist/src/skills/bundled/ai-elements/references/speech-input.md +167 -0
  479. package/dist/src/skills/bundled/ai-elements/references/stack-trace.md +225 -0
  480. package/dist/src/skills/bundled/ai-elements/references/suggestion.md +128 -0
  481. package/dist/src/skills/bundled/ai-elements/references/task.md +222 -0
  482. package/dist/src/skills/bundled/ai-elements/references/terminal.md +110 -0
  483. package/dist/src/skills/bundled/ai-elements/references/test-results.md +164 -0
  484. package/dist/src/skills/bundled/ai-elements/references/tool.md +282 -0
  485. package/dist/src/skills/bundled/ai-elements/references/toolbar.md +37 -0
  486. package/dist/src/skills/bundled/ai-elements/references/transcription.md +127 -0
  487. package/dist/src/skills/bundled/ai-elements/references/voice-selector.md +248 -0
  488. package/dist/src/skills/bundled/ai-elements/references/web-preview.md +204 -0
  489. package/dist/src/skills/bundled/ai-elements/scripts/agent.tsx +67 -0
  490. package/dist/src/skills/bundled/ai-elements/scripts/artifact.tsx +117 -0
  491. package/dist/src/skills/bundled/ai-elements/scripts/attachments-inline.tsx +123 -0
  492. package/dist/src/skills/bundled/ai-elements/scripts/attachments-list.tsx +94 -0
  493. package/dist/src/skills/bundled/ai-elements/scripts/attachments.tsx +84 -0
  494. package/dist/src/skills/bundled/ai-elements/scripts/audio-player-remote.tsx +35 -0
  495. package/dist/src/skills/bundled/ai-elements/scripts/audio-player.tsx +74 -0
  496. package/dist/src/skills/bundled/ai-elements/scripts/chain-of-thought.tsx +80 -0
  497. package/dist/src/skills/bundled/ai-elements/scripts/checkpoint.tsx +96 -0
  498. package/dist/src/skills/bundled/ai-elements/scripts/code-block-dark.tsx +46 -0
  499. package/dist/src/skills/bundled/ai-elements/scripts/code-block.tsx +120 -0
  500. package/dist/src/skills/bundled/ai-elements/scripts/commit.tsx +94 -0
  501. package/dist/src/skills/bundled/ai-elements/scripts/confirmation-accepted.tsx +41 -0
  502. package/dist/src/skills/bundled/ai-elements/scripts/confirmation-rejected.tsx +41 -0
  503. package/dist/src/skills/bundled/ai-elements/scripts/confirmation-request.tsx +54 -0
  504. package/dist/src/skills/bundled/ai-elements/scripts/confirmation.tsx +59 -0
  505. package/dist/src/skills/bundled/ai-elements/scripts/context.tsx +45 -0
  506. package/dist/src/skills/bundled/ai-elements/scripts/conversation.tsx +182 -0
  507. package/dist/src/skills/bundled/ai-elements/scripts/environment-variables.tsx +61 -0
  508. package/dist/src/skills/bundled/ai-elements/scripts/file-tree-basic.tsx +20 -0
  509. package/dist/src/skills/bundled/ai-elements/scripts/file-tree-expanded.tsx +23 -0
  510. package/dist/src/skills/bundled/ai-elements/scripts/file-tree-selection.tsx +26 -0
  511. package/dist/src/skills/bundled/ai-elements/scripts/file-tree.tsx +44 -0
  512. package/dist/src/skills/bundled/ai-elements/scripts/image.tsx +20 -0
  513. package/dist/src/skills/bundled/ai-elements/scripts/inline-citation.tsx +101 -0
  514. package/dist/src/skills/bundled/ai-elements/scripts/jsx-preview.tsx +105 -0
  515. package/dist/src/skills/bundled/ai-elements/scripts/message.tsx +330 -0
  516. package/dist/src/skills/bundled/ai-elements/scripts/mic-selector.tsx +52 -0
  517. package/dist/src/skills/bundled/ai-elements/scripts/model-selector.tsx +368 -0
  518. package/dist/src/skills/bundled/ai-elements/scripts/open-in-chat.tsx +33 -0
  519. package/dist/src/skills/bundled/ai-elements/scripts/package-info.tsx +52 -0
  520. package/dist/src/skills/bundled/ai-elements/scripts/persona-command.tsx +101 -0
  521. package/dist/src/skills/bundled/ai-elements/scripts/persona-glint.tsx +101 -0
  522. package/dist/src/skills/bundled/ai-elements/scripts/persona-halo.tsx +101 -0
  523. package/dist/src/skills/bundled/ai-elements/scripts/persona-mana.tsx +101 -0
  524. package/dist/src/skills/bundled/ai-elements/scripts/persona-obsidian.tsx +101 -0
  525. package/dist/src/skills/bundled/ai-elements/scripts/persona-opal.tsx +101 -0
  526. package/dist/src/skills/bundled/ai-elements/scripts/plan.tsx +69 -0
  527. package/dist/src/skills/bundled/ai-elements/scripts/prompt-input-cursor.tsx +462 -0
  528. package/dist/src/skills/bundled/ai-elements/scripts/prompt-input-tooltip.tsx +46 -0
  529. package/dist/src/skills/bundled/ai-elements/scripts/prompt-input.tsx +254 -0
  530. package/dist/src/skills/bundled/ai-elements/scripts/queue-prompt-input.tsx +372 -0
  531. package/dist/src/skills/bundled/ai-elements/scripts/queue.tsx +281 -0
  532. package/dist/src/skills/bundled/ai-elements/scripts/reasoning.tsx +73 -0
  533. package/dist/src/skills/bundled/ai-elements/scripts/sandbox.tsx +171 -0
  534. package/dist/src/skills/bundled/ai-elements/scripts/schema-display-basic.tsx +13 -0
  535. package/dist/src/skills/bundled/ai-elements/scripts/schema-display-body.tsx +20 -0
  536. package/dist/src/skills/bundled/ai-elements/scripts/schema-display-nested.tsx +23 -0
  537. package/dist/src/skills/bundled/ai-elements/scripts/schema-display-params.tsx +16 -0
  538. package/dist/src/skills/bundled/ai-elements/scripts/schema-display.tsx +110 -0
  539. package/dist/src/skills/bundled/ai-elements/scripts/shimmer-duration.tsx +35 -0
  540. package/dist/src/skills/bundled/ai-elements/scripts/shimmer-elements.tsx +45 -0
  541. package/dist/src/skills/bundled/ai-elements/scripts/shimmer.tsx +17 -0
  542. package/dist/src/skills/bundled/ai-elements/scripts/snippet-plain.tsx +19 -0
  543. package/dist/src/skills/bundled/ai-elements/scripts/snippet.tsx +25 -0
  544. package/dist/src/skills/bundled/ai-elements/scripts/sources-custom.tsx +40 -0
  545. package/dist/src/skills/bundled/ai-elements/scripts/sources.tsx +33 -0
  546. package/dist/src/skills/bundled/ai-elements/scripts/speech-input.tsx +85 -0
  547. package/dist/src/skills/bundled/ai-elements/scripts/stack-trace-collapsed.tsx +39 -0
  548. package/dist/src/skills/bundled/ai-elements/scripts/stack-trace-no-internal.tsx +41 -0
  549. package/dist/src/skills/bundled/ai-elements/scripts/stack-trace.tsx +60 -0
  550. package/dist/src/skills/bundled/ai-elements/scripts/suggestion-input.tsx +142 -0
  551. package/dist/src/skills/bundled/ai-elements/scripts/suggestion.tsx +34 -0
  552. package/dist/src/skills/bundled/ai-elements/scripts/task.tsx +59 -0
  553. package/dist/src/skills/bundled/ai-elements/scripts/terminal-basic.tsx +7 -0
  554. package/dist/src/skills/bundled/ai-elements/scripts/terminal-clear.tsx +19 -0
  555. package/dist/src/skills/bundled/ai-elements/scripts/terminal-streaming.tsx +38 -0
  556. package/dist/src/skills/bundled/ai-elements/scripts/terminal.tsx +83 -0
  557. package/dist/src/skills/bundled/ai-elements/scripts/test-results-basic.tsx +27 -0
  558. package/dist/src/skills/bundled/ai-elements/scripts/test-results-errors.tsx +51 -0
  559. package/dist/src/skills/bundled/ai-elements/scripts/test-results-suites.tsx +40 -0
  560. package/dist/src/skills/bundled/ai-elements/scripts/test-results.tsx +84 -0
  561. package/dist/src/skills/bundled/ai-elements/scripts/tool-input-available.tsx +31 -0
  562. package/dist/src/skills/bundled/ai-elements/scripts/tool-input-streaming.tsx +30 -0
  563. package/dist/src/skills/bundled/ai-elements/scripts/tool-output-available.tsx +81 -0
  564. package/dist/src/skills/bundled/ai-elements/scripts/tool-output-error.tsx +50 -0
  565. package/dist/src/skills/bundled/ai-elements/scripts/tool.tsx +210 -0
  566. package/dist/src/skills/bundled/ai-elements/scripts/transcription.tsx +289 -0
  567. package/dist/src/skills/bundled/ai-elements/scripts/voice-selector.tsx +233 -0
  568. package/dist/src/skills/bundled/ai-elements/scripts/web-preview.tsx +105 -0
  569. package/dist/src/skills/bundled/control-browser/SKILL.md +21 -0
  570. package/dist/src/skills/bundled/dynamic-workflows/SKILL.md +1520 -0
  571. package/dist/src/skills/bundled/dynamic-workflows/examples.md +801 -0
  572. package/dist/src/skills/bundled/dynamic-workflows/patterns.md +460 -0
  573. package/dist/src/skills/bundled/provenance.json +684 -0
  574. package/dist/src/skills/bundled/web-gui-tester/SKILL.md +159 -0
  575. package/dist/src/skills/project-skills.d.ts +11 -0
  576. package/dist/src/skills/project-skills.js +132 -0
  577. package/dist/src/skills/runtime-skills.d.ts +10 -0
  578. package/dist/src/skills/runtime-skills.js +237 -0
  579. package/dist/src/subagent-run.d.ts +278 -0
  580. package/dist/src/subagent-run.js +930 -0
  581. package/dist/src/telemetry/aggregate.d.ts +80 -0
  582. package/dist/src/telemetry/aggregate.js +217 -0
  583. package/dist/src/telemetry/capture-core.d.ts +190 -0
  584. package/dist/src/telemetry/capture-core.js +374 -0
  585. package/dist/src/telemetry/capture.d.ts +5 -0
  586. package/dist/src/telemetry/capture.js +16 -0
  587. package/dist/src/telemetry/classify.d.ts +102 -0
  588. package/dist/src/telemetry/classify.js +252 -0
  589. package/dist/src/telemetry/decision-capture.d.ts +13 -0
  590. package/dist/src/telemetry/decision-capture.js +40 -0
  591. package/dist/src/telemetry/emitter.d.ts +77 -0
  592. package/dist/src/telemetry/emitter.js +279 -0
  593. package/dist/src/telemetry/gate.d.ts +48 -0
  594. package/dist/src/telemetry/gate.js +55 -0
  595. package/dist/src/telemetry/identity.d.ts +19 -0
  596. package/dist/src/telemetry/identity.js +109 -0
  597. package/dist/src/telemetry/outbox.d.ts +91 -0
  598. package/dist/src/telemetry/outbox.js +356 -0
  599. package/dist/src/telemetry/schema.d.ts +184 -0
  600. package/dist/src/telemetry/schema.js +492 -0
  601. package/dist/src/telemetry/state.d.ts +90 -0
  602. package/dist/src/telemetry/state.js +195 -0
  603. package/dist/src/telemetry/surface.d.ts +76 -0
  604. package/dist/src/telemetry/surface.js +116 -0
  605. package/dist/src/telemetry/uploader.d.ts +29 -0
  606. package/dist/src/telemetry/uploader.js +151 -0
  607. package/dist/src/telemetry/uploads.d.ts +13 -0
  608. package/dist/src/telemetry/uploads.js +19 -0
  609. package/dist/src/telemetry/version.d.ts +5 -0
  610. package/dist/src/telemetry/version.js +25 -0
  611. package/dist/src/telemetry/workspace.d.ts +14 -0
  612. package/dist/src/telemetry/workspace.js +93 -0
  613. package/dist/src/terminal-ui.d.ts +744 -0
  614. package/dist/src/terminal-ui.js +3012 -0
  615. package/dist/src/text.d.ts +2 -0
  616. package/dist/src/text.js +8 -0
  617. package/dist/src/timers.d.ts +189 -0
  618. package/dist/src/timers.js +244 -0
  619. package/dist/src/todos.d.ts +12 -0
  620. package/dist/src/todos.js +33 -0
  621. package/dist/src/token-rate.d.ts +119 -0
  622. package/dist/src/token-rate.js +287 -0
  623. package/dist/src/tool-activity.d.ts +20 -0
  624. package/dist/src/tool-activity.js +76 -0
  625. package/dist/src/tool-call-clock.d.ts +32 -0
  626. package/dist/src/tool-call-clock.js +157 -0
  627. package/dist/src/tool-catalog.d.ts +40 -0
  628. package/dist/src/tool-catalog.js +100 -0
  629. package/dist/src/tool-dependencies.d.ts +23 -0
  630. package/dist/src/tool-dependencies.js +36 -0
  631. package/dist/src/tool-diff-stats.d.ts +24 -0
  632. package/dist/src/tool-diff-stats.js +122 -0
  633. package/dist/src/tool-errors.d.ts +12 -0
  634. package/dist/src/tool-errors.js +13 -0
  635. package/dist/src/tool-failure-tracker.d.ts +17 -0
  636. package/dist/src/tool-failure-tracker.js +71 -0
  637. package/dist/src/tool-names.d.ts +16 -0
  638. package/dist/src/tool-names.js +75 -0
  639. package/dist/src/tool-result-filter.d.ts +65 -0
  640. package/dist/src/tool-result-filter.js +447 -0
  641. package/dist/src/tool-schema-compatibility.d.ts +2 -0
  642. package/dist/src/tool-schema-compatibility.js +42 -0
  643. package/dist/src/tools.d.ts +3 -0
  644. package/dist/src/tools.js +663 -0
  645. package/dist/src/trajectory.d.ts +34 -0
  646. package/dist/src/trajectory.js +426 -0
  647. package/dist/src/transcript.d.ts +45 -0
  648. package/dist/src/transcript.js +228 -0
  649. package/dist/src/types.d.ts +248 -0
  650. package/dist/src/types.js +1 -0
  651. package/dist/src/update.d.ts +48 -0
  652. package/dist/src/update.js +614 -0
  653. package/dist/src/usage-analytics.d.ts +48 -0
  654. package/dist/src/usage-analytics.js +663 -0
  655. package/dist/src/widgets.d.ts +45 -0
  656. package/dist/src/widgets.js +71 -0
  657. package/dist/src/workspace-facts.d.ts +35 -0
  658. package/dist/src/workspace-facts.js +85 -0
  659. package/dist/src/workspace-git-metadata.d.ts +6 -0
  660. package/dist/src/workspace-git-metadata.js +114 -0
  661. package/dist/src/workspace-instructions.d.ts +7 -0
  662. package/dist/src/workspace-instructions.js +46 -0
  663. package/dist/vendor/engine/LICENSE.upstream +21 -0
  664. package/dist/vendor/engine/provenance.json +17923 -0
  665. package/dist/vendor/engine/runtime/agent/agent-loop.d.ts +23 -0
  666. package/dist/vendor/engine/runtime/agent/agent-loop.js +601 -0
  667. package/dist/vendor/engine/runtime/agent/agent.d.ts +130 -0
  668. package/dist/vendor/engine/runtime/agent/agent.js +430 -0
  669. package/dist/vendor/engine/runtime/agent/harness/agent-harness.d.ts +715 -0
  670. package/dist/vendor/engine/runtime/agent/harness/agent-harness.js +5 -0
  671. package/dist/vendor/engine/runtime/agent/harness/compaction/branch-summarization.d.ts +67 -0
  672. package/dist/vendor/engine/runtime/agent/harness/compaction/branch-summarization.js +175 -0
  673. package/dist/vendor/engine/runtime/agent/harness/compaction/compaction.d.ts +125 -0
  674. package/dist/vendor/engine/runtime/agent/harness/compaction/compaction.js +559 -0
  675. package/dist/vendor/engine/runtime/agent/harness/compaction/utils.d.ts +24 -0
  676. package/dist/vendor/engine/runtime/agent/harness/compaction/utils.js +119 -0
  677. package/dist/vendor/engine/runtime/agent/harness/config.d.ts +8 -0
  678. package/dist/vendor/engine/runtime/agent/harness/config.js +34 -0
  679. package/dist/vendor/engine/runtime/agent/harness/context.d.ts +8 -0
  680. package/dist/vendor/engine/runtime/agent/harness/context.js +12 -0
  681. package/dist/vendor/engine/runtime/agent/harness/events.d.ts +24 -0
  682. package/dist/vendor/engine/runtime/agent/harness/events.js +249 -0
  683. package/dist/vendor/engine/runtime/agent/harness/execution/assistant.d.ts +41 -0
  684. package/dist/vendor/engine/runtime/agent/harness/execution/assistant.js +81 -0
  685. package/dist/vendor/engine/runtime/agent/harness/execution/effect-gate.d.ts +21 -0
  686. package/dist/vendor/engine/runtime/agent/harness/execution/effect-gate.js +48 -0
  687. package/dist/vendor/engine/runtime/agent/harness/execution/tools.d.ts +66 -0
  688. package/dist/vendor/engine/runtime/agent/harness/execution/tools.js +118 -0
  689. package/dist/vendor/engine/runtime/agent/harness/hooks.d.ts +37 -0
  690. package/dist/vendor/engine/runtime/agent/harness/hooks.js +405 -0
  691. package/dist/vendor/engine/runtime/agent/harness/messages.d.ts +50 -0
  692. package/dist/vendor/engine/runtime/agent/harness/messages.js +102 -0
  693. package/dist/vendor/engine/runtime/agent/harness/prompt-templates.d.ts +48 -0
  694. package/dist/vendor/engine/runtime/agent/harness/prompt-templates.js +224 -0
  695. package/dist/vendor/engine/runtime/agent/harness/result.d.ts +132 -0
  696. package/dist/vendor/engine/runtime/agent/harness/result.js +80 -0
  697. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/boundary.d.ts +27 -0
  698. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/boundary.js +172 -0
  699. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/checkpoint.d.ts +7 -0
  700. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/checkpoint.js +132 -0
  701. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/deferred.d.ts +14 -0
  702. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/deferred.js +178 -0
  703. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/generation.d.ts +7 -0
  704. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/generation.js +204 -0
  705. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/reconcile.d.ts +4 -0
  706. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/reconcile.js +139 -0
  707. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/recovery.d.ts +7 -0
  708. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/recovery.js +84 -0
  709. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/response.d.ts +22 -0
  710. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/response.js +393 -0
  711. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/retry.d.ts +3 -0
  712. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/retry.js +33 -0
  713. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/structural.d.ts +31 -0
  714. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/structural.js +928 -0
  715. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/terminal.d.ts +6 -0
  716. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/terminal.js +48 -0
  717. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/tool-placement.d.ts +13 -0
  718. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/tool-placement.js +218 -0
  719. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/tools.d.ts +5 -0
  720. package/dist/vendor/engine/runtime/agent/harness/runtime/drive/tools.js +448 -0
  721. package/dist/vendor/engine/runtime/agent/harness/runtime/drive.d.ts +5 -0
  722. package/dist/vendor/engine/runtime/agent/harness/runtime/drive.js +92 -0
  723. package/dist/vendor/engine/runtime/agent/harness/runtime/harness.d.ts +58 -0
  724. package/dist/vendor/engine/runtime/agent/harness/runtime/harness.js +310 -0
  725. package/dist/vendor/engine/runtime/agent/harness/runtime/lane.d.ts +117 -0
  726. package/dist/vendor/engine/runtime/agent/harness/runtime/lane.js +1574 -0
  727. package/dist/vendor/engine/runtime/agent/harness/runtime/progress.d.ts +14 -0
  728. package/dist/vendor/engine/runtime/agent/harness/runtime/progress.js +65 -0
  729. package/dist/vendor/engine/runtime/agent/harness/runtime/reducer.d.ts +4 -0
  730. package/dist/vendor/engine/runtime/agent/harness/runtime/reducer.js +239 -0
  731. package/dist/vendor/engine/runtime/agent/harness/runtime/restore.d.ts +23 -0
  732. package/dist/vendor/engine/runtime/agent/harness/runtime/restore.js +116 -0
  733. package/dist/vendor/engine/runtime/agent/harness/runtime/transcript.d.ts +20 -0
  734. package/dist/vendor/engine/runtime/agent/harness/runtime/transcript.js +71 -0
  735. package/dist/vendor/engine/runtime/agent/harness/runtime/types.d.ts +104 -0
  736. package/dist/vendor/engine/runtime/agent/harness/runtime/types.js +60 -0
  737. package/dist/vendor/engine/runtime/agent/harness/session/commit.d.ts +52 -0
  738. package/dist/vendor/engine/runtime/agent/harness/session/commit.js +56 -0
  739. package/dist/vendor/engine/runtime/agent/harness/session/context.d.ts +9 -0
  740. package/dist/vendor/engine/runtime/agent/harness/session/context.js +48 -0
  741. package/dist/vendor/engine/runtime/agent/harness/session/fork-policy.d.ts +20 -0
  742. package/dist/vendor/engine/runtime/agent/harness/session/fork-policy.js +54 -0
  743. package/dist/vendor/engine/runtime/agent/harness/session/fork.d.ts +15 -0
  744. package/dist/vendor/engine/runtime/agent/harness/session/fork.js +78 -0
  745. package/dist/vendor/engine/runtime/agent/harness/session/in-memory-storage-state.d.ts +38 -0
  746. package/dist/vendor/engine/runtime/agent/harness/session/in-memory-storage-state.js +275 -0
  747. package/dist/vendor/engine/runtime/agent/harness/session/index.d.ts +10 -0
  748. package/dist/vendor/engine/runtime/agent/harness/session/index.js +8 -0
  749. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/codec.d.ts +20 -0
  750. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/codec.js +44 -0
  751. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/fork.d.ts +37 -0
  752. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/fork.js +263 -0
  753. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/index.d.ts +3 -0
  754. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/index.js +3 -0
  755. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/io.d.ts +13 -0
  756. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/io.js +85 -0
  757. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/legacy-v3.d.ts +43 -0
  758. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/legacy-v3.js +461 -0
  759. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/repo.d.ts +34 -0
  760. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/repo.js +300 -0
  761. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/storage.d.ts +40 -0
  762. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/storage.js +199 -0
  763. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/types.d.ts +38 -0
  764. package/dist/vendor/engine/runtime/agent/harness/session/jsonl/types.js +2 -0
  765. package/dist/vendor/engine/runtime/agent/harness/session/memory.d.ts +47 -0
  766. package/dist/vendor/engine/runtime/agent/harness/session/memory.js +368 -0
  767. package/dist/vendor/engine/runtime/agent/harness/session/mutation-line.d.ts +7 -0
  768. package/dist/vendor/engine/runtime/agent/harness/session/mutation-line.js +20 -0
  769. package/dist/vendor/engine/runtime/agent/harness/session/session.d.ts +81 -0
  770. package/dist/vendor/engine/runtime/agent/harness/session/session.js +360 -0
  771. package/dist/vendor/engine/runtime/agent/harness/session/types.d.ts +511 -0
  772. package/dist/vendor/engine/runtime/agent/harness/session/types.js +8 -0
  773. package/dist/vendor/engine/runtime/agent/harness/session/values.d.ts +94 -0
  774. package/dist/vendor/engine/runtime/agent/harness/session/values.js +80 -0
  775. package/dist/vendor/engine/runtime/agent/harness/skills.d.ts +45 -0
  776. package/dist/vendor/engine/runtime/agent/harness/skills.js +325 -0
  777. package/dist/vendor/engine/runtime/agent/harness/system-prompt.d.ts +2 -0
  778. package/dist/vendor/engine/runtime/agent/harness/system-prompt.js +29 -0
  779. package/dist/vendor/engine/runtime/agent/harness/telemetry.d.ts +1241 -0
  780. package/dist/vendor/engine/runtime/agent/harness/telemetry.js +526 -0
  781. package/dist/vendor/engine/runtime/agent/harness/tools/bash.d.ts +26 -0
  782. package/dist/vendor/engine/runtime/agent/harness/tools/bash.js +104 -0
  783. package/dist/vendor/engine/runtime/agent/harness/tools/edit-diff.d.ts +88 -0
  784. package/dist/vendor/engine/runtime/agent/harness/tools/edit-diff.js +385 -0
  785. package/dist/vendor/engine/runtime/agent/harness/tools/edit.d.ts +18 -0
  786. package/dist/vendor/engine/runtime/agent/harness/tools/edit.js +107 -0
  787. package/dist/vendor/engine/runtime/agent/harness/tools/file-mutation-queue.d.ts +4 -0
  788. package/dist/vendor/engine/runtime/agent/harness/tools/file-mutation-queue.js +45 -0
  789. package/dist/vendor/engine/runtime/agent/harness/tools/image.d.ts +2 -0
  790. package/dist/vendor/engine/runtime/agent/harness/tools/image.js +105 -0
  791. package/dist/vendor/engine/runtime/agent/harness/tools/index.d.ts +5 -0
  792. package/dist/vendor/engine/runtime/agent/harness/tools/index.js +4 -0
  793. package/dist/vendor/engine/runtime/agent/harness/tools/path-utils.d.ts +4 -0
  794. package/dist/vendor/engine/runtime/agent/harness/tools/path-utils.js +25 -0
  795. package/dist/vendor/engine/runtime/agent/harness/tools/read.d.ts +34 -0
  796. package/dist/vendor/engine/runtime/agent/harness/tools/read.js +107 -0
  797. package/dist/vendor/engine/runtime/agent/harness/tools/tool-context.d.ts +5 -0
  798. package/dist/vendor/engine/runtime/agent/harness/tools/tool-context.js +1 -0
  799. package/dist/vendor/engine/runtime/agent/harness/tools/write.d.ts +10 -0
  800. package/dist/vendor/engine/runtime/agent/harness/tools/write.js +30 -0
  801. package/dist/vendor/engine/runtime/agent/harness/types.d.ts +304 -0
  802. package/dist/vendor/engine/runtime/agent/harness/types.js +74 -0
  803. package/dist/vendor/engine/runtime/agent/harness/utils/adaptive-publisher.d.ts +23 -0
  804. package/dist/vendor/engine/runtime/agent/harness/utils/adaptive-publisher.js +78 -0
  805. package/dist/vendor/engine/runtime/agent/harness/utils/output-capture.d.ts +30 -0
  806. package/dist/vendor/engine/runtime/agent/harness/utils/output-capture.js +216 -0
  807. package/dist/vendor/engine/runtime/agent/harness/utils/shell-output.d.ts +28 -0
  808. package/dist/vendor/engine/runtime/agent/harness/utils/shell-output.js +70 -0
  809. package/dist/vendor/engine/runtime/agent/harness/utils/truncate.d.ts +70 -0
  810. package/dist/vendor/engine/runtime/agent/harness/utils/truncate.js +295 -0
  811. package/dist/vendor/engine/runtime/agent/harness/utils/usage.d.ts +3 -0
  812. package/dist/vendor/engine/runtime/agent/harness/utils/usage.js +32 -0
  813. package/dist/vendor/engine/runtime/agent/index.d.ts +27 -0
  814. package/dist/vendor/engine/runtime/agent/index.js +25 -0
  815. package/dist/vendor/engine/runtime/agent/proxy.d.ts +71 -0
  816. package/dist/vendor/engine/runtime/agent/proxy.js +309 -0
  817. package/dist/vendor/engine/runtime/agent/search/index.d.ts +28 -0
  818. package/dist/vendor/engine/runtime/agent/search/index.js +1 -0
  819. package/dist/vendor/engine/runtime/agent/stream-fn.d.ts +9 -0
  820. package/dist/vendor/engine/runtime/agent/stream-fn.js +16 -0
  821. package/dist/vendor/engine/runtime/agent/types.d.ts +431 -0
  822. package/dist/vendor/engine/runtime/agent/types.js +1 -0
  823. package/dist/vendor/engine/runtime/ai/api/anthropic-messages.d.ts +70 -0
  824. package/dist/vendor/engine/runtime/ai/api/anthropic-messages.js +1204 -0
  825. package/dist/vendor/engine/runtime/ai/api/anthropic-messages.lazy.d.ts +2 -0
  826. package/dist/vendor/engine/runtime/ai/api/anthropic-messages.lazy.js +2 -0
  827. package/dist/vendor/engine/runtime/ai/api/azure-openai-responses.d.ts +16 -0
  828. package/dist/vendor/engine/runtime/ai/api/azure-openai-responses.js +260 -0
  829. package/dist/vendor/engine/runtime/ai/api/azure-openai-responses.lazy.d.ts +2 -0
  830. package/dist/vendor/engine/runtime/ai/api/azure-openai-responses.lazy.js +2 -0
  831. package/dist/vendor/engine/runtime/ai/api/bedrock-converse-stream.d.ts +37 -0
  832. package/dist/vendor/engine/runtime/ai/api/bedrock-converse-stream.js +1091 -0
  833. package/dist/vendor/engine/runtime/ai/api/bedrock-converse-stream.lazy.d.ts +9 -0
  834. package/dist/vendor/engine/runtime/ai/api/bedrock-converse-stream.lazy.js +21 -0
  835. package/dist/vendor/engine/runtime/ai/api/constrained-sampling.d.ts +19 -0
  836. package/dist/vendor/engine/runtime/ai/api/constrained-sampling.js +221 -0
  837. package/dist/vendor/engine/runtime/ai/api/github-copilot-headers.d.ts +7 -0
  838. package/dist/vendor/engine/runtime/ai/api/github-copilot-headers.js +28 -0
  839. package/dist/vendor/engine/runtime/ai/api/google-generative-ai.d.ts +12 -0
  840. package/dist/vendor/engine/runtime/ai/api/google-generative-ai.js +368 -0
  841. package/dist/vendor/engine/runtime/ai/api/google-generative-ai.lazy.d.ts +2 -0
  842. package/dist/vendor/engine/runtime/ai/api/google-generative-ai.lazy.js +2 -0
  843. package/dist/vendor/engine/runtime/ai/api/google-shared.d.ts +92 -0
  844. package/dist/vendor/engine/runtime/ai/api/google-shared.js +450 -0
  845. package/dist/vendor/engine/runtime/ai/api/google-vertex.d.ts +14 -0
  846. package/dist/vendor/engine/runtime/ai/api/google-vertex.js +429 -0
  847. package/dist/vendor/engine/runtime/ai/api/google-vertex.lazy.d.ts +2 -0
  848. package/dist/vendor/engine/runtime/ai/api/google-vertex.lazy.js +2 -0
  849. package/dist/vendor/engine/runtime/ai/api/lazy.d.ts +24 -0
  850. package/dist/vendor/engine/runtime/ai/api/lazy.js +69 -0
  851. package/dist/vendor/engine/runtime/ai/api/mistral-conversations.d.ts +24 -0
  852. package/dist/vendor/engine/runtime/ai/api/mistral-conversations.js +747 -0
  853. package/dist/vendor/engine/runtime/ai/api/mistral-conversations.lazy.d.ts +2 -0
  854. package/dist/vendor/engine/runtime/ai/api/mistral-conversations.lazy.js +2 -0
  855. package/dist/vendor/engine/runtime/ai/api/openai-codex-responses.d.ts +30 -0
  856. package/dist/vendor/engine/runtime/ai/api/openai-codex-responses.js +1302 -0
  857. package/dist/vendor/engine/runtime/ai/api/openai-codex-responses.lazy.d.ts +2 -0
  858. package/dist/vendor/engine/runtime/ai/api/openai-codex-responses.lazy.js +2 -0
  859. package/dist/vendor/engine/runtime/ai/api/openai-completions.d.ts +25 -0
  860. package/dist/vendor/engine/runtime/ai/api/openai-completions.js +1339 -0
  861. package/dist/vendor/engine/runtime/ai/api/openai-completions.lazy.d.ts +2 -0
  862. package/dist/vendor/engine/runtime/ai/api/openai-completions.lazy.js +2 -0
  863. package/dist/vendor/engine/runtime/ai/api/openai-prompt-cache.d.ts +2 -0
  864. package/dist/vendor/engine/runtime/ai/api/openai-prompt-cache.js +9 -0
  865. package/dist/vendor/engine/runtime/ai/api/openai-responses-shared.d.ts +27 -0
  866. package/dist/vendor/engine/runtime/ai/api/openai-responses-shared.js +688 -0
  867. package/dist/vendor/engine/runtime/ai/api/openai-responses.d.ts +13 -0
  868. package/dist/vendor/engine/runtime/ai/api/openai-responses.js +292 -0
  869. package/dist/vendor/engine/runtime/ai/api/openai-responses.lazy.d.ts +2 -0
  870. package/dist/vendor/engine/runtime/ai/api/openai-responses.lazy.js +2 -0
  871. package/dist/vendor/engine/runtime/ai/api/openrouter-images.d.ts +2 -0
  872. package/dist/vendor/engine/runtime/ai/api/openrouter-images.js +131 -0
  873. package/dist/vendor/engine/runtime/ai/api/openrouter-images.lazy.d.ts +2 -0
  874. package/dist/vendor/engine/runtime/ai/api/openrouter-images.lazy.js +3 -0
  875. package/dist/vendor/engine/runtime/ai/api/pi-messages.d.ts +98 -0
  876. package/dist/vendor/engine/runtime/ai/api/pi-messages.js +312 -0
  877. package/dist/vendor/engine/runtime/ai/api/pi-messages.lazy.d.ts +2 -0
  878. package/dist/vendor/engine/runtime/ai/api/pi-messages.lazy.js +2 -0
  879. package/dist/vendor/engine/runtime/ai/api/simple-options.d.ts +14 -0
  880. package/dist/vendor/engine/runtime/ai/api/simple-options.js +65 -0
  881. package/dist/vendor/engine/runtime/ai/api/transform-messages.d.ts +7 -0
  882. package/dist/vendor/engine/runtime/ai/api/transform-messages.js +200 -0
  883. package/dist/vendor/engine/runtime/ai/auth/context.d.ts +6 -0
  884. package/dist/vendor/engine/runtime/ai/auth/context.js +33 -0
  885. package/dist/vendor/engine/runtime/ai/auth/credential-store.d.ts +16 -0
  886. package/dist/vendor/engine/runtime/ai/auth/credential-store.js +50 -0
  887. package/dist/vendor/engine/runtime/ai/auth/helpers.d.ts +21 -0
  888. package/dist/vendor/engine/runtime/ai/auth/helpers.js +52 -0
  889. package/dist/vendor/engine/runtime/ai/auth/oauth/load.d.ts +28 -0
  890. package/dist/vendor/engine/runtime/ai/auth/oauth/load.js +55 -0
  891. package/dist/vendor/engine/runtime/ai/auth/resolve.d.ts +26 -0
  892. package/dist/vendor/engine/runtime/ai/auth/resolve.js +131 -0
  893. package/dist/vendor/engine/runtime/ai/auth/types.d.ts +230 -0
  894. package/dist/vendor/engine/runtime/ai/auth/types.js +1 -0
  895. package/dist/vendor/engine/runtime/ai/compat/extension-oauth-types.d.ts +38 -0
  896. package/dist/vendor/engine/runtime/ai/compat/extension-oauth-types.js +1 -0
  897. package/dist/vendor/engine/runtime/ai/compat.d.ts +66 -0
  898. package/dist/vendor/engine/runtime/ai/compat.js +201 -0
  899. package/dist/vendor/engine/runtime/ai/env-api-keys.d.ts +20 -0
  900. package/dist/vendor/engine/runtime/ai/env-api-keys.js +148 -0
  901. package/dist/vendor/engine/runtime/ai/image-models.d.ts +9 -0
  902. package/dist/vendor/engine/runtime/ai/image-models.generated.d.ts +814 -0
  903. package/dist/vendor/engine/runtime/ai/image-models.generated.js +816 -0
  904. package/dist/vendor/engine/runtime/ai/image-models.js +22 -0
  905. package/dist/vendor/engine/runtime/ai/images-api-registry.d.ts +13 -0
  906. package/dist/vendor/engine/runtime/ai/images-api-registry.js +21 -0
  907. package/dist/vendor/engine/runtime/ai/images-models.d.ts +94 -0
  908. package/dist/vendor/engine/runtime/ai/images-models.js +142 -0
  909. package/dist/vendor/engine/runtime/ai/images.d.ts +3 -0
  910. package/dist/vendor/engine/runtime/ai/images.js +13 -0
  911. package/dist/vendor/engine/runtime/ai/index.d.ts +36 -0
  912. package/dist/vendor/engine/runtime/ai/index.js +23 -0
  913. package/dist/vendor/engine/runtime/ai/legacy-api-aliases.d.ts +41 -0
  914. package/dist/vendor/engine/runtime/ai/legacy-api-aliases.js +48 -0
  915. package/dist/vendor/engine/runtime/ai/model-catalog.d.ts +16 -0
  916. package/dist/vendor/engine/runtime/ai/model-catalog.js +3 -0
  917. package/dist/vendor/engine/runtime/ai/models-store.d.ts +28 -0
  918. package/dist/vendor/engine/runtime/ai/models-store.js +16 -0
  919. package/dist/vendor/engine/runtime/ai/models.d.ts +201 -0
  920. package/dist/vendor/engine/runtime/ai/models.generated.d.ts +84 -0
  921. package/dist/vendor/engine/runtime/ai/models.generated.js +86 -0
  922. package/dist/vendor/engine/runtime/ai/models.js +593 -0
  923. package/dist/vendor/engine/runtime/ai/oauth.d.ts +2 -0
  924. package/dist/vendor/engine/runtime/ai/oauth.js +1 -0
  925. package/dist/vendor/engine/runtime/ai/providers/all.d.ts +27 -0
  926. package/dist/vendor/engine/runtime/ai/providers/all.js +132 -0
  927. package/dist/vendor/engine/runtime/ai/providers/amazon-bedrock.d.ts +2 -0
  928. package/dist/vendor/engine/runtime/ai/providers/amazon-bedrock.js +92 -0
  929. package/dist/vendor/engine/runtime/ai/providers/amazon-bedrock.models.d.ts +3 -0
  930. package/dist/vendor/engine/runtime/ai/providers/amazon-bedrock.models.js +5 -0
  931. package/dist/vendor/engine/runtime/ai/providers/ant-ling.d.ts +2 -0
  932. package/dist/vendor/engine/runtime/ai/providers/ant-ling.js +14 -0
  933. package/dist/vendor/engine/runtime/ai/providers/ant-ling.models.d.ts +3 -0
  934. package/dist/vendor/engine/runtime/ai/providers/ant-ling.models.js +5 -0
  935. package/dist/vendor/engine/runtime/ai/providers/anthropic.d.ts +2 -0
  936. package/dist/vendor/engine/runtime/ai/providers/anthropic.js +55 -0
  937. package/dist/vendor/engine/runtime/ai/providers/anthropic.models.d.ts +3 -0
  938. package/dist/vendor/engine/runtime/ai/providers/anthropic.models.js +5 -0
  939. package/dist/vendor/engine/runtime/ai/providers/azure-openai-responses.d.ts +2 -0
  940. package/dist/vendor/engine/runtime/ai/providers/azure-openai-responses.js +13 -0
  941. package/dist/vendor/engine/runtime/ai/providers/azure-openai-responses.models.d.ts +3 -0
  942. package/dist/vendor/engine/runtime/ai/providers/azure-openai-responses.models.js +5 -0
  943. package/dist/vendor/engine/runtime/ai/providers/baseten.d.ts +2 -0
  944. package/dist/vendor/engine/runtime/ai/providers/baseten.js +14 -0
  945. package/dist/vendor/engine/runtime/ai/providers/baseten.models.d.ts +3 -0
  946. package/dist/vendor/engine/runtime/ai/providers/baseten.models.js +5 -0
  947. package/dist/vendor/engine/runtime/ai/providers/cerebras.d.ts +2 -0
  948. package/dist/vendor/engine/runtime/ai/providers/cerebras.js +14 -0
  949. package/dist/vendor/engine/runtime/ai/providers/cerebras.models.d.ts +3 -0
  950. package/dist/vendor/engine/runtime/ai/providers/cerebras.models.js +5 -0
  951. package/dist/vendor/engine/runtime/ai/providers/cloudflare-ai-gateway.d.ts +4 -0
  952. package/dist/vendor/engine/runtime/ai/providers/cloudflare-ai-gateway.js +24 -0
  953. package/dist/vendor/engine/runtime/ai/providers/cloudflare-ai-gateway.models.d.ts +3 -0
  954. package/dist/vendor/engine/runtime/ai/providers/cloudflare-ai-gateway.models.js +5 -0
  955. package/dist/vendor/engine/runtime/ai/providers/cloudflare-auth.d.ts +3 -0
  956. package/dist/vendor/engine/runtime/ai/providers/cloudflare-auth.js +85 -0
  957. package/dist/vendor/engine/runtime/ai/providers/cloudflare-stream.d.ts +7 -0
  958. package/dist/vendor/engine/runtime/ai/providers/cloudflare-stream.js +20 -0
  959. package/dist/vendor/engine/runtime/ai/providers/cloudflare-workers-ai.d.ts +2 -0
  960. package/dist/vendor/engine/runtime/ai/providers/cloudflare-workers-ai.js +14 -0
  961. package/dist/vendor/engine/runtime/ai/providers/cloudflare-workers-ai.models.d.ts +3 -0
  962. package/dist/vendor/engine/runtime/ai/providers/cloudflare-workers-ai.models.js +5 -0
  963. package/dist/vendor/engine/runtime/ai/providers/data/.manifest.json +1 -0
  964. package/dist/vendor/engine/runtime/ai/providers/data/amazon-bedrock.json +1 -0
  965. package/dist/vendor/engine/runtime/ai/providers/data/ant-ling.json +1 -0
  966. package/dist/vendor/engine/runtime/ai/providers/data/anthropic.json +1 -0
  967. package/dist/vendor/engine/runtime/ai/providers/data/azure-openai-responses.json +1 -0
  968. package/dist/vendor/engine/runtime/ai/providers/data/baseten.json +1 -0
  969. package/dist/vendor/engine/runtime/ai/providers/data/cerebras.json +1 -0
  970. package/dist/vendor/engine/runtime/ai/providers/data/cloudflare-ai-gateway.json +1 -0
  971. package/dist/vendor/engine/runtime/ai/providers/data/cloudflare-workers-ai.json +1 -0
  972. package/dist/vendor/engine/runtime/ai/providers/data/deepseek.json +1 -0
  973. package/dist/vendor/engine/runtime/ai/providers/data/fireworks.json +1 -0
  974. package/dist/vendor/engine/runtime/ai/providers/data/github-copilot.json +1 -0
  975. package/dist/vendor/engine/runtime/ai/providers/data/google-vertex.json +1 -0
  976. package/dist/vendor/engine/runtime/ai/providers/data/google.json +1 -0
  977. package/dist/vendor/engine/runtime/ai/providers/data/groq.json +1 -0
  978. package/dist/vendor/engine/runtime/ai/providers/data/huggingface.json +1 -0
  979. package/dist/vendor/engine/runtime/ai/providers/data/kimi-coding.json +1 -0
  980. package/dist/vendor/engine/runtime/ai/providers/data/meta.json +1 -0
  981. package/dist/vendor/engine/runtime/ai/providers/data/minimax-cn.json +1 -0
  982. package/dist/vendor/engine/runtime/ai/providers/data/minimax.json +1 -0
  983. package/dist/vendor/engine/runtime/ai/providers/data/mistral.json +1 -0
  984. package/dist/vendor/engine/runtime/ai/providers/data/moonshotai-cn.json +1 -0
  985. package/dist/vendor/engine/runtime/ai/providers/data/moonshotai.json +1 -0
  986. package/dist/vendor/engine/runtime/ai/providers/data/nvidia.json +1 -0
  987. package/dist/vendor/engine/runtime/ai/providers/data/openai-codex.json +1 -0
  988. package/dist/vendor/engine/runtime/ai/providers/data/openai.json +1 -0
  989. package/dist/vendor/engine/runtime/ai/providers/data/opencode-go.json +1 -0
  990. package/dist/vendor/engine/runtime/ai/providers/data/opencode.json +1 -0
  991. package/dist/vendor/engine/runtime/ai/providers/data/openrouter.json +1 -0
  992. package/dist/vendor/engine/runtime/ai/providers/data/qwen-token-plan-cn.json +1 -0
  993. package/dist/vendor/engine/runtime/ai/providers/data/qwen-token-plan-individual.json +1 -0
  994. package/dist/vendor/engine/runtime/ai/providers/data/qwen-token-plan.json +1 -0
  995. package/dist/vendor/engine/runtime/ai/providers/data/radius.json +1 -0
  996. package/dist/vendor/engine/runtime/ai/providers/data/together.json +1 -0
  997. package/dist/vendor/engine/runtime/ai/providers/data/vercel-ai-gateway.json +1 -0
  998. package/dist/vendor/engine/runtime/ai/providers/data/xai.json +1 -0
  999. package/dist/vendor/engine/runtime/ai/providers/data/xiaomi-token-plan-ams.json +1 -0
  1000. package/dist/vendor/engine/runtime/ai/providers/data/xiaomi-token-plan-cn.json +1 -0
  1001. package/dist/vendor/engine/runtime/ai/providers/data/xiaomi-token-plan-sgp.json +1 -0
  1002. package/dist/vendor/engine/runtime/ai/providers/data/xiaomi.json +1 -0
  1003. package/dist/vendor/engine/runtime/ai/providers/data/zai-coding-cn.json +1 -0
  1004. package/dist/vendor/engine/runtime/ai/providers/data/zai.json +1 -0
  1005. package/dist/vendor/engine/runtime/ai/providers/deepseek.d.ts +2 -0
  1006. package/dist/vendor/engine/runtime/ai/providers/deepseek.js +14 -0
  1007. package/dist/vendor/engine/runtime/ai/providers/deepseek.models.d.ts +3 -0
  1008. package/dist/vendor/engine/runtime/ai/providers/deepseek.models.js +5 -0
  1009. package/dist/vendor/engine/runtime/ai/providers/faux.d.ts +102 -0
  1010. package/dist/vendor/engine/runtime/ai/providers/faux.js +488 -0
  1011. package/dist/vendor/engine/runtime/ai/providers/fireworks.d.ts +2 -0
  1012. package/dist/vendor/engine/runtime/ai/providers/fireworks.js +18 -0
  1013. package/dist/vendor/engine/runtime/ai/providers/fireworks.models.d.ts +3 -0
  1014. package/dist/vendor/engine/runtime/ai/providers/fireworks.models.js +5 -0
  1015. package/dist/vendor/engine/runtime/ai/providers/github-copilot.d.ts +2 -0
  1016. package/dist/vendor/engine/runtime/ai/providers/github-copilot.js +34 -0
  1017. package/dist/vendor/engine/runtime/ai/providers/github-copilot.models.d.ts +3 -0
  1018. package/dist/vendor/engine/runtime/ai/providers/github-copilot.models.js +5 -0
  1019. package/dist/vendor/engine/runtime/ai/providers/google-vertex.d.ts +2 -0
  1020. package/dist/vendor/engine/runtime/ai/providers/google-vertex.js +93 -0
  1021. package/dist/vendor/engine/runtime/ai/providers/google-vertex.models.d.ts +3 -0
  1022. package/dist/vendor/engine/runtime/ai/providers/google-vertex.models.js +5 -0
  1023. package/dist/vendor/engine/runtime/ai/providers/google.d.ts +2 -0
  1024. package/dist/vendor/engine/runtime/ai/providers/google.js +14 -0
  1025. package/dist/vendor/engine/runtime/ai/providers/google.models.d.ts +3 -0
  1026. package/dist/vendor/engine/runtime/ai/providers/google.models.js +5 -0
  1027. package/dist/vendor/engine/runtime/ai/providers/groq.d.ts +2 -0
  1028. package/dist/vendor/engine/runtime/ai/providers/groq.js +14 -0
  1029. package/dist/vendor/engine/runtime/ai/providers/groq.models.d.ts +3 -0
  1030. package/dist/vendor/engine/runtime/ai/providers/groq.models.js +5 -0
  1031. package/dist/vendor/engine/runtime/ai/providers/huggingface.d.ts +2 -0
  1032. package/dist/vendor/engine/runtime/ai/providers/huggingface.js +14 -0
  1033. package/dist/vendor/engine/runtime/ai/providers/huggingface.models.d.ts +3 -0
  1034. package/dist/vendor/engine/runtime/ai/providers/huggingface.models.js +5 -0
  1035. package/dist/vendor/engine/runtime/ai/providers/images/register-builtins.d.ts +3 -0
  1036. package/dist/vendor/engine/runtime/ai/providers/images/register-builtins.js +33 -0
  1037. package/dist/vendor/engine/runtime/ai/providers/kimi-coding.d.ts +2 -0
  1038. package/dist/vendor/engine/runtime/ai/providers/kimi-coding.js +23 -0
  1039. package/dist/vendor/engine/runtime/ai/providers/kimi-coding.models.d.ts +3 -0
  1040. package/dist/vendor/engine/runtime/ai/providers/kimi-coding.models.js +5 -0
  1041. package/dist/vendor/engine/runtime/ai/providers/meta.d.ts +2 -0
  1042. package/dist/vendor/engine/runtime/ai/providers/meta.js +23 -0
  1043. package/dist/vendor/engine/runtime/ai/providers/meta.models.d.ts +3 -0
  1044. package/dist/vendor/engine/runtime/ai/providers/meta.models.js +5 -0
  1045. package/dist/vendor/engine/runtime/ai/providers/minimax-cn.d.ts +2 -0
  1046. package/dist/vendor/engine/runtime/ai/providers/minimax-cn.js +14 -0
  1047. package/dist/vendor/engine/runtime/ai/providers/minimax-cn.models.d.ts +3 -0
  1048. package/dist/vendor/engine/runtime/ai/providers/minimax-cn.models.js +5 -0
  1049. package/dist/vendor/engine/runtime/ai/providers/minimax.d.ts +2 -0
  1050. package/dist/vendor/engine/runtime/ai/providers/minimax.js +14 -0
  1051. package/dist/vendor/engine/runtime/ai/providers/minimax.models.d.ts +3 -0
  1052. package/dist/vendor/engine/runtime/ai/providers/minimax.models.js +5 -0
  1053. package/dist/vendor/engine/runtime/ai/providers/mistral.d.ts +2 -0
  1054. package/dist/vendor/engine/runtime/ai/providers/mistral.js +14 -0
  1055. package/dist/vendor/engine/runtime/ai/providers/mistral.models.d.ts +3 -0
  1056. package/dist/vendor/engine/runtime/ai/providers/mistral.models.js +5 -0
  1057. package/dist/vendor/engine/runtime/ai/providers/moonshotai-cn.d.ts +2 -0
  1058. package/dist/vendor/engine/runtime/ai/providers/moonshotai-cn.js +14 -0
  1059. package/dist/vendor/engine/runtime/ai/providers/moonshotai-cn.models.d.ts +3 -0
  1060. package/dist/vendor/engine/runtime/ai/providers/moonshotai-cn.models.js +5 -0
  1061. package/dist/vendor/engine/runtime/ai/providers/moonshotai.d.ts +2 -0
  1062. package/dist/vendor/engine/runtime/ai/providers/moonshotai.js +14 -0
  1063. package/dist/vendor/engine/runtime/ai/providers/moonshotai.models.d.ts +3 -0
  1064. package/dist/vendor/engine/runtime/ai/providers/moonshotai.models.js +5 -0
  1065. package/dist/vendor/engine/runtime/ai/providers/nvidia.d.ts +2 -0
  1066. package/dist/vendor/engine/runtime/ai/providers/nvidia.js +14 -0
  1067. package/dist/vendor/engine/runtime/ai/providers/nvidia.models.d.ts +3 -0
  1068. package/dist/vendor/engine/runtime/ai/providers/nvidia.models.js +5 -0
  1069. package/dist/vendor/engine/runtime/ai/providers/openai-codex.d.ts +2 -0
  1070. package/dist/vendor/engine/runtime/ai/providers/openai-codex.js +21 -0
  1071. package/dist/vendor/engine/runtime/ai/providers/openai-codex.models.d.ts +3 -0
  1072. package/dist/vendor/engine/runtime/ai/providers/openai-codex.models.js +5 -0
  1073. package/dist/vendor/engine/runtime/ai/providers/openai.d.ts +2 -0
  1074. package/dist/vendor/engine/runtime/ai/providers/openai.js +14 -0
  1075. package/dist/vendor/engine/runtime/ai/providers/openai.models.d.ts +3 -0
  1076. package/dist/vendor/engine/runtime/ai/providers/openai.models.js +5 -0
  1077. package/dist/vendor/engine/runtime/ai/providers/opencode-go.d.ts +2 -0
  1078. package/dist/vendor/engine/runtime/ai/providers/opencode-go.js +20 -0
  1079. package/dist/vendor/engine/runtime/ai/providers/opencode-go.models.d.ts +3 -0
  1080. package/dist/vendor/engine/runtime/ai/providers/opencode-go.models.js +5 -0
  1081. package/dist/vendor/engine/runtime/ai/providers/opencode-headers.d.ts +3 -0
  1082. package/dist/vendor/engine/runtime/ai/providers/opencode-headers.js +21 -0
  1083. package/dist/vendor/engine/runtime/ai/providers/opencode.d.ts +2 -0
  1084. package/dist/vendor/engine/runtime/ai/providers/opencode.js +22 -0
  1085. package/dist/vendor/engine/runtime/ai/providers/opencode.models.d.ts +3 -0
  1086. package/dist/vendor/engine/runtime/ai/providers/opencode.models.js +5 -0
  1087. package/dist/vendor/engine/runtime/ai/providers/openrouter-images.d.ts +2 -0
  1088. package/dist/vendor/engine/runtime/ai/providers/openrouter-images.js +21 -0
  1089. package/dist/vendor/engine/runtime/ai/providers/openrouter.d.ts +2 -0
  1090. package/dist/vendor/engine/runtime/ai/providers/openrouter.js +26 -0
  1091. package/dist/vendor/engine/runtime/ai/providers/openrouter.models.d.ts +3 -0
  1092. package/dist/vendor/engine/runtime/ai/providers/openrouter.models.js +5 -0
  1093. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-cn.d.ts +2 -0
  1094. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-cn.js +14 -0
  1095. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-cn.models.d.ts +3 -0
  1096. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-cn.models.js +5 -0
  1097. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-individual.d.ts +2 -0
  1098. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-individual.js +14 -0
  1099. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-individual.models.d.ts +3 -0
  1100. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan-individual.models.js +5 -0
  1101. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan.d.ts +2 -0
  1102. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan.js +14 -0
  1103. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan.models.d.ts +3 -0
  1104. package/dist/vendor/engine/runtime/ai/providers/qwen-token-plan.models.js +5 -0
  1105. package/dist/vendor/engine/runtime/ai/providers/radius-config.d.ts +25 -0
  1106. package/dist/vendor/engine/runtime/ai/providers/radius-config.js +62 -0
  1107. package/dist/vendor/engine/runtime/ai/providers/radius.d.ts +8 -0
  1108. package/dist/vendor/engine/runtime/ai/providers/radius.js +77 -0
  1109. package/dist/vendor/engine/runtime/ai/providers/radius.models.d.ts +3 -0
  1110. package/dist/vendor/engine/runtime/ai/providers/radius.models.js +5 -0
  1111. package/dist/vendor/engine/runtime/ai/providers/together.d.ts +2 -0
  1112. package/dist/vendor/engine/runtime/ai/providers/together.js +14 -0
  1113. package/dist/vendor/engine/runtime/ai/providers/together.models.d.ts +3 -0
  1114. package/dist/vendor/engine/runtime/ai/providers/together.models.js +5 -0
  1115. package/dist/vendor/engine/runtime/ai/providers/vercel-ai-gateway.d.ts +2 -0
  1116. package/dist/vendor/engine/runtime/ai/providers/vercel-ai-gateway.js +14 -0
  1117. package/dist/vendor/engine/runtime/ai/providers/vercel-ai-gateway.models.d.ts +3 -0
  1118. package/dist/vendor/engine/runtime/ai/providers/vercel-ai-gateway.models.js +5 -0
  1119. package/dist/vendor/engine/runtime/ai/providers/xai.d.ts +2 -0
  1120. package/dist/vendor/engine/runtime/ai/providers/xai.js +23 -0
  1121. package/dist/vendor/engine/runtime/ai/providers/xai.models.d.ts +3 -0
  1122. package/dist/vendor/engine/runtime/ai/providers/xai.models.js +5 -0
  1123. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-ams.d.ts +2 -0
  1124. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-ams.js +14 -0
  1125. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-ams.models.d.ts +3 -0
  1126. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-ams.models.js +5 -0
  1127. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-cn.d.ts +2 -0
  1128. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-cn.js +14 -0
  1129. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-cn.models.d.ts +3 -0
  1130. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-cn.models.js +5 -0
  1131. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-sgp.d.ts +2 -0
  1132. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-sgp.js +14 -0
  1133. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-sgp.models.d.ts +3 -0
  1134. package/dist/vendor/engine/runtime/ai/providers/xiaomi-token-plan-sgp.models.js +5 -0
  1135. package/dist/vendor/engine/runtime/ai/providers/xiaomi.d.ts +2 -0
  1136. package/dist/vendor/engine/runtime/ai/providers/xiaomi.js +14 -0
  1137. package/dist/vendor/engine/runtime/ai/providers/xiaomi.models.d.ts +3 -0
  1138. package/dist/vendor/engine/runtime/ai/providers/xiaomi.models.js +5 -0
  1139. package/dist/vendor/engine/runtime/ai/providers/zai-coding-cn.d.ts +2 -0
  1140. package/dist/vendor/engine/runtime/ai/providers/zai-coding-cn.js +14 -0
  1141. package/dist/vendor/engine/runtime/ai/providers/zai-coding-cn.models.d.ts +3 -0
  1142. package/dist/vendor/engine/runtime/ai/providers/zai-coding-cn.models.js +5 -0
  1143. package/dist/vendor/engine/runtime/ai/providers/zai.d.ts +2 -0
  1144. package/dist/vendor/engine/runtime/ai/providers/zai.js +14 -0
  1145. package/dist/vendor/engine/runtime/ai/providers/zai.models.d.ts +3 -0
  1146. package/dist/vendor/engine/runtime/ai/providers/zai.models.js +5 -0
  1147. package/dist/vendor/engine/runtime/ai/session-resources.d.ts +3 -0
  1148. package/dist/vendor/engine/runtime/ai/session-resources.js +21 -0
  1149. package/dist/vendor/engine/runtime/ai/types.d.ts +835 -0
  1150. package/dist/vendor/engine/runtime/ai/types.js +1 -0
  1151. package/dist/vendor/engine/runtime/ai/utils/abort-signals.d.ts +5 -0
  1152. package/dist/vendor/engine/runtime/ai/utils/abort-signals.js +33 -0
  1153. package/dist/vendor/engine/runtime/ai/utils/abort.d.ts +7 -0
  1154. package/dist/vendor/engine/runtime/ai/utils/abort.js +48 -0
  1155. package/dist/vendor/engine/runtime/ai/utils/assistant-message-frame.d.ts +76 -0
  1156. package/dist/vendor/engine/runtime/ai/utils/assistant-message-frame.js +424 -0
  1157. package/dist/vendor/engine/runtime/ai/utils/diagnostics.d.ts +19 -0
  1158. package/dist/vendor/engine/runtime/ai/utils/diagnostics.js +24 -0
  1159. package/dist/vendor/engine/runtime/ai/utils/error-body.d.ts +24 -0
  1160. package/dist/vendor/engine/runtime/ai/utils/error-body.js +132 -0
  1161. package/dist/vendor/engine/runtime/ai/utils/estimate.d.ts +16 -0
  1162. package/dist/vendor/engine/runtime/ai/utils/estimate.js +94 -0
  1163. package/dist/vendor/engine/runtime/ai/utils/event-stream.d.ts +20 -0
  1164. package/dist/vendor/engine/runtime/ai/utils/event-stream.js +98 -0
  1165. package/dist/vendor/engine/runtime/ai/utils/hash.d.ts +2 -0
  1166. package/dist/vendor/engine/runtime/ai/utils/hash.js +13 -0
  1167. package/dist/vendor/engine/runtime/ai/utils/headers.d.ts +3 -0
  1168. package/dist/vendor/engine/runtime/ai/utils/headers.js +17 -0
  1169. package/dist/vendor/engine/runtime/ai/utils/json-parse.d.ts +15 -0
  1170. package/dist/vendor/engine/runtime/ai/utils/json-parse.js +112 -0
  1171. package/dist/vendor/engine/runtime/ai/utils/node-http-proxy.d.ts +3 -0
  1172. package/dist/vendor/engine/runtime/ai/utils/node-http-proxy.js +132 -0
  1173. package/dist/vendor/engine/runtime/ai/utils/overflow.d.ts +68 -0
  1174. package/dist/vendor/engine/runtime/ai/utils/overflow.js +177 -0
  1175. package/dist/vendor/engine/runtime/ai/utils/pi-user-agent.d.ts +1 -0
  1176. package/dist/vendor/engine/runtime/ai/utils/pi-user-agent.js +11 -0
  1177. package/dist/vendor/engine/runtime/ai/utils/provider-env.d.ts +6 -0
  1178. package/dist/vendor/engine/runtime/ai/utils/provider-env.js +43 -0
  1179. package/dist/vendor/engine/runtime/ai/utils/provider-retry.d.ts +15 -0
  1180. package/dist/vendor/engine/runtime/ai/utils/provider-retry.js +93 -0
  1181. package/dist/vendor/engine/runtime/ai/utils/retry.d.ts +57 -0
  1182. package/dist/vendor/engine/runtime/ai/utils/retry.js +182 -0
  1183. package/dist/vendor/engine/runtime/ai/utils/sanitize-unicode.d.ts +21 -0
  1184. package/dist/vendor/engine/runtime/ai/utils/sanitize-unicode.js +25 -0
  1185. package/dist/vendor/engine/runtime/ai/utils/text.d.ts +13 -0
  1186. package/dist/vendor/engine/runtime/ai/utils/text.js +35 -0
  1187. package/dist/vendor/engine/runtime/ai/utils/transcript.d.ts +83 -0
  1188. package/dist/vendor/engine/runtime/ai/utils/transcript.js +203 -0
  1189. package/dist/vendor/engine/runtime/ai/utils/typebox-helpers.d.ts +16 -0
  1190. package/dist/vendor/engine/runtime/ai/utils/typebox-helpers.js +20 -0
  1191. package/dist/vendor/engine/runtime/ai/utils/uuid.d.ts +2 -0
  1192. package/dist/vendor/engine/runtime/ai/utils/uuid.js +41 -0
  1193. package/dist/vendor/engine/runtime/ai/utils/validation.d.ts +17 -0
  1194. package/dist/vendor/engine/runtime/ai/utils/validation.js +308 -0
  1195. package/dist/vendor/engine/runtime/chord/api.d.ts +14 -0
  1196. package/dist/vendor/engine/runtime/chord/api.js +71 -0
  1197. package/dist/vendor/engine/runtime/chord/context/index.d.ts +23 -0
  1198. package/dist/vendor/engine/runtime/chord/context/index.js +96 -0
  1199. package/dist/vendor/engine/runtime/chord/delta/index.d.ts +118 -0
  1200. package/dist/vendor/engine/runtime/chord/delta/index.js +1903 -0
  1201. package/dist/vendor/engine/runtime/chord/facets/host.d.ts +11 -0
  1202. package/dist/vendor/engine/runtime/chord/facets/host.js +762 -0
  1203. package/dist/vendor/engine/runtime/chord/facets/loader.d.ts +2 -0
  1204. package/dist/vendor/engine/runtime/chord/facets/loader.js +4 -0
  1205. package/dist/vendor/engine/runtime/chord/index.d.ts +10 -0
  1206. package/dist/vendor/engine/runtime/chord/index.js +9 -0
  1207. package/dist/vendor/engine/runtime/chord/json.d.ts +3 -0
  1208. package/dist/vendor/engine/runtime/chord/json.js +56 -0
  1209. package/dist/vendor/engine/runtime/chord/services/consumer.d.ts +10 -0
  1210. package/dist/vendor/engine/runtime/chord/services/consumer.js +536 -0
  1211. package/dist/vendor/engine/runtime/chord/services/errors.d.ts +7 -0
  1212. package/dist/vendor/engine/runtime/chord/services/errors.js +21 -0
  1213. package/dist/vendor/engine/runtime/chord/services/handle.d.ts +14 -0
  1214. package/dist/vendor/engine/runtime/chord/services/handle.js +100 -0
  1215. package/dist/vendor/engine/runtime/chord/services/instances.d.ts +24 -0
  1216. package/dist/vendor/engine/runtime/chord/services/instances.js +136 -0
  1217. package/dist/vendor/engine/runtime/chord/services/loopback.d.ts +4 -0
  1218. package/dist/vendor/engine/runtime/chord/services/loopback.js +14 -0
  1219. package/dist/vendor/engine/runtime/chord/services/provider.d.ts +36 -0
  1220. package/dist/vendor/engine/runtime/chord/services/provider.js +471 -0
  1221. package/dist/vendor/engine/runtime/chord/services/state-codec.d.ts +14 -0
  1222. package/dist/vendor/engine/runtime/chord/services/state-codec.js +114 -0
  1223. package/dist/vendor/engine/runtime/chord/services/state-internals.d.ts +10 -0
  1224. package/dist/vendor/engine/runtime/chord/services/state-internals.js +9 -0
  1225. package/dist/vendor/engine/runtime/chord/services/state.d.ts +22 -0
  1226. package/dist/vendor/engine/runtime/chord/services/state.js +123 -0
  1227. package/dist/vendor/engine/runtime/chord/services/wire.d.ts +59 -0
  1228. package/dist/vendor/engine/runtime/chord/services/wire.js +172 -0
  1229. package/dist/vendor/engine/runtime/chord/types.d.ts +202 -0
  1230. package/dist/vendor/engine/runtime/chord/types.js +1 -0
  1231. package/dist/vendor/engine/runtime/coding-agent/cli/args.d.ts +60 -0
  1232. package/dist/vendor/engine/runtime/coding-agent/cli/args.js +439 -0
  1233. package/dist/vendor/engine/runtime/coding-agent/cli/auth-check.d.ts +18 -0
  1234. package/dist/vendor/engine/runtime/coding-agent/cli/auth-check.js +49 -0
  1235. package/dist/vendor/engine/runtime/coding-agent/cli/auth-command.d.ts +23 -0
  1236. package/dist/vendor/engine/runtime/coding-agent/cli/auth-command.js +102 -0
  1237. package/dist/vendor/engine/runtime/coding-agent/cli/config-selector.d.ts +15 -0
  1238. package/dist/vendor/engine/runtime/coding-agent/cli/config-selector.js +31 -0
  1239. package/dist/vendor/engine/runtime/coding-agent/cli/credential-print.d.ts +12 -0
  1240. package/dist/vendor/engine/runtime/coding-agent/cli/credential-print.js +75 -0
  1241. package/dist/vendor/engine/runtime/coding-agent/cli/file-processor.d.ts +14 -0
  1242. package/dist/vendor/engine/runtime/coding-agent/cli/file-processor.js +70 -0
  1243. package/dist/vendor/engine/runtime/coding-agent/cli/initial-message.d.ts +17 -0
  1244. package/dist/vendor/engine/runtime/coding-agent/cli/initial-message.js +21 -0
  1245. package/dist/vendor/engine/runtime/coding-agent/cli/list-models.d.ts +8 -0
  1246. package/dist/vendor/engine/runtime/coding-agent/cli/list-models.js +97 -0
  1247. package/dist/vendor/engine/runtime/coding-agent/cli/project-trust.d.ts +9 -0
  1248. package/dist/vendor/engine/runtime/coding-agent/cli/project-trust.js +47 -0
  1249. package/dist/vendor/engine/runtime/coding-agent/cli/session-picker.d.ts +9 -0
  1250. package/dist/vendor/engine/runtime/coding-agent/cli/session-picker.js +35 -0
  1251. package/dist/vendor/engine/runtime/coding-agent/cli/startup-ui.d.ts +19 -0
  1252. package/dist/vendor/engine/runtime/coding-agent/cli/startup-ui.js +184 -0
  1253. package/dist/vendor/engine/runtime/coding-agent/config.d.ts +97 -0
  1254. package/dist/vendor/engine/runtime/coding-agent/config.js +463 -0
  1255. package/dist/vendor/engine/runtime/coding-agent/core/agent-session-runtime.d.ts +118 -0
  1256. package/dist/vendor/engine/runtime/coding-agent/core/agent-session-runtime.js +316 -0
  1257. package/dist/vendor/engine/runtime/coding-agent/core/agent-session-services.d.ts +85 -0
  1258. package/dist/vendor/engine/runtime/coding-agent/core/agent-session-services.js +133 -0
  1259. package/dist/vendor/engine/runtime/coding-agent/core/agent-session.d.ts +771 -0
  1260. package/dist/vendor/engine/runtime/coding-agent/core/agent-session.js +2990 -0
  1261. package/dist/vendor/engine/runtime/coding-agent/core/auth-guidance.d.ts +4 -0
  1262. package/dist/vendor/engine/runtime/coding-agent/core/auth-guidance.js +20 -0
  1263. package/dist/vendor/engine/runtime/coding-agent/core/auth-storage.d.ts +71 -0
  1264. package/dist/vendor/engine/runtime/coding-agent/core/auth-storage.js +425 -0
  1265. package/dist/vendor/engine/runtime/coding-agent/core/bash-executor.d.ts +31 -0
  1266. package/dist/vendor/engine/runtime/coding-agent/core/bash-executor.js +110 -0
  1267. package/dist/vendor/engine/runtime/coding-agent/core/bug-report-upload.d.ts +11 -0
  1268. package/dist/vendor/engine/runtime/coding-agent/core/bug-report-upload.js +21 -0
  1269. package/dist/vendor/engine/runtime/coding-agent/core/bug-report.d.ts +175 -0
  1270. package/dist/vendor/engine/runtime/coding-agent/core/bug-report.js +291 -0
  1271. package/dist/vendor/engine/runtime/coding-agent/core/cache-stats.d.ts +48 -0
  1272. package/dist/vendor/engine/runtime/coding-agent/core/cache-stats.js +111 -0
  1273. package/dist/vendor/engine/runtime/coding-agent/core/cache-warmer.d.ts +102 -0
  1274. package/dist/vendor/engine/runtime/coding-agent/core/cache-warmer.js +355 -0
  1275. package/dist/vendor/engine/runtime/coding-agent/core/compaction/branch-summarization.d.ts +97 -0
  1276. package/dist/vendor/engine/runtime/coding-agent/core/compaction/branch-summarization.js +250 -0
  1277. package/dist/vendor/engine/runtime/coding-agent/core/compaction/compaction.d.ts +142 -0
  1278. package/dist/vendor/engine/runtime/coding-agent/core/compaction/compaction.js +666 -0
  1279. package/dist/vendor/engine/runtime/coding-agent/core/compaction/index.d.ts +6 -0
  1280. package/dist/vendor/engine/runtime/coding-agent/core/compaction/index.js +6 -0
  1281. package/dist/vendor/engine/runtime/coding-agent/core/compaction/utils.d.ts +37 -0
  1282. package/dist/vendor/engine/runtime/coding-agent/core/compaction/utils.js +141 -0
  1283. package/dist/vendor/engine/runtime/coding-agent/core/crash-log.d.ts +26 -0
  1284. package/dist/vendor/engine/runtime/coding-agent/core/crash-log.js +138 -0
  1285. package/dist/vendor/engine/runtime/coding-agent/core/defaults.d.ts +3 -0
  1286. package/dist/vendor/engine/runtime/coding-agent/core/defaults.js +10 -0
  1287. package/dist/vendor/engine/runtime/coding-agent/core/diagnostics.d.ts +14 -0
  1288. package/dist/vendor/engine/runtime/coding-agent/core/diagnostics.js +1 -0
  1289. package/dist/vendor/engine/runtime/coding-agent/core/event-bus.d.ts +8 -0
  1290. package/dist/vendor/engine/runtime/coding-agent/core/event-bus.js +24 -0
  1291. package/dist/vendor/engine/runtime/coding-agent/core/exec.d.ts +28 -0
  1292. package/dist/vendor/engine/runtime/coding-agent/core/exec.js +74 -0
  1293. package/dist/vendor/engine/runtime/coding-agent/core/experimental.d.ts +1 -0
  1294. package/dist/vendor/engine/runtime/coding-agent/core/experimental.js +3 -0
  1295. package/dist/vendor/engine/runtime/coding-agent/core/export-html/ansi-to-html.d.ts +21 -0
  1296. package/dist/vendor/engine/runtime/coding-agent/core/export-html/ansi-to-html.js +248 -0
  1297. package/dist/vendor/engine/runtime/coding-agent/core/export-html/index.d.ts +36 -0
  1298. package/dist/vendor/engine/runtime/coding-agent/core/export-html/index.js +225 -0
  1299. package/dist/vendor/engine/runtime/coding-agent/core/export-html/template.css +1066 -0
  1300. package/dist/vendor/engine/runtime/coding-agent/core/export-html/template.html +55 -0
  1301. package/dist/vendor/engine/runtime/coding-agent/core/export-html/template.js +1864 -0
  1302. package/dist/vendor/engine/runtime/coding-agent/core/export-html/tool-renderer.d.ts +33 -0
  1303. package/dist/vendor/engine/runtime/coding-agent/core/export-html/tool-renderer.js +107 -0
  1304. package/dist/vendor/engine/runtime/coding-agent/core/export-html/vendor/highlight.min.js +1213 -0
  1305. package/dist/vendor/engine/runtime/coding-agent/core/export-html/vendor/marked.min.js +78 -0
  1306. package/dist/vendor/engine/runtime/coding-agent/core/extensions/index.d.ts +11 -0
  1307. package/dist/vendor/engine/runtime/coding-agent/core/extensions/index.js +8 -0
  1308. package/dist/vendor/engine/runtime/coding-agent/core/extensions/jiti-loader.d.ts +1 -0
  1309. package/dist/vendor/engine/runtime/coding-agent/core/extensions/jiti-loader.js +3 -0
  1310. package/dist/vendor/engine/runtime/coding-agent/core/extensions/jiti-static-loader.d.ts +1 -0
  1311. package/dist/vendor/engine/runtime/coding-agent/core/extensions/jiti-static-loader.js +3 -0
  1312. package/dist/vendor/engine/runtime/coding-agent/core/extensions/loader.d.ts +22 -0
  1313. package/dist/vendor/engine/runtime/coding-agent/core/extensions/loader.js +633 -0
  1314. package/dist/vendor/engine/runtime/coding-agent/core/extensions/runner.d.ts +180 -0
  1315. package/dist/vendor/engine/runtime/coding-agent/core/extensions/runner.js +1028 -0
  1316. package/dist/vendor/engine/runtime/coding-agent/core/extensions/types.d.ts +1362 -0
  1317. package/dist/vendor/engine/runtime/coding-agent/core/extensions/types.js +47 -0
  1318. package/dist/vendor/engine/runtime/coding-agent/core/extensions/virtual-modules.d.ts +2 -0
  1319. package/dist/vendor/engine/runtime/coding-agent/core/extensions/virtual-modules.js +37 -0
  1320. package/dist/vendor/engine/runtime/coding-agent/core/extensions/wrapper.d.ts +19 -0
  1321. package/dist/vendor/engine/runtime/coding-agent/core/extensions/wrapper.js +21 -0
  1322. package/dist/vendor/engine/runtime/coding-agent/core/footer-data-provider.d.ts +63 -0
  1323. package/dist/vendor/engine/runtime/coding-agent/core/footer-data-provider.js +337 -0
  1324. package/dist/vendor/engine/runtime/coding-agent/core/http-dispatcher.d.ts +21 -0
  1325. package/dist/vendor/engine/runtime/coding-agent/core/http-dispatcher.js +97 -0
  1326. package/dist/vendor/engine/runtime/coding-agent/core/keybindings.d.ts +427 -0
  1327. package/dist/vendor/engine/runtime/coding-agent/core/keybindings.js +320 -0
  1328. package/dist/vendor/engine/runtime/coding-agent/core/messages.d.ts +76 -0
  1329. package/dist/vendor/engine/runtime/coding-agent/core/messages.js +123 -0
  1330. package/dist/vendor/engine/runtime/coding-agent/core/model-config.d.ts +723 -0
  1331. package/dist/vendor/engine/runtime/coding-agent/core/model-config.js +281 -0
  1332. package/dist/vendor/engine/runtime/coding-agent/core/model-registry.d.ts +48 -0
  1333. package/dist/vendor/engine/runtime/coding-agent/core/model-registry.js +114 -0
  1334. package/dist/vendor/engine/runtime/coding-agent/core/model-resolver.d.ts +123 -0
  1335. package/dist/vendor/engine/runtime/coding-agent/core/model-resolver.js +589 -0
  1336. package/dist/vendor/engine/runtime/coding-agent/core/model-runtime.d.ts +100 -0
  1337. package/dist/vendor/engine/runtime/coding-agent/core/model-runtime.js +603 -0
  1338. package/dist/vendor/engine/runtime/coding-agent/core/models-store.d.ts +21 -0
  1339. package/dist/vendor/engine/runtime/coding-agent/core/models-store.js +114 -0
  1340. package/dist/vendor/engine/runtime/coding-agent/core/output-guard.d.ts +6 -0
  1341. package/dist/vendor/engine/runtime/coding-agent/core/output-guard.js +88 -0
  1342. package/dist/vendor/engine/runtime/coding-agent/core/package-manager.d.ts +212 -0
  1343. package/dist/vendor/engine/runtime/coding-agent/core/package-manager.js +2176 -0
  1344. package/dist/vendor/engine/runtime/coding-agent/core/pi-manifest.d.ts +7 -0
  1345. package/dist/vendor/engine/runtime/coding-agent/core/pi-manifest.js +25 -0
  1346. package/dist/vendor/engine/runtime/coding-agent/core/project-trust.d.ts +14 -0
  1347. package/dist/vendor/engine/runtime/coding-agent/core/project-trust.js +58 -0
  1348. package/dist/vendor/engine/runtime/coding-agent/core/prompt-templates.d.ts +53 -0
  1349. package/dist/vendor/engine/runtime/coding-agent/core/prompt-templates.js +235 -0
  1350. package/dist/vendor/engine/runtime/coding-agent/core/provider-attribution.d.ts +3 -0
  1351. package/dist/vendor/engine/runtime/coding-agent/core/provider-attribution.js +71 -0
  1352. package/dist/vendor/engine/runtime/coding-agent/core/provider-composer.d.ts +59 -0
  1353. package/dist/vendor/engine/runtime/coding-agent/core/provider-composer.js +422 -0
  1354. package/dist/vendor/engine/runtime/coding-agent/core/radius.d.ts +4 -0
  1355. package/dist/vendor/engine/runtime/coding-agent/core/radius.js +7 -0
  1356. package/dist/vendor/engine/runtime/coding-agent/core/remote-catalog-provider.d.ts +4 -0
  1357. package/dist/vendor/engine/runtime/coding-agent/core/remote-catalog-provider.js +121 -0
  1358. package/dist/vendor/engine/runtime/coding-agent/core/resolve-config-value.d.ts +29 -0
  1359. package/dist/vendor/engine/runtime/coding-agent/core/resolve-config-value.js +246 -0
  1360. package/dist/vendor/engine/runtime/coding-agent/core/resource-loader.d.ts +220 -0
  1361. package/dist/vendor/engine/runtime/coding-agent/core/resource-loader.js +874 -0
  1362. package/dist/vendor/engine/runtime/coding-agent/core/runtime-credentials.d.ts +14 -0
  1363. package/dist/vendor/engine/runtime/coding-agent/core/runtime-credentials.js +38 -0
  1364. package/dist/vendor/engine/runtime/coding-agent/core/sdk.d.ts +107 -0
  1365. package/dist/vendor/engine/runtime/coding-agent/core/sdk.js +296 -0
  1366. package/dist/vendor/engine/runtime/coding-agent/core/session-cwd.d.ts +18 -0
  1367. package/dist/vendor/engine/runtime/coding-agent/core/session-cwd.js +37 -0
  1368. package/dist/vendor/engine/runtime/coding-agent/core/session-export.d.ts +7 -0
  1369. package/dist/vendor/engine/runtime/coding-agent/core/session-export.js +32 -0
  1370. package/dist/vendor/engine/runtime/coding-agent/core/session-manager.d.ts +379 -0
  1371. package/dist/vendor/engine/runtime/coding-agent/core/session-manager.js +1432 -0
  1372. package/dist/vendor/engine/runtime/coding-agent/core/settings-diagnostics.d.ts +8 -0
  1373. package/dist/vendor/engine/runtime/coding-agent/core/settings-diagnostics.js +20 -0
  1374. package/dist/vendor/engine/runtime/coding-agent/core/settings-manager.d.ts +346 -0
  1375. package/dist/vendor/engine/runtime/coding-agent/core/settings-manager.js +1032 -0
  1376. package/dist/vendor/engine/runtime/coding-agent/core/skills.d.ts +59 -0
  1377. package/dist/vendor/engine/runtime/coding-agent/core/skills.js +406 -0
  1378. package/dist/vendor/engine/runtime/coding-agent/core/slash-commands.d.ts +14 -0
  1379. package/dist/vendor/engine/runtime/coding-agent/core/slash-commands.js +27 -0
  1380. package/dist/vendor/engine/runtime/coding-agent/core/source-info.d.ts +17 -0
  1381. package/dist/vendor/engine/runtime/coding-agent/core/source-info.js +18 -0
  1382. package/dist/vendor/engine/runtime/coding-agent/core/system-prompt.d.ts +70 -0
  1383. package/dist/vendor/engine/runtime/coding-agent/core/system-prompt.js +146 -0
  1384. package/dist/vendor/engine/runtime/coding-agent/core/telemetry.d.ts +2 -0
  1385. package/dist/vendor/engine/runtime/coding-agent/core/telemetry.js +8 -0
  1386. package/dist/vendor/engine/runtime/coding-agent/core/timings.d.ts +9 -0
  1387. package/dist/vendor/engine/runtime/coding-agent/core/timings.js +40 -0
  1388. package/dist/vendor/engine/runtime/coding-agent/core/tools/bash.d.ts +89 -0
  1389. package/dist/vendor/engine/runtime/coding-agent/core/tools/bash.js +303 -0
  1390. package/dist/vendor/engine/runtime/coding-agent/core/tools/edit-diff.d.ts +100 -0
  1391. package/dist/vendor/engine/runtime/coding-agent/core/tools/edit-diff.js +420 -0
  1392. package/dist/vendor/engine/runtime/coding-agent/core/tools/edit.d.ts +43 -0
  1393. package/dist/vendor/engine/runtime/coding-agent/core/tools/edit.js +146 -0
  1394. package/dist/vendor/engine/runtime/coding-agent/core/tools/file-mutation-queue.d.ts +5 -0
  1395. package/dist/vendor/engine/runtime/coding-agent/core/tools/file-mutation-queue.js +51 -0
  1396. package/dist/vendor/engine/runtime/coding-agent/core/tools/find.d.ts +41 -0
  1397. package/dist/vendor/engine/runtime/coding-agent/core/tools/find.js +250 -0
  1398. package/dist/vendor/engine/runtime/coding-agent/core/tools/grep.d.ts +40 -0
  1399. package/dist/vendor/engine/runtime/coding-agent/core/tools/grep.js +251 -0
  1400. package/dist/vendor/engine/runtime/coding-agent/core/tools/index.d.ts +42 -0
  1401. package/dist/vendor/engine/runtime/coding-agent/core/tools/index.js +128 -0
  1402. package/dist/vendor/engine/runtime/coding-agent/core/tools/ls.d.ts +40 -0
  1403. package/dist/vendor/engine/runtime/coding-agent/core/tools/ls.js +125 -0
  1404. package/dist/vendor/engine/runtime/coding-agent/core/tools/output-accumulator.d.ts +54 -0
  1405. package/dist/vendor/engine/runtime/coding-agent/core/tools/output-accumulator.js +189 -0
  1406. package/dist/vendor/engine/runtime/coding-agent/core/tools/path-utils.d.ts +9 -0
  1407. package/dist/vendor/engine/runtime/coding-agent/core/tools/path-utils.js +98 -0
  1408. package/dist/vendor/engine/runtime/coding-agent/core/tools/powershell.d.ts +15 -0
  1409. package/dist/vendor/engine/runtime/coding-agent/core/tools/powershell.js +38 -0
  1410. package/dist/vendor/engine/runtime/coding-agent/core/tools/read.d.ts +41 -0
  1411. package/dist/vendor/engine/runtime/coding-agent/core/tools/read.js +168 -0
  1412. package/dist/vendor/engine/runtime/coding-agent/core/tools/render-utils.d.ts +23 -0
  1413. package/dist/vendor/engine/runtime/coding-agent/core/tools/render-utils.js +64 -0
  1414. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/bash.d.ts +11 -0
  1415. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/bash.js +137 -0
  1416. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/edit.d.ts +22 -0
  1417. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/edit.js +166 -0
  1418. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/find.d.ts +9 -0
  1419. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/find.js +63 -0
  1420. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/grep.d.ts +9 -0
  1421. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/grep.js +68 -0
  1422. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/index.d.ts +27 -0
  1423. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/index.js +46 -0
  1424. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/ls.d.ts +9 -0
  1425. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/ls.js +57 -0
  1426. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/read.d.ts +10 -0
  1427. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/read.js +128 -0
  1428. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/write.d.ts +9 -0
  1429. package/dist/vendor/engine/runtime/coding-agent/core/tools/renderers/write.js +152 -0
  1430. package/dist/vendor/engine/runtime/coding-agent/core/tools/tool-definition-wrapper.d.ts +13 -0
  1431. package/dist/vendor/engine/runtime/coding-agent/core/tools/tool-definition-wrapper.js +35 -0
  1432. package/dist/vendor/engine/runtime/coding-agent/core/tools/truncate.d.ts +69 -0
  1433. package/dist/vendor/engine/runtime/coding-agent/core/tools/truncate.js +214 -0
  1434. package/dist/vendor/engine/runtime/coding-agent/core/tools/write.d.ts +29 -0
  1435. package/dist/vendor/engine/runtime/coding-agent/core/tools/write.js +60 -0
  1436. package/dist/vendor/engine/runtime/coding-agent/core/trust-manager.d.ts +35 -0
  1437. package/dist/vendor/engine/runtime/coding-agent/core/trust-manager.js +202 -0
  1438. package/dist/vendor/engine/runtime/coding-agent/core/usage-totals.d.ts +18 -0
  1439. package/dist/vendor/engine/runtime/coding-agent/core/usage-totals.js +55 -0
  1440. package/dist/vendor/engine/runtime/coding-agent/extensions/index.d.ts +2 -0
  1441. package/dist/vendor/engine/runtime/coding-agent/extensions/index.js +2 -0
  1442. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/client.d.ts +68 -0
  1443. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/client.js +312 -0
  1444. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/huggingface.d.ts +22 -0
  1445. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/huggingface.js +140 -0
  1446. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/index.d.ts +2 -0
  1447. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/index.js +218 -0
  1448. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/provider.d.ts +11 -0
  1449. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/provider.js +160 -0
  1450. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/ui.d.ts +41 -0
  1451. package/dist/vendor/engine/runtime/coding-agent/extensions/llama/ui.js +415 -0
  1452. package/dist/vendor/engine/runtime/coding-agent/index.d.ts +36 -0
  1453. package/dist/vendor/engine/runtime/coding-agent/index.js +47 -0
  1454. package/dist/vendor/engine/runtime/coding-agent/main.d.ts +15 -0
  1455. package/dist/vendor/engine/runtime/coding-agent/main.js +808 -0
  1456. package/dist/vendor/engine/runtime/coding-agent/migrations.d.ts +32 -0
  1457. package/dist/vendor/engine/runtime/coding-agent/migrations.js +281 -0
  1458. package/dist/vendor/engine/runtime/coding-agent/modes/index.d.ts +9 -0
  1459. package/dist/vendor/engine/runtime/coding-agent/modes/index.js +7 -0
  1460. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/bug-report.d.ts +15 -0
  1461. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/bug-report.js +209 -0
  1462. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/chat-viewport.d.ts +19 -0
  1463. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/chat-viewport.js +27 -0
  1464. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/armin.d.ts +33 -0
  1465. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/armin.js +332 -0
  1466. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/assistant-message.d.ts +25 -0
  1467. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/assistant-message.js +157 -0
  1468. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/bash-execution.d.ts +33 -0
  1469. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/bash-execution.js +174 -0
  1470. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/bordered-loader.d.ts +15 -0
  1471. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/bordered-loader.js +53 -0
  1472. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/branch-summary-message.d.ts +15 -0
  1473. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/branch-summary-message.js +50 -0
  1474. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/compaction-summary-message.d.ts +15 -0
  1475. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/compaction-summary-message.js +51 -0
  1476. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/config-selector.d.ts +101 -0
  1477. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/config-selector.js +760 -0
  1478. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/countdown-timer.d.ts +13 -0
  1479. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/countdown-timer.js +32 -0
  1480. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-editor.d.ts +29 -0
  1481. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-editor.js +114 -0
  1482. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-entry.d.ts +18 -0
  1483. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-entry.js +51 -0
  1484. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-message.d.ts +21 -0
  1485. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/custom-message.js +86 -0
  1486. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/daxnuts.d.ts +22 -0
  1487. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/daxnuts.js +139 -0
  1488. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/diff.d.ts +11 -0
  1489. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/diff.js +132 -0
  1490. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/dynamic-border.d.ts +14 -0
  1491. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/dynamic-border.js +20 -0
  1492. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/earendil-announcement.d.ts +4 -0
  1493. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/earendil-announcement.js +39 -0
  1494. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-editor.d.ts +23 -0
  1495. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-editor.js +102 -0
  1496. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-input.d.ts +24 -0
  1497. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-input.js +66 -0
  1498. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-selector.d.ts +26 -0
  1499. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/extension-selector.js +86 -0
  1500. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/first-time-setup.d.ts +24 -0
  1501. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/first-time-setup.js +102 -0
  1502. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/footer.d.ts +31 -0
  1503. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/footer.js +224 -0
  1504. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/index.d.ts +33 -0
  1505. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/index.js +34 -0
  1506. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/keybinding-hints.d.ts +12 -0
  1507. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/keybinding-hints.js +35 -0
  1508. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/login-dialog.d.ts +51 -0
  1509. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/login-dialog.js +187 -0
  1510. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/markdown-transform.d.ts +2 -0
  1511. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/markdown-transform.js +18 -0
  1512. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/mermaid.d.ts +10 -0
  1513. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/mermaid.js +74 -0
  1514. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/model-selector.d.ts +59 -0
  1515. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/model-selector.js +360 -0
  1516. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/oauth-selector.d.ts +32 -0
  1517. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/oauth-selector.js +162 -0
  1518. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/scoped-models-selector.d.ts +45 -0
  1519. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/scoped-models-selector.js +325 -0
  1520. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/session-selector-search.d.ts +22 -0
  1521. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/session-selector-search.js +154 -0
  1522. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/session-selector.d.ts +94 -0
  1523. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/session-selector.js +892 -0
  1524. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/settings-selector.d.ts +93 -0
  1525. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/settings-selector.js +719 -0
  1526. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/settings-submenu.d.ts +71 -0
  1527. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/settings-submenu.js +164 -0
  1528. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/show-images-selector.d.ts +9 -0
  1529. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/show-images-selector.js +38 -0
  1530. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/skill-invocation-message.d.ts +16 -0
  1531. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/skill-invocation-message.js +53 -0
  1532. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/status-indicator.d.ts +29 -0
  1533. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/status-indicator.js +66 -0
  1534. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/theme-selector.d.ts +10 -0
  1535. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/theme-selector.js +49 -0
  1536. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/thinking-selector.d.ts +22 -0
  1537. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/thinking-selector.js +108 -0
  1538. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/tool-execution.d.ts +79 -0
  1539. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/tool-execution.js +336 -0
  1540. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/tree-selector.d.ts +93 -0
  1541. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/tree-selector.js +1246 -0
  1542. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/trust-selector.d.ts +22 -0
  1543. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/trust-selector.js +90 -0
  1544. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/user-message-selector.d.ts +29 -0
  1545. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/user-message-selector.js +113 -0
  1546. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/user-message.d.ts +15 -0
  1547. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/user-message.js +48 -0
  1548. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/visual-truncate.d.ts +23 -0
  1549. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/components/visual-truncate.js +32 -0
  1550. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/external-editor.d.ts +11 -0
  1551. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/external-editor.js +37 -0
  1552. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/interactive-mode.d.ts +467 -0
  1553. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/interactive-mode.js +5720 -0
  1554. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/model-catalog-refresh.d.ts +6 -0
  1555. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/model-catalog-refresh.js +33 -0
  1556. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/model-search.d.ts +11 -0
  1557. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/model-search.js +14 -0
  1558. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/session-share.d.ts +17 -0
  1559. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/session-share.js +187 -0
  1560. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/dark.json +91 -0
  1561. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/light.json +90 -0
  1562. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-controller.d.ts +40 -0
  1563. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-controller.js +129 -0
  1564. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-json.d.ts +83 -0
  1565. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-json.js +129 -0
  1566. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme-schema.json +356 -0
  1567. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme.d.ts +130 -0
  1568. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/theme/theme.js +990 -0
  1569. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/tui-renderer.d.ts +20 -0
  1570. package/dist/vendor/engine/runtime/coding-agent/modes/interactive/tui-renderer.js +65 -0
  1571. package/dist/vendor/engine/runtime/coding-agent/modes/json-event.d.ts +33 -0
  1572. package/dist/vendor/engine/runtime/coding-agent/modes/json-event.js +28 -0
  1573. package/dist/vendor/engine/runtime/coding-agent/modes/print-mode.d.ts +27 -0
  1574. package/dist/vendor/engine/runtime/coding-agent/modes/print-mode.js +141 -0
  1575. package/dist/vendor/engine/runtime/coding-agent/modes/rpc/jsonl.d.ts +16 -0
  1576. package/dist/vendor/engine/runtime/coding-agent/modes/rpc/jsonl.js +48 -0
  1577. package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-client.d.ts +253 -0
  1578. package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-client.js +494 -0
  1579. package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-mode.d.ts +19 -0
  1580. package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-mode.js +656 -0
  1581. package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-types.d.ts +468 -0
  1582. package/dist/vendor/engine/runtime/coding-agent/modes/rpc/rpc-types.js +7 -0
  1583. package/dist/vendor/engine/runtime/coding-agent/package-manager-cli.d.ts +8 -0
  1584. package/dist/vendor/engine/runtime/coding-agent/package-manager-cli.js +960 -0
  1585. package/dist/vendor/engine/runtime/coding-agent/utils/abort.d.ts +4 -0
  1586. package/dist/vendor/engine/runtime/coding-agent/utils/abort.js +47 -0
  1587. package/dist/vendor/engine/runtime/coding-agent/utils/ansi.d.ts +1 -0
  1588. package/dist/vendor/engine/runtime/coding-agent/utils/ansi.js +51 -0
  1589. package/dist/vendor/engine/runtime/coding-agent/utils/changelog.d.ts +21 -0
  1590. package/dist/vendor/engine/runtime/coding-agent/utils/changelog.js +164 -0
  1591. package/dist/vendor/engine/runtime/coding-agent/utils/child-process.d.ts +17 -0
  1592. package/dist/vendor/engine/runtime/coding-agent/utils/child-process.js +105 -0
  1593. package/dist/vendor/engine/runtime/coding-agent/utils/clipboard-command.d.ts +6 -0
  1594. package/dist/vendor/engine/runtime/coding-agent/utils/clipboard-command.js +44 -0
  1595. package/dist/vendor/engine/runtime/coding-agent/utils/clipboard-image.d.ts +10 -0
  1596. package/dist/vendor/engine/runtime/coding-agent/utils/clipboard-image.js +216 -0
  1597. package/dist/vendor/engine/runtime/coding-agent/utils/clipboard.d.ts +3 -0
  1598. package/dist/vendor/engine/runtime/coding-agent/utils/clipboard.js +150 -0
  1599. package/dist/vendor/engine/runtime/coding-agent/utils/exif-orientation.d.ts +4 -0
  1600. package/dist/vendor/engine/runtime/coding-agent/utils/exif-orientation.js +156 -0
  1601. package/dist/vendor/engine/runtime/coding-agent/utils/frontmatter.d.ts +7 -0
  1602. package/dist/vendor/engine/runtime/coding-agent/utils/frontmatter.js +26 -0
  1603. package/dist/vendor/engine/runtime/coding-agent/utils/fs-watch.d.ts +4 -0
  1604. package/dist/vendor/engine/runtime/coding-agent/utils/fs-watch.js +24 -0
  1605. package/dist/vendor/engine/runtime/coding-agent/utils/git.d.ts +25 -0
  1606. package/dist/vendor/engine/runtime/coding-agent/utils/git.js +194 -0
  1607. package/dist/vendor/engine/runtime/coding-agent/utils/html.d.ts +6 -0
  1608. package/dist/vendor/engine/runtime/coding-agent/utils/html.js +39 -0
  1609. package/dist/vendor/engine/runtime/coding-agent/utils/image-convert.d.ts +9 -0
  1610. package/dist/vendor/engine/runtime/coding-agent/utils/image-convert.js +44 -0
  1611. package/dist/vendor/engine/runtime/coding-agent/utils/image-process.d.ts +17 -0
  1612. package/dist/vendor/engine/runtime/coding-agent/utils/image-process.js +82 -0
  1613. package/dist/vendor/engine/runtime/coding-agent/utils/image-resize-core.d.ts +29 -0
  1614. package/dist/vendor/engine/runtime/coding-agent/utils/image-resize-core.js +123 -0
  1615. package/dist/vendor/engine/runtime/coding-agent/utils/image-resize-worker.d.ts +1 -0
  1616. package/dist/vendor/engine/runtime/coding-agent/utils/image-resize-worker.js +30 -0
  1617. package/dist/vendor/engine/runtime/coding-agent/utils/image-resize.d.ts +15 -0
  1618. package/dist/vendor/engine/runtime/coding-agent/utils/image-resize.js +96 -0
  1619. package/dist/vendor/engine/runtime/coding-agent/utils/json.d.ts +2 -0
  1620. package/dist/vendor/engine/runtime/coding-agent/utils/json.js +6 -0
  1621. package/dist/vendor/engine/runtime/coding-agent/utils/management-http.d.ts +24 -0
  1622. package/dist/vendor/engine/runtime/coding-agent/utils/management-http.js +53 -0
  1623. package/dist/vendor/engine/runtime/coding-agent/utils/mime.d.ts +2 -0
  1624. package/dist/vendor/engine/runtime/coding-agent/utils/mime.js +109 -0
  1625. package/dist/vendor/engine/runtime/coding-agent/utils/open-browser.d.ts +8 -0
  1626. package/dist/vendor/engine/runtime/coding-agent/utils/open-browser.js +21 -0
  1627. package/dist/vendor/engine/runtime/coding-agent/utils/paths.d.ts +33 -0
  1628. package/dist/vendor/engine/runtime/coding-agent/utils/paths.js +113 -0
  1629. package/dist/vendor/engine/runtime/coding-agent/utils/photon.d.ts +20 -0
  1630. package/dist/vendor/engine/runtime/coding-agent/utils/photon.js +120 -0
  1631. package/dist/vendor/engine/runtime/coding-agent/utils/pi-user-agent.d.ts +1 -0
  1632. package/dist/vendor/engine/runtime/coding-agent/utils/pi-user-agent.js +4 -0
  1633. package/dist/vendor/engine/runtime/coding-agent/utils/shell.d.ts +33 -0
  1634. package/dist/vendor/engine/runtime/coding-agent/utils/shell.js +215 -0
  1635. package/dist/vendor/engine/runtime/coding-agent/utils/sleep.d.ts +4 -0
  1636. package/dist/vendor/engine/runtime/coding-agent/utils/sleep.js +16 -0
  1637. package/dist/vendor/engine/runtime/coding-agent/utils/syntax-highlight.d.ts +12 -0
  1638. package/dist/vendor/engine/runtime/coding-agent/utils/syntax-highlight.js +176 -0
  1639. package/dist/vendor/engine/runtime/coding-agent/utils/text.d.ts +7 -0
  1640. package/dist/vendor/engine/runtime/coding-agent/utils/text.js +8 -0
  1641. package/dist/vendor/engine/runtime/coding-agent/utils/tool-result-images.d.ts +20 -0
  1642. package/dist/vendor/engine/runtime/coding-agent/utils/tool-result-images.js +47 -0
  1643. package/dist/vendor/engine/runtime/coding-agent/utils/tools-manager.d.ts +12 -0
  1644. package/dist/vendor/engine/runtime/coding-agent/utils/tools-manager.js +308 -0
  1645. package/dist/vendor/engine/runtime/coding-agent/utils/version-check.d.ts +18 -0
  1646. package/dist/vendor/engine/runtime/coding-agent/utils/version-check.js +78 -0
  1647. package/dist/vendor/engine/runtime/coding-agent/utils/windows-self-update.d.ts +2 -0
  1648. package/dist/vendor/engine/runtime/coding-agent/utils/windows-self-update.js +76 -0
  1649. package/dist/vendor/engine/runtime/coding-agent/utils/wsl.d.ts +2 -0
  1650. package/dist/vendor/engine/runtime/coding-agent/utils/wsl.js +14 -0
  1651. package/dist/vendor/engine/runtime/coding-agent/utils/zip.d.ts +6 -0
  1652. package/dist/vendor/engine/runtime/coding-agent/utils/zip.js +59 -0
  1653. package/dist/vendor/engine/runtime/package.json +9 -0
  1654. package/dist/vendor/engine/runtime/telemetry/index.d.ts +193 -0
  1655. package/dist/vendor/engine/runtime/telemetry/index.js +17 -0
  1656. package/dist/vendor/engine/runtime/telemetry/memory.d.ts +25 -0
  1657. package/dist/vendor/engine/runtime/telemetry/memory.js +153 -0
  1658. package/dist/vendor/engine/runtime/telemetry/noop.d.ts +3 -0
  1659. package/dist/vendor/engine/runtime/telemetry/noop.js +17 -0
  1660. package/dist/vendor/engine/runtime/tui/alt-screen-search.d.ts +45 -0
  1661. package/dist/vendor/engine/runtime/tui/alt-screen-search.js +281 -0
  1662. package/dist/vendor/engine/runtime/tui/autocomplete.d.ts +56 -0
  1663. package/dist/vendor/engine/runtime/tui/autocomplete.js +671 -0
  1664. package/dist/vendor/engine/runtime/tui/components/alt-screen-flash.d.ts +12 -0
  1665. package/dist/vendor/engine/runtime/tui/components/alt-screen-flash.js +36 -0
  1666. package/dist/vendor/engine/runtime/tui/components/box.d.ts +23 -0
  1667. package/dist/vendor/engine/runtime/tui/components/box.js +132 -0
  1668. package/dist/vendor/engine/runtime/tui/components/cancellable-loader.d.ts +21 -0
  1669. package/dist/vendor/engine/runtime/tui/components/cancellable-loader.js +34 -0
  1670. package/dist/vendor/engine/runtime/tui/components/editor.d.ts +259 -0
  1671. package/dist/vendor/engine/runtime/tui/components/editor.js +2041 -0
  1672. package/dist/vendor/engine/runtime/tui/components/h-stack.d.ts +6 -0
  1673. package/dist/vendor/engine/runtime/tui/components/h-stack.js +42 -0
  1674. package/dist/vendor/engine/runtime/tui/components/image.d.ts +27 -0
  1675. package/dist/vendor/engine/runtime/tui/components/image.js +89 -0
  1676. package/dist/vendor/engine/runtime/tui/components/input.d.ts +47 -0
  1677. package/dist/vendor/engine/runtime/tui/components/input.js +416 -0
  1678. package/dist/vendor/engine/runtime/tui/components/loader.d.ts +32 -0
  1679. package/dist/vendor/engine/runtime/tui/components/loader.js +75 -0
  1680. package/dist/vendor/engine/runtime/tui/components/markdown.d.ts +102 -0
  1681. package/dist/vendor/engine/runtime/tui/components/markdown.js +810 -0
  1682. package/dist/vendor/engine/runtime/tui/components/mouse-region.d.ts +11 -0
  1683. package/dist/vendor/engine/runtime/tui/components/mouse-region.js +20 -0
  1684. package/dist/vendor/engine/runtime/tui/components/scroll-view.d.ts +58 -0
  1685. package/dist/vendor/engine/runtime/tui/components/scroll-view.js +194 -0
  1686. package/dist/vendor/engine/runtime/tui/components/select-list.d.ts +52 -0
  1687. package/dist/vendor/engine/runtime/tui/components/select-list.js +205 -0
  1688. package/dist/vendor/engine/runtime/tui/components/settings-list.d.ts +59 -0
  1689. package/dist/vendor/engine/runtime/tui/components/settings-list.js +251 -0
  1690. package/dist/vendor/engine/runtime/tui/components/spacer.d.ts +11 -0
  1691. package/dist/vendor/engine/runtime/tui/components/spacer.js +22 -0
  1692. package/dist/vendor/engine/runtime/tui/components/stack.d.ts +31 -0
  1693. package/dist/vendor/engine/runtime/tui/components/stack.js +110 -0
  1694. package/dist/vendor/engine/runtime/tui/components/text.d.ts +18 -0
  1695. package/dist/vendor/engine/runtime/tui/components/text.js +89 -0
  1696. package/dist/vendor/engine/runtime/tui/components/truncated-text.d.ts +12 -0
  1697. package/dist/vendor/engine/runtime/tui/components/truncated-text.js +50 -0
  1698. package/dist/vendor/engine/runtime/tui/components/v-stack.d.ts +7 -0
  1699. package/dist/vendor/engine/runtime/tui/components/v-stack.js +25 -0
  1700. package/dist/vendor/engine/runtime/tui/editor-component.d.ts +38 -0
  1701. package/dist/vendor/engine/runtime/tui/editor-component.js +1 -0
  1702. package/dist/vendor/engine/runtime/tui/fuzzy.d.ts +15 -0
  1703. package/dist/vendor/engine/runtime/tui/fuzzy.js +110 -0
  1704. package/dist/vendor/engine/runtime/tui/index.d.ts +32 -0
  1705. package/dist/vendor/engine/runtime/tui/index.js +44 -0
  1706. package/dist/vendor/engine/runtime/tui/keybindings.d.ts +272 -0
  1707. package/dist/vendor/engine/runtime/tui/keybindings.js +232 -0
  1708. package/dist/vendor/engine/runtime/tui/keys.d.ts +183 -0
  1709. package/dist/vendor/engine/runtime/tui/keys.js +1173 -0
  1710. package/dist/vendor/engine/runtime/tui/kill-ring.d.ts +27 -0
  1711. package/dist/vendor/engine/runtime/tui/kill-ring.js +43 -0
  1712. package/dist/vendor/engine/runtime/tui/latex.d.ts +9 -0
  1713. package/dist/vendor/engine/runtime/tui/latex.js +1377 -0
  1714. package/dist/vendor/engine/runtime/tui/layout-node.d.ts +39 -0
  1715. package/dist/vendor/engine/runtime/tui/layout-node.js +5 -0
  1716. package/dist/vendor/engine/runtime/tui/layout.d.ts +41 -0
  1717. package/dist/vendor/engine/runtime/tui/layout.js +343 -0
  1718. package/dist/vendor/engine/runtime/tui/native-modifiers.d.ts +3 -0
  1719. package/dist/vendor/engine/runtime/tui/native-modifiers.js +12 -0
  1720. package/dist/vendor/engine/runtime/tui/native-module-path.d.ts +6 -0
  1721. package/dist/vendor/engine/runtime/tui/native-module-path.js +18 -0
  1722. package/dist/vendor/engine/runtime/tui/native-platform.d.ts +17 -0
  1723. package/dist/vendor/engine/runtime/tui/native-platform.js +41 -0
  1724. package/dist/vendor/engine/runtime/tui/stdin-buffer.d.ts +55 -0
  1725. package/dist/vendor/engine/runtime/tui/stdin-buffer.js +365 -0
  1726. package/dist/vendor/engine/runtime/tui/terminal-colors.d.ts +9 -0
  1727. package/dist/vendor/engine/runtime/tui/terminal-colors.js +58 -0
  1728. package/dist/vendor/engine/runtime/tui/terminal-image.d.ts +117 -0
  1729. package/dist/vendor/engine/runtime/tui/terminal-image.js +549 -0
  1730. package/dist/vendor/engine/runtime/tui/terminal.d.ts +122 -0
  1731. package/dist/vendor/engine/runtime/tui/terminal.js +441 -0
  1732. package/dist/vendor/engine/runtime/tui/tui-alt-screen.d.ts +159 -0
  1733. package/dist/vendor/engine/runtime/tui/tui-alt-screen.js +1507 -0
  1734. package/dist/vendor/engine/runtime/tui/tui-main-screen.d.ts +38 -0
  1735. package/dist/vendor/engine/runtime/tui/tui-main-screen.js +593 -0
  1736. package/dist/vendor/engine/runtime/tui/tui.d.ts +385 -0
  1737. package/dist/vendor/engine/runtime/tui/tui.js +1054 -0
  1738. package/dist/vendor/engine/runtime/tui/undo-stack.d.ts +16 -0
  1739. package/dist/vendor/engine/runtime/tui/undo-stack.js +24 -0
  1740. package/dist/vendor/engine/runtime/tui/utils.d.ts +100 -0
  1741. package/dist/vendor/engine/runtime/tui/utils.js +1203 -0
  1742. package/dist/vendor/engine/runtime/tui/word-navigation.d.ts +24 -0
  1743. package/dist/vendor/engine/runtime/tui/word-navigation.js +95 -0
  1744. package/dist/vendor/zcode/LICENSE.upstream +202 -0
  1745. package/dist/vendor/zcode/provenance.json +141 -0
  1746. package/dist/vendor/zcode/source/agent/turn-machine.d.ts +56 -0
  1747. package/dist/vendor/zcode/source/agent/turn-machine.js +214 -0
  1748. package/dist/vendor/zcode/source/agent/turn-state.d.ts +118 -0
  1749. package/dist/vendor/zcode/source/agent/turn-state.js +93 -0
  1750. package/dist/vendor/zcode/source/compact/manual.d.ts +11 -0
  1751. package/dist/vendor/zcode/source/compact/manual.js +38 -0
  1752. package/dist/vendor/zcode/source/compact/microcompact.d.ts +47 -0
  1753. package/dist/vendor/zcode/source/compact/microcompact.js +194 -0
  1754. package/dist/vendor/zcode/source/compact/policy.d.ts +59 -0
  1755. package/dist/vendor/zcode/source/compact/policy.js +89 -0
  1756. package/dist/vendor/zcode/source/compact/selection.d.ts +6 -0
  1757. package/dist/vendor/zcode/source/compact/selection.js +12 -0
  1758. package/dist/vendor/zcode/source/contracts.d.ts +52 -0
  1759. package/dist/vendor/zcode/source/contracts.js +9 -0
  1760. package/dist/vendor/zcode/source/runtime/goal-completion-verification.d.ts +17 -0
  1761. package/dist/vendor/zcode/source/runtime/goal-completion-verification.js +138 -0
  1762. package/dist/vendor/zcode/source/runtime/turn-loop.d.ts +3 -0
  1763. package/dist/vendor/zcode/source/runtime/turn-loop.js +21 -0
  1764. package/dist/vendor/zcode/source/runtime/turn-model-step.d.ts +54 -0
  1765. package/dist/vendor/zcode/source/runtime/turn-model-step.js +97 -0
  1766. package/dist/vendor/zcode/source/runtime/turn-output-token-continuation.d.ts +8 -0
  1767. package/dist/vendor/zcode/source/runtime/turn-output-token-continuation.js +15 -0
  1768. package/dist/vendor/zcode/source/runtime/turn-stop.d.ts +6 -0
  1769. package/dist/vendor/zcode/source/runtime/turn-stop.js +18 -0
  1770. package/dist/vendor/zcode/source/tool/executor/validation.d.ts +6 -0
  1771. package/dist/vendor/zcode/source/tool/executor/validation.js +76 -0
  1772. package/dist/vendor/zcode/source/tool/input-normalization.d.ts +16 -0
  1773. package/dist/vendor/zcode/source/tool/input-normalization.js +62 -0
  1774. package/dist/vendor/zcode/source/tool/input-validation-model-content.d.ts +4 -0
  1775. package/dist/vendor/zcode/source/tool/input-validation-model-content.js +263 -0
  1776. package/dist/vendor/zcode/source/tool/json-schema.d.ts +9 -0
  1777. package/dist/vendor/zcode/source/tool/json-schema.js +230 -0
  1778. package/dist/vendor/zcode/source/tool/scheduler.d.ts +43 -0
  1779. package/dist/vendor/zcode/source/tool/scheduler.js +167 -0
  1780. package/dist/vendor/zcode/source/tool/tool-input-validation-issues.d.ts +76 -0
  1781. package/dist/vendor/zcode/source/tool/tool-input-validation-issues.js +148 -0
  1782. package/dist/vendor/zcode/source/tool/validation-contracts.d.ts +27 -0
  1783. package/dist/vendor/zcode/source/tool/validation-contracts.js +8 -0
  1784. package/docs/README.md +36 -0
  1785. package/docs/agents/README.md +62 -0
  1786. package/docs/agents/install-for-agents.md +64 -0
  1787. package/docs/agents/mcp-server.md +187 -0
  1788. package/docs/agents/subagent-mode.md +146 -0
  1789. package/docs/concepts/README.md +47 -0
  1790. package/docs/concepts/jev-actionable-routing.md +113 -0
  1791. package/docs/concepts/jev-decision-thresholds.md +412 -0
  1792. package/docs/concepts/jev-efficiency.md +216 -0
  1793. package/docs/concepts/jev-eval-2026-11-01.md +78 -0
  1794. package/docs/concepts/limits.md +43 -0
  1795. package/docs/concepts/memory.md +30 -0
  1796. package/docs/concepts/security.md +40 -0
  1797. package/docs/concepts/workspace-instructions.md +28 -0
  1798. package/docs/getting-started/README.md +74 -0
  1799. package/docs/getting-started/accounts.md +67 -0
  1800. package/docs/getting-started/configure-providers.md +103 -0
  1801. package/docs/guides/README.md +12 -0
  1802. package/docs/guides/browser.md +15 -0
  1803. package/docs/guides/desktop-app.md +325 -0
  1804. package/docs/guides/extensions.md +100 -0
  1805. package/docs/guides/graph-builder.md +93 -0
  1806. package/docs/guides/headless.md +45 -0
  1807. package/docs/guides/tui.md +75 -0
  1808. package/docs/guides/update.md +47 -0
  1809. package/docs/guides/windows-code-signing.md +316 -0
  1810. package/docs/llms.txt +45 -0
  1811. package/docs/reference/README.md +7 -0
  1812. package/docs/reference/cli.md +70 -0
  1813. package/docs/reference/config.md +85 -0
  1814. package/docs/reference/slash-commands.md +54 -0
  1815. package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +111 -0
  1816. package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +910 -0
  1817. package/docs/superpowers/plans/2026-11-02-workflow-pane.md +398 -0
  1818. package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +50 -0
  1819. package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +176 -0
  1820. package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +164 -0
  1821. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +104 -0
  1822. package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +130 -0
  1823. package/licenses/GEIST-OFL-1.1.txt +92 -0
  1824. package/licenses/ZCODE-APACHE-2.0.txt +202 -0
  1825. package/package.json +118 -6
  1826. package/scripts/jev-efficiency-eval.mjs +187 -0
  1827. package/scripts/jev-efficiency-live.mjs +193 -0
  1828. package/scripts/zcode-engine-replay.mjs +223 -0
  1829. package/tests/agent-centric-mcp-test-plan.md +208 -0
  1830. package/tests/analytics-settings-test-plan.md +165 -0
  1831. package/tests/browser-cli-smoke.mjs +276 -0
  1832. package/tests/browser-test-plan.md +280 -0
  1833. package/tests/chat-side-panel-test-plan.md +309 -0
  1834. package/tests/decision-engine-test-plan.md +163 -0
  1835. package/tests/default-active-jev-test-plan.md +85 -0
  1836. package/tests/graphiti-test-plan.md +359 -0
  1837. package/tests/harness-extensions-test-plan.md +110 -0
  1838. package/tests/jev-all-decisions-test-plan.md +156 -0
  1839. package/tests/jev-efficiency/criteria.json +158 -0
  1840. package/tests/jev-efficiency/workloads.mjs +242 -0
  1841. package/tests/jev-efficiency-test-plan.md +198 -0
  1842. package/tests/mock-graphiti.mjs +106 -0
  1843. package/tests/permissions-sandbox-probe.mjs +74 -0
  1844. package/tests/permissions-test-plan.md +190 -0
  1845. package/tests/product-telemetry-test-plan.md +536 -0
  1846. package/tests/thinking-stream-preview-test-plan.md +136 -0
  1847. package/tests/zcode-react-engine-test-plan.md +396 -0
@@ -0,0 +1,2564 @@
1
+ #!/usr/bin/env node
2
+ import { randomUUID } from 'node:crypto';
3
+ import { bootMark } from './boot-trace.js';
4
+ import { createSessionTrajectory } from './trajectory.js';
5
+ import { hostedDecisionPolicy } from './decision/hostedPolicy.js';
6
+ import { parseArgs, stripVTControlCharacters } from 'node:util';
7
+ import { appendFile, mkdir, open, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises';
8
+ import { existsSync } from 'node:fs';
9
+ import { isAbsolute, join, relative, resolve } from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { homedir } from 'node:os';
12
+ import { workspacePermissionKey, permissionLabel } from './permissions.js';
13
+ import { configDirectory, loadConfig, resolveCodeIntelConfig, resolveConfiguredLimits, saveConfig } from './config.js';
14
+ import { compactHistory, compactedContextEstimate, executeCommand, HELP } from './commands.js';
15
+ import { applyModelContextWindow, createAdapter, providerSecrets, recordProviderModel } from './providers.js';
16
+ import { createTools } from './tools.js';
17
+ import { QA_SYSTEM_GUIDANCE, disposeAllQaProcesses, disposeAllQaPtys, getQaPtyManager } from './qa/index.js';
18
+ import { disposePooledPowerShell } from './powershell-pool.js';
19
+ import { loadWorkspaceInstructions } from './workspace-instructions.js';
20
+ import { runGraph, stopReasonPhrase } from './runtime.js';
21
+ import { validateGraph } from './graphs.js';
22
+ import { checkGraphModelHealth, formatGraphHealthFailure } from './graph-health.js';
23
+ import { getMembership, loadAccessibleGraph, PaidMembershipRequiredError } from './membership.js';
24
+ import { configuredSurface, createRunHandle, drainTelemetry, graphShape, reportInterruptedRuns, reportRunFinished, reportRunStarted, reportSessionStarted } from './telemetry/surface.js';
25
+ import { createRunTelemetry, recordModelUse } from './telemetry/capture.js';
26
+ import { pricingFor } from './model-tiers.js';
27
+ import { GraphProviderUnavailableError } from './graph-provider-portability.js';
28
+ import { MAX_SUBAGENT_TASK_CHARS, SubagentInvalidArgumentError, SubagentProviderNotSetError, SubagentRunInProgressError, SubagentRunner, SubagentSelectionError } from './subagent-run.js';
29
+ /** Shown when a saved per-account graph selection is denied account access at launch or refresh. */
30
+ const GRAPH_FALLBACK_NOTICE = 'The selected graph needs paid account access, which is currently unavailable. Starting with the local Default graph; once access is restored, switch back with /graph.';
31
+ /** The free allowance names its own reason; any other membership refusal is an access outage. */
32
+ const graphFallbackReason = (error) => error instanceof FreeTierLimitError ? `${error.message} Starting with the local Default graph.` : GRAPH_FALLBACK_NOTICE;
33
+ import { configuredGraphSelection, currentGraphSubject } from './graph-selection.js';
34
+ import { launchGraphEditor } from './graph-server.js';
35
+ import { createGraphEditorSession } from './graph-editor-session.js';
36
+ import { FreeTierLimitError } from './graph-quota.js';
37
+ import { updateInstallation } from './update.js';
38
+ import { RunControl } from './run-control.js';
39
+ import { TimerRegistry } from './timers.js';
40
+ import { TerminalUI } from './terminal-ui.js';
41
+ import { meterStreamedRequest } from './token-rate.js';
42
+ import { attachmentLabel, attachmentReadRoots, attachmentReferenceBlock, pruneAttachments, readClipboardImage, resolveAttachments, writeClipboardText } from './attachments.js';
43
+ import { describeTool, formatEvent, formatRunResult } from './transcript.js';
44
+ import { staticToolTimestamp } from './tool-call-clock.js';
45
+ import { LocalToolMemory } from './memory/LocalToolMemory.js';
46
+ import { askClarification } from './clarification-ui.js';
47
+ import { refreshModelContext, resolveModelContext, withEvaluationReasoningEffort } from './model-metadata.js';
48
+ import { isScreenCommand, runCommandScreen } from './command-screens.js';
49
+ import { CodeIntelligenceManager } from './code-intelligence/CodeIntelligenceManager.js';
50
+ import { ToolActivity, activityForRuntimeEvent } from './tool-activity.js';
51
+ import { extensionSnapshot, resolveSkillInvocation } from './extensions.js';
52
+ import { isBuiltinSlashCommand } from './skill-commands.js';
53
+ import { executeAuthCommand } from './auth-commands.js';
54
+ import { setAuthSignOutReporter } from './auth/index.js';
55
+ import { getAccountPresentation } from './account-presentation.js';
56
+ import { acquireSessionMutationLock, clearOpenRunClaim, noteCheckpointWriteFailure, removeRunCheckpoint, RUNNING_TURN_SUMMARY, reconcileInterruptedRuns, runRecordPath, runRecordsDirectory, writeOpenRunRecord, writeRunCheckpoint, writeStudioRunSummary } from './run-records.js';
57
+ import { gitChangeSummary } from './git-summary.js';
58
+ import { writeActivity } from './activity.js';
59
+ import { TodoStore } from './todos.js';
60
+ import { canExtendLineage, carryRailOwnedFields, displayHistory, lineagePoints, lineageThrough, SessionStore, sessionName, projectIdentity } from './sessions.js';
61
+ import { SessionTitle } from './session-title.js';
62
+ import { createBrowserBridge } from './browser-bridge.js';
63
+ import { startBrowserServer, openBrowserUrl } from './browser-server.js';
64
+ /**
65
+ * The version this build reports, read from the package manifest rather than hard-coded.
66
+ *
67
+ * The release workflow rewrites `package.json` and then publishes; a literal here would keep
68
+ * reporting the old version forever, so `andorra --version` would disagree with the package that
69
+ * was actually installed. `dist/src/cli.js` sits two directories below the manifest
70
+ * (`dist/src/cli.js` -> `dist` -> repository root), both in a checkout and in an installed
71
+ * package. A manifest that cannot be read leaves the version unknown rather than wrong.
72
+ */
73
+ export async function cliVersion() {
74
+ try {
75
+ const manifest = JSON.parse(await readFile(fileURLToPath(new URL('../../package.json', import.meta.url)), 'utf8'));
76
+ return typeof manifest.version === 'string' ? manifest.version : 'unknown';
77
+ }
78
+ catch {
79
+ return 'unknown';
80
+ }
81
+ }
82
+ /** Display-only Git metadata must never run workspace-controlled PATH helpers. */
83
+ export async function gitBranch(workspace) {
84
+ try {
85
+ const root = await realpath(workspace);
86
+ const contained = (target) => {
87
+ const suffix = relative(root, target);
88
+ return suffix === '' || (!isAbsolute(suffix) && suffix !== '..' && !suffix.startsWith(`..${process.platform === 'win32' ? '\\' : '/'}`));
89
+ };
90
+ const metadataPath = async (target) => {
91
+ // Check lexical paths before resolution, then reject symlink/junction escapes.
92
+ if (!contained(resolve(target)))
93
+ throw new Error('Git metadata is outside the workspace');
94
+ const canonical = await realpath(target);
95
+ if (!contained(canonical))
96
+ throw new Error('Git metadata is outside the workspace');
97
+ return canonical;
98
+ };
99
+ const metadataText = async (target) => {
100
+ const canonical = await metadataPath(target);
101
+ const handle = await open(canonical, 'r');
102
+ try {
103
+ const info = await handle.stat();
104
+ if (!info.isFile() || info.size > 4096)
105
+ throw new Error('Invalid Git metadata');
106
+ const buffer = Buffer.alloc(4097);
107
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
108
+ if (bytesRead > 4096)
109
+ throw new Error('Invalid Git metadata');
110
+ return buffer.subarray(0, bytesRead).toString('utf8').trim();
111
+ }
112
+ finally {
113
+ await handle.close();
114
+ }
115
+ };
116
+ let gitDirectory = await metadataPath(join(root, '.git'));
117
+ if (!(await stat(gitDirectory)).isDirectory()) {
118
+ const pointer = /^gitdir: (.+)$/.exec(await metadataText(gitDirectory));
119
+ if (!pointer)
120
+ return 'No Git branch';
121
+ gitDirectory = await metadataPath(resolve(root, pointer[1]));
122
+ if (!(await stat(gitDirectory)).isDirectory())
123
+ return 'No Git branch';
124
+ }
125
+ const head = await metadataText(join(gitDirectory, 'HEAD'));
126
+ const branch = /^ref: refs\/heads\/([^\x00-\x20\x7f]+)$/.exec(head);
127
+ if (branch)
128
+ return branch[1];
129
+ return /^[a-f0-9]{40,64}$/i.test(head) ? `HEAD (detached at ${head.slice(0, 7)})` : 'No Git branch';
130
+ }
131
+ catch {
132
+ return 'No Git branch';
133
+ }
134
+ }
135
+ export function safeTerminal(text) {
136
+ return stripVTControlCharacters(text).replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, '');
137
+ }
138
+ /** Short follow-up directions that mean "continue the unfinished work" rather than start a new task. */
139
+ export function isContinuationPrompt(text) {
140
+ const normalized = text.trim().replace(/[.!?]+$/, '').trim();
141
+ return normalized.length <= 160 && /^(?:continue|resume|retry|try again|keep going|keep working)(?:\b.*)?$/i.test(normalized);
142
+ }
143
+ /** Retain an unfinished run's plan only when the next prompt explicitly continues that work. */
144
+ export function continuedTodos(task, lastRun) {
145
+ return lastRun && lastRun.status !== 'succeeded' && isContinuationPrompt(task)
146
+ ? (lastRun.todos ?? []).map(todo => ({ ...todo }))
147
+ : [];
148
+ }
149
+ // Re-exported for the callers that already imported it from the CLI; the definition moved beside
150
+ // the provider configuration it reads so the app-server can register secrets without the CLI.
151
+ export { providerSecrets };
152
+ /**
153
+ * Append one runtime event to the record of the run it belongs to.
154
+ *
155
+ * Not every event belongs to a run. The memory health check emitted while the memory manager is
156
+ * constructed, and code-intelligence state before the first run starts, carry no run identity at
157
+ * all: they describe the session. They are skipped, because a per-run file cannot name them --
158
+ * writing one anyway is what used to leave a `runs/undefined.jsonl` behind in the installation.
159
+ * An identity that is present but not well formed is a bug in whatever produced it rather than an
160
+ * absent one, so `runRecordPath` still throws for it.
161
+ * @param directory - the installation directory holding `runs/`.
162
+ * @param event - the runtime event to persist.
163
+ */
164
+ export async function appendRunEvent(directory, event) {
165
+ const runId = event.data.runId;
166
+ if (runId === undefined || runId === null)
167
+ return;
168
+ await appendFile(runRecordPath(directory, runId, 'jsonl'), JSON.stringify(event) + '\n', { mode: 0o600 });
169
+ }
170
+ /**
171
+ * Add the reasoning effort and context window of a root node's own resolution to its
172
+ * `agent.session.started` data, so the footer can describe the model that is answering.
173
+ *
174
+ * The executor reports the provider and model a node resolved but not the effort or window that
175
+ * came with them, and those differ per node: a node that overrides the model loses the provider's
176
+ * saved effort and window (`resolveModelContext`), so reusing the session's numbers would put
177
+ * values on the footer that belong to a model that is not running. Only a root node session is
178
+ * decorated -- a delegated child repeats its parent's node id, and a plain prompt run has no
179
+ * graph node at all -- and the caller's event object is never mutated, so the events the run
180
+ * record holds stay exactly as the runtime emitted them. Both keys are always written together,
181
+ * even when unknown: the terminal reads their presence as proof that this node's resolution is
182
+ * authoritative, so an unknown window cannot silently inherit the session's.
183
+ * @param event - the runtime event on its way to the terminal.
184
+ * @param lookup - the memoized resolution of a provider/model pair, as the node's executor asked for it.
185
+ * @returns the event to hand to the terminal; the original event when there is nothing to add.
186
+ */
187
+ export async function withNodeModelResolution(event, lookup) {
188
+ if (event.type !== 'agent.session.started' || typeof event.data.subagentId === 'string')
189
+ return event;
190
+ const { provider, model } = event.data;
191
+ if (typeof provider !== 'string' || typeof model !== 'string')
192
+ return event;
193
+ let resolved;
194
+ try {
195
+ resolved = await lookup(provider, model);
196
+ }
197
+ catch {
198
+ return event;
199
+ }
200
+ if (!resolved)
201
+ return event;
202
+ return { ...event, data: { ...event.data, reasoningEffort: resolved.reasoningEffort, contextWindow: resolved.contextWindow } };
203
+ }
204
+ const SIGN_OUT_NOTICE = 'Your Andorra session was revoked or expired, so the stored login was removed. Run /login to sign in again.';
205
+ /**
206
+ * Report an automatic sign-out where the current surface can see it, and record it.
207
+ *
208
+ * `--json` paths reserve stdout for the machine-readable result, the interactive path must print
209
+ * through the terminal (its alternate screen owns stdout), and the early command paths have
210
+ * neither, so the destination is chosen per call. The journal callback is optional because a
211
+ * sign-out can be discovered before the session journal exists (`auth status`, `--configure`).
212
+ */
213
+ function reportSignOut(json, terminal, reason, journal) {
214
+ if (json)
215
+ process.stderr.write(safeTerminal(SIGN_OUT_NOTICE) + '\n');
216
+ else if (terminal)
217
+ terminal.print(SIGN_OUT_NOTICE);
218
+ else
219
+ process.stdout.write(safeTerminal(SIGN_OUT_NOTICE) + '\n');
220
+ journal?.(reason);
221
+ }
222
+ export async function main(argv = process.argv.slice(2), dependencies = {}) {
223
+ bootMark('cli.main');
224
+ const persistConfig = dependencies.saveConfig ?? saveConfig;
225
+ const loadGraph = dependencies.loadGraph ?? loadAccessibleGraph;
226
+ const checkGraphHealth = dependencies.checkGraphHealth ?? checkGraphModelHealth;
227
+ // MCP uses stdio for JSON-RPC; never install the ordinary auth reporter here,
228
+ // because a mid-session sign-out notice on stdout would corrupt the protocol.
229
+ if (argv[0] === 'mcp-server') {
230
+ if (argv.length !== 2 || argv[1] !== '--stdio')
231
+ throw new Error('Usage: andorra mcp-server --stdio');
232
+ const { runAgentMcpServer } = await import('./agent-mcp.js');
233
+ return await runAgentMcpServer();
234
+ }
235
+ // Registered before the early authenticated commands (`login`, `logout`, `auth status`,
236
+ // `graph`, `--configure`): each can refresh a stale token and discover a revoked session, and
237
+ // that sign-out must not be silent. The registration after the journal exists replaces this one
238
+ // so the notice also reaches the terminal and the `--debug` journal.
239
+ // The subagent command prints one JSON line on stdout and --json is optional there, so its
240
+ // sign-out notice belongs on stderr like the other machine-output paths.
241
+ const machineOutput = argv.includes('--json') || argv[0] === 'subagent' || argv[0] === 'automations';
242
+ setAuthSignOutReporter(error => reportSignOut(machineOutput, undefined, error.message));
243
+ if (argv[0] === 'login' || argv[0] === 'logout' || argv[0] === 'auth') {
244
+ if ((argv[0] === 'auth' && (argv.length !== 2 || argv[1] !== 'status')) || (argv[0] !== 'auth' && argv.length !== 1))
245
+ throw new Error('Usage: andorra login | andorra logout | andorra auth status');
246
+ const controller = new AbortController();
247
+ const cancel = () => controller.abort();
248
+ process.once('SIGINT', cancel);
249
+ process.once('SIGTERM', cancel);
250
+ try {
251
+ const print = (message) => process.stdout.write(safeTerminal(message) + '\n');
252
+ print(await executeAuthCommand(argv[0] === 'auth' ? 'status' : argv[0], { signal: controller.signal, print }));
253
+ }
254
+ finally {
255
+ process.removeListener('SIGINT', cancel);
256
+ process.removeListener('SIGTERM', cancel);
257
+ }
258
+ return 0;
259
+ }
260
+ if (argv[0] === 'graph') {
261
+ if (argv.length > 2 || (argv[1] !== undefined && argv[1] !== '--no-open'))
262
+ throw new Error('Usage: andorra graph [--no-open]');
263
+ await launchGraphEditor(argv[1] === '--no-open');
264
+ return 0;
265
+ }
266
+ if (argv[0] === 'app-server') {
267
+ if (argv.length !== 2 || argv[1] !== '--stdio')
268
+ throw new Error('Usage: andorra app-server --stdio');
269
+ // Loaded on demand: the machine-client surface pulls in the PTY, QA, and graph-server modules,
270
+ // and an ordinary TUI or headless invocation must not pay for them.
271
+ const { runAppServer } = await import('./app-server.js');
272
+ bootMark('app-server.imported');
273
+ // The desktop client owns this process and its stdio; in this mode nothing may print to stdout.
274
+ return await runAppServer();
275
+ }
276
+ if (argv[0] === 'automations') {
277
+ const { runAutomationCommand } = await import('./automation-service.js');
278
+ return runAutomationCommand(argv.slice(1), line => process.stdout.write(line + '\n'));
279
+ }
280
+ if (argv[0] === 'remote') {
281
+ // Loaded on demand like `app-server`: the remote modules pull in TLS, x509, and the peer
282
+ // client, and no other command path needs them.
283
+ const { REMOTE_USAGE, runRemoteCommand } = await import('./remote/command.js');
284
+ if (argv.includes('--help') || argv.includes('-h')) {
285
+ process.stdout.write(`${REMOTE_USAGE}\n`);
286
+ return 0;
287
+ }
288
+ const version = await cliVersion().catch(() => '0.0.0');
289
+ return await runRemoteCommand(argv.slice(1), line => process.stdout.write(safeTerminal(line) + '\n'), { version });
290
+ }
291
+ if (argv[0] === 'setup') {
292
+ if (argv.length !== 1)
293
+ throw new Error('Usage: andorra setup');
294
+ process.stdout.write('Provider setup has moved. Run andorra, open /providers, and press Right Arrow or e to edit a provider or choose Add provider.\n');
295
+ return 0;
296
+ }
297
+ if (argv[0] === 'subagent')
298
+ return await runSubagentCommand(argv.slice(1));
299
+ if (argv[0] === 'update') {
300
+ if (argv.length > 2 || (argv.length === 2 && argv[1] !== '--break-lock'))
301
+ throw new Error('Usage: andorra update [--break-lock]');
302
+ process.stdout.write('Updating Andorra from GitHub main...\n');
303
+ const notify = (message) => process.stdout.write(safeTerminal(message) + '\n');
304
+ process.stdout.write(safeTerminal(await updateInstallation({ breakLock: argv[1] === '--break-lock', notify })) + '\n');
305
+ return 0;
306
+ }
307
+ const { values } = parseArgs({ args: argv, options: {
308
+ help: { type: 'boolean', short: 'h' }, version: { type: 'boolean' },
309
+ prompt: { type: 'string', short: 'p' }, 'no-tui': { type: 'boolean' },
310
+ provider: { type: 'string' }, model: { type: 'string' }, graph: { type: 'string' },
311
+ cwd: { type: 'string' }, yolo: { type: 'boolean' }, jev: { type: 'string' }, json: { type: 'boolean' }, debug: { type: 'boolean' },
312
+ configure: { type: 'boolean' }, 'run-input': { type: 'string' }, 'run-state': { type: 'string' },
313
+ } });
314
+ const readValues = async (path, flag) => {
315
+ if (!path)
316
+ return undefined;
317
+ const value = JSON.parse(await readFile(path, 'utf8'));
318
+ if (!value || typeof value !== 'object' || Array.isArray(value))
319
+ throw new Error(`${flag} must reference a JSON object file`);
320
+ return value;
321
+ };
322
+ const runInput = await readValues(values['run-input'], '--run-input');
323
+ const runState = await readValues(values['run-state'], '--run-state');
324
+ let terminal;
325
+ const print = (text) => terminal ? terminal.print(text) : process.stdout.write(safeTerminal(text) + '\n');
326
+ if (values.help) {
327
+ print(`Andorra Code\nUsage: andorra [--cwd path] [--provider id] [--model id] [--graph id] [--run-input file.json] [--run-state file.json] [--yolo] [--jev on|off] [--debug]\n andorra --prompt "task" [--json] [--yolo] [--jev on|off] [--debug]\n andorra subagent --prompt "task" [--provider id] [--model id] [--read-only]\n andorra graph [--no-open]\n andorra automations list|run|service|serve\n andorra app-server --stdio\n andorra mcp-server --stdio\n andorra remote serve|status|code|devices|revoke|share|unshare|pair|workspaces|unpair|rotate-cert\n andorra update\n andorra login\n andorra logout\n andorra auth status\n\n${HELP}`);
328
+ return 0;
329
+ }
330
+ if (values.version) {
331
+ print(await cliVersion());
332
+ return 0;
333
+ }
334
+ if (values.configure) {
335
+ await launchGraphEditor();
336
+ return 0;
337
+ }
338
+ const interactive = values.prompt === undefined;
339
+ const sessionStartedAt = Date.now();
340
+ // Declared early because the startup guard's closing record reads it before the signal
341
+ // handlers below exist; nothing sets it true until terminate() runs.
342
+ let terminated = false;
343
+ // The journal starts before the first fallible startup step (graph flag, config load,
344
+ // workspace resolution), so a failed `--debug` invocation still explains itself. Provider
345
+ // credentials are not known until the config loads; they register once it does.
346
+ let trajectory = await createSessionTrajectory({
347
+ // The log lives beside the sessions this terminal writes, so the window can find a session's
348
+ // conversation: it reads the log of the session it is showing.
349
+ directory: dependencies.trajectoryDirectory ?? join(configDirectory(), 'trajectories'),
350
+ onError: message => { if (values.json)
351
+ process.stderr.write(safeTerminal(message) + '\n');
352
+ else
353
+ print(message); },
354
+ ...(values.debug ? { meta: {
355
+ debug: true, argv, pid: process.pid, platform: process.platform, arch: process.arch, nodeVersion: process.version,
356
+ version: await cliVersion(), interactive,
357
+ } } : {}),
358
+ });
359
+ // The trajectory just recorded `session.started`; the conversation began here. It is emitted once
360
+ // per creation, never for a reopen. The promise is retained so the drain at exit runs after the
361
+ // enqueue: a drain that starts first exits with the event still pending in a tearing-down home.
362
+ // The conversation does not exist yet: an interactive session opened and closed without a task
363
+ // creates no saved conversation, so the start is emitted where the first one is created.
364
+ let sessionStarted = Promise.resolve();
365
+ const noteSessionStarted = (extra = {}) => {
366
+ sessionStarted = sessionStarted.then(() => currentGraphSubject().catch(() => undefined)).then(subject => reportSessionStarted({ home: configDirectory(), surface: configuredSurface('cli'), ...(subject === undefined ? {} : { subject }), ...extra })).catch(() => { });
367
+ };
368
+ /**
369
+ * The log a session's conversation is written to.
370
+ *
371
+ * A session has one log. The process opens one before the configuration is read, so a failed
372
+ * start still explains itself, and a session the user picks or forks takes a log of its own: the
373
+ * records of two conversations must never share a file, or the window would show them mixed. The
374
+ * log is named after the session, so the window finds it by the session's own id.
375
+ */
376
+ const openSessionTrajectory = async (sessionId) => {
377
+ const directory = dependencies.trajectoryDirectory ?? join(configDirectory(), 'trajectories');
378
+ const path = join(directory, `${sessionId}.jsonl`);
379
+ const reopened = await stat(path).then(() => true, () => false);
380
+ trajectory = await createSessionTrajectory({
381
+ sessionId, directory, reopened,
382
+ onError: message => { if (values.json)
383
+ process.stderr.write(safeTerminal(message) + '\n');
384
+ else
385
+ print(message); },
386
+ ...(values.debug ? { meta: { debug: true, argv, pid: process.pid, platform: process.platform, arch: process.arch, nodeVersion: process.version, version: await cliVersion(), interactive } } : {}),
387
+ });
388
+ if (!reopened)
389
+ noteSessionStarted({ workspace });
390
+ trajectory.addSecrets(providerSecrets(config.providers));
391
+ };
392
+ /**
393
+ * `--debug` session accounting: every user command with its wall-clock cost, CLI-level
394
+ * errors that never reach a runtime event, and a closing summary. Model requests, tool
395
+ * calls and their timings are recorded unconditionally through the adapter wrapper and
396
+ * runtime events; these records add the conversation layer around them.
397
+ */
398
+ const debugRecord = (type, data) => values.debug ? trajectory.record(type, data) : undefined;
399
+ const sessionEndedRecord = (extra = {}) => debugRecord('session.ended', { durationMs: Date.now() - sessionStartedAt, usage: sessionUsage(), interactive, terminated, ...extra });
400
+ // An automatic sign-out must be visible and recorded: the wipe removes the credential itself,
401
+ // so without this the user only sees authenticated features stop working. Explicit /logout is
402
+ // reported by its own command and never reaches this reporter. This registration replaces the
403
+ // early one, so the notice also reaches the terminal and the `--debug` journal.
404
+ setAuthSignOutReporter(error => reportSignOut(values.json === true, terminal, error.message, message => { void debugRecord('auth.signed-out', { message }); }));
405
+ /**
406
+ * Startup failures after the journal exists must still close it: a `--debug` invocation
407
+ * that dies during validation or initialization would otherwise leave the log open at
408
+ * `session.started` with no explanation. No provider call can have happened yet, so the
409
+ * closing summary reports zero usage; whatever manager was created is released.
410
+ */
411
+ let releaseCodeIntel;
412
+ const startupGuard = async (operation) => {
413
+ try {
414
+ return await operation();
415
+ }
416
+ catch (error) {
417
+ await debugRecord('session.ended', {
418
+ durationMs: Date.now() - sessionStartedAt, usage: { requests: 0, inputTokens: 0, outputTokens: 0 },
419
+ interactive, terminated, startupError: error instanceof Error ? error.message : String(error),
420
+ });
421
+ await trajectory.flush();
422
+ try {
423
+ await releaseCodeIntel?.();
424
+ }
425
+ catch { /* Disposal is best effort during startup failure. */ }
426
+ throw error;
427
+ }
428
+ };
429
+ /** Fails startup under the journal-closing guard; the guard rethrows the wrapped error. */
430
+ const startupReject = (message) => startupGuard(async () => { throw new Error(message); });
431
+ if (values.graph && values.graph !== 'default')
432
+ await startupGuard(() => loadGraph(values.graph));
433
+ if (values.json && !values.prompt)
434
+ await startupReject('--json requires --prompt');
435
+ if (values['no-tui'] && !values.prompt)
436
+ await startupReject('--no-tui requires --prompt');
437
+ if (values.jev !== undefined && !['on', 'off'].includes(values.jev))
438
+ await startupReject('--jev takes on or off');
439
+ if (values.prompt !== undefined && !values.prompt.trim())
440
+ await startupReject('--prompt must not be empty');
441
+ if (interactive && (!process.stdin.isTTY || !process.stdout.isTTY))
442
+ await startupReject('Interactive mode requires a terminal. Use --prompt "task" for headless execution.');
443
+ const config = await startupGuard(() => loadConfig());
444
+ const workspace = await startupGuard(async () => {
445
+ const resolved = await realpath(values.cwd ?? process.cwd());
446
+ if (!(await stat(resolved)).isDirectory())
447
+ throw new Error('--cwd must be a directory');
448
+ return resolved;
449
+ });
450
+ if (!config.providers.length && !interactive)
451
+ await startupReject('No providers configured. Run andorra, then /providers to add a provider before starting a task.');
452
+ await startupGuard(async () => {
453
+ if (values.provider) {
454
+ if (!config.providers.some(p => p.id === values.provider))
455
+ throw new Error(`Unknown provider: ${values.provider}`);
456
+ config.provider = values.provider;
457
+ }
458
+ if (values.model) {
459
+ const selected = config.providers.find(p => p.id === config.provider);
460
+ if (!selected)
461
+ throw new Error('Add a provider in /providers before choosing a model.');
462
+ if (selected.model !== values.model) {
463
+ applyModelContextWindow(selected, values.model);
464
+ delete selected.reasoningEffort;
465
+ }
466
+ recordProviderModel(selected, values.model);
467
+ selected.model = values.model;
468
+ }
469
+ });
470
+ const permissions = values.yolo ? 'full-access' : config.workspacePermissions?.[workspacePermissionKey(workspace)] ?? 'ask-for-approval';
471
+ // `--jev on|off` is this session's decision policy the way `--yolo` is its permission mode: it is
472
+ // never written to the configuration, and an explicit `/jev on|off` during the session replaces it.
473
+ let jevOverride = values.jev === undefined ? undefined : values.jev === 'on';
474
+ const jevOn = () => jevOverride ?? config.jevEnabled !== false;
475
+ const afterJevCommand = (input, result) => {
476
+ const match = /^\/jev(?:\s+(on|off|status))?\s*$/.exec(input.trim());
477
+ if (!match || jevOverride === undefined)
478
+ return;
479
+ if (match[1] === 'on' || match[1] === 'off')
480
+ jevOverride = undefined;
481
+ else
482
+ result.text += `\nThis session started with --jev ${jevOverride ? 'on' : 'off'}, which overrides the saved preference until /jev on|off.`;
483
+ };
484
+ const state = await startupGuard(async () => ({ config, workspace, graph: values.graph ?? configuredGraphSelection(config, await currentGraphSubject()), permissions, yolo: permissions === 'full-access', usage: { inputTokens: 0, outputTokens: 0, requests: 0 }, notify: print, history: [],
485
+ // Direct /model shares the graph-override question with the /model screen; without a
486
+ // terminal the answer is always "keep", so nothing is ever overridden unobserved.
487
+ confirmModelOverride: async (question) => {
488
+ if (!terminal)
489
+ return false;
490
+ const choice = await terminal.select('Override graph models?', [
491
+ { id: 'override', label: 'Override every node with the new model', description: 'Saves the graph; every node and delegation follows this model.' },
492
+ { id: 'keep', label: 'Keep the models selected in the graph', description: 'Cancels this model change; nothing is saved.' },
493
+ ], { description: question });
494
+ return choice === 'override';
495
+ } }));
496
+ // A saved per-account graph selection re-checks membership on every launch, so a transient
497
+ // account-service failure or a membership lapse must not deny the whole session: fall back
498
+ // to the local Software Engineer graph and say so. A selection whose providers this machine
499
+ // cannot serve stays selected instead — the session refresh reports it and the header asks for
500
+ // the model override that runs it, so /model is one command away rather than a re-selection.
501
+ // An explicit --graph flag still fails fast because the caller asked for that exact graph.
502
+ let startupGraph;
503
+ let startupGraphSelection;
504
+ let startupGraphReused = false;
505
+ let graphFallbackNotice;
506
+ await startupGuard(async () => {
507
+ const selection = state.graph ?? 'default';
508
+ if (selection === 'default')
509
+ return;
510
+ try {
511
+ startupGraph = await loadGraph(selection);
512
+ startupGraphSelection = selection;
513
+ }
514
+ catch (error) {
515
+ // Nothing is printed here: the refresh right below the terminal's start reports the
516
+ // binding failure and sets the override hint, so the reason and the way out arrive together.
517
+ if (error instanceof GraphProviderUnavailableError && values.graph === undefined)
518
+ return;
519
+ if (values.graph !== undefined || !(error instanceof PaidMembershipRequiredError))
520
+ throw error;
521
+ state.graph = 'default';
522
+ graphFallbackNotice = graphFallbackReason(error);
523
+ if (!interactive)
524
+ process.stderr.write(safeTerminal(graphFallbackNotice) + '\n');
525
+ }
526
+ });
527
+ let activeUsage = { inputTokens: 0, outputTokens: 0, requests: 0, cacheRead: 0, cacheWrite: 0 };
528
+ // Cache totals stay sparse: a provider that reports no cache counts must not
529
+ // materialize explicit zeros in persisted session state or the /usage screen.
530
+ const foldCache = (target, cacheRead, cacheWrite) => {
531
+ const read = (target.cacheRead ?? 0) + (cacheRead ?? 0);
532
+ if (read > 0)
533
+ target.cacheRead = read;
534
+ const write = (target.cacheWrite ?? 0) + (cacheWrite ?? 0);
535
+ if (write > 0)
536
+ target.cacheWrite = write;
537
+ };
538
+ // Input size of the most recent model request, i.e. how full the live conversation
539
+ // context currently is. Providers that report no usage leave it at its last value.
540
+ let contextUsedTokens = 0;
541
+ // The reading the record keeps for the desktop's context ring: only what the current run
542
+ // measured, never the footer's estimates. The window is left out — the footer sizes against
543
+ // the active provider, not the model that answered — so the desktop sizes it from configuration.
544
+ let runContext;
545
+ const sessionUsage = () => ({
546
+ requests: state.usage.requests + activeUsage.requests,
547
+ inputTokens: state.usage.inputTokens + activeUsage.inputTokens,
548
+ outputTokens: state.usage.outputTokens + activeUsage.outputTokens,
549
+ cacheRead: (state.usage.cacheRead ?? 0) + activeUsage.cacheRead,
550
+ cacheWrite: (state.usage.cacheWrite ?? 0) + activeUsage.cacheWrite,
551
+ contextUsed: contextUsedTokens,
552
+ });
553
+ const sessionContexts = new Map();
554
+ const contextKey = (provider) => JSON.stringify([
555
+ provider.id, provider.type, provider.baseUrl, provider.model, provider.apiKeyEnv, provider.contextWindow,
556
+ ]);
557
+ const runtimeProvider = (provider) => ({
558
+ ...provider, contextWindow: sessionContexts.get(contextKey(provider)) ?? provider.contextWindow,
559
+ });
560
+ // Config is known only now (the journal starts before config load), so provider credentials
561
+ // register here; mid-session /providers edits re-register through the same helper.
562
+ trajectory.addSecrets(providerSecrets(config.providers));
563
+ const selectedProvider = config.providers.find(p => p.id === config.provider);
564
+ await debugRecord('session.context', {
565
+ workspace, yolo: state.yolo, graph: state.graph ?? 'default', provider: config.provider, model: selectedProvider?.model,
566
+ providers: config.providers.map(provider => ({ id: provider.id, type: provider.type, baseUrl: provider.baseUrl, model: provider.model, ...(provider.contextWindow !== undefined ? { contextWindow: provider.contextWindow } : {}) })),
567
+ });
568
+ const sessionDescription = () => `Conversation ID: ${savedSession?.id ?? trajectory.sessionId}\nTrajectory: ${trajectory.path}`;
569
+ const sessions = new SessionStore(configDirectory());
570
+ const tabTitle = new SessionTitle({ isTTY: interactive && process.stdout.isTTY, write: text => process.stdout.write(text) });
571
+ let savedSession;
572
+ let sessionArchive = [];
573
+ let awaitingInput = 0;
574
+ const updateTitle = (working = true) => tabTitle.set(savedSession?.name ?? '', working ? (awaitingInput || runControl?.isPaused ? 'input' : 'working') : 'idle');
575
+ const persistSession = async (pendingTask, pendingRunId, pendingAttachments) => {
576
+ if (!savedSession)
577
+ return;
578
+ const pendingHistory = pendingTask ? [{ task: pendingTask, completion: { summary: RUNNING_TURN_SUMMARY, tests: [], status: 'running' }, ...(pendingRunId === undefined ? {} : { runId: pendingRunId }), ...(pendingAttachments?.length ? { attachments: pendingAttachments } : {}) }] : [];
579
+ savedSession = { projectId: savedSession.projectId ?? projectIdentity(workspace), ...savedSession, contextHistory: [...state.history ?? [], ...pendingHistory].slice(-6), updatedAt: new Date().toISOString(), history: [...sessionArchive, ...pendingHistory], usage: { ...state.usage }, trajectoryId: trajectory.sessionId };
580
+ const record = savedSession;
581
+ try {
582
+ // This command's copy of the session was read when it started, while the desktop archives
583
+ // and renames through its own process. Take the same per-session mutation lock every rail
584
+ // mutation takes, read the stored record under it, and carry the fields that belong to the
585
+ // rail, or a save here silently returns an archived session to the working rail. A lock
586
+ // another process will not give up is not a reason to lose this turn: the save then goes
587
+ // through unmerged, which is exactly what it did before.
588
+ let releaseRailLock;
589
+ try {
590
+ releaseRailLock = await acquireSessionMutationLock(configDirectory(), record.id);
591
+ }
592
+ catch { /* held elsewhere: save unmerged rather than not at all */ }
593
+ try {
594
+ if (releaseRailLock) {
595
+ let stored;
596
+ try {
597
+ stored = JSON.parse(await readFile(join(configDirectory(), 'sessions', `${record.id}.json`), 'utf8'));
598
+ }
599
+ catch { /* no record yet: nothing to carry */ }
600
+ carryRailOwnedFields(record, stored);
601
+ }
602
+ if (browserBridge)
603
+ await browserBridge.persist(() => sessions.save(record));
604
+ else
605
+ await sessions.save(record);
606
+ }
607
+ finally {
608
+ await releaseRailLock?.().catch(() => { });
609
+ }
610
+ }
611
+ catch (error) {
612
+ const message = `Could not save session: ${error instanceof Error ? error.message : String(error)}`;
613
+ if (values.json)
614
+ process.stderr.write(safeTerminal(message) + '\n');
615
+ else
616
+ print(message);
617
+ }
618
+ };
619
+ const directory = configDirectory();
620
+ // Spooled attachments are files, not records: retire the ones no conversation can still reference.
621
+ void pruneAttachments(directory).catch(() => { });
622
+ let browserApp;
623
+ let browserBridge;
624
+ const browserSteering = [];
625
+ let browserPrompt;
626
+ let browserAcceptance = Promise.resolve();
627
+ let browserRollbackFailed = false;
628
+ // Finalization keeps the session non-idle so the browser cannot submit into
629
+ // a terminal whose next question is not armed yet. A cancellation recorded
630
+ // while a durably accepted prompt is still starting aborts it at run start.
631
+ let browserDraining = false;
632
+ let browserCancelPending = false;
633
+ const rollbackFailureMessage = 'Session storage rollback failed. Repair local storage and inspect session history before restarting this CLI.';
634
+ await startupGuard(() => mkdir(runRecordsDirectory(directory), { recursive: true }));
635
+ // Attempts a previous process left in flight (or never opened a record for at all) are classified
636
+ // before this one can write any: the pass reads pids and rewrites markers, and sessions are not
637
+ // loaded yet here, so it can never race an in-memory copy. Best-effort: a damaged home must not
638
+ // block opening the CLI.
639
+ try {
640
+ const recovered = await reconcileInterruptedRuns(directory, undefined, { skipOwnProcess: true, includePending: true });
641
+ // A recovered run still owes its `interrupted` finish, so the pair joins through the same
642
+ // telemetry id the open record carried.
643
+ await reportInterruptedRuns({ home: directory, surface: configuredSurface('cli') }, recovered.interrupted);
644
+ const parts = [];
645
+ if (recovered.runs.length > 0)
646
+ parts.push(`${recovered.runs.length} interrupted run${recovered.runs.length === 1 ? '' : 's'}`);
647
+ if (recovered.markers > 0)
648
+ parts.push(`${recovered.markers} unfinished turn${recovered.markers === 1 ? '' : 's'}`);
649
+ if (parts.length > 0) {
650
+ const notice = `Recovered ${parts.join(' and ')} from earlier sessions.`;
651
+ if (values.json)
652
+ process.stderr.write(safeTerminal(notice) + '\n');
653
+ else
654
+ print(notice);
655
+ }
656
+ }
657
+ catch { /* Recovery is best effort. */ }
658
+ let runEventSink;
659
+ const codeIntelLabel = (state) => state === 'indexing' ? 'Indexing' : state === 'ready' ? 'Ready' : state === 'syncing' ? 'Updating'
660
+ : state === 'degraded' ? 'Degraded' : state === 'error' ? 'Error' : undefined;
661
+ const codeIntelNotice = (event) => {
662
+ if (event.type === 'codeintel.state') {
663
+ const label = codeIntelLabel(event.data.state);
664
+ terminal?.setStatus({ codeIntel: label });
665
+ if (event.data.state === 'error')
666
+ process.stderr.write(`CodeGraph: ${String(event.data.detail ?? 'unavailable')}\n`);
667
+ }
668
+ };
669
+ // A shell commonly starts in the user's home. Never recursively index that
670
+ // personal tree as an implicit side effect of opening the coding client.
671
+ // This override is session-only; /codegraph enable remains an explicit opt-in.
672
+ const homeWorkspace = workspace === await realpath(homedir()).catch(() => homedir());
673
+ const codeIntel = await startupGuard(() => CodeIntelligenceManager.create({
674
+ permissions: state.permissions,
675
+ config: homeWorkspace ? { ...resolveCodeIntelConfig(config), enabled: false, enabledRepos: [] } : resolveCodeIntelConfig(config), workspace,
676
+ onEvent: event => (runEventSink ?? codeIntelNotice)(event),
677
+ }));
678
+ releaseCodeIntel = () => codeIntel.dispose();
679
+ state.codeIntel = codeIntel;
680
+ /**
681
+ * Feed the side panel's live sections: the working tree, the branch, and the terminals.
682
+ *
683
+ * The Git summary spawns `git`, so it runs at most once at a time and not more often than the
684
+ * panel could show a difference - a run that writes a file per second must not spawn a process
685
+ * per file, and a reader only needs the count to move. A call the throttle or an in-flight read
686
+ * turns away is not dropped: it is remembered as pending and re-run when the read settles, so
687
+ * the last event before a quiet stretch is still reflected. The branch is read here rather than
688
+ * only at run boundaries because a tool can switch branches mid-run, and reading it is two
689
+ * bounded file reads (`gitBranch` never executes anything). The terminal list needs no care at
690
+ * all: the QA PTY sessions live in this process, so listing them is a map walk.
691
+ * @param force - read the working tree now, ignoring the throttle. Run boundaries pass it;
692
+ * tool completions do not, so a tool-heavy run cannot spawn hundreds of git processes.
693
+ */
694
+ let changesInFlight = false;
695
+ let changesReadAt = 0;
696
+ let changesPending;
697
+ let changesEverRead = false;
698
+ let changesTimer;
699
+ let terminalsTimer;
700
+ const panelReads = new AbortController();
701
+ const CHANGE_REFRESH_MS = 2_000;
702
+ const TERMINAL_WATCH_MS = 1_000;
703
+ const listTerminals = () => getQaPtyManager(workspace).list().map(session => ({ id: session.id, command: session.command, running: session.running, startedAt: session.startedAt }));
704
+ /**
705
+ * Notice a background terminal that exits on its own.
706
+ *
707
+ * The manager records the exit in its own session, but nothing in the tool flow reports it:
708
+ * without this watch the panel would keep a finished session as running, keep counting its age
709
+ * up, and keep the frame's clock ticking until the run ended. The watch exists only while a
710
+ * displayed session is running, and the map walk it performs is free.
711
+ */
712
+ const watchTerminals = (sessions) => {
713
+ const running = sessions.some(session => session.running);
714
+ if (running && !terminalsTimer) {
715
+ terminalsTimer = setInterval(() => {
716
+ // The ages it maintains are only drawn by the panel: hidden, the watch stops and the
717
+ // `panel` event re-arms it when the panel comes back.
718
+ if (!terminal || !terminal.panelVisible()) {
719
+ clearInterval(terminalsTimer);
720
+ terminalsTimer = undefined;
721
+ return;
722
+ }
723
+ const listed = listTerminals();
724
+ terminal.setStatus({ terminals: listed });
725
+ if (!listed.some(session => session.running)) {
726
+ clearInterval(terminalsTimer);
727
+ terminalsTimer = undefined;
728
+ }
729
+ }, TERMINAL_WATCH_MS);
730
+ terminalsTimer.unref?.();
731
+ }
732
+ else if (!running && terminalsTimer) {
733
+ clearInterval(terminalsTimer);
734
+ terminalsTimer = undefined;
735
+ }
736
+ };
737
+ const readChanges = () => {
738
+ changesInFlight = true;
739
+ changesPending = undefined;
740
+ if (changesTimer) {
741
+ clearTimeout(changesTimer);
742
+ changesTimer = undefined;
743
+ }
744
+ void gitChangeSummary(workspace, { signal: panelReads.signal })
745
+ .then(changes => { changesReadAt = Date.now(); changesEverRead = true; terminal?.setStatus({ changes }); })
746
+ .catch(() => {
747
+ // A read that failed leaves the last good reading in place, and it counts as an attempt:
748
+ // a repository that rejects every read (an unreadable index, a filter it cannot vouch for)
749
+ // must not make each following tool event start another full scan. With nothing to keep,
750
+ // the section is told the reading is unavailable instead of claiming to still read.
751
+ changesReadAt = Date.now();
752
+ if (!changesEverRead) {
753
+ terminal?.setStatus({ changes: { isGit: true, files: 0, untracked: 0, insertions: 0, deletions: 0, unavailable: 'the working tree could not be read' } });
754
+ }
755
+ })
756
+ .finally(() => {
757
+ changesInFlight = false;
758
+ const pending = changesPending;
759
+ changesPending = undefined;
760
+ if (panelReads.signal.aborted || pending === undefined)
761
+ return;
762
+ // A queued forced read (a run boundary) starts now; a queued tool boundary waits out the
763
+ // rest of the window it was turned away from, so draining the queue cannot run two scans
764
+ // milliseconds apart.
765
+ // Through the gate even here: the panel may have been hidden (a narrowed terminal, the
766
+ // dashboard, a modal) between the request and this drain.
767
+ if (pending === 'force')
768
+ refreshPanelStatus(true);
769
+ else
770
+ scheduleChanges(CHANGE_REFRESH_MS - (Date.now() - changesReadAt));
771
+ });
772
+ };
773
+ /**
774
+ * Read now, or at the end of the throttle window - never later, and never not at all.
775
+ *
776
+ * A request that arrives inside the window is queued rather than dropped, and because nothing
777
+ * else would come back for it, the queue is drained by a timer armed for the remainder of the
778
+ * window: the last tool completion of a quiet task must still reach the panel, and a run that
779
+ * ends while a read is in flight must not leave the counts behind an unsettled snapshot.
780
+ */
781
+ const scheduleChanges = (delayMs) => {
782
+ if (changesTimer || panelReads.signal.aborted)
783
+ return;
784
+ // Through the gate, not around it: the panel may have been hidden (a narrowed terminal, the
785
+ // dashboard) between the request and its timer, and a hidden panel buys no git process.
786
+ changesTimer = setTimeout(() => { changesTimer = undefined; refreshPanelStatus(true); }, Math.max(0, delayMs));
787
+ changesTimer.unref?.();
788
+ };
789
+ const refreshPanelStatus = (force = false) => {
790
+ if (!terminal)
791
+ return;
792
+ // The panel is the only consumer of both reads, so a terminal that cannot show it - too
793
+ // narrow, too short, or on the dashboard or a modal screen - costs nothing: no terminal list,
794
+ // no branch read and, above all, no git process. `panel-visible` brings the summary back when
795
+ // a resize or a closed screen makes the panel reachable again.
796
+ if (!terminal.panelVisible()) {
797
+ changesPending = undefined;
798
+ return;
799
+ }
800
+ const sessions = listTerminals();
801
+ terminal.setStatus({ terminals: sessions });
802
+ watchTerminals(sessions);
803
+ void gitBranch(workspace).then(branch => terminal?.setStatus({ branch }));
804
+ // The queue remembers which kind of request is waiting, because the two are drained
805
+ // differently and a forced request must not be softened into a throttled one.
806
+ if (changesInFlight) {
807
+ changesPending = force || changesPending === 'force' ? 'force' : 'throttled';
808
+ return;
809
+ }
810
+ const remaining = CHANGE_REFRESH_MS - (Date.now() - changesReadAt);
811
+ if (!force && remaining > 0) {
812
+ scheduleChanges(remaining);
813
+ return;
814
+ }
815
+ readChanges();
816
+ };
817
+ let jevEnabled = jevOn();
818
+ if (interactive)
819
+ await startupGuard(async () => {
820
+ const selected = config.providers.find(p => p.id === config.provider);
821
+ const codeIntelState = codeIntelLabel((await codeIntel.getStatus()).state);
822
+ terminal = new TerminalUI({ account: { label: 'Checking account...', notice: 'Checking member access. Local Software Engineer remains available.' }, workspace, provider: selected?.id ?? 'No provider', model: selected?.model ?? '/providers to configure', providerModels: Object.fromEntries(config.providers.map(p => [p.id, p.model])), reasoningEffort: selected?.reasoningEffort, contextWindow: selected?.contextWindow, version: await cliVersion(), branch: await gitBranch(workspace), yolo: state.yolo, permissions: permissionLabel(state.permissions), graphSelection: state.graph ?? 'default', // The refresh below reads the definition of a graph that cannot bind, so construction must not depend on binding it.
823
+ graph: startupGraph ?? await loadGraph(state.graph ?? 'default').catch(() => undefined), ...(codeIntelState ? { codeIntel: codeIntelState } : {}), clipboardImageProbe: readClipboardImage, clipboardTextWriter: writeClipboardText });
824
+ terminal.setLocalCommandHandler((input, mode, durationMs) => {
825
+ // Local view commands never reach either CLI command loop.
826
+ void debugRecord('command.started', { input, mode });
827
+ void debugRecord('command.completed', { input, mode, durationMs });
828
+ });
829
+ terminal.setStatus({ codeIntel: codeIntelLabel((await codeIntel.getStatus()).state), jevEnabled });
830
+ // The first render after `start()` announces the panel when it is visible, and that event owns
831
+ // the first summary: asking here as well would run the whole multi-process read twice on every
832
+ // wide-terminal launch.
833
+ terminal.on('panel', () => refreshPanelStatus(true));
834
+ if (graphFallbackNotice)
835
+ terminal.print(graphFallbackNotice);
836
+ });
837
+ const refreshStatus = () => {
838
+ jevEnabled = jevOn();
839
+ const configured = config.providers.find(p => p.id === config.provider);
840
+ const selected = configured ? runtimeProvider(configured) : undefined;
841
+ terminal?.setStatus({ provider: selected?.id ?? 'No provider', model: selected?.model ?? '/providers to configure', providerModels: Object.fromEntries(config.providers.map(p => [p.id, p.model])), reasoningEffort: selected?.reasoningEffort, contextWindow: selected?.contextWindow, yolo: state.yolo, permissions: permissionLabel(state.permissions), jevEnabled, ...sessionUsage() });
842
+ };
843
+ let graphModelsHealthy = false;
844
+ const refreshGraphStatus = async () => {
845
+ if (terminal) {
846
+ const controller = active ?? new AbortController();
847
+ const ownsController = !active;
848
+ if (ownsController)
849
+ active = controller;
850
+ terminal.setStatus({ activity: 'Checking graph models' });
851
+ graphModelsHealthy = false;
852
+ // Run preflights reuse the startup graph until a refresh replaces it; dropping the
853
+ // cache first means a failed refresh falls back to loading again at run time.
854
+ startupGraph = undefined;
855
+ startupGraphSelection = undefined;
856
+ startupGraphReused = false;
857
+ try {
858
+ let graph;
859
+ try {
860
+ graph = await loadGraph(state.graph ?? 'default', controller.signal);
861
+ }
862
+ catch (error) {
863
+ // A graph that cannot bind keeps the selection: `/graph` has just accepted it (or the
864
+ // user is about to repair it with /model), the run is what refuses it, and replacing it
865
+ // with Default here would silently undo the choice — and point /model's repair at the
866
+ // wrong graph. Its definition is still read, unbound, so the status bar names it; the
867
+ // run preflight keeps loading the bound graph, so the refusal stays where it belongs.
868
+ if (error instanceof GraphProviderUnavailableError) {
869
+ const definition = await loadGraph(state.graph ?? 'default', controller.signal, undefined, { bindProviders: false }).catch(() => undefined);
870
+ if (!controller.signal.aborted) {
871
+ // The hint is what the session should do about the selection, so it is set from the
872
+ // binding failure itself; the unbound definition only names the graph beside it.
873
+ terminal.setStatus({ graphSelection: state.graph ?? 'default', ...(definition === undefined ? {} : { graph: definition }), graphNeedsOverride: true, jevEnabled: jevOn() });
874
+ print(error.message);
875
+ }
876
+ return;
877
+ }
878
+ // The refresh path applies the same membership fallback as startup: without it the
879
+ // denial would only print here while state.graph stays on the paid graph and the first
880
+ // task retries the denied selection.
881
+ if (values.graph !== undefined || (state.graph ?? 'default') === 'default' || !(error instanceof PaidMembershipRequiredError))
882
+ throw error;
883
+ state.graph = 'default';
884
+ graphFallbackNotice = graphFallbackReason(error);
885
+ print(graphFallbackNotice);
886
+ graph = await loadGraph('default', controller.signal);
887
+ }
888
+ startupGraph = graph;
889
+ startupGraphSelection = state.graph ?? 'default';
890
+ jevEnabled = jevOn();
891
+ terminal.setStatus({ graphSelection: state.graph ?? 'default', graph, graphNeedsOverride: false, jevEnabled });
892
+ const health = await checkGraphHealth(graph, config, controller.signal);
893
+ graphModelsHealthy = health.healthy;
894
+ if (!health.healthy)
895
+ print(formatGraphHealthFailure(health));
896
+ }
897
+ finally {
898
+ if (ownsController)
899
+ active = undefined;
900
+ terminal.setStatus({ activity: graphModelsHealthy ? 'Ready' : 'Graph models unavailable' });
901
+ }
902
+ }
903
+ };
904
+ const graphEditor = createGraphEditorSession();
905
+ let accountRefresh;
906
+ let accountRefreshTimer;
907
+ let accountPolling;
908
+ const refreshAccountStatus = async () => {
909
+ accountRefresh?.abort();
910
+ const request = accountRefresh = new AbortController();
911
+ try {
912
+ const account = await getAccountPresentation(request.signal);
913
+ if (!request.signal.aborted)
914
+ terminal?.setStatus({ account });
915
+ }
916
+ catch { /* Cancellation leaves the next refresh in control. */ }
917
+ };
918
+ let active;
919
+ let exiting = false;
920
+ const scheduleAccountRefresh = () => {
921
+ if (!terminal || exiting || accountRefreshTimer)
922
+ return;
923
+ accountRefreshTimer = setTimeout(() => { accountRefreshTimer = undefined; if (!exiting)
924
+ void refreshAccountStatus(); }, 250);
925
+ accountRefreshTimer.unref?.();
926
+ };
927
+ let runControl;
928
+ let approvePending;
929
+ // Self-wake prompts armed by the agent's set_timer tool. A due prompt goes to whichever
930
+ // surface can take it right now: a live terminal-graph run consumes it as steering at its
931
+ // next turn boundary, and an idle conversation composer receives it as a new task. Anywhere
932
+ // else - a command screen, a browser task, the save/teardown window between runs - it waits
933
+ // in `timerPending` until a composer or a turn boundary comes back to collect it, so a
934
+ // prompt is never delivered to the wrong surface and never silently dropped.
935
+ const sessionTimers = new TimerRegistry();
936
+ const timerSteering = [];
937
+ const timerPending = [];
938
+ // Set when a timer's prompt resumed a paused run: prepareTurn injects steering *before*
939
+ // the direction queue, so any later timer must hold in `timerPending` until the poll that
940
+ // carried the resume direction has happened, and only then join the steering channel.
941
+ // Without the hold, the later prompt would reach the model ahead of the earliest deadline.
942
+ let timerResumePending = false;
943
+ const deliverTimerPrompts = () => {
944
+ // Canceled runs may not receive a prompt that no conversation will ever read, so past
945
+ // teardown the due timers are reaped and discarded rather than queued.
946
+ if (exiting) {
947
+ sessionTimers.takeDue();
948
+ return;
949
+ }
950
+ // `takeDue` returns prompts soonest-deadline first, so every channel below preserves order.
951
+ for (const due of sessionTimers.takeDue())
952
+ timerPending.push(`[Timer] ${due.prompt}`);
953
+ while (timerPending.length) {
954
+ const text = timerPending[0];
955
+ if (runControl && active && !active.signal.aborted) {
956
+ // A paused run is blocked in RunControl.wait() until resume(): only that call both
957
+ // clears the pause and carries a direction in, which is why user steering from the
958
+ // browser resumes with its text instead of queueing. A timer due mid-pause must wake
959
+ // the run the same way, or the promised self-wake waits for the user to type.
960
+ if (runControl.isPaused) {
961
+ if (runControl.resume(text)) {
962
+ timerResumePending = true;
963
+ timerPending.shift();
964
+ }
965
+ else
966
+ break;
967
+ }
968
+ else if (timerResumePending)
969
+ break;
970
+ else
971
+ timerSteering.push(timerPending.shift());
972
+ continue;
973
+ }
974
+ // Runs this process executes through `run()` — terminal tasks and prompts accepted by
975
+ // the authenticated browser bridge — drain `timerSteering` at their turn boundaries. A
976
+ // task owned by the standalone browser server polls its own queue instead, so a timer
977
+ // due then waits in `timerPending` and reaches the composer when the terminal is idle.
978
+ if (terminal?.acceptConversationPrompt(text)) {
979
+ timerPending.shift();
980
+ continue;
981
+ }
982
+ break;
983
+ }
984
+ };
985
+ sessionTimers.onDue = deliverTimerPrompts;
986
+ // Ctrl+C escalates: the first press stops the live run — pausing interactive runs so a
987
+ // message can resume them, aborting everything else — and the next press, or a press with
988
+ // nothing left to stop, terminates the program. A run that keeps running past its abort
989
+ // signal would otherwise leave Ctrl+C with no remaining effect.
990
+ const interrupt = () => {
991
+ if (runControl) {
992
+ if (runControl.isPaused)
993
+ kill();
994
+ else
995
+ runControl.pause();
996
+ }
997
+ else if (active) {
998
+ if (active.signal.aborted)
999
+ kill();
1000
+ else
1001
+ active.abort();
1002
+ }
1003
+ else
1004
+ kill();
1005
+ };
1006
+ const teardown = () => { terminated = true; exiting = true; active?.abort(); sessionTimers.clear(); terminal?.close(); };
1007
+ // The Ctrl+C escalation must not become a suggestion: after the terminal is restored, a
1008
+ // run wedged past its abort signal gets a short grace window and then a hard exit.
1009
+ // SIGTERM keeps the patient teardown instead — cleanup of a canceled shell tree is a
1010
+ // bounded wait that outlives this window, and its contract is tested to finish it.
1011
+ // The timer stays referenced on purpose: a wedge can leave main() awaiting a promise
1012
+ // with no other live handle, and an unreferenced timer would let the event loop drain
1013
+ // and the process exit with the implicit status 0 before the backstop ever fires.
1014
+ let killBackstop;
1015
+ const kill = () => {
1016
+ teardown();
1017
+ if (!killBackstop)
1018
+ killBackstop = setTimeout(() => process.exit(143), 2_000);
1019
+ };
1020
+ process.on('SIGINT', interrupt);
1021
+ process.on('SIGTERM', teardown);
1022
+ terminal?.on('SIGINT', interrupt);
1023
+ terminal?.on('close', () => { tabTitle.close(); exiting = true; active?.abort(); });
1024
+ /**
1025
+ * Carry one attempt into the next turn's context. The turns live on `state` so commands
1026
+ * such as /compact and /clear can replace them and the next run sees the result.
1027
+ *
1028
+ * A turn that failed, was cancelled, or crashed still happened: the user asked for this
1029
+ * work and the agent may already have read files or changed the workspace. Dropping it
1030
+ * would make the next message start from a blank history, so the task is retained with a
1031
+ * plain statement of how it ended instead of a fabricated success.
1032
+ * @param task - the task the user submitted.
1033
+ * @param completion - the validated completion, or a summary of the outcome.
1034
+ */
1035
+ const rememberTurn = (task, completion, runId, attachments) => {
1036
+ sessionArchive.push({ task, completion, runId, ...(attachments?.length ? { attachments } : {}) });
1037
+ state.history = [...state.history ?? [], { task, completion, runId, ...(attachments?.length ? { attachments } : {}) }].slice(-6);
1038
+ };
1039
+ /** Render how an attempt ended as history the next turn can read. */
1040
+ const outcomeCompletion = (status, reason, limits) => ({
1041
+ summary: status === 'cancelled'
1042
+ ? 'This attempt was cancelled before it finished; its work may be incomplete.'
1043
+ : `This attempt did not finish: ${stopReasonPhrase(reason, limits)}.`,
1044
+ tests: [], ...(status === 'succeeded' ? {} : { status: status }),
1045
+ });
1046
+ const toolActivity = new ToolActivity();
1047
+ /** The task text an attachment-only submission runs with; both surfaces substitute the same words. */
1048
+ const ATTACHMENT_ONLY_TASK = 'See the attached file(s).';
1049
+ const run = async (task, pending = []) => {
1050
+ if (browserRollbackFailed)
1051
+ throw new Error(rollbackFailureMessage);
1052
+ if (!config.providers.length) {
1053
+ print('Add a provider in /providers before starting a task.');
1054
+ return 1;
1055
+ }
1056
+ // Attachments resolve to disk-backed refs once, before any record names them: a bad
1057
+ // reference refuses the whole turn rather than half-attaching.
1058
+ if (pending.length && terminal)
1059
+ terminal.print(`⌷ attached: ${pending.map(attachmentLabel).join(' · ')}`);
1060
+ let attachments;
1061
+ // Spool directories this run's attached content lives in: the tool layer reads them as
1062
+ // trusted paths, so a paste is readable in every permission mode, steers included. The
1063
+ // replayed history's spools count too — the model is told to read those files again — but
1064
+ // they are owned by the persisted turns, so only this run's steers are cleaned up below.
1065
+ const attachmentSpools = new Set();
1066
+ const steeredSpools = new Set();
1067
+ for (const root of await attachmentReadRoots(directory, (state.history ?? []).flatMap(turn => turn.attachments ?? [])))
1068
+ attachmentSpools.add(root);
1069
+ if (pending.length) {
1070
+ try {
1071
+ attachments = await resolveAttachments(directory, workspace, pending);
1072
+ }
1073
+ catch (error) {
1074
+ print(`Could not attach the queued attachments: ${error instanceof Error ? error.message : String(error)}. The task was not started; re-attach and resend.`);
1075
+ return 1;
1076
+ }
1077
+ for (const root of await attachmentReadRoots(directory, attachments.refs))
1078
+ attachmentSpools.add(root);
1079
+ }
1080
+ // Cancellation must already own this run while its first snapshot is pending.
1081
+ active = new AbortController();
1082
+ if (browserCancelPending) {
1083
+ browserCancelPending = false;
1084
+ active.abort(new Error('Cancelled from browser'));
1085
+ }
1086
+ browserPrompt = task;
1087
+ trajectory.addSecrets(providerSecrets(config.providers));
1088
+ if (!savedSession) {
1089
+ savedSession = { version: 1, id: trajectory.sessionId, name: sessionName(task), workspace, updatedAt: new Date().toISOString(), history: [], usage: { ...state.usage } };
1090
+ // This is the creation this event names: the first task that lands on the session.
1091
+ noteSessionStarted({ workspace });
1092
+ }
1093
+ const accepted = browserAcceptance;
1094
+ browserAcceptance = Promise.resolve();
1095
+ try {
1096
+ await accepted;
1097
+ }
1098
+ catch (error) {
1099
+ active = undefined;
1100
+ browserPrompt = undefined;
1101
+ throw error;
1102
+ }
1103
+ browserBridge?.startRun();
1104
+ const runId = randomUUID();
1105
+ // The telemetry id is random and unrelated to the persisted run id, which is derived from local
1106
+ // state. It is written into the open record so recovery can still join a crash's pair.
1107
+ const telemetryRunId = randomUUID();
1108
+ const startedAt = new Date().toISOString();
1109
+ // Whether a checkpoint could not be written. A checkpoint is the conversation a resume
1110
+ // re-enters the node with, so a run whose checkpoint failed is one no resume may replay: the
1111
+ // resume would re-enter the node from its opening task and repeat the tool calls it had
1112
+ // already made. The failure is marked, and the record carries it past a crash.
1113
+ let checkpointFailed = false;
1114
+ // The selector this attempt runs on, captured at start. Every record the attempt writes
1115
+ // carries it: the result's own `graph` is the pinned graph object, whose id is the bundled
1116
+ // harness's id rather than the selection that loaded it ('default' loads `software-engineer`),
1117
+ // and a resume has to re-select through the same access rules — so it needs this, not the
1118
+ // pinned identity. Captured here rather than re-read at finalize, where a later /graph change
1119
+ // could mislabel the attempt.
1120
+ const runGraphSelection = state.graph ?? 'default';
1121
+ // Bind persisted run inspection to the signed-in account at run creation.
1122
+ const accountSubject = await currentGraphSubject();
1123
+ // The flushable telemetry handle, created before the first terminal path can reach it. The
1124
+ // graph's own size is filled in once it is pinned; until then the open record and a crash carry
1125
+ // zeros rather than a guess.
1126
+ const telemetrySurface = { home: directory, config, ...(accountSubject ? { subject: accountSubject } : {}), surface: configuredSurface('cli') };
1127
+ const telemetryHandle = createRunHandle(telemetryRunId, startedAt, {
1128
+ graphId: runGraphSelection, nodes: 0, subagents: false, permissionMode: state.permissions,
1129
+ jevEnabled: jevOn(), decisionRouting: config.decisions?.mode ?? 'off',
1130
+ }, workspace);
1131
+ let telemetryFinished = false;
1132
+ let telemetryStart;
1133
+ let telemetrySettled = Promise.resolve();
1134
+ // One start per run, and the finish waits for it: a preflight failure reaches the finish before
1135
+ // the normal start site, and emitting the finish alone would leave a run with no start.
1136
+ const startTelemetry = () => {
1137
+ telemetryStart ??= reportRunStarted(telemetrySurface, telemetryHandle).catch(() => { });
1138
+ return telemetryStart;
1139
+ };
1140
+ // Preflight probes are billed requests this attempt made, so they get their own model tuples:
1141
+ // without one, `models[].requests` and the token totals omit every probe, and a run that failed
1142
+ // the health check alone would report no model at all.
1143
+ const probeModels = new Map();
1144
+ // Set when the health check was rejected by the provider: the run never reached the graph, so
1145
+ // the finish has to classify it from this evidence rather than from a missing result.
1146
+ let healthProviderFailed = false;
1147
+ const finishTelemetry = (status, reason, result) => {
1148
+ if (telemetryFinished)
1149
+ return;
1150
+ telemetryFinished = true;
1151
+ // The probes precede the graph, so their tuples are added to whatever capture the finish
1152
+ // reports; a run with no result still reports them, which is the probe-only failure.
1153
+ const capture = result?.telemetry ?? createRunTelemetry();
1154
+ for (const probe of probeModels.values()) {
1155
+ const provider = config.providers.find(item => item.id === probe.provider);
1156
+ recordModelUse(capture, {
1157
+ ...(provider === undefined ? {} : { providerType: provider.type, baseUrl: provider.baseUrl }),
1158
+ model: probe.model, role: 'other', usage: probe.usage,
1159
+ // A probe is a billed request like any other: the user's routing prices cost it too.
1160
+ ...(provider === undefined ? {} : { pricing: pricingFor(config.efficiency?.adaptiveRouting, probe.provider, probe.model) }),
1161
+ });
1162
+ }
1163
+ telemetrySettled = startTelemetry().then(() => reportRunFinished(telemetrySurface, telemetryHandle, {
1164
+ status, reason,
1165
+ ...(result?.providerRequestFailed || healthProviderFailed ? { providerRequestFailed: true } : {}),
1166
+ ...(result?.providerOverflow ? { providerOverflow: true } : {}),
1167
+ ...(result?.telemetry !== undefined || probeModels.size > 0 ? { telemetry: capture } : {}),
1168
+ ...(result ? { toolCalls: result.toolCalls } : {}),
1169
+ })).catch(() => { });
1170
+ };
1171
+ // Any terminal rewrite of this attempt's record keeps its identity fields and folds in the
1172
+ // partial usage accumulated before the failure, so the Runs view never reports a crashed
1173
+ // attempt's model calls as zero while the session totals already count them.
1174
+ const finalizeRunRecord = async (status, reason) => {
1175
+ const record = { id: runId, status, reason, graphSelection: runGraphSelection,
1176
+ ...(accountSubject ? { accountSubject } : {}), usage: { ...activeUsage },
1177
+ ...(savedSession ? { sessionId: savedSession.id } : {}), startedAt,
1178
+ // A record that stopped being a live run says when it did. A terminal status alone cannot tell a
1179
+ // closed attempt apart from the open claim of a run that reused this id, and that difference is
1180
+ // what lets a claim left by a failed cleanup be reclaimed instead of holding the session busy.
1181
+ endedAt: new Date().toISOString(),
1182
+ // The flag a resume consults before it trusts this attempt's conversation: a checkpoint
1183
+ // that could not be written leaves the node to be re-entered from its opening task.
1184
+ ...(checkpointFailed ? { checkpointIntegrity: 'failed' } : {}),
1185
+ ...(runInput === undefined ? {} : { runInput }), ...(runState === undefined ? {} : { runState }) };
1186
+ try {
1187
+ await writeFile(runRecordPath(directory, runId, 'json'), JSON.stringify(record, null, 2) + '\n', { mode: 0o600 });
1188
+ await writeStudioRunSummary(directory, record).catch(() => { });
1189
+ }
1190
+ catch (writeError) {
1191
+ process.stderr.write(`Could not record the stopped run: ${writeError instanceof Error ? writeError.message : String(writeError)}\n`);
1192
+ }
1193
+ finishTelemetry(status, reason);
1194
+ };
1195
+ // The attempt ends by landing this process's own session record and only then withdrawing the
1196
+ // open claim that names the run to every engine's mutation guard. Clearing the claim before the
1197
+ // save would let a rename, archive or delete be accepted into the window that save — written
1198
+ // from the record this process captured at start — then silently overwrites, or recreates for a
1199
+ // delete. Until this point the claim keeps the guard's answer true: the run may be finished, but
1200
+ // its record is still the one arriving. On a failed save the open record and the claim both
1201
+ // stay, and startup recovery owns that pair.
1202
+ const settleRunRecord = async () => {
1203
+ await persistSession();
1204
+ await clearOpenRunClaim(directory, runId);
1205
+ };
1206
+ // The open record names the session and the process that own this attempt, and it lands before
1207
+ // both the cancellation check below and the marker turn: a second engine's startup recovery
1208
+ // must never see the marker before the record that proves the attempt is live — otherwise it
1209
+ // classifies the live attempt as a crash and races its synthesized record against this one,
1210
+ // exactly as the app-server path's ordering prevents. A stop arriving while the first snapshot
1211
+ // is still saving must leave a record the Runs view can find, and the early return finalizes
1212
+ // that record in place. The normal finalizer replaces it too; a crash before then leaves it on
1213
+ // disk, where startup recovery turns it into an interrupted one instead of the run vanishing
1214
+ // with only a journal behind.
1215
+ // The run's own scope and effort ride in the open record too, not only in the result the
1216
+ // finalizer writes: a hard kill leaves this record as the only thing recovery preserves, and a
1217
+ // later resume of an attempt that never finalized rebuilds `$run.input.*`/`$run.state.*` from
1218
+ // it. Persisting them only at the end would make a crashed run resume under a different scope
1219
+ // than the one it was started with — silently dropping or changing mapped inputs.
1220
+ // Kept in a variable because the pinned graph's real shape is stamped into it after preflight:
1221
+ // a crash before finalization then emits an interrupted finish that matches the start instead
1222
+ // of the zeros written here.
1223
+ const openRecord = {
1224
+ id: runId, status: 'running', sessionId: savedSession.id, startedAt, pid: process.pid,
1225
+ graphSelection: runGraphSelection, ...(accountSubject ? { accountSubject } : {}),
1226
+ graph: { id: state.graph ?? 'default' }, provider: config.provider, model: config.providers.find(p => p.id === config.provider)?.model ?? '',
1227
+ // The producing surface travels with the record: recovery can run on another surface in the
1228
+ // same home, and an interrupted finish must still be labeled with the one that started.
1229
+ surface: telemetrySurface.surface,
1230
+ // `startSent` stays false until the start is queued: this record is written before graph
1231
+ // loading and the model-health check, and recovery reads the flag to decide whether it owes
1232
+ // the missing start as well as the finish.
1233
+ telemetry: { runId: telemetryRunId, nodes: 0, subagents: false, jevEnabled: jevOn(), decisionRouting: config.decisions?.mode ?? 'off', permissions: state.permissions, startSent: false },
1234
+ ...(runInput === undefined ? {} : { runInput }), ...(runState === undefined ? {} : { runState }),
1235
+ };
1236
+ const openRecordWritten = await writeOpenRunRecord(directory, openRecord).then(() => true).catch(error => {
1237
+ process.stderr.write(`Could not write the open run record: ${error instanceof Error ? error.message : String(error)}\n`);
1238
+ return false;
1239
+ });
1240
+ // The marker's in-flight claim is only provable through that record: without it recovery would
1241
+ // read the marker as an orphaned crash, so the marker stays unwritten and the run proceeds —
1242
+ // the same order and fallback the app-server start uses.
1243
+ // The saved reading belongs to the newest run: one this session inherited (a fork of a desktop
1244
+ // session) or an earlier run left must not describe the run starting now.
1245
+ runContext = undefined;
1246
+ if (savedSession?.context !== undefined)
1247
+ savedSession = { ...savedSession, context: undefined };
1248
+ if (openRecordWritten)
1249
+ await persistSession(task, runId, attachments?.refs);
1250
+ if (active.signal.aborted || exiting) {
1251
+ // Cancellation can arrive while the accepted prompt is still being saved,
1252
+ // before the graph's try/finally owns cleanup. Retain the cancelled turn and
1253
+ // clear its pending state before persisting the idle browser snapshot.
1254
+ await finalizeRunRecord('cancelled', 'the user stopped this run');
1255
+ rememberTurn(task, outcomeCompletion('cancelled', undefined, undefined), runId, attachments?.refs);
1256
+ browserDraining = true;
1257
+ active = undefined;
1258
+ browserPrompt = undefined;
1259
+ browserSteering.length = 0;
1260
+ browserCancelPending = false;
1261
+ updateTitle(false);
1262
+ await settleRunRecord();
1263
+ browserDraining = false;
1264
+ return terminated ? 143 : 130;
1265
+ }
1266
+ updateTitle();
1267
+ terminal?.setStatus({ session: savedSession.name });
1268
+ // The node's furthest conversation, persisted as it is reached so a stopped run leaves a
1269
+ // resumable checkpoint (`run.resume` in the app-server re-enters it). Writes serialize —
1270
+ // concurrent branches must not leave an older conversation as the file's final content — and
1271
+ // a failure only costs durability, never the run.
1272
+ let checkpointWrites = Promise.resolve();
1273
+ const persistCheckpoint = (nodeId, messages, state, meta) => {
1274
+ checkpointWrites = checkpointWrites
1275
+ .then(() => writeRunCheckpoint(directory, runId, { nodeId, messages, state, revision: state.directionRevision, savedAt: new Date().toISOString(), ...(meta?.generation === undefined ? {} : { generation: meta.generation }), ...(meta?.provider === undefined ? {} : { provider: meta.provider }), ...(meta?.model === undefined ? {} : { model: meta.model }), ...(meta?.routedFrom === undefined ? {} : { routedFrom: meta.routedFrom }) }))
1276
+ .catch(async (error) => {
1277
+ checkpointFailed = true;
1278
+ await noteCheckpointWriteFailure(directory, runId, error instanceof Error ? error.message : String(error));
1279
+ process.stderr.write(`Could not write the run checkpoint: ${error instanceof Error ? error.message : String(error)}\n`);
1280
+ });
1281
+ // The write is handed back so the runtime can await it: the checkpoint is the conversation a
1282
+ // resume re-enters the node with, and a run that advanced past a mutating tool call while its
1283
+ // checkpoint was still queued could be killed with that conversation unwritten.
1284
+ return checkpointWrites;
1285
+ };
1286
+ // Interactive runs stream the model's reasoning into the terminal's live preview
1287
+ // line. The wrap sits outside the trajectory so reasoning deltas never reach run
1288
+ // records. Subagent calls are excluded, and so are calls that arrive while another
1289
+ // previewing call is in flight: concurrent graph branches and parallel modifier
1290
+ // copies carry no subagentId, and several streams sharing one preview line would
1291
+ // interleave and flicker. The flag is claimed synchronously before the first await,
1292
+ // so exactly one concurrent call ever owns the preview.
1293
+ let previewInFlight = false;
1294
+ const tracedAdapter = (provider) => {
1295
+ if (provider.apiKey)
1296
+ trajectory.addSecrets([provider.apiKey]);
1297
+ if (provider.apiKeyEnv && process.env[provider.apiKeyEnv])
1298
+ trajectory.addSecrets([process.env[provider.apiKeyEnv]]);
1299
+ const traced = trajectory.wrap(createAdapter(provider), () => ({ runId, providerId: provider.id }));
1300
+ if (!terminal)
1301
+ return traced;
1302
+ return {
1303
+ ...(traced.listModels ? { listModels: (signal) => traced.listModels(signal) } : {}),
1304
+ async generate(request) {
1305
+ // Every runtime call, previewing or not, feeds the footer's speed readout as it
1306
+ // streams, so a long thinking stream moves the number instead of holding it until
1307
+ // usage arrives. A new attempt or a failure drops the estimate; a success leaves it
1308
+ // for the usage delta to replace, so the reading does not flick back to the old
1309
+ // average in between. Calls without an invocation id (health probes) are not metered.
1310
+ const invocationId = request.context?.invocationId;
1311
+ const metered = meterStreamedRequest(request, terminal);
1312
+ const generate = async (call) => {
1313
+ try {
1314
+ return await traced.generate(call);
1315
+ }
1316
+ catch (error) {
1317
+ if (invocationId !== undefined)
1318
+ terminal.noteStreamEnded(invocationId);
1319
+ throw error;
1320
+ }
1321
+ };
1322
+ if (request.context?.subagentId || previewInFlight)
1323
+ return generate(metered);
1324
+ previewInFlight = true;
1325
+ terminal.clearThinking();
1326
+ // Each HTTP attempt retraces the preview, so a retried stream replaces the
1327
+ // failed attempt's text instead of concatenating with it.
1328
+ try {
1329
+ return await generate({
1330
+ ...metered,
1331
+ onRequest: () => { terminal.clearThinking(); metered.onRequest?.(); },
1332
+ onReasoning: delta => { terminal.appendThinking(delta); metered.onReasoning?.(delta); },
1333
+ });
1334
+ }
1335
+ finally {
1336
+ previewInFlight = false;
1337
+ terminal.clearThinking();
1338
+ }
1339
+ },
1340
+ };
1341
+ };
1342
+ await writeActivity(directory, 'running', { detail: task, runId });
1343
+ // Back to running after a prompt, unless the user paused the run while it waited; paused
1344
+ // runs are themselves waiting on the user's next message.
1345
+ const runResumed = () => runControl?.isPaused
1346
+ ? writeActivity(directory, 'awaiting-input', { kind: 'steering', detail: 'Paused - send a message in the terminal to steer the run', runId })
1347
+ : writeActivity(directory, 'running', { runId });
1348
+ runControl = terminal ? new RunControl() : undefined;
1349
+ // A fresh control cannot hold a timer resume, so a latch left set by a run that ended
1350
+ // between the resume and its next poll must not hold this run's first due batch.
1351
+ timerResumePending = false;
1352
+ if (runControl) {
1353
+ runControl.yolo = state.yolo;
1354
+ runControl.permissions = state.permissions;
1355
+ }
1356
+ const removeControlListener = runControl?.onChange(paused => {
1357
+ updateTitle();
1358
+ terminal?.setStatus({ activity: paused ? 'Paused' : 'Thinking' });
1359
+ print(paused ? 'Paused. Send a message to resume with new direction; /yolo on|off changes permissions, Ctrl+C again exits.' : 'Resuming with your direction.');
1360
+ if (paused)
1361
+ void writeActivity(directory, 'awaiting-input', { kind: 'steering', detail: 'Paused - send a message in the terminal to steer the run', runId });
1362
+ else
1363
+ void writeActivity(directory, 'running', { runId });
1364
+ });
1365
+ let liveCommands = Promise.resolve();
1366
+ terminal?.setRunInputHandler(text => {
1367
+ // Composer input during a run bypasses the question loop, so it gets no outer
1368
+ // command pair: steering text gets a single marker (delivery is traced by
1369
+ // agent.messages.injected), while the live commands below keep full timing records.
1370
+ if (!text.startsWith('/')) {
1371
+ void debugRecord('command.steer', { input: text });
1372
+ return runControl?.isPaused ? runControl.resume(text) : false;
1373
+ }
1374
+ const command = text.split(/\s/, 1)[0];
1375
+ if (command === '/exit' || command === '/quit') {
1376
+ void debugRecord('command.steer', { input: text });
1377
+ exiting = true;
1378
+ active?.abort();
1379
+ terminal?.close();
1380
+ return true;
1381
+ }
1382
+ if (command === '/attach') {
1383
+ // Mid-run, an attachment rides the next steer rather than a new task.
1384
+ void debugRecord('command.steer', { input: text });
1385
+ const argument = text.slice('/attach'.length).trim().replace(/^"(.*)"$/, '$1');
1386
+ const target = argument ? resolve(workspace, argument) : '';
1387
+ if (!target || !existsSync(target))
1388
+ print('Usage: /attach <existing path> — attaches to your next steer.');
1389
+ else if (terminal.addAttachment({ kind: 'file', path: target }))
1390
+ print(`Attached ${target}. It rides your next steer.`);
1391
+ return true;
1392
+ }
1393
+ if (!['/browser', '/yolo', '/permissions', '/jev', '/help', '/status', '/usage', '/tools'].includes(command)) {
1394
+ void debugRecord('command.steer', { input: text });
1395
+ print(`${command} is unavailable during a run. Use /permissions <mode>, /yolo on|off, /jev on|off, /status, /usage, /help, or /exit.`);
1396
+ return true;
1397
+ }
1398
+ const commandStartedAt = Date.now();
1399
+ void debugRecord('command.started', { input: text, mode: 'in-run' });
1400
+ // Create each command's draft only after prior saves and live updates finish.
1401
+ // Even status commands must queue: executeCommand commits their draft too.
1402
+ liveCommands = liveCommands.then(async () => {
1403
+ if (command === '/browser') {
1404
+ browserApp ??= await startBrowserServer();
1405
+ // Teardown can pass the cleanup loop while this startup is pending;
1406
+ // a server that finishes after exiting must neither open nor linger.
1407
+ if (exiting)
1408
+ await browserApp.close().catch(() => { });
1409
+ else {
1410
+ print(`Andorra Browser: ${browserApp.url}`);
1411
+ openBrowserUrl(browserApp.url);
1412
+ }
1413
+ }
1414
+ else {
1415
+ // `/jev` saves at once but the run keeps the decision policy it started with; the reply says so.
1416
+ // The spread shares `state.config`, so the saved value lands on the session's configuration.
1417
+ const commandState = command === '/usage' ? { ...state, usage: sessionUsage() } : command === '/jev' ? { ...state, running: true } : state;
1418
+ const result = await executeCommand(text, commandState, persistConfig);
1419
+ afterJevCommand(text, result);
1420
+ if (runControl) {
1421
+ runControl.yolo = state.yolo;
1422
+ runControl.permissions = state.permissions;
1423
+ }
1424
+ if (state.yolo)
1425
+ approvePending?.();
1426
+ print(result.text);
1427
+ if (command === '/status')
1428
+ print(sessionDescription());
1429
+ refreshStatus();
1430
+ }
1431
+ void debugRecord('command.completed', { input: text, mode: 'in-run', durationMs: Date.now() - commandStartedAt });
1432
+ }).catch(error => {
1433
+ const message = error instanceof Error ? error.message : String(error);
1434
+ print(message);
1435
+ void debugRecord('command.error', { input: text, mode: 'in-run', message });
1436
+ void debugRecord('command.completed', { input: text, mode: 'in-run', durationMs: Date.now() - commandStartedAt });
1437
+ });
1438
+ return true;
1439
+ });
1440
+ terminal?.startTask();
1441
+ // A run's own preflight and teardown both change what the working tree holds.
1442
+ refreshPanelStatus(true);
1443
+ const retainedTodos = continuedTodos(task, state.lastRun);
1444
+ const todoStore = new TodoStore();
1445
+ if (retainedTodos.length)
1446
+ todoStore.update(retainedTodos);
1447
+ toolActivity.clear();
1448
+ // A short "Continue"/"Resume" after an unfinished run is the same work. Keep the
1449
+ // previous plan visible and seed it into the new graph run until the agent updates it.
1450
+ if (retainedTodos.length)
1451
+ terminal?.setTodos(retainedTodos);
1452
+ else
1453
+ terminal?.setTodos([]);
1454
+ terminal?.setStatus({ activity: 'Thinking' });
1455
+ // Interactive runs keep the composer live so the user can steer the run in place;
1456
+ // approved/clarification questions still take precedence over steering.
1457
+ terminal?.setSteering(true);
1458
+ const selected = config.providers.find(p => p.id === config.provider);
1459
+ const preflight = async (operation) => {
1460
+ while (true) {
1461
+ if (active.signal.aborted)
1462
+ return operation(active.signal);
1463
+ await runControl?.wait(active.signal);
1464
+ const interruption = runControl?.signal;
1465
+ const signal = interruption ? AbortSignal.any([active.signal, interruption]) : active.signal;
1466
+ try {
1467
+ return await operation(signal);
1468
+ }
1469
+ catch (error) {
1470
+ if (!interruption?.aborted || active.signal.aborted)
1471
+ throw error;
1472
+ }
1473
+ }
1474
+ };
1475
+ let mcp;
1476
+ try {
1477
+ // The startup preflight already loaded this selection through the membership gate, so the
1478
+ // initial run reuses it rather than spending a second account-service round trip whose
1479
+ // transient failure could still deny the run. Later runs load again so on-disk graph
1480
+ // edits stay observable mid-session; a graph refresh arms one more reuse.
1481
+ const loadedGraph = startupGraph && !startupGraphReused && startupGraphSelection === (state.graph ?? 'default')
1482
+ ? (startupGraphReused = true, startupGraph)
1483
+ : await preflight(signal => loadGraph(state.graph ?? 'default', signal));
1484
+ terminal?.setStatus({ activity: 'Checking graph models' });
1485
+ graphModelsHealthy = false;
1486
+ const health = await preflight(signal => checkGraphHealth(loadedGraph, config, signal, {
1487
+ onUsage: (delta, reference) => {
1488
+ const key = `${reference.provider}\0${reference.model}`;
1489
+ const entry = probeModels.get(key) ?? { provider: reference.provider, model: reference.model, usage: {} };
1490
+ // Only the measurements the provider actually reported are carried, so the tuple keeps
1491
+ // its coverage instead of claiming a measured zero.
1492
+ for (const field of ['requests', 'inputTokens', 'outputTokens', 'cacheRead', 'cacheWrite']) {
1493
+ const value = delta[field];
1494
+ if (typeof value === 'number')
1495
+ entry.usage[field] = (entry.usage[field] ?? 0) + value;
1496
+ }
1497
+ probeModels.set(key, entry);
1498
+ },
1499
+ // The probes are model calls this attempt pays for, so they belong in the trajectory
1500
+ // beside the run's own calls.
1501
+ createAdapter: provider => tracedAdapter(provider),
1502
+ }));
1503
+ graphModelsHealthy = health.healthy;
1504
+ if (!health.healthy) {
1505
+ healthProviderFailed = health.failures.some(failure => failure.providerError === true);
1506
+ throw new Error(formatGraphHealthFailure(health));
1507
+ }
1508
+ const graph = validateGraph(loadedGraph, { providers: config.providers, defaultProvider: config.provider, spawnAvailable: true });
1509
+ // The pinned graph is known now, so the start carries its real size and delegation shape.
1510
+ Object.assign(telemetryHandle.dimensions, { graphId: runGraphSelection, ...graphShape(graph) });
1511
+ const startQueued = startTelemetry();
1512
+ if (!openRecordWritten)
1513
+ void startQueued;
1514
+ // Stamp the same shape into the open record, because a crash before finalization is
1515
+ // recovered from that file: zeros there would produce a finish that disagrees with its start.
1516
+ // `startSent` is stamped only once the start is actually queued, so a crash in between is
1517
+ // recovered as a pair rather than as a finish with no start.
1518
+ if (openRecordWritten) {
1519
+ await startQueued.catch(() => { });
1520
+ openRecord.telemetry = { ...openRecord.telemetry, ...graphShape(graph), startSent: telemetryHandle.started !== false };
1521
+ await writeOpenRunRecord(directory, openRecord).catch(() => { });
1522
+ }
1523
+ // The in-flight record is created before graph preflight. Once the pinned
1524
+ // revision is known, stamp its small sidecar so live runs can safely show
1525
+ // revision-matched node and edge overlays before finalization.
1526
+ await writeStudioRunSummary(directory, {
1527
+ id: runId, status: 'running', startedAt, graphSelection: runGraphSelection,
1528
+ ...(accountSubject ? { accountSubject } : {}),
1529
+ graph: { id: graph.id, revision: graph.revision }
1530
+ }).catch(() => { });
1531
+ terminal?.setStatus({ activity: 'Thinking' });
1532
+ const workspaceGuidance = await preflight(signal => loadWorkspaceInstructions(workspace, signal, config.systemPromptOverride));
1533
+ // QA workflow guidance rides the same channel as the workspace guide; it is
1534
+ // guidance only — permission gates and the command policy still enforce.
1535
+ const invocation = isBuiltinSlashCommand(task) ? undefined : await preflight(signal => resolveSkillInvocation(task, config, signal, directory));
1536
+ const snapshot = await preflight(signal => extensionSnapshot(config, signal, directory, invocation?.id));
1537
+ for (const notice of snapshot.notices)
1538
+ terminal ? terminal.print(notice) : process.stderr.write(safeTerminal(notice) + '\n');
1539
+ const instructions = `${workspaceGuidance}\n${QA_SYSTEM_GUIDANCE}${snapshot.instructions}`;
1540
+ const resolvedModels = new Map();
1541
+ const onRunEvent = async (event) => {
1542
+ if (!/reasoning|thinking\.delta/.test(event.type))
1543
+ browserBridge?.event(trajectory.sanitize(event));
1544
+ event = { ...event, data: { ...event.data, conversationId: savedSession?.id ?? trajectory.sessionId } };
1545
+ if (event.data.provider === 'andorra' && ['decision.completed', 'decision.fallback', 'decision.provider_error'].includes(event.type))
1546
+ scheduleAccountRefresh();
1547
+ if (event.type === 'codeintel.state')
1548
+ codeIntelNotice(event);
1549
+ await appendRunEvent(directory, event);
1550
+ await trajectory.recordEvent(event);
1551
+ terminal?.setStatus({ session: savedSession?.name ?? trajectory.sessionId });
1552
+ // The executor's own resolution of this node's model is memoized here, so the footer can
1553
+ // follow the node instead of the session's selection.
1554
+ terminal?.handleRuntimeEvent(await withNodeModelResolution(event, (provider, model) => resolvedModels.get(JSON.stringify([provider, model]))));
1555
+ // Tool boundaries are when the panel's live sections can have moved: a completion may
1556
+ // have written files or ended a background terminal, a start may have opened one. These
1557
+ // stay on the summary's own throttle - a tool-heavy run would otherwise spawn a git
1558
+ // process per tool - while the run boundaries above force the read.
1559
+ if (event.type === 'node.tool.started' || event.type === 'node.tool.completed' || event.type === 'node.tool.failed')
1560
+ refreshPanelStatus();
1561
+ if (terminal && event.type === 'graph.todos.updated') {
1562
+ terminal.setTodos(event.data.todos);
1563
+ return;
1564
+ }
1565
+ const activity = activityForRuntimeEvent(event, toolActivity);
1566
+ if (activity !== undefined)
1567
+ terminal?.setStatus({ activity: runControl?.isPaused ? 'Paused' : activity });
1568
+ if (terminal && event.type === 'agent.model.completed') {
1569
+ terminal.setStatus(sessionUsage());
1570
+ }
1571
+ if (!values.json) {
1572
+ const entry = formatEvent(event);
1573
+ if (entry) {
1574
+ if (terminal)
1575
+ terminal.print(entry.text, entry.detail, entry.toolCall, false, /failed|error|stopped/.test(event.type));
1576
+ // The plain path has no Ctrl+O, so an agent message whose code block collapsed into
1577
+ // `detail` must print the full rendering, not the truncated summary.
1578
+ else if (event.type === 'agent.message' && entry.detail)
1579
+ print(staticToolTimestamp(entry.detail, entry.toolCall));
1580
+ else
1581
+ print(staticToolTimestamp(entry.text, entry.toolCall));
1582
+ }
1583
+ }
1584
+ };
1585
+ runEventSink = onRunEvent;
1586
+ mcp = Object.keys(snapshot.servers).length ? await preflight(async (signal) => {
1587
+ const extensionContext = { workspace, signal, runControl, get yolo() { return state.yolo; }, get permissions() { return state.permissions; },
1588
+ onApprovalEvent: (type, data) => onRunEvent({ type, time: new Date().toISOString(), data: { ...data, runId } }),
1589
+ approvalMode: terminal ? 'interactive' : 'headless', approve: async (name, args, signal) => {
1590
+ if (!terminal || exiting)
1591
+ return false;
1592
+ awaitingInput++;
1593
+ updateTitle();
1594
+ terminal.setStatus({ activity: `Approval needed: ${name}` });
1595
+ await writeActivity(directory, 'awaiting-input', { kind: 'approval', detail: `Approval needed: ${name}`, runId });
1596
+ terminal.print(`Approval details for ${describeTool(name, args)}`, JSON.stringify(args, null, 2));
1597
+ const answerPromise = terminal.chooseQuestion(safeTerminal(`Approve ${describeTool(name, args)}?`), [{ id: 'deny', label: 'Deny' }, { id: 'approve', label: 'Approve' }], { signal, kind: 'approval', approvalDetails: { name, arguments: args } });
1598
+ const grant = () => terminal.resolveQuestion('policy-changed');
1599
+ approvePending = grant;
1600
+ try {
1601
+ const answer = await answerPromise;
1602
+ return answer === 'policy-changed' ? answer : answer === 'approve';
1603
+ }
1604
+ finally {
1605
+ awaitingInput--;
1606
+ updateTitle();
1607
+ if (approvePending === grant)
1608
+ approvePending = undefined;
1609
+ terminal.setStatus({ activity: runControl?.isPaused ? 'Paused' : 'Thinking' });
1610
+ await runResumed();
1611
+ }
1612
+ } };
1613
+ return (await import('./mcp.js')).connectMcpServers(snapshot.servers, extensionContext, message => terminal ? terminal.print(message) : process.stderr.write(safeTerminal(message) + '\n'), active.signal);
1614
+ }) : { tools: [], close: async () => { } };
1615
+ if (terminal) {
1616
+ try {
1617
+ const refreshed = await preflight(signal => refreshModelContext(selected, signal));
1618
+ resolvedModels.set(JSON.stringify([selected.id, selected.model]), Promise.resolve({ model: refreshed.model, adapter: tracedAdapter(refreshed), contextWindow: refreshed.contextWindow, reasoningEffort: refreshed.reasoningEffort, providerType: selected.type, baseUrl: selected.baseUrl }));
1619
+ if (refreshed.contextWindow !== undefined)
1620
+ sessionContexts.set(contextKey(selected), refreshed.contextWindow);
1621
+ else
1622
+ sessionContexts.delete(contextKey(selected));
1623
+ }
1624
+ catch (error) {
1625
+ if (!active.signal.aborted)
1626
+ throw error;
1627
+ }
1628
+ refreshStatus();
1629
+ }
1630
+ // A cancelled metadata lookup must not create a graph run after preflight.
1631
+ active.signal.throwIfAborted();
1632
+ let membership = !jevOn() ? { paid: false } : await preflight(signal => getMembership(signal));
1633
+ if (jevOn() && !membership.subject && membership.unavailable) {
1634
+ // The lookup has a five-second budget and the account service cold-starts past it after a
1635
+ // quiet spell; the second lookup then answers in well under a second. Without the retry
1636
+ // Jev is off for the whole run and nothing says so (7 of 12 Jev runs in the 2026-11-01
1637
+ // A/B ran without a single decision round).
1638
+ membership = await preflight(signal => getMembership(signal));
1639
+ }
1640
+ if (jevOn() && !membership.subject) {
1641
+ const reason = membership.unavailable ? membership.failureReason ?? 'membership_unavailable' : 'not_signed_in';
1642
+ await onRunEvent({ type: 'decision.unavailable', time: new Date().toISOString(), data: { runId, provider: 'andorra', reason } });
1643
+ const notice = `Jev is off for this run: ${reason === 'not_signed_in' ? 'no signed-in account' : `the account lookup was unavailable (${reason})`}.`;
1644
+ if (terminal)
1645
+ terminal.print(notice);
1646
+ else
1647
+ process.stderr.write(safeTerminal(notice) + '\n');
1648
+ }
1649
+ const decisionPolicy = hostedDecisionPolicy(membership, jevOn(), config.decisions);
1650
+ jevEnabled = jevOn();
1651
+ terminal?.setStatus({ graph, jevEnabled });
1652
+ const commandMemory = config.commandMemory === false ? undefined : await LocalToolMemory.open({ workspace, directory });
1653
+ const execute = (options) => runGraph(graph, { ...options, runInput, runState, commandMemory, todoStore,
1654
+ ...(invocation ? { inheritedSkills: [invocation.id], skillInvocationInstruction: invocation.task } : {}),
1655
+ resolveModel: (id, model) => {
1656
+ const provider = config.providers.find(item => item.id === id);
1657
+ if (!provider)
1658
+ throw new Error(`Unknown provider: ${id}. Use /providers to add or edit providers.`);
1659
+ const key = JSON.stringify([id, model || provider.model]);
1660
+ let pending = resolvedModels.get(key);
1661
+ if (!pending) {
1662
+ pending = preflight(signal => resolveModelContext(provider, model || provider.model, signal))
1663
+ .then(snapshot => withEvaluationReasoningEffort(snapshot, process.env.ANDORRA_EVAL_REASONING_EFFORT))
1664
+ .then(snapshot => ({ model: snapshot.model, adapter: tracedAdapter(snapshot), contextWindow: snapshot.contextWindow, reasoningEffort: snapshot.reasoningEffort, providerType: provider.type, baseUrl: provider.baseUrl }));
1665
+ resolvedModels.set(key, pending);
1666
+ void pending.catch(() => { if (resolvedModels.get(key) === pending)
1667
+ resolvedModels.delete(key); });
1668
+ }
1669
+ return pending;
1670
+ },
1671
+ resolveProvider: id => {
1672
+ const provider = config.providers.find(item => item.id === id);
1673
+ if (!provider)
1674
+ throw new Error(`Unknown provider: ${id}. Use /providers to add or edit providers.`);
1675
+ const snapshot = withEvaluationReasoningEffort(runtimeProvider(provider), process.env.ANDORRA_EVAL_REASONING_EFFORT);
1676
+ return { model: snapshot.model, adapter: tracedAdapter(snapshot), contextWindow: snapshot.contextWindow, providerType: snapshot.type, baseUrl: snapshot.baseUrl };
1677
+ },
1678
+ });
1679
+ const result = await execute({ task, runId, provider: selected.id, model: selected.model, ...(attachments ? { attachments } : {}),
1680
+ ...(config.efficiency ? { efficiency: config.efficiency } : {}),
1681
+ // A `--model`/`--provider` flag is the user's choice; adaptive routing leaves it alone.
1682
+ modelPinned: Boolean(values.model || values.provider),
1683
+ configuredModels: config.providers.map(item => ({ id: item.id, model: item.model, ...(item.models ? { models: [...item.models] } : {}) })),
1684
+ onNodeCheckpoint: persistCheckpoint,
1685
+ onUsage: (usage, origin) => {
1686
+ activeUsage.requests += usage.requests;
1687
+ activeUsage.inputTokens += usage.inputTokens;
1688
+ activeUsage.outputTokens += usage.outputTokens;
1689
+ activeUsage.cacheRead += usage.cacheRead ?? 0;
1690
+ activeUsage.cacheWrite += usage.cacheWrite ?? 0;
1691
+ // The delta's input size is the live conversation: every request resends the
1692
+ // whole context, so the latest measured one shows how full the window currently
1693
+ // is. Deltas that carry no measurement - transport attempts, a completion whose
1694
+ // provider omitted usage, a failed request's close signal - report zeros by
1695
+ // design, and treating them as a context size would wipe the last real estimate
1696
+ // (model-backed distillation runs last, so its no-usage close would otherwise
1697
+ // leave the idle footer at `context: 0%`).
1698
+ if (usage.inputTokens > 0) {
1699
+ contextUsedTokens = usage.inputTokens;
1700
+ runContext = { usedTokens: usage.inputTokens, ...(usage.cacheRead === undefined ? {} : { cacheRead: usage.cacheRead }) };
1701
+ }
1702
+ // The same per-request delta feeds the footer speed readout. Providers report a
1703
+ // request's tokens only as it completes, so this is the number credited to the
1704
+ // window that produced it - the streamed decode window when the adapter measured
1705
+ // one, so prompt processing does not count as generating time; the origin's
1706
+ // invocation id names that request, so a completion pairs with its own window even
1707
+ // when concurrent requests finish out of order. Diffing the cumulative totals
1708
+ // instead would smear or drop it in a graph whose nodes each report their own totals.
1709
+ terminal?.noteGeneratedTokens(usage.outputTokens, origin?.invocationId, origin?.final === true, usage.decodeMs);
1710
+ terminal?.setStatus(sessionUsage());
1711
+ },
1712
+ adapter: tracedAdapter(runtimeProvider(selected)), tools: [...createTools(), ...snapshot.tools, ...mcp.tools], history: state.history, instructions, codeIntel, ...decisionPolicy,
1713
+ // Installation-wide bounds. Nothing is set by default, which leaves the run with no
1714
+ // wall clock and no iteration ceiling; a graph or node bound still narrows these.
1715
+ limits: resolveConfiguredLimits(config),
1716
+ // Polled at turn boundaries: each queued steer becomes a user message in the live
1717
+ // conversation, so the run redirects without restarting or losing its context.
1718
+ getSteeringMessages: terminal ? async () => {
1719
+ if (exiting)
1720
+ return [];
1721
+ deliverTimerPrompts();
1722
+ // Release held timer prompts only after the poll that carried a timer's resume
1723
+ // direction: this poll runs immediately before prepareTurn injects those directions,
1724
+ // so prompts released from the next poll onward reach the model strictly later.
1725
+ timerResumePending = false;
1726
+ // A steered turn carries its own attachments: each queued steer is one user message,
1727
+ // so its files and images are resolved against that steer alone, never pooled.
1728
+ const steered = terminal.takeSteeringTurns();
1729
+ const messages = [];
1730
+ for (const turn of steered) {
1731
+ if (!turn.attachments.length) {
1732
+ messages.push({ role: 'user', content: turn.text });
1733
+ continue;
1734
+ }
1735
+ try {
1736
+ const resolved = await resolveAttachments(directory, workspace, turn.attachments);
1737
+ for (const root of await attachmentReadRoots(directory, resolved.refs)) {
1738
+ attachmentSpools.add(root);
1739
+ steeredSpools.add(root);
1740
+ }
1741
+ // An attachment-only steer arrives with empty text; the stand-in names what the
1742
+ // chips carry, exactly as an attachment-only task does (ATTACHMENT_ONLY_TASK).
1743
+ messages.push({ role: 'user', content: `${turn.text || ATTACHMENT_ONLY_TASK}\n\n${attachmentReferenceBlock(resolved.refs)}`, ...(resolved.images.length ? { images: resolved.images } : {}) });
1744
+ }
1745
+ catch (error) {
1746
+ messages.push({ role: 'user', content: `${turn.text}\n\n[Attachment failed: ${error instanceof Error ? error.message : String(error)}]` });
1747
+ }
1748
+ }
1749
+ messages.push(...browserSteering.splice(0).map(text => ({ role: 'user', content: text })), ...timerSteering.splice(0).map(text => ({ role: 'user', content: text })));
1750
+ return messages;
1751
+ } : undefined,
1752
+ context: { workspace, signal: active.signal, runControl, timers: terminal ? sessionTimers : undefined,
1753
+ // Both terminal surfaces create future work through this context. Carry the run's
1754
+ // selections, including CLI overrides; the graph selector must retain 'default'
1755
+ // rather than the resolved harness id so replay follows the same access rules.
1756
+ automationDirectory: directory,
1757
+ wakeCarry: { provider: selected.id, model: selected.model, graph: runGraphSelection,
1758
+ ...(selected.reasoningEffort === undefined ? {} : { reasoningEffort: selected.reasoningEffort }) },
1759
+ get yolo() { return state.yolo; }, get permissions() { return state.permissions; }, get attachmentRoots() { return [...attachmentSpools]; }, approvalMode: terminal ? 'interactive' : 'headless',
1760
+ askUser: terminal ? async (question, signal, choices) => {
1761
+ if (exiting)
1762
+ return undefined;
1763
+ awaitingInput++;
1764
+ updateTitle();
1765
+ terminal.setStatus({ activity: 'Clarifying requirements' });
1766
+ await writeActivity(directory, 'awaiting-input', { kind: 'clarification', detail: safeTerminal(question), runId });
1767
+ try {
1768
+ return await askClarification(terminal, safeTerminal(question), signal, choices);
1769
+ }
1770
+ finally {
1771
+ awaitingInput--;
1772
+ updateTitle();
1773
+ terminal.setStatus({ activity: runControl?.isPaused ? 'Paused' : 'Planning' });
1774
+ await runResumed();
1775
+ }
1776
+ } : undefined,
1777
+ approve: async (name, args, signal) => {
1778
+ if (!terminal || exiting)
1779
+ return false;
1780
+ awaitingInput++;
1781
+ updateTitle();
1782
+ terminal.setStatus({ activity: `Approval needed: ${name}` });
1783
+ terminal.print(`Approval details for ${describeTool(name, args)}`, JSON.stringify(args, null, 2));
1784
+ await writeActivity(directory, 'awaiting-input', { kind: 'approval', detail: `Approval needed: ${name}`, runId });
1785
+ const answerPromise = terminal.chooseQuestion(safeTerminal(`Approve ${describeTool(name, args)}? (Ctrl+O: details)`), [
1786
+ { id: 'deny', label: 'Deny' }, { id: 'approve', label: 'Approve' },
1787
+ ], { signal, kind: 'approval', approvalDetails: { name, arguments: args } });
1788
+ const grant = () => terminal.resolveQuestion('policy-changed');
1789
+ approvePending = grant;
1790
+ try {
1791
+ const answer = await answerPromise;
1792
+ return answer === 'policy-changed' ? answer : answer === 'approve';
1793
+ }
1794
+ finally {
1795
+ awaitingInput--;
1796
+ updateTitle();
1797
+ if (approvePending === grant)
1798
+ approvePending = undefined;
1799
+ terminal.setStatus({ activity: runControl?.isPaused ? 'Paused' : `Running ${name}` });
1800
+ await runResumed();
1801
+ }
1802
+ },
1803
+ },
1804
+ onEvent: onRunEvent, });
1805
+ state.lastRun = result;
1806
+ state.usage.requests += result.usage.requests;
1807
+ state.usage.inputTokens += result.usage.inputTokens;
1808
+ state.usage.outputTokens += result.usage.outputTokens;
1809
+ foldCache(state.usage, result.usage.cacheRead, result.usage.cacheWrite);
1810
+ activeUsage = { inputTokens: 0, outputTokens: 0, requests: 0, cacheRead: 0, cacheWrite: 0 };
1811
+ // Let the last checkpoint land before the record and the cleanup below decide whether one
1812
+ // survives: deleting while a write was in flight would recreate the file a succeeded run is
1813
+ // meant to leave behind nothing to resume.
1814
+ await checkpointWrites;
1815
+ // The final record keeps the open record's identity fields: recovery and the Runs view key a
1816
+ // run by its session and start time, and the finalizer replaces the open record in place.
1817
+ const finishedRecord = { ...result, graphSelection: runGraphSelection,
1818
+ ...(accountSubject ? { accountSubject } : {}),
1819
+ ...(savedSession ? { sessionId: savedSession.id } : {}), startedAt,
1820
+ // The stamp the mutation guard needs to tell a closed attempt from a live claim of the same run id.
1821
+ endedAt: new Date().toISOString(),
1822
+ // The flag a resume consults before it trusts this attempt's conversation: a checkpoint
1823
+ // that could not be written leaves the node to be re-entered from its opening task.
1824
+ ...(checkpointFailed ? { checkpointIntegrity: 'failed' } : {}),
1825
+ ...(runInput === undefined ? {} : { runInput }), ...(runState === undefined ? {} : { runState }) };
1826
+ await writeFile(runRecordPath(directory, result.id, 'json'), JSON.stringify(finishedRecord, null, 2) + '\n', { mode: 0o600 });
1827
+ finishTelemetry(result.status, result.reason, result);
1828
+ await writeStudioRunSummary(directory, {
1829
+ id: result.id, status: result.status, startedAt, graphSelection: runGraphSelection,
1830
+ ...(accountSubject ? { accountSubject } : {}),
1831
+ graph: { id: result.graph.id, revision: typeof result.graph.revision === 'number' ? result.graph.revision : undefined },
1832
+ toolCalls: result.toolCalls
1833
+ }).catch(() => { });
1834
+ // A multi-node graph can finish an early node and stop in a later one, keeping that node's
1835
+ // completion on a non-success result; the status is the attempt's last word, so stamp it.
1836
+ rememberTurn(task, { ...(result.completion ?? outcomeCompletion(result.status, result.reason, result.limits)), ...(result.status === 'succeeded' ? {} : { status: result.status }) }, runId, attachments?.refs);
1837
+ // The run's final widget values are the session's newest; a result without widgets clears
1838
+ // older ones so a persisted record never shows values its graph no longer defines.
1839
+ // The context reading is the run's too: what it last measured, or nothing.
1840
+ if (savedSession)
1841
+ savedSession = { ...savedSession, widgets: result.widgets, context: runContext };
1842
+ // A finished run has nothing to resume: only stopped attempts keep a durable checkpoint.
1843
+ if (result.status === 'succeeded') {
1844
+ await removeRunCheckpoint(directory, result.id);
1845
+ // Nothing resumes a finished run, and only the opening turn's refs are persisted — a
1846
+ // steer's spools have no reader left once its checkpoint is gone. Until then (stopped,
1847
+ // failed) they stay: the checkpoint's conversation still names those files.
1848
+ await Promise.all([...steeredSpools].map(root => rm(root, { recursive: true, force: true }).catch(() => { })));
1849
+ }
1850
+ if (values.json)
1851
+ process.stdout.write(JSON.stringify(result) + '\n');
1852
+ else {
1853
+ const summary = result.completion?.summary ?? (result.status === 'cancelled' ? 'Cancelled.' : `The run did not finish: ${stopReasonPhrase(result.reason, result.limits)}.`);
1854
+ if (terminal) {
1855
+ // The summary is markdown like every agent message: render it, and keep a collapsed
1856
+ // code block's full text behind Ctrl+O instead of printing fences verbatim.
1857
+ const entry = formatRunResult({ id: result.id, status: result.status, summary, tests: result.completion?.tests });
1858
+ terminal.print(entry.text, entry.detail, undefined, true);
1859
+ }
1860
+ else
1861
+ print(summary);
1862
+ if (!terminal)
1863
+ for (const check of result.completion?.tests ?? [])
1864
+ print(` ${check}`);
1865
+ if (!terminal)
1866
+ print(`Run ${result.id} · ${result.status}`);
1867
+ }
1868
+ return terminated ? 143 : result.status === 'succeeded' ? 0 : result.status === 'cancelled' ? 130 : 1;
1869
+ }
1870
+ catch (error) {
1871
+ // An attempt that never reached `runGraph` still owns its open record: leaving it `running`
1872
+ // tells the Runs view a task is working until the process dies, and recovery then calls a
1873
+ // deliberate stop a crash. Replace it with the outcome this path actually knows — the shared
1874
+ // finalizer carries the identity fields and whatever usage the run had already spent.
1875
+ if (active?.signal.aborted) {
1876
+ await finalizeRunRecord('cancelled', 'the user stopped this run');
1877
+ rememberTurn(task, outcomeCompletion('cancelled', undefined, undefined), runId, attachments?.refs);
1878
+ return terminated ? 143 : 130;
1879
+ }
1880
+ // A crash is an attempt too. Record it before rethrowing so the caller's error report
1881
+ // does not also cost the user the context of what they asked for.
1882
+ await finalizeRunRecord('infrastructure_error', error instanceof Error ? error.message : 'the run failed unexpectedly');
1883
+ rememberTurn(task, outcomeCompletion('infrastructure_error', error instanceof Error ? error.message : 'the run failed unexpectedly', undefined), runId, attachments?.refs);
1884
+ throw error;
1885
+ }
1886
+ finally {
1887
+ browserDraining = true;
1888
+ // Stop accepting live commands before draining; idle commands must not race
1889
+ // a permission save accepted just before the run completed.
1890
+ terminal?.setRunInputHandler(undefined);
1891
+ // A cancelled or crashed attempt leaves its checkpoint in place for `run.resume`, but the
1892
+ // pending write itself has to finish before the process moves on; the chain never rejects.
1893
+ await checkpointWrites;
1894
+ await liveCommands;
1895
+ // A crashed run's partial provider spend still happened: fold it into the session
1896
+ await mcp?.close();
1897
+ // totals before the live counter resets, or a crashed command's usage vanishes from
1898
+ // /usage and the --debug summary even though the journal recorded the model calls.
1899
+ state.usage.requests += activeUsage.requests;
1900
+ state.usage.inputTokens += activeUsage.inputTokens;
1901
+ state.usage.outputTokens += activeUsage.outputTokens;
1902
+ foldCache(state.usage, activeUsage.cacheRead, activeUsage.cacheWrite);
1903
+ activeUsage = { inputTokens: 0, outputTokens: 0, requests: 0, cacheRead: 0, cacheWrite: 0 };
1904
+ terminal?.finishTask();
1905
+ runEventSink = undefined;
1906
+ // The run is over: detach its live state before the awaited cleanup below, so a
1907
+ // Ctrl+C landing during slow cleanup I/O reads as idle and exits instead of pausing
1908
+ // a run that no longer exists (and the pause listener cannot re-attach to claim
1909
+ // input is needed when nothing is listening anymore).
1910
+ removeControlListener?.();
1911
+ runControl = undefined;
1912
+ approvePending = undefined;
1913
+ browserPrompt = undefined;
1914
+ browserSteering.length = 0;
1915
+ awaitingInput = 0;
1916
+ updateTitle(false);
1917
+ await settleRunRecord();
1918
+ // Deliver what this run queued before the process leaves; a no-op while no endpoint exists.
1919
+ await telemetrySettled;
1920
+ await sessionStarted;
1921
+ await drainTelemetry(telemetrySurface);
1922
+ active?.abort();
1923
+ active = undefined;
1924
+ try {
1925
+ await browserBridge?.persist();
1926
+ }
1927
+ catch (error) {
1928
+ print(`Could not save browser activity: ${error instanceof Error ? error.message : String(error)}`);
1929
+ }
1930
+ await writeActivity(directory, 'idle');
1931
+ refreshStatus();
1932
+ // Release the composer back to the normal question flow before the next prompt. A steer
1933
+ // submitted after the executor's final poll has nowhere to go; say so rather than
1934
+ // dropping text the user watched being accepted.
1935
+ for (const undelivered of terminal?.setSteering(false) ?? []) {
1936
+ // An attachment-only steer returns empty text: its chips went back to the queue, where
1937
+ // they are visible, so a blank "Not delivered" line would report nothing at all.
1938
+ if (undelivered)
1939
+ terminal?.print(`Not delivered — the run had already finished: ${undelivered}`);
1940
+ }
1941
+ // A timer prompt that queued as steering after the executor's final poll still owes its
1942
+ // delivery: it goes back to `timerPending` so the next composer hand-off runs it as a
1943
+ // fresh task rather than dropping a wake-up the agent asked for.
1944
+ for (const queued of timerSteering.splice(0))
1945
+ timerPending.push(queued);
1946
+ if (terminal)
1947
+ terminal.setStatus({ activity: graphModelsHealthy ? 'Ready' : 'Graph models unavailable', branch: await gitBranch(workspace) });
1948
+ refreshPanelStatus(true);
1949
+ scheduleAccountRefresh();
1950
+ browserDraining = false;
1951
+ browserCancelPending = false;
1952
+ }
1953
+ };
1954
+ try {
1955
+ if (values.prompt !== undefined) {
1956
+ if (!values.json)
1957
+ print(sessionDescription());
1958
+ // Machine consumers keep stdout pure JSON, so the debug log location goes to stderr.
1959
+ else if (values.debug)
1960
+ process.stderr.write(safeTerminal(sessionDescription()) + '\n');
1961
+ const commandStartedAt = Date.now();
1962
+ await debugRecord('command.started', { input: values.prompt, mode: 'headless' });
1963
+ try {
1964
+ return await run(values.prompt);
1965
+ }
1966
+ catch (error) {
1967
+ await debugRecord('command.error', { input: values.prompt, mode: 'headless', message: error instanceof Error ? error.message : String(error) });
1968
+ throw error;
1969
+ }
1970
+ finally {
1971
+ await debugRecord('command.completed', { input: values.prompt, mode: 'headless', durationMs: Date.now() - commandStartedAt });
1972
+ }
1973
+ }
1974
+ terminal.start();
1975
+ browserBridge = await createBrowserBridge(directory, () => {
1976
+ const snapshot = {
1977
+ ...(savedSession ?? { version: 1, id: trajectory.sessionId, name: 'New CLI session', workspace, updatedAt: new Date(sessionStartedAt).toISOString(), history: [], usage: { ...state.usage } }),
1978
+ projectId: projectIdentity(workspace), contextHistory: structuredClone(state.history ?? []), history: sessionArchive, status: browserDraining || (browserPrompt && browserCancelPending) ? 'cancelling' : browserPrompt || (runControl && active) ? active?.signal.aborted ? 'cancelling' : 'running' : 'idle', prompt: browserPrompt, events: [], pending: runControl && active && !active.signal.aborted ? terminal.browserQuestion() : undefined, permissions: state.permissions, provider: config.provider, model: config.providers.find(item => item.id === config.provider)?.model, graph: state.graph,
1979
+ };
1980
+ // The authenticated bridge also persists this snapshot. Preserve canonical
1981
+ // routing/storage metadata; the server separately redacts public paths.
1982
+ return { ...trajectory.sanitize(snapshot), id: snapshot.id, parentId: snapshot.parentId, workspace: snapshot.workspace, updatedAt: snapshot.updatedAt, status: snapshot.status };
1983
+ }, {
1984
+ prompt: async (text) => {
1985
+ if (browserDraining)
1986
+ throw new Error('The previous task is still finishing its save; try again in a moment.');
1987
+ if (browserRollbackFailed)
1988
+ throw new Error(rollbackFailureMessage);
1989
+ text = text.trim();
1990
+ if (text.startsWith('/') && (isBuiltinSlashCommand(text) || !await resolveSkillInvocation(text, config, undefined, directory)))
1991
+ throw new Error('Run built-in slash commands in the terminal, or invoke an enabled skill as /skillname.');
1992
+ if (!config.providers.length)
1993
+ throw new Error('Add a provider in /providers before starting a task.');
1994
+ if (!terminal.acceptConversationPrompt(text))
1995
+ throw new Error('Terminal is displaying a command screen; return to its prompt first.');
1996
+ const previousSession = savedSession;
1997
+ browserPrompt = text;
1998
+ if (!savedSession)
1999
+ savedSession = { version: 1, id: trajectory.sessionId, name: sessionName(text), workspace, updatedAt: new Date().toISOString(), history: [], usage: { ...state.usage } };
2000
+ // A fresh acceptance timestamp keeps the acknowledged interrupted task
2001
+ // inside the history age window even if the CLI exits before the run's
2002
+ // own persistence. Rejection restores the untouched previous record.
2003
+ else
2004
+ savedSession = { ...savedSession, updatedAt: new Date().toISOString() };
2005
+ // Register fresh sessions as well as their recoverable browser prompt.
2006
+ // The terminal run waits for these writes before updating either record.
2007
+ const record = { projectId: projectIdentity(workspace), ...savedSession, history: sessionArchive, contextHistory: state.history ?? [] };
2008
+ browserAcceptance = browserBridge.persist(() => sessions.save(record)).catch(async (error) => {
2009
+ // The archive may commit before the primary fails. Clear the rejected
2010
+ // prompt through the same queue before allowing another terminal task.
2011
+ // Steering queued during the pending start must not leak into the
2012
+ // next task either.
2013
+ active = undefined;
2014
+ browserPrompt = undefined;
2015
+ browserSteering.length = 0;
2016
+ browserCancelPending = false;
2017
+ savedSession = previousSession;
2018
+ try {
2019
+ if (previousSession)
2020
+ await browserBridge.persist(() => sessions.save(previousSession));
2021
+ else {
2022
+ // There was no durable session before this rejected first prompt.
2023
+ // Do not create an empty archive that would reappear after restart,
2024
+ // or retry the same unavailable archive write during rollback.
2025
+ const cleanup = await Promise.allSettled([
2026
+ rm(join(directory, 'browser-history', `${record.id}.json`), { force: true }),
2027
+ rm(join(directory, 'sessions', `${record.id}.json`), { force: true }),
2028
+ ]);
2029
+ const failures = cleanup.filter(result => result.status === 'rejected');
2030
+ if (failures.length)
2031
+ throw new AggregateError(failures.map(result => result.reason), 'Fresh session cleanup failed');
2032
+ }
2033
+ }
2034
+ catch (rollbackError) {
2035
+ // An archive-first acceptance can leave a rejected prompt recoverable
2036
+ // against the old primary. Remove it even if rollback storage fails,
2037
+ // and fence both browser and terminal tasks until storage is repaired.
2038
+ browserRollbackFailed = true;
2039
+ const cleanup = await Promise.allSettled([
2040
+ rm(join(directory, 'browser-history', `${record.id}.json`), { force: true }),
2041
+ // Fresh sessions have no previous primary to preserve. Retry its
2042
+ // removal independently even if the archive cleanup still fails.
2043
+ ...(!previousSession ? [rm(join(directory, 'sessions', `${record.id}.json`), { force: true })] : []),
2044
+ ]);
2045
+ const failures = cleanup.filter(result => result.status === 'rejected');
2046
+ const remaining = `${cleanup[0].status === 'rejected' ? ' Its partial archive could not be removed.' : ''}${cleanup[1]?.status === 'rejected' ? ' Its partial primary session could not be removed.' : ''}`;
2047
+ throw new AggregateError([error, rollbackError, ...failures.map(result => result.reason)], `Prompt rejected; ${rollbackFailureMessage}${remaining}`);
2048
+ }
2049
+ throw error;
2050
+ });
2051
+ const accepted = browserAcceptance;
2052
+ void accepted.catch(() => { });
2053
+ return accepted;
2054
+ },
2055
+ steer: text => {
2056
+ // Command screens also own `active`, but cannot consume graph steering.
2057
+ // Reject here so their input cannot be queued into the next task. An
2058
+ // acknowledged or starting prompt owns browserPrompt before runControl
2059
+ // exists: queue its steering for the run's first poll instead of
2060
+ // rejecting text the UI already advertises as steerable.
2061
+ if (browserDraining || active?.signal.aborted || (!browserPrompt && (!runControl || !active)))
2062
+ throw new Error('No task is accepting steering; return to the terminal prompt first.');
2063
+ if (runControl?.isPaused)
2064
+ runControl.resume(text);
2065
+ else
2066
+ browserSteering.push(text);
2067
+ },
2068
+ cancel: () => {
2069
+ // Command screens own `active` too. A task prompt identifies the
2070
+ // accepted/preflight window before its graph RunControl is installed.
2071
+ // While that acknowledged prompt is still starting, record the
2072
+ // cancellation intent: run() honors it as soon as it owns a signal.
2073
+ if (!active && browserPrompt) {
2074
+ browserCancelPending = true;
2075
+ return;
2076
+ }
2077
+ if ((!runControl && !browserPrompt) || !active || active.signal.aborted)
2078
+ throw new Error('No task is accepting cancellation; return to the terminal prompt first.');
2079
+ active.abort(new Error('Cancelled from browser'));
2080
+ },
2081
+ answer: answer => {
2082
+ // Configuration wizards also ask terminal questions, but only live
2083
+ // graph questions and approvals belong to the browser runtime controls.
2084
+ if (!runControl || !active || active.signal.aborted)
2085
+ throw new Error('No task is accepting answers; return to the terminal prompt first.');
2086
+ terminal.resolveQuestion(answer);
2087
+ },
2088
+ });
2089
+ terminal.setStatus({ session: trajectory.sessionId });
2090
+ // Keep the startup transcript focused on the task. Full identifiers and journal paths
2091
+ // remain available through /status, and --debug opts into their startup display.
2092
+ if (values.debug)
2093
+ print(sessionDescription());
2094
+ void refreshAccountStatus();
2095
+ try {
2096
+ await refreshGraphStatus();
2097
+ }
2098
+ catch (error) {
2099
+ if (!exiting)
2100
+ print(`Graph check failed: ${error instanceof Error ? error.message : 'Unknown failure'}`);
2101
+ }
2102
+ accountPolling = setInterval(scheduleAccountRefresh, 60_000);
2103
+ accountPolling.unref?.();
2104
+ while (!exiting) {
2105
+ let line;
2106
+ try {
2107
+ const asked = terminal.question('Describe a task, or type /help', { conversationPrompt: true });
2108
+ // A timer may have come due while the previous task was still saving, or while a
2109
+ // command screen or an approval owned the terminal; now the composer is armed again,
2110
+ // so hand it every self-wake prompt that had to wait.
2111
+ deliverTimerPrompts();
2112
+ line = (await asked).trim();
2113
+ }
2114
+ catch {
2115
+ break;
2116
+ }
2117
+ if (!line) {
2118
+ // An empty submission is a real submission when attachments are queued — paste-then-Enter
2119
+ // is the primary flow — and the substitute text names the intent the paste carried.
2120
+ if (!(terminal?.hasQueuedAttachments() ?? false))
2121
+ continue;
2122
+ line = ATTACHMENT_ONLY_TASK;
2123
+ }
2124
+ const commandStartedAt = Date.now();
2125
+ await debugRecord('command.started', { input: line, mode: 'interactive' });
2126
+ try {
2127
+ if (line === '/browser') {
2128
+ browserApp ??= await startBrowserServer();
2129
+ // A pending startup can outlive teardown; close instead of opening.
2130
+ if (exiting)
2131
+ await browserApp.close().catch(() => { });
2132
+ else {
2133
+ print(`Andorra Browser: ${browserApp.url}`);
2134
+ openBrowserUrl(browserApp.url);
2135
+ }
2136
+ continue;
2137
+ }
2138
+ if (line === '/session') {
2139
+ await persistSession();
2140
+ const records = await sessions.list(workspace);
2141
+ if (!records.length) {
2142
+ print('No saved sessions in this workspace yet. Send a task to create one.');
2143
+ continue;
2144
+ }
2145
+ const selected = await terminal.select('Sessions - most recently touched first', records.map(record => ({ id: record.id, label: record.name, description: `${record.id.slice(-10)} - ${new Date(record.updatedAt).toLocaleString()}` })), { description: 'Enter resumes saved conversation context in this workspace. Esc returns. Current model and graph settings are retained.', selectedId: savedSession?.id });
2146
+ const record = records.find(item => item.id === selected);
2147
+ if (!record || record.id === savedSession?.id)
2148
+ continue;
2149
+ // The lineage and the fork points that go with it are what make the totals exact, so
2150
+ // they are kept whole: a chain that was cut short would lose the older ancestors. The
2151
+ // refusal runs before the current conversation's timers are cleared, because a switch
2152
+ // that cannot happen must not leave the conversation it was leaving without them.
2153
+ if (!canExtendLineage(record.ancestors)) {
2154
+ throw new Error('This session has been resumed too many times to keep its lineage, so it cannot be resumed again.');
2155
+ }
2156
+ // Armed timers and undelivered prompts belong to the conversation being replaced:
2157
+ // firing one into a different resumed conversation would wake that session with a
2158
+ // prompt nobody inside it asked for. Cancel them at the switch, visibly.
2159
+ const abandonedTimers = sessionTimers.list().length + timerPending.length + timerSteering.length;
2160
+ sessionTimers.clear();
2161
+ timerPending.length = 0;
2162
+ timerSteering.length = 0;
2163
+ // Fork the saved snapshot so concurrent terminals never overwrite one another.
2164
+ // Archive files the record the user picked, not the work: the resumed conversation is a
2165
+ // live task, so the fork starts unarchived even when its source is put away.
2166
+ const { archived: _archived, autoArchived: _autoArchived, ...resumedRecord } = record;
2167
+ // The fork copies the parent's history and the parent's totals. The totals it inherited
2168
+ // are recorded as they are now, so the work this fork does itself can be told from the
2169
+ // work it was given, even if the parent keeps working afterwards. The lineage is written
2170
+ // down as well, so a session deleted later in the chain does not leave this fork looking
2171
+ // like the root of its own work.
2172
+ savedSession = { ...resumedRecord, id: randomUUID(), parentId: record.id,
2173
+ ancestors: lineageThrough(record.ancestors, record.id), inheritedUsage: { ...record.usage },
2174
+ inheritedTurns: record.history.length, lineage: lineagePoints(record, record.usage, record.history.length) };
2175
+ // The conversation that is being replaced keeps the log it was written to, and this one
2176
+ // takes a log of its own, so neither session shows the other's records.
2177
+ await openSessionTrajectory(savedSession.id);
2178
+ await trajectory.record('session.resumed', { resumedSessionId: savedSession.id, sourceSessionId: record.id });
2179
+ sessionArchive = structuredClone(record.history);
2180
+ state.history = structuredClone(record.contextHistory ?? record.history).slice(-6);
2181
+ state.usage = { ...record.usage };
2182
+ terminal.resetDashboardSession(record.usage);
2183
+ delete state.lastRun;
2184
+ contextUsedTokens = compactedContextEstimate(state.history);
2185
+ sessionContexts.clear();
2186
+ terminal.clearConversation();
2187
+ terminal.setTodos([]);
2188
+ // A continued turn leads with the direction the user sent after the stop — the same line the
2189
+ // desktop's timeline shows — because that message, not the stopped attempt's original task,
2190
+ // is what this turn's work answers to; the stopped turn above it still carries the original.
2191
+ for (const turn of displayHistory(sessionArchive)) {
2192
+ terminal.printPrompt(turn.direction ?? turn.task);
2193
+ terminal.print(turn.completion.summary);
2194
+ }
2195
+ print(`Resumed ${record.name} (${record.id.slice(-10)}) in a new session. Saved task/outcome context restored; current model and graph settings retained.`);
2196
+ if (abandonedTimers)
2197
+ print(`${abandonedTimers} self-wake timer${abandonedTimers === 1 ? '' : 's'} from the previous conversation ${abandonedTimers === 1 ? 'was' : 'were'} cancelled at the session switch.`);
2198
+ terminal.setStatus({ session: record.name, contextUsed: contextUsedTokens });
2199
+ refreshStatus();
2200
+ updateTitle(false);
2201
+ await persistSession();
2202
+ continue;
2203
+ }
2204
+ if (/^\/attach(?:\s|$)/.test(line)) {
2205
+ // Composer-local, so it lives beside the loop rather than in the command table:
2206
+ // it queues an attachment for the next task instead of running to completion.
2207
+ const argument = line.slice('/attach'.length).trim().replace(/^"(.*)"$/, '$1');
2208
+ if (!argument) {
2209
+ print('Usage: /attach <path> — queue a file or folder with your next task. Large pastes and dropped files attach automatically.');
2210
+ continue;
2211
+ }
2212
+ const target = resolve(workspace, argument);
2213
+ if (!existsSync(target)) {
2214
+ print(`No such file or folder: ${target}`);
2215
+ continue;
2216
+ }
2217
+ if (terminal.addAttachment({ kind: 'file', path: target }))
2218
+ print(`Attached ${target}. It rides your next task.`);
2219
+ continue;
2220
+ }
2221
+ if (isScreenCommand(line)) {
2222
+ active = new AbortController();
2223
+ try {
2224
+ const result = await runCommandScreen(line, state, terminal, persistConfig, active.signal, undefined, undefined, (signal, mode) => graphEditor.open(signal, mode));
2225
+ if (result.clear) {
2226
+ state.history = [];
2227
+ contextUsedTokens = 0;
2228
+ sessionContexts.clear();
2229
+ terminal?.setTodos([]);
2230
+ browserBridge?.startRun();
2231
+ trajectory.addSecrets(providerSecrets(config.providers));
2232
+ }
2233
+ if (/^\/graph(?:\s|$)/.test(line) || result.clear && /^\/(providers|model)(?:\s|$)/.test(line))
2234
+ await refreshGraphStatus();
2235
+ trajectory.addSecrets(providerSecrets(config.providers));
2236
+ refreshStatus();
2237
+ }
2238
+ finally {
2239
+ active = undefined;
2240
+ }
2241
+ continue;
2242
+ }
2243
+ if (terminal)
2244
+ terminal.printPrompt(line);
2245
+ else
2246
+ print(`You > ${line}`);
2247
+ const skillInvocation = line.startsWith('/') && !isBuiltinSlashCommand(line)
2248
+ ? await resolveSkillInvocation(line, config, undefined, directory) : undefined;
2249
+ if (line.startsWith('/') && !skillInvocation) {
2250
+ let command;
2251
+ if (/^\/codegraph\s+rebuild\s*$|^\/(login|logout|auth)(?:\s|$)/.test(line.trim())) {
2252
+ active = new AbortController();
2253
+ terminal?.setStatus({ activity: line.startsWith('/codegraph') ? 'Rebuilding CodeGraph' : 'Account authentication' });
2254
+ try {
2255
+ command = await executeCommand(line, state, persistConfig, active.signal);
2256
+ }
2257
+ finally {
2258
+ active = undefined;
2259
+ terminal?.setStatus({ activity: 'Ready' });
2260
+ if (/^\/(login|logout|auth)(?:\s|$)/.test(line.trim()))
2261
+ void refreshAccountStatus();
2262
+ }
2263
+ }
2264
+ else
2265
+ command = await executeCommand(line, state, persistConfig);
2266
+ afterJevCommand(line, command);
2267
+ trajectory.addSecrets(providerSecrets(config.providers));
2268
+ if (/^\/graph(?:\s|$)|^\/(?:auth\s+)?logout\s*$/.test(line) || command.clear && /^\/(providers|model)(?:\s|$)/.test(line))
2269
+ await refreshGraphStatus();
2270
+ refreshStatus();
2271
+ // `/clear` drops the chat entries before its own notice is printed, so the notice lands on
2272
+ // the wiped screen and survives it. The headless paths have no terminal (and no screen
2273
+ // entries), so they keep their plain stdout stream.
2274
+ if (command.resetScreen)
2275
+ terminal?.clearConversation();
2276
+ if (command.text)
2277
+ print(command.text);
2278
+ if (line === '/status')
2279
+ print(sessionDescription());
2280
+ if (command.clear) {
2281
+ state.history = [];
2282
+ contextUsedTokens = 0;
2283
+ terminal?.setTodos([]);
2284
+ browserBridge?.startRun();
2285
+ terminal?.setStatus({ contextUsed: 0 });
2286
+ }
2287
+ if (command.compact && state.history?.length) {
2288
+ state.history = compactHistory(state.history);
2289
+ // Until the next request reports the real input size, show the compacted
2290
+ // seed's estimated footprint so the utilization meter drops immediately.
2291
+ contextUsedTokens = compactedContextEstimate(state.history);
2292
+ terminal?.setStatus({ contextUsed: contextUsedTokens });
2293
+ }
2294
+ if (command.exit)
2295
+ break;
2296
+ if (command.discover) {
2297
+ active = new AbortController();
2298
+ terminal?.setStatus({ activity: 'Fetching models' });
2299
+ try {
2300
+ const adapter = createAdapter(config.providers.find(p => p.id === config.provider));
2301
+ if (!adapter.listModels)
2302
+ print('Model discovery unavailable. Select a model with /model <id>.');
2303
+ // Only the user's own cancellation is passed through: the adapter bounds the listing
2304
+ // itself (MODEL_LISTING_TIMEOUT_MS) and reports that deadline as a timeout, whereas a
2305
+ // timer armed here would fire first and be reported as a user cancellation.
2306
+ else
2307
+ print((await adapter.listModels(active.signal)).join('\n'));
2308
+ }
2309
+ finally {
2310
+ active = undefined;
2311
+ terminal?.setStatus({ activity: 'Ready' });
2312
+ }
2313
+ }
2314
+ }
2315
+ else
2316
+ await run(line, terminal?.takeAttachments() ?? []);
2317
+ }
2318
+ catch (error) {
2319
+ await debugRecord('command.error', { input: line, mode: 'interactive', message: error instanceof Error ? error.message : String(error) });
2320
+ print(`Error: ${error instanceof Error ? error.message : 'Unknown failure'}`);
2321
+ }
2322
+ finally {
2323
+ await persistSession();
2324
+ await debugRecord('command.completed', { input: line, mode: 'interactive', durationMs: Date.now() - commandStartedAt });
2325
+ }
2326
+ }
2327
+ return terminated ? 143 : 0;
2328
+ }
2329
+ finally {
2330
+ const cleanupErrors = [];
2331
+ // Each resource must be released even when another close rejects. In
2332
+ // particular, an app persistence error must not strand the CLI bridge.
2333
+ for (const cleanup of [
2334
+ // The panel's Git read is a display-only child process: it must not keep the process
2335
+ // alive behind a slow or network-backed worktree once the session is closing.
2336
+ () => {
2337
+ panelReads.abort();
2338
+ if (terminalsTimer)
2339
+ clearInterval(terminalsTimer);
2340
+ terminalsTimer = undefined;
2341
+ if (changesTimer)
2342
+ clearTimeout(changesTimer);
2343
+ changesTimer = undefined;
2344
+ },
2345
+ () => browserApp?.close(),
2346
+ () => browserBridge?.close(),
2347
+ () => tabTitle.close(),
2348
+ () => sessionEndedRecord(),
2349
+ // The session-start enqueue is part of the session's records: an exit that skips it leaves a
2350
+ // conversation the user created out of the counts, so this path waits for it like the flush.
2351
+ () => sessionStarted,
2352
+ () => trajectory.flush(),
2353
+ () => { if (accountPolling)
2354
+ clearInterval(accountPolling); if (accountRefreshTimer)
2355
+ clearTimeout(accountRefreshTimer); accountRefresh?.abort(); process.off('SIGINT', interrupt); process.off('SIGTERM', teardown); },
2356
+ () => terminal?.close(),
2357
+ () => graphEditor.close(),
2358
+ () => codeIntel.dispose(),
2359
+ // QA dev servers are owned by this CLI session.
2360
+ () => Promise.all([disposeAllQaProcesses(), disposeAllQaPtys(), disposePooledPowerShell()]).catch(() => { }),
2361
+ ]) {
2362
+ try {
2363
+ await cleanup();
2364
+ }
2365
+ catch (error) {
2366
+ cleanupErrors.push(error);
2367
+ }
2368
+ }
2369
+ // The hard-exit backstop stays armed through the cleanup above: a hung trajectory
2370
+ // flush, editor close or code-intel dispose must not outlive the user's kill. It is
2371
+ // disarmed only once every await has settled, and reset so a later kill() can re-arm.
2372
+ if (killBackstop) {
2373
+ clearTimeout(killBackstop);
2374
+ killBackstop = undefined;
2375
+ }
2376
+ if (cleanupErrors.length)
2377
+ throw new AggregateError(cleanupErrors, 'CLI cleanup failed');
2378
+ }
2379
+ }
2380
+ if (process.argv[1] && await realpath(fileURLToPath(import.meta.url)) === await realpath(process.argv[1]).catch(() => undefined)) {
2381
+ main().then(code => { process.exitCode = code; }, error => {
2382
+ process.stderr.write(safeTerminal(`Error: ${error instanceof Error ? error.message : 'Unknown failure'}`) + '\n');
2383
+ process.exitCode = 1;
2384
+ });
2385
+ }
2386
+ /**
2387
+ * The exit code a finished subagent command reports.
2388
+ *
2389
+ * A signal that arrived while the records were still being written is still a signal: the
2390
+ * supervisor that sent it is told the run was interrupted, not that it succeeded. The run's own
2391
+ * cancellation is refused that late, and the refusal must not turn into a success.
2392
+ */
2393
+ export function subagentExitCode(outcome, signals) {
2394
+ if (signals.interrupted)
2395
+ return 130;
2396
+ if (signals.terminated)
2397
+ return 143;
2398
+ if (outcome.status === 'succeeded')
2399
+ return 0;
2400
+ if (outcome.status === 'cancelled')
2401
+ return 143;
2402
+ return 1;
2403
+ }
2404
+ /**
2405
+ * `andorra subagent`: one Andorra run driven by an external host (Claude CLI, Codex CLI).
2406
+ *
2407
+ * The graph is always the bundled Software Engineer harness and the provider/model is mandatory:
2408
+ * the call's own flags win, the saved `/subagent` setting is next, and with neither the command
2409
+ * answers on stdout with the PROVIDER_NOT_SET envelope carrying every configured provider and
2410
+ * model, so a Bash-spawning host can ask its user and retry with the pick. Stdout stays reserved
2411
+ * for machine-readable output — one JSON line either way; progress notes go to stderr.
2412
+ */
2413
+ async function runSubagentCommand(argv) {
2414
+ const accepted = ['--prompt', '-p', '--provider', '--model', '--read-only', '--cwd', '--json', '--help', '-h'];
2415
+ // Every failure of this command answers on stdout with the same JSON envelope, so a host that
2416
+ // always parses a result-or-error line is not left with a bare stderr message.
2417
+ const fail = (code, message, extra = {}, exit = 1) => {
2418
+ process.stdout.write(JSON.stringify({ ok: false, error: { code, message, ...extra } }) + '\n');
2419
+ return exit;
2420
+ };
2421
+ // The options that take a value. The value that follows one is the option's value, even when it
2422
+ // begins with a hyphen: a prompt may well start with one, and the configuration permits a
2423
+ // provider or model id that does.
2424
+ const valued = new Set(['--prompt', '-p', '--provider', '--model', '--cwd']);
2425
+ for (let index = 0; index < argv.length; index += 1) {
2426
+ const argument = argv[index];
2427
+ if (!argument.startsWith('-'))
2428
+ continue;
2429
+ const name = argument.split('=')[0];
2430
+ if (!accepted.includes(name)) {
2431
+ fail('INVALID_ARGUMENTS', `Unknown option ${name}. andorra subagent accepts --prompt, --provider, --model, --read-only and --cwd, and always runs the Software Engineer default graph.`);
2432
+ return 1;
2433
+ }
2434
+ if (valued.has(name) && !argument.includes('='))
2435
+ index += 1;
2436
+ }
2437
+ let values;
2438
+ try {
2439
+ ({ values } = parseArgs({ args: argv, options: {
2440
+ help: { type: 'boolean', short: 'h' }, prompt: { type: 'string', short: 'p' },
2441
+ provider: { type: 'string' }, model: { type: 'string' }, 'read-only': { type: 'boolean' },
2442
+ cwd: { type: 'string' }, json: { type: 'boolean' },
2443
+ } }));
2444
+ }
2445
+ catch (error) {
2446
+ // The parser refuses a malformed invocation — an option without its value, an unknown one it
2447
+ // did not see — and that refusal is an answer this command owes on stdout, like every other
2448
+ // failure of it: a host that parses a result-or-error line must not be left with a bare
2449
+ // stderr message.
2450
+ fail('INVALID_ARGUMENTS', error instanceof Error ? error.message : String(error));
2451
+ return 1;
2452
+ }
2453
+ if (values.help) {
2454
+ process.stdout.write('Usage: andorra subagent --prompt "task" [--provider id] [--model id] [--read-only] [--cwd path]\n'
2455
+ + 'Runs the built-in Software Engineer graph once and prints the run result as one JSON line on stdout.\n'
2456
+ + 'Provider/model is mandatory: pass --provider/--model, or set it in Andorra with /subagent. Without either,\n'
2457
+ + 'the output is a PROVIDER_NOT_SET error listing every configured provider and model — show that list to\n'
2458
+ + 'the user, ask which pair to use, and retry with --provider and --model.\n'
2459
+ + 'Writes are allowed by default; pass --read-only to deny them. Exit codes: 0 succeeded, 1 failed or\n'
2460
+ + 'provider not set, 130 cancelled, 143 terminated.\n');
2461
+ return 0;
2462
+ }
2463
+ if (values.prompt === undefined || !values.prompt.trim()) {
2464
+ fail('INVALID_ARGUMENTS', 'andorra subagent requires --prompt "task".');
2465
+ return 1;
2466
+ }
2467
+ // The same bound the MCP tools apply, checked before the run is prepared: a task this long is
2468
+ // persisted and turned into model context, and the CLI path must refuse it the way the MCP
2469
+ // path does rather than write it out and refuse later.
2470
+ if (values.prompt.length > MAX_SUBAGENT_TASK_CHARS) {
2471
+ fail('INVALID_ARGUMENTS', `The task must be at most ${MAX_SUBAGENT_TASK_CHARS} characters.`);
2472
+ return 1;
2473
+ }
2474
+ const runner = new SubagentRunner();
2475
+ let interrupted = false;
2476
+ let terminated = false;
2477
+ const cancel = () => { runner.cancel(); };
2478
+ const onInterrupt = () => { interrupted = true; cancel(); };
2479
+ const onTerminate = () => { terminated = true; cancel(); };
2480
+ // The handlers are installed before the first asynchronous work: a signal that arrives while
2481
+ // the command resolves its workspace or classifies the attempts a previous process left in
2482
+ // flight would otherwise terminate the process directly, and the command would promise neither
2483
+ // its JSON error line nor its exit code.
2484
+ process.once('SIGINT', onInterrupt);
2485
+ process.once('SIGTERM', onTerminate);
2486
+ try {
2487
+ let workspace;
2488
+ try {
2489
+ workspace = await realpath(values.cwd ?? process.cwd());
2490
+ if (!(await stat(workspace)).isDirectory())
2491
+ throw new Error('--cwd must be a directory');
2492
+ }
2493
+ catch (error) {
2494
+ // A signal that arrived while the workspace was resolved is the command's to answer: the
2495
+ // filesystem error is not what the supervisor asked about.
2496
+ const signalled = subagentExitCode({ status: 'infrastructure_error' }, { interrupted, terminated });
2497
+ if (signalled !== 1) {
2498
+ return fail(interrupted ? 'CANCELLED' : 'TERMINATED', interrupted ? 'The run was interrupted before it started.' : 'The run was terminated before it started.', {}, signalled);
2499
+ }
2500
+ fail('INVALID_ARGUMENTS', error instanceof Error ? error.message : String(error));
2501
+ return 1;
2502
+ }
2503
+ // Attempts a previous process left in flight are classified before this one starts: this
2504
+ // command returns before the CLI's own startup recovery, so without this pass a crashed
2505
+ // subagent run would keep its record and its session turn `running` until an unrelated
2506
+ // interactive CLI or app-server was opened. Best effort: a damaged home must not block the run.
2507
+ // A run this process is still executing is not debris: an embedding process can call this
2508
+ // command while another engine works in the same home, and terminalizing that run would
2509
+ // remove the claim that holds its session and let a mutation in while it saves over it.
2510
+ try {
2511
+ const recovered = await reconcileInterruptedRuns(configDirectory(), undefined, { skipOwnProcess: true, includePending: true });
2512
+ // The reconciliation has already rewritten these records, so a later interactive startup
2513
+ // will not see them again: the finish is owed here or the start stays unmatched forever.
2514
+ await reportInterruptedRuns({ home: configDirectory(), surface: configuredSurface('subagent') }, recovered.interrupted);
2515
+ }
2516
+ catch { /* Recovery is best effort. */ }
2517
+ // A signal that arrived while the command was preparing is the command's to answer: a run that
2518
+ // starts now would be a full-access, billable run after the supervisor asked it to stop.
2519
+ const signalled = subagentExitCode({ status: 'infrastructure_error' }, { interrupted, terminated });
2520
+ if (signalled !== 1) {
2521
+ return fail(interrupted ? 'CANCELLED' : 'TERMINATED', interrupted ? 'The run was interrupted before it started.' : 'The run was terminated before it started.', {}, signalled);
2522
+ }
2523
+ const started = await runner.start({
2524
+ task: values.prompt, workspace,
2525
+ ...(values.provider !== undefined ? { provider: values.provider } : {}),
2526
+ ...(values.model !== undefined ? { model: values.model } : {}),
2527
+ permissions: values['read-only'] ? 'read-only' : 'full-access',
2528
+ });
2529
+ process.stderr.write(safeTerminal(`Subagent run ${started.runId} on ${started.provider}/${started.model} (${started.permissions}).\n`));
2530
+ let outcome = await runner.result(60_000);
2531
+ while (outcome.state === 'running')
2532
+ outcome = await runner.result(60_000);
2533
+ process.stdout.write(JSON.stringify(outcome.result ?? { status: outcome.status, ...(outcome.reason !== undefined ? { reason: outcome.reason } : {}) }) + '\n');
2534
+ // A signal that arrived while the records were still being written is still a signal: the
2535
+ // supervisor that sent it is told the run was interrupted, not that it succeeded. The run's
2536
+ // own cancellation is refused that late, and the refusal must not turn into a success.
2537
+ return subagentExitCode(outcome, { interrupted, terminated });
2538
+ }
2539
+ catch (error) {
2540
+ // A signal that arrived while the start was preparing is still a signal: the supervising host
2541
+ // is told the run was interrupted, not that it failed for some reason of its own.
2542
+ const signalled = subagentExitCode({ status: 'infrastructure_error' }, { interrupted, terminated });
2543
+ if (signalled !== 1) {
2544
+ // The command promises one JSON line on stdout: a host that parses a result-or-error line
2545
+ // must not be left with an empty answer.
2546
+ return fail(interrupted ? 'CANCELLED' : 'TERMINATED', interrupted ? 'The run was interrupted before it started.' : 'The run was terminated before it started.', {}, signalled);
2547
+ }
2548
+ if (error instanceof SubagentProviderNotSetError)
2549
+ return fail('PROVIDER_NOT_SET', error.message, { providers: error.providers });
2550
+ if (error instanceof SubagentRunInProgressError)
2551
+ return fail('RUN_IN_PROGRESS', error.message);
2552
+ if (error instanceof SubagentSelectionError)
2553
+ return fail('INVALID_ARGUMENTS', error.message);
2554
+ if (error instanceof SubagentInvalidArgumentError)
2555
+ return fail('INVALID_ARGUMENTS', error.message);
2556
+ return fail('SUBAGENT_FAILED', error instanceof Error ? error.message : String(error));
2557
+ }
2558
+ finally {
2559
+ // Only this command own handlers go: an embedding process may have listeners of its own,
2560
+ // and they are not this command to remove.
2561
+ process.removeListener('SIGINT', onInterrupt);
2562
+ process.removeListener('SIGTERM', onTerminate);
2563
+ }
2564
+ }