@armadra/agent 0.13.0 → 0.15.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 (53) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/CHANGELOG.zh-CN.md +16 -0
  3. package/README.md +1 -0
  4. package/README.zh-CN.md +1 -0
  5. package/dist/bridge/pi/args.d.ts +19 -0
  6. package/dist/bridge/pi/args.js +96 -0
  7. package/dist/bridge/pi/capabilities.d.ts +57 -0
  8. package/dist/bridge/pi/capabilities.js +65 -0
  9. package/dist/bridge/pi/config.d.ts +28 -0
  10. package/dist/bridge/pi/config.js +67 -0
  11. package/dist/bridge/pi/elicit.d.ts +23 -0
  12. package/dist/bridge/pi/elicit.js +86 -0
  13. package/dist/bridge/pi/entry.d.ts +14 -0
  14. package/dist/bridge/pi/entry.js +59 -0
  15. package/dist/bridge/pi/events.d.ts +62 -0
  16. package/dist/bridge/pi/events.js +223 -0
  17. package/dist/bridge/pi/gate.d.ts +42 -0
  18. package/dist/bridge/pi/gate.js +69 -0
  19. package/dist/bridge/pi/mcp.d.ts +17 -0
  20. package/dist/bridge/pi/mcp.js +49 -0
  21. package/dist/bridge/pi/prompt.d.ts +8 -0
  22. package/dist/bridge/pi/prompt.js +26 -0
  23. package/dist/bridge/pi/replay.d.ts +10 -0
  24. package/dist/bridge/pi/replay.js +87 -0
  25. package/dist/bridge/pi/server.d.ts +61 -0
  26. package/dist/bridge/pi/server.js +240 -0
  27. package/dist/bridge/pi/session.d.ts +112 -0
  28. package/dist/bridge/pi/session.js +497 -0
  29. package/dist/bridge/pi/tools.d.ts +36 -0
  30. package/dist/bridge/pi/tools.js +129 -0
  31. package/dist/bundle/ama.cjs +2398 -562
  32. package/dist/cli/main.d.ts +1 -0
  33. package/dist/cli/main.js +7 -0
  34. package/dist/drivers/catalog.js +23 -1
  35. package/dist/drivers/native/pi-extension.d.ts +39 -0
  36. package/dist/drivers/native/pi-extension.js +100 -0
  37. package/dist/drivers/native/pi-rpc-core.d.ts +49 -0
  38. package/dist/drivers/native/pi-rpc-core.js +108 -0
  39. package/dist/drivers/native/pi-rpc.d.ts +4 -1
  40. package/dist/drivers/native/pi-rpc.js +40 -76
  41. package/dist/i18n/catalog.d.ts +56 -0
  42. package/dist/i18n/catalog.js +3 -0
  43. package/dist/i18n/messages/bridge.d.ts +123 -0
  44. package/dist/i18n/messages/bridge.js +123 -0
  45. package/dist/i18n/messages/cli-help.js +4 -0
  46. package/docs/README.md +6 -6
  47. package/docs/en/README.md +1 -1
  48. package/docs/en/reference/acp.md +87 -9
  49. package/docs/guides/agents.md +3 -0
  50. package/docs/reference/acp.md +87 -9
  51. package/package.json +1 -1
  52. package/dist/drivers/native/pi-gate.d.ts +0 -19
  53. package/dist/drivers/native/pi-gate.js +0 -39
@@ -2374,6 +2374,62 @@ declare const en: {
2374
2374
  authTerminal: (name: string, command: string) => string;
2375
2375
  };
2376
2376
  };
2377
+ bridge: {
2378
+ args: {
2379
+ unknownOption: (option: string) => string;
2380
+ needsValue: (option: string) => string;
2381
+ unsupportedBridge: (value: string) => string;
2382
+ needsAcpMode: string;
2383
+ ownedFlag: (flag: string) => string;
2384
+ };
2385
+ pi: {
2386
+ missing: (pkg: string) => string;
2387
+ outdated: (installed: string, minimum: string, pkg: string) => string;
2388
+ unverified: (version: string, range: string) => string;
2389
+ versionUnknown: (range: string) => string;
2390
+ noModel: string;
2391
+ startFailed: (error: string) => string;
2392
+ exited: (hint: string) => string;
2393
+ promptRejected: (error: string) => string;
2394
+ turnFailed: (error: string) => string;
2395
+ commandTimedOut: (command: string) => string;
2396
+ cancelGraceExpired: string;
2397
+ dialogUnsupported: (title: string) => string;
2398
+ mcpFailed: (error: string) => string;
2399
+ mcpSkipped: (names: string) => string;
2400
+ };
2401
+ modes: {
2402
+ default: string;
2403
+ "auto-edit": string;
2404
+ plan: string;
2405
+ "full-auto": string;
2406
+ };
2407
+ session: {
2408
+ notFound: (id: string) => string;
2409
+ notOpen: (id: string) => string;
2410
+ busy: string;
2411
+ unknownMode: (mode: string) => string;
2412
+ invalidCwd: (cwd: string) => string;
2413
+ missingParam: (key: string) => string;
2414
+ promptNotArray: string;
2415
+ };
2416
+ config: {
2417
+ model: string;
2418
+ thoughtLevel: string;
2419
+ unknownOption: (id: string) => string;
2420
+ invalidValue: (id: string, value: string) => string;
2421
+ setFailed: (id: string, error: string) => string;
2422
+ levels: {
2423
+ off: string;
2424
+ minimal: string;
2425
+ low: string;
2426
+ medium: string;
2427
+ high: string;
2428
+ xhigh: string;
2429
+ max: string;
2430
+ };
2431
+ };
2432
+ };
2377
2433
  };
