toc-ocra 0.3.21 → 0.3.23
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 +751 -197
- package/dist/service/agent.mjs +726 -172
- 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 +4 -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/platform/posix.d.ts +2 -0
- package/dist/src/platform/posix.js +69 -2
- package/dist/src/platform/posix.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 +10 -1
- package/dist/src/providers/model-catalog.js +130 -4
- 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/dist/src/runtime/cli/hydrate-shell-path.d.ts +10 -1
- package/dist/src/runtime/cli/hydrate-shell-path.js +47 -4
- package/dist/src/runtime/cli/hydrate-shell-path.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";
|
|
@@ -20442,6 +20442,60 @@ function parseCapturedProxy(stdout) {
|
|
|
20442
20442
|
const values = stdout.slice(start + PROXY_DELIMITER.length, end).split("\0");
|
|
20443
20443
|
return Object.fromEntries(PROXY_KEYS.flatMap((key, index) => values[index] ? [[key, values[index]]] : []));
|
|
20444
20444
|
}
|
|
20445
|
+
function parseMacSystemProxy(stdout) {
|
|
20446
|
+
const field = (name) => {
|
|
20447
|
+
const match = new RegExp(`^\\s*${name}\\s*:\\s*(.+?)\\s*$`, "m").exec(stdout);
|
|
20448
|
+
return match?.[1]?.trim() || void 0;
|
|
20449
|
+
};
|
|
20450
|
+
const out = {};
|
|
20451
|
+
const httpEnabled = field("HTTPEnable") === "1";
|
|
20452
|
+
const httpHost = field("HTTPProxy");
|
|
20453
|
+
const httpPort = field("HTTPPort");
|
|
20454
|
+
if (httpEnabled && httpHost && httpPort) {
|
|
20455
|
+
const url2 = `http://${httpHost}:${httpPort}`;
|
|
20456
|
+
out.http_proxy = url2;
|
|
20457
|
+
out.HTTP_PROXY = url2;
|
|
20458
|
+
}
|
|
20459
|
+
const httpsEnabled = field("HTTPSEnable") === "1";
|
|
20460
|
+
const httpsHost = field("HTTPSProxy");
|
|
20461
|
+
const httpsPort = field("HTTPSPort");
|
|
20462
|
+
if (httpsEnabled && httpsHost && httpsPort) {
|
|
20463
|
+
const url2 = `http://${httpsHost}:${httpsPort}`;
|
|
20464
|
+
out.https_proxy = url2;
|
|
20465
|
+
out.HTTPS_PROXY = url2;
|
|
20466
|
+
}
|
|
20467
|
+
const socksEnabled = field("SOCKSEnable") === "1";
|
|
20468
|
+
const socksHost = field("SOCKSProxy");
|
|
20469
|
+
const socksPort = field("SOCKSPort");
|
|
20470
|
+
if (socksEnabled && socksHost && socksPort) {
|
|
20471
|
+
const url2 = `socks5://${socksHost}:${socksPort}`;
|
|
20472
|
+
out.all_proxy = url2;
|
|
20473
|
+
out.ALL_PROXY = url2;
|
|
20474
|
+
if (!out.http_proxy && !out.https_proxy) {
|
|
20475
|
+
out.http_proxy = url2;
|
|
20476
|
+
out.HTTP_PROXY = url2;
|
|
20477
|
+
out.https_proxy = url2;
|
|
20478
|
+
out.HTTPS_PROXY = url2;
|
|
20479
|
+
}
|
|
20480
|
+
}
|
|
20481
|
+
if (Object.keys(out).length > 0) {
|
|
20482
|
+
const exceptionsBlock = /ExceptionsList\s*:\s*<array>\s*\{([\s\S]*?)\}/m.exec(stdout)?.[1] ?? "";
|
|
20483
|
+
const exceptions = [...exceptionsBlock.matchAll(/^\s*\d+\s*:\s*(.+?)\s*$/gm)].map((match) => match[1]?.trim()).filter((item) => Boolean(item));
|
|
20484
|
+
const defaults = ["localhost", "127.0.0.1", "::1", ".local"];
|
|
20485
|
+
const merged = [.../* @__PURE__ */ new Set([...defaults, ...exceptions])];
|
|
20486
|
+
out.no_proxy = merged.join(",");
|
|
20487
|
+
out.NO_PROXY = out.no_proxy;
|
|
20488
|
+
}
|
|
20489
|
+
return out;
|
|
20490
|
+
}
|
|
20491
|
+
function readMacSystemProxy() {
|
|
20492
|
+
return new Promise((resolve9) => {
|
|
20493
|
+
execFile("scutil", ["--proxy"], { timeout: 2e3 }, (error62, stdout) => {
|
|
20494
|
+
if (error62 || !stdout) return resolve9({});
|
|
20495
|
+
resolve9(parseMacSystemProxy(stdout));
|
|
20496
|
+
});
|
|
20497
|
+
});
|
|
20498
|
+
}
|
|
20445
20499
|
function readLoginShell(shell) {
|
|
20446
20500
|
return new Promise((resolve9) => {
|
|
20447
20501
|
const proxyValues = PROXY_KEYS.map((key) => `"\${${key}-}"`).join(" ");
|
|
@@ -20534,9 +20588,17 @@ function createPosixPlatform(id) {
|
|
|
20534
20588
|
});
|
|
20535
20589
|
},
|
|
20536
20590
|
scriptShell: (command) => ({ executable: "/bin/sh", args: ["-lc", command] }),
|
|
20537
|
-
readLoginEnvironment() {
|
|
20591
|
+
async readLoginEnvironment() {
|
|
20538
20592
|
const shell = process.env.SHELL || (id === "darwin" ? "/bin/zsh" : "/bin/bash");
|
|
20539
|
-
|
|
20593
|
+
const [shellResult, macProxy] = await Promise.all([
|
|
20594
|
+
readLoginShell(shell),
|
|
20595
|
+
id === "darwin" ? readMacSystemProxy() : Promise.resolve({})
|
|
20596
|
+
]);
|
|
20597
|
+
if (!shellResult.ok || Object.keys(macProxy).length === 0) return shellResult;
|
|
20598
|
+
return {
|
|
20599
|
+
...shellResult,
|
|
20600
|
+
proxyEnv: { ...macProxy, ...shellResult.proxyEnv }
|
|
20601
|
+
};
|
|
20540
20602
|
}
|
|
20541
20603
|
};
|
|
20542
20604
|
}
|
|
@@ -20740,6 +20802,16 @@ function directLaunch2(path, args, nodePath = process.execPath) {
|
|
|
20740
20802
|
|
|
20741
20803
|
// src/runtime/cli/hydrate-shell-path.ts
|
|
20742
20804
|
var cached2 = null;
|
|
20805
|
+
var cachedAt = 0;
|
|
20806
|
+
var cachedHasProxy = false;
|
|
20807
|
+
var EMPTY_PROXY_RETRY_MS = 3e4;
|
|
20808
|
+
function hasProxyKeys(env) {
|
|
20809
|
+
if (!env) return false;
|
|
20810
|
+
return PROXY_KEYS.slice(0, 3).some((key) => {
|
|
20811
|
+
const upper = key.toUpperCase();
|
|
20812
|
+
return Boolean(env[key]?.trim() || env[upper]?.trim());
|
|
20813
|
+
});
|
|
20814
|
+
}
|
|
20743
20815
|
function mergeShellProxyEnvironment(hydration, baseline = process.env) {
|
|
20744
20816
|
const environment = { ...baseline };
|
|
20745
20817
|
if (!hydration.ok) return environment;
|
|
@@ -20752,9 +20824,29 @@ function mergeShellProxyEnvironment(hydration, baseline = process.env) {
|
|
|
20752
20824
|
return environment;
|
|
20753
20825
|
}
|
|
20754
20826
|
function hydrateShellPath(options = {}) {
|
|
20755
|
-
|
|
20756
|
-
cached2
|
|
20757
|
-
|
|
20827
|
+
const staleEmptyProxy = !cachedHasProxy && cached2 !== null && Date.now() - cachedAt >= EMPTY_PROXY_RETRY_MS;
|
|
20828
|
+
if (cached2 && !options.force && !staleEmptyProxy) return cached2;
|
|
20829
|
+
cachedAt = Date.now();
|
|
20830
|
+
const next = (options.reader ?? (() => currentPlatform.readLoginEnvironment()))();
|
|
20831
|
+
cached2 = next;
|
|
20832
|
+
void next.then((result) => {
|
|
20833
|
+
if (cached2 === next) cachedHasProxy = result.ok && hasProxyKeys(result.proxyEnv);
|
|
20834
|
+
});
|
|
20835
|
+
return next;
|
|
20836
|
+
}
|
|
20837
|
+
async function hydrateRuntimeProxy(baseline = process.env) {
|
|
20838
|
+
if (hasProxyKeys(baseline)) return { ...baseline };
|
|
20839
|
+
const hydration = await hydrateShellPath({ force: !cachedHasProxy });
|
|
20840
|
+
const merged = mergeShellProxyEnvironment(hydration, baseline);
|
|
20841
|
+
if (hydration.ok && hasProxyKeys(hydration.proxyEnv)) {
|
|
20842
|
+
for (const key of PROXY_KEYS.slice(0, 4)) {
|
|
20843
|
+
const upper = key.toUpperCase();
|
|
20844
|
+
if (process.env[key] === void 0 && process.env[upper] === void 0 && merged[key]) {
|
|
20845
|
+
process.env[key] = merged[key];
|
|
20846
|
+
}
|
|
20847
|
+
}
|
|
20848
|
+
}
|
|
20849
|
+
return merged;
|
|
20758
20850
|
}
|
|
20759
20851
|
function mergePathSegments(segments) {
|
|
20760
20852
|
if (segments.length === 0) return [];
|
|
@@ -20781,6 +20873,7 @@ var SOURCES = [
|
|
|
20781
20873
|
{ 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
20874
|
{ id: "grok", label: "Grok CLI", command: "grok", versionArguments: ["--version"] },
|
|
20783
20875
|
{ id: "gemini", label: "Gemini CLI", command: "gemini", versionArguments: ["--version"], restrictedPermission: true, installHint: "npm i -g @google/gemini-cli" },
|
|
20876
|
+
{ id: "antigravity", label: "Antigravity", aliases: ["agy"], command: "agy", versionArguments: ["--version"], restrictedPermission: true, installHint: "https://antigravity.google/cli" },
|
|
20784
20877
|
{ id: "opencode", label: "OpenCode", command: "opencode", versionArguments: ["--version"], installHint: "npm i -g opencode-ai" },
|
|
20785
20878
|
{ id: "kiro", label: "Kiro CLI", aliases: ["kiro-cli"], command: "kiro-cli", commandAliases: ["kiro"], versionArguments: ["--version"], promptStdin: "omit", restrictedPermission: true },
|
|
20786
20879
|
{ id: "omp", label: "OMP", command: "omp", versionArguments: ["--version"] },
|
|
@@ -21011,7 +21104,7 @@ function textRows(prefix, text3, maxRows = 40) {
|
|
|
21011
21104
|
|
|
21012
21105
|
// src/acp/acp-launch-specs.ts
|
|
21013
21106
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
21014
|
-
import { join as
|
|
21107
|
+
import { join as join14 } from "node:path";
|
|
21015
21108
|
|
|
21016
21109
|
// src/providers/claude-sessions.ts
|
|
21017
21110
|
import { existsSync as existsSync5, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -21173,8 +21266,8 @@ function codexCatalogArgs() {
|
|
|
21173
21266
|
// src/providers/model-catalog.ts
|
|
21174
21267
|
import { spawn as spawn5 } from "node:child_process";
|
|
21175
21268
|
import { readdir, readFile as readFile4 } from "node:fs/promises";
|
|
21176
|
-
import { homedir as
|
|
21177
|
-
import { isAbsolute as isAbsolute2, join as
|
|
21269
|
+
import { homedir as homedir8 } from "node:os";
|
|
21270
|
+
import { isAbsolute as isAbsolute2, join as join11, resolve as resolve3 } from "node:path";
|
|
21178
21271
|
|
|
21179
21272
|
// src/providers/kiro-auth.ts
|
|
21180
21273
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -21294,6 +21387,116 @@ async function readKiroNativeModels(launch, cwd, options = {}) {
|
|
|
21294
21387
|
}
|
|
21295
21388
|
}
|
|
21296
21389
|
|
|
21390
|
+
// src/acp/acp-dialects/antigravity-dialect.ts
|
|
21391
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
21392
|
+
import { homedir as homedir7 } from "node:os";
|
|
21393
|
+
import { join as join10 } from "node:path";
|
|
21394
|
+
|
|
21395
|
+
// src/acp/acp-dialects/acp-dialect.ts
|
|
21396
|
+
var record2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21397
|
+
|
|
21398
|
+
// src/acp/acp-dialects/antigravity-dialect.ts
|
|
21399
|
+
var str2 = (value) => typeof value === "string" && value ? value : void 0;
|
|
21400
|
+
var num = (value) => typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
21401
|
+
var ANTIGRAVITY_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"];
|
|
21402
|
+
var ANTIGRAVITY_LEVEL_SUFFIX = /^(.+)-(low|medium|high|xhigh|max)$/;
|
|
21403
|
+
var CLOUD_CODE_PREFIX = /^Cloud Code Assist API error \(\d{3}\):\s*/;
|
|
21404
|
+
var EXECUTOR_API_ERROR = /^(\u26a0 agent executor error: [^\n]*?Error (\d{3}), Message: ([^\n]*?)), Status: ([A-Z_]+)(?:, Details: ([^\n]*))?$/;
|
|
21405
|
+
var ANTIGRAVITY_FAILURE_RULES = [
|
|
21406
|
+
{
|
|
21407
|
+
kind: "notSignedIn",
|
|
21408
|
+
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
|
|
21409
|
+
},
|
|
21410
|
+
{
|
|
21411
|
+
kind: "rateLimited",
|
|
21412
|
+
pattern: /resource_exhausted|quota exceeded|rate limit|too many requests|429/i
|
|
21413
|
+
},
|
|
21414
|
+
{
|
|
21415
|
+
kind: "sessionMissing",
|
|
21416
|
+
pattern: /session not found|failed to rebuild agent:/i
|
|
21417
|
+
}
|
|
21418
|
+
];
|
|
21419
|
+
function antigravityUsesApiKeyProvider(homePath = homedir7()) {
|
|
21420
|
+
try {
|
|
21421
|
+
const raw = readFileSync5(join10(homePath, ".gemini", "antigravity-cli", "settings.json"), "utf8");
|
|
21422
|
+
const parsed = JSON.parse(raw);
|
|
21423
|
+
return Boolean(record2(parsed).modelProvider);
|
|
21424
|
+
} catch {
|
|
21425
|
+
return false;
|
|
21426
|
+
}
|
|
21427
|
+
}
|
|
21428
|
+
function scrubAntigravityEnv(env, homePath = homedir7()) {
|
|
21429
|
+
const next = { ...env };
|
|
21430
|
+
if (!antigravityUsesApiKeyProvider(homePath)) {
|
|
21431
|
+
for (const key of Object.keys(next)) {
|
|
21432
|
+
const normalized = process.platform === "win32" ? key.toUpperCase() : key;
|
|
21433
|
+
if (normalized === "GEMINI_API_KEY" || normalized === "GOOGLE_API_KEY") {
|
|
21434
|
+
delete next[key];
|
|
21435
|
+
}
|
|
21436
|
+
}
|
|
21437
|
+
}
|
|
21438
|
+
if (process.platform === "win32") {
|
|
21439
|
+
for (const key of Object.keys(next)) {
|
|
21440
|
+
if (key.toUpperCase() === "AGY_CLI_DISABLE_AUTO_UPDATE" && key !== "AGY_CLI_DISABLE_AUTO_UPDATE") {
|
|
21441
|
+
delete next[key];
|
|
21442
|
+
}
|
|
21443
|
+
}
|
|
21444
|
+
}
|
|
21445
|
+
next.AGY_CLI_DISABLE_AUTO_UPDATE = "true";
|
|
21446
|
+
return next;
|
|
21447
|
+
}
|
|
21448
|
+
function errorText(error62) {
|
|
21449
|
+
if (typeof error62.data === "string" && error62.data.trim()) return error62.data.trim();
|
|
21450
|
+
const nested = record2(error62.data);
|
|
21451
|
+
const nestedMsg = str2(nested.message) ?? str2(nested.details) ?? str2(nested.error);
|
|
21452
|
+
return nestedMsg ?? error62.message ?? "";
|
|
21453
|
+
}
|
|
21454
|
+
function promptErrorDetail(error62) {
|
|
21455
|
+
const text3 = errorText(error62);
|
|
21456
|
+
if (!text3) return void 0;
|
|
21457
|
+
const prefix = CLOUD_CODE_PREFIX.exec(text3);
|
|
21458
|
+
if (prefix) {
|
|
21459
|
+
try {
|
|
21460
|
+
const parsed = record2(JSON.parse(text3.slice(prefix[0].length)));
|
|
21461
|
+
const msg = str2(record2(parsed.error).message)?.trim();
|
|
21462
|
+
if (msg) return msg;
|
|
21463
|
+
} catch {
|
|
21464
|
+
}
|
|
21465
|
+
}
|
|
21466
|
+
const execMatch = EXECUTOR_API_ERROR.exec(text3);
|
|
21467
|
+
if (execMatch) {
|
|
21468
|
+
const [, , code, rawMessage, status] = execMatch;
|
|
21469
|
+
const message = rawMessage?.trim();
|
|
21470
|
+
return message || `Google returned error ${code} (${status}).`;
|
|
21471
|
+
}
|
|
21472
|
+
return void 0;
|
|
21473
|
+
}
|
|
21474
|
+
function normalizeToolUpdate(update) {
|
|
21475
|
+
const input2 = record2(update.rawInput);
|
|
21476
|
+
const output2 = record2(update.rawOutput);
|
|
21477
|
+
const command = str2(input2.CommandLine) ?? str2(input2.command_line) ?? str2(input2.commandLine);
|
|
21478
|
+
const cwd = str2(input2.Cwd) ?? str2(input2.WorkingDirectory) ?? str2(input2.working_dir) ?? str2(input2.workingDir) ?? str2(input2.cwd);
|
|
21479
|
+
const stdout = str2(output2.combinedOutput) ?? str2(output2.combined_output);
|
|
21480
|
+
const exitCode = num(output2.exitCode) ?? num(output2.exit_code);
|
|
21481
|
+
return {
|
|
21482
|
+
...update,
|
|
21483
|
+
...command === void 0 ? {} : { rawInput: { command, ...cwd === void 0 ? {} : { cwd } } },
|
|
21484
|
+
...stdout === void 0 && exitCode === void 0 ? {} : {
|
|
21485
|
+
rawOutput: {
|
|
21486
|
+
...stdout === void 0 ? {} : { stdout },
|
|
21487
|
+
...exitCode === void 0 ? {} : { exitCode }
|
|
21488
|
+
}
|
|
21489
|
+
}
|
|
21490
|
+
};
|
|
21491
|
+
}
|
|
21492
|
+
var ANTIGRAVITY_ACP_DIALECT = {
|
|
21493
|
+
failureRules: ANTIGRAVITY_FAILURE_RULES,
|
|
21494
|
+
failureKind: ({ code }) => code === 401 ? "notSignedIn" : code === 429 ? "rateLimited" : void 0,
|
|
21495
|
+
promptErrorDetail,
|
|
21496
|
+
normalizeToolUpdate,
|
|
21497
|
+
toolName: (update) => update.kind === "execute" ? "execute" : void 0
|
|
21498
|
+
};
|
|
21499
|
+
|
|
21297
21500
|
// src/providers/model-catalog.ts
|
|
21298
21501
|
function stringValue(value) {
|
|
21299
21502
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
@@ -21382,15 +21585,16 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
|
|
|
21382
21585
|
models: [...models2.values()]
|
|
21383
21586
|
};
|
|
21384
21587
|
}
|
|
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
|
|
21588
|
+
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join11(homedir8(), ".claude");
|
|
21589
|
+
var codexHome2 = () => process.env.CODEX_HOME?.trim() || join11(homedir8(), ".codex");
|
|
21590
|
+
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() || join11(homedir8(), ".gemini");
|
|
21591
|
+
var antigravityHome = () => join11(homedir8(), ".gemini", "antigravity-cli");
|
|
21592
|
+
var grokHome = () => process.env.GROK_HOME?.trim() || join11(homedir8(), ".grok");
|
|
21593
|
+
var opencodeHome = () => join11(process.env.XDG_CONFIG_HOME?.trim() || join11(homedir8(), ".config"), "opencode");
|
|
21594
|
+
var kiroHome = () => join11(homedir8(), ".kiro");
|
|
21391
21595
|
async function readClaudeModelCatalog() {
|
|
21392
21596
|
const home = claudeHome();
|
|
21393
|
-
const content = await readFile4(
|
|
21597
|
+
const content = await readFile4(join11(home, "settings.json"), "utf8").catch(() => "");
|
|
21394
21598
|
let settings = {};
|
|
21395
21599
|
if (content) {
|
|
21396
21600
|
try {
|
|
@@ -21402,13 +21606,13 @@ async function readClaudeModelCatalog() {
|
|
|
21402
21606
|
return parseClaudeModelCatalog(settings, process.env, (/* @__PURE__ */ new Date()).toISOString(), await readClaudeCachedModels(home));
|
|
21403
21607
|
}
|
|
21404
21608
|
async function readClaudeCachedModels(home) {
|
|
21405
|
-
const dir =
|
|
21609
|
+
const dir = join11(home, "cache", "model-catalog");
|
|
21406
21610
|
const names = await readdir(dir).catch(() => []);
|
|
21407
21611
|
let newest;
|
|
21408
21612
|
for (const name of names) {
|
|
21409
21613
|
if (!name.endsWith(".json")) continue;
|
|
21410
21614
|
try {
|
|
21411
|
-
const cache = JSON.parse(await readFile4(
|
|
21615
|
+
const cache = JSON.parse(await readFile4(join11(dir, name), "utf8"));
|
|
21412
21616
|
const models2 = parseClaudeCachedModels(cache);
|
|
21413
21617
|
const fetchedAt = Number(objectValue(cache).fetchedAt) || 0;
|
|
21414
21618
|
if (models2.length && (!newest || fetchedAt > newest.fetchedAt)) newest = { fetchedAt, models: models2 };
|
|
@@ -21464,13 +21668,13 @@ async function readCodexModels(codexHome3, config2) {
|
|
|
21464
21668
|
const configuredModels = parseCodexModels(await readFile4(catalogPath, "utf8").catch(() => ""));
|
|
21465
21669
|
if (configuredModels?.length) return configuredModels;
|
|
21466
21670
|
}
|
|
21467
|
-
const cached3 = parseCodexModels(await readFile4(
|
|
21671
|
+
const cached3 = parseCodexModels(await readFile4(join11(codexHome3, "models_cache.json"), "utf8").catch(() => ""));
|
|
21468
21672
|
if (cached3?.length) return cached3;
|
|
21469
21673
|
return codexModelsFrom(await codexBundledCatalog().catch(() => void 0), { listedOnly: true }) ?? [];
|
|
21470
21674
|
}
|
|
21471
21675
|
async function readCodexModelCatalog() {
|
|
21472
21676
|
const home = codexHome2();
|
|
21473
|
-
const config2 = await readFile4(
|
|
21677
|
+
const config2 = await readFile4(join11(home, "config.toml"), "utf8").catch(() => "");
|
|
21474
21678
|
const models2 = await readCodexModels(home, config2);
|
|
21475
21679
|
const defaultModel = configValue(config2, "model");
|
|
21476
21680
|
const defaultReasoningEffort = configValue(config2, "model_reasoning_effort");
|
|
@@ -21518,7 +21722,7 @@ function cliExecutable(id) {
|
|
|
21518
21722
|
const spec = requireCliSpec(id);
|
|
21519
21723
|
return process.env[spec.overrideEnv]?.trim() || resolveCliCommand(cliCommand(spec));
|
|
21520
21724
|
}
|
|
21521
|
-
function runModelListCommand(executable, args, label, environment) {
|
|
21725
|
+
function runModelListCommand(executable, args, label, environment, timeoutMs = MODEL_LIST_TIMEOUT_MS) {
|
|
21522
21726
|
return new Promise((resolve9, reject) => {
|
|
21523
21727
|
const launch = directLaunch2(executable, args);
|
|
21524
21728
|
const child = spawn5(launch.executable, launch.args, { shell: false, windowsHide: true, ...environment ? { env: environment } : {}, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -21527,7 +21731,7 @@ function runModelListCommand(executable, args, label, environment) {
|
|
|
21527
21731
|
const timer = setTimeout(() => {
|
|
21528
21732
|
child.kill("SIGKILL");
|
|
21529
21733
|
reject(new Error(`${label} \u8BFB\u53D6\u6A21\u578B\u5217\u8868\u8D85\u65F6`));
|
|
21530
|
-
},
|
|
21734
|
+
}, timeoutMs);
|
|
21531
21735
|
child.stdout.setEncoding("utf8");
|
|
21532
21736
|
child.stderr.setEncoding("utf8");
|
|
21533
21737
|
child.stdout.on("data", (chunk) => {
|
|
@@ -21561,7 +21765,7 @@ function withKnownEfforts(base, known) {
|
|
|
21561
21765
|
};
|
|
21562
21766
|
}
|
|
21563
21767
|
async function readKiroModelCatalog(options = {}) {
|
|
21564
|
-
const environment =
|
|
21768
|
+
const environment = await hydrateRuntimeProxy(providerEnvironment());
|
|
21565
21769
|
const kiro = requireCliSpec("kiro");
|
|
21566
21770
|
await requireKiroAuthentication(environment, { force: options.force === true });
|
|
21567
21771
|
const listLaunch = launchCli({ spec: kiro, args: ["chat", "--list-models", "--format", "json"], env: environment });
|
|
@@ -21584,7 +21788,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
21584
21788
|
if (current) return known.catalog;
|
|
21585
21789
|
try {
|
|
21586
21790
|
const launch = launchCli({ spec: kiro, args: ["acp", "--trust-tools="], env: environment });
|
|
21587
|
-
const catalog = await readKiroNativeModels(launch,
|
|
21791
|
+
const catalog = await readKiroNativeModels(launch, homedir8(), { catalog: base });
|
|
21588
21792
|
kiroEfforts = { signature, readAt: Date.now(), catalog };
|
|
21589
21793
|
return catalog;
|
|
21590
21794
|
} catch {
|
|
@@ -21593,7 +21797,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
21593
21797
|
};
|
|
21594
21798
|
const [payload, content] = await Promise.all([
|
|
21595
21799
|
readEfforts(),
|
|
21596
|
-
readFile4(
|
|
21800
|
+
readFile4(join11(kiroHome(), "settings", "cli.json"), "utf8").catch(() => "{}")
|
|
21597
21801
|
]);
|
|
21598
21802
|
let settings;
|
|
21599
21803
|
try {
|
|
@@ -21650,7 +21854,7 @@ function geminiModelsUrl(baseUrl) {
|
|
|
21650
21854
|
}
|
|
21651
21855
|
async function readGeminiModelCatalog() {
|
|
21652
21856
|
const fileEnvironment = parseEnvFile(
|
|
21653
|
-
await readFile4(
|
|
21857
|
+
await readFile4(join11(geminiHome(), ".env"), "utf8").catch(() => "")
|
|
21654
21858
|
);
|
|
21655
21859
|
const environment = { ...fileEnvironment, ...process.env };
|
|
21656
21860
|
const baseUrl = environment.GOOGLE_GEMINI_BASE_URL?.trim();
|
|
@@ -21695,7 +21899,7 @@ function parseGrokModelCatalog(output2, config2 = "", fetchedAt = (/* @__PURE__
|
|
|
21695
21899
|
return catalog;
|
|
21696
21900
|
}
|
|
21697
21901
|
async function readGrokModelCatalog() {
|
|
21698
|
-
const config2 = await readFile4(
|
|
21902
|
+
const config2 = await readFile4(join11(grokHome(), "config.toml"), "utf8").catch(() => "");
|
|
21699
21903
|
const output2 = await runModelListCommand(cliExecutable("grok"), ["models"], "grok");
|
|
21700
21904
|
const catalog = parseGrokModelCatalog(output2, config2);
|
|
21701
21905
|
if (catalog.models.length === 0) throw new Error("Grok \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -21714,30 +21918,139 @@ function parseOpencodeModelCatalog(output2, config2 = "", fetchedAt = (/* @__PUR
|
|
|
21714
21918
|
return catalog;
|
|
21715
21919
|
}
|
|
21716
21920
|
async function readOpencodeModelCatalog() {
|
|
21717
|
-
const config2 = await readFile4(
|
|
21921
|
+
const config2 = await readFile4(join11(opencodeHome(), "opencode.json"), "utf8").catch(() => "") || await readFile4(join11(opencodeHome(), "opencode.jsonc"), "utf8").catch(() => "");
|
|
21718
21922
|
const output2 = await runModelListCommand(cliExecutable("opencode"), ["models"], "opencode");
|
|
21719
21923
|
const catalog = parseOpencodeModelCatalog(output2, config2);
|
|
21720
21924
|
if (catalog.models.length === 0) throw new Error("OpenCode \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
21721
21925
|
return catalog;
|
|
21722
21926
|
}
|
|
21927
|
+
function parseAntigravityModelCatalog(output2, settingsContent = "", fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
21928
|
+
const plain = output2.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "");
|
|
21929
|
+
const variants = [];
|
|
21930
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
21931
|
+
for (const line of plain.split(/\r?\n/)) {
|
|
21932
|
+
const parts = line.split(" ").map((field) => field.trim());
|
|
21933
|
+
const [modelId, name, ...extra] = parts;
|
|
21934
|
+
if (!modelId || !name || extra.length > 0 || seenIds.has(modelId)) continue;
|
|
21935
|
+
seenIds.add(modelId);
|
|
21936
|
+
variants.push({ modelId, name });
|
|
21937
|
+
}
|
|
21938
|
+
const familyLevels = /* @__PURE__ */ new Map();
|
|
21939
|
+
for (const variant of variants) {
|
|
21940
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(variant.modelId);
|
|
21941
|
+
const family = match?.[1];
|
|
21942
|
+
const level = match?.[2];
|
|
21943
|
+
if (!family || !level || seenIds.has(family)) continue;
|
|
21944
|
+
const list = familyLevels.get(family) ?? [];
|
|
21945
|
+
if (!list.includes(level)) list.push(level);
|
|
21946
|
+
familyLevels.set(family, list);
|
|
21947
|
+
}
|
|
21948
|
+
const models2 = [];
|
|
21949
|
+
const addedFamilies = /* @__PURE__ */ new Set();
|
|
21950
|
+
for (const variant of variants) {
|
|
21951
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(variant.modelId);
|
|
21952
|
+
const family = match?.[1];
|
|
21953
|
+
const levels = family ? familyLevels.get(family) : void 0;
|
|
21954
|
+
if (family && levels && levels.length > 1) {
|
|
21955
|
+
if (addedFamilies.has(family)) continue;
|
|
21956
|
+
addedFamilies.add(family);
|
|
21957
|
+
const ordered = ANTIGRAVITY_EFFORT_LEVELS.filter((level) => levels.includes(level));
|
|
21958
|
+
const firstLevel = levels[0];
|
|
21959
|
+
models2.push({
|
|
21960
|
+
id: family,
|
|
21961
|
+
name: variant.name.replace(/\s*\([^()]+\)$/, ""),
|
|
21962
|
+
supported_reasoning_efforts: [...ordered],
|
|
21963
|
+
...firstLevel && ordered.includes(firstLevel) ? { default_reasoning_effort: firstLevel } : {}
|
|
21964
|
+
});
|
|
21965
|
+
} else {
|
|
21966
|
+
models2.push({
|
|
21967
|
+
id: variant.modelId,
|
|
21968
|
+
name: variant.name,
|
|
21969
|
+
supported_reasoning_efforts: []
|
|
21970
|
+
});
|
|
21971
|
+
}
|
|
21972
|
+
}
|
|
21973
|
+
let configuredModel;
|
|
21974
|
+
if (settingsContent.trim()) {
|
|
21975
|
+
try {
|
|
21976
|
+
configuredModel = stringValue(objectValue(JSON.parse(settingsContent)).model);
|
|
21977
|
+
} catch {
|
|
21978
|
+
}
|
|
21979
|
+
}
|
|
21980
|
+
let defaultModel;
|
|
21981
|
+
let defaultEffort;
|
|
21982
|
+
if (configuredModel) {
|
|
21983
|
+
const matchedVariant = variants.find(
|
|
21984
|
+
(variant) => variant.modelId === configuredModel || variant.name.toLowerCase() === configuredModel.toLowerCase()
|
|
21985
|
+
);
|
|
21986
|
+
if (matchedVariant) {
|
|
21987
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(matchedVariant.modelId);
|
|
21988
|
+
const family = match?.[1];
|
|
21989
|
+
const level = match?.[2];
|
|
21990
|
+
if (family && addedFamilies.has(family)) {
|
|
21991
|
+
defaultModel = family;
|
|
21992
|
+
defaultEffort = level;
|
|
21993
|
+
} else {
|
|
21994
|
+
defaultModel = matchedVariant.modelId;
|
|
21995
|
+
}
|
|
21996
|
+
} else {
|
|
21997
|
+
const matchedFamily = models2.find(
|
|
21998
|
+
(model) => model.id === configuredModel || model.name.toLowerCase() === configuredModel.toLowerCase()
|
|
21999
|
+
);
|
|
22000
|
+
if (matchedFamily) {
|
|
22001
|
+
defaultModel = matchedFamily.id;
|
|
22002
|
+
defaultEffort = matchedFamily.default_reasoning_effort;
|
|
22003
|
+
}
|
|
22004
|
+
}
|
|
22005
|
+
}
|
|
22006
|
+
if (!defaultModel && models2.length > 0) {
|
|
22007
|
+
defaultModel = models2[0].id;
|
|
22008
|
+
defaultEffort = models2[0].default_reasoning_effort;
|
|
22009
|
+
}
|
|
22010
|
+
return {
|
|
22011
|
+
agent_type: "antigravity",
|
|
22012
|
+
fetched_at: fetchedAt,
|
|
22013
|
+
...defaultModel ? { default_model: defaultModel } : {},
|
|
22014
|
+
...defaultEffort ? { default_reasoning_effort: defaultEffort } : {},
|
|
22015
|
+
models: models2
|
|
22016
|
+
};
|
|
22017
|
+
}
|
|
22018
|
+
async function readAntigravityModelCatalog() {
|
|
22019
|
+
const baseEnv = await hydrateRuntimeProxy(providerEnvironment());
|
|
22020
|
+
const env = scrubAntigravityEnv(baseEnv);
|
|
22021
|
+
const spec = requireCliSpec("antigravity");
|
|
22022
|
+
const launch = launchCli({ spec, args: ["models"], env });
|
|
22023
|
+
const [output2, settings] = await Promise.all([
|
|
22024
|
+
runModelListCommand(launch.executable, launch.args, "agy", launch.env ?? env, 3e4),
|
|
22025
|
+
readFile4(join11(antigravityHome(), "settings.json"), "utf8").catch(() => "")
|
|
22026
|
+
]);
|
|
22027
|
+
const catalog = parseAntigravityModelCatalog(output2, settings);
|
|
22028
|
+
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");
|
|
22029
|
+
return catalog;
|
|
22030
|
+
}
|
|
21723
22031
|
var TEN_MINUTES = 10 * 60 * 1e3;
|
|
21724
22032
|
var MODEL_SOURCES = {
|
|
21725
|
-
|
|
22033
|
+
antigravity: {
|
|
22034
|
+
read: readAntigravityModelCatalog,
|
|
22035
|
+
watchFiles: () => [join11(antigravityHome(), "settings.json")],
|
|
22036
|
+
refreshEveryMs: TEN_MINUTES
|
|
22037
|
+
},
|
|
22038
|
+
claude: { read: readClaudeModelCatalog, watchFiles: () => [join11(claudeHome(), "settings.json"), join11(claudeHome(), "cache", "model-catalog")] },
|
|
21726
22039
|
codex: {
|
|
21727
22040
|
read: readCodexModelCatalog,
|
|
21728
22041
|
watchFiles: () => {
|
|
21729
22042
|
const home = codexHome2();
|
|
21730
|
-
return [
|
|
22043
|
+
return [join11(home, "config.toml"), join11(home, "models_cache.json")];
|
|
21731
22044
|
},
|
|
21732
22045
|
// model_catalog_json may point anywhere; a periodic re-read covers it.
|
|
21733
22046
|
refreshEveryMs: TEN_MINUTES
|
|
21734
22047
|
},
|
|
21735
|
-
gemini: { read: readGeminiModelCatalog, watchFiles: () => [
|
|
21736
|
-
grok: { read: readGrokModelCatalog, watchFiles: () => [
|
|
21737
|
-
kiro: { read: readKiroModelCatalog, watchFiles: () => [
|
|
22048
|
+
gemini: { read: readGeminiModelCatalog, watchFiles: () => [join11(geminiHome(), ".env")], refreshEveryMs: TEN_MINUTES },
|
|
22049
|
+
grok: { read: readGrokModelCatalog, watchFiles: () => [join11(grokHome(), "config.toml")], refreshEveryMs: TEN_MINUTES },
|
|
22050
|
+
kiro: { read: readKiroModelCatalog, watchFiles: () => [join11(kiroHome(), "settings", "cli.json")] },
|
|
21738
22051
|
opencode: {
|
|
21739
22052
|
read: readOpencodeModelCatalog,
|
|
21740
|
-
watchFiles: () => [
|
|
22053
|
+
watchFiles: () => [join11(opencodeHome(), "opencode.json"), join11(opencodeHome(), "opencode.jsonc")],
|
|
21741
22054
|
refreshEveryMs: TEN_MINUTES
|
|
21742
22055
|
}
|
|
21743
22056
|
};
|
|
@@ -21753,9 +22066,6 @@ var GEMINI_ACP_DIALECT = {
|
|
|
21753
22066
|
linksFileMentions: true
|
|
21754
22067
|
};
|
|
21755
22068
|
|
|
21756
|
-
// src/acp/acp-dialects/acp-dialect.ts
|
|
21757
|
-
var record2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21758
|
-
|
|
21759
22069
|
// src/acp/acp-dialects/grok-dialect.ts
|
|
21760
22070
|
function modelEfforts(model) {
|
|
21761
22071
|
const meta3 = record2(model._meta);
|
|
@@ -21855,11 +22165,11 @@ function classifySpawnError(error62, context) {
|
|
|
21855
22165
|
|
|
21856
22166
|
// src/providers/cli/kiro-session-log.ts
|
|
21857
22167
|
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
|
|
22168
|
+
import { homedir as homedir9 } from "node:os";
|
|
22169
|
+
import { join as join12 } from "node:path";
|
|
21860
22170
|
var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "execute_bash", "bash"]);
|
|
21861
22171
|
function kiroSessionsDirectory() {
|
|
21862
|
-
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR ||
|
|
22172
|
+
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR || join12(homedir9(), ".kiro", "sessions", "cli");
|
|
21863
22173
|
}
|
|
21864
22174
|
var KiroSessionLog = class {
|
|
21865
22175
|
constructor(options) {
|
|
@@ -21878,7 +22188,7 @@ var KiroSessionLog = class {
|
|
|
21878
22188
|
/** Called before the CLI starts: a resumed log is followed from its current end. */
|
|
21879
22189
|
async begin() {
|
|
21880
22190
|
if (!this.options.sessionId) return;
|
|
21881
|
-
this.path =
|
|
22191
|
+
this.path = join12(this.directory, `${this.options.sessionId}.jsonl`);
|
|
21882
22192
|
this.offset = await stat2(this.path).then((info) => info.size, () => 0);
|
|
21883
22193
|
}
|
|
21884
22194
|
/**
|
|
@@ -21891,11 +22201,11 @@ var KiroSessionLog = class {
|
|
|
21891
22201
|
const found = [];
|
|
21892
22202
|
for (const name of names) {
|
|
21893
22203
|
if (!name.endsWith(".json")) continue;
|
|
21894
|
-
const meta3 = await readFile5(
|
|
22204
|
+
const meta3 = await readFile5(join12(this.directory, name), "utf8").then((text3) => JSON.parse(text3), () => void 0);
|
|
21895
22205
|
const created = meta3?.created_at ? Date.parse(meta3.created_at) : NaN;
|
|
21896
22206
|
if (meta3?.cwd && sameFolder(meta3.cwd, this.options.workdir) && created >= this.options.startedAt - 2e3) found.push(name.slice(0, -5));
|
|
21897
22207
|
}
|
|
21898
|
-
if (found.length === 1) this.path =
|
|
22208
|
+
if (found.length === 1) this.path = join12(this.directory, `${found[0]}.jsonl`);
|
|
21899
22209
|
}
|
|
21900
22210
|
/** Reads entries appended since the last call. */
|
|
21901
22211
|
async refresh() {
|
|
@@ -22206,7 +22516,7 @@ var KIRO_ACP_DIALECT = {
|
|
|
22206
22516
|
};
|
|
22207
22517
|
|
|
22208
22518
|
// src/acp/acp-dialects/omp-dialect.ts
|
|
22209
|
-
function
|
|
22519
|
+
function normalizeToolUpdate2(update) {
|
|
22210
22520
|
const rawOutput = record2(update.rawOutput);
|
|
22211
22521
|
if (!Array.isArray(rawOutput.content)) return update;
|
|
22212
22522
|
if (["exitCode", "exit_code", "stdout", "stderr"].some((key) => rawOutput[key] !== void 0)) return update;
|
|
@@ -22222,7 +22532,7 @@ function normalizeToolUpdate(update) {
|
|
|
22222
22532
|
};
|
|
22223
22533
|
}
|
|
22224
22534
|
var OMP_ACP_DIALECT = {
|
|
22225
|
-
normalizeToolUpdate,
|
|
22535
|
+
normalizeToolUpdate: normalizeToolUpdate2,
|
|
22226
22536
|
promptErrorDetail: (error62) => {
|
|
22227
22537
|
const details = record2(error62.data).details;
|
|
22228
22538
|
return typeof details === "string" && details ? details : void 0;
|
|
@@ -22234,7 +22544,7 @@ var OMP_ACP_DIALECT = {
|
|
|
22234
22544
|
};
|
|
22235
22545
|
|
|
22236
22546
|
// src/acp/acp-dialects/opencode-dialect.ts
|
|
22237
|
-
function
|
|
22547
|
+
function normalizeToolUpdate3(update) {
|
|
22238
22548
|
const raw = update.rawOutput;
|
|
22239
22549
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return update;
|
|
22240
22550
|
const rawOutput = raw;
|
|
@@ -22254,7 +22564,7 @@ function normalizeToolUpdate2(update) {
|
|
|
22254
22564
|
};
|
|
22255
22565
|
}
|
|
22256
22566
|
var OPENCODE_ACP_DIALECT = {
|
|
22257
|
-
normalizeToolUpdate:
|
|
22567
|
+
normalizeToolUpdate: normalizeToolUpdate3,
|
|
22258
22568
|
failureRules: [
|
|
22259
22569
|
{ kind: "usageLimit", pattern: /"errorName"\s*:\s*"provider\.quota"/ },
|
|
22260
22570
|
{ kind: "rateLimited", pattern: /"errorName"\s*:\s*"provider\.rate-limit"/ }
|
|
@@ -22264,9 +22574,9 @@ var OPENCODE_ACP_DIALECT = {
|
|
|
22264
22574
|
// src/acp/vendor.ts
|
|
22265
22575
|
import { spawn as spawn6 } from "node:child_process";
|
|
22266
22576
|
import { createHash } from "node:crypto";
|
|
22267
|
-
import { existsSync as existsSync6, readFileSync as
|
|
22577
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "node:fs";
|
|
22268
22578
|
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
|
|
22579
|
+
import { dirname as dirname7, join as join13, resolve as resolve4 } from "node:path";
|
|
22270
22580
|
import { fileURLToPath } from "node:url";
|
|
22271
22581
|
var AcpRuntimeUnavailable = class extends Error {
|
|
22272
22582
|
constructor(message) {
|
|
@@ -22281,7 +22591,7 @@ function packageRoot() {
|
|
|
22281
22591
|
const path = resolve4(directory, "package.json");
|
|
22282
22592
|
if (existsSync6(path)) {
|
|
22283
22593
|
try {
|
|
22284
|
-
if (JSON.parse(
|
|
22594
|
+
if (JSON.parse(readFileSync6(path, "utf8")).name === "toc-ocra") return directory;
|
|
22285
22595
|
} catch {
|
|
22286
22596
|
}
|
|
22287
22597
|
}
|
|
@@ -22299,29 +22609,29 @@ function agentPackageVersion() {
|
|
|
22299
22609
|
const directory = agentRoot();
|
|
22300
22610
|
if (!directory) return "0";
|
|
22301
22611
|
try {
|
|
22302
|
-
return JSON.parse(
|
|
22612
|
+
return JSON.parse(readFileSync6(join13(directory, "package.json"), "utf8")).version ?? "0";
|
|
22303
22613
|
} catch {
|
|
22304
22614
|
return "0";
|
|
22305
22615
|
}
|
|
22306
22616
|
}
|
|
22307
22617
|
function vendoredAdapter(name) {
|
|
22308
22618
|
const directory = agentRoot();
|
|
22309
|
-
const entry = directory ?
|
|
22619
|
+
const entry = directory ? join13(directory, "assets", "acp", name, "index.mjs") : void 0;
|
|
22310
22620
|
return entry && existsSync6(entry) ? entry : void 0;
|
|
22311
22621
|
}
|
|
22312
22622
|
var installs = /* @__PURE__ */ new Map();
|
|
22313
22623
|
function ensureClaudeRuntime(dataDir2) {
|
|
22314
22624
|
const entry = vendoredAdapter("claude");
|
|
22315
22625
|
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 =
|
|
22626
|
+
const manifestPath = join13(dirname7(entry), "runtime.json");
|
|
22317
22627
|
let manifest;
|
|
22318
22628
|
try {
|
|
22319
|
-
manifest = JSON.parse(
|
|
22629
|
+
manifest = JSON.parse(readFileSync6(manifestPath, "utf8"));
|
|
22320
22630
|
} catch {
|
|
22321
22631
|
return Promise.reject(new AcpRuntimeUnavailable("Claude ACP \u9002\u914D\u5668\u7F3A\u5C11 runtime.json"));
|
|
22322
22632
|
}
|
|
22323
|
-
const hash2 = createHash("sha256").update(
|
|
22324
|
-
const directory =
|
|
22633
|
+
const hash2 = createHash("sha256").update(readFileSync6(entry)).digest("hex").slice(0, 12);
|
|
22634
|
+
const directory = join13(dataDir2, "acp-runtimes", `claude-${manifest.adapterVersion}-sdk-${manifest.sdk.version}-${hash2}`);
|
|
22325
22635
|
const existing = installs.get(directory);
|
|
22326
22636
|
if (existing) return existing;
|
|
22327
22637
|
const install = installClaudeRuntime(directory, entry, manifest).catch((error62) => {
|
|
@@ -22332,19 +22642,19 @@ function ensureClaudeRuntime(dataDir2) {
|
|
|
22332
22642
|
return install;
|
|
22333
22643
|
}
|
|
22334
22644
|
async function installClaudeRuntime(directory, entry, manifest) {
|
|
22335
|
-
const sdkPackage =
|
|
22336
|
-
if (existsSync6(sdkPackage) && existsSync6(
|
|
22645
|
+
const sdkPackage = join13(directory, "node_modules", ...manifest.sdk.name.split("/"), "package.json");
|
|
22646
|
+
if (existsSync6(sdkPackage) && existsSync6(join13(directory, "index.mjs"))) return directory;
|
|
22337
22647
|
const temporary = `${directory}.tmp-${process.pid}-${Date.now()}`;
|
|
22338
22648
|
await mkdir4(temporary, { recursive: true, mode: 448 });
|
|
22339
22649
|
try {
|
|
22340
|
-
await writeFile4(
|
|
22650
|
+
await writeFile4(join13(temporary, "package.json"), JSON.stringify({
|
|
22341
22651
|
name: "toc-ocra-claude-acp-runtime",
|
|
22342
22652
|
private: true,
|
|
22343
22653
|
type: "module",
|
|
22344
22654
|
dependencies: { [manifest.sdk.name]: manifest.sdk.version }
|
|
22345
22655
|
}, null, 2));
|
|
22346
22656
|
await runNpm(["install", "--omit=optional", "--no-audit", "--no-fund", "--no-package-lock", "--loglevel=error"], temporary);
|
|
22347
|
-
await copyFile(entry,
|
|
22657
|
+
await copyFile(entry, join13(temporary, "index.mjs"));
|
|
22348
22658
|
await rm2(directory, { recursive: true, force: true });
|
|
22349
22659
|
await rename4(temporary, directory);
|
|
22350
22660
|
} catch (error62) {
|
|
@@ -22418,6 +22728,22 @@ var GEMINI_LAUNCH_SPEC = {
|
|
|
22418
22728
|
dialect: GEMINI_ACP_DIALECT,
|
|
22419
22729
|
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.gemini }
|
|
22420
22730
|
};
|
|
22731
|
+
var ANTIGRAVITY_LAUNCH_SPEC = {
|
|
22732
|
+
agent: "antigravity",
|
|
22733
|
+
headless: "acp",
|
|
22734
|
+
// agy has no full-access mode in session/set_mode; its launch flag grants it while plan approvals still reach the chat.
|
|
22735
|
+
args: ({ access }) => ["acp", ...access === "bypassPermissions" ? ["--dangerously-skip-permissions"] : []],
|
|
22736
|
+
env: { AGY_CLI_DISABLE_AUTO_UPDATE: "true" },
|
|
22737
|
+
scrubEnv: (env) => scrubAntigravityEnv(env),
|
|
22738
|
+
minimumVersions: ["1.5.2"],
|
|
22739
|
+
permissionModeConfig: {
|
|
22740
|
+
values: { ask: "default", acceptEdits: "accept-edits", bypassPermissions: "default", plan: "plan" }
|
|
22741
|
+
},
|
|
22742
|
+
resumePreference: "resume",
|
|
22743
|
+
dialect: ANTIGRAVITY_ACP_DIALECT,
|
|
22744
|
+
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.antigravity },
|
|
22745
|
+
runSettings: { permissionModes: ["read-only", "acceptEdits", "bypassPermissions"], plan: "native" }
|
|
22746
|
+
};
|
|
22421
22747
|
var GROK_LAUNCH_SPEC = {
|
|
22422
22748
|
agent: "grok",
|
|
22423
22749
|
headless: "acp",
|
|
@@ -22470,7 +22796,7 @@ var CLAUDE_LAUNCH_SPEC = {
|
|
|
22470
22796
|
const executable = installedCli(claude);
|
|
22471
22797
|
const runtime = await ensureClaudeRuntime(dataDir2);
|
|
22472
22798
|
return {
|
|
22473
|
-
launch: { executable: process.execPath, args: [
|
|
22799
|
+
launch: { executable: process.execPath, args: [join14(runtime, "index.mjs")], env: { ...providerEnvironment(), CLAUDE_CODE_EXECUTABLE: executable }, cwd: workdir },
|
|
22474
22800
|
fingerprint: `claude:${runtime}:${executable}`
|
|
22475
22801
|
};
|
|
22476
22802
|
},
|
|
@@ -22518,6 +22844,7 @@ var ACP_LAUNCH_SPECS = [
|
|
|
22518
22844
|
KIRO_LAUNCH_SPEC,
|
|
22519
22845
|
KIMI_LAUNCH_SPEC,
|
|
22520
22846
|
GEMINI_LAUNCH_SPEC,
|
|
22847
|
+
ANTIGRAVITY_LAUNCH_SPEC,
|
|
22521
22848
|
GROK_LAUNCH_SPEC,
|
|
22522
22849
|
OPENCODE_LAUNCH_SPEC,
|
|
22523
22850
|
OMP_LAUNCH_SPEC,
|
|
@@ -22565,7 +22892,9 @@ function chatSpec(row) {
|
|
|
22565
22892
|
async launch({ access, model, reasoningEffort, workdir, dataDir: dataDir2 }) {
|
|
22566
22893
|
if (row.adapter) return row.adapter({ access, model, reasoningEffort, workdir, dataDir: dataDir2 });
|
|
22567
22894
|
const args = row.args({ access, model, reasoningEffort });
|
|
22568
|
-
const
|
|
22895
|
+
const baseEnv = { ...await hydrateRuntimeProxy(providerEnvironment()), ...row.env };
|
|
22896
|
+
const env = row.scrubEnv ? row.scrubEnv(baseEnv) : baseEnv;
|
|
22897
|
+
const spec = launchCli({ spec: cli, args, env });
|
|
22569
22898
|
return { launch: { executable: spec.executable, args: spec.args, env: spec.env, cwd: workdir }, fingerprint: args.join(" ") };
|
|
22570
22899
|
},
|
|
22571
22900
|
...row.permissionModeConfig ? { modeFor: (access, plan) => acpModeFor(row, access, plan) } : {},
|
|
@@ -22589,7 +22918,7 @@ var ACP_CHAT_IDS = [...ACP_CHAT.keys()];
|
|
|
22589
22918
|
// src/acp/acp-model-catalog-probe.ts
|
|
22590
22919
|
import { mkdtemp, rm as rm3 } from "node:fs/promises";
|
|
22591
22920
|
import { tmpdir } from "node:os";
|
|
22592
|
-
import { join as
|
|
22921
|
+
import { join as join15 } from "node:path";
|
|
22593
22922
|
|
|
22594
22923
|
// src/acp/acp-options.ts
|
|
22595
22924
|
var text = (value) => typeof value === "string" && value ? value : void 0;
|
|
@@ -22668,7 +22997,8 @@ function settingWrite(state, step, settings, cliLabel) {
|
|
|
22668
22997
|
if (!model) return {};
|
|
22669
22998
|
const option = findOption(state.configOptions, "model");
|
|
22670
22999
|
if (option) {
|
|
22671
|
-
const
|
|
23000
|
+
const stripped = /^(.+)-(?:low|medium|high|xhigh|max)$/i.exec(model)?.[1];
|
|
23001
|
+
const value = matchChoice(option, model) ?? (stripped ? matchChoice(option, stripped) : void 0);
|
|
22672
23002
|
if (!value) return { note: `${cliLabel} \u6CA1\u6709\u6A21\u578B\u300C${model}\u300D\uFF0C\u672C\u8F6E\u4F7F\u7528\u5F53\u524D\u6A21\u578B` };
|
|
22673
23003
|
return option.currentValue === value ? {} : config2(option, value);
|
|
22674
23004
|
}
|
|
@@ -22676,9 +23006,11 @@ function settingWrite(state, step, settings, cliLabel) {
|
|
|
22676
23006
|
return state.currentModelId === model ? {} : { write: { step, label: STEP_LABEL[step], method: "session/set_model", params: { modelId: model } } };
|
|
22677
23007
|
}
|
|
22678
23008
|
case "effort": {
|
|
22679
|
-
|
|
23009
|
+
const inferred = settings.model ? /^.+-(low|medium|high|xhigh|max)$/i.exec(settings.model)?.[1] : void 0;
|
|
23010
|
+
const wantedEffort = settings.reasoningEffort || inferred;
|
|
23011
|
+
if (!wantedEffort) return {};
|
|
22680
23012
|
const option = findOption(state.configOptions, "thought_level");
|
|
22681
|
-
const value = option ? matchChoice(option,
|
|
23013
|
+
const value = option ? matchChoice(option, wantedEffort) : void 0;
|
|
22682
23014
|
return option && value && option.currentValue !== value ? config2(option, value) : {};
|
|
22683
23015
|
}
|
|
22684
23016
|
case "fast": {
|
|
@@ -23222,9 +23554,9 @@ async function readSessionModels(row, clientVersion = "1") {
|
|
|
23222
23554
|
const discovery = row.modelDiscovery;
|
|
23223
23555
|
if (discovery.kind !== "session") throw new Error(`${row.agent} does not list its models in a session`);
|
|
23224
23556
|
const cli = requireCliSpec(row.agent);
|
|
23225
|
-
const folder = await mkdtemp(
|
|
23557
|
+
const folder = await mkdtemp(join15(tmpdir(), `toc-ocra-acp-models-${row.agent}-`));
|
|
23226
23558
|
try {
|
|
23227
|
-
const folderArgs = discovery.sessionFolderArgs?.(
|
|
23559
|
+
const folderArgs = discovery.sessionFolderArgs?.(join15(folder, "sessions")) ?? [];
|
|
23228
23560
|
const args = [...row.args({ access: "read-only", model: "", reasoningEffort: "" }), ...folderArgs];
|
|
23229
23561
|
const launch = launchCli({ spec: cli, args, env: { ...providerEnvironment(), ...row.env } });
|
|
23230
23562
|
const connection = await AcpConnection.open({ executable: launch.executable, args: launch.args, env: launch.env, cwd: folder }, {
|
|
@@ -23853,14 +24185,14 @@ function isWriterConflict(message) {
|
|
|
23853
24185
|
}
|
|
23854
24186
|
|
|
23855
24187
|
// src/providers/cli/claude.ts
|
|
23856
|
-
import { readdirSync as readdirSync4, readFileSync as
|
|
23857
|
-
import { homedir as
|
|
23858
|
-
import { join as
|
|
24188
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync7 } from "node:fs";
|
|
24189
|
+
import { homedir as homedir10 } from "node:os";
|
|
24190
|
+
import { join as join16 } from "node:path";
|
|
23859
24191
|
var CLAUDE = requireCliSpec("claude");
|
|
23860
24192
|
function claudeProjectRoots() {
|
|
23861
24193
|
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) =>
|
|
24194
|
+
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [join16(homedir10(), ".claude")];
|
|
24195
|
+
return dirs.map((dir) => join16(dir, "projects"));
|
|
23864
24196
|
}
|
|
23865
24197
|
function claudeTranscriptExists(sessionId) {
|
|
23866
24198
|
return claudeTranscriptPath(sessionId) !== void 0;
|
|
@@ -23876,7 +24208,7 @@ function claudeTranscriptPath(sessionId) {
|
|
|
23876
24208
|
}
|
|
23877
24209
|
for (const project of projects) {
|
|
23878
24210
|
try {
|
|
23879
|
-
if (readdirSync4(
|
|
24211
|
+
if (readdirSync4(join16(root2, project)).includes(file2)) return join16(root2, project, file2);
|
|
23880
24212
|
} catch {
|
|
23881
24213
|
}
|
|
23882
24214
|
}
|
|
@@ -23920,7 +24252,7 @@ var claudeProvider = {
|
|
|
23920
24252
|
settings.disableAllHooks = true;
|
|
23921
24253
|
args.push("--restricted", "--permission-mode", "plan", "--tools", "Read,Glob,Grep", "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--disallowedTools", "mcp__*");
|
|
23922
24254
|
try {
|
|
23923
|
-
const userSettings = JSON.parse(
|
|
24255
|
+
const userSettings = JSON.parse(readFileSync7(join16(homedir10(), ".claude", "settings.json"), "utf8"));
|
|
23924
24256
|
for (const [key, value] of Object.entries(userSettings.env ?? {})) {
|
|
23925
24257
|
if (/^ANTHROPIC_[A-Z0-9_]+$/.test(key) && typeof value === "string" && env[key] === void 0) env[key] = value;
|
|
23926
24258
|
}
|
|
@@ -23936,7 +24268,7 @@ var claudeProvider = {
|
|
|
23936
24268
|
if (source && request.fork.keepTurns > 0) {
|
|
23937
24269
|
let text3 = "";
|
|
23938
24270
|
try {
|
|
23939
|
-
text3 =
|
|
24271
|
+
text3 = readFileSync7(source, "utf8");
|
|
23940
24272
|
} catch {
|
|
23941
24273
|
}
|
|
23942
24274
|
const at = claudeForkBoundary(text3, request.fork.keepTurns);
|
|
@@ -24654,7 +24986,8 @@ function createAcpProvider(row) {
|
|
|
24654
24986
|
...turn.reasoningEffort && !row.launchApplies?.reasoningEffort ? { reasoningEffort: turn.reasoningEffort } : {},
|
|
24655
24987
|
...row.runSettings?.fast && turn.fast !== void 0 ? { fast: turn.fast } : {}
|
|
24656
24988
|
};
|
|
24657
|
-
const
|
|
24989
|
+
const baseEnv = { ...providerEnvironment(), ...row.env };
|
|
24990
|
+
const env = row.scrubEnv ? row.scrubEnv(baseEnv) : baseEnv;
|
|
24658
24991
|
launchEnv = env;
|
|
24659
24992
|
return launchCli({ spec: cli, args: row.args({ access, model: turn.model, reasoningEffort: turn.reasoningEffort }), env });
|
|
24660
24993
|
},
|
|
@@ -24731,11 +25064,229 @@ var opencodeProvider = {
|
|
|
24731
25064
|
}
|
|
24732
25065
|
};
|
|
24733
25066
|
|
|
25067
|
+
// src/providers/antigravity-quota.ts
|
|
25068
|
+
import { spawn as spawn8 } from "node:child_process";
|
|
25069
|
+
var ANTIGRAVITY_MIN_USAGE_VERSION = "1.1.11";
|
|
25070
|
+
var ANTIGRAVITY_USAGE_ARGS = ["-p", "/usage", "--output-format", "json", "--print-timeout", "20s"];
|
|
25071
|
+
var VERSION_TIMEOUT_MS = 5e3;
|
|
25072
|
+
var USAGE_TIMEOUT_MS = 3e4;
|
|
25073
|
+
var MAX_OUTPUT_BYTES = 512 * 1024;
|
|
25074
|
+
var AGY_ERROR_PREFIX = "AGY_ERROR:";
|
|
25075
|
+
var WEEKLY_WINDOW_SECONDS = 7 * 86400;
|
|
25076
|
+
var SESSION_WINDOW_SECONDS = 5 * 3600;
|
|
25077
|
+
var SIGNED_OUT_PHRASES = [
|
|
25078
|
+
"not logged into antigravity",
|
|
25079
|
+
"not logged in",
|
|
25080
|
+
"not signed in",
|
|
25081
|
+
"not authenticated",
|
|
25082
|
+
"not-authenticated",
|
|
25083
|
+
"unauthenticated",
|
|
25084
|
+
"run agy login",
|
|
25085
|
+
"please sign in",
|
|
25086
|
+
"please log in",
|
|
25087
|
+
"sign in to antigravity",
|
|
25088
|
+
"no credentials",
|
|
25089
|
+
"authentication required"
|
|
25090
|
+
];
|
|
25091
|
+
var unsupportedUsageLatched = false;
|
|
25092
|
+
function isRecord(value) {
|
|
25093
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25094
|
+
}
|
|
25095
|
+
function readString(value) {
|
|
25096
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
25097
|
+
}
|
|
25098
|
+
function parseResetSeconds(value) {
|
|
25099
|
+
const text3 = readString(value);
|
|
25100
|
+
if (!text3) return 0;
|
|
25101
|
+
const ms = Date.parse(text3);
|
|
25102
|
+
return Number.isFinite(ms) ? Math.floor(ms / 1e3) : 0;
|
|
25103
|
+
}
|
|
25104
|
+
function windowSecondsFor(window) {
|
|
25105
|
+
if (window === "weekly") return WEEKLY_WINDOW_SECONDS;
|
|
25106
|
+
if (window === "5h") return SESSION_WINDOW_SECONDS;
|
|
25107
|
+
return void 0;
|
|
25108
|
+
}
|
|
25109
|
+
function shortGroupLabel(groupName) {
|
|
25110
|
+
const lower = groupName.toLowerCase();
|
|
25111
|
+
if (lower === "gemini models" || lower === "gemini") return "Gemini";
|
|
25112
|
+
if (lower === "claude and gpt models" || lower === "claude & gpt models") return "Claude / GPT";
|
|
25113
|
+
return groupName.replace(/\s+models$/i, "").trim() || groupName;
|
|
25114
|
+
}
|
|
25115
|
+
function shortWindowLabel(window, rawName) {
|
|
25116
|
+
if (window === "weekly") return "\u6BCF\u5468\u989D\u5EA6";
|
|
25117
|
+
if (window === "5h") return "5 \u5C0F\u65F6\u989D\u5EA6";
|
|
25118
|
+
if (!rawName) return "\u989D\u5EA6";
|
|
25119
|
+
return rawName.replace(/\s+(?:remaining|used|left)$/i, "").trim() || rawName;
|
|
25120
|
+
}
|
|
25121
|
+
function formatBucketLabel(groupName, window, rawName, siblings) {
|
|
25122
|
+
const group = shortGroupLabel(groupName);
|
|
25123
|
+
const win = shortWindowLabel(window, rawName);
|
|
25124
|
+
return siblings <= 1 && !window && !rawName ? group : `${group} \xB7 ${win}`;
|
|
25125
|
+
}
|
|
25126
|
+
function findEnvelope(stdout, parse4) {
|
|
25127
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
25128
|
+
const trimmed = line.trim();
|
|
25129
|
+
if (!trimmed.startsWith("{")) continue;
|
|
25130
|
+
try {
|
|
25131
|
+
const found = parse4(JSON.parse(trimmed));
|
|
25132
|
+
if (found !== null) return found;
|
|
25133
|
+
} catch {
|
|
25134
|
+
continue;
|
|
25135
|
+
}
|
|
25136
|
+
}
|
|
25137
|
+
return null;
|
|
25138
|
+
}
|
|
25139
|
+
function antigravityStdoutShowsModelTurn(stdout) {
|
|
25140
|
+
return findEnvelope(stdout, (value) => {
|
|
25141
|
+
if (!isRecord(value)) return null;
|
|
25142
|
+
if (typeof value.num_turns === "number" && value.num_turns > 0) return true;
|
|
25143
|
+
return readString(value.conversation_id) !== null ? true : null;
|
|
25144
|
+
}) !== null;
|
|
25145
|
+
}
|
|
25146
|
+
function parseAntigravityUsageEnvelope(value) {
|
|
25147
|
+
if (!isRecord(value) || readString(value.status) !== "SUCCESS") return null;
|
|
25148
|
+
const command = value.command;
|
|
25149
|
+
if (!isRecord(command) || readString(command.name) !== "usage") return null;
|
|
25150
|
+
const data = command.data;
|
|
25151
|
+
if (!isRecord(data) || !Array.isArray(data.groups)) return null;
|
|
25152
|
+
const windows = [];
|
|
25153
|
+
for (const rawGroup of data.groups) {
|
|
25154
|
+
if (!isRecord(rawGroup)) continue;
|
|
25155
|
+
const groupName = readString(rawGroup.name);
|
|
25156
|
+
const rawBuckets = Array.isArray(rawGroup.buckets) ? rawGroup.buckets : [];
|
|
25157
|
+
if (!groupName) continue;
|
|
25158
|
+
const enabled = rawBuckets.filter((item) => isRecord(item) && item.disabled !== true);
|
|
25159
|
+
for (const bucket of enabled) {
|
|
25160
|
+
const id = readString(bucket.id);
|
|
25161
|
+
const fraction = bucket.remaining_fraction;
|
|
25162
|
+
if (!id || typeof fraction !== "number" || !Number.isFinite(fraction)) continue;
|
|
25163
|
+
const windowKind = readString(bucket.window);
|
|
25164
|
+
const windowSeconds = windowSecondsFor(windowKind);
|
|
25165
|
+
const usedPercent = Math.min(100, Math.max(0, Math.round((1 - fraction) * 1e4) / 100));
|
|
25166
|
+
windows.push({
|
|
25167
|
+
key: `antigravity:${id}`,
|
|
25168
|
+
label: formatBucketLabel(groupName, windowKind, readString(bucket.name), enabled.length),
|
|
25169
|
+
used_percent: usedPercent,
|
|
25170
|
+
resets_at: parseResetSeconds(bucket.reset_time),
|
|
25171
|
+
...windowSeconds ? { window_seconds: windowSeconds } : {}
|
|
25172
|
+
});
|
|
25173
|
+
}
|
|
25174
|
+
}
|
|
25175
|
+
if (data.groups.length > 0 && windows.length === 0) return null;
|
|
25176
|
+
return windows;
|
|
25177
|
+
}
|
|
25178
|
+
function parseAntigravityUsageStdout(stdout) {
|
|
25179
|
+
return findEnvelope(stdout, parseAntigravityUsageEnvelope);
|
|
25180
|
+
}
|
|
25181
|
+
function readAgyErrorEnvelope(stdout) {
|
|
25182
|
+
return findEnvelope(
|
|
25183
|
+
stdout,
|
|
25184
|
+
(value) => isRecord(value) && readString(value.status) === "ERROR" ? readString(value.error) : null
|
|
25185
|
+
);
|
|
25186
|
+
}
|
|
25187
|
+
function classifyFailure(output2, stderr) {
|
|
25188
|
+
if (stderr.includes("Authentication required. Please visit the URL")) {
|
|
25189
|
+
return "Antigravity \u672A\u767B\u5F55\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u5B8C\u6210\u540E\u518D\u540C\u6B65\u989D\u5EA6";
|
|
25190
|
+
}
|
|
25191
|
+
for (const line of output2.split(/\r?\n/)) {
|
|
25192
|
+
const idx = line.indexOf(AGY_ERROR_PREFIX);
|
|
25193
|
+
if (idx === -1) continue;
|
|
25194
|
+
const payload = line.slice(idx + AGY_ERROR_PREFIX.length).trim();
|
|
25195
|
+
if (!payload.startsWith("{")) continue;
|
|
25196
|
+
try {
|
|
25197
|
+
const parsed = JSON.parse(payload);
|
|
25198
|
+
const status = typeof parsed.status === "string" ? parsed.status.toUpperCase() : "";
|
|
25199
|
+
const code = typeof parsed.error_code === "number" ? parsed.error_code : null;
|
|
25200
|
+
if (status === "UNAUTHENTICATED" || code === 401) return "Antigravity \u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u91CD\u65B0\u767B\u5F55";
|
|
25201
|
+
if (status === "PERMISSION_DENIED" || code === 403) return "\u5F53\u524D Antigravity \u8D26\u53F7\u6CA1\u6709\u53EF\u7528\u7684\u8BA2\u9605\u989D\u5EA6\u6743\u9650";
|
|
25202
|
+
if (status === "RESOURCE_EXHAUSTED" || code === 429) return "Antigravity \u989D\u5EA6\u63A5\u53E3\u6682\u65F6\u9650\u6D41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5";
|
|
25203
|
+
if (code !== null && code >= 500 && code < 600) return `Antigravity \u670D\u52A1\u7AEF\u8FD4\u56DE\u9519\u8BEF (${code})`;
|
|
25204
|
+
} catch {
|
|
25205
|
+
continue;
|
|
25206
|
+
}
|
|
25207
|
+
}
|
|
25208
|
+
const lowered = output2.toLowerCase();
|
|
25209
|
+
if (SIGNED_OUT_PHRASES.some((phrase) => lowered.includes(phrase))) {
|
|
25210
|
+
return "Antigravity \u672A\u767B\u5F55\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u5B8C\u6210\u540E\u518D\u540C\u6B65\u989D\u5EA6";
|
|
25211
|
+
}
|
|
25212
|
+
return null;
|
|
25213
|
+
}
|
|
25214
|
+
function runCommand(executable, args, env, timeoutMs) {
|
|
25215
|
+
return new Promise((resolve9, reject) => {
|
|
25216
|
+
const child = spawn8(executable, [...args], { env, stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
25217
|
+
let stdout = "";
|
|
25218
|
+
let stderr = "";
|
|
25219
|
+
let timedOut = false;
|
|
25220
|
+
const append = (current, chunk) => {
|
|
25221
|
+
if (current.length >= MAX_OUTPUT_BYTES) return current;
|
|
25222
|
+
return current + chunk.toString("utf8", 0, Math.max(0, MAX_OUTPUT_BYTES - current.length));
|
|
25223
|
+
};
|
|
25224
|
+
const timer = setTimeout(() => {
|
|
25225
|
+
timedOut = true;
|
|
25226
|
+
child.kill("SIGKILL");
|
|
25227
|
+
}, timeoutMs);
|
|
25228
|
+
child.stdout.on("data", (chunk) => {
|
|
25229
|
+
stdout = append(stdout, chunk);
|
|
25230
|
+
});
|
|
25231
|
+
child.stderr.on("data", (chunk) => {
|
|
25232
|
+
stderr = append(stderr, chunk);
|
|
25233
|
+
});
|
|
25234
|
+
child.on("error", (error62) => {
|
|
25235
|
+
clearTimeout(timer);
|
|
25236
|
+
reject(error62);
|
|
25237
|
+
});
|
|
25238
|
+
child.on("close", (code) => {
|
|
25239
|
+
clearTimeout(timer);
|
|
25240
|
+
resolve9({ code, stdout, stderr, timedOut });
|
|
25241
|
+
});
|
|
25242
|
+
});
|
|
25243
|
+
}
|
|
25244
|
+
async function readAntigravityQuotaWindows() {
|
|
25245
|
+
if (unsupportedUsageLatched) {
|
|
25246
|
+
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");
|
|
25247
|
+
}
|
|
25248
|
+
const spec = requireCliSpec("antigravity");
|
|
25249
|
+
const baseEnv = await hydrateRuntimeProxy(providerEnvironment());
|
|
25250
|
+
const env = scrubAntigravityEnv(baseEnv);
|
|
25251
|
+
const versionLaunch = launchCli({ spec, args: ["--version"], env });
|
|
25252
|
+
const versionRun = await runCommand(versionLaunch.executable, versionLaunch.args, versionLaunch.env ?? env, VERSION_TIMEOUT_MS).catch((error62) => {
|
|
25253
|
+
const message = error62 instanceof Error ? error62.message : String(error62);
|
|
25254
|
+
if (/ENOENT/i.test(message)) throw new Error("\u672C\u673A\u672A\u5B89\u88C5 Antigravity CLI\uFF08agy\uFF09");
|
|
25255
|
+
throw new Error(`\u65E0\u6CD5\u542F\u52A8 Antigravity CLI\uFF1A${message}`);
|
|
25256
|
+
});
|
|
25257
|
+
const detected = versionRun.code === 0 && !versionRun.timedOut ? versionNumber(versionRun.stdout.trim() || versionRun.stderr.trim()) : void 0;
|
|
25258
|
+
if (!detected || compareVersions(detected, ANTIGRAVITY_MIN_USAGE_VERSION) < 0) {
|
|
25259
|
+
throw new Error(
|
|
25260
|
+
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"
|
|
25261
|
+
);
|
|
25262
|
+
}
|
|
25263
|
+
const usageLaunch = launchCli({ spec, args: [...ANTIGRAVITY_USAGE_ARGS], env });
|
|
25264
|
+
const result = await runCommand(usageLaunch.executable, usageLaunch.args, usageLaunch.env ?? env, USAGE_TIMEOUT_MS);
|
|
25265
|
+
const windows = parseAntigravityUsageStdout(result.stdout);
|
|
25266
|
+
if (!windows) {
|
|
25267
|
+
const classified = classifyFailure(`${result.stdout}
|
|
25268
|
+
${result.stderr}`, result.stderr);
|
|
25269
|
+
if (classified) throw new Error(classified);
|
|
25270
|
+
if (result.timedOut) throw new Error("\u8BFB\u53D6 Antigravity \u989D\u5EA6\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
25271
|
+
if (antigravityStdoutShowsModelTurn(result.stdout)) {
|
|
25272
|
+
unsupportedUsageLatched = true;
|
|
25273
|
+
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");
|
|
25274
|
+
}
|
|
25275
|
+
const envelopeError = readAgyErrorEnvelope(result.stdout);
|
|
25276
|
+
if (envelopeError) throw new Error(`Antigravity \u989D\u5EA6\u8BFB\u53D6\u5931\u8D25\uFF1A${envelopeError}`);
|
|
25277
|
+
throw new Error(`Antigravity \u672A\u8FD4\u56DE\u6709\u6548\u989D\u5EA6\u6570\u636E${result.code ? ` (exit ${result.code})` : ""}`);
|
|
25278
|
+
}
|
|
25279
|
+
if (windows.length === 0) {
|
|
25280
|
+
throw new Error("Antigravity \u5F53\u524D\u8D26\u53F7\u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u7684\u989D\u5EA6\u7A97\u53E3");
|
|
25281
|
+
}
|
|
25282
|
+
return windows;
|
|
25283
|
+
}
|
|
25284
|
+
|
|
24734
25285
|
// src/providers/claude-quota.ts
|
|
24735
25286
|
import { execFile as execFile5 } from "node:child_process";
|
|
24736
25287
|
import { readFile as readFile6 } from "node:fs/promises";
|
|
24737
|
-
import { homedir as
|
|
24738
|
-
import { join as
|
|
25288
|
+
import { homedir as homedir11 } from "node:os";
|
|
25289
|
+
import { join as join17 } from "node:path";
|
|
24739
25290
|
import { promisify as promisify3 } from "node:util";
|
|
24740
25291
|
var execFileAsync3 = promisify3(execFile5);
|
|
24741
25292
|
var CLAUDE_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
@@ -24774,7 +25325,7 @@ function parseClaudeQuota(body) {
|
|
|
24774
25325
|
}
|
|
24775
25326
|
return windows;
|
|
24776
25327
|
}
|
|
24777
|
-
var claudeHome2 = () => process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
25328
|
+
var claudeHome2 = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join17(homedir11(), ".claude");
|
|
24778
25329
|
function tokenFrom(content) {
|
|
24779
25330
|
try {
|
|
24780
25331
|
const token = objectValue2(objectValue2(JSON.parse(content)).claudeAiOauth).accessToken;
|
|
@@ -24786,7 +25337,7 @@ function tokenFrom(content) {
|
|
|
24786
25337
|
async function readClaudeAccessToken() {
|
|
24787
25338
|
const fromEnv = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
24788
25339
|
if (fromEnv) return fromEnv;
|
|
24789
|
-
const fromFile = tokenFrom(await readFile6(
|
|
25340
|
+
const fromFile = tokenFrom(await readFile6(join17(claudeHome2(), ".credentials.json"), "utf8").catch(() => ""));
|
|
24790
25341
|
if (fromFile) return fromFile;
|
|
24791
25342
|
if (process.platform !== "darwin") return void 0;
|
|
24792
25343
|
const { stdout } = await execFileAsync3("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 1e4 }).catch(() => ({ stdout: "" }));
|
|
@@ -24808,11 +25359,11 @@ async function readClaudeQuotaWindows() {
|
|
|
24808
25359
|
}
|
|
24809
25360
|
|
|
24810
25361
|
// src/providers/codex-quota.ts
|
|
24811
|
-
import { spawn as
|
|
25362
|
+
import { spawn as spawn9 } from "node:child_process";
|
|
24812
25363
|
import { createInterface as createInterface3 } from "node:readline";
|
|
24813
25364
|
async function readCodexQuotaWindows() {
|
|
24814
25365
|
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--stdio"] });
|
|
24815
|
-
const child =
|
|
25366
|
+
const child = spawn9(launch.executable, launch.args, { env: launch.env, stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
24816
25367
|
let nextId = 0;
|
|
24817
25368
|
const pending = /* @__PURE__ */ new Map();
|
|
24818
25369
|
const lines = createInterface3({ input: child.stdout });
|
|
@@ -24984,6 +25535,7 @@ var NATIVE = {
|
|
|
24984
25535
|
claude: { headless: claudeProvider, chat: (_request, attachments) => claudeChatProvider(attachments), models: MODEL_SOURCES.claude, quota: readClaudeQuotaWindows, runSettings: { permissionModes: ALL_LEVELS, plan: "native", fast: true } }
|
|
24985
25536
|
};
|
|
24986
25537
|
var ACP_EXTRAS = {
|
|
25538
|
+
antigravity: { quota: readAntigravityQuotaWindows },
|
|
24987
25539
|
kiro: { quota: readKiroQuotaWindows, legacy: { headless: kiroProvider, restrictedPermission: true, runSettings: { permissionModes: ["read-only", "bypassPermissions"], plan: "prompt" } } },
|
|
24988
25540
|
gemini: { legacy: { headless: geminiProvider, restrictedPermission: false } },
|
|
24989
25541
|
grok: { legacy: { headless: grokProvider, restrictedPermission: false } },
|
|
@@ -25083,7 +25635,7 @@ function probeVersion(path, args) {
|
|
|
25083
25635
|
if (args.length === 0) return Promise.resolve({});
|
|
25084
25636
|
return new Promise((resolve9) => {
|
|
25085
25637
|
const launch = directLaunch2(path, args, process.env.TOC_OCRA_NODE_PATH || process.execPath);
|
|
25086
|
-
const child =
|
|
25638
|
+
const child = spawn10(launch.executable, launch.args, { stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
25087
25639
|
let stdout = "";
|
|
25088
25640
|
let stderr = "";
|
|
25089
25641
|
let settled = false;
|
|
@@ -25167,10 +25719,10 @@ var cliDetection = new CliDetectionService();
|
|
|
25167
25719
|
|
|
25168
25720
|
// src/runtime/agent-runtime.ts
|
|
25169
25721
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
25170
|
-
import { join as
|
|
25722
|
+
import { join as join24 } from "node:path";
|
|
25171
25723
|
|
|
25172
25724
|
// src/exec/script-runner.ts
|
|
25173
|
-
import { spawn as
|
|
25725
|
+
import { spawn as spawn11 } from "node:child_process";
|
|
25174
25726
|
var MAX_SCRIPT_OUTPUT_BYTES = 112 * 1024;
|
|
25175
25727
|
function executeScript(command, workdir, timeoutSeconds) {
|
|
25176
25728
|
return new Promise((resolveExecution) => {
|
|
@@ -25201,7 +25753,7 @@ function executeScript(command, workdir, timeoutSeconds) {
|
|
|
25201
25753
|
};
|
|
25202
25754
|
let child;
|
|
25203
25755
|
try {
|
|
25204
|
-
child =
|
|
25756
|
+
child = spawn11(executable, args, {
|
|
25205
25757
|
cwd: workdir,
|
|
25206
25758
|
env: process.env,
|
|
25207
25759
|
detached: ownGroup,
|
|
@@ -25295,12 +25847,12 @@ var MemoryBindingSchema = external_exports.object({
|
|
|
25295
25847
|
memory_id: external_exports.string().trim().min(1).max(200)
|
|
25296
25848
|
});
|
|
25297
25849
|
var COMMAND_TIMEOUT_MS = 15e3;
|
|
25298
|
-
var
|
|
25850
|
+
var MAX_OUTPUT_BYTES2 = 1024 * 1024;
|
|
25299
25851
|
var runNmem = (args) => {
|
|
25300
25852
|
const env = providerEnvironment();
|
|
25301
25853
|
const launch = resolveExecutable("nmem", args, env, process.env.TOC_OCRA_NMEM_PATH);
|
|
25302
25854
|
return new Promise((resolve9) => {
|
|
25303
|
-
execFile7(launch.executable, launch.args, { env: launch.env, timeout: COMMAND_TIMEOUT_MS, maxBuffer:
|
|
25855
|
+
execFile7(launch.executable, launch.args, { env: launch.env, timeout: COMMAND_TIMEOUT_MS, maxBuffer: MAX_OUTPUT_BYTES2, windowsHide: true }, (error62, stdout) => {
|
|
25304
25856
|
if (!error62) {
|
|
25305
25857
|
resolve9({ stdout: String(stdout) });
|
|
25306
25858
|
return;
|
|
@@ -25456,15 +26008,15 @@ async function readCLIQuotaReport(agentType) {
|
|
|
25456
26008
|
|
|
25457
26009
|
// src/providers/tb-switch-control.ts
|
|
25458
26010
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
25459
|
-
import { homedir as
|
|
25460
|
-
import { join as
|
|
26011
|
+
import { homedir as homedir12 } from "node:os";
|
|
26012
|
+
import { join as join18 } from "node:path";
|
|
25461
26013
|
function dataDir() {
|
|
25462
|
-
return process.env.TB_SWITCH_HOME?.trim() ||
|
|
26014
|
+
return process.env.TB_SWITCH_HOME?.trim() || join18(homedir12(), ".tb-switch");
|
|
25463
26015
|
}
|
|
25464
26016
|
async function readLocalService() {
|
|
25465
26017
|
let discovery;
|
|
25466
26018
|
try {
|
|
25467
|
-
discovery = JSON.parse(await readFile7(
|
|
26019
|
+
discovery = JSON.parse(await readFile7(join18(dataDir(), "api.json"), "utf8"));
|
|
25468
26020
|
} catch {
|
|
25469
26021
|
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
26022
|
}
|
|
@@ -25480,7 +26032,7 @@ async function readLocalService() {
|
|
|
25480
26032
|
}
|
|
25481
26033
|
let token = process.env.TB_SWITCH_API_TOKEN?.trim() ?? "";
|
|
25482
26034
|
try {
|
|
25483
|
-
token = (await readFile7(
|
|
26035
|
+
token = (await readFile7(join18(dataDir(), "api-token"), "utf8")).trim();
|
|
25484
26036
|
} catch {
|
|
25485
26037
|
}
|
|
25486
26038
|
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 +26175,9 @@ function commandOf(pid) {
|
|
|
25623
26175
|
}
|
|
25624
26176
|
|
|
25625
26177
|
// src/runs/run-supervisor.ts
|
|
25626
|
-
import { spawn as
|
|
26178
|
+
import { spawn as spawn13 } from "node:child_process";
|
|
25627
26179
|
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
|
|
26180
|
+
import { basename as basename3, isAbsolute as isAbsolute4, join as join22, relative as relative2, resolve as resolve5 } from "node:path";
|
|
25629
26181
|
import { createInterface as createInterface5 } from "node:readline";
|
|
25630
26182
|
|
|
25631
26183
|
// src/session/terminal-tail-buffer.ts
|
|
@@ -25907,12 +26459,12 @@ function codexGoalProvider(request, goal) {
|
|
|
25907
26459
|
}
|
|
25908
26460
|
|
|
25909
26461
|
// src/providers/cli/codex-fork.ts
|
|
25910
|
-
import { spawn as
|
|
26462
|
+
import { spawn as spawn12 } from "node:child_process";
|
|
25911
26463
|
import { createInterface as createInterface4 } from "node:readline";
|
|
25912
26464
|
var FORK_TIMEOUT_MS = 9e4;
|
|
25913
26465
|
async function forkCodexThread(options) {
|
|
25914
26466
|
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--listen", "stdio://"] });
|
|
25915
|
-
const child =
|
|
26467
|
+
const child = spawn12(launch.executable, launch.args, {
|
|
25916
26468
|
cwd: options.workdir,
|
|
25917
26469
|
env: launch.env,
|
|
25918
26470
|
shell: false,
|
|
@@ -25987,19 +26539,19 @@ async function forkCodexThread(options) {
|
|
|
25987
26539
|
|
|
25988
26540
|
// src/runs/run-recorder.ts
|
|
25989
26541
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
25990
|
-
import { homedir as
|
|
25991
|
-
import { join as
|
|
26542
|
+
import { homedir as homedir13 } from "node:os";
|
|
26543
|
+
import { join as join19 } from "node:path";
|
|
25992
26544
|
var RunRecorder = class _RunRecorder {
|
|
25993
26545
|
constructor(path) {
|
|
25994
26546
|
this.path = path;
|
|
25995
26547
|
}
|
|
25996
26548
|
path;
|
|
25997
|
-
home =
|
|
26549
|
+
home = homedir13();
|
|
25998
26550
|
static fromEnvironment(runId, meta3) {
|
|
25999
26551
|
const directory = process.env.TOC_OCRA_RECORD_DIR?.trim();
|
|
26000
26552
|
if (!directory) return void 0;
|
|
26001
26553
|
mkdirSync3(directory, { recursive: true });
|
|
26002
|
-
const recorder = new _RunRecorder(
|
|
26554
|
+
const recorder = new _RunRecorder(join19(directory, `${String(meta3.agent ?? "cli")}-${runId}.jsonl`));
|
|
26003
26555
|
recorder.write({ meta: meta3 });
|
|
26004
26556
|
return recorder;
|
|
26005
26557
|
}
|
|
@@ -26015,7 +26567,7 @@ var RunRecorder = class _RunRecorder {
|
|
|
26015
26567
|
|
|
26016
26568
|
// src/runs/run-transcript.ts
|
|
26017
26569
|
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
|
|
26570
|
+
import { join as join20 } from "node:path";
|
|
26019
26571
|
var MAX_TRANSCRIPT_ITEMS = 5e3;
|
|
26020
26572
|
var MAX_TRANSCRIPT_TEXT = 2e5;
|
|
26021
26573
|
var MAX_TRANSCRIPT_LINES = 2e4;
|
|
@@ -26280,7 +26832,7 @@ function transcriptFileName(runId) {
|
|
|
26280
26832
|
var TranscriptStore = class {
|
|
26281
26833
|
constructor(dataDir2, logger, env = process.env) {
|
|
26282
26834
|
this.logger = logger;
|
|
26283
|
-
this.directory = dataDir2 ?
|
|
26835
|
+
this.directory = dataDir2 ? join20(dataDir2, "transcripts") : "";
|
|
26284
26836
|
this.enabled = Boolean(dataDir2) && transcriptsOnDisk(env);
|
|
26285
26837
|
}
|
|
26286
26838
|
logger;
|
|
@@ -26335,7 +26887,7 @@ var TranscriptStore = class {
|
|
|
26335
26887
|
await this.writes.get(runId);
|
|
26336
26888
|
let text3;
|
|
26337
26889
|
try {
|
|
26338
|
-
text3 = await readFile9(
|
|
26890
|
+
text3 = await readFile9(join20(this.directory, name), "utf8");
|
|
26339
26891
|
} catch (error62) {
|
|
26340
26892
|
if (errorCode(error62) !== "ENOENT") this.logger.warn("run-transcript-read-failed", { runId, error: errorMessage(error62) });
|
|
26341
26893
|
return void 0;
|
|
@@ -26400,7 +26952,7 @@ var TranscriptStore = class {
|
|
|
26400
26952
|
transcript.dirty = false;
|
|
26401
26953
|
const body = JSON.stringify(transcript.toFile());
|
|
26402
26954
|
await this.ensureDirectory();
|
|
26403
|
-
const file2 =
|
|
26955
|
+
const file2 = join20(this.directory, name);
|
|
26404
26956
|
const temporary = `${file2}.${process.pid}.tmp`;
|
|
26405
26957
|
await writeFile6(temporary, body, { mode: 384 });
|
|
26406
26958
|
await rename6(temporary, file2);
|
|
@@ -26437,7 +26989,7 @@ var TranscriptStore = class {
|
|
|
26437
26989
|
const now = Date.now();
|
|
26438
26990
|
const files = [];
|
|
26439
26991
|
for (const name of names) {
|
|
26440
|
-
const path =
|
|
26992
|
+
const path = join20(this.directory, name);
|
|
26441
26993
|
if (name.endsWith(".tmp")) {
|
|
26442
26994
|
const info2 = await stat4(path).catch(() => void 0);
|
|
26443
26995
|
if (info2?.isFile() && now - info2.mtimeMs > STALE_TEMPORARY_MS) await unlink(path).catch(() => void 0);
|
|
@@ -26487,7 +27039,7 @@ function errorMessage(error62) {
|
|
|
26487
27039
|
import { createHash as createHash3, randomUUID as randomUUID2 } from "node:crypto";
|
|
26488
27040
|
import { constants as constants2 } from "node:fs";
|
|
26489
27041
|
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
|
|
27042
|
+
import { basename as basename2, isAbsolute as isAbsolute3, join as join21, relative } from "node:path";
|
|
26491
27043
|
function within(root2, path) {
|
|
26492
27044
|
const segment = relative(root2, path);
|
|
26493
27045
|
return segment === "" || !segment.startsWith("..") && !isAbsolute3(segment);
|
|
@@ -26495,7 +27047,7 @@ function within(root2, path) {
|
|
|
26495
27047
|
async function attachmentDirectory(workdir, messageId) {
|
|
26496
27048
|
let directory = workdir;
|
|
26497
27049
|
for (const segment of [".echo", "attachments", `message-${encodeURIComponent(messageId).slice(0, 180)}`]) {
|
|
26498
|
-
directory =
|
|
27050
|
+
directory = join21(directory, segment);
|
|
26499
27051
|
await mkdir7(directory, { mode: 448 }).catch((error62) => {
|
|
26500
27052
|
if (error62.code !== "EEXIST") throw error62;
|
|
26501
27053
|
});
|
|
@@ -26503,7 +27055,7 @@ async function attachmentDirectory(workdir, messageId) {
|
|
|
26503
27055
|
if (metadata.isSymbolicLink() || !metadata.isDirectory() || !within(workdir, await realpath(directory))) {
|
|
26504
27056
|
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
27057
|
}
|
|
26506
|
-
if (segment === ".echo") await writeFile7(
|
|
27058
|
+
if (segment === ".echo") await writeFile7(join21(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
|
|
26507
27059
|
if (error62.code !== "EEXIST") throw error62;
|
|
26508
27060
|
});
|
|
26509
27061
|
}
|
|
@@ -26540,9 +27092,9 @@ async function prepareTaskAttachments(payload, workdir, download, signal2) {
|
|
|
26540
27092
|
const characters = Array.from(basename2(file2.name.replace(/\\/g, "/")).replace(/[^\p{L}\p{N}._-]/gu, "_").replace(/\.+$/u, ""));
|
|
26541
27093
|
while (Buffer.byteLength(characters.join("")) > 160) characters.shift();
|
|
26542
27094
|
const name = characters.join("") || "attachment";
|
|
26543
|
-
const path =
|
|
27095
|
+
const path = join21(directory, `${file2.file_id}-${name}`);
|
|
26544
27096
|
if (!await matches(path, file2.size, file2.sha256, signal2)) {
|
|
26545
|
-
const temporary =
|
|
27097
|
+
const temporary = join21(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
|
|
26546
27098
|
try {
|
|
26547
27099
|
await download(payload.run_id, file2.file_id, temporary, file2.size, file2.sha256, signal2);
|
|
26548
27100
|
signal2.throwIfAborted();
|
|
@@ -26662,29 +27214,29 @@ import { extname } from "node:path";
|
|
|
26662
27214
|
import { pathToFileURL } from "node:url";
|
|
26663
27215
|
|
|
26664
27216
|
// src/acp/ask-user-question.ts
|
|
26665
|
-
var
|
|
27217
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26666
27218
|
var getLodyMeta = (meta3) => {
|
|
26667
|
-
if (!
|
|
26668
|
-
return
|
|
27219
|
+
if (!isRecord2(meta3)) return null;
|
|
27220
|
+
return isRecord2(meta3.lody) ? meta3.lody : null;
|
|
26669
27221
|
};
|
|
26670
27222
|
var getClaudeCodeMeta = (meta3) => {
|
|
26671
|
-
if (!
|
|
26672
|
-
return
|
|
27223
|
+
if (!isRecord2(meta3)) return null;
|
|
27224
|
+
return isRecord2(meta3.claudeCode) ? meta3.claudeCode : null;
|
|
26673
27225
|
};
|
|
26674
27226
|
var getCodexMeta = (meta3) => {
|
|
26675
|
-
if (!
|
|
26676
|
-
return
|
|
27227
|
+
if (!isRecord2(meta3)) return null;
|
|
27228
|
+
return isRecord2(meta3.codex) ? meta3.codex : null;
|
|
26677
27229
|
};
|
|
26678
27230
|
var getLodyElicitationMeta = (meta3) => {
|
|
26679
27231
|
const elicitation = getLodyMeta(meta3)?.elicitation;
|
|
26680
|
-
return
|
|
27232
|
+
return isRecord2(elicitation) && elicitation.version === 1 ? elicitation : null;
|
|
26681
27233
|
};
|
|
26682
27234
|
function isAskUserQuestionPermission(params) {
|
|
26683
27235
|
const meta3 = params._meta;
|
|
26684
27236
|
const lody = getLodyElicitationMeta(meta3);
|
|
26685
27237
|
if (lody && Array.isArray(lody.questions)) return true;
|
|
26686
|
-
if (
|
|
26687
|
-
return
|
|
27238
|
+
if (isRecord2(getClaudeCodeMeta(meta3)?.askUserQuestion)) return true;
|
|
27239
|
+
return isRecord2(getCodexMeta(meta3)?.requestUserInput);
|
|
26688
27240
|
}
|
|
26689
27241
|
function hasValidNoteKeys(questions) {
|
|
26690
27242
|
if (!questions.some((question) => question.note)) return true;
|
|
@@ -26708,18 +27260,18 @@ function getAskUserQuestionAnswerKey(questions, index) {
|
|
|
26708
27260
|
}
|
|
26709
27261
|
var getLodyOutcomeAnswers = (outcomeMeta) => {
|
|
26710
27262
|
const elicitation = getLodyMeta(outcomeMeta)?.elicitation;
|
|
26711
|
-
return
|
|
27263
|
+
return isRecord2(elicitation) && isRecord2(elicitation.answers) ? elicitation.answers : null;
|
|
26712
27264
|
};
|
|
26713
27265
|
var getCodexOutcomeAnswers = (outcomeMeta) => {
|
|
26714
27266
|
const requestUserInput = getCodexMeta(outcomeMeta)?.requestUserInput;
|
|
26715
|
-
return
|
|
27267
|
+
return isRecord2(requestUserInput) && isRecord2(requestUserInput.answers) ? requestUserInput.answers : null;
|
|
26716
27268
|
};
|
|
26717
27269
|
var getClaudeOutcomeAnswers = (outcomeMeta) => {
|
|
26718
27270
|
const askUserQuestion = getClaudeCodeMeta(outcomeMeta)?.askUserQuestion;
|
|
26719
|
-
return
|
|
27271
|
+
return isRecord2(askUserQuestion) && isRecord2(askUserQuestion.answers) ? askUserQuestion.answers : null;
|
|
26720
27272
|
};
|
|
26721
27273
|
function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
26722
|
-
if (!outcome || !
|
|
27274
|
+
if (!outcome || !isRecord2(outcome._meta) || !hasValidNoteKeys(meta3.questions)) return null;
|
|
26723
27275
|
const answerSources = [
|
|
26724
27276
|
{ source: "lody", answers: getLodyOutcomeAnswers(outcome._meta) },
|
|
26725
27277
|
{ source: "codex", answers: getCodexOutcomeAnswers(outcome._meta) },
|
|
@@ -26738,7 +27290,7 @@ function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
|
26738
27290
|
const raw = answerSource.answers[sourceKey];
|
|
26739
27291
|
if (raw === void 0) continue;
|
|
26740
27292
|
if (answerSource.source === "codex") {
|
|
26741
|
-
if (!
|
|
27293
|
+
if (!isRecord2(raw) || !Array.isArray(raw.answers)) continue;
|
|
26742
27294
|
const values = raw.answers.filter((value) => typeof value === "string");
|
|
26743
27295
|
if (values.length === 0) continue;
|
|
26744
27296
|
result[key] = question.multiSelect ? values : values[0] ?? "";
|
|
@@ -26752,20 +27304,20 @@ function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
|
26752
27304
|
}
|
|
26753
27305
|
return Object.keys(result).length > 0 ? result : null;
|
|
26754
27306
|
}
|
|
26755
|
-
var isEnumOption = (value) =>
|
|
27307
|
+
var isEnumOption = (value) => isRecord2(value) && typeof value.const === "string";
|
|
26756
27308
|
var getEnumOptionSource = (prop) => {
|
|
26757
27309
|
if (Array.isArray(prop.oneOf)) return prop.oneOf;
|
|
26758
27310
|
if (Array.isArray(prop.enum)) return prop.enum;
|
|
26759
27311
|
const items = prop.items;
|
|
26760
|
-
if (
|
|
27312
|
+
if (isRecord2(items)) {
|
|
26761
27313
|
if (Array.isArray(items.anyOf)) return items.anyOf;
|
|
26762
27314
|
if (Array.isArray(items.enum)) return items.enum;
|
|
26763
27315
|
}
|
|
26764
27316
|
return null;
|
|
26765
27317
|
};
|
|
26766
|
-
var isQuestionProperty = (prop) =>
|
|
26767
|
-
var isFreeTextProperty = (prop) =>
|
|
26768
|
-
var isMultiSelectProperty = (prop) => prop.type === "array" ||
|
|
27318
|
+
var isQuestionProperty = (prop) => isRecord2(prop) && getEnumOptionSource(prop) !== null;
|
|
27319
|
+
var isFreeTextProperty = (prop) => isRecord2(prop) && prop.type === "string" && !Array.isArray(prop.oneOf) && !Array.isArray(prop.enum);
|
|
27320
|
+
var isMultiSelectProperty = (prop) => prop.type === "array" || isRecord2(prop.items);
|
|
26769
27321
|
var parseElicitationOptions = (source) => {
|
|
26770
27322
|
const options = [];
|
|
26771
27323
|
for (const entry of source) {
|
|
@@ -26784,9 +27336,9 @@ var parseElicitationOptions = (source) => {
|
|
|
26784
27336
|
return options;
|
|
26785
27337
|
};
|
|
26786
27338
|
function parseAskUserQuestionElicitationRequest(request) {
|
|
26787
|
-
if (!
|
|
27339
|
+
if (!isRecord2(request) || request.mode !== "form") return null;
|
|
26788
27340
|
const schema = request.requestedSchema;
|
|
26789
|
-
if (!
|
|
27341
|
+
if (!isRecord2(schema) || !isRecord2(schema.properties)) return null;
|
|
26790
27342
|
const properties = schema.properties;
|
|
26791
27343
|
const entries = Object.entries(properties);
|
|
26792
27344
|
const requestMeta = getLodyElicitationMeta(request._meta);
|
|
@@ -26794,9 +27346,9 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26794
27346
|
const noteFieldKeyByQuestionId = /* @__PURE__ */ new Map();
|
|
26795
27347
|
const associatedFields = /* @__PURE__ */ new Set();
|
|
26796
27348
|
for (const [key, prop] of entries) {
|
|
26797
|
-
if (!
|
|
27349
|
+
if (!isRecord2(prop)) continue;
|
|
26798
27350
|
const rawMeta = getLodyMeta(prop._meta)?.elicitation;
|
|
26799
|
-
if (
|
|
27351
|
+
if (isRecord2(rawMeta) && rawMeta.noteFor !== void 0 && rawMeta.version !== 1) return null;
|
|
26800
27352
|
const meta3 = getLodyElicitationMeta(prop._meta);
|
|
26801
27353
|
if (!meta3 || meta3.noteFor === void 0 && meta3.customAnswerFor === void 0) continue;
|
|
26802
27354
|
if (meta3.noteFor !== void 0 && meta3.customAnswerFor !== void 0) return null;
|
|
@@ -26809,7 +27361,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26809
27361
|
}
|
|
26810
27362
|
const isLodyForm = requestMeta !== null || associatedFields.size > 0;
|
|
26811
27363
|
const questionEntries = entries.filter(([key, prop]) => {
|
|
26812
|
-
if (!
|
|
27364
|
+
if (!isRecord2(prop) || associatedFields.has(key)) return false;
|
|
26813
27365
|
return isQuestionProperty(prop) || isLodyForm && isFreeTextProperty(prop);
|
|
26814
27366
|
});
|
|
26815
27367
|
if (questionEntries.length === 0) return null;
|
|
@@ -26819,13 +27371,13 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26819
27371
|
}
|
|
26820
27372
|
if (associatedFields.size > 0 && questionEntries.some(([key]) => !key.trim())) return null;
|
|
26821
27373
|
const singleQuestion = questionEntries.length === 1;
|
|
26822
|
-
const allowCustomAnswer = isLodyForm ? questionEntries.some(([key, prop]) =>
|
|
27374
|
+
const allowCustomAnswer = isLodyForm ? questionEntries.some(([key, prop]) => isRecord2(prop) && (getEnumOptionSource(prop) === null || customFieldKeyByQuestionId.has(key))) : entries.some(([, prop]) => isFreeTextProperty(prop));
|
|
26823
27375
|
const message = typeof request.message === "string" ? request.message : "";
|
|
26824
27376
|
const questions = [];
|
|
26825
27377
|
const fieldKeys = [];
|
|
26826
27378
|
const customFieldKeys = [];
|
|
26827
27379
|
for (const [key, prop] of questionEntries) {
|
|
26828
|
-
if (!
|
|
27380
|
+
if (!isRecord2(prop)) continue;
|
|
26829
27381
|
const source = getEnumOptionSource(prop);
|
|
26830
27382
|
const header = typeof prop.title === "string" ? prop.title : "";
|
|
26831
27383
|
const description = typeof prop.description === "string" ? prop.description : "";
|
|
@@ -26840,7 +27392,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26840
27392
|
multiSelect: isMultiSelectProperty(prop),
|
|
26841
27393
|
...isLodyForm ? { allowCustomAnswer: source === null || customFieldKeyByQuestionId.has(key) } : {},
|
|
26842
27394
|
...isLodyForm && getLodyElicitationMeta(prop._meta)?.secret === true ? { isSecret: true } : {},
|
|
26843
|
-
...noteFieldId !== void 0 &&
|
|
27395
|
+
...noteFieldId !== void 0 && isRecord2(noteProp) ? {
|
|
26844
27396
|
note: {
|
|
26845
27397
|
fieldId: noteFieldId,
|
|
26846
27398
|
...typeof noteProp.title === "string" ? { title: noteProp.title } : {},
|
|
@@ -26863,7 +27415,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
26863
27415
|
}
|
|
26864
27416
|
function buildAskUserQuestionElicitationResponse(elicitation, outcome) {
|
|
26865
27417
|
if (!outcome || outcome.outcome !== "selected" || outcome.optionId === "cancel") return { action: "cancel" };
|
|
26866
|
-
const answers = extractAskUserQuestionAnswersFromOutcome(elicitation.meta, { _meta:
|
|
27418
|
+
const answers = extractAskUserQuestionAnswersFromOutcome(elicitation.meta, { _meta: isRecord2(outcome._meta) ? outcome._meta : null });
|
|
26867
27419
|
if (!answers) return { action: "accept", content: {} };
|
|
26868
27420
|
const content = /* @__PURE__ */ Object.create(null);
|
|
26869
27421
|
elicitation.meta.questions.forEach((question, index) => {
|
|
@@ -26890,8 +27442,8 @@ function redactSecretAnswers(elicitation, outcome) {
|
|
|
26890
27442
|
if (question.note?.isSecret) secret.add(question.note.fieldId);
|
|
26891
27443
|
});
|
|
26892
27444
|
const lody = getLodyMeta(outcome._meta);
|
|
26893
|
-
const elicitationMeta = lody &&
|
|
26894
|
-
if (!secret.size || !elicitationMeta || !
|
|
27445
|
+
const elicitationMeta = lody && isRecord2(lody.elicitation) ? lody.elicitation : null;
|
|
27446
|
+
if (!secret.size || !elicitationMeta || !isRecord2(elicitationMeta.answers)) return outcome;
|
|
26895
27447
|
const answers = Object.fromEntries(Object.entries(elicitationMeta.answers).map(([key, value]) => [key, secret.has(key) ? "[redacted]" : value]));
|
|
26896
27448
|
return { ...outcome, _meta: { ...outcome._meta, lody: { ...lody, elicitation: { ...elicitationMeta, answers } } } };
|
|
26897
27449
|
}
|
|
@@ -27317,8 +27869,10 @@ var AcpChatSession = class {
|
|
|
27317
27869
|
*/
|
|
27318
27870
|
forwardsPermission(params, prompts) {
|
|
27319
27871
|
if (isAskUserQuestionPermission(params)) return true;
|
|
27872
|
+
const call = record4(params.toolCall);
|
|
27873
|
+
if (typeof call.toolCallId === "string" && call.toolCallId.startsWith("interaction_")) return true;
|
|
27320
27874
|
if (prompts.permissions === "none") return false;
|
|
27321
|
-
const title =
|
|
27875
|
+
const title = call.title;
|
|
27322
27876
|
if (ECHO_CALLBACK.test(typeof title === "string" ? title : "")) return false;
|
|
27323
27877
|
if (prompts.permissions === "all") return true;
|
|
27324
27878
|
return !permissionAllowed(params, { permissionMode: "full", access: "acceptEdits" });
|
|
@@ -27960,7 +28514,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27960
28514
|
if (!fitsCommandLine(launch)) return refuse(cliFailure("promptTooLong", { label: cli.label }));
|
|
27961
28515
|
let child;
|
|
27962
28516
|
try {
|
|
27963
|
-
child =
|
|
28517
|
+
child = spawn13(launch.executable, launch.args, {
|
|
27964
28518
|
cwd: workdir,
|
|
27965
28519
|
env: Object.keys(memoryEnv).length ? { ...launch.env, ...memoryEnv } : launch.env,
|
|
27966
28520
|
detached: currentPlatform.runsInOwnProcessGroup,
|
|
@@ -28499,12 +29053,12 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
28499
29053
|
async prepareChatAttachments(payload) {
|
|
28500
29054
|
if (!payload.attachments?.length) return [];
|
|
28501
29055
|
if (!this.reporter.chatMedia) throw new Error("\u9644\u4EF6\u8F6C\u53D1\u672A\u914D\u7F6E");
|
|
28502
|
-
const directory =
|
|
29056
|
+
const directory = join22(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
|
|
28503
29057
|
await mkdir8(directory, { recursive: true, mode: 448 });
|
|
28504
29058
|
const files = [];
|
|
28505
29059
|
for (const attachment of payload.attachments) {
|
|
28506
29060
|
const name = basename3(attachment.name).replace(/[^\p{L}\p{N}._-]/gu, "_").slice(-120) || "attachment";
|
|
28507
|
-
const path =
|
|
29061
|
+
const path = join22(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
|
|
28508
29062
|
const existing = await stat6(path).catch(() => void 0);
|
|
28509
29063
|
if (!existing?.isFile()) {
|
|
28510
29064
|
const data = await this.reporter.chatMedia(payload.run_id, attachment.media_id);
|
|
@@ -28818,11 +29372,11 @@ var GatewayClient = class {
|
|
|
28818
29372
|
|
|
28819
29373
|
// src/workspace/directory-browser.ts
|
|
28820
29374
|
import { mkdir as mkdir9, readdir as readdir4, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28821
|
-
import { homedir as
|
|
29375
|
+
import { homedir as homedir14 } from "node:os";
|
|
28822
29376
|
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
28823
29377
|
var MAX_ENTRIES = 1e3;
|
|
28824
29378
|
async function listDirectory(requested, allowedRoots) {
|
|
28825
|
-
const raw = requested.trim().replace(/^~(?=$|[\\/])/,
|
|
29379
|
+
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir14()) || homedir14();
|
|
28826
29380
|
const directory = await realpath3(resolve6(raw)).catch(() => {
|
|
28827
29381
|
throw new Error(`\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${requested}`);
|
|
28828
29382
|
});
|
|
@@ -28840,8 +29394,8 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
28840
29394
|
else if (entry.isFile()) files.push(item);
|
|
28841
29395
|
}
|
|
28842
29396
|
const parent = dirname9(directory);
|
|
28843
|
-
const places = [{ label: "\u4E3B\u76EE\u5F55", path:
|
|
28844
|
-
for (const root2 of allowedRoots) if (root2 !==
|
|
29397
|
+
const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir14() }];
|
|
29398
|
+
for (const root2 of allowedRoots) if (root2 !== homedir14()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root2 });
|
|
28845
29399
|
places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
|
|
28846
29400
|
return {
|
|
28847
29401
|
path: directory,
|
|
@@ -28877,9 +29431,9 @@ async function createDirectory(parentRequested, name) {
|
|
|
28877
29431
|
}
|
|
28878
29432
|
|
|
28879
29433
|
// src/workspace/workspace-manager.ts
|
|
28880
|
-
import { spawn as
|
|
29434
|
+
import { spawn as spawn14 } from "node:child_process";
|
|
28881
29435
|
import { opendir, realpath as realpath4, stat as stat8 } from "node:fs/promises";
|
|
28882
|
-
import { homedir as
|
|
29436
|
+
import { homedir as homedir15 } from "node:os";
|
|
28883
29437
|
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
28884
29438
|
var MAX_NODES = 2e3;
|
|
28885
29439
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
@@ -28915,7 +29469,7 @@ var WorkspaceManager = class {
|
|
|
28915
29469
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
28916
29470
|
}
|
|
28917
29471
|
validateRootPath(value) {
|
|
28918
|
-
const raw = value.trim().replace(/^~(?=$|[\\/])/,
|
|
29472
|
+
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir15());
|
|
28919
29473
|
const root2 = resolve7(raw);
|
|
28920
29474
|
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28921
29475
|
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 +29595,7 @@ var WorkspaceManager = class {
|
|
|
29041
29595
|
}
|
|
29042
29596
|
runGit(args, cwd, timeoutSeconds, allowFailure = false) {
|
|
29043
29597
|
return new Promise((resolveCommand, rejectCommand) => {
|
|
29044
|
-
const child =
|
|
29598
|
+
const child = spawn14("git", args, {
|
|
29045
29599
|
cwd,
|
|
29046
29600
|
env: process.env,
|
|
29047
29601
|
shell: false,
|
|
@@ -29255,7 +29809,7 @@ var AgentRuntime = class {
|
|
|
29255
29809
|
}
|
|
29256
29810
|
};
|
|
29257
29811
|
this.workspaces = new WorkspaceManager(config2, this.logger);
|
|
29258
|
-
this.orphans = new OrphanRegistry(
|
|
29812
|
+
this.orphans = new OrphanRegistry(join24(config2.dataDir, "active-runs.json"));
|
|
29259
29813
|
this.runs = new RunSupervisor(config2, this.logger, reporter, this.orphans);
|
|
29260
29814
|
}
|
|
29261
29815
|
config;
|
|
@@ -29960,7 +30514,7 @@ function errorMessage3(error62) {
|
|
|
29960
30514
|
}
|
|
29961
30515
|
|
|
29962
30516
|
// src/runtime/run-service.ts
|
|
29963
|
-
import { existsSync as existsSync7, readFileSync as
|
|
30517
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
|
|
29964
30518
|
import { dirname as dirname10, resolve as resolve8 } from "node:path";
|
|
29965
30519
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
29966
30520
|
var PACKAGE_NAME = "toc-ocra";
|
|
@@ -29970,7 +30524,7 @@ function agentPackageRoot() {
|
|
|
29970
30524
|
const packagePath = resolve8(directory, "package.json");
|
|
29971
30525
|
if (existsSync7(packagePath)) {
|
|
29972
30526
|
try {
|
|
29973
|
-
const info = JSON.parse(
|
|
30527
|
+
const info = JSON.parse(readFileSync8(packagePath, "utf8"));
|
|
29974
30528
|
if (info.name === PACKAGE_NAME && typeof info.version === "string") return directory;
|
|
29975
30529
|
} catch {
|
|
29976
30530
|
}
|
|
@@ -29982,7 +30536,7 @@ function agentPackageRoot() {
|
|
|
29982
30536
|
}
|
|
29983
30537
|
function agentVersion() {
|
|
29984
30538
|
const root2 = agentPackageRoot();
|
|
29985
|
-
return root2 ? JSON.parse(
|
|
30539
|
+
return root2 ? JSON.parse(readFileSync8(resolve8(root2, "package.json"), "utf8")).version : "unknown";
|
|
29986
30540
|
}
|
|
29987
30541
|
async function runService(options = {}) {
|
|
29988
30542
|
const version2 = agentVersion();
|
|
@@ -30038,7 +30592,7 @@ function preferSystemNode() {
|
|
|
30038
30592
|
const names = process.platform === "win32" ? ["node.exe"] : ["node"];
|
|
30039
30593
|
for (const directory of (process.env.PATH ?? "").split(delimiter5)) {
|
|
30040
30594
|
for (const name of names) {
|
|
30041
|
-
const candidate = directory &&
|
|
30595
|
+
const candidate = directory && join25(directory, name);
|
|
30042
30596
|
if (candidate && existsSync8(candidate)) {
|
|
30043
30597
|
process.env.TOC_OCRA_NODE_PATH = candidate;
|
|
30044
30598
|
return;
|