agent-bridge-service 1.0.0 → 1.2.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 +30 -0
- package/README.md +38 -9
- package/README.zh-CN.md +30 -8
- package/dist/adapters/agent-adapters.js +4 -0
- package/dist/adapters/codex-app-server.js +60 -5
- package/dist/app/session.js +1 -0
- package/dist/cli/help.js +2 -1
- package/dist/commands/connect.js +2 -0
- package/dist/commands/serve.js +2 -0
- package/dist/core/context-overflow.js +78 -0
- package/dist/core/emitter.js +5 -1
- package/dist/core/errors.js +7 -0
- package/dist/core/task-supervisor.js +40 -1
- package/dist/infra/proxy-env.js +24 -3
- package/dist/transport/control-plane.js +12 -0
- package/dist/transport/gateway.js +18 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,36 @@ 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.2.0](https://github.com/shaylanwu/agent-bridge/compare/v1.1.0...v1.2.0) (2026-11-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **emitter:** 终态后 get_artifact 零响应——读回包被终态闸门一起丢了 ([7bcf3ff](https://github.com/shaylanwu/agent-bridge/commit/7bcf3ffcaf4c3a01101bb188ab4ccfd69eea4946))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* **errors:** context_exhausted 落地为反应式识别,不再只是规格承诺 ([1aad19e](https://github.com/shaylanwu/agent-bridge/commit/1aad19e6d7979c93d337788c26b17938d901ffd1))
|
|
19
|
+
|
|
20
|
+
## [1.1.0](https://github.com/shaylanwu/agent-bridge/compare/v1.0.0...v1.1.0) (2026-11-27)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **codex:** app-server 子进程注入外部代理并排空 stderr,修掉「回合静默挂住」 ([d685f22](https://github.com/shaylanwu/agent-bridge/commit/d685f227596f799a154322d573f9311f30a0e138))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **codex:** 重连/配置告警上行成任务日志,不再整段静默 ([d31a2f4](https://github.com/shaylanwu/agent-bridge/commit/d31a2f45e4b3e865cdf995e80054b2b75f29abe2))
|
|
31
|
+
* **gateway:** 控制面与 ACP 会话可按任务申请交互(allowInteractive 透传) ([f88e900](https://github.com/shaylanwu/agent-bridge/commit/f88e9005f1da627a4623dcf318d2a2125eb64ee5))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Performance Improvements
|
|
35
|
+
|
|
36
|
+
* **proxy-env:** 系统代理探测按进程缓存,每进程只查一次注册表 ([da1f3ee](https://github.com/shaylanwu/agent-bridge/commit/da1f3ee718f7a6fdac51e66824839a011a776f30))
|
|
37
|
+
|
|
8
38
|
## [1.0.0](https://github.com/shaylanwu/agent-bridge/compare/v0.2.3...v1.0.0) (2026-11-26)
|
|
9
39
|
|
|
10
40
|
|
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
|
|
149
|
-
system proxy
|
|
150
|
-
|
|
151
|
-
|
|
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
|
|
|
@@ -385,7 +387,9 @@ ACP: `codebuddy-cli`, `ds-harness`, `agy`, `opencode`, `mimo-code`, `kimi-code`,
|
|
|
385
387
|
automation-only on that channel: it announces `permission` nowhere (tools run without asking, so its
|
|
386
388
|
`executionModes` declares an empty `interactionKinds`) and continues sessions through its own
|
|
387
389
|
`session/resume` rather than the standard `session/load`. `codex` uses the
|
|
388
|
-
`codex app-server` JSON-RPC surface (thread/resume, turn/steer,
|
|
390
|
+
`codex app-server` JSON-RPC surface (thread/resume, turn/steer, and approval requests plumbed through
|
|
391
|
+
`item/*/requestApproval` — no real-CLI approval evidence yet on our test machine, see the interaction
|
|
392
|
+
loop below); Claude
|
|
389
393
|
conversations keep a resident `stream-json` process across turns; Qoder uses headless with native `--resume`.
|
|
390
394
|
CodeBuddy prefers an explicit `CODEBUDDY_AUTH_TOKEN`; otherwise the bridge reads the plaintext
|
|
391
395
|
`auth/*.info` from the local CodeBuddyExtension and injects it into the ACP child. If neither exists it
|
|
@@ -651,6 +655,7 @@ v1. **But if a message carries a token, it must verify** — there is no "presen
|
|
|
651
655
|
| `agent_protocol_error` | The agent ended a turn with an unresolved interaction or violated the execution protocol |
|
|
652
656
|
| `idempotency_conflict` | The same idempotency key was reused with a different request fingerprint |
|
|
653
657
|
| `session_not_continuable` | The tool has no way to continue a session (`executionModes[].continuation` is `single-turn`), so `sessionMode = conversation` is refused at creation |
|
|
658
|
+
| `context_exhausted` | The CLI itself reported that the history no longer fits its context window (`prompt is too long: … tokens > … maximum`, `context_length_exceeded`, …). Retrying the same prompt cannot succeed — open a new session or shorten the history. Detected from the CLI's own failure text (**never** predicted from a model budget table), and it only replaces `agent_error` |
|
|
654
659
|
| `unauthorized` / `invalid_token` / `token_expired` / `insufficient_scope` | Service-token failures |
|
|
655
660
|
| `protocol_incompatible` / `internal` | Version mismatch / bridge-side fault |
|
|
656
661
|
|
|
@@ -714,7 +719,7 @@ Remote platforms keep using the outbound WebSocket; this is a separate channel,
|
|
|
714
719
|
| GET | `/v1/interactions?taskId=&state=&limit=` | `session:read` or `task:read` (bounded interaction list; `state=pending` is the common one) |
|
|
715
720
|
| GET | `/v1/interactions/{requestId}` | `session:read` or `task:read` (one interaction: pending request or settled result) |
|
|
716
721
|
| 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` |
|
|
722
|
+
| POST | `/v1/tasks` | `task:create` (body may carry `allowInteractive: true` to request interactions for that task; still requires `--interaction-enabled`) |
|
|
718
723
|
| GET | `/v1/tasks` | `task:read` (cursor-paginated) |
|
|
719
724
|
| GET | `/v1/tasks/{id}` | `task:read` |
|
|
720
725
|
| POST | `/v1/tasks/{id}:cancel` | `task:cancel` (idempotent) |
|
|
@@ -794,6 +799,10 @@ gateway route returns 404. The `a2a` / `acp` sub-flags turn individual surfaces
|
|
|
794
799
|
approve/respond loop itself only exists on the bridge wire (`task_interaction_request/response`) and on
|
|
795
800
|
the ACP surface (`session/request_permission` / `elicitation/create`). An A2A client that wants to
|
|
796
801
|
answer an interaction must use one of those channels; the bridge will not invent A2A extensions for it.
|
|
802
|
+
Accordingly `message.metadata.allowInteractive: true` is **rejected outright** (`-32000` with
|
|
803
|
+
`data.code = "interaction_not_supported"`) and no task is created — silently running non-interactively
|
|
804
|
+
would let callers believe their permissions were auto-approved. Use ACP `session/new`
|
|
805
|
+
`_meta.allowInteractive` instead.
|
|
797
806
|
- **Bridge extension URIs** live under `message.metadata` / `Task.metadata.bridge.*` and are additive:
|
|
798
807
|
|
|
799
808
|
| Extension | Where | Meaning |
|
|
@@ -801,6 +810,7 @@ gateway route returns 404. The `a2a` / `acp` sub-flags turn individual surfaces
|
|
|
801
810
|
| `agentType` | `message.metadata` | managed CLI whitelist entry (required) |
|
|
802
811
|
| `cwd` | `message.metadata` | task working directory (required) |
|
|
803
812
|
| `timeoutMs` / `captureDiff` / `permissionMode` | `message.metadata` | optional per-task overrides |
|
|
813
|
+
| `allowInteractive` | `message.metadata` | **unsupported**: A2A has no request-frame channel, `true` is rejected (`interaction_not_supported`) |
|
|
804
814
|
| `bridge.taskLogEndpoint` | `Task.metadata` | where debug logs live (not a message source) |
|
|
805
815
|
| `bridge.statusDetail` | `Task.metadata` | true cause when a state collapses several bridge statuses |
|
|
806
816
|
| `afterEventSeq` | resubscribe `params.metadata` | hole-filling cursor (eventSeq; absent = full replay) |
|
|
@@ -826,7 +836,9 @@ an external contract** (decided 2026-11-22: frame formats will not follow upstre
|
|
|
826
836
|
- **`initialize`**: declares only real capabilities — `loadSession: false` (sessions are not persisted
|
|
827
837
|
for resumption), text-only prompts, no fs/terminal client capabilities.
|
|
828
838
|
- **`session/new`**: pins `params.cwd` and `params._meta.agentType` (one of the 12 managed CLIs must be
|
|
829
|
-
chosen explicitly).
|
|
839
|
+
chosen explicitly). Optional `params._meta.allowInteractive: true` requests interactions for that
|
|
840
|
+
session (booleans only). It is a **request**: unless the process runs with `--interaction-enabled`,
|
|
841
|
+
the session still runs non-interactively and the CLI's permission asks are declined locally.
|
|
830
842
|
- **`session/prompt` (conversation multi-turn, add-acp-session-memory)**: the first turn creates a
|
|
831
843
|
bridge conversation session (`run_task` semantics); subsequent turns use `send_message` on the
|
|
832
844
|
**same session** — CLI-native continuation (resume / ACP session / replay fallback across the
|
|
@@ -840,21 +852,38 @@ an external contract** (decided 2026-11-22: frame formats will not follow upstre
|
|
|
840
852
|
continuable.
|
|
841
853
|
- **`session/cancel`**: cancels the active turn (`cancel_turn` orchestration, idempotent
|
|
842
854
|
operationId); with no active turn it succeeds silently.
|
|
843
|
-
- **Interaction loop**:
|
|
855
|
+
- **Interaction loop**: **requires the session to declare `_meta.allowInteractive: true` at
|
|
856
|
+
`session/new`** (without it no request frame is ever produced — the default is non-interactive).
|
|
857
|
+
When a task enters `waiting_interaction`, the prompt stream injects an
|
|
844
858
|
`event: request` frame (`session/request_permission` or `elicitation/create` — permission uses the
|
|
845
859
|
standard options; form/auth-url use elicitation with form/url modes). The client answers via
|
|
846
860
|
`POST /acp` with a response envelope (no method, carrying the gateway-issued id + result); the
|
|
847
861
|
gateway converts it into `task_interaction_response` and runs the **same** dispatch path as
|
|
848
862
|
`POST /v1/interactions/{id}:respond` (double-checked permissions).
|
|
863
|
+
**Evidence level**: the permission loop is proven end-to-end with a real CLI (kimi-code). The
|
|
864
|
+
form/auth-url (elicitation) path is implemented and unit-tested but **has no real-CLI evidence on
|
|
865
|
+
any adapter** — `interactionKinds` advertising `form` therefore records what the mode *can relay*,
|
|
866
|
+
not what has been observed. `opencode`/`minimax-code` auto-allow tool calls so they never ask;
|
|
867
|
+
`codex` does not issue tool calls at all on our Windows test machine (`codex exec` produces
|
|
868
|
+
reasoning only), so its approval path stays unproven even with `E2E_INTERACTION=1`.
|
|
849
869
|
- End-to-end proof: `npm run e2e:gateway` (real bridge process + real service token + one real local
|
|
850
870
|
CLI run, covering A2A send/get/cancel, messageId idempotency, and the ACP prompt/cancel loop;
|
|
851
871
|
**multi-turn memory is asserted with a real two-round CLI dialogue**. If the CLIs' outbound proxy
|
|
852
872
|
differs from the system proxy, pass `E2E_PROXY=http://127.0.0.1:<port>`).
|
|
873
|
+
Without `E2E_AGENT` the script **auto-selects any ready CLI** on this machine, so a single tool's
|
|
874
|
+
subscription/login state can't be mistaken for a bridge regression; set `E2E_AGENT` to pin one.
|
|
875
|
+
When none is ready it exits `2`, and only `E2E_ALLOW_SKIP=1` turns that into a skip (clearly
|
|
876
|
+
reported as "nothing was verified"). The interaction loop (request frame → response envelope →
|
|
877
|
+
turn continues) needs a CLI that actually asks for permission — tools differ a lot (kimi-code asks,
|
|
878
|
+
opencode/minimax auto-allow, codex issues no tool call on our test machine), so it is off by default
|
|
879
|
+
and enabled with `E2E_INTERACTION=1`. When the phase receives **zero** request frames it is reported
|
|
880
|
+
as *not verified* rather than as a bridge failure — an agent that never asks says nothing about
|
|
881
|
+
whether forwarding works.
|
|
853
882
|
- Full contract: the `a2a-gateway` tag in `contracts/openapi.control-plane.yaml`.
|
|
854
883
|
|
|
855
884
|
### Live scan progress and brand icons
|
|
856
885
|
|
|
857
|
-
Probing
|
|
886
|
+
Probing 12 CLIs takes a few seconds, so results stream in instead of arriving as one batch: for every adapter
|
|
858
887
|
that finishes, the bridge sends `scan_progress` with the newly finished `items` and `done: false`; one final
|
|
859
888
|
`scan_progress` with `done: true` closes the probing phase, followed by the terminal list (`agent_list` on
|
|
860
889
|
connect, or `scan_result` carrying the same `requestId` when answering `scan`). A platform that ignores
|
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
|
-
|
|
133
|
-
|
|
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
|
|
|
@@ -339,7 +340,8 @@ ACP:`codebuddy-cli`、`ds-harness`、`agy`、`opencode`、`mimo-code`、`kimi-
|
|
|
339
340
|
`ds-harness` 在这条通道上是 **automation-only**(实测):跑工具只发 `tool_call`、从不回问权限,所以它的
|
|
340
341
|
`executionModes.interactionKinds` 声明为空数组;续会话靠自家的 `session/resume`,标准 `session/load`
|
|
341
342
|
会回 `-32601 Method not found`(客户端先试 load 再退 resume)。
|
|
342
|
-
`codex` 走 `codex app-server` JSON-RPC(thread/resume、turn/steer
|
|
343
|
+
`codex` 走 `codex app-server` JSON-RPC(thread/resume、turn/steer,审批请求经
|
|
344
|
+
`item/*/requestApproval` 接通——但**本机尚未取到真 CLI 的审批证据**,见下面交互闭环段);Claude 的
|
|
343
345
|
conversation 保持常驻 `stream-json` 进程(Turn 间复用);Qoder 用 headless + 原生 `--resume`,其余工具保持各自已声明通道。
|
|
344
346
|
CodeBuddy 优先用显式 `CODEBUDDY_AUTH_TOKEN`;未设置时从本机 CodeBuddyExtension 的明文
|
|
345
347
|
`auth/*.info` 读取登录态并注入 ACP 子进程。两者都没有时回落 `codebuddy -p`,不会启动无认证子进程。
|
|
@@ -592,6 +594,7 @@ bridge 会在终态 `task_status` 上**回显 `requestedBy`**,供平台落 `re
|
|
|
592
594
|
| `agent_protocol_error` | Agent 在交互未决时结束回合或违反执行协议 |
|
|
593
595
|
| `idempotency_conflict` | 同一幂等键携带了不同的请求指纹 |
|
|
594
596
|
| `session_not_continuable` | 该工具没有任何续接回合的通道(`executionModes[].continuation` 为 `single-turn`),`sessionMode = conversation` 在**创建时**即被拒绝 |
|
|
597
|
+
| `context_exhausted` | CLI 自己报告历史已装不进上下文窗口(`prompt is too long: … tokens > … maximum`、`context_length_exceeded` 等)。原样重试同一个 prompt 一定还是失败——应开新会话或缩短历史。判定来自 CLI 自己的失败文本(**不做**模型上下文预算预测),且只替换 `agent_error` |
|
|
595
598
|
| `unauthorized` / `invalid_token` / `token_expired` / `insufficient_scope` | 服务令牌四类失败 |
|
|
596
599
|
| `protocol_incompatible` / `internal` | 版本不匹配 / bridge 自身异常 |
|
|
597
600
|
|
|
@@ -653,7 +656,7 @@ bridge 会在终态 `task_status` 上**回显 `requestedBy`**,供平台落 `re
|
|
|
653
656
|
| GET | `/v1/interactions?taskId=&state=&limit=` | `session:read` 或 `task:read`(有界交互列表,常用 `state=pending`) |
|
|
654
657
|
| GET | `/v1/interactions/{requestId}` | `session:read` 或 `task:read`(单条交互:待答请求或已结算结果) |
|
|
655
658
|
| POST | `/v1/interactions/{requestId}:respond` | permission 要 `task:approve`,form/auth-url 要 `task:respond`(规则与代码路径同 WS 的 `task_interaction_response`) |
|
|
656
|
-
| POST | `/v1/tasks` | `task:create` |
|
|
659
|
+
| POST | `/v1/tasks` | `task:create`(请求体可带 `allowInteractive: true` 申请本任务交互;生效还须 `--interaction-enabled`) |
|
|
657
660
|
| GET | `/v1/tasks` | `task:read`(游标分页) |
|
|
658
661
|
| GET | `/v1/tasks/{id}` | `task:read` |
|
|
659
662
|
| POST | `/v1/tasks/{id}:cancel` | `task:cancel`(幂等) |
|
|
@@ -720,6 +723,9 @@ curl --noproxy '*' -H "Authorization: Bearer abs_…" -H "Idempotency-Key: 3f9a
|
|
|
720
723
|
- **权限不是 A2A 原生能力**:等待中的任务表现为 `INPUT_REQUIRED`,但批准/应答闭环只存在于
|
|
721
724
|
bridge wire(`task_interaction_request/response`)与 ACP 表面(`session/request_permission` /
|
|
722
725
|
`elicitation/create`)。A2A 客户端要回答交互必须走这两条通道之一;bridge 不为它发明 A2A 扩展。
|
|
726
|
+
相应地,`message.metadata.allowInteractive: true` 会被**明确拒绝**(`-32000`,
|
|
727
|
+
`data.code = "interaction_not_supported"`)且不创建任务 —— 静默跑成非交互会让调用方误以为
|
|
728
|
+
「权限已被自动批准」。要交互请用 ACP `session/new` 的 `_meta.allowInteractive`。
|
|
723
729
|
- **bridge 扩展 URI** 位于 `message.metadata` / `Task.metadata.bridge.*`,全部是增量可选字段:
|
|
724
730
|
|
|
725
731
|
| 扩展 | 位置 | 含义 |
|
|
@@ -727,6 +733,7 @@ curl --noproxy '*' -H "Authorization: Bearer abs_…" -H "Idempotency-Key: 3f9a
|
|
|
727
733
|
| `agentType` | `message.metadata` | 受管 CLI 白名单项(必填) |
|
|
728
734
|
| `cwd` | `message.metadata` | 任务工作目录(必填) |
|
|
729
735
|
| `timeoutMs` / `captureDiff` / `permissionMode` | `message.metadata` | 可选的任务级覆盖 |
|
|
736
|
+
| `allowInteractive` | `message.metadata` | **不支持**:A2A 无请求帧通道,传 `true` 会被拒绝(`interaction_not_supported`) |
|
|
730
737
|
| `bridge.taskLogEndpoint` | `Task.metadata` | 调试日志位置(不是消息来源) |
|
|
731
738
|
| `bridge.statusDetail` | `Task.metadata` | 多个 bridge 状态坍缩到一个 A2A 状态时的真实归因 |
|
|
732
739
|
| `afterEventSeq` | resubscribe `params.metadata` | 补洞游标(eventSeq;缺省 0 = 全量回放) |
|
|
@@ -748,7 +755,9 @@ ACP v1 的 HTTP 承载在上游还是 RFD 阶段,但**本网关这一侧的口
|
|
|
748
755
|
|
|
749
756
|
- **`initialize`**:只声明真实能力——`loadSession: false`(会话不持久续接)、prompt 只收
|
|
750
757
|
text block、fs/terminal 客户端能力不开放。
|
|
751
|
-
- **`session/new`**:固化 `params.cwd` 与 `params._meta.agentType`(12 个受管 CLI
|
|
758
|
+
- **`session/new`**:固化 `params.cwd` 与 `params._meta.agentType`(12 个受管 CLI 必须显式选择);
|
|
759
|
+
可选 `params._meta.allowInteractive: true` 申请本会话的交互(只认布尔)。申请只是**请求**:
|
|
760
|
+
进程没以 `--interaction-enabled` 启动时仍按非交互跑,CLI 的权限申请会被本机直接拒绝。
|
|
752
761
|
- **`session/prompt`(conversation 多轮,add-acp-session-memory)**:首轮创建 bridge conversation
|
|
753
762
|
会话(`run_task` 语义);后续轮 `send_message` 续接**同一会话**——CLI 原生续接(resume /
|
|
754
763
|
ACP session / 重放兜底,12 适配器续接矩阵),**上下文由 CLI 持有、token 只传增量**。
|
|
@@ -759,14 +768,27 @@ ACP v1 的 HTTP 承载在上游还是 RFD 阶段,但**本网关这一侧的口
|
|
|
759
768
|
会话空闲回收复用 conversation 的 `idleTimeoutMs`。bridge 重启后 acp 会话绑定丢失(内存态),
|
|
760
769
|
旧会话不假装可续。
|
|
761
770
|
- **`session/cancel`**:取消当前轮次(`cancel_turn` 编排,operationId 幂等);无活动轮次静默成功。
|
|
762
|
-
-
|
|
763
|
-
|
|
771
|
+
- **交互闭环**:**前提是该 ACP 会话在 `session/new` 声明了 `_meta.allowInteractive: true`**
|
|
772
|
+
(不声明就不会弹请求——默认按非交互执行)。任务进入 `waiting_interaction` 时,prompt 流中注入
|
|
773
|
+
`event: request` 帧(`session/request_permission` 或 `elicitation/create`——permission 走标准选项,
|
|
764
774
|
form/auth-url 走 elicitation(form/url 两种 mode))。客户端用 `POST /acp` 发响应报文
|
|
765
775
|
(无 method、带网关下发的 id + result)应答;网关转成 `task_interaction_response` 走与
|
|
766
776
|
`POST /v1/interactions/{id}:respond` **同一条** dispatch 路径(权限判定双保险)。
|
|
777
|
+
**证据等级**:permission 闭环有真 CLI 证据(kimi-code);form/auth-url(elicitation)已实现且有单测,
|
|
778
|
+
但**在任何适配器上都没有真 CLI 证据**——`interactionKinds` 里的 `form` 表示「这条通道能中转什么」,
|
|
779
|
+
不是「已经观测到什么」。`opencode`/`minimax-code` 会自动放行工具调用所以从不发问;`codex` 在本机
|
|
780
|
+
Windows 上根本不发起工具调用(`codex exec` 只出 reasoning),因此即使 `E2E_INTERACTION=1`,
|
|
781
|
+
它的审批路径仍未被证明。
|
|
767
782
|
- 端到端取证:`npm run e2e:gateway`(真 bridge 进程 + 真服务令牌 + 真跑一次本机 CLI,
|
|
768
783
|
覆盖 A2A send/get/cancel、messageId 幂等与 ACP prompt/cancel 全链路;**多轮记忆含真 CLI
|
|
769
784
|
两轮对话断言**。CLI 出网代理与系统不一致时用 `E2E_PROXY=http://127.0.0.1:<port>` 指定)。
|
|
785
|
+
不指定 `E2E_AGENT` 时脚本会**自动挑一个本机就绪的 CLI**(避免把某个工具的订阅/登录态
|
|
786
|
+
问题当成桥接回归);指定时按指定跑。一个就绪的都没有时退出码 `2`,
|
|
787
|
+
设 `E2E_ALLOW_SKIP=1` 才会以「跳过」结束(并明确打印本轮未验证任何行为)。
|
|
788
|
+
交互闭环(权限请求帧 → 响应报文 → 回合继续)需要 CLI 真的申请权限,各工具差异大
|
|
789
|
+
(kimi-code 会问,opencode/minimax 自动放行,codex 在本机不发工具调用),因此默认不跑:
|
|
790
|
+
`E2E_INTERACTION=1` 才启用。该段**一帧 request 都没收到时记为「未验证」而不是 FAIL**——
|
|
791
|
+
一个从不发问的 agent 既没证伪也没证明桥接。
|
|
770
792
|
- 详见 `contracts/openapi.control-plane.yaml` 的 `a2a-gateway` tag。
|
|
771
793
|
|
|
772
794
|
### 扫描结果实时回传与品牌图标
|
|
@@ -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:
|
|
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;
|
package/dist/app/session.js
CHANGED
package/dist/cli/help.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* 帮助文本(CLI 支撑件)
|
|
3
3
|
*
|
|
4
4
|
* 命令清单与 `dispatch.ts` 的注册表必须一致 —— README 由 `doc:check` 机检,
|
|
5
|
-
*
|
|
5
|
+
* 这里则是给人看的第一份说明:规格里有、实现里没有的条款必须当场写清,不能写成已支持
|
|
6
|
+
*(`context_exhausted` 曾是这种「规格有、实现无」的例子,2026-11-28 落地后不再是)。
|
|
6
7
|
*/
|
|
7
8
|
import { existsSync } from 'node:fs';
|
|
8
9
|
import { configPath } from '../infra/config.js';
|
package/dist/commands/connect.js
CHANGED
|
@@ -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)
|
package/dist/commands/serve.js
CHANGED
|
@@ -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}`;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 上下文超限的**反应式**识别(`context_exhausted`)
|
|
3
|
+
*
|
|
4
|
+
* 为什么不做预算表:桥接拿不到「本次实际模型 → 上下文窗口」的稳定映射
|
|
5
|
+
*(模型可被 `--model`/配置文件/服务端路由随时切换),token 计数也要与各家分词器一致,
|
|
6
|
+
* 阈值附近必然误报;而误报的代价是把能成功的任务提前判死,比不报更坏。
|
|
7
|
+
*
|
|
8
|
+
* 所以判定只来自**失败输出里 CLI 自己给出的超限信号**:claude 的
|
|
9
|
+
* `prompt is too long: 213456 tokens > 200000 maximum`、OpenAI 兼容端的
|
|
10
|
+
* `context_length_exceeded`、Gemini 的 `The input token count exceeds the maximum …`。
|
|
11
|
+
*
|
|
12
|
+
* 规则刻意要求「上下文/token 量词」与「超限语义」**同一行内 80 字符内同现**,
|
|
13
|
+
* 否则会把 gRPC 的 `context deadline exceeded`(超时)、`credit limit exceeded`(额度)
|
|
14
|
+
* 这类完全无关的失败误判成超限 —— 宁可不报,不得虚报。
|
|
15
|
+
*/
|
|
16
|
+
/** 显式错误码风格(出现即命中,不需要量词判断) */
|
|
17
|
+
export const CONTEXT_OVERFLOW_CODES = [
|
|
18
|
+
'context_length_exceeded',
|
|
19
|
+
'context_window_exceeded',
|
|
20
|
+
'context_overflow',
|
|
21
|
+
'prompt_too_long',
|
|
22
|
+
'too_many_tokens',
|
|
23
|
+
'max_tokens_exceeded',
|
|
24
|
+
'token_limit_exceeded',
|
|
25
|
+
'input_too_long',
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* 「什么被撑爆了」——注意 `context` 必须与窗口类词组合,
|
|
29
|
+
* 单写 `context` 会命中 gRPC 的 `context deadline exceeded`(那是超时,不是超限)。
|
|
30
|
+
*/
|
|
31
|
+
const SUBJECT = String.raw `(?:prompt|input|conversation|messages?|token count|tokens?|context[ _-]?(?:window|length|size|limit|budget))`;
|
|
32
|
+
/** 「撑爆了」的语义 */
|
|
33
|
+
const OVERFLOW = String.raw `(?:exceed(?:s|ed|ing)?|too\s+(?:long|large|many|big)|overflow(?:ed|s)?|over\s+the\s+limit|(?:maximum|max)\s*(?:allowed|limit)?\s*(?:is|of)?\s*[\d,]+|out\s+of\s+(?:context|space))`;
|
|
34
|
+
/**
|
|
35
|
+
* 英文:量词与超限语义同现,允许 80 字符间隔(同一行内)。
|
|
36
|
+
*
|
|
37
|
+
* `prompt is too long: 213456 tokens > 200000 maximum` 这类文案里量词在前、语义在后,
|
|
38
|
+
* 也有 `maximum context length is 200000 tokens, however you requested …` 这种反序的,
|
|
39
|
+
* 所以两个方向都要匹配。
|
|
40
|
+
*/
|
|
41
|
+
const EN_PATTERN = new RegExp(`${SUBJECT}[^\\n]{0,80}${OVERFLOW}|${OVERFLOW}[^\\n]{0,80}${SUBJECT}`, 'i');
|
|
42
|
+
/** 中文文案(部分国内 CLI 用中文报错) */
|
|
43
|
+
const ZH_PATTERNS = [
|
|
44
|
+
/上下文(?:窗口|长度|容量)?[^\n。]{0,20}(?:超出|超过|超限|过大|溢出|不够)/,
|
|
45
|
+
/(?:提示词|对话|会话|历史|输入)[^\n。]{0,12}(?:过长|太长|超出|超过)[^\n。]{0,12}(?:上限|限制|窗口|长度)/,
|
|
46
|
+
/token[^\n。]{0,12}(?:超出|超过|超限)[^\n。]{0,8}(?:上限|限制)/i,
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* 反序句式:`maximum context length is 128000 tokens` —— 量词跟在 `maximum` 后面,
|
|
50
|
+
* 数字隔得更远,上面对称规则覆盖不到。
|
|
51
|
+
*
|
|
52
|
+
* 这里刻意要求「max + 窗口类量词 + 至少 4 位数字」,避免把 `--max-tokens 4096`
|
|
53
|
+
* 这类**配置值**(不是错误)当成超限:那个句式里 max 后面直接是 tokens,没有窗口类词。
|
|
54
|
+
*/
|
|
55
|
+
const MAX_CONTEXT_PATTERN = /(?:maximum|max)[ _-]?(?:context[ _-]?(?:window|length|size)|prompt|input|conversation)[^\n]{0,40}?[\d,]{4,}/i;
|
|
56
|
+
/**
|
|
57
|
+
* 判断给定文本是否表达了「上下文超限」。
|
|
58
|
+
*
|
|
59
|
+
* 传入多段(如 `info.error` 与输出尾部)时,**任意一段**命中即算命中。
|
|
60
|
+
* 未命中一律返回 `false`:调用方据此维持 `agent_error`,不得猜测。
|
|
61
|
+
*/
|
|
62
|
+
export function looksLikeContextOverflow(...texts) {
|
|
63
|
+
for (const raw of texts) {
|
|
64
|
+
if (!raw)
|
|
65
|
+
continue;
|
|
66
|
+
const text = String(raw);
|
|
67
|
+
const lower = text.toLowerCase();
|
|
68
|
+
if (CONTEXT_OVERFLOW_CODES.some((code) => lower.includes(code)))
|
|
69
|
+
return true;
|
|
70
|
+
if (MAX_CONTEXT_PATTERN.test(text))
|
|
71
|
+
return true;
|
|
72
|
+
if (EN_PATTERN.test(text))
|
|
73
|
+
return true;
|
|
74
|
+
if (ZH_PATTERNS.some((re) => re.test(text)))
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
package/dist/core/emitter.js
CHANGED
|
@@ -71,6 +71,9 @@ export class Emitter {
|
|
|
71
71
|
emit(msg) {
|
|
72
72
|
// —— 1. 幂等 ——
|
|
73
73
|
// task_snapshot/session_ack 是补取/控制回执,终态后仍必须可发。
|
|
74
|
+
// **artifact_content 同理**:协议里明写「终态后仍可取(走持久元数据 + CAS)」,
|
|
75
|
+
// 而「任务跑完再去取产物」恰恰是最常见的读法——按 taskId 一刀切会把这条读回包也丢掉,
|
|
76
|
+
// 平台只能干等超时(2026-11-28 WS e2e 实测:settle 之后 get_artifact 零响应)。
|
|
74
77
|
// 相同终态也必须能回放(断线重发/同步拒绝重试);不同终态及后续日志仍然拒绝。
|
|
75
78
|
const identicalTerminalReplay = msg.type === 'task_status' &&
|
|
76
79
|
isTerminal(msg.status) &&
|
|
@@ -82,7 +85,8 @@ export class Emitter {
|
|
|
82
85
|
msg.type !== 'session_ack' &&
|
|
83
86
|
msg.type !== 'message_ack' &&
|
|
84
87
|
msg.type !== 'task_interaction_result' &&
|
|
85
|
-
msg.type !== 'interaction_url'
|
|
88
|
+
msg.type !== 'interaction_url' &&
|
|
89
|
+
msg.type !== 'artifact_content') {
|
|
86
90
|
return;
|
|
87
91
|
}
|
|
88
92
|
let out = msg;
|
package/dist/core/errors.js
CHANGED
|
@@ -52,6 +52,10 @@ export const BRIDGE_ERROR_CODES = [
|
|
|
52
52
|
// conversation 创建前就拒:该工具没有任何可续接回合的通道(continuation=single-turn)。
|
|
53
53
|
// 在 message_ack 上早就用它了,这里钉住,让 run_task 的拒绝也能被程序化分支。
|
|
54
54
|
'session_not_continuable',
|
|
55
|
+
// —— 会话历史(replay 超上下文)——
|
|
56
|
+
// 只由 CLI **自己报出的超限文本**触发(core/context-overflow.ts),不做预算预测:
|
|
57
|
+
// 重试同一个 prompt 一定还是失败,正确处理是「开新会话 / 缩短历史」,不是原样重试。
|
|
58
|
+
'context_exhausted',
|
|
55
59
|
];
|
|
56
60
|
export function isBridgeErrorCode(v) {
|
|
57
61
|
return typeof v === 'string' && BRIDGE_ERROR_CODES.includes(v);
|
|
@@ -106,6 +110,9 @@ export const ERROR_HTTP_STATUS = {
|
|
|
106
110
|
artifact_not_found: 404,
|
|
107
111
|
// 会话形态与请求不符(工具不支持多轮),换个参数就能成功 ⇒ 409 而不是 400
|
|
108
112
|
session_not_continuable: 409,
|
|
113
|
+
// 请求本身没写错,服务端也没坏,是「这段历史装不进模型的上下文窗口」⇒ 422(语义不可处理)。
|
|
114
|
+
// 重试无效,客户端应改用新会话或缩短历史。
|
|
115
|
+
context_exhausted: 422,
|
|
109
116
|
};
|
|
110
117
|
export function toProblem(code, opts = {}) {
|
|
111
118
|
return {
|
|
@@ -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';
|
|
@@ -30,6 +30,7 @@ import { buildWinCommandLine, isWinShim } from '../adapters/win-exec.js';
|
|
|
30
30
|
import { withoutHostEnv } from '../adapters/host-env.js';
|
|
31
31
|
import { createStepParser, claudeToolCallOf } from '../adapters/step-parsers.js';
|
|
32
32
|
import { BridgeError } from './errors.js';
|
|
33
|
+
import { looksLikeContextOverflow } from './context-overflow.js';
|
|
33
34
|
import { PartialMessageTracker, acpChunkText, claudeBlockText, codexDeltaText } from './partial-messages.js';
|
|
34
35
|
import { decidePermissionMode, fullResidualPermissionOutcome, permissionEnvFor } from './permission-policy.js';
|
|
35
36
|
import { externalProxyEnv } from '../infra/proxy-env.js';
|
|
@@ -40,6 +41,18 @@ export const KILL_GRACE_MS = 2000;
|
|
|
40
41
|
export const DEFAULT_MAX_TASKS = 30;
|
|
41
42
|
/** 默认队列上限:再长的排队对调用方也没意义(2026-10-24 由 32 调整为 60) */
|
|
42
43
|
export const DEFAULT_MAX_QUEUED = 60;
|
|
44
|
+
/** 单个任务最多上行多少条 codex 非内容通知(去重后);重连风暴时防刷屏 */
|
|
45
|
+
const CODEX_NOTICE_LIMIT = 40;
|
|
46
|
+
/**
|
|
47
|
+
* 失败分类用输出尾部的上限(字符)。
|
|
48
|
+
* 只用来读「上下文超限」这类终局文案,2 KiB 足够(各家报错都在一两行内)。
|
|
49
|
+
*/
|
|
50
|
+
export const CONTEXT_TAIL_LIMIT = 2048;
|
|
51
|
+
/** 追加到有界尾部缓冲:超出即从头部截掉 */
|
|
52
|
+
function appendTail(tail, text) {
|
|
53
|
+
const next = tail + text;
|
|
54
|
+
return next.length > CONTEXT_TAIL_LIMIT ? next.slice(next.length - CONTEXT_TAIL_LIMIT) : next;
|
|
55
|
+
}
|
|
43
56
|
/**
|
|
44
57
|
* `child` 是否位于 `parent` 目录之下(含相等)。
|
|
45
58
|
* 必须按目录边界判断;Windows 路径大小写不敏感,比较前统一折叠。
|
|
@@ -314,6 +327,7 @@ export class TaskSupervisor {
|
|
|
314
327
|
stepRefs: new Map(),
|
|
315
328
|
authGuard: def.authGuard,
|
|
316
329
|
authStderr: '',
|
|
330
|
+
tail: '',
|
|
317
331
|
resolve,
|
|
318
332
|
done,
|
|
319
333
|
};
|
|
@@ -531,6 +545,8 @@ export class TaskSupervisor {
|
|
|
531
545
|
if (entry.state === 'settled')
|
|
532
546
|
return;
|
|
533
547
|
const text = buf.toString('utf8');
|
|
548
|
+
// 失败分类用的输出尾部(有界,不上行):很多 CLI 把「上下文超限」只写在 stderr 上
|
|
549
|
+
entry.tail = appendTail(entry.tail, text);
|
|
534
550
|
if (stream === 'stdout' && entry.hooks.onSession) {
|
|
535
551
|
const nativeSessionId = detectNativeSession(text);
|
|
536
552
|
if (nativeSessionId)
|
|
@@ -798,6 +814,17 @@ export class TaskSupervisor {
|
|
|
798
814
|
return;
|
|
799
815
|
const method = String(notification['method'] ?? '');
|
|
800
816
|
const params = (notification['params'] ?? {});
|
|
817
|
+
// 非内容型通知(重连/回退/配置告警)必须上行:静默是「挂死」误判的温床
|
|
818
|
+
const notice = codexNoticeText(notification);
|
|
819
|
+
if (notice !== undefined) {
|
|
820
|
+
const key = notice.slice(0, 160);
|
|
821
|
+
const seen = (entry.codexNotices ??= new Set());
|
|
822
|
+
if (seen.has(key) || seen.size >= CODEX_NOTICE_LIMIT)
|
|
823
|
+
return;
|
|
824
|
+
seen.add(key);
|
|
825
|
+
entry.hooks.onLog('stderr', `[codex] ${notice}${notice.endsWith('\n') ? '' : '\n'}`);
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
801
828
|
if (method === 'item/agentMessage/delta') {
|
|
802
829
|
const delta = codexDeltaText(notification);
|
|
803
830
|
if (delta !== undefined) {
|
|
@@ -1110,6 +1137,18 @@ export class TaskSupervisor {
|
|
|
1110
1137
|
for (const resolve of entry.acpPermissions?.values() ?? [])
|
|
1111
1138
|
resolve(undefined);
|
|
1112
1139
|
entry.acpPermissions?.clear();
|
|
1140
|
+
/**
|
|
1141
|
+
* 上下文超限的反应式改判(`context_exhausted`)。
|
|
1142
|
+
*
|
|
1143
|
+
* 判定只来自 CLI 自己的失败文本(`info.error` 或输出尾部),**不做预算预测**;
|
|
1144
|
+
* 只替换 `agent_error`,success / cancelled / timeout 与其它受控码一律不动,
|
|
1145
|
+
* 识别不出来就维持 `agent_error` —— 宁可不报,不得虚报。
|
|
1146
|
+
*/
|
|
1147
|
+
if (status === 'failed' &&
|
|
1148
|
+
info.errorCode === 'agent_error' &&
|
|
1149
|
+
looksLikeContextOverflow(info.error, entry.tail)) {
|
|
1150
|
+
info = { ...info, errorCode: 'context_exhausted' };
|
|
1151
|
+
}
|
|
1113
1152
|
// 终态快照存 entry:本条调用链内的重放直接用,不重跑 git diff
|
|
1114
1153
|
entry.finishInfo = withDiff(entry.req, info);
|
|
1115
1154
|
entry.hooks.onStatus(status, entry.finishInfo);
|
package/dist/infra/proxy-env.js
CHANGED
|
@@ -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
|
-
|
|
48
|
+
value = parseWindowsProxyRegistry(queryRegistry('ProxyEnable'), queryRegistry('ProxyServer'));
|
|
40
49
|
}
|
|
41
50
|
catch {
|
|
42
|
-
|
|
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
|
|
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
|
});
|