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/plugin.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;
@@ -7278,7 +7278,7 @@ var require_util2 = __commonJS({
7278
7278
  exports.getEnumValues = getEnumValues3;
7279
7279
  exports.joinValues = joinValues3;
7280
7280
  exports.jsonStringifyReplacer = jsonStringifyReplacer3;
7281
- exports.cached = cached4;
7281
+ exports.cached = cached5;
7282
7282
  exports.nullish = nullish4;
7283
7283
  exports.cleanRegex = cleanRegex3;
7284
7284
  exports.floatSafeRemainder = floatSafeRemainder4;
@@ -7380,7 +7380,7 @@ var require_util2 = __commonJS({
7380
7380
  return this._value;
7381
7381
  }
7382
7382
  };
7383
- function cached4(getter) {
7383
+ function cached5(getter) {
7384
7384
  return new Cached3(getter);
7385
7385
  }
7386
7386
  function nullish4(input2) {
@@ -7529,7 +7529,7 @@ var require_util2 = __commonJS({
7529
7529
  function isObject3(data) {
7530
7530
  return typeof data === "object" && data !== null && !Array.isArray(data);
7531
7531
  }
7532
- exports.allowsEval = cached4(() => {
7532
+ exports.allowsEval = cached5(() => {
7533
7533
  if (core_js_1.globalConfig.jitless) {
7534
7534
  return false;
7535
7535
  }
@@ -12123,9 +12123,9 @@ var require_memoizer = __commonJS({
12123
12123
  var ASSUMED3 = 1;
12124
12124
  var PROVEN3 = 2;
12125
12125
  function isRecursive3(inst, stack, resolve2) {
12126
- const cached4 = recursive3.get(inst);
12127
- if (cached4 !== void 0)
12128
- return cached4 ? PROVEN3 : NONE3;
12126
+ const cached5 = recursive3.get(inst);
12127
+ if (cached5 !== void 0)
12128
+ return cached5 ? PROVEN3 : NONE3;
12129
12129
  if (stack.has(inst))
12130
12130
  return PROVEN3;
12131
12131
  stack.add(inst);
@@ -29913,15 +29913,15 @@ var require_visit = __commonJS({
29913
29913
  };
29914
29914
  const cache = /* @__PURE__ */ new Map();
29915
29915
  function run3(s) {
29916
- const cached4 = cache.get(s);
29917
- if (cached4 === RESOLVING2) {
29916
+ const cached5 = cache.get(s);
29917
+ if (cached5 === RESOLVING2) {
29918
29918
  return new schemas.$ZodLazy({
29919
29919
  type: "lazy",
29920
29920
  getter: () => cache.get(s)
29921
29921
  });
29922
29922
  }
29923
- if (cached4 !== void 0)
29924
- return cached4;
29923
+ if (cached5 !== void 0)
29924
+ return cached5;
29925
29925
  cache.set(s, RESOLVING2);
29926
29926
  const inner = mapInner(s);
29927
29927
  const mapped = fn(inner, inner !== s);
@@ -76468,9 +76468,9 @@ var NONE = 0;
76468
76468
  var ASSUMED = 1;
76469
76469
  var PROVEN = 2;
76470
76470
  function isRecursive(inst, stack, resolve2) {
76471
- const cached4 = recursive.get(inst);
76472
- if (cached4 !== void 0)
76473
- return cached4 ? PROVEN : NONE;
76471
+ const cached5 = recursive.get(inst);
76472
+ if (cached5 !== void 0)
76473
+ return cached5 ? PROVEN : NONE;
76474
76474
  if (stack.has(inst))
76475
76475
  return PROVEN;
76476
76476
  stack.add(inst);
@@ -90904,15 +90904,15 @@ function visit(schema, fnOrHandlers) {
90904
90904
  };
90905
90905
  const cache = /* @__PURE__ */ new Map();
90906
90906
  function run3(s) {
90907
- const cached4 = cache.get(s);
90908
- if (cached4 === RESOLVING) {
90907
+ const cached5 = cache.get(s);
90908
+ if (cached5 === RESOLVING) {
90909
90909
  return new $ZodLazy({
90910
90910
  type: "lazy",
90911
90911
  getter: () => cache.get(s)
90912
90912
  });
90913
90913
  }
90914
- if (cached4 !== void 0)
90915
- return cached4;
90914
+ if (cached5 !== void 0)
90915
+ return cached5;
90916
90916
  cache.set(s, RESOLVING);
90917
90917
  const inner = mapInner(s);
90918
90918
  const mapped = fn(inner, inner !== s);
@@ -98549,9 +98549,9 @@ var NONE2 = 0;
98549
98549
  var ASSUMED2 = 1;
98550
98550
  var PROVEN2 = 2;
98551
98551
  function isRecursive2(inst, stack, resolve2) {
98552
- const cached4 = recursive2.get(inst);
98553
- if (cached4 !== void 0)
98554
- return cached4 ? PROVEN2 : NONE2;
98552
+ const cached5 = recursive2.get(inst);
98553
+ if (cached5 !== void 0)
98554
+ return cached5 ? PROVEN2 : NONE2;
98555
98555
  if (stack.has(inst))
98556
98556
  return PROVEN2;
98557
98557
  stack.add(inst);
@@ -107903,7 +107903,7 @@ function rootAbove(board) {
107903
107903
  var NESTED_STATE = /(^|[/\\])\.akb[/\\](?:(?:boards|hidden-boards)[/\\])?\.akb(?=[/\\]|$)/;
107904
107904
  var InvalidBoardStatePath = class extends BoardError {
107905
107905
  constructor(file3, state2, id2) {
107906
- const use = state2 ? `Use ${state2}${id2 ? ` or an .assets/${id2}/\u2026 reference` : ""}.` : "Use the board\u2019s project-local .akb/hidden-boards/ or .akb/boards/ directory.";
107906
+ const use = state2 ? `Use ${state2}${id2 ? ` or an .assets/${id2}/\u2026 reference` : ""}.` : "Use the board\u2019s project-local state directory.";
107907
107907
  super(`Invalid nested board state path: ${file3}. ${use}`, { kind: "board-state-path" });
107908
107908
  }
107909
107909
  };
@@ -107923,18 +107923,21 @@ function stateLayout(board, root2) {
107923
107923
  }
107924
107924
  const hiddenPrefix = `.akb${path3.sep}`;
107925
107925
  const hidden = relative.startsWith(hiddenPrefix);
107926
- const state2 = path3.join(project, ".akb", hidden ? "hidden-boards" : "boards", (hidden ? relative.slice(hiddenPrefix.length) : relative) || "_root");
107926
+ const runnerBoard = relative === `${hiddenPrefix}kanban`;
107927
+ const akb = path3.join(project, ".akb");
107928
+ const state2 = runnerBoard ? path3.join(akb, "state") : hidden ? path3.join(akb, "hidden-boards", relative.slice(hiddenPrefix.length)) : path3.join(akb, "boards", relative || "_root");
107927
107929
  assertBoardStatePath(state2, state2);
107928
107930
  assertBoardStatePath(realPathOf(state2), state2);
107929
- const legacy = hidden ? path3.join(project, ".akb", "boards", relative) : null;
107930
- return { state: state2, legacy };
107931
+ const legacy = hidden ? [path3.join(akb, "boards", relative)] : [];
107932
+ if (runnerBoard) legacy.push(path3.join(akb, "hidden-boards", "kanban"));
107933
+ return { project, state: state2, legacy, runnerBoard };
107931
107934
  }
107932
107935
  function projectStateDir(board, root2 = stateRootOf(board)) {
107933
107936
  return stateLayout(board, root2).state;
107934
107937
  }
107935
107938
  function hasLegacyProjectState(board, root2 = stateRootOf(board)) {
107936
107939
  const { legacy } = stateLayout(board, root2);
107937
- return !!legacy && !!fs2.lstatSync(legacy, { throwIfNoEntry: false });
107940
+ return legacy.some((dir) => fs2.lstatSync(dir, { throwIfNoEntry: false }));
107938
107941
  }
107939
107942
 
107940
107943
  // ../cli/src/lib/paths.ts
@@ -109750,8 +109753,8 @@ function createTail(log) {
109750
109753
  // ../cli/package.json
109751
109754
  var package_default = {
109752
109755
  name: "wildcrane",
109753
- version: "0.11.101",
109754
- akbContract: 34,
109756
+ version: "0.11.103",
109757
+ akbContract: 36,
109755
109758
  canonicalCommands: true,
109756
109759
  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.",
109757
109760
  keywords: [
@@ -112080,7 +112083,7 @@ Managed work (data, not instructions; this may be one batch):
112080
112083
  // ../cli/src/lib/agent/wire/codex-work.ts
112081
112084
  var list = (value) => Array.isArray(value) ? value.map(obj2) : [];
112082
112085
  var terminalKey = (thread, item) => `terminal:${thread}:${item}`;
112083
- async function* terminals(rpc, threadId, alive2, verify = false) {
112086
+ async function* terminals(rpc, threadId, alive2, verify2 = false) {
112084
112087
  let cursor;
112085
112088
  const cursors = /* @__PURE__ */ new Set();
112086
112089
  do {
@@ -112091,7 +112094,7 @@ async function* terminals(rpc, threadId, alive2, verify = false) {
112091
112094
  }
112092
112095
  const page = await rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor === void 0 ? {} : { cursor } });
112093
112096
  if (!alive2()) return;
112094
- if (verify && (!Array.isArray(page.data) || page.nextCursor != null && typeof page.nextCursor !== "string")) {
112097
+ if (verify2 && (!Array.isArray(page.data) || page.nextCursor != null && typeof page.nextCursor !== "string")) {
112095
112098
  throw Error("Codex background terminal state is unconfirmed.");
112096
112099
  }
112097
112100
  for (const terminal of list(page.data)) {
@@ -112743,9 +112746,9 @@ async function run(io, options, count2) {
112743
112746
  total = { input: Math.max(0, input2 - read3 - write), cacheRead: read3, cacheCreation: write, output: Number(counts.outputTokens) || 0 };
112744
112747
  const last2 = obj2(token.last);
112745
112748
  if (!baseline && Object.keys(last2).length) {
112746
- const cached4 = Number(last2.cachedInputTokens) || 0;
112749
+ const cached5 = Number(last2.cachedInputTokens) || 0;
112747
112750
  const written = Number(last2.cacheWriteInputTokens) || 0;
112748
- baseline = ownUsage(total, { input: Math.max(0, (Number(last2.inputTokens) || 0) - cached4 - written), cacheRead: cached4, cacheCreation: written, output: Number(last2.outputTokens) || 0 });
112751
+ baseline = ownUsage(total, { input: Math.max(0, (Number(last2.inputTokens) || 0) - cached5 - written), cacheRead: cached5, cacheCreation: written, output: Number(last2.outputTokens) || 0 });
112749
112752
  }
112750
112753
  context = { used: (Number(last2.inputTokens) || 0) + (Number(last2.outputTokens) || 0), ...Number(token.modelContextWindow) > 0 ? { limit: Number(token.modelContextWindow) } : {} };
112751
112754
  io.gotContext?.(context);
@@ -113532,10 +113535,10 @@ function dshHome(argv) {
113532
113535
  const binary = argv[0];
113533
113536
  if (!binary) return void 0;
113534
113537
  const names = process.platform === "win32" && !path21.extname(binary) ? [".exe", ".cmd"].map((ext) => binary + ext) : [binary];
113535
- const candidates2 = binary.includes("/") || binary.includes("\\") ? names : (process.env.PATH ?? "").split(path21.delimiter).filter(Boolean).flatMap((dir2) => names.map((name) => path21.join(dir2, name)));
113538
+ const candidates = binary.includes("/") || binary.includes("\\") ? names : (process.env.PATH ?? "").split(path21.delimiter).filter(Boolean).flatMap((dir2) => names.map((name) => path21.join(dir2, name)));
113536
113539
  let dir;
113537
113540
  try {
113538
- const found = candidates2.find((candidate) => fs17.existsSync(candidate));
113541
+ const found = candidates.find((candidate) => fs17.existsSync(candidate));
113539
113542
  if (!found) return void 0;
113540
113543
  const script = /\.cmd$/i.test(found) ? shimTarget(fs17.readFileSync(found, "utf8"), found)?.script : void 0;
113541
113544
  dir = path21.dirname(fs17.realpathSync(script ?? found));
@@ -114258,9 +114261,8 @@ function machineId() {
114258
114261
  var machineName = () => os4.hostname().replace(/\.local$/, "");
114259
114262
 
114260
114263
  // src/protocol.ts
114261
- var VERSION = true ? "0.6.119" : "0.0.0";
114262
- var AKB_VERSION = true ? "0.11.101" : "0.0.0";
114263
- var EXIT_REFUSED = 10;
114264
+ var VERSION = true ? "0.6.121" : "0.0.0";
114265
+ var AKB_VERSION = true ? "0.11.103" : "0.0.0";
114264
114266
  var EXIT_OUTDATED = 11;
114265
114267
  var EXIT_UPDATE = 12;
114266
114268
  var EXIT_ALREADY_RUNNING = 13;
@@ -114540,6 +114542,22 @@ var unsent = (dir) => fs22.existsSync(unsentFile(dir));
114540
114542
  var holds = /* @__PURE__ */ new Map();
114541
114543
  var holdsDir = () => path26.join(runnerHome(), "holds");
114542
114544
  var holdFile = (dir) => path26.join(holdsDir(), `${crypto4.createHash("sha256").update(dir).digest("hex")}.${process.pid}`);
114545
+ function hold(dir) {
114546
+ fs22.mkdirSync(holdsDir(), { recursive: true, mode: 448 });
114547
+ fs22.writeFileSync(holdFile(dir), "", { mode: 384 });
114548
+ holds.set(dir, (holds.get(dir) ?? 0) + 1);
114549
+ let held2 = true;
114550
+ return () => {
114551
+ if (!held2) return;
114552
+ held2 = false;
114553
+ const left = holds.get(dir) - 1;
114554
+ if (left) holds.set(dir, left);
114555
+ else {
114556
+ holds.delete(dir);
114557
+ fs22.rmSync(holdFile(dir), { force: true });
114558
+ }
114559
+ };
114560
+ }
114543
114561
  function paused(dir) {
114544
114562
  try {
114545
114563
  const file3 = path26.join(projectStateDir(path26.join(akbDir(dir), "kanban")), SESSIONS_FILE);
@@ -114620,6 +114638,8 @@ ${url2}`,
114620
114638
  refused: (why) => `WildCrane \u62D2\u7EDD\u4E86\u8FDE\u63A5\uFF1A${why}`,
114621
114639
  updated: (version3) => `\u5DF2\u66F4\u65B0\u5230 ${version3}`,
114622
114640
  rolledBack: (version3) => `\u65B0\u7248\u672C\u672A\u80FD\u542F\u52A8\uFF0C\u5DF2\u9000\u56DE ${version3}`,
114641
+ spawnFailed: (why) => `Runner \u65E0\u6CD5\u542F\u52A8\uFF1A${why}`,
114642
+ updateDownloadFailed: () => "Runner \u66F4\u65B0\u4E0B\u8F7D\u5931\u8D25\uFF0C\u7EE7\u7EED\u8FD0\u884C\u5F53\u524D\u7248\u672C\uFF0C\u7A0D\u540E\u91CD\u8BD5\u3002",
114623
114643
  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`,
114624
114644
  alreadyRunning: () => "\u672C\u673A\u5DF2\u6709 WildCrane Runner \u6B63\u5728\u8FD0\u884C\uFF0C\u65E0\u6CD5\u542F\u52A8\u7B2C\u4E8C\u4E2A\u5B9E\u4F8B\u3002",
114625
114645
  stopped: () => "\u5DF2\u505C\u6B62"
@@ -114637,6 +114657,8 @@ ${url2}`,
114637
114657
  refused: (why) => `WildCrane refused the connection: ${why}`,
114638
114658
  updated: (version3) => `Updated to ${version3}`,
114639
114659
  rolledBack: (version3) => `The new version did not start \u2014 back on ${version3}`,
114660
+ spawnFailed: (why) => `Runner could not start: ${why}`,
114661
+ updateDownloadFailed: () => "The Runner update could not download. The current version will keep running and retry later.",
114640
114662
  nodeTooOld: (range) => `The new version needs Node ${range}. Update Node; running the current version for now.`,
114641
114663
  alreadyRunning: () => "A WildCrane Runner is already running on this computer. A second instance cannot start.",
114642
114664
  stopped: () => "Stopped"
@@ -115013,35 +115035,40 @@ function logRunner(component, event2, fields2 = {}) {
115013
115035
  // src/launcher.ts
115014
115036
  var ASK_MS = 5e3;
115015
115037
  var CONNECT_MS = 2 * 6e4;
115016
- var KEEP2 = 2;
115038
+ var RETRY_MS = 5 * 6e4;
115039
+ var isVersion = (value) => typeof value === "string" && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(value);
115017
115040
  var stateFile = () => path30.join(versionsDir(), "state.json");
115018
115041
  function readState() {
115019
115042
  try {
115020
- const held2 = JSON.parse(fs26.readFileSync(stateFile(), "utf8"));
115021
- return { ...held2, good: held2.good ?? [], bad: held2.bad ?? [] };
115043
+ const { verified, good, retry: retry2, alpha, rollbackAt } = JSON.parse(fs26.readFileSync(stateFile(), "utf8"));
115044
+ const last2 = verified === void 0 && Array.isArray(good) ? good[0] : verified;
115045
+ return { verified: isVersion(last2) ? last2 : null, retry: retry2, alpha, rollbackAt };
115022
115046
  } catch {
115023
- return { good: [], bad: [] };
115047
+ return { verified: null };
115024
115048
  }
115025
115049
  }
115026
115050
  function writeState(state2) {
115051
+ const staged = `${stateFile()}.${process.pid}.tmp`;
115027
115052
  fs26.mkdirSync(versionsDir(), { recursive: true });
115028
- fs26.writeFileSync(stateFile(), `${JSON.stringify(state2, null, 2)}
115053
+ fs26.writeFileSync(staged, `${JSON.stringify(state2, null, 2)}
115029
115054
  `);
115055
+ fs26.renameSync(staged, stateFile());
115030
115056
  }
115031
- function markGood(version3) {
115057
+ function verify(candidate) {
115032
115058
  const state2 = readState();
115033
- state2.good = [version3, ...state2.good.filter((v) => v !== version3)].slice(0, KEEP2);
115059
+ const changed = state2.verified !== candidate.version;
115060
+ state2.verified = candidate.version;
115061
+ if (state2.retry?.version === candidate.version || (state2.retry?.after ?? 0) <= Date.now()) delete state2.retry;
115062
+ if (candidate.target) remember(state2, candidate.target);
115034
115063
  writeState(state2);
115035
- for (const name of fs26.readdirSync(versionsDir())) {
115036
- if (name === "state.json" || state2.good.includes(name) || name.endsWith(".tmp") || busy(path30.join(versionsDir(), name))) continue;
115037
- fs26.rmSync(path30.join(versionsDir(), name), { recursive: true, force: true });
115064
+ if (!changed) return;
115065
+ for (const version3 of fs26.readdirSync(versionsDir()).filter(isVersion)) {
115066
+ if (version3 !== candidate.version && !busy(versionDir(version3))) fs26.rmSync(versionDir(version3), { recursive: true, force: true });
115038
115067
  }
115039
115068
  }
115040
- function markBad(version3) {
115041
- const state2 = readState();
115042
- state2.bad = [.../* @__PURE__ */ new Set([...state2.bad, version3])];
115043
- state2.good = state2.good.filter((v) => v !== version3);
115044
- writeState(state2);
115069
+ function cooling(version3) {
115070
+ const { retry: retry2 } = readState();
115071
+ return retry2?.version === version3 && retry2.after > Date.now();
115045
115072
  }
115046
115073
  async function askTarget(machine) {
115047
115074
  const alpha = acceptAlphaUpdates();
@@ -115052,7 +115079,7 @@ async function askTarget(machine) {
115052
115079
  if (!answer.ok) return null;
115053
115080
  const { version: version3, restartable, alpha: selectedAlpha, rollback } = await answer.json();
115054
115081
  if (acceptAlphaUpdates() !== alpha) return null;
115055
- return typeof version3 === "string" && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version3) ? { version: version3, restartable: restartable === true, alpha: selectedAlpha === true, rollback } : null;
115082
+ return isVersion(version3) ? { version: version3, restartable: restartable === true, alpha: selectedAlpha === true, rollback } : null;
115056
115083
  } catch {
115057
115084
  return null;
115058
115085
  }
@@ -115061,47 +115088,52 @@ function waiting(target, current2) {
115061
115088
  const state2 = readState();
115062
115089
  return !target.alpha && !!state2.alpha?.includes(current2) && compare2(target.version, current2) < 0 && (target.rollback === void 0 || target.rollback === (state2.rollbackAt?.[current2] ?? 0));
115063
115090
  }
115064
- function remember(target) {
115065
- const state2 = readState();
115066
- if (target.alpha) state2.alpha = [.../* @__PURE__ */ new Set([...state2.alpha ?? [], target.version])];
115067
- if (target.rollback !== void 0) state2.rollbackAt = { ...state2.rollbackAt, [target.version]: target.rollback };
115068
- writeState(state2);
115091
+ function remember(state2, target) {
115092
+ let changed = false;
115093
+ if (target.alpha && !state2.alpha?.includes(target.version)) {
115094
+ state2.alpha = [...state2.alpha ?? [], target.version];
115095
+ changed = true;
115096
+ }
115097
+ if (target.rollback !== void 0 && state2.rollbackAt?.[target.version] !== target.rollback) {
115098
+ state2.rollbackAt = { ...state2.rollbackAt, [target.version]: target.rollback };
115099
+ changed = true;
115100
+ }
115101
+ return changed;
115102
+ }
115103
+ function verifiedCandidate() {
115104
+ const { verified } = readState();
115105
+ if (!verified) return null;
115106
+ const entry = entryOf(versionDir(verified));
115107
+ return fs26.existsSync(entry) ? { version: verified, entry } : null;
115069
115108
  }
115070
115109
  function provenNewer(own4) {
115071
- const proven = readState().good.find((v) => fs26.existsSync(entryOf(versionDir(v))));
115072
- return proven && compare2(proven, own4) > 0 ? proven : null;
115110
+ const verified = verifiedCandidate();
115111
+ return verified && compare2(verified.version, own4) > 0 ? verified.version : null;
115073
115112
  }
115074
- async function candidates(own4, source = "terminal") {
115075
- const state2 = readState();
115076
- const proven = provenNewer(own4.version);
115077
- const current2 = proven ? { version: proven, entry: entryOf(versionDir(proven)) } : own4;
115113
+ var cached4 = (candidate) => candidate.entry === entryOf(versionDir(candidate.version));
115114
+ async function findUpdate(own4, current2, source, online = false) {
115078
115115
  const desired = await askTarget(machineId());
115079
- const target = desired?.version;
115080
- if (!desired || !target || waiting(desired, current2.version) || state2.bad.includes(target)) return [current2];
115081
- if (target === current2.version) {
115082
- remember(desired);
115083
- return [current2];
115084
- }
115085
- if (target === own4.version) {
115086
- remember(desired);
115087
- if (compare2(target, current2.version) < 0) logRunner("launcher", "rollback", { version: target, source });
115088
- return [own4, current2];
115089
- }
115090
- const got = await install2(target);
115091
- if (got.ok) {
115092
- const latest = await askTarget(machineId());
115093
- if (!latest || latest.version !== target || waiting(latest, current2.version)) return [current2];
115094
- remember(latest);
115095
- const known2 = state2.good.includes(target);
115096
- logRunner("launcher", "update_ready", { version: target, source, stage: "download" });
115097
- if (compare2(target, current2.version) < 0) logRunner("launcher", "rollback", { version: target, source });
115098
- return [{ version: target, entry: entryOf(got.dir), fresh: !known2 }, current2];
115099
- }
115100
- logRunner("launcher", "update_failed", { version: target, source, stage: "download", code: got.why });
115101
- if (got.why === "node") status(t.nodeTooOld(got.detail));
115102
- return [current2];
115103
- }
115104
- function runOnce(candidate, options) {
115116
+ if (!desired || online && !desired.restartable || waiting(desired, current2.version)) return null;
115117
+ const version3 = desired.version;
115118
+ if (version3 === current2.version) return { ...current2, target: desired };
115119
+ if (cooling(version3)) return null;
115120
+ let entry = own4.entry;
115121
+ if (version3 !== own4.version || !fs26.existsSync(entry)) {
115122
+ const got = await install2(version3);
115123
+ if (!got.ok) {
115124
+ logRunner("launcher", "update_failed", { version: version3, source, stage: "download", code: got.why });
115125
+ if (got.why === "node") status(t.nodeTooOld(got.detail));
115126
+ else if (online) status(t.updateDownloadFailed());
115127
+ return null;
115128
+ }
115129
+ entry = entryOf(got.dir);
115130
+ }
115131
+ const latest = await askTarget(machineId());
115132
+ if (latest?.version !== version3 || online && !latest.restartable || waiting(latest, current2.version)) return null;
115133
+ logRunner("launcher", "update_ready", { version: version3, source, stage: "download" });
115134
+ return { version: version3, entry, target: latest };
115135
+ }
115136
+ function runOnce(own4, candidate, options, trial) {
115105
115137
  const fields2 = { version: candidate.version, source: options.kind ?? "terminal" };
115106
115138
  logRunner("launcher", "starting", fields2);
115107
115139
  return new Promise((resolve2) => {
@@ -115120,22 +115152,14 @@ function runOnce(candidate, options) {
115120
115152
  if (checking || stopping2 || update3) return;
115121
115153
  checking = true;
115122
115154
  try {
115123
- const desired = await askTarget(machineId());
115124
- if (!desired?.restartable || waiting(desired, candidate.version)) return;
115125
- const target = desired.version;
115126
- if (!target || target === candidate.version || readState().bad.includes(target)) return;
115127
- const got = await install2(target);
115128
- if (!got.ok) {
115129
- logRunner("launcher", "update_failed", { ...fields2, version: target, stage: "download", code: got.why });
115130
- status("Runner \u66F4\u65B0\u4E0B\u8F7D\u5931\u8D25\uFF0C\u7EE7\u7EED\u8FD0\u884C\u5F53\u524D\u7248\u672C\uFF0C\u7A0D\u540E\u91CD\u8BD5\u3002");
115155
+ const next = await findUpdate(own4, candidate, fields2.source, true);
115156
+ if (!next || stopping2 || !child.connected) return;
115157
+ if (next.version === candidate.version) {
115158
+ const state2 = readState();
115159
+ if (next.target && state2.verified === candidate.version && remember(state2, next.target)) writeState(state2);
115131
115160
  return;
115132
115161
  }
115133
- if (stopping2 || child.exitCode !== null || child.signalCode !== null) return;
115134
- const latest = await askTarget(machineId());
115135
- if (!latest?.restartable || latest.version !== target || waiting(latest, candidate.version)) return;
115136
- remember(latest);
115137
- update3 = { version: target, entry: entryOf(got.dir), fresh: !readState().good.includes(target) };
115138
- logRunner("launcher", "update_ready", { ...fields2, version: target, stage: "download" });
115162
+ update3 = next;
115139
115163
  child.send({ type: "update" }, () => {
115140
115164
  });
115141
115165
  } finally {
@@ -115147,20 +115171,15 @@ function runOnce(candidate, options) {
115147
115171
  });
115148
115172
  }, Number(process.env.WILDCRANE_UPDATE_MS) || 6e4);
115149
115173
  let connected = false;
115150
- let timer = null;
115151
115174
  let timedOut = false;
115152
115175
  let stopping2 = false;
115153
115176
  let duplicate = false;
115154
115177
  let forceKill;
115155
- const watchConnection = () => {
115156
- if (timer) clearTimeout(timer);
115157
- timer = setTimeout(() => {
115158
- timedOut = true;
115159
- child.kill("SIGTERM");
115160
- forceKill = setTimeout(() => child.kill("SIGKILL"), 5e3);
115161
- }, Number(process.env.WILDCRANE_CONNECT_MS) || CONNECT_MS);
115162
- };
115163
- if (candidate.fresh) watchConnection();
115178
+ const timer = trial ? setTimeout(() => {
115179
+ timedOut = true;
115180
+ child.kill("SIGTERM");
115181
+ forceKill = setTimeout(() => child.kill("SIGKILL"), 5e3);
115182
+ }, Number(process.env.WILDCRANE_CONNECT_MS) || CONNECT_MS) : void 0;
115164
115183
  const forward = (signal) => () => {
115165
115184
  stopping2 = true;
115166
115185
  child.kill(signal);
@@ -115176,7 +115195,6 @@ function runOnce(candidate, options) {
115176
115195
  if (update3) logRunner("launcher", "update_deferred", { ...fields2, version: update3.version });
115177
115196
  update3 = null;
115178
115197
  }
115179
- if (message.type === "reconnecting" && candidate.fresh && !connected && !timedOut) watchConnection();
115180
115198
  if (message.type === "waiting") {
115181
115199
  duplicate = true;
115182
115200
  process.stderr.write(`${t.alreadyRunning()}
@@ -115184,14 +115202,14 @@ function runOnce(candidate, options) {
115184
115202
  child.kill("SIGTERM");
115185
115203
  return;
115186
115204
  }
115205
+ if (timedOut || duplicate || stopping2) return;
115187
115206
  if (message.type === "connected" && !connected) {
115188
115207
  connected = true;
115189
115208
  logRunner("launcher", "connected", fields2);
115190
115209
  if (timer) clearTimeout(timer);
115191
- if (candidate.entry.startsWith(versionsDir() + path30.sep)) fs26.rmSync(legacyVersionsDir(), { recursive: true, force: true });
115192
- const installed = candidate.entry.startsWith(versionsDir() + path30.sep);
115193
- if (candidate.fresh || installed && !readState().good.includes(candidate.version)) markGood(candidate.version);
115194
- if (candidate.fresh) status(t.updated(candidate.version));
115210
+ if (cached4(candidate)) fs26.rmSync(legacyVersionsDir(), { recursive: true, force: true });
115211
+ verify(candidate);
115212
+ if (trial) status(t.updated(candidate.version));
115195
115213
  }
115196
115214
  options.onMessage?.(message);
115197
115215
  });
@@ -115209,62 +115227,63 @@ function runOnce(candidate, options) {
115209
115227
  logRunner("launcher", "exited", { ...fields2, exitCode: code, signal });
115210
115228
  if (spawnError) {
115211
115229
  logRunner("launcher", "startup_failed", { ...fields2, stage: "spawn", code: errno(spawnError) });
115212
- status(`Runner \u65E0\u6CD5\u542F\u52A8\uFF1A${spawnError.message}`);
115213
- return resolve2({ exit: 1 });
115230
+ status(t.spawnFailed(spawnError.message));
115231
+ return resolve2(trial && !stopping2 ? { failed: "crashed" } : { exit: 1 });
115214
115232
  }
115215
115233
  if (duplicate || code === EXIT_ALREADY_RUNNING) {
115216
115234
  logRunner("launcher", "startup_failed", { ...fields2, code: "already_running" });
115217
115235
  return resolve2({ exit: EXIT_ALREADY_RUNNING });
115218
115236
  }
115219
115237
  if (code === EXIT_UPDATE && update3 && !stopping2) return resolve2({ update: update3 });
115220
- const expectedExit = code === 0 || code === EXIT_REFUSED || code === EXIT_OUTDATED;
115221
115238
  const failed = timedOut ? "timeout" : "crashed";
115222
- if (!connected && !stopping2 && (timedOut || !expectedExit)) {
115239
+ if (!connected && !stopping2 && (trial || code === null || code === 1)) {
115223
115240
  logRunner("launcher", "startup_failed", { ...fields2, code: failed });
115224
115241
  }
115225
- if (connected || !candidate.fresh || stopping2) return resolve2({ exit: code ?? (signal ? 1 : 0) });
115226
- if (!timedOut && expectedExit) return resolve2({ exit: code });
115227
- resolve2({ failed });
115242
+ resolve2(trial && !connected && !stopping2 ? { failed } : { exit: code ?? (signal ? 1 : 0) });
115228
115243
  });
115229
115244
  });
115230
115245
  }
115231
115246
  async function launch(own4, options = {}) {
115232
115247
  startRunnerLogMaintenance();
115233
115248
  const source = options.kind ?? "terminal";
115249
+ const release = cached4(own4) ? hold(versionDir(own4.version)) : void 0;
115234
115250
  try {
115235
115251
  return await supervise(own4, source, options);
115236
115252
  } catch (error63) {
115237
115253
  logRunner("launcher", "startup_failed", { version: own4.version, source, code: errno(error63) });
115238
115254
  throw error63;
115255
+ } finally {
115256
+ release?.();
115239
115257
  }
115240
115258
  }
115241
115259
  async function supervise(own4, source, options) {
115242
- const list3 = await candidates(own4, source);
115243
- for (let i = 0; i < list3.length; i++) {
115244
- if (options.signal?.aborted) return 0;
115245
- const candidate = list3[i];
115246
- const outcome = await runOnce(candidate, options);
115260
+ const verified = verifiedCandidate();
115261
+ const current2 = verified && (cached4(own4) || compare2(verified.version, own4.version) > 0) ? verified : own4;
115262
+ let candidate = await findUpdate(own4, current2, source) ?? current2;
115263
+ let previous = candidate.version === current2.version ? null : current2;
115264
+ while (!options.signal?.aborted) {
115265
+ if (previous && compare2(candidate.version, previous.version) < 0) logRunner("launcher", "rollback", { version: candidate.version, source });
115266
+ const outcome = await runOnce(own4, candidate, options, previous !== null);
115247
115267
  if ("exit" in outcome) return outcome.exit;
115248
115268
  if ("update" in outcome) {
115249
115269
  const latest = await askTarget(machineId());
115250
- if (!latest || latest.version !== outcome.update.version || waiting(latest, candidate.version)) {
115251
- list3.splice(i + 1, list3.length, candidate);
115270
+ if (!latest?.restartable || latest.version !== outcome.update.version || waiting(latest, candidate.version)) {
115271
+ previous = null;
115252
115272
  continue;
115253
115273
  }
115254
- if (compare2(outcome.update.version, candidate.version) < 0) {
115255
- logRunner("launcher", "rollback", { version: outcome.update.version, source });
115256
- }
115257
- list3.splice(i + 1, list3.length, outcome.update, candidate);
115258
- continue;
115259
- }
115260
- markBad(candidate.version);
115261
- const next = list3[i + 1];
115262
- if (next) {
115263
- logRunner("launcher", "rollback", { version: next.version, source, code: outcome.failed });
115264
- status(t.rolledBack(next.version));
115274
+ previous = candidate;
115275
+ candidate = { ...outcome.update, target: latest };
115276
+ } else if (previous) {
115277
+ const state2 = readState();
115278
+ state2.retry = { version: candidate.version, after: Date.now() + RETRY_MS };
115279
+ writeState(state2);
115280
+ logRunner("launcher", "rollback", { version: previous.version, source, code: outcome.failed });
115281
+ status(t.rolledBack(previous.version));
115282
+ candidate = previous;
115283
+ previous = null;
115265
115284
  }
115266
115285
  }
115267
- return 1;
115286
+ return 0;
115268
115287
  }
115269
115288
 
115270
115289
  // src/urls.ts
@@ -115279,7 +115298,7 @@ var RELEASED = "https://raw.githubusercontent.com/wildcrane-ai/wildcrane/main/pl
115279
115298
  var ANTIGRAVITY_RELEASED = "https://raw.githubusercontent.com/wildcrane-ai/wildcrane/antigravity-plugin/plugin.json";
115280
115299
  var TIMEOUT_MS3 = 5e3;
115281
115300
  var KEEP_MS2 = 6 * 60 * 6e4;
115282
- var RETRY_MS = 5 * 6e4;
115301
+ var RETRY_MS2 = 5 * 6e4;
115283
115302
  var pluginRoot = (host2) => (host2 === "claude-code" || host2 === "zcode") && process.env.CLAUDE_PLUGIN_ROOT || path31.resolve(path31.dirname(process.argv[1] ?? ""), "..", "..");
115284
115303
  var CLAUDE_MANIFEST = path31.join(".claude-plugin", "plugin.json");
115285
115304
  var MANIFEST = { "claude-code": CLAUDE_MANIFEST, zcode: CLAUDE_MANIFEST, codex: "plugin.json", grok: "plugin.json", antigravity: "plugin.json", opencode: "package.json", dsh: "package.json", cursor: path31.join(".cursor-plugin", "plugin.json"), kimi: "kimi.plugin.json" };
@@ -115304,7 +115323,7 @@ var newerOf = (version3, latest) => version3 && latest && compare2(latest, versi
115304
115323
  var released = null;
115305
115324
  var fetching = null;
115306
115325
  function checkReleased(url2 = RELEASED, now = Date.now()) {
115307
- const stale2 = !released || now - released.at > (released.value ? KEEP_MS2 : RETRY_MS);
115326
+ const stale2 = !released || now - released.at > (released.value ? KEEP_MS2 : RETRY_MS2);
115308
115327
  if (!stale2 || fetching) return fetching ?? Promise.resolve();
115309
115328
  fetching = get(url2).then(releasedOf, () => null).then((value) => void (released = { at: Date.now(), value })).finally(() => fetching = null);
115310
115329
  return fetching;