@karlorz/codexhost-cli-win32-x64 0.17.4-1 → 0.17.4-2
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 +364 -138
- package/app/plugins/grok/plugin.mjs +207 -153
- package/bin/codexhost.exe +0 -0
- package/libexec/codexhost-node-repl.exe +0 -0
- package/libexec/codexhost-shim.exe +0 -0
- package/libexec/codexhost-updater.exe +0 -0
- package/package.json +1 -1
package/app/host-runtime.mjs
CHANGED
|
@@ -3720,6 +3720,10 @@ var DELEGATION_CLI_NODE_PATH_ENV = "CODEXHOST_CLI_NODE_PATH";
|
|
|
3720
3720
|
var DELEGATION_THREAD_ID_ENV = "CODEXHOST_THREAD_ID";
|
|
3721
3721
|
var NATIVE_CODEX_THREAD_ID_ENV = "CODEX_THREAD_ID";
|
|
3722
3722
|
var DEFAULT_WATCH_TIMEOUT_MS = 29 * 6e4;
|
|
3723
|
+
var DEFAULT_WATCH_QUIET_MS = 8e3;
|
|
3724
|
+
function isTerminalDelegationStatus(status2) {
|
|
3725
|
+
return status2 === "completed" || status2 === "failed" || status2 === "interrupted";
|
|
3726
|
+
}
|
|
3723
3727
|
var DelegationControlError = class extends Error {
|
|
3724
3728
|
constructor(code, message2, details) {
|
|
3725
3729
|
super(message2);
|
|
@@ -3733,9 +3737,11 @@ var DelegationControlError = class extends Error {
|
|
|
3733
3737
|
|
|
3734
3738
|
// packages/host-runtime/src/delegation-cli-options.ts
|
|
3735
3739
|
var FREE_TEXT_OPTIONS = /* @__PURE__ */ new Set(["--task", "--task-name", "--message"]);
|
|
3740
|
+
var FLAG_OPTIONS = /* @__PURE__ */ new Set(["--fallback-default"]);
|
|
3736
3741
|
function consumesNextArgument(argument, next) {
|
|
3737
3742
|
if (!argument.startsWith("--") || argument.includes("=")) return false;
|
|
3738
3743
|
if (FREE_TEXT_OPTIONS.has(argument)) return true;
|
|
3744
|
+
if (FLAG_OPTIONS.has(argument)) return next === "true" || next === "false";
|
|
3739
3745
|
return next !== void 0 && !next.startsWith("--");
|
|
3740
3746
|
}
|
|
3741
3747
|
function parseDelegationArguments(arguments_2) {
|
|
@@ -3759,8 +3765,15 @@ function parseDelegationArguments(arguments_2) {
|
|
|
3759
3765
|
optionValue = arguments_2[index + 1];
|
|
3760
3766
|
index += 1;
|
|
3761
3767
|
}
|
|
3768
|
+
if (optionValue === void 0 && FLAG_OPTIONS.has(name)) {
|
|
3769
|
+
parsed2.set(name, "true");
|
|
3770
|
+
continue;
|
|
3771
|
+
}
|
|
3762
3772
|
if (optionValue === void 0 || optionValue === "" && !FREE_TEXT_OPTIONS.has(name))
|
|
3763
3773
|
throw new DelegationControlError("INVALID_ARGUMENT", `${name} requires a value`);
|
|
3774
|
+
if (FLAG_OPTIONS.has(name) && optionValue !== "true" && optionValue !== "false") {
|
|
3775
|
+
throw new DelegationControlError("INVALID_ARGUMENT", `${name} must be true or false`);
|
|
3776
|
+
}
|
|
3764
3777
|
parsed2.set(name, optionValue);
|
|
3765
3778
|
}
|
|
3766
3779
|
return { positionals, options: parsed2 };
|
|
@@ -3773,11 +3786,13 @@ List Harnesses available in the active Runtime.`,
|
|
|
3773
3786
|
"harness inspect": `codexhost harness inspect <harness> [--cwd <path>] [--refresh true|false] [--format json|compact]
|
|
3774
3787
|
Read available Models, native defaults, Thinking options, and configuration capabilities.
|
|
3775
3788
|
Use the returned Model and Thinking IDs for explicit selections.`,
|
|
3776
|
-
"delegate start": `codexhost delegate start --harness <id> --task <text> [--task-name <name>] [--cwd <path>] [--model <opaque-ref>] [--thinking <option-id>] [--parent-thread <thread>] [--request-id <id>] [--watch true|false] [--watch-timeout-ms <n>] [--format json|compact]
|
|
3789
|
+
"delegate start": `codexhost delegate start --harness <id> --task <text> [--task-name <name>] [--cwd <path>] [--model <opaque-ref>] [--thinking <option-id>] [--fallback-default] [--parent-thread <thread>] [--request-id <id>] [--watch true|false] [--watch-timeout-ms <n>] [--format json|compact]
|
|
3777
3790
|
Create an independent child Thread, submit the task, and return immediately.
|
|
3778
3791
|
--task-name supplies a short subtask name (1-120 characters); otherwise the first task line is used.
|
|
3779
3792
|
The child title is "subtask name · parent title", fixed at creation; renaming the parent does not rename existing children.
|
|
3780
3793
|
Omit --model and --thinking to use the Harness native defaults.
|
|
3794
|
+
Requested --model/--thinking are validated against the target Harness catalog at submit. Catalog membership is necessary, not sufficient: some Harnesses cannot prove entitlement before spawn. When they can, an unusable Model is rejected as MODEL_NOT_USABLE (for example MODEL_NOT_USABLE: model 'grok-4.6' is not usable on harness 'grok'). Unknown IDs are MODEL_NOT_IN_CATALOG or THINKING_NOT_AVAILABLE.
|
|
3795
|
+
Do not silently replace a requested Model with the Harness default. Pass --fallback-default (or --fallback-default true) to opt in; the start response's configuration.modelResolution and Host Runtime log record the decision either way.
|
|
3781
3796
|
--cwd overrides the child workspace; a relative path resolves against the caller process cwd. Otherwise use the resolved parent Thread workspace, then the Host Runtime process cwd.
|
|
3782
3797
|
--parent-thread overrides caller inference. PARENT_THREAD_AMBIGUOUS requires an explicit parent.
|
|
3783
3798
|
Reuse --request-id for an idempotent retry. Identical recent parent/target/task/configuration requests are also deduplicated briefly.
|
|
@@ -3792,7 +3807,7 @@ Request cancellation of the active Turn while preserving the Thread and history.
|
|
|
3792
3807
|
cancelled=true (compact: cancelRequested=true) means the cancellation request was accepted. Read or wait to confirm the terminal state. An idle Thread returns false.`,
|
|
3793
3808
|
"thread read": `codexhost thread read <thread> [--host <hostId>] [--view result|messages] [--cursor <cursor>] [--limit <n>] [--format json|compact]
|
|
3794
3809
|
Read immediately without starting a Turn. Accepts thread://<id>?hostId=<encoded-host-id> or --host with a bare ID. Explicit remote Hosts use the existing Desktop connection, never local fallback. Requires updated local and remote codexhost; remote send/wait/watch are not supported.
|
|
3795
|
-
The default result view reports the latest Turn's status and result.
|
|
3810
|
+
The default result view reports the latest Turn's status and result. When a newer Turn is running, lastCompleted holds the previous terminal Turn's result so compact output does not hide it.
|
|
3796
3811
|
The messages view pages visible user/Agent messages, oldest first. Default limit 25, maximum 100; --cursor and --limit require --view messages.
|
|
3797
3812
|
hasMore describes remaining messages now. Save nextCursor for later incremental reads even when hasMore=false.
|
|
3798
3813
|
Compact messages output contains only the message page and status; compact result output includes the latest nonempty progress while running.
|
|
@@ -3804,7 +3819,7 @@ Message pagination uses --view messages, default limit 25, maximum 100. hasMore
|
|
|
3804
3819
|
"thread watch": `codexhost thread watch <thread> [--notify <thread>] [--timeout-ms <n>] [--format json|compact]
|
|
3805
3820
|
Ask the Host to notify one Thread, once, when the watched Thread stops. Returns immediately; no waiting or polling by the caller is needed, and the caller may end its Turn.
|
|
3806
3821
|
--notify defaults to the calling Thread when it is identified (CODEXHOST_THREAD_ID, or CODEX_THREAD_ID in native Codex); otherwise it is required. delegate start reports the caller as its parent.
|
|
3807
|
-
The notification starts a new Turn in the notified Thread with the watched Thread's link and outcome: completed, failed, interrupted, timedOut, unreadable, or notFound; a terminal outcome names the Turn it came from. It reports execution state only; read the Thread to judge the work.
|
|
3822
|
+
The notification starts a new Turn in the notified Thread with the watched Thread's link and outcome: completed, failed, interrupted, timedOut, unreadable, or notFound; a terminal outcome names the Turn it came from, including turn index and turnStatus when known. completed waits a quiet period (default 8s) so a follow-up Turn can start before the watch fires. failed and interrupted notify immediately. It reports execution state only; read the Thread to judge the work.
|
|
3808
3823
|
--timeout-ms defaults to 1740000 (29 min). timedOut means the Thread had not reached a terminal state, which also covers a Harness that stopped without reporting it; watch again to keep waiting. unreadable means reads failed for 60 s, so the state is unknown.
|
|
3809
3824
|
state=watching means registered. state=alreadyTerminal means the Thread was not running: nothing was registered and nothing will be sent.
|
|
3810
3825
|
A busy notified Thread is notified after its Turn ends (retried for up to 6 hours); notifications due together arrive as one message. THREAD_BUSY is never treated as delivered.
|
|
@@ -3946,10 +3961,12 @@ function snapshotOutput(snapshot2, view) {
|
|
|
3946
3961
|
};
|
|
3947
3962
|
}
|
|
3948
3963
|
const progress = snapshot2.progress.filter(({ text }) => text.trim()).at(-1)?.text;
|
|
3964
|
+
const lastCompleted = snapshot2.lastCompleted;
|
|
3949
3965
|
return {
|
|
3950
3966
|
...common,
|
|
3951
3967
|
result: snapshot2.result,
|
|
3952
|
-
...snapshot2.status === "running" && progress ? { progress } : {}
|
|
3968
|
+
...snapshot2.status === "running" && progress ? { progress } : {},
|
|
3969
|
+
...lastCompleted ? { lastCompleted } : {}
|
|
3953
3970
|
};
|
|
3954
3971
|
}
|
|
3955
3972
|
function compactDelegationOutput(command, body, view = "result") {
|
|
@@ -4004,13 +4021,27 @@ function compactDelegationOutput(command, body, view = "result") {
|
|
|
4004
4021
|
case "thread watches": {
|
|
4005
4022
|
const result = body;
|
|
4006
4023
|
return {
|
|
4007
|
-
watches: result.watches.map(
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4024
|
+
watches: result.watches.map(
|
|
4025
|
+
({
|
|
4026
|
+
threadId: threadId2,
|
|
4027
|
+
notifyThreadId,
|
|
4028
|
+
state,
|
|
4029
|
+
outcome,
|
|
4030
|
+
reason,
|
|
4031
|
+
turnId,
|
|
4032
|
+
turnIndex,
|
|
4033
|
+
turnStatus: turnStatus3
|
|
4034
|
+
}) => ({
|
|
4035
|
+
thread: threadLink(threadId2),
|
|
4036
|
+
notify: threadLink(notifyThreadId),
|
|
4037
|
+
state,
|
|
4038
|
+
...outcome ? { outcome } : {},
|
|
4039
|
+
...turnId ? { turnId } : {},
|
|
4040
|
+
...turnIndex !== void 0 ? { turnIndex } : {},
|
|
4041
|
+
...turnStatus3 ? { turnStatus: turnStatus3 } : {},
|
|
4042
|
+
...reason ? { reason } : {}
|
|
4043
|
+
})
|
|
4044
|
+
)
|
|
4014
4045
|
};
|
|
4015
4046
|
}
|
|
4016
4047
|
case "thread list": {
|
|
@@ -4880,7 +4911,8 @@ async function runDelegationCli(input) {
|
|
|
4880
4911
|
"--parent-thread",
|
|
4881
4912
|
"--request-id",
|
|
4882
4913
|
"--watch",
|
|
4883
|
-
"--watch-timeout-ms"
|
|
4914
|
+
"--watch-timeout-ms",
|
|
4915
|
+
"--fallback-default"
|
|
4884
4916
|
]);
|
|
4885
4917
|
if (parsed2.positionals.length > 0)
|
|
4886
4918
|
throw new DelegationControlError(
|
|
@@ -4895,6 +4927,7 @@ async function runDelegationCli(input) {
|
|
|
4895
4927
|
const watch = value(parsed2, "--watch");
|
|
4896
4928
|
if (watch !== void 0 && watch !== "true" && watch !== "false")
|
|
4897
4929
|
throw new DelegationControlError("INVALID_ARGUMENT", "--watch must be true or false");
|
|
4930
|
+
const fallbackDefault = value(parsed2, "--fallback-default");
|
|
4898
4931
|
if (watch !== "true" && value(parsed2, "--watch-timeout-ms"))
|
|
4899
4932
|
throw new DelegationControlError(
|
|
4900
4933
|
"INVALID_ARGUMENT",
|
|
@@ -4913,7 +4946,8 @@ async function runDelegationCli(input) {
|
|
|
4913
4946
|
...value(parsed2, "--request-id") ? { requestId: value(parsed2, "--request-id") } : {},
|
|
4914
4947
|
...watch === "true" ? {
|
|
4915
4948
|
watchTimeoutMs: value(parsed2, "--watch-timeout-ms") ? positiveInteger(value(parsed2, "--watch-timeout-ms"), "--watch-timeout-ms") : DEFAULT_WATCH_TIMEOUT_MS
|
|
4916
|
-
} : {}
|
|
4949
|
+
} : {},
|
|
4950
|
+
...fallbackDefault !== void 0 ? { fallbackDefault: fallbackDefault === "true" } : {}
|
|
4917
4951
|
})
|
|
4918
4952
|
);
|
|
4919
4953
|
return 0;
|
|
@@ -26567,12 +26601,17 @@ function turnStatus(outcome) {
|
|
|
26567
26601
|
return "interrupted";
|
|
26568
26602
|
return "failed";
|
|
26569
26603
|
}
|
|
26570
|
-
function
|
|
26571
|
-
return
|
|
26572
|
-
message:
|
|
26604
|
+
function projectedTurnError(error51) {
|
|
26605
|
+
return {
|
|
26606
|
+
message: error51.message,
|
|
26573
26607
|
codexErrorInfo: "other",
|
|
26574
|
-
additionalDetails: null
|
|
26575
|
-
|
|
26608
|
+
additionalDetails: error51.diagnostic ?? null,
|
|
26609
|
+
...error51.code ? { code: error51.code } : {},
|
|
26610
|
+
...error51.diagnostic ? { diagnostic: error51.diagnostic } : {}
|
|
26611
|
+
};
|
|
26612
|
+
}
|
|
26613
|
+
function turnError(outcome) {
|
|
26614
|
+
return outcome.status === "failed" ? projectedTurnError(outcome.error) : null;
|
|
26576
26615
|
}
|
|
26577
26616
|
function historicalStatus(outcome) {
|
|
26578
26617
|
if (outcome.status === "failed")
|
|
@@ -26587,11 +26626,7 @@ function projectHistoricalTurn(input) {
|
|
|
26587
26626
|
const startedAtMs = snapshot2.startedAtMs;
|
|
26588
26627
|
const completedAtMs = snapshot2.completedAtMs;
|
|
26589
26628
|
const hasTiming = startedAtMs !== void 0 && completedAtMs !== void 0 && Number.isFinite(startedAtMs) && Number.isFinite(completedAtMs) && startedAtMs >= 0 && completedAtMs >= startedAtMs;
|
|
26590
|
-
const error51 = snapshot2.outcome.status === "failed" ?
|
|
26591
|
-
message: snapshot2.outcome.error.message,
|
|
26592
|
-
codexErrorInfo: "other",
|
|
26593
|
-
additionalDetails: null
|
|
26594
|
-
} : null;
|
|
26629
|
+
const error51 = snapshot2.outcome.status === "failed" ? projectedTurnError(snapshot2.outcome.error) : null;
|
|
26595
26630
|
const projectEntry = ({ item, outcome }) => {
|
|
26596
26631
|
if (itemFileChanges(item) !== null) {
|
|
26597
26632
|
return files?.itemId === item.itemId ? [projectItem(files, { status: "succeeded" }, cwd)] : [];
|
|
@@ -39114,6 +39149,143 @@ function sameWorkspace(left, right) {
|
|
|
39114
39149
|
return path30.resolve(left) === path30.resolve(right);
|
|
39115
39150
|
}
|
|
39116
39151
|
|
|
39152
|
+
// packages/host-runtime/src/delegation-model-validation.ts
|
|
39153
|
+
function catalogModelIds(catalog) {
|
|
39154
|
+
return catalog.models.flatMap(
|
|
39155
|
+
(candidate) => candidate.fastModel ? [candidate.ref.id, candidate.fastModel.id] : [candidate.ref.id]
|
|
39156
|
+
);
|
|
39157
|
+
}
|
|
39158
|
+
function namedError(code, message2, details) {
|
|
39159
|
+
return new DelegationControlError(code, `${code}: ${message2}`, details);
|
|
39160
|
+
}
|
|
39161
|
+
function readyInspection(inspection, harnessId) {
|
|
39162
|
+
if (inspection?.status === "ready") return inspection;
|
|
39163
|
+
throw new DelegationControlError(
|
|
39164
|
+
"DELEGATION_FAILED",
|
|
39165
|
+
inspection ? inspection.error.message : `Harness '${harnessId}' Model catalog is unavailable`,
|
|
39166
|
+
...inspection ? [{ status: inspection.status }] : []
|
|
39167
|
+
);
|
|
39168
|
+
}
|
|
39169
|
+
function fallbackLog(harnessId, requested, fallbackId, reason) {
|
|
39170
|
+
return `MODEL_RESOLUTION: falling back to harness '${harnessId}' default model '${fallbackId}' because ${reason}; requested '${requested}' (--fallback-default)`;
|
|
39171
|
+
}
|
|
39172
|
+
function fallbackOrThrow(fallbackDefault, defaultModel, harnessId, requested, reason, error51) {
|
|
39173
|
+
if (fallbackDefault && defaultModel) {
|
|
39174
|
+
return {
|
|
39175
|
+
model: defaultModel,
|
|
39176
|
+
log: fallbackLog(harnessId, requested.id, defaultModel.id, reason)
|
|
39177
|
+
};
|
|
39178
|
+
}
|
|
39179
|
+
throw error51();
|
|
39180
|
+
}
|
|
39181
|
+
function resolveDelegationStartConfiguration(input) {
|
|
39182
|
+
const fallbackDefault = input.fallbackDefault === true;
|
|
39183
|
+
const harnessId = input.harnessId;
|
|
39184
|
+
if (!input.model && !input.thinkingOptionId) {
|
|
39185
|
+
return {
|
|
39186
|
+
decision: "harness-default",
|
|
39187
|
+
log: `MODEL_RESOLUTION: using harness '${harnessId}' native default (no --model; fallback-default=${fallbackDefault})`
|
|
39188
|
+
};
|
|
39189
|
+
}
|
|
39190
|
+
const inspection = readyInspection(input.inspection, harnessId);
|
|
39191
|
+
const catalog = inspection.catalog;
|
|
39192
|
+
let model2 = input.model;
|
|
39193
|
+
let thinkingOptionId = input.thinkingOptionId;
|
|
39194
|
+
let decision = input.model ? "requested" : "harness-default";
|
|
39195
|
+
const logs = [];
|
|
39196
|
+
if (model2) {
|
|
39197
|
+
const requested = model2;
|
|
39198
|
+
if (!inspection.capabilities.configuration.selectModel) {
|
|
39199
|
+
throw namedError(
|
|
39200
|
+
"MODEL_SELECTION_UNSUPPORTED",
|
|
39201
|
+
`harness '${harnessId}' does not support Model selection`
|
|
39202
|
+
);
|
|
39203
|
+
}
|
|
39204
|
+
const listed = catalogModelForRef(catalog, requested);
|
|
39205
|
+
const defaultModel = catalog.defaultModel;
|
|
39206
|
+
if (!listed) {
|
|
39207
|
+
const fallback = fallbackOrThrow(
|
|
39208
|
+
fallbackDefault,
|
|
39209
|
+
defaultModel,
|
|
39210
|
+
harnessId,
|
|
39211
|
+
requested,
|
|
39212
|
+
"model is not in the catalog",
|
|
39213
|
+
() => namedError(
|
|
39214
|
+
"MODEL_NOT_IN_CATALOG",
|
|
39215
|
+
`model '${requested.id}' is not in the catalog for harness '${harnessId}'`,
|
|
39216
|
+
{ validModelIds: catalogModelIds(catalog) }
|
|
39217
|
+
)
|
|
39218
|
+
);
|
|
39219
|
+
logs.push(fallback.log);
|
|
39220
|
+
model2 = fallback.model;
|
|
39221
|
+
decision = "fallback-default";
|
|
39222
|
+
} else if (input.usability?.checked === true && input.usability.usable === false) {
|
|
39223
|
+
const usability = input.usability;
|
|
39224
|
+
const fallback = fallbackOrThrow(
|
|
39225
|
+
fallbackDefault,
|
|
39226
|
+
defaultModel,
|
|
39227
|
+
harnessId,
|
|
39228
|
+
requested,
|
|
39229
|
+
usability.reason ?? "model is not usable",
|
|
39230
|
+
() => namedError(
|
|
39231
|
+
"MODEL_NOT_USABLE",
|
|
39232
|
+
`model '${requested.id}' is not usable on harness '${harnessId}'`,
|
|
39233
|
+
{
|
|
39234
|
+
...usability.reason ? { reason: usability.reason } : {}
|
|
39235
|
+
}
|
|
39236
|
+
)
|
|
39237
|
+
);
|
|
39238
|
+
logs.push(fallback.log);
|
|
39239
|
+
model2 = fallback.model;
|
|
39240
|
+
decision = "fallback-default";
|
|
39241
|
+
} else if (input.usability?.checked === false) {
|
|
39242
|
+
logs.push(
|
|
39243
|
+
`MODEL_RESOLUTION: using requested model '${model2.id}' on harness '${harnessId}'; entitlement cannot be checked before spawn${input.usability.reason ? ` (${input.usability.reason})` : ""}`
|
|
39244
|
+
);
|
|
39245
|
+
} else {
|
|
39246
|
+
logs.push(
|
|
39247
|
+
`MODEL_RESOLUTION: using requested model '${model2.id}' on harness '${harnessId}' (no fallback)`
|
|
39248
|
+
);
|
|
39249
|
+
}
|
|
39250
|
+
} else {
|
|
39251
|
+
logs.push(
|
|
39252
|
+
`MODEL_RESOLUTION: using harness '${harnessId}' native default Model with explicit Thinking (fallback-default=${fallbackDefault})`
|
|
39253
|
+
);
|
|
39254
|
+
}
|
|
39255
|
+
if (thinkingOptionId) {
|
|
39256
|
+
if (!inspection.capabilities.configuration.selectThinkingOption) {
|
|
39257
|
+
throw namedError(
|
|
39258
|
+
"THINKING_SELECTION_UNSUPPORTED",
|
|
39259
|
+
`harness '${harnessId}' does not support Thinking selection`
|
|
39260
|
+
);
|
|
39261
|
+
}
|
|
39262
|
+
const selectedModel = model2 ?? catalog.defaultModel;
|
|
39263
|
+
const modelEntry = selectedModel ? catalogModelForRef(catalog, selectedModel) : void 0;
|
|
39264
|
+
const validThinkingOptionIds = modelEntry?.supportedThinkingOptionIds ?? [];
|
|
39265
|
+
if (!validThinkingOptionIds.includes(thinkingOptionId)) {
|
|
39266
|
+
if (fallbackDefault) {
|
|
39267
|
+
logs.push(
|
|
39268
|
+
`MODEL_RESOLUTION: dropping requested thinking '${thinkingOptionId}' on harness '${harnessId}' (--fallback-default); valid=${JSON.stringify(validThinkingOptionIds)}`
|
|
39269
|
+
);
|
|
39270
|
+
thinkingOptionId = void 0;
|
|
39271
|
+
if (decision === "requested") decision = "fallback-default";
|
|
39272
|
+
} else {
|
|
39273
|
+
throw namedError(
|
|
39274
|
+
"THINKING_NOT_AVAILABLE",
|
|
39275
|
+
`thinking '${thinkingOptionId}' is not available for model '${selectedModel?.id ?? "default"}' on harness '${harnessId}'`,
|
|
39276
|
+
{ validThinkingOptionIds }
|
|
39277
|
+
);
|
|
39278
|
+
}
|
|
39279
|
+
}
|
|
39280
|
+
}
|
|
39281
|
+
return {
|
|
39282
|
+
...model2 ? { model: model2 } : {},
|
|
39283
|
+
...thinkingOptionId ? { thinkingOptionId } : {},
|
|
39284
|
+
decision,
|
|
39285
|
+
log: logs.join(" | ")
|
|
39286
|
+
};
|
|
39287
|
+
}
|
|
39288
|
+
|
|
39117
39289
|
// packages/host-runtime/src/harness-delegation-coordinator.ts
|
|
39118
39290
|
import { createHash as createHash9, randomUUID as randomUUID16 } from "node:crypto";
|
|
39119
39291
|
import path31 from "node:path";
|
|
@@ -39148,6 +39320,49 @@ function turnStatus2(value2) {
|
|
|
39148
39320
|
if (value2 === "interrupted" || value2 === "cancelled") return "interrupted";
|
|
39149
39321
|
return "completed";
|
|
39150
39322
|
}
|
|
39323
|
+
function turnErrorPayload(turn) {
|
|
39324
|
+
if (!isRecord15(turn?.error)) return void 0;
|
|
39325
|
+
const error51 = turn.error;
|
|
39326
|
+
const message2 = typeof error51.message === "string" && error51.message ? error51.message : void 0;
|
|
39327
|
+
const diagnostic = typeof error51.diagnostic === "string" && error51.diagnostic ? error51.diagnostic : typeof error51.additionalDetails === "string" && error51.additionalDetails ? error51.additionalDetails : void 0;
|
|
39328
|
+
const code = typeof error51.code === "string" && error51.code ? error51.code : void 0;
|
|
39329
|
+
if (!message2 && !diagnostic) return void 0;
|
|
39330
|
+
return {
|
|
39331
|
+
message: message2 ?? diagnostic ?? "Turn failed",
|
|
39332
|
+
...code ? { code } : {},
|
|
39333
|
+
...diagnostic && diagnostic !== message2 ? { diagnostic } : {}
|
|
39334
|
+
};
|
|
39335
|
+
}
|
|
39336
|
+
function agentMessagesForTurn(visible, turnId) {
|
|
39337
|
+
return turnId ? visible.filter((message2) => message2.turnId === turnId && message2.role === "agent") : [];
|
|
39338
|
+
}
|
|
39339
|
+
function lastCompletedForRunningTurns(turns, latestTurnId, visible) {
|
|
39340
|
+
for (let index = turns.length - 1; index >= 0; index -= 1) {
|
|
39341
|
+
const turn = turns[index];
|
|
39342
|
+
if (!isRecord15(turn)) continue;
|
|
39343
|
+
const turnId = stringValue(turn.id);
|
|
39344
|
+
if (!turnId || turnId === latestTurnId) continue;
|
|
39345
|
+
const status2 = turnStatus2(turn.status);
|
|
39346
|
+
if (!isTerminalDelegationStatus(status2)) continue;
|
|
39347
|
+
return {
|
|
39348
|
+
turnId,
|
|
39349
|
+
status: status2,
|
|
39350
|
+
result: resultForTurn(turn, agentMessagesForTurn(visible, turnId), false)
|
|
39351
|
+
};
|
|
39352
|
+
}
|
|
39353
|
+
return void 0;
|
|
39354
|
+
}
|
|
39355
|
+
function resultForTurn(turn, messages, running) {
|
|
39356
|
+
const final = messages.filter((message2) => message2.phase === "final" && message2.text.trim()).at(-1);
|
|
39357
|
+
const error51 = turnErrorPayload(turn);
|
|
39358
|
+
if (running)
|
|
39359
|
+
return { availability: "pending", ...error51 ? { error: error51, message: error51.message } : {} };
|
|
39360
|
+
if (final) return { availability: "available", text: final.text };
|
|
39361
|
+
return {
|
|
39362
|
+
availability: "unavailable",
|
|
39363
|
+
...error51 ? { message: error51.message, error: error51 } : {}
|
|
39364
|
+
};
|
|
39365
|
+
}
|
|
39151
39366
|
function allVisibleMessages(turns) {
|
|
39152
39367
|
const messages = [];
|
|
39153
39368
|
for (const turn of turns) {
|
|
@@ -39227,13 +39442,10 @@ function projectDelegationThreadSnapshot(input) {
|
|
|
39227
39442
|
const latestTurnId = latestTurn ? stringValue(latestTurn.id) : null;
|
|
39228
39443
|
const latestTurnStatus = latestTurn ? turnStatus2(latestTurn.status) : null;
|
|
39229
39444
|
const status2 = input.running ? "running" : latestTurnStatus === "failed" || latestTurnStatus === "interrupted" ? latestTurnStatus : threadStatus(input.thread.status, input.running);
|
|
39230
|
-
const latestTurnMessages =
|
|
39231
|
-
const final = latestTurnMessages.filter((message2) => message2.phase === "final" && message2.text.trim()).at(-1);
|
|
39445
|
+
const latestTurnMessages = agentMessagesForTurn(visible, latestTurnId);
|
|
39232
39446
|
const progress = latestTurnMessages.filter((message2) => message2.phase !== "final" && message2.text.trim()).map(({ id: id2, turnId, text }) => ({ id: id2, turnId, text }));
|
|
39233
|
-
const result =
|
|
39234
|
-
|
|
39235
|
-
...isRecord15(latestTurn?.error) && typeof latestTurn.error.message === "string" ? { message: latestTurn.error.message } : {}
|
|
39236
|
-
};
|
|
39447
|
+
const result = resultForTurn(latestTurn, latestTurnMessages, input.running);
|
|
39448
|
+
const lastCompleted = input.running && input.turns.length >= 2 ? lastCompletedForRunningTurns(input.turns, latestTurnId, visible) : void 0;
|
|
39237
39449
|
const offset = options.view === "messages" ? decodeCursor(input.threadId, options.cursor) : visible.length;
|
|
39238
39450
|
const page = options.view === "messages" ? [] : void 0;
|
|
39239
39451
|
let nextOffset = offset;
|
|
@@ -39248,8 +39460,10 @@ function projectDelegationThreadSnapshot(input) {
|
|
|
39248
39460
|
harnessId: input.harnessId,
|
|
39249
39461
|
status: status2,
|
|
39250
39462
|
turn: latestTurnId && latestTurnStatus ? { turnId: latestTurnId, status: latestTurnStatus } : null,
|
|
39463
|
+
...input.turns.length > 0 ? { turnIndex: input.turns.length } : {},
|
|
39251
39464
|
progress,
|
|
39252
39465
|
result,
|
|
39466
|
+
...lastCompleted ? { lastCompleted } : {},
|
|
39253
39467
|
...page ? {
|
|
39254
39468
|
messages: page,
|
|
39255
39469
|
hasMore: visible.slice(nextOffset).some((message2) => message2.text.trim())
|
|
@@ -39274,7 +39488,7 @@ function delay4(milliseconds) {
|
|
|
39274
39488
|
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
39275
39489
|
}
|
|
39276
39490
|
function terminal(status2) {
|
|
39277
|
-
return status2
|
|
39491
|
+
return isTerminalDelegationStatus(status2);
|
|
39278
39492
|
}
|
|
39279
39493
|
function taskDigest(input) {
|
|
39280
39494
|
return createHash9("sha256").update(
|
|
@@ -39282,7 +39496,8 @@ function taskDigest(input) {
|
|
|
39282
39496
|
task: input.task,
|
|
39283
39497
|
cwd: path31.resolve(input.cwd),
|
|
39284
39498
|
modelId: input.model?.id ?? null,
|
|
39285
|
-
thinkingOptionId: input.thinkingOptionId ?? null
|
|
39499
|
+
thinkingOptionId: input.thinkingOptionId ?? null,
|
|
39500
|
+
fallbackDefault: input.fallbackDefault === true
|
|
39286
39501
|
})
|
|
39287
39502
|
).digest("hex");
|
|
39288
39503
|
}
|
|
@@ -39325,6 +39540,7 @@ var HarnessDelegationCoordinator = class {
|
|
|
39325
39540
|
#officialThreadMetadata;
|
|
39326
39541
|
#activeOfficialParents;
|
|
39327
39542
|
#externalThreadBusy;
|
|
39543
|
+
#log;
|
|
39328
39544
|
constructor(input) {
|
|
39329
39545
|
this.#adapters = input.adapters;
|
|
39330
39546
|
this.#environment = input.environment;
|
|
@@ -39342,6 +39558,7 @@ var HarnessDelegationCoordinator = class {
|
|
|
39342
39558
|
this.#officialThreadMetadata = input.officialThreadMetadata;
|
|
39343
39559
|
this.#activeOfficialParents = input.activeOfficialParents;
|
|
39344
39560
|
this.#externalThreadBusy = input.externalThreadBusy;
|
|
39561
|
+
this.#log = input.log ?? (() => void 0);
|
|
39345
39562
|
}
|
|
39346
39563
|
async listHarnesses() {
|
|
39347
39564
|
return { harnesses: ["codex", ...this.#adapters.keys()] };
|
|
@@ -39412,13 +39629,9 @@ var HarnessDelegationCoordinator = class {
|
|
|
39412
39629
|
}
|
|
39413
39630
|
);
|
|
39414
39631
|
}
|
|
39415
|
-
|
|
39416
|
-
|
|
39417
|
-
|
|
39418
|
-
cwd: startInput.cwd
|
|
39419
|
-
});
|
|
39420
|
-
this.#validateConfiguration(inspected.inspection, input.model, input.thinkingOptionId);
|
|
39421
|
-
}
|
|
39632
|
+
const resolved = await this.#resolveSpawnConfiguration(adapter, startInput);
|
|
39633
|
+
const spawnModel = resolved.model;
|
|
39634
|
+
const spawnThinking = resolved.thinkingOptionId;
|
|
39422
39635
|
const delegationId = hostThreadIdSchema.parse(randomUUID16());
|
|
39423
39636
|
const childThreadId = hostThreadIdSchema.parse(randomUUID16());
|
|
39424
39637
|
const turnId = hostTurnIdSchema.parse(randomUUID16());
|
|
@@ -39430,9 +39643,9 @@ var HarnessDelegationCoordinator = class {
|
|
|
39430
39643
|
harnessId: harnessIdSchema.parse(targetHarnessId),
|
|
39431
39644
|
cwd: startInput.cwd,
|
|
39432
39645
|
title,
|
|
39433
|
-
transportModelId:
|
|
39434
|
-
...
|
|
39435
|
-
...
|
|
39646
|
+
transportModelId: spawnModel || spawnThinking ? encodeExternalTransportSelection(targetHarnessId, {
|
|
39647
|
+
...spawnModel ? { model: spawnModel } : {},
|
|
39648
|
+
...spawnThinking ? { thinkingOptionId: spawnThinking } : {}
|
|
39436
39649
|
}) : transportModelIdForHarness(targetHarnessId),
|
|
39437
39650
|
ephemeral: false,
|
|
39438
39651
|
historyMode: "paginated"
|
|
@@ -39457,8 +39670,8 @@ var HarnessDelegationCoordinator = class {
|
|
|
39457
39670
|
cwd: record6.cwd,
|
|
39458
39671
|
environment: { ...this.#environment, [DELEGATION_THREAD_ID_ENV]: childThreadId },
|
|
39459
39672
|
executionPolicy: "unattended-full-access",
|
|
39460
|
-
...
|
|
39461
|
-
...
|
|
39673
|
+
...spawnModel ? { model: spawnModel } : {},
|
|
39674
|
+
...spawnThinking ? { thinkingOptionId: spawnThinking } : {}
|
|
39462
39675
|
});
|
|
39463
39676
|
if (!opened.ok) throw new DelegationControlError("DELEGATION_FAILED", opened.error.message);
|
|
39464
39677
|
session = opened.value;
|
|
@@ -39480,8 +39693,8 @@ var HarnessDelegationCoordinator = class {
|
|
|
39480
39693
|
sessionId: record6.hostThreadId,
|
|
39481
39694
|
thread: threadValue,
|
|
39482
39695
|
turns: [],
|
|
39483
|
-
...
|
|
39484
|
-
...
|
|
39696
|
+
...spawnModel ? { requestedModel: spawnModel } : {},
|
|
39697
|
+
...spawnThinking ? { requestedThinkingOptionId: spawnThinking } : {},
|
|
39485
39698
|
...session.initialState.nativeRef ? {} : { restoredState: session.initialState }
|
|
39486
39699
|
});
|
|
39487
39700
|
const beforeRevision = thread.stateObserver.revision;
|
|
@@ -39532,6 +39745,10 @@ var HarnessDelegationCoordinator = class {
|
|
|
39532
39745
|
...thread.stateObserver.state.effectiveThinkingOptionId ? {
|
|
39533
39746
|
effectiveThinkingOptionId: thread.stateObserver.state.effectiveThinkingOptionId
|
|
39534
39747
|
} : {}
|
|
39748
|
+
},
|
|
39749
|
+
modelResolution: {
|
|
39750
|
+
decision: resolved.decision,
|
|
39751
|
+
fallbackDefault: input.fallbackDefault === true
|
|
39535
39752
|
}
|
|
39536
39753
|
}),
|
|
39537
39754
|
cwd: record6.cwd,
|
|
@@ -39747,46 +39964,29 @@ var HarnessDelegationCoordinator = class {
|
|
|
39747
39964
|
{ activeThreadIds: active }
|
|
39748
39965
|
);
|
|
39749
39966
|
}
|
|
39750
|
-
#
|
|
39751
|
-
|
|
39752
|
-
|
|
39753
|
-
|
|
39754
|
-
});
|
|
39755
|
-
|
|
39756
|
-
|
|
39757
|
-
|
|
39758
|
-
|
|
39759
|
-
|
|
39760
|
-
|
|
39761
|
-
|
|
39762
|
-
}
|
|
39763
|
-
if (model2 && !catalogModelForRef(inspection.catalog, model2)) {
|
|
39764
|
-
throw new DelegationControlError(
|
|
39765
|
-
"INVALID_ARGUMENT",
|
|
39766
|
-
"Model is unavailable for the target Harness",
|
|
39767
|
-
{
|
|
39768
|
-
validModelIds: inspection.catalog.models.flatMap(
|
|
39769
|
-
(candidate) => candidate.fastModel ? [candidate.ref.id, candidate.fastModel.id] : [candidate.ref.id]
|
|
39770
|
-
)
|
|
39771
|
-
}
|
|
39772
|
-
);
|
|
39773
|
-
}
|
|
39774
|
-
if (!thinkingOptionId) return;
|
|
39775
|
-
if (!inspection.capabilities.configuration.selectThinkingOption) {
|
|
39776
|
-
throw new DelegationControlError(
|
|
39777
|
-
"INVALID_ARGUMENT",
|
|
39778
|
-
"Harness does not support Thinking selection"
|
|
39779
|
-
);
|
|
39780
|
-
}
|
|
39781
|
-
const modelEntry = catalogModelForRef(inspection.catalog, selectedModel);
|
|
39782
|
-
const validThinkingOptionIds = modelEntry?.supportedThinkingOptionIds ?? [];
|
|
39783
|
-
if (!validThinkingOptionIds.includes(thinkingOptionId)) {
|
|
39784
|
-
throw new DelegationControlError(
|
|
39785
|
-
"INVALID_ARGUMENT",
|
|
39786
|
-
"Thinking option is unavailable for the selected Model",
|
|
39787
|
-
{ validThinkingOptionIds }
|
|
39788
|
-
);
|
|
39967
|
+
async #resolveSpawnConfiguration(adapter, input) {
|
|
39968
|
+
let inspection;
|
|
39969
|
+
let usability;
|
|
39970
|
+
if (input.model || input.thinkingOptionId) {
|
|
39971
|
+
const inspectPromise = this.inspect({ harnessId: input.harnessId, cwd: input.cwd });
|
|
39972
|
+
const usabilityPromise = input.model && adapter.isModelUsable ? adapter.isModelUsable({ model: input.model, cwd: input.cwd }) : void 0;
|
|
39973
|
+
const [inspected, probed] = await Promise.all([
|
|
39974
|
+
inspectPromise,
|
|
39975
|
+
usabilityPromise ?? Promise.resolve(void 0)
|
|
39976
|
+
]);
|
|
39977
|
+
inspection = inspected.inspection;
|
|
39978
|
+
usability = probed;
|
|
39789
39979
|
}
|
|
39980
|
+
const resolved = resolveDelegationStartConfiguration({
|
|
39981
|
+
harnessId: input.harnessId,
|
|
39982
|
+
...inspection ? { inspection } : {},
|
|
39983
|
+
...input.model ? { model: input.model } : {},
|
|
39984
|
+
...input.thinkingOptionId ? { thinkingOptionId: input.thinkingOptionId } : {},
|
|
39985
|
+
fallbackDefault: input.fallbackDefault === true,
|
|
39986
|
+
...usability ? { usability } : {}
|
|
39987
|
+
});
|
|
39988
|
+
this.#log(resolved.log);
|
|
39989
|
+
return resolved;
|
|
39790
39990
|
}
|
|
39791
39991
|
async #parentMetadata(parentThreadId) {
|
|
39792
39992
|
const record6 = await this.#repository.find(parentThreadId);
|
|
@@ -39834,7 +40034,7 @@ var HarnessDelegationCoordinator = class {
|
|
|
39834
40034
|
harnessId,
|
|
39835
40035
|
deepLink: `codex://threads/${threadId2}`,
|
|
39836
40036
|
status: status2,
|
|
39837
|
-
...configuration
|
|
40037
|
+
...configuration ? { configuration } : {},
|
|
39838
40038
|
next: {
|
|
39839
40039
|
read: `codexhost thread read ${threadId2}`,
|
|
39840
40040
|
wait: `codexhost thread wait ${threadId2} --timeout-ms 30000`
|
|
@@ -44382,7 +44582,8 @@ var AppServerHost = class {
|
|
|
44382
44582
|
listOfficial: (input) => this.#listDelegationThreads(input),
|
|
44383
44583
|
officialThreadMetadata: (threadId2) => this.#readOfficialThreadMetadata(threadId2),
|
|
44384
44584
|
activeOfficialParents: () => [...this.#activeOfficialTurns.keys()],
|
|
44385
|
-
externalThreadBusy: (thread) => this.#externalThreadBusy(thread)
|
|
44585
|
+
externalThreadBusy: (thread) => this.#externalThreadBusy(thread),
|
|
44586
|
+
log: (message2) => this.#diagnose(message2)
|
|
44386
44587
|
});
|
|
44387
44588
|
const maintenanceOperation = (run) => options.runtimeMaintenance ? options.runtimeMaintenance.operation(run) : run();
|
|
44388
44589
|
const unregisterDelegationApi = options.onDelegationApi?.({
|
|
@@ -45929,13 +46130,13 @@ var AppServerHost = class {
|
|
|
45929
46130
|
} catch {
|
|
45930
46131
|
throw new DelegationControlError("INVALID_ARGUMENT", "Official Model Ref is invalid");
|
|
45931
46132
|
}
|
|
45932
|
-
const nativeModelId = requestedModel ? decodeOfficialCodexModelRef(requestedModel) : void 0;
|
|
45933
46133
|
const digest3 = createHash10("sha256").update(
|
|
45934
46134
|
JSON.stringify({
|
|
45935
46135
|
task: input.task,
|
|
45936
46136
|
cwd: input.cwd,
|
|
45937
46137
|
modelId: requestedModel?.id ?? null,
|
|
45938
|
-
thinkingOptionId: input.thinkingOptionId ?? null
|
|
46138
|
+
thinkingOptionId: input.thinkingOptionId ?? null,
|
|
46139
|
+
fallbackDefault: input.fallbackDefault === true
|
|
45939
46140
|
})
|
|
45940
46141
|
).digest("hex");
|
|
45941
46142
|
const existing = input.requestId ? await this.#repository.findDelegationByRequest(input.requestId) : await this.#repository.findRecentDelegation({
|
|
@@ -45965,39 +46166,20 @@ var AppServerHost = class {
|
|
|
45965
46166
|
}
|
|
45966
46167
|
};
|
|
45967
46168
|
}
|
|
45968
|
-
|
|
45969
|
-
|
|
45970
|
-
|
|
45971
|
-
|
|
45972
|
-
|
|
45973
|
-
|
|
45974
|
-
|
|
45975
|
-
|
|
45976
|
-
|
|
45977
|
-
|
|
45978
|
-
|
|
45979
|
-
|
|
45980
|
-
|
|
45981
|
-
|
|
45982
|
-
throw new DelegationControlError("INVALID_ARGUMENT", "Official Model is unavailable", {
|
|
45983
|
-
validModelIds: inspected.inspection.catalog.models.map((candidate) => candidate.ref.id)
|
|
45984
|
-
});
|
|
45985
|
-
}
|
|
45986
|
-
if (input.thinkingOptionId) {
|
|
45987
|
-
const selectedModel = requestedModel ?? inspected.inspection.catalog.defaultModel;
|
|
45988
|
-
const selectedEntry = selectedModel ? inspected.inspection.catalog.models.find(
|
|
45989
|
-
(candidate) => candidate.ref.id === selectedModel.id
|
|
45990
|
-
) : void 0;
|
|
45991
|
-
const validThinkingOptionIds = selectedEntry?.supportedThinkingOptionIds ?? [];
|
|
45992
|
-
if (!validThinkingOptionIds.includes(input.thinkingOptionId)) {
|
|
45993
|
-
throw new DelegationControlError(
|
|
45994
|
-
"INVALID_ARGUMENT",
|
|
45995
|
-
"Official Thinking option is unavailable for the selected Model",
|
|
45996
|
-
{ validThinkingOptionIds }
|
|
45997
|
-
);
|
|
45998
|
-
}
|
|
45999
|
-
}
|
|
46000
|
-
}
|
|
46169
|
+
const inspected = requestedModel || input.thinkingOptionId ? await this.#inspectOfficialDelegationTarget({
|
|
46170
|
+
harnessId: "codex",
|
|
46171
|
+
cwd: input.cwd
|
|
46172
|
+
}) : void 0;
|
|
46173
|
+
const resolved = resolveDelegationStartConfiguration({
|
|
46174
|
+
harnessId: "codex",
|
|
46175
|
+
...inspected ? { inspection: inspected.inspection } : {},
|
|
46176
|
+
...requestedModel ? { model: requestedModel } : {},
|
|
46177
|
+
...input.thinkingOptionId ? { thinkingOptionId: input.thinkingOptionId } : {},
|
|
46178
|
+
fallbackDefault: input.fallbackDefault === true
|
|
46179
|
+
});
|
|
46180
|
+
this.#diagnose(resolved.log);
|
|
46181
|
+
const nativeModelId = resolved.model ? decodeOfficialCodexModelRef(resolved.model) : void 0;
|
|
46182
|
+
const spawnThinking = resolved.thinkingOptionId;
|
|
46001
46183
|
const started = await this.#officialRuntime.request("thread/start", {
|
|
46002
46184
|
cwd: input.cwd,
|
|
46003
46185
|
...nativeModelId ? { model: nativeModelId } : {},
|
|
@@ -46020,7 +46202,7 @@ var AppServerHost = class {
|
|
|
46020
46202
|
threadId: threadId2,
|
|
46021
46203
|
input: [{ type: "text", text: input.task }],
|
|
46022
46204
|
...nativeModelId ? { model: nativeModelId } : {},
|
|
46023
|
-
...
|
|
46205
|
+
...spawnThinking ? { effort: spawnThinking } : {}
|
|
46024
46206
|
});
|
|
46025
46207
|
const turnResult = isRecord21(turn.result) ? turn.result : null;
|
|
46026
46208
|
const turnValue = turnResult && isRecord21(turnResult.turn) ? turnResult.turn : null;
|
|
@@ -46056,17 +46238,19 @@ var AppServerHost = class {
|
|
|
46056
46238
|
deepLink: `codex://threads/${threadId2}`,
|
|
46057
46239
|
status: pendingTerminal ?? "running",
|
|
46058
46240
|
cwd: thread && typeof thread.cwd === "string" ? thread.cwd : input.cwd,
|
|
46059
|
-
|
|
46060
|
-
|
|
46061
|
-
|
|
46062
|
-
|
|
46063
|
-
|
|
46064
|
-
|
|
46065
|
-
|
|
46066
|
-
|
|
46067
|
-
|
|
46241
|
+
configuration: {
|
|
46242
|
+
requested: {
|
|
46243
|
+
...requestedModel ? { model: requestedModel } : {},
|
|
46244
|
+
...input.thinkingOptionId ? { thinkingOptionId: input.thinkingOptionId } : {}
|
|
46245
|
+
},
|
|
46246
|
+
effective: {
|
|
46247
|
+
...startedResult && typeof startedResult.model === "string" ? { effectiveModel: encodeOfficialCodexModelRef(startedResult.model) } : {}
|
|
46248
|
+
},
|
|
46249
|
+
modelResolution: {
|
|
46250
|
+
decision: resolved.decision,
|
|
46251
|
+
fallbackDefault: input.fallbackDefault === true
|
|
46068
46252
|
}
|
|
46069
|
-
}
|
|
46253
|
+
},
|
|
46070
46254
|
next: {
|
|
46071
46255
|
read: `codexhost thread read ${threadId2}`,
|
|
46072
46256
|
wait: `codexhost thread wait ${threadId2} --timeout-ms 30000`
|
|
@@ -50583,7 +50767,7 @@ var DELIVERY_WINDOW_MS = 6 * 60 * 6e4;
|
|
|
50583
50767
|
var MAX_UNDELIVERABLE_ENTRIES = 50;
|
|
50584
50768
|
var UNREADABLE_GRACE_MS = 6e4;
|
|
50585
50769
|
function terminal2(status2) {
|
|
50586
|
-
return status2
|
|
50770
|
+
return isTerminalDelegationStatus(status2);
|
|
50587
50771
|
}
|
|
50588
50772
|
function errorCode(error51) {
|
|
50589
50773
|
return error51 instanceof DelegationControlError ? error51.code : void 0;
|
|
@@ -50610,7 +50794,7 @@ function describe3(watch) {
|
|
|
50610
50794
|
case "notFound":
|
|
50611
50795
|
return `${link2} no longer exists.`;
|
|
50612
50796
|
default:
|
|
50613
|
-
return watch.turnId ? `${link2}: ${watch.outcome} (Turn ${watch.turnId}).` : `${link2}: ${watch.outcome}.`;
|
|
50797
|
+
return watch.turnId ? `${link2}: ${watch.outcome} (Turn ${watch.turnId}).${watch.turnIndex !== void 0 || watch.turnStatus ? ` Turn index ${watch.turnIndex ?? "?"}, status ${watch.turnStatus ?? "unknown"}.` : ""}` : `${link2}: ${watch.outcome}.`;
|
|
50614
50798
|
}
|
|
50615
50799
|
}
|
|
50616
50800
|
function notification(watches) {
|
|
@@ -50622,6 +50806,7 @@ function notification(watches) {
|
|
|
50622
50806
|
var DelegationWatchService = class {
|
|
50623
50807
|
#api;
|
|
50624
50808
|
#pollIntervalMs;
|
|
50809
|
+
#quietMs;
|
|
50625
50810
|
#diagnose;
|
|
50626
50811
|
#watches = [];
|
|
50627
50812
|
#timer;
|
|
@@ -50629,6 +50814,7 @@ var DelegationWatchService = class {
|
|
|
50629
50814
|
constructor(api, options = {}) {
|
|
50630
50815
|
this.#api = api;
|
|
50631
50816
|
this.#pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
50817
|
+
this.#quietMs = options.quietMs ?? DEFAULT_WATCH_QUIET_MS;
|
|
50632
50818
|
this.#diagnose = options.diagnose ?? (() => void 0);
|
|
50633
50819
|
}
|
|
50634
50820
|
async watch(input) {
|
|
@@ -50672,12 +50858,24 @@ var DelegationWatchService = class {
|
|
|
50672
50858
|
async watches() {
|
|
50673
50859
|
return {
|
|
50674
50860
|
watches: this.#watches.map(
|
|
50675
|
-
({
|
|
50861
|
+
({
|
|
50862
|
+
threadId: threadId2,
|
|
50863
|
+
notifyThreadId,
|
|
50864
|
+
state,
|
|
50865
|
+
outcome,
|
|
50866
|
+
turnId,
|
|
50867
|
+
turnIndex,
|
|
50868
|
+
turnStatus: turnStatus3,
|
|
50869
|
+
reason,
|
|
50870
|
+
registeredAt
|
|
50871
|
+
}) => ({
|
|
50676
50872
|
threadId: threadId2,
|
|
50677
50873
|
notifyThreadId,
|
|
50678
50874
|
state,
|
|
50679
50875
|
...outcome ? { outcome } : {},
|
|
50680
50876
|
...turnId ? { turnId } : {},
|
|
50877
|
+
...turnIndex !== void 0 ? { turnIndex } : {},
|
|
50878
|
+
...turnStatus3 ? { turnStatus: turnStatus3 } : {},
|
|
50681
50879
|
...reason ? { reason } : {},
|
|
50682
50880
|
registeredAt
|
|
50683
50881
|
})
|
|
@@ -50707,10 +50905,12 @@ var DelegationWatchService = class {
|
|
|
50707
50905
|
if (watch.state !== "watching") continue;
|
|
50708
50906
|
const observed = await this.#observe(watch);
|
|
50709
50907
|
if (!observed) continue;
|
|
50710
|
-
const { outcome, turnId } = observed;
|
|
50908
|
+
const { outcome, turnId, turnIndex, turnStatus: turnStatus3 } = observed;
|
|
50711
50909
|
watch.state = "pendingDelivery";
|
|
50712
50910
|
watch.outcome = outcome;
|
|
50713
50911
|
if (turnId) watch.turnId = turnId;
|
|
50912
|
+
if (turnIndex !== void 0) watch.turnIndex = turnIndex;
|
|
50913
|
+
if (turnStatus3) watch.turnStatus = turnStatus3;
|
|
50714
50914
|
watch.deliveryDeadline = Date.now() + DELIVERY_WINDOW_MS;
|
|
50715
50915
|
}
|
|
50716
50916
|
const subscribers = new Set(
|
|
@@ -50724,11 +50924,37 @@ var DelegationWatchService = class {
|
|
|
50724
50924
|
async #observe(watch) {
|
|
50725
50925
|
try {
|
|
50726
50926
|
const snapshot2 = await this.#api.read({ threadId: watch.threadId, view: "result" });
|
|
50927
|
+
if (snapshot2.status === "running") {
|
|
50928
|
+
delete watch.quietUntil;
|
|
50929
|
+
delete watch.quietTurnId;
|
|
50930
|
+
delete watch.unreadableSince;
|
|
50931
|
+
return Date.now() >= watch.deadline ? { outcome: "timedOut" } : void 0;
|
|
50932
|
+
}
|
|
50727
50933
|
if (terminal2(snapshot2.status)) {
|
|
50728
|
-
|
|
50934
|
+
delete watch.unreadableSince;
|
|
50935
|
+
const detail = {
|
|
50729
50936
|
outcome: snapshot2.status,
|
|
50730
|
-
...snapshot2.turn ? { turnId: snapshot2.turn.turnId } : {}
|
|
50937
|
+
...snapshot2.turn ? { turnId: snapshot2.turn.turnId, turnStatus: snapshot2.turn.status } : {},
|
|
50938
|
+
...snapshot2.turnIndex !== void 0 ? { turnIndex: snapshot2.turnIndex } : {}
|
|
50731
50939
|
};
|
|
50940
|
+
if (snapshot2.status !== "completed" || this.#quietMs <= 0) {
|
|
50941
|
+
delete watch.quietUntil;
|
|
50942
|
+
delete watch.quietTurnId;
|
|
50943
|
+
return detail;
|
|
50944
|
+
}
|
|
50945
|
+
const now = Date.now();
|
|
50946
|
+
const turnId = snapshot2.turn?.turnId;
|
|
50947
|
+
if (watch.quietUntil === void 0 || watch.quietTurnId !== turnId) {
|
|
50948
|
+
watch.quietUntil = now + this.#quietMs;
|
|
50949
|
+
if (turnId) watch.quietTurnId = turnId;
|
|
50950
|
+
else delete watch.quietTurnId;
|
|
50951
|
+
}
|
|
50952
|
+
if (now >= watch.quietUntil || now >= watch.deadline) {
|
|
50953
|
+
delete watch.quietUntil;
|
|
50954
|
+
delete watch.quietTurnId;
|
|
50955
|
+
return detail;
|
|
50956
|
+
}
|
|
50957
|
+
return void 0;
|
|
50732
50958
|
}
|
|
50733
50959
|
delete watch.unreadableSince;
|
|
50734
50960
|
} catch (error51) {
|