toc-ocra 0.3.10 → 0.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/cli/cli.mjs +167 -291
- package/dist/plugin/renderer.js +1 -1
- package/dist/plugin/renderer.js.map +3 -3
- package/dist/service/agent.mjs +159 -282
- package/dist/src/acp/acp-launch-specs.js +9 -0
- package/dist/src/acp/acp-launch-specs.js.map +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/platform/win32.js +84 -12
- package/dist/src/platform/win32.js.map +1 -1
- package/dist/src/providers/cli-specs.js +1 -0
- package/dist/src/providers/cli-specs.js.map +1 -1
- package/dist/src/providers/detection.js +10 -6
- package/dist/src/providers/detection.js.map +1 -1
- package/dist/src/providers/provider.js +1 -1
- package/dist/src/providers/provider.js.map +1 -1
- package/dist/src/runtime/agent-runtime.d.ts +1 -2
- package/dist/src/runtime/agent-runtime.js +8 -11
- package/dist/src/runtime/agent-runtime.js.map +1 -1
- package/dist/src/runtime/agent-service.js +4 -2
- package/dist/src/runtime/agent-service.js.map +1 -1
- package/dist/src/shared/node-cli-command-resolution.js +5 -1
- package/dist/src/shared/node-cli-command-resolution.js.map +1 -1
- package/dist/src/types/protocol.d.ts +4 -23
- package/dist/src/types/protocol.js +4 -11
- package/dist/src/types/protocol.js.map +1 -1
- package/dist/src/workspace/directory-browser.d.ts +4 -0
- package/dist/src/workspace/directory-browser.js +43 -5
- package/dist/src/workspace/directory-browser.js.map +1 -1
- package/dist/src/workspace/workspace-manager.d.ts +1 -12
- package/dist/src/workspace/workspace-manager.js +5 -216
- package/dist/src/workspace/workspace-manager.js.map +1 -1
- package/locales/en.json +1 -0
- package/locales/zh-CN.json +1 -0
- package/package.json +1 -1
- package/scripts/service.mjs +48 -12
package/dist/service/agent.mjs
CHANGED
|
@@ -20543,11 +20543,12 @@ function createPosixPlatform(id) {
|
|
|
20543
20543
|
|
|
20544
20544
|
// src/platform/win32.ts
|
|
20545
20545
|
import { execFile as execFile2, spawn as spawn2 } from "node:child_process";
|
|
20546
|
-
import { readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
|
|
20547
|
-
import { join as join5, win32 } from "node:path";
|
|
20546
|
+
import { readFileSync as readFileSync4, readdirSync, statSync as statSync3 } from "node:fs";
|
|
20547
|
+
import { dirname as dirname3, join as join5, win32 } from "node:path";
|
|
20548
20548
|
var SYSTEM_ROOT = process.env.SystemRoot || process.env.windir || "C:\\Windows";
|
|
20549
20549
|
var POWERSHELL = join5(SYSTEM_ROOT, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
20550
20550
|
var HELPER_TIMEOUT_MS = 5e3;
|
|
20551
|
+
var bundledCliDirectories = [];
|
|
20551
20552
|
var SHIM_TARGET_RE = /%~?dp0%?\\?([^"%\r\n]+)/gi;
|
|
20552
20553
|
var SHIM_TARGET_EXTENSIONS = /\.(c|m)?js$|\.exe$/i;
|
|
20553
20554
|
var MAX_SHIM_BYTES = 64 * 1024;
|
|
@@ -20596,6 +20597,47 @@ function runPowerShell(script) {
|
|
|
20596
20597
|
function expandVariables(value) {
|
|
20597
20598
|
return value.replace(/%([^%;]+)%/g, (whole2, name) => process.env[name] ?? whole2);
|
|
20598
20599
|
}
|
|
20600
|
+
async function bundledCodexDirectories() {
|
|
20601
|
+
const local = process.env.LOCALAPPDATA;
|
|
20602
|
+
const roots = [local, process.env.ProgramFiles, process.env["ProgramFiles(x86)"]].filter((value) => Boolean(value)).flatMap((base) => ["ChatGPT", "Codex", join5("Programs", "ChatGPT"), join5("Programs", "Codex")].map((name) => join5(base, name)));
|
|
20603
|
+
const result = await runPowerShell("@(Get-AppxPackage -ErrorAction SilentlyContinue | Where-Object { $_.Name -match 'OpenAI|ChatGPT|Codex' } | Select-Object -ExpandProperty InstallLocation) | ConvertTo-Json -Compress");
|
|
20604
|
+
if (result.ok) {
|
|
20605
|
+
try {
|
|
20606
|
+
const locations = JSON.parse(result.stdout.trim());
|
|
20607
|
+
for (const location of Array.isArray(locations) ? locations : [locations]) {
|
|
20608
|
+
if (typeof location === "string" && location) roots.push(location);
|
|
20609
|
+
}
|
|
20610
|
+
} catch {
|
|
20611
|
+
}
|
|
20612
|
+
}
|
|
20613
|
+
const found = /* @__PURE__ */ new Set();
|
|
20614
|
+
for (const root2 of new Set(roots)) {
|
|
20615
|
+
const pending = ["resources", join5("app", "resources"), "codex-cli", join5("app", "codex-cli")].map((relative4) => ({ directory: join5(root2, relative4), depth: 0 }));
|
|
20616
|
+
for (let visited = 0; pending.length && visited < 256; visited++) {
|
|
20617
|
+
const { directory, depth } = pending.shift();
|
|
20618
|
+
try {
|
|
20619
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
20620
|
+
const file2 = join5(directory, entry.name);
|
|
20621
|
+
if (entry.isFile() && entry.name.toLowerCase() === "codex.exe") found.add(dirname3(file2));
|
|
20622
|
+
else if (entry.isDirectory() && depth < 5) pending.push({ directory: file2, depth: depth + 1 });
|
|
20623
|
+
}
|
|
20624
|
+
} catch {
|
|
20625
|
+
}
|
|
20626
|
+
}
|
|
20627
|
+
}
|
|
20628
|
+
return [...found];
|
|
20629
|
+
}
|
|
20630
|
+
function npmPrefix(home) {
|
|
20631
|
+
let prefix = process.env.npm_config_prefix ?? process.env.NPM_CONFIG_PREFIX;
|
|
20632
|
+
if (!prefix) {
|
|
20633
|
+
try {
|
|
20634
|
+
prefix = /^\s*prefix\s*=\s*(.+?)\s*$/mi.exec(readFileSync4(process.env.NPM_CONFIG_USERCONFIG ?? join5(home, ".npmrc"), "utf8"))?.[1];
|
|
20635
|
+
} catch {
|
|
20636
|
+
}
|
|
20637
|
+
}
|
|
20638
|
+
if (!prefix) return void 0;
|
|
20639
|
+
return expandVariables(prefix.replace(/^(["'])(.*)\1$/, "$2").replace(/^~(?=[\\/]|$)/, home).replace(/\$\{([^}]+)\}/g, (whole2, name) => process.env[name] ?? whole2));
|
|
20640
|
+
}
|
|
20599
20641
|
async function readRegistryEnvironment() {
|
|
20600
20642
|
const names = [...new Set(PROXY_KEYS.map((key) => key.toLowerCase()))];
|
|
20601
20643
|
const script = [
|
|
@@ -20606,7 +20648,8 @@ async function readRegistryEnvironment() {
|
|
|
20606
20648
|
"$v=[Environment]::GetEnvironmentVariable($k,'User');if(-not $v){$v=[Environment]::GetEnvironmentVariable($k,'Machine')};if($v){$r.proxy[$k]=$v}};",
|
|
20607
20649
|
"$r|ConvertTo-Json -Compress -Depth 4"
|
|
20608
20650
|
].join("");
|
|
20609
|
-
const result = await runPowerShell(script);
|
|
20651
|
+
const [result, bundled] = await Promise.all([runPowerShell(script), bundledCodexDirectories()]);
|
|
20652
|
+
bundledCliDirectories = bundled;
|
|
20610
20653
|
if (!result.ok) return { ok: false, segments: [], failureReason: result.reason };
|
|
20611
20654
|
let parsed;
|
|
20612
20655
|
try {
|
|
@@ -20615,7 +20658,7 @@ async function readRegistryEnvironment() {
|
|
|
20615
20658
|
return { ok: false, segments: [], failureReason: "empty_path" };
|
|
20616
20659
|
}
|
|
20617
20660
|
const raw = (Array.isArray(parsed.path) ? parsed.path : [parsed.path]).filter((value) => typeof value === "string");
|
|
20618
|
-
const segments = [...new Set(raw.flatMap((value) => value.split(";")).map((segment) => expandVariables(segment.trim())).filter(Boolean))];
|
|
20661
|
+
const segments = [...new Set(raw.flatMap((value) => value.split(";")).map((segment) => expandVariables(segment.trim().replace(/^"(.*)"$/, "$1"))).filter(Boolean))];
|
|
20619
20662
|
if (segments.length === 0) return { ok: false, segments: [], failureReason: "empty_path" };
|
|
20620
20663
|
const proxyEnv = Object.fromEntries(Object.entries(parsed.proxy ?? {}).filter((entry) => typeof entry[1] === "string" && entry[1].length > 0));
|
|
20621
20664
|
return { ok: true, segments, proxyEnv, failureReason: "none" };
|
|
@@ -20630,14 +20673,29 @@ var win32Platform = {
|
|
|
20630
20673
|
return false;
|
|
20631
20674
|
}
|
|
20632
20675
|
},
|
|
20633
|
-
userBinDirectories: (home) =>
|
|
20634
|
-
|
|
20635
|
-
|
|
20636
|
-
|
|
20637
|
-
|
|
20638
|
-
|
|
20639
|
-
|
|
20640
|
-
|
|
20676
|
+
userBinDirectories: (home) => {
|
|
20677
|
+
const roaming = process.env.APPDATA ?? join5(home, "AppData", "Roaming");
|
|
20678
|
+
const local = process.env.LOCALAPPDATA ?? join5(home, "AppData", "Local");
|
|
20679
|
+
return [
|
|
20680
|
+
// Native Windows CLI installers use this directory even without PATH.
|
|
20681
|
+
join5(home, ".local", "bin"),
|
|
20682
|
+
join5(roaming, "npm"),
|
|
20683
|
+
join5(roaming, "pnpm"),
|
|
20684
|
+
join5(local, "pnpm"),
|
|
20685
|
+
join5(local, "Yarn", "bin"),
|
|
20686
|
+
join5(local, "Microsoft", "WindowsApps"),
|
|
20687
|
+
join5(local, "Microsoft", "WinGet", "Links"),
|
|
20688
|
+
join5(home, "npm-global"),
|
|
20689
|
+
join5(process.env.SCOOP ?? join5(home, "scoop"), "shims"),
|
|
20690
|
+
npmPrefix(home),
|
|
20691
|
+
process.env.PNPM_HOME,
|
|
20692
|
+
process.env.NVM_SYMLINK,
|
|
20693
|
+
process.env.NVM_HOME,
|
|
20694
|
+
process.env.FNM_MULTISHELL_PATH,
|
|
20695
|
+
process.env.VOLTA_HOME && join5(process.env.VOLTA_HOME, "bin"),
|
|
20696
|
+
...bundledCliDirectories
|
|
20697
|
+
].filter((value) => Boolean(value));
|
|
20698
|
+
},
|
|
20641
20699
|
fallbackBinDirectories: (home) => [join5(home, ".local", "bin")],
|
|
20642
20700
|
normalizeEnvironment(env) {
|
|
20643
20701
|
const copy = { ...env };
|
|
@@ -20719,6 +20777,7 @@ function mergePathSegments(segments) {
|
|
|
20719
20777
|
// src/providers/cli-specs.ts
|
|
20720
20778
|
var SOURCES = [
|
|
20721
20779
|
{ id: "codex", label: "Codex", command: "codex", versionArguments: ["--version"], promptStdin: { replaceWith: "-" }, restrictedPermission: true, installHint: "npm i -g @openai/codex" },
|
|
20780
|
+
{ id: "kimi", label: "Kimi Code CLI", command: "kimi", versionArguments: ["--version"], installHint: "curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash" },
|
|
20722
20781
|
{ id: "claude", label: "Claude Code", aliases: ["claude-code"], command: "claude", commandAliases: ["claude-code"], versionArguments: ["--version"], promptStdin: "omit", restrictedPermission: true, installHint: "npm i -g @anthropic-ai/claude-code" },
|
|
20723
20782
|
{ id: "grok", label: "Grok CLI", command: "grok", versionArguments: ["--version"] },
|
|
20724
20783
|
{ id: "gemini", label: "Gemini CLI", command: "gemini", versionArguments: ["--version"], restrictedPermission: true, installHint: "npm i -g @google/gemini-cli" },
|
|
@@ -20764,18 +20823,18 @@ function detectedCliVersion(id) {
|
|
|
20764
20823
|
// src/providers/provider.ts
|
|
20765
20824
|
import { realpathSync } from "node:fs";
|
|
20766
20825
|
import { homedir as homedir3 } from "node:os";
|
|
20767
|
-
import { delimiter as delimiter4, dirname as
|
|
20826
|
+
import { delimiter as delimiter4, dirname as dirname5 } from "node:path";
|
|
20768
20827
|
|
|
20769
20828
|
// src/shared/node-cli-command-resolution.ts
|
|
20770
|
-
import { existsSync as existsSync4, readdirSync } from "node:fs";
|
|
20829
|
+
import { existsSync as existsSync4, readdirSync as readdirSync2 } from "node:fs";
|
|
20771
20830
|
import { homedir as homedir2 } from "node:os";
|
|
20772
|
-
import { dirname as
|
|
20831
|
+
import { dirname as dirname4, join as join6 } from "node:path";
|
|
20773
20832
|
function adapterOf(options) {
|
|
20774
20833
|
return platformFor(options.platform ?? process.platform);
|
|
20775
20834
|
}
|
|
20776
20835
|
function splitPath(platform2, pathEnv) {
|
|
20777
20836
|
if (!pathEnv) return [];
|
|
20778
|
-
return pathEnv.split(platform2.id === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean);
|
|
20837
|
+
return pathEnv.split(platform2.id === "win32" ? ";" : ":").map((entry) => entry.trim().replace(/^"(.*)"$/, "$1")).filter(Boolean);
|
|
20779
20838
|
}
|
|
20780
20839
|
function parseVersionSegment(raw) {
|
|
20781
20840
|
return raw.replace(/^v/i, "").split(".").map((segment) => Number.parseInt(segment, 10)).map((segment) => Number.isFinite(segment) ? segment : 0);
|
|
@@ -20809,12 +20868,12 @@ function getBaseVersionManagerDirectories(platform2, homePath) {
|
|
|
20809
20868
|
function getNvmVersionDirectories(homePath) {
|
|
20810
20869
|
const nvmVersionsDir = join6(homePath, ".nvm", "versions", "node");
|
|
20811
20870
|
if (!existsSync4(nvmVersionsDir)) return [];
|
|
20812
|
-
return
|
|
20871
|
+
return readdirSync2(nvmVersionsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareVersionDesc).map((entry) => join6(nvmVersionsDir, entry, "bin"));
|
|
20813
20872
|
}
|
|
20814
20873
|
function getVersionManagerDirectories(platform2, homePath, executableNames) {
|
|
20815
20874
|
const directories = getBaseVersionManagerDirectories(platform2, homePath);
|
|
20816
20875
|
const firstNvmMatch = findFirstExecutable(platform2, getNvmVersionDirectories(homePath), executableNames);
|
|
20817
|
-
if (firstNvmMatch) directories.unshift(
|
|
20876
|
+
if (firstNvmMatch) directories.unshift(dirname4(firstNvmMatch));
|
|
20818
20877
|
return directories;
|
|
20819
20878
|
}
|
|
20820
20879
|
function resolveCliCommand(commandName, options = {}) {
|
|
@@ -20822,6 +20881,7 @@ function resolveCliCommand(commandName, options = {}) {
|
|
|
20822
20881
|
}
|
|
20823
20882
|
function findCliCommand(commandName, options = {}) {
|
|
20824
20883
|
const platform2 = adapterOf(options);
|
|
20884
|
+
if (/[\\/]/.test(commandName)) return platform2.isRunnableFile(commandName) ? commandName : null;
|
|
20825
20885
|
const executableNames = platform2.executableNames(commandName);
|
|
20826
20886
|
const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null;
|
|
20827
20887
|
const pathCandidate = findFirstExecutable(platform2, splitPath(platform2, pathEnv), executableNames);
|
|
@@ -20888,9 +20948,9 @@ function toolCallRows(name, path) {
|
|
|
20888
20948
|
function providerEnvironment() {
|
|
20889
20949
|
const env = currentPlatform.normalizeEnvironment(process.env);
|
|
20890
20950
|
const commandPaths = [
|
|
20891
|
-
|
|
20892
|
-
...getVersionManagerBinPaths(),
|
|
20951
|
+
dirname5(process.execPath),
|
|
20893
20952
|
env.PATH,
|
|
20953
|
+
...getVersionManagerBinPaths(),
|
|
20894
20954
|
...currentPlatform.fallbackBinDirectories(homedir3())
|
|
20895
20955
|
].filter((value) => Boolean(value));
|
|
20896
20956
|
env.PATH = [...new Set(commandPaths)].join(delimiter4);
|
|
@@ -20958,7 +21018,7 @@ import { spawn as spawn3 } from "node:child_process";
|
|
|
20958
21018
|
import { statSync as statSync4 } from "node:fs";
|
|
20959
21019
|
import { chmod as chmod3, mkdir as mkdir3, readFile as readFile3, rename as rename3, stat, writeFile as writeFile3 } from "node:fs/promises";
|
|
20960
21020
|
import { homedir as homedir4 } from "node:os";
|
|
20961
|
-
import { dirname as
|
|
21021
|
+
import { dirname as dirname6, isAbsolute, join as join7, resolve as resolve2 } from "node:path";
|
|
20962
21022
|
var codexHome = () => process.env.CODEX_HOME?.trim() || join7(homedir4(), ".codex");
|
|
20963
21023
|
var BUNDLED_TIMEOUT_MS = 1e4;
|
|
20964
21024
|
function configuredCatalogPath(config2, home = codexHome()) {
|
|
@@ -21067,7 +21127,7 @@ async function rebuild() {
|
|
|
21067
21127
|
return;
|
|
21068
21128
|
}
|
|
21069
21129
|
const path = overlayPath();
|
|
21070
|
-
await mkdir3(
|
|
21130
|
+
await mkdir3(dirname6(path), { recursive: true, mode: 448 });
|
|
21071
21131
|
const temporary = `${path}.${process.pid}.tmp`;
|
|
21072
21132
|
await writeFile3(temporary, JSON.stringify(filled), { mode: 384 });
|
|
21073
21133
|
await rename3(temporary, path);
|
|
@@ -22121,7 +22181,7 @@ import { spawn as spawn6 } from "node:child_process";
|
|
|
22121
22181
|
import { createHash } from "node:crypto";
|
|
22122
22182
|
import { existsSync as existsSync5, readFileSync as readFileSync5 } from "node:fs";
|
|
22123
22183
|
import { copyFile, mkdir as mkdir4, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
22124
|
-
import { dirname as
|
|
22184
|
+
import { dirname as dirname7, join as join11, resolve as resolve4 } from "node:path";
|
|
22125
22185
|
import { fileURLToPath } from "node:url";
|
|
22126
22186
|
var AcpRuntimeUnavailable = class extends Error {
|
|
22127
22187
|
constructor(message) {
|
|
@@ -22131,7 +22191,7 @@ var AcpRuntimeUnavailable = class extends Error {
|
|
|
22131
22191
|
};
|
|
22132
22192
|
var NPM_INSTALL_TIMEOUT_MS = 10 * 6e4;
|
|
22133
22193
|
function packageRoot() {
|
|
22134
|
-
let directory =
|
|
22194
|
+
let directory = dirname7(fileURLToPath(import.meta.url));
|
|
22135
22195
|
while (true) {
|
|
22136
22196
|
const path = resolve4(directory, "package.json");
|
|
22137
22197
|
if (existsSync5(path)) {
|
|
@@ -22140,7 +22200,7 @@ function packageRoot() {
|
|
|
22140
22200
|
} catch {
|
|
22141
22201
|
}
|
|
22142
22202
|
}
|
|
22143
|
-
const parent =
|
|
22203
|
+
const parent = dirname7(directory);
|
|
22144
22204
|
if (parent === directory) return void 0;
|
|
22145
22205
|
directory = parent;
|
|
22146
22206
|
}
|
|
@@ -22168,7 +22228,7 @@ var installs = /* @__PURE__ */ new Map();
|
|
|
22168
22228
|
function ensureClaudeRuntime(dataDir2) {
|
|
22169
22229
|
const entry = vendoredAdapter("claude");
|
|
22170
22230
|
if (!entry) return Promise.reject(new AcpRuntimeUnavailable("\u8FD9\u4E2A\u7248\u672C\u7684\u8BBE\u5907\u4EE3\u7406\u6CA1\u6709\u9644\u5E26 Claude ACP \u9002\u914D\u5668"));
|
|
22171
|
-
const manifestPath = join11(
|
|
22231
|
+
const manifestPath = join11(dirname7(entry), "runtime.json");
|
|
22172
22232
|
let manifest;
|
|
22173
22233
|
try {
|
|
22174
22234
|
manifest = JSON.parse(readFileSync5(manifestPath, "utf8"));
|
|
@@ -22253,6 +22313,14 @@ var KIRO_LAUNCH_SPEC = {
|
|
|
22253
22313
|
resumable: (sessionId) => !sessionId.startsWith("sess_"),
|
|
22254
22314
|
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.kiro }
|
|
22255
22315
|
};
|
|
22316
|
+
var KIMI_LAUNCH_SPEC = {
|
|
22317
|
+
agent: "kimi",
|
|
22318
|
+
headless: "acp",
|
|
22319
|
+
args: () => ["acp"],
|
|
22320
|
+
resumePreference: "resume",
|
|
22321
|
+
dialect: { failureRules: [{ kind: "sessionMissing", pattern: /session[^\n]{0,60}(?:not found|does not exist)|no such session/i }] },
|
|
22322
|
+
modelDiscovery: { kind: "session" }
|
|
22323
|
+
};
|
|
22256
22324
|
var GEMINI_LAUNCH_SPEC = {
|
|
22257
22325
|
agent: "gemini",
|
|
22258
22326
|
headless: "acp",
|
|
@@ -22358,6 +22426,7 @@ var CODEX_LAUNCH_SPEC = {
|
|
|
22358
22426
|
};
|
|
22359
22427
|
var ACP_LAUNCH_SPECS = [
|
|
22360
22428
|
KIRO_LAUNCH_SPEC,
|
|
22429
|
+
KIMI_LAUNCH_SPEC,
|
|
22361
22430
|
GEMINI_LAUNCH_SPEC,
|
|
22362
22431
|
GROK_LAUNCH_SPEC,
|
|
22363
22432
|
OPENCODE_LAUNCH_SPEC,
|
|
@@ -23644,7 +23713,7 @@ function isWriterConflict(message) {
|
|
|
23644
23713
|
}
|
|
23645
23714
|
|
|
23646
23715
|
// src/providers/cli/claude.ts
|
|
23647
|
-
import { readdirSync as
|
|
23716
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
23648
23717
|
import { homedir as homedir8 } from "node:os";
|
|
23649
23718
|
import { join as join14 } from "node:path";
|
|
23650
23719
|
var CLAUDE = requireCliSpec("claude");
|
|
@@ -23661,13 +23730,13 @@ function claudeTranscriptPath(sessionId) {
|
|
|
23661
23730
|
for (const root2 of claudeProjectRoots()) {
|
|
23662
23731
|
let projects;
|
|
23663
23732
|
try {
|
|
23664
|
-
projects =
|
|
23733
|
+
projects = readdirSync3(root2);
|
|
23665
23734
|
} catch {
|
|
23666
23735
|
continue;
|
|
23667
23736
|
}
|
|
23668
23737
|
for (const project of projects) {
|
|
23669
23738
|
try {
|
|
23670
|
-
if (
|
|
23739
|
+
if (readdirSync3(join14(root2, project)).includes(file2)) return join14(root2, project, file2);
|
|
23671
23740
|
} catch {
|
|
23672
23741
|
}
|
|
23673
23742
|
}
|
|
@@ -24796,7 +24865,7 @@ function resolveDetectedProviderCommands(foundCommands, commands = DETECTION_COM
|
|
|
24796
24865
|
function probeVersion(path, args) {
|
|
24797
24866
|
if (args.length === 0) return Promise.resolve({});
|
|
24798
24867
|
return new Promise((resolve9) => {
|
|
24799
|
-
const launch = directLaunch2(path, args);
|
|
24868
|
+
const launch = directLaunch2(path, args, process.env.TOC_OCRA_NODE_PATH || process.execPath);
|
|
24800
24869
|
const child = spawn9(launch.executable, launch.args, { stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
24801
24870
|
let stdout = "";
|
|
24802
24871
|
let stderr = "";
|
|
@@ -24845,13 +24914,15 @@ var CliDetectionService = class {
|
|
|
24845
24914
|
const foundCommands = new Set(commands.filter((command) => resolved.get(command)?.found));
|
|
24846
24915
|
const detected = resolveDetectedProviderCommands(foundCommands, DETECTION_COMMANDS);
|
|
24847
24916
|
const providers2 = await Promise.all(CLI_CATALOG.map(async (config2) => {
|
|
24848
|
-
const
|
|
24849
|
-
const
|
|
24917
|
+
const override = process.env[config2.overrideEnv]?.trim();
|
|
24918
|
+
const unsupported = config2.detectUnsupportedRuntimes?.includes(process.platform) ?? false;
|
|
24919
|
+
const requiredPresent = (config2.detectRequiredCommands ?? []).every((command) => foundCommands.has(command));
|
|
24920
|
+
const matchedDetectionCommand = unsupported || !requiredPresent ? void 0 : override ? config2.detectCmd : detected.get(config2.id);
|
|
24921
|
+
const result = matchedDetectionCommand ? override ? resolveCliCommandDetailed(override) : resolved.get(matchedDetectionCommand) : void 0;
|
|
24850
24922
|
const executablePath = result?.found ? result.path : void 0;
|
|
24851
24923
|
const installed = Boolean(executablePath);
|
|
24852
|
-
const unsupported = config2.detectUnsupportedRuntimes?.includes(process.platform) ?? false;
|
|
24853
24924
|
const diagnostic = executablePath ? await probeVersion(executablePath, config2.versionArguments ?? []) : {};
|
|
24854
|
-
const detail = installed ? diagnostic.detail : unsupported ? "unsupported runtime" :
|
|
24925
|
+
const detail = installed ? diagnostic.detail : unsupported ? "unsupported runtime" : !requiredPresent ? "command or required command not found" : override && !result?.found ? `${config2.overrideEnv} \u6307\u5411\u7684\u7A0B\u5E8F\u4E0D\u5B58\u5728\uFF1A${override}` : "command not found";
|
|
24855
24926
|
return {
|
|
24856
24927
|
id: config2.id,
|
|
24857
24928
|
installed,
|
|
@@ -25283,7 +25354,7 @@ async function controlTbSwitch(payload) {
|
|
|
25283
25354
|
|
|
25284
25355
|
// src/runs/orphan-registry.ts
|
|
25285
25356
|
import { mkdir as mkdir5, readFile as readFile7, rename as rename5, writeFile as writeFile5 } from "node:fs/promises";
|
|
25286
|
-
import { basename, dirname as
|
|
25357
|
+
import { basename, dirname as dirname8 } from "node:path";
|
|
25287
25358
|
var OrphanRegistry = class {
|
|
25288
25359
|
constructor(file2) {
|
|
25289
25360
|
this.file = file2;
|
|
@@ -25301,7 +25372,7 @@ var OrphanRegistry = class {
|
|
|
25301
25372
|
persist() {
|
|
25302
25373
|
const snapshot = JSON.stringify([...this.records.values()]);
|
|
25303
25374
|
this.writing = this.writing.then(async () => {
|
|
25304
|
-
await mkdir5(
|
|
25375
|
+
await mkdir5(dirname8(this.file), { recursive: true, mode: 448 });
|
|
25305
25376
|
const temporary = `${this.file}.${process.pid}.tmp`;
|
|
25306
25377
|
await writeFile5(temporary, snapshot, { mode: 384 });
|
|
25307
25378
|
await rename5(temporary, this.file);
|
|
@@ -28453,9 +28524,9 @@ var GatewayClient = class {
|
|
|
28453
28524
|
};
|
|
28454
28525
|
|
|
28455
28526
|
// src/workspace/directory-browser.ts
|
|
28456
|
-
import { readdir as readdir3, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28527
|
+
import { mkdir as mkdir9, readdir as readdir3, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28457
28528
|
import { homedir as homedir11 } from "node:os";
|
|
28458
|
-
import { dirname as
|
|
28529
|
+
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
28459
28530
|
var MAX_ENTRIES = 1e3;
|
|
28460
28531
|
async function listDirectory(requested, allowedRoots) {
|
|
28461
28532
|
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir11()) || homedir11();
|
|
@@ -28475,7 +28546,7 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
28475
28546
|
if (entry.isDirectory()) directories.push(item);
|
|
28476
28547
|
else if (entry.isFile()) files.push(item);
|
|
28477
28548
|
}
|
|
28478
|
-
const parent =
|
|
28549
|
+
const parent = dirname9(directory);
|
|
28479
28550
|
const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir11() }];
|
|
28480
28551
|
for (const root2 of allowedRoots) if (root2 !== homedir11()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root2 });
|
|
28481
28552
|
places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
|
|
@@ -28488,12 +28559,35 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
28488
28559
|
places
|
|
28489
28560
|
};
|
|
28490
28561
|
}
|
|
28562
|
+
async function createDirectory(parentRequested, name) {
|
|
28563
|
+
const parentInput = parentRequested.trim();
|
|
28564
|
+
if (!parentInput || !isAbsolute5(parentInput)) throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28565
|
+
if (!name || name !== name.trim() || name === "." || name === ".." || name.includes("/") || name.includes("\\") || Array.from(name).length > 255 || Array.from(name).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127)) {
|
|
28566
|
+
throw new Error("\u8BF7\u8F93\u5165\u6709\u6548\u7684\u6587\u4EF6\u5939\u540D\u79F0");
|
|
28567
|
+
}
|
|
28568
|
+
const parent = await realpath3(resolve6(parentInput)).catch(() => {
|
|
28569
|
+
throw new Error(`\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${parentRequested}`);
|
|
28570
|
+
});
|
|
28571
|
+
if (!(await stat7(parent)).isDirectory()) throw new Error("\u4E0A\u7EA7\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
|
|
28572
|
+
const path = resolve6(parent, name);
|
|
28573
|
+
if (dirname9(path) !== parent) throw new Error("\u6587\u4EF6\u5939\u540D\u79F0\u65E0\u6548");
|
|
28574
|
+
try {
|
|
28575
|
+
await mkdir9(path);
|
|
28576
|
+
} catch (error62) {
|
|
28577
|
+
const code = error62.code;
|
|
28578
|
+
if (code === "EEXIST") throw new Error("\u8BE5\u6587\u4EF6\u5939\u5DF2\u5B58\u5728");
|
|
28579
|
+
if (code === "EACCES" || code === "EPERM") throw new Error("\u6CA1\u6709\u6743\u9650\u5728\u6B64\u4F4D\u7F6E\u521B\u5EFA\u6587\u4EF6\u5939");
|
|
28580
|
+
if (code === "ENOENT") throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728");
|
|
28581
|
+
throw error62;
|
|
28582
|
+
}
|
|
28583
|
+
return { path };
|
|
28584
|
+
}
|
|
28491
28585
|
|
|
28492
28586
|
// src/workspace/workspace-manager.ts
|
|
28493
28587
|
import { spawn as spawn13 } from "node:child_process";
|
|
28494
|
-
import {
|
|
28495
|
-
import { homedir as homedir12
|
|
28496
|
-
import { isAbsolute as
|
|
28588
|
+
import { opendir, realpath as realpath4, stat as stat8 } from "node:fs/promises";
|
|
28589
|
+
import { homedir as homedir12 } from "node:os";
|
|
28590
|
+
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
28497
28591
|
var MAX_NODES = 2e3;
|
|
28498
28592
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
28499
28593
|
var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
@@ -28527,193 +28621,13 @@ var WorkspaceManager = class {
|
|
|
28527
28621
|
const nodes = await this.scanTree(rootPath, request.max_depth, request.scan_roots);
|
|
28528
28622
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
28529
28623
|
}
|
|
28530
|
-
/** Creates missing folders, clones missing repos, fast-forwards clean ones. */
|
|
28531
|
-
async sync(request) {
|
|
28532
|
-
const startedAt = Date.now();
|
|
28533
|
-
const rootPath = this.validateRootPath(request.root_path);
|
|
28534
|
-
const results = await this.syncTree(rootPath, request);
|
|
28535
|
-
const failed = results.some((result) => result.status === "failed");
|
|
28536
|
-
return {
|
|
28537
|
-
root_path: rootPath,
|
|
28538
|
-
results,
|
|
28539
|
-
...failed ? { error: "\u90E8\u5206\u76EE\u5F55\u6216\u4ED3\u5E93\u540C\u6B65\u5931\u8D25" } : {},
|
|
28540
|
-
duration_ms: Date.now() - startedAt
|
|
28541
|
-
};
|
|
28542
|
-
}
|
|
28543
28624
|
validateRootPath(value) {
|
|
28544
28625
|
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir12());
|
|
28545
28626
|
const root2 = resolve7(raw);
|
|
28546
|
-
if (!
|
|
28627
|
+
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28547
28628
|
if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
|
|
28548
28629
|
return root2;
|
|
28549
28630
|
}
|
|
28550
|
-
async syncTree(rootPath, request) {
|
|
28551
|
-
await mkdir9(rootPath, { recursive: true });
|
|
28552
|
-
await addAllowedRoot(this.config, rootPath);
|
|
28553
|
-
const results = [];
|
|
28554
|
-
const requestedPaths = /* @__PURE__ */ new Set();
|
|
28555
|
-
for (const directory of request.directories) {
|
|
28556
|
-
const relativePath = this.cleanRelativePath(directory);
|
|
28557
|
-
if (requestedPaths.has(relativePath)) continue;
|
|
28558
|
-
requestedPaths.add(relativePath);
|
|
28559
|
-
const target = this.resolveWithinRoot(rootPath, relativePath);
|
|
28560
|
-
try {
|
|
28561
|
-
const metadata = await stat8(target).catch(() => void 0);
|
|
28562
|
-
if (metadata) {
|
|
28563
|
-
if (!metadata.isDirectory()) {
|
|
28564
|
-
throw new Error("The existing workspace path is not a directory");
|
|
28565
|
-
}
|
|
28566
|
-
results.push({
|
|
28567
|
-
relative_path: relativePath,
|
|
28568
|
-
status: "skipped",
|
|
28569
|
-
kind: "directory",
|
|
28570
|
-
action: "skip",
|
|
28571
|
-
message: "\u76EE\u5F55\u5DF2\u5B58\u5728"
|
|
28572
|
-
});
|
|
28573
|
-
continue;
|
|
28574
|
-
}
|
|
28575
|
-
await mkdir9(target, { recursive: true });
|
|
28576
|
-
results.push({
|
|
28577
|
-
relative_path: relativePath,
|
|
28578
|
-
status: "created",
|
|
28579
|
-
kind: "directory",
|
|
28580
|
-
action: "mkdir",
|
|
28581
|
-
message: "\u76EE\u5F55\u5DF2\u521B\u5EFA"
|
|
28582
|
-
});
|
|
28583
|
-
} catch (error62) {
|
|
28584
|
-
results.push({
|
|
28585
|
-
relative_path: relativePath,
|
|
28586
|
-
status: "failed",
|
|
28587
|
-
kind: "directory",
|
|
28588
|
-
action: "mkdir",
|
|
28589
|
-
error: this.message(error62)
|
|
28590
|
-
});
|
|
28591
|
-
}
|
|
28592
|
-
}
|
|
28593
|
-
const authEnvironment = await this.createGitAuthEnvironment(request.git_auth);
|
|
28594
|
-
try {
|
|
28595
|
-
for (const repo of request.repos) {
|
|
28596
|
-
const relativePath = this.cleanRelativePath(repo.relative_path);
|
|
28597
|
-
try {
|
|
28598
|
-
results.push(await this.syncRepository(rootPath, relativePath, repo.git_url?.trim() || void 0, repo.branch?.trim() || void 0, request.timeout_s, authEnvironment?.env));
|
|
28599
|
-
} catch (error62) {
|
|
28600
|
-
results.push({
|
|
28601
|
-
relative_path: relativePath,
|
|
28602
|
-
status: "failed",
|
|
28603
|
-
kind: "repo",
|
|
28604
|
-
action: "sync",
|
|
28605
|
-
error: this.message(error62)
|
|
28606
|
-
});
|
|
28607
|
-
}
|
|
28608
|
-
}
|
|
28609
|
-
} finally {
|
|
28610
|
-
await authEnvironment?.cleanup();
|
|
28611
|
-
}
|
|
28612
|
-
return results;
|
|
28613
|
-
}
|
|
28614
|
-
async syncRepository(rootPath, relativePath, gitUrl, branch, timeoutSeconds, gitEnvironment) {
|
|
28615
|
-
const target = this.resolveWithinRoot(rootPath, relativePath);
|
|
28616
|
-
let created = false;
|
|
28617
|
-
let metadata;
|
|
28618
|
-
try {
|
|
28619
|
-
metadata = await stat8(target);
|
|
28620
|
-
} catch {
|
|
28621
|
-
}
|
|
28622
|
-
if (!metadata) {
|
|
28623
|
-
if (!gitUrl) throw new Error("A missing repository needs a Git remote URL");
|
|
28624
|
-
await mkdir9(resolve7(target, ".."), { recursive: true });
|
|
28625
|
-
const cloneArgs = branch ? ["clone", "--branch", branch, "--single-branch", gitUrl, target] : ["clone", gitUrl, target];
|
|
28626
|
-
await this.runGit(cloneArgs, rootPath, timeoutSeconds, false, gitEnvironment);
|
|
28627
|
-
created = true;
|
|
28628
|
-
} else {
|
|
28629
|
-
if (!metadata.isDirectory()) throw new Error("The repository path is not a directory");
|
|
28630
|
-
if (!await this.isGitRepository(target, timeoutSeconds)) {
|
|
28631
|
-
throw new Error("The existing directory is not a Git repository");
|
|
28632
|
-
}
|
|
28633
|
-
if (gitUrl) {
|
|
28634
|
-
const currentOrigin = (await this.runGit(["config", "--get", "remote.origin.url"], target, timeoutSeconds, true)).stdout.trim();
|
|
28635
|
-
if (currentOrigin && currentOrigin !== gitUrl) {
|
|
28636
|
-
throw new Error("The existing repository origin does not match the configured Git URL");
|
|
28637
|
-
}
|
|
28638
|
-
}
|
|
28639
|
-
const worktree = await this.runGit(["status", "--porcelain"], target, timeoutSeconds);
|
|
28640
|
-
if (worktree.stdout.trim()) {
|
|
28641
|
-
return {
|
|
28642
|
-
relative_path: relativePath,
|
|
28643
|
-
status: "skipped",
|
|
28644
|
-
kind: "repo",
|
|
28645
|
-
action: "skip",
|
|
28646
|
-
message: "\u4ED3\u5E93\u5B58\u5728\u672A\u63D0\u4EA4\u7684\u672C\u5730\u4FEE\u6539"
|
|
28647
|
-
};
|
|
28648
|
-
}
|
|
28649
|
-
if (branch) {
|
|
28650
|
-
const currentBranch = await this.runGit(["branch", "--show-current"], target, timeoutSeconds);
|
|
28651
|
-
if (currentBranch.stdout.trim() !== branch) {
|
|
28652
|
-
return {
|
|
28653
|
-
relative_path: relativePath,
|
|
28654
|
-
status: "skipped",
|
|
28655
|
-
kind: "repo",
|
|
28656
|
-
action: "skip",
|
|
28657
|
-
message: `\u5F53\u524D\u5206\u652F ${currentBranch.stdout.trim() || "(detached)"} \u4E0E\u76EE\u6807\u5206\u652F ${branch} \u4E0D\u4E00\u81F4`
|
|
28658
|
-
};
|
|
28659
|
-
}
|
|
28660
|
-
}
|
|
28661
|
-
}
|
|
28662
|
-
await this.runGit(["fetch", "--prune", "origin"], target, timeoutSeconds, false, gitEnvironment);
|
|
28663
|
-
if (branch) {
|
|
28664
|
-
const remoteBranch = await this.runGit(
|
|
28665
|
-
["show-ref", "--verify", "--quiet", `refs/remotes/origin/${branch}`],
|
|
28666
|
-
target,
|
|
28667
|
-
timeoutSeconds,
|
|
28668
|
-
true
|
|
28669
|
-
);
|
|
28670
|
-
if (remoteBranch.exitCode !== 0) {
|
|
28671
|
-
return {
|
|
28672
|
-
relative_path: relativePath,
|
|
28673
|
-
status: "skipped",
|
|
28674
|
-
kind: "repo",
|
|
28675
|
-
action: "skip",
|
|
28676
|
-
message: `\u8FDC\u7AEF\u5206\u652F origin/${branch} \u4E0D\u5B58\u5728`
|
|
28677
|
-
};
|
|
28678
|
-
}
|
|
28679
|
-
if (!created) {
|
|
28680
|
-
const currentCommit = await this.runGit(["rev-parse", "HEAD"], target, timeoutSeconds);
|
|
28681
|
-
const remoteCommit = await this.runGit(["rev-parse", `origin/${branch}`], target, timeoutSeconds);
|
|
28682
|
-
if (currentCommit.stdout.trim() === remoteCommit.stdout.trim()) {
|
|
28683
|
-
return {
|
|
28684
|
-
relative_path: relativePath,
|
|
28685
|
-
status: "skipped",
|
|
28686
|
-
kind: "repo",
|
|
28687
|
-
action: "skip",
|
|
28688
|
-
message: "\u4ED3\u5E93\u5DF2\u662F\u6700\u65B0"
|
|
28689
|
-
};
|
|
28690
|
-
}
|
|
28691
|
-
const fastForward = await this.runGit(
|
|
28692
|
-
["merge-base", "--is-ancestor", "HEAD", `origin/${branch}`],
|
|
28693
|
-
target,
|
|
28694
|
-
timeoutSeconds,
|
|
28695
|
-
true
|
|
28696
|
-
);
|
|
28697
|
-
if (fastForward.exitCode !== 0) {
|
|
28698
|
-
return {
|
|
28699
|
-
relative_path: relativePath,
|
|
28700
|
-
status: "skipped",
|
|
28701
|
-
kind: "repo",
|
|
28702
|
-
action: "skip",
|
|
28703
|
-
message: "\u672C\u5730\u63D0\u4EA4\u65E0\u6CD5\u5FEB\u8FDB\u5230\u8FDC\u7AEF\u5206\u652F"
|
|
28704
|
-
};
|
|
28705
|
-
}
|
|
28706
|
-
}
|
|
28707
|
-
await this.runGit(["pull", "--ff-only", "origin", branch], target, timeoutSeconds, false, gitEnvironment);
|
|
28708
|
-
}
|
|
28709
|
-
return {
|
|
28710
|
-
relative_path: relativePath,
|
|
28711
|
-
status: created ? "created" : "updated",
|
|
28712
|
-
kind: "repo",
|
|
28713
|
-
action: created ? "clone" : "pull",
|
|
28714
|
-
message: created ? "\u4ED3\u5E93\u5DF2\u514B\u9686" : "\u4ED3\u5E93\u5DF2\u5FEB\u8FDB\u66F4\u65B0"
|
|
28715
|
-
};
|
|
28716
|
-
}
|
|
28717
28631
|
async scanTree(rootPath, maxDepth, scanRoots) {
|
|
28718
28632
|
const resolvedRoot = await realpath4(rootPath);
|
|
28719
28633
|
const rootMetadata = await stat8(resolvedRoot);
|
|
@@ -28827,16 +28741,16 @@ var WorkspaceManager = class {
|
|
|
28827
28741
|
resolveWithinRoot(rootPath, relativePath) {
|
|
28828
28742
|
const target = resolve7(rootPath, relativePath);
|
|
28829
28743
|
const relativeToRoot = relative3(rootPath, target);
|
|
28830
|
-
if (relativeToRoot.startsWith("..") ||
|
|
28744
|
+
if (relativeToRoot.startsWith("..") || isAbsolute6(relativeToRoot)) {
|
|
28831
28745
|
throw new Error("A workspace path must remain under the configured workspace root");
|
|
28832
28746
|
}
|
|
28833
28747
|
return target;
|
|
28834
28748
|
}
|
|
28835
|
-
runGit(args, cwd, timeoutSeconds, allowFailure = false
|
|
28749
|
+
runGit(args, cwd, timeoutSeconds, allowFailure = false) {
|
|
28836
28750
|
return new Promise((resolveCommand, rejectCommand) => {
|
|
28837
28751
|
const child = spawn13("git", args, {
|
|
28838
28752
|
cwd,
|
|
28839
|
-
env:
|
|
28753
|
+
env: process.env,
|
|
28840
28754
|
shell: false,
|
|
28841
28755
|
stdio: ["ignore", "pipe", "pipe"]
|
|
28842
28756
|
});
|
|
@@ -28866,37 +28780,6 @@ var WorkspaceManager = class {
|
|
|
28866
28780
|
});
|
|
28867
28781
|
});
|
|
28868
28782
|
}
|
|
28869
|
-
async createGitAuthEnvironment(auth) {
|
|
28870
|
-
if (!auth) return void 0;
|
|
28871
|
-
const directory = await mkdtemp2(join20(tmpdir3(), "toc-ocra-git-auth-"));
|
|
28872
|
-
const isWindows = process.platform === "win32";
|
|
28873
|
-
const scriptPath = join20(directory, isWindows ? "askpass.cmd" : "askpass.sh");
|
|
28874
|
-
let script;
|
|
28875
|
-
if (isWindows) {
|
|
28876
|
-
const helperPath = join20(directory, "askpass.cjs");
|
|
28877
|
-
await writeFile9(
|
|
28878
|
-
helperPath,
|
|
28879
|
-
'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',
|
|
28880
|
-
{ mode: 448 }
|
|
28881
|
-
);
|
|
28882
|
-
script = '@echo off\r\n"%ECHO_NODE_PATH%" "%~dp0askpass.cjs" "%~1"\r\n';
|
|
28883
|
-
} else {
|
|
28884
|
-
script = '#!/bin/sh\ncase "$1" in *Username*|*username*) printf "%s\\n" "$ECHO_GIT_USERNAME" ;; *) printf "%s\\n" "$ECHO_GIT_PASSWORD" ;; esac\n';
|
|
28885
|
-
}
|
|
28886
|
-
await writeFile9(scriptPath, script, { mode: 448 });
|
|
28887
|
-
if (!isWindows) await chmod5(scriptPath, 448);
|
|
28888
|
-
return {
|
|
28889
|
-
env: {
|
|
28890
|
-
...process.env,
|
|
28891
|
-
GIT_ASKPASS: scriptPath,
|
|
28892
|
-
GIT_TERMINAL_PROMPT: "0",
|
|
28893
|
-
ECHO_NODE_PATH: process.execPath,
|
|
28894
|
-
ECHO_GIT_USERNAME: auth.username,
|
|
28895
|
-
ECHO_GIT_PASSWORD: auth.password
|
|
28896
|
-
},
|
|
28897
|
-
cleanup: () => rm5(directory, { recursive: true, force: true })
|
|
28898
|
-
};
|
|
28899
|
-
}
|
|
28900
28783
|
message(error62) {
|
|
28901
28784
|
return error62 instanceof Error ? error62.message : String(error62);
|
|
28902
28785
|
}
|
|
@@ -29022,22 +28905,15 @@ var CliProviderControlPayloadSchema = external_exports.object({
|
|
|
29022
28905
|
}).strict();
|
|
29023
28906
|
var RelativePathSchema = external_exports.string().min(1).max(500);
|
|
29024
28907
|
var FsListPayloadSchema = external_exports.object({ path: external_exports.string().max(4096).optional().default("") });
|
|
28908
|
+
var FsMkdirPayloadSchema = external_exports.object({
|
|
28909
|
+
parent_path: external_exports.string().min(1).max(4096),
|
|
28910
|
+
name: external_exports.string().min(1).max(255)
|
|
28911
|
+
}).strict();
|
|
29025
28912
|
var WorkspaceScanPayloadSchema = external_exports.object({
|
|
29026
28913
|
root_path: external_exports.string().min(1).max(4096),
|
|
29027
28914
|
max_depth: external_exports.number().int().positive().max(20).optional(),
|
|
29028
28915
|
scan_roots: external_exports.array(external_exports.object({ relative_path: RelativePathSchema, max_depth: external_exports.number().int().positive().max(20) })).max(2e3).optional()
|
|
29029
28916
|
});
|
|
29030
|
-
var WorkspaceSyncPayloadSchema = external_exports.object({
|
|
29031
|
-
root_path: external_exports.string().min(1).max(4096),
|
|
29032
|
-
directories: external_exports.array(RelativePathSchema).max(2e3).default([]),
|
|
29033
|
-
repos: external_exports.array(external_exports.object({
|
|
29034
|
-
relative_path: RelativePathSchema,
|
|
29035
|
-
git_url: external_exports.string().max(2e3).nullable().optional(),
|
|
29036
|
-
branch: external_exports.string().max(200).nullable().optional()
|
|
29037
|
-
})).max(2e3).default([]),
|
|
29038
|
-
timeout_s: external_exports.number().int().positive().max(3600).optional(),
|
|
29039
|
-
git_auth: external_exports.object({ username: external_exports.string().min(1).max(500), password: external_exports.string().min(1).max(4096) }).optional()
|
|
29040
|
-
});
|
|
29041
28917
|
|
|
29042
28918
|
// src/runtime/agent-runtime.ts
|
|
29043
28919
|
var sleep2 = (ms, signal2) => new Promise((resolve9) => {
|
|
@@ -29430,15 +29306,14 @@ var AgentRuntime = class {
|
|
|
29430
29306
|
const payload = FsListPayloadSchema.parse(command.payload ?? {});
|
|
29431
29307
|
return { success: true, result: await listDirectory(payload.path, this.config.allowedRoots) };
|
|
29432
29308
|
}
|
|
29309
|
+
case "fs.mkdir": {
|
|
29310
|
+
const payload = FsMkdirPayloadSchema.parse(command.payload);
|
|
29311
|
+
return { success: true, result: await createDirectory(payload.parent_path, payload.name) };
|
|
29312
|
+
}
|
|
29433
29313
|
case "workspace.scan": {
|
|
29434
29314
|
const payload = WorkspaceScanPayloadSchema.parse(command.payload);
|
|
29435
29315
|
return { success: true, result: await this.workspaces.scan(payload) };
|
|
29436
29316
|
}
|
|
29437
|
-
case "workspace.sync": {
|
|
29438
|
-
const payload = WorkspaceSyncPayloadSchema.parse(command.payload);
|
|
29439
|
-
const result = await this.workspaces.sync(payload);
|
|
29440
|
-
return { success: !result.error, result, ...result.error ? { error: result.error } : {} };
|
|
29441
|
-
}
|
|
29442
29317
|
case "sql.run": {
|
|
29443
29318
|
const payload = SqlRunPayloadSchema.parse(command.payload);
|
|
29444
29319
|
this.checkPolicy("sql", payload.policy);
|
|
@@ -29449,16 +29324,14 @@ var AgentRuntime = class {
|
|
|
29449
29324
|
}
|
|
29450
29325
|
}
|
|
29451
29326
|
/**
|
|
29452
|
-
* Script / SQL run
|
|
29453
|
-
* owner has not switched it off. The policy attached to the command was
|
|
29327
|
+
* Script / SQL run when the server policy allows it. The policy attached to the command was
|
|
29454
29328
|
* checked by the server at enqueue time, so it wins over the (up to one
|
|
29455
29329
|
* heartbeat old) cached copy. New policy fields (read-only SQL,
|
|
29456
29330
|
* allowlists) are enforced here.
|
|
29457
29331
|
*/
|
|
29458
29332
|
checkPolicy(kind, commandPolicy) {
|
|
29459
|
-
const localOff = kind === "script" ? this.config.disableScript : this.config.disableSql;
|
|
29460
29333
|
const policy = commandPolicy ?? this.policy;
|
|
29461
|
-
const enabled =
|
|
29334
|
+
const enabled = policy[kind].enabled;
|
|
29462
29335
|
if (!enabled) throw new Error(kind === "script" ? "\u8BE5\u8BBE\u5907\u672A\u5F00\u542F\u811A\u672C\u6267\u884C" : "\u8BE5\u8BBE\u5907\u672A\u5F00\u542F SQL \u6267\u884C");
|
|
29463
29336
|
}
|
|
29464
29337
|
// ---- Reports ----
|
|
@@ -29638,7 +29511,9 @@ var AgentService = class {
|
|
|
29638
29511
|
await this.stop();
|
|
29639
29512
|
throw error62;
|
|
29640
29513
|
}
|
|
29641
|
-
} else process.stdout.write(
|
|
29514
|
+
} else process.stdout.write(`\u672C\u673A\u5C1A\u672A\u7ED1\u5B9A\u670D\u52A1\u5668\uFF0C\u8BF7\u5728\u300C\u8BBE\u5907\u4EE3\u7406\u300D\u63D2\u4EF6\u4E2D\u5B8C\u6210\u7ED1\u5B9A\uFF0C\u6216\u8FD0\u884C toc-ocra setup --server <\u670D\u52A1\u5668\u5730\u5740>
|
|
29515
|
+
\u5F53\u524D\u914D\u7F6E\uFF1A${this.config.configPath}
|
|
29516
|
+
`);
|
|
29642
29517
|
}
|
|
29643
29518
|
stop() {
|
|
29644
29519
|
return this.stopPromise ??= (async () => {
|
|
@@ -29708,7 +29583,9 @@ var AgentService = class {
|
|
|
29708
29583
|
id: provider.id,
|
|
29709
29584
|
installed: provider.installed,
|
|
29710
29585
|
runnable: provider.available,
|
|
29711
|
-
version: provider.version ?? ""
|
|
29586
|
+
version: provider.version ?? "",
|
|
29587
|
+
path: provider.resolvedPath ?? "",
|
|
29588
|
+
detail: provider.detail ?? ""
|
|
29712
29589
|
}))
|
|
29713
29590
|
};
|
|
29714
29591
|
}
|
|
@@ -29778,11 +29655,11 @@ function errorMessage3(error62) {
|
|
|
29778
29655
|
|
|
29779
29656
|
// src/runtime/run-service.ts
|
|
29780
29657
|
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "node:fs";
|
|
29781
|
-
import { dirname as
|
|
29658
|
+
import { dirname as dirname10, resolve as resolve8 } from "node:path";
|
|
29782
29659
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
29783
29660
|
var PACKAGE_NAME = "toc-ocra";
|
|
29784
29661
|
function agentPackageRoot() {
|
|
29785
|
-
let directory =
|
|
29662
|
+
let directory = dirname10(fileURLToPath2(import.meta.url));
|
|
29786
29663
|
while (true) {
|
|
29787
29664
|
const packagePath = resolve8(directory, "package.json");
|
|
29788
29665
|
if (existsSync6(packagePath)) {
|
|
@@ -29792,7 +29669,7 @@ function agentPackageRoot() {
|
|
|
29792
29669
|
} catch {
|
|
29793
29670
|
}
|
|
29794
29671
|
}
|
|
29795
|
-
const parent =
|
|
29672
|
+
const parent = dirname10(directory);
|
|
29796
29673
|
if (parent === directory) return void 0;
|
|
29797
29674
|
directory = parent;
|
|
29798
29675
|
}
|