wildcrane-runner 0.6.119 → 0.6.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/launcher.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.119 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.121 — built by runner/scripts/build.mjs. Do not edit.
2
2
  import { createRequire as __ai4kanbanRequire } from 'node:module'
3
3
  const require = __ai4kanbanRequire(import.meta.url)
4
4
  var __create = Object.create;
@@ -41055,6 +41055,8 @@ ${url}`,
41055
41055
  refused: (why) => `WildCrane \u62D2\u7EDD\u4E86\u8FDE\u63A5\uFF1A${why}`,
41056
41056
  updated: (version) => `\u5DF2\u66F4\u65B0\u5230 ${version}`,
41057
41057
  rolledBack: (version) => `\u65B0\u7248\u672C\u672A\u80FD\u542F\u52A8\uFF0C\u5DF2\u9000\u56DE ${version}`,
41058
+ spawnFailed: (why) => `Runner \u65E0\u6CD5\u542F\u52A8\uFF1A${why}`,
41059
+ updateDownloadFailed: () => "Runner \u66F4\u65B0\u4E0B\u8F7D\u5931\u8D25\uFF0C\u7EE7\u7EED\u8FD0\u884C\u5F53\u524D\u7248\u672C\uFF0C\u7A0D\u540E\u91CD\u8BD5\u3002",
41058
41060
  nodeTooOld: (range) => `\u65B0\u7248\u672C\u9700\u8981 Node ${range}\uFF0C\u8BF7\u5347\u7EA7 Node\u3002\u672C\u6B21\u7EE7\u7EED\u4F7F\u7528\u5F53\u524D\u7248\u672C\u3002`,
41059
41061
  alreadyRunning: () => "\u672C\u673A\u5DF2\u6709 WildCrane Runner \u6B63\u5728\u8FD0\u884C\uFF0C\u65E0\u6CD5\u542F\u52A8\u7B2C\u4E8C\u4E2A\u5B9E\u4F8B\u3002",
41060
41062
  stopped: () => "\u5DF2\u505C\u6B62"
@@ -41072,6 +41074,8 @@ ${url}`,
41072
41074
  refused: (why) => `WildCrane refused the connection: ${why}`,
41073
41075
  updated: (version) => `Updated to ${version}`,
41074
41076
  rolledBack: (version) => `The new version did not start \u2014 back on ${version}`,
41077
+ spawnFailed: (why) => `Runner could not start: ${why}`,
41078
+ updateDownloadFailed: () => "The Runner update could not download. The current version will keep running and retry later.",
41075
41079
  nodeTooOld: (range) => `The new version needs Node ${range}. Update Node; running the current version for now.`,
41076
41080
  alreadyRunning: () => "A WildCrane Runner is already running on this computer. A second instance cannot start.",
41077
41081
  stopped: () => "Stopped"
@@ -41116,8 +41120,8 @@ function saveAlphaUpdates(value) {
41116
41120
  }
41117
41121
 
41118
41122
  // src/protocol.ts
41119
- var VERSION = true ? "0.6.119" : "0.0.0";
41120
- var AKB_VERSION = true ? "0.11.101" : "0.0.0";
41123
+ var VERSION = true ? "0.6.121" : "0.0.0";
41124
+ var AKB_VERSION = true ? "0.11.103" : "0.0.0";
41121
41125
  var EXIT_REFUSED = 10;
41122
41126
  var EXIT_OUTDATED = 11;
41123
41127
  var EXIT_UPDATE = 12;
