toc-ocra 0.3.10 → 0.3.11

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 CHANGED
@@ -48,8 +48,8 @@ node dist/src/index.js run
48
48
 
49
49
  **其他电脑**(一条命令接入)
50
50
 
51
- 1. 选择系统(Linux / macOS / Windows)和设备名,插件在当前工作空间创建设备、生成配对码,并给出一条命令,例如 `npm install -g toc-ocra@latest && toc-ocra setup --code ABCD-EFGH --server https://echo.example.com`(Windows PowerShell:`npm install -g toc-ocra@latest; if ($?) { toc-ocra setup ... }`)。
52
- 2. `toc-ocra setup` = 配对 + 安装后台服务(macOS LaunchAgent / Linux systemd 用户服务 / Windows 计划任务),执行完设备即上线;插件轮询到新凭据且在线后显示「已匹配」。
51
+ 1. 选择系统(Linux / macOS / Windows)和设备名,插件在当前工作空间创建设备、生成配对码,并给出一条命令,例如 `npm install -g toc-ocra@latest && toc-ocra setup --code ABCD-EFGH --server https://echo.example.com`(Windows PowerShell:`npm.cmd install -g toc-ocra@latest; if ($?) { toc-ocra.cmd setup ... }`,使用 `.cmd` 避免 PowerShell 拦截 npm 的 `.ps1` 启动脚本)。
52
+ 2. `toc-ocra setup` = 配对 + 安装后台服务(macOS LaunchAgent / Linux systemd 用户服务 / Windows 计划任务)。后台服务使用配对时实际保存的配置文件和数据目录,包括 `--config`、`TOC_OCRA_CONFIG`、`TOC_OCRA_DATA_DIR`;安装完成前会确认服务版本、设备身份和服务器绑定地址,启动失败或读取了其他配置时会报错。插件轮询到新凭据且在线后显示「已匹配」。
53
53
  3. 「接收任务」开关调用 `PUT /api/devices/:id/enabled`:关闭即停用,保留配对、不再派发任务,重新打开立即恢复,不需要操作那台电脑。彻底卸载在那台电脑执行 `toc-ocra service:uninstall`。
54
54
  4. 服务器地址必须能被那台电脑访问,填 `127.0.0.1` / `localhost` 时插件会提示。
55
55
 
@@ -103,6 +103,8 @@ kiro-cli chat --no-interactive --trust-all-tools --model gpt-5.6-luna --effort h
103
103
 
104
104
  数据目录:macOS `~/Library/Application Support/toc-ocra`,Linux `~/.local/state/toc-ocra`,Windows `%APPDATA%\toc-ocra`。与旧的 `echo-cli-agent` 互不影响,可以同时安装。
105
105
 
106
+ Windows CLI 探测会读取系统和用户 PATH、实际的 `%APPDATA%` / `%LOCALAPPDATA%`、npm 自定义 prefix、pnpm / NVM / fnm / Volta / Scoop 目录,并从当前用户安装的 ChatGPT / Codex 应用资源中查找内置 `codex.exe`。用户 PATH 优先于应用内置 CLI。指定 `TOC_OCRA_CODEX_PATH` 等变量时,探测与执行共用该路径;配置失效时,`toc-ocra doctor` 会指出变量名和路径。插件连接本机服务后会立即尝试绑定当前服务器,自动绑定失败会显示具体原因。
107
+
106
108
  ## 设计要点
107
109
 
108
110
  - **不保持长连接**:每 30 秒一次心跳,另有一个长轮询拉指令(有指令立即返回,最长等 25 秒)。超过 90 秒没有心跳,服务端判定设备离线。
package/dist/cli/cli.mjs CHANGED
@@ -4579,7 +4579,7 @@ import { createHash as createHash5 } from "node:crypto";
4579
4579
  import { existsSync as existsSync7, mkdtempSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
4580
4580
  import { tmpdir as tmpdir5 } 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 };
