@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
@@ -5,13 +5,17 @@
5
5
  * - list [--all]:缺省只列当前目录的会话;`--all` 列全部。
6
6
  * - show <id>:头信息 + 条目类型统计 + 首条提示 + 用户消息编号(`--from <id>#<编号>` 复用)。
7
7
  * - search / export:见 sessions-search.ts、sessions-export.ts(只读扫描,不经会话存储)。
8
- * - prune [--older-than <天>] [--dry-run]:缺省 30 天,移到 trash(不删除)。
8
+ * - prune [--older-than <天>] [--dry-run]:缺省 30 天,移到 trash(不删除);之后清理检查点备份
9
+ * (未被任何会话引用且超过 1 天的 blob,docs/rewind-plan.md §1.4)与超过 7 天的剪贴板图片
10
+ * (`<数据目录>/clipboard/`,W5-I),`--dry-run` 时只报告。
9
11
  */
10
- import { resolve } from "node:path";
12
+ import { join, resolve } from "node:path";
13
+ import { formatBytes, gcBlobs } from "../../checkpoints/gc.js";
11
14
  import { expandHome, resolveDataDir } from "../../config/paths.js";
12
15
  import { parseSubArgs, UsageError } from "../args.js";
13
16
  import { ExitCode } from "../exit-codes.js";
14
17
  import { numberUserMessages } from "../../session/reuse.js";
18
+ import { gcClipboardImages } from "../../tools/clipboard-image.js";
15
19
  import { runSessionsExport } from "./sessions-export.js";
16
20
  import { runSessionsSearch } from "./sessions-search.js";
