cwm-assistant 0.3.10 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 fs25 from "node:fs";
9
+ import fs26 from "node:fs";
10
10
  import os9 from "node:os";
11
- import path28 from "node:path";
11
+ import path29 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.10";
2622
+ var ASSISTANT_VERSION = "0.3.12";
2623
2623
  var ASSISTANT_PORT = 46322;
2624
2624
 
2625
2625
  // ../../packages/contracts/src/index.ts
@@ -2913,15 +2913,18 @@ function removeLocalWorkspace(options) {
2913
2913
  const extraFiles = [];
2914
2914
  const warnings = [];
2915
2915
  const isFinderMetadata = (p) => path2.basename(p) === ".DS_Store" && fs2.lstatSync(p).isFile();
2916
- if (otherMounts.some((m) => {
2916
+ const blocking = otherMounts.filter((m) => {
2917
2917
  try {
2918
2918
  const p = fs2.realpathSync(m.folder_path);
2919
2919
  return p === root || inside(root, p);
2920
2920
  } catch {
2921
2921
  return false;
2922
2922
  }
2923
- }))
2924
- throw new Error("\u76EE\u5F55\u4ECD\u88AB\u5176\u4ED6 Workspace \u6302\u8F7D\uFF0C\u8BF7\u5148\u89E3\u9664\u5F15\u7528");
2923
+ });
2924
+ if (blocking.length)
2925
+ throw new Error(
2926
+ blocking.some((m) => m.workspaceId !== id) ? "\u76EE\u5F55\u4ECD\u88AB\u5176\u4ED6 Workspace \u6302\u8F7D\uFF0C\u8BF7\u5148\u89E3\u9664\u5F15\u7528" : "\u8BE5\u76EE\u5F55\u8FD8\u88AB\u540C\u4E00 Workspace \u5728\u5176\u4ED6\u8D26\u53F7\u4E0B\u7684\u672C\u673A\u526F\u672C\u5F15\u7528\uFF0C\u8BF7\u5148\u5207\u6362\u5230\u90A3\u4E2A\u8D26\u53F7\u79FB\u9664"
2927
+ );
2925
2928
  const inspect = (directory) => {
2926
2929
  for (const entry of fs2.readdirSync(directory, { withFileTypes: true })) {
2927
2930
  const p = path2.join(directory, entry.name);
@@ -3337,6 +3340,13 @@ function macApplication(name) {
3337
3340
  (candidate) => fs5.existsSync(candidate)
3338
3341
  ) || "";
3339
3342
  }
3343
+ function appBundleBinary(bundle, binary) {
3344
+ const candidate = path6.join(bundle, "Contents/Resources/app/bin", binary);
3345
+ return fs5.existsSync(candidate) ? candidate : "";
3346
+ }
3347
+ function macBundleBinary(app, binary) {
3348
+ return [path6.join("/Applications", app), path6.join(os3.homedir(), "Applications", app)].map((bundle) => appBundleBinary(bundle, binary)).find(Boolean) || "";
3349
+ }
3340
3350
  function detectToolCommands() {
3341
3351
  if (process.platform === "win32") {
3342
3352
  return {
@@ -3350,8 +3360,8 @@ function detectToolCommands() {
3350
3360
  };
3351
3361
  }
3352
3362
  return {
3353
- vscode: commandOnPath("code") || macApplication("Visual Studio Code.app"),
3354
- cursor: commandOnPath("cursor") || macApplication("Cursor.app"),
3363
+ vscode: commandOnPath("code") || macBundleBinary("Visual Studio Code.app", "code"),
3364
+ cursor: commandOnPath("cursor") || macBundleBinary("Cursor.app", "cursor"),
3355
3365
  idea: toolboxIdeaScript() || commandOnPath("idea") || macApplication("IntelliJ IDEA.app"),
3356
3366
  claude: commandOnPath("claude"),
3357
3367
  codex: commandOnPath("codex"),
@@ -3521,14 +3531,10 @@ function launchIde(workspaceFile, ide, configuredCommand = "", targetKind = "wor
3521
3531
  if (ide === "idea") return launchIntelliJIdea(workingDirectory, configuredCommand);
3522
3532
  const cursorLike = ide === "cursor" || ide === "cursor-agent";
3523
3533
  let command = configuredCommand || (ide === "codex" ? process.env.CWM_CODEX_PATH : cursorLike ? process.env.CWM_CURSOR_PATH : process.env.CWM_VSCODE_PATH) || "";
3534
+ const bundleBinary = cursorLike ? "cursor" : "code";
3535
+ if (command) command = appBundleBinary(command, bundleBinary) || command;
3524
3536
  if (!command && ide !== "codex" && process.platform === "darwin") {
3525
- const app = cursorLike ? "Cursor.app" : "Visual Studio Code.app";
3526
- const binary = cursorLike ? "cursor" : "code";
3527
- const candidates = [
3528
- path7.join("/Applications", app, "Contents/Resources/app/bin", binary),
3529
- path7.join(os4.homedir(), "Applications", app, "Contents/Resources/app/bin", binary)
3530
- ];
3531
- command = candidates.find((candidate) => fs6.existsSync(candidate)) || "";
3537
+ command = macBundleBinary(cursorLike ? "Cursor.app" : "Visual Studio Code.app", bundleBinary);
3532
3538
  }
3533
3539
  if (!command && process.platform === "win32" && (cursorLike || ide === "vscode" || ide === "codex")) {
3534
3540
  command = ide === "codex" ? windowsCodexExecutable() : windowsCliShim(cursorLike ? "cursor" : "vscode");
@@ -3984,6 +3990,21 @@ function localWorkspace(store, grant, id) {
3984
3990
 
3985
3991
  // src/routes.ts
3986
3992
  var requestGrant = (request) => request.assistantGrant;
3993
+ function mountedWorkspaces(store, root) {
3994
+ let base;
3995
+ try {
3996
+ base = fs11.realpathSync(root);
3997
+ } catch {
3998
+ return 0;
3999
+ }
4000
+ return Object.values(store.state.mounts).filter((mount) => {
4001
+ try {
4002
+ return inside3(base, fs11.realpathSync(mount.directory));
4003
+ } catch {
4004
+ return false;
4005
+ }
4006
+ }).length;
4007
+ }
3987
4008
  function registerLocalRoutes(app, store, options = {}) {
3988
4009
  const git4 = (fn) => gitExecution.run({ executable: store.state.git }, fn);
3989
4010
  app.get("/v1/capabilities", async () => {
@@ -4011,7 +4032,10 @@ function registerLocalRoutes(app, store, options = {}) {
4011
4032
  error,
4012
4033
  root: store.state.root,
4013
4034
  git: store.state.git,
4014
- tools: store.state.tools
4035
+ tools: store.state.tools,
4036
+ // The page greys out the directory field while any copy still lives under it, so the count
4037
+ // has to describe the saved root rather than whatever the user has typed into the form.
4038
+ mountedWorkspaces: mountedWorkspaces(store, store.state.root)
4015
4039
  };
4016
4040
  });
4017
4041
  app.get("/v1/settings", async () => ({
@@ -4027,7 +4051,16 @@ function registerLocalRoutes(app, store, options = {}) {
4027
4051
  if (!path12.isAbsolute(body.parentFolder) || !fs11.statSync(body.parentFolder).isDirectory())
4028
4052
  throw new Error("\u8BF7\u9009\u62E9\u672C\u673A\u5DF2\u5B58\u5728\u7684\u7EDD\u5BF9\u76EE\u5F55");
4029
4053
  fs11.accessSync(body.parentFolder, fs11.constants.W_OK);
4030
- root = fs11.realpathSync(body.parentFolder);
4054
+ const next = fs11.realpathSync(body.parentFolder);
4055
+ const mounted = next === fs11.realpathSync(root) ? 0 : mountedWorkspaces(store, root);
4056
+ if (mounted)
4057
+ throw Object.assign(
4058
+ new Error(
4059
+ `\u5F53\u524D\u76EE\u5F55\u4E0B\u8FD8\u6709 ${mounted} \u4E2A\u672C\u673A\u526F\u672C\uFF0C\u8BF7\u5148\u5728 Workspace \u9875\u9762\u79FB\u9664\u5B83\u4EEC\uFF0C\u518D\u66F4\u6362\u5DE5\u4F5C\u76EE\u5F55`
4060
+ ),
4061
+ { statusCode: 409 }
4062
+ );
4063
+ root = next;
4031
4064
  }
4032
4065
  if (body.git !== void 0) {
4033
4066
  if (body.git !== "git" && !path12.isAbsolute(body.git))
@@ -4147,9 +4180,12 @@ function registerDeleteRoute(app, store, jobs) {
4147
4180
  store,
4148
4181
  { ...grant, userId: mount.userId, workbenchId: mount.workbenchId },
4149
4182
  mount.workspaceId
4150
- ).folders.map((folder) => ({ folder_path: folder.path }));
4183
+ ).folders.map((folder) => ({
4184
+ folder_path: folder.path,
4185
+ workspaceId: mount.workspaceId
4186
+ }));
4151
4187
  } catch {
4152
- return [{ folder_path: mount.directory }];
4188
+ return [{ folder_path: mount.directory, workspaceId: mount.workspaceId }];
4153
4189
  }
4154
4190
  });
4155
4191
  const removalKey = scopeKey(grant.workbenchId, grant.userId, id);
@@ -4930,7 +4966,9 @@ async function fetchWorkbenchIdentity(origin) {
4930
4966
  }
4931
4967
 
4932
4968
  // src/query-routes.ts
4969
+ import fs23 from "node:fs";
4933
4970
  import os8 from "node:os";
4971
+ import path25 from "node:path";
4934
4972
 
4935
4973
  // ../../packages/runtime/src/agent-sessions/service.ts
4936
4974
  import path23 from "node:path";
@@ -5631,23 +5669,32 @@ async function readWorkspaceCommits(mount, offset = 0, refresh = false) {
5631
5669
  // src/query-routes.ts
5632
5670
  function registerQueryRoutes(app, store) {
5633
5671
  const git4 = (fn) => gitExecution.run({ executable: store.state.git }, fn);
5672
+ const cachePath = (root, target) => {
5673
+ let resolved = root;
5674
+ try {
5675
+ resolved = fs23.realpathSync(root);
5676
+ } catch {
5677
+ }
5678
+ return target.startsWith(path25.join(resolved, ".cwm") + path25.sep);
5679
+ };
5634
5680
  app.get("/v1/repositories", async (request) => {
5635
5681
  const grant = requestGrant(request);
5636
5682
  const prefix = scopeKey(grant.workbenchId, grant.userId, "");
5637
- return Object.entries(store.state.repositories).filter(([key]) => key.startsWith(prefix)).map(([key, path29]) => ({ id: key.slice(prefix.length), path: path29 }));
5683
+ const root = store.state.root;
5684
+ return Object.entries(store.state.repositories).filter(([key]) => key.startsWith(prefix)).map(([key, path30]) => ({ id: key.slice(prefix.length), path: path30 })).filter((entry) => !cachePath(root, entry.path));
5638
5685
  });
5639
5686
  app.post("/v1/repositories/inspect", async (request) => {
5640
5687
  const body = request.body;
5641
- const path29 = body.path;
5642
- if (!path29 || !(await import("node:path")).default.isAbsolute(path29))
5688
+ const path30 = body.path;
5689
+ if (!path30 || !(await import("node:path")).default.isAbsolute(path30))
5643
5690
  throw new Error("\u8BF7\u9009\u62E9\u7EDD\u5BF9\u8DEF\u5F84");
5644
5691
  return git4(async () => ({
5645
- root: await runGit(path29, ["rev-parse", "--show-toplevel"]),
5646
- remoteUrl: (await runGit(path29, ["remote", "get-url", "origin"]).catch(() => "")).replace(
5692
+ root: await runGit(path30, ["rev-parse", "--show-toplevel"]),
5693
+ remoteUrl: (await runGit(path30, ["remote", "get-url", "origin"]).catch(() => "")).replace(
5647
5694
  /(https?:\/\/)[^/@\s]+@/gi,
5648
5695
  "$1"
5649
5696
  ),
5650
- branches: (await runGit(path29, [
5697
+ branches: (await runGit(path30, [
5651
5698
  "for-each-ref",
5652
5699
  "--format=%(refname:short)",
5653
5700
  "refs/heads",
@@ -5701,11 +5748,11 @@ function registerQueryRoutes(app, store) {
5701
5748
  }
5702
5749
 
5703
5750
  // src/review-route.ts
5704
- import path26 from "node:path";
5751
+ import path27 from "node:path";
5705
5752
 
5706
5753
  // ../../packages/runtime/src/reviews/audit.ts
5707
- import fs23 from "node:fs";
5708
- import path25 from "node:path";
5754
+ import fs24 from "node:fs";
5755
+ import path26 from "node:path";
5709
5756
 
5710
5757
  // ../../packages/runtime/src/reviews/branch-scope.ts
5711
5758
  var lines = (text) => text ? text.split("\n") : [];
@@ -5906,14 +5953,14 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
5906
5953
  const valid = (value) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(value) && !value.includes("..") && !value.endsWith("/");
5907
5954
  if (!valid(production) || !valid(staging) || production === staging)
5908
5955
  throw new Error("\u8BF7\u586B\u5199\u4E0D\u540C\u7684\u6709\u6548\u751F\u4EA7\u3001UAT \u5206\u652F\u540D");
5909
- fs23.mkdirSync(root, { recursive: true });
5956
+ fs24.mkdirSync(root, { recursive: true });
5910
5957
  const results = [], folders = [];
5911
5958
  const groups = [...new Set(includedMounts.map((mount) => mount.repository_id))];
5912
5959
  log("\u5BA1\u67E5\u4ED3\u5E93\u603B\u6570\uFF1A" + groups.length);
5913
5960
  excludedRepositories.forEach((repo) => log("\u5DF2\u6392\u9664\uFF1A" + repo.alias + "\uFF08" + repo.reason + "\uFF09"));
5914
5961
  for (const repositoryId of groups) {
5915
5962
  const entries = includedMounts.filter((entry) => entry.repository_id === repositoryId), repo = entries[0];
5916
- const directory = path25.join(root, repositoryId.replace(/[^a-zA-Z0-9_-]/g, "_"));
5963
+ const directory = path26.join(root, repositoryId.replace(/[^a-zA-Z0-9_-]/g, "_"));
5917
5964
  const result2 = {
5918
5965
  repositoryId,
5919
5966
  alias: repo.alias,
@@ -5929,10 +5976,10 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
5929
5976
  let remote = repo.remote_url?.trim() || "";
5930
5977
  let localOrigin = false;
5931
5978
  if (!remote) {
5932
- if (!repo.canonical_path || !fs23.existsSync(repo.canonical_path))
5979
+ if (!repo.canonical_path || !fs24.existsSync(repo.canonical_path))
5933
5980
  throw new Error("\u8BF7\u914D\u7F6E\u8FDC\u7A0B\u4ED3\u5E93\u5730\u5740\u6216\u6709\u6548\u672C\u5730\u6765\u6E90");
5934
5981
  remote = await git3(repo.canonical_path, ["config", "--get", "remote.origin.url"]);
5935
- localOrigin = path25.isAbsolute(remote) && fs23.existsSync(remote);
5982
+ localOrigin = path26.isAbsolute(remote) && fs24.existsSync(remote);
5936
5983
  }
5937
5984
  if (!localOrigin && !/^(https:\/\/|ssh:\/\/|[\w.-]+@[\w.-]+:)/.test(remote) || remote.includes("::") || /[\s\x00-\x1f]/.test(remote) || /https?:\/\/[^/]*@/.test(remote))
5938
5985
  throw new Error("\u8FDC\u7AEF\u5730\u5740\u65E0\u6548");
@@ -5994,11 +6041,11 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
5994
6041
  );
5995
6042
  const stale = false;
5996
6043
  const result = stale ? "STALE" : results.some((repo) => ["ERROR", "CONFLICT"].includes(repo.status)) ? "BLOCKED" : uncoveredRequirements.length || results.some((repo) => repo.status === "WARN") ? "WARN" : "PASS";
5997
- const workspaceFile = path25.join(
6044
+ const workspaceFile = path26.join(
5998
6045
  root,
5999
6046
  "version-" + initial.version.name.replace(/[^A-Za-z0-9._-]/g, "-") + ".code-workspace"
6000
6047
  );
6001
- fs23.writeFileSync(
6048
+ fs24.writeFileSync(
6002
6049
  workspaceFile,
6003
6050
  JSON.stringify(
6004
6051
  { folders, settings: { "codeWorkspace.description": "\u9694\u79BB\u5BA1\u67E5\u5FEB\u7167\uFF1B\u8BF7\u52FF\u7528\u4E8E\u53D1\u5E03\u63A8\u9001" } },
@@ -6021,8 +6068,8 @@ async function auditLocalVersion(initial, root, runId, inputHash, body, log) {
6021
6068
  stale
6022
6069
  };
6023
6070
  const report = readableReport(snapshot, result, createdAt, runId);
6024
- fs23.writeFileSync(path25.join(root, "report.md"), report, { mode: 384 });
6025
- fs23.writeFileSync(path25.join(root, "snapshot.json"), JSON.stringify(snapshot, null, 2), {
6071
+ fs24.writeFileSync(path26.join(root, "report.md"), report, { mode: 384 });
6072
+ fs24.writeFileSync(path26.join(root, "snapshot.json"), JSON.stringify(snapshot, null, 2), {
6026
6073
  mode: 384
6027
6074
  });
6028
6075
  return { runId, result, report, workspaceFile, snapshot, createdAt };
@@ -6054,7 +6101,7 @@ function registerReviewRoute(app, store, jobs) {
6054
6101
  },
6055
6102
  (log) => auditLocalVersion(
6056
6103
  snapshot,
6057
- path26.join(store.directory, "reviews", body.id),
6104
+ path27.join(store.directory, "reviews", body.id),
6058
6105
  body.id,
6059
6106
  body.inputHash,
6060
6107
  body,
@@ -6067,25 +6114,25 @@ function registerReviewRoute(app, store, jobs) {
6067
6114
 
6068
6115
  // src/upgrade.ts
6069
6116
  import { spawn as spawn7 } from "node:child_process";
6070
- import fs24 from "node:fs";
6071
- import path27 from "node:path";
6117
+ import fs25 from "node:fs";
6118
+ import path28 from "node:path";
6072
6119
  function packageRoot(entry) {
6073
- let directory = path27.dirname(path27.resolve(entry));
6120
+ let directory = path28.dirname(path28.resolve(entry));
6074
6121
  for (let depth = 0; depth < 4; depth++) {
6075
- if (fs24.existsSync(path27.join(directory, "package.json"))) return directory;
6076
- directory = path27.dirname(directory);
6122
+ if (fs25.existsSync(path28.join(directory, "package.json"))) return directory;
6123
+ directory = path28.dirname(directory);
6077
6124
  }
6078
- return path27.dirname(path27.dirname(path27.resolve(entry)));
6125
+ return path28.dirname(path28.dirname(path28.resolve(entry)));
6079
6126
  }
6080
6127
  function isGlobalInstall(root, prefix) {
6081
6128
  if (!prefix) return false;
6082
- const relative = path27.relative(path27.resolve(prefix), path27.resolve(root));
6083
- return Boolean(relative) && !relative.startsWith("..") && !path27.isAbsolute(relative);
6129
+ const relative = path28.relative(path28.resolve(prefix), path28.resolve(root));
6130
+ return Boolean(relative) && !relative.startsWith("..") && !path28.isAbsolute(relative);
6084
6131
  }
6085
6132
  function looksGlobal(root) {
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"));
6133
+ const modules = path28.dirname(path28.resolve(root));
6134
+ if (path28.basename(modules) !== "node_modules") return false;
6135
+ return !fs25.existsSync(path28.join(path28.dirname(modules), "package.json"));
6089
6136
  }
6090
6137
  function isNewer(candidate, current) {
6091
6138
  const parse = (value) => value.split("-")[0].split(".").map((part) => Number(part) || 0);
@@ -6106,10 +6153,10 @@ async function latestPublished() {
6106
6153
  if (!data.version) throw new Error("npm \u8FD4\u56DE\u7684\u7248\u672C\u4FE1\u606F\u65E0\u6548");
6107
6154
  return data.version;
6108
6155
  }
6109
- var statusFile = (store) => path27.join(store.directory, "upgrade.json");
6156
+ var statusFile = (store) => path28.join(store.directory, "upgrade.json");
6110
6157
  function readStatus(store) {
6111
6158
  try {
6112
- return JSON.parse(fs24.readFileSync(statusFile(store), "utf8"));
6159
+ return JSON.parse(fs25.readFileSync(statusFile(store), "utf8"));
6113
6160
  } catch {
6114
6161
  return void 0;
6115
6162
  }
@@ -6153,7 +6200,7 @@ function registerUpgradeRoutes(app, store, entry, options = {}) {
6153
6200
  return reply.code(502).send({ error: cause.message });
6154
6201
  }
6155
6202
  if (!isNewer(latest, ASSISTANT_VERSION)) return { latest, started: false };
6156
- fs24.writeFileSync(
6203
+ fs25.writeFileSync(
6157
6204
  statusFile(store),
6158
6205
  JSON.stringify({ target: latest, state: "running", startedAt: (/* @__PURE__ */ new Date()).toISOString() }),
6159
6206
  { mode: 384 }
@@ -6161,7 +6208,7 @@ function registerUpgradeRoutes(app, store, entry, options = {}) {
6161
6208
  const child = spawn7(
6162
6209
  process.execPath,
6163
6210
  [
6164
- path27.join(root, "scripts", "upgrade.mjs"),
6211
+ path28.join(root, "scripts", "upgrade.mjs"),
6165
6212
  "--version",
6166
6213
  latest,
6167
6214
  "--state-dir",
@@ -6195,7 +6242,7 @@ async function buildAssistant(store, options = {}, entry, upgrade = {}) {
6195
6242
  return;
6196
6243
  }
6197
6244
  const origin = request.headers.origin || "";
6198
- const path29 = request.url.split("?")[0];
6245
+ const path30 = request.url.split("?")[0];
6199
6246
  let workbench = store.state.workbenches[origin];
6200
6247
  if (!workbench && trustedOrigin(origin)) {
6201
6248
  try {
@@ -6218,7 +6265,7 @@ async function buildAssistant(store, options = {}, entry, upgrade = {}) {
6218
6265
  reply.header("Access-Control-Allow-Headers", "Authorization, Content-Type, X-CWM-Binding");
6219
6266
  return reply.code(204).send();
6220
6267
  }
6221
- if (path29 === "/v1/health" || path29 === "/v1/pairings") return;
6268
+ if (path30 === "/v1/health" || path30 === "/v1/pairings") return;
6222
6269
  try {
6223
6270
  const token = request.headers.authorization?.replace(/^Bearer /, "") || "";
6224
6271
  const grant = verifyGrant(token, workbench.publicKey);
@@ -6392,7 +6439,7 @@ async function cli(args, entry) {
6392
6439
  return;
6393
6440
  }
6394
6441
  const dirIndex = args.indexOf("--state-dir");
6395
- const directory = dirIndex >= 0 ? path28.resolve(args[dirIndex + 1]) : defaultStateDirectory();
6442
+ const directory = dirIndex >= 0 ? path29.resolve(args[dirIndex + 1]) : defaultStateDirectory();
6396
6443
  const command = args[0] || "status";
6397
6444
  const store = new StateStore(directory);
6398
6445
  const control = async (action) => {
@@ -6418,7 +6465,7 @@ async function cli(args, entry) {
6418
6465
  }
6419
6466
  if (store.state.autostart) await startAutostart();
6420
6467
  else {
6421
- const log = fs25.openSync(path28.join(directory, "assistant.log"), "a", 384);
6468
+ const log = fs26.openSync(path29.join(directory, "assistant.log"), "a", 384);
6422
6469
  const child = spawn8(process.execPath, [entry, "serve", "--state-dir", directory], {
6423
6470
  detached: true,
6424
6471
  windowsHide: true,
@@ -6428,7 +6475,7 @@ async function cli(args, entry) {
6428
6475
  cwd: directory
6429
6476
  });
6430
6477
  child.unref();
6431
- fs25.closeSync(log);
6478
+ fs26.closeSync(log);
6432
6479
  }
6433
6480
  const deadline = Date.now() + 1e4;
6434
6481
  while (Date.now() < deadline) {
@@ -6443,18 +6490,18 @@ async function cli(args, entry) {
6443
6490
  throw new Error("\u542F\u52A8\u5931\u8D25\uFF0C\u8BF7\u8FD0\u884C cwm-assistant logs \u68C0\u67E5\u7AEF\u53E3\u548C\u8FD0\u884C\u73AF\u5883");
6444
6491
  }
6445
6492
  if (command === "serve") {
6446
- const lock = path28.join(directory, "process.lock");
6447
- if (fs25.existsSync(lock)) {
6448
- const pid = Number(fs25.readFileSync(lock, "utf8"));
6493
+ const lock = path29.join(directory, "process.lock");
6494
+ if (fs26.existsSync(lock)) {
6495
+ const pid = Number(fs26.readFileSync(lock, "utf8"));
6449
6496
  try {
6450
6497
  process.kill(pid, 0);
6451
6498
  throw new Error("Workspace \u52A9\u624B\u5DF2\u8FD0\u884C");
6452
6499
  } catch (error) {
6453
6500
  if (error.code !== "ESRCH") throw error;
6454
- fs25.unlinkSync(lock);
6501
+ fs26.unlinkSync(lock);
6455
6502
  }
6456
6503
  }
6457
- fs25.writeFileSync(lock, String(process.pid), { flag: "wx", mode: 384 });
6504
+ fs26.writeFileSync(lock, String(process.pid), { flag: "wx", mode: 384 });
6458
6505
  store.reload();
6459
6506
  store.recover();
6460
6507
  const { app, jobs } = await buildAssistant(store, {}, entry);
@@ -6478,12 +6525,12 @@ async function cli(args, entry) {
6478
6525
  return reply.code(400).send({ error: "\u63A7\u5236\u64CD\u4F5C\u65E0\u6548" });
6479
6526
  });
6480
6527
  app.addHook("onClose", async () => {
6481
- fs25.rmSync(lock, { force: true });
6528
+ fs26.rmSync(lock, { force: true });
6482
6529
  });
6483
6530
  try {
6484
6531
  await app.listen({ host: "127.0.0.1", port: ASSISTANT_PORT });
6485
6532
  } catch (error) {
6486
- fs25.rmSync(lock, { force: true });
6533
+ fs26.rmSync(lock, { force: true });
6487
6534
  throw error;
6488
6535
  }
6489
6536
  for (const signal of ["SIGTERM", "SIGINT"])
@@ -6508,7 +6555,7 @@ async function cli(args, entry) {
6508
6555
  await control("stop").catch(() => {
6509
6556
  });
6510
6557
  const deadline = Date.now() + 1e4;
6511
- while (fs25.existsSync(path28.join(directory, "process.lock")) && Date.now() < deadline) {
6558
+ while (fs26.existsSync(path29.join(directory, "process.lock")) && Date.now() < deadline) {
6512
6559
  await new Promise((resolve) => setTimeout(resolve, 100));
6513
6560
  }
6514
6561
  }
@@ -6540,9 +6587,9 @@ async function cli(args, entry) {
6540
6587
  return;
6541
6588
  }
6542
6589
  if (command === "logs") {
6543
- const file = path28.join(directory, "assistant.log");
6590
+ const file = path29.join(directory, "assistant.log");
6544
6591
  console.log(
6545
- fs25.existsSync(file) ? fs25.readFileSync(file, "utf8").split("\n").slice(-100).join("\n") : "\u6682\u65E0\u65E5\u5FD7"
6592
+ fs26.existsSync(file) ? fs26.readFileSync(file, "utf8").split("\n").slice(-100).join("\n") : "\u6682\u65E0\u65E5\u5FD7"
6546
6593
  );
6547
6594
  return;
6548
6595
  }
@@ -6557,10 +6604,10 @@ async function cli(args, entry) {
6557
6604
  await control("stop").catch(() => {
6558
6605
  });
6559
6606
  const deadline = Date.now() + 1e4;
6560
- while (fs25.existsSync(path28.join(directory, "process.lock")) && Date.now() < deadline) {
6607
+ while (fs26.existsSync(path29.join(directory, "process.lock")) && Date.now() < deadline) {
6561
6608
  await new Promise((resolve) => setTimeout(resolve, 100));
6562
6609
  }
6563
- if (fs25.existsSync(path28.join(directory, "process.lock")))
6610
+ if (fs26.existsSync(path29.join(directory, "process.lock")))
6564
6611
  throw new Error("\u52A9\u624B\u5C1A\u672A\u505C\u6B62\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF1B\u672A\u4FEE\u6539\u672C\u5730\u72B6\u6001");
6565
6612
  }
6566
6613
  store.reload();
@@ -6595,11 +6642,11 @@ async function cli(args, entry) {
6595
6642
  {
6596
6643
  node: process.version,
6597
6644
  nodePath: process.execPath,
6598
- entryExists: fs25.existsSync(entry),
6645
+ entryExists: fs26.existsSync(entry),
6599
6646
  git: store.state.git,
6600
6647
  gitVersion,
6601
6648
  platform: process.platform,
6602
- rootExists: Boolean(store.state.root && fs25.existsSync(store.state.root)),
6649
+ rootExists: Boolean(store.state.root && fs26.existsSync(store.state.root)),
6603
6650
  configuredWorkbenches: Object.keys(store.state.workbenches),
6604
6651
  autostart: store.state.autostart,
6605
6652
  process: await control("status").catch(() => "\u672A\u8FD0\u884C")
@@ -6640,9 +6687,9 @@ async function cli(args, entry) {
6640
6687
  }
6641
6688
  }
6642
6689
  if (rootArg) {
6643
- if (!path28.isAbsolute(rootArg) || !fs25.statSync(rootArg).isDirectory())
6690
+ if (!path29.isAbsolute(rootArg) || !fs26.statSync(rootArg).isDirectory())
6644
6691
  throw new Error("\u5DE5\u4F5C\u76EE\u5F55\u5FC5\u987B\u662F\u5DF2\u5B58\u5728\u7684\u7EDD\u5BF9\u8DEF\u5F84");
6645
- store.state.root = fs25.realpathSync(rootArg);
6692
+ store.state.root = fs26.realpathSync(rootArg);
6646
6693
  }
6647
6694
  const auto = wantAutostart || !assumeYes && await ask("\u767B\u5F55\u7535\u8111\u65F6\u81EA\u52A8\u542F\u52A8\uFF1F[Y/n] ") !== "n";
6648
6695
  store.save();
@@ -6672,4 +6719,4 @@ async function cli(args, entry) {
6672
6719
  export {
6673
6720
  cli
6674
6721
  };
6675
- //# sourceMappingURL=cli-EWRIMGEP.js.map
6722
+ //# sourceMappingURL=cli-33RDLVJY.js.map