@@ -25127,18 +25185,18 @@ function detectedCliVersion(id) {
25127
25185
  // src/providers/provider.ts
25128
25186
  import { realpathSync } from "node:fs";
25129
25187
  import { homedir as homedir3 } from "node:os";
25130
- import { delimiter as delimiter4, dirname as dirname3 } from "node:path";
25188
+ import { delimiter as delimiter4, dirname as dirname4 } from "node:path";
25131
25189
 
25132
25190
  // src/shared/node-cli-command-resolution.ts
25133
- import { existsSync as existsSync3, readdirSync } from "node:fs";
25191
+ import { existsSync as existsSync3, readdirSync as readdirSync2 } from "node:fs";
25134
25192
  import { homedir as homedir2 } from "node:os";
25135
- import { dirname as dirname2, join as join6 } from "node:path";
25193
+ import { dirname as dirname3, join as join6 } from "node:path";
25136
25194
  function adapterOf(options) {
25137
25195
  return platformFor(options.platform ?? process.platform);
25138
25196
  }
25139
25197
  function splitPath(platform2, pathEnv) {
25140
25198
  if (!pathEnv) return [];
25141
- return pathEnv.split(platform2.id === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean);
25199
+ return pathEnv.split(platform2.id === "win32" ? ";" : ":").map((entry) => entry.trim().replace(/^"(.*)"$/, "$1")).filter(Boolean);
25142
25200
  }
25143
25201
  function parseVersionSegment(raw) {
25144
25202
  return raw.replace(/^v/i, "").split(".").map((segment) => Number.parseInt(segment, 10)).map((segment) => Number.isFinite(segment) ? segment : 0);
@@ -25172,12 +25230,12 @@ function getBaseVersionManagerDirectories(platform2, homePath) {
25172
25230
  function getNvmVersionDirectories(homePath) {
25173
25231
  const nvmVersionsDir = join6(homePath, ".nvm", "versions", "node");
25174
25232
  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"));
25233
+ return readdirSync2(nvmVersionsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareVersionDesc).map((entry) => join6(nvmVersionsDir, entry, "bin"));
25176
25234
  }
25177
25235
  function getVersionManagerDirectories(platform2, homePath, executableNames) {
25178
25236
  const directories = getBaseVersionManagerDirectories(platform2, homePath);
25179
25237
  const firstNvmMatch = findFirstExecutable(platform2, getNvmVersionDirectories(homePath), executableNames);
25180
- if (firstNvmMatch) directories.unshift(dirname2(firstNvmMatch));
25238
+ if (firstNvmMatch) directories.unshift(dirname3(firstNvmMatch));
25181
25239
  return directories;
25182
25240
  }
25183
25241
  function resolveCliCommand(commandName, options = {}) {
@@ -25185,6 +25243,7 @@ function resolveCliCommand(commandName, options = {}) {
25185
25243
  }
25186
25244
  function findCliCommand(commandName, options = {}) {
25187
25245
  const platform2 = adapterOf(options);
25246
+ if (/[\\/]/.test(commandName)) return platform2.isRunnableFile(commandName) ? commandName : null;
25188
25247
  const executableNames = platform2.executableNames(commandName);
25189
25248
  const pathEnv = options.pathEnv ?? process.env.PATH ?? process.env.Path ?? null;
25190
25249
  const pathCandidate = findFirstExecutable(platform2, splitPath(platform2, pathEnv), executableNames);
@@ -25251,9 +25310,9 @@ function toolCallRows(name, path) {
25251
25310
  function providerEnvironment() {
25252
25311
  const env = currentPlatform.normalizeEnvironment(process.env);
25253
25312
  const commandPaths = [
25254
- dirname3(process.execPath),
25255
- ...getVersionManagerBinPaths(),
25313
+ dirname4(process.execPath),
25256
25314
  env.PATH,
25315
+ ...getVersionManagerBinPaths(),
25257
25316
  ...currentPlatform.fallbackBinDirectories(homedir3())
25258
25317
  ].filter((value) => Boolean(value));
25259
25318
  env.PATH = [...new Set(commandPaths)].join(delimiter4);
@@ -25321,7 +25380,7 @@ import { spawn as spawn3 } from "node:child_process";
25321
25380
  import { statSync as statSync3 } from "node:fs";
25322
25381
  import { chmod as chmod3, mkdir as mkdir3, readFile as readFile2, rename as rename3, stat, writeFile as writeFile3 } from "node:fs/promises";
25323
25382
  import { homedir as homedir4 } from "node:os";
25324
- import { dirname as dirname4, isAbsolute, join as join7, resolve as resolve2 } from "node:path";
25383
+ import { dirname as dirname5, isAbsolute, join as join7, resolve as resolve2 } from "node:path";
25325
25384
  var codexHome = () => process.env.CODEX_HOME?.trim() || join7(homedir4(), ".codex");
25326
25385
  var BUNDLED_TIMEOUT_MS = 1e4;
25327
25386
  function configuredCatalogPath(config2, home = codexHome()) {
@@ -25430,7 +25489,7 @@ async function rebuild() {
25430
25489
  return;
25431
25490
  }
25432
25491
  const path = overlayPath();
25433
- await mkdir3(dirname4(path), { recursive: true, mode: 448 });
25492
+ await mkdir3(dirname5(path), { recursive: true, mode: 448 });
25434
25493
  const temporary = `${path}.${process.pid}.tmp`;
25435
25494
  await writeFile3(temporary, JSON.stringify(filled), { mode: 384 });
25436
25495
  await rename3(temporary, path);
@@ -26484,7 +26543,7 @@ import { spawn as spawn6 } from "node:child_process";
26484
26543
  import { createHash } from "node:crypto";
26485
26544
  import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
26486
26545
  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";
26546
+ import { dirname as dirname6, join as join11, resolve as resolve4 } from "node:path";
26488
26547
  import { fileURLToPath } from "node:url";
26489
26548
  var AcpRuntimeUnavailable = class extends Error {
26490
26549
  constructor(message) {
@@ -26494,7 +26553,7 @@ var AcpRuntimeUnavailable = class extends Error {
26494
26553
  };
26495
26554
  var NPM_INSTALL_TIMEOUT_MS = 10 * 6e4;
26496
26555
  function packageRoot() {
26497
- let directory = dirname5(fileURLToPath(import.meta.url));
26556
+ let directory = dirname6(fileURLToPath(import.meta.url));
26498
26557
  while (true) {
26499
26558
  const path = resolve4(directory, "package.json");
26500
26559
  if (existsSync4(path)) {
@@ -26503,7 +26562,7 @@ function packageRoot() {
26503
26562
  } catch {
26504
26563
  }
26505
26564
  }
26506
- const parent = dirname5(directory);
26565
+ const parent = dirname6(directory);
26507
26566
  if (parent === directory) return void 0;
26508
26567
  directory = parent;
26509
26568
  }
@@ -26531,7 +26590,7 @@ var installs = /* @__PURE__ */ new Map();
26531
26590
  function ensureClaudeRuntime(dataDir2) {
26532
26591
  const entry = vendoredAdapter("claude");
26533
26592
  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");
26593
+ const manifestPath = join11(dirname6(entry), "runtime.json");
26535
26594
  let manifest;
26536
26595
  try {
26537
26596
  manifest = JSON.parse(readFileSync4(manifestPath, "utf8"));
@@ -28007,7 +28066,7 @@ function isWriterConflict(message) {
28007
28066
  }
28008
28067
 
28009
28068
  // src/providers/cli/claude.ts
28010
- import { readdirSync as readdirSync2, readFileSync as readFileSync5 } from "node:fs";
28069
+ import { readdirSync as readdirSync3, readFileSync as readFileSync5 } from "node:fs";
28011
28070
  import { homedir as homedir8 } from "node:os";
28012
28071
  import { join as join14 } from "node:path";
28013
28072
  var CLAUDE = requireCliSpec("claude");
@@ -28024,13 +28083,13 @@ function claudeTranscriptPath(sessionId) {
28024
28083
  for (const root2 of claudeProjectRoots()) {
28025
28084
  let projects;
28026
28085
  try {
28027
- projects = readdirSync2(root2);
28086
+ projects = readdirSync3(root2);
28028
28087
  } catch {
28029
28088
  continue;
28030
28089
  }
28031
28090
  for (const project of projects) {
28032
28091
  try {
28033
- if (readdirSync2(join14(root2, project)).includes(file2)) return join14(root2, project, file2);
28092
+ if (readdirSync3(join14(root2, project)).includes(file2)) return join14(root2, project, file2);
28034
28093
  } catch {
28035
28094
  }
28036
28095
  }
@@ -29159,7 +29218,7 @@ function resolveDetectedProviderCommands(foundCommands, commands = DETECTION_COM
29159
29218
  function probeVersion(path, args) {
29160
29219
  if (args.length === 0) return Promise.resolve({});
29161
29220
  return new Promise((resolve10) => {
29162
- const launch = directLaunch2(path, args);
29221
+ const launch = directLaunch2(path, args, process.env.TOC_OCRA_NODE_PATH || process.execPath);
29163
29222
  const child = spawn9(launch.executable, launch.args, { stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
29164
29223
  let stdout = "";
29165
29224
  let stderr = "";
@@ -29208,13 +29267,15 @@ var CliDetectionService = class {
29208
29267
  const foundCommands = new Set(commands.filter((command) => resolved.get(command)?.found));
29209
29268
  const detected = resolveDetectedProviderCommands(foundCommands, DETECTION_COMMANDS);
29210
29269
  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;
29270
+ const override = process.env[config2.overrideEnv]?.trim();
29271
+ const unsupported = config2.detectUnsupportedRuntimes?.includes(process.platform) ?? false;
29272
+ const requiredPresent = (config2.detectRequiredCommands ?? []).every((command) => foundCommands.has(command));
29273
+ const matchedDetectionCommand = unsupported || !requiredPresent ? void 0 : override ? config2.detectCmd : detected.get(config2.id);
29274
+ const result = matchedDetectionCommand ? override ? resolveCliCommandDetailed(override) : resolved.get(matchedDetectionCommand) : void 0;
29213
29275
  const executablePath = result?.found ? result.path : void 0;
29214
29276
  const installed = Boolean(executablePath);
29215
- const unsupported = config2.detectUnsupportedRuntimes?.includes(process.platform) ?? false;
29216
29277
  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";
29278
+ 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
29279
  return {
29219
29280
  id: config2.id,
29220
29281
  installed,
@@ -32442,7 +32503,7 @@ async function runCliSmoke(options = {}) {
32442
32503
 
32443
32504
  // src/runtime/run-service.ts
32444
32505
  import { existsSync as existsSync6, readFileSync as readFileSync7 } from "node:fs";
32445
- import { dirname as dirname9, resolve as resolve8 } from "node:path";
32506
+ import { dirname as dirname10, resolve as resolve8 } from "node:path";
32446
32507
  import { fileURLToPath as fileURLToPath2 } from "node:url";
32447
32508
 
32448
32509
  // src/health/server.ts
@@ -32692,7 +32753,7 @@ import {
32692
32753
  unlinkSync,
32693
32754
  writeFileSync as writeFileSync2
32694
32755
  } from "node:fs";
32695
- import { dirname as dirname6 } from "node:path";
32756
+ import { dirname as dirname7 } from "node:path";
32696
32757
  var DEFAULT_MAX_BYTES = 5 * 1024 * 1024;
32697
32758
  var DEFAULT_MAX_ROTATED_FILES = 2;
32698
32759
  var PRIVATE_FILE_MODE = 384;
@@ -32716,7 +32777,7 @@ function createDiagnosticLogger(filePath, options = {}) {
32716
32777
  let disabled = false;
32717
32778
  let currentBytes = 0;
32718
32779
  try {
32719
- mkdirSync3(dirname6(filePath), { recursive: true });
32780
+ mkdirSync3(dirname7(filePath), { recursive: true });
32720
32781
  pruneExpired();
32721
32782
  currentBytes = existsSync5(filePath) ? statSync4(filePath).size : 0;
32722
32783
  } catch {
@@ -33091,7 +33152,7 @@ async function controlTbSwitch(payload) {
33091
33152
 
33092
33153
  // src/runs/orphan-registry.ts
33093
33154
  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";
33155
+ import { basename as basename3, dirname as dirname8 } from "node:path";
33095
33156
  var OrphanRegistry = class {
33096
33157
  constructor(file2) {
33097
33158
  this.file = file2;
@@ -33109,7 +33170,7 @@ var OrphanRegistry = class {
33109
33170
  persist() {
33110
33171
  const snapshot = JSON.stringify([...this.records.values()]);
33111
33172
  this.writing = this.writing.then(async () => {
33112
- await mkdir8(dirname7(this.file), { recursive: true, mode: 448 });
33173
+ await mkdir8(dirname8(this.file), { recursive: true, mode: 448 });
33113
33174
  const temporary = `${this.file}.${process.pid}.tmp`;
33114
33175
  await writeFile8(temporary, snapshot, { mode: 384 });
33115
33176
  await rename7(temporary, this.file);
@@ -33273,7 +33334,7 @@ var GatewayClient = class {
33273
33334
  // src/workspace/directory-browser.ts
33274
33335
  import { readdir as readdir3, realpath as realpath4, stat as stat7 } from "node:fs/promises";
33275
33336
  import { homedir as homedir11 } from "node:os";
33276
- import { dirname as dirname8, parse as parse3, resolve as resolve6 } from "node:path";
33337
+ import { dirname as dirname9, parse as parse3, resolve as resolve6 } from "node:path";
33277
33338
  var MAX_ENTRIES = 1e3;
33278
33339
  async function listDirectory(requested, allowedRoots) {
33279
33340
  const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir11()) || homedir11();
@@ -33293,7 +33354,7 @@ async function listDirectory(requested, allowedRoots) {
33293
33354
  if (entry.isDirectory()) directories.push(item);
33294
33355
  else if (entry.isFile()) files.push(item);
33295
33356
  }
33296
- const parent = dirname8(directory);
33357
+ const parent = dirname9(directory);
33297
33358
  const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir11() }];
33298
33359
  for (const root2 of allowedRoots) if (root2 !== homedir11()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root2 });
33299
33360
  places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
@@ -34456,7 +34517,9 @@ var AgentService = class {
34456
34517
  await this.stop();
34457
34518
  throw error62;
34458
34519
  }
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");
34520
+ } 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>
34521
+ \u5F53\u524D\u914D\u7F6E\uFF1A${this.config.configPath}
34522
+ `);
34460
34523
  }
34461
34524
  stop() {
34462
34525
  return this.stopPromise ??= (async () => {
@@ -34526,7 +34589,9 @@ var AgentService = class {
34526
34589
  id: provider.id,
34527
34590
  installed: provider.installed,
34528
34591
  runnable: provider.available,
34529
- version: provider.version ?? ""
34592
+ version: provider.version ?? "",
34593
+ path: provider.resolvedPath ?? "",
34594
+ detail: provider.detail ?? ""
34530
34595
  }))
34531
34596
  };
34532
34597
  }
@@ -34597,7 +34662,7 @@ function errorMessage3(error62) {
34597
34662
  // src/runtime/run-service.ts
34598
34663
  var PACKAGE_NAME = "toc-ocra";
34599
34664
  function agentPackageRoot() {
34600
- let directory = dirname9(fileURLToPath2(import.meta.url));
34665
+ let directory = dirname10(fileURLToPath2(import.meta.url));
34601
34666
  while (true) {
34602
34667
  const packagePath = resolve8(directory, "package.json");
34603
34668
  if (existsSync6(packagePath)) {
@@ -34607,7 +34672,7 @@ function agentPackageRoot() {
34607
34672
  } catch {
34608
34673
  }
34609
34674
  }
34610
- const parent = dirname9(directory);
34675
+ const parent = dirname10(directory);
34611
34676
  if (parent === directory) return void 0;
34612
34677
  directory = parent;
34613
34678
  }
@@ -34760,23 +34825,22 @@ async function enroll(args) {
34760
34825
  async function setup(args) {
34761
34826
  const server = option(args, "--server");
34762
34827
  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
34828
  const result = await pairDevice(args, server);
34765
34829
  process.stdout.write(`\u914D\u5BF9\u6210\u529F\uFF1A\u8BBE\u5907\u300C${result.deviceName}\u300D\uFF08${result.deviceId}\uFF09
34766
34830
  \u540E\u7AEF\uFF1A${result.serverUrl}
34767
34831
  \u6B63\u5728\u5B89\u88C5\u540E\u53F0\u670D\u52A1\u2026
34768
34832
  `);
34769
- if (!manageService("install", configPath ? ["--config", configPath] : [])) {
34833
+ if (!manageService("install", ["--config", result.configPath])) {
34770
34834
  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
34835
  return;
34772
34836
  }
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");
34837
+ 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
34838
  if (process.platform === "linux") {
34775
34839
  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
34840
  }
34777
34841
  }
34778
34842
  function manageService(action, args) {
34779
- const script = resolve9(dirname10(fileURLToPath3(import.meta.url)), "../../scripts/service.mjs");
34843
+ const script = resolve9(dirname11(fileURLToPath3(import.meta.url)), "../../scripts/service.mjs");
34780
34844
  if (!existsSync7(script)) throw new Error(`service manager is missing: ${script}`);
34781
34845
  const result = spawnSync(process.execPath, [script, action, ...args], { stdio: "inherit", shell: false });
34782
34846
  if (result.error) throw result.error;