agent-bridge-service 1.1.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 CHANGED
@@ -5,6 +5,18 @@ 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
+
8
20
  ## [1.1.0](https://github.com/shaylanwu/agent-bridge/compare/v1.0.0...v1.1.0) (2026-11-27)
9
21
 
10
22
 
package/README.md CHANGED
@@ -387,7 +387,9 @@ ACP: `codebuddy-cli`, `ds-harness`, `agy`, `opencode`, `mimo-code`, `kimi-code`,
387
387
  automation-only on that channel: it announces `permission` nowhere (tools run without asking, so its
388
388
  `executionModes` declares an empty `interactionKinds`) and continues sessions through its own
389
389
  `session/resume` rather than the standard `session/load`. `codex` uses the
390
- `codex app-server` JSON-RPC surface (thread/resume, turn/steer, approvals); Claude
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
391
393
  conversations keep a resident `stream-json` process across turns; Qoder uses headless with native `--resume`.
392
394
  CodeBuddy prefers an explicit `CODEBUDDY_AUTH_TOKEN`; otherwise the bridge reads the plaintext
393
395
  `auth/*.info` from the local CodeBuddyExtension and injects it into the ACP child. If neither exists it
@@ -653,6 +655,7 @@ v1. **But if a message carries a token, it must verify** — there is no "presen
653
655
  | `agent_protocol_error` | The agent ended a turn with an unresolved interaction or violated the execution protocol |
654
656
  | `idempotency_conflict` | The same idempotency key was reused with a different request fingerprint |
