cwm-assistant 0.3.8 → 0.3.10

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.
@@ -6,9 +6,9 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/cli.ts
8
8
  import { spawn as spawn8 } from "node:child_process";
9
- import fs24 from "node:fs";
9
+ import fs25 from "node:fs";
10
10
  import os9 from "node:os";
11
- import path27 from "node:path";
11
+ import path28 from "node:path";
12
12
  import { createInterface } from "node:readline/promises";
13
13
 
14
14
  // ../../node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
@@ -2619,7 +2619,7 @@ var Type = type_exports2;
2619
2619
 
2620
2620
  // ../../packages/contracts/src/assistant.ts
2621
2621
  var ASSISTANT_PROTOCOL = 1;
2622
- var ASSISTANT_VERSION = "0.3.8";
2622
+ var ASSISTANT_VERSION = "0.3.10";
2623
2623
  var ASSISTANT_PORT = 46322;
2624
2624
 
2625
2625
  // ../../packages/contracts/src/index.ts
@@ -2754,6 +2754,33 @@ import path from "node:path";
2754
2754
  import { promisify } from "node:util";
2755
2755
  var execute = promisify(execFile);
2756
2756
  var xml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
2757
+ var vbs = (value) => '"' + value.replaceAll('"', '""') + '"';
2758
+ function writeWindowsLauncher(file, script) {
2759
+ fs.writeFileSync(file, "\uFEFF" + script, { encoding: "utf16le" });
2760
+ }
2761
+ function windowsLauncherScript(nodePath, entry, directory) {
2762
+ const quote = (value) => '"' + value + '"';
2763
+ const command = [quote(nodePath), quote(entry), "serve", "--state-dir", quote(directory)].join(
2764
+ " "
2765
+ );
2766
+ return [
2767
+ "' Starts the Workspace assistant with no console window. Written by cwm-assistant.",
2768
+ 'Set shell = CreateObject("WScript.Shell")',
2769
+ // The state directory, never the package: a live cwd inside the package blocks npm's rename.
2770
+ "shell.CurrentDirectory = " + vbs(directory),
2771
+ "code = shell.Run(" + vbs(command) + ", 0, True)",
2772
+ "WScript.Quit code",
2773
+ ""
2774
+ ].join("\r\n");
2775
+ }
2776
+ function windowsTaskXml(options) {
2777
+ return `\uFEFF<?xml version="1.0" encoding="UTF-16"?>
2778
+ <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><Triggers><LogonTrigger><Enabled>true</Enabled><UserId>${xml(options.user)}</UserId></LogonTrigger></Triggers><Principals><Principal id="Author"><UserId>${xml(options.user)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals><Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>3</Count></RestartOnFailure></Settings><Actions Context="Author"><Exec><Command>${xml(options.wscript)}</Command><Arguments>${xml(vbs(options.launcher))}</Arguments></Exec></Actions></Task>`;
2779
+ }
2780
+ function wscriptPath(env = process.env) {
2781
+ const systemRoot = (env.SystemRoot || env.windir || "C:\\Windows").replace(/[\\/]+$/, "");
2782
+ return systemRoot + "\\System32\\wscript.exe";
2783
+ }
2757
2784
  async function startAutostart() {
2758
2785
  if (process.platform === "darwin")
2759
2786
  await execute("launchctl", ["kickstart", `gui/${process.getuid()}/com.cwm.assistant`]);
@@ -2796,13 +2823,12 @@ async function configureAutostart(enable, directory, entry) {
2796
2823
  return;
2797
2824
  }
2798
2825
  const user = os.userInfo().username;
2826
+ const launcher = path.join(directory, "assistant-start.vbs");
2827
+ writeWindowsLauncher(launcher, windowsLauncherScript(process.execPath, entry, directory));
2799
2828
  const file = path.join(directory, "autostart.xml");
2800
- fs.writeFileSync(
2801
- file,
2802
- `\uFEFF<?xml version="1.0" encoding="UTF-16"?>
2803
- <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><Triggers><LogonTrigger><Enabled>true</Enabled><UserId>${xml(user)}</UserId></LogonTrigger></Triggers><Principals><Principal id="Author"><UserId>${xml(user)}</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals><Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><ExecutionTimeLimit>PT0S</ExecutionTimeLimit><RestartOnFailure><Interval>PT1M</Interval><Count>3</Count></RestartOnFailure></Settings><Actions Context="Author"><Exec><Command>${xml(process.execPath)}</Command><Arguments>&quot;${xml(entry)}&quot; serve --state-dir &quot;${xml(directory)}&quot;</Arguments></Exec></Actions></Task>`,
2804
- { encoding: "utf16le" }
2805
- );
2829
+ fs.writeFileSync(file, windowsTaskXml({ user, launcher, wscript: wscriptPath() }), {
2830
+ encoding: "utf16le"
2831
+ });
2806
2832
  await execute("schtasks.exe", ["/Create", "/TN", task, "/XML", file, "/F"]);
2807
2833
  await execute("schtasks.exe", ["/Run", "/TN", task]);
2808
2834
  } else throw new Error("\u81EA\u542F\u52A8\u4EC5\u652F\u6301 Windows \u548C macOS");
@@ -4255,8 +4281,8 @@ function registerAdoptRoutes(app, store, jobs) {
4255
4281
 
4256
4282
  // src/jobs.ts
4257
4283
  import { randomUUID as randomUUID6 } from "node:crypto";
4258
- import fs14 from "node:fs";
4259
- import path16 from "node:path";
4284
+ import fs15 from "node:fs";
4285
+ import path17 from "node:path";
4260
4286
 
4261
4287
  // ../../packages/runtime/src/workspaces/edit.ts
4262
4288
  import { randomUUID as randomUUID5 } from "node:crypto";
@@ -4520,6 +4546,52 @@ async function editLocalWorkspace(options) {
4520
4546
  }
4521
4547
  }
4522
4548
 
