@yitom/acp-client 0.1.14 → 0.1.15
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/README.md +30 -12
- package/dist/client/acp-client.d.ts +7 -0
- package/dist/client/client-handlers.d.ts +4 -1
- package/dist/index.cjs +202 -55
- package/dist/index.d.ts +2 -2
- package/dist/index.js +196 -49
- package/dist/resources/runtime-bindings.d.ts +5 -0
- package/dist/runtimes/agy/index.d.ts +15 -0
- package/dist/runtimes/agy/quota.d.ts +1 -0
- package/dist/session/session-capabilities.d.ts +2 -2
- package/dist/sidecar.cjs +8797 -8967
- package/dist/version.d.ts +1 -1
- package/docs/adding-an-agent.md +1 -1
- package/docs/api-reference.md +10 -3
- package/docs/getting-started.md +15 -17
- package/docs/tauri-integration.md +4 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
## ⚡ 核心特性
|
|
21
21
|
|
|
22
|
-
- **多 Agent 统一适配(
|
|
23
|
-
开箱即用支持 `codex-acp` (ChatGPT)、`claude`、`cursor-cli`、`deepseek`、`gemini`、`copilot`、`opencode`、`agy`。新增 Agent 只需在该包实现一个适配器,全局所有项目自动生效。
|
|
22
|
+
- **多 Agent 统一适配(10 大内置运行时)**:
|
|
23
|
+
开箱即用支持 `codex-acp` (ChatGPT)、`claude`、`cursor-cli`、`deepseek`、`gemini`、`copilot`、`opencode`、`opencode-v2`、`antigravity-cli`、`agy`。新增 Agent 只需在该包实现一个适配器,全局所有项目自动生效。
|
|
24
24
|
- **纯 Node.js / Headless 架构**:
|
|
25
25
|
不依赖任何 Electron API、React 或特定前端框架。配置目录跨平台自动检测回落(支持自定义 `dataDir`)。
|
|
26
26
|
- **生命周期全托管**:
|
|
@@ -47,7 +47,9 @@
|
|
|
47
47
|
| `gemini` | Gemini | `~/.gemini/oauth_creds.json` / `GEMINI_API_KEY` | 自动探测 OAuth 凭证与系统 Key |
|
|
48
48
|
| `copilot` | Copilot | `~/.copilot/config.json` / `GH_TOKEN` | 自动提取 `loggedInUsers` 凭证列表 |
|
|
49
49
|
| `opencode` | OpenCode | `$XDG_DATA_HOME/opencode/auth.json` | 遵循 XDG / `%LOCALAPPDATA%` 规范 |
|
|
50
|
-
| `
|
|
50
|
+
| `opencode-v2` | OpenCode v2 | v2 SQLite 登录态 | 通过 `npx @opencode/cli acp` 启动 |
|
|
51
|
+
| `antigravity-cli` | Antigravity | Antigravity CLI 登录态 (`agy acp`) | 自动探测 `PATH` 与 `~/.local/bin/agy`,支持配额探测与浏览器认证 |
|
|
52
|
+
| `agy` | Antigravity (legacy bridge) | `@yitom/agy-acp-map` 桥接器 | `tryDirectSessionFirst` 免鉴权直通,保留旧会话 ID 与扩展 |
|
|
51
53
|
|
|
52
54
|
---
|
|
53
55
|
|
|
@@ -70,11 +72,9 @@ const client = new AcpClient({
|
|
|
70
72
|
},
|
|
71
73
|
onPermissionRequest: async ({ toolCall, params }) => {
|
|
72
74
|
console.log(`Agent 请求调用工具:`, toolCall)
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
return
|
|
76
|
-
? { outcome: 'selected' as const, optionId: pickAllowOptionId(params)! }
|
|
77
|
-
: { outcome: 'cancelled' as const }
|
|
75
|
+
console.log('审批选项', params.options)
|
|
76
|
+
// 交互宿主展示选项,并返回用户选择的 optionId。
|
|
77
|
+
return { outcome: 'cancelled' as const }
|
|
78
78
|
},
|
|
79
79
|
onSessionUpdate: (event) => {
|
|
80
80
|
console.log(`[Stream Event]:`, event)
|
|
@@ -92,7 +92,7 @@ if (!connectResult.ok) {
|
|
|
92
92
|
// 3. 创建/恢复会话
|
|
93
93
|
const sessionResult = await client.createSession()
|
|
94
94
|
if (sessionResult.ok) {
|
|
95
|
-
const session = sessionResult.
|
|
95
|
+
const session = sessionResult.value
|
|
96
96
|
// 4. 发送提示词 / 消息交互
|
|
97
97
|
await session.prompt('请帮我分析当前项目目录结构')
|
|
98
98
|
}
|
|
@@ -122,7 +122,7 @@ Sidecar:`session/open` 结果带 `availableCommands`(若已收到),并
|
|
|
122
122
|
在本包根目录一键构建生成 `dist`(ESM / CJS / `.d.ts`):
|
|
123
123
|
|
|
124
124
|
```bash
|
|
125
|
-
bun run build
|
|
125
|
+
bun run build
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
产物说明:
|
|
@@ -137,7 +137,7 @@ bun run build:acp
|
|
|
137
137
|
我们在 [`examples/standalone-acp-demo.ts`](./examples/standalone-acp-demo.ts) 提供了可在终端直接运行的验证脚本:
|
|
138
138
|
|
|
139
139
|
```bash
|
|
140
|
-
bun run
|
|
140
|
+
bun run examples/standalone-acp-demo.ts
|
|
141
141
|
```
|
|
142
142
|
|
|
143
143
|
资源接口当前为未发布试点:规则准备与会话应用分开记录;已有磁盘配置保守回退;skillsFound 仅 SDK 文件扫描,尚无原生技能挂载或通用兼容提示词注入。详见 docs/api-reference.md 第 5 节。
|
|
@@ -148,7 +148,25 @@ bun run packages/acp/examples/standalone-acp-demo.ts
|
|
|
148
148
|
|
|
149
149
|
会话专属配置环境:`resources: { directory, configurationScope: 'session' }`。仅替换子进程原生配置根,生成规则/纯文档技能、断开清理;不复制用户认证。支持范围、Cursor 规则边界及 agy/DeepSeek 的明确拒绝见 `docs/api-reference.md`。实现与测试:`src/resources/session-config.ts` / `session-config.test.ts`。
|
|
150
150
|
|
|
151
|
-
###
|
|
151
|
+
### Agent 启动方式
|
|
152
|
+
|
|
153
|
+
Codex、Claude 和 DeepSeek 的启动命令会解析各自发布包的 `latest`,OpenCode v2 由 npm 启动。Antigravity、Gemini、Copilot、Cursor 和 `opencode` 入口使用宿主安装的 CLI。握手使用 ACP v1。
|
|
154
|
+
|
|
155
|
+
需要安装包时,在 GitHub Actions 手动运行 `CI & Publish`。测试通过后,Artifacts 中的 `acp-client-npm-package` 包含 npm `.tgz`。
|
|
156
|
+
|
|
157
|
+
### Antigravity CLI
|
|
158
|
+
|
|
159
|
+
Use `new AcpClient({ runtime: 'antigravity-cli', workspaceRoot })` to start Google's `agy acp` (auto-resolved from `PATH` or `~/.local/bin/agy`, and `%LOCALAPPDATA%\antigravity\agy.exe` / `%USERPROFILE%\.local\bin\agy.exe` on Windows). If the host needs extra flags or a custom path, pass a runtime object with an explicit `command` and `args` (explicit custom runtimes are never overwritten by `resolveSpawnCommand`). Also supports `session.getQuota()` / `probeAgyQuota({ runtimeId: 'antigravity-cli' })`. The sidecar accepts the same runtime ID in `client/connect`.
|
|
160
|
+
|
|
161
|
+
For session-supplied HTTP MCP servers, include `--process-per-session` in the runtime arguments.
|
|
162
|
+
|
|
163
|
+
Call `createSession()` after `connect()` to reuse the CLI's cached sign-in. When the server requires sign-in, the SDK returns `UNAUTHORIZED`. Let the user select an advertised browser method from `init.authMethods`, call `client.authenticate(methodId)` (sidecar `client/authenticate`), and retry. For terminal login, run `agy acp --login` interactively and reconnect. Google stores the credentials through its CLI. See the [official ACP setup](https://antigravity.google/docs/ide/extensions/acp/#authentication).
|
|
164
|
+
|
|
165
|
+
The CLI sends ACP permission requests when its policy requires review. Display the agent's choices and return the exact option ID the user selected. The sidecar sends `permission/request` with `requestId`, `sessionId`, `toolCall` and `options`. Reply via `permission/respond` with `{ requestId, outcome: { outcome: 'selected', optionId } }`. Dismissing the prompt uses `{ outcome: 'cancelled' }` as its outcome. Cancellation, timeout and connection changes emit `permission/cancelled` so the host can dismiss stale prompts. SDK hosts receive an `AbortSignal` for the same purpose. See the [CLI permission settings](https://antigravity.google/docs/cli-permissions) to configure which operations require review.
|
|
166
|
+
|
|
167
|
+
Keep the `agy` runtime ID for sessions created by `@yitom/agy-acp-map` and for its resource extension. Keep session IDs paired with their runtime when saving history.
|
|
168
|
+
|
|
169
|
+
### Antigravity bridge session resources
|
|
152
170
|
|
|
153
171
|
With `@yitom/agy-acp-map` 0.1.24 / 0.1.25 / 0.1.26, `resources.directory` is delivered through the bridge session extension `_meta.appResources.directory`. Rules, native Skills and session MCP live in a private temporary additional workspace; cwd, global configuration and authentication remain unchanged. Close/delete/orderly shutdown remove the temporary workspace. Unknown bridge versions keep compatibility guidance and the app-skills MCP fallback. This extension is bridge-specific, not a standard ACP configuration-home API. `configurationScope: "session"` also supports agy; its configuration report remains conservative until the bridge accepts the session extension.
|
|
154
172
|
|
|
@@ -16,6 +16,7 @@ export interface AcpClientCallbacks {
|
|
|
16
16
|
kind?: string;
|
|
17
17
|
};
|
|
18
18
|
params: Record<string, unknown>;
|
|
19
|
+
signal: AbortSignal;
|
|
19
20
|
}) => Promise<AcpPermissionOutcome>;
|
|
20
21
|
/** 会话内容流式/状态更新通知 */
|
|
21
22
|
onSessionUpdate?: (params: Record<string, unknown>) => void;
|
|
@@ -104,6 +105,7 @@ export declare class AcpClient {
|
|
|
104
105
|
private readonly commandsCache;
|
|
105
106
|
private readonly quotaCache;
|
|
106
107
|
private runtimeInfo;
|
|
108
|
+
private readonly hasCustomRuntime;
|
|
107
109
|
private adapter;
|
|
108
110
|
private readonly workspaceRoot;
|
|
109
111
|
private readonly clientInfo;
|
|
@@ -112,6 +114,8 @@ export declare class AcpClient {
|
|
|
112
114
|
private readonly configurationScope;
|
|
113
115
|
private sessionConfig;
|
|
114
116
|
private readonly resourcesDir;
|
|
117
|
+
private authenticatingAgent?;
|
|
118
|
+
private readonly permissionRequests;
|
|
115
119
|
private readonly processScopeKey;
|
|
116
120
|
private readonly callbacks;
|
|
117
121
|
private readonly terminals;
|
|
@@ -146,6 +150,8 @@ export declare class AcpClient {
|
|
|
146
150
|
/** 获取底层当前 Agent 的 RPC 客户端句柄 */
|
|
147
151
|
get agent(): import("@agentclientprotocol/sdk").ClientContext | null;
|
|
148
152
|
get initializeResponse(): InitializeResponse | null;
|
|
153
|
+
/** Authenticate explicitly using a method advertised by the connected agent. */
|
|
154
|
+
authenticate(methodId: string): Promise<Result<void, AppError>>;
|
|
149
155
|
/**
|
|
150
156
|
* 启动并连接 Agent:
|
|
151
157
|
* 1. 预检判停(如缺少 API Key、未安装 CLI);
|
|
@@ -198,5 +204,6 @@ export declare class AcpClient {
|
|
|
198
204
|
setSessionConfigOption(sessionId: string, configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
|
|
199
205
|
/** 断开连接并清理资源 */
|
|
200
206
|
disconnect(reason?: string): Promise<void>;
|
|
207
|
+
private cancelPermissionRequests;
|
|
201
208
|
private setStatus;
|
|
202
209
|
}
|
|
@@ -13,6 +13,7 @@ export interface AcpClientHandlerDeps {
|
|
|
13
13
|
onPermission: (payload: {
|
|
14
14
|
sessionId?: string;
|
|
15
15
|
params: Record<string, unknown>;
|
|
16
|
+
signal: AbortSignal;
|
|
16
17
|
}) => Promise<AcpPermissionOutcome>;
|
|
17
18
|
/** session/update 通知透传(回放压制由调用方做) */
|
|
18
19
|
onSessionUpdate: (params: Record<string, unknown>) => void;
|
|
@@ -23,5 +24,7 @@ export interface AcpClientHandlerDeps {
|
|
|
23
24
|
* 无需手写 transport.respond/respondError。
|
|
24
25
|
*/
|
|
25
26
|
export declare function registerAcpClientHandlers(app: ClientApp, deps: AcpClientHandlerDeps): void;
|
|
26
|
-
/**
|
|
27
|
+
/** Accept cancellation or a selection explicitly advertised for this request. */
|
|
28
|
+
export declare function isAcpPermissionOutcome(outcome: unknown, params: Record<string, unknown>): outcome is AcpPermissionOutcome;
|
|
29
|
+
/** Find an allow option after user approval, preferring a one-time grant. */
|
|
27
30
|
export declare function pickAllowOptionId(params: Record<string, unknown>): string | null;
|