wildcrane-runner 0.6.103 → 0.6.105
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/akb/dist/kanban.mjs +1281 -747
- package/dist/akb/package.json +1 -1
- package/dist/akb-proxy.mjs +1 -1
- package/dist/codex-proxy.mjs +356 -219
- package/dist/codex-retained.mjs +145 -51
- package/dist/flow-worker-main.mjs +1284 -1032
- package/dist/launcher.mjs +84 -53
- package/dist/plugin.mjs +84 -53
- package/dist/runner.mjs +1234 -935
- package/dist/settings.mjs +84 -53
- package/package.json +1 -1
package/dist/codex-retained.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// wildcrane-runner 0.6.
|
|
1
|
+
// wildcrane-runner 0.6.105 — 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,
|
|
222
|
+
constructor(callback, delay2, arg) {
|
|
223
223
|
this._onTimeout = callback;
|
|
224
|
-
this._idleTimeout =
|
|
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,
|
|
270
|
-
return
|
|
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,
|
|
297
|
-
return new FastTimer(callback,
|
|
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(
|
|
324
|
-
fastNow +=
|
|
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(
|
|
6843
|
-
if (
|
|
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 (
|
|
6848
|
+
if (delay2) {
|
|
6849
6849
|
if (type & USE_FAST_TIMER) {
|
|
6850
|
-
this.timeout = timers.setFastTimeout(onParserTimeout,
|
|
6850
|
+
this.timeout = timers.setFastTimeout(onParserTimeout, delay2, this.timeoutWeakRef);
|
|
6851
6851
|
} else {
|
|
6852
|
-
this.timeout = setTimeout(onParserTimeout,
|
|
6852
|
+
this.timeout = setTimeout(onParserTimeout, delay2, this.timeoutWeakRef);
|
|
6853
6853
|
this.timeout?.unref();
|
|
6854
6854
|
}
|
|
6855
6855
|
}
|
|
6856
|
-
this.timeoutValue =
|
|
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
|
|
13045
|
+
if (typeof delay2 === "number" && delay2 > 0) {
|
|
13046
13046
|
timer = setTimeout(() => {
|
|
13047
13047
|
timer = null;
|
|
13048
13048
|
handleReply(this[kDispatches]);
|
|
13049
|
-
},
|
|
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) {
|
|
@@ -27035,48 +27036,141 @@ async function nativeConnection(backend, onMessage) {
|
|
|
27035
27036
|
close();
|
|
27036
27037
|
throw error;
|
|
27037
27038
|
}
|
|
27038
|
-
const
|
|
27039
|
-
|
|
27039
|
+
const unloads = new EventTarget();
|
|
27040
|
+
const rpc = connect(incoming, outgoing, (message) => {
|
|
27041
|
+
const params = obj(message.params), id = str(params.threadId);
|
|
27042
|
+
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));
|
|
27043
|
+
onMessage(message);
|
|
27044
|
+
});
|
|
27045
|
+
return { rpc, incoming, close, unloads };
|
|
27040
27046
|
}
|
|
27041
27047
|
async function initializeNative(connection) {
|
|
27042
27048
|
const result = await bounded(connection.rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), CODEX_TIMEOUT, "Codex initialize timed out.");
|
|
27043
27049
|
connection.rpc.notify("initialized");
|
|
27044
27050
|
return result;
|
|
27045
27051
|
}
|
|
27046
|
-
async function
|
|
27047
|
-
const
|
|
27052
|
+
async function backgroundTerminals(rpc, threadId, deadline = Date.now() + CODEX_TIMEOUT) {
|
|
27053
|
+
const result = [], seen = /* @__PURE__ */ new Set();
|
|
27054
|
+
let cursor;
|
|
27055
|
+
do {
|
|
27056
|
+
if (cursor !== void 0) {
|
|
27057
|
+
if (seen.has(cursor)) throw Error("Codex repeated a terminal cursor.");
|
|
27058
|
+
seen.add(cursor);
|
|
27059
|
+
}
|
|
27060
|
+
const page = await beforeDeadline(deadline, "background terminal verification", () => rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor === void 0 ? {} : { cursor } }));
|
|
27061
|
+
if (!Array.isArray(page.data) || page.nextCursor != null && typeof page.nextCursor !== "string") throw Error("Codex background terminal state is unconfirmed.");
|
|
27062
|
+
for (const value of page.data) result.push({ ...obj(value), threadId });
|
|
27063
|
+
cursor = typeof page.nextCursor === "string" ? page.nextCursor : void 0;
|
|
27064
|
+
} while (cursor !== void 0);
|
|
27065
|
+
return result;
|
|
27066
|
+
}
|
|
27067
|
+
function codexDiagnostic(error) {
|
|
27068
|
+
return error instanceof RpcError ? `RPC ${error.code ?? "unknown"}: ${error.message}` : error instanceof Error ? error.message : String(error);
|
|
27069
|
+
}
|
|
27070
|
+
function beforeDeadline(deadline, operation, run) {
|
|
27071
|
+
const timeout = `Codex ${operation} timed out.`;
|
|
27072
|
+
const remaining = deadline - Date.now();
|
|
27073
|
+
if (remaining <= 0) throw Error(timeout);
|
|
27074
|
+
return bounded(run(), remaining, timeout);
|
|
27075
|
+
}
|
|
27076
|
+
async function inspectNativeThread(rpc, threadId, deadline = Date.now() + CODEX_TIMEOUT, checkBackground = true) {
|
|
27077
|
+
let diagnostic;
|
|
27048
27078
|
try {
|
|
27049
|
-
await
|
|
27050
|
-
|
|
27051
|
-
|
|
27052
|
-
|
|
27053
|
-
|
|
27054
|
-
|
|
27055
|
-
|
|
27056
|
-
|
|
27057
|
-
|
|
27058
|
-
|
|
27059
|
-
|
|
27060
|
-
|
|
27061
|
-
|
|
27062
|
-
|
|
27063
|
-
|
|
27064
|
-
|
|
27065
|
-
|
|
27079
|
+
const reply = await beforeDeadline(deadline, "thread/read", () => rpc.call("thread/read", { threadId }));
|
|
27080
|
+
const thread = obj(reply.thread), status = obj(thread.status).type;
|
|
27081
|
+
if (thread.id !== threadId || status !== "notLoaded" && status !== "active" && status !== "idle") {
|
|
27082
|
+
throw Error("thread/read returned an unexpected thread or status.");
|
|
27083
|
+
}
|
|
27084
|
+
if (status === "idle" && checkBackground) {
|
|
27085
|
+
const work = await backgroundTerminals(rpc, threadId, deadline);
|
|
27086
|
+
if (work.length) return { status: "background-work", thread };
|
|
27087
|
+
}
|
|
27088
|
+
return { status, thread };
|
|
27089
|
+
} catch (error) {
|
|
27090
|
+
diagnostic = codexDiagnostic(error);
|
|
27091
|
+
}
|
|
27092
|
+
let cursor;
|
|
27093
|
+
const seen = /* @__PURE__ */ new Set();
|
|
27094
|
+
try {
|
|
27095
|
+
do {
|
|
27096
|
+
const page = await beforeDeadline(deadline, "thread/loaded/list", () => rpc.call("thread/loaded/list", cursor === void 0 ? {} : { cursor }));
|
|
27097
|
+
const next = page.nextCursor;
|
|
27098
|
+
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.");
|
|
27099
|
+
if (page.data.includes(threadId)) return { status: "unverified", diagnostic: `${diagnostic} The thread is still loaded.` };
|
|
27100
|
+
cursor = typeof next === "string" ? next : void 0;
|
|
27101
|
+
if (cursor !== void 0) {
|
|
27102
|
+
if (seen.has(cursor)) throw Error("thread/loaded/list repeated a cursor.");
|
|
27103
|
+
seen.add(cursor);
|
|
27104
|
+
}
|
|
27105
|
+
} while (cursor !== void 0);
|
|
27106
|
+
return { status: "notLoaded", diagnostic };
|
|
27107
|
+
} catch (error) {
|
|
27108
|
+
return { status: "unverified", diagnostic: `${diagnostic} ${codexDiagnostic(error)}` };
|
|
27109
|
+
}
|
|
27110
|
+
}
|
|
27111
|
+
function releaseError(method, threadId, evidence, error) {
|
|
27112
|
+
const diagnostic = [`${method} could not confirm Codex thread ${threadId}: ${evidence.status}.`, evidence.diagnostic].filter(Boolean).join(" ");
|
|
27113
|
+
return error instanceof RpcError ? new RpcError(`${error.message} ${diagnostic}`, error.code, error.data) : Error([error && codexDiagnostic(error), diagnostic].filter(Boolean).join(" "));
|
|
27114
|
+
}
|
|
27115
|
+
async function interruptNativeThread(connection, threadId, turnId, deadline) {
|
|
27116
|
+
try {
|
|
27117
|
+
await beforeDeadline(deadline, "turn/interrupt", () => connection.rpc.call("turn/interrupt", { threadId, turnId }));
|
|
27118
|
+
} catch (error) {
|
|
27119
|
+
const evidence = await inspectNativeThread(connection.rpc, threadId, deadline, false);
|
|
27120
|
+
if (evidence.status !== "idle" && evidence.status !== "notLoaded") throw releaseError("turn/interrupt", threadId, evidence, error);
|
|
27121
|
+
console.error(`Codex turn/interrupt: ${codexDiagnostic(error)} (${evidence.status}, ${threadId})`);
|
|
27122
|
+
}
|
|
27123
|
+
}
|
|
27124
|
+
async function releaseNativeThread(connection, threadId, turnId, stopWork, deadline = Date.now() + CODEX_TIMEOUT) {
|
|
27125
|
+
const { rpc, unloads } = connection;
|
|
27126
|
+
let closed = false;
|
|
27127
|
+
let observed;
|
|
27128
|
+
const unloaded = new Promise((resolve) => {
|
|
27129
|
+
observed = () => {
|
|
27130
|
+
closed = true;
|
|
27131
|
+
resolve();
|
|
27132
|
+
};
|
|
27133
|
+
});
|
|
27134
|
+
unloads.addEventListener(threadId, observed, { once: true });
|
|
27135
|
+
const release = async () => {
|
|
27136
|
+
if (stopWork && turnId) await interruptNativeThread(connection, threadId, turnId, deadline);
|
|
27137
|
+
if (closed) return;
|
|
27138
|
+
if (stopWork) {
|
|
27066
27139
|
try {
|
|
27067
|
-
|
|
27140
|
+
await beforeDeadline(deadline, "thread/backgroundTerminals/clean", () => rpc.call("thread/backgroundTerminals/clean", { threadId }));
|
|
27068
27141
|
} catch (error) {
|
|
27069
|
-
if (
|
|
27070
|
-
|
|
27142
|
+
if (closed) return;
|
|
27143
|
+
if (!(error instanceof RpcError && error.code === -32601)) {
|
|
27144
|
+
const evidence = await inspectNativeThread(rpc, threadId, deadline, false);
|
|
27145
|
+
if (!closed && evidence.status !== "notLoaded") throw releaseError("thread/backgroundTerminals/clean", threadId, evidence, error);
|
|
27146
|
+
console.error(`Codex thread/backgroundTerminals/clean: ${codexDiagnostic(error)} (${threadId})`);
|
|
27147
|
+
return;
|
|
27148
|
+
}
|
|
27071
27149
|
}
|
|
27072
|
-
|
|
27073
|
-
|
|
27074
|
-
|
|
27075
|
-
|
|
27150
|
+
}
|
|
27151
|
+
if (closed) return;
|
|
27152
|
+
let status, failure;
|
|
27153
|
+
try {
|
|
27154
|
+
status = (await beforeDeadline(deadline, "thread/unsubscribe", () => rpc.call("thread/unsubscribe", { threadId }))).status;
|
|
27155
|
+
} catch (error) {
|
|
27156
|
+
failure = error;
|
|
27157
|
+
}
|
|
27158
|
+
if (status === "notLoaded") return;
|
|
27159
|
+
while (!closed) {
|
|
27160
|
+
const evidence = await inspectNativeThread(rpc, threadId, deadline, false);
|
|
27161
|
+
if (closed || evidence.status === "notLoaded") {
|
|
27162
|
+
if (failure) console.error(`Codex thread/unsubscribe: ${codexDiagnostic(failure)} (${threadId})`);
|
|
27163
|
+
return;
|
|
27076
27164
|
}
|
|
27077
|
-
|
|
27165
|
+
if (status !== "unsubscribed") throw releaseError("thread/unsubscribe", threadId, evidence, failure);
|
|
27166
|
+
if (Date.now() >= deadline) throw releaseError("thread unload", threadId, evidence, Error("Codex thread cleanup timed out."));
|
|
27167
|
+
await delay(Math.min(50, deadline - Date.now()));
|
|
27168
|
+
}
|
|
27169
|
+
};
|
|
27170
|
+
try {
|
|
27171
|
+
await Promise.race([release(), unloaded]);
|
|
27078
27172
|
} finally {
|
|
27079
|
-
|
|
27173
|
+
unloads.removeEventListener(threadId, observed);
|
|
27080
27174
|
}
|
|
27081
27175
|
}
|
|
27082
27176
|
|
|
@@ -27109,7 +27203,7 @@ async function retain() {
|
|
|
27109
27203
|
const release = executorRecord();
|
|
27110
27204
|
const state = { ...initial, ...identity };
|
|
27111
27205
|
let closing = false, transferred = false;
|
|
27112
|
-
const active = /* @__PURE__ */ new Map()
|
|
27206
|
+
const active = /* @__PURE__ */ new Map();
|
|
27113
27207
|
let wake;
|
|
27114
27208
|
const done = new Promise((resolve) => {
|
|
27115
27209
|
wake = resolve;
|
|
@@ -27122,7 +27216,6 @@ async function retain() {
|
|
|
27122
27216
|
}
|
|
27123
27217
|
if (message.method === "turn/started") active.set(id, str(obj(params.turn).id));
|
|
27124
27218
|
if (message.method === "turn/completed") active.delete(id);
|
|
27125
|
-
if (message.method === "thread/closed") unloaded.get(id)?.();
|
|
27126
27219
|
if (message.method === "item/completed" && obj(params.item).type === "commandExecution") {
|
|
27127
27220
|
state.retained = { ...state.retained, kept: state.retained.kept.filter((item) => item.threadId !== id || item.itemId !== obj(params.item).id) };
|
|
27128
27221
|
for (const thread of initial.threads) {
|
|
@@ -27154,7 +27247,7 @@ async function retain() {
|
|
|
27154
27247
|
if (transferred) return;
|
|
27155
27248
|
const results = await Promise.allSettled(initial.threads.map(async (id) => {
|
|
27156
27249
|
if (readPrivate(leaseFile(backend, id))?.lease !== lease) return;
|
|
27157
|
-
await releaseNativeThread(connection, id, active.get(id), true
|
|
27250
|
+
await releaseNativeThread(connection, id, active.get(id), true);
|
|
27158
27251
|
if (readPrivate(leaseFile(backend, id))?.lease === lease) fs5.rmSync(leaseFile(backend, id), { force: true });
|
|
27159
27252
|
}));
|
|
27160
27253
|
const failure = results.find((result) => result.status === "rejected");
|
|
@@ -27162,6 +27255,7 @@ async function retain() {
|
|
|
27162
27255
|
} catch (error) {
|
|
27163
27256
|
for (const id of initial.threads) if (readPrivate(leaseFile(backend, id))?.lease === lease) writeLease(backend, id, { ...state, retained: void 0, uncertain: true });
|
|
27164
27257
|
if (!closing) throw error;
|
|
27258
|
+
console.error(codexDiagnostic(error));
|
|
27165
27259
|
} finally {
|
|
27166
27260
|
connection.close();
|
|
27167
27261
|
release();
|