artificial-code 1.17.13 → 1.17.14

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/bin/ac +56 -31
  2. package/bin/ac.js +224 -0
  3. package/package.json +16 -2
  4. package/AGENTS.md +0 -131
  5. package/Dockerfile +0 -18
  6. package/bunfig.toml +0 -7
  7. package/git +0 -0
  8. package/migration/20260511173437_session-metadata/migration.sql +0 -1
  9. package/migration/20260511173437_session-metadata/snapshot.json +0 -1500
  10. package/parsers-config.ts +0 -1
  11. package/script/bench-search.ts +0 -94
  12. package/script/bench-test-suite.ts +0 -52
  13. package/script/build.ts +0 -243
  14. package/script/generate.ts +0 -14
  15. package/script/httpapi-exercise.ts +0 -1
  16. package/script/postinstall.mjs +0 -189
  17. package/script/profile-test-files.ts +0 -42
  18. package/script/publish.ts +0 -213
  19. package/script/run-workspace-server +0 -106
  20. package/script/schema.ts +0 -77
  21. package/script/time.ts +0 -6
  22. package/script/trace-imports.ts +0 -153
  23. package/specs/effect/error-boundaries-plan.md +0 -235
  24. package/specs/effect/errors.md +0 -207
  25. package/specs/effect/facades.md +0 -218
  26. package/specs/effect/guide.md +0 -247
  27. package/specs/effect/instance-context.md +0 -13
  28. package/specs/effect/loose-ends.md +0 -30
  29. package/specs/effect/migration.md +0 -62
  30. package/specs/effect/routes.md +0 -61
  31. package/specs/effect/schema.md +0 -88
  32. package/specs/effect/server-package.md +0 -58
  33. package/specs/effect/todo.md +0 -241
  34. package/specs/effect/tools.md +0 -88
  35. package/specs/openapi-translation-cleanup.md +0 -204
  36. package/specs/tui-plugins.md +0 -544
  37. package/specs/v2/api.ts +0 -67
  38. package/specs/v2/message-shape.md +0 -136
  39. package/specs/v2/notifications.md +0 -13
  40. package/specs/v2/tui-command-shim.md +0 -67
  41. package/src/account/account.ts +0 -461
  42. package/src/account/repo.ts +0 -171
  43. package/src/account/schema.ts +0 -99
  44. package/src/account/url.ts +0 -8
  45. package/src/acp/agent.ts +0 -95
  46. package/src/acp/config-option.ts +0 -203
  47. package/src/acp/content.ts +0 -269
  48. package/src/acp/directory.ts +0 -212
  49. package/src/acp/error.ts +0 -97
  50. package/src/acp/event.ts +0 -342
  51. package/src/acp/permission.ts +0 -254
  52. package/src/acp/profile.ts +0 -42
  53. package/src/acp/service.ts +0 -1097
  54. package/src/acp/session.ts +0 -232
  55. package/src/acp/tool.ts +0 -364
  56. package/src/acp/usage.ts +0 -239
  57. package/src/agent/agent.ts +0 -453
  58. package/src/agent/generate.txt +0 -75
  59. package/src/agent/prompt/compaction.txt +0 -9
  60. package/src/agent/prompt/explore.txt +0 -18
  61. package/src/agent/prompt/summary.txt +0 -11
  62. package/src/agent/prompt/title.txt +0 -44
  63. package/src/agent/subagent-permissions.ts +0 -27
  64. package/src/audio.d.ts +0 -14
  65. package/src/auth/index.ts +0 -97
  66. package/src/background/job.ts +0 -37
  67. package/src/bus/global.ts +0 -22
  68. package/src/cli/bootstrap.ts +0 -11
  69. package/src/cli/cmd/account.ts +0 -264
  70. package/src/cli/cmd/acp.ts +0 -73
  71. package/src/cli/cmd/agent.ts +0 -259
  72. package/src/cli/cmd/attach.ts +0 -148
  73. package/src/cli/cmd/cmd.ts +0 -7
  74. package/src/cli/cmd/db.ts +0 -62
  75. package/src/cli/cmd/debug/agent.handler.ts +0 -193
  76. package/src/cli/cmd/debug/agent.ts +0 -27
  77. package/src/cli/cmd/debug/config.ts +0 -14
  78. package/src/cli/cmd/debug/file.ts +0 -73
  79. package/src/cli/cmd/debug/index.ts +0 -87
  80. package/src/cli/cmd/debug/lsp.ts +0 -50
  81. package/src/cli/cmd/debug/ripgrep.ts +0 -79
  82. package/src/cli/cmd/debug/scrap.ts +0 -16
  83. package/src/cli/cmd/debug/skill.ts +0 -15
  84. package/src/cli/cmd/debug/snapshot.ts +0 -50
  85. package/src/cli/cmd/debug/startup.ts +0 -11
  86. package/src/cli/cmd/debug/v2.ts +0 -42
  87. package/src/cli/cmd/export.ts +0 -292
  88. package/src/cli/cmd/generate.ts +0 -54
  89. package/src/cli/cmd/github.handler.ts +0 -1593
  90. package/src/cli/cmd/github.shared.ts +0 -30
  91. package/src/cli/cmd/github.ts +0 -42
  92. package/src/cli/cmd/import.ts +0 -224
  93. package/src/cli/cmd/mcp.ts +0 -840
  94. package/src/cli/cmd/models.ts +0 -66
  95. package/src/cli/cmd/plug.ts +0 -230
  96. package/src/cli/cmd/pr.ts +0 -115
  97. package/src/cli/cmd/prompt-display.ts +0 -1
  98. package/src/cli/cmd/providers.ts +0 -534
  99. package/src/cli/cmd/run/demo.ts +0 -1274
  100. package/src/cli/cmd/run/entry.body.ts +0 -205
  101. package/src/cli/cmd/run/footer.command.tsx +0 -1064
  102. package/src/cli/cmd/run/footer.menu.tsx +0 -351
  103. package/src/cli/cmd/run/footer.permission.tsx +0 -472
  104. package/src/cli/cmd/run/footer.prompt.tsx +0 -1306
  105. package/src/cli/cmd/run/footer.question.tsx +0 -573
  106. package/src/cli/cmd/run/footer.subagent.tsx +0 -173
  107. package/src/cli/cmd/run/footer.ts +0 -1129
  108. package/src/cli/cmd/run/footer.view.tsx +0 -943
  109. package/src/cli/cmd/run/footer.width.ts +0 -27
  110. package/src/cli/cmd/run/permission.shared.ts +0 -256
  111. package/src/cli/cmd/run/prompt.editor.ts +0 -157
  112. package/src/cli/cmd/run/prompt.shared.ts +0 -153
  113. package/src/cli/cmd/run/question.shared.ts +0 -340
  114. package/src/cli/cmd/run/runtime.boot.ts +0 -202
  115. package/src/cli/cmd/run/runtime.lifecycle.ts +0 -406
  116. package/src/cli/cmd/run/runtime.queue.ts +0 -349
  117. package/src/cli/cmd/run/runtime.shared.ts +0 -17
  118. package/src/cli/cmd/run/runtime.stdin.ts +0 -37
  119. package/src/cli/cmd/run/runtime.ts +0 -814
  120. package/src/cli/cmd/run/scrollback.shared.ts +0 -92
  121. package/src/cli/cmd/run/scrollback.surface.ts +0 -431
  122. package/src/cli/cmd/run/scrollback.writer.tsx +0 -352
  123. package/src/cli/cmd/run/session-data.ts +0 -1113
  124. package/src/cli/cmd/run/session-replay.ts +0 -374
  125. package/src/cli/cmd/run/session.shared.ts +0 -196
  126. package/src/cli/cmd/run/splash.ts +0 -280
  127. package/src/cli/cmd/run/stream.transport.ts +0 -1462
  128. package/src/cli/cmd/run/stream.ts +0 -175
  129. package/src/cli/cmd/run/subagent-data.ts +0 -876
  130. package/src/cli/cmd/run/theme.ts +0 -690
  131. package/src/cli/cmd/run/tool.ts +0 -1486
  132. package/src/cli/cmd/run/trace.ts +0 -94
  133. package/src/cli/cmd/run/turn-summary.ts +0 -47
  134. package/src/cli/cmd/run/types.ts +0 -350
  135. package/src/cli/cmd/run/variant.shared.ts +0 -216
  136. package/src/cli/cmd/run.ts +0 -1011
  137. package/src/cli/cmd/serve.ts +0 -24
  138. package/src/cli/cmd/session.ts +0 -147
  139. package/src/cli/cmd/stats.ts +0 -393
  140. package/src/cli/cmd/tui.ts +0 -305
  141. package/src/cli/cmd/uninstall.ts +0 -353
  142. package/src/cli/cmd/upgrade.ts +0 -74
  143. package/src/cli/cmd/web.ts +0 -84
  144. package/src/cli/effect/prompt.ts +0 -37
  145. package/src/cli/effect-cmd.ts +0 -96
  146. package/src/cli/error.ts +0 -130
  147. package/src/cli/heap.ts +0 -45
  148. package/src/cli/logo.ts +0 -1
  149. package/src/cli/network.ts +0 -80
  150. package/src/cli/tui/layer.ts +0 -8
  151. package/src/cli/tui/validate-session.ts +0 -29
  152. package/src/cli/tui/worker.ts +0 -80
  153. package/src/cli/ui.ts +0 -132
  154. package/src/cli/upgrade.ts +0 -53
  155. package/src/command/index.ts +0 -177
  156. package/src/command/template/initialize.txt +0 -66
  157. package/src/command/template/review.txt +0 -101
  158. package/src/config/agent.ts +0 -59
  159. package/src/config/command.ts +0 -39
  160. package/src/config/config.ts +0 -680
  161. package/src/config/entry-name.ts +0 -19
  162. package/src/config/managed.ts +0 -69
  163. package/src/config/markdown.ts +0 -36
  164. package/src/config/parse.ts +0 -79
  165. package/src/config/paths.ts +0 -45
  166. package/src/config/plugin.ts +0 -79
  167. package/src/config/tui-cwd.ts +0 -5
  168. package/src/config/tui-host-attention.ts +0 -21
  169. package/src/config/tui-migrate.ts +0 -132
  170. package/src/config/tui.ts +0 -276
  171. package/src/config/variable.ts +0 -91
  172. package/src/control-plane/adapters/index.ts +0 -41
  173. package/src/control-plane/adapters/worktree.ts +0 -96
  174. package/src/control-plane/dev/README.md +0 -19
  175. package/src/control-plane/dev/debug-workspace-plugin.ts +0 -73
  176. package/src/control-plane/types.ts +0 -59
  177. package/src/control-plane/util.ts +0 -39
  178. package/src/control-plane/workspace-adapter-runtime.ts +0 -51
  179. package/src/control-plane/workspace-context.ts +0 -26
  180. package/src/control-plane/workspace.ts +0 -964
  181. package/src/effect/app-node-builder-v1.ts +0 -12
  182. package/src/effect/app-runtime.ts +0 -135
  183. package/src/effect/bootstrap-runtime.ts +0 -19
  184. package/src/effect/bridge.ts +0 -84
  185. package/src/effect/config-service.ts +0 -67
  186. package/src/effect/instance-ref.ts +0 -11
  187. package/src/effect/instance-registry.ts +0 -12
  188. package/src/effect/instance-state.ts +0 -69
  189. package/src/effect/promise.ts +0 -17
  190. package/src/effect/run-service.ts +0 -47
  191. package/src/effect/runner.ts +0 -217
  192. package/src/effect/runtime-flags.ts +0 -77
  193. package/src/env/index.ts +0 -41
  194. package/src/event-manifest.ts +0 -3
  195. package/src/event-v2-bridge.ts +0 -71
  196. package/src/format/formatter.ts +0 -404
  197. package/src/format/index.ts +0 -203
  198. package/src/git/index.ts +0 -348
  199. package/src/id/id.ts +0 -80
  200. package/src/ide/index.ts +0 -54
  201. package/src/image/image.ts +0 -172
  202. package/src/index.ts +0 -142
  203. package/src/installation/index.ts +0 -336
  204. package/src/lsp/client.ts +0 -650
  205. package/src/lsp/diagnostic.ts +0 -29
  206. package/src/lsp/language.ts +0 -121
  207. package/src/lsp/launch.ts +0 -21
  208. package/src/lsp/lsp.ts +0 -507
  209. package/src/lsp/server.ts +0 -1983
  210. package/src/markdown.d.ts +0 -4
  211. package/src/mcp/auth.ts +0 -163
  212. package/src/mcp/catalog.ts +0 -170
  213. package/src/mcp/index.ts +0 -1012
  214. package/src/mcp/oauth-callback.ts +0 -194
  215. package/src/mcp/oauth-provider.ts +0 -259
  216. package/src/node.ts +0 -4
  217. package/src/patch/index.ts +0 -686
  218. package/src/permission/arity.ts +0 -163
  219. package/src/permission/evaluate.ts +0 -1
  220. package/src/permission/index.ts +0 -218
  221. package/src/plugin/azure.ts +0 -26
  222. package/src/plugin/cloudflare.ts +0 -76
  223. package/src/plugin/digitalocean.ts +0 -325
  224. package/src/plugin/github-copilot/copilot.ts +0 -414
  225. package/src/plugin/github-copilot/models.ts +0 -246
  226. package/src/plugin/index.ts +0 -314
  227. package/src/plugin/install.ts +0 -439
  228. package/src/plugin/loader.ts +0 -237
  229. package/src/plugin/meta.ts +0 -188
  230. package/src/plugin/openai/README.md +0 -31
  231. package/src/plugin/openai/codex.ts +0 -556
  232. package/src/plugin/openai/ws-pool.ts +0 -270
  233. package/src/plugin/openai/ws.ts +0 -381
  234. package/src/plugin/pty-environment.ts +0 -24
  235. package/src/plugin/shared.ts +0 -323
  236. package/src/plugin/snowflake-cortex.ts +0 -507
  237. package/src/plugin/tui/internal.ts +0 -10
  238. package/src/plugin/tui/runtime.ts +0 -1131
  239. package/src/plugin/xai.ts +0 -626
  240. package/src/project/bootstrap-service.ts +0 -9
  241. package/src/project/bootstrap.ts +0 -58
  242. package/src/project/instance-context.ts +0 -24
  243. package/src/project/instance-runtime.ts +0 -16
  244. package/src/project/instance-store.ts +0 -213
  245. package/src/project/project.ts +0 -483
  246. package/src/project/vcs.ts +0 -423
  247. package/src/provider/auth.ts +0 -229
  248. package/src/provider/error.ts +0 -188
  249. package/src/provider/model-status.ts +0 -8
  250. package/src/provider/provider.ts +0 -1977
  251. package/src/provider/transform.ts +0 -1561
  252. package/src/question/index.ts +0 -161
  253. package/src/question/schema.ts +0 -4
  254. package/src/server/auth.ts +0 -48
  255. package/src/server/event.ts +0 -10
  256. package/src/server/global-lifecycle.ts +0 -28
  257. package/src/server/init-projectors.ts +0 -3
  258. package/src/server/mdns.ts +0 -47
  259. package/src/server/projectors.ts +0 -1
  260. package/src/server/proxy-util.ts +0 -48
  261. package/src/server/routes/instance/httpapi/AGENTS.md +0 -39
  262. package/src/server/routes/instance/httpapi/api.ts +0 -97
  263. package/src/server/routes/instance/httpapi/errors.ts +0 -193
  264. package/src/server/routes/instance/httpapi/groups/config.ts +0 -65
  265. package/src/server/routes/instance/httpapi/groups/control-plane.ts +0 -35
  266. package/src/server/routes/instance/httpapi/groups/control.ts +0 -76
  267. package/src/server/routes/instance/httpapi/groups/event.ts +0 -29
  268. package/src/server/routes/instance/httpapi/groups/experimental.ts +0 -275
  269. package/src/server/routes/instance/httpapi/groups/file.ts +0 -185
  270. package/src/server/routes/instance/httpapi/groups/global.ts +0 -136
  271. package/src/server/routes/instance/httpapi/groups/instance.ts +0 -206
  272. package/src/server/routes/instance/httpapi/groups/mcp.ts +0 -156
  273. package/src/server/routes/instance/httpapi/groups/metadata.ts +0 -18
  274. package/src/server/routes/instance/httpapi/groups/permission.ts +0 -61
  275. package/src/server/routes/instance/httpapi/groups/project-copy.ts +0 -32
  276. package/src/server/routes/instance/httpapi/groups/project.ts +0 -93
  277. package/src/server/routes/instance/httpapi/groups/provider.ts +0 -101
  278. package/src/server/routes/instance/httpapi/groups/pty.ts +0 -172
  279. package/src/server/routes/instance/httpapi/groups/query.ts +0 -12
  280. package/src/server/routes/instance/httpapi/groups/question.ts +0 -74
  281. package/src/server/routes/instance/httpapi/groups/session.ts +0 -462
  282. package/src/server/routes/instance/httpapi/groups/sync.ts +0 -113
  283. package/src/server/routes/instance/httpapi/groups/tui.ts +0 -208
  284. package/src/server/routes/instance/httpapi/groups/workspace.ts +0 -141
  285. package/src/server/routes/instance/httpapi/handlers/config.ts +0 -34
  286. package/src/server/routes/instance/httpapi/handlers/control-plane.ts +0 -37
  287. package/src/server/routes/instance/httpapi/handlers/control.ts +0 -43
  288. package/src/server/routes/instance/httpapi/handlers/event.ts +0 -99
  289. package/src/server/routes/instance/httpapi/handlers/experimental.ts +0 -193
  290. package/src/server/routes/instance/httpapi/handlers/file.ts +0 -139
  291. package/src/server/routes/instance/httpapi/handlers/global.ts +0 -156
  292. package/src/server/routes/instance/httpapi/handlers/instance.ts +0 -110
  293. package/src/server/routes/instance/httpapi/handlers/mcp.ts +0 -111
  294. package/src/server/routes/instance/httpapi/handlers/permission.ts +0 -41
  295. package/src/server/routes/instance/httpapi/handlers/project-copy.ts +0 -83
  296. package/src/server/routes/instance/httpapi/handlers/project.ts +0 -63
  297. package/src/server/routes/instance/httpapi/handlers/provider.ts +0 -113
  298. package/src/server/routes/instance/httpapi/handlers/pty.ts +0 -273
  299. package/src/server/routes/instance/httpapi/handlers/question.ts +0 -54
  300. package/src/server/routes/instance/httpapi/handlers/session-errors.ts +0 -21
  301. package/src/server/routes/instance/httpapi/handlers/session.ts +0 -442
  302. package/src/server/routes/instance/httpapi/handlers/sync.ts +0 -89
  303. package/src/server/routes/instance/httpapi/handlers/tui.ts +0 -131
  304. package/src/server/routes/instance/httpapi/handlers/workspace.ts +0 -102
  305. package/src/server/routes/instance/httpapi/lifecycle.ts +0 -54
  306. package/src/server/routes/instance/httpapi/middleware/authorization.ts +0 -150
  307. package/src/server/routes/instance/httpapi/middleware/compression.ts +0 -64
  308. package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +0 -29
  309. package/src/server/routes/instance/httpapi/middleware/error.ts +0 -43
  310. package/src/server/routes/instance/httpapi/middleware/fence.ts +0 -25
  311. package/src/server/routes/instance/httpapi/middleware/instance-context.ts +0 -43
  312. package/src/server/routes/instance/httpapi/middleware/proxy.ts +0 -108
  313. package/src/server/routes/instance/httpapi/middleware/schema-error.ts +0 -41
  314. package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +0 -250
  315. package/src/server/routes/instance/httpapi/public.ts +0 -537
  316. package/src/server/routes/instance/httpapi/server.ts +0 -322
  317. package/src/server/routes/instance/httpapi/websocket-tracker.ts +0 -60
  318. package/src/server/server.ts +0 -226
  319. package/src/server/shared/fence.ts +0 -60
  320. package/src/server/shared/pty-ticket.ts +0 -15
  321. package/src/server/shared/public-ui.ts +0 -12
  322. package/src/server/shared/tui-control.ts +0 -28
  323. package/src/server/shared/ui.ts +0 -108
  324. package/src/server/shared/workspace-routing.ts +0 -38
  325. package/src/server/tui-event.ts +0 -1
  326. package/src/session/compaction.ts +0 -562
  327. package/src/session/instruction.ts +0 -237
  328. package/src/session/llm/AGENTS.md +0 -90
  329. package/src/session/llm/ai-sdk.ts +0 -288
  330. package/src/session/llm/native-request.ts +0 -196
  331. package/src/session/llm/native-runtime.ts +0 -195
  332. package/src/session/llm/request.ts +0 -226
  333. package/src/session/llm.ts +0 -404
  334. package/src/session/message-error.ts +0 -14
  335. package/src/session/message-v2.ts +0 -734
  336. package/src/session/message.ts +0 -148
  337. package/src/session/overflow.ts +0 -34
  338. package/src/session/processor.ts +0 -716
  339. package/src/session/prompt/anthropic.txt +0 -105
  340. package/src/session/prompt/beast.txt +0 -147
  341. package/src/session/prompt/build-switch.txt +0 -5
  342. package/src/session/prompt/codex.txt +0 -79
  343. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  344. package/src/session/prompt/default.txt +0 -95
  345. package/src/session/prompt/gemini.txt +0 -155
  346. package/src/session/prompt/gpt.txt +0 -107
  347. package/src/session/prompt/kimi.txt +0 -95
  348. package/src/session/prompt/plan-mode.txt +0 -70
  349. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  350. package/src/session/prompt/plan.txt +0 -26
  351. package/src/session/prompt/trinity.txt +0 -97
  352. package/src/session/prompt.ts +0 -1630
  353. package/src/session/reminders.ts +0 -92
  354. package/src/session/retry.ts +0 -201
  355. package/src/session/revert.ts +0 -146
  356. package/src/session/run-state.ts +0 -151
  357. package/src/session/schema.ts +0 -26
  358. package/src/session/session.ts +0 -1018
  359. package/src/session/status.ts +0 -56
  360. package/src/session/summary.ts +0 -160
  361. package/src/session/system.ts +0 -143
  362. package/src/session/todo.ts +0 -74
  363. package/src/session/tools.ts +0 -583
  364. package/src/share/session.ts +0 -58
  365. package/src/share/share-next.ts +0 -371
  366. package/src/skill/discovery.ts +0 -140
  367. package/src/skill/index.ts +0 -354
  368. package/src/snapshot/index.ts +0 -807
  369. package/src/sql.d.ts +0 -4
  370. package/src/storage/schema.ts +0 -5
  371. package/src/storage/storage.ts +0 -327
  372. package/src/sync/README.md +0 -179
  373. package/src/sync/schema.ts +0 -11
  374. package/src/temporary.ts +0 -31
  375. package/src/tool/apply_patch.ts +0 -313
  376. package/src/tool/apply_patch.txt +0 -33
  377. package/src/tool/edit.ts +0 -737
  378. package/src/tool/edit.txt +0 -10
  379. package/src/tool/external-directory.ts +0 -49
  380. package/src/tool/glob.ts +0 -76
  381. package/src/tool/glob.txt +0 -6
  382. package/src/tool/grep.ts +0 -112
  383. package/src/tool/grep.txt +0 -8
  384. package/src/tool/invalid.ts +0 -21
  385. package/src/tool/json-schema.ts +0 -164
  386. package/src/tool/lsp.ts +0 -113
  387. package/src/tool/lsp.txt +0 -24
  388. package/src/tool/mcp-websearch.ts +0 -96
  389. package/src/tool/plan-enter.txt +0 -14
  390. package/src/tool/plan-exit.txt +0 -13
  391. package/src/tool/plan.ts +0 -79
  392. package/src/tool/question.ts +0 -44
  393. package/src/tool/question.txt +0 -10
  394. package/src/tool/read.ts +0 -386
  395. package/src/tool/read.txt +0 -14
  396. package/src/tool/registry.ts +0 -420
  397. package/src/tool/schema.ts +0 -14
  398. package/src/tool/shell/id.ts +0 -19
  399. package/src/tool/shell/prompt.ts +0 -293
  400. package/src/tool/shell/shell.txt +0 -21
  401. package/src/tool/shell.ts +0 -645
  402. package/src/tool/skill.ts +0 -70
  403. package/src/tool/skill.txt +0 -5
  404. package/src/tool/task.ts +0 -346
  405. package/src/tool/task.txt +0 -19
  406. package/src/tool/todo.ts +0 -46
  407. package/src/tool/todowrite.txt +0 -44
  408. package/src/tool/tool.ts +0 -183
  409. package/src/tool/truncate.ts +0 -156
  410. package/src/tool/truncation-dir.ts +0 -4
  411. package/src/tool/webfetch.ts +0 -192
  412. package/src/tool/webfetch.txt +0 -13
  413. package/src/tool/websearch.ts +0 -143
  414. package/src/tool/websearch.txt +0 -14
  415. package/src/tool/write.ts +0 -104
  416. package/src/tool/write.txt +0 -8
  417. package/src/util/archive.ts +0 -17
  418. package/src/util/bom.ts +0 -27
  419. package/src/util/data-url.ts +0 -9
  420. package/src/util/defer.ts +0 -10
  421. package/src/util/effect-http-client.ts +0 -11
  422. package/src/util/error.ts +0 -1
  423. package/src/util/filesystem.ts +0 -251
  424. package/src/util/html.ts +0 -8
  425. package/src/util/iife.ts +0 -3
  426. package/src/util/lazy.ts +0 -20
  427. package/src/util/local-context.ts +0 -25
  428. package/src/util/locale.ts +0 -2
  429. package/src/util/media.ts +0 -26
  430. package/src/util/process.ts +0 -177
  431. package/src/util/proxy-env.ts +0 -72
  432. package/src/util/queue.ts +0 -32
  433. package/src/util/record.ts +0 -1
  434. package/src/util/repository.ts +0 -232
  435. package/src/util/rpc.ts +0 -66
  436. package/src/util/signal.ts +0 -12
  437. package/src/util/timeout.ts +0 -13
  438. package/src/util/token.ts +0 -1
  439. package/src/util/wildcard.ts +0 -59
  440. package/src/worktree/index.ts +0 -623
  441. package/test/AGENTS.md +0 -204
  442. package/test/EFFECT_TEST_MIGRATION.md +0 -169
  443. package/test/account/repo.test.ts +0 -355
  444. package/test/account/service.test.ts +0 -456
  445. package/test/acp/config-option.test.ts +0 -229
  446. package/test/acp/content.test.ts +0 -235
  447. package/test/acp/directory.test.ts +0 -188
  448. package/test/acp/error.test.ts +0 -67
  449. package/test/acp/event.test.ts +0 -751
  450. package/test/acp/permission.test.ts +0 -401
  451. package/test/acp/service-session.test.ts +0 -1248
  452. package/test/acp/session.test.ts +0 -201
  453. package/test/acp/tool.test.ts +0 -298
  454. package/test/acp/usage.test.ts +0 -318
  455. package/test/agent/agent.test.ts +0 -755
  456. package/test/agent/plan-mode-subagent-bypass.test.ts +0 -160
  457. package/test/agent/plugin-agent-regression.test.ts +0 -51
  458. package/test/auth/auth.test.ts +0 -75
  459. package/test/background/job.test.ts +0 -244
  460. package/test/cli/account.test.ts +0 -30
  461. package/test/cli/acp/acp-test-client.ts +0 -97
  462. package/test/cli/acp/config-options.test.ts +0 -103
  463. package/test/cli/acp/helpers.ts +0 -96
  464. package/test/cli/acp/initialize-auth.test.ts +0 -61
  465. package/test/cli/acp/lifecycle.test.ts +0 -118
  466. package/test/cli/acp/prompt-content.test.ts +0 -97
  467. package/test/cli/acp/skills.test.ts +0 -38
  468. package/test/cli/cmd/tui/attention.test.ts +0 -484
  469. package/test/cli/effect-cmd-instance-als.test.ts +0 -40
  470. package/test/cli/error.test.ts +0 -95
  471. package/test/cli/github-action.test.ts +0 -199
  472. package/test/cli/github-remote.test.ts +0 -90
  473. package/test/cli/help/__snapshots__/help-snapshots.test.ts.snap +0 -623
  474. package/test/cli/help/help-snapshots.test.ts +0 -140
  475. package/test/cli/import.test.ts +0 -54
  476. package/test/cli/mcp-add.test.ts +0 -74
  477. package/test/cli/plugin-auth-picker.test.ts +0 -120
  478. package/test/cli/run/entry.body.test.ts +0 -536
  479. package/test/cli/run/footer.menu.test.ts +0 -43
  480. package/test/cli/run/footer.view.test.tsx +0 -1375
  481. package/test/cli/run/footer.width.test.ts +0 -35
  482. package/test/cli/run/permission.shared.test.ts +0 -144
  483. package/test/cli/run/prompt.editor.test.ts +0 -101
  484. package/test/cli/run/prompt.shared.test.ts +0 -101
  485. package/test/cli/run/question.shared.test.ts +0 -115
  486. package/test/cli/run/run-process.test.ts +0 -331
  487. package/test/cli/run/runtime.boot.test.ts +0 -283
  488. package/test/cli/run/runtime.queue.test.ts +0 -481
  489. package/test/cli/run/runtime.stdin.test.ts +0 -71
  490. package/test/cli/run/runtime.test.ts +0 -238
  491. package/test/cli/run/scrollback.surface.test.ts +0 -1092
  492. package/test/cli/run/session-data.test.ts +0 -593
  493. package/test/cli/run/session-replay.test.ts +0 -691
  494. package/test/cli/run/session.shared.test.ts +0 -247
  495. package/test/cli/run/stream.test.ts +0 -56
  496. package/test/cli/run/stream.transport.test.ts +0 -2363
  497. package/test/cli/run/subagent-data.test.ts +0 -547
  498. package/test/cli/run/theme.test.ts +0 -177
  499. package/test/cli/run/variant.shared.test.ts +0 -218
  500. package/test/cli/serve/serve-process.test.ts +0 -61
  501. package/test/cli/smokes/read-only.test.ts +0 -115
  502. package/test/cli/tui/attach.test.ts +0 -11
  503. package/test/cli/tui/editor-context-zed.test.ts +0 -379
  504. package/test/cli/tui/editor-context.test.tsx +0 -297
  505. package/test/cli/tui/plugin-add.test.ts +0 -110
  506. package/test/cli/tui/plugin-install.test.ts +0 -87
  507. package/test/cli/tui/plugin-lifecycle.test.ts +0 -224
  508. package/test/cli/tui/plugin-loader-entrypoint.test.ts +0 -485
  509. package/test/cli/tui/plugin-loader-pure.test.ts +0 -72
  510. package/test/cli/tui/plugin-loader.test.ts +0 -1332
  511. package/test/cli/tui/plugin-toggle.test.ts +0 -264
  512. package/test/cli/tui/thread.test.ts +0 -95
  513. package/test/config/agent-color.test.ts +0 -47
  514. package/test/config/config.test.ts +0 -2027
  515. package/test/config/entry-name.test.ts +0 -57
  516. package/test/config/fixtures/empty-frontmatter.md +0 -4
  517. package/test/config/fixtures/frontmatter.md +0 -28
  518. package/test/config/fixtures/markdown-header.md +0 -11
  519. package/test/config/fixtures/no-frontmatter.md +0 -1
  520. package/test/config/fixtures/weird-model-id.md +0 -13
  521. package/test/config/lsp.test.ts +0 -69
  522. package/test/config/markdown.test.ts +0 -228
  523. package/test/config/plugin.test.ts +0 -0
  524. package/test/config/tui.test.ts +0 -894
  525. package/test/control-plane/adapters.test.ts +0 -71
  526. package/test/control-plane/workspace.test.ts +0 -1701
  527. package/test/effect/app-runtime-logger.test.ts +0 -101
  528. package/test/effect/config-service.test.ts +0 -65
  529. package/test/effect/instance-state.test.ts +0 -392
  530. package/test/effect/run-service.test.ts +0 -89
  531. package/test/effect/runner.test.ts +0 -514
  532. package/test/effect/runtime-flags.test.ts +0 -374
  533. package/test/event-manifest.test.ts +0 -24
  534. package/test/fake/account.ts +0 -9
  535. package/test/fake/auth.ts +0 -8
  536. package/test/fake/npm.ts +0 -8
  537. package/test/fake/provider.ts +0 -82
  538. package/test/fake/skill.ts +0 -8
  539. package/test/filesystem/filesystem.test.ts +0 -318
  540. package/test/fixture/agent-plugin.constants.ts +0 -6
  541. package/test/fixture/agent-plugin.ts +0 -12
  542. package/test/fixture/config.ts +0 -23
  543. package/test/fixture/db.ts +0 -11
  544. package/test/fixture/fixture.test.ts +0 -26
  545. package/test/fixture/fixture.ts +0 -228
  546. package/test/fixture/flag.ts +0 -20
  547. package/test/fixture/flock-worker.ts +0 -72
  548. package/test/fixture/lsp/fake-lsp-server.js +0 -249
  549. package/test/fixture/mcp-session-recovery.ts +0 -50
  550. package/test/fixture/plug-worker.ts +0 -93
  551. package/test/fixture/plugin-meta-worker.ts +0 -19
  552. package/test/fixture/plugin.ts +0 -10
  553. package/test/fixture/skills/agents-sdk/SKILL.md +0 -152
  554. package/test/fixture/skills/agents-sdk/references/callable.md +0 -92
  555. package/test/fixture/skills/cloudflare/SKILL.md +0 -211
  556. package/test/fixture/skills/index.json +0 -6
  557. package/test/fixture/tui-environment.tsx +0 -32
  558. package/test/fixture/tui-plugin.ts +0 -355
  559. package/test/fixture/tui-runtime.ts +0 -56
  560. package/test/fixture/tui-sdk.ts +0 -82
  561. package/test/fixture/workspace.ts +0 -34
  562. package/test/fixtures/recordings/session/native-anthropic-tool-loop.json +0 -49
  563. package/test/fixtures/recordings/session/native-openai-oauth-tool-loop.json +0 -45
  564. package/test/fixtures/recordings/session/native-zen-tool-loop.json +0 -49
  565. package/test/format/format.test.ts +0 -235
  566. package/test/git/git.test.ts +0 -179
  567. package/test/ide/ide.test.ts +0 -82
  568. package/test/image/fixtures/picture-5mb-base64.png +0 -0
  569. package/test/image/image.test.ts +0 -121
  570. package/test/installation/installation.test.ts +0 -240
  571. package/test/lib/cli-process.ts +0 -535
  572. package/test/lib/effect.ts +0 -177
  573. package/test/lib/filesystem.ts +0 -10
  574. package/test/lib/llm-server.ts +0 -779
  575. package/test/lib/snapshot.ts +0 -73
  576. package/test/lib/test-provider.ts +0 -37
  577. package/test/lib/websocket.ts +0 -46
  578. package/test/lsp/client.test.ts +0 -488
  579. package/test/lsp/index.test.ts +0 -231
  580. package/test/lsp/jdtls-root.test.ts +0 -459
  581. package/test/lsp/launch.test.ts +0 -22
  582. package/test/lsp/lifecycle.test.ts +0 -160
  583. package/test/mcp/auth.test.ts +0 -78
  584. package/test/mcp/catalog.test.ts +0 -47
  585. package/test/mcp/headers.test.ts +0 -127
  586. package/test/mcp/lifecycle.test.ts +0 -1304
  587. package/test/mcp/oauth-auto-connect.test.ts +0 -367
  588. package/test/mcp/oauth-browser.test.ts +0 -243
  589. package/test/mcp/oauth-callback.test.ts +0 -114
  590. package/test/mcp/oauth-provider.test.ts +0 -102
  591. package/test/mcp/session-recovery.test.ts +0 -27
  592. package/test/patch/patch.test.ts +0 -384
  593. package/test/permission/arity.test.ts +0 -33
  594. package/test/permission/next.test.ts +0 -1174
  595. package/test/permission-task.test.ts +0 -319
  596. package/test/plugin/auth-override.test.ts +0 -101
  597. package/test/plugin/cloudflare.test.ts +0 -68
  598. package/test/plugin/codex.test.ts +0 -256
  599. package/test/plugin/github-copilot-models.test.ts +0 -332
  600. package/test/plugin/install-concurrency.test.ts +0 -140
  601. package/test/plugin/install.test.ts +0 -570
  602. package/test/plugin/loader-shared.test.ts +0 -1306
  603. package/test/plugin/meta.test.ts +0 -137
  604. package/test/plugin/openai-rollout.test.ts +0 -17
  605. package/test/plugin/openai-ws.test.ts +0 -884
  606. package/test/plugin/shared.test.ts +0 -88
  607. package/test/plugin/snowflake-cortex.test.ts +0 -278
  608. package/test/plugin/trigger.test.ts +0 -108
  609. package/test/plugin/workspace-adapter.test.ts +0 -111
  610. package/test/plugin/xai.test.ts +0 -620
  611. package/test/preload.ts +0 -92
  612. package/test/project/instance-bootstrap.test.ts +0 -115
  613. package/test/project/instance.test.ts +0 -248
  614. package/test/project/migrate-global.test.ts +0 -168
  615. package/test/project/project-directory.test.ts +0 -202
  616. package/test/project/project.test.ts +0 -808
  617. package/test/project/vcs.test.ts +0 -335
  618. package/test/project/worktree-remove.test.ts +0 -128
  619. package/test/project/worktree.test.ts +0 -324
  620. package/test/provider/amazon-bedrock.test.ts +0 -361
  621. package/test/provider/cf-ai-gateway-e2e.test.ts +0 -132
  622. package/test/provider/digitalocean.test.ts +0 -124
  623. package/test/provider/gitlab-duo.test.ts +0 -412
  624. package/test/provider/header-timeout.test.ts +0 -234
  625. package/test/provider/model-status.test.ts +0 -61
  626. package/test/provider/provider.test.ts +0 -1912
  627. package/test/provider/transform.test.ts +0 -4742
  628. package/test/question/question.test.ts +0 -459
  629. package/test/server/AGENTS.md +0 -15
  630. package/test/server/auth.test.ts +0 -59
  631. package/test/server/global-bus.ts +0 -31
  632. package/test/server/global-session-list.test.ts +0 -108
  633. package/test/server/httpapi-authorization.test.ts +0 -174
  634. package/test/server/httpapi-compression.test.ts +0 -151
  635. package/test/server/httpapi-config.test.ts +0 -110
  636. package/test/server/httpapi-control-plane.test.ts +0 -63
  637. package/test/server/httpapi-cors-vary.test.ts +0 -63
  638. package/test/server/httpapi-cors.test.ts +0 -122
  639. package/test/server/httpapi-error-middleware.test.ts +0 -101
  640. package/test/server/httpapi-event.test.ts +0 -94
  641. package/test/server/httpapi-exercise/assertions.ts +0 -64
  642. package/test/server/httpapi-exercise/backend.ts +0 -144
  643. package/test/server/httpapi-exercise/dsl.ts +0 -210
  644. package/test/server/httpapi-exercise/environment.ts +0 -40
  645. package/test/server/httpapi-exercise/index.ts +0 -1814
  646. package/test/server/httpapi-exercise/report.ts +0 -66
  647. package/test/server/httpapi-exercise/routing.ts +0 -96
  648. package/test/server/httpapi-exercise/runner.ts +0 -267
  649. package/test/server/httpapi-exercise/runtime.ts +0 -52
  650. package/test/server/httpapi-exercise/types.ts +0 -127
  651. package/test/server/httpapi-experimental.test.ts +0 -298
  652. package/test/server/httpapi-file.test.ts +0 -83
  653. package/test/server/httpapi-global.test.ts +0 -66
  654. package/test/server/httpapi-instance-context.test.ts +0 -337
  655. package/test/server/httpapi-instance-route-auth.test.ts +0 -81
  656. package/test/server/httpapi-instance.test.ts +0 -265
  657. package/test/server/httpapi-layer.ts +0 -33
  658. package/test/server/httpapi-listen.test.ts +0 -465
  659. package/test/server/httpapi-mcp-oauth.test.ts +0 -73
  660. package/test/server/httpapi-mcp.test.ts +0 -223
  661. package/test/server/httpapi-mdns.test.ts +0 -79
  662. package/test/server/httpapi-promptasync-context.test.ts +0 -212
  663. package/test/server/httpapi-provider.test.ts +0 -401
  664. package/test/server/httpapi-pty.test.ts +0 -299
  665. package/test/server/httpapi-public-openapi.test.ts +0 -350
  666. package/test/server/httpapi-query-schema-drift.test.ts +0 -330
  667. package/test/server/httpapi-reference.test.ts +0 -63
  668. package/test/server/httpapi-schema-error-body.test.ts +0 -166
  669. package/test/server/httpapi-sdk.test.ts +0 -913
  670. package/test/server/httpapi-session.test.ts +0 -1090
  671. package/test/server/httpapi-sync.test.ts +0 -149
  672. package/test/server/httpapi-ui.test.ts +0 -456
  673. package/test/server/httpapi-v2-location.test.ts +0 -126
  674. package/test/server/httpapi-v2-pty.test.ts +0 -250
  675. package/test/server/httpapi-workspace-routing.test.ts +0 -552
  676. package/test/server/httpapi-workspace.test.ts +0 -506
  677. package/test/server/negative-tokens-regression.test.ts +0 -84
  678. package/test/server/project-copy.test.ts +0 -127
  679. package/test/server/project-init-git.test.ts +0 -118
  680. package/test/server/proxy-util.test.ts +0 -113
  681. package/test/server/sdk-error-shape.test.ts +0 -81
  682. package/test/server/sdk-v1-smoke.test.ts +0 -57
  683. package/test/server/session-actions.test.ts +0 -110
  684. package/test/server/session-diff-missing-patch.test.ts +0 -97
  685. package/test/server/session-list.test.ts +0 -302
  686. package/test/server/session-messages.test.ts +0 -180
  687. package/test/server/session-select.test.ts +0 -67
  688. package/test/server/workspace-proxy.test.ts +0 -181
  689. package/test/server/workspace-routing.test.ts +0 -94
  690. package/test/server/worktree-endpoint-repro.test.ts +0 -307
  691. package/test/session/compaction.test.ts +0 -1819
  692. package/test/session/instruction.test.ts +0 -264
  693. package/test/session/llm-native-recorded.test.ts +0 -413
  694. package/test/session/llm-native.test.ts +0 -761
  695. package/test/session/llm.test.ts +0 -2003
  696. package/test/session/message-v2.test.ts +0 -1661
  697. package/test/session/messages-pagination.test.ts +0 -1057
  698. package/test/session/processor-effect.test.ts +0 -1067
  699. package/test/session/prompt.test.ts +0 -2402
  700. package/test/session/retry.test.ts +0 -440
  701. package/test/session/revert-compact.test.ts +0 -638
  702. package/test/session/schema-decoding.test.ts +0 -313
  703. package/test/session/session-schema.test.ts +0 -78
  704. package/test/session/session.test.ts +0 -253
  705. package/test/session/snapshot-tool-race.test.ts +0 -189
  706. package/test/session/structured-output-integration.test.ts +0 -235
  707. package/test/session/structured-output.test.ts +0 -387
  708. package/test/session/system.test.ts +0 -142
  709. package/test/share/share-next.test.ts +0 -324
  710. package/test/skill/discovery.test.ts +0 -186
  711. package/test/skill/skill.test.ts +0 -585
  712. package/test/snapshot/snapshot.test.ts +0 -1218
  713. package/test/storage/storage.test.ts +0 -297
  714. package/test/tool/__snapshots__/parameters.test.ts.snap +0 -466
  715. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  716. package/test/tool/apply_patch.test.ts +0 -529
  717. package/test/tool/edit.test.ts +0 -574
  718. package/test/tool/external-directory.test.ts +0 -156
  719. package/test/tool/fixtures/large-image.png +0 -0
  720. package/test/tool/fixtures/models-api.json +0 -117299
  721. package/test/tool/glob.test.ts +0 -132
  722. package/test/tool/grep.test.ts +0 -221
  723. package/test/tool/lsp.test.ts +0 -184
  724. package/test/tool/parameters.test.ts +0 -290
  725. package/test/tool/question.test.ts +0 -133
  726. package/test/tool/read.test.ts +0 -608
  727. package/test/tool/registry.test.ts +0 -493
  728. package/test/tool/shell.test.ts +0 -1199
  729. package/test/tool/skill.test.ts +0 -134
  730. package/test/tool/task.test.ts +0 -905
  731. package/test/tool/tool-define.test.ts +0 -154
  732. package/test/tool/truncation.test.ts +0 -264
  733. package/test/tool/webfetch.test.ts +0 -119
  734. package/test/tool/websearch.test.ts +0 -99
  735. package/test/tool/write.test.ts +0 -279
  736. package/test/util/data-url.test.ts +0 -14
  737. package/test/util/error.test.ts +0 -16
  738. package/test/util/filesystem.test.ts +0 -656
  739. package/test/util/glob.test.ts +0 -164
  740. package/test/util/html.test.ts +0 -15
  741. package/test/util/iife.test.ts +0 -36
  742. package/test/util/lazy.test.ts +0 -50
  743. package/test/util/module.test.ts +0 -59
  744. package/test/util/process.test.ts +0 -128
  745. package/test/util/repository.test.ts +0 -93
  746. package/test/util/timeout.test.ts +0 -21
  747. package/test/util/wildcard.test.ts +0 -90
  748. package/test/v2/session-message-updater.test.ts +0 -269
  749. package/tsconfig.json +0 -16
@@ -1,2402 +0,0 @@
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
- )