4549
+ // src/mount-relocation.ts
4550
+ import fs14 from "node:fs";
4551
+ import path16 from "node:path";
4552
+ async function relocateMount(options) {
4553
+ const { root, mount, log } = options;
4554
+ if (!inside3(mount.directory, mount.workspaceFile))
4555
+ throw new Error("\u672C\u673A\u526F\u672C\u7684 Workspace \u6587\u4EF6\u4E0D\u5728\u526F\u672C\u76EE\u5F55\u5185\uFF0C\u65E0\u6CD5\u968F\u5DE5\u4F5C\u76EE\u5F55\u79FB\u52A8");
4556
+ const target = checkedPath(root, path16.join(root, path16.basename(mount.directory)), false);
4557
+ if (fs14.existsSync(target)) throw new Error("\u65B0\u7684\u5DE5\u4F5C\u76EE\u5F55\u91CC\u5DF2\u6709\u540C\u540D\u76EE\u5F55\uFF1A" + target);
4558
+ log("\u5DE5\u4F5C\u76EE\u5F55\u5DF2\u53D8\u66F4\uFF0C\u79FB\u52A8\u672C\u673A\u526F\u672C\uFF1A" + mount.directory + " \u2192 " + target);
4559
+ try {
4560
+ fs14.renameSync(mount.directory, target);
4561
+ } catch (error) {
4562
+ if (error.code === "EXDEV")
4563
+ throw new Error("\u65B0\u7684\u5DE5\u4F5C\u76EE\u5F55\u4E0E\u65E7\u526F\u672C\u4E0D\u5728\u540C\u4E00\u78C1\u76D8\uFF0C\u65E0\u6CD5\u76F4\u63A5\u79FB\u52A8\uFF1B\u8BF7\u5148\u79FB\u9664\u672C\u673A\u526F\u672C\u540E\u91CD\u65B0\u6302\u8F7D");
4564
+ throw error;
4565
+ }
4566
+ const moved = {
4567
+ ...mount,
4568
+ managedRoot: root,
4569
+ directory: target,
4570
+ workspaceFile: path16.join(target, path16.basename(mount.workspaceFile))
4571
+ };
4572
+ for (const folder of workspaceFolders(moved)) {
4573
+ if (!folder) continue;
4574
+ await runGit(folder, ["worktree", "repair"]).catch(() => {
4575
+ });
4576
+ }
4577
+ return moved;
4578
+ }
4579
+ function workspaceFolders(mount) {
4580
+ try {
4581
+ const parsed = JSON.parse(fs14.readFileSync(mount.workspaceFile, "utf8"));
4582
+ return (parsed.folders ?? []).map((folder) => folder.path ? path16.resolve(mount.directory, folder.path) : "").filter((folder) => {
4583
+ if (!folder || !inside3(mount.directory, folder)) return false;
4584
+ try {
4585
+ return fs14.statSync(path16.join(folder, ".git")).isFile();
4586
+ } catch {
4587
+ return false;
4588
+ }
4589
+ });
4590
+ } catch {
4591
+ return [];
4592
+ }
4593
+ }
4594
+
4523
4595
  // src/jobs.ts
