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.
Files changed (37) hide show
  1. package/README.md +12 -6
  2. package/dist/cli/cli.mjs +167 -291
  3. package/dist/plugin/renderer.js +1 -1
  4. package/dist/plugin/renderer.js.map +3 -3
  5. package/dist/service/agent.mjs +159 -282
  6. package/dist/src/acp/acp-launch-specs.js +9 -0
  7. package/dist/src/acp/acp-launch-specs.js.map +1 -1
  8. package/dist/src/index.js +4 -3
  9. package/dist/src/index.js.map +1 -1
  10. package/dist/src/platform/win32.js +84 -12
  11. package/dist/src/platform/win32.js.map +1 -1
  12. package/dist/src/providers/cli-specs.js +1 -0
  13. package/dist/src/providers/cli-specs.js.map +1 -1
  14. package/dist/src/providers/detection.js +10 -6
  15. package/dist/src/providers/detection.js.map +1 -1
  16. package/dist/src/providers/provider.js +1 -1
  17. package/dist/src/providers/provider.js.map +1 -1
  18. package/dist/src/runtime/agent-runtime.d.ts +1 -2
  19. package/dist/src/runtime/agent-runtime.js +8 -11
  20. package/dist/src/runtime/agent-runtime.js.map +1 -1
  21. package/dist/src/runtime/agent-service.js +4 -2
  22. package/dist/src/runtime/agent-service.js.map +1 -1
  23. package/dist/src/shared/node-cli-command-resolution.js +5 -1
  24. package/dist/src/shared/node-cli-command-resolution.js.map +1 -1
  25. package/dist/src/types/protocol.d.ts +4 -23
  26. package/dist/src/types/protocol.js +4 -11
  27. package/dist/src/types/protocol.js.map +1 -1
  28. package/dist/src/workspace/directory-browser.d.ts +4 -0
  29. package/dist/src/workspace/directory-browser.js +43 -5
  30. package/dist/src/workspace/directory-browser.js.map +1 -1
  31. package/dist/src/workspace/workspace-manager.d.ts +1 -12
  32. package/dist/src/workspace/workspace-manager.js +5 -216
  33. package/dist/src/workspace/workspace-manager.js.map +1 -1
  34. package/locales/en.json +1 -0
  35. package/locales/zh-CN.json +1 -0
  36. package/package.json +1 -1
  37. package/scripts/service.mjs +48 -12
