@yitom/acp-client 0.1.11 → 0.1.12
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 +20 -0
- package/dist/client/acp-client.d.ts +2 -2
- package/dist/client/client-handlers.d.ts +3 -3
- package/dist/client/sdk-client.d.ts +6 -2
- package/dist/client/session-open.d.ts +16 -5
- package/dist/index.cjs +106 -44
- package/dist/index.js +123 -60
- package/dist/resources/app-resources.d.ts +7 -0
- package/dist/resources/runtime-bindings.d.ts +6 -1
- package/dist/sidecar.cjs +475 -670
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -151,3 +151,23 @@ bun run packages/acp/examples/standalone-acp-demo.ts
|
|
|
151
151
|
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.
|
|
152
152
|
|
|
153
153
|
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.
|
|
154
|
+
|
|
155
|
+
### OpenCode ACP question compatibility
|
|
156
|
+
|
|
157
|
+
When a host supplies application resources, OpenCode 1.18.35 and 2.0.6 receive a child-process-only
|
|
158
|
+
OPENCODE_CONFIG_CONTENT overlay setting permission.question to deny. Its upstream ACP event
|
|
159
|
+
dispatcher omits native questions in 1.18.35 and cancels form.created in 2.0.6.
|
|
160
|
+
The v2 adapter prepares only the question overlay; native rules and skills remain unverified. The SDK preserves existing providers,
|
|
161
|
+
models, MCP servers, instructions and all unrelated permission rules, including shorthand
|
|
162
|
+
permission defaults. It never edits project/global OpenCode config files or authentication homes.
|
|
163
|
+
Overlay and isolated session configuration use the same policy.
|
|
164
|
+
|
|
165
|
+
Inspect resourceReport.openCodeQuestions: fallback + prepared means the overlay was prepared,
|
|
166
|
+
not proof that the runtime applied it. Unknown releases report unverified + unchanged; no semver
|
|
167
|
+
range or permission capability is treated as proof of question support. Hosts should provide
|
|
168
|
+
an available MCP question tool or a textual question, wait for the user, and keep security
|
|
169
|
+
approval separate. Standard ACP request_permission remains independent; elicitation support
|
|
170
|
+
is negotiated separately and is not implied by permissions or this fallback.
|
|
171
|
+
|
|
172
|
+
GitHub Actions builds and smoke-checks Linux, Windows and macOS packages and uploads a dist
|
|
173
|
+
artifact per OS. Only version-tag pushes publish to npm; branch/PR builds do not publish.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AcpAvailableCommand } from '../session/available-commands';
|
|
2
2
|
import type { AcpAgentQuota } from '../contracts';
|
|
3
|
-
import { type InitializeResponse } from '@agentclientprotocol/sdk';
|
|
3
|
+
import { type InitializeResponse, type McpServer } from '@agentclientprotocol/sdk';
|
|
4
4
|
import type { AcpConnectionStatus, AcpPermissionOutcome, AcpProxySettings, AcpRuntimeInfo, AcpSessionRestoreMethod, AppError, InkdownVirtualResource } from "../contracts";
|
|
5
5
|
import { type Result } from "../contracts";
|
|
6
6
|
import type { AppResourceReport } from '../resources/app-resources';
|
|
@@ -161,7 +161,7 @@ export declare class AcpClient {
|
|
|
161
161
|
/** 创建或恢复会话 */
|
|
162
162
|
createSession(options?: {
|
|
163
163
|
resumeSessionId?: string | null;
|
|
164
|
-
mcpServers?:
|
|
164
|
+
mcpServers?: McpServer[];
|
|
165
165
|
}): Promise<Result<AcpSessionHandle, AppError>>;
|
|
166
166
|
/** 向指定会话发送消息 */
|
|
167
167
|
promptSession(sessionId: string, promptText: string, options?: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AcpPermissionOutcome, type InkdownVirtualResource } from "../contracts";
|
|
2
|
-
import { type ClientApp } from '@agentclientprotocol/sdk';
|
|
2
|
+
import { type ClientApp, type RequestPermissionRequest, type SessionNotification } from '@agentclientprotocol/sdk';
|
|
3
3
|
import type { AcpTerminalManager } from './acp-terminal';
|
|
4
4
|
export interface AcpClientHandlerDeps {
|
|
5
5
|
getWorkspaceRoot: () => string | null;
|
|
@@ -12,10 +12,10 @@ export interface AcpClientHandlerDeps {
|
|
|
12
12
|
*/
|
|
13
13
|
onPermission: (payload: {
|
|
14
14
|
sessionId?: string;
|
|
15
|
-
params:
|
|
15
|
+
params: RequestPermissionRequest;
|
|
16
16
|
}) => Promise<AcpPermissionOutcome>;
|
|
17
17
|
/** session/update 通知透传(回放压制由调用方做) */
|
|
18
|
-
onSessionUpdate: (params:
|
|
18
|
+
onSessionUpdate: (params: SessionNotification) => void;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Agent → Client 回调:permission + fs + terminal(声明能力后才会收到)。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
-
import { type ClientApp, type ClientConnection, type ClientContext, type Stream } from '@agentclientprotocol/sdk';
|
|
2
|
+
import { type ClientApp, type ClientConnection, type ClientContext, type AgentRequestMethod, type AgentRequestParamsByMethod, type AgentRequestResponsesByMethod, 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,12 +23,16 @@ 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
|
|
26
|
+
runtimeId?: string, options?: {
|
|
27
|
+
name?: string;
|
|
28
|
+
}): {
|
|
27
29
|
app: ClientApp;
|
|
28
30
|
connection: ClientConnection;
|
|
29
31
|
streamHandle: SdkStreamHandle;
|
|
30
32
|
};
|
|
31
33
|
/** 带显式超时的 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. */
|
|
32
36
|
export declare function sdkRequest<Response, Params>(agent: ClientContext, method: string, params: Params, timeoutMs?: number): Promise<Response>;
|
|
33
37
|
/** Close owned sessions before transport/process teardown; unsupported failures stay bounded. */
|
|
34
38
|
export declare function closeAcpSessions(agent: ClientContext, sessionIds: Iterable<string>, timeoutMs?: number): Promise<string[]>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type McpServer } from '@agentclientprotocol/sdk';
|
|
2
|
+
import type { AcpSessionRestoreAttempt, AcpSessionRestoreMethod } from '../contracts';
|
|
2
3
|
export type AcpRpcRequest = (method: string, params?: unknown) => Promise<unknown>;
|
|
4
|
+
export declare function isAuthenticationRequired(message: string): boolean;
|
|
3
5
|
export interface RestoreOrCreateSessionInput {
|
|
4
6
|
/** SDK 调用源:(method, params) => agent.request(method, params)(超时由 sdk-client 显式透传) */
|
|
5
7
|
request: AcpRpcRequest;
|
|
@@ -7,9 +9,10 @@ export interface RestoreOrCreateSessionInput {
|
|
|
7
9
|
resumeSessionId: string | null;
|
|
8
10
|
resumeSupported: boolean;
|
|
9
11
|
loadSupported: boolean;
|
|
10
|
-
/**
|
|
11
|
-
mcpServers?:
|
|
12
|
-
/**
|
|
12
|
+
/** 客户端自带的窗口 MCP stdio 配置 */
|
|
13
|
+
mcpServers?: McpServer[];
|
|
14
|
+
/** Keep the same tools on retry; hosts requiring reader tools should enable this. */
|
|
15
|
+
preserveMcpOnRetry?: boolean;
|
|
13
16
|
sessionMeta?: Record<string, unknown>;
|
|
14
17
|
/** session/load 回放期间回调(主进程用来压制 UI 更新) */
|
|
15
18
|
onSuppressUpdates?: (suppress: boolean) => void;
|
|
@@ -18,8 +21,11 @@ export interface RestoreOrCreateSessionInput {
|
|
|
18
21
|
log?: (level: 'info' | 'warn', message: string, data?: Record<string, unknown>) => void;
|
|
19
22
|
}
|
|
20
23
|
export interface RestoreOrCreateSessionResult {
|
|
21
|
-
/** Agent accepted the supplied MCP descriptors; not proof of tool execution. */
|
|
22
24
|
mcpServersAccepted: boolean;
|
|
25
|
+
recoveredToolOutputs?: Array<{
|
|
26
|
+
toolCallId: string;
|
|
27
|
+
text: string;
|
|
28
|
+
}>;
|
|
23
29
|
nativeSessionAccepted: boolean;
|
|
24
30
|
sessionId: string;
|
|
25
31
|
configOptions: unknown;
|
|
@@ -42,3 +48,8 @@ export declare function isTransientAcpTransportError(error: unknown): boolean;
|
|
|
42
48
|
* resume/load 对瞬时传输错误最多再试 1 次;失败明细写入 restoreAttempts。
|
|
43
49
|
*/
|
|
44
50
|
export declare function restoreOrCreateAcpSession(input: RestoreOrCreateSessionInput): Promise<RestoreOrCreateSessionResult>;
|
|
51
|
+
/** Preserve MCP when a bridge rejects only its optional native resource extension. */
|
|
52
|
+
export declare function requestSessionWithResources(request: AcpRpcRequest, method: string, params: Record<string, unknown>, sessionMeta?: Record<string, unknown>): Promise<{
|
|
53
|
+
result: Record<string, unknown>;
|
|
54
|
+
nativeSessionAccepted: boolean;
|
|
55
|
+
}>;
|
package/dist/index.cjs
CHANGED
|
@@ -142,6 +142,7 @@ __export(exports_src, {
|
|
|
142
142
|
handleInkdownMcpRpc: () => handleInkdownMcpRpc,
|
|
143
143
|
isAbsolutePathLike: () => isAbsolutePathLike,
|
|
144
144
|
isAppError: () => isAppError,
|
|
145
|
+
isAuthenticationRequired: () => isAuthenticationRequired,
|
|
145
146
|
isBinaryDocumentPath: () => isBinaryDocumentPath,
|
|
146
147
|
isCancelled: () => isCancelled,
|
|
147
148
|
isCodexPreflightRuntime: () => isCodexPreflightRuntime,
|
|
@@ -159,6 +160,7 @@ __export(exports_src, {
|
|
|
159
160
|
mergeCodexConfigJson: () => mergeCodexConfigJson,
|
|
160
161
|
mergeConfigTomlPreserving: () => mergeConfigTomlPreserving,
|
|
161
162
|
mergeOpenCodeAppConfig: () => mergeOpenCodeAppConfig,
|
|
163
|
+
mergeOpenCodeQuestionConfig: () => mergeOpenCodeQuestionConfig,
|
|
162
164
|
mergeTopLevelModelsIntoConfigOptions: () => mergeTopLevelModelsIntoConfigOptions,
|
|
163
165
|
ok: () => ok,
|
|
164
166
|
opencodeAdapter: () => opencodeAdapter,
|
|
@@ -195,6 +197,7 @@ __export(exports_src, {
|
|
|
195
197
|
readAppRulesText: () => readAppRulesText,
|
|
196
198
|
readStoredAcpProvider: () => readStoredAcpProvider,
|
|
197
199
|
registerAcpClientHandlers: () => registerAcpClientHandlers,
|
|
200
|
+
requestSessionWithResources: () => requestSessionWithResources,
|
|
198
201
|
resolveClaudeHome: () => resolveClaudeHome,
|
|
199
202
|
resolveCodexHome: () => resolveCodexHome,
|
|
200
203
|
resolveCopilotHome: () => resolveCopilotHome,
|
|
@@ -205,6 +208,7 @@ __export(exports_src, {
|
|
|
205
208
|
resolveDeepseekSpawnBlocker: () => resolveDeepseekSpawnBlocker,
|
|
206
209
|
resolveDeepseekSpawnCommand: () => resolveDeepseekSpawnCommand,
|
|
207
210
|
resolveGeminiHome: () => resolveGeminiHome,
|
|
211
|
+
resolveOpenCodeQuestionMode: () => resolveOpenCodeQuestionMode,
|
|
208
212
|
resolveOpencodeAuthCandidates: () => resolveOpencodeAuthCandidates,
|
|
209
213
|
resolveOpencodeAuthFile: () => resolveOpencodeAuthFile,
|
|
210
214
|
resolveOpencodeAuthPath: () => resolveOpencodeAuthPath,
|
|
@@ -385,7 +389,7 @@ function findBuiltinAcpRuntime(id) {
|
|
|
385
389
|
return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
|
|
386
390
|
}
|
|
387
391
|
// src/version.ts
|
|
388
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
392
|
+
var ACP_CLIENT_VERSION = "0.1.12";
|
|
389
393
|
// src/client/sdk-client.ts
|
|
390
394
|
var import_node_stream = require("node:stream");
|
|
391
395
|
var import_sdk = require("@agentclientprotocol/sdk");
|
|
@@ -393,6 +397,8 @@ var ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
|
|
|
393
397
|
function createSdkStreamHandle(child) {
|
|
394
398
|
const stdoutBridge = new import_node_stream.PassThrough;
|
|
395
399
|
const stdinBridge = new import_node_stream.PassThrough;
|
|
400
|
+
stdoutBridge.on("error", () => {});
|
|
401
|
+
stdinBridge.on("error", () => {});
|
|
396
402
|
child.stdout.pipe(stdoutBridge);
|
|
397
403
|
stdinBridge.pipe(child.stdin, { end: false });
|
|
398
404
|
const output = import_node_stream.Writable.toWeb(stdinBridge);
|
|
@@ -420,11 +426,11 @@ function createSdkStreamHandle(child) {
|
|
|
420
426
|
}
|
|
421
427
|
};
|
|
422
428
|
}
|
|
423
|
-
function connectSdkClient(child, configure, runtimeId) {
|
|
429
|
+
function connectSdkClient(child, configure, runtimeId, options = {}) {
|
|
424
430
|
if (runtimeId && true) {
|
|
425
431
|
console.info(`[acp:sdk] connect runtime=${runtimeId} pid=${child.pid ?? "?"}`);
|
|
426
432
|
}
|
|
427
|
-
const app = import_sdk.client({ name: "inkdown" });
|
|
433
|
+
const app = import_sdk.client({ name: options.name ?? "inkdown" });
|
|
428
434
|
configure(app);
|
|
429
435
|
const streamHandle = createSdkStreamHandle(child);
|
|
430
436
|
const connection = app.connect(streamHandle.stream);
|
|
@@ -454,7 +460,7 @@ async function closeAcpSessions(agent, sessionIds, timeoutMs = 2000) {
|
|
|
454
460
|
const failed = [];
|
|
455
461
|
await Promise.all([...new Set(sessionIds)].map(async (sessionId) => {
|
|
456
462
|
try {
|
|
457
|
-
await sdkRequest(agent,
|
|
463
|
+
await sdkRequest(agent, import_sdk.methods.agent.session.close, { sessionId }, timeoutMs);
|
|
458
464
|
} catch {
|
|
459
465
|
failed.push(sessionId);
|
|
460
466
|
}
|
|
@@ -1534,7 +1540,7 @@ var import_node_util = require("node:util");
|
|
|
1534
1540
|
var APP_RESOURCE_CAPABILITIES = {
|
|
1535
1541
|
"codex-acp": { entry: "CODEX_CONFIG", strategy: "native-overlay", configHome: "CODEX_HOME" },
|
|
1536
1542
|
opencode: { entry: "OPENCODE_CONFIG_CONTENT", strategy: "native-overlay", configHome: "OPENCODE_CONFIG_DIR" },
|
|
1537
|
-
"opencode-v2": { entry:
|
|
1543
|
+
"opencode-v2": { entry: "OPENCODE_CONFIG_CONTENT (questions only)", strategy: "compatibility", configHome: null },
|
|
1538
1544
|
claude: { entry: "_meta.systemPrompt + _meta.claudeCode.options.plugins", strategy: "native-session", configHome: "CLAUDE_CONFIG_DIR" },
|
|
1539
1545
|
gemini: { entry: null, strategy: "compatibility", configHome: "GEMINI_CLI_HOME" },
|
|
1540
1546
|
copilot: { entry: null, strategy: "compatibility", configHome: "COPILOT_HOME", candidateEntry: "COPILOT_CUSTOM_INSTRUCTIONS_DIRS" },
|
|
@@ -1572,18 +1578,49 @@ function mergeOpenCodeAppConfig(raw, directory) {
|
|
|
1572
1578
|
skills: { ...skills, paths: [...new Set([...skills.paths ?? [], import_node_path8.join(directory, "skills")])] }
|
|
1573
1579
|
});
|
|
1574
1580
|
}
|
|
1581
|
+
function resolveOpenCodeQuestionMode(version) {
|
|
1582
|
+
const normalized = version.trim().replace(/^opencode\s+v?/i, "");
|
|
1583
|
+
return ["1.18.35", "2.0.6"].includes(normalized) ? "fallback" : "unverified";
|
|
1584
|
+
}
|
|
1585
|
+
function mergeOpenCodeQuestionConfig(raw) {
|
|
1586
|
+
const value = raw?.trim() ? JSON.parse(raw) : {};
|
|
1587
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
1588
|
+
throw new Error("invalid-opencode-config");
|
|
1589
|
+
const config = value;
|
|
1590
|
+
const permission = config.permission;
|
|
1591
|
+
if (permission !== undefined && (typeof permission !== "string" || !["allow", "ask", "deny"].includes(permission)) && (!permission || typeof permission !== "object" || Array.isArray(permission)))
|
|
1592
|
+
throw new Error("invalid-opencode-permission");
|
|
1593
|
+
const rules = typeof permission === "string" ? { "*": permission } : permission ?? {};
|
|
1594
|
+
return JSON.stringify({ ...config, permission: { ...rules, question: "deny" } });
|
|
1595
|
+
}
|
|
1575
1596
|
async function prepareOpenCodeResources(input) {
|
|
1576
1597
|
const prep = prepareCompatibilityResources(input.directory, "native-entry-not-verified");
|
|
1577
|
-
|
|
1598
|
+
prep.report.openCodeQuestions = { mode: "unverified", configuration: "unchanged", reason: "version-not-verified" };
|
|
1599
|
+
if (!input.command)
|
|
1578
1600
|
return prep;
|
|
1579
1601
|
try {
|
|
1580
1602
|
const { stdout } = await import_node_util.promisify(import_node_child_process2.execFile)(input.command, ["--version"], { env: input.env, timeout: 8000, windowsHide: true });
|
|
1581
|
-
|
|
1603
|
+
const version = stdout.trim().replace(/^opencode\s+v?/i, "");
|
|
1604
|
+
if (resolveOpenCodeQuestionMode(version) !== "fallback") {
|
|
1605
|
+
prep.report.openCodeQuestions.version = version;
|
|
1582
1606
|
return prep;
|
|
1583
|
-
|
|
1584
|
-
|
|
1607
|
+
}
|
|
1608
|
+
let json = mergeOpenCodeQuestionConfig(input.env?.OPENCODE_CONFIG_CONTENT);
|
|
1609
|
+
const hasRules = version === "1.18.35" && !!readAppRulesText(input.directory);
|
|
1610
|
+
if (hasRules)
|
|
1611
|
+
json = mergeOpenCodeAppConfig(json, input.directory);
|
|
1612
|
+
return { env: { OPENCODE_CONFIG_CONTENT: json }, report: {
|
|
1613
|
+
...prep.report,
|
|
1614
|
+
rulesPrepared: hasRules,
|
|
1615
|
+
reason: hasRules ? undefined : version === "2.0.6" ? "native-entry-not-verified" : "missing-app-rules",
|
|
1616
|
+
openCodeQuestions: { version, mode: "fallback", configuration: "prepared", reason: "acp-question-not-forwarded" }
|
|
1617
|
+
} };
|
|
1585
1618
|
} catch {
|
|
1586
|
-
return { ...prep, report: {
|
|
1619
|
+
return { ...prep, report: {
|
|
1620
|
+
...prep.report,
|
|
1621
|
+
reason: "native-config-prepare-failed",
|
|
1622
|
+
openCodeQuestions: { mode: "unverified", configuration: "unchanged", reason: "prepare-failed" }
|
|
1623
|
+
} };
|
|
1587
1624
|
}
|
|
1588
1625
|
}
|
|
1589
1626
|
function prepareClaudeResources(directory) {
|
|
@@ -2179,7 +2216,7 @@ var opencodeAdapter = {
|
|
|
2179
2216
|
// src/runtimes/opencode-v2/index.ts
|
|
2180
2217
|
var opencodeV2Adapter = {
|
|
2181
2218
|
id: "opencode-v2",
|
|
2182
|
-
prepareAppResources:
|
|
2219
|
+
prepareAppResources: prepareOpenCodeResources,
|
|
2183
2220
|
probeAuth: () => probeOpencodeAuth(),
|
|
2184
2221
|
orderAuthMethods: (methods) => methods,
|
|
2185
2222
|
canSkipInteractiveAuth: () => false,
|
|
@@ -3457,6 +3494,9 @@ function mergeTopLevelModelsIntoConfigOptions(configOptionsRaw, response) {
|
|
|
3457
3494
|
}
|
|
3458
3495
|
|
|
3459
3496
|
// src/client/session-open.ts
|
|
3497
|
+
function isAuthenticationRequired(message) {
|
|
3498
|
+
return !/\bmcp\b/i.test(message) && /authentication required|not authenticated|please (?:log|sign) in|需要认证|尚未认证/i.test(message);
|
|
3499
|
+
}
|
|
3460
3500
|
function errorMessage(error) {
|
|
3461
3501
|
return error instanceof Error ? error.message : String(error);
|
|
3462
3502
|
}
|
|
@@ -3476,29 +3516,30 @@ function isTransientAcpTransportError(error) {
|
|
|
3476
3516
|
return /ACP connection closed|connection closed|closed|abort|超时|timeout|timed out|econnreset|epipe|stdio|stream/i.test(message);
|
|
3477
3517
|
}
|
|
3478
3518
|
async function restoreOrCreateAcpSession(input) {
|
|
3479
|
-
const resumeId = input.resumeSessionId?.trim() || null;
|
|
3480
|
-
const restoreAttempts = [];
|
|
3481
3519
|
let mcpServersAccepted = (input.mcpServers ?? []).length > 0;
|
|
3482
3520
|
let nativeSessionAccepted = false;
|
|
3521
|
+
let recoveredToolOutputs;
|
|
3483
3522
|
const request = async (method, params) => {
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3523
|
+
const opened = await requestSessionWithResources(input.request, method, params, input.sessionMeta);
|
|
3524
|
+
nativeSessionAccepted = opened.nativeSessionAccepted;
|
|
3525
|
+
const meta = opened.result._meta;
|
|
3526
|
+
const outputs = meta?.toolOutputRecovery?.outputs;
|
|
3527
|
+
let total = 0;
|
|
3528
|
+
recoveredToolOutputs = Array.isArray(outputs) ? outputs.slice(0, 20).filter((row) => {
|
|
3529
|
+
if (!row || typeof row.toolCallId !== "string" || row.toolCallId.length > 120 || typeof row.text !== "string")
|
|
3530
|
+
return false;
|
|
3531
|
+
const bytes = Buffer.byteLength(row.text);
|
|
3532
|
+
if (bytes > 128 * 1024 || total + bytes > 256 * 1024)
|
|
3533
|
+
return false;
|
|
3534
|
+
total += bytes;
|
|
3535
|
+
return true;
|
|
3536
|
+
}) : undefined;
|
|
3537
|
+
return opened.result;
|
|
3499
3538
|
};
|
|
3539
|
+
const resumeId = input.resumeSessionId?.trim() || null;
|
|
3540
|
+
const restoreAttempts = [];
|
|
3500
3541
|
const delayMs = input.retryDelayMs ?? 250;
|
|
3501
|
-
const
|
|
3542
|
+
const outputLog = input.log ?? ((level, message, data) => {
|
|
3502
3543
|
if (level === "info" && false)
|
|
3503
3544
|
;
|
|
3504
3545
|
const line = `[acp] ${message}`;
|
|
@@ -3507,6 +3548,7 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3507
3548
|
else
|
|
3508
3549
|
console.info(line, data ?? "");
|
|
3509
3550
|
});
|
|
3551
|
+
const log = outputLog;
|
|
3510
3552
|
const tryRestoreMethod = async (method, rpcMethod) => {
|
|
3511
3553
|
const maxTries = 2;
|
|
3512
3554
|
let lastError = "";
|
|
@@ -3557,19 +3599,17 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3557
3599
|
mcpServers: input.mcpServers ?? []
|
|
3558
3600
|
};
|
|
3559
3601
|
try {
|
|
3560
|
-
return await request(
|
|
3602
|
+
return await request(import_sdk3.methods.agent.session.new, baseParams);
|
|
3561
3603
|
} catch (firstError) {
|
|
3562
3604
|
if ((input.mcpServers ?? []).length === 0)
|
|
3563
3605
|
throw firstError;
|
|
3564
|
-
log("warn", "session/new failed, retry without mcpServers", {
|
|
3606
|
+
log("warn", input.preserveMcpOnRetry ? "session/new failed, retry with mcpServers" : "session/new failed, retry without mcpServers", {
|
|
3565
3607
|
error: errorMessage(firstError)
|
|
3566
3608
|
});
|
|
3567
3609
|
try {
|
|
3568
|
-
const
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
});
|
|
3572
|
-
mcpServersAccepted = false;
|
|
3610
|
+
const retryServers = input.preserveMcpOnRetry ? input.mcpServers ?? [] : [];
|
|
3611
|
+
const result = await request(import_sdk3.methods.agent.session.new, { cwd: input.cwd, mcpServers: retryServers });
|
|
3612
|
+
mcpServersAccepted = retryServers.length > 0;
|
|
3573
3613
|
return result;
|
|
3574
3614
|
} catch {
|
|
3575
3615
|
throw firstError;
|
|
@@ -3578,16 +3618,17 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3578
3618
|
};
|
|
3579
3619
|
const withModelsFallback = (result) => mergeTopLevelModelsIntoConfigOptions(result.configOptions, result);
|
|
3580
3620
|
if (resumeId && input.resumeSupported) {
|
|
3581
|
-
const resumed = await tryRestoreMethod("resume",
|
|
3621
|
+
const resumed = await tryRestoreMethod("resume", import_sdk3.methods.agent.session.resume);
|
|
3582
3622
|
if (resumed) {
|
|
3583
3623
|
const id = typeof resumed.sessionId === "string" ? resumed.sessionId : resumeId;
|
|
3584
3624
|
return {
|
|
3585
3625
|
sessionId: id,
|
|
3626
|
+
mcpServersAccepted,
|
|
3627
|
+
recoveredToolOutputs,
|
|
3628
|
+
nativeSessionAccepted,
|
|
3586
3629
|
configOptions: withModelsFallback(resumed),
|
|
3587
3630
|
restoreMethod: "resume",
|
|
3588
3631
|
sessionRestored: true,
|
|
3589
|
-
mcpServersAccepted,
|
|
3590
|
-
nativeSessionAccepted,
|
|
3591
3632
|
requestedSessionId: resumeId,
|
|
3592
3633
|
restoreAttempts
|
|
3593
3634
|
};
|
|
@@ -3598,16 +3639,17 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3598
3639
|
if (resumeId && input.loadSupported) {
|
|
3599
3640
|
input.onSuppressUpdates?.(true);
|
|
3600
3641
|
try {
|
|
3601
|
-
const loaded = await tryRestoreMethod("load",
|
|
3642
|
+
const loaded = await tryRestoreMethod("load", import_sdk3.methods.agent.session.load);
|
|
3602
3643
|
if (loaded) {
|
|
3603
3644
|
const id = typeof loaded.sessionId === "string" ? loaded.sessionId : resumeId;
|
|
3604
3645
|
return {
|
|
3605
3646
|
sessionId: id,
|
|
3647
|
+
mcpServersAccepted,
|
|
3648
|
+
recoveredToolOutputs,
|
|
3649
|
+
nativeSessionAccepted,
|
|
3606
3650
|
configOptions: withModelsFallback(loaded),
|
|
3607
3651
|
restoreMethod: "load",
|
|
3608
3652
|
sessionRestored: true,
|
|
3609
|
-
mcpServersAccepted,
|
|
3610
|
-
nativeSessionAccepted,
|
|
3611
3653
|
requestedSessionId: resumeId,
|
|
3612
3654
|
restoreAttempts
|
|
3613
3655
|
};
|
|
@@ -3626,15 +3668,27 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3626
3668
|
}
|
|
3627
3669
|
return {
|
|
3628
3670
|
sessionId: newSessionId,
|
|
3671
|
+
mcpServersAccepted,
|
|
3672
|
+
nativeSessionAccepted,
|
|
3629
3673
|
configOptions: withModelsFallback(sessionResult),
|
|
3630
3674
|
restoreMethod: "new",
|
|
3631
3675
|
sessionRestored: false,
|
|
3632
|
-
mcpServersAccepted,
|
|
3633
|
-
nativeSessionAccepted,
|
|
3634
3676
|
requestedSessionId: resumeId ?? undefined,
|
|
3635
3677
|
restoreAttempts
|
|
3636
3678
|
};
|
|
3637
3679
|
}
|
|
3680
|
+
async function requestSessionWithResources(request, method, params, sessionMeta) {
|
|
3681
|
+
if (!sessionMeta)
|
|
3682
|
+
return { result: await request(method, params), nativeSessionAccepted: false };
|
|
3683
|
+
try {
|
|
3684
|
+
return { result: await request(method, { ...params, _meta: sessionMeta }), nativeSessionAccepted: true };
|
|
3685
|
+
} catch (error) {
|
|
3686
|
+
const rejected = error instanceof import_sdk3.RequestError && error.code === -32602 || /native.*meta.*reject|unsupported.*(meta|systemPrompt)|unknown.*(meta|systemPrompt)/i.test(errorMessage(error));
|
|
3687
|
+
if (!rejected || isTransientAcpTransportError(error))
|
|
3688
|
+
throw error;
|
|
3689
|
+
return { result: await request(method, params), nativeSessionAccepted: false };
|
|
3690
|
+
}
|
|
3691
|
+
}
|
|
3638
3692
|
|
|
3639
3693
|
// src/client/acp-terminal.ts
|
|
3640
3694
|
var import_node_child_process8 = require("node:child_process");
|
|
@@ -4177,6 +4231,13 @@ class AcpClient {
|
|
|
4177
4231
|
}
|
|
4178
4232
|
this.sessionConfig = profile;
|
|
4179
4233
|
resourceEnv = this.sessionConfig.env;
|
|
4234
|
+
const interactions = ["opencode", "opencode-v2"].includes(this.runtimeInfo.id) && this.adapter.prepareAppResources ? await this.adapter.prepareAppResources({
|
|
4235
|
+
directory: this.resourcesDir,
|
|
4236
|
+
command: effectiveRuntime.command,
|
|
4237
|
+
workspaceRoot: this.workspaceRoot,
|
|
4238
|
+
env: { ...process.env, ...spawnEnv.env, ...resourceEnv }
|
|
4239
|
+
}) : undefined;
|
|
4240
|
+
Object.assign(resourceEnv, interactions?.env);
|
|
4180
4241
|
const load = readAppResourcesDir(this.resourcesDir);
|
|
4181
4242
|
this.resourcePrep = { profileTag: null, report: {
|
|
4182
4243
|
rulesApplied: false,
|
|
@@ -4185,6 +4246,7 @@ class AcpClient {
|
|
|
4185
4246
|
rulesChars: load.rules?.chars ?? 0,
|
|
4186
4247
|
profileDigest: digestAppResources(load),
|
|
4187
4248
|
skillsFound: load.skills.map((s) => s.name),
|
|
4249
|
+
openCodeQuestions: interactions?.report.openCodeQuestions,
|
|
4188
4250
|
configurationScope: "session",
|
|
4189
4251
|
configurationDirectory: this.sessionConfig.directory,
|
|
4190
4252
|
configurationRulesFile: this.sessionConfig.rulesFile,
|