artificial-code 1.17.13

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 (749) hide show
  1. package/AGENTS.md +131 -0
  2. package/Dockerfile +18 -0
  3. package/README.md +15 -0
  4. package/bin/ac +199 -0
  5. package/bunfig.toml +7 -0
  6. package/git +0 -0
  7. package/migration/20260511173437_session-metadata/migration.sql +1 -0
  8. package/migration/20260511173437_session-metadata/snapshot.json +1500 -0
  9. package/package.json +156 -0
  10. package/parsers-config.ts +1 -0
  11. package/script/bench-search.ts +94 -0
  12. package/script/bench-test-suite.ts +52 -0
  13. package/script/build.ts +243 -0
  14. package/script/generate.ts +14 -0
  15. package/script/httpapi-exercise.ts +1 -0
  16. package/script/postinstall.mjs +189 -0
  17. package/script/profile-test-files.ts +42 -0
  18. package/script/publish.ts +213 -0
  19. package/script/run-workspace-server +106 -0
  20. package/script/schema.ts +77 -0
  21. package/script/time.ts +6 -0
  22. package/script/trace-imports.ts +153 -0
  23. package/specs/effect/error-boundaries-plan.md +235 -0
  24. package/specs/effect/errors.md +207 -0
  25. package/specs/effect/facades.md +218 -0
  26. package/specs/effect/guide.md +247 -0
  27. package/specs/effect/instance-context.md +13 -0
  28. package/specs/effect/loose-ends.md +30 -0
  29. package/specs/effect/migration.md +62 -0
  30. package/specs/effect/routes.md +61 -0
  31. package/specs/effect/schema.md +88 -0
  32. package/specs/effect/server-package.md +58 -0
  33. package/specs/effect/todo.md +241 -0
  34. package/specs/effect/tools.md +88 -0
  35. package/specs/openapi-translation-cleanup.md +204 -0
  36. package/specs/tui-plugins.md +544 -0
  37. package/specs/v2/api.ts +67 -0
  38. package/specs/v2/message-shape.md +136 -0
  39. package/specs/v2/notifications.md +13 -0
  40. package/specs/v2/tui-command-shim.md +67 -0
  41. package/src/account/account.ts +461 -0
  42. package/src/account/repo.ts +171 -0
  43. package/src/account/schema.ts +99 -0
  44. package/src/account/url.ts +8 -0
  45. package/src/acp/agent.ts +95 -0
  46. package/src/acp/config-option.ts +203 -0
  47. package/src/acp/content.ts +269 -0
  48. package/src/acp/directory.ts +212 -0
  49. package/src/acp/error.ts +97 -0
  50. package/src/acp/event.ts +342 -0
  51. package/src/acp/permission.ts +254 -0
  52. package/src/acp/profile.ts +42 -0
  53. package/src/acp/service.ts +1097 -0
  54. package/src/acp/session.ts +232 -0
  55. package/src/acp/tool.ts +364 -0
  56. package/src/acp/usage.ts +239 -0
  57. package/src/agent/agent.ts +453 -0
  58. package/src/agent/generate.txt +75 -0
  59. package/src/agent/prompt/compaction.txt +9 -0
  60. package/src/agent/prompt/explore.txt +18 -0
  61. package/src/agent/prompt/summary.txt +11 -0
  62. package/src/agent/prompt/title.txt +44 -0
  63. package/src/agent/subagent-permissions.ts +27 -0
  64. package/src/audio.d.ts +14 -0
  65. package/src/auth/index.ts +97 -0
  66. package/src/background/job.ts +37 -0
  67. package/src/bus/global.ts +22 -0
  68. package/src/cli/bootstrap.ts +11 -0
  69. package/src/cli/cmd/account.ts +264 -0
  70. package/src/cli/cmd/acp.ts +73 -0
  71. package/src/cli/cmd/agent.ts +259 -0
  72. package/src/cli/cmd/attach.ts +148 -0
  73. package/src/cli/cmd/cmd.ts +7 -0
  74. package/src/cli/cmd/db.ts +62 -0
  75. package/src/cli/cmd/debug/agent.handler.ts +193 -0
  76. package/src/cli/cmd/debug/agent.ts +27 -0
  77. package/src/cli/cmd/debug/config.ts +14 -0
  78. package/src/cli/cmd/debug/file.ts +73 -0
  79. package/src/cli/cmd/debug/index.ts +87 -0
  80. package/src/cli/cmd/debug/lsp.ts +50 -0
  81. package/src/cli/cmd/debug/ripgrep.ts +79 -0
  82. package/src/cli/cmd/debug/scrap.ts +16 -0
  83. package/src/cli/cmd/debug/skill.ts +15 -0
  84. package/src/cli/cmd/debug/snapshot.ts +50 -0
  85. package/src/cli/cmd/debug/startup.ts +11 -0
  86. package/src/cli/cmd/debug/v2.ts +42 -0
  87. package/src/cli/cmd/export.ts +292 -0
  88. package/src/cli/cmd/generate.ts +54 -0
  89. package/src/cli/cmd/github.handler.ts +1593 -0
  90. package/src/cli/cmd/github.shared.ts +30 -0
  91. package/src/cli/cmd/github.ts +42 -0
  92. package/src/cli/cmd/import.ts +224 -0
  93. package/src/cli/cmd/mcp.ts +840 -0
  94. package/src/cli/cmd/models.ts +66 -0
  95. package/src/cli/cmd/plug.ts +230 -0
  96. package/src/cli/cmd/pr.ts +115 -0
  97. package/src/cli/cmd/prompt-display.ts +1 -0
  98. package/src/cli/cmd/providers.ts +534 -0
  99. package/src/cli/cmd/run/demo.ts +1274 -0
  100. package/src/cli/cmd/run/entry.body.ts +205 -0
  101. package/src/cli/cmd/run/footer.command.tsx +1064 -0
  102. package/src/cli/cmd/run/footer.menu.tsx +351 -0
  103. package/src/cli/cmd/run/footer.permission.tsx +472 -0
  104. package/src/cli/cmd/run/footer.prompt.tsx +1306 -0
  105. package/src/cli/cmd/run/footer.question.tsx +573 -0
  106. package/src/cli/cmd/run/footer.subagent.tsx +173 -0
  107. package/src/cli/cmd/run/footer.ts +1129 -0
  108. package/src/cli/cmd/run/footer.view.tsx +943 -0
  109. package/src/cli/cmd/run/footer.width.ts +27 -0
  110. package/src/cli/cmd/run/permission.shared.ts +256 -0
  111. package/src/cli/cmd/run/prompt.editor.ts +157 -0
  112. package/src/cli/cmd/run/prompt.shared.ts +153 -0
  113. package/src/cli/cmd/run/question.shared.ts +340 -0
  114. package/src/cli/cmd/run/runtime.boot.ts +202 -0
  115. package/src/cli/cmd/run/runtime.lifecycle.ts +406 -0
  116. package/src/cli/cmd/run/runtime.queue.ts +349 -0
  117. package/src/cli/cmd/run/runtime.shared.ts +17 -0
  118. package/src/cli/cmd/run/runtime.stdin.ts +37 -0
  119. package/src/cli/cmd/run/runtime.ts +814 -0
  120. package/src/cli/cmd/run/scrollback.shared.ts +92 -0
  121. package/src/cli/cmd/run/scrollback.surface.ts +431 -0
  122. package/src/cli/cmd/run/scrollback.writer.tsx +352 -0
  123. package/src/cli/cmd/run/session-data.ts +1113 -0
  124. package/src/cli/cmd/run/session-replay.ts +374 -0
  125. package/src/cli/cmd/run/session.shared.ts +196 -0
  126. package/src/cli/cmd/run/splash.ts +280 -0
  127. package/src/cli/cmd/run/stream.transport.ts +1462 -0
  128. package/src/cli/cmd/run/stream.ts +175 -0
  129. package/src/cli/cmd/run/subagent-data.ts +876 -0
  130. package/src/cli/cmd/run/theme.ts +690 -0
  131. package/src/cli/cmd/run/tool.ts +1486 -0
  132. package/src/cli/cmd/run/trace.ts +94 -0
  133. package/src/cli/cmd/run/turn-summary.ts +47 -0
  134. package/src/cli/cmd/run/types.ts +350 -0
  135. package/src/cli/cmd/run/variant.shared.ts +216 -0
  136. package/src/cli/cmd/run.ts +1011 -0
  137. package/src/cli/cmd/serve.ts +24 -0
  138. package/src/cli/cmd/session.ts +147 -0
  139. package/src/cli/cmd/stats.ts +393 -0
  140. package/src/cli/cmd/tui.ts +305 -0
  141. package/src/cli/cmd/uninstall.ts +353 -0
  142. package/src/cli/cmd/upgrade.ts +74 -0
  143. package/src/cli/cmd/web.ts +84 -0
  144. package/src/cli/effect/prompt.ts +37 -0
  145. package/src/cli/effect-cmd.ts +96 -0
  146. package/src/cli/error.ts +130 -0
  147. package/src/cli/heap.ts +45 -0
  148. package/src/cli/logo.ts +1 -0
  149. package/src/cli/network.ts +80 -0
  150. package/src/cli/tui/layer.ts +8 -0
  151. package/src/cli/tui/validate-session.ts +29 -0
  152. package/src/cli/tui/worker.ts +80 -0
  153. package/src/cli/ui.ts +132 -0
  154. package/src/cli/upgrade.ts +53 -0
  155. package/src/command/index.ts +177 -0
  156. package/src/command/template/initialize.txt +66 -0
  157. package/src/command/template/review.txt +101 -0
  158. package/src/config/agent.ts +59 -0
  159. package/src/config/command.ts +39 -0
  160. package/src/config/config.ts +680 -0
  161. package/src/config/entry-name.ts +19 -0
  162. package/src/config/managed.ts +69 -0
  163. package/src/config/markdown.ts +36 -0
  164. package/src/config/parse.ts +79 -0
  165. package/src/config/paths.ts +45 -0
  166. package/src/config/plugin.ts +79 -0
  167. package/src/config/tui-cwd.ts +5 -0
  168. package/src/config/tui-host-attention.ts +21 -0
  169. package/src/config/tui-migrate.ts +132 -0
  170. package/src/config/tui.ts +276 -0
  171. package/src/config/variable.ts +91 -0
  172. package/src/control-plane/adapters/index.ts +41 -0
  173. package/src/control-plane/adapters/worktree.ts +96 -0
  174. package/src/control-plane/dev/README.md +19 -0
  175. package/src/control-plane/dev/debug-workspace-plugin.ts +73 -0
  176. package/src/control-plane/types.ts +59 -0
  177. package/src/control-plane/util.ts +39 -0
  178. package/src/control-plane/workspace-adapter-runtime.ts +51 -0
  179. package/src/control-plane/workspace-context.ts +26 -0
  180. package/src/control-plane/workspace.ts +964 -0
  181. package/src/effect/app-node-builder-v1.ts +12 -0
  182. package/src/effect/app-runtime.ts +135 -0
  183. package/src/effect/bootstrap-runtime.ts +19 -0
  184. package/src/effect/bridge.ts +84 -0
  185. package/src/effect/config-service.ts +67 -0
  186. package/src/effect/instance-ref.ts +11 -0
  187. package/src/effect/instance-registry.ts +12 -0
  188. package/src/effect/instance-state.ts +69 -0
  189. package/src/effect/promise.ts +17 -0
  190. package/src/effect/run-service.ts +47 -0
  191. package/src/effect/runner.ts +217 -0
  192. package/src/effect/runtime-flags.ts +77 -0
  193. package/src/env/index.ts +41 -0
  194. package/src/event-manifest.ts +3 -0
  195. package/src/event-v2-bridge.ts +71 -0
  196. package/src/format/formatter.ts +404 -0
  197. package/src/format/index.ts +203 -0
  198. package/src/git/index.ts +348 -0
  199. package/src/id/id.ts +80 -0
  200. package/src/ide/index.ts +54 -0
  201. package/src/image/image.ts +172 -0
  202. package/src/index.ts +142 -0
  203. package/src/installation/index.ts +336 -0
  204. package/src/lsp/client.ts +650 -0
  205. package/src/lsp/diagnostic.ts +29 -0
  206. package/src/lsp/language.ts +121 -0
  207. package/src/lsp/launch.ts +21 -0
  208. package/src/lsp/lsp.ts +507 -0
  209. package/src/lsp/server.ts +1983 -0
  210. package/src/markdown.d.ts +4 -0
  211. package/src/mcp/auth.ts +163 -0
  212. package/src/mcp/catalog.ts +170 -0
  213. package/src/mcp/index.ts +1012 -0
  214. package/src/mcp/oauth-callback.ts +194 -0
  215. package/src/mcp/oauth-provider.ts +259 -0
  216. package/src/node.ts +4 -0
  217. package/src/patch/index.ts +686 -0
  218. package/src/permission/arity.ts +163 -0
  219. package/src/permission/evaluate.ts +1 -0
  220. package/src/permission/index.ts +218 -0
  221. package/src/plugin/azure.ts +26 -0
  222. package/src/plugin/cloudflare.ts +76 -0
  223. package/src/plugin/digitalocean.ts +325 -0
  224. package/src/plugin/github-copilot/copilot.ts +414 -0
  225. package/src/plugin/github-copilot/models.ts +246 -0
  226. package/src/plugin/index.ts +314 -0
  227. package/src/plugin/install.ts +439 -0
  228. package/src/plugin/loader.ts +237 -0
  229. package/src/plugin/meta.ts +188 -0
  230. package/src/plugin/openai/README.md +31 -0
  231. package/src/plugin/openai/codex.ts +556 -0
  232. package/src/plugin/openai/ws-pool.ts +270 -0
  233. package/src/plugin/openai/ws.ts +381 -0
  234. package/src/plugin/pty-environment.ts +24 -0
  235. package/src/plugin/shared.ts +323 -0
  236. package/src/plugin/snowflake-cortex.ts +507 -0
  237. package/src/plugin/tui/internal.ts +10 -0
  238. package/src/plugin/tui/runtime.ts +1131 -0
  239. package/src/plugin/xai.ts +626 -0
  240. package/src/project/bootstrap-service.ts +9 -0
  241. package/src/project/bootstrap.ts +58 -0
  242. package/src/project/instance-context.ts +24 -0
  243. package/src/project/instance-runtime.ts +16 -0
  244. package/src/project/instance-store.ts +213 -0
  245. package/src/project/project.ts +483 -0
  246. package/src/project/vcs.ts +423 -0
  247. package/src/provider/auth.ts +229 -0
  248. package/src/provider/error.ts +188 -0
  249. package/src/provider/model-status.ts +8 -0
  250. package/src/provider/provider.ts +1977 -0
  251. package/src/provider/transform.ts +1561 -0
  252. package/src/question/index.ts +161 -0
  253. package/src/question/schema.ts +4 -0
  254. package/src/server/auth.ts +48 -0
  255. package/src/server/event.ts +10 -0
  256. package/src/server/global-lifecycle.ts +28 -0
  257. package/src/server/init-projectors.ts +3 -0
  258. package/src/server/mdns.ts +47 -0
  259. package/src/server/projectors.ts +1 -0
  260. package/src/server/proxy-util.ts +48 -0
  261. package/src/server/routes/instance/httpapi/AGENTS.md +39 -0
  262. package/src/server/routes/instance/httpapi/api.ts +97 -0
  263. package/src/server/routes/instance/httpapi/errors.ts +193 -0
  264. package/src/server/routes/instance/httpapi/groups/config.ts +65 -0
  265. package/src/server/routes/instance/httpapi/groups/control-plane.ts +35 -0
  266. package/src/server/routes/instance/httpapi/groups/control.ts +76 -0
  267. package/src/server/routes/instance/httpapi/groups/event.ts +29 -0
  268. package/src/server/routes/instance/httpapi/groups/experimental.ts +275 -0
  269. package/src/server/routes/instance/httpapi/groups/file.ts +185 -0
  270. package/src/server/routes/instance/httpapi/groups/global.ts +136 -0
  271. package/src/server/routes/instance/httpapi/groups/instance.ts +206 -0
  272. package/src/server/routes/instance/httpapi/groups/mcp.ts +156 -0
  273. package/src/server/routes/instance/httpapi/groups/metadata.ts +18 -0
  274. package/src/server/routes/instance/httpapi/groups/permission.ts +61 -0
  275. package/src/server/routes/instance/httpapi/groups/project-copy.ts +32 -0
  276. package/src/server/routes/instance/httpapi/groups/project.ts +93 -0
  277. package/src/server/routes/instance/httpapi/groups/provider.ts +101 -0
  278. package/src/server/routes/instance/httpapi/groups/pty.ts +172 -0
  279. package/src/server/routes/instance/httpapi/groups/query.ts +12 -0
  280. package/src/server/routes/instance/httpapi/groups/question.ts +74 -0
  281. package/src/server/routes/instance/httpapi/groups/session.ts +462 -0
  282. package/src/server/routes/instance/httpapi/groups/sync.ts +113 -0
  283. package/src/server/routes/instance/httpapi/groups/tui.ts +208 -0
  284. package/src/server/routes/instance/httpapi/groups/workspace.ts +141 -0
  285. package/src/server/routes/instance/httpapi/handlers/config.ts +34 -0
  286. package/src/server/routes/instance/httpapi/handlers/control-plane.ts +37 -0
  287. package/src/server/routes/instance/httpapi/handlers/control.ts +43 -0
  288. package/src/server/routes/instance/httpapi/handlers/event.ts +99 -0
  289. package/src/server/routes/instance/httpapi/handlers/experimental.ts +193 -0
  290. package/src/server/routes/instance/httpapi/handlers/file.ts +139 -0
  291. package/src/server/routes/instance/httpapi/handlers/global.ts +156 -0
  292. package/src/server/routes/instance/httpapi/handlers/instance.ts +110 -0
  293. package/src/server/routes/instance/httpapi/handlers/mcp.ts +111 -0
  294. package/src/server/routes/instance/httpapi/handlers/permission.ts +41 -0
  295. package/src/server/routes/instance/httpapi/handlers/project-copy.ts +83 -0
  296. package/src/server/routes/instance/httpapi/handlers/project.ts +63 -0
  297. package/src/server/routes/instance/httpapi/handlers/provider.ts +113 -0
  298. package/src/server/routes/instance/httpapi/handlers/pty.ts +273 -0
  299. package/src/server/routes/instance/httpapi/handlers/question.ts +54 -0
  300. package/src/server/routes/instance/httpapi/handlers/session-errors.ts +21 -0
  301. package/src/server/routes/instance/httpapi/handlers/session.ts +442 -0
  302. package/src/server/routes/instance/httpapi/handlers/sync.ts +89 -0
  303. package/src/server/routes/instance/httpapi/handlers/tui.ts +131 -0
  304. package/src/server/routes/instance/httpapi/handlers/workspace.ts +102 -0
  305. package/src/server/routes/instance/httpapi/lifecycle.ts +54 -0
  306. package/src/server/routes/instance/httpapi/middleware/authorization.ts +150 -0
  307. package/src/server/routes/instance/httpapi/middleware/compression.ts +64 -0
  308. package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +29 -0
  309. package/src/server/routes/instance/httpapi/middleware/error.ts +43 -0
  310. package/src/server/routes/instance/httpapi/middleware/fence.ts +25 -0
  311. package/src/server/routes/instance/httpapi/middleware/instance-context.ts +43 -0
  312. package/src/server/routes/instance/httpapi/middleware/proxy.ts +108 -0
  313. package/src/server/routes/instance/httpapi/middleware/schema-error.ts +41 -0
  314. package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +250 -0
  315. package/src/server/routes/instance/httpapi/public.ts +537 -0
  316. package/src/server/routes/instance/httpapi/server.ts +322 -0
  317. package/src/server/routes/instance/httpapi/websocket-tracker.ts +60 -0
  318. package/src/server/server.ts +226 -0
  319. package/src/server/shared/fence.ts +60 -0
  320. package/src/server/shared/pty-ticket.ts +15 -0
  321. package/src/server/shared/public-ui.ts +12 -0
  322. package/src/server/shared/tui-control.ts +28 -0
  323. package/src/server/shared/ui.ts +108 -0
  324. package/src/server/shared/workspace-routing.ts +38 -0
  325. package/src/server/tui-event.ts +1 -0
  326. package/src/session/compaction.ts +562 -0
  327. package/src/session/instruction.ts +237 -0
  328. package/src/session/llm/AGENTS.md +90 -0
  329. package/src/session/llm/ai-sdk.ts +288 -0
  330. package/src/session/llm/native-request.ts +196 -0
  331. package/src/session/llm/native-runtime.ts +195 -0
  332. package/src/session/llm/request.ts +226 -0
  333. package/src/session/llm.ts +404 -0
  334. package/src/session/message-error.ts +14 -0
  335. package/src/session/message-v2.ts +734 -0
  336. package/src/session/message.ts +148 -0
  337. package/src/session/overflow.ts +34 -0
  338. package/src/session/processor.ts +716 -0
  339. package/src/session/prompt/anthropic.txt +105 -0
  340. package/src/session/prompt/beast.txt +147 -0
  341. package/src/session/prompt/build-switch.txt +5 -0
  342. package/src/session/prompt/codex.txt +79 -0
  343. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  344. package/src/session/prompt/default.txt +95 -0
  345. package/src/session/prompt/gemini.txt +155 -0
  346. package/src/session/prompt/gpt.txt +107 -0
  347. package/src/session/prompt/kimi.txt +95 -0
  348. package/src/session/prompt/plan-mode.txt +70 -0
  349. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  350. package/src/session/prompt/plan.txt +26 -0
  351. package/src/session/prompt/trinity.txt +97 -0
  352. package/src/session/prompt.ts +1630 -0
  353. package/src/session/reminders.ts +92 -0
  354. package/src/session/retry.ts +201 -0
  355. package/src/session/revert.ts +146 -0
  356. package/src/session/run-state.ts +151 -0
  357. package/src/session/schema.ts +26 -0
  358. package/src/session/session.ts +1018 -0
  359. package/src/session/status.ts +56 -0
  360. package/src/session/summary.ts +160 -0
  361. package/src/session/system.ts +143 -0
  362. package/src/session/todo.ts +74 -0
  363. package/src/session/tools.ts +583 -0
  364. package/src/share/session.ts +58 -0
  365. package/src/share/share-next.ts +371 -0
  366. package/src/skill/discovery.ts +140 -0
  367. package/src/skill/index.ts +354 -0
  368. package/src/snapshot/index.ts +807 -0
  369. package/src/sql.d.ts +4 -0
  370. package/src/storage/schema.ts +5 -0
  371. package/src/storage/storage.ts +327 -0
  372. package/src/sync/README.md +179 -0
  373. package/src/sync/schema.ts +11 -0
  374. package/src/temporary.ts +31 -0
  375. package/src/tool/apply_patch.ts +313 -0
  376. package/src/tool/apply_patch.txt +33 -0
  377. package/src/tool/edit.ts +737 -0
  378. package/src/tool/edit.txt +10 -0
  379. package/src/tool/external-directory.ts +49 -0
  380. package/src/tool/glob.ts +76 -0
  381. package/src/tool/glob.txt +6 -0
  382. package/src/tool/grep.ts +112 -0
  383. package/src/tool/grep.txt +8 -0
  384. package/src/tool/invalid.ts +21 -0
  385. package/src/tool/json-schema.ts +164 -0
  386. package/src/tool/lsp.ts +113 -0
  387. package/src/tool/lsp.txt +24 -0
  388. package/src/tool/mcp-websearch.ts +96 -0
  389. package/src/tool/plan-enter.txt +14 -0
  390. package/src/tool/plan-exit.txt +13 -0
  391. package/src/tool/plan.ts +79 -0
  392. package/src/tool/question.ts +44 -0
  393. package/src/tool/question.txt +10 -0
  394. package/src/tool/read.ts +386 -0
  395. package/src/tool/read.txt +14 -0
  396. package/src/tool/registry.ts +420 -0
  397. package/src/tool/schema.ts +14 -0
  398. package/src/tool/shell/id.ts +19 -0
  399. package/src/tool/shell/prompt.ts +293 -0
  400. package/src/tool/shell/shell.txt +21 -0
  401. package/src/tool/shell.ts +645 -0
  402. package/src/tool/skill.ts +70 -0
  403. package/src/tool/skill.txt +5 -0
  404. package/src/tool/task.ts +346 -0
  405. package/src/tool/task.txt +19 -0
  406. package/src/tool/todo.ts +46 -0
  407. package/src/tool/todowrite.txt +44 -0
  408. package/src/tool/tool.ts +183 -0
  409. package/src/tool/truncate.ts +156 -0
  410. package/src/tool/truncation-dir.ts +4 -0
  411. package/src/tool/webfetch.ts +192 -0
  412. package/src/tool/webfetch.txt +13 -0
  413. package/src/tool/websearch.ts +143 -0
  414. package/src/tool/websearch.txt +14 -0
  415. package/src/tool/write.ts +104 -0
  416. package/src/tool/write.txt +8 -0
  417. package/src/util/archive.ts +17 -0
  418. package/src/util/bom.ts +27 -0
  419. package/src/util/data-url.ts +9 -0
  420. package/src/util/defer.ts +10 -0
  421. package/src/util/effect-http-client.ts +11 -0
  422. package/src/util/error.ts +1 -0
  423. package/src/util/filesystem.ts +251 -0
  424. package/src/util/html.ts +8 -0
  425. package/src/util/iife.ts +3 -0
  426. package/src/util/lazy.ts +20 -0
  427. package/src/util/local-context.ts +25 -0
  428. package/src/util/locale.ts +2 -0
  429. package/src/util/media.ts +26 -0
  430. package/src/util/process.ts +177 -0
  431. package/src/util/proxy-env.ts +72 -0
  432. package/src/util/queue.ts +32 -0
  433. package/src/util/record.ts +1 -0
  434. package/src/util/repository.ts +232 -0
  435. package/src/util/rpc.ts +66 -0
  436. package/src/util/signal.ts +12 -0
  437. package/src/util/timeout.ts +13 -0
  438. package/src/util/token.ts +1 -0
  439. package/src/util/wildcard.ts +59 -0
  440. package/src/worktree/index.ts +623 -0
  441. package/test/AGENTS.md +204 -0
  442. package/test/EFFECT_TEST_MIGRATION.md +169 -0
  443. package/test/account/repo.test.ts +355 -0
  444. package/test/account/service.test.ts +456 -0
  445. package/test/acp/config-option.test.ts +229 -0
  446. package/test/acp/content.test.ts +235 -0
  447. package/test/acp/directory.test.ts +188 -0
  448. package/test/acp/error.test.ts +67 -0
  449. package/test/acp/event.test.ts +751 -0
  450. package/test/acp/permission.test.ts +401 -0
  451. package/test/acp/service-session.test.ts +1248 -0
  452. package/test/acp/session.test.ts +201 -0
  453. package/test/acp/tool.test.ts +298 -0
  454. package/test/acp/usage.test.ts +318 -0
  455. package/test/agent/agent.test.ts +755 -0
  456. package/test/agent/plan-mode-subagent-bypass.test.ts +160 -0
  457. package/test/agent/plugin-agent-regression.test.ts +51 -0
  458. package/test/auth/auth.test.ts +75 -0
  459. package/test/background/job.test.ts +244 -0
  460. package/test/cli/account.test.ts +30 -0
  461. package/test/cli/acp/acp-test-client.ts +97 -0
  462. package/test/cli/acp/config-options.test.ts +103 -0
  463. package/test/cli/acp/helpers.ts +96 -0
  464. package/test/cli/acp/initialize-auth.test.ts +61 -0
  465. package/test/cli/acp/lifecycle.test.ts +118 -0
  466. package/test/cli/acp/prompt-content.test.ts +97 -0
  467. package/test/cli/acp/skills.test.ts +38 -0
  468. package/test/cli/cmd/tui/attention.test.ts +484 -0
  469. package/test/cli/effect-cmd-instance-als.test.ts +40 -0
  470. package/test/cli/error.test.ts +95 -0
  471. package/test/cli/github-action.test.ts +199 -0
  472. package/test/cli/github-remote.test.ts +90 -0
  473. package/test/cli/help/__snapshots__/help-snapshots.test.ts.snap +623 -0
  474. package/test/cli/help/help-snapshots.test.ts +140 -0
  475. package/test/cli/import.test.ts +54 -0
  476. package/test/cli/mcp-add.test.ts +74 -0
  477. package/test/cli/plugin-auth-picker.test.ts +120 -0
  478. package/test/cli/run/entry.body.test.ts +536 -0
  479. package/test/cli/run/footer.menu.test.ts +43 -0
  480. package/test/cli/run/footer.view.test.tsx +1375 -0
  481. package/test/cli/run/footer.width.test.ts +35 -0
  482. package/test/cli/run/permission.shared.test.ts +144 -0
  483. package/test/cli/run/prompt.editor.test.ts +101 -0
  484. package/test/cli/run/prompt.shared.test.ts +101 -0
  485. package/test/cli/run/question.shared.test.ts +115 -0
  486. package/test/cli/run/run-process.test.ts +331 -0
  487. package/test/cli/run/runtime.boot.test.ts +283 -0
  488. package/test/cli/run/runtime.queue.test.ts +481 -0
  489. package/test/cli/run/runtime.stdin.test.ts +71 -0
  490. package/test/cli/run/runtime.test.ts +238 -0
  491. package/test/cli/run/scrollback.surface.test.ts +1092 -0
  492. package/test/cli/run/session-data.test.ts +593 -0
  493. package/test/cli/run/session-replay.test.ts +691 -0
  494. package/test/cli/run/session.shared.test.ts +247 -0
  495. package/test/cli/run/stream.test.ts +56 -0
  496. package/test/cli/run/stream.transport.test.ts +2363 -0
  497. package/test/cli/run/subagent-data.test.ts +547 -0
  498. package/test/cli/run/theme.test.ts +177 -0
  499. package/test/cli/run/variant.shared.test.ts +218 -0
  500. package/test/cli/serve/serve-process.test.ts +61 -0
  501. package/test/cli/smokes/read-only.test.ts +115 -0
  502. package/test/cli/tui/attach.test.ts +11 -0
  503. package/test/cli/tui/editor-context-zed.test.ts +379 -0
  504. package/test/cli/tui/editor-context.test.tsx +297 -0
  505. package/test/cli/tui/plugin-add.test.ts +110 -0
  506. package/test/cli/tui/plugin-install.test.ts +87 -0
  507. package/test/cli/tui/plugin-lifecycle.test.ts +224 -0
  508. package/test/cli/tui/plugin-loader-entrypoint.test.ts +485 -0
  509. package/test/cli/tui/plugin-loader-pure.test.ts +72 -0
  510. package/test/cli/tui/plugin-loader.test.ts +1332 -0
  511. package/test/cli/tui/plugin-toggle.test.ts +264 -0
  512. package/test/cli/tui/thread.test.ts +95 -0
  513. package/test/config/agent-color.test.ts +47 -0
  514. package/test/config/config.test.ts +2027 -0
  515. package/test/config/entry-name.test.ts +57 -0
  516. package/test/config/fixtures/empty-frontmatter.md +4 -0
  517. package/test/config/fixtures/frontmatter.md +28 -0
  518. package/test/config/fixtures/markdown-header.md +11 -0
  519. package/test/config/fixtures/no-frontmatter.md +1 -0
  520. package/test/config/fixtures/weird-model-id.md +13 -0
  521. package/test/config/lsp.test.ts +69 -0
  522. package/test/config/markdown.test.ts +228 -0
  523. package/test/config/plugin.test.ts +0 -0
  524. package/test/config/tui.test.ts +894 -0
  525. package/test/control-plane/adapters.test.ts +71 -0
  526. package/test/control-plane/workspace.test.ts +1701 -0
  527. package/test/effect/app-runtime-logger.test.ts +101 -0
  528. package/test/effect/config-service.test.ts +65 -0
  529. package/test/effect/instance-state.test.ts +392 -0
  530. package/test/effect/run-service.test.ts +89 -0
  531. package/test/effect/runner.test.ts +514 -0
  532. package/test/effect/runtime-flags.test.ts +374 -0
  533. package/test/event-manifest.test.ts +24 -0
  534. package/test/fake/account.ts +9 -0
  535. package/test/fake/auth.ts +8 -0
  536. package/test/fake/npm.ts +8 -0
  537. package/test/fake/provider.ts +82 -0
  538. package/test/fake/skill.ts +8 -0
  539. package/test/filesystem/filesystem.test.ts +318 -0
  540. package/test/fixture/agent-plugin.constants.ts +6 -0
  541. package/test/fixture/agent-plugin.ts +12 -0
  542. package/test/fixture/config.ts +23 -0
  543. package/test/fixture/db.ts +11 -0
  544. package/test/fixture/fixture.test.ts +26 -0
  545. package/test/fixture/fixture.ts +228 -0
  546. package/test/fixture/flag.ts +20 -0
  547. package/test/fixture/flock-worker.ts +72 -0
  548. package/test/fixture/lsp/fake-lsp-server.js +249 -0
  549. package/test/fixture/mcp-session-recovery.ts +50 -0
  550. package/test/fixture/plug-worker.ts +93 -0
  551. package/test/fixture/plugin-meta-worker.ts +19 -0
  552. package/test/fixture/plugin.ts +10 -0
  553. package/test/fixture/skills/agents-sdk/SKILL.md +152 -0
  554. package/test/fixture/skills/agents-sdk/references/callable.md +92 -0
  555. package/test/fixture/skills/cloudflare/SKILL.md +211 -0
  556. package/test/fixture/skills/index.json +6 -0
  557. package/test/fixture/tui-environment.tsx +32 -0
  558. package/test/fixture/tui-plugin.ts +355 -0
  559. package/test/fixture/tui-runtime.ts +56 -0
  560. package/test/fixture/tui-sdk.ts +82 -0
  561. package/test/fixture/workspace.ts +34 -0
  562. package/test/fixtures/recordings/session/native-anthropic-tool-loop.json +49 -0
  563. package/test/fixtures/recordings/session/native-openai-oauth-tool-loop.json +45 -0
  564. package/test/fixtures/recordings/session/native-zen-tool-loop.json +49 -0
  565. package/test/format/format.test.ts +235 -0
  566. package/test/git/git.test.ts +179 -0
  567. package/test/ide/ide.test.ts +82 -0
  568. package/test/image/fixtures/picture-5mb-base64.png +0 -0
  569. package/test/image/image.test.ts +121 -0
  570. package/test/installation/installation.test.ts +240 -0
  571. package/test/lib/cli-process.ts +535 -0
  572. package/test/lib/effect.ts +177 -0
  573. package/test/lib/filesystem.ts +10 -0
  574. package/test/lib/llm-server.ts +779 -0
  575. package/test/lib/snapshot.ts +73 -0
  576. package/test/lib/test-provider.ts +37 -0
  577. package/test/lib/websocket.ts +46 -0
  578. package/test/lsp/client.test.ts +488 -0
  579. package/test/lsp/index.test.ts +231 -0
  580. package/test/lsp/jdtls-root.test.ts +459 -0
  581. package/test/lsp/launch.test.ts +22 -0
  582. package/test/lsp/lifecycle.test.ts +160 -0
  583. package/test/mcp/auth.test.ts +78 -0
  584. package/test/mcp/catalog.test.ts +47 -0
  585. package/test/mcp/headers.test.ts +127 -0
  586. package/test/mcp/lifecycle.test.ts +1304 -0
  587. package/test/mcp/oauth-auto-connect.test.ts +367 -0
  588. package/test/mcp/oauth-browser.test.ts +243 -0
  589. package/test/mcp/oauth-callback.test.ts +114 -0
  590. package/test/mcp/oauth-provider.test.ts +102 -0
  591. package/test/mcp/session-recovery.test.ts +27 -0
  592. package/test/patch/patch.test.ts +384 -0
  593. package/test/permission/arity.test.ts +33 -0
  594. package/test/permission/next.test.ts +1174 -0
  595. package/test/permission-task.test.ts +319 -0
  596. package/test/plugin/auth-override.test.ts +101 -0
  597. package/test/plugin/cloudflare.test.ts +68 -0
  598. package/test/plugin/codex.test.ts +256 -0
  599. package/test/plugin/github-copilot-models.test.ts +332 -0
  600. package/test/plugin/install-concurrency.test.ts +140 -0
  601. package/test/plugin/install.test.ts +570 -0
  602. package/test/plugin/loader-shared.test.ts +1306 -0
  603. package/test/plugin/meta.test.ts +137 -0
  604. package/test/plugin/openai-rollout.test.ts +17 -0
  605. package/test/plugin/openai-ws.test.ts +884 -0
  606. package/test/plugin/shared.test.ts +88 -0
  607. package/test/plugin/snowflake-cortex.test.ts +278 -0
  608. package/test/plugin/trigger.test.ts +108 -0
  609. package/test/plugin/workspace-adapter.test.ts +111 -0
  610. package/test/plugin/xai.test.ts +620 -0
  611. package/test/preload.ts +92 -0
  612. package/test/project/instance-bootstrap.test.ts +115 -0
  613. package/test/project/instance.test.ts +248 -0
  614. package/test/project/migrate-global.test.ts +168 -0
  615. package/test/project/project-directory.test.ts +202 -0
  616. package/test/project/project.test.ts +808 -0
  617. package/test/project/vcs.test.ts +335 -0
  618. package/test/project/worktree-remove.test.ts +128 -0
  619. package/test/project/worktree.test.ts +324 -0
  620. package/test/provider/amazon-bedrock.test.ts +361 -0
  621. package/test/provider/cf-ai-gateway-e2e.test.ts +132 -0
  622. package/test/provider/digitalocean.test.ts +124 -0
  623. package/test/provider/gitlab-duo.test.ts +412 -0
  624. package/test/provider/header-timeout.test.ts +234 -0
  625. package/test/provider/model-status.test.ts +61 -0
  626. package/test/provider/provider.test.ts +1912 -0
  627. package/test/provider/transform.test.ts +4742 -0
  628. package/test/question/question.test.ts +459 -0
  629. package/test/server/AGENTS.md +15 -0
  630. package/test/server/auth.test.ts +59 -0
  631. package/test/server/global-bus.ts +31 -0
  632. package/test/server/global-session-list.test.ts +108 -0
  633. package/test/server/httpapi-authorization.test.ts +174 -0
  634. package/test/server/httpapi-compression.test.ts +151 -0
  635. package/test/server/httpapi-config.test.ts +110 -0
  636. package/test/server/httpapi-control-plane.test.ts +63 -0
  637. package/test/server/httpapi-cors-vary.test.ts +63 -0
  638. package/test/server/httpapi-cors.test.ts +122 -0
  639. package/test/server/httpapi-error-middleware.test.ts +101 -0
  640. package/test/server/httpapi-event.test.ts +94 -0
  641. package/test/server/httpapi-exercise/assertions.ts +64 -0
  642. package/test/server/httpapi-exercise/backend.ts +144 -0
  643. package/test/server/httpapi-exercise/dsl.ts +210 -0
  644. package/test/server/httpapi-exercise/environment.ts +40 -0
  645. package/test/server/httpapi-exercise/index.ts +1814 -0
  646. package/test/server/httpapi-exercise/report.ts +66 -0
  647. package/test/server/httpapi-exercise/routing.ts +96 -0
  648. package/test/server/httpapi-exercise/runner.ts +267 -0
  649. package/test/server/httpapi-exercise/runtime.ts +52 -0
  650. package/test/server/httpapi-exercise/types.ts +127 -0
  651. package/test/server/httpapi-experimental.test.ts +298 -0
  652. package/test/server/httpapi-file.test.ts +83 -0
  653. package/test/server/httpapi-global.test.ts +66 -0
  654. package/test/server/httpapi-instance-context.test.ts +337 -0
  655. package/test/server/httpapi-instance-route-auth.test.ts +81 -0
  656. package/test/server/httpapi-instance.test.ts +265 -0
  657. package/test/server/httpapi-layer.ts +33 -0
  658. package/test/server/httpapi-listen.test.ts +465 -0
  659. package/test/server/httpapi-mcp-oauth.test.ts +73 -0
  660. package/test/server/httpapi-mcp.test.ts +223 -0
  661. package/test/server/httpapi-mdns.test.ts +79 -0
  662. package/test/server/httpapi-promptasync-context.test.ts +212 -0
  663. package/test/server/httpapi-provider.test.ts +401 -0
  664. package/test/server/httpapi-pty.test.ts +299 -0
  665. package/test/server/httpapi-public-openapi.test.ts +350 -0
  666. package/test/server/httpapi-query-schema-drift.test.ts +330 -0
  667. package/test/server/httpapi-reference.test.ts +63 -0
  668. package/test/server/httpapi-schema-error-body.test.ts +166 -0
  669. package/test/server/httpapi-sdk.test.ts +913 -0
  670. package/test/server/httpapi-session.test.ts +1090 -0
  671. package/test/server/httpapi-sync.test.ts +149 -0
  672. package/test/server/httpapi-ui.test.ts +456 -0
  673. package/test/server/httpapi-v2-location.test.ts +126 -0
  674. package/test/server/httpapi-v2-pty.test.ts +250 -0
  675. package/test/server/httpapi-workspace-routing.test.ts +552 -0
  676. package/test/server/httpapi-workspace.test.ts +506 -0
  677. package/test/server/negative-tokens-regression.test.ts +84 -0
  678. package/test/server/project-copy.test.ts +127 -0
  679. package/test/server/project-init-git.test.ts +118 -0
  680. package/test/server/proxy-util.test.ts +113 -0
  681. package/test/server/sdk-error-shape.test.ts +81 -0
  682. package/test/server/sdk-v1-smoke.test.ts +57 -0
  683. package/test/server/session-actions.test.ts +110 -0
  684. package/test/server/session-diff-missing-patch.test.ts +97 -0
  685. package/test/server/session-list.test.ts +302 -0
  686. package/test/server/session-messages.test.ts +180 -0
  687. package/test/server/session-select.test.ts +67 -0
  688. package/test/server/workspace-proxy.test.ts +181 -0
  689. package/test/server/workspace-routing.test.ts +94 -0
  690. package/test/server/worktree-endpoint-repro.test.ts +307 -0
  691. package/test/session/compaction.test.ts +1819 -0
  692. package/test/session/instruction.test.ts +264 -0
  693. package/test/session/llm-native-recorded.test.ts +413 -0
  694. package/test/session/llm-native.test.ts +761 -0
  695. package/test/session/llm.test.ts +2003 -0
  696. package/test/session/message-v2.test.ts +1661 -0
  697. package/test/session/messages-pagination.test.ts +1057 -0
  698. package/test/session/processor-effect.test.ts +1067 -0
  699. package/test/session/prompt.test.ts +2402 -0
  700. package/test/session/retry.test.ts +440 -0
  701. package/test/session/revert-compact.test.ts +638 -0
  702. package/test/session/schema-decoding.test.ts +313 -0
  703. package/test/session/session-schema.test.ts +78 -0
  704. package/test/session/session.test.ts +253 -0
  705. package/test/session/snapshot-tool-race.test.ts +189 -0
  706. package/test/session/structured-output-integration.test.ts +235 -0
  707. package/test/session/structured-output.test.ts +387 -0
  708. package/test/session/system.test.ts +142 -0
  709. package/test/share/share-next.test.ts +324 -0
  710. package/test/skill/discovery.test.ts +186 -0
  711. package/test/skill/skill.test.ts +585 -0
  712. package/test/snapshot/snapshot.test.ts +1218 -0
  713. package/test/storage/storage.test.ts +297 -0
  714. package/test/tool/__snapshots__/parameters.test.ts.snap +466 -0
  715. package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
  716. package/test/tool/apply_patch.test.ts +529 -0
  717. package/test/tool/edit.test.ts +574 -0
  718. package/test/tool/external-directory.test.ts +156 -0
  719. package/test/tool/fixtures/large-image.png +0 -0
  720. package/test/tool/fixtures/models-api.json +117299 -0
  721. package/test/tool/glob.test.ts +132 -0
  722. package/test/tool/grep.test.ts +221 -0
  723. package/test/tool/lsp.test.ts +184 -0
  724. package/test/tool/parameters.test.ts +290 -0
  725. package/test/tool/question.test.ts +133 -0
  726. package/test/tool/read.test.ts +608 -0
  727. package/test/tool/registry.test.ts +493 -0
  728. package/test/tool/shell.test.ts +1199 -0
  729. package/test/tool/skill.test.ts +134 -0
  730. package/test/tool/task.test.ts +905 -0
  731. package/test/tool/tool-define.test.ts +154 -0
  732. package/test/tool/truncation.test.ts +264 -0
  733. package/test/tool/webfetch.test.ts +119 -0
  734. package/test/tool/websearch.test.ts +99 -0
  735. package/test/tool/write.test.ts +279 -0
  736. package/test/util/data-url.test.ts +14 -0
  737. package/test/util/error.test.ts +16 -0
  738. package/test/util/filesystem.test.ts +656 -0
  739. package/test/util/glob.test.ts +164 -0
  740. package/test/util/html.test.ts +15 -0
  741. package/test/util/iife.test.ts +36 -0
  742. package/test/util/lazy.test.ts +50 -0
  743. package/test/util/module.test.ts +59 -0
  744. package/test/util/process.test.ts +128 -0
  745. package/test/util/repository.test.ts +93 -0
  746. package/test/util/timeout.test.ts +21 -0
  747. package/test/util/wildcard.test.ts +90 -0
  748. package/test/v2/session-message-updater.test.ts +269 -0
  749. package/tsconfig.json +16 -0
