@armadra/agent 0.4.0 → 0.5.0

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 (422) hide show
  1. package/CHANGELOG.md +174 -1
  2. package/README.md +201 -82
  3. package/THIRD_PARTY_NOTICES.md +34 -0
  4. package/dist/acp.d.ts +18 -0
  5. package/dist/acp.js +19 -0
  6. package/dist/agent/limits.d.ts +38 -0
  7. package/dist/agent/limits.js +127 -0
  8. package/dist/agent/loop-guard.d.ts +38 -0
  9. package/dist/agent/loop-guard.js +95 -0
  10. package/dist/agent/loop.d.ts +4 -0
  11. package/dist/agent/loop.js +7 -0
  12. package/dist/agent/prompt-rules.d.ts +12 -0
  13. package/dist/agent/prompt-rules.js +18 -0
  14. package/dist/agent/reminders.d.ts +59 -0
  15. package/dist/agent/reminders.js +327 -0
  16. package/dist/agent/session-cache.d.ts +5 -0
  17. package/dist/agent/session-cache.js +17 -1
  18. package/dist/agent/session-classifier.d.ts +1 -1
  19. package/dist/agent/session-classifier.js +3 -1
  20. package/dist/agent/session-compaction.d.ts +35 -6
  21. package/dist/agent/session-compaction.js +157 -31
  22. package/dist/agent/session-core.d.ts +27 -1
  23. package/dist/agent/session-extensions.d.ts +61 -0
  24. package/dist/agent/session-extensions.js +129 -0
  25. package/dist/agent/session-images.d.ts +23 -0
  26. package/dist/agent/session-images.js +97 -0
  27. package/dist/agent/session-plan.d.ts +21 -0
  28. package/dist/agent/session-plan.js +524 -0
  29. package/dist/agent/session-rewind.d.ts +81 -0
  30. package/dist/agent/session-rewind.js +354 -0
  31. package/dist/agent/session-run.d.ts +28 -1
  32. package/dist/agent/session-run.js +157 -6
  33. package/dist/agent/session-settings.d.ts +49 -0
  34. package/dist/agent/session-settings.js +95 -0
  35. package/dist/agent/session-subagent.d.ts +36 -24
  36. package/dist/agent/session-subagent.js +259 -129
  37. package/dist/agent/session-sync.d.ts +10 -3
  38. package/dist/agent/session-sync.js +37 -8
  39. package/dist/agent/session-telemetry.d.ts +39 -0
  40. package/dist/agent/session-telemetry.js +231 -0
  41. package/dist/agent/session-tools.js +40 -1
  42. package/dist/agent/session.d.ts +30 -29
  43. package/dist/agent/session.js +79 -123
  44. package/dist/agent/subagent-registry.d.ts +91 -0
  45. package/dist/agent/subagent-registry.js +494 -0
  46. package/dist/agent/system-prompt.d.ts +6 -3
  47. package/dist/agent/system-prompt.js +7 -2
  48. package/dist/agent/tool-runner.d.ts +8 -1
  49. package/dist/agent/tool-runner.js +57 -4
  50. package/dist/agent/types-w5.d.ts +192 -0
  51. package/dist/agent/types-w5.js +10 -0
  52. package/dist/agent/types.d.ts +47 -4
  53. package/dist/agent/types.js +2 -0
  54. package/dist/agent/worktree.d.ts +36 -0
  55. package/dist/agent/worktree.js +86 -0
  56. package/dist/agents/builtin.d.ts +14 -0
  57. package/dist/agents/builtin.js +39 -0
  58. package/dist/agents/catalog.d.ts +43 -0
  59. package/dist/agents/catalog.js +82 -0
  60. package/dist/agents/discover.d.ts +35 -0
  61. package/dist/agents/discover.js +83 -0
  62. package/dist/agents/external.d.ts +82 -0
  63. package/dist/agents/external.js +326 -0
  64. package/dist/agents/parse.d.ts +18 -0
  65. package/dist/agents/parse.js +116 -0
  66. package/dist/agents/result.d.ts +32 -0
  67. package/dist/agents/result.js +67 -0
  68. package/dist/agents/task-control.d.ts +17 -0
  69. package/dist/agents/task-control.js +17 -0
  70. package/dist/agents/task-record.d.ts +78 -0
  71. package/dist/agents/task-record.js +141 -0
  72. package/dist/agents/types.d.ts +46 -0
  73. package/dist/agents/types.js +8 -0
  74. package/dist/ai/apis/anthropic-compat.d.ts +36 -0
  75. package/dist/ai/apis/anthropic-compat.js +92 -0
  76. package/dist/ai/apis/anthropic-request.d.ts +7 -6
  77. package/dist/ai/apis/anthropic-request.js +10 -28
  78. package/dist/ai/apis/cache-params.d.ts +11 -2
  79. package/dist/ai/apis/cache-params.js +25 -6
  80. package/dist/ai/apis/openai-compat.d.ts +4 -1
  81. package/dist/ai/apis/openai-compat.js +8 -1
  82. package/dist/ai/image-limits.d.ts +45 -0
  83. package/dist/ai/image-limits.js +68 -0
  84. package/dist/ai/providers/builtin.d.ts +18 -6
  85. package/dist/ai/providers/builtin.js +135 -6
  86. package/dist/ai/providers/catalog-data.js +17 -13
  87. package/dist/ai/providers/catalog.d.ts +60 -7
  88. package/dist/ai/providers/catalog.js +197 -38
  89. package/dist/ai/providers/channels.d.ts +33 -3
  90. package/dist/ai/providers/channels.js +108 -7
  91. package/dist/ai/providers/enrich.d.ts +6 -3
  92. package/dist/ai/providers/enrich.js +19 -4
  93. package/dist/ai/providers/models-dev-cache.d.ts +28 -24
  94. package/dist/ai/providers/models-dev-cache.js +92 -78
  95. package/dist/ai/providers/models-dev-data.d.ts +7 -0
  96. package/dist/ai/providers/models-dev-data.js +32 -0
  97. package/dist/ai/providers/models-dev-snapshot.d.ts +50 -0
  98. package/dist/ai/providers/models-dev-snapshot.js +137 -0
  99. package/dist/ai/providers/models-dev.d.ts +51 -10
  100. package/dist/ai/providers/models-dev.js +132 -39
  101. package/dist/ai/providers/registry.d.ts +20 -10
  102. package/dist/ai/providers/registry.js +82 -43
  103. package/dist/ai/types.d.ts +28 -2
  104. package/dist/ai/types.js +5 -0
  105. package/dist/bundle/ama.cjs +36203 -20499
  106. package/dist/checkpoints/backend.d.ts +61 -0
  107. package/dist/checkpoints/backend.js +135 -0
  108. package/dist/checkpoints/blobs.d.ts +60 -0
  109. package/dist/checkpoints/blobs.js +203 -0
  110. package/dist/checkpoints/gc.d.ts +47 -0
  111. package/dist/checkpoints/gc.js +144 -0
  112. package/dist/checkpoints/git-head.d.ts +15 -0
  113. package/dist/checkpoints/git-head.js +89 -0
  114. package/dist/checkpoints/index.d.ts +17 -0
  115. package/dist/checkpoints/index.js +17 -0
  116. package/dist/checkpoints/replay.d.ts +48 -0
  117. package/dist/checkpoints/replay.js +154 -0
  118. package/dist/checkpoints/restore.d.ts +86 -0
  119. package/dist/checkpoints/restore.js +263 -0
  120. package/dist/checkpoints/settings.d.ts +14 -0
  121. package/dist/checkpoints/settings.js +23 -0
  122. package/dist/checkpoints/shadow-git.d.ts +108 -0
  123. package/dist/checkpoints/shadow-git.js +491 -0
  124. package/dist/checkpoints/shadow-restore.d.ts +25 -0
  125. package/dist/checkpoints/shadow-restore.js +128 -0
  126. package/dist/checkpoints/tracker.d.ts +64 -0
  127. package/dist/checkpoints/tracker.js +192 -0
  128. package/dist/checkpoints/types.d.ts +99 -0
  129. package/dist/checkpoints/types.js +12 -0
  130. package/dist/cli/args.d.ts +8 -4
  131. package/dist/cli/args.js +17 -97
  132. package/dist/cli/bootstrap.js +13 -1
  133. package/dist/cli/codemode-notice.d.ts +3 -2
  134. package/dist/cli/codemode-notice.js +3 -2
  135. package/dist/cli/compose-agents.d.ts +27 -0
  136. package/dist/cli/compose-agents.js +111 -0
  137. package/dist/cli/compose-extensions.d.ts +29 -0
  138. package/dist/cli/compose-extensions.js +44 -0
  139. package/dist/cli/compose-session.d.ts +3 -0
  140. package/dist/cli/compose-session.js +47 -4
  141. package/dist/cli/compose.d.ts +3 -0
  142. package/dist/cli/compose.js +33 -6
  143. package/dist/cli/deps.d.ts +6 -0
  144. package/dist/cli/exit-codes.d.ts +10 -0
  145. package/dist/cli/exit-codes.js +12 -0
  146. package/dist/cli/help-text.d.ts +4 -0
  147. package/dist/cli/help-text.js +102 -0
  148. package/dist/cli/startup-screen.js +5 -3
  149. package/dist/cli/startup-steps.js +7 -1
  150. package/dist/cli/subcommands/config.d.ts +4 -1
  151. package/dist/cli/subcommands/config.js +17 -6
  152. package/dist/cli/subcommands/doctor.js +21 -0
  153. package/dist/cli/subcommands/models-discover.js +5 -6
  154. package/dist/cli/subcommands/models.d.ts +2 -0
  155. package/dist/cli/subcommands/models.js +33 -14
  156. package/dist/cli/subcommands/providers.js +5 -6
  157. package/dist/cli/subcommands/sessions.d.ts +3 -1
  158. package/dist/cli/subcommands/sessions.js +36 -2
  159. package/dist/codemode/capability.d.ts +24 -7
  160. package/dist/codemode/capability.js +38 -10
  161. package/dist/codemode/host-side.d.ts +14 -0
  162. package/dist/codemode/host-side.js +24 -1
  163. package/dist/codemode/tool.d.ts +1 -1
  164. package/dist/codemode/tool.js +6 -4
  165. package/dist/compaction/breaker.d.ts +25 -9
  166. package/dist/compaction/breaker.js +47 -17
  167. package/dist/compaction/estimate.d.ts +11 -3
  168. package/dist/compaction/estimate.js +64 -22
  169. package/dist/compaction/image-budget.d.ts +45 -0
  170. package/dist/compaction/image-budget.js +115 -0
  171. package/dist/compaction/post-compact.d.ts +38 -0
  172. package/dist/compaction/post-compact.js +152 -0
  173. package/dist/compaction/protect.d.ts +27 -0
  174. package/dist/compaction/protect.js +56 -0
  175. package/dist/compaction/prune-tier.d.ts +58 -12
  176. package/dist/compaction/prune-tier.js +120 -54
  177. package/dist/compaction/summarize-tier.d.ts +23 -4
  178. package/dist/compaction/summarize-tier.js +100 -29
  179. package/dist/config/checker.d.ts +28 -0
  180. package/dist/config/checker.js +97 -0
  181. package/dist/config/json-schema.js +63 -2
  182. package/dist/config/key-docs.js +72 -3
  183. package/dist/config/merge.d.ts +5 -3
  184. package/dist/config/merge.js +81 -7
  185. package/dist/config/profile.d.ts +2 -0
  186. package/dist/config/profile.js +2 -0
  187. package/dist/config/schema-w5.d.ts +18 -0
  188. package/dist/config/schema-w5.js +109 -0
  189. package/dist/config/schema.d.ts +5 -9
  190. package/dist/config/schema.js +68 -114
  191. package/dist/config/types-w5.d.ts +118 -0
  192. package/dist/config/types-w5.js +20 -0
  193. package/dist/config/types.d.ts +50 -1
  194. package/dist/config/types.js +12 -0
  195. package/dist/drivers/acp/client.d.ts +57 -0
  196. package/dist/drivers/acp/client.js +160 -0
  197. package/dist/drivers/acp/driver.d.ts +31 -0
  198. package/dist/drivers/acp/driver.js +274 -0
  199. package/dist/drivers/acp/testing/fake-agent-main.d.ts +5 -0
  200. package/dist/drivers/acp/testing/fake-agent-main.js +7 -0
  201. package/dist/drivers/acp/testing/fake-agent.d.ts +27 -0
  202. package/dist/drivers/acp/testing/fake-agent.js +211 -0
  203. package/dist/drivers/acp/types.d.ts +285 -0
  204. package/dist/drivers/acp/types.js +36 -0
  205. package/dist/drivers/agents.d.ts +58 -0
  206. package/dist/drivers/agents.js +142 -0
  207. package/dist/drivers/base.d.ts +35 -0
  208. package/dist/drivers/base.js +59 -0
  209. package/dist/drivers/catalog.d.ts +46 -0
  210. package/dist/drivers/catalog.js +167 -0
  211. package/dist/drivers/env.d.ts +20 -0
  212. package/dist/drivers/env.js +46 -0
  213. package/dist/drivers/host-runners.d.ts +18 -0
  214. package/dist/drivers/host-runners.js +45 -0
  215. package/dist/drivers/jsonrpc.d.ts +58 -0
  216. package/dist/drivers/jsonrpc.js +180 -0
  217. package/dist/drivers/native/claude-normalize.d.ts +46 -0
  218. package/dist/drivers/native/claude-normalize.js +106 -0
  219. package/dist/drivers/native/claude-stream.d.ts +29 -0
  220. package/dist/drivers/native/claude-stream.js +456 -0
  221. package/dist/drivers/native/codex-app-server.d.ts +26 -0
  222. package/dist/drivers/native/codex-app-server.js +407 -0
  223. package/dist/drivers/native/codex-normalize.d.ts +38 -0
  224. package/dist/drivers/native/codex-normalize.js +124 -0
  225. package/dist/drivers/native/oneshot.d.ts +28 -0
  226. package/dist/drivers/native/oneshot.js +312 -0
  227. package/dist/drivers/permissions.d.ts +40 -0
  228. package/dist/drivers/permissions.js +92 -0
  229. package/dist/drivers/pids.d.ts +32 -0
  230. package/dist/drivers/pids.js +93 -0
  231. package/dist/drivers/pool.d.ts +28 -0
  232. package/dist/drivers/pool.js +96 -0
  233. package/dist/drivers/probe.d.ts +47 -0
  234. package/dist/drivers/probe.js +172 -0
  235. package/dist/drivers/process.d.ts +48 -0
  236. package/dist/drivers/process.js +100 -0
  237. package/dist/drivers/runner.d.ts +61 -0
  238. package/dist/drivers/runner.js +388 -0
  239. package/dist/drivers/store.d.ts +49 -0
  240. package/dist/drivers/store.js +91 -0
  241. package/dist/drivers/turn.d.ts +41 -0
  242. package/dist/drivers/turn.js +99 -0
  243. package/dist/drivers/types.d.ts +122 -0
  244. package/dist/drivers/types.js +11 -0
  245. package/dist/git/info.d.ts +75 -0
  246. package/dist/git/info.js +191 -0
  247. package/dist/hooks/protocol.js +6 -1
  248. package/dist/hooks/types.d.ts +10 -1
  249. package/dist/hooks/types.js +2 -0
  250. package/dist/host/api-impl.d.ts +7 -0
  251. package/dist/host/api-impl.js +15 -0
  252. package/dist/host/types.d.ts +24 -2
  253. package/dist/host/types.js +4 -0
  254. package/dist/index.d.ts +3 -0
  255. package/dist/index.js +1 -0
  256. package/dist/modes/acp/acp-events.d.ts +46 -0
  257. package/dist/modes/acp/acp-events.js +233 -0
  258. package/dist/modes/acp/acp-mode.d.ts +17 -0
  259. package/dist/modes/acp/acp-mode.js +47 -0
  260. package/dist/modes/acp/acp-server.d.ts +79 -0
  261. package/dist/modes/acp/acp-server.js +315 -0
  262. package/dist/modes/commands-core.d.ts +7 -1
  263. package/dist/modes/commands-core.js +55 -0
  264. package/dist/modes/image-input.d.ts +12 -4
  265. package/dist/modes/image-input.js +22 -5
  266. package/dist/modes/interactive/agent-panels.d.ts +14 -0
  267. package/dist/modes/interactive/agent-panels.js +103 -0
  268. package/dist/modes/interactive/agent-ui.d.ts +73 -0
  269. package/dist/modes/interactive/agent-ui.js +234 -0
  270. package/dist/modes/interactive/approval-dialog.d.ts +21 -4
  271. package/dist/modes/interactive/approval-dialog.js +98 -20
  272. package/dist/modes/interactive/approval-merge.d.ts +41 -0
  273. package/dist/modes/interactive/approval-merge.js +89 -0
  274. package/dist/modes/interactive/clipboard-paste.d.ts +18 -0
  275. package/dist/modes/interactive/clipboard-paste.js +28 -0
  276. package/dist/modes/interactive/commands.d.ts +9 -1
  277. package/dist/modes/interactive/commands.js +19 -0
  278. package/dist/modes/interactive/double-esc.d.ts +20 -0
  279. package/dist/modes/interactive/double-esc.js +34 -0
  280. package/dist/modes/interactive/event-notices.d.ts +32 -0
  281. package/dist/modes/interactive/event-notices.js +79 -0
  282. package/dist/modes/interactive/external-editor.d.ts +16 -0
  283. package/dist/modes/interactive/external-editor.js +39 -0
  284. package/dist/modes/interactive/interactive-mode.d.ts +14 -1
  285. package/dist/modes/interactive/interactive-mode.js +134 -136
  286. package/dist/modes/interactive/key-dispatch.d.ts +16 -2
  287. package/dist/modes/interactive/key-dispatch.js +49 -1
  288. package/dist/modes/interactive/line/line-mode.d.ts +2 -1
  289. package/dist/modes/interactive/line/line-mode.js +22 -5
  290. package/dist/modes/interactive/line/line-render.d.ts +2 -1
  291. package/dist/modes/interactive/line/line-render.js +40 -4
  292. package/dist/modes/interactive/message-view.d.ts +1 -1
  293. package/dist/modes/interactive/message-view.js +24 -2
  294. package/dist/modes/interactive/panels.d.ts +18 -1
  295. package/dist/modes/interactive/panels.js +19 -5
  296. package/dist/modes/interactive/plan-command.d.ts +40 -0
  297. package/dist/modes/interactive/plan-command.js +129 -0
  298. package/dist/modes/interactive/plan-dialog.d.ts +98 -0
  299. package/dist/modes/interactive/plan-dialog.js +290 -0
  300. package/dist/modes/interactive/plan-flow.d.ts +34 -0
  301. package/dist/modes/interactive/plan-flow.js +98 -0
  302. package/dist/modes/interactive/rewind-command.d.ts +31 -0
  303. package/dist/modes/interactive/rewind-command.js +106 -0
  304. package/dist/modes/interactive/rewind-flow.d.ts +37 -0
  305. package/dist/modes/interactive/rewind-flow.js +151 -0
  306. package/dist/modes/interactive/rewind-list.d.ts +36 -0
  307. package/dist/modes/interactive/rewind-list.js +123 -0
  308. package/dist/modes/interactive/rewind-panel.d.ts +77 -0
  309. package/dist/modes/interactive/rewind-panel.js +309 -0
  310. package/dist/modes/interactive/rewind-text.d.ts +40 -0
  311. package/dist/modes/interactive/rewind-text.js +139 -0
  312. package/dist/modes/interactive/session-events.d.ts +24 -0
  313. package/dist/modes/interactive/session-events.js +96 -0
  314. package/dist/modes/interactive/status-area.d.ts +73 -0
  315. package/dist/modes/interactive/status-area.js +190 -0
  316. package/dist/modes/interactive/status-bar.d.ts +99 -11
  317. package/dist/modes/interactive/status-bar.js +273 -90
  318. package/dist/modes/interactive/status-line.d.ts +33 -0
  319. package/dist/modes/interactive/status-line.js +113 -0
  320. package/dist/modes/interactive/subagent-view.d.ts +56 -0
  321. package/dist/modes/interactive/subagent-view.js +154 -0
  322. package/dist/modes/interactive/tasks-report.d.ts +27 -0
  323. package/dist/modes/interactive/tasks-report.js +114 -0
  324. package/dist/modes/interactive/tool-view.d.ts +12 -2
  325. package/dist/modes/interactive/tool-view.js +34 -4
  326. package/dist/modes/print/print-mode.d.ts +13 -4
  327. package/dist/modes/print/print-mode.js +56 -12
  328. package/dist/modes/rpc/commands.d.ts +9 -0
  329. package/dist/modes/rpc/commands.js +44 -0
  330. package/dist/modes/rpc/rpc-mode.js +7 -1
  331. package/dist/modes/session-report.d.ts +11 -0
  332. package/dist/modes/session-report.js +48 -1
  333. package/dist/permissions/auto-safe.d.ts +5 -0
  334. package/dist/permissions/auto-safe.js +18 -0
  335. package/dist/permissions/classifier.d.ts +4 -0
  336. package/dist/permissions/classifier.js +2 -0
  337. package/dist/permissions/modes.js +1 -1
  338. package/dist/permissions/pipeline.d.ts +43 -4
  339. package/dist/permissions/pipeline.js +114 -9
  340. package/dist/permissions/readonly-bash.d.ts +30 -0
  341. package/dist/permissions/readonly-bash.js +118 -0
  342. package/dist/permissions/types.d.ts +42 -0
  343. package/dist/plan/compose.d.ts +9 -0
  344. package/dist/plan/compose.js +19 -0
  345. package/dist/plan/controller.d.ts +71 -0
  346. package/dist/plan/controller.js +27 -0
  347. package/dist/plan/done-markers.d.ts +17 -0
  348. package/dist/plan/done-markers.js +51 -0
  349. package/dist/plan/extract.d.ts +29 -0
  350. package/dist/plan/extract.js +160 -0
  351. package/dist/plan/prompts.d.ts +36 -0
  352. package/dist/plan/prompts.js +89 -0
  353. package/dist/plan/store.d.ts +37 -0
  354. package/dist/plan/store.js +90 -0
  355. package/dist/rpc.d.ts +58 -2
  356. package/dist/rpc.js +7 -0
  357. package/dist/sandbox/bash.d.ts +74 -0
  358. package/dist/sandbox/bash.js +126 -0
  359. package/dist/sandbox/detect.d.ts +48 -0
  360. package/dist/sandbox/detect.js +149 -0
  361. package/dist/sandbox/index.d.ts +5 -0
  362. package/dist/sandbox/index.js +5 -0
  363. package/dist/sandbox/profile.d.ts +33 -0
  364. package/dist/sandbox/profile.js +76 -0
  365. package/dist/sandbox/wrap.d.ts +29 -0
  366. package/dist/sandbox/wrap.js +117 -0
  367. package/dist/sdk.d.ts +33 -2
  368. package/dist/sdk.js +24 -2
  369. package/dist/session/types.d.ts +3 -1
  370. package/dist/session/types.js +1 -0
  371. package/dist/skills/builtin.d.ts +31 -0
  372. package/dist/skills/builtin.js +109 -0
  373. package/dist/skills/discover.d.ts +2 -1
  374. package/dist/skills/index-prompt.js +5 -8
  375. package/dist/tools/background-jobs.d.ts +71 -0
  376. package/dist/tools/background-jobs.js +198 -0
  377. package/dist/tools/bash.d.ts +53 -1
  378. package/dist/tools/bash.js +158 -7
  379. package/dist/tools/clipboard-image.d.ts +44 -0
  380. package/dist/tools/clipboard-image.js +148 -0
  381. package/dist/tools/edit.d.ts +2 -0
  382. package/dist/tools/edit.js +18 -3
  383. package/dist/tools/image-file.d.ts +38 -3
  384. package/dist/tools/image-file.js +81 -10
  385. package/dist/tools/image-resize.d.ts +58 -0
  386. package/dist/tools/image-resize.js +97 -0
  387. package/dist/tools/presets.d.ts +7 -2
  388. package/dist/tools/presets.js +11 -4
  389. package/dist/tools/read.d.ts +5 -2
  390. package/dist/tools/read.js +13 -10
  391. package/dist/tools/registry.d.ts +7 -1
  392. package/dist/tools/registry.js +27 -4
  393. package/dist/tools/task-ctl.d.ts +22 -0
  394. package/dist/tools/task-ctl.js +116 -0
  395. package/dist/tools/task.d.ts +22 -10
  396. package/dist/tools/task.js +66 -26
  397. package/dist/tools/todo.d.ts +22 -2
  398. package/dist/tools/todo.js +58 -14
  399. package/dist/tools/truncate.d.ts +15 -0
  400. package/dist/tools/truncate.js +25 -0
  401. package/dist/tools/types.d.ts +113 -0
  402. package/dist/tools/types.js +5 -0
  403. package/dist/tools/write.js +3 -0
  404. package/dist/tui/glyphs.d.ts +4 -0
  405. package/dist/tui/glyphs.js +4 -0
  406. package/dist/tui/keybindings.d.ts +5 -0
  407. package/dist/tui/keybindings.js +5 -0
  408. package/docs/acp.md +78 -0
  409. package/docs/agents.md +250 -0
  410. package/docs/codemode.md +12 -8
  411. package/docs/hooks.md +26 -22
  412. package/docs/permissions.md +77 -13
  413. package/docs/plan.md +107 -0
  414. package/docs/providers.md +228 -52
  415. package/docs/rewind-plan.md +181 -0
  416. package/docs/rpc.md +92 -5
  417. package/docs/sandbox.md +215 -0
  418. package/docs/session-format.md +41 -21
  419. package/docs/sessions.md +41 -1
  420. package/docs/tui-design.md +751 -0
  421. package/docs/tui.md +125 -6
  422. package/package.json +13 -2
