anymous 1.2.7 → 1.3.1

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 (448) hide show
  1. package/bin/anymous.exe +7 -0
  2. package/package.json +20 -135
  3. package/postinstall.mjs +214 -0
  4. package/bin/anymous.cjs +0 -45
  5. package/src/account/account.ts +0 -473
  6. package/src/account/repo.ts +0 -171
  7. package/src/account/schema.ts +0 -99
  8. package/src/account/url.ts +0 -8
  9. package/src/acp/agent.ts +0 -95
  10. package/src/acp/config-option.ts +0 -203
  11. package/src/acp/content.ts +0 -269
  12. package/src/acp/directory.ts +0 -212
  13. package/src/acp/error.ts +0 -97
  14. package/src/acp/event.ts +0 -342
  15. package/src/acp/permission.ts +0 -254
  16. package/src/acp/profile.ts +0 -42
  17. package/src/acp/service.ts +0 -1097
  18. package/src/acp/session.ts +0 -232
  19. package/src/acp/tool.ts +0 -364
  20. package/src/acp/usage.ts +0 -239
  21. package/src/agent/agent.ts +0 -973
  22. package/src/agent/generate.txt +0 -75
  23. package/src/agent/prompt/architect.txt +0 -26
  24. package/src/agent/prompt/backend.txt +0 -26
  25. package/src/agent/prompt/build.txt +0 -31
  26. package/src/agent/prompt/code-reviewer.txt +0 -29
  27. package/src/agent/prompt/compaction.txt +0 -45
  28. package/src/agent/prompt/database.txt +0 -27
  29. package/src/agent/prompt/debug-tools.txt +0 -40
  30. package/src/agent/prompt/debug.txt +0 -23
  31. package/src/agent/prompt/devops.txt +0 -26
  32. package/src/agent/prompt/docs.txt +0 -23
  33. package/src/agent/prompt/exe-extractor.txt +0 -39
  34. package/src/agent/prompt/explore.txt +0 -42
  35. package/src/agent/prompt/frontend.txt +0 -29
  36. package/src/agent/prompt/general.txt +0 -25
  37. package/src/agent/prompt/memory-dump.txt +0 -37
  38. package/src/agent/prompt/pentest-critic.txt +0 -51
  39. package/src/agent/prompt/pentest-enumerator.txt +0 -72
  40. package/src/agent/prompt/pentest-exploiter.txt +0 -69
  41. package/src/agent/prompt/pentest-identity.txt +0 -59
  42. package/src/agent/prompt/pentest-lead.txt +0 -46
  43. package/src/agent/prompt/pentest-postexploit.txt +0 -84
  44. package/src/agent/prompt/pentest-recon.txt +0 -50
  45. package/src/agent/prompt/pentest-reporter.txt +0 -76
  46. package/src/agent/prompt/pentest-scanner.txt +0 -57
  47. package/src/agent/prompt/pentest-webapp.txt +0 -94
  48. package/src/agent/prompt/performance.txt +0 -27
  49. package/src/agent/prompt/plan.txt +0 -35
  50. package/src/agent/prompt/refactor.txt +0 -31
  51. package/src/agent/prompt/reverser-automator.txt +0 -96
  52. package/src/agent/prompt/reverser-binary.txt +0 -62
  53. package/src/agent/prompt/reverser-dynamic.txt +0 -76
  54. package/src/agent/prompt/reverser-source.txt +0 -93
  55. package/src/agent/prompt/reverser-static.txt +0 -76
  56. package/src/agent/prompt/security.txt +0 -34
  57. package/src/agent/prompt/summary.txt +0 -22
  58. package/src/agent/prompt/test-writer.txt +0 -34
  59. package/src/agent/prompt/title.txt +0 -44
  60. package/src/agent/prompt/web-designer.txt +0 -23
  61. package/src/agent/subagent-permissions.ts +0 -27
  62. package/src/audio.d.ts +0 -14
  63. package/src/auth/index.ts +0 -97
  64. package/src/background/job.ts +0 -37
  65. package/src/bus/global.ts +0 -22
  66. package/src/cli/bootstrap.ts +0 -11
  67. package/src/cli/cmd/account.ts +0 -264
  68. package/src/cli/cmd/acp.ts +0 -73
  69. package/src/cli/cmd/agent.ts +0 -259
  70. package/src/cli/cmd/attach.ts +0 -148
  71. package/src/cli/cmd/cmd.ts +0 -7
  72. package/src/cli/cmd/db.ts +0 -62
  73. package/src/cli/cmd/debug/agent.handler.ts +0 -193
  74. package/src/cli/cmd/debug/agent.ts +0 -27
  75. package/src/cli/cmd/debug/config.ts +0 -14
  76. package/src/cli/cmd/debug/file.ts +0 -73
  77. package/src/cli/cmd/debug/index.ts +0 -87
  78. package/src/cli/cmd/debug/lsp.ts +0 -50
  79. package/src/cli/cmd/debug/ripgrep.ts +0 -79
  80. package/src/cli/cmd/debug/scrap.ts +0 -16
  81. package/src/cli/cmd/debug/skill.ts +0 -15
  82. package/src/cli/cmd/debug/snapshot.ts +0 -50
  83. package/src/cli/cmd/debug/startup.ts +0 -11
  84. package/src/cli/cmd/debug/v2.ts +0 -42
  85. package/src/cli/cmd/export.ts +0 -292
  86. package/src/cli/cmd/generate.ts +0 -54
  87. package/src/cli/cmd/github.handler.ts +0 -1593
  88. package/src/cli/cmd/github.shared.ts +0 -30
  89. package/src/cli/cmd/github.ts +0 -42
  90. package/src/cli/cmd/import.ts +0 -230
  91. package/src/cli/cmd/mcp.ts +0 -840
  92. package/src/cli/cmd/models.ts +0 -66
  93. package/src/cli/cmd/plug.ts +0 -230
  94. package/src/cli/cmd/pr.ts +0 -115
  95. package/src/cli/cmd/prompt-display.ts +0 -1
  96. package/src/cli/cmd/providers.ts +0 -534
  97. package/src/cli/cmd/run/demo.ts +0 -1274
  98. package/src/cli/cmd/run/entry.body.ts +0 -205
  99. package/src/cli/cmd/run/footer.command.tsx +0 -1070
  100. package/src/cli/cmd/run/footer.menu.tsx +0 -351
  101. package/src/cli/cmd/run/footer.permission.tsx +0 -472
  102. package/src/cli/cmd/run/footer.prompt.tsx +0 -1315
  103. package/src/cli/cmd/run/footer.question.tsx +0 -573
  104. package/src/cli/cmd/run/footer.subagent.tsx +0 -175
  105. package/src/cli/cmd/run/footer.ts +0 -1129
  106. package/src/cli/cmd/run/footer.view.tsx +0 -945
  107. package/src/cli/cmd/run/footer.width.ts +0 -27
  108. package/src/cli/cmd/run/permission.shared.ts +0 -256
  109. package/src/cli/cmd/run/prompt.editor.ts +0 -157
  110. package/src/cli/cmd/run/prompt.shared.ts +0 -153
  111. package/src/cli/cmd/run/question.shared.ts +0 -340
  112. package/src/cli/cmd/run/runtime.boot.ts +0 -202
  113. package/src/cli/cmd/run/runtime.lifecycle.ts +0 -410
  114. package/src/cli/cmd/run/runtime.queue.ts +0 -349
  115. package/src/cli/cmd/run/runtime.shared.ts +0 -17
  116. package/src/cli/cmd/run/runtime.stdin.ts +0 -37
  117. package/src/cli/cmd/run/runtime.ts +0 -821
  118. package/src/cli/cmd/run/scrollback.shared.ts +0 -92
  119. package/src/cli/cmd/run/scrollback.surface.ts +0 -431
  120. package/src/cli/cmd/run/scrollback.writer.tsx +0 -352
  121. package/src/cli/cmd/run/session-data.ts +0 -1113
  122. package/src/cli/cmd/run/session-replay.ts +0 -374
  123. package/src/cli/cmd/run/session.shared.ts +0 -196
  124. package/src/cli/cmd/run/splash.ts +0 -289
  125. package/src/cli/cmd/run/stream.transport.ts +0 -1462
  126. package/src/cli/cmd/run/stream.ts +0 -175
  127. package/src/cli/cmd/run/subagent-data.ts +0 -876
  128. package/src/cli/cmd/run/theme.ts +0 -690
  129. package/src/cli/cmd/run/tool.ts +0 -1486
  130. package/src/cli/cmd/run/trace.ts +0 -94
  131. package/src/cli/cmd/run/turn-summary.ts +0 -47
  132. package/src/cli/cmd/run/types.ts +0 -350
  133. package/src/cli/cmd/run/variant.shared.ts +0 -216
  134. package/src/cli/cmd/run.ts +0 -1011
  135. package/src/cli/cmd/serve.ts +0 -24
  136. package/src/cli/cmd/session.ts +0 -147
  137. package/src/cli/cmd/stats.ts +0 -393
  138. package/src/cli/cmd/tui.ts +0 -309
  139. package/src/cli/cmd/uninstall.ts +0 -353
  140. package/src/cli/cmd/upgrade.ts +0 -113
  141. package/src/cli/cmd/web.ts +0 -84
  142. package/src/cli/effect/prompt.ts +0 -37
  143. package/src/cli/effect-cmd.ts +0 -96
  144. package/src/cli/error.ts +0 -130
  145. package/src/cli/heap.ts +0 -45
  146. package/src/cli/logo.ts +0 -1
  147. package/src/cli/network.ts +0 -80
  148. package/src/cli/tui/layer.ts +0 -8
  149. package/src/cli/tui/validate-session.ts +0 -29
  150. package/src/cli/tui/worker.ts +0 -80
  151. package/src/cli/ui.ts +0 -146
  152. package/src/cli/upgrade.ts +0 -79
  153. package/src/cli/version.ts +0 -14
  154. package/src/command/index.ts +0 -177
  155. package/src/command/template/initialize.txt +0 -66
  156. package/src/command/template/review.txt +0 -101
  157. package/src/config/agent.ts +0 -59
  158. package/src/config/command.ts +0 -39
  159. package/src/config/config.ts +0 -689
  160. package/src/config/entry-name.ts +0 -19
  161. package/src/config/managed.ts +0 -69
  162. package/src/config/markdown.ts +0 -36
  163. package/src/config/parse.ts +0 -79
  164. package/src/config/paths.ts +0 -45
  165. package/src/config/plugin.ts +0 -79
  166. package/src/config/tui-cwd.ts +0 -5
  167. package/src/config/tui-host-attention.ts +0 -21
  168. package/src/config/tui-migrate.ts +0 -132
  169. package/src/config/tui.ts +0 -276
  170. package/src/config/variable.ts +0 -91
  171. package/src/control-plane/adapters/index.ts +0 -41
  172. package/src/control-plane/adapters/worktree.ts +0 -96
  173. package/src/control-plane/dev/README.md +0 -19
  174. package/src/control-plane/dev/debug-workspace-plugin.ts +0 -73
  175. package/src/control-plane/types.ts +0 -59
  176. package/src/control-plane/util.ts +0 -39
  177. package/src/control-plane/workspace-adapter-runtime.ts +0 -51
  178. package/src/control-plane/workspace-context.ts +0 -26
  179. package/src/control-plane/workspace.ts +0 -964
  180. package/src/effect/app-node-builder-v1.ts +0 -12
  181. package/src/effect/app-runtime.ts +0 -137
  182. package/src/effect/bootstrap-runtime.ts +0 -19
  183. package/src/effect/bridge.ts +0 -84
  184. package/src/effect/config-service.ts +0 -67
  185. package/src/effect/instance-ref.ts +0 -11
  186. package/src/effect/instance-registry.ts +0 -12
  187. package/src/effect/instance-state.ts +0 -69
  188. package/src/effect/promise.ts +0 -17
  189. package/src/effect/run-service.ts +0 -47
  190. package/src/effect/runner.ts +0 -217
  191. package/src/effect/runtime-flags.ts +0 -79
  192. package/src/env/index.ts +0 -41
  193. package/src/event-manifest.ts +0 -3
  194. package/src/event-v2-bridge.ts +0 -71
  195. package/src/format/formatter.ts +0 -404
  196. package/src/format/index.ts +0 -203
  197. package/src/git/index.ts +0 -348
  198. package/src/id/id.ts +0 -80
  199. package/src/ide/index.ts +0 -54
  200. package/src/image/image.ts +0 -172
  201. package/src/index.ts +0 -142
  202. package/src/installation/index.ts +0 -336
  203. package/src/lsp/client.ts +0 -650
  204. package/src/lsp/diagnostic.ts +0 -29
  205. package/src/lsp/language.ts +0 -121
  206. package/src/lsp/launch.ts +0 -21
  207. package/src/lsp/lsp.ts +0 -507
  208. package/src/lsp/server.ts +0 -1983
  209. package/src/markdown.d.ts +0 -4
  210. package/src/mcp/auth.ts +0 -163
  211. package/src/mcp/browser.ts +0 -37
  212. package/src/mcp/catalog.ts +0 -170
  213. package/src/mcp/index.ts +0 -1004
  214. package/src/mcp/oauth-callback.ts +0 -194
  215. package/src/mcp/oauth-provider.ts +0 -259
  216. package/src/memory/memory.ts +0 -133
  217. package/src/node.ts +0 -4
  218. package/src/patch/index.ts +0 -686
  219. package/src/permission/arity.ts +0 -163
  220. package/src/permission/evaluate.ts +0 -1
  221. package/src/permission/index.ts +0 -229
  222. package/src/plugin/azure.ts +0 -26
  223. package/src/plugin/cloudflare.ts +0 -76
  224. package/src/plugin/digitalocean.ts +0 -325
  225. package/src/plugin/github-copilot/copilot.ts +0 -414
  226. package/src/plugin/github-copilot/models.ts +0 -258
  227. package/src/plugin/index.ts +0 -311
  228. package/src/plugin/install.ts +0 -439
  229. package/src/plugin/loader.ts +0 -237
  230. package/src/plugin/meta.ts +0 -188
  231. package/src/plugin/openai/README.md +0 -31
  232. package/src/plugin/openai/codex.ts +0 -565
  233. package/src/plugin/openai/ws-pool.ts +0 -270
  234. package/src/plugin/openai/ws.ts +0 -381
  235. package/src/plugin/pty-environment.ts +0 -24
  236. package/src/plugin/shared.ts +0 -323
  237. package/src/plugin/snowflake-cortex.ts +0 -507
  238. package/src/plugin/tui/internal.ts +0 -10
  239. package/src/plugin/tui/runtime.ts +0 -1131
  240. package/src/plugin/xai.ts +0 -626
  241. package/src/project/bootstrap-service.ts +0 -9
  242. package/src/project/bootstrap.ts +0 -58
  243. package/src/project/instance-context.ts +0 -24
  244. package/src/project/instance-runtime.ts +0 -16
  245. package/src/project/instance-store.ts +0 -213
  246. package/src/project/project.ts +0 -483
  247. package/src/project/vcs.ts +0 -423
  248. package/src/provider/auth.ts +0 -229
  249. package/src/provider/error.ts +0 -188
  250. package/src/provider/model-status.ts +0 -8
  251. package/src/provider/provider.ts +0 -2006
  252. package/src/provider/transform.ts +0 -1832
  253. package/src/question/index.ts +0 -161
  254. package/src/question/schema.ts +0 -4
  255. package/src/server/auth.ts +0 -48
  256. package/src/server/event.ts +0 -10
  257. package/src/server/global-lifecycle.ts +0 -28
  258. package/src/server/init-projectors.ts +0 -3
  259. package/src/server/mdns.ts +0 -47
  260. package/src/server/projectors.ts +0 -1
  261. package/src/server/proxy-util.ts +0 -48
  262. package/src/server/routes/instance/httpapi/AGENTS.md +0 -39
  263. package/src/server/routes/instance/httpapi/api.ts +0 -97
  264. package/src/server/routes/instance/httpapi/errors.ts +0 -193
  265. package/src/server/routes/instance/httpapi/groups/config.ts +0 -65
  266. package/src/server/routes/instance/httpapi/groups/control-plane.ts +0 -35
  267. package/src/server/routes/instance/httpapi/groups/control.ts +0 -76
  268. package/src/server/routes/instance/httpapi/groups/event.ts +0 -29
  269. package/src/server/routes/instance/httpapi/groups/experimental.ts +0 -275
  270. package/src/server/routes/instance/httpapi/groups/file.ts +0 -185
  271. package/src/server/routes/instance/httpapi/groups/global.ts +0 -136
  272. package/src/server/routes/instance/httpapi/groups/instance.ts +0 -206
  273. package/src/server/routes/instance/httpapi/groups/mcp.ts +0 -156
  274. package/src/server/routes/instance/httpapi/groups/metadata.ts +0 -18
  275. package/src/server/routes/instance/httpapi/groups/permission.ts +0 -61
  276. package/src/server/routes/instance/httpapi/groups/project-copy.ts +0 -32
  277. package/src/server/routes/instance/httpapi/groups/project.ts +0 -93
  278. package/src/server/routes/instance/httpapi/groups/provider.ts +0 -101
  279. package/src/server/routes/instance/httpapi/groups/pty.ts +0 -172
  280. package/src/server/routes/instance/httpapi/groups/query.ts +0 -12
  281. package/src/server/routes/instance/httpapi/groups/question.ts +0 -74
  282. package/src/server/routes/instance/httpapi/groups/session.ts +0 -462
  283. package/src/server/routes/instance/httpapi/groups/sync.ts +0 -113
  284. package/src/server/routes/instance/httpapi/groups/tui.ts +0 -208
  285. package/src/server/routes/instance/httpapi/groups/workspace.ts +0 -141
  286. package/src/server/routes/instance/httpapi/handlers/config.ts +0 -34
  287. package/src/server/routes/instance/httpapi/handlers/control-plane.ts +0 -37
  288. package/src/server/routes/instance/httpapi/handlers/control.ts +0 -43
  289. package/src/server/routes/instance/httpapi/handlers/event.ts +0 -99
  290. package/src/server/routes/instance/httpapi/handlers/experimental.ts +0 -193
  291. package/src/server/routes/instance/httpapi/handlers/file.ts +0 -139
  292. package/src/server/routes/instance/httpapi/handlers/global.ts +0 -156
  293. package/src/server/routes/instance/httpapi/handlers/instance.ts +0 -110
  294. package/src/server/routes/instance/httpapi/handlers/mcp.ts +0 -111
  295. package/src/server/routes/instance/httpapi/handlers/permission.ts +0 -41
  296. package/src/server/routes/instance/httpapi/handlers/project-copy.ts +0 -83
  297. package/src/server/routes/instance/httpapi/handlers/project.ts +0 -63
  298. package/src/server/routes/instance/httpapi/handlers/provider.ts +0 -113
  299. package/src/server/routes/instance/httpapi/handlers/pty.ts +0 -273
  300. package/src/server/routes/instance/httpapi/handlers/question.ts +0 -54
  301. package/src/server/routes/instance/httpapi/handlers/session-errors.ts +0 -21
  302. package/src/server/routes/instance/httpapi/handlers/session.ts +0 -442
  303. package/src/server/routes/instance/httpapi/handlers/sync.ts +0 -89
  304. package/src/server/routes/instance/httpapi/handlers/tui.ts +0 -131
  305. package/src/server/routes/instance/httpapi/handlers/workspace.ts +0 -102
  306. package/src/server/routes/instance/httpapi/lifecycle.ts +0 -54
  307. package/src/server/routes/instance/httpapi/middleware/authorization.ts +0 -150
  308. package/src/server/routes/instance/httpapi/middleware/compression.ts +0 -64
  309. package/src/server/routes/instance/httpapi/middleware/cors-vary.ts +0 -29
  310. package/src/server/routes/instance/httpapi/middleware/error.ts +0 -43
  311. package/src/server/routes/instance/httpapi/middleware/fence.ts +0 -25
  312. package/src/server/routes/instance/httpapi/middleware/instance-context.ts +0 -43
  313. package/src/server/routes/instance/httpapi/middleware/proxy.ts +0 -108
  314. package/src/server/routes/instance/httpapi/middleware/schema-error.ts +0 -41
  315. package/src/server/routes/instance/httpapi/middleware/workspace-routing.ts +0 -250
  316. package/src/server/routes/instance/httpapi/public.ts +0 -537
  317. package/src/server/routes/instance/httpapi/server.ts +0 -327
  318. package/src/server/routes/instance/httpapi/websocket-tracker.ts +0 -60
  319. package/src/server/server.ts +0 -226
  320. package/src/server/shared/fence.ts +0 -60
  321. package/src/server/shared/pty-ticket.ts +0 -15
  322. package/src/server/shared/public-ui.ts +0 -12
  323. package/src/server/shared/tui-control.ts +0 -28
  324. package/src/server/shared/ui.ts +0 -108
  325. package/src/server/shared/workspace-routing.ts +0 -38
  326. package/src/server/tui-event.ts +0 -1
  327. package/src/session/compaction.ts +0 -562
  328. package/src/session/instruction.ts +0 -237
  329. package/src/session/llm/AGENTS.md +0 -90
  330. package/src/session/llm/ai-sdk.ts +0 -288
  331. package/src/session/llm/native-request.ts +0 -196
  332. package/src/session/llm/native-runtime.ts +0 -195
  333. package/src/session/llm/request.ts +0 -226
  334. package/src/session/llm.ts +0 -404
  335. package/src/session/message-error.ts +0 -14
  336. package/src/session/message-v2.ts +0 -734
  337. package/src/session/message.ts +0 -148
  338. package/src/session/overflow.ts +0 -34
  339. package/src/session/processor.ts +0 -718
  340. package/src/session/prompt/anthropic.txt +0 -96
  341. package/src/session/prompt/beast.txt +0 -147
  342. package/src/session/prompt/build-switch.txt +0 -5
  343. package/src/session/prompt/codex.txt +0 -79
  344. package/src/session/prompt/copilot-gpt-5.txt +0 -143
  345. package/src/session/prompt/default.txt +0 -89
  346. package/src/session/prompt/gemini.txt +0 -155
  347. package/src/session/prompt/gpt.txt +0 -107
  348. package/src/session/prompt/kimi.txt +0 -95
  349. package/src/session/prompt/meta.txt +0 -64
  350. package/src/session/prompt/plan-mode.txt +0 -70
  351. package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  352. package/src/session/prompt/plan.txt +0 -26
  353. package/src/session/prompt/trinity.txt +0 -97
  354. package/src/session/prompt.ts +0 -1636
  355. package/src/session/reminders.ts +0 -92
  356. package/src/session/retry.ts +0 -201
  357. package/src/session/revert.ts +0 -146
  358. package/src/session/run-state.ts +0 -151
  359. package/src/session/schema.ts +0 -26
  360. package/src/session/session.ts +0 -1018
  361. package/src/session/status.ts +0 -56
  362. package/src/session/summary.ts +0 -160
  363. package/src/session/system.ts +0 -145
  364. package/src/session/todo.ts +0 -74
  365. package/src/session/tools.ts +0 -590
  366. package/src/share/session.ts +0 -58
  367. package/src/share/share-next.ts +0 -371
  368. package/src/skill/discovery.ts +0 -140
  369. package/src/skill/index.ts +0 -354
  370. package/src/snapshot/index.ts +0 -807
  371. package/src/sql.d.ts +0 -4
  372. package/src/storage/schema.ts +0 -5
  373. package/src/storage/storage.ts +0 -327
  374. package/src/sync/README.md +0 -179
  375. package/src/sync/schema.ts +0 -11
  376. package/src/temporary.ts +0 -31
  377. package/src/tool/apply_patch.ts +0 -313
  378. package/src/tool/apply_patch.txt +0 -33
  379. package/src/tool/code-mode.ts +0 -310
  380. package/src/tool/computer.ts +0 -476
  381. package/src/tool/computer.txt +0 -25
  382. package/src/tool/edit.ts +0 -737
  383. package/src/tool/edit.txt +0 -10
  384. package/src/tool/external-directory.ts +0 -49
  385. package/src/tool/glob.ts +0 -76
  386. package/src/tool/glob.txt +0 -6
  387. package/src/tool/grep.ts +0 -115
  388. package/src/tool/grep.txt +0 -8
  389. package/src/tool/invalid.ts +0 -21
  390. package/src/tool/json-schema.ts +0 -164
  391. package/src/tool/lsp.ts +0 -113
  392. package/src/tool/lsp.txt +0 -24
  393. package/src/tool/mcp-websearch.ts +0 -96
  394. package/src/tool/memory.ts +0 -59
  395. package/src/tool/memory.txt +0 -14
  396. package/src/tool/plan-enter.txt +0 -14
  397. package/src/tool/plan-exit.txt +0 -13
  398. package/src/tool/plan.ts +0 -79
  399. package/src/tool/question.ts +0 -44
  400. package/src/tool/question.txt +0 -10
  401. package/src/tool/read.ts +0 -386
  402. package/src/tool/read.txt +0 -14
  403. package/src/tool/registry.ts +0 -460
  404. package/src/tool/schema.ts +0 -14
  405. package/src/tool/shell/id.ts +0 -19
  406. package/src/tool/shell/prompt.ts +0 -293
  407. package/src/tool/shell/shell.txt +0 -21
  408. package/src/tool/shell.ts +0 -645
  409. package/src/tool/skill.ts +0 -70
  410. package/src/tool/skill.txt +0 -5
  411. package/src/tool/task.ts +0 -360
  412. package/src/tool/task.txt +0 -19
  413. package/src/tool/todo.ts +0 -46
  414. package/src/tool/todowrite.txt +0 -44
  415. package/src/tool/tool.ts +0 -183
  416. package/src/tool/truncate.ts +0 -156
  417. package/src/tool/truncation-dir.ts +0 -4
  418. package/src/tool/webfetch.ts +0 -192
  419. package/src/tool/webfetch.txt +0 -13
  420. package/src/tool/websearch.ts +0 -143
  421. package/src/tool/websearch.txt +0 -14
  422. package/src/tool/write.ts +0 -104
  423. package/src/tool/write.txt +0 -8
  424. package/src/util/archive.ts +0 -17
  425. package/src/util/bom.ts +0 -27
  426. package/src/util/data-url.ts +0 -9
  427. package/src/util/defer.ts +0 -10
  428. package/src/util/effect-http-client.ts +0 -11
  429. package/src/util/error.ts +0 -1
  430. package/src/util/filesystem.ts +0 -251
  431. package/src/util/html.ts +0 -8
  432. package/src/util/iife.ts +0 -3
  433. package/src/util/lazy.ts +0 -20
  434. package/src/util/local-context.ts +0 -25
  435. package/src/util/locale.ts +0 -2
  436. package/src/util/media.ts +0 -26
  437. package/src/util/process.ts +0 -177
  438. package/src/util/proxy-env.ts +0 -72
  439. package/src/util/queue.ts +0 -32
  440. package/src/util/record.ts +0 -1
  441. package/src/util/repository.ts +0 -232
  442. package/src/util/rpc.ts +0 -66
  443. package/src/util/signal.ts +0 -12
  444. package/src/util/timeout.ts +0 -13
  445. package/src/util/token.ts +0 -1
  446. package/src/util/wildcard.ts +0 -59
  447. package/src/worktree/index.ts +0 -623
  448. package/tsconfig.json +0 -17
