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/cli/cli.mjs
CHANGED
|
@@ -185,9 +185,9 @@ var require_bit_buffer = __commonJS({
|
|
|
185
185
|
const bufIndex = Math.floor(index / 8);
|
|
186
186
|
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
|
|
187
187
|
},
|
|
188
|
-
put: function(
|
|
188
|
+
put: function(num2, length) {
|
|
189
189
|
for (let i = 0; i < length; i++) {
|
|
190
|
-
this.putBit((
|
|
190
|
+
this.putBit((num2 >>> length - i - 1 & 1) === 1);
|
|
191
191
|
}
|
|
192
192
|
},
|
|
193
193
|
getLengthInBits: function() {
|
|
@@ -920,14 +920,14 @@ var require_regex = __commonJS({
|
|
|
920
920
|
var TEST_KANJI = new RegExp("^" + kanji + "$");
|
|
921
921
|
var TEST_NUMERIC = new RegExp("^" + numeric + "$");
|
|
922
922
|
var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
|
|
923
|
-
exports.testKanji = function testKanji(
|
|
924
|
-
return TEST_KANJI.test(
|
|
923
|
+
exports.testKanji = function testKanji(str3) {
|
|
924
|
+
return TEST_KANJI.test(str3);
|
|
925
925
|
};
|
|
926
|
-
exports.testNumeric = function testNumeric(
|
|
927
|
-
return TEST_NUMERIC.test(
|
|
926
|
+
exports.testNumeric = function testNumeric(str3) {
|
|
927
|
+
return TEST_NUMERIC.test(str3);
|
|
928
928
|
};
|
|
929
|
-
exports.testAlphanumeric = function testAlphanumeric(
|
|
930
|
-
return TEST_ALPHANUMERIC.test(
|
|
929
|
+
exports.testAlphanumeric = function testAlphanumeric(str3) {
|
|
930
|
+
return TEST_ALPHANUMERIC.test(str3);
|
|
931
931
|
};
|
|
932
932
|
}
|
|
933
933
|
});
|
|
@@ -1421,13 +1421,13 @@ var require_segments = __commonJS({
|
|
|
1421
1421
|
var Regex = require_regex();
|
|
1422
1422
|
var Utils = require_utils();
|
|
1423
1423
|
var dijkstra = require_dijkstra();
|
|
1424
|
-
function getStringByteLength(
|
|
1425
|
-
return unescape(encodeURIComponent(
|
|
1424
|
+
function getStringByteLength(str3) {
|
|
1425
|
+
return unescape(encodeURIComponent(str3)).length;
|
|
1426
1426
|
}
|
|
1427
|
-
function getSegments(regex, mode,
|
|
1427
|
+
function getSegments(regex, mode, str3) {
|
|
1428
1428
|
const segments = [];
|
|
1429
1429
|
let result;
|
|
1430
|
-
while ((result = regex.exec(
|
|
1430
|
+
while ((result = regex.exec(str3)) !== null) {
|
|
1431
1431
|
segments.push({
|
|
1432
1432
|
data: result[0],
|
|
1433
1433
|
index: result.index,
|
|
@@ -4253,13 +4253,13 @@ var require_svg_tag = __commonJS({
|
|
|
4253
4253
|
var Utils = require_utils2();
|
|
4254
4254
|
function getColorAttrib(color, attrib) {
|
|
4255
4255
|
const alpha = color.a / 255;
|
|
4256
|
-
const
|
|
4257
|
-
return alpha < 1 ?
|
|
4256
|
+
const str3 = attrib + '="' + color.hex + '"';
|
|
4257
|
+
return alpha < 1 ? str3 + " " + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str3;
|
|
4258
4258
|
}
|
|
4259
4259
|
function svgCmd(cmd, x, y) {
|
|
4260
|
-
let
|
|
4261
|
-
if (typeof y !== "undefined")
|
|
4262
|
-
return
|
|
4260
|
+
let str3 = cmd + x;
|
|
4261
|
+
if (typeof y !== "undefined") str3 += " " + y;
|
|
4262
|
+
return str3;
|
|
4263
4263
|
}
|
|
4264
4264
|
function qrToPath(data, size, margin) {
|
|
4265
4265
|
let path = "";
|
|
@@ -4579,7 +4579,7 @@ import { createHash as createHash5 } from "node:crypto";
|
|
|
4579
4579
|
import { existsSync as existsSync8, mkdtempSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
4580
4580
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
4581
4581
|
import { createRequire } from "node:module";
|
|
4582
|
-
import { dirname as dirname11, join as
|
|
4582
|
+
import { dirname as dirname11, join as join26, resolve as resolve9 } from "node:path";
|
|
4583
4583
|
import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
4584
4584
|
|
|
4585
4585
|
// src/config.ts
|
|
@@ -5424,14 +5424,14 @@ function promiseAllObject(promisesObj) {
|
|
|
5424
5424
|
}
|
|
5425
5425
|
function randomString(length = 10) {
|
|
5426
5426
|
const chars = "abcdefghijklmnopqrstuvwxyz";
|
|
5427
|
-
let
|
|
5427
|
+
let str3 = "";
|
|
5428
5428
|
for (let i = 0; i < length; i++) {
|
|
5429
|
-
|
|
5429
|
+
str3 += chars[Math.floor(Math.random() * chars.length)];
|
|
5430
5430
|
}
|
|
5431
|
-
return
|
|
5431
|
+
return str3;
|
|
5432
5432
|
}
|
|
5433
|
-
function esc(
|
|
5434
|
-
return JSON.stringify(
|
|
5433
|
+
function esc(str3) {
|
|
5434
|
+
return JSON.stringify(str3);
|
|
5435
5435
|
}
|
|
5436
5436
|
function slugify(input2) {
|
|
5437
5437
|
return input2.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -5545,8 +5545,8 @@ var primitiveTypes = /* @__PURE__ */ new Set([
|
|
|
5545
5545
|
"symbol",
|
|
5546
5546
|
"undefined"
|
|
5547
5547
|
]);
|
|
5548
|
-
function escapeRegex(
|
|
5549
|
-
return
|
|
5548
|
+
function escapeRegex(str3) {
|
|
5549
|
+
return str3.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5550
5550
|
}
|
|
5551
5551
|
function clone(inst, def, params) {
|
|
5552
5552
|
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
@@ -5812,13 +5812,13 @@ function getSizableOrigin(input2) {
|
|
|
5812
5812
|
return "unknown";
|
|
5813
5813
|
}
|
|
5814
5814
|
var highSurrogate = /[\uD800-\uDBFF]/;
|
|
5815
|
-
function codePointLength(
|
|
5816
|
-
const units =
|
|
5817
|
-
if (!highSurrogate.test(
|
|
5815
|
+
function codePointLength(str3) {
|
|
5816
|
+
const units = str3.length;
|
|
5817
|
+
if (!highSurrogate.test(str3))
|
|
5818
5818
|
return units;
|
|
5819
5819
|
let count2 = units;
|
|
5820
5820
|
for (let i = 0; i < units - 1; i++) {
|
|
5821
|
-
if ((
|
|
5821
|
+
if ((str3.charCodeAt(i) & 64512) === 55296 && (str3.charCodeAt(i + 1) & 64512) === 56320) {
|
|
5822
5822
|
count2--;
|
|
5823
5823
|
i++;
|
|
5824
5824
|
}
|
|
@@ -24694,7 +24694,7 @@ Echo \u8D26\u53F7 ${who} \u786E\u8BA4\u5C06\u8FD9\u53F0\u7535\u8111\u6DFB\u52A0\
|
|
|
24694
24694
|
}
|
|
24695
24695
|
|
|
24696
24696
|
// src/providers/detection.ts
|
|
24697
|
-
import { spawn as
|
|
24697
|
+
import { spawn as spawn10 } from "node:child_process";
|
|
24698
24698
|
|
|
24699
24699
|
// src/runtime/cli/hydrate-shell-path.ts
|
|
24700
24700
|
import { delimiter as delimiter3 } from "node:path";
|
|
@@ -24805,6 +24805,60 @@ function parseCapturedProxy(stdout) {
|
|
|
24805
24805
|
const values = stdout.slice(start + PROXY_DELIMITER.length, end).split("\0");
|
|
24806
24806
|
return Object.fromEntries(PROXY_KEYS.flatMap((key, index) => values[index] ? [[key, values[index]]] : []));
|
|
24807
24807
|
}
|
|
24808
|
+
function parseMacSystemProxy(stdout) {
|
|
24809
|
+
const field = (name) => {
|
|
24810
|
+
const match = new RegExp(`^\\s*${name}\\s*:\\s*(.+?)\\s*$`, "m").exec(stdout);
|
|
24811
|
+
return match?.[1]?.trim() || void 0;
|
|
24812
|
+
};
|
|
24813
|
+
const out = {};
|
|
24814
|
+
const httpEnabled = field("HTTPEnable") === "1";
|
|
24815
|
+
const httpHost = field("HTTPProxy");
|
|
24816
|
+
const httpPort = field("HTTPPort");
|
|
24817
|
+
if (httpEnabled && httpHost && httpPort) {
|
|
24818
|
+
const url2 = `http://${httpHost}:${httpPort}`;
|
|
24819
|
+
out.http_proxy = url2;
|
|
24820
|
+
out.HTTP_PROXY = url2;
|
|
24821
|
+
}
|
|
24822
|
+
const httpsEnabled = field("HTTPSEnable") === "1";
|
|
24823
|
+
const httpsHost = field("HTTPSProxy");
|
|
24824
|
+
const httpsPort = field("HTTPSPort");
|
|
24825
|
+
if (httpsEnabled && httpsHost && httpsPort) {
|
|
24826
|
+
const url2 = `http://${httpsHost}:${httpsPort}`;
|
|
24827
|
+
out.https_proxy = url2;
|
|
24828
|
+
out.HTTPS_PROXY = url2;
|
|
24829
|
+
}
|
|
24830
|
+
const socksEnabled = field("SOCKSEnable") === "1";
|
|
24831
|
+
const socksHost = field("SOCKSProxy");
|
|
24832
|
+
const socksPort = field("SOCKSPort");
|
|
24833
|
+
if (socksEnabled && socksHost && socksPort) {
|
|
24834
|
+
const url2 = `socks5://${socksHost}:${socksPort}`;
|
|
24835
|
+
out.all_proxy = url2;
|
|
24836
|
+
out.ALL_PROXY = url2;
|
|
24837
|
+
if (!out.http_proxy && !out.https_proxy) {
|
|
24838
|
+
out.http_proxy = url2;
|
|
24839
|
+
out.HTTP_PROXY = url2;
|
|
24840
|
+
out.https_proxy = url2;
|
|
24841
|
+
out.HTTPS_PROXY = url2;
|
|
24842
|
+
}
|
|
24843
|
+
}
|
|
24844
|
+
if (Object.keys(out).length > 0) {
|
|
24845
|
+
const exceptionsBlock = /ExceptionsList\s*:\s*<array>\s*\{([\s\S]*?)\}/m.exec(stdout)?.[1] ?? "";
|
|
24846
|
+
const exceptions = [...exceptionsBlock.matchAll(/^\s*\d+\s*:\s*(.+?)\s*$/gm)].map((match) => match[1]?.trim()).filter((item) => Boolean(item));
|
|
24847
|
+
const defaults = ["localhost", "127.0.0.1", "::1", ".local"];
|
|
24848
|
+
const merged = [.../* @__PURE__ */ new Set([...defaults, ...exceptions])];
|
|
24849
|
+
out.no_proxy = merged.join(",");
|
|
24850
|
+
out.NO_PROXY = out.no_proxy;
|
|
24851
|
+
}
|
|
24852
|
+
return out;
|
|
24853
|
+
}
|
|
24854
|
+
function readMacSystemProxy() {
|
|
24855
|
+
return new Promise((resolve10) => {
|
|
24856
|
+
execFile("scutil", ["--proxy"], { timeout: 2e3 }, (error62, stdout) => {
|
|
24857
|
+
if (error62 || !stdout) return resolve10({});
|
|
24858
|
+
resolve10(parseMacSystemProxy(stdout));
|
|
24859
|
+
});
|
|
24860
|
+
});
|
|
24861
|
+
}
|
|
24808
24862
|
function readLoginShell(shell) {
|
|
24809
24863
|
return new Promise((resolve10) => {
|
|
24810
24864
|
const proxyValues = PROXY_KEYS.map((key) => `"\${${key}-}"`).join(" ");
|
|
@@ -24897,9 +24951,17 @@ function createPosixPlatform(id) {
|
|
|
24897
24951
|
});
|
|
24898
24952
|
},
|
|
24899
24953
|
scriptShell: (command) => ({ executable: "/bin/sh", args: ["-lc", command] }),
|
|
24900
|
-
readLoginEnvironment() {
|
|
24954
|
+
async readLoginEnvironment() {
|
|
24901
24955
|
const shell = process.env.SHELL || (id === "darwin" ? "/bin/zsh" : "/bin/bash");
|
|
24902
|
-
|
|
24956
|
+
const [shellResult, macProxy] = await Promise.all([
|
|
24957
|
+
readLoginShell(shell),
|
|
24958
|
+
id === "darwin" ? readMacSystemProxy() : Promise.resolve({})
|
|
24959
|
+
]);
|
|
24960
|
+
if (!shellResult.ok || Object.keys(macProxy).length === 0) return shellResult;
|
|
24961
|
+
return {
|
|
24962
|
+
...shellResult,
|
|
24963
|
+
proxyEnv: { ...macProxy, ...shellResult.proxyEnv }
|
|
24964
|
+
};
|
|
24903
24965
|
}
|
|
24904
24966
|
};
|
|
24905
24967
|
}
|
|
@@ -25103,6 +25165,16 @@ function directLaunch2(path, args, nodePath = process.execPath) {
|
|
|
25103
25165
|
|
|
25104
25166
|
// src/runtime/cli/hydrate-shell-path.ts
|
|
25105
25167
|
var cached2 = null;
|
|
25168
|
+
var cachedAt = 0;
|
|
25169
|
+
var cachedHasProxy = false;
|
|
25170
|
+
var EMPTY_PROXY_RETRY_MS = 3e4;
|
|
25171
|
+
function hasProxyKeys(env) {
|
|
25172
|
+
if (!env) return false;
|
|
25173
|
+
return PROXY_KEYS.slice(0, 3).some((key) => {
|
|
25174
|
+
const upper = key.toUpperCase();
|
|
25175
|
+
return Boolean(env[key]?.trim() || env[upper]?.trim());
|
|
25176
|
+
});
|
|
25177
|
+
}
|
|
25106
25178
|
function mergeShellProxyEnvironment(hydration, baseline = process.env) {
|
|
25107
25179
|
const environment = { ...baseline };
|
|
25108
25180
|
if (!hydration.ok) return environment;
|
|
@@ -25115,9 +25187,29 @@ function mergeShellProxyEnvironment(hydration, baseline = process.env) {
|
|
|
25115
25187
|
return environment;
|
|
25116
25188
|
}
|
|
25117
25189
|
function hydrateShellPath(options = {}) {
|
|
25118
|
-
|
|
25119
|
-
cached2
|
|
25120
|
-
|
|
25190
|
+
const staleEmptyProxy = !cachedHasProxy && cached2 !== null && Date.now() - cachedAt >= EMPTY_PROXY_RETRY_MS;
|
|
25191
|
+
if (cached2 && !options.force && !staleEmptyProxy) return cached2;
|
|
25192
|
+
cachedAt = Date.now();
|
|
25193
|
+
const next = (options.reader ?? (() => currentPlatform.readLoginEnvironment()))();
|
|
25194
|
+
cached2 = next;
|
|
25195
|
+
void next.then((result) => {
|
|
25196
|
+
if (cached2 === next) cachedHasProxy = result.ok && hasProxyKeys(result.proxyEnv);
|
|
25197
|
+
});
|
|
25198
|
+
return next;
|
|
25199
|
+
}
|
|
25200
|
+
async function hydrateRuntimeProxy(baseline = process.env) {
|
|
25201
|
+
if (hasProxyKeys(baseline)) return { ...baseline };
|
|
25202
|
+
const hydration = await hydrateShellPath({ force: !cachedHasProxy });
|
|
25203
|
+
const merged = mergeShellProxyEnvironment(hydration, baseline);
|
|
25204
|
+
if (hydration.ok && hasProxyKeys(hydration.proxyEnv)) {
|
|
25205
|
+
for (const key of PROXY_KEYS.slice(0, 4)) {
|
|
25206
|
+
const upper = key.toUpperCase();
|
|
25207
|
+
if (process.env[key] === void 0 && process.env[upper] === void 0 && merged[key]) {
|
|
25208
|
+
process.env[key] = merged[key];
|
|
25209
|
+
}
|
|
25210
|
+
}
|
|
25211
|
+
}
|
|
25212
|
+
return merged;
|
|
25121
25213
|
}
|
|
25122
25214
|
function mergePathSegments(segments) {
|
|
25123
25215
|
if (segments.length === 0) return [];
|
|
@@ -25144,6 +25236,7 @@ var SOURCES = [
|
|
|
25144
25236
|
{ 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" },
|
|
25145
25237
|
{ id: "grok", label: "Grok CLI", command: "grok", versionArguments: ["--version"] },
|
|
25146
25238
|
{ id: "gemini", label: "Gemini CLI", command: "gemini", versionArguments: ["--version"], restrictedPermission: true, installHint: "npm i -g @google/gemini-cli" },
|
|
25239
|
+
{ id: "antigravity", label: "Antigravity", aliases: ["agy"], command: "agy", versionArguments: ["--version"], restrictedPermission: true, installHint: "https://antigravity.google/cli" },
|
|
25147
25240
|
{ id: "opencode", label: "OpenCode", command: "opencode", versionArguments: ["--version"], installHint: "npm i -g opencode-ai" },
|
|
25148
25241
|
{ id: "kiro", label: "Kiro CLI", aliases: ["kiro-cli"], command: "kiro-cli", commandAliases: ["kiro"], versionArguments: ["--version"], promptStdin: "omit", restrictedPermission: true },
|
|
25149
25242
|
{ id: "omp", label: "OMP", command: "omp", versionArguments: ["--version"] },
|
|
@@ -25374,7 +25467,7 @@ function textRows(prefix, text3, maxRows = 40) {
|
|
|
25374
25467
|
|
|
25375
25468
|
// src/acp/acp-launch-specs.ts
|
|
25376
25469
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
25377
|
-
import { join as
|
|
25470
|
+
import { join as join14 } from "node:path";
|
|
25378
25471
|
|
|
25379
25472
|
// src/providers/claude-sessions.ts
|
|
25380
25473
|
import { existsSync as existsSync4, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -25536,8 +25629,8 @@ function codexCatalogArgs() {
|
|
|
25536
25629
|
// src/providers/model-catalog.ts
|
|
25537
25630
|
import { spawn as spawn5 } from "node:child_process";
|
|
25538
25631
|
import { readdir, readFile as readFile3 } from "node:fs/promises";
|
|
25539
|
-
import { homedir as
|
|
25540
|
-
import { isAbsolute as isAbsolute2, join as
|
|
25632
|
+
import { homedir as homedir8 } from "node:os";
|
|
25633
|
+
import { isAbsolute as isAbsolute2, join as join11, resolve as resolve3 } from "node:path";
|
|
25541
25634
|
|
|
25542
25635
|
// src/providers/kiro-auth.ts
|
|
25543
25636
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -25657,6 +25750,116 @@ async function readKiroNativeModels(launch, cwd, options = {}) {
|
|
|
25657
25750
|
}
|
|
25658
25751
|
}
|
|
25659
25752
|
|
|
25753
|
+
// src/acp/acp-dialects/antigravity-dialect.ts
|
|
25754
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
25755
|
+
import { homedir as homedir7 } from "node:os";
|
|
25756
|
+
import { join as join10 } from "node:path";
|
|
25757
|
+
|
|
25758
|
+
// src/acp/acp-dialects/acp-dialect.ts
|
|
25759
|
+
var record2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
25760
|
+
|
|
25761
|
+
// src/acp/acp-dialects/antigravity-dialect.ts
|
|
25762
|
+
var str2 = (value) => typeof value === "string" && value ? value : void 0;
|
|
25763
|
+
var num = (value) => typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
25764
|
+
var ANTIGRAVITY_EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"];
|
|
25765
|
+
var ANTIGRAVITY_LEVEL_SUFFIX = /^(.+)-(low|medium|high|xhigh|max)$/;
|
|
25766
|
+
var CLOUD_CODE_PREFIX = /^Cloud Code Assist API error \(\d{3}\):\s*/;
|
|
25767
|
+
var EXECUTOR_API_ERROR = /^(\u26a0 agent executor error: [^\n]*?Error (\d{3}), Message: ([^\n]*?)), Status: ([A-Z_]+)(?:, Details: ([^\n]*))?$/;
|
|
25768
|
+
var ANTIGRAVITY_FAILURE_RULES = [
|
|
25769
|
+
{
|
|
25770
|
+
kind: "notSignedIn",
|
|
25771
|
+
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
|
|
25772
|
+
},
|
|
25773
|
+
{
|
|
25774
|
+
kind: "rateLimited",
|
|
25775
|
+
pattern: /resource_exhausted|quota exceeded|rate limit|too many requests|429/i
|
|
25776
|
+
},
|
|
25777
|
+
{
|
|
25778
|
+
kind: "sessionMissing",
|
|
25779
|
+
pattern: /session not found|failed to rebuild agent:/i
|
|
25780
|
+
}
|
|
25781
|
+
];
|
|
25782
|
+
function antigravityUsesApiKeyProvider(homePath = homedir7()) {
|
|
25783
|
+
try {
|
|
25784
|
+
const raw = readFileSync4(join10(homePath, ".gemini", "antigravity-cli", "settings.json"), "utf8");
|
|
25785
|
+
const parsed = JSON.parse(raw);
|
|
25786
|
+
return Boolean(record2(parsed).modelProvider);
|
|
25787
|
+
} catch {
|
|
25788
|
+
return false;
|
|
25789
|
+
}
|
|
25790
|
+
}
|
|
25791
|
+
function scrubAntigravityEnv(env, homePath = homedir7()) {
|
|
25792
|
+
const next = { ...env };
|
|
25793
|
+
if (!antigravityUsesApiKeyProvider(homePath)) {
|
|
25794
|
+
for (const key of Object.keys(next)) {
|
|
25795
|
+
const normalized = process.platform === "win32" ? key.toUpperCase() : key;
|
|
25796
|
+
if (normalized === "GEMINI_API_KEY" || normalized === "GOOGLE_API_KEY") {
|
|
25797
|
+
delete next[key];
|
|
25798
|
+
}
|
|
25799
|
+
}
|
|
25800
|
+
}
|
|
25801
|
+
if (process.platform === "win32") {
|
|
25802
|
+
for (const key of Object.keys(next)) {
|
|
25803
|
+
if (key.toUpperCase() === "AGY_CLI_DISABLE_AUTO_UPDATE" && key !== "AGY_CLI_DISABLE_AUTO_UPDATE") {
|
|
25804
|
+
delete next[key];
|
|
25805
|
+
}
|
|
25806
|
+
}
|
|
25807
|
+
}
|
|
25808
|
+
next.AGY_CLI_DISABLE_AUTO_UPDATE = "true";
|
|
25809
|
+
return next;
|
|
25810
|
+
}
|
|
25811
|
+
function errorText(error62) {
|
|
25812
|
+
if (typeof error62.data === "string" && error62.data.trim()) return error62.data.trim();
|
|
25813
|
+
const nested = record2(error62.data);
|
|
25814
|
+
const nestedMsg = str2(nested.message) ?? str2(nested.details) ?? str2(nested.error);
|
|
25815
|
+
return nestedMsg ?? error62.message ?? "";
|
|
25816
|
+
}
|
|
25817
|
+
function promptErrorDetail(error62) {
|
|
25818
|
+
const text3 = errorText(error62);
|
|
25819
|
+
if (!text3) return void 0;
|
|
25820
|
+
const prefix = CLOUD_CODE_PREFIX.exec(text3);
|
|
25821
|
+
if (prefix) {
|
|
25822
|
+
try {
|
|
25823
|
+
const parsed = record2(JSON.parse(text3.slice(prefix[0].length)));
|
|
25824
|
+
const msg = str2(record2(parsed.error).message)?.trim();
|
|
25825
|
+
if (msg) return msg;
|
|
25826
|
+
} catch {
|
|
25827
|
+
}
|
|
25828
|
+
}
|
|
25829
|
+
const execMatch = EXECUTOR_API_ERROR.exec(text3);
|
|
25830
|
+
if (execMatch) {
|
|
25831
|
+
const [, , code2, rawMessage, status] = execMatch;
|
|
25832
|
+
const message = rawMessage?.trim();
|
|
25833
|
+
return message || `Google returned error ${code2} (${status}).`;
|
|
25834
|
+
}
|
|
25835
|
+
return void 0;
|
|
25836
|
+
}
|
|
25837
|
+
function normalizeToolUpdate(update2) {
|
|
25838
|
+
const input2 = record2(update2.rawInput);
|
|
25839
|
+
const output2 = record2(update2.rawOutput);
|
|
25840
|
+
const command = str2(input2.CommandLine) ?? str2(input2.command_line) ?? str2(input2.commandLine);
|
|
25841
|
+
const cwd = str2(input2.Cwd) ?? str2(input2.WorkingDirectory) ?? str2(input2.working_dir) ?? str2(input2.workingDir) ?? str2(input2.cwd);
|
|
25842
|
+
const stdout = str2(output2.combinedOutput) ?? str2(output2.combined_output);
|
|
25843
|
+
const exitCode = num(output2.exitCode) ?? num(output2.exit_code);
|
|
25844
|
+
return {
|
|
25845
|
+
...update2,
|
|
25846
|
+
...command === void 0 ? {} : { rawInput: { command, ...cwd === void 0 ? {} : { cwd } } },
|
|
25847
|
+
...stdout === void 0 && exitCode === void 0 ? {} : {
|
|
25848
|
+
rawOutput: {
|
|
25849
|
+
...stdout === void 0 ? {} : { stdout },
|
|
25850
|
+
...exitCode === void 0 ? {} : { exitCode }
|
|
25851
|
+
}
|
|
25852
|
+
}
|
|
25853
|
+
};
|
|
25854
|
+
}
|
|
25855
|
+
var ANTIGRAVITY_ACP_DIALECT = {
|
|
25856
|
+
failureRules: ANTIGRAVITY_FAILURE_RULES,
|
|
25857
|
+
failureKind: ({ code: code2 }) => code2 === 401 ? "notSignedIn" : code2 === 429 ? "rateLimited" : void 0,
|
|
25858
|
+
promptErrorDetail,
|
|
25859
|
+
normalizeToolUpdate,
|
|
25860
|
+
toolName: (update2) => update2.kind === "execute" ? "execute" : void 0
|
|
25861
|
+
};
|
|
25862
|
+
|
|
25660
25863
|
// src/providers/model-catalog.ts
|
|
25661
25864
|
function stringValue(value) {
|
|
25662
25865
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
@@ -25745,15 +25948,16 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
|
|
|
25745
25948
|
models: [...models2.values()]
|
|
25746
25949
|
};
|
|
25747
25950
|
}
|
|
25748
|
-
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
25749
|
-
var codexHome2 = () => process.env.CODEX_HOME?.trim() ||
|
|
25750
|
-
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() ||
|
|
25751
|
-
var
|
|
25752
|
-
var
|
|
25753
|
-
var
|
|
25951
|
+
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join11(homedir8(), ".claude");
|
|
25952
|
+
var codexHome2 = () => process.env.CODEX_HOME?.trim() || join11(homedir8(), ".codex");
|
|
25953
|
+
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() || join11(homedir8(), ".gemini");
|
|
25954
|
+
var antigravityHome = () => join11(homedir8(), ".gemini", "antigravity-cli");
|
|
25955
|
+
var grokHome = () => process.env.GROK_HOME?.trim() || join11(homedir8(), ".grok");
|
|
25956
|
+
var opencodeHome = () => join11(process.env.XDG_CONFIG_HOME?.trim() || join11(homedir8(), ".config"), "opencode");
|
|
25957
|
+
var kiroHome = () => join11(homedir8(), ".kiro");
|
|
25754
25958
|
async function readClaudeModelCatalog() {
|
|
25755
25959
|
const home = claudeHome();
|
|
25756
|
-
const content = await readFile3(
|
|
25960
|
+
const content = await readFile3(join11(home, "settings.json"), "utf8").catch(() => "");
|
|
25757
25961
|
let settings = {};
|
|
25758
25962
|
if (content) {
|
|
25759
25963
|
try {
|
|
@@ -25765,13 +25969,13 @@ async function readClaudeModelCatalog() {
|
|
|
25765
25969
|
return parseClaudeModelCatalog(settings, process.env, (/* @__PURE__ */ new Date()).toISOString(), await readClaudeCachedModels(home));
|
|
25766
25970
|
}
|
|
25767
25971
|
async function readClaudeCachedModels(home) {
|
|
25768
|
-
const dir =
|
|
25972
|
+
const dir = join11(home, "cache", "model-catalog");
|
|
25769
25973
|
const names = await readdir(dir).catch(() => []);
|
|
25770
25974
|
let newest;
|
|
25771
25975
|
for (const name of names) {
|
|
25772
25976
|
if (!name.endsWith(".json")) continue;
|
|
25773
25977
|
try {
|
|
25774
|
-
const cache = JSON.parse(await readFile3(
|
|
25978
|
+
const cache = JSON.parse(await readFile3(join11(dir, name), "utf8"));
|
|
25775
25979
|
const models2 = parseClaudeCachedModels(cache);
|
|
25776
25980
|
const fetchedAt = Number(objectValue(cache).fetchedAt) || 0;
|
|
25777
25981
|
if (models2.length && (!newest || fetchedAt > newest.fetchedAt)) newest = { fetchedAt, models: models2 };
|
|
@@ -25827,13 +26031,13 @@ async function readCodexModels(codexHome3, config2) {
|
|
|
25827
26031
|
const configuredModels = parseCodexModels(await readFile3(catalogPath, "utf8").catch(() => ""));
|
|
25828
26032
|
if (configuredModels?.length) return configuredModels;
|
|
25829
26033
|
}
|
|
25830
|
-
const cached3 = parseCodexModels(await readFile3(
|
|
26034
|
+
const cached3 = parseCodexModels(await readFile3(join11(codexHome3, "models_cache.json"), "utf8").catch(() => ""));
|
|
25831
26035
|
if (cached3?.length) return cached3;
|
|
25832
26036
|
return codexModelsFrom(await codexBundledCatalog().catch(() => void 0), { listedOnly: true }) ?? [];
|
|
25833
26037
|
}
|
|
25834
26038
|
async function readCodexModelCatalog() {
|
|
25835
26039
|
const home = codexHome2();
|
|
25836
|
-
const config2 = await readFile3(
|
|
26040
|
+
const config2 = await readFile3(join11(home, "config.toml"), "utf8").catch(() => "");
|
|
25837
26041
|
const models2 = await readCodexModels(home, config2);
|
|
25838
26042
|
const defaultModel = configValue(config2, "model");
|
|
25839
26043
|
const defaultReasoningEffort = configValue(config2, "model_reasoning_effort");
|
|
@@ -25881,7 +26085,7 @@ function cliExecutable(id) {
|
|
|
25881
26085
|
const spec = requireCliSpec(id);
|
|
25882
26086
|
return process.env[spec.overrideEnv]?.trim() || resolveCliCommand(cliCommand(spec));
|
|
25883
26087
|
}
|
|
25884
|
-
function runModelListCommand(executable, args, label, environment) {
|
|
26088
|
+
function runModelListCommand(executable, args, label, environment, timeoutMs = MODEL_LIST_TIMEOUT_MS) {
|
|
25885
26089
|
return new Promise((resolve10, reject) => {
|
|
25886
26090
|
const launch = directLaunch2(executable, args);
|
|
25887
26091
|
const child = spawn5(launch.executable, launch.args, { shell: false, windowsHide: true, ...environment ? { env: environment } : {}, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -25890,7 +26094,7 @@ function runModelListCommand(executable, args, label, environment) {
|
|
|
25890
26094
|
const timer = setTimeout(() => {
|
|
25891
26095
|
child.kill("SIGKILL");
|
|
25892
26096
|
reject(new Error(`${label} \u8BFB\u53D6\u6A21\u578B\u5217\u8868\u8D85\u65F6`));
|
|
25893
|
-
},
|
|
26097
|
+
}, timeoutMs);
|
|
25894
26098
|
child.stdout.setEncoding("utf8");
|
|
25895
26099
|
child.stderr.setEncoding("utf8");
|
|
25896
26100
|
child.stdout.on("data", (chunk) => {
|
|
@@ -25924,7 +26128,7 @@ function withKnownEfforts(base, known) {
|
|
|
25924
26128
|
};
|
|
25925
26129
|
}
|
|
25926
26130
|
async function readKiroModelCatalog(options = {}) {
|
|
25927
|
-
const environment =
|
|
26131
|
+
const environment = await hydrateRuntimeProxy(providerEnvironment());
|
|
25928
26132
|
const kiro = requireCliSpec("kiro");
|
|
25929
26133
|
await requireKiroAuthentication(environment, { force: options.force === true });
|
|
25930
26134
|
const listLaunch = launchCli({ spec: kiro, args: ["chat", "--list-models", "--format", "json"], env: environment });
|
|
@@ -25947,7 +26151,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
25947
26151
|
if (current) return known.catalog;
|
|
25948
26152
|
try {
|
|
25949
26153
|
const launch = launchCli({ spec: kiro, args: ["acp", "--trust-tools="], env: environment });
|
|
25950
|
-
const catalog = await readKiroNativeModels(launch,
|
|
26154
|
+
const catalog = await readKiroNativeModels(launch, homedir8(), { catalog: base });
|
|
25951
26155
|
kiroEfforts = { signature, readAt: Date.now(), catalog };
|
|
25952
26156
|
return catalog;
|
|
25953
26157
|
} catch {
|
|
@@ -25956,7 +26160,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
25956
26160
|
};
|
|
25957
26161
|
const [payload, content] = await Promise.all([
|
|
25958
26162
|
readEfforts(),
|
|
25959
|
-
readFile3(
|
|
26163
|
+
readFile3(join11(kiroHome(), "settings", "cli.json"), "utf8").catch(() => "{}")
|
|
25960
26164
|
]);
|
|
25961
26165
|
let settings;
|
|
25962
26166
|
try {
|
|
@@ -26013,7 +26217,7 @@ function geminiModelsUrl(baseUrl) {
|
|
|
26013
26217
|
}
|
|
26014
26218
|
async function readGeminiModelCatalog() {
|
|
26015
26219
|
const fileEnvironment = parseEnvFile(
|
|
26016
|
-
await readFile3(
|
|
26220
|
+
await readFile3(join11(geminiHome(), ".env"), "utf8").catch(() => "")
|
|
26017
26221
|
);
|
|
26018
26222
|
const environment = { ...fileEnvironment, ...process.env };
|
|
26019
26223
|
const baseUrl = environment.GOOGLE_GEMINI_BASE_URL?.trim();
|
|
@@ -26058,7 +26262,7 @@ function parseGrokModelCatalog(output2, config2 = "", fetchedAt = (/* @__PURE__
|
|
|
26058
26262
|
return catalog;
|
|
26059
26263
|
}
|
|
26060
26264
|
async function readGrokModelCatalog() {
|
|
26061
|
-
const config2 = await readFile3(
|
|
26265
|
+
const config2 = await readFile3(join11(grokHome(), "config.toml"), "utf8").catch(() => "");
|
|
26062
26266
|
const output2 = await runModelListCommand(cliExecutable("grok"), ["models"], "grok");
|
|
26063
26267
|
const catalog = parseGrokModelCatalog(output2, config2);
|
|
26064
26268
|
if (catalog.models.length === 0) throw new Error("Grok \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -26077,30 +26281,139 @@ function parseOpencodeModelCatalog(output2, config2 = "", fetchedAt = (/* @__PUR
|
|
|
26077
26281
|
return catalog;
|
|
26078
26282
|
}
|
|
26079
26283
|
async function readOpencodeModelCatalog() {
|
|
26080
|
-
const config2 = await readFile3(
|
|
26284
|
+
const config2 = await readFile3(join11(opencodeHome(), "opencode.json"), "utf8").catch(() => "") || await readFile3(join11(opencodeHome(), "opencode.jsonc"), "utf8").catch(() => "");
|
|
26081
26285
|
const output2 = await runModelListCommand(cliExecutable("opencode"), ["models"], "opencode");
|
|
26082
26286
|
const catalog = parseOpencodeModelCatalog(output2, config2);
|
|
26083
26287
|
if (catalog.models.length === 0) throw new Error("OpenCode \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
26084
26288
|
return catalog;
|
|
26085
26289
|
}
|
|
26290
|
+
function parseAntigravityModelCatalog(output2, settingsContent = "", fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
26291
|
+
const plain = output2.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "");
|
|
26292
|
+
const variants = [];
|
|
26293
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
26294
|
+
for (const line of plain.split(/\r?\n/)) {
|
|
26295
|
+
const parts = line.split(" ").map((field) => field.trim());
|
|
26296
|
+
const [modelId, name, ...extra] = parts;
|
|
26297
|
+
if (!modelId || !name || extra.length > 0 || seenIds.has(modelId)) continue;
|
|
26298
|
+
seenIds.add(modelId);
|
|
26299
|
+
variants.push({ modelId, name });
|
|
26300
|
+
}
|
|
26301
|
+
const familyLevels = /* @__PURE__ */ new Map();
|
|
26302
|
+
for (const variant of variants) {
|
|
26303
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(variant.modelId);
|
|
26304
|
+
const family = match?.[1];
|
|
26305
|
+
const level = match?.[2];
|
|
26306
|
+
if (!family || !level || seenIds.has(family)) continue;
|
|
26307
|
+
const list = familyLevels.get(family) ?? [];
|
|
26308
|
+
if (!list.includes(level)) list.push(level);
|
|
26309
|
+
familyLevels.set(family, list);
|
|
26310
|
+
}
|
|
26311
|
+
const models2 = [];
|
|
26312
|
+
const addedFamilies = /* @__PURE__ */ new Set();
|
|
26313
|
+
for (const variant of variants) {
|
|
26314
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(variant.modelId);
|
|
26315
|
+
const family = match?.[1];
|
|
26316
|
+
const levels = family ? familyLevels.get(family) : void 0;
|
|
26317
|
+
if (family && levels && levels.length > 1) {
|
|
26318
|
+
if (addedFamilies.has(family)) continue;
|
|
26319
|
+
addedFamilies.add(family);
|
|
26320
|
+
const ordered = ANTIGRAVITY_EFFORT_LEVELS.filter((level) => levels.includes(level));
|
|
26321
|
+
const firstLevel = levels[0];
|
|
26322
|
+
models2.push({
|
|
26323
|
+
id: family,
|
|
26324
|
+
name: variant.name.replace(/\s*\([^()]+\)$/, ""),
|
|
26325
|
+
supported_reasoning_efforts: [...ordered],
|
|
26326
|
+
...firstLevel && ordered.includes(firstLevel) ? { default_reasoning_effort: firstLevel } : {}
|
|
26327
|
+
});
|
|
26328
|
+
} else {
|
|
26329
|
+
models2.push({
|
|
26330
|
+
id: variant.modelId,
|
|
26331
|
+
name: variant.name,
|
|
26332
|
+
supported_reasoning_efforts: []
|
|
26333
|
+
});
|
|
26334
|
+
}
|
|
26335
|
+
}
|
|
26336
|
+
let configuredModel;
|
|
26337
|
+
if (settingsContent.trim()) {
|
|
26338
|
+
try {
|
|
26339
|
+
configuredModel = stringValue(objectValue(JSON.parse(settingsContent)).model);
|
|
26340
|
+
} catch {
|
|
26341
|
+
}
|
|
26342
|
+
}
|
|
26343
|
+
let defaultModel;
|
|
26344
|
+
let defaultEffort;
|
|
26345
|
+
if (configuredModel) {
|
|
26346
|
+
const matchedVariant = variants.find(
|
|
26347
|
+
(variant) => variant.modelId === configuredModel || variant.name.toLowerCase() === configuredModel.toLowerCase()
|
|
26348
|
+
);
|
|
26349
|
+
if (matchedVariant) {
|
|
26350
|
+
const match = ANTIGRAVITY_LEVEL_SUFFIX.exec(matchedVariant.modelId);
|
|
26351
|
+
const family = match?.[1];
|
|
26352
|
+
const level = match?.[2];
|
|
26353
|
+
if (family && addedFamilies.has(family)) {
|
|
26354
|
+
defaultModel = family;
|
|
26355
|
+
defaultEffort = level;
|
|
26356
|
+
} else {
|
|
26357
|
+
defaultModel = matchedVariant.modelId;
|
|
26358
|
+
}
|
|
26359
|
+
} else {
|
|
26360
|
+
const matchedFamily = models2.find(
|
|
26361
|
+
(model) => model.id === configuredModel || model.name.toLowerCase() === configuredModel.toLowerCase()
|
|
26362
|
+
);
|
|
26363
|
+
if (matchedFamily) {
|
|
26364
|
+
defaultModel = matchedFamily.id;
|
|
26365
|
+
defaultEffort = matchedFamily.default_reasoning_effort;
|
|
26366
|
+
}
|
|
26367
|
+
}
|
|
26368
|
+
}
|
|
26369
|
+
if (!defaultModel && models2.length > 0) {
|
|
26370
|
+
defaultModel = models2[0].id;
|
|
26371
|
+
defaultEffort = models2[0].default_reasoning_effort;
|
|
26372
|
+
}
|
|
26373
|
+
return {
|
|
26374
|
+
agent_type: "antigravity",
|
|
26375
|
+
fetched_at: fetchedAt,
|
|
26376
|
+
...defaultModel ? { default_model: defaultModel } : {},
|
|
26377
|
+
...defaultEffort ? { default_reasoning_effort: defaultEffort } : {},
|
|
26378
|
+
models: models2
|
|
26379
|
+
};
|
|
26380
|
+
}
|
|
26381
|
+
async function readAntigravityModelCatalog() {
|
|
26382
|
+
const baseEnv = await hydrateRuntimeProxy(providerEnvironment());
|
|
26383
|
+
const env = scrubAntigravityEnv(baseEnv);
|
|
26384
|
+
const spec = requireCliSpec("antigravity");
|
|
26385
|
+
const launch = launchCli({ spec, args: ["models"], env });
|
|
26386
|
+
const [output2, settings] = await Promise.all([
|
|
26387
|
+
runModelListCommand(launch.executable, launch.args, "agy", launch.env ?? env, 3e4),
|
|
26388
|
+
readFile3(join11(antigravityHome(), "settings.json"), "utf8").catch(() => "")
|
|
26389
|
+
]);
|
|
26390
|
+
const catalog = parseAntigravityModelCatalog(output2, settings);
|
|
26391
|
+
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");
|
|
26392
|
+
return catalog;
|
|
26393
|
+
}
|
|
26086
26394
|
var TEN_MINUTES = 10 * 60 * 1e3;
|
|
26087
26395
|
var MODEL_SOURCES = {
|
|
26088
|
-
|
|
26396
|
+
antigravity: {
|
|
26397
|
+
read: readAntigravityModelCatalog,
|
|
26398
|
+
watchFiles: () => [join11(antigravityHome(), "settings.json")],
|
|
26399
|
+
refreshEveryMs: TEN_MINUTES
|
|
26400
|
+
},
|
|
26401
|
+
claude: { read: readClaudeModelCatalog, watchFiles: () => [join11(claudeHome(), "settings.json"), join11(claudeHome(), "cache", "model-catalog")] },
|
|
26089
26402
|
codex: {
|
|
26090
26403
|
read: readCodexModelCatalog,
|
|
26091
26404
|
watchFiles: () => {
|
|
26092
26405
|
const home = codexHome2();
|
|
26093
|
-
return [
|
|
26406
|
+
return [join11(home, "config.toml"), join11(home, "models_cache.json")];
|
|
26094
26407
|
},
|
|
26095
26408
|
// model_catalog_json may point anywhere; a periodic re-read covers it.
|
|
26096
26409
|
refreshEveryMs: TEN_MINUTES
|
|
26097
26410
|
},
|
|
26098
|
-
gemini: { read: readGeminiModelCatalog, watchFiles: () => [
|
|
26099
|
-
grok: { read: readGrokModelCatalog, watchFiles: () => [
|
|
26100
|
-
kiro: { read: readKiroModelCatalog, watchFiles: () => [
|
|
26411
|
+
gemini: { read: readGeminiModelCatalog, watchFiles: () => [join11(geminiHome(), ".env")], refreshEveryMs: TEN_MINUTES },
|
|
26412
|
+
grok: { read: readGrokModelCatalog, watchFiles: () => [join11(grokHome(), "config.toml")], refreshEveryMs: TEN_MINUTES },
|
|
26413
|
+
kiro: { read: readKiroModelCatalog, watchFiles: () => [join11(kiroHome(), "settings", "cli.json")] },
|
|
26101
26414
|
opencode: {
|
|
26102
26415
|
read: readOpencodeModelCatalog,
|
|
26103
|
-
watchFiles: () => [
|
|
26416
|
+
watchFiles: () => [join11(opencodeHome(), "opencode.json"), join11(opencodeHome(), "opencode.jsonc")],
|
|
26104
26417
|
refreshEveryMs: TEN_MINUTES
|
|
26105
26418
|
}
|
|
26106
26419
|
};
|
|
@@ -26116,9 +26429,6 @@ var GEMINI_ACP_DIALECT = {
|
|
|
26116
26429
|
linksFileMentions: true
|
|
26117
26430
|
};
|
|
26118
26431
|
|
|
26119
|
-
// src/acp/acp-dialects/acp-dialect.ts
|
|
26120
|
-
var record2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
26121
|
-
|
|
26122
26432
|
// src/acp/acp-dialects/grok-dialect.ts
|
|
26123
26433
|
function modelEfforts(model) {
|
|
26124
26434
|
const meta3 = record2(model._meta);
|
|
@@ -26218,11 +26528,11 @@ function classifySpawnError(error62, context) {
|
|
|
26218
26528
|
|
|
26219
26529
|
// src/providers/cli/kiro-session-log.ts
|
|
26220
26530
|
import { open as open2, readdir as readdir2, readFile as readFile4, stat as stat2 } from "node:fs/promises";
|
|
26221
|
-
import { homedir as
|
|
26222
|
-
import { join as
|
|
26531
|
+
import { homedir as homedir9 } from "node:os";
|
|
26532
|
+
import { join as join12 } from "node:path";
|
|
26223
26533
|
var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "execute_bash", "bash"]);
|
|
26224
26534
|
function kiroSessionsDirectory() {
|
|
26225
|
-
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR ||
|
|
26535
|
+
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR || join12(homedir9(), ".kiro", "sessions", "cli");
|
|
26226
26536
|
}
|
|
26227
26537
|
var KiroSessionLog = class {
|
|
26228
26538
|
constructor(options) {
|
|
@@ -26241,7 +26551,7 @@ var KiroSessionLog = class {
|
|
|
26241
26551
|
/** Called before the CLI starts: a resumed log is followed from its current end. */
|
|
26242
26552
|
async begin() {
|
|
26243
26553
|
if (!this.options.sessionId) return;
|
|
26244
|
-
this.path =
|
|
26554
|
+
this.path = join12(this.directory, `${this.options.sessionId}.jsonl`);
|
|
26245
26555
|
this.offset = await stat2(this.path).then((info) => info.size, () => 0);
|
|
26246
26556
|
}
|
|
26247
26557
|
/**
|
|
@@ -26254,11 +26564,11 @@ var KiroSessionLog = class {
|
|
|
26254
26564
|
const found = [];
|
|
26255
26565
|
for (const name of names) {
|
|
26256
26566
|
if (!name.endsWith(".json")) continue;
|
|
26257
|
-
const meta3 = await readFile4(
|
|
26567
|
+
const meta3 = await readFile4(join12(this.directory, name), "utf8").then((text3) => JSON.parse(text3), () => void 0);
|
|
26258
26568
|
const created = meta3?.created_at ? Date.parse(meta3.created_at) : NaN;
|
|
26259
26569
|
if (meta3?.cwd && sameFolder(meta3.cwd, this.options.workdir) && created >= this.options.startedAt - 2e3) found.push(name.slice(0, -5));
|
|
26260
26570
|
}
|
|
26261
|
-
if (found.length === 1) this.path =
|
|
26571
|
+
if (found.length === 1) this.path = join12(this.directory, `${found[0]}.jsonl`);
|
|
26262
26572
|
}
|
|
26263
26573
|
/** Reads entries appended since the last call. */
|
|
26264
26574
|
async refresh() {
|
|
@@ -26569,7 +26879,7 @@ var KIRO_ACP_DIALECT = {
|
|
|
26569
26879
|
};
|
|
26570
26880
|
|
|
26571
26881
|
// src/acp/acp-dialects/omp-dialect.ts
|
|
26572
|
-
function
|
|
26882
|
+
function normalizeToolUpdate2(update2) {
|
|
26573
26883
|
const rawOutput = record2(update2.rawOutput);
|
|
26574
26884
|
if (!Array.isArray(rawOutput.content)) return update2;
|
|
26575
26885
|
if (["exitCode", "exit_code", "stdout", "stderr"].some((key) => rawOutput[key] !== void 0)) return update2;
|
|
@@ -26585,7 +26895,7 @@ function normalizeToolUpdate(update2) {
|
|
|
26585
26895
|
};
|
|
26586
26896
|
}
|
|
26587
26897
|
var OMP_ACP_DIALECT = {
|
|
26588
|
-
normalizeToolUpdate,
|
|
26898
|
+
normalizeToolUpdate: normalizeToolUpdate2,
|
|
26589
26899
|
promptErrorDetail: (error62) => {
|
|
26590
26900
|
const details = record2(error62.data).details;
|
|
26591
26901
|
return typeof details === "string" && details ? details : void 0;
|
|
@@ -26597,7 +26907,7 @@ var OMP_ACP_DIALECT = {
|
|
|
26597
26907
|
};
|
|
26598
26908
|
|
|
26599
26909
|
// src/acp/acp-dialects/opencode-dialect.ts
|
|
26600
|
-
function
|
|
26910
|
+
function normalizeToolUpdate3(update2) {
|
|
26601
26911
|
const raw = update2.rawOutput;
|
|
26602
26912
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return update2;
|
|
26603
26913
|
const rawOutput = raw;
|
|
@@ -26617,7 +26927,7 @@ function normalizeToolUpdate2(update2) {
|
|
|
26617
26927
|
};
|
|
26618
26928
|
}
|
|
26619
26929
|
var OPENCODE_ACP_DIALECT = {
|
|
26620
|
-
normalizeToolUpdate:
|
|
26930
|
+
normalizeToolUpdate: normalizeToolUpdate3,
|
|
26621
26931
|
failureRules: [
|
|
26622
26932
|
{ kind: "usageLimit", pattern: /"errorName"\s*:\s*"provider\.quota"/ },
|
|
26623
26933
|
{ kind: "rateLimited", pattern: /"errorName"\s*:\s*"provider\.rate-limit"/ }
|
|
@@ -26627,9 +26937,9 @@ var OPENCODE_ACP_DIALECT = {
|
|
|
26627
26937
|
// src/acp/vendor.ts
|
|
26628
26938
|
import { spawn as spawn6 } from "node:child_process";
|
|
26629
26939
|
import { createHash } from "node:crypto";
|
|
26630
|
-
import { existsSync as existsSync5, readFileSync as
|
|
26940
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5 } from "node:fs";
|
|
26631
26941
|
import { copyFile, mkdir as mkdir4, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
26632
|
-
import { dirname as dirname6, join as
|
|
26942
|
+
import { dirname as dirname6, join as join13, resolve as resolve4 } from "node:path";
|
|
26633
26943
|
import { fileURLToPath } from "node:url";
|
|
26634
26944
|
var AcpRuntimeUnavailable = class extends Error {
|
|
26635
26945
|
constructor(message) {
|
|
@@ -26644,7 +26954,7 @@ function packageRoot() {
|
|
|
26644
26954
|
const path = resolve4(directory, "package.json");
|
|
26645
26955
|
if (existsSync5(path)) {
|
|
26646
26956
|
try {
|
|
26647
|
-
if (JSON.parse(
|
|
26957
|
+
if (JSON.parse(readFileSync5(path, "utf8")).name === "toc-ocra") return directory;
|
|
26648
26958
|
} catch {
|
|
26649
26959
|
}
|
|
26650
26960
|
}
|
|
@@ -26662,29 +26972,29 @@ function agentPackageVersion() {
|
|
|
26662
26972
|
const directory = agentRoot();
|
|
26663
26973
|
if (!directory) return "0";
|
|
26664
26974
|
try {
|
|
26665
|
-
return JSON.parse(
|
|
26975
|
+
return JSON.parse(readFileSync5(join13(directory, "package.json"), "utf8")).version ?? "0";
|
|
26666
26976
|
} catch {
|
|
26667
26977
|
return "0";
|
|
26668
26978
|
}
|
|
26669
26979
|
}
|
|
26670
26980
|
function vendoredAdapter(name) {
|
|
26671
26981
|
const directory = agentRoot();
|
|
26672
|
-
const entry = directory ?
|
|
26982
|
+
const entry = directory ? join13(directory, "assets", "acp", name, "index.mjs") : void 0;
|
|
26673
26983
|
return entry && existsSync5(entry) ? entry : void 0;
|
|
26674
26984
|
}
|
|
26675
26985
|
var installs = /* @__PURE__ */ new Map();
|
|
26676
26986
|
function ensureClaudeRuntime(dataDir2) {
|
|
26677
26987
|
const entry = vendoredAdapter("claude");
|
|
26678
26988
|
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"));
|
|
26679
|
-
const manifestPath =
|
|
26989
|
+
const manifestPath = join13(dirname6(entry), "runtime.json");
|
|
26680
26990
|
let manifest;
|
|
26681
26991
|
try {
|
|
26682
|
-
manifest = JSON.parse(
|
|
26992
|
+
manifest = JSON.parse(readFileSync5(manifestPath, "utf8"));
|
|
26683
26993
|
} catch {
|
|
26684
26994
|
return Promise.reject(new AcpRuntimeUnavailable("Claude ACP \u9002\u914D\u5668\u7F3A\u5C11 runtime.json"));
|
|
26685
26995
|
}
|
|
26686
|
-
const hash2 = createHash("sha256").update(
|
|
26687
|
-
const directory =
|
|
26996
|
+
const hash2 = createHash("sha256").update(readFileSync5(entry)).digest("hex").slice(0, 12);
|
|
26997
|
+
const directory = join13(dataDir2, "acp-runtimes", `claude-${manifest.adapterVersion}-sdk-${manifest.sdk.version}-${hash2}`);
|
|
26688
26998
|
const existing = installs.get(directory);
|
|
26689
26999
|
if (existing) return existing;
|
|
26690
27000
|
const install = installClaudeRuntime(directory, entry, manifest).catch((error62) => {
|
|
@@ -26695,19 +27005,19 @@ function ensureClaudeRuntime(dataDir2) {
|
|
|
26695
27005
|
return install;
|
|
26696
27006
|
}
|
|
26697
27007
|
async function installClaudeRuntime(directory, entry, manifest) {
|
|
26698
|
-
const sdkPackage =
|
|
26699
|
-
if (existsSync5(sdkPackage) && existsSync5(
|
|
27008
|
+
const sdkPackage = join13(directory, "node_modules", ...manifest.sdk.name.split("/"), "package.json");
|
|
27009
|
+
if (existsSync5(sdkPackage) && existsSync5(join13(directory, "index.mjs"))) return directory;
|
|
26700
27010
|
const temporary = `${directory}.tmp-${process.pid}-${Date.now()}`;
|
|
26701
27011
|
await mkdir4(temporary, { recursive: true, mode: 448 });
|
|
26702
27012
|
try {
|
|
26703
|
-
await writeFile4(
|
|
27013
|
+
await writeFile4(join13(temporary, "package.json"), JSON.stringify({
|
|
26704
27014
|
name: "toc-ocra-claude-acp-runtime",
|
|
26705
27015
|
private: true,
|
|
26706
27016
|
type: "module",
|
|
26707
27017
|
dependencies: { [manifest.sdk.name]: manifest.sdk.version }
|
|
26708
27018
|
}, null, 2));
|
|
26709
27019
|
await runNpm(["install", "--omit=optional", "--no-audit", "--no-fund", "--no-package-lock", "--loglevel=error"], temporary);
|
|
26710
|
-
await copyFile(entry,
|
|
27020
|
+
await copyFile(entry, join13(temporary, "index.mjs"));
|
|
26711
27021
|
await rm2(directory, { recursive: true, force: true });
|
|
26712
27022
|
await rename4(temporary, directory);
|
|
26713
27023
|
} catch (error62) {
|
|
@@ -26781,6 +27091,22 @@ var GEMINI_LAUNCH_SPEC = {
|
|
|
26781
27091
|
dialect: GEMINI_ACP_DIALECT,
|
|
26782
27092
|
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.gemini }
|
|
26783
27093
|
};
|
|
27094
|
+
var ANTIGRAVITY_LAUNCH_SPEC = {
|
|
27095
|
+
agent: "antigravity",
|
|
27096
|
+
headless: "acp",
|
|
27097
|
+
// agy has no full-access mode in session/set_mode; its launch flag grants it while plan approvals still reach the chat.
|
|
27098
|
+
args: ({ access }) => ["acp", ...access === "bypassPermissions" ? ["--dangerously-skip-permissions"] : []],
|
|
27099
|
+
env: { AGY_CLI_DISABLE_AUTO_UPDATE: "true" },
|
|
27100
|
+
scrubEnv: (env) => scrubAntigravityEnv(env),
|
|
27101
|
+
minimumVersions: ["1.5.2"],
|
|
27102
|
+
permissionModeConfig: {
|
|
27103
|
+
values: { ask: "default", acceptEdits: "accept-edits", bypassPermissions: "default", plan: "plan" }
|
|
27104
|
+
},
|
|
27105
|
+
resumePreference: "resume",
|
|
27106
|
+
dialect: ANTIGRAVITY_ACP_DIALECT,
|
|
27107
|
+
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.antigravity },
|
|
27108
|
+
runSettings: { permissionModes: ["read-only", "acceptEdits", "bypassPermissions"], plan: "native" }
|
|
27109
|
+
};
|
|
26784
27110
|
var GROK_LAUNCH_SPEC = {
|
|
26785
27111
|
agent: "grok",
|
|
26786
27112
|
headless: "acp",
|
|
@@ -26833,7 +27159,7 @@ var CLAUDE_LAUNCH_SPEC = {
|
|
|
26833
27159
|
const executable = installedCli(claude);
|
|
26834
27160
|
const runtime = await ensureClaudeRuntime(dataDir2);
|
|
26835
27161
|
return {
|
|
26836
|
-
launch: { executable: process.execPath, args: [
|
|
27162
|
+
launch: { executable: process.execPath, args: [join14(runtime, "index.mjs")], env: { ...providerEnvironment(), CLAUDE_CODE_EXECUTABLE: executable }, cwd: workdir },
|
|
26837
27163
|
fingerprint: `claude:${runtime}:${executable}`
|
|
26838
27164
|
};
|
|
26839
27165
|
},
|
|
@@ -26881,6 +27207,7 @@ var ACP_LAUNCH_SPECS = [
|
|
|
26881
27207
|
KIRO_LAUNCH_SPEC,
|
|
26882
27208
|
KIMI_LAUNCH_SPEC,
|
|
26883
27209
|
GEMINI_LAUNCH_SPEC,
|
|
27210
|
+
ANTIGRAVITY_LAUNCH_SPEC,
|
|
26884
27211
|
GROK_LAUNCH_SPEC,
|
|
26885
27212
|
OPENCODE_LAUNCH_SPEC,
|
|
26886
27213
|
OMP_LAUNCH_SPEC,
|
|
@@ -26928,7 +27255,9 @@ function chatSpec(row) {
|
|
|
26928
27255
|
async launch({ access, model, reasoningEffort, workdir, dataDir: dataDir2 }) {
|
|
26929
27256
|
if (row.adapter) return row.adapter({ access, model, reasoningEffort, workdir, dataDir: dataDir2 });
|
|
26930
27257
|
const args = row.args({ access, model, reasoningEffort });
|
|
26931
|
-
const
|
|
27258
|
+
const baseEnv = { ...await hydrateRuntimeProxy(providerEnvironment()), ...row.env };
|
|
27259
|
+
const env = row.scrubEnv ? row.scrubEnv(baseEnv) : baseEnv;
|
|
27260
|
+
const spec = launchCli({ spec: cli, args, env });
|
|
26932
27261
|
return { launch: { executable: spec.executable, args: spec.args, env: spec.env, cwd: workdir }, fingerprint: args.join(" ") };
|
|
26933
27262
|
},
|
|
26934
27263
|
...row.permissionModeConfig ? { modeFor: (access, plan) => acpModeFor(row, access, plan) } : {},
|
|
@@ -26952,7 +27281,7 @@ var ACP_CHAT_IDS = [...ACP_CHAT.keys()];
|
|
|
26952
27281
|
// src/acp/acp-model-catalog-probe.ts
|
|
26953
27282
|
import { mkdtemp, rm as rm3 } from "node:fs/promises";
|
|
26954
27283
|
import { tmpdir } from "node:os";
|
|
26955
|
-
import { join as
|
|
27284
|
+
import { join as join15 } from "node:path";
|
|
26956
27285
|
|
|
26957
27286
|
// src/acp/acp-options.ts
|
|
26958
27287
|
var text = (value) => typeof value === "string" && value ? value : void 0;
|
|
@@ -27031,7 +27360,8 @@ function settingWrite(state, step, settings, cliLabel) {
|
|
|
27031
27360
|
if (!model) return {};
|
|
27032
27361
|
const option2 = findOption(state.configOptions, "model");
|
|
27033
27362
|
if (option2) {
|
|
27034
|
-
const
|
|
27363
|
+
const stripped = /^(.+)-(?:low|medium|high|xhigh|max)$/i.exec(model)?.[1];
|
|
27364
|
+
const value = matchChoice(option2, model) ?? (stripped ? matchChoice(option2, stripped) : void 0);
|
|
27035
27365
|
if (!value) return { note: `${cliLabel} \u6CA1\u6709\u6A21\u578B\u300C${model}\u300D\uFF0C\u672C\u8F6E\u4F7F\u7528\u5F53\u524D\u6A21\u578B` };
|
|
27036
27366
|
return option2.currentValue === value ? {} : config2(option2, value);
|
|
27037
27367
|
}
|
|
@@ -27039,9 +27369,11 @@ function settingWrite(state, step, settings, cliLabel) {
|
|
|
27039
27369
|
return state.currentModelId === model ? {} : { write: { step, label: STEP_LABEL[step], method: "session/set_model", params: { modelId: model } } };
|
|
27040
27370
|
}
|
|
27041
27371
|
case "effort": {
|
|
27042
|
-
|
|
27372
|
+
const inferred = settings.model ? /^.+-(low|medium|high|xhigh|max)$/i.exec(settings.model)?.[1] : void 0;
|
|
27373
|
+
const wantedEffort = settings.reasoningEffort || inferred;
|
|
27374
|
+
if (!wantedEffort) return {};
|
|
27043
27375
|
const option2 = findOption(state.configOptions, "thought_level");
|
|
27044
|
-
const value = option2 ? matchChoice(option2,
|
|
27376
|
+
const value = option2 ? matchChoice(option2, wantedEffort) : void 0;
|
|
27045
27377
|
return option2 && value && option2.currentValue !== value ? config2(option2, value) : {};
|
|
27046
27378
|
}
|
|
27047
27379
|
case "fast": {
|
|
@@ -27585,9 +27917,9 @@ async function readSessionModels(row, clientVersion = "1") {
|
|
|
27585
27917
|
const discovery = row.modelDiscovery;
|
|
27586
27918
|
if (discovery.kind !== "session") throw new Error(`${row.agent} does not list its models in a session`);
|
|
27587
27919
|
const cli = requireCliSpec(row.agent);
|
|
27588
|
-
const folder = await mkdtemp(
|
|
27920
|
+
const folder = await mkdtemp(join15(tmpdir(), `toc-ocra-acp-models-${row.agent}-`));
|
|
27589
27921
|
try {
|
|
27590
|
-
const folderArgs = discovery.sessionFolderArgs?.(
|
|
27922
|
+
const folderArgs = discovery.sessionFolderArgs?.(join15(folder, "sessions")) ?? [];
|
|
27591
27923
|
const args = [...row.args({ access: "read-only", model: "", reasoningEffort: "" }), ...folderArgs];
|
|
27592
27924
|
const launch = launchCli({ spec: cli, args, env: { ...providerEnvironment(), ...row.env } });
|
|
27593
27925
|
const connection = await AcpConnection.open({ executable: launch.executable, args: launch.args, env: launch.env, cwd: folder }, {
|
|
@@ -28216,14 +28548,14 @@ function isWriterConflict(message) {
|
|
|
28216
28548
|
}
|
|
28217
28549
|
|
|
28218
28550
|
// src/providers/cli/claude.ts
|
|
28219
|
-
import { readdirSync as readdirSync4, readFileSync as
|
|
28220
|
-
import { homedir as
|
|
28221
|
-
import { join as
|
|
28551
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
28552
|
+
import { homedir as homedir10 } from "node:os";
|
|
28553
|
+
import { join as join16 } from "node:path";
|
|
28222
28554
|
var CLAUDE = requireCliSpec("claude");
|
|
28223
28555
|
function claudeProjectRoots() {
|
|
28224
28556
|
const configured = process.env.CLAUDE_CONFIG_DIR;
|
|
28225
|
-
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [
|
|
28226
|
-
return dirs.map((dir) =>
|
|
28557
|
+
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [join16(homedir10(), ".claude")];
|
|
28558
|
+
return dirs.map((dir) => join16(dir, "projects"));
|
|
28227
28559
|
}
|
|
28228
28560
|
function claudeTranscriptExists(sessionId) {
|
|
28229
28561
|
return claudeTranscriptPath(sessionId) !== void 0;
|
|
@@ -28239,7 +28571,7 @@ function claudeTranscriptPath(sessionId) {
|
|
|
28239
28571
|
}
|
|
28240
28572
|
for (const project of projects) {
|
|
28241
28573
|
try {
|
|
28242
|
-
if (readdirSync4(
|
|
28574
|
+
if (readdirSync4(join16(root2, project)).includes(file2)) return join16(root2, project, file2);
|
|
28243
28575
|
} catch {
|
|
28244
28576
|
}
|
|
28245
28577
|
}
|
|
@@ -28283,7 +28615,7 @@ var claudeProvider = {
|
|
|
28283
28615
|
settings.disableAllHooks = true;
|
|
28284
28616
|
args.push("--restricted", "--permission-mode", "plan", "--tools", "Read,Glob,Grep", "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--disallowedTools", "mcp__*");
|
|
28285
28617
|
try {
|
|
28286
|
-
const userSettings = JSON.parse(
|
|
28618
|
+
const userSettings = JSON.parse(readFileSync6(join16(homedir10(), ".claude", "settings.json"), "utf8"));
|
|
28287
28619
|
for (const [key, value] of Object.entries(userSettings.env ?? {})) {
|
|
28288
28620
|
if (/^ANTHROPIC_[A-Z0-9_]+$/.test(key) && typeof value === "string" && env[key] === void 0) env[key] = value;
|
|
28289
28621
|
}
|
|
@@ -28299,7 +28631,7 @@ var claudeProvider = {
|
|
|
28299
28631
|
if (source && request.fork.keepTurns > 0) {
|
|
28300
28632
|
let text3 = "";
|
|
28301
28633
|
try {
|
|
28302
|
-
text3 =
|
|
28634
|
+
text3 = readFileSync6(source, "utf8");
|
|
28303
28635
|
} catch {
|
|
28304
28636
|
}
|
|
28305
28637
|
const at = claudeForkBoundary(text3, request.fork.keepTurns);
|
|
@@ -29017,7 +29349,8 @@ function createAcpProvider(row) {
|
|
|
29017
29349
|
...turn.reasoningEffort && !row.launchApplies?.reasoningEffort ? { reasoningEffort: turn.reasoningEffort } : {},
|
|
29018
29350
|
...row.runSettings?.fast && turn.fast !== void 0 ? { fast: turn.fast } : {}
|
|
29019
29351
|
};
|
|
29020
|
-
const
|
|
29352
|
+
const baseEnv = { ...providerEnvironment(), ...row.env };
|
|
29353
|
+
const env = row.scrubEnv ? row.scrubEnv(baseEnv) : baseEnv;
|
|
29021
29354
|
launchEnv = env;
|
|
29022
29355
|
return launchCli({ spec: cli, args: row.args({ access, model: turn.model, reasoningEffort: turn.reasoningEffort }), env });
|
|
29023
29356
|
},
|
|
@@ -29094,11 +29427,229 @@ var opencodeProvider = {
|
|
|
29094
29427
|
}
|
|
29095
29428
|
};
|
|
29096
29429
|
|
|
29430
|
+
// src/providers/antigravity-quota.ts
|
|
29431
|
+
import { spawn as spawn8 } from "node:child_process";
|
|
29432
|
+
var ANTIGRAVITY_MIN_USAGE_VERSION = "1.1.11";
|
|
29433
|
+
var ANTIGRAVITY_USAGE_ARGS = ["-p", "/usage", "--output-format", "json", "--print-timeout", "20s"];
|
|
29434
|
+
var VERSION_TIMEOUT_MS = 5e3;
|
|
29435
|
+
var USAGE_TIMEOUT_MS = 3e4;
|
|
29436
|
+
var MAX_OUTPUT_BYTES = 512 * 1024;
|
|
29437
|
+
var AGY_ERROR_PREFIX = "AGY_ERROR:";
|
|
29438
|
+
var WEEKLY_WINDOW_SECONDS = 7 * 86400;
|
|
29439
|
+
var SESSION_WINDOW_SECONDS = 5 * 3600;
|
|
29440
|
+
var SIGNED_OUT_PHRASES = [
|
|
29441
|
+
"not logged into antigravity",
|
|
29442
|
+
"not logged in",
|
|
29443
|
+
"not signed in",
|
|
29444
|
+
"not authenticated",
|
|
29445
|
+
"not-authenticated",
|
|
29446
|
+
"unauthenticated",
|
|
29447
|
+
"run agy login",
|
|
29448
|
+
"please sign in",
|
|
29449
|
+
"please log in",
|
|
29450
|
+
"sign in to antigravity",
|
|
29451
|
+
"no credentials",
|
|
29452
|
+
"authentication required"
|
|
29453
|
+
];
|
|
29454
|
+
var unsupportedUsageLatched = false;
|
|
29455
|
+
function isRecord(value) {
|
|
29456
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29457
|
+
}
|
|
29458
|
+
function readString(value) {
|
|
29459
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
|
29460
|
+
}
|
|
29461
|
+
function parseResetSeconds(value) {
|
|
29462
|
+
const text3 = readString(value);
|
|
29463
|
+
if (!text3) return 0;
|
|
29464
|
+
const ms = Date.parse(text3);
|
|
29465
|
+
return Number.isFinite(ms) ? Math.floor(ms / 1e3) : 0;
|
|
29466
|
+
}
|
|
29467
|
+
function windowSecondsFor(window) {
|
|
29468
|
+
if (window === "weekly") return WEEKLY_WINDOW_SECONDS;
|
|
29469
|
+
if (window === "5h") return SESSION_WINDOW_SECONDS;
|
|
29470
|
+
return void 0;
|
|
29471
|
+
}
|
|
29472
|
+
function shortGroupLabel(groupName) {
|
|
29473
|
+
const lower = groupName.toLowerCase();
|
|
29474
|
+
if (lower === "gemini models" || lower === "gemini") return "Gemini";
|
|
29475
|
+
if (lower === "claude and gpt models" || lower === "claude & gpt models") return "Claude / GPT";
|
|
29476
|
+
return groupName.replace(/\s+models$/i, "").trim() || groupName;
|
|
29477
|
+
}
|
|
29478
|
+
function shortWindowLabel(window, rawName) {
|
|
29479
|
+
if (window === "weekly") return "\u6BCF\u5468\u989D\u5EA6";
|
|
29480
|
+
if (window === "5h") return "5 \u5C0F\u65F6\u989D\u5EA6";
|
|
29481
|
+
if (!rawName) return "\u989D\u5EA6";
|
|
29482
|
+
return rawName.replace(/\s+(?:remaining|used|left)$/i, "").trim() || rawName;
|
|
29483
|
+
}
|
|
29484
|
+
function formatBucketLabel(groupName, window, rawName, siblings) {
|
|
29485
|
+
const group = shortGroupLabel(groupName);
|
|
29486
|
+
const win = shortWindowLabel(window, rawName);
|
|
29487
|
+
return siblings <= 1 && !window && !rawName ? group : `${group} \xB7 ${win}`;
|
|
29488
|
+
}
|
|
29489
|
+
function findEnvelope(stdout, parse4) {
|
|
29490
|
+
for (const line of stdout.split(/\r?\n/)) {
|
|
29491
|
+
const trimmed = line.trim();
|
|
29492
|
+
if (!trimmed.startsWith("{")) continue;
|
|
29493
|
+
try {
|
|
29494
|
+
const found = parse4(JSON.parse(trimmed));
|
|
29495
|
+
if (found !== null) return found;
|
|
29496
|
+
} catch {
|
|
29497
|
+
continue;
|
|
29498
|
+
}
|
|
29499
|
+
}
|
|
29500
|
+
return null;
|
|
29501
|
+
}
|
|
29502
|
+
function antigravityStdoutShowsModelTurn(stdout) {
|
|
29503
|
+
return findEnvelope(stdout, (value) => {
|
|
29504
|
+
if (!isRecord(value)) return null;
|
|
29505
|
+
if (typeof value.num_turns === "number" && value.num_turns > 0) return true;
|
|
29506
|
+
return readString(value.conversation_id) !== null ? true : null;
|
|
29507
|
+
}) !== null;
|
|
29508
|
+
}
|
|
29509
|
+
function parseAntigravityUsageEnvelope(value) {
|
|
29510
|
+
if (!isRecord(value) || readString(value.status) !== "SUCCESS") return null;
|
|
29511
|
+
const command = value.command;
|
|
29512
|
+
if (!isRecord(command) || readString(command.name) !== "usage") return null;
|
|
29513
|
+
const data = command.data;
|
|
29514
|
+
if (!isRecord(data) || !Array.isArray(data.groups)) return null;
|
|
29515
|
+
const windows = [];
|
|
29516
|
+
for (const rawGroup of data.groups) {
|
|
29517
|
+
if (!isRecord(rawGroup)) continue;
|
|
29518
|
+
const groupName = readString(rawGroup.name);
|
|
29519
|
+
const rawBuckets = Array.isArray(rawGroup.buckets) ? rawGroup.buckets : [];
|
|
29520
|
+
if (!groupName) continue;
|
|
29521
|
+
const enabled = rawBuckets.filter((item) => isRecord(item) && item.disabled !== true);
|
|
29522
|
+
for (const bucket of enabled) {
|
|
29523
|
+
const id = readString(bucket.id);
|
|
29524
|
+
const fraction = bucket.remaining_fraction;
|
|
29525
|
+
if (!id || typeof fraction !== "number" || !Number.isFinite(fraction)) continue;
|
|
29526
|
+
const windowKind = readString(bucket.window);
|
|
29527
|
+
const windowSeconds = windowSecondsFor(windowKind);
|
|
29528
|
+
const usedPercent = Math.min(100, Math.max(0, Math.round((1 - fraction) * 1e4) / 100));
|
|
29529
|
+
windows.push({
|
|
29530
|
+
key: `antigravity:${id}`,
|
|
29531
|
+
label: formatBucketLabel(groupName, windowKind, readString(bucket.name), enabled.length),
|
|
29532
|
+
used_percent: usedPercent,
|
|
29533
|
+
resets_at: parseResetSeconds(bucket.reset_time),
|
|
29534
|
+
...windowSeconds ? { window_seconds: windowSeconds } : {}
|
|
29535
|
+
});
|
|
29536
|
+
}
|
|
29537
|
+
}
|
|
29538
|
+
if (data.groups.length > 0 && windows.length === 0) return null;
|
|
29539
|
+
return windows;
|
|
29540
|
+
}
|
|
29541
|
+
function parseAntigravityUsageStdout(stdout) {
|
|
29542
|
+
return findEnvelope(stdout, parseAntigravityUsageEnvelope);
|
|
29543
|
+
}
|
|
29544
|
+
function readAgyErrorEnvelope(stdout) {
|
|
29545
|
+
return findEnvelope(
|
|
29546
|
+
stdout,
|
|
29547
|
+
(value) => isRecord(value) && readString(value.status) === "ERROR" ? readString(value.error) : null
|
|
29548
|
+
);
|
|
29549
|
+
}
|
|
29550
|
+
function classifyFailure(output2, stderr) {
|
|
29551
|
+
if (stderr.includes("Authentication required. Please visit the URL")) {
|
|
29552
|
+
return "Antigravity \u672A\u767B\u5F55\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u5B8C\u6210\u540E\u518D\u540C\u6B65\u989D\u5EA6";
|
|
29553
|
+
}
|
|
29554
|
+
for (const line of output2.split(/\r?\n/)) {
|
|
29555
|
+
const idx = line.indexOf(AGY_ERROR_PREFIX);
|
|
29556
|
+
if (idx === -1) continue;
|
|
29557
|
+
const payload = line.slice(idx + AGY_ERROR_PREFIX.length).trim();
|
|
29558
|
+
if (!payload.startsWith("{")) continue;
|
|
29559
|
+
try {
|
|
29560
|
+
const parsed = JSON.parse(payload);
|
|
29561
|
+
const status = typeof parsed.status === "string" ? parsed.status.toUpperCase() : "";
|
|
29562
|
+
const code2 = typeof parsed.error_code === "number" ? parsed.error_code : null;
|
|
29563
|
+
if (status === "UNAUTHENTICATED" || code2 === 401) return "Antigravity \u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u91CD\u65B0\u767B\u5F55";
|
|
29564
|
+
if (status === "PERMISSION_DENIED" || code2 === 403) return "\u5F53\u524D Antigravity \u8D26\u53F7\u6CA1\u6709\u53EF\u7528\u7684\u8BA2\u9605\u989D\u5EA6\u6743\u9650";
|
|
29565
|
+
if (status === "RESOURCE_EXHAUSTED" || code2 === 429) return "Antigravity \u989D\u5EA6\u63A5\u53E3\u6682\u65F6\u9650\u6D41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5";
|
|
29566
|
+
if (code2 !== null && code2 >= 500 && code2 < 600) return `Antigravity \u670D\u52A1\u7AEF\u8FD4\u56DE\u9519\u8BEF (${code2})`;
|
|
29567
|
+
} catch {
|
|
29568
|
+
continue;
|
|
29569
|
+
}
|
|
29570
|
+
}
|
|
29571
|
+
const lowered = output2.toLowerCase();
|
|
29572
|
+
if (SIGNED_OUT_PHRASES.some((phrase) => lowered.includes(phrase))) {
|
|
29573
|
+
return "Antigravity \u672A\u767B\u5F55\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C agy \u5B8C\u6210\u540E\u518D\u540C\u6B65\u989D\u5EA6";
|
|
29574
|
+
}
|
|
29575
|
+
return null;
|
|
29576
|
+
}
|
|
29577
|
+
function runCommand(executable, args, env, timeoutMs) {
|
|
29578
|
+
return new Promise((resolve10, reject) => {
|
|
29579
|
+
const child = spawn8(executable, [...args], { env, stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
29580
|
+
let stdout = "";
|
|
29581
|
+
let stderr = "";
|
|
29582
|
+
let timedOut = false;
|
|
29583
|
+
const append = (current, chunk) => {
|
|
29584
|
+
if (current.length >= MAX_OUTPUT_BYTES) return current;
|
|
29585
|
+
return current + chunk.toString("utf8", 0, Math.max(0, MAX_OUTPUT_BYTES - current.length));
|
|
29586
|
+
};
|
|
29587
|
+
const timer = setTimeout(() => {
|
|
29588
|
+
timedOut = true;
|
|
29589
|
+
child.kill("SIGKILL");
|
|
29590
|
+
}, timeoutMs);
|
|
29591
|
+
child.stdout.on("data", (chunk) => {
|
|
29592
|
+
stdout = append(stdout, chunk);
|
|
29593
|
+
});
|
|
29594
|
+
child.stderr.on("data", (chunk) => {
|
|
29595
|
+
stderr = append(stderr, chunk);
|
|
29596
|
+
});
|
|
29597
|
+
child.on("error", (error62) => {
|
|
29598
|
+
clearTimeout(timer);
|
|
29599
|
+
reject(error62);
|
|
29600
|
+
});
|
|
29601
|
+
child.on("close", (code2) => {
|
|
29602
|
+
clearTimeout(timer);
|
|
29603
|
+
resolve10({ code: code2, stdout, stderr, timedOut });
|
|
29604
|
+
});
|
|
29605
|
+
});
|
|
29606
|
+
}
|
|
29607
|
+
async function readAntigravityQuotaWindows() {
|
|
29608
|
+
if (unsupportedUsageLatched) {
|
|
29609
|
+
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");
|
|
29610
|
+
}
|
|
29611
|
+
const spec = requireCliSpec("antigravity");
|
|
29612
|
+
const baseEnv = await hydrateRuntimeProxy(providerEnvironment());
|
|
29613
|
+
const env = scrubAntigravityEnv(baseEnv);
|
|
29614
|
+
const versionLaunch = launchCli({ spec, args: ["--version"], env });
|
|
29615
|
+
const versionRun = await runCommand(versionLaunch.executable, versionLaunch.args, versionLaunch.env ?? env, VERSION_TIMEOUT_MS).catch((error62) => {
|
|
29616
|
+
const message = error62 instanceof Error ? error62.message : String(error62);
|
|
29617
|
+
if (/ENOENT/i.test(message)) throw new Error("\u672C\u673A\u672A\u5B89\u88C5 Antigravity CLI\uFF08agy\uFF09");
|
|
29618
|
+
throw new Error(`\u65E0\u6CD5\u542F\u52A8 Antigravity CLI\uFF1A${message}`);
|
|
29619
|
+
});
|
|
29620
|
+
const detected = versionRun.code === 0 && !versionRun.timedOut ? versionNumber(versionRun.stdout.trim() || versionRun.stderr.trim()) : void 0;
|
|
29621
|
+
if (!detected || compareVersions(detected, ANTIGRAVITY_MIN_USAGE_VERSION) < 0) {
|
|
29622
|
+
throw new Error(
|
|
29623
|
+
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"
|
|
29624
|
+
);
|
|
29625
|
+
}
|
|
29626
|
+
const usageLaunch = launchCli({ spec, args: [...ANTIGRAVITY_USAGE_ARGS], env });
|
|
29627
|
+
const result = await runCommand(usageLaunch.executable, usageLaunch.args, usageLaunch.env ?? env, USAGE_TIMEOUT_MS);
|
|
29628
|
+
const windows = parseAntigravityUsageStdout(result.stdout);
|
|
29629
|
+
if (!windows) {
|
|
29630
|
+
const classified = classifyFailure(`${result.stdout}
|
|
29631
|
+
${result.stderr}`, result.stderr);
|
|
29632
|
+
if (classified) throw new Error(classified);
|
|
29633
|
+
if (result.timedOut) throw new Error("\u8BFB\u53D6 Antigravity \u989D\u5EA6\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
29634
|
+
if (antigravityStdoutShowsModelTurn(result.stdout)) {
|
|
29635
|
+
unsupportedUsageLatched = true;
|
|
29636
|
+
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");
|
|
29637
|
+
}
|
|
29638
|
+
const envelopeError = readAgyErrorEnvelope(result.stdout);
|
|
29639
|
+
if (envelopeError) throw new Error(`Antigravity \u989D\u5EA6\u8BFB\u53D6\u5931\u8D25\uFF1A${envelopeError}`);
|
|
29640
|
+
throw new Error(`Antigravity \u672A\u8FD4\u56DE\u6709\u6548\u989D\u5EA6\u6570\u636E${result.code ? ` (exit ${result.code})` : ""}`);
|
|
29641
|
+
}
|
|
29642
|
+
if (windows.length === 0) {
|
|
29643
|
+
throw new Error("Antigravity \u5F53\u524D\u8D26\u53F7\u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u7684\u989D\u5EA6\u7A97\u53E3");
|
|
29644
|
+
}
|
|
29645
|
+
return windows;
|
|
29646
|
+
}
|
|
29647
|
+
|
|
29097
29648
|
// src/providers/claude-quota.ts
|
|
29098
29649
|
import { execFile as execFile5 } from "node:child_process";
|
|
29099
29650
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
29100
|
-
import { homedir as
|
|
29101
|
-
import { join as
|
|
29651
|
+
import { homedir as homedir11 } from "node:os";
|
|
29652
|
+
import { join as join17 } from "node:path";
|
|
29102
29653
|
import { promisify as promisify3 } from "node:util";
|
|
29103
29654
|
var execFileAsync3 = promisify3(execFile5);
|
|
29104
29655
|
var CLAUDE_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
@@ -29137,7 +29688,7 @@ function parseClaudeQuota(body) {
|
|
|
29137
29688
|
}
|
|
29138
29689
|
return windows;
|
|
29139
29690
|
}
|
|
29140
|
-
var claudeHome2 = () => process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
29691
|
+
var claudeHome2 = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join17(homedir11(), ".claude");
|
|
29141
29692
|
function tokenFrom(content) {
|
|
29142
29693
|
try {
|
|
29143
29694
|
const token = objectValue2(objectValue2(JSON.parse(content)).claudeAiOauth).accessToken;
|
|
@@ -29149,7 +29700,7 @@ function tokenFrom(content) {
|
|
|
29149
29700
|
async function readClaudeAccessToken() {
|
|
29150
29701
|
const fromEnv = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
29151
29702
|
if (fromEnv) return fromEnv;
|
|
29152
|
-
const fromFile = tokenFrom(await readFile5(
|
|
29703
|
+
const fromFile = tokenFrom(await readFile5(join17(claudeHome2(), ".credentials.json"), "utf8").catch(() => ""));
|
|
29153
29704
|
if (fromFile) return fromFile;
|
|
29154
29705
|
if (process.platform !== "darwin") return void 0;
|
|
29155
29706
|
const { stdout } = await execFileAsync3("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 1e4 }).catch(() => ({ stdout: "" }));
|
|
@@ -29171,11 +29722,11 @@ async function readClaudeQuotaWindows() {
|
|
|
29171
29722
|
}
|
|
29172
29723
|
|
|
29173
29724
|
// src/providers/codex-quota.ts
|
|
29174
|
-
import { spawn as
|
|
29725
|
+
import { spawn as spawn9 } from "node:child_process";
|
|
29175
29726
|
import { createInterface as createInterface4 } from "node:readline";
|
|
29176
29727
|
async function readCodexQuotaWindows() {
|
|
29177
29728
|
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--stdio"] });
|
|
29178
|
-
const child =
|
|
29729
|
+
const child = spawn9(launch.executable, launch.args, { env: launch.env, stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
29179
29730
|
let nextId = 0;
|
|
29180
29731
|
const pending = /* @__PURE__ */ new Map();
|
|
29181
29732
|
const lines = createInterface4({ input: child.stdout });
|
|
@@ -29347,6 +29898,7 @@ var NATIVE = {
|
|
|
29347
29898
|
claude: { headless: claudeProvider, chat: (_request, attachments) => claudeChatProvider(attachments), models: MODEL_SOURCES.claude, quota: readClaudeQuotaWindows, runSettings: { permissionModes: ALL_LEVELS, plan: "native", fast: true } }
|
|
29348
29899
|
};
|
|
29349
29900
|
var ACP_EXTRAS = {
|
|
29901
|
+
antigravity: { quota: readAntigravityQuotaWindows },
|
|
29350
29902
|
kiro: { quota: readKiroQuotaWindows, legacy: { headless: kiroProvider, restrictedPermission: true, runSettings: { permissionModes: ["read-only", "bypassPermissions"], plan: "prompt" } } },
|
|
29351
29903
|
gemini: { legacy: { headless: geminiProvider, restrictedPermission: false } },
|
|
29352
29904
|
grok: { legacy: { headless: grokProvider, restrictedPermission: false } },
|
|
@@ -29446,7 +29998,7 @@ function probeVersion(path, args) {
|
|
|
29446
29998
|
if (args.length === 0) return Promise.resolve({});
|
|
29447
29999
|
return new Promise((resolve10) => {
|
|
29448
30000
|
const launch = directLaunch2(path, args, process.env.TOC_OCRA_NODE_PATH || process.execPath);
|
|
29449
|
-
const child =
|
|
30001
|
+
const child = spawn10(launch.executable, launch.args, { stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
29450
30002
|
let stdout = "";
|
|
29451
30003
|
let stderr = "";
|
|
29452
30004
|
let settled = false;
|
|
@@ -29531,12 +30083,12 @@ var cliDetection = new CliDetectionService();
|
|
|
29531
30083
|
// src/smoke/cli-smoke.ts
|
|
29532
30084
|
import { mkdtemp as mkdtemp2, realpath as realpath3, rm as rm5 } from "node:fs/promises";
|
|
29533
30085
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
29534
|
-
import { join as
|
|
30086
|
+
import { join as join22 } from "node:path";
|
|
29535
30087
|
|
|
29536
30088
|
// src/runs/run-supervisor.ts
|
|
29537
|
-
import { spawn as
|
|
30089
|
+
import { spawn as spawn12 } from "node:child_process";
|
|
29538
30090
|
import { mkdir as mkdir7, realpath as realpath2, stat as stat5, writeFile as writeFile7 } from "node:fs/promises";
|
|
29539
|
-
import { basename as basename2, isAbsolute as isAbsolute4, join as
|
|
30091
|
+
import { basename as basename2, isAbsolute as isAbsolute4, join as join21, relative as relative2, resolve as resolve5 } from "node:path";
|
|
29540
30092
|
import { createInterface as createInterface6 } from "node:readline";
|
|
29541
30093
|
|
|
29542
30094
|
// src/providers/chat/index.ts
|
|
@@ -29825,12 +30377,12 @@ function codexGoalProvider(request, goal) {
|
|
|
29825
30377
|
}
|
|
29826
30378
|
|
|
29827
30379
|
// src/providers/cli/codex-fork.ts
|
|
29828
|
-
import { spawn as
|
|
30380
|
+
import { spawn as spawn11 } from "node:child_process";
|
|
29829
30381
|
import { createInterface as createInterface5 } from "node:readline";
|
|
29830
30382
|
var FORK_TIMEOUT_MS = 9e4;
|
|
29831
30383
|
async function forkCodexThread(options) {
|
|
29832
30384
|
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--listen", "stdio://"] });
|
|
29833
|
-
const child =
|
|
30385
|
+
const child = spawn11(launch.executable, launch.args, {
|
|
29834
30386
|
cwd: options.workdir,
|
|
29835
30387
|
env: launch.env,
|
|
29836
30388
|
shell: false,
|
|
@@ -29905,19 +30457,19 @@ async function forkCodexThread(options) {
|
|
|
29905
30457
|
|
|
29906
30458
|
// src/runs/run-recorder.ts
|
|
29907
30459
|
import { appendFileSync, mkdirSync as mkdirSync2 } from "node:fs";
|
|
29908
|
-
import { homedir as
|
|
29909
|
-
import { join as
|
|
30460
|
+
import { homedir as homedir12 } from "node:os";
|
|
30461
|
+
import { join as join18 } from "node:path";
|
|
29910
30462
|
var RunRecorder = class _RunRecorder {
|
|
29911
30463
|
constructor(path) {
|
|
29912
30464
|
this.path = path;
|
|
29913
30465
|
}
|
|
29914
30466
|
path;
|
|
29915
|
-
home =
|
|
30467
|
+
home = homedir12();
|
|
29916
30468
|
static fromEnvironment(runId, meta3) {
|
|
29917
30469
|
const directory = process.env.TOC_OCRA_RECORD_DIR?.trim();
|
|
29918
30470
|
if (!directory) return void 0;
|
|
29919
30471
|
mkdirSync2(directory, { recursive: true });
|
|
29920
|
-
const recorder = new _RunRecorder(
|
|
30472
|
+
const recorder = new _RunRecorder(join18(directory, `${String(meta3.agent ?? "cli")}-${runId}.jsonl`));
|
|
29921
30473
|
recorder.write({ meta: meta3 });
|
|
29922
30474
|
return recorder;
|
|
29923
30475
|
}
|
|
@@ -29933,7 +30485,7 @@ var RunRecorder = class _RunRecorder {
|
|
|
29933
30485
|
|
|
29934
30486
|
// src/runs/run-transcript.ts
|
|
29935
30487
|
import { chmod as chmod4, mkdir as mkdir5, readdir as readdir3, readFile as readFile6, rename as rename5, stat as stat3, unlink, writeFile as writeFile5 } from "node:fs/promises";
|
|
29936
|
-
import { join as
|
|
30488
|
+
import { join as join19 } from "node:path";
|
|
29937
30489
|
var MAX_TRANSCRIPT_ITEMS = 5e3;
|
|
29938
30490
|
var MAX_TRANSCRIPT_TEXT = 2e5;
|
|
29939
30491
|
var MAX_TRANSCRIPT_LINES = 2e4;
|
|
@@ -30198,7 +30750,7 @@ function transcriptFileName(runId) {
|
|
|
30198
30750
|
var TranscriptStore = class {
|
|
30199
30751
|
constructor(dataDir2, logger, env = process.env) {
|
|
30200
30752
|
this.logger = logger;
|
|
30201
|
-
this.directory = dataDir2 ?
|
|
30753
|
+
this.directory = dataDir2 ? join19(dataDir2, "transcripts") : "";
|
|
30202
30754
|
this.enabled = Boolean(dataDir2) && transcriptsOnDisk(env);
|
|
30203
30755
|
}
|
|
30204
30756
|
logger;
|
|
@@ -30253,7 +30805,7 @@ var TranscriptStore = class {
|
|
|
30253
30805
|
await this.writes.get(runId);
|
|
30254
30806
|
let text3;
|
|
30255
30807
|
try {
|
|
30256
|
-
text3 = await readFile6(
|
|
30808
|
+
text3 = await readFile6(join19(this.directory, name), "utf8");
|
|
30257
30809
|
} catch (error62) {
|
|
30258
30810
|
if (errorCode(error62) !== "ENOENT") this.logger.warn("run-transcript-read-failed", { runId, error: errorMessage(error62) });
|
|
30259
30811
|
return void 0;
|
|
@@ -30318,7 +30870,7 @@ var TranscriptStore = class {
|
|
|
30318
30870
|
transcript.dirty = false;
|
|
30319
30871
|
const body = JSON.stringify(transcript.toFile());
|
|
30320
30872
|
await this.ensureDirectory();
|
|
30321
|
-
const file2 =
|
|
30873
|
+
const file2 = join19(this.directory, name);
|
|
30322
30874
|
const temporary = `${file2}.${process.pid}.tmp`;
|
|
30323
30875
|
await writeFile5(temporary, body, { mode: 384 });
|
|
30324
30876
|
await rename5(temporary, file2);
|
|
@@ -30355,7 +30907,7 @@ var TranscriptStore = class {
|
|
|
30355
30907
|
const now = Date.now();
|
|
30356
30908
|
const files = [];
|
|
30357
30909
|
for (const name of names) {
|
|
30358
|
-
const path =
|
|
30910
|
+
const path = join19(this.directory, name);
|
|
30359
30911
|
if (name.endsWith(".tmp")) {
|
|
30360
30912
|
const info2 = await stat3(path).catch(() => void 0);
|
|
30361
30913
|
if (info2?.isFile() && now - info2.mtimeMs > STALE_TEMPORARY_MS) await unlink(path).catch(() => void 0);
|
|
@@ -30405,7 +30957,7 @@ function errorMessage(error62) {
|
|
|
30405
30957
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
30406
30958
|
import { constants as constants2 } from "node:fs";
|
|
30407
30959
|
import { lstat, mkdir as mkdir6, open as open3, realpath, rename as rename6, rm as rm4, writeFile as writeFile6 } from "node:fs/promises";
|
|
30408
|
-
import { basename, isAbsolute as isAbsolute3, join as
|
|
30960
|
+
import { basename, isAbsolute as isAbsolute3, join as join20, relative } from "node:path";
|
|
30409
30961
|
function within(root2, path) {
|
|
30410
30962
|
const segment = relative(root2, path);
|
|
30411
30963
|
return segment === "" || !segment.startsWith("..") && !isAbsolute3(segment);
|
|
@@ -30413,7 +30965,7 @@ function within(root2, path) {
|
|
|
30413
30965
|
async function attachmentDirectory(workdir, messageId) {
|
|
30414
30966
|
let directory = workdir;
|
|
30415
30967
|
for (const segment of [".echo", "attachments", `message-${encodeURIComponent(messageId).slice(0, 180)}`]) {
|
|
30416
|
-
directory =
|
|
30968
|
+
directory = join20(directory, segment);
|
|
30417
30969
|
await mkdir6(directory, { mode: 448 }).catch((error62) => {
|
|
30418
30970
|
if (error62.code !== "EEXIST") throw error62;
|
|
30419
30971
|
});
|
|
@@ -30421,7 +30973,7 @@ async function attachmentDirectory(workdir, messageId) {
|
|
|
30421
30973
|
if (metadata.isSymbolicLink() || !metadata.isDirectory() || !within(workdir, await realpath(directory))) {
|
|
30422
30974
|
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");
|
|
30423
30975
|
}
|
|
30424
|
-
if (segment === ".echo") await writeFile6(
|
|
30976
|
+
if (segment === ".echo") await writeFile6(join20(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
|
|
30425
30977
|
if (error62.code !== "EEXIST") throw error62;
|
|
30426
30978
|
});
|
|
30427
30979
|
}
|
|
@@ -30458,9 +31010,9 @@ async function prepareTaskAttachments(payload, workdir, download, signal2) {
|
|
|
30458
31010
|
const characters = Array.from(basename(file2.name.replace(/\\/g, "/")).replace(/[^\p{L}\p{N}._-]/gu, "_").replace(/\.+$/u, ""));
|
|
30459
31011
|
while (Buffer.byteLength(characters.join("")) > 160) characters.shift();
|
|
30460
31012
|
const name = characters.join("") || "attachment";
|
|
30461
|
-
const path =
|
|
31013
|
+
const path = join20(directory, `${file2.file_id}-${name}`);
|
|
30462
31014
|
if (!await matches(path, file2.size, file2.sha256, signal2)) {
|
|
30463
|
-
const temporary =
|
|
31015
|
+
const temporary = join20(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
|
|
30464
31016
|
try {
|
|
30465
31017
|
await download(payload.run_id, file2.file_id, temporary, file2.size, file2.sha256, signal2);
|
|
30466
31018
|
signal2.throwIfAborted();
|
|
@@ -30580,29 +31132,29 @@ import { extname } from "node:path";
|
|
|
30580
31132
|
import { pathToFileURL } from "node:url";
|
|
30581
31133
|
|
|
30582
31134
|
// src/acp/ask-user-question.ts
|
|
30583
|
-
var
|
|
31135
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
30584
31136
|
var getLodyMeta = (meta3) => {
|
|
30585
|
-
if (!
|
|
30586
|
-
return
|
|
31137
|
+
if (!isRecord2(meta3)) return null;
|
|
31138
|
+
return isRecord2(meta3.lody) ? meta3.lody : null;
|
|
30587
31139
|
};
|
|
30588
31140
|
var getClaudeCodeMeta = (meta3) => {
|
|
30589
|
-
if (!
|
|
30590
|
-
return
|
|
31141
|
+
if (!isRecord2(meta3)) return null;
|
|
31142
|
+
return isRecord2(meta3.claudeCode) ? meta3.claudeCode : null;
|
|
30591
31143
|
};
|
|
30592
31144
|
var getCodexMeta = (meta3) => {
|
|
30593
|
-
if (!
|
|
30594
|
-
return
|
|
31145
|
+
if (!isRecord2(meta3)) return null;
|
|
31146
|
+
return isRecord2(meta3.codex) ? meta3.codex : null;
|
|
30595
31147
|
};
|
|
30596
31148
|
var getLodyElicitationMeta = (meta3) => {
|
|
30597
31149
|
const elicitation = getLodyMeta(meta3)?.elicitation;
|
|
30598
|
-
return
|
|
31150
|
+
return isRecord2(elicitation) && elicitation.version === 1 ? elicitation : null;
|
|
30599
31151
|
};
|
|
30600
31152
|
function isAskUserQuestionPermission(params) {
|
|
30601
31153
|
const meta3 = params._meta;
|
|
30602
31154
|
const lody = getLodyElicitationMeta(meta3);
|
|
30603
31155
|
if (lody && Array.isArray(lody.questions)) return true;
|
|
30604
|
-
if (
|
|
30605
|
-
return
|
|
31156
|
+
if (isRecord2(getClaudeCodeMeta(meta3)?.askUserQuestion)) return true;
|
|
31157
|
+
return isRecord2(getCodexMeta(meta3)?.requestUserInput);
|
|
30606
31158
|
}
|
|
30607
31159
|
function hasValidNoteKeys(questions) {
|
|
30608
31160
|
if (!questions.some((question) => question.note)) return true;
|
|
@@ -30626,18 +31178,18 @@ function getAskUserQuestionAnswerKey(questions, index) {
|
|
|
30626
31178
|
}
|
|
30627
31179
|
var getLodyOutcomeAnswers = (outcomeMeta) => {
|
|
30628
31180
|
const elicitation = getLodyMeta(outcomeMeta)?.elicitation;
|
|
30629
|
-
return
|
|
31181
|
+
return isRecord2(elicitation) && isRecord2(elicitation.answers) ? elicitation.answers : null;
|
|
30630
31182
|
};
|
|
30631
31183
|
var getCodexOutcomeAnswers = (outcomeMeta) => {
|
|
30632
31184
|
const requestUserInput = getCodexMeta(outcomeMeta)?.requestUserInput;
|
|
30633
|
-
return
|
|
31185
|
+
return isRecord2(requestUserInput) && isRecord2(requestUserInput.answers) ? requestUserInput.answers : null;
|
|
30634
31186
|
};
|
|
30635
31187
|
var getClaudeOutcomeAnswers = (outcomeMeta) => {
|
|
30636
31188
|
const askUserQuestion = getClaudeCodeMeta(outcomeMeta)?.askUserQuestion;
|
|
30637
|
-
return
|
|
31189
|
+
return isRecord2(askUserQuestion) && isRecord2(askUserQuestion.answers) ? askUserQuestion.answers : null;
|
|
30638
31190
|
};
|
|
30639
31191
|
function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
30640
|
-
if (!outcome || !
|
|
31192
|
+
if (!outcome || !isRecord2(outcome._meta) || !hasValidNoteKeys(meta3.questions)) return null;
|
|
30641
31193
|
const answerSources = [
|
|
30642
31194
|
{ source: "lody", answers: getLodyOutcomeAnswers(outcome._meta) },
|
|
30643
31195
|
{ source: "codex", answers: getCodexOutcomeAnswers(outcome._meta) },
|
|
@@ -30656,7 +31208,7 @@ function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
|
30656
31208
|
const raw = answerSource.answers[sourceKey];
|
|
30657
31209
|
if (raw === void 0) continue;
|
|
30658
31210
|
if (answerSource.source === "codex") {
|
|
30659
|
-
if (!
|
|
31211
|
+
if (!isRecord2(raw) || !Array.isArray(raw.answers)) continue;
|
|
30660
31212
|
const values = raw.answers.filter((value) => typeof value === "string");
|
|
30661
31213
|
if (values.length === 0) continue;
|
|
30662
31214
|
result[key] = question.multiSelect ? values : values[0] ?? "";
|
|
@@ -30670,20 +31222,20 @@ function extractAskUserQuestionAnswersFromOutcome(meta3, outcome) {
|
|
|
30670
31222
|
}
|
|
30671
31223
|
return Object.keys(result).length > 0 ? result : null;
|
|
30672
31224
|
}
|
|
30673
|
-
var isEnumOption = (value) =>
|
|
31225
|
+
var isEnumOption = (value) => isRecord2(value) && typeof value.const === "string";
|
|
30674
31226
|
var getEnumOptionSource = (prop) => {
|
|
30675
31227
|
if (Array.isArray(prop.oneOf)) return prop.oneOf;
|
|
30676
31228
|
if (Array.isArray(prop.enum)) return prop.enum;
|
|
30677
31229
|
const items = prop.items;
|
|
30678
|
-
if (
|
|
31230
|
+
if (isRecord2(items)) {
|
|
30679
31231
|
if (Array.isArray(items.anyOf)) return items.anyOf;
|
|
30680
31232
|
if (Array.isArray(items.enum)) return items.enum;
|
|
30681
31233
|
}
|
|
30682
31234
|
return null;
|
|
30683
31235
|
};
|
|
30684
|
-
var isQuestionProperty = (prop) =>
|
|
30685
|
-
var isFreeTextProperty = (prop) =>
|
|
30686
|
-
var isMultiSelectProperty = (prop) => prop.type === "array" ||
|
|
31236
|
+
var isQuestionProperty = (prop) => isRecord2(prop) && getEnumOptionSource(prop) !== null;
|
|
31237
|
+
var isFreeTextProperty = (prop) => isRecord2(prop) && prop.type === "string" && !Array.isArray(prop.oneOf) && !Array.isArray(prop.enum);
|
|
31238
|
+
var isMultiSelectProperty = (prop) => prop.type === "array" || isRecord2(prop.items);
|
|
30687
31239
|
var parseElicitationOptions = (source) => {
|
|
30688
31240
|
const options = [];
|
|
30689
31241
|
for (const entry of source) {
|
|
@@ -30702,9 +31254,9 @@ var parseElicitationOptions = (source) => {
|
|
|
30702
31254
|
return options;
|
|
30703
31255
|
};
|
|
30704
31256
|
function parseAskUserQuestionElicitationRequest(request) {
|
|
30705
|
-
if (!
|
|
31257
|
+
if (!isRecord2(request) || request.mode !== "form") return null;
|
|
30706
31258
|
const schema = request.requestedSchema;
|
|
30707
|
-
if (!
|
|
31259
|
+
if (!isRecord2(schema) || !isRecord2(schema.properties)) return null;
|
|
30708
31260
|
const properties = schema.properties;
|
|
30709
31261
|
const entries = Object.entries(properties);
|
|
30710
31262
|
const requestMeta = getLodyElicitationMeta(request._meta);
|
|
@@ -30712,9 +31264,9 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
30712
31264
|
const noteFieldKeyByQuestionId = /* @__PURE__ */ new Map();
|
|
30713
31265
|
const associatedFields = /* @__PURE__ */ new Set();
|
|
30714
31266
|
for (const [key, prop] of entries) {
|
|
30715
|
-
if (!
|
|
31267
|
+
if (!isRecord2(prop)) continue;
|
|
30716
31268
|
const rawMeta = getLodyMeta(prop._meta)?.elicitation;
|
|
30717
|
-
if (
|
|
31269
|
+
if (isRecord2(rawMeta) && rawMeta.noteFor !== void 0 && rawMeta.version !== 1) return null;
|
|
30718
31270
|
const meta3 = getLodyElicitationMeta(prop._meta);
|
|
30719
31271
|
if (!meta3 || meta3.noteFor === void 0 && meta3.customAnswerFor === void 0) continue;
|
|
30720
31272
|
if (meta3.noteFor !== void 0 && meta3.customAnswerFor !== void 0) return null;
|
|
@@ -30727,7 +31279,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
30727
31279
|
}
|
|
30728
31280
|
const isLodyForm = requestMeta !== null || associatedFields.size > 0;
|
|
30729
31281
|
const questionEntries = entries.filter(([key, prop]) => {
|
|
30730
|
-
if (!
|
|
31282
|
+
if (!isRecord2(prop) || associatedFields.has(key)) return false;
|
|
30731
31283
|
return isQuestionProperty(prop) || isLodyForm && isFreeTextProperty(prop);
|
|
30732
31284
|
});
|
|
30733
31285
|
if (questionEntries.length === 0) return null;
|
|
@@ -30737,13 +31289,13 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
30737
31289
|
}
|
|
30738
31290
|
if (associatedFields.size > 0 && questionEntries.some(([key]) => !key.trim())) return null;
|
|
30739
31291
|
const singleQuestion = questionEntries.length === 1;
|
|
30740
|
-
const allowCustomAnswer = isLodyForm ? questionEntries.some(([key, prop]) =>
|
|
31292
|
+
const allowCustomAnswer = isLodyForm ? questionEntries.some(([key, prop]) => isRecord2(prop) && (getEnumOptionSource(prop) === null || customFieldKeyByQuestionId.has(key))) : entries.some(([, prop]) => isFreeTextProperty(prop));
|
|
30741
31293
|
const message = typeof request.message === "string" ? request.message : "";
|
|
30742
31294
|
const questions = [];
|
|
30743
31295
|
const fieldKeys = [];
|
|
30744
31296
|
const customFieldKeys = [];
|
|
30745
31297
|
for (const [key, prop] of questionEntries) {
|
|
30746
|
-
if (!
|
|
31298
|
+
if (!isRecord2(prop)) continue;
|
|
30747
31299
|
const source = getEnumOptionSource(prop);
|
|
30748
31300
|
const header = typeof prop.title === "string" ? prop.title : "";
|
|
30749
31301
|
const description = typeof prop.description === "string" ? prop.description : "";
|
|
@@ -30758,7 +31310,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
30758
31310
|
multiSelect: isMultiSelectProperty(prop),
|
|
30759
31311
|
...isLodyForm ? { allowCustomAnswer: source === null || customFieldKeyByQuestionId.has(key) } : {},
|
|
30760
31312
|
...isLodyForm && getLodyElicitationMeta(prop._meta)?.secret === true ? { isSecret: true } : {},
|
|
30761
|
-
...noteFieldId !== void 0 &&
|
|
31313
|
+
...noteFieldId !== void 0 && isRecord2(noteProp) ? {
|
|
30762
31314
|
note: {
|
|
30763
31315
|
fieldId: noteFieldId,
|
|
30764
31316
|
...typeof noteProp.title === "string" ? { title: noteProp.title } : {},
|
|
@@ -30781,7 +31333,7 @@ function parseAskUserQuestionElicitationRequest(request) {
|
|
|
30781
31333
|
}
|
|
30782
31334
|
function buildAskUserQuestionElicitationResponse(elicitation, outcome) {
|
|
30783
31335
|
if (!outcome || outcome.outcome !== "selected" || outcome.optionId === "cancel") return { action: "cancel" };
|
|
30784
|
-
const answers = extractAskUserQuestionAnswersFromOutcome(elicitation.meta, { _meta:
|
|
31336
|
+
const answers = extractAskUserQuestionAnswersFromOutcome(elicitation.meta, { _meta: isRecord2(outcome._meta) ? outcome._meta : null });
|
|
30785
31337
|
if (!answers) return { action: "accept", content: {} };
|
|
30786
31338
|
const content = /* @__PURE__ */ Object.create(null);
|
|
30787
31339
|
elicitation.meta.questions.forEach((question, index) => {
|
|
@@ -30808,8 +31360,8 @@ function redactSecretAnswers(elicitation, outcome) {
|
|
|
30808
31360
|
if (question.note?.isSecret) secret.add(question.note.fieldId);
|
|
30809
31361
|
});
|
|
30810
31362
|
const lody = getLodyMeta(outcome._meta);
|
|
30811
|
-
const elicitationMeta = lody &&
|
|
30812
|
-
if (!secret.size || !elicitationMeta || !
|
|
31363
|
+
const elicitationMeta = lody && isRecord2(lody.elicitation) ? lody.elicitation : null;
|
|
31364
|
+
if (!secret.size || !elicitationMeta || !isRecord2(elicitationMeta.answers)) return outcome;
|
|
30813
31365
|
const answers = Object.fromEntries(Object.entries(elicitationMeta.answers).map(([key, value]) => [key, secret.has(key) ? "[redacted]" : value]));
|
|
30814
31366
|
return { ...outcome, _meta: { ...outcome._meta, lody: { ...lody, elicitation: { ...elicitationMeta, answers } } } };
|
|
30815
31367
|
}
|
|
@@ -31235,8 +31787,10 @@ var AcpChatSession = class {
|
|
|
31235
31787
|
*/
|
|
31236
31788
|
forwardsPermission(params, prompts) {
|
|
31237
31789
|
if (isAskUserQuestionPermission(params)) return true;
|
|
31790
|
+
const call = record4(params.toolCall);
|
|
31791
|
+
if (typeof call.toolCallId === "string" && call.toolCallId.startsWith("interaction_")) return true;
|
|
31238
31792
|
if (prompts.permissions === "none") return false;
|
|
31239
|
-
const title =
|
|
31793
|
+
const title = call.title;
|
|
31240
31794
|
if (ECHO_CALLBACK.test(typeof title === "string" ? title : "")) return false;
|
|
31241
31795
|
if (prompts.permissions === "all") return true;
|
|
31242
31796
|
return !permissionAllowed(params, { permissionMode: "full", access: "acceptEdits" });
|
|
@@ -31544,12 +32098,12 @@ var MemoryBindingSchema = external_exports.object({
|
|
|
31544
32098
|
memory_id: external_exports.string().trim().min(1).max(200)
|
|
31545
32099
|
});
|
|
31546
32100
|
var COMMAND_TIMEOUT_MS = 15e3;
|
|
31547
|
-
var
|
|
32101
|
+
var MAX_OUTPUT_BYTES2 = 1024 * 1024;
|
|
31548
32102
|
var runNmem = (args) => {
|
|
31549
32103
|
const env = providerEnvironment();
|
|
31550
32104
|
const launch = resolveExecutable("nmem", args, env, process.env.TOC_OCRA_NMEM_PATH);
|
|
31551
32105
|
return new Promise((resolve10) => {
|
|
31552
|
-
execFile7(launch.executable, launch.args, { env: launch.env, timeout: COMMAND_TIMEOUT_MS, maxBuffer:
|
|
32106
|
+
execFile7(launch.executable, launch.args, { env: launch.env, timeout: COMMAND_TIMEOUT_MS, maxBuffer: MAX_OUTPUT_BYTES2, windowsHide: true }, (error62, stdout) => {
|
|
31553
32107
|
if (!error62) {
|
|
31554
32108
|
resolve10({ stdout: String(stdout) });
|
|
31555
32109
|
return;
|
|
@@ -31988,7 +32542,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31988
32542
|
if (!fitsCommandLine(launch)) return refuse(cliFailure("promptTooLong", { label: cli.label }));
|
|
31989
32543
|
let child;
|
|
31990
32544
|
try {
|
|
31991
|
-
child =
|
|
32545
|
+
child = spawn12(launch.executable, launch.args, {
|
|
31992
32546
|
cwd: workdir,
|
|
31993
32547
|
env: Object.keys(memoryEnv).length ? { ...launch.env, ...memoryEnv } : launch.env,
|
|
31994
32548
|
detached: currentPlatform.runsInOwnProcessGroup,
|
|
@@ -32527,12 +33081,12 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
32527
33081
|
async prepareChatAttachments(payload) {
|
|
32528
33082
|
if (!payload.attachments?.length) return [];
|
|
32529
33083
|
if (!this.reporter.chatMedia) throw new Error("\u9644\u4EF6\u8F6C\u53D1\u672A\u914D\u7F6E");
|
|
32530
|
-
const directory =
|
|
33084
|
+
const directory = join21(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
|
|
32531
33085
|
await mkdir7(directory, { recursive: true, mode: 448 });
|
|
32532
33086
|
const files = [];
|
|
32533
33087
|
for (const attachment of payload.attachments) {
|
|
32534
33088
|
const name = basename2(attachment.name).replace(/[^\p{L}\p{N}._-]/gu, "_").slice(-120) || "attachment";
|
|
32535
|
-
const path =
|
|
33089
|
+
const path = join21(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
|
|
32536
33090
|
const existing = await stat5(path).catch(() => void 0);
|
|
32537
33091
|
if (!existing?.isFile()) {
|
|
32538
33092
|
const data = await this.reporter.chatMedia(payload.run_id, attachment.media_id);
|
|
@@ -32733,7 +33287,7 @@ var silent = { debug() {
|
|
|
32733
33287
|
async function runCliSmoke(options = {}) {
|
|
32734
33288
|
const detection = await cliDetection.detect(true);
|
|
32735
33289
|
const ids = options.only?.length ? options.only.map((id) => catalogEntry(id)?.id ?? id) : CLI_CATALOG.filter((entry) => entry.headless && detection.detectedIds.includes(entry.id)).map((entry) => entry.id);
|
|
32736
|
-
const root2 = await realpath3(await mkdtemp2(
|
|
33290
|
+
const root2 = await realpath3(await mkdtemp2(join22(tmpdir3(), "toc-ocra-smoke-")));
|
|
32737
33291
|
const finished = /* @__PURE__ */ new Map();
|
|
32738
33292
|
const config2 = { allowedRoots: [root2], maxConcurrentRuns: 0, maxRunSeconds: options.timeoutSeconds ?? 300, dataDir: root2 };
|
|
32739
33293
|
const supervisor = new RunSupervisor(config2, silent, {
|
|
@@ -32805,7 +33359,7 @@ async function runCliSmoke(options = {}) {
|
|
|
32805
33359
|
}
|
|
32806
33360
|
|
|
32807
33361
|
// src/runtime/run-service.ts
|
|
32808
|
-
import { existsSync as existsSync7, readFileSync as
|
|
33362
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
|
|
32809
33363
|
import { dirname as dirname10, resolve as resolve8 } from "node:path";
|
|
32810
33364
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
32811
33365
|
|
|
@@ -33050,7 +33604,7 @@ import {
|
|
|
33050
33604
|
chmodSync,
|
|
33051
33605
|
existsSync as existsSync6,
|
|
33052
33606
|
mkdirSync as mkdirSync3,
|
|
33053
|
-
readFileSync as
|
|
33607
|
+
readFileSync as readFileSync7,
|
|
33054
33608
|
renameSync,
|
|
33055
33609
|
statSync as statSync4,
|
|
33056
33610
|
unlinkSync,
|
|
@@ -33108,7 +33662,7 @@ function createDiagnosticLogger(filePath, options = {}) {
|
|
|
33108
33662
|
for (let index = 0; index <= maxRotatedFiles; index += 1) {
|
|
33109
33663
|
const path = index === 0 ? filePath : `${filePath}.${index}`;
|
|
33110
33664
|
if (!existsSync6(path)) continue;
|
|
33111
|
-
const kept =
|
|
33665
|
+
const kept = readFileSync7(path, "utf8").split("\n").filter((line) => {
|
|
33112
33666
|
if (!line.trim()) return false;
|
|
33113
33667
|
try {
|
|
33114
33668
|
const timestamp = Date.parse(JSON.parse(line).ts);
|
|
@@ -33168,10 +33722,10 @@ function createDiagnosticLogger(filePath, options = {}) {
|
|
|
33168
33722
|
|
|
33169
33723
|
// src/runtime/agent-runtime.ts
|
|
33170
33724
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
33171
|
-
import { join as
|
|
33725
|
+
import { join as join25 } from "node:path";
|
|
33172
33726
|
|
|
33173
33727
|
// src/exec/script-runner.ts
|
|
33174
|
-
import { spawn as
|
|
33728
|
+
import { spawn as spawn13 } from "node:child_process";
|
|
33175
33729
|
var MAX_SCRIPT_OUTPUT_BYTES = 112 * 1024;
|
|
33176
33730
|
function executeScript(command, workdir, timeoutSeconds) {
|
|
33177
33731
|
return new Promise((resolveExecution) => {
|
|
@@ -33202,7 +33756,7 @@ function executeScript(command, workdir, timeoutSeconds) {
|
|
|
33202
33756
|
};
|
|
33203
33757
|
let child;
|
|
33204
33758
|
try {
|
|
33205
|
-
child =
|
|
33759
|
+
child = spawn13(executable, args, {
|
|
33206
33760
|
cwd: workdir,
|
|
33207
33761
|
env: process.env,
|
|
33208
33762
|
detached: ownGroup,
|
|
@@ -33340,15 +33894,15 @@ async function readCLIQuotaReport(agentType) {
|
|
|
33340
33894
|
|
|
33341
33895
|
// src/providers/tb-switch-control.ts
|
|
33342
33896
|
import { readFile as readFile9 } from "node:fs/promises";
|
|
33343
|
-
import { homedir as
|
|
33344
|
-
import { join as
|
|
33897
|
+
import { homedir as homedir13 } from "node:os";
|
|
33898
|
+
import { join as join23 } from "node:path";
|
|
33345
33899
|
function dataDir() {
|
|
33346
|
-
return process.env.TB_SWITCH_HOME?.trim() ||
|
|
33900
|
+
return process.env.TB_SWITCH_HOME?.trim() || join23(homedir13(), ".tb-switch");
|
|
33347
33901
|
}
|
|
33348
33902
|
async function readLocalService() {
|
|
33349
33903
|
let discovery;
|
|
33350
33904
|
try {
|
|
33351
|
-
discovery = JSON.parse(await readFile9(
|
|
33905
|
+
discovery = JSON.parse(await readFile9(join23(dataDir(), "api.json"), "utf8"));
|
|
33352
33906
|
} catch {
|
|
33353
33907
|
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");
|
|
33354
33908
|
}
|
|
@@ -33364,7 +33918,7 @@ async function readLocalService() {
|
|
|
33364
33918
|
}
|
|
33365
33919
|
let token = process.env.TB_SWITCH_API_TOKEN?.trim() ?? "";
|
|
33366
33920
|
try {
|
|
33367
|
-
token = (await readFile9(
|
|
33921
|
+
token = (await readFile9(join23(dataDir(), "api-token"), "utf8")).trim();
|
|
33368
33922
|
} catch {
|
|
33369
33923
|
}
|
|
33370
33924
|
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");
|
|
@@ -33636,11 +34190,11 @@ var GatewayClient = class {
|
|
|
33636
34190
|
|
|
33637
34191
|
// src/workspace/directory-browser.ts
|
|
33638
34192
|
import { mkdir as mkdir9, readdir as readdir4, realpath as realpath4, stat as stat7 } from "node:fs/promises";
|
|
33639
|
-
import { homedir as
|
|
34193
|
+
import { homedir as homedir14 } from "node:os";
|
|
33640
34194
|
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
33641
34195
|
var MAX_ENTRIES = 1e3;
|
|
33642
34196
|
async function listDirectory(requested, allowedRoots) {
|
|
33643
|
-
const raw = requested.trim().replace(/^~(?=$|[\\/])/,
|
|
34197
|
+
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir14()) || homedir14();
|
|
33644
34198
|
const directory = await realpath4(resolve6(raw)).catch(() => {
|
|
33645
34199
|
throw new Error(`\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${requested}`);
|
|
33646
34200
|
});
|
|
@@ -33658,8 +34212,8 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
33658
34212
|
else if (entry.isFile()) files.push(item);
|
|
33659
34213
|
}
|
|
33660
34214
|
const parent = dirname9(directory);
|
|
33661
|
-
const places = [{ label: "\u4E3B\u76EE\u5F55", path:
|
|
33662
|
-
for (const root2 of allowedRoots) if (root2 !==
|
|
34215
|
+
const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir14() }];
|
|
34216
|
+
for (const root2 of allowedRoots) if (root2 !== homedir14()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root2 });
|
|
33663
34217
|
places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
|
|
33664
34218
|
return {
|
|
33665
34219
|
path: directory,
|
|
@@ -33695,9 +34249,9 @@ async function createDirectory(parentRequested, name) {
|
|
|
33695
34249
|
}
|
|
33696
34250
|
|
|
33697
34251
|
// src/workspace/workspace-manager.ts
|
|
33698
|
-
import { spawn as
|
|
34252
|
+
import { spawn as spawn14 } from "node:child_process";
|
|
33699
34253
|
import { opendir, realpath as realpath5, stat as stat8 } from "node:fs/promises";
|
|
33700
|
-
import { homedir as
|
|
34254
|
+
import { homedir as homedir15 } from "node:os";
|
|
33701
34255
|
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
33702
34256
|
var MAX_NODES = 2e3;
|
|
33703
34257
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
@@ -33733,7 +34287,7 @@ var WorkspaceManager = class {
|
|
|
33733
34287
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
33734
34288
|
}
|
|
33735
34289
|
validateRootPath(value) {
|
|
33736
|
-
const raw = value.trim().replace(/^~(?=$|[\\/])/,
|
|
34290
|
+
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir15());
|
|
33737
34291
|
const root2 = resolve7(raw);
|
|
33738
34292
|
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
33739
34293
|
if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
|
|
@@ -33859,7 +34413,7 @@ var WorkspaceManager = class {
|
|
|
33859
34413
|
}
|
|
33860
34414
|
runGit(args, cwd, timeoutSeconds, allowFailure = false) {
|
|
33861
34415
|
return new Promise((resolveCommand, rejectCommand) => {
|
|
33862
|
-
const child =
|
|
34416
|
+
const child = spawn14("git", args, {
|
|
33863
34417
|
cwd,
|
|
33864
34418
|
env: process.env,
|
|
33865
34419
|
shell: false,
|
|
@@ -34073,7 +34627,7 @@ var AgentRuntime = class {
|
|
|
34073
34627
|
}
|
|
34074
34628
|
};
|
|
34075
34629
|
this.workspaces = new WorkspaceManager(config2, this.logger);
|
|
34076
|
-
this.orphans = new OrphanRegistry(
|
|
34630
|
+
this.orphans = new OrphanRegistry(join25(config2.dataDir, "active-runs.json"));
|
|
34077
34631
|
this.runs = new RunSupervisor(config2, this.logger, reporter, this.orphans);
|
|
34078
34632
|
}
|
|
34079
34633
|
config;
|
|
@@ -34785,7 +35339,7 @@ function agentPackageRoot() {
|
|
|
34785
35339
|
const packagePath = resolve8(directory, "package.json");
|
|
34786
35340
|
if (existsSync7(packagePath)) {
|
|
34787
35341
|
try {
|
|
34788
|
-
const info = JSON.parse(
|
|
35342
|
+
const info = JSON.parse(readFileSync8(packagePath, "utf8"));
|
|
34789
35343
|
if (info.name === PACKAGE_NAME && typeof info.version === "string") return directory;
|
|
34790
35344
|
} catch {
|
|
34791
35345
|
}
|
|
@@ -34797,7 +35351,7 @@ function agentPackageRoot() {
|
|
|
34797
35351
|
}
|
|
34798
35352
|
function agentVersion() {
|
|
34799
35353
|
const root2 = agentPackageRoot();
|
|
34800
|
-
return root2 ? JSON.parse(
|
|
35354
|
+
return root2 ? JSON.parse(readFileSync8(resolve8(root2, "package.json"), "utf8")).version : "unknown";
|
|
34801
35355
|
}
|
|
34802
35356
|
async function runService(options = {}) {
|
|
34803
35357
|
const version2 = agentVersion();
|
|
@@ -34846,7 +35400,7 @@ async function runService(options = {}) {
|
|
|
34846
35400
|
}
|
|
34847
35401
|
|
|
34848
35402
|
// src/index.ts
|
|
34849
|
-
var { currentInstallation, installShared, ensureIdle, compareVersions: compareVersions2 } = createRequire(import.meta.url)(
|
|
35403
|
+
var { currentInstallation, installShared, ensureIdle, compareVersions: compareVersions2 } = createRequire(import.meta.url)(join26(agentPackageRoot(), "scripts", "installation.cjs"));
|
|
34850
35404
|
async function run() {
|
|
34851
35405
|
try {
|
|
34852
35406
|
await runService();
|
|
@@ -34973,7 +35527,7 @@ async function update(args) {
|
|
|
34973
35527
|
if (customConfig) process.env.TOC_OCRA_CONFIG = resolve9(customConfig);
|
|
34974
35528
|
await ensureIdle();
|
|
34975
35529
|
const npmPath = resolveCliCommand("npm");
|
|
34976
|
-
const temporary = mkdtempSync(
|
|
35530
|
+
const temporary = mkdtempSync(join26(tmpdir4(), "toc-ocra-update-"));
|
|
34977
35531
|
try {
|
|
34978
35532
|
const metadataResponse = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`, { headers: { accept: "application/json", "cache-control": "no-cache" }, signal: AbortSignal.timeout(15e3) });
|
|
34979
35533
|
if (!metadataResponse.ok) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 npm \u6700\u65B0\u7248\u672C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
@@ -35000,7 +35554,7 @@ async function update(args) {
|
|
|
35000
35554
|
}
|
|
35001
35555
|
const archive = Buffer.concat(chunks);
|
|
35002
35556
|
if (`sha512-${createHash5("sha512").update(archive).digest("base64")}` !== dist.integrity) throw new Error("\u8BBE\u5907\u4EE3\u7406\u5B89\u88C5\u5305\u6821\u9A8C\u5931\u8D25\uFF0C\u5DF2\u505C\u6B62\u5347\u7EA7");
|
|
35003
|
-
const archivePath =
|
|
35557
|
+
const archivePath = join26(temporary, "toc-ocra.tgz");
|
|
35004
35558
|
writeFileSync3(archivePath, archive, { mode: 384 });
|
|
35005
35559
|
const npm = directLaunch2(npmPath, ["install", "--prefix", temporary, "--ignore-scripts", "--omit=dev", "--no-package-lock", "--no-audit", "--no-fund", "--prefer-online", "--registry=https://registry.npmjs.org", archivePath]);
|
|
35006
35560
|
const install = spawnSync(npm.executable, npm.args, { stdio: "inherit", shell: false, windowsHide: true });
|
|
@@ -35010,7 +35564,7 @@ async function update(args) {
|
|
|
35010
35564
|
return;
|
|
35011
35565
|
}
|
|
35012
35566
|
const previousVersion = agentVersion();
|
|
35013
|
-
const current = await installShared(
|
|
35567
|
+
const current = await installShared(join26(temporary, "node_modules", PACKAGE_NAME), { startService: existsSync8(defaultConfigPath()) });
|
|
35014
35568
|
if (current.version === previousVersion) process.stdout.write(`toc-ocra \u5DF2\u662F\u6700\u65B0\u7248\u672C ${current.version}
|
|
35015
35569
|
`);
|
|
35016
35570
|
else process.stdout.write(`toc-ocra \u5DF2\u5347\u7EA7\u5230 ${current.version}\uFF0C\u7EC8\u7AEF\u4E0E Echo \u63D2\u4EF6\u5171\u7528\u6B64\u7248\u672C
|
|
@@ -35038,7 +35592,7 @@ async function main() {
|
|
|
35038
35592
|
const selected = !shared || compareVersions2(agentVersion(), shared.version) > 0 ? await installShared(root2) : shared;
|
|
35039
35593
|
const same = (a, b) => process.platform === "win32" ? resolve9(a).toLowerCase() === resolve9(b).toLowerCase() : resolve9(a) === resolve9(b);
|
|
35040
35594
|
if (!same(selected.root, root2)) {
|
|
35041
|
-
await import(pathToFileURL2(
|
|
35595
|
+
await import(pathToFileURL2(join26(selected.root, "dist", "cli", "cli.mjs")).href);
|
|
35042
35596
|
return;
|
|
35043
35597
|
}
|
|
35044
35598
|
}
|