@yitom/acp-client 0.1.13 → 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 CHANGED
@@ -19,18 +19,20 @@
19
19
 
20
20
  ## ⚡ 核心特性
21
21
 
22
- - **多 Agent 统一适配(8 大主流运行时)**:
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
  - **生命周期全托管**:
27
27
  负责跨平台后台进程拉起(Windows PID 级联杀进程)、Stdio ndJson 传输桥接、协议初始化(Initialize 握手)、温进程池长驻复用、错误诊断(stderr 尾部日志聚合)。
28
28
  - **会话状态机与容错**:
29
- 自动处理 `resume` → `load` → `new` 会话恢复流程,处理模型方言(models 数组/对象)、无 MCP 自动降级与网络抖动重试。
29
+ 自动处理 `resume` → `load` → `new` 会话恢复流程,处理模型方言(models 数组/对象)、默认保留 MCP 配置重试;提供健康监测后,在下一轮 prompt 前恢复失效的工具挂载。
30
30
  - **解耦的事件钩子与审批**:
31
31
  工具调用审批、权限请求、会话流式更新采用标准的回调与事件驱动,宿主自由决定如何确认(命令行交互 / 桌面弹窗 / Web 消息)。
32
32
  - **应用资源目录(单目录接口)**:
33
33
  宿主只传 `resources: { directory }`(`AGENTS.md` + `skills/<name>/SKILL.md`),SDK 负责读取、摘要、配置合并、资格/版本门、会话级记录与温复用标签;详见 `docs/api-reference.md §5` 与 `examples/app-resources-demo.ts`。
34
+ - **会话级 Code Mode(PTC)**:
35
+ Agent 在 `initialize` 声明 `agentCapabilities._meta.toolsMode.values` 后,`createSession({ codeMode: 'on' })` 会通过 `_meta.toolsMode = 'ptc'` 请求该表现层;模型改为写代码、以 `tools.<name>()` 调用全部可见工具(含本次会话挂载的 MCP 工具)。未声明的 Agent 不会被请求,也不会出现“开关无效”的假支持。详见 `docs/api-reference.md §1`。
34
36
 
35
37
  ---
36
38
 
@@ -41,31 +43,13 @@
41
43
  | `codex-acp` | ChatGPT | `~/.codex/auth.json` / 自定义供应商 API Key | 支持隔离 `CODEX_HOME` 生成 `config.toml` |
42
44
  | `claude` | Claude | `~/.claude.json` / `ANTHROPIC_API_KEY` | 自动复用本机 Claude Code CLI 登录态 |
43
45
  | `cursor-cli` | Cursor | `CURSOR_API_KEY` / 系统 Keychain 登录态 | 自动探测 `%LOCALAPPDATA%\cursor-agent\agent.cmd` |
44
- | `deepseek` | DeepSeek | `DEEPSEEK_API_KEY` 或 `~/.dsh/.credentials.yaml` | 缺凭证提前判停;`DSH_BIN` 指向稳定安装,`DSH_PACKAGE` pin 版本 |
46
+ | `deepseek` | DeepSeek | `DEEPSEEK_API_KEY` | 缺 key 提前拦截判停,避免子进程秒退 |
45
47
  | `gemini` | Gemini | `~/.gemini/oauth_creds.json` / `GEMINI_API_KEY` | 自动探测 OAuth 凭证与系统 Key |
46
48
  | `copilot` | Copilot | `~/.copilot/config.json` / `GH_TOKEN` | 自动提取 `loggedInUsers` 凭证列表 |
47
49
  | `opencode` | OpenCode | `$XDG_DATA_HOME/opencode/auth.json` | 遵循 XDG / `%LOCALAPPDATA%` 规范 |
