wildcrane-runner 0.6.74 → 0.6.77
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 +615 -251
- package/dist/akb/package.json +1 -1
- package/dist/akb-proxy.mjs +1 -1
- package/dist/codex-proxy.mjs +105 -249
- package/dist/codex-service-main.mjs +184 -229
- package/dist/flow-worker-main.mjs +559 -241
- package/dist/launcher.mjs +452 -173
- package/dist/plugin.mjs +471 -192
- package/dist/runner.mjs +780 -468
- package/dist/settings.mjs +446 -167
- package/package.json +1 -1
- package/dist/akb/dist/retire-legacy.mjs +0 -5337
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// wildcrane-runner 0.6.
|
|
1
|
+
// wildcrane-runner 0.6.77 — 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;
|
|
@@ -1397,13 +1397,13 @@ var require_util = __commonJS({
|
|
|
1397
1397
|
function isFormDataLike(object) {
|
|
1398
1398
|
return object && typeof object === "object" && typeof object.append === "function" && typeof object.delete === "function" && typeof object.get === "function" && typeof object.getAll === "function" && typeof object.has === "function" && typeof object.set === "function" && object[Symbol.toStringTag] === "FormData";
|
|
1399
1399
|
}
|
|
1400
|
-
function addAbortListener(
|
|
1401
|
-
if ("addEventListener" in
|
|
1402
|
-
|
|
1403
|
-
return () =>
|
|
1400
|
+
function addAbortListener(signal, listener) {
|
|
1401
|
+
if ("addEventListener" in signal) {
|
|
1402
|
+
signal.addEventListener("abort", listener, { once: true });
|
|
1403
|
+
return () => signal.removeEventListener("abort", listener);
|
|
1404
1404
|
}
|
|
1405
|
-
|
|
1406
|
-
return () =>
|
|
1405
|
+
signal.once("abort", listener);
|
|
1406
|
+
return () => signal.removeListener("abort", listener);
|
|
1407
1407
|
}
|
|
1408
1408
|
var validTokenChars = new Uint8Array([
|
|
1409
1409
|
0,
|
|
@@ -8248,7 +8248,7 @@ var require_client_h2 = __commonJS({
|
|
|
8248
8248
|
const headersTimeout = request.headersTimeout ?? client[kHeadersTimeout];
|
|
8249
8249
|
const bodyTimeout = request.bodyTimeout ?? client[kBodyTimeout];
|
|
8250
8250
|
const session = client[kHTTP2Session];
|
|
8251
|
-
const { method, path: path17, host, upgrade, expectContinue, signal
|
|
8251
|
+
const { method, path: path17, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request;
|
|
8252
8252
|
let { body } = request;
|
|
8253
8253
|
if (upgrade != null && upgrade !== "websocket") {
|
|
8254
8254
|
util.errorRequest(client, request, new InvalidArgumentError(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
|
|
@@ -8323,7 +8323,7 @@ var require_client_h2 = __commonJS({
|
|
|
8323
8323
|
} else {
|
|
8324
8324
|
headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
|
|
8325
8325
|
}
|
|
8326
|
-
stream = session.request(headers, { endStream: false, signal
|
|
8326
|
+
stream = session.request(headers, { endStream: false, signal });
|
|
8327
8327
|
stream[kHTTP2Stream] = true;
|
|
8328
8328
|
++session[kOpenStreams];
|
|
8329
8329
|
stream.once("response", (headers2, _flags) => {
|
|
@@ -8348,7 +8348,7 @@ var require_client_h2 = __commonJS({
|
|
|
8348
8348
|
stream.setTimeout(headersTimeout);
|
|
8349
8349
|
return true;
|
|
8350
8350
|
}
|
|
8351
|
-
stream = session.request(headers, { endStream: false, signal
|
|
8351
|
+
stream = session.request(headers, { endStream: false, signal });
|
|
8352
8352
|
stream[kHTTP2Stream] = true;
|
|
8353
8353
|
++session[kOpenStreams];
|
|
8354
8354
|
stream.on("response", (headers2) => {
|
|
@@ -8412,13 +8412,13 @@ var require_client_h2 = __commonJS({
|
|
|
8412
8412
|
const shouldEndStream = method === "GET" || method === "HEAD" || body === null;
|
|
8413
8413
|
if (expectContinue) {
|
|
8414
8414
|
headers[HTTP2_HEADER_EXPECT] = "100-continue";
|
|
8415
|
-
stream = session.request(headers, { endStream: shouldEndStream, signal
|
|
8415
|
+
stream = session.request(headers, { endStream: shouldEndStream, signal });
|
|
8416
8416
|
stream[kHTTP2Stream] = true;
|
|
8417
8417
|
stream.once("continue", writeBodyH2);
|
|
8418
8418
|
} else {
|
|
8419
8419
|
stream = session.request(headers, {
|
|
8420
8420
|
endStream: shouldEndStream,
|
|
8421
|
-
signal
|
|
8421
|
+
signal
|
|
8422
8422
|
});
|
|
8423
8423
|
stream[kHTTP2Stream] = true;
|
|
8424
8424
|
writeBodyH2();
|
|
@@ -11738,13 +11738,13 @@ var require_readable = __commonJS({
|
|
|
11738
11738
|
* @returns {Promise<null>}
|
|
11739
11739
|
*/
|
|
11740
11740
|
dump(opts) {
|
|
11741
|
-
const
|
|
11742
|
-
if (
|
|
11741
|
+
const signal = opts?.signal;
|
|
11742
|
+
if (signal != null && (typeof signal !== "object" || !("aborted" in signal))) {
|
|
11743
11743
|
return Promise.reject(new InvalidArgumentError("signal must be an AbortSignal"));
|
|
11744
11744
|
}
|
|
11745
11745
|
const limit = opts?.limit && Number.isFinite(opts.limit) ? opts.limit : 128 * 1024;
|
|
11746
|
-
if (
|
|
11747
|
-
return Promise.reject(
|
|
11746
|
+
if (signal?.aborted) {
|
|
11747
|
+
return Promise.reject(signal.reason ?? new AbortError());
|
|
11748
11748
|
}
|
|
11749
11749
|
if (this._readableState.closeEmitted) {
|
|
11750
11750
|
return Promise.resolve(null);
|
|
@@ -11753,15 +11753,15 @@ var require_readable = __commonJS({
|
|
|
11753
11753
|
if (this[kContentLength] && this[kContentLength] > limit || this[kBytesRead] > limit) {
|
|
11754
11754
|
this.destroy(new AbortError());
|
|
11755
11755
|
}
|
|
11756
|
-
if (
|
|
11756
|
+
if (signal) {
|
|
11757
11757
|
const onAbort = () => {
|
|
11758
|
-
this.destroy(
|
|
11758
|
+
this.destroy(signal.reason ?? new AbortError());
|
|
11759
11759
|
};
|
|
11760
|
-
|
|
11760
|
+
signal.addEventListener("abort", onAbort);
|
|
11761
11761
|
this.on("close", function() {
|
|
11762
|
-
|
|
11763
|
-
if (
|
|
11764
|
-
reject(
|
|
11762
|
+
signal.removeEventListener("abort", onAbort);
|
|
11763
|
+
if (signal.aborted) {
|
|
11764
|
+
reject(signal.reason ?? new AbortError());
|
|
11765
11765
|
} else {
|
|
11766
11766
|
resolve(null);
|
|
11767
11767
|
}
|
|
@@ -11945,7 +11945,7 @@ var require_api_request = __commonJS({
|
|
|
11945
11945
|
if (!opts || typeof opts !== "object") {
|
|
11946
11946
|
throw new InvalidArgumentError("invalid opts");
|
|
11947
11947
|
}
|
|
11948
|
-
const { signal
|
|
11948
|
+
const { signal, method, opaque, body, onInfo, responseHeaders, highWaterMark } = opts;
|
|
11949
11949
|
try {
|
|
11950
11950
|
if (typeof callback !== "function") {
|
|
11951
11951
|
throw new InvalidArgumentError("invalid callback");
|
|
@@ -11953,7 +11953,7 @@ var require_api_request = __commonJS({
|
|
|
11953
11953
|
if (highWaterMark != null && (!Number.isFinite(highWaterMark) || highWaterMark < 0)) {
|
|
11954
11954
|
throw new InvalidArgumentError("invalid highWaterMark");
|
|
11955
11955
|
}
|
|
11956
|
-
if (
|
|
11956
|
+
if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") {
|
|
11957
11957
|
throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget");
|
|
11958
11958
|
}
|
|
11959
11959
|
if (method === "CONNECT") {
|
|
@@ -11982,11 +11982,11 @@ var require_api_request = __commonJS({
|
|
|
11982
11982
|
this.highWaterMark = highWaterMark;
|
|
11983
11983
|
this.reason = null;
|
|
11984
11984
|
this.removeAbortListener = null;
|
|
11985
|
-
if (
|
|
11986
|
-
this.reason =
|
|
11987
|
-
} else if (
|
|
11988
|
-
this.removeAbortListener = util.addAbortListener(
|
|
11989
|
-
this.reason =
|
|
11985
|
+
if (signal?.aborted) {
|
|
11986
|
+
this.reason = signal.reason ?? new RequestAbortedError();
|
|
11987
|
+
} else if (signal) {
|
|
11988
|
+
this.removeAbortListener = util.addAbortListener(signal, () => {
|
|
11989
|
+
this.reason = signal.reason ?? new RequestAbortedError();
|
|
11990
11990
|
if (this.res) {
|
|
11991
11991
|
util.destroy(this.res.on("error", noop), this.reason);
|
|
11992
11992
|
} else if (this.abort) {
|
|
@@ -12123,18 +12123,18 @@ var require_abort_signal = __commonJS({
|
|
|
12123
12123
|
}
|
|
12124
12124
|
removeSignal(self);
|
|
12125
12125
|
}
|
|
12126
|
-
function addSignal(self,
|
|
12126
|
+
function addSignal(self, signal) {
|
|
12127
12127
|
self.reason = null;
|
|
12128
12128
|
self[kSignal] = null;
|
|
12129
12129
|
self[kListener] = null;
|
|
12130
|
-
if (!
|
|
12130
|
+
if (!signal) {
|
|
12131
12131
|
return;
|
|
12132
12132
|
}
|
|
12133
|
-
if (
|
|
12133
|
+
if (signal.aborted) {
|
|
12134
12134
|
abort(self);
|
|
12135
12135
|
return;
|
|
12136
12136
|
}
|
|
12137
|
-
self[kSignal] =
|
|
12137
|
+
self[kSignal] = signal;
|
|
12138
12138
|
self[kListener] = () => {
|
|
12139
12139
|
abort(self);
|
|
12140
12140
|
};
|
|
@@ -12176,7 +12176,7 @@ var require_api_stream = __commonJS({
|
|
|
12176
12176
|
if (!opts || typeof opts !== "object") {
|
|
12177
12177
|
throw new InvalidArgumentError("invalid opts");
|
|
12178
12178
|
}
|
|
12179
|
-
const { signal
|
|
12179
|
+
const { signal, method, opaque, body, onInfo, responseHeaders } = opts;
|
|
12180
12180
|
try {
|
|
12181
12181
|
if (typeof callback !== "function") {
|
|
12182
12182
|
throw new InvalidArgumentError("invalid callback");
|
|
@@ -12184,7 +12184,7 @@ var require_api_stream = __commonJS({
|
|
|
12184
12184
|
if (typeof factory !== "function") {
|
|
12185
12185
|
throw new InvalidArgumentError("invalid factory");
|
|
12186
12186
|
}
|
|
12187
|
-
if (
|
|
12187
|
+
if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") {
|
|
12188
12188
|
throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget");
|
|
12189
12189
|
}
|
|
12190
12190
|
if (method === "CONNECT") {
|
|
@@ -12215,7 +12215,7 @@ var require_api_stream = __commonJS({
|
|
|
12215
12215
|
this.onError(err);
|
|
12216
12216
|
});
|
|
12217
12217
|
}
|
|
12218
|
-
addSignal(this,
|
|
12218
|
+
addSignal(this, signal);
|
|
12219
12219
|
}
|
|
12220
12220
|
onConnect(abort, context) {
|
|
12221
12221
|
if (this.reason) {
|
|
@@ -12381,8 +12381,8 @@ var require_api_pipeline = __commonJS({
|
|
|
12381
12381
|
if (typeof handler !== "function") {
|
|
12382
12382
|
throw new InvalidArgumentError("invalid handler");
|
|
12383
12383
|
}
|
|
12384
|
-
const { signal
|
|
12385
|
-
if (
|
|
12384
|
+
const { signal, method, opaque, onInfo, responseHeaders } = opts;
|
|
12385
|
+
if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") {
|
|
12386
12386
|
throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget");
|
|
12387
12387
|
}
|
|
12388
12388
|
if (method === "CONNECT") {
|
|
@@ -12435,7 +12435,7 @@ var require_api_pipeline = __commonJS({
|
|
|
12435
12435
|
req.push(null);
|
|
12436
12436
|
});
|
|
12437
12437
|
this.res = null;
|
|
12438
|
-
addSignal(this,
|
|
12438
|
+
addSignal(this, signal);
|
|
12439
12439
|
}
|
|
12440
12440
|
onConnect(abort, context) {
|
|
12441
12441
|
const { res } = this;
|
|
@@ -12539,8 +12539,8 @@ var require_api_upgrade = __commonJS({
|
|
|
12539
12539
|
if (typeof callback !== "function") {
|
|
12540
12540
|
throw new InvalidArgumentError("invalid callback");
|
|
12541
12541
|
}
|
|
12542
|
-
const { signal
|
|
12543
|
-
if (
|
|
12542
|
+
const { signal, opaque, responseHeaders } = opts;
|
|
12543
|
+
if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") {
|
|
12544
12544
|
throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget");
|
|
12545
12545
|
}
|
|
12546
12546
|
super("UNDICI_UPGRADE");
|
|
@@ -12549,7 +12549,7 @@ var require_api_upgrade = __commonJS({
|
|
|
12549
12549
|
this.callback = callback;
|
|
12550
12550
|
this.abort = null;
|
|
12551
12551
|
this.context = null;
|
|
12552
|
-
addSignal(this,
|
|
12552
|
+
addSignal(this, signal);
|
|
12553
12553
|
}
|
|
12554
12554
|
onConnect(abort, context) {
|
|
12555
12555
|
if (this.reason) {
|
|
@@ -12632,8 +12632,8 @@ var require_api_connect = __commonJS({
|
|
|
12632
12632
|
if (typeof callback !== "function") {
|
|
12633
12633
|
throw new InvalidArgumentError("invalid callback");
|
|
12634
12634
|
}
|
|
12635
|
-
const { signal
|
|
12636
|
-
if (
|
|
12635
|
+
const { signal, opaque, responseHeaders } = opts;
|
|
12636
|
+
if (signal && typeof signal.on !== "function" && typeof signal.addEventListener !== "function") {
|
|
12637
12637
|
throw new InvalidArgumentError("signal must be an EventEmitter or EventTarget");
|
|
12638
12638
|
}
|
|
12639
12639
|
super("UNDICI_CONNECT");
|
|
@@ -12641,7 +12641,7 @@ var require_api_connect = __commonJS({
|
|
|
12641
12641
|
this.responseHeaders = responseHeaders || null;
|
|
12642
12642
|
this.callback = callback;
|
|
12643
12643
|
this.abort = null;
|
|
12644
|
-
addSignal(this,
|
|
12644
|
+
addSignal(this, signal);
|
|
12645
12645
|
}
|
|
12646
12646
|
onConnect(abort, context) {
|
|
12647
12647
|
if (this.reason) {
|
|
@@ -15045,7 +15045,7 @@ var require_dump = __commonJS({
|
|
|
15045
15045
|
#size = 0;
|
|
15046
15046
|
aborted = false;
|
|
15047
15047
|
reason = false;
|
|
15048
|
-
constructor({ maxSize, signal
|
|
15048
|
+
constructor({ maxSize, signal }, handler) {
|
|
15049
15049
|
if (maxSize != null && (!Number.isFinite(maxSize) || maxSize < 1)) {
|
|
15050
15050
|
throw new InvalidArgumentError("maxSize must be a number greater than 0");
|
|
15051
15051
|
}
|
|
@@ -20348,8 +20348,8 @@ var require_request2 = __commonJS({
|
|
|
20348
20348
|
var assert = __require("node:assert");
|
|
20349
20349
|
var { getMaxListeners, setMaxListeners, defaultMaxListeners } = __require("node:events");
|
|
20350
20350
|
var kAbortController = /* @__PURE__ */ Symbol("abortController");
|
|
20351
|
-
var requestFinalizer = new FinalizationRegistry(({ signal
|
|
20352
|
-
|
|
20351
|
+
var requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
|
|
20352
|
+
signal.removeEventListener("abort", abort);
|
|
20353
20353
|
});
|
|
20354
20354
|
var dependentControllerMap = /* @__PURE__ */ new WeakMap();
|
|
20355
20355
|
var abortSignalHasEventHandlerLeakWarning;
|
|
@@ -20404,7 +20404,7 @@ var require_request2 = __commonJS({
|
|
|
20404
20404
|
let request = null;
|
|
20405
20405
|
let fallbackMode = null;
|
|
20406
20406
|
const baseUrl = environmentSettingsObject.settingsObject.baseUrl;
|
|
20407
|
-
let
|
|
20407
|
+
let signal = null;
|
|
20408
20408
|
if (typeof input === "string") {
|
|
20409
20409
|
this.#dispatcher = init.dispatcher;
|
|
20410
20410
|
let parsedURL;
|
|
@@ -20423,7 +20423,7 @@ var require_request2 = __commonJS({
|
|
|
20423
20423
|
} else {
|
|
20424
20424
|
assert(webidl.is.Request(input));
|
|
20425
20425
|
request = input.#state;
|
|
20426
|
-
|
|
20426
|
+
signal = input.#signal;
|
|
20427
20427
|
this.#dispatcher = init.dispatcher || input.#dispatcher;
|
|
20428
20428
|
}
|
|
20429
20429
|
const origin = environmentSettingsObject.settingsObject.origin;
|
|
@@ -20573,23 +20573,23 @@ var require_request2 = __commonJS({
|
|
|
20573
20573
|
}
|
|
20574
20574
|
}
|
|
20575
20575
|
if (init.signal !== void 0) {
|
|
20576
|
-
|
|
20576
|
+
signal = init.signal;
|
|
20577
20577
|
}
|
|
20578
20578
|
this.#state = request;
|
|
20579
20579
|
const ac = new AbortController();
|
|
20580
20580
|
this.#signal = ac.signal;
|
|
20581
|
-
if (
|
|
20582
|
-
if (
|
|
20583
|
-
ac.abort(
|
|
20581
|
+
if (signal != null) {
|
|
20582
|
+
if (signal.aborted) {
|
|
20583
|
+
ac.abort(signal.reason);
|
|
20584
20584
|
} else {
|
|
20585
20585
|
this[kAbortController] = ac;
|
|
20586
20586
|
const acRef = new WeakRef(ac);
|
|
20587
20587
|
const abort = buildAbort(acRef);
|
|
20588
|
-
if (abortSignalHasEventHandlerLeakWarning && getMaxListeners(
|
|
20589
|
-
setMaxListeners(1500,
|
|
20588
|
+
if (abortSignalHasEventHandlerLeakWarning && getMaxListeners(signal) === defaultMaxListeners) {
|
|
20589
|
+
setMaxListeners(1500, signal);
|
|
20590
20590
|
}
|
|
20591
|
-
util.addAbortListener(
|
|
20592
|
-
requestFinalizer.register(ac, { signal
|
|
20591
|
+
util.addAbortListener(signal, abort);
|
|
20592
|
+
requestFinalizer.register(ac, { signal, abort }, abort);
|
|
20593
20593
|
}
|
|
20594
20594
|
}
|
|
20595
20595
|
this.#headers = new Headers(kConstruct);
|
|
@@ -20928,11 +20928,11 @@ var require_request2 = __commonJS({
|
|
|
20928
20928
|
}
|
|
20929
20929
|
return newRequest;
|
|
20930
20930
|
}
|
|
20931
|
-
function fromInnerRequest(innerRequest, dispatcher,
|
|
20931
|
+
function fromInnerRequest(innerRequest, dispatcher, signal, guard) {
|
|
20932
20932
|
const request = new Request(kConstruct);
|
|
20933
20933
|
setRequestState(request, innerRequest);
|
|
20934
20934
|
setRequestDispatcher(request, dispatcher);
|
|
20935
|
-
setRequestSignal(request,
|
|
20935
|
+
setRequestSignal(request, signal);
|
|
20936
20936
|
const headers = new Headers(kConstruct);
|
|
20937
20937
|
setRequestHeaders(request, headers);
|
|
20938
20938
|
setHeadersList(headers, innerRequest.headersList);
|
|
@@ -21035,8 +21035,8 @@ var require_request2 = __commonJS({
|
|
|
21035
21035
|
{
|
|
21036
21036
|
key: "signal",
|
|
21037
21037
|
converter: webidl.nullableConverter(
|
|
21038
|
-
(
|
|
21039
|
-
|
|
21038
|
+
(signal) => webidl.converters.AbortSignal(
|
|
21039
|
+
signal,
|
|
21040
21040
|
"RequestInit",
|
|
21041
21041
|
"signal"
|
|
21042
21042
|
)
|
|
@@ -25511,18 +25511,18 @@ var require_websocketstream = __commonJS({
|
|
|
25511
25511
|
this.#openedPromise = createDeferredPromise();
|
|
25512
25512
|
this.#closedPromise = createDeferredPromise();
|
|
25513
25513
|
if (options.signal != null) {
|
|
25514
|
-
const
|
|
25515
|
-
if (
|
|
25516
|
-
this.#openedPromise.reject(
|
|
25517
|
-
this.#closedPromise.reject(
|
|
25514
|
+
const signal = options.signal;
|
|
25515
|
+
if (signal.aborted) {
|
|
25516
|
+
this.#openedPromise.reject(signal.reason);
|
|
25517
|
+
this.#closedPromise.reject(signal.reason);
|
|
25518
25518
|
return;
|
|
25519
25519
|
}
|
|
25520
|
-
|
|
25520
|
+
signal.addEventListener("abort", () => {
|
|
25521
25521
|
if (!isEstablished(this.#handler.readyState)) {
|
|
25522
25522
|
failWebsocketConnection(this.#handler);
|
|
25523
25523
|
this.#handler.readyState = states.CLOSING;
|
|
25524
|
-
this.#openedPromise.reject(
|
|
25525
|
-
this.#closedPromise.reject(
|
|
25524
|
+
this.#openedPromise.reject(signal.reason);
|
|
25525
|
+
this.#closedPromise.reject(signal.reason);
|
|
25526
25526
|
this.#handshakeAborted = true;
|
|
25527
25527
|
}
|
|
25528
25528
|
}, { once: true });
|
|
@@ -28593,7 +28593,7 @@ function hold(dir) {
|
|
|
28593
28593
|
var import_smol_toml = __toESM(require_dist(), 1);
|
|
28594
28594
|
import { spawn } from "node:child_process";
|
|
28595
28595
|
import crypto3 from "node:crypto";
|
|
28596
|
-
import
|
|
28596
|
+
import fs13 from "node:fs";
|
|
28597
28597
|
import net from "node:net";
|
|
28598
28598
|
import path15 from "node:path";
|
|
28599
28599
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -28668,9 +28668,7 @@ function spawnable(command, args, options = {}, platform = process.platform) {
|
|
|
28668
28668
|
}
|
|
28669
28669
|
|
|
28670
28670
|
// ../cli/src/lib/agent/stop.ts
|
|
28671
|
-
import { spawnSync } from "node:child_process";
|
|
28672
28671
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
28673
|
-
import fs13 from "node:fs";
|
|
28674
28672
|
|
|
28675
28673
|
// ../cli/src/lib/agent/env.ts
|
|
28676
28674
|
var STOP_ENV = "KANBAN_STOP_ID";
|
|
@@ -28679,133 +28677,11 @@ var STOP_ENV = "KANBAN_STOP_ID";
|
|
|
28679
28677
|
var stopMark = () => ({ name: STOP_ENV, value: randomUUID2(), since: Date.now() });
|
|
28680
28678
|
var markEnv = (env, mark) => ({ ...env, [mark.name]: mark.value });
|
|
28681
28679
|
var WINDOWS = process.platform === "win32";
|
|
28682
|
-
function markedInProc(entry, strict = false, since) {
|
|
28683
|
-
const pids = [];
|
|
28684
|
-
for (const name of fs13.readdirSync("/proc")) {
|
|
28685
|
-
if (!/^\d+$/.test(name)) continue;
|
|
28686
|
-
try {
|
|
28687
|
-
if (fs13.readFileSync(`/proc/${name}/environ`, "utf8").split("\0").includes(entry)) pids.push(Number(name));
|
|
28688
|
-
} catch (error) {
|
|
28689
|
-
if (strict && !["ENOENT", "ESRCH"].includes(error.code ?? "")) {
|
|
28690
|
-
const stat = fs13.statSync(`/proc/${name}`, { throwIfNoEntry: false });
|
|
28691
|
-
if (stat?.uid === process.getuid?.() && !startedBefore(Number(name), since)) throw error;
|
|
28692
|
-
}
|
|
28693
|
-
}
|
|
28694
|
-
}
|
|
28695
|
-
return pids;
|
|
28696
|
-
}
|
|
28697
|
-
function startedBefore(pid, since) {
|
|
28698
|
-
if (since === void 0) return false;
|
|
28699
|
-
const result = spawnSync("ps", ["-p", String(pid), "-o", "lstart="], {
|
|
28700
|
-
encoding: "utf8",
|
|
28701
|
-
timeout: 5e3,
|
|
28702
|
-
env: { ...process.env, LC_ALL: "C" }
|
|
28703
|
-
});
|
|
28704
|
-
const birth = Date.parse(result.stdout?.trim() ?? "");
|
|
28705
|
-
return result.status === 0 && Number.isFinite(birth) && birth + 2e3 <= since;
|
|
28706
|
-
}
|
|
28707
|
-
function markedInPs(entry, roots) {
|
|
28708
|
-
const ps = spawnSync("ps", ["-A", "-E", "-ww", "-o", "pid=,ppid=,command="], {
|
|
28709
|
-
encoding: "utf8",
|
|
28710
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
28711
|
-
timeout: 5e3
|
|
28712
|
-
});
|
|
28713
|
-
if (ps.status !== 0 || !ps.stdout) throw new Error("\u65E0\u6CD5\u67E5\u8BE2\u8FDB\u7A0B\u6811\u3002");
|
|
28714
|
-
const children = /* @__PURE__ */ new Map();
|
|
28715
|
-
const listed = /* @__PURE__ */ new Set();
|
|
28716
|
-
const found = /* @__PURE__ */ new Set();
|
|
28717
|
-
for (const line of ps.stdout.split("\n")) {
|
|
28718
|
-
const m = /^\s*(\d+)\s+(\d+)\s(.*)$/.exec(line);
|
|
28719
|
-
if (!m) continue;
|
|
28720
|
-
const pid = Number(m[1]);
|
|
28721
|
-
const ppid = Number(m[2]);
|
|
28722
|
-
listed.add(pid);
|
|
28723
|
-
children.set(ppid, [...children.get(ppid) ?? [], pid]);
|
|
28724
|
-
if (`${m[3]} `.includes(` ${entry} `)) found.add(pid);
|
|
28725
|
-
}
|
|
28726
|
-
const queue = [...found, ...roots.filter((pid) => listed.has(pid))];
|
|
28727
|
-
for (const pid of queue) {
|
|
28728
|
-
found.add(pid);
|
|
28729
|
-
for (const child of children.get(pid) ?? []) if (!found.has(child)) queue.push(child);
|
|
28730
|
-
}
|
|
28731
|
-
return [...found];
|
|
28732
|
-
}
|
|
28733
|
-
function marked(mark, roots = []) {
|
|
28734
|
-
if (WINDOWS || !mark.value) return [];
|
|
28735
|
-
const entry = `${mark.name}=${mark.value}`;
|
|
28736
|
-
try {
|
|
28737
|
-
const pids = process.platform === "linux" ? markedInProc(entry) : markedInPs(entry, roots);
|
|
28738
|
-
return pids.filter((pid) => pid !== process.pid);
|
|
28739
|
-
} catch {
|
|
28740
|
-
return [];
|
|
28741
|
-
}
|
|
28742
|
-
}
|
|
28743
|
-
function signal(pids, sig) {
|
|
28744
|
-
for (const pid of pids) {
|
|
28745
|
-
try {
|
|
28746
|
-
process.kill(pid, sig);
|
|
28747
|
-
} catch {
|
|
28748
|
-
}
|
|
28749
|
-
}
|
|
28750
|
-
}
|
|
28751
|
-
function startedUnder(list, root2, since) {
|
|
28752
|
-
const self = list.procs.find((p) => p.pid === root2);
|
|
28753
|
-
const from = since ?? self?.startedAt;
|
|
28754
|
-
if (from === void 0 || list.bootedAt > from) return [];
|
|
28755
|
-
if (self && self.startedAt > from) return [];
|
|
28756
|
-
const found = self ? [root2] : [];
|
|
28757
|
-
const seen = /* @__PURE__ */ new Set([root2]);
|
|
28758
|
-
const queue = [{ pid: root2, startedAt: from }];
|
|
28759
|
-
for (const parent of queue) {
|
|
28760
|
-
for (const p of list.procs) {
|
|
28761
|
-
if (p.ppid !== parent.pid || seen.has(p.pid) || p.startedAt < parent.startedAt) continue;
|
|
28762
|
-
seen.add(p.pid);
|
|
28763
|
-
found.push(p.pid);
|
|
28764
|
-
queue.push(p);
|
|
28765
|
-
}
|
|
28766
|
-
}
|
|
28767
|
-
return found.reverse();
|
|
28768
|
-
}
|
|
28769
28680
|
var LIST_PROCS = [
|
|
28770
28681
|
"$ErrorActionPreference = 'Stop'",
|
|
28771
28682
|
"Get-CimInstance Win32_Process | ForEach-Object { if ($_.CreationDate) { '{0} {1} {2}' -f $_.ProcessId, $_.ParentProcessId, ([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds() } }",
|
|
28772
28683
|
"'boot {0}' -f ([DateTimeOffset](Get-CimInstance Win32_OperatingSystem).LastBootUpTime).ToUnixTimeMilliseconds()"
|
|
28773
28684
|
].join("; ");
|
|
28774
|
-
function readProcList(out) {
|
|
28775
|
-
const procs = [];
|
|
28776
|
-
let bootedAt;
|
|
28777
|
-
for (const line of out.split(/\r?\n/)) {
|
|
28778
|
-
const boot = /^boot (\d+)$/.exec(line.trim());
|
|
28779
|
-
if (boot) bootedAt = Number(boot[1]);
|
|
28780
|
-
const m = /^(\d+) (\d+) (\d+)$/.exec(line.trim());
|
|
28781
|
-
if (m) procs.push({ pid: Number(m[1]), ppid: Number(m[2]), startedAt: Number(m[3]) });
|
|
28782
|
-
}
|
|
28783
|
-
return bootedAt !== void 0 && procs.length ? { procs, bootedAt } : void 0;
|
|
28784
|
-
}
|
|
28785
|
-
function procsOnWindows() {
|
|
28786
|
-
const ps = spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", LIST_PROCS], {
|
|
28787
|
-
encoding: "utf8",
|
|
28788
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
28789
|
-
timeout: 5e3,
|
|
28790
|
-
windowsHide: true
|
|
28791
|
-
});
|
|
28792
|
-
return ps.status === 0 && ps.stdout ? readProcList(ps.stdout) : void 0;
|
|
28793
|
-
}
|
|
28794
|
-
function killUnderOnWindows(pid, since) {
|
|
28795
|
-
if (!WINDOWS || !pid) return;
|
|
28796
|
-
const list = procsOnWindows();
|
|
28797
|
-
if (!list) return;
|
|
28798
|
-
const pids = startedUnder(list, pid, since).filter((p) => p !== process.pid);
|
|
28799
|
-
if (!pids.length) return;
|
|
28800
|
-
spawnSync("taskkill", ["/F", ...pids.flatMap((p) => ["/PID", String(p)])], { stdio: "ignore", windowsHide: true, timeout: 1e4 });
|
|
28801
|
-
}
|
|
28802
|
-
function killMarked(mark, agent) {
|
|
28803
|
-
if (WINDOWS) {
|
|
28804
|
-
if (agent) killUnderOnWindows(agent.pid, agent.since);
|
|
28805
|
-
return;
|
|
28806
|
-
}
|
|
28807
|
-
signal(marked(mark), "SIGKILL");
|
|
28808
|
-
}
|
|
28809
28685
|
|
|
28810
28686
|
// ../cli/src/lib/agent/wire/json.ts
|
|
28811
28687
|
function obj(value) {
|
|
@@ -28899,8 +28775,8 @@ function connect(stdout, stdin, onCall, dialect = {}) {
|
|
|
28899
28775
|
|
|
28900
28776
|
// src/codex-service.ts
|
|
28901
28777
|
var TIMEOUT = 1e4;
|
|
28902
|
-
var CODEX_PROTOCOL =
|
|
28903
|
-
var codexRecordFile = () => path15.join(runnerCwd(), "codex-service.json");
|
|
28778
|
+
var CODEX_PROTOCOL = 2;
|
|
28779
|
+
var codexRecordFile = () => path15.join(runnerCwd(), "codex-service-v2.json");
|
|
28904
28780
|
async function serveCodex() {
|
|
28905
28781
|
const token = crypto3.randomBytes(32).toString("hex");
|
|
28906
28782
|
const home = runnerCwd();
|
|
@@ -28909,8 +28785,8 @@ async function serveCodex() {
|
|
|
28909
28785
|
const record = codexRecordFile();
|
|
28910
28786
|
const publish = () => {
|
|
28911
28787
|
const temporary = `${record}.${identity.instance}.tmp`;
|
|
28912
|
-
|
|
28913
|
-
|
|
28788
|
+
fs13.writeFileSync(temporary, JSON.stringify(identity), { mode: 384 });
|
|
28789
|
+
fs13.renameSync(temporary, record);
|
|
28914
28790
|
};
|
|
28915
28791
|
const sockets = /* @__PURE__ */ new Set();
|
|
28916
28792
|
const controls = /* @__PURE__ */ new Set();
|
|
@@ -28929,7 +28805,7 @@ async function serveCodex() {
|
|
|
28929
28805
|
try {
|
|
28930
28806
|
const msg = JSON.parse(line);
|
|
28931
28807
|
if (controls.has(socket)) {
|
|
28932
|
-
if (msg.method === "shutdown" && sockets.size === controls.size) void close();
|
|
28808
|
+
if (msg.method === "shutdown" && sockets.size === controls.size && ![...services.values()].some((s) => s.held())) void close();
|
|
28933
28809
|
} else if (!peer) {
|
|
28934
28810
|
if (closing || msg.token !== token) return socket.destroy();
|
|
28935
28811
|
clearTimeout(authTimer);
|
|
@@ -28952,7 +28828,7 @@ async function serveCodex() {
|
|
|
28952
28828
|
});
|
|
28953
28829
|
services.set(key, service);
|
|
28954
28830
|
}
|
|
28955
|
-
peer = { socket, cwd: str2(msg.cwd), config, service, threads: /* @__PURE__ */ new Set(), pending: /* @__PURE__ */ new Set() };
|
|
28831
|
+
peer = { socket, cwd: str2(msg.cwd), config, service, threads: /* @__PURE__ */ new Set(), pending: /* @__PURE__ */ new Set(), lease: crypto3.randomUUID() };
|
|
28956
28832
|
service.peers.add(peer);
|
|
28957
28833
|
} else {
|
|
28958
28834
|
const p = peer;
|
|
@@ -28976,7 +28852,7 @@ async function serveCodex() {
|
|
|
28976
28852
|
server.once("error", reject);
|
|
28977
28853
|
server.listen(address, resolve);
|
|
28978
28854
|
});
|
|
28979
|
-
if (process.platform !== "win32")
|
|
28855
|
+
if (process.platform !== "win32") fs13.chmodSync(address, 384);
|
|
28980
28856
|
publish();
|
|
28981
28857
|
let closingWork;
|
|
28982
28858
|
let finished;
|
|
@@ -28988,9 +28864,9 @@ async function serveCodex() {
|
|
|
28988
28864
|
server.close();
|
|
28989
28865
|
await Promise.all([...services.values()].map((service) => service.close()));
|
|
28990
28866
|
for (const socket of sockets) socket.destroy();
|
|
28991
|
-
if (process.platform !== "win32")
|
|
28867
|
+
if (process.platform !== "win32") fs13.rmSync(address, { force: true });
|
|
28992
28868
|
try {
|
|
28993
|
-
if (JSON.parse(
|
|
28869
|
+
if (JSON.parse(fs13.readFileSync(record, "utf8")).instance === identity.instance) fs13.rmSync(record, { force: true });
|
|
28994
28870
|
} catch {
|
|
28995
28871
|
}
|
|
28996
28872
|
finished();
|
|
@@ -28999,7 +28875,7 @@ async function serveCodex() {
|
|
|
28999
28875
|
env: { WILDCRANE_CODEX_SERVER: record, WILDCRANE_CODEX_GENERATION: identity.generation, WILDCRANE_CODEX_PROXY: fileURLToPath2(new URL("./codex-proxy.mjs", import.meta.url)) },
|
|
29000
28876
|
close,
|
|
29001
28877
|
closed,
|
|
29002
|
-
idle: () => sockets.size === 0
|
|
28878
|
+
idle: () => sockets.size === 0 && ![...services.values()].some((s) => s.held())
|
|
29003
28879
|
};
|
|
29004
28880
|
}
|
|
29005
28881
|
function providerServer(command, provider, environment, home, remember) {
|
|
@@ -29008,6 +28884,9 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29008
28884
|
const active = /* @__PURE__ */ new Map();
|
|
29009
28885
|
const requests = /* @__PURE__ */ new Map();
|
|
29010
28886
|
const unloading = /* @__PURE__ */ new Map();
|
|
28887
|
+
const retained = /* @__PURE__ */ new Map();
|
|
28888
|
+
const quarantined = /* @__PURE__ */ new Set();
|
|
28889
|
+
let backend = "";
|
|
29011
28890
|
let child;
|
|
29012
28891
|
let rpc;
|
|
29013
28892
|
let initializing;
|
|
@@ -29029,12 +28908,12 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29029
28908
|
const env = { ...process.env, OPENAI_API_KEY: void 0, CODEX_HOME: environment.CODEX_HOME ?? process.env.CODEX_HOME, WILDCRANE_JOB: "1" };
|
|
29030
28909
|
for (const key of Object.keys(env)) if (/^(KANBAN_|AI4KANBAN_EXECUTION|WILDCRANE_FLOW_WORKER|WILDCRANE_CODEX_)/.test(key)) delete env[key];
|
|
29031
28910
|
Object.assign(env, providerCredentials(provider, environment));
|
|
28911
|
+
backend = crypto3.randomUUID();
|
|
29032
28912
|
const mark = stopMark();
|
|
29033
28913
|
const start = spawnable(command, ["app-server", "-c", "thread_unload_delay_secs=0", ...Object.entries(provider).flatMap(([key, value]) => ["-c", `${key}=${tomlValue(value)}`])], { cwd: home, env: markEnv(env, mark), detached: process.platform !== "win32", stdio: ["pipe", "pipe", "pipe"] });
|
|
29034
28914
|
const current2 = child = spawn(start.command, start.args, start.options);
|
|
29035
28915
|
const processAt = Date.now();
|
|
29036
28916
|
const stop = () => {
|
|
29037
|
-
if (current2.pid) killMarked(mark, { pid: current2.pid, since: processAt });
|
|
29038
28917
|
current2.kill("SIGKILL");
|
|
29039
28918
|
};
|
|
29040
28919
|
stopChild = stop;
|
|
@@ -29049,6 +28928,8 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29049
28928
|
rpc = void 0;
|
|
29050
28929
|
initializing = void 0;
|
|
29051
28930
|
for (const p of peers) p.socket.destroy();
|
|
28931
|
+
retained.clear();
|
|
28932
|
+
quarantined.clear();
|
|
29052
28933
|
owners.clear();
|
|
29053
28934
|
active.clear();
|
|
29054
28935
|
requests.clear();
|
|
@@ -29074,6 +28955,18 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29074
28955
|
}
|
|
29075
28956
|
if (msg.method === "turn/started") active.set(id, str2(obj(params.turn).id));
|
|
29076
28957
|
if (msg.method === "turn/completed") active.delete(id);
|
|
28958
|
+
if (msg.method === "item/completed" && obj(params.item).type === "commandExecution") {
|
|
28959
|
+
for (const [root2, group] of retained) {
|
|
28960
|
+
group.kept = group.kept.filter((t) => t.threadId !== id || t.itemId !== obj(params.item).id);
|
|
28961
|
+
if (group.kept.length) continue;
|
|
28962
|
+
retained.delete(root2);
|
|
28963
|
+
const p = group.peer;
|
|
28964
|
+
p.settled = { root: root2, execution: group.execution, kept: [] };
|
|
28965
|
+
p.closing = void 0;
|
|
28966
|
+
for (const thread2 of group.threads) claim(p, thread2);
|
|
28967
|
+
void release2(p);
|
|
28968
|
+
}
|
|
28969
|
+
}
|
|
29077
28970
|
let owner = owners.get(id);
|
|
29078
28971
|
if (!owner) {
|
|
29079
28972
|
const parent = str2(thread.parentThreadId) || str2(thread.forkedFromId);
|
|
@@ -29082,8 +28975,9 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29082
28975
|
}
|
|
29083
28976
|
if (owner) {
|
|
29084
28977
|
const item = obj(params.item);
|
|
29085
|
-
if (item.type === "
|
|
29086
|
-
|
|
28978
|
+
if (item.type === "subAgentActivity" && item.kind === "started" && str2(item.agentThreadId) && !owners.has(str2(item.agentThreadId))) claim(owner, str2(item.agentThreadId));
|
|
28979
|
+
if (item.type === "collabAgentToolCall" && item.tool === "spawnAgent") {
|
|
28980
|
+
for (const id2 of Array.isArray(item.receiverThreadIds) ? item.receiverThreadIds : []) {
|
|
29087
28981
|
if (typeof id2 === "string" && !owners.has(id2)) claim(owner, id2);
|
|
29088
28982
|
}
|
|
29089
28983
|
}
|
|
@@ -29100,33 +28994,62 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29100
28994
|
});
|
|
29101
28995
|
return initializing;
|
|
29102
28996
|
};
|
|
28997
|
+
const terminals = async (wire, threadId) => {
|
|
28998
|
+
const result = [];
|
|
28999
|
+
const seen = /* @__PURE__ */ new Set();
|
|
29000
|
+
let cursor = null;
|
|
29001
|
+
do {
|
|
29002
|
+
if (seen.has(cursor)) throw Error("Codex repeated a terminal cursor.");
|
|
29003
|
+
seen.add(cursor);
|
|
29004
|
+
const page = await wire.call("thread/backgroundTerminals/list", { threadId, ...cursor ? { cursor } : {} });
|
|
29005
|
+
for (const value of Array.isArray(page.data) ? page.data : []) result.push({ ...obj(value), threadId });
|
|
29006
|
+
cursor = page.nextCursor;
|
|
29007
|
+
} while (cursor);
|
|
29008
|
+
return result;
|
|
29009
|
+
};
|
|
29103
29010
|
const release2 = (p) => {
|
|
29104
29011
|
if (p.closing) return p.closing;
|
|
29105
|
-
|
|
29106
|
-
await
|
|
29107
|
-
});
|
|
29012
|
+
const cleanup = async () => {
|
|
29013
|
+
await Promise.allSettled(p.pending);
|
|
29108
29014
|
const wire = p.wire;
|
|
29109
29015
|
if (wire) {
|
|
29110
29016
|
for (const [id, owner] of requests) if (owner === p) {
|
|
29111
29017
|
wire.refuse(id, "Run disconnected.");
|
|
29112
29018
|
requests.delete(id);
|
|
29113
29019
|
}
|
|
29114
|
-
|
|
29115
|
-
|
|
29116
|
-
|
|
29117
|
-
|
|
29118
|
-
|
|
29119
|
-
|
|
29120
|
-
|
|
29121
|
-
|
|
29122
|
-
|
|
29123
|
-
|
|
29124
|
-
|
|
29125
|
-
|
|
29126
|
-
|
|
29127
|
-
|
|
29020
|
+
if (p.settled?.kept.length && !closing) {
|
|
29021
|
+
retained.set(p.settled.root, { threads: new Set(p.threads), kept: p.settled.kept, execution: p.settled.execution, peer: p, settings: JSON.stringify([p.cwd, p.config]) });
|
|
29022
|
+
} else {
|
|
29023
|
+
for (const threadId of p.threads) {
|
|
29024
|
+
if (owners.get(threadId) !== p || wire !== rpc) continue;
|
|
29025
|
+
if (!p.settled) {
|
|
29026
|
+
const turnId = active.get(threadId);
|
|
29027
|
+
if (turnId) await wire.call("turn/interrupt", { threadId, turnId });
|
|
29028
|
+
try {
|
|
29029
|
+
await wire.call("thread/backgroundTerminals/clean", { threadId });
|
|
29030
|
+
} catch (e) {
|
|
29031
|
+
if (!(e instanceof RpcError) || e.code !== -32601) throw e;
|
|
29032
|
+
}
|
|
29033
|
+
}
|
|
29034
|
+
const unloaded = new Promise((resolve) => unloading.set(threadId, resolve));
|
|
29035
|
+
const result = obj(await wire.call("thread/unsubscribe", { threadId }));
|
|
29036
|
+
if (result.status === "unsubscribed") await unloaded;
|
|
29037
|
+
unloading.delete(threadId);
|
|
29038
|
+
}
|
|
29039
|
+
}
|
|
29128
29040
|
}
|
|
29129
29041
|
for (const id of p.threads) if (owners.get(id) === p) owners.delete(id);
|
|
29042
|
+
quarantined.delete(p);
|
|
29043
|
+
};
|
|
29044
|
+
const work = cleanup();
|
|
29045
|
+
p.closing = (async () => {
|
|
29046
|
+
try {
|
|
29047
|
+
await bounded(work, TIMEOUT, "Codex thread cleanup timed out; the thread remains reserved.");
|
|
29048
|
+
} catch (e) {
|
|
29049
|
+
quarantined.add(p);
|
|
29050
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
29051
|
+
send(p, { method: "wildcrane/cleanup", params: { status: "unconfirmed", lease: p.lease } });
|
|
29052
|
+
}
|
|
29130
29053
|
peers.delete(p);
|
|
29131
29054
|
p.socket.end();
|
|
29132
29055
|
})();
|
|
@@ -29151,14 +29074,43 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29151
29074
|
const initialized = await ensure();
|
|
29152
29075
|
p.wire = rpc;
|
|
29153
29076
|
if (msg.method === "initialize") {
|
|
29154
|
-
send(p, { id, result: initialized });
|
|
29077
|
+
send(p, { id, result: { ...initialized, wildcrane: { instance: backend, lease: p.lease } } });
|
|
29155
29078
|
return;
|
|
29156
29079
|
}
|
|
29157
29080
|
if (msg.method === "initialized") return;
|
|
29158
29081
|
const wire = rpc;
|
|
29159
29082
|
let params = obj(msg.params);
|
|
29083
|
+
if (msg.method === "wildcrane/settled") {
|
|
29084
|
+
if (params.instance !== backend || params.lease !== p.lease || !str2(params.execution) || owners.get(str2(params.threadId)) !== p || params.confirmed !== true) throw Error("Codex cleanup is unconfirmed; the host will perform bounded session recovery.");
|
|
29085
|
+
const kept = Array.isArray(params.kept) ? params.kept.map(obj) : [];
|
|
29086
|
+
await bounded((async () => {
|
|
29087
|
+
const actual = [];
|
|
29088
|
+
for (const thread of p.threads) {
|
|
29089
|
+
if (active.has(thread)) throw Error("A Codex turn is still active.");
|
|
29090
|
+
actual.push(...await terminals(wire, thread));
|
|
29091
|
+
}
|
|
29092
|
+
const key = (v) => JSON.stringify([v.threadId, v.itemId, v.processId]);
|
|
29093
|
+
if (new Set(kept.map(key)).size !== kept.length || actual.length !== kept.length || actual.some((t) => !kept.some((k) => key(k) === key(t)))) throw Error("Codex retained terminal state changed before handoff.");
|
|
29094
|
+
})(), TIMEOUT, "Codex retention verification timed out.");
|
|
29095
|
+
if (p.closing || wire !== rpc) throw Error("Codex execution ownership expired.");
|
|
29096
|
+
p.settled = { root: str2(params.threadId), execution: str2(params.execution), kept };
|
|
29097
|
+
send(p, { id, result: { confirmed: true, instance: backend, lease: p.lease } });
|
|
29098
|
+
return;
|
|
29099
|
+
}
|
|
29100
|
+
let held;
|
|
29160
29101
|
if (["thread/start", "thread/resume", "thread/fork"].includes(msg.method)) {
|
|
29161
|
-
if (msg.method !== "thread/start")
|
|
29102
|
+
if (msg.method !== "thread/start") {
|
|
29103
|
+
const source = str2(params.threadId);
|
|
29104
|
+
const previous = retained.get(source);
|
|
29105
|
+
if (previous && msg.method === "thread/resume" && previous.settings !== JSON.stringify([p.cwd, p.config])) 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.");
|
|
29106
|
+
held = msg.method === "thread/resume" ? previous : void 0;
|
|
29107
|
+
if ([...retained.values()].some((group) => group.threads.has(source)) && !previous) throw Error("Resume the owning Codex thread to adopt its retained work.");
|
|
29108
|
+
if (msg.method === "thread/resume" || !previous) claim(p, source);
|
|
29109
|
+
if (held) {
|
|
29110
|
+
for (const thread of held.threads) claim(p, thread);
|
|
29111
|
+
retained.delete(source);
|
|
29112
|
+
}
|
|
29113
|
+
}
|
|
29162
29114
|
const cwd = params.cwd ?? p.cwd;
|
|
29163
29115
|
const settings = await wire.call("config/read", { cwd, includeLayers: false });
|
|
29164
29116
|
const config = { ...p.config, ...obj(params.config), thread_unload_delay_secs: 0 };
|
|
@@ -29168,7 +29120,9 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29168
29120
|
const threadId2 = str2(params.threadId);
|
|
29169
29121
|
if (!threadId2 || owners.get(threadId2) !== p) throw Error("This run does not own that Codex thread.");
|
|
29170
29122
|
}
|
|
29123
|
+
if (msg.method === "turn/start") p.settled = void 0;
|
|
29171
29124
|
const result = await wire.call(msg.method, params);
|
|
29125
|
+
if (held) result.retainedThreads = [...held.threads].map((id2) => ({ id: id2 }));
|
|
29172
29126
|
const threadId = str2(obj(result.thread).id);
|
|
29173
29127
|
if (threadId) claim(p, threadId);
|
|
29174
29128
|
if (id !== void 0) send(p, { id, result });
|
|
@@ -29180,6 +29134,7 @@ function providerServer(command, provider, environment, home, remember) {
|
|
|
29180
29134
|
peers,
|
|
29181
29135
|
request,
|
|
29182
29136
|
release: release2,
|
|
29137
|
+
held: () => retained.size > 0 || quarantined.size > 0,
|
|
29183
29138
|
async close() {
|
|
29184
29139
|
closing = true;
|
|
29185
29140
|
await bounded(Promise.allSettled([...peers].map(release2)), TIMEOUT, "Codex cleanup timed out.").catch(() => {
|
|
@@ -29226,7 +29181,7 @@ function threadConfig(argv, env) {
|
|
|
29226
29181
|
config[key] = value;
|
|
29227
29182
|
}
|
|
29228
29183
|
}
|
|
29229
|
-
const local = Object.fromEntries(Object.entries(env).filter(([key, value]) => value !== void 0 && key !== "OPENAI_API_KEY" && (process.env[key] !== value || /^(KANBAN_|AI4KANBAN_|WILDCRANE_|PATH$)/.test(key))));
|
|
29184
|
+
const local = Object.fromEntries(Object.entries(env).filter(([key, value]) => value !== void 0 && key !== "OPENAI_API_KEY" && key !== "WILDCRANE_FLOW_WORKER" && (process.env[key] !== value || /^(KANBAN_|AI4KANBAN_|WILDCRANE_|PATH$)/.test(key))));
|
|
29230
29185
|
config["shell_environment_policy.set"] = { ...obj(config["shell_environment_policy.set"]), ...local };
|
|
29231
29186
|
return config;
|
|
29232
29187
|
}
|
|
@@ -29246,7 +29201,7 @@ function tomlValue(value) {
|
|
|
29246
29201
|
|
|
29247
29202
|
// src/codex-service-main.ts
|
|
29248
29203
|
useRunnerHome();
|
|
29249
|
-
var release = tryLock(path16.join(runnerCwd(), "codex-service.owner.lock"));
|
|
29204
|
+
var release = tryLock(path16.join(runnerCwd(), "codex-service-v2.owner.lock"));
|
|
29250
29205
|
if (!release) process.exit(1);
|
|
29251
29206
|
var keep = hold(path16.resolve(path16.dirname(fileURLToPath3(import.meta.url)), ".."));
|
|
29252
29207
|
var unregister = executorRecord();
|
|
@@ -29258,7 +29213,7 @@ try {
|
|
|
29258
29213
|
if (!service.idle()) idleAt = Date.now();
|
|
29259
29214
|
if (generation !== accountGeneration() || service.idle() && Date.now() - idleAt >= (Number(process.env.WILDCRANE_CODEX_IDLE_MS) || 3e4)) void service.close();
|
|
29260
29215
|
}, 200);
|
|
29261
|
-
for (const
|
|
29216
|
+
for (const signal of ["SIGTERM", "SIGINT"]) process.on(signal, () => {
|
|
29262
29217
|
void service.close();
|
|
29263
29218
|
});
|
|
29264
29219
|
await service.closed;
|