toc-ocra 0.3.22 → 0.3.24
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/dist/cli/cli.mjs +252 -44
- package/dist/service/agent.mjs +252 -44
- package/dist/src/acp/chat-agents.js +2 -1
- package/dist/src/acp/chat-agents.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/antigravity-quota.js +2 -2
- package/dist/src/providers/antigravity-quota.js.map +1 -1
- package/dist/src/providers/claude-quota.d.ts +9 -0
- package/dist/src/providers/claude-quota.js +168 -25
- package/dist/src/providers/claude-quota.js.map +1 -1
- package/dist/src/providers/model-catalog.d.ts +1 -1
- package/dist/src/providers/model-catalog.js +6 -6
- package/dist/src/providers/model-catalog.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
|
@@ -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 spawn11 } 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 [];
|
|
@@ -25993,7 +26085,7 @@ function cliExecutable(id) {
|
|
|
25993
26085
|
const spec = requireCliSpec(id);
|
|
25994
26086
|
return process.env[spec.overrideEnv]?.trim() || resolveCliCommand(cliCommand(spec));
|
|
25995
26087
|
}
|
|
25996
|
-
function runModelListCommand(executable, args, label, environment) {
|
|
26088
|
+
function runModelListCommand(executable, args, label, environment, timeoutMs = MODEL_LIST_TIMEOUT_MS) {
|
|
25997
26089
|
return new Promise((resolve10, reject) => {
|
|
25998
26090
|
const launch = directLaunch2(executable, args);
|
|
25999
26091
|
const child = spawn5(launch.executable, launch.args, { shell: false, windowsHide: true, ...environment ? { env: environment } : {}, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -26002,7 +26094,7 @@ function runModelListCommand(executable, args, label, environment) {
|
|
|
26002
26094
|
const timer = setTimeout(() => {
|
|
26003
26095
|
child.kill("SIGKILL");
|
|
26004
26096
|
reject(new Error(`${label} \u8BFB\u53D6\u6A21\u578B\u5217\u8868\u8D85\u65F6`));
|
|
26005
|
-
},
|
|
26097
|
+
}, timeoutMs);
|
|
26006
26098
|
child.stdout.setEncoding("utf8");
|
|
26007
26099
|
child.stderr.setEncoding("utf8");
|
|
26008
26100
|
child.stdout.on("data", (chunk) => {
|
|
@@ -26036,7 +26128,7 @@ function withKnownEfforts(base, known) {
|
|
|
26036
26128
|
};
|
|
26037
26129
|
}
|
|
26038
26130
|
async function readKiroModelCatalog(options = {}) {
|
|
26039
|
-
const environment =
|
|
26131
|
+
const environment = await hydrateRuntimeProxy(providerEnvironment());
|
|
26040
26132
|
const kiro = requireCliSpec("kiro");
|
|
26041
26133
|
await requireKiroAuthentication(environment, { force: options.force === true });
|
|
26042
26134
|
const listLaunch = launchCli({ spec: kiro, args: ["chat", "--list-models", "--format", "json"], env: environment });
|
|
@@ -26287,12 +26379,12 @@ function parseAntigravityModelCatalog(output2, settingsContent = "", fetchedAt =
|
|
|
26287
26379
|
};
|
|
26288
26380
|
}
|
|
26289
26381
|
async function readAntigravityModelCatalog() {
|
|
26290
|
-
const baseEnv =
|
|
26382
|
+
const baseEnv = await hydrateRuntimeProxy(providerEnvironment());
|
|
26291
26383
|
const env = scrubAntigravityEnv(baseEnv);
|
|
26292
26384
|
const spec = requireCliSpec("antigravity");
|
|
26293
26385
|
const launch = launchCli({ spec, args: ["models"], env });
|
|
26294
26386
|
const [output2, settings] = await Promise.all([
|
|
26295
|
-
runModelListCommand(launch.executable, launch.args, "agy", launch.env ?? env),
|
|
26387
|
+
runModelListCommand(launch.executable, launch.args, "agy", launch.env ?? env, 3e4),
|
|
26296
26388
|
readFile3(join11(antigravityHome(), "settings.json"), "utf8").catch(() => "")
|
|
26297
26389
|
]);
|
|
26298
26390
|
const catalog = parseAntigravityModelCatalog(output2, settings);
|
|
@@ -27163,7 +27255,7 @@ function chatSpec(row) {
|
|
|
27163
27255
|
async launch({ access, model, reasoningEffort, workdir, dataDir: dataDir2 }) {
|
|
27164
27256
|
if (row.adapter) return row.adapter({ access, model, reasoningEffort, workdir, dataDir: dataDir2 });
|
|
27165
27257
|
const args = row.args({ access, model, reasoningEffort });
|
|
27166
|
-
const baseEnv = { ...providerEnvironment(), ...row.env };
|
|
27258
|
+
const baseEnv = { ...await hydrateRuntimeProxy(providerEnvironment()), ...row.env };
|
|
27167
27259
|
const env = row.scrubEnv ? row.scrubEnv(baseEnv) : baseEnv;
|
|
27168
27260
|
const spec = launchCli({ spec: cli, args, env });
|
|
27169
27261
|
return { launch: { executable: spec.executable, args: spec.args, env: spec.env, cwd: workdir }, fingerprint: args.join(" ") };
|
|
@@ -29517,7 +29609,7 @@ async function readAntigravityQuotaWindows() {
|
|
|
29517
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");
|
|
29518
29610
|
}
|
|
29519
29611
|
const spec = requireCliSpec("antigravity");
|
|
29520
|
-
const baseEnv =
|
|
29612
|
+
const baseEnv = await hydrateRuntimeProxy(providerEnvironment());
|
|
29521
29613
|
const env = scrubAntigravityEnv(baseEnv);
|
|
29522
29614
|
const versionLaunch = launchCli({ spec, args: ["--version"], env });
|
|
29523
29615
|
const versionRun = await runCommand(versionLaunch.executable, versionLaunch.args, versionLaunch.env ?? env, VERSION_TIMEOUT_MS).catch((error62) => {
|
|
@@ -29554,13 +29646,15 @@ ${result.stderr}`, result.stderr);
|
|
|
29554
29646
|
}
|
|
29555
29647
|
|
|
29556
29648
|
// src/providers/claude-quota.ts
|
|
29557
|
-
import { execFile as execFile5 } from "node:child_process";
|
|
29649
|
+
import { execFile as execFile5, spawn as spawn9 } from "node:child_process";
|
|
29558
29650
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
29559
29651
|
import { homedir as homedir11 } from "node:os";
|
|
29560
29652
|
import { join as join17 } from "node:path";
|
|
29561
29653
|
import { promisify as promisify3 } from "node:util";
|
|
29562
29654
|
var execFileAsync3 = promisify3(execFile5);
|
|
29563
29655
|
var CLAUDE_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
29656
|
+
var CLAUDE_USAGE_USER_AGENT = "claude-code/2.1.0";
|
|
29657
|
+
var REFRESH_TIMEOUT_MS = 25e3;
|
|
29564
29658
|
var WINDOWS = [
|
|
29565
29659
|
{ key: "five_hour", label: "5 \u5C0F\u65F6\u989D\u5EA6", seconds: 5 * 3600 },
|
|
29566
29660
|
{ key: "seven_day", label: "\u6BCF\u5468\u989D\u5EA6", seconds: 7 * 86400 },
|
|
@@ -29578,6 +29672,12 @@ function resetSeconds(value) {
|
|
|
29578
29672
|
}
|
|
29579
29673
|
return 0;
|
|
29580
29674
|
}
|
|
29675
|
+
function epochMs(value) {
|
|
29676
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) {
|
|
29677
|
+
return value > 1e10 ? value : value * 1e3;
|
|
29678
|
+
}
|
|
29679
|
+
return void 0;
|
|
29680
|
+
}
|
|
29581
29681
|
function parseClaudeQuota(body) {
|
|
29582
29682
|
const source = objectValue2(body);
|
|
29583
29683
|
const windows = [];
|
|
@@ -29597,44 +29697,152 @@ function parseClaudeQuota(body) {
|
|
|
29597
29697
|
return windows;
|
|
29598
29698
|
}
|
|
29599
29699
|
var claudeHome2 = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join17(homedir11(), ".claude");
|
|
29600
|
-
function
|
|
29700
|
+
function parseClaudeCredentialsJson(content, source) {
|
|
29701
|
+
const trimmed = content.trim();
|
|
29702
|
+
if (!trimmed) return void 0;
|
|
29601
29703
|
try {
|
|
29602
|
-
const
|
|
29603
|
-
|
|
29704
|
+
const parsed = objectValue2(JSON.parse(trimmed));
|
|
29705
|
+
const oauth = Object.keys(objectValue2(parsed.claudeAiOauth)).length ? objectValue2(parsed.claudeAiOauth) : parsed;
|
|
29706
|
+
const accessToken = typeof oauth.accessToken === "string" ? oauth.accessToken.trim() : "";
|
|
29707
|
+
if (!accessToken) return void 0;
|
|
29708
|
+
const refreshToken = typeof oauth.refreshToken === "string" && oauth.refreshToken.trim() ? oauth.refreshToken.trim() : void 0;
|
|
29709
|
+
const expiresAt = epochMs(oauth.expiresAt);
|
|
29710
|
+
const refreshTokenExpiresAt = epochMs(oauth.refreshTokenExpiresAt);
|
|
29711
|
+
return {
|
|
29712
|
+
accessToken,
|
|
29713
|
+
...refreshToken ? { refreshToken } : {},
|
|
29714
|
+
...expiresAt !== void 0 ? { expiresAt } : {},
|
|
29715
|
+
...refreshTokenExpiresAt !== void 0 ? { refreshTokenExpiresAt } : {},
|
|
29716
|
+
source
|
|
29717
|
+
};
|
|
29604
29718
|
} catch {
|
|
29605
|
-
return void 0;
|
|
29719
|
+
return source === "env" ? { accessToken: trimmed, source } : void 0;
|
|
29606
29720
|
}
|
|
29607
29721
|
}
|
|
29608
|
-
|
|
29722
|
+
function isClaudeCredentialsRefreshable(creds, now = Date.now()) {
|
|
29723
|
+
if (!creds.refreshToken) return false;
|
|
29724
|
+
if (creds.refreshTokenExpiresAt !== void 0 && creds.refreshTokenExpiresAt <= now) return false;
|
|
29725
|
+
return true;
|
|
29726
|
+
}
|
|
29727
|
+
async function readClaudeCredentialCandidates() {
|
|
29728
|
+
const candidates = [];
|
|
29729
|
+
const push = (creds) => {
|
|
29730
|
+
if (!creds) return;
|
|
29731
|
+
if (!candidates.some((item) => item.accessToken === creds.accessToken)) candidates.push(creds);
|
|
29732
|
+
};
|
|
29609
29733
|
const fromEnv = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
29610
|
-
if (fromEnv)
|
|
29611
|
-
|
|
29612
|
-
|
|
29613
|
-
|
|
29614
|
-
|
|
29615
|
-
|
|
29734
|
+
if (fromEnv) push(parseClaudeCredentialsJson(fromEnv, "env"));
|
|
29735
|
+
if (process.platform === "darwin") {
|
|
29736
|
+
const { stdout } = await execFileAsync3("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 1e4 }).catch(() => ({ stdout: "" }));
|
|
29737
|
+
push(parseClaudeCredentialsJson(String(stdout).trim(), "keychain"));
|
|
29738
|
+
}
|
|
29739
|
+
const fileContent = await readFile5(join17(claudeHome2(), ".credentials.json"), "utf8").catch(() => "");
|
|
29740
|
+
push(parseClaudeCredentialsJson(fileContent, "credentials-file"));
|
|
29741
|
+
return candidates;
|
|
29616
29742
|
}
|
|
29617
|
-
|
|
29618
|
-
|
|
29619
|
-
|
|
29743
|
+
function runQuietCli(executable, args, env, timeoutMs) {
|
|
29744
|
+
return new Promise((resolve10) => {
|
|
29745
|
+
const child = spawn9(executable, [...args], { env, stdio: "ignore", shell: false, windowsHide: true });
|
|
29746
|
+
let settled = false;
|
|
29747
|
+
const done = () => {
|
|
29748
|
+
if (settled) return;
|
|
29749
|
+
settled = true;
|
|
29750
|
+
clearTimeout(timer);
|
|
29751
|
+
resolve10();
|
|
29752
|
+
};
|
|
29753
|
+
const timer = setTimeout(() => {
|
|
29754
|
+
try {
|
|
29755
|
+
child.kill("SIGKILL");
|
|
29756
|
+
} catch {
|
|
29757
|
+
}
|
|
29758
|
+
done();
|
|
29759
|
+
}, timeoutMs);
|
|
29760
|
+
child.once("error", done);
|
|
29761
|
+
child.once("close", done);
|
|
29762
|
+
});
|
|
29763
|
+
}
|
|
29764
|
+
var inFlightRefresh = null;
|
|
29765
|
+
async function refreshClaudeTokenViaCli(previousToken, env) {
|
|
29766
|
+
if (inFlightRefresh) {
|
|
29767
|
+
await inFlightRefresh;
|
|
29768
|
+
const after = await readClaudeCredentialCandidates();
|
|
29769
|
+
return after.find((item) => item.accessToken !== previousToken);
|
|
29770
|
+
}
|
|
29771
|
+
const spec = requireCliSpec("claude");
|
|
29772
|
+
const run2 = async () => {
|
|
29773
|
+
const statusLaunch = launchCli({ spec, args: ["auth", "status"], env });
|
|
29774
|
+
await runQuietCli(statusLaunch.executable, statusLaunch.args, statusLaunch.env ?? env, 15e3);
|
|
29775
|
+
let updated = (await readClaudeCredentialCandidates()).find((item) => item.accessToken !== previousToken);
|
|
29776
|
+
if (updated) return updated;
|
|
29777
|
+
const pingLaunch = launchCli({
|
|
29778
|
+
spec,
|
|
29779
|
+
args: ["-p", "ok", "--model", "haiku", "--no-session-persistence", "--tools", ""],
|
|
29780
|
+
env
|
|
29781
|
+
});
|
|
29782
|
+
await runQuietCli(pingLaunch.executable, pingLaunch.args, pingLaunch.env ?? env, REFRESH_TIMEOUT_MS);
|
|
29783
|
+
updated = (await readClaudeCredentialCandidates()).find((item) => item.accessToken !== previousToken);
|
|
29784
|
+
return updated;
|
|
29785
|
+
};
|
|
29786
|
+
let refreshed;
|
|
29787
|
+
inFlightRefresh = run2().then((result) => {
|
|
29788
|
+
refreshed = result;
|
|
29789
|
+
}).finally(() => {
|
|
29790
|
+
inFlightRefresh = null;
|
|
29791
|
+
});
|
|
29792
|
+
await inFlightRefresh;
|
|
29793
|
+
return refreshed;
|
|
29794
|
+
}
|
|
29795
|
+
async function fetchUsage(token) {
|
|
29620
29796
|
const response = await fetch(CLAUDE_USAGE_URL, {
|
|
29621
|
-
headers: {
|
|
29797
|
+
headers: {
|
|
29798
|
+
authorization: `Bearer ${token}`,
|
|
29799
|
+
"anthropic-beta": "oauth-2025-04-20",
|
|
29800
|
+
"user-agent": CLAUDE_USAGE_USER_AGENT,
|
|
29801
|
+
accept: "application/json"
|
|
29802
|
+
},
|
|
29622
29803
|
redirect: "error",
|
|
29623
29804
|
signal: AbortSignal.timeout(15e3)
|
|
29624
29805
|
});
|
|
29625
|
-
if (response.status === 401 || response.status === 403)
|
|
29626
|
-
if (
|
|
29806
|
+
if (response.status === 401 || response.status === 403) return { kind: "auth", status: response.status };
|
|
29807
|
+
if (response.status === 429) return { kind: "error", message: "Claude \u989D\u5EA6\u63A5\u53E3\u6682\u65F6\u9650\u6D41\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5" };
|
|
29808
|
+
if (!response.ok) return { kind: "error", message: `Claude \u989D\u5EA6\u63A5\u53E3\u8BF7\u6C42\u5931\u8D25 (${response.status})` };
|
|
29627
29809
|
const windows = parseClaudeQuota(await response.json());
|
|
29628
|
-
if (!windows.length)
|
|
29629
|
-
return windows;
|
|
29810
|
+
if (!windows.length) return { kind: "error", message: "Claude \u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u7684\u989D\u5EA6\u7A97\u53E3" };
|
|
29811
|
+
return { kind: "ok", windows };
|
|
29812
|
+
}
|
|
29813
|
+
async function readClaudeQuotaWindows() {
|
|
29814
|
+
const env = await hydrateRuntimeProxy(providerEnvironment());
|
|
29815
|
+
const candidates = await readClaudeCredentialCandidates();
|
|
29816
|
+
if (!candidates.length) {
|
|
29817
|
+
throw new Error("Claude Code \u672A\u4F7F\u7528 Claude \u8D26\u53F7\u767B\u5F55\uFF08API Key \u65B9\u5F0F\u6CA1\u6709\u5957\u9910\u989D\u5EA6\uFF09\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C claude \u5E76 /login");
|
|
29818
|
+
}
|
|
29819
|
+
let sawRefreshable = false;
|
|
29820
|
+
let lastAuthToken = "";
|
|
29821
|
+
for (const creds of candidates) {
|
|
29822
|
+
if (isClaudeCredentialsRefreshable(creds)) sawRefreshable = true;
|
|
29823
|
+
const result = await fetchUsage(creds.accessToken);
|
|
29824
|
+
if (result.kind === "ok") return result.windows;
|
|
29825
|
+
if (result.kind === "error") throw new Error(result.message);
|
|
29826
|
+
lastAuthToken = creds.accessToken;
|
|
29827
|
+
}
|
|
29828
|
+
if (sawRefreshable && lastAuthToken) {
|
|
29829
|
+
const refreshed = await refreshClaudeTokenViaCli(lastAuthToken, env).catch(() => void 0);
|
|
29830
|
+
if (refreshed) {
|
|
29831
|
+
const retry = await fetchUsage(refreshed.accessToken);
|
|
29832
|
+
if (retry.kind === "ok") return retry.windows;
|
|
29833
|
+
if (retry.kind === "error") throw new Error(retry.message);
|
|
29834
|
+
}
|
|
29835
|
+
throw new Error("Claude Code \u8BBF\u95EE\u4EE4\u724C\u5DF2\u8FC7\u671F\u4E14\u81EA\u52A8\u5237\u65B0\u672A\u751F\u6548\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C\u4E00\u6B21 claude \u540E\u518D\u540C\u6B65");
|
|
29836
|
+
}
|
|
29837
|
+
throw new Error("Claude Code \u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C claude \u5E76 /login \u540E\u518D\u8BD5");
|
|
29630
29838
|
}
|
|
29631
29839
|
|
|
29632
29840
|
// src/providers/codex-quota.ts
|
|
29633
|
-
import { spawn as
|
|
29841
|
+
import { spawn as spawn10 } from "node:child_process";
|
|
29634
29842
|
import { createInterface as createInterface4 } from "node:readline";
|
|
29635
29843
|
async function readCodexQuotaWindows() {
|
|
29636
29844
|
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--stdio"] });
|
|
29637
|
-
const child =
|
|
29845
|
+
const child = spawn10(launch.executable, launch.args, { env: launch.env, stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
29638
29846
|
let nextId = 0;
|
|
29639
29847
|
const pending = /* @__PURE__ */ new Map();
|
|
29640
29848
|
const lines = createInterface4({ input: child.stdout });
|
|
@@ -29906,7 +30114,7 @@ function probeVersion(path, args) {
|
|
|
29906
30114
|
if (args.length === 0) return Promise.resolve({});
|
|
29907
30115
|
return new Promise((resolve10) => {
|
|
29908
30116
|
const launch = directLaunch2(path, args, process.env.TOC_OCRA_NODE_PATH || process.execPath);
|
|
29909
|
-
const child =
|
|
30117
|
+
const child = spawn11(launch.executable, launch.args, { stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
29910
30118
|
let stdout = "";
|
|
29911
30119
|
let stderr = "";
|
|
29912
30120
|
let settled = false;
|
|
@@ -29994,7 +30202,7 @@ import { tmpdir as tmpdir3 } from "node:os";
|
|
|
29994
30202
|
import { join as join22 } from "node:path";
|
|
29995
30203
|
|
|
29996
30204
|
// src/runs/run-supervisor.ts
|
|
29997
|
-
import { spawn as
|
|
30205
|
+
import { spawn as spawn13 } from "node:child_process";
|
|
29998
30206
|
import { mkdir as mkdir7, realpath as realpath2, stat as stat5, writeFile as writeFile7 } from "node:fs/promises";
|
|
29999
30207
|
import { basename as basename2, isAbsolute as isAbsolute4, join as join21, relative as relative2, resolve as resolve5 } from "node:path";
|
|
30000
30208
|
import { createInterface as createInterface6 } from "node:readline";
|
|
@@ -30285,12 +30493,12 @@ function codexGoalProvider(request, goal) {
|
|
|
30285
30493
|
}
|
|
30286
30494
|
|
|
30287
30495
|
// src/providers/cli/codex-fork.ts
|
|
30288
|
-
import { spawn as
|
|
30496
|
+
import { spawn as spawn12 } from "node:child_process";
|
|
30289
30497
|
import { createInterface as createInterface5 } from "node:readline";
|
|
30290
30498
|
var FORK_TIMEOUT_MS = 9e4;
|
|
30291
30499
|
async function forkCodexThread(options) {
|
|
30292
30500
|
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--listen", "stdio://"] });
|
|
30293
|
-
const child =
|
|
30501
|
+
const child = spawn12(launch.executable, launch.args, {
|
|
30294
30502
|
cwd: options.workdir,
|
|
30295
30503
|
env: launch.env,
|
|
30296
30504
|
shell: false,
|
|
@@ -32450,7 +32658,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
32450
32658
|
if (!fitsCommandLine(launch)) return refuse(cliFailure("promptTooLong", { label: cli.label }));
|
|
32451
32659
|
let child;
|
|
32452
32660
|
try {
|
|
32453
|
-
child =
|
|
32661
|
+
child = spawn13(launch.executable, launch.args, {
|
|
32454
32662
|
cwd: workdir,
|
|
32455
32663
|
env: Object.keys(memoryEnv).length ? { ...launch.env, ...memoryEnv } : launch.env,
|
|
32456
32664
|
detached: currentPlatform.runsInOwnProcessGroup,
|
|
@@ -33633,7 +33841,7 @@ import { randomUUID as randomUUID4 } from "node:crypto";
|
|
|
33633
33841
|
import { join as join25 } from "node:path";
|
|
33634
33842
|
|
|
33635
33843
|
// src/exec/script-runner.ts
|
|
33636
|
-
import { spawn as
|
|
33844
|
+
import { spawn as spawn14 } from "node:child_process";
|
|
33637
33845
|
var MAX_SCRIPT_OUTPUT_BYTES = 112 * 1024;
|
|
33638
33846
|
function executeScript(command, workdir, timeoutSeconds) {
|
|
33639
33847
|
return new Promise((resolveExecution) => {
|
|
@@ -33664,7 +33872,7 @@ function executeScript(command, workdir, timeoutSeconds) {
|
|
|
33664
33872
|
};
|
|
33665
33873
|
let child;
|
|
33666
33874
|
try {
|
|
33667
|
-
child =
|
|
33875
|
+
child = spawn14(executable, args, {
|
|
33668
33876
|
cwd: workdir,
|
|
33669
33877
|
env: process.env,
|
|
33670
33878
|
detached: ownGroup,
|
|
@@ -34157,7 +34365,7 @@ async function createDirectory(parentRequested, name) {
|
|
|
34157
34365
|
}
|
|
34158
34366
|
|
|
34159
34367
|
// src/workspace/workspace-manager.ts
|
|
34160
|
-
import { spawn as
|
|
34368
|
+
import { spawn as spawn15 } from "node:child_process";
|
|
34161
34369
|
import { opendir, realpath as realpath5, stat as stat8 } from "node:fs/promises";
|
|
34162
34370
|
import { homedir as homedir15 } from "node:os";
|
|
34163
34371
|
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
@@ -34321,7 +34529,7 @@ var WorkspaceManager = class {
|
|
|
34321
34529
|
}
|
|
34322
34530
|
runGit(args, cwd, timeoutSeconds, allowFailure = false) {
|
|
34323
34531
|
return new Promise((resolveCommand, rejectCommand) => {
|
|
34324
|
-
const child =
|
|
34532
|
+
const child = spawn15("git", args, {
|
|
34325
34533
|
cwd,
|
|
34326
34534
|
env: process.env,
|
|
34327
34535
|
shell: false,
|