saeeol 1.2.4 → 1.2.7

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 (483) hide show
  1. package/bin/saeeol.cjs +2 -1
  2. package/package.json +15 -12
  3. package/src/ltm/config.ts +15 -15
  4. package/src/ltm/events.ts +1 -1
  5. package/src/ltm/index.ts +1 -1
  6. package/src/ltm/pipeline.ts +23 -23
  7. package/src/ltm/scheduler.ts +91 -17
  8. package/src/ltm/store.ts +9 -7
  9. package/src/ltm/types.ts +15 -15
  10. package/src/provider/local/embedder.ts +24 -24
  11. package/src/provider/models-snapshot.d.ts +2 -0
  12. package/src/provider/models-snapshot.js +3 -0
  13. package/src/session/message/message-errors.ts +1 -1
  14. package/src/session/message/message-parts.ts +1 -1
  15. package/src/session/message/message-transform.ts +1 -1
  16. package/src/session/message/message-types.ts +1 -1
  17. package/src/tool/core/tool.ts +1 -1
  18. package/AGENTS.md +0 -72
  19. package/BUN_SHELL_MIGRATION_PLAN.md +0 -136
  20. package/Dockerfile +0 -18
  21. package/assets/saeeol.ico +0 -0
  22. package/bin/saeeol +0 -187
  23. package/bunfig.toml +0 -7
  24. package/database.db +0 -0
  25. package/drizzle.config.ts +0 -10
  26. package/git +0 -0
  27. package/migration/20260127222353_familiar_lady_ursula/migration.sql +0 -90
  28. package/migration/20260127222353_familiar_lady_ursula/snapshot.json +0 -796
  29. package/migration/20260211171708_add_project_commands/migration.sql +0 -1
  30. package/migration/20260211171708_add_project_commands/snapshot.json +0 -806
  31. package/migration/20260213144116_wakeful_the_professor/migration.sql +0 -11
  32. package/migration/20260213144116_wakeful_the_professor/snapshot.json +0 -897
  33. package/migration/20260225215848_workspace/migration.sql +0 -7
  34. package/migration/20260225215848_workspace/snapshot.json +0 -959
  35. package/migration/20260227213759_add_session_workspace_id/migration.sql +0 -2
  36. package/migration/20260227213759_add_session_workspace_id/snapshot.json +0 -983
  37. package/migration/20260228203230_blue_harpoon/migration.sql +0 -17
  38. package/migration/20260228203230_blue_harpoon/snapshot.json +0 -1102
  39. package/migration/20260303231226_add_workspace_fields/migration.sql +0 -5
  40. package/migration/20260303231226_add_workspace_fields/snapshot.json +0 -1013
  41. package/migration/20260309230000_move_org_to_state/migration.sql +0 -3
  42. package/migration/20260309230000_move_org_to_state/snapshot.json +0 -1156
  43. package/migration/20260312043431_session_message_cursor/migration.sql +0 -4
  44. package/migration/20260312043431_session_message_cursor/snapshot.json +0 -1168
  45. package/migration/20260323234822_events/migration.sql +0 -13
  46. package/migration/20260323234822_events/snapshot.json +0 -1271
  47. package/migration/20260410174513_workspace-name/migration.sql +0 -16
  48. package/migration/20260410174513_workspace-name/snapshot.json +0 -1271
  49. package/migration/20260413175956_chief_energizer/migration.sql +0 -13
  50. package/migration/20260413175956_chief_energizer/snapshot.json +0 -1399
  51. package/migration/20260423070820_add_icon_url_override/migration.sql +0 -2
  52. package/migration/20260423070820_add_icon_url_override/snapshot.json +0 -1409
  53. package/migration/20260428004200_add_session_path/migration.sql +0 -1
  54. package/migration/20260428004200_add_session_path/snapshot.json +0 -1419
  55. package/npm/bin/saeeol +0 -42
  56. package/npm/package.json +0 -39
  57. package/npm/postinstall.js +0 -162
  58. package/parsers-config.ts +0 -289
  59. package/script/build.ts +0 -393
  60. package/script/check-migrations.ts +0 -16
  61. package/script/fix-node-pty.ts +0 -34
  62. package/script/generate.ts +0 -23
  63. package/script/postinstall.mjs +0 -189
  64. package/script/publish.ts +0 -200
  65. package/script/run-workspace-server +0 -106
  66. package/script/schema.ts +0 -63
  67. package/script/test-runner.ts +0 -420
  68. package/script/time.ts +0 -6
  69. package/script/trace-imports.ts +0 -153
  70. package/script/upgrade-opentui.ts +0 -64
  71. package/scripts/diff-sdk-types.sh +0 -52
  72. package/specs/effect/facades.md +0 -221
  73. package/specs/effect/http-api.md +0 -401
  74. package/specs/effect/instance-context.md +0 -309
  75. package/specs/effect/loose-ends.md +0 -34
  76. package/specs/effect/migration.md +0 -299
  77. package/specs/effect/routes.md +0 -64
  78. package/specs/effect/schema.md +0 -399
  79. package/specs/effect/server-package.md +0 -668
  80. package/specs/effect/tools.md +0 -90
  81. package/specs/tui-plugins.md +0 -433
  82. package/specs/v2/api.ts +0 -67
  83. package/specs/v2/keymappings.md +0 -10
  84. package/specs/v2/message-shape.md +0 -136
  85. package/src/tool/apply_patch.txt +0 -33
  86. package/src/tool/bash.txt +0 -119
  87. package/src/tool/edit.txt +0 -10
  88. package/src/tool/glob.txt +0 -6
  89. package/src/tool/grep.txt +0 -8
  90. package/src/tool/lsp.txt +0 -24
  91. package/src/tool/plan-enter.txt +0 -14
  92. package/src/tool/plan-exit.txt +0 -13
  93. package/src/tool/question.txt +0 -11
  94. package/src/tool/read.txt +0 -14
  95. package/src/tool/recall.txt +0 -12
  96. package/src/tool/skill.txt +0 -5
  97. package/src/tool/task.txt +0 -57
  98. package/src/tool/todowrite.txt +0 -167
  99. package/src/tool/warpgrep.txt +0 -10
  100. package/src/tool/webfetch.txt +0 -13
  101. package/src/tool/websearch.txt +0 -14
  102. package/src/tool/write.txt +0 -8
  103. package/sst-env.d.ts +0 -10
  104. package/test/AGENTS.md +0 -133
  105. package/test/account/repo.test.ts +0 -352
  106. package/test/account/service.test.ts +0 -456
  107. package/test/acp/agent-interface.test.ts +0 -51
  108. package/test/acp/event-subscription.test.ts +0 -725
  109. package/test/agent/agent.test.ts +0 -890
  110. package/test/auth/auth.test.ts +0 -86
  111. package/test/bun/registry.test.ts +0 -75
  112. package/test/bus/bus-effect.test.ts +0 -161
  113. package/test/bus/bus-integration.test.ts +0 -87
  114. package/test/bus/bus.test.ts +0 -219
  115. package/test/cli/account.test.ts +0 -26
  116. package/test/cli/auto-mode.test.ts +0 -75
  117. package/test/cli/bin-saeeol.test.ts +0 -8
  118. package/test/cli/cmd/tui/prompt-part.test.ts +0 -47
  119. package/test/cli/cmd/tui/prompt-traits.test.ts +0 -38
  120. package/test/cli/cmd/tui/sync.test.tsx +0 -159
  121. package/test/cli/error.test.ts +0 -18
  122. package/test/cli/github-action.test.ts +0 -198
  123. package/test/cli/github-remote.test.ts +0 -85
  124. package/test/cli/import.test.ts +0 -97
  125. package/test/cli/install-artifact.test.ts +0 -72
  126. package/test/cli/plugin-auth-picker.test.ts +0 -120
  127. package/test/cli/pr.test.ts +0 -59
  128. package/test/cli/tui/editor-context-zed.test.ts +0 -356
  129. package/test/cli/tui/editor-context.test.tsx +0 -228
  130. package/test/cli/tui/keybind-plugin.test.ts +0 -90
  131. package/test/cli/tui/markdown.test.ts +0 -161
  132. package/test/cli/tui/plugin-add.test.ts +0 -111
  133. package/test/cli/tui/plugin-install.test.ts +0 -87
  134. package/test/cli/tui/plugin-lifecycle.test.ts +0 -224
  135. package/test/cli/tui/plugin-loader-entrypoint.test.ts +0 -484
  136. package/test/cli/tui/plugin-loader-pure.test.ts +0 -71
  137. package/test/cli/tui/plugin-loader.test.ts +0 -816
  138. package/test/cli/tui/plugin-toggle.test.ts +0 -157
  139. package/test/cli/tui/revert-diff.test.ts +0 -35
  140. package/test/cli/tui/slot-replace.test.tsx +0 -47
  141. package/test/cli/tui/theme-store.test.ts +0 -54
  142. package/test/cli/tui/thread.test.ts +0 -28
  143. package/test/cli/tui/transcript.test.ts +0 -426
  144. package/test/cli/tui/usage.test.ts +0 -60
  145. package/test/cli/tui/use-event.test.tsx +0 -175
  146. package/test/config/agent-color.test.ts +0 -67
  147. package/test/config/config.test.ts +0 -2544
  148. package/test/config/fixtures/empty-frontmatter.md +0 -4
  149. package/test/config/fixtures/frontmatter.md +0 -28
  150. package/test/config/fixtures/markdown-header.md +0 -11
  151. package/test/config/fixtures/no-frontmatter.md +0 -1
  152. package/test/config/fixtures/weird-model-id.md +0 -13
  153. package/test/config/lsp.test.ts +0 -87
  154. package/test/config/markdown.test.ts +0 -228
  155. package/test/config/plugin.test.ts +0 -0
  156. package/test/config/tui.test.ts +0 -624
  157. package/test/control-plane/adapters.test.ts +0 -71
  158. package/test/control-plane/workspace.test.ts +0 -1526
  159. package/test/effect/app-runtime-logger.test.ts +0 -98
  160. package/test/effect/config-service.test.ts +0 -65
  161. package/test/effect/instance-state.test.ts +0 -394
  162. package/test/effect/run-service.test.ts +0 -89
  163. package/test/effect/runner.test.ts +0 -523
  164. package/test/fake/provider.ts +0 -82
  165. package/test/file/fsmonitor.test.ts +0 -68
  166. package/test/file/ignore.test.ts +0 -10
  167. package/test/file/index.test.ts +0 -954
  168. package/test/file/path-traversal.test.ts +0 -205
  169. package/test/file/ripgrep.test.ts +0 -226
  170. package/test/file/watcher.test.ts +0 -249
  171. package/test/filesystem/filesystem.test.ts +0 -319
  172. package/test/fixture/db.ts +0 -11
  173. package/test/fixture/fixture.test.ts +0 -26
  174. package/test/fixture/fixture.ts +0 -175
  175. package/test/fixture/flock-worker.ts +0 -72
  176. package/test/fixture/log-init-worker.ts +0 -62
  177. package/test/fixture/lsp/fake-lsp-server.js +0 -249
  178. package/test/fixture/plug-worker.ts +0 -93
  179. package/test/fixture/plugin-meta-worker.ts +0 -19
  180. package/test/fixture/skills/agents-sdk/SKILL.md +0 -152
  181. package/test/fixture/skills/cloudflare/SKILL.md +0 -211
  182. package/test/fixture/skills/index.json +0 -6
  183. package/test/fixture/tui-plugin.ts +0 -323
  184. package/test/fixture/tui-runtime.ts +0 -31
  185. package/test/format/format.test.ts +0 -272
  186. package/test/git/git.test.ts +0 -128
  187. package/test/ide/ide.test.ts +0 -82
  188. package/test/installation/installation.test.ts +0 -168
  189. package/test/keybind.test.ts +0 -421
  190. package/test/lib/effect.ts +0 -53
  191. package/test/lib/filesystem.ts +0 -10
  192. package/test/lib/llm-server.ts +0 -778
  193. package/test/lib/websocket.ts +0 -46
  194. package/test/lsp/client.test.ts +0 -482
  195. package/test/lsp/index.test.ts +0 -160
  196. package/test/lsp/launch.test.ts +0 -22
  197. package/test/lsp/lifecycle.test.ts +0 -184
  198. package/test/mcp/headers.test.ts +0 -178
  199. package/test/mcp/lifecycle.test.ts +0 -787
  200. package/test/mcp/oauth-auto-connect.test.ts +0 -311
  201. package/test/mcp/oauth-browser.test.ts +0 -276
  202. package/test/mcp/oauth-callback.test.ts +0 -34
  203. package/test/memory/abort-leak-webfetch.ts +0 -49
  204. package/test/memory/abort-leak.test.ts +0 -128
  205. package/test/patch/patch.test.ts +0 -348
  206. package/test/permission/arity.test.ts +0 -33
  207. package/test/permission/next.test.ts +0 -1227
  208. package/test/permission/next.toConfig.test.ts +0 -110
  209. package/test/permission-task.test.ts +0 -326
  210. package/test/plugin/auth-override.test.ts +0 -79
  211. package/test/plugin/cloudflare.test.ts +0 -68
  212. package/test/plugin/codex.test.ts +0 -123
  213. package/test/plugin/github-copilot-models.test.ts +0 -261
  214. package/test/plugin/install-concurrency.test.ts +0 -140
  215. package/test/plugin/install.test.ts +0 -570
  216. package/test/plugin/loader-shared.test.ts +0 -1169
  217. package/test/plugin/meta.test.ts +0 -137
  218. package/test/plugin/shared.test.ts +0 -88
  219. package/test/plugin/trigger.test.ts +0 -102
  220. package/test/plugin/workspace-adapter.test.ts +0 -109
  221. package/test/preload.ts +0 -77
  222. package/test/project/instance.test.ts +0 -276
  223. package/test/project/migrate-global.test.ts +0 -152
  224. package/test/project/project.test.ts +0 -600
  225. package/test/project/vcs.test.ts +0 -286
  226. package/test/project/worktree-remove.test.ts +0 -126
  227. package/test/project/worktree.test.ts +0 -223
  228. package/test/provider/amazon-bedrock.test.ts +0 -462
  229. package/test/provider/copilot/convert-to-copilot-messages.test.ts +0 -523
  230. package/test/provider/copilot/copilot-chat-model.test.ts +0 -592
  231. package/test/provider/gitlab-duo.test.ts +0 -413
  232. package/test/provider/local.test.ts +0 -208
  233. package/test/provider/models.test.ts +0 -261
  234. package/test/provider/provider-category.test.ts +0 -190
  235. package/test/provider/provider.test.ts +0 -2758
  236. package/test/provider/transform.test.ts +0 -3681
  237. package/test/pty/pty-output-isolation.test.ts +0 -147
  238. package/test/pty/pty-session.test.ts +0 -102
  239. package/test/pty/pty-shell.test.ts +0 -104
  240. package/test/question/question.test.ts +0 -490
  241. package/test/saeeol/agent-global-config-dirs.test.ts +0 -24
  242. package/test/saeeol/agent-manager-tool.test.ts +0 -71
  243. package/test/saeeol/agent-permission-overrides.test.ts +0 -75
  244. package/test/saeeol/agent-skill-permissions.test.ts +0 -37
  245. package/test/saeeol/ask-agent-permissions.test.ts +0 -303
  246. package/test/saeeol/bash-hierarchy.test.ts +0 -64
  247. package/test/saeeol/bash-permission-metadata.test.ts +0 -66
  248. package/test/saeeol/bash-security-extended.test.ts +0 -243
  249. package/test/saeeol/bedrock-claude-empty-content.test.ts +0 -138
  250. package/test/saeeol/boxes-integration.test.ts +0 -415
  251. package/test/saeeol/builtin-skills.test.ts +0 -75
  252. package/test/saeeol/cleanup.ts +0 -28
  253. package/test/saeeol/cli/dev-setup.test.ts +0 -74
  254. package/test/saeeol/cli/roll-call.test.ts +0 -161
  255. package/test/saeeol/cli-run-auto-helper.test.ts +0 -58
  256. package/test/saeeol/codex-auth-refresh.test.ts +0 -124
  257. package/test/saeeol/commit-message/generate.test.ts +0 -188
  258. package/test/saeeol/commit-message/git-context.test.ts +0 -303
  259. package/test/saeeol/commit-message-windows.test.ts +0 -38
  260. package/test/saeeol/compaction-payload-recovery.test.ts +0 -406
  261. package/test/saeeol/compaction-preservation-audit.test.ts +0 -122
  262. package/test/saeeol/compaction-skip-guard.test.ts +0 -224
  263. package/test/saeeol/compaction-smart-select.test.ts +0 -100
  264. package/test/saeeol/config/config.test.ts +0 -166
  265. package/test/saeeol/config/indexing-default-plugin.test.ts +0 -82
  266. package/test/saeeol/config/opentelemetry-default.test.ts +0 -29
  267. package/test/saeeol/config-gitignore.test.ts +0 -70
  268. package/test/saeeol/config-injector.test.ts +0 -305
  269. package/test/saeeol/config-resilience.test.ts +0 -234
  270. package/test/saeeol/config-validation.test.ts +0 -183
  271. package/test/saeeol/cost-propagation.test.ts +0 -94
  272. package/test/saeeol/cost-tracker-extended.test.ts +0 -141
  273. package/test/saeeol/cost-tracker.test.ts +0 -64
  274. package/test/saeeol/custom-provider-delete.test.ts +0 -149
  275. package/test/saeeol/diff-full.test.ts +0 -226
  276. package/test/saeeol/edit-permission-filediff.test.ts +0 -223
  277. package/test/saeeol/encoding.test.ts +0 -364
  278. package/test/saeeol/enhance-prompt.test.ts +0 -61
  279. package/test/saeeol/ensure-plan-dir.test.ts +0 -32
  280. package/test/saeeol/errors.test.ts +0 -144
  281. package/test/saeeol/external-directory-boundary.test.ts +0 -96
  282. package/test/saeeol/gateway-headers.test.ts +0 -88
  283. package/test/saeeol/help.test.ts +0 -191
  284. package/test/saeeol/ignore-migrator.test.ts +0 -308
  285. package/test/saeeol/indexing-auth.test.ts +0 -45
  286. package/test/saeeol/indexing-feature.test.ts +0 -44
  287. package/test/saeeol/indexing-label.test.ts +0 -70
  288. package/test/saeeol/indexing-startup.test.ts +0 -381
  289. package/test/saeeol/indexing-worktree.test.ts +0 -73
  290. package/test/saeeol/instruction.test.ts +0 -136
  291. package/test/saeeol/lancedb-runtime.test.ts +0 -116
  292. package/test/saeeol/loader-auth.test.ts +0 -168
  293. package/test/saeeol/local-model.test.ts +0 -621
  294. package/test/saeeol/logo.test.ts +0 -31
  295. package/test/saeeol/lsp-typescript-lightweight.test.ts +0 -89
  296. package/test/saeeol/mcp-branding.test.ts +0 -33
  297. package/test/saeeol/mcp-docker-rm.test.ts +0 -32
  298. package/test/saeeol/mcp-migrator.test.ts +0 -736
  299. package/test/saeeol/mcp-oauth-callback.test.ts +0 -33
  300. package/test/saeeol/memory-io.test.ts +0 -198
  301. package/test/saeeol/memory-paths.test.ts +0 -87
  302. package/test/saeeol/memory-security.test.ts +0 -166
  303. package/test/saeeol/model-cache-org.test.ts +0 -164
  304. package/test/saeeol/model-info-panel-utils.test.ts +0 -52
  305. package/test/saeeol/model-info-panel.types.test.ts +0 -7
  306. package/test/saeeol/models-401-fallback.test.ts +0 -52
  307. package/test/saeeol/modes-migrator.test.ts +0 -320
  308. package/test/saeeol/nvidia-headers.test.ts +0 -74
  309. package/test/saeeol/patch-jsonc.test.ts +0 -73
  310. package/test/saeeol/patch.test.ts +0 -172
  311. package/test/saeeol/paths.test.ts +0 -265
  312. package/test/saeeol/permission/config-paths.test.ts +0 -174
  313. package/test/saeeol/permission/env-read.test.ts +0 -149
  314. package/test/saeeol/permission/external-directory-allow.test.ts +0 -327
  315. package/test/saeeol/permission/next.always-rules.test.ts +0 -882
  316. package/test/saeeol/permission/next.reply-http.test.ts +0 -205
  317. package/test/saeeol/permission/next.reply-routing.test.ts +0 -184
  318. package/test/saeeol/plan-exit-detection.test.ts +0 -494
  319. package/test/saeeol/plan-followup.test.ts +0 -1376
  320. package/test/saeeol/project-config-update.test.ts +0 -120
  321. package/test/saeeol/project-id.test.ts +0 -455
  322. package/test/saeeol/provider-cost.test.ts +0 -171
  323. package/test/saeeol/provider-list-failed-state.test.ts +0 -100
  324. package/test/saeeol/question-dismiss-all.test.ts +0 -174
  325. package/test/saeeol/read-directory.test.ts +0 -116
  326. package/test/saeeol/rules-migrator.test.ts +0 -257
  327. package/test/saeeol/run-auto.test.ts +0 -176
  328. package/test/saeeol/run-network.test.ts +0 -224
  329. package/test/saeeol/semantic-search.test.ts +0 -186
  330. package/test/saeeol/server/permission-allow-everything.test.ts +0 -125
  331. package/test/saeeol/session/instruction-substitution.test.ts +0 -72
  332. package/test/saeeol/session/platform-attribution.test.ts +0 -118
  333. package/test/saeeol/session/session.test.ts +0 -105
  334. package/test/saeeol/session-compaction-cap.test.ts +0 -399
  335. package/test/saeeol/session-compaction-chunks.test.ts +0 -501
  336. package/test/saeeol/session-compaction-safety.test.ts +0 -481
  337. package/test/saeeol/session-fork-remap.test.ts +0 -251
  338. package/test/saeeol/session-import-service.test.ts +0 -114
  339. package/test/saeeol/session-list.test.ts +0 -47
  340. package/test/saeeol/session-message-metadata.test.ts +0 -128
  341. package/test/saeeol/session-overflow.test.ts +0 -78
  342. package/test/saeeol/session-processor-empty-tool-calls.test.ts +0 -571
  343. package/test/saeeol/session-processor-network-offline.test.ts +0 -204
  344. package/test/saeeol/session-processor-retry-limit.test.ts +0 -238
  345. package/test/saeeol/session-processor-review-telemetry.test.ts +0 -82
  346. package/test/saeeol/session-prompt-compaction-safety.test.ts +0 -517
  347. package/test/saeeol/session-prompt-queue.test.ts +0 -815
  348. package/test/saeeol/sessions/inflight-cache.test.ts +0 -157
  349. package/test/saeeol/sessions/ingest-queue.test.ts +0 -402
  350. package/test/saeeol/sessions/remote-protocol.test.ts +0 -258
  351. package/test/saeeol/sessions/remote-sender.test.ts +0 -1036
  352. package/test/saeeol/sessions/remote-ws.test.ts +0 -367
  353. package/test/saeeol/sessions/sessions-enable-remote.test.disable +0 -181
  354. package/test/saeeol/slot-prop-reactivity.test.ts +0 -142
  355. package/test/saeeol/snapshot-cache.test.ts +0 -84
  356. package/test/saeeol/snapshot-freeze-repro.test.ts +0 -100
  357. package/test/saeeol/snapshot-track-timeout.test.ts +0 -519
  358. package/test/saeeol/stats-subagent-cost.test.ts +0 -123
  359. package/test/saeeol/suggestion/auto-dismiss.test.ts +0 -65
  360. package/test/saeeol/suggestion/suggestion.test.ts +0 -145
  361. package/test/saeeol/suggestion/tool.test.ts +0 -298
  362. package/test/saeeol/summary-file-diff.test.ts +0 -28
  363. package/test/saeeol/system-prompt.test.ts +0 -142
  364. package/test/saeeol/task-nesting.test.ts +0 -193
  365. package/test/saeeol/telemetry/feedback.test.ts +0 -8
  366. package/test/saeeol/todo-view.test.ts +0 -57
  367. package/test/saeeol/tool-encoding.test.ts +0 -455
  368. package/test/saeeol/tool-registry-indexing-import-failure.test.ts +0 -49
  369. package/test/saeeol/tool-registry-indexing.test.ts +0 -236
  370. package/test/saeeol/tool-registry-semantic-import-failure.test.ts +0 -55
  371. package/test/saeeol/tool-task-model.test.ts +0 -352
  372. package/test/saeeol/transform-opus-4.7.test.ts +0 -89
  373. package/test/saeeol/tui-diff.test.ts +0 -91
  374. package/test/saeeol/tui-sync.test.ts +0 -80
  375. package/test/saeeol/util/url.test.ts +0 -141
  376. package/test/saeeol/workflows-migrator.test.ts +0 -261
  377. package/test/saeeol/worktree-diff-summary.test.ts +0 -64
  378. package/test/saeeol/worktree-diff.test.ts +0 -223
  379. package/test/saeeol/worktree-remove-lock.test.ts +0 -82
  380. package/test/server/AGENTS.md +0 -15
  381. package/test/server/contract.test.ts +0 -249
  382. package/test/server/experimental-session-list.test.ts +0 -157
  383. package/test/server/global-session-list.test.ts +0 -155
  384. package/test/server/httpapi-authorization.test.ts +0 -103
  385. package/test/server/httpapi-bridge.test.ts +0 -440
  386. package/test/server/httpapi-config.test.ts +0 -67
  387. package/test/server/httpapi-cors.test.ts +0 -89
  388. package/test/server/httpapi-event.test.ts +0 -57
  389. package/test/server/httpapi-experimental.test.ts +0 -219
  390. package/test/server/httpapi-file.test.ts +0 -79
  391. package/test/server/httpapi-instance-context.test.ts +0 -237
  392. package/test/server/httpapi-instance.legacy.test.ts +0 -140
  393. package/test/server/httpapi-instance.test.ts +0 -83
  394. package/test/server/httpapi-json-parity.test.ts +0 -263
  395. package/test/server/httpapi-mcp-oauth.test.ts +0 -76
  396. package/test/server/httpapi-mcp.test.ts +0 -189
  397. package/test/server/httpapi-provider.test.ts +0 -153
  398. package/test/server/httpapi-pty-websocket.test.ts +0 -16
  399. package/test/server/httpapi-pty.test.ts +0 -175
  400. package/test/server/httpapi-raw-route-auth.test.ts +0 -89
  401. package/test/server/httpapi-sdk.test.ts +0 -679
  402. package/test/server/httpapi-session.test.ts +0 -464
  403. package/test/server/httpapi-sync.test.ts +0 -130
  404. package/test/server/httpapi-tui.test.ts +0 -121
  405. package/test/server/httpapi-workspace-routing.test.ts +0 -471
  406. package/test/server/httpapi-workspace.test.ts +0 -427
  407. package/test/server/project-init-git.test.ts +0 -113
  408. package/test/server/proxy-util.test.ts +0 -113
  409. package/test/server/session-actions.test.ts +0 -49
  410. package/test/server/session-list.test.ts +0 -238
  411. package/test/server/session-messages.test.ts +0 -167
  412. package/test/server/session-select.test.ts +0 -100
  413. package/test/server/trace-attributes.test.ts +0 -76
  414. package/test/server/workspace-proxy.test.ts +0 -165
  415. package/test/server/workspace-routing.test.ts +0 -85
  416. package/test/session/compaction.test.ts +0 -2420
  417. package/test/session/instruction.test.ts +0 -247
  418. package/test/session/llm.test.ts +0 -1273
  419. package/test/session/message-v2.test.ts +0 -1291
  420. package/test/session/messages-pagination.test.ts +0 -1173
  421. package/test/session/network.test.ts +0 -249
  422. package/test/session/processor-effect.test.ts +0 -847
  423. package/test/session/prompt.test.ts +0 -2131
  424. package/test/session/retry.test.ts +0 -340
  425. package/test/session/revert-compact.test.ts +0 -639
  426. package/test/session/schema-decoding.test.ts +0 -311
  427. package/test/session/session-entry-stepper.test.ts +0 -917
  428. package/test/session/session-schema.test.ts +0 -76
  429. package/test/session/snapshot-tool-race.test.ts +0 -257
  430. package/test/session/structured-output-integration.test.ts +0 -265
  431. package/test/session/structured-output.test.ts +0 -381
  432. package/test/session/system.test.ts +0 -73
  433. package/test/share/share-next.test.ts +0 -333
  434. package/test/shell/shell.test.ts +0 -99
  435. package/test/skill/discovery.test.ts +0 -116
  436. package/test/skill/skill.test.ts +0 -393
  437. package/test/snapshot/snapshot.test.ts +0 -1531
  438. package/test/storage/db.test.ts +0 -23
  439. package/test/storage/json-migration.test.ts +0 -832
  440. package/test/storage/storage.test.ts +0 -293
  441. package/test/suggestion/suggestion.test.ts +0 -1
  442. package/test/sync/index.test.ts +0 -256
  443. package/test/tool/__snapshots__/parameters.test.ts.snap +0 -500
  444. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  445. package/test/tool/apply_patch.test.ts +0 -614
  446. package/test/tool/bash.test.ts +0 -1225
  447. package/test/tool/diagnostics-filter.test.ts +0 -55
  448. package/test/tool/edit.test.ts +0 -754
  449. package/test/tool/external-directory.test.ts +0 -169
  450. package/test/tool/fixtures/large-image.png +0 -0
  451. package/test/tool/fixtures/models-api.json +0 -65179
  452. package/test/tool/glob.test.ts +0 -107
  453. package/test/tool/grep.test.ts +0 -114
  454. package/test/tool/lsp.test.ts +0 -187
  455. package/test/tool/parameters.test.ts +0 -243
  456. package/test/tool/question.test.ts +0 -129
  457. package/test/tool/read.test.ts +0 -500
  458. package/test/tool/recall.test.ts +0 -151
  459. package/test/tool/registry.test.ts +0 -203
  460. package/test/tool/skill.test.ts +0 -135
  461. package/test/tool/suggest.test.ts +0 -1
  462. package/test/tool/task.test.ts +0 -612
  463. package/test/tool/tool-define.test.ts +0 -99
  464. package/test/tool/truncation.test.ts +0 -260
  465. package/test/tool/webfetch.test.ts +0 -103
  466. package/test/tool/write.test.ts +0 -291
  467. package/test/util/data-url.test.ts +0 -14
  468. package/test/util/effect-zod.test.ts +0 -754
  469. package/test/util/error.test.ts +0 -38
  470. package/test/util/filesystem.test.ts +0 -656
  471. package/test/util/format.test.ts +0 -59
  472. package/test/util/glob.test.ts +0 -164
  473. package/test/util/iife.test.ts +0 -36
  474. package/test/util/lazy.test.ts +0 -50
  475. package/test/util/lock.test.ts +0 -72
  476. package/test/util/log.test.ts +0 -86
  477. package/test/util/module.test.ts +0 -59
  478. package/test/util/process.test.ts +0 -128
  479. package/test/util/timeout.test.ts +0 -21
  480. package/test/util/which.test.ts +0 -100
  481. package/test/util/wildcard.test.ts +0 -90
  482. package/test/workspace/workspace-restore.test.ts +0 -296
  483. package/tsconfig.json +0 -19