@@ -0,0 +1,2402 @@
1
+ import { ConfigV1 } from "@ac/core/v1/config/config"
2
+ import { SessionV1 } from "@ac/core/v1/session"
3
+ import { Database } from "@ac/core/database/database"
4
+ import { LayerNode } from "@ac/core/effect/layer-node"
5
+ import { SessionProjector } from "@ac/core/session/projector"
6
+ import { eq } from "drizzle-orm"
7
+ import { EventV2Bridge } from "@/event-v2-bridge"
8
+ import { expect } from "bun:test"
9
+ import { Cause, Deferred, Duration, Effect, Exit, Fiber, Layer } from "effect"
10
+ import path from "path"
11
+ import { fileURLToPath } from "url"
12
+ import { NamedError } from "@ac/core/util/error"
13
+ import { Agent as AgentSvc } from "../../src/agent/agent"
14
+ import { BackgroundJob } from "@/background/job"
15
+ import { Command } from "../../src/command"
16
+ import { Config } from "@/config/config"
17
+ import { LSP } from "@/lsp/lsp"
18
+ import { MCP } from "../../src/mcp"
19
+ import { Permission } from "../../src/permission"
20
+ import { Plugin } from "../../src/plugin"
21
+ import { Provider as ProviderSvc } from "@/provider/provider"
22
+ import { Env } from "../../src/env"
23
+ import { Git } from "../../src/git"
24
+ import { Image } from "../../src/image/image"
25
+
26
+ import { Question } from "../../src/question"
27
+ import { Todo } from "../../src/session/todo"
28
+ import { Session } from "@/session/session"
29
+ import { SessionMessageTable } from "@ac/core/session/sql"
30
+ import { LLM } from "../../src/session/llm"
31
+ import { MessageV2 } from "../../src/session/message-v2"
32
+ import { FSUtil } from "@ac/core/fs-util"
33
+ import { SessionCompaction } from "../../src/session/compaction"
34
+ import { SessionSummary } from "../../src/session/summary"
35
+ import { Instruction } from "../../src/session/instruction"
36
+ import { SessionProcessor } from "../../src/session/processor"
37
+ import { SessionPrompt } from "../../src/session/prompt"
38
+ import { SessionRevert } from "../../src/session/revert"
39
+ import { SessionRunState } from "../../src/session/run-state"
40
+ import { MessageID, PartID, SessionID } from "../../src/session/schema"
41
+ import { SessionStatus } from "../../src/session/status"
42
+ import { SessionV2 } from "@ac/core/session"
43
+ import { SessionExecution } from "@ac/core/session/execution"
44
+ import { Skill } from "../../src/skill"
45
+ import { SystemPrompt } from "../../src/session/system"
46
+ import { Shell } from "@ac/core/shell"
47
+ import { Snapshot } from "../../src/snapshot"
48
+ import { ToolRegistry } from "@/tool/registry"
49
+ import { Truncate } from "@/tool/truncate"
50
+ import { CrossSpawnSpawner } from "@ac/core/cross-spawn-spawner"
51
+ import { Ripgrep } from "@ac/core/ripgrep"
52
+ import { Format } from "../../src/format"
53
+ import { TestInstance } from "../fixture/fixture"
54
+ import { awaitWithTimeout, pollWithTimeout, testEffect } from "../lib/effect"
55
+ import { reply, TestLLMServer } from "../lib/llm-server"
56
+ import { RuntimeFlags } from "@/effect/runtime-flags"
57
+ import { ProviderV2 } from "@ac/core/provider"
58
+ import { ModelV2 } from "@ac/core/model"
59
+ import { LocationServiceMap, locationServiceMapLayer } from "@ac/core/location-services"
60
+
61
+ const summary = Layer.succeed(
62
+ SessionSummary.Service,
63
+ SessionSummary.Service.of({
64
+ summarize: () => Effect.void,
65
+ diff: () => Effect.succeed([]),
66
+ computeDiff: () => Effect.succeed([]),
67
+ }),
68
+ )
69
+
70
+ const ref = {
71
+ providerID: ProviderV2.ID.make("test"),
72
+ modelID: ModelV2.ID.make("test-model"),
73
+ }
74
+
75
+ function withSh<A, E, R>(fx: () => Effect.Effect<A, E, R>) {
76
+ return Effect.acquireUseRelease(
77
+ Effect.sync(() => {
78
+ const prev = process.env.SHELL
79
+ process.env.SHELL = "/bin/sh"
80
+ Shell.preferred.reset()
81
+ return prev
82
+ }),
83
+ () => fx(),
84
+ (prev) =>
85
+ Effect.sync(() => {
86
+ if (prev === undefined) delete process.env.SHELL
87
+ else process.env.SHELL = prev
88
+ Shell.preferred.reset()
89
+ }),
90
+ )
91
+ }
92
+
93
+ function toolPart(parts: SessionV1.Part[]) {
94
+ return parts.find((part): part is SessionV1.ToolPart => part.type === "tool")
95
+ }
96
+
97
+ type CompletedToolPart = SessionV1.ToolPart & { state: SessionV1.ToolStateCompleted }
98
+ type ErrorToolPart = SessionV1.ToolPart & { state: SessionV1.ToolStateError }
99
+
100
+ function completedTool(parts: SessionV1.Part[]) {
101
+ const part = toolPart(parts)
102
+ expect(part?.state.status).toBe("completed")
103
+ return part?.state.status === "completed" ? (part as CompletedToolPart) : undefined
104
+ }
105
+
106
+ function errorTool(parts: SessionV1.Part[]) {
107
+ const part = toolPart(parts)
108
+ expect(part?.state.status).toBe("error")
109
+ return part?.state.status === "error" ? (part as ErrorToolPart) : undefined
110
+ }
111
+
112
+ function makeMcp(instructions: MCP.ServerInstructions[] = []) {
113
+ return Layer.succeed(
114
+ MCP.Service,
115
+ MCP.Service.of({
116
+ status: () => Effect.succeed({}),
117
+ clients: () => Effect.succeed({}),
118
+ instructions: () => Effect.succeed(instructions),
119
+ tools: () => Effect.succeed({}),
120
+ prompts: () => Effect.succeed({}),
121
+ resources: () => Effect.succeed({}),
122
+ resourceTemplates: () => Effect.succeed({}),
123
+ add: () => Effect.succeed({ status: { status: "disabled" as const } }),
124
+ connect: () => Effect.void,
125
+ disconnect: () => Effect.void,
126
+ getPrompt: () => Effect.succeed(undefined),
127
+ readResource: () => Effect.succeed(undefined),
128
+ startAuth: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
129
+ authenticate: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
130
+ finishAuth: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
131
+ removeAuth: () => Effect.void,
132
+ supportsOAuth: () => Effect.succeed(false),
133
+ hasStoredTokens: () => Effect.succeed(false),
134
+ getAuthStatus: () => Effect.succeed("not_authenticated" as const),
135
+ }),
136
+ )
137
+ }
138
+
139
+ const lsp = Layer.succeed(
140
+ LSP.Service,
141
+ LSP.Service.of({
142
+ init: () => Effect.void,
143
+ status: () => Effect.succeed([]),
144
+ hasClients: () => Effect.succeed(false),
145
+ touchFile: () => Effect.void,
146
+ diagnostics: () => Effect.succeed({}),
147
+ hover: () => Effect.succeed(undefined),
148
+ definition: () => Effect.succeed([]),
149
+ references: () => Effect.succeed([]),
150
+ implementation: () => Effect.succeed([]),
151
+ documentSymbol: () => Effect.succeed([]),
152
+ workspaceSymbol: () => Effect.succeed([]),
153
+ prepareCallHierarchy: () => Effect.succeed([]),
154
+ incomingCalls: () => Effect.succeed([]),
155
+ outgoingCalls: () => Effect.succeed([]),
156
+ }),
157
+ )
158
+
159
+ const processorCreateStarted: Array<() => void> = []
160
+ const blockingProcessor = Layer.succeed(
161
+ SessionProcessor.Service,
162
+ SessionProcessor.Service.of({
163
+ create: () => Effect.sync(() => processorCreateStarted.shift()?.()).pipe(Effect.andThen(Effect.never)),
164
+ }),
165
+ )
166
+
167
+ const runtimeFlags = RuntimeFlags.layer({ experimentalEventSystem: true })
168
+
169
+ const testLLMServerNode = LayerNode.make({ service: TestLLMServer, layer: TestLLMServer.layer, deps: [] })
170
+
171
+ const promptRoot = LayerNode.group([
172
+ SessionPrompt.node,
173
+ Session.node,
174
+ SessionProjector.node,
175
+ MessageV2.node,
176
+ Snapshot.node,
177
+ LLM.node,
178
+ Env.node,
179
+ AgentSvc.node,
180
+ Command.node,
181
+ Permission.node,
182
+ Plugin.node,
183
+ Config.node,
184
+ ProviderSvc.node,
185
+ LSP.node,
186
+ MCP.node,
187
+ FSUtil.node,
188
+ BackgroundJob.node,
189
+ SessionStatus.node,
190
+ SessionRunState.node,
191
+ Database.node,
192
+ EventV2Bridge.node,
193
+ Question.node,
194
+ Todo.node,
195
+ ToolRegistry.node,
196
+ Skill.node,
197
+ Git.node,
198
+ Ripgrep.node,
199
+ Format.node,
200
+ Truncate.node,
201
+ SessionProcessor.node,
202
+ Image.node,
203
+ SessionCompaction.node,
204
+ SessionRevert.node,
205
+ Instruction.node,
206
+ SystemPrompt.node,
207
+ CrossSpawnSpawner.node,
208
+ RuntimeFlags.node,
209
+ ])
210
+
211
+ function makePrompt(input?: { mcpInstructions?: MCP.ServerInstructions[]; processor?: "blocking" }) {
212
+ const replacements = [
213
+ [SessionSummary.node, summary],
214
+ [LSP.node, lsp],
215
+ [MCP.node, makeMcp(input?.mcpInstructions)],
216
+ [RuntimeFlags.node, runtimeFlags],
217
+ ] as const
218
+ if (input?.processor === "blocking") {
219
+ return LayerNode.compile(promptRoot, [...replacements, [SessionProcessor.node, blockingProcessor]])
220
+ }
221
+ return LayerNode.compile(promptRoot, replacements)
222
+ }
223
+
224
+ function makeHttp(input?: { mcpInstructions?: MCP.ServerInstructions[]; processor?: "blocking" }) {
225
+ const root = LayerNode.group([promptRoot, testLLMServerNode])
226
+ const replacements = [
227
+ [SessionSummary.node, summary],
228
+ [LSP.node, lsp],
229
+ [MCP.node, makeMcp(input?.mcpInstructions)],
230
+ [RuntimeFlags.node, runtimeFlags],
231
+ ] as const
232
+ if (input?.processor === "blocking") {
233
+ return LayerNode.compile(root, [...replacements, [SessionProcessor.node, blockingProcessor]])
234
+ }
235
+ return LayerNode.compile(root, replacements)
236
+ }
237
+
238
+ function makeHttpNoLLMServer(input?: { mcpInstructions?: MCP.ServerInstructions[]; processor?: "blocking" }) {
239
+ return makePrompt(input)
240
+ }
241
+
242
+ const it = testEffect(makeHttp())
243
+ const noLLMServer = testEffect(makeHttpNoLLMServer())
244
+ const raceNoLLMServer = testEffect(makeHttpNoLLMServer({ processor: "blocking" }))
245
+ const withMcpInstructions = testEffect(
246
+ makeHttp({
247
+ mcpInstructions: [
248
+ {
249
+ name: "guide-server",
250
+ instructions: "Use lookup before mutate.",
251
+ tools: ["guide-server_lookup"],
252
+ },
253
+ ],
254
+ }),
255
+ )
256
+ const unix = process.platform !== "win32" ? it.instance : it.instance.skip
257
+ const unixNoLLMServer = process.platform !== "win32" ? noLLMServer.instance : noLLMServer.instance.skip
258
+
259
+ // Config that registers a custom "test" provider with a "test-model" model
260
+ // so provider model lookup succeeds inside the loop.
261
+ const cfg = {
262
+ provider: {
263
+ test: {
264
+ name: "Test",
265
+ id: "test",
266
+ env: [],
267
+ npm: "@ai-sdk/openai-compatible",
268
+ models: {
269
+ "test-model": {
270
+ id: "test-model",
271
+ name: "Test Model",
272
+ attachment: false,
273
+ reasoning: false,
274
+ temperature: false,
275
+ tool_call: true,
276
+ release_date: "2025-01-01",
277
+ limit: { context: 100000, output: 10000 },
278
+ cost: { input: 0, output: 0 },
279
+ options: {},
280
+ },
281
+ },
282
+ options: {
283
+ apiKey: "test-key",
284
+ baseURL: "http://localhost:1/v1",
285
+ },
286
+ },
287
+ },
288
+ }
289
+
290
+ function providerCfg(url: string) {
291
+ return {
292
+ ...cfg,
293
+ provider: {
294
+ ...cfg.provider,
295
+ test: {
296
+ ...cfg.provider.test,
297
+ options: {
298
+ ...cfg.provider.test.options,
299
+ baseURL: url,
300
+ },
301
+ },
302
+ },
303
+ }
304
+ }
305
+
306
+ const writeText = Effect.fn("test.writeText")(function* (file: string, text: string) {
307
+ const fs = yield* FSUtil.Service
308
+ yield* fs.writeWithDirs(file, text)
309
+ })
310
+
311
+ const writeConfig = Effect.fn("test.writeConfig")(function* (dir: string, config: Partial<ConfigV1.Info>) {
312
+ yield* writeText(
313
+ path.join(dir, "opencode.json"),
314
+ JSON.stringify({ $schema: "https://artificialcode.dev/config.json", ...config }),
315
+ )
316
+ })
317
+
318
+ const useServerConfig = Effect.fn("test.useServerConfig")(function* (config: (url: string) => Partial<ConfigV1.Info>) {
319
+ const { directory: dir } = yield* TestInstance
320
+ const llm = yield* TestLLMServer
321
+ yield* writeConfig(dir, config(llm.url))
322
+ return { dir, llm }
323
+ })
324
+
325
+ // Wait for a session's runner to enter a busy state. SessionStatus is flipped
326
+ // inside Runner.startShell's serialized transition, so cancel can't no-op once
327
+ // we observe it.
328
+ const waitForBusy = (sessionID: SessionID, duration: Duration.Input = "2 seconds") =>
329
+ pollWithTimeout(
330
+ Effect.gen(function* () {
331
+ const status = yield* SessionStatus.Service
332
+ const s = yield* status.get(sessionID)
333
+ return s.type === "busy" ? (true as const) : undefined
334
+ }),
335
+ `session ${sessionID} never became busy`,
336
+ duration,
337
+ )
338
+
339
+ const hasBash = Effect.sync(() => Bun.which("bash") !== null)
340
+
341
+ const deferredAsPromise = <A>(deferred: Deferred.Deferred<A>): PromiseLike<A> => ({
342
+ then: (onfulfilled, onrejected) => {
343
+ Effect.runFork(
344
+ Deferred.await(deferred).pipe(
345
+ Effect.match({
346
+ onFailure: (error) => {
347
+ onrejected?.(error)
348
+ },
349
+ onSuccess: (value) => {
350
+ onfulfilled?.(value)
351
+ },
352
+ }),
353
+ ),
354
+ )
355
+ return deferredAsPromise(deferred) as PromiseLike<never>
356
+ },
357
+ })
358
+
359
+ function defer<T>() {
360
+ let resolve!: (value: T | PromiseLike<T>) => void
361
+ const promise = new Promise<T>((done) => {
362
+ resolve = done
363
+ })
364
+ return { promise, resolve }
365
+ }
366
+
367
+ const succeedVoid = (deferred: Deferred.Deferred<void>) => {
368
+ Effect.runSync(Deferred.succeed(deferred, void 0).pipe(Effect.ignore))
369
+ }
370
+
371
+ const user = Effect.fn("test.user")(function* (sessionID: SessionID, text: string) {
372
+ const session = yield* Session.Service
373
+ const msg = yield* session.updateMessage({
374
+ id: MessageID.ascending(),
375
+ role: "user",
376
+ sessionID,
377
+ agent: "build",
378
+ model: ref,
379
+ time: { created: Date.now() },
380
+ })
381
+ yield* session.updatePart({
382
+ id: PartID.ascending(),
383
+ messageID: msg.id,
384
+ sessionID,
385
+ type: "text",
386
+ text,
387
+ })
388
+ return msg
389
+ })
390
+
391
+ const seed = Effect.fn("test.seed")(function* (sessionID: SessionID, opts?: { finish?: string }) {
392
+ const session = yield* Session.Service
393
+ const msg = yield* user(sessionID, "hello")
394
+ const assistant: SessionV1.Assistant = {
395
+ id: MessageID.ascending(),
396
+ role: "assistant",
397
+ parentID: msg.id,
398
+ sessionID,
399
+ mode: "build",
400
+ agent: "build",
401
+ cost: 0,
402
+ path: { cwd: "/tmp", root: "/tmp" },
403
+ tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
404
+ modelID: ref.modelID,
405
+ providerID: ref.providerID,
406
+ time: { created: Date.now() },
407
+ ...(opts?.finish ? { finish: opts.finish } : {}),
408
+ }
409
+ yield* session.updateMessage(assistant)
410
+ yield* session.updatePart({
411
+ id: PartID.ascending(),
412
+ messageID: assistant.id,
413
+ sessionID,
414
+ type: "text",
415
+ text: "hi there",
416
+ })
417
+ return { user: msg, assistant }
418
+ })
419
+
420
+ const addSubtask = (sessionID: SessionID, messageID: MessageID, model = ref) =>
421
+ Effect.gen(function* () {
422
+ const session = yield* Session.Service
423
+ yield* session.updatePart({
424
+ id: PartID.ascending(),
425
+ messageID,
426
+ sessionID,
427
+ type: "subtask",
428
+ prompt: "look into the cache key path",
429
+ description: "inspect bug",
430
+ agent: "general",
431
+ model,
432
+ })
433
+ })
434
+
435
+ const boot = Effect.fn("test.boot")(function* (input?: { title?: string }) {
436
+ const config = yield* Config.Service
437
+ const prompt = yield* SessionPrompt.Service
438
+ const run = yield* SessionRunState.Service
439
+ const sessions = yield* Session.Service
440
+ yield* config.get()
441
+ const chat = yield* sessions.create(input ?? { title: "Pinned" })
442
+ return { prompt, run, sessions, chat }
443
+ })
444
+
445
+ // Loop semantics
446
+
447
+ noLLMServer.instance(
448
+ "loop exits immediately when last assistant has stop finish",
449
+ () =>
450
+ Effect.gen(function* () {
451
+ const prompt = yield* SessionPrompt.Service
452
+ const sessions = yield* Session.Service
453
+ const chat = yield* sessions.create({ title: "Pinned" })
454
+ yield* seed(chat.id, { finish: "stop" })
455
+
456
+ const result = yield* prompt.loop({ sessionID: chat.id })
457
+ expect(result.info.role).toBe("assistant")
458
+ if (result.info.role === "assistant") expect(result.info.finish).toBe("stop")
459
+ }),
460
+ { config: cfg },
461
+ )
462
+
463
+ it.instance("loop exits without an LLM request for interrupted orphan tool calls", () =>
464
+ Effect.gen(function* () {
465
+ const { llm } = yield* useServerConfig(providerCfg)
466
+ const prompt = yield* SessionPrompt.Service
467
+ const sessions = yield* Session.Service
468
+ const chat = yield* sessions.create({ title: "Pinned" })
469
+ const seeded = yield* seed(chat.id, { finish: "stop" })
470
+ yield* sessions.updatePart({
471
+ id: PartID.ascending(),
472
+ messageID: seeded.assistant.id,
473
+ sessionID: chat.id,
474
+ type: "tool",
475
+ callID: "interrupted-call",
476
+ tool: "edit",
477
+ state: {
478
+ status: "error",
479
+ input: {},
480
+ error: "Tool execution aborted",
481
+ metadata: { interrupted: true },
482
+ time: { start: 1, end: 2 },
483
+ },
484
+ })
485
+
486
+ const result = yield* prompt.loop({ sessionID: chat.id })
487
+ expect(result.info.id).toBe(seeded.assistant.id)
488
+ expect(yield* llm.hits).toHaveLength(0)
489
+ }),
490
+ )
491
+
492
+ it.instance("loop calls LLM and returns assistant message", () =>
493
+ Effect.gen(function* () {
494
+ const { llm } = yield* useServerConfig(providerCfg)
495
+ const prompt = yield* SessionPrompt.Service
496
+ const sessions = yield* Session.Service
497
+ const chat = yield* sessions.create({
498
+ title: "Pinned",
499
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
500
+ })
501
+ yield* prompt.prompt({
502
+ sessionID: chat.id,
503
+ agent: "build",
504
+ noReply: true,
505
+ parts: [{ type: "text", text: "hello" }],
506
+ })
507
+ yield* llm.text("world")
508
+
509
+ const result = yield* prompt.loop({ sessionID: chat.id })
510
+ expect(result.info.role).toBe("assistant")
511
+ const parts = result.parts.filter((p) => p.type === "text")
512
+ expect(parts.some((p) => p.type === "text" && p.text === "world")).toBe(true)
513
+ expect(yield* llm.hits).toHaveLength(1)
514
+ }),
515
+ )
516
+
517
+ withMcpInstructions.instance(
518
+ "loop includes MCP instructions in model system context",
519
+ () =>
520
+ Effect.gen(function* () {
521
+ const { llm } = yield* useServerConfig(providerCfg)
522
+ const prompt = yield* SessionPrompt.Service
523
+ const sessions = yield* Session.Service
524
+ const chat = yield* sessions.create({
525
+ title: "Pinned",
526
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
527
+ })
528
+ yield* llm.hang
529
+ yield* user(chat.id, "hello")
530
+
531
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
532
+ yield* awaitWithTimeout(llm.wait(1), "timed out waiting for MCP instruction request", "10 seconds")
533
+
534
+ const hits = yield* llm.hits
535
+ const body = JSON.stringify(hits[0]?.body)
536
+ expect(body).toContain('<server name=\\"guide-server\\">')
537
+ expect(body).toContain("Use lookup before mutate.")
538
+ yield* Fiber.interrupt(fiber)
539
+ }),
540
+ 15_000,
541
+ )
542
+
543
+ it.instance("legacy prompt emits message events without session.next events", () =>
544
+ Effect.gen(function* () {
545
+ const events = yield* EventV2Bridge.Service
546
+ const prompt = yield* SessionPrompt.Service
547
+ const sessions = yield* Session.Service
548
+ const chat = yield* sessions.create({
549
+ title: "Pinned",
550
+ agent: "plan",
551
+ model: { providerID: ProviderV2.ID.make("old"), id: ModelV2.ID.make("old-model") },
552
+ })
553
+ const seen: string[] = []
554
+ const off = yield* events.listen((event) => {
555
+ seen.push(event.type)
556
+ return Effect.void
557
+ })
558
+
559
+ const first = yield* prompt.prompt({
560
+ sessionID: chat.id,
561
+ agent: "build",
562
+ model: ref,
563
+ noReply: true,
564
+ parts: [{ type: "text", text: "hello" }],
565
+ })
566
+ const second = yield* prompt.prompt({
567
+ sessionID: chat.id,
568
+ agent: "build",
569
+ noReply: true,
570
+ parts: [{ type: "text", text: "again" }],
571
+ })
572
+ yield* off
573
+
574
+ expect(first.info.role).toBe("user")
575
+ expect(second.info.role).toBe("user")
576
+ if (first.info.role === "user" && second.info.role === "user") {
577
+ expect(first.info.model).toEqual(ref)
578
+ expect(second.info.model).toEqual(ref)
579
+ }
580
+ expect(yield* sessions.get(chat.id)).toMatchObject({
581
+ agent: "build",
582
+ model: { providerID: ref.providerID, id: ref.modelID },
583
+ })
584
+ expect(seen).toContain(Session.Event.Updated.type)
585
+ expect(seen).toContain(MessageV2.Event.Updated.type)
586
+ expect(seen).toContain(MessageV2.Event.PartUpdated.type)
587
+ expect(seen.filter((type) => type.startsWith("session.next."))).toEqual([])
588
+ }),
589
+ )
590
+
591
+ it.instance("loop surfaces content-filter finishes as session errors", () =>
592
+ Effect.gen(function* () {
593
+ const { llm } = yield* useServerConfig(providerCfg)
594
+ const events = yield* EventV2Bridge.Service
595
+ const prompt = yield* SessionPrompt.Service
596
+ const sessions = yield* Session.Service
597
+ const chat = yield* sessions.create({ title: "Pinned" })
598
+ const errors: NonNullable<SessionV1.Assistant["error"]>[] = []
599
+ const expected = {
600
+ name: "ContentFilterError",
601
+ data: { message: "The response was blocked by the provider's content filter" },
602
+ } satisfies NonNullable<SessionV1.Assistant["error"]>
603
+ const off = yield* events.listen((event) => {
604
+ if (event.type !== Session.Event.Error.type) return Effect.void
605
+ const data = event.data as typeof Session.Event.Error.data.Type
606
+ if (data.sessionID === chat.id && data.error) errors.push(data.error)
607
+ return Effect.void
608
+ })
609
+
610
+ yield* prompt.prompt({
611
+ sessionID: chat.id,
612
+ agent: "build",
613
+ noReply: true,
614
+ parts: [{ type: "text", text: "hello" }],
615
+ })
616
+ yield* llm.push(reply().text("partial response").contentFilter())
617
+
618
+ const result = yield* prompt.loop({ sessionID: chat.id })
619
+ const stored = yield* MessageV2.get({ sessionID: chat.id, messageID: result.info.id })
620
+ yield* off
621
+
622
+ expect(yield* llm.hits).toHaveLength(1)
623
+ expect(result.info.role).toBe("assistant")
624
+ expect(stored.info.role).toBe("assistant")
625
+ if (result.info.role === "assistant" && stored.info.role === "assistant") {
626
+ expect(result.info.finish).toBe("content-filter")
627
+ expect(result.info.error).toEqual(expected)
628
+ expect(stored.info.error).toEqual(result.info.error)
629
+ expect(errors).toContainEqual(expected)
630
+ }
631
+ expect(result.parts).toEqual(
632
+ expect.arrayContaining([expect.objectContaining({ type: "text", text: "partial response" })]),
633
+ )
634
+ }),
635
+ )
636
+
637
+ it.instance("loop stops provider overflow instead of auto-compacting when disabled", () =>
638
+ Effect.gen(function* () {
639
+ const { llm } = yield* useServerConfig((url) => ({
640
+ ...providerCfg(url),
641
+ compaction: { auto: false },
642
+ }))
643
+ const prompt = yield* SessionPrompt.Service
644
+ const sessions = yield* Session.Service
645
+ const chat = yield* sessions.create({ title: "Pinned" })
646
+
647
+ yield* llm.error(413, { error: { message: "request entity too large" } })
648
+ yield* prompt.prompt({
649
+ sessionID: chat.id,
650
+ agent: "build",
651
+ noReply: true,
652
+ parts: [{ type: "text", text: "hello" }],
653
+ })
654
+
655
+ const result = yield* prompt.loop({ sessionID: chat.id })
656
+ const messages = yield* sessions.messages({ sessionID: chat.id })
657
+
658
+ expect(result.info.role).toBe("assistant")
659
+ if (result.info.role === "assistant") {
660
+ expect(result.info.error?.name).toBe("ContextOverflowError")
661
+ expect(result.info.finish).toBe("error")
662
+ }
663
+ expect(messages.some((message) => message.parts.some((part) => part.type === "compaction"))).toBe(false)
664
+ }),
665
+ )
666
+
667
+ noLLMServer.instance.skip(
668
+ "prompt emits v2 prompted and synthetic events (v2 projector disabled)",
669
+ () =>
670
+ Effect.gen(function* () {
671
+ const prompt = yield* SessionPrompt.Service
672
+ const sessions = yield* Session.Service
673
+ const chat = yield* sessions.create({ title: "Pinned" })
674
+
675
+ yield* prompt.prompt({
676
+ sessionID: chat.id,
677
+ agent: "build",
678
+ noReply: true,
679
+ parts: [
680
+ { type: "text", text: "hello v2" },
681
+ {
682
+ type: "file",
683
+ mime: "text/plain",
684
+ filename: "note.txt",
685
+ url: "data:text/plain;base64,bm90ZSBjb250ZW50",
686
+ },
687
+ ],
688
+ })
689
+
690
+ const messages = yield* SessionV2.Service.use((session) => session.messages({ sessionID: chat.id })).pipe(
691
+ Effect.provide(
692
+ LayerNode.compile(SessionV2.node, [
693
+ [SessionExecution.node, SessionExecution.noopLayer],
694
+ [LocationServiceMap.node, locationServiceMapLayer],
695
+ ]),
696
+ ),
697
+ )
698
+ const { db } = yield* Database.Service
699
+ const row = yield* db
700
+ .select()
701
+ .from(SessionMessageTable)
702
+ .where(eq(SessionMessageTable.session_id, chat.id))
703
+ .get()
704
+ .pipe(Effect.orDie)
705
+ expect(messages.find((message) => message.type === "user")).toMatchObject({ type: "user", text: "hello v2" })
706
+ expect(typeof row?.data.time.created).toBe("number")
707
+ expect(messages).toEqual(
708
+ expect.arrayContaining([
709
+ expect.objectContaining({ type: "synthetic", text: expect.stringContaining("Called the Read tool") }),
710
+ expect.objectContaining({ type: "synthetic", text: "note content" }),
711
+ ]),
712
+ )
713
+ }),
714
+ { config: cfg },
715
+ )
716
+
717
+ it.instance("static loop returns assistant text through local provider", () =>
718
+ Effect.gen(function* () {
719
+ const { llm } = yield* useServerConfig(providerCfg)
720
+ const prompt = yield* SessionPrompt.Service
721
+ const sessions = yield* Session.Service
722
+ const session = yield* sessions.create({
723
+ title: "Prompt provider",
724
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
725
+ })
726
+
727
+ yield* prompt.prompt({
728
+ sessionID: session.id,
729
+ agent: "build",
730
+ noReply: true,
731
+ parts: [{ type: "text", text: "hello" }],
732
+ })
733
+
734
+ yield* llm.text("world")
735
+
736
+ const result = yield* prompt.loop({ sessionID: session.id })
737
+ expect(result.info.role).toBe("assistant")
738
+ expect(result.parts.some((part) => part.type === "text" && part.text === "world")).toBe(true)
739
+ expect(yield* llm.hits).toHaveLength(1)
740
+ expect(yield* llm.pending).toBe(0)
741
+ }),
742
+ )
743
+
744
+ it.instance("static loop consumes queued replies across turns", () =>
745
+ Effect.gen(function* () {
746
+ const { llm } = yield* useServerConfig(providerCfg)
747
+ const prompt = yield* SessionPrompt.Service
748
+ const sessions = yield* Session.Service
749
+ const session = yield* sessions.create({
750
+ title: "Prompt provider turns",
751
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
752
+ })
753
+
754
+ yield* prompt.prompt({
755
+ sessionID: session.id,
756
+ agent: "build",
757
+ noReply: true,
758
+ parts: [{ type: "text", text: "hello one" }],
759
+ })
760
+
761
+ yield* llm.text("world one")
762
+
763
+ const first = yield* prompt.loop({ sessionID: session.id })
764
+ expect(first.info.role).toBe("assistant")
765
+ expect(first.parts.some((part) => part.type === "text" && part.text === "world one")).toBe(true)
766
+
767
+ yield* prompt.prompt({
768
+ sessionID: session.id,
769
+ agent: "build",
770
+ noReply: true,
771
+ parts: [{ type: "text", text: "hello two" }],
772
+ })
773
+
774
+ yield* llm.text("world two")
775
+
776
+ const second = yield* prompt.loop({ sessionID: session.id })
777
+ expect(second.info.role).toBe("assistant")
778
+ expect(second.parts.some((part) => part.type === "text" && part.text === "world two")).toBe(true)
779
+
780
+ expect(yield* llm.hits).toHaveLength(2)
781
+ expect(yield* llm.pending).toBe(0)
782
+ }),
783
+ )
784
+
785
+ it.instance("loop continues when finish is tool-calls", () =>
786
+ Effect.gen(function* () {
787
+ const { llm } = yield* useServerConfig(providerCfg)
788
+ const prompt = yield* SessionPrompt.Service
789
+ const sessions = yield* Session.Service
790
+ const session = yield* sessions.create({
791
+ title: "Pinned",
792
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
793
+ })
794
+ yield* prompt.prompt({
795
+ sessionID: session.id,
796
+ agent: "build",
797
+ noReply: true,
798
+ parts: [{ type: "text", text: "hello" }],
799
+ })
800
+ yield* llm.tool("first", { value: "first" })
801
+ yield* llm.text("second")
802
+
803
+ const result = yield* prompt.loop({ sessionID: session.id })
804
+ expect(yield* llm.calls).toBe(2)
805
+ expect(result.info.role).toBe("assistant")
806
+ if (result.info.role === "assistant") {
807
+ expect(result.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
808
+ expect(result.info.finish).toBe("stop")
809
+ }
810
+ }),
811
+ )
812
+
813
+ it.instance("glob tool keeps instance context during prompt runs", () =>
814
+ Effect.gen(function* () {
815
+ const { dir, llm } = yield* useServerConfig(providerCfg)
816
+ const prompt = yield* SessionPrompt.Service
817
+ const sessions = yield* Session.Service
818
+ const session = yield* sessions.create({
819
+ title: "Glob context",
820
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
821
+ })
822
+ const file = path.join(dir, "probe.txt")
823
+ yield* writeText(file, "probe")
824
+
825
+ yield* prompt.prompt({
826
+ sessionID: session.id,
827
+ agent: "build",
828
+ noReply: true,
829
+ parts: [{ type: "text", text: "find text files" }],
830
+ })
831
+ yield* llm.tool("glob", { pattern: "**/*.txt" })
832
+ yield* llm.text("done")
833
+
834
+ const result = yield* prompt.loop({ sessionID: session.id })
835
+ expect(result.info.role).toBe("assistant")
836
+
837
+ const msgs = yield* MessageV2.filterCompactedEffect(session.id)
838
+ const tool = msgs
839
+ .flatMap((msg) => msg.parts)
840
+ .find(
841
+ (part): part is CompletedToolPart =>
842
+ part.type === "tool" && part.tool === "glob" && part.state.status === "completed",
843
+ )
844
+ if (!tool) return
845
+
846
+ expect(tool.state.output).toContain(file)
847
+ expect(tool.state.output).not.toContain("No context found for instance")
848
+ expect(result.parts.some((part) => part.type === "text" && part.text === "done")).toBe(true)
849
+ }),
850
+ )
851
+
852
+ it.instance("loop continues when finish is stop but assistant has tool parts", () =>
853
+ Effect.gen(function* () {
854
+ const { llm } = yield* useServerConfig(providerCfg)
855
+ const prompt = yield* SessionPrompt.Service
856
+ const sessions = yield* Session.Service
857
+ const session = yield* sessions.create({
858
+ title: "Pinned",
859
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
860
+ })
861
+ yield* prompt.prompt({
862
+ sessionID: session.id,
863
+ agent: "build",
864
+ noReply: true,
865
+ parts: [{ type: "text", text: "hello" }],
866
+ })
867
+ yield* llm.push(reply().tool("first", { value: "first" }).stop())
868
+ yield* llm.text("second")
869
+
870
+ const result = yield* prompt.loop({ sessionID: session.id })
871
+ expect(yield* llm.calls).toBe(2)
872
+ expect(result.info.role).toBe("assistant")
873
+ if (result.info.role === "assistant") {
874
+ expect(result.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
875
+ expect(result.info.finish).toBe("stop")
876
+ }
877
+ }),
878
+ )
879
+
880
+ it.instance("failed subtask preserves metadata on error tool state", () =>
881
+ Effect.gen(function* () {
882
+ const { llm } = yield* useServerConfig((url) => ({
883
+ ...providerCfg(url),
884
+ agent: {
885
+ general: {
886
+ model: "test/missing-model",
887
+ },
888
+ },
889
+ }))
890
+ const prompt = yield* SessionPrompt.Service
891
+ const sessions = yield* Session.Service
892
+ const chat = yield* sessions.create({ title: "Pinned" })
893
+ yield* llm.tool("task", {
894
+ description: "inspect bug",
895
+ prompt: "look into the cache key path",
896
+ subagent_type: "general",
897
+ })
898
+ yield* llm.text("done")
899
+ const msg = yield* user(chat.id, "hello")
900
+ yield* addSubtask(chat.id, msg.id)
901
+
902
+ const result = yield* prompt.loop({ sessionID: chat.id })
903
+ expect(result.info.role).toBe("assistant")
904
+ expect(yield* llm.calls).toBe(2)
905
+
906
+ const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
907
+ const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
908
+ expect(taskMsg?.info.role).toBe("assistant")
909
+ if (!taskMsg || taskMsg.info.role !== "assistant") return
910
+
911
+ const tool = errorTool(taskMsg.parts)
912
+ if (!tool) return
913
+
914
+ expect(tool.state.error).toContain("Tool execution failed")
915
+ expect(tool.state.metadata).toBeDefined()
916
+ expect(tool.state.metadata?.sessionId).toBeDefined()
917
+ expect(tool.state.metadata?.model).toEqual({
918
+ providerID: ProviderV2.ID.make("test"),
919
+ modelID: ModelV2.ID.make("missing-model"),
920
+ })
921
+ }),
922
+ )
923
+
924
+ it.instance("subtask child inherits parent session external_directory allow", () =>
925
+ Effect.gen(function* () {
926
+ const { llm } = yield* useServerConfig(providerCfg)
927
+ const prompt = yield* SessionPrompt.Service
928
+ const sessions = yield* Session.Service
929
+ const chat = yield* sessions.create({
930
+ title: "Parent",
931
+ permission: [{ permission: "external_directory", pattern: "/tmp/allowed/*", action: "allow" }],
932
+ })
933
+ yield* llm.text("done")
934
+ const msg = yield* user(chat.id, "hello")
935
+ yield* addSubtask(chat.id, msg.id)
936
+
937
+ yield* prompt.loop({ sessionID: chat.id })
938
+
939
+ const kids = yield* sessions.children(chat.id)
940
+ expect(kids).toHaveLength(1)
941
+ const child = kids[0]!
942
+ const rules = child.permission ?? []
943
+ expect(rules).toEqual(
944
+ expect.arrayContaining([{ permission: "external_directory", pattern: "/tmp/allowed/*", action: "allow" }]),
945
+ )
946
+ expect(Permission.evaluate("external_directory", "/tmp/allowed/file", rules).action).toBe("allow")
947
+ expect(Permission.evaluate("task", "anything", rules).action).toBe("deny")
948
+ }),
949
+ )
950
+
951
+ noLLMServer.instance("prompt tools replace previous prompt tool rules", () =>
952
+ Effect.gen(function* () {
953
+ const prompt = yield* SessionPrompt.Service
954
+ const sessions = yield* Session.Service
955
+ const session = yield* sessions.create({ title: "Prompt tools" })
956
+
957
+ yield* prompt.prompt({
958
+ sessionID: session.id,
959
+ agent: "build",
960
+ noReply: true,
961
+ tools: { bash: false },
962
+ parts: [{ type: "text", text: "first" }],
963
+ })
964
+ yield* prompt.prompt({
965
+ sessionID: session.id,
966
+ agent: "build",
967
+ noReply: true,
968
+ tools: { read: true },
969
+ parts: [{ type: "text", text: "second" }],
970
+ })
971
+
972
+ const reloaded = yield* sessions.get(session.id)
973
+ expect(reloaded.permission).toEqual([{ permission: "read", pattern: "*", action: "allow" }])
974
+ expect(Permission.evaluate("bash", "anything", reloaded.permission ?? []).action).toBe("ask")
975
+ }),
976
+ )
977
+
978
+ it.instance(
979
+ "running subtask preserves metadata after tool-call transition",
980
+ () =>
981
+ Effect.gen(function* () {
982
+ const { llm } = yield* useServerConfig(providerCfg)
983
+ const prompt = yield* SessionPrompt.Service
984
+ const sessions = yield* Session.Service
985
+ const chat = yield* sessions.create({ title: "Pinned" })
986
+ yield* llm.hang
987
+ const msg = yield* user(chat.id, "hello")
988
+ yield* addSubtask(chat.id, msg.id)
989
+
990
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
991
+
992
+ const tool = yield* pollWithTimeout(
993
+ Effect.gen(function* () {
994
+ const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
995
+ const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
996
+ const tool = taskMsg?.parts.find((part): part is SessionV1.ToolPart => part.type === "tool")
997
+ if (tool?.state.status === "running" && tool.state.metadata?.sessionId) return tool
998
+ }),
999
+ "timed out waiting for running subtask metadata",
1000
+ )
1001
+
1002
+ if (tool.state.status !== "running") return
1003
+ expect(typeof tool.state.metadata?.sessionId).toBe("string")
1004
+ expect(tool.state.title).toBeDefined()
1005
+ expect(tool.state.metadata?.model).toBeDefined()
1006
+
1007
+ yield* prompt.cancel(chat.id)
1008
+ yield* Fiber.await(fiber)
1009
+ }),
1010
+ 5_000,
1011
+ )
1012
+
1013
+ it.instance(
1014
+ "running task tool preserves metadata after tool-call transition",
1015
+ () =>
1016
+ Effect.gen(function* () {
1017
+ const { llm } = yield* useServerConfig(providerCfg)
1018
+ const prompt = yield* SessionPrompt.Service
1019
+ const sessions = yield* Session.Service
1020
+ const chat = yield* sessions.create({
1021
+ title: "Pinned",
1022
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
1023
+ })
1024
+ yield* llm.tool("task", {
1025
+ description: "inspect bug",
1026
+ prompt: "look into the cache key path",
1027
+ subagent_type: "general",
1028
+ })
1029
+ yield* llm.hang
1030
+ yield* user(chat.id, "hello")
1031
+
1032
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1033
+
1034
+ const tool = yield* pollWithTimeout(
1035
+ Effect.gen(function* () {
1036
+ const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
1037
+ const assistant = msgs.findLast((item) => item.info.role === "assistant" && item.info.agent === "build")
1038
+ const tool = assistant?.parts.find(
1039
+ (part): part is SessionV1.ToolPart => part.type === "tool" && part.tool === "task",
1040
+ )
1041
+ if (tool?.state.status === "running" && tool.state.metadata?.sessionId) return tool
1042
+ }),
1043
+ "timed out waiting for running task metadata",
1044
+ )
1045
+
1046
+ if (tool.state.status !== "running") return
1047
+ expect(typeof tool.state.metadata?.sessionId).toBe("string")
1048
+ expect(tool.state.title).toBe("inspect bug")
1049
+ expect(tool.state.metadata?.model).toBeDefined()
1050
+
1051
+ yield* prompt.cancel(chat.id)
1052
+ yield* Fiber.await(fiber)
1053
+ }),
1054
+ 10_000,
1055
+ )
1056
+
1057
+ it.instance(
1058
+ "loop sets status to busy then idle",
1059
+ () =>
1060
+ Effect.gen(function* () {
1061
+ const { llm } = yield* useServerConfig(providerCfg)
1062
+ const prompt = yield* SessionPrompt.Service
1063
+ const sessions = yield* Session.Service
1064
+ const status = yield* SessionStatus.Service
1065
+
1066
+ yield* llm.hang
1067
+
1068
+ const chat = yield* sessions.create({})
1069
+ yield* user(chat.id, "hi")
1070
+
1071
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1072
+ yield* llm.wait(1)
1073
+ expect((yield* status.get(chat.id)).type).toBe("busy")
1074
+ yield* prompt.cancel(chat.id)
1075
+ yield* Fiber.await(fiber)
1076
+ expect((yield* status.get(chat.id)).type).toBe("idle")
1077
+ }),
1078
+ 3_000,
1079
+ )
1080
+
1081
+ // Cancel semantics
1082
+
1083
+ it.instance("cancel interrupts loop and resolves with an assistant message", () =>
1084
+ Effect.gen(function* () {
1085
+ const { llm } = yield* useServerConfig(providerCfg)
1086
+ const prompt = yield* SessionPrompt.Service
1087
+ const sessions = yield* Session.Service
1088
+ const chat = yield* sessions.create({ title: "Pinned" })
1089
+ yield* seed(chat.id)
1090
+
1091
+ yield* llm.hang
1092
+
1093
+ yield* user(chat.id, "more")
1094
+
1095
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1096
+ yield* llm.wait(1)
1097
+ yield* waitForBusy(chat.id)
1098
+ yield* prompt.cancel(chat.id)
1099
+ const exit = yield* Fiber.await(fiber)
1100
+ expect(Exit.isSuccess(exit)).toBe(true)
1101
+ if (Exit.isSuccess(exit)) {
1102
+ expect(exit.value.info.role).toBe("assistant")
1103
+ }
1104
+ }),
1105
+ )
1106
+
1107
+ it.instance("cancel records MessageAbortedError on interrupted process", () =>
1108
+ Effect.gen(function* () {
1109
+ const { llm } = yield* useServerConfig(providerCfg)
1110
+ const prompt = yield* SessionPrompt.Service
1111
+ const sessions = yield* Session.Service
1112
+ const chat = yield* sessions.create({ title: "Pinned" })
1113
+ yield* llm.hang
1114
+ yield* user(chat.id, "hello")
1115
+
1116
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1117
+ yield* llm.wait(1)
1118
+ yield* waitForBusy(chat.id)
1119
+ yield* prompt.cancel(chat.id)
1120
+ const exit = yield* Fiber.await(fiber)
1121
+ expect(Exit.isSuccess(exit)).toBe(true)
1122
+ if (Exit.isSuccess(exit)) {
1123
+ const info = exit.value.info
1124
+ if (info.role === "assistant") {
1125
+ expect(info.error?.name).toBe("MessageAbortedError")
1126
+ }
1127
+ }
1128
+ }),
1129
+ )
1130
+
1131
+ raceNoLLMServer.instance(
1132
+ "finalizes assistant when cancelled before processor creation completes",
1133
+ () =>
1134
+ Effect.gen(function* () {
1135
+ processorCreateStarted.length = 0
1136
+ yield* Effect.addFinalizer(() =>
1137
+ Effect.sync(() => {
1138
+ processorCreateStarted.length = 0
1139
+ }),
1140
+ )
1141
+
1142
+ const prompt = yield* SessionPrompt.Service
1143
+ const sessions = yield* Session.Service
1144
+ const chat = yield* sessions.create({ title: "Processor creation race" })
1145
+
1146
+ yield* prompt.prompt({
1147
+ sessionID: chat.id,
1148
+ agent: "build",
1149
+ noReply: true,
1150
+ parts: [{ type: "text", text: "first" }],
1151
+ })
1152
+
1153
+ const firstCreate = defer<void>()
1154
+ processorCreateStarted.push(firstCreate.resolve)
1155
+ const first = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1156
+ yield* Effect.promise(() => firstCreate.promise)
1157
+
1158
+ yield* prompt.cancel(chat.id)
1159
+ const firstExit = yield* Fiber.await(first)
1160
+ expect(Exit.isSuccess(firstExit)).toBe(true)
1161
+
1162
+ let messages = yield* sessions.messages({ sessionID: chat.id })
1163
+ const firstInterrupted = messages.at(-1)
1164
+ expect(firstInterrupted?.info.role).toBe("assistant")
1165
+ expect(firstInterrupted?.parts).toHaveLength(0)
1166
+ if (firstInterrupted?.info.role === "assistant") {
1167
+ expect(firstInterrupted.info.finish).toBeUndefined()
1168
+ expect(firstInterrupted.info.time.completed).toBeNumber()
1169
+ expect(firstInterrupted.info.error?.name).toBe("MessageAbortedError")
1170
+ }
1171
+
1172
+ yield* prompt.prompt({
1173
+ sessionID: chat.id,
1174
+ agent: "build",
1175
+ noReply: true,
1176
+ parts: [{ type: "text", text: "second" }],
1177
+ })
1178
+
1179
+ const secondCreate = defer<void>()
1180
+ processorCreateStarted.push(secondCreate.resolve)
1181
+ const second = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1182
+ yield* Effect.promise(() => secondCreate.promise)
1183
+
1184
+ yield* prompt.cancel(chat.id)
1185
+ const secondExit = yield* Fiber.await(second)
1186
+ expect(Exit.isSuccess(secondExit)).toBe(true)
1187
+
1188
+ messages = yield* sessions.messages({ sessionID: chat.id })
1189
+ const poisonMessages = messages.filter(
1190
+ (message) =>
1191
+ message.info.role === "assistant" &&
1192
+ message.parts.length === 0 &&
1193
+ !message.info.finish &&
1194
+ !message.info.time.completed &&
1195
+ !message.info.error,
1196
+ )
1197
+ expect(poisonMessages).toHaveLength(0)
1198
+
1199
+ const interruptedMessages = messages.filter(
1200
+ (message) =>
1201
+ message.info.role === "assistant" &&
1202
+ message.parts.length === 0 &&
1203
+ message.info.time.completed &&
1204
+ message.info.error?.name === "MessageAbortedError",
1205
+ )
1206
+ expect(interruptedMessages).toHaveLength(2)
1207
+
1208
+ const lastUser = messages.at(-2)
1209
+ const lastAssistant = messages.at(-1)
1210
+ expect(lastUser?.info.role).toBe("user")
1211
+ expect(lastAssistant?.info.role).toBe("assistant")
1212
+ if (lastUser?.info.role === "user" && lastAssistant?.info.role === "assistant") {
1213
+ expect(lastAssistant.info.parentID).toBe(lastUser?.info.id)
1214
+ }
1215
+ }),
1216
+ { config: cfg },
1217
+ 3_000,
1218
+ )
1219
+
1220
+ noLLMServer.instance(
1221
+ "cancel finalizes subtask tool state",
1222
+ () =>
1223
+ Effect.gen(function* () {
1224
+ const ready = yield* Deferred.make<void>()
1225
+ const aborted = yield* Deferred.make<void>()
1226
+ const registry = yield* ToolRegistry.Service
1227
+ const { task } = yield* registry.named()
1228
+ const original = task.execute
1229
+ task.execute = (_args, ctx) =>
1230
+ Effect.callback<never>((_resume) => {
1231
+ ctx.abort.addEventListener("abort", () => succeedVoid(aborted), { once: true })
1232
+ if (ctx.abort.aborted) succeedVoid(aborted)
1233
+ succeedVoid(ready)
1234
+ return Effect.sync(() => succeedVoid(aborted))
1235
+ })
1236
+ yield* Effect.addFinalizer(() => Effect.sync(() => void (task.execute = original)))
1237
+
1238
+ const { prompt, chat } = yield* boot()
1239
+ const msg = yield* user(chat.id, "hello")
1240
+ yield* addSubtask(chat.id, msg.id)
1241
+
1242
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1243
+ yield* awaitWithTimeout(Deferred.await(ready), "timed out waiting for task tool to start", "10 seconds")
1244
+ yield* prompt.cancel(chat.id)
1245
+
1246
+ const exit = yield* Fiber.await(fiber)
1247
+ expect(Exit.isSuccess(exit)).toBe(true)
1248
+ yield* awaitWithTimeout(Deferred.await(aborted), "timed out waiting for task tool abort", "10 seconds")
1249
+
1250
+ const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
1251
+ const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
1252
+ expect(taskMsg?.info.role).toBe("assistant")
1253
+ if (!taskMsg || taskMsg.info.role !== "assistant") return
1254
+
1255
+ const tool = toolPart(taskMsg.parts)
1256
+ expect(tool?.type).toBe("tool")
1257
+ if (!tool) return
1258
+
1259
+ expect(tool.state.status).not.toBe("running")
1260
+ expect(taskMsg.info.time.completed).toBeDefined()
1261
+ expect(taskMsg.info.finish).toBeDefined()
1262
+ }),
1263
+ { config: cfg },
1264
+ 30_000,
1265
+ )
1266
+
1267
+ it.instance(
1268
+ "cancel propagates from slash command subtask to child session",
1269
+ () =>
1270
+ Effect.gen(function* () {
1271
+ const { llm } = yield* useServerConfig(providerCfg)
1272
+ const prompt = yield* SessionPrompt.Service
1273
+ const sessions = yield* Session.Service
1274
+ const status = yield* SessionStatus.Service
1275
+ const chat = yield* sessions.create({ title: "Pinned" })
1276
+ yield* llm.hang
1277
+ const msg = yield* user(chat.id, "hello")
1278
+ yield* addSubtask(chat.id, msg.id)
1279
+
1280
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1281
+ yield* llm.wait(1)
1282
+
1283
+ const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
1284
+ const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
1285
+ const tool = taskMsg ? toolPart(taskMsg.parts) : undefined
1286
+ const sessionID = tool?.state.status === "running" ? tool.state.metadata?.sessionId : undefined
1287
+ expect(typeof sessionID).toBe("string")
1288
+ if (typeof sessionID !== "string") throw new Error("missing child session id")
1289
+ const childID = SessionID.make(sessionID)
1290
+ expect((yield* status.get(childID)).type).toBe("busy")
1291
+
1292
+ yield* prompt.cancel(chat.id)
1293
+ const exit = yield* Fiber.await(fiber)
1294
+ expect(Exit.isSuccess(exit)).toBe(true)
1295
+
1296
+ expect((yield* status.get(chat.id)).type).toBe("idle")
1297
+ expect((yield* status.get(childID)).type).toBe("idle")
1298
+ }),
1299
+ 10_000,
1300
+ )
1301
+
1302
+ it.instance(
1303
+ "cancel with queued callers resolves all cleanly",
1304
+ () =>
1305
+ Effect.gen(function* () {
1306
+ const { llm } = yield* useServerConfig(providerCfg)
1307
+ const prompt = yield* SessionPrompt.Service
1308
+ const sessions = yield* Session.Service
1309
+ const chat = yield* sessions.create({ title: "Pinned" })
1310
+ yield* llm.hang
1311
+ yield* user(chat.id, "hello")
1312
+
1313
+ const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1314
+ yield* llm.wait(1)
1315
+ const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1316
+ yield* Effect.sleep(50)
1317
+
1318
+ yield* prompt.cancel(chat.id)
1319
+ const [exitA, exitB] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
1320
+ expect(Exit.isSuccess(exitA)).toBe(true)
1321
+ expect(Exit.isSuccess(exitB)).toBe(true)
1322
+ if (Exit.isSuccess(exitA) && Exit.isSuccess(exitB)) {
1323
+ expect(exitA.value.info.id).toBe(exitB.value.info.id)
1324
+ }
1325
+ }),
1326
+ { git: true },
1327
+ 10_000,
1328
+ )
1329
+
1330
+ // Queue semantics
1331
+
1332
+ noLLMServer.instance("concurrent loop callers get same result", () =>
1333
+ Effect.gen(function* () {
1334
+ const { prompt, run, chat } = yield* boot()
1335
+ yield* seed(chat.id, { finish: "stop" })
1336
+
1337
+ const [a, b] = yield* Effect.all([prompt.loop({ sessionID: chat.id }), prompt.loop({ sessionID: chat.id })], {
1338
+ concurrency: "unbounded",
1339
+ })
1340
+
1341
+ expect(a.info.id).toBe(b.info.id)
1342
+ expect(a.info.role).toBe("assistant")
1343
+ yield* run.assertNotBusy(chat.id)
1344
+ }),
1345
+ )
1346
+
1347
+ it.instance("concurrent loop callers all receive same error result", () =>
1348
+ Effect.gen(function* () {
1349
+ const { llm } = yield* useServerConfig(providerCfg)
1350
+ const prompt = yield* SessionPrompt.Service
1351
+ const sessions = yield* Session.Service
1352
+ const chat = yield* sessions.create({ title: "Pinned" })
1353
+
1354
+ yield* llm.fail("boom")
1355
+ yield* user(chat.id, "hello")
1356
+
1357
+ const [a, b] = yield* Effect.all([prompt.loop({ sessionID: chat.id }), prompt.loop({ sessionID: chat.id })], {
1358
+ concurrency: "unbounded",
1359
+ })
1360
+ expect(a.info.id).toBe(b.info.id)
1361
+ expect(a.info.role).toBe("assistant")
1362
+ }),
1363
+ )
1364
+
1365
+ it.instance("prompt submitted during an active run is included in the next LLM input", () =>
1366
+ Effect.gen(function* () {
1367
+ const { llm } = yield* useServerConfig(providerCfg)
1368
+ const gate = yield* Deferred.make<void>()
1369
+ const prompt = yield* SessionPrompt.Service
1370
+ const sessions = yield* Session.Service
1371
+ const chat = yield* sessions.create({ title: "Pinned" })
1372
+
1373
+ yield* llm.hold("first", deferredAsPromise(gate))
1374
+ yield* llm.text("second")
1375
+
1376
+ const a = yield* prompt
1377
+ .prompt({
1378
+ sessionID: chat.id,
1379
+ agent: "build",
1380
+ model: ref,
1381
+ parts: [{ type: "text", text: "first" }],
1382
+ })
1383
+ .pipe(Effect.forkChild)
1384
+
1385
+ yield* llm.wait(1)
1386
+ yield* waitForBusy(chat.id)
1387
+
1388
+ const id = MessageID.ascending()
1389
+ const b = yield* prompt
1390
+ .prompt({
1391
+ sessionID: chat.id,
1392
+ messageID: id,
1393
+ agent: "build",
1394
+ model: ref,
1395
+ parts: [{ type: "text", text: "second" }],
1396
+ })
1397
+ .pipe(Effect.forkChild)
1398
+
1399
+ yield* pollWithTimeout(
1400
+ sessions
1401
+ .messages({ sessionID: chat.id })
1402
+ .pipe(
1403
+ Effect.map((msgs) => (msgs.some((msg) => msg.info.role === "user" && msg.info.id === id) ? true : undefined)),
1404
+ ),
1405
+ "timed out waiting for second prompt to save",
1406
+ )
1407
+
1408
+ yield* Deferred.succeed(gate, void 0)
1409
+
1410
+ const [ea, eb] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
1411
+ expect(Exit.isSuccess(ea)).toBe(true)
1412
+ expect(Exit.isSuccess(eb)).toBe(true)
1413
+ expect(yield* llm.calls).toBe(2)
1414
+
1415
+ const msgs = yield* sessions.messages({ sessionID: chat.id })
1416
+ const assistants = msgs.filter((msg) => msg.info.role === "assistant")
1417
+ expect(assistants).toHaveLength(2)
1418
+ const last = assistants.at(-1)
1419
+ if (!last || last.info.role !== "assistant") throw new Error("expected second assistant")
1420
+ expect(last.info.parentID).toBe(id)
1421
+ expect(last.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
1422
+
1423
+ const inputs = yield* llm.inputs
1424
+ expect(inputs).toHaveLength(2)
1425
+ const messages = inputs.at(-1)?.messages
1426
+ if (!Array.isArray(messages)) throw new Error("expected LLM messages")
1427
+ expect(messages.at(-1)).toEqual({ role: "user", content: "second" })
1428
+ }),
1429
+ )
1430
+
1431
+ it.instance("assertNotBusy fails with BusyError when loop running", () =>
1432
+ Effect.gen(function* () {
1433
+ const { llm } = yield* useServerConfig(providerCfg)
1434
+ const prompt = yield* SessionPrompt.Service
1435
+ const run = yield* SessionRunState.Service
1436
+ const sessions = yield* Session.Service
1437
+ yield* llm.hang
1438
+
1439
+ const chat = yield* sessions.create({})
1440
+ yield* user(chat.id, "hi")
1441
+
1442
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1443
+ yield* llm.wait(1)
1444
+ yield* waitForBusy(chat.id)
1445
+
1446
+ const exit = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
1447
+ expect(Exit.isFailure(exit)).toBe(true)
1448
+ if (Exit.isFailure(exit)) {
1449
+ expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
1450
+ expect(Cause.squash(exit.cause)).toMatchObject({ _tag: "SessionBusyError", sessionID: chat.id })
1451
+ }
1452
+
1453
+ yield* prompt.cancel(chat.id)
1454
+ yield* Fiber.await(fiber)
1455
+ }),
1456
+ )
1457
+
1458
+ noLLMServer.instance("assertNotBusy succeeds when idle", () =>
1459
+ Effect.gen(function* () {
1460
+ const run = yield* SessionRunState.Service
1461
+ const sessions = yield* Session.Service
1462
+
1463
+ const chat = yield* sessions.create({})
1464
+ const exit = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
1465
+ expect(Exit.isSuccess(exit)).toBe(true)
1466
+ }),
1467
+ )
1468
+
1469
+ // Shell semantics
1470
+
1471
+ it.instance("shell rejects with BusyError when loop running", () =>
1472
+ Effect.gen(function* () {
1473
+ const { llm } = yield* useServerConfig(providerCfg)
1474
+ const prompt = yield* SessionPrompt.Service
1475
+ const sessions = yield* Session.Service
1476
+ const chat = yield* sessions.create({ title: "Pinned" })
1477
+ yield* llm.hang
1478
+ yield* user(chat.id, "hi")
1479
+
1480
+ const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1481
+ yield* llm.wait(1)
1482
+ yield* waitForBusy(chat.id)
1483
+
1484
+ const exit = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "echo hi" }).pipe(Effect.exit)
1485
+ expect(Exit.isFailure(exit)).toBe(true)
1486
+ if (Exit.isFailure(exit)) {
1487
+ expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
1488
+ expect(Cause.squash(exit.cause)).toMatchObject({ _tag: "SessionBusyError", sessionID: chat.id })
1489
+ }
1490
+
1491
+ yield* prompt.cancel(chat.id)
1492
+ yield* Fiber.await(fiber)
1493
+ }),
1494
+ )
1495
+
1496
+ unixNoLLMServer(
1497
+ "shell captures stdout and stderr in completed tool output",
1498
+ () =>
1499
+ Effect.gen(function* () {
1500
+ const { prompt, run, chat } = yield* boot()
1501
+ const result = yield* prompt.shell({
1502
+ sessionID: chat.id,
1503
+ agent: "build",
1504
+ command: "printf out && printf err >&2",
1505
+ })
1506
+
1507
+ expect(result.info.role).toBe("assistant")
1508
+ const tool = completedTool(result.parts)
1509
+ if (!tool) return
1510
+
1511
+ expect(tool.state.output).toContain("out")
1512
+ expect(tool.state.output).toContain("err")
1513
+ expect(tool.state.metadata.output).toContain("out")
1514
+ expect(tool.state.metadata.output).toContain("err")
1515
+ yield* run.assertNotBusy(chat.id)
1516
+ }),
1517
+ { config: cfg },
1518
+ )
1519
+
1520
+ unixNoLLMServer(
1521
+ "shell completes a fast command on the preferred shell",
1522
+ () =>
1523
+ Effect.gen(function* () {
1524
+ const { directory: dir } = yield* TestInstance
1525
+ const { prompt, run, chat } = yield* boot()
1526
+ const result = yield* prompt.shell({
1527
+ sessionID: chat.id,
1528
+ agent: "build",
1529
+ command: "pwd",
1530
+ })
1531
+
1532
+ expect(result.info.role).toBe("assistant")
1533
+ const tool = completedTool(result.parts)
1534
+ if (!tool) return
1535
+
1536
+ expect(tool.state.input.command).toBe("pwd")
1537
+ expect(tool.state.output).toContain(dir)
1538
+ expect(tool.state.metadata.output).toContain(dir)
1539
+ yield* run.assertNotBusy(chat.id)
1540
+ }),
1541
+ { config: cfg },
1542
+ )
1543
+
1544
+ unixNoLLMServer(
1545
+ "shell uses configured shell over env shell",
1546
+ () =>
1547
+ withSh(() =>
1548
+ Effect.gen(function* () {
1549
+ if (!(yield* hasBash)) return
1550
+
1551
+ const { prompt, chat } = yield* boot()
1552
+ const result = yield* prompt.shell({
1553
+ sessionID: chat.id,
1554
+ agent: "build",
1555
+ command: "[[ 1 -eq 1 ]] && printf configured",
1556
+ })
1557
+
1558
+ const tool = completedTool(result.parts)
1559
+ if (!tool) return
1560
+ expect(tool.state.output).toContain("configured")
1561
+ }),
1562
+ ),
1563
+ { config: { ...cfg, shell: "bash" } },
1564
+ 30_000,
1565
+ )
1566
+
1567
+ unixNoLLMServer(
1568
+ "shell commands can change directory after startup",
1569
+ () =>
1570
+ withSh(() =>
1571
+ Effect.gen(function* () {
1572
+ const { directory: dir } = yield* TestInstance
1573
+ const { prompt, run, chat } = yield* boot()
1574
+ const parent = path.dirname(dir)
1575
+ const result = yield* prompt.shell({
1576
+ sessionID: chat.id,
1577
+ agent: "build",
1578
+ command: "cd .. && pwd",
1579
+ })
1580
+
1581
+ expect(result.info.role).toBe("assistant")
1582
+ const tool = completedTool(result.parts)
1583
+ if (!tool) return
1584
+
1585
+ expect(tool.state.output).toContain(parent)
1586
+ expect(tool.state.metadata.output).toContain(parent)
1587
+ yield* run.assertNotBusy(chat.id)
1588
+ }),
1589
+ ),
1590
+ { config: cfg },
1591
+ )
1592
+
1593
+ unixNoLLMServer(
1594
+ "shell lists files from the project directory",
1595
+ () =>
1596
+ Effect.gen(function* () {
1597
+ const { directory: dir } = yield* TestInstance
1598
+ const { prompt, run, chat } = yield* boot()
1599
+ yield* writeText(path.join(dir, "README.md"), "# e2e\n")
1600
+
1601
+ const result = yield* prompt.shell({
1602
+ sessionID: chat.id,
1603
+ agent: "build",
1604
+ command: "command ls",
1605
+ })
1606
+
1607
+ expect(result.info.role).toBe("assistant")
1608
+ const tool = completedTool(result.parts)
1609
+ if (!tool) return
1610
+
1611
+ expect(tool.state.input.command).toBe("command ls")
1612
+ expect(tool.state.output).toContain("README.md")
1613
+ expect(tool.state.metadata.output).toContain("README.md")
1614
+ yield* run.assertNotBusy(chat.id)
1615
+ }),
1616
+ { config: cfg },
1617
+ )
1618
+
1619
+ unixNoLLMServer(
1620
+ "shell captures stderr from a failing command",
1621
+ () =>
1622
+ Effect.gen(function* () {
1623
+ const { prompt, run, chat } = yield* boot()
1624
+ const result = yield* prompt.shell({
1625
+ sessionID: chat.id,
1626
+ agent: "build",
1627
+ command: "command -v __nonexistent_cmd_e2e__ || echo 'not found' >&2; exit 1",
1628
+ })
1629
+
1630
+ expect(result.info.role).toBe("assistant")
1631
+ const tool = completedTool(result.parts)
1632
+ if (!tool) return
1633
+
1634
+ expect(tool.state.output).toContain("not found")
1635
+ expect(tool.state.metadata.output).toContain("not found")
1636
+ yield* run.assertNotBusy(chat.id)
1637
+ }),
1638
+ { config: cfg },
1639
+ )
1640
+
1641
+ unixNoLLMServer(
1642
+ "shell updates running metadata before process exit",
1643
+ () =>
1644
+ withSh(() =>
1645
+ Effect.gen(function* () {
1646
+ const { prompt, chat } = yield* boot()
1647
+
1648
+ const fiber = yield* prompt
1649
+ .shell({ sessionID: chat.id, agent: "build", command: "printf first && sleep 0.2 && printf second" })
1650
+ .pipe(Effect.forkChild)
1651
+
1652
+ yield* pollWithTimeout(
1653
+ Effect.gen(function* () {
1654
+ const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
1655
+ const taskMsg = msgs.find((item) => item.info.role === "assistant")
1656
+ const tool = taskMsg ? toolPart(taskMsg.parts) : undefined
1657
+ if (tool?.state.status === "running" && tool.state.metadata?.output.includes("first")) return true
1658
+ }),
1659
+ "timed out waiting for running shell metadata",
1660
+ )
1661
+
1662
+ const exit = yield* Fiber.await(fiber)
1663
+ expect(Exit.isSuccess(exit)).toBe(true)
1664
+ }),
1665
+ ),
1666
+ { config: cfg },
1667
+ 30_000,
1668
+ )
1669
+
1670
+ it.instance(
1671
+ "loop waits while shell runs and starts after shell exits",
1672
+ () =>
1673
+ Effect.gen(function* () {
1674
+ const { llm } = yield* useServerConfig(providerCfg)
1675
+ const prompt = yield* SessionPrompt.Service
1676
+ const sessions = yield* Session.Service
1677
+ const chat = yield* sessions.create({
1678
+ title: "Pinned",
1679
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
1680
+ })
1681
+ yield* llm.text("after-shell")
1682
+
1683
+ const sh = yield* prompt
1684
+ .shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
1685
+ .pipe(Effect.forkChild)
1686
+ yield* waitForBusy(chat.id)
1687
+
1688
+ const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1689
+ yield* Effect.sleep(50)
1690
+
1691
+ expect(yield* llm.calls).toBe(0)
1692
+
1693
+ yield* Fiber.await(sh)
1694
+ const exit = yield* Fiber.await(loop)
1695
+
1696
+ expect(Exit.isSuccess(exit)).toBe(true)
1697
+ if (Exit.isSuccess(exit)) {
1698
+ expect(exit.value.info.role).toBe("assistant")
1699
+ expect(exit.value.parts.some((part) => part.type === "text" && part.text === "after-shell")).toBe(true)
1700
+ }
1701
+ expect(yield* llm.calls).toBe(1)
1702
+ }),
1703
+ { git: true },
1704
+ 10_000,
1705
+ )
1706
+
1707
+ it.instance(
1708
+ "shell completion resumes queued loop callers",
1709
+ () =>
1710
+ Effect.gen(function* () {
1711
+ const { llm } = yield* useServerConfig(providerCfg)
1712
+ const prompt = yield* SessionPrompt.Service
1713
+ const sessions = yield* Session.Service
1714
+ const chat = yield* sessions.create({
1715
+ title: "Pinned",
1716
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
1717
+ })
1718
+ yield* llm.text("done")
1719
+
1720
+ const sh = yield* prompt
1721
+ .shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
1722
+ .pipe(Effect.forkChild)
1723
+ yield* waitForBusy(chat.id)
1724
+
1725
+ const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1726
+ const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1727
+ yield* Effect.sleep(50)
1728
+
1729
+ expect(yield* llm.calls).toBe(0)
1730
+
1731
+ yield* Fiber.await(sh)
1732
+ const [ea, eb] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
1733
+
1734
+ expect(Exit.isSuccess(ea)).toBe(true)
1735
+ expect(Exit.isSuccess(eb)).toBe(true)
1736
+ if (Exit.isSuccess(ea) && Exit.isSuccess(eb)) {
1737
+ expect(ea.value.info.id).toBe(eb.value.info.id)
1738
+ expect(ea.value.info.role).toBe("assistant")
1739
+ }
1740
+ expect(yield* llm.calls).toBe(1)
1741
+ }),
1742
+ { git: true },
1743
+ 10_000,
1744
+ )
1745
+
1746
+ unix(
1747
+ "command ! expansion uses configured shell over env shell",
1748
+ () =>
1749
+ withSh(() =>
1750
+ Effect.gen(function* () {
1751
+ if (!(yield* hasBash)) return
1752
+ const { llm } = yield* useServerConfig((url) => ({
1753
+ ...providerCfg(url),
1754
+ shell: "bash",
1755
+ command: {
1756
+ probe: {
1757
+ template: "Probe: !`[[ 1 -eq 1 ]] && printf configured`",
1758
+ },
1759
+ },
1760
+ }))
1761
+
1762
+ const { prompt, chat } = yield* boot()
1763
+ yield* llm.text("done")
1764
+
1765
+ const result = yield* prompt.command({
1766
+ sessionID: chat.id,
1767
+ command: "probe",
1768
+ arguments: "",
1769
+ })
1770
+
1771
+ expect(result.info.role).toBe("assistant")
1772
+ const inputs = yield* llm.inputs
1773
+ expect(JSON.stringify(inputs.at(-1)?.messages)).toContain("configured")
1774
+ }),
1775
+ ),
1776
+ 30_000,
1777
+ )
1778
+
1779
+ unixNoLLMServer(
1780
+ "cancel interrupts shell and resolves cleanly",
1781
+ () =>
1782
+ withSh(() =>
1783
+ Effect.gen(function* () {
1784
+ const { prompt, run, chat } = yield* boot()
1785
+ const { directory: dir } = yield* TestInstance
1786
+ const afs = yield* FSUtil.Service
1787
+ const ready = path.join(dir, ".shell-ready")
1788
+
1789
+ const sh = yield* prompt
1790
+ .shell({ sessionID: chat.id, agent: "build", command: ": > '.shell-ready'; sleep 30" })
1791
+ .pipe(Effect.forkChild)
1792
+ yield* pollWithTimeout(
1793
+ afs.existsSafe(ready).pipe(Effect.map((exists) => (exists ? (true as const) : undefined))),
1794
+ "shell never created readiness marker",
1795
+ )
1796
+
1797
+ yield* prompt.cancel(chat.id)
1798
+
1799
+ const status = yield* SessionStatus.Service
1800
+ expect((yield* status.get(chat.id)).type).toBe("idle")
1801
+ const busy = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
1802
+ expect(Exit.isSuccess(busy)).toBe(true)
1803
+
1804
+ const exit = yield* Fiber.await(sh)
1805
+ expect(Exit.isSuccess(exit)).toBe(true)
1806
+ if (Exit.isSuccess(exit)) {
1807
+ expect(exit.value.info.role).toBe("assistant")
1808
+ const tool = completedTool(exit.value.parts)
1809
+ if (tool) {
1810
+ expect(tool.state.output).toContain("User aborted the command")
1811
+ }
1812
+ }
1813
+ }),
1814
+ ),
1815
+ { git: true, config: cfg },
1816
+ 30_000,
1817
+ )
1818
+
1819
+ unixNoLLMServer(
1820
+ "cancel persists aborted shell result when shell ignores TERM",
1821
+ () =>
1822
+ withSh(() =>
1823
+ Effect.gen(function* () {
1824
+ const { prompt, chat } = yield* boot()
1825
+ const { directory: dir } = yield* TestInstance
1826
+ const afs = yield* FSUtil.Service
1827
+ const ready = path.join(dir, ".trap-ready")
1828
+
1829
+ const sh = yield* prompt
1830
+ .shell({
1831
+ sessionID: chat.id,
1832
+ agent: "build",
1833
+ // Touch marker AFTER trap installs so the test waits for the actual
1834
+ // ignore-TERM state before cancelling; otherwise SIGTERM can arrive
1835
+ // before `trap` runs and the escalation path is never exercised.
1836
+ command: `trap '' TERM; touch "${ready}"; sleep 30`,
1837
+ })
1838
+ .pipe(Effect.forkChild)
1839
+
1840
+ yield* Effect.gen(function* () {
1841
+ while (!(yield* afs.existsSafe(ready))) {
1842
+ yield* Effect.sleep(Duration.millis(10))
1843
+ }
1844
+ }).pipe(Effect.timeout(Duration.seconds(5)))
1845
+
1846
+ yield* prompt.cancel(chat.id)
1847
+
1848
+ const exit = yield* Fiber.await(sh)
1849
+ expect(Exit.isSuccess(exit)).toBe(true)
1850
+ if (Exit.isSuccess(exit)) {
1851
+ expect(exit.value.info.role).toBe("assistant")
1852
+ const tool = completedTool(exit.value.parts)
1853
+ if (tool) {
1854
+ expect(tool.state.output).toContain("User aborted the command")
1855
+ }
1856
+ }
1857
+ }),
1858
+ ),
1859
+ { git: true, config: cfg },
1860
+ 30_000,
1861
+ )
1862
+
1863
+ unix(
1864
+ "cancel finalizes interrupted bash tool output through normal truncation",
1865
+ () =>
1866
+ Effect.gen(function* () {
1867
+ const { dir, llm } = yield* useServerConfig(providerCfg)
1868
+ const prompt = yield* SessionPrompt.Service
1869
+ const sessions = yield* Session.Service
1870
+ const chat = yield* sessions.create({
1871
+ title: "Interrupted bash truncation",
1872
+ permission: [{ permission: "*", pattern: "*", action: "allow" }],
1873
+ })
1874
+
1875
+ yield* prompt.prompt({
1876
+ sessionID: chat.id,
1877
+ agent: "build",
1878
+ noReply: true,
1879
+ parts: [{ type: "text", text: "run bash" }],
1880
+ })
1881
+
1882
+ yield* llm.tool("bash", {
1883
+ command:
1884
+ 'i=0; while [ "$i" -lt 4000 ]; do printf "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx %05d\\n" "$i"; i=$((i + 1)); done; printf truncation-ready; sleep 30',
1885
+ timeout: 30_000,
1886
+ workdir: path.resolve(dir),
1887
+ })
1888
+
1889
+ const run = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1890
+ yield* llm.wait(1)
1891
+ yield* pollWithTimeout(
1892
+ Effect.gen(function* () {
1893
+ const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
1894
+ const assistant = msgs.findLast((item) => item.info.role === "assistant")
1895
+ const tool = assistant ? toolPart(assistant.parts) : undefined
1896
+ if (tool?.state.status === "running" && tool.state.metadata?.output.includes("truncation-ready")) return true
1897
+ }),
1898
+ "timed out waiting for truncated shell output",
1899
+ )
1900
+ yield* prompt.cancel(chat.id)
1901
+
1902
+ const exit = yield* Fiber.await(run)
1903
+ expect(Exit.isSuccess(exit)).toBe(true)
1904
+ if (Exit.isFailure(exit)) return
1905
+
1906
+ const tool = completedTool(exit.value.parts)
1907
+ if (!tool) return
1908
+
1909
+ expect(tool.state.metadata.truncated).toBe(true)
1910
+ expect(typeof tool.state.metadata.outputPath).toBe("string")
1911
+ expect(tool.state.output).toMatch(/\.\.\.output truncated\.\.\./)
1912
+ expect(tool.state.output).toMatch(/Full output saved to:\s+\S+/)
1913
+ expect(tool.state.output).not.toContain("Tool execution aborted")
1914
+ }),
1915
+ { git: true },
1916
+ 30_000,
1917
+ )
1918
+
1919
+ unixNoLLMServer(
1920
+ "cancel interrupts loop queued behind shell",
1921
+ () =>
1922
+ Effect.gen(function* () {
1923
+ const { prompt, chat } = yield* boot()
1924
+
1925
+ const sh = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "sleep 30" }).pipe(Effect.forkChild)
1926
+ yield* waitForBusy(chat.id)
1927
+
1928
+ const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1929
+ yield* Effect.sleep(50)
1930
+
1931
+ yield* prompt.cancel(chat.id)
1932
+
1933
+ const exit = yield* Fiber.await(loop)
1934
+ expect(Exit.isSuccess(exit)).toBe(true)
1935
+ if (Exit.isSuccess(exit)) {
1936
+ const tool = completedTool(exit.value.parts)
1937
+ expect(tool?.state.output).toContain("User aborted the command")
1938
+ }
1939
+
1940
+ yield* Fiber.await(sh)
1941
+ }),
1942
+ { git: true, config: cfg },
1943
+ 30_000,
1944
+ )
1945
+
1946
+ unixNoLLMServer(
1947
+ "shell rejects when another shell is already running",
1948
+ () =>
1949
+ withSh(() =>
1950
+ Effect.gen(function* () {
1951
+ const { prompt, chat } = yield* boot()
1952
+
1953
+ const a = yield* prompt
1954
+ .shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
1955
+ .pipe(Effect.forkChild)
1956
+ yield* waitForBusy(chat.id)
1957
+
1958
+ const exit = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "echo hi" }).pipe(Effect.exit)
1959
+ expect(Exit.isFailure(exit)).toBe(true)
1960
+ if (Exit.isFailure(exit)) {
1961
+ expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
1962
+ }
1963
+
1964
+ yield* prompt.cancel(chat.id)
1965
+ yield* Fiber.await(a)
1966
+ }),
1967
+ ),
1968
+ { git: true, config: cfg },
1969
+ 30_000,
1970
+ )
1971
+
1972
+ // Abort signal propagation tests for inline tool execution
1973
+
1974
+ function hangUntilAborted(tool: { execute: (...args: any[]) => any }) {
1975
+ return Effect.gen(function* () {
1976
+ const ready = yield* Deferred.make<void>()
1977
+ const aborted = yield* Deferred.make<void>()
1978
+ const original = tool.execute
1979
+ tool.execute = (_args: any, ctx: any) => {
1980
+ ctx.abort.addEventListener("abort", () => succeedVoid(aborted), { once: true })
1981
+ if (ctx.abort.aborted) succeedVoid(aborted)
1982
+ succeedVoid(ready)
1983
+ return Effect.callback<never>(() => Effect.sync(() => succeedVoid(aborted)))
1984
+ }
1985
+ const restore = Effect.addFinalizer(() => Effect.sync(() => void (tool.execute = original)))
1986
+ return { ready, aborted, restore }
1987
+ })
1988
+ }
1989
+
1990
+ noLLMServer.instance(
1991
+ "interrupt propagates abort signal to read tool via file part (text/plain)",
1992
+ () =>
1993
+ Effect.gen(function* () {
1994
+ const { directory: dir } = yield* TestInstance
1995
+ const registry = yield* ToolRegistry.Service
1996
+ const { read } = yield* registry.named()
1997
+ const { ready, restore } = yield* hangUntilAborted(read)
1998
+ yield* restore
1999
+
2000
+ const prompt = yield* SessionPrompt.Service
2001
+ const sessions = yield* Session.Service
2002
+ const chat = yield* sessions.create({ title: "Abort Test" })
2003
+
2004
+ const testFile = path.join(dir, "test.txt")
2005
+ yield* writeText(testFile, "hello world")
2006
+
2007
+ const fiber = yield* prompt
2008
+ .prompt({
2009
+ sessionID: chat.id,
2010
+ agent: "build",
2011
+ parts: [
2012
+ { type: "text", text: "read this" },
2013
+ { type: "file", url: `file://${testFile}`, filename: "test.txt", mime: "text/plain" },
2014
+ ],
2015
+ })
2016
+ .pipe(Effect.forkChild)
2017
+
2018
+ yield* awaitWithTimeout(Deferred.await(ready), "timed out waiting for read tool to start", "10 seconds")
2019
+ yield* prompt.cancel(chat.id)
2020
+ yield* Fiber.interrupt(fiber)
2021
+ const exit = yield* Fiber.await(fiber)
2022
+ expect(Exit.isFailure(exit)).toBe(true)
2023
+ }),
2024
+ { config: cfg },
2025
+ 30_000,
2026
+ )
2027
+
2028
+ noLLMServer.instance(
2029
+ "interrupt propagates abort signal to read tool via file part (directory)",
2030
+ () =>
2031
+ Effect.gen(function* () {
2032
+ const { directory: dir } = yield* TestInstance
2033
+ const registry = yield* ToolRegistry.Service
2034
+ const { read } = yield* registry.named()
2035
+ const { ready, restore } = yield* hangUntilAborted(read)
2036
+ yield* restore
2037
+
2038
+ const prompt = yield* SessionPrompt.Service
2039
+ const sessions = yield* Session.Service
2040
+ const chat = yield* sessions.create({ title: "Abort Test" })
2041
+
2042
+ const fiber = yield* prompt
2043
+ .prompt({
2044
+ sessionID: chat.id,
2045
+ agent: "build",
2046
+ parts: [
2047
+ { type: "text", text: "read this" },
2048
+ { type: "file", url: `file://${dir}`, filename: "dir", mime: "application/x-directory" },
2049
+ ],
2050
+ })
2051
+ .pipe(Effect.forkChild)
2052
+
2053
+ yield* awaitWithTimeout(Deferred.await(ready), "timed out waiting for read tool to start", "10 seconds")
2054
+ yield* prompt.cancel(chat.id)
2055
+ yield* Fiber.interrupt(fiber)
2056
+ const exit = yield* Fiber.await(fiber)
2057
+ expect(Exit.isFailure(exit)).toBe(true)
2058
+ }),
2059
+ { config: cfg },
2060
+ 30_000,
2061
+ )
2062
+
2063
+ // Missing file handling
2064
+
2065
+ noLLMServer.instance(
2066
+ "does not fail the prompt when a file part is missing",
2067
+ () =>
2068
+ Effect.gen(function* () {
2069
+ const { directory: dir } = yield* TestInstance
2070
+ const prompt = yield* SessionPrompt.Service
2071
+ const sessions = yield* Session.Service
2072
+ const session = yield* sessions.create({})
2073
+
2074
+ const missing = path.join(dir, "does-not-exist.ts")
2075
+ const msg = yield* prompt.prompt({
2076
+ sessionID: session.id,
2077
+ agent: "build",
2078
+ noReply: true,
2079
+ parts: [
2080
+ { type: "text", text: "please review @does-not-exist.ts" },
2081
+ {
2082
+ type: "file",
2083
+ mime: "text/plain",
2084
+ url: `file://${missing}`,
2085
+ filename: "does-not-exist.ts",
2086
+ },
2087
+ ],
2088
+ })
2089
+
2090
+ if (msg.info.role !== "user") throw new Error("expected user message")
2091
+ const hasFailure = msg.parts.some(
2092
+ (part) => part.type === "text" && part.synthetic && part.text.includes("Read tool failed to read"),
2093
+ )
2094
+ expect(hasFailure).toBe(true)
2095
+
2096
+ yield* sessions.remove(session.id)
2097
+ }),
2098
+ { config: cfg },
2099
+ )
2100
+
2101
+ noLLMServer.instance(
2102
+ "keeps stored part order stable when file resolution is async",
2103
+ () =>
2104
+ Effect.gen(function* () {
2105
+ const { directory: dir } = yield* TestInstance
2106
+ const prompt = yield* SessionPrompt.Service
2107
+ const sessions = yield* Session.Service
2108
+ const session = yield* sessions.create({})
2109
+
2110
+ const missing = path.join(dir, "still-missing.ts")
2111
+ const msg = yield* prompt.prompt({
2112
+ sessionID: session.id,
2113
+ agent: "build",
2114
+ noReply: true,
2115
+ parts: [
2116
+ {
2117
+ type: "file",
2118
+ mime: "text/plain",
2119
+ url: `file://${missing}`,
2120
+ filename: "still-missing.ts",
2121
+ },
2122
+ { type: "text", text: "after-file" },
2123
+ ],
2124
+ })
2125
+
2126
+ if (msg.info.role !== "user") throw new Error("expected user message")
2127
+
2128
+ const stored = yield* MessageV2.get({
2129
+ sessionID: session.id,
2130
+ messageID: msg.info.id,
2131
+ })
2132
+ const text = stored.parts.filter((part) => part.type === "text").map((part) => part.text)
2133
+
2134
+ expect(text[0]?.startsWith("Called the Read tool with the following input:")).toBe(true)
2135
+ expect(text[1]?.includes("Read tool failed to read")).toBe(true)
2136
+ expect(text[2]).toBe("after-file")
2137
+
2138
+ yield* sessions.remove(session.id)
2139
+ }),
2140
+ { config: cfg },
2141
+ )
2142
+
2143
+ // Special characters in filenames
2144
+
2145
+ noLLMServer.instance(
2146
+ "handles filenames with # character",
2147
+ () =>
2148
+ Effect.gen(function* () {
2149
+ const { directory: dir } = yield* TestInstance
2150
+ yield* writeText(path.join(dir, "file#name.txt"), "special content\n")
2151
+
2152
+ const prompt = yield* SessionPrompt.Service
2153
+ const sessions = yield* Session.Service
2154
+ const session = yield* sessions.create({})
2155
+ const parts = yield* prompt.resolvePromptParts("Read @file#name.txt")
2156
+ const fileParts = parts.filter((part) => part.type === "file")
2157
+
2158
+ expect(fileParts.length).toBe(1)
2159
+ expect(fileParts[0].filename).toBe("file#name.txt")
2160
+ expect(fileParts[0].url).toContain("%23")
2161
+
2162
+ const decodedPath = fileURLToPath(fileParts[0].url)
2163
+ expect(decodedPath).toBe(path.join(dir, "file#name.txt"))
2164
+
2165
+ const message = yield* prompt.prompt({
2166
+ sessionID: session.id,
2167
+ parts,
2168
+ noReply: true,
2169
+ })
2170
+ const stored = yield* MessageV2.get({ sessionID: session.id, messageID: message.info.id })
2171
+ const textParts = stored.parts.filter((part) => part.type === "text")
2172
+ const hasContent = textParts.some((part) => part.text.includes("special content"))
2173
+ expect(hasContent).toBe(true)
2174
+
2175
+ yield* sessions.remove(session.id)
2176
+ }),
2177
+ { git: true, config: cfg },
2178
+ )
2179
+
2180
+ // Regression: empty assistant turn loop
2181
+
2182
+ it.instance("does not loop empty assistant turns for a simple reply", () =>
2183
+ Effect.gen(function* () {
2184
+ const { llm } = yield* useServerConfig(providerCfg)
2185
+ const prompt = yield* SessionPrompt.Service
2186
+ const sessions = yield* Session.Service
2187
+ const session = yield* sessions.create({ title: "Prompt regression" })
2188
+
2189
+ yield* llm.text("packages/opencode/src/session/processor.ts")
2190
+
2191
+ const result = yield* prompt.prompt({
2192
+ sessionID: session.id,
2193
+ agent: "build",
2194
+ parts: [{ type: "text", text: "Where is SessionProcessor?" }],
2195
+ })
2196
+
2197
+ expect(result.info.role).toBe("assistant")
2198
+ expect(result.parts.some((part) => part.type === "text" && part.text.includes("processor.ts"))).toBe(true)
2199
+
2200
+ const msgs = yield* sessions.messages({ sessionID: session.id })
2201
+ expect(msgs.filter((msg) => msg.info.role === "assistant")).toHaveLength(1)
2202
+ expect(yield* llm.calls).toBe(1)
2203
+ }),
2204
+ )
2205
+
2206
+ it.instance("records aborted errors when prompt is cancelled mid-stream", () =>
2207
+ Effect.gen(function* () {
2208
+ const { llm } = yield* useServerConfig(providerCfg)
2209
+ const prompt = yield* SessionPrompt.Service
2210
+ const sessions = yield* Session.Service
2211
+ const session = yield* sessions.create({ title: "Prompt cancel regression" })
2212
+
2213
+ yield* llm.hang
2214
+
2215
+ const fiber = yield* prompt
2216
+ .prompt({
2217
+ sessionID: session.id,
2218
+ agent: "build",
2219
+ parts: [{ type: "text", text: "Cancel me" }],
2220
+ })
2221
+ .pipe(Effect.forkChild)
2222
+
2223
+ yield* llm.wait(1)
2224
+ yield* waitForBusy(session.id)
2225
+ yield* prompt.cancel(session.id)
2226
+
2227
+ const exit = yield* Fiber.await(fiber)
2228
+ expect(Exit.isSuccess(exit)).toBe(true)
2229
+ if (Exit.isSuccess(exit)) {
2230
+ expect(exit.value.info.role).toBe("assistant")
2231
+ if (exit.value.info.role === "assistant") {
2232
+ expect(exit.value.info.error?.name).toBe("MessageAbortedError")
2233
+ }
2234
+ }
2235
+
2236
+ const msgs = yield* sessions.messages({ sessionID: session.id })
2237
+ const last = msgs.findLast((msg) => msg.info.role === "assistant")
2238
+ expect(last?.info.role).toBe("assistant")
2239
+ if (last?.info.role === "assistant") {
2240
+ expect(last.info.error?.name).toBe("MessageAbortedError")
2241
+ }
2242
+ }),
2243
+ )
2244
+
2245
+ // Agent variant
2246
+
2247
+ noLLMServer.instance(
2248
+ "applies agent variant only when using agent model",
2249
+ () =>
2250
+ Effect.gen(function* () {
2251
+ const prompt = yield* SessionPrompt.Service
2252
+ const sessions = yield* Session.Service
2253
+ const session = yield* sessions.create({})
2254
+
2255
+ const other = yield* prompt.prompt({
2256
+ sessionID: session.id,
2257
+ agent: "build",
2258
+ model: { providerID: ProviderV2.ID.make("opencode"), modelID: ModelV2.ID.make("kimi-k2.5-free") },
2259
+ noReply: true,
2260
+ parts: [{ type: "text", text: "hello" }],
2261
+ })
2262
+ if (other.info.role !== "user") throw new Error("expected user message")
2263
+ expect(other.info.model.variant).toBeUndefined()
2264
+
2265
+ const match = yield* prompt.prompt({
2266
+ sessionID: session.id,
2267
+ agent: "build",
2268
+ noReply: true,
2269
+ parts: [{ type: "text", text: "hello again" }],
2270
+ })
2271
+ if (match.info.role !== "user") throw new Error("expected user message")
2272
+ expect(match.info.model).toEqual({
2273
+ providerID: ProviderV2.ID.make("test"),
2274
+ modelID: ModelV2.ID.make("test-model"),
2275
+ variant: "xhigh",
2276
+ })
2277
+ expect(match.info.model.variant).toBe("xhigh")
2278
+
2279
+ const override = yield* prompt.prompt({
2280
+ sessionID: session.id,
2281
+ agent: "build",
2282
+ noReply: true,
2283
+ variant: "high",
2284
+ parts: [{ type: "text", text: "hello third" }],
2285
+ })
2286
+ if (override.info.role !== "user") throw new Error("expected user message")
2287
+ expect(override.info.model.variant).toBe("high")
2288
+
2289
+ yield* sessions.remove(session.id)
2290
+ }),
2291
+ {
2292
+ config: {
2293
+ ...cfg,
2294
+ provider: {
2295
+ ...cfg.provider,
2296
+ test: {
2297
+ ...cfg.provider.test,
2298
+ models: {
2299
+ "test-model": {
2300
+ ...cfg.provider.test.models["test-model"],
2301
+ variants: { xhigh: {}, high: {} },
2302
+ },
2303
+ },
2304
+ },
2305
+ },
2306
+ agent: {
2307
+ build: {
2308
+ model: "test/test-model",
2309
+ variant: "xhigh",
2310
+ },
2311
+ },
2312
+ },
2313
+ },
2314
+ )
2315
+
2316
+ // Agent / command resolution errors
2317
+
2318
+ noLLMServer.instance(
2319
+ "unknown agent throws typed error",
2320
+ () =>
2321
+ Effect.gen(function* () {
2322
+ const prompt = yield* SessionPrompt.Service
2323
+ const sessions = yield* Session.Service
2324
+ const session = yield* sessions.create({})
2325
+ const exit = yield* prompt
2326
+ .prompt({
2327
+ sessionID: session.id,
2328
+ agent: "nonexistent-agent-xyz",
2329
+ noReply: true,
2330
+ parts: [{ type: "text", text: "hello" }],
2331
+ })
2332
+ .pipe(Effect.exit)
2333
+
2334
+ expect(Exit.isFailure(exit)).toBe(true)
2335
+ if (Exit.isFailure(exit)) {
2336
+ const err = Cause.squash(exit.cause)
2337
+ expect(err).not.toBeInstanceOf(TypeError)
2338
+ expect(NamedError.Unknown.isInstance(err)).toBe(true)
2339
+ if (NamedError.Unknown.isInstance(err)) {
2340
+ expect(err.data.message).toContain('Agent not found: "nonexistent-agent-xyz"')
2341
+ }
2342
+ }
2343
+ }),
2344
+ 30_000,
2345
+ )
2346
+
2347
+ noLLMServer.instance(
2348
+ "unknown agent error includes available agent names",
2349
+ () =>
2350
+ Effect.gen(function* () {
2351
+ const prompt = yield* SessionPrompt.Service
2352
+ const sessions = yield* Session.Service
2353
+ const session = yield* sessions.create({})
2354
+ const exit = yield* prompt
2355
+ .prompt({
2356
+ sessionID: session.id,
2357
+ agent: "nonexistent-agent-xyz",
2358
+ noReply: true,
2359
+ parts: [{ type: "text", text: "hello" }],
2360
+ })
2361
+ .pipe(Effect.exit)
2362
+
2363
+ expect(Exit.isFailure(exit)).toBe(true)
2364
+ if (Exit.isFailure(exit)) {
2365
+ const err = Cause.squash(exit.cause)
2366
+ expect(NamedError.Unknown.isInstance(err)).toBe(true)
2367
+ if (NamedError.Unknown.isInstance(err)) {
2368
+ expect(err.data.message).toContain("build")
2369
+ }
2370
+ }
2371
+ }),
2372
+ 30_000,
2373
+ )
2374
+
2375
+ noLLMServer.instance(
2376
+ "unknown command throws typed error with available names",
2377
+ () =>
2378
+ Effect.gen(function* () {
2379
+ const prompt = yield* SessionPrompt.Service
2380
+ const sessions = yield* Session.Service
2381
+ const session = yield* sessions.create({})
2382
+ const exit = yield* prompt
2383
+ .command({
2384
+ sessionID: session.id,
2385
+ command: "nonexistent-command-xyz",
2386
+ arguments: "",
2387
+ })
2388
+ .pipe(Effect.exit)
2389
+
2390
+ expect(Exit.isFailure(exit)).toBe(true)
2391
+ if (Exit.isFailure(exit)) {
2392
+ const err = Cause.squash(exit.cause)
2393
+ expect(err).not.toBeInstanceOf(TypeError)
2394
+ expect(NamedError.Unknown.isInstance(err)).toBe(true)
2395
+ if (NamedError.Unknown.isInstance(err)) {
2396
+ expect(err.data.message).toContain('Command not found: "nonexistent-command-xyz"')
2397
+ expect(err.data.message).toContain("init")
2398
+ }
2399
+ }
2400
+ }),
2401
+ 30_000,
2402
+ )