@armadra/agent 0.7.6 → 0.8.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 (516) hide show
  1. package/CHANGELOG.md +51 -31
  2. package/CHANGELOG.zh-CN.md +68 -48
  3. package/README.md +162 -204
  4. package/README.zh-CN.md +150 -199
  5. package/dist/acp.d.ts +1 -1
  6. package/dist/acp.js +1 -1
  7. package/dist/agent/limits.d.ts +1 -1
  8. package/dist/agent/limits.js +1 -1
  9. package/dist/agent/loop-guard.d.ts +1 -1
  10. package/dist/agent/loop-guard.js +1 -1
  11. package/dist/agent/prompt-rules.d.ts +1 -1
  12. package/dist/agent/prompt-rules.js +1 -1
  13. package/dist/agent/reminders.d.ts +1 -1
  14. package/dist/agent/reminders.js +1 -1
  15. package/dist/agent/session-cache-key.d.ts +1 -1
  16. package/dist/agent/session-cache-key.js +1 -1
  17. package/dist/agent/session-extensions.d.ts +1 -1
  18. package/dist/agent/session-extensions.js +1 -1
  19. package/dist/agent/session-images.d.ts +1 -1
  20. package/dist/agent/session-images.js +1 -1
  21. package/dist/agent/session-plan.d.ts +1 -1
  22. package/dist/agent/session-plan.js +1 -1
  23. package/dist/agent/session-rewind.d.ts +1 -1
  24. package/dist/agent/session-rewind.js +1 -1
  25. package/dist/agent/session-settings.d.ts +1 -1
  26. package/dist/agent/session-settings.js +1 -1
  27. package/dist/agent/session-subagent.d.ts +1 -1
  28. package/dist/agent/session-subagent.js +1 -1
  29. package/dist/agent/session-telemetry.d.ts +1 -1
  30. package/dist/agent/session-telemetry.js +1 -1
  31. package/dist/agent/session-trace-writer.d.ts +1 -1
  32. package/dist/agent/session-trace-writer.js +1 -1
  33. package/dist/agent/session.js +1 -1
  34. package/dist/agent/subagent-background.d.ts +1 -1
  35. package/dist/agent/subagent-background.js +1 -1
  36. package/dist/agent/subagent-direct.d.ts +1 -1
  37. package/dist/agent/subagent-direct.js +1 -1
  38. package/dist/agent/subagent-fork.d.ts +1 -1
  39. package/dist/agent/subagent-fork.js +1 -1
  40. package/dist/agent/subagent-registry.d.ts +1 -1
  41. package/dist/agent/subagent-registry.js +1 -1
  42. package/dist/agent/system-prompt.js +1 -1
  43. package/dist/agent/tool-availability.d.ts +1 -1
  44. package/dist/agent/tool-availability.js +1 -1
  45. package/dist/agent/types-w5.d.ts +2 -2
  46. package/dist/agent/types-w5.js +1 -1
  47. package/dist/agent/types-w6.d.ts +1 -1
  48. package/dist/agent/types-w6.js +1 -1
  49. package/dist/agent/types.d.ts +1 -1
  50. package/dist/agent/worktree.d.ts +1 -1
  51. package/dist/agent/worktree.js +1 -1
  52. package/dist/agents/builtin.d.ts +1 -1
  53. package/dist/agents/builtin.js +1 -1
  54. package/dist/agents/catalog.d.ts +1 -1
  55. package/dist/agents/catalog.js +1 -1
  56. package/dist/agents/discover.d.ts +1 -1
  57. package/dist/agents/discover.js +1 -1
  58. package/dist/agents/external.d.ts +1 -1
  59. package/dist/agents/external.js +1 -1
  60. package/dist/agents/parse.d.ts +1 -1
  61. package/dist/agents/parse.js +1 -1
  62. package/dist/agents/result.d.ts +1 -1
  63. package/dist/agents/result.js +2 -2
  64. package/dist/agents/task-record.d.ts +3 -3
  65. package/dist/agents/task-record.js +2 -2
  66. package/dist/agents/types.d.ts +1 -1
  67. package/dist/agents/types.js +1 -1
  68. package/dist/ai/apis/anthropic-compat.d.ts +2 -2
  69. package/dist/ai/apis/anthropic-compat.js +2 -2
  70. package/dist/ai/apis/cache-params.d.ts +1 -1
  71. package/dist/ai/apis/cache-params.js +1 -1
  72. package/dist/ai/apis/chatgpt-backend.d.ts +4 -2
  73. package/dist/ai/apis/chatgpt-backend.js +11 -2
  74. package/dist/ai/apis/chatgpt-rate-limits.d.ts +1 -1
  75. package/dist/ai/apis/chatgpt-rate-limits.js +1 -1
  76. package/dist/ai/apis/max-tokens.d.ts +1 -1
  77. package/dist/ai/apis/max-tokens.js +1 -1
  78. package/dist/ai/apis/shared.d.ts +1 -1
  79. package/dist/ai/apis/shared.js +1 -1
  80. package/dist/ai/image-intern.d.ts +2 -2
  81. package/dist/ai/image-intern.js +1 -1
  82. package/dist/ai/image-limits.d.ts +1 -1
  83. package/dist/ai/image-limits.js +1 -1
  84. package/dist/ai/json-body.d.ts +1 -1
  85. package/dist/ai/json-body.js +1 -1
  86. package/dist/ai/providers/builtin.d.ts +2 -2
  87. package/dist/ai/providers/builtin.js +4 -4
  88. package/dist/ai/providers/catalog.d.ts +2 -2
  89. package/dist/ai/providers/catalog.js +1 -1
  90. package/dist/ai/providers/channels.d.ts +1 -1
  91. package/dist/ai/providers/channels.js +1 -1
  92. package/dist/ai/providers/enrich.d.ts +1 -1
  93. package/dist/ai/providers/enrich.js +1 -1
  94. package/dist/ai/providers/models-dev-cache.d.ts +1 -1
  95. package/dist/ai/providers/models-dev-cache.js +1 -1
  96. package/dist/ai/providers/models-dev-data.d.ts +1 -1
  97. package/dist/ai/providers/models-dev-data.js +1 -1
  98. package/dist/ai/providers/models-dev-snapshot.d.ts +1 -1
  99. package/dist/ai/providers/models-dev-snapshot.js +1 -1
  100. package/dist/ai/providers/models-dev.d.ts +4 -4
  101. package/dist/ai/providers/models-dev.js +3 -3
  102. package/dist/ai/types.d.ts +2 -2
  103. package/dist/ai/types.js +1 -1
  104. package/dist/auth/chatgpt/cli.d.ts +1 -1
  105. package/dist/auth/chatgpt/cli.js +1 -1
  106. package/dist/auth/chatgpt/host-id.d.ts +1 -1
  107. package/dist/auth/chatgpt/host-id.js +1 -1
  108. package/dist/auth/chatgpt/login.d.ts +1 -1
  109. package/dist/auth/chatgpt/login.js +1 -1
  110. package/dist/auth/chatgpt/presets.d.ts +1 -1
  111. package/dist/auth/chatgpt/presets.js +1 -1
  112. package/dist/auth/oauth/callback-server.d.ts +1 -1
  113. package/dist/auth/oauth/callback-server.js +1 -1
  114. package/dist/auth/oauth/flows.d.ts +1 -1
  115. package/dist/auth/oauth/flows.js +1 -1
  116. package/dist/auth/oauth/oidc.d.ts +1 -1
  117. package/dist/auth/oauth/oidc.js +1 -1
  118. package/dist/auth/oauth/pkce.d.ts +1 -1
  119. package/dist/auth/oauth/pkce.js +1 -1
  120. package/dist/auth/oauth/refresh.d.ts +1 -1
  121. package/dist/auth/oauth/refresh.js +1 -1
  122. package/dist/auth/oauth/token-client.d.ts +1 -1
  123. package/dist/auth/oauth/token-client.js +1 -1
  124. package/dist/auth/oauth/token-store.d.ts +1 -1
  125. package/dist/auth/oauth/token-store.js +1 -1
  126. package/dist/auth/testing/fake-oauth.d.ts +1 -1
  127. package/dist/auth/testing/fake-oauth.js +1 -1
  128. package/dist/bundle/ama.cjs +1041 -359
  129. package/dist/checkpoints/blobs.d.ts +1 -1
  130. package/dist/checkpoints/blobs.js +1 -1
  131. package/dist/checkpoints/gc.d.ts +1 -1
  132. package/dist/checkpoints/gc.js +1 -1
  133. package/dist/checkpoints/git-head.d.ts +1 -1
  134. package/dist/checkpoints/git-head.js +1 -1
  135. package/dist/checkpoints/index.d.ts +1 -1
  136. package/dist/checkpoints/index.js +1 -1
  137. package/dist/checkpoints/replay.d.ts +1 -1
  138. package/dist/checkpoints/replay.js +1 -1
  139. package/dist/checkpoints/restore.d.ts +1 -1
  140. package/dist/checkpoints/restore.js +1 -1
  141. package/dist/checkpoints/settings.d.ts +1 -1
  142. package/dist/checkpoints/settings.js +1 -1
  143. package/dist/checkpoints/shadow-git.d.ts +1 -1
  144. package/dist/checkpoints/shadow-git.js +1 -1
  145. package/dist/checkpoints/shadow-restore.d.ts +1 -1
  146. package/dist/checkpoints/shadow-restore.js +1 -1
  147. package/dist/checkpoints/tracker.d.ts +1 -1
  148. package/dist/checkpoints/tracker.js +1 -1
  149. package/dist/checkpoints/types.d.ts +1 -1
  150. package/dist/checkpoints/types.js +1 -1
  151. package/dist/cli/args.d.ts +2 -2
  152. package/dist/cli/args.js +1 -1
  153. package/dist/cli/bootstrap.js +1 -1
  154. package/dist/cli/choice-prompt.d.ts +1 -1
  155. package/dist/cli/choice-prompt.js +1 -1
  156. package/dist/cli/codemode-notice.d.ts +1 -1
  157. package/dist/cli/codemode-notice.js +1 -1
  158. package/dist/cli/compose-agents.d.ts +1 -1
  159. package/dist/cli/compose-agents.js +1 -1
  160. package/dist/cli/compose-extensions.d.ts +1 -1
  161. package/dist/cli/compose-extensions.js +1 -1
  162. package/dist/cli/compose-memory.d.ts +1 -1
  163. package/dist/cli/compose-memory.js +1 -1
  164. package/dist/cli/compose-providers.d.ts +1 -1
  165. package/dist/cli/compose-providers.js +1 -1
  166. package/dist/cli/compose-request.d.ts +1 -1
  167. package/dist/cli/compose-request.js +1 -1
  168. package/dist/cli/from-prompt.d.ts +1 -1
  169. package/dist/cli/from-prompt.js +1 -1
  170. package/dist/cli/main.d.ts +1 -1
  171. package/dist/cli/main.js +1 -1
  172. package/dist/cli/subcommands/auth.d.ts +1 -1
  173. package/dist/cli/subcommands/auth.js +1 -1
  174. package/dist/cli/subcommands/config-set.d.ts +1 -1
  175. package/dist/cli/subcommands/config-set.js +1 -1
  176. package/dist/cli/subcommands/doctor.js +1 -1
  177. package/dist/cli/subcommands/init.d.ts +1 -1
  178. package/dist/cli/subcommands/init.js +1 -1
  179. package/dist/cli/subcommands/memory.d.ts +1 -1
  180. package/dist/cli/subcommands/memory.js +1 -1
  181. package/dist/cli/subcommands/models.js +1 -1
  182. package/dist/cli/subcommands/providers-list.d.ts +1 -1
  183. package/dist/cli/subcommands/providers-list.js +1 -1
  184. package/dist/cli/subcommands/providers-plan.d.ts +1 -1
  185. package/dist/cli/subcommands/providers-plan.js +1 -1
  186. package/dist/cli/subcommands/providers.d.ts +1 -1
  187. package/dist/cli/subcommands/providers.js +1 -1
  188. package/dist/cli/subcommands/sessions-export.d.ts +1 -1
  189. package/dist/cli/subcommands/sessions-export.js +1 -1
  190. package/dist/cli/subcommands/sessions-trace.d.ts +1 -1
  191. package/dist/cli/subcommands/sessions-trace.js +1 -1
  192. package/dist/cli/subcommands/sessions.d.ts +1 -1
  193. package/dist/cli/subcommands/sessions.js +1 -1
  194. package/dist/cli/subcommands/stats.d.ts +1 -1
  195. package/dist/cli/subcommands/stats.js +1 -1
  196. package/dist/codemode/capability.d.ts +1 -1
  197. package/dist/codemode/capability.js +1 -1
  198. package/dist/codemode/host-side.d.ts +2 -2
  199. package/dist/codemode/host-side.js +2 -2
  200. package/dist/compaction/image-budget.d.ts +1 -1
  201. package/dist/compaction/image-budget.js +1 -1
  202. package/dist/config/edit.d.ts +1 -1
  203. package/dist/config/edit.js +1 -1
  204. package/dist/config/init.d.ts +1 -1
  205. package/dist/config/init.js +1 -1
  206. package/dist/config/json-schema.d.ts +2 -2
  207. package/dist/config/json-schema.js +2 -2
  208. package/dist/config/schema-w5.d.ts +1 -1
  209. package/dist/config/schema-w5.js +1 -1
  210. package/dist/config/schema-w6.d.ts +1 -1
  211. package/dist/config/schema-w6.js +1 -1
  212. package/dist/config/settings-registry.d.ts +1 -1
  213. package/dist/config/settings-registry.js +1 -1
  214. package/dist/config/types-w5.d.ts +2 -2
  215. package/dist/config/types-w5.js +2 -2
  216. package/dist/config/types-w6.d.ts +5 -5
  217. package/dist/config/types-w6.js +1 -1
  218. package/dist/config/types.d.ts +6 -6
  219. package/dist/config/types.js +1 -1
  220. package/dist/drivers/acp/client.d.ts +1 -1
  221. package/dist/drivers/acp/client.js +1 -1
  222. package/dist/drivers/acp/driver.d.ts +23 -2
  223. package/dist/drivers/acp/driver.js +60 -6
  224. package/dist/drivers/acp/testing/fake-agent.d.ts +1 -1
  225. package/dist/drivers/acp/testing/fake-agent.js +1 -1
  226. package/dist/drivers/acp/types.d.ts +1 -1
  227. package/dist/drivers/acp/types.js +1 -1
  228. package/dist/drivers/agents.d.ts +1 -1
  229. package/dist/drivers/agents.js +4 -1
  230. package/dist/drivers/base.d.ts +1 -1
  231. package/dist/drivers/base.js +1 -1
  232. package/dist/drivers/catalog.d.ts +3 -1
  233. package/dist/drivers/catalog.js +95 -5
  234. package/dist/drivers/env.d.ts +1 -1
  235. package/dist/drivers/env.js +1 -1
  236. package/dist/drivers/host-runners.d.ts +1 -1
  237. package/dist/drivers/host-runners.js +1 -1
  238. package/dist/drivers/jsonrpc.d.ts +1 -1
  239. package/dist/drivers/jsonrpc.js +1 -1
  240. package/dist/drivers/native/claude-normalize.d.ts +9 -1
  241. package/dist/drivers/native/claude-normalize.js +28 -1
  242. package/dist/drivers/native/claude-stream.d.ts +1 -1
  243. package/dist/drivers/native/claude-stream.js +17 -2
  244. package/dist/drivers/native/codex-app-server.d.ts +1 -1
  245. package/dist/drivers/native/codex-app-server.js +5 -3
  246. package/dist/drivers/native/codex-normalize.d.ts +1 -1
  247. package/dist/drivers/native/codex-normalize.js +1 -1
  248. package/dist/drivers/native/oneshot.d.ts +1 -1
  249. package/dist/drivers/native/oneshot.js +13 -3
  250. package/dist/drivers/native/pi-gate.d.ts +19 -0
  251. package/dist/drivers/native/pi-gate.js +39 -0
  252. package/dist/drivers/native/pi-rpc.d.ts +29 -0
  253. package/dist/drivers/native/pi-rpc.js +483 -0
  254. package/dist/drivers/permissions.d.ts +1 -1
  255. package/dist/drivers/permissions.js +1 -1
  256. package/dist/drivers/pids.d.ts +1 -1
  257. package/dist/drivers/pids.js +1 -1
  258. package/dist/drivers/pool.d.ts +1 -1
  259. package/dist/drivers/pool.js +1 -1
  260. package/dist/drivers/probe.d.ts +1 -1
  261. package/dist/drivers/probe.js +1 -1
  262. package/dist/drivers/process.d.ts +1 -1
  263. package/dist/drivers/process.js +1 -1
  264. package/dist/drivers/runner.d.ts +1 -1
  265. package/dist/drivers/runner.js +2 -1
  266. package/dist/drivers/store.d.ts +1 -1
  267. package/dist/drivers/store.js +1 -1
  268. package/dist/drivers/types.d.ts +2 -2
  269. package/dist/drivers/types.js +1 -1
  270. package/dist/git/info.d.ts +1 -1
  271. package/dist/git/info.js +1 -1
  272. package/dist/host/api-impl.d.ts +1 -1
  273. package/dist/host/api-impl.js +1 -1
  274. package/dist/host/types.d.ts +2 -2
  275. package/dist/i18n/catalog.d.ts +5 -2
  276. package/dist/i18n/catalog.js +2 -2
  277. package/dist/i18n/format.d.ts +1 -1
  278. package/dist/i18n/format.js +1 -1
  279. package/dist/i18n/index.d.ts +1 -1
  280. package/dist/i18n/index.js +1 -1
  281. package/dist/i18n/messages/acp.d.ts +1 -1
  282. package/dist/i18n/messages/acp.js +1 -1
  283. package/dist/i18n/messages/agents.d.ts +1 -1
  284. package/dist/i18n/messages/agents.js +1 -1
  285. package/dist/i18n/messages/approval.d.ts +1 -1
  286. package/dist/i18n/messages/approval.js +1 -1
  287. package/dist/i18n/messages/auth.d.ts +3 -1
  288. package/dist/i18n/messages/auth.js +3 -1
  289. package/dist/i18n/messages/cli.d.ts +1 -1
  290. package/dist/i18n/messages/cli.js +1 -1
  291. package/dist/i18n/messages/config-keys.js +12 -12
  292. package/dist/i18n/messages/config.d.ts +1 -1
  293. package/dist/i18n/messages/config.js +3 -3
  294. package/dist/i18n/messages/drivers.d.ts +5 -1
  295. package/dist/i18n/messages/drivers.js +5 -1
  296. package/dist/i18n/messages/errors.d.ts +1 -1
  297. package/dist/i18n/messages/errors.js +1 -1
  298. package/dist/i18n/messages/interactive-line.d.ts +1 -1
  299. package/dist/i18n/messages/interactive-line.js +1 -1
  300. package/dist/i18n/messages/interactive-startup.d.ts +1 -1
  301. package/dist/i18n/messages/interactive-startup.js +1 -1
  302. package/dist/i18n/messages/interactive-view.d.ts +1 -1
  303. package/dist/i18n/messages/interactive-view.js +1 -1
  304. package/dist/i18n/messages/interactive.d.ts +1 -1
  305. package/dist/i18n/messages/interactive.js +1 -1
  306. package/dist/i18n/messages/memory.d.ts +1 -1
  307. package/dist/i18n/messages/memory.js +1 -1
  308. package/dist/i18n/messages/panels.d.ts +1 -1
  309. package/dist/i18n/messages/panels.js +1 -1
  310. package/dist/i18n/messages/permissions.d.ts +1 -1
  311. package/dist/i18n/messages/permissions.js +1 -1
  312. package/dist/i18n/messages/plan.d.ts +1 -1
  313. package/dist/i18n/messages/plan.js +1 -1
  314. package/dist/i18n/messages/print.d.ts +2 -2
  315. package/dist/i18n/messages/print.js +2 -2
  316. package/dist/i18n/messages/report-context.d.ts +1 -1
  317. package/dist/i18n/messages/report-context.js +1 -1
  318. package/dist/i18n/messages/report.d.ts +1 -1
  319. package/dist/i18n/messages/report.js +1 -1
  320. package/dist/i18n/messages/rewind.d.ts +1 -1
  321. package/dist/i18n/messages/rewind.js +1 -1
  322. package/dist/i18n/messages/session.d.ts +1 -1
  323. package/dist/i18n/messages/session.js +1 -1
  324. package/dist/i18n/messages/settings.d.ts +1 -1
  325. package/dist/i18n/messages/settings.js +1 -1
  326. package/dist/i18n/messages/subcommands.d.ts +1 -1
  327. package/dist/i18n/messages/subcommands.js +1 -1
  328. package/dist/i18n/messages/trace.d.ts +1 -1
  329. package/dist/i18n/messages/trace.js +1 -1
  330. package/dist/i18n/types.d.ts +1 -1
  331. package/dist/i18n/types.js +1 -1
  332. package/dist/memory/frontmatter.d.ts +1 -1
  333. package/dist/memory/frontmatter.js +1 -1
  334. package/dist/memory/index.d.ts +1 -1
  335. package/dist/memory/index.js +1 -1
  336. package/dist/memory/lock.d.ts +1 -1
  337. package/dist/memory/lock.js +1 -1
  338. package/dist/memory/paths.d.ts +1 -1
  339. package/dist/memory/paths.js +1 -1
  340. package/dist/memory/runtime.d.ts +1 -1
  341. package/dist/memory/runtime.js +1 -1
  342. package/dist/memory/secrets.d.ts +1 -1
  343. package/dist/memory/secrets.js +1 -1
  344. package/dist/memory/section.d.ts +1 -1
  345. package/dist/memory/section.js +1 -1
  346. package/dist/memory/store.d.ts +1 -1
  347. package/dist/memory/store.js +1 -1
  348. package/dist/memory/tool.d.ts +1 -1
  349. package/dist/memory/tool.js +1 -1
  350. package/dist/modes/acp/acp-auth-gate.d.ts +1 -1
  351. package/dist/modes/acp/acp-auth-gate.js +1 -1
  352. package/dist/modes/acp/acp-config.d.ts +1 -1
  353. package/dist/modes/acp/acp-config.js +1 -1
  354. package/dist/modes/acp/acp-connection.d.ts +1 -1
  355. package/dist/modes/acp/acp-connection.js +1 -1
  356. package/dist/modes/acp/acp-events.d.ts +1 -1
  357. package/dist/modes/acp/acp-events.js +1 -1
  358. package/dist/modes/acp/acp-mode.d.ts +1 -1
  359. package/dist/modes/acp/acp-mode.js +1 -1
  360. package/dist/modes/acp/acp-server.d.ts +2 -2
  361. package/dist/modes/acp/acp-server.js +2 -2
  362. package/dist/modes/acp/acp-sessions.d.ts +2 -2
  363. package/dist/modes/acp/acp-sessions.js +2 -2
  364. package/dist/modes/acp/acp-tool-text.d.ts +1 -1
  365. package/dist/modes/acp/acp-tool-text.js +1 -1
  366. package/dist/modes/commands-core.js +1 -1
  367. package/dist/modes/image-input.d.ts +1 -1
  368. package/dist/modes/image-input.js +1 -1
  369. package/dist/modes/interactive/agent-bar.d.ts +1 -1
  370. package/dist/modes/interactive/agent-bar.js +1 -1
  371. package/dist/modes/interactive/agent-transcript.d.ts +1 -1
  372. package/dist/modes/interactive/agent-transcript.js +1 -1
  373. package/dist/modes/interactive/agent-view.d.ts +1 -1
  374. package/dist/modes/interactive/agent-view.js +1 -1
  375. package/dist/modes/interactive/approval-dock.d.ts +1 -1
  376. package/dist/modes/interactive/approval-dock.js +1 -1
  377. package/dist/modes/interactive/config-panel.d.ts +1 -1
  378. package/dist/modes/interactive/config-panel.js +1 -1
  379. package/dist/modes/interactive/config-ui.d.ts +1 -1
  380. package/dist/modes/interactive/config-ui.js +1 -1
  381. package/dist/modes/interactive/memory-panel.d.ts +1 -1
  382. package/dist/modes/interactive/memory-panel.js +1 -1
  383. package/dist/modes/interactive/plan-command.d.ts +1 -1
  384. package/dist/modes/interactive/plan-command.js +1 -1
  385. package/dist/modes/interactive/plan-dialog.d.ts +1 -1
  386. package/dist/modes/interactive/plan-dialog.js +1 -1
  387. package/dist/modes/interactive/plan-flow.d.ts +1 -1
  388. package/dist/modes/interactive/plan-flow.js +1 -1
  389. package/dist/modes/interactive/subagent-view.d.ts +1 -1
  390. package/dist/modes/interactive/subagent-view.js +1 -1
  391. package/dist/modes/interactive/task-background.d.ts +1 -1
  392. package/dist/modes/interactive/task-background.js +1 -1
  393. package/dist/modes/interactive/trace-view.d.ts +1 -1
  394. package/dist/modes/interactive/trace-view.js +1 -1
  395. package/dist/modes/print/json-event.d.ts +1 -1
  396. package/dist/modes/print/json-event.js +2 -2
  397. package/dist/modes/print/print-mode.d.ts +1 -1
  398. package/dist/modes/print/print-mode.js +1 -1
  399. package/dist/modes/print/search-hint.d.ts +1 -1
  400. package/dist/modes/print/search-hint.js +1 -1
  401. package/dist/modes/rpc/commands.js +2 -2
  402. package/dist/permissions/auto-safe.d.ts +1 -1
  403. package/dist/permissions/auto-safe.js +1 -1
  404. package/dist/permissions/bypass.d.ts +1 -1
  405. package/dist/permissions/bypass.js +1 -1
  406. package/dist/permissions/classifier.d.ts +1 -1
  407. package/dist/permissions/classifier.js +1 -1
  408. package/dist/permissions/memory-class.d.ts +1 -1
  409. package/dist/permissions/memory-class.js +1 -1
  410. package/dist/permissions/pipeline.d.ts +2 -2
  411. package/dist/permissions/pipeline.js +2 -2
  412. package/dist/permissions/protected.d.ts +1 -1
  413. package/dist/permissions/protected.js +1 -1
  414. package/dist/permissions/readonly-bash.d.ts +1 -1
  415. package/dist/permissions/readonly-bash.js +1 -1
  416. package/dist/permissions/types.d.ts +2 -2
  417. package/dist/plan/done-markers.d.ts +1 -1
  418. package/dist/plan/done-markers.js +1 -1
  419. package/dist/plan/extract.d.ts +1 -1
  420. package/dist/plan/extract.js +1 -1
  421. package/dist/plan/prompts.d.ts +1 -1
  422. package/dist/plan/prompts.js +1 -1
  423. package/dist/plan/store.d.ts +1 -1
  424. package/dist/plan/store.js +1 -1
  425. package/dist/rpc.d.ts +3 -3
  426. package/dist/rpc.js +3 -3
  427. package/dist/sandbox/bash.d.ts +1 -1
  428. package/dist/sandbox/bash.js +1 -1
  429. package/dist/sandbox/detect.d.ts +1 -1
  430. package/dist/sandbox/detect.js +1 -1
  431. package/dist/sandbox/index.d.ts +1 -1
  432. package/dist/sandbox/index.js +1 -1
  433. package/dist/sandbox/profile.d.ts +1 -1
  434. package/dist/sandbox/profile.js +1 -1
  435. package/dist/sandbox/wrap.d.ts +1 -1
  436. package/dist/sandbox/wrap.js +1 -1
  437. package/dist/sdk.d.ts +3 -3
  438. package/dist/sdk.js +2 -2
  439. package/dist/session/line-reader.d.ts +1 -1
  440. package/dist/session/line-reader.js +1 -1
  441. package/dist/session/list.d.ts +1 -1
  442. package/dist/session/list.js +1 -1
  443. package/dist/session/migrate.d.ts +1 -1
  444. package/dist/session/migrate.js +1 -1
  445. package/dist/session/store.d.ts +1 -1
  446. package/dist/session/store.js +1 -1
  447. package/dist/skills/builtin.js +2 -2
  448. package/dist/tools/background-jobs.d.ts +1 -1
  449. package/dist/tools/background-jobs.js +1 -1
  450. package/dist/tools/clipboard-image.d.ts +1 -1
  451. package/dist/tools/clipboard-image.js +1 -1
  452. package/dist/tools/edit.d.ts +1 -1
  453. package/dist/tools/edit.js +1 -1
  454. package/dist/tools/grep.d.ts +1 -1
  455. package/dist/tools/grep.js +1 -1
  456. package/dist/tools/image-resize.d.ts +1 -1
  457. package/dist/tools/image-resize.js +1 -1
  458. package/dist/tools/read-lines.d.ts +1 -1
  459. package/dist/tools/read-lines.js +1 -1
  460. package/dist/tools/read.d.ts +1 -1
  461. package/dist/tools/read.js +1 -1
  462. package/dist/tools/task-ctl.d.ts +1 -1
  463. package/dist/tools/task-ctl.js +1 -1
  464. package/dist/tools/task.d.ts +2 -2
  465. package/dist/tools/task.js +2 -2
  466. package/dist/tools/types.d.ts +3 -3
  467. package/dist/tools/types.js +1 -1
  468. package/dist/trace/build.d.ts +1 -1
  469. package/dist/trace/build.js +1 -1
  470. package/dist/trace/detail.d.ts +1 -1
  471. package/dist/trace/detail.js +1 -1
  472. package/dist/trace/flatten.d.ts +1 -1
  473. package/dist/trace/flatten.js +1 -1
  474. package/dist/trace/format.d.ts +1 -1
  475. package/dist/trace/format.js +1 -1
  476. package/dist/trace/html-template.d.ts +1 -1
  477. package/dist/trace/html-template.js +1 -1
  478. package/dist/trace/html.d.ts +1 -1
  479. package/dist/trace/html.js +1 -1
  480. package/dist/trace/query-session.d.ts +1 -1
  481. package/dist/trace/query-session.js +1 -1
  482. package/dist/trace/query.d.ts +1 -1
  483. package/dist/trace/query.js +1 -1
  484. package/dist/trace/types.d.ts +1 -1
  485. package/dist/trace/types.js +1 -1
  486. package/dist/tui/components/settings-list.d.ts +1 -1
  487. package/dist/tui/components/settings-list.js +1 -1
  488. package/docs/README.md +85 -0
  489. package/docs/assets/ama-wordmark-dark.svg +37 -0
  490. package/docs/assets/ama-wordmark-light.svg +37 -0
  491. package/docs/en/README.md +39 -0
  492. package/docs/en/{permissions.md → guides/permissions.md} +14 -14
  493. package/docs/en/{providers.md → guides/providers.md} +13 -12
  494. package/docs/en/{sessions.md → guides/sessions.md} +6 -6
  495. package/docs/en/{tui.md → guides/tui.md} +15 -15
  496. package/docs/en/{acp.md → reference/acp.md} +6 -6
  497. package/docs/en/{host-api.md → reference/host-api.md} +7 -7
  498. package/docs/en/{rpc.md → reference/rpc.md} +13 -13
  499. package/docs/{agents.md → guides/agents.md} +68 -23
  500. package/docs/{codemode.md → guides/codemode.md} +3 -3
  501. package/docs/{hooks.md → guides/hooks.md} +2 -2
  502. package/docs/guides/i18n.md +93 -0
  503. package/docs/{memory.md → guides/memory.md} +1 -1
  504. package/docs/{permissions.md → guides/permissions.md} +2 -2
  505. package/docs/{plan.md → guides/plan.md} +4 -4
  506. package/docs/{providers.md → guides/providers.md} +11 -10
  507. package/docs/{sessions.md → guides/sessions.md} +5 -5
  508. package/docs/{tui.md → guides/tui.md} +8 -8
  509. package/docs/{acp.md → reference/acp.md} +5 -5
  510. package/docs/{host-api.md → reference/host-api.md} +4 -4
  511. package/docs/{rpc.md → reference/rpc.md} +11 -11
  512. package/docs/{session-format.md → reference/session-format.md} +7 -7
  513. package/package.json +12 -23
  514. package/docs/rewind-plan.md +0 -181
  515. package/docs/tui-design.md +0 -764
  516. /package/docs/{sandbox.md → guides/sandbox.md} +0 -0
