@covro/covro 0.1.1-dev.7 → 0.1.1-dev.8

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.
@@ -101,10 +101,10 @@ var require_polyfills = __commonJS({
101
101
  if (platform === "win32") {
102
102
  fs.rename = typeof fs.rename !== "function" ? fs.rename : (function(fs$rename) {
103
103
  function rename4(from, to, cb) {
104
- var start = Date.now();
104
+ var start2 = Date.now();
105
105
  var backoff = 0;
106
106
  fs$rename(from, to, function CB(er) {
107
- if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
107
+ if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start2 < 6e4) {
108
108
  setTimeout(function() {
109
109
  fs.stat(to, function(stater, st) {
110
110
  if (stater && stater.code === "ENOENT")
@@ -542,8 +542,8 @@ var require_graceful_fs = __commonJS({
542
542
  }
543
543
  }
544
544
  var fs$writeFile = fs2.writeFile;
545
- fs2.writeFile = writeFile;
546
- function writeFile(path, data, options, cb) {
545
+ fs2.writeFile = writeFile2;
546
+ function writeFile2(path, data, options, cb) {
547
547
  if (typeof options === "function")
548
548
  cb = options, options = null;
549
549
  return go$writeFile(path, data, options, cb);
@@ -1108,7 +1108,7 @@ var require_signal_exit = __commonJS({
1108
1108
  };
1109
1109
  }
1110
1110
  assert2.equal(typeof cb, "function", "a callback must be provided for exit handler");
1111
- if (loaded === false) {
1111
+ if (loaded2 === false) {
1112
1112
  load();
1113
1113
  }
1114
1114
  var ev = "exit";
@@ -1125,10 +1125,10 @@ var require_signal_exit = __commonJS({
1125
1125
  return remove;
1126
1126
  };
1127
1127
  unload = function unload2() {
1128
- if (!loaded || !processOk(global.process)) {
1128
+ if (!loaded2 || !processOk(global.process)) {
1129
1129
  return;
1130
1130
  }
1131
- loaded = false;
1131
+ loaded2 = false;
1132
1132
  signals.forEach(function(sig) {
1133
1133
  try {
1134
1134
  process2.removeListener(sig, sigListeners[sig]);
@@ -1168,12 +1168,12 @@ var require_signal_exit = __commonJS({
1168
1168
  module2.exports.signals = function() {
1169
1169
  return signals;
1170
1170
  };
1171
- loaded = false;
1171
+ loaded2 = false;
1172
1172
  load = function load2() {
1173
- if (loaded || !processOk(global.process)) {
1173
+ if (loaded2 || !processOk(global.process)) {
1174
1174
  return;
1175
1175
  }
1176
- loaded = true;
1176
+ loaded2 = true;
1177
1177
  emitter.count += 1;
1178
1178
  signals = signals.filter(function(sig) {
1179
1179
  try {
@@ -1221,7 +1221,7 @@ var require_signal_exit = __commonJS({
1221
1221
  var unload;
1222
1222
  var emit;
1223
1223
  var sigListeners;
1224
- var loaded;
1224
+ var loaded2;
1225
1225
  var load;
1226
1226
  var originalProcessReallyExit;
1227
1227
  var processReallyExit;
@@ -1578,27 +1578,27 @@ var require_adapter = __commonJS({
1578
1578
  var require_proper_lockfile = __commonJS({
1579
1579
  "node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/index.js"(exports2, module2) {
1580
1580
  "use strict";
1581
- var lockfile3 = require_lockfile();
1581
+ var lockfile4 = require_lockfile();
1582
1582
  var { toPromise, toSync, toSyncOptions } = require_adapter();
1583
1583
  async function lock(file2, options) {
1584
- const release = await toPromise(lockfile3.lock)(file2, options);
1584
+ const release = await toPromise(lockfile4.lock)(file2, options);
1585
1585
  return toPromise(release);
1586
1586
  }
1587
1587
  function lockSync(file2, options) {
1588
- const release = toSync(lockfile3.lock)(file2, toSyncOptions(options));
1588
+ const release = toSync(lockfile4.lock)(file2, toSyncOptions(options));
1589
1589
  return toSync(release);
1590
1590
  }
1591
1591
  function unlock(file2, options) {
1592
- return toPromise(lockfile3.unlock)(file2, options);
1592
+ return toPromise(lockfile4.unlock)(file2, options);
1593
1593
  }
1594
1594
  function unlockSync(file2, options) {
1595
- return toSync(lockfile3.unlock)(file2, toSyncOptions(options));
1595
+ return toSync(lockfile4.unlock)(file2, toSyncOptions(options));
1596
1596
  }
1597
1597
  function check2(file2, options) {
1598
- return toPromise(lockfile3.check)(file2, options);
1598
+ return toPromise(lockfile4.check)(file2, options);
1599
1599
  }
1600
1600
  function checkSync(file2, options) {
1601
- return toSync(lockfile3.check)(file2, toSyncOptions(options));
1601
+ return toSync(lockfile4.check)(file2, toSyncOptions(options));
1602
1602
  }
1603
1603
  module2.exports = lock;
1604
1604
  module2.exports.lock = lock;
@@ -2323,9 +2323,9 @@ function nullish(input2) {
2323
2323
  return input2 === null || input2 === void 0;
2324
2324
  }
2325
2325
  function cleanRegex(source) {
2326
- const start = source.startsWith("^") ? 1 : 0;
2326
+ const start2 = source.startsWith("^") ? 1 : 0;
2327
2327
  const end = source.endsWith("$") ? source.length - 1 : source.length;
2328
- return source.slice(start, end);
2328
+ return source.slice(start2, end);
2329
2329
  }
2330
2330
  function floatSafeRemainder(val, step) {
2331
2331
  const ratio = val / step;
@@ -2796,9 +2796,9 @@ function sizeCaps(defChecks) {
2796
2796
  }
2797
2797
  return caps;
2798
2798
  }
2799
- function attachSchema(issues, start, inst) {
2799
+ function attachSchema(issues, start2, inst) {
2800
2800
  var _a3;
2801
- for (let i = start; i < issues.length; i++) {
2801
+ for (let i = start2; i < issues.length; i++) {
2802
2802
  (_a3 = issues[i]).schema ?? (_a3.schema = inst);
2803
2803
  }
2804
2804
  }
@@ -4983,10 +4983,10 @@ function capSize(inst, size) {
4983
4983
  if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
4984
4984
  for (const [max, ch] of sizeCaps(inst._zod.def.checks)) {
4985
4985
  if (n > max && ch._zod.def.when(payload)) {
4986
- const start = payload.issues.length;
4986
+ const start2 = payload.issues.length;
4987
4987
  ch._zod.check(payload);
4988
- payload.issues[start].continue = false;
4989
- attachSchema(payload.issues, start, inst);
4988
+ payload.issues[start2].continue = false;
4989
+ attachSchema(payload.issues, start2, inst);
4990
4990
  return payload;
4991
4991
  }
4992
4992
  }
@@ -21390,17 +21390,15 @@ function requireCodexCompatibility(metadata, running, confirmed = false) {
21390
21390
  }
21391
21391
 
21392
21392
  // src/updates/worker.ts
21393
- var import_node_child_process2 = require("node:child_process");
21394
- var import_node_util2 = require("node:util");
21393
+ var import_node_child_process4 = require("node:child_process");
21394
+ var import_node_util4 = require("node:util");
21395
21395
  var import_node_module = require("node:module");
21396
- var import_node_crypto2 = require("node:crypto");
21397
- var import_promises5 = require("node:fs/promises");
21396
+ var import_node_crypto4 = require("node:crypto");
21397
+ var import_promises9 = require("node:fs/promises");
21398
21398
  var import_node_fs2 = require("node:fs");
21399
- var import_node_path4 = require("node:path");
21400
- var import_promises6 = require("node:timers/promises");
21401
- var import_node_child_process3 = require("node:child_process");
21402
- var import_node_os = require("node:os");
21403
- var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
21399
+ var import_node_path7 = require("node:path");
21400
+ var import_promises10 = require("node:timers/promises");
21401
+ var import_proper_lockfile3 = __toESM(require_proper_lockfile(), 1);
21404
21402
 
21405
21403
  // src/cli/control.ts
21406
21404
  var import_node_http = require("node:http");
@@ -21464,23 +21462,121 @@ async function stopAndWait(location) {
21464
21462
  throw new Error("Covro \u5C1A\u672A\u5B8C\u6210\u5173\u95ED\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
21465
21463
  }
21466
21464
 
21467
- // src/updates/files.ts
21465
+ // src/cli/background.ts
21466
+ var import_node_child_process2 = require("node:child_process");
21467
+ var import_promises5 = require("node:fs/promises");
21468
+ var import_node_path4 = require("node:path");
21469
+ var import_node_util2 = require("node:util");
21470
+ var import_promises6 = require("node:timers/promises");
21471
+ var import_proper_lockfile2 = __toESM(require_proper_lockfile(), 1);
21472
+
21473
+ // src/cli/launchd.ts
21474
+ var import_node_child_process = require("node:child_process");
21475
+ var import_node_util = require("node:util");
21476
+ var import_node_crypto3 = require("node:crypto");
21477
+ var import_node_os = require("node:os");
21478
+ var import_node_path3 = require("node:path");
21479
+ var import_promises4 = require("node:fs/promises");
21480
+
21481
+ // src/cli/launch-environment.ts
21482
+ var import_node_net = require("node:net");
21483
+ var import_promises2 = require("node:fs/promises");
21468
21484
  var import_node_crypto = require("node:crypto");
21469
21485
  var import_node_path = require("node:path");
21470
- var import_promises2 = require("node:fs/promises");
21486
+ async function environmentBridge(home) {
21487
+ const path = (0, import_node_path.join)(home, `e-${(0, import_node_crypto.randomBytes)(6).toString("hex")}.sock`);
21488
+ const clients = /* @__PURE__ */ new Set();
21489
+ let accept;
21490
+ const consumed = new Promise((resolve) => {
21491
+ accept = resolve;
21492
+ });
21493
+ const payload = JSON.stringify({ env: { ...process.env, COVRO_HOME: home }, cwd: process.cwd() });
21494
+ const server = (0, import_node_net.createServer)((socket) => {
21495
+ clients.add(socket);
21496
+ socket.setTimeout(5e3, () => socket.destroy());
21497
+ socket.on("error", () => {
21498
+ });
21499
+ socket.on("close", () => clients.delete(socket));
21500
+ socket.end(payload, () => accept?.());
21501
+ });
21502
+ try {
21503
+ await new Promise((resolve, reject) => {
21504
+ server.once("error", reject);
21505
+ server.listen(path, resolve);
21506
+ });
21507
+ await (0, import_promises2.chmod)(path, 384);
21508
+ return {
21509
+ path,
21510
+ async wait() {
21511
+ let timer;
21512
+ try {
21513
+ await Promise.race([
21514
+ consumed,
21515
+ new Promise((_, reject) => {
21516
+ timer = setTimeout(
21517
+ () => reject(new Error("launchd \u542F\u52A8\u73AF\u5883\u4F20\u9012\u8D85\u65F6\uFF0C\u8BF7\u67E5\u770B Covro \u65E5\u5FD7")),
21518
+ 1e4
21519
+ );
21520
+ })
21521
+ ]);
21522
+ } finally {
21523
+ clearTimeout(timer);
21524
+ }
21525
+ },
21526
+ async close() {
21527
+ for (const socket of clients) socket.destroy();
21528
+ await new Promise(
21529
+ (resolve, reject) => server.close((error62) => error62 ? reject(error62) : resolve())
21530
+ );
21531
+ await (0, import_promises2.rm)(path, { force: true });
21532
+ }
21533
+ };
21534
+ } catch (error62) {
21535
+ server.close();
21536
+ await (0, import_promises2.rm)(path, { force: true });
21537
+ throw error62;
21538
+ }
21539
+ }
21540
+ var launchRunner = `import { connect } from 'node:net';
21541
+ const [socketPath, entry, config] = process.argv.slice(2);
21542
+ try {
21543
+ const input = await new Promise((resolve, reject) => {
21544
+ const socket = connect(socketPath);
21545
+ let body = '';
21546
+ socket.setTimeout(10000, () => socket.destroy(new Error('launch environment timed out')));
21547
+ socket.setEncoding('utf8');
21548
+ socket.on('data', chunk => {
21549
+ body += chunk;
21550
+ if (Buffer.byteLength(body) > 2 * 1024 * 1024) socket.destroy(new Error('launch environment too large'));
21551
+ });
21552
+ socket.on('error', reject);
21553
+ socket.on('end', () => { try { resolve(JSON.parse(body)); } catch { reject(new Error('invalid launch environment')); } });
21554
+ });
21555
+ process.chdir(input.cwd);
21556
+ process.execve(process.execPath, [process.execPath, entry, 'run', '--config', config], input.env);
21557
+ } catch {
21558
+ console.error('Covro launch environment unavailable; restart with covro start.');
21559
+ process.exitCode = 1;
21560
+ }
21561
+ `;
21562
+
21563
+ // src/updates/files.ts
21564
+ var import_node_crypto2 = require("node:crypto");
21565
+ var import_node_path2 = require("node:path");
21566
+ var import_promises3 = require("node:fs/promises");
21471
21567
  async function readJson(filename) {
21472
21568
  try {
21473
- return JSON.parse(await (0, import_promises2.readFile)(filename, "utf8"));
21569
+ return JSON.parse(await (0, import_promises3.readFile)(filename, "utf8"));
21474
21570
  } catch (error62) {
21475
21571
  if (error62.code === "ENOENT") return void 0;
21476
21572
  throw error62;
21477
21573
  }
21478
21574
  }
21479
21575
  async function saveJson(filename, value) {
21480
- await (0, import_promises2.mkdir)((0, import_node_path.dirname)(filename), { recursive: true, mode: 448 });
21481
- const temporary = `${filename}.${(0, import_node_crypto.randomUUID)()}.tmp`;
21576
+ await (0, import_promises3.mkdir)((0, import_node_path2.dirname)(filename), { recursive: true, mode: 448 });
21577
+ const temporary = `${filename}.${(0, import_node_crypto2.randomUUID)()}.tmp`;
21482
21578
  try {
21483
- const file2 = await (0, import_promises2.open)(temporary, "wx", 384);
21579
+ const file2 = await (0, import_promises3.open)(temporary, "wx", 384);
21484
21580
  try {
21485
21581
  await file2.writeFile(`${JSON.stringify(value, null, 2)}
21486
21582
  `);
@@ -21488,15 +21584,15 @@ async function saveJson(filename, value) {
21488
21584
  } finally {
21489
21585
  await file2.close();
21490
21586
  }
21491
- await (0, import_promises2.rename)(temporary, filename);
21492
- await syncDirectory((0, import_node_path.dirname)(filename));
21587
+ await (0, import_promises3.rename)(temporary, filename);
21588
+ await syncDirectory((0, import_node_path2.dirname)(filename));
21493
21589
  } finally {
21494
- await (0, import_promises2.rm)(temporary, { force: true });
21590
+ await (0, import_promises3.rm)(temporary, { force: true });
21495
21591
  }
21496
21592
  }
21497
21593
  async function syncDirectory(directory) {
21498
21594
  if (process.platform === "win32") return;
21499
- const handle = await (0, import_promises2.open)(directory, "r");
21595
+ const handle = await (0, import_promises3.open)(directory, "r");
21500
21596
  try {
21501
21597
  await handle.sync();
21502
21598
  } finally {
@@ -21504,20 +21600,228 @@ async function syncDirectory(directory) {
21504
21600
  }
21505
21601
  }
21506
21602
  async function copyDurable(source, target) {
21507
- await (0, import_promises2.cp)(source, target);
21508
- const file2 = await (0, import_promises2.open)(target, "r");
21603
+ await (0, import_promises3.cp)(source, target);
21604
+ const file2 = await (0, import_promises3.open)(target, "r");
21509
21605
  try {
21510
21606
  await file2.sync();
21511
21607
  } finally {
21512
21608
  await file2.close();
21513
21609
  }
21514
- await syncDirectory((0, import_node_path.dirname)(target));
21610
+ await syncDirectory((0, import_node_path2.dirname)(target));
21515
21611
  }
21516
21612
 
21613
+ // src/cli/launchd.ts
21614
+ var exec = (0, import_node_util.promisify)(import_node_child_process.execFile);
21615
+ var launchctl = (args) => exec("/bin/launchctl", args, { timeout: 5e3, maxBuffer: 2 * 1024 * 1024 });
21616
+ var xml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
21617
+ function failureDetail(error62) {
21618
+ const failure2 = error62;
21619
+ if (failure2.killed) return "launchctl \u8BF7\u6C42\u8D85\u65F6";
21620
+ return (failure2.stderr?.trim() || (error62 instanceof Error ? error62.message : "\u672A\u77E5\u9519\u8BEF")).slice(
21621
+ 0,
21622
+ 1024
21623
+ );
21624
+ }
21625
+ function launchdPaths(location, label = `dev.covro.${location.key}.${(0, import_node_crypto3.createHash)("sha256").update(location.home).digest("hex").slice(0, 12)}`) {
21626
+ const domain2 = `gui/${process.getuid()}`;
21627
+ return {
21628
+ label,
21629
+ domain: domain2,
21630
+ target: `${domain2}/${label}`,
21631
+ temporary: (0, import_node_path3.join)(location.state, "launchd.plist"),
21632
+ login: (0, import_node_path3.join)((0, import_node_os.homedir)(), "Library/LaunchAgents", `${label}.plist`)
21633
+ };
21634
+ }
21635
+ async function loaded(target) {
21636
+ try {
21637
+ await launchctl(["print", target]);
21638
+ return true;
21639
+ } catch (error62) {
21640
+ const stderr = error62.stderr ?? "";
21641
+ if (/Could not find (?:domain|service|specified service)/i.test(stderr)) return false;
21642
+ throw new Error(
21643
+ `\u65E0\u6CD5\u67E5\u8BE2 launchd ${target}\uFF1A${failureDetail(error62)}\uFF1B\u8BF7\u68C0\u67E5\u5F53\u524D\u7528\u6237\u7684 launchd \u6743\u9650`,
21644
+ { cause: error62 }
21645
+ );
21646
+ }
21647
+ }
21648
+ async function guiSessionAvailable(location) {
21649
+ return loaded(launchdPaths(location).domain);
21650
+ }
21651
+ async function loginRegistration(location) {
21652
+ const installed = await readJson(
21653
+ (0, import_node_path3.join)(location.state, "service.json")
21654
+ );
21655
+ if (installed?.platform !== "darwin") return void 0;
21656
+ if (installed.label !== launchdPaths(location).label && installed.label !== `dev.covro.${location.key}`)
21657
+ throw new Error("\u767B\u5F55\u670D\u52A1\u8EAB\u4EFD\u4E0E\u5F53\u524D\u914D\u7F6E\u4E0D\u5339\u914D");
21658
+ return installed;
21659
+ }
21660
+ function launchdPlist(location, args, login) {
21661
+ const { label } = launchdPaths(location, login ? `dev.covro.${location.key}` : void 0);
21662
+ const environment = {
21663
+ PATH: process.env.PATH ?? "/usr/bin:/bin",
21664
+ COVRO_HOME: location.home,
21665
+ ...process.env.CODEX_HOME ? { CODEX_HOME: process.env.CODEX_HOME } : {}
21666
+ };
21667
+ return `<?xml version="1.0" encoding="UTF-8"?>
21668
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
21669
+ <plist version="1.0"><dict>
21670
+ <key>Label</key><string>${label}</string>
21671
+ <key>ProgramArguments</key><array>${args.map((arg) => `<string>${xml(arg)}</string>`).join("")}</array>
21672
+ <key>LimitLoadToSessionType</key><string>Aqua</string>
21673
+ <key>RunAtLoad</key><true/>
21674
+ ${login ? "<key>KeepAlive</key><dict><key>SuccessfulExit</key><false/></dict><key>ThrottleInterval</key><integer>30</integer>" : ""}
21675
+ <key>EnvironmentVariables</key><dict>${Object.entries(environment).map(([key, value]) => `<key>${key}</key><string>${xml(value)}</string>`).join("")}</dict>
21676
+ <key>StandardOutPath</key><string>${xml(location.log)}</string>
21677
+ <key>StandardErrorPath</key><string>${xml(location.log)}</string>
21678
+ </dict></plist>
21679
+ `;
21680
+ }
21681
+ async function unloadLaunchd(location) {
21682
+ const { target, temporary } = launchdPaths(location);
21683
+ const installed = await loginRegistration(location);
21684
+ const targets = /* @__PURE__ */ new Set([
21685
+ target,
21686
+ ...installed ? [launchdPaths(location, installed.label).target] : []
21687
+ ]);
21688
+ for (const serviceTarget of targets) {
21689
+ if (await loaded(serviceTarget)) {
21690
+ try {
21691
+ await launchctl(["bootout", serviceTarget]);
21692
+ } catch (error62) {
21693
+ if (await loaded(serviceTarget)) throw error62;
21694
+ }
21695
+ }
21696
+ }
21697
+ await (0, import_promises4.rm)(temporary, { force: true });
21698
+ }
21699
+ async function startLaunchd(location, entry) {
21700
+ const installed = await loginRegistration(location);
21701
+ const { domain: domain2, target, temporary, login } = launchdPaths(location, installed?.label);
21702
+ if (!await guiSessionAvailable(location)) {
21703
+ if (installed) throw new Error("\u5F53\u524D\u6CA1\u6709 macOS \u684C\u9762\u767B\u5F55\u4F1A\u8BDD\uFF0C\u65E0\u6CD5\u542F\u52A8 GUI \u767B\u5F55\u670D\u52A1");
21704
+ return false;
21705
+ }
21706
+ await unloadLaunchd(location);
21707
+ if (installed) {
21708
+ await launchctl(["enable", target]);
21709
+ await launchctl(["bootstrap", domain2, login]);
21710
+ return true;
21711
+ }
21712
+ const bridge = await environmentBridge(location.home);
21713
+ try {
21714
+ const runner = (0, import_node_path3.join)(location.state, "launch-runner.mjs");
21715
+ await (0, import_promises4.writeFile)(runner, launchRunner, { mode: 384 });
21716
+ await (0, import_promises4.writeFile)(
21717
+ temporary,
21718
+ launchdPlist(
21719
+ location,
21720
+ [process.execPath, runner, bridge.path, entry, location.config],
21721
+ false
21722
+ ),
21723
+ { mode: 384 }
21724
+ );
21725
+ await launchctl(["enable", target]);
21726
+ await launchctl(["bootstrap", domain2, temporary]);
21727
+ await bridge.wait();
21728
+ return true;
21729
+ } catch (error62) {
21730
+ let cleanup = "";
21731
+ try {
21732
+ await unloadLaunchd(location);
21733
+ } catch (cleanupError) {
21734
+ cleanup = `\uFF1B\u6E05\u7406\u4EFB\u52A1\u5931\u8D25\uFF1A${failureDetail(cleanupError)}`;
21735
+ }
21736
+ throw new Error(
21737
+ `Covro GUI \u540E\u53F0\u542F\u52A8\u5931\u8D25\uFF1A${failureDetail(error62)}${cleanup}\uFF1B\u8FDB\u7A0B\u65E5\u5FD7\u4F4D\u4E8E ${location.log}`,
21738
+ { cause: error62 }
21739
+ );
21740
+ } finally {
21741
+ await bridge.close();
21742
+ }
21743
+ }
21744
+
21745
+ // src/cli/background.ts
21746
+ var exec2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
21747
+ async function lifecycle(location, action) {
21748
+ await (0, import_promises5.mkdir)(location.state, { recursive: true, mode: 448 });
21749
+ const release = await import_proper_lockfile2.default.lock(location.state, {
21750
+ lockfilePath: (0, import_node_path4.join)(location.state, "lifecycle.lock"),
21751
+ stale: 1e4,
21752
+ update: 2e3,
21753
+ retries: { retries: 280, minTimeout: 250, maxTimeout: 250 }
21754
+ });
21755
+ try {
21756
+ return await action();
21757
+ } finally {
21758
+ await release();
21759
+ }
21760
+ }
21761
+ async function start(location, entry) {
21762
+ try {
21763
+ return await control(location, "status");
21764
+ } catch (error62) {
21765
+ if (!isNotRunning(error62)) throw error62;
21766
+ }
21767
+ let child;
21768
+ const installed = await readJson(
21769
+ (0, import_node_path4.join)(location.state, "service.json")
21770
+ );
21771
+ if (process.platform === "darwin" && await startLaunchd(location, entry)) {
21772
+ } else if (installed?.platform === "linux") {
21773
+ await exec2("systemctl", ["--user", "start", `${installed.label}.service`]);
21774
+ } else {
21775
+ if (process.platform === "darwin")
21776
+ console.warn(
21777
+ "\u5F53\u524D\u6CA1\u6709 macOS \u684C\u9762\u767B\u5F55\u4F1A\u8BDD\uFF0C\u4F7F\u7528 headless \u540E\u53F0\u542F\u52A8\uFF1B\u7CFB\u7EDF\u94A5\u5319\u4E32\u51ED\u8BC1\u53EF\u80FD\u4E0D\u53EF\u7528\u3002"
21778
+ );
21779
+ const log = await (0, import_promises5.open)(location.log, "a", 384);
21780
+ try {
21781
+ child = (0, import_node_child_process2.spawn)(process.execPath, [entry, "run", "--config", location.config], {
21782
+ detached: true,
21783
+ stdio: ["ignore", log.fd, log.fd],
21784
+ windowsHide: true,
21785
+ env: { ...process.env, COVRO_HOME: location.home }
21786
+ });
21787
+ await new Promise((resolve, reject) => {
21788
+ child.once("spawn", resolve);
21789
+ child.once("error", reject);
21790
+ });
21791
+ child.unref();
21792
+ } finally {
21793
+ await log.close();
21794
+ }
21795
+ }
21796
+ for (let attempt = 0; attempt < 240; attempt++) {
21797
+ try {
21798
+ return await control(location, "status");
21799
+ } catch (error62) {
21800
+ if (!isNotRunning(error62)) throw error62;
21801
+ }
21802
+ if (child && child.exitCode !== null) throw new Error(`Covro \u542F\u52A8\u5931\u8D25\uFF0C\u8BF7\u67E5\u770B ${location.log}`);
21803
+ await (0, import_promises6.setTimeout)(250);
21804
+ }
21805
+ throw new Error(`Covro \u5C1A\u672A\u786E\u8BA4\u542F\u52A8\uFF0C\u8BF7\u8FD0\u884C covro status \u5E76\u67E5\u770B ${location.log}`);
21806
+ }
21807
+ async function stop(location) {
21808
+ await stopAndWait(location);
21809
+ if (process.platform === "darwin") await unloadLaunchd(location);
21810
+ else {
21811
+ const installed = await readJson(
21812
+ (0, import_node_path4.join)(location.state, "service.json")
21813
+ );
21814
+ if (installed?.platform === "linux")
21815
+ await exec2("systemctl", ["--user", "stop", `${installed.label}.service`]);
21816
+ }
21817
+ }
21818
+ var startBackground = (location, entry) => lifecycle(location, () => start(location, entry));
21819
+ var stopBackground = (location) => lifecycle(location, () => stop(location));
21820
+
21517
21821
  // src/updates/transaction.ts
21518
- var import_promises3 = require("node:fs/promises");
21519
- var import_node_path2 = require("node:path");
21520
- var exists = async (path) => (0, import_promises3.stat)(path).then(
21822
+ var import_promises7 = require("node:fs/promises");
21823
+ var import_node_path5 = require("node:path");
21824
+ var exists = async (path) => (0, import_promises7.stat)(path).then(
21521
21825
  () => true,
21522
21826
  (error62) => {
21523
21827
  if (error62.code === "ENOENT") return false;
@@ -21535,17 +21839,17 @@ async function activateUpdate(paths, effects) {
21535
21839
  await effects.phase("stopping", "\u5DF2\u5173\u95ED\u65B0\u4EFB\u52A1\u5165\u53E3\uFF0C\u6B63\u5728\u505C\u6B62\u65E7\u670D\u52A1\u5E76\u5907\u4EFD\u6570\u636E");
21536
21840
  stopped = true;
21537
21841
  await effects.stop();
21538
- await (0, import_promises3.mkdir)(paths.backup, { recursive: true, mode: 448 });
21842
+ await (0, import_promises7.mkdir)(paths.backup, { recursive: true, mode: 448 });
21539
21843
  for (const name of ["app.sqlite", "app.sqlite-wal", "app.sqlite-shm"]) {
21540
- if (await exists((0, import_node_path2.join)(paths.dataDir, name)))
21541
- await copyDurable((0, import_node_path2.join)(paths.dataDir, name), (0, import_node_path2.join)(paths.backup, name));
21844
+ if (await exists((0, import_node_path5.join)(paths.dataDir, name)))
21845
+ await copyDurable((0, import_node_path5.join)(paths.dataDir, name), (0, import_node_path5.join)(paths.backup, name));
21542
21846
  }
21543
- await copyDurable(paths.config, (0, import_node_path2.join)(paths.backup, "config.json"));
21544
- await saveJson((0, import_node_path2.join)(paths.backup, "snapshot.json"), { complete: true });
21847
+ await copyDurable(paths.config, (0, import_node_path5.join)(paths.backup, "config.json"));
21848
+ await saveJson((0, import_node_path5.join)(paths.backup, "snapshot.json"), { complete: true });
21545
21849
  backedUp = true;
21546
- await (0, import_promises3.rename)(paths.root, paths.previous);
21850
+ await (0, import_promises7.rename)(paths.root, paths.previous);
21547
21851
  moved = true;
21548
- await (0, import_promises3.rename)(paths.candidate, paths.root);
21852
+ await (0, import_promises7.rename)(paths.candidate, paths.root);
21549
21853
  await effects.phase("verifying", "\u6B63\u5728\u542F\u52A8\u65B0\u7248\u3001\u8FC1\u79FB\u6570\u636E\u5E93\u5E76\u9A8C\u8BC1\uFF1B\u4E1A\u52A1\u5199\u5165\u4FDD\u6301\u6682\u505C");
21550
21854
  await effects.start(true);
21551
21855
  await effects.verify();
@@ -21562,16 +21866,16 @@ async function activateUpdate(paths, effects) {
21562
21866
  try {
21563
21867
  await effects.stop();
21564
21868
  if (moved) {
21565
- await (0, import_promises3.rm)(paths.root, { recursive: true, force: true });
21566
- await (0, import_promises3.rename)(paths.previous, paths.root);
21869
+ await (0, import_promises7.rm)(paths.root, { recursive: true, force: true });
21870
+ await (0, import_promises7.rename)(paths.previous, paths.root);
21567
21871
  }
21568
21872
  if (backedUp) {
21569
21873
  for (const name of ["app.sqlite", "app.sqlite-wal", "app.sqlite-shm"]) {
21570
- await (0, import_promises3.rm)((0, import_node_path2.join)(paths.dataDir, name), { force: true });
21571
- if (await exists((0, import_node_path2.join)(paths.backup, name)))
21572
- await copyDurable((0, import_node_path2.join)(paths.backup, name), (0, import_node_path2.join)(paths.dataDir, name));
21874
+ await (0, import_promises7.rm)((0, import_node_path5.join)(paths.dataDir, name), { force: true });
21875
+ if (await exists((0, import_node_path5.join)(paths.backup, name)))
21876
+ await copyDurable((0, import_node_path5.join)(paths.backup, name), (0, import_node_path5.join)(paths.dataDir, name));
21573
21877
  }
21574
- await copyDurable((0, import_node_path2.join)(paths.backup, "config.json"), paths.config);
21878
+ await copyDurable((0, import_node_path5.join)(paths.backup, "config.json"), paths.config);
21575
21879
  }
21576
21880
  await effects.phase(
21577
21881
  "rolledBack",
@@ -21589,16 +21893,16 @@ async function activateUpdate(paths, effects) {
21589
21893
  }
21590
21894
  }
21591
21895
  function transactionPaths(root, id, dataDir, config2, backup) {
21592
- const prefix = (0, import_node_path2.join)((0, import_node_path2.dirname)(root), `.covro-stage-${id}`);
21896
+ const prefix = (0, import_node_path5.join)((0, import_node_path5.dirname)(root), `.covro-stage-${id}`);
21593
21897
  return {
21594
21898
  root,
21595
21899
  prefix,
21596
- candidate: (0, import_node_path2.join)(
21900
+ candidate: (0, import_node_path5.join)(
21597
21901
  prefix,
21598
21902
  process.platform === "win32" ? "node_modules" : "lib/node_modules",
21599
21903
  npmPackageName
21600
21904
  ),
21601
- previous: (0, import_node_path2.join)((0, import_node_path2.dirname)(root), `.covro-previous-${id}`),
21905
+ previous: (0, import_node_path5.join)((0, import_node_path5.dirname)(root), `.covro-previous-${id}`),
21602
21906
  backup,
21603
21907
  dataDir,
21604
21908
  config: config2
@@ -21606,12 +21910,12 @@ function transactionPaths(root, id, dataDir, config2, backup) {
21606
21910
  }
21607
21911
 
21608
21912
  // src/updates/registry.ts
21609
- var import_node_child_process = require("node:child_process");
21610
- var import_node_util = require("node:util");
21611
- var import_promises4 = require("node:fs/promises");
21913
+ var import_node_child_process3 = require("node:child_process");
21914
+ var import_node_util3 = require("node:util");
21915
+ var import_promises8 = require("node:fs/promises");
21612
21916
  var import_node_fs = require("node:fs");
21613
- var import_node_path3 = require("node:path");
21614
- var run = (0, import_node_util.promisify)(import_node_child_process.execFile);
21917
+ var import_node_path6 = require("node:path");
21918
+ var run = (0, import_node_util3.promisify)(import_node_child_process3.execFile);
21615
21919
  var registry2 = "https://registry.npmjs.org";
21616
21920
  var releaseSchema = external_exports.object({
21617
21921
  name: external_exports.literal(npmPackageName),
@@ -21628,80 +21932,27 @@ async function inspectInstallation(root) {
21628
21932
  }
21629
21933
  }
21630
21934
  async function inspectPackageDirectory(root, globalRoot) {
21631
- const expected = (0, import_node_path3.join)(await (0, import_promises4.realpath)(globalRoot), npmPackageName);
21632
- if ((await (0, import_promises4.lstat)(expected)).isSymbolicLink() || await (0, import_promises4.realpath)(root) !== expected)
21935
+ const expected = (0, import_node_path6.join)(await (0, import_promises8.realpath)(globalRoot), npmPackageName);
21936
+ if ((await (0, import_promises8.lstat)(expected)).isSymbolicLink() || await (0, import_promises8.realpath)(root) !== expected)
21633
21937
  return "\u5F53\u524D\u4E3A\u6E90\u7801\u3001\u94FE\u63A5\u6216\u975E npm \u5168\u5C40\u5B89\u88C5\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
21634
21938
  try {
21635
- await (0, import_promises4.lstat)((0, import_node_path3.join)(expected, ".git"));
21939
+ await (0, import_promises8.lstat)((0, import_node_path6.join)(expected, ".git"));
21636
21940
  return "\u5F53\u524D\u5B89\u88C5\u5305\u542B Git \u5DE5\u4F5C\u533A\uFF1B\u8BF7\u4F7F\u7528\u539F\u90E8\u7F72\u65B9\u5F0F\u66F4\u65B0\u3002";
21637
21941
  } catch (error62) {
21638
21942
  if (error62.code !== "ENOENT") throw error62;
21639
21943
  }
21640
- await (0, import_promises4.access)(root, import_node_fs.constants.W_OK);
21944
+ await (0, import_promises8.access)(root, import_node_fs.constants.W_OK);
21641
21945
  return void 0;
21642
21946
  }
21643
21947
 
21644
21948
  // src/updates/worker.ts
21645
- var exec = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
21949
+ var exec3 = (0, import_node_util4.promisify)(import_node_child_process4.execFile);
21646
21950
  var message = (error62) => error62 instanceof Error ? error62.message : String(error62);
21647
- async function startService(context, activation) {
21648
- const installed = await readJson(
21649
- (0, import_node_path4.join)(context.location.state, "service.json")
21650
- );
21651
- if (installed) {
21652
- if (installed.platform === "darwin")
21653
- await exec("launchctl", [
21654
- "bootstrap",
21655
- `gui/${process.getuid()}`,
21656
- (0, import_node_path4.join)((0, import_node_os.homedir)(), "Library/LaunchAgents", `${installed.label}.plist`)
21657
- ]);
21658
- else await exec("systemctl", ["--user", "start", `${installed.label}.service`]);
21659
- } else {
21660
- const log = await (0, import_promises5.open)(context.location.log, "a", 384);
21661
- try {
21662
- const child = (0, import_node_child_process3.spawn)(
21663
- process.execPath,
21664
- [(0, import_node_path4.join)(context.root, "bin/covro.mjs"), "run", "--config", context.location.config],
21665
- {
21666
- detached: true,
21667
- stdio: ["ignore", log.fd, log.fd],
21668
- windowsHide: true,
21669
- env: {
21670
- ...process.env,
21671
- COVRO_HOME: context.location.home,
21672
- ...activation ? { COVRO_ACTIVATING: activation } : {}
21673
- }
21674
- }
21675
- );
21676
- await new Promise((done, reject) => {
21677
- child.once("spawn", done);
21678
- child.once("error", reject);
21679
- });
21680
- child.unref();
21681
- } finally {
21682
- await log.close();
21683
- }
21684
- }
21951
+ async function startService(context) {
21952
+ await startBackground(context.location, (0, import_node_path7.join)(context.root, "bin/covro.mjs"));
21685
21953
  }
21686
21954
  async function stopService(context) {
21687
- await stopAndWait(context.location);
21688
- const installed = await readJson(
21689
- (0, import_node_path4.join)(context.location.state, "service.json")
21690
- );
21691
- if (installed?.platform === "linux")
21692
- await exec("systemctl", ["--user", "stop", `${installed.label}.service`]);
21693
- else if (installed?.platform === "darwin") {
21694
- const target = `gui/${process.getuid()}/${installed.label}`;
21695
- try {
21696
- await exec("launchctl", ["bootout", target]);
21697
- } catch (error62) {
21698
- const stillLoaded = await exec("launchctl", ["print", target]).then(
21699
- () => true,
21700
- () => false
21701
- );
21702
- if (stillLoaded) throw error62;
21703
- }
21704
- }
21955
+ await stopBackground(context.location);
21705
21956
  }
21706
21957
  async function verifyRestoredService(context, version3) {
21707
21958
  for (let attempt = 0; attempt < 240; attempt++) {
@@ -21713,15 +21964,15 @@ async function verifyRestoredService(context, version3) {
21713
21964
  } catch (error62) {
21714
21965
  if (attempt === 239) throw error62;
21715
21966
  }
21716
- await (0, import_promises6.setTimeout)(250);
21967
+ await (0, import_promises10.setTimeout)(250);
21717
21968
  }
21718
21969
  }
21719
21970
  async function verifyMigrations(context, candidate) {
21720
- const require2 = (0, import_node_module.createRequire)((0, import_node_path4.join)(context.root, "package.json"));
21971
+ const require2 = (0, import_node_module.createRequire)((0, import_node_path7.join)(context.root, "package.json"));
21721
21972
  const Sqlite = require2("better-sqlite3");
21722
- const filename = (0, import_node_path4.join)(context.dataDir, "app.sqlite");
21973
+ const filename = (0, import_node_path7.join)(context.dataDir, "app.sqlite");
21723
21974
  try {
21724
- await (0, import_promises5.access)(filename);
21975
+ await (0, import_promises9.access)(filename);
21725
21976
  } catch (error62) {
21726
21977
  if (error62.code === "ENOENT") return;
21727
21978
  throw error62;
@@ -21732,12 +21983,12 @@ async function verifyMigrations(context, candidate) {
21732
21983
  if (!table) return;
21733
21984
  const applied = db.prepare("SELECT hash FROM __drizzle_migrations ORDER BY created_at").all();
21734
21985
  const journal = JSON.parse(
21735
- await (0, import_promises5.readFile)((0, import_node_path4.join)(candidate, "dist/drizzle/meta/_journal.json"), "utf8")
21986
+ await (0, import_promises9.readFile)((0, import_node_path7.join)(candidate, "dist/drizzle/meta/_journal.json"), "utf8")
21736
21987
  );
21737
21988
  const hashes = await Promise.all(
21738
21989
  journal.entries.map(async (entry) => {
21739
21990
  if (!/^[a-zA-Z0-9_-]+$/.test(entry.tag)) throw new Error("\u5019\u9009\u5305\u5305\u542B\u65E0\u6548\u8FC1\u79FB\u8DEF\u5F84");
21740
- return (0, import_node_crypto2.createHash)("sha256").update(await (0, import_promises5.readFile)((0, import_node_path4.join)(candidate, "dist/drizzle", `${entry.tag}.sql`))).digest("hex");
21991
+ return (0, import_node_crypto4.createHash)("sha256").update(await (0, import_promises9.readFile)((0, import_node_path7.join)(candidate, "dist/drizzle", `${entry.tag}.sql`))).digest("hex");
21741
21992
  })
21742
21993
  );
21743
21994
  if (applied.some((entry, i) => entry.hash !== hashes[i]))
@@ -21747,28 +21998,28 @@ async function verifyMigrations(context, candidate) {
21747
21998
  }
21748
21999
  }
21749
22000
  async function worker(directory) {
21750
- await (0, import_promises5.mkdir)(directory, { recursive: true, mode: 448 });
21751
- const release = await import_proper_lockfile2.default.lock(directory, {
22001
+ await (0, import_promises9.mkdir)(directory, { recursive: true, mode: 448 });
22002
+ const release = await import_proper_lockfile3.default.lock(directory, {
21752
22003
  stale: 1e4,
21753
22004
  update: 2e3,
21754
22005
  retries: { retries: 30, minTimeout: 100, maxTimeout: 500 }
21755
22006
  });
21756
- let record2 = await readJson((0, import_node_path4.join)(directory, "run.json"));
21757
- const context = await readJson((0, import_node_path4.join)(directory, "context.json"));
22007
+ let record2 = await readJson((0, import_node_path7.join)(directory, "run.json"));
22008
+ const context = await readJson((0, import_node_path7.join)(directory, "context.json"));
21758
22009
  if (!record2 || !context) {
21759
22010
  await release();
21760
22011
  throw new Error("\u7F3A\u5C11\u5347\u7EA7\u8BB0\u5F55");
21761
22012
  }
21762
22013
  const update = async (phase, detail) => {
21763
22014
  record2 = { ...record2, phase, message: detail, updatedAt: Date.now() };
21764
- await saveJson((0, import_node_path4.join)(directory, "run.json"), record2);
22015
+ await saveJson((0, import_node_path7.join)(directory, "run.json"), record2);
21765
22016
  };
21766
22017
  const paths = transactionPaths(
21767
22018
  context.root,
21768
22019
  record2.id,
21769
22020
  context.dataDir,
21770
22021
  context.location.config,
21771
- (0, import_node_path4.join)(directory, `backup-${record2.id}`)
22022
+ (0, import_node_path7.join)(directory, `backup-${record2.id}`)
21772
22023
  );
21773
22024
  try {
21774
22025
  if (process.argv[3] === "--repair") {
@@ -21782,18 +22033,18 @@ async function worker(directory) {
21782
22033
  if (active && !active.maintenance && active.version !== record2.from)
21783
22034
  throw new Error("\u5F53\u524D\u670D\u52A1\u53EF\u80FD\u5DF2\u63A5\u53D7\u65B0\u7248\u4E1A\u52A1\u6570\u636E\uFF1B\u62D2\u7EDD\u6062\u590D\u65E7\u5FEB\u7167\uFF0C\u8BF7\u4F7F\u7528\u517C\u5BB9\u7248\u672C\u68C0\u67E5\u3002");
21784
22035
  const previous = await readJson(
21785
- (0, import_node_path4.join)(paths.previous, "package.json")
22036
+ (0, import_node_path7.join)(paths.previous, "package.json")
21786
22037
  );
21787
22038
  if (previous) {
21788
22039
  if (active && !active.maintenance)
21789
22040
  throw new Error("\u65E7\u670D\u52A1\u5DF2\u6062\u590D\u4E1A\u52A1\u5199\u5165\uFF1B\u62D2\u7EDD\u7528\u5347\u7EA7\u524D\u5FEB\u7167\u8986\u76D6\u73B0\u6709\u6570\u636E\uFF0C\u8BF7\u4FDD\u7559\u73B0\u573A\u68C0\u67E5\u3002");
21790
22041
  if (previous.name !== npmPackageName || previous.version !== record2.from)
21791
22042
  throw new Error("\u65E7\u7248\u5907\u4EFD\u8EAB\u4EFD\u4E0D\u5339\u914D");
21792
- const snapshot = await readJson((0, import_node_path4.join)(paths.backup, "snapshot.json"));
22043
+ const snapshot = await readJson((0, import_node_path7.join)(paths.backup, "snapshot.json"));
21793
22044
  if (!snapshot?.complete) throw new Error("\u6570\u636E\u5E93\u5907\u4EFD\u4E0D\u5B8C\u6574\uFF0C\u4FDD\u7559\u5168\u90E8\u73B0\u573A\u4F9B\u68C0\u67E5");
21794
22045
  } else {
21795
22046
  const original = await readJson(
21796
- (0, import_node_path4.join)(paths.root, "package.json")
22047
+ (0, import_node_path7.join)(paths.root, "package.json")
21797
22048
  );
21798
22049
  if (original?.name !== npmPackageName || original.version !== record2.from)
21799
22050
  throw new Error("\u672A\u627E\u5230\u5B8C\u6574\u7684\u4E0A\u4E00\u7248\u672C\u5B89\u88C5");
@@ -21804,20 +22055,20 @@ async function worker(directory) {
21804
22055
  }
21805
22056
  await stopService(context);
21806
22057
  if (previous) {
21807
- await (0, import_promises5.rm)(paths.root, { recursive: true, force: true });
21808
- await (0, import_promises5.rename)(paths.previous, paths.root);
22058
+ await (0, import_promises9.rm)(paths.root, { recursive: true, force: true });
22059
+ await (0, import_promises9.rename)(paths.previous, paths.root);
21809
22060
  for (const name of ["app.sqlite", "app.sqlite-wal", "app.sqlite-shm"]) {
21810
- await (0, import_promises5.rm)((0, import_node_path4.join)(paths.dataDir, name), { force: true });
22061
+ await (0, import_promises9.rm)((0, import_node_path7.join)(paths.dataDir, name), { force: true });
21811
22062
  try {
21812
- await copyDurable((0, import_node_path4.join)(paths.backup, name), (0, import_node_path4.join)(paths.dataDir, name));
22063
+ await copyDurable((0, import_node_path7.join)(paths.backup, name), (0, import_node_path7.join)(paths.dataDir, name));
21813
22064
  } catch (error62) {
21814
22065
  if (error62.code !== "ENOENT") throw error62;
21815
22066
  }
21816
22067
  }
21817
- await copyDurable((0, import_node_path4.join)(paths.backup, "config.json"), paths.config);
22068
+ await copyDurable((0, import_node_path7.join)(paths.backup, "config.json"), paths.config);
21818
22069
  }
21819
22070
  const restored = await readJson(
21820
- (0, import_node_path4.join)(paths.root, "package.json")
22071
+ (0, import_node_path7.join)(paths.root, "package.json")
21821
22072
  );
21822
22073
  if (restored?.name !== npmPackageName || restored.version !== record2.from)
21823
22074
  throw new Error("\u672A\u627E\u5230\u5B8C\u6574\u7684\u4E0A\u4E00\u7248\u672C\u5B89\u88C5");
@@ -21834,10 +22085,10 @@ async function worker(directory) {
21834
22085
  }
21835
22086
  const reason = await inspectInstallation(context.root);
21836
22087
  if (reason) throw new Error(reason);
21837
- for (const key of await (0, import_promises5.readdir)((0, import_node_path4.join)(context.location.home, "instances"))) {
22088
+ for (const key of await (0, import_promises9.readdir)((0, import_node_path7.join)(context.location.home, "instances"))) {
21838
22089
  if (key === context.location.key) continue;
21839
22090
  const instance = await readJson(
21840
- (0, import_node_path4.join)(context.location.home, "instances", key, "instance.json")
22091
+ (0, import_node_path7.join)(context.location.home, "instances", key, "instance.json")
21841
22092
  );
21842
22093
  if (instance?.root !== context.root) continue;
21843
22094
  try {
@@ -21847,8 +22098,8 @@ async function worker(directory) {
21847
22098
  if (!isNotRunning(error62)) throw error62;
21848
22099
  }
21849
22100
  }
21850
- await (0, import_promises5.access)((0, import_node_path4.dirname)(context.root), import_node_fs2.constants.W_OK);
21851
- await exec(
22101
+ await (0, import_promises9.access)((0, import_node_path7.dirname)(context.root), import_node_fs2.constants.W_OK);
22102
+ await exec3(
21852
22103
  "npm",
21853
22104
  [
21854
22105
  "install",
@@ -21865,7 +22116,7 @@ async function worker(directory) {
21865
22116
  { timeout: 10 * 6e4, maxBuffer: 2 * 1024 * 1024 }
21866
22117
  );
21867
22118
  const candidate = await readJson(
21868
- (0, import_node_path4.join)(paths.candidate, "package.json")
22119
+ (0, import_node_path7.join)(paths.candidate, "package.json")
21869
22120
  );
21870
22121
  if (candidate?.name !== npmPackageName || candidate.version !== record2.target)
21871
22122
  throw new Error("\u5019\u9009\u5305\u8EAB\u4EFD\u6216\u7248\u672C\u4E0D\u5339\u914D");
@@ -21884,13 +22135,13 @@ async function worker(directory) {
21884
22135
  );
21885
22136
  };
21886
22137
  await checkCodex();
21887
- await exec(process.execPath, [(0, import_node_path4.join)(paths.candidate, "bin/covro.mjs"), "--version"], {
22138
+ await exec3(process.execPath, [(0, import_node_path7.join)(paths.candidate, "bin/covro.mjs"), "--version"], {
21888
22139
  timeout: 3e4
21889
22140
  });
21890
22141
  const nativeProbe = 'const {createRequire}=await import("node:module"); const r=createRequire(process.argv[1]); const DB=r("better-sqlite3"); const db=new DB(":memory:"); db.close();';
21891
- await exec(
22142
+ await exec3(
21892
22143
  process.execPath,
21893
- ["--input-type=module", "-e", nativeProbe, (0, import_node_path4.join)(paths.candidate, "package.json")],
22144
+ ["--input-type=module", "-e", nativeProbe, (0, import_node_path7.join)(paths.candidate, "package.json")],
21894
22145
  { timeout: 3e4 }
21895
22146
  );
21896
22147
  await verifyMigrations(context, paths.candidate);
@@ -21908,12 +22159,12 @@ async function worker(directory) {
21908
22159
  return;
21909
22160
  }
21910
22161
  await update("waiting", result.reason ?? "\u7B49\u5F85\u6240\u6709\u4EFB\u52A1\u7ED3\u675F");
21911
- await (0, import_promises6.setTimeout)(2e3);
22162
+ await (0, import_promises10.setTimeout)(2e3);
21912
22163
  }
21913
22164
  },
21914
22165
  stop: () => stopService(context),
21915
22166
  start: async (candidate2) => {
21916
- await startService(context, candidate2 ? record2.id : void 0);
22167
+ await startService(context);
21917
22168
  if (!candidate2) await verifyRestoredService(context, record2.from);
21918
22169
  },
21919
22170
  verify: async () => {
@@ -21927,7 +22178,7 @@ async function worker(directory) {
21927
22178
  await checkCodex(current);
21928
22179
  if (current.codexReady) return;
21929
22180
  }
21930
- await (0, import_promises6.setTimeout)(250);
22181
+ await (0, import_promises10.setTimeout)(250);
21931
22182
  }
21932
22183
  throw new Error("\u65B0\u7248\u670D\u52A1\u6216 Codex \u8FDE\u63A5\u672A\u5C31\u7EEA\uFF0C\u62D2\u7EDD\u6FC0\u6D3B");
21933
22184
  },
@@ -21936,18 +22187,18 @@ async function worker(directory) {
21936
22187
  id: record2.id,
21937
22188
  channel: record2.channel
21938
22189
  });
21939
- const final = await readJson((0, import_node_path4.join)(directory, "run.json"));
22190
+ const final = await readJson((0, import_node_path7.join)(directory, "run.json"));
21940
22191
  if (!final?.committed) throw new Error("\u65B0\u7248\u5C1A\u672A\u786E\u8BA4\u5347\u7EA7\u63D0\u4EA4");
21941
22192
  record2 = final;
21942
22193
  },
21943
- hasCommitted: async () => Boolean((await readJson((0, import_node_path4.join)(directory, "run.json")))?.committed),
22194
+ hasCommitted: async () => Boolean((await readJson((0, import_node_path7.join)(directory, "run.json")))?.committed),
21944
22195
  resume: async () => {
21945
22196
  await control(context.location, "cancel-update").catch(() => {
21946
22197
  });
21947
22198
  }
21948
22199
  });
21949
22200
  } catch (error62) {
21950
- const latest = await readJson((0, import_node_path4.join)(directory, "run.json"));
22201
+ const latest = await readJson((0, import_node_path7.join)(directory, "run.json"));
21951
22202
  if (latest?.committed) {
21952
22203
  record2 = latest;
21953
22204
  } else if (!["rolledBack", "failed"].includes(record2.phase))
@@ -21957,7 +22208,7 @@ async function worker(directory) {
21957
22208
  } finally {
21958
22209
  await release();
21959
22210
  if (record2.phase === "succeeded" || record2.phase === "rolledBack") {
21960
- await (0, import_promises5.rm)(paths.prefix, { recursive: true, force: true });
22211
+ await (0, import_promises9.rm)(paths.prefix, { recursive: true, force: true });
21961
22212
  }
21962
22213
  }
21963
22214
  }