@@ -1,718 +0,0 @@
1
- import { LayerNode } from "@anymous-ai/core/effect/layer-node"
2
- import { PermissionV1 } from "@anymous-ai/core/v1/permission"
3
- import { Image } from "@/image/image"
4
- import { SessionV1 } from "@anymous-ai/core/v1/session"
5
- import { Cause, Deferred, Effect, Exit, Layer, Context, Scope, Schema } from "effect"
6
- import * as Stream from "effect/Stream"
7
- import { Agent } from "@/agent/agent"
8
- import { Config } from "@/config/config"
9
- import { Permission } from "@/permission"
10
- import { Plugin } from "@/plugin"
11
- import { Snapshot } from "@/snapshot"
12
- import { Session } from "./session"
13
- import { LLM } from "./llm"
14
- import { MessageV2 } from "./message-v2"
15
- import { isOverflow } from "./overflow"
16
- import { PartID } from "./schema"
17
- import type { SessionID } from "./schema"
18
- import { SessionRetry } from "./retry"
19
- import { SessionStatus } from "./status"
20
- import { SessionSummary } from "./summary"
21
- import type { Provider } from "@/provider/provider"
22
- import { Question } from "@/question"
23
- import { errorMessage } from "@/util/error"
24
- import { isRecord } from "@/util/record"
25
- import { EventV2Bridge } from "@/event-v2-bridge"
26
- import { Database } from "@anymous-ai/core/database/database"
27
- import { Usage, type LLMEvent } from "@anymous-ai/llm"
28
-
29
- const DOOM_LOOP_THRESHOLD = 3
30
- export type Result = "compact" | "stop" | "continue"
31
-
32
- export interface Handle {
33
- readonly message: SessionV1.Assistant
34
- readonly updateToolCall: (
35
- toolCallID: string,
36
- update: (part: SessionV1.ToolPart) => SessionV1.ToolPart,
37
- ) => Effect.Effect<SessionV1.ToolPart | undefined>
38
- readonly completeToolCall: (
39
- toolCallID: string,
40
- output: {
41
- title: string
42
- metadata: Record<string, any>
43
- output: string
44
- attachments?: SessionV1.FilePart[]
45
- },
46
- ) => Effect.Effect<void>
47
- readonly process: (streamInput: LLM.StreamInput) => Effect.Effect<Result>
48
- }
49
-
50
- type Input = {
51
- assistantMessage: SessionV1.Assistant
52
- sessionID: SessionID
53
- model: Provider.Model
54
- }
55
-
56
- export interface Interface {
57
- readonly create: (input: Input) => Effect.Effect<Handle>
58
- }
59
-
60
- type ToolCall = {
61
- partID: SessionV1.ToolPart["id"]
62
- messageID: SessionV1.ToolPart["messageID"]
63
- sessionID: SessionV1.ToolPart["sessionID"]
64
- done: Deferred.Deferred<void>
65
- }
66
-
67
- interface ProcessorContext extends Input {
68
- toolcalls: Record<string, ToolCall>
69
- shouldBreak: boolean
70
- snapshot: string | undefined
71
- blocked: boolean
72
- needsCompaction: boolean
73
- currentText: SessionV1.TextPart | undefined
74
- reasoningMap: Record<string, SessionV1.ReasoningPart>
75
- }
76
-
77
- type StreamEvent = LLMEvent
78
-
79
- export class Service extends Context.Service<Service, Interface>()("@anymous/SessionProcessor") {}
80
-
81
- const layer = Layer.effect(
82
- Service,
83
- Effect.gen(function* () {
84
- const session = yield* Session.Service
85
- const config = yield* Config.Service
86
- const snapshot = yield* Snapshot.Service
87
- const agents = yield* Agent.Service
88
- const llm = yield* LLM.Service
89
- const permission = yield* Permission.Service
90
- const plugin = yield* Plugin.Service
91
- const summary = yield* SessionSummary.Service
92
- const scope = yield* Scope.Scope
93
- const status = yield* SessionStatus.Service
94
- const image = yield* Image.Service
95
- const events = yield* EventV2Bridge.Service
96
- const database = yield* Database.Service
97
-
98
- const create = Effect.fn("SessionProcessor.create")(function* (input: Input) {
99
- // Pre-capture snapshot before the LLM stream starts. The AI SDK
100
- // may execute tools internally before emitting start-step events,
101
- // so capturing inside the event handler can be too late.
102
- const initialSnapshot = yield* snapshot.track()
103
- const ctx: ProcessorContext = {
104
- assistantMessage: input.assistantMessage,
105
- sessionID: input.sessionID,
106
- model: input.model,
107
- toolcalls: {},
108
- shouldBreak: false,
109
- snapshot: initialSnapshot,
110
- blocked: false,
111
- needsCompaction: false,
112
- currentText: undefined,
113
- reasoningMap: {},
114
- }
115
- let aborted = false
116
-
117
- const parse = (e: unknown) =>
118
- MessageV2.fromError(e, {
119
- providerID: input.model.providerID,
120
- aborted,
121
- })
122
-
123
- const settleToolCall = Effect.fn("SessionProcessor.settleToolCall")(function* (toolCallID: string) {
124
- const done = ctx.toolcalls[toolCallID]?.done
125
- delete ctx.toolcalls[toolCallID]
126
- if (done) yield* Deferred.succeed(done, undefined).pipe(Effect.ignore)
127
- })
128
-
129
- const readToolCall = Effect.fn("SessionProcessor.readToolCall")(function* (toolCallID: string) {
130
- const call = ctx.toolcalls[toolCallID]
131
- if (!call) return undefined
132
- const part = yield* session.getPart({
133
- partID: call.partID,
134
- messageID: call.messageID,
135
- sessionID: call.sessionID,
136
- })
137
- if (!part || part.type !== "tool") {
138
- delete ctx.toolcalls[toolCallID]
139
- return undefined
140
- }
141
- return { call, part }
142
- })
143
-
144
- const updateToolCall = Effect.fn("SessionProcessor.updateToolCall")(function* (
145
- toolCallID: string,
146
- update: (part: SessionV1.ToolPart) => SessionV1.ToolPart,
147
- ) {
148
- const match = yield* readToolCall(toolCallID)
149
- if (!match) return undefined
150
- const part = yield* session.updatePart(update(match.part))
151
- ctx.toolcalls[toolCallID] = {
152
- ...match.call,
153
- partID: part.id,
154
- messageID: part.messageID,
155
- sessionID: part.sessionID,
156
- }
157
- return part
158
- })
159
-
160
- const completeToolCall = Effect.fn("SessionProcessor.completeToolCall")(function* (
161
- toolCallID: string,
162
- output: {
163
- title: string
164
- metadata: Record<string, any>
165
- output: string
166
- attachments?: SessionV1.FilePart[]
167
- },
168
- ) {
169
- const match = yield* readToolCall(toolCallID)
170
- if (!match || match.part.state.status !== "running") return
171
- yield* session.updatePart({
172
- ...match.part,
173
- state: {
174
- status: "completed",
175
- input: match.part.state.input,
176
- output: output.output,
177
- metadata: output.metadata,
178
- title: output.title,
179
- time: { start: match.part.state.time.start, end: Date.now() },
180
- attachments: output.attachments,
181
- },
182
- })
183
- yield* settleToolCall(toolCallID)
184
- })
185
-
186
- const failToolCall = Effect.fn("SessionProcessor.failToolCall")(function* (toolCallID: string, error: unknown) {
187
- const match = yield* readToolCall(toolCallID)
188
- if (!match || match.part.state.status !== "running") return false
189
- yield* session.updatePart({
190
- ...match.part,
191
- state: {
192
- status: "error",
193
- input: match.part.state.input,
194
- error: errorMessage(error),
195
- // Keep metadata streamed while running so failures retain progress detail (e.g. execute's child calls).
196
- metadata: match.part.state.metadata,
197
- time: { start: match.part.state.time.start, end: Date.now() },
198
- },
199
- })
200
- if (error instanceof PermissionV1.RejectedError || error instanceof Question.RejectedError) {
201
- ctx.blocked = ctx.shouldBreak
202
- }
203
- yield* settleToolCall(toolCallID)
204
- return true
205
- })
206
-
207
- const finishReasoning = Effect.fn("SessionProcessor.finishReasoning")(function* (reasoningID: string) {
208
- if (!(reasoningID in ctx.reasoningMap)) return
209
- // oxlint-disable-next-line no-self-assign -- reactivity trigger
210
- ctx.reasoningMap[reasoningID].text = ctx.reasoningMap[reasoningID].text
211
- ctx.reasoningMap[reasoningID].time = { ...ctx.reasoningMap[reasoningID].time, end: Date.now() }
212
- yield* session.updatePart(ctx.reasoningMap[reasoningID])
213
- delete ctx.reasoningMap[reasoningID]
214
- })
215
-
216
- const ensureToolCall = Effect.fn("SessionProcessor.ensureToolCall")(function* (input: {
217
- id: string
218
- name: string
219
- providerExecuted?: boolean
220
- }) {
221
- const existing = yield* readToolCall(input.id)
222
- if (existing) {
223
- if (!input.providerExecuted || existing.part.metadata?.providerExecuted) return existing
224
- const part = yield* session.updatePart({
225
- ...existing.part,
226
- metadata: { ...existing.part.metadata, providerExecuted: true },
227
- })
228
- ctx.toolcalls[input.id] = {
229
- ...existing.call,
230
- partID: part.id,
231
- messageID: part.messageID,
232
- sessionID: part.sessionID,
233
- }
234
- return { call: ctx.toolcalls[input.id], part }
235
- }
236
- const part = yield* session.updatePart({
237
- id: PartID.ascending(),
238
- messageID: ctx.assistantMessage.id,
239
- sessionID: ctx.assistantMessage.sessionID,
240
- type: "tool",
241
- tool: input.name,
242
- callID: input.id,
243
- state: { status: "pending", input: {}, raw: "" },
244
- metadata: input.providerExecuted ? { providerExecuted: true } : undefined,
245
- } satisfies SessionV1.ToolPart)
246
- ctx.toolcalls[input.id] = {
247
- done: yield* Deferred.make<void>(),
248
- partID: part.id,
249
- messageID: part.messageID,
250
- sessionID: part.sessionID,
251
- }
252
- return { call: ctx.toolcalls[input.id], part }
253
- })
254
-
255
- const isFilePart = (value: unknown): value is SessionV1.FilePart => Schema.is(SessionV1.FilePart)(value)
256
-
257
- const toolResultOutput = (
258
- value: Extract<StreamEvent, { type: "tool-result" }>,
259
- ): { title: string; metadata: Record<string, any>; output: string; attachments?: SessionV1.FilePart[] } => {
260
- if (isRecord(value.result.value) && typeof value.result.value.output === "string") {
261
- return {
262
- title: typeof value.result.value.title === "string" ? value.result.value.title : value.name,
263
- metadata: isRecord(value.result.value.metadata) ? value.result.value.metadata : {},
264
- output: value.result.value.output,
265
- attachments: Array.isArray(value.result.value.attachments)
266
- ? value.result.value.attachments.filter(isFilePart)
267
- : undefined,
268
- }
269
- }
270
- return {
271
- title: value.name,
272
- metadata: value.result.type === "json" && isRecord(value.result.value) ? value.result.value : {},
273
- output:
274
- typeof value.result.value === "string" ? value.result.value : (JSON.stringify(value.result.value) ?? ""),
275
- }
276
- }
277
-
278
- const handleEvent = Effect.fnUntraced(function* (value: StreamEvent) {
279
- switch (value.type) {
280
- case "reasoning-start":
281
- if (value.id in ctx.reasoningMap) return
282
- ctx.reasoningMap[value.id] = {
283
- id: PartID.ascending(),
284
- messageID: ctx.assistantMessage.id,
285
- sessionID: ctx.assistantMessage.sessionID,
286
- type: "reasoning",
287
- text: "",
288
- time: { start: Date.now() },
289
- metadata: value.providerMetadata,
290
- }
291
- yield* session.updatePart(ctx.reasoningMap[value.id])
292
- return
293
-
294
- case "reasoning-delta":
295
- // Match dev: silently drop orphan deltas (no preceding reasoning-start).
296
- if (!(value.id in ctx.reasoningMap)) return
297
- ctx.reasoningMap[value.id].text += value.text
298
- if (value.providerMetadata) ctx.reasoningMap[value.id].metadata = value.providerMetadata
299
- yield* session.updatePartDelta({
300
- sessionID: ctx.reasoningMap[value.id].sessionID,
301
- messageID: ctx.reasoningMap[value.id].messageID,
302
- partID: ctx.reasoningMap[value.id].id,
303
- field: "text",
304
- delta: value.text,
305
- })
306
- return
307
-
308
- case "reasoning-end":
309
- if (value.providerMetadata && value.id in ctx.reasoningMap) {
310
- ctx.reasoningMap[value.id].metadata = value.providerMetadata
311
- }
312
- yield* finishReasoning(value.id)
313
- return
314
-
315
- case "tool-input-start":
316
- if (ctx.assistantMessage.summary) {
317
- throw new Error(`Tool call not allowed while generating summary: ${value.name}`)
318
- }
319
- yield* ensureToolCall(value)
320
- return
321
-
322
- case "tool-input-delta":
323
- yield* ensureToolCall(value)
324
- return
325
-
326
- case "tool-input-end": {
327
- yield* ensureToolCall(value)
328
- return
329
- }
330
-
331
- case "tool-call": {
332
- if (ctx.assistantMessage.summary) {
333
- throw new Error(`Tool call not allowed while generating summary: ${value.name}`)
334
- }
335
- yield* ensureToolCall(value)
336
- const input = isRecord(value.input) ? value.input : { value: value.input }
337
- yield* updateToolCall(value.id, (match) => ({
338
- ...match,
339
- tool: value.name,
340
- state:
341
- match.state.status === "running"
342
- ? { ...match.state, input }
343
- : {
344
- status: "running",
345
- input,
346
- time: { start: Date.now() },
347
- },
348
- metadata: match.metadata?.providerExecuted
349
- ? { ...value.providerMetadata, providerExecuted: true }
350
- : value.providerMetadata,
351
- }))
352
-
353
- const parts = yield* MessageV2.parts(ctx.assistantMessage.id).pipe(
354
- Effect.provideService(Database.Service, database),
355
- )
356
- const recentParts = parts.slice(-DOOM_LOOP_THRESHOLD)
357
-
358
- if (
359
- recentParts.length !== DOOM_LOOP_THRESHOLD ||
360
- !recentParts.every(
361
- (part) =>
362
- part.type === "tool" &&
363
- part.tool === value.name &&
364
- part.state.status !== "pending" &&
365
- JSON.stringify(part.state.input) === JSON.stringify(input),
366
- )
367
- ) {
368
- return
369
- }
370
-
371
- const agent = yield* agents.get(ctx.assistantMessage.agent)
372
- yield* permission.ask({
373
- permission: "doom_loop",
374
- patterns: [value.name],
375
- sessionID: ctx.assistantMessage.sessionID,
376
- metadata: { tool: value.name, input },
377
- always: [value.name],
378
- ruleset: agent.permission,
379
- })
380
- return
381
- }
382
-
383
- case "tool-result": {
384
- const toolCall = yield* readToolCall(value.id)
385
- if (!toolCall && value.result.type === "error") return
386
- if (value.result.type === "error") {
387
- yield* failToolCall(value.id, value.result.value)
388
- return
389
- }
390
- const rawOutput = toolResultOutput(value)
391
- const normalized = yield* Effect.forEach(rawOutput.attachments ?? [], (attachment) =>
392
- attachment.mime.startsWith("image/")
393
- ? image.normalize(attachment).pipe(
394
- Effect.catchIf(
395
- (error) => error instanceof Image.ResizerUnavailableError,
396
- () => Effect.succeed(attachment),
397
- ),
398
- Effect.exit,
399
- )
400
- : Effect.succeed(Exit.succeed<SessionV1.FilePart>(attachment)),
401
- )
402
- const omitted = normalized.filter(Exit.isFailure).length
403
- const attachments = normalized.filter(Exit.isSuccess).map((item) => item.value)
404
- const output = {
405
- ...rawOutput,
406
- output:
407
- omitted === 0
408
- ? rawOutput.output
409
- : `${rawOutput.output}\n\n[${omitted} image${omitted === 1 ? "" : "s"} omitted: could not be resized below the image size limit.]`,
410
- attachments: attachments.length ? attachments : undefined,
411
- }
412
- yield* completeToolCall(value.id, output)
413
- return
414
- }
415
-
416
- case "tool-error": {
417
- yield* failToolCall(value.id, value.error ?? new Error(value.message))
418
- return
419
- }
420
-
421
- case "provider-error":
422
- throw new Error(value.message)
423
-
424
- case "step-start":
425
- if (!ctx.snapshot) ctx.snapshot = yield* snapshot.track()
426
- yield* session.updatePart({
427
- id: PartID.ascending(),
428
- messageID: ctx.assistantMessage.id,
429
- sessionID: ctx.sessionID,
430
- snapshot: ctx.snapshot,
431
- type: "step-start",
432
- })
433
- return
434
-
435
- case "step-finish": {
436
- const completedSnapshot = yield* snapshot.track()
437
- yield* Effect.forEach(Object.keys(ctx.reasoningMap), finishReasoning)
438
- const usage = Session.getUsage({
439
- model: ctx.model,
440
- usage: value.usage ?? new Usage({}),
441
- metadata: value.providerMetadata,
442
- })
443
- ctx.assistantMessage.finish = value.reason
444
- ctx.assistantMessage.cost += usage.cost
445
- ctx.assistantMessage.tokens = usage.tokens
446
- yield* session.updatePart({
447
- id: PartID.ascending(),
448
- reason: value.reason,
449
- snapshot: completedSnapshot,
450
- messageID: ctx.assistantMessage.id,
451
- sessionID: ctx.assistantMessage.sessionID,
452
- type: "step-finish",
453
- tokens: usage.tokens,
454
- cost: usage.cost,
455
- })
456
- yield* session.updateMessage(ctx.assistantMessage)
457
- if (ctx.snapshot) {
458
- const patch = yield* snapshot.patch(ctx.snapshot)
459
- if (patch.files.length) {
460
- yield* session.updatePart({
461
- id: PartID.ascending(),
462
- messageID: ctx.assistantMessage.id,
463
- sessionID: ctx.sessionID,
464
- type: "patch",
465
- hash: patch.hash,
466
- files: patch.files,
467
- })
468
- }
469
- ctx.snapshot = undefined
470
- }
471
- yield* summary
472
- .summarize({
473
- sessionID: ctx.sessionID,
474
- messageID: ctx.assistantMessage.parentID,
475
- })
476
- .pipe(Effect.ignore, Effect.forkIn(scope))
477
- if (
478
- !ctx.assistantMessage.summary &&
479
- isOverflow({ cfg: yield* config.get(), tokens: usage.tokens, model: ctx.model })
480
- ) {
481
- ctx.needsCompaction = true
482
- }
483
- return
484
- }
485
-
486
- case "text-start":
487
- ctx.currentText = {
488
- id: PartID.ascending(),
489
- messageID: ctx.assistantMessage.id,
490
- sessionID: ctx.assistantMessage.sessionID,
491
- type: "text",
492
- text: "",
493
- time: { start: Date.now() },
494
- metadata: value.providerMetadata,
495
- }
496
- yield* session.updatePart(ctx.currentText)
497
- return
498
-
499
- case "text-delta":
500
- if (!ctx.currentText) return
501
- ctx.currentText.text += value.text
502
- if (value.providerMetadata) ctx.currentText.metadata = value.providerMetadata
503
- yield* session.updatePartDelta({
504
- sessionID: ctx.currentText.sessionID,
505
- messageID: ctx.currentText.messageID,
506
- partID: ctx.currentText.id,
507
- field: "text",
508
- delta: value.text,
509
- })
510
- return
511
-
512
- case "text-end":
513
- if (!ctx.currentText) return
514
- // oxlint-disable-next-line no-self-assign -- reactivity trigger
515
- ctx.currentText.text = ctx.currentText.text
516
- ctx.currentText.text = (yield* plugin.trigger(
517
- "experimental.text.complete",
518
- {
519
- sessionID: ctx.sessionID,
520
- messageID: ctx.assistantMessage.id,
521
- partID: ctx.currentText.id,
522
- },
523
- { text: ctx.currentText.text },
524
- )).text
525
- {
526
- const end = Date.now()
527
- ctx.currentText.time = { start: ctx.currentText.time?.start ?? end, end }
528
- }
529
- if (value.providerMetadata) ctx.currentText.metadata = value.providerMetadata
530
- yield* session.updatePart(ctx.currentText)
531
- ctx.currentText = undefined
532
- return
533
-
534
- case "finish":
535
- return
536
- }
537
- })
538
-
539
- const cleanup = Effect.fn("SessionProcessor.cleanup")(function* () {
540
- if (ctx.snapshot) {
541
- const patch = yield* snapshot.patch(ctx.snapshot)
542
- if (patch.files.length) {
543
- yield* session.updatePart({
544
- id: PartID.ascending(),
545
- messageID: ctx.assistantMessage.id,
546
- sessionID: ctx.sessionID,
547
- type: "patch",
548
- hash: patch.hash,
549
- files: patch.files,
550
- })
551
- }
552
- ctx.snapshot = undefined
553
- }
554
-
555
- if (ctx.currentText) {
556
- const end = Date.now()
557
- ctx.currentText.time = { start: ctx.currentText.time?.start ?? end, end }
558
- yield* session.updatePart(ctx.currentText)
559
- ctx.currentText = undefined
560
- }
561
-
562
- for (const part of Object.values(ctx.reasoningMap)) {
563
- const end = Date.now()
564
- yield* session.updatePart({
565
- ...part,
566
- time: { start: part.time.start ?? end, end },
567
- })
568
- }
569
- ctx.reasoningMap = {}
570
-
571
- yield* Effect.forEach(
572
- Object.values(ctx.toolcalls),
573
- (call) => Deferred.await(call.done).pipe(Effect.timeout("250 millis"), Effect.ignore),
574
- { concurrency: "unbounded" },
575
- )
576
-
577
- for (const toolCallID of Object.keys(ctx.toolcalls)) {
578
- const match = yield* readToolCall(toolCallID)
579
- if (!match) continue
580
- const part = match.part
581
- const end = Date.now()
582
- const metadata = "metadata" in part.state && isRecord(part.state.metadata) ? part.state.metadata : {}
583
- yield* session.updatePart({
584
- ...part,
585
- state: {
586
- ...part.state,
587
- status: "error",
588
- error: "Tool execution aborted",
589
- metadata: { ...metadata, interrupted: true },
590
- time: { start: "time" in part.state ? part.state.time.start : end, end },
591
- },
592
- })
593
- }
594
- ctx.toolcalls = {}
595
- ctx.assistantMessage.time.completed = Date.now()
596
- yield* session.updateMessage(ctx.assistantMessage)
597
- })
598
-
599
- const halt = Effect.fn("SessionProcessor.halt")(function* (e: unknown) {
600
- yield* Effect.logError("process", {
601
- "session.id": input.sessionID,
602
- messageID: input.assistantMessage.id,
603
- error: errorMessage(e),
604
- stack: e instanceof Error ? e.stack : undefined,
605
- })
606
- const error = parse(e)
607
- if (SessionV1.ContextOverflowError.isInstance(error)) {
608
- if ((yield* config.get()).compaction?.auto === false && !ctx.assistantMessage.summary) {
609
- ctx.assistantMessage.error = error
610
- ctx.assistantMessage.finish = "error"
611
- yield* events.publish(Session.Event.Error, { sessionID: ctx.sessionID, error })
612
- yield* status.set(ctx.sessionID, { type: "idle" })
613
- return
614
- }
615
- ctx.needsCompaction = true
616
- yield* events.publish(Session.Event.Error, { sessionID: ctx.sessionID, error })
617
- return
618
- }
619
- ctx.assistantMessage.error = error
620
- yield* events.publish(Session.Event.Error, {
621
- sessionID: ctx.assistantMessage.sessionID,
622
- error: ctx.assistantMessage.error,
623
- })
624
- yield* status.set(ctx.sessionID, { type: "idle" })
625
- })
626
-
627
- const process = Effect.fn("SessionProcessor.process")(function* (streamInput: LLM.StreamInput) {
628
- yield* Effect.logInfo("process", {
629
- "session.id": input.sessionID,
630
- messageID: input.assistantMessage.id,
631
- })
632
- ctx.needsCompaction = false
633
- ctx.shouldBreak = (yield* config.get()).experimental?.continue_loop_on_deny !== true
634
-
635
- return yield* Effect.gen(function* () {
636
- yield* Effect.gen(function* () {
637
- ctx.currentText = undefined
638
- ctx.reasoningMap = {}
639
- yield* status.set(ctx.sessionID, { type: "busy" })
640
- const stream = llm.stream(streamInput)
641
-
642
- yield* stream.pipe(
643
- Stream.tap((event) => handleEvent(event)),
644
- Stream.takeUntil(() => ctx.needsCompaction),
645
- Stream.runDrain,
646
- )
647
- }).pipe(
648
- Effect.onInterrupt(() =>
649
- Effect.gen(function* () {
650
- aborted = true
651
- if (!ctx.assistantMessage.error) {
652
- yield* halt(new DOMException("Aborted", "AbortError"))
653
- }
654
- }),
655
- ),
656
- Effect.catchCauseIf(
657
- (cause) => !Cause.hasInterruptsOnly(cause),
658
- (cause) => Effect.fail(Cause.squash(cause)),
659
- ),
660
- Effect.retry(
661
- SessionRetry.policy({
662
- provider: input.model.providerID,
663
- parse,
664
- set: (info) => {
665
- return status.set(ctx.sessionID, {
666
- type: "retry",
667
- attempt: info.attempt,
668
- message: info.message,
669
- action: info.action,
670
- next: info.next,
671
- })
672
- },
673
- }),
674
- ),
675
- Effect.catch(halt),
676
- Effect.ensuring(cleanup()),
677
- )
678
-
679
- if (ctx.needsCompaction) return "compact"
680
- if (ctx.blocked || ctx.assistantMessage.error) return "stop"
681
- return "continue"
682
- })
683
- })
684
-
685
- return {
686
- get message() {
687
- return ctx.assistantMessage
688
- },
689
- updateToolCall,
690
- completeToolCall,
691
- process,
692
- } satisfies Handle
693
- })
694
-
695
- return Service.of({ create })
696
- }),
697
- )
698
-
699
- export const node = LayerNode.make({
700
- service: Service,
701
- layer: layer,
702
- deps: [
703
- Session.node,
704
- Config.node,
705
- Snapshot.node,
706
- Agent.node,
707
- LLM.node,
708
- Permission.node,
709
- Plugin.node,
710
- SessionSummary.node,
711
- SessionStatus.node,
712
- Image.node,
713
- EventV2Bridge.node,
714
- Database.node,
715
- ],
716
- })
717
-
718
- export * as SessionProcessor from "./processor"