agent-bridge-service 1.0.0 → 1.1.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,24 @@ All notable changes to this project are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres
6
6
  to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.0](https://github.com/shaylanwu/agent-bridge/compare/v1.0.0...v1.1.0) (2026-11-27)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **codex:** app-server 子进程注入外部代理并排空 stderr,修掉「回合静默挂住」 ([d685f22](https://github.com/shaylanwu/agent-bridge/commit/d685f227596f799a154322d573f9311f30a0e138))
14
+
15
+
16
+ ### Features
17
+
18
+ * **codex:** 重连/配置告警上行成任务日志,不再整段静默 ([d31a2f4](https://github.com/shaylanwu/agent-bridge/commit/d31a2f45e4b3e865cdf995e80054b2b75f29abe2))
19
+ * **gateway:** 控制面与 ACP 会话可按任务申请交互(allowInteractive 透传) ([f88e900](https://github.com/shaylanwu/agent-bridge/commit/f88e9005f1da627a4623dcf318d2a2125eb64ee5))
20
+
21
+
22
+ ### Performance Improvements
23
+
24
+ * **proxy-env:** 系统代理探测按进程缓存,每进程只查一次注册表 ([da1f3ee](https://github.com/shaylanwu/agent-bridge/commit/da1f3ee718f7a6fdac51e66824839a011a776f30))
25
+
8
26
  ## [1.0.0](https://github.com/shaylanwu/agent-bridge/compare/v0.2.3...v1.0.0) (2026-11-26)
9
27
 
10
28
 
package/README.md CHANGED
@@ -145,10 +145,12 @@ code of the official `traecli login status`; installation directories are not tr
145
145
  output is never reported. Note: trae-cli 0.121.3 ships no `login` subcommand — it authenticates through the OS
146
146
  keyring written by the Trae IDE team/enterprise sign-in, or the PAT env above; without either, no model task can run.
147
147
 
148
- For agy's external requests, set `AGENT_BRIDGE_EXTERNAL_PROXY` explicitly or let Windows read the current user's
149
- system proxy. This avoids Google API 502s when the WorkBuddy process proxy differs from the system proxy, without
150
- hardcoding a local port. agy declares ACP starting at 1.5.9; older versions remain headless-only. First and resumed
151
- turns were verified, while permission/form interactions that were not tested individually are not declared.
148
+ For agy and codex, external requests use `AGENT_BRIDGE_EXTERNAL_PROXY` when set, otherwise Windows reads the
149
+ current user's system proxy; set it to `off` (or `none`) to inject nothing and connect directly. This avoids
150
+ Google API 502s when the WorkBuddy process proxy differs from the system proxy, and keeps codex's responses
151
+ WebSocket from stalling for ~113s on a direct route, without hardcoding a local port. agy declares ACP starting
152
+ at 1.5.9; older versions remain headless-only. First and resumed turns were verified, while permission/form
153
+ interactions that were not tested individually are not declared.
152
154
 
153
155
  ### Stable device identity and local state
154
156
 
@@ -714,7 +716,7 @@ Remote platforms keep using the outbound WebSocket; this is a separate channel,
714
716
  | GET | `/v1/interactions?taskId=&state=&limit=` | `session:read` or `task:read` (bounded interaction list; `state=pending` is the common one) |
715
717
  | GET | `/v1/interactions/{requestId}` | `session:read` or `task:read` (one interaction: pending request or settled result) |
716
718
  | POST | `/v1/interactions/{requestId}:respond` | `task:approve` for permission, `task:respond` for form/auth-url (same rule and same code path as the WS `task_interaction_response`) |
717
- | POST | `/v1/tasks` | `task:create` |
719
+ | POST | `/v1/tasks` | `task:create` (body may carry `allowInteractive: true` to request interactions for that task; still requires `--interaction-enabled`) |
718
720
  | GET | `/v1/tasks` | `task:read` (cursor-paginated) |
719
721
  | GET | `/v1/tasks/{id}` | `task:read` |
720
722
  | POST | `/v1/tasks/{id}:cancel` | `task:cancel` (idempotent) |
@@ -794,6 +796,10 @@ gateway route returns 404. The `a2a` / `acp` sub-flags turn individual surfaces
794
796
  approve/respond loop itself only exists on the bridge wire (`task_interaction_request/response`) and on
795
797
  the ACP surface (`session/request_permission` / `elicitation/create`). An A2A client that wants to
796
798
  answer an interaction must use one of those channels; the bridge will not invent A2A extensions for it.
799
+ Accordingly `message.metadata.allowInteractive: true` is **rejected outright** (`-32000` with
800
+ `data.code = "interaction_not_supported"`) and no task is created — silently running non-interactively
801
+ would let callers believe their permissions were auto-approved. Use ACP `session/new`
802
+ `_meta.allowInteractive` instead.
797
803
  - **Bridge extension URIs** live under `message.metadata` / `Task.metadata.bridge.*` and are additive:
798
804
 
799
805
  | Extension | Where | Meaning |
@@ -801,6 +807,7 @@ gateway route returns 404. The `a2a` / `acp` sub-flags turn individual surfaces
801
807
  | `agentType` | `message.metadata` | managed CLI whitelist entry (required) |
802
808
  | `cwd` | `message.metadata` | task working directory (required) |
803
809
  | `timeoutMs` / `captureDiff` / `permissionMode` | `message.metadata` | optional per-task overrides |
810
+ | `allowInteractive` | `message.metadata` | **unsupported**: A2A has no request-frame channel, `true` is rejected (`interaction_not_supported`) |
804
811
  | `bridge.taskLogEndpoint` | `Task.metadata` | where debug logs live (not a message source) |
805
812
  | `bridge.statusDetail` | `Task.metadata` | true cause when a state collapses several bridge statuses |
806
813
  | `afterEventSeq` | resubscribe `params.metadata` | hole-filling cursor (eventSeq; absent = full replay) |
@@ -826,7 +833,9 @@ an external contract** (decided 2026-11-22: frame formats will not follow upstre
826
833
  - **`initialize`**: declares only real capabilities — `loadSession: false` (sessions are not persisted
827
834
  for resumption), text-only prompts, no fs/terminal client capabilities.
828
835
  - **`session/new`**: pins `params.cwd` and `params._meta.agentType` (one of the 12 managed CLIs must be
829
- chosen explicitly).
836
+ chosen explicitly). Optional `params._meta.allowInteractive: true` requests interactions for that
837
+ session (booleans only). It is a **request**: unless the process runs with `--interaction-enabled`,
838
+ the session still runs non-interactively and the CLI's permission asks are declined locally.
830
839
  - **`session/prompt` (conversation multi-turn, add-acp-session-memory)**: the first turn creates a
831
840
  bridge conversation session (`run_task` semantics); subsequent turns use `send_message` on the
832
841
  **same session** — CLI-native continuation (resume / ACP session / replay fallback across the
@@ -840,7 +849,9 @@ an external contract** (decided 2026-11-22: frame formats will not follow upstre
840
849
  continuable.
841
850
  - **`session/cancel`**: cancels the active turn (`cancel_turn` orchestration, idempotent
842
851
  operationId); with no active turn it succeeds silently.
843
- - **Interaction loop**: when a task enters `waiting_interaction`, the prompt stream injects an
852
+ - **Interaction loop**: **requires the session to declare `_meta.allowInteractive: true` at
853
+ `session/new`** (without it no request frame is ever produced — the default is non-interactive).
854
+ When a task enters `waiting_interaction`, the prompt stream injects an
844
855
  `event: request` frame (`session/request_permission` or `elicitation/create` — permission uses the
845
856
  standard options; form/auth-url use elicitation with form/url modes). The client answers via
846
857
  `POST /acp` with a response envelope (no method, carrying the gateway-issued id + result); the
@@ -850,6 +861,12 @@ an external contract** (decided 2026-11-22: frame formats will not follow upstre
850
861
  CLI run, covering A2A send/get/cancel, messageId idempotency, and the ACP prompt/cancel loop;
851
862
  **multi-turn memory is asserted with a real two-round CLI dialogue**. If the CLIs' outbound proxy
852
863
  differs from the system proxy, pass `E2E_PROXY=http://127.0.0.1:<port>`).
864
+ Without `E2E_AGENT` the script **auto-selects any ready CLI** on this machine, so a single tool's
865
+ subscription/login state can't be mistaken for a bridge regression; set `E2E_AGENT` to pin one.
866
+ When none is ready it exits `2`, and only `E2E_ALLOW_SKIP=1` turns that into a skip (clearly
867
+ reported as "nothing was verified"). The interaction loop (request frame → response envelope →
868
+ turn continues) needs a CLI that actually asks for permission — tools differ a lot (kimi-code asks,
869
+ opencode/minimax auto-allow), so it is off by default and enabled with `E2E_INTERACTION=1`.
853
870
  - Full contract: the `a2a-gateway` tag in `contracts/openapi.control-plane.yaml`.
854
871
 
855
872
  ### Live scan progress and brand icons
package/README.zh-CN.md CHANGED
@@ -128,9 +128,10 @@ apiKey 配置;kimi 探测 oauth 登录态 `~/.kimi-code/credentials/kimi-code.
128
128
  不含 `login` 子命令——认证走 Trae IDE 团队/企业登录写入的 OS keyring,或上面的 PAT 环境变量;两者都没有时任何
129
129
  模型任务都无法运行。
130
130
 
131
- agy 的外部请求可用 `AGENT_BRIDGE_EXTERNAL_PROXY` 显式指定代理;未指定时,Windows 自动读取当前用户系统代理。
132
- 这避免 WorkBuddy 进程代理与系统代理不一致导致 Google API 502;不会把本机端口写死进代码。agy 1.5.9 起
133
- 声明 ACP,旧版只保留 headless;已实测首轮和原生续接,未逐项实测的 permission/form 不声明。
131
+ agy 与 codex 的外部请求可用 `AGENT_BRIDGE_EXTERNAL_PROXY` 显式指定代理;未指定时,Windows 自动读取当前用户
132
+ 系统代理;设为 `off`(或 `none`)则不注入任何代理、直连。这避免 WorkBuddy 进程代理与系统代理不一致导致
133
+ Google API 502,也避免 codex 的 responses WebSocket 走直连时空转约 113s;不会把本机端口写死进代码。
134
+ agy 1.5.9 起声明 ACP,旧版只保留 headless;已实测首轮和原生续接,未逐项实测的 permission/form 不声明。
134
135
 
135
136
  ### 稳定设备身份与本地状态
136
137
 
@@ -653,7 +654,7 @@ bridge 会在终态 `task_status` 上**回显 `requestedBy`**,供平台落 `re
653
654
  | GET | `/v1/interactions?taskId=&state=&limit=` | `session:read` 或 `task:read`(有界交互列表,常用 `state=pending`) |
654
655
  | GET | `/v1/interactions/{requestId}` | `session:read` 或 `task:read`(单条交互:待答请求或已结算结果) |
655
656
  | POST | `/v1/interactions/{requestId}:respond` | permission 要 `task:approve`,form/auth-url 要 `task:respond`(规则与代码路径同 WS 的 `task_interaction_response`) |
656
- | POST | `/v1/tasks` | `task:create` |
657
+ | POST | `/v1/tasks` | `task:create`(请求体可带 `allowInteractive: true` 申请本任务交互;生效还须 `--interaction-enabled`) |
657
658
  | GET | `/v1/tasks` | `task:read`(游标分页) |
658
659
  | GET | `/v1/tasks/{id}` | `task:read` |
659
660
  | POST | `/v1/tasks/{id}:cancel` | `task:cancel`(幂等) |
@@ -720,6 +721,9 @@ curl --noproxy '*' -H "Authorization: Bearer abs_…" -H "Idempotency-Key: 3f9a
720
721
  - **权限不是 A2A 原生能力**:等待中的任务表现为 `INPUT_REQUIRED`,但批准/应答闭环只存在于
721
722
  bridge wire(`task_interaction_request/response`)与 ACP 表面(`session/request_permission` /
722
723
  `elicitation/create`)。A2A 客户端要回答交互必须走这两条通道之一;bridge 不为它发明 A2A 扩展。
724
+ 相应地,`message.metadata.allowInteractive: true` 会被**明确拒绝**(`-32000`,
725
+ `data.code = "interaction_not_supported"`)且不创建任务 —— 静默跑成非交互会让调用方误以为
726
+ 「权限已被自动批准」。要交互请用 ACP `session/new` 的 `_meta.allowInteractive`。
723
727
  - **bridge 扩展 URI** 位于 `message.metadata` / `Task.metadata.bridge.*`,全部是增量可选字段:
724
728
 
725
729
  | 扩展 | 位置 | 含义 |
@@ -727,6 +731,7 @@ curl --noproxy '*' -H "Authorization: Bearer abs_…" -H "Idempotency-Key: 3f9a
727
731
  | `agentType` | `message.metadata` | 受管 CLI 白名单项(必填) |
728
732
  | `cwd` | `message.metadata` | 任务工作目录(必填) |
729
733
  | `timeoutMs` / `captureDiff` / `permissionMode` | `message.metadata` | 可选的任务级覆盖 |
734
+ | `allowInteractive` | `message.metadata` | **不支持**:A2A 无请求帧通道,传 `true` 会被拒绝(`interaction_not_supported`) |
730
735
  | `bridge.taskLogEndpoint` | `Task.metadata` | 调试日志位置(不是消息来源) |
731
736
  | `bridge.statusDetail` | `Task.metadata` | 多个 bridge 状态坍缩到一个 A2A 状态时的真实归因 |
732
737
  | `afterEventSeq` | resubscribe `params.metadata` | 补洞游标(eventSeq;缺省 0 = 全量回放) |
@@ -748,7 +753,9 @@ ACP v1 的 HTTP 承载在上游还是 RFD 阶段,但**本网关这一侧的口
748
753
 
749
754
  - **`initialize`**:只声明真实能力——`loadSession: false`(会话不持久续接)、prompt 只收
750
755
  text block、fs/terminal 客户端能力不开放。
751
- - **`session/new`**:固化 `params.cwd` 与 `params._meta.agentType`(12 个受管 CLI 必须显式选择)。
756
+ - **`session/new`**:固化 `params.cwd` 与 `params._meta.agentType`(12 个受管 CLI 必须显式选择);
757
+ 可选 `params._meta.allowInteractive: true` 申请本会话的交互(只认布尔)。申请只是**请求**:
758
+ 进程没以 `--interaction-enabled` 启动时仍按非交互跑,CLI 的权限申请会被本机直接拒绝。
752
759
  - **`session/prompt`(conversation 多轮,add-acp-session-memory)**:首轮创建 bridge conversation
753
760
  会话(`run_task` 语义);后续轮 `send_message` 续接**同一会话**——CLI 原生续接(resume /
754
761
  ACP session / 重放兜底,12 适配器续接矩阵),**上下文由 CLI 持有、token 只传增量**。
@@ -759,14 +766,20 @@ ACP v1 的 HTTP 承载在上游还是 RFD 阶段,但**本网关这一侧的口
759
766
  会话空闲回收复用 conversation 的 `idleTimeoutMs`。bridge 重启后 acp 会话绑定丢失(内存态),
760
767
  旧会话不假装可续。
761
768
  - **`session/cancel`**:取消当前轮次(`cancel_turn` 编排,operationId 幂等);无活动轮次静默成功。
762
- - **交互闭环**:任务进入 `waiting_interaction` 时,prompt 流中注入 `event: request` 帧
763
- (`session/request_permission` 或 `elicitation/create`——permission 走标准选项,
769
+ - **交互闭环**:**前提是该 ACP 会话在 `session/new` 声明了 `_meta.allowInteractive: true`**
770
+ (不声明就不会弹请求——默认按非交互执行)。任务进入 `waiting_interaction` 时,prompt 流中注入
771
+ `event: request` 帧(`session/request_permission` 或 `elicitation/create`——permission 走标准选项,
764
772
  form/auth-url 走 elicitation(form/url 两种 mode))。客户端用 `POST /acp` 发响应报文
765
773
  (无 method、带网关下发的 id + result)应答;网关转成 `task_interaction_response` 走与
766
774
  `POST /v1/interactions/{id}:respond` **同一条** dispatch 路径(权限判定双保险)。
767
775
  - 端到端取证:`npm run e2e:gateway`(真 bridge 进程 + 真服务令牌 + 真跑一次本机 CLI,
768
776
  覆盖 A2A send/get/cancel、messageId 幂等与 ACP prompt/cancel 全链路;**多轮记忆含真 CLI
769
777
  两轮对话断言**。CLI 出网代理与系统不一致时用 `E2E_PROXY=http://127.0.0.1:<port>` 指定)。
778
+ 不指定 `E2E_AGENT` 时脚本会**自动挑一个本机就绪的 CLI**(避免把某个工具的订阅/登录态
779
+ 问题当成桥接回归);指定时按指定跑。一个就绪的都没有时退出码 `2`,
780
+ 设 `E2E_ALLOW_SKIP=1` 才会以「跳过」结束(并明确打印本轮未验证任何行为)。
781
+ 交互闭环(权限请求帧 → 响应报文 → 回合继续)需要 CLI 真的申请权限,各工具差异大
782
+ (kimi-code 会问,opencode/minimax 自动放行),因此默认不跑:`E2E_INTERACTION=1` 才启用。
770
783
  - 详见 `contracts/openapi.control-plane.yaml` 的 `a2a-gateway` tag。
771
784
 
772
785
  ### 扫描结果实时回传与品牌图标
@@ -71,6 +71,10 @@ export const AGENTS = [
71
71
  // full:同时绕过审批与 Codex 自身沙箱
72
72
  fullArgs: ['--dangerously-bypass-approvals-and-sandbox'],
73
73
  steps: 'codex-json',
74
+ // codex 0.171 的 responses 走 WebSocket:本机直连该通道会被丢(重试 5 次 ≈113s 后
75
+ // 才回退 HTTPS,见 2026-11-27 实测)。桌面/终端启动的 bridge 环境里通常没有代理变量,
76
+ // 因此与 agy 同源处理:显式 AGENT_BRIDGE_EXTERNAL_PROXY → Windows 系统代理。
77
+ preferSystemProxy: true,
74
78
  credential: {
75
79
  envKey: 'OPENAI_API_KEY',
76
80
  envs: ['OPENAI_API_KEY'],
@@ -12,10 +12,40 @@
12
12
  * They pause the turn until the client replies.
13
13
  */
14
14
  import { createInterface } from 'node:readline';
15
+ import { externalProxyEnv } from '../infra/proxy-env.js';
15
16
  import { killCliProcess, spawnCliProcess } from './agent-adapters.js';
17
+ import { withoutHostEnv } from './host-env.js';
16
18
  export function codexAppServerArgs() {
17
19
  return ['app-server', '--stdio'];
18
20
  }
21
+ /** stderr 尾部保留上限:与 ACP 通道同量级,够看清最后一条错误栈又不塞满错误消息 */
22
+ export const CODEX_STDERR_TAIL_LIMIT = 4 * 1024;
23
+ export function codexChildEnv(base = process.env) {
24
+ return externalProxyEnv(withoutHostEnv(base));
25
+ }
26
+ /**
27
+ * 把 codex 的「非内容型」通知压成一行给人看的文本(`error` / `warning` / `configWarning`)。
28
+ *
29
+ * 这些通知不承载对话内容,却常常是**唯一能解释「回合为什么不动」**的信息:
30
+ * 2026-11-27 复盘到的 113s 静默就是 `error` 里的一串 `Reconnecting... n/5`。返回 undefined
31
+ * 表示这条通知不该上行。
32
+ */
33
+ export function codexNoticeText(notification) {
34
+ const method = String(notification['method'] ?? '');
35
+ const params = asObject(notification['params']);
36
+ if (method === 'warning' || method === 'configWarning') {
37
+ const text = params['message'] ?? params['summary'];
38
+ return typeof text === 'string' && text.trim() ? text.trim() : undefined;
39
+ }
40
+ if (method !== 'error')
41
+ return undefined;
42
+ const error = asObject(params['error']);
43
+ const message = typeof error['message'] === 'string' ? error['message'] : Object.keys(error).length ? JSON.stringify(error) : '';
44
+ const detail = typeof params['additionalDetails'] === 'string' ? params['additionalDetails'] : '';
45
+ const suffix = params['willRetry'] === true ? '[将自动重试]' : '';
46
+ const body = `${message}${detail ? `(${detail})` : ''}`.trim();
47
+ return body || suffix ? `${body}${suffix}`.trim() : undefined;
48
+ }
19
49
  function asObject(value) {
20
50
  return typeof value === 'object' && value !== null ? value : {};
21
51
  }
@@ -43,8 +73,29 @@ function deliveryFuture() {
43
73
  export async function runCodexPrompt(opts) {
44
74
  const child = spawnCliProcess(opts.command ?? 'codex', codexAppServerArgs(), {
45
75
  cwd: opts.cwd,
46
- env: process.env,
76
+ env: opts.env ?? codexChildEnv(),
47
77
  });
78
+ /**
79
+ * stderr 必须持续读走:codex app-server 会往这里写配置告警、重连/回退提示与失败栈。
80
+ * 不读有两个后果 —— ①失败只剩一个退出码,用户无法自查;②pipe 缓冲(64 KiB)写满后
81
+ * 子进程阻塞在 write 上,协议流彻底停摆,外部只看得到 heartbeat(2026-11-27 复盘到的
82
+ * 「交互模式回合挂死」就是这么被误判的)。尾部同时用于错误消息后缀。
83
+ */
84
+ let stderrTail = '';
85
+ child.stderr?.on('data', (chunk) => {
86
+ const text = chunk.toString('utf8');
87
+ stderrTail = (stderrTail + text).slice(-CODEX_STDERR_TAIL_LIMIT);
88
+ try {
89
+ opts.onStderr?.(text);
90
+ }
91
+ catch {
92
+ /* 诊断旁路不得影响回合 */
93
+ }
94
+ });
95
+ const withStderr = (message) => {
96
+ const tail = stderrTail.trim();
97
+ return tail ? `${message}\n[stderr] ${tail}` : message;
98
+ };
48
99
  let nextId = 1;
49
100
  let threadId = '';
50
101
  let turnId = '';
@@ -63,6 +114,10 @@ export async function runCodexPrompt(opts) {
63
114
  resolveTurn = resolve;
64
115
  rejectTurn = reject;
65
116
  });
117
+ // 握手阶段(initialize/thread/start/turn/start)失败时 turnDone 永远不会被 await,
118
+ // 它的 rejection 会变成未处理拒绝(Node 默认直接终止进程)。先挂一个空 catch 标记已处理;
119
+ // 后面 `await turnDone` 仍然正常抛错,语义不变。
120
+ void turnDone.catch(() => undefined);
66
121
  const pending = new Map();
67
122
  const send = (message) => {
68
123
  if (closed || !child.stdin.writable || child.stdin.destroyed)
@@ -80,7 +135,7 @@ export async function runCodexPrompt(opts) {
80
135
  const id = nextId++;
81
136
  const timer = setTimeout(() => {
82
137
  pending.delete(id);
83
- reject(new Error(`Codex ${method} 超时(${timeoutMs}ms)`));
138
+ reject(new Error(withStderr(`Codex ${method} 超时(${timeoutMs}ms)`)));
84
139
  }, timeoutMs);
85
140
  pending.set(id, { resolve, reject, timer });
86
141
  send({ jsonrpc: '2.0', id, method, params });
@@ -184,7 +239,7 @@ export async function runCodexPrompt(opts) {
184
239
  const status = String(turn['status'] ?? 'unknown');
185
240
  const error = codexTurnError(status, turn['error']);
186
241
  if (error)
187
- rejectTurn?.(error);
242
+ rejectTurn?.(new Error(withStderr(error.message)));
188
243
  else
189
244
  resolveTurn?.();
190
245
  return;
@@ -210,7 +265,7 @@ export async function runCodexPrompt(opts) {
210
265
  pending.delete(id);
211
266
  clearTimeout(p.timer);
212
267
  if (message['error'])
213
- p.reject(new Error(errorText(message['error'])));
268
+ p.reject(new Error(withStderr(errorText(message['error']))));
214
269
  else
215
270
  p.resolve(message['result']);
216
271
  return;
@@ -240,7 +295,7 @@ export async function runCodexPrompt(opts) {
240
295
  child.on('close', (code) => {
241
296
  closed = true;
242
297
  settleResponseWaiters();
243
- const error = new Error(`Codex app-server 退出(code ${code ?? 'null'})`);
298
+ const error = new Error(withStderr(`Codex app-server 退出(code ${code ?? 'null'})`));
244
299
  failAll(error);
245
300
  if (!turnSettled) {
246
301
  turnSettled = true;
@@ -477,6 +477,7 @@ export function createSession(opts) {
477
477
  emitter,
478
478
  registry: opts.registry,
479
479
  store: opts.store,
480
+ interactionEnabled: opts.interactionEnabled === true,
480
481
  artifacts,
481
482
  artifactsForTenant,
482
483
  urls,
package/dist/cli/help.js CHANGED
@@ -2,7 +2,8 @@
2
2
  * 帮助文本(CLI 支撑件)
3
3
  *
4
4
  * 命令清单与 `dispatch.ts` 的注册表必须一致 —— README 由 `doc:check` 机检,
5
- * 这里则是给人看的第一份说明,未实现的能力必须当场写清(daemon install/uninstall 仍是 stub)。
5
+ * 这里则是给人看的第一份说明,未实现的能力必须当场写清(例如 `context_exhausted`
6
+ * 这类规格里有、实现里没有的条款,不能写成已支持)。
6
7
  */
7
8
  import { existsSync } from 'node:fs';
8
9
  import { configPath } from '../infra/config.js';
@@ -106,6 +106,8 @@ async function runConnect(flags) {
106
106
  // 控制面与 WS 共用同一套权限策略,不能被本地通道绕过
107
107
  permissionPolicy: resolvePermissionPolicy(config?.permissionPolicy, strFlag(flags, 'permission-policy')),
108
108
  externalSandbox: resolveExternalSandbox(config?.externalSandbox, boolFlag(flags, 'external-sandbox')),
109
+ // 交互开关取会话里的同一个值(dispatch 判定也用它),通道只能申请、不能自开
110
+ interactionEnabled: session.interactionEnabled,
109
111
  },
110
112
  }));
111
113
  if (plane)
@@ -125,6 +125,8 @@ async function runServe(flags) {
125
125
  // 控制面与 WS 共用同一套权限策略,不能被本地通道绕过
126
126
  permissionPolicy: resolvePermissionPolicy(config?.permissionPolicy, strFlag(flags, 'permission-policy')),
127
127
  externalSandbox: resolveExternalSandbox(config?.externalSandbox, boolFlag(flags, 'external-sandbox')),
128
+ // 交互开关取会话里的同一个值(dispatch 判定也用它),通道只能申请、不能自开
129
+ interactionEnabled: session.interactionEnabled,
128
130
  },
129
131
  });
130
132
  const boardUrl = `${plane.url}/?token=${uiToken}`;
@@ -19,7 +19,7 @@
19
19
  import { spawn } from 'node:child_process';
20
20
  import { randomUUID } from 'node:crypto';
21
21
  import { AcpAuthRequiredError, runAcpPrompt, } from '../adapters/acp-codebuddy.js';
22
- import { runCodexPrompt } from '../adapters/codex-app-server.js';
22
+ import { codexNoticeText, runCodexPrompt } from '../adapters/codex-app-server.js';
23
23
  import { runClaudeStreamPrompt } from '../adapters/claude-stream.js';
24
24
  import { existsSync, realpathSync, statSync } from 'node:fs';
25
25
  import { resolve as resolvePath, sep } from 'node:path';
@@ -40,6 +40,8 @@ export const KILL_GRACE_MS = 2000;
40
40
  export const DEFAULT_MAX_TASKS = 30;
41
41
  /** 默认队列上限:再长的排队对调用方也没意义(2026-10-24 由 32 调整为 60) */
42
42
  export const DEFAULT_MAX_QUEUED = 60;
43
+ /** 单个任务最多上行多少条 codex 非内容通知(去重后);重连风暴时防刷屏 */
44
+ const CODEX_NOTICE_LIMIT = 40;
43
45
  /**
44
46
  * `child` 是否位于 `parent` 目录之下(含相等)。
45
47
  * 必须按目录边界判断;Windows 路径大小写不敏感,比较前统一折叠。
@@ -798,6 +800,17 @@ export class TaskSupervisor {
798
800
  return;
799
801
  const method = String(notification['method'] ?? '');
800
802
  const params = (notification['params'] ?? {});
803
+ // 非内容型通知(重连/回退/配置告警)必须上行:静默是「挂死」误判的温床
804
+ const notice = codexNoticeText(notification);
805
+ if (notice !== undefined) {
806
+ const key = notice.slice(0, 160);
807
+ const seen = (entry.codexNotices ??= new Set());
808
+ if (seen.has(key) || seen.size >= CODEX_NOTICE_LIMIT)
809
+ return;
810
+ seen.add(key);
811
+ entry.hooks.onLog('stderr', `[codex] ${notice}${notice.endsWith('\n') ? '' : '\n'}`);
812
+ return;
813
+ }
801
814
  if (method === 'item/agentMessage/delta') {
802
815
  const delta = codexDeltaText(notification);
803
816
  if (delta !== undefined) {
@@ -34,16 +34,37 @@ function queryRegistry(value) {
34
34
  windowsHide: true,
35
35
  });
36
36
  }
37
+ let cachedSystemProxy;
38
+ /**
39
+ * 进程内缓存:每次 spawn 都 `reg.exe query` 一次没必要(Windows 上约 10–30ms,
40
+ * 且在安全策略拉黑 reg.exe 的机器上每次都会留下一条拦截噪音)。
41
+ * 代价是改了系统代理要重启 bridge 才生效 —— 与 agy 的既有语义一致。
42
+ */
37
43
  export function detectWindowsSystemProxy() {
44
+ if (cachedSystemProxy)
45
+ return cachedSystemProxy.value;
46
+ let value;
38
47
  try {
39
- return parseWindowsProxyRegistry(queryRegistry('ProxyEnable'), queryRegistry('ProxyServer'));
48
+ value = parseWindowsProxyRegistry(queryRegistry('ProxyEnable'), queryRegistry('ProxyServer'));
40
49
  }
41
50
  catch {
42
- return undefined;
51
+ value = undefined;
43
52
  }
53
+ cachedSystemProxy = { value };
54
+ return value;
55
+ }
56
+ /** 测试用:清掉探测缓存(生产路径不需要调用) */
57
+ export function resetSystemProxyCache() {
58
+ cachedSystemProxy = undefined;
44
59
  }
60
+ /** `AGENT_BRIDGE_EXTERNAL_PROXY=off|none`:显式关闭代理注入(系统代理配错时的逃生口) */
61
+ const PROXY_OFF_VALUES = new Set(['off', 'none', 'false', '0']);
45
62
  export function externalProxyEnv(base, opts = {}) {
46
- const explicit = normalizeProxy(base['AGENT_BRIDGE_EXTERNAL_PROXY'] ?? '');
63
+ const declared = (base['AGENT_BRIDGE_EXTERNAL_PROXY'] ?? '').trim();
64
+ // 逃生口先于一切:用户明确要求直连时不得再读系统代理(否则等于把开关做成摆设)
65
+ if (PROXY_OFF_VALUES.has(declared.toLowerCase()))
66
+ return { ...base };
67
+ const explicit = normalizeProxy(declared);
47
68
  const proxy = explicit ??
48
69
  ((opts.platform ?? process.platform) === 'win32'
49
70
  ? (opts.detect ?? detectWindowsSystemProxy)()
@@ -163,6 +163,7 @@ export async function startControlPlane(settings, deps) {
163
163
  args: [],
164
164
  prompt: input.prompt,
165
165
  timeoutMs: input.timeoutMs,
166
+ allowInteractive: input.allowInteractive,
166
167
  requestedBy: input.requestedBy,
167
168
  idempotencyKey: input.idempotencyKey,
168
169
  idempotencyFingerprint: input.idempotencyFingerprint,
@@ -353,6 +354,7 @@ export async function startControlPlane(settings, deps) {
353
354
  timeoutMs: input.timeoutMs,
354
355
  captureDiff: input.captureDiff ?? deps.defaults.captureDiffByDefault,
355
356
  permissionMode: input.permissionMode,
357
+ allowInteractive: input.allowInteractive,
356
358
  requestedBy: input.requestedBy,
357
359
  purpose: input.purpose,
358
360
  },
@@ -394,6 +396,8 @@ export async function startControlPlane(settings, deps) {
394
396
  maxQueued: deps.defaults.maxQueued,
395
397
  captureDiff: input.captureDiff ?? deps.defaults.captureDiffByDefault,
396
398
  diffMaxBytes: deps.defaults.diffMaxBytes,
399
+ // 交互:调用方只能申请;本机未开放时按非交互跑(supervisor 会直接拒绝 ACP 权限请求)
400
+ interactive: input.allowInteractive === true && deps.defaults.interactionEnabled === true,
397
401
  // 权限:平台/本地调用方可以请求,但本机策略同样适用(受管参数模式不会被本地通道绕过)
398
402
  permissionMode: input.permissionMode,
399
403
  permissionPolicy: deps.defaults.permissionPolicy,
@@ -519,6 +523,13 @@ export async function startControlPlane(settings, deps) {
519
523
  problem(ctx.res, 400, 'protocol_incompatible', '缺 agentType 或 cwd');
520
524
  return;
521
525
  }
526
+ // 交互申请必须是**布尔**:字符串 "true"/1 这类猜测会让「本机到底开没开交互」变得不可推理
527
+ const allowInteractiveRaw = body['allowInteractive'];
528
+ if (allowInteractiveRaw !== undefined && typeof allowInteractiveRaw !== 'boolean') {
529
+ problem(ctx.res, 400, 'protocol_incompatible', 'allowInteractive 必须是布尔');
530
+ return;
531
+ }
532
+ const allowInteractive = allowInteractiveRaw === true;
522
533
  // SQLite 是唯一权威:同 key 同 body 重放原 taskId,异参冲突;进程重启/记录数量均不失效。
523
534
  const idemRaw = ctx.req.headers['idempotency-key'];
524
535
  const idemHeader = Array.isArray(idemRaw) ? idemRaw[0] : idemRaw;
@@ -532,6 +543,7 @@ export async function startControlPlane(settings, deps) {
532
543
  timeoutMs: typeof body['timeoutMs'] === 'number' ? body['timeoutMs'] : undefined,
533
544
  captureDiff: body['captureDiff'] === true || deps.defaults.captureDiffByDefault,
534
545
  permissionMode: body['permissionMode'] === 'full' ? 'full' : body['permissionMode'] === 'default' ? 'default' : undefined,
546
+ allowInteractive,
535
547
  requestedBy: str(body['requestedBy']),
536
548
  purpose: str(body['purpose']),
537
549
  idempotencyKey: idemHeader ?? undefined,
@@ -187,6 +187,14 @@ export function createGatewayHandlers(deps) {
187
187
  rpcErr(ctx.res, rpcId, A2A_JSONRPC_ERRORS.invalidParams, `未知 agentType:${agentType}(不在受管适配器白名单内)`);
188
188
  return;
189
189
  }
190
+ // A2A 没有 agent→client 请求帧通道(也没有 task_interaction_response 的投递口):
191
+ // 申请交互就明确拒绝,不静默跑成非交互任务——否则调用方会以为「权限已被自动批准」。
192
+ if (metadata?.['allowInteractive'] === true) {
193
+ rpcErr(ctx.res, rpcId, -32000, 'A2A 表面不支持交互(无请求帧通道);需要权限/表单请改用 ACP session/prompt', {
194
+ code: 'interaction_not_supported',
195
+ });
196
+ return;
197
+ }
190
198
  const timeoutMs = typeof metadata?.['timeoutMs'] === 'number' ? metadata['timeoutMs'] : undefined;
191
199
  const messageId = typeof message['messageId'] === 'string' && message['messageId'] ? message['messageId'] : undefined;
192
200
  if (!messageId) {
@@ -585,11 +593,19 @@ export function createGatewayHandlers(deps) {
585
593
  rpcErr(ctx.res, rpcId, ACP_JSONRPC_ERRORS.invalidParams, `未知 agentType:${agentType}(不在受管适配器白名单内)`);
586
594
  return;
587
595
  }
596
+ // 交互申请(add-interaction-optin):只认严格布尔。字符串 "true"/1 会让
597
+ // 「这个会话到底会不会弹权限」不可推理,宁可报错。
598
+ const allowInteractiveRaw = meta?.['allowInteractive'];
599
+ if (allowInteractiveRaw !== undefined && typeof allowInteractiveRaw !== 'boolean') {
600
+ rpcErr(ctx.res, rpcId, ACP_JSONRPC_ERRORS.invalidParams, 'params._meta.allowInteractive 必须是布尔');
601
+ return;
602
+ }
588
603
  const acpSessionId = `acp_${randomBytes(8).toString('hex')}`;
589
604
  acpSessions.set(acpSessionId, {
590
605
  agentType,
591
606
  cwd,
592
607
  tenantId: ctx.tenantId ?? DEFAULT_TENANT,
608
+ ...(allowInteractiveRaw === true ? { allowInteractive: true } : {}),
593
609
  });
594
610
  rpcOk(ctx.res, rpcId, { sessionId: acpSessionId });
595
611
  };
@@ -807,6 +823,8 @@ export function createGatewayHandlers(deps) {
807
823
  args: [],
808
824
  prompt: text.text,
809
825
  sessionMode: 'conversation',
826
+ // 会话级交互申请(add-interaction-optin):续轮由 turn.execution 继承,不必重复声明
827
+ ...(session.allowInteractive === true ? { allowInteractive: true } : {}),
810
828
  requestedBy: 'acp-gateway',
811
829
  ...(token ? { serviceToken: token } : {}),
812
830
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-service",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Give a remote platform control of the AI agents installed on your machine, over an outbound WebSocket",
5
5
  "type": "module",
6
6
  "bin": {