toc-ocra 0.2.35 → 0.2.36
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/LICENSE +21 -21
- package/README.md +129 -121
- package/assets/icon.svg +1 -1
- package/dist/cli/cli.mjs +495 -357
- package/dist/plugin/renderer.css.map +1 -1
- package/dist/plugin/renderer.js.map +1 -1
- package/dist/service/agent.mjs +484 -347
- package/dist/src/exec/script-runner.js +9 -5
- package/dist/src/exec/script-runner.js.map +1 -1
- package/dist/src/health/server.js +8 -8
- package/dist/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/platform/common.d.ts +20 -0
- package/dist/src/platform/common.js +40 -0
- package/dist/src/platform/common.js.map +1 -0
- package/dist/src/platform/index.d.ts +10 -0
- package/dist/src/platform/index.js +20 -0
- package/dist/src/platform/index.js.map +1 -0
- package/dist/src/platform/posix.d.ts +2 -0
- package/dist/src/platform/posix.js +210 -0
- package/dist/src/platform/posix.js.map +1 -0
- package/dist/src/platform/types.d.ts +61 -0
- package/dist/src/platform/types.js +2 -0
- package/dist/src/platform/types.js.map +1 -0
- package/dist/src/platform/win32.d.ts +4 -0
- package/dist/src/platform/win32.js +162 -0
- package/dist/src/platform/win32.js.map +1 -0
- package/dist/src/providers/cli/claude.js +3 -2
- package/dist/src/providers/cli/claude.js.map +1 -1
- package/dist/src/providers/cli/codex.js +3 -2
- package/dist/src/providers/cli/codex.js.map +1 -1
- package/dist/src/providers/cli/gemini.js +2 -2
- package/dist/src/providers/cli/gemini.js.map +1 -1
- package/dist/src/providers/cli/grok.js +2 -2
- package/dist/src/providers/cli/grok.js.map +1 -1
- package/dist/src/providers/cli/kiro.d.ts +2 -0
- package/dist/src/providers/cli/kiro.js +15 -6
- package/dist/src/providers/cli/kiro.js.map +1 -1
- package/dist/src/providers/cli/opencode.js +2 -2
- package/dist/src/providers/cli/opencode.js.map +1 -1
- package/dist/src/providers/codex-quota.js +3 -2
- package/dist/src/providers/codex-quota.js.map +1 -1
- package/dist/src/providers/detection.js +3 -1
- package/dist/src/providers/detection.js.map +1 -1
- package/dist/src/providers/kiro-models.js +3 -2
- package/dist/src/providers/kiro-models.js.map +1 -1
- package/dist/src/providers/model-catalog.js +3 -1
- package/dist/src/providers/model-catalog.js.map +1 -1
- package/dist/src/providers/provider.d.ts +43 -2
- package/dist/src/providers/provider.js +51 -15
- package/dist/src/providers/provider.js.map +1 -1
- package/dist/src/runs/orphan-registry.js +2 -8
- package/dist/src/runs/orphan-registry.js.map +1 -1
- package/dist/src/runs/process-tree.d.ts +5 -14
- package/dist/src/runs/process-tree.js +7 -83
- package/dist/src/runs/process-tree.js.map +1 -1
- package/dist/src/runs/run-supervisor.d.ts +2 -0
- package/dist/src/runs/run-supervisor.js +34 -4
- package/dist/src/runs/run-supervisor.js.map +1 -1
- package/dist/src/runtime/cli/hydrate-shell-path.d.ts +9 -22
- package/dist/src/runtime/cli/hydrate-shell-path.js +17 -148
- package/dist/src/runtime/cli/hydrate-shell-path.js.map +1 -1
- package/dist/src/shared/node-cli-command-resolution.d.ts +5 -0
- package/dist/src/shared/node-cli-command-resolution.js +28 -81
- package/dist/src/shared/node-cli-command-resolution.js.map +1 -1
- package/locales/en.json +202 -202
- package/locales/zh-CN.json +202 -202
- package/package.json +100 -100
- package/scripts/installation.cjs +239 -239
- package/scripts/postinstall.cjs +22 -22
- package/scripts/service.mjs +253 -253
package/dist/cli/cli.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { createHash as createHash4 } from "node:crypto";
|
|
|
12
12
|
import { existsSync as existsSync6, mkdtempSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
13
13
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
14
14
|
import { createRequire } from "node:module";
|
|
15
|
-
import { dirname as dirname8, join as
|
|
15
|
+
import { dirname as dirname8, join as join15, resolve as resolve7 } from "node:path";
|
|
16
16
|
import { fileURLToPath as fileURLToPath2, pathToFileURL } from "node:url";
|
|
17
17
|
|
|
18
18
|
// src/config.ts
|
|
@@ -19986,46 +19986,109 @@ function safeEqual(left, right) {
|
|
|
19986
19986
|
}
|
|
19987
19987
|
|
|
19988
19988
|
// src/providers/detection.ts
|
|
19989
|
-
import { spawn as
|
|
19989
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
19990
19990
|
|
|
19991
19991
|
// src/runtime/cli/hydrate-shell-path.ts
|
|
19992
|
-
import {
|
|
19993
|
-
|
|
19994
|
-
|
|
19995
|
-
|
|
19992
|
+
import { delimiter as delimiter3 } from "node:path";
|
|
19993
|
+
|
|
19994
|
+
// src/platform/common.ts
|
|
19995
|
+
import { join as join3 } from "node:path";
|
|
19996
19996
|
var PROXY_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy", "HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "NO_PROXY"];
|
|
19997
|
-
var
|
|
19998
|
-
|
|
19999
|
-
|
|
20000
|
-
|
|
20001
|
-
|
|
20002
|
-
|
|
19997
|
+
var NODE_SCRIPT = /\.(c|m)?js$/i;
|
|
19998
|
+
function isNodeScript(path) {
|
|
19999
|
+
return NODE_SCRIPT.test(path);
|
|
20000
|
+
}
|
|
20001
|
+
function sharedUserBinDirectoriesHead(home) {
|
|
20002
|
+
return [
|
|
20003
|
+
join3(home, ".volta", "bin"),
|
|
20004
|
+
join3(home, ".asdf", "shims"),
|
|
20005
|
+
join3(home, ".fnm", "aliases", "default", "bin"),
|
|
20006
|
+
// Why: mise (formerly rtx) exposes managed tool binaries via a shims
|
|
20007
|
+
// directory, similar to asdf.
|
|
20008
|
+
join3(home, ".local", "share", "mise", "shims")
|
|
20009
|
+
];
|
|
20010
|
+
}
|
|
20011
|
+
function sharedUserBinDirectoriesTail(home) {
|
|
20012
|
+
return [join3(home, ".bun", "bin")];
|
|
20013
|
+
}
|
|
20014
|
+
function directLaunch(platform2, path, args, nodePath = process.execPath) {
|
|
20015
|
+
const target = platform2.unwrapLauncher(path) ?? path;
|
|
20016
|
+
if (isNodeScript(target)) return { executable: nodePath, args: [target, ...args] };
|
|
20017
|
+
return { executable: target, args: [...args] };
|
|
20018
|
+
}
|
|
20019
|
+
function commandLineLength(executable, args) {
|
|
20020
|
+
return [executable, ...args].reduce((total, value) => total + value.length + (value.match(/["\\]/g)?.length ?? 0) + 3, 0);
|
|
20021
|
+
}
|
|
20022
|
+
|
|
20023
|
+
// src/platform/posix.ts
|
|
20024
|
+
import { execFile, spawn } from "node:child_process";
|
|
20025
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
20026
|
+
import { delimiter as delimiter2, join as join4 } from "node:path";
|
|
20027
|
+
function readProcessTable() {
|
|
20028
|
+
return new Promise((resolve8) => {
|
|
20029
|
+
execFile("ps", ["-axo", "pid=,ppid="], { maxBuffer: 32 * 1024 * 1024, timeout: 2e3 }, (error62, stdout) => {
|
|
20030
|
+
if (error62) return resolve8([]);
|
|
20031
|
+
resolve8(stdout.split("\n").flatMap((line) => {
|
|
20032
|
+
const [pid, ppid] = line.trim().split(/\s+/).map(Number);
|
|
20033
|
+
return pid && ppid !== void 0 && Number.isFinite(ppid) ? [{ pid, ppid }] : [];
|
|
20034
|
+
}));
|
|
20035
|
+
});
|
|
20036
|
+
});
|
|
20037
|
+
}
|
|
20038
|
+
async function listDescendants(rootPid) {
|
|
20039
|
+
const rows = await readProcessTable();
|
|
20040
|
+
const children = /* @__PURE__ */ new Map();
|
|
20041
|
+
for (const row of rows) children.set(row.ppid, [...children.get(row.ppid) ?? [], row.pid]);
|
|
20042
|
+
const out = [];
|
|
20043
|
+
const queue = [...children.get(rootPid) ?? []];
|
|
20044
|
+
while (queue.length > 0) {
|
|
20045
|
+
const pid = queue.shift();
|
|
20046
|
+
if (out.includes(pid)) continue;
|
|
20047
|
+
out.push(pid);
|
|
20048
|
+
queue.push(...children.get(pid) ?? []);
|
|
20003
20049
|
}
|
|
20004
|
-
|
|
20005
|
-
|
|
20006
|
-
|
|
20050
|
+
return out;
|
|
20051
|
+
}
|
|
20052
|
+
function signal(pid, sig) {
|
|
20053
|
+
try {
|
|
20054
|
+
process.kill(pid, sig);
|
|
20055
|
+
} catch {
|
|
20056
|
+
}
|
|
20057
|
+
}
|
|
20058
|
+
function alive(pid) {
|
|
20059
|
+
try {
|
|
20060
|
+
process.kill(pid, 0);
|
|
20061
|
+
return true;
|
|
20062
|
+
} catch {
|
|
20063
|
+
return false;
|
|
20007
20064
|
}
|
|
20008
|
-
return process.platform === "darwin" ? "/bin/zsh" : "/bin/bash";
|
|
20009
20065
|
}
|
|
20066
|
+
var sleep = (ms) => new Promise((resolve8) => setTimeout(resolve8, ms));
|
|
20067
|
+
async function killPosixTree(rootPid, graceMs) {
|
|
20068
|
+
const descendants = await listDescendants(rootPid);
|
|
20069
|
+
signal(-rootPid, "SIGTERM");
|
|
20070
|
+
signal(rootPid, "SIGTERM");
|
|
20071
|
+
for (const pid of descendants) signal(pid, "SIGTERM");
|
|
20072
|
+
const members2 = [rootPid, ...descendants];
|
|
20073
|
+
const deadline = Date.now() + graceMs;
|
|
20074
|
+
while (Date.now() < deadline && members2.some(alive)) await sleep(100);
|
|
20075
|
+
const late = alive(rootPid) ? await listDescendants(rootPid) : [];
|
|
20076
|
+
signal(-rootPid, "SIGKILL");
|
|
20077
|
+
for (const pid of [...members2, ...late]) if (alive(pid)) signal(pid, "SIGKILL");
|
|
20078
|
+
}
|
|
20079
|
+
var PATH_DELIMITER = "__ORCA_SHELL_PATH__";
|
|
20080
|
+
var PROXY_DELIMITER = "__ECHO_SHELL_PROXY__";
|
|
20081
|
+
var SHELL_TIMEOUT_MS = 5e3;
|
|
20082
|
+
var ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]/g;
|
|
20010
20083
|
function parseCapturedPath(stdout) {
|
|
20011
20084
|
const cleaned = stdout.replace(ANSI_RE, "");
|
|
20012
|
-
const first = cleaned.indexOf(
|
|
20013
|
-
if (first < 0)
|
|
20014
|
-
|
|
20015
|
-
|
|
20016
|
-
const
|
|
20017
|
-
if (
|
|
20018
|
-
|
|
20019
|
-
}
|
|
20020
|
-
const value = cleaned.slice(first + DELIMITER.length, second).trim();
|
|
20021
|
-
if (!value) {
|
|
20022
|
-
return [];
|
|
20023
|
-
}
|
|
20024
|
-
return [
|
|
20025
|
-
...new Set(
|
|
20026
|
-
value.split(delimiter2).map((s) => s.trim()).filter(Boolean)
|
|
20027
|
-
)
|
|
20028
|
-
];
|
|
20085
|
+
const first = cleaned.indexOf(PATH_DELIMITER);
|
|
20086
|
+
if (first < 0) return [];
|
|
20087
|
+
const second = cleaned.indexOf(PATH_DELIMITER, first + PATH_DELIMITER.length);
|
|
20088
|
+
if (second < 0) return [];
|
|
20089
|
+
const value = cleaned.slice(first + PATH_DELIMITER.length, second).trim();
|
|
20090
|
+
if (!value) return [];
|
|
20091
|
+
return [...new Set(value.split(delimiter2).map((s) => s.trim()).filter(Boolean))];
|
|
20029
20092
|
}
|
|
20030
20093
|
function parseCapturedProxy(stdout) {
|
|
20031
20094
|
const start = stdout.indexOf(PROXY_DELIMITER);
|
|
@@ -20034,48 +20097,28 @@ function parseCapturedProxy(stdout) {
|
|
|
20034
20097
|
const values = stdout.slice(start + PROXY_DELIMITER.length, end).split("\0");
|
|
20035
20098
|
return Object.fromEntries(PROXY_KEYS.flatMap((key, index) => values[index] ? [[key, values[index]]] : []));
|
|
20036
20099
|
}
|
|
20037
|
-
function
|
|
20038
|
-
const environment = { ...baseline };
|
|
20039
|
-
if (!hydration.ok) return environment;
|
|
20040
|
-
for (const key of PROXY_KEYS.slice(0, 4)) {
|
|
20041
|
-
const upper = key.toUpperCase();
|
|
20042
|
-
if (baseline[key] !== void 0 || baseline[upper] !== void 0) continue;
|
|
20043
|
-
const value = hydration.proxyEnv?.[key] ?? hydration.proxyEnv?.[upper];
|
|
20044
|
-
if (value) environment[key] = value;
|
|
20045
|
-
}
|
|
20046
|
-
return environment;
|
|
20047
|
-
}
|
|
20048
|
-
function spawnShellAndReadPath(shell) {
|
|
20100
|
+
function readLoginShell(shell) {
|
|
20049
20101
|
return new Promise((resolve8) => {
|
|
20050
20102
|
const proxyValues = PROXY_KEYS.map((key) => `"\${${key}-}"`).join(" ");
|
|
20051
|
-
const command = `printf '%s' '${
|
|
20103
|
+
const command = `printf '%s' '${PATH_DELIMITER}'; printf '%s' "$PATH"; printf '%s' '${PATH_DELIMITER}'; printf '%s' '${PROXY_DELIMITER}'; printf '%s\\0' ${proxyValues}; printf '%s' '${PROXY_DELIMITER}'`;
|
|
20052
20104
|
let finished = false;
|
|
20053
20105
|
let stdout = "";
|
|
20054
20106
|
let timer = null;
|
|
20055
20107
|
const child = spawn(shell, ["-ilc", command], {
|
|
20056
20108
|
// Why: inherit current env so the shell sees the same baseline, then let
|
|
20057
20109
|
// it layer its own rc files on top. Do NOT forward stdio — some shells
|
|
20058
|
-
// (oh-my-zsh setups, powerlevel10k) print a lot to stderr on startup
|
|
20059
|
-
// and we don't want that in Orca's console.
|
|
20110
|
+
// (oh-my-zsh setups, powerlevel10k) print a lot to stderr on startup.
|
|
20060
20111
|
env: process.env,
|
|
20061
20112
|
stdio: ["ignore", "pipe", "ignore"],
|
|
20062
20113
|
detached: false
|
|
20063
20114
|
});
|
|
20064
|
-
const cleanup = () => {
|
|
20065
|
-
if (timer) {
|
|
20066
|
-
clearTimeout(timer);
|
|
20067
|
-
timer = null;
|
|
20068
|
-
}
|
|
20069
|
-
child.stdout.off("data", onStdoutData);
|
|
20070
|
-
child.off("error", onError);
|
|
20071
|
-
child.off("close", onClose);
|
|
20072
|
-
};
|
|
20073
20115
|
const finish = (result) => {
|
|
20074
|
-
if (finished)
|
|
20075
|
-
return;
|
|
20076
|
-
}
|
|
20116
|
+
if (finished) return;
|
|
20077
20117
|
finished = true;
|
|
20078
|
-
|
|
20118
|
+
if (timer) clearTimeout(timer);
|
|
20119
|
+
child.stdout.removeAllListeners("data");
|
|
20120
|
+
child.removeAllListeners("error");
|
|
20121
|
+
child.removeAllListeners("close");
|
|
20079
20122
|
resolve8(result);
|
|
20080
20123
|
};
|
|
20081
20124
|
timer = setTimeout(() => {
|
|
@@ -20084,44 +20127,229 @@ function spawnShellAndReadPath(shell) {
|
|
|
20084
20127
|
} catch {
|
|
20085
20128
|
}
|
|
20086
20129
|
finish({ segments: [], ok: false, failureReason: "timeout" });
|
|
20087
|
-
},
|
|
20088
|
-
|
|
20130
|
+
}, SHELL_TIMEOUT_MS);
|
|
20131
|
+
child.stdout.on("data", (chunk) => {
|
|
20089
20132
|
stdout += chunk.toString("utf8");
|
|
20090
|
-
};
|
|
20091
|
-
|
|
20092
|
-
|
|
20093
|
-
};
|
|
20094
|
-
const onClose = () => {
|
|
20133
|
+
});
|
|
20134
|
+
child.on("error", () => finish({ segments: [], ok: false, failureReason: "spawn_error" }));
|
|
20135
|
+
child.on("close", () => {
|
|
20095
20136
|
const segments = parseCapturedPath(stdout);
|
|
20096
20137
|
if (segments.length === 0) {
|
|
20097
20138
|
finish({ segments: [], ok: false, failureReason: "empty_path" });
|
|
20098
20139
|
return;
|
|
20099
20140
|
}
|
|
20100
20141
|
finish({ segments, proxyEnv: parseCapturedProxy(stdout), ok: true, failureReason: "none" });
|
|
20101
|
-
};
|
|
20102
|
-
child.stdout.on("data", onStdoutData);
|
|
20103
|
-
child.on("error", onError);
|
|
20104
|
-
child.on("close", onClose);
|
|
20142
|
+
});
|
|
20105
20143
|
});
|
|
20106
20144
|
}
|
|
20107
|
-
function
|
|
20108
|
-
|
|
20109
|
-
|
|
20145
|
+
function createPosixPlatform(id) {
|
|
20146
|
+
return {
|
|
20147
|
+
id,
|
|
20148
|
+
executableNames: (command) => [command],
|
|
20149
|
+
isRunnableFile(path) {
|
|
20150
|
+
try {
|
|
20151
|
+
if (!statSync(path).isFile()) return false;
|
|
20152
|
+
accessSync(path, constants.X_OK);
|
|
20153
|
+
return true;
|
|
20154
|
+
} catch {
|
|
20155
|
+
return false;
|
|
20156
|
+
}
|
|
20157
|
+
},
|
|
20158
|
+
userBinDirectories: (home) => [
|
|
20159
|
+
join4(home, ".local", "bin"),
|
|
20160
|
+
// Why: pnpm uses platform-specific global bin directories that differ
|
|
20161
|
+
// from npm's ~/.local/bin.
|
|
20162
|
+
id === "darwin" ? join4(home, "Library", "pnpm") : join4(home, ".local", "share", "pnpm"),
|
|
20163
|
+
join4(home, ".yarn", "bin")
|
|
20164
|
+
],
|
|
20165
|
+
fallbackBinDirectories: (home) => ["/opt/homebrew/bin", "/usr/local/bin", join4(home, ".local", "bin")],
|
|
20166
|
+
normalizeEnvironment: (env) => ({ ...env }),
|
|
20167
|
+
// Shebang scripts and symlinks start directly.
|
|
20168
|
+
unwrapLauncher: () => void 0,
|
|
20169
|
+
// Linux caps a single argument at 128 KiB (MAX_ARG_STRLEN); macOS caps
|
|
20170
|
+
// the whole command line plus environment at 1 MiB (ARG_MAX).
|
|
20171
|
+
maxCommandLineLength: id === "linux" ? 12e4 : 9e5,
|
|
20172
|
+
runsInOwnProcessGroup: true,
|
|
20173
|
+
killProcessTree: killPosixTree,
|
|
20174
|
+
stopHelper: (child) => {
|
|
20175
|
+
child.kill("SIGTERM");
|
|
20176
|
+
},
|
|
20177
|
+
processCommandLine(pid) {
|
|
20178
|
+
return new Promise((resolve8) => {
|
|
20179
|
+
execFile("ps", ["-o", "command=", "-p", String(pid)], { timeout: 2e3 }, (error62, stdout) => {
|
|
20180
|
+
resolve8(error62 ? void 0 : stdout.trim() || void 0);
|
|
20181
|
+
});
|
|
20182
|
+
});
|
|
20183
|
+
},
|
|
20184
|
+
scriptShell: (command) => ({ executable: "/bin/sh", args: ["-lc", command] }),
|
|
20185
|
+
readLoginEnvironment() {
|
|
20186
|
+
const shell = process.env.SHELL || (id === "darwin" ? "/bin/zsh" : "/bin/bash");
|
|
20187
|
+
return readLoginShell(shell);
|
|
20188
|
+
}
|
|
20189
|
+
};
|
|
20190
|
+
}
|
|
20191
|
+
|
|
20192
|
+
// src/platform/win32.ts
|
|
20193
|
+
import { execFile as execFile2, spawn as spawn2 } from "node:child_process";
|
|
20194
|
+
import { readFileSync as readFileSync3, statSync as statSync2 } from "node:fs";
|
|
20195
|
+
import { join as join5, win32 } from "node:path";
|
|
20196
|
+
var SYSTEM_ROOT = process.env.SystemRoot || process.env.windir || "C:\\Windows";
|
|
20197
|
+
var POWERSHELL = join5(SYSTEM_ROOT, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
20198
|
+
var HELPER_TIMEOUT_MS = 5e3;
|
|
20199
|
+
var SHIM_TARGET_RE = /%~?dp0%?\\?([^"%\r\n]+)/gi;
|
|
20200
|
+
var SHIM_TARGET_EXTENSIONS = /\.(c|m)?js$|\.exe$/i;
|
|
20201
|
+
var MAX_SHIM_BYTES = 64 * 1024;
|
|
20202
|
+
function resolveWindowsCommandShim(shimPath) {
|
|
20203
|
+
if (!/\.(cmd|bat)$/i.test(shimPath)) return void 0;
|
|
20204
|
+
let content;
|
|
20205
|
+
try {
|
|
20206
|
+
if (statSync2(shimPath).size > MAX_SHIM_BYTES) return void 0;
|
|
20207
|
+
content = readFileSync3(shimPath, "utf8");
|
|
20208
|
+
} catch {
|
|
20209
|
+
return void 0;
|
|
20110
20210
|
}
|
|
20111
|
-
const
|
|
20112
|
-
|
|
20113
|
-
|
|
20114
|
-
|
|
20211
|
+
const base = win32.dirname(shimPath);
|
|
20212
|
+
const targets = [...content.matchAll(SHIM_TARGET_RE)].map((match) => match[1].trim()).filter((target) => SHIM_TARGET_EXTENSIONS.test(target) && !/(^|\\)node\.exe$/i.test(target));
|
|
20213
|
+
for (const target of targets.reverse()) {
|
|
20214
|
+
const absolute = win32.isAbsolute(target) ? target : win32.resolve(base, target);
|
|
20215
|
+
try {
|
|
20216
|
+
if (statSync2(absolute).isFile()) return absolute;
|
|
20217
|
+
} catch {
|
|
20218
|
+
}
|
|
20219
|
+
}
|
|
20220
|
+
return void 0;
|
|
20221
|
+
}
|
|
20222
|
+
function taskkillTree(rootPid) {
|
|
20223
|
+
return new Promise((resolve8) => {
|
|
20224
|
+
const child = spawn2(join5(SYSTEM_ROOT, "System32", "taskkill.exe"), ["/PID", String(rootPid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
20225
|
+
child.once("error", () => resolve8());
|
|
20226
|
+
child.once("close", () => resolve8());
|
|
20227
|
+
});
|
|
20228
|
+
}
|
|
20229
|
+
function runPowerShell(script) {
|
|
20230
|
+
const prelude = '$ProgressPreference="SilentlyContinue";[Console]::OutputEncoding=[Text.Encoding]::UTF8;';
|
|
20231
|
+
const encoded = Buffer.from(prelude + script, "utf16le").toString("base64");
|
|
20232
|
+
return new Promise((resolve8) => {
|
|
20233
|
+
execFile2(
|
|
20234
|
+
POWERSHELL,
|
|
20235
|
+
["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", encoded],
|
|
20236
|
+
{ timeout: HELPER_TIMEOUT_MS, windowsHide: true, encoding: "utf8", maxBuffer: 4 * 1024 * 1024 },
|
|
20237
|
+
(error62, stdout) => {
|
|
20238
|
+
if (!error62) return resolve8({ ok: true, stdout });
|
|
20239
|
+
resolve8({ ok: false, reason: error62.killed ? "timeout" : "spawn_error" });
|
|
20240
|
+
}
|
|
20241
|
+
);
|
|
20242
|
+
});
|
|
20243
|
+
}
|
|
20244
|
+
function expandVariables(value) {
|
|
20245
|
+
return value.replace(/%([^%;]+)%/g, (whole, name) => process.env[name] ?? whole);
|
|
20246
|
+
}
|
|
20247
|
+
async function readRegistryEnvironment() {
|
|
20248
|
+
const names = [...new Set(PROXY_KEYS.map((key) => key.toLowerCase()))];
|
|
20249
|
+
const script = [
|
|
20250
|
+
"$r=@{};",
|
|
20251
|
+
"$r.path=@([Environment]::GetEnvironmentVariable('Path','Machine'),[Environment]::GetEnvironmentVariable('Path','User'));",
|
|
20252
|
+
"$r.proxy=@{};",
|
|
20253
|
+
`foreach($k in @(${names.map((name) => `'${name}'`).join(",")})){`,
|
|
20254
|
+
"$v=[Environment]::GetEnvironmentVariable($k,'User');if(-not $v){$v=[Environment]::GetEnvironmentVariable($k,'Machine')};if($v){$r.proxy[$k]=$v}};",
|
|
20255
|
+
"$r|ConvertTo-Json -Compress -Depth 4"
|
|
20256
|
+
].join("");
|
|
20257
|
+
const result = await runPowerShell(script);
|
|
20258
|
+
if (!result.ok) return { ok: false, segments: [], failureReason: result.reason };
|
|
20259
|
+
let parsed;
|
|
20260
|
+
try {
|
|
20261
|
+
parsed = JSON.parse(result.stdout.trim());
|
|
20262
|
+
} catch {
|
|
20263
|
+
return { ok: false, segments: [], failureReason: "empty_path" };
|
|
20264
|
+
}
|
|
20265
|
+
const raw = (Array.isArray(parsed.path) ? parsed.path : [parsed.path]).filter((value) => typeof value === "string");
|
|
20266
|
+
const segments = [...new Set(raw.flatMap((value) => value.split(";")).map((segment) => expandVariables(segment.trim())).filter(Boolean))];
|
|
20267
|
+
if (segments.length === 0) return { ok: false, segments: [], failureReason: "empty_path" };
|
|
20268
|
+
const proxyEnv = Object.fromEntries(Object.entries(parsed.proxy ?? {}).filter((entry) => typeof entry[1] === "string" && entry[1].length > 0));
|
|
20269
|
+
return { ok: true, segments, proxyEnv, failureReason: "none" };
|
|
20270
|
+
}
|
|
20271
|
+
var win32Platform = {
|
|
20272
|
+
id: "win32",
|
|
20273
|
+
executableNames: (command) => [`${command}.cmd`, `${command}.exe`, `${command}.bat`, command],
|
|
20274
|
+
isRunnableFile(path) {
|
|
20275
|
+
try {
|
|
20276
|
+
return statSync2(path).isFile();
|
|
20277
|
+
} catch {
|
|
20278
|
+
return false;
|
|
20279
|
+
}
|
|
20280
|
+
},
|
|
20281
|
+
userBinDirectories: (home) => [
|
|
20282
|
+
// Why: Anthropic's native Windows installer places claude.exe here, and
|
|
20283
|
+
// GUI-launched processes may not inherit the user's PATH entry for it.
|
|
20284
|
+
join5(home, ".local", "bin"),
|
|
20285
|
+
join5(home, "AppData", "Roaming", "npm"),
|
|
20286
|
+
join5(home, "AppData", "Local", "pnpm"),
|
|
20287
|
+
join5(home, "AppData", "Local", "Yarn", "bin")
|
|
20288
|
+
],
|
|
20289
|
+
fallbackBinDirectories: (home) => [join5(home, ".local", "bin")],
|
|
20290
|
+
normalizeEnvironment(env) {
|
|
20291
|
+
const copy = { ...env };
|
|
20292
|
+
const keys = Object.keys(copy).filter((key) => key.toUpperCase() === "PATH");
|
|
20293
|
+
const value = keys.map((key) => copy[key]).find((entry) => entry);
|
|
20294
|
+
for (const key of keys) delete copy[key];
|
|
20295
|
+
if (value) copy.PATH = value;
|
|
20296
|
+
return copy;
|
|
20297
|
+
},
|
|
20298
|
+
unwrapLauncher: resolveWindowsCommandShim,
|
|
20299
|
+
// CreateProcess limit is 32 767 UTF-16 units; keep a margin for the
|
|
20300
|
+
// wrapper that relaunches the native binary with the same arguments.
|
|
20301
|
+
maxCommandLineLength: 3e4,
|
|
20302
|
+
runsInOwnProcessGroup: false,
|
|
20303
|
+
killProcessTree: (rootPid) => taskkillTree(rootPid),
|
|
20304
|
+
stopHelper(child) {
|
|
20305
|
+
child.stdin?.end();
|
|
20306
|
+
if (child.pid) void taskkillTree(child.pid);
|
|
20307
|
+
else child.kill();
|
|
20308
|
+
},
|
|
20309
|
+
async processCommandLine(pid) {
|
|
20310
|
+
if (!Number.isInteger(pid) || pid <= 0) return void 0;
|
|
20311
|
+
const result = await runPowerShell(`(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CommandLine`);
|
|
20312
|
+
return result.ok ? result.stdout.trim() || void 0 : void 0;
|
|
20313
|
+
},
|
|
20314
|
+
scriptShell: (command) => ({ executable: process.env.ComSpec ?? "cmd.exe", args: ["/d", "/s", "/c", command] }),
|
|
20315
|
+
readLoginEnvironment: readRegistryEnvironment
|
|
20316
|
+
};
|
|
20317
|
+
|
|
20318
|
+
// src/platform/index.ts
|
|
20319
|
+
var darwinPlatform = createPosixPlatform("darwin");
|
|
20320
|
+
var linuxPlatform = createPosixPlatform("linux");
|
|
20321
|
+
function platformFor(id) {
|
|
20322
|
+
if (id === "win32") return win32Platform;
|
|
20323
|
+
if (id === "darwin") return darwinPlatform;
|
|
20324
|
+
return linuxPlatform;
|
|
20325
|
+
}
|
|
20326
|
+
var currentPlatform = platformFor(process.platform);
|
|
20327
|
+
function directLaunch2(path, args, nodePath = process.execPath) {
|
|
20328
|
+
return directLaunch(currentPlatform, path, args, nodePath);
|
|
20329
|
+
}
|
|
20330
|
+
|
|
20331
|
+
// src/runtime/cli/hydrate-shell-path.ts
|
|
20332
|
+
var cached2 = null;
|
|
20333
|
+
function mergeShellProxyEnvironment(hydration, baseline = process.env) {
|
|
20334
|
+
const environment = { ...baseline };
|
|
20335
|
+
if (!hydration.ok) return environment;
|
|
20336
|
+
for (const key of PROXY_KEYS.slice(0, 4)) {
|
|
20337
|
+
const upper = key.toUpperCase();
|
|
20338
|
+
if (baseline[key] !== void 0 || baseline[upper] !== void 0) continue;
|
|
20339
|
+
const value = hydration.proxyEnv?.[key] ?? hydration.proxyEnv?.[upper];
|
|
20340
|
+
if (value) environment[key] = value;
|
|
20115
20341
|
}
|
|
20116
|
-
|
|
20342
|
+
return environment;
|
|
20343
|
+
}
|
|
20344
|
+
function hydrateShellPath(options = {}) {
|
|
20345
|
+
if (cached2 && !options.force) return cached2;
|
|
20346
|
+
cached2 = (options.reader ?? (() => currentPlatform.readLoginEnvironment()))();
|
|
20117
20347
|
return cached2;
|
|
20118
20348
|
}
|
|
20119
20349
|
function mergePathSegments(segments) {
|
|
20120
|
-
if (segments.length === 0)
|
|
20121
|
-
return [];
|
|
20122
|
-
}
|
|
20350
|
+
if (segments.length === 0) return [];
|
|
20123
20351
|
const current = process.env.PATH ?? "";
|
|
20124
|
-
const currentSegments = current.split(
|
|
20352
|
+
const currentSegments = current.split(delimiter3).filter(Boolean);
|
|
20125
20353
|
const shellSegments = [...new Set(segments)];
|
|
20126
20354
|
const shellSegmentSet = new Set(shellSegments);
|
|
20127
20355
|
const existing = new Set(currentSegments);
|
|
@@ -20130,39 +20358,32 @@ function mergePathSegments(segments) {
|
|
|
20130
20358
|
...shellSegments,
|
|
20131
20359
|
...currentSegments.filter((segment) => !shellSegmentSet.has(segment))
|
|
20132
20360
|
];
|
|
20133
|
-
const next = merged.join(
|
|
20134
|
-
if (next === current)
|
|
20135
|
-
return [];
|
|
20136
|
-
}
|
|
20361
|
+
const next = merged.join(delimiter3);
|
|
20362
|
+
if (next === current) return [];
|
|
20137
20363
|
process.env.PATH = next;
|
|
20138
20364
|
return added;
|
|
20139
20365
|
}
|
|
20140
20366
|
|
|
20141
20367
|
// src/providers/cli/claude.ts
|
|
20142
|
-
import { readFileSync as
|
|
20368
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
20143
20369
|
import { homedir as homedir4 } from "node:os";
|
|
20144
|
-
import { join as
|
|
20370
|
+
import { join as join7 } from "node:path";
|
|
20145
20371
|
|
|
20146
20372
|
// src/providers/provider.ts
|
|
20147
20373
|
import { realpathSync } from "node:fs";
|
|
20148
20374
|
import { homedir as homedir3 } from "node:os";
|
|
20149
|
-
import { delimiter as delimiter4, dirname as dirname3
|
|
20375
|
+
import { delimiter as delimiter4, dirname as dirname3 } from "node:path";
|
|
20150
20376
|
|
|
20151
20377
|
// src/shared/node-cli-command-resolution.ts
|
|
20152
|
-
import {
|
|
20378
|
+
import { existsSync as existsSync3, readdirSync } from "node:fs";
|
|
20153
20379
|
import { homedir as homedir2 } from "node:os";
|
|
20154
|
-
import {
|
|
20155
|
-
function
|
|
20156
|
-
|
|
20157
|
-
return [`${commandName}.cmd`, `${commandName}.exe`, `${commandName}.bat`, commandName];
|
|
20158
|
-
}
|
|
20159
|
-
return [commandName];
|
|
20380
|
+
import { dirname as dirname2, join as join6 } from "node:path";
|
|
20381
|
+
function adapterOf(options) {
|
|
20382
|
+
return platformFor(options.platform ?? process.platform);
|
|
20160
20383
|
}
|
|
20161
|
-
function splitPath(pathEnv) {
|
|
20162
|
-
if (!pathEnv)
|
|
20163
|
-
|
|
20164
|
-
}
|
|
20165
|
-
return pathEnv.split(delimiter3).map((entry) => entry.trim()).filter(Boolean);
|
|
20384
|
+
function splitPath(platform2, pathEnv) {
|
|
20385
|
+
if (!pathEnv) return [];
|
|
20386
|
+
return pathEnv.split(platform2.id === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean);
|
|
20166
20387
|
}
|
|
20167
20388
|
function parseVersionSegment(raw) {
|
|
20168
20389
|
return raw.replace(/^v/i, "").split(".").map((segment) => Number.parseInt(segment, 10)).map((segment) => Number.isFinite(segment) ? segment : 0);
|
|
@@ -20173,116 +20394,58 @@ function compareVersionDesc(left, right) {
|
|
|
20173
20394
|
const length = Math.max(leftParts.length, rightParts.length);
|
|
20174
20395
|
for (let index = 0; index < length; index += 1) {
|
|
20175
20396
|
const delta = (rightParts[index] ?? 0) - (leftParts[index] ?? 0);
|
|
20176
|
-
if (delta !== 0)
|
|
20177
|
-
return delta;
|
|
20178
|
-
}
|
|
20397
|
+
if (delta !== 0) return delta;
|
|
20179
20398
|
}
|
|
20180
20399
|
return right.localeCompare(left);
|
|
20181
20400
|
}
|
|
20182
20401
|
function findFirstExecutable(platform2, directories, executableNames) {
|
|
20183
20402
|
for (const directory of directories) {
|
|
20184
20403
|
for (const executableName of executableNames) {
|
|
20185
|
-
const candidate =
|
|
20186
|
-
if (
|
|
20187
|
-
return candidate;
|
|
20188
|
-
}
|
|
20404
|
+
const candidate = join6(directory, executableName);
|
|
20405
|
+
if (platform2.isRunnableFile(candidate)) return candidate;
|
|
20189
20406
|
}
|
|
20190
20407
|
}
|
|
20191
20408
|
return null;
|
|
20192
20409
|
}
|
|
20193
|
-
function isRunnableCommand(platform2, candidate) {
|
|
20194
|
-
try {
|
|
20195
|
-
const stats = statSync(candidate);
|
|
20196
|
-
if (!stats.isFile()) {
|
|
20197
|
-
return false;
|
|
20198
|
-
}
|
|
20199
|
-
if (platform2 === "win32") {
|
|
20200
|
-
return true;
|
|
20201
|
-
}
|
|
20202
|
-
accessSync(candidate, constants.X_OK);
|
|
20203
|
-
return true;
|
|
20204
|
-
} catch {
|
|
20205
|
-
return false;
|
|
20206
|
-
}
|
|
20207
|
-
}
|
|
20208
20410
|
function getBaseVersionManagerDirectories(platform2, homePath) {
|
|
20209
|
-
|
|
20210
|
-
|
|
20211
|
-
|
|
20212
|
-
|
|
20213
|
-
// Why: mise (formerly rtx) exposes managed tool binaries via a shims
|
|
20214
|
-
// directory, similar to asdf.
|
|
20215
|
-
join3(homePath, ".local", "share", "mise", "shims")
|
|
20411
|
+
return [
|
|
20412
|
+
...sharedUserBinDirectoriesHead(homePath),
|
|
20413
|
+
...platform2.userBinDirectories(homePath),
|
|
20414
|
+
...sharedUserBinDirectoriesTail(homePath)
|
|
20216
20415
|
];
|
|
20217
|
-
if (platform2 === "win32") {
|
|
20218
|
-
directories.push(join3(homePath, ".local", "bin"));
|
|
20219
|
-
directories.push(join3(homePath, "AppData", "Roaming", "npm"));
|
|
20220
|
-
directories.push(join3(homePath, "AppData", "Local", "pnpm"));
|
|
20221
|
-
directories.push(join3(homePath, "AppData", "Local", "Yarn", "bin"));
|
|
20222
|
-
} else {
|
|
20223
|
-
directories.push(join3(homePath, ".local", "bin"));
|
|
20224
|
-
if (platform2 === "darwin") {
|
|
20225
|
-
directories.push(join3(homePath, "Library", "pnpm"));
|
|
20226
|
-
} else {
|
|
20227
|
-
directories.push(join3(homePath, ".local", "share", "pnpm"));
|
|
20228
|
-
}
|
|
20229
|
-
directories.push(join3(homePath, ".yarn", "bin"));
|
|
20230
|
-
}
|
|
20231
|
-
directories.push(join3(homePath, ".bun", "bin"));
|
|
20232
|
-
return directories;
|
|
20233
20416
|
}
|
|
20234
20417
|
function getNvmVersionDirectories(homePath) {
|
|
20235
|
-
const nvmVersionsDir =
|
|
20236
|
-
if (!existsSync3(nvmVersionsDir))
|
|
20237
|
-
|
|
20238
|
-
}
|
|
20239
|
-
return readdirSync(nvmVersionsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareVersionDesc).map((entry) => join3(nvmVersionsDir, entry, "bin"));
|
|
20418
|
+
const nvmVersionsDir = join6(homePath, ".nvm", "versions", "node");
|
|
20419
|
+
if (!existsSync3(nvmVersionsDir)) return [];
|
|
20420
|
+
return readdirSync(nvmVersionsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareVersionDesc).map((entry) => join6(nvmVersionsDir, entry, "bin"));
|
|
20240
20421
|
}
|
|
20241
20422
|
function getVersionManagerDirectories(platform2, homePath, executableNames) {
|
|
20242
20423
|
const directories = getBaseVersionManagerDirectories(platform2, homePath);
|
|
20243
|
-
const firstNvmMatch = findFirstExecutable(
|
|
20244
|
-
|
|
20245
|
-
getNvmVersionDirectories(homePath),
|
|
20246
|
-
executableNames
|
|
20247
|
-
);
|
|
20248
|
-
if (firstNvmMatch) {
|
|
20249
|
-
directories.unshift(dirname2(firstNvmMatch));
|
|
20250
|
-
}
|
|
20424
|
+
const firstNvmMatch = findFirstExecutable(platform2, getNvmVersionDirectories(homePath), executableNames);
|
|
20425
|
+
if (firstNvmMatch) directories.unshift(dirname2(firstNvmMatch));
|
|
20251
20426
|
return directories;
|
|
20252
20427
|
}
|
|
20253
20428
|
function resolveCliCommand(commandName, options = {}) {
|
|
20254
20429
|
return findCliCommand(commandName, options) ?? commandName;
|
|
20255
20430
|
}
|
|
20256
20431
|
function findCliCommand(commandName, options = {}) {
|
|
20257
|
-
const platform2 = options
|
|
20258
|
-
const executableNames =
|
|
20432
|
+
const platform2 = adapterOf(options);
|
|
20433
|
+
const executableNames = platform2.executableNames(commandName);
|
|
20259
20434
|
const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null;
|
|
20260
|
-
const pathCandidate = findFirstExecutable(platform2, splitPath(pathEnv), executableNames);
|
|
20261
|
-
if (pathCandidate)
|
|
20262
|
-
return pathCandidate;
|
|
20263
|
-
}
|
|
20435
|
+
const pathCandidate = findFirstExecutable(platform2, splitPath(platform2, pathEnv), executableNames);
|
|
20436
|
+
if (pathCandidate) return pathCandidate;
|
|
20264
20437
|
const homePath = options.homePath ?? homedir2();
|
|
20265
|
-
const nvmCandidate = findFirstExecutable(
|
|
20266
|
-
|
|
20267
|
-
getNvmVersionDirectories(homePath),
|
|
20268
|
-
executableNames
|
|
20269
|
-
);
|
|
20270
|
-
const versionManagerCandidate = nvmCandidate ?? findFirstExecutable(
|
|
20271
|
-
platform2,
|
|
20272
|
-
getBaseVersionManagerDirectories(platform2, homePath),
|
|
20273
|
-
executableNames
|
|
20274
|
-
);
|
|
20275
|
-
return versionManagerCandidate;
|
|
20438
|
+
const nvmCandidate = findFirstExecutable(platform2, getNvmVersionDirectories(homePath), executableNames);
|
|
20439
|
+
return nvmCandidate ?? findFirstExecutable(platform2, getBaseVersionManagerDirectories(platform2, homePath), executableNames);
|
|
20276
20440
|
}
|
|
20277
20441
|
function resolveCliCommandDetailed(commandName, options = {}) {
|
|
20278
20442
|
const resolved = findCliCommand(commandName, options);
|
|
20279
20443
|
return resolved ? { command: resolved, found: true, path: resolved } : { command: commandName, found: false };
|
|
20280
20444
|
}
|
|
20281
20445
|
function getVersionManagerBinPaths(options = {}) {
|
|
20282
|
-
const platform2 = options
|
|
20446
|
+
const platform2 = adapterOf(options);
|
|
20283
20447
|
const homePath = options.homePath ?? homedir2();
|
|
20284
|
-
|
|
20285
|
-
return getVersionManagerDirectories(platform2, homePath, nodeNames);
|
|
20448
|
+
return getVersionManagerDirectories(platform2, homePath, platform2.executableNames("node"));
|
|
20286
20449
|
}
|
|
20287
20450
|
|
|
20288
20451
|
// src/providers/provider.ts
|
|
@@ -20323,14 +20486,12 @@ function toolCallRows(name, path) {
|
|
|
20323
20486
|
return [runLog.tool("tool_call")];
|
|
20324
20487
|
}
|
|
20325
20488
|
function providerEnvironment() {
|
|
20326
|
-
const env =
|
|
20489
|
+
const env = currentPlatform.normalizeEnvironment(process.env);
|
|
20327
20490
|
const commandPaths = [
|
|
20328
20491
|
dirname3(process.execPath),
|
|
20329
|
-
...getVersionManagerBinPaths(
|
|
20492
|
+
...getVersionManagerBinPaths(),
|
|
20330
20493
|
env.PATH,
|
|
20331
|
-
|
|
20332
|
-
"/usr/local/bin",
|
|
20333
|
-
join4(homedir3(), ".local", "bin")
|
|
20494
|
+
...currentPlatform.fallbackBinDirectories(homedir3())
|
|
20334
20495
|
].filter((value) => Boolean(value));
|
|
20335
20496
|
env.PATH = [...new Set(commandPaths)].join(delimiter4);
|
|
20336
20497
|
return env;
|
|
@@ -20338,15 +20499,30 @@ function providerEnvironment() {
|
|
|
20338
20499
|
function resolveExecutable(command, args, env, override) {
|
|
20339
20500
|
const candidate = override?.trim() || resolveCliCommand(command, env.PATH === void 0 ? {} : { pathEnv: env.PATH });
|
|
20340
20501
|
if (!candidate) return { executable: command, args, env };
|
|
20502
|
+
let resolved = candidate;
|
|
20341
20503
|
try {
|
|
20342
|
-
|
|
20343
|
-
if (resolved.endsWith(".js") || resolved.endsWith(".mjs") || resolved.endsWith(".cjs")) {
|
|
20344
|
-
return { executable: process.env.TOC_OCRA_NODE_PATH || process.execPath, args: [resolved, ...args], env };
|
|
20345
|
-
}
|
|
20346
|
-
return { executable: resolved, args, env };
|
|
20504
|
+
resolved = realpathSync(candidate);
|
|
20347
20505
|
} catch {
|
|
20348
|
-
return { executable: candidate, args, env };
|
|
20349
20506
|
}
|
|
20507
|
+
return { ...directLaunch2(resolved, args, process.env.TOC_OCRA_NODE_PATH || process.execPath), env };
|
|
20508
|
+
}
|
|
20509
|
+
function launchCli(options) {
|
|
20510
|
+
const launch = resolveExecutable(options.command, options.args, options.env ?? providerEnvironment(), process.env[options.overrideEnv]);
|
|
20511
|
+
return options.prompt && options.promptStdin ? fitPromptOnCommandLine(launch, options.prompt, options.promptStdin) : launch;
|
|
20512
|
+
}
|
|
20513
|
+
function fitsCommandLine(launch) {
|
|
20514
|
+
return commandLineLength(launch.executable, launch.args) <= currentPlatform.maxCommandLineLength;
|
|
20515
|
+
}
|
|
20516
|
+
function fitPromptOnCommandLine(launch, prompt, stdin) {
|
|
20517
|
+
if (!prompt || fitsCommandLine(launch)) return launch;
|
|
20518
|
+
const index = launch.args.lastIndexOf(prompt);
|
|
20519
|
+
if (index < 0) return launch;
|
|
20520
|
+
const args = [...launch.args];
|
|
20521
|
+
if (stdin === "omit") {
|
|
20522
|
+
const separator = index > 0 && args[index - 1] === "--" && index === args.length - 1;
|
|
20523
|
+
args.splice(separator ? index - 1 : index, separator ? 2 : 1);
|
|
20524
|
+
} else args[index] = stdin.replaceWith;
|
|
20525
|
+
return { ...launch, args, stdin: prompt };
|
|
20350
20526
|
}
|
|
20351
20527
|
function tryJson(line) {
|
|
20352
20528
|
const start = line.indexOf("{");
|
|
@@ -20382,7 +20558,7 @@ var claudeProvider = {
|
|
|
20382
20558
|
else {
|
|
20383
20559
|
args.push("--restricted", "--permission-mode", "plan", "--tools", "Read,Glob,Grep", "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--disallowedTools", "mcp__*", "--settings", '{"disableAllHooks":true}');
|
|
20384
20560
|
try {
|
|
20385
|
-
const settings = JSON.parse(
|
|
20561
|
+
const settings = JSON.parse(readFileSync4(join7(homedir4(), ".claude", "settings.json"), "utf8"));
|
|
20386
20562
|
for (const [key, value] of Object.entries(settings.env ?? {})) {
|
|
20387
20563
|
if (/^ANTHROPIC_[A-Z0-9_]+$/.test(key) && typeof value === "string" && env[key] === void 0) env[key] = value;
|
|
20388
20564
|
}
|
|
@@ -20392,7 +20568,7 @@ var claudeProvider = {
|
|
|
20392
20568
|
if (request.model) args.push("--model", request.model);
|
|
20393
20569
|
if (request.reasoningEffort) args.push("--effort", request.reasoningEffort);
|
|
20394
20570
|
if (request.sessionId) args.push("--resume", request.sessionId);
|
|
20395
|
-
return
|
|
20571
|
+
return launchCli({ command: "claude", overrideEnv: "TOC_OCRA_CLAUDE_PATH", args, env, prompt: request.prompt, promptStdin: "omit" });
|
|
20396
20572
|
},
|
|
20397
20573
|
parseLine(line) {
|
|
20398
20574
|
return claudeLineParser()(line);
|
|
@@ -20493,7 +20669,7 @@ var codexProvider = {
|
|
|
20493
20669
|
if (request.reasoningEffort) args.push("-c", `model_reasoning_effort=${JSON.stringify(request.reasoningEffort)}`);
|
|
20494
20670
|
if (request.sessionId) args.push("resume", request.sessionId);
|
|
20495
20671
|
args.push("--", request.prompt);
|
|
20496
|
-
return
|
|
20672
|
+
return launchCli({ command: "codex", overrideEnv: "TOC_OCRA_CODEX_PATH", args, prompt: request.prompt, promptStdin: { replaceWith: "-" } });
|
|
20497
20673
|
},
|
|
20498
20674
|
parseLine(line) {
|
|
20499
20675
|
const event = tryJson(line);
|
|
@@ -20549,7 +20725,7 @@ var geminiProvider = {
|
|
|
20549
20725
|
const args = ["-p", request.prompt, "--output-format", "json", "--yolo"];
|
|
20550
20726
|
if (request.model) args.push("--model", request.model);
|
|
20551
20727
|
if (request.sessionId) args.push("--resume", request.sessionId);
|
|
20552
|
-
return
|
|
20728
|
+
return launchCli({ command: "gemini", overrideEnv: "TOC_OCRA_GEMINI_PATH", args });
|
|
20553
20729
|
},
|
|
20554
20730
|
parseLine(line) {
|
|
20555
20731
|
const event = tryJson(line);
|
|
@@ -20574,7 +20750,7 @@ var grokProvider = {
|
|
|
20574
20750
|
if (request.model) args.push("--model", request.model);
|
|
20575
20751
|
if (request.reasoningEffort) args.push("--reasoning-effort", request.reasoningEffort);
|
|
20576
20752
|
if (request.sessionId) args.push("--resume", request.sessionId);
|
|
20577
|
-
return
|
|
20753
|
+
return launchCli({ command: "grok", overrideEnv: "TOC_OCRA_GROK_PATH", args });
|
|
20578
20754
|
},
|
|
20579
20755
|
parseLine(line) {
|
|
20580
20756
|
const event = tryJson(line);
|
|
@@ -20590,16 +20766,16 @@ var grokProvider = {
|
|
|
20590
20766
|
};
|
|
20591
20767
|
|
|
20592
20768
|
// src/providers/cli/kiro.ts
|
|
20593
|
-
import { execFile } from "node:child_process";
|
|
20769
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
20594
20770
|
import { promisify } from "node:util";
|
|
20595
20771
|
|
|
20596
20772
|
// src/providers/cli/kiro-session-log.ts
|
|
20597
20773
|
import { open as open2, readdir, readFile as readFile2, stat } from "node:fs/promises";
|
|
20598
20774
|
import { homedir as homedir5 } from "node:os";
|
|
20599
|
-
import { join as
|
|
20775
|
+
import { join as join8 } from "node:path";
|
|
20600
20776
|
var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "execute_bash", "bash"]);
|
|
20601
20777
|
function kiroSessionsDirectory() {
|
|
20602
|
-
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR ||
|
|
20778
|
+
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR || join8(homedir5(), ".kiro", "sessions", "cli");
|
|
20603
20779
|
}
|
|
20604
20780
|
var KiroSessionLog = class {
|
|
20605
20781
|
constructor(options) {
|
|
@@ -20618,7 +20794,7 @@ var KiroSessionLog = class {
|
|
|
20618
20794
|
/** Called before the CLI starts: a resumed log is followed from its current end. */
|
|
20619
20795
|
async begin() {
|
|
20620
20796
|
if (!this.options.sessionId) return;
|
|
20621
|
-
this.path =
|
|
20797
|
+
this.path = join8(this.directory, `${this.options.sessionId}.jsonl`);
|
|
20622
20798
|
this.offset = await stat(this.path).then((info) => info.size, () => 0);
|
|
20623
20799
|
}
|
|
20624
20800
|
/**
|
|
@@ -20631,11 +20807,11 @@ var KiroSessionLog = class {
|
|
|
20631
20807
|
const found = [];
|
|
20632
20808
|
for (const name of names) {
|
|
20633
20809
|
if (!name.endsWith(".json")) continue;
|
|
20634
|
-
const meta3 = await readFile2(
|
|
20810
|
+
const meta3 = await readFile2(join8(this.directory, name), "utf8").then((text) => JSON.parse(text), () => void 0);
|
|
20635
20811
|
const created = meta3?.created_at ? Date.parse(meta3.created_at) : NaN;
|
|
20636
20812
|
if (meta3?.cwd && sameFolder(meta3.cwd, this.options.workdir) && created >= this.options.startedAt - 2e3) found.push(name.slice(0, -5));
|
|
20637
20813
|
}
|
|
20638
|
-
if (found.length === 1) this.path =
|
|
20814
|
+
if (found.length === 1) this.path = join8(this.directory, `${found[0]}.jsonl`);
|
|
20639
20815
|
}
|
|
20640
20816
|
/** Reads entries appended since the last call. */
|
|
20641
20817
|
async refresh() {
|
|
@@ -20731,10 +20907,10 @@ function sameFolder(a, b) {
|
|
|
20731
20907
|
}
|
|
20732
20908
|
|
|
20733
20909
|
// src/providers/cli/kiro.ts
|
|
20734
|
-
var execFileAsync = promisify(
|
|
20910
|
+
var execFileAsync = promisify(execFile3);
|
|
20735
20911
|
var ANSI = /\u001b(?:\][^\u0007]*?(?:\u0007|\u001b\\)|\[[0-?]*[ -/]*[@-~]|[@-Z\\-_])/g;
|
|
20736
20912
|
function kiroLaunch(args) {
|
|
20737
|
-
return
|
|
20913
|
+
return launchCli({ command: "kiro-cli", overrideEnv: "TOC_OCRA_KIRO_PATH", args });
|
|
20738
20914
|
}
|
|
20739
20915
|
var LIST_SESSIONS = ["chat", "--list-sessions", "--format", "json"];
|
|
20740
20916
|
function parseKiroSessions(stdout) {
|
|
@@ -20760,7 +20936,7 @@ async function listKiroSessions(workdir, options = {}) {
|
|
|
20760
20936
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
20761
20937
|
if (attempt) await new Promise((resolve8) => setTimeout(resolve8, options.retryDelayMs ?? LIST_SESSIONS_RETRY_DELAY_MS));
|
|
20762
20938
|
try {
|
|
20763
|
-
const { stdout } = await execFileAsync(executable, args, { cwd: workdir, env, timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024 });
|
|
20939
|
+
const { stdout } = await execFileAsync(executable, args, { cwd: workdir, env, timeout: timeoutMs, maxBuffer: 8 * 1024 * 1024, windowsHide: true });
|
|
20764
20940
|
return parseKiroSessions(stdout);
|
|
20765
20941
|
} catch (error62) {
|
|
20766
20942
|
lastError = error62;
|
|
@@ -20786,7 +20962,7 @@ function kiroToolRows(text) {
|
|
|
20786
20962
|
return [runLog.tool("tool_call")];
|
|
20787
20963
|
}
|
|
20788
20964
|
function isKiroNoise(text) {
|
|
20789
|
-
return /^\[(INFO|DEBUG|WARN|TRACE)\]/.test(text) || /^\[ERROR\] \(node:\d+\) ExperimentalWarning/.test(text) || /^\(Use `node --trace-warnings/.test(text);
|
|
20965
|
+
return /^\[(INFO|DEBUG|WARN|TRACE)\]/.test(text) || /^\[ERROR\] \(node:\d+\) ExperimentalWarning/.test(text) || /^\(Use `node --trace-warnings/.test(text) || /^Warning: Kiro CLI is running as\b/i.test(text) || /^Hide this warning: kiro-cli settings\b/i.test(text);
|
|
20790
20966
|
}
|
|
20791
20967
|
function kiroRunParser(context) {
|
|
20792
20968
|
let pending = "";
|
|
@@ -20892,6 +21068,7 @@ function kiroRunParser(context) {
|
|
|
20892
21068
|
}
|
|
20893
21069
|
};
|
|
20894
21070
|
}
|
|
21071
|
+
var KIRO_IMAGE_LIMIT = "\u56FE\u7247\u8D85\u9650\uFF1A\u8FD9\u4E2A\u4F1A\u8BDD\u91CC\u7D2F\u8BA1\u7684\u56FE\u7247\u5DF2\u8D85\u8FC7\u6A21\u578B\u5355\u6B21\u5BF9\u8BDD\u7684\u4E0A\u9650\uFF08100 \u5F20\uFF09\uFF0C\u5728\u8FD9\u4E2A\u4F1A\u8BDD\u91CC\u7EE7\u7EED\u67E5\u770B\u56FE\u7247\u90FD\u4F1A\u5931\u8D25";
|
|
20895
21072
|
var kiroProvider = {
|
|
20896
21073
|
id: "kiro",
|
|
20897
21074
|
buildLaunch(request) {
|
|
@@ -20902,13 +21079,14 @@ var kiroProvider = {
|
|
|
20902
21079
|
if (request.reasoningEffort) args.push("--effort", request.reasoningEffort);
|
|
20903
21080
|
if (request.sessionId && !request.sessionId.startsWith("sess_")) args.push("--resume-id", request.sessionId);
|
|
20904
21081
|
args.push("--", request.prompt);
|
|
20905
|
-
return
|
|
21082
|
+
return launchCli({ command: "kiro-cli", overrideEnv: "TOC_OCRA_KIRO_PATH", args, prompt: request.prompt, promptStdin: "omit" });
|
|
20906
21083
|
},
|
|
20907
21084
|
listSessions: (workdir) => listKiroSessions(workdir),
|
|
20908
21085
|
isMissingSession: (stderr) => isKiroMissingSession(stderr),
|
|
20909
21086
|
inspectExit(context) {
|
|
20910
21087
|
const businessError = kiroStderrError(context.stderr);
|
|
20911
|
-
|
|
21088
|
+
if (!businessError) return {};
|
|
21089
|
+
return businessError === KIRO_IMAGE_LIMIT ? { turnError: businessError, display: [runLog.error(businessError)] } : { turnError: businessError };
|
|
20912
21090
|
},
|
|
20913
21091
|
/** A single stdout line read as a complete reply (the supervisor uses `createRunParser`). */
|
|
20914
21092
|
parseLine(line) {
|
|
@@ -20919,6 +21097,7 @@ var kiroProvider = {
|
|
|
20919
21097
|
};
|
|
20920
21098
|
function kiroStderrError(stderrLines) {
|
|
20921
21099
|
const text = stderrLines.join("\n");
|
|
21100
|
+
if (/too many inline media segments/i.test(text)) return KIRO_IMAGE_LIMIT;
|
|
20922
21101
|
if (/Monthly request limit reached|request limit reached/i.test(text)) {
|
|
20923
21102
|
return "Kiro \u672C\u6708\u989D\u5EA6\u5DF2\u7528\u5C3D\uFF0C\u8BF7\u5347\u7EA7\u5957\u9910\u6216\u7B49\u5F85\u989D\u5EA6\u91CD\u7F6E\u540E\u518D\u8BD5";
|
|
20924
21103
|
}
|
|
@@ -20941,7 +21120,7 @@ var opencodeProvider = {
|
|
|
20941
21120
|
if (request.model) args.push("--model", request.model);
|
|
20942
21121
|
if (request.sessionId) args.push("--session", request.sessionId);
|
|
20943
21122
|
args.push(request.prompt);
|
|
20944
|
-
return
|
|
21123
|
+
return launchCli({ command: "opencode", overrideEnv: "TOC_OCRA_OPENCODE_PATH", args });
|
|
20945
21124
|
},
|
|
20946
21125
|
parseLine(line) {
|
|
20947
21126
|
const event = tryJson(line);
|
|
@@ -21010,7 +21189,8 @@ function resolveDetectedProviderCommands(foundCommands, commands = DETECTION_COM
|
|
|
21010
21189
|
function probeVersion(path, args) {
|
|
21011
21190
|
if (args.length === 0) return Promise.resolve({});
|
|
21012
21191
|
return new Promise((resolve8) => {
|
|
21013
|
-
const
|
|
21192
|
+
const launch = directLaunch2(path, args);
|
|
21193
|
+
const child = spawn3(launch.executable, launch.args, { stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
21014
21194
|
let stdout = "";
|
|
21015
21195
|
let stderr = "";
|
|
21016
21196
|
let settled = false;
|
|
@@ -21090,7 +21270,7 @@ var CliDetectionService = class {
|
|
|
21090
21270
|
var cliDetection = new CliDetectionService();
|
|
21091
21271
|
|
|
21092
21272
|
// src/runtime/run-service.ts
|
|
21093
|
-
import { existsSync as existsSync5, readFileSync as
|
|
21273
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "node:fs";
|
|
21094
21274
|
import { dirname as dirname7, resolve as resolve6 } from "node:path";
|
|
21095
21275
|
import { fileURLToPath } from "node:url";
|
|
21096
21276
|
|
|
@@ -21335,9 +21515,9 @@ import {
|
|
|
21335
21515
|
chmodSync,
|
|
21336
21516
|
existsSync as existsSync4,
|
|
21337
21517
|
mkdirSync as mkdirSync2,
|
|
21338
|
-
readFileSync as
|
|
21518
|
+
readFileSync as readFileSync5,
|
|
21339
21519
|
renameSync,
|
|
21340
|
-
statSync as
|
|
21520
|
+
statSync as statSync3,
|
|
21341
21521
|
unlinkSync,
|
|
21342
21522
|
writeFileSync as writeFileSync2
|
|
21343
21523
|
} from "node:fs";
|
|
@@ -21367,7 +21547,7 @@ function createDiagnosticLogger(filePath, options = {}) {
|
|
|
21367
21547
|
try {
|
|
21368
21548
|
mkdirSync2(dirname4(filePath), { recursive: true });
|
|
21369
21549
|
pruneExpired();
|
|
21370
|
-
currentBytes = existsSync4(filePath) ?
|
|
21550
|
+
currentBytes = existsSync4(filePath) ? statSync3(filePath).size : 0;
|
|
21371
21551
|
} catch {
|
|
21372
21552
|
disabled = true;
|
|
21373
21553
|
}
|
|
@@ -21393,7 +21573,7 @@ function createDiagnosticLogger(filePath, options = {}) {
|
|
|
21393
21573
|
for (let index = 0; index <= maxRotatedFiles; index += 1) {
|
|
21394
21574
|
const path = index === 0 ? filePath : `${filePath}.${index}`;
|
|
21395
21575
|
if (!existsSync4(path)) continue;
|
|
21396
|
-
const kept =
|
|
21576
|
+
const kept = readFileSync5(path, "utf8").split("\n").filter((line) => {
|
|
21397
21577
|
if (!line.trim()) return false;
|
|
21398
21578
|
try {
|
|
21399
21579
|
const timestamp = Date.parse(JSON.parse(line).ts);
|
|
@@ -21453,16 +21633,24 @@ function createDiagnosticLogger(filePath, options = {}) {
|
|
|
21453
21633
|
|
|
21454
21634
|
// src/runtime/agent-runtime.ts
|
|
21455
21635
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
21456
|
-
import { join as
|
|
21636
|
+
import { join as join14 } from "node:path";
|
|
21637
|
+
|
|
21638
|
+
// src/exec/script-runner.ts
|
|
21639
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
21640
|
+
|
|
21641
|
+
// src/runs/process-tree.ts
|
|
21642
|
+
var KILL_GRACE_MS = 3e3;
|
|
21643
|
+
async function killProcessTree(rootPid, graceMs = KILL_GRACE_MS) {
|
|
21644
|
+
if (!Number.isInteger(rootPid) || rootPid <= 1) return;
|
|
21645
|
+
await currentPlatform.killProcessTree(rootPid, graceMs);
|
|
21646
|
+
}
|
|
21457
21647
|
|
|
21458
21648
|
// src/exec/script-runner.ts
|
|
21459
|
-
import { spawn as spawn3 } from "node:child_process";
|
|
21460
21649
|
var MAX_SCRIPT_OUTPUT_BYTES = 112 * 1024;
|
|
21461
21650
|
function executeScript(command, workdir, timeoutSeconds) {
|
|
21462
21651
|
return new Promise((resolveExecution) => {
|
|
21463
|
-
const
|
|
21464
|
-
const executable
|
|
21465
|
-
const args = windows ? ["/d", "/s", "/c", command] : ["-lc", command];
|
|
21652
|
+
const ownGroup = currentPlatform.runsInOwnProcessGroup;
|
|
21653
|
+
const { executable, args } = currentPlatform.scriptShell(command);
|
|
21466
21654
|
const startedAt = Date.now();
|
|
21467
21655
|
const stdout = [];
|
|
21468
21656
|
const stderr = [];
|
|
@@ -21488,11 +21676,12 @@ function executeScript(command, workdir, timeoutSeconds) {
|
|
|
21488
21676
|
};
|
|
21489
21677
|
let child;
|
|
21490
21678
|
try {
|
|
21491
|
-
child =
|
|
21679
|
+
child = spawn4(executable, args, {
|
|
21492
21680
|
cwd: workdir,
|
|
21493
21681
|
env: process.env,
|
|
21494
|
-
detached:
|
|
21682
|
+
detached: ownGroup,
|
|
21495
21683
|
shell: false,
|
|
21684
|
+
windowsHide: true,
|
|
21496
21685
|
stdio: ["ignore", "pipe", "pipe"]
|
|
21497
21686
|
});
|
|
21498
21687
|
} catch (error62) {
|
|
@@ -21509,7 +21698,8 @@ function executeScript(command, workdir, timeoutSeconds) {
|
|
|
21509
21698
|
const kill = () => {
|
|
21510
21699
|
if (child.exitCode !== null || child.killed) return;
|
|
21511
21700
|
try {
|
|
21512
|
-
if (
|
|
21701
|
+
if (ownGroup && child.pid) process.kill(-child.pid, "SIGKILL");
|
|
21702
|
+
else if (child.pid) void killProcessTree(child.pid, 0);
|
|
21513
21703
|
else child.kill("SIGKILL");
|
|
21514
21704
|
} catch {
|
|
21515
21705
|
try {
|
|
@@ -21861,16 +22051,16 @@ import { createHash } from "node:crypto";
|
|
|
21861
22051
|
import { stat as stat2 } from "node:fs/promises";
|
|
21862
22052
|
|
|
21863
22053
|
// src/providers/model-catalog.ts
|
|
21864
|
-
import { spawn as
|
|
22054
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
21865
22055
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
21866
22056
|
import { homedir as homedir6 } from "node:os";
|
|
21867
|
-
import { isAbsolute, join as
|
|
22057
|
+
import { isAbsolute, join as join9, resolve as resolve2 } from "node:path";
|
|
21868
22058
|
|
|
21869
22059
|
// src/providers/kiro-models.ts
|
|
21870
|
-
import { spawn as
|
|
22060
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
21871
22061
|
import { createInterface } from "node:readline";
|
|
21872
22062
|
async function readKiroNativeModels(launch, cwd, options = {}) {
|
|
21873
|
-
const child =
|
|
22063
|
+
const child = spawn5(launch.executable, launch.args, { cwd, env: launch.env, shell: false, windowsHide: true, stdio: ["pipe", "pipe", "pipe"] });
|
|
21874
22064
|
const lines = createInterface({ input: child.stdout });
|
|
21875
22065
|
let nextId = 0;
|
|
21876
22066
|
let failure2;
|
|
@@ -21942,7 +22132,7 @@ async function readKiroNativeModels(launch, cwd, options = {}) {
|
|
|
21942
22132
|
clearTimeout(timer);
|
|
21943
22133
|
lines.close();
|
|
21944
22134
|
child.stdin.end();
|
|
21945
|
-
|
|
22135
|
+
currentPlatform.stopHelper(child);
|
|
21946
22136
|
const killTimer = setTimeout(() => {
|
|
21947
22137
|
if (child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
|
|
21948
22138
|
}, 1e3);
|
|
@@ -21986,15 +22176,15 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
|
|
|
21986
22176
|
if (defaultModel) catalog.default_model = defaultModel;
|
|
21987
22177
|
return catalog;
|
|
21988
22178
|
}
|
|
21989
|
-
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
21990
|
-
var codexHome = () => process.env.CODEX_HOME?.trim() ||
|
|
21991
|
-
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() ||
|
|
21992
|
-
var grokHome = () => process.env.GROK_HOME?.trim() ||
|
|
21993
|
-
var opencodeHome = () =>
|
|
21994
|
-
var kiroHome = () =>
|
|
22179
|
+
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join9(homedir6(), ".claude");
|
|
22180
|
+
var codexHome = () => process.env.CODEX_HOME?.trim() || join9(homedir6(), ".codex");
|
|
22181
|
+
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() || join9(homedir6(), ".gemini");
|
|
22182
|
+
var grokHome = () => process.env.GROK_HOME?.trim() || join9(homedir6(), ".grok");
|
|
22183
|
+
var opencodeHome = () => join9(process.env.XDG_CONFIG_HOME?.trim() || join9(homedir6(), ".config"), "opencode");
|
|
22184
|
+
var kiroHome = () => join9(homedir6(), ".kiro");
|
|
21995
22185
|
async function readClaudeModelCatalog() {
|
|
21996
22186
|
const home = claudeHome();
|
|
21997
|
-
const content = await readFile4(
|
|
22187
|
+
const content = await readFile4(join9(home, "settings.json"), "utf8").catch(() => "");
|
|
21998
22188
|
let settings = {};
|
|
21999
22189
|
if (content) {
|
|
22000
22190
|
try {
|
|
@@ -22054,12 +22244,12 @@ async function readCodexModels(codexHome2, config2) {
|
|
|
22054
22244
|
if (configuredModels?.length) return configuredModels;
|
|
22055
22245
|
}
|
|
22056
22246
|
return parseCodexModels(
|
|
22057
|
-
await readFile4(
|
|
22247
|
+
await readFile4(join9(codexHome2, "models_cache.json"), "utf8").catch(() => "")
|
|
22058
22248
|
) ?? [];
|
|
22059
22249
|
}
|
|
22060
22250
|
async function readCodexModelCatalog() {
|
|
22061
22251
|
const home = codexHome();
|
|
22062
|
-
const config2 = await readFile4(
|
|
22252
|
+
const config2 = await readFile4(join9(home, "config.toml"), "utf8").catch(() => "");
|
|
22063
22253
|
const models = await readCodexModels(home, config2);
|
|
22064
22254
|
const defaultModel = configValue(config2, "model");
|
|
22065
22255
|
const defaultReasoningEffort = configValue(config2, "model_reasoning_effort");
|
|
@@ -22105,7 +22295,8 @@ function parseKiroModelCatalog(payload, fetchedAt = (/* @__PURE__ */ new Date())
|
|
|
22105
22295
|
var MODEL_LIST_TIMEOUT_MS = 2e4;
|
|
22106
22296
|
function runModelListCommand(executable, args, label, environment) {
|
|
22107
22297
|
return new Promise((resolve8, reject) => {
|
|
22108
|
-
const
|
|
22298
|
+
const launch = directLaunch2(executable, args);
|
|
22299
|
+
const child = spawn6(launch.executable, launch.args, { shell: false, windowsHide: true, ...environment ? { env: environment } : {}, stdio: ["ignore", "pipe", "pipe"] });
|
|
22109
22300
|
let stdout = "";
|
|
22110
22301
|
let stderr = "";
|
|
22111
22302
|
const timer = setTimeout(() => {
|
|
@@ -22150,7 +22341,7 @@ async function readKiroModelCatalog() {
|
|
|
22150
22341
|
const launch = resolveExecutable("kiro-cli", ["acp", "--trust-tools="], environment, override);
|
|
22151
22342
|
const [payload, content] = await Promise.all([
|
|
22152
22343
|
readKiroNativeModels(launch, homedir6(), { catalog: base }),
|
|
22153
|
-
readFile4(
|
|
22344
|
+
readFile4(join9(kiroHome(), "settings", "cli.json"), "utf8").catch(() => "{}")
|
|
22154
22345
|
]);
|
|
22155
22346
|
let settings;
|
|
22156
22347
|
try {
|
|
@@ -22207,7 +22398,7 @@ function geminiModelsUrl(baseUrl) {
|
|
|
22207
22398
|
}
|
|
22208
22399
|
async function readGeminiModelCatalog() {
|
|
22209
22400
|
const fileEnvironment = parseEnvFile(
|
|
22210
|
-
await readFile4(
|
|
22401
|
+
await readFile4(join9(geminiHome(), ".env"), "utf8").catch(() => "")
|
|
22211
22402
|
);
|
|
22212
22403
|
const environment = { ...fileEnvironment, ...process.env };
|
|
22213
22404
|
const baseUrl = environment.GOOGLE_GEMINI_BASE_URL?.trim();
|
|
@@ -22252,7 +22443,7 @@ function parseGrokModelCatalog(output2, config2 = "", fetchedAt = (/* @__PURE__
|
|
|
22252
22443
|
return catalog;
|
|
22253
22444
|
}
|
|
22254
22445
|
async function readGrokModelCatalog() {
|
|
22255
|
-
const config2 = await readFile4(
|
|
22446
|
+
const config2 = await readFile4(join9(grokHome(), "config.toml"), "utf8").catch(() => "");
|
|
22256
22447
|
const output2 = await runModelListCommand(resolveCliCommand("grok"), ["models"], "grok");
|
|
22257
22448
|
const catalog = parseGrokModelCatalog(output2, config2);
|
|
22258
22449
|
if (catalog.models.length === 0) throw new Error("Grok \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -22271,7 +22462,7 @@ function parseOpencodeModelCatalog(output2, config2 = "", fetchedAt = (/* @__PUR
|
|
|
22271
22462
|
return catalog;
|
|
22272
22463
|
}
|
|
22273
22464
|
async function readOpencodeModelCatalog() {
|
|
22274
|
-
const config2 = await readFile4(
|
|
22465
|
+
const config2 = await readFile4(join9(opencodeHome(), "opencode.json"), "utf8").catch(() => "") || await readFile4(join9(opencodeHome(), "opencode.jsonc"), "utf8").catch(() => "");
|
|
22275
22466
|
const output2 = await runModelListCommand(resolveCliCommand("opencode"), ["models"], "opencode");
|
|
22276
22467
|
const catalog = parseOpencodeModelCatalog(output2, config2);
|
|
22277
22468
|
if (catalog.models.length === 0) throw new Error("OpenCode \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -22279,22 +22470,22 @@ async function readOpencodeModelCatalog() {
|
|
|
22279
22470
|
}
|
|
22280
22471
|
var TEN_MINUTES = 10 * 60 * 1e3;
|
|
22281
22472
|
var MODEL_SOURCES = {
|
|
22282
|
-
claude: { read: readClaudeModelCatalog, watchFiles: () => [
|
|
22473
|
+
claude: { read: readClaudeModelCatalog, watchFiles: () => [join9(claudeHome(), "settings.json")] },
|
|
22283
22474
|
codex: {
|
|
22284
22475
|
read: readCodexModelCatalog,
|
|
22285
22476
|
watchFiles: () => {
|
|
22286
22477
|
const home = codexHome();
|
|
22287
|
-
return [
|
|
22478
|
+
return [join9(home, "config.toml"), join9(home, "models_cache.json")];
|
|
22288
22479
|
},
|
|
22289
22480
|
// model_catalog_json may point anywhere; a periodic re-read covers it.
|
|
22290
22481
|
refreshEveryMs: TEN_MINUTES
|
|
22291
22482
|
},
|
|
22292
|
-
gemini: { read: readGeminiModelCatalog, watchFiles: () => [
|
|
22293
|
-
grok: { read: readGrokModelCatalog, watchFiles: () => [
|
|
22294
|
-
kiro: { read: readKiroModelCatalog, watchFiles: () => [
|
|
22483
|
+
gemini: { read: readGeminiModelCatalog, watchFiles: () => [join9(geminiHome(), ".env")], refreshEveryMs: TEN_MINUTES },
|
|
22484
|
+
grok: { read: readGrokModelCatalog, watchFiles: () => [join9(grokHome(), "config.toml")], refreshEveryMs: TEN_MINUTES },
|
|
22485
|
+
kiro: { read: readKiroModelCatalog, watchFiles: () => [join9(kiroHome(), "settings", "cli.json")], refreshEveryMs: TEN_MINUTES },
|
|
22295
22486
|
opencode: {
|
|
22296
22487
|
read: readOpencodeModelCatalog,
|
|
22297
|
-
watchFiles: () => [
|
|
22488
|
+
watchFiles: () => [join9(opencodeHome(), "opencode.json"), join9(opencodeHome(), "opencode.jsonc")],
|
|
22298
22489
|
refreshEveryMs: TEN_MINUTES
|
|
22299
22490
|
}
|
|
22300
22491
|
};
|
|
@@ -22352,11 +22543,11 @@ var ModelCatalogCollector = class {
|
|
|
22352
22543
|
};
|
|
22353
22544
|
|
|
22354
22545
|
// src/providers/codex-quota.ts
|
|
22355
|
-
import { spawn as
|
|
22546
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
22356
22547
|
import { createInterface as createInterface2 } from "node:readline";
|
|
22357
22548
|
async function readCodexQuotaWindows() {
|
|
22358
22549
|
const launch = resolveExecutable("codex", ["app-server", "--stdio"], providerEnvironment(), process.env.TOC_OCRA_CODEX_PATH);
|
|
22359
|
-
const child =
|
|
22550
|
+
const child = spawn7(launch.executable, launch.args, { env: launch.env, stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
|
|
22360
22551
|
let nextId = 0;
|
|
22361
22552
|
const pending = /* @__PURE__ */ new Map();
|
|
22362
22553
|
const lines = createInterface2({ input: child.stdout });
|
|
@@ -22444,15 +22635,15 @@ async function readCodexQuotaWindows() {
|
|
|
22444
22635
|
for (const waiter of pending.values()) waiter.reject(new Error("Codex app-server \u5DF2\u5173\u95ED"));
|
|
22445
22636
|
pending.clear();
|
|
22446
22637
|
lines.close();
|
|
22447
|
-
|
|
22638
|
+
currentPlatform.stopHelper(child);
|
|
22448
22639
|
}
|
|
22449
22640
|
}
|
|
22450
22641
|
|
|
22451
22642
|
// src/providers/kiro-quota.ts
|
|
22452
|
-
import { execFile as
|
|
22643
|
+
import { execFile as execFile4 } from "node:child_process";
|
|
22453
22644
|
import { tmpdir } from "node:os";
|
|
22454
22645
|
import { promisify as promisify2, stripVTControlCharacters } from "node:util";
|
|
22455
|
-
var execFileAsync2 = promisify2(
|
|
22646
|
+
var execFileAsync2 = promisify2(execFile4);
|
|
22456
22647
|
var amount = (value) => Number(value.replace(/,/g, ""));
|
|
22457
22648
|
var rounded = (value) => Math.round(value * 100) / 100;
|
|
22458
22649
|
function parseKiroQuota(stdout, now = /* @__PURE__ */ new Date()) {
|
|
@@ -22539,14 +22730,14 @@ async function readCLIQuotaReport(agentType) {
|
|
|
22539
22730
|
// src/providers/tb-switch-control.ts
|
|
22540
22731
|
import { readFile as readFile5 } from "node:fs/promises";
|
|
22541
22732
|
import { homedir as homedir7 } from "node:os";
|
|
22542
|
-
import { join as
|
|
22733
|
+
import { join as join10 } from "node:path";
|
|
22543
22734
|
function dataDir() {
|
|
22544
|
-
return process.env.TB_SWITCH_HOME?.trim() ||
|
|
22735
|
+
return process.env.TB_SWITCH_HOME?.trim() || join10(homedir7(), ".tb-switch");
|
|
22545
22736
|
}
|
|
22546
22737
|
async function readLocalService() {
|
|
22547
22738
|
let discovery;
|
|
22548
22739
|
try {
|
|
22549
|
-
discovery = JSON.parse(await readFile5(
|
|
22740
|
+
discovery = JSON.parse(await readFile5(join10(dataDir(), "api.json"), "utf8"));
|
|
22550
22741
|
} catch {
|
|
22551
22742
|
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");
|
|
22552
22743
|
}
|
|
@@ -22562,7 +22753,7 @@ async function readLocalService() {
|
|
|
22562
22753
|
}
|
|
22563
22754
|
let token = process.env.TB_SWITCH_API_TOKEN?.trim() ?? "";
|
|
22564
22755
|
try {
|
|
22565
|
-
token = (await readFile5(
|
|
22756
|
+
token = (await readFile5(join10(dataDir(), "api-token"), "utf8")).trim();
|
|
22566
22757
|
} catch {
|
|
22567
22758
|
}
|
|
22568
22759
|
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");
|
|
@@ -22652,76 +22843,8 @@ async function controlTbSwitch(payload) {
|
|
|
22652
22843
|
}
|
|
22653
22844
|
|
|
22654
22845
|
// src/runs/orphan-registry.ts
|
|
22655
|
-
import { execFile as execFile4 } from "node:child_process";
|
|
22656
22846
|
import { mkdir as mkdir3, readFile as readFile6, rename as rename3, writeFile as writeFile3 } from "node:fs/promises";
|
|
22657
22847
|
import { basename, dirname as dirname5 } from "node:path";
|
|
22658
|
-
|
|
22659
|
-
// src/runs/process-tree.ts
|
|
22660
|
-
import { execFile as execFile3, spawn as spawn7 } from "node:child_process";
|
|
22661
|
-
var KILL_GRACE_MS = 3e3;
|
|
22662
|
-
function readProcessTable() {
|
|
22663
|
-
return new Promise((resolve8) => {
|
|
22664
|
-
execFile3("ps", ["-axo", "pid=,ppid="], { maxBuffer: 32 * 1024 * 1024, timeout: 2e3 }, (error62, stdout) => {
|
|
22665
|
-
if (error62) return resolve8([]);
|
|
22666
|
-
resolve8(stdout.split("\n").flatMap((line) => {
|
|
22667
|
-
const [pid, ppid] = line.trim().split(/\s+/).map(Number);
|
|
22668
|
-
return pid && ppid !== void 0 && Number.isFinite(ppid) ? [{ pid, ppid }] : [];
|
|
22669
|
-
}));
|
|
22670
|
-
});
|
|
22671
|
-
});
|
|
22672
|
-
}
|
|
22673
|
-
async function listDescendants(rootPid) {
|
|
22674
|
-
const rows = await readProcessTable();
|
|
22675
|
-
const children = /* @__PURE__ */ new Map();
|
|
22676
|
-
for (const row of rows) children.set(row.ppid, [...children.get(row.ppid) ?? [], row.pid]);
|
|
22677
|
-
const out = [];
|
|
22678
|
-
const queue = [...children.get(rootPid) ?? []];
|
|
22679
|
-
while (queue.length > 0) {
|
|
22680
|
-
const pid = queue.shift();
|
|
22681
|
-
if (out.includes(pid)) continue;
|
|
22682
|
-
out.push(pid);
|
|
22683
|
-
queue.push(...children.get(pid) ?? []);
|
|
22684
|
-
}
|
|
22685
|
-
return out;
|
|
22686
|
-
}
|
|
22687
|
-
function signal(pid, sig) {
|
|
22688
|
-
try {
|
|
22689
|
-
process.kill(pid, sig);
|
|
22690
|
-
} catch {
|
|
22691
|
-
}
|
|
22692
|
-
}
|
|
22693
|
-
function alive(pid) {
|
|
22694
|
-
try {
|
|
22695
|
-
process.kill(pid, 0);
|
|
22696
|
-
return true;
|
|
22697
|
-
} catch {
|
|
22698
|
-
return false;
|
|
22699
|
-
}
|
|
22700
|
-
}
|
|
22701
|
-
var sleep = (ms) => new Promise((resolve8) => setTimeout(resolve8, ms));
|
|
22702
|
-
async function killProcessTree(rootPid, graceMs = KILL_GRACE_MS) {
|
|
22703
|
-
if (!Number.isInteger(rootPid) || rootPid <= 1) return;
|
|
22704
|
-
if (process.platform === "win32") {
|
|
22705
|
-
await new Promise((resolve8) => {
|
|
22706
|
-
const child = spawn7("taskkill", ["/PID", String(rootPid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
|
|
22707
|
-
child.once("error", () => resolve8());
|
|
22708
|
-
child.once("close", () => resolve8());
|
|
22709
|
-
});
|
|
22710
|
-
return;
|
|
22711
|
-
}
|
|
22712
|
-
const descendants = await listDescendants(rootPid);
|
|
22713
|
-
signal(-rootPid, "SIGTERM");
|
|
22714
|
-
signal(rootPid, "SIGTERM");
|
|
22715
|
-
for (const pid of descendants) signal(pid, "SIGTERM");
|
|
22716
|
-
const members2 = [rootPid, ...descendants];
|
|
22717
|
-
const deadline = Date.now() + graceMs;
|
|
22718
|
-
while (Date.now() < deadline && members2.some(alive)) await sleep(100);
|
|
22719
|
-
const late = alive(rootPid) ? await listDescendants(rootPid) : [];
|
|
22720
|
-
signal(-rootPid, "SIGKILL");
|
|
22721
|
-
for (const pid of [...members2, ...late]) if (alive(pid)) signal(pid, "SIGKILL");
|
|
22722
|
-
}
|
|
22723
|
-
|
|
22724
|
-
// src/runs/orphan-registry.ts
|
|
22725
22848
|
var OrphanRegistry = class {
|
|
22726
22849
|
constructor(file2) {
|
|
22727
22850
|
this.file = file2;
|
|
@@ -22769,18 +22892,13 @@ var OrphanRegistry = class {
|
|
|
22769
22892
|
}
|
|
22770
22893
|
};
|
|
22771
22894
|
function commandOf(pid) {
|
|
22772
|
-
|
|
22773
|
-
return new Promise((resolve8) => {
|
|
22774
|
-
execFile4("ps", ["-o", "command=", "-p", String(pid)], { timeout: 2e3 }, (error62, stdout) => {
|
|
22775
|
-
resolve8(error62 ? void 0 : stdout.trim() || void 0);
|
|
22776
|
-
});
|
|
22777
|
-
});
|
|
22895
|
+
return currentPlatform.processCommandLine(pid);
|
|
22778
22896
|
}
|
|
22779
22897
|
|
|
22780
22898
|
// src/runs/run-supervisor.ts
|
|
22781
22899
|
import { spawn as spawn8 } from "node:child_process";
|
|
22782
22900
|
import { mkdir as mkdir5, realpath as realpath2, stat as stat3, writeFile as writeFile5 } from "node:fs/promises";
|
|
22783
|
-
import { basename as basename3, isAbsolute as isAbsolute3, join as
|
|
22901
|
+
import { basename as basename3, isAbsolute as isAbsolute3, join as join12, relative as relative2, resolve as resolve3 } from "node:path";
|
|
22784
22902
|
import { createInterface as createInterface3 } from "node:readline";
|
|
22785
22903
|
|
|
22786
22904
|
// src/session/terminal-line-sanitizer.ts
|
|
@@ -22907,7 +23025,7 @@ function clipToCharacterBudget(rows, budget) {
|
|
|
22907
23025
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
22908
23026
|
import { constants as constants2 } from "node:fs";
|
|
22909
23027
|
import { lstat, mkdir as mkdir4, open as open3, realpath, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
22910
|
-
import { basename as basename2, isAbsolute as isAbsolute2, join as
|
|
23028
|
+
import { basename as basename2, isAbsolute as isAbsolute2, join as join11, relative } from "node:path";
|
|
22911
23029
|
function within(root, path) {
|
|
22912
23030
|
const segment = relative(root, path);
|
|
22913
23031
|
return segment === "" || !segment.startsWith("..") && !isAbsolute2(segment);
|
|
@@ -22915,7 +23033,7 @@ function within(root, path) {
|
|
|
22915
23033
|
async function attachmentDirectory(workdir, messageId) {
|
|
22916
23034
|
let directory = workdir;
|
|
22917
23035
|
for (const segment of [".echo", "attachments", `message-${encodeURIComponent(messageId).slice(0, 180)}`]) {
|
|
22918
|
-
directory =
|
|
23036
|
+
directory = join11(directory, segment);
|
|
22919
23037
|
await mkdir4(directory, { mode: 448 }).catch((error62) => {
|
|
22920
23038
|
if (error62.code !== "EEXIST") throw error62;
|
|
22921
23039
|
});
|
|
@@ -22923,7 +23041,7 @@ async function attachmentDirectory(workdir, messageId) {
|
|
|
22923
23041
|
if (metadata.isSymbolicLink() || !metadata.isDirectory() || !within(workdir, await realpath(directory))) {
|
|
22924
23042
|
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");
|
|
22925
23043
|
}
|
|
22926
|
-
if (segment === ".echo") await writeFile4(
|
|
23044
|
+
if (segment === ".echo") await writeFile4(join11(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
|
|
22927
23045
|
if (error62.code !== "EEXIST") throw error62;
|
|
22928
23046
|
});
|
|
22929
23047
|
}
|
|
@@ -22960,9 +23078,9 @@ async function prepareTaskAttachments(payload, workdir, download, signal2) {
|
|
|
22960
23078
|
const characters = Array.from(basename2(file2.name.replace(/\\/g, "/")).replace(/[^\p{L}\p{N}._-]/gu, "_").replace(/\.+$/u, ""));
|
|
22961
23079
|
while (Buffer.byteLength(characters.join("")) > 160) characters.shift();
|
|
22962
23080
|
const name = characters.join("") || "attachment";
|
|
22963
|
-
const path =
|
|
23081
|
+
const path = join11(directory, `${file2.file_id}-${name}`);
|
|
22964
23082
|
if (!await matches(path, file2.size, file2.sha256, signal2)) {
|
|
22965
|
-
const temporary =
|
|
23083
|
+
const temporary = join11(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
|
|
22966
23084
|
try {
|
|
22967
23085
|
await download(payload.run_id, file2.file_id, temporary, file2.size, file2.sha256, signal2);
|
|
22968
23086
|
signal2.throwIfAborted();
|
|
@@ -22987,6 +23105,7 @@ ${paths.join("\n")}`;
|
|
|
22987
23105
|
|
|
22988
23106
|
// src/runs/run-supervisor.ts
|
|
22989
23107
|
var COMPLETION_EXIT_GRACE_MS = 15e3;
|
|
23108
|
+
var EXIT_OUTPUT_GRACE_MS = 2e3;
|
|
22990
23109
|
var RECENT_RUN_TTL_MS = 10 * 6e4;
|
|
22991
23110
|
var MAX_RECENT_RUNS = 100;
|
|
22992
23111
|
var MAX_ERROR_ROWS = 40;
|
|
@@ -23176,15 +23295,16 @@ var RunSupervisor = class {
|
|
|
23176
23295
|
reasoningEffort: payload.reasoning_effort,
|
|
23177
23296
|
workdir
|
|
23178
23297
|
});
|
|
23298
|
+
if (!fitsCommandLine(launch)) return refuse(`\u6D88\u606F\u8FC7\u957F\uFF0C\u8D85\u51FA\u672C\u673A\u547D\u4EE4\u884C\u957F\u5EA6\u4E0A\u9650\uFF0C${provider.id} \u6682\u4E0D\u652F\u6301\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6\u63D0\u793A\u8BCD\uFF0C\u8BF7\u7F29\u77ED\u6D88\u606F\u540E\u91CD\u8BD5`);
|
|
23179
23299
|
let child;
|
|
23180
23300
|
try {
|
|
23181
23301
|
child = spawn8(launch.executable, launch.args, {
|
|
23182
23302
|
cwd: workdir,
|
|
23183
23303
|
env: launch.env,
|
|
23184
|
-
detached:
|
|
23304
|
+
detached: currentPlatform.runsInOwnProcessGroup,
|
|
23185
23305
|
shell: false,
|
|
23186
23306
|
windowsHide: true,
|
|
23187
|
-
stdio: [provider.startInput ? "pipe" : "ignore", "pipe", "pipe"]
|
|
23307
|
+
stdio: [provider.startInput || launch.stdin !== void 0 ? "pipe" : "ignore", "pipe", "pipe"]
|
|
23188
23308
|
});
|
|
23189
23309
|
} catch (error62) {
|
|
23190
23310
|
return refuse(`\u65E0\u6CD5\u542F\u52A8 ${provider.id}\uFF1A${errorMessage(error62)}`);
|
|
@@ -23247,6 +23367,7 @@ var RunSupervisor = class {
|
|
|
23247
23367
|
this.logger.info("run-started", { runId: run2.runId, agentType: provider.id, pid: run2.pid, resume: Boolean(sessionId) });
|
|
23248
23368
|
let spawnError = "";
|
|
23249
23369
|
child.stdin?.on("error", () => void 0);
|
|
23370
|
+
if (launch.stdin !== void 0 && !provider.startInput) child.stdin?.end(launch.stdin, "utf8");
|
|
23250
23371
|
child.once("error", (error62) => {
|
|
23251
23372
|
spawnError = error62.message;
|
|
23252
23373
|
});
|
|
@@ -23274,7 +23395,22 @@ var RunSupervisor = class {
|
|
|
23274
23395
|
}
|
|
23275
23396
|
}
|
|
23276
23397
|
});
|
|
23277
|
-
|
|
23398
|
+
let exited = false;
|
|
23399
|
+
const finish = (code2, signal3) => {
|
|
23400
|
+
if (exited) return;
|
|
23401
|
+
exited = true;
|
|
23402
|
+
void this.onExit(run2, code2, signal3, spawnError);
|
|
23403
|
+
};
|
|
23404
|
+
child.once("exit", (code2, signal3) => {
|
|
23405
|
+
run2.timers.push(setTimeout(() => {
|
|
23406
|
+
if (exited) return;
|
|
23407
|
+
this.logger.warn("run-output-held", { runId: run2.runId, pid: run2.pid });
|
|
23408
|
+
child.stdout?.destroy();
|
|
23409
|
+
child.stderr?.destroy();
|
|
23410
|
+
finish(code2, signal3);
|
|
23411
|
+
}, EXIT_OUTPUT_GRACE_MS));
|
|
23412
|
+
});
|
|
23413
|
+
child.once("close", (code2, signal3) => finish(code2, signal3));
|
|
23278
23414
|
if (provider.startInput) {
|
|
23279
23415
|
child.once("spawn", () => {
|
|
23280
23416
|
try {
|
|
@@ -23350,6 +23486,7 @@ var RunSupervisor = class {
|
|
|
23350
23486
|
}
|
|
23351
23487
|
async onExit(run2, code2, signal2, spawnError) {
|
|
23352
23488
|
for (const timer of run2.timers) clearTimeout(timer);
|
|
23489
|
+
run2.timers = [];
|
|
23353
23490
|
if (run2.stream) this.applyParsed(run2, await run2.stream.end(), "");
|
|
23354
23491
|
this.active.delete(run2.runId);
|
|
23355
23492
|
this.orphans?.remove(run2.runId);
|
|
@@ -23486,12 +23623,12 @@ var RunSupervisor = class {
|
|
|
23486
23623
|
async prepareChatAttachments(payload) {
|
|
23487
23624
|
if (!payload.attachments?.length) return [];
|
|
23488
23625
|
if (!this.reporter.chatMedia) throw new Error("\u9644\u4EF6\u8F6C\u53D1\u672A\u914D\u7F6E");
|
|
23489
|
-
const directory =
|
|
23626
|
+
const directory = join12(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
|
|
23490
23627
|
await mkdir5(directory, { recursive: true, mode: 448 });
|
|
23491
23628
|
const files = [];
|
|
23492
23629
|
for (const attachment of payload.attachments) {
|
|
23493
23630
|
const name = basename3(attachment.name).replace(/[^\p{L}\p{N}._-]/gu, "_").slice(-120) || "attachment";
|
|
23494
|
-
const path =
|
|
23631
|
+
const path = join12(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
|
|
23495
23632
|
const existing = await stat3(path).catch(() => void 0);
|
|
23496
23633
|
if (!existing?.isFile()) {
|
|
23497
23634
|
const data = await this.reporter.chatMedia(payload.run_id, attachment.media_id);
|
|
@@ -23768,7 +23905,7 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
23768
23905
|
import { spawn as spawn9 } from "node:child_process";
|
|
23769
23906
|
import { chmod as chmod3, mkdir as mkdir6, mkdtemp, opendir, realpath as realpath4, rm as rm3, stat as stat5, writeFile as writeFile6 } from "node:fs/promises";
|
|
23770
23907
|
import { homedir as homedir9, tmpdir as tmpdir2 } from "node:os";
|
|
23771
|
-
import { isAbsolute as isAbsolute4, join as
|
|
23908
|
+
import { isAbsolute as isAbsolute4, join as join13, relative as relative3, resolve as resolve5 } from "node:path";
|
|
23772
23909
|
var MAX_NODES = 2e3;
|
|
23773
23910
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
23774
23911
|
var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
@@ -24143,12 +24280,12 @@ var WorkspaceManager = class {
|
|
|
24143
24280
|
}
|
|
24144
24281
|
async createGitAuthEnvironment(auth) {
|
|
24145
24282
|
if (!auth) return void 0;
|
|
24146
|
-
const directory = await mkdtemp(
|
|
24283
|
+
const directory = await mkdtemp(join13(tmpdir2(), "toc-ocra-git-auth-"));
|
|
24147
24284
|
const isWindows = process.platform === "win32";
|
|
24148
|
-
const scriptPath =
|
|
24285
|
+
const scriptPath = join13(directory, isWindows ? "askpass.cmd" : "askpass.sh");
|
|
24149
24286
|
let script;
|
|
24150
24287
|
if (isWindows) {
|
|
24151
|
-
const helperPath =
|
|
24288
|
+
const helperPath = join13(directory, "askpass.cjs");
|
|
24152
24289
|
await writeFile6(
|
|
24153
24290
|
helperPath,
|
|
24154
24291
|
'const prompt = process.argv.slice(2).join(" ");\nprocess.stdout.write(/username/i.test(prompt) ? process.env.ECHO_GIT_USERNAME ?? "" : process.env.ECHO_GIT_PASSWORD ?? "");\n',
|
|
@@ -24298,7 +24435,7 @@ var AgentRuntime = class {
|
|
|
24298
24435
|
}
|
|
24299
24436
|
};
|
|
24300
24437
|
this.workspaces = new WorkspaceManager(config2, this.logger);
|
|
24301
|
-
this.orphans = new OrphanRegistry(
|
|
24438
|
+
this.orphans = new OrphanRegistry(join14(config2.dataDir, "active-runs.json"));
|
|
24302
24439
|
this.runs = new RunSupervisor(config2, this.logger, reporter, this.orphans);
|
|
24303
24440
|
}
|
|
24304
24441
|
config;
|
|
@@ -24945,7 +25082,7 @@ function agentPackageRoot() {
|
|
|
24945
25082
|
const packagePath = resolve6(directory, "package.json");
|
|
24946
25083
|
if (existsSync5(packagePath)) {
|
|
24947
25084
|
try {
|
|
24948
|
-
const info = JSON.parse(
|
|
25085
|
+
const info = JSON.parse(readFileSync6(packagePath, "utf8"));
|
|
24949
25086
|
if (info.name === PACKAGE_NAME && typeof info.version === "string") return directory;
|
|
24950
25087
|
} catch {
|
|
24951
25088
|
}
|
|
@@ -24957,7 +25094,7 @@ function agentPackageRoot() {
|
|
|
24957
25094
|
}
|
|
24958
25095
|
function agentVersion() {
|
|
24959
25096
|
const root = agentPackageRoot();
|
|
24960
|
-
return root ? JSON.parse(
|
|
25097
|
+
return root ? JSON.parse(readFileSync6(resolve6(root, "package.json"), "utf8")).version : "unknown";
|
|
24961
25098
|
}
|
|
24962
25099
|
async function runService(options = {}) {
|
|
24963
25100
|
const version2 = agentVersion();
|
|
@@ -25006,7 +25143,7 @@ async function runService(options = {}) {
|
|
|
25006
25143
|
}
|
|
25007
25144
|
|
|
25008
25145
|
// src/index.ts
|
|
25009
|
-
var { currentInstallation, installShared, ensureIdle, compareVersions } = createRequire(import.meta.url)(
|
|
25146
|
+
var { currentInstallation, installShared, ensureIdle, compareVersions } = createRequire(import.meta.url)(join15(agentPackageRoot(), "scripts", "installation.cjs"));
|
|
25010
25147
|
async function run() {
|
|
25011
25148
|
try {
|
|
25012
25149
|
await runService();
|
|
@@ -25108,8 +25245,8 @@ async function update(args) {
|
|
|
25108
25245
|
const customConfig = option(args, "--config");
|
|
25109
25246
|
if (customConfig) process.env.TOC_OCRA_CONFIG = resolve7(customConfig);
|
|
25110
25247
|
await ensureIdle();
|
|
25111
|
-
const
|
|
25112
|
-
const temporary = mkdtempSync(
|
|
25248
|
+
const npmPath = resolveCliCommand("npm");
|
|
25249
|
+
const temporary = mkdtempSync(join15(tmpdir3(), "toc-ocra-update-"));
|
|
25113
25250
|
try {
|
|
25114
25251
|
const metadataResponse = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`, { headers: { accept: "application/json", "cache-control": "no-cache" }, signal: AbortSignal.timeout(15e3) });
|
|
25115
25252
|
if (!metadataResponse.ok) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 npm \u6700\u65B0\u7248\u672C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
@@ -25136,16 +25273,17 @@ async function update(args) {
|
|
|
25136
25273
|
}
|
|
25137
25274
|
const archive = Buffer.concat(chunks);
|
|
25138
25275
|
if (`sha512-${createHash4("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");
|
|
25139
|
-
const archivePath =
|
|
25276
|
+
const archivePath = join15(temporary, "toc-ocra.tgz");
|
|
25140
25277
|
writeFileSync3(archivePath, archive, { mode: 384 });
|
|
25141
|
-
const
|
|
25278
|
+
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]);
|
|
25279
|
+
const install = spawnSync(npm.executable, npm.args, { stdio: "inherit", shell: false, windowsHide: true });
|
|
25142
25280
|
if (install.error) throw install.error;
|
|
25143
25281
|
if (install.status !== 0) {
|
|
25144
25282
|
process.exitCode = install.status ?? 1;
|
|
25145
25283
|
return;
|
|
25146
25284
|
}
|
|
25147
25285
|
const previousVersion = agentVersion();
|
|
25148
|
-
const current = await installShared(
|
|
25286
|
+
const current = await installShared(join15(temporary, "node_modules", PACKAGE_NAME), { startService: existsSync6(defaultConfigPath()) });
|
|
25149
25287
|
if (current.version === previousVersion) process.stdout.write(`toc-ocra \u5DF2\u662F\u6700\u65B0\u7248\u672C ${current.version}
|
|
25150
25288
|
`);
|
|
25151
25289
|
else process.stdout.write(`toc-ocra \u5DF2\u5347\u7EA7\u5230 ${current.version}\uFF0C\u7EC8\u7AEF\u4E0E Echo \u63D2\u4EF6\u5171\u7528\u6B64\u7248\u672C
|
|
@@ -25171,7 +25309,7 @@ async function main() {
|
|
|
25171
25309
|
const shared = currentInstallation();
|
|
25172
25310
|
if (root && root.split(/[\\/]/).includes("node_modules") && root !== shared?.root) {
|
|
25173
25311
|
const selected = !shared || compareVersions(agentVersion(), shared.version) > 0 ? await installShared(root) : shared;
|
|
25174
|
-
await import(pathToFileURL(
|
|
25312
|
+
await import(pathToFileURL(join15(selected.root, "dist", "cli", "cli.mjs")).href);
|
|
25175
25313
|
return;
|
|
25176
25314
|
}
|
|
25177
25315
|
const command = process.argv[2] ?? "run";
|