package/dist/cli/cli.mjs CHANGED
@@ -4577,9 +4577,9 @@ var require_lib = __commonJS({
4577
4577
  import { spawnSync } from "node:child_process";
4578
4578
  import { createHash as createHash5 } from "node:crypto";
4579
4579
  import { existsSync as existsSync7, mkdtempSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
4580
- import { tmpdir as tmpdir5 } from "node:os";
4580
+ import { tmpdir as tmpdir4 } from "node:os";
4581
4581
  import { createRequire } from "node:module";
4582
- import { dirname as dirname10, join as join23, resolve as resolve9 } from "node:path";
4582
+ import { dirname as dirname11, join as join23, resolve as resolve9 } from "node:path";
4583
4583
  import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL2 } from "node:url";
4584
4584
 
4585
4585
  // src/config.ts
@@ -24906,11 +24906,12 @@ function createPosixPlatform(id) {
24906
24906
 
24907
24907
  // src/platform/win32.ts
24908
24908
  import { execFile as execFile2, spawn as spawn2 } from "node:child_process";
24909
- import { readFileSync as readFileSync3, statSync as statSync2 } from "node:fs";
24910
- import { join as join5, win32 } from "node:path";
24909
+ import { readFileSync as readFileSync3, readdirSync, statSync as statSync2 } from "node:fs";
24910
+ import { dirname as dirname2, join as join5, win32 } from "node:path";
24911
24911
  var SYSTEM_ROOT = process.env.SystemRoot || process.env.windir || "C:\\Windows";
24912
24912
  var POWERSHELL = join5(SYSTEM_ROOT, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
24913
24913
  var HELPER_TIMEOUT_MS = 5e3;
24914
+ var bundledCliDirectories = [];
24914
24915
  var SHIM_TARGET_RE = /%~?dp0%?\\?([^"%\r\n]+)/gi;
24915
24916
  var SHIM_TARGET_EXTENSIONS = /\.(c|m)?js$|\.exe$/i;
24916
24917
  var MAX_SHIM_BYTES = 64 * 1024;
@@ -24959,6 +24960,47 @@ function runPowerShell(script) {
24959
24960
  function expandVariables(value) {
24960
24961
  return value.replace(/%([^%;]+)%/g, (whole2, name) => process.env[name] ?? whole2);
24961
24962
  }
24963
+ async function bundledCodexDirectories() {
24964
+ const local = process.env.LOCALAPPDATA;
24965
+ 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)));
24966
+ const result = await runPowerShell("@(Get-AppxPackage -ErrorAction SilentlyContinue | Where-Object { $_.Name -match 'OpenAI|ChatGPT|Codex' } | Select-Object -ExpandProperty InstallLocation) | ConvertTo-Json -Compress");
24967
+ if (result.ok) {
24968
+ try {
24969
+ const locations = JSON.parse(result.stdout.trim());
24970
+ for (const location of Array.isArray(locations) ? locations : [locations]) {
24971
+ if (typeof location === "string" && location) roots.push(location);
24972
+ }
24973
+ } catch {
24974
+ }
24975
+ }
24976
+ const found = /* @__PURE__ */ new Set();
24977
+ for (const root2 of new Set(roots)) {
24978
+ const pending = ["resources", join5("app", "resources"), "codex-cli", join5("app", "codex-cli")].map((relative4) => ({ directory: join5(root2, relative4), depth: 0 }));
24979
+ for (let visited = 0; pending.length && visited < 256; visited++) {
24980
+ const { directory, depth } = pending.shift();
24981
+ try {
24982
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
24983
+ const file2 = join5(directory, entry.name);
24984
+ if (entry.isFile() && entry.name.toLowerCase() === "codex.exe") found.add(dirname2(file2));
24985
+ else if (entry.isDirectory() && depth < 5) pending.push({ directory: file2, depth: depth + 1 });
24986
+ }
24987
+ } catch {
24988
+ }
24989
+ }
24990
+ }
24991
+ return [...found];
24992
+ }
24993
+ function npmPrefix(home) {
24994
+ let prefix = process.env.npm_config_prefix ?? process.env.NPM_CONFIG_PREFIX;
24995
+ if (!prefix) {
24996
+ try {
24997
+ prefix = /^\s*prefix\s*=\s*(.+?)\s*$/mi.exec(readFileSync3(process.env.NPM_CONFIG_USERCONFIG ?? join5(home, ".npmrc"), "utf8"))?.[1];
24998
+ } catch {
24999
+ }
25000
+ }
25001
+ if (!prefix) return void 0;
25002
+ return expandVariables(prefix.replace(/^(["'])(.*)\1$/, "$2").replace(/^~(?=[\\/]|$)/, home).replace(/\$\{([^}]+)\}/g, (whole2, name) => process.env[name] ?? whole2));
25003
+ }
24962
25004
  async function readRegistryEnvironment() {
24963
25005
  const names = [...new Set(PROXY_KEYS.map((key) => key.toLowerCase()))];
24964
25006
  const script = [
@@ -24969,7 +25011,8 @@ async function readRegistryEnvironment() {
24969
25011
  "$v=[Environment]::GetEnvironmentVariable($k,'User');if(-not $v){$v=[Environment]::GetEnvironmentVariable($k,'Machine')};if($v){$r.proxy[$k]=$v}};",
24970
25012
  "$r|ConvertTo-Json -Compress -Depth 4"
24971
25013
  ].join("");
24972
- const result = await runPowerShell(script);
25014
+ const [result, bundled] = await Promise.all([runPowerShell(script), bundledCodexDirectories()]);
25015
+ bundledCliDirectories = bundled;
24973
25016
  if (!result.ok) return { ok: false, segments: [], failureReason: result.reason };
24974
25017
  let parsed;
24975
25018
  try {
@@ -24978,7 +25021,7 @@ async function readRegistryEnvironment() {
24978
25021
  return { ok: false, segments: [], failureReason: "empty_path" };
24979
25022
  }
24980
25023
  const raw = (Array.isArray(parsed.path) ? parsed.path : [parsed.path]).filter((value) => typeof value === "string");
24981
- const segments = [...new Set(raw.flatMap((value) => value.split(";")).map((segment) => expandVariables(segment.trim())).filter(Boolean))];
25024
+ const segments = [...new Set(raw.flatMap((value) => value.split(";")).map((segment) => expandVariables(segment.trim().replace(/^"(.*)"$/, "$1"))).filter(Boolean))];
24982
25025
  if (segments.length === 0) return { ok: false, segments: [], failureReason: "empty_path" };
24983
25026
  const proxyEnv = Object.fromEntries(Object.entries(parsed.proxy ?? {}).filter((entry) => typeof entry[1] === "string" && entry[1].length > 0));
24984
25027
  return { ok: true, segments, proxyEnv, failureReason: "none" };
@@ -24993,14 +25036,29 @@ var win32Platform = {
24993
25036
  return false;
24994
25037
  }
24995
25038
  },
24996
- userBinDirectories: (home) => [
24997
- // Why: Anthropic's native Windows installer places claude.exe here, and
24998
- // GUI-launched processes may not inherit the user's PATH entry for it.
24999
- join5(home, ".local", "bin"),
25000
- join5(home, "AppData", "Roaming", "npm"),
25001
- join5(home, "AppData", "Local", "pnpm"),
25002
- join5(home, "AppData", "Local", "Yarn", "bin")
25003
- ],
25039
+ userBinDirectories: (home) => {
25040
+ const roaming = process.env.APPDATA ?? join5(home, "AppData", "Roaming");
25041
+ const local = process.env.LOCALAPPDATA ?? join5(home, "AppData", "Local");
25042
+ return [
25043
+ // Native Windows CLI installers use this directory even without PATH.
25044
+ join5(home, ".local", "bin"),
25045
+ join5(roaming, "npm"),
25046
+ join5(roaming, "pnpm"),
25047
+ join5(local, "pnpm"),
25048
+ join5(local, "Yarn", "bin"),
25049
+ join5(local, "Microsoft", "WindowsApps"),
25050
+ join5(local, "Microsoft", "WinGet", "Links"),
25051
+ join5(home, "npm-global"),
25052
+ join5(process.env.SCOOP ?? join5(home, "scoop"), "shims"),
25053
+ npmPrefix(home),
25054
+ process.env.PNPM_HOME,
25055
+ process.env.NVM_SYMLINK,
25056
+ process.env.NVM_HOME,
25057
+ process.env.FNM_MULTISHELL_PATH,
25058
+ process.env.VOLTA_HOME && join5(process.env.VOLTA_HOME, "bin"),
25059
+ ...bundledCliDirectories
25060
+ ].filter((value) => Boolean(value));
25061
+ },
25004
25062
  fallbackBinDirectories: (home) => [join5(home, ".local", "bin")],
25005
25063
  normalizeEnvironment(env) {
25006
25064
  const copy = { ...env };
@@ -25082,6 +25140,7 @@ function mergePathSegments(segments) {
25082
25140
  // src/providers/cli-specs.ts
25083
25141
  var SOURCES = [
25084
25142
  { id: "codex", label: "Codex", command: "codex", versionArguments: ["--version"], promptStdin: { replaceWith: "-" }, restrictedPermission: true, installHint: "npm i -g @openai/codex" },
25143
+ { id: "kimi", label: "Kimi Code CLI", command: "kimi", versionArguments: ["--version"], installHint: "curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash" },
25085
25144
  { 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" },
25086
25145
  { id: "grok", label: "Grok CLI", command: "grok", versionArguments: ["--version"] },
25087
25146
  { id: "gemini", label: "Gemini CLI", command: "gemini", versionArguments: ["--version"], restrictedPermission: true, installHint: "npm i -g @google/gemini-cli" },
@@ -25127,18 +25186,18 @@ function detectedCliVersion(id) {
25127
25186
  // src/providers/provider.ts
25128
25187
  import { realpathSync } from "node:fs";
25129
25188
  import { homedir as homedir3 } from "node:os";
25130
- import { delimiter as delimiter4, dirname as dirname3 } from "node:path";
25189
+ import { delimiter as delimiter4, dirname as dirname4 } from "node:path";
25131
25190
 
25132
25191
  // src/shared/node-cli-command-resolution.ts
25133
- import { existsSync as existsSync3, readdirSync } from "node:fs";
25192
+ import { existsSync as existsSync3, readdirSync as readdirSync2 } from "node:fs";
25134
25193
  import { homedir as homedir2 } from "node:os";
25135
- import { dirname as dirname2, join as join6 } from "node:path";
25194
+ import { dirname as dirname3, join as join6 } from "node:path";
25136
25195
  function adapterOf(options) {
25137
25196
  return platformFor(options.platform ?? process.platform);
25138
25197
  }
25139
25198
  function splitPath(platform2, pathEnv) {
25140
25199
  if (!pathEnv) return [];
25141
- return pathEnv.split(platform2.id === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean);
25200
+ return pathEnv.split(platform2.id === "win32" ? ";" : ":").map((entry) => entry.trim().replace(/^"(.*)"$/, "$1")).filter(Boolean);
25142
25201
  }
25143
25202
  function parseVersionSegment(raw) {
25144
25203
  return raw.replace(/^v/i, "").split(".").map((segment) => Number.parseInt(segment, 10)).map((segment) => Number.isFinite(segment) ? segment : 0);
@@ -25172,12 +25231,12 @@ function getBaseVersionManagerDirectories(platform2, homePath) {
25172
25231
  function getNvmVersionDirectories(homePath) {
25173
25232
  const nvmVersionsDir = join6(homePath, ".nvm", "versions", "node");
25174
25233
  if (!existsSync3(nvmVersionsDir)) return [];
25175
- return readdirSync(nvmVersionsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareVersionDesc).map((entry) => join6(nvmVersionsDir, entry, "bin"));
25234
+ return readdirSync2(nvmVersionsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareVersionDesc).map((entry) => join6(nvmVersionsDir, entry, "bin"));
25176
25235
  }
25177
25236
  function getVersionManagerDirectories(platform2, homePath, executableNames) {
25178
25237
  const directories = getBaseVersionManagerDirectories(platform2, homePath);
25179
25238
  const firstNvmMatch = findFirstExecutable(platform2, getNvmVersionDirectories(homePath), executableNames);
25180
- if (firstNvmMatch) directories.unshift(dirname2(firstNvmMatch));
25239
+ if (firstNvmMatch) directories.unshift(dirname3(firstNvmMatch));
25181
25240
  return directories;
25182
25241
  }
25183
25242
  function resolveCliCommand(commandName, options = {}) {
@@ -25185,6 +25244,7 @@ function resolveCliCommand(commandName, options = {}) {
25185
25244
  }
25186
25245
  function findCliCommand(commandName, options = {}) {
25187
25246
  const platform2 = adapterOf(options);
25247
+ if (/[\\/]/.test(commandName)) return platform2.isRunnableFile(commandName) ? commandName : null;
25188
25248
  const executableNames = platform2.executableNames(commandName);
25189
25249
  const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null;
25190
25250
  const pathCandidate = findFirstExecutable(platform2, splitPath(platform2, pathEnv), executableNames);
@@ -25251,9 +25311,9 @@ function toolCallRows(name, path) {
25251
25311
  function providerEnvironment() {
25252
25312
  const env = currentPlatform.normalizeEnvironment(process.env);
25253
25313
  const commandPaths = [
25254
- dirname3(process.execPath),
25255
- ...getVersionManagerBinPaths(),
25314
+ dirname4(process.execPath),
25256
25315
  env.PATH,
25316
+ ...getVersionManagerBinPaths(),
25257
25317
  ...currentPlatform.fallbackBinDirectories(homedir3())
25258
25318
  ].filter((value) => Boolean(value));
25259
25319
  env.PATH = [...new Set(commandPaths)].join(delimiter4);
@@ -25321,7 +25381,7 @@ import { spawn as spawn3 } from "node:child_process";
25321
25381
  import { statSync as statSync3 } from "node:fs";
25322
25382
  import { chmod as chmod3, mkdir as mkdir3, readFile as readFile2, rename as rename3, stat, writeFile as writeFile3 } from "node:fs/promises";
25323
25383
  import { homedir as homedir4 } from "node:os";
25324
- import { dirname as dirname4, isAbsolute, join as join7, resolve as resolve2 } from "node:path";
25384
+ import { dirname as dirname5, isAbsolute, join as join7, resolve as resolve2 } from "node:path";
25325
25385
  var codexHome = () => process.env.CODEX_HOME?.trim() || join7(homedir4(), ".codex");
25326
25386
  var BUNDLED_TIMEOUT_MS = 1e4;
25327
25387
  function configuredCatalogPath(config2, home = codexHome()) {
@@ -25430,7 +25490,7 @@ async function rebuild() {
25430
25490
  return;
25431
25491
  }
25432
25492
  const path = overlayPath();
25433
- await mkdir3(dirname4(path), { recursive: true, mode: 448 });
25493
+ await mkdir3(dirname5(path), { recursive: true, mode: 448 });
25434
25494
  const temporary = `${path}.${process.pid}.tmp`;
25435
25495
  await writeFile3(temporary, JSON.stringify(filled), { mode: 384 });
25436
25496
  await rename3(temporary, path);
@@ -26484,7 +26544,7 @@ import { spawn as spawn6 } from "node:child_process";
26484
26544
  import { createHash } from "node:crypto";
26485
26545
  import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
26486
26546
  import { copyFile, mkdir as mkdir4, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
26487
- import { dirname as dirname5, join as join11, resolve as resolve4 } from "node:path";
26547
+ import { dirname as dirname6, join as join11, resolve as resolve4 } from "node:path";
26488
26548
  import { fileURLToPath } from "node:url";
26489
26549
  var AcpRuntimeUnavailable = class extends Error {
26490
26550
  constructor(message) {
@@ -26494,7 +26554,7 @@ var AcpRuntimeUnavailable = class extends Error {
26494
26554
  };
26495
26555
  var NPM_INSTALL_TIMEOUT_MS = 10 * 6e4;
26496
26556
  function packageRoot() {
26497
- let directory = dirname5(fileURLToPath(import.meta.url));
26557
+ let directory = dirname6(fileURLToPath(import.meta.url));
26498
26558
  while (true) {
26499
26559
  const path = resolve4(directory, "package.json");
26500
26560
  if (existsSync4(path)) {
@@ -26503,7 +26563,7 @@ function packageRoot() {
26503
26563
  } catch {
26504
26564
  }
26505
26565
  }
26506
- const parent = dirname5(directory);
26566
+ const parent = dirname6(directory);
26507
26567
  if (parent === directory) return void 0;
26508
26568
  directory = parent;
26509
26569
  }
@@ -26531,7 +26591,7 @@ var installs = /* @__PURE__ */ new Map();
26531
26591
  function ensureClaudeRuntime(dataDir2) {
26532
26592
  const entry = vendoredAdapter("claude");
26533
26593
  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"));
26534
- const manifestPath = join11(dirname5(entry), "runtime.json");
26594
+ const manifestPath = join11(dirname6(entry), "runtime.json");
26535
26595
  let manifest;
26536
26596
  try {
26537
26597
  manifest = JSON.parse(readFileSync4(manifestPath, "utf8"));
@@ -26616,6 +26676,14 @@ var KIRO_LAUNCH_SPEC = {
26616
26676
  resumable: (sessionId) => !sessionId.startsWith("sess_"),
26617
26677
  modelDiscovery: { kind: "reader", source: MODEL_SOURCES.kiro }
26618
26678
  };
26679
+ var KIMI_LAUNCH_SPEC = {
26680
+ agent: "kimi",
26681
+ headless: "acp",
26682
+ args: () => ["acp"],
26683
+ resumePreference: "resume",
26684
+ dialect: { failureRules: [{ kind: "sessionMissing", pattern: /session[^\n]{0,60}(?:not found|does not exist)|no such session/i }] },
26685
+ modelDiscovery: { kind: "session" }
26686
+ };
26619
26687
  var GEMINI_LAUNCH_SPEC = {
26620
26688
  agent: "gemini",
26621
26689
  headless: "acp",
@@ -26721,6 +26789,7 @@ var CODEX_LAUNCH_SPEC = {
26721
26789
  };
26722
26790
  var ACP_LAUNCH_SPECS = [
26723
26791
  KIRO_LAUNCH_SPEC,
26792
+ KIMI_LAUNCH_SPEC,
26724
26793
  GEMINI_LAUNCH_SPEC,
26725
26794
  GROK_LAUNCH_SPEC,
26726
26795
  OPENCODE_LAUNCH_SPEC,
@@ -28007,7 +28076,7 @@ function isWriterConflict(message) {
28007
28076
  }
28008
28077
 
28009
28078
  // src/providers/cli/claude.ts
28010
- import { readdirSync as readdirSync2, readFileSync as readFileSync5 } from "node:fs";
28079
+ import { readdirSync as readdirSync3, readFileSync as readFileSync5 } from "node:fs";
28011
28080
  import { homedir as homedir8 } from "node:os";
28012
28081
  import { join as join14 } from "node:path";
28013
28082
  var CLAUDE = requireCliSpec("claude");
@@ -28024,13 +28093,13 @@ function claudeTranscriptPath(sessionId) {
28024
28093
  for (const root2 of claudeProjectRoots()) {
28025
28094
  let projects;
28026
28095
  try {
28027
- projects = readdirSync2(root2);
28096
+ projects = readdirSync3(root2);
28028
28097
  } catch {
28029
28098
  continue;
28030
28099
  }
28031
28100
  for (const project of projects) {
28032
28101
  try {
28033
- if (readdirSync2(join14(root2, project)).includes(file2)) return join14(root2, project, file2);
28102
+ if (readdirSync3(join14(root2, project)).includes(file2)) return join14(root2, project, file2);
28034
28103
  } catch {
28035
28104
  }
28036
28105
  }
@@ -29159,7 +29228,7 @@ function resolveDetectedProviderCommands(foundCommands, commands = DETECTION_COM
29159
29228
  function probeVersion(path, args) {
29160
29229
  if (args.length === 0) return Promise.resolve({});
29161
29230
  return new Promise((resolve10) => {
29162
- const launch = directLaunch2(path, args);
29231
+ const launch = directLaunch2(path, args, process.env.TOC_OCRA_NODE_PATH || process.execPath);
29163
29232
  const child = spawn9(launch.executable, launch.args, { stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
29164
29233
  let stdout = "";
29165
29234
  let stderr = "";
@@ -29208,13 +29277,15 @@ var CliDetectionService = class {
29208
29277
  const foundCommands = new Set(commands.filter((command) => resolved.get(command)?.found));
29209
29278
  const detected = resolveDetectedProviderCommands(foundCommands, DETECTION_COMMANDS);
29210
29279
  const providers2 = await Promise.all(CLI_CATALOG.map(async (config2) => {
29211
- const matchedDetectionCommand = detected.get(config2.id);
29212
- const result = matchedDetectionCommand ? resolved.get(matchedDetectionCommand) : void 0;
29280
+ const override = process.env[config2.overrideEnv]?.trim();
29281
+ const unsupported = config2.detectUnsupportedRuntimes?.includes(process.platform) ?? false;
29282
+ const requiredPresent = (config2.detectRequiredCommands ?? []).every((command) => foundCommands.has(command));
29283
+ const matchedDetectionCommand = unsupported || !requiredPresent ? void 0 : override ? config2.detectCmd : detected.get(config2.id);
29284
+ const result = matchedDetectionCommand ? override ? resolveCliCommandDetailed(override) : resolved.get(matchedDetectionCommand) : void 0;
29213
29285
  const executablePath = result?.found ? result.path : void 0;
29214
29286
  const installed = Boolean(executablePath);
29215
- const unsupported = config2.detectUnsupportedRuntimes?.includes(process.platform) ?? false;
29216
29287
  const diagnostic = executablePath ? await probeVersion(executablePath, config2.versionArguments ?? []) : {};
29217
- const detail = installed ? diagnostic.detail : unsupported ? "unsupported runtime" : config2.detectRequiredCommands?.length ? "command or required command not found" : "command not found";
29288
+ 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";
29218
29289
  return {
29219
29290
  id: config2.id,
29220
29291
  installed,
@@ -32442,7 +32513,7 @@ async function runCliSmoke(options = {}) {
32442
32513
 
32443
32514
  // src/runtime/run-service.ts
32444
32515
  import { existsSync as existsSync6, readFileSync as readFileSync7 } from "node:fs";
32445
- import { dirname as dirname9, resolve as resolve8 } from "node:path";
32516
+ import { dirname as dirname10, resolve as resolve8 } from "node:path";
32446
32517
  import { fileURLToPath as fileURLToPath2 } from "node:url";
32447
32518
 
32448
32519
  // src/health/server.ts
@@ -32692,7 +32763,7 @@ import {
32692
32763
  unlinkSync,
32693
32764
  writeFileSync as writeFileSync2
32694
32765
  } from "node:fs";
32695
- import { dirname as dirname6 } from "node:path";
32766
+ import { dirname as dirname7 } from "node:path";
32696
32767
  var DEFAULT_MAX_BYTES = 5 * 1024 * 1024;
32697
32768
  var DEFAULT_MAX_ROTATED_FILES = 2;
32698
32769
  var PRIVATE_FILE_MODE = 384;
@@ -32716,7 +32787,7 @@ function createDiagnosticLogger(filePath, options = {}) {
32716
32787
  let disabled = false;
32717
32788
  let currentBytes = 0;
32718
32789
  try {
32719
- mkdirSync3(dirname6(filePath), { recursive: true });
32790
+ mkdirSync3(dirname7(filePath), { recursive: true });
32720
32791
  pruneExpired();
32721
32792
  currentBytes = existsSync5(filePath) ? statSync4(filePath).size : 0;
32722
32793
  } catch {
@@ -33091,7 +33162,7 @@ async function controlTbSwitch(payload) {
33091
33162
 
33092
33163
  // src/runs/orphan-registry.ts
33093
33164
  import { mkdir as mkdir8, readFile as readFile9, rename as rename7, writeFile as writeFile8 } from "node:fs/promises";
33094
- import { basename as basename3, dirname as dirname7 } from "node:path";
33165
+ import { basename as basename3, dirname as dirname8 } from "node:path";
33095
33166
  var OrphanRegistry = class {
33096
33167
  constructor(file2) {
33097
33168
  this.file = file2;
@@ -33109,7 +33180,7 @@ var OrphanRegistry = class {
33109
33180
  persist() {
33110
33181
  const snapshot = JSON.stringify([...this.records.values()]);
33111
33182
  this.writing = this.writing.then(async () => {
33112
- await mkdir8(dirname7(this.file), { recursive: true, mode: 448 });
33183
+ await mkdir8(dirname8(this.file), { recursive: true, mode: 448 });
33113
33184
  const temporary = `${this.file}.${process.pid}.tmp`;
33114
33185
  await writeFile8(temporary, snapshot, { mode: 384 });
33115
33186
  await rename7(temporary, this.file);
@@ -33271,9 +33342,9 @@ var GatewayClient = class {
33271
33342
  };
33272
33343
 
33273
33344
  // src/workspace/directory-browser.ts
33274
- import { readdir as readdir3, realpath as realpath4, stat as stat7 } from "node:fs/promises";
33345
+ import { mkdir as mkdir9, readdir as readdir3, realpath as realpath4, stat as stat7 } from "node:fs/promises";
33275
33346
  import { homedir as homedir11 } from "node:os";
33276
- import { dirname as dirname8, parse as parse3, resolve as resolve6 } from "node:path";
33347
+ import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
33277
33348
  var MAX_ENTRIES = 1e3;
33278
33349
  async function listDirectory(requested, allowedRoots) {
33279
33350
  const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir11()) || homedir11();
@@ -33293,7 +33364,7 @@ async function listDirectory(requested, allowedRoots) {
33293
33364
  if (entry.isDirectory()) directories.push(item);
33294
33365
  else if (entry.isFile()) files.push(item);
33295
33366
  }
33296
- const parent = dirname8(directory);
33367
+ const parent = dirname9(directory);
33297
33368
  const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir11() }];
33298
33369
  for (const root2 of allowedRoots) if (root2 !== homedir11()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root2 });
33299
33370
  places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
@@ -33306,12 +33377,35 @@ async function listDirectory(requested, allowedRoots) {
33306
33377
  places
33307
33378
  };
33308
33379
  }
33380
+ async function createDirectory(parentRequested, name) {
33381
+ const parentInput = parentRequested.trim();
33382
+ if (!parentInput || !isAbsolute5(parentInput)) throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
33383
+ 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)) {
33384
+ throw new Error("\u8BF7\u8F93\u5165\u6709\u6548\u7684\u6587\u4EF6\u5939\u540D\u79F0");
33385
+ }
33386
+ const parent = await realpath4(resolve6(parentInput)).catch(() => {
33387
+ throw new Error(`\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${parentRequested}`);
33388
+ });
33389
+ if (!(await stat7(parent)).isDirectory()) throw new Error("\u4E0A\u7EA7\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
33390
+ const path = resolve6(parent, name);
33391
+ if (dirname9(path) !== parent) throw new Error("\u6587\u4EF6\u5939\u540D\u79F0\u65E0\u6548");
33392
+ try {
33393
+ await mkdir9(path);
33394
+ } catch (error62) {
33395
+ const code2 = error62.code;
33396
+ if (code2 === "EEXIST") throw new Error("\u8BE5\u6587\u4EF6\u5939\u5DF2\u5B58\u5728");
33397
+ if (code2 === "EACCES" || code2 === "EPERM") throw new Error("\u6CA1\u6709\u6743\u9650\u5728\u6B64\u4F4D\u7F6E\u521B\u5EFA\u6587\u4EF6\u5939");
33398
+ if (code2 === "ENOENT") throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728");
33399
+ throw error62;
33400
+ }
33401
+ return { path };
33402
+ }
33309
33403
 
33310
33404
  // src/workspace/workspace-manager.ts
33311
33405
  import { spawn as spawn13 } from "node:child_process";
33312
- import { chmod as chmod5, mkdir as mkdir9, mkdtemp as mkdtemp3, opendir, realpath as realpath5, rm as rm6, stat as stat8, writeFile as writeFile9 } from "node:fs/promises";
33313
- import { homedir as homedir12, tmpdir as tmpdir4 } from "node:os";
33314
- import { isAbsolute as isAbsolute5, join as join21, relative as relative3, resolve as resolve7 } from "node:path";
33406
+ import { opendir, realpath as realpath5, stat as stat8 } from "node:fs/promises";
33407
+ import { homedir as homedir12 } from "node:os";
33408
+ import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
33315
33409
  var MAX_NODES = 2e3;
33316
33410
  var MAX_DIRECTORY_ENTRIES = 12e3;
33317
33411
  var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
@@ -33345,193 +33439,13 @@ var WorkspaceManager = class {
33345
33439
  const nodes = await this.scanTree(rootPath, request.max_depth, request.scan_roots);
33346
33440
  return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
33347
33441
  }
33348
- /** Creates missing folders, clones missing repos, fast-forwards clean ones. */
33349
- async sync(request) {
33350
- const startedAt = Date.now();
33351
- const rootPath = this.validateRootPath(request.root_path);
33352
- const results = await this.syncTree(rootPath, request);
33353
- const failed = results.some((result) => result.status === "failed");
33354
- return {
33355
- root_path: rootPath,
33356
- results,
33357
- ...failed ? { error: "\u90E8\u5206\u76EE\u5F55\u6216\u4ED3\u5E93\u540C\u6B65\u5931\u8D25" } : {},
33358
- duration_ms: Date.now() - startedAt
33359
- };
33360
- }
33361
33442
  validateRootPath(value) {
33362
33443
  const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir12());
33363
33444
  const root2 = resolve7(raw);
33364
- if (!isAbsolute5(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
33445
+ if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
33365
33446
  if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
33366
33447
  return root2;
33367
33448
  }
33368
- async syncTree(rootPath, request) {
33369
- await mkdir9(rootPath, { recursive: true });
33370
- await addAllowedRoot(this.config, rootPath);
33371
- const results = [];
33372
- const requestedPaths = /* @__PURE__ */ new Set();
33373
- for (const directory of request.directories) {
33374
- const relativePath = this.cleanRelativePath(directory);
33375
- if (requestedPaths.has(relativePath)) continue;
33376
- requestedPaths.add(relativePath);
33377
- const target = this.resolveWithinRoot(rootPath, relativePath);
33378
- try {
33379
- const metadata = await stat8(target).catch(() => void 0);
33380
- if (metadata) {
33381
- if (!metadata.isDirectory()) {
33382
- throw new Error("The existing workspace path is not a directory");
33383
- }
33384
- results.push({
33385
- relative_path: relativePath,
33386
- status: "skipped",
33387
- kind: "directory",
33388
- action: "skip",
33389
- message: "\u76EE\u5F55\u5DF2\u5B58\u5728"
33390
- });
33391
- continue;
33392
- }
33393
- await mkdir9(target, { recursive: true });
33394
- results.push({
33395
- relative_path: relativePath,
33396
- status: "created",
33397
- kind: "directory",
33398
- action: "mkdir",
33399
- message: "\u76EE\u5F55\u5DF2\u521B\u5EFA"
33400
- });
33401
- } catch (error62) {
33402
- results.push({
33403
- relative_path: relativePath,
33404
- status: "failed",
33405
- kind: "directory",
33406
- action: "mkdir",
33407
- error: this.message(error62)
33408
- });
33409
- }
33410
- }
33411
- const authEnvironment = await this.createGitAuthEnvironment(request.git_auth);
33412
- try {
33413
- for (const repo of request.repos) {
33414
- const relativePath = this.cleanRelativePath(repo.relative_path);
33415
- try {
33416
- results.push(await this.syncRepository(rootPath, relativePath, repo.git_url?.trim() || void 0, repo.branch?.trim() || void 0, request.timeout_s, authEnvironment?.env));
33417
- } catch (error62) {
33418
- results.push({
33419
- relative_path: relativePath,
33420
- status: "failed",
33421
- kind: "repo",
33422
- action: "sync",
33423
- error: this.message(error62)
33424
- });
33425
- }
33426
- }
33427
- } finally {
33428
- await authEnvironment?.cleanup();
33429
- }
33430
- return results;
33431
- }
33432
- async syncRepository(rootPath, relativePath, gitUrl, branch, timeoutSeconds, gitEnvironment) {
33433
- const target = this.resolveWithinRoot(rootPath, relativePath);
33434
- let created = false;
33435
- let metadata;
33436
- try {
33437
- metadata = await stat8(target);
33438
- } catch {
33439
- }
33440
- if (!metadata) {
33441
- if (!gitUrl) throw new Error("A missing repository needs a Git remote URL");
33442
- await mkdir9(resolve7(target, ".."), { recursive: true });
33443
- const cloneArgs = branch ? ["clone", "--branch", branch, "--single-branch", gitUrl, target] : ["clone", gitUrl, target];
33444
- await this.runGit(cloneArgs, rootPath, timeoutSeconds, false, gitEnvironment);
33445
- created = true;
33446
- } else {
33447
- if (!metadata.isDirectory()) throw new Error("The repository path is not a directory");
33448
- if (!await this.isGitRepository(target, timeoutSeconds)) {
33449
- throw new Error("The existing directory is not a Git repository");
33450
- }
33451
- if (gitUrl) {
33452
- const currentOrigin = (await this.runGit(["config", "--get", "remote.origin.url"], target, timeoutSeconds, true)).stdout.trim();
33453
- if (currentOrigin && currentOrigin !== gitUrl) {
33454
- throw new Error("The existing repository origin does not match the configured Git URL");
33455
- }
33456
- }
33457
- const worktree = await this.runGit(["status", "--porcelain"], target, timeoutSeconds);
33458
- if (worktree.stdout.trim()) {
33459
- return {
33460
- relative_path: relativePath,
33461
- status: "skipped",
33462
- kind: "repo",
33463
- action: "skip",
33464
- message: "\u4ED3\u5E93\u5B58\u5728\u672A\u63D0\u4EA4\u7684\u672C\u5730\u4FEE\u6539"
33465
- };
33466
- }
33467
- if (branch) {
33468
- const currentBranch = await this.runGit(["branch", "--show-current"], target, timeoutSeconds);
33469
- if (currentBranch.stdout.trim() !== branch) {
33470
- return {
33471
- relative_path: relativePath,
33472
- status: "skipped",
33473
- kind: "repo",
33474
- action: "skip",
33475
- message: `\u5F53\u524D\u5206\u652F ${currentBranch.stdout.trim() || "(detached)"} \u4E0E\u76EE\u6807\u5206\u652F ${branch} \u4E0D\u4E00\u81F4`
33476
- };
33477
- }
33478
- }
33479
- }
33480
- await this.runGit(["fetch", "--prune", "origin"], target, timeoutSeconds, false, gitEnvironment);
33481
- if (branch) {
33482
- const remoteBranch = await this.runGit(
33483
- ["show-ref", "--verify", "--quiet", `refs/remotes/origin/${branch}`],
33484
- target,
33485
- timeoutSeconds,
33486
- true
33487
- );
33488
- if (remoteBranch.exitCode !== 0) {
33489
- return {
33490
- relative_path: relativePath,
33491
- status: "skipped",
33492
- kind: "repo",
33493
- action: "skip",
33494
- message: `\u8FDC\u7AEF\u5206\u652F origin/${branch} \u4E0D\u5B58\u5728`
33495
- };
33496
- }
33497
- if (!created) {
33498
- const currentCommit = await this.runGit(["rev-parse", "HEAD"], target, timeoutSeconds);
33499
- const remoteCommit = await this.runGit(["rev-parse", `origin/${branch}`], target, timeoutSeconds);
33500
- if (currentCommit.stdout.trim() === remoteCommit.stdout.trim()) {
33501
- return {
33502
- relative_path: relativePath,
33503
- status: "skipped",
33504
- kind: "repo",
33505
- action: "skip",
33506
- message: "\u4ED3\u5E93\u5DF2\u662F\u6700\u65B0"
33507
- };
33508
- }
33509
- const fastForward = await this.runGit(
33510
- ["merge-base", "--is-ancestor", "HEAD", `origin/${branch}`],
33511
- target,
33512
- timeoutSeconds,
33513
- true
33514
- );
33515
- if (fastForward.exitCode !== 0) {
33516
- return {
33517
- relative_path: relativePath,
33518
- status: "skipped",
33519
- kind: "repo",
33520
- action: "skip",
33521
- message: "\u672C\u5730\u63D0\u4EA4\u65E0\u6CD5\u5FEB\u8FDB\u5230\u8FDC\u7AEF\u5206\u652F"
33522
- };
33523
- }
33524
- }
33525
- await this.runGit(["pull", "--ff-only", "origin", branch], target, timeoutSeconds, false, gitEnvironment);
33526
- }
33527
- return {
33528
- relative_path: relativePath,
33529
- status: created ? "created" : "updated",
33530
- kind: "repo",
33531
- action: created ? "clone" : "pull",
33532
- message: created ? "\u4ED3\u5E93\u5DF2\u514B\u9686" : "\u4ED3\u5E93\u5DF2\u5FEB\u8FDB\u66F4\u65B0"
33533
- };
33534
- }
33535
33449
  async scanTree(rootPath, maxDepth, scanRoots) {
33536
33450
  const resolvedRoot = await realpath5(rootPath);
33537
33451
  const rootMetadata = await stat8(resolvedRoot);
@@ -33645,16 +33559,16 @@ var WorkspaceManager = class {
33645
33559
  resolveWithinRoot(rootPath, relativePath) {
33646
33560
  const target = resolve7(rootPath, relativePath);
33647
33561
  const relativeToRoot = relative3(rootPath, target);
33648
- if (relativeToRoot.startsWith("..") || isAbsolute5(relativeToRoot)) {
33562
+ if (relativeToRoot.startsWith("..") || isAbsolute6(relativeToRoot)) {
33649
33563
  throw new Error("A workspace path must remain under the configured workspace root");
33650
33564
  }
33651
33565
  return target;
33652
33566
  }
33653
- runGit(args, cwd, timeoutSeconds, allowFailure = false, environment) {
33567
+ runGit(args, cwd, timeoutSeconds, allowFailure = false) {
33654
33568
  return new Promise((resolveCommand, rejectCommand) => {
33655
33569
  const child = spawn13("git", args, {
33656
33570
  cwd,
33657
- env: environment ?? process.env,
33571
+ env: process.env,
33658
33572
  shell: false,
33659
33573
  stdio: ["ignore", "pipe", "pipe"]
33660
33574
  });
@@ -33684,37 +33598,6 @@ var WorkspaceManager = class {
33684
33598
  });
33685
33599
  });
33686
33600
  }
33687
- async createGitAuthEnvironment(auth) {
33688
- if (!auth) return void 0;
33689
- const directory = await mkdtemp3(join21(tmpdir4(), "toc-ocra-git-auth-"));
33690
- const isWindows = process.platform === "win32";
33691
- const scriptPath = join21(directory, isWindows ? "askpass.cmd" : "askpass.sh");
33692
- let script;
33693
- if (isWindows) {
33694
- const helperPath = join21(directory, "askpass.cjs");
33695
- await writeFile9(
33696
- helperPath,
33697
- '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',
33698
- { mode: 448 }
33699
- );
33700
- script = '@echo off\r\n"%ECHO_NODE_PATH%" "%~dp0askpass.cjs" "%~1"\r\n';
33701
- } else {
33702
- script = '#!/bin/sh\ncase "$1" in *Username*|*username*) printf "%s\\n" "$ECHO_GIT_USERNAME" ;; *) printf "%s\\n" "$ECHO_GIT_PASSWORD" ;; esac\n';
33703
- }
33704
- await writeFile9(scriptPath, script, { mode: 448 });
33705
- if (!isWindows) await chmod5(scriptPath, 448);
33706
- return {
33707
- env: {
33708
- ...process.env,
33709
- GIT_ASKPASS: scriptPath,
33710
- GIT_TERMINAL_PROMPT: "0",
33711
- ECHO_NODE_PATH: process.execPath,
33712
- ECHO_GIT_USERNAME: auth.username,
33713
- ECHO_GIT_PASSWORD: auth.password
33714
- },
33715
- cleanup: () => rm6(directory, { recursive: true, force: true })
33716
- };
33717
- }
33718
33601
  message(error62) {
33719
33602
  return error62 instanceof Error ? error62.message : String(error62);
33720
33603
  }
@@ -33840,22 +33723,15 @@ var CliProviderControlPayloadSchema = external_exports.object({
33840
33723
  }).strict();
33841
33724
  var RelativePathSchema = external_exports.string().min(1).max(500);
33842
33725
  var FsListPayloadSchema = external_exports.object({ path: external_exports.string().max(4096).optional().default("") });
33726
+ var FsMkdirPayloadSchema = external_exports.object({
33727
+ parent_path: external_exports.string().min(1).max(4096),
33728
+ name: external_exports.string().min(1).max(255)
33729
+ }).strict();
33843
33730
  var WorkspaceScanPayloadSchema = external_exports.object({
33844
33731
  root_path: external_exports.string().min(1).max(4096),
33845
33732
  max_depth: external_exports.number().int().positive().max(20).optional(),
33846
33733
  scan_roots: external_exports.array(external_exports.object({ relative_path: RelativePathSchema, max_depth: external_exports.number().int().positive().max(20) })).max(2e3).optional()
33847
33734
  });
33848
- var WorkspaceSyncPayloadSchema = external_exports.object({
33849
- root_path: external_exports.string().min(1).max(4096),
33850
- directories: external_exports.array(RelativePathSchema).max(2e3).default([]),
33851
- repos: external_exports.array(external_exports.object({
33852
- relative_path: RelativePathSchema,
33853
- git_url: external_exports.string().max(2e3).nullable().optional(),
33854
- branch: external_exports.string().max(200).nullable().optional()
33855
- })).max(2e3).default([]),
33856
- timeout_s: external_exports.number().int().positive().max(3600).optional(),
33857
- git_auth: external_exports.object({ username: external_exports.string().min(1).max(500), password: external_exports.string().min(1).max(4096) }).optional()
33858
- });
33859
33735
 
33860
33736
  // src/runtime/agent-runtime.ts
33861
33737
  var sleep3 = (ms, signal2) => new Promise((resolve10) => {
@@ -34248,15 +34124,14 @@ var AgentRuntime = class {
34248
34124
  const payload = FsListPayloadSchema.parse(command.payload ?? {});
34249
34125
  return { success: true, result: await listDirectory(payload.path, this.config.allowedRoots) };
34250
34126
  }
34127
+ case "fs.mkdir": {
34128
+ const payload = FsMkdirPayloadSchema.parse(command.payload);
34129
+ return { success: true, result: await createDirectory(payload.parent_path, payload.name) };
34130
+ }
34251
34131
  case "workspace.scan": {
34252
34132
  const payload = WorkspaceScanPayloadSchema.parse(command.payload);
34253
34133
  return { success: true, result: await this.workspaces.scan(payload) };
34254
34134
  }
34255
- case "workspace.sync": {
34256
- const payload = WorkspaceSyncPayloadSchema.parse(command.payload);
34257
- const result = await this.workspaces.sync(payload);
34258
- return { success: !result.error, result, ...result.error ? { error: result.error } : {} };
34259
- }
34260
34135
  case "sql.run": {
34261
34136
  const payload = SqlRunPayloadSchema.parse(command.payload);
34262
34137
  this.checkPolicy("sql", payload.policy);
@@ -34267,16 +34142,14 @@ var AgentRuntime = class {
34267
34142
  }
34268
34143
  }
34269
34144
  /**
34270
- * Script / SQL run only when the server policy allows it and the local
34271
- * owner has not switched it off. The policy attached to the command was
34145
+ * Script / SQL run when the server policy allows it. The policy attached to the command was
34272
34146
  * checked by the server at enqueue time, so it wins over the (up to one
34273
34147
  * heartbeat old) cached copy. New policy fields (read-only SQL,
34274
34148
  * allowlists) are enforced here.
34275
34149
  */
34276
34150
  checkPolicy(kind, commandPolicy) {
34277
- const localOff = kind === "script" ? this.config.disableScript : this.config.disableSql;
34278
34151
  const policy = commandPolicy ?? this.policy;
34279
- const enabled = !localOff && policy[kind].enabled;
34152
+ const enabled = policy[kind].enabled;
34280
34153
  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");
34281
34154
  }
34282
34155
  // ---- Reports ----
@@ -34456,7 +34329,9 @@ var AgentService = class {
34456
34329
  await this.stop();
34457
34330
  throw error62;
34458
34331
  }
34459
- } 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\n");
34332
+ } 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>
34333
+ \u5F53\u524D\u914D\u7F6E\uFF1A${this.config.configPath}
34334
+ `);
34460
34335
  }
34461
34336
  stop() {
34462
34337
  return this.stopPromise ??= (async () => {
@@ -34526,7 +34401,9 @@ var AgentService = class {
34526
34401
  id: provider.id,
34527
34402
  installed: provider.installed,
34528
34403
  runnable: provider.available,
34529
- version: provider.version ?? ""
34404
+ version: provider.version ?? "",
34405
+ path: provider.resolvedPath ?? "",
34406
+ detail: provider.detail ?? ""
34530
34407
  }))
34531
34408
  };
34532
34409
  }
@@ -34597,7 +34474,7 @@ function errorMessage3(error62) {
34597
34474
  // src/runtime/run-service.ts
34598
34475
  var PACKAGE_NAME = "toc-ocra";
34599
34476
  function agentPackageRoot() {
34600
- let directory = dirname9(fileURLToPath2(import.meta.url));
34477
+ let directory = dirname10(fileURLToPath2(import.meta.url));
34601
34478
  while (true) {
34602
34479
  const packagePath = resolve8(directory, "package.json");
34603
34480
  if (existsSync6(packagePath)) {
@@ -34607,7 +34484,7 @@ function agentPackageRoot() {
34607
34484
  } catch {
34608
34485
  }
34609
34486
  }
34610
- const parent = dirname9(directory);
34487
+ const parent = dirname10(directory);
34611
34488
  if (parent === directory) return void 0;
34612
34489
  directory = parent;
34613
34490
  }
@@ -34760,23 +34637,22 @@ async function enroll(args) {
34760
34637
  async function setup(args) {
34761
34638
  const server = option(args, "--server");
34762
34639
  if (!server) throw new Error("\u7528\u6CD5\uFF1Atoc-ocra setup --server <\u540E\u7AEF\u5730\u5740> [--code <\u914D\u5BF9\u7801>]\uFF08\u4E0D\u5E26 --code \u65F6\u626B\u7801\u6216\u8F93\u5165\u8FDE\u63A5\u7801\u914D\u5BF9\uFF09");
34763
- const configPath = option(args, "--config");
34764
34640
  const result = await pairDevice(args, server);
34765
34641
  process.stdout.write(`\u914D\u5BF9\u6210\u529F\uFF1A\u8BBE\u5907\u300C${result.deviceName}\u300D\uFF08${result.deviceId}\uFF09
34766
34642
  \u540E\u7AEF\uFF1A${result.serverUrl}
34767
34643
  \u6B63\u5728\u5B89\u88C5\u540E\u53F0\u670D\u52A1\u2026
34768
34644
  `);
34769
- if (!manageService("install", configPath ? ["--config", configPath] : [])) {
34645
+ if (!manageService("install", ["--config", result.configPath])) {
34770
34646
  process.stderr.write("\u540E\u53F0\u670D\u52A1\u5B89\u88C5\u5931\u8D25\uFF0C\u53EF\u4EE5\u5148\u8FD0\u884C toc-ocra run \u4E34\u65F6\u542F\u52A8\n");
34771
34647
  return;
34772
34648
  }
34773
- process.stdout.write("\u5B8C\u6210\uFF1A\u8BBE\u5907\u4EE3\u7406\u5DF2\u4F5C\u4E3A\u540E\u53F0\u670D\u52A1\u8FD0\u884C\uFF0C\u5F00\u673A\u81EA\u52A8\u542F\u52A8\u3002\u56DE\u5230 Echo \u9875\u9762\u5373\u53EF\u770B\u5230\u8FD9\u53F0\u8BBE\u5907\u4E0A\u7EBF\u3002\n");
34649
+ process.stdout.write("\u5B8C\u6210\uFF1A\u540E\u53F0\u670D\u52A1\u5DF2\u542F\u52A8\u5E76\u786E\u8BA4\u7ED1\u5B9A\uFF0C\u5F00\u673A\u81EA\u52A8\u542F\u52A8\u3002\u56DE\u5230 Echo \u9875\u9762\u53EF\u67E5\u770B\u5728\u7EBF\u72B6\u6001\u3002\n");
34774
34650
  if (process.platform === "linux") {
34775
34651
  process.stdout.write('\u63D0\u793A\uFF1A\u5982\u9700\u5728\u9000\u51FA\u767B\u5F55\u540E\u7EE7\u7EED\u8FD0\u884C\uFF0C\u8BF7\u6267\u884C\u4E00\u6B21 loginctl enable-linger "$USER"\n');
34776
34652
  }
34777
34653
  }
34778
34654
  function manageService(action, args) {
34779
- const script = resolve9(dirname10(fileURLToPath3(import.meta.url)), "../../scripts/service.mjs");
34655
+ const script = resolve9(dirname11(fileURLToPath3(import.meta.url)), "../../scripts/service.mjs");
34780
34656
  if (!existsSync7(script)) throw new Error(`service manager is missing: ${script}`);
34781
34657
  const result = spawnSync(process.execPath, [script, action, ...args], { stdio: "inherit", shell: false });
34782
34658
  if (result.error) throw result.error;
@@ -34791,7 +34667,7 @@ async function update(args) {
34791
34667
  if (customConfig) process.env.TOC_OCRA_CONFIG = resolve9(customConfig);
34792
34668
  await ensureIdle();
34793
34669
  const npmPath = resolveCliCommand("npm");
34794
- const temporary = mkdtempSync(join23(tmpdir5(), "toc-ocra-update-"));
34670
+ const temporary = mkdtempSync(join23(tmpdir4(), "toc-ocra-update-"));
34795
34671
  try {
34796
34672
  const metadataResponse = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`, { headers: { accept: "application/json", "cache-control": "no-cache" }, signal: AbortSignal.timeout(15e3) });
34797
34673
  if (!metadataResponse.ok) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 npm \u6700\u65B0\u7248\u672C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");