agent-bridge-service 0.0.0-stage → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +207 -0
  2. package/LICENSE +21 -0
  3. package/README.md +521 -2
  4. package/README.zh-CN.md +498 -0
  5. package/assets/agent-icons/claude-code.svg +1 -0
  6. package/assets/agent-icons/codebuddy-cli.svg +35 -0
  7. package/assets/agent-icons/codex.svg +1 -0
  8. package/assets/agent-icons/ds-harness.svg +1 -0
  9. package/assets/agent-icons/gemini.svg +1 -0
  10. package/assets/agent-icons/grok-cli.svg +1 -0
  11. package/assets/agent-icons/kimi-code.svg +1 -0
  12. package/assets/agent-icons/mimo-code.svg +1 -0
  13. package/assets/agent-icons/minimax-code.svg +1 -0
  14. package/assets/agent-icons/opencode.svg +1 -0
  15. package/assets/agent-icons/qoder-cli-light.svg +1 -0
  16. package/assets/agent-icons/qoder-cli.svg +1 -0
  17. package/assets/agent-icons/trae-cli.svg +1 -0
  18. package/dist/adapters/agent-adapters.js +437 -0
  19. package/dist/adapters/agent-logos.js +40 -0
  20. package/dist/adapters/win-exec.js +25 -0
  21. package/dist/app/bootstrap.js +101 -0
  22. package/dist/app/service-gate.js +43 -0
  23. package/dist/app/session-log.js +7 -0
  24. package/dist/app/session.js +107 -0
  25. package/dist/app/task-dispatch.js +81 -0
  26. package/dist/cli/dispatch.js +42 -0
  27. package/dist/cli/flags.js +40 -0
  28. package/dist/cli/help.js +36 -0
  29. package/dist/cli/hold.js +15 -0
  30. package/dist/cli/meta.js +16 -0
  31. package/dist/cli/render.js +53 -0
  32. package/dist/cli.js +26 -0
  33. package/dist/commands/connect.js +20 -0
  34. package/dist/commands/daemon.js +13 -0
  35. package/dist/commands/logout.js +18 -0
  36. package/dist/commands/serve.js +65 -0
  37. package/dist/commands/services.js +89 -0
  38. package/dist/commands/status.js +16 -0
  39. package/dist/core/emitter.js +119 -0
  40. package/dist/core/errors.js +89 -0
  41. package/dist/core/redact.js +34 -0
  42. package/dist/core/scan.js +55 -0
  43. package/dist/core/task-supervisor.js +277 -0
  44. package/dist/infra/audit.js +54 -0
  45. package/dist/infra/auth.js +174 -0
  46. package/dist/infra/config.js +191 -0
  47. package/dist/infra/git.js +141 -0
  48. package/dist/infra/service-token.js +198 -0
  49. package/dist/protocol.js +144 -0
  50. package/dist/runner.js +37 -0
  51. package/dist/transport/bridge-client.js +139 -0
  52. package/dist/transport/control-plane.js +482 -0
  53. package/dist/transport/outbox.js +95 -0
  54. package/package.json +80 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,207 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres
