@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
package/CHANGELOG.md CHANGED
@@ -5,6 +5,22 @@ English · [简体中文](CHANGELOG.zh-CN.md)
5
5
  > This file is in English starting with 0.6.0. Release notes for 0.1 through 0.5.1 are in Chinese in
6
6
  > [CHANGELOG.zh-CN.md](CHANGELOG.zh-CN.md). New entries go into both files.
7
7
 
8
+ ## 0.15.0 (2026-11-05)
9
+
10
+ ### External agents
11
+
12
+ - **omp joins the driver catalog**: `agent: "omp"` starts `omp acp` (Bun >= 1.4.4 required). Verified against omp 18.16.0: session modes `default` / `plan` (the other ama modes stay in `default`), session list / resume / fork / close, image prompts; shown in `/agents`. See [docs/guides/agents.md](docs/guides/agents.md) (#259).
13
+
14
+ ## 0.14.0 (2026-11-05)
15
+
16
+ ### ACP
17
+
18
+ - **A Pi bridge, `ama --mode acp --bridge pi`**: ama itself exposes the locally installed Pi as an ACP agent, with no ama key or model needed (it branches off before bootstrap). Each ACP session is one `pi --mode rpc --session-id <id>` child; `session/new` / `load` / `resume` / `close` / `prompt` / `cancel`, the `model` and `thought_level` config options, and `usage_update` with cost (from 1.5.0 it says whether the cost is a billed total). The four permission modes (`default` / `auto-edit` / `plan` / `full-auto`) are implemented by the approval gate and `session/set_mode` takes effect at once; requests that need a human go out as `session/request_permission` and the bridge never answers for the user. The client's `mcpServers` (stdio and http) are handed to Pi's built-in MCP, and the client's own tools carry `_meta.is_mcp_tool_call`. Arguments after `--` pass through to pi (flags the bridge manages are refused). Todos become `plan`, subagent calls carry `_meta["armadra.subagent"]`, and other extensions' dialogs become `elicitation/create`. It adapts to the Pi version: floor 1.1.0 (older answers `pi_outdated`), verified range `>=1.1.0 <2.0.0`, newer or unreadable versions run with a notice (`_meta["armadra.pi"].verified: false`), and only commands in the capability table are sent. The bridge registers no todo or questionnaire tools of its own; when Pi lacks them the gap shows in `_meta["armadra.pi"].capabilities`. See [docs/reference/acp.md](docs/reference/acp.md) (#254).
19
+
20
+ ### External agents
21
+
22
+ - **The pi driver and the bridge share one extension**: `pi-gate` is merged into `pi-extension` (besides the approval gate it hands over MCP servers, reports capabilities and returns refusal reasons); request correlation, the command table and the 10 s deadline for non-prompt commands of `pi-rpc` moved into `pi-rpc-core`. Driver behaviour is unchanged (#254).
23
+
8
24
  ## 0.13.0 (2026-11-04)
9
25
 
10
26
  ### Maintenance
@@ -4,6 +4,22 @@
4
4
 
5
5
  > 从 0.6.0 起 [CHANGELOG.md](CHANGELOG.md) 为英文,本文件保留中文记录(0.1–0.5.1 的完整历史在此)。新条目两份都要加。
6
6
 
7
+ ## 0.15.0(2026-11-05)
8
+
9
+ ### 外部 Agent
10
+
11
+ - **驱动表收录 omp**:`agent: "omp"` 启动 `omp acp`(需要 Bun >= 1.4.4)。按 omp 18.16.0 实测:会话模式 `default` / `plan`(ama 的其余模式留在 `default`)、会话列表 / 恢复 / 分叉 / 关闭、图片提示;`/agents` 列出。见 [docs/guides/agents.md](docs/guides/agents.md)(#259)。
12
+
13
+ ## 0.14.0(2026-11-05)
14
+
15
+ ### ACP
16
+
17
+ - **Pi 的 ACP 桥 `ama --mode acp --bridge pi`**:ama 自己把本机装的 Pi 暴露为 ACP Agent,不需要 ama 的 key 与模型(bootstrap 之前分流)。一个 ACP 会话对应一个 `pi --mode rpc --session-id <id>` 子进程;`session/new` / `load` / `resume` / `close` / `prompt` / `cancel`,`model` 与 `thought_level` 配置项,带费用的 `usage_update`(≥1.5.0 标费用是不是账单值);四个权限模式(`default` / `auto-edit` / `plan` / `full-auto`)经审批闸实现、`session/set_mode` 立即生效,需要人的请求发 `session/request_permission`,桥从不代答;客户端的 `mcpServers`(stdio 与 http)交给 Pi 内置的 MCP,自家工具带 `_meta.is_mcp_tool_call`;`--` 之后的参数原样交给 pi(桥自管的旗标拒绝);待办 → `plan`、子 Agent 的 `_meta["armadra.subagent"]`、其它扩展的对话框 → `elicitation/create`。按 Pi 版本适配:下限 1.1.0(更低答 `pi_outdated`)、已验证区间 `>=1.1.0 <2.0.0`、更高或读不出版本照跑并提示(`_meta["armadra.pi"].verified: false`),只发能力表里有的命令。桥不注册自己的 todo / 问卷工具,Pi 里没有对应工具时缺口体现在 `_meta["armadra.pi"].capabilities`。见 [docs/reference/acp.md](docs/reference/acp.md)(#254)。
18
+
19
+ ### 外部 Agent
20
+
21
+ - **pi 驱动与桥共用一份扩展**:`pi-gate` 并入 `pi-extension`(审批闸之外加 MCP 透传、能力报告与拒绝理由);`pi-rpc` 的请求关联、命令表与非 prompt 命令的 10 秒截止拆成 `pi-rpc-core`。驱动的行为不变(#254)。
22
+
7
23
  ## 0.13.0(2026-11-04)
8
24
 
9
25
  ### 维护
package/README.md CHANGED
@@ -121,6 +121,7 @@ as a tool result. Approvals it raises go to you only, and its mode is never wide
121
121
  | `copilot` | `copilot --acp --stdio` | Verified |
122
122
  | `opencode` | `opencode acp` | Verified |
123
123
  | `pi` | `pi --mode rpc` with an approval gate loaded for the run | Verified |
124
+ | `omp` | `omp acp` | Verified |
124
125
  | `cursor` | `cursor-agent acp` | Listed, not verified |
125
126
  | `gemini`, `qwen`, `kimi`, `goose` | Their ACP subcommands | Listed, not verified |
126
127
  | `acp:<program>` | Any other ACP agent | — |
package/README.zh-CN.md CHANGED
@@ -118,6 +118,7 @@ ama -p "列出 TODO" --output-format json # 或 stream-json,事件与 RPC
118
118
  | `copilot` | `copilot --acp --stdio` | 已实测 |
119
119
  | `opencode` | `opencode acp` | 已实测 |
120
120
  | `pi` | `pi --mode rpc`,运行时加载审批闸扩展 | 已实测 |
121
+ | `omp` | `omp acp` | 已实测 |
121
122
  | `cursor` | `cursor-agent acp` | 已收录,未实测 |
122
123
  | `gemini`、`qwen`、`kimi`、`goose` | 各自的 ACP 子命令 | 已收录,未实测 |
123
124
  | `acp:<程序>` | 其它任意 ACP Agent | — |
@@ -0,0 +1,19 @@
1
+ /**
2
+ * `ama --mode acp --bridge pi [--lang zh|en] [-- <pi 的参数>]` 的参数解析(#254)。
3
+ *
4
+ * - `--bridge` 只认 `pi`,且必须配 `--mode acp`;除 `--lang` 外不收别的选项(桥不起 ama 的模型与会话);
5
+ * - `--` 之后的参数原样交给 pi(宿主的 `--skill`、`--append-system-prompt` 注入照用),但桥自己管的旗标
6
+ * 一律拒绝:模式、会话选择与存储、`--tools`、`--no-mcp`、`-p`——放行它们会让审批闸、会话 id 或 MCP 透传失效。
7
+ */
8
+ import { type Locale } from "../../i18n/index.js";
9
+ export interface BridgeArgs {
10
+ bridge: "pi";
11
+ passthrough: string[];
12
+ lang?: Locale;
13
+ }
14
+ /** `--` 之前出现 `--bridge`(含 `--bridge=pi`)。 */
15
+ export declare function hasBridgeFlag(argv: readonly string[]): boolean;
16
+ /** 宽松预扫 `--lang`(`--` 之前,无效值忽略):用法错误信息也要按界面语言出。 */
17
+ export declare function bridgeLangOf(argv: readonly string[]): Locale | undefined;
18
+ /** 解析;用法错误抛 {@link UsageError}(退出码 2)。 */
19
+ export declare function parseBridgeArgs(argv: readonly string[]): BridgeArgs;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * `ama --mode acp --bridge pi [--lang zh|en] [-- <pi 的参数>]` 的参数解析(#254)。
3
+ *
4
+ * - `--bridge` 只认 `pi`,且必须配 `--mode acp`;除 `--lang` 外不收别的选项(桥不起 ama 的模型与会话);
5
+ * - `--` 之后的参数原样交给 pi(宿主的 `--skill`、`--append-system-prompt` 注入照用),但桥自己管的旗标
6
+ * 一律拒绝:模式、会话选择与存储、`--tools`、`--no-mcp`、`-p`——放行它们会让审批闸、会话 id 或 MCP 透传失效。
7
+ */
8
+ import { UsageError } from "../../cli/args.js";
9
+ import { LOCALES, msg } from "../../i18n/index.js";
10
+ /** 桥自己管的 pi 旗标(长名与短名;`--名=值` 形式同样命中)。 */
11
+ const OWNED_FLAGS = new Set([
12
+ "--mode",
13
+ "--session",
14
+ "--session-id",
15
+ "--session-dir",
16
+ "--continue",
17
+ "-c",
18
+ "--resume",
19
+ "-r",
20
+ "--fork",
21
+ "--no-session",
22
+ "--tools",
23
+ "-t",
24
+ "--no-mcp",
25
+ "--print",
26
+ "-p",
27
+ ]);
28
+ /** `--` 之前出现 `--bridge`(含 `--bridge=pi`)。 */
29
+ export function hasBridgeFlag(argv) {
30
+ for (const token of argv) {
31
+ if (token === "--")
32
+ return false;
33
+ if (token === "--bridge" || token.startsWith("--bridge="))
34
+ return true;
35
+ }
36
+ return false;
37
+ }
38
+ /** 宽松预扫 `--lang`(`--` 之前,无效值忽略):用法错误信息也要按界面语言出。 */
39
+ export function bridgeLangOf(argv) {
40
+ let lang;
41
+ for (let i = 0; i < argv.length && argv[i] !== "--"; i++) {
42
+ const token = argv[i] ?? "";
43
+ const value = token === "--lang" ? argv[i + 1] : token.startsWith("--lang=") ? token.slice(7) : undefined;
44
+ if (value !== undefined && LOCALES.includes(value))
45
+ lang = value;
46
+ }
47
+ return lang;
48
+ }
49
+ /** 解析;用法错误抛 {@link UsageError}(退出码 2)。 */
50
+ export function parseBridgeArgs(argv) {
51
+ const m = msg().bridge.args;
52
+ let bridge;
53
+ let mode;
54
+ let lang;
55
+ let passthrough = [];
56
+ const valueOf = (name, inline, at) => {
57
+ if (inline !== undefined)
58
+ return [inline, at];
59
+ const next = argv[at + 1];
60
+ if (next === undefined)
61
+ throw new UsageError(m.needsValue(name));
62
+ return [next, at + 1];
63
+ };
64
+ for (let i = 0; i < argv.length; i++) {
65
+ const token = argv[i] ?? "";
66
+ if (token === "--") {
67
+ passthrough = argv.slice(i + 1).map(String);
68
+ break;
69
+ }
70
+ const eq = token.indexOf("=");
71
+ const name = token.startsWith("--") && eq !== -1 ? token.slice(0, eq) : token;
72
+ const inline = token.startsWith("--") && eq !== -1 ? token.slice(eq + 1) : undefined;
73
+ if (name !== "--bridge" && name !== "--mode" && name !== "--lang")
74
+ throw new UsageError(m.unknownOption(token));
75
+ const [value, next] = valueOf(name, inline, i);
76
+ i = next;
77
+ if (name === "--bridge")
78
+ bridge = value;
79
+ else if (name === "--mode")
80
+ mode = value;
81
+ else if (LOCALES.includes(value))
82
+ lang = value;
83
+ else
84
+ throw new UsageError(m.unknownOption(`--lang ${value}`));
85
+ }
86
+ if (bridge !== "pi")
87
+ throw new UsageError(m.unsupportedBridge(bridge ?? ""));
88
+ if (mode !== "acp")
89
+ throw new UsageError(m.needsAcpMode);
90
+ for (const token of passthrough) {
91
+ const flag = token.startsWith("--") ? token.split("=")[0] : token;
92
+ if (OWNED_FLAGS.has(flag))
93
+ throw new UsageError(m.ownedFlag(flag));
94
+ }
95
+ return { bridge: "pi", passthrough, ...(lang !== undefined ? { lang } : {}) };
96
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Pi 版本能力表(#254):桥只发表里有的 RPC 命令、只开表里起始版本不高于已装版本的可选能力。
3
+ *
4
+ * - 下限 {@link PI_FLOOR}:必需能力里起始版本最晚的一项(`agent_settled.aborted`,1.1.0),低于它拒绝;
5
+ * - 已验证区间 {@link PI_VERIFIED}:区间内按表开关可选能力;高于区间或读不出版本:照跑,按最高已知能力处理,
6
+ * 由调用方给出提示;
7
+ * - 永不发表外命令:旧版 Pi 对未知命令的应答不带 id,请求无从关联(Armadra#710 的根因)。
8
+ */
9
+ export declare const PI_FLOOR = "1.1.0";
10
+ export declare const PI_VERIFIED = ">=1.1.0 <2.0.0";
11
+ export declare const PI_PACKAGE = "@earendil-works/pi-coding-agent";
12
+ /** 能力 id → 起始版本(含)。 */
13
+ export declare const PI_CAPABILITY_SINCE: {
14
+ /** `--session-id`:新开与接回都用它。 */
15
+ readonly sessionId: "0.76.0";
16
+ /** `agent_settled` 事件:判定回合结束。 */
17
+ readonly agentSettled: "0.80.4";
18
+ /** `agent_settled.aborted`:判定取消。 */
19
+ readonly settledAborted: "1.1.0";
20
+ /** `get_available_thinking_levels`:thought_level 配置项。 */
21
+ readonly thinkingLevels: "0.81.0";
22
+ /** `prompt` 应答里的 `disposition`:`handled` 时不等回合。 */
23
+ readonly disposition: "0.99.0";
24
+ /** 内置 MCP、`pi.registerMcpServer`、工具 `annotations`。 */
25
+ readonly mcp: "0.99.0";
26
+ /** `get_session_stats` 的 `cost` / `contextUsage`。 */
27
+ readonly sessionStats: "0.63.0";
28
+ /** `Usage.cost.totalFromProvider`:区分账单值与价目表估算。 */
29
+ readonly costFromProvider: "1.5.0";
30
+ };
31
+ export type PiCapabilityId = keyof typeof PI_CAPABILITY_SINCE;
32
+ export type PiCapabilities = Readonly<Record<PiCapabilityId, boolean>>;
33
+ /** 桥会发的 RPC 命令 → 起始版本(都不晚于下限,除 thinking 外)。 */
34
+ export declare const PI_COMMAND_SINCE: {
35
+ readonly get_state: "0.76.0";
36
+ readonly get_messages: "0.76.0";
37
+ readonly prompt: "0.76.0";
38
+ readonly steer: "0.76.0";
39
+ readonly abort: "0.76.0";
40
+ readonly set_model: "0.76.0";
41
+ readonly get_available_models: "0.76.0";
42
+ readonly set_thinking_level: "0.76.0";
43
+ readonly get_available_thinking_levels: "0.81.0";
44
+ readonly get_session_stats: "0.63.0";
45
+ };
46
+ export type PiCommandName = keyof typeof PI_COMMAND_SINCE;
47
+ /** 版本 → 能力判定的结果。 */
48
+ export interface PiVersionInfo {
49
+ /** `unsupported` 低于下限;`verified` 在已验证区间内;`newer` 高于区间;`unknown` 读不出版本。 */
50
+ status: "unsupported" | "verified" | "newer" | "unknown";
51
+ version?: string;
52
+ capabilities: PiCapabilities;
53
+ /** 可发的命令。 */
54
+ commands: ReadonlySet<string>;
55
+ }
56
+ /** 按版本求能力与可发命令;`undefined`(读不出)与高于区间一样按最高已知能力。 */
57
+ export declare function piVersionInfo(version: string | undefined): PiVersionInfo;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Pi 版本能力表(#254):桥只发表里有的 RPC 命令、只开表里起始版本不高于已装版本的可选能力。
3
+ *
4
+ * - 下限 {@link PI_FLOOR}:必需能力里起始版本最晚的一项(`agent_settled.aborted`,1.1.0),低于它拒绝;
5
+ * - 已验证区间 {@link PI_VERIFIED}:区间内按表开关可选能力;高于区间或读不出版本:照跑,按最高已知能力处理,
6
+ * 由调用方给出提示;
7
+ * - 永不发表外命令:旧版 Pi 对未知命令的应答不带 id,请求无从关联(Armadra#710 的根因)。
8
+ */
9
+ import { versionSatisfies } from "../../drivers/probe.js";
10
+ export const PI_FLOOR = "1.1.0";
11
+ export const PI_VERIFIED = ">=1.1.0 <2.0.0";
12
+ export const PI_PACKAGE = "@earendil-works/pi-coding-agent";
13
+ /** 能力 id → 起始版本(含)。 */
14
+ export const PI_CAPABILITY_SINCE = {
15
+ /** `--session-id`:新开与接回都用它。 */
16
+ sessionId: "0.76.0",
17
+ /** `agent_settled` 事件:判定回合结束。 */
18
+ agentSettled: "0.80.4",
19
+ /** `agent_settled.aborted`:判定取消。 */
20
+ settledAborted: "1.1.0",
21
+ /** `get_available_thinking_levels`:thought_level 配置项。 */
22
+ thinkingLevels: "0.81.0",
23
+ /** `prompt` 应答里的 `disposition`:`handled` 时不等回合。 */
24
+ disposition: "0.99.0",
25
+ /** 内置 MCP、`pi.registerMcpServer`、工具 `annotations`。 */
26
+ mcp: "0.99.0",
27
+ /** `get_session_stats` 的 `cost` / `contextUsage`。 */
28
+ sessionStats: "0.63.0",
29
+ /** `Usage.cost.totalFromProvider`:区分账单值与价目表估算。 */
30
+ costFromProvider: "1.5.0",
31
+ };
32
+ /** 桥会发的 RPC 命令 → 起始版本(都不晚于下限,除 thinking 外)。 */
33
+ export const PI_COMMAND_SINCE = {
34
+ get_state: "0.76.0",
35
+ get_messages: "0.76.0",
36
+ prompt: "0.76.0",
37
+ steer: "0.76.0",
38
+ abort: "0.76.0",
39
+ set_model: "0.76.0",
40
+ get_available_models: "0.76.0",
41
+ set_thinking_level: "0.76.0",
42
+ get_available_thinking_levels: PI_CAPABILITY_SINCE.thinkingLevels,
43
+ get_session_stats: PI_CAPABILITY_SINCE.sessionStats,
44
+ };
45
+ function atLeast(version, since) {
46
+ return versionSatisfies(version, `>=${since}`);
47
+ }
48
+ /** 按版本求能力与可发命令;`undefined`(读不出)与高于区间一样按最高已知能力。 */
49
+ export function piVersionInfo(version) {
50
+ const known = version !== undefined;
51
+ const has = (since) => !known || atLeast(version, since);
52
+ const capabilities = Object.fromEntries(Object.keys(PI_CAPABILITY_SINCE).map((id) => [
53
+ id,
54
+ has(PI_CAPABILITY_SINCE[id]),
55
+ ]));
56
+ const commands = new Set(Object.keys(PI_COMMAND_SINCE).filter((c) => has(PI_COMMAND_SINCE[c])));
57
+ const status = !known
58
+ ? "unknown"
59
+ : !atLeast(version, PI_FLOOR)
60
+ ? "unsupported"
61
+ : versionSatisfies(version, PI_VERIFIED)
62
+ ? "verified"
63
+ : "newer";
64
+ return { status, ...(known ? { version } : {}), capabilities, commands };
65
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 桥的会话配置项(#254):`model` 与 `thought_level` 两个 select。
3
+ *
4
+ * - `model`:值 `provider/id`(`get_available_models`),按供应商分组;当前模型不在列表里时补一项;
5
+ * - `thought_level`:值是 Pi 的级别(`get_available_thinking_levels`,`off`…`max`),是唯一的推理强度控件,
6
+ * 不进 `modes`;当前模型只支持 `off`(不支持推理)时不给这一项。
7
+ */
8
+ import type { AcpSessionConfigOption } from "../../drivers/acp/types.js";
9
+ export declare const CONFIG_IDS: {
10
+ readonly model: "model";
11
+ readonly thoughtLevel: "thought_level";
12
+ };
13
+ export interface PiModelRef {
14
+ provider: string;
15
+ id: string;
16
+ name?: string;
17
+ }
18
+ /** 配置项依赖的 Pi 状态快照。 */
19
+ export interface ConfigState {
20
+ models: readonly PiModelRef[];
21
+ current?: PiModelRef;
22
+ /** `get_available_thinking_levels`(读不到为空)。 */
23
+ levels: readonly string[];
24
+ level?: string;
25
+ }
26
+ export declare function modelRefOf(value: unknown): PiModelRef | undefined;
27
+ export declare const modelValue: (m: PiModelRef) => string;
28
+ export declare function buildConfigOptions(state: ConfigState): AcpSessionConfigOption[];
@@ -0,0 +1,67 @@
1
+ /**
2
+ * 桥的会话配置项(#254):`model` 与 `thought_level` 两个 select。
3
+ *
4
+ * - `model`:值 `provider/id`(`get_available_models`),按供应商分组;当前模型不在列表里时补一项;
5
+ * - `thought_level`:值是 Pi 的级别(`get_available_thinking_levels`,`off`…`max`),是唯一的推理强度控件,
6
+ * 不进 `modes`;当前模型只支持 `off`(不支持推理)时不给这一项。
7
+ */
8
+ import { msg } from "../../i18n/index.js";
9
+ export const CONFIG_IDS = { model: "model", thoughtLevel: "thought_level" };
10
+ export function modelRefOf(value) {
11
+ if (value === null || typeof value !== "object")
12
+ return undefined;
13
+ const m = value;
14
+ if (typeof m["id"] !== "string" || typeof m["provider"] !== "string")
15
+ return undefined;
16
+ return {
17
+ provider: m["provider"],
18
+ id: m["id"],
19
+ ...(typeof m["name"] === "string" && m["name"] !== "" ? { name: m["name"] } : {}),
20
+ };
21
+ }
22
+ export const modelValue = (m) => `${m.provider}/${m.id}`;
23
+ function levelName(level) {
24
+ const names = msg().bridge.config.levels;
25
+ return names[level] ?? level;
26
+ }
27
+ export function buildConfigOptions(state) {
28
+ const m = msg().bridge.config;
29
+ const options = [];
30
+ const models = [...state.models];
31
+ if (state.current !== undefined &&
32
+ !models.some((x) => modelValue(x) === modelValue(state.current)))
33
+ models.unshift(state.current);
34
+ if (state.current !== undefined) {
35
+ const groups = new Map();
36
+ for (const model of models) {
37
+ let group = groups.get(model.provider);
38
+ if (group === undefined) {
39
+ group = { group: model.provider, name: model.provider, options: [] };
40
+ groups.set(model.provider, group);
41
+ }
42
+ group.options.push({ value: modelValue(model), name: model.name ?? model.id });
43
+ }
44
+ options.push({
45
+ id: CONFIG_IDS.model,
46
+ name: m.model,
47
+ category: "model",
48
+ type: "select",
49
+ currentValue: modelValue(state.current),
50
+ options: [...groups.values()],
51
+ });
52
+ }
53
+ const levels = state.levels.filter((l) => l !== "");
54
+ if (levels.some((l) => l !== "off")) {
55
+ options.push({
56
+ id: CONFIG_IDS.thoughtLevel,
57
+ name: m.thoughtLevel,
58
+ category: "thought_level",
59
+ type: "select",
60
+ currentValue: state.level !== undefined && levels.includes(state.level)
61
+ ? state.level
62
+ : (levels[0] ?? "off"),
63
+ options: levels.map((level) => ({ value: level, name: levelName(level) })),
64
+ });
65
+ }
66
+ return options;
67
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Pi 扩展的对话框 → ACP `elicitation/create`(#254)。
3
+ *
4
+ * 客户端声明了 `elicitation` 时,其它扩展经 RPC 发来的 select / confirm / input / editor 转成 form 型征询:
5
+ * - select → 带标题的枚举(`oneOf`);confirm → boolean;input / editor → string(editor 的预填作默认值);
6
+ * - `accept` → 把值回给 Pi;`decline` / `cancel` / 出错 → Pi 一侧 `cancelled: true`;
7
+ * - 桥从不替人填表,也不挑选项。
8
+ *
9
+ * ama 自己的对话框(审批闸、拒绝理由、能力报告)不走这里;桥也不注册自己的 todo / 问卷工具——Pi 里没有对应
10
+ * 扩展时,什么也不加,缺口体现在 `_meta["armadra.pi"].capabilities`。
11
+ */
12
+ import type { AcpElicitationSchema } from "../../drivers/acp/types.js";
13
+ import type { Json } from "./tools.js";
14
+ export interface ElicitationPlan {
15
+ /** 给人看的说明(Pi 扩展给的标题,confirm 附上正文)。 */
16
+ message: string;
17
+ schema: AcpElicitationSchema;
18
+ /** `accept` 的内容 → 回给 Pi 的 `extension_ui_response` 正文;内容不合就取消。 */
19
+ toResponse(content: Record<string, unknown> | null | undefined): Json;
20
+ }
21
+ /** 为一个 Pi 对话框请求建征询;不是四种对话框、或没有可选项的 select 返回 undefined(按取消处理)。 */
22
+ export declare function planElicitation(record: Json): ElicitationPlan | undefined;
23
+ export declare const CANCELLED_RESPONSE: Json;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Pi 扩展的对话框 → ACP `elicitation/create`(#254)。
3
+ *
4
+ * 客户端声明了 `elicitation` 时,其它扩展经 RPC 发来的 select / confirm / input / editor 转成 form 型征询:
5
+ * - select → 带标题的枚举(`oneOf`);confirm → boolean;input / editor → string(editor 的预填作默认值);
6
+ * - `accept` → 把值回给 Pi;`decline` / `cancel` / 出错 → Pi 一侧 `cancelled: true`;
7
+ * - 桥从不替人填表,也不挑选项。
8
+ *
9
+ * ama 自己的对话框(审批闸、拒绝理由、能力报告)不走这里;桥也不注册自己的 todo / 问卷工具——Pi 里没有对应
10
+ * 扩展时,什么也不加,缺口体现在 `_meta["armadra.pi"].capabilities`。
11
+ */
12
+ import { oneLine } from "../../drivers/turn.js";
13
+ const CANCELLED = { cancelled: true };
14
+ function label(record, fallback) {
15
+ const title = record["title"];
16
+ return typeof title === "string" && title !== "" ? oneLine(title, 200) : fallback;
17
+ }
18
+ /** 为一个 Pi 对话框请求建征询;不是四种对话框、或没有可选项的 select 返回 undefined(按取消处理)。 */
19
+ export function planElicitation(record) {
20
+ const method = String(record["method"] ?? "");
21
+ const title = label(record, method);
22
+ const string = (v) => (typeof v === "string" ? v : undefined);
23
+ switch (method) {
24
+ case "select": {
25
+ const options = Array.isArray(record["options"])
26
+ ? record["options"].filter((o) => typeof o === "string")
27
+ : [];
28
+ if (options.length === 0)
29
+ return undefined;
30
+ return {
31
+ message: title,
32
+ schema: {
33
+ type: "object",
34
+ properties: {
35
+ value: { type: "string", title, oneOf: options.map((o) => ({ const: o, title: o })) },
36
+ },
37
+ required: ["value"],
38
+ },
39
+ toResponse: (content) => {
40
+ const value = content?.["value"];
41
+ return typeof value === "string" && options.includes(value) ? { value } : CANCELLED;
42
+ },
43
+ };
44
+ }
45
+ case "confirm": {
46
+ const body = string(record["message"]);
47
+ return {
48
+ message: body !== undefined && body !== "" ? `${title}\n${oneLine(body, 400)}` : title,
49
+ schema: {
50
+ type: "object",
51
+ properties: { confirmed: { type: "boolean", title, default: false } },
52
+ required: ["confirmed"],
53
+ },
54
+ toResponse: (content) => ({ confirmed: content?.["confirmed"] === true }),
55
+ };
56
+ }
57
+ case "input":
58
+ case "editor": {
59
+ const hint = string(record[method === "input" ? "placeholder" : "prefill"]);
60
+ return {
61
+ message: title,
62
+ schema: {
63
+ type: "object",
64
+ properties: {
65
+ value: {
66
+ type: "string",
67
+ title,
68
+ ...(method === "input" && hint !== undefined && hint !== ""
69
+ ? { description: oneLine(hint, 200) }
70
+ : {}),
71
+ ...(method === "editor" && hint !== undefined ? { default: hint } : {}),
72
+ },
73
+ },
74
+ required: ["value"],
75
+ },
76
+ toResponse: (content) => {
77
+ const value = content?.["value"];
78
+ return typeof value === "string" ? { value } : CANCELLED;
79
+ },
80
+ };
81
+ }
82
+ default:
83
+ return undefined;
84
+ }
85
+ }
86
+ export const CANCELLED_RESPONSE = CANCELLED;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `ama --mode acp --bridge pi` 的进程入口(#254)。
3
+ *
4
+ * bootstrap 之前分流:不解析供应商与模型,不需要 ama 的 key 或会话;stdin / stdout 是 ACP(NDJSON),
5
+ * 诊断写 stderr。退出语义同 `--mode acp`:stdin 关闭 → 收掉全部 Pi 子进程 → 退出 0;SIGINT / SIGTERM → 130 / 143。
6
+ */
7
+ import type { CliIo } from "../../cli/deps.js";
8
+ import { type BridgeDeps } from "./server.js";
9
+ export interface BridgeRunOptions {
10
+ stdin?: NodeJS.ReadableStream;
11
+ stdout?: NodeJS.WritableStream;
12
+ deps?: BridgeDeps;
13
+ }
14
+ export declare function runBridge(argv: readonly string[], io: Pick<CliIo, "stderr" | "env">, options?: BridgeRunOptions): Promise<number>;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * `ama --mode acp --bridge pi` 的进程入口(#254)。
3
+ *
4
+ * bootstrap 之前分流:不解析供应商与模型,不需要 ama 的 key 或会话;stdin / stdout 是 ACP(NDJSON),
5
+ * 诊断写 stderr。退出语义同 `--mode acp`:stdin 关闭 → 收掉全部 Pi 子进程 → 退出 0;SIGINT / SIGTERM → 130 / 143。
6
+ */
7
+ import { reportError } from "../../cli/bootstrap.js";
8
+ import { ExitCode } from "../../cli/exit-codes.js";
9
+ import { createAcpConnection } from "../../modes/acp/acp-connection.js";
10
+ import { onTerminationSignals } from "../../modes/shared.js";
11
+ import { RpcError } from "../../drivers/jsonrpc.js";
12
+ import { RPC_ERRORS } from "../../drivers/acp/types.js";
13
+ import { parseBridgeArgs } from "./args.js";
14
+ import { PiBridgeServer } from "./server.js";
15
+ export async function runBridge(argv, io, options = {}) {
16
+ let passthrough;
17
+ try {
18
+ passthrough = parseBridgeArgs(argv).passthrough;
19
+ }
20
+ catch (error) {
21
+ return reportError(error, io);
22
+ }
23
+ const stdin = options.stdin ?? process.stdin;
24
+ const stdout = options.stdout ?? process.stdout;
25
+ const log = (message) => io.stderr(`ama: ${message}\n`);
26
+ const target = {};
27
+ const connection = createAcpConnection({ input: stdin, output: stdout }, log, {
28
+ onRequest: async (method, params, ctx) => {
29
+ if (target.server === undefined)
30
+ throw new RpcError(RPC_ERRORS.internalError, method);
31
+ return target.server.handle(method, (params ?? {}), ctx);
32
+ },
33
+ onNotification: (method, params) => target.server?.handleNotification(method, params),
34
+ });
35
+ const server = new PiBridgeServer({
36
+ connection,
37
+ passthrough,
38
+ env: io.env,
39
+ log,
40
+ ...(options.deps !== undefined ? { deps: options.deps } : {}),
41
+ });
42
+ target.server = server;
43
+ return new Promise((resolve) => {
44
+ let finished = false;
45
+ const finish = async (code) => {
46
+ if (finished)
47
+ return;
48
+ finished = true;
49
+ offSignals();
50
+ stdin.pause?.();
51
+ await server.dispose();
52
+ await connection.peer.flush();
53
+ connection.peer.close();
54
+ resolve(code);
55
+ };
56
+ void connection.peer.closed.then(() => finish(ExitCode.Ok));
57
+ const offSignals = onTerminationSignals((code) => void finish(code));
58
+ });
59
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Pi 事件 → ACP `session/update`(#254)。
3
+ *
4
+ * - `message_update` 的 text / thinking delta → `agent_message_chunk` / `agent_thought_chunk`;
5
+ * - `tool_execution_start|update|end` → `tool_call` / `tool_call_update`(标题、类别、位置沿用驱动的规则;
6
+ * `partialResult` 与 `result` 转成内容;`rawInput` 带参数)。审批闸在 `tool_execution_start` 之后才问,
7
+ * 所以要过闸的调用先以 `pending` 公布(权限请求关联到它),放行后 `markRunning` 转 `in_progress`;只读内置工具直接 `in_progress`;
8
+ * - MCP 工具(`mcp__<server>__<tool>`,只认桥注册过的服务器)写 `_meta.is_mcp_tool_call` 与
9
+ * `rawInput {server, tool, arguments}`,客户端据此识别自家工具;codemode 里发起的内层调用带
10
+ * `_meta.ama.parentToolCallId`;
11
+ * - 结果的 `details.todos` → `plan`(整表);子 Agent 工具(`subagent`)写 `_meta["armadra.subagent"]`;
12
+ * - assistant 的 `message_end` 累加本回合用量(input 不含缓存命中)与费用来源。
13
+ */
14
+ import { type AcpPromptUsage, type AcpSessionUpdate, type AcpToolCall } from "../../drivers/acp/types.js";
15
+ import { type Json } from "./tools.js";
16
+ export interface EventsOptions {
17
+ cwd: string;
18
+ emit(update: AcpSessionUpdate): void;
19
+ /** 桥注册给 Pi 的 MCP 服务器名(客户端给的原样)。 */
20
+ mcpServers(): readonly string[];
21
+ }
22
+ export declare class PiEventMapper {
23
+ private readonly options;
24
+ /** 已公布的工具调用(id → 展示字段),供审批关联与结束时补全。 */
25
+ private readonly published;
26
+ private usage;
27
+ /** 本会话里 assistant 消息的费用是否都是账单值(`cost.totalFromProvider`)。 */
28
+ private costMessages;
29
+ private costFromProvider;
30
+ private last;
31
+ constructor(options: EventsOptions);
32
+ /** 回合开始:清空本回合用量。 */
33
+ resetTurn(): void;
34
+ /** 本回合最后一条 assistant 消息(判停止原因、取最终文本)。 */
35
+ lastAssistant(): Json | undefined;
36
+ /** 本回合累加的用量(没收到任何 assistant 消息返回 undefined)。 */
37
+ turnUsage(): AcpPromptUsage | undefined;
38
+ /** 费用是否全是账单值:没见过任何带费用的 assistant 消息时 undefined。 */
39
+ costIsFromProvider(): boolean | undefined;
40
+ /** 已公布调用的标题与类别。 */
41
+ toolInfo(id: string): {
42
+ title: string;
43
+ kind: AcpToolCall["kind"];
44
+ } | undefined;
45
+ /** 审批闸放行:调用从 `pending` 转为 `in_progress`。 */
46
+ markRunning(id: string): void;
47
+ onEvent(record: Json): void;
48
+ private onMessageUpdate;
49
+ private onMessageEnd;
50
+ private mcpRef;
51
+ /** 一次调用的展示字段(`tool_call` 与权限请求的 `toolCall` 共用)。 */
52
+ describe(tool: string, input: Json, record?: Json): Omit<AcpToolCall, "toolCallId" | "status"> & {
53
+ title: string;
54
+ };
55
+ /** 公布一个新调用(`tool_call`)。 */
56
+ private publish;
57
+ /** `_meta`:自家工具标记(顶层,客户端约定)与 ama 命名空间下的父调用。 */
58
+ private metaOf;
59
+ private onToolStart;
60
+ private onToolUpdate;
61
+ private onToolEnd;
62
+ }