@armadra/agent 0.11.0 → 0.13.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,25 @@ 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.13.0 (2026-11-04)
9
+
10
+ ### Maintenance
11
+
12
+ - **Maintenance release aligned with the unified version**: no user-visible changes. Timing-sensitive tests (scripted provider, background approval docking, the code-mode sandbox timeout, session stats and trace generation) now use gates and manual clocks instead of wall-clock sleeps and absolute time limits; the absolute limits are asserted only with `AMA_PERF=1` (#249, #250).
13
+
14
+ ## 0.12.0 (2026-11-02)
15
+
16
+ ### Tools and permissions
17
+
18
+ - **The `coordinator` preset never blocks**: when `task` / `task_ctl` are exposed, `task` defaults to background (regardless of `-p` and `subagents.background`; an explicit `background` argument and an agent definition's `background:` still win) and `task_ctl wait` is capped at 5 s (the default and larger `timeoutMs` included); the timed-out reply says the wait was capped and that a `<task-notification>` follows. Other presets, tool descriptions and schemas are byte-identical (#242).
19
+ - **`env` / `printenv` are no longer auto-safe**: the bash subprocess inherits the whole process environment (provider API keys included), so in Auto mode a bare `env`, `printenv`, `env FOO=1` or `env | grep …` now goes to the classifier / approval instead of being allowed statically; `env FOO=1 cmd` is still judged as `cmd`. The read-only list for Plan already excluded them, so both lists now agree (#240).
20
+
21
+ ### ACP client
22
+
23
+ - **Authentication**: `AcpClient.authenticate(methodId)` and `logout()` (`supportsLogout()`), `isAuthRequiredError` for -32000, and the `authTerminal` option that declares `clientCapabilities.auth.terminal`. `authMethods` keeps id, name, description, type and, for terminal methods, `args` / `env`; a known terminal method is refused locally by `authenticate` (-32602) as the spec requires. `isTerminalAuthMethod` and the types `AcpAuthenticateResult`, `AcpLogoutResult`, `AcpTerminalAuthMethod` are exported (#245).
24
+ - **`elicitation/complete` and richer forms**: `onElicitationComplete` handles the notification (declaring `elicitation: { form: {}, url: {} }`) and dismisses a still-pending request with the same `elicitationId`; form fields gain `array` multi-select and titled `oneOf` / `anyOf`, `content` values may be string arrays, and `multiSelectOptions` / `singleSelectOptions` normalize the option lists (#245).
25
+ - **Sessions**: `listSessions` takes a `signal`, `listAllSessions` follows `nextCursor`, `closeSession` takes a `signal` and first answers the session's pending permission and elicitation requests with cancel; `AcpSessionInfo` gains `additionalDirectories` and `_meta`. `AcpClient.features` gains `auth` and `elicitationComplete`. Default wire output is unchanged unless the new options are used (#245).
26
+
8
27
  ## 0.11.0 (2026-10-30)
9
28
 
10
29
  ### Tools and permissions
@@ -4,6 +4,25 @@
4
4
 
5
5
  > 从 0.6.0 起 [CHANGELOG.md](CHANGELOG.md) 为英文,本文件保留中文记录(0.1–0.5.1 的完整历史在此)。新条目两份都要加。
6
6
 
7
+ ## 0.13.0(2026-11-04)
8
+
9
+ ### 维护
10
+
11
+ - **与统一版本对齐的维护版**:没有用户可见的变化。对时间敏感的测试(脚本化供应商、后台审批停靠、代码模式沙箱超时、会话统计与轨迹生成)改用闸门与手动时钟,不再靠墙钟睡眠与绝对时限;绝对时限只在 `AMA_PERF=1` 时断言(#249、#250)。
12
+
13
+ ## 0.12.0(2026-11-02)
14
+
15
+ ### 工具与权限
16
+
17
+ - **`coordinator` 预设不阻塞**:暴露 `task` / `task_ctl` 时,`task` 缺省后台(不受 `-p` 与 `subagents.background` 影响,调用参数 `background` 与类型定义的 `background:` 仍优先),`task_ctl wait` 的超时封顶 5 秒(含缺省与更大的 `timeoutMs`),超时回复说明被封顶、完成后会有 `<task-notification>`。其它预设、工具描述与 schema 逐字节不变(#242)。
18
+ - **`env` / `printenv` 不再免审批**:bash 子进程继承整个进程环境(含供应商 API key),Auto 模式下裸 `env`、`printenv`、`env FOO=1`、`env | grep …` 现在交给分类器 / 审批,不再静态放行;`env FOO=1 cmd` 仍按 `cmd` 判断。Plan 的只读名单本来就没有它们,两份名单现在一致(#240)。
19
+
20
+ ### ACP 客户端
21
+
22
+ - **认证**:`AcpClient.authenticate(methodId)` 与 `logout()`(`supportsLogout()`)、判断 -32000 的 `isAuthRequiredError`,以及声明 `clientCapabilities.auth.terminal` 的构造参数 `authTerminal`。`authMethods` 保留 id、name、description、type,terminal 型还有 `args` / `env`;已知是 terminal 型的方法按规范由 `authenticate` 本地拒绝(-32602)。新增导出 `isTerminalAuthMethod` 与类型 `AcpAuthenticateResult`、`AcpLogoutResult`、`AcpTerminalAuthMethod`(#245)。
23
+ - **`elicitation/complete` 与更丰富的表单**:`onElicitationComplete` 接这条通知(声明 `elicitation: { form: {}, url: {} }`),并收掉同 `elicitationId` 还挂着的请求;表单字段新增 `array` 多选与带标题的 `oneOf` / `anyOf`,`content` 的值可以是字符串数组,`multiSelectOptions` / `singleSelectOptions` 把几种写法收成统一的选项列表(#245)。
24
+ - **会话**:`listSessions` 可传 `signal`,新增跟 `nextCursor` 翻页的 `listAllSessions`;`closeSession` 可传 `signal`,并先把该会话挂起的权限与 elicitation 请求答成取消;`AcpSessionInfo` 补 `additionalDirectories`、`_meta`。`AcpClient.features` 增加 `auth` 与 `elicitationComplete`。不用新选项时默认线路输出不变(#245)。
25
+
7
26
  ## 0.11.0(2026-10-30)
8
27
 
9
28
  ### 工具与权限
package/dist/acp.d.ts CHANGED
@@ -8,10 +8,10 @@
8
8
  */
9
9
  export type * from "./drivers/types.js";
10
10
  export type * from "./drivers/acp/types.js";
11
- export { ACP_META_KEY, ACP_METHODS, ACP_PROTOCOL_VERSION, RPC_ERRORS, } from "./drivers/acp/types.js";
11
+ export { ACP_META_KEY, isTerminalAuthMethod, multiSelectOptions, singleSelectOptions, ACP_METHODS, ACP_PROTOCOL_VERSION, RPC_ERRORS, } from "./drivers/acp/types.js";
12
12
  export { WRITE_CHUNK_BYTES, createLineReader, writeChunked, type LineReader, } from "./modes/rpc/jsonl.js";
13
13
  export { JsonRpcPeer, RpcError, type IncomingRequestContext, type JsonRpcPeerOptions, type RpcId, } from "./drivers/jsonrpc.js";
14
- export { AcpClient, unattendedOutcome, type AcpClientHandlers, type AcpClientOptions, } from "./drivers/acp/client.js";
14
+ export { AcpClient, isAuthRequiredError, unattendedOutcome, type AcpClientHandlers, type AcpClientOptions, } from "./drivers/acp/client.js";
15
15
  export { AcpDriver } from "./drivers/acp/driver.js";
16
16
  export { runFakeAcpAgent, type FakeAcpAgentOptions } from "./drivers/acp/testing/fake-agent.js";
17
17
  /** 假 ACP Agent 的可执行入口(`node <path> [--minimal] [--config-options] [--config-only] [--auth-required]`);只在已编译的包里存在。 */
package/dist/acp.js CHANGED
@@ -7,10 +7,10 @@
7
7
  * - 假 ACP Agent(进程内 `runFakeAcpAgent`,或 `fakeAcpAgentPath()` 起子进程),用于黄金记录。
8
8
  */
9
9
  import { fileURLToPath } from "node:url";
10
- export { ACP_META_KEY, ACP_METHODS, ACP_PROTOCOL_VERSION, RPC_ERRORS, } from "./drivers/acp/types.js";
10
+ export { ACP_META_KEY, isTerminalAuthMethod, multiSelectOptions, singleSelectOptions, ACP_METHODS, ACP_PROTOCOL_VERSION, RPC_ERRORS, } from "./drivers/acp/types.js";
11
11
  export { WRITE_CHUNK_BYTES, createLineReader, writeChunked, } from "./modes/rpc/jsonl.js";
12
12
  export { JsonRpcPeer, RpcError, } from "./drivers/jsonrpc.js";
13
- export { AcpClient, unattendedOutcome, } from "./drivers/acp/client.js";
13
+ export { AcpClient, isAuthRequiredError, unattendedOutcome, } from "./drivers/acp/client.js";
14
14
  export { AcpDriver } from "./drivers/acp/driver.js";
15
15
  export { runFakeAcpAgent } from "./drivers/acp/testing/fake-agent.js";
16
16
  /** 假 ACP Agent 的可执行入口(`node <path> [--minimal] [--config-options] [--config-only] [--auth-required]`);只在已编译的包里存在。 */
@@ -54,12 +54,18 @@ export declare class FakeProvider {
54
54
  private readonly recordFile;
55
55
  private readonly keepCalls;
56
56
  private count;
57
+ private readonly gates;
57
58
  constructor(script?: FakeScript | FakeResponse[] | (() => FakeScript | undefined), options?: FakeProviderOptions);
58
59
  readonly api: ApiImplementation;
59
60
  get callCount(): number;
60
61
  setScript(script: FakeScript | FakeResponse[]): void;
61
62
  append(...responses: FakeResponse[]): void;
62
63
  reset(): void;
64
+ private gate;
65
+ /** 放行名为 `name` 的闸门(`FakeResponse.gate`):正在等的调用继续,之后到达的也直接通过。 */
66
+ release(name: string): void;
67
+ /** 正停在闸门 `name` 上的调用个数(测试确认「请求已发出、正在等」)。 */
68
+ waitingAt(name: string): number;
63
69
  private ensureLoaded;
64
70
  /** 第 index 次调用的响应;undefined = 回显。 */
65
71
  private responseFor;
@@ -96,6 +96,21 @@ function sleep(ms, signal) {
96
96
  function tick() {
97
97
  return new Promise((resolve) => setImmediate(resolve));
98
98
  }
99
+ /** 等闸门放行;abort 时提前返回(随后由 checkAbort 收尾)。 */
100
+ function waitOpen(open, signal) {
101
+ return new Promise((resolve) => {
102
+ if (signal.aborted) {
103
+ resolve();
104
+ return;
105
+ }
106
+ const done = () => {
107
+ signal.removeEventListener("abort", done);
108
+ resolve();
109
+ };
110
+ signal.addEventListener("abort", done, { once: true });
111
+ void open.then(done);
112
+ });
113
+ }
99
114
  class AbortedError extends Error {
100
115
  }
101
116
  export class FakeProvider {
@@ -106,6 +121,7 @@ export class FakeProvider {
106
121
  recordFile;
107
122
  keepCalls;
108
123
  count = 0;
124
+ gates = new Map();
109
125
  constructor(script, options = {}) {
110
126
  if (typeof script === "function")
111
127
  this.scriptLoader = script;
@@ -134,6 +150,25 @@ export class FakeProvider {
134
150
  reset() {
135
151
  this.calls.length = 0;
136
152
  this.count = 0;
153
+ this.gates.clear();
154
+ }
155
+ gate(name) {
156
+ let gate = this.gates.get(name);
157
+ if (gate === undefined) {
158
+ let release;
159
+ const open = new Promise((resolve) => (release = resolve));
160
+ gate = { open, release, waiting: 0 };
161
+ this.gates.set(name, gate);
162
+ }
163
+ return gate;
164
+ }
165
+ /** 放行名为 `name` 的闸门(`FakeResponse.gate`):正在等的调用继续,之后到达的也直接通过。 */
166
+ release(name) {
167
+ this.gate(name).release();
168
+ }
169
+ /** 正停在闸门 `name` 上的调用个数(测试确认「请求已发出、正在等」)。 */
170
+ waitingAt(name) {
171
+ return this.gates.get(name)?.waiting ?? 0;
137
172
  }
138
173
  ensureLoaded() {
139
174
  if (this.loaded)
@@ -202,6 +237,17 @@ export class FakeProvider {
202
237
  };
203
238
  try {
204
239
  options.onPayload?.({ fake: true, model: model.id, messages: context.messages.length });
240
+ if (response.gate !== undefined) {
241
+ const gate = this.gate(response.gate);
242
+ gate.waiting++;
243
+ try {
244
+ await waitOpen(gate.open, signal);
245
+ }
246
+ finally {
247
+ gate.waiting--;
248
+ }
249
+ checkAbort();
250
+ }
205
251
  if (response.delayMs)
206
252
  await sleep(response.delayMs, signal);
207
253
  checkAbort();
@@ -9,7 +9,8 @@
9
9
  * { "error": { "kind": "rate_limit" } },
10
10
  * { "text": "完成", "usage": { "input": 1200, "output": 30 } },
11
11
  * { "steps": [{ "text": "写到一半" }], "error": { "kind": "disconnect" } },
12
- * { "delayMs": 500, "text": "慢响应", "stopReason": "length" }
12
+ * { "delayMs": 500, "text": "慢响应", "stopReason": "length" },
13
+ * { "gate": "reply", "text": "等放行(进程内测试 provider.release('reply'))" }
13
14
  * ] }
14
15
  * ```
15
16
  *
@@ -57,6 +58,12 @@ export interface FakeResponse {
57
58
  error?: FakeError;
58
59
  /** start 之前的延迟(毫秒,可被 abort 打断)。 */
59
60
  delayMs?: number;
61
+ /**
62
+ * start 之前的闸门:这次调用停在闸门上,直到进程内的 `FakeProvider.release(gate)` 放行(可被 abort 打断;
63
+ * 先放行再调用也立即通过)。测试用它显式控制「谁先回」,不靠 `delayMs` 的墙钟。脚本文件里没人放行,
64
+ * 仅用于进程内测试;与 `delayMs` 同给时先过闸门再延迟。
65
+ */
66
+ gate?: string;
60
67
  }
61
68
  export type FakeExhaustedBehavior = "echo" | "repeat-last" | "error";
62
69
  export interface FakeScript {
@@ -9,7 +9,8 @@
9
9
  * { "error": { "kind": "rate_limit" } },
10
10
  * { "text": "完成", "usage": { "input": 1200, "output": 30 } },
11
11
  * { "steps": [{ "text": "写到一半" }], "error": { "kind": "disconnect" } },
12
- * { "delayMs": 500, "text": "慢响应", "stopReason": "length" }
12
+ * { "delayMs": 500, "text": "慢响应", "stopReason": "length" },
13
+ * { "gate": "reply", "text": "等放行(进程内测试 provider.release('reply'))" }
13
14
  * ] }
14
15
  * ```
15
16
  *
@@ -65,6 +66,9 @@ function checkResponse(value, path) {
65
66
  if (value["text"] !== undefined && typeof value["text"] !== "string") {
66
67
  fail(`${path}.text`, "must be a string");
67
68
  }
69
+ if (value["gate"] !== undefined && typeof value["gate"] !== "string") {
70
+ fail(`${path}.gate`, "must be a string");
71
+ }
68
72
  const stop = value["stopReason"];
69
73
  if (stop !== undefined &&
70
74
  stop !== "stop" &&