wildcrane-runner 0.6.104 → 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 +262 -110
- 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 +924 -783
- package/dist/launcher.mjs +4 -4
- package/dist/plugin.mjs +4 -4
- package/dist/runner.mjs +847 -661
- package/dist/settings.mjs +4 -4
- package/package.json +1 -1
package/dist/codex-proxy.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;
|
|
@@ -958,9 +958,9 @@ var require_timers = __commonJS({
|
|
|
958
958
|
* before the specified function or code is executed.
|
|
959
959
|
* @param {*} arg
|
|
960
960
|
*/
|
|
961
|
-
constructor(callback,
|
|
961
|
+
constructor(callback, delay4, arg) {
|
|
962
962
|
this._onTimeout = callback;
|
|
963
|
-
this._idleTimeout =
|
|
963
|
+
this._idleTimeout = delay4;
|
|
964
964
|
this._timerArg = arg;
|
|
965
965
|
this.refresh();
|
|
966
966
|
}
|
|
@@ -1005,8 +1005,8 @@ var require_timers = __commonJS({
|
|
|
1005
1005
|
* when the timer expires.
|
|
1006
1006
|
* @returns {NodeJS.Timeout|FastTimer}
|
|
1007
1007
|
*/
|
|
1008
|
-
setTimeout(callback,
|
|
1009
|
-
return
|
|
1008
|
+
setTimeout(callback, delay4, arg) {
|
|
1009
|
+
return delay4 <= RESOLUTION_MS ? setTimeout(callback, delay4, arg) : new FastTimer(callback, delay4, arg);
|
|
1010
1010
|
},
|
|
1011
1011
|
/**
|
|
1012
1012
|
* The clearTimeout method cancels an instantiated Timer previously created
|
|
@@ -1032,8 +1032,8 @@ var require_timers = __commonJS({
|
|
|
1032
1032
|
* when the timer expires.
|
|
1033
1033
|
* @returns {FastTimer}
|
|
1034
1034
|
*/
|
|
1035
|
-
setFastTimeout(callback,
|
|
1036
|
-
return new FastTimer(callback,
|
|
1035
|
+
setFastTimeout(callback, delay4, arg) {
|
|
1036
|
+
return new FastTimer(callback, delay4, arg);
|
|
1037
1037
|
},
|
|
1038
1038
|
/**
|
|
1039
1039
|
* The clearTimeout method cancels an instantiated FastTimer previously
|
|
@@ -1059,8 +1059,8 @@ var require_timers = __commonJS({
|
|
|
1059
1059
|
* @deprecated
|
|
1060
1060
|
* @param {number} [delay=0] The delay in milliseconds to add to the now value.
|
|
1061
1061
|
*/
|
|
1062
|
-
tick(
|
|
1063
|
-
fastNow +=
|
|
1062
|
+
tick(delay4 = 0) {
|
|
1063
|
+
fastNow += delay4 - RESOLUTION_MS + 1;
|
|
1064
1064
|
onTick();
|
|
1065
1065
|
onTick();
|
|
1066
1066
|
},
|
|
@@ -1885,14 +1885,14 @@ var require_util = __commonJS({
|
|
|
1885
1885
|
}
|
|
1886
1886
|
const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80;
|
|
1887
1887
|
let origin = url.origin != null ? url.origin : `${url.protocol || ""}//${url.hostname || ""}:${port}`;
|
|
1888
|
-
let
|
|
1888
|
+
let path9 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`;
|
|
1889
1889
|
if (origin[origin.length - 1] === "/") {
|
|
1890
1890
|
origin = origin.slice(0, origin.length - 1);
|
|
1891
1891
|
}
|
|
1892
|
-
if (
|
|
1893
|
-
|
|
1892
|
+
if (path9 && path9[0] !== "/") {
|
|
1893
|
+
path9 = `/${path9}`;
|
|
1894
1894
|
}
|
|
1895
|
-
return new URL(`${origin}${
|
|
1895
|
+
return new URL(`${origin}${path9}`);
|
|
1896
1896
|
}
|
|
1897
1897
|
if (!isHttpOrHttpsPrefixed(url.origin || url.protocol)) {
|
|
1898
1898
|
throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`.");
|
|
@@ -2727,9 +2727,9 @@ var require_diagnostics = __commonJS({
|
|
|
2727
2727
|
"undici:client:sendHeaders",
|
|
2728
2728
|
(evt) => {
|
|
2729
2729
|
const {
|
|
2730
|
-
request: { method, path:
|
|
2730
|
+
request: { method, path: path9, origin }
|
|
2731
2731
|
} = evt;
|
|
2732
|
-
debugLog("sending request to %s %s%s", method, origin,
|
|
2732
|
+
debugLog("sending request to %s %s%s", method, origin, path9);
|
|
2733
2733
|
}
|
|
2734
2734
|
);
|
|
2735
2735
|
}
|
|
@@ -2747,14 +2747,14 @@ var require_diagnostics = __commonJS({
|
|
|
2747
2747
|
"undici:request:headers",
|
|
2748
2748
|
(evt) => {
|
|
2749
2749
|
const {
|
|
2750
|
-
request: { method, path:
|
|
2750
|
+
request: { method, path: path9, origin },
|
|
2751
2751
|
response: { statusCode }
|
|
2752
2752
|
} = evt;
|
|
2753
2753
|
debugLog(
|
|
2754
2754
|
"received response to %s %s%s - HTTP %d",
|
|
2755
2755
|
method,
|
|
2756
2756
|
origin,
|
|
2757
|
-
|
|
2757
|
+
path9,
|
|
2758
2758
|
statusCode
|
|
2759
2759
|
);
|
|
2760
2760
|
}
|
|
@@ -2763,23 +2763,23 @@ var require_diagnostics = __commonJS({
|
|
|
2763
2763
|
"undici:request:trailers",
|
|
2764
2764
|
(evt) => {
|
|
2765
2765
|
const {
|
|
2766
|
-
request: { method, path:
|
|
2766
|
+
request: { method, path: path9, origin }
|
|
2767
2767
|
} = evt;
|
|
2768
|
-
debugLog("trailers received from %s %s%s", method, origin,
|
|
2768
|
+
debugLog("trailers received from %s %s%s", method, origin, path9);
|
|
2769
2769
|
}
|
|
2770
2770
|
);
|
|
2771
2771
|
diagnosticsChannel.subscribe(
|
|
2772
2772
|
"undici:request:error",
|
|
2773
2773
|
(evt) => {
|
|
2774
2774
|
const {
|
|
2775
|
-
request: { method, path:
|
|
2775
|
+
request: { method, path: path9, origin },
|
|
2776
2776
|
error
|
|
2777
2777
|
} = evt;
|
|
2778
2778
|
debugLog(
|
|
2779
2779
|
"request to %s %s%s errored - %s",
|
|
2780
2780
|
method,
|
|
2781
2781
|
origin,
|
|
2782
|
-
|
|
2782
|
+
path9,
|
|
2783
2783
|
error.message
|
|
2784
2784
|
);
|
|
2785
2785
|
}
|
|
@@ -2894,7 +2894,7 @@ var require_request = __commonJS({
|
|
|
2894
2894
|
var kHandler = /* @__PURE__ */ Symbol("handler");
|
|
2895
2895
|
var Request = class {
|
|
2896
2896
|
constructor(origin, {
|
|
2897
|
-
path:
|
|
2897
|
+
path: path9,
|
|
2898
2898
|
method,
|
|
2899
2899
|
body,
|
|
2900
2900
|
headers,
|
|
@@ -2911,11 +2911,11 @@ var require_request = __commonJS({
|
|
|
2911
2911
|
maxRedirections,
|
|
2912
2912
|
typeOfService
|
|
2913
2913
|
}, handler) {
|
|
2914
|
-
if (typeof
|
|
2914
|
+
if (typeof path9 !== "string") {
|
|
2915
2915
|
throw new InvalidArgumentError("path must be a string");
|
|
2916
|
-
} else if (
|
|
2916
|
+
} else if (path9[0] !== "/" && !(path9.startsWith("http://") || path9.startsWith("https://")) && method !== "CONNECT") {
|
|
2917
2917
|
throw new InvalidArgumentError("path must be an absolute URL or start with a slash");
|
|
2918
|
-
} else if (invalidPathRegex.test(
|
|
2918
|
+
} else if (invalidPathRegex.test(path9)) {
|
|
2919
2919
|
throw new InvalidArgumentError("invalid request path");
|
|
2920
2920
|
}
|
|
2921
2921
|
if (typeof method !== "string") {
|
|
@@ -2990,7 +2990,7 @@ var require_request = __commonJS({
|
|
|
2990
2990
|
this.completed = false;
|
|
2991
2991
|
this.aborted = false;
|
|
2992
2992
|
this.upgrade = upgrade || null;
|
|
2993
|
-
this.path = query ? serializePathWithQuery(
|
|
2993
|
+
this.path = query ? serializePathWithQuery(path9, query) : path9;
|
|
2994
2994
|
this.origin = origin;
|
|
2995
2995
|
this.protocol = getProtocolFromUrlString(origin);
|
|
2996
2996
|
this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
|
|
@@ -7578,21 +7578,21 @@ var require_client_h1 = __commonJS({
|
|
|
7578
7578
|
this.connection = "";
|
|
7579
7579
|
this.maxResponseSize = client[kMaxResponseSize];
|
|
7580
7580
|
}
|
|
7581
|
-
setTimeout(
|
|
7582
|
-
if (
|
|
7581
|
+
setTimeout(delay4, type) {
|
|
7582
|
+
if (delay4 !== this.timeoutValue || type & USE_FAST_TIMER ^ this.timeoutType & USE_FAST_TIMER) {
|
|
7583
7583
|
if (this.timeout) {
|
|
7584
7584
|
timers.clearTimeout(this.timeout);
|
|
7585
7585
|
this.timeout = null;
|
|
7586
7586
|
}
|
|
7587
|
-
if (
|
|
7587
|
+
if (delay4) {
|
|
7588
7588
|
if (type & USE_FAST_TIMER) {
|
|
7589
|
-
this.timeout = timers.setFastTimeout(onParserTimeout,
|
|
7589
|
+
this.timeout = timers.setFastTimeout(onParserTimeout, delay4, this.timeoutWeakRef);
|
|
7590
7590
|
} else {
|
|
7591
|
-
this.timeout = setTimeout(onParserTimeout,
|
|
7591
|
+
this.timeout = setTimeout(onParserTimeout, delay4, this.timeoutWeakRef);
|
|
7592
7592
|
this.timeout?.unref();
|
|
7593
7593
|
}
|
|
7594
7594
|
}
|
|
7595
|
-
this.timeoutValue =
|
|
7595
|
+
this.timeoutValue = delay4;
|
|
7596
7596
|
} else if (this.timeout) {
|
|
7597
7597
|
if (this.timeout.refresh) {
|
|
7598
7598
|
this.timeout.refresh();
|
|
@@ -8234,7 +8234,7 @@ var require_client_h1 = __commonJS({
|
|
|
8234
8234
|
}
|
|
8235
8235
|
}
|
|
8236
8236
|
function writeH1(client, request) {
|
|
8237
|
-
const { method, path:
|
|
8237
|
+
const { method, path: path9, host, upgrade, blocking, reset } = request;
|
|
8238
8238
|
let { body, headers, contentLength } = request;
|
|
8239
8239
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
|
|
8240
8240
|
if (util.isFormDataLike(body)) {
|
|
@@ -8310,7 +8310,7 @@ var require_client_h1 = __commonJS({
|
|
|
8310
8310
|
socket[kBlocking] = true;
|
|
8311
8311
|
}
|
|
8312
8312
|
setTypeOfService(socket, request);
|
|
8313
|
-
let header = `${method} ${
|
|
8313
|
+
let header = `${method} ${path9} HTTP/1.1\r
|
|
8314
8314
|
`;
|
|
8315
8315
|
if (typeof host === "string") {
|
|
8316
8316
|
header += `host: ${host}\r
|
|
@@ -8987,7 +8987,7 @@ var require_client_h2 = __commonJS({
|
|
|
8987
8987
|
const headersTimeout = request.headersTimeout ?? client[kHeadersTimeout];
|
|
8988
8988
|
const bodyTimeout = request.bodyTimeout ?? client[kBodyTimeout];
|
|
8989
8989
|
const session = client[kHTTP2Session];
|
|
8990
|
-
const { method, path:
|
|
8990
|
+
const { method, path: path9, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request;
|
|
8991
8991
|
let { body } = request;
|
|
8992
8992
|
if (upgrade != null && upgrade !== "websocket") {
|
|
8993
8993
|
util.errorRequest(client, request, new InvalidArgumentError(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
|
|
@@ -9056,7 +9056,7 @@ var require_client_h2 = __commonJS({
|
|
|
9056
9056
|
}
|
|
9057
9057
|
headers[HTTP2_HEADER_METHOD] = "CONNECT";
|
|
9058
9058
|
headers[HTTP2_HEADER_PROTOCOL] = "websocket";
|
|
9059
|
-
headers[HTTP2_HEADER_PATH] =
|
|
9059
|
+
headers[HTTP2_HEADER_PATH] = path9;
|
|
9060
9060
|
if (protocol === "ws:" || protocol === "wss:") {
|
|
9061
9061
|
headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
|
|
9062
9062
|
} else {
|
|
@@ -9108,7 +9108,7 @@ var require_client_h2 = __commonJS({
|
|
|
9108
9108
|
stream.setTimeout(headersTimeout);
|
|
9109
9109
|
return true;
|
|
9110
9110
|
}
|
|
9111
|
-
headers[HTTP2_HEADER_PATH] =
|
|
9111
|
+
headers[HTTP2_HEADER_PATH] = path9;
|
|
9112
9112
|
headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
|
|
9113
9113
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
|
|
9114
9114
|
if (body && typeof body.read === "function") {
|
|
@@ -11464,10 +11464,10 @@ var require_proxy_agent = __commonJS({
|
|
|
11464
11464
|
};
|
|
11465
11465
|
const {
|
|
11466
11466
|
origin,
|
|
11467
|
-
path:
|
|
11467
|
+
path: path9 = "/",
|
|
11468
11468
|
headers = {}
|
|
11469
11469
|
} = opts;
|
|
11470
|
-
opts.path = origin +
|
|
11470
|
+
opts.path = origin + path9;
|
|
11471
11471
|
if (!("host" in headers) && !("Host" in headers)) {
|
|
11472
11472
|
const { host } = new URL(origin);
|
|
11473
11473
|
headers.host = host;
|
|
@@ -13627,20 +13627,20 @@ var require_mock_utils = __commonJS({
|
|
|
13627
13627
|
}
|
|
13628
13628
|
return normalizedQp;
|
|
13629
13629
|
}
|
|
13630
|
-
function safeUrl(
|
|
13631
|
-
if (typeof
|
|
13632
|
-
return
|
|
13630
|
+
function safeUrl(path9) {
|
|
13631
|
+
if (typeof path9 !== "string") {
|
|
13632
|
+
return path9;
|
|
13633
13633
|
}
|
|
13634
|
-
const pathSegments =
|
|
13634
|
+
const pathSegments = path9.split("?", 3);
|
|
13635
13635
|
if (pathSegments.length !== 2) {
|
|
13636
|
-
return
|
|
13636
|
+
return path9;
|
|
13637
13637
|
}
|
|
13638
13638
|
const qp = new URLSearchParams(pathSegments.pop());
|
|
13639
13639
|
qp.sort();
|
|
13640
13640
|
return [...pathSegments, qp.toString()].join("?");
|
|
13641
13641
|
}
|
|
13642
|
-
function matchKey(mockDispatch2, { path:
|
|
13643
|
-
const pathMatch = matchValue(mockDispatch2.path,
|
|
13642
|
+
function matchKey(mockDispatch2, { path: path9, method, body, headers }) {
|
|
13643
|
+
const pathMatch = matchValue(mockDispatch2.path, path9);
|
|
13644
13644
|
const methodMatch = matchValue(mockDispatch2.method, method);
|
|
13645
13645
|
const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
|
|
13646
13646
|
const headersMatch = matchHeaders(mockDispatch2, headers);
|
|
@@ -13665,8 +13665,8 @@ var require_mock_utils = __commonJS({
|
|
|
13665
13665
|
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
|
|
13666
13666
|
const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
|
|
13667
13667
|
const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
|
|
13668
|
-
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path:
|
|
13669
|
-
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(
|
|
13668
|
+
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path9, ignoreTrailingSlash }) => {
|
|
13669
|
+
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path9)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path9), resolvedPath);
|
|
13670
13670
|
});
|
|
13671
13671
|
if (matchedMockDispatches.length === 0) {
|
|
13672
13672
|
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
|
|
@@ -13705,19 +13705,19 @@ var require_mock_utils = __commonJS({
|
|
|
13705
13705
|
mockDispatches.splice(index, 1);
|
|
13706
13706
|
}
|
|
13707
13707
|
}
|
|
13708
|
-
function removeTrailingSlash(
|
|
13709
|
-
while (
|
|
13710
|
-
|
|
13708
|
+
function removeTrailingSlash(path9) {
|
|
13709
|
+
while (path9.endsWith("/")) {
|
|
13710
|
+
path9 = path9.slice(0, -1);
|
|
13711
13711
|
}
|
|
13712
|
-
if (
|
|
13713
|
-
|
|
13712
|
+
if (path9.length === 0) {
|
|
13713
|
+
path9 = "/";
|
|
13714
13714
|
}
|
|
13715
|
-
return
|
|
13715
|
+
return path9;
|
|
13716
13716
|
}
|
|
13717
13717
|
function buildKey(opts) {
|
|
13718
|
-
const { path:
|
|
13718
|
+
const { path: path9, method, body, headers, query } = opts;
|
|
13719
13719
|
return {
|
|
13720
|
-
path:
|
|
13720
|
+
path: path9,
|
|
13721
13721
|
method,
|
|
13722
13722
|
body,
|
|
13723
13723
|
headers,
|
|
@@ -13758,7 +13758,7 @@ var require_mock_utils = __commonJS({
|
|
|
13758
13758
|
if (mockDispatch2.data.callback) {
|
|
13759
13759
|
mockDispatch2.data = { ...mockDispatch2.data, ...mockDispatch2.data.callback(opts) };
|
|
13760
13760
|
}
|
|
13761
|
-
const { data: { statusCode, data, headers, trailers, error }, delay:
|
|
13761
|
+
const { data: { statusCode, data, headers, trailers, error }, delay: delay4, persist } = mockDispatch2;
|
|
13762
13762
|
const { timesInvoked, times } = mockDispatch2;
|
|
13763
13763
|
mockDispatch2.consumed = !persist && timesInvoked >= times;
|
|
13764
13764
|
mockDispatch2.pending = timesInvoked < times;
|
|
@@ -13781,11 +13781,11 @@ var require_mock_utils = __commonJS({
|
|
|
13781
13781
|
handler.onError(err);
|
|
13782
13782
|
}
|
|
13783
13783
|
handler.onConnect?.(abort, null);
|
|
13784
|
-
if (typeof
|
|
13784
|
+
if (typeof delay4 === "number" && delay4 > 0) {
|
|
13785
13785
|
timer = setTimeout(() => {
|
|
13786
13786
|
timer = null;
|
|
13787
13787
|
handleReply(this[kDispatches]);
|
|
13788
|
-
},
|
|
13788
|
+
}, delay4);
|
|
13789
13789
|
} else {
|
|
13790
13790
|
handleReply(this[kDispatches]);
|
|
13791
13791
|
}
|
|
@@ -14407,10 +14407,10 @@ var require_pending_interceptors_formatter = __commonJS({
|
|
|
14407
14407
|
}
|
|
14408
14408
|
format(pendingInterceptors) {
|
|
14409
14409
|
const withPrettyHeaders = pendingInterceptors.map(
|
|
14410
|
-
({ method, path:
|
|
14410
|
+
({ method, path: path9, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
|
14411
14411
|
Method: method,
|
|
14412
14412
|
Origin: origin,
|
|
14413
|
-
Path:
|
|
14413
|
+
Path: path9,
|
|
14414
14414
|
"Status code": statusCode,
|
|
14415
14415
|
Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
|
|
14416
14416
|
Invocations: timesInvoked,
|
|
@@ -14492,9 +14492,9 @@ var require_mock_agent = __commonJS({
|
|
|
14492
14492
|
const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
|
|
14493
14493
|
const dispatchOpts = { ...opts };
|
|
14494
14494
|
if (acceptNonStandardSearchParameters && dispatchOpts.path) {
|
|
14495
|
-
const [
|
|
14495
|
+
const [path9, searchParams] = dispatchOpts.path.split("?");
|
|
14496
14496
|
const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
|
|
14497
|
-
dispatchOpts.path = `${
|
|
14497
|
+
dispatchOpts.path = `${path9}?${normalizedSearchParams}`;
|
|
14498
14498
|
}
|
|
14499
14499
|
return this[kAgent].dispatch(dispatchOpts, handler);
|
|
14500
14500
|
}
|
|
@@ -14895,12 +14895,12 @@ var require_snapshot_recorder = __commonJS({
|
|
|
14895
14895
|
* @return {Promise<void>} - Resolves when snapshots are loaded
|
|
14896
14896
|
*/
|
|
14897
14897
|
async loadSnapshots(filePath) {
|
|
14898
|
-
const
|
|
14899
|
-
if (!
|
|
14898
|
+
const path9 = filePath || this.#snapshotPath;
|
|
14899
|
+
if (!path9) {
|
|
14900
14900
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
14901
14901
|
}
|
|
14902
14902
|
try {
|
|
14903
|
-
const data = await readFile(resolve(
|
|
14903
|
+
const data = await readFile(resolve(path9), "utf8");
|
|
14904
14904
|
const parsed = JSON.parse(data);
|
|
14905
14905
|
if (Array.isArray(parsed)) {
|
|
14906
14906
|
this.#snapshots.clear();
|
|
@@ -14914,7 +14914,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
14914
14914
|
if (error.code === "ENOENT") {
|
|
14915
14915
|
this.#snapshots.clear();
|
|
14916
14916
|
} else {
|
|
14917
|
-
throw new UndiciError(`Failed to load snapshots from ${
|
|
14917
|
+
throw new UndiciError(`Failed to load snapshots from ${path9}`, { cause: error });
|
|
14918
14918
|
}
|
|
14919
14919
|
}
|
|
14920
14920
|
}
|
|
@@ -14925,11 +14925,11 @@ var require_snapshot_recorder = __commonJS({
|
|
|
14925
14925
|
* @returns {Promise<void>} - Resolves when snapshots are saved
|
|
14926
14926
|
*/
|
|
14927
14927
|
async saveSnapshots(filePath) {
|
|
14928
|
-
const
|
|
14929
|
-
if (!
|
|
14928
|
+
const path9 = filePath || this.#snapshotPath;
|
|
14929
|
+
if (!path9) {
|
|
14930
14930
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
14931
14931
|
}
|
|
14932
|
-
const resolvedPath = resolve(
|
|
14932
|
+
const resolvedPath = resolve(path9);
|
|
14933
14933
|
await mkdir(dirname(resolvedPath), { recursive: true });
|
|
14934
14934
|
const data = Array.from(this.#snapshots.entries()).map(([hash, snapshot]) => ({
|
|
14935
14935
|
hash,
|
|
@@ -15570,15 +15570,15 @@ var require_redirect_handler = __commonJS({
|
|
|
15570
15570
|
receivedAt: Date.now()
|
|
15571
15571
|
});
|
|
15572
15572
|
const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
|
|
15573
|
-
const
|
|
15574
|
-
const redirectUrlString = `${origin}${
|
|
15573
|
+
const path9 = search ? `${pathname}${search}` : pathname;
|
|
15574
|
+
const redirectUrlString = `${origin}${path9}`;
|
|
15575
15575
|
for (const historyUrl of this.history) {
|
|
15576
15576
|
if (historyUrl.toString() === redirectUrlString) {
|
|
15577
15577
|
throw new InvalidArgumentError(`Redirect loop detected. Cannot redirect to ${origin}. This typically happens when using a Client or Pool with cross-origin redirects. Use an Agent for cross-origin redirects.`);
|
|
15578
15578
|
}
|
|
15579
15579
|
}
|
|
15580
15580
|
this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
|
|
15581
|
-
this.opts.path =
|
|
15581
|
+
this.opts.path = path9;
|
|
15582
15582
|
this.opts.origin = origin;
|
|
15583
15583
|
this.opts.query = null;
|
|
15584
15584
|
}
|
|
@@ -17395,10 +17395,10 @@ var require_cache_handler = __commonJS({
|
|
|
17395
17395
|
}
|
|
17396
17396
|
return locationUrl.pathname + locationUrl.search;
|
|
17397
17397
|
}
|
|
17398
|
-
function deleteCachedUri(store, cacheKey,
|
|
17398
|
+
function deleteCachedUri(store, cacheKey, path9) {
|
|
17399
17399
|
deleteCachedValue(store, {
|
|
17400
17400
|
...cacheKey,
|
|
17401
|
-
path:
|
|
17401
|
+
path: path9
|
|
17402
17402
|
});
|
|
17403
17403
|
for (let i = 0; i < util.safeHTTPMethods.length; i++) {
|
|
17404
17404
|
const method = util.safeHTTPMethods[i];
|
|
@@ -17406,7 +17406,7 @@ var require_cache_handler = __commonJS({
|
|
|
17406
17406
|
deleteCachedValue(store, {
|
|
17407
17407
|
...cacheKey,
|
|
17408
17408
|
method,
|
|
17409
|
-
path:
|
|
17409
|
+
path: path9
|
|
17410
17410
|
});
|
|
17411
17411
|
}
|
|
17412
17412
|
}
|
|
@@ -17417,9 +17417,9 @@ var require_cache_handler = __commonJS({
|
|
|
17417
17417
|
}
|
|
17418
17418
|
const values = Array.isArray(headerValue) ? headerValue : [headerValue];
|
|
17419
17419
|
for (let i = 0; i < values.length; i++) {
|
|
17420
|
-
const
|
|
17421
|
-
if (
|
|
17422
|
-
deleteCachedUri(store, cacheKey,
|
|
17420
|
+
const path9 = getSameOriginPath(cacheKey, values[i]);
|
|
17421
|
+
if (path9 !== void 0) {
|
|
17422
|
+
deleteCachedUri(store, cacheKey, path9);
|
|
17423
17423
|
}
|
|
17424
17424
|
}
|
|
17425
17425
|
}
|
|
@@ -22907,11 +22907,11 @@ var require_fetch = __commonJS({
|
|
|
22907
22907
|
function dispatch({ body }) {
|
|
22908
22908
|
const url = requestCurrentURL(request);
|
|
22909
22909
|
const agent = fetchParams.controller.dispatcher;
|
|
22910
|
-
const
|
|
22910
|
+
const path9 = url.pathname + url.search;
|
|
22911
22911
|
const hasTrailingQuestionMark = url.search.length === 0 && url.href[url.href.length - url.hash.length - 1] === "?";
|
|
22912
22912
|
return new Promise((resolve, reject) => agent.dispatch(
|
|
22913
22913
|
{
|
|
22914
|
-
path: hasTrailingQuestionMark ? `${
|
|
22914
|
+
path: hasTrailingQuestionMark ? `${path9}?` : path9,
|
|
22915
22915
|
origin: url.origin,
|
|
22916
22916
|
method: request.method,
|
|
22917
22917
|
body: agent.isMockActive ? request.body && (request.body.source || request.body.stream) : body,
|
|
@@ -23858,9 +23858,9 @@ var require_util4 = __commonJS({
|
|
|
23858
23858
|
}
|
|
23859
23859
|
}
|
|
23860
23860
|
}
|
|
23861
|
-
function validateCookiePath(
|
|
23862
|
-
for (let i = 0; i <
|
|
23863
|
-
const code =
|
|
23861
|
+
function validateCookiePath(path9) {
|
|
23862
|
+
for (let i = 0; i < path9.length; ++i) {
|
|
23863
|
+
const code = path9.charCodeAt(i);
|
|
23864
23864
|
if (code < 32 || // exclude CTLs (0-31)
|
|
23865
23865
|
code > 126 || // exclude DEL and non-ascii
|
|
23866
23866
|
code === 59) {
|
|
@@ -27296,11 +27296,11 @@ var require_undici = __commonJS({
|
|
|
27296
27296
|
if (typeof opts.path !== "string") {
|
|
27297
27297
|
throw new InvalidArgumentError("invalid opts.path");
|
|
27298
27298
|
}
|
|
27299
|
-
let
|
|
27299
|
+
let path9 = opts.path;
|
|
27300
27300
|
if (!opts.path.startsWith("/")) {
|
|
27301
|
-
|
|
27301
|
+
path9 = `/${path9}`;
|
|
27302
27302
|
}
|
|
27303
|
-
url = new URL(util.parseOrigin(url).origin +
|
|
27303
|
+
url = new URL(util.parseOrigin(url).origin + path9);
|
|
27304
27304
|
} else {
|
|
27305
27305
|
if (!opts) {
|
|
27306
27306
|
opts = typeof url === "object" ? url : {};
|
|
@@ -27414,9 +27414,9 @@ import { createInterface } from "node:readline";
|
|
|
27414
27414
|
|
|
27415
27415
|
// src/codex-execution.ts
|
|
27416
27416
|
import crypto2 from "node:crypto";
|
|
27417
|
-
import
|
|
27418
|
-
import
|
|
27419
|
-
import { setTimeout as
|
|
27417
|
+
import fs6 from "node:fs";
|
|
27418
|
+
import path7 from "node:path";
|
|
27419
|
+
import { setTimeout as delay2 } from "node:timers/promises";
|
|
27420
27420
|
import { spawn } from "node:child_process";
|
|
27421
27421
|
import { fileURLToPath } from "node:url";
|
|
27422
27422
|
|
|
@@ -27772,12 +27772,17 @@ function mcpEnvironment(config, defaults) {
|
|
|
27772
27772
|
}
|
|
27773
27773
|
}
|
|
27774
27774
|
|
|
27775
|
+
// src/codex-ownership.ts
|
|
27776
|
+
import fs5 from "node:fs";
|
|
27777
|
+
import path6 from "node:path";
|
|
27778
|
+
|
|
27775
27779
|
// src/codex-native.ts
|
|
27776
27780
|
import crypto from "node:crypto";
|
|
27777
27781
|
import fs4 from "node:fs";
|
|
27778
27782
|
var import_undici2 = __toESM(require_undici(), 1);
|
|
27779
27783
|
import path5 from "node:path";
|
|
27780
27784
|
import { PassThrough, Writable } from "node:stream";
|
|
27785
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
27781
27786
|
|
|
27782
27787
|
// ../cli/src/lib/agent/connection-process.ts
|
|
27783
27788
|
import { spawnSync } from "node:child_process";
|
|
@@ -27874,61 +27879,141 @@ async function nativeConnection(backend, onMessage) {
|
|
|
27874
27879
|
close();
|
|
27875
27880
|
throw error;
|
|
27876
27881
|
}
|
|
27877
|
-
const
|
|
27878
|
-
|
|
27882
|
+
const unloads = new EventTarget();
|
|
27883
|
+
const rpc = connect(incoming, outgoing, (message) => {
|
|
27884
|
+
const params = obj(message.params), id = str(params.threadId);
|
|
27885
|
+
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));
|
|
27886
|
+
onMessage(message);
|
|
27887
|
+
});
|
|
27888
|
+
return { rpc, incoming, close, unloads };
|
|
27879
27889
|
}
|
|
27880
27890
|
async function initializeNative(connection) {
|
|
27881
27891
|
const result = await bounded(connection.rpc.call("initialize", { clientInfo: { name: "wildcrane", version: "1" }, capabilities: { experimentalApi: true } }), CODEX_TIMEOUT, "Codex initialize timed out.");
|
|
27882
27892
|
connection.rpc.notify("initialized");
|
|
27883
27893
|
return result;
|
|
27884
27894
|
}
|
|
27885
|
-
async function backgroundTerminals(rpc, threadId) {
|
|
27895
|
+
async function backgroundTerminals(rpc, threadId, deadline = Date.now() + CODEX_TIMEOUT) {
|
|
27886
27896
|
const result = [], seen = /* @__PURE__ */ new Set();
|
|
27887
|
-
let cursor
|
|
27897
|
+
let cursor;
|
|
27888
27898
|
do {
|
|
27889
|
-
if (
|
|
27890
|
-
|
|
27891
|
-
|
|
27899
|
+
if (cursor !== void 0) {
|
|
27900
|
+
if (seen.has(cursor)) throw Error("Codex repeated a terminal cursor.");
|
|
27901
|
+
seen.add(cursor);
|
|
27902
|
+
}
|
|
27903
|
+
const page = await beforeDeadline(deadline, "background terminal verification", () => rpc.call("thread/backgroundTerminals/list", { threadId, ...cursor === void 0 ? {} : { cursor } }));
|
|
27892
27904
|
if (!Array.isArray(page.data) || page.nextCursor != null && typeof page.nextCursor !== "string") throw Error("Codex background terminal state is unconfirmed.");
|
|
27893
27905
|
for (const value of page.data) result.push({ ...obj(value), threadId });
|
|
27894
|
-
cursor = page.nextCursor;
|
|
27895
|
-
} while (cursor);
|
|
27906
|
+
cursor = typeof page.nextCursor === "string" ? page.nextCursor : void 0;
|
|
27907
|
+
} while (cursor !== void 0);
|
|
27896
27908
|
return result;
|
|
27897
27909
|
}
|
|
27898
|
-
|
|
27899
|
-
|
|
27910
|
+
function codexDiagnostic(error) {
|
|
27911
|
+
return error instanceof RpcError ? `RPC ${error.code ?? "unknown"}: ${error.message}` : error instanceof Error ? error.message : String(error);
|
|
27912
|
+
}
|
|
27913
|
+
function beforeDeadline(deadline, operation, run) {
|
|
27914
|
+
const timeout = `Codex ${operation} timed out.`;
|
|
27915
|
+
const remaining = deadline - Date.now();
|
|
27916
|
+
if (remaining <= 0) throw Error(timeout);
|
|
27917
|
+
return bounded(run(), remaining, timeout);
|
|
27918
|
+
}
|
|
27919
|
+
async function inspectNativeThread(rpc, threadId, deadline = Date.now() + CODEX_TIMEOUT, checkBackground = true) {
|
|
27920
|
+
let diagnostic;
|
|
27900
27921
|
try {
|
|
27901
|
-
await
|
|
27902
|
-
|
|
27903
|
-
|
|
27904
|
-
|
|
27905
|
-
|
|
27906
|
-
|
|
27907
|
-
|
|
27908
|
-
|
|
27909
|
-
|
|
27910
|
-
|
|
27911
|
-
|
|
27912
|
-
|
|
27913
|
-
|
|
27914
|
-
|
|
27915
|
-
|
|
27916
|
-
|
|
27917
|
-
|
|
27922
|
+
const reply = await beforeDeadline(deadline, "thread/read", () => rpc.call("thread/read", { threadId }));
|
|
27923
|
+
const thread = obj(reply.thread), status = obj(thread.status).type;
|
|
27924
|
+
if (thread.id !== threadId || status !== "notLoaded" && status !== "active" && status !== "idle") {
|
|
27925
|
+
throw Error("thread/read returned an unexpected thread or status.");
|
|
27926
|
+
}
|
|
27927
|
+
if (status === "idle" && checkBackground) {
|
|
27928
|
+
const work = await backgroundTerminals(rpc, threadId, deadline);
|
|
27929
|
+
if (work.length) return { status: "background-work", thread };
|
|
27930
|
+
}
|
|
27931
|
+
return { status, thread };
|
|
27932
|
+
} catch (error) {
|
|
27933
|
+
diagnostic = codexDiagnostic(error);
|
|
27934
|
+
}
|
|
27935
|
+
let cursor;
|
|
27936
|
+
const seen = /* @__PURE__ */ new Set();
|
|
27937
|
+
try {
|
|
27938
|
+
do {
|
|
27939
|
+
const page = await beforeDeadline(deadline, "thread/loaded/list", () => rpc.call("thread/loaded/list", cursor === void 0 ? {} : { cursor }));
|
|
27940
|
+
const next = page.nextCursor;
|
|
27941
|
+
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.");
|
|
27942
|
+
if (page.data.includes(threadId)) return { status: "unverified", diagnostic: `${diagnostic} The thread is still loaded.` };
|
|
27943
|
+
cursor = typeof next === "string" ? next : void 0;
|
|
27944
|
+
if (cursor !== void 0) {
|
|
27945
|
+
if (seen.has(cursor)) throw Error("thread/loaded/list repeated a cursor.");
|
|
27946
|
+
seen.add(cursor);
|
|
27947
|
+
}
|
|
27948
|
+
} while (cursor !== void 0);
|
|
27949
|
+
return { status: "notLoaded", diagnostic };
|
|
27950
|
+
} catch (error) {
|
|
27951
|
+
return { status: "unverified", diagnostic: `${diagnostic} ${codexDiagnostic(error)}` };
|
|
27952
|
+
}
|
|
27953
|
+
}
|
|
27954
|
+
function releaseError(method, threadId, evidence, error) {
|
|
27955
|
+
const diagnostic = [`${method} could not confirm Codex thread ${threadId}: ${evidence.status}.`, evidence.diagnostic].filter(Boolean).join(" ");
|
|
27956
|
+
return error instanceof RpcError ? new RpcError(`${error.message} ${diagnostic}`, error.code, error.data) : Error([error && codexDiagnostic(error), diagnostic].filter(Boolean).join(" "));
|
|
27957
|
+
}
|
|
27958
|
+
async function interruptNativeThread(connection, threadId, turnId, deadline) {
|
|
27959
|
+
try {
|
|
27960
|
+
await beforeDeadline(deadline, "turn/interrupt", () => connection.rpc.call("turn/interrupt", { threadId, turnId }));
|
|
27961
|
+
} catch (error) {
|
|
27962
|
+
const evidence = await inspectNativeThread(connection.rpc, threadId, deadline, false);
|
|
27963
|
+
if (evidence.status !== "idle" && evidence.status !== "notLoaded") throw releaseError("turn/interrupt", threadId, evidence, error);
|
|
27964
|
+
console.error(`Codex turn/interrupt: ${codexDiagnostic(error)} (${evidence.status}, ${threadId})`);
|
|
27965
|
+
}
|
|
27966
|
+
}
|
|
27967
|
+
async function releaseNativeThread(connection, threadId, turnId, stopWork, deadline = Date.now() + CODEX_TIMEOUT) {
|
|
27968
|
+
const { rpc, unloads } = connection;
|
|
27969
|
+
let closed = false;
|
|
27970
|
+
let observed;
|
|
27971
|
+
const unloaded = new Promise((resolve) => {
|
|
27972
|
+
observed = () => {
|
|
27973
|
+
closed = true;
|
|
27974
|
+
resolve();
|
|
27975
|
+
};
|
|
27976
|
+
});
|
|
27977
|
+
unloads.addEventListener(threadId, observed, { once: true });
|
|
27978
|
+
const release = async () => {
|
|
27979
|
+
if (stopWork && turnId) await interruptNativeThread(connection, threadId, turnId, deadline);
|
|
27980
|
+
if (closed) return;
|
|
27981
|
+
if (stopWork) {
|
|
27918
27982
|
try {
|
|
27919
|
-
|
|
27983
|
+
await beforeDeadline(deadline, "thread/backgroundTerminals/clean", () => rpc.call("thread/backgroundTerminals/clean", { threadId }));
|
|
27920
27984
|
} catch (error) {
|
|
27921
|
-
if (
|
|
27922
|
-
|
|
27985
|
+
if (closed) return;
|
|
27986
|
+
if (!(error instanceof RpcError && error.code === -32601)) {
|
|
27987
|
+
const evidence = await inspectNativeThread(rpc, threadId, deadline, false);
|
|
27988
|
+
if (!closed && evidence.status !== "notLoaded") throw releaseError("thread/backgroundTerminals/clean", threadId, evidence, error);
|
|
27989
|
+
console.error(`Codex thread/backgroundTerminals/clean: ${codexDiagnostic(error)} (${threadId})`);
|
|
27990
|
+
return;
|
|
27991
|
+
}
|
|
27923
27992
|
}
|
|
27924
|
-
|
|
27925
|
-
|
|
27926
|
-
|
|
27927
|
-
|
|
27993
|
+
}
|
|
27994
|
+
if (closed) return;
|
|
27995
|
+
let status, failure;
|
|
27996
|
+
try {
|
|
27997
|
+
status = (await beforeDeadline(deadline, "thread/unsubscribe", () => rpc.call("thread/unsubscribe", { threadId }))).status;
|
|
27998
|
+
} catch (error) {
|
|
27999
|
+
failure = error;
|
|
28000
|
+
}
|
|
28001
|
+
if (status === "notLoaded") return;
|
|
28002
|
+
while (!closed) {
|
|
28003
|
+
const evidence = await inspectNativeThread(rpc, threadId, deadline, false);
|
|
28004
|
+
if (closed || evidence.status === "notLoaded") {
|
|
28005
|
+
if (failure) console.error(`Codex thread/unsubscribe: ${codexDiagnostic(failure)} (${threadId})`);
|
|
28006
|
+
return;
|
|
27928
28007
|
}
|
|
27929
|
-
|
|
28008
|
+
if (status !== "unsubscribed") throw releaseError("thread/unsubscribe", threadId, evidence, failure);
|
|
28009
|
+
if (Date.now() >= deadline) throw releaseError("thread unload", threadId, evidence, Error("Codex thread cleanup timed out."));
|
|
28010
|
+
await delay(Math.min(50, deadline - Date.now()));
|
|
28011
|
+
}
|
|
28012
|
+
};
|
|
28013
|
+
try {
|
|
28014
|
+
await Promise.race([release(), unloaded]);
|
|
27930
28015
|
} finally {
|
|
27931
|
-
|
|
28016
|
+
unloads.removeEventListener(threadId, observed);
|
|
27932
28017
|
}
|
|
27933
28018
|
}
|
|
27934
28019
|
|
|
@@ -27941,35 +28026,68 @@ function executionOwner(environment) {
|
|
|
27941
28026
|
}
|
|
27942
28027
|
return { run: environment.KANBAN_RUN?.trim() || void 0, task: environment.AI4KANBAN_TASK?.trim() || void 0, job: str(execution.job).trim() || void 0 };
|
|
27943
28028
|
}
|
|
27944
|
-
function ownershipConflict(thread, requester, owner, status, phase, wait = false) {
|
|
28029
|
+
function ownershipConflict(thread, requester, owner, status, phase, wait = false, diagnostic) {
|
|
27945
28030
|
const describe = (value) => ({ run: value?.run ?? "unknown", task: value?.task ?? "unknown", job: value?.job ?? "unknown", pid: value?.pid ?? "unknown", lease: value?.lease ?? "unknown" });
|
|
27946
|
-
const evidence = { thread, requester: describe(requester), owner: describe(owner), status, phase };
|
|
28031
|
+
const evidence = { thread, requester: describe(requester), owner: describe(owner), status, phase, diagnostic };
|
|
27947
28032
|
const failure = wait ? { code: "codex_source_busy", level: 2, source: "harness", reason: "Waiting for the source conversation to finish." } : { code: "codex_ownership_unconfirmed", level: 3, source: "invariant", reason: "The conversation could not be opened safely. Saved work was preserved." };
|
|
27948
28033
|
if (!wait) console.error(JSON.stringify({ code: failure.code, ...evidence }));
|
|
27949
28034
|
const message = status === "caller-does-not-own-thread" ? "This run does not own that Codex thread." : "Codex thread is already in use by another run.";
|
|
27950
28035
|
return new RpcError(`${message} ${JSON.stringify(evidence)}`, -32e3, { wildcraneFailure: failure });
|
|
27951
28036
|
}
|
|
27952
|
-
|
|
27953
|
-
|
|
28037
|
+
function leaseGroups(backend) {
|
|
28038
|
+
const directory2 = path6.join(nativeDirectory(), "threads", backend.instance);
|
|
28039
|
+
const groups = /* @__PURE__ */ new Map();
|
|
28040
|
+
let files;
|
|
27954
28041
|
try {
|
|
27955
|
-
|
|
28042
|
+
files = fs5.readdirSync(directory2).filter((name) => name.endsWith(".json"));
|
|
27956
28043
|
} catch (error) {
|
|
27957
|
-
if (
|
|
27958
|
-
|
|
27959
|
-
|
|
27960
|
-
|
|
27961
|
-
|
|
27962
|
-
|
|
27963
|
-
|
|
27964
|
-
|
|
27965
|
-
|
|
27966
|
-
|
|
27967
|
-
|
|
27968
|
-
return "notLoaded";
|
|
28044
|
+
if (error.code === "ENOENT") return groups;
|
|
28045
|
+
throw error;
|
|
28046
|
+
}
|
|
28047
|
+
for (const name of files) {
|
|
28048
|
+
const file = path6.join(directory2, name), owner = readPrivate(file);
|
|
28049
|
+
if (!owner || owner.instance !== backend.instance || !Array.isArray(owner.threads)) continue;
|
|
28050
|
+
const thread = owner.thread ?? owner.threads.find((id) => leaseFile(backend, id) === file);
|
|
28051
|
+
if (!thread || leaseFile(backend, thread) !== file) continue;
|
|
28052
|
+
const group = groups.get(owner.lease) ?? /* @__PURE__ */ new Map();
|
|
28053
|
+
group.set(thread, owner);
|
|
28054
|
+
groups.set(owner.lease, group);
|
|
27969
28055
|
}
|
|
27970
|
-
|
|
27971
|
-
|
|
27972
|
-
|
|
28056
|
+
return groups;
|
|
28057
|
+
}
|
|
28058
|
+
function abandonedLeaseGroup(backend, thread, owner) {
|
|
28059
|
+
const group = leaseGroups(backend).get(owner.lease) ?? /* @__PURE__ */ new Map();
|
|
28060
|
+
group.set(thread, owner);
|
|
28061
|
+
return group;
|
|
28062
|
+
}
|
|
28063
|
+
function lockLeaseGroup(backend, group) {
|
|
28064
|
+
const threads = [...new Set([...group].flatMap(([thread, owner]) => [thread, ...owner.threads]))].sort();
|
|
28065
|
+
const releases = [];
|
|
28066
|
+
const release = () => {
|
|
28067
|
+
for (const unlock of releases.reverse()) unlock();
|
|
28068
|
+
};
|
|
28069
|
+
try {
|
|
28070
|
+
for (const thread of threads) {
|
|
28071
|
+
const unlock = tryLock(leaseFile(backend, thread) + ".lock");
|
|
28072
|
+
if (!unlock) {
|
|
28073
|
+
release();
|
|
28074
|
+
return;
|
|
28075
|
+
}
|
|
28076
|
+
releases.push(unlock);
|
|
28077
|
+
}
|
|
28078
|
+
const abandoned = () => threads.every((thread) => {
|
|
28079
|
+
const owner = readPrivate(leaseFile(backend, thread)), expected = group.get(thread);
|
|
28080
|
+
return !owner || !!expected && Number.isInteger(owner.pid) && owner.pid > 0 && JSON.stringify(owner) === JSON.stringify(expected) && !liveLease(owner);
|
|
28081
|
+
});
|
|
28082
|
+
return { threads, abandoned, release };
|
|
28083
|
+
} catch (error) {
|
|
28084
|
+
release();
|
|
28085
|
+
throw error;
|
|
28086
|
+
}
|
|
28087
|
+
}
|
|
28088
|
+
async function verifyStoppedThreads(rpc, threads, deadline = Date.now() + CODEX_TIMEOUT) {
|
|
28089
|
+
const evidence = await Promise.all(threads.map(async (threadId) => ({ threadId, ...await inspectNativeThread(rpc, threadId, deadline) })));
|
|
28090
|
+
return evidence.find(({ status }) => status !== "idle" && status !== "notLoaded");
|
|
27973
28091
|
}
|
|
27974
28092
|
|
|
27975
28093
|
// src/codex-execution.ts
|
|
@@ -27980,15 +28098,14 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
27980
28098
|
const threads = /* @__PURE__ */ new Set(), active = /* @__PURE__ */ new Map(), requests = /* @__PURE__ */ new Set();
|
|
27981
28099
|
const preparing = /* @__PURE__ */ new Map();
|
|
27982
28100
|
const pending = /* @__PURE__ */ new Set();
|
|
27983
|
-
const unloading = /* @__PURE__ */ new Map();
|
|
27984
28101
|
let closing;
|
|
27985
28102
|
let settled;
|
|
27986
28103
|
let keeper = false;
|
|
27987
28104
|
let stoppingForRetry = false;
|
|
27988
|
-
const state = () => ({ ...identity, lease, instance: backend.instance, settings, threads: [...threads], ...settled ? { retained: settled } : {} });
|
|
28105
|
+
const state = () => ({ ...identity, lease, instance: backend.instance, settings, threads: [...threads], ...settled?.kept.length ? { retained: settled } : {} });
|
|
27989
28106
|
const owned = (id) => readPrivate(leaseFile(backend, id))?.lease === lease;
|
|
27990
28107
|
const remove = (id) => {
|
|
27991
|
-
if (owned(id))
|
|
28108
|
+
if (owned(id)) fs6.rmSync(leaseFile(backend, id), { force: true });
|
|
27992
28109
|
};
|
|
27993
28110
|
const leaseAt = (id, phase) => {
|
|
27994
28111
|
const file = leaseFile(backend, id);
|
|
@@ -27999,50 +28116,66 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
27999
28116
|
}
|
|
28000
28117
|
throw ownershipConflict(id, state(), void 0, "invalid-ownership-record", phase);
|
|
28001
28118
|
};
|
|
28119
|
+
const claimLocked = (id, loaded, previous, forkSource = false) => {
|
|
28120
|
+
const current = leaseAt(id, "claim-thread");
|
|
28121
|
+
if (current && current.lease !== lease && current.lease !== previous?.lease) throw ownershipConflict(id, state(), current, liveLease(current) ? "owner-alive" : "unverified", loaded ? "claim-thread" : "reserve-source", forkSource && liveLease(current));
|
|
28122
|
+
if (loaded) threads.add(id);
|
|
28123
|
+
writeLease(backend, id, { ...state(), ...previous?.retained?.kept.length ? { retained: previous.retained, adopting: previous.lease } : {} });
|
|
28124
|
+
for (const thread of threads) {
|
|
28125
|
+
const owner = readPrivate(leaseFile(backend, thread));
|
|
28126
|
+
if (owner?.lease === lease) writeLease(backend, thread, { ...owner, threads: [...threads] });
|
|
28127
|
+
}
|
|
28128
|
+
};
|
|
28002
28129
|
const claim = (id, loaded = true, previous, forkSource = false) => {
|
|
28003
28130
|
if (!id) return;
|
|
28004
|
-
const
|
|
28005
|
-
const release = tryLock(file + ".lock");
|
|
28131
|
+
const release = tryLock(leaseFile(backend, id) + ".lock");
|
|
28006
28132
|
if (!release) throw ownershipConflict(id, state(), leaseAt(id, "claim-thread"), "ownership-transfer", loaded ? "claim-thread" : "reserve-source", forkSource);
|
|
28007
28133
|
try {
|
|
28008
|
-
|
|
28009
|
-
if (current && current.lease !== lease && current.lease !== previous?.lease) throw ownershipConflict(id, state(), current, liveLease(current) ? "owner-alive" : "unverified", loaded ? "claim-thread" : "reserve-source", forkSource && liveLease(current));
|
|
28010
|
-
if (loaded) threads.add(id);
|
|
28011
|
-
writeLease(backend, id, { ...state(), ...previous?.retained ? { retained: previous.retained, adopting: previous.lease } : {} });
|
|
28012
|
-
for (const thread of threads) {
|
|
28013
|
-
const owner = readPrivate(leaseFile(backend, thread));
|
|
28014
|
-
if (owner?.lease === lease) writeLease(backend, thread, { ...owner, threads: [...threads] });
|
|
28015
|
-
}
|
|
28134
|
+
claimLocked(id, loaded, previous, forkSource);
|
|
28016
28135
|
} finally {
|
|
28017
28136
|
release();
|
|
28018
28137
|
}
|
|
28019
28138
|
};
|
|
28139
|
+
const reserveAbandoned = async (id, owner) => {
|
|
28140
|
+
const deadline = Date.now() + CODEX_TIMEOUT;
|
|
28141
|
+
const group = abandonedLeaseGroup(backend, id, owner);
|
|
28142
|
+
let locked = lockLeaseGroup(backend, group);
|
|
28143
|
+
while (!locked && !closing && Date.now() < deadline) {
|
|
28144
|
+
await delay2(25);
|
|
28145
|
+
locked = lockLeaseGroup(backend, group);
|
|
28146
|
+
}
|
|
28147
|
+
if (!locked) throw ownershipConflict(id, state(), owner, "ownership-transfer", "verify-source", false, "Codex ownership verification timed out.");
|
|
28148
|
+
try {
|
|
28149
|
+
if (closing || !locked.abandoned()) throw ownershipConflict(id, state(), owner, "ownership-changed", "verify-source");
|
|
28150
|
+
const problem = await verifyStoppedThreads(connection.rpc, locked.threads, deadline);
|
|
28151
|
+
if (problem) {
|
|
28152
|
+
const busy = problem.status === "active" || problem.status === "background-work";
|
|
28153
|
+
throw ownershipConflict(problem.threadId, state(), owner, busy ? "work still running; automatic replay refused" : "unverified", "verify-source", false, problem.diagnostic);
|
|
28154
|
+
}
|
|
28155
|
+
if (closing || !locked.abandoned()) throw ownershipConflict(id, state(), owner, "ownership-changed", "verify-source");
|
|
28156
|
+
claimLocked(id, false, owner);
|
|
28157
|
+
for (const thread of group.keys()) if (thread !== id) fs6.rmSync(leaseFile(backend, thread), { force: true });
|
|
28158
|
+
} finally {
|
|
28159
|
+
locked.release();
|
|
28160
|
+
}
|
|
28161
|
+
};
|
|
28020
28162
|
const reserve = async (id, forkSource) => {
|
|
28021
28163
|
const previous = leaseAt(id, "reserve-source");
|
|
28022
|
-
|
|
28023
|
-
|
|
28024
|
-
|
|
28025
|
-
|
|
28026
|
-
|
|
28027
|
-
|
|
28028
|
-
|
|
28029
|
-
|
|
28030
|
-
|
|
28031
|
-
|
|
28032
|
-
|
|
28033
|
-
|
|
28034
|
-
|
|
28035
|
-
status = await inspectThread(connection.rpc, thread);
|
|
28036
|
-
} catch {
|
|
28037
|
-
throw ownershipConflict(thread, state(), previous, "unverified", "verify-source");
|
|
28038
|
-
}
|
|
28039
|
-
if (status !== "idle" && status !== "notLoaded") throw ownershipConflict(thread, state(), previous, status === "active" || status === "background-work" ? "work still running; automatic replay refused" : "unverified", "verify-source");
|
|
28040
|
-
}
|
|
28041
|
-
}
|
|
28042
|
-
}
|
|
28043
|
-
claim(id, false, previous, forkSource);
|
|
28164
|
+
const retained = previous?.retained?.kept.length ? previous.retained : void 0;
|
|
28165
|
+
if (previous && previous.lease !== lease && retained) {
|
|
28166
|
+
if (retained.root !== id) throw Error("Resume the owning Codex thread to adopt its retained work.");
|
|
28167
|
+
if (previous.settings !== settings) throw Error("This Codex version cannot change execution settings while retaining a loaded session. Its services and saved results were preserved; no new work was submitted.");
|
|
28168
|
+
const actual = [];
|
|
28169
|
+
for (const thread of previous.threads) actual.push(...await backgroundTerminals(connection.rpc, thread));
|
|
28170
|
+
const key = (value) => JSON.stringify([value.threadId, value.itemId, value.processId]);
|
|
28171
|
+
if (actual.length !== retained.kept.length || actual.some((value) => !retained.kept.some((item) => key(item) === key(value)))) throw Error("The retained Codex services changed; no new work was submitted.");
|
|
28172
|
+
}
|
|
28173
|
+
if (previous && previous.lease !== lease && !retained) {
|
|
28174
|
+
if (liveLease(previous)) throw ownershipConflict(id, state(), previous, "owner-alive", "reserve-source", forkSource);
|
|
28175
|
+
await reserveAbandoned(id, previous);
|
|
28176
|
+
} else claim(id, false, previous, forkSource);
|
|
28044
28177
|
preparing.set(id, (preparing.get(id) ?? 0) + 1);
|
|
28045
|
-
return { previous:
|
|
28178
|
+
return { previous: retained ? previous : void 0, release() {
|
|
28046
28179
|
const remaining = preparing.get(id) - 1;
|
|
28047
28180
|
if (remaining) preparing.set(id, remaining);
|
|
28048
28181
|
else {
|
|
@@ -28058,15 +28191,11 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28058
28191
|
const notify = (message) => {
|
|
28059
28192
|
const params = obj(message.params), thread = obj(params.thread);
|
|
28060
28193
|
const id = str(params.threadId) || str(thread.id);
|
|
28061
|
-
if (message.method === "thread/closed") {
|
|
28062
|
-
unloading.get(id)?.();
|
|
28063
|
-
unloading.delete(id);
|
|
28064
|
-
}
|
|
28065
28194
|
if (!threads.has(id)) {
|
|
28066
|
-
const parent = str(thread.parentThreadId)
|
|
28195
|
+
const parent = str(thread.parentThreadId);
|
|
28067
28196
|
if (parent && threads.has(parent)) {
|
|
28068
28197
|
try {
|
|
28069
|
-
claim(id);
|
|
28198
|
+
if (owned(parent)) claim(id);
|
|
28070
28199
|
} catch (error) {
|
|
28071
28200
|
failNotification(error);
|
|
28072
28201
|
return;
|
|
@@ -28083,7 +28212,7 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28083
28212
|
const children = item.type === "subAgentActivity" && item.kind === "started" ? [item.agentThreadId] : item.type === "collabAgentToolCall" && item.tool === "spawnAgent" && Array.isArray(item.receiverThreadIds) ? item.receiverThreadIds : [];
|
|
28084
28213
|
for (const child of children) if (typeof child === "string" && !threads.has(child)) {
|
|
28085
28214
|
try {
|
|
28086
|
-
claim(child);
|
|
28215
|
+
if (owned(id)) claim(child);
|
|
28087
28216
|
} catch (error) {
|
|
28088
28217
|
failNotification(error);
|
|
28089
28218
|
return;
|
|
@@ -28101,7 +28230,7 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28101
28230
|
throw error;
|
|
28102
28231
|
}
|
|
28103
28232
|
const keep = async () => {
|
|
28104
|
-
const entry = process.env.RUNNER_DIST ?
|
|
28233
|
+
const entry = process.env.RUNNER_DIST ? path7.join(process.env.RUNNER_DIST, "codex-retained.mjs") : fileURLToPath(new URL("./codex-retained.mjs", import.meta.url));
|
|
28105
28234
|
const child = spawn(process.execPath, [entry, backendFile(backend.key), leaseFile(backend, settled.root), lease], {
|
|
28106
28235
|
cwd,
|
|
28107
28236
|
env: { ...environment, WILDCRANE_CODEX_GENERATION: backend.generation },
|
|
@@ -28132,7 +28261,7 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28132
28261
|
for (const id of requests) connection.rpc.refuse(id, "Execution disconnected.");
|
|
28133
28262
|
const results = await Promise.allSettled([...threads].map(async (id) => {
|
|
28134
28263
|
if (!owned(id)) return;
|
|
28135
|
-
await releaseNativeThread(connection, id, active.get(id), !settled
|
|
28264
|
+
await releaseNativeThread(connection, id, active.get(id), !settled);
|
|
28136
28265
|
remove(id);
|
|
28137
28266
|
}));
|
|
28138
28267
|
const failure = results.find((result) => result.status === "rejected");
|
|
@@ -28142,9 +28271,10 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28142
28271
|
try {
|
|
28143
28272
|
await cleanup();
|
|
28144
28273
|
} catch (error) {
|
|
28274
|
+
const diagnostic = codexDiagnostic(error);
|
|
28145
28275
|
for (const id of threads) if (owned(id)) writeLease(backend, id, { ...state(), uncertain: true });
|
|
28146
|
-
send({ method: "wildcrane/cleanup", params: { status: "unconfirmed", lease } });
|
|
28147
|
-
console.error(
|
|
28276
|
+
send({ method: "wildcrane/cleanup", params: { status: "unconfirmed", lease, diagnostic } });
|
|
28277
|
+
console.error(diagnostic);
|
|
28148
28278
|
} finally {
|
|
28149
28279
|
connection.close();
|
|
28150
28280
|
}
|
|
@@ -28156,16 +28286,19 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28156
28286
|
}
|
|
28157
28287
|
stoppingForRetry = true;
|
|
28158
28288
|
const otherWork = pending.size || requests.size || active.size !== 1;
|
|
28159
|
-
await
|
|
28289
|
+
await interruptNativeThread(connection, threadId, turnId, Date.now() + CODEX_TIMEOUT);
|
|
28160
28290
|
if (otherWork) throw Error("Other Codex operations were pending when the idle turn was interrupted.");
|
|
28161
28291
|
const deadline = Date.now() + CODEX_TIMEOUT;
|
|
28162
28292
|
const call = (method, input) => bounded(connection.rpc.call(method, input), deadline - Date.now(), "Codex did not confirm the idle turn stopped.");
|
|
28163
28293
|
for (; ; ) {
|
|
28164
|
-
const
|
|
28165
|
-
|
|
28166
|
-
if (
|
|
28294
|
+
const evidence = await inspectNativeThread(connection.rpc, threadId, deadline, false);
|
|
28295
|
+
const snapshot = evidence.thread;
|
|
28296
|
+
if (!snapshot || closing) throw Error(evidence.diagnostic ?? "Codex session availability could not be confirmed.");
|
|
28297
|
+
if ((evidence.status === "idle" || evidence.status === "notLoaded") && !active.has(threadId)) {
|
|
28167
28298
|
const paginated = snapshot.historyMode === "paginated";
|
|
28168
|
-
const
|
|
28299
|
+
const history = paginated ? void 0 : obj((await call("thread/read", { threadId, includeTurns: true })).thread);
|
|
28300
|
+
if (history && history.id !== threadId) throw Error("Codex returned a different session during interruption.");
|
|
28301
|
+
const listed = paginated ? (await call("thread/turns/list", { threadId, sortDirection: "desc", limit: 1, itemsView: "full" })).data : history?.turns;
|
|
28169
28302
|
const turns = Array.isArray(listed) ? listed.map(obj) : [];
|
|
28170
28303
|
const turn = turns.at(paginated ? 0 : -1);
|
|
28171
28304
|
if (turn?.id !== turnId || turn.status !== "interrupted" || !Array.isArray(turn.items)) {
|
|
@@ -28177,16 +28310,18 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28177
28310
|
break;
|
|
28178
28311
|
}
|
|
28179
28312
|
if (Date.now() >= deadline) throw Error("Codex did not confirm the idle turn stopped.");
|
|
28180
|
-
await
|
|
28313
|
+
await delay2(50);
|
|
28181
28314
|
}
|
|
28182
28315
|
const claimed = [...threads];
|
|
28183
|
-
|
|
28184
|
-
|
|
28185
|
-
|
|
28186
|
-
|
|
28187
|
-
|
|
28188
|
-
await Promise.
|
|
28189
|
-
|
|
28316
|
+
const changed = () => active.size || requests.size || threads.size !== claimed.length || claimed.some((thread) => !owned(thread)) || closing;
|
|
28317
|
+
if (changed()) throw Error("Codex ownership or pending operations changed during interruption.");
|
|
28318
|
+
const problem = await verifyStoppedThreads(connection.rpc, claimed);
|
|
28319
|
+
if (problem) throw Error([`Codex thread ${problem.threadId} has unconfirmed or unfinished work after interruption (${problem.status}).`, problem.diagnostic].filter(Boolean).join(" "));
|
|
28320
|
+
if (changed()) throw Error("Codex ownership or pending operations changed during verification.");
|
|
28321
|
+
const results = await Promise.allSettled(claimed.map((thread) => releaseNativeThread(connection, thread, void 0, false)));
|
|
28322
|
+
const failure = results.find((result) => result.status === "rejected");
|
|
28323
|
+
if (failure?.status === "rejected") throw failure.reason;
|
|
28324
|
+
if (changed()) {
|
|
28190
28325
|
throw Error("Codex ownership or pending operations changed during release.");
|
|
28191
28326
|
}
|
|
28192
28327
|
for (const thread of claimed) {
|
|
@@ -28242,7 +28377,7 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28242
28377
|
if (["thread/start", "thread/resume", "thread/fork"].includes(message.method)) {
|
|
28243
28378
|
if (message.method !== "thread/start") {
|
|
28244
28379
|
const id2 = str(params.threadId);
|
|
28245
|
-
if (message.method !== "thread/fork" || !leaseAt(id2, "reserve-source")?.retained) {
|
|
28380
|
+
if (message.method !== "thread/fork" || !leaseAt(id2, "reserve-source")?.retained?.kept.length) {
|
|
28246
28381
|
source = id2;
|
|
28247
28382
|
const reservation = await reserve(source, message.method === "thread/fork");
|
|
28248
28383
|
previous = reservation.previous;
|
|
@@ -28250,6 +28385,7 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28250
28385
|
}
|
|
28251
28386
|
}
|
|
28252
28387
|
const defaults = await connection.rpc.call("config/read", { cwd: params.cwd ?? cwd, includeLayers: false });
|
|
28388
|
+
if (closing) throw Error("Codex execution is stopping.");
|
|
28253
28389
|
const overrides = { ...config, ...obj(params.config), thread_unload_delay_secs: 0 };
|
|
28254
28390
|
mcpEnvironment(overrides, obj(obj(defaults.config).mcp_servers));
|
|
28255
28391
|
params = { ...params, cwd: params.cwd ?? cwd, config: overrides };
|
|
@@ -28281,6 +28417,7 @@ async function codexExecution(backend, config, environment, cwd, send) {
|
|
|
28281
28417
|
if (owned(thread)) writeLease(backend, thread, previous);
|
|
28282
28418
|
threads.delete(thread);
|
|
28283
28419
|
}
|
|
28420
|
+
if (message.method === "wildcrane/stopForRetry" && error instanceof RpcError) console.error(codexDiagnostic(error));
|
|
28284
28421
|
if (id !== void 0) send({ id, error: { code: error instanceof RpcError ? error.code : -32e3, message: error instanceof Error ? error.message : String(error), ...error instanceof RpcError ? { data: error.data } : {} } });
|
|
28285
28422
|
} finally {
|
|
28286
28423
|
releaseSource?.();
|
|
@@ -28305,26 +28442,26 @@ var LIST_PROCS = [
|
|
|
28305
28442
|
].join("; ");
|
|
28306
28443
|
|
|
28307
28444
|
// src/settings-control.ts
|
|
28308
|
-
import
|
|
28309
|
-
import
|
|
28310
|
-
var directory = () =>
|
|
28311
|
-
var epochFile = () =>
|
|
28445
|
+
import fs7 from "node:fs";
|
|
28446
|
+
import path8 from "node:path";
|
|
28447
|
+
var directory = () => path8.join(runnerHome(), "executors");
|
|
28448
|
+
var epochFile = () => path8.join(runnerHome(), "account-generation");
|
|
28312
28449
|
function accountGeneration() {
|
|
28313
28450
|
try {
|
|
28314
|
-
return
|
|
28451
|
+
return fs7.readFileSync(epochFile(), "utf8");
|
|
28315
28452
|
} catch {
|
|
28316
28453
|
return "";
|
|
28317
28454
|
}
|
|
28318
28455
|
}
|
|
28319
28456
|
function executorRecord() {
|
|
28320
|
-
|
|
28321
|
-
const file =
|
|
28322
|
-
|
|
28323
|
-
return () =>
|
|
28457
|
+
fs7.mkdirSync(directory(), { recursive: true, mode: 448 });
|
|
28458
|
+
const file = path8.join(directory(), `${process.pid}.json`);
|
|
28459
|
+
fs7.writeFileSync(file, "{}", { mode: 384 });
|
|
28460
|
+
return () => fs7.rmSync(file, { force: true });
|
|
28324
28461
|
}
|
|
28325
28462
|
|
|
28326
28463
|
// src/codex-server.ts
|
|
28327
|
-
var
|
|
28464
|
+
var delay3 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
28328
28465
|
async function requestCodexBackend(argv, env) {
|
|
28329
28466
|
const until = Date.now() + CODEX_TIMEOUT;
|
|
28330
28467
|
for (; ; ) {
|
|
@@ -28360,7 +28497,7 @@ async function requestCodexBackend(argv, env) {
|
|
|
28360
28497
|
}
|
|
28361
28498
|
}
|
|
28362
28499
|
if (Date.now() >= until) throw Error("No active Runner could prepare Codex. Existing work was preserved.");
|
|
28363
|
-
await
|
|
28500
|
+
await delay3(50);
|
|
28364
28501
|
}
|
|
28365
28502
|
}
|
|
28366
28503
|
|