@yitom/acp-client 0.1.7 → 0.1.8
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 +14 -0
- package/dist/app-skills-mcp-serve.cjs +291 -0
- package/dist/client/acp-client.d.ts +52 -1
- package/dist/client/session-open.d.ts +5 -0
- package/dist/index.cjs +1098 -189
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1080 -171
- package/dist/mcp/app-skills-mcp-serve.d.ts +1 -0
- package/dist/mcp/app-skills-mcp.d.ts +48 -0
- package/dist/process/process-manager.d.ts +51 -5
- package/dist/resources/app-resources.d.ts +91 -0
- package/dist/resources/config-text.d.ts +36 -0
- package/dist/resources/eligibility.d.ts +19 -0
- package/dist/resources/index.d.ts +5 -0
- package/dist/resources/runtime-bindings.d.ts +59 -0
- package/dist/resources/session-config.d.ts +9 -0
- package/dist/runtimes/index.d.ts +17 -0
- package/dist/session/compat-guide.d.ts +33 -0
- package/dist/sidecar.cjs +1050 -170
- package/dist/version.d.ts +1 -1
- package/docs/api-reference.md +108 -0
- package/package.json +2 -2
package/dist/sidecar.cjs
CHANGED
|
@@ -36,7 +36,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
36
36
|
var readline2 = __toESM(require("node:readline"), 1);
|
|
37
37
|
|
|
38
38
|
// src/version.ts
|
|
39
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
39
|
+
var ACP_CLIENT_VERSION = "0.1.8";
|
|
40
40
|
// src/contracts/index.ts
|
|
41
41
|
function ok(value) {
|
|
42
42
|
return { ok: true, value };
|
|
@@ -175,6 +175,243 @@ var BUILTIN_ACP_RUNTIMES = [
|
|
|
175
175
|
function findBuiltinAcpRuntime(id) {
|
|
176
176
|
return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
|
|
177
177
|
}
|
|
178
|
+
// src/resources/session-config.ts
|
|
179
|
+
var import_node_fs2 = require("node:fs");
|
|
180
|
+
var import_promises = require("node:fs/promises");
|
|
181
|
+
var import_node_os = require("node:os");
|
|
182
|
+
var import_node_path2 = require("node:path");
|
|
183
|
+
|
|
184
|
+
// src/resources/app-resources.ts
|
|
185
|
+
var import_node_crypto = require("node:crypto");
|
|
186
|
+
var import_node_fs = require("node:fs");
|
|
187
|
+
var import_node_path = require("node:path");
|
|
188
|
+
var APP_RULES_FILE = "AGENTS.md";
|
|
189
|
+
var APP_SKILLS_DIR = "skills";
|
|
190
|
+
var APP_SKILL_FILE = "SKILL.md";
|
|
191
|
+
function parseSkillFrontmatter(text) {
|
|
192
|
+
const lines = text.split(`
|
|
193
|
+
`);
|
|
194
|
+
if (lines[0]?.trim() !== "---")
|
|
195
|
+
return {};
|
|
196
|
+
const out = {};
|
|
197
|
+
for (let i = 1;i < lines.length; i += 1) {
|
|
198
|
+
const line = lines[i] ?? "";
|
|
199
|
+
if (line.trim() === "---")
|
|
200
|
+
break;
|
|
201
|
+
const cut = line.indexOf(":");
|
|
202
|
+
if (cut <= 0)
|
|
203
|
+
continue;
|
|
204
|
+
const key = line.slice(0, cut).trim().toLowerCase();
|
|
205
|
+
if (key !== "name" && key !== "description")
|
|
206
|
+
continue;
|
|
207
|
+
const value = line.slice(cut + 1).trim().replace(/^['"]|['"]$/g, "");
|
|
208
|
+
if (value)
|
|
209
|
+
out[key] = value;
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
function sha256Hex(text) {
|
|
214
|
+
return import_node_crypto.createHash("sha256").update(text, "utf8").digest("hex");
|
|
215
|
+
}
|
|
216
|
+
function readTextFile(path) {
|
|
217
|
+
try {
|
|
218
|
+
if (!import_node_fs.statSync(path).isFile())
|
|
219
|
+
return null;
|
|
220
|
+
const text = import_node_fs.readFileSync(path, "utf8");
|
|
221
|
+
return text.trim() ? text : null;
|
|
222
|
+
} catch {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function readAppResourcesDir(directory) {
|
|
227
|
+
const warnings = [];
|
|
228
|
+
if (!import_node_path.isAbsolute(directory))
|
|
229
|
+
return { directoryReadable: false, rules: null, skills: [], warnings: ["资源目录必须是本机绝对路径"] };
|
|
230
|
+
let directoryReadable = false;
|
|
231
|
+
try {
|
|
232
|
+
directoryReadable = import_node_fs.statSync(directory).isDirectory();
|
|
233
|
+
} catch {
|
|
234
|
+
directoryReadable = false;
|
|
235
|
+
}
|
|
236
|
+
if (!directoryReadable) {
|
|
237
|
+
return { directoryReadable: false, rules: null, skills: [], warnings: [`资源目录不可读: ${directory}`] };
|
|
238
|
+
}
|
|
239
|
+
let rules = null;
|
|
240
|
+
const rulesText = readTextFile(import_node_path.join(directory, APP_RULES_FILE));
|
|
241
|
+
if (rulesText === null) {
|
|
242
|
+
warnings.push(`缺常驻规则: ${APP_RULES_FILE}`);
|
|
243
|
+
} else {
|
|
244
|
+
rules = { chars: rulesText.length, digest: sha256Hex(`app-rules-v1
|
|
245
|
+
${rulesText}`) };
|
|
246
|
+
}
|
|
247
|
+
const skills = [];
|
|
248
|
+
const skillsRoot = import_node_path.join(directory, APP_SKILLS_DIR);
|
|
249
|
+
let skillNames = [];
|
|
250
|
+
try {
|
|
251
|
+
if (import_node_fs.statSync(skillsRoot).isDirectory()) {
|
|
252
|
+
skillNames = import_node_fs.readdirSync(skillsRoot).filter((name) => {
|
|
253
|
+
try {
|
|
254
|
+
return import_node_fs.statSync(import_node_path.join(skillsRoot, name)).isDirectory();
|
|
255
|
+
} catch {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
} catch {
|
|
261
|
+
skillNames = [];
|
|
262
|
+
}
|
|
263
|
+
for (const name of skillNames.sort()) {
|
|
264
|
+
const rel = `${APP_SKILLS_DIR}/${name}/${APP_SKILL_FILE}`;
|
|
265
|
+
const text = readTextFile(import_node_path.join(directory, rel));
|
|
266
|
+
if (text === null) {
|
|
267
|
+
warnings.push(`技能缺正文已跳过: ${rel}`);
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const front = parseSkillFrontmatter(text);
|
|
271
|
+
const skillName = front.name || name;
|
|
272
|
+
if (skills.some((s) => s.name === skillName)) {
|
|
273
|
+
warnings.push(`技能重名已跳过(保留首个): ${skillName}`);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const description = front.description || "";
|
|
277
|
+
skills.push({
|
|
278
|
+
name: skillName,
|
|
279
|
+
description,
|
|
280
|
+
path: rel,
|
|
281
|
+
chars: text.length,
|
|
282
|
+
digest: sha256Hex(`app-skill-v1
|
|
283
|
+
${skillName}
|
|
284
|
+
${description}
|
|
285
|
+
${text}`)
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return { directoryReadable: true, rules, skills, warnings };
|
|
289
|
+
}
|
|
290
|
+
function digestAppResources(load) {
|
|
291
|
+
if (!load.rules)
|
|
292
|
+
return null;
|
|
293
|
+
const skillPart = load.skills.map((s) => `${s.name}:${s.digest}`).join(`
|
|
294
|
+
`);
|
|
295
|
+
return sha256Hex(`app-resources-v1
|
|
296
|
+
${load.rules.digest}
|
|
297
|
+
${skillPart}`);
|
|
298
|
+
}
|
|
299
|
+
function readAppRulesText(directory) {
|
|
300
|
+
return readTextFile(import_node_path.join(directory, APP_RULES_FILE));
|
|
301
|
+
}
|
|
302
|
+
function isAbsolutePathLike(path) {
|
|
303
|
+
return import_node_path.isAbsolute(path);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/resources/session-config.ts
|
|
307
|
+
async function createSessionConfigHome(runtime, resources) {
|
|
308
|
+
if (!import_node_path2.isAbsolute(resources))
|
|
309
|
+
throw new Error("Resources must be an absolute path");
|
|
310
|
+
const id = runtime === "cursor" ? "cursor-cli" : runtime;
|
|
311
|
+
const supported = ["agy", "codex-acp", "claude", "gemini", "copilot", "cursor-cli", "opencode", "opencode-v2"];
|
|
312
|
+
if (!supported.includes(id))
|
|
313
|
+
throw new Error("Session configuration home is not verified for runtime: " + runtime);
|
|
314
|
+
const text = readAppRulesText(resources);
|
|
315
|
+
if (!text)
|
|
316
|
+
throw new Error("Session configuration requires nonempty AGENTS.md");
|
|
317
|
+
const parent = import_node_path2.resolve(import_node_os.tmpdir());
|
|
318
|
+
const directory = await import_promises.mkdtemp(import_node_path2.join(parent, "acp-session-config-"));
|
|
319
|
+
const checkRoot = () => {
|
|
320
|
+
if (import_node_path2.resolve(directory) === parent || !import_node_path2.resolve(directory).startsWith(parent + import_node_path2.sep) || !import_node_path2.relative(parent, directory).startsWith("acp-session-config-"))
|
|
321
|
+
throw new Error("Unsafe configuration cleanup target");
|
|
322
|
+
};
|
|
323
|
+
const dispose = async () => {
|
|
324
|
+
checkRoot();
|
|
325
|
+
let failure;
|
|
326
|
+
for (let i = 0;i < 30; i++) {
|
|
327
|
+
try {
|
|
328
|
+
await import_promises.rm(directory, { recursive: true, force: true });
|
|
329
|
+
return;
|
|
330
|
+
} catch (error) {
|
|
331
|
+
failure = error;
|
|
332
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
throw failure;
|
|
336
|
+
};
|
|
337
|
+
try {
|
|
338
|
+
const config = import_node_path2.join(directory, "config");
|
|
339
|
+
await import_promises.mkdir(config, { recursive: true, mode: 448 });
|
|
340
|
+
let env;
|
|
341
|
+
let rulesFile;
|
|
342
|
+
let skillsRoot = import_node_path2.join(config, "skills");
|
|
343
|
+
let nativeRules = true;
|
|
344
|
+
if (id === "agy") {
|
|
345
|
+
rulesFile = import_node_path2.join(config, "AGENTS.md");
|
|
346
|
+
env = { AGY_ACP_RESOURCES_DIR: config };
|
|
347
|
+
nativeRules = false;
|
|
348
|
+
} else if (id === "gemini") {
|
|
349
|
+
const root = import_node_path2.join(directory, "home", ".gemini");
|
|
350
|
+
await import_promises.mkdir(root, { recursive: true, mode: 448 });
|
|
351
|
+
rulesFile = import_node_path2.join(root, "GEMINI.md");
|
|
352
|
+
skillsRoot = import_node_path2.join(root, "skills");
|
|
353
|
+
env = { GEMINI_CLI_HOME: import_node_path2.join(directory, "home") };
|
|
354
|
+
} else if (id === "claude") {
|
|
355
|
+
rulesFile = import_node_path2.join(config, "CLAUDE.md");
|
|
356
|
+
env = { CLAUDE_CONFIG_DIR: config };
|
|
357
|
+
} else if (id === "codex-acp") {
|
|
358
|
+
rulesFile = import_node_path2.join(config, "AGENTS.md");
|
|
359
|
+
env = { CODEX_HOME: config };
|
|
360
|
+
} else if (id === "copilot") {
|
|
361
|
+
rulesFile = import_node_path2.join(config, "copilot-instructions.md");
|
|
362
|
+
env = { COPILOT_HOME: config, COPILOT_CUSTOM_INSTRUCTIONS_DIRS: config, COPILOT_SKILLS_DIRS: skillsRoot };
|
|
363
|
+
await import_promises.writeFile(import_node_path2.join(config, "AGENTS.md"), text, { mode: 384 });
|
|
364
|
+
} else if (id === "cursor-cli") {
|
|
365
|
+
rulesFile = import_node_path2.join(config, "AGENTS.md");
|
|
366
|
+
env = { CURSOR_CONFIG_DIR: config };
|
|
367
|
+
nativeRules = false;
|
|
368
|
+
} else {
|
|
369
|
+
const root = import_node_path2.join(directory, "xdg-config", "opencode");
|
|
370
|
+
await import_promises.mkdir(root, { recursive: true, mode: 448 });
|
|
371
|
+
rulesFile = import_node_path2.join(root, "AGENTS.md");
|
|
372
|
+
skillsRoot = import_node_path2.join(root, "skills");
|
|
373
|
+
env = { XDG_CONFIG_HOME: import_node_path2.join(directory, "xdg-config"), XDG_DATA_HOME: import_node_path2.join(directory, "xdg-data"), XDG_CACHE_HOME: import_node_path2.join(directory, "xdg-cache"), XDG_STATE_HOME: import_node_path2.join(directory, "xdg-state") };
|
|
374
|
+
if (id === "opencode")
|
|
375
|
+
env.OPENCODE_CONFIG_DIR = root;
|
|
376
|
+
const skills = id === "opencode" ? { paths: [skillsRoot] } : [skillsRoot];
|
|
377
|
+
await import_promises.writeFile(import_node_path2.join(root, "opencode.json"), JSON.stringify({ instructions: [rulesFile], skills }), { mode: 384 });
|
|
378
|
+
}
|
|
379
|
+
await import_promises.writeFile(rulesFile, text, { mode: 384 });
|
|
380
|
+
const input = import_node_path2.join(resources, "skills");
|
|
381
|
+
try {
|
|
382
|
+
const info = await import_promises.lstat(input);
|
|
383
|
+
if (info.isSymbolicLink() || !info.isDirectory())
|
|
384
|
+
throw new Error("Skill root must be a regular directory");
|
|
385
|
+
const physical = await import_promises.realpath(input);
|
|
386
|
+
const copy = async (from, to) => {
|
|
387
|
+
await import_promises.mkdir(to, { recursive: true, mode: 448 });
|
|
388
|
+
for (const entry of await import_promises.readdir(from, { withFileTypes: true })) {
|
|
389
|
+
const src = import_node_path2.join(from, entry.name);
|
|
390
|
+
const info = await import_promises.lstat(src);
|
|
391
|
+
if (info.isSymbolicLink())
|
|
392
|
+
throw new Error("Skill symlink is not allowed");
|
|
393
|
+
const actual = await import_promises.realpath(src);
|
|
394
|
+
const rel = import_node_path2.relative(physical, actual);
|
|
395
|
+
if (rel.startsWith(".." + import_node_path2.sep) || rel === ".." || import_node_path2.isAbsolute(rel))
|
|
396
|
+
throw new Error("Skill path escapes resources");
|
|
397
|
+
if (info.isDirectory())
|
|
398
|
+
await copy(src, import_node_path2.join(to, entry.name));
|
|
399
|
+
else if (info.isFile() && entry.name.toLowerCase().endsWith(".md"))
|
|
400
|
+
await import_promises.writeFile(import_node_path2.join(to, entry.name), await import_promises.readFile(src), { mode: 384 });
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
await copy(input, skillsRoot);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
if (error.code !== "ENOENT" || import_node_fs2.existsSync(input))
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
return { directory, env, rulesFile, nativeRules, dispose };
|
|
409
|
+
} catch (error) {
|
|
410
|
+
await dispose();
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
178
415
|
// src/session/available-commands.ts
|
|
179
416
|
function normalizeCommand(raw) {
|
|
180
417
|
if (!raw || typeof raw !== "object")
|
|
@@ -10298,15 +10535,15 @@ var legacyClientNotificationMethods = new Set([
|
|
|
10298
10535
|
]);
|
|
10299
10536
|
|
|
10300
10537
|
// src/runtimes/codex/quota.ts
|
|
10301
|
-
var
|
|
10302
|
-
var
|
|
10538
|
+
var import_node_fs4 = require("node:fs");
|
|
10539
|
+
var import_node_path4 = require("node:path");
|
|
10303
10540
|
var import_node_child_process = require("node:child_process");
|
|
10304
10541
|
var import_node_readline = __toESM(require("node:readline"), 1);
|
|
10305
10542
|
|
|
10306
10543
|
// src/runtimes/codex/codex-auth-preflight.ts
|
|
10307
|
-
var
|
|
10308
|
-
var
|
|
10309
|
-
var
|
|
10544
|
+
var import_node_fs3 = require("node:fs");
|
|
10545
|
+
var import_node_os2 = require("node:os");
|
|
10546
|
+
var import_node_path3 = require("node:path");
|
|
10310
10547
|
function emptyAcpAuthPreflight() {
|
|
10311
10548
|
return {
|
|
10312
10549
|
codexHome: "",
|
|
@@ -10320,12 +10557,12 @@ function resolveCodexHome() {
|
|
|
10320
10557
|
const fromEnv = process.env.CODEX_HOME?.trim();
|
|
10321
10558
|
if (fromEnv)
|
|
10322
10559
|
return fromEnv;
|
|
10323
|
-
return
|
|
10560
|
+
return import_node_path3.join(import_node_os2.homedir(), ".codex");
|
|
10324
10561
|
}
|
|
10325
10562
|
function probeCodexAuth() {
|
|
10326
10563
|
const codexHome = resolveCodexHome();
|
|
10327
|
-
const hasCodexHome =
|
|
10328
|
-
const hasAuthFile =
|
|
10564
|
+
const hasCodexHome = import_node_fs3.existsSync(codexHome);
|
|
10565
|
+
const hasAuthFile = import_node_fs3.existsSync(import_node_path3.join(codexHome, "auth.json"));
|
|
10329
10566
|
const hasApiKeyEnv = Boolean(process.env.CODEX_API_KEY?.trim() || process.env.OPENAI_API_KEY?.trim());
|
|
10330
10567
|
return {
|
|
10331
10568
|
codexHome,
|
|
@@ -10375,7 +10612,7 @@ async function queryCodexAppServer(timeoutMs = 1e4) {
|
|
|
10375
10612
|
};
|
|
10376
10613
|
timer = setTimeout(() => cleanup(null), timeoutMs);
|
|
10377
10614
|
try {
|
|
10378
|
-
const cmd = process.platform === "win32" ? "codex" :
|
|
10615
|
+
const cmd = process.platform === "win32" ? "codex" : import_node_fs4.existsSync("/mnt/c/Users") ? "codex.exe" : "codex";
|
|
10379
10616
|
proc = import_node_child_process.spawn(cmd, ["app-server"], {
|
|
10380
10617
|
stdio: ["pipe", "pipe", "pipe"],
|
|
10381
10618
|
shell: process.platform === "win32",
|
|
@@ -10446,13 +10683,13 @@ function formatEpochTime(epochSeconds) {
|
|
|
10446
10683
|
}
|
|
10447
10684
|
async function probeCodexQuota(options) {
|
|
10448
10685
|
const codexHome = resolveCodexHome();
|
|
10449
|
-
const authPath =
|
|
10686
|
+
const authPath = import_node_path4.join(codexHome, "auth.json");
|
|
10450
10687
|
let accountEmail;
|
|
10451
10688
|
let accountPlan = "Codex Free / Local";
|
|
10452
10689
|
let isLoggedIn = false;
|
|
10453
|
-
if (
|
|
10690
|
+
if (import_node_fs4.existsSync(authPath)) {
|
|
10454
10691
|
try {
|
|
10455
|
-
const authData = JSON.parse(
|
|
10692
|
+
const authData = JSON.parse(import_node_fs4.readFileSync(authPath, "utf8"));
|
|
10456
10693
|
if (authData.OPENAI_API_KEY) {
|
|
10457
10694
|
isLoggedIn = true;
|
|
10458
10695
|
accountPlan = "OpenAI API Key";
|
|
@@ -10543,8 +10780,92 @@ async function probeCodexQuota(options) {
|
|
|
10543
10780
|
}
|
|
10544
10781
|
|
|
10545
10782
|
// src/runtimes/codex/index.ts
|
|
10546
|
-
var
|
|
10547
|
-
var
|
|
10783
|
+
var import_promises3 = require("node:fs/promises");
|
|
10784
|
+
var import_node_path7 = require("node:path");
|
|
10785
|
+
var import_node_os4 = require("node:os");
|
|
10786
|
+
var import_node_fs6 = require("node:fs");
|
|
10787
|
+
var import_node_crypto2 = require("node:crypto");
|
|
10788
|
+
|
|
10789
|
+
// src/resources/config-text.ts
|
|
10790
|
+
function mergeCodexConfigJson(input) {
|
|
10791
|
+
const block = (input.hostBlock ?? "").trim();
|
|
10792
|
+
if (!block)
|
|
10793
|
+
return { ok: false, reason: "empty-block" };
|
|
10794
|
+
const raw = (input.existingRaw ?? "").trim();
|
|
10795
|
+
if (!raw) {
|
|
10796
|
+
return { ok: true, json: JSON.stringify({ developer_instructions: block }), preservedUserInstructions: false };
|
|
10797
|
+
}
|
|
10798
|
+
let parsed;
|
|
10799
|
+
try {
|
|
10800
|
+
parsed = JSON.parse(raw);
|
|
10801
|
+
} catch {
|
|
10802
|
+
return { ok: false, reason: "invalid-json" };
|
|
10803
|
+
}
|
|
10804
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
10805
|
+
return { ok: false, reason: "invalid-json" };
|
|
10806
|
+
}
|
|
10807
|
+
const merged = { ...parsed };
|
|
10808
|
+
const existing = merged["developer_instructions"];
|
|
10809
|
+
if (existing === undefined) {
|
|
10810
|
+
merged["developer_instructions"] = block;
|
|
10811
|
+
return { ok: true, json: JSON.stringify(merged), preservedUserInstructions: false };
|
|
10812
|
+
}
|
|
10813
|
+
if (typeof existing !== "string") {
|
|
10814
|
+
return { ok: false, reason: "conflicting-value" };
|
|
10815
|
+
}
|
|
10816
|
+
const kept = existing.trim();
|
|
10817
|
+
merged["developer_instructions"] = kept ? `${block}
|
|
10818
|
+
|
|
10819
|
+
${kept}` : block;
|
|
10820
|
+
return { ok: true, json: JSON.stringify(merged), preservedUserInstructions: kept !== "" };
|
|
10821
|
+
}
|
|
10822
|
+
function mergeConfigTomlPreserving(input) {
|
|
10823
|
+
const block = (input.replacementBlock ?? "").trim() ? `${input.replacementBlock.trim()}
|
|
10824
|
+
` : "";
|
|
10825
|
+
if (!input.existingText || !input.existingText.trim())
|
|
10826
|
+
return block;
|
|
10827
|
+
if (/"""|'''/.test(input.existingText) || /^\s*\[.*["'].*\]|^\s*\[\[|^\s*["'](?:model|model_provider)["']\s*=/m.test(input.existingText)) {
|
|
10828
|
+
throw new Error("复杂 TOML 配置需要结构化合并,已保留原文件");
|
|
10829
|
+
}
|
|
10830
|
+
const topKeys = new Set(input.managedTopKeys);
|
|
10831
|
+
const tables = new Set(input.managedTables);
|
|
10832
|
+
const out = [];
|
|
10833
|
+
let inManagedTable = false;
|
|
10834
|
+
let inAnyTable = false;
|
|
10835
|
+
for (const line of input.existingText.split(`
|
|
10836
|
+
`)) {
|
|
10837
|
+
const header = /^\s*\[([^\]]+)\]\s*(?:#.*)?$/.exec(line)?.[1]?.trim() ?? null;
|
|
10838
|
+
if (header !== null) {
|
|
10839
|
+
inAnyTable = true;
|
|
10840
|
+
inManagedTable = tables.has(header);
|
|
10841
|
+
if (!inManagedTable)
|
|
10842
|
+
out.push(line);
|
|
10843
|
+
continue;
|
|
10844
|
+
}
|
|
10845
|
+
if (inManagedTable)
|
|
10846
|
+
continue;
|
|
10847
|
+
if (!inAnyTable) {
|
|
10848
|
+
const key = /^\s*([A-Za-z0-9_-]+)\s*=/.exec(line)?.[1];
|
|
10849
|
+
if (key && topKeys.has(key))
|
|
10850
|
+
continue;
|
|
10851
|
+
}
|
|
10852
|
+
out.push(line);
|
|
10853
|
+
}
|
|
10854
|
+
const kept = out.join(`
|
|
10855
|
+
`).trim();
|
|
10856
|
+
if (!kept)
|
|
10857
|
+
return block;
|
|
10858
|
+
const tableAt = block.search(/^\s*\[/m);
|
|
10859
|
+
if (tableAt < 0)
|
|
10860
|
+
return block + `
|
|
10861
|
+
` + kept + `
|
|
10862
|
+
`;
|
|
10863
|
+
return block.slice(0, tableAt).trimEnd() + `
|
|
10864
|
+
|
|
10865
|
+
` + kept + `
|
|
10866
|
+
|
|
10867
|
+
` + block.slice(tableAt);
|
|
10868
|
+
}
|
|
10548
10869
|
|
|
10549
10870
|
// src/runtimes/codex/codex-provider-home.ts
|
|
10550
10871
|
var INKDOWN_PROVIDER_ID = "inkdown-custom";
|
|
@@ -10576,13 +10897,13 @@ function buildCustomProviderSpawnEnv(config, apiKey, codexHome) {
|
|
|
10576
10897
|
}
|
|
10577
10898
|
|
|
10578
10899
|
// src/runtimes/codex/codex-provider.ts
|
|
10579
|
-
var
|
|
10580
|
-
var
|
|
10581
|
-
var
|
|
10900
|
+
var import_promises2 = require("node:fs/promises");
|
|
10901
|
+
var import_node_fs5 = require("node:fs");
|
|
10902
|
+
var import_node_path6 = require("node:path");
|
|
10582
10903
|
|
|
10583
10904
|
// src/client/acp-paths.ts
|
|
10584
|
-
var
|
|
10585
|
-
var
|
|
10905
|
+
var import_node_os3 = require("node:os");
|
|
10906
|
+
var import_node_path5 = require("node:path");
|
|
10586
10907
|
function getDefaultAgentDataDir() {
|
|
10587
10908
|
if (process.env.INKDOWN_DATA_DIR) {
|
|
10588
10909
|
return process.env.INKDOWN_DATA_DIR;
|
|
@@ -10591,27 +10912,27 @@ function getDefaultAgentDataDir() {
|
|
|
10591
10912
|
return process.env.ACP_DATA_DIR;
|
|
10592
10913
|
}
|
|
10593
10914
|
if (process.platform === "win32") {
|
|
10594
|
-
return process.env.LOCALAPPDATA || process.env.APPDATA ||
|
|
10915
|
+
return process.env.LOCALAPPDATA || process.env.APPDATA || import_node_path5.join(import_node_os3.homedir(), "AppData", "Local", "inkdown");
|
|
10595
10916
|
}
|
|
10596
10917
|
if (process.platform === "darwin") {
|
|
10597
|
-
return
|
|
10918
|
+
return import_node_path5.join(import_node_os3.homedir(), "Library", "Application Support", "inkdown");
|
|
10598
10919
|
}
|
|
10599
|
-
return process.env.XDG_DATA_HOME ||
|
|
10920
|
+
return process.env.XDG_DATA_HOME || import_node_path5.join(import_node_os3.homedir(), ".local", "share", "inkdown");
|
|
10600
10921
|
}
|
|
10601
10922
|
|
|
10602
10923
|
// src/runtimes/codex/codex-provider.ts
|
|
10603
10924
|
function providerFilePath(dir) {
|
|
10604
|
-
return
|
|
10925
|
+
return import_node_path6.join(dir, "agent", "provider.json");
|
|
10605
10926
|
}
|
|
10606
10927
|
function providerHomePath(dir) {
|
|
10607
|
-
return
|
|
10928
|
+
return import_node_path6.join(dir, "agent", "codex-home");
|
|
10608
10929
|
}
|
|
10609
10930
|
async function readStoredAcpProvider(dir = getDefaultAgentDataDir()) {
|
|
10610
10931
|
const file = providerFilePath(dir);
|
|
10611
|
-
if (!
|
|
10932
|
+
if (!import_node_fs5.existsSync(file))
|
|
10612
10933
|
return null;
|
|
10613
10934
|
try {
|
|
10614
|
-
const raw = JSON.parse(await
|
|
10935
|
+
const raw = JSON.parse(await import_promises2.readFile(file, "utf8"));
|
|
10615
10936
|
if (typeof raw.baseUrl !== "string" || typeof raw.model !== "string" || typeof raw.apiKey !== "string" || !raw.apiKey.trim()) {
|
|
10616
10937
|
return null;
|
|
10617
10938
|
}
|
|
@@ -10633,8 +10954,20 @@ function getAcpProviderCodexHome(dir = getDefaultAgentDataDir()) {
|
|
|
10633
10954
|
// src/runtimes/codex/index.ts
|
|
10634
10955
|
async function provisionCustomProviderCodexHome(provider, codexHome) {
|
|
10635
10956
|
try {
|
|
10636
|
-
await
|
|
10637
|
-
|
|
10957
|
+
await import_promises3.mkdir(codexHome, { recursive: true });
|
|
10958
|
+
let existing = null;
|
|
10959
|
+
try {
|
|
10960
|
+
existing = await import_promises3.readFile(import_node_path7.join(codexHome, "config.toml"), "utf8");
|
|
10961
|
+
} catch (error) {
|
|
10962
|
+
if (error.code !== "ENOENT")
|
|
10963
|
+
throw error;
|
|
10964
|
+
}
|
|
10965
|
+
await import_promises3.writeFile(import_node_path7.join(codexHome, "config.toml"), mergeConfigTomlPreserving({
|
|
10966
|
+
existingText: existing,
|
|
10967
|
+
managedTopKeys: ["model", "model_provider"],
|
|
10968
|
+
managedTables: [`model_providers.${INKDOWN_PROVIDER_ID}`],
|
|
10969
|
+
replacementBlock: buildCustomProviderConfigToml(provider)
|
|
10970
|
+
}), "utf8");
|
|
10638
10971
|
return true;
|
|
10639
10972
|
} catch (error) {
|
|
10640
10973
|
console.error("[acp] 自定义供应商 config.toml 写入失败,回落本机登录", error);
|
|
@@ -10644,6 +10977,78 @@ async function provisionCustomProviderCodexHome(provider, codexHome) {
|
|
|
10644
10977
|
var codexAdapter = {
|
|
10645
10978
|
id: "codex-acp",
|
|
10646
10979
|
probeQuota: async (options) => probeCodexQuota(options),
|
|
10980
|
+
supportedBridgeVersions: ["2.2.2"],
|
|
10981
|
+
prepareAppResources: async ({ directory, workspaceRoot, env: overrideEnv }) => {
|
|
10982
|
+
const load = readAppResourcesDir(directory);
|
|
10983
|
+
const skillsFound = load.skills.map((s) => s.name);
|
|
10984
|
+
const rulesText = readAppRulesText(directory);
|
|
10985
|
+
if (!rulesText) {
|
|
10986
|
+
return {
|
|
10987
|
+
report: {
|
|
10988
|
+
rulesApplied: false,
|
|
10989
|
+
rulesChars: 0,
|
|
10990
|
+
profileDigest: null,
|
|
10991
|
+
skillsFound,
|
|
10992
|
+
reason: "rules-missing"
|
|
10993
|
+
}
|
|
10994
|
+
};
|
|
10995
|
+
}
|
|
10996
|
+
const env = { ...process.env, ...overrideEnv };
|
|
10997
|
+
const notApplied = (reason) => ({ report: {
|
|
10998
|
+
rulesApplied: false,
|
|
10999
|
+
rulesPrepared: false,
|
|
11000
|
+
skillsApplied: false,
|
|
11001
|
+
rulesChars: rulesText.length,
|
|
11002
|
+
profileDigest: digestAppResources(load),
|
|
11003
|
+
skillsFound,
|
|
11004
|
+
reason
|
|
11005
|
+
} });
|
|
11006
|
+
if (!load.directoryReadable)
|
|
11007
|
+
return notApplied("invalid-resource-directory");
|
|
11008
|
+
if (env.CODEX_PATH)
|
|
11009
|
+
return notApplied("execution-not-verified");
|
|
11010
|
+
const codexHome = env.CODEX_HOME || import_node_path7.join(import_node_os4.homedir(), ".codex");
|
|
11011
|
+
try {
|
|
11012
|
+
await import_promises3.readFile(import_node_path7.join(codexHome, "config.toml"));
|
|
11013
|
+
return notApplied("effective-config-not-verified");
|
|
11014
|
+
} catch (error) {
|
|
11015
|
+
if (error.code !== "ENOENT")
|
|
11016
|
+
return notApplied("effective-config-not-verified");
|
|
11017
|
+
}
|
|
11018
|
+
for (let dir = workspaceRoot;dir; ) {
|
|
11019
|
+
if (import_node_fs6.existsSync(import_node_path7.join(dir, ".codex", "config.toml")))
|
|
11020
|
+
return notApplied("effective-config-not-verified");
|
|
11021
|
+
if (import_node_fs6.existsSync(import_node_path7.join(dir, ".git")))
|
|
11022
|
+
break;
|
|
11023
|
+
const parent = import_node_path7.dirname(dir);
|
|
11024
|
+
if (parent === dir)
|
|
11025
|
+
break;
|
|
11026
|
+
dir = parent;
|
|
11027
|
+
}
|
|
11028
|
+
const merged = mergeCodexConfigJson({ existingRaw: env["CODEX_CONFIG"], hostBlock: rulesText });
|
|
11029
|
+
if (!merged.ok) {
|
|
11030
|
+
return {
|
|
11031
|
+
report: {
|
|
11032
|
+
rulesApplied: false,
|
|
11033
|
+
rulesChars: rulesText.length,
|
|
11034
|
+
profileDigest: digestAppResources(load),
|
|
11035
|
+
skillsFound,
|
|
11036
|
+
reason: merged.reason === "invalid-json" ? "invalid-codex-config" : "conflicting-codex-config"
|
|
11037
|
+
}
|
|
11038
|
+
};
|
|
11039
|
+
}
|
|
11040
|
+
return {
|
|
11041
|
+
env: { CODEX_CONFIG: merged.json },
|
|
11042
|
+
report: {
|
|
11043
|
+
rulesApplied: false,
|
|
11044
|
+
rulesPrepared: true,
|
|
11045
|
+
skillsApplied: false,
|
|
11046
|
+
rulesChars: rulesText.length,
|
|
11047
|
+
profileDigest: import_node_crypto2.createHash("sha256").update(JSON.stringify([digestAppResources(load), codexHome, workspaceRoot, merged.json])).digest("hex"),
|
|
11048
|
+
skillsFound
|
|
11049
|
+
}
|
|
11050
|
+
};
|
|
11051
|
+
},
|
|
10647
11052
|
probeAuth: () => {
|
|
10648
11053
|
return probeCodexAuth();
|
|
10649
11054
|
},
|
|
@@ -10660,11 +11065,73 @@ var codexAdapter = {
|
|
|
10660
11065
|
}
|
|
10661
11066
|
};
|
|
10662
11067
|
|
|
10663
|
-
// src/
|
|
10664
|
-
var
|
|
10665
|
-
var import_node_os3 = require("node:os");
|
|
10666
|
-
var import_node_path6 = require("node:path");
|
|
11068
|
+
// src/resources/runtime-bindings.ts
|
|
11069
|
+
var import_node_path8 = require("node:path");
|
|
10667
11070
|
var import_node_child_process2 = require("node:child_process");
|
|
11071
|
+
var import_node_util = require("node:util");
|
|
11072
|
+
function prepareCompatibilityResources(directory, reason) {
|
|
11073
|
+
const load = readAppResourcesDir(directory);
|
|
11074
|
+
return { report: {
|
|
11075
|
+
rulesApplied: false,
|
|
11076
|
+
rulesPrepared: false,
|
|
11077
|
+
skillsApplied: false,
|
|
11078
|
+
rulesChars: load.rules?.chars ?? 0,
|
|
11079
|
+
profileDigest: digestAppResources(load),
|
|
11080
|
+
skillsFound: load.skills.map((s) => s.name),
|
|
11081
|
+
reason
|
|
11082
|
+
} };
|
|
11083
|
+
}
|
|
11084
|
+
function mergeOpenCodeAppConfig(raw, directory) {
|
|
11085
|
+
const value = raw?.trim() ? JSON.parse(raw) : {};
|
|
11086
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
11087
|
+
throw new Error("invalid-opencode-config");
|
|
11088
|
+
const config = value;
|
|
11089
|
+
if (config.instructions !== undefined && (!Array.isArray(config.instructions) || config.instructions.some((v) => typeof v !== "string")))
|
|
11090
|
+
throw new Error("invalid-opencode-instructions");
|
|
11091
|
+
if (config.skills !== undefined && (!config.skills || typeof config.skills !== "object" || Array.isArray(config.skills)))
|
|
11092
|
+
throw new Error("invalid-opencode-skills");
|
|
11093
|
+
const skills = config.skills ?? {};
|
|
11094
|
+
if (skills.paths !== undefined && (!Array.isArray(skills.paths) || skills.paths.some((v) => typeof v !== "string")))
|
|
11095
|
+
throw new Error("invalid-opencode-skill-paths");
|
|
11096
|
+
return JSON.stringify({
|
|
11097
|
+
...config,
|
|
11098
|
+
instructions: [...new Set([...config.instructions ?? [], import_node_path8.join(directory, "AGENTS.md")])],
|
|
11099
|
+
skills: { ...skills, paths: [...new Set([...skills.paths ?? [], import_node_path8.join(directory, "skills")])] }
|
|
11100
|
+
});
|
|
11101
|
+
}
|
|
11102
|
+
async function prepareOpenCodeResources(input) {
|
|
11103
|
+
const prep = prepareCompatibilityResources(input.directory, "native-entry-not-verified");
|
|
11104
|
+
if (!input.command || !readAppRulesText(input.directory))
|
|
11105
|
+
return prep;
|
|
11106
|
+
try {
|
|
11107
|
+
const { stdout } = await import_node_util.promisify(import_node_child_process2.execFile)(input.command, ["--version"], { env: input.env, timeout: 8000, windowsHide: true });
|
|
11108
|
+
if (stdout.trim() !== "1.18.35")
|
|
11109
|
+
return prep;
|
|
11110
|
+
const json = mergeOpenCodeAppConfig(input.env?.OPENCODE_CONFIG_CONTENT, input.directory);
|
|
11111
|
+
return { env: { OPENCODE_CONFIG_CONTENT: json }, report: { ...prep.report, rulesPrepared: true, reason: undefined } };
|
|
11112
|
+
} catch {
|
|
11113
|
+
return { ...prep, report: { ...prep.report, reason: "native-config-prepare-failed" } };
|
|
11114
|
+
}
|
|
11115
|
+
}
|
|
11116
|
+
function prepareClaudeResources(directory) {
|
|
11117
|
+
const prep = prepareCompatibilityResources(directory, "native-session-version-not-verified");
|
|
11118
|
+
return { ...prep, report: { ...prep.report, rulesPrepared: !!readAppRulesText(directory) } };
|
|
11119
|
+
}
|
|
11120
|
+
function claudeResourceSessionMeta(directory) {
|
|
11121
|
+
const text = readAppRulesText(directory);
|
|
11122
|
+
if (!text)
|
|
11123
|
+
return;
|
|
11124
|
+
return {
|
|
11125
|
+
systemPrompt: { type: "preset", preset: "claude_code", append: text },
|
|
11126
|
+
claudeCode: { options: { plugins: [{ type: "local", path: directory }] } }
|
|
11127
|
+
};
|
|
11128
|
+
}
|
|
11129
|
+
|
|
11130
|
+
// src/runtimes/claude/quota.ts
|
|
11131
|
+
var import_node_fs7 = require("node:fs");
|
|
11132
|
+
var import_node_os5 = require("node:os");
|
|
11133
|
+
var import_node_path9 = require("node:path");
|
|
11134
|
+
var import_node_child_process3 = require("node:child_process");
|
|
10668
11135
|
var cachedClaudeAuth = null;
|
|
10669
11136
|
async function queryClaudeAuthStatus(timeoutMs = 1200) {
|
|
10670
11137
|
if (cachedClaudeAuth && Date.now() - cachedClaudeAuth.time < 30000) {
|
|
@@ -10672,7 +11139,7 @@ async function queryClaudeAuthStatus(timeoutMs = 1200) {
|
|
|
10672
11139
|
}
|
|
10673
11140
|
return new Promise((resolve) => {
|
|
10674
11141
|
try {
|
|
10675
|
-
|
|
11142
|
+
import_node_child_process3.execFile("claude", ["auth", "status", "--json"], { timeout: timeoutMs, windowsHide: true, shell: process.platform === "win32" }, (err, stdout) => {
|
|
10676
11143
|
if (!stdout)
|
|
10677
11144
|
return resolve(null);
|
|
10678
11145
|
try {
|
|
@@ -10690,15 +11157,15 @@ async function queryClaudeAuthStatus(timeoutMs = 1200) {
|
|
|
10690
11157
|
}
|
|
10691
11158
|
async function probeClaudeQuota(options) {
|
|
10692
11159
|
const claudeHome = resolveClaudeHome();
|
|
10693
|
-
const claudeJsonPath =
|
|
10694
|
-
const credsPath =
|
|
11160
|
+
const claudeJsonPath = import_node_path9.join(import_node_os5.homedir(), ".claude.json");
|
|
11161
|
+
const credsPath = import_node_path9.join(claudeHome, ".credentials.json");
|
|
10695
11162
|
let isLoggedIn = false;
|
|
10696
11163
|
let isBanned = false;
|
|
10697
11164
|
let accountEmail;
|
|
10698
11165
|
let plan = "Claude Free / Default";
|
|
10699
|
-
if (
|
|
11166
|
+
if (import_node_fs7.existsSync(claudeJsonPath)) {
|
|
10700
11167
|
try {
|
|
10701
|
-
const data = JSON.parse(
|
|
11168
|
+
const data = JSON.parse(import_node_fs7.readFileSync(claudeJsonPath, "utf8"));
|
|
10702
11169
|
if (data.oauthAccount) {
|
|
10703
11170
|
isLoggedIn = true;
|
|
10704
11171
|
accountEmail = data.oauthAccount.emailAddress;
|
|
@@ -10709,9 +11176,9 @@ async function probeClaudeQuota(options) {
|
|
|
10709
11176
|
}
|
|
10710
11177
|
} catch {}
|
|
10711
11178
|
}
|
|
10712
|
-
if (
|
|
11179
|
+
if (import_node_fs7.existsSync(credsPath)) {
|
|
10713
11180
|
try {
|
|
10714
|
-
const creds = JSON.parse(
|
|
11181
|
+
const creds = JSON.parse(import_node_fs7.readFileSync(credsPath, "utf8"));
|
|
10715
11182
|
if (creds.accessToken || creds.sessionKey)
|
|
10716
11183
|
isLoggedIn = true;
|
|
10717
11184
|
} catch {}
|
|
@@ -10763,19 +11230,19 @@ async function probeClaudeQuota(options) {
|
|
|
10763
11230
|
}
|
|
10764
11231
|
|
|
10765
11232
|
// src/runtimes/claude/index.ts
|
|
10766
|
-
var
|
|
10767
|
-
var
|
|
10768
|
-
var
|
|
11233
|
+
var import_node_fs8 = require("node:fs");
|
|
11234
|
+
var import_node_os6 = require("node:os");
|
|
11235
|
+
var import_node_path10 = require("node:path");
|
|
10769
11236
|
function resolveClaudeHome() {
|
|
10770
11237
|
const fromEnv = process.env.CLAUDE_CONFIG_DIR?.trim();
|
|
10771
11238
|
if (fromEnv)
|
|
10772
11239
|
return fromEnv;
|
|
10773
|
-
return
|
|
11240
|
+
return import_node_path10.join(import_node_os6.homedir(), ".claude");
|
|
10774
11241
|
}
|
|
10775
11242
|
function probeClaudeAuth() {
|
|
10776
11243
|
const claudeHome = resolveClaudeHome();
|
|
10777
|
-
const hasCodexHome =
|
|
10778
|
-
const hasAuthFile =
|
|
11244
|
+
const hasCodexHome = import_node_fs8.existsSync(claudeHome);
|
|
11245
|
+
const hasAuthFile = import_node_fs8.existsSync(import_node_path10.join(import_node_os6.homedir(), ".claude.json")) || import_node_fs8.existsSync(import_node_path10.join(claudeHome, ".credentials.json"));
|
|
10779
11246
|
const hasApiKeyEnv = Boolean(process.env.ANTHROPIC_API_KEY?.trim() || process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim());
|
|
10780
11247
|
return {
|
|
10781
11248
|
codexHome: claudeHome,
|
|
@@ -10787,6 +11254,9 @@ function probeClaudeAuth() {
|
|
|
10787
11254
|
}
|
|
10788
11255
|
var claudeAdapter = {
|
|
10789
11256
|
id: "claude",
|
|
11257
|
+
supportedBridgeVersions: ["0.91.0"],
|
|
11258
|
+
prepareAppResources: async ({ directory }) => prepareClaudeResources(directory),
|
|
11259
|
+
appResourceSessionMeta: claudeResourceSessionMeta,
|
|
10790
11260
|
probeAuth: () => probeClaudeAuth(),
|
|
10791
11261
|
probeQuota: async (options) => probeClaudeQuota(options),
|
|
10792
11262
|
orderAuthMethods: (methods) => methods,
|
|
@@ -10794,16 +11264,16 @@ var claudeAdapter = {
|
|
|
10794
11264
|
};
|
|
10795
11265
|
|
|
10796
11266
|
// src/runtimes/gemini/index.ts
|
|
10797
|
-
var
|
|
10798
|
-
var
|
|
10799
|
-
var
|
|
11267
|
+
var import_node_fs9 = require("node:fs");
|
|
11268
|
+
var import_node_os7 = require("node:os");
|
|
11269
|
+
var import_node_path11 = require("node:path");
|
|
10800
11270
|
function resolveGeminiHome() {
|
|
10801
|
-
return
|
|
11271
|
+
return import_node_path11.join(import_node_os7.homedir(), ".gemini");
|
|
10802
11272
|
}
|
|
10803
11273
|
function probeGeminiAuth() {
|
|
10804
11274
|
const geminiHome = resolveGeminiHome();
|
|
10805
|
-
const hasCodexHome =
|
|
10806
|
-
const hasAuthFile =
|
|
11275
|
+
const hasCodexHome = import_node_fs9.existsSync(geminiHome);
|
|
11276
|
+
const hasAuthFile = import_node_fs9.existsSync(import_node_path11.join(geminiHome, "oauth_creds.json")) || Boolean(process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim());
|
|
10807
11277
|
const hasApiKeyEnv = Boolean(process.env.GEMINI_API_KEY?.trim() || process.env.GOOGLE_API_KEY?.trim());
|
|
10808
11278
|
return {
|
|
10809
11279
|
codexHome: geminiHome,
|
|
@@ -10815,24 +11285,25 @@ function probeGeminiAuth() {
|
|
|
10815
11285
|
}
|
|
10816
11286
|
var geminiAdapter = {
|
|
10817
11287
|
id: "gemini",
|
|
11288
|
+
prepareAppResources: async ({ directory }) => prepareCompatibilityResources(directory, "config-home-would-isolate-auth"),
|
|
10818
11289
|
probeAuth: () => probeGeminiAuth(),
|
|
10819
11290
|
orderAuthMethods: (methods) => methods,
|
|
10820
11291
|
canSkipInteractiveAuth: () => false
|
|
10821
11292
|
};
|
|
10822
11293
|
|
|
10823
11294
|
// src/runtimes/copilot/index.ts
|
|
10824
|
-
var
|
|
10825
|
-
var
|
|
10826
|
-
var
|
|
11295
|
+
var import_node_fs10 = require("node:fs");
|
|
11296
|
+
var import_node_os8 = require("node:os");
|
|
11297
|
+
var import_node_path12 = require("node:path");
|
|
10827
11298
|
function resolveCopilotHome() {
|
|
10828
11299
|
const fromEnv = process.env.COPILOT_HOME?.trim();
|
|
10829
11300
|
if (fromEnv)
|
|
10830
11301
|
return fromEnv;
|
|
10831
|
-
return
|
|
11302
|
+
return import_node_path12.join(import_node_os8.homedir(), ".copilot");
|
|
10832
11303
|
}
|
|
10833
11304
|
function hasCopilotLogin(home) {
|
|
10834
11305
|
try {
|
|
10835
|
-
const raw =
|
|
11306
|
+
const raw = import_node_fs10.readFileSync(import_node_path12.join(home, "config.json"), "utf8");
|
|
10836
11307
|
const parsed = JSON.parse(raw);
|
|
10837
11308
|
return Array.isArray(parsed.loggedInUsers) && parsed.loggedInUsers.length > 0;
|
|
10838
11309
|
} catch {
|
|
@@ -10841,7 +11312,7 @@ function hasCopilotLogin(home) {
|
|
|
10841
11312
|
}
|
|
10842
11313
|
function probeCopilotAuth() {
|
|
10843
11314
|
const copilotHome = resolveCopilotHome();
|
|
10844
|
-
const hasCodexHome =
|
|
11315
|
+
const hasCodexHome = import_node_fs10.existsSync(copilotHome);
|
|
10845
11316
|
const hasAuthFile = hasCopilotLogin(copilotHome);
|
|
10846
11317
|
const hasApiKeyEnv = Boolean(process.env.COPILOT_GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim() || process.env.GITHUB_TOKEN?.trim());
|
|
10847
11318
|
return {
|
|
@@ -10854,20 +11325,21 @@ function probeCopilotAuth() {
|
|
|
10854
11325
|
}
|
|
10855
11326
|
var copilotAdapter = {
|
|
10856
11327
|
id: "copilot",
|
|
11328
|
+
prepareAppResources: async ({ directory }) => prepareCompatibilityResources(directory, "native-entry-not-verified"),
|
|
10857
11329
|
probeAuth: () => probeCopilotAuth(),
|
|
10858
11330
|
orderAuthMethods: (methods) => methods,
|
|
10859
11331
|
canSkipInteractiveAuth: () => false
|
|
10860
11332
|
};
|
|
10861
11333
|
|
|
10862
11334
|
// src/runtimes/opencode/quota.ts
|
|
10863
|
-
var
|
|
10864
|
-
var
|
|
11335
|
+
var import_node_fs11 = require("node:fs");
|
|
11336
|
+
var import_node_child_process4 = require("node:child_process");
|
|
10865
11337
|
var os = __toESM(require("node:os"), 1);
|
|
10866
11338
|
var path = __toESM(require("node:path"), 1);
|
|
10867
11339
|
function resolveOpencodeAuthPath() {
|
|
10868
11340
|
const candidates = resolveOpencodeAuthCandidates();
|
|
10869
11341
|
for (const c of candidates) {
|
|
10870
|
-
if (
|
|
11342
|
+
if (import_node_fs11.existsSync(c))
|
|
10871
11343
|
return c;
|
|
10872
11344
|
}
|
|
10873
11345
|
return candidates[0] ?? null;
|
|
@@ -10879,7 +11351,7 @@ async function queryOpencodeStats(timeoutMs = 1200) {
|
|
|
10879
11351
|
}
|
|
10880
11352
|
return new Promise((resolve) => {
|
|
10881
11353
|
try {
|
|
10882
|
-
|
|
11354
|
+
import_node_child_process4.execFile("opencode", ["stats", "--standalone", "--cost", "--json"], { timeout: timeoutMs, windowsHide: true }, (err, stdout) => {
|
|
10883
11355
|
if (!stdout)
|
|
10884
11356
|
return resolve(null);
|
|
10885
11357
|
try {
|
|
@@ -10898,7 +11370,7 @@ async function queryOpencodeStats(timeoutMs = 1200) {
|
|
|
10898
11370
|
async function queryOpencodeAuthList(timeoutMs = 1200) {
|
|
10899
11371
|
return new Promise((resolve) => {
|
|
10900
11372
|
try {
|
|
10901
|
-
|
|
11373
|
+
import_node_child_process4.execFile("opencode", ["auth", "list"], { timeout: timeoutMs, windowsHide: true }, (err, stdout) => {
|
|
10902
11374
|
if (!stdout)
|
|
10903
11375
|
return resolve([]);
|
|
10904
11376
|
const lines = stdout.split(`
|
|
@@ -10918,7 +11390,7 @@ function readLocalOpencodeCredentials() {
|
|
|
10918
11390
|
path.join(home, ".config", "opencode", "opencode.db")
|
|
10919
11391
|
].filter(Boolean);
|
|
10920
11392
|
for (const dbPath of dbPaths) {
|
|
10921
|
-
if (!
|
|
11393
|
+
if (!import_node_fs11.existsSync(dbPath))
|
|
10922
11394
|
continue;
|
|
10923
11395
|
try {
|
|
10924
11396
|
let rows = [];
|
|
@@ -10947,7 +11419,7 @@ function readLocalOpencodeCredentials() {
|
|
|
10947
11419
|
}
|
|
10948
11420
|
} catch {
|
|
10949
11421
|
try {
|
|
10950
|
-
const buf =
|
|
11422
|
+
const buf = import_node_fs11.readFileSync(dbPath, "utf8");
|
|
10951
11423
|
const emailMatch = buf.match(/"email"\s*:\s*"([^"]+)"/);
|
|
10952
11424
|
const tokenMatch = buf.match(/"access"\s*:\s*"(st_[a-zA-Z0-9_\\-]+)"/);
|
|
10953
11425
|
const orgMatch = buf.match(/"orgID"\s*:\s*"(wrk_[a-zA-Z0-9_\\-]+)"/);
|
|
@@ -11071,9 +11543,9 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
|
11071
11543
|
let accountEmail = dbCreds.email;
|
|
11072
11544
|
let accountName = dbCreds.name;
|
|
11073
11545
|
let plan = "OpenCode Community";
|
|
11074
|
-
if (authPath &&
|
|
11546
|
+
if (authPath && import_node_fs11.existsSync(authPath)) {
|
|
11075
11547
|
try {
|
|
11076
|
-
const data = JSON.parse(
|
|
11548
|
+
const data = JSON.parse(import_node_fs11.readFileSync(authPath, "utf8"));
|
|
11077
11549
|
if (data && typeof data === "object") {
|
|
11078
11550
|
const keys = Object.keys(data);
|
|
11079
11551
|
if (keys.length > 0) {
|
|
@@ -11133,16 +11605,16 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
|
11133
11605
|
}
|
|
11134
11606
|
|
|
11135
11607
|
// src/runtimes/opencode/index.ts
|
|
11136
|
-
var
|
|
11137
|
-
var
|
|
11138
|
-
var
|
|
11608
|
+
var import_node_fs12 = require("node:fs");
|
|
11609
|
+
var import_node_os9 = require("node:os");
|
|
11610
|
+
var import_node_path13 = require("node:path");
|
|
11139
11611
|
function pickEnv(env, key) {
|
|
11140
11612
|
return env?.[key]?.trim() ?? "";
|
|
11141
11613
|
}
|
|
11142
11614
|
function resolveOpencodeAuthCandidates(overrides) {
|
|
11143
11615
|
const platform = overrides?.platform ?? process.platform;
|
|
11144
11616
|
const env = overrides?.env ?? process.env;
|
|
11145
|
-
const home = overrides?.home ??
|
|
11617
|
+
const home = overrides?.home ?? import_node_os9.homedir();
|
|
11146
11618
|
const seen = new Set;
|
|
11147
11619
|
const out = [];
|
|
11148
11620
|
const push = (p) => {
|
|
@@ -11153,27 +11625,27 @@ function resolveOpencodeAuthCandidates(overrides) {
|
|
|
11153
11625
|
};
|
|
11154
11626
|
const xdg = pickEnv(env, "XDG_DATA_HOME");
|
|
11155
11627
|
if (xdg)
|
|
11156
|
-
push(
|
|
11628
|
+
push(import_node_path13.join(xdg, "opencode", "auth.json"));
|
|
11157
11629
|
if (platform === "win32") {
|
|
11158
|
-
const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ?
|
|
11630
|
+
const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? import_node_path13.join(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
|
|
11159
11631
|
if (localAppData)
|
|
11160
|
-
push(
|
|
11632
|
+
push(import_node_path13.join(localAppData, "opencode", "auth.json"));
|
|
11161
11633
|
const userProfile = pickEnv(env, "USERPROFILE") || home;
|
|
11162
11634
|
if (userProfile)
|
|
11163
|
-
push(
|
|
11635
|
+
push(import_node_path13.join(userProfile, ".local", "share", "opencode", "auth.json"));
|
|
11164
11636
|
} else if (home) {
|
|
11165
|
-
push(
|
|
11637
|
+
push(import_node_path13.join(home, ".local", "share", "opencode", "auth.json"));
|
|
11166
11638
|
}
|
|
11167
11639
|
return out;
|
|
11168
11640
|
}
|
|
11169
11641
|
function resolveOpencodeAuthFile() {
|
|
11170
|
-
return resolveOpencodeAuthCandidates()[0] ??
|
|
11642
|
+
return resolveOpencodeAuthCandidates()[0] ?? import_node_path13.join(import_node_os9.homedir(), ".local", "share", "opencode", "auth.json");
|
|
11171
11643
|
}
|
|
11172
11644
|
function isValidOpencodeAuthFile(authFile) {
|
|
11173
11645
|
try {
|
|
11174
|
-
if (!authFile || !
|
|
11646
|
+
if (!authFile || !import_node_fs12.existsSync(authFile))
|
|
11175
11647
|
return false;
|
|
11176
|
-
const raw =
|
|
11648
|
+
const raw = import_node_fs12.readFileSync(authFile, "utf8").trim();
|
|
11177
11649
|
if (!raw)
|
|
11178
11650
|
return false;
|
|
11179
11651
|
const parsed = JSON.parse(raw);
|
|
@@ -11191,7 +11663,7 @@ function probeOpencodeAuth(overrides) {
|
|
|
11191
11663
|
for (const candidate of candidates) {
|
|
11192
11664
|
let exists = false;
|
|
11193
11665
|
try {
|
|
11194
|
-
exists =
|
|
11666
|
+
exists = import_node_fs12.existsSync(candidate);
|
|
11195
11667
|
} catch {
|
|
11196
11668
|
exists = false;
|
|
11197
11669
|
}
|
|
@@ -11204,10 +11676,10 @@ function probeOpencodeAuth(overrides) {
|
|
|
11204
11676
|
validFile = candidate;
|
|
11205
11677
|
}
|
|
11206
11678
|
const authFile = validFile ?? firstExisting ?? candidates[0] ?? resolveOpencodeAuthFile();
|
|
11207
|
-
const authDir =
|
|
11679
|
+
const authDir = import_node_path13.dirname(authFile);
|
|
11208
11680
|
let hasCodexHome = false;
|
|
11209
11681
|
try {
|
|
11210
|
-
hasCodexHome =
|
|
11682
|
+
hasCodexHome = import_node_fs12.existsSync(authDir);
|
|
11211
11683
|
} catch {
|
|
11212
11684
|
hasCodexHome = false;
|
|
11213
11685
|
}
|
|
@@ -11222,6 +11694,8 @@ function probeOpencodeAuth(overrides) {
|
|
|
11222
11694
|
}
|
|
11223
11695
|
var opencodeAdapter = {
|
|
11224
11696
|
id: "opencode",
|
|
11697
|
+
supportedBridgeVersions: ["1.18.35"],
|
|
11698
|
+
prepareAppResources: prepareOpenCodeResources,
|
|
11225
11699
|
probeAuth: () => probeOpencodeAuth(),
|
|
11226
11700
|
probeQuota: async () => probeOpencodeQuota(),
|
|
11227
11701
|
orderAuthMethods: (methods) => methods,
|
|
@@ -11232,6 +11706,7 @@ var opencodeAdapter = {
|
|
|
11232
11706
|
// src/runtimes/opencode-v2/index.ts
|
|
11233
11707
|
var opencodeV2Adapter = {
|
|
11234
11708
|
id: "opencode-v2",
|
|
11709
|
+
prepareAppResources: async ({ directory }) => prepareCompatibilityResources(directory, "native-config-entry-not-verified"),
|
|
11235
11710
|
probeAuth: () => probeOpencodeAuth(),
|
|
11236
11711
|
orderAuthMethods: (methods) => methods,
|
|
11237
11712
|
canSkipInteractiveAuth: () => false,
|
|
@@ -11261,27 +11736,27 @@ async function probeCursorQuota() {
|
|
|
11261
11736
|
};
|
|
11262
11737
|
}
|
|
11263
11738
|
// src/runtimes/cursor/index.ts
|
|
11264
|
-
var
|
|
11265
|
-
var
|
|
11266
|
-
var
|
|
11739
|
+
var import_node_fs13 = require("node:fs");
|
|
11740
|
+
var import_node_os10 = require("node:os");
|
|
11741
|
+
var import_node_path14 = require("node:path");
|
|
11267
11742
|
function cursorLocalAppData(env) {
|
|
11268
11743
|
const local = env.LOCALAPPDATA?.trim();
|
|
11269
11744
|
if (local)
|
|
11270
11745
|
return local;
|
|
11271
11746
|
const profile = env.USERPROFILE?.trim();
|
|
11272
|
-
return profile ?
|
|
11747
|
+
return profile ? import_node_path14.join(profile, "AppData", "Local") : "";
|
|
11273
11748
|
}
|
|
11274
11749
|
function isOnPath(command, env, platform) {
|
|
11275
11750
|
const pathValue = env.PATH ?? env.Path ?? "";
|
|
11276
11751
|
if (!pathValue.trim())
|
|
11277
11752
|
return false;
|
|
11278
|
-
const sep = platform === "win32" ? ";" :
|
|
11753
|
+
const sep = platform === "win32" ? ";" : import_node_path14.delimiter;
|
|
11279
11754
|
for (const dir of pathValue.split(sep)) {
|
|
11280
11755
|
const trimmed = dir.trim().replace(/^"|"$/g, "");
|
|
11281
11756
|
if (!trimmed)
|
|
11282
11757
|
continue;
|
|
11283
11758
|
try {
|
|
11284
|
-
if (
|
|
11759
|
+
if (import_node_fs13.existsSync(import_node_path14.join(trimmed, command)))
|
|
11285
11760
|
return true;
|
|
11286
11761
|
} catch {}
|
|
11287
11762
|
}
|
|
@@ -11290,19 +11765,19 @@ function isOnPath(command, env, platform) {
|
|
|
11290
11765
|
function resolveDirectCursorCommand(platform, env, home) {
|
|
11291
11766
|
if (platform === "win32") {
|
|
11292
11767
|
const localAppData = cursorLocalAppData(env);
|
|
11293
|
-
return localAppData ?
|
|
11768
|
+
return localAppData ? import_node_path14.join(localAppData, "cursor-agent", "agent.cmd") : "";
|
|
11294
11769
|
}
|
|
11295
|
-
return home ?
|
|
11770
|
+
return home ? import_node_path14.join(home, ".local", "bin", "agent") : "";
|
|
11296
11771
|
}
|
|
11297
11772
|
function resolveCursorSpawnCommand(overrides) {
|
|
11298
11773
|
const args = ["acp"];
|
|
11299
11774
|
const platform = overrides?.platform ?? process.platform;
|
|
11300
11775
|
const env = overrides?.env ?? process.env;
|
|
11301
|
-
const home = overrides?.home ??
|
|
11776
|
+
const home = overrides?.home ?? import_node_os10.homedir();
|
|
11302
11777
|
const binary = platform === "win32" ? "agent.cmd" : "agent";
|
|
11303
11778
|
const direct = resolveDirectCursorCommand(platform, env, home);
|
|
11304
11779
|
try {
|
|
11305
|
-
if (direct &&
|
|
11780
|
+
if (direct && import_node_fs13.existsSync(direct))
|
|
11306
11781
|
return { command: direct, args };
|
|
11307
11782
|
} catch {}
|
|
11308
11783
|
if (isOnPath(binary, env, platform))
|
|
@@ -11317,12 +11792,12 @@ function cursorRoamingAppData(env, home) {
|
|
|
11317
11792
|
if (roaming)
|
|
11318
11793
|
return roaming;
|
|
11319
11794
|
const profile = pickEnv2(env, "USERPROFILE") || home;
|
|
11320
|
-
return profile ?
|
|
11795
|
+
return profile ? import_node_path14.join(profile, "AppData", "Roaming") : "";
|
|
11321
11796
|
}
|
|
11322
11797
|
function resolveCursorAuthCandidates(overrides) {
|
|
11323
11798
|
const platform = overrides?.platform ?? process.platform;
|
|
11324
11799
|
const env = overrides?.env ?? process.env;
|
|
11325
|
-
const home = overrides?.home ??
|
|
11800
|
+
const home = overrides?.home ?? import_node_os10.homedir();
|
|
11326
11801
|
const seen = new Set;
|
|
11327
11802
|
const out = [];
|
|
11328
11803
|
const push = (p) => {
|
|
@@ -11333,16 +11808,16 @@ function resolveCursorAuthCandidates(overrides) {
|
|
|
11333
11808
|
};
|
|
11334
11809
|
const xdg = pickEnv2(env, "XDG_CONFIG_HOME");
|
|
11335
11810
|
if (xdg)
|
|
11336
|
-
push(
|
|
11811
|
+
push(import_node_path14.join(xdg, "cursor", "auth.json"));
|
|
11337
11812
|
if (platform === "win32") {
|
|
11338
11813
|
const profile = pickEnv2(env, "USERPROFILE") || home;
|
|
11339
11814
|
if (profile)
|
|
11340
|
-
push(
|
|
11815
|
+
push(import_node_path14.join(profile, ".config", "cursor", "auth.json"));
|
|
11341
11816
|
const roaming = cursorRoamingAppData(env, home);
|
|
11342
11817
|
if (roaming)
|
|
11343
|
-
push(
|
|
11818
|
+
push(import_node_path14.join(roaming, "Cursor", "User", "globalStorage", "storage.json"));
|
|
11344
11819
|
} else if (home) {
|
|
11345
|
-
push(
|
|
11820
|
+
push(import_node_path14.join(home, ".config", "cursor", "auth.json"));
|
|
11346
11821
|
}
|
|
11347
11822
|
return out;
|
|
11348
11823
|
}
|
|
@@ -11353,9 +11828,9 @@ function isValidCursorAuthFile(authFile) {
|
|
|
11353
11828
|
try {
|
|
11354
11829
|
if (!authFile || isStorageHintPath(authFile))
|
|
11355
11830
|
return false;
|
|
11356
|
-
if (!
|
|
11831
|
+
if (!import_node_fs13.existsSync(authFile))
|
|
11357
11832
|
return false;
|
|
11358
|
-
const raw =
|
|
11833
|
+
const raw = import_node_fs13.readFileSync(authFile, "utf8").trim();
|
|
11359
11834
|
if (!raw)
|
|
11360
11835
|
return false;
|
|
11361
11836
|
const parsed = JSON.parse(raw);
|
|
@@ -11373,9 +11848,9 @@ function isHintCursorStorageFile(authFile) {
|
|
|
11373
11848
|
try {
|
|
11374
11849
|
if (!authFile || !isStorageHintPath(authFile))
|
|
11375
11850
|
return false;
|
|
11376
|
-
if (!
|
|
11851
|
+
if (!import_node_fs13.existsSync(authFile))
|
|
11377
11852
|
return false;
|
|
11378
|
-
const raw =
|
|
11853
|
+
const raw = import_node_fs13.readFileSync(authFile, "utf8").trim();
|
|
11379
11854
|
if (!raw)
|
|
11380
11855
|
return false;
|
|
11381
11856
|
const parsed = JSON.parse(raw);
|
|
@@ -11391,7 +11866,7 @@ function isValidCursorCandidate(authFile) {
|
|
|
11391
11866
|
}
|
|
11392
11867
|
function probeCursorAuth(overrides) {
|
|
11393
11868
|
const env = overrides?.env ?? process.env;
|
|
11394
|
-
const home = overrides?.home ??
|
|
11869
|
+
const home = overrides?.home ?? import_node_os10.homedir();
|
|
11395
11870
|
const hasApiKeyEnv = Boolean(env.CURSOR_API_KEY?.trim() || env.CURSOR_AUTH_TOKEN?.trim());
|
|
11396
11871
|
const candidates = resolveCursorAuthCandidates(overrides);
|
|
11397
11872
|
let firstExisting = null;
|
|
@@ -11399,7 +11874,7 @@ function probeCursorAuth(overrides) {
|
|
|
11399
11874
|
for (const candidate of candidates) {
|
|
11400
11875
|
let exists = false;
|
|
11401
11876
|
try {
|
|
11402
|
-
exists =
|
|
11877
|
+
exists = import_node_fs13.existsSync(candidate);
|
|
11403
11878
|
} catch {
|
|
11404
11879
|
exists = false;
|
|
11405
11880
|
}
|
|
@@ -11411,12 +11886,12 @@ function probeCursorAuth(overrides) {
|
|
|
11411
11886
|
if (isValidCursorCandidate(candidate))
|
|
11412
11887
|
validFile = candidate;
|
|
11413
11888
|
}
|
|
11414
|
-
const fallback = home ?
|
|
11889
|
+
const fallback = home ? import_node_path14.join(home, ".config", "cursor", "auth.json") : "";
|
|
11415
11890
|
const authFile = validFile ?? firstExisting ?? candidates[0] ?? fallback;
|
|
11416
|
-
const authDir = authFile ?
|
|
11891
|
+
const authDir = authFile ? import_node_path14.dirname(authFile) : "";
|
|
11417
11892
|
let hasCodexHome = false;
|
|
11418
11893
|
try {
|
|
11419
|
-
hasCodexHome = authDir ?
|
|
11894
|
+
hasCodexHome = authDir ? import_node_fs13.existsSync(authDir) : false;
|
|
11420
11895
|
} catch {
|
|
11421
11896
|
hasCodexHome = false;
|
|
11422
11897
|
}
|
|
@@ -11430,6 +11905,7 @@ function probeCursorAuth(overrides) {
|
|
|
11430
11905
|
}
|
|
11431
11906
|
var cursorAdapter = {
|
|
11432
11907
|
id: "cursor-cli",
|
|
11908
|
+
prepareAppResources: async ({ directory }) => prepareCompatibilityResources(directory, "config-home-does-not-guarantee-rules"),
|
|
11433
11909
|
probeAuth: () => probeCursorAuth(),
|
|
11434
11910
|
probeQuota: async () => probeCursorQuota(),
|
|
11435
11911
|
resolveSpawnCommand: () => resolveCursorSpawnCommand(),
|
|
@@ -11478,6 +11954,7 @@ function probeDeepseekAuth() {
|
|
|
11478
11954
|
}
|
|
11479
11955
|
var deepseekAdapter = {
|
|
11480
11956
|
id: "deepseek",
|
|
11957
|
+
prepareAppResources: async ({ directory }) => prepareCompatibilityResources(directory, "native-config-entry-not-verified"),
|
|
11481
11958
|
probeAuth: () => probeDeepseekAuth(),
|
|
11482
11959
|
resolveSpawnCommand: () => resolveDeepseekSpawnCommand(),
|
|
11483
11960
|
resolveSpawnBlocker: () => resolveDeepseekSpawnBlocker(),
|
|
@@ -11486,13 +11963,13 @@ var deepseekAdapter = {
|
|
|
11486
11963
|
};
|
|
11487
11964
|
|
|
11488
11965
|
// src/runtimes/agy/quota.ts
|
|
11489
|
-
var
|
|
11490
|
-
var
|
|
11491
|
-
var
|
|
11966
|
+
var import_node_fs14 = require("node:fs");
|
|
11967
|
+
var import_node_path15 = require("node:path");
|
|
11968
|
+
var import_node_child_process5 = require("node:child_process");
|
|
11492
11969
|
var os2 = __toESM(require("node:os"), 1);
|
|
11493
11970
|
function resolveGeminiHome2() {
|
|
11494
11971
|
const home = process.env.USERPROFILE || process.env.HOME || "";
|
|
11495
|
-
return
|
|
11972
|
+
return import_node_path15.join(home, ".gemini");
|
|
11496
11973
|
}
|
|
11497
11974
|
function resolveAntigravityAccount() {
|
|
11498
11975
|
if (process.env.GOOGLE_ACCOUNT?.trim()) {
|
|
@@ -11505,14 +11982,14 @@ function resolveAntigravityAccount() {
|
|
|
11505
11982
|
}
|
|
11506
11983
|
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
11507
11984
|
const candidates = [
|
|
11508
|
-
process.env.APPDATA ?
|
|
11509
|
-
|
|
11510
|
-
|
|
11985
|
+
process.env.APPDATA ? import_node_path15.join(process.env.APPDATA, "Antigravity", "app_storage.json") : null,
|
|
11986
|
+
import_node_path15.join(home, ".config", "Antigravity", "app_storage.json"),
|
|
11987
|
+
import_node_path15.join(home, "Library", "Application Support", "Antigravity", "app_storage.json")
|
|
11511
11988
|
].filter(Boolean);
|
|
11512
11989
|
for (const file of candidates) {
|
|
11513
11990
|
try {
|
|
11514
|
-
if (
|
|
11515
|
-
const raw =
|
|
11991
|
+
if (import_node_fs14.existsSync(file)) {
|
|
11992
|
+
const raw = import_node_fs14.readFileSync(file, "utf8");
|
|
11516
11993
|
const json = JSON.parse(raw);
|
|
11517
11994
|
const username = json["jetski.onboarding.lastLoginUsername"];
|
|
11518
11995
|
if (username && typeof username === "string" && username.trim()) {
|
|
@@ -11533,30 +12010,30 @@ function resolveAntigravityAccount() {
|
|
|
11533
12010
|
}
|
|
11534
12011
|
function resolveAntigravityLanguageServer() {
|
|
11535
12012
|
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
11536
|
-
const appData = process.env.APPDATA || (process.platform === "win32" ?
|
|
12013
|
+
const appData = process.env.APPDATA || (process.platform === "win32" ? import_node_path15.join(home, "AppData", "Roaming") : "");
|
|
11537
12014
|
const baseDirs = [
|
|
11538
|
-
appData ?
|
|
11539
|
-
appData ?
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
12015
|
+
appData ? import_node_path15.join(appData, "Antigravity IDE", "logs") : null,
|
|
12016
|
+
appData ? import_node_path15.join(appData, "Antigravity", "logs") : null,
|
|
12017
|
+
import_node_path15.join(home, ".config", "Antigravity IDE", "logs"),
|
|
12018
|
+
import_node_path15.join(home, ".config", "Antigravity", "logs"),
|
|
12019
|
+
import_node_path15.join(home, "Library", "Application Support", "Antigravity IDE", "logs"),
|
|
12020
|
+
import_node_path15.join(home, "Library", "Application Support", "Antigravity", "logs")
|
|
11544
12021
|
].filter(Boolean);
|
|
11545
12022
|
for (const base of baseDirs) {
|
|
11546
12023
|
try {
|
|
11547
|
-
if (!
|
|
12024
|
+
if (!import_node_fs14.existsSync(base))
|
|
11548
12025
|
continue;
|
|
11549
|
-
const sessionDirs =
|
|
12026
|
+
const sessionDirs = import_node_fs14.readdirSync(base).map((d) => {
|
|
11550
12027
|
try {
|
|
11551
|
-
return { name: d, time:
|
|
12028
|
+
return { name: d, time: import_node_fs14.statSync(import_node_path15.join(base, d)).mtimeMs };
|
|
11552
12029
|
} catch {
|
|
11553
12030
|
return null;
|
|
11554
12031
|
}
|
|
11555
12032
|
}).filter((d) => Boolean(d)).sort((a, b) => b.time - a.time);
|
|
11556
12033
|
for (const s of sessionDirs) {
|
|
11557
|
-
const logFile =
|
|
11558
|
-
if (
|
|
11559
|
-
const content =
|
|
12034
|
+
const logFile = import_node_path15.join(base, s.name, "ls-main.log");
|
|
12035
|
+
if (import_node_fs14.existsSync(logFile)) {
|
|
12036
|
+
const content = import_node_fs14.readFileSync(logFile, "utf8");
|
|
11560
12037
|
const csrfMatch = content.match(/--csrf_token\s+([a-f0-9\-]+)/);
|
|
11561
12038
|
const portMatch = content.match(/LS started on port\s+(\d+)/) || content.match(/--https_server_port\s+(\d+)/);
|
|
11562
12039
|
if (csrfMatch && portMatch) {
|
|
@@ -11572,13 +12049,13 @@ function resolveAntigravityLanguageServer() {
|
|
|
11572
12049
|
try {
|
|
11573
12050
|
let out = "";
|
|
11574
12051
|
if (process.platform === "win32") {
|
|
11575
|
-
out =
|
|
12052
|
+
out = import_node_child_process5.execFileSync("powershell", [
|
|
11576
12053
|
"-NoProfile",
|
|
11577
12054
|
"-Command",
|
|
11578
12055
|
`Get-CimInstance Win32_Process -Filter "Name like '%language_server%'" | Select-Object -ExpandProperty CommandLine`
|
|
11579
12056
|
], { encoding: "utf8", timeout: 4000, windowsHide: true });
|
|
11580
12057
|
} else {
|
|
11581
|
-
out =
|
|
12058
|
+
out = import_node_child_process5.execFileSync("ps", ["aux"], { encoding: "utf8", timeout: 4000 });
|
|
11582
12059
|
}
|
|
11583
12060
|
const lines = out.split(/\r?\n/);
|
|
11584
12061
|
for (const l of lines) {
|
|
@@ -11615,7 +12092,7 @@ async function probeAgyQuota(options) {
|
|
|
11615
12092
|
}
|
|
11616
12093
|
} catch {
|
|
11617
12094
|
try {
|
|
11618
|
-
const raw =
|
|
12095
|
+
const raw = import_node_child_process5.execFileSync(process.platform === "win32" ? "curl.exe" : "curl", [
|
|
11619
12096
|
"-k",
|
|
11620
12097
|
"-s",
|
|
11621
12098
|
"-X",
|
|
@@ -11713,7 +12190,7 @@ async function probeAgyQuota(options) {
|
|
|
11713
12190
|
} catch {}
|
|
11714
12191
|
}
|
|
11715
12192
|
const geminiHome = resolveGeminiHome2();
|
|
11716
|
-
const hasAgyDir =
|
|
12193
|
+
const hasAgyDir = import_node_fs14.existsSync(import_node_path15.join(geminiHome, "antigravity")) || import_node_fs14.existsSync(import_node_path15.join(geminiHome, "antigravity-cli"));
|
|
11717
12194
|
const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
|
|
11718
12195
|
const isAvailable = hasAgyDir || hasApiKey || Boolean(acc.email || acc.name);
|
|
11719
12196
|
if (!isAvailable) {
|
|
@@ -11785,6 +12262,12 @@ function probeAgyAuth() {
|
|
|
11785
12262
|
}
|
|
11786
12263
|
var agyAdapter = {
|
|
11787
12264
|
id: "agy",
|
|
12265
|
+
prepareAppResources: async ({ directory }) => {
|
|
12266
|
+
const prep = prepareCompatibilityResources(directory, "native-session-version-not-verified");
|
|
12267
|
+
return { ...prep, env: { AGY_ACP_RESOURCES_DIR: directory }, report: { ...prep.report, rulesPrepared: prep.report.rulesChars > 0 } };
|
|
12268
|
+
},
|
|
12269
|
+
appResourceSessionMeta: (directory) => ({ appResources: { directory } }),
|
|
12270
|
+
supportedBridgeVersions: ["0.1.24"],
|
|
11788
12271
|
probeAuth: () => probeAgyAuth(),
|
|
11789
12272
|
probeQuota: (options) => probeAgyQuota(options),
|
|
11790
12273
|
orderAuthMethods: (methods) => methods,
|
|
@@ -11824,7 +12307,10 @@ function getAcpRuntimeAdapter(runtimeId) {
|
|
|
11824
12307
|
}
|
|
11825
12308
|
|
|
11826
12309
|
// src/process/process-manager.ts
|
|
11827
|
-
var
|
|
12310
|
+
var import_node_child_process6 = require("node:child_process");
|
|
12311
|
+
function processKey(runtimeId, scopeKey) {
|
|
12312
|
+
return scopeKey ? `${scopeKey}:${runtimeId}` : runtimeId;
|
|
12313
|
+
}
|
|
11828
12314
|
var active = new Map;
|
|
11829
12315
|
var ACP_EARLY_EXIT_STDERR_TAIL_LINES = 20;
|
|
11830
12316
|
function isSpawnedAcpProcessAlive(handle) {
|
|
@@ -11835,7 +12321,7 @@ function killProcessTree(pid) {
|
|
|
11835
12321
|
if (process.platform !== "win32")
|
|
11836
12322
|
return;
|
|
11837
12323
|
try {
|
|
11838
|
-
|
|
12324
|
+
import_node_child_process6.spawnSync("taskkill", ["/F", "/T", "/PID", String(pid)], {
|
|
11839
12325
|
windowsHide: true,
|
|
11840
12326
|
timeout: 8000
|
|
11841
12327
|
});
|
|
@@ -11855,7 +12341,8 @@ function spawnAcpProcess(options) {
|
|
|
11855
12341
|
if (!options.runtime?.id || !options.runtime.command || !Array.isArray(options.runtime.args)) {
|
|
11856
12342
|
throw new Error(`ACP 运行时模板缺失 command/args: ${options.runtime?.id ?? "(empty)"}`);
|
|
11857
12343
|
}
|
|
11858
|
-
const
|
|
12344
|
+
const key = processKey(options.runtime.id, options.scopeKey);
|
|
12345
|
+
const existing = active.get(key);
|
|
11859
12346
|
if (existing) {
|
|
11860
12347
|
existing.kill();
|
|
11861
12348
|
}
|
|
@@ -11878,7 +12365,7 @@ function spawnAcpProcess(options) {
|
|
|
11878
12365
|
} else {
|
|
11879
12366
|
delete env.NO_BROWSER;
|
|
11880
12367
|
}
|
|
11881
|
-
const child =
|
|
12368
|
+
const child = import_node_child_process6.spawn(file, options.runtime.args, {
|
|
11882
12369
|
cwd: options.cwd,
|
|
11883
12370
|
env,
|
|
11884
12371
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -11916,6 +12403,9 @@ function spawnAcpProcess(options) {
|
|
|
11916
12403
|
});
|
|
11917
12404
|
const handle = {
|
|
11918
12405
|
runtimeId: options.runtime.id,
|
|
12406
|
+
scopeKey: options.scopeKey,
|
|
12407
|
+
executionContext: options.executionContext,
|
|
12408
|
+
profileTag: options.profileTag ?? null,
|
|
11919
12409
|
child,
|
|
11920
12410
|
spawnedAt: Date.now(),
|
|
11921
12411
|
stderrTail,
|
|
@@ -11933,7 +12423,7 @@ function spawnAcpProcess(options) {
|
|
|
11933
12423
|
} catch {}
|
|
11934
12424
|
}
|
|
11935
12425
|
}
|
|
11936
|
-
active.delete(
|
|
12426
|
+
active.delete(key);
|
|
11937
12427
|
}
|
|
11938
12428
|
};
|
|
11939
12429
|
child.on("exit", (code, signal) => {
|
|
@@ -11941,12 +12431,43 @@ function spawnAcpProcess(options) {
|
|
|
11941
12431
|
if (rest)
|
|
11942
12432
|
pushStderrTailLine(rest);
|
|
11943
12433
|
stderrBuffer = "";
|
|
11944
|
-
active.
|
|
12434
|
+
if (active.get(key) === handle)
|
|
12435
|
+
active.delete(key);
|
|
11945
12436
|
options.onExit?.(code, signal);
|
|
11946
12437
|
});
|
|
11947
|
-
active.set(
|
|
12438
|
+
active.set(key, handle);
|
|
12439
|
+
return handle;
|
|
12440
|
+
}
|
|
12441
|
+
function getLiveAcpProcess(runtimeId, query = {}) {
|
|
12442
|
+
const key = processKey(runtimeId, query.scopeKey);
|
|
12443
|
+
const handle = active.get(key);
|
|
12444
|
+
if (!handle)
|
|
12445
|
+
return;
|
|
12446
|
+
if (!isSpawnedAcpProcessAlive(handle)) {
|
|
12447
|
+
active.delete(key);
|
|
12448
|
+
return;
|
|
12449
|
+
}
|
|
12450
|
+
if (query.executionContext !== undefined && (handle.executionContext ?? null) !== query.executionContext) {
|
|
12451
|
+
return;
|
|
12452
|
+
}
|
|
12453
|
+
if (query.expectedTag !== undefined && (handle.profileTag ?? null) !== query.expectedTag)
|
|
12454
|
+
return;
|
|
11948
12455
|
return handle;
|
|
11949
12456
|
}
|
|
12457
|
+
function tryReuseLiveAcpProcess(runtimeId, query = {}) {
|
|
12458
|
+
const hit = getLiveAcpProcess(runtimeId, query);
|
|
12459
|
+
if (hit)
|
|
12460
|
+
return { status: "hit", handle: hit };
|
|
12461
|
+
if (query.expectedTag === undefined)
|
|
12462
|
+
return { status: "miss" };
|
|
12463
|
+
const stale = getLiveAcpProcess(runtimeId, { scopeKey: query.scopeKey, executionContext: query.executionContext });
|
|
12464
|
+
if (!stale)
|
|
12465
|
+
return { status: "miss" };
|
|
12466
|
+
if (query.isBusy?.(stale))
|
|
12467
|
+
return { status: "busy", handle: stale };
|
|
12468
|
+
stale.kill();
|
|
12469
|
+
return { status: "miss" };
|
|
12470
|
+
}
|
|
11950
12471
|
|
|
11951
12472
|
// src/client/sdk-client.ts
|
|
11952
12473
|
var import_node_stream = require("node:stream");
|
|
@@ -12013,18 +12534,18 @@ async function sdkRequest(agent, method, params, timeoutMs = ACP_SDK_REQUEST_TIM
|
|
|
12013
12534
|
}
|
|
12014
12535
|
|
|
12015
12536
|
// src/client/acp-fs.ts
|
|
12016
|
-
var import_promises3 = require("node:fs/promises");
|
|
12017
|
-
var import_node_path13 = require("node:path");
|
|
12018
12537
|
var import_promises4 = require("node:fs/promises");
|
|
12538
|
+
var import_node_path16 = require("node:path");
|
|
12539
|
+
var import_promises5 = require("node:fs/promises");
|
|
12019
12540
|
var MAX_READ_BYTES = 2 * 1024 * 1024;
|
|
12020
12541
|
var BINARY_DOCUMENT_EXTENSIONS = new Set([".epub", ".mobi", ".azw", ".azw3", ".pdf"]);
|
|
12021
12542
|
function isBinaryDocumentPath(filePath) {
|
|
12022
|
-
return BINARY_DOCUMENT_EXTENSIONS.has(
|
|
12543
|
+
return BINARY_DOCUMENT_EXTENSIONS.has(import_node_path16.extname(filePath).toLowerCase());
|
|
12023
12544
|
}
|
|
12024
12545
|
function assertPathInsideWorkspace(filePath, workspaceRoot) {
|
|
12025
|
-
const root =
|
|
12026
|
-
const target =
|
|
12027
|
-
const rootWithSep = root.endsWith(
|
|
12546
|
+
const root = import_node_path16.resolve(workspaceRoot);
|
|
12547
|
+
const target = import_node_path16.resolve(filePath);
|
|
12548
|
+
const rootWithSep = root.endsWith(import_node_path16.sep) ? root : root + import_node_path16.sep;
|
|
12028
12549
|
if (target !== root && !target.startsWith(rootWithSep)) {
|
|
12029
12550
|
throw new Error(`路径不在工作区内: ${filePath}`);
|
|
12030
12551
|
}
|
|
@@ -12035,8 +12556,8 @@ async function acpReadTextFile(params) {
|
|
|
12035
12556
|
throw new Error(`Inkdown 拒绝按文本读取电子书/PDF:${params.path}。` + "该格式已由客户端解析,请改为向用户索取所需的章节、目录或视口文本。");
|
|
12036
12557
|
}
|
|
12037
12558
|
const abs = assertPathInsideWorkspace(params.path, params.workspaceRoot);
|
|
12038
|
-
await
|
|
12039
|
-
let content = await
|
|
12559
|
+
await import_promises4.access(abs);
|
|
12560
|
+
let content = await import_promises4.readFile(abs, "utf-8");
|
|
12040
12561
|
if (Buffer.byteLength(content, "utf-8") > MAX_READ_BYTES) {
|
|
12041
12562
|
content = content.slice(0, Math.floor(MAX_READ_BYTES / 2));
|
|
12042
12563
|
content += `
|
|
@@ -12055,8 +12576,8 @@ async function acpReadTextFile(params) {
|
|
|
12055
12576
|
}
|
|
12056
12577
|
async function acpWriteTextFile(params) {
|
|
12057
12578
|
const abs = assertPathInsideWorkspace(params.path, params.workspaceRoot);
|
|
12058
|
-
await
|
|
12059
|
-
await
|
|
12579
|
+
await import_promises5.mkdir(import_node_path16.dirname(abs), { recursive: true });
|
|
12580
|
+
await import_promises4.writeFile(abs, params.content, "utf-8");
|
|
12060
12581
|
return {};
|
|
12061
12582
|
}
|
|
12062
12583
|
|
|
@@ -12383,6 +12904,25 @@ function isTransientAcpTransportError(error) {
|
|
|
12383
12904
|
async function restoreOrCreateAcpSession(input) {
|
|
12384
12905
|
const resumeId = input.resumeSessionId?.trim() || null;
|
|
12385
12906
|
const restoreAttempts = [];
|
|
12907
|
+
let mcpServersAccepted = (input.mcpServers ?? []).length > 0;
|
|
12908
|
+
let nativeSessionAccepted = false;
|
|
12909
|
+
const request = async (method, params) => {
|
|
12910
|
+
if (!input.sessionMeta)
|
|
12911
|
+
return input.request(method, params);
|
|
12912
|
+
try {
|
|
12913
|
+
const result = await input.request(method, { ...params, _meta: input.sessionMeta });
|
|
12914
|
+
nativeSessionAccepted = true;
|
|
12915
|
+
return result;
|
|
12916
|
+
} catch (error) {
|
|
12917
|
+
const rejected = error instanceof RequestError && error.code === -32602 || /native.*meta.*reject|unsupported.*(meta|systemPrompt)|unknown.*(meta|systemPrompt)/i.test(errorMessage(error));
|
|
12918
|
+
if (!rejected || isTransientAcpTransportError(error))
|
|
12919
|
+
throw error;
|
|
12920
|
+
log("warn", "native resource options failed; retry without extension");
|
|
12921
|
+
const result = await input.request(method, params);
|
|
12922
|
+
nativeSessionAccepted = false;
|
|
12923
|
+
return result;
|
|
12924
|
+
}
|
|
12925
|
+
};
|
|
12386
12926
|
const delayMs = input.retryDelayMs ?? 250;
|
|
12387
12927
|
const log = input.log ?? ((level, message, data) => {
|
|
12388
12928
|
if (level === "info" && false)
|
|
@@ -12404,7 +12944,7 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
12404
12944
|
maxTries
|
|
12405
12945
|
});
|
|
12406
12946
|
try {
|
|
12407
|
-
const result = await
|
|
12947
|
+
const result = await request(rpcMethod, {
|
|
12408
12948
|
sessionId: resumeId,
|
|
12409
12949
|
cwd: input.cwd,
|
|
12410
12950
|
mcpServers: input.mcpServers ?? []
|
|
@@ -12443,7 +12983,7 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
12443
12983
|
mcpServers: input.mcpServers ?? []
|
|
12444
12984
|
};
|
|
12445
12985
|
try {
|
|
12446
|
-
return await
|
|
12986
|
+
return await request("session/new", baseParams);
|
|
12447
12987
|
} catch (firstError) {
|
|
12448
12988
|
if ((input.mcpServers ?? []).length === 0)
|
|
12449
12989
|
throw firstError;
|
|
@@ -12451,10 +12991,12 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
12451
12991
|
error: errorMessage(firstError)
|
|
12452
12992
|
});
|
|
12453
12993
|
try {
|
|
12454
|
-
|
|
12994
|
+
const result = await request("session/new", {
|
|
12455
12995
|
cwd: input.cwd,
|
|
12456
12996
|
mcpServers: []
|
|
12457
12997
|
});
|
|
12998
|
+
mcpServersAccepted = false;
|
|
12999
|
+
return result;
|
|
12458
13000
|
} catch {
|
|
12459
13001
|
throw firstError;
|
|
12460
13002
|
}
|
|
@@ -12470,6 +13012,8 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
12470
13012
|
configOptions: withModelsFallback(resumed),
|
|
12471
13013
|
restoreMethod: "resume",
|
|
12472
13014
|
sessionRestored: true,
|
|
13015
|
+
mcpServersAccepted,
|
|
13016
|
+
nativeSessionAccepted,
|
|
12473
13017
|
requestedSessionId: resumeId,
|
|
12474
13018
|
restoreAttempts
|
|
12475
13019
|
};
|
|
@@ -12488,6 +13032,8 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
12488
13032
|
configOptions: withModelsFallback(loaded),
|
|
12489
13033
|
restoreMethod: "load",
|
|
12490
13034
|
sessionRestored: true,
|
|
13035
|
+
mcpServersAccepted,
|
|
13036
|
+
nativeSessionAccepted,
|
|
12491
13037
|
requestedSessionId: resumeId,
|
|
12492
13038
|
restoreAttempts
|
|
12493
13039
|
};
|
|
@@ -12509,14 +13055,16 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
12509
13055
|
configOptions: withModelsFallback(sessionResult),
|
|
12510
13056
|
restoreMethod: "new",
|
|
12511
13057
|
sessionRestored: false,
|
|
13058
|
+
mcpServersAccepted,
|
|
13059
|
+
nativeSessionAccepted,
|
|
12512
13060
|
requestedSessionId: resumeId ?? undefined,
|
|
12513
13061
|
restoreAttempts
|
|
12514
13062
|
};
|
|
12515
13063
|
}
|
|
12516
13064
|
|
|
12517
13065
|
// src/client/acp-terminal.ts
|
|
12518
|
-
var
|
|
12519
|
-
var
|
|
13066
|
+
var import_node_child_process7 = require("node:child_process");
|
|
13067
|
+
var import_node_crypto3 = require("node:crypto");
|
|
12520
13068
|
|
|
12521
13069
|
// src/transport/terminal-output-buffer.ts
|
|
12522
13070
|
function truncateOutputFromStart(text, byteLimit) {
|
|
@@ -12568,14 +13116,14 @@ class AcpTerminalManager {
|
|
|
12568
13116
|
throw new Error("terminal/create 需要 command");
|
|
12569
13117
|
const cwd = resolveCwd(params.cwd, params.workspaceRoot);
|
|
12570
13118
|
const outputByteLimit = typeof params.outputByteLimit === "number" && params.outputByteLimit > 0 ? params.outputByteLimit : DEFAULT_OUTPUT_BYTE_LIMIT;
|
|
12571
|
-
const child =
|
|
13119
|
+
const child = import_node_child_process7.spawn(command, params.args ?? [], {
|
|
12572
13120
|
cwd,
|
|
12573
13121
|
env: buildEnv(params.env),
|
|
12574
13122
|
windowsHide: true,
|
|
12575
13123
|
shell: false,
|
|
12576
13124
|
stdio: ["ignore", "pipe", "pipe"]
|
|
12577
13125
|
});
|
|
12578
|
-
const id = `term_${
|
|
13126
|
+
const id = `term_${import_node_crypto3.randomUUID().replace(/-/g, "").slice(0, 12)}`;
|
|
12579
13127
|
const record = {
|
|
12580
13128
|
id,
|
|
12581
13129
|
sessionId: params.sessionId,
|
|
@@ -12664,7 +13212,7 @@ class AcpTerminalManager {
|
|
|
12664
13212
|
return;
|
|
12665
13213
|
if (process.platform === "win32") {
|
|
12666
13214
|
try {
|
|
12667
|
-
|
|
13215
|
+
import_node_child_process7.spawn("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
12668
13216
|
windowsHide: true,
|
|
12669
13217
|
stdio: "ignore"
|
|
12670
13218
|
});
|
|
@@ -12699,9 +13247,9 @@ class AcpTerminalManager {
|
|
|
12699
13247
|
}
|
|
12700
13248
|
|
|
12701
13249
|
// src/client/acp-proxy-service.ts
|
|
12702
|
-
var
|
|
12703
|
-
var
|
|
12704
|
-
var
|
|
13250
|
+
var import_promises6 = require("node:fs/promises");
|
|
13251
|
+
var import_node_fs15 = require("node:fs");
|
|
13252
|
+
var import_node_path17 = require("node:path");
|
|
12705
13253
|
var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
12706
13254
|
enabled: false,
|
|
12707
13255
|
host: "127.0.0.1",
|
|
@@ -12710,14 +13258,14 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
|
12710
13258
|
var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
|
|
12711
13259
|
var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
|
|
12712
13260
|
function proxyFilePath(dir) {
|
|
12713
|
-
return
|
|
13261
|
+
return import_node_path17.join(dir, "agent", "proxy.json");
|
|
12714
13262
|
}
|
|
12715
13263
|
async function readAcpProxySettings(dir = getDefaultAgentDataDir()) {
|
|
12716
13264
|
const file = proxyFilePath(dir);
|
|
12717
|
-
if (!
|
|
13265
|
+
if (!import_node_fs15.existsSync(file))
|
|
12718
13266
|
return { ...DEFAULT_ACP_PROXY_SETTINGS };
|
|
12719
13267
|
try {
|
|
12720
|
-
const raw = JSON.parse(await
|
|
13268
|
+
const raw = JSON.parse(await import_promises6.readFile(file, "utf8"));
|
|
12721
13269
|
return {
|
|
12722
13270
|
enabled: raw.enabled === true,
|
|
12723
13271
|
host: typeof raw.host === "string" && raw.host.trim() ? raw.host : DEFAULT_ACP_PROXY_SETTINGS.host,
|
|
@@ -12746,6 +13294,109 @@ function buildAcpProxySpawnEnv(settings) {
|
|
|
12746
13294
|
};
|
|
12747
13295
|
}
|
|
12748
13296
|
|
|
13297
|
+
// src/session/compat-guide.ts
|
|
13298
|
+
var COMPAT_CONTEXT_TAG = "acp-compat-context";
|
|
13299
|
+
function shortDigest(digest) {
|
|
13300
|
+
return digest ? digest.slice(0, 16) : "none";
|
|
13301
|
+
}
|
|
13302
|
+
function buildCompatGuideText(input) {
|
|
13303
|
+
const hasRules = (input.rulesText ?? "").trim() !== "";
|
|
13304
|
+
const hasSkills = input.skills.length > 0;
|
|
13305
|
+
if (!hasRules && !hasSkills)
|
|
13306
|
+
return null;
|
|
13307
|
+
const lines = [];
|
|
13308
|
+
lines.push(`<${COMPAT_CONTEXT_TAG} mode="compatibility" profile="${shortDigest(input.digest)}" session="${input.sessionId}" gen="${input.generation}">`, "NOTE FOR THE MODEL: the block below is host-provided context delivered over the user channel", "(compatibility mode). It is NOT a system or developer instruction and does not override them.", "");
|
|
13309
|
+
if (hasRules) {
|
|
13310
|
+
lines.push("--- host rules (same source as the host app, delivered once per session) ---", "");
|
|
13311
|
+
lines.push(input.rulesText.trim(), "");
|
|
13312
|
+
}
|
|
13313
|
+
if (hasSkills) {
|
|
13314
|
+
lines.push("--- host skills catalog (names and descriptions only; read full text on demand) ---", "");
|
|
13315
|
+
for (const skill of input.skills) {
|
|
13316
|
+
lines.push(`- ${skill.name}${skill.description ? `: ${skill.description}` : ""}`);
|
|
13317
|
+
}
|
|
13318
|
+
lines.push("", input.skillsViaMcp ? "Read a skill body with the app_read_skill MCP tool before claiming its content." : "Skill bodies are available on request; ask the host if no skill tool is listed.");
|
|
13319
|
+
lines.push("");
|
|
13320
|
+
}
|
|
13321
|
+
lines.push(`</${COMPAT_CONTEXT_TAG}>`);
|
|
13322
|
+
return lines.join(`
|
|
13323
|
+
`);
|
|
13324
|
+
}
|
|
13325
|
+
function compatDeliveryKey(sessionId, generation, digest) {
|
|
13326
|
+
return `${generation}:${sessionId}:${digest ?? "none"}`;
|
|
13327
|
+
}
|
|
13328
|
+
|
|
13329
|
+
// src/mcp/app-skills-mcp.ts
|
|
13330
|
+
var import_node_path18 = require("node:path");
|
|
13331
|
+
var import_node_url = require("node:url");
|
|
13332
|
+
var import_node_fs16 = require("node:fs");
|
|
13333
|
+
var APP_SKILLS_MCP_SERVER_NAME = "app-skills";
|
|
13334
|
+
var APP_SKILLS_TOOLS = [
|
|
13335
|
+
{
|
|
13336
|
+
name: "app_list_skills",
|
|
13337
|
+
description: "List host skill catalog (names and one-line descriptions). " + "Call this first to discover available skills; then read a body with app_read_skill before claiming its content. " + "Skill bodies are never inlined here—always read on demand.",
|
|
13338
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false }
|
|
13339
|
+
},
|
|
13340
|
+
{
|
|
13341
|
+
name: "app_read_skill",
|
|
13342
|
+
description: "Read one registered skill body by exact name from app_list_skills. " + "Optional ref reads another Markdown file in the same skill directory " + "(same-directory relative .md only; anything else is rejected).",
|
|
13343
|
+
inputSchema: {
|
|
13344
|
+
type: "object",
|
|
13345
|
+
properties: {
|
|
13346
|
+
name: { type: "string", description: "Exact skill name from app_list_skills" },
|
|
13347
|
+
ref: {
|
|
13348
|
+
type: "string",
|
|
13349
|
+
description: "Optional same-directory relative Markdown file (default SKILL.md)"
|
|
13350
|
+
}
|
|
13351
|
+
},
|
|
13352
|
+
required: ["name"],
|
|
13353
|
+
additionalProperties: false
|
|
13354
|
+
}
|
|
13355
|
+
}
|
|
13356
|
+
];
|
|
13357
|
+
function buildAppSkillsMcpServer(directory, opts) {
|
|
13358
|
+
return {
|
|
13359
|
+
name: opts?.name ?? APP_SKILLS_MCP_SERVER_NAME,
|
|
13360
|
+
command: process.execPath,
|
|
13361
|
+
env: process.versions.electron ? [{ name: "ELECTRON_RUN_AS_NODE", value: "1" }] : [],
|
|
13362
|
+
args: [opts?.runnerPath ?? resolveAppSkillsRunnerPath(), directory]
|
|
13363
|
+
};
|
|
13364
|
+
}
|
|
13365
|
+
function resolveAppSkillsRunnerPath(fromFile) {
|
|
13366
|
+
const base = fromFile ?? import_node_url.fileURLToPath("file:///home/runner/work/acp-client/acp-client/src/mcp/app-skills-mcp.ts");
|
|
13367
|
+
const candidates = [
|
|
13368
|
+
import_node_path18.join(import_node_path18.dirname(base), "app-skills-mcp-serve.cjs"),
|
|
13369
|
+
import_node_path18.join(import_node_path18.dirname(base), "app-skills-mcp-serve.ts")
|
|
13370
|
+
];
|
|
13371
|
+
for (const candidate of candidates) {
|
|
13372
|
+
if (import_node_fs16.existsSync(candidate))
|
|
13373
|
+
return candidate;
|
|
13374
|
+
}
|
|
13375
|
+
throw new Error(`技能 MCP 入口缺失(dist 未构建?): ${candidates[0]}`);
|
|
13376
|
+
}
|
|
13377
|
+
|
|
13378
|
+
// src/client/acp-client.ts
|
|
13379
|
+
var import_node_crypto4 = require("node:crypto");
|
|
13380
|
+
|
|
13381
|
+
// src/resources/eligibility.ts
|
|
13382
|
+
var NATIVE_ELIGIBLE_BRIDGE_VERSIONS = {
|
|
13383
|
+
"codex-acp": ["2.2.2"],
|
|
13384
|
+
opencode: ["1.18.35"],
|
|
13385
|
+
claude: ["0.91.0"],
|
|
13386
|
+
agy: ["0.1.24"]
|
|
13387
|
+
};
|
|
13388
|
+
function isSupportedBridgeVersion(runtimeId, version) {
|
|
13389
|
+
const versions = NATIVE_ELIGIBLE_BRIDGE_VERSIONS[(runtimeId ?? "").trim()];
|
|
13390
|
+
if (!versions)
|
|
13391
|
+
return { eligible: false, reason: "runtime-not-verified" };
|
|
13392
|
+
const normalized = version?.trim().replace(/^v/, "");
|
|
13393
|
+
if (!normalized)
|
|
13394
|
+
return { eligible: false, reason: "unknown-bridge-version" };
|
|
13395
|
+
if (!versions.includes(normalized))
|
|
13396
|
+
return { eligible: false, reason: "unsupported-bridge-version" };
|
|
13397
|
+
return { eligible: true };
|
|
13398
|
+
}
|
|
13399
|
+
|
|
12749
13400
|
// src/session/session-capabilities.ts
|
|
12750
13401
|
function parseLoadSessionSupported(caps) {
|
|
12751
13402
|
return caps.loadSession === true;
|
|
@@ -12768,11 +13419,13 @@ class AcpSessionHandle {
|
|
|
12768
13419
|
client;
|
|
12769
13420
|
restoreMethod;
|
|
12770
13421
|
configOptions;
|
|
12771
|
-
|
|
13422
|
+
resourceReport;
|
|
13423
|
+
constructor(sessionId, client, restoreMethod, configOptions, resourceReport) {
|
|
12772
13424
|
this.sessionId = sessionId;
|
|
12773
13425
|
this.client = client;
|
|
12774
13426
|
this.restoreMethod = restoreMethod;
|
|
12775
13427
|
this.configOptions = configOptions;
|
|
13428
|
+
this.resourceReport = resourceReport;
|
|
12776
13429
|
}
|
|
12777
13430
|
async prompt(promptText, options) {
|
|
12778
13431
|
return this.client.promptSession(this.sessionId, promptText, options);
|
|
@@ -12801,6 +13454,10 @@ class AcpClient {
|
|
|
12801
13454
|
clientInfo;
|
|
12802
13455
|
dataDir;
|
|
12803
13456
|
extraEnv;
|
|
13457
|
+
configurationScope;
|
|
13458
|
+
sessionConfig = null;
|
|
13459
|
+
resourcesDir;
|
|
13460
|
+
processScopeKey = import_node_crypto4.randomUUID();
|
|
12804
13461
|
callbacks;
|
|
12805
13462
|
terminals = new AcpTerminalManager;
|
|
12806
13463
|
processHandle = null;
|
|
@@ -12808,6 +13465,17 @@ class AcpClient {
|
|
|
12808
13465
|
sdkConnection = null;
|
|
12809
13466
|
streamHandle = null;
|
|
12810
13467
|
initResponse = null;
|
|
13468
|
+
inflightPrompts = new Set;
|
|
13469
|
+
resourcePrep = null;
|
|
13470
|
+
connectionGen = 0;
|
|
13471
|
+
attachSkillsMcp;
|
|
13472
|
+
sessionLedger = new Map;
|
|
13473
|
+
compatSentKeys = new Set;
|
|
13474
|
+
compatSnapshots = new Map;
|
|
13475
|
+
get resourceReport() {
|
|
13476
|
+
const report = this.resourcePrep?.report;
|
|
13477
|
+
return report ? { ...report, skillsFound: [...report.skillsFound] } : null;
|
|
13478
|
+
}
|
|
12811
13479
|
constructor(options) {
|
|
12812
13480
|
this.workspaceRoot = options.workspaceRoot;
|
|
12813
13481
|
this.clientInfo = {
|
|
@@ -12816,6 +13484,14 @@ class AcpClient {
|
|
|
12816
13484
|
};
|
|
12817
13485
|
this.dataDir = options.dataDir ?? getDefaultAgentDataDir();
|
|
12818
13486
|
this.extraEnv = options.env ?? {};
|
|
13487
|
+
if (options.resources && !isAbsolutePathLike(options.resources.directory)) {
|
|
13488
|
+
throw new Error("resources.directory 必须是本机绝对路径");
|
|
13489
|
+
}
|
|
13490
|
+
this.configurationScope = options.resources?.configurationScope ?? "overlay";
|
|
13491
|
+
if (!["overlay", "session"].includes(this.configurationScope))
|
|
13492
|
+
throw new Error("Invalid resources.configurationScope");
|
|
13493
|
+
this.resourcesDir = options.resources?.directory ?? null;
|
|
13494
|
+
this.attachSkillsMcp = options.resources?.attachSkillsMcp !== false;
|
|
12819
13495
|
this.callbacks = options.callbacks ?? {};
|
|
12820
13496
|
const runtimeId = typeof options.runtime === "string" ? options.runtime : options.runtime?.id ?? DEFAULT_ACP_RUNTIME_ID;
|
|
12821
13497
|
this.adapter = getAcpRuntimeAdapter(runtimeId);
|
|
@@ -12842,6 +13518,14 @@ class AcpClient {
|
|
|
12842
13518
|
return this.initResponse;
|
|
12843
13519
|
}
|
|
12844
13520
|
async connect() {
|
|
13521
|
+
if (this.inflightPrompts.size > 0)
|
|
13522
|
+
return err({ code: "ACP_PROTOCOL_ERROR", message: "Agent 正在回答,请结束后重新连接" });
|
|
13523
|
+
if (this.isConnected && this.initResponse)
|
|
13524
|
+
return ok({ status: this.status, init: this.initResponse });
|
|
13525
|
+
if (this.currentStatus === "connecting")
|
|
13526
|
+
return err({ code: "ACP_PROTOCOL_ERROR", message: "Agent 正在连接" });
|
|
13527
|
+
this.connectionGen += 1;
|
|
13528
|
+
const connectGen = this.connectionGen;
|
|
12845
13529
|
try {
|
|
12846
13530
|
this.setStatus("connecting");
|
|
12847
13531
|
const blocker = this.adapter.resolveSpawnBlocker?.();
|
|
@@ -12867,16 +13551,105 @@ class AcpClient {
|
|
|
12867
13551
|
...baseEnv,
|
|
12868
13552
|
env: { ...baseEnv.env ?? {}, ...this.extraEnv ?? {} }
|
|
12869
13553
|
};
|
|
13554
|
+
let resourceEnv = {};
|
|
13555
|
+
let profileTag = null;
|
|
13556
|
+
if (this.resourcesDir && this.configurationScope === "session") {
|
|
13557
|
+
const profile = await createSessionConfigHome(this.runtimeInfo.id, this.resourcesDir);
|
|
13558
|
+
if (connectGen !== this.connectionGen || this.status !== "connecting") {
|
|
13559
|
+
await profile.dispose();
|
|
13560
|
+
return err({ code: "CANCELLED", message: "连接已取消" });
|
|
13561
|
+
}
|
|
13562
|
+
this.sessionConfig = profile;
|
|
13563
|
+
resourceEnv = this.sessionConfig.env;
|
|
13564
|
+
const load = readAppResourcesDir(this.resourcesDir);
|
|
13565
|
+
this.resourcePrep = { profileTag: null, report: {
|
|
13566
|
+
rulesApplied: false,
|
|
13567
|
+
rulesPrepared: false,
|
|
13568
|
+
skillsApplied: false,
|
|
13569
|
+
rulesChars: load.rules?.chars ?? 0,
|
|
13570
|
+
profileDigest: digestAppResources(load),
|
|
13571
|
+
skillsFound: load.skills.map((s) => s.name),
|
|
13572
|
+
configurationScope: "session",
|
|
13573
|
+
configurationDirectory: this.sessionConfig.directory,
|
|
13574
|
+
configurationRulesFile: this.sessionConfig.rulesFile,
|
|
13575
|
+
reason: this.sessionConfig.nativeRules ? "isolated-config-not-runtime-verified" : "isolated-config-rule-discovery-not-verified"
|
|
13576
|
+
} };
|
|
13577
|
+
} else if (this.resourcesDir && this.adapter.prepareAppResources) {
|
|
13578
|
+
try {
|
|
13579
|
+
const prep = await this.adapter.prepareAppResources({
|
|
13580
|
+
directory: this.resourcesDir,
|
|
13581
|
+
command: effectiveRuntime.command,
|
|
13582
|
+
workspaceRoot: this.workspaceRoot,
|
|
13583
|
+
env: { ...process.env, ...spawnEnv.env }
|
|
13584
|
+
});
|
|
13585
|
+
if (prep.env)
|
|
13586
|
+
resourceEnv = prep.env;
|
|
13587
|
+
prep.report.rulesPrepared = prep.report.rulesPrepared ?? prep.report.rulesApplied;
|
|
13588
|
+
prep.report.rulesApplied = false;
|
|
13589
|
+
prep.report.skillsApplied = false;
|
|
13590
|
+
const digest = prep.report.profileDigest;
|
|
13591
|
+
profileTag = digest ? `${this.runtimeInfo.id}:resources@${digest.slice(0, 16)}` : null;
|
|
13592
|
+
this.resourcePrep = { profileTag, report: prep.report };
|
|
13593
|
+
} catch (error) {
|
|
13594
|
+
this.resourcePrep = {
|
|
13595
|
+
profileTag: null,
|
|
13596
|
+
report: {
|
|
13597
|
+
rulesApplied: false,
|
|
13598
|
+
rulesChars: 0,
|
|
13599
|
+
profileDigest: null,
|
|
13600
|
+
skillsFound: [],
|
|
13601
|
+
reason: "prepare-failed"
|
|
13602
|
+
}
|
|
13603
|
+
};
|
|
13604
|
+
this.callbacks.onLog?.("warn", "应用资源准备失败,已回退兼容", {
|
|
13605
|
+
error: error instanceof Error ? error.message : String(error)
|
|
13606
|
+
});
|
|
13607
|
+
}
|
|
13608
|
+
} else {
|
|
13609
|
+
const load = this.resourcesDir ? readAppResourcesDir(this.resourcesDir) : null;
|
|
13610
|
+
this.resourcePrep = load ? { profileTag: null, report: {
|
|
13611
|
+
rulesApplied: false,
|
|
13612
|
+
rulesPrepared: false,
|
|
13613
|
+
skillsApplied: false,
|
|
13614
|
+
rulesChars: load.rules?.chars ?? 0,
|
|
13615
|
+
profileDigest: digestAppResources(load),
|
|
13616
|
+
skillsFound: load.skills.map((s) => s.name),
|
|
13617
|
+
reason: "runtime-not-supported"
|
|
13618
|
+
} } : null;
|
|
13619
|
+
}
|
|
13620
|
+
const finalEnv = { ...spawnEnv.env, ...resourceEnv };
|
|
12870
13621
|
await this.adapter.beforeSpawn?.();
|
|
12871
|
-
|
|
13622
|
+
if (connectGen !== this.connectionGen || this.status !== "connecting")
|
|
13623
|
+
return err({ code: "CANCELLED", message: "连接已取消" });
|
|
13624
|
+
let reuseDegraded = false;
|
|
13625
|
+
let reusedHandle = null;
|
|
13626
|
+
if (profileTag) {
|
|
13627
|
+
const reuse = tryReuseLiveAcpProcess(this.runtimeInfo.id, {
|
|
13628
|
+
expectedTag: profileTag,
|
|
13629
|
+
scopeKey: this.processScopeKey,
|
|
13630
|
+
isBusy: (h) => this.inflightPrompts.size > 0 && this.processHandle === h
|
|
13631
|
+
});
|
|
13632
|
+
if (reuse.status === "hit") {
|
|
13633
|
+
reusedHandle = reuse.handle;
|
|
13634
|
+
} else if (reuse.status === "busy") {
|
|
13635
|
+
reusedHandle = reuse.handle;
|
|
13636
|
+
reuseDegraded = true;
|
|
13637
|
+
this.callbacks.onLog?.("warn", "应用资源摘要已变更但旧进程正忙,沿用旧进程并降级,新摘要下次冷启动生效");
|
|
13638
|
+
}
|
|
13639
|
+
}
|
|
13640
|
+
const processHandle = reusedHandle ?? spawnAcpProcess({
|
|
12872
13641
|
runtime: effectiveRuntime,
|
|
12873
13642
|
cwd: this.workspaceRoot,
|
|
12874
|
-
|
|
13643
|
+
scopeKey: this.processScopeKey,
|
|
13644
|
+
env: finalEnv,
|
|
12875
13645
|
envRemove: spawnEnv.envRemove,
|
|
13646
|
+
profileTag,
|
|
12876
13647
|
onStderrLine: (line) => {
|
|
12877
13648
|
this.callbacks.onStderrLine?.(line);
|
|
12878
13649
|
},
|
|
12879
13650
|
onExit: (code, signal) => {
|
|
13651
|
+
if (this.connectionGen !== connectGen)
|
|
13652
|
+
return;
|
|
12880
13653
|
this.callbacks.onLog?.("warn", `Agent 进程已退出 (code: ${code}, signal: ${signal})`);
|
|
12881
13654
|
if (this.status === "connected" || this.status === "connecting") {
|
|
12882
13655
|
this.disconnect("Agent 进程异常终止");
|
|
@@ -12927,9 +13700,28 @@ class AcpClient {
|
|
|
12927
13700
|
}
|
|
12928
13701
|
});
|
|
12929
13702
|
this.initResponse = initResp;
|
|
13703
|
+
if (this.resourcePrep) {
|
|
13704
|
+
const agentInfo = initResp?.agentInfo;
|
|
13705
|
+
const bridgeVersion = typeof agentInfo?.version === "string" ? agentInfo.version : undefined;
|
|
13706
|
+
const supported = isSupportedBridgeVersion(this.runtimeInfo.id, bridgeVersion).eligible && (this.adapter.supportedBridgeVersions?.includes(bridgeVersion?.replace(/^v/, "") ?? "") ?? false);
|
|
13707
|
+
this.resourcePrep.report.bridgeVersion = bridgeVersion;
|
|
13708
|
+
this.resourcePrep.report.bridgeSupported = supported;
|
|
13709
|
+
if (this.processHandle)
|
|
13710
|
+
this.processHandle.bridgeVersion = bridgeVersion;
|
|
13711
|
+
if (supported && this.resourcePrep.report.reason === "native-session-version-not-verified")
|
|
13712
|
+
delete this.resourcePrep.report.reason;
|
|
13713
|
+
if (!supported) {
|
|
13714
|
+
this.resourcePrep.report.reason = this.resourcePrep.report.reason ?? "unsupported-bridge-version";
|
|
13715
|
+
}
|
|
13716
|
+
if (reuseDegraded) {
|
|
13717
|
+
this.resourcePrep.report.reason = this.resourcePrep.report.reason ?? "busy-deferred-stale-rules";
|
|
13718
|
+
}
|
|
13719
|
+
}
|
|
12930
13720
|
this.setStatus("connected");
|
|
12931
13721
|
return ok({ status: "connected", init: initResp });
|
|
12932
13722
|
} catch (e) {
|
|
13723
|
+
if (connectGen !== this.connectionGen)
|
|
13724
|
+
return err({ code: "CANCELLED", message: "连接已被新请求取代" });
|
|
12933
13725
|
const message = e instanceof Error ? e.message : String(e);
|
|
12934
13726
|
this.setStatus("error", message);
|
|
12935
13727
|
await this.disconnect(message);
|
|
@@ -12968,6 +13760,29 @@ class AcpClient {
|
|
|
12968
13760
|
const resumeSupported = Boolean(init && parseResumeSessionSupported(init.agentCapabilities));
|
|
12969
13761
|
const loadSupported = Boolean(init && parseLoadSessionSupported(init.agentCapabilities));
|
|
12970
13762
|
try {
|
|
13763
|
+
let skillsExposed = "none";
|
|
13764
|
+
let mcpServers = options?.mcpServers ?? [];
|
|
13765
|
+
if (this.resourcesDir && this.attachSkillsMcp) {
|
|
13766
|
+
try {
|
|
13767
|
+
const descriptor = buildAppSkillsMcpServer(this.resourcesDir);
|
|
13768
|
+
const callerNames = new Set;
|
|
13769
|
+
for (const entry of mcpServers) {
|
|
13770
|
+
if (entry !== null && typeof entry === "object" && typeof entry.name === "string") {
|
|
13771
|
+
callerNames.add(entry.name);
|
|
13772
|
+
}
|
|
13773
|
+
}
|
|
13774
|
+
if (callerNames.has(descriptor.name)) {
|
|
13775
|
+
this.callbacks.onLog?.("warn", "调用方已有同名技能 MCP 服务,保留调用方版本", { name: descriptor.name });
|
|
13776
|
+
} else {
|
|
13777
|
+
mcpServers = [...mcpServers, descriptor];
|
|
13778
|
+
skillsExposed = "mcp-exposed";
|
|
13779
|
+
}
|
|
13780
|
+
} catch (error) {
|
|
13781
|
+
this.callbacks.onLog?.("warn", "技能 MCP 描述符构建失败,本次会话无技能 MCP", {
|
|
13782
|
+
error: error instanceof Error ? error.message : String(error)
|
|
13783
|
+
});
|
|
13784
|
+
}
|
|
13785
|
+
}
|
|
12971
13786
|
const openResult = await restoreOrCreateAcpSession({
|
|
12972
13787
|
request: async (method, params) => {
|
|
12973
13788
|
return sdkRequest(agent, method, params);
|
|
@@ -12976,12 +13791,27 @@ class AcpClient {
|
|
|
12976
13791
|
resumeSessionId: options?.resumeSessionId ?? null,
|
|
12977
13792
|
resumeSupported,
|
|
12978
13793
|
loadSupported,
|
|
12979
|
-
mcpServers
|
|
13794
|
+
mcpServers,
|
|
13795
|
+
sessionMeta: (!this.sessionConfig || this.runtimeInfo.id === "agy") && this.resourcesDir && this.resourcePrep?.report.bridgeSupported ? this.adapter.appResourceSessionMeta?.(this.resourcesDir) : undefined,
|
|
12980
13796
|
log: (level, msg, meta) => {
|
|
12981
13797
|
this.callbacks.onLog?.(level, msg, meta);
|
|
12982
13798
|
}
|
|
12983
13799
|
});
|
|
12984
|
-
|
|
13800
|
+
if (!openResult.mcpServersAccepted)
|
|
13801
|
+
skillsExposed = "none";
|
|
13802
|
+
this.sessionLedger.set(openResult.sessionId, {
|
|
13803
|
+
restoreMethod: openResult.restoreMethod,
|
|
13804
|
+
gen: this.connectionGen,
|
|
13805
|
+
skillsExposed,
|
|
13806
|
+
nativeRules: openResult.nativeSessionAccepted
|
|
13807
|
+
});
|
|
13808
|
+
const handle = new AcpSessionHandle(openResult.sessionId, this, openResult.restoreMethod, openResult.configOptions, this.resourcePrep?.report ? {
|
|
13809
|
+
...this.resourcePrep.report,
|
|
13810
|
+
skillsFound: [...this.resourcePrep.report.skillsFound],
|
|
13811
|
+
skillsExposed,
|
|
13812
|
+
rulesApplied: openResult.nativeSessionAccepted || !this.adapter.appResourceSessionMeta && openResult.restoreMethod === "new" && this.resourcePrep.report.bridgeSupported === true && this.resourcePrep.report.rulesPrepared === true,
|
|
13813
|
+
...openResult.restoreMethod !== "new" && !openResult.nativeSessionAccepted ? { reason: "session-restored-not-verified" } : {}
|
|
13814
|
+
} : null);
|
|
12985
13815
|
return ok(handle);
|
|
12986
13816
|
} catch (e) {
|
|
12987
13817
|
const message = e instanceof Error ? e.message : String(e);
|
|
@@ -12992,6 +13822,7 @@ class AcpClient {
|
|
|
12992
13822
|
if (!this.sdkConnection?.agent) {
|
|
12993
13823
|
return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
|
|
12994
13824
|
}
|
|
13825
|
+
this.inflightPrompts.add(sessionId);
|
|
12995
13826
|
try {
|
|
12996
13827
|
const prompt = [{ type: "text", text: promptText }];
|
|
12997
13828
|
for (const image of options?.images ?? []) {
|
|
@@ -12999,16 +13830,52 @@ class AcpClient {
|
|
|
12999
13830
|
continue;
|
|
13000
13831
|
prompt.push({ type: "image", mimeType: image.mimeType, data: image.data });
|
|
13001
13832
|
}
|
|
13833
|
+
const compat = this.buildCompatPrepend(sessionId);
|
|
13834
|
+
const blocks = compat ? [{ type: "text", text: compat }, ...prompt] : prompt;
|
|
13002
13835
|
const response = await sdkRequest(this.sdkConnection.agent, methods.agent.session.prompt, {
|
|
13003
13836
|
sessionId,
|
|
13004
|
-
prompt
|
|
13837
|
+
prompt: blocks
|
|
13005
13838
|
}, options?.timeoutMs);
|
|
13006
13839
|
return ok(response);
|
|
13007
13840
|
} catch (e) {
|
|
13008
13841
|
const message = e instanceof Error ? e.message : String(e);
|
|
13009
13842
|
return err({ code: "ACP_PROTOCOL_ERROR", message });
|
|
13843
|
+
} finally {
|
|
13844
|
+
this.inflightPrompts.delete(sessionId);
|
|
13010
13845
|
}
|
|
13011
13846
|
}
|
|
13847
|
+
buildCompatPrepend(sessionId) {
|
|
13848
|
+
if (!this.resourcesDir)
|
|
13849
|
+
return null;
|
|
13850
|
+
if (this.sessionConfig?.nativeRules)
|
|
13851
|
+
return null;
|
|
13852
|
+
const entry = this.sessionLedger.get(sessionId);
|
|
13853
|
+
if (!entry)
|
|
13854
|
+
return null;
|
|
13855
|
+
const connReport = this.resourcePrep?.report;
|
|
13856
|
+
const nativelyDelivered = entry.nativeRules || !this.adapter.appResourceSessionMeta && entry.restoreMethod === "new" && entry.gen === this.connectionGen && connReport?.rulesPrepared === true && connReport?.bridgeSupported === true;
|
|
13857
|
+
if (nativelyDelivered)
|
|
13858
|
+
return null;
|
|
13859
|
+
const load = readAppResourcesDir(this.resourcesDir);
|
|
13860
|
+
const rulesText = readAppRulesText(this.resourcesDir);
|
|
13861
|
+
const digest = digestAppResources(load);
|
|
13862
|
+
const key = compatDeliveryKey(sessionId, this.connectionGen, digest);
|
|
13863
|
+
if (this.compatSentKeys.has(key))
|
|
13864
|
+
return null;
|
|
13865
|
+
const text = buildCompatGuideText({
|
|
13866
|
+
rulesText,
|
|
13867
|
+
skills: load.skills.map((s) => ({ name: s.name, description: s.description })),
|
|
13868
|
+
skillsViaMcp: entry.skillsExposed === "mcp-exposed",
|
|
13869
|
+
digest,
|
|
13870
|
+
sessionId,
|
|
13871
|
+
generation: this.connectionGen
|
|
13872
|
+
});
|
|
13873
|
+
if (!text)
|
|
13874
|
+
return null;
|
|
13875
|
+
this.compatSnapshots.set(key, { text, digest });
|
|
13876
|
+
this.compatSentKeys.add(key);
|
|
13877
|
+
return text;
|
|
13878
|
+
}
|
|
13012
13879
|
async setSessionConfigOption(sessionId, configId, value) {
|
|
13013
13880
|
if (!this.sdkConnection?.agent) {
|
|
13014
13881
|
return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
|
|
@@ -13027,6 +13894,10 @@ class AcpClient {
|
|
|
13027
13894
|
}
|
|
13028
13895
|
async disconnect(reason) {
|
|
13029
13896
|
this.setStatus("disconnected", reason);
|
|
13897
|
+
this.resourcePrep = null;
|
|
13898
|
+
this.sessionLedger.clear();
|
|
13899
|
+
this.compatSentKeys.clear();
|
|
13900
|
+
this.compatSnapshots.clear();
|
|
13030
13901
|
try {
|
|
13031
13902
|
this.streamHandle?.dispose();
|
|
13032
13903
|
this.sdkConnection?.close();
|
|
@@ -13042,6 +13913,15 @@ class AcpClient {
|
|
|
13042
13913
|
} catch {}
|
|
13043
13914
|
this.processHandle = null;
|
|
13044
13915
|
}
|
|
13916
|
+
const config = this.sessionConfig;
|
|
13917
|
+
this.sessionConfig = null;
|
|
13918
|
+
if (config) {
|
|
13919
|
+
try {
|
|
13920
|
+
await config.dispose();
|
|
13921
|
+
} catch {
|
|
13922
|
+
this.callbacks.onLog?.("warn", "Session configuration cleanup failed; directory retained", { directory: config.directory });
|
|
13923
|
+
}
|
|
13924
|
+
}
|
|
13045
13925
|
}
|
|
13046
13926
|
setStatus(status, detail) {
|
|
13047
13927
|
this.status = status;
|