48
- | `agy` | agy | 官方桥接器免密直连 | `tryDirectSessionFirst` 免鉴权直通 |
49
-
50
- ### DeepSeek(dsh)在新机器上接入
51
-
52
- 不需要改任何本机 profile,三步即可复现:
53
-
54
- ```bash
55
- node scripts/setup-dsh-acp.mjs # 装/复用用户级运行时并自检 ACP 握手
56
- export DEEPSEEK_API_KEY=sk-... # 或在 dsh/桌面版里登录(二选一)
57
- ```
58
-
59
- 如果用户本机根本没装/没登录 harness,宿主可以直接用内置的「URL + Token」表单,免环境变量:
60
-
61
- ```typescript
62
- import { saveDeepseekProvider, getDeepseekProviderStatus } from '@yitom/acp-client'
63
-
64
- getDeepseekProviderStatus() // { configured, baseUrl?, isOfficial, hasApiKey }
65
- saveDeepseekProvider({ baseUrl: 'https://api.deepseek.com', apiKey: 'sk-...' }) // URL 留空即官方端点
66
- ```
67
-
68
- SDK 会按 `DSH_BIN` → 用户级稳定安装(自动取已装最高版本)→ `DSH_PACKAGE` → `bunx` 的顺序解析启动目标,并在 spawn 时附加 `--patch` 覆盖层把会话模型修正为 `deepseek-flash`(= DeepSeek-V4.1-Flash;桌面端的 `1017` 只是 UI 徽标)。详见 [API 参考 §DeepSeek](./docs/api-reference.md)。
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 与扩展 |
69
53
 
70
54
  ---
71
55
 