6
+ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.1](https://github.com/shaylanwu/agent-bridge/compare/v0.2.0...v0.2.1) (2026-10-24)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **release:** 发布后显式触发站点重建,补上历史页滞后一环 ([3285d95](https://github.com/shaylanwu/agent-bridge/commit/3285d953e2208760170e50a3794c6ba397be29f6))
14
+
15
+ ## [0.2.0](https://github.com/shaylanwu/agent-bridge/compare/v0.1.0...v0.2.0) (2026-10-24)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **release:** 发布流水线读取正确的 npm token secret 名 ([d09d393](https://github.com/shaylanwu/agent-bridge/commit/d09d3933d7316f5f382c32aee6ab88c0a33f5f27))
21
+ * **release:** 同时提供 NODE_AUTH_TOKEN,修掉 npm 401 ([2282fde](https://github.com/shaylanwu/agent-bridge/commit/2282fde60179f0c3c78fe95588c2fca948e46d3f))
22
+ * **release:** 预检兼容两种 secret 名,并清理粘贴带进来的空白 ([94aeaa7](https://github.com/shaylanwu/agent-bridge/commit/94aeaa7922a28371e987f0366face924963638a2))
23
+
24
+
25
+ ### Features
26
+
27
+ * **bridge-client:** 断线期间的 task_log 缓冲并重连补发 ([c183244](https://github.com/shaylanwu/agent-bridge/commit/c1832446bc7d4c25d334b569c65b4450b5624775))
28
+ * **cli:** --token 模式支持 --device-id,WS 地址不再发空 deviceId ([d1c9603](https://github.com/shaylanwu/agent-bridge/commit/d1c960387cc20acd8b3b8a03cf44093ece2d1f93))
29
+ * **release:** semantic-release 自动发布,站点构建期渲染版本历史 ([d6a0815](https://github.com/shaylanwu/agent-bridge/commit/d6a08158e3219eb02f8374296b34db84d6d1a0b6))
30
+ * **runner:** 平台 env 白名单 + 并发任务上限 ([ce85c83](https://github.com/shaylanwu/agent-bridge/commit/ce85c834c0457b0aabd3fdeabf2433f0cd48d580))
31
+ * **runner:** 移除平台 env 通道(不做白名单,直接删)+ max_tasks 可配置 ([6f4473b](https://github.com/shaylanwu/agent-bridge/commit/6f4473be8d6485fc58af4270a3c2acf191efd8e4))
32
+ * **runner:** 超限任务改为有界 FIFO 排队(标准做法),不再直接拒绝 ([4d57852](https://github.com/shaylanwu/agent-bridge/commit/4d578524efc612a642403af130e2cae6f499dd43))
33
+ * **scan:** 并发探测 + 扫描结果实时回传 + 官方品牌图标 ([1c07231](https://github.com/shaylanwu/agent-bridge/commit/1c072315d081d794f58ecdb6710d0fae04df62ed))
34
+ * **site:** 中英文档站(Astro Starlight + Scalar),API 参考由契约生成 ([a1994d4](https://github.com/shaylanwu/agent-bridge/commit/a1994d44368595d557dfdeacddd7f0ecfd9ee436))
35
+
36
+ ## [Unreleased]
37
+
38
+ ### Added
39
+
40
+ - **Release automation** — version numbers now come from commit messages. `.releaserc.json` +
41
+ `.github/workflows/release.yml` run semantic-release on every push to `main` (`feat` → minor,
42
+ `fix` → patch, `feat!` / `BREAKING CHANGE:` → major, everything else publishes nothing): it bumps
43
+ `package.json`, writes `CHANGELOG.md`, tags `v*`, opens the GitHub Release and publishes to npm.
44
+ Needs two repository secrets — `AGENT_BRIDGE_NPM_TOKEN` and the default `GITHUB_TOKEN` — and **takes over tagging**:
45
+ a hand-made `v*` tag now collides with it. `commitlint` + `husky` reject non-conventional commit
46
+ messages locally, and `.github/workflows/site.yml` builds and deploys the docs site to GitHub Pages on
47
+ the same push. The site's changelog page is now rendered from `CHANGELOG.md` at build time
48
+ (`site/scripts/gen-changelog.mjs`) instead of being a placeholder that said "automation pending", so the
49
+ two can't drift — `site-check` fails if they do. Two deviations from the stock setup, both verified
50
+ offline by `scripts/verify-release.mjs`: `scripts/semantic-release-changelog.mjs` replaces
51
+ `@semantic-release/changelog` because that plugin can only prepend to the file (which would put
52
+ `# Changelog` *below* the version headings), and the preset is `angular` rather than
53
+ `conventionalcommits` because the latter's current majors need a newer changelog writer than
54
+ semantic-release 25 ships.
55
+
56
+ - **CodeBuddy CLI adapter** — `kind: "codebuddy-cli"` (Tencent `@tencent-ai/codebuddy-code`, command `codebuddy`,
57
+ alias `cbc`). Non-interactive like Claude Code (`-p "{{prompt}}" --output-format text`); credentials detected via
58
+ the `~/.codebuddy` directory (interactive login, no env key). The adapter registry is now **12 tools**, and every
59
+ "11 adapters/agents" figure across the READMEs, `llms.txt`, `AGENTS.md`, CLI help, tests and the docs site has been
60
+ updated in the same pass. OpenSpec proposal: `openspec/changes/add-codebuddy-cli/`.
61
+
62
+ - **Documentation site (W1–W3)** — `site/` is a standalone Astro + Starlight workspace (never built by the
63
+ main package, never published to npm). English + 简体中文 content trees with a language switcher;
64
+ Pagefind full-text search indexes **2 locales / 28 pages**.
65
+ - **API reference is generated, not retyped**: `site/scripts/gen-reference.mjs` renders
66
+ `protocol/messages.md`, `api/reference.md` and `api/control-plane-reference.md` from the three contracts,
67
+ in both locales. Because those pages are static HTML, endpoint paths and field names are searchable —
68
+ the Scalar try-it pages (`api/`, `api/control-plane/`) render client-side and are deliberately not
69
+ searchable, so both exist and each does one job.
70
+ - `site/scripts/site-check.mjs` fails on: a CLI command with no docs page, a control-plane endpoint missing
71
+ from the generated pages, generated pages out of sync with contracts, or an en/zh-cn page mismatch.
72
+ - Contracts and `llms.txt` are copied into `site/public/` at build time — the site never keeps a second copy.
73
+ - **Light / dark / follow-system theming** — Starlight ships the theme picker (`auto` follows the OS by
74
+ default) and code blocks switch with it. The Scalar API viewer is client-rendered and would otherwise stay
75
+ stuck on one theme, so `ApiReference.astro` reads `document.documentElement.dataset.theme`, watches it with a
76
+ `MutationObserver` (covers both manual picks and OS changes under `auto`), and re-renders on change; Scalar's
77
+ own toggle is hidden so there is only one theme control on the page.
78
+ - **Site design system (v3)** — `site/src/styles/custom.css` overrides only Starlight's exposed CSS variables
79
+ plus a few structural rules: one accent (`#17A67F` light / `#41C398` dark) over cool grey neutrals, dark mode
80
+ on deep navy (`#0B1220`) rather than pure black, headings capped at weight 500 with negative tracking, the
81
+ sidebar's current item marked by a 2px accent bar, borderless three-column features separated by whitespace,
82
+ and a two-column path switch split by a 1px rule. The homepage (centered hero + outbound connection figure +
83
+ features + paths) lives in `site/src/components/home/`, shared by both locales with copy passed in from
84
+ `index.mdx`. The site has exactly one animation — a packet dot travelling the outbound link (2.4 s), disabled
85
+ under `prefers-reduced-motion` — plus a 2px reading-progress bar in the header. CJK copy gets 1.8 line height,
86
+ strict line breaking and tabular numerals.
87
+ - **AI-agent narrative + agent wall** — visitor-facing copy now says "AI agents" (the product story) while
88
+ "CLI" stays in technical contexts (CLI reference, status probing); README ×2 and the package description
89
+ follow the same wording. The homepage lists all 11 supported agents with their official brand-coloured
90
+ logos, synced from `assets/agent-icons/` at build time by `sync-contracts.mjs` — the site never keeps a
91
+ second copy, and `site-check` fails if the wall and `src/adapters/agent-adapters.ts` drift apart.
92
+ Generated reference pages are now regenerated on every build (`build.mjs` runs `gen-reference.mjs` first).
93
+ - **Brand mark** — a geometric logo (`site/src/assets/logo-{light,dark}.svg`): a device square, an outbound
94
+ line, a platform dot. Rendered in the header (per-theme variant) and as `favicon.svg`. Code blocks are dark
95
+ in both themes (single `starlight-dark` theme), matching the docs-page reference style.
96
+
97
+ - **Diff capture (P0-6)** — a `run_task` with `captureDiff: true` now returns the worktree diff on the terminal
98
+ `task_status`: `diff` (unified diff), `changedFiles` (repo-relative paths) and `diffTruncated`.
99
+ Non-git directories yield an empty diff instead of an error; oversized diffs are cut on a line boundary at
100
+ `diff_max_bytes` (default 256 KB, `AGENT_BRIDGE_DIFF_MAX_BYTES` overrides). Untracked files are `git add -N`-ed
101
+ only for the duration of the capture and `git reset -q`-ed afterwards, so nothing is committed and the index is
102
+ left exactly as it was.
103
+ - **Service identity / scoped service tokens (P0-8)** — `agent-bridge services issue|list|revoke|rotate` manages
104
+ tokens of the form `abs_<kid>_<secret>`; only the SHA-256 of the secret is stored (0600) and comparison is
105
+ constant-time. Scopes: `task:create`, `task:cancel`, `task:read`, `device:read` — `cancel_task` needs
106
+ `task:cancel`, holding `task:create` is not enough. Rotation keeps the previous token alive for a grace window
107
+ (`--grace-hours`, default 24).
108
+ - `run_task` / `cancel_task` accept `requestedBy` (≤128), `purpose` (≤64) and `serviceToken`;
109
+ the bridge echoes `requestedBy` on the terminal `task_status` so platforms can persist `requested_by`.
110
+ With no token registered and `require_service_token = false`, behaviour is unchanged; a token that is present
111
+ must verify.
112
+ - `hello.capabilities` — capability negotiation (`diff`, `service-token`, `queue`, `scan-progress`) so
113
+ third-party platforms degrade by feature instead of guessing from the CLI version.
114
+ - Audit trail at `~/.agent-bridge/audit.jsonl` (0600, one JSON per line): id / scope / purpose / action / outcome,
115
+ never tokens or credential contents.
116
+ - New config keys: `diff_default`, `diff_max_bytes`, `require_service_token`.
117
+ - New module map: `src/git.ts`, `src/service-token.ts`, `src/audit.ts`.
118
+
119
+ ### Changed(架构通用化:第一期 + 第二期 + 第三期)
120
+
121
+ - **源码分层**:`src/core/`(领域:错误码 / 上行出口 / 任务调度 / 脱敏 / 扫描)、`src/transport/`
122
+ (出站 WebSocket + 补发缓冲)、`src/adapters/`(11 个 CLI 适配器 / 图标 / Windows 引号)、
123
+ `src/infra/`(配置 / 授权 / git / 审计 / 服务令牌)。根目录只留 `cli.ts`、`protocol.ts`
124
+ 与 `runner.ts`(后者降级为 v1 兼容包装,新代码请引 `src/core/task-supervisor.ts`)。
125
+ - **本地回环控制面(可选扩展,默认关闭)**:`agent-bridge serve <platformUrl> [--port=8787]` = `connect`
126
+ + 一个只绑 `127.0.0.1` 的 HTTP 控制面,服务**本机上的其它程序**(IDE 插件 / 脚本 / MCP server / CI),
127
+ 远程平台仍走出站 WebSocket(两条通道互不干扰)。端点:`/v1/health`(免鉴权)、`/v1/capabilities`、
128
+ `/v1/agents`、`/v1/agents:scan`、`/v1/tasks`(`Idempotency-Key` 防重跑)、`GET /v1/tasks/{id}`、
129
+ `POST /v1/tasks/{id}:cancel`(幂等)、`/v1/tasks/{id}/events`(SSE)、`/v1/tasks/{id}/diff`。
130
+ 红线:默认关闭(`[control_plane] enabled` / `--port` 才启用)、只绑回环、强制 scoped Bearer、
131
+ **不返回 CORS 头**、不新增运行时依赖。控制面下发的任务与平台下发的共享同一个 `TaskSupervisor`
132
+ (并发上限不因多开一条通道而翻倍),上行同样只经 `Emitter`。错误统一 RFC 9457 `problem+json`。
133
+ 契约:`contracts/openapi.control-plane.yaml`。
134
+ - **受控错误码**:`task_status.errorCode` 取自 `src/core/errors.ts` 的受控枚举(15 个),
135
+ 与平台侧 design §7 的错误分类表对齐;`error` 仍保留人类可读串。平台不再需要匹配文案。
136
+ - **唯一上行出口 `src/core/emitter.ts`**:所有上行报文只经 `Emitter.emit()`,在这里收口
137
+ ①终态幂等(settled 后丢弃该 task 的后续事件)②日志脱敏(家目录 → `~`、≥64 位长串折叠)
138
+ ③审计旁路 ④可选 CloudEvents 1.0 信封。横切逻辑只写一遍,不再每个能力各写一次。
139
+ - **任务调度可实例化**:`runner.ts` 的模块级单例状态(`runningTasks` / `queue` / `currentMaxTasks`)
140
+ 内聚为 `class TaskSupervisor`,可注入、可单测、可多实例;状态机显式化为
141
+ `queued → running → settled`(settled 是吸收态)。
142
+ - **排队语义**:并发之上的任务排队而非失败;为保持 v1 兼容 `status` 仍是 `running`,
143
+ 额外给出 `phase: 'queued'` 与 `queuePosition`(1 起)。老平台忽略即可,行为不变。
144
+ - **机器可读契约**:新增 `contracts/asyncapi-3.0.yaml`(WebSocket 通道)与
145
+ `contracts/openapi-3.1.yaml`(**平台需实现**的 4 个 HTTP 端点),以及 `llms.txt`。
146
+ `npm run contracts:check` 校验 wire 类型 / 能力清单 / 错误码 / 平台端点与代码一致,漂移即失败,
147
+ 并已接入 `npm run gate`。
148
+ - **护栏同步**:`protocol-boundary-check` 的 shell / 监听白名单改按新路径(`src/core/task-supervisor.ts`、
149
+ `src/infra/auth.ts`),并为本地回环控制面预留了**有条件**的口子(必须只绑回环 + 默认关闭 +
150
+ 不返回 CORS 头);`doc-contract-check` 新增能力清单记载校验与 `services` 命令;
151
+ `always-on.md` 新增「分层与唯一出口」红线。
152
+ - **入口瘦身(第四期)**:`src/cli.ts` 548 行 → 31 行,只做 `argv → dispatch()` 与顶层错误兜底。
153
+ 新增 `src/cli/`(参数解析 / 终端渲染 / 帮助 / 命令注册表)与 `src/commands/`(一个命令一个文件),
154
+ 并把「连接生命周期、指令路由、任务编排、服务身份校验」从入口抽出为 `src/app/`
155
+ (`session.ts` / `task-dispatch.ts` / `service-gate.ts` / `session-log.ts`)。
156
+ 依赖单向:`cli.ts → cli/ → commands/ → app/ → { core, transport, adapters, infra }`;
157
+ ⛔ `src/app/` 不得直接 `console.*`(输出走注入的 `SessionLog`)—— 这是本地控制面板能复用
158
+ 同一段编排、且不被 stdout 绑死的前提。对外契约、报文、CLI 用法、配置键**零变化**
159
+ (`e2e:smoke` 10 项全 PASS 取证)。
160
+ - 单测 54 → 71。
161
+
162
+ ### Changed(项目名称与开源许可)
163
+
164
+ - **许可证由 Apache-2.0 改为 MIT**:`LICENSE`、`package.json`、两份 README、两份契约的
165
+ `info.license` 同步;此后发布的版本以 MIT 授权(0.1.0 及更早的已发布版本仍按 Apache-2.0 授权)。
166
+ - **显示名统一为 `Agent Bridge Service`**(文档站标题、页脚版权声明、各页 description、
167
+ `gen-reference` 生成的 API 参考描述)。⛔ 不动的东西:npm 包名 `agent-bridge-service`、
168
+ CLI 命令 `agent-bridge`、配置目录 `~/.agent-bridge/`、站点 base `/agent-bridge`、
169
+ OAuth `client_id = "agent-bridge"` —— 这些是对外契约,改名等于破坏兼容性。
170
+
171
+ ### Planned
172
+
173
+ - `daemon` mode (systemd / launchd / Windows service) with start-on-boot.
174
+ - Self-update from the release channel.
175
+
176
+ ## [0.1.0] - 2026-10-22
177
+
178
+ ### Added
179
+
180
+ - `agent-bridge status` — probes 11 AI coding CLIs (Claude Code, Codex, DeepSeek Harness, Gemini CLI,
181
+ opencode, Mimo Code, Qoder CLI, Grok CLI, Kimi Code, MiniMax Code, Trae CLI) and reports
182
+ `ready` / `no credentials` / `not installed`, plus a `broken` flag when a binary exists but cannot run.
183
+ Includes a 30-second cache with `--fresh` and machine-readable `--json` output.
184
+ - `agent-bridge connect <platformUrl>` — binds this machine over an outbound WebSocket. Authorization uses
185
+ a loopback callback with PKCE S256 and reuses the existing browser session; `--no-browser` falls back to
186
+ a device code, `--token` accepts a pre-issued device token.
187
+ - `agent-bridge logout` — clears local device credentials.
188
+ - WebSocket transport with bearer handshake, 15 s heartbeat, exponential backoff (1 s → 30 s), buffered
189
+ status messages replayed after reconnect, and no reconnect loop once a device is revoked.
190
+ - Task execution with an adapter whitelist, argument arrays (no shell interpolation), working-directory
191
+ validation, per-task timeout, graceful cancel (`SIGTERM` → 2 s → `SIGKILL`) and 4 KB log chunks.
192
+ - Protocol v1 with runtime validation. Bridge → platform: `hello`, `agent_list`, `scan_result`,
193
+ `task_log`, `task_status`, `pong`. Platform → bridge: `run_task`, `cancel_task`, `scan`, `ping`.
194
+ - Configuration at `~/.agent-bridge/config.toml` (`%APPDATA%\agent-bridge\config.toml` on Windows) with
195
+ `0600` permissions and token redaction in all output.
196
+ - Windows support for `.cmd` / `.bat` shims through an explicitly quoted command line.
197
+ - Unit tests covering protocol validation, log chunking, PKCE shape, the adapter registry and command-line
198
+ quoting.
199
+
200
+ ### Security
201
+
202
+ - API keys and credential files are never read or uploaded; only their presence is reported.
203
+ - The authorization callback listens on `127.0.0.1` only, accepts a single request, and authorization
204
+ codes are single-use with PKCE S256 verification.
205
+
206
+ [unreleased]: https://github.com/shaylanwu/agent-bridge/compare/v0.1.0...HEAD
207
+ [0.1.0]: https://github.com/shaylanwu/agent-bridge/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agent Bridge Service contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.