@@ -0,0 +1,151 @@
1
+ /**
2
+ * 回滚交互流程(rewind-plan §3.5、§3.6、§4):列表 → 确认面板 → 执行 → 结果通知。[RW-C]
3
+ *
4
+ * - `open()`(`/rewind`、空闲时双击 Esc):运行中只提示;没有回滚点提示一行。
5
+ * - 执行:对话类(恢复代码和对话 / 恢复对话 / 从这里摘要)之后重画消息区并把原消息回填输入框
6
+ * (文本进编辑器,图片随下一条消息发送);结果写一条通知,错误码换成中文说明。
7
+ * - `afterInterrupt()`(中断即撤回):Esc 中断后等运行结束;输入框仍为空且会话判定可撤回
8
+ * (`ui.restoreOnCancel`、本回合没有任何助手文本 / 工具调用)→ 撤回并回填原消息。
9
+ */
10
+ import { AgentSessionImpl } from "../../agent/session.js";
11
+ import { PreviewCache, openRewindList } from "./rewind-list.js";
12
+ import { RewindPanel } from "./rewind-panel.js";
13
+ import { rewindErrorText, rewindResultLines } from "./rewind-text.js";
14
+ export const REFILLED = "原消息已放回输入框";
15
+ /** 打开确认面板(底部覆盖层);返回选择或 undefined(取消)。 */
16
+ export function openRewindPanel(host, model) {
17
+ return new Promise((resolve) => {
18
+ let handle;
19
+ const panel = new RewindPanel(model, {
20
+ theme: host.theme,
21
+ ...(host.keybindings !== undefined ? { keybindings: host.keybindings } : {}),
22
+ ...(host.rows !== undefined ? { rows: host.rows } : {}),
23
+ }, (choice) => {
24
+ handle?.hide();
25
+ resolve(choice);
26
+ });
27
+ handle = host.showOverlay(panel, { anchor: "bottom" });
28
+ });
29
+ }
30
+ function draftNote(draft) {
31
+ const images = draft.images?.length ?? 0;
32
+ return images > 0 ? `${REFILLED}(${images} 张图片随下一条消息发送)` : REFILLED;
33
+ }
34
+ /** 执行面板里的选择,结果与错误都写成通知。 */
35
+ export async function executeRewind(host, point, choice) {
36
+ const session = host.session();
37
+ try {
38
+ switch (choice.action) {
39
+ case "both":
40
+ case "conversation":
41
+ case "code": {
42
+ host.hint("回滚中…");
43
+ const result = await session.rewind({
44
+ entryId: point.entryId,
45
+ mode: choice.action,
46
+ ...(choice.onConflict !== undefined ? { onConflict: choice.onConflict } : {}),
47
+ });
48
+ const draft = result.conversation?.draft;
49
+ if (draft !== undefined) {
50
+ host.reload();
51
+ host.setDraft(draft);
52
+ }
53
+ const shown = { ...result };
54
+ if (choice.action === "conversation")
55
+ delete shown.gitHint;
56
+ const lines = rewindResultLines(shown, {
57
+ overwrite: choice.onConflict === "overwrite",
58
+ ...(draft !== undefined
59
+ ? { conversation: `对话已回到这条消息之前,${draftNote(draft)}` }
60
+ : {}),
61
+ });
62
+ const code = result.code;
63
+ const nothing = code !== undefined &&
64
+ code.restored.length + code.deleted.length === 0 &&
65
+ (choice.onConflict !== "overwrite" || code.conflicts.length === 0);
66
+ host.notice(nothing && choice.action === "code" ? "warn" : "info", lines.join("\n"));
67
+ break;
68
+ }
69
+ case "summarize-from": {
70
+ host.hint("正在为离开的部分写摘要…");
71
+ const result = await session.summarizeFrom(point.entryId, choice.instructions);
72
+ host.reload();
73
+ host.setDraft(result.draft);
74
+ host.notice("info", `已从这里分叉,离开的部分写成了摘要;${draftNote(result.draft)}`);
75
+ break;
76
+ }
77
+ case "summarize-up-to": {
78
+ host.hint("正在摘要…");
79
+ const result = await session.summarizeUpTo(point.entryId, choice.instructions);
80
+ const after = result.tokensAfter !== undefined ? ` → ${result.tokensAfter}` : "";
81
+ host.notice("info", `已摘要到这里:${result.tokensBefore}${after} token`);
82
+ break;
83
+ }
84
+ }
85
+ }
86
+ catch (error) {
87
+ host.notice("error", rewindErrorText(error));
88
+ }
89
+ finally {
90
+ host.hint("");
91
+ }
92
+ }
93
+ export function createRewindFlow(host) {
94
+ let opening = false;
95
+ return {
96
+ async open() {
97
+ const session = host.session();
98
+ if (session.state.isStreaming) {
99
+ host.notice("warn", "正在运行,不能回滚(先按 Esc 中断)");
100
+ return;
101
+ }
102
+ if (opening)
103
+ return;
104
+ opening = true;
105
+ try {
106
+ const points = session.rewindPoints();
107
+ if (points.length === 0) {
108
+ host.notice("info", "还没有可回滚的消息");
109
+ return;
110
+ }
111
+ const cache = new PreviewCache((entryId) => session.rewind({ entryId, mode: "code", dryRun: true }));
112
+ const point = await openRewindList(host, points, cache);
113
+ if (point === undefined)
114
+ return;
115
+ const model = { point, now: host.now() };
116
+ if (point.hasCheckpoint) {
117
+ const state = await cache.ensure(point.entryId);
118
+ if (state.state === "done")
119
+ model.preview = state.result;
120
+ else if (state.state === "error")
121
+ model.previewError = state.message;
122
+ }
123
+ const choice = await openRewindPanel(host, model);
124
+ if (choice !== undefined)
125
+ await executeRewind(host, point, choice);
126
+ }
127
+ finally {
128
+ opening = false;
129
+ }
130
+ },
131
+ async afterInterrupt(editorWasEmpty) {
132
+ const session = host.session();
133
+ await session.waitForIdle();
134
+ if (!editorWasEmpty || !host.editorEmpty())
135
+ return;
136
+ if (!(session instanceof AgentSessionImpl) || !session.canUndoAbortedTurn())
137
+ return;
138
+ try {
139
+ const draft = await session.undoAbortedTurn();
140
+ if (draft === undefined)
141
+ return;
142
+ host.reload();
143
+ host.setDraft(draft);
144
+ host.notice("info", `已撤回被中断的消息,${draftNote(draft)}`);
145
+ }
146
+ catch (error) {
147
+ host.notice("error", rewindErrorText(error));
148
+ }
149
+ },
150
+ };
151
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 回滚列表(rewind-plan §4):居中覆盖层 + `SelectList`。[RW-C]
3
+ *
4
+ * - 活动路径上的回滚点,最旧在上、最近在下,缺省选中最后一条;标签是消息首行,说明是相对时间。
5
+ * - 右侧徽标:没有检查点的行一律「仅对话」;有检查点的只给高亮行算——对它做一次代码 dry-run,
6
+ * 结果按 entryId 缓存,算好后异步刷新:`N 文件 +x −y` / `无代码改动`,计算中 `…`,失败 `—`。
7
+ */
8
+ import type { RewindPoint, RewindResult } from "../../checkpoints/types.js";
9
+ import { type SelectItem } from "../../tui.js";
10
+ import { type PickerHost } from "./pickers.js";
11
+ export type PreviewState = {
12
+ state: "pending";
13
+ } | {
14
+ state: "done";
15
+ result: RewindResult;
16
+ } | {
17
+ state: "error";
18
+ message: string;
19
+ };
20
+ /** 代码 dry-run 的缓存:每个回滚点最多算一次。 */
21
+ export declare class PreviewCache {
22
+ private readonly load;
23
+ private readonly states;
24
+ private readonly running;
25
+ constructor(load: (entryId: string) => Promise<RewindResult>);
26
+ get(entryId: string): PreviewState | undefined;
27
+ ensure(entryId: string): Promise<PreviewState>;
28
+ }
29
+ /** 列表项:value = 用户消息条目 id。 */
30
+ export declare function rewindListItems(points: readonly RewindPoint[], cache: PreviewCache, highlighted: string | undefined, now: number, ascii?: boolean): SelectItem[];
31
+ export interface RewindListHost extends PickerHost {
32
+ render(): void;
33
+ now(): number;
34
+ }
35
+ /** 打开回滚列表;Enter 返回选中的回滚点,Esc 返回 undefined。 */
36
+ export declare function openRewindList(host: RewindListHost, points: readonly RewindPoint[], cache: PreviewCache): Promise<RewindPoint | undefined>;
@@ -0,0 +1,123 @@
1
+ /**
2
+ * 回滚列表(rewind-plan §4):居中覆盖层 + `SelectList`。[RW-C]
3
+ *
4
+ * - 活动路径上的回滚点,最旧在上、最近在下,缺省选中最后一条;标签是消息首行,说明是相对时间。
5
+ * - 右侧徽标:没有检查点的行一律「仅对话」;有检查点的只给高亮行算——对它做一次代码 dry-run,
6
+ * 结果按 entryId 缓存,算好后异步刷新:`N 文件 +x −y` / `无代码改动`,计算中 `…`,失败 `—`。
7
+ */
8
+ import { Box, SelectList } from "../../tui.js";
9
+ import { PICKER_FOOTER } from "./pickers.js";
10
+ import { badgeText, hasCodeChanges, oneLine, rewindErrorText } from "./rewind-text.js";
11
+ import { relativeTime } from "./startup-ui.js";
12
+ /** 代码 dry-run 的缓存:每个回滚点最多算一次。 */
13
+ export class PreviewCache {
14
+ load;
15
+ states = new Map();
16
+ running = new Map();
17
+ constructor(load) {
18
+ this.load = load;
19
+ }
20
+ get(entryId) {
21
+ return this.states.get(entryId);
22
+ }
23
+ ensure(entryId) {
24
+ const known = this.states.get(entryId);
25
+ if (known !== undefined && known.state !== "pending")
26
+ return Promise.resolve(known);
27
+ const running = this.running.get(entryId);
28
+ if (running !== undefined)
29
+ return running;
30
+ this.states.set(entryId, { state: "pending" });
31
+ const promise = this.load(entryId).then((result) => ({ state: "done", result }), (error) => ({ state: "error", message: rewindErrorText(error) }));
32
+ const settled = promise.then((state) => {
33
+ this.states.set(entryId, state);
34
+ this.running.delete(entryId);
35
+ return state;
36
+ });
37
+ this.running.set(entryId, settled);
38
+ return settled;
39
+ }
40
+ }
41
+ /** 列表项:value = 用户消息条目 id。 */
42
+ export function rewindListItems(points, cache, highlighted, now, ascii = false) {
43
+ return points.map((point) => {
44
+ const text = oneLine(point.text, 60, ascii ? "..." : "…");
45
+ const item = {
46
+ value: point.entryId,
47
+ label: text === "" ? "(空)" : text,
48
+ description: relativeTime(new Date(point.timestamp).toISOString(), now),
49
+ };
50
+ if (!point.hasCheckpoint) {
51
+ item.badge = "仅对话";
52
+ item.badgeColor = "dim";
53
+ }
54
+ else if (point.entryId === highlighted) {
55
+ const state = cache.get(point.entryId);
56
+ if (state === undefined || state.state === "pending") {
57
+ item.badge = ascii ? "..." : "…";
58
+ item.badgeColor = "dim";
59
+ }
60
+ else if (state.state === "error") {
61
+ item.badge = ascii ? "-" : "—";
62
+ item.badgeColor = "dim";
63
+ }
64
+ else {
65
+ const code = state.result.code;
66
+ item.badge = code === undefined ? "无代码改动" : badgeText(code, ascii);
67
+ item.badgeColor = hasCodeChanges(code) ? "accent" : "dim";
68
+ }
69
+ }
70
+ return item;
71
+ });
72
+ }
73
+ /** 打开回滚列表;Enter 返回选中的回滚点,Esc 返回 undefined。 */
74
+ export function openRewindList(host, points, cache) {
75
+ return new Promise((resolve) => {
76
+ const ascii = host.theme.glyphs.ascii;
77
+ let highlighted = points.at(-1)?.entryId;
78
+ let refreshing = false;
79
+ let closed = false;
80
+ const items = () => rewindListItems(points, cache, highlighted, host.now(), ascii);
81
+ const refresh = () => {
82
+ if (refreshing || closed)
83
+ return;
84
+ refreshing = true;
85
+ list.setItems(items());
86
+ refreshing = false;
87
+ host.render();
88
+ };
89
+ const close = (point) => {
90
+ closed = true;
91
+ handle.hide();
92
+ resolve(point);
93
+ };
94
+ const highlight = (entryId) => {
95
+ highlighted = entryId;
96
+ const point = points.find((p) => p.entryId === entryId);
97
+ if (point?.hasCheckpoint === true)
98
+ void cache.ensure(point.entryId).then(refresh);
99
+ refresh();
100
+ };
101
+ const list = new SelectList(items(), {
102
+ theme: host.theme,
103
+ maxVisible: 10,
104
+ filterable: points.length > 8,
105
+ ...(host.keybindings !== undefined ? { keybindings: host.keybindings } : {}),
106
+ footer: PICKER_FOOTER.replace("↑↓", host.theme.glyphs.arrowUp + host.theme.glyphs.arrowDown),
107
+ onSelect: (item) => close(points.find((p) => p.entryId === item.value)),
108
+ onCancel: () => close(undefined),
109
+ onSelectionChange: (item) => {
110
+ if (!refreshing && item?.value !== highlighted)
111
+ highlight(item?.value);
112
+ },
113
+ });
114
+ if (highlighted !== undefined)
115
+ list.selectValue(highlighted);
116
+ const width = Math.max(20, Math.min(host.columns() - 2, 72));
117
+ const handle = host.showOverlay(new Box(list, { title: "回滚到哪条消息之前", theme: host.theme }), {
118
+ anchor: "center",
119
+ width,
120
+ });
121
+ highlight(highlighted);
122
+ });
123
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * 回滚确认面板(rewind-plan §4):底部覆盖层,左竖条样式与 `/session` 面板一致(`Card`)。[RW-C]
3
+ *
4
+ * - 标题「回滚到这条消息之前」+ 相对时间;消息原文最多 3 行(超出计数)。
5
+ * - 选项编号列表:恢复代码和对话 / 恢复对话 / 恢复代码(两个代码项只在 dry-run 有改动时出现)/
6
+ * 从这里摘要 / 摘要到这里 / 取消。每项下一行是预览(「将恢复 N 个文件 +x −y」「代码不变 · 对话将分叉」…);
7
+ * 宽 < 56 时只给选中项画预览、去空行。
8
+ * - 两个摘要项可以在行内输入说明:选中后直接打字,Enter 提交;数字键直接执行(不带说明);
9
+ * 有说明时 Esc 先清空说明,再按才关闭。
10
+ * - 冲突:选了代码类且 dry-run 有冲突 → 进入第二步「跳过冲突文件 / 覆盖冲突文件 / 返回」,
11
+ * 覆盖对应 `onConflict: "overwrite"`。
12
+ * - 明细:冲突与无法恢复的文件(各最多 5 个)、git HEAD 变化提示与两条命令(只显示,不执行)。
13
+ */
14
+ import type { RewindMode, RewindPoint, RewindResult } from "../../checkpoints/types.js";
15
+ import { type Component, type Focusable, type Keybindings, type Theme } from "../../tui.js";
16
+ export type RewindAction = RewindMode | "summarize-from" | "summarize-up-to";
17
+ export interface RewindChoice {
18
+ action: RewindAction;
19
+ /** 摘要两项的说明。 */
20
+ instructions?: string;
21
+ /** 代码类且有冲突时的选择。 */
22
+ onConflict?: "skip" | "overwrite";
23
+ }
24
+ export interface RewindPanelModel {
25
+ point: RewindPoint;
26
+ /** 代码 dry-run(`mode: "code"`);没有检查点或预览失败时 undefined。 */
27
+ preview?: RewindResult;
28
+ /** 预览失败的说明。 */
29
+ previewError?: string;
30
+ now: number;
31
+ }
32
+ export interface RewindOption {
33
+ action: RewindAction | "cancel";
34
+ label: string;
35
+ preview?: string;
36
+ /** 可在行内输入说明。 */
37
+ input?: boolean;
38
+ }
39
+ /** 面板的选项(按显示顺序)。 */
40
+ export declare function rewindOptions(model: RewindPanelModel, ascii?: boolean): RewindOption[];
41
+ export interface RewindPanelHost {
42
+ theme: Theme;
43
+ keybindings?: Keybindings;
44
+ /** 终端行数:整面板放不下时改用紧凑排版。 */
45
+ rows?(): number;
46
+ }
47
+ export declare class RewindPanel implements Component, Focusable {
48
+ private readonly model;
49
+ private readonly host;
50
+ private readonly done;
51
+ focused: boolean;
52
+ private selected;
53
+ private readonly inputs;
54
+ private stage;
55
+ /** 终端放不下时:原文 1 行、文件清单并成一行、git 提示去掉说明。 */
56
+ private tight;
57
+ readonly options: readonly RewindOption[];
58
+ constructor(model: RewindPanelModel, host: RewindPanelHost, done: (choice: RewindChoice | undefined) => void);
59
+ /** 当前选中项(测试用)。 */
60
+ get selectedOption(): RewindOption;
61
+ /** 选中项的说明(测试用)。 */
62
+ inputOf(action: RewindAction): string;
63
+ private get conflicts();
64
+ private choose;
65
+ handleInput(data: string): void;
66
+ private move;
67
+ private conflictInput;
68
+ render(width: number): string[];
69
+ invalidate(): void;
70
+ private body;
71
+ private messageLines;
72
+ private optionLabel;
73
+ private optionLine;
74
+ /** 文件清单:每个一行(最多 5 个);紧凑时接在 `head` 后面并成一行。 */
75
+ private fileLines;
76
+ private detailLines;
77
+ }