655
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` |
656
659
  | `unauthorized` / `invalid_token` / `token_expired` / `insufficient_scope` | Service-token failures |
657
660
  | `protocol_incompatible` / `internal` | Version mismatch / bridge-side fault |
658
661
 
@@ -857,6 +860,12 @@ an external contract** (decided 2026-11-22: frame formats will not follow upstre
857
860
  `POST /acp` with a response envelope (no method, carrying the gateway-issued id + result); the
858
861
  gateway converts it into `task_interaction_response` and runs the **same** dispatch path as
859
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`.
860
869
  - End-to-end proof: `npm run e2e:gateway` (real bridge process + real service token + one real local
861
870
  CLI run, covering A2A send/get/cancel, messageId idempotency, and the ACP prompt/cancel loop;
862
871
  **multi-turn memory is asserted with a real two-round CLI dialogue**. If the CLIs' outbound proxy
@@ -866,12 +875,15 @@ an external contract** (decided 2026-11-22: frame formats will not follow upstre
866
875
  When none is ready it exits `2`, and only `E2E_ALLOW_SKIP=1` turns that into a skip (clearly
867
876
  reported as "nothing was verified"). The interaction loop (request frame → response envelope →
868
877
  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`.
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.
870
882
  - Full contract: the `a2a-gateway` tag in `contracts/openapi.control-plane.yaml`.
871
883
 
872
884
  ### Live scan progress and brand icons
873
885
 
874
- Probing 11 CLIs takes a few seconds, so results stream in instead of arriving as one batch: for every adapter
886
+ Probing 12 CLIs takes a few seconds, so results stream in instead of arriving as one batch: for every adapter
875
887
  that finishes, the bridge sends `scan_progress` with the newly finished `items` and `done: false`; one final
876
888
  `scan_progress` with `done: true` closes the probing phase, followed by the terminal list (`agent_list` on
877
889
  connect, or `scan_result` carrying the same `requestId` when answering `scan`). A platform that ignores
package/README.zh-CN.md CHANGED
@@ -340,7 +340,8 @@ ACP:`codebuddy-cli`、`ds-harness`、`agy`、`opencode`、`mimo-code`、`kimi-
340
340
  `ds-harness` 在这条通道上是 **automation-only**(实测):跑工具只发 `tool_call`、从不回问权限,所以它的
341
341
  `executionModes.interactionKinds` 声明为空数组;续会话靠自家的 `session/resume`,标准 `session/load`
342
342
  会回 `-32601 Method not found`(客户端先试 load 再退 resume)。
343
- `codex` 走 `codex app-server` JSON-RPC(thread/resume、turn/steer、审批);Claude 的
343
+ `codex` 走 `codex app-server` JSON-RPC(thread/resume、turn/steer,审批请求经
344
+ `item/*/requestApproval` 接通——但**本机尚未取到真 CLI 的审批证据**,见下面交互闭环段);Claude 的
344
345
  conversation 保持常驻 `stream-json` 进程(Turn 间复用);Qoder 用 headless + 原生 `--resume`,其余工具保持各自已声明通道。
345
346
  CodeBuddy 优先用显式 `CODEBUDDY_AUTH_TOKEN`;未设置时从本机 CodeBuddyExtension 的明文
346
347
  `auth/*.info` 读取登录态并注入 ACP 子进程。两者都没有时回落 `codebuddy -p`,不会启动无认证子进程。
@@ -593,6 +594,7 @@ bridge 会在终态 `task_status` 上**回显 `requestedBy`**,供平台落 `re
593
594
  | `agent_protocol_error` | Agent 在交互未决时结束回合或违反执行协议 |
594
595
  | `idempotency_conflict` | 同一幂等键携带了不同的请求指纹 |
595
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` |
596
598
  | `unauthorized` / `invalid_token` / `token_expired` / `insufficient_scope` | 服务令牌四类失败 |
597
599
  | `protocol_incompatible` / `internal` | 版本不匹配 / bridge 自身异常 |
598
600
 
@@ -772,6 +774,11 @@ ACP v1 的 HTTP 承载在上游还是 RFD 阶段,但**本网关这一侧的口
772
774
  form/auth-url 走 elicitation(form/url 两种 mode))。客户端用 `POST /acp` 发响应报文
773
775
  (无 method、带网关下发的 id + result)应答;网关转成 `task_interaction_response` 走与
774
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
+ 它的审批路径仍未被证明。
775
782
  - 端到端取证:`npm run e2e:gateway`(真 bridge 进程 + 真服务令牌 + 真跑一次本机 CLI,
776
783
  覆盖 A2A send/get/cancel、messageId 幂等与 ACP prompt/cancel 全链路;**多轮记忆含真 CLI
777
784
  两轮对话断言**。CLI 出网代理与系统不一致时用 `E2E_PROXY=http://127.0.0.1:<port>` 指定)。
@@ -779,7 +786,9 @@ ACP v1 的 HTTP 承载在上游还是 RFD 阶段,但**本网关这一侧的口
779
786
  问题当成桥接回归);指定时按指定跑。一个就绪的都没有时退出码 `2`,
780
787
  设 `E2E_ALLOW_SKIP=1` 才会以「跳过」结束(并明确打印本轮未验证任何行为)。
781
788
  交互闭环(权限请求帧 → 响应报文 → 回合继续)需要 CLI 真的申请权限,各工具差异大
782
- (kimi-code 会问,opencode/minimax 自动放行),因此默认不跑:`E2E_INTERACTION=1` 才启用。
789
+ (kimi-code 会问,opencode/minimax 自动放行,codex 在本机不发工具调用),因此默认不跑:
790
+ `E2E_INTERACTION=1` 才启用。该段**一帧 request 都没收到时记为「未验证」而不是 FAIL**——
791
+ 一个从不发问的 agent 既没证伪也没证明桥接。
783
792
  - 详见 `contracts/openapi.control-plane.yaml` 的 `a2a-gateway` tag。
784
793
 
785
794
  ### 扫描结果实时回传与品牌图标
package/dist/cli/help.js CHANGED
@@ -2,8 +2,8 @@
2
2
  * 帮助文本(CLI 支撑件)
3
3
  *
4
4
  * 命令清单与 `dispatch.ts` 的注册表必须一致 —— README 由 `doc:check` 机检,
5
- * 这里则是给人看的第一份说明,未实现的能力必须当场写清(例如 `context_exhausted`
6
- * 这类规格里有、实现里没有的条款,不能写成已支持)。
5
+ * 这里则是给人看的第一份说明:规格里有、实现里没有的条款必须当场写清,不能写成已支持
6
+ *(`context_exhausted` 曾是这种「规格有、实现无」的例子,2026-11-28 落地后不再是)。
7
7
  */
8
8
  import { existsSync } from 'node:fs';
9
9
  import { configPath } from '../infra/config.js';
@@ -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
+ }
@@ -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;
@@ -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 {
@@ -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';
@@ -42,6 +43,16 @@ export const DEFAULT_MAX_TASKS = 30;
42
43
  export const DEFAULT_MAX_QUEUED = 60;
43
44
  /** 单个任务最多上行多少条 codex 非内容通知(去重后);重连风暴时防刷屏 */
44
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
+ }
45
56
  /**
46
57
  * `child` 是否位于 `parent` 目录之下(含相等)。
47
58
  * 必须按目录边界判断;Windows 路径大小写不敏感,比较前统一折叠。
@@ -316,6 +327,7 @@ export class TaskSupervisor {
316
327
  stepRefs: new Map(),
317
328
  authGuard: def.authGuard,
318
329
  authStderr: '',
330
+ tail: '',
319
331
  resolve,
320
332
  done,
321
333
  };
@@ -533,6 +545,8 @@ export class TaskSupervisor {
533
545
  if (entry.state === 'settled')
534
546
  return;
535
547
  const text = buf.toString('utf8');
548
+ // 失败分类用的输出尾部(有界,不上行):很多 CLI 把「上下文超限」只写在 stderr 上
549
+ entry.tail = appendTail(entry.tail, text);
536
550
  if (stream === 'stdout' && entry.hooks.onSession) {
537
551
  const nativeSessionId = detectNativeSession(text);
538
552
  if (nativeSessionId)
@@ -1123,6 +1137,18 @@ export class TaskSupervisor {
1123
1137
  for (const resolve of entry.acpPermissions?.values() ?? [])
1124
1138
  resolve(undefined);
1125
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
+ }
1126
1152
  // 终态快照存 entry:本条调用链内的重放直接用,不重跑 git diff
1127
1153
  entry.finishInfo = withDiff(entry.req, info);
1128
1154
  entry.hooks.onStatus(status, entry.finishInfo);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-bridge-service",
3
- "version": "1.1.0",
3
+ "version": "1.2.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": {