@liberseek/boft-cli-win32-arm64 0.8.7 → 0.8.8
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/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/host-runtime.mjs +658 -298
- package/bin/boft.exe +0 -0
- package/libexec/boft-node-repl.exe +0 -0
- package/libexec/boft-shim.exe +0 -0
- package/libexec/boft-updater.exe +0 -0
- package/package.json +1 -1
package/app/host-runtime.mjs
CHANGED
|
@@ -9608,7 +9608,7 @@ var require_websocket = __commonJS({
|
|
|
9608
9608
|
var http = __require("http");
|
|
9609
9609
|
var net5 = __require("net");
|
|
9610
9610
|
var tls = __require("tls");
|
|
9611
|
-
var { randomBytes: randomBytes11, createHash:
|
|
9611
|
+
var { randomBytes: randomBytes11, createHash: createHash20 } = __require("crypto");
|
|
9612
9612
|
var { Duplex: Duplex2, Readable } = __require("stream");
|
|
9613
9613
|
var { URL: URL2 } = __require("url");
|
|
9614
9614
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -10276,7 +10276,7 @@ var require_websocket = __commonJS({
|
|
|
10276
10276
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
10277
10277
|
return;
|
|
10278
10278
|
}
|
|
10279
|
-
const digest2 =
|
|
10279
|
+
const digest2 = createHash20("sha1").update(key + GUID).digest("base64");
|
|
10280
10280
|
if (res.headers["sec-websocket-accept"] !== digest2) {
|
|
10281
10281
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
10282
10282
|
return;
|
|
@@ -10645,7 +10645,7 @@ var require_websocket_server = __commonJS({
|
|
|
10645
10645
|
var EventEmitter2 = __require("events");
|
|
10646
10646
|
var http = __require("http");
|
|
10647
10647
|
var { Duplex: Duplex2 } = __require("stream");
|
|
10648
|
-
var { createHash:
|
|
10648
|
+
var { createHash: createHash20 } = __require("crypto");
|
|
10649
10649
|
var extension2 = require_extension();
|
|
10650
10650
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
10651
10651
|
var subprotocol2 = require_subprotocol();
|
|
@@ -10952,7 +10952,7 @@ var require_websocket_server = __commonJS({
|
|
|
10952
10952
|
);
|
|
10953
10953
|
}
|
|
10954
10954
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
10955
|
-
const digest2 =
|
|
10955
|
+
const digest2 = createHash20("sha1").update(key + GUID).digest("base64");
|
|
10956
10956
|
const headers = [
|
|
10957
10957
|
"HTTP/1.1 101 Switching Protocols",
|
|
10958
10958
|
"Upgrade: websocket",
|
|
@@ -13216,15 +13216,15 @@ function selectInstallerReleaseArtifact(release, target2) {
|
|
|
13216
13216
|
if (!asset)
|
|
13217
13217
|
throw new Error(`GitHub Release must contain exactly one ${name}`);
|
|
13218
13218
|
const digest2 = asset.digest === null ? null : SHA256_DIGEST_PATTERN.exec(asset.digest);
|
|
13219
|
-
const
|
|
13220
|
-
if (!
|
|
13219
|
+
const sha2562 = digest2?.[1];
|
|
13220
|
+
if (!sha2562)
|
|
13221
13221
|
throw new Error(`GitHub Release asset ${name} has no valid SHA-256 digest`);
|
|
13222
13222
|
if (!isBoftReleaseDownloadUrl(asset.downloadUrl, release.version) || !asset.downloadUrl.endsWith(`/${name}`)) {
|
|
13223
13223
|
throw new Error(`GitHub Release asset ${name} has an unexpected download URL`);
|
|
13224
13224
|
}
|
|
13225
13225
|
return Object.freeze({
|
|
13226
13226
|
name,
|
|
13227
|
-
source: Object.freeze({ url: asset.downloadUrl, sha256, size: asset.size })
|
|
13227
|
+
source: Object.freeze({ url: asset.downloadUrl, sha256: sha2562, size: asset.size })
|
|
13228
13228
|
});
|
|
13229
13229
|
}
|
|
13230
13230
|
|
|
@@ -32088,7 +32088,7 @@ function retainRendererHostResponses(client, hostId2, target2) {
|
|
|
32088
32088
|
if (typeof client.addRequestLifecycleListener !== "function" || typeof target2.addEventListener !== "function" || typeof target2.removeEventListener !== "function")
|
|
32089
32089
|
return () => {
|
|
32090
32090
|
};
|
|
32091
|
-
const
|
|
32091
|
+
const isRecord26 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
32092
32092
|
const pending = /* @__PURE__ */ new Set();
|
|
32093
32093
|
let retired = false;
|
|
32094
32094
|
let unsubscribe = () => {
|
|
@@ -32104,15 +32104,15 @@ function retainRendererHostResponses(client, hostId2, target2) {
|
|
|
32104
32104
|
const ownOrigin2 = target2.location?.origin;
|
|
32105
32105
|
if (source === target2 && ownOrigin2 && ownOrigin2 !== "null" && origin !== ownOrigin2)
|
|
32106
32106
|
return;
|
|
32107
|
-
if (!
|
|
32107
|
+
if (!isRecord26(data) || data.type !== "mcp-response" || data.hostId !== hostId2)
|
|
32108
32108
|
return;
|
|
32109
32109
|
const message2 = data.message;
|
|
32110
|
-
if (!
|
|
32110
|
+
if (!isRecord26(message2))
|
|
32111
32111
|
return;
|
|
32112
32112
|
const id2 = message2.id;
|
|
32113
32113
|
if (typeof id2 !== "string" && typeof id2 !== "number" || !pending.has(id2))
|
|
32114
32114
|
return;
|
|
32115
|
-
const hasError =
|
|
32115
|
+
const hasError = isRecord26(message2.error);
|
|
32116
32116
|
if (!hasError && !Object.prototype.hasOwnProperty.call(message2, "result"))
|
|
32117
32117
|
return;
|
|
32118
32118
|
queueMicrotask(() => {
|
|
@@ -32126,7 +32126,7 @@ function retainRendererHostResponses(client, hostId2, target2) {
|
|
|
32126
32126
|
};
|
|
32127
32127
|
target2.addEventListener("message", receive);
|
|
32128
32128
|
unsubscribe = client.addRequestLifecycleListener((event) => {
|
|
32129
|
-
if (!
|
|
32129
|
+
if (!isRecord26(event) || event.hostId !== hostId2)
|
|
32130
32130
|
return;
|
|
32131
32131
|
const id2 = event.id;
|
|
32132
32132
|
if (typeof id2 !== "string" && typeof id2 !== "number")
|
|
@@ -32259,13 +32259,13 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32259
32259
|
let selectedModel = null;
|
|
32260
32260
|
let prewarmGeneration = 0;
|
|
32261
32261
|
const externalPrewarms = /* @__PURE__ */ new Set();
|
|
32262
|
-
const
|
|
32262
|
+
const isRecord26 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
32263
32263
|
const isUnsupportedPosixBridgeSpawn = (value2) => {
|
|
32264
32264
|
const marker = "AbsolutePathBuf deserialized without a base path";
|
|
32265
32265
|
if (typeof value2 === "string") {
|
|
32266
32266
|
return value2.startsWith("Invalid request:") && value2.includes(marker);
|
|
32267
32267
|
}
|
|
32268
|
-
if (!
|
|
32268
|
+
if (!isRecord26(value2))
|
|
32269
32269
|
return false;
|
|
32270
32270
|
if (typeof value2.message === "string" && value2.message.includes(marker)) {
|
|
32271
32271
|
if (value2.code === -32600 || value2.message.startsWith("Invalid request:"))
|
|
@@ -32358,7 +32358,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32358
32358
|
bridgeState = "idle";
|
|
32359
32359
|
};
|
|
32360
32360
|
const rememberExternalThread = (value2) => {
|
|
32361
|
-
if (!
|
|
32361
|
+
if (!isRecord26(value2) || typeof value2.id !== "string")
|
|
32362
32362
|
return;
|
|
32363
32363
|
if (value2.modelProvider === "codexhost" || value2.cliVersion === "codexhost") {
|
|
32364
32364
|
knownExternalThreadIds.add(value2.id);
|
|
@@ -32366,7 +32366,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32366
32366
|
}
|
|
32367
32367
|
};
|
|
32368
32368
|
const observeBridgeResult = (request, result) => {
|
|
32369
|
-
if (!request || !
|
|
32369
|
+
if (!request || !isRecord26(result))
|
|
32370
32370
|
return;
|
|
32371
32371
|
if (request.method === "thread/list" && Array.isArray(result.data)) {
|
|
32372
32372
|
for (const thread3 of result.data)
|
|
@@ -32377,7 +32377,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32377
32377
|
rememberExternalThread(result.thread);
|
|
32378
32378
|
return;
|
|
32379
32379
|
}
|
|
32380
|
-
if (request.method === "codexhost/thread/inspect" &&
|
|
32380
|
+
if (request.method === "codexhost/thread/inspect" && isRecord26(request.parameters) && typeof request.parameters.threadId === "string") {
|
|
32381
32381
|
if (result.owner === "external") {
|
|
32382
32382
|
knownExternalThreadIds.add(request.parameters.threadId);
|
|
32383
32383
|
knownOfficialThreadIds.delete(request.parameters.threadId);
|
|
@@ -32387,18 +32387,18 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32387
32387
|
}
|
|
32388
32388
|
return;
|
|
32389
32389
|
}
|
|
32390
|
-
if (request.method === "thread/delete" &&
|
|
32390
|
+
if (request.method === "thread/delete" && isRecord26(request.parameters) && typeof request.parameters.threadId === "string") {
|
|
32391
32391
|
knownExternalThreadIds.delete(request.parameters.threadId);
|
|
32392
32392
|
knownOfficialThreadIds.delete(request.parameters.threadId);
|
|
32393
32393
|
}
|
|
32394
32394
|
};
|
|
32395
32395
|
const handleBridgeFrame = (value2) => {
|
|
32396
|
-
if (!
|
|
32396
|
+
if (!isRecord26(value2)) {
|
|
32397
32397
|
failBridge("received a non-object app-server frame");
|
|
32398
32398
|
return;
|
|
32399
32399
|
}
|
|
32400
32400
|
if (value2.method === bridgeReadyMethod && value2.id === void 0) {
|
|
32401
|
-
if (
|
|
32401
|
+
if (isRecord26(value2.params) && value2.params.protocolVersion === 1) {
|
|
32402
32402
|
bridgeState = "ready";
|
|
32403
32403
|
if (bridgeReadyTimeout !== null)
|
|
32404
32404
|
globalThis.clearTimeout(bridgeReadyTimeout);
|
|
@@ -32412,7 +32412,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32412
32412
|
return;
|
|
32413
32413
|
}
|
|
32414
32414
|
if (typeof value2.method === "string" && value2.id === void 0) {
|
|
32415
|
-
if (value2.method === "thread/started" &&
|
|
32415
|
+
if (value2.method === "thread/started" && isRecord26(value2.params)) {
|
|
32416
32416
|
rememberExternalThread(value2.params.thread);
|
|
32417
32417
|
}
|
|
32418
32418
|
originalOnNotification.call(manager, value2.method, value2.params);
|
|
@@ -32463,13 +32463,13 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32463
32463
|
}
|
|
32464
32464
|
};
|
|
32465
32465
|
const handleOuterNotification = (method, parameters) => {
|
|
32466
|
-
if (method === "process/exited" &&
|
|
32466
|
+
if (method === "process/exited" && isRecord26(parameters) && parameters.processHandle === bridgeProcessHandle) {
|
|
32467
32467
|
const exitCode = typeof parameters.exitCode === "number" ? parameters.exitCode : "unknown";
|
|
32468
32468
|
const stderr = typeof parameters.stderr === "string" ? parameters.stderr.trim() : "";
|
|
32469
32469
|
failBridge(`process exited unexpectedly with code ${exitCode}${stderr ? `: ${stderr}` : ""}`, false);
|
|
32470
32470
|
return true;
|
|
32471
32471
|
}
|
|
32472
|
-
if (method !== "process/outputDelta" || !
|
|
32472
|
+
if (method !== "process/outputDelta" || !isRecord26(parameters) || parameters.processHandle !== bridgeProcessHandle || parameters.stream !== "stdout" && parameters.stream !== "stderr" || typeof parameters.deltaBase64 !== "string") {
|
|
32473
32473
|
return false;
|
|
32474
32474
|
}
|
|
32475
32475
|
if (parameters.capReached === true) {
|
|
@@ -32573,7 +32573,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32573
32573
|
return bridgeInitialization;
|
|
32574
32574
|
};
|
|
32575
32575
|
const threadIdFromParameters = (parameters) => {
|
|
32576
|
-
if (!
|
|
32576
|
+
if (!isRecord26(parameters))
|
|
32577
32577
|
return null;
|
|
32578
32578
|
const value2 = parameters.threadId ?? parameters.conversationId;
|
|
32579
32579
|
return typeof value2 === "string" ? value2 : null;
|
|
@@ -32590,9 +32590,9 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32590
32590
|
const resolution = initializeBridge().then(() => enqueueBridgeRequest("codexhost/thread/ownership/list", {
|
|
32591
32591
|
threadIds: [threadId3]
|
|
32592
32592
|
})).then((value2) => {
|
|
32593
|
-
const ownerships =
|
|
32593
|
+
const ownerships = isRecord26(value2) && Array.isArray(value2.threads) ? value2.threads : null;
|
|
32594
32594
|
const ownership = ownerships?.[0];
|
|
32595
|
-
if (!ownerships || !
|
|
32595
|
+
if (!ownerships || !isRecord26(ownership) || ownerships.length !== 1 || ownership.threadId !== threadId3 || ownership.owner !== "external" && ownership.owner !== "codex") {
|
|
32596
32596
|
throw transportError("Thread ownership lookup returned an invalid result");
|
|
32597
32597
|
}
|
|
32598
32598
|
if (ownership.owner === "external") {
|
|
@@ -32631,7 +32631,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32631
32631
|
if (method === "thread/list")
|
|
32632
32632
|
return true;
|
|
32633
32633
|
if (method === "thread/start") {
|
|
32634
|
-
return
|
|
32634
|
+
return isRecord26(parameters) && typeof parameters.model === "string" && parameters.model.startsWith("codexhost/");
|
|
32635
32635
|
}
|
|
32636
32636
|
const threadId3 = threadIdFromParameters(parameters);
|
|
32637
32637
|
if (threadId3 && knownExternalThreadIds.has(threadId3))
|
|
@@ -32664,12 +32664,12 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32664
32664
|
return shouldUseBridge(method, parameters) ? sendBridged() : sendDirect();
|
|
32665
32665
|
};
|
|
32666
32666
|
const publishDraftWorkspace = (parameters) => {
|
|
32667
|
-
if (!
|
|
32667
|
+
if (!isRecord26(parameters) || parameters.ephemeral === true)
|
|
32668
32668
|
return;
|
|
32669
32669
|
const cwd = parameters.cwd;
|
|
32670
32670
|
if (typeof cwd !== "string" || cwd.length === 0)
|
|
32671
32671
|
return;
|
|
32672
|
-
const drafts =
|
|
32672
|
+
const drafts = isRecord26(target2.__codexhostDraftWorkspacesV1) ? target2.__codexhostDraftWorkspacesV1 : {};
|
|
32673
32673
|
drafts[hostId2] = cwd;
|
|
32674
32674
|
Object.defineProperty(target2, "__codexhostDraftWorkspacesV1", {
|
|
32675
32675
|
configurable: true,
|
|
@@ -32692,16 +32692,16 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32692
32692
|
};
|
|
32693
32693
|
const restoreConsumption = isolateConsumption(manager, discardExternalPrewarm);
|
|
32694
32694
|
const routedPrewarm = (parameters, options) => {
|
|
32695
|
-
const external =
|
|
32695
|
+
const external = isRecord26(parameters) && parameters.ephemeral !== true && typeof parameters.model === "string" && parameters.model.startsWith("codexhost/");
|
|
32696
32696
|
const routedParameters = external ? { ...parameters, codexhostPrewarm: true } : parameters;
|
|
32697
32697
|
const generation = prewarmGeneration;
|
|
32698
32698
|
publishDraftWorkspace(routedParameters);
|
|
32699
32699
|
const pending = shouldUseBridge("thread/start", routedParameters) ? routedSend("thread/start", routedParameters, options) : options === void 0 ? originalPrewarm.call(bridge, routedParameters) : originalPrewarm.call(bridge, routedParameters, options);
|
|
32700
|
-
if (
|
|
32700
|
+
if (isRecord26(parameters) && parameters.ephemeral === true || typeof pending !== "object" && typeof pending !== "function" || pending === null || typeof Reflect.get(pending, "then") !== "function") {
|
|
32701
32701
|
return pending;
|
|
32702
32702
|
}
|
|
32703
32703
|
return Promise.resolve(pending).then((result) => {
|
|
32704
|
-
const threadId3 = external &&
|
|
32704
|
+
const threadId3 = external && isRecord26(result) && isRecord26(result.thread) && typeof result.thread.id === "string" ? result.thread.id : null;
|
|
32705
32705
|
if (disposed || generation !== prewarmGeneration) {
|
|
32706
32706
|
if (threadId3)
|
|
32707
32707
|
discardExternalPrewarm(threadId3);
|
|
@@ -32717,7 +32717,7 @@ function createDraftPrewarmPolicyBridge(manager, bridge, hostId2, target2, prewa
|
|
|
32717
32717
|
bridge.prewarmThreadStart = routedPrewarm;
|
|
32718
32718
|
const routedWindowMessage = (event) => {
|
|
32719
32719
|
const message2 = event.data;
|
|
32720
|
-
if (!
|
|
32720
|
+
if (!isRecord26(message2) || message2.type !== "mcp-notification" || message2.hostId !== hostId2 || typeof message2.method !== "string") {
|
|
32721
32721
|
return;
|
|
32722
32722
|
}
|
|
32723
32723
|
handleOuterNotification(message2.method, message2.params);
|
|
@@ -33212,7 +33212,7 @@ function installRendererHostRpcRouting(root, target2, dependencies2) {
|
|
|
33212
33212
|
}
|
|
33213
33213
|
};
|
|
33214
33214
|
const sameConnection = (previous, current) => previous === void 0 ? current === void 0 : current?.owner === previous.owner && current.revision === previous.revision;
|
|
33215
|
-
const
|
|
33215
|
+
const isRecord26 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
33216
33216
|
const externalDrafts = /* @__PURE__ */ new Map();
|
|
33217
33217
|
const selectedModels = /* @__PURE__ */ new Map();
|
|
33218
33218
|
const prewarmCarrier = (carrier) => {
|
|
@@ -33222,7 +33222,7 @@ function installRendererHostRpcRouting(root, target2, dependencies2) {
|
|
|
33222
33222
|
try {
|
|
33223
33223
|
const json2 = carrier.slice(prefix.length).replace(/[a-f0-9]{2}/gu, (byte) => String.fromCharCode(Number.parseInt(byte, 16)));
|
|
33224
33224
|
const route = JSON.parse(json2);
|
|
33225
|
-
if (!
|
|
33225
|
+
if (!isRecord26(route))
|
|
33226
33226
|
return null;
|
|
33227
33227
|
const payload = [...JSON.stringify({ ...route, prewarm: true })].map((character) => character.charCodeAt(0).toString(16).padStart(2, "0")).join("");
|
|
33228
33228
|
return `${prefix}${payload}`;
|
|
@@ -33233,7 +33233,7 @@ function installRendererHostRpcRouting(root, target2, dependencies2) {
|
|
|
33233
33233
|
const publishDraftWorkspace = (hostId2, cwd) => {
|
|
33234
33234
|
if (typeof cwd !== "string" || cwd.length === 0)
|
|
33235
33235
|
return;
|
|
33236
|
-
const drafts =
|
|
33236
|
+
const drafts = isRecord26(target2.__codexhostDraftWorkspacesV1) ? target2.__codexhostDraftWorkspacesV1 : {};
|
|
33237
33237
|
if (drafts[hostId2] === cwd)
|
|
33238
33238
|
return;
|
|
33239
33239
|
drafts[hostId2] = cwd;
|
|
@@ -33255,15 +33255,15 @@ function installRendererHostRpcRouting(root, target2, dependencies2) {
|
|
|
33255
33255
|
if (!Array.isArray(path66) || path66.length !== 1 || !Array.isArray(args))
|
|
33256
33256
|
return message2;
|
|
33257
33257
|
const [input, options] = args;
|
|
33258
|
-
if (!
|
|
33258
|
+
if (!isRecord26(input) || !isRecord26(input.collaborationMode))
|
|
33259
33259
|
return message2;
|
|
33260
33260
|
const settings = input.collaborationMode.settings;
|
|
33261
|
-
if (!
|
|
33261
|
+
if (!isRecord26(settings))
|
|
33262
33262
|
return message2;
|
|
33263
33263
|
const nativeModel = typeof settings.model === "string" ? settings.model : null;
|
|
33264
33264
|
let model2 = null;
|
|
33265
33265
|
if (path66[0] === "startConversation") {
|
|
33266
|
-
const draftId =
|
|
33266
|
+
const draftId = isRecord26(options) ? options.clientThreadId : null;
|
|
33267
33267
|
model2 = typeof draftId === "string" ? externalDrafts.get(draftId)?.model ?? null : null;
|
|
33268
33268
|
} else if (path66[0] === "prewarmConversation") {
|
|
33269
33269
|
if (input.ephemeral !== true)
|
|
@@ -33276,7 +33276,7 @@ function installRendererHostRpcRouting(root, target2, dependencies2) {
|
|
|
33276
33276
|
return message2;
|
|
33277
33277
|
if (path66[0] === "startConversation" && nativeModel?.startsWith("codexhost/"))
|
|
33278
33278
|
model2 = nativeModel;
|
|
33279
|
-
const config2 = input.config == null ? { model: model2 } :
|
|
33279
|
+
const config2 = input.config == null ? { model: model2 } : isRecord26(input.config) ? { model: model2, ...input.config } : input.config;
|
|
33280
33280
|
return [
|
|
33281
33281
|
"push",
|
|
33282
33282
|
[
|
|
@@ -33355,7 +33355,7 @@ function installRendererHostRpcRouting(root, target2, dependencies2) {
|
|
|
33355
33355
|
const { source, data } = event;
|
|
33356
33356
|
if (source != null && source !== target2)
|
|
33357
33357
|
return;
|
|
33358
|
-
if (!
|
|
33358
|
+
if (!isRecord26(data) || data.type !== "mcp-notification" || data.hostId !== hostId2 || typeof data.method !== "string" || !accepted.has(data.method) || !isCurrent())
|
|
33359
33359
|
return;
|
|
33360
33360
|
listener({ method: data.method, params: data.params });
|
|
33361
33361
|
};
|
|
@@ -35591,6 +35591,7 @@ var storedGitInfoV1Schema = external_exports.object({
|
|
|
35591
35591
|
originUrl: nonBlankTextSchema6.max(16384).optional(),
|
|
35592
35592
|
sha: nonBlankTextSchema6.max(1024).optional()
|
|
35593
35593
|
}).strict();
|
|
35594
|
+
var MAX_PENDING_INJECTED_TEXTS = 64;
|
|
35594
35595
|
var storedThreadCoreV1Shape = {
|
|
35595
35596
|
formatVersion: external_exports.literal(1),
|
|
35596
35597
|
revision: external_exports.number().int().positive(),
|
|
@@ -35618,6 +35619,24 @@ var storedThreadCoreV1Shape = {
|
|
|
35618
35619
|
nativeSubagentId: nonBlankTextSchema6.max(1024),
|
|
35619
35620
|
role: external_exports.string().max(1024).optional()
|
|
35620
35621
|
}).strict().optional(),
|
|
35622
|
+
// Side Chat fields fall back to absent rather than quarantining the Thread.
|
|
35623
|
+
/** Desktop Side Chat source; attached Threads are listed only under it. */
|
|
35624
|
+
attachedToThreadId: hostThreadIdSchema.optional().catch(void 0),
|
|
35625
|
+
/** Leading Turns an attached Side Chat inherited from its source; they are not listed. */
|
|
35626
|
+
inheritedTurnCount: external_exports.number().int().nonnegative().optional().catch(void 0),
|
|
35627
|
+
/** `thread/inject_items` text not yet delivered; the next Turn carries it. */
|
|
35628
|
+
pendingInjectedText: external_exports.array(external_exports.string()).max(MAX_PENDING_INJECTED_TEXTS).optional().catch(void 0),
|
|
35629
|
+
/** How many held texts were released. A Turn releases by position, never by content. */
|
|
35630
|
+
releasedInjectedTexts: external_exports.number().int().nonnegative().optional().catch(void 0),
|
|
35631
|
+
/**
|
|
35632
|
+
* Turns whose native input begins with delivered injected text, hidden when replayed. One
|
|
35633
|
+
* entry per such Turn, never trimmed, so every replayed Turn stays clean.
|
|
35634
|
+
*/
|
|
35635
|
+
injectedTurnPrefixes: external_exports.array(external_exports.object({
|
|
35636
|
+
hostTurnId: hostTurnIdSchema,
|
|
35637
|
+
length: external_exports.number().int().positive(),
|
|
35638
|
+
sha256: external_exports.string().regex(/^[a-f0-9]{64}$/u)
|
|
35639
|
+
})).optional().catch(void 0),
|
|
35621
35640
|
turnMappings: external_exports.array(storedTurnMappingV1Schema),
|
|
35622
35641
|
createdAt: isoDateSchema,
|
|
35623
35642
|
updatedAt: isoDateSchema
|
|
@@ -35676,6 +35695,13 @@ function refineThreadRecord(record7, context) {
|
|
|
35676
35695
|
message: "Subagent Threads cannot have an import source"
|
|
35677
35696
|
});
|
|
35678
35697
|
}
|
|
35698
|
+
if (record7.attachedToThreadId && (record7.attachedToThreadId === record7.hostThreadId || record7.subagent)) {
|
|
35699
|
+
context.addIssue({
|
|
35700
|
+
code: "custom",
|
|
35701
|
+
path: ["attachedToThreadId"],
|
|
35702
|
+
message: "Only a non-Subagent Thread can attach to another Thread"
|
|
35703
|
+
});
|
|
35704
|
+
}
|
|
35679
35705
|
const hostTurnIds = /* @__PURE__ */ new Set();
|
|
35680
35706
|
const nativeTurnKeys = /* @__PURE__ */ new Set();
|
|
35681
35707
|
for (const [index, mapping] of record7.turnMappings.entries()) {
|
|
@@ -36350,6 +36376,8 @@ var MappingStore = class {
|
|
|
36350
36376
|
historyMode: input.historyMode,
|
|
36351
36377
|
...input.projectlessWorkspace ? { projectlessWorkspace: input.projectlessWorkspace } : {},
|
|
36352
36378
|
...input.forkSource ? { forkSource: input.forkSource } : {},
|
|
36379
|
+
...input.attachedToThreadId ? { attachedToThreadId: input.attachedToThreadId } : {},
|
|
36380
|
+
...input.inheritedTurnCount !== void 0 ? { inheritedTurnCount: input.inheritedTurnCount } : {},
|
|
36353
36381
|
...input.subagent ? { subagent: input.subagent } : {},
|
|
36354
36382
|
turnMappings: [],
|
|
36355
36383
|
createdAt: timestamp,
|
|
@@ -36525,6 +36553,41 @@ var MappingStore = class {
|
|
|
36525
36553
|
async setPinned(hostThreadId, isPinned) {
|
|
36526
36554
|
return this.#update(hostThreadId, (current) => current.isPinned === isPinned ? null : { ...current, isPinned });
|
|
36527
36555
|
}
|
|
36556
|
+
/** Hold `thread/inject_items` text for the next Turn; over the limit, fail and keep the queue. */
|
|
36557
|
+
async appendPendingInjectedText(hostThreadId, texts) {
|
|
36558
|
+
return this.#update(hostThreadId, (current) => {
|
|
36559
|
+
if (texts.length === 0)
|
|
36560
|
+
return null;
|
|
36561
|
+
const pending = [...current.pendingInjectedText ?? [], ...texts];
|
|
36562
|
+
if (pending.length > MAX_PENDING_INJECTED_TEXTS) {
|
|
36563
|
+
throw new MappingStoreError("INVALID_RECORD", `At most ${MAX_PENDING_INJECTED_TEXTS} injected texts can wait for the next Turn`);
|
|
36564
|
+
}
|
|
36565
|
+
return { ...current, pendingInjectedText: pending };
|
|
36566
|
+
}, true);
|
|
36567
|
+
}
|
|
36568
|
+
/**
|
|
36569
|
+
* Record that a started Turn delivered the held texts before position `through`, counted over
|
|
36570
|
+
* every text ever held, and release the ones still queued. Another Turn may have released
|
|
36571
|
+
* them already; texts held after that keep their own positions, even with the same content.
|
|
36572
|
+
*/
|
|
36573
|
+
async consumePendingInjectedText(hostThreadId, through, prefix) {
|
|
36574
|
+
return this.#update(hostThreadId, (current) => {
|
|
36575
|
+
const released = current.releasedInjectedTexts ?? 0;
|
|
36576
|
+
const queued = current.pendingInjectedText ?? [];
|
|
36577
|
+
const count2 = Math.min(Math.max(through - released, 0), queued.length);
|
|
36578
|
+
const pending = queued.slice(count2);
|
|
36579
|
+
const next = {
|
|
36580
|
+
...current,
|
|
36581
|
+
releasedInjectedTexts: released + count2,
|
|
36582
|
+
injectedTurnPrefixes: [...current.injectedTurnPrefixes ?? [], prefix]
|
|
36583
|
+
};
|
|
36584
|
+
if (pending.length > 0)
|
|
36585
|
+
next.pendingInjectedText = pending;
|
|
36586
|
+
else
|
|
36587
|
+
delete next.pendingInjectedText;
|
|
36588
|
+
return next;
|
|
36589
|
+
}, true);
|
|
36590
|
+
}
|
|
36528
36591
|
/**
|
|
36529
36592
|
* Patch Desktop metadata. With `ifProjectId`, the patch applies only while the
|
|
36530
36593
|
* stored assignment still equals it; otherwise the current record is returned.
|
|
@@ -39899,6 +39962,10 @@ function decodeThreadForkRequest(request) {
|
|
|
39899
39962
|
}
|
|
39900
39963
|
const path66 = optionalText2(params, "path", { allowEmpty: true });
|
|
39901
39964
|
const ephemeral = optionalBoolean(params, "ephemeral");
|
|
39965
|
+
const attachToSource = optionalBoolean(params, "attachToSource");
|
|
39966
|
+
if (attachToSource && ephemeral) {
|
|
39967
|
+
throw new Error("thread/fork cannot combine attachToSource with ephemeral");
|
|
39968
|
+
}
|
|
39902
39969
|
return {
|
|
39903
39970
|
threadId: threadId3,
|
|
39904
39971
|
...lastTurnText ? { lastTurnId: hostTurnIdSchema.parse(lastTurnText) } : {},
|
|
@@ -39909,6 +39976,7 @@ function decodeThreadForkRequest(request) {
|
|
|
39909
39976
|
...optionalField(params, "cwd"),
|
|
39910
39977
|
excludeTurns: optionalBoolean(params, "excludeTurns") ?? false,
|
|
39911
39978
|
...ephemeral !== void 0 ? { ephemeral } : {},
|
|
39979
|
+
...attachToSource ? { attachToSource } : {},
|
|
39912
39980
|
...Array.isArray(runtimeWorkspaceRoots) ? { runtimeWorkspaceRoots } : {},
|
|
39913
39981
|
...optionalField(params, "approvalPolicy"),
|
|
39914
39982
|
...optionalField(params, "sandbox"),
|
|
@@ -39999,6 +40067,39 @@ function threadForkResult(thread3, input) {
|
|
|
39999
40067
|
};
|
|
40000
40068
|
}
|
|
40001
40069
|
|
|
40070
|
+
// packages/protocol-core/dist/thread-inject.js
|
|
40071
|
+
function isRecord9(value2) {
|
|
40072
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
40073
|
+
}
|
|
40074
|
+
function decodeThreadInjectItemsRequest(request) {
|
|
40075
|
+
if (request.method !== "thread/inject_items")
|
|
40076
|
+
return null;
|
|
40077
|
+
if (!isRecord9(request.params))
|
|
40078
|
+
throw new Error("thread/inject_items params must be an object");
|
|
40079
|
+
const { threadId: threadId3, items } = request.params;
|
|
40080
|
+
if (typeof threadId3 !== "string" || threadId3.length === 0) {
|
|
40081
|
+
throw new Error("thread/inject_items params.threadId must be non-empty text");
|
|
40082
|
+
}
|
|
40083
|
+
if (!Array.isArray(items))
|
|
40084
|
+
throw new Error("thread/inject_items params.items must be an array");
|
|
40085
|
+
const texts = items.flatMap((item, index) => {
|
|
40086
|
+
if (!isRecord9(item) || item.type !== "message" || item.role !== "user") {
|
|
40087
|
+
throw new Error(`thread/inject_items items[${index}] must be a user message`);
|
|
40088
|
+
}
|
|
40089
|
+
if (!Array.isArray(item.content)) {
|
|
40090
|
+
throw new Error(`thread/inject_items items[${index}].content must be an array`);
|
|
40091
|
+
}
|
|
40092
|
+
const text4 = item.content.map((part, partIndex) => {
|
|
40093
|
+
if (!isRecord9(part) || part.type !== "input_text" && part.type !== "text" || typeof part.text !== "string") {
|
|
40094
|
+
throw new Error(`thread/inject_items items[${index}].content[${partIndex}] must be text`);
|
|
40095
|
+
}
|
|
40096
|
+
return part.text;
|
|
40097
|
+
}).join("\n");
|
|
40098
|
+
return text4.length > 0 ? [text4] : [];
|
|
40099
|
+
});
|
|
40100
|
+
return { threadId: threadId3, texts };
|
|
40101
|
+
}
|
|
40102
|
+
|
|
40002
40103
|
// packages/protocol-core/dist/thread-management.js
|
|
40003
40104
|
import { createHash as createHash5 } from "node:crypto";
|
|
40004
40105
|
var HOST_CURSOR_PREFIX = "codexhost:thread-list:v1:";
|
|
@@ -40010,7 +40111,9 @@ var UINT32_MAX = 4294967295;
|
|
|
40010
40111
|
var THREAD_LIST_FIELDS = /* @__PURE__ */ new Set([
|
|
40011
40112
|
"ancestorThreadId",
|
|
40012
40113
|
"archived",
|
|
40114
|
+
"attachedToThreadId",
|
|
40013
40115
|
"cursor",
|
|
40116
|
+
"includeAttachedThreads",
|
|
40014
40117
|
"cwd",
|
|
40015
40118
|
"isPinned",
|
|
40016
40119
|
"limit",
|
|
@@ -40036,13 +40139,13 @@ var THREAD_SOURCE_KINDS = /* @__PURE__ */ new Set([
|
|
|
40036
40139
|
"subAgentOther",
|
|
40037
40140
|
"unknown"
|
|
40038
40141
|
]);
|
|
40039
|
-
function
|
|
40142
|
+
function isRecord10(value2) {
|
|
40040
40143
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
40041
40144
|
}
|
|
40042
40145
|
function paramsObject(request, method) {
|
|
40043
40146
|
if (request.params === void 0 && method === "thread/list")
|
|
40044
40147
|
return {};
|
|
40045
|
-
if (!
|
|
40148
|
+
if (!isRecord10(request.params))
|
|
40046
40149
|
throw new Error(`${method} params must be an object`);
|
|
40047
40150
|
return request.params;
|
|
40048
40151
|
}
|
|
@@ -40114,7 +40217,7 @@ function cursorPayload(value2) {
|
|
|
40114
40217
|
};
|
|
40115
40218
|
}
|
|
40116
40219
|
function parseCursorPayload(value2) {
|
|
40117
|
-
if (!
|
|
40220
|
+
if (!isRecord10(value2) || value2.formatVersion !== 1)
|
|
40118
40221
|
throw new Error("Host cursor is invalid");
|
|
40119
40222
|
const { queryFingerprint: fingerprint2, sortDirection: sortDirection2, officialCursor, officialDone } = value2;
|
|
40120
40223
|
const { externalAnchor: externalAnchor2, externalDone } = value2;
|
|
@@ -40123,7 +40226,7 @@ function parseCursorPayload(value2) {
|
|
|
40123
40226
|
}
|
|
40124
40227
|
let anchor = null;
|
|
40125
40228
|
if (externalAnchor2 !== null) {
|
|
40126
|
-
if (!
|
|
40229
|
+
if (!isRecord10(externalAnchor2) || !Number.isSafeInteger(externalAnchor2.timestamp) || typeof externalAnchor2.threadId !== "string" || externalAnchor2.threadId.length === 0) {
|
|
40127
40230
|
throw new Error("Host cursor is invalid");
|
|
40128
40231
|
}
|
|
40129
40232
|
anchor = {
|
|
@@ -40161,7 +40264,7 @@ function decodeHostThreadListCursor(value2, expected) {
|
|
|
40161
40264
|
return cursor;
|
|
40162
40265
|
}
|
|
40163
40266
|
function carriesHostThreadListCursor(request) {
|
|
40164
|
-
if (request.method !== "thread/list" || !
|
|
40267
|
+
if (request.method !== "thread/list" || !isRecord10(request.params))
|
|
40165
40268
|
return false;
|
|
40166
40269
|
const cursor = request.params.cursor;
|
|
40167
40270
|
return typeof cursor === "string" && (cursor.startsWith(HOST_CURSOR_PREFIX) || cursor.startsWith(SECTION_CURSOR_PREFIX));
|
|
@@ -40179,8 +40282,16 @@ function decodeThreadListRequest(request) {
|
|
|
40179
40282
|
if (parentThreadId !== null && ancestorThreadId !== null) {
|
|
40180
40283
|
throw new Error("thread/list cannot combine parentThreadId and ancestorThreadId");
|
|
40181
40284
|
}
|
|
40285
|
+
const attachedToThreadId = nullableText(params.attachedToThreadId, "thread/list params.attachedToThreadId");
|
|
40286
|
+
if (attachedToThreadId !== null && (parentThreadId !== null || ancestorThreadId !== null)) {
|
|
40287
|
+
throw new Error("thread/list cannot combine attachedToThreadId with parentThreadId or ancestorThreadId");
|
|
40288
|
+
}
|
|
40289
|
+
const includeAttachedThreads = nullableBoolean(params.includeAttachedThreads, "thread/list params.includeAttachedThreads") ?? false;
|
|
40182
40290
|
const projectId = params.projectId === void 0 ? void 0 : nullableText(params.projectId, "thread/list params.projectId");
|
|
40183
40291
|
const searchTerm = nullableText(params.searchTerm, "thread/list params.searchTerm");
|
|
40292
|
+
if (includeAttachedThreads && !searchTerm) {
|
|
40293
|
+
throw new Error("thread/list includeAttachedThreads requires a non-empty searchTerm");
|
|
40294
|
+
}
|
|
40184
40295
|
const sectionId = params.sectionId === void 0 ? void 0 : nullableText(params.sectionId, "thread/list params.sectionId");
|
|
40185
40296
|
const sortKey = decodeSortKey(params.sortKey);
|
|
40186
40297
|
const sortDirection2 = decodeSortDirection(params.sortDirection, sortKey);
|
|
@@ -40194,6 +40305,8 @@ function decodeThreadListRequest(request) {
|
|
|
40194
40305
|
const fingerprint2 = queryFingerprint({
|
|
40195
40306
|
ancestorThreadId,
|
|
40196
40307
|
archived,
|
|
40308
|
+
attachedToThreadId,
|
|
40309
|
+
includeAttachedThreads,
|
|
40197
40310
|
cwd,
|
|
40198
40311
|
isPinned,
|
|
40199
40312
|
modelProviders,
|
|
@@ -40231,6 +40344,8 @@ function decodeThreadListRequest(request) {
|
|
|
40231
40344
|
modelProviders,
|
|
40232
40345
|
parentThreadId,
|
|
40233
40346
|
ancestorThreadId,
|
|
40347
|
+
attachedToThreadId,
|
|
40348
|
+
includeAttachedThreads,
|
|
40234
40349
|
projectId,
|
|
40235
40350
|
searchTerm,
|
|
40236
40351
|
sectionId,
|
|
@@ -40258,7 +40373,7 @@ function decodeSectionCursor(value2, queryFingerprint2) {
|
|
|
40258
40373
|
} catch {
|
|
40259
40374
|
throw new Error("thread/list cursor is invalid");
|
|
40260
40375
|
}
|
|
40261
|
-
if (!
|
|
40376
|
+
if (!isRecord10(decoded) || decoded.formatVersion !== 1 || !Number.isSafeInteger(decoded.offset) || decoded.offset <= 0) {
|
|
40262
40377
|
throw new Error("thread/list cursor is invalid");
|
|
40263
40378
|
}
|
|
40264
40379
|
if (decoded.queryFingerprint !== queryFingerprint2) {
|
|
@@ -40325,7 +40440,7 @@ function decodeThreadMetadataUpdateRequest(request) {
|
|
|
40325
40440
|
if (daybreakEnabled !== null)
|
|
40326
40441
|
decoded.daybreakEnabled = daybreakEnabled;
|
|
40327
40442
|
if (params.gitInfo !== void 0 && params.gitInfo !== null) {
|
|
40328
|
-
if (!
|
|
40443
|
+
if (!isRecord10(params.gitInfo)) {
|
|
40329
40444
|
throw new Error("thread/metadata/update params.gitInfo must be an object or null");
|
|
40330
40445
|
}
|
|
40331
40446
|
const gitInfo = {};
|
|
@@ -40345,10 +40460,10 @@ function decodeThreadMetadataUpdateRequest(request) {
|
|
|
40345
40460
|
return decoded;
|
|
40346
40461
|
}
|
|
40347
40462
|
function observeDeletedProject(value2) {
|
|
40348
|
-
if (!
|
|
40463
|
+
if (!isRecord10(value2) || value2.method !== "project/changed" || "id" in value2)
|
|
40349
40464
|
return null;
|
|
40350
40465
|
const params = value2.params;
|
|
40351
|
-
if (!
|
|
40466
|
+
if (!isRecord10(params) || params.changeType !== "deleted")
|
|
40352
40467
|
return null;
|
|
40353
40468
|
return typeof params.projectId === "string" && params.projectId.length > 0 ? params.projectId : null;
|
|
40354
40469
|
}
|
|
@@ -40360,7 +40475,7 @@ function optionalCursor(value2, name) {
|
|
|
40360
40475
|
return value2;
|
|
40361
40476
|
}
|
|
40362
40477
|
function decodeOfficialThreadListPage(value2) {
|
|
40363
|
-
if (!
|
|
40478
|
+
if (!isRecord10(value2) || !Array.isArray(value2.data) || value2.data.some((row) => !isRecord10(row))) {
|
|
40364
40479
|
throw new Error("Official thread/list response is invalid");
|
|
40365
40480
|
}
|
|
40366
40481
|
return {
|
|
@@ -40919,9 +41034,100 @@ function firstUserMessagePreview(turns) {
|
|
|
40919
41034
|
}
|
|
40920
41035
|
|
|
40921
41036
|
// packages/host-runtime/src/external-subagent-threads.ts
|
|
40922
|
-
import { createHash as
|
|
41037
|
+
import { createHash as createHash7, randomUUID as randomUUID7 } from "node:crypto";
|
|
41038
|
+
|
|
41039
|
+
// packages/host-runtime/src/external-thread-side-chat.ts
|
|
41040
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
41041
|
+
|
|
41042
|
+
// packages/host-runtime/src/desktop-rpc.ts
|
|
41043
|
+
function isRecord11(value2) {
|
|
41044
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
41045
|
+
}
|
|
41046
|
+
function errorMessage2(error51) {
|
|
41047
|
+
return error51 instanceof Error ? error51.message : String(error51);
|
|
41048
|
+
}
|
|
41049
|
+
function rpcEnvelope(request, value2) {
|
|
41050
|
+
return {
|
|
41051
|
+
...request.jsonrpc === "2.0" ? { jsonrpc: "2.0" } : {},
|
|
41052
|
+
id: request.id,
|
|
41053
|
+
...value2
|
|
41054
|
+
};
|
|
41055
|
+
}
|
|
41056
|
+
function rpcError(request, code, message2) {
|
|
41057
|
+
return rpcEnvelope(request, { error: { code, message: message2 } });
|
|
41058
|
+
}
|
|
41059
|
+
function routingParams(request) {
|
|
41060
|
+
return isRecord11(request.params) ? request.params : {};
|
|
41061
|
+
}
|
|
41062
|
+
|
|
41063
|
+
// packages/host-runtime/src/external-thread-side-chat.ts
|
|
41064
|
+
async function holdInjectedItems(input) {
|
|
41065
|
+
if (input.record.subagent) {
|
|
41066
|
+
return {
|
|
41067
|
+
code: -32076,
|
|
41068
|
+
message: "External Subagent Thread does not support thread/inject_items"
|
|
41069
|
+
};
|
|
41070
|
+
}
|
|
41071
|
+
let texts;
|
|
41072
|
+
try {
|
|
41073
|
+
texts = decodeThreadInjectItemsRequest(input.request)?.texts ?? [];
|
|
41074
|
+
} catch (error51) {
|
|
41075
|
+
return { code: -32602, message: errorMessage2(error51) };
|
|
41076
|
+
}
|
|
41077
|
+
try {
|
|
41078
|
+
const record7 = await input.repository.appendPendingInjectedText(
|
|
41079
|
+
input.record.hostThreadId,
|
|
41080
|
+
texts
|
|
41081
|
+
);
|
|
41082
|
+
const live = input.runtime.get(record7.hostThreadId);
|
|
41083
|
+
if (live) live.record = record7;
|
|
41084
|
+
return null;
|
|
41085
|
+
} catch (error51) {
|
|
41086
|
+
return { code: -32081, message: `Injected items could not be saved: ${errorMessage2(error51)}` };
|
|
41087
|
+
}
|
|
41088
|
+
}
|
|
41089
|
+
function sha256(text4) {
|
|
41090
|
+
return createHash6("sha256").update(text4, "utf8").digest("hex");
|
|
41091
|
+
}
|
|
41092
|
+
function withInjectedText(held, text4) {
|
|
41093
|
+
const pending = held?.pendingInjectedText;
|
|
41094
|
+
const released = held?.releasedInjectedTexts ?? 0;
|
|
41095
|
+
if (!pending?.length) return { text: text4, through: released };
|
|
41096
|
+
const prefix = `${pending.join("\n\n")}
|
|
41097
|
+
|
|
41098
|
+
`;
|
|
41099
|
+
return {
|
|
41100
|
+
text: `${prefix}${text4}`,
|
|
41101
|
+
through: released + pending.length,
|
|
41102
|
+
prefix: { length: prefix.length, sha256: sha256(prefix) }
|
|
41103
|
+
};
|
|
41104
|
+
}
|
|
41105
|
+
async function releaseInjectedText(input) {
|
|
41106
|
+
if (!input.injected.prefix) return;
|
|
41107
|
+
input.thread.record = await input.repository.consumePendingInjectedText(
|
|
41108
|
+
input.thread.id,
|
|
41109
|
+
input.injected.through,
|
|
41110
|
+
{ hostTurnId: input.turnId, ...input.injected.prefix }
|
|
41111
|
+
);
|
|
41112
|
+
}
|
|
41113
|
+
function withoutInjectedText(input, prefix) {
|
|
41114
|
+
const first = input[0];
|
|
41115
|
+
if (!prefix || first?.type !== "text" || first.text.length < prefix.length) return input;
|
|
41116
|
+
if (sha256(first.text.slice(0, prefix.length)) !== prefix.sha256) return input;
|
|
41117
|
+
return [{ ...first, text: first.text.slice(prefix.length) }, ...input.slice(1)];
|
|
41118
|
+
}
|
|
41119
|
+
function ownTurns(record7, turns) {
|
|
41120
|
+
const count2 = record7.attachedToThreadId ? record7.inheritedTurnCount ?? 0 : 0;
|
|
41121
|
+
if (count2 === 0) return turns;
|
|
41122
|
+
const inherited = new Set(
|
|
41123
|
+
record7.turnMappings.slice(0, count2).map(({ hostTurnId }) => hostTurnId)
|
|
41124
|
+
);
|
|
41125
|
+
return turns.filter((turn) => !inherited.has(String(turn.id)));
|
|
41126
|
+
}
|
|
41127
|
+
|
|
41128
|
+
// packages/host-runtime/src/external-subagent-threads.ts
|
|
40923
41129
|
function childCreateRequest(parent, nativeRef, id2) {
|
|
40924
|
-
const key =
|
|
41130
|
+
const key = createHash7("sha256").update(JSON.stringify([parent.hostThreadId, parent.harnessId, nativeRef.nativeSessionId, id2])).digest("hex");
|
|
40925
41131
|
return `subagent:${key}`;
|
|
40926
41132
|
}
|
|
40927
41133
|
function subagentMaterializer(store, parent, previousParent) {
|
|
@@ -41035,12 +41241,15 @@ async function projectExternalSnapshot(store, record7, snapshot2, previousParent
|
|
|
41035
41241
|
return { ...entry, item: { ...entry.item, subagents } };
|
|
41036
41242
|
})
|
|
41037
41243
|
);
|
|
41244
|
+
const injected = record7.injectedTurnPrefixes?.find(
|
|
41245
|
+
({ hostTurnId }) => hostTurnId === mapping.hostTurnId
|
|
41246
|
+
);
|
|
41038
41247
|
turns.push(
|
|
41039
41248
|
projectHistoricalTurn({
|
|
41040
41249
|
threadId: record7.hostThreadId,
|
|
41041
41250
|
turnId: mapping.hostTurnId,
|
|
41042
41251
|
cwd: record7.cwd,
|
|
41043
|
-
snapshot: { ...turn, items }
|
|
41252
|
+
snapshot: { ...turn, input: withoutInjectedText(turn.input, injected), items }
|
|
41044
41253
|
})
|
|
41045
41254
|
);
|
|
41046
41255
|
}
|
|
@@ -41143,6 +41352,12 @@ var ExternalThreadRepository = class {
|
|
|
41143
41352
|
setTransportModelId(hostThreadId, transportModelId) {
|
|
41144
41353
|
return this.store.setTransportModelId(hostThreadId, transportModelId);
|
|
41145
41354
|
}
|
|
41355
|
+
appendPendingInjectedText(hostThreadId, texts) {
|
|
41356
|
+
return this.store.appendPendingInjectedText(hostThreadId, texts);
|
|
41357
|
+
}
|
|
41358
|
+
consumePendingInjectedText(hostThreadId, through, prefix) {
|
|
41359
|
+
return this.store.consumePendingInjectedText(hostThreadId, through, prefix);
|
|
41360
|
+
}
|
|
41146
41361
|
setArchived(hostThreadId, archived) {
|
|
41147
41362
|
return this.store.setArchived(hostThreadId, archived);
|
|
41148
41363
|
}
|
|
@@ -41318,7 +41533,7 @@ var ExternalThreadRepository = class {
|
|
|
41318
41533
|
async #projectSnapshot(record7, snapshot2, previous) {
|
|
41319
41534
|
const turns = await projectExternalSnapshot(this.store, record7, snapshot2, previous);
|
|
41320
41535
|
return {
|
|
41321
|
-
record: await this.updatePreview(record7, turns, previous !== void 0),
|
|
41536
|
+
record: await this.updatePreview(record7, ownTurns(record7, turns), previous !== void 0),
|
|
41322
41537
|
turns
|
|
41323
41538
|
};
|
|
41324
41539
|
}
|
|
@@ -41335,6 +41550,8 @@ function createExternalThreadRecordInput(input) {
|
|
|
41335
41550
|
historyMode: input.historyMode,
|
|
41336
41551
|
...input.projectlessWorkspace ? { projectlessWorkspace: input.projectlessWorkspace } : {},
|
|
41337
41552
|
...input.forkSource ? { forkSource: input.forkSource } : {},
|
|
41553
|
+
...input.attachedToThreadId ? { attachedToThreadId: input.attachedToThreadId } : {},
|
|
41554
|
+
...input.inheritedTurnCount !== void 0 ? { inheritedTurnCount: input.inheritedTurnCount } : {},
|
|
41338
41555
|
...input.importSourceRef ? { importSourceRef: input.importSourceRef } : {},
|
|
41339
41556
|
...input.subagent ? { subagent: input.subagent } : {}
|
|
41340
41557
|
};
|
|
@@ -41362,7 +41579,7 @@ function externalThreadValue(input) {
|
|
|
41362
41579
|
const { record: record7 } = input;
|
|
41363
41580
|
const createdAt = Math.floor(Date.parse(record7.createdAt) / 1e3);
|
|
41364
41581
|
const updatedAt = Math.floor(Date.parse(record7.updatedAt) / 1e3);
|
|
41365
|
-
const previewText2 = record7.preview ?? firstUserMessagePreview(input.turns) ?? "";
|
|
41582
|
+
const previewText2 = record7.preview ?? (record7.attachedToThreadId ? void 0 : firstUserMessagePreview(input.turns)) ?? "";
|
|
41366
41583
|
return {
|
|
41367
41584
|
id: record7.hostThreadId,
|
|
41368
41585
|
sessionId: input.sessionId,
|
|
@@ -41394,7 +41611,9 @@ function externalThreadValue(input) {
|
|
|
41394
41611
|
originUrl: record7.gitInfo.originUrl ?? null,
|
|
41395
41612
|
sha: record7.gitInfo.sha ?? null
|
|
41396
41613
|
} : null,
|
|
41397
|
-
|
|
41614
|
+
// A Side Chat forked before its source completed a Turn has no fork boundary Turn.
|
|
41615
|
+
forkedFromId: record7.forkSource?.hostThreadId ?? record7.attachedToThreadId ?? null,
|
|
41616
|
+
...record7.attachedToThreadId ? { attachedToThreadId: record7.attachedToThreadId } : {},
|
|
41398
41617
|
...record7.importSourceRef && record7.nativeSessionRef && record7.importSourceRef.nativeSessionId !== record7.nativeSessionRef.nativeSessionId ? {
|
|
41399
41618
|
codexhostImportSource: {
|
|
41400
41619
|
harnessId: record7.importSourceRef.harnessId,
|
|
@@ -41490,6 +41709,8 @@ function includesExternalRecord(record7, query, byId, sectionId) {
|
|
|
41490
41709
|
if (record7.hostThreadId === query.ancestorThreadId || parentId !== query.ancestorThreadId)
|
|
41491
41710
|
return false;
|
|
41492
41711
|
}
|
|
41712
|
+
if (query.attachedToThreadId !== null ? record7.attachedToThreadId !== query.attachedToThreadId : record7.attachedToThreadId !== void 0 && !query.includeAttachedThreads)
|
|
41713
|
+
return false;
|
|
41493
41714
|
if (record7.archived !== query.archived) return false;
|
|
41494
41715
|
if (query.projectId !== void 0 && (record7.projectId ?? null) !== query.projectId) return false;
|
|
41495
41716
|
if (query.cwd !== null && !query.cwd.includes(record7.cwd)) return false;
|
|
@@ -42263,27 +42484,6 @@ var SkillLibrary = class {
|
|
|
42263
42484
|
}
|
|
42264
42485
|
};
|
|
42265
42486
|
|
|
42266
|
-
// packages/host-runtime/src/desktop-rpc.ts
|
|
42267
|
-
function isRecord10(value2) {
|
|
42268
|
-
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
42269
|
-
}
|
|
42270
|
-
function errorMessage2(error51) {
|
|
42271
|
-
return error51 instanceof Error ? error51.message : String(error51);
|
|
42272
|
-
}
|
|
42273
|
-
function rpcEnvelope(request, value2) {
|
|
42274
|
-
return {
|
|
42275
|
-
...request.jsonrpc === "2.0" ? { jsonrpc: "2.0" } : {},
|
|
42276
|
-
id: request.id,
|
|
42277
|
-
...value2
|
|
42278
|
-
};
|
|
42279
|
-
}
|
|
42280
|
-
function rpcError(request, code, message2) {
|
|
42281
|
-
return rpcEnvelope(request, { error: { code, message: message2 } });
|
|
42282
|
-
}
|
|
42283
|
-
function routingParams(request) {
|
|
42284
|
-
return isRecord10(request.params) ? request.params : {};
|
|
42285
|
-
}
|
|
42286
|
-
|
|
42287
42487
|
// packages/host-runtime/src/skill-library-host.ts
|
|
42288
42488
|
async function handleSkillsList(request, library, host) {
|
|
42289
42489
|
const parsed2 = skillsListParamsSchema.safeParse(request.params ?? {});
|
|
@@ -43330,20 +43530,20 @@ var CHECK_EVERY_MS = HOUR_MS;
|
|
|
43330
43530
|
var MISSING_AFTER_MS = 6 * HOUR_MS;
|
|
43331
43531
|
var FETCH_TIMEOUT_MS = 3e4;
|
|
43332
43532
|
var MINIMUM_PRICED_MODELS = 1e3;
|
|
43333
|
-
function
|
|
43533
|
+
function isRecord12(value2) {
|
|
43334
43534
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
43335
43535
|
}
|
|
43336
43536
|
function price(value2) {
|
|
43337
43537
|
return typeof value2 === "number" && Number.isFinite(value2) && value2 >= 0 ? value2 : null;
|
|
43338
43538
|
}
|
|
43339
43539
|
function compactModelsDev(api) {
|
|
43340
|
-
if (!
|
|
43540
|
+
if (!isRecord12(api)) throw new Error("models.dev catalog must be an object");
|
|
43341
43541
|
const providers = {};
|
|
43342
43542
|
let count2 = 0;
|
|
43343
43543
|
for (const [providerId, provider] of Object.entries(api)) {
|
|
43344
|
-
if (!
|
|
43544
|
+
if (!isRecord12(provider) || !isRecord12(provider.models)) continue;
|
|
43345
43545
|
for (const [modelId2, model2] of Object.entries(provider.models)) {
|
|
43346
|
-
if (!
|
|
43546
|
+
if (!isRecord12(model2) || !isRecord12(model2.cost)) continue;
|
|
43347
43547
|
const input = price(model2.cost.input);
|
|
43348
43548
|
const output = price(model2.cost.output);
|
|
43349
43549
|
if (input === null || output === null) continue;
|
|
@@ -43370,22 +43570,22 @@ function isEntry(value2) {
|
|
|
43370
43570
|
return value2.length < 5 || value2[4] === true || typeof value2[4] === "string";
|
|
43371
43571
|
}
|
|
43372
43572
|
function parseModelPriceTable(value2) {
|
|
43373
|
-
if (!
|
|
43573
|
+
if (!isRecord12(value2) || !isRecord12(value2.providers)) return null;
|
|
43374
43574
|
if (typeof value2.fetchedAtMs !== "number" || !Number.isSafeInteger(value2.fetchedAtMs)) {
|
|
43375
43575
|
return null;
|
|
43376
43576
|
}
|
|
43377
43577
|
for (const models of Object.values(value2.providers)) {
|
|
43378
|
-
if (!
|
|
43578
|
+
if (!isRecord12(models) || !Object.values(models).every(isEntry)) return null;
|
|
43379
43579
|
}
|
|
43380
43580
|
return value2;
|
|
43381
43581
|
}
|
|
43382
43582
|
function parseModelPriceOverrides(value2) {
|
|
43383
|
-
if (!
|
|
43583
|
+
if (!isRecord12(value2) || !isRecord12(value2.models)) {
|
|
43384
43584
|
throw new Error("Price overrides must contain a 'models' object");
|
|
43385
43585
|
}
|
|
43386
43586
|
const overrides = /* @__PURE__ */ new Map();
|
|
43387
43587
|
for (const [key, entry] of Object.entries(value2.models)) {
|
|
43388
|
-
if (key.length === 0 || !
|
|
43588
|
+
if (key.length === 0 || !isRecord12(entry)) {
|
|
43389
43589
|
throw new Error(`Price override '${key}' is invalid`);
|
|
43390
43590
|
}
|
|
43391
43591
|
for (const field2 of Object.keys(entry)) {
|
|
@@ -43741,7 +43941,7 @@ var ModelPriceCatalog = class {
|
|
|
43741
43941
|
function errorMessage3(error51) {
|
|
43742
43942
|
return error51 instanceof Error ? error51.message : String(error51);
|
|
43743
43943
|
}
|
|
43744
|
-
function
|
|
43944
|
+
function isRecord13(value2) {
|
|
43745
43945
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
43746
43946
|
}
|
|
43747
43947
|
async function readDocument(file2) {
|
|
@@ -43782,7 +43982,7 @@ async function updateModelPriceOverridesFile(file2, change) {
|
|
|
43782
43982
|
);
|
|
43783
43983
|
}
|
|
43784
43984
|
const document = current.document ?? { models: {} };
|
|
43785
|
-
const models =
|
|
43985
|
+
const models = isRecord13(document.models) ? document.models : {};
|
|
43786
43986
|
const { key, price: price2, previousKey } = change;
|
|
43787
43987
|
if (previousKey !== void 0 && !Object.hasOwn(models, previousKey)) {
|
|
43788
43988
|
throw new ModelPriceOverridesError(`Custom price '${previousKey}' no longer exists`);
|
|
@@ -43839,7 +44039,7 @@ async function handleModelPriceOverridesRequest(catalog, method, params) {
|
|
|
43839
44039
|
}
|
|
43840
44040
|
|
|
43841
44041
|
// packages/host-runtime/src/delegation-skill.ts
|
|
43842
|
-
import { createHash as
|
|
44042
|
+
import { createHash as createHash8, randomUUID as randomUUID13 } from "node:crypto";
|
|
43843
44043
|
import { mkdir as mkdir14, open as open11, readFile as readFile18, rename as rename14, rm as rm13, stat as stat9 } from "node:fs/promises";
|
|
43844
44044
|
import os7 from "node:os";
|
|
43845
44045
|
import path27 from "node:path";
|
|
@@ -43932,9 +44132,9 @@ judging or reporting its work.
|
|
|
43932
44132
|
Report the result returned by read or a completed wait, together with the target
|
|
43933
44133
|
agent, status, and a labeled task link. Keep internal tracking IDs in tool calls.
|
|
43934
44134
|
`;
|
|
43935
|
-
var CURRENT_DIGEST =
|
|
44135
|
+
var CURRENT_DIGEST = createHash8("sha256").update(CODEXHOST_DELEGATION_SKILL).digest("hex");
|
|
43936
44136
|
function digest(value2) {
|
|
43937
|
-
return
|
|
44137
|
+
return createHash8("sha256").update(value2).digest("hex");
|
|
43938
44138
|
}
|
|
43939
44139
|
function managedVersion(value2) {
|
|
43940
44140
|
const match = /^version:\s*(\d+)\s*$/mu.exec(value2);
|
|
@@ -44062,7 +44262,7 @@ function rewriteDelegationMentionText(text4) {
|
|
|
44062
44262
|
const { text: stripped, mentions } = stripDelegationMentions(text4);
|
|
44063
44263
|
return mentions.length === 0 ? text4 : appendInstruction(stripped, mentions);
|
|
44064
44264
|
}
|
|
44065
|
-
function
|
|
44265
|
+
function isRecord14(value2) {
|
|
44066
44266
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
44067
44267
|
}
|
|
44068
44268
|
function rewriteDelegationMentionInput(input, skill) {
|
|
@@ -44070,7 +44270,7 @@ function rewriteDelegationMentionInput(input, skill) {
|
|
|
44070
44270
|
const seen = /* @__PURE__ */ new Set();
|
|
44071
44271
|
let lastTextIndex = -1;
|
|
44072
44272
|
const rewritten = input.map((item, index) => {
|
|
44073
|
-
if (!
|
|
44273
|
+
if (!isRecord14(item) || item.type !== "text" || typeof item.text !== "string") return item;
|
|
44074
44274
|
lastTextIndex = index;
|
|
44075
44275
|
const result = stripDelegationMentions(item.text);
|
|
44076
44276
|
for (const mention of result.mentions) {
|
|
@@ -44082,14 +44282,14 @@ function rewriteDelegationMentionInput(input, skill) {
|
|
|
44082
44282
|
});
|
|
44083
44283
|
if (mentions.length === 0) return null;
|
|
44084
44284
|
const target2 = rewritten[lastTextIndex];
|
|
44085
|
-
if (
|
|
44285
|
+
if (isRecord14(target2) && typeof target2.text === "string") {
|
|
44086
44286
|
rewritten[lastTextIndex] = {
|
|
44087
44287
|
...target2,
|
|
44088
44288
|
text: appendInstruction(target2.text, mentions)
|
|
44089
44289
|
};
|
|
44090
44290
|
}
|
|
44091
44291
|
const hasSkill = rewritten.some(
|
|
44092
|
-
(item) =>
|
|
44292
|
+
(item) => isRecord14(item) && item.type === "skill" && item.name === skill?.name
|
|
44093
44293
|
);
|
|
44094
44294
|
if (skill && !hasSkill) rewritten.push({ type: "skill", name: skill.name, path: skill.path });
|
|
44095
44295
|
return rewritten;
|
|
@@ -44391,7 +44591,7 @@ var HarnessAccountInspectionCache = class {
|
|
|
44391
44591
|
};
|
|
44392
44592
|
|
|
44393
44593
|
// packages/host-runtime/src/app-server-host.ts
|
|
44394
|
-
import { createHash as
|
|
44594
|
+
import { createHash as createHash16, randomUUID as randomUUID25 } from "node:crypto";
|
|
44395
44595
|
import os9 from "node:os";
|
|
44396
44596
|
import path34 from "node:path";
|
|
44397
44597
|
|
|
@@ -44413,6 +44613,18 @@ async function executeExternalThreadFork(input) {
|
|
|
44413
44613
|
error: { code: -32602, message: "External Fork target cwd is invalid" }
|
|
44414
44614
|
};
|
|
44415
44615
|
}
|
|
44616
|
+
if (fork.attachToSource && source.record.historyMode !== "paginated") {
|
|
44617
|
+
return {
|
|
44618
|
+
ok: false,
|
|
44619
|
+
error: { code: -32602, message: "attachToSource requires a paginated parent" }
|
|
44620
|
+
};
|
|
44621
|
+
}
|
|
44622
|
+
if (fork.attachToSource && source.record.ephemeral) {
|
|
44623
|
+
return {
|
|
44624
|
+
ok: false,
|
|
44625
|
+
error: { code: -32602, message: "attachToSource requires a persistent parent" }
|
|
44626
|
+
};
|
|
44627
|
+
}
|
|
44416
44628
|
if (!source.session.capabilities.history.fork) {
|
|
44417
44629
|
return {
|
|
44418
44630
|
ok: false,
|
|
@@ -44430,6 +44642,9 @@ async function executeExternalThreadFork(input) {
|
|
|
44430
44642
|
if (refreshError) return { ok: false, error: refreshError };
|
|
44431
44643
|
}
|
|
44432
44644
|
const mappings = source.record.turnMappings;
|
|
44645
|
+
if ((fork.attachToSource || fork.ephemeral) && mappings.length === 0 && !fork.lastTurnId && !fork.beforeTurnId) {
|
|
44646
|
+
return forkWithoutHistory({ ...input, cwd: targetCwd });
|
|
44647
|
+
}
|
|
44433
44648
|
let boundaryIndex;
|
|
44434
44649
|
if (fork.lastTurnId) {
|
|
44435
44650
|
boundaryIndex = mappings.findIndex(({ hostTurnId }) => hostTurnId === fork.lastTurnId);
|
|
@@ -44475,7 +44690,9 @@ async function executeExternalThreadFork(input) {
|
|
|
44475
44690
|
forkSource: {
|
|
44476
44691
|
hostThreadId: source.id,
|
|
44477
44692
|
hostTurnId: boundary.hostTurnId
|
|
44478
|
-
}
|
|
44693
|
+
},
|
|
44694
|
+
// A persistent Side Chat: the source's history up to the boundary stays as context only.
|
|
44695
|
+
...fork.attachToSource ? { attachedToThreadId: source.id, inheritedTurnCount: boundaryIndex + 1 } : {}
|
|
44479
44696
|
})
|
|
44480
44697
|
);
|
|
44481
44698
|
} catch {
|
|
@@ -44540,7 +44757,7 @@ async function executeExternalThreadFork(input) {
|
|
|
44540
44757
|
);
|
|
44541
44758
|
const thread3 = externalThreadValue({
|
|
44542
44759
|
record: aligned.record,
|
|
44543
|
-
turns: aligned.turns,
|
|
44760
|
+
turns: ownTurns(aligned.record, aligned.turns),
|
|
44544
44761
|
sessionId: source.sessionId
|
|
44545
44762
|
});
|
|
44546
44763
|
const derived = runtime.register({
|
|
@@ -44568,6 +44785,91 @@ async function executeExternalThreadFork(input) {
|
|
|
44568
44785
|
};
|
|
44569
44786
|
}
|
|
44570
44787
|
}
|
|
44788
|
+
async function forkWithoutHistory(input) {
|
|
44789
|
+
const { source, fork, cwd, repository, runtime } = input;
|
|
44790
|
+
const adapter = input.adapters.get(source.harnessId);
|
|
44791
|
+
if (!adapter) {
|
|
44792
|
+
return {
|
|
44793
|
+
ok: false,
|
|
44794
|
+
error: { code: -32070, message: `External Harness '${source.harnessId}' is unavailable` }
|
|
44795
|
+
};
|
|
44796
|
+
}
|
|
44797
|
+
let record7;
|
|
44798
|
+
try {
|
|
44799
|
+
record7 = await repository.createProvisional(
|
|
44800
|
+
createExternalThreadRecordInput({
|
|
44801
|
+
harnessId: source.record.harnessId,
|
|
44802
|
+
cwd,
|
|
44803
|
+
transportModelId: source.transportModelId,
|
|
44804
|
+
ephemeral: fork.ephemeral ?? source.record.ephemeral,
|
|
44805
|
+
historyMode: source.record.historyMode,
|
|
44806
|
+
...fork.attachToSource ? { attachedToThreadId: source.id, inheritedTurnCount: 0 } : {}
|
|
44807
|
+
})
|
|
44808
|
+
);
|
|
44809
|
+
} catch {
|
|
44810
|
+
return {
|
|
44811
|
+
ok: false,
|
|
44812
|
+
error: { code: -32081, message: "External Fork could not be persisted" }
|
|
44813
|
+
};
|
|
44814
|
+
}
|
|
44815
|
+
let persisted2;
|
|
44816
|
+
try {
|
|
44817
|
+
persisted2 = decodeExternalTransportSelection(source.harnessId, source.transportModelId);
|
|
44818
|
+
} catch {
|
|
44819
|
+
persisted2 = null;
|
|
44820
|
+
}
|
|
44821
|
+
const state = source.stateObserver.state;
|
|
44822
|
+
const model2 = state.effectiveModel ?? source.requestedModel ?? persisted2?.model;
|
|
44823
|
+
const thinkingOptionId = state.effectiveThinkingOptionId ?? source.requestedThinkingOptionId ?? persisted2?.thinkingOptionId;
|
|
44824
|
+
const permissionModeId = state.effectivePermissionModeId ?? source.requestedPermissionModeId ?? persisted2?.permissionModeId;
|
|
44825
|
+
let opened;
|
|
44826
|
+
try {
|
|
44827
|
+
opened = await adapter.open({
|
|
44828
|
+
kind: "create",
|
|
44829
|
+
cwd,
|
|
44830
|
+
environment: {
|
|
44831
|
+
...input.environment ?? process.env,
|
|
44832
|
+
[DELEGATION_THREAD_ID_ENV]: record7.hostThreadId
|
|
44833
|
+
},
|
|
44834
|
+
...model2 ? { model: model2 } : {},
|
|
44835
|
+
...thinkingOptionId ? { thinkingOptionId } : {},
|
|
44836
|
+
...permissionModeId ? { permissionModeId } : {}
|
|
44837
|
+
});
|
|
44838
|
+
} catch {
|
|
44839
|
+
await repository.removeProvisional(record7.hostThreadId).catch(() => void 0);
|
|
44840
|
+
return { ok: false, error: { code: -32076, message: "External Thread fork failed" } };
|
|
44841
|
+
}
|
|
44842
|
+
if (!opened.ok) {
|
|
44843
|
+
await repository.removeProvisional(record7.hostThreadId).catch(() => void 0);
|
|
44844
|
+
return { ok: false, error: mapExternalThreadHarnessError(opened.error, "create") };
|
|
44845
|
+
}
|
|
44846
|
+
const session = opened.value;
|
|
44847
|
+
try {
|
|
44848
|
+
if (session.initialState.nativeRef) {
|
|
44849
|
+
record7 = await repository.commitNative(record7.hostThreadId, session.initialState.nativeRef);
|
|
44850
|
+
}
|
|
44851
|
+
const thread3 = externalThreadValue({ record: record7, turns: [], sessionId: record7.hostThreadId });
|
|
44852
|
+
const derived = runtime.register({
|
|
44853
|
+
record: record7,
|
|
44854
|
+
session,
|
|
44855
|
+
sessionId: record7.hostThreadId,
|
|
44856
|
+
thread: thread3,
|
|
44857
|
+
turns: [],
|
|
44858
|
+
...model2 ? { requestedModel: model2 } : {},
|
|
44859
|
+
...thinkingOptionId ? { requestedThinkingOptionId: thinkingOptionId } : {},
|
|
44860
|
+
...permissionModeId ? { requestedPermissionModeId: permissionModeId } : {}
|
|
44861
|
+
});
|
|
44862
|
+
return { ok: true, derived, thread: thread3, responseThread: thread3 };
|
|
44863
|
+
} catch {
|
|
44864
|
+
runtime.remove(record7.hostThreadId);
|
|
44865
|
+
await session.close().catch(() => void 0);
|
|
44866
|
+
await repository.removeProvisional(record7.hostThreadId).catch(() => void 0);
|
|
44867
|
+
return {
|
|
44868
|
+
ok: false,
|
|
44869
|
+
error: { code: -32081, message: "External Fork could not be persisted" }
|
|
44870
|
+
};
|
|
44871
|
+
}
|
|
44872
|
+
}
|
|
44571
44873
|
async function inheritSourceModel(source, session) {
|
|
44572
44874
|
let persisted2;
|
|
44573
44875
|
try {
|
|
@@ -44628,7 +44930,7 @@ async function settleExternalOutputFailure(thread3, error51, project2, diagnose)
|
|
|
44628
44930
|
}
|
|
44629
44931
|
|
|
44630
44932
|
// packages/host-runtime/src/harness-session-import.ts
|
|
44631
|
-
import { createHash as
|
|
44933
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
44632
44934
|
function fixedError(code, message2) {
|
|
44633
44935
|
return { code, message: message2 };
|
|
44634
44936
|
}
|
|
@@ -44835,7 +45137,7 @@ var HarnessSessionImporter = class {
|
|
|
44835
45137
|
ephemeral: false,
|
|
44836
45138
|
historyMode: "paginated",
|
|
44837
45139
|
importSourceRef: source.nativeRef,
|
|
44838
|
-
createRequestId: `session-import:${this.#harnessId}:${
|
|
45140
|
+
createRequestId: `session-import:${this.#harnessId}:${createHash9("sha256").update(source.nativeRef.nativeSessionId).digest("hex")}`
|
|
44839
45141
|
});
|
|
44840
45142
|
let provisional;
|
|
44841
45143
|
try {
|
|
@@ -45328,7 +45630,7 @@ async function executeCurrentLastTurnRollback(input) {
|
|
|
45328
45630
|
}
|
|
45329
45631
|
const thread3 = externalThreadValue({
|
|
45330
45632
|
record: aligned.record,
|
|
45331
|
-
turns: aligned.turns,
|
|
45633
|
+
turns: ownTurns(aligned.record, aligned.turns),
|
|
45332
45634
|
sessionId: current.sessionId
|
|
45333
45635
|
});
|
|
45334
45636
|
await runtime.replace(current, {
|
|
@@ -45364,6 +45666,13 @@ async function executeExternalThreadRollback(input) {
|
|
|
45364
45666
|
error: { code: -32080, message: "External Revert boundary is unavailable" }
|
|
45365
45667
|
};
|
|
45366
45668
|
}
|
|
45669
|
+
const inherited = derived.record.attachedToThreadId ? derived.record.inheritedTurnCount ?? 0 : 0;
|
|
45670
|
+
if (inherited > 0 && rollback.numTurns > derived.record.turnMappings.length - inherited) {
|
|
45671
|
+
return {
|
|
45672
|
+
ok: false,
|
|
45673
|
+
error: { code: -32602, message: "A Side Chat cannot undo the history it inherited" }
|
|
45674
|
+
};
|
|
45675
|
+
}
|
|
45367
45676
|
if (rollback.numTurns === 1 && derived.session.capabilities.history.rollbackLastTurn) {
|
|
45368
45677
|
return executeCurrentLastTurnRollback({
|
|
45369
45678
|
current: derived,
|
|
@@ -45494,7 +45803,7 @@ async function executeExternalThreadRollback(input) {
|
|
|
45494
45803
|
}
|
|
45495
45804
|
const thread3 = externalThreadValue({
|
|
45496
45805
|
record: aligned.record,
|
|
45497
|
-
turns: aligned.turns,
|
|
45806
|
+
turns: ownTurns(aligned.record, aligned.turns),
|
|
45498
45807
|
sessionId: derived.sessionId
|
|
45499
45808
|
});
|
|
45500
45809
|
await runtime.replace(derived, {
|
|
@@ -46416,7 +46725,8 @@ var ExternalThreadRuntime = class {
|
|
|
46416
46725
|
}
|
|
46417
46726
|
/** Persist first accepted input before replying, never on the output/token path. */
|
|
46418
46727
|
async capturePreview(thread3, turn) {
|
|
46419
|
-
|
|
46728
|
+
const inherited = thread3.record.attachedToThreadId ? thread3.record.inheritedTurnCount ?? 0 : 0;
|
|
46729
|
+
if (thread3.record.preview !== void 0 || thread3.record.turnMappings.length !== inherited || thread3.turns.length !== inherited)
|
|
46420
46730
|
return;
|
|
46421
46731
|
try {
|
|
46422
46732
|
thread3.record = await this.#repository.updatePreview(thread3.record, [turn]);
|
|
@@ -47153,15 +47463,15 @@ function sameWorkspace(left, right) {
|
|
|
47153
47463
|
}
|
|
47154
47464
|
|
|
47155
47465
|
// packages/host-runtime/src/harness-delegation-coordinator.ts
|
|
47156
|
-
import { createHash as
|
|
47466
|
+
import { createHash as createHash11, randomUUID as randomUUID16 } from "node:crypto";
|
|
47157
47467
|
import path30 from "node:path";
|
|
47158
47468
|
|
|
47159
47469
|
// packages/host-runtime/src/delegation-snapshot.ts
|
|
47160
|
-
import { createHash as
|
|
47470
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
47161
47471
|
var CURSOR_PREFIX = "codexhost:thread-messages:v1:";
|
|
47162
47472
|
var DEFAULT_MESSAGE_LIMIT = 25;
|
|
47163
47473
|
var MAX_MESSAGE_LIMIT = 100;
|
|
47164
|
-
function
|
|
47474
|
+
function isRecord15(value2) {
|
|
47165
47475
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
47166
47476
|
}
|
|
47167
47477
|
function stringValue(value2) {
|
|
@@ -47175,12 +47485,12 @@ function threadTitle(thread3) {
|
|
|
47175
47485
|
function textFromUserItem(item) {
|
|
47176
47486
|
if (!Array.isArray(item.content)) return "";
|
|
47177
47487
|
return item.content.flatMap(
|
|
47178
|
-
(part) =>
|
|
47488
|
+
(part) => isRecord15(part) && part.type === "text" && typeof part.text === "string" ? [part.text] : []
|
|
47179
47489
|
).join("\n");
|
|
47180
47490
|
}
|
|
47181
47491
|
function threadStatus(value2, running) {
|
|
47182
47492
|
if (running) return "running";
|
|
47183
|
-
if (
|
|
47493
|
+
if (isRecord15(value2)) {
|
|
47184
47494
|
if (value2.type === "active") return "running";
|
|
47185
47495
|
}
|
|
47186
47496
|
return "completed";
|
|
@@ -47197,10 +47507,10 @@ function allVisibleMessages(turns) {
|
|
|
47197
47507
|
const turnId = stringValue(turn.id);
|
|
47198
47508
|
if (!turnId || !Array.isArray(turn.items)) continue;
|
|
47199
47509
|
const agentItems = turn.items.filter(
|
|
47200
|
-
(item) =>
|
|
47510
|
+
(item) => isRecord15(item) && item.type === "agentMessage"
|
|
47201
47511
|
);
|
|
47202
47512
|
for (const item of turn.items) {
|
|
47203
|
-
if (!
|
|
47513
|
+
if (!isRecord15(item)) continue;
|
|
47204
47514
|
const id2 = stringValue(item.id);
|
|
47205
47515
|
if (!id2) continue;
|
|
47206
47516
|
if (item.type === "userMessage") {
|
|
@@ -47216,7 +47526,7 @@ function allVisibleMessages(turns) {
|
|
|
47216
47526
|
return messages;
|
|
47217
47527
|
}
|
|
47218
47528
|
function cursorFingerprint(threadId3) {
|
|
47219
|
-
return
|
|
47529
|
+
return createHash10("sha256").update(threadId3).digest("hex");
|
|
47220
47530
|
}
|
|
47221
47531
|
function encodeCursor(threadId3, offset) {
|
|
47222
47532
|
const payload = JSON.stringify({ version: 1, fingerprint: cursorFingerprint(threadId3), offset });
|
|
@@ -47275,7 +47585,7 @@ function projectDelegationThreadSnapshot(input) {
|
|
|
47275
47585
|
const progress = latestTurnMessages.filter((message2) => message2.phase !== "final" && message2.text.trim()).map(({ id: id2, turnId, text: text4 }) => ({ id: id2, turnId, text: text4 }));
|
|
47276
47586
|
const result = input.running ? { availability: "pending" } : final ? { availability: "available", text: final.text } : {
|
|
47277
47587
|
availability: "unavailable",
|
|
47278
|
-
...
|
|
47588
|
+
...isRecord15(latestTurn?.error) && typeof latestTurn.error.message === "string" ? { message: latestTurn.error.message } : {}
|
|
47279
47589
|
};
|
|
47280
47590
|
const offset = options.view === "messages" ? decodeCursor2(input.threadId, options.cursor) : visible.length;
|
|
47281
47591
|
const page = options.view === "messages" ? [] : void 0;
|
|
@@ -47341,7 +47651,7 @@ function terminal(status2) {
|
|
|
47341
47651
|
return status2 === "completed" || status2 === "failed" || status2 === "interrupted";
|
|
47342
47652
|
}
|
|
47343
47653
|
function taskDigest(input) {
|
|
47344
|
-
return
|
|
47654
|
+
return createHash11("sha256").update(
|
|
47345
47655
|
JSON.stringify({
|
|
47346
47656
|
task: input.task,
|
|
47347
47657
|
cwd: path30.resolve(input.cwd),
|
|
@@ -50317,11 +50627,11 @@ function spawnOfficialAppServerConnection(input) {
|
|
|
50317
50627
|
}
|
|
50318
50628
|
|
|
50319
50629
|
// packages/host-runtime/src/account/codex-account-control.ts
|
|
50320
|
-
function
|
|
50630
|
+
function isRecord16(value2) {
|
|
50321
50631
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
50322
50632
|
}
|
|
50323
50633
|
function currentCodexAccountFromOfficialRead(result) {
|
|
50324
|
-
if (!
|
|
50634
|
+
if (!isRecord16(result) || !isRecord16(result.account) || result.account.type !== "chatgpt") {
|
|
50325
50635
|
return null;
|
|
50326
50636
|
}
|
|
50327
50637
|
const email3 = external_exports.string().email().max(320).safeParse(result.account.email);
|
|
@@ -50357,7 +50667,7 @@ import { randomUUID as randomUUID18 } from "node:crypto";
|
|
|
50357
50667
|
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
50358
50668
|
var INTERNAL_REQUEST_PREFIX = "codexhost:official:";
|
|
50359
50669
|
var MAX_RETIRED_IDS = 1024;
|
|
50360
|
-
function
|
|
50670
|
+
function isRecord17(value2) {
|
|
50361
50671
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
50362
50672
|
}
|
|
50363
50673
|
var OfficialRequestBroker = class {
|
|
@@ -50400,7 +50710,7 @@ var OfficialRequestBroker = class {
|
|
|
50400
50710
|
});
|
|
50401
50711
|
}
|
|
50402
50712
|
handle(value2) {
|
|
50403
|
-
if (!
|
|
50713
|
+
if (!isRecord17(value2) || typeof value2.id !== "string") return false;
|
|
50404
50714
|
const pending = this.#pending.get(value2.id);
|
|
50405
50715
|
if (!pending) return this.#retired.has(value2.id);
|
|
50406
50716
|
clearTimeout(pending.timeout);
|
|
@@ -51282,7 +51592,7 @@ var ClientChannelEvents = class {
|
|
|
51282
51592
|
import { readFile as readFile20 } from "node:fs/promises";
|
|
51283
51593
|
|
|
51284
51594
|
// packages/host-runtime/src/account/codex-credential-export.ts
|
|
51285
|
-
import { createHash as
|
|
51595
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
51286
51596
|
import { readFile as readFile19 } from "node:fs/promises";
|
|
51287
51597
|
import os8 from "node:os";
|
|
51288
51598
|
import path31 from "node:path";
|
|
@@ -51314,7 +51624,7 @@ async function readCodexCredentialFile(environment) {
|
|
|
51314
51624
|
const identity2 = `${t.account_id}:${claims.sub ?? ""}`;
|
|
51315
51625
|
return {
|
|
51316
51626
|
source: {
|
|
51317
|
-
id: `codex:${
|
|
51627
|
+
id: `codex:${createHash12("sha256").update(identity2).digest("hex")}`,
|
|
51318
51628
|
harnessId: "codex",
|
|
51319
51629
|
provider: "openai-codex",
|
|
51320
51630
|
label: typeof email3 === "string" && email3 ? email3 : "Codex"
|
|
@@ -51404,7 +51714,7 @@ var ClientChannelRequestError = class extends Error {
|
|
|
51404
51714
|
};
|
|
51405
51715
|
|
|
51406
51716
|
// packages/host-runtime/src/client-command-receipts.ts
|
|
51407
|
-
import { createHash as
|
|
51717
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
51408
51718
|
var ClientCommandReceipts = class {
|
|
51409
51719
|
entries = /* @__PURE__ */ new Map();
|
|
51410
51720
|
clientIdForTurn(threadId3, turnId) {
|
|
@@ -51419,7 +51729,7 @@ var ClientCommandReceipts = class {
|
|
|
51419
51729
|
Object.keys(value2).sort().map((key2) => [key2, value2[key2]])
|
|
51420
51730
|
) : value2
|
|
51421
51731
|
);
|
|
51422
|
-
const fingerprint2 =
|
|
51732
|
+
const fingerprint2 = createHash13("sha256").update(canonical2).digest("hex");
|
|
51423
51733
|
const existing = this.entries.get(key);
|
|
51424
51734
|
if (existing)
|
|
51425
51735
|
return existing.fingerprint === fingerprint2 ? existing.result : Promise.resolve({
|
|
@@ -51463,7 +51773,7 @@ var ClientCommandReceipts = class {
|
|
|
51463
51773
|
};
|
|
51464
51774
|
|
|
51465
51775
|
// packages/host-runtime/src/client-snapshot-compaction.ts
|
|
51466
|
-
import { createHash as
|
|
51776
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
51467
51777
|
var SNAPSHOT_TOOL_OUTPUT_LIMIT = 64 * 1024;
|
|
51468
51778
|
var SNAPSHOT_TOOL_OUTPUT_PREVIEW = 8 * 1024;
|
|
51469
51779
|
var OUTPUT_FIELDS = {
|
|
@@ -51507,7 +51817,7 @@ function truncateItem(item) {
|
|
|
51507
51817
|
return fields2.length ? { ...next, codexhostTruncated: { fields: fields2 } } : item;
|
|
51508
51818
|
}
|
|
51509
51819
|
function fingerprint(epoch, turn) {
|
|
51510
|
-
return
|
|
51820
|
+
return createHash14("sha256").update(epoch).update("\0").update(JSON.stringify(turn)).digest("base64url").slice(0, 32);
|
|
51511
51821
|
}
|
|
51512
51822
|
function compactClientSnapshot(snapshot2, options) {
|
|
51513
51823
|
const { knownTurns, truncateToolOutput } = options;
|
|
@@ -51539,11 +51849,11 @@ var OfficialThreadListError = class extends Error {
|
|
|
51539
51849
|
}
|
|
51540
51850
|
rpcError;
|
|
51541
51851
|
};
|
|
51542
|
-
function
|
|
51852
|
+
function isRecord18(value2) {
|
|
51543
51853
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
51544
51854
|
}
|
|
51545
51855
|
function officialThreadListPageFromResponse(response) {
|
|
51546
|
-
if (
|
|
51856
|
+
if (isRecord18(response.error)) {
|
|
51547
51857
|
if (!Number.isSafeInteger(response.error.code) || typeof response.error.message !== "string") {
|
|
51548
51858
|
throw new Error("Official thread/list error response is invalid");
|
|
51549
51859
|
}
|
|
@@ -52113,9 +52423,9 @@ async function readExternalWorkspaceSnapshot(environment, threads, placements, n
|
|
|
52113
52423
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
52114
52424
|
|
|
52115
52425
|
// packages/host-runtime/src/codex-runtime/native-thread-controls.ts
|
|
52116
|
-
var
|
|
52426
|
+
var isRecord19 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
52117
52427
|
function nativeThreadConfiguration(settings) {
|
|
52118
|
-
const profile =
|
|
52428
|
+
const profile = isRecord19(settings.activePermissionProfile) ? settings.activePermissionProfile : void 0;
|
|
52119
52429
|
const effort = settings.effort ?? settings.reasoningEffort;
|
|
52120
52430
|
return harnessConfigurationStateSchema.parse({
|
|
52121
52431
|
...typeof settings.model === "string" ? {
|
|
@@ -52140,10 +52450,10 @@ async function updateNativeThreadSettings(request, notifications, threadId3, set
|
|
|
52140
52450
|
reject(new Error("Official Codex stopped before confirming settings"));
|
|
52141
52451
|
return;
|
|
52142
52452
|
}
|
|
52143
|
-
if (!
|
|
52453
|
+
if (!isRecord19(value2) || value2.method !== "thread/settings/updated" || !isRecord19(value2.params) || value2.params.threadId !== threadId3)
|
|
52144
52454
|
return;
|
|
52145
52455
|
const applied = value2.params.threadSettings;
|
|
52146
|
-
if (!
|
|
52456
|
+
if (!isRecord19(applied) || typeof applied.model !== "string") {
|
|
52147
52457
|
reject(new Error("Codex returned invalid model settings"));
|
|
52148
52458
|
return;
|
|
52149
52459
|
}
|
|
@@ -52156,7 +52466,7 @@ async function updateNativeThreadSettings(request, notifications, threadId3, set
|
|
|
52156
52466
|
}
|
|
52157
52467
|
if ((applied.serviceTier ?? "default") !== (settings.serviceTier ?? "default")) return;
|
|
52158
52468
|
}
|
|
52159
|
-
if (settings.permissions !== void 0 && (!
|
|
52469
|
+
if (settings.permissions !== void 0 && (!isRecord19(applied.activePermissionProfile) || applied.activePermissionProfile.id !== settings.permissions))
|
|
52160
52470
|
return;
|
|
52161
52471
|
resolve3(applied);
|
|
52162
52472
|
};
|
|
@@ -52165,7 +52475,7 @@ async function updateNativeThreadSettings(request, notifications, threadId3, set
|
|
|
52165
52475
|
try {
|
|
52166
52476
|
const [, applied] = await Promise.all([
|
|
52167
52477
|
request("thread/settings/update", { threadId: threadId3, ...settings }).then((response) => {
|
|
52168
|
-
if (
|
|
52478
|
+
if (isRecord19(response.error)) throw new Error(String(response.error.message));
|
|
52169
52479
|
}),
|
|
52170
52480
|
confirmed
|
|
52171
52481
|
]);
|
|
@@ -52181,7 +52491,7 @@ function nativeSkills(result) {
|
|
|
52181
52491
|
const warnings = [];
|
|
52182
52492
|
if (!Array.isArray(result.data)) warnings.push("Codex returned an invalid Skills list");
|
|
52183
52493
|
for (const entry of Array.isArray(result.data) ? result.data : []) {
|
|
52184
|
-
if (!
|
|
52494
|
+
if (!isRecord19(entry) || !Array.isArray(entry.skills)) {
|
|
52185
52495
|
warnings.push("Codex returned an invalid Skills list entry");
|
|
52186
52496
|
continue;
|
|
52187
52497
|
}
|
|
@@ -52189,9 +52499,9 @@ function nativeSkills(result) {
|
|
|
52189
52499
|
warnings.push(`Codex Skill error: ${JSON.stringify(error51)}`);
|
|
52190
52500
|
}
|
|
52191
52501
|
for (const skill of entry.skills) {
|
|
52192
|
-
if (
|
|
52502
|
+
if (isRecord19(skill) && skill.enabled === false) continue;
|
|
52193
52503
|
const command = harnessCommandDescriptorSchema.safeParse(
|
|
52194
|
-
|
|
52504
|
+
isRecord19(skill) ? {
|
|
52195
52505
|
id: `skill:${skill.name}`,
|
|
52196
52506
|
invocation: `$${skill.name}`,
|
|
52197
52507
|
label: skill.name,
|
|
@@ -52200,7 +52510,7 @@ function nativeSkills(result) {
|
|
|
52200
52510
|
kind: "skill"
|
|
52201
52511
|
} : null
|
|
52202
52512
|
);
|
|
52203
|
-
if (!
|
|
52513
|
+
if (!isRecord19(skill) || skill.enabled !== true || typeof skill.name !== "string" || skill.name !== skill.name.trim() || typeof skill.path !== "string" || !skill.path.trim() || !command.success) {
|
|
52204
52514
|
warnings.push(`Skipped invalid Codex Skill: ${JSON.stringify(skill)}`);
|
|
52205
52515
|
continue;
|
|
52206
52516
|
}
|
|
@@ -52605,24 +52915,24 @@ ${JSON.stringify([
|
|
|
52605
52915
|
};
|
|
52606
52916
|
|
|
52607
52917
|
// packages/host-runtime/src/native-elicitation.ts
|
|
52608
|
-
var
|
|
52918
|
+
var isRecord20 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
52609
52919
|
var text = (value2) => typeof value2 === "string" && value2.length > 0 ? value2 : void 0;
|
|
52610
52920
|
function persistence(params) {
|
|
52611
|
-
const meta3 =
|
|
52921
|
+
const meta3 = isRecord20(params._meta) ? params._meta : {};
|
|
52612
52922
|
if (meta3.codex_approval_kind !== "mcp_tool_call") return [];
|
|
52613
52923
|
const values = Array.isArray(meta3.persist) ? meta3.persist : [meta3.persist];
|
|
52614
52924
|
return ["session", "always"].filter((scope) => values.includes(scope));
|
|
52615
52925
|
}
|
|
52616
52926
|
function nativeElicitationApproval(params) {
|
|
52617
52927
|
if (params.mode !== void 0 && params.mode !== "form") return void 0;
|
|
52618
|
-
const schema =
|
|
52619
|
-
if (!schema || schema.type !== "object" || !
|
|
52928
|
+
const schema = isRecord20(params.requestedSchema) ? params.requestedSchema : void 0;
|
|
52929
|
+
if (!schema || schema.type !== "object" || !isRecord20(schema.properties) || Object.keys(schema.properties).length !== 0 || schema.required !== void 0 && (!Array.isArray(schema.required) || schema.required.length !== 0))
|
|
52620
52930
|
return void 0;
|
|
52621
52931
|
const title = text(params.message);
|
|
52622
52932
|
if (!title) return void 0;
|
|
52623
|
-
const meta3 =
|
|
52933
|
+
const meta3 = isRecord20(params._meta) ? params._meta : {};
|
|
52624
52934
|
const tool = text(meta3.tool_name);
|
|
52625
|
-
const args =
|
|
52935
|
+
const args = isRecord20(meta3.tool_params) ? meta3.tool_params : void 0;
|
|
52626
52936
|
const description = [
|
|
52627
52937
|
text(meta3.reason),
|
|
52628
52938
|
text(meta3.subtitle),
|
|
@@ -52654,16 +52964,16 @@ function nativeElicitationApprovalResponse(params, value2) {
|
|
|
52654
52964
|
"Native elicitation approval response is invalid or selects an unavailable scope"
|
|
52655
52965
|
);
|
|
52656
52966
|
};
|
|
52657
|
-
if (!
|
|
52967
|
+
if (!isRecord20(value2) || Object.keys(value2).some((key) => !["action", "content", "_meta"].includes(key)))
|
|
52658
52968
|
return invalid();
|
|
52659
52969
|
const meta3 = value2._meta;
|
|
52660
|
-
if (meta3 != null && (!
|
|
52970
|
+
if (meta3 != null && (!isRecord20(meta3) || Object.keys(meta3).length !== 1 || !("persist" in meta3)))
|
|
52661
52971
|
return invalid();
|
|
52662
|
-
const scope =
|
|
52972
|
+
const scope = isRecord20(meta3) ? meta3.persist : void 0;
|
|
52663
52973
|
if (scope !== void 0 && (typeof scope !== "string" || !persistence(params).includes(scope)))
|
|
52664
52974
|
return invalid();
|
|
52665
52975
|
if (value2.action === "accept") {
|
|
52666
|
-
if (value2.content !== void 0 && (!
|
|
52976
|
+
if (value2.content !== void 0 && (!isRecord20(value2.content) || Object.keys(value2.content).length !== 0))
|
|
52667
52977
|
return invalid();
|
|
52668
52978
|
} else if (value2.action === "decline" || value2.action === "cancel") {
|
|
52669
52979
|
if (value2.content != null || scope !== void 0) return invalid();
|
|
@@ -52672,8 +52982,8 @@ function nativeElicitationApprovalResponse(params, value2) {
|
|
|
52672
52982
|
}
|
|
52673
52983
|
|
|
52674
52984
|
// packages/host-runtime/src/native-client-channel.ts
|
|
52675
|
-
var
|
|
52676
|
-
var isJsonObject2 = (value2) =>
|
|
52985
|
+
var isRecord21 = (value2) => typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
52986
|
+
var isJsonObject2 = (value2) => isRecord21(value2);
|
|
52677
52987
|
var requestKey2 = (id2) => JSON.stringify([typeof id2, id2]);
|
|
52678
52988
|
var NATIVE_REQUEST_PREFIX = "codexhost:native-interaction:";
|
|
52679
52989
|
function stringValue2(value2) {
|
|
@@ -52682,11 +52992,11 @@ function stringValue2(value2) {
|
|
|
52682
52992
|
function threadIdFromParams(params) {
|
|
52683
52993
|
const direct = stringValue2(params.threadId);
|
|
52684
52994
|
if (direct) return direct;
|
|
52685
|
-
const thread3 =
|
|
52995
|
+
const thread3 = isRecord21(params.thread) ? stringValue2(params.thread.id) : void 0;
|
|
52686
52996
|
if (thread3) return thread3;
|
|
52687
|
-
const turn =
|
|
52997
|
+
const turn = isRecord21(params.turn) ? stringValue2(params.turn.threadId) : void 0;
|
|
52688
52998
|
if (turn) return turn;
|
|
52689
|
-
const item =
|
|
52999
|
+
const item = isRecord21(params.item) ? stringValue2(params.item.threadId) : void 0;
|
|
52690
53000
|
return item;
|
|
52691
53001
|
}
|
|
52692
53002
|
function resultObject(reply2) {
|
|
@@ -52764,11 +53074,11 @@ function nativeQuestions(params) {
|
|
|
52764
53074
|
if (!Array.isArray(params.questions)) return void 0;
|
|
52765
53075
|
const questions = [];
|
|
52766
53076
|
params.questions.forEach((value2, index) => {
|
|
52767
|
-
if (!
|
|
53077
|
+
if (!isRecord21(value2)) return;
|
|
52768
53078
|
const id2 = stringValue2(value2.id) ?? `question-${index + 1}`;
|
|
52769
53079
|
const prompt = stringValue2(value2.question) ?? stringValue2(value2.header) ?? id2;
|
|
52770
53080
|
const options = Array.isArray(value2.options) ? value2.options.flatMap((option) => {
|
|
52771
|
-
if (!
|
|
53081
|
+
if (!isRecord21(option)) return [];
|
|
52772
53082
|
const optionValueText = optionValue(option.value) ?? optionValue(option.label) ?? optionValue(option.name);
|
|
52773
53083
|
if (!optionValueText) return [];
|
|
52774
53084
|
return [
|
|
@@ -52798,11 +53108,11 @@ function nativeQuestions(params) {
|
|
|
52798
53108
|
return { type: "question", questions };
|
|
52799
53109
|
}
|
|
52800
53110
|
function schemaQuestions(params) {
|
|
52801
|
-
const schema =
|
|
52802
|
-
if (!schema || !
|
|
53111
|
+
const schema = isRecord21(params.requestedSchema) ? params.requestedSchema : void 0;
|
|
53112
|
+
if (!schema || !isRecord21(schema.properties)) return void 0;
|
|
52803
53113
|
const properties = schema.properties;
|
|
52804
53114
|
for (const value2 of Object.values(properties)) {
|
|
52805
|
-
if (!
|
|
53115
|
+
if (!isRecord21(value2)) return void 0;
|
|
52806
53116
|
if (value2.type !== void 0 && value2.type !== "string") return void 0;
|
|
52807
53117
|
if (Array.isArray(value2.enum) && value2.enum.some((entry) => typeof entry !== "string"))
|
|
52808
53118
|
return void 0;
|
|
@@ -52812,7 +53122,7 @@ function schemaQuestions(params) {
|
|
|
52812
53122
|
);
|
|
52813
53123
|
const questions = [];
|
|
52814
53124
|
for (const [id2, value2] of Object.entries(properties)) {
|
|
52815
|
-
if (!
|
|
53125
|
+
if (!isRecord21(value2)) continue;
|
|
52816
53126
|
const prompt = stringValue2(value2.title) ?? stringValue2(value2.description) ?? id2;
|
|
52817
53127
|
const enumValues = Array.isArray(value2.enum) ? value2.enum.filter((entry) => typeof entry === "string") : [];
|
|
52818
53128
|
const question = enumValues.length ? {
|
|
@@ -52837,7 +53147,7 @@ function nativeInteraction(method, params) {
|
|
|
52837
53147
|
const approval = approvalInteraction(method, params);
|
|
52838
53148
|
if (approval) return approval;
|
|
52839
53149
|
if (method === "item/tool/requestUserInput") {
|
|
52840
|
-
if (Array.isArray(params.questions) && params.questions.some((question) =>
|
|
53150
|
+
if (Array.isArray(params.questions) && params.questions.some((question) => isRecord21(question) && question.isSecret === true))
|
|
52841
53151
|
return void 0;
|
|
52842
53152
|
const interaction = nativeQuestions(params);
|
|
52843
53153
|
return interaction ? { kind: "question", interaction } : void 0;
|
|
@@ -52846,7 +53156,7 @@ function nativeInteraction(method, params) {
|
|
|
52846
53156
|
if (params.mode !== void 0 && params.mode !== "form") return void 0;
|
|
52847
53157
|
const approval2 = nativeElicitationApproval(params);
|
|
52848
53158
|
if (approval2) return { kind: "approval", interaction: approval2 };
|
|
52849
|
-
const meta3 =
|
|
53159
|
+
const meta3 = isRecord21(params._meta) ? params._meta : {};
|
|
52850
53160
|
if (meta3.codex_approval_kind === "mcp_tool_call") return void 0;
|
|
52851
53161
|
const interaction = schemaQuestions(params);
|
|
52852
53162
|
return interaction ? { kind: "question", interaction } : void 0;
|
|
@@ -52855,11 +53165,11 @@ function nativeInteraction(method, params) {
|
|
|
52855
53165
|
return void 0;
|
|
52856
53166
|
}
|
|
52857
53167
|
function answersContent(value2) {
|
|
52858
|
-
if (!
|
|
52859
|
-
const answers =
|
|
53168
|
+
if (!isRecord21(value2)) return {};
|
|
53169
|
+
const answers = isRecord21(value2.answers) ? value2.answers : value2;
|
|
52860
53170
|
return Object.fromEntries(
|
|
52861
53171
|
Object.entries(answers).flatMap(([id2, answer]) => {
|
|
52862
|
-
if (
|
|
53172
|
+
if (isRecord21(answer) && Array.isArray(answer.answers)) {
|
|
52863
53173
|
return [[id2, answer.answers.length === 1 ? answer.answers[0] : answer.answers]];
|
|
52864
53174
|
}
|
|
52865
53175
|
return [[id2, answer]];
|
|
@@ -52867,14 +53177,14 @@ function answersContent(value2) {
|
|
|
52867
53177
|
);
|
|
52868
53178
|
}
|
|
52869
53179
|
function validMcpContent(params, content) {
|
|
52870
|
-
const schema =
|
|
52871
|
-
if (!schema || !
|
|
53180
|
+
const schema = isRecord21(params.requestedSchema) ? params.requestedSchema : void 0;
|
|
53181
|
+
if (!schema || !isRecord21(schema.properties)) return false;
|
|
52872
53182
|
const properties = schema.properties;
|
|
52873
53183
|
const required2 = Array.isArray(schema.required) ? schema.required.filter((entry) => typeof entry === "string") : [];
|
|
52874
53184
|
if (required2.some((key) => !Object.hasOwn(content, key))) return false;
|
|
52875
53185
|
for (const [key, value2] of Object.entries(content)) {
|
|
52876
53186
|
const definition = properties[key];
|
|
52877
|
-
if (!
|
|
53187
|
+
if (!isRecord21(definition)) return false;
|
|
52878
53188
|
if (definition.type === "string" && typeof value2 !== "string") return false;
|
|
52879
53189
|
if (definition.type === "number" && typeof value2 !== "number") return false;
|
|
52880
53190
|
if (definition.type === "integer" && (!Number.isInteger(value2) || typeof value2 !== "number"))
|
|
@@ -52887,14 +53197,14 @@ function validMcpContent(params, content) {
|
|
|
52887
53197
|
}
|
|
52888
53198
|
function validatedDecision(pending, value2) {
|
|
52889
53199
|
const allowed = availableDecisions(pending.params);
|
|
52890
|
-
if (!
|
|
53200
|
+
if (!isRecord21(value2)) throw new Error("Native approval response must be an object");
|
|
52891
53201
|
if (typeof value2.decision === "string") {
|
|
52892
53202
|
if (!allowed.includes(value2.decision))
|
|
52893
53203
|
throw new Error(`Native approval decision '${value2.decision}' is not available`);
|
|
52894
53204
|
return value2;
|
|
52895
53205
|
}
|
|
52896
53206
|
const action = typeof value2.action === "string" ? value2.action : void 0;
|
|
52897
|
-
const content =
|
|
53207
|
+
const content = isRecord21(value2.content) ? value2.content : void 0;
|
|
52898
53208
|
const actionId = content && stringValue2(content.actionId);
|
|
52899
53209
|
const decision = actionId ?? action;
|
|
52900
53210
|
if (!decision || !allowed.includes(decision))
|
|
@@ -52910,9 +53220,9 @@ function nativeResponse(pending, value2) {
|
|
|
52910
53220
|
}
|
|
52911
53221
|
if (pending.method === "mcpServer/elicitation/request" && pending.kind === "approval")
|
|
52912
53222
|
return nativeElicitationApprovalResponse(pending.params, value2);
|
|
52913
|
-
if (pending.method === "mcpServer/elicitation/request" &&
|
|
53223
|
+
if (pending.method === "mcpServer/elicitation/request" && isRecord21(value2)) {
|
|
52914
53224
|
if (typeof value2.action === "string") return value2;
|
|
52915
|
-
if (
|
|
53225
|
+
if (isRecord21(value2.answers)) {
|
|
52916
53226
|
const content = answersContent(value2);
|
|
52917
53227
|
if (!validMcpContent(pending.params, content))
|
|
52918
53228
|
throw new Error("Native elicitation response does not match its schema");
|
|
@@ -52922,7 +53232,7 @@ function nativeResponse(pending, value2) {
|
|
|
52922
53232
|
return value2;
|
|
52923
53233
|
}
|
|
52924
53234
|
function turnIdFromPage(turn) {
|
|
52925
|
-
if (!
|
|
53235
|
+
if (!isRecord21(turn) || typeof turn.id !== "string") return void 0;
|
|
52926
53236
|
return turn.status === "inProgress" ? turn.id : void 0;
|
|
52927
53237
|
}
|
|
52928
53238
|
var RESUME_BEFORE = /* @__PURE__ */ new Set([
|
|
@@ -52970,8 +53280,8 @@ var NativeClientChannel = class {
|
|
|
52970
53280
|
this.#knownThreads.add(threadId3);
|
|
52971
53281
|
}
|
|
52972
53282
|
observeMessage(value2) {
|
|
52973
|
-
if (!
|
|
52974
|
-
const params =
|
|
53283
|
+
if (!isRecord21(value2) || typeof value2.method !== "string") return;
|
|
53284
|
+
const params = isRecord21(value2.params) ? value2.params : {};
|
|
52975
53285
|
this.#items.observe(value2.method, params);
|
|
52976
53286
|
const asyncQuestionsChanged = this.#asyncQuestions.observe(value2.method, params);
|
|
52977
53287
|
const threadId3 = threadIdFromParams(params);
|
|
@@ -53053,7 +53363,7 @@ var NativeClientChannel = class {
|
|
|
53053
53363
|
const data = resultObject(reply2)?.data;
|
|
53054
53364
|
if (Array.isArray(data)) {
|
|
53055
53365
|
for (const item of data)
|
|
53056
|
-
if (
|
|
53366
|
+
if (isRecord21(item) && typeof item.id === "string") this.noteThread(item.id);
|
|
53057
53367
|
}
|
|
53058
53368
|
}
|
|
53059
53369
|
}
|
|
@@ -53269,11 +53579,11 @@ function classifyCreateRequestRoute(request) {
|
|
|
53269
53579
|
selectionSource: "official-model"
|
|
53270
53580
|
};
|
|
53271
53581
|
}
|
|
53272
|
-
function
|
|
53582
|
+
function isRecord22(value2) {
|
|
53273
53583
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
53274
53584
|
}
|
|
53275
53585
|
function classifyThreadPurpose(request) {
|
|
53276
|
-
return
|
|
53586
|
+
return isRecord22(request.params) && request.params.ephemeral === true ? "ephemeral" : "conversation";
|
|
53277
53587
|
}
|
|
53278
53588
|
var RequestRouteObservationTracker = class {
|
|
53279
53589
|
#nextCreateOrdinal = 0;
|
|
@@ -53298,13 +53608,13 @@ var RequestRouteObservationTracker = class {
|
|
|
53298
53608
|
this.#createByThreadId.set(threadId3, tracked);
|
|
53299
53609
|
}
|
|
53300
53610
|
bindOfficialResponse(response) {
|
|
53301
|
-
if (!
|
|
53611
|
+
if (!isRecord22(response) || !("id" in response)) return;
|
|
53302
53612
|
const tracked = this.#pendingByRequestId.get(response.id);
|
|
53303
53613
|
if (!tracked) return;
|
|
53304
53614
|
this.#pendingByRequestId.delete(response.id);
|
|
53305
53615
|
const result = response.result;
|
|
53306
|
-
const thread3 =
|
|
53307
|
-
if (
|
|
53616
|
+
const thread3 = isRecord22(result) ? result.thread : null;
|
|
53617
|
+
if (isRecord22(thread3) && typeof thread3.id === "string") {
|
|
53308
53618
|
this.#createByThreadId.set(thread3.id, tracked);
|
|
53309
53619
|
}
|
|
53310
53620
|
}
|
|
@@ -53409,7 +53719,7 @@ var OFFICIAL_METHODS = {
|
|
|
53409
53719
|
"codexhost/thread/usage/inspect": "host",
|
|
53410
53720
|
"codexhost/thread/inspect": "native"
|
|
53411
53721
|
};
|
|
53412
|
-
function
|
|
53722
|
+
function isRecord23(value2) {
|
|
53413
53723
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
53414
53724
|
}
|
|
53415
53725
|
var ClientChannelHost = class {
|
|
@@ -53429,9 +53739,9 @@ var ClientChannelHost = class {
|
|
|
53429
53739
|
}
|
|
53430
53740
|
/** Desktop-bound notifications about a client-visible Thread invalidate that Thread. */
|
|
53431
53741
|
observeDesktopMessage(value2) {
|
|
53432
|
-
if (
|
|
53742
|
+
if (isRecord23(value2) && typeof value2.method === "string" && isRecord23(value2.params)) {
|
|
53433
53743
|
const params = value2.params;
|
|
53434
|
-
const thread3 =
|
|
53744
|
+
const thread3 = isRecord23(params.thread) ? params.thread : void 0;
|
|
53435
53745
|
const id2 = typeof params.threadId === "string" ? params.threadId : thread3?.id;
|
|
53436
53746
|
if (typeof id2 === "string" && (this.#clientOwnedThreads.has(id2) || thread3?.modelProvider === "codexhost" || this.#host.loadedThread(id2))) {
|
|
53437
53747
|
this.#clientOwnedThreads.add(id2);
|
|
@@ -53452,7 +53762,7 @@ var ClientChannelHost = class {
|
|
|
53452
53762
|
if (!CLIENT_CHANNEL_METHODS.includes(method))
|
|
53453
53763
|
return { error: { code: -32601, message: "Client method is not available" } };
|
|
53454
53764
|
const parsed2 = jsonRpcRequestSchema.safeParse({ id: "client", method, params: input ?? {} });
|
|
53455
|
-
if (!parsed2.success || !
|
|
53765
|
+
if (!parsed2.success || !isRecord23(parsed2.data.params))
|
|
53456
53766
|
return { error: { code: -32602, message: "Invalid client parameters" } };
|
|
53457
53767
|
const params = parsed2.data.params;
|
|
53458
53768
|
if (method === "codexhost/voice/status")
|
|
@@ -53526,7 +53836,7 @@ var ClientChannelHost = class {
|
|
|
53526
53836
|
nativeParams = {
|
|
53527
53837
|
...params,
|
|
53528
53838
|
input: params.input.map((part) => {
|
|
53529
|
-
if (!
|
|
53839
|
+
if (!isRecord23(part) || part.type !== "text" || typeof part.text !== "string")
|
|
53530
53840
|
return part;
|
|
53531
53841
|
const text4 = restoreHarnessCommandMentions(part.text);
|
|
53532
53842
|
if (text4 !== part.text) skillName ??= /^\$([A-Za-z0-9._:-]+)(?:\s|$)/u.exec(text4)?.[1];
|
|
@@ -53535,20 +53845,20 @@ var ClientChannelHost = class {
|
|
|
53535
53845
|
};
|
|
53536
53846
|
if (["turn/start", "turn/steer", "thread/queue/add", "thread/queue/update"].includes(method) && typeof params.threadId === "string" && Array.isArray(nativeParams.input)) {
|
|
53537
53847
|
if (skillName && !nativeParams.input.some(
|
|
53538
|
-
(part) =>
|
|
53848
|
+
(part) => isRecord23(part) && part.type === "skill" && part.name === skillName
|
|
53539
53849
|
)) {
|
|
53540
53850
|
const read = await nativeChannel.request("thread/read", {
|
|
53541
53851
|
threadId: params.threadId,
|
|
53542
53852
|
includeTurns: false
|
|
53543
53853
|
});
|
|
53544
53854
|
if ("error" in read) return normalize(read);
|
|
53545
|
-
const thread3 =
|
|
53855
|
+
const thread3 = isRecord23(read.result) && isRecord23(read.result.thread) ? read.result.thread : {};
|
|
53546
53856
|
if (typeof thread3.cwd !== "string" || !thread3.cwd)
|
|
53547
53857
|
return { error: { code: -32078, message: "Codex Thread has no Skill workspace" } };
|
|
53548
53858
|
const listed = await nativeChannel.request("skills/list", { cwds: [thread3.cwd] });
|
|
53549
53859
|
if ("error" in listed) return normalize(listed);
|
|
53550
53860
|
const skill = nativeThreadSkillInput(
|
|
53551
|
-
|
|
53861
|
+
isRecord23(listed.result) ? listed.result : {},
|
|
53552
53862
|
skillName
|
|
53553
53863
|
);
|
|
53554
53864
|
if (!skill)
|
|
@@ -53559,14 +53869,14 @@ var ClientChannelHost = class {
|
|
|
53559
53869
|
}
|
|
53560
53870
|
}
|
|
53561
53871
|
if (["turn/start", "turn/steer", "thread/queue/add", "thread/queue/update"].includes(method) && Array.isArray(nativeParams.input)) {
|
|
53562
|
-
const text4 = nativeParams.input.filter((part) =>
|
|
53872
|
+
const text4 = nativeParams.input.filter((part) => isRecord23(part) && part.type === "text").map((part) => isRecord23(part) ? part.text : "").join("\n");
|
|
53563
53873
|
const command = /^\/(compact|review)(?:\s+([\s\S]*))?$/u.exec(text4.trim());
|
|
53564
53874
|
if (command?.[1] && typeof params.threadId === "string") {
|
|
53565
53875
|
if (method !== "turn/start" || params.delivery === "queue")
|
|
53566
53876
|
return {
|
|
53567
53877
|
error: { code: -32078, message: "Codex compact/review cannot be queued or steered" }
|
|
53568
53878
|
};
|
|
53569
|
-
if (!nativeParams.input.every((part) =>
|
|
53879
|
+
if (!nativeParams.input.every((part) => isRecord23(part) && part.type === "text"))
|
|
53570
53880
|
return {
|
|
53571
53881
|
error: { code: -32602, message: "Codex compact/review only accepts text arguments" }
|
|
53572
53882
|
};
|
|
@@ -53631,8 +53941,8 @@ var ClientChannelHost = class {
|
|
|
53631
53941
|
const queue = snapshot3.thread.nativeSendError ? { result: { data: [] } } : await this.#native.request("thread/queue/list", { threadId: threadId3 });
|
|
53632
53942
|
if ("error" in queue)
|
|
53633
53943
|
throw new ClientChannelRequestError(queue.error.code, queue.error.message);
|
|
53634
|
-
const items =
|
|
53635
|
-
(item) =>
|
|
53944
|
+
const items = isRecord23(queue.result) && Array.isArray(queue.result.data) ? queue.result.data.map(
|
|
53945
|
+
(item) => isRecord23(item) ? { ...item, clientUserMessageId: item.clientUserMessageId ?? item.id } : item
|
|
53636
53946
|
) : [];
|
|
53637
53947
|
for (const turn of snapshot3.turnsPage.data) {
|
|
53638
53948
|
const clientId = this.#clientReceipts.clientIdForTurn(threadId3, turn.id);
|
|
@@ -53708,7 +54018,7 @@ var ClientChannelHost = class {
|
|
|
53708
54018
|
if (typeof turn.id !== "string" || !Array.isArray(turn.items)) continue;
|
|
53709
54019
|
const clientId = this.#clientReceipts.clientIdForTurn(threadId3, turn.id);
|
|
53710
54020
|
const user = turn.items.find(
|
|
53711
|
-
(item) =>
|
|
54021
|
+
(item) => isRecord23(item) && item.type === "userMessage"
|
|
53712
54022
|
);
|
|
53713
54023
|
if (clientId && user && typeof user.clientId !== "string") user.clientId = clientId;
|
|
53714
54024
|
}
|
|
@@ -54416,13 +54726,14 @@ function externalThreadEmptyOfficialResult(method) {
|
|
|
54416
54726
|
}
|
|
54417
54727
|
|
|
54418
54728
|
// packages/host-runtime/src/desktop-thread-routing.ts
|
|
54419
|
-
function
|
|
54729
|
+
function isRecord24(value2) {
|
|
54420
54730
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
54421
54731
|
}
|
|
54422
54732
|
var EXPLICIT_EXTERNAL_THREAD_METHODS = /* @__PURE__ */ new Set([
|
|
54423
54733
|
"thread/archive",
|
|
54424
54734
|
"thread/delete",
|
|
54425
54735
|
"thread/fork",
|
|
54736
|
+
"thread/inject_items",
|
|
54426
54737
|
"thread/items/list",
|
|
54427
54738
|
"thread/metadata/update",
|
|
54428
54739
|
"thread/name/set",
|
|
@@ -54657,7 +54968,7 @@ var DesktopThreadRouting = class {
|
|
|
54657
54968
|
return true;
|
|
54658
54969
|
}
|
|
54659
54970
|
if (request.method === "thread/fork") {
|
|
54660
|
-
const params =
|
|
54971
|
+
const params = isRecord24(request.params) ? request.params : {};
|
|
54661
54972
|
const resolution = typeof params.threadId === "string" ? await this.#host.resolveExternalThread(params.threadId) : { kind: "official" };
|
|
54662
54973
|
if (resolution.kind === "error") {
|
|
54663
54974
|
await this.#host.writeJson(
|
|
@@ -54680,7 +54991,7 @@ var DesktopThreadRouting = class {
|
|
|
54680
54991
|
}
|
|
54681
54992
|
}
|
|
54682
54993
|
if (request.method === "thread/revert") {
|
|
54683
|
-
const params =
|
|
54994
|
+
const params = isRecord24(request.params) ? request.params : {};
|
|
54684
54995
|
const resolution = typeof params.threadId === "string" ? await this.#host.resolveExternalThread(params.threadId) : { kind: "official" };
|
|
54685
54996
|
if (resolution.kind === "error") {
|
|
54686
54997
|
await this.#host.writeJson(
|
|
@@ -54703,7 +55014,7 @@ var DesktopThreadRouting = class {
|
|
|
54703
55014
|
}
|
|
54704
55015
|
}
|
|
54705
55016
|
if (request.method === "thread/rollback") {
|
|
54706
|
-
const params =
|
|
55017
|
+
const params = isRecord24(request.params) ? request.params : {};
|
|
54707
55018
|
const resolution = typeof params.threadId === "string" ? await this.#host.resolveExternalThread(params.threadId) : { kind: "official" };
|
|
54708
55019
|
if (resolution.kind === "error") {
|
|
54709
55020
|
await this.#host.writeJson(
|
|
@@ -54863,7 +55174,18 @@ var DesktopThreadRouting = class {
|
|
|
54863
55174
|
return true;
|
|
54864
55175
|
}
|
|
54865
55176
|
}
|
|
54866
|
-
if (request.method === "thread/
|
|
55177
|
+
if (request.method === "thread/inject_items") {
|
|
55178
|
+
const threadId3 = routingParams(request).threadId;
|
|
55179
|
+
if (typeof threadId3 === "string") {
|
|
55180
|
+
const location = await this.#host.locateExternalThread(threadId3);
|
|
55181
|
+
if (await this.#host.writeResolutionError(request, location)) return true;
|
|
55182
|
+
if (location.kind === "external") {
|
|
55183
|
+
await this.#host.injectExternalThreadItems(request, location);
|
|
55184
|
+
return true;
|
|
55185
|
+
}
|
|
55186
|
+
}
|
|
55187
|
+
}
|
|
55188
|
+
if (request.method === "thread/backgroundTerminals/clean" && isRecord24(request.params) && typeof request.params.threadId === "string") {
|
|
54867
55189
|
const location = await this.#host.locateExternalThread(request.params.threadId);
|
|
54868
55190
|
if (await this.#host.writeResolutionError(request, location)) return true;
|
|
54869
55191
|
if (location.kind === "external") {
|
|
@@ -54871,7 +55193,7 @@ var DesktopThreadRouting = class {
|
|
|
54871
55193
|
return true;
|
|
54872
55194
|
}
|
|
54873
55195
|
}
|
|
54874
|
-
if (request.method === "thread/compact/start" &&
|
|
55196
|
+
if (request.method === "thread/compact/start" && isRecord24(request.params) && typeof request.params.threadId === "string") {
|
|
54875
55197
|
const location = await this.#host.locateExternalThread(request.params.threadId);
|
|
54876
55198
|
if (await this.#host.writeResolutionError(request, location)) return true;
|
|
54877
55199
|
if (location.kind === "external") {
|
|
@@ -54879,7 +55201,7 @@ var DesktopThreadRouting = class {
|
|
|
54879
55201
|
return true;
|
|
54880
55202
|
}
|
|
54881
55203
|
}
|
|
54882
|
-
if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) &&
|
|
55204
|
+
if (request.method.startsWith("thread/") && !EXPLICIT_EXTERNAL_THREAD_METHODS.has(request.method) && isRecord24(request.params) && typeof request.params.threadId === "string") {
|
|
54883
55205
|
const location = await this.#host.locateExternalThread(request.params.threadId);
|
|
54884
55206
|
if (await this.#host.writeResolutionError(request, location)) return true;
|
|
54885
55207
|
if (location.kind === "external") {
|
|
@@ -54993,7 +55315,7 @@ var ThreadListTiming = class {
|
|
|
54993
55315
|
};
|
|
54994
55316
|
|
|
54995
55317
|
// packages/host-runtime/src/usage-measurements-store.ts
|
|
54996
|
-
import { createHash as
|
|
55318
|
+
import { createHash as createHash15, randomUUID as randomUUID24 } from "node:crypto";
|
|
54997
55319
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
54998
55320
|
import { mkdir as mkdir16, readFile as readFile21, rename as rename15, rm as rm14, writeFile as writeFile12 } from "node:fs/promises";
|
|
54999
55321
|
import { createInterface } from "node:readline";
|
|
@@ -55015,7 +55337,7 @@ var UsageMeasurementsStore = class {
|
|
|
55015
55337
|
return join6(
|
|
55016
55338
|
this.directory,
|
|
55017
55339
|
"usage-measurements-v1",
|
|
55018
|
-
|
|
55340
|
+
createHash15("sha256").update(JSON.stringify([scope, sessionId])).digest("hex") + ".json"
|
|
55019
55341
|
);
|
|
55020
55342
|
}
|
|
55021
55343
|
state(file2) {
|
|
@@ -55402,14 +55724,14 @@ var OFFICIAL_PERMISSION_LABELS = /* @__PURE__ */ new Map([
|
|
|
55402
55724
|
function delay5(milliseconds) {
|
|
55403
55725
|
return new Promise((resolve3) => setTimeout(resolve3, milliseconds));
|
|
55404
55726
|
}
|
|
55405
|
-
function
|
|
55727
|
+
function isRecord25(value2) {
|
|
55406
55728
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
55407
55729
|
}
|
|
55408
55730
|
function officialThreadBusy(thread3) {
|
|
55409
|
-
if (thread3 &&
|
|
55731
|
+
if (thread3 && isRecord25(thread3.status) && thread3.status.type === "active") return true;
|
|
55410
55732
|
const turns = thread3 && Array.isArray(thread3.turns) ? thread3.turns : [];
|
|
55411
55733
|
const latestTurn = turns.at(-1);
|
|
55412
|
-
return
|
|
55734
|
+
return isRecord25(latestTurn) && (latestTurn.status === "inProgress" || latestTurn.status === "running");
|
|
55413
55735
|
}
|
|
55414
55736
|
var OFFICIAL_THREAD_MISSING = /no rollout found for thread id|thread not found|invalid thread id/i;
|
|
55415
55737
|
function officialThreadReadError(error51) {
|
|
@@ -55482,17 +55804,17 @@ function isHostQuestionRequestId(value2) {
|
|
|
55482
55804
|
return typeof value2 === "number" && Number.isSafeInteger(value2) && value2 >= HOST_QUESTION_REQUEST_ID_MIN && value2 <= HOST_QUESTION_REQUEST_ID_MAX;
|
|
55483
55805
|
}
|
|
55484
55806
|
function requestObject(request) {
|
|
55485
|
-
if (!
|
|
55807
|
+
if (!isRecord25(request.params)) throw new Error(`${request.method} params must be an object`);
|
|
55486
55808
|
return request.params;
|
|
55487
55809
|
}
|
|
55488
55810
|
function requestInput(params) {
|
|
55489
|
-
if (!Array.isArray(params.input) || params.input.some((item) => !
|
|
55811
|
+
if (!Array.isArray(params.input) || params.input.some((item) => !isRecord25(item)))
|
|
55490
55812
|
throw new Error("turn/start input must be an array of input objects");
|
|
55491
55813
|
return params.input;
|
|
55492
55814
|
}
|
|
55493
55815
|
function requestPresentationInput(params) {
|
|
55494
55816
|
if (params.presentationInput === void 0) return void 0;
|
|
55495
|
-
if (!Array.isArray(params.presentationInput) || params.presentationInput.some((item) => !
|
|
55817
|
+
if (!Array.isArray(params.presentationInput) || params.presentationInput.some((item) => !isRecord25(item)))
|
|
55496
55818
|
throw new Error("presentationInput must be an array of input objects");
|
|
55497
55819
|
return params.presentationInput;
|
|
55498
55820
|
}
|
|
@@ -55916,6 +56238,7 @@ var AppServerHost = class {
|
|
|
55916
56238
|
resumeExternalThread: (request, thread3, params, historyFresh) => this.#resumeExternalThread(request, thread3, params, historyFresh),
|
|
55917
56239
|
setExternalThreadName: (request, location, name) => this.#setExternalThreadName(request, location, name),
|
|
55918
56240
|
deleteExternalThread: (request, location) => this.#deleteExternalThread(request, location),
|
|
56241
|
+
injectExternalThreadItems: (request, location) => this.#injectExternalThreadItems(request, location),
|
|
55919
56242
|
cleanExternalBackgroundTerminals: (request, threadId3) => this.#cleanExternalBackgroundTerminals(request, threadId3),
|
|
55920
56243
|
startExternalCompaction: (request, threadId3) => this.#startExternalCompaction(request, threadId3)
|
|
55921
56244
|
});
|
|
@@ -56139,19 +56462,19 @@ var AppServerHost = class {
|
|
|
56139
56462
|
for (const resolve3 of waiters) resolve3();
|
|
56140
56463
|
}
|
|
56141
56464
|
#observeOfficialTurnStartResponse(value2) {
|
|
56142
|
-
if (!
|
|
56465
|
+
if (!isRecord25(value2) || !("id" in value2)) return;
|
|
56143
56466
|
const threadId3 = this.#pendingOfficialTurnStarts.get(value2.id);
|
|
56144
56467
|
if (!threadId3) return;
|
|
56145
56468
|
this.#pendingOfficialTurnStarts.delete(value2.id);
|
|
56146
|
-
const result =
|
|
56147
|
-
const turn = result &&
|
|
56469
|
+
const result = isRecord25(value2.result) ? value2.result : null;
|
|
56470
|
+
const turn = result && isRecord25(result.turn) ? result.turn : null;
|
|
56148
56471
|
if (turn && typeof turn.id === "string") {
|
|
56149
56472
|
this.#activeOfficialTurns.set(threadId3, turn.id);
|
|
56150
56473
|
}
|
|
56151
56474
|
this.#signalActiveWorkChanged();
|
|
56152
56475
|
}
|
|
56153
56476
|
#takeConsoleReply(value2) {
|
|
56154
|
-
if (!
|
|
56477
|
+
if (!isRecord25(value2) || typeof value2.id !== "string") return false;
|
|
56155
56478
|
const reply2 = this.#consoleReplies.get(value2.id);
|
|
56156
56479
|
if (!reply2) return value2.id.startsWith(this.#consoleRequestPrefix);
|
|
56157
56480
|
this.#consoleReplies.delete(value2.id);
|
|
@@ -56204,10 +56527,10 @@ var AppServerHost = class {
|
|
|
56204
56527
|
);
|
|
56205
56528
|
try {
|
|
56206
56529
|
const message2 = await reply2;
|
|
56207
|
-
if (
|
|
56530
|
+
if (isRecord25(message2) && "result" in message2) {
|
|
56208
56531
|
return { result: message2.result ?? null };
|
|
56209
56532
|
}
|
|
56210
|
-
const error51 =
|
|
56533
|
+
const error51 = isRecord25(message2) && isRecord25(message2.error) ? message2.error : void 0;
|
|
56211
56534
|
return {
|
|
56212
56535
|
error: {
|
|
56213
56536
|
code: typeof error51?.code === "number" ? error51.code : -32603,
|
|
@@ -56246,7 +56569,7 @@ var AppServerHost = class {
|
|
|
56246
56569
|
this.#diagnose(error51);
|
|
56247
56570
|
continue;
|
|
56248
56571
|
}
|
|
56249
|
-
if (
|
|
56572
|
+
if (isRecord25(parsed2) && parsed2.method === "initialized" && !("id" in parsed2)) {
|
|
56250
56573
|
continue;
|
|
56251
56574
|
}
|
|
56252
56575
|
if (await this.#handleDesktopApprovalResponse(parsed2)) continue;
|
|
@@ -56268,7 +56591,7 @@ var AppServerHost = class {
|
|
|
56268
56591
|
const options = this.#observedSessionUsage.requestOptions("initialize", params);
|
|
56269
56592
|
const nativeParams = options ? { ...params, ...options } : params;
|
|
56270
56593
|
const response = await this.#officialRuntime.initializeProtocol(nativeParams);
|
|
56271
|
-
if (!
|
|
56594
|
+
if (!isRecord25(response.error)) this.#observedSessionUsage.initialized(nativeParams);
|
|
56272
56595
|
await this.#writer.json({ ...response, id: request.id });
|
|
56273
56596
|
this.#nativeAccountObserver?.initialized(nativeGeneration);
|
|
56274
56597
|
} catch (error51) {
|
|
@@ -56276,7 +56599,7 @@ var AppServerHost = class {
|
|
|
56276
56599
|
}
|
|
56277
56600
|
continue;
|
|
56278
56601
|
}
|
|
56279
|
-
const threadId3 =
|
|
56602
|
+
const threadId3 = isRecord25(request.params) && typeof request.params.threadId === "string" ? request.params.threadId : void 0;
|
|
56280
56603
|
const queueThreadId = request.method === "codexhost/thread/usage/inspect" ? void 0 : threadId3;
|
|
56281
56604
|
this.#dispatchDesktopRequest(
|
|
56282
56605
|
() => this.#desktopRequests.run(
|
|
@@ -56325,7 +56648,7 @@ var AppServerHost = class {
|
|
|
56325
56648
|
for (const guard of this.#replyGuards.get(id2) ?? []) guard.answered = true;
|
|
56326
56649
|
}
|
|
56327
56650
|
#noteDesktopReply(value2) {
|
|
56328
|
-
if (
|
|
56651
|
+
if (isRecord25(value2) && "id" in value2 && !("method" in value2)) {
|
|
56329
56652
|
this.#markDesktopRequestAnswered(value2.id);
|
|
56330
56653
|
}
|
|
56331
56654
|
}
|
|
@@ -56335,7 +56658,7 @@ var AppServerHost = class {
|
|
|
56335
56658
|
}
|
|
56336
56659
|
async #handleDesktopRequest(request, frame, origin) {
|
|
56337
56660
|
if (this.#closeRequested) return;
|
|
56338
|
-
if (request.method === "thread/start" &&
|
|
56661
|
+
if (request.method === "thread/start" && isRecord25(request.params) && isRecord25(request.params.request)) {
|
|
56339
56662
|
const nested = {
|
|
56340
56663
|
id: request.id,
|
|
56341
56664
|
method: request.method,
|
|
@@ -56473,10 +56796,10 @@ var AppServerHost = class {
|
|
|
56473
56796
|
/** Native Codex Turns: turn `#` delegation chips into an explicit Skill-backed request. */
|
|
56474
56797
|
async #rewriteOfficialDelegationMentions(request, frame) {
|
|
56475
56798
|
if (request.method !== "turn/start" && request.method !== "turn/steer") return frame;
|
|
56476
|
-
if (!
|
|
56799
|
+
if (!isRecord25(request.params) || !Array.isArray(request.params.input)) return frame;
|
|
56477
56800
|
const input = request.params.input;
|
|
56478
56801
|
if (!input.some(
|
|
56479
|
-
(item) =>
|
|
56802
|
+
(item) => isRecord25(item) && typeof item.text === "string" && item.text.includes(DELEGATION_MENTION_PATH_PREFIX)
|
|
56480
56803
|
)) {
|
|
56481
56804
|
return frame;
|
|
56482
56805
|
}
|
|
@@ -56489,7 +56812,7 @@ var AppServerHost = class {
|
|
|
56489
56812
|
}
|
|
56490
56813
|
async #forwardOfficialNonRequest(value2, frame) {
|
|
56491
56814
|
if (this.#options.externalOnly) return;
|
|
56492
|
-
const response =
|
|
56815
|
+
const response = isRecord25(value2) ? value2 : null;
|
|
56493
56816
|
const request = response && (typeof response.id === "string" || typeof response.id === "number") ? this.#officialServerRequests.get(response.id) : null;
|
|
56494
56817
|
if (request !== void 0 && response) {
|
|
56495
56818
|
this.#officialServerRequests.delete(response.id);
|
|
@@ -56509,13 +56832,13 @@ var AppServerHost = class {
|
|
|
56509
56832
|
return;
|
|
56510
56833
|
}
|
|
56511
56834
|
try {
|
|
56512
|
-
const options =
|
|
56835
|
+
const options = isRecord25(request.params) ? this.#observedSessionUsage.requestOptions(request.method, request.params) : null;
|
|
56513
56836
|
if (options) {
|
|
56514
56837
|
const original = parseJsonFrame(frame);
|
|
56515
|
-
if (
|
|
56838
|
+
if (isRecord25(original))
|
|
56516
56839
|
frame = encodeJsonFrame({
|
|
56517
56840
|
...original,
|
|
56518
|
-
params: { ...
|
|
56841
|
+
params: { ...isRecord25(original.params) ? original.params : {}, ...options }
|
|
56519
56842
|
});
|
|
56520
56843
|
}
|
|
56521
56844
|
await this.#officialRuntime.sendFrame(frame);
|
|
@@ -56541,7 +56864,7 @@ var AppServerHost = class {
|
|
|
56541
56864
|
const observedAtMs = Date.now();
|
|
56542
56865
|
this.#observeOfficialTurnStartResponse(parsed2);
|
|
56543
56866
|
let forwarded = parsed2;
|
|
56544
|
-
if (
|
|
56867
|
+
if (isRecord25(parsed2) && typeof parsed2.method === "string" && "id" in parsed2) {
|
|
56545
56868
|
const originalId = parsed2.id;
|
|
56546
56869
|
if (typeof originalId === "string" || typeof originalId === "number") {
|
|
56547
56870
|
const forwardedId = `codexhost:official:${++this.#nextOfficialServerRequestId}`;
|
|
@@ -56549,7 +56872,7 @@ var AppServerHost = class {
|
|
|
56549
56872
|
forwarded = { ...parsed2, id: forwardedId };
|
|
56550
56873
|
}
|
|
56551
56874
|
}
|
|
56552
|
-
const accountScopedNotification =
|
|
56875
|
+
const accountScopedNotification = isRecord25(parsed2) && typeof parsed2.method === "string" && (parsed2.method === "account/updated" || parsed2.method.startsWith("account/rateLimits/"));
|
|
56553
56876
|
if (accountScopedNotification) {
|
|
56554
56877
|
if (parsed2.method === "account/updated") this.#officialRateLimits.reset(input.accountId);
|
|
56555
56878
|
}
|
|
@@ -56561,7 +56884,7 @@ var AppServerHost = class {
|
|
|
56561
56884
|
this.#diagnose(error51);
|
|
56562
56885
|
}
|
|
56563
56886
|
this.#routeObservationTracker.bindOfficialResponse(parsed2);
|
|
56564
|
-
const privateTelemetry =
|
|
56887
|
+
const privateTelemetry = isRecord25(parsed2) && typeof parsed2.method === "string" && !("id" in parsed2) && !this.#observedSessionUsage.shouldForwardNotification(parsed2);
|
|
56565
56888
|
if (!privateTelemetry) {
|
|
56566
56889
|
if (forwarded === parsed2) await this.#writer.frame(input.frame);
|
|
56567
56890
|
else await this.#writer.json(forwarded);
|
|
@@ -56593,7 +56916,7 @@ var AppServerHost = class {
|
|
|
56593
56916
|
async #requestClientNative(method, params) {
|
|
56594
56917
|
try {
|
|
56595
56918
|
const response = await this.#requestOfficial(method, params);
|
|
56596
|
-
if (
|
|
56919
|
+
if (isRecord25(response.error)) {
|
|
56597
56920
|
return {
|
|
56598
56921
|
error: {
|
|
56599
56922
|
code: typeof response.error.code === "number" ? response.error.code : -32603,
|
|
@@ -56605,7 +56928,7 @@ var AppServerHost = class {
|
|
|
56605
56928
|
} catch (error51) {
|
|
56606
56929
|
if (error51 instanceof OfficialAdmissionError)
|
|
56607
56930
|
return { error: { code: -32090, message: "Native Codex is unavailable" } };
|
|
56608
|
-
if (
|
|
56931
|
+
if (isRecord25(error51) && typeof error51.code === "number")
|
|
56609
56932
|
return { error: { code: error51.code, message: errorMessage2(error51) } };
|
|
56610
56933
|
return {
|
|
56611
56934
|
error: {
|
|
@@ -56657,10 +56980,10 @@ var AppServerHost = class {
|
|
|
56657
56980
|
}
|
|
56658
56981
|
}
|
|
56659
56982
|
async #observeOfficialTurnLifecycle(value2) {
|
|
56660
|
-
if (!
|
|
56983
|
+
if (!isRecord25(value2) || !isRecord25(value2.params)) return;
|
|
56661
56984
|
const params = value2.params;
|
|
56662
56985
|
if (value2.method === "turn/started" && typeof params.threadId === "string") {
|
|
56663
|
-
const turn =
|
|
56986
|
+
const turn = isRecord25(params.turn) ? params.turn : null;
|
|
56664
56987
|
if (turn && typeof turn.id === "string") {
|
|
56665
56988
|
this.#forgetPendingOfficialTurnStarts(params.threadId);
|
|
56666
56989
|
this.#activeOfficialTurns.set(params.threadId, turn.id);
|
|
@@ -56673,7 +56996,7 @@ var AppServerHost = class {
|
|
|
56673
56996
|
const delegation = await this.#repository.getDelegationByChild(
|
|
56674
56997
|
hostThreadIdSchema.parse(params.threadId)
|
|
56675
56998
|
);
|
|
56676
|
-
const turn =
|
|
56999
|
+
const turn = isRecord25(params.turn) ? params.turn : null;
|
|
56677
57000
|
const status2 = turn?.status === "failed" ? "failed" : turn?.status === "interrupted" || turn?.status === "cancelled" ? "interrupted" : "completed";
|
|
56678
57001
|
if (this.#pendingOfficialDelegationThreads.has(params.threadId)) {
|
|
56679
57002
|
this.#pendingOfficialTerminalStatuses.set(params.threadId, status2);
|
|
@@ -56694,8 +57017,8 @@ var AppServerHost = class {
|
|
|
56694
57017
|
if (parsed2.success && await this.#repository.find(parsed2.data) !== null) return true;
|
|
56695
57018
|
try {
|
|
56696
57019
|
const reply2 = await this.#requestOfficial("thread/read", { threadId: threadId3, includeTurns: false });
|
|
56697
|
-
const thread3 =
|
|
56698
|
-
return
|
|
57020
|
+
const thread3 = isRecord25(reply2.result) ? reply2.result.thread : void 0;
|
|
57021
|
+
return isRecord25(thread3) && thread3.id === threadId3;
|
|
56699
57022
|
} catch {
|
|
56700
57023
|
return false;
|
|
56701
57024
|
}
|
|
@@ -56718,9 +57041,9 @@ var AppServerHost = class {
|
|
|
56718
57041
|
}
|
|
56719
57042
|
async #readOfficialThreadMetadata(threadId3) {
|
|
56720
57043
|
const response = await this.#requestOfficial("thread/read", { threadId: threadId3, includeTurns: false });
|
|
56721
|
-
if (
|
|
56722
|
-
const result =
|
|
56723
|
-
const thread3 = result &&
|
|
57044
|
+
if (isRecord25(response.error)) return {};
|
|
57045
|
+
const result = isRecord25(response.result) ? response.result : null;
|
|
57046
|
+
const thread3 = result && isRecord25(result.thread) ? result.thread : null;
|
|
56724
57047
|
if (!thread3) return {};
|
|
56725
57048
|
const title = typeof thread3.name === "string" && thread3.name.trim() ? thread3.name : thread3.preview;
|
|
56726
57049
|
return {
|
|
@@ -56730,21 +57053,21 @@ var AppServerHost = class {
|
|
|
56730
57053
|
}
|
|
56731
57054
|
async #inspectOfficialDelegationTarget(input) {
|
|
56732
57055
|
const response = await this.#requestOfficial("model/list", {});
|
|
56733
|
-
if (
|
|
57056
|
+
if (isRecord25(response.error)) {
|
|
56734
57057
|
throw new DelegationControlError(
|
|
56735
57058
|
"DELEGATION_FAILED",
|
|
56736
57059
|
typeof response.error.message === "string" ? response.error.message : "Official Model catalog could not be read"
|
|
56737
57060
|
);
|
|
56738
57061
|
}
|
|
56739
|
-
const result =
|
|
57062
|
+
const result = isRecord25(response.result) ? response.result : null;
|
|
56740
57063
|
const data = result && Array.isArray(result.data) ? result.data : [];
|
|
56741
57064
|
const thinkingById = /* @__PURE__ */ new Map();
|
|
56742
57065
|
const models = data.flatMap((candidate) => {
|
|
56743
|
-
if (!
|
|
57066
|
+
if (!isRecord25(candidate) || typeof candidate.model !== "string" || !candidate.model.trim()) {
|
|
56744
57067
|
return [];
|
|
56745
57068
|
}
|
|
56746
57069
|
const supportedThinkingOptionIds = Array.isArray(candidate.supportedReasoningEfforts) ? candidate.supportedReasoningEfforts.flatMap((option) => {
|
|
56747
|
-
if (!
|
|
57070
|
+
if (!isRecord25(option) || typeof option.reasoningEffort !== "string" || !option.reasoningEffort.trim()) {
|
|
56748
57071
|
return [];
|
|
56749
57072
|
}
|
|
56750
57073
|
const id2 = harnessThinkingOptionIdSchema.safeParse(option.reasoningEffort);
|
|
@@ -56755,16 +57078,16 @@ var AppServerHost = class {
|
|
|
56755
57078
|
return [
|
|
56756
57079
|
{
|
|
56757
57080
|
ref: encodeOfficialCodexModelRef(candidate.model),
|
|
56758
|
-
...Array.isArray(candidate.serviceTiers) && candidate.serviceTiers.some((tier) =>
|
|
57081
|
+
...Array.isArray(candidate.serviceTiers) && candidate.serviceTiers.some((tier) => isRecord25(tier) && tier.id === "priority") ? { fastModel: encodeOfficialCodexModelRef(candidate.model, "priority") } : {},
|
|
56759
57082
|
label: typeof candidate.displayName === "string" && candidate.displayName.trim() ? candidate.displayName : candidate.model,
|
|
56760
57083
|
...supportedThinkingOptionIds.length > 0 ? { supportedThinkingOptionIds } : {}
|
|
56761
57084
|
}
|
|
56762
57085
|
];
|
|
56763
57086
|
});
|
|
56764
57087
|
const defaultEntry = data.find(
|
|
56765
|
-
(candidate) =>
|
|
57088
|
+
(candidate) => isRecord25(candidate) && candidate.isDefault === true
|
|
56766
57089
|
);
|
|
56767
|
-
const defaultModel =
|
|
57090
|
+
const defaultModel = isRecord25(defaultEntry) && typeof defaultEntry.model === "string" ? encodeOfficialCodexModelRef(defaultEntry.model) : void 0;
|
|
56768
57091
|
return {
|
|
56769
57092
|
harnessId: input.harnessId,
|
|
56770
57093
|
inspection: {
|
|
@@ -56794,7 +57117,7 @@ var AppServerHost = class {
|
|
|
56794
57117
|
throw new DelegationControlError("INVALID_ARGUMENT", "Official Model Ref is invalid");
|
|
56795
57118
|
}
|
|
56796
57119
|
const nativeSelection = requestedModel ? decodeOfficialCodexModelSelection(requestedModel) : void 0;
|
|
56797
|
-
const digest2 =
|
|
57120
|
+
const digest2 = createHash16("sha256").update(
|
|
56798
57121
|
JSON.stringify({
|
|
56799
57122
|
task: input.task,
|
|
56800
57123
|
cwd: input.cwd,
|
|
@@ -56866,8 +57189,8 @@ var AppServerHost = class {
|
|
|
56866
57189
|
ephemeral: false,
|
|
56867
57190
|
historyMode: "paginated"
|
|
56868
57191
|
});
|
|
56869
|
-
const startedResult =
|
|
56870
|
-
const thread3 = startedResult &&
|
|
57192
|
+
const startedResult = isRecord25(started.result) ? started.result : null;
|
|
57193
|
+
const thread3 = startedResult && isRecord25(startedResult.thread) ? startedResult.thread : null;
|
|
56871
57194
|
const threadId3 = thread3 && typeof thread3.id === "string" ? thread3.id : null;
|
|
56872
57195
|
if (!threadId3) throw new Error("Official thread/start returned no Thread identity");
|
|
56873
57196
|
this.#pendingOfficialDelegationThreads.add(threadId3);
|
|
@@ -56882,8 +57205,8 @@ var AppServerHost = class {
|
|
|
56882
57205
|
...nativeSelection,
|
|
56883
57206
|
...input.thinkingOptionId ? { effort: input.thinkingOptionId } : {}
|
|
56884
57207
|
});
|
|
56885
|
-
const turnResult =
|
|
56886
|
-
const turnValue = turnResult &&
|
|
57208
|
+
const turnResult = isRecord25(turn.result) ? turn.result : null;
|
|
57209
|
+
const turnValue = turnResult && isRecord25(turnResult.turn) ? turnResult.turn : null;
|
|
56887
57210
|
const parsedTurnId = turnValue && typeof turnValue.id === "string" ? turnValue.id : null;
|
|
56888
57211
|
if (!parsedTurnId) throw new Error("Official turn/start returned no Turn identity");
|
|
56889
57212
|
turnId = parsedTurnId;
|
|
@@ -56958,11 +57281,11 @@ var AppServerHost = class {
|
|
|
56958
57281
|
threadId: input.threadId,
|
|
56959
57282
|
includeTurns: true
|
|
56960
57283
|
});
|
|
56961
|
-
if (
|
|
56962
|
-
if (!
|
|
57284
|
+
if (isRecord25(current.error)) throw officialThreadReadError(current.error);
|
|
57285
|
+
if (!isRecord25(current.result)) {
|
|
56963
57286
|
throw new DelegationControlError("INTERNAL_ERROR", "Official Thread read returned no result");
|
|
56964
57287
|
}
|
|
56965
|
-
const currentThread =
|
|
57288
|
+
const currentThread = isRecord25(current.result.thread) ? current.result.thread : null;
|
|
56966
57289
|
if (officialThreadBusy(currentThread)) {
|
|
56967
57290
|
throw new DelegationControlError("THREAD_BUSY", "Thread already has an active Turn");
|
|
56968
57291
|
}
|
|
@@ -56970,14 +57293,14 @@ var AppServerHost = class {
|
|
|
56970
57293
|
threadId: input.threadId,
|
|
56971
57294
|
excludeTurns: true
|
|
56972
57295
|
});
|
|
56973
|
-
if (
|
|
57296
|
+
if (isRecord25(resumed.error) || !isRecord25(resumed.result)) {
|
|
56974
57297
|
throw new DelegationControlError(
|
|
56975
57298
|
"DELEGATION_FAILED",
|
|
56976
|
-
|
|
57299
|
+
isRecord25(resumed.error) && typeof resumed.error.message === "string" ? resumed.error.message : "Official Thread resume failed",
|
|
56977
57300
|
{ notStarted: true }
|
|
56978
57301
|
);
|
|
56979
57302
|
}
|
|
56980
|
-
const resumedThread =
|
|
57303
|
+
const resumedThread = isRecord25(resumed.result.thread) ? resumed.result.thread : null;
|
|
56981
57304
|
if (!resumedThread || resumedThread.id !== input.threadId) {
|
|
56982
57305
|
throw new DelegationControlError(
|
|
56983
57306
|
"DELEGATION_FAILED",
|
|
@@ -56988,7 +57311,7 @@ var AppServerHost = class {
|
|
|
56988
57311
|
if (officialThreadBusy(resumedThread)) {
|
|
56989
57312
|
throw new DelegationControlError("THREAD_BUSY", "Thread already has an active Turn");
|
|
56990
57313
|
}
|
|
56991
|
-
if (!
|
|
57314
|
+
if (!isRecord25(resumedThread.status) || resumedThread.status.type !== "idle") {
|
|
56992
57315
|
throw new DelegationControlError(
|
|
56993
57316
|
"DELEGATION_FAILED",
|
|
56994
57317
|
"Official Thread is not idle after resume",
|
|
@@ -56999,15 +57322,15 @@ var AppServerHost = class {
|
|
|
56999
57322
|
threadId: input.threadId,
|
|
57000
57323
|
input: [{ type: "text", text: input.message }]
|
|
57001
57324
|
});
|
|
57002
|
-
if (
|
|
57325
|
+
if (isRecord25(response.error)) {
|
|
57003
57326
|
throw new DelegationControlError(
|
|
57004
57327
|
"DELEGATION_FAILED",
|
|
57005
57328
|
typeof response.error.message === "string" ? response.error.message : "Turn start failed",
|
|
57006
57329
|
{ notStarted: true }
|
|
57007
57330
|
);
|
|
57008
57331
|
}
|
|
57009
|
-
const result =
|
|
57010
|
-
const turn = result &&
|
|
57332
|
+
const result = isRecord25(response.result) ? response.result : null;
|
|
57333
|
+
const turn = result && isRecord25(result.turn) ? result.turn : null;
|
|
57011
57334
|
const turnId = turn && typeof turn.id === "string" ? turn.id : null;
|
|
57012
57335
|
if (!turnId) throw new Error("Official turn/start returned no Turn identity");
|
|
57013
57336
|
this.#activeOfficialTurns.set(input.threadId, turnId);
|
|
@@ -57029,13 +57352,13 @@ var AppServerHost = class {
|
|
|
57029
57352
|
threadId: input.threadId,
|
|
57030
57353
|
includeTurns: true
|
|
57031
57354
|
});
|
|
57032
|
-
if (
|
|
57355
|
+
if (isRecord25(current.error) || !isRecord25(current.result)) {
|
|
57033
57356
|
throw new DelegationControlError("THREAD_NOT_FOUND", "Official Thread was not found");
|
|
57034
57357
|
}
|
|
57035
|
-
const currentThread =
|
|
57358
|
+
const currentThread = isRecord25(current.result.thread) ? current.result.thread : null;
|
|
57036
57359
|
const currentTurns = currentThread && Array.isArray(currentThread.turns) ? currentThread.turns : [];
|
|
57037
57360
|
const latestTurn = currentTurns.at(-1);
|
|
57038
|
-
if (
|
|
57361
|
+
if (isRecord25(latestTurn) && typeof latestTurn.id === "string" && (latestTurn.status === "inProgress" || latestTurn.status === "running")) {
|
|
57039
57362
|
turnId = latestTurn.id;
|
|
57040
57363
|
this.#activeOfficialTurns.set(input.threadId, turnId);
|
|
57041
57364
|
} else {
|
|
@@ -57046,7 +57369,7 @@ var AppServerHost = class {
|
|
|
57046
57369
|
threadId: input.threadId,
|
|
57047
57370
|
turnId
|
|
57048
57371
|
});
|
|
57049
|
-
if (
|
|
57372
|
+
if (isRecord25(response.error)) {
|
|
57050
57373
|
throw new DelegationControlError(
|
|
57051
57374
|
"DELEGATION_FAILED",
|
|
57052
57375
|
typeof response.error.message === "string" ? response.error.message : "Turn cancel failed"
|
|
@@ -57059,13 +57382,13 @@ var AppServerHost = class {
|
|
|
57059
57382
|
threadId: input.threadId,
|
|
57060
57383
|
includeTurns: true
|
|
57061
57384
|
});
|
|
57062
|
-
if (
|
|
57063
|
-
const result =
|
|
57064
|
-
const thread3 = result &&
|
|
57385
|
+
if (isRecord25(response.error)) throw officialThreadReadError(response.error);
|
|
57386
|
+
const result = isRecord25(response.result) ? response.result : null;
|
|
57387
|
+
const thread3 = result && isRecord25(result.thread) ? result.thread : null;
|
|
57065
57388
|
if (!thread3)
|
|
57066
57389
|
throw new DelegationControlError("INTERNAL_ERROR", "Official Thread read returned no Thread");
|
|
57067
|
-
const turns = Array.isArray(thread3.turns) ? thread3.turns.filter((turn) =>
|
|
57068
|
-
const running = this.#activeOfficialTurns.has(input.threadId) ||
|
|
57390
|
+
const turns = Array.isArray(thread3.turns) ? thread3.turns.filter((turn) => isRecord25(turn)) : [];
|
|
57391
|
+
const running = this.#activeOfficialTurns.has(input.threadId) || isRecord25(thread3.status) && thread3.status.type === "active";
|
|
57069
57392
|
const snapshot2 = projectDelegationThreadSnapshot({
|
|
57070
57393
|
threadId: input.threadId,
|
|
57071
57394
|
harnessId: "codex",
|
|
@@ -57114,7 +57437,7 @@ var AppServerHost = class {
|
|
|
57114
57437
|
threads: result.data.flatMap((entry) => {
|
|
57115
57438
|
if (typeof entry.id !== "string") return [];
|
|
57116
57439
|
const record7 = records.find((candidate) => candidate.hostThreadId === entry.id);
|
|
57117
|
-
const status2 =
|
|
57440
|
+
const status2 = isRecord25(entry.status) && entry.status.type === "active" ? "running" : "completed";
|
|
57118
57441
|
return [
|
|
57119
57442
|
rememberNativeListSeconds(
|
|
57120
57443
|
{
|
|
@@ -57376,7 +57699,7 @@ var AppServerHost = class {
|
|
|
57376
57699
|
const exists3 = await this.#requestOfficial("project/read", {
|
|
57377
57700
|
projectId: update.projectId
|
|
57378
57701
|
}).then(
|
|
57379
|
-
(response) => !
|
|
57702
|
+
(response) => !isRecord25(response.error) && isRecord25(response.result) && isRecord25(response.result.project) && response.result.project.id === update.projectId,
|
|
57380
57703
|
() => false
|
|
57381
57704
|
);
|
|
57382
57705
|
if (!exists3) {
|
|
@@ -57566,9 +57889,9 @@ var AppServerHost = class {
|
|
|
57566
57889
|
});
|
|
57567
57890
|
if (inspection2.status === "ready") {
|
|
57568
57891
|
const response = await this.#requestOfficial("permissionProfile/list", {});
|
|
57569
|
-
if (
|
|
57570
|
-
const profiles =
|
|
57571
|
-
(profile) =>
|
|
57892
|
+
if (isRecord25(response.error)) throw new Error(String(response.error.message));
|
|
57893
|
+
const profiles = isRecord25(response.result) && Array.isArray(response.result.data) ? response.result.data.filter(
|
|
57894
|
+
(profile) => isRecord25(profile) && profile.allowed === true
|
|
57572
57895
|
) : [];
|
|
57573
57896
|
const modes = profiles.map((profile) => ({
|
|
57574
57897
|
id: profile.id,
|
|
@@ -57859,8 +58182,8 @@ var AppServerHost = class {
|
|
|
57859
58182
|
const metadata2 = await this.#readOfficialThreadMetadata(params.data.threadId);
|
|
57860
58183
|
if (!metadata2.cwd) throw new Error("Codex Thread has no Skill workspace");
|
|
57861
58184
|
const response = await this.#requestOfficial("skills/list", { cwds: [metadata2.cwd] });
|
|
57862
|
-
if (
|
|
57863
|
-
catalog = nativeThreadCommands(
|
|
58185
|
+
if (isRecord25(response.error)) throw new Error(String(response.error.message));
|
|
58186
|
+
catalog = nativeThreadCommands(isRecord25(response.result) ? response.result : {});
|
|
57864
58187
|
} catch (error51) {
|
|
57865
58188
|
this.#diagnose(error51);
|
|
57866
58189
|
catalog = nativeThreadCommands({ data: [] });
|
|
@@ -57974,8 +58297,8 @@ var AppServerHost = class {
|
|
|
57974
58297
|
await this.#writer.json(rpcEnvelope(request, response));
|
|
57975
58298
|
return;
|
|
57976
58299
|
}
|
|
57977
|
-
const result =
|
|
57978
|
-
const turn =
|
|
58300
|
+
const result = isRecord25(response.result) ? response.result : {};
|
|
58301
|
+
const turn = isRecord25(result.turn) ? result.turn : {};
|
|
57979
58302
|
await this.#writer.json(
|
|
57980
58303
|
rpcEnvelope(request, {
|
|
57981
58304
|
result: {
|
|
@@ -58138,7 +58461,7 @@ var AppServerHost = class {
|
|
|
58138
58461
|
threadId: threadId3,
|
|
58139
58462
|
excludeTurns: true
|
|
58140
58463
|
});
|
|
58141
|
-
if (
|
|
58464
|
+
if (isRecord25(resumed.error)) {
|
|
58142
58465
|
await this.#writer.json(rpcEnvelope(request, { error: resumed.error }));
|
|
58143
58466
|
return;
|
|
58144
58467
|
}
|
|
@@ -58738,6 +59061,19 @@ var AppServerHost = class {
|
|
|
58738
59061
|
});
|
|
58739
59062
|
}
|
|
58740
59063
|
async #deleteExternalThread(request, location) {
|
|
59064
|
+
const attached = (await this.#repository.list()).find(
|
|
59065
|
+
({ attachedToThreadId, state }) => attachedToThreadId === location.record.hostThreadId && state === "ready"
|
|
59066
|
+
);
|
|
59067
|
+
if (attached) {
|
|
59068
|
+
await this.#writer.json(
|
|
59069
|
+
rpcError(
|
|
59070
|
+
request,
|
|
59071
|
+
-32602,
|
|
59072
|
+
`Cannot delete a Thread while attached Thread ${attached.hostThreadId} exists`
|
|
59073
|
+
)
|
|
59074
|
+
);
|
|
59075
|
+
return;
|
|
59076
|
+
}
|
|
58741
59077
|
try {
|
|
58742
59078
|
await this.#externalRuntime.deleteThread(location.record.hostThreadId);
|
|
58743
59079
|
} catch (error51) {
|
|
@@ -58854,10 +59190,10 @@ var AppServerHost = class {
|
|
|
58854
59190
|
...typeof params.serviceTier === "string" ? { serviceTier: params.serviceTier } : {}
|
|
58855
59191
|
});
|
|
58856
59192
|
try {
|
|
58857
|
-
if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !
|
|
59193
|
+
if (params.initialTurnsPage !== void 0 && params.initialTurnsPage !== null && !isRecord25(params.initialTurnsPage)) {
|
|
58858
59194
|
throw new ExternalHistoryRequestError("initialTurnsPage must be an object");
|
|
58859
59195
|
}
|
|
58860
|
-
const initialPageParams =
|
|
59196
|
+
const initialPageParams = isRecord25(params.initialTurnsPage) ? params.initialTurnsPage : null;
|
|
58861
59197
|
const initialTurnsPage = initialPageParams ? listExternalTurns(turns, initialPageParams) : null;
|
|
58862
59198
|
const paginated = thread3.record.historyMode === "paginated";
|
|
58863
59199
|
const turnsBackwardsCursor = paginated ? listExternalTurns(turns, { limit: 1, itemsView: "notLoaded" }).backwardsCursor : null;
|
|
@@ -58885,7 +59221,7 @@ var AppServerHost = class {
|
|
|
58885
59221
|
}
|
|
58886
59222
|
}
|
|
58887
59223
|
#externalHistoryTurns(thread3, forClient2 = false) {
|
|
58888
|
-
const turns = this.#withOpenBackgroundCommands(thread3, thread3.turns);
|
|
59224
|
+
const turns = this.#withOpenBackgroundCommands(thread3, ownTurns(thread3.record, thread3.turns));
|
|
58889
59225
|
if (!thread3.activeTurnId || forClient2 && thread3.ephemeralTurnIds.has(thread3.activeTurnId))
|
|
58890
59226
|
return turns;
|
|
58891
59227
|
const active2 = thread3.projectedTurns.get(thread3.activeTurnId);
|
|
@@ -58939,10 +59275,12 @@ var AppServerHost = class {
|
|
|
58939
59275
|
promise: Promise.resolve(),
|
|
58940
59276
|
resolve: () => void 0
|
|
58941
59277
|
});
|
|
59278
|
+
const stored = await this.#repository.find(thread3.id);
|
|
59279
|
+
const injected = withInjectedText(stored, text4);
|
|
58942
59280
|
const result = await thread3.session.execute({
|
|
58943
59281
|
type: "turn.start",
|
|
58944
59282
|
turnId,
|
|
58945
|
-
input: [{ type: "text", text:
|
|
59283
|
+
input: [{ type: "text", text: injected.text }]
|
|
58946
59284
|
});
|
|
58947
59285
|
if (!result.ok) {
|
|
58948
59286
|
thread3.running = false;
|
|
@@ -58952,10 +59290,29 @@ var AppServerHost = class {
|
|
|
58952
59290
|
this.#signalActiveWorkChanged();
|
|
58953
59291
|
throw new Error(result.error.message);
|
|
58954
59292
|
}
|
|
59293
|
+
await this.#releaseInjectedText(thread3, turnId, injected);
|
|
59294
|
+
}
|
|
59295
|
+
async #injectExternalThreadItems(request, location) {
|
|
59296
|
+
const error51 = await holdInjectedItems({
|
|
59297
|
+
request,
|
|
59298
|
+
record: location.record,
|
|
59299
|
+
repository: this.#repository,
|
|
59300
|
+
runtime: this.#externalRuntime
|
|
59301
|
+
});
|
|
59302
|
+
await this.#writer.json(
|
|
59303
|
+
error51 ? rpcError(request, error51.code, error51.message) : rpcEnvelope(request, { result: {} })
|
|
59304
|
+
);
|
|
59305
|
+
}
|
|
59306
|
+
async #releaseInjectedText(thread3, turnId, injected) {
|
|
59307
|
+
try {
|
|
59308
|
+
await releaseInjectedText({ thread: thread3, turnId, injected, repository: this.#repository });
|
|
59309
|
+
} catch (error51) {
|
|
59310
|
+
this.#diagnose(`Injected items could not be released: ${errorMessage2(error51)}`);
|
|
59311
|
+
}
|
|
58955
59312
|
}
|
|
58956
59313
|
async #startExternalTurn(request, thread3) {
|
|
58957
59314
|
const context = requestObject(request).additionalContext;
|
|
58958
|
-
if (
|
|
59315
|
+
if (isRecord25(context) && Object.hasOwn(context, THREAD_STEERING_CONTEXT_PARAM)) {
|
|
58959
59316
|
await this.#steerExternalTurn(request, thread3, true);
|
|
58960
59317
|
return;
|
|
58961
59318
|
}
|
|
@@ -59080,7 +59437,7 @@ var AppServerHost = class {
|
|
|
59080
59437
|
})
|
|
59081
59438
|
);
|
|
59082
59439
|
const lastTurn = thread3.turns.at(-1);
|
|
59083
|
-
if (thread3.projectedTerminalTurnId === lastTurn?.id && lastTurn?.status === "completed" &&
|
|
59440
|
+
if (thread3.projectedTerminalTurnId === lastTurn?.id && lastTurn?.status === "completed" && isRecord25(thread3.thread.status) && thread3.thread.status.type === "idle")
|
|
59084
59441
|
void this.#startNextQueuedExternalTurn(thread3);
|
|
59085
59442
|
return;
|
|
59086
59443
|
}
|
|
@@ -59248,7 +59605,7 @@ var AppServerHost = class {
|
|
|
59248
59605
|
try {
|
|
59249
59606
|
let params2 = requestObject(request);
|
|
59250
59607
|
const context = params2.additionalContext;
|
|
59251
|
-
if (
|
|
59608
|
+
if (isRecord25(context) && Object.hasOwn(context, THREAD_STEERING_CONTEXT_PARAM)) {
|
|
59252
59609
|
const marker = threadSteeringContextSchema.safeParse(
|
|
59253
59610
|
context[THREAD_STEERING_CONTEXT_PARAM]
|
|
59254
59611
|
);
|
|
@@ -59432,12 +59789,15 @@ var AppServerHost = class {
|
|
|
59432
59789
|
if (thread3.unsubmittedPrewarm && await this.#externalRuntime.submitPrewarm(thread3)) {
|
|
59433
59790
|
await this.#notifyExternalThreadStarted(thread3.thread);
|
|
59434
59791
|
}
|
|
59792
|
+
const stored = await this.#repository.find(thread3.id);
|
|
59793
|
+
const injected = withInjectedText(stored, rewriteDelegationMentionText(text4));
|
|
59435
59794
|
const result = await thread3.session.execute({
|
|
59436
59795
|
type: "turn.start",
|
|
59437
59796
|
turnId,
|
|
59438
|
-
input: [{ type: "text", text:
|
|
59797
|
+
input: [{ type: "text", text: injected.text }]
|
|
59439
59798
|
});
|
|
59440
59799
|
if (!result.ok) throw new ExternalSteerError(-32073, result.error.message);
|
|
59800
|
+
await this.#releaseInjectedText(thread3, turnId, injected);
|
|
59441
59801
|
await this.#externalRuntime.capturePreview(thread3, projection.projector.snapshotTurn());
|
|
59442
59802
|
return { turnId, turn: projection.projector.pendingTurn(), gate };
|
|
59443
59803
|
} catch (error51) {
|
|
@@ -59724,7 +60084,7 @@ var AppServerHost = class {
|
|
|
59724
60084
|
const previousItems = new Map(
|
|
59725
60085
|
child.turns.flatMap(
|
|
59726
60086
|
(turn) => Array.isArray(turn.items) ? turn.items.flatMap(
|
|
59727
|
-
(item) =>
|
|
60087
|
+
(item) => isRecord25(item) && typeof item.id === "string" ? [[item.id, JSON.stringify(item)]] : []
|
|
59728
60088
|
) : []
|
|
59729
60089
|
)
|
|
59730
60090
|
);
|
|
@@ -59737,7 +60097,7 @@ var AppServerHost = class {
|
|
|
59737
60097
|
for (const turn of child.turns) {
|
|
59738
60098
|
if (typeof turn.id !== "string" || !Array.isArray(turn.items)) continue;
|
|
59739
60099
|
const changedItems = turn.items.filter(
|
|
59740
|
-
(item) =>
|
|
60100
|
+
(item) => isRecord25(item) && typeof item.id === "string" && previousItems.get(item.id) !== JSON.stringify(item)
|
|
59741
60101
|
);
|
|
59742
60102
|
if (changedItems.length > 0) {
|
|
59743
60103
|
await this.#writer.json({
|
|
@@ -59869,7 +60229,7 @@ var AppServerHost = class {
|
|
|
59869
60229
|
}
|
|
59870
60230
|
}
|
|
59871
60231
|
async #handleDesktopApprovalResponse(value2) {
|
|
59872
|
-
if (!
|
|
60232
|
+
if (!isRecord25(value2) || !isHostApprovalRequestId(value2.id)) return false;
|
|
59873
60233
|
const requestId = value2.id;
|
|
59874
60234
|
const pending = this.#pendingDesktopApprovals.get(requestId);
|
|
59875
60235
|
if (!pending) return true;
|
|
@@ -60081,7 +60441,7 @@ var AppServerHost = class {
|
|
|
60081
60441
|
}
|
|
60082
60442
|
}
|
|
60083
60443
|
async #handleDesktopQuestionResponse(value2, fromClient = false) {
|
|
60084
|
-
if (!
|
|
60444
|
+
if (!isRecord25(value2) || !isHostQuestionRequestId(value2.id)) return false;
|
|
60085
60445
|
const requestId = value2.id;
|
|
60086
60446
|
const pending = this.#pendingDesktopQuestions.get(requestId);
|
|
60087
60447
|
if (!pending) return true;
|
|
@@ -60111,7 +60471,7 @@ var AppServerHost = class {
|
|
|
60111
60471
|
if (pending.timeout) clearTimeout(pending.timeout);
|
|
60112
60472
|
let response;
|
|
60113
60473
|
try {
|
|
60114
|
-
response =
|
|
60474
|
+
response = isRecord25(value2.error) ? { type: "question", answers: {}, cancelled: true } : pending.projection.parseResponse(value2.result);
|
|
60115
60475
|
} catch (error51) {
|
|
60116
60476
|
this.#diagnose(error51);
|
|
60117
60477
|
response = { type: "question", answers: {}, cancelled: true };
|
|
@@ -60255,7 +60615,7 @@ import { homedir as homedir6 } from "node:os";
|
|
|
60255
60615
|
import path42 from "node:path";
|
|
60256
60616
|
|
|
60257
60617
|
// packages/host-runtime/src/codex-runtime/owned-official-backends.ts
|
|
60258
|
-
import { createHash as
|
|
60618
|
+
import { createHash as createHash17, randomBytes as randomBytes4 } from "node:crypto";
|
|
60259
60619
|
import { Writable as Writable2 } from "node:stream";
|
|
60260
60620
|
|
|
60261
60621
|
// packages/host-runtime/src/remote-app-server.ts
|
|
@@ -61502,7 +61862,7 @@ function createOwnedLoopbackBackend(input) {
|
|
|
61502
61862
|
"--ws-auth",
|
|
61503
61863
|
"capability-token",
|
|
61504
61864
|
"--ws-token-sha256",
|
|
61505
|
-
|
|
61865
|
+
createHash17("sha256").update(capabilityToken).digest("hex")
|
|
61506
61866
|
],
|
|
61507
61867
|
// Managed stderr may carry credential-bearing errors. Never forward raw bytes.
|
|
61508
61868
|
diagnosticOutput: new Writable2({
|
|
@@ -62512,7 +62872,7 @@ var DelegationWatchService = class {
|
|
|
62512
62872
|
};
|
|
62513
62873
|
|
|
62514
62874
|
// packages/host-runtime/src/thread-refs.ts
|
|
62515
|
-
import { createHash as
|
|
62875
|
+
import { createHash as createHash18, randomBytes as randomBytes5 } from "node:crypto";
|
|
62516
62876
|
import { mkdir as mkdir20, readFile as readFile24, readdir as readdir8, rename as rename17, rm as rm18, writeFile as writeFile14 } from "node:fs/promises";
|
|
62517
62877
|
import path43 from "node:path";
|
|
62518
62878
|
var MAX_THREAD_REFS = 16;
|
|
@@ -62613,7 +62973,7 @@ var FileThreadRefsStore = class {
|
|
|
62613
62973
|
}));
|
|
62614
62974
|
}
|
|
62615
62975
|
#path(threadId3) {
|
|
62616
|
-
const name =
|
|
62976
|
+
const name = createHash18("sha256").update(threadId3).digest("hex");
|
|
62617
62977
|
return path43.join(this.#directory, `${name}.json`);
|
|
62618
62978
|
}
|
|
62619
62979
|
};
|
|
@@ -62956,9 +63316,9 @@ var FileDelegationWatchStore = class {
|
|
|
62956
63316
|
const adopted = [];
|
|
62957
63317
|
for (const name of names) {
|
|
62958
63318
|
const claimAt = name.indexOf(CLAIM_MARKER);
|
|
62959
|
-
const
|
|
63319
|
+
const isRecord26 = claimAt < 0 && name.endsWith(RECORD_SUFFIX);
|
|
62960
63320
|
const claimer = claimAt >= 0 ? Number(name.slice(claimAt + CLAIM_MARKER.length).split(".")[0]) : NaN;
|
|
62961
|
-
if (!
|
|
63321
|
+
if (!isRecord26 && !(Number.isSafeInteger(claimer) && !processAlive(claimer))) continue;
|
|
62962
63322
|
const watch3 = await this.#adoptFile(name).catch((error51) => {
|
|
62963
63323
|
this.#diagnose(error51);
|
|
62964
63324
|
return void 0;
|
|
@@ -67158,7 +67518,7 @@ async function runSharedHostService(arguments_2, environment, runtimeUrl) {
|
|
|
67158
67518
|
}
|
|
67159
67519
|
|
|
67160
67520
|
// packages/host-runtime/src/remote-host-install.ts
|
|
67161
|
-
import { createHash as
|
|
67521
|
+
import { createHash as createHash19, randomUUID as randomUUID36 } from "node:crypto";
|
|
67162
67522
|
import { constants as fsConstants } from "node:fs";
|
|
67163
67523
|
import {
|
|
67164
67524
|
access as access4,
|
|
@@ -67218,7 +67578,7 @@ async function existingText(filePath) {
|
|
|
67218
67578
|
}
|
|
67219
67579
|
}
|
|
67220
67580
|
async function fileSha256(filePath) {
|
|
67221
|
-
return
|
|
67581
|
+
return createHash19("sha256").update(await readFile29(filePath)).digest("hex");
|
|
67222
67582
|
}
|
|
67223
67583
|
async function executable(filePath, label) {
|
|
67224
67584
|
const absolute2 = path61.resolve(filePath);
|
|
@@ -67359,7 +67719,7 @@ ${WRAPPER_MARKER}
|
|
|
67359
67719
|
return "legacy-wrapper";
|
|
67360
67720
|
}
|
|
67361
67721
|
if (manifest.entrypointSha256 !== void 0) {
|
|
67362
|
-
return
|
|
67722
|
+
return createHash19("sha256").update(entrypoint).digest("hex") === manifest.entrypointSha256 ? "native" : "modified";
|
|
67363
67723
|
}
|
|
67364
67724
|
const shim = await readFile29(manifest.shimPath).catch((error51) => {
|
|
67365
67725
|
if (error51.code === "ENOENT") return null;
|