@@ -0,0 +1,483 @@
1
+ /**
2
+ * pi 原生驱动:`pi --mode rpc` 长驻进程(stdin 命令 / stdout 响应与事件,严格按 LF 分帧)。[#198]
3
+ *
4
+ * `pi --mode rpc --session-id <uuid> [--model <m>] -e <审批闸> [--tools read,grep,find,ls]`
5
+ * (新会话与续聊都用 `--session-id`:pi 找到同 id 的项目会话就续上,否则新建)。
6
+ *
7
+ * - 回合:`prompt` → 响应 `disposition`(`handled` 时没有运行,直接结束)→ 事件流 → `agent_settled`
8
+ * 结束(`aborted` 为真即中断);运行中追加用 `steer`;中断 `abort`(15 s 看门狗)。
9
+ * - 审批:pi 自己不问人,ama 以 `-e` 加载审批闸({@link PI_GATE_SOURCE}),只读内置工具以外的调用
10
+ * 经 `extension_ui_request{confirm, title: "ama-approval"}` 到这里:plan / allowlist 直接拒绝(并以
11
+ * `--tools` 只开只读工具),auto-edit / auto / full-auto 放行 `edit` / `write`,其余交给人(只交给人,
12
+ * 不代答)。其它扩展的对话框(select / input / editor / 别的 confirm)一律取消并提示。
13
+ * - 用量:assistant `message_end` 的 usage 累加(input 不含缓存命中,cost.total 是 pi 按价目表的估算);
14
+ * 回合结束后 `get_session_stats` 的 `contextUsage` 记上下文占用与窗口。
15
+ */
16
+ import { randomUUID } from "node:crypto";
17
+ import { resolve as resolvePath } from "node:path";
18
+ import { AmaError } from "../../errors.js";
19
+ import { createLineReader } from "../../modes/rpc/jsonl.js";
20
+ import { armCancelWatchdog, isReadOnlyMode, probeCandidate, spawnOf, } from "../base.js";
21
+ import { stderrHint } from "../process.js";
22
+ import { TurnCollector, oneLine } from "../turn.js";
23
+ import { PI_GATE_TITLE, PI_READ_ONLY_TOOLS, writePiGate } from "./pi-gate.js";
24
+ import { msg } from "../../i18n/index.js";
25
+ const DIALOG_METHODS = new Set(["select", "confirm", "input", "editor"]);
26
+ /** auto-edit 及更宽的模式下不问人的文件编辑工具。 */
27
+ const EDIT_TOOLS = new Set(["edit", "write"]);
28
+ export function piArgs(options, sessionId, gatePath) {
29
+ const args = ["--session-id", sessionId];
30
+ if (options.model !== undefined)
31
+ args.push("--model", options.model);
32
+ args.push("-e", gatePath);
33
+ if (isReadOnlyMode(options.mode))
34
+ args.push("--tools", PI_READ_ONLY_TOOLS.join(","));
35
+ return args;
36
+ }
37
+ export function piToolKind(tool) {
38
+ switch (tool) {
39
+ case "bash":
40
+ case "powershell":
41
+ return "execute";
42
+ case "edit":
43
+ case "write":
44
+ return "edit";
45
+ case "read":
46
+ return "read";
47
+ case "grep":
48
+ case "find":
49
+ case "ls":
50
+ return "search";
51
+ default:
52
+ return "other";
53
+ }
54
+ }
55
+ function piToolTitle(tool, input) {
56
+ if (typeof input["command"] === "string")
57
+ return `$ ${oneLine(input["command"], 100)}`;
58
+ if (typeof input["path"] === "string")
59
+ return `${tool} ${input["path"]}`;
60
+ if (typeof input["pattern"] === "string")
61
+ return `${tool} ${oneLine(input["pattern"], 80)}`;
62
+ return tool;
63
+ }
64
+ function textOf(message) {
65
+ const content = message["content"];
66
+ if (typeof content === "string")
67
+ return content;
68
+ if (!Array.isArray(content))
69
+ return "";
70
+ return content
71
+ .map((b) => (b["type"] === "text" && typeof b["text"] === "string" ? b["text"] : ""))
72
+ .join("");
73
+ }
74
+ export class PiRpcDriver {
75
+ agentId;
76
+ candidate;
77
+ deps;
78
+ kind = "pi-rpc";
79
+ constructor(agentId, candidate, deps = {}) {
80
+ this.agentId = agentId;
81
+ this.candidate = candidate;
82
+ this.deps = deps;
83
+ }
84
+ probe() {
85
+ return probeCandidate(this.candidate, this.deps);
86
+ }
87
+ async open(options) {
88
+ const probed = await probeCandidate(this.candidate, this.deps);
89
+ const sessionId = options.resume ?? randomUUID();
90
+ const gate = writePiGate();
91
+ const transport = spawnOf(this.deps)({
92
+ program: probed.path ?? this.candidate.program,
93
+ args: [...this.candidate.args, ...piArgs(options, sessionId, gate.path)],
94
+ cwd: options.cwd,
95
+ env: options.env,
96
+ });
97
+ const session = new PiSession(this.agentId, sessionId, transport, options, this.deps, () => gate.dispose());
98
+ if (probed.warning !== undefined)
99
+ session.notices.push(probed.warning);
100
+ try {
101
+ await session.start(options.signal);
102
+ }
103
+ catch (error) {
104
+ await session.close();
105
+ throw new AmaError("agent_start_failed", `${this.agentId}: failed to start (${error.message})${stderrHint(transport) !== "" ? `: ${stderrHint(transport)}` : ""}`, { cause: error });
106
+ }
107
+ return session;
108
+ }
109
+ }
110
+ class PiSession {
111
+ agentId;
112
+ id;
113
+ transport;
114
+ options;
115
+ deps;
116
+ dispose;
117
+ notices = [];
118
+ nextId = 1;
119
+ pending = new Map();
120
+ permissions = new Set();
121
+ turn;
122
+ hooks;
123
+ settle;
124
+ running;
125
+ usage = { input: 0, output: 0, cacheRead: 0, costUsd: 0, seen: false };
126
+ lastAssistant;
127
+ interrupted = false;
128
+ closed = false;
129
+ exited = false;
130
+ exitWaiters = new Set();
131
+ constructor(agentId, id, transport, options, deps, dispose) {
132
+ this.agentId = agentId;
133
+ this.id = id;
134
+ this.transport = transport;
135
+ this.options = options;
136
+ this.deps = deps;
137
+ this.dispose = dispose;
138
+ createLineReader(transport.stdout, (line) => this.onLine(line), () => this.onExit());
139
+ transport.stdin.on?.("error", () => undefined);
140
+ }
141
+ get sessionId() {
142
+ return this.id;
143
+ }
144
+ /** 握手:`get_state` 确认进程起来了,并取 pi 实际使用的会话 id。 */
145
+ async start(signal) {
146
+ const aborted = new Promise((_, reject) => {
147
+ if (signal.aborted)
148
+ reject(new Error("aborted"));
149
+ signal.addEventListener("abort", () => reject(new Error("aborted")), { once: true });
150
+ });
151
+ void aborted.catch(() => undefined);
152
+ const state = await Promise.race([this.request({ type: "get_state" }), aborted]);
153
+ const data = (state["data"] ?? {});
154
+ if (typeof data["sessionId"] === "string" && data["sessionId"] !== "")
155
+ this.id = data["sessionId"];
156
+ }
157
+ async prompt(content, hooks) {
158
+ if (this.closed || this.exited)
159
+ throw new AmaError("agent_closed", `${this.agentId} session is closed`);
160
+ if (this.running !== undefined)
161
+ throw new AmaError("busy", `${this.agentId} is already running`);
162
+ const turn = new TurnCollector((e) => hooks.onEvent(e));
163
+ for (const text of this.notices.splice(0))
164
+ turn.push({ type: "notice", level: "warn", text });
165
+ this.turn = turn;
166
+ this.hooks = hooks;
167
+ this.interrupted = false;
168
+ this.usage = { input: 0, output: 0, cacheRead: 0, costUsd: 0, seen: false };
169
+ this.lastAssistant = undefined;
170
+ this.running = this.run(content, turn);
171
+ try {
172
+ return await this.running;
173
+ }
174
+ finally {
175
+ this.running = undefined;
176
+ this.turn = undefined;
177
+ this.hooks = undefined;
178
+ this.settle = undefined;
179
+ this.exitWaiters.clear();
180
+ }
181
+ }
182
+ async run(content, turn) {
183
+ // 先让出一拍:`this.running` 赋值之后再写命令(同步回显的对端里事件可能立刻到达并触发 cancel)
184
+ await Promise.resolve();
185
+ const settled = new Promise((resolve) => (this.settle = resolve));
186
+ const response = await this.request({ type: "prompt", ...this.message(content) });
187
+ if (response["success"] !== true)
188
+ throw new AmaError("agent_failed", `${this.agentId} rejected the prompt: ${oneLine(String(response["error"] ?? "unknown"), 300)}`);
189
+ const disposition = (response["data"] ?? {})["disposition"];
190
+ if (disposition === "handled")
191
+ return turn.result("end_turn");
192
+ const aborted = await Promise.race([settled, this.exitPromise()]);
193
+ await this.reportContext(turn);
194
+ return this.complete(turn, aborted);
195
+ }
196
+ async steer(content) {
197
+ if (this.closed || this.exited)
198
+ throw new AmaError("agent_closed", `${this.agentId} session is closed`);
199
+ await this.request({ type: "steer", ...this.message(content) });
200
+ }
201
+ async cancel() {
202
+ const running = this.running;
203
+ if (running === undefined || this.closed)
204
+ return;
205
+ this.interrupted = true;
206
+ for (const c of this.permissions)
207
+ c.abort();
208
+ void this.request({ type: "abort" }).catch(() => undefined);
209
+ armCancelWatchdog(this.transport, running.catch(() => undefined), this.deps);
210
+ }
211
+ async close() {
212
+ if (this.closed)
213
+ return;
214
+ this.closed = true;
215
+ for (const c of this.permissions)
216
+ c.abort();
217
+ if (this.running !== undefined) {
218
+ this.interrupted = true;
219
+ this.write({ type: "abort" });
220
+ }
221
+ try {
222
+ await this.transport.terminate();
223
+ }
224
+ finally {
225
+ this.dispose();
226
+ }
227
+ }
228
+ message(content) {
229
+ const text = content.map((b) => (b.type === "text" ? b.text : "")).join("\n");
230
+ const images = content.flatMap((b) => b.type === "image" ? [{ type: "image", data: b.data, mimeType: b.mimeType }] : []);
231
+ return { message: text, ...(images.length > 0 ? { images } : {}) };
232
+ }
233
+ complete(turn, aborted) {
234
+ const u = this.usage;
235
+ if (u.seen)
236
+ turn.push({
237
+ type: "usage",
238
+ input: u.input,
239
+ output: u.output,
240
+ cacheRead: u.cacheRead,
241
+ costUsd: u.costUsd,
242
+ });
243
+ const last = this.lastAssistant;
244
+ if (last !== undefined) {
245
+ const text = textOf(last);
246
+ if (text !== "")
247
+ turn.setFinalText(text);
248
+ }
249
+ if (aborted || this.interrupted)
250
+ return turn.result("cancelled");
251
+ switch (last?.["stopReason"]) {
252
+ case "error":
253
+ throw new AmaError("agent_failed", `${this.agentId} failed: ${oneLine(String(last["errorMessage"] ?? "unknown error"), 300)}`);
254
+ case "aborted":
255
+ return turn.result("cancelled");
256
+ case "length":
257
+ return turn.result("max_tokens");
258
+ default:
259
+ return turn.result("end_turn");
260
+ }
261
+ }
262
+ /** `get_session_stats.contextUsage` → 上下文占用与窗口(拿不到就算了)。 */
263
+ async reportContext(turn) {
264
+ if (this.exited)
265
+ return;
266
+ try {
267
+ const stats = await Promise.race([
268
+ this.request({ type: "get_session_stats" }),
269
+ new Promise((resolve) => setTimeout(() => resolve({}), 5_000).unref()),
270
+ ]);
271
+ const usage = ((stats["data"] ?? {})["contextUsage"] ?? {});
272
+ const tokens = usage["tokens"];
273
+ const window = usage["contextWindow"];
274
+ if (typeof tokens === "number" || typeof window === "number")
275
+ turn.push({
276
+ type: "usage",
277
+ ...(typeof tokens === "number" ? { contextTokens: tokens } : {}),
278
+ ...(typeof window === "number" ? { contextWindow: window } : {}),
279
+ });
280
+ }
281
+ catch {
282
+ // 统计拿不到不影响回合
283
+ }
284
+ }
285
+ exitPromise() {
286
+ return new Promise((_, reject) => {
287
+ if (this.exited)
288
+ reject(this.exitError());
289
+ else
290
+ this.exitWaiters.add(reject);
291
+ });
292
+ }
293
+ exitError() {
294
+ const hint = stderrHint(this.transport);
295
+ return new AmaError("agent_exited", `${this.agentId} process exited${hint !== "" ? `: ${hint}` : ""}`);
296
+ }
297
+ request(command) {
298
+ if (this.exited)
299
+ return Promise.reject(this.exitError());
300
+ const id = `ama-${this.nextId++}`;
301
+ return new Promise((resolve, reject) => {
302
+ this.pending.set(id, { resolve, reject });
303
+ this.write({ id, ...command });
304
+ });
305
+ }
306
+ write(record) {
307
+ if (this.exited)
308
+ return;
309
+ this.transport.stdin.write(`${JSON.stringify(record)}\n`);
310
+ }
311
+ onExit() {
312
+ this.exited = true;
313
+ const error = this.exitError();
314
+ for (const p of this.pending.values())
315
+ p.reject(error);
316
+ this.pending.clear();
317
+ for (const reject of this.exitWaiters)
318
+ reject(error);
319
+ this.exitWaiters.clear();
320
+ for (const c of this.permissions)
321
+ c.abort();
322
+ }
323
+ onLine(line) {
324
+ let record;
325
+ try {
326
+ record = JSON.parse(line);
327
+ }
328
+ catch {
329
+ this.deps.log?.("debug", msg().drivers.agent.nonJson(this.agentId));
330
+ return;
331
+ }
332
+ switch (record["type"]) {
333
+ case "response": {
334
+ const id = record["id"];
335
+ const pending = typeof id === "string" ? this.pending.get(id) : undefined;
336
+ if (pending === undefined || typeof id !== "string")
337
+ return;
338
+ this.pending.delete(id);
339
+ pending.resolve(record);
340
+ return;
341
+ }
342
+ case "agent_settled":
343
+ this.settle?.(record["aborted"] === true);
344
+ return;
345
+ case "extension_ui_request":
346
+ void this.onDialog(record);
347
+ return;
348
+ default:
349
+ this.onEvent(record);
350
+ }
351
+ }
352
+ onEvent(record) {
353
+ const turn = this.turn;
354
+ if (turn === undefined)
355
+ return;
356
+ switch (record["type"]) {
357
+ case "message_update": {
358
+ const event = (record["assistantMessageEvent"] ?? {});
359
+ const delta = event["delta"];
360
+ if (typeof delta !== "string")
361
+ return;
362
+ if (event["type"] === "text_delta")
363
+ turn.push({ type: "message_delta", text: delta });
364
+ else if (event["type"] === "thinking_delta")
365
+ turn.push({ type: "thought_delta", text: delta });
366
+ return;
367
+ }
368
+ case "message_end": {
369
+ const message = (record["message"] ?? {});
370
+ if (message["role"] !== "assistant")
371
+ return;
372
+ this.lastAssistant = message;
373
+ const usage = (message["usage"] ?? {});
374
+ const num = (key) => typeof usage[key] === "number" ? usage[key] : 0;
375
+ const cost = (usage["cost"] ?? {})["total"];
376
+ this.usage = {
377
+ input: this.usage.input + num("input"),
378
+ output: this.usage.output + num("output"),
379
+ cacheRead: this.usage.cacheRead + num("cacheRead"),
380
+ costUsd: this.usage.costUsd + (typeof cost === "number" ? cost : 0),
381
+ seen: true,
382
+ };
383
+ return;
384
+ }
385
+ case "tool_execution_start":
386
+ case "tool_execution_end": {
387
+ const tool = String(record["toolName"] ?? "tool");
388
+ const known = turn.tool(String(record["toolCallId"] ?? ""));
389
+ const input = (record["args"] ?? {});
390
+ const path = typeof input["path"] === "string" ? input["path"] : undefined;
391
+ const locations = path !== undefined ? [resolvePath(this.options.cwd, path)] : known?.locations;
392
+ turn.push({
393
+ type: "tool_call",
394
+ id: String(record["toolCallId"] ?? ""),
395
+ title: known?.title ?? piToolTitle(tool, input),
396
+ kind: piToolKind(tool),
397
+ status: record["type"] === "tool_execution_start"
398
+ ? "in_progress"
399
+ : record["isError"] === true
400
+ ? "failed"
401
+ : "completed",
402
+ ...(locations !== undefined && locations.length > 0 ? { locations } : {}),
403
+ });
404
+ return;
405
+ }
406
+ case "auto_retry_start":
407
+ turn.push({
408
+ type: "notice",
409
+ level: "warn",
410
+ text: msg().drivers.agent.error(this.agentId, oneLine(String(record["errorMessage"] ?? "error"), 200), true),
411
+ });
412
+ return;
413
+ default:
414
+ return;
415
+ }
416
+ }
417
+ /** 扩展对话框:ama 的审批闸按模式决定或交给人;其它扩展的对话框取消(不代答)。 */
418
+ async onDialog(record) {
419
+ const id = String(record["id"] ?? "");
420
+ const method = String(record["method"] ?? "");
421
+ if (!DIALOG_METHODS.has(method)) {
422
+ if (record["method"] === "notify" && record["notifyType"] !== "info")
423
+ this.turn?.push({
424
+ type: "notice",
425
+ level: "warn",
426
+ text: `${this.agentId}: ${oneLine(String(record["message"] ?? ""), 200)}`,
427
+ });
428
+ return;
429
+ }
430
+ if (method !== "confirm" || record["title"] !== PI_GATE_TITLE) {
431
+ this.turn?.push({
432
+ type: "notice",
433
+ level: "warn",
434
+ text: msg().drivers.agent.extensionDialog(this.agentId, oneLine(String(record["title"] ?? method), 80)),
435
+ });
436
+ this.write({ type: "extension_ui_response", id, cancelled: true });
437
+ return;
438
+ }
439
+ const confirmed = await this.decide(record);
440
+ this.write({ type: "extension_ui_response", id, confirmed });
441
+ }
442
+ async decide(record) {
443
+ let call;
444
+ try {
445
+ call = JSON.parse(String(record["message"] ?? "{}"));
446
+ }
447
+ catch {
448
+ return false;
449
+ }
450
+ const tool = String(call["tool"] ?? "tool");
451
+ const input = (call["input"] ?? {});
452
+ const mode = this.options.mode;
453
+ if (isReadOnlyMode(mode))
454
+ return false;
455
+ if (mode !== "default" && EDIT_TOOLS.has(tool))
456
+ return true;
457
+ const hooks = this.hooks;
458
+ if (hooks === undefined || this.interrupted || this.closed)
459
+ return false;
460
+ const known = this.turn?.tool(String(call["id"] ?? ""));
461
+ const path = typeof input["path"] === "string" ? input["path"] : undefined;
462
+ const controller = new AbortController();
463
+ this.permissions.add(controller);
464
+ try {
465
+ const outcome = await hooks.onPermission({
466
+ toolCall: {
467
+ title: known?.title ?? piToolTitle(tool, input),
468
+ kind: piToolKind(tool),
469
+ ...(path !== undefined ? { locations: [resolvePath(this.options.cwd, path)] } : {}),
470
+ inputSummary: oneLine(JSON.stringify(input), 300),
471
+ },
472
+ options: [
473
+ { optionId: "allow", kind: "allow_once" },
474
+ { optionId: "reject", kind: "reject_once" },
475
+ ],
476
+ }, controller.signal);
477
+ return (!controller.signal.aborted && outcome.outcome === "selected" && outcome.optionId === "allow");
478
+ }
479
+ finally {
480
+ this.permissions.delete(controller);
481
+ }
482
+ }
483
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 的权限:交人、不代答(docs/wave5-plan.md §5.3,D15)。[W5-E]
2
+ * 外部 Agent 的权限:交人、不代答(docs/history/wave5-plan.md §5.3,D15)。[W5-E]
3
3
  *
4
4
  * 1. 子 Agent 自己的策略先判,它决定要问人的才到 ama;到了以后只走审批通道(宿主 → UI →
5
5
  * 无人值守拒绝),auto 分类器与模型都不参与——`approve` 由调用方接到会话的
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 的权限:交人、不代答(docs/wave5-plan.md §5.3,D15)。[W5-E]
2
+ * 外部 Agent 的权限:交人、不代答(docs/history/wave5-plan.md §5.3,D15)。[W5-E]
3
3
  *
4
4
  * 1. 子 Agent 自己的策略先判,它决定要问人的才到 ama;到了以后只走审批通道(宿主 → UI →
5
5
  * 无人值守拒绝),auto 分类器与模型都不参与——`approve` 由调用方接到会话的
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 进程登记与孤儿清理(docs/wave5-plan.md §5.4 孤儿进程)。[W5-E]
2
+ * 外部 Agent 进程登记与孤儿清理(docs/history/wave5-plan.md §5.4 孤儿进程)。[W5-E]
3
3
  *
4
4
  * `<dataDir>/drivers/pids.json` 记 `{ pid, program, owner }`(owner = 起它的 ama 进程)。
5
5
  * 正常退出时 `process-tree.ts` 已同步杀掉仍存活的组;这里处理 ama 被 SIGKILL / 崩溃留下的孤儿:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 进程登记与孤儿清理(docs/wave5-plan.md §5.4 孤儿进程)。[W5-E]
2
+ * 外部 Agent 进程登记与孤儿清理(docs/history/wave5-plan.md §5.4 孤儿进程)。[W5-E]
3
3
  *
4
4
  * `<dataDir>/drivers/pids.json` 记 `{ pid, program, owner }`(owner = 起它的 ama 进程)。
5
5
  * 正常退出时 `process-tree.ts` 已同步杀掉仍存活的组;这里处理 ama 被 SIGKILL / 崩溃留下的孤儿:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 并发池(docs/wave5-plan.md §5.4 并发)。[W5-E]
2
+ * 外部 Agent 并发池(docs/history/wave5-plan.md §5.4 并发)。[W5-E]
3
3
  *
4
4
  * 总并发 `agents.maxConcurrent`(缺省 3)+ 每个 Agent 的上限 `agents.<id>.maxConcurrent`
5
5
  * (claude 缺省 2:订阅有速率限制);超出排队(先来先得),排队可被 abort。与 ama 自己的
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 并发池(docs/wave5-plan.md §5.4 并发)。[W5-E]
2
+ * 外部 Agent 并发池(docs/history/wave5-plan.md §5.4 并发)。[W5-E]
3
3
  *
4
4
  * 总并发 `agents.maxConcurrent`(缺省 3)+ 每个 Agent 的上限 `agents.<id>.maxConcurrent`
5
5
  * (claude 缺省 2:订阅有速率限制);超出排队(先来先得),排队可被 abort。与 ama 自己的
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 的探测(docs/wave5-plan.md §5.1 probe.ts)。[W5-E]
2
+ * 外部 Agent 的探测(docs/history/wave5-plan.md §5.1 probe.ts)。[W5-E]
3
3
  *
4
4
  * - PATH 查找不起 shell:逐个目录拼程序名(Windows 加 PATHEXT 后缀);绝对 / 相对路径直接认。
5
5
  * - 版本:`<program> --version` 取第一个 `x.y.z`,5 s 超时,不联网、不计费。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 的探测(docs/wave5-plan.md §5.1 probe.ts)。[W5-E]
2
+ * 外部 Agent 的探测(docs/history/wave5-plan.md §5.1 probe.ts)。[W5-E]
3
3
  *
4
4
  * - PATH 查找不起 shell:逐个目录拼程序名(Windows 加 PATHEXT 后缀);绝对 / 相对路径直接认。
5
5
  * - 版本:`<program> --version` 取第一个 `x.y.z`,5 s 超时,不联网、不计费。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 子进程(docs/wave5-plan.md §5.4 看门狗 / 孤儿进程)。[W5-E]
2
+ * 外部 Agent 子进程(docs/history/wave5-plan.md §5.4 看门狗 / 孤儿进程)。[W5-E]
3
3
  *
4
4
  * - POSIX 以 `detached` 自成进程组,结束时 `killProcessTree`(SIGTERM → 宽限 → SIGKILL);
5
5
  * 登记到 `tools/process-tree.ts`,ama 退出时同步清掉仍存活的组。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 子进程(docs/wave5-plan.md §5.4 看门狗 / 孤儿进程)。[W5-E]
2
+ * 外部 Agent 子进程(docs/history/wave5-plan.md §5.4 看门狗 / 孤儿进程)。[W5-E]
3
3
  *
4
4
  * - POSIX 以 `detached` 自成进程组,结束时 `killProcessTree`(SIGTERM → 宽限 → SIGKILL);
5
5
  * 登记到 `tools/process-tree.ts`,ama 退出时同步清掉仍存活的组。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * ProcessRunner:把 AgentDriver 适配成 SubagentRunner(docs/wave5-plan.md §7.6、§5.3–§5.4)。[W5-E]
2
+ * ProcessRunner:把 AgentDriver 适配成 SubagentRunner(docs/history/wave5-plan.md §7.6、§5.3–§5.4)。[W5-E]
3
3
  *
4
4
  * 外部 CLI Agent 由此与 ama 子 Agent 共用 `task(agent=…)` 入口(D13)。`start()`:
5
5
  * 1. 只在已信任目录里起(§5.4 信任;`claude -p` 会跳过目录信任对话框并执行项目 hooks);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * ProcessRunner:把 AgentDriver 适配成 SubagentRunner(docs/wave5-plan.md §7.6、§5.3–§5.4)。[W5-E]
2
+ * ProcessRunner:把 AgentDriver 适配成 SubagentRunner(docs/history/wave5-plan.md §7.6、§5.3–§5.4)。[W5-E]
3
3
  *
4
4
  * 外部 CLI Agent 由此与 ama 子 Agent 共用 `task(agent=…)` 入口(D13)。`start()`:
5
5
  * 1. 只在已信任目录里起(§5.4 信任;`claude -p` 会跳过目录信任对话框并执行项目 hooks);
@@ -144,6 +144,7 @@ const TURN_INTERRUPT = new Set([
144
144
  "acp-adapter",
145
145
  "claude-stream",
146
146
  "codex-app-server",
147
+ "pi-rpc",
147
148
  ]);
148
149
  class ProcessHandle {
149
150
  runner;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 的会话引用与记账(docs/wave5-plan.md §5.4 记账 / 敏感数据,session-format 登记)。[W5-E]
2
+ * 外部 Agent 的会话引用与记账(docs/history/wave5-plan.md §5.4 记账 / 敏感数据,session-format 登记)。[W5-E]
3
3
  *
4
4
  * - `custom{ama.agent-session}`:`{ agent, runner, sessionId, cwd?, taskId? }`——外部 CLI 自己的
5
5
  * 会话 id,续聊(`taskId` / resume)用;不含原始事件与转录。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 的会话引用与记账(docs/wave5-plan.md §5.4 记账 / 敏感数据,session-format 登记)。[W5-E]
2
+ * 外部 Agent 的会话引用与记账(docs/history/wave5-plan.md §5.4 记账 / 敏感数据,session-format 登记)。[W5-E]
3
3
  *
4
4
  * - `custom{ama.agent-session}`:`{ agent, runner, sessionId, cwd?, taskId? }`——外部 CLI 自己的
5
5
  * 会话 id,续聊(`taskId` / resume)用;不含原始事件与转录。
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 驱动契约(docs/wave5-plan.md §5.1–§5.3,D14)。[W5-C0] 契约文件,实现归 W5-E。
2
+ * 外部 Agent 驱动契约(docs/history/wave5-plan.md §5.1–§5.3,D14)。[W5-C0] 契约文件,实现归 W5-E。
3
3
  *
4
4
  * 内部词汇 = ACP v1 子集:各家原生协议(Claude stream-json、Codex app-server、一次性打印模式)
5
5
  * 都映射成 `DriverEvent`;权限请求以 `DriverPermissionRequest` 交给 ama 的 broker 链——**只交给人,
@@ -20,7 +20,7 @@ export interface DriverCapabilities {
20
20
  usage: "tokens" | "usd" | "requests" | "none";
21
21
  images: boolean;
22
22
  }
23
- export type DriverKind = "acp" | "acp-adapter" | "claude-stream" | "codex-app-server" | "oneshot" | "host";
23
+ export type DriverKind = "acp" | "acp-adapter" | "claude-stream" | "codex-app-server" | "pi-rpc" | "oneshot" | "host";
24
24
  export interface DriverProbe {
25
25
  installed: boolean;
26
26
  version?: string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 外部 Agent 驱动契约(docs/wave5-plan.md §5.1–§5.3,D14)。[W5-C0] 契约文件,实现归 W5-E。
2
+ * 外部 Agent 驱动契约(docs/history/wave5-plan.md §5.1–§5.3,D14)。[W5-C0] 契约文件,实现归 W5-E。
3
3
  *
4
4
  * 内部词汇 = ACP v1 子集:各家原生协议(Claude stream-json、Codex app-server、一次性打印模式)
5
5
  * 都映射成 `DriverEvent`;权限请求以 `DriverPermissionRequest` 交给 ama 的 broker 链——**只交给人,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 状态行的 git 信息(docs/wave5-plan.md §1.3)。[W5-A]
2
+ * 状态行的 git 信息(docs/history/wave5-plan.md §1.3)。[W5-A]
3
3
  *
4
4
  * - 分支与短提交零依赖读 `.git/HEAD`(`checkpoints/git-head.ts`,worktree / 子模块的 gitdir 文件、
5
5
  * packed-refs 都认);detached 时没有分支只显示短提交;还没有提交的分支只显示分支名。
package/dist/git/info.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 状态行的 git 信息(docs/wave5-plan.md §1.3)。[W5-A]
2
+ * 状态行的 git 信息(docs/history/wave5-plan.md §1.3)。[W5-A]
3
3
  *
4
4
  * - 分支与短提交零依赖读 `.git/HEAD`(`checkpoints/git-head.ts`,worktree / 子模块的 gitdir 文件、
5
5
  * packed-refs 都认);detached 时没有分支只显示短提交;还没有提交的分支只显示分支名。
@@ -6,7 +6,7 @@
6
6
  * 事件总线 `AgentEventBus` 由 bootstrap 创建并交给 AgentSession 发事件;处理器只观察,
7
7
  * 抛错记日志;`emit` 等待全部处理器(`session_shutdown` 需要被 await)。
8
8
  *
9
- * [W5-EG] `runners.provide`(docs/wave5-plan.md §5.5,D17):宿主注入的 runner 进本适配器的
9
+ * [W5-EG] `runners.provide`(docs/history/wave5-plan.md §5.5,D17):宿主注入的 runner 进本适配器的
10
10
  * {@link HostRunnerRegistry}(跨会话共享),每个主会话的外部 Agent 入口(agents/external.ts)经
11
11
  * {@link hostRunnersOf} 取到它;有宿主时 ama 不自 spawn 外部 CLI,只认这里注入的。
12
12
  */
@@ -6,7 +6,7 @@
6
6
  * 事件总线 `AgentEventBus` 由 bootstrap 创建并交给 AgentSession 发事件;处理器只观察,
7
7
  * 抛错记日志;`emit` 等待全部处理器(`session_shutdown` 需要被 await)。
8
8
  *
9
- * [W5-EG] `runners.provide`(docs/wave5-plan.md §5.5,D17):宿主注入的 runner 进本适配器的
9
+ * [W5-EG] `runners.provide`(docs/history/wave5-plan.md §5.5,D17):宿主注入的 runner 进本适配器的
10
10
  * {@link HostRunnerRegistry}(跨会话共享),每个主会话的外部 Agent 入口(agents/external.ts)经
11
11
  * {@link hostRunnersOf} 取到它;有宿主时 ama 不自 spawn 外部 CLI,只认这里注入的。
12
12
  */