4524
4596
  var LocalJobs = class {
4525
4597
  constructor(store) {
@@ -4630,15 +4702,20 @@ var LocalJobs = class {
4630
4702
  job.state = "running";
4631
4703
  this.store.save();
4632
4704
  await gitExecution.run({ executable: state.git, signal: controller.signal }, async () => {
4633
- const root = fs14.realpathSync(state.root);
4705
+ const root = fs15.realpathSync(state.root);
4634
4706
  const definition = job.intent.definition;
4635
4707
  const mountKey = scopeKey(job.workbenchId, job.userId, definition.id);
4636
- const existingMount = state.mounts[mountKey];
4708
+ const recorded = state.mounts[mountKey];
4709
+ const existingMount = recorded && inside3(root, recorded.directory) ? recorded : recorded && fs15.existsSync(recorded.directory) ? await relocateMount({ root, mount: recorded, log }) : void 0;
4710
+ if (existingMount !== recorded && existingMount) {
4711
+ state.mounts[mountKey] = existingMount;
4712
+ this.store.save();
4713
+ }
4637
4714
  if (existingMount && definition.revision < existingMount.revision)
4638
4715
  throw new Error("\u4EFB\u52A1\u5B9A\u4E49\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u4F7F\u7528\u5F53\u524D\u5171\u4EAB\u5B9A\u4E49\u91CD\u65B0\u540C\u6B65");
4639
- const namespace = path16.join(root, ".cwm", job.workbenchId, job.userId);
4716
+ const namespace = path17.join(root, ".cwm", job.workbenchId, job.userId);
4640
4717
  checkedPath(root, namespace, false);
4641
- fs14.mkdirSync(namespace, { recursive: true });
4718
+ fs15.mkdirSync(namespace, { recursive: true });
4642
4719
  const prepared = [];
4643
4720
  for (const repo of definition.repositories) {
4644
4721
  controller.signal.throwIfAborted();
@@ -4646,9 +4723,9 @@ var LocalJobs = class {
4646
4723
  if (!source) {
4647
4724
  if (!/^(https:\/\/|ssh:\/\/|[\w.-]+@[\w.-]+:)/.test(repo.remoteUrl))
4648
4725
  throw new Error(`${repo.alias} \u7F3A\u5C11 HTTPS \u6216 SSH \u8FDC\u7A0B\u5730\u5740\uFF0C\u8BF7\u5148\u767B\u8BB0\u672C\u673A\u4ED3\u5E93`);
4649
- source = path16.join(namespace, repo.repositoryId);
4726
+ source = path17.join(namespace, repo.repositoryId);
4650
4727
  checkedPath(root, source, false);
4651
- if (!fs14.existsSync(source)) {
4728
+ if (!fs15.existsSync(source)) {
4652
4729
  const temporary = source + ".clone-" + randomUUID6();
4653
4730
  log("\u514B\u9686\u4ED3\u5E93\uFF1A" + repo.alias);
4654
4731
  try {
@@ -4657,17 +4734,17 @@ var LocalJobs = class {
4657
4734
  timeoutMs: 6e5
4658
4735
  });
4659
4736
  } catch (error) {
4660
- fs14.rmSync(temporary, { recursive: true, force: true });
4737
+ fs15.rmSync(temporary, { recursive: true, force: true });
4661
4738
  throw error;
4662
4739
  }
4663
- fs14.renameSync(temporary, source);
4740
+ fs15.renameSync(temporary, source);
4664
4741
  }
4665
4742
  if (await runGit(source, ["config", "--get", "remote.origin.url"]) !== repo.remoteUrl)
4666
4743
  throw new Error("\u4ED3\u5E93\u7F13\u5B58\u4E0E\u8FDC\u7A0B\u5730\u5740\u4E0D\u4E00\u81F4");
4667
4744
  state.repositories[scopeKey(job.workbenchId, job.userId, repo.repositoryId)] = source;
4668
4745
  this.store.save();
4669
4746
  }
4670
- if (!fs14.existsSync(source)) throw new Error("\u5DF2\u767B\u8BB0\u7684\u672C\u673A\u4ED3\u5E93\u4E0D\u5B58\u5728");
4747
+ if (!fs15.existsSync(source)) throw new Error("\u5DF2\u767B\u8BB0\u7684\u672C\u673A\u4ED3\u5E93\u4E0D\u5B58\u5728");
4671
4748
  if (repo.remoteUrl) {
4672
4749
  const configured = (await runGit(source, ["config", "--get", "remote.origin.url"])).replace(/(https?:\/\/)[^/@\s]+@/g, "$1");
4673
4750
  if (configured !== repo.remoteUrl)
@@ -4704,20 +4781,20 @@ var LocalJobs = class {
4704
4781
  subpath: repo.subpath
4705
4782
  });
4706
4783
  }
4707
- const destination = existingMount?.directory || path16.join(root, "cw-" + definition.slug);
4784
+ const destination = existingMount?.directory || path17.join(root, "cw-" + definition.slug);
4708
4785
  checkedPath(
4709
- existingMount ? path16.dirname(existingMount.directory) : root,
4786
+ existingMount ? path17.dirname(existingMount.directory) : root,
4710
4787
  destination,
4711
4788
  false
4712
4789
  );
4713
4790
  const key = scopeKey(job.workbenchId, job.userId, definition.id);
4714
- const marker = path16.join(destination, ".cwm-owner.json");
4715
- if (fs14.existsSync(destination)) {
4716
- if (!existingMount && !fs14.existsSync(marker) || fs14.existsSync(marker) && JSON.parse(fs14.readFileSync(marker, "utf8")).key !== key)
4791
+ const marker = path17.join(destination, ".cwm-owner.json");
4792
+ if (fs15.existsSync(destination)) {
4793
+ if (!existingMount && !fs15.existsSync(marker) || fs15.existsSync(marker) && JSON.parse(fs15.readFileSync(marker, "utf8")).key !== key)
4717
4794
  throw new Error("\u76EE\u5F55\u5DF2\u5B58\u5728\u4E14\u4E0D\u5C5E\u4E8E\u672C\u4EFB\u52A1\uFF0C\u8BF7\u5148\u5BFC\u5165\u6216\u66F4\u6362\u540D\u79F0");
4718
4795
  } else {
4719
- fs14.mkdirSync(destination);
4720
- fs14.writeFileSync(marker, JSON.stringify({ key }), { flag: "wx", mode: 384 });
4796
+ fs15.mkdirSync(destination);
4797
+ fs15.writeFileSync(marker, JSON.stringify({ key }), { flag: "wx", mode: 384 });
4721
4798
  }
4722
4799
  const result = existingMount ? await (async () => {
4723
4800
  localWorkspace(
@@ -4728,7 +4805,7 @@ var LocalJobs = class {
4728
4805
  checkedPath(existingMount.directory, existingMount.workspaceFile);
4729
4806
  await editLocalWorkspace({
4730
4807
  id: definition.id,
4731
- parent: path16.dirname(existingMount.directory),
4808
+ parent: path17.dirname(existingMount.directory),
4732
4809
  file: existingMount.workspaceFile,
4733
4810
  definition,
4734
4811
  sources: Object.fromEntries(
@@ -4750,7 +4827,7 @@ var LocalJobs = class {
4750
4827
  log
4751
4828
  );
4752
4829
  for (const repo of prepared) {
4753
- const document = JSON.parse(fs14.readFileSync(result.workspace, "utf8"));
4830
+ const document = JSON.parse(fs15.readFileSync(result.workspace, "utf8"));
4754
4831
  const folder = document.folders.find(
4755
4832
  (folder2) => folder2.name === repo.alias
4756
4833
  );
@@ -4758,7 +4835,7 @@ var LocalJobs = class {
4758
4835
  this.store,
4759
4836
  { workbenchId: job.workbenchId, userId: job.userId },
4760
4837
  definition.id
4761
- ).folders.find((item) => item.name === repo.alias).path : checkedPath(destination, path16.resolve(destination, folder.path));
4838
+ ).folders.find((item) => item.name === repo.alias).path : checkedPath(destination, path17.resolve(destination, folder.path));
4762
4839
  const branch = await runGit(directory, ["branch", "--show-current"]);
4763
4840
  if (branch !== repo.branch) throw new Error("\u672C\u673A\u5206\u652F\u6838\u9A8C\u5931\u8D25");
4764
4841
  await runGit(directory, ["rev-parse", "--verify", "HEAD"]);
@@ -4856,10 +4933,10 @@ async function fetchWorkbenchIdentity(origin) {
4856
4933
  import os8 from "node:os";
4857
4934
 
4858
4935
  // ../../packages/runtime/src/agent-sessions/service.ts
4859
- import path22 from "node:path";
4936
+ import path23 from "node:path";
4860
4937
 
4861
4938
  // ../../packages/runtime/src/agent-sessions/matching.ts
4862
- import path17 from "node:path";
4939
+ import path18 from "node:path";
4863
4940
  var SESSION_LIMIT = 40;
4864
4941
  function dedupeSessions(sessions) {
4865
4942
  const merged = /* @__PURE__ */ new Map();
@@ -4885,38 +4962,38 @@ function titleRank(title) {
4885
4962
  return 1;
4886
4963
  }
4887
4964
  function sessionMatches(cwd, scope) {
4888
- if (!cwd || !path17.isAbsolute(cwd)) return false;
4889
- const target = path17.resolve(cwd);
4965
+ if (!cwd || !path18.isAbsolute(cwd)) return false;
4966
+ const target = path18.resolve(cwd);
4890
4967
  if (sameOrInside(scope.containerDir, target)) return true;
4891
- if (scope.workspaceFile && path17.resolve(scope.workspaceFile) === target) return true;
4968
+ if (scope.workspaceFile && path18.resolve(scope.workspaceFile) === target) return true;
4892
4969
  return scope.mountPaths.some((mount) => Boolean(mount) && sameOrInside(mount, target));
4893
4970
  }
4894
4971
  function candidateDirectories(scope) {
4895
4972
  const values = [scope.containerDir, ...scope.mountPaths].filter(
4896
- (value) => value && path17.isAbsolute(value)
4973
+ (value) => value && path18.isAbsolute(value)
4897
4974
  );
4898
- return [...new Set(values.map((value) => path17.resolve(value)))];
4975
+ return [...new Set(values.map((value) => path18.resolve(value)))];
4899
4976
  }
4900
4977
  function sameOrInside(root, target) {
4901
- if (!root || !path17.isAbsolute(root)) return false;
4902
- const relative = path17.relative(path17.resolve(root), path17.resolve(target));
4903
- return relative === "" || !relative.startsWith("..") && !path17.isAbsolute(relative);
4978
+ if (!root || !path18.isAbsolute(root)) return false;
4979
+ const relative = path18.relative(path18.resolve(root), path18.resolve(target));
4980
+ return relative === "" || !relative.startsWith("..") && !path18.isAbsolute(relative);
4904
4981
  }
4905
4982
  function cursorSlug(directory) {
4906
- return path17.resolve(directory).split(path17.sep).filter(Boolean).join("-").replace(/:/g, "-");
4983
+ return path18.resolve(directory).split(path18.sep).filter(Boolean).join("-").replace(/:/g, "-");
4907
4984
  }
4908
4985
  function claudeSlug(directory) {
4909
- return path17.resolve(directory).split(path17.sep).join("-").replace(/:/g, "-");
4986
+ return path18.resolve(directory).split(path18.sep).join("-").replace(/:/g, "-");
4910
4987
  }
4911
4988
 
4912
4989
  // ../../packages/runtime/src/agent-sessions/providers/claude.ts
4913
- import fs16 from "node:fs";
4914
- import path19 from "node:path";
4990
+ import fs17 from "node:fs";
4991
+ import path20 from "node:path";
4915
4992
 
4916
4993
  // ../../packages/runtime/src/agent-sessions/storage.ts
4917
- import fs15 from "node:fs";
4994
+ import fs16 from "node:fs";
4918
4995
  import os7 from "node:os";
4919
- import path18 from "node:path";
4996
+ import path19 from "node:path";
4920
4997
  var PREFIX_BYTES = 65536;
4921
4998
  var TAIL_BYTES = 262144;
4922
4999
  function clipTitle(value) {
@@ -4925,23 +5002,23 @@ function clipTitle(value) {
4925
5002
  return text.length > 80 ? text.slice(0, 79) + "\u2026" : text;
4926
5003
  }
4927
5004
  function readPrefix(file, maxBytes = PREFIX_BYTES) {
4928
- const fd = fs15.openSync(file, "r");
5005
+ const fd = fs16.openSync(file, "r");
4929
5006
  try {
4930
5007
  const buffer = Buffer.alloc(maxBytes);
4931
- const size = fs15.readSync(fd, buffer, 0, maxBytes, 0);
5008
+ const size = fs16.readSync(fd, buffer, 0, maxBytes, 0);
4932
5009
  const text = buffer.subarray(0, size).toString("utf8");
4933
5010
  return size === maxBytes ? text.slice(0, text.lastIndexOf("\n")) : text;
4934
5011
  } finally {
4935
- fs15.closeSync(fd);
5012
+ fs16.closeSync(fd);
4936
5013
  }
4937
5014
  }
4938
5015
  function readTailRecords(file) {
4939
- const fd = fs15.openSync(file, "r");
5016
+ const fd = fs16.openSync(file, "r");
4940
5017
  try {
4941
- const size = fs15.fstatSync(fd).size;
5018
+ const size = fs16.fstatSync(fd).size;
4942
5019
  const start = Math.max(0, size - TAIL_BYTES);
4943
5020
  const buffer = Buffer.alloc(size - start);
4944
- const read = fs15.readSync(fd, buffer, 0, buffer.length, start);
5021
+ const read = fs16.readSync(fd, buffer, 0, buffer.length, start);
4945
5022
  const text = buffer.subarray(0, read).toString("utf8");
4946
5023
  const lines2 = text.split("\n");
4947
5024
  if (start > 0) lines2.shift();
@@ -4957,7 +5034,7 @@ function readTailRecords(file) {
4957
5034
  }
4958
5035
  return records;
4959
5036
  } finally {
4960
- fs15.closeSync(fd);
5037
+ fs16.closeSync(fd);
4961
5038
  }
4962
5039
  }
4963
5040
  function firstText(value, depth = 0) {
@@ -4995,17 +5072,17 @@ function parseFirstRecord(file) {
4995
5072
  }
4996
5073
  }
4997
5074
  function walkFiles(directory, include, depth) {
4998
- if (depth < 0 || !fs15.existsSync(directory)) return [];
5075
+ if (depth < 0 || !fs16.existsSync(directory)) return [];
4999
5076
  const files = [];
5000
- for (const entry of fs15.readdirSync(directory, { withFileTypes: true })) {
5001
- const target = path18.join(directory, entry.name);
5077
+ for (const entry of fs16.readdirSync(directory, { withFileTypes: true })) {
5078
+ const target = path19.join(directory, entry.name);
5002
5079
  if (entry.isDirectory()) files.push(...walkFiles(target, include, depth - 1));
5003
5080
  else if (include(entry.name)) files.push(target);
5004
5081
  }
5005
5082
  return files;
5006
5083
  }
5007
5084
  function agentStoragePaths(home, platform = process.platform, env = home === os7.homedir() ? process.env : {}) {
5008
- const paths = platform === "win32" ? path18.win32 : path18.posix;
5085
+ const paths = platform === "win32" ? path19.win32 : path19.posix;
5009
5086
  const cursorUser = platform === "darwin" ? paths.join(home, "Library", "Application Support", "Cursor", "User") : platform === "win32" ? paths.join(env.APPDATA || paths.join(home, "AppData", "Roaming"), "Cursor", "User") : paths.join(env.XDG_CONFIG_HOME || paths.join(home, ".config"), "Cursor", "User");
5010
5087
  return {
5011
5088
  cursorUser,
@@ -5086,13 +5163,13 @@ function listClaudeSessions(home, directories) {
5086
5163
  const sessions = [];
5087
5164
  for (const directory of directories) {
5088
5165
  const roots = [
5089
- .../* @__PURE__ */ new Set([claudeSlug(directory), path19.resolve(directory).replace(/[^A-Za-z0-9]/g, "-")])
5090
- ].map((slug) => path19.join(agentStoragePaths(home).claudeProjects, slug));
5166
+ .../* @__PURE__ */ new Set([claudeSlug(directory), path20.resolve(directory).replace(/[^A-Za-z0-9]/g, "-")])
5167
+ ].map((slug) => path20.join(agentStoragePaths(home).claudeProjects, slug));
5091
5168
  for (const root of roots) {
5092
- if (!fs16.existsSync(root)) continue;
5093
- for (const name of fs16.readdirSync(root)) {
5169
+ if (!fs17.existsSync(root)) continue;
5170
+ for (const name of fs17.readdirSync(root)) {
5094
5171
  if (!name.endsWith(".jsonl")) continue;
5095
- const file = path19.join(root, name);
5172
+ const file = path20.join(root, name);
5096
5173
  const record = claudeRecord(file, directory, name);
5097
5174
  if (record) sessions.push(record);
5098
5175
  }
@@ -5101,7 +5178,7 @@ function listClaudeSessions(home, directories) {
5101
5178
  return sessions;
5102
5179
  }
5103
5180
  function claudeRecord(file, directory, name) {
5104
- const stat2 = fs16.statSync(file);
5181
+ const stat2 = fs17.statSync(file);
5105
5182
  let cwd = directory;
5106
5183
  let title = "";
5107
5184
  let id = name.replace(/\.jsonl$/, "");
@@ -5130,11 +5207,11 @@ function claudeRecord(file, directory, name) {
5130
5207
  }
5131
5208
 
5132
5209
  // ../../packages/runtime/src/agent-sessions/providers/codex.ts
5133
- import fs17 from "node:fs";
5134
- import path20 from "node:path";
5210
+ import fs18 from "node:fs";
5211
+ import path21 from "node:path";
5135
5212
  function listCodexSessions(home, scope) {
5136
5213
  const root = agentStoragePaths(home).codexSessions;
5137
- if (!fs17.existsSync(root)) return [];
5214
+ if (!fs18.existsSync(root)) return [];
5138
5215
  const sessions = [];
5139
5216
  for (const file of walkFiles(
5140
5217
  root,
@@ -5158,7 +5235,7 @@ function codexRecord(file, scope) {
5158
5235
  }
5159
5236
  const cwd = meta.payload?.cwd || "";
5160
5237
  if (!sessionMatches(cwd, scope)) return void 0;
5161
- const stat2 = fs17.statSync(file);
5238
+ const stat2 = fs18.statSync(file);
5162
5239
  let title = meta.payload?.git?.branch || "";
5163
5240
  const titlePrefix = stat2.size > PREFIX_BYTES ? readPrefix(file, TAIL_BYTES) : prefix;
5164
5241
  for (const line of titlePrefix.split("\n").slice(1)) {
@@ -5185,7 +5262,7 @@ function codexRecord(file, scope) {
5185
5262
  }
5186
5263
  }
5187
5264
  return {
5188
- id: meta.payload?.session_id || meta.payload?.id || path20.basename(file),
5265
+ id: meta.payload?.session_id || meta.payload?.id || path21.basename(file),
5189
5266
  tool: "codex",
5190
5267
  title: clipTitle(title),
5191
5268
  cwd,
@@ -5195,17 +5272,17 @@ function codexRecord(file, scope) {
5195
5272
  }
5196
5273
 
5197
5274
  // ../../packages/runtime/src/agent-sessions/providers/cursor.ts
5198
- import fs19 from "node:fs";
5199
- import path21 from "node:path";
5275
+ import fs20 from "node:fs";
5276
+ import path22 from "node:path";
5200
5277
  import { fileURLToPath } from "node:url";
5201
5278
 
5202
5279
  // ../../packages/runtime/src/agent-sessions/sqlite-reader.ts
5203
- import fs18 from "node:fs";
5280
+ import fs19 from "node:fs";
5204
5281
  import { DatabaseSync } from "node:sqlite";
5205
5282
  var SqliteReader = class {
5206
5283
  database;
5207
5284
  constructor(file, _options) {
5208
- if (!fs18.existsSync(file)) throw new Error("\u4F1A\u8BDD\u6570\u636E\u5E93\u4E0D\u5B58\u5728");
5285
+ if (!fs19.existsSync(file)) throw new Error("\u4F1A\u8BDD\u6570\u636E\u5E93\u4E0D\u5B58\u5728");
5209
5286
  this.database = new DatabaseSync(file, { readOnly: true });
5210
5287
  }
5211
5288
  prepare(sql) {
@@ -5220,12 +5297,12 @@ var SqliteReader = class {
5220
5297
  function listCursorTranscripts(home, directories) {
5221
5298
  const sessions = [];
5222
5299
  for (const directory of directories) {
5223
- const root = path21.join(home, ".cursor", "projects", cursorSlug(directory), "agent-transcripts");
5224
- if (!fs19.existsSync(root)) continue;
5225
- for (const entry of fs19.readdirSync(root, { withFileTypes: true })) {
5226
- const file = entry.isDirectory() ? path21.join(root, entry.name, entry.name + ".jsonl") : path21.join(root, entry.name);
5227
- if (!file.endsWith(".jsonl") || !fs19.existsSync(file)) continue;
5228
- const stat2 = fs19.statSync(file);
5300
+ const root = path22.join(home, ".cursor", "projects", cursorSlug(directory), "agent-transcripts");
5301
+ if (!fs20.existsSync(root)) continue;
5302
+ for (const entry of fs20.readdirSync(root, { withFileTypes: true })) {
5303
+ const file = entry.isDirectory() ? path22.join(root, entry.name, entry.name + ".jsonl") : path22.join(root, entry.name);
5304
+ if (!file.endsWith(".jsonl") || !fs20.existsSync(file)) continue;
5305
+ const stat2 = fs20.statSync(file);
5229
5306
  const text = firstText(parseFirstRecord(file));
5230
5307
  sessions.push({
5231
5308
  id: entry.name.replace(/\.jsonl$/, ""),
@@ -5241,10 +5318,10 @@ function listCursorTranscripts(home, directories) {
5241
5318
  }
5242
5319
  function listCursorComposers(home, scope) {
5243
5320
  const root = agentStoragePaths(home).cursorUser;
5244
- const storage = path21.join(root, "workspaceStorage");
5245
- const databaseFile = path21.join(root, "globalStorage", "state.vscdb");
5321
+ const storage = path22.join(root, "workspaceStorage");
5322
+ const databaseFile = path22.join(root, "globalStorage", "state.vscdb");
5246
5323
  const workspaceIds = cursorWorkspaceIds(storage, scope);
5247
- if (!workspaceIds.length || !fs19.existsSync(databaseFile)) return [];
5324
+ if (!workspaceIds.length || !fs20.existsSync(databaseFile)) return [];
5248
5325
  try {
5249
5326
  const database = new SqliteReader(databaseFile, { readonly: true, fileMustExist: true });
5250
5327
  try {
@@ -5303,16 +5380,16 @@ function cursorStatus(database, id, header) {
5303
5380
  }
5304
5381
  }
5305
5382
  function cursorWorkspaceIds(storage, scope) {
5306
- if (!fs19.existsSync(storage)) return [];
5383
+ if (!fs20.existsSync(storage)) return [];
5307
5384
  const ids = [];
5308
- for (const entry of fs19.readdirSync(storage, { withFileTypes: true })) {
5385
+ for (const entry of fs20.readdirSync(storage, { withFileTypes: true })) {
5309
5386
  if (!entry.isDirectory()) continue;
5310
- const descriptor = path21.join(storage, entry.name, "workspace.json");
5311
- if (!fs19.existsSync(descriptor)) continue;
5387
+ const descriptor = path22.join(storage, entry.name, "workspace.json");
5388
+ if (!fs20.existsSync(descriptor)) continue;
5312
5389
  try {
5313
- const parsed = JSON.parse(fs19.readFileSync(descriptor, "utf8"));
5390
+ const parsed = JSON.parse(fs20.readFileSync(descriptor, "utf8"));
5314
5391
  const location = fileUriPath(parsed.workspace || "") || fileUriPath(parsed.folder || "");
5315
- if (location && (location === path21.resolve(scope.workspaceFile) || sessionMatches(location, scope)))
5392
+ if (location && (location === path22.resolve(scope.workspaceFile) || sessionMatches(location, scope)))
5316
5393
  ids.push(entry.name);
5317
5394
  } catch {
5318
5395
  }
@@ -5349,10 +5426,10 @@ function composerRecord(row, cwd) {
5349
5426
  }
5350
5427
 
5351
5428
  // ../../packages/runtime/src/agent-sessions/providers/opencode.ts
5352
- import fs20 from "node:fs";
5429
+ import fs21 from "node:fs";
5353
5430
  function listOpenCodeSessions(home, scope) {
5354
5431
  const databaseFile = agentStoragePaths(home).openCodeDatabase;
5355
- if (!fs20.existsSync(databaseFile)) return [];
5432
+ if (!fs21.existsSync(databaseFile)) return [];
5356
5433
  try {
5357
5434
  const database = new SqliteReader(databaseFile, { readonly: true, fileMustExist: true });
5358
5435
  try {
@@ -5401,7 +5478,7 @@ function agentSessionTarget(session) {
5401
5478
  if (session.tool === "claude")
5402
5479
  return CLAUDE_SESSION_ID.test(session.id) ? "claude://resume?session=" + encodeURIComponent(session.id) : void 0;
5403
5480
  if (session.tool === "codex") return "codex://threads/" + encodeURIComponent(session.id);
5404
- if (session.tool === "opencode" && path22.isAbsolute(session.cwd))
5481
+ if (session.tool === "opencode" && path23.isAbsolute(session.cwd))
5405
5482
  return "opencode://open-project?directory=" + encodeURIComponent(session.cwd);
5406
5483
  return void 0;
5407
5484
  }
@@ -5423,8 +5500,8 @@ function listAgentSessions(home, scope) {
5423
5500
  }
5424
5501
 
5425
5502
  // ../../packages/runtime/src/git/commits.ts
5426
- import fs21 from "node:fs";
5427
- import path23 from "node:path";
5503
+ import fs22 from "node:fs";
5504
+ import path24 from "node:path";
5428
5505
  var PAGE_SIZE = 20;
5429
5506
  var SYNC_INTERVAL_MS = 3e4;
5430
5507
  var comparisonSyncs = /* @__PURE__ */ new Map();
@@ -5445,8 +5522,8 @@ async function latestComparison(cwd, branch, force) {
5445
5522
  if (!(await git2(cwd, ["remote"])).split("\n").includes("origin"))
5446
5523
  return { unavailable: "\u4ED3\u5E93\u672A\u914D\u7F6E origin\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u6700\u65B0 " + branch };
5447
5524
  const remoteRef = "refs/remotes/origin/" + branch;
5448
- const common = fs21.realpathSync(
5449
- path23.resolve(cwd, await git2(cwd, ["rev-parse", "--git-common-dir"]))
5525
+ const common = fs22.realpathSync(
5526
+ path24.resolve(cwd, await git2(cwd, ["rev-parse", "--git-common-dir"]))
5450
5527
  );
5451
5528
  const key = common + "\0" + await git2(cwd, ["remote", "get-url", "origin"]) + "\0" + branch;
5452
5529
  const cached = comparisonSyncs.get(key);
@@ -5494,7 +5571,7 @@ async function readWorkspaceCommits(mount, offset = 0, refresh = false) {
5494
5571
  baseRef: "origin/" + (compareBranch || "production")
5495
5572
  };
5496
5573
  if (!compareBranch) return { ...empty, unavailable: "\u4ED3\u5E93 Commit \u5BF9\u6BD4\u5206\u652F\u914D\u7F6E\u65E0\u6548" };
5497
- if (!mount.folder_path || !fs21.existsSync(mount.folder_path))
5574
+ if (!mount.folder_path || !fs22.existsSync(mount.folder_path))
5498
5575
  return { ...empty, unavailable: "\u6302\u8F7D\u8DEF\u5F84\u4E0D\u5B58\u5728" };
5499
5576
  try {
5500
5577
  const head = await git2(mount.folder_path, ["rev-parse", "--verify", "HEAD^{commit}"]);
@@ -5557,20 +5634,20 @@ function registerQueryRoutes(app, store) {
5557
5634
  app.get("/v1/repositories", async (request) => {
5558
5635
  const grant = requestGrant(request);
5559
5636
  const prefix = scopeKey(grant.workbenchId, grant.userId, "");
5560
- return Object.entries(store.state.repositories).filter(([key]) => key.startsWith(prefix)).map(([key, path28]) => ({ id: key.slice(prefix.length), path: path28 }));
5637
+ return Object.entries(store.state.repositories).filter(([key]) => key.startsWith(prefix)).map(([key, path29]) => ({ id: key.slice(prefix.length), path: path29 }));
5561
5638
  });
5562
5639
  app.post("/v1/repositories/inspect", async (request) => {
5563
5640
  const body = request.body;
5564
- const path28 = body.path;
5565
- if (!path28 || !(await import("node:path")).default.isAbsolute(path28))
5641
+ const path29 = body.path;
5642
+ if (!path29 || !(await import("node:path")).default.isAbsolute(path29))
5566
5643
  throw new Error("\u8BF7\u9009\u62E9\u7EDD\u5BF9\u8DEF\u5F84");
5567
5644
  return git4(async () => ({
5568
- root: await runGit(path28, ["rev-parse", "--show-toplevel"]),
5569
- remoteUrl: (await runGit(path28, ["remote", "get-url", "origin"]).catch(() => "")).replace(
5645
+ root: await runGit(path29, ["rev-parse", "--show-toplevel"]),
5646
+ remoteUrl: (await runGit(path29, ["remote", "get-url", "origin"]).catch(() => "")).replace(
5570
5647
  /(https?:\/\/)[^/@\s]+@/gi,
5571
5648
  "$1"
5572
5649
  ),
5573
- branches: (await runGit(path28, [
5650
+ branches: (await runGit(path29, [
5574
5651
  "for-each-ref",
5575
5652
  "--format=%(refname:short)",
5576
5653
  "refs/heads",
@@ -5624,11 +5701,11 @@ function registerQueryRoutes(app, store) {
5624
5701
  }
5625
5702
 
5626
5703
  // src/review-route.ts
5627
- import path25 from "node:path";
5704
+ import path26 from "node:path";
5628
5705
 
5629
5706
  // ../../packages/runtime/src/reviews/audit.ts
5630
- import fs22 from "node:fs";
5631
- import path24 from "node:path";
5707
+ import fs23 from "node:fs";
5708
+ import path25 from "node:path";
5632
5709
 
5633
5710
  // ../../packages/runtime/src/reviews/branch-scope.ts
5634
5711
  var lines = (text) => text ? text.split("\n") : [];
@@ -5829,14 +5906,14 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
5829
5906
  const valid = (value) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(value) && !value.includes("..") && !value.endsWith("/");
5830
5907
  if (!valid(production) || !valid(staging) || production === staging)
5831
5908
  throw new Error("\u8BF7\u586B\u5199\u4E0D\u540C\u7684\u6709\u6548\u751F\u4EA7\u3001UAT \u5206\u652F\u540D");
5832
- fs22.mkdirSync(root, { recursive: true });
5909
+ fs23.mkdirSync(root, { recursive: true });
5833
5910
  const results = [], folders = [];
5834
5911
  const groups = [...new Set(includedMounts.map((mount) => mount.repository_id))];
5835
5912
  log("\u5BA1\u67E5\u4ED3\u5E93\u603B\u6570\uFF1A" + groups.length);
5836
5913
  excludedRepositories.forEach((repo) => log("\u5DF2\u6392\u9664\uFF1A" + repo.alias + "\uFF08" + repo.reason + "\uFF09"));
5837
5914
  for (const repositoryId of groups) {
5838
5915
  const entries = includedMounts.filter((entry) => entry.repository_id === repositoryId), repo = entries[0];
5839
- const directory = path24.join(root, repositoryId.replace(/[^a-zA-Z0-9_-]/g, "_"));
5916
+ const directory = path25.join(root, repositoryId.replace(/[^a-zA-Z0-9_-]/g, "_"));
5840
5917
  const result2 = {
5841
5918
  repositoryId,
5842
5919
  alias: repo.alias,
@@ -5852,10 +5929,10 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
5852
5929
  let remote = repo.remote_url?.trim() || "";
5853
5930
  let localOrigin = false;
5854
5931
  if (!remote) {
5855
- if (!repo.canonical_path || !fs22.existsSync(repo.canonical_path))
5932
+ if (!repo.canonical_path || !fs23.existsSync(repo.canonical_path))
5856
5933
  throw new Error("\u8BF7\u914D\u7F6E\u8FDC\u7A0B\u4ED3\u5E93\u5730\u5740\u6216\u6709\u6548\u672C\u5730\u6765\u6E90");
5857
5934
  remote = await git3(repo.canonical_path, ["config", "--get", "remote.origin.url"]);
5858
- localOrigin = path24.isAbsolute(remote) && fs22.existsSync(remote);
5935
+ localOrigin = path25.isAbsolute(remote) && fs23.existsSync(remote);
5859
5936
  }
5860
5937
  if (!localOrigin && !/^(https:\/\/|ssh:\/\/|[\w.-]+@[\w.-]+:)/.test(remote) || remote.includes("::") || /[\s\x00-\x1f]/.test(remote) || /https?:\/\/[^/]*@/.test(remote))
5861
5938
  throw new Error("\u8FDC\u7AEF\u5730\u5740\u65E0\u6548");
@@ -5917,11 +5994,11 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
5917
5994
  );
5918
5995
  const stale = false;
5919
5996
  const result = stale ? "STALE" : results.some((repo) => ["ERROR", "CONFLICT"].includes(repo.status)) ? "BLOCKED" : uncoveredRequirements.length || results.some((repo) => repo.status === "WARN") ? "WARN" : "PASS";
5920
- const workspaceFile = path24.join(
5997
+ const workspaceFile = path25.join(
5921
5998
  root,
5922
5999
  "version-" + initial.version.name.replace(/[^A-Za-z0-9._-]/g, "-") + ".code-workspace"
5923
6000
  );
5924
- fs22.writeFileSync(
6001
+ fs23.writeFileSync(
5925
6002
  workspaceFile,
5926
6003
  JSON.stringify(
5927
6004
  { folders, settings: { "codeWorkspace.description": "\u9694\u79BB\u5BA1\u67E5\u5FEB\u7167\uFF1B\u8BF7\u52FF\u7528\u4E8E\u53D1\u5E03\u63A8\u9001" } },
@@ -5944,8 +6021,8 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
5944
6021
  stale
5945
6022
  };
5946
6023
  const report = readableReport(snapshot, result, createdAt, runId);
5947
- fs22.writeFileSync(path24.join(root, "report.md"), report, { mode: 384 });
5948
- fs22.writeFileSync(path24.join(root, "snapshot.json"), JSON.stringify(snapshot, null, 2), {
6024
+ fs23.writeFileSync(path25.join(root, "report.md"), report, { mode: 384 });
6025
+ fs23.writeFileSync(path25.join(root, "snapshot.json"), JSON.stringify(snapshot, null, 2), {
5949
6026
  mode: 384
5950
6027
  });
5951
6028
  return { runId, result, report, workspaceFile, snapshot, createdAt };
@@ -5977,7 +6054,7 @@ function registerReviewRoute(app, store, jobs) {
5977
6054
  },
5978
6055
  (log) => auditLocalVersion(
5979
6056
  snapshot,
5980
- path25.join(store.directory, "reviews", body.id),
6057
+ path26.join(store.directory, "reviews", body.id),
5981
6058
  body.id,
5982
6059
  body.inputHash,
5983
6060
  body,
@@ -5990,25 +6067,25 @@ function registerReviewRoute(app, store, jobs) {
5990
6067
 
5991
6068
  // src/upgrade.ts
5992
6069
  import { spawn as spawn7 } from "node:child_process";
5993
- import fs23 from "node:fs";
5994
- import path26 from "node:path";
6070
+ import fs24 from "node:fs";
6071
+ import path27 from "node:path";
5995
6072
  function packageRoot(entry) {
5996
- let directory = path26.dirname(path26.resolve(entry));
6073
+ let directory = path27.dirname(path27.resolve(entry));
5997
6074
  for (let depth = 0; depth < 4; depth++) {
5998
- if (fs23.existsSync(path26.join(directory, "package.json"))) return directory;
5999
- directory = path26.dirname(directory);
6075
+ if (fs24.existsSync(path27.join(directory, "package.json"))) return directory;
6076
+ directory = path27.dirname(directory);
6000
6077
  }
6001
- return path26.dirname(path26.dirname(path26.resolve(entry)));
6078
+ return path27.dirname(path27.dirname(path27.resolve(entry)));
6002
6079
  }
6003
6080
  function isGlobalInstall(root, prefix) {
6004
6081
  if (!prefix) return false;
6005
- const relative = path26.relative(path26.resolve(prefix), path26.resolve(root));
6006
- return Boolean(relative) && !relative.startsWith("..") && !path26.isAbsolute(relative);
6082
+ const relative = path27.relative(path27.resolve(prefix), path27.resolve(root));
6083
+ return Boolean(relative) && !relative.startsWith("..") && !path27.isAbsolute(relative);
6007
6084
  }
6008
6085
  function looksGlobal(root) {
6009
- const modules = path26.dirname(path26.resolve(root));
6010
- if (path26.basename(modules) !== "node_modules") return false;
6011
- return !fs23.existsSync(path26.join(path26.dirname(modules), "package.json"));
6086
+ const modules = path27.dirname(path27.resolve(root));
6087
+ if (path27.basename(modules) !== "node_modules") return false;
6088
+ return !fs24.existsSync(path27.join(path27.dirname(modules), "package.json"));
6012
6089
  }
6013
6090
  function isNewer(candidate, current) {
6014
6091
  const parse = (value) => value.split("-")[0].split(".").map((part) => Number(part) || 0);
@@ -6029,10 +6106,10 @@ async function latestPublished() {
6029
6106
  if (!data.version) throw new Error("npm \u8FD4\u56DE\u7684\u7248\u672C\u4FE1\u606F\u65E0\u6548");
6030
6107
  return data.version;
6031
6108
  }
6032
- var statusFile = (store) => path26.join(store.directory, "upgrade.json");
6109
+ var statusFile = (store) => path27.join(store.directory, "upgrade.json");
6033
6110
  function readStatus(store) {
6034
6111
  try {
6035
- return JSON.parse(fs23.readFileSync(statusFile(store), "utf8"));
6112
+ return JSON.parse(fs24.readFileSync(statusFile(store), "utf8"));
6036
6113
  } catch {
6037
6114
  return void 0;
6038
6115
  }
@@ -6076,7 +6153,7 @@ function registerUpgradeRoutes(app, store, entry, options = {}) {
6076
6153
  return reply.code(502).send({ error: cause.message });
6077
6154
  }
6078
6155
  if (!isNewer(latest, ASSISTANT_VERSION)) return { latest, started: false };
6079
- fs23.writeFileSync(
6156
+ fs24.writeFileSync(
6080
6157
  statusFile(store),
6081
6158
  JSON.stringify({ target: latest, state: "running", startedAt: (/* @__PURE__ */ new Date()).toISOString() }),
6082
6159
  { mode: 384 }
@@ -6084,7 +6161,7 @@ function registerUpgradeRoutes(app, store, entry, options = {}) {
6084
6161
  const child = spawn7(
6085
6162
  process.execPath,
6086
6163
  [
6087
- path26.join(root, "scripts", "upgrade.mjs"),
6164
+ path27.join(root, "scripts", "upgrade.mjs"),
6088
6165
  "--version",
6089
6166
  latest,
6090
6167
  "--state-dir",
@@ -6118,7 +6195,7 @@ async function buildAssistant(store, options = {}, entry, upgrade = {}) {
6118
6195
  return;
6119
6196
  }
6120
6197
  const origin = request.headers.origin || "";
6121
- const path28 = request.url.split("?")[0];
6198
+ const path29 = request.url.split("?")[0];
6122
6199
  let workbench = store.state.workbenches[origin];
6123
6200
  if (!workbench && trustedOrigin(origin)) {
6124
6201
  try {
@@ -6141,7 +6218,7 @@ async function buildAssistant(store, options = {}, entry, upgrade = {}) {
6141
6218
  reply.header("Access-Control-Allow-Headers", "Authorization, Content-Type, X-CWM-Binding");
6142
6219
  return reply.code(204).send();
6143
6220
  }
6144
- if (path28 === "/v1/health" || path28 === "/v1/pairings") return;
6221
+ if (path29 === "/v1/health" || path29 === "/v1/pairings") return;
6145
6222
  try {
6146
6223
  const token = request.headers.authorization?.replace(/^Bearer /, "") || "";
6147
6224
  const grant = verifyGrant(token, workbench.publicKey);
@@ -6315,7 +6392,7 @@ async function cli(args, entry) {
6315
6392
  return;
6316
6393
  }
6317
6394
  const dirIndex = args.indexOf("--state-dir");
6318
- const directory = dirIndex >= 0 ? path27.resolve(args[dirIndex + 1]) : defaultStateDirectory();
6395
+ const directory = dirIndex >= 0 ? path28.resolve(args[dirIndex + 1]) : defaultStateDirectory();
6319
6396
  const command = args[0] || "status";
6320
6397
  const store = new StateStore(directory);
6321
6398
  const control = async (action) => {
@@ -6341,7 +6418,7 @@ async function cli(args, entry) {
6341
6418
  }
6342
6419
  if (store.state.autostart) await startAutostart();
6343
6420
  else {
6344
- const log = fs24.openSync(path27.join(directory, "assistant.log"), "a", 384);
6421
+ const log = fs25.openSync(path28.join(directory, "assistant.log"), "a", 384);
6345
6422
  const child = spawn8(process.execPath, [entry, "serve", "--state-dir", directory], {
6346
6423
  detached: true,
6347
6424
  windowsHide: true,
@@ -6351,7 +6428,7 @@ async function cli(args, entry) {
6351
6428
  cwd: directory
6352
6429
  });
6353
6430
  child.unref();
6354
- fs24.closeSync(log);
6431
+ fs25.closeSync(log);
6355
6432
  }
6356
6433
  const deadline = Date.now() + 1e4;
6357
6434
  while (Date.now() < deadline) {
@@ -6366,18 +6443,18 @@ async function cli(args, entry) {
6366
6443
  throw new Error("\u542F\u52A8\u5931\u8D25\uFF0C\u8BF7\u8FD0\u884C cwm-assistant logs \u68C0\u67E5\u7AEF\u53E3\u548C\u8FD0\u884C\u73AF\u5883");
6367
6444
  }
6368
6445
  if (command === "serve") {
6369
- const lock = path27.join(directory, "process.lock");
6370
- if (fs24.existsSync(lock)) {
6371
- const pid = Number(fs24.readFileSync(lock, "utf8"));
6446
+ const lock = path28.join(directory, "process.lock");
6447
+ if (fs25.existsSync(lock)) {
6448
+ const pid = Number(fs25.readFileSync(lock, "utf8"));
6372
6449
  try {
6373
6450
  process.kill(pid, 0);
6374
6451
  throw new Error("Workspace \u52A9\u624B\u5DF2\u8FD0\u884C");
6375
6452
  } catch (error) {
6376
6453
  if (error.code !== "ESRCH") throw error;
6377
- fs24.unlinkSync(lock);
6454
+ fs25.unlinkSync(lock);
6378
6455
  }
6379
6456
  }
6380
- fs24.writeFileSync(lock, String(process.pid), { flag: "wx", mode: 384 });
6457
+ fs25.writeFileSync(lock, String(process.pid), { flag: "wx", mode: 384 });
6381
6458
  store.reload();
6382
6459
  store.recover();
6383
6460
  const { app, jobs } = await buildAssistant(store, {}, entry);
@@ -6401,12 +6478,12 @@ async function cli(args, entry) {
6401
6478
  return reply.code(400).send({ error: "\u63A7\u5236\u64CD\u4F5C\u65E0\u6548" });
6402
6479
  });
6403
6480
  app.addHook("onClose", async () => {
6404
- fs24.rmSync(lock, { force: true });
6481
+ fs25.rmSync(lock, { force: true });
6405
6482
  });
6406
6483
  try {
6407
6484
  await app.listen({ host: "127.0.0.1", port: ASSISTANT_PORT });
6408
6485
  } catch (error) {
6409
- fs24.rmSync(lock, { force: true });
6486
+ fs25.rmSync(lock, { force: true });
6410
6487
  throw error;
6411
6488
  }
6412
6489
  for (const signal of ["SIGTERM", "SIGINT"])
@@ -6431,7 +6508,7 @@ async function cli(args, entry) {
6431
6508
  await control("stop").catch(() => {
6432
6509
  });
6433
6510
  const deadline = Date.now() + 1e4;
6434
- while (fs24.existsSync(path27.join(directory, "process.lock")) && Date.now() < deadline) {
6511
+ while (fs25.existsSync(path28.join(directory, "process.lock")) && Date.now() < deadline) {
6435
6512
  await new Promise((resolve) => setTimeout(resolve, 100));
6436
6513
  }
6437
6514
  }
@@ -6463,9 +6540,9 @@ async function cli(args, entry) {
6463
6540
  return;
6464
6541
  }
6465
6542
  if (command === "logs") {
6466
- const file = path27.join(directory, "assistant.log");
6543
+ const file = path28.join(directory, "assistant.log");
6467
6544
  console.log(
6468
- fs24.existsSync(file) ? fs24.readFileSync(file, "utf8").split("\n").slice(-100).join("\n") : "\u6682\u65E0\u65E5\u5FD7"
6545
+ fs25.existsSync(file) ? fs25.readFileSync(file, "utf8").split("\n").slice(-100).join("\n") : "\u6682\u65E0\u65E5\u5FD7"
6469
6546
  );
6470
6547
  return;
6471
6548
  }
@@ -6480,10 +6557,10 @@ async function cli(args, entry) {
6480
6557
  await control("stop").catch(() => {
6481
6558
  });
6482
6559
  const deadline = Date.now() + 1e4;
6483
- while (fs24.existsSync(path27.join(directory, "process.lock")) && Date.now() < deadline) {
6560
+ while (fs25.existsSync(path28.join(directory, "process.lock")) && Date.now() < deadline) {
6484
6561
  await new Promise((resolve) => setTimeout(resolve, 100));
6485
6562
  }
6486
- if (fs24.existsSync(path27.join(directory, "process.lock")))
6563
+ if (fs25.existsSync(path28.join(directory, "process.lock")))
6487
6564
  throw new Error("\u52A9\u624B\u5C1A\u672A\u505C\u6B62\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF1B\u672A\u4FEE\u6539\u672C\u5730\u72B6\u6001");
6488
6565
  }
6489
6566
  store.reload();
@@ -6518,11 +6595,11 @@ async function cli(args, entry) {
6518
6595
  {
6519
6596
  node: process.version,
6520
6597
  nodePath: process.execPath,
6521
- entryExists: fs24.existsSync(entry),
6598
+ entryExists: fs25.existsSync(entry),
6522
6599
  git: store.state.git,
6523
6600
  gitVersion,
6524
6601
  platform: process.platform,
6525
- rootExists: Boolean(store.state.root && fs24.existsSync(store.state.root)),
6602
+ rootExists: Boolean(store.state.root && fs25.existsSync(store.state.root)),
6526
6603
  configuredWorkbenches: Object.keys(store.state.workbenches),
6527
6604
  autostart: store.state.autostart,
6528
6605
  process: await control("status").catch(() => "\u672A\u8FD0\u884C")
@@ -6563,9 +6640,9 @@ async function cli(args, entry) {
6563
6640
  }
6564
6641
  }
6565
6642
  if (rootArg) {
6566
- if (!path27.isAbsolute(rootArg) || !fs24.statSync(rootArg).isDirectory())
6643
+ if (!path28.isAbsolute(rootArg) || !fs25.statSync(rootArg).isDirectory())
6567
6644
  throw new Error("\u5DE5\u4F5C\u76EE\u5F55\u5FC5\u987B\u662F\u5DF2\u5B58\u5728\u7684\u7EDD\u5BF9\u8DEF\u5F84");
6568
- store.state.root = fs24.realpathSync(rootArg);
6645
+ store.state.root = fs25.realpathSync(rootArg);
6569
6646
  }
6570
6647
  const auto = wantAutostart || !assumeYes && await ask("\u767B\u5F55\u7535\u8111\u65F6\u81EA\u52A8\u542F\u52A8\uFF1F[Y/n] ") !== "n";
6571
6648
  store.save();
@@ -6595,4 +6672,4 @@ async function cli(args, entry) {
6595
6672
  export {
6596
6673
  cli
6597
6674
  };
6598
- //# sourceMappingURL=cli-TPXAFK3D.js.map
6675
+ //# sourceMappingURL=cli-EWRIMGEP.js.map