@@ -88,11 +72,9 @@ const client = new AcpClient({
88
72
  },
89
73
  onPermissionRequest: async ({ toolCall, params }) => {
90
74
  console.log(`Agent 请求调用工具:`, toolCall)
91
- // 交互式批准(y)或自动放行:协议层只有 selected/cancelled,
92
- // 允许项用 pickAllowOptionId 从 Agent 给的 options 里挑(无 'approved')。
93
- return pickAllowOptionId(params)
94
- ? { outcome: 'selected' as const, optionId: pickAllowOptionId(params)! }
95
- : { outcome: 'cancelled' as const }
75
+ console.log('审批选项', params.options)
76
+ // 交互宿主展示选项,并返回用户选择的 optionId。
77
+ return { outcome: 'cancelled' as const }
96
78
  },
97
79
  onSessionUpdate: (event) => {
98
80
  console.log(`[Stream Event]:`, event)
@@ -110,7 +92,7 @@ if (!connectResult.ok) {
110
92
  // 3. 创建/恢复会话
111
93
  const sessionResult = await client.createSession()
112
94
  if (sessionResult.ok) {
113
- const session = sessionResult.data
95
+ const session = sessionResult.value
114
96
  // 4. 发送提示词 / 消息交互
115
97
  await session.prompt('请帮我分析当前项目目录结构')
116
98
  }
@@ -140,7 +122,7 @@ Sidecar:`session/open` 结果带 `availableCommands`(若已收到),并
140
122
  在本包根目录一键构建生成 `dist`(ESM / CJS / `.d.ts`):
141
123
 
142
124
  ```bash
143
- bun run build:acp
125
+ bun run build
144
126
  ```
145
127
 
146
128
  产物说明:
@@ -155,7 +137,7 @@ bun run build:acp
155
137
  我们在 [`examples/standalone-acp-demo.ts`](./examples/standalone-acp-demo.ts) 提供了可在终端直接运行的验证脚本:
156
138
 
157
139
  ```bash
158
- bun run packages/acp/examples/standalone-acp-demo.ts
140
+ bun run examples/standalone-acp-demo.ts
159
141
  ```
160
142
 
161
143
  资源接口当前为未发布试点:规则准备与会话应用分开记录;已有磁盘配置保守回退;skillsFound 仅 SDK 文件扫描,尚无原生技能挂载或通用兼容提示词注入。详见 docs/api-reference.md 第 5 节。
@@ -166,32 +148,43 @@ bun run packages/acp/examples/standalone-acp-demo.ts
166
148
 
167
149
  会话专属配置环境:`resources: { directory, configurationScope: 'session' }`。仅替换子进程原生配置根,生成规则/纯文档技能、断开清理;不复制用户认证。支持范围、Cursor 规则边界及 agy/DeepSeek 的明确拒绝见 `docs/api-reference.md`。实现与测试:`src/resources/session-config.ts` / `session-config.test.ts`。
168
150
 
169
- ### Antigravity session resources
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
170
170
 
171
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.
172
172
 
173
173
  Normal disconnect closes owned sessions on agents advertising `sessionCapabilities.close` before terminating the transport/process. Requests are bounded to two seconds; failures are logged and teardown continues. This permits session resource cleanup on Windows as well.
174
174
 
175
- ### OpenCode ACP question compatibility
176
-
177
- When a host supplies application resources, OpenCode 1.18.35 and 2.0.6 receive a child-process-only
178
- OPENCODE_CONFIG_CONTENT overlay setting permission.question to deny. Its upstream ACP event
179
- dispatcher omits native questions in 1.18.35 and cancels form.created in 2.0.6.
180
- The v2 adapter prepares only the question overlay; native rules and skills remain unverified. The SDK preserves existing providers,
181
- models, MCP servers, instructions and all unrelated permission rules, including shorthand
182
- permission defaults. It never edits project/global OpenCode config files or authentication homes.
183
- Overlay and isolated session configuration use the same policy.
175
+ ## MCP 长会话恢复
184
176
 
185
- Inspect resourceReport.openCodeQuestions: fallback + prepared means the overlay was prepared,
186
- not proof that the runtime applied it. Unknown releases report unverified + unchanged; no semver
187
- range or permission capability is treated as proof of question support. Hosts should provide
188
- an available MCP question tool or a textual question, wait for the user, and keep security
189
- approval separate. Standard ACP request_permission remains independent; elicitation support
190
- is negotiated separately and is not implied by permissions or this fallback.
177
+ SDK 导出 `McpConnectionHealth`(传输/发现观测)与 `AcpMcpSessionRecovery`(通用恢复管理器),不依赖 Electron、窗口、管道或应用名称。
178
+ 宿主把 MCP 工具发现和连接关闭通知给监测器,并通过 `createSession({ mcpServers, mcpHealth })` 绑定;随后 `AcpClient.promptSession()` / 会话 `prompt()` 会在已知断连后先恢复原会话、重新下发相同 MCP 配置并等待新的工具发现,再发送本轮消息。
179
+ 失败阻止发送;不创建替代会话,不重发 prompt。取消、断连、恢复互斥、RPC 与发现超时统一由 SDK 处理。详见 [API 参考:MCP 恢复](./docs/api-reference.md#mcp-长会话恢复)。
180
+ 没有监测信号时不凭空推断 MCP 可用性,也不以恢复 RPC 成功冒充工具可用;工具发现仍不等同于模型目录/工具执行验证。
181
+ 此能力属于客户端兜底,不能修复 Agent 自身工作区服务回收后的内部状态。
191
182
 
192
- GitHub Actions builds and smoke-checks Linux, Windows and macOS packages and uploads a dist
193
- artifact per OS. Only version-tag pushes publish to npm; branch/PR builds do not publish.
183
+ ## 测试入口
194
184
 
195
- ### 宿主接入的通用生命周期
185
+ 本项目统一使用 Vitest。Bun 用于安装依赖及启动 package.json 脚本;直接执行 bun test 会启动 Bun 内置测试器,不是项目测试入口。
196
186
 
197
- `src/client/sdk-client.ts` 统一官方 SDK 流桥接、请求超时与方法类型推导;`connectSdkClient` 可传第四参 `{ name }`。`src/client/session-open.ts` 统一恢复/新建、原生扩展回退与有界工具输出恢复。`preserveMcpOnRetry: true` 保留重试时的 MCP 工具;缺省保持旧客户端的裸调回退策略。窗口、IPC、诊断日志由宿主提供,不进入协议包。
187
+ ```bash
188
+ bun run test # 全量 Vitest
189
+ bun run test:mcp # 仅 MCP 恢复与客户端接入测试
190
+ ```
@@ -1,6 +1,8 @@
1
+ import type { AcpMcpHealthMonitor } from '../mcp/connection-health';
1
2
  import { type AcpAvailableCommand } from '../session/available-commands';
3
+ import { type AcpCodeMode } from '../session/code-mode';
2
4
  import type { AcpAgentQuota } from '../contracts';
3
- import { type InitializeResponse, type McpServer } from '@agentclientprotocol/sdk';
5
+ import { type InitializeResponse } from '@agentclientprotocol/sdk';
4
6
  import type { AcpConnectionStatus, AcpPermissionOutcome, AcpProxySettings, AcpRuntimeInfo, AcpSessionRestoreMethod, AppError, InkdownVirtualResource } from "../contracts";
5
7
  import { type Result } from "../contracts";
6
8
  import type { AppResourceReport } from '../resources/app-resources';
@@ -14,6 +16,7 @@ export interface AcpClientCallbacks {
14
16
  kind?: string;
15
17
  };
16
18
  params: Record<string, unknown>;
19
+ signal: AbortSignal;
17
20
  }) => Promise<AcpPermissionOutcome>;
18
21
  /** 会话内容流式/状态更新通知 */
19
22
  onSessionUpdate?: (params: Record<string, unknown>) => void;
@@ -83,6 +86,8 @@ export declare class AcpSessionHandle {
83
86
  /** 主动获取/刷新配额(优先缓存,过期或无缓存时触发适配器探针) */
84
87
  getQuota(): Promise<AcpAgentQuota | null>;
85
88
  get availableCommands(): AcpAvailableCommand[] | undefined;
89
+ /** Cancel an in-flight prompt or MCP recovery. */
90
+ cancel(): Promise<Result<void, AppError>>;
86
91
  /** 修改会话配置项(如模型 ID、模式等) */
87
92
  setConfigOption(configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
88
93
  }
@@ -94,10 +99,13 @@ export declare class AcpSessionHandle {
94
99
  * - 可在任意 Node.js 项目、CLI 命令行工具或 Web 服务中直接复用。
95
100
  */
96
101
  export declare class AcpClient {
102
+ private readonly mcpRecovery;
103
+ private suppressRecoveryUpdates;
97
104
  private status;
98
105
  private readonly commandsCache;
99
106
  private readonly quotaCache;
100
107
  private runtimeInfo;
108
+ private readonly hasCustomRuntime;
101
109
  private adapter;
102
110
  private readonly workspaceRoot;
103
111
  private readonly clientInfo;
@@ -106,6 +114,8 @@ export declare class AcpClient {
106
114
  private readonly configurationScope;
107
115
  private sessionConfig;
108
116
  private readonly resourcesDir;
117
+ private authenticatingAgent?;
118
+ private readonly permissionRequests;
109
119
  private readonly processScopeKey;
110
120
  private readonly callbacks;
111
121
  private readonly terminals;
@@ -140,6 +150,8 @@ export declare class AcpClient {
140
150
  /** 获取底层当前 Agent 的 RPC 客户端句柄 */
141
151
  get agent(): import("@agentclientprotocol/sdk").ClientContext | null;
142
152
  get initializeResponse(): InitializeResponse | null;
153
+ /** Authenticate explicitly using a method advertised by the connected agent. */
154
+ authenticate(methodId: string): Promise<Result<void, AppError>>;
143
155
  /**
144
156
  * 启动并连接 Agent:
145
157
  * 1. 预检判停(如缺少 API Key、未安装 CLI);
@@ -161,7 +173,14 @@ export declare class AcpClient {
161
173
  /** 创建或恢复会话 */
162
174
  createSession(options?: {
163
175
  resumeSessionId?: string | null;
164
- mcpServers?: McpServer[];
176
+ mcpServers?: unknown[];
177
+ /** Host MCP discovery/close observations enable automatic recovery before prompts. */
178
+ mcpHealth?: AcpMcpHealthMonitor;
179
+ /**
180
+ * 会话级 code mode(PTC):模型改为写代码、以 `tools.<name>()` 调用全部可见工具,
181
+ * 包括本次会话挂载的 MCP 工具。仅对声明支持的运行时生效(见 supportsCodeMode)。
182
+ */
183
+ codeMode?: AcpCodeMode;
165
184
  }): Promise<Result<AcpSessionHandle, AppError>>;
166
185
  /** 向指定会话发送消息 */
167
186
  promptSession(sessionId: string, promptText: string, options?: {
@@ -179,9 +198,12 @@ export declare class AcpClient {
179
198
  * 恢复会话因送达状态未知,按新代次重新附带一次(有界、可诊断,不声称 exactly-once)。
180
199
  */
181
200
  private buildCompatPrepend;
201
+ /** Cancel recovery before notifying the agent; prompts are never automatically replayed. */
202
+ cancelSession(sessionId: string): Promise<Result<void, AppError>>;
182
203
  /** 动态更新会话配置项(如模型 ID) */
183
204
  setSessionConfigOption(sessionId: string, configId: string, value: string | boolean): Promise<Result<unknown, AppError>>;
184
205
  /** 断开连接并清理资源 */
185
206
  disconnect(reason?: string): Promise<void>;
207
+ private cancelPermissionRequests;
186
208
  private setStatus;
187
209
  }
@@ -1,5 +1,5 @@
1
1
  import { type AcpPermissionOutcome, type InkdownVirtualResource } from "../contracts";
2
- import { type ClientApp, type RequestPermissionRequest, type SessionNotification } from '@agentclientprotocol/sdk';
2
+ import { type ClientApp } from '@agentclientprotocol/sdk';
3
3
  import type { AcpTerminalManager } from './acp-terminal';
4
4
  export interface AcpClientHandlerDeps {
5
5
  getWorkspaceRoot: () => string | null;
@@ -12,10 +12,11 @@ export interface AcpClientHandlerDeps {
12
12
  */
13
13
  onPermission: (payload: {
14
14
  sessionId?: string;
15
- params: RequestPermissionRequest;
15
+ params: Record<string, unknown>;
16
+ signal: AbortSignal;
16
17
  }) => Promise<AcpPermissionOutcome>;
17
18
  /** session/update 通知透传(回放压制由调用方做) */
18
- onSessionUpdate: (params: SessionNotification) => void;
19
+ onSessionUpdate: (params: Record<string, unknown>) => void;
19
20
  }
20
21
  /**
21
22
  * Agent → Client 回调:permission + fs + terminal(声明能力后才会收到)。
@@ -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
- /** 从 permission options 中挑一个「允许」类 optionId,否则 cancelled */
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;
@@ -0,0 +1,47 @@
1
+ import type { AcpMcpHealthMonitor } from '../mcp/connection-health';
2
+ export declare class AcpMcpRecoveryCancelledError extends Error {
3
+ }
4
+ export interface AcpMcpRecoveryEvent {
5
+ type: 'started' | 'failed' | 'discovered' | 'cancelled';
6
+ sessionId: string;
7
+ method?: string;
8
+ }
9
+ export interface AcpMcpRecoveryOptions {
10
+ request: AcpMcpRecoveryRequest;
11
+ getCapabilities: () => {
12
+ resume: boolean;
13
+ load: boolean;
14
+ };
15
+ isConnected: () => boolean;
16
+ isBusy?: (sessionId: string) => boolean;
17
+ onSuppressUpdates?: (suppress: boolean) => void;
18
+ onEvent?: (event: AcpMcpRecoveryEvent) => void;
19
+ discoveryTimeoutMs?: number;
20
+ requestTimeoutMs?: number;
21
+ }
22
+ export type AcpMcpRecoveryRequest = (method: string, params: unknown, signal?: AbortSignal) => Promise<unknown>;
23
+ export interface AcpMcpSessionBinding {
24
+ sessionId: string;
25
+ cwd: string;
26
+ mcpServers: unknown[];
27
+ sessionMeta?: Record<string, unknown>;
28
+ monitor: AcpMcpHealthMonitor;
29
+ }
30
+ /** One manager per ACP connection owner. Does not own MCP transports or send prompts. */
31
+ export declare class AcpMcpSessionRecovery {
32
+ private readonly options;
33
+ private readonly sessions;
34
+ private generation;
35
+ private suppressing;
36
+ private active?;
37
+ constructor(options: AcpMcpRecoveryOptions);
38
+ get isRecovering(): boolean;
39
+ register(input: AcpMcpSessionBinding): void;
40
+ cancel(sessionId?: string): void;
41
+ reset(): void;
42
+ ensureReady(sessionId: string): Promise<void>;
43
+ private emit;
44
+ private recover;
45
+ private boundedRequest;
46
+ private bounded;
47
+ }
@@ -1,5 +1,5 @@
1
1
  import type { ChildProcessWithoutNullStreams } from 'node:child_process';
2
- import { type ClientApp, type ClientConnection, type ClientContext, type AgentRequestMethod, type AgentRequestParamsByMethod, type AgentRequestResponsesByMethod, type Stream } from '@agentclientprotocol/sdk';
2
+ import { type ClientApp, type ClientConnection, type ClientContext, type Stream } from '@agentclientprotocol/sdk';
3
3
  /** SDK 请求超时:沿用旧手搓传输的 120s,显式透传 */
4
4
  export declare const ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
5
5
  export interface SdkStreamHandle {
@@ -23,16 +23,12 @@ export declare function createSdkStreamHandle(child: ChildProcessWithoutNullStre
23
23
  */
24
24
  export declare function connectSdkClient(child: ChildProcessWithoutNullStreams, configure: (app: ClientApp) => void,
25
25
  /** 所属运行时 id:仅日志/隔离用,不改变 SDK 建连形态;缺省向后兼容单 codex 路径 */
26
- runtimeId?: string, options?: {
27
- name?: string;
28
- }): {
26
+ runtimeId?: string): {
29
27
  app: ClientApp;
30
28
  connection: ClientConnection;
31
29
  streamHandle: SdkStreamHandle;
32
30
  };
33
31
  /** 带显式超时的 agent.request:超时 abort(触发 $/cancel_request)并拒绝 */
34
- export declare function sdkRequest<Method extends AgentRequestMethod>(agent: ClientContext, method: Method, params: AgentRequestParamsByMethod[Method], timeoutMs?: number): Promise<AgentRequestResponsesByMethod[Method]>;
35
- /** Explicit generic overload for vendor extensions and legacy callers. */
36
32
  export declare function sdkRequest<Response, Params>(agent: ClientContext, method: string, params: Params, timeoutMs?: number): Promise<Response>;
37
33
  /** Close owned sessions before transport/process teardown; unsupported failures stay bounded. */
38
34
  export declare function closeAcpSessions(agent: ClientContext, sessionIds: Iterable<string>, timeoutMs?: number): Promise<string[]>;
@@ -1,7 +1,5 @@
1
- import { type McpServer } from '@agentclientprotocol/sdk';
2
- import type { AcpSessionRestoreAttempt, AcpSessionRestoreMethod } from '../contracts';
1
+ import type { AcpSessionRestoreAttempt, AcpSessionRestoreMethod } from "../contracts";
3
2
  export type AcpRpcRequest = (method: string, params?: unknown) => Promise<unknown>;
4
- export declare function isAuthenticationRequired(message: string): boolean;
5
3
  export interface RestoreOrCreateSessionInput {
6
4
  /** SDK 调用源:(method, params) => agent.request(method, params)(超时由 sdk-client 显式透传) */
7
5
  request: AcpRpcRequest;
@@ -9,11 +7,18 @@ export interface RestoreOrCreateSessionInput {
9
7
  resumeSessionId: string | null;
10
8
  resumeSupported: boolean;
11
9
  loadSupported: boolean;
12
- /** 客户端自带的窗口 MCP stdio 配置 */
13
- mcpServers?: McpServer[];
14
- /** Keep the same tools on retry; hosts requiring reader tools should enable this. */
10
+ /** 客户端自带的 MCP server(Inkdown 工具);Agent 不支持 HTTP 传输时传空数组 */
11
+ mcpServers?: unknown[];
12
+ /** Default true: never silently remove tools after a failed session/new. */
15
13
  preserveMcpOnRetry?: boolean;
14
+ /** Runtime-specific native options; not a standard ACP system prompt field. */
16
15
  sessionMeta?: Record<string, unknown>;
16
+ /**
17
+ * Ask the runtime for its code-mode (PTC) presentation on this session.
18
+ * Callers must gate this on `supportsCodeMode(agentCapabilities, runtimeId)`;
19
+ * the helper only applies it to new|load|resume requests.
20
+ */
21
+ codeMode?: boolean;
17
22
  /** session/load 回放期间回调(主进程用来压制 UI 更新) */
18
23
  onSuppressUpdates?: (suppress: boolean) => void;
19
24
  /** 测试可设为 0 */
@@ -21,6 +26,7 @@ export interface RestoreOrCreateSessionInput {
21
26
  log?: (level: 'info' | 'warn', message: string, data?: Record<string, unknown>) => void;
22
27
  }
23
28
  export interface RestoreOrCreateSessionResult {
29
+ /** Agent accepted the supplied MCP descriptors; not proof of tool execution. */
24
30
  mcpServersAccepted: boolean;
25
31
  recoveredToolOutputs?: Array<{
26
32
  toolCallId: string;
@@ -34,6 +40,7 @@ export interface RestoreOrCreateSessionResult {
34
40
  requestedSessionId?: string;
35
41
  restoreAttempts: AcpSessionRestoreAttempt[];
36
42
  }
43
+ export declare function isAuthenticationRequired(message: string): boolean;
37
44
  /**
38
45
  * SDK 瞬时错误判定:连接层故障(关闭/中断/超时/管道)可重试 1 次;
39
46
  * 协议层拒绝(cancelled / method-not-found / invalid-params / 业务 not-found)
@@ -48,7 +55,7 @@ export declare function isTransientAcpTransportError(error: unknown): boolean;
48
55
  * resume/load 对瞬时传输错误最多再试 1 次;失败明细写入 restoreAttempts。
49
56
  */
50
57
  export declare function restoreOrCreateAcpSession(input: RestoreOrCreateSessionInput): Promise<RestoreOrCreateSessionResult>;
51
- /** Preserve MCP when a bridge rejects only its optional native resource extension. */
58
+ /** Retry rejected native extensions without changing the MCP descriptors. */
52
59
  export declare function requestSessionWithResources(request: AcpRpcRequest, method: string, params: Record<string, unknown>, sessionMeta?: Record<string, unknown>): Promise<{
53
60
  result: Record<string, unknown>;
54
61
  nativeSessionAccepted: boolean;
@@ -119,11 +119,6 @@ export interface AcpConfigOptionValue {
119
119
  value: string;
120
120
  name: string;
121
121
  description?: string;
122
- /**
123
- * 分组名(ACP 允许 select 选项嵌套 `{group, name, options}`)。
124
- * 解析时拍平为一维列表并保留分组标签,value 保持 agent 原始编码不变。
125
- */
126
- group?: string;
127
122
  }
128
123
  export interface AcpConfigOption {
129
124
  configId: string;
@@ -272,28 +267,6 @@ export interface AcpProxySettings {
272
267
  host: string;
273
268
  port: number;
274
269
  }
275
- /**
276
- * DeepSeek(dsh)自定义端点/凭证:宿主表单「URL + Token」的落库形状。
277
- * 落库后由 SDK 在 spawn 时转成 `DEEPSEEK_BASE_URL` / `DEEPSEEK_API_KEY`,
278
- * 不写 harness 自己的 `$DSH_HOME/.credentials.yaml`(留在官方位置)。
279
- */
280
- export interface AcpDeepseekProviderStatus {
281
- configured: boolean;
282
- /** 已落库的端点;未配置时不返回 */
283
- baseUrl?: string;
284
- /**
285
- * 是否使用官方默认端点(未配置或配置值等于官方地址)。
286
- * 宿主据此渲染「官方 / 自定义」二选一。
287
- */
288
- isOfficial: boolean;
289
- hasApiKey: boolean;
290
- }
291
- export interface AcpDeepseekProviderSavePayload {
292
- /** 空串/未填时回落官方端点 */
293
- baseUrl?: string;
294
- /** 空串时保留已存的 Key(只改端点不重填 Token 的常见操作) */
295
- apiKey?: string;
296
- }
297
270
  export declare const CODEX_ACP_NPM_PACKAGE: '@agentclientprotocol/codex-acp';
298
271
  export declare const CLAUDE_ACP_NPM_PACKAGE: '@agentclientprotocol/claude-agent-acp';
299
272
  export declare const DEEPSEEK_DSH_NPM_PACKAGE: '@deepseek-ai/dsh';