toc-ocra 0.3.21 → 0.3.22
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 +1 -1
- package/dist/cli/cli.mjs +651 -189
- package/dist/service/agent.mjs +626 -164
- package/dist/src/acp/acp-dialects/antigravity-dialect.d.ts +20 -0
- package/dist/src/acp/acp-dialects/antigravity-dialect.js +126 -0
- package/dist/src/acp/acp-dialects/antigravity-dialect.js.map +1 -0
- package/dist/src/acp/acp-launch-specs.d.ts +2 -0
- package/dist/src/acp/acp-launch-specs.js +19 -0
- package/dist/src/acp/acp-launch-specs.js.map +1 -1
- package/dist/src/acp/acp-options.js +6 -3
- package/dist/src/acp/acp-options.js.map +1 -1
- package/dist/src/acp/chat-agents.js +3 -1
- package/dist/src/acp/chat-agents.js.map +1 -1
- package/dist/src/acp/chat-session.js +4 -1
- package/dist/src/acp/chat-session.js.map +1 -1
- package/dist/src/providers/acp/acp-driver.js +2 -1
- package/dist/src/providers/acp/acp-driver.js.map +1 -1
- package/dist/src/providers/antigravity-quota.d.ts +17 -0
- package/dist/src/providers/antigravity-quota.js +253 -0
- package/dist/src/providers/antigravity-quota.js.map +1 -0
- package/dist/src/providers/cli-specs.js +1 -0
- package/dist/src/providers/cli-specs.js.map +1 -1
- package/dist/src/providers/model-catalog.d.ts +9 -0
- package/dist/src/providers/model-catalog.js +126 -0
- package/dist/src/providers/model-catalog.js.map +1 -1
- package/dist/src/providers/registry.js +2 -0
- package/dist/src/providers/registry.js.map +1 -1
- package/package.json +1 -1
package/dist/service/agent.mjs
CHANGED
|
@@ -7,7 +7,7 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/plugin-service.ts
|
|
9
9
|
import { existsSync as existsSync8 } from "node:fs";
|
|
10
|
-
import { delimiter as delimiter5, join as
|
|
10
|
+
import { delimiter as delimiter5, join as join25 } from "node:path";
|
|
11
11
|
|
|
12
12
|
// src/config.ts
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
@@ -851,14 +851,14 @@ function promiseAllObject(promisesObj) {
|
|
|
851
851
|
}
|
|
852
852
|
function randomString(length = 10) {
|
|
853
853
|
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
854
|
-
let
|
|
854
|
+
let str3 = "";
|
|
855
855
|
for (let i = 0; i < length; i++) {
|
|
856
|
-
|
|
856
|
+
str3 += chars[Math.floor(Math.random() * chars.length)];
|
|
857
857
|
}
|
|
858
|
-
return
|
|
858
|
+
return str3;
|
|
859
859
|
}
|
|
860
|
-
function esc(
|
|
861
|
-
return JSON.stringify(
|
|
860
|
+
function esc(str3) {
|
|
861
|
+
return JSON.stringify(str3);
|
|
862
862
|
}
|
|
863
863
|
function slugify(input2) {
|
|
864
864
|
return input2.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -972,8 +972,8 @@ var primitiveTypes = /* @__PURE__ */ new Set([
|
|
|
972
972
|
"symbol",
|
|
973
973
|
"undefined"
|
|
974
974
|
]);
|
|
975
|
-
function escapeRegex(
|
|
976
|
-
return
|
|
975
|
+
function escapeRegex(str3) {
|
|
976
|
+
return str3.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
977
977
|
}
|
|
978
978
|
function clone(inst, def, params) {
|
|
979
979
|
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
@@ -1239,13 +1239,13 @@ function getSizableOrigin(input2) {
|
|
|
1239
1239
|
return "unknown";
|
|
1240
1240
|
}
|
|
1241
1241
|
var highSurrogate = /[\uD800-\uDBFF]/;
|
|
1242
|
-
function codePointLength(
|
|
1243
|
-
const units =
|
|
1244
|
-
if (!highSurrogate.test(
|
|
1242
|
+
function codePointLength(str3) {
|
|
1243
|
+
const units = str3.length;
|
|
1244
|
+
if (!highSurrogate.test(str3))
|
|
1245
1245
|
return units;
|
|
1246
1246
|
let count2 = units;
|
|
1247
1247
|
for (let i = 0; i < units - 1; i++) {
|
|
1248
|
-
if ((
|
|
1248
|
+
if ((str3.charCodeAt(i) & 64512) === 55296 && (str3.charCodeAt(i + 1) & 64512) === 56320) {
|
|
1249
1249
|
count2--;
|
|
1250
1250
|
i++;
|
|
1251
1251
|
}
|
|
@@ -20331,7 +20331,7 @@ function createDiagnosticLogger(filePath, options = {}) {
|
|
|
20331
20331
|
}
|
|
20332
20332
|
|
|
20333
20333
|
// src/providers/detection.ts
|
|
20334
|
-
import { spawn as
|
|
20334
|
+
import { spawn as spawn10 } from "node:child_process";
|
|
20335
20335
|
|
|
20336
20336
|
// src/runtime/cli/hydrate-shell-path.ts
|
|
20337
20337
|
import { delimiter as delimiter3 } from "node:path";
|
|
@@ -20781,6 +20781,7 @@ var SOURCES = [
|
|
|
20781
20781
|
{ id: "claude", label: "Claude Code", aliases: ["claude-code"], command: "claude", commandAliases: ["claude-code"], versionArguments: ["--version"], promptStdin: "omit", restrictedPermission: true, installHint: "npm i -g @anthropic-ai/claude-code" },
|
|
20782
20782
|
{ id: "grok", label: "Grok CLI", command: "grok", versionArguments: ["--version"] },
|
|
20783
20783
|
{ id: "gemini", label: "Gemini CLI", command: "gemini", versionArguments: ["--version"], restrictedPermission: true, installHint: "npm i -g @google/gemini-cli" },
|
|
20784
|
+
{ id: "antigravity", label: "Antigravity", aliases: ["agy"], command: "agy", versionArguments: ["--version"], restrictedPermission: true, installHint: "https://antigravity.google/cli" },
|
|
20784
20785
|
{ id: "opencode", label: "OpenCode", command: "opencode", versionArguments: ["--version"], installHint: "npm i -g opencode-ai" },
|
|
20785
20786
|
{ id: "kiro", label: "Kiro CLI", aliases: ["kiro-cli"], command: "kiro-cli", commandAliases: ["kiro"], versionArguments: ["--version"], promptStdin: "omit", restrictedPermission: true },
|
|
20786
20787
|
{ id: "omp", label: "OMP", command: "omp", versionArguments: ["--version"] },
|
|
@@ -21011,7 +21012,7 @@ function textRows(prefix, text3, maxRows = 40) {
|
|
|
21011
21012
|
|
|
21012
21013
|
// src/acp/acp-launch-specs.ts
|
|
21013
21014
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
21014
|
-
import { join as
|
|
21015
|
+
import { join as join14 } from "node:path";
|
|
21015
21016
|
|
|
21016
21017
|
// src/providers/claude-sessions.ts
|
|
21017
21018
|
import { existsSync as existsSync5, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -21173,8 +21174,8 @@ function codexCatalogArgs() {
|
|
|
21173
21174
|
// src/providers/model-catalog.ts
|
|
21174
21175
|
import { spawn as spawn5 } from "node:child_process";
|
|
21175
21176
|
import { readdir, readFile as readFile4 } from "node:fs/promises";
|
|
21176
|
-
import { homedir as
|
|
21177
|
-
import { isAbsolute as isAbsolute2, join as
|
|
21177
|
+
import { homedir as homedir8 } from "node:os";
|
|
21178
|
+
import { isAbsolute as isAbsolute2, join as join11, resolve as resolve3 } from "node:path";
|
|
21178
21179
|
|
|
21179
21180
|
// src/providers/kiro-auth.ts
|
|
21180
21181
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -21294,6 +21295,116 @@ async function readKiroNativeModels(launch, cwd, options = {}) {
|
|
|
21294
21295
|
}
|
|
21295
21296
|
}
|
|
21296
21297
|
|
|
21298
|
+
// src/acp/acp-dialects/antigravity-dialect.ts
|
|
21299
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
21300
|
+
import { homedir as homedir7 } from "node:os";
|
|
21301
|
+
import { join as join10 } from "node:path";
|
|
21302
|
+
|
|
21303
|
+
// src/acp/acp-dialects/acp-dialect.ts
|
|
21304
|
+
var record2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21305
|
+
|
|
21306
|
+
// src/acp/acp-dialects/antigravity-dialect.ts
|
|
21307
|
+
var str2 = (value) => typeof value === "string" && value ? value : void 0;
|
|
21308
|
+
var num = (value) => typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
21309
|
+
var ANTIGRAVITY_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"];
|
|
21310
|
+
var ANTIGRAVITY_LEVEL_SUFFIX = /^(.+)-(low|medium|high|xhigh|max)$/;
|
|
21311
|
+
var CLOUD_CODE_PREFIX = /^Cloud Code Assist API error \(\d{3}\):\s*/;
|
|
21312
|
+
var EXECUTOR_API_ERROR = /^(\u26a0 agent executor error: [^\n]*?Error (\d{3}), Message: ([^\n]*?)), Status: ([A-Z_]+)(?:, Details: ([^\n]*))?$/;
|
|
21313
|
+
var ANTIGRAVITY_FAILURE_RULES = [
|
|
21314
|
+
{
|
|
21315
|
+
kind: "notSignedIn",
|
|
21316
|
+
pattern: /not logged into antigravity|not logged in|not signed in|not authenticated|unauthenticated|authentication required|run agy login|please sign in|api key not valid/i
|
|
21317
|
+
},
|
|
21318
|
+
{
|
|
21319
|
+
kind: "rateLimited",
|
|
21320
|
+
pattern: /resource_exhausted|quota exceeded|rate limit|too many requests|429/i
|
|
21321
|
+
},
|
|
21322
|
+
{
|
|
21323
|
+
kind: "sessionMissing",
|
|
21324
|
+
pattern: /session not found|failed to rebuild agent:/i
|
|
21325
|
+
}
|
|
21326
|
+
];
|
|
21327
|
+
function antigravityUsesApiKeyProvider(homePath = homedir7()) {
|
|
21328
|
+
try {
|
|
21329
|
+
const raw = readFileSync5(join10(homePath, ".gemini", "antigravity-cli", "settings.json"), "utf8");
|
|
21330
|
+
const parsed = JSON.parse(raw);
|
|
21331
|
+
return Boolean(record2(parsed).modelProvider);
|
|
21332
|
+
} catch {
|
|
21333
|
+
return false;
|
|
21334
|
+
}
|
|
21335
|
+
}
|
|
21336
|
+
function scrubAntigravityEnv(env, homePath = homedir7()) {
|
|
21337
|
+
const next = { ...env };
|
|
21338
|
+
if (!antigravityUsesApiKeyProvider(homePath)) {
|
|
21339
|
+
for (const key of Object.keys(next)) {
|
|
21340
|
+
const normalized = process.platform === "win32" ? key.toUpperCase() : key;
|
|
21341
|
+
if (normalized === "GEMINI_API_KEY" || normalized === "GOOGLE_API_KEY") {
|
|
21342
|
+
delete next[key];
|
|
21343
|
+
}
|
|
21344
|
+
}
|
|
21345
|
+
}
|
|
21346
|
+
if (process.platform === "win32") {
|
|
21347
|
+
for (const key of Object.keys(next)) {
|
|
21348
|
+
if (key.toUpperCase() === "AGY_CLI_DISABLE_AUTO_UPDATE" && key !== "AGY_CLI_DISABLE_AUTO_UPDATE") {
|
|
21349
|
+
delete next[key];
|
|
21350
|
+
}
|
|
21351
|
+
}
|
|
21352
|
+
}
|
|
21353
|
+
next.AGY_CLI_DISABLE_AUTO_UPDATE = "true";
|
|
21354
|
+
return next;
|
|
21355
|
+
}
|
|
21356
|
+
function errorText(error62) {
|
|
21357
|
+
if (typeof error62.data === "string" && error62.data.trim()) return error62.data.trim();
|
|
21358
|
+
const nested = record2(error62.data);
|
|
21359
|
+
const nestedMsg = str2(nested.message) ?? str2(nested.details) ?? str2(nested.error);
|
|
21360
|
+
return nestedMsg ?? error62.message ?? "";
|
|
21361
|
+
}
|
|
21362
|
+
function promptErrorDetail(error62) {
|
|
21363
|
+
const text3 = errorText(error62);
|
|
21364
|
+
if (!text3) return void 0;
|
|
21365
|
+
const prefix = CLOUD_CODE_PREFIX.exec(text3);
|
|
21366
|
+
if (prefix) {
|
|
21367
|
+
try {
|
|
21368
|
+
const parsed = record2(JSON.parse(text3.slice(prefix[0].length)));
|
|
21369
|
+
const msg = str2(record2(parsed.error).message)?.trim();
|
|
21370
|
+
if (msg) return msg;
|
|
21371
|
+
} catch {
|
|
21372
|
+
}
|
|
21373
|
+
}
|
|
21374
|
+
const execMatch = EXECUTOR_API_ERROR.exec(text3);
|
|
21375
|
+
if (execMatch) {
|
|
21376
|
+
const [, , code, rawMessage, status] = execMatch;
|
|
21377
|
+
const message = rawMessage?.trim();
|
|
21378
|
+
return message || `Google returned error ${code} (${status}).`;
|
|
21379
|
+
}
|
|
21380
|
+
return void 0;
|
|
21381
|
+
}
|
|
21382
|
+
function normalizeToolUpdate(update) {
|
|
21383
|
+
const input2 = record2(update.rawInput);
|
|
21384
|
+
const output2 = record2(update.rawOutput);
|
|
21385
|
+
const command = str2(input2.CommandLine) ?? str2(input2.command_line) ?? str2(input2.commandLine);
|
|
21386
|
+
const cwd = str2(input2.Cwd) ?? str2(input2.WorkingDirectory) ?? str2(input2.working_dir) ?? str2(input2.workingDir) ?? str2(input2.cwd);
|
|
21387
|
+
const stdout = str2(output2.combinedOutput) ?? str2(output2.combined_output);
|
|
21388
|
+
const exitCode = num(output2.exitCode) ?? num(output2.exit_code);
|
|
21389
|
+
return {
|
|
21390
|
+
...update,
|
|
21391
|
+
...command === void 0 ? {} : { rawInput: { command, ...cwd === void 0 ? {} : { cwd } } },
|
|
21392
|
+
...stdout === void 0 && exitCode === void 0 ? {} : {
|
|
21393
|
+
rawOutput: {
|
|
21394
|
+
...stdout === void 0 ? {} : { stdout },
|
|
21395
|
+
...exitCode === void 0 ? {} : { exitCode }
|
|
21396
|
+
}
|
|
21397
|
+
}
|
|
21398
|
+
};
|
|
21399
|
+
}
|
|
21400
|
+
var ANTIGRAVITY_ACP_DIALECT = {
|
|
21401
|
+
failureRules: ANTIGRAVITY_FAILURE_RULES,
|
|
21402
|
+
failureKind: ({ code }) => code === 401 ? "notSignedIn" : code === 429 ? "rateLimited" : void 0,
|
|
21403
|
+
promptErrorDetail,
|
|
21404
|
+
normalizeToolUpdate,
|
|
21405
|
+
toolName: (update) => update.kind === "execute" ? "execute" : void 0
|
|
21406
|
+
};
|
|
21407
|
+
|
|
21297
21408
|
// src/providers/model-catalog.ts
|
|
21298
21409
|
function stringValue(value) {
|
|
21299
21410
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
@@ -21382,15 +21493,16 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
|
|
|
21382
21493
|
models: [...models2.values()]
|
|
21383
21494
|
};
|
|
21384
21495
|
}
|
|
21385
|
-
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
21386
|
-
var codexHome2 = () => process.env.CODEX_HOME?.trim() ||
|
|
21387
|
-
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() ||
|
|
21388
|
-
var
|
|
21389
|
-
var
|
|
21390
|
-
var
|
|
21496
|
+
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join11(homedir8(), ".claude");
|
|
21497
|
+
var codexHome2 = () => process.env.CODEX_HOME?.trim() || join11(homedir8(), ".codex");
|
|
21498
|
+
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() || join11(homedir8(), ".gemini");
|
|
21499
|
+
var antigravityHome = () => join11(homedir8(), ".gemini", "antigravity-cli");
|
|
21500
|
+
var grokHome = () => process.env.GROK_HOME?.trim() || join11(homedir8(), ".grok");
|
|
21501
|
+
var opencodeHome = () => join11(process.env.XDG_CONFIG_HOME?.trim() || join11(homedir8(), ".config"), "opencode");
|
|
21502
|
+
var kiroHome = () => join11(homedir8(), ".kiro");
|
|
21391
21503
|
async function readClaudeModelCatalog() {
|
|
21392
21504
|
const home = claudeHome();
|
|
21393
|
-
const content = await readFile4(
|
|
21505
|
+
const content = await readFile4(join11(home, "settings.json"), "utf8").catch(() => "");
|
|
21394
21506
|
let settings = {};
|
|
21395
21507
|
if (content) {
|
|
21396
21508
|
try {
|
|
@@ -21402,13 +21514,13 @@ async function readClaudeModelCatalog() {
|
|
|
21402
21514
|
return parseClaudeModelCatalog(settings, process.env, (/* @__PURE__ */ new Date()).toISOString(), await readClaudeCachedModels(home));
|
|
21403
21515
|
}
|
|
21404
21516
|
async function readClaudeCachedModels(home) {
|
|
21405
|
-
const dir =
|
|
21517
|
+
const dir = join11(home, "cache", "model-catalog");
|
|
21406
21518
|
const names = await readdir(dir).catch(() => []);
|
|
21407
21519
|
let newest;
|
|
21408
21520
|
for (const name of names) {
|
|
21409
21521
|
if (!name.endsWith(".json")) continue;
|
|
21410
21522
|
try {
|
|
21411
|
-
const cache = JSON.parse(await readFile4(
|
|
21523
|
+
const cache = JSON.parse(await readFile4(join11(dir, name), "utf8"));
|
|
21412
21524
|
const models2 = parseClaudeCachedModels(cache);
|
|
21413
21525
|
const fetchedAt = Number(objectValue(cache).fetchedAt) || 0;
|
|
21414
21526
|
if (models2.length && (!newest || fetchedAt > newest.fetchedAt)) newest = { fetchedAt, models: models2 };
|
|
@@ -21464,13 +21576,13 @@ async function readCodexModels(codexHome3, config2) {
|
|
|
21464
21576
|
const configuredModels = parseCodexModels(await readFile4(catalogPath, "utf8").catch(() => ""));
|
|
21465
21577
|
if (configuredModels?.length) return configuredModels;
|
|
21466
21578
|
}
|
|
21467
|
-
const cached3 = parseCodexModels(await readFile4(
|
|
21579
|
+
const cached3 = parseCodexModels(await readFile4(join11(codexHome3, "models_cache.json"), "utf8").catch(() => ""));
|
|
21468
21580
|
if (cached3?.length) return cached3;
|
|
21469
21581
|
return codexModelsFrom(await codexBundledCatalog().catch(() => void 0), { listedOnly: true }) ?? [];
|
|
21470
21582
|
}
|
|
21471
21583
|
async function readCodexModelCatalog() {
|
|
21472
21584
|
const home = codexHome2();
|
|
21473
|
-
const config2 = await readFile4(
|
|
21585
|
+
const config2 = await readFile4(join11(home, "config.toml"), "utf8").catch(() => "");
|
|
21474
21586
|
const models2 = await readCodexModels(home, config2);
|
|
21475
21587
|
const defaultModel = configValue(config2, "model");
|
|
21476
21588
|
const defaultReasoningEffort = configValue(config2, "model_reasoning_effort");
|
|
@@ -21584,7 +21696,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
21584
21696
|
if (current) return known.catalog;
|
|
21585
21697
|
try {
|
|
21586
21698
|
const launch = launchCli({ spec: kiro, args: ["acp", "--trust-tools="], env: environment });
|
|
21587
|
-
const catalog = await readKiroNativeModels(launch,
|
|
21699
|
+
const catalog = await readKiroNativeModels(launch, homedir8(), { catalog: base });
|
|
21588
21700
|
kiroEfforts = { signature, readAt: Date.now(), catalog };
|
|
21589
21701
|
return catalog;
|
|
21590
21702
|
} catch {
|
|
@@ -21593,7 +21705,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
21593
21705
|
};
|
|
21594
21706
|
const [payload, content] = await Promise.all([
|
|
21595
21707
|
readEfforts(),
|
|
21596
|
-
readFile4(
|
|
21708
|
+
readFile4(join11(kiroHome(), "settings", "cli.json"), "utf8").catch(() => "{}")
|
|
21597
21709
|
]);
|
|
21598
21710
|
let settings;
|
|
21599
21711
|
try {
|
|
@@ -21650,7 +21762,7 @@ function geminiModelsUrl(baseUrl) {
|
|
|
21650
21762
|
}
|
|
21651
21763
|
async function readGeminiModelCatalog() {
|
|
21652
21764
|
const fileEnvironment = parseEnvFile(
|
|
21653
|
-
await readFile4(
|
|
21765
|
+
await readFile4(join11(geminiHome(), ".env"), "utf8").catch(() => "")
|
|
21654
21766
|
);
|
|
21655
21767
|
const environment = { ...fileEnvironment, ...process.env };
|
|
21656
21768
|
const baseUrl = environment.GOOGLE_GEMINI_BASE_URL?.trim();
|
|
@@ -21695,7 +21807,7 @@ function parseGrokModelCatalog(output2, config2 = "", fetchedAt = (/* @__PURE__
|
|
|
21695
21807
|
return catalog;
|
|
21696
21808
|
}
|
|
21697
21809
|
async function readGrokModelCatalog() {
|
|
21698
|
-
const config2 = await readFile4(
|
|
21810
|
+
const config2 = await readFile4(join11(grokHome(), "config.toml"), "utf8").catch(() => "");
|
|
21699
21811
|
const output2 = await runModelListCommand(cliExecutable("grok"), ["models"], "grok");
|
|
21700
21812
|
const catalog = parseGrokModelCatalog(output2, config2);
|
|
21701
21813
|
if (catalog.models.length === 0) throw new Error("Grok \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -21714,30 +21826,139 @@ function parseOpencodeModelCatalog(output2, config2 = "", fetchedAt = (/* @__PUR
|
|
|
21714
21826
|
return catalog;
|
|
21715
21827
|
}
|
|
21716
21828
|
async function readOpencodeModelCatalog() {
|
|
21717
|
-
const config2 = await readFile4(
|
|
21829
|
+
const config2 = await readFile4(join11(opencodeHome(), "opencode.json"), "utf8").catch(() => "") || await readFile4(join11(opencodeHome(), "opencode.jsonc"), "utf8").catch(() => "");
|
|
21718
21830
|
const output2 = await runModelListCommand(cliExecutable("opencode"), ["models"], "opencode");
|
|
21719
21831
|
const catalog = parseOpencodeModelCatalog(output2, config2);
|
|
21720
21832
|
if (catalog.models.length === 0) throw new Error("OpenCode \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
21721
21833
|
return catalog;
|
|
21722
21834
|
}
|
|
21835
|
+
function parseAntigravityModelCatalog(output2, settingsContent = "", fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
21836
|
+
const plain = output2.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "");
|
|
21837
|
+
const variants = [];
|
|
21838
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
21839
|
+
for (const line of plain.split(/\r?\n/)) {
|
|
21840
|
+
const parts = line.split(" ").map((field) => field.trim());
|
|
21841
|
+
const [modelId, name, ...extra] = parts;
|
|
21842
|
+
if (!modelId || !name || extra.length > 0 || seenIds.has(modelId)) continue;
|
|
21843
|
+
seenIds.add(modelId);
|
|
21844
|
+
variants.push({ modelId, name });
|
|
21845
|
+
}
|
|
21846
|
+
const familyLevels = /* @__PURE__ */ new Map();
|
|
21847
|
+
for (const variant of variants) {
|
|
21848
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(variant.modelId);
|
|
21849
|
+
const family = match?.[1];
|
|
21850
|
+
const level = match?.[2];
|
|
21851
|
+
if (!family || !level || seenIds.has(family)) continue;
|
|
21852
|
+
const list = familyLevels.get(family) ?? [];
|
|
21853
|
+
if (!list.includes(level)) list.push(level);
|
|
21854
|
+
familyLevels.set(family, list);
|
|
21855
|
+
}
|
|
21856
|
+
const models2 = [];
|
|
21857
|
+
const addedFamilies = /* @__PURE__ */ new Set();
|
|
21858
|
+
for (const variant of variants) {
|
|
21859
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(variant.modelId);
|
|
21860
|
+
const family = match?.[1];
|
|
21861
|
+
const levels = family ? familyLevels.get(family) : void 0;
|
|
21862
|
+
if (family && levels && levels.length > 1) {
|
|
21863
|
+
if (addedFamilies.has(family)) continue;
|
|
21864
|
+
addedFamilies.add(family);
|
|
21865
|
+
const ordered = ANTIGRAVITY_EFFORT_LEVELS.filter((level) => levels.includes(level));
|
|
21866
|
+
const firstLevel = levels[0];
|
|
21867
|
+
models2.push({
|
|
21868
|
+
id: family,
|
|
21869
|
+
name: variant.name.replace(/\s*\([^()]+\)$/, ""),
|
|
21870
|
+
supported_reasoning_efforts: [...ordered],
|
|
21871
|
+
...firstLevel && ordered.includes(firstLevel) ? { default_reasoning_effort: firstLevel } : {}
|
|
21872
|
+
});
|
|
21873
|
+
} else {
|
|
21874
|
+
models2.push({
|
|
21875
|
+
id: variant.modelId,
|
|
21876
|
+
name: variant.name,
|
|
21877
|
+
supported_reasoning_efforts: []
|
|
21878
|
+
});
|
|
21879
|
+
}
|
|
21880
|
+
}
|
|
21881
|
+
let configuredModel;
|
|
21882
|
+
if (settingsContent.trim()) {
|
|
21883
|
+
try {
|
|
21884
|
+
configuredModel = stringValue(objectValue(JSON.parse(settingsContent)).model);
|
|
21885
|
+
} catch {
|
|
21886
|
+
}
|
|
21887
|
+
}
|
|
21888
|
+
let defaultModel;
|
|
21889
|
+
let defaultEffort;
|
|
21890
|
+
if (configuredModel) {
|
|
21891
|
+
const matchedVariant = variants.find(
|
|
21892
|
+
(variant) => variant.modelId === configuredModel || variant.name.toLowerCase() === configuredModel.toLowerCase()
|
|
21893
|
+
);
|
|
21894
|
+
if (matchedVariant) {
|
|
21895
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(matchedVariant.modelId);
|
|
21896
|
+
const family = match?.[1];
|
|
21897
|
+
const level = match?.[2];
|
|
21898
|
+
if (family && addedFamilies.has(family)) {
|
|
21899
|
+
defaultModel = family;
|
|
21900
|
+
defaultEffort = level;
|
|
21901
|
+
} else {
|
|
21902
|
+
defaultModel = matchedVariant.modelId;
|
|
21903
|
+
}
|
|
21904
|
+
} else {
|
|
21905
|
+
const matchedFamily = models2.find(
|
|
21906
|
+
(model) => model.id === configuredModel || model.name.toLowerCase() === configuredModel.toLowerCase()
|
|
21907
|
+
);
|
|
21908
|
+
if (matchedFamily) {
|
|
21909
|
+
defaultModel = matchedFamily.id;
|
|
21910
|
+
defaultEffort = matchedFamily.default_reasoning_effort;
|
|
21911
|
+
}
|
|
21912
|
+
}
|
|
21913
|
+
}
|
|
21914
|
+
if (!defaultModel && models2.length > 0) {
|
|
21915
|
+
defaultModel = models2[0].id;
|
|
21916
|
+
defaultEffort = models2[0].default_reasoning_effort;
|
|
21917
|
+
}
|
|
21918
|
+
return {
|
|
21919
|
+
agent_type: "antigravity",
|
|
21920
|
+
fetched_at: fetchedAt,
|
|
21921
|
+
...defaultModel ? { default_model: defaultModel } : {},
|
|
21922
|
+
...defaultEffort ? { default_reasoning_effort: defaultEffort } : {},
|
|
21923
|
+
models: models2
|
|
21924
|
+
};
|
|
21925
|
+
}
|
|
21926
|
+
async function readAntigravityModelCatalog() {
|
|
21927
|
+
const baseEnv = mergeShellProxyEnvironment(await hydrateShellPath(), providerEnvironment());
|
|
21928
|
+
const env = scrubAntigravityEnv(baseEnv);
|
|
21929
|
+
const spec = requireCliSpec("antigravity");
|
|
21930
|
+
const launch = launchCli({ spec, args: ["models"], env });
|
|
21931
|
+
const [output2, settings] = await Promise.all([
|
|
21932
|
+
runModelListCommand(launch.executable, launch.args, "agy", launch.env ?? env),
|
|
21933
|
+
readFile4(join11(antigravityHome(), "settings.json"), "utf8").catch(() => "")
|
|
21934
|
+
]);
|
|
21935
|
+
const catalog = parseAntigravityModelCatalog(output2, settings);
|
|
21936
|
+
if (catalog.models.length === 0) throw new Error("Antigravity \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B\uFF0C\u8BF7\u786E\u8BA4\u5DF2\u767B\u5F55 agy");
|
|
21937
|
+
return catalog;
|
|
21938
|
+
}
|
|
21723
21939
|
var TEN_MINUTES = 10 * 60 * 1e3;
|
|
21724
21940
|
var MODEL_SOURCES = {
|
|
21725
|
-
|
|
21941
|
+
antigravity: {
|
|
21942
|
+
read: readAntigravityModelCatalog,
|
|
21943
|
+
watchFiles: () => [join11(antigravityHome(), "settings.json")],
|
|
21944
|
+
refreshEveryMs: TEN_MINUTES
|
|
21945
|
+
},
|
|
21946
|
+
claude: { read: readClaudeModelCatalog, watchFiles: () => [join11(claudeHome(), "settings.json"), join11(claudeHome(), "cache", "model-catalog")] },
|
|
21726
21947
|
codex: {
|
|
21727
21948
|
read: readCodexModelCatalog,
|
|
21728
21949
|
watchFiles: () => {
|
|
21729
21950
|
const home = codexHome2();
|
|
21730
|
-
return [
|
|
21951
|
+
return [join11(home, "config.toml"), join11(home, "models_cache.json")];
|
|
21731
21952
|
},
|
|
21732
21953
|
// model_catalog_json may point anywhere; a periodic re-read covers it.
|
|
21733
21954
|
refreshEveryMs: TEN_MINUTES
|
|
21734
21955
|
},
|
|
21735
|
-
gemini: { read: readGeminiModelCatalog, watchFiles: () => [
|
|
21736
|
-
grok: { read: readGrokModelCatalog, watchFiles: () => [
|
|
21737
|
-
kiro: { read: readKiroModelCatalog, watchFiles: () => [
|
|
21956
|
+
gemini: { read: readGeminiModelCatalog, watchFiles: () => [join11(geminiHome(), ".env")], refreshEveryMs: TEN_MINUTES },
|
|
21957
|
+
grok: { read: readGrokModelCatalog, watchFiles: () => [join11(grokHome(), "config.toml")], refreshEveryMs: TEN_MINUTES },
|
|
21958
|
+
kiro: { read: readKiroModelCatalog, watchFiles: () => [join11(kiroHome(), "settings", "cli.json")] },
|
|
21738
21959
|
opencode: {
|
|
21739
21960
|
read: readOpencodeModelCatalog,
|
|
21740
|
-
watchFiles: () => [
|
|
21961
|
+
watchFiles: () => [join11(opencodeHome(), "opencode.json"), join11(opencodeHome(), "opencode.jsonc")],
|
|
21741
21962
|
refreshEveryMs: TEN_MINUTES
|
|
21742
21963
|
}
|
|
21743
21964
|
};
|
|
@@ -21753,9 +21974,6 @@ var GEMINI_ACP_DIALECT = {
|
|
|
21753
21974
|
linksFileMentions: true
|
|
21754
21975
|
};
|
|
21755
21976
|
|
|
21756
|
-
// src/acp/acp-dialects/acp-dialect.ts
|
|
21757
|
-
var record2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21758
|
-
|
|
21759
21977
|
// src/acp/acp-dialects/grok-dialect.ts
|
|
21760
21978
|
function modelEfforts(model) {
|
|
21761
21979
|
const meta3 = record2(model._meta);
|
|
@@ -21855,11 +22073,11 @@ function classifySpawnError(error62, context) {
|
|
|
21855
22073
|
|
|
21856
22074
|
// src/providers/cli/kiro-session-log.ts
|
|
21857
22075
|
import { open as open2, readdir as readdir2, readFile as readFile5, stat as stat2 } from "node:fs/promises";
|
|
21858
|
-
import { homedir as
|
|
21859
|
-
import { join as
|
|
22076
|
+
import { homedir as homedir9 } from "node:os";
|
|
22077
|
+
import { join as join12 } from "node:path";
|
|
21860
22078
|
var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "execute_bash", "bash"]);
|
|
21861
22079
|
function kiroSessionsDirectory() {
|
|
21862
|
-
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR ||
|
|
22080
|
+
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR || join12(homedir9(), ".kiro", "sessions", "cli");
|
|
21863
22081
|
}
|
|
21864
22082
|
var KiroSessionLog = class {
|
|
21865
22083
|
constructor(options) {
|
|
@@ -21878,7 +22096,7 @@ var KiroSessionLog = class {
|
|
|
21878
22096
|
/** Called before the CLI starts: a resumed log is followed from its current end. */
|
|
21879
22097
|
async begin() {
|
|
21880
22098
|
if (!this.options.sessionId) return;
|
|
21881
|
-
this.path =
|
|
22099
|
+
this.path = join12(this.directory, `${this.options.sessionId}.jsonl`);
|
|
21882
22100
|
this.offset = await stat2(this.path).then((info) => info.size, () => 0);
|
|
21883
22101
|
}
|
|
21884
22102
|
/**
|
|
@@ -21891,11 +22109,11 @@ var KiroSessionLog = class {
|
|
|
21891
22109
|
const found = [];
|
|
21892
22110
|
for (const name of names) {
|
|
21893
22111
|
if (!name.endsWith(".json")) continue;
|
|
21894
|
-
const meta3 = await readFile5(
|
|
22112
|
+
const meta3 = await readFile5(join12(this.directory, name), "utf8").then((text3) => JSON.parse(text3), () => void 0);
|
|
21895
22113
|
const created = meta3?.created_at ? Date.parse(meta3.created_at) : NaN;
|
|
21896
22114
|
if (meta3?.cwd && sameFolder(meta3.cwd, this.options.workdir) && created >= this.options.startedAt - 2e3) found.push(name.slice(0, -5));
|
|
21897
22115
|
}
|
|
21898
|
-
if (found.length === 1) this.path =
|
|
22116
|
+
if (found.length === 1) this.path = join12(this.directory, `${found[0]}.jsonl`);
|
|
21899
22117
|
}
|
|
21900
22118
|
/** Reads entries appended since the last call. */
|
|
21901
22119
|
async refresh() {
|
|
@@ -22206,7 +22424,7 @@ var KIRO_ACP_DIALECT = {
|
|
|
22206
22424
|
};
|
|
22207
22425
|
|
|
22208
22426
|
// src/acp/acp-dialects/omp-dialect.ts
|
|
22209
|
-
function
|
|
22427
|
+
function normalizeToolUpdate2(update) {
|
|
22210
22428
|
const rawOutput = record2(update.rawOutput);
|
|
22211
22429
|
if (!Array.isArray(rawOutput.content)) return update;
|
|
22212
22430
|
if (["exitCode", "exit_code", "stdout", "stderr"].some((key) => rawOutput[key] !== void 0)) return update;
|
|
@@ -22222,7 +22440,7 @@ function normalizeToolUpdate(update) {
|
|
|
22222
22440
|
};
|
|
22223
22441
|
}
|
|
22224
22442
|
var OMP_ACP_DIALECT = {
|
|
22225
|
-
normalizeToolUpdate,
|
|
22443
|
+
normalizeToolUpdate: normalizeToolUpdate2,
|
|
22226
22444
|
promptErrorDetail: (error62) => {
|
|
22227
22445
|
const details = record2(error62.data).details;
|
|
22228
22446
|
return typeof details === "string" && details ? details : void 0;
|
|
@@ -22234,7 +22452,7 @@ var OMP_ACP_DIALECT = {
|
|
|
22234
22452
|
};
|
|
22235
22453
|
|
|
22236
22454
|
// src/acp/acp-dialects/opencode-dialect.ts
|
|
22237
|
-
function
|
|
22455
|
+
function normalizeToolUpdate3(update) {
|
|
22238
22456
|
const raw = update.rawOutput;
|
|
22239
22457
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return update;
|
|
22240
22458
|
const rawOutput = raw;
|
|
@@ -22254,7 +22472,7 @@ function normalizeToolUpdate2(update) {
|
|
|
22254
22472
|
};
|
|
22255
22473
|
}
|
|
22256
22474
|
var OPENCODE_ACP_DIALECT = {
|
|
22257
|
-
normalizeToolUpdate:
|
|
22475
|
+
normalizeToolUpdate: normalizeToolUpdate3,
|
|
22258
22476
|
failureRules: [
|
|
22259
22477
|
{ kind: "usageLimit", pattern: /"errorName"\s*:\s*"provider\.quota"/ },
|
|
22260
22478
|
{ kind: "rateLimited", pattern: /"errorName"\s*:\s*"provider\.rate-limit"/ }
|
|
@@ -22264,9 +22482,9 @@ var OPENCODE_ACP_DIALECT = {
|
|
|
22264
22482
|
// src/acp/vendor.ts
|
|
22265
22483
|
import { spawn as spawn6 } from "node:child_process";
|
|
22266
22484
|
import { createHash } from "node:crypto";
|
|
22267
|
-
import { existsSync as existsSync6, readFileSync as
|
|
22485
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "node:fs";
|
|
22268
22486
|
import { copyFile, mkdir as mkdir4, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
22269
|
-
import { dirname as dirname7, join as
|
|
22487
|
+
import { dirname as dirname7, join as join13, resolve as resolve4 } from "node:path";
|
|
22270
22488
|
import { fileURLToPath } from "node:url";
|
|
22271
22489
|
var AcpRuntimeUnavailable = class extends Error {
|
|
22272
22490
|
constructor(message) {
|
|
@@ -22281,7 +22499,7 @@ function packageRoot() {
|
|
|
22281
22499
|
const path = resolve4(directory, "package.json");
|
|
22282
22500
|
if (existsSync6(path)) {
|
|
22283
22501
|
try {
|
|
22284
|
-
if (JSON.parse(
|
|
22502
|
+
if (JSON.parse(readFileSync6(path, "utf8")).name === "toc-ocra") return directory;
|
|
22285
22503
|
} catch {
|
|
22286
22504
|
}
|
|
22287
22505
|
}
|
|
@@ -22299,29 +22517,29 @@ function agentPackageVersion() {
|
|
|
22299
22517
|
const directory = agentRoot();
|
|
22300
22518
|
if (!directory) return "0";
|
|
22301
22519
|
try {
|
|
22302
|
-
return JSON.parse(
|
|
22520
|
+
return JSON.parse(readFileSync6(join13(directory, "package.json"), "utf8")).version ?? "0";
|
|
22303
22521
|
} catch {
|
|
22304
22522
|
return "0";
|
|
22305
22523
|
}
|
|
22306
22524
|
}
|
|
22307
22525
|
function vendoredAdapter(name) {
|
|
22308
22526
|
const directory = agentRoot();
|
|
22309
|
-
const entry = directory ?
|
|
22527
|
+
const entry = directory ? join13(directory, "assets", "acp", name, "index.mjs") : void 0;
|
|
22310
22528
|
return entry && existsSync6(entry) ? entry : void 0;
|
|
22311
22529
|
}
|
|
22312
22530
|
var installs = /* @__PURE__ */ new Map();
|
|
22313
22531
|
function ensureClaudeRuntime(dataDir2) {
|
|
22314
22532
|
const entry = vendoredAdapter("claude");
|
|
22315
22533
|
if (!entry) return Promise.reject(new AcpRuntimeUnavailable("\u8FD9\u4E2A\u7248\u672C\u7684\u8BBE\u5907\u4EE3\u7406\u6CA1\u6709\u9644\u5E26 Claude ACP \u9002\u914D\u5668"));
|
|
22316
|
-
const manifestPath =
|
|
22534
|
+
const manifestPath = join13(dirname7(entry), "runtime.json");
|
|
22317
22535
|
let manifest;
|
|
22318
22536
|
try {
|
|
22319
|
-
manifest = JSON.parse(
|
|
22537
|
+
manifest = JSON.parse(readFileSync6(manifestPath, "utf8"));
|
|
22320
22538
|
} catch {
|
|
22321
22539
|
return Promise.reject(new AcpRuntimeUnavailable("Claude ACP \u9002\u914D\u5668\u7F3A\u5C11 runtime.json"));
|
|
22322
22540
|
}
|
|
22323
|
-
const hash2 = createHash("sha256").update(
|
|
22324
|
-
const directory =
|
|
22541
|
+
const hash2 = createHash("sha256").update(readFileSync6(entry)).digest("hex").slice(0, 12);
|
|
22542
|
+
const directory = join13(dataDir2, "acp-runtimes", `claude-${manifest.adapterVersion}-sdk-${manifest.sdk.version}-${hash2}`);
|
|
22325
22543
|
const existing = installs.get(directory);
|
|
22326
22544
|
if (existing) return existing;
|
|
22327
22545
|
const install = installClaudeRuntime(directory, entry, manifest).catch((error62) => {
|
|
@@ -22332,19 +22550,19 @@ function ensureClaudeRuntime(dataDir2) {
|
|
|
22332
22550
|
return install;
|
|
22333
22551
|
}
|
|
22334
22552
|
async function installClaudeRuntime(directory, entry, manifest) {
|
|
22335
|
-
const sdkPackage =
|
|
22336
|
-
if (existsSync6(sdkPackage) && existsSync6(
|
|
22553
|
+
const sdkPackage = join13(directory, "node_modules", ...manifest.sdk.name.split("/"), "package.json");
|
|
22554
|
+
if (existsSync6(sdkPackage) && existsSync6(join13(directory, "index.mjs"))) return directory;
|
|
22337
22555
|
const temporary = `${directory}.tmp-${process.pid}-${Date.now()}`;
|
|
22338
22556
|
await mkdir4(temporary, { recursive: true, mode: 448 });
|
|
22339
22557
|
try {
|
|
22340
|
-
await writeFile4(
|
|
22558
|
+
await writeFile4(join13(temporary, "package.json"), JSON.stringify({
|
|
22341
22559
|
name: "toc-ocra-claude-acp-runtime",
|
|
22342
22560
|
private: true,
|
|
22343
22561
|
type: "module",
|
|
22344
22562
|
dependencies: { [manifest.sdk.name]: manifest.sdk.version }
|
|
22345
22563
|
}, null, 2));
|
|
22346
22564
|
await runNpm(["install", "--omit=optional", "--no-audit", "--no-fund", "--no-package-lock", "--loglevel=error"], temporary);
|
|
22347
|
-
await copyFile(entry,
|
|
22565
|
+
await copyFile(entry, join13(temporary, "index.mjs"));
|
|
22348
22566
|
await rm2(directory, { recursive: true, force: true });
|
|
22349
22567
|
await rename4(temporary, directory);
|
|
22350
22568
|
} catch (error62) {
|
|
@@ -22418,6 +22636,22 @@ var GEMINI_LAUNCH_SPEC = {
|
|
|
22418
22636
|
dialect: GEMINI_ACP_DIALECT,
|
|
22419
22637
|
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.gemini }
|
|
22420
22638
|
};
|
|
22639
|
+
var ANTIGRAVITY_LAUNCH_SPEC = {
|
|
22640
|
+
agent: "antigravity",
|
|
22641
|
+
headless: "acp",
|
|
22642
|
+
// agy has no full-access mode in session/set_mode; its launch flag grants it while plan approvals still reach the chat.
|
|
22643
|
+
args: ({ access }) => ["acp", ...access === "bypassPermissions" ? ["--dangerously-skip-permissions"] : []],
|
|
22644
|
+
env: { AGY_CLI_DISABLE_AUTO_UPDATE: "true" },
|
|
22645
|
+
scrubEnv: (env) => scrubAntigravityEnv(env),
|
|
22646
|
+
minimumVersions: ["1.5.2"],
|
|
22647
|
+
permissionModeConfig: {
|
|
22648
|
+
values: { ask: "default", acceptEdits: "accept-edits", bypassPermissions: "default", plan: "plan" }
|
|
22649
|
+
},
|
|
22650
|
+
resumePreference: "resume",
|
|
22651
|
+
dialect: ANTIGRAVITY_ACP_DIALECT,
|
|
22652
|
+
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.antigravity },
|
|
22653
|
+
runSettings: { permissionModes: ["read-only", "acceptEdits", "bypassPermissions"], plan: "native" }
|
|
22654
|
+
};
|
|
22421
22655
|
var GROK_LAUNCH_SPEC = {
|
|
22422
22656
|
agent: "grok",
|
|
22423
22657
|
headless: "acp",
|
|
@@ -22470,7 +22704,7 @@ var CLAUDE_LAUNCH_SPEC = {
|
|
|
22470
22704
|
const executable = installedCli(claude);
|
|
22471
22705
|
const runtime = await ensureClaudeRuntime(dataDir2);
|
|
22472
22706
|
return {
|
|
22473
|
-
launch: { executable: process.execPath, args: [
|
|
22707
|
+
launch: { executable: process.execPath, args: [join14(runtime, "index.mjs")], env: { ...providerEnvironment(), CLAUDE_CODE_EXECUTABLE: executable }, cwd: workdir },
|
|
22474
22708
|
fingerprint: `claude:${runtime}:${executable}`
|
|
22475
22709
|
};
|
|
22476
22710
|
},
|
|
@@ -22518,6 +22752,7 @@ var ACP_LAUNCH_SPECS = [
|
|
|
22518
22752
|
KIRO_LAUNCH_SPEC,
|
|
22519
22753
|
KIMI_LAUNCH_SPEC,
|
|
22520
22754
|
GEMINI_LAUNCH_SPEC,
|
|
22755
|
+
ANTIGRAVITY_LAUNCH_SPEC,
|
|
22521
22756
|
GROK_LAUNCH_SPEC,
|
|
22522
22757
|
OPENCODE_LAUNCH_SPEC,
|
|
22523
22758
|
OMP_LAUNCH_SPEC,
|
|
@@ -22565,7 +22800,9 @@ function chatSpec(row) {
|
|
|
22565
22800
|
async launch({ access, model, reasoningEffort, workdir, dataDir: dataDir2 }) {
|
|
22566
22801
|
if (row.adapter) return row.adapter({ access, model, reasoningEffort, workdir, dataDir: dataDir2 });
|
|
22567
22802
|
const args = row.args({ access, model, reasoningEffort });
|
|
22568
|
-
const
|
|
22803
|
+
const baseEnv = { ...providerEnvironment(), ...row.env };
|
|
22804
|
+
const env = row.scrubEnv ? row.scrubEnv(baseEnv) : baseEnv;
|
|
22805
|
+
const spec = launchCli({ spec: cli, args, env });
|
|
22569
22806
|
return { launch: { executable: spec.executable, args: spec.args, env: spec.env, cwd: workdir }, fingerprint: args.join(" ") };
|
|
22570
22807
|
},
|
|
22571
22808
|
...row.permissionModeConfig ? { modeFor: (access, plan) => acpModeFor(row, access, plan) } : {},
|
|
@@ -22589,7 +22826,7 @@ var ACP_CHAT_IDS = [...ACP_CHAT.keys()];
|
|
|
22589
22826
|
// src/acp/acp-model-catalog-probe.ts
|
|
22590
22827
|
import { mkdtemp, rm as rm3 } from "node:fs/promises";
|
|
22591
22828
|
import { tmpdir } from "node:os";
|
|
22592
|
-
import { join as
|
|
22829
|
+
import { join as join15 } from "node:path";
|
|
22593
22830
|
|
|
22594
22831
|
// src/acp/acp-options.ts
|
|
22595
22832
|
var text = (value) => typeof value === "string" && value ? value : void 0;
|
|
@@ -22668,7 +22905,8 @@ function settingWrite(state, step, settings, cliLabel) {
|
|
|
22668
22905
|
if (!model) return {};
|
|
22669
22906
|
const option = findOption(state.configOptions, "model");
|
|
22670
22907
|
if (option) {
|
|
22671
|
-
const
|
|
22908
|
+
const stripped = /^(.+)-(?:low|medium|high|xhigh|max)$/i.exec(model)?.[1];
|
|
22909
|
+
const value = matchChoice(option, model) ?? (stripped ? matchChoice(option, stripped) : void 0);
|
|
22672
22910
|
if (!value) return { note: `${cliLabel} \u6CA1\u6709\u6A21\u578B\u300C${model}\u300D\uFF0C\u672C\u8F6E\u4F7F\u7528\u5F53\u524D\u6A21\u578B` };
|
|
22673
22911
|
return option.currentValue === value ? {} : config2(option, value);
|
|
22674
22912
|
}
|
|
@@ -22676,9 +22914,11 @@ function settingWrite(state, step, settings, cliLabel) {
|
|
|
22676
22914
|
return state.currentModelId === model ? {} : { write: { step, label: STEP_LABEL[step], method: "session/set_model", params: { modelId: model } } };
|
|
22677
22915
|
}
|
|
22678
22916
|
case "effort": {
|
|
22679
|
-
|
|
22917
|
+
const inferred = settings.model ? /^.+-(low|medium|high|xhigh|max)$/i.exec(settings.model)?.[1] : void 0;
|
|
22918
|
+
const wantedEffort = settings.reasoningEffort || inferred;
|
|
22919
|
+
if (!wantedEffort) return {};
|
|
22680
22920
|
const option = findOption(state.configOptions, "thought_level");
|
|
22681
|
-
const value = option ? matchChoice(option,
|
|
22921
|
+
const value = option ? matchChoice(option, wantedEffort) : void 0;
|
|
22682
22922
|
return option && value && option.currentValue !== value ? config2(option, value) : {};
|
|
22683
22923
|
}
|
|
22684
22924
|
case "fast": {
|
|
@@ -23222,9 +23462,9 @@ async function readSessionModels(row, clientVersion = "1") {
|
|
|
23222
23462
|
const discovery = row.modelDiscovery;
|
|
23223
23463
|
if (discovery.kind !== "session") throw new Error(`${row.agent} does not list its models in a session`);
|
|
23224
23464
|
const cli = requireCliSpec(row.agent);
|
|
23225
|
-
const folder = await mkdtemp(
|
|
23465
|
+
const folder = await mkdtemp(join15(tmpdir(), `toc-ocra-acp-models-${row.agent}-`));
|
|
23226
23466
|
try {
|
|
23227
|
-
const folderArgs = discovery.sessionFolderArgs?.(
|
|
23467
|
+
const folderArgs = discovery.sessionFolderArgs?.(join15(folder, "sessions")) ?? [];
|
|
23228
23468
|
const args = [...row.args({ access: "read-only", model: "", reasoningEffort: "" }), ...folderArgs];
|
|
23229
23469
|
const launch = launchCli({ spec: cli, args, env: { ...providerEnvironment(), ...row.env } });
|
|
23230
23470
|
const connection = await AcpConnection.open({ executable: launch.executable, args: launch.args, env: launch.env, cwd: folder }, {
|
|
@@ -23853,14 +24093,14 @@ function isWriterConflict(message) {
|
|
|
23853
24093
|
}
|
|
23854
24094
|
|
|
23855
24095
|
// src/providers/cli/claude.ts
|
|
23856
|
-
import { readdirSync as readdirSync4, readFileSync as
|
|
23857
|
-
import { homedir as
|
|
23858
|
-
import { join as
|
|
24096
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync7 } from "node:fs";
|
|
24097
|
+
import { homedir as homedir10 } from "node:os";
|
|
24098
|
+
import { join as join16 } from "node:path";
|
|
23859
24099
|
var CLAUDE = requireCliSpec("claude");
|
|
23860
24100
|
function claudeProjectRoots() {
|
|
23861
24101
|
const configured = process.env.CLAUDE_CONFIG_DIR;
|
|
23862
|
-
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [
|
|
23863
|
-
return dirs.map((dir) =>
|
|
24102
|
+
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [join16(homedir10(), ".claude")];
|
|
24103
|
+
return dirs.map((dir) => join16(dir, "projects"));
|
|
23864
24104
|
}
|
|
23865
24105
|
function claudeTranscriptExists(sessionId) {
|
|
23866
24106
|
return claudeTranscriptPath(sessionId) !== void 0;
|
|
@@ -23876,7 +24116,7 @@ function claudeTranscriptPath(sessionId) {
|
|
|
23876
24116
|
}
|
|
23877
24117
|
for (const project of projects) {
|
|
23878
24118
|
try {
|
|
23879
|
-
if (readdirSync4(
|
|
24119
|
+
if (readdirSync4(join16(root2, project)).includes(file2)) return join16(root2, project, file2);
|
|
23880
24120
|
} catch {
|
|
23881
24121
|
}
|
|
23882
24122
|
}
|
|
@@ -23920,7 +24160,7 @@ var claudeProvider = {
|
|
|
23920
24160
|
settings.disableAllHooks = true;
|
|
23921
24161
|
args.push("--restricted", "--permission-mode", "plan", "--tools", "Read,Glob,Grep", "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--disallowedTools", "mcp__*");
|
|
23922
24162
|
try {
|
|
23923
|
-
const userSettings = JSON.parse(
|
|
24163
|
+
const userSettings = JSON.parse(readFileSync7(join16(homedir10(), ".claude", "settings.json"), "utf8"));
|
|
23924
24164
|
for (const [key, value] of Object.entries(userSettings.env ?? {})) {
|
|
23925
24165
|
if (/^ANTHROPIC_[A-Z0-9_]+$/.test(key) && typeof value === "string" && env[key] === void 0) env[key] = value;
|
|
23926
24166
|
}
|
|
@@ -23936,7 +24176,7 @@ var claudeProvider = {
|
|
|
23936
24176
|
if (source && request.fork.keepTurns > 0) {
|
|
23937
24177
|
let text3 = "";
|
|
23938
24178
|
try {
|
|
23939
|
-
text3 =
|
|
24179
|
+
text3 = readFileSync7(source, "utf8");
|
|
23940
24180
|
} catch {
|
|
23941
24181
|
}
|
|
23942
24182
|
const at = claudeForkBoundary(text3, request.fork.keepTurns);
|
|
@@ -24654,7 +24894,8 @@ function createAcpProvider(row) {
|
|
|
24654
24894
|
...turn.reasoningEffort && !row.launchApplies?.reasoningEffort ? { reasoningEffort: turn.reasoningEffort } : {},
|
|
24655
24895
|
...row.runSettings?.fast && turn.fast !== void 0 ? { fast: turn.fast } : {}
|
|
24656
24896
|
};
|
|
24657
|
-
const
|
|
24897
|
+
const baseEnv = { ...providerEnvironment(), ...row.env };
|
|
24898
|
+
const env = row.scrubEnv ? row.scrubEnv(baseEnv) : baseEnv;
|
|
24658
24899
|
launchEnv = env;
|
|
24659
24900
|
return launchCli({ spec: cli, args: row.args({ access, model: turn.model, reasoningEffort: turn.reasoningEffort }), env });
|
|
24660
24901
|
},
|
|
@@ -24731,11 +24972,229 @@ var opencodeProvider = {
|
|
|
24731
24972
|
}
|
|
24732
24973
|
};
|
|
24733
24974
|
|
|
24975
|
+
// src/providers/antigravity-quota.ts
|
|
24976
|
+
import { spawn as spawn8 } from "node:child_process";
|
|
24977
|
+
var ANTIGRAVITY_MIN_USAGE_VERSION = "1.1.11";
|
|
24978
|
+
var ANTIGRAVITY_USAGE_ARGS = ["-p", "/usage", "--output-format", "json", "--print-timeout", "20s"];
|
|
24979
|
+
var VERSION_TIMEOUT_MS = 5e3;
|
|
24980
|
+
var USAGE_TIMEOUT_MS = 3e4;
|
|
24981
|
+
var MAX_OUTPUT_BYTES = 512 * 1024;
|
|
24982
|
+
var AGY_ERROR_PREFIX = "AGY_ERROR:";
|
|
24983
|
+
var WEEKLY_WINDOW_SECONDS = 7 * 86400;
|
|
24984
|
+
var SESSION_WINDOW_SECONDS = 5 * 3600;
|
|
24985
|
+
var SIGNED_OUT_PHRASES = [
|
|
24986
|
+
"not logged into antigravity",
|
|
24987
|
+
"not logged in",
|
|
24988
|
+
"not signed in",
|
|
24989
|
+
"not authenticated",
|
|
24990
|
+
"not-authenticated",
|
|
24991
|
+
"unauthenticated",
|
|
24992
|
+
"run agy login",
|
|
24993
|
+
"please sign in",
|
|
24994
|
+
"please log in",
|
|
24995
|
+
"sign in to antigravity",
|
|
24996
|
+
"no credentials",
|
|
24997
|
+
"authentication required"
|
|
24998
|
+
];
|
|
24999
|
+
var unsupportedUsageLatched = false;
|
|
25000
|
+
function isRecord(value) {
|
|
25001
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25002
|
+
}
|
|
25003
|
+
function readString(value) {
|
|
25004
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
25005
|
+
}
|
|
25006
|
+
function parseResetSeconds(value) {
|
|
25007
|
+
const text3 = readString(value);
|
|
25008
|
+
if (!text3) return 0;
|
|
25009
|
+
const ms = Date.parse(text3);
|
|
25010
|
+
return Number.isFinite(ms) ? Math.floor(ms / 1e3) : 0;
|
|
25011
|
+
}
|
|
25012
|
+
function windowSecondsFor(window) {
|
|
25013
|
+
if (window === "weekly") return WEEKLY_WINDOW_SECONDS;
|
|
25014
|
+
if (window === "5h") return SESSION_WINDOW_SECONDS;
|
|
25015
|
+
return void 0;
|
|
25016
|
+
}
|
|
25017
|
+
function shortGroupLabel(groupName) {
|
|
25018
|
+
const lower = groupName.toLowerCase();
|
|
25019
|
+
if (lower === "gemini models" || lower === "gemini") return "Gemini";
|
|
25020
|
+
if (lower === "claude and gpt models" || lower === "claude & gpt models") return "Claude / GPT";
|
|
25021
|
+
return groupName.replace(/\s+models$/i, "").trim() || groupName;
|
|
25022
|
+
}
|
|
25023
|
+
function shortWindowLabel(window, rawName) {
|
|
25024
|
+
if (window === "weekly") return "\u6BCF\u5468\u989D\u5EA6";
|
|
25025
|
+
if (window === "5h") return "5 \u5C0F\u65F6\u989D\u5EA6";
|
|
25026
|
+
if (!rawName) return "\u989D\u5EA6";
|
|
25027
|
+
return rawName.replace(/\s+(?:remaining|used|left)$/i, "").trim() || rawName;
|
|
25028
|
+
}
|
|
25029
|
+
function formatBucketLabel(groupName, window, rawName, siblings) {
|
|
25030
|
+
const group = shortGroupLabel(groupName);
|
|
25031
|
+
const win = shortWindowLabel(window, rawName);
|
|
25032
|
+
return siblings <= 1 && !window && !rawName ? group : `${group} \xB7 ${win}`;
|
|
25033
|
+
}
|
|
25034
|
+
function findEnvelope(stdout, parse4) {
|
|
25035
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
25036
|
+
const trimmed = line.trim();
|
|
25037
|
+
if (!trimmed.startsWith("{")) continue;
|
|
25038
|
+
try {
|
|
25039
|
+
const found = parse4(JSON.parse(trimmed));
|
|
25040
|
+
if (found !== null) return found;
|
|
25041
|
+
} catch {
|
|
25042
|
+
continue;
|
|
25043
|
+
}
|
|
25044
|
+
}
|
|
25045
|
+
return null;
|
|
25046
|
+
}
|
|
25047
|
+
function antigravityStdoutShowsModelTurn(stdout) {
|
|
25048
|
+
return findEnvelope(stdout, (value) => {
|
|
25049
|
+
if (!isRecord(value)) return null;
|
|
25050
|
+
if (typeof value.num_turns === "number" && value.num_turns > 0) return true;
|
|
25051
|
+
return readString(value.conversation_id) !== null ? true : null;
|
|
25052
|
+
}) !== null;
|
|
25053
|
+
}
|
|
25054
|
+
function parseAntigravityUsageEnvelope(value) {
|
|
25055
|
+
if (!isRecord(value) || readString(value.status) !== "SUCCESS") return null;
|
|
25056
|
+
const command = value.command;
|
|
25057
|
+
if (!isRecord(command) || readString(command.name) !== "usage") return null;
|
|
25058
|
+
const data = command.data;
|
|
25059
|
+
if (!isRecord(data) || !Array.isArray(data.groups)) return null;
|
|
25060
|
+
const windows = [];
|
|
25061
|
+
for (const rawGroup of data.groups) {
|
|
25062
|
+
if (!isRecord(rawGroup)) continue;
|
|
25063
|
+
const groupName = readString(rawGroup.name);
|
|
25064
|
+
const rawBuckets = Array.isArray(rawGroup.buckets) ? rawGroup.buckets : [];
|
|
25065
|
+
if (!groupName) continue;
|
|
25066
|
+
const enabled = rawBuckets.filter((item) => isRecord(item) && item.disabled !== true);
|
|
25067
|
+
for (const bucket of enabled) {
|
|
25068
|
+
const id = readString(bucket.id);
|
|
25069
|
+
const fraction = bucket.remaining_fraction;
|
|
25070
|
+
if (!id || typeof fraction !== "number" || !Number.isFinite(fraction)) continue;
|
|
25071
|
+
const windowKind = readString(bucket.window);
|
|
25072
|
+
const windowSeconds = windowSecondsFor(windowKind);
|
|
25073
|
+
const usedPercent = Math.min(100, Math.max(0, Math.round((1 - fraction) * 1e4) / 100));
|
|
25074
|
+
windows.push({
|
|
25075
|
+
key: `antigravity:${id}`,
|
|
25076
|
+
label: formatBucketLabel(groupName, windowKind, readString(bucket.name), enabled.length),
|
|
25077
|
+
used_percent: usedPercent,
|
|
25078
|
+
resets_at: parseResetSeconds(bucket.reset_time),
|
|
25079
|
+
...windowSeconds ? { window_seconds: windowSeconds } : {}
|
|
25080
|
+
});
|
|
25081
|
+
}
|
|
25082
|
+
}
|
|
25083
|
+
if (data.groups.length > 0 && windows.length === 0) return null;
|
|
25084
|
+
return windows;
|
|
25085
|
+
}
|
|
25086
|
+
function parseAntigravityUsageStdout(stdout) {
|
|
25087
|
+
return findEnvelope(stdout, parseAntigravityUsageEnvelope);
|
|
25088
|
+
}
|
|
25089
|
+
function readAgyErrorEnvelope(stdout) {
|
|
25090
|
+
return findEnvelope(
|
|
25091
|
+
stdout,
|
|
25092
|
+
(value) => isRecord(value) && readString(value.status) === "ERROR" ? readString(value.error) : null
|
|
25093
|
+
);
|
|
25094
|
+
}
|
|
25095
|
+
function classifyFailure(output2, stderr) {
|
|
25096
|
+
if (stderr.includes("Authentication required. Please visit the URL")) {
|
|
25097
|
+
return "Antigravity \u672A\u767B\u5F55\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u5B8C\u6210\u540E\u518D\u540C\u6B65\u989D\u5EA6";
|
|
25098
|
+
}
|
|
25099
|
+
for (const line of output2.split(/\r?\n/)) {
|
|
25100
|
+
const idx = line.indexOf(AGY_ERROR_PREFIX);
|
|
25101
|
+
if (idx === -1) continue;
|
|
25102
|
+
const payload = line.slice(idx + AGY_ERROR_PREFIX.length).trim();
|
|
25103
|
+
if (!payload.startsWith("{")) continue;
|
|
25104
|
+
try {
|
|
25105
|
+
const parsed = JSON.parse(payload);
|
|
25106
|
+
const status = typeof parsed.status === "string" ? parsed.status.toUpperCase() : "";
|
|
25107
|
+
const code = typeof parsed.error_code === "number" ? parsed.error_code : null;
|
|
25108
|
+
if (status === "UNAUTHENTICATED" || code === 401) return "Antigravity \u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u91CD\u65B0\u767B\u5F55";
|
|
25109
|
+
if (status === "PERMISSION_DENIED" || code === 403) return "\u5F53\u524D Antigravity \u8D26\u53F7\u6CA1\u6709\u53EF\u7528\u7684\u8BA2\u9605\u989D\u5EA6\u6743\u9650";
|
|
25110
|
+
if (status === "RESOURCE_EXHAUSTED" || code === 429) return "Antigravity \u989D\u5EA6\u63A5\u53E3\u6682\u65F6\u9650\u6D41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5";
|
|
25111
|
+
if (code !== null && code >= 500 && code < 600) return `Antigravity \u670D\u52A1\u7AEF\u8FD4\u56DE\u9519\u8BEF (${code})`;
|
|
25112
|
+
} catch {
|
|
25113
|
+
continue;
|
|
25114
|
+
}
|
|
25115
|
+
}
|
|
25116
|
+
const lowered = output2.toLowerCase();
|
|
25117
|
+
if (SIGNED_OUT_PHRASES.some((phrase) => lowered.includes(phrase))) {
|
|
25118
|
+
return "Antigravity \u672A\u767B\u5F55\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u5B8C\u6210\u540E\u518D\u540C\u6B65\u989D\u5EA6";
|
|
25119
|
+
}
|
|
25120
|
+
return null;
|
|
25121
|
+
}
|
|
25122
|
+
function runCommand(executable, args, env, timeoutMs) {
|
|
25123
|
+
return new Promise((resolve9, reject) => {
|
|
25124
|
+
const child = spawn8(executable, [...args], { env, stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
25125
|
+
let stdout = "";
|
|
25126
|
+
let stderr = "";
|
|
25127
|
+
let timedOut = false;
|
|
25128
|
+
const append = (current, chunk) => {
|
|
25129
|
+
if (current.length >= MAX_OUTPUT_BYTES) return current;
|
|
25130
|
+
return current + chunk.toString("utf8", 0, Math.max(0, MAX_OUTPUT_BYTES - current.length));
|
|
25131
|
+
};
|
|
25132
|
+
const timer = setTimeout(() => {
|
|
25133
|
+
timedOut = true;
|
|
25134
|
+
child.kill("SIGKILL");
|
|
25135
|
+
}, timeoutMs);
|
|
25136
|
+
child.stdout.on("data", (chunk) => {
|
|
25137
|
+
stdout = append(stdout, chunk);
|
|
25138
|
+
});
|
|
25139
|
+
child.stderr.on("data", (chunk) => {
|
|
25140
|
+
stderr = append(stderr, chunk);
|
|
25141
|
+
});
|
|
25142
|
+
child.on("error", (error62) => {
|
|
25143
|
+
clearTimeout(timer);
|
|
25144
|
+
reject(error62);
|
|
25145
|
+
});
|
|
25146
|
+
child.on("close", (code) => {
|
|
25147
|
+
clearTimeout(timer);
|
|
25148
|
+
resolve9({ code, stdout, stderr, timedOut });
|
|
25149
|
+
});
|
|
25150
|
+
});
|
|
25151
|
+
}
|
|
25152
|
+
async function readAntigravityQuotaWindows() {
|
|
25153
|
+
if (unsupportedUsageLatched) {
|
|
25154
|
+
throw new Error("\u5F53\u524D\u7248\u672C\u7684 Antigravity CLI \u4E0D\u652F\u6301 /usage \u547D\u4EE4\uFF0C\u8BF7\u5347\u7EA7 agy \u540E\u91CD\u542F\u8BBE\u5907\u4EE3\u7406");
|
|
25155
|
+
}
|
|
25156
|
+
const spec = requireCliSpec("antigravity");
|
|
25157
|
+
const baseEnv = mergeShellProxyEnvironment(await hydrateShellPath(), providerEnvironment());
|
|
25158
|
+
const env = scrubAntigravityEnv(baseEnv);
|
|
25159
|
+
const versionLaunch = launchCli({ spec, args: ["--version"], env });
|
|
25160
|
+
const versionRun = await runCommand(versionLaunch.executable, versionLaunch.args, versionLaunch.env ?? env, VERSION_TIMEOUT_MS).catch((error62) => {
|
|
25161
|
+
const message = error62 instanceof Error ? error62.message : String(error62);
|
|
25162
|
+
if (/ENOENT/i.test(message)) throw new Error("\u672C\u673A\u672A\u5B89\u88C5 Antigravity CLI\uFF08agy\uFF09");
|
|
25163
|
+
throw new Error(`\u65E0\u6CD5\u542F\u52A8 Antigravity CLI\uFF1A${message}`);
|
|
25164
|
+
});
|
|
25165
|
+
const detected = versionRun.code === 0 && !versionRun.timedOut ? versionNumber(versionRun.stdout.trim() || versionRun.stderr.trim()) : void 0;
|
|
25166
|
+
if (!detected || compareVersions(detected, ANTIGRAVITY_MIN_USAGE_VERSION) < 0) {
|
|
25167
|
+
throw new Error(
|
|
25168
|
+
detected ? `Antigravity \u989D\u5EA6\u8BFB\u53D6\u9700\u8981 agy ${ANTIGRAVITY_MIN_USAGE_VERSION} \u6216\u66F4\u65B0\u7248\u672C\uFF08\u5F53\u524D ${detected}\uFF09` : "\u65E0\u6CD5\u8BFB\u53D6 Antigravity CLI \u7248\u672C\uFF0C\u8BF7\u786E\u8BA4 agy \u5DF2\u6B63\u786E\u5B89\u88C5"
|
|
25169
|
+
);
|
|
25170
|
+
}
|
|
25171
|
+
const usageLaunch = launchCli({ spec, args: [...ANTIGRAVITY_USAGE_ARGS], env });
|
|
25172
|
+
const result = await runCommand(usageLaunch.executable, usageLaunch.args, usageLaunch.env ?? env, USAGE_TIMEOUT_MS);
|
|
25173
|
+
const windows = parseAntigravityUsageStdout(result.stdout);
|
|
25174
|
+
if (!windows) {
|
|
25175
|
+
const classified = classifyFailure(`${result.stdout}
|
|
25176
|
+
${result.stderr}`, result.stderr);
|
|
25177
|
+
if (classified) throw new Error(classified);
|
|
25178
|
+
if (result.timedOut) throw new Error("\u8BFB\u53D6 Antigravity \u989D\u5EA6\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
25179
|
+
if (antigravityStdoutShowsModelTurn(result.stdout)) {
|
|
25180
|
+
unsupportedUsageLatched = true;
|
|
25181
|
+
throw new Error("\u5F53\u524D\u7248\u672C\u7684 Antigravity CLI \u5C06 /usage \u5F53\u4F5C\u5BF9\u8BDD\u6267\u884C\uFF0C\u5DF2\u505C\u6B62\u8BFB\u53D6\u4EE5\u514D\u6D88\u8017\u989D\u5EA6\uFF0C\u8BF7\u5347\u7EA7 agy");
|
|
25182
|
+
}
|
|
25183
|
+
const envelopeError = readAgyErrorEnvelope(result.stdout);
|
|
25184
|
+
if (envelopeError) throw new Error(`Antigravity \u989D\u5EA6\u8BFB\u53D6\u5931\u8D25\uFF1A${envelopeError}`);
|
|
25185
|
+
throw new Error(`Antigravity \u672A\u8FD4\u56DE\u6709\u6548\u989D\u5EA6\u6570\u636E${result.code ? ` (exit ${result.code})` : ""}`);
|
|
25186
|
+
}
|
|
25187
|
+
if (windows.length === 0) {
|
|
25188
|
+
throw new Error("Antigravity \u5F53\u524D\u8D26\u53F7\u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u7684\u989D\u5EA6\u7A97\u53E3");
|
|
25189
|
+
}
|
|
25190
|
+
return windows;
|
|
25191
|
+
}
|
|
25192
|
+
|
|
24734
25193
|
// src/providers/claude-quota.ts
|
|
24735
25194
|
import { execFile as execFile5 } from "node:child_process";
|
|
24736
25195
|
import { readFile as readFile6 } from "node:fs/promises";
|
|
24737
|
-
import { homedir as
|
|
24738
|
-
import { join as
|
|
25196
|
+
import { homedir as homedir11 } from "node:os";
|
|
25197
|
+
import { join as join17 } from "node:path";
|
|
24739
25198
|
import { promisify as promisify3 } from "node:util";
|
|
24740
25199
|
var execFileAsync3 = promisify3(execFile5);
|
|
24741
25200
|
var CLAUDE_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
@@ -24774,7 +25233,7 @@ function parseClaudeQuota(body) {
|
|
|
24774
25233
|
}
|
|
24775
25234
|
return windows;
|
|
24776
25235
|
}
|
|
24777
|
-
var claudeHome2 = () => process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
25236
|
+
var claudeHome2 = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join17(homedir11(), ".claude");
|
|
24778
25237
|
function tokenFrom(content) {
|
|
24779
25238
|
try {
|
|
24780
25239
|
const token = objectValue2(objectValue2(JSON.parse(content)).claudeAiOauth).accessToken;
|
|
@@ -24786,7 +25245,7 @@ function tokenFrom(content) {
|
|
|
24786
25245
|
async function readClaudeAccessToken() {
|
|
24787
25246
|
const fromEnv = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
24788
25247
|
if (fromEnv) return fromEnv;
|
|
24789
|
-
const fromFile = tokenFrom(await readFile6(
|
|
25248
|
+
const fromFile = tokenFrom(await readFile6(join17(claudeHome2(), ".credentials.json"), "utf8").catch(() => ""));
|
|
24790
25249
|
if (fromFile) return fromFile;
|
|
24791
25250
|
if (process.platform !== "darwin") return void 0;
|
|
24792
25251
|
const { stdout } = await execFileAsync3("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 1e4 }).catch(() => ({ stdout: "" }));
|
|
@@ -24808,11 +25267,11 @@ async function readClaudeQuotaWindows() {
|
|
|
24808
25267
|
}
|
|
24809
25268
|
|
|
24810
25269
|
// src/providers/codex-quota.ts
|
|
24811
|
-
import { spawn as
|
|
25270
|
+
import { spawn as spawn9 } from "node:child_process";
|
|
24812
25271
|
import { createInterface as createInterface3 } from "node:readline";
|
|
24813
25272
|
async function readCodexQuotaWindows() {
|
|
24814
25273
|
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--stdio"] });
|
|
24815
|
-
const child =
|
|
25274
|
+
const child = spawn9(launch.executable, launch.args, { env: launch.env, stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
24816
25275
|
let nextId = 0;
|
|
24817
25276
|
const pending = /* @__PURE__ */ new Map();
|
|
24818
25277
|
const lines = createInterface3({ input: child.stdout });
|
|
@@ -24984,6 +25443,7 @@ var NATIVE = {
|
|
|
24984
25443
|
claude: { headless: claudeProvider, chat: (_request, attachments) => claudeChatProvider(attachments), models: MODEL_SOURCES.claude, quota: readClaudeQuotaWindows, runSettings: { permissionModes: ALL_LEVELS, plan: "native", fast: true } }
|
|
24985
25444
|
};
|
|
24986
25445
|
var ACP_EXTRAS = {
|
|
25446
|
+
antigravity: { quota: readAntigravityQuotaWindows },
|
|
24987
25447
|
kiro: { quota: readKiroQuotaWindows, legacy: { headless: kiroProvider, restrictedPermission: true, runSettings: { permissionModes: ["read-only", "bypassPermissions"], plan: "prompt" } } },
|
|
24988
25448
|
gemini: { legacy: { headless: geminiProvider, restrictedPermission: false } },
|
|
24989
25449
|
grok: { legacy: { headless: grokProvider, restrictedPermission: false } },
|
|
@@ -25083,7 +25543,7 @@ function probeVersion(path, args) {
|
|
|
25083
25543
|
if (args.length === 0) return Promise.resolve({});
|
|
25084
25544
|
return new Promise((resolve9) => {
|
|
25085
25545
|
const launch = directLaunch2(path, args, process.env.TOC_OCRA_NODE_PATH || process.execPath);
|
|
25086
|
-
const child =
|
|
25546
|
+
const child = spawn10(launch.executable, launch.args, { stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
25087
25547
|
let stdout = "";
|
|
25088
25548
|
let stderr = "";
|
|
25089
25549
|
let settled = false;
|
|
@@ -25167,10 +25627,10 @@ var cliDetection = new CliDetectionService();
|
|
|
25167
25627
|
|
|
25168
25628
|
// src/runtime/agent-runtime.ts
|
|
25169
25629
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
25170
|
-
import { join as
|
|
25630
|
+
import { join as join24 } from "node:path";
|
|
25171
25631
|
|
|
25172
25632
|
// src/exec/script-runner.ts
|
|
25173
|
-
import { spawn as
|
|
25633
|
+
import { spawn as spawn11 } from "node:child_process";
|
|
25174
25634
|
var MAX_SCRIPT_OUTPUT_BYTES = 112 * 1024;
|
|
25175
25635
|
function executeScript(command, workdir, timeoutSeconds) {
|
|
25176
25636
|
return new Promise((resolveExecution) => {
|
|
@@ -25201,7 +25661,7 @@ function executeScript(command, workdir, timeoutSeconds) {
|
|
|
25201
25661
|
};
|
|
25202
25662
|
let child;
|
|
25203
25663
|
try {
|
|
25204
|
-
child =
|
|
25664
|
+
child = spawn11(executable, args, {
|
|
25205
25665
|
cwd: workdir,
|
|
25206
25666
|
env: process.env,
|
|
25207
25667
|
detached: ownGroup,
|
|
@@ -25295,12 +25755,12 @@ var MemoryBindingSchema = external_exports.object({
|
|
|
25295
25755
|
memory_id: external_exports.string().trim().min(1).max(200)
|
|
25296
25756
|
});
|
|
25297
25757
|
var COMMAND_TIMEOUT_MS = 15e3;
|
|
25298
|
-
var
|
|
25758
|
+
var MAX_OUTPUT_BYTES2 = 1024 * 1024;
|
|
25299
25759
|
var runNmem = (args) => {
|
|
25300
25760
|
const env = providerEnvironment();
|
|
25301
25761
|
const launch = resolveExecutable("nmem", args, env, process.env.TOC_OCRA_NMEM_PATH);
|
|
25302
25762
|
return new Promise((resolve9) => {
|
|
25303
|
-
execFile7(launch.executable, launch.args, { env: launch.env, timeout: COMMAND_TIMEOUT_MS, maxBuffer:
|
|
25763
|
+
execFile7(launch.executable, launch.args, { env: launch.env, timeout: COMMAND_TIMEOUT_MS, maxBuffer: MAX_OUTPUT_BYTES2, windowsHide: true }, (error62, stdout) => {
|
|
25304
25764
|
if (!error62) {
|
|
25305
25765
|
resolve9({ stdout: String(stdout) });
|
|
25306
25766
|
return;
|
|
@@ -25456,15 +25916,15 @@ async function readCLIQuotaReport(agentType) {
|
|
|
25456
25916
|
|
|
25457
25917
|
// src/providers/tb-switch-control.ts
|
|
25458
25918
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
25459
|
-
import { homedir as
|
|
25460
|
-
import { join as
|
|
25919
|
+
import { homedir as homedir12 } from "node:os";
|
|
25920
|
+
import { join as join18 } from "node:path";
|
|
25461
25921
|
function dataDir() {
|
|
25462
|
-
return process.env.TB_SWITCH_HOME?.trim() ||
|
|
25922
|
+
return process.env.TB_SWITCH_HOME?.trim() || join18(homedir12(), ".tb-switch");
|
|
25463
25923
|
}
|
|
25464
25924
|
async function readLocalService() {
|
|
25465
25925
|
let discovery;
|
|
25466
25926
|
try {
|
|
25467
|
-
discovery = JSON.parse(await readFile7(
|
|
25927
|
+
discovery = JSON.parse(await readFile7(join18(dataDir(), "api.json"), "utf8"));
|
|
25468
25928
|
} catch {
|
|
25469
25929
|
throw new Error("\u8FD9\u53F0\u8BBE\u5907\u4E0A\u7684 TB Switch \u670D\u52A1\u672A\u8FD0\u884C\uFF0C\u8BF7\u6253\u5F00\u684C\u9762\u7AEF\u63D2\u4EF6\u540E\u91CD\u8BD5\u3002");
|
|
25470
25930
|
}
|
|
@@ -25480,7 +25940,7 @@ async function readLocalService() {
|
|
|
25480
25940
|
}
|
|
25481
25941
|
let token = process.env.TB_SWITCH_API_TOKEN?.trim() ?? "";
|
|
25482
25942
|
try {
|
|
25483
|
-
token = (await readFile7(
|
|
25943
|
+
token = (await readFile7(join18(dataDir(), "api-token"), "utf8")).trim();
|
|
25484
25944
|
} catch {
|
|
25485
25945
|
}
|
|
25486
25946
|
if (!token) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 TB Switch \u672C\u673A\u670D\u52A1\u51ED\u636E\uFF0C\u8BF7\u91CD\u542F\u684C\u9762\u7AEF\u63D2\u4EF6\u540E\u91CD\u8BD5\u3002");
|
|
@@ -25623,9 +26083,9 @@ function commandOf(pid) {
|
|
|
25623
26083
|
}
|
|
25624
26084
|
|
|
25625
26085
|
// src/runs/run-supervisor.ts
|
|
25626
|
-
import { spawn as
|
|
26086
|
+
import { spawn as spawn13 } from "node:child_process";
|
|
25627
26087
|
import { mkdir as mkdir8, realpath as realpath2, stat as stat6, writeFile as writeFile8 } from "node:fs/promises";
|
|
25628
|
-
import { basename as basename3, isAbsolute as isAbsolute4, join as
|
|
26088
|
+
import { basename as basename3, isAbsolute as isAbsolute4, join as join22, relative as relative2, resolve as resolve5 } from "node:path";
|
|
25629
26089
|
import { createInterface as createInterface5 } from "node:readline";
|
|
25630
26090
|
|
|
25631
26091
|
// src/session/terminal-tail-buffer.ts
|
|
@@ -25907,12 +26367,12 @@ function codexGoalProvider(request, goal) {
|
|
|
25907
26367
|
}
|
|
25908
26368
|
|
|
25909
26369
|
// src/providers/cli/codex-fork.ts
|
|
25910
|
-
import { spawn as
|
|
26370
|
+
import { spawn as spawn12 } from "node:child_process";
|
|
25911
26371
|
import { createInterface as createInterface4 } from "node:readline";
|
|
25912
26372
|
var FORK_TIMEOUT_MS = 9e4;
|
|
25913
26373
|
async function forkCodexThread(options) {
|
|
25914
26374
|
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--listen", "stdio://"] });
|
|
25915
|
-
const child =
|
|
26375
|
+
const child = spawn12(launch.executable, launch.args, {
|
|
25916
26376
|
cwd: options.workdir,
|
|
25917
26377
|
env: launch.env,
|
|
25918
26378
|
shell: false,
|
|
@@ -25987,19 +26447,19 @@ async function forkCodexThread(options) {
|
|
|
25987
26447
|
|
|
25988
26448
|
// src/runs/run-recorder.ts
|
|
25989
26449
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
25990
|
-
import { homedir as
|
|
25991
|
-
import { join as
|
|
26450
|
+
import { homedir as homedir13 } from "node:os";
|
|
26451
|
+
import { join as join19 } from "node:path";
|
|
25992
26452
|
var RunRecorder = class _RunRecorder {
|
|
25993
26453
|
constructor(path) {
|
|
25994
26454
|
this.path = path;
|
|
25995
26455
|
}
|
|
25996
26456
|
path;
|
|
25997
|
-
home =
|
|
26457
|
+
home = homedir13();
|
|
25998
26458
|
static fromEnvironment(runId, meta3) {
|
|
25999
26459
|
const directory = process.env.TOC_OCRA_RECORD_DIR?.trim();
|
|
26000
26460
|
if (!directory) return void 0;
|
|
26001
26461
|
mkdirSync3(directory, { recursive: true });
|
|
26002
|
-
const recorder = new _RunRecorder(
|
|
26462
|
+
const recorder = new _RunRecorder(join19(directory, `${String(meta3.agent ?? "cli")}-${runId}.jsonl`));
|
|
26003
26463
|
recorder.write({ meta: meta3 });
|
|
26004
26464
|
return recorder;
|
|
26005
26465
|
}
|
|
@@ -26015,7 +26475,7 @@ var RunRecorder = class _RunRecorder {
|
|
|
26015
26475
|
|
|
26016
26476
|
// src/runs/run-transcript.ts
|
|
26017
26477
|
import { chmod as chmod4, mkdir as mkdir6, readdir as readdir3, readFile as readFile9, rename as rename6, stat as stat4, unlink, writeFile as writeFile6 } from "node:fs/promises";
|
|
26018
|
-
import { join as
|
|
26478
|
+
import { join as join20 } from "node:path";
|
|
26019
26479
|
var MAX_TRANSCRIPT_ITEMS = 5e3;
|
|
26020
26480
|
var MAX_TRANSCRIPT_TEXT = 2e5;
|
|
26021
26481
|
var MAX_TRANSCRIPT_LINES = 2e4;
|
|
@@ -26280,7 +26740,7 @@ function transcriptFileName(runId) {
|
|
|
26280
26740
|
var TranscriptStore = class {
|
|
26281
26741
|
constructor(dataDir2, logger, env = process.env) {
|
|
26282
26742
|
this.logger = logger;
|
|
26283
|
-
this.directory = dataDir2 ?
|
|
26743
|
+
this.directory = dataDir2 ? join20(dataDir2, "transcripts") : "";
|
|
26284
26744
|
this.enabled = Boolean(dataDir2) && transcriptsOnDisk(env);
|
|
26285
26745
|
}
|
|
26286
26746
|
logger;
|
|
@@ -26335,7 +26795,7 @@ var TranscriptStore = class {
|
|
|
26335
26795
|
await this.writes.get(runId);
|
|
26336
26796
|
let text3;
|
|
26337
26797
|
try {
|
|
26338
|
-
text3 = await readFile9(
|
|
26798
|
+
text3 = await readFile9(join20(this.directory, name), "utf8");
|
|
26339
26799
|
} catch (error62) {
|
|
26340
26800
|
if (errorCode(error62) !== "ENOENT") this.logger.warn("run-transcript-read-failed", { runId, error: errorMessage(error62) });
|
|
26341
26801
|
return void 0;
|
|
@@ -26400,7 +26860,7 @@ var TranscriptStore = class {
|
|
|
26400
26860
|
transcript.dirty = false;
|
|
26401
26861
|
const body = JSON.stringify(transcript.toFile());
|
|
26402
26862
|
await this.ensureDirectory();
|
|
26403
|
-
const file2 =
|
|
26863
|
+
const file2 = join20(this.directory, name);
|
|
26404
26864
|
const temporary = `${file2}.${process.pid}.tmp`;
|
|
26405
26865
|
await writeFile6(temporary, body, { mode: 384 });
|
|
26406
26866
|
await rename6(temporary, file2);
|
|
@@ -26437,7 +26897,7 @@ var TranscriptStore = class {
|
|
|
26437
26897
|
const now = Date.now();
|
|
26438
26898
|
const files = [];
|
|
26439
26899
|
for (const name of names) {
|
|
26440
|
-
const path =
|
|
26900
|
+
const path = join20(this.directory, name);
|
|
26441
26901
|
if (name.endsWith(".tmp")) {
|
|
26442
26902
|
const info2 = await stat4(path).catch(() => void 0);
|
|
26443
26903
|
if (info2?.isFile() && now - info2.mtimeMs > STALE_TEMPORARY_MS) await unlink(path).catch(() => void 0);
|
|
@@ -26487,7 +26947,7 @@ function errorMessage(error62) {
|
|
|
26487
26947
|
import { createHash as createHash3, randomUUID as randomUUID2 } from "node:crypto";
|
|
26488
26948
|
import { constants as constants2 } from "node:fs";
|
|
26489
26949
|
import { lstat, mkdir as mkdir7, open as open3, realpath, rename as rename7, rm as rm4, writeFile as writeFile7 } from "node:fs/promises";
|
|
26490
|
-
import { basename as basename2, isAbsolute as isAbsolute3, join as
|
|
26950
|
+
import { basename as basename2, isAbsolute as isAbsolute3, join as join21, relative } from "node:path";
|
|
26491
26951
|
function within(root2, path) {
|
|
26492
26952
|
const segment = relative(root2, path);
|
|
26493
26953
|
return segment === "" || !segment.startsWith("..") && !isAbsolute3(segment);
|
|
@@ -26495,7 +26955,7 @@ function within(root2, path) {
|
|
|
26495
26955
|
async function attachmentDirectory(workdir, messageId) {
|
|
26496
26956
|
let directory = workdir;
|
|
26497
26957
|
for (const segment of [".echo", "attachments", `message-${encodeURIComponent(messageId).slice(0, 180)}`]) {
|
|
26498
|
-
directory =
|
|
26958
|
+
directory = join21(directory, segment);
|
|
26499
26959
|
await mkdir7(directory, { mode: 448 }).catch((error62) => {
|
|
26500
26960
|
if (error62.code !== "EEXIST") throw error62;
|
|
26501
26961
|
});
|
|
@@ -26503,7 +26963,7 @@ async function attachmentDirectory(workdir, messageId) {
|
|
|
26503
26963
|
if (metadata.isSymbolicLink() || !metadata.isDirectory() || !within(workdir, await realpath(directory))) {
|
|
26504
26964
|
throw new Error("\u9644\u4EF6\u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E CLI \u5DE5\u4F5C\u76EE\u5F55\u5185\uFF0C\u4E14\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5");
|
|
26505
26965
|
}
|
|
26506
|
-
if (segment === ".echo") await writeFile7(
|
|
26966
|
+
if (segment === ".echo") await writeFile7(join21(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
|
|
26507
26967
|
if (error62.code !== "EEXIST") throw error62;
|
|
26508
26968
|
});
|
|
26509
26969
|
}
|
|
@@ -26540,9 +27000,9 @@ async function prepareTaskAttachments(payload, workdir, download, signal2) {
|
|
|
26540
27000
|
const characters = Array.from(basename2(file2.name.replace(/\\/g, "/")).replace(/[^\p{L}\p{N}._-]/gu, "_").replace(/\.+$/u, ""));
|
|
26541
27001
|
while (Buffer.byteLength(characters.join("")) > 160) characters.shift();
|
|
26542
27002
|
const name = characters.join("") || "attachment";
|
|
26543
|
-
const path =
|
|
27003
|
+
const path = join21(directory, `${file2.file_id}-${name}`);
|
|
26544
27004
|
if (!await matches(path, file2.size, file2.sha256, signal2)) {
|
|
26545
|
-
const temporary =
|
|
27005
|
+
const temporary = join21(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
|
|
26546
27006
|
try {
|
|
26547
27007
|
await download(payload.run_id, file2.file_id, temporary, file2.size, file2.sha256, signal2);
|
|
26548
27008
|
signal2.throwIfAborted();
|
|
@@ -26662,29 +27122,29 @@ import { extname } from "node:path";
|
|
|
26662
27122
|
import { pathToFileURL } from "node:url";
|
|
26663
27123
|
|
|
26664
27124
|
// src/acp/ask-user-question.ts
|
|
26665
|
-
var
|
|
27125
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26666
27126
|
var getLodyMeta = (meta3) => {
|
|
26667
|
-
if (!
|
|
26668
|
-
return
|
|
27127
|
+
if (!isRecord2(meta3)) return null;
|
|
27128
|
+
return isRecord2(meta3.lody) ? meta3.lody : null;
|
|
26669
27129
|
};
|
|
26670
27130
|
var getClaudeCodeMeta = (meta3) => {
|
|
26671
|
-
if (!
|
|
26672
|
-
return
|
|
27131
|
+
if (!isRecord2(meta3)) return null;
|
|
27132
|
+
return isRecord2(meta3.claudeCode) ? meta3.claudeCode : null;
|
|
26673
27133
|
};
|
|
26674
27134
|
var getCodexMeta = (meta3) => {
|
|
26675
|
-
if (!
|
|
26676
|
-
return
|
|
27135
|
+
if (!isRecord2(meta3)) return null;
|
|
27136
|
+
return isRecord2(meta3.codex) ? meta3.codex : null;
|
|
26677
27137
|
};
|
|
26678
27138
|
var getLodyElicitationMeta = (meta3) => {
|
|
26679
27139
|
const elicitation = getLodyMeta(meta3)?.elicitation;
|
|
26680
|
-
return
|
|
27140
|
+
return isRecord2(elicitation) && elicitation.version === 1 ? elicitation : null;
|
|
26681
27141
|
};
|
|
26682
27142
|
function isAskUserQuestionPermission(params) {
|
|
26683
27143
|
const meta3 = params._meta;
|
|
26684
27144
|
const lody = getLodyElicitationMeta(meta3);
|
|
26685
27145
|
if (lody && Array.isArray(lody.questions)) return true;
|
|
26686
|
-
if (
|
|
26687
|
-
return
|
|
27146
|
+
if (isRecord2(getClaudeCodeMeta(meta3)?.askUserQuestion)) return true;
|
|
27147
|
+
return isRecord2(getCodexMeta(meta3)?.requestUserInput);
|
|
26688
27148
|
}
|
|
26689
27149
|
function hasValidNoteKeys(questions) {
|
|
26690
27150
|
if (!questions.some((question) => question.note)) return true;
|
|
@@ -26708,18 +27168,18 @@ function getAskUserQuestionAnswerKey(questions, index) {
|
|
|
26708
27168
|
}
|
|
26709
27169
|
var getLodyOutcomeAnswers = (outcomeMeta) => {
|
|
26710
27170
|
const elicitation = getLodyMeta(outcomeMeta)?.elicitation;
|
|
26711
|
-
return
|
|
27171
|
+
return isRecord2(elicitation) && isRecord2(elicitation.answers) ? elicitation.answers : null;
|
|
26712
27172
|
};
|
|
26713
27173
|
var getCodexOutcomeAnswers = (outcomeMeta) => {
|
|
26714
27174
|
const requestUserInput = getCodexMeta(outcomeMeta)?.requestUserInput;
|
|
26715
|
-
return
|
|
27175
|
+
return isRecord2(requestUserInput) && isRecord2(requestUserInput.answers) ? requestUserInput.answers : null;
|
|
26716
27176
|
};
|
|
26717
27177
|
var getClaudeOutcomeAnswers = (outcomeMeta) => {
|
|
26718
27178
|
const askUserQuestion = getClaudeCodeMeta(outcomeMeta)?.askUserQuestion;
|
|
26719
|
-
return
|
|
27179
|
+
return isRecord2(askUserQuestion) && isRecord2(askUserQuestion.answers) ? askUserQuestion.answers : null;
|
|
26720
27180
|
};
|
|
26721
27181
|
function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
26722
|
-
if (!outcome || !
|
|
27182
|
+
if (!outcome || !isRecord2(outcome._meta) || !hasValidNoteKeys(meta3.questions)) return null;
|
|
26723
27183
|
const answerSources = [
|
|
26724
27184
|
{ source: "lody", answers: getLodyOutcomeAnswers(outcome._meta) },
|
|
26725
27185
|
{ source: "codex", answers: getCodexOutcomeAnswers(outcome._meta) },
|
|
@@ -26738,7 +27198,7 @@ function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
|
26738
27198
|
const raw = answerSource.answers[sourceKey];
|
|
26739
27199
|
if (raw === void 0) continue;
|
|
26740
27200
|
if (answerSource.source === "codex") {
|
|
26741
|
-
if (!
|
|
27201
|
+
if (!isRecord2(raw) || !Array.isArray(raw.answers)) continue;
|
|
26742
27202
|
const values = raw.answers.filter((value) => typeof value === "string");
|
|
26743
27203
|
if (values.length === 0) continue;
|
|
26744
27204
|
result[key] = question.multiSelect ? values : values[0] ?? "";
|
|
@@ -26752,20 +27212,20 @@ function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
|
26752
27212
|
}
|
|
26753
27213
|
return Object.keys(result).length > 0 ? result : null;
|
|
26754
27214
|
}
|
|
26755
|
-
var isEnumOption = (value) =>
|
|
27215
|
+
var isEnumOption = (value) => isRecord2(value) && typeof value.const === "string";
|
|
26756
27216
|
var getEnumOptionSource = (prop) => {
|
|
26757
27217
|
if (Array.isArray(prop.oneOf)) return prop.oneOf;
|
|
26758
27218
|
if (Array.isArray(prop.enum)) return prop.enum;
|
|
26759
27219
|
const items = prop.items;
|
|
26760
|
-
if (
|
|
27220
|
+
if (isRecord2(items)) {
|
|
26761
27221
|
if (Array.isArray(items.anyOf)) return items.anyOf;
|
|
26762
27222
|
if (Array.isArray(items.enum)) return items.enum;
|
|
26763
27223
|
}
|
|
26764
27224
|
return null;
|
|
26765
27225
|
};
|
|
26766
|
-
var isQuestionProperty = (prop) =>
|
|
26767
|
-
var isFreeTextProperty = (prop) =>
|
|
26768
|
-
var isMultiSelectProperty = (prop) => prop.type === "array" ||
|
|
27226
|
+
var isQuestionProperty = (prop) => isRecord2(prop) && getEnumOptionSource(prop) !== null;
|
|
27227
|
+
var isFreeTextProperty = (prop) => isRecord2(prop) && prop.type === "string" && !Array.isArray(prop.oneOf) && !Array.isArray(prop.enum);
|
|
27228
|
+
var isMultiSelectProperty = (prop) => prop.type === "array" || isRecord2(prop.items);
|
|
26769
27229
|
var parseElicitationOptions = (source) => {
|
|
26770
27230
|
const options = [];
|
|
26771
27231
|
for (const entry of source) {
|
|
@@ -26784,9 +27244,9 @@ var parseElicitationOptions = (source) => {
|
|
|
26784
27244
|
return options;
|
|
26785
27245
|
};
|
|
26786
27246
|
function parseAskUserQuestionElicitationRequest(request) {
|
|
26787
|
-
if (!
|
|
27247
|
+
if (!isRecord2(request) || request.mode !== "form") return null;
|
|
26788
27248
|
const schema = request.requestedSchema;
|
|
26789
|
-
if (!
|
|
27249
|
+
if (!isRecord2(schema) || !isRecord2(schema.properties)) return null;
|
|
26790
27250
|
const properties = schema.properties;
|
|
26791
27251
|
const entries = Object.entries(properties);
|
|
26792
27252
|
const requestMeta = getLodyElicitationMeta(request._meta);
|
|
@@ -26794,9 +27254,9 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26794
27254
|
const noteFieldKeyByQuestionId = /* @__PURE__ */ new Map();
|
|
26795
27255
|
const associatedFields = /* @__PURE__ */ new Set();
|
|
26796
27256
|
for (const [key, prop] of entries) {
|
|
26797
|
-
if (!
|
|
27257
|
+
if (!isRecord2(prop)) continue;
|
|
26798
27258
|
const rawMeta = getLodyMeta(prop._meta)?.elicitation;
|
|
26799
|
-
if (
|
|
27259
|
+
if (isRecord2(rawMeta) && rawMeta.noteFor !== void 0 && rawMeta.version !== 1) return null;
|
|
26800
27260
|
const meta3 = getLodyElicitationMeta(prop._meta);
|
|
26801
27261
|
if (!meta3 || meta3.noteFor === void 0 && meta3.customAnswerFor === void 0) continue;
|
|
26802
27262
|
if (meta3.noteFor !== void 0 && meta3.customAnswerFor !== void 0) return null;
|
|
@@ -26809,7 +27269,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26809
27269
|
}
|
|
26810
27270
|
const isLodyForm = requestMeta !== null || associatedFields.size > 0;
|
|
26811
27271
|
const questionEntries = entries.filter(([key, prop]) => {
|
|
26812
|
-
if (!
|
|
27272
|
+
if (!isRecord2(prop) || associatedFields.has(key)) return false;
|
|
26813
27273
|
return isQuestionProperty(prop) || isLodyForm && isFreeTextProperty(prop);
|
|
26814
27274
|
});
|
|
26815
27275
|
if (questionEntries.length === 0) return null;
|
|
@@ -26819,13 +27279,13 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26819
27279
|
}
|
|
26820
27280
|
if (associatedFields.size > 0 && questionEntries.some(([key]) => !key.trim())) return null;
|
|
26821
27281
|
const singleQuestion = questionEntries.length === 1;
|
|
26822
|
-
const allowCustomAnswer = isLodyForm ? questionEntries.some(([key, prop]) =>
|
|
27282
|
+
const allowCustomAnswer = isLodyForm ? questionEntries.some(([key, prop]) => isRecord2(prop) && (getEnumOptionSource(prop) === null || customFieldKeyByQuestionId.has(key))) : entries.some(([, prop]) => isFreeTextProperty(prop));
|
|
26823
27283
|
const message = typeof request.message === "string" ? request.message : "";
|
|
26824
27284
|
const questions = [];
|
|
26825
27285
|
const fieldKeys = [];
|
|
26826
27286
|
const customFieldKeys = [];
|
|
26827
27287
|
for (const [key, prop] of questionEntries) {
|
|
26828
|
-
if (!
|
|
27288
|
+
if (!isRecord2(prop)) continue;
|
|
26829
27289
|
const source = getEnumOptionSource(prop);
|
|
26830
27290
|
const header = typeof prop.title === "string" ? prop.title : "";
|
|
26831
27291
|
const description = typeof prop.description === "string" ? prop.description : "";
|
|
@@ -26840,7 +27300,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26840
27300
|
multiSelect: isMultiSelectProperty(prop),
|
|
26841
27301
|
...isLodyForm ? { allowCustomAnswer: source === null || customFieldKeyByQuestionId.has(key) } : {},
|
|
26842
27302
|
...isLodyForm && getLodyElicitationMeta(prop._meta)?.secret === true ? { isSecret: true } : {},
|
|
26843
|
-
...noteFieldId !== void 0 &&
|
|
27303
|
+
...noteFieldId !== void 0 && isRecord2(noteProp) ? {
|
|
26844
27304
|
note: {
|
|
26845
27305
|
fieldId: noteFieldId,
|
|
26846
27306
|
...typeof noteProp.title === "string" ? { title: noteProp.title } : {},
|
|
@@ -26863,7 +27323,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26863
27323
|
}
|
|
26864
27324
|
function buildAskUserQuestionElicitationResponse(elicitation, outcome) {
|
|
26865
27325
|
if (!outcome || outcome.outcome !== "selected" || outcome.optionId === "cancel") return { action: "cancel" };
|
|
26866
|
-
const answers = extractAskUserQuestionAnswersFromOutcome(elicitation.meta, { _meta:
|
|
27326
|
+
const answers = extractAskUserQuestionAnswersFromOutcome(elicitation.meta, { _meta: isRecord2(outcome._meta) ? outcome._meta : null });
|
|
26867
27327
|
if (!answers) return { action: "accept", content: {} };
|
|
26868
27328
|
const content = /* @__PURE__ */ Object.create(null);
|
|
26869
27329
|
elicitation.meta.questions.forEach((question, index) => {
|
|
@@ -26890,8 +27350,8 @@ function redactSecretAnswers(elicitation, outcome) {
|
|
|
26890
27350
|
if (question.note?.isSecret) secret.add(question.note.fieldId);
|
|
26891
27351
|
});
|
|
26892
27352
|
const lody = getLodyMeta(outcome._meta);
|
|
26893
|
-
const elicitationMeta = lody &&
|
|
26894
|
-
if (!secret.size || !elicitationMeta || !
|
|
27353
|
+
const elicitationMeta = lody && isRecord2(lody.elicitation) ? lody.elicitation : null;
|
|
27354
|
+
if (!secret.size || !elicitationMeta || !isRecord2(elicitationMeta.answers)) return outcome;
|
|
26895
27355
|
const answers = Object.fromEntries(Object.entries(elicitationMeta.answers).map(([key, value]) => [key, secret.has(key) ? "[redacted]" : value]));
|
|
26896
27356
|
return { ...outcome, _meta: { ...outcome._meta, lody: { ...lody, elicitation: { ...elicitationMeta, answers } } } };
|
|
26897
27357
|
}
|
|
@@ -27317,8 +27777,10 @@ var AcpChatSession = class {
|
|
|
27317
27777
|
*/
|
|
27318
27778
|
forwardsPermission(params, prompts) {
|
|
27319
27779
|
if (isAskUserQuestionPermission(params)) return true;
|
|
27780
|
+
const call = record4(params.toolCall);
|
|
27781
|
+
if (typeof call.toolCallId === "string" && call.toolCallId.startsWith("interaction_")) return true;
|
|
27320
27782
|
if (prompts.permissions === "none") return false;
|
|
27321
|
-
const title =
|
|
27783
|
+
const title = call.title;
|
|
27322
27784
|
if (ECHO_CALLBACK.test(typeof title === "string" ? title : "")) return false;
|
|
27323
27785
|
if (prompts.permissions === "all") return true;
|
|
27324
27786
|
return !permissionAllowed(params, { permissionMode: "full", access: "acceptEdits" });
|
|
@@ -27960,7 +28422,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27960
28422
|
if (!fitsCommandLine(launch)) return refuse(cliFailure("promptTooLong", { label: cli.label }));
|
|
27961
28423
|
let child;
|
|
27962
28424
|
try {
|
|
27963
|
-
child =
|
|
28425
|
+
child = spawn13(launch.executable, launch.args, {
|
|
27964
28426
|
cwd: workdir,
|
|
27965
28427
|
env: Object.keys(memoryEnv).length ? { ...launch.env, ...memoryEnv } : launch.env,
|
|
27966
28428
|
detached: currentPlatform.runsInOwnProcessGroup,
|
|
@@ -28499,12 +28961,12 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
28499
28961
|
async prepareChatAttachments(payload) {
|
|
28500
28962
|
if (!payload.attachments?.length) return [];
|
|
28501
28963
|
if (!this.reporter.chatMedia) throw new Error("\u9644\u4EF6\u8F6C\u53D1\u672A\u914D\u7F6E");
|
|
28502
|
-
const directory =
|
|
28964
|
+
const directory = join22(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
|
|
28503
28965
|
await mkdir8(directory, { recursive: true, mode: 448 });
|
|
28504
28966
|
const files = [];
|
|
28505
28967
|
for (const attachment of payload.attachments) {
|
|
28506
28968
|
const name = basename3(attachment.name).replace(/[^\p{L}\p{N}._-]/gu, "_").slice(-120) || "attachment";
|
|
28507
|
-
const path =
|
|
28969
|
+
const path = join22(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
|
|
28508
28970
|
const existing = await stat6(path).catch(() => void 0);
|
|
28509
28971
|
if (!existing?.isFile()) {
|
|
28510
28972
|
const data = await this.reporter.chatMedia(payload.run_id, attachment.media_id);
|
|
@@ -28818,11 +29280,11 @@ var GatewayClient = class {
|
|
|
28818
29280
|
|
|
28819
29281
|
// src/workspace/directory-browser.ts
|
|
28820
29282
|
import { mkdir as mkdir9, readdir as readdir4, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28821
|
-
import { homedir as
|
|
29283
|
+
import { homedir as homedir14 } from "node:os";
|
|
28822
29284
|
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
28823
29285
|
var MAX_ENTRIES = 1e3;
|
|
28824
29286
|
async function listDirectory(requested, allowedRoots) {
|
|
28825
|
-
const raw = requested.trim().replace(/^~(?=$|[\\/])/,
|
|
29287
|
+
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir14()) || homedir14();
|
|
28826
29288
|
const directory = await realpath3(resolve6(raw)).catch(() => {
|
|
28827
29289
|
throw new Error(`\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${requested}`);
|
|
28828
29290
|
});
|
|
@@ -28840,8 +29302,8 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
28840
29302
|
else if (entry.isFile()) files.push(item);
|
|
28841
29303
|
}
|
|
28842
29304
|
const parent = dirname9(directory);
|
|
28843
|
-
const places = [{ label: "\u4E3B\u76EE\u5F55", path:
|
|
28844
|
-
for (const root2 of allowedRoots) if (root2 !==
|
|
29305
|
+
const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir14() }];
|
|
29306
|
+
for (const root2 of allowedRoots) if (root2 !== homedir14()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root2 });
|
|
28845
29307
|
places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
|
|
28846
29308
|
return {
|
|
28847
29309
|
path: directory,
|
|
@@ -28877,9 +29339,9 @@ async function createDirectory(parentRequested, name) {
|
|
|
28877
29339
|
}
|
|
28878
29340
|
|
|
28879
29341
|
// src/workspace/workspace-manager.ts
|
|
28880
|
-
import { spawn as
|
|
29342
|
+
import { spawn as spawn14 } from "node:child_process";
|
|
28881
29343
|
import { opendir, realpath as realpath4, stat as stat8 } from "node:fs/promises";
|
|
28882
|
-
import { homedir as
|
|
29344
|
+
import { homedir as homedir15 } from "node:os";
|
|
28883
29345
|
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
28884
29346
|
var MAX_NODES = 2e3;
|
|
28885
29347
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
@@ -28915,7 +29377,7 @@ var WorkspaceManager = class {
|
|
|
28915
29377
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
28916
29378
|
}
|
|
28917
29379
|
validateRootPath(value) {
|
|
28918
|
-
const raw = value.trim().replace(/^~(?=$|[\\/])/,
|
|
29380
|
+
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir15());
|
|
28919
29381
|
const root2 = resolve7(raw);
|
|
28920
29382
|
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28921
29383
|
if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
|
|
@@ -29041,7 +29503,7 @@ var WorkspaceManager = class {
|
|
|
29041
29503
|
}
|
|
29042
29504
|
runGit(args, cwd, timeoutSeconds, allowFailure = false) {
|
|
29043
29505
|
return new Promise((resolveCommand, rejectCommand) => {
|
|
29044
|
-
const child =
|
|
29506
|
+
const child = spawn14("git", args, {
|
|
29045
29507
|
cwd,
|
|
29046
29508
|
env: process.env,
|
|
29047
29509
|
shell: false,
|
|
@@ -29255,7 +29717,7 @@ var AgentRuntime = class {
|
|
|
29255
29717
|
}
|
|
29256
29718
|
};
|
|
29257
29719
|
this.workspaces = new WorkspaceManager(config2, this.logger);
|
|
29258
|
-
this.orphans = new OrphanRegistry(
|
|
29720
|
+
this.orphans = new OrphanRegistry(join24(config2.dataDir, "active-runs.json"));
|
|
29259
29721
|
this.runs = new RunSupervisor(config2, this.logger, reporter, this.orphans);
|
|
29260
29722
|
}
|
|
29261
29723
|
config;
|
|
@@ -29960,7 +30422,7 @@ function errorMessage3(error62) {
|
|
|
29960
30422
|
}
|
|
29961
30423
|
|
|
29962
30424
|
// src/runtime/run-service.ts
|
|
29963
|
-
import { existsSync as existsSync7, readFileSync as
|
|
30425
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
|
|
29964
30426
|
import { dirname as dirname10, resolve as resolve8 } from "node:path";
|
|
29965
30427
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
29966
30428
|
var PACKAGE_NAME = "toc-ocra";
|
|
@@ -29970,7 +30432,7 @@ function agentPackageRoot() {
|
|
|
29970
30432
|
const packagePath = resolve8(directory, "package.json");
|
|
29971
30433
|
if (existsSync7(packagePath)) {
|
|
29972
30434
|
try {
|
|
29973
|
-
const info = JSON.parse(
|
|
30435
|
+
const info = JSON.parse(readFileSync8(packagePath, "utf8"));
|
|
29974
30436
|
if (info.name === PACKAGE_NAME && typeof info.version === "string") return directory;
|
|
29975
30437
|
} catch {
|
|
29976
30438
|
}
|
|
@@ -29982,7 +30444,7 @@ function agentPackageRoot() {
|
|
|
29982
30444
|
}
|
|
29983
30445
|
function agentVersion() {
|
|
29984
30446
|
const root2 = agentPackageRoot();
|
|
29985
|
-
return root2 ? JSON.parse(
|
|
30447
|
+
return root2 ? JSON.parse(readFileSync8(resolve8(root2, "package.json"), "utf8")).version : "unknown";
|
|
29986
30448
|
}
|
|
29987
30449
|
async function runService(options = {}) {
|
|
29988
30450
|
const version2 = agentVersion();
|
|
@@ -30038,7 +30500,7 @@ function preferSystemNode() {
|
|
|
30038
30500
|
const names = process.platform === "win32" ? ["node.exe"] : ["node"];
|
|
30039
30501
|
for (const directory of (process.env.PATH ?? "").split(delimiter5)) {
|
|
30040
30502
|
for (const name of names) {
|
|
30041
|
-
const candidate = directory &&
|
|
30503
|
+
const candidate = directory && join25(directory, name);
|
|
30042
30504
|
if (candidate && existsSync8(candidate)) {
|
|
30043
30505
|
process.env.TOC_OCRA_NODE_PATH = candidate;
|
|
30044
30506
|
return;
|