wildcrane-runner 0.6.104 → 0.6.106

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.
@@ -1,4 +1,4 @@
1
- // wildcrane-runner 0.6.104 — built by runner/scripts/build.mjs. Do not edit.
1
+ // wildcrane-runner 0.6.106 — 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;
@@ -219,9 +219,9 @@ var require_timers = __commonJS({
219
219
  * before the specified function or code is executed.
220
220
  * @param {*} arg
221
221
  */
222
- constructor(callback, delay, arg) {
222
+ constructor(callback, delay2, arg) {
223
223
  this._onTimeout = callback;
224
- this._idleTimeout = delay;
224
+ this._idleTimeout = delay2;
225
225
  this._timerArg = arg;
226
226
  this.refresh();
227
227
  }
@@ -266,8 +266,8 @@ var require_timers = __commonJS({
266
266
  * when the timer expires.
267
267
  * @returns {NodeJS.Timeout|FastTimer}
268
268
  */
269
- setTimeout(callback, delay, arg) {
270
- return delay <= RESOLUTION_MS ? setTimeout(callback, delay, arg) : new FastTimer(callback, delay, arg);
269
+ setTimeout(callback, delay2, arg) {
270
+ return delay2 <= RESOLUTION_MS ? setTimeout(callback, delay2, arg) : new FastTimer(callback, delay2, arg);
271
271
  },
272
272
  /**
273
273
  * The clearTimeout method cancels an instantiated Timer previously created
@@ -293,8 +293,8 @@ var require_timers = __commonJS({
293
293
  * when the timer expires.
294
294
  * @returns {FastTimer}
295
295
  */
296
- setFastTimeout(callback, delay, arg) {
297
- return new FastTimer(callback, delay, arg);
296
+ setFastTimeout(callback, delay2, arg) {
297
+ return new FastTimer(callback, delay2, arg);
298
298
  },
299
299
  /**
300
300
  * The clearTimeout method cancels an instantiated FastTimer previously
@@ -320,8 +320,8 @@ var require_timers = __commonJS({
320
320
  * @deprecated
321
321
  * @param {number} [delay=0] The delay in milliseconds to add to the now value.
322
322
  */
323
- tick(delay = 0) {
324
- fastNow += delay - RESOLUTION_MS + 1;
323
+ tick(delay2 = 0) {
324
+ fastNow += delay2 - RESOLUTION_MS + 1;
325
325
  onTick();
326
326
  onTick();
327
327
  },
@@ -6839,21 +6839,21 @@ var require_client_h1 = __commonJS({
6839
6839
  this.connection = "";
6840
6840
  this.maxResponseSize = client[kMaxResponseSize];
6841
6841
  }
6842
- setTimeout(delay, type) {
6843
- if (delay !== this.timeoutValue || type & USE_FAST_TIMER ^ this.timeoutType & USE_FAST_TIMER) {
6842
+ setTimeout(delay2, type) {
6843
+ if (delay2 !== this.timeoutValue || type & USE_FAST_TIMER ^ this.timeoutType & USE_FAST_TIMER) {
6844
6844
  if (this.timeout) {
6845
6845
  timers.clearTimeout(this.timeout);
6846
6846
  this.timeout = null;
6847
6847
  }
6848
- if (delay) {
6848
+ if (delay2) {
6849
6849
  if (type & USE_FAST_TIMER) {
6850
- this.timeout = timers.setFastTimeout(onParserTimeout, delay, this.timeoutWeakRef);
6850
+ this.timeout = timers.setFastTimeout(onParserTimeout, delay2, this.timeoutWeakRef);
6851
6851
  } else {
6852
- this.timeout = setTimeout(onParserTimeout, delay, this.timeoutWeakRef);
6852
+ this.timeout = setTimeout(onParserTimeout, delay2, this.timeoutWeakRef);
6853
6853
  this.timeout?.unref();
6854
6854
  }
6855
6855
  }
6856
- this.timeoutValue = delay;
6856
+ this.timeoutValue = delay2;
6857
6857
  } else if (this.timeout) {
6858
6858
  if (this.timeout.refresh) {
6859
6859
  this.timeout.refresh();
@@ -13019,7 +13019,7 @@ var require_mock_utils = __commonJS({
13019
13019
  if (mockDispatch2.data.callback) {
13020
13020
  mockDispatch2.data = { ...mockDispatch2.data, ...mockDispatch2.data.callback(opts) };
13021
13021
  }
13022
- const { data: { statusCode, data, headers, trailers, error }, delay, persist } = mockDispatch2;
13022
+ const { data: { statusCode, data, headers, trailers, error }, delay: delay2, persist } = mockDispatch2;
13023
13023
  const { timesInvoked, times } = mockDispatch2;
13024
13024
  mockDispatch2.consumed = !persist && timesInvoked >= times;
13025
13025
  mockDispatch2.pending = timesInvoked < times;
@@ -13042,11 +13042,11 @@ var require_mock_utils = __commonJS({
13042
13042
  handler.onError(err);
13043
13043
  }
13044
13044
  handler.onConnect?.(abort, null);
13045
- if (typeof delay === "number" && delay > 0) {
13045
+ if (typeof delay2 === "number" && delay2 > 0) {
13046
13046
  timer = setTimeout(() => {
13047
13047
  timer = null;
13048
13048
  handleReply(this[kDispatches]);
13049
- }, delay);
13049
+ }, delay2);
13050
13050
  } else {
13051
13051
  handleReply(this[kDispatches]);
13052
13052
  }
@@ -26679,6 +26679,7 @@ import fs3 from "node:fs";
26679
26679
  var import_undici2 = __toESM(require_undici(), 1);
26680
26680
  import path4 from "node:path";
26681
26681
  import { PassThrough, Writable } from "node:stream";
26682
+ import { setTimeout as delay } from "node:timers/promises";
26682
26683
 
26683
26684
  // ../cli/src/lib/shared/conversation.ts
26684
26685
  function bounded(work, ms, reason) {
@@ -26844,6 +26845,36 @@ function connectionIdentity(pid) {
26844
26845
  return result.status === 0 ? result.stdout.trim() || void 0 : void 0;
26845
26846
  }
26846
26847
 
26848
+ // ../cli/src/lib/agent/retry.ts
26849
+ var MAX_SUMMARY_CHARS = 300;
26850
+ var MAX_DETAIL_CHARS = 4e3;
26851
+ function clipSummary(text) {
26852
+ const clean = text.replace(/\s+/g, " ").trim();
26853
+ return clean.length > MAX_SUMMARY_CHARS ? `${clean.slice(0, MAX_SUMMARY_CHARS - 1)}\u2026` : clean;
26854
+ }
26855
+ function clipDetail(text) {
26856
+ if (!text) return void 0;
26857
+ const trimmed = text.trim();
26858
+ if (!trimmed) return void 0;
26859
+ return trimmed.length > MAX_DETAIL_CHARS ? `${trimmed.slice(0, MAX_DETAIL_CHARS - 1)}\u2026` : trimmed;
26860
+ }
26861
+ function makeFailure(source, rawSummary, options) {
26862
+ const summary = clipSummary(rawSummary) || "Execution failed.";
26863
+ const rawDetail = options?.detail?.trim() || (rawSummary.trim().length > summary.length || rawSummary.includes("\n") ? rawSummary.trim() : void 0);
26864
+ const detail = clipDetail(rawDetail);
26865
+ return {
26866
+ ...options?.code ? { code: options.code } : {},
26867
+ source,
26868
+ summary,
26869
+ ...detail && detail !== summary ? { detail } : {},
26870
+ ...typeof options?.retryAfterMs === "number" && Number.isFinite(options.retryAfterMs) && options.retryAfterMs >= 0 ? { retryAfterMs: options.retryAfterMs } : {}
26871
+ };
26872
+ }
26873
+ var SESSION_MISSING_RE = /no rollout found for thread id|no conversation found with session id|session[_\s-]*not[_\s-]*found|session[_\s-]*mismatch|(?:session|thread|conversation)\s+\S+\s+not\s+found|unknown\s+(?:session|thread)|did not resume the requested conversation|did not return the requested session/i;
26874
+ function isSessionMissingText(text) {
26875
+ return !!text && SESSION_MISSING_RE.test(text);
26876
+ }
26877
+
26847
26878
  // ../cli/src/lib/agent/wire/json.ts
26848
26879
  function obj(value) {
26849
26880
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
@@ -26855,7 +26886,7 @@ function str(value) {
26855
26886
  // ../cli/src/lib/agent/wire/failures.ts
26856
26887
  var ExecutionError = class extends Error {
26857
26888
  constructor(failure) {
26858
- super(failure.reason);
26889
+ super(failure.summary);
26859
26890
  this.failure = failure;
26860
26891
  }
26861
26892
  failure;
@@ -26864,13 +26895,9 @@ var NETWORK = /* @__PURE__ */ new Set(["ECONNRESET", "ECONNREFUSED", "EPIPE", "E
26864
26895
  function executionFailure(error) {
26865
26896
  if (error instanceof ExecutionError) return error.failure;
26866
26897
  const code = str(obj(error).code);
26867
- const reason = error instanceof Error ? error.message : String(error);
26868
- return {
26869
- code: NETWORK.has(code) ? "connection_lost" : code === "ENOENT" ? "executable_missing" : "execution_failed",
26870
- level: NETWORK.has(code) ? 2 : 3,
26871
- source: "harness",
26872
- reason
26873
- };
26898
+ const raw = error instanceof Error ? error.message : String(error);
26899
+ const resolvedCode = isSessionMissingText(raw) ? "session_not_found" : NETWORK.has(code) ? "connection_lost" : code === "ENOENT" ? "executable_missing" : "execution_failed";
26900
+ return makeFailure("runner", raw, { code: resolvedCode, detail: raw });
26874
26901
  }
26875
26902
 
26876
26903
  // ../cli/src/lib/agent/wire/rpc.ts
@@ -26929,7 +26956,7 @@ function connect(stdout, stdin, onCall, dialect = {}) {
26929
26956
  } else pending.ok(obj(msg.result));
26930
26957
  }
26931
26958
  });
26932
- stdout.on("close", () => closed(new ExecutionError({ code: "connection_lost", level: 2, reason: "The agent closed the connection." })));
26959
+ stdout.on("close", () => closed(new ExecutionError({ code: "connection_lost", source: "runtime", summary: "The agent closed the connection." })));
26933
26960
  stdout.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
26934
26961
  stdin.on("error", (err) => closed(new ExecutionError(executionFailure(err))));
26935
26962
  return {
@@ -27035,48 +27062,141 @@ async function nativeConnection(backend, onMessage) {
27035
27062
  close();
27036
27063
  throw error;
27037
27064
  }
27038
- const rpc = connect(incoming, outgoing, onMessage);
27039
- return { rpc, incoming, close };
27065
+ const unloads = new EventTarget();
27066
+ const rpc = connect(incoming, outgoing, (message) => {
27067
+ const params = obj(message.params), id = str(params.threadId);
27068
+ if (id && message.id === void 0 && (message.method === "thread/closed" || message.method === "thread/status/changed" && obj(params.status).type === "notLoaded")) unloads.dispatchEvent(new Event(id));
27069
+ onMessage(message);
27070
+ });
27071
+ return { rpc, incoming, close, unloads };
27040
27072
  }
27041
27073
  async function initializeNative(connection) {
27042
27074
  const result = await bounded(connection.rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), CODEX_TIMEOUT, "Codex initialize timed out.");
27043
27075
  connection.rpc.notify("initialized");
27044
27076
  return result;
27045
27077
  }
27046
- async function releaseNativeThread(connection, threadId, turnId, stopWork, unloading) {
27047
- const missing = (error) => error instanceof RpcError && /thread not (?:found|loaded)/i.test(error.message);
27078
+ async function backgroundTerminals(rpc, threadId, deadline = Date.now() + CODEX_TIMEOUT) {
27079
+ const result = [], seen = /* @__PURE__ */ new Set();
27080
+ let cursor;
27081
+ do {
27082
+ if (cursor !== void 0) {
27083
+ if (seen.has(cursor)) throw Error("Codex repeated a terminal cursor.");
27084
+ seen.add(cursor);
27085
+ }
27086
+ const page = await beforeDeadline(deadline, "background terminal verification", () => rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor === void 0 ? {} : { cursor } }));
27087
+ if (!Array.isArray(page.data) || page.nextCursor != null && typeof page.nextCursor !== "string") throw Error("Codex background terminal state is unconfirmed.");
27088
+ for (const value of page.data) result.push({ ...obj(value), threadId });
27089
+ cursor = typeof page.nextCursor === "string" ? page.nextCursor : void 0;
27090
+ } while (cursor !== void 0);
27091
+ return result;
27092
+ }
27093
+ function codexDiagnostic(error) {
27094
+ return error instanceof RpcError ? `RPC ${error.code ?? "unknown"}: ${error.message}` : error instanceof Error ? error.message : String(error);
27095
+ }
27096
+ function beforeDeadline(deadline, operation, run) {
27097
+ const timeout = `Codex ${operation} timed out.`;
27098
+ const remaining = deadline - Date.now();
27099
+ if (remaining <= 0) throw Error(timeout);
27100
+ return bounded(run(), remaining, timeout);
27101
+ }
27102
+ async function inspectNativeThread(rpc, threadId, deadline = Date.now() + CODEX_TIMEOUT, checkBackground = true) {
27103
+ let diagnostic;
27048
27104
  try {
27049
- await bounded((async () => {
27050
- if (stopWork) {
27051
- if (turnId) {
27052
- try {
27053
- await connection.rpc.call("turn/interrupt", { threadId, turnId });
27054
- } catch (error) {
27055
- if (!missing(error)) throw error;
27056
- }
27057
- }
27058
- try {
27059
- await connection.rpc.call("thread/backgroundTerminals/clean", { threadId });
27060
- } catch (error) {
27061
- if (!(error instanceof RpcError) || error.code !== -32601 && !missing(error)) throw error;
27062
- }
27063
- }
27064
- const unloaded = new Promise((resolve) => unloading.set(threadId, resolve));
27065
- let result;
27105
+ const reply = await beforeDeadline(deadline, "thread/read", () => rpc.call("thread/read", { threadId }));
27106
+ const thread = obj(reply.thread), status = obj(thread.status).type;
27107
+ if (thread.id !== threadId || status !== "notLoaded" && status !== "active" && status !== "idle") {
27108
+ throw Error("thread/read returned an unexpected thread or status.");
27109
+ }
27110
+ if (status === "idle" && checkBackground) {
27111
+ const work = await backgroundTerminals(rpc, threadId, deadline);
27112
+ if (work.length) return { status: "background-work", thread };
27113
+ }
27114
+ return { status, thread };
27115
+ } catch (error) {
27116
+ diagnostic = codexDiagnostic(error);
27117
+ }
27118
+ let cursor;
27119
+ const seen = /* @__PURE__ */ new Set();
27120
+ try {
27121
+ do {
27122
+ const page = await beforeDeadline(deadline, "thread/loaded/list", () => rpc.call("thread/loaded/list", cursor === void 0 ? {} : { cursor }));
27123
+ const next = page.nextCursor;
27124
+ if (!Array.isArray(page.data) || page.data.some((id) => typeof id !== "string" || !id.trim()) || next != null && typeof next !== "string") throw Error("thread/loaded/list returned an invalid page.");
27125
+ if (page.data.includes(threadId)) return { status: "unverified", diagnostic: `${diagnostic} The thread is still loaded.` };
27126
+ cursor = typeof next === "string" ? next : void 0;
27127
+ if (cursor !== void 0) {
27128
+ if (seen.has(cursor)) throw Error("thread/loaded/list repeated a cursor.");
27129
+ seen.add(cursor);
27130
+ }
27131
+ } while (cursor !== void 0);
27132
+ return { status: "notLoaded", diagnostic };
27133
+ } catch (error) {
27134
+ return { status: "unverified", diagnostic: `${diagnostic} ${codexDiagnostic(error)}` };
27135
+ }
27136
+ }
27137
+ function releaseError(method, threadId, evidence, error) {
27138
+ const diagnostic = [`${method} could not confirm Codex thread ${threadId}: ${evidence.status}.`, evidence.diagnostic].filter(Boolean).join(" ");
27139
+ return error instanceof RpcError ? new RpcError(`${error.message} ${diagnostic}`, error.code, error.data) : Error([error && codexDiagnostic(error), diagnostic].filter(Boolean).join(" "));
27140
+ }
27141
+ async function interruptNativeThread(connection, threadId, turnId, deadline) {
27142
+ try {
27143
+ await beforeDeadline(deadline, "turn/interrupt", () => connection.rpc.call("turn/interrupt", { threadId, turnId }));
27144
+ } catch (error) {
27145
+ const evidence = await inspectNativeThread(connection.rpc, threadId, deadline, false);
27146
+ if (evidence.status !== "idle" && evidence.status !== "notLoaded") throw releaseError("turn/interrupt", threadId, evidence, error);
27147
+ console.error(`Codex turn/interrupt: ${codexDiagnostic(error)} (${evidence.status}, ${threadId})`);
27148
+ }
27149
+ }
27150
+ async function releaseNativeThread(connection, threadId, turnId, stopWork, deadline = Date.now() + CODEX_TIMEOUT) {
27151
+ const { rpc, unloads } = connection;
27152
+ let closed = false;
27153
+ let observed;
27154
+ const unloaded = new Promise((resolve) => {
27155
+ observed = () => {
27156
+ closed = true;
27157
+ resolve();
27158
+ };
27159
+ });
27160
+ unloads.addEventListener(threadId, observed, { once: true });
27161
+ const release = async () => {
27162
+ if (stopWork && turnId) await interruptNativeThread(connection, threadId, turnId, deadline);
27163
+ if (closed) return;
27164
+ if (stopWork) {
27066
27165
  try {
27067
- result = await connection.rpc.call("thread/unsubscribe", { threadId });
27166
+ await beforeDeadline(deadline, "thread/backgroundTerminals/clean", () => rpc.call("thread/backgroundTerminals/clean", { threadId }));
27068
27167
  } catch (error) {
27069
- if (!missing(error)) throw error;
27070
- result = { status: "notLoaded" };
27168
+ if (closed) return;
27169
+ if (!(error instanceof RpcError && error.code === -32601)) {
27170
+ const evidence = await inspectNativeThread(rpc, threadId, deadline, false);
27171
+ if (!closed && evidence.status !== "notLoaded") throw releaseError("thread/backgroundTerminals/clean", threadId, evidence, error);
27172
+ console.error(`Codex thread/backgroundTerminals/clean: ${codexDiagnostic(error)} (${threadId})`);
27173
+ return;
27174
+ }
27071
27175
  }
27072
- if (result.status === "unsubscribed") await unloaded;
27073
- else if (result.status !== "notLoaded") {
27074
- const snapshot = obj((await connection.rpc.call("thread/read", { threadId })).thread);
27075
- if (obj(snapshot.status).type !== "notLoaded") throw Error("Codex thread unload is unconfirmed.");
27176
+ }
27177
+ if (closed) return;
27178
+ let status, failure;
27179
+ try {
27180
+ status = (await beforeDeadline(deadline, "thread/unsubscribe", () => rpc.call("thread/unsubscribe", { threadId }))).status;
27181
+ } catch (error) {
27182
+ failure = error;
27183
+ }
27184
+ if (status === "notLoaded") return;
27185
+ while (!closed) {
27186
+ const evidence = await inspectNativeThread(rpc, threadId, deadline, false);
27187
+ if (closed || evidence.status === "notLoaded") {
27188
+ if (failure) console.error(`Codex thread/unsubscribe: ${codexDiagnostic(failure)} (${threadId})`);
27189
+ return;
27076
27190
  }
27077
- })(), CODEX_TIMEOUT, "Codex thread cleanup timed out; ownership remains unconfirmed.");
27191
+ if (status !== "unsubscribed") throw releaseError("thread/unsubscribe", threadId, evidence, failure);
27192
+ if (Date.now() >= deadline) throw releaseError("thread unload", threadId, evidence, Error("Codex thread cleanup timed out."));
27193
+ await delay(Math.min(50, deadline - Date.now()));
27194
+ }
27195
+ };
27196
+ try {
27197
+ await Promise.race([release(), unloaded]);
27078
27198
  } finally {
27079
- unloading.delete(threadId);
27199
+ unloads.removeEventListener(threadId, observed);
27080
27200
  }
27081
27201
  }
27082
27202
 
@@ -27109,7 +27229,7 @@ async function retain() {
27109
27229
  const release = executorRecord();
27110
27230
  const state = { ...initial, ...identity };
27111
27231
  let closing = false, transferred = false;
27112
- const active = /* @__PURE__ */ new Map(), unloaded = /* @__PURE__ */ new Map();
27232
+ const active = /* @__PURE__ */ new Map();
27113
27233
  let wake;
27114
27234
  const done = new Promise((resolve) => {
27115
27235
  wake = resolve;
@@ -27122,7 +27242,6 @@ async function retain() {
27122
27242
  }
27123
27243
  if (message.method === "turn/started") active.set(id, str(obj(params.turn).id));
27124
27244
  if (message.method === "turn/completed") active.delete(id);
27125
- if (message.method === "thread/closed") unloaded.get(id)?.();
27126
27245
  if (message.method === "item/completed" && obj(params.item).type === "commandExecution") {
27127
27246
  state.retained = { ...state.retained, kept: state.retained.kept.filter((item) => item.threadId !== id || item.itemId !== obj(params.item).id) };
27128
27247
  for (const thread of initial.threads) {
@@ -27154,7 +27273,7 @@ async function retain() {
27154
27273
  if (transferred) return;
27155
27274
  const results = await Promise.allSettled(initial.threads.map(async (id) => {
27156
27275
  if (readPrivate(leaseFile(backend, id))?.lease !== lease) return;
27157
- await releaseNativeThread(connection, id, active.get(id), true, unloaded);
27276
+ await releaseNativeThread(connection, id, active.get(id), true);
27158
27277
  if (readPrivate(leaseFile(backend, id))?.lease === lease) fs5.rmSync(leaseFile(backend, id), { force: true });
27159
27278
  }));
27160
27279
  const failure = results.find((result) => result.status === "rejected");
@@ -27162,6 +27281,7 @@ async function retain() {
27162
27281
  } catch (error) {
27163
27282
  for (const id of initial.threads) if (readPrivate(leaseFile(backend, id))?.lease === lease) writeLease(backend, id, { ...state, retained: void 0, uncertain: true });
27164
27283
  if (!closing) throw error;
27284
+ console.error(codexDiagnostic(error));
27165
27285
  } finally {
27166
27286
  connection.close();
27167
27287
  release();