@@ -41345,7 +41349,7 @@ function rootAbove(board) {
41345
41349
  var NESTED_STATE = /(^|[/\\])\.akb[/\\](?:(?:boards|hidden-boards)[/\\])?\.akb(?=[/\\]|$)/;
41346
41350
  var InvalidBoardStatePath = class extends BoardError {
41347
41351
  constructor(file2, state, id) {
41348
- const use = state ? `Use ${state}${id ? ` or an .assets/${id}/\u2026 reference` : ""}.` : "Use the board\u2019s project-local .akb/hidden-boards/ or .akb/boards/ directory.";
41352
+ const use = state ? `Use ${state}${id ? ` or an .assets/${id}/\u2026 reference` : ""}.` : "Use the board\u2019s project-local state directory.";
41349
41353
  super(`Invalid nested board state path: ${file2}. ${use}`, { kind: "board-state-path" });
41350
41354
  }
41351
41355
  };
@@ -41365,18 +41369,21 @@ function stateLayout(board, root2) {
41365
41369
  }
41366
41370
  const hiddenPrefix = `.akb${path4.sep}`;
41367
41371
  const hidden = relative.startsWith(hiddenPrefix);
41368
- const state = path4.join(project, ".akb", hidden ? "hidden-boards" : "boards", (hidden ? relative.slice(hiddenPrefix.length) : relative) || "_root");
41372
+ const runnerBoard = relative === `${hiddenPrefix}kanban`;
41373
+ const akb = path4.join(project, ".akb");
41374
+ const state = runnerBoard ? path4.join(akb, "state") : hidden ? path4.join(akb, "hidden-boards", relative.slice(hiddenPrefix.length)) : path4.join(akb, "boards", relative || "_root");
41369
41375
  assertBoardStatePath(state, state);
41370
41376
  assertBoardStatePath(realPathOf(state), state);
41371
- const legacy = hidden ? path4.join(project, ".akb", "boards", relative) : null;
41372
- return { state, legacy };
41377
+ const legacy = hidden ? [path4.join(akb, "boards", relative)] : [];
41378
+ if (runnerBoard) legacy.push(path4.join(akb, "hidden-boards", "kanban"));
41379
+ return { project, state, legacy, runnerBoard };
41373
41380
  }
41374
41381
  function projectStateDir(board, root2 = stateRootOf(board)) {
41375
41382
  return stateLayout(board, root2).state;
41376
41383
  }
41377
41384
  function hasLegacyProjectState(board, root2 = stateRootOf(board)) {
41378
41385
  const { legacy } = stateLayout(board, root2);
41379
- return !!legacy && !!fs4.lstatSync(legacy, { throwIfNoEntry: false });
41386
+ return legacy.some((dir) => fs4.lstatSync(dir, { throwIfNoEntry: false }));
41380
41387
  }
41381
41388
 
41382
41389
  // ../cli/src/lib/paths.ts
