toc-ocra 0.4.0 → 0.5.1

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
@@ -3791,7 +3791,7 @@ import { createHash as createHash6 } from "node:crypto";
3791
3791
  import { existsSync as existsSync8, mkdtempSync, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "node:fs";
3792
3792
  import { tmpdir as tmpdir4 } from "node:os";
3793
3793
  import { createRequire } from "node:module";
3794
- import { dirname as dirname11, join as join27, resolve as resolve9 } from "node:path";
3794
+ import { dirname as dirname11, join as join28, resolve as resolve9 } from "node:path";
3795
3795
  import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL2 } from "node:url";
3796
3796
 
3797
3797
  // src/config.ts
@@ -24226,11 +24226,40 @@ function resolveWindowsCommandShim(shimPath) {
24226
24226
  }
24227
24227
  return void 0;
24228
24228
  }
24229
+ var TASKKILL_TIMEOUT_MS = 5e3;
24230
+ function processAlive(pid) {
24231
+ try {
24232
+ process.kill(pid, 0);
24233
+ return true;
24234
+ } catch (error62) {
24235
+ return error62.code === "EPERM";
24236
+ }
24237
+ }
24229
24238
  function taskkillTree(rootPid) {
24230
24239
  return new Promise((resolve10) => {
24240
+ let settled = false;
24241
+ const finish = () => {
24242
+ if (settled) return;
24243
+ settled = true;
24244
+ clearTimeout(timer);
24245
+ if (processAlive(rootPid)) {
24246
+ try {
24247
+ process.kill(rootPid, "SIGKILL");
24248
+ } catch {
24249
+ }
24250
+ }
24251
+ resolve10();
24252
+ };
24231
24253
  const child = spawn2(join5(SYSTEM_ROOT, "System32", "taskkill.exe"), ["/PID", String(rootPid), "/T", "/F"], { stdio: "ignore", windowsHide: true });
24232
- child.once("error", () => resolve10());
24233
- child.once("close", () => resolve10());
24254
+ const timer = setTimeout(() => {
24255
+ try {
24256
+ child.kill();
24257
+ } catch {
24258
+ }
24259
+ finish();
24260
+ }, TASKKILL_TIMEOUT_MS);
24261
+ child.once("error", finish);
24262
+ child.once("close", finish);
24234
24263
  });
24235
24264
  }
24236
24265
  function runPowerShell(script) {
@@ -25253,14 +25282,14 @@ function parseCodexModels(content) {
25253
25282
  return void 0;
25254
25283
  }
25255
25284
  }
25256
- async function readCodexModels(codexHome3, config2) {
25285
+ async function readCodexModels(codexHome4, config2) {
25257
25286
  const configuredCatalog = configValue(config2, "model_catalog_json");
25258
25287
  if (configuredCatalog) {
25259
- const catalogPath = isAbsolute2(configuredCatalog) ? configuredCatalog : resolve3(codexHome3, configuredCatalog);
25288
+ const catalogPath = isAbsolute2(configuredCatalog) ? configuredCatalog : resolve3(codexHome4, configuredCatalog);
25260
25289
  const configuredModels = parseCodexModels(await readFile3(catalogPath, "utf8").catch(() => ""));
25261
25290
  if (configuredModels?.length) return configuredModels;
25262
25291
  }
25263
- const cached3 = parseCodexModels(await readFile3(join11(codexHome3, "models_cache.json"), "utf8").catch(() => ""));
25292
+ const cached3 = parseCodexModels(await readFile3(join11(codexHome4, "models_cache.json"), "utf8").catch(() => ""));
25264
25293
  if (cached3?.length) return cached3;
25265
25294
  return codexModelsFrom(await codexBundledCatalog().catch(() => void 0), { listedOnly: true }) ?? [];
25266
25295
  }
@@ -33045,7 +33074,7 @@ function createDiagnosticLogger(filePath, options = {}) {
33045
33074
  }
33046
33075
 
33047
33076
  // src/runtime/hub-runtime.ts
33048
- import { join as join26 } from "node:path";
33077
+ import { join as join27 } from "node:path";
33049
33078
 
33050
33079
  // node_modules/ws/wrapper.mjs
33051
33080
  var import_stream = __toESM(require_stream(), 1);
@@ -33980,7 +34009,7 @@ var HubLink = class {
33980
34009
  return;
33981
34010
  default:
33982
34011
  if (frame.type.startsWith("terminal.")) {
33983
- this.reply(frame.type, frame.id, { ok: false, error: rpcError(ERROR_TAGS.terminalUnsupported, "ocra \u8BBE\u5907\u5305\u6682\u4E0D\u652F\u6301 Web \u7EC8\u7AEF\uFF0C\u8BF7\u5728\u8BBE\u5907\u672C\u673A\u6253\u5F00\u7EC8\u7AEF", `frame=${frame.type}`) });
34012
+ this.reply(frame.type, frame.id, { ok: false, error: rpcError(ERROR_TAGS.terminalUnsupported, "ocra \u8BBE\u5907\u5305\u6682\u4E0D\u652F\u6301 Web \u7EC8\u7AEF\u548C\u8BBE\u5907\u547D\u4EE4\u6267\u884C\uFF08exec\uFF09\uFF0C\u8BF7\u5728\u8BBE\u5907\u672C\u673A\u7684\u7EC8\u7AEF\u91CC\u64CD\u4F5C", `frame=${frame.type}`) });
33984
34013
  }
33985
34014
  }
33986
34015
  }
@@ -33991,9 +34020,9 @@ function errorMessage3(error62) {
33991
34020
 
33992
34021
  // src/t3/t3-backend.ts
33993
34022
  import { randomUUID as randomUUID5 } from "node:crypto";
33994
- import { mkdir as mkdir9, stat as stat8, writeFile as writeFile11 } from "node:fs/promises";
33995
- import { homedir as homedir14 } from "node:os";
33996
- import { basename as basename4, join as join25, resolve as resolve7 } from "node:path";
34023
+ import { mkdir as mkdir9, stat as stat9, writeFile as writeFile11 } from "node:fs/promises";
34024
+ import { homedir as homedir15 } from "node:os";
34025
+ import { basename as basename4, join as join26, resolve as resolve7 } from "node:path";
33997
34026
 
33998
34027
  // src/runs/orphan-registry.ts
33999
34028
  import { mkdir as mkdir8, readFile as readFile9, rename as rename8, writeFile as writeFile9 } from "node:fs/promises";
@@ -34228,6 +34257,144 @@ var ModelCatalogCollector = class {
34228
34257
  }
34229
34258
  };
34230
34259
 