@@ -1,2131 +0,0 @@
1
- import { NodeFileSystem } from "@effect/platform-node"
2
- import { FetchHttpClient } from "effect/unstable/http"
3
- import { afterEach, expect, mock, spyOn } from "bun:test"
4
- import { Telemetry } from "@saeeol/telemetry"
5
- import { Cause, Effect, Exit, Fiber, Layer } from "effect"
6
- import path from "path"
7
- import { fileURLToPath } from "url"
8
- import { NamedError } from "@saeeol/core/util/error"
9
- import { Agent as AgentSvc } from "../../src/agent/agent"
10
- import { Bus } from "../../src/bus"
11
- import { Command } from "../../src/command"
12
- import { Config } from "@/config/config"
13
- import { LSP } from "@/lsp/lsp"
14
- import { MCP } from "../../src/mcp"
15
- import { Permission } from "../../src/permission"
16
- import { Plugin } from "../../src/plugin"
17
- import { Provider as ProviderSvc } from "@/provider/provider"
18
- import { Env } from "../../src/env"
19
- import { ModelID, ProviderID } from "../../src/provider/schema"
20
- import { Question } from "../../src/question"
21
- import { Todo } from "../../src/session/todo"
22
- import { Session } from "@/session/session"
23
- import { LLM } from "../../src/session/llm"
24
- import { MessageV2 } from "../../src/session/message-v2"
25
- import { AppFileSystem } from "@saeeol/core/filesystem"
26
- import { SessionCompaction } from "../../src/session/compaction"
27
- import { SessionSummary } from "../../src/session/summary"
28
- import { Instruction } from "../../src/session/instruction"
29
- import { SessionProcessor } from "../../src/session/processor"
30
- import { SessionPrompt } from "../../src/session/prompt"
31
- import { SessionRevert } from "../../src/session/revert"
32
- import { SessionRunState } from "../../src/session/run-state"
33
- import { MessageID, PartID, SessionID } from "../../src/session/schema"
34
- import { SessionStatus } from "../../src/session/status"
35
- import { Skill } from "../../src/skill"
36
- import { SystemPrompt } from "../../src/session/system"
37
- import { Shell } from "../../src/shell/shell"
38
- import { Snapshot } from "../../src/snapshot"
39
- import { ToolRegistry } from "@/tool/registry"
40
- import { Truncate } from "@/tool/truncate"
41
- import { defaultLayer as resolveToolsLayer } from "../../src/session/resolve-tools"
42
- import { defaultLayer as userPartLayer } from "../../src/session/user-part"
43
- import { defaultLayer as subtaskLayer } from "../../src/session/subtask"
44
- import { defaultLayer as shellLayer } from "../../src/session/shell-exec"
45
- import * as Log from "@saeeol/core/util/log"
46
- import { CrossSpawnSpawner } from "@saeeol/core/cross-spawn-spawner"
47
- import { Ripgrep } from "../../src/file/ripgrep"
48
- import { Format } from "../../src/format"
49
- import { provideTmpdirInstance, provideTmpdirServer } from "../fixture/fixture"
50
- import { testEffect } from "../lib/effect"
51
- import { reply, TestLLMServer } from "../lib/llm-server"
52
-
53
- void Log.init({ print: false })
54
- const summary = Layer.succeed(
55
- SessionSummary.Service,
56
- SessionSummary.Service.of({
57
- summarize: () => Effect.void,
58
- diff: () => Effect.succeed([]),
59
- computeDiff: () => Effect.succeed([]),
60
- }),
61
- )
62
-
63
- const ref = {
64
- providerID: ProviderID.make("test"),
65
- modelID: ModelID.make("test-model"),
66
- }
67
-
68
- function defer<T>() {
69
- let resolve!: (value: T | PromiseLike<T>) => void
70
- const promise = new Promise<T>((done) => {
71
- resolve = done
72
- })
73
- return { promise, resolve }
74
- }
75
- const waitFor = <A, E, R>(label: string, run: Effect.Effect<A | undefined, E, R>) =>
76
- Effect.gen(function* () {
77
- const end = Date.now() + 5_000
78
- while (Date.now() < end) {
79
- const result = yield* run
80
- if (result !== undefined) return result
81
- yield* Effect.sleep(20)
82
- }
83
- throw new Error(`timed out waiting for ${label}`)
84
- })
85
-
86
- function withSh<A, E, R>(fx: () => Effect.Effect<A, E, R>) {
87
- return Effect.acquireUseRelease(
88
- Effect.sync(() => {
89
- const prev = process.env.SHELL
90
- process.env.SHELL = "/bin/sh"
91
- Shell.preferred.reset()
92
- return prev
93
- }),
94
- () => fx(),
95
- (prev) =>
96
- Effect.sync(() => {
97
- if (prev === undefined) delete process.env.SHELL
98
- else process.env.SHELL = prev
99
- Shell.preferred.reset()
100
- }),
101
- )
102
- }
103
-
104
- function toolPart(parts: MessageV2.Part[]) {
105
- return parts.find((part): part is MessageV2.ToolPart => part.type === "tool")
106
- }
107
-
108
- type CompletedToolPart = MessageV2.ToolPart & { state: MessageV2.ToolStateCompleted }
109
- type ErrorToolPart = MessageV2.ToolPart & { state: MessageV2.ToolStateError }
110
-
111
- function completedTool(parts: MessageV2.Part[]) {
112
- const part = toolPart(parts)
113
- expect(part?.state.status).toBe("completed")
114
- return part?.state.status === "completed" ? (part as CompletedToolPart) : undefined
115
- }
116
-
117
- function errorTool(parts: MessageV2.Part[]) {
118
- const part = toolPart(parts)
119
- expect(part?.state.status).toBe("error")
120
- return part?.state.status === "error" ? (part as ErrorToolPart) : undefined
121
- }
122
-
123
- const mcp = Layer.succeed(
124
- MCP.Service,
125
- MCP.Service.of({
126
- status: () => Effect.succeed({}),
127
- clients: () => Effect.succeed({}),
128
- tools: () => Effect.succeed({}),
129
- prompts: () => Effect.succeed({}),
130
- resources: () => Effect.succeed({}),
131
- add: () => Effect.succeed({ status: { status: "disabled" as const } }),
132
- connect: () => Effect.void,
133
- disconnect: () => Effect.void,
134
- getPrompt: () => Effect.succeed(undefined),
135
- readResource: () => Effect.succeed(undefined),
136
- startAuth: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
137
- authenticate: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
138
- finishAuth: () => Effect.die("unexpected MCP auth in prompt-effect tests"),
139
- removeAuth: () => Effect.void,
140
- supportsOAuth: () => Effect.succeed(false),
141
- hasStoredTokens: () => Effect.succeed(false),
142
- getAuthStatus: () => Effect.succeed("not_authenticated" as const),
143
- }),
144
- )
145
-
146
- const lsp = Layer.succeed(
147
- LSP.Service,
148
- LSP.Service.of({
149
- init: () => Effect.void,
150
- status: () => Effect.succeed([]),
151
- hasClients: () => Effect.succeed(false),
152
- touchFile: () => Effect.void,
153
- diagnostics: () => Effect.succeed({}),
154
- hover: () => Effect.succeed(undefined),
155
- definition: () => Effect.succeed([]),
156
- references: () => Effect.succeed([]),
157
- implementation: () => Effect.succeed([]),
158
- documentSymbol: () => Effect.succeed([]),
159
- workspaceSymbol: () => Effect.succeed([]),
160
- prepareCallHierarchy: () => Effect.succeed([]),
161
- incomingCalls: () => Effect.succeed([]),
162
- outgoingCalls: () => Effect.succeed([]),
163
- }),
164
- )
165
-
166
- const status = SessionStatus.layer.pipe(Layer.provideMerge(Bus.layer))
167
- const run = SessionRunState.layer.pipe(Layer.provide(status))
168
- const infra = Layer.mergeAll(NodeFileSystem.layer, CrossSpawnSpawner.defaultLayer)
169
- function makeHttp() {
170
- const deps = Layer.mergeAll(
171
- Session.defaultLayer,
172
- Snapshot.defaultLayer,
173
- LLM.defaultLayer,
174
- Env.defaultLayer,
175
- AgentSvc.defaultLayer,
176
- Command.defaultLayer,
177
- Permission.defaultLayer,
178
- Plugin.defaultLayer,
179
- Config.defaultLayer,
180
- ProviderSvc.defaultLayer,
181
- lsp,
182
- mcp,
183
- AppFileSystem.defaultLayer,
184
- status,
185
- ).pipe(Layer.provideMerge(infra))
186
- const question = Question.layer.pipe(Layer.provideMerge(deps))
187
- const todo = Todo.layer.pipe(Layer.provideMerge(deps))
188
- const registry = ToolRegistry.layer.pipe(
189
- Layer.provide(Skill.defaultLayer),
190
- Layer.provide(FetchHttpClient.layer),
191
- Layer.provide(CrossSpawnSpawner.defaultLayer),
192
- Layer.provide(Ripgrep.defaultLayer),
193
- Layer.provide(Format.defaultLayer),
194
- Layer.provideMerge(todo),
195
- Layer.provideMerge(question),
196
- Layer.provideMerge(deps),
197
- )
198
- const trunc = Truncate.layer.pipe(Layer.provideMerge(deps))
199
- const proc = SessionProcessor.layer.pipe(Layer.provide(summary), Layer.provideMerge(deps))
200
- const compact = SessionCompaction.layer.pipe(Layer.provideMerge(proc), Layer.provideMerge(deps))
201
- return Layer.mergeAll(
202
- TestLLMServer.layer,
203
- SessionPrompt.layer.pipe(
204
- Layer.provide(resolveToolsLayer),
205
- Layer.provide(userPartLayer),
206
- Layer.provide(subtaskLayer),
207
- Layer.provide(shellLayer),
208
- Layer.provide(SessionRevert.defaultLayer),
209
- Layer.provide(summary),
210
- Layer.provideMerge(run),
211
- Layer.provideMerge(compact),
212
- Layer.provideMerge(proc),
213
- Layer.provideMerge(registry),
214
- Layer.provideMerge(trunc),
215
- Layer.provide(Instruction.defaultLayer),
216
- Layer.provide(SystemPrompt.defaultLayer),
217
- Layer.provideMerge(deps),
218
- ),
219
- ).pipe(Layer.provide(summary))
220
- }
221
-
222
- const it = testEffect(makeHttp())
223
- const unix = process.platform !== "win32" ? it.live : it.live.skip
224
- afterEach(() => {
225
- mock.restore()
226
- })
227
-
228
- // Config that registers a custom "test" provider with a "test-model" model
229
- // so provider model lookup succeeds inside the loop.
230
- const cfg = {
231
- provider: {
232
- test: {
233
- name: "Test",
234
- id: "test",
235
- env: [],
236
- npm: "@ai-sdk/openai-compatible",
237
- models: {
238
- "test-model": {
239
- id: "test-model",
240
- name: "Test Model",
241
- attachment: false,
242
- reasoning: false,
243
- temperature: false,
244
- tool_call: true,
245
- release_date: "2025-01-01",
246
- limit: { context: 100000, output: 10000 },
247
- cost: { input: 0, output: 0 },
248
- options: {},
249
- },
250
- },
251
- options: {
252
- apiKey: "test-key",
253
- baseURL: "http://localhost:1/v1",
254
- },
255
- },
256
- },
257
- }
258
-
259
- function providerCfg(url: string) {
260
- return {
261
- ...cfg,
262
- provider: {
263
- ...cfg.provider,
264
- test: {
265
- ...cfg.provider.test,
266
- options: {
267
- ...cfg.provider.test.options,
268
- baseURL: url,
269
- },
270
- },
271
- },
272
- }
273
- }
274
-
275
- const user = Effect.fn("test.user")(function* (sessionID: SessionID, text: string) {
276
- const session = yield* Session.Service
277
- const msg = yield* session.updateMessage({
278
- id: MessageID.ascending(),
279
- role: "user",
280
- sessionID,
281
- agent: "build",
282
- model: ref,
283
- time: { created: Date.now() },
284
- })
285
- yield* session.updatePart({
286
- id: PartID.ascending(),
287
- messageID: msg.id,
288
- sessionID,
289
- type: "text",
290
- text,
291
- })
292
- return msg
293
- })
294
-
295
- const seed = Effect.fn("test.seed")(function* (sessionID: SessionID, opts?: { finish?: string }) {
296
- const session = yield* Session.Service
297
- const msg = yield* user(sessionID, "hello")
298
- const assistant: MessageV2.Assistant = {
299
- id: MessageID.ascending(),
300
- role: "assistant",
301
- parentID: msg.id,
302
- sessionID,
303
- mode: "build",
304
- agent: "build",
305
- cost: 0,
306
- path: { cwd: "/tmp", root: "/tmp" },
307
- tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
308
- modelID: ref.modelID,
309
- providerID: ref.providerID,
310
- time: { created: Date.now() },
311
- ...(opts?.finish ? { finish: opts.finish } : {}),
312
- }
313
- yield* session.updateMessage(assistant)
314
- yield* session.updatePart({
315
- id: PartID.ascending(),
316
- messageID: assistant.id,
317
- sessionID,
318
- type: "text",
319
- text: "hi there",
320
- })
321
- return { user: msg, assistant }
322
- })
323
-
324
- const addSubtask = (sessionID: SessionID, messageID: MessageID, model = ref) =>
325
- Effect.gen(function* () {
326
- const session = yield* Session.Service
327
- yield* session.updatePart({
328
- id: PartID.ascending(),
329
- messageID,
330
- sessionID,
331
- type: "subtask",
332
- prompt: "look into the cache key path",
333
- description: "inspect bug",
334
- agent: "general",
335
- model,
336
- })
337
- })
338
-
339
- const boot = Effect.fn("test.boot")(function* (input?: { title?: string }) {
340
- const config = yield* Config.Service
341
- const prompt = yield* SessionPrompt.Service
342
- const run = yield* SessionRunState.Service
343
- const sessions = yield* Session.Service
344
- yield* config.get()
345
- const chat = yield* sessions.create(input ?? { title: "Pinned" })
346
- return { prompt, run, sessions, chat }
347
- })
348
-
349
- // Loop semantics
350
-
351
- it.live("loop exits immediately when last assistant has stop finish", () =>
352
- provideTmpdirServer(
353
- Effect.fnUntraced(function* ({ llm }) {
354
- const prompt = yield* SessionPrompt.Service
355
- const sessions = yield* Session.Service
356
- const chat = yield* sessions.create({ title: "Pinned" })
357
- yield* seed(chat.id, { finish: "stop" })
358
-
359
- const result = yield* prompt.loop({ sessionID: chat.id })
360
- expect(result.info.role).toBe("assistant")
361
- if (result.info.role === "assistant") expect(result.info.finish).toBe("stop")
362
- expect(yield* llm.calls).toBe(0)
363
- }),
364
- { git: true, config: providerCfg },
365
- ),
366
- )
367
-
368
- it.live("loop calls LLM and returns assistant message", () =>
369
- provideTmpdirServer(
370
- Effect.fnUntraced(function* ({ llm }) {
371
- const prompt = yield* SessionPrompt.Service
372
- const sessions = yield* Session.Service
373
- const chat = yield* sessions.create({
374
- title: "Pinned",
375
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
376
- })
377
- yield* prompt.prompt({
378
- sessionID: chat.id,
379
- agent: "build",
380
- noReply: true,
381
- parts: [{ type: "text", text: "hello" }],
382
- })
383
- yield* llm.text("world")
384
-
385
- const result = yield* prompt.loop({ sessionID: chat.id })
386
- expect(result.info.role).toBe("assistant")
387
- const parts = result.parts.filter((p) => p.type === "text")
388
- expect(parts.some((p) => p.type === "text" && p.text === "world")).toBe(true)
389
- expect(yield* llm.hits).toHaveLength(1)
390
- }),
391
- { git: true, config: providerCfg },
392
- ),
393
- )
394
-
395
- it.live("static loop returns assistant text through local provider", () =>
396
- provideTmpdirServer(
397
- Effect.fnUntraced(function* ({ llm }) {
398
- const prompt = yield* SessionPrompt.Service
399
- const sessions = yield* Session.Service
400
- const session = yield* sessions.create({
401
- title: "Prompt provider",
402
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
403
- })
404
-
405
- yield* prompt.prompt({
406
- sessionID: session.id,
407
- agent: "build",
408
- noReply: true,
409
- parts: [{ type: "text", text: "hello" }],
410
- })
411
-
412
- yield* llm.text("world")
413
-
414
- const result = yield* prompt.loop({ sessionID: session.id })
415
- expect(result.info.role).toBe("assistant")
416
- expect(result.parts.some((part) => part.type === "text" && part.text === "world")).toBe(true)
417
- expect(yield* llm.hits).toHaveLength(1)
418
- expect(yield* llm.pending).toBe(0)
419
- }),
420
- { git: true, config: providerCfg },
421
- ),
422
- )
423
-
424
- it.live("static loop consumes queued replies across turns", () =>
425
- provideTmpdirServer(
426
- Effect.fnUntraced(function* ({ llm }) {
427
- const prompt = yield* SessionPrompt.Service
428
- const sessions = yield* Session.Service
429
- const session = yield* sessions.create({
430
- title: "Prompt provider turns",
431
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
432
- })
433
-
434
- yield* prompt.prompt({
435
- sessionID: session.id,
436
- agent: "build",
437
- noReply: true,
438
- parts: [{ type: "text", text: "hello one" }],
439
- })
440
-
441
- yield* llm.text("world one")
442
-
443
- const first = yield* prompt.loop({ sessionID: session.id })
444
- expect(first.info.role).toBe("assistant")
445
- expect(first.parts.some((part) => part.type === "text" && part.text === "world one")).toBe(true)
446
-
447
- yield* prompt.prompt({
448
- sessionID: session.id,
449
- agent: "build",
450
- noReply: true,
451
- parts: [{ type: "text", text: "hello two" }],
452
- })
453
-
454
- yield* llm.text("world two")
455
-
456
- const second = yield* prompt.loop({ sessionID: session.id })
457
- expect(second.info.role).toBe("assistant")
458
- expect(second.parts.some((part) => part.type === "text" && part.text === "world two")).toBe(true)
459
-
460
- expect(yield* llm.hits).toHaveLength(2)
461
- expect(yield* llm.pending).toBe(0)
462
- }),
463
- { git: true, config: providerCfg },
464
- ),
465
- )
466
-
467
- it.live("loop continues when finish is tool-calls", () =>
468
- provideTmpdirServer(
469
- Effect.fnUntraced(function* ({ llm }) {
470
- const prompt = yield* SessionPrompt.Service
471
- const sessions = yield* Session.Service
472
- const session = yield* sessions.create({
473
- title: "Pinned",
474
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
475
- })
476
- yield* prompt.prompt({
477
- sessionID: session.id,
478
- agent: "build",
479
- noReply: true,
480
- parts: [{ type: "text", text: "hello" }],
481
- })
482
- yield* llm.tool("first", { value: "first" })
483
- yield* llm.text("second")
484
-
485
- const result = yield* prompt.loop({ sessionID: session.id })
486
- expect(yield* llm.calls).toBe(2)
487
- expect(result.info.role).toBe("assistant")
488
- if (result.info.role === "assistant") {
489
- expect(result.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
490
- expect(result.info.finish).toBe("stop")
491
- }
492
- }),
493
- { git: true, config: providerCfg },
494
- ),
495
- )
496
- it.live.skip("glob tool keeps instance context during prompt runs", () =>
497
- provideTmpdirServer(
498
- ({ dir, llm }) =>
499
- Effect.gen(function* () {
500
- const prompt = yield* SessionPrompt.Service
501
- const sessions = yield* Session.Service
502
- const session = yield* sessions.create({
503
- title: "Glob context",
504
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
505
- })
506
- const file = path.join(dir, "probe.txt")
507
- yield* Effect.promise(() => Bun.write(file, "probe"))
508
-
509
- yield* prompt.prompt({
510
- sessionID: session.id,
511
- agent: "build",
512
- noReply: true,
513
- parts: [{ type: "text", text: "find text files" }],
514
- })
515
- yield* llm.tool("glob", { pattern: "**/*.txt" })
516
- yield* llm.text("done")
517
-
518
- const result = yield* prompt.loop({ sessionID: session.id })
519
- expect(result.info.role).toBe("assistant")
520
-
521
- const msgs = yield* MessageV2.filterCompactedEffect(session.id)
522
- const tool = msgs
523
- .flatMap((msg) => msg.parts)
524
- .find(
525
- (part): part is CompletedToolPart =>
526
- part.type === "tool" && part.tool === "glob" && part.state.status === "completed",
527
- )
528
- if (!tool) return
529
-
530
- expect(tool.state.output).toContain(file)
531
- expect(tool.state.output).not.toContain("No context found for instance")
532
- expect(result.parts.some((part) => part.type === "text" && part.text === "done")).toBe(true)
533
- }),
534
- { git: true, config: providerCfg },
535
- ),
536
- )
537
-
538
- it.live("loop continues when finish is stop but assistant has tool parts", () =>
539
- provideTmpdirServer(
540
- Effect.fnUntraced(function* ({ llm }) {
541
- const prompt = yield* SessionPrompt.Service
542
- const sessions = yield* Session.Service
543
- const session = yield* sessions.create({
544
- title: "Pinned",
545
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
546
- })
547
- yield* prompt.prompt({
548
- sessionID: session.id,
549
- agent: "build",
550
- noReply: true,
551
- parts: [{ type: "text", text: "hello" }],
552
- })
553
- yield* llm.push(reply().tool("first", { value: "first" }).stop())
554
- yield* llm.text("second")
555
-
556
- const result = yield* prompt.loop({ sessionID: session.id })
557
- expect(yield* llm.calls).toBe(2)
558
- expect(result.info.role).toBe("assistant")
559
- if (result.info.role === "assistant") {
560
- expect(result.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
561
- expect(result.info.finish).toBe("stop")
562
- }
563
- }),
564
- { git: true, config: providerCfg },
565
- ),
566
- )
567
-
568
- it.live("failed subtask preserves metadata on error tool state", () =>
569
- provideTmpdirServer(
570
- Effect.fnUntraced(function* ({ llm }) {
571
- const prompt = yield* SessionPrompt.Service
572
- const sessions = yield* Session.Service
573
- const chat = yield* sessions.create({ title: "Pinned" })
574
- yield* llm.tool("task", {
575
- description: "inspect bug",
576
- prompt: "look into the cache key path",
577
- subagent_type: "general",
578
- })
579
- yield* llm.text("done")
580
- const msg = yield* user(chat.id, "hello")
581
- yield* addSubtask(chat.id, msg.id)
582
-
583
- const result = yield* prompt.loop({ sessionID: chat.id })
584
- expect(result.info.role).toBe("assistant")
585
- expect(yield* llm.calls).toBe(2)
586
-
587
- const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
588
- const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
589
- expect(taskMsg?.info.role).toBe("assistant")
590
- if (!taskMsg || taskMsg.info.role !== "assistant") return
591
-
592
- const tool = errorTool(taskMsg.parts)
593
- if (!tool) return
594
-
595
- expect(tool.state.error).toContain("Tool execution failed")
596
- expect(tool.state.metadata).toBeDefined()
597
- expect(tool.state.metadata?.sessionId).toBeDefined()
598
- expect(tool.state.metadata?.model).toEqual({
599
- providerID: ProviderID.make("test"),
600
- modelID: ModelID.make("missing-model"),
601
- })
602
- }),
603
- {
604
- git: true,
605
- config: (url) => ({
606
- ...providerCfg(url),
607
- agent: {
608
- general: {
609
- model: "test/missing-model",
610
- },
611
- },
612
- }),
613
- },
614
- ),
615
- )
616
-
617
- it.live(
618
- "running subtask preserves metadata after tool-call transition",
619
- () =>
620
- provideTmpdirServer(
621
- Effect.fnUntraced(function* ({ llm }) {
622
- const prompt = yield* SessionPrompt.Service
623
- const sessions = yield* Session.Service
624
- const chat = yield* sessions.create({ title: "Pinned" })
625
- yield* llm.hang
626
- const msg = yield* user(chat.id, "hello")
627
- yield* addSubtask(chat.id, msg.id)
628
-
629
- const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
630
-
631
- const tool = yield* Effect.promise(async () => {
632
- const end = Date.now() + 5_000
633
- while (Date.now() < end) {
634
- const msgs = await Effect.runPromise(MessageV2.filterCompactedEffect(chat.id))
635
- const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
636
- const tool = taskMsg?.parts.find((part): part is MessageV2.ToolPart => part.type === "tool")
637
- if (tool?.state.status === "running" && tool.state.metadata?.sessionId) return tool
638
- await new Promise((done) => setTimeout(done, 20))
639
- }
640
- throw new Error("timed out waiting for running subtask metadata")
641
- })
642
-
643
- if (tool.state.status !== "running") return
644
- expect(typeof tool.state.metadata?.sessionId).toBe("string")
645
- expect(tool.state.title).toBeDefined()
646
- expect(tool.state.metadata?.model).toBeDefined()
647
-
648
- yield* prompt.cancel(chat.id)
649
- yield* Fiber.await(fiber)
650
- }),
651
- { git: true, config: providerCfg },
652
- ),
653
- 5_000,
654
- )
655
-
656
- it.live(
657
- "running task tool preserves metadata after tool-call transition",
658
- () =>
659
- provideTmpdirServer(
660
- Effect.fnUntraced(function* ({ llm }) {
661
- const prompt = yield* SessionPrompt.Service
662
- const sessions = yield* Session.Service
663
- const chat = yield* sessions.create({
664
- title: "Pinned",
665
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
666
- })
667
- yield* llm.tool("task", {
668
- description: "inspect bug",
669
- prompt: "look into the cache key path",
670
- subagent_type: "general",
671
- })
672
- yield* llm.hang
673
- yield* user(chat.id, "hello")
674
-
675
- const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
676
-
677
- const tool = yield* Effect.promise(async () => {
678
- const end = Date.now() + 5_000
679
- while (Date.now() < end) {
680
- const msgs = await Effect.runPromise(MessageV2.filterCompactedEffect(chat.id))
681
- const assistant = msgs.findLast((item) => item.info.role === "assistant" && item.info.agent === "code")
682
- const tool = assistant?.parts.find(
683
- (part): part is MessageV2.ToolPart => part.type === "tool" && part.tool === "task",
684
- )
685
- if (tool?.state.status === "running" && tool.state.metadata?.sessionId) return tool
686
- await new Promise((done) => setTimeout(done, 20))
687
- }
688
- throw new Error("timed out waiting for running task metadata")
689
- })
690
-
691
- if (tool.state.status !== "running") return
692
- expect(typeof tool.state.metadata?.sessionId).toBe("string")
693
- expect(tool.state.title).toBe("inspect bug")
694
- expect(tool.state.metadata?.model).toBeDefined()
695
-
696
- yield* prompt.cancel(chat.id)
697
- yield* Fiber.await(fiber)
698
- }),
699
- { git: true, config: providerCfg },
700
- ),
701
- 10_000,
702
- )
703
-
704
- it.live(
705
- "loop sets status to busy then idle",
706
- () =>
707
- provideTmpdirServer(
708
- Effect.fnUntraced(function* ({ llm }) {
709
- const gate = defer<void>()
710
- const prompt = yield* SessionPrompt.Service
711
- const sessions = yield* Session.Service
712
- const status = yield* SessionStatus.Service
713
-
714
- yield* llm.push(reply().wait(gate.promise).text("done").stop())
715
-
716
- const chat = yield* sessions.create({ title: "Pinned" })
717
- yield* user(chat.id, "hi")
718
-
719
- const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
720
- yield* waitFor(
721
- "busy status",
722
- status.get(chat.id).pipe(Effect.map((item) => (item.type === "busy" ? item : undefined))),
723
- )
724
- gate.resolve()
725
- yield* Fiber.await(fiber)
726
- yield* waitFor(
727
- "idle status",
728
- status.get(chat.id).pipe(Effect.map((item) => (item.type === "idle" ? item : undefined))),
729
- )
730
- }),
731
- { git: true, config: providerCfg },
732
- ),
733
- 10_000,
734
- )
735
-
736
- // Cancel semantics
737
-
738
- it.live(
739
- "cancel interrupts loop and resolves with an assistant message",
740
- () =>
741
- provideTmpdirServer(
742
- Effect.fnUntraced(function* ({ llm }) {
743
- const prompt = yield* SessionPrompt.Service
744
- const sessions = yield* Session.Service
745
- const chat = yield* sessions.create({ title: "Pinned" })
746
- yield* seed(chat.id)
747
-
748
- yield* llm.hang
749
-
750
- yield* user(chat.id, "more")
751
-
752
- const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
753
- yield* llm.wait(1)
754
- yield* prompt.cancel(chat.id)
755
- const exit = yield* Fiber.await(fiber)
756
- expect(Exit.isSuccess(exit)).toBe(true)
757
- if (Exit.isSuccess(exit)) {
758
- expect(exit.value.info.role).toBe("assistant")
759
- }
760
- }),
761
- { git: true, config: providerCfg },
762
- ),
763
- 3_000,
764
- )
765
-
766
- unix(
767
- "cancel records MessageAbortedError on interrupted process",
768
- () =>
769
- provideTmpdirServer(
770
- Effect.fnUntraced(function* ({ llm }) {
771
- const prompt = yield* SessionPrompt.Service
772
- const sessions = yield* Session.Service
773
- const chat = yield* sessions.create({ title: "Pinned" })
774
- yield* llm.hang
775
- yield* user(chat.id, "hello")
776
-
777
- const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
778
- yield* llm.wait(1)
779
- yield* prompt.cancel(chat.id)
780
- const exit = yield* Fiber.await(fiber)
781
- expect(Exit.isSuccess(exit)).toBe(true)
782
- if (Exit.isSuccess(exit)) {
783
- const info = exit.value.info
784
- if (info.role === "assistant") {
785
- expect(info.error?.name).toBe("MessageAbortedError")
786
- }
787
- }
788
- }),
789
- { git: true, config: providerCfg },
790
- ),
791
- 3_000,
792
- )
793
-
794
- it.live(
795
- "cancel finalizes subtask tool state",
796
- () =>
797
- provideTmpdirInstance(
798
- () =>
799
- Effect.gen(function* () {
800
- const ready = defer<void>()
801
- const aborted = defer<void>()
802
- const registry = yield* ToolRegistry.Service
803
- const { task } = yield* registry.named()
804
- const original = task.execute
805
- task.execute = (_args, ctx) =>
806
- Effect.callback<never>((_resume) => {
807
- ready.resolve()
808
- ctx.abort.addEventListener("abort", () => aborted.resolve(), { once: true })
809
- return Effect.sync(() => aborted.resolve())
810
- })
811
- yield* Effect.addFinalizer(() => Effect.sync(() => void (task.execute = original)))
812
-
813
- const { prompt, chat } = yield* boot()
814
- const msg = yield* user(chat.id, "hello")
815
- yield* addSubtask(chat.id, msg.id)
816
-
817
- const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
818
- yield* Effect.promise(() => ready.promise)
819
- yield* prompt.cancel(chat.id)
820
- yield* Effect.promise(() => aborted.promise)
821
-
822
- const exit = yield* Fiber.await(fiber)
823
- expect(Exit.isSuccess(exit)).toBe(true)
824
-
825
- const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
826
- const taskMsg = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
827
- expect(taskMsg?.info.role).toBe("assistant")
828
- if (!taskMsg || taskMsg.info.role !== "assistant") return
829
-
830
- const tool = toolPart(taskMsg.parts)
831
- expect(tool?.type).toBe("tool")
832
- if (!tool) return
833
-
834
- expect(tool.state.status).not.toBe("running")
835
- expect(taskMsg.info.time.completed).toBeDefined()
836
- expect(taskMsg.info.finish).toBeDefined()
837
- }),
838
- { git: true, config: cfg },
839
- ),
840
- 30_000,
841
- )
842
- it.live(
843
- "handleSubtask propagates subagent cost to wrapper message",
844
- () =>
845
- provideTmpdirServer(
846
- Effect.fnUntraced(function* ({ llm }) {
847
- const prompt = yield* SessionPrompt.Service
848
- const sessions = yield* Session.Service
849
- const registry = yield* ToolRegistry.Service
850
- const { task } = yield* registry.named()
851
- const original = task.execute
852
- // Simulate task tool: create a child session, persist an assistant with cost, return metadata.
853
- task.execute = (_args, ctx) =>
854
- Effect.gen(function* () {
855
- const child = yield* sessions.create({ parentID: ctx.sessionID, title: "subagent" })
856
- const childAssistant: MessageV2.Assistant = {
857
- id: MessageID.ascending(),
858
- role: "assistant",
859
- parentID: ctx.messageID,
860
- sessionID: child.id,
861
- mode: "general",
862
- agent: "general",
863
- cost: 0.42,
864
- path: { cwd: "/tmp", root: "/tmp" },
865
- tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
866
- modelID: ref.modelID,
867
- providerID: ref.providerID,
868
- time: { created: Date.now(), completed: Date.now() },
869
- finish: "stop",
870
- }
871
- yield* sessions.updateMessage(childAssistant)
872
- yield* ctx.metadata({
873
- title: "done",
874
- metadata: { sessionId: child.id, model: ref, variant: undefined },
875
- })
876
- return { title: "done", metadata: { sessionId: child.id, model: ref, variant: undefined }, output: "done" }
877
- })
878
- yield* Effect.addFinalizer(() => Effect.sync(() => void (task.execute = original)))
879
-
880
- const chat = yield* sessions.create({ title: "Pinned" })
881
- const msg = yield* user(chat.id, "hello")
882
- yield* addSubtask(chat.id, msg.id)
883
- // The loop continues past handleSubtask into a normal LLM step; provide one response to exit.
884
- yield* llm.text("wrapped")
885
-
886
- yield* prompt.loop({ sessionID: chat.id })
887
-
888
- const msgs = yield* MessageV2.filterCompactedEffect(chat.id)
889
- const wrapper = msgs.find((item) => item.info.role === "assistant" && item.info.agent === "general")
890
- expect(wrapper?.info.role).toBe("assistant")
891
- if (!wrapper || wrapper.info.role !== "assistant") return
892
- expect(wrapper.info.cost).toBeCloseTo(0.42, 6)
893
- }),
894
- { git: true, config: providerCfg },
895
- ),
896
- 30_000,
897
- )
898
-
899
- it.live(
900
- "cancel with queued callers resolves all cleanly",
901
- () =>
902
- provideTmpdirServer(
903
- Effect.fnUntraced(function* ({ llm }) {
904
- const prompt = yield* SessionPrompt.Service
905
- const sessions = yield* Session.Service
906
- const chat = yield* sessions.create({ title: "Pinned" })
907
- yield* llm.hang
908
- yield* user(chat.id, "hello")
909
-
910
- const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
911
- yield* llm.wait(1)
912
- const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
913
- yield* Effect.sleep(50)
914
-
915
- yield* prompt.cancel(chat.id)
916
- const [exitA, exitB] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
917
- expect(Exit.isSuccess(exitA)).toBe(true)
918
- expect(Exit.isSuccess(exitB)).toBe(true)
919
- if (Exit.isSuccess(exitA) && Exit.isSuccess(exitB)) {
920
- expect(exitA.value.info.id).toBe(exitB.value.info.id)
921
- }
922
- }),
923
- { git: true, config: providerCfg },
924
- ),
925
- 3_000,
926
- )
927
-
928
- // Queue semantics
929
-
930
- it.live("concurrent loop callers get same result", () =>
931
- provideTmpdirInstance(
932
- (_dir) =>
933
- Effect.gen(function* () {
934
- const { prompt, run, chat } = yield* boot()
935
- yield* seed(chat.id, { finish: "stop" })
936
-
937
- const [a, b] = yield* Effect.all([prompt.loop({ sessionID: chat.id }), prompt.loop({ sessionID: chat.id })], {
938
- concurrency: "unbounded",
939
- })
940
-
941
- expect(a.info.id).toBe(b.info.id)
942
- expect(a.info.role).toBe("assistant")
943
- yield* run.assertNotBusy(chat.id)
944
- }),
945
- { git: true },
946
- ),
947
- )
948
-
949
- it.live(
950
- "concurrent loop callers all receive same error result",
951
- () =>
952
- provideTmpdirServer(
953
- Effect.fnUntraced(function* ({ llm }) {
954
- const gate = defer<void>()
955
- const prompt = yield* SessionPrompt.Service
956
- const sessions = yield* Session.Service
957
- const chat = yield* sessions.create({ title: "Pinned" })
958
-
959
- yield* llm.push(reply().wait(gate.promise).streamError("boom"))
960
- yield* user(chat.id, "hello")
961
-
962
- const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
963
- yield* llm.wait(1)
964
- const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
965
- yield* Effect.sleep(50)
966
- gate.resolve()
967
-
968
- const [ea, eb] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
969
- expect(Exit.isSuccess(ea)).toBe(true)
970
- expect(Exit.isSuccess(eb)).toBe(true)
971
- if (!Exit.isSuccess(ea) || !Exit.isSuccess(eb)) return
972
- const [first, second] = [ea.value, eb.value]
973
- expect(first.info.id).toBe(second.info.id)
974
- expect(first.info.role).toBe("assistant")
975
- }),
976
- { git: true, config: providerCfg },
977
- ),
978
- 10_000,
979
- )
980
- // loses Instance AsyncLocalStorage context in the second forked prompt, which
981
- // surfaces as a "No context found for instance" die before the queue behavior
982
- // can be exercised. The Saeeol queue semantics (in-flight stream drains, second
983
- // LLM request ends with the queued user message) are covered end-to-end in
984
- // packages/saeeol/test/saeeol/session-prompt-queue.test.ts — keep this
985
- // upstream scaffold skipped so future Saeeol merges remain friction-free.
986
- it.live.skip(
987
- "prompt submitted during an active run is included in the next LLM input",
988
- () =>
989
- provideTmpdirServer(
990
- Effect.fnUntraced(function* ({ llm }) {
991
- const gate = defer<void>()
992
- const prompt = yield* SessionPrompt.Service
993
- const sessions = yield* Session.Service
994
- const chat = yield* sessions.create({ title: "Pinned" })
995
-
996
- yield* llm.hold("first", gate.promise)
997
- yield* llm.text("second")
998
-
999
- const a = yield* prompt
1000
- .prompt({
1001
- sessionID: chat.id,
1002
- agent: "build",
1003
- model: ref,
1004
- parts: [{ type: "text", text: "first" }],
1005
- })
1006
- .pipe(Effect.forkChild)
1007
-
1008
- yield* llm.wait(1)
1009
-
1010
- const id = MessageID.ascending()
1011
- const b = yield* prompt
1012
- .prompt({
1013
- sessionID: chat.id,
1014
- messageID: id,
1015
- agent: "build",
1016
- model: ref,
1017
- parts: [{ type: "text", text: "second" }],
1018
- })
1019
- .pipe(Effect.forkChild)
1020
-
1021
- yield* Effect.promise(async () => {
1022
- const end = Date.now() + 5000
1023
- while (Date.now() < end) {
1024
- const msgs = await Effect.runPromise(sessions.messages({ sessionID: chat.id }))
1025
- if (msgs.some((msg) => msg.info.role === "user" && msg.info.id === id)) return
1026
- await new Promise((done) => setTimeout(done, 20))
1027
- }
1028
- throw new Error("timed out waiting for second prompt to save")
1029
- })
1030
-
1031
- gate.resolve()
1032
-
1033
- const [ea, eb] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
1034
- expect(Exit.isSuccess(ea)).toBe(true)
1035
- expect(Exit.isSuccess(eb)).toBe(true)
1036
- expect(yield* llm.calls).toBe(2)
1037
-
1038
- const msgs = yield* sessions.messages({ sessionID: chat.id })
1039
- const assistants = msgs.filter((msg) => msg.info.role === "assistant")
1040
- expect(assistants).toHaveLength(2)
1041
- const last = assistants.at(-1)
1042
- if (!last || last.info.role !== "assistant") throw new Error("expected second assistant")
1043
- expect(last.info.parentID).toBe(id)
1044
- expect(last.parts.some((part) => part.type === "text" && part.text === "second")).toBe(true)
1045
-
1046
- const inputs = yield* llm.inputs
1047
- expect(inputs).toHaveLength(2)
1048
- expect(JSON.stringify(inputs.at(-1)?.messages)).toContain("second")
1049
- }),
1050
- { git: true, config: providerCfg },
1051
- ),
1052
- 3_000,
1053
- )
1054
-
1055
- it.live(
1056
- "assertNotBusy throws BusyError when loop running",
1057
- () =>
1058
- provideTmpdirServer(
1059
- Effect.fnUntraced(function* ({ llm }) {
1060
- const prompt = yield* SessionPrompt.Service
1061
- const run = yield* SessionRunState.Service
1062
- const sessions = yield* Session.Service
1063
- yield* llm.hang
1064
-
1065
- const chat = yield* sessions.create({})
1066
- yield* user(chat.id, "hi")
1067
-
1068
- const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1069
- yield* llm.wait(1)
1070
-
1071
- const exit = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
1072
- expect(Exit.isFailure(exit)).toBe(true)
1073
- if (Exit.isFailure(exit)) {
1074
- expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
1075
- }
1076
-
1077
- yield* prompt.cancel(chat.id)
1078
- yield* Fiber.await(fiber)
1079
- }),
1080
- { git: true, config: providerCfg },
1081
- ),
1082
- 3_000,
1083
- )
1084
-
1085
- it.live("assertNotBusy succeeds when idle", () =>
1086
- provideTmpdirInstance(
1087
- (_dir) =>
1088
- Effect.gen(function* () {
1089
- const run = yield* SessionRunState.Service
1090
- const sessions = yield* Session.Service
1091
-
1092
- const chat = yield* sessions.create({})
1093
- const exit = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
1094
- expect(Exit.isSuccess(exit)).toBe(true)
1095
- }),
1096
- { git: true },
1097
- ),
1098
- )
1099
-
1100
- // Shell semantics
1101
-
1102
- it.live(
1103
- "shell rejects with BusyError when loop running",
1104
- () =>
1105
- provideTmpdirServer(
1106
- Effect.fnUntraced(function* ({ llm }) {
1107
- const prompt = yield* SessionPrompt.Service
1108
- const sessions = yield* Session.Service
1109
- const chat = yield* sessions.create({ title: "Pinned" })
1110
- yield* llm.hang
1111
- yield* user(chat.id, "hi")
1112
-
1113
- const fiber = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1114
- yield* llm.wait(1)
1115
-
1116
- const exit = yield* prompt.shell({ sessionID: chat.id, agent: "build", command: "echo hi" }).pipe(Effect.exit)
1117
- expect(Exit.isFailure(exit)).toBe(true)
1118
- if (Exit.isFailure(exit)) {
1119
- expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
1120
- }
1121
-
1122
- yield* prompt.cancel(chat.id)
1123
- yield* Fiber.await(fiber)
1124
- }),
1125
- { git: true, config: providerCfg },
1126
- ),
1127
- 3_000,
1128
- )
1129
-
1130
- unix("shell captures stdout and stderr in completed tool output", () =>
1131
- provideTmpdirInstance(
1132
- (_dir) =>
1133
- Effect.gen(function* () {
1134
- const { prompt, run, chat } = yield* boot()
1135
- const result = yield* prompt.shell({
1136
- sessionID: chat.id,
1137
- agent: "build",
1138
- command: "printf out && printf err >&2",
1139
- })
1140
-
1141
- expect(result.info.role).toBe("assistant")
1142
- const tool = completedTool(result.parts)
1143
- if (!tool) return
1144
-
1145
- expect(tool.state.output).toContain("out")
1146
- expect(tool.state.output).toContain("err")
1147
- expect(tool.state.metadata.output).toContain("out")
1148
- expect(tool.state.metadata.output).toContain("err")
1149
- yield* run.assertNotBusy(chat.id)
1150
- }),
1151
- { git: true, config: cfg },
1152
- ),
1153
- )
1154
-
1155
- unix("shell completes a fast command on the preferred shell", () =>
1156
- provideTmpdirInstance(
1157
- (dir) =>
1158
- Effect.gen(function* () {
1159
- const { prompt, run, chat } = yield* boot()
1160
- const result = yield* prompt.shell({
1161
- sessionID: chat.id,
1162
- agent: "build",
1163
- command: "pwd",
1164
- })
1165
-
1166
- expect(result.info.role).toBe("assistant")
1167
- const tool = completedTool(result.parts)
1168
- if (!tool) return
1169
-
1170
- expect(tool.state.input.command).toBe("pwd")
1171
- expect(tool.state.output).toContain(dir)
1172
- expect(tool.state.metadata.output).toContain(dir)
1173
- yield* run.assertNotBusy(chat.id)
1174
- }),
1175
- { git: true, config: cfg },
1176
- ),
1177
- )
1178
-
1179
- unix(
1180
- "shell uses configured shell over env shell",
1181
- () =>
1182
- withSh(() =>
1183
- provideTmpdirInstance(
1184
- (_dir) =>
1185
- Effect.gen(function* () {
1186
- if (!Bun.which("bash")) return
1187
-
1188
- const { prompt, chat } = yield* boot()
1189
- const result = yield* prompt.shell({
1190
- sessionID: chat.id,
1191
- agent: "build",
1192
- command: "[[ 1 -eq 1 ]] && printf configured",
1193
- })
1194
-
1195
- const tool = completedTool(result.parts)
1196
- if (!tool) return
1197
- expect(tool.state.output).toContain("configured")
1198
- }),
1199
- { git: true, config: { ...cfg, shell: "bash" } },
1200
- ),
1201
- ),
1202
- 30_000,
1203
- )
1204
-
1205
- unix("shell commands can change directory after startup", () =>
1206
- provideTmpdirInstance(
1207
- (dir) =>
1208
- Effect.gen(function* () {
1209
- const { prompt, run, chat } = yield* boot()
1210
- const parent = path.dirname(dir)
1211
- const result = yield* prompt.shell({
1212
- sessionID: chat.id,
1213
- agent: "build",
1214
- command: "cd .. && pwd",
1215
- })
1216
-
1217
- expect(result.info.role).toBe("assistant")
1218
- const tool = completedTool(result.parts)
1219
- if (!tool) return
1220
-
1221
- expect(tool.state.output).toContain(parent)
1222
- expect(tool.state.metadata.output).toContain(parent)
1223
- yield* run.assertNotBusy(chat.id)
1224
- }),
1225
- { git: true, config: cfg },
1226
- ),
1227
- )
1228
-
1229
- unix("shell lists files from the project directory", () =>
1230
- provideTmpdirInstance(
1231
- (dir) =>
1232
- Effect.gen(function* () {
1233
- const { prompt, run, chat } = yield* boot()
1234
- yield* Effect.promise(() => Bun.write(path.join(dir, "README.md"), "# e2e\n"))
1235
-
1236
- const result = yield* prompt.shell({
1237
- sessionID: chat.id,
1238
- agent: "build",
1239
- command: "command ls",
1240
- })
1241
-
1242
- expect(result.info.role).toBe("assistant")
1243
- const tool = completedTool(result.parts)
1244
- if (!tool) return
1245
-
1246
- expect(tool.state.input.command).toBe("command ls")
1247
- expect(tool.state.output).toContain("README.md")
1248
- expect(tool.state.metadata.output).toContain("README.md")
1249
- yield* run.assertNotBusy(chat.id)
1250
- }),
1251
- { git: true, config: cfg },
1252
- ),
1253
- )
1254
-
1255
- unix("shell captures stderr from a failing command", () =>
1256
- provideTmpdirInstance(
1257
- (_dir) =>
1258
- Effect.gen(function* () {
1259
- const { prompt, run, chat } = yield* boot()
1260
- const result = yield* prompt.shell({
1261
- sessionID: chat.id,
1262
- agent: "build",
1263
- command: "command -v __nonexistent_cmd_e2e__ || echo 'not found' >&2; exit 1",
1264
- })
1265
-
1266
- expect(result.info.role).toBe("assistant")
1267
- const tool = completedTool(result.parts)
1268
- if (!tool) return
1269
-
1270
- expect(tool.state.output).toContain("not found")
1271
- expect(tool.state.metadata.output).toContain("not found")
1272
- yield* run.assertNotBusy(chat.id)
1273
- }),
1274
- { git: true, config: cfg },
1275
- ),
1276
- )
1277
-
1278
- unix(
1279
- "shell updates running metadata before process exit",
1280
- () =>
1281
- withSh(() =>
1282
- provideTmpdirInstance(
1283
- (_dir) =>
1284
- Effect.gen(function* () {
1285
- const { prompt, chat } = yield* boot()
1286
-
1287
- const fiber = yield* prompt
1288
- .shell({ sessionID: chat.id, agent: "build", command: "printf first && sleep 0.2 && printf second" })
1289
- .pipe(Effect.forkChild)
1290
-
1291
- yield* Effect.promise(async () => {
1292
- const start = Date.now()
1293
- while (Date.now() - start < 5000) {
1294
- const msgs = await MessageV2.filterCompacted(MessageV2.stream(chat.id))
1295
- const taskMsg = msgs.find((item) => item.info.role === "assistant")
1296
- const tool = taskMsg ? toolPart(taskMsg.parts) : undefined
1297
- if (tool?.state.status === "running" && tool.state.metadata?.output.includes("first")) return
1298
- await new Promise((done) => setTimeout(done, 20))
1299
- }
1300
- throw new Error("timed out waiting for running shell metadata")
1301
- })
1302
-
1303
- const exit = yield* Fiber.await(fiber)
1304
- expect(Exit.isSuccess(exit)).toBe(true)
1305
- }),
1306
- { git: true, config: cfg },
1307
- ),
1308
- ),
1309
- 30_000,
1310
- )
1311
-
1312
- it.live(
1313
- "loop waits while shell runs and starts after shell exits",
1314
- () =>
1315
- provideTmpdirServer(
1316
- Effect.fnUntraced(function* ({ llm }) {
1317
- const prompt = yield* SessionPrompt.Service
1318
- const sessions = yield* Session.Service
1319
- const status = yield* SessionStatus.Service
1320
- const chat = yield* sessions.create({
1321
- title: "Pinned",
1322
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1323
- })
1324
- yield* llm.text("after-shell")
1325
-
1326
- const sh = yield* prompt
1327
- .shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
1328
- .pipe(Effect.forkChild)
1329
- yield* waitFor("shell busy", status.get(chat.id).pipe(Effect.map((s) => (s.type === "busy" ? s : undefined))))
1330
-
1331
- const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1332
- yield* Effect.sleep(50)
1333
-
1334
- expect(yield* llm.calls).toBe(0)
1335
-
1336
- yield* Fiber.await(sh)
1337
- const exit = yield* Fiber.await(loop)
1338
-
1339
- expect(Exit.isSuccess(exit)).toBe(true)
1340
- if (Exit.isSuccess(exit)) {
1341
- expect(exit.value.info.role).toBe("assistant")
1342
- expect(exit.value.parts.some((part) => part.type === "text" && part.text === "after-shell")).toBe(true)
1343
- }
1344
- expect(yield* llm.calls).toBe(1)
1345
- }),
1346
- { git: true, config: providerCfg },
1347
- ),
1348
- 30_000,
1349
- )
1350
-
1351
- it.live(
1352
- "shell completion resumes queued loop callers",
1353
- () =>
1354
- provideTmpdirServer(
1355
- Effect.fnUntraced(function* ({ llm }) {
1356
- const prompt = yield* SessionPrompt.Service
1357
- const sessions = yield* Session.Service
1358
- const status = yield* SessionStatus.Service
1359
- const chat = yield* sessions.create({
1360
- title: "Pinned",
1361
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1362
- })
1363
- yield* llm.text("done")
1364
-
1365
- const sh = yield* prompt
1366
- .shell({ sessionID: chat.id, agent: "build", command: "sleep 0.2" })
1367
- .pipe(Effect.forkChild)
1368
- yield* waitFor("shell busy", status.get(chat.id).pipe(Effect.map((s) => (s.type === "busy" ? s : undefined))))
1369
-
1370
- const a = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1371
- const b = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1372
- yield* Effect.sleep(50)
1373
-
1374
- expect(yield* llm.calls).toBe(0)
1375
-
1376
- yield* Fiber.await(sh)
1377
- const [ea, eb] = yield* Effect.all([Fiber.await(a), Fiber.await(b)])
1378
-
1379
- expect(Exit.isSuccess(ea)).toBe(true)
1380
- expect(Exit.isSuccess(eb)).toBe(true)
1381
- if (Exit.isSuccess(ea) && Exit.isSuccess(eb)) {
1382
- expect(ea.value.info.id).toBe(eb.value.info.id)
1383
- expect(ea.value.info.role).toBe("assistant")
1384
- }
1385
- expect(yield* llm.calls).toBe(1)
1386
- }),
1387
- { git: true, config: providerCfg },
1388
- ),
1389
- 30_000,
1390
- )
1391
-
1392
- unix(
1393
- "command ! expansion uses configured shell over env shell",
1394
- () =>
1395
- withSh(() =>
1396
- provideTmpdirServer(
1397
- ({ llm }) =>
1398
- Effect.gen(function* () {
1399
- if (!Bun.which("bash")) return
1400
-
1401
- const { prompt, chat } = yield* boot()
1402
- yield* llm.text("done")
1403
-
1404
- const result = yield* prompt.command({
1405
- sessionID: chat.id,
1406
- command: "probe",
1407
- arguments: "",
1408
- })
1409
-
1410
- expect(result.info.role).toBe("assistant")
1411
- const inputs = yield* llm.inputs
1412
- expect(JSON.stringify(inputs.at(-1)?.messages)).toContain("configured")
1413
- }),
1414
- {
1415
- git: true,
1416
- config: (url) => ({
1417
- ...providerCfg(url),
1418
- shell: "bash",
1419
- command: {
1420
- probe: {
1421
- template: "Probe: !`[[ 1 -eq 1 ]] && printf configured`",
1422
- },
1423
- },
1424
- }),
1425
- },
1426
- ),
1427
- ),
1428
- 30_000,
1429
- )
1430
-
1431
- unix(
1432
- "cancel interrupts shell and resolves cleanly",
1433
- () =>
1434
- withSh(() =>
1435
- provideTmpdirInstance(
1436
- (_dir) =>
1437
- Effect.gen(function* () {
1438
- const { prompt, run, chat } = yield* boot()
1439
-
1440
- const sh = yield* prompt
1441
- .shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
1442
- .pipe(Effect.forkChild)
1443
- yield* Effect.sleep(50)
1444
-
1445
- yield* prompt.cancel(chat.id)
1446
-
1447
- const status = yield* SessionStatus.Service
1448
- expect((yield* status.get(chat.id)).type).toBe("idle")
1449
- const busy = yield* run.assertNotBusy(chat.id).pipe(Effect.exit)
1450
- expect(Exit.isSuccess(busy)).toBe(true)
1451
-
1452
- const exit = yield* Fiber.await(sh)
1453
- expect(Exit.isSuccess(exit)).toBe(true)
1454
- if (Exit.isSuccess(exit)) {
1455
- expect(exit.value.info.role).toBe("assistant")
1456
- const tool = completedTool(exit.value.parts)
1457
- if (tool) {
1458
- expect(tool.state.output).toContain("User aborted the command")
1459
- }
1460
- }
1461
- }),
1462
- { git: true, config: cfg },
1463
- ),
1464
- ),
1465
- 30_000,
1466
- )
1467
- unix(
1468
- "cancel persists aborted shell result when shell ignores TERM",
1469
- () =>
1470
- withSh(() =>
1471
- provideTmpdirInstance(
1472
- (_dir) =>
1473
- Effect.gen(function* () {
1474
- const { prompt, chat, sessions } = yield* boot()
1475
-
1476
- const sh = yield* prompt
1477
- .shell({
1478
- sessionID: chat.id,
1479
- agent: "build",
1480
- command: "trap '' TERM; printf started; sleep 10; printf not-killed",
1481
- })
1482
- .pipe(Effect.forkChild)
1483
- yield* waitFor(
1484
- "shell start output",
1485
- sessions
1486
- .messages({ sessionID: chat.id })
1487
- .pipe(
1488
- Effect.map((msgs) =>
1489
- msgs
1490
- .flatMap((msg) => msg.parts)
1491
- .find(
1492
- (part) =>
1493
- part.type === "tool" &&
1494
- part.state.status === "running" &&
1495
- (part.state.metadata?.output ?? "").includes("started"),
1496
- ),
1497
- ),
1498
- ),
1499
- )
1500
-
1501
- yield* prompt.cancel(chat.id)
1502
-
1503
- const exit = yield* Fiber.await(sh)
1504
- expect(Exit.isSuccess(exit)).toBe(true)
1505
- if (Exit.isSuccess(exit)) {
1506
- expect(exit.value.info.role).toBe("assistant")
1507
- const tool = completedTool(exit.value.parts)
1508
- if (tool) {
1509
- expect(tool.state.output).toContain("started")
1510
- expect(tool.state.output).toContain("User aborted the command")
1511
- expect(tool.state.output).not.toContain("not-killed")
1512
- }
1513
- }
1514
- }),
1515
- { git: true, config: cfg },
1516
- ),
1517
- ),
1518
- 30_000,
1519
- )
1520
-
1521
- unix(
1522
- "cancel finalizes interrupted bash tool output through normal truncation",
1523
- () =>
1524
- provideTmpdirServer(
1525
- ({ dir, llm }) =>
1526
- Effect.gen(function* () {
1527
- const prompt = yield* SessionPrompt.Service
1528
- const sessions = yield* Session.Service
1529
- const chat = yield* sessions.create({
1530
- title: "Interrupted bash truncation",
1531
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
1532
- })
1533
-
1534
- yield* prompt.prompt({
1535
- sessionID: chat.id,
1536
- agent: "build",
1537
- noReply: true,
1538
- parts: [{ type: "text", text: "run bash" }],
1539
- })
1540
-
1541
- yield* llm.tool("bash", {
1542
- command:
1543
- 'i=0; while [ "$i" -lt 4000 ]; do printf "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx %05d\\n" "$i"; i=$((i + 1)); done; sleep 30',
1544
- description: "Print many lines",
1545
- timeout: 30_000,
1546
- workdir: path.resolve(dir),
1547
- })
1548
-
1549
- const run = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1550
- yield* llm.wait(1)
1551
- yield* Effect.sleep(150)
1552
- yield* prompt.cancel(chat.id)
1553
-
1554
- const exit = yield* Fiber.await(run)
1555
- expect(Exit.isSuccess(exit)).toBe(true)
1556
- if (Exit.isFailure(exit)) return
1557
-
1558
- const tool = completedTool(exit.value.parts)
1559
- if (!tool) return
1560
-
1561
- expect(tool.state.metadata.truncated).toBe(true)
1562
- expect(typeof tool.state.metadata.outputPath).toBe("string")
1563
- expect(tool.state.output).toMatch(/\.\.\.output truncated\.\.\./)
1564
- expect(tool.state.output).toMatch(/Full output saved to:\s+\S+/)
1565
- expect(tool.state.output).not.toContain("Tool execution aborted")
1566
- }),
1567
- { git: true, config: providerCfg },
1568
- ),
1569
- 30_000,
1570
- )
1571
-
1572
- unix(
1573
- "cancel interrupts loop queued behind shell",
1574
- () =>
1575
- provideTmpdirInstance(
1576
- (_dir) =>
1577
- Effect.gen(function* () {
1578
- const { prompt, chat } = yield* boot()
1579
-
1580
- const sh = yield* prompt
1581
- .shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
1582
- .pipe(Effect.forkChild)
1583
- yield* Effect.sleep(50)
1584
-
1585
- const loop = yield* prompt.loop({ sessionID: chat.id }).pipe(Effect.forkChild)
1586
- yield* Effect.sleep(50)
1587
-
1588
- yield* prompt.cancel(chat.id)
1589
-
1590
- const exit = yield* Fiber.await(loop)
1591
- expect(Exit.isSuccess(exit)).toBe(true)
1592
- if (Exit.isSuccess(exit)) {
1593
- const tool = completedTool(exit.value.parts)
1594
- expect(tool?.state.output).toContain("User aborted the command")
1595
- }
1596
-
1597
- yield* Fiber.await(sh)
1598
- }),
1599
- { git: true, config: cfg },
1600
- ),
1601
- 30_000,
1602
- )
1603
-
1604
- unix(
1605
- "shell rejects when another shell is already running",
1606
- () =>
1607
- withSh(() =>
1608
- provideTmpdirInstance(
1609
- (_dir) =>
1610
- Effect.gen(function* () {
1611
- const { prompt, chat } = yield* boot()
1612
-
1613
- const a = yield* prompt
1614
- .shell({ sessionID: chat.id, agent: "build", command: "sleep 30" })
1615
- .pipe(Effect.forkChild)
1616
- yield* Effect.sleep(50)
1617
-
1618
- const exit = yield* prompt
1619
- .shell({ sessionID: chat.id, agent: "build", command: "echo hi" })
1620
- .pipe(Effect.exit)
1621
- expect(Exit.isFailure(exit)).toBe(true)
1622
- if (Exit.isFailure(exit)) {
1623
- expect(Cause.squash(exit.cause)).toBeInstanceOf(Session.BusyError)
1624
- }
1625
-
1626
- yield* prompt.cancel(chat.id)
1627
- yield* Fiber.await(a)
1628
- }),
1629
- { git: true, config: cfg },
1630
- ),
1631
- ),
1632
- 30_000,
1633
- )
1634
-
1635
- // Abort signal propagation tests for inline tool execution
1636
-
1637
- /** Override a tool's execute to hang until aborted. Returns ready/aborted defers and a finalizer. */
1638
- function hangUntilAborted(tool: { execute: (...args: any[]) => any }) {
1639
- const ready = defer<void>()
1640
- const aborted = defer<void>()
1641
- const original = tool.execute
1642
- tool.execute = (_args: any, ctx: any) => {
1643
- ready.resolve()
1644
- ctx.abort.addEventListener("abort", () => aborted.resolve(), { once: true })
1645
- return Effect.callback<never>(() => {})
1646
- }
1647
- const restore = Effect.addFinalizer(() => Effect.sync(() => void (tool.execute = original)))
1648
- return { ready, aborted, restore }
1649
- }
1650
-
1651
- it.live(
1652
- "interrupt propagates abort signal to read tool via file part (text/plain)",
1653
- () =>
1654
- provideTmpdirInstance(
1655
- (dir) =>
1656
- Effect.gen(function* () {
1657
- const registry = yield* ToolRegistry.Service
1658
- const { read } = yield* registry.named()
1659
- const { ready, aborted, restore } = hangUntilAborted(read)
1660
- yield* restore
1661
-
1662
- const prompt = yield* SessionPrompt.Service
1663
- const sessions = yield* Session.Service
1664
- const chat = yield* sessions.create({ title: "Abort Test" })
1665
-
1666
- const testFile = path.join(dir, "test.txt")
1667
- yield* Effect.promise(() => Bun.write(testFile, "hello world"))
1668
-
1669
- const fiber = yield* prompt
1670
- .prompt({
1671
- sessionID: chat.id,
1672
- agent: "build",
1673
- parts: [
1674
- { type: "text", text: "read this" },
1675
- { type: "file", url: `file://${testFile}`, filename: "test.txt", mime: "text/plain" },
1676
- ],
1677
- })
1678
- .pipe(Effect.forkChild)
1679
-
1680
- yield* Effect.promise(() => ready.promise)
1681
- yield* Fiber.interrupt(fiber)
1682
-
1683
- yield* Effect.promise(() =>
1684
- Promise.race([
1685
- aborted.promise,
1686
- new Promise<void>((_, reject) =>
1687
- setTimeout(() => reject(new Error("abort signal not propagated within 2s")), 2_000),
1688
- ),
1689
- ]),
1690
- )
1691
- }),
1692
- { git: true, config: cfg },
1693
- ),
1694
- 30_000,
1695
- )
1696
-
1697
- it.live(
1698
- "interrupt propagates abort signal to read tool via file part (directory)",
1699
- () =>
1700
- provideTmpdirInstance(
1701
- (dir) =>
1702
- Effect.gen(function* () {
1703
- const registry = yield* ToolRegistry.Service
1704
- const { read } = yield* registry.named()
1705
- const { ready, aborted, restore } = hangUntilAborted(read)
1706
- yield* restore
1707
-
1708
- const prompt = yield* SessionPrompt.Service
1709
- const sessions = yield* Session.Service
1710
- const chat = yield* sessions.create({ title: "Abort Test" })
1711
-
1712
- const fiber = yield* prompt
1713
- .prompt({
1714
- sessionID: chat.id,
1715
- agent: "build",
1716
- parts: [
1717
- { type: "text", text: "read this" },
1718
- { type: "file", url: `file://${dir}`, filename: "dir", mime: "application/x-directory" },
1719
- ],
1720
- })
1721
- .pipe(Effect.forkChild)
1722
-
1723
- yield* Effect.promise(() => ready.promise)
1724
- yield* Fiber.interrupt(fiber)
1725
-
1726
- yield* Effect.promise(() =>
1727
- Promise.race([
1728
- aborted.promise,
1729
- new Promise<void>((_, reject) =>
1730
- setTimeout(() => reject(new Error("abort signal not propagated within 2s")), 2_000),
1731
- ),
1732
- ]),
1733
- )
1734
- }),
1735
- { git: true, config: cfg },
1736
- ),
1737
- 30_000,
1738
- )
1739
-
1740
- // Missing file handling
1741
-
1742
- it.live("does not fail the prompt when a file part is missing", () =>
1743
- provideTmpdirInstance(
1744
- (dir) =>
1745
- Effect.gen(function* () {
1746
- const prompt = yield* SessionPrompt.Service
1747
- const sessions = yield* Session.Service
1748
- const session = yield* sessions.create({})
1749
-
1750
- const missing = path.join(dir, "does-not-exist.ts")
1751
- const msg = yield* prompt.prompt({
1752
- sessionID: session.id,
1753
- agent: "build",
1754
- noReply: true,
1755
- parts: [
1756
- { type: "text", text: "please review @does-not-exist.ts" },
1757
- {
1758
- type: "file",
1759
- mime: "text/plain",
1760
- url: `file://${missing}`,
1761
- filename: "does-not-exist.ts",
1762
- },
1763
- ],
1764
- })
1765
-
1766
- if (msg.info.role !== "user") throw new Error("expected user message")
1767
- const hasFailure = msg.parts.some(
1768
- (part) => part.type === "text" && part.synthetic && part.text.includes("Read tool failed to read"),
1769
- )
1770
- expect(hasFailure).toBe(true)
1771
-
1772
- yield* sessions.remove(session.id)
1773
- }),
1774
- { git: true, config: cfg },
1775
- ),
1776
- )
1777
-
1778
- it.live("keeps stored part order stable when file resolution is async", () =>
1779
- provideTmpdirInstance(
1780
- (dir) =>
1781
- Effect.gen(function* () {
1782
- const prompt = yield* SessionPrompt.Service
1783
- const sessions = yield* Session.Service
1784
- const session = yield* sessions.create({})
1785
-
1786
- const missing = path.join(dir, "still-missing.ts")
1787
- const msg = yield* prompt.prompt({
1788
- sessionID: session.id,
1789
- agent: "build",
1790
- noReply: true,
1791
- parts: [
1792
- {
1793
- type: "file",
1794
- mime: "text/plain",
1795
- url: `file://${missing}`,
1796
- filename: "still-missing.ts",
1797
- },
1798
- { type: "text", text: "after-file" },
1799
- ],
1800
- })
1801
-
1802
- if (msg.info.role !== "user") throw new Error("expected user message")
1803
-
1804
- const stored = MessageV2.get({
1805
- sessionID: session.id,
1806
- messageID: msg.info.id,
1807
- })
1808
- const text = stored.parts.filter((part) => part.type === "text").map((part) => part.text)
1809
-
1810
- expect(text[0]?.startsWith("Called the Read tool with the following input:")).toBe(true)
1811
- expect(text[1]?.includes("Read tool failed to read")).toBe(true)
1812
- expect(text[2]).toBe("after-file")
1813
-
1814
- yield* sessions.remove(session.id)
1815
- }),
1816
- { git: true, config: cfg },
1817
- ),
1818
- )
1819
-
1820
- // Special characters in filenames
1821
-
1822
- it.live("handles filenames with # character", () =>
1823
- provideTmpdirInstance(
1824
- (dir) =>
1825
- Effect.gen(function* () {
1826
- yield* Effect.promise(() => Bun.write(path.join(dir, "file#name.txt"), "special content\n"))
1827
-
1828
- const prompt = yield* SessionPrompt.Service
1829
- const sessions = yield* Session.Service
1830
- const session = yield* sessions.create({})
1831
- const parts = yield* prompt.resolvePromptParts("Read @file#name.txt")
1832
- const fileParts = parts.filter((part) => part.type === "file")
1833
-
1834
- expect(fileParts.length).toBe(1)
1835
- expect(fileParts[0].filename).toBe("file#name.txt")
1836
- expect(fileParts[0].url).toContain("%23")
1837
-
1838
- const decodedPath = fileURLToPath(fileParts[0].url)
1839
- expect(decodedPath).toBe(path.join(dir, "file#name.txt"))
1840
-
1841
- const message = yield* prompt.prompt({
1842
- sessionID: session.id,
1843
- parts,
1844
- noReply: true,
1845
- })
1846
- const stored = MessageV2.get({ sessionID: session.id, messageID: message.info.id })
1847
- const textParts = stored.parts.filter((part) => part.type === "text")
1848
- const hasContent = textParts.some((part) => part.text.includes("special content"))
1849
- expect(hasContent).toBe(true)
1850
-
1851
- yield* sessions.remove(session.id)
1852
- }),
1853
- { git: true, config: cfg },
1854
- ),
1855
- )
1856
-
1857
- // Regression: empty assistant turn loop
1858
-
1859
- it.live("does not loop empty assistant turns for a simple reply", () =>
1860
- provideTmpdirServer(
1861
- Effect.fnUntraced(function* ({ llm }) {
1862
- const prompt = yield* SessionPrompt.Service
1863
- const sessions = yield* Session.Service
1864
- const session = yield* sessions.create({ title: "Prompt regression" })
1865
-
1866
- yield* llm.text("packages/saeeol/src/session/processor.ts")
1867
-
1868
- const result = yield* prompt.prompt({
1869
- sessionID: session.id,
1870
- agent: "build",
1871
- parts: [{ type: "text", text: "Where is SessionProcessor?" }],
1872
- })
1873
-
1874
- expect(result.info.role).toBe("assistant")
1875
- expect(result.parts.some((part) => part.type === "text" && part.text.includes("processor.ts"))).toBe(true)
1876
-
1877
- const msgs = yield* sessions.messages({ sessionID: session.id })
1878
- expect(msgs.filter((msg) => msg.info.role === "assistant")).toHaveLength(1)
1879
- expect(yield* llm.calls).toBe(1)
1880
- }),
1881
- { git: true, config: providerCfg },
1882
- ),
1883
- )
1884
-
1885
- it.live(
1886
- "records aborted errors when prompt is cancelled mid-stream",
1887
- () =>
1888
- provideTmpdirServer(
1889
- Effect.fnUntraced(function* ({ llm }) {
1890
- const prompt = yield* SessionPrompt.Service
1891
- const sessions = yield* Session.Service
1892
- const session = yield* sessions.create({ title: "Prompt cancel regression" })
1893
-
1894
- yield* llm.hang
1895
-
1896
- const fiber = yield* prompt
1897
- .prompt({
1898
- sessionID: session.id,
1899
- agent: "build",
1900
- parts: [{ type: "text", text: "Cancel me" }],
1901
- })
1902
- .pipe(Effect.forkChild)
1903
-
1904
- yield* llm.wait(1)
1905
- yield* prompt.cancel(session.id)
1906
-
1907
- const exit = yield* Fiber.await(fiber)
1908
- expect(Exit.isSuccess(exit)).toBe(true)
1909
- if (Exit.isSuccess(exit)) {
1910
- expect(exit.value.info.role).toBe("assistant")
1911
- if (exit.value.info.role === "assistant") {
1912
- expect(exit.value.info.error?.name).toBe("MessageAbortedError")
1913
- }
1914
- }
1915
-
1916
- const msgs = yield* sessions.messages({ sessionID: session.id })
1917
- const last = msgs.findLast((msg) => msg.info.role === "assistant")
1918
- expect(last?.info.role).toBe("assistant")
1919
- if (last?.info.role === "assistant") {
1920
- expect(last.info.error?.name).toBe("MessageAbortedError")
1921
- }
1922
- }),
1923
- { git: true, config: providerCfg },
1924
- ),
1925
- 3_000,
1926
- )
1927
-
1928
- // Agent variant
1929
-
1930
- it.live("applies agent variant only when using agent model", () =>
1931
- provideTmpdirInstance(
1932
- (_dir) =>
1933
- Effect.gen(function* () {
1934
- const prompt = yield* SessionPrompt.Service
1935
- const sessions = yield* Session.Service
1936
- const session = yield* sessions.create({})
1937
-
1938
- const other = yield* prompt.prompt({
1939
- sessionID: session.id,
1940
- agent: "build",
1941
- model: { providerID: ProviderID.make("saeeol"), modelID: ModelID.make("kimi-k2.5-free") },
1942
- noReply: true,
1943
- parts: [{ type: "text", text: "hello" }],
1944
- })
1945
- if (other.info.role !== "user") throw new Error("expected user message")
1946
- expect(other.info.model.variant).toBeUndefined()
1947
-
1948
- const match = yield* prompt.prompt({
1949
- sessionID: session.id,
1950
- agent: "build",
1951
- noReply: true,
1952
- parts: [{ type: "text", text: "hello again" }],
1953
- })
1954
- if (match.info.role !== "user") throw new Error("expected user message")
1955
- expect(match.info.model).toEqual({
1956
- providerID: ProviderID.make("test"),
1957
- modelID: ModelID.make("test-model"),
1958
- variant: "xhigh",
1959
- })
1960
- expect(match.info.model.variant).toBe("xhigh")
1961
-
1962
- const override = yield* prompt.prompt({
1963
- sessionID: session.id,
1964
- agent: "build",
1965
- noReply: true,
1966
- variant: "high",
1967
- parts: [{ type: "text", text: "hello third" }],
1968
- })
1969
- if (override.info.role !== "user") throw new Error("expected user message")
1970
- expect(override.info.model.variant).toBe("high")
1971
-
1972
- yield* sessions.remove(session.id)
1973
- }),
1974
- {
1975
- git: true,
1976
- config: {
1977
- ...cfg,
1978
- provider: {
1979
- ...cfg.provider,
1980
- test: {
1981
- ...cfg.provider.test,
1982
- models: {
1983
- "test-model": {
1984
- ...cfg.provider.test.models["test-model"],
1985
- variants: { xhigh: {}, high: {} },
1986
- },
1987
- },
1988
- },
1989
- },
1990
- agent: {
1991
- build: {
1992
- model: "test/test-model",
1993
- variant: "xhigh",
1994
- },
1995
- },
1996
- },
1997
- },
1998
- ),
1999
- )
2000
- it.live(
2001
- "review command marks child completions with review telemetry",
2002
- () =>
2003
- provideTmpdirServer(
2004
- Effect.fnUntraced(function* ({ llm }) {
2005
- const trackSpy = spyOn(Telemetry, "trackLlmCompletion")
2006
- const prompt = yield* SessionPrompt.Service
2007
- const sessions = yield* Session.Service
2008
- const chat = yield* sessions.create({
2009
- title: "Review telemetry",
2010
- permission: [{ permission: "*", pattern: "*", action: "allow" }],
2011
- })
2012
-
2013
- // child subagent's first LLM step needs non-zero usage so trackStep fires
2014
- yield* llm.text("review done", { usage: { input: 100, output: 50 } })
2015
-
2016
- yield* prompt.command({
2017
- sessionID: chat.id,
2018
- command: "review",
2019
- arguments: "",
2020
- agent: "general",
2021
- })
2022
-
2023
- const tagged = trackSpy.mock.calls
2024
- .map((args) => args[0] as Parameters<typeof Telemetry.trackLlmCompletion>[0])
2025
- .find((p) => p.mode === "review" && p.feature === "code_reviews" && p.command === "review")
2026
- expect(tagged).toBeDefined()
2027
- }),
2028
- { git: true, config: providerCfg },
2029
- ),
2030
- 30_000,
2031
- )
2032
-
2033
- // Agent / command resolution errors
2034
-
2035
- it.live(
2036
- "unknown agent throws typed error",
2037
- () =>
2038
- provideTmpdirInstance(
2039
- (_dir) =>
2040
- Effect.gen(function* () {
2041
- const prompt = yield* SessionPrompt.Service
2042
- const sessions = yield* Session.Service
2043
- const session = yield* sessions.create({})
2044
- const exit = yield* prompt
2045
- .prompt({
2046
- sessionID: session.id,
2047
- agent: "nonexistent-agent-xyz",
2048
- noReply: true,
2049
- parts: [{ type: "text", text: "hello" }],
2050
- })
2051
- .pipe(Effect.exit)
2052
-
2053
- expect(Exit.isFailure(exit)).toBe(true)
2054
- if (Exit.isFailure(exit)) {
2055
- const err = Cause.squash(exit.cause)
2056
- expect(err).not.toBeInstanceOf(TypeError)
2057
- expect(NamedError.Unknown.isInstance(err)).toBe(true)
2058
- if (NamedError.Unknown.isInstance(err)) {
2059
- expect(err.data.message).toContain('Agent not found: "nonexistent-agent-xyz"')
2060
- }
2061
- }
2062
- }),
2063
- { git: true },
2064
- ),
2065
- 30_000,
2066
- )
2067
-
2068
- it.live(
2069
- "unknown agent error includes available agent names",
2070
- () =>
2071
- provideTmpdirInstance(
2072
- (_dir) =>
2073
- Effect.gen(function* () {
2074
- const prompt = yield* SessionPrompt.Service
2075
- const sessions = yield* Session.Service
2076
- const session = yield* sessions.create({})
2077
- const exit = yield* prompt
2078
- .prompt({
2079
- sessionID: session.id,
2080
- agent: "nonexistent-agent-xyz",
2081
- noReply: true,
2082
- parts: [{ type: "text", text: "hello" }],
2083
- })
2084
- .pipe(Effect.exit)
2085
-
2086
- expect(Exit.isFailure(exit)).toBe(true)
2087
- if (Exit.isFailure(exit)) {
2088
- const err = Cause.squash(exit.cause)
2089
- expect(NamedError.Unknown.isInstance(err)).toBe(true)
2090
- if (NamedError.Unknown.isInstance(err)) {
2091
- expect(err.data.message).toContain("code")
2092
- }
2093
- }
2094
- }),
2095
- { git: true },
2096
- ),
2097
- 30_000,
2098
- )
2099
-
2100
- it.live(
2101
- "unknown command throws typed error with available names",
2102
- () =>
2103
- provideTmpdirInstance(
2104
- (_dir) =>
2105
- Effect.gen(function* () {
2106
- const prompt = yield* SessionPrompt.Service
2107
- const sessions = yield* Session.Service
2108
- const session = yield* sessions.create({})
2109
- const exit = yield* prompt
2110
- .command({
2111
- sessionID: session.id,
2112
- command: "nonexistent-command-xyz",
2113
- arguments: "",
2114
- })
2115
- .pipe(Effect.exit)
2116
-
2117
- expect(Exit.isFailure(exit)).toBe(true)
2118
- if (Exit.isFailure(exit)) {
2119
- const err = Cause.squash(exit.cause)
2120
- expect(err).not.toBeInstanceOf(TypeError)
2121
- expect(NamedError.Unknown.isInstance(err)).toBe(true)
2122
- if (NamedError.Unknown.isInstance(err)) {
2123
- expect(err.data.message).toContain('Command not found: "nonexistent-command-xyz"')
2124
- expect(err.data.message).toContain("init")
2125
- }
2126
- }
2127
- }),
2128
- { git: true },
2129
- ),
2130
- 30_000,
2131
- )