toc-ocra 0.2.34 → 0.2.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/cli.mjs CHANGED
@@ -12,7 +12,7 @@ import { createHash as createHash4 } from "node:crypto";
12
12
  import { existsSync as existsSync6, mkdtempSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
13
13
  import { tmpdir as tmpdir3 } from "node:os";
14
14
  import { createRequire } from "node:module";
15
- import { dirname as dirname8, join as join12, resolve as resolve7 } from "node:path";
15
+ import { dirname as dirname8, join as join13, resolve as resolve7 } from "node:path";
16
16
  import { fileURLToPath as fileURLToPath2, pathToFileURL } from "node:url";
17
17
 
18
18
  // src/config.ts
@@ -20592,6 +20592,145 @@ var grokProvider = {
20592
20592
  // src/providers/cli/kiro.ts
20593
20593
  import { execFile } from "node:child_process";
20594
20594
  import { promisify } from "node:util";
20595
+
20596
+ // src/providers/cli/kiro-session-log.ts
20597
+ import { open as open2, readdir, readFile as readFile2, stat } from "node:fs/promises";
20598
+ import { homedir as homedir5 } from "node:os";
20599
+ import { join as join6 } from "node:path";
20600
+ var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "execute_bash", "bash"]);
20601
+ function kiroSessionsDirectory() {
20602
+ return process.env.TOC_OCRA_KIRO_SESSIONS_DIR || join6(homedir5(), ".kiro", "sessions", "cli");
20603
+ }
20604
+ var KiroSessionLog = class {
20605
+ constructor(options) {
20606
+ this.options = options;
20607
+ }
20608
+ options;
20609
+ path;
20610
+ offset = 0;
20611
+ partial = "";
20612
+ steps = [];
20613
+ results = /* @__PURE__ */ new Map();
20614
+ claimed = /* @__PURE__ */ new Set();
20615
+ get directory() {
20616
+ return this.options.directory ?? kiroSessionsDirectory();
20617
+ }
20618
+ /** Called before the CLI starts: a resumed log is followed from its current end. */
20619
+ async begin() {
20620
+ if (!this.options.sessionId) return;
20621
+ this.path = join6(this.directory, `${this.options.sessionId}.jsonl`);
20622
+ this.offset = await stat(this.path).then((info) => info.size, () => 0);
20623
+ }
20624
+ /**
20625
+ * A fresh turn's chat has no known id: the one log for this folder created
20626
+ * after the turn started. Several candidates (another turn starting a chat
20627
+ * in the same folder) leave it unknown.
20628
+ */
20629
+ async findFreshLog() {
20630
+ const names = await readdir(this.directory).catch(() => []);
20631
+ const found = [];
20632
+ for (const name of names) {
20633
+ if (!name.endsWith(".json")) continue;
20634
+ const meta3 = await readFile2(join6(this.directory, name), "utf8").then((text) => JSON.parse(text), () => void 0);
20635
+ const created = meta3?.created_at ? Date.parse(meta3.created_at) : NaN;
20636
+ if (meta3?.cwd && sameFolder(meta3.cwd, this.options.workdir) && created >= this.options.startedAt - 2e3) found.push(name.slice(0, -5));
20637
+ }
20638
+ if (found.length === 1) this.path = join6(this.directory, `${found[0]}.jsonl`);
20639
+ }
20640
+ /** Reads entries appended since the last call. */
20641
+ async refresh() {
20642
+ if (!this.path) await this.findFreshLog();
20643
+ if (!this.path) return;
20644
+ const file2 = await open2(this.path, "r").catch(() => void 0);
20645
+ if (!file2) return;
20646
+ try {
20647
+ const { size } = await file2.stat();
20648
+ if (size <= this.offset) return;
20649
+ const buffer = Buffer.alloc(size - this.offset);
20650
+ await file2.read(buffer, 0, buffer.length, this.offset);
20651
+ this.offset = size;
20652
+ const lines = (this.partial + buffer.toString("utf8")).split("\n");
20653
+ this.partial = lines.pop() ?? "";
20654
+ for (const line of lines) this.take(line);
20655
+ } finally {
20656
+ await file2.close();
20657
+ }
20658
+ }
20659
+ take(line) {
20660
+ let entry;
20661
+ try {
20662
+ entry = JSON.parse(line);
20663
+ } catch {
20664
+ return;
20665
+ }
20666
+ for (const part of entry.data?.content ?? []) {
20667
+ const data = part.data ?? {};
20668
+ if (part.kind === "toolUse" && SHELL_TOOLS.has(String(data.name))) {
20669
+ const command = data.input?.command;
20670
+ if (typeof data.toolUseId === "string" && typeof command === "string") this.steps.push({ id: data.toolUseId, command });
20671
+ } else if (part.kind === "toolResult" && typeof data.toolUseId === "string") {
20672
+ this.results.set(data.toolUseId, resultOf(data));
20673
+ }
20674
+ }
20675
+ }
20676
+ /** The shell step a `[tool] Running:` row announced (its text may be cut short). */
20677
+ async step(shown, waitMs = 2e3) {
20678
+ const prefix = shown.replace(/\.\.\.$|…$/, "").trim();
20679
+ const deadline = Date.now() + waitMs;
20680
+ for (; ; ) {
20681
+ await this.refresh();
20682
+ const step = this.steps.find((item) => !this.claimed.has(item.id) && item.command.trim().startsWith(prefix));
20683
+ if (step) {
20684
+ this.claimed.add(step.id);
20685
+ return step;
20686
+ }
20687
+ if (Date.now() >= deadline) return void 0;
20688
+ await new Promise((resolve8) => setTimeout(resolve8, 150));
20689
+ }
20690
+ }
20691
+ /** The first of `ids` whose result is in the log, waiting up to `waitMs`. */
20692
+ async firstFinished(ids, waitMs) {
20693
+ const deadline = Date.now() + waitMs;
20694
+ for (; ; ) {
20695
+ await this.refresh();
20696
+ const id = ids.find((item) => this.results.has(item));
20697
+ if (id || Date.now() >= deadline) return id;
20698
+ await new Promise((resolve8) => setTimeout(resolve8, 150));
20699
+ }
20700
+ }
20701
+ async result(id, waitMs = 3e3) {
20702
+ const deadline = Date.now() + waitMs;
20703
+ for (; ; ) {
20704
+ await this.refresh();
20705
+ const result = this.results.get(id);
20706
+ if (result || Date.now() >= deadline) return result;
20707
+ await new Promise((resolve8) => setTimeout(resolve8, 200));
20708
+ }
20709
+ }
20710
+ };
20711
+ function resultOf(data) {
20712
+ const parts = Array.isArray(data.content) ? data.content : [];
20713
+ const texts = [];
20714
+ let exitCode;
20715
+ for (const part of parts) {
20716
+ if (part.kind === "json" && part.data && typeof part.data === "object") {
20717
+ const value = part.data;
20718
+ const code2 = /(-?\d+)/.exec(String(value.exit_status ?? ""))?.[1];
20719
+ if (code2 !== void 0) exitCode = Number(code2);
20720
+ for (const text of [value.stdout, value.stderr]) if (typeof text === "string" && text.trim()) texts.push(text.replace(/\s+$/, ""));
20721
+ } else if (part.kind === "text" && typeof part.data === "string" && part.data.trim()) {
20722
+ texts.push(part.data.replace(/\s+$/, ""));
20723
+ }
20724
+ }
20725
+ if (exitCode === void 0 && data.status === "error") exitCode = 1;
20726
+ return { ...exitCode === void 0 ? {} : { exitCode }, output: texts.join("\n") };
20727
+ }
20728
+ function sameFolder(a, b) {
20729
+ const normal = (path) => path.replace(/\/+$/, "").replace(/^\/private(?=\/)/, "");
20730
+ return normal(a) === normal(b);
20731
+ }
20732
+
20733
+ // src/providers/cli/kiro.ts
20595
20734
  var execFileAsync = promisify(execFile);