34260
+ // src/t3/skills.ts
34261
+ import { readdir as readdir5, readFile as readFile10, stat as stat8 } from "node:fs/promises";
34262
+ import { homedir as homedir14 } from "node:os";
34263
+ import { join as join24 } from "node:path";
34264
+ var MAX_SKILLS_PER_CLI = 500;
34265
+ var MAX_SKILL_FILE_BYTES = 256 * 1024;
34266
+ var MAX_TEXT = 1e3;
34267
+ var claudeHome3 = () => process.env.CLAUDE_CONFIG_DIR?.trim().split(process.platform === "win32" ? ";" : ":")[0]?.trim() || join24(homedir14(), ".claude");
34268
+ var codexHome3 = () => process.env.CODEX_HOME?.trim() || join24(homedir14(), ".codex");
34269
+ function skillRoots(cli, home = homedir14()) {
34270
+ const agents = { directory: join24(home, ".agents", "skills"), source: "user", depth: 2 };
34271
+ switch (cli) {
34272
+ case "claude":
34273
+ return [
34274
+ { directory: join24(claudeHome3(), "skills"), source: "user", depth: 2 },
34275
+ // Installed plugins keep their skills under <plugin>/skills/<name>/SKILL.md, several levels down.
34276
+ { directory: join24(claudeHome3(), "plugins"), source: "plugin", depth: 7 }
34277
+ ];
34278
+ case "codex":
34279
+ return [
34280
+ // Bundled skills live in skills/.system/<name>.
34281
+ { directory: join24(codexHome3(), "skills"), source: "user", depth: 3 },
34282
+ { directory: join24(codexHome3(), "plugins"), source: "plugin", depth: 7 },
34283
+ agents
34284
+ ];
34285
+ case "antigravity":
34286
+ return [
34287
+ { directory: join24(home, ".gemini", "antigravity", "skills"), source: "user", depth: 2 },
34288
+ { directory: join24(home, ".gemini", "antigravity-cli", "skills"), source: "user", depth: 2 },
34289
+ agents
34290
+ ];
34291
+ }
34292
+ }
34293
+ var unquote = (value) => {
34294
+ const trimmed = value.trim();
34295
+ if (trimmed.length >= 2 && (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'"))) {
34296
+ const inner = trimmed.slice(1, -1);
34297
+ return trimmed.startsWith('"') ? inner.replace(/\\"/g, '"').replace(/\\n/g, "\n").replace(/\\\\/g, "\\") : inner.replace(/''/g, "'");
34298
+ }
34299
+ return trimmed;
34300
+ };
34301
+ function yamlScalars(source) {
34302
+ const out = {};
34303
+ const lines = source.split(/\r?\n/);
34304
+ const parents = [];
34305
+ for (let index = 0; index < lines.length; index++) {
34306
+ const line = lines[index];
34307
+ if (!line.trim() || line.trimStart().startsWith("#") || line.trimStart().startsWith("- ")) continue;
34308
+ const match = /^(\s*)([A-Za-z0-9_.-]+)\s*:\s*(.*)$/.exec(line);
34309
+ if (!match) continue;
34310
+ const indent = match[1].length;
34311
+ while (parents.length && parents[parents.length - 1].indent >= indent) parents.pop();
34312
+ const path = [...parents.map((parent) => parent.key), match[2]].join(".");
34313
+ let value = match[3].replace(/\s+#.*$/, "");
34314
+ if (value === "") {
34315
+ parents.push({ indent, key: match[2] });
34316
+ continue;
34317
+ }
34318
+ if (/^[|>][+-]?$/.test(value)) {
34319
+ const folded = value.startsWith(">");
34320
+ const block = [];
34321
+ while (index + 1 < lines.length && (!lines[index + 1].trim() || lines[index + 1].length - lines[index + 1].trimStart().length > indent)) {
34322
+ block.push(lines[++index].trim());
34323
+ }
34324
+ value = block.join(folded ? " " : "\n").trim();
34325
+ } else value = unquote(value);
34326
+ out[path] = value;
34327
+ }
34328
+ return out;
34329
+ }
34330
+ function skillFrontMatter(markdown) {
34331
+ const match = /^?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(markdown);
34332
+ return match ? yamlScalars(match[1]) : {};
34333
+ }
34334
+ var clip3 = (value) => {
34335
+ const flat = value?.replace(/\s+/g, " ").trim();
34336
+ return flat ? flat.length > MAX_TEXT ? `${flat.slice(0, MAX_TEXT)}\u2026` : flat : void 0;
34337
+ };
34338
+ async function readSmall(path) {
34339
+ try {
34340
+ const info = await stat8(path);
34341
+ if (!info.isFile() || info.size > MAX_SKILL_FILE_BYTES) return void 0;
34342
+ return await readFile10(path, "utf8");
34343
+ } catch {
34344
+ return void 0;
34345
+ }
34346
+ }
34347
+ async function readSkill(directory, folder, source) {
34348
+ const markdown = await readSmall(join24(directory, "SKILL.md"));
34349
+ if (markdown === void 0) return void 0;
34350
+ const front = skillFrontMatter(markdown);
34351
+ const openai = yamlScalars(await readSmall(join24(directory, "agents", "openai.yaml")) ?? "");
34352
+ const name = (front.name || folder).trim();
34353
+ if (!name) return void 0;
34354
+ const displayName = clip3(openai["interface.display_name"] ?? front["metadata.display-name"] ?? front["metadata.display_name"] ?? front["display-name"] ?? front.display_name);
34355
+ const description = clip3(front.description);
34356
+ const shortDescription = clip3(openai["interface.short_description"] ?? front["metadata.short-description"] ?? front["metadata.short_description"]);
34357
+ return {
34358
+ name,
34359
+ ...displayName ? { displayName } : {},
34360
+ ...description ? { description } : {},
34361
+ ...shortDescription ? { shortDescription } : {},
34362
+ path: join24(directory, "SKILL.md"),
34363
+ source,
34364
+ enabled: true,
34365
+ userInvocable: true
34366
+ };
34367
+ }
34368
+ async function scan(root2, found) {
34369
+ const walk = async (directory, folder, depth, source) => {
34370
+ if (found.size >= MAX_SKILLS_PER_CLI) return;
34371
+ let entries;
34372
+ try {
34373
+ entries = await readdir5(directory, { withFileTypes: true });
34374
+ } catch {
34375
+ return;
34376
+ }
34377
+ if (entries.some((entry) => entry.name === "SKILL.md")) {
34378
+ const skill = await readSkill(directory, folder, source);
34379
+ if (skill && !found.has(skill.name)) found.set(skill.name, skill);
34380
+ return;
34381
+ }
34382
+ if (depth <= 0) return;
34383
+ for (const entry of entries) {
34384
+ if (entry.name === "node_modules" || entry.name === ".git") continue;
34385
+ const isDirectory = entry.isDirectory() || entry.isSymbolicLink() && await stat8(join24(directory, entry.name)).then((info) => info.isDirectory(), () => false);
34386
+ if (!isDirectory) continue;
34387
+ await walk(join24(directory, entry.name), entry.name, depth - 1, entry.name === ".system" ? "system" : source);
34388
+ }
34389
+ };
34390
+ await walk(root2.directory, "", root2.depth, root2.source);
34391
+ }
34392
+ async function readCliSkills(cli, home = homedir14()) {
34393
+ const found = /* @__PURE__ */ new Map();
34394
+ for (const root2 of skillRoots(cli, home)) await scan(root2, found);
34395
+ return [...found.values()].sort((a, b) => a.name.localeCompare(b.name));
34396
+ }
34397
+
34231
34398
  // src/t3/provider-catalog.ts
34232
34399
  var HUB_CLIS = [
34233
34400
  { cli: "codex", instanceId: "codex", driver: "codex", displayName: "Codex", effortOptionId: "reasoning_effort" },
@@ -34266,7 +34433,7 @@ function models2(cli, item) {
34266
34433
  function usageWindows(windows) {
34267
34434
  return windows.filter((window) => typeof window.used_percent === "number").map((window) => {
34268
34435
  const minutes = window.window_seconds ? Math.round(window.window_seconds / 60) : void 0;
34269
- const kind = minutes === void 0 ? "other" : minutes <= 6 * 60 ? "session" : minutes <= 8 * 24 * 60 ? "weekly" : minutes <= 32 * 24 * 60 ? "monthly" : "other";
34436
+ const kind = minutes === void 0 ? "other" : minutes >= 25 * 24 * 60 ? "monthly" : minutes >= 6 * 24 * 60 ? "weekly" : minutes <= 24 * 60 ? "session" : "other";
34270
34437
  return {
34271
34438
  id: window.key,
34272
34439
  kind,
@@ -34310,6 +34477,10 @@ var ProviderCatalog = class {
34310
34477
  const detected = HUB_CLIS.filter((cli) => detection.providers.some((provider) => provider.id === cli.cli && provider.installed)).map((cli) => cli.cli);
34311
34478
  const report = await this.collector.collect(detected, { force: Boolean(options.force) });
34312
34479
  if (options.quota) await this.readQuotas(detected, options.providerId);
34480
+ const skills = new Map(await Promise.all(HUB_CLIS.map(async (cli) => [
34481
+ cli.cli,
34482
+ detected.includes(cli.cli) ? await readCliSkills(cli.cli).catch(() => []) : []
34483
+ ])));
34313
34484
  const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
34314
34485
  this.last = HUB_CLIS.map((cli) => {
34315
34486
  const found = detection.providers.find((provider) => provider.id === cli.cli);
@@ -34332,7 +34503,7 @@ var ProviderCatalog = class {
34332
34503
  checkedAt,
34333
34504
  models: list,
34334
34505
  ...usage && runnable ? { usageLimits: usage } : {},
34335
- skills: [],
34506
+ skills: skills.get(cli.cli) ?? [],
34336
34507
  slashCommands: []
34337
34508
  };
34338
34509
  });
@@ -34343,16 +34514,18 @@ var ProviderCatalog = class {
34343
34514
  await Promise.all(detected.filter((cli) => !only || cli === only).map(async (cli) => {
34344
34515
  const read = catalogEntry(cli)?.quota;
34345
34516
  if (!read) return;
34517
+ const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
34346
34518
  try {
34347
34519
  const windows = await Promise.race([
34348
34520
  read(),
34349
34521
  new Promise((_resolve, reject) => {
34350
- setTimeout(() => reject(new Error("timeout")), QUOTA_TIMEOUT_MS).unref?.();
34522
+ setTimeout(() => reject(new Error("\u8BFB\u53D6\u989D\u5EA6\u8D85\u65F6")), QUOTA_TIMEOUT_MS).unref?.();
34351
34523
  })
34352
34524
  ]);
34353
34525
  const shaped = usageWindows(windows);
34354
- if (shaped.length) this.quotas.set(cli, { checkedAt: (/* @__PURE__ */ new Date()).toISOString(), windows: shaped });
34355
- } catch {
34526
+ this.quotas.set(cli, shaped.length ? { checkedAt, windows: shaped } : { checkedAt, windows: [], unavailable: { reason: "unsupported", message: "\u8BE5\u8D26\u53F7\u6CA1\u6709\u6309\u767E\u5206\u6BD4\u8BA1\u7684\u989D\u5EA6\u7A97\u53E3" } });
34527
+ } catch (error62) {
34528
+ this.quotas.set(cli, { checkedAt, windows: [], unavailable: { reason: "probeFailed", message: (error62 instanceof Error ? error62.message : String(error62)).slice(0, 300) } });
34356
34529
  }
34357
34530
  }));
34358
34531
  }
@@ -34362,7 +34535,7 @@ var ProviderCatalog = class {
34362
34535
  import { createHash as createHash5 } from "node:crypto";
34363
34536
  import { mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync9, renameSync as renameSync3, rmSync, writeFileSync as writeFileSync4 } from "node:fs";
34364
34537
  import { rename as rename9, writeFile as writeFile10 } from "node:fs/promises";
34365
- import { join as join24 } from "node:path";
34538
+ import { join as join25 } from "node:path";
34366
34539
  var ITEM_RUNS_KEPT = 40;
34367
34540
  var SEQUENCE_BLOCK = 500;
34368
34541
  var SAVE_DEBOUNCE_MS = 800;
@@ -34375,9 +34548,9 @@ function writeAtomicSync(path, text5) {
34375
34548
  var ThreadStore = class {
34376
34549
  constructor(dataDir, onError = () => void 0) {
34377
34550
  this.onError = onError;
34378
- this.root = join24(dataDir, "hub");
34379
- this.threadsDir = join24(this.root, "threads");
34380
- this.statePath = join24(this.root, "state.json");
34551
+ this.root = join25(dataDir, "hub");
34552
+ this.threadsDir = join25(this.root, "threads");
34553
+ this.statePath = join25(this.root, "state.json");
34381
34554
  mkdirSync4(this.threadsDir, { recursive: true, mode: 448 });
34382
34555
  try {
34383
34556
  const state = JSON.parse(readFileSync9(this.statePath, "utf8"));
@@ -34389,7 +34562,7 @@ var ThreadStore = class {
34389
34562
  for (const name of readdirSync5(this.threadsDir)) {
34390
34563
  if (!name.endsWith(".json")) continue;
34391
34564
  try {
34392
- const thread = JSON.parse(readFileSync9(join24(this.threadsDir, name), "utf8"));
34565
+ const thread = JSON.parse(readFileSync9(join25(this.threadsDir, name), "utf8"));
34393
34566
  if (thread?.v === 1 && typeof thread.id === "string" && Array.isArray(thread.runs) && Array.isArray(thread.items)) this.threads.set(thread.id, thread);
34394
34567
  } catch {
34395
34568
  }
@@ -34461,7 +34634,7 @@ var ThreadStore = class {
34461
34634
  clearTimeout(timer);
34462
34635
  this.timers.delete(threadId);
34463
34636
  }
34464
- if (safeId(threadId)) rmSync(join24(this.threadsDir, `${threadId}.json`), { force: true });
34637
+ if (safeId(threadId)) rmSync(join25(this.threadsDir, `${threadId}.json`), { force: true });
34465
34638
  }
34466
34639
  /** Marks the thread changed; it is written shortly after (and on `flush`). */
34467
34640
  touch(thread) {
@@ -34472,7 +34645,7 @@ var ThreadStore = class {
34472
34645
  const current = this.threads.get(thread.id);
34473
34646
  if (!current) return;
34474
34647
  this.trim(current);
34475
- const path = join24(this.threadsDir, `${current.id}.json`);
34648
+ const path = join25(this.threadsDir, `${current.id}.json`);
34476
34649
  const temporary = `${path}.${process.pid}.tmp`;
34477
34650
  void writeFile10(temporary, JSON.stringify(current), { encoding: "utf8", mode: 384 }).then(() => rename9(temporary, path)).catch((error62) => this.onError(error62 instanceof Error ? error62.message : String(error62)));
34478
34651
  }, SAVE_DEBOUNCE_MS);
@@ -34487,7 +34660,7 @@ var ThreadStore = class {
34487
34660
  if (!thread) continue;
34488
34661
  this.trim(thread);
34489
34662
  try {
34490
- writeAtomicSync(join24(this.threadsDir, `${threadId}.json`), JSON.stringify(thread));
34663
+ writeAtomicSync(join25(this.threadsDir, `${threadId}.json`), JSON.stringify(thread));
34491
34664
  } catch (error62) {
34492
34665
  this.onError(error62 instanceof Error ? error62.message : String(error62));
34493
34666
  }
@@ -34504,10 +34677,10 @@ var ThreadStore = class {
34504
34677
  };
34505
34678
 
34506
34679
  // src/t3/turn-items.ts
34507
- var MAX_TEXT = 2e5;
34680
+ var MAX_TEXT2 = 2e5;
34508
34681
  var MAX_OUTPUT = 16e3;
34509
34682
  var MAX_DIFF = 24e3;
34510
- var clip3 = (text5, max) => text5.length > max ? `${text5.slice(0, max)}\u2026` : text5;
34683
+ var clip4 = (text5, max) => text5.length > max ? `${text5.slice(0, max)}\u2026` : text5;
34511
34684
  var record10 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
34512
34685
  var text3 = (value) => typeof value === "string" ? value : "";
34513
34686
  var STATUS = { pending: "pending", in_progress: "running", completed: "completed", failed: "failed" };
@@ -34540,7 +34713,7 @@ var TurnItemFolder = class {
34540
34713
  }
34541
34714
  this.open.delete(kind === "assistant_message" ? "reasoning" : "assistant_message");
34542
34715
  const item = this.upsert(key2, kind, { streaming: true });
34543
- item.text = clip3(text3(item.text) + event.text, MAX_TEXT);
34716
+ item.text = clip4(text3(item.text) + event.text, MAX_TEXT2);
34544
34717
  item.status = "running";
34545
34718
  return this.touch(item);
34546
34719
  }
@@ -34551,7 +34724,7 @@ var TurnItemFolder = class {
34551
34724
  case "text":
34552
34725
  case "thought": {
34553
34726
  const item = this.upsert(key, source.type === "text" ? "assistant_message" : "reasoning", { streaming: true });
34554
- item.text = clip3(text3(source.text), MAX_TEXT);
34727
+ item.text = clip4(text3(source.text), MAX_TEXT2);
34555
34728
  item.status = "running";
34556
34729
  return this.touch(item);
34557
34730
  }
@@ -34565,7 +34738,7 @@ var TurnItemFolder = class {
34565
34738
  }
34566
34739
  case "proposed_plan": {
34567
34740
  const item = this.upsert(key, "proposed_plan", { planId: text3(source.turnId) || key });
34568
- item.markdown = clip3(text3(source.markdown), MAX_TEXT);
34741
+ item.markdown = clip4(text3(source.markdown), MAX_TEXT2);
34569
34742
  item.status = "completed";
34570
34743
  return this.touch(item);
34571
34744
  }
@@ -34632,7 +34805,7 @@ var TurnItemFolder = class {
34632
34805
  const exitCode = record10(output2?.exitStatus).exitCode;
34633
34806
  item = this.upsert(key, "command_execution", {});
34634
34807
  item.input = text3(command?.command) || title;
34635
- if (output2) item.output = clip3(text3(output2.output), MAX_OUTPUT);
34808
+ if (output2) item.output = clip4(text3(output2.output), MAX_OUTPUT);
34636
34809
  if (typeof exitCode === "number") item.exitCode = exitCode;
34637
34810
  } else if (kind === "edit") {
34638
34811
  const paths = [...new Set([...diffs.map((part) => text3(part.path)), ...locations].filter(Boolean))];
@@ -34641,8 +34814,8 @@ var TurnItemFolder = class {
34641
34814
  if (paths.length) item.changes = paths.slice(0, 200).map((path) => ({ operation: "edit", path }));
34642
34815
  const first = diffs[0];
34643
34816
  if (first) {
34644
- if (typeof first.oldText === "string") item.oldStr = clip3(first.oldText, MAX_DIFF);
34645
- item.newStr = clip3(text3(first.newText), MAX_DIFF);
34817
+ if (typeof first.oldText === "string") item.oldStr = clip4(first.oldText, MAX_DIFF);
34818
+ item.newStr = clip4(text3(first.newText), MAX_DIFF);
34646
34819
  }
34647
34820
  } else if (kind === "search") {
34648
34821
  item = this.upsert(key, "file_search", {});
@@ -34656,7 +34829,7 @@ var TurnItemFolder = class {
34656
34829
  if (source.rawInput !== void 0) item.input = source.rawInput;
34657
34830
  if (source.rawOutput !== void 0) item.output = source.rawOutput;
34658
34831
  }
34659
- if (title) item.title = clip3(title, 400);
34832
+ if (title) item.title = clip4(title, 400);
34660
34833
  item.status = status2;
34661
34834
  if (status2 === "completed" || status2 === "failed") item.completedAt = (/* @__PURE__ */ new Date()).toISOString();
34662
34835
  return this.touch(item);
@@ -34668,8 +34841,10 @@ var ACTIVE = /* @__PURE__ */ new Set(["starting", "running"]);
34668
34841
  var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "interrupted", "cancelled"]);
34669
34842
  var ITEM_FLUSH_MS = 200;
34670
34843
  var SNAPSHOT_RUNS = 30;
34844
+ var DRAIN_TIMEOUT_MS = 15e3;
34671
34845
  var MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
34672
34846
  var DEFAULT_MODEL_SENTINELS = /* @__PURE__ */ new Set(["antigravity-default", "default"]);
34847
+ var providerThreadId = (threadId, sessionId) => `${threadId}:${sessionId}`;
34673
34848
  var record11 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
34674
34849
  var text4 = (value) => typeof value === "string" ? value : "";
34675
34850
  function selectionEffort(selection) {
@@ -34687,7 +34862,7 @@ var T3Backend = class {
34687
34862
  this.config = config2;
34688
34863
  this.logger = logger;
34689
34864
  this.store = new ThreadStore(config2.dataDir, (message) => logger.warn("hub-thread-save-failed", { error: message }));
34690
- this.orphans = new OrphanRegistry(join25(config2.dataDir, "active-runs.json"));
34865
+ this.orphans = new OrphanRegistry(join26(config2.dataDir, "active-runs.json"));
34691
34866
  const reporter = {
34692
34867
  started: async (runId, report) => this.onRunStarted(runId, report),
34693
34868
  content: (runId, events) => this.onRunContent(runId, events),
@@ -34704,6 +34879,12 @@ var T3Backend = class {
34704
34879
  live = /* @__PURE__ */ new Map();
34705
34880
  /** Run id → thread id for every run this process started. */
34706
34881
  runThreads = /* @__PURE__ */ new Map();
34882
+ /**
34883
+ * Runs already reported as interrupted whose CLI process tree is still being
34884
+ * ended in the background (run id → release timer). The thread starts no
34885
+ * other turn until the supervisor confirms the process is gone.
34886
+ */
34887
+ draining = /* @__PURE__ */ new Map();
34707
34888
  publisher;
34708
34889
  /** Where events go. Until the link attaches (and while it is down) the link buffers them itself. */
34709
34890
  attach(publisher) {
@@ -34730,6 +34911,8 @@ var T3Backend = class {
34730
34911
  async stop() {
34731
34912
  await this.supervisor.disposeAll();
34732
34913
  for (const live of this.live.values()) if (live.timer) clearTimeout(live.timer);
34914
+ for (const timer of this.draining.values()) clearTimeout(timer);
34915
+ this.draining.clear();
34733
34916
  this.store.flush();
34734
34917
  }
34735
34918
  activeRuns() {
@@ -34752,12 +34935,12 @@ var T3Backend = class {
34752
34935
  // ---- DeviceBackend: projects and snapshots ----
34753
34936
  async ensureProject(workspaceRoot) {
34754
34937
  let target = (workspaceRoot ?? "").trim();
34755
- if (!target || target === "~") target = homedir14();
34756
- else if (target.startsWith("~/") || target.startsWith("~\\")) target = join25(homedir14(), target.slice(2));
34938
+ if (!target || target === "~") target = homedir15();
34939
+ else if (target.startsWith("~/") || target.startsWith("~\\")) target = join26(homedir15(), target.slice(2));
34757
34940
  const root2 = resolve7(target);
34758
34941
  try {
34759
34942
  await mkdir9(root2, { recursive: true });
34760
- if (!(await stat8(root2)).isDirectory()) throw new Error("\u4E0D\u662F\u76EE\u5F55");
34943
+ if (!(await stat9(root2)).isDirectory()) throw new Error("\u4E0D\u662F\u76EE\u5F55");
34761
34944
  } catch (error62) {
34762
34945
  throw rpcError("ProjectMutationError", `\u65E0\u6CD5\u4F7F\u7528\u5DE5\u4F5C\u76EE\u5F55 ${root2}\uFF1A${error62 instanceof Error ? error62.message : String(error62)}`, `workspaceRoot=${root2}`);
34763
34946
  }
@@ -34776,6 +34959,8 @@ var T3Backend = class {
34776
34959
  thread: this.threadState(thread),
34777
34960
  runs: runs.map((entry) => entry.run),
34778
34961
  turnItems: thread.items.filter((entry) => typeof entry.item.runId !== "string" || kept.has(entry.item.runId)).map((entry) => entry.item),
34962
+ // The CLI sessions the runs ran in; the Hub offers a native fork only from a run with a strong one.
34963
+ providerThreads: this.providerThreads(thread),
34779
34964
  runtimeRequests: []
34780
34965
  }
34781
34966
  };
@@ -34823,7 +35008,7 @@ var T3Backend = class {
34823
35008
  case "provider.switch":
34824
35009
  return this.selectModel(command);
34825
35010
  case "thread.fork":
34826
- throw rpcError(ERROR_TAGS.forkUnsupported, "ocra \u8BBE\u5907\u5305\u6682\u4E0D\u652F\u6301\u4F1A\u8BDD\u5206\u53C9\uFF0C\u8BF7\u65B0\u5EFA\u4F1A\u8BDD\u7EE7\u7EED", "command=thread.fork");
35011
+ return this.forkThread(command);
34827
35012
  case "runtime-request.respond":
34828
35013
  throw rpcError("RuntimeRequestNotFound", "\u8FD9\u53F0\u8BBE\u5907\u4EE5\u5B8C\u5168\u8BBF\u95EE\u6A21\u5F0F\u8FD0\u884C\uFF0C\u6CA1\u6709\u7B49\u5F85\u786E\u8BA4\u7684\u8BF7\u6C42", `requestId=${text4(command.requestId)}`);
34829
35014
  default:
@@ -34940,7 +35125,7 @@ var T3Backend = class {
34940
35125
  const prompt = body + await this.saveAttachments(thread, messageId, attachments);
34941
35126
  const now = (/* @__PURE__ */ new Date()).toISOString();
34942
35127
  const runId = randomUUID5();
34943
- const busy = thread.runs.some((entry2) => ACTIVE.has(entry2.run.status) || entry2.run.status === "queued");
35128
+ const busy = thread.runs.some((entry2) => ACTIVE.has(entry2.run.status) || entry2.run.status === "queued" || this.draining.has(entry2.run.id));
34944
35129
  const run2 = {
34945
35130
  id: runId,
34946
35131
  threadId: thread.id,
@@ -34980,7 +35165,7 @@ var T3Backend = class {
34980
35165
  async saveAttachments(thread, messageId, attachments) {
34981
35166
  if (!attachments.length) return "";
34982
35167
  const lines = [];
34983
- const directory = join25(this.config.dataDir, "hub", "attachments", thread.id.replace(/[^A-Za-z0-9_.-]/g, "_"), messageId.replace(/[^A-Za-z0-9_.-]/g, "_"));
35168
+ const directory = join26(this.config.dataDir, "hub", "attachments", thread.id.replace(/[^A-Za-z0-9_.-]/g, "_"), messageId.replace(/[^A-Za-z0-9_.-]/g, "_"));
34984
35169
  for (const [index, attachment] of attachments.entries()) {
34985
35170
  const name = (text4(attachment.name) || `attachment-${index + 1}`).replace(/[^\p{L}\p{N}_.-]/gu, "_").slice(0, 120);
34986
35171
  const dataUrl = text4(attachment.dataUrl);
@@ -34993,7 +35178,7 @@ var T3Backend = class {
34993
35178
  }
34994
35179
  try {
34995
35180
  await mkdir9(directory, { recursive: true, mode: 448 });
34996
- const path = join25(directory, `${index + 1}-${name}`);
35181
+ const path = join26(directory, `${index + 1}-${name}`);
34997
35182
  await writeFile11(path, bytes, { mode: 384 });
34998
35183
  lines.push(`- ${path}`);
34999
35184
  } catch (error62) {
@@ -35022,6 +35207,12 @@ ${lines.join("\n")}` : "";
35022
35207
  run2.status = "starting";
35023
35208
  this.emitRun(thread, cli, entry, "run.updated");
35024
35209
  }
35210
+ const fork = thread.nativeSessionId ? void 0 : thread.fork;
35211
+ const sessionId = thread.nativeSessionId || (fork && cli.cli === "claude" ? randomUUID5() : "");
35212
+ if (fork && cli.cli === "claude" && !claudeTranscriptExists(fork.sourceSessionId)) {
35213
+ this.onRunFinished(run2.id, { status: "failed", error: "\u539F\u4F1A\u8BDD\u5728\u8FD9\u53F0\u8BBE\u5907\u4E0A\u5DF2\u7ECF\u4E0D\u5B58\u5728\uFF08\u53EF\u80FD\u88AB\u6E05\u7406\u6216\u6362\u4E86\u8BBE\u5907\uFF09\uFF0C\u65E0\u6CD5\u5206\u53C9", failure_kind: "sessionMissing", duration_ms: 0 });
35214
+ return;
35215
+ }
35025
35216
  void (async () => {
35026
35217
  const payload = RunStartPayloadSchema.parse({
35027
35218
  // Full access, always: no turn of this device ever waits for a confirmation.
@@ -35031,7 +35222,8 @@ ${lines.join("\n")}` : "";
35031
35222
  task_chain_id: thread.id,
35032
35223
  message_id: run2.userMessageId,
35033
35224
  prompt: entry.prompt ?? "",
35034
- session_id: thread.nativeSessionId,
35225
+ session_id: sessionId,
35226
+ ...fork ? { fork: { source_session_id: fork.sourceSessionId, keep_turns: fork.keepTurns } } : {},
35035
35227
  model: DEFAULT_MODEL_SENTINELS.has(model) ? "" : model,
35036
35228
  reasoning_effort: selectionEffort(thread.modelSelection),
35037
35229
  workdir: thread.workspaceRoot
@@ -35043,11 +35235,18 @@ ${lines.join("\n")}` : "";
35043
35235
  });
35044
35236
  }
35045
35237
  startNextQueued(thread) {
35046
- if (thread.queueHeld || thread.runs.some((entry) => ACTIVE.has(entry.run.status))) return;
35238
+ if (thread.queueHeld || thread.runs.some((entry) => ACTIVE.has(entry.run.status) || this.draining.has(entry.run.id))) return;
35047
35239
  const next = thread.runs.find((entry) => entry.run.status === "queued");
35048
35240
  if (next) this.launch(thread, next);
35049
35241
  }
35050
- async interruptRun(command) {
35242
+ /**
35243
+ * `run.interrupt`. The run is reported as interrupted and the command is
35244
+ * answered at once; ending the CLI's process tree (a polite signal, a grace
35245
+ * period, then a forced kill; `taskkill` on Windows) goes on in the
35246
+ * background. The report used to wait for the process to exit and its
35247
+ * output pipes to close, so a CLI slow to die kept the page on "running".
35248
+ */
35249
+ interruptRun(command) {
35051
35250
  const thread = this.requireThread(command.threadId);
35052
35251
  const wanted = text4(command.runId);
35053
35252
  const entry = wanted ? thread.runs.find((candidate) => candidate.run.id === wanted) : [...thread.runs].reverse().find((candidate) => ACTIVE.has(candidate.run.status));
@@ -35059,10 +35258,31 @@ ${lines.join("\n")}` : "";
35059
35258
  this.closeRun(thread, entry, "interrupted", "");
35060
35259
  return { interrupted: true };
35061
35260
  }
35062
- const stopping = await this.supervisor.cancel(entry.run.id);
35063
- if (!stopping && !TERMINAL.has(entry.run.status)) this.closeRun(thread, entry, "interrupted", "");
35261
+ const runId = entry.run.id;
35262
+ const live = this.live.get(runId);
35263
+ if (live) {
35264
+ for (const item of live.folder.finish("interrupted", (/* @__PURE__ */ new Date()).toISOString())) live.dirty.add(item);
35265
+ this.flushItems(runId);
35266
+ }
35267
+ this.draining.set(runId, setTimeout(() => {
35268
+ this.logger.warn("hub-run-stop-unconfirmed", { runId, seconds: DRAIN_TIMEOUT_MS / 1e3 });
35269
+ this.releaseDrain(runId);
35270
+ }, DRAIN_TIMEOUT_MS));
35271
+ this.closeRun(thread, entry, "interrupted", "");
35272
+ void this.supervisor.cancel(runId).then((stopping) => {
35273
+ if (!stopping) this.releaseDrain(runId);
35274
+ }, () => this.releaseDrain(runId));
35064
35275
  return { interrupted: true };
35065
35276
  }
35277
+ /** The stopped run's process is gone (or was never there): the thread may run its next turn. */
35278
+ releaseDrain(runId) {
35279
+ const timer = this.draining.get(runId);
35280
+ if (timer === void 0) return;
35281
+ clearTimeout(timer);
35282
+ this.draining.delete(runId);
35283
+ const thread = this.store.get(this.runThreads.get(runId) ?? "");
35284
+ if (thread) this.startNextQueued(thread);
35285
+ }
35066
35286
  // ---- Run reports from the supervisor ----
35067
35287
  runOf(runId) {
35068
35288
  const threadId = this.runThreads.get(runId);
@@ -35074,15 +35294,85 @@ ${lines.join("\n")}` : "";
35074
35294
  const found = this.runOf(runId);
35075
35295
  if (!found) return;
35076
35296
  const { thread, entry } = found;
35077
- if (report.session_id && report.session_id !== thread.nativeSessionId) {
35078
- thread.nativeSessionId = report.session_id;
35079
- this.store.touch(thread);
35297
+ if (report.session_id) this.noteNativeSession(thread, entry, report.session_id);
35298
+ if (report.pid) {
35299
+ entry.launched = true;
35300
+ if (this.draining.has(runId)) void this.supervisor.cancel(runId).catch(() => false);
35301
+ if (entry.run.status === "starting") {
35302
+ entry.run.status = "running";
35303
+ entry.run.startedAt = (/* @__PURE__ */ new Date()).toISOString();
35304
+ this.emitRun(thread, this.cliOf(thread), entry, "run.updated");
35305
+ }
35080
35306
  }
35081
- if (report.pid && entry.run.status === "starting") {
35082
- entry.run.status = "running";
35083
- entry.run.startedAt = (/* @__PURE__ */ new Date()).toISOString();
35084
- this.emitRun(thread, this.cliOf(thread), entry, "run.updated");
35307
+ }
35308
+ /** The CLI named the session this turn runs in: the thread continues it, and the run points at it. */
35309
+ noteNativeSession(thread, entry, sessionId) {
35310
+ entry.nativeSessionId = sessionId;
35311
+ entry.run.providerThreadId = providerThreadId(thread.id, sessionId);
35312
+ if (thread.nativeSessionId !== sessionId) {
35313
+ thread.nativeSessionId = sessionId;
35314
+ delete thread.fork;
35085
35315
  }
35316
+ this.store.touch(thread);
35317
+ }
35318
+ providerThreads(thread) {
35319
+ const cli = this.cliOf(thread);
35320
+ const sessions = new Set(thread.runs.map((entry) => entry.nativeSessionId).filter((id) => Boolean(id)));
35321
+ return [...sessions].map((sessionId) => ({
35322
+ id: providerThreadId(thread.id, sessionId),
35323
+ threadId: thread.id,
35324
+ driver: cli.driver,
35325
+ providerInstanceId: cli.instanceId,
35326
+ nativeThreadRef: { strength: "strong", id: sessionId }
35327
+ }));
35328
+ }
35329
+ /**
35330
+ * `thread.fork`: a new thread on the same CLI and work directory whose first
35331
+ * turn continues a native copy of the source CLI session up to the chosen
35332
+ * run. The source thread is not touched. Only CLIs that can copy a session
35333
+ * are forked (Claude Code, Codex); the others are refused, never imitated.
35334
+ */
35335
+ forkThread(command) {
35336
+ const source = this.requireThread(command.sourceThreadId);
35337
+ const targetId = text4(command.targetThreadId);
35338
+ if (!targetId) throw rpcError(ERROR_TAGS.invalidCommand, "thread.fork \u7F3A\u5C11 targetThreadId");
35339
+ if (this.store.get(targetId)) return { threadId: targetId, created: false };
35340
+ const cli = this.cliOf(source);
35341
+ if (cli.cli !== "claude" && cli.cli !== "codex") {
35342
+ throw rpcError(ERROR_TAGS.forkUnsupported, `${cli.displayName} \u6682\u4E0D\u652F\u6301\u5206\u53C9\uFF0C\u8BF7\u65B0\u5EFA\u4F1A\u8BDD\u7EE7\u7EED`, `thread.fork driver=${cli.driver}`);
35343
+ }
35344
+ const point = record11(command.sourcePoint);
35345
+ const runId = text4(point.runId);
35346
+ const at = runId ? source.runs.find((entry) => entry.run.id === runId) : [...source.runs].reverse().find((entry) => entry.run.status === "completed");
35347
+ if (!at) throw rpcError(ERROR_TAGS.forkUnsupported, "\u8BBE\u5907\u4E0A\u627E\u4E0D\u5230\u8981\u5206\u53C9\u7684\u8FD9\u4E00\u8F6E", `thread.fork run ${runId || "(latest)"} not found`);
35348
+ if (!TERMINAL.has(at.run.status)) throw rpcError(ERROR_TAGS.forkUnsupported, "\u8FD9\u4E00\u8F6E\u8FD8\u5728\u8FD0\u884C\uFF08in-progress\uFF09\uFF0C\u4E0D\u80FD\u5206\u53C9\uFF0C\u8BF7\u7B49\u5B83\u5B8C\u6210\u540E\u518D\u8BD5", `run ${at.run.id} status=${at.run.status}`);
35349
+ if (!at.nativeSessionId) throw rpcError(ERROR_TAGS.forkUnsupported, `\u8FD9\u4E00\u8F6E\u6CA1\u6709 ${cli.displayName} \u7684\u539F\u751F\u4F1A\u8BDD\uFF0C\u65E0\u6CD5\u5206\u53C9\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u8F6E\u6B21`, `run ${at.run.id} has no native session`);
35350
+ const keepTurns = source.runs.filter((entry) => entry.launched && entry.nativeSessionId === at.nativeSessionId && entry.run.ordinal <= at.run.ordinal).length;
35351
+ const now = (/* @__PURE__ */ new Date()).toISOString();
35352
+ const thread = {
35353
+ v: 1,
35354
+ id: targetId,
35355
+ projectId: source.projectId,
35356
+ workspaceRoot: source.workspaceRoot,
35357
+ title: text4(command.title) || `${source.title}\uFF08\u5206\u53C9\uFF09`,
35358
+ cli: source.cli,
35359
+ modelSelection: record11(at.run.modelSelection).model ? record11(at.run.modelSelection) : source.modelSelection,
35360
+ runtimeMode: source.runtimeMode,
35361
+ interactionMode: source.interactionMode,
35362
+ createdAt: now,
35363
+ updatedAt: now,
35364
+ nativeSessionId: "",
35365
+ archived: false,
35366
+ queueHeld: false,
35367
+ seq: 0,
35368
+ nextItemOrdinal: 1,
35369
+ runs: [],
35370
+ items: [],
35371
+ fork: { sourceThreadId: source.id, sourceRunId: at.run.id, sourceSessionId: at.nativeSessionId, keepTurns }
35372
+ };
35373
+ this.store.put(thread);
35374
+ this.emitThread(thread, "thread.created");
35375
+ return { threadId: targetId, created: true, forkedFrom: { threadId: source.id, runId: at.run.id, keepTurns } };
35086
35376
  }
35087
35377
  onRunContent(runId, events) {
35088
35378
  const live = this.live.get(runId);
@@ -35123,10 +35413,12 @@ ${lines.join("\n")}` : "";
35123
35413
  }
35124
35414
  const { thread, entry } = found;
35125
35415
  if (TERMINAL.has(entry.run.status)) {
35416
+ if (report.session_id) this.noteNativeSession(thread, entry, report.session_id);
35126
35417
  this.dropLive(runId);
35418
+ this.releaseDrain(runId);
35127
35419
  return;
35128
35420
  }
35129
- if (report.session_id && report.session_id !== thread.nativeSessionId) thread.nativeSessionId = report.session_id;
35421
+ if (report.session_id) this.noteNativeSession(thread, entry, report.session_id);
35130
35422
  const outcome = report.status === "succeeded" ? "completed" : report.status === "cancelled" ? "interrupted" : "failed";
35131
35423
  const live = this.live.get(runId);
35132
35424
  if (live) {
@@ -35191,7 +35483,9 @@ ${lines.join("\n")}` : "";
35191
35483
  workspaceRoot: thread.workspaceRoot,
35192
35484
  createdAt: thread.createdAt,
35193
35485
  updatedAt: thread.updatedAt,
35194
- archivedAt: thread.archived ? thread.updatedAt : null
35486
+ archived: thread.archived,
35487
+ archivedAt: thread.archived ? thread.updatedAt : null,
35488
+ ...thread.fork ? { forkedFrom: { threadId: thread.fork.sourceThreadId, runId: thread.fork.sourceRunId } } : {}
35195
35489
  };
35196
35490
  }
35197
35491
  emitThread(thread, type) {
@@ -35220,7 +35514,7 @@ var HubRuntime = class {
35220
35514
  },
35221
35515
  backend: this.backend,
35222
35516
  appVersion: hubAppVersion(version2),
35223
- eventStatePath: join26(config2.dataDir, "hub-events.json"),
35517
+ eventStatePath: join27(config2.dataDir, "hub-events.json"),
35224
35518
  logger: this.logger
35225
35519
  });
35226
35520
  this.backend.attach({ event: (envelope) => this.link.publishEvent(envelope) });
@@ -35651,7 +35945,7 @@ async function runService(options = {}) {
35651
35945
  }
35652
35946
 
35653
35947
  // src/index.ts
35654
- var { currentInstallation, installShared, ensureIdle, compareVersions: compareVersions2 } = createRequire(import.meta.url)(join27(agentPackageRoot(), "scripts", "installation.cjs"));
35948
+ var { currentInstallation, installShared, ensureIdle, compareVersions: compareVersions2 } = createRequire(import.meta.url)(join28(agentPackageRoot(), "scripts", "installation.cjs"));
35655
35949
  async function run() {
35656
35950
  try {
35657
35951
  await runService();
@@ -35823,7 +36117,7 @@ async function update(args) {
35823
36117
  if (customConfig) process.env.TOC_OCRA_CONFIG = resolve9(customConfig);
35824
36118
  await ensureIdle();
35825
36119
  const npmPath = resolveCliCommand("npm");
35826
- const temporary = mkdtempSync(join27(tmpdir4(), "toc-ocra-update-"));
36120
+ const temporary = mkdtempSync(join28(tmpdir4(), "toc-ocra-update-"));
35827
36121
  try {
35828
36122
  const metadataResponse = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`, { headers: { accept: "application/json", "cache-control": "no-cache" }, signal: AbortSignal.timeout(15e3) });
35829
36123
  if (!metadataResponse.ok) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 npm \u6700\u65B0\u7248\u672C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
@@ -35850,7 +36144,7 @@ async function update(args) {
35850
36144
  }
35851
36145
  const archive = Buffer.concat(chunks);
35852
36146
  if (`sha512-${createHash6("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");
35853
- const archivePath = join27(temporary, "toc-ocra.tgz");
36147
+ const archivePath = join28(temporary, "toc-ocra.tgz");
35854
36148
  writeFileSync5(archivePath, archive, { mode: 384 });
35855
36149
  const npm = directLaunch2(npmPath, ["install", "--prefix", temporary, "--ignore-scripts", "--omit=dev", "--no-package-lock", "--no-audit", "--no-fund", "--prefer-online", "--registry=https://registry.npmjs.org", archivePath]);
35856
36150
  const install = spawnSync(npm.executable, npm.args, { stdio: "inherit", shell: false, windowsHide: true });
@@ -35860,7 +36154,7 @@ async function update(args) {
35860
36154
  return;
35861
36155
  }
35862
36156
  const previousVersion = agentVersion();
35863
- const current = await installShared(join27(temporary, "node_modules", PACKAGE_NAME), { startService: existsSync8(defaultConfigPath()) });
36157
+ const current = await installShared(join28(temporary, "node_modules", PACKAGE_NAME), { startService: existsSync8(defaultConfigPath()) });
35864
36158
  if (current.version === previousVersion) process.stdout.write(`toc-ocra \u5DF2\u662F\u6700\u65B0\u7248\u672C ${current.version}
35865
36159
  `);
35866
36160
  else process.stdout.write(`toc-ocra \u5DF2\u5347\u7EA7\u5230 ${current.version}\uFF0C\u7EC8\u7AEF\u4E0E Echo \u63D2\u4EF6\u5171\u7528\u6B64\u7248\u672C
@@ -35888,7 +36182,7 @@ async function main() {
35888
36182
  const selected = !shared || compareVersions2(agentVersion(), shared.version) > 0 ? await installShared(root2) : shared;
35889
36183
  const same = (a, b) => process.platform === "win32" ? resolve9(a).toLowerCase() === resolve9(b).toLowerCase() : resolve9(a) === resolve9(b);
35890
36184
  if (!same(selected.root, root2)) {
35891
- await import(pathToFileURL2(join27(selected.root, "dist", "cli", "cli.mjs")).href);
36185
+ await import(pathToFileURL2(join28(selected.root, "dist", "cli", "cli.mjs")).href);
35892
36186
  return;
35893
36187
  }
35894
36188
  }