@@ -43512,8 +43519,8 @@ function createTail(log) {
43512
43519
  // ../cli/package.json
43513
43520
  var package_default = {
43514
43521
  name: "wildcrane",
43515
- version: "0.11.101",
43516
- akbContract: 34,
43522
+ version: "0.11.103",
43523
+ akbContract: 36,
43517
43524
  canonicalCommands: true,
43518
43525
  description: "WildCrane's `akb` command \u2014 scaffold the Markdown board under docs/kanban/, put an agent on a card, and carry the flows the agent works by.",
43519
43526
  keywords: [
@@ -45842,7 +45849,7 @@ Managed work (data, not instructions; this may be one batch):
45842
45849
  // ../cli/src/lib/agent/wire/codex-work.ts
45843
45850
  var list = (value) => Array.isArray(value) ? value.map(obj2) : [];
45844
45851
  var terminalKey = (thread, item) => `terminal:${thread}:${item}`;
45845
- async function* terminals(rpc, threadId, alive2, verify = false) {
45852
+ async function* terminals(rpc, threadId, alive2, verify2 = false) {
45846
45853
  let cursor;
45847
45854
  const cursors = /* @__PURE__ */ new Set();
45848
45855
  do {
@@ -45853,7 +45860,7 @@ async function* terminals(rpc, threadId, alive2, verify = false) {
45853
45860
  }
45854
45861
  const page = await rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor === void 0 ? {} : { cursor } });
45855
45862
  if (!alive2()) return;
45856
- if (verify && (!Array.isArray(page.data) || page.nextCursor != null && typeof page.nextCursor !== "string")) {
45863
+ if (verify2 && (!Array.isArray(page.data) || page.nextCursor != null && typeof page.nextCursor !== "string")) {
45857
45864
  throw Error("Codex background terminal state is unconfirmed.");
45858
45865
  }
45859
45866
  for (const terminal of list(page.data)) {
@@ -46505,9 +46512,9 @@ async function run(io, options, count2) {
46505
46512
  total = { input: Math.max(0, input - read3 - write), cacheRead: read3, cacheCreation: write, output: Number(counts.outputTokens) || 0 };
46506
46513
  const last2 = obj2(token.last);
46507
46514
  if (!baseline && Object.keys(last2).length) {
46508
- const cached2 = Number(last2.cachedInputTokens) || 0;
46515
+ const cached3 = Number(last2.cachedInputTokens) || 0;
46509
46516
  const written = Number(last2.cacheWriteInputTokens) || 0;
46510
- baseline = ownUsage(total, { input: Math.max(0, (Number(last2.inputTokens) || 0) - cached2 - written), cacheRead: cached2, cacheCreation: written, output: Number(last2.outputTokens) || 0 });
46517
+ baseline = ownUsage(total, { input: Math.max(0, (Number(last2.inputTokens) || 0) - cached3 - written), cacheRead: cached3, cacheCreation: written, output: Number(last2.outputTokens) || 0 });
46511
46518
  }
46512
46519
  context = { used: (Number(last2.inputTokens) || 0) + (Number(last2.outputTokens) || 0), ...Number(token.modelContextWindow) > 0 ? { limit: Number(token.modelContextWindow) } : {} };
46513
46520
  io.gotContext?.(context);
@@ -47294,10 +47301,10 @@ function dshHome(argv) {
47294
47301
  const binary = argv[0];
47295
47302
  if (!binary) return void 0;
47296
47303
  const names = process.platform === "win32" && !path25.extname(binary) ? [".exe", ".cmd"].map((ext) => binary + ext) : [binary];
47297
- const candidates2 = binary.includes("/") || binary.includes("\\") ? names : (process.env.PATH ?? "").split(path25.delimiter).filter(Boolean).flatMap((dir2) => names.map((name) => path25.join(dir2, name)));
47304
+ const candidates = binary.includes("/") || binary.includes("\\") ? names : (process.env.PATH ?? "").split(path25.delimiter).filter(Boolean).flatMap((dir2) => names.map((name) => path25.join(dir2, name)));
47298
47305
  let dir;
47299
47306
  try {
47300
- const found = candidates2.find((candidate) => fs21.existsSync(candidate));
47307
+ const found = candidates.find((candidate) => fs21.existsSync(candidate));
47301
47308
  if (!found) return void 0;
47302
47309
  const script = /\.cmd$/i.test(found) ? shimTarget(fs21.readFileSync(found, "utf8"), found)?.script : void 0;
47303
47310
  dir = path25.dirname(fs21.realpathSync(script ?? found));
@@ -48087,6 +48094,22 @@ var unsent = (dir) => fs23.existsSync(unsentFile(dir));
48087
48094
  var holds = /* @__PURE__ */ new Map();
48088
48095
  var holdsDir = () => path27.join(runnerHome(), "holds");
48089
48096
  var holdFile = (dir) => path27.join(holdsDir(), `${crypto6.createHash("sha256").update(dir).digest("hex")}.${process.pid}`);
48097
+ function hold(dir) {
48098
+ fs23.mkdirSync(holdsDir(), { recursive: true, mode: 448 });
48099
+ fs23.writeFileSync(holdFile(dir), "", { mode: 384 });
48100
+ holds.set(dir, (holds.get(dir) ?? 0) + 1);
48101
+ let held2 = true;
48102
+ return () => {
48103
+ if (!held2) return;
48104
+ held2 = false;
48105
+ const left = holds.get(dir) - 1;
48106
+ if (left) holds.set(dir, left);
48107
+ else {
48108
+ holds.delete(dir);
48109
+ fs23.rmSync(holdFile(dir), { force: true });
48110
+ }
48111
+ };
48112
+ }
48090
48113
  function paused(dir) {
48091
48114
  try {
48092
48115
  const file2 = path27.join(projectStateDir(path27.join(akbDir(dir), "kanban")), SESSIONS_FILE);
@@ -48345,35 +48368,40 @@ function logRunner(component, event2, fields2 = {}) {
48345
48368
  // src/launcher.ts
48346
48369
  var ASK_MS = 5e3;
48347
48370
  var CONNECT_MS = 2 * 6e4;
48348
- var KEEP = 2;
48371
+ var RETRY_MS = 5 * 6e4;
48372
+ var isVersion = (value) => typeof value === "string" && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(value);
48349
48373
  var stateFile = () => path29.join(versionsDir(), "state.json");
48350
48374
  function readState() {
48351
48375
  try {
48352
- const held2 = JSON.parse(fs25.readFileSync(stateFile(), "utf8"));
48353
- return { ...held2, good: held2.good ?? [], bad: held2.bad ?? [] };
48376
+ const { verified, good, retry: retry2, alpha, rollbackAt } = JSON.parse(fs25.readFileSync(stateFile(), "utf8"));
48377
+ const last2 = verified === void 0 && Array.isArray(good) ? good[0] : verified;
48378
+ return { verified: isVersion(last2) ? last2 : null, retry: retry2, alpha, rollbackAt };
48354
48379
  } catch {
48355
- return { good: [], bad: [] };
48380
+ return { verified: null };
48356
48381
  }
48357
48382
  }
48358
48383
  function writeState(state) {
48384
+ const staged = `${stateFile()}.${process.pid}.tmp`;
48359
48385
  fs25.mkdirSync(versionsDir(), { recursive: true });
48360
- fs25.writeFileSync(stateFile(), `${JSON.stringify(state, null, 2)}
48386
+ fs25.writeFileSync(staged, `${JSON.stringify(state, null, 2)}
48361
48387
  `);
48388
+ fs25.renameSync(staged, stateFile());
48362
48389
  }
48363
- function markGood(version) {
48390
+ function verify(candidate) {
48364
48391
  const state = readState();
48365
- state.good = [version, ...state.good.filter((v) => v !== version)].slice(0, KEEP);
48392
+ const changed = state.verified !== candidate.version;
48393
+ state.verified = candidate.version;
48394
+ if (state.retry?.version === candidate.version || (state.retry?.after ?? 0) <= Date.now()) delete state.retry;
48395
+ if (candidate.target) remember(state, candidate.target);
48366
48396
  writeState(state);
48367
- for (const name of fs25.readdirSync(versionsDir())) {
48368
- if (name === "state.json" || state.good.includes(name) || name.endsWith(".tmp") || busy(path29.join(versionsDir(), name))) continue;
48369
- fs25.rmSync(path29.join(versionsDir(), name), { recursive: true, force: true });
48397
+ if (!changed) return;
48398
+ for (const version of fs25.readdirSync(versionsDir()).filter(isVersion)) {
48399
+ if (version !== candidate.version && !busy(versionDir(version))) fs25.rmSync(versionDir(version), { recursive: true, force: true });
48370
48400
  }
48371
48401
  }
48372
- function markBad(version) {
48373
- const state = readState();
48374
- state.bad = [.../* @__PURE__ */ new Set([...state.bad, version])];
48375
- state.good = state.good.filter((v) => v !== version);
48376
- writeState(state);
48402
+ function cooling(version) {
48403
+ const { retry: retry2 } = readState();
48404
+ return retry2?.version === version && retry2.after > Date.now();
48377
48405
  }
48378
48406
  async function askTarget(machine) {
48379
48407
  const alpha = acceptAlphaUpdates();
@@ -48384,7 +48412,7 @@ async function askTarget(machine) {
48384
48412
  if (!answer.ok) return null;
48385
48413
  const { version, restartable, alpha: selectedAlpha, rollback } = await answer.json();
48386
48414
  if (acceptAlphaUpdates() !== alpha) return null;
48387
- return typeof version === "string" && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version) ? { version, restartable: restartable === true, alpha: selectedAlpha === true, rollback } : null;
48415
+ return isVersion(version) ? { version, restartable: restartable === true, alpha: selectedAlpha === true, rollback } : null;
48388
48416
  } catch {
48389
48417
  return null;
48390
48418
  }
@@ -48393,47 +48421,52 @@ function waiting(target, current2) {
48393
48421
  const state = readState();
48394
48422
  return !target.alpha && !!state.alpha?.includes(current2) && compare(target.version, current2) < 0 && (target.rollback === void 0 || target.rollback === (state.rollbackAt?.[current2] ?? 0));
48395
48423
  }
48396
- function remember(target) {
48397
- const state = readState();
48398
- if (target.alpha) state.alpha = [.../* @__PURE__ */ new Set([...state.alpha ?? [], target.version])];
48399
- if (target.rollback !== void 0) state.rollbackAt = { ...state.rollbackAt, [target.version]: target.rollback };
48400
- writeState(state);
48424
+ function remember(state, target) {
48425
+ let changed = false;
48426
+ if (target.alpha && !state.alpha?.includes(target.version)) {
48427
+ state.alpha = [...state.alpha ?? [], target.version];
48428
+ changed = true;
48429
+ }
48430
+ if (target.rollback !== void 0 && state.rollbackAt?.[target.version] !== target.rollback) {
48431
+ state.rollbackAt = { ...state.rollbackAt, [target.version]: target.rollback };
48432
+ changed = true;
48433
+ }
48434
+ return changed;
48435
+ }
48436
+ function verifiedCandidate() {
48437
+ const { verified } = readState();
48438
+ if (!verified) return null;
48439
+ const entry2 = entryOf(versionDir(verified));
48440
+ return fs25.existsSync(entry2) ? { version: verified, entry: entry2 } : null;
48401
48441
  }
48402
48442
  function provenNewer(own2) {
48403
- const proven = readState().good.find((v) => fs25.existsSync(entryOf(versionDir(v))));
48404
- return proven && compare(proven, own2) > 0 ? proven : null;
48443
+ const verified = verifiedCandidate();
48444
+ return verified && compare(verified.version, own2) > 0 ? verified.version : null;
48405
48445
  }
48406
- async function candidates(own2, source = "terminal") {
48407
- const state = readState();
48408
- const proven = provenNewer(own2.version);
48409
- const current2 = proven ? { version: proven, entry: entryOf(versionDir(proven)) } : own2;
48446
+ var cached2 = (candidate) => candidate.entry === entryOf(versionDir(candidate.version));
48447
+ async function findUpdate(own2, current2, source, online = false) {
48410
48448
  const desired = await askTarget(machineId());
48411
- const target = desired?.version;
48412
- if (!desired || !target || waiting(desired, current2.version) || state.bad.includes(target)) return [current2];
48413
- if (target === current2.version) {
48414
- remember(desired);
48415
- return [current2];
48416
- }
48417
- if (target === own2.version) {
48418
- remember(desired);
48419
- if (compare(target, current2.version) < 0) logRunner("launcher", "rollback", { version: target, source });
48420
- return [own2, current2];
48421
- }
48422
- const got = await install2(target);
48423
- if (got.ok) {
48424
- const latest = await askTarget(machineId());
48425
- if (!latest || latest.version !== target || waiting(latest, current2.version)) return [current2];
48426
- remember(latest);
48427
- const known2 = state.good.includes(target);
48428
- logRunner("launcher", "update_ready", { version: target, source, stage: "download" });
48429
- if (compare(target, current2.version) < 0) logRunner("launcher", "rollback", { version: target, source });
48430
- return [{ version: target, entry: entryOf(got.dir), fresh: !known2 }, current2];
48431
- }
48432
- logRunner("launcher", "update_failed", { version: target, source, stage: "download", code: got.why });
48433
- if (got.why === "node") status(t.nodeTooOld(got.detail));
48434
- return [current2];
48435
- }
48436
- function runOnce(candidate, options) {
48449
+ if (!desired || online && !desired.restartable || waiting(desired, current2.version)) return null;
48450
+ const version = desired.version;
48451
+ if (version === current2.version) return { ...current2, target: desired };
48452
+ if (cooling(version)) return null;
48453
+ let entry2 = own2.entry;
48454
+ if (version !== own2.version || !fs25.existsSync(entry2)) {
48455
+ const got = await install2(version);
48456
+ if (!got.ok) {
48457
+ logRunner("launcher", "update_failed", { version, source, stage: "download", code: got.why });
48458
+ if (got.why === "node") status(t.nodeTooOld(got.detail));
48459
+ else if (online) status(t.updateDownloadFailed());
48460
+ return null;
48461
+ }
48462
+ entry2 = entryOf(got.dir);
48463
+ }
48464
+ const latest = await askTarget(machineId());
48465
+ if (latest?.version !== version || online && !latest.restartable || waiting(latest, current2.version)) return null;
48466
+ logRunner("launcher", "update_ready", { version, source, stage: "download" });
48467
+ return { version, entry: entry2, target: latest };
48468
+ }
48469
+ function runOnce(own2, candidate, options, trial) {
48437
48470
  const fields2 = { version: candidate.version, source: options.kind ?? "terminal" };
48438
48471
  logRunner("launcher", "starting", fields2);
48439
48472
  return new Promise((resolve2) => {
@@ -48452,22 +48485,14 @@ function runOnce(candidate, options) {
48452
48485
  if (checking || stopping2 || update3) return;
48453
48486
  checking = true;
48454
48487
  try {
48455
- const desired = await askTarget(machineId());
48456
- if (!desired?.restartable || waiting(desired, candidate.version)) return;
48457
- const target = desired.version;
48458
- if (!target || target === candidate.version || readState().bad.includes(target)) return;
48459
- const got = await install2(target);
48460
- if (!got.ok) {
48461
- logRunner("launcher", "update_failed", { ...fields2, version: target, stage: "download", code: got.why });
48462
- status("Runner \u66F4\u65B0\u4E0B\u8F7D\u5931\u8D25\uFF0C\u7EE7\u7EED\u8FD0\u884C\u5F53\u524D\u7248\u672C\uFF0C\u7A0D\u540E\u91CD\u8BD5\u3002");
48488
+ const next = await findUpdate(own2, candidate, fields2.source, true);
48489
+ if (!next || stopping2 || !child.connected) return;
48490
+ if (next.version === candidate.version) {
48491
+ const state = readState();
48492
+ if (next.target && state.verified === candidate.version && remember(state, next.target)) writeState(state);
48463
48493
  return;
48464
48494
  }
48465
- if (stopping2 || child.exitCode !== null || child.signalCode !== null) return;
48466
- const latest = await askTarget(machineId());
48467
- if (!latest?.restartable || latest.version !== target || waiting(latest, candidate.version)) return;
48468
- remember(latest);
48469
- update3 = { version: target, entry: entryOf(got.dir), fresh: !readState().good.includes(target) };
48470
- logRunner("launcher", "update_ready", { ...fields2, version: target, stage: "download" });
48495
+ update3 = next;
48471
48496
  child.send({ type: "update" }, () => {
48472
48497
  });
48473
48498
  } finally {
@@ -48479,20 +48504,15 @@ function runOnce(candidate, options) {
48479
48504
  });
48480
48505
  }, Number(process.env.WILDCRANE_UPDATE_MS) || 6e4);
48481
48506
  let connected = false;
48482
- let timer = null;
48483
48507
  let timedOut = false;
48484
48508
  let stopping2 = false;
48485
48509
  let duplicate = false;
48486
48510
  let forceKill;
48487
- const watchConnection = () => {
48488
- if (timer) clearTimeout(timer);
48489
- timer = setTimeout(() => {
48490
- timedOut = true;
48491
- child.kill("SIGTERM");
48492
- forceKill = setTimeout(() => child.kill("SIGKILL"), 5e3);
48493
- }, Number(process.env.WILDCRANE_CONNECT_MS) || CONNECT_MS);
48494
- };
48495
- if (candidate.fresh) watchConnection();
48511
+ const timer = trial ? setTimeout(() => {
48512
+ timedOut = true;
48513
+ child.kill("SIGTERM");
48514
+ forceKill = setTimeout(() => child.kill("SIGKILL"), 5e3);
48515
+ }, Number(process.env.WILDCRANE_CONNECT_MS) || CONNECT_MS) : void 0;
48496
48516
  const forward = (signal) => () => {
48497
48517
  stopping2 = true;
48498
48518
  child.kill(signal);
@@ -48508,7 +48528,6 @@ function runOnce(candidate, options) {
48508
48528
  if (update3) logRunner("launcher", "update_deferred", { ...fields2, version: update3.version });
48509
48529
  update3 = null;
48510
48530
  }
48511
- if (message.type === "reconnecting" && candidate.fresh && !connected && !timedOut) watchConnection();
48512
48531
  if (message.type === "waiting") {
48513
48532
  duplicate = true;
48514
48533
  process.stderr.write(`${t.alreadyRunning()}
@@ -48516,14 +48535,14 @@ function runOnce(candidate, options) {
48516
48535
  child.kill("SIGTERM");
48517
48536
  return;
48518
48537
  }
48538
+ if (timedOut || duplicate || stopping2) return;
48519
48539
  if (message.type === "connected" && !connected) {
48520
48540
  connected = true;
48521
48541
  logRunner("launcher", "connected", fields2);
48522
48542
  if (timer) clearTimeout(timer);
48523
- if (candidate.entry.startsWith(versionsDir() + path29.sep)) fs25.rmSync(legacyVersionsDir(), { recursive: true, force: true });
48524
- const installed = candidate.entry.startsWith(versionsDir() + path29.sep);
48525
- if (candidate.fresh || installed && !readState().good.includes(candidate.version)) markGood(candidate.version);
48526
- if (candidate.fresh) status(t.updated(candidate.version));
48543
+ if (cached2(candidate)) fs25.rmSync(legacyVersionsDir(), { recursive: true, force: true });
48544
+ verify(candidate);
48545
+ if (trial) status(t.updated(candidate.version));
48527
48546
  }
48528
48547
  options.onMessage?.(message);
48529
48548
  });
@@ -48541,62 +48560,63 @@ function runOnce(candidate, options) {
48541
48560
  logRunner("launcher", "exited", { ...fields2, exitCode: code, signal });
48542
48561
  if (spawnError) {
48543
48562
  logRunner("launcher", "startup_failed", { ...fields2, stage: "spawn", code: errno(spawnError) });
48544
- status(`Runner \u65E0\u6CD5\u542F\u52A8\uFF1A${spawnError.message}`);
48545
- return resolve2({ exit: 1 });
48563
+ status(t.spawnFailed(spawnError.message));
48564
+ return resolve2(trial && !stopping2 ? { failed: "crashed" } : { exit: 1 });
48546
48565
  }
48547
48566
  if (duplicate || code === EXIT_ALREADY_RUNNING) {
48548
48567
  logRunner("launcher", "startup_failed", { ...fields2, code: "already_running" });
48549
48568
  return resolve2({ exit: EXIT_ALREADY_RUNNING });
48550
48569
  }
48551
48570
  if (code === EXIT_UPDATE && update3 && !stopping2) return resolve2({ update: update3 });
48552
- const expectedExit = code === 0 || code === EXIT_REFUSED || code === EXIT_OUTDATED;
48553
48571
  const failed = timedOut ? "timeout" : "crashed";
48554
- if (!connected && !stopping2 && (timedOut || !expectedExit)) {
48572
+ if (!connected && !stopping2 && (trial || code === null || code === 1)) {
48555
48573
  logRunner("launcher", "startup_failed", { ...fields2, code: failed });
48556
48574
  }
48557
- if (connected || !candidate.fresh || stopping2) return resolve2({ exit: code ?? (signal ? 1 : 0) });
48558
- if (!timedOut && expectedExit) return resolve2({ exit: code });
48559
- resolve2({ failed });
48575
+ resolve2(trial && !connected && !stopping2 ? { failed } : { exit: code ?? (signal ? 1 : 0) });
48560
48576
  });
48561
48577
  });
48562
48578
  }
48563
48579
  async function launch(own2, options = {}) {
48564
48580
  startRunnerLogMaintenance();
48565
48581
  const source = options.kind ?? "terminal";
48582
+ const release = cached2(own2) ? hold(versionDir(own2.version)) : void 0;
48566
48583
  try {
48567
48584
  return await supervise(own2, source, options);
48568
48585
  } catch (error) {
48569
48586
  logRunner("launcher", "startup_failed", { version: own2.version, source, code: errno(error) });
48570
48587
  throw error;
48588
+ } finally {
48589
+ release?.();
48571
48590
  }
48572
48591
  }
48573
48592
  async function supervise(own2, source, options) {
48574
- const list3 = await candidates(own2, source);
48575
- for (let i = 0; i < list3.length; i++) {
48576
- if (options.signal?.aborted) return 0;
48577
- const candidate = list3[i];
48578
- const outcome = await runOnce(candidate, options);
48593
+ const verified = verifiedCandidate();
48594
+ const current2 = verified && (cached2(own2) || compare(verified.version, own2.version) > 0) ? verified : own2;
48595
+ let candidate = await findUpdate(own2, current2, source) ?? current2;
48596
+ let previous = candidate.version === current2.version ? null : current2;
48597
+ while (!options.signal?.aborted) {
48598
+ if (previous && compare(candidate.version, previous.version) < 0) logRunner("launcher", "rollback", { version: candidate.version, source });
48599
+ const outcome = await runOnce(own2, candidate, options, previous !== null);
48579
48600
  if ("exit" in outcome) return outcome.exit;
48580
48601
  if ("update" in outcome) {
48581
48602
  const latest = await askTarget(machineId());
48582
- if (!latest || latest.version !== outcome.update.version || waiting(latest, candidate.version)) {
48583
- list3.splice(i + 1, list3.length, candidate);
48603
+ if (!latest?.restartable || latest.version !== outcome.update.version || waiting(latest, candidate.version)) {
48604
+ previous = null;
48584
48605
  continue;
48585
48606
  }
48586
- if (compare(outcome.update.version, candidate.version) < 0) {
48587
- logRunner("launcher", "rollback", { version: outcome.update.version, source });
48588
- }
48589
- list3.splice(i + 1, list3.length, outcome.update, candidate);
48590
- continue;
48591
- }
48592
- markBad(candidate.version);
48593
- const next = list3[i + 1];
48594
- if (next) {
48595
- logRunner("launcher", "rollback", { version: next.version, source, code: outcome.failed });
48596
- status(t.rolledBack(next.version));
48607
+ previous = candidate;
48608
+ candidate = { ...outcome.update, target: latest };
48609
+ } else if (previous) {
48610
+ const state = readState();
48611
+ state.retry = { version: candidate.version, after: Date.now() + RETRY_MS };
48612
+ writeState(state);
48613
+ logRunner("launcher", "rollback", { version: previous.version, source, code: outcome.failed });
48614
+ status(t.rolledBack(previous.version));
48615
+ candidate = previous;
48616
+ previous = null;
48597
48617
  }
48598
48618
  }
48599
- return 1;
48619
+ return 0;
48600
48620
  }
48601
48621
 
48602
48622
  // src/settings-server.ts
@@ -49245,7 +49265,7 @@ exec ${shellLine} "$@"
49245
49265
  fs29.writeFileSync(file2, text2, { mode: 493 });
49246
49266
  return dir;
49247
49267
  }
49248
- var KEEP2 = 256 * 1024;
49268
+ var KEEP = 256 * 1024;
49249
49269
 
49250
49270
  // src/lock.ts
49251
49271
  import crypto8 from "node:crypto";