20596
20735
  var ANSI = /\u001b(?:\][^\u0007]*?(?:\u0007|\u001b\\)|\[[0-?]*[ -/]*[@-~]|[@-Z\\-_])/g;
20597
20736
  function kiroLaunch(args) {
@@ -20615,7 +20754,7 @@ function describeListSessionsError(error62, timeoutMs) {
20615
20754
  return (failure2?.message || String(error62)).split("\n")[0].slice(0, 160);
20616
20755
  }
20617
20756
  async function listKiroSessions(workdir, options = {}) {
20618
- const timeoutMs = options.timeoutMs ?? KIRO_LIST_SESSIONS_TIMEOUT_MS;
20757
+ const timeoutMs = options.timeoutMs ?? (Number(process.env.TOC_OCRA_KIRO_LIST_TIMEOUT_MS) || KIRO_LIST_SESSIONS_TIMEOUT_MS);
20619
20758
  const { executable, args, env } = kiroLaunch(LIST_SESSIONS);
20620
20759
  let lastError;
20621
20760
  for (let attempt = 0; attempt < 2; attempt++) {
@@ -20649,10 +20788,32 @@ function kiroToolRows(text) {
20649
20788
  function isKiroNoise(text) {
20650
20789
  return /^\[(INFO|DEBUG|WARN|TRACE)\]/.test(text) || /^\[ERROR\] \(node:\d+\) ExperimentalWarning/.test(text) || /^\(Use `node --trace-warnings/.test(text);
20651
20790
  }
20652
- function kiroRunParser() {
20791
+ function kiroRunParser(context) {
20653
20792
  let pending = "";
20654
20793
  let started = false;
20655
20794
  let segment = [];
20795
+ const log = context ? new KiroSessionLog({ sessionId: context.sessionId, workdir: context.workdir, startedAt: context.startedAt }) : void 0;
20796
+ const ready = log?.begin().catch(() => void 0);
20797
+ let queue = Promise.resolve();
20798
+ const openSteps = [];
20799
+ let lastHeader;
20800
+ const out = (parsed) => {
20801
+ if (!context) return typeof parsed === "function" ? { display: [] } : parsed;
20802
+ queue = queue.then(async () => {
20803
+ const value = typeof parsed === "function" ? await parsed().catch(() => ({ display: [] })) : parsed;
20804
+ if (value.display.length && typeof parsed !== "function") lastHeader = void 0;
20805
+ context.emit(value);
20806
+ });
20807
+ return { display: [] };
20808
+ };
20809
+ const finishShell = async (step, status) => {
20810
+ const found = await step.shell.lookup;
20811
+ const result = found ? await log.result(found.id, 1e3) : void 0;
20812
+ const header = step.shell.headerShown && lastHeader === step ? [] : [runLog.command(found?.command ?? step.shell.shown)];
20813
+ lastHeader = void 0;
20814
+ if (!result) return { display: [...header, ...status === "failed" ? [runLog.error("\u4E0A\u4E00\u6B65\u6267\u884C\u5931\u8D25")] : []] };
20815
+ return { display: [...header, ...runLog.commandOutput(result.output), runLog.commandExit(result.exitCode ?? (status === "failed" ? 1 : 0))] };
20816
+ };
20656
20817
  const replyRows = (lines) => {
20657
20818
  const display = [];
20658
20819
  for (const raw of lines) {
@@ -20680,16 +20841,55 @@ function kiroRunParser() {
20680
20841
  stdout(chunk) {
20681
20842
  const lines = (pending + chunk).split(/\r?\n/);
20682
20843
  pending = lines.pop() ?? "";
20683
- return replyRows(lines);
20844
+ return out(replyRows(lines));
20684
20845
  },
20685
20846
  stderr(raw) {
20686
20847
  const text = raw.replace(ANSI, "").trim();
20687
20848
  if (!text || isKiroNoise(text)) return { display: [] };
20688
- const rows = kiroToolRows(text) ?? [runLog.error(text)];
20689
20849
  const closed = closeSegment();
20690
- return { ...closed, display: [...closed.display, ...rows] };
20850
+ const status = /^\[tool\]\s*status:\s*(\w+)/i.exec(text)?.[1]?.toLowerCase();
20851
+ if (!log) {
20852
+ const rows2 = kiroToolRows(text) ?? [runLog.error(text)];
20853
+ return out({ ...closed, display: [...closed.display, ...rows2] });
20854
+ }
20855
+ out(closed);
20856
+ const running = /^\[tool\]\s*Running:\s*(.+)$/.exec(text)?.[1]?.trim();
20857
+ if (running && !running.startsWith("@")) {
20858
+ const step = { shell: { shown: running, lookup: (async () => {
20859
+ await ready;
20860
+ return log.step(running);
20861
+ })(), headerShown: !openSteps.some((item) => item.shell) } };
20862
+ openSteps.push(step);
20863
+ if (!step.shell.headerShown) return { display: [] };
20864
+ return out(async () => {
20865
+ const found = await step.shell.lookup;
20866
+ lastHeader = step;
20867
+ return { display: [runLog.command(found?.command ?? running)] };
20868
+ });
20869
+ }
20870
+ if (status) {
20871
+ return out(async () => {
20872
+ const shells = openSteps.filter((item) => item.shell);
20873
+ const ids = (await Promise.all(shells.map((item) => item.shell.lookup))).map((found) => found?.id ?? "");
20874
+ const others = openSteps.some((item) => !item.shell);
20875
+ const id = shells.length ? await log.firstFinished(ids.filter(Boolean), others ? 1200 : 3e3) : void 0;
20876
+ const step = id ? shells[ids.indexOf(id)] : openSteps.find((item) => !item.shell) ?? openSteps[0];
20877
+ if (step) openSteps.splice(openSteps.indexOf(step), 1);
20878
+ if (step?.shell) return finishShell(step, status);
20879
+ lastHeader = void 0;
20880
+ return { display: status === "failed" ? [runLog.error("\u4E0A\u4E00\u6B65\u6267\u884C\u5931\u8D25")] : [] };
20881
+ });
20882
+ }
20883
+ if (/^\[tool\]/.test(text)) openSteps.push({});
20884
+ const rows = kiroToolRows(text) ?? [runLog.error(text)];
20885
+ return out({ display: rows });
20691
20886
  },
20692
- end: closeSegment
20887
+ end: async () => {
20888
+ const rest = out(closeSegment());
20889
+ if (!context) return rest;
20890
+ await queue;
20891
+ return { display: [] };
20892
+ }
20693
20893
  };
20694
20894
  }
20695
20895
  var kiroProvider = {
@@ -20715,7 +20915,7 @@ var kiroProvider = {
20715
20915
  return kiroRunParser().stdout(`${line}
20716
20916
  `);
20717
20917
  },
20718
- createRunParser: () => kiroRunParser()
20918
+ createRunParser: (context) => kiroRunParser(context)
20719
20919
  };
20720
20920
  function kiroStderrError(stderrLines) {
20721
20921
  const text = stderrLines.join("\n");
@@ -20895,7 +21095,7 @@ import { dirname as dirname7, resolve as resolve6 } from "node:path";
20895
21095
  import { fileURLToPath } from "node:url";
20896
21096
 
20897
21097
  // src/health/server.ts
20898
- import { readFile as readFile2 } from "node:fs/promises";
21098
+ import { readFile as readFile3 } from "node:fs/promises";
20899
21099
  import { createServer } from "node:http";
20900
21100
  var ControlError = class extends Error {
20901
21101
  constructor(status, message, code2 = "bad_request") {
@@ -21076,7 +21276,7 @@ var HealthServer = class {
21076
21276
  }
21077
21277
  async recentEvents() {
21078
21278
  try {
21079
- const raw = await readFile2(this.logFile, "utf8");
21279
+ const raw = await readFile3(this.logFile, "utf8");
21080
21280
  return raw.trim().split("\n").slice(-60).flatMap((line) => {
21081
21281
  try {
21082
21282
  const parsed = JSON.parse(line);
@@ -21253,7 +21453,7 @@ function createDiagnosticLogger(filePath, options = {}) {
21253
21453
 
21254
21454
  // src/runtime/agent-runtime.ts
21255
21455
  import { randomUUID as randomUUID3 } from "node:crypto";
21256
- import { join as join11 } from "node:path";
21456
+ import { join as join12 } from "node:path";
21257
21457
 
21258
21458
  // src/exec/script-runner.ts
21259
21459
  import { spawn as spawn3 } from "node:child_process";
@@ -21658,13 +21858,13 @@ function resolveChatProvider(type, request, attachments) {
21658
21858
 
21659
21859
  // src/providers/model-catalog-collector.ts
21660
21860
  import { createHash } from "node:crypto";
21661
- import { stat } from "node:fs/promises";
21861
+ import { stat as stat2 } from "node:fs/promises";
21662
21862
 
21663
21863
  // src/providers/model-catalog.ts
21664
21864
  import { spawn as spawn5 } from "node:child_process";
21665
- import { readFile as readFile3 } from "node:fs/promises";
21666
- import { homedir as homedir5 } from "node:os";
21667
- import { isAbsolute, join as join6, resolve as resolve2 } from "node:path";
21865
+ import { readFile as readFile4 } from "node:fs/promises";
21866
+ import { homedir as homedir6 } from "node:os";
21867
+ import { isAbsolute, join as join7, resolve as resolve2 } from "node:path";
21668
21868
 
21669
21869
  // src/providers/kiro-models.ts
21670
21870
  import { spawn as spawn4 } from "node:child_process";
@@ -21786,15 +21986,15 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
21786
21986
  if (defaultModel) catalog.default_model = defaultModel;
21787
21987
  return catalog;
21788
21988
  }
21789
- var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join6(homedir5(), ".claude");
21790
- var codexHome = () => process.env.CODEX_HOME?.trim() || join6(homedir5(), ".codex");
21791
- var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() || join6(homedir5(), ".gemini");
21792
- var grokHome = () => process.env.GROK_HOME?.trim() || join6(homedir5(), ".grok");
21793
- var opencodeHome = () => join6(process.env.XDG_CONFIG_HOME?.trim() || join6(homedir5(), ".config"), "opencode");
21794
- var kiroHome = () => join6(homedir5(), ".kiro");
21989
+ var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join7(homedir6(), ".claude");
21990
+ var codexHome = () => process.env.CODEX_HOME?.trim() || join7(homedir6(), ".codex");
21991
+ var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() || join7(homedir6(), ".gemini");
21992
+ var grokHome = () => process.env.GROK_HOME?.trim() || join7(homedir6(), ".grok");
21993
+ var opencodeHome = () => join7(process.env.XDG_CONFIG_HOME?.trim() || join7(homedir6(), ".config"), "opencode");
21994
+ var kiroHome = () => join7(homedir6(), ".kiro");
21795
21995
  async function readClaudeModelCatalog() {
21796
21996
  const home = claudeHome();
21797
- const content = await readFile3(join6(home, "settings.json"), "utf8").catch(() => "");
21997
+ const content = await readFile4(join7(home, "settings.json"), "utf8").catch(() => "");
21798
21998
  let settings = {};
21799
21999
  if (content) {
21800
22000
  try {
@@ -21850,16 +22050,16 @@ async function readCodexModels(codexHome2, config2) {
21850
22050
  const configuredCatalog = configValue(config2, "model_catalog_json");
21851
22051
  if (configuredCatalog) {
21852
22052
  const catalogPath = isAbsolute(configuredCatalog) ? configuredCatalog : resolve2(codexHome2, configuredCatalog);
21853
- const configuredModels = parseCodexModels(await readFile3(catalogPath, "utf8").catch(() => ""));
22053
+ const configuredModels = parseCodexModels(await readFile4(catalogPath, "utf8").catch(() => ""));
21854
22054
  if (configuredModels?.length) return configuredModels;
21855
22055
  }
21856
22056
  return parseCodexModels(
21857
- await readFile3(join6(codexHome2, "models_cache.json"), "utf8").catch(() => "")
22057
+ await readFile4(join7(codexHome2, "models_cache.json"), "utf8").catch(() => "")
21858
22058
  ) ?? [];
21859
22059
  }
21860
22060
  async function readCodexModelCatalog() {
21861
22061
  const home = codexHome();
21862
- const config2 = await readFile3(join6(home, "config.toml"), "utf8").catch(() => "");
22062
+ const config2 = await readFile4(join7(home, "config.toml"), "utf8").catch(() => "");
21863
22063
  const models = await readCodexModels(home, config2);
21864
22064
  const defaultModel = configValue(config2, "model");
21865
22065
  const defaultReasoningEffort = configValue(config2, "model_reasoning_effort");
@@ -21949,8 +22149,8 @@ async function readKiroModelCatalog() {
21949
22149
  };
21950
22150
  const launch = resolveExecutable("kiro-cli", ["acp", "--trust-tools="], environment, override);
21951
22151
  const [payload, content] = await Promise.all([
21952
- readKiroNativeModels(launch, homedir5(), { catalog: base }),
21953
- readFile3(join6(kiroHome(), "settings", "cli.json"), "utf8").catch(() => "{}")
22152
+ readKiroNativeModels(launch, homedir6(), { catalog: base }),
22153
+ readFile4(join7(kiroHome(), "settings", "cli.json"), "utf8").catch(() => "{}")
21954
22154
  ]);
21955
22155
  let settings;
21956
22156
  try {
@@ -22007,7 +22207,7 @@ function geminiModelsUrl(baseUrl) {
22007
22207
  }
22008
22208
  async function readGeminiModelCatalog() {
22009
22209
  const fileEnvironment = parseEnvFile(
22010
- await readFile3(join6(geminiHome(), ".env"), "utf8").catch(() => "")
22210
+ await readFile4(join7(geminiHome(), ".env"), "utf8").catch(() => "")
22011
22211
  );
22012
22212
  const environment = { ...fileEnvironment, ...process.env };
22013
22213
  const baseUrl = environment.GOOGLE_GEMINI_BASE_URL?.trim();
@@ -22052,7 +22252,7 @@ function parseGrokModelCatalog(output2, config2 = "", fetchedAt = (/* @__PURE__
22052
22252
  return catalog;
22053
22253
  }
22054
22254
  async function readGrokModelCatalog() {
22055
- const config2 = await readFile3(join6(grokHome(), "config.toml"), "utf8").catch(() => "");
22255
+ const config2 = await readFile4(join7(grokHome(), "config.toml"), "utf8").catch(() => "");
22056
22256
  const output2 = await runModelListCommand(resolveCliCommand("grok"), ["models"], "grok");
22057
22257
  const catalog = parseGrokModelCatalog(output2, config2);
22058
22258
  if (catalog.models.length === 0) throw new Error("Grok \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
@@ -22071,7 +22271,7 @@ function parseOpencodeModelCatalog(output2, config2 = "", fetchedAt = (/* @__PUR
22071
22271
  return catalog;
22072
22272
  }
22073
22273
  async function readOpencodeModelCatalog() {
22074
- const config2 = await readFile3(join6(opencodeHome(), "opencode.json"), "utf8").catch(() => "") || await readFile3(join6(opencodeHome(), "opencode.jsonc"), "utf8").catch(() => "");
22274
+ const config2 = await readFile4(join7(opencodeHome(), "opencode.json"), "utf8").catch(() => "") || await readFile4(join7(opencodeHome(), "opencode.jsonc"), "utf8").catch(() => "");
22075
22275
  const output2 = await runModelListCommand(resolveCliCommand("opencode"), ["models"], "opencode");
22076
22276
  const catalog = parseOpencodeModelCatalog(output2, config2);
22077
22277
  if (catalog.models.length === 0) throw new Error("OpenCode \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
@@ -22079,22 +22279,22 @@ async function readOpencodeModelCatalog() {
22079
22279
  }
22080
22280
  var TEN_MINUTES = 10 * 60 * 1e3;
22081
22281
  var MODEL_SOURCES = {
22082
- claude: { read: readClaudeModelCatalog, watchFiles: () => [join6(claudeHome(), "settings.json")] },
22282
+ claude: { read: readClaudeModelCatalog, watchFiles: () => [join7(claudeHome(), "settings.json")] },
22083
22283
  codex: {
22084
22284
  read: readCodexModelCatalog,
22085
22285
  watchFiles: () => {
22086
22286
  const home = codexHome();
22087
- return [join6(home, "config.toml"), join6(home, "models_cache.json")];
22287
+ return [join7(home, "config.toml"), join7(home, "models_cache.json")];
22088
22288
  },
22089
22289
  // model_catalog_json may point anywhere; a periodic re-read covers it.
22090
22290
  refreshEveryMs: TEN_MINUTES
22091
22291
  },
22092
- gemini: { read: readGeminiModelCatalog, watchFiles: () => [join6(geminiHome(), ".env")], refreshEveryMs: TEN_MINUTES },
22093
- grok: { read: readGrokModelCatalog, watchFiles: () => [join6(grokHome(), "config.toml")], refreshEveryMs: TEN_MINUTES },
22094
- kiro: { read: readKiroModelCatalog, watchFiles: () => [join6(kiroHome(), "settings", "cli.json")], refreshEveryMs: TEN_MINUTES },
22292
+ gemini: { read: readGeminiModelCatalog, watchFiles: () => [join7(geminiHome(), ".env")], refreshEveryMs: TEN_MINUTES },
22293
+ grok: { read: readGrokModelCatalog, watchFiles: () => [join7(grokHome(), "config.toml")], refreshEveryMs: TEN_MINUTES },
22294
+ kiro: { read: readKiroModelCatalog, watchFiles: () => [join7(kiroHome(), "settings", "cli.json")], refreshEveryMs: TEN_MINUTES },
22095
22295
  opencode: {
22096
22296
  read: readOpencodeModelCatalog,
22097
- watchFiles: () => [join6(opencodeHome(), "opencode.json"), join6(opencodeHome(), "opencode.jsonc")],
22297
+ watchFiles: () => [join7(opencodeHome(), "opencode.json"), join7(opencodeHome(), "opencode.jsonc")],
22098
22298
  refreshEveryMs: TEN_MINUTES
22099
22299
  }
22100
22300
  };
@@ -22102,7 +22302,7 @@ var MODEL_SOURCES = {
22102
22302
  // src/providers/model-catalog-collector.ts
22103
22303
  async function fileStamp(path) {
22104
22304
  try {
22105
- const info = await stat(path);
22305
+ const info = await stat2(path);
22106
22306
  return `${path}:${info.mtimeMs}:${info.size}`;
22107
22307
  } catch {
22108
22308
  return `${path}:-`;
@@ -22337,16 +22537,16 @@ async function readCLIQuotaReport(agentType) {
22337
22537
  }
22338
22538
 
22339
22539
  // src/providers/tb-switch-control.ts
22340
- import { readFile as readFile4 } from "node:fs/promises";
22341
- import { homedir as homedir6 } from "node:os";
22342
- import { join as join7 } from "node:path";
22540
+ import { readFile as readFile5 } from "node:fs/promises";
22541
+ import { homedir as homedir7 } from "node:os";
22542
+ import { join as join8 } from "node:path";
22343
22543
  function dataDir() {
22344
- return process.env.TB_SWITCH_HOME?.trim() || join7(homedir6(), ".tb-switch");
22544
+ return process.env.TB_SWITCH_HOME?.trim() || join8(homedir7(), ".tb-switch");
22345
22545
  }
22346
22546
  async function readLocalService() {
22347
22547
  let discovery;
22348
22548
  try {
22349
- discovery = JSON.parse(await readFile4(join7(dataDir(), "api.json"), "utf8"));
22549
+ discovery = JSON.parse(await readFile5(join8(dataDir(), "api.json"), "utf8"));
22350
22550
  } catch {
22351
22551
  throw new Error("\u8FD9\u53F0\u8BBE\u5907\u4E0A\u7684 TB Switch \u670D\u52A1\u672A\u8FD0\u884C\uFF0C\u8BF7\u6253\u5F00\u684C\u9762\u7AEF\u63D2\u4EF6\u540E\u91CD\u8BD5\u3002");
22352
22552
  }
@@ -22362,7 +22562,7 @@ async function readLocalService() {
22362
22562
  }
22363
22563
  let token = process.env.TB_SWITCH_API_TOKEN?.trim() ?? "";
22364
22564
  try {
22365
- token = (await readFile4(join7(dataDir(), "api-token"), "utf8")).trim();
22565
+ token = (await readFile5(join8(dataDir(), "api-token"), "utf8")).trim();
22366
22566
  } catch {
22367
22567
  }
22368
22568
  if (!token) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 TB Switch \u672C\u673A\u670D\u52A1\u51ED\u636E\uFF0C\u8BF7\u91CD\u542F\u684C\u9762\u7AEF\u63D2\u4EF6\u540E\u91CD\u8BD5\u3002");
@@ -22453,7 +22653,7 @@ async function controlTbSwitch(payload) {
22453
22653
 
22454
22654
  // src/runs/orphan-registry.ts
22455
22655
  import { execFile as execFile4 } from "node:child_process";
22456
- import { mkdir as mkdir3, readFile as readFile5, rename as rename3, writeFile as writeFile3 } from "node:fs/promises";
22656
+ import { mkdir as mkdir3, readFile as readFile6, rename as rename3, writeFile as writeFile3 } from "node:fs/promises";
22457
22657
  import { basename, dirname as dirname5 } from "node:path";
22458
22658
 
22459
22659
  // src/runs/process-tree.ts
@@ -22549,7 +22749,7 @@ var OrphanRegistry = class {
22549
22749
  async reapPrevious() {
22550
22750
  let previous = [];
22551
22751
  try {
22552
- previous = JSON.parse(await readFile5(this.file, "utf8"));
22752
+ previous = JSON.parse(await readFile6(this.file, "utf8"));
22553
22753
  } catch {
22554
22754
  return [];
22555
22755
  }
@@ -22579,8 +22779,8 @@ function commandOf(pid) {
22579
22779
 
22580
22780
  // src/runs/run-supervisor.ts
22581
22781
  import { spawn as spawn8 } from "node:child_process";
22582
- import { mkdir as mkdir5, realpath as realpath2, stat as stat2, writeFile as writeFile5 } from "node:fs/promises";
22583
- import { basename as basename3, isAbsolute as isAbsolute3, join as join9, relative as relative2, resolve as resolve3 } from "node:path";
22782
+ import { mkdir as mkdir5, realpath as realpath2, stat as stat3, writeFile as writeFile5 } from "node:fs/promises";
22783
+ import { basename as basename3, isAbsolute as isAbsolute3, join as join10, relative as relative2, resolve as resolve3 } from "node:path";
22584
22784
  import { createInterface as createInterface3 } from "node:readline";
22585
22785
 
22586
22786
  // src/session/terminal-line-sanitizer.ts
@@ -22706,8 +22906,8 @@ function clipToCharacterBudget(rows, budget) {
22706
22906
  // src/runs/task-attachments.ts
22707
22907
  import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
22708
22908
  import { constants as constants2 } from "node:fs";
22709
- import { lstat, mkdir as mkdir4, open as open2, realpath, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
22710
- import { basename as basename2, isAbsolute as isAbsolute2, join as join8, relative } from "node:path";
22909
+ import { lstat, mkdir as mkdir4, open as open3, realpath, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
22910
+ import { basename as basename2, isAbsolute as isAbsolute2, join as join9, relative } from "node:path";
22711
22911
  function within(root, path) {
22712
22912
  const segment = relative(root, path);
22713
22913
  return segment === "" || !segment.startsWith("..") && !isAbsolute2(segment);
@@ -22715,7 +22915,7 @@ function within(root, path) {
22715
22915
  async function attachmentDirectory(workdir, messageId) {
22716
22916
  let directory = workdir;
22717
22917
  for (const segment of [".echo", "attachments", `message-${encodeURIComponent(messageId).slice(0, 180)}`]) {
22718
- directory = join8(directory, segment);
22918
+ directory = join9(directory, segment);
22719
22919
  await mkdir4(directory, { mode: 448 }).catch((error62) => {
22720
22920
  if (error62.code !== "EEXIST") throw error62;
22721
22921
  });
@@ -22723,7 +22923,7 @@ async function attachmentDirectory(workdir, messageId) {
22723
22923
  if (metadata.isSymbolicLink() || !metadata.isDirectory() || !within(workdir, await realpath(directory))) {
22724
22924
  throw new Error("\u9644\u4EF6\u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E CLI \u5DE5\u4F5C\u76EE\u5F55\u5185\uFF0C\u4E14\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5");
22725
22925
  }
22726
- if (segment === ".echo") await writeFile4(join8(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
22926
+ if (segment === ".echo") await writeFile4(join9(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
22727
22927
  if (error62.code !== "EEXIST") throw error62;
22728
22928
  });
22729
22929
  }
@@ -22732,7 +22932,7 @@ async function attachmentDirectory(workdir, messageId) {
22732
22932
  async function matches(path, size, sha256, signal2) {
22733
22933
  const metadata = await lstat(path).catch(() => void 0);
22734
22934
  if (!metadata?.isFile() || metadata.isSymbolicLink() || metadata.size !== size) return false;
22735
- const file2 = await open2(path, constants2.O_RDONLY | (constants2.O_NOFOLLOW ?? 0));
22935
+ const file2 = await open3(path, constants2.O_RDONLY | (constants2.O_NOFOLLOW ?? 0));
22736
22936
  try {
22737
22937
  const hash2 = createHash2("sha256");
22738
22938
  let read = 0;
@@ -22760,9 +22960,9 @@ async function prepareTaskAttachments(payload, workdir, download, signal2) {
22760
22960
  const characters = Array.from(basename2(file2.name.replace(/\\/g, "/")).replace(/[^\p{L}\p{N}._-]/gu, "_").replace(/\.+$/u, ""));
22761
22961
  while (Buffer.byteLength(characters.join("")) > 160) characters.shift();
22762
22962
  const name = characters.join("") || "attachment";
22763
- const path = join8(directory, `${file2.file_id}-${name}`);
22963
+ const path = join9(directory, `${file2.file_id}-${name}`);
22764
22964
  if (!await matches(path, file2.size, file2.sha256, signal2)) {
22765
- const temporary = join8(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
22965
+ const temporary = join9(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
22766
22966
  try {
22767
22967
  await download(payload.run_id, file2.file_id, temporary, file2.size, file2.sha256, signal2);
22768
22968
  signal2.throwIfAborted();
@@ -23003,7 +23203,6 @@ var RunSupervisor = class {
23003
23203
  agentType: provider.id,
23004
23204
  provider,
23005
23205
  parse: provider.createLineParser?.() ?? ((line) => provider.parseLine(line)),
23006
- ...provider.createRunParser ? { stream: provider.createRunParser() } : {},
23007
23206
  ...sessionsBefore ? { sessionsBefore } : {},
23008
23207
  ...unverifiedResume ? { unverifiedResume: payload } : {},
23009
23208
  prompt: payload.prompt,
@@ -23026,6 +23225,16 @@ var RunSupervisor = class {
23026
23225
  lastLine: "",
23027
23226
  lastOutputAt: Date.now()
23028
23227
  };
23228
+ if (provider.createRunParser) {
23229
+ run2.stream = provider.createRunParser({
23230
+ workdir,
23231
+ sessionId,
23232
+ startedAt: run2.startedAt,
23233
+ emit: (parsed) => {
23234
+ if (this.active.has(run2.runId)) this.applyParsed(run2, parsed, "");
23235
+ }
23236
+ });
23237
+ }
23029
23238
  this.active.set(run2.runId, run2);
23030
23239
  this.preparing.delete(run2.runId);
23031
23240
  this.unreported.add(run2.runId);
@@ -23141,7 +23350,7 @@ var RunSupervisor = class {
23141
23350
  }
23142
23351
  async onExit(run2, code2, signal2, spawnError) {
23143
23352
  for (const timer of run2.timers) clearTimeout(timer);
23144
- if (run2.stream) this.applyParsed(run2, run2.stream.end(), "");
23353
+ if (run2.stream) this.applyParsed(run2, await run2.stream.end(), "");
23145
23354
  this.active.delete(run2.runId);
23146
23355
  this.orphans?.remove(run2.runId);
23147
23356
  if (run2.eventTimer) clearTimeout(run2.eventTimer);
@@ -23277,13 +23486,13 @@ var RunSupervisor = class {
23277
23486
  async prepareChatAttachments(payload) {
23278
23487
  if (!payload.attachments?.length) return [];
23279
23488
  if (!this.reporter.chatMedia) throw new Error("\u9644\u4EF6\u8F6C\u53D1\u672A\u914D\u7F6E");
23280
- const directory = join9(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
23489
+ const directory = join10(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
23281
23490
  await mkdir5(directory, { recursive: true, mode: 448 });
23282
23491
  const files = [];
23283
23492
  for (const attachment of payload.attachments) {
23284
23493
  const name = basename3(attachment.name).replace(/[^\p{L}\p{N}._-]/gu, "_").slice(-120) || "attachment";
23285
- const path = join9(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
23286
- const existing = await stat2(path).catch(() => void 0);
23494
+ const path = join10(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
23495
+ const existing = await stat3(path).catch(() => void 0);
23287
23496
  if (!existing?.isFile()) {
23288
23497
  const data = await this.reporter.chatMedia(payload.run_id, attachment.media_id);
23289
23498
  await writeFile5(path, data, { mode: 384 });
@@ -23321,10 +23530,15 @@ var RunSupervisor = class {
23321
23530
  if (live) return live;
23322
23531
  return [...this.recent.values()].filter((run2) => run2.workstationId === id).sort((a, b) => b.finishedAt - a.finishedAt)[0];
23323
23532
  };
23324
- const target = byId(query.runId) ?? byWorkstation(query.workstationId);
23325
- if (!target) {
23326
- return { status: "idle", lines: [], startCursor: 0, nextCursor: 0, oldestCursor: 0, latestCursor: 0, hasMore: false, truncated: false, limited: false, idleMs: void 0 };
23327
- }
23533
+ const empty = { lines: [], startCursor: 0, nextCursor: 0, oldestCursor: 0, latestCursor: 0, hasMore: false, truncated: false, limited: false, idleMs: void 0 };
23534
+ if (query.runId) {
23535
+ const run2 = byId(query.runId);
23536
+ if (!run2) return { ...empty, status: this.preparing.has(query.runId) ? "running" : "idle", run_id: query.runId };
23537
+ const read2 = run2.tail.read(beforeCursor === void 0 ? { limit } : { limit, beforeCursor });
23538
+ return { ...read2, status: this.active.has(run2.runId) ? "running" : "finished", run_id: run2.runId };
23539
+ }
23540
+ const target = byWorkstation(query.workstationId);
23541
+ if (!target) return { ...empty, status: "idle" };
23328
23542
  const read = target.tail.read(beforeCursor === void 0 ? { limit } : { limit, beforeCursor });
23329
23543
  return { ...read, status: this.active.has(target.runId) ? "running" : "finished", run_id: target.runId };
23330
23544
  }
@@ -23514,17 +23728,17 @@ var GatewayClient = class {
23514
23728
  };
23515
23729
 
23516
23730
  // src/workspace/directory-browser.ts
23517
- import { readdir, realpath as realpath3, stat as stat3 } from "node:fs/promises";
23518
- import { homedir as homedir7 } from "node:os";
23731
+ import { readdir as readdir2, realpath as realpath3, stat as stat4 } from "node:fs/promises";
23732
+ import { homedir as homedir8 } from "node:os";
23519
23733
  import { dirname as dirname6, parse as parse3, resolve as resolve4 } from "node:path";
23520
23734
  var MAX_ENTRIES = 1e3;
23521
23735
  async function listDirectory(requested, allowedRoots) {
23522
- const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir7()) || homedir7();
23736
+ const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir8()) || homedir8();
23523
23737
  const directory = await realpath3(resolve4(raw)).catch(() => {
23524
23738
  throw new Error(`\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${requested}`);
23525
23739
  });
23526
- if (!(await stat3(directory)).isDirectory()) throw new Error("\u8FD9\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
23527
- const entries = await readdir(directory, { withFileTypes: true }).catch((error62) => {
23740
+ if (!(await stat4(directory)).isDirectory()) throw new Error("\u8FD9\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
23741
+ const entries = await readdir2(directory, { withFileTypes: true }).catch((error62) => {
23528
23742
  throw new Error(error62.code === "EACCES" || error62.code === "EPERM" ? "\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u8FD9\u4E2A\u76EE\u5F55" : error62.message);
23529
23743
  });
23530
23744
  const byName = (a, b) => a.name.localeCompare(b.name, void 0, { sensitivity: "base", numeric: true });
@@ -23537,8 +23751,8 @@ async function listDirectory(requested, allowedRoots) {
23537
23751
  else if (entry.isFile()) files.push(item);
23538
23752
  }
23539
23753
  const parent = dirname6(directory);
23540
- const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir7() }];
23541
- for (const root of allowedRoots) if (root !== homedir7()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root });
23754
+ const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir8() }];
23755
+ for (const root of allowedRoots) if (root !== homedir8()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root });
23542
23756
  places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
23543
23757
  return {
23544
23758
  path: directory,
@@ -23552,9 +23766,9 @@ async function listDirectory(requested, allowedRoots) {
23552
23766
 
23553
23767
  // src/workspace/workspace-manager.ts
23554
23768
  import { spawn as spawn9 } from "node:child_process";
23555
- import { chmod as chmod3, mkdir as mkdir6, mkdtemp, opendir, realpath as realpath4, rm as rm3, stat as stat4, writeFile as writeFile6 } from "node:fs/promises";
23556
- import { homedir as homedir8, tmpdir as tmpdir2 } from "node:os";
23557
- import { isAbsolute as isAbsolute4, join as join10, relative as relative3, resolve as resolve5 } from "node:path";
23769
+ import { chmod as chmod3, mkdir as mkdir6, mkdtemp, opendir, realpath as realpath4, rm as rm3, stat as stat5, writeFile as writeFile6 } from "node:fs/promises";
23770
+ import { homedir as homedir9, tmpdir as tmpdir2 } from "node:os";
23771
+ import { isAbsolute as isAbsolute4, join as join11, relative as relative3, resolve as resolve5 } from "node:path";
23558
23772
  var MAX_NODES = 2e3;
23559
23773
  var MAX_DIRECTORY_ENTRIES = 12e3;
23560
23774
  var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
@@ -23602,7 +23816,7 @@ var WorkspaceManager = class {
23602
23816
  };
23603
23817
  }
23604
23818
  validateRootPath(value) {
23605
- const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir8());
23819
+ const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir9());
23606
23820
  const root = resolve5(raw);
23607
23821
  if (!isAbsolute4(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
23608
23822
  if (relative3(root, resolve5(root, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
@@ -23619,7 +23833,7 @@ var WorkspaceManager = class {
23619
23833
  requestedPaths.add(relativePath);
23620
23834
  const target = this.resolveWithinRoot(rootPath, relativePath);
23621
23835
  try {
23622
- const metadata = await stat4(target).catch(() => void 0);
23836
+ const metadata = await stat5(target).catch(() => void 0);
23623
23837
  if (metadata) {
23624
23838
  if (!metadata.isDirectory()) {
23625
23839
  throw new Error("The existing workspace path is not a directory");
@@ -23677,7 +23891,7 @@ var WorkspaceManager = class {
23677
23891
  let created = false;
23678
23892
  let metadata;
23679
23893
  try {
23680
- metadata = await stat4(target);
23894
+ metadata = await stat5(target);
23681
23895
  } catch {
23682
23896
  }
23683
23897
  if (!metadata) {
@@ -23777,7 +23991,7 @@ var WorkspaceManager = class {
23777
23991
  }
23778
23992
  async scanTree(rootPath, maxDepth, scanRoots) {
23779
23993
  const resolvedRoot = await realpath4(rootPath);
23780
- const rootMetadata = await stat4(resolvedRoot);
23994
+ const rootMetadata = await stat5(resolvedRoot);
23781
23995
  if (!rootMetadata.isDirectory()) throw new Error("The workspace root is not a directory");
23782
23996
  const nodes = [];
23783
23997
  let entriesRead = 0;
@@ -23832,7 +24046,7 @@ var WorkspaceManager = class {
23832
24046
  const target = this.resolveWithinRoot(resolvedRoot, relativePath);
23833
24047
  let metadata;
23834
24048
  try {
23835
- metadata = await stat4(target);
24049
+ metadata = await stat5(target);
23836
24050
  } catch (error62) {
23837
24051
  this.logger.warn("workspace-scan-root-missing", {
23838
24052
  rootPath: target,
@@ -23929,12 +24143,12 @@ var WorkspaceManager = class {
23929
24143
  }
23930
24144
  async createGitAuthEnvironment(auth) {
23931
24145
  if (!auth) return void 0;
23932
- const directory = await mkdtemp(join10(tmpdir2(), "toc-ocra-git-auth-"));
24146
+ const directory = await mkdtemp(join11(tmpdir2(), "toc-ocra-git-auth-"));
23933
24147
  const isWindows = process.platform === "win32";
23934
- const scriptPath = join10(directory, isWindows ? "askpass.cmd" : "askpass.sh");
24148
+ const scriptPath = join11(directory, isWindows ? "askpass.cmd" : "askpass.sh");
23935
24149
  let script;
23936
24150
  if (isWindows) {
23937
- const helperPath = join10(directory, "askpass.cjs");
24151
+ const helperPath = join11(directory, "askpass.cjs");
23938
24152
  await writeFile6(
23939
24153
  helperPath,
23940
24154
  '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',
@@ -24084,7 +24298,7 @@ var AgentRuntime = class {
24084
24298
  }
24085
24299
  };
24086
24300
  this.workspaces = new WorkspaceManager(config2, this.logger);
24087
- this.orphans = new OrphanRegistry(join11(config2.dataDir, "active-runs.json"));
24301
+ this.orphans = new OrphanRegistry(join12(config2.dataDir, "active-runs.json"));
24088
24302
  this.runs = new RunSupervisor(config2, this.logger, reporter, this.orphans);
24089
24303
  }
24090
24304
  config;
@@ -24792,7 +25006,7 @@ async function runService(options = {}) {
24792
25006
  }
24793
25007
 
24794
25008
  // src/index.ts
24795
- var { currentInstallation, installShared, ensureIdle, compareVersions } = createRequire(import.meta.url)(join12(agentPackageRoot(), "scripts", "installation.cjs"));
25009
+ var { currentInstallation, installShared, ensureIdle, compareVersions } = createRequire(import.meta.url)(join13(agentPackageRoot(), "scripts", "installation.cjs"));
24796
25010
  async function run() {
24797
25011
  try {
24798
25012
  await runService();
@@ -24895,7 +25109,7 @@ async function update(args) {
24895
25109
  if (customConfig) process.env.TOC_OCRA_CONFIG = resolve7(customConfig);
24896
25110
  await ensureIdle();
24897
25111
  const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
24898
- const temporary = mkdtempSync(join12(tmpdir3(), "toc-ocra-update-"));
25112
+ const temporary = mkdtempSync(join13(tmpdir3(), "toc-ocra-update-"));
24899
25113
  try {
24900
25114
  const metadataResponse = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`, { headers: { accept: "application/json", "cache-control": "no-cache" }, signal: AbortSignal.timeout(15e3) });
24901
25115
  if (!metadataResponse.ok) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 npm \u6700\u65B0\u7248\u672C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
@@ -24922,7 +25136,7 @@ async function update(args) {
24922
25136
  }
24923
25137
  const archive = Buffer.concat(chunks);
24924
25138
  if (`sha512-${createHash4("sha512").update(archive).digest("base64")}` !== dist.integrity) throw new Error("\u8BBE\u5907\u4EE3\u7406\u5B89\u88C5\u5305\u6821\u9A8C\u5931\u8D25\uFF0C\u5DF2\u505C\u6B62\u5347\u7EA7");
24925
- const archivePath = join12(temporary, "toc-ocra.tgz");
25139
+ const archivePath = join13(temporary, "toc-ocra.tgz");
24926
25140
  writeFileSync3(archivePath, archive, { mode: 384 });
24927
25141
  const install = spawnSync(npmCommand, ["install", "--prefix", temporary, "--ignore-scripts", "--omit=dev", "--no-package-lock", "--no-audit", "--no-fund", "--prefer-online", "--registry=https://registry.npmjs.org", archivePath], { stdio: "inherit", shell: false });
24928
25142
  if (install.error) throw install.error;
@@ -24931,7 +25145,7 @@ async function update(args) {
24931
25145
  return;
24932
25146
  }
24933
25147
  const previousVersion = agentVersion();
24934
- const current = await installShared(join12(temporary, "node_modules", PACKAGE_NAME), { startService: existsSync6(defaultConfigPath()) });
25148
+ const current = await installShared(join13(temporary, "node_modules", PACKAGE_NAME), { startService: existsSync6(defaultConfigPath()) });
24935
25149
  if (current.version === previousVersion) process.stdout.write(`toc-ocra \u5DF2\u662F\u6700\u65B0\u7248\u672C ${current.version}
24936
25150
  `);
24937
25151
  else process.stdout.write(`toc-ocra \u5DF2\u5347\u7EA7\u5230 ${current.version}\uFF0C\u7EC8\u7AEF\u4E0E Echo \u63D2\u4EF6\u5171\u7528\u6B64\u7248\u672C
@@ -24957,7 +25171,7 @@ async function main() {
24957
25171
  const shared = currentInstallation();
24958
25172
  if (root && root.split(/[\\/]/).includes("node_modules") && root !== shared?.root) {
24959
25173
  const selected = !shared || compareVersions(agentVersion(), shared.version) > 0 ? await installShared(root) : shared;
24960
- await import(pathToFileURL(join12(selected.root, "dist", "cli", "cli.mjs")).href);
25174
+ await import(pathToFileURL(join13(selected.root, "dist", "cli", "cli.mjs")).href);
24961
25175
  return;
24962
25176
  }
24963
25177
  const command = process.argv[2] ?? "run";