2378
2434
  /** 运行期取用的目录形状:en 的形状、叶子放宽为 string / 同签名函数。 */
2379
2435
  export type Catalog = Messages<typeof en>;
@@ -26,6 +26,7 @@ import * as memory from "./messages/memory.js";
26
26
  import * as auth from "./messages/auth.js";
27
27
  import * as settings from "./messages/settings.js";
28
28
  import * as acp from "./messages/acp.js";
29
+ import * as bridge from "./messages/bridge.js";
29
30
  const en = {
30
31
  cli: cli.en,
31
32
  subcommands: subcommands.en,
@@ -47,6 +48,7 @@ const en = {
47
48
  auth: auth.en,
48
49
  settings: settings.en,
49
50
  acp: acp.en,
51
+ bridge: bridge.en,
50
52
  };
51
53
  const zh = {
52
54
  cli: cli.zh,
@@ -69,6 +71,7 @@ const zh = {
69
71
  auth: auth.zh,
70
72
  settings: settings.zh,
71
73
  acp: acp.zh,
74
+ bridge: bridge.zh,
72
75
  };
73
76
  export const CATALOGS = { en, zh };
74
77
  /** 领域名(一级命名空间)。 */
@@ -0,0 +1,123 @@
1
+ /**
2
+ * 消息目录:bridge(`ama --mode acp --bridge pi`,键名规范见 docs/guides/i18n.md)。[#254]
3
+ *
4
+ * en 是形状源;zh 用 `satisfies Messages<typeof en>`。桥只翻译给人看的文案(ACP 错误信息、stderr 诊断、
5
+ * 配置项名称);`_meta`、id、value 等机器字段与发给 Pi 的一切固定英文,不走这里。
6
+ */
7
+ export declare const en: {
8
+ /** 命令行用法错误。 */
9
+ args: {
10
+ unknownOption: (option: string) => string;
11
+ needsValue: (option: string) => string;
12
+ unsupportedBridge: (value: string) => string;
13
+ needsAcpMode: string;
14
+ ownedFlag: (flag: string) => string;
15
+ };
16
+ /** Pi 的探测与版本。 */
17
+ pi: {
18
+ missing: (pkg: string) => string;
19
+ outdated: (installed: string, minimum: string, pkg: string) => string;
20
+ unverified: (version: string, range: string) => string;
21
+ versionUnknown: (range: string) => string;
22
+ noModel: string;
23
+ startFailed: (error: string) => string;
24
+ exited: (hint: string) => string;
25
+ promptRejected: (error: string) => string;
26
+ turnFailed: (error: string) => string;
27
+ commandTimedOut: (command: string) => string;
28
+ cancelGraceExpired: string;
29
+ dialogUnsupported: (title: string) => string;
30
+ mcpFailed: (error: string) => string;
31
+ mcpSkipped: (names: string) => string;
32
+ };
33
+ /** 权限模式的一行说明(名称沿用 ama 的显示名)。 */
34
+ modes: {
35
+ default: string;
36
+ "auto-edit": string;
37
+ plan: string;
38
+ "full-auto": string;
39
+ };
40
+ /** ACP 会话。 */
41
+ session: {
42
+ notFound: (id: string) => string;
43
+ notOpen: (id: string) => string;
44
+ busy: string;
45
+ unknownMode: (mode: string) => string;
46
+ invalidCwd: (cwd: string) => string;
47
+ missingParam: (key: string) => string;
48
+ promptNotArray: string;
49
+ };
50
+ /** 配置项(给人看的名称)。 */
51
+ config: {
52
+ model: string;
53
+ thoughtLevel: string;
54
+ unknownOption: (id: string) => string;
55
+ invalidValue: (id: string, value: string) => string;
56
+ setFailed: (id: string, error: string) => string;
57
+ levels: {
58
+ off: string;
59
+ minimal: string;
60
+ low: string;
61
+ medium: string;
62
+ high: string;
63
+ xhigh: string;
64
+ max: string;
65
+ };
66
+ };
67
+ };
68
+ export declare const zh: {
69
+ args: {
70
+ unknownOption: (option: string) => string;
71
+ needsValue: (option: string) => string;
72
+ unsupportedBridge: (value: string) => string;
73
+ needsAcpMode: string;
74
+ ownedFlag: (flag: string) => string;
75
+ };
76
+ pi: {
77
+ missing: (pkg: string) => string;
78
+ outdated: (installed: string, minimum: string, pkg: string) => string;
79
+ unverified: (version: string, range: string) => string;
80
+ versionUnknown: (range: string) => string;
81
+ noModel: string;
82
+ startFailed: (error: string) => string;
83
+ exited: (hint: string) => string;
84
+ promptRejected: (error: string) => string;
85
+ turnFailed: (error: string) => string;
86
+ commandTimedOut: (command: string) => string;
87
+ cancelGraceExpired: string;
88
+ dialogUnsupported: (title: string) => string;
89
+ mcpFailed: (error: string) => string;
90
+ mcpSkipped: (names: string) => string;
91
+ };
92
+ modes: {
93
+ default: string;
94
+ "auto-edit": string;
95
+ plan: string;
96
+ "full-auto": string;
97
+ };
98
+ session: {
99
+ notFound: (id: string) => string;
100
+ notOpen: (id: string) => string;
101
+ busy: string;
102
+ unknownMode: (mode: string) => string;
103
+ invalidCwd: (cwd: string) => string;
104
+ missingParam: (key: string) => string;
105
+ promptNotArray: string;
106
+ };
107
+ config: {
108
+ model: string;
109
+ thoughtLevel: string;
110
+ unknownOption: (id: string) => string;
111
+ invalidValue: (id: string, value: string) => string;
112
+ setFailed: (id: string, error: string) => string;
113
+ levels: {
114
+ off: string;
115
+ minimal: string;
116
+ low: string;
117
+ medium: string;
118
+ high: string;
119
+ xhigh: string;
120
+ max: string;
121
+ };
122
+ };
123
+ };
@@ -0,0 +1,123 @@
1
+ /**
2
+ * 消息目录:bridge(`ama --mode acp --bridge pi`,键名规范见 docs/guides/i18n.md)。[#254]
3
+ *
4
+ * en 是形状源;zh 用 `satisfies Messages<typeof en>`。桥只翻译给人看的文案(ACP 错误信息、stderr 诊断、
5
+ * 配置项名称);`_meta`、id、value 等机器字段与发给 Pi 的一切固定英文,不走这里。
6
+ */
7
+ export const en = {
8
+ /** 命令行用法错误。 */
9
+ args: {
10
+ unknownOption: (option) => `--bridge pi: unknown option ${option}`,
11
+ needsValue: (option) => `${option} needs a value`,
12
+ unsupportedBridge: (value) => `--bridge only supports pi (got ${value})`,
13
+ needsAcpMode: "--bridge pi requires --mode acp",
14
+ ownedFlag: (flag) => `${flag} is managed by the bridge and cannot be passed through to pi after --`,
15
+ },
16
+ /** Pi 的探测与版本。 */
17
+ pi: {
18
+ missing: (pkg) => `pi is not installed or not on PATH; install it with: npm i -g ${pkg}`,
19
+ outdated: (installed, minimum, pkg) => `pi ${installed} is older than the minimum ${minimum}; update it with: npm i -g ${pkg}`,
20
+ unverified: (version, range) => `pi ${version} is outside the verified range ${range}; running with the newest known capabilities`,
21
+ versionUnknown: (range) => `could not read the pi version (verified range ${range}); running with the newest known capabilities`,
22
+ noModel: "pi has no usable model; sign in with /login in pi (or configure a model), then try again",
23
+ startFailed: (error) => `pi failed to start (${error})`,
24
+ exited: (hint) => `pi exited${hint === "" ? "" : `: ${hint}`}`,
25
+ promptRejected: (error) => `pi rejected the prompt: ${error}`,
26
+ turnFailed: (error) => `pi turn failed: ${error}`,
27
+ commandTimedOut: (command) => `pi did not answer ${command} in time`,
28
+ cancelGraceExpired: "pi did not stop within the grace period after cancel; closing the process",
29
+ dialogUnsupported: (title) => `an extension in pi asked for input (${title}), but the client does not support elicitation; cancelled`,
30
+ mcpFailed: (error) => `could not hand an MCP server to pi: ${error}`,
31
+ mcpSkipped: (names) => `ignoring MCP servers the bridge cannot pass to pi (only stdio and http are supported): ${names}`,
32
+ },
33
+ /** 权限模式的一行说明(名称沿用 ama 的显示名)。 */
34
+ modes: {
35
+ default: "Ask before writing files or running commands",
36
+ "auto-edit": "Accept file edits automatically; still ask before commands",
37
+ plan: "Read-only: pi may read and search but changes nothing",
38
+ "full-auto": "Allow everything (dangerous commands still ask)",
39
+ },
40
+ /** ACP 会话。 */
41
+ session: {
42
+ notFound: (id) => `session ${id} not found in pi`,
43
+ notOpen: (id) => `session ${id} is not open in this connection; send session/load or session/resume first`,
44
+ busy: "a prompt is already running in this session",
45
+ unknownMode: (mode) => `unknown mode: ${mode}`,
46
+ invalidCwd: (cwd) => `cwd must be an absolute path (got ${cwd})`,
47
+ missingParam: (key) => `missing ${key}`,
48
+ promptNotArray: "prompt must be an array of content blocks",
49
+ },
50
+ /** 配置项(给人看的名称)。 */
51
+ config: {
52
+ model: "Model",
53
+ thoughtLevel: "Thinking level",
54
+ unknownOption: (id) => `unknown config option: ${id}`,
55
+ invalidValue: (id, value) => `invalid value for config option ${id}: ${value}`,
56
+ setFailed: (id, error) => `pi could not change ${id}: ${error}`,
57
+ levels: {
58
+ off: "Off",
59
+ minimal: "Minimal",
60
+ low: "Low",
61
+ medium: "Medium",
62
+ high: "High",
63
+ xhigh: "Extra high",
64
+ max: "Max",
65
+ },
66
+ },
67
+ };
68
+ export const zh = {
69
+ args: {
70
+ unknownOption: (option) => `--bridge pi:未知选项 ${option}`,
71
+ needsValue: (option) => `${option} 需要一个值`,
72
+ unsupportedBridge: (value) => `--bridge 只支持 pi(收到 ${value})`,
73
+ needsAcpMode: "--bridge pi 需要配合 --mode acp",
74
+ ownedFlag: (flag) => `${flag} 由桥自己管理,不能经 -- 之后透传给 pi`,
75
+ },
76
+ pi: {
77
+ missing: (pkg) => `没有找到 pi(未安装或不在 PATH 里);用 npm i -g ${pkg} 安装`,
78
+ outdated: (installed, minimum, pkg) => `pi ${installed} 低于最低版本 ${minimum};用 npm i -g ${pkg} 更新`,
79
+ unverified: (version, range) => `pi ${version} 超出已验证区间 ${range};按已知的最新能力运行`,
80
+ versionUnknown: (range) => `读不出 pi 的版本(已验证区间 ${range});按已知的最新能力运行`,
81
+ noModel: "pi 没有可用模型;请在 pi 里用 /login 登录(或配置模型)后再试",
82
+ startFailed: (error) => `pi 启动失败(${error})`,
83
+ exited: (hint) => `pi 已退出${hint === "" ? "" : `:${hint}`}`,
84
+ promptRejected: (error) => `pi 拒绝了这条提示:${error}`,
85
+ turnFailed: (error) => `pi 这一轮出错:${error}`,
86
+ commandTimedOut: (command) => `pi 没有及时回应 ${command}`,
87
+ cancelGraceExpired: "取消后 pi 没有在宽限期内停下;关闭进程",
88
+ dialogUnsupported: (title) => `pi 里的扩展要求输入(${title}),但客户端不支持征询;已取消`,
89
+ mcpFailed: (error) => `无法把 MCP 服务器交给 pi:${error}`,
90
+ mcpSkipped: (names) => `忽略桥无法交给 pi 的 MCP 服务器(只支持 stdio 与 http):${names}`,
91
+ },
92
+ modes: {
93
+ default: "写文件、执行命令前询问",
94
+ "auto-edit": "自动接受文件编辑,执行命令仍询问",
95
+ plan: "只读:pi 可以读和搜索,但不改任何东西",
96
+ "full-auto": "全部放行(危险命令仍询问)",
97
+ },
98
+ session: {
99
+ notFound: (id) => `pi 里没有会话 ${id}`,
100
+ notOpen: (id) => `会话 ${id} 没有在本连接中打开;先发 session/load 或 session/resume`,
101
+ busy: "这个会话里已有提示在运行",
102
+ unknownMode: (mode) => `未知模式:${mode}`,
103
+ invalidCwd: (cwd) => `cwd 必须是绝对路径(收到 ${cwd})`,
104
+ missingParam: (key) => `缺少 ${key}`,
105
+ promptNotArray: "prompt 应为内容块数组",
106
+ },
107
+ config: {
108
+ model: "模型",
109
+ thoughtLevel: "思考级别",
110
+ unknownOption: (id) => `未知配置项:${id}`,
111
+ invalidValue: (id, value) => `配置项 ${id} 的值无效:${value}`,
112
+ setFailed: (id, error) => `pi 无法修改 ${id}:${error}`,
113
+ levels: {
114
+ off: "关",
115
+ minimal: "最低",
116
+ low: "低",
117
+ medium: "中",
118
+ high: "高",
119
+ xhigh: "超高",
120
+ max: "最大",
121
+ },
122
+ },
123
+ };
@@ -25,6 +25,8 @@ Modes
25
25
  ≤ 5 MB each); in the interactive UI write @image-path or paste an image path
26
26
  --mode rpc stdio JSONL protocol (for embedding)
27
27
  --mode acp ACP server (driven by Zed / JetBrains / Armadra)
28
+ --mode acp --bridge pi [-- <pi args>]
29
+ ACP server for an installed Pi (no ama key or model needed)
28
30
  --max-cost <USD> Dollar limit for one run (estimated from catalog prices); stops the run,
29
31
  -p exits with 8
30
32
  --tui-mode <mode> Display mode; only regular (main screen) for now
@@ -149,6 +151,8 @@ export const zh = {
149
151
  交互界面里写 @图片路径 或粘贴图片路径
150
152
  --mode rpc stdio JSONL 协议(供嵌入)
151
153
  --mode acp ACP 服务端(供 Zed / JetBrains / Armadra 驱动)
154
+ --mode acp --bridge pi [-- <pi 参数>]
155
+ 把本机的 Pi 暴露为 ACP 服务端(不需要 ama 的 key 与模型)
152
156
  --max-cost <USD> 一次运行的美元上限(按目录价估算);到限结束运行,-p 退出码 8
153
157
  --tui-mode <模式> 显示模式,第一期只有 regular(主屏)
154
158
  --quiet-startup <档> 启动画面:normal | header | silent
package/docs/README.md CHANGED
@@ -34,12 +34,12 @@
34
34
 
35
35
  ## reference/ 协议与格式
36
36
 
37
- | 文档 | 内容 |
38
- | ------------------------------------------- | -------------------------------------------------------- |
39
- | [RPC 协议](reference/rpc.md) | `ama --mode rpc` 的 stdio JSONL 命令、响应与事件 |
40
- | [ACP](reference/acp.md) | `ama --mode acp` 服务端、登录方法、偏差,以及 ACP 客户端 |
41
- | [宿主适配器 API](reference/host-api.md) | `@armadra/agent/host`:注册工具、审批、注入消息、状态 |
42
- | [会话文件格式](reference/session-format.md) | JSONL 条目树、头、条目类型与版本 |
37
+ | 文档 | 内容 |
38
+ | ------------------------------------------- | ---------------------------------------------------------------------- |
39
+ | [RPC 协议](reference/rpc.md) | `ama --mode rpc` 的 stdio JSONL 命令、响应与事件 |
40
+ | [ACP](reference/acp.md) | `ama --mode acp` 服务端、Pi 的 ACP 桥、登录方法、偏差,以及 ACP 客户端 |
41
+ | [宿主适配器 API](reference/host-api.md) | `@armadra/agent/host`:注册工具、审批、注入消息、状态 |
42
+ | [会话文件格式](reference/session-format.md) | JSONL 条目树、头、条目类型与版本 |
43
43
 
44
44
  ## design/ 目标设计
45
45
 
package/docs/en/README.md CHANGED
@@ -24,7 +24,7 @@ When a translation and the Chinese version differ, the Chinese version is author
24
24
  | [Permissions](guides/permissions.md) | The six modes, decision order, auto's three tiers |
25
25
  | [Sessions](guides/sessions.md) | Stats, search, `--from`, export, traces, checkpoints |
26
26
  | [RPC protocol](reference/rpc.md) | `ama --mode rpc`: stdio JSONL commands, responses and events |
27
- | [ACP](reference/acp.md) | `ama --mode acp`, sign-in methods, deviations, the ACP client |
27
+ | [ACP](reference/acp.md) | `ama --mode acp`, the Pi ACP bridge, sign-in methods, deviations, the ACP client |
28
28
  | [Host adapter API](reference/host-api.md) | `@armadra/agent/host`: tools, approvals, injected messages, status |
29
29
 
30
30
  ## Chinese only
@@ -7,7 +7,7 @@ English · [简体中文](../../reference/acp.md)
7
7
 
8
8
  ama works on both sides of ACP:
9
9
 
10
- - **Agent**: `ama --mode acp` exposes ama as an ACP agent for Zed, JetBrains and Armadra's ACP nodes;
10
+ - **Agent**: `ama --mode acp` exposes ama as an ACP agent for Zed, JetBrains and Armadra's ACP nodes; `ama --mode acp --bridge pi` exposes the locally installed Pi as an ACP agent (see below);
11
11
  - **Client**: ama drives external agents over ACP (native ACP agents such as Gemini CLI, OpenCode, Kimi and Copilot, or Claude Code / Codex with an adapter installed); see [agents.md](../../guides/agents.md) (Chinese).
12
12
 
13
13
  The protocol stack is hand-written with no dependencies and maintained in one place: `@armadra/agent/acp` exports the types, framing, client and fake agent, and Armadra reuses them directly. The design rationale is in [wave5-plan.md](../../history/wave5-plan.md) §5 (D14, Chinese).
@@ -130,18 +130,96 @@ Session-open answers (new / load / resume) carry `configOptions`, followed by an
130
130
 
131
131
  After stdin closes, ama waits for the run in progress to finish, then exits (0); from the first start-up step the stdout of the `ama` process carries only the protocol (`console.log` while hosts / hooks load is redirected to stderr); after SIGINT / SIGTERM it exits 130 / 143. Hosts see the mode as `rpc` (`HostApi.mode`). When the SDK calls `bootstrap(--mode acp)` directly it gets a Runtime with `mode: "rpc"` and hands it to `runAcpMode`.
132
132
 
133
+ ## `ama --mode acp --bridge pi`
134
+
135
+ ```sh
136
+ ama --mode acp --bridge pi [--lang zh|en] [-- <pi arguments>]
137
+ ```
138
+
139
+ Exposes the locally installed [Pi](https://github.com/earendil-works/pi) (`@earendil-works/pi-coding-agent`) as an ACP agent for Armadra and other ACP clients. The entry point branches off **before** bootstrap: it resolves no provider or model, needs no ama key and reads or writes no ama sessions. `--bridge` accepts only `pi` and requires `--mode acp`. The bridge sends no model requests itself, so the prompt-byte rules are unaffected.
140
+
141
+ **Processes and sessions**: each ACP session is one `pi --mode rpc --session-id <id> -e <bridge extension>` child; the ACP `sessionId` is Pi's session id, and the child's working directory is the `cwd` of `session/new` (it must be absolute). Arguments after `--` are passed to pi unchanged (`--skill`, `--append-system-prompt` and so on keep working), but flags the bridge manages are always refused (exit code 2): `--mode`, `--session*`, `-c` / `--continue`, `-r` / `--resume`, `--fork`, `--no-session`, `--tools` / `-t`, `--no-mcp`, `-p` / `--print`. When stdin closes, all pi children are closed and the bridge exits 0. The bridge neither reads nor writes Pi's configuration or login (`auth.json`, `mcp.json`, `settings.json`); sign in with `/login` inside Pi.
142
+
143
+ | Method | What the bridge does |
144
+ | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
145
+ | `initialize` | `loadSession: true`, `sessionCapabilities: { resume, close }` (no `list`: Pi's RPC has no command to list sessions and the bridge does not read Pi's session directory), `mcpCapabilities: { http: true, sse: false }`, `promptCapabilities: { image: true, embeddedContext: true }`, `authMethods: []` |
146
+ | `session/new` | Starts a child with a fresh uuid; the result carries `modes`, `configOptions` and `_meta`. If Pi has no usable model, the error has `error.data.code = "pi_no_model"` and asks the user to sign in inside Pi |
147
+ | `session/load` | The same, with the requested id. A session with no messages in Pi (Pi silently creates an empty one) counts as not found: -32002 and the child is closed. Otherwise history is replayed as `user_message_chunk`, `agent_*_chunk` and final-state `tool_call`s, followed by the current plan |
148
+ | `session/resume` | Like load, without the replay |
149
+ | `session/close` | Interrupts, closes the child and deletes the temporary directory |
150
+ | `session/prompt` | Text and embedded resources become the message; images go in `images`. `disposition: handled` does not wait for a turn; `agent_settled.aborted` → `cancelled`, `length` → `max_tokens`, an error → a JSON-RPC error. The result's `usage` is the sum for this turn. A prompt arriving while one runs gets invalid request (busy) |
151
+ | `session/cancel` | Withdraws pending approvals and elicitations, sends `abort` and arms a 15 s watchdog (then closes stdin and ends the process tree); the turn ends with `cancelled` |
152
+ | `session/set_mode` | The four modes below; takes effect immediately |
153
+ | `session/set_config_option` | `model` and `thought_level`, below |
154
+
155
+ ### Pi versions
156
+
157
+ The bridge only sends RPC commands that its capability table lists (old Pi answers an unknown command without an id, so the request cannot be correlated), and every non-prompt command has a 10 s deadline.
158
+
159
+ | Capability | Since | Used for |
160
+ | -------------------------------------------------------- | -------------- | ------------------------------------- |
161
+ | `--session-id` | 0.76.0 | New and resumed sessions |
162
+ | `agent_settled` / its `aborted` | 0.80.4 / 1.1.0 | Detecting turn end and cancel |
163
+ | `get_available_thinking_levels` | 0.81.0 | The `thought_level` option |
164
+ | `disposition` in the `prompt` response | 0.99.0 | Not waiting for a turn when `handled` |
165
+ | Built-in MCP, `pi.registerMcpServer`, tool `annotations` | 0.99.0 | Canvas tools; read-only check in plan |
166
+ | `cost` / `contextUsage` of `get_session_stats` | 0.63.0 | `usage_update` |
167
+ | `Usage.cost.totalFromProvider` | 1.5.0 | Billed cost versus catalog estimate |
168
+
169
+ - **Floor 1.1.0** (the latest `since` among the required capabilities). Older Pi: `session/new` answers `error.data = { code: "pi_outdated", installed, minimum, package }`; a missing `pi` answers `{ code: "pi_missing", package }`. No child is started in either case.
170
+ - **Verified range `>=1.1.0 <2.0.0`**: optional capabilities follow the table (below 1.5.0, for example, cost is not marked as billed). Tested on Pi 1.5.0.
171
+ - **Above the range, or version unreadable**: runs with the newest known capabilities; one stderr line, and `_meta["armadra.pi"].verified` is `false` in the result so the client can show a notice.
172
+ - The result's `_meta["armadra.pi"] = { version?, verified, capabilities? }`; `capabilities = { todo, subagent, questionnaire }` says whether Pi has a tool with that name (see "Todos, subagents and elicitation").
173
+
174
+ ### Modes and approval
175
+
176
+ Pi has neither permission modes nor an approval channel, so the bridge loads an extension into every run (`-e`, in the session's own `mkdtemp` directory with mode 0600, deleted when the session closes; shared with the external-agent driver, see [agents.md](../../guides/agents.md), Chinese). Before every tool call the extension hands the request to the bridge, and it asks the bridge **every time**, so `session/set_mode` takes effect immediately.
177
+
178
+ | Mode (ids as in ama) | Behaviour |
179
+ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
180
+ | `default` | Read-only calls (built-in `read` / `grep` / `find` / `ls`, or MCP tools declaring `readOnlyHint`) pass; everything else goes to the human |
181
+ | `auto-edit` | Also allows `edit` / `write`; the rest goes to the human |
182
+ | `plan` | Read-only passes; everything else is refused and the model is told it is in plan mode (describe the change instead of making it) |
183
+ | `full-auto` | Everything passes, except bash commands matching ama's dangerous-command rules, which still go to the human |
184
+
185
+ Going to the human means `session/request_permission` (`allow_once` / `reject_once`, with `toolCallId`, title, kind, `rawInput` and locations). A call that must pass the gate is announced as `pending` first and becomes `in_progress` once allowed. A `cancelled` outcome, a failing request or a cancelled session all count as a refusal; **the bridge never answers on the human's behalf**.
186
+
187
+ ### Config options and usage
188
+
189
+ - `model`: values are `provider/id` (grouped by provider); after a model change the thinking levels are re-read and a `config_option_update` is sent;
190
+ - `thought_level`: Pi's `off` … `max`; omitted when the current model has no reasoning. It is the only thinking control and is not part of `modes`;
191
+ - `usage_update`: sent when a session opens, after each turn and after a model change; `used` = `contextUsage.tokens`, `size` = the context window, `cost = { amount, currency: "USD" }`. From 1.5.0, `_meta["armadra.pi"].fromProvider` says whether the cost is a billed total.
192
+
193
+ ### MCP
194
+
195
+ The client's `mcpServers` (stdio and http; sse is skipped with one stderr line) are written to `bridge.json` in the session's temporary directory. When the extension loads it calls `pi.registerMcpServer(name, { …, exposure: "direct" })` for each one: ama itself speaks no MCP, Pi's built-in MCP makes the connections. Pi server names may only contain letters, digits, `_` and `-`; anything else becomes `_`. A server of the same name in the user's `mcp.json` wins under Pi's own rules.
196
+
197
+ `tool_call`s and permission requests for `mcp__<server>__<tool>` (only servers the bridge registered are recognised) carry `_meta.is_mcp_tool_call: true` and `rawInput { server, tool, arguments }`, so the client can recognise its own tools. Inner calls made from code mode carry `_meta.ama.parentToolCallId`.
198
+
199
+ ### Todos, subagents and elicitation
200
+
201
+ The bridge **registers no todo or questionnaire tools of its own**: these appear only when the installed Pi already has the matching tool or extension. When it does not, nothing is added and the gap shows up in `_meta["armadra.pi"].capabilities`.
202
+
203
+ - **Todos → `plan`**: every tool result with `details.todos` (`{text, done}` or `{content, status}`) sends the whole list as a `plan`; the `todo` tool has kind `think`;
204
+ - **Subagents**: Pi's `subagent` extension tool is one `tool_call` of kind `other` with `_meta["armadra.subagent"] = { agent, task }` (parallel and chain calls use `{ mode, tasks }`); streamed progress goes into content, and the cost is already part of `get_session_stats`;
205
+ - **Dialogs → `elicitation/create`**: when the client declared `elicitation`, other extensions' select (titled enum), confirm (boolean) and input / editor (string; the editor's prefill is the default) become form elicitations. `accept` hands the value to Pi; `decline`, `cancel` and a value outside the options all end as a cancel on Pi's side, and the bridge never chooses for the user. When Pi gives a `timeout`, the request is withdrawn (`$/cancel_request`) when it expires; a cancelled session withdraws it too. Without the client capability the dialog is cancelled with one stderr line. ama's own dialogs (approval gate, refusal reason, capability report) are not included.
206
+
207
+ ### Tests
208
+
209
+ A scripted fake Pi (`test/helpers/fake-pi.ts`) covers versions 1.0.4 / 1.1.0 / 1.4.0 / 1.5.0 / 2.0.0 / unreadable, the four modes, cancel, MCP, plan, subagents and elicitation. Like old Pi it answers unknown commands without an id, and the tests assert that the bridge never sends one. Every wire message passes the official schema (`test/helpers/acp-schema.ts`). Bundle level: `AMA_E2E=1 pnpm test:e2e` (`test/e2e/bridge.e2e.test.ts`, a `pi` shim on PATH that runs the fake).
210
+
133
211
  ## Deviations and non-goals
134
212
 
135
213
  These are deliberate choices, not omissions:
136
214
 
137
- | Item | What ama does and why |
138
- | ------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
139
- | The client's `fs/*` and `terminal/*` | Not used (even when the client declares them). ama reads and writes files and runs commands itself, all through its own permission pipeline, sandbox and checkpoints; borrowing the client's file system or terminal would bypass them and make TUI / RPC / ACP behave differently. |
140
- | MCP (`mcpServers`, including stdio, which the spec requires) | Not connected; `mcpCapabilities.http` / `sse` are false; a non-empty `mcpServers` gets one stderr line and the session opens as usual. **This deviates from the spec's MUST "agents must support stdio MCP"**: ama's tools come only from itself and the host (profile), and extensions are skills; MCP would put external tool descriptions into the request prefix, breaking the byte-stable prompt cache, and bypass how the permission pipeline classifies tools. |
141
- | elicitation (the agent asking a human for structured input) | As an agent, ama never sends `elicitation/create`: the only thing it needs a human to decide is approvals, which go through `session/request_permission`. As a client it is supported (see below). |
142
- | `session/delete` | Not implemented (-32601). Clean up session files with `ama sessions prune`. |
143
- | `logout` | Not implemented, and `agentCapabilities.auth.logout` is not declared (-32601). Sign out with `ama auth logout chatgpt` / `ama auth remove <provider>`. |
144
- | Session `cwd` | Fixed to ama's start directory: `session/new` with another directory answers -32602 and `additionalDirectories` is ignored. Trust, project config, the session directory and the sandbox are all decided by the start directory, and changing directories inside one process would invalidate them. To work in another directory, start another `ama --mode acp` there. |
215
+ | Item | What ama does and why |
216
+ | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
217
+ | The client's `fs/*` and `terminal/*` | Not used (even when the client declares them). ama reads and writes files and runs commands itself, all through its own permission pipeline, sandbox and checkpoints; borrowing the client's file system or terminal would bypass them and make TUI / RPC / ACP behave differently. |
218
+ | MCP (`mcpServers`, including stdio, which the spec requires) | Not connected; `mcpCapabilities.http` / `sse` are false; a non-empty `mcpServers` gets one stderr line and the session opens as usual (the Pi bridge is the exception: it hands `mcpServers` to Pi's built-in MCP, see above). **This deviates from the spec's MUST "agents must support stdio MCP"**: ama's tools come only from itself and the host (profile), and extensions are skills; MCP would put external tool descriptions into the request prefix, breaking the byte-stable prompt cache, and bypass how the permission pipeline classifies tools. |
219
+ | elicitation (the agent asking a human for structured input) | As an agent, ama never sends `elicitation/create`: the only thing it needs a human to decide is approvals, which go through `session/request_permission`. As a client it is supported (see below). |
220
+ | `session/delete` | Not implemented (-32601). Clean up session files with `ama sessions prune`. |
221
+ | `logout` | Not implemented, and `agentCapabilities.auth.logout` is not declared (-32601). Sign out with `ama auth logout chatgpt` / `ama auth remove <provider>`. |
222
+ | Session `cwd` | Fixed to ama's start directory: `session/new` with another directory answers -32602 and `additionalDirectories` is ignored. Trust, project config, the session directory and the sandbox are all decided by the start directory, and changing directories inside one process would invalidate them. To work in another directory, start another `ama --mode acp` there. |
145
223
 
146
224
  ## As a client
147
225
 
@@ -246,6 +246,7 @@ ama 能以各 CLI 自己的账户、模型与权限策略驱动外部编码 Agen
246
246
  | `copilot` | `copilot --acp --stdio` | 1.0.95 |
247
247
  | `opencode` | `opencode acp` | 1.18.x |
248
248
  | `pi` | `pi --mode rpc`(原生;审批经 ama 加载的审批闸扩展,见下) | 1.1.x |
249
+ | `omp` | `omp acp`(模式 `default` / `plan`;需要 Bun ≥1.4.4) | 18.16.x |
249
250
  | `cursor` | `cursor-agent acp`(按官方文档:模式 `agent` / `plan` / `ask`) | 未验证(本机未装) |
250
251
  | `gemini` | `gemini --acp` → `gemini -p --output-format stream-json`(一次性,只读) | 未验证 |
251
252
  | `qwen` | `qwen --acp`(0.23.x 有不发权限请求的问题,只在 plan 下用) | 未验证 |
@@ -257,6 +258,8 @@ pi 的社区 ACP 适配器 `pi-acp` 不收录:pi 本身没有审批通道,
257
258
  ama 改为直接驱动 `pi --mode rpc`,并以 `-e` 给这一次运行加载一个最小扩展(写在每个会话自己的临时目录,关会话即删,不碰 pi 的配置):
258
259
  只读内置工具(`read` / `grep` / `find` / `ls`)以外的调用都经 RPC 的扩展对话框交给 ama——`plan` / `allowlist` 直接拒绝(并以
259
260
  `--tools` 只开只读工具),`auto-edit` 及更宽的模式放行 `edit` / `write`,其余交给人。用户自己的扩展弹出的对话框一律取消、不代答。
261
+ 这份扩展(`src/drivers/native/pi-extension.ts`)与 ACP 桥共用;Armadra 等 ACP 客户端想直接驱动 pi 时用 `ama --mode acp --bridge pi`
262
+ (四个权限模式、MCP 透传、待办与征询,见 [acp.md](../reference/acp.md)),不必经 `task`。
260
263
 
261
264
  #### 实测能力矩阵(2026-10-10)
262
265