17
21
  export const SESSIONS_USAGE = `用法:ama sessions list [--all] [--session-dir <目录>]
@@ -109,12 +113,42 @@ export async function runSessions(argv, io, deps) {
109
113
  for (const file of moved)
110
114
  io.stdout(`${dryRun ? "将移到 trash" : "已移到 trash"}:${file}\n`);
111
115
  io.stdout(`${moved.length} 个会话${dryRun ? "(演练,未改动)" : ""}\n`);
116
+ await pruneFileHistory(io, sessionDir, dryRun);
117
+ await pruneClipboard(io, dryRun);
112
118
  return ExitCode.Ok;
113
119
  }
114
120
  default:
115
121
  throw new UsageError(`未知的 sessions 子命令:${action}`);
116
122
  }
117
123
  }
124
+ /** 检查点备份 GC:扫描本次的会话目录、缺省会话目录与登记过的目录。失败只提示,不影响 prune。 */
125
+ async function pruneFileHistory(io, sessionDir, dryRun) {
126
+ const dataDir = resolveDataDir({ env: io.env });
127
+ try {
128
+ const result = await gcBlobs({
129
+ dataDir,
130
+ sessionRoots: [sessionDir, join(dataDir, "sessions")],
131
+ dryRun,
132
+ });
133
+ if (result.removed.length === 0)
134
+ return;
135
+ io.stdout(`file-history:${dryRun ? "将清除" : "已清除"} ${result.removed.length} 个未引用的备份(${formatBytes(result.removedBytes)})\n`);
136
+ }
137
+ catch (error) {
138
+ io.stderr(`ama: file-history 清理跳过(${error instanceof Error ? error.message : String(error)})\n`);
139
+ }
140
+ }
141
+ /** [W5-I] `<数据目录>/clipboard/` 超过 7 天的剪贴板图片。失败只提示。 */
142
+ async function pruneClipboard(io, dryRun) {
143
+ try {
144
+ const removed = await gcClipboardImages(resolveDataDir({ env: io.env }), { dryRun });
145
+ if (removed.length > 0)
146
+ io.stdout(`clipboard:${dryRun ? "将清除" : "已清除"} ${removed.length} 个超过 7 天的剪贴板图片\n`);
147
+ }
148
+ catch (error) {
149
+ io.stderr(`ama: clipboard 清理跳过(${error instanceof Error ? error.message : String(error)})\n`);
150
+ }
151
+ }
118
152
  function notWired(io, what) {
119
153
  io.stderr(`ama: ${what} 尚未装配(会话存储由集成批次注入)\n`);
120
154
  return ExitCode.RuntimeError;
@@ -1,14 +1,19 @@
1
1
  /**
2
- * 沙箱能力探测(设计 §5.5 沙箱第 4 条)。[B10]
2
+ * 沙箱能力探测(设计 §5.5 沙箱第 4 条;docs/sandbox.md「探测与降级」)。[B10][S2]
3
3
  *
4
4
  * Node 的权限模型(`--permission`)在 Node ≥ 25 同时拒绝网络;Node 22 / 24 只管文件、子进程、
5
- * worker 与 addon,不管网络——脚本若逃出 `vm` 就能联网。所以:
6
- * - Node ≥ 25 → `strict`;
7
- * - Node 22 / 24 → 仍可用,但工具描述与状态栏标注「网络未隔离」;`codemode.requireStrict: true`
8
- * 时直接禁用 codemode 工具并 warning(`codemodeAvailability`)。
5
+ * worker 与 addon,不管网络——脚本若逃出 `vm` 就能联网。子进程另外经操作系统沙箱(macOS
6
+ * sandbox-exec、Linux bwrap / unshare,src/sandbox)启动时,网络由内核拒绝。所以:
7
+ * - Node ≥ 25 → `strict`(OS 沙箱可用时叠加,纵深防御);
8
+ * - Node 22 / 24 + 可用的 OS 沙箱 → `strict`(子进程必须经 OS 沙箱启动);
9
+ * - Node 22 / 24 且没有 OS 沙箱 → 仍可用,但工具描述与状态栏标注「网络未隔离」;
10
+ * `codemode.requireStrict: true` 时直接禁用 codemode 工具并 warning(`codemodeAvailability`)。
9
11
  *
10
- * 状态栏由 B7 直接调用 `detectSandboxCapability()` 判断(不经宿主 status)。
12
+ * 能力在进程内只探测一次(OS 沙箱探针有缓存),同一环境下描述与权限类字节稳定。状态栏直接调用
13
+ * `detectSandboxCapability()`(不经宿主 status);组装根先用 `configureOsSandbox` 记下 `sandbox.enabled`。
11
14
  */
15
+ import type { SandboxConfig } from "../config/types.js";
16
+ import { type OsSandboxStatus } from "../sandbox/detect.js";
12
17
  export interface SandboxCapability {
13
18
  /** 权限模型同时隔离文件、子进程与网络。 */
14
19
  strict: boolean;
@@ -18,12 +23,24 @@ export interface SandboxCapability {
18
23
  reason: string;
19
24
  /** 运行时支持的权限开关:Node ≥ 22.13 / 23.5 为 `--permission`,更早为 `--experimental-permission`。 */
20
25
  permissionFlag: "--permission" | "--experimental-permission";
26
+ /** 操作系统沙箱(`kind: none` 表示没有);codemode 子进程经它启动。 */
27
+ os: OsSandboxStatus;
21
28
  }
22
29
  export declare const NETWORK_NOT_ISOLATED = "network not isolated";
23
30
  export declare function parseNodeMajor(version: string): number;
24
31
  /** `--permission` 在 Node 22.13 / 23.5 之后才是稳定名字;之前只有 `--experimental-permission`。 */
25
32
  export declare function permissionFlagFor(allowedFlags?: ReadonlySet<string>): SandboxCapability["permissionFlag"];
26
- export declare function detectSandboxCapability(nodeVersion?: string, allowedFlags?: ReadonlySet<string>): SandboxCapability;
33
+ /**
34
+ * 运行时的沙箱能力。`os` 缺省:不传 `nodeVersion` 时用进程内缓存的探测结果(`osSandboxStatus()`);
35
+ * 传了假设的 Node 版本(测试、展示)时不探测,按没有 OS 沙箱算,需要时显式传入。
36
+ */
37
+ export declare function detectSandboxCapability(nodeVersion?: string, allowedFlags?: ReadonlySet<string>, os?: OsSandboxStatus): SandboxCapability;
38
+ /** 按配置的 `sandbox.enabled`(缺省 auto)得到运行时能力。 */
39
+ export declare function sandboxCapabilityFor(config: {
40
+ sandbox?: SandboxConfig;
41
+ }): SandboxCapability;
42
+ /** strict 是否依赖 OS 沙箱(Node 22 / 24):此时子进程必须经 OS 沙箱启动,包装不了就报错。 */
43
+ export declare function strictNeedsOsSandbox(capability: Pick<SandboxCapability, "strict" | "nodeMajor">): boolean;
27
44
  export type CodemodeAvailability = {
28
45
  available: true;
29
46
  capability: SandboxCapability;
@@ -1,14 +1,18 @@
1
1
  /**
2
- * 沙箱能力探测(设计 §5.5 沙箱第 4 条)。[B10]
2
+ * 沙箱能力探测(设计 §5.5 沙箱第 4 条;docs/sandbox.md「探测与降级」)。[B10][S2]
3
3
  *
4
4
  * Node 的权限模型(`--permission`)在 Node ≥ 25 同时拒绝网络;Node 22 / 24 只管文件、子进程、
5
- * worker 与 addon,不管网络——脚本若逃出 `vm` 就能联网。所以:
6
- * - Node ≥ 25 → `strict`;
7
- * - Node 22 / 24 → 仍可用,但工具描述与状态栏标注「网络未隔离」;`codemode.requireStrict: true`
8
- * 时直接禁用 codemode 工具并 warning(`codemodeAvailability`)。
5
+ * worker 与 addon,不管网络——脚本若逃出 `vm` 就能联网。子进程另外经操作系统沙箱(macOS
6
+ * sandbox-exec、Linux bwrap / unshare,src/sandbox)启动时,网络由内核拒绝。所以:
7
+ * - Node ≥ 25 → `strict`(OS 沙箱可用时叠加,纵深防御);
8
+ * - Node 22 / 24 + 可用的 OS 沙箱 → `strict`(子进程必须经 OS 沙箱启动);
9
+ * - Node 22 / 24 且没有 OS 沙箱 → 仍可用,但工具描述与状态栏标注「网络未隔离」;
10
+ * `codemode.requireStrict: true` 时直接禁用 codemode 工具并 warning(`codemodeAvailability`)。
9
11
  *
10
- * 状态栏由 B7 直接调用 `detectSandboxCapability()` 判断(不经宿主 status)。
12
+ * 能力在进程内只探测一次(OS 沙箱探针有缓存),同一环境下描述与权限类字节稳定。状态栏直接调用
13
+ * `detectSandboxCapability()`(不经宿主 status);组装根先用 `configureOsSandbox` 记下 `sandbox.enabled`。
11
14
  */
15
+ import { NO_OS_SANDBOX, osSandboxStatus } from "../sandbox/detect.js";
12
16
  export const NETWORK_NOT_ISOLATED = "network not isolated";
13
17
  export function parseNodeMajor(version) {
14
18
  const major = Number.parseInt(version.replace(/^v/, "").split(".")[0] ?? "", 10);
@@ -18,8 +22,13 @@ export function parseNodeMajor(version) {
18
22
  export function permissionFlagFor(allowedFlags = process.allowedNodeEnvironmentFlags) {
19
23
  return allowedFlags.has("--permission") ? "--permission" : "--experimental-permission";
20
24
  }
21
- export function detectSandboxCapability(nodeVersion = process.versions.node, allowedFlags) {
22
- const nodeMajor = parseNodeMajor(nodeVersion);
25
+ /**
26
+ * 运行时的沙箱能力。`os` 缺省:不传 `nodeVersion` 时用进程内缓存的探测结果(`osSandboxStatus()`);
27
+ * 传了假设的 Node 版本(测试、展示)时不探测,按没有 OS 沙箱算,需要时显式传入。
28
+ */
29
+ export function detectSandboxCapability(nodeVersion, allowedFlags, os) {
30
+ const osStatus = os ?? (nodeVersion === undefined ? osSandboxStatus() : NO_OS_SANDBOX);
31
+ const nodeMajor = parseNodeMajor(nodeVersion ?? process.versions.node);
23
32
  const permissionFlag = permissionFlagFor(allowedFlags);
24
33
  if (nodeMajor >= 25) {
25
34
  return {
@@ -27,6 +36,16 @@ export function detectSandboxCapability(nodeVersion = process.versions.node, all
27
36
  nodeMajor,
28
37
  reason: `Node ${nodeMajor}: the permission model blocks file access, child processes and network`,
29
38
  permissionFlag,
39
+ os: osStatus,
40
+ };
41
+ }
42
+ if (osStatus.isolatesNetwork) {
43
+ return {
44
+ strict: true,
45
+ nodeMajor,
46
+ reason: `Node ${nodeMajor}: the OS sandbox (${osStatus.kind}) blocks network; the permission model blocks file access and child processes`,
47
+ permissionFlag,
48
+ os: osStatus,
30
49
  };
31
50
  }
32
51
  return {
@@ -34,8 +53,17 @@ export function detectSandboxCapability(nodeVersion = process.versions.node, all
34
53
  nodeMajor,
35
54
  reason: `Node ${nodeMajor}: ${NETWORK_NOT_ISOLATED} (the permission model blocks file access and child processes only)`,
36
55
  permissionFlag,
56
+ os: osStatus,
37
57
  };
38
58
  }
59
+ /** 按配置的 `sandbox.enabled`(缺省 auto)得到运行时能力。 */
60
+ export function sandboxCapabilityFor(config) {
61
+ return detectSandboxCapability(undefined, undefined, osSandboxStatus(config.sandbox?.enabled ?? "auto"));
62
+ }
63
+ /** strict 是否依赖 OS 沙箱(Node 22 / 24):此时子进程必须经 OS 沙箱启动,包装不了就报错。 */
64
+ export function strictNeedsOsSandbox(capability) {
65
+ return capability.strict && capability.nodeMajor < 25;
66
+ }
39
67
  /** `requireStrict` 且运行时不是 strict → 禁用并给出 warning;非 strict 但允许 → 可用并提示。 */
40
68
  export function codemodeAvailability(requireStrict, capability = detectSandboxCapability()) {
41
69
  if (capability.strict)
@@ -44,12 +72,12 @@ export function codemodeAvailability(requireStrict, capability = detectSandboxCa
44
72
  return {
45
73
  available: false,
46
74
  capability,
47
- warning: `codemode 已禁用:Node ${capability.nodeMajor} 的权限模型不隔离网络(codemode.requireStrict 为 true;Node ≥ 25 才隔离)`,
75
+ warning: `codemode 已禁用:Node ${capability.nodeMajor} 的权限模型不隔离网络,也没有可用的操作系统沙箱(${capability.os.detail};codemode.requireStrict 为 true;Node ≥ 25 或 macOS sandbox-exec / Linux bwrap 可隔离)`,
48
76
  };
49
77
  }
50
78
  return {
51
79
  available: true,
52
80
  capability,
53
- warning: `codemode:Node ${capability.nodeMajor} 下网络未隔离(Node ≥ 25 才隔离;要求隔离可设 codemode.requireStrict)`,
81
+ warning: `codemode:Node ${capability.nodeMajor} 下网络未隔离(没有可用的操作系统沙箱:${capability.os.detail};要求隔离可设 codemode.requireStrict)`,
54
82
  };
55
83
  }
@@ -12,7 +12,13 @@
12
12
  * (完整门禁);名字是 `codemode` 直接拒绝。脚本结束时 abort 仍在跑的调用。
13
13
  * - 超时:父进程计时,到点杀子进程树(POSIX 进程组 / Windows taskkill);外层 abort:先发
14
14
  * `abort`,宽限后杀树。
15
+ * - OS 沙箱(docs/sandbox.md):有可用的 sandbox-exec / bwrap / unshare 时,整条命令行经它启动,拒绝
16
+ * 网络与一切写入(`CODEMODE_OS_POLICY`;子进程本来就没有写权限)。Node 22 / 24 的 strict 依赖这一层
17
+ * (`requireOsSandbox`),包装不了就报错,不裸跑;Node ≥ 25 是叠加的纵深防御。
15
18
  */
19
+ import { type OsSandboxStatus } from "../sandbox/detect.js";
20
+ import type { OsSandboxPolicy } from "../sandbox/profile.js";
21
+ import { type WrappedCommand } from "../sandbox/wrap.js";
16
22
  import { type SandboxCapability } from "./capability.js";
17
23
  import { type ScriptOptions, type StoreSnapshot, type ToolDecl } from "./protocol.js";
18
24
  /** 父进程累积的输出上限(字符);超出后丢弃中段(给模型的再按 max_output_tokens 截)。 */
@@ -23,6 +29,10 @@ export declare const ABORT_GRACE_MS = 500;
23
29
  export declare function resolveSandboxEntry(moduleUrl?: string): string | undefined;
24
30
  /** 子进程参数(不含可执行文件)。 */
25
31
  export declare function sandboxArgs(entry: string, capability?: Pick<SandboxCapability, "permissionFlag">): string[];
32
+ /** codemode 子进程的 OS 沙箱策略:拒绝网络,任何位置都不可写。 */
33
+ export declare const CODEMODE_OS_POLICY: OsSandboxPolicy;
34
+ /** 完整命令行:`<node> <sandboxArgs>`,有 OS 沙箱时再经它包装。 */
35
+ export declare function sandboxCommand(nodePath: string, args: readonly string[], os: Pick<OsSandboxStatus, "kind" | "path">): WrappedCommand;
26
36
  /** 子进程环境:空;Electron 下以 Node 方式运行同一可执行文件;Windows 保留 SystemRoot。 */
27
37
  export declare function sandboxEnv(versions?: NodeJS.ProcessVersions, platform?: NodeJS.Platform, parentEnv?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
28
38
  export interface SandboxRunRequest {
@@ -39,6 +49,10 @@ export interface SandboxRunRequest {
39
49
  /** 缺省 process.execPath。 */
40
50
  nodePath?: string;
41
51
  capability?: Pick<SandboxCapability, "permissionFlag">;
52
+ /** 缺省 osSandboxStatus()(进程内缓存的探测结果)。 */
53
+ os?: Pick<OsSandboxStatus, "kind" | "path">;
54
+ /** true:必须经 OS 沙箱启动(Node 22 / 24 的 strict 依赖它),包装不了直接失败。 */
55
+ requireOsSandbox?: boolean;
42
56
  }
43
57
  export interface SandboxRunResult {
44
58
  ok: boolean;
@@ -12,11 +12,16 @@
12
12
  * (完整门禁);名字是 `codemode` 直接拒绝。脚本结束时 abort 仍在跑的调用。
13
13
  * - 超时:父进程计时,到点杀子进程树(POSIX 进程组 / Windows taskkill);外层 abort:先发
14
14
  * `abort`,宽限后杀树。
15
+ * - OS 沙箱(docs/sandbox.md):有可用的 sandbox-exec / bwrap / unshare 时,整条命令行经它启动,拒绝
16
+ * 网络与一切写入(`CODEMODE_OS_POLICY`;子进程本来就没有写权限)。Node 22 / 24 的 strict 依赖这一层
17
+ * (`requireOsSandbox`),包装不了就报错,不裸跑;Node ≥ 25 是叠加的纵深防御。
15
18
  */
16
19
  import { spawn } from "node:child_process";
17
20
  import { existsSync, realpathSync } from "node:fs";
18
21
  import { dirname, join } from "node:path";
19
22
  import { fileURLToPath } from "node:url";
23
+ import { osSandboxStatus } from "../sandbox/detect.js";
24
+ import { wrapCommand } from "../sandbox/wrap.js";
20
25
  import { killProcessTree, trackProcessGroup, untrackProcessGroup } from "../tools/process-tree.js";
21
26
  import { detectSandboxCapability } from "./capability.js";
22
27
  import { LineSplitter, SANDBOX_MAIN_FLAG, decodeChildLine, encodeLine, } from "./protocol.js";
@@ -49,6 +54,15 @@ export function sandboxArgs(entry, capability = detectSandboxCapability()) {
49
54
  SANDBOX_MAIN_FLAG,
50
55
  ];
51
56
  }
57
+ /** codemode 子进程的 OS 沙箱策略:拒绝网络,任何位置都不可写。 */
58
+ export const CODEMODE_OS_POLICY = Object.freeze({
59
+ network: "deny",
60
+ writable: Object.freeze([]),
61
+ });
62
+ /** 完整命令行:`<node> <sandboxArgs>`,有 OS 沙箱时再经它包装。 */
63
+ export function sandboxCommand(nodePath, args, os) {
64
+ return wrapCommand(os, nodePath, args, CODEMODE_OS_POLICY);
65
+ }
52
66
  /** 子进程环境:空;Electron 下以 Node 方式运行同一可执行文件;Windows 保留 SystemRoot。 */
53
67
  export function sandboxEnv(versions = process.versions, platform = process.platform, parentEnv = process.env) {
54
68
  const env = {};
@@ -82,8 +96,17 @@ export async function runSandbox(request) {
82
96
  if (request.signal.aborted) {
83
97
  return { ...base, ok: false, error: "Script aborted", aborted: true, elapsedMs: 0 };
84
98
  }
99
+ const command = sandboxCommand(request.nodePath ?? process.execPath, sandboxArgs(entry, request.capability), request.os ?? osSandboxStatus());
100
+ if (request.requireOsSandbox === true && !command.networkDenied) {
101
+ return {
102
+ ...base,
103
+ ok: false,
104
+ error: "codemode sandbox requires an OS sandbox to isolate network, but none is available",
105
+ elapsedMs: 0,
106
+ };
107
+ }
85
108
  const isWindows = process.platform === "win32";
86
- const child = spawn(request.nodePath ?? process.execPath, sandboxArgs(entry, request.capability), {
109
+ const child = spawn(command.command, command.args, {
87
110
  env: sandboxEnv(),
88
111
  stdio: ["pipe", "pipe", "pipe"],
89
112
  detached: !isWindows,
@@ -88,7 +88,7 @@ export declare const CODEMODE_ONLY_GUIDELINE = "read, edit, write, bash and the
88
88
  export declare function createCodemodeTool(options: CodemodeToolOptions): ToolDefinition<CodemodeInput>;
89
89
  /** 组装根用:从 ToolFactoryContext 的形状取所需(避免 codemode → cli 的依赖)。 */
90
90
  export interface CodemodeFactoryContext {
91
- config: Pick<AmaConfig, "tools" | "codemode">;
91
+ config: Pick<AmaConfig, "tools" | "codemode" | "sandbox">;
92
92
  registry: {
93
93
  list(): readonly string[];
94
94
  get(name: string): ToolDefinition | undefined;
@@ -20,7 +20,7 @@ import { mkdirSync, writeFileSync } from "node:fs";
20
20
  import { tmpdir } from "node:os";
21
21
  import { join } from "node:path";
22
22
  import { codemodeCallableFilter, resolveCodemodeMode } from "../tools/presets.js";
23
- import { codemodeAvailability, detectSandboxCapability, } from "./capability.js";
23
+ import { codemodeAvailability, detectSandboxCapability, sandboxCapabilityFor, strictNeedsOsSandbox, } from "./capability.js";
24
24
  import { BASH_RESULT_DECLARATION, DEFAULT_INLINE_BUDGET, buildDeclarationBlock, toolDeclaration, } from "./declarations.js";
25
25
  import { runSandbox } from "./host-side.js";
26
26
  import { parseOptionsLine } from "./protocol.js";
@@ -189,8 +189,8 @@ export function createCodemodeTool(options) {
189
189
  },
190
190
  required: ["script"],
191
191
  },
192
- // 网络隔离(Node ≥ 25)时脚本只能经 tools.* 做事,每次内层调用各自过权限:codemode 本身按 read
193
- // 类(default 模式免审批);不隔离网络时脚本逃出 vm 就能联网,仍按 execute。
192
+ // 网络隔离(Node ≥ 25,或 OS 沙箱)时脚本只能经 tools.* 做事,每次内层调用各自过权限:codemode
193
+ // 本身按 read 类(default 模式免审批);不隔离网络时脚本逃出 vm 就能联网,仍按 execute。
194
194
  permission: capability.strict ? "read" : "execute",
195
195
  executionMode: "sequential",
196
196
  promptSnippet: options.exclusive === true
@@ -218,6 +218,8 @@ export function createCodemodeTool(options) {
218
218
  tools,
219
219
  store: readStore(ctx.session),
220
220
  signal: ctx.signal,
221
+ os: capability.os,
222
+ requireOsSandbox: strictNeedsOsSandbox(capability),
221
223
  ...(options.entry !== undefined ? { entry: options.entry } : {}),
222
224
  ...(options.nodePath !== undefined ? { nodePath: options.nodePath } : {}),
223
225
  callTool: async (name, args, signal) => {
@@ -280,7 +282,7 @@ export function createCodemodeTool(options) {
280
282
  */
281
283
  export function codemodeToolFactory(overrides = {}) {
282
284
  return (ctx) => {
283
- const capability = overrides.capability ?? detectSandboxCapability();
285
+ const capability = overrides.capability ?? sandboxCapabilityFor(ctx.config);
284
286
  const mode = resolveCodemodeMode(ctx.config, capability.strict).mode;
285
287
  if (mode === "off")
286
288
  return undefined;
@@ -1,31 +1,47 @@
1
1
  /**
2
- * 压缩熔断(设计 §9「熔断」)。[B2]
2
+ * 压缩熔断(设计 §9「熔断」,wave5 §8.2 C5)。[B2][W5-H1]
3
3
  *
4
4
  * - 无 `contextWindow` 或配置关闭 → 自动压缩关闭(手动 /compact 仍可用)。
5
- * - 同一 run 内档二(摘要)≤ 1 次(`startRun()` 重置计数)。
6
- * - 连续两次摘要失败 → 跳闸,关闭自动压缩直到 `reset()`(例如用户手动压缩成功)。
5
+ * - 不再限制「每 run 档二 ≤ 1 次」(单提示长任务需要多次摘要);改为两种跳闸:
6
+ * - 连续 3 次摘要失败;
7
+ * - 快速回填:连续 3 次摘要都在上一次摘要后不到 3 回合就又需要摘要(压缩不动、越压越满)。
8
+ * 跳闸后关闭自动压缩直到 `reset()`(例如用户手动压缩成功)。
9
+ * - 固定前缀(system + 工具表)已超过预算:摘要无济于事,直接告警、不再尝试(`prefix_overflow`,
10
+ * 由调用方每次检查时更新)。
11
+ * - 「nothing to compact」不计失败(调用方不调 `recordSummary`)。
7
12
  * - 溢出恢复:压缩后估算仍 > 0.8 × window → 不重试。
8
13
  */
9
- export declare const MAX_SUMMARIES_PER_RUN = 1;
10
- export declare const MAX_CONSECUTIVE_FAILURES = 2;
14
+ export declare const MAX_CONSECUTIVE_FAILURES = 3;
15
+ /** 上一次摘要后不到这么多回合又需要摘要,记一次快速回填。 */
16
+ export declare const RAPID_REFILL_TURNS = 3;
17
+ export declare const MAX_RAPID_REFILLS = 3;
11
18
  export declare const RETRY_AFTER_COMPACTION_RATIO = 0.8;
12
- export type BreakerBlockReason = "disabled" | "no_window" | "tripped" | "run_limit";
19
+ export type BreakerBlockReason = "disabled" | "no_window" | "tripped" | "rapid_refill" | "prefix_overflow";
13
20
  export declare class CompactionBreaker {
14
- private summariesThisRun;
15
21
  private consecutiveFailures;
22
+ private rapidRefills;
23
+ private turn;
24
+ private lastSummaryTurn;
25
+ private prefixOverflow;
16
26
  private enabled;
17
27
  private contextWindow;
18
28
  constructor(enabled: boolean, contextWindow: number | undefined);
19
29
  configure(enabled: boolean, contextWindow: number | undefined): void;
30
+ /** 连续失败或快速回填跳闸(溢出恢复也不再尝试)。 */
20
31
  get tripped(): boolean;
21
- /** 自动压缩整体是否开启(不看本 run 计数)。 */
32
+ /** 自动压缩整体是否开启。 */
22
33
  get autoEnabled(): boolean;
34
+ /** 新 run 开始(会话在 agent_start 时调用);不再重置任何计数,保留以兼容调用点。 */
23
35
  startRun(): void;
36
+ /** 每次请求前的阈值检查调用一次:回合计数(快速回填按它判断)。 */
37
+ tick(): void;
38
+ /** 固定前缀是否已超预算(调用方每次准备摘要前更新)。 */
39
+ setPrefixOverflow(overflow: boolean): void;
24
40
  /** 自动档二能否执行;不能则给出原因。 */
25
41
  blockReason(): BreakerBlockReason | undefined;
26
42
  canSummarize(): boolean;
27
43
  recordSummary(success: boolean): void;
28
- /** 手动压缩成功等场景:清零失败计数。 */
44
+ /** 手动压缩成功等场景:清零全部计数。 */
29
45
  reset(): void;
30
46
  /** 溢出恢复后是否值得重试。 */
31
47
  shouldRetryAfterCompaction(tokensAfter: number): boolean;
@@ -1,17 +1,27 @@
1
1
  /**
2
- * 压缩熔断(设计 §9「熔断」)。[B2]
2
+ * 压缩熔断(设计 §9「熔断」,wave5 §8.2 C5)。[B2][W5-H1]
3
3
  *
4
4
  * - 无 `contextWindow` 或配置关闭 → 自动压缩关闭(手动 /compact 仍可用)。
5
- * - 同一 run 内档二(摘要)≤ 1 次(`startRun()` 重置计数)。
6
- * - 连续两次摘要失败 → 跳闸,关闭自动压缩直到 `reset()`(例如用户手动压缩成功)。
5
+ * - 不再限制「每 run 档二 ≤ 1 次」(单提示长任务需要多次摘要);改为两种跳闸:
6
+ * - 连续 3 次摘要失败;
7
+ * - 快速回填:连续 3 次摘要都在上一次摘要后不到 3 回合就又需要摘要(压缩不动、越压越满)。
8
+ * 跳闸后关闭自动压缩直到 `reset()`(例如用户手动压缩成功)。
9
+ * - 固定前缀(system + 工具表)已超过预算:摘要无济于事,直接告警、不再尝试(`prefix_overflow`,
10
+ * 由调用方每次检查时更新)。
11
+ * - 「nothing to compact」不计失败(调用方不调 `recordSummary`)。
7
12
  * - 溢出恢复:压缩后估算仍 > 0.8 × window → 不重试。
8
13
  */
9
- export const MAX_SUMMARIES_PER_RUN = 1;
10
- export const MAX_CONSECUTIVE_FAILURES = 2;
14
+ export const MAX_CONSECUTIVE_FAILURES = 3;
15
+ /** 上一次摘要后不到这么多回合又需要摘要,记一次快速回填。 */
16
+ export const RAPID_REFILL_TURNS = 3;
17
+ export const MAX_RAPID_REFILLS = 3;
11
18
  export const RETRY_AFTER_COMPACTION_RATIO = 0.8;
12
19
  export class CompactionBreaker {
13
- summariesThisRun = 0;
14
20
  consecutiveFailures = 0;
21
+ rapidRefills = 0;
22
+ turn = 0;
23
+ lastSummaryTurn;
24
+ prefixOverflow = false;
15
25
  enabled;
16
26
  contextWindow;
17
27
  constructor(enabled, contextWindow) {
@@ -22,15 +32,23 @@ export class CompactionBreaker {
22
32
  this.enabled = enabled;
23
33
  this.contextWindow = contextWindow;
24
34
  }
35
+ /** 连续失败或快速回填跳闸(溢出恢复也不再尝试)。 */
25
36
  get tripped() {
26
- return this.consecutiveFailures >= MAX_CONSECUTIVE_FAILURES;
37
+ return (this.consecutiveFailures >= MAX_CONSECUTIVE_FAILURES || this.rapidRefills >= MAX_RAPID_REFILLS);
27
38
  }
28
- /** 自动压缩整体是否开启(不看本 run 计数)。 */
39
+ /** 自动压缩整体是否开启。 */
29
40
  get autoEnabled() {
30
41
  return this.enabled && this.contextWindow !== undefined && !this.tripped;
31
42
  }
32
- startRun() {
33
- this.summariesThisRun = 0;
43
+ /** 新 run 开始(会话在 agent_start 时调用);不再重置任何计数,保留以兼容调用点。 */
44
+ startRun() { }
45
+ /** 每次请求前的阈值检查调用一次:回合计数(快速回填按它判断)。 */
46
+ tick() {
47
+ this.turn++;
48
+ }
49
+ /** 固定前缀是否已超预算(调用方每次准备摘要前更新)。 */
50
+ setPrefixOverflow(overflow) {
51
+ this.prefixOverflow = overflow;
34
52
  }
35
53
  /** 自动档二能否执行;不能则给出原因。 */
36
54
  blockReason() {
@@ -38,23 +56,35 @@ export class CompactionBreaker {
38
56
  return "disabled";
39
57
  if (this.contextWindow === undefined)
40
58
  return "no_window";
41
- if (this.tripped)
59
+ if (this.consecutiveFailures >= MAX_CONSECUTIVE_FAILURES)
42
60
  return "tripped";
43
- if (this.summariesThisRun >= MAX_SUMMARIES_PER_RUN)
44
- return "run_limit";
61
+ if (this.rapidRefills >= MAX_RAPID_REFILLS)
62
+ return "rapid_refill";
63
+ if (this.prefixOverflow)
64
+ return "prefix_overflow";
45
65
  return undefined;
46
66
  }
47
67
  canSummarize() {
48
68
  return this.blockReason() === undefined;
49
69
  }
50
70
  recordSummary(success) {
51
- this.summariesThisRun++;
52
- this.consecutiveFailures = success ? 0 : this.consecutiveFailures + 1;
71
+ if (!success) {
72
+ this.consecutiveFailures++;
73
+ return;
74
+ }
75
+ this.consecutiveFailures = 0;
76
+ const last = this.lastSummaryTurn;
77
+ if (last !== undefined && this.turn - last < RAPID_REFILL_TURNS)
78
+ this.rapidRefills++;
79
+ else
80
+ this.rapidRefills = 0;
81
+ this.lastSummaryTurn = this.turn;
53
82
  }
54
- /** 手动压缩成功等场景:清零失败计数。 */
83
+ /** 手动压缩成功等场景:清零全部计数。 */
55
84
  reset() {
56
85
  this.consecutiveFailures = 0;
57
- this.summariesThisRun = 0;
86
+ this.rapidRefills = 0;
87
+ this.lastSummaryTurn = undefined;
58
88
  }
59
89
  /** 溢出恢复后是否值得重试。 */
60
90
  shouldRetryAfterCompaction(tokensAfter) {
@@ -2,15 +2,23 @@
2
2
  * 上下文 token 估算(设计 §9「估算」)。[B2]
3
3
  *
4
4
  * `contextTokens` = 最后一条非 error / aborted 助手消息的 `totalTokens`(缺则
5
- * `input + output + cacheRead + cacheWrite`,**含 output**)+ 其后消息的估算(字符 / 4,图片 1 600)。
5
+ * `input + output + cacheRead + cacheWrite`,**含 output**)+ 其后消息的估算(图片 1 600)。
6
6
  * 若该 usage 之后活动分支上出现过 `context_edit` 或 `compaction`,usage 不再可信,按投影全量重估。
7
+ *
8
+ * [W5-H1] 文本估算按脚本区分(wave5 D28 / C10):CJK 统一表意文字(含扩展区与兼容区)、假名、
9
+ * 谚文、CJK 符号与全角形式每字 1 token,其余字符合计 / 4 向上取整。「字符 / 4」对中文低估 3–4 倍,
10
+ * 中文会话会晚触发直至溢出;所有阈值(档一、档二、保留区)都用这个口径。
7
11
  */
8
- import type { Usage } from "../ai/types.js";
12
+ import type { ContentBlock, Usage } from "../ai/types.js";
9
13
  import type { ContextItem } from "../session/projection.js";
10
14
  import type { AgentMessage, SessionEntry } from "../session/types.js";
11
15
  export declare const IMAGE_TOKENS = 1600;
16
+ /** 文本的 token 估算:CJK / 假名 / 谚文每字 1,其余字符 / 4(向上取整)。 */
17
+ export declare function estimateTextTokens(text: string): number;
12
18
  export declare function calculateContextTokens(usage: Usage): number;
13
- /** 单条消息的估算(字符 / 4 向上取整,图片每张 1 600)。 */
19
+ /** 内容的估算(文本按脚本,图片每张 1 600)。 */
20
+ export declare function estimateContentTokens(content: string | readonly ContentBlock[]): number;
21
+ /** 单条消息的估算(文本按脚本区分,图片每张 1 600)。 */
14
22
  export declare function estimateMessageTokens(message: AgentMessage): number;
15
23
  export declare function estimateMessagesTokens(messages: readonly AgentMessage[]): number;
16
24
  export interface ContextEstimate {