@karlorz/codexhost-cli-win32-x64 0.17.4-4 → 0.17.4-5
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/console-server.mjs +1 -1
- package/app/console-web.js +20 -15
- package/app/cpa-live-voice-hook.js +1 -1
- package/app/desktop-controller.mjs +1 -1
- package/app/host-runtime.mjs +326 -103
- package/app/plugins/antigravity/plugin.mjs +1 -1
- package/app/plugins/claude-code/plugin.mjs +1 -1
- package/app/plugins/codebuddy/plugin.mjs +1 -1
- package/app/plugins/codex-usage/plugin.mjs +1 -1
- package/app/plugins/copilot/plugin.mjs +1 -1
- package/app/plugins/cursor-cli/plugin.mjs +1 -1
- package/app/plugins/deepseek-harness/plugin.mjs +1 -1
- package/app/plugins/devin/plugin.mjs +1 -1
- package/app/plugins/grok/plugin.mjs +1 -1
- package/app/plugins/hermes/plugin.mjs +1 -1
- package/app/plugins/kimi-code/plugin.mjs +1 -1
- package/app/plugins/kiro-cli/plugin.mjs +1 -1
- package/app/plugins/omp/plugin.mjs +1 -1
- package/app/plugins/opencode/plugin.mjs +1 -1
- package/app/plugins/pi/plugin.mjs +1 -1
- package/app/plugins/qoder/plugin.mjs +1 -1
- package/app/plugins/qoder-cn/plugin.mjs +1 -1
- package/app/plugins/qwen-code/plugin.mjs +1 -1
- package/app/plugins/workbuddy/plugin.mjs +1 -1
- package/app/plugins/zcode/plugin.mjs +1 -1
- package/app/renderer-extension.js +20 -15
- 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
|
@@ -3718,6 +3718,7 @@ var DELEGATION_RUNTIME_TOKEN_ENV = "CODEXHOST_RUNTIME_TOKEN";
|
|
|
3718
3718
|
var DELEGATION_CLI_PATH_ENV = "CODEXHOST_CLI_PATH";
|
|
3719
3719
|
var DELEGATION_CLI_NODE_PATH_ENV = "CODEXHOST_CLI_NODE_PATH";
|
|
3720
3720
|
var DELEGATION_THREAD_ID_ENV = "CODEXHOST_THREAD_ID";
|
|
3721
|
+
var DELEGATION_ENROLL_CLIENT_ENV = "CODEXHOST_ENROLL_CLIENT";
|
|
3721
3722
|
var NATIVE_CODEX_THREAD_ID_ENV = "CODEX_THREAD_ID";
|
|
3722
3723
|
var DEFAULT_WATCH_TIMEOUT_MS = 29 * 6e4;
|
|
3723
3724
|
var DEFAULT_WATCH_QUIET_MS = 8e3;
|
|
@@ -3734,6 +3735,13 @@ var DelegationControlError = class extends Error {
|
|
|
3734
3735
|
code;
|
|
3735
3736
|
details;
|
|
3736
3737
|
};
|
|
3738
|
+
var THREAD_BUSY_MESSAGE = "Thread already has an active Turn; no new Turn started. Wait or read until idle, then retry. Cancellation requires a separate cancel grant.";
|
|
3739
|
+
function threadBusyError(threadId2) {
|
|
3740
|
+
return new DelegationControlError("THREAD_BUSY", THREAD_BUSY_MESSAGE, {
|
|
3741
|
+
threadId: threadId2,
|
|
3742
|
+
notStarted: true
|
|
3743
|
+
});
|
|
3744
|
+
}
|
|
3737
3745
|
|
|
3738
3746
|
// packages/host-runtime/src/delegation-cli-options.ts
|
|
3739
3747
|
var FREE_TEXT_OPTIONS = /* @__PURE__ */ new Set(["--task", "--task-name", "--message"]);
|
|
@@ -3798,25 +3806,27 @@ Do not silently replace a requested Model with the Harness default. Pass --fallb
|
|
|
3798
3806
|
Reuse --request-id for an idempotent retry. Identical recent parent/target/task/configuration requests are also deduplicated briefly.
|
|
3799
3807
|
--watch true also registers thread watch on the child with the resolved parent as the notified Thread; the response's watch field reports whether it was registered.
|
|
3800
3808
|
The response confirms cwd and parent. Use its Thread reference with thread read, wait, send, cancel, or watch.`,
|
|
3801
|
-
"thread send": `codexhost thread send <thread> --message <text> [--format json|compact]
|
|
3809
|
+
"thread send": `codexhost thread send <thread> --message <text> [--enrolled-client <id>] [--format json|compact]
|
|
3802
3810
|
Start a new Turn in an idle writable Thread and return immediately.
|
|
3803
|
-
THREAD_BUSY means the
|
|
3811
|
+
THREAD_BUSY means the target already has an active Turn. No new Turn started. Wait or read until idle, then send again. Messages are not queued. Cancellation requires a cancel grant, distinct from send. For an enrolled client, THREAD_BUSY is returned after allowlist authorization.
|
|
3812
|
+
--enrolled-client uses that enrollment even when Host Runtime env is set. A missing or invalid enrollment fails without using Host credentials.
|
|
3804
3813
|
To be notified when that Turn ends, run thread watch after sending.`,
|
|
3805
|
-
"thread cancel": `codexhost thread cancel <thread> [--format json|compact]
|
|
3814
|
+
"thread cancel": `codexhost thread cancel <thread> [--enrolled-client <id>] [--format json|compact]
|
|
3806
3815
|
Request cancellation of the active Turn while preserving the Thread and history.
|
|
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
|
|
3808
|
-
|
|
3816
|
+
cancelled=true (compact: cancelRequested=true) means the cancellation request was accepted. Read or wait to confirm the terminal state. An idle Thread returns false.
|
|
3817
|
+
Enrolled clients need an explicit cancel grant; send does not authorize cancel.`,
|
|
3818
|
+
"thread read": `codexhost thread read <thread> [--host <hostId>] [--enrolled-client <id>] [--view result|messages] [--cursor <cursor>] [--limit <n>] [--format json|compact]
|
|
3809
3819
|
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.
|
|
3810
3820
|
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.
|
|
3811
3821
|
The messages view pages visible user/Agent messages, oldest first. Default limit 25, maximum 100; --cursor and --limit require --view messages.
|
|
3812
3822
|
hasMore describes remaining messages now. Save nextCursor for later incremental reads even when hasMore=false.
|
|
3813
3823
|
Compact messages output contains only the message page and status; compact result output includes the latest nonempty progress while running.
|
|
3814
3824
|
Full JSON retains the complete snapshot. Tool calls/output, file activity, and reasoning are not included in either format.`,
|
|
3815
|
-
"thread wait": `codexhost thread wait <thread> [--timeout-ms <n>] [--view result|messages] [--cursor <cursor>] [--limit <n>] [--format json|compact]
|
|
3825
|
+
"thread wait": `codexhost thread wait <thread> [--timeout-ms <n>] [--enrolled-client <id>] [--view result|messages] [--cursor <cursor>] [--limit <n>] [--format json|compact]
|
|
3816
3826
|
Wait until the Thread is terminal or the timeout expires (default 30000 ms), then return the same snapshot as thread read plus timedOut.
|
|
3817
3827
|
timedOut=true is a running checkpoint: the child keeps running. The response already includes the result when available; another read is unnecessary unless more information is needed.
|
|
3818
3828
|
Message pagination uses --view messages, default limit 25, maximum 100. hasMore is for current pages; nextCursor also supports future incremental reads.`,
|
|
3819
|
-
"thread watch": `codexhost thread watch <thread> [--notify <thread>] [--timeout-ms <n>] [--format json|compact]
|
|
3829
|
+
"thread watch": `codexhost thread watch <thread> [--notify <thread>] [--timeout-ms <n>] [--enrolled-client <id>] [--format json|compact]
|
|
3820
3830
|
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.
|
|
3821
3831
|
--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.
|
|
3822
3832
|
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.
|
|
@@ -3824,24 +3834,26 @@ The notification starts a new Turn in the notified Thread with the watched Threa
|
|
|
3824
3834
|
state=watching means registered. state=alreadyTerminal means the Thread was not running: nothing was registered and nothing will be sent.
|
|
3825
3835
|
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.
|
|
3826
3836
|
A watch is one-shot and cannot be cancelled. Watching the same pair again while it is still watched returns that watch; once it has stopped, a new watch covers the next stop and any pending notification is still delivered. Watches live in Host Runtime memory and are lost when it restarts.`,
|
|
3827
|
-
"thread watches": `codexhost thread watches [--format json|compact]
|
|
3837
|
+
"thread watches": `codexhost thread watches [--enrolled-client <id>] [--format json|compact]
|
|
3828
3838
|
List watches that have not been delivered: watching, pendingDelivery (waiting for the notified Thread), or undeliverable (with the reason). Delivered watches are removed.`,
|
|
3829
|
-
"thread list": `codexhost thread list [--cwd <path>] [--parent <thread>] [--limit <n>] [--cursor <cursor>] [--sort created-asc|created-desc|updated-asc|updated-desc|recency-asc|recency-desc] [--format json|compact]
|
|
3839
|
+
"thread list": `codexhost thread list [--cwd <path>] [--parent <thread>] [--limit <n>] [--cursor <cursor>] [--sort created-asc|created-desc|updated-asc|updated-desc|recency-asc|recency-desc] [--enrolled-client <id>] [--format json|compact]
|
|
3830
3840
|
Find existing Threads by workspace, or use --parent to list a Thread's delegated children.
|
|
3831
3841
|
Workspace listing defaults to the caller process cwd. Default limit 25 (maximum 100), sorted created-desc.
|
|
3832
3842
|
--parent uses Delegation relationships. A null nextCursor ends the list.
|
|
3833
3843
|
Compact output keeps task links, Harness, status, title, and workspace.`,
|
|
3834
3844
|
enroll: `codexhost enroll --client <id> [--allow <threadId:verb[,verb][;...]>] [--executable <path>] [--machine] [--session] [--format json|compact]
|
|
3835
3845
|
Request attended Host enrollment for a local client such as grok-bot.
|
|
3836
|
-
|
|
3846
|
+
Request enrollment from an authorized Host session. Unmanaged bootstrap has no Desktop consent UI and fails immediately with consent_ui_unavailable. Host-authenticated enroll auto-approves under that session's attended authorization.
|
|
3837
3847
|
On Approve, Host issues a distinct enrollment_id, Thread id, and token, and the CLI writes a user-private mode-600 store.
|
|
3838
|
-
The allowlist defaults to empty besides the new Thread (read/watch/send). Parent Thread access requires an explicit allowlist entry.
|
|
3839
|
-
Enrollment defaults to machine pairing
|
|
3848
|
+
The allowlist defaults to empty besides the new Thread (read/watch/send/cancel). Parent Thread access requires an explicit allowlist entry. send does not grant cancel; list cancel explicitly.
|
|
3849
|
+
Enrollment defaults to machine pairing with a recorded expiry (ten years unless revoked sooner), like an SSH authorized key: a Host-authenticated session reuses the same client and allowlist without a new consent. Changing the allowlist is a new trust step. enroll revoke removes the key. --session issues a 24-hour token.
|
|
3840
3850
|
Does not copy another process's Runtime environment, a Runtime descriptor, or a parent env file.`,
|
|
3841
|
-
"enroll status": `codexhost enroll status [--client <id>] [--format json|compact]
|
|
3842
|
-
Show the local enrollment store for this login without printing the token
|
|
3843
|
-
|
|
3844
|
-
|
|
3851
|
+
"enroll status": `codexhost enroll status [--client <id>] [--enrolled-client <id>] [--format json|compact]
|
|
3852
|
+
Show the local enrollment store for this login without printing the token.
|
|
3853
|
+
Selects the client from --client, --enrolled-client, or CODEXHOST_ENROLL_CLIENT (default grok-bot). Reports authentication.source for what thread commands would use: host-session when both Host Runtime variables are set, incomplete-host-session with missing variable names when only one is set, enrollment when --enrolled-client is set or both Host Runtime variables are absent. Invalid stores fail closed with client, path, and reason (expired, insecure_store_mode, missing_store).`,
|
|
3854
|
+
"enroll revoke": `codexhost enroll revoke [--client <id>] [--enrolled-client <id>] [--format json|compact]
|
|
3855
|
+
Revoke the enrollment at the Host Runtime and delete the local store. Later commands fail closed.
|
|
3856
|
+
Uses the same client selector as enroll status.`,
|
|
3845
3857
|
"enroll serve": `codexhost enroll serve --client <id> --listen <tailscale-ipv4> [--port 4398] --export-file <absolute-path>
|
|
3846
3858
|
Serve one existing local enrollment over Tailscale without restarting Desktop.
|
|
3847
3859
|
Accepts only that client's token and forwards read/send/status/revoke to the live loopback Runtime from the local enroll bootstrap when present.
|
|
@@ -3884,8 +3896,11 @@ function hasHelpOption(arguments_2) {
|
|
|
3884
3896
|
}
|
|
3885
3897
|
function groupHelp(group) {
|
|
3886
3898
|
const usages = Object.entries(COMMAND_HELP).filter(([name]) => name === group || name.startsWith(`${group} `)).map(([, help]) => help.split("\n")[0]);
|
|
3899
|
+
const enrollDetail = group === "enroll" ? `
|
|
3900
|
+
${COMMAND_HELP.enroll.split("\n").slice(1).join("\n")}
|
|
3901
|
+
` : "";
|
|
3887
3902
|
return `${usages.join("\n")}
|
|
3888
|
-
|
|
3903
|
+
${enrollDetail}
|
|
3889
3904
|
${COMMON_HELP}
|
|
3890
3905
|
`;
|
|
3891
3906
|
}
|
|
@@ -4091,7 +4106,7 @@ function matchesBearerToken(header, token) {
|
|
|
4091
4106
|
import { createHash } from "node:crypto";
|
|
4092
4107
|
import { isIPv4 } from "node:net";
|
|
4093
4108
|
var FIXTURE_PARENT_THREAD_ID = "70afcd8a-2124-44e3-aa9d-9a7d4695f97c";
|
|
4094
|
-
var ENROLLMENT_VERBS = ["read", "watch", "send"];
|
|
4109
|
+
var ENROLLMENT_VERBS = ["read", "watch", "send", "cancel"];
|
|
4095
4110
|
var DEFAULT_ENROLLMENT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
4096
4111
|
var MACHINE_ENROLLMENT_TTL_MS = 10 * 365 * 24 * 60 * 60 * 1e3;
|
|
4097
4112
|
var ENROLLMENT_CLOCK_SKEW_MS = 5 * 60 * 1e3;
|
|
@@ -4105,7 +4120,7 @@ function parseEnrollmentClientId(value2) {
|
|
|
4105
4120
|
if (!CLIENT_ID_PATTERN.test(value2)) {
|
|
4106
4121
|
throw new DelegationControlError(
|
|
4107
4122
|
"INVALID_ARGUMENT",
|
|
4108
|
-
"
|
|
4123
|
+
"client id must be a lowercase id such as grok-bot"
|
|
4109
4124
|
);
|
|
4110
4125
|
}
|
|
4111
4126
|
return value2;
|
|
@@ -4297,7 +4312,9 @@ function verifyEnrollmentRecord(record6, nowMs) {
|
|
|
4297
4312
|
}
|
|
4298
4313
|
if (nowMs > expiresAt) {
|
|
4299
4314
|
throw enrollmentError("ENROLLMENT_INVALID", "Enrollment token has expired", "expired", {
|
|
4300
|
-
enrollmentId: record6.enrollmentId
|
|
4315
|
+
enrollmentId: record6.enrollmentId,
|
|
4316
|
+
clientId: record6.clientId,
|
|
4317
|
+
expiresAt: record6.expiresAt
|
|
4301
4318
|
});
|
|
4302
4319
|
}
|
|
4303
4320
|
}
|
|
@@ -4350,7 +4367,6 @@ function authorizeEnrollment(record6, action, nowMs) {
|
|
|
4350
4367
|
}
|
|
4351
4368
|
return;
|
|
4352
4369
|
case "send":
|
|
4353
|
-
case "cancel":
|
|
4354
4370
|
if (!entryAllows(record6, action.threadId, "send")) {
|
|
4355
4371
|
throw enrollmentError(
|
|
4356
4372
|
"UNAUTHORIZED_TARGET",
|
|
@@ -4360,6 +4376,16 @@ function authorizeEnrollment(record6, action, nowMs) {
|
|
|
4360
4376
|
);
|
|
4361
4377
|
}
|
|
4362
4378
|
return;
|
|
4379
|
+
case "cancel":
|
|
4380
|
+
if (!entryAllows(record6, action.threadId, "cancel")) {
|
|
4381
|
+
throw enrollmentError(
|
|
4382
|
+
"UNAUTHORIZED_TARGET",
|
|
4383
|
+
"Thread is not allowlisted for cancel",
|
|
4384
|
+
"denied",
|
|
4385
|
+
{ threadId: action.threadId, verb: "cancel" }
|
|
4386
|
+
);
|
|
4387
|
+
}
|
|
4388
|
+
return;
|
|
4363
4389
|
}
|
|
4364
4390
|
}
|
|
4365
4391
|
function filterEnrollmentThreadList(record6, result) {
|
|
@@ -4419,6 +4445,9 @@ function isPrivateFileMode(mode) {
|
|
|
4419
4445
|
if (process.platform === "win32") return true;
|
|
4420
4446
|
return (mode & 511) === 384;
|
|
4421
4447
|
}
|
|
4448
|
+
function posixFileMode(mode) {
|
|
4449
|
+
return (mode & 511).toString(8).padStart(3, "0");
|
|
4450
|
+
}
|
|
4422
4451
|
async function writePrivateJsonFile(filePath, value2) {
|
|
4423
4452
|
await mkdir(path.dirname(filePath), { recursive: true, mode: 448 });
|
|
4424
4453
|
if (process.platform !== "win32") await chmod(path.dirname(filePath), 448);
|
|
@@ -4479,7 +4508,8 @@ async function readRuntimeEnrollmentRecords(filePath) {
|
|
|
4479
4508
|
throw enrollmentError(
|
|
4480
4509
|
"ENROLLMENT_INVALID",
|
|
4481
4510
|
"Runtime enrollment records are not user-private mode 600",
|
|
4482
|
-
"insecure_store_mode"
|
|
4511
|
+
"insecure_store_mode",
|
|
4512
|
+
{ observedMode: posixFileMode(mode), requiredMode: "600" }
|
|
4483
4513
|
);
|
|
4484
4514
|
}
|
|
4485
4515
|
let parsed2;
|
|
@@ -4501,7 +4531,7 @@ async function writeEnrollmentStore(filePath, record6) {
|
|
|
4501
4531
|
assertEnrollmentBindings(record6);
|
|
4502
4532
|
await writePrivateJsonFile(filePath, record6);
|
|
4503
4533
|
}
|
|
4504
|
-
async function readEnrollmentStore(filePath, nowMs) {
|
|
4534
|
+
async function readEnrollmentStore(filePath, nowMs, expectedClientId) {
|
|
4505
4535
|
let text;
|
|
4506
4536
|
let mode;
|
|
4507
4537
|
try {
|
|
@@ -4524,7 +4554,8 @@ async function readEnrollmentStore(filePath, nowMs) {
|
|
|
4524
4554
|
throw enrollmentError(
|
|
4525
4555
|
"ENROLLMENT_INVALID",
|
|
4526
4556
|
"Enrollment store is not user-private mode 600",
|
|
4527
|
-
"insecure_store_mode"
|
|
4557
|
+
"insecure_store_mode",
|
|
4558
|
+
{ observedMode: posixFileMode(mode), requiredMode: "600" }
|
|
4528
4559
|
);
|
|
4529
4560
|
}
|
|
4530
4561
|
let parsed2;
|
|
@@ -4541,6 +4572,14 @@ async function readEnrollmentStore(filePath, nowMs) {
|
|
|
4541
4572
|
throw enrollmentError("ENROLLMENT_INVALID", "Enrollment store is invalid", "allowlist_tamper");
|
|
4542
4573
|
}
|
|
4543
4574
|
verifyEnrollmentRecord(parsed2, nowMs);
|
|
4575
|
+
if (expectedClientId !== void 0 && parsed2.clientId !== expectedClientId) {
|
|
4576
|
+
throw enrollmentError(
|
|
4577
|
+
"ENROLLMENT_INVALID",
|
|
4578
|
+
"Enrollment store belongs to a different client",
|
|
4579
|
+
"client_mismatch",
|
|
4580
|
+
{ clientId: expectedClientId, storedClientId: parsed2.clientId, storePath: filePath }
|
|
4581
|
+
);
|
|
4582
|
+
}
|
|
4544
4583
|
return parsed2;
|
|
4545
4584
|
}
|
|
4546
4585
|
async function deleteEnrollmentStore(filePath) {
|
|
@@ -4571,7 +4610,8 @@ async function readEnrollmentBootstrap(filePath) {
|
|
|
4571
4610
|
throw enrollmentError(
|
|
4572
4611
|
"ENROLLMENT_INVALID",
|
|
4573
4612
|
"Enrollment bootstrap is not user-private mode 600",
|
|
4574
|
-
"insecure_store_mode"
|
|
4613
|
+
"insecure_store_mode",
|
|
4614
|
+
{ observedMode: posixFileMode(mode), requiredMode: "600" }
|
|
4575
4615
|
);
|
|
4576
4616
|
}
|
|
4577
4617
|
let parsed2;
|
|
@@ -4598,6 +4638,13 @@ async function readEnrollmentBootstrap(filePath) {
|
|
|
4598
4638
|
|
|
4599
4639
|
// packages/host-runtime/src/delegation-cli-enrollment.ts
|
|
4600
4640
|
import path2 from "node:path";
|
|
4641
|
+
var ENROLLED_CLIENT_OPTION = "--enrolled-client";
|
|
4642
|
+
var HOST_IDENTITY_ENVS = [
|
|
4643
|
+
DELEGATION_RUNTIME_ENDPOINT_ENV,
|
|
4644
|
+
DELEGATION_RUNTIME_TOKEN_ENV,
|
|
4645
|
+
DELEGATION_THREAD_ID_ENV,
|
|
4646
|
+
NATIVE_CODEX_THREAD_ID_ENV
|
|
4647
|
+
];
|
|
4601
4648
|
function missingRuntimeEnvironmentError(endpoint, token) {
|
|
4602
4649
|
const missingEnvironmentVariables = [
|
|
4603
4650
|
...!endpoint ? [DELEGATION_RUNTIME_ENDPOINT_ENV] : [],
|
|
@@ -4622,6 +4669,29 @@ function missingRuntimeEnvironmentError(endpoint, token) {
|
|
|
4622
4669
|
function option(parsed2, name) {
|
|
4623
4670
|
return parsed2.options.get(name);
|
|
4624
4671
|
}
|
|
4672
|
+
function presentEnv(environment, names) {
|
|
4673
|
+
return names.filter((name) => Boolean(environment[name]));
|
|
4674
|
+
}
|
|
4675
|
+
function enrollmentRecovery(reason, clientId) {
|
|
4676
|
+
if (reason === "expired" || reason === "missing_store" || reason === "consent_ui_unavailable") {
|
|
4677
|
+
return `Request a new enrollment from an authorized Host session: codexhost enroll --client ${clientId} --machine`;
|
|
4678
|
+
}
|
|
4679
|
+
if (reason === "insecure_store_mode") {
|
|
4680
|
+
return "Re-enroll from an authorized Host session. Do not chmod a store whose origin is untrusted.";
|
|
4681
|
+
}
|
|
4682
|
+
return void 0;
|
|
4683
|
+
}
|
|
4684
|
+
function annotateEnrollmentClientError(error51, details) {
|
|
4685
|
+
if (!(error51 instanceof DelegationControlError)) throw error51;
|
|
4686
|
+
const reason = error51.details?.reason;
|
|
4687
|
+
const recovery = enrollmentRecovery(reason, details.clientId);
|
|
4688
|
+
throw new DelegationControlError(error51.code, error51.message, {
|
|
4689
|
+
...error51.details,
|
|
4690
|
+
clientId: details.clientId,
|
|
4691
|
+
storePath: details.storePath,
|
|
4692
|
+
...recovery ? { recovery } : {}
|
|
4693
|
+
});
|
|
4694
|
+
}
|
|
4625
4695
|
function rejectEnrollmentAttackOptions(environment, parsed2) {
|
|
4626
4696
|
const fromPid = option(parsed2, "--from-pid");
|
|
4627
4697
|
const fromEnvFile = option(parsed2, "--from-env-file");
|
|
@@ -4633,8 +4703,108 @@ function rejectEnrollmentAttackOptions(environment, parsed2) {
|
|
|
4633
4703
|
...asThread ? { asThread } : {}
|
|
4634
4704
|
});
|
|
4635
4705
|
}
|
|
4706
|
+
function selectedEnrollmentClientId(parsed2, environment) {
|
|
4707
|
+
const enrolled = option(parsed2, ENROLLED_CLIENT_OPTION);
|
|
4708
|
+
const client = option(parsed2, "--client");
|
|
4709
|
+
if (enrolled && client && enrolled !== client) {
|
|
4710
|
+
throw new DelegationControlError(
|
|
4711
|
+
"INVALID_ARGUMENT",
|
|
4712
|
+
"--client and --enrolled-client must name the same client"
|
|
4713
|
+
);
|
|
4714
|
+
}
|
|
4715
|
+
return parseEnrollmentClientId(
|
|
4716
|
+
enrolled ?? client ?? environment[DELEGATION_ENROLL_CLIENT_ENV] ?? DEFAULT_ENROLLMENT_CLIENT_ID
|
|
4717
|
+
);
|
|
4718
|
+
}
|
|
4719
|
+
function inspectCliAuthentication(input) {
|
|
4720
|
+
const enrolled = option(input.parsed, ENROLLED_CLIENT_OPTION);
|
|
4721
|
+
const endpoint = input.environment[DELEGATION_RUNTIME_ENDPOINT_ENV];
|
|
4722
|
+
const token = input.environment[DELEGATION_RUNTIME_TOKEN_ENV];
|
|
4723
|
+
if (enrolled) {
|
|
4724
|
+
return {
|
|
4725
|
+
source: "enrollment",
|
|
4726
|
+
clientId: input.clientId,
|
|
4727
|
+
...input.enrollmentThreadId ? { callerThreadId: input.enrollmentThreadId } : {},
|
|
4728
|
+
ignoredAmbient: presentEnv(input.environment, HOST_IDENTITY_ENVS)
|
|
4729
|
+
};
|
|
4730
|
+
}
|
|
4731
|
+
if (Boolean(endpoint) !== Boolean(token)) {
|
|
4732
|
+
return {
|
|
4733
|
+
source: "incomplete-host-session",
|
|
4734
|
+
clientId: input.clientId,
|
|
4735
|
+
ignoredAmbient: [],
|
|
4736
|
+
missingEnvironmentVariables: [
|
|
4737
|
+
...!endpoint ? [DELEGATION_RUNTIME_ENDPOINT_ENV] : [],
|
|
4738
|
+
...!token ? [DELEGATION_RUNTIME_TOKEN_ENV] : []
|
|
4739
|
+
]
|
|
4740
|
+
};
|
|
4741
|
+
}
|
|
4742
|
+
if (endpoint && token) {
|
|
4743
|
+
const callerThreadId = input.environment[DELEGATION_THREAD_ID_ENV] || input.environment[NATIVE_CODEX_THREAD_ID_ENV] || void 0;
|
|
4744
|
+
return {
|
|
4745
|
+
source: "host-session",
|
|
4746
|
+
clientId: input.clientId,
|
|
4747
|
+
...callerThreadId ? { callerThreadId } : {},
|
|
4748
|
+
ignoredAmbient: []
|
|
4749
|
+
};
|
|
4750
|
+
}
|
|
4751
|
+
return {
|
|
4752
|
+
source: "enrollment",
|
|
4753
|
+
clientId: input.clientId,
|
|
4754
|
+
...input.enrollmentThreadId ? { callerThreadId: input.enrollmentThreadId } : {},
|
|
4755
|
+
ignoredAmbient: presentEnv(input.environment, [
|
|
4756
|
+
DELEGATION_THREAD_ID_ENV,
|
|
4757
|
+
NATIVE_CODEX_THREAD_ID_ENV
|
|
4758
|
+
])
|
|
4759
|
+
};
|
|
4760
|
+
}
|
|
4761
|
+
function explicitEnrollmentClientSelected(parsed2, environment) {
|
|
4762
|
+
return Boolean(
|
|
4763
|
+
option(parsed2, ENROLLED_CLIENT_OPTION) || option(parsed2, "--client") || environment[DELEGATION_ENROLL_CLIENT_ENV]
|
|
4764
|
+
);
|
|
4765
|
+
}
|
|
4766
|
+
async function loadEnrollmentConnection(input) {
|
|
4767
|
+
const storePath = enrollmentStorePath(input.environment, input.clientId);
|
|
4768
|
+
try {
|
|
4769
|
+
const [record6, liveEndpoint] = await Promise.all([
|
|
4770
|
+
readEnrollmentStore(storePath, input.nowMs, input.clientId),
|
|
4771
|
+
readLiveEnrollmentEndpoint(input.environment)
|
|
4772
|
+
]);
|
|
4773
|
+
if (!record6) {
|
|
4774
|
+
if (input.explicit) {
|
|
4775
|
+
throw enrollmentError(
|
|
4776
|
+
"ENROLLMENT_INVALID",
|
|
4777
|
+
"No enrollment store is present",
|
|
4778
|
+
"missing_store",
|
|
4779
|
+
{ clientId: input.clientId, storePath }
|
|
4780
|
+
);
|
|
4781
|
+
}
|
|
4782
|
+
throw missingRuntimeEnvironmentError(void 0, void 0);
|
|
4783
|
+
}
|
|
4784
|
+
return {
|
|
4785
|
+
endpoint: enrollmentClientEndpoint(record6, liveEndpoint),
|
|
4786
|
+
token: record6.token,
|
|
4787
|
+
callerThreadId: record6.threadId,
|
|
4788
|
+
source: "enrollment"
|
|
4789
|
+
};
|
|
4790
|
+
} catch (error51) {
|
|
4791
|
+
if (error51 instanceof DelegationControlError && error51.details?.reason === "missing_runtime_environment") {
|
|
4792
|
+
throw error51;
|
|
4793
|
+
}
|
|
4794
|
+
annotateEnrollmentClientError(error51, { clientId: input.clientId, storePath });
|
|
4795
|
+
}
|
|
4796
|
+
}
|
|
4636
4797
|
async function resolveCliRuntimeConnection(input) {
|
|
4637
4798
|
rejectEnrollmentAttackOptions(input.environment, input.parsed);
|
|
4799
|
+
const enrolledClient = option(input.parsed, ENROLLED_CLIENT_OPTION);
|
|
4800
|
+
if (enrolledClient) {
|
|
4801
|
+
return loadEnrollmentConnection({
|
|
4802
|
+
environment: input.environment,
|
|
4803
|
+
clientId: parseEnrollmentClientId(enrolledClient),
|
|
4804
|
+
nowMs: input.nowMs,
|
|
4805
|
+
explicit: true
|
|
4806
|
+
});
|
|
4807
|
+
}
|
|
4638
4808
|
const endpoint = input.environment[DELEGATION_RUNTIME_ENDPOINT_ENV];
|
|
4639
4809
|
const token = input.environment[DELEGATION_RUNTIME_TOKEN_ENV];
|
|
4640
4810
|
if (endpoint && token) {
|
|
@@ -4647,20 +4817,13 @@ async function resolveCliRuntimeConnection(input) {
|
|
|
4647
4817
|
};
|
|
4648
4818
|
}
|
|
4649
4819
|
if (endpoint || token) throw missingRuntimeEnvironmentError(endpoint, token);
|
|
4650
|
-
const clientId =
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
if (!record6) throw missingRuntimeEnvironmentError(void 0, void 0);
|
|
4658
|
-
return {
|
|
4659
|
-
endpoint: enrollmentClientEndpoint(record6, liveEndpoint),
|
|
4660
|
-
token: record6.token,
|
|
4661
|
-
callerThreadId: record6.threadId,
|
|
4662
|
-
source: "enrollment"
|
|
4663
|
-
};
|
|
4820
|
+
const clientId = selectedEnrollmentClientId(input.parsed, input.environment);
|
|
4821
|
+
return loadEnrollmentConnection({
|
|
4822
|
+
environment: input.environment,
|
|
4823
|
+
clientId,
|
|
4824
|
+
nowMs: input.nowMs,
|
|
4825
|
+
explicit: explicitEnrollmentClientSelected(input.parsed, input.environment)
|
|
4826
|
+
});
|
|
4664
4827
|
}
|
|
4665
4828
|
function enrollmentClientEndpoint(record6, liveEndpoint) {
|
|
4666
4829
|
return record6.networkScope === "tailnet" ? record6.endpoint : liveEndpoint ?? record6.endpoint;
|
|
@@ -4734,31 +4897,70 @@ async function runEnrollRequest(input) {
|
|
|
4734
4897
|
}
|
|
4735
4898
|
async function runEnrollStatus(input) {
|
|
4736
4899
|
rejectEnrollmentAttackOptions(input.environment, input.parsed);
|
|
4737
|
-
const clientId =
|
|
4738
|
-
option(input.parsed, "--client") ?? DEFAULT_ENROLLMENT_CLIENT_ID
|
|
4739
|
-
);
|
|
4900
|
+
const clientId = selectedEnrollmentClientId(input.parsed, input.environment);
|
|
4740
4901
|
const storePath = enrollmentStorePath(input.environment, clientId);
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4902
|
+
try {
|
|
4903
|
+
const record6 = await readEnrollmentStore(storePath, input.nowMs, clientId);
|
|
4904
|
+
if (!record6) {
|
|
4905
|
+
throw enrollmentError(
|
|
4906
|
+
"ENROLLMENT_INVALID",
|
|
4907
|
+
"No enrollment store is present",
|
|
4908
|
+
"missing_store",
|
|
4909
|
+
{
|
|
4910
|
+
clientId,
|
|
4911
|
+
storePath
|
|
4912
|
+
}
|
|
4913
|
+
);
|
|
4914
|
+
}
|
|
4915
|
+
const authentication = inspectCliAuthentication({
|
|
4916
|
+
environment: input.environment,
|
|
4917
|
+
parsed: input.parsed,
|
|
4918
|
+
clientId,
|
|
4919
|
+
enrollmentThreadId: record6.threadId
|
|
4745
4920
|
});
|
|
4921
|
+
return {
|
|
4922
|
+
storePath,
|
|
4923
|
+
view: { ...publicEnrollmentView(record6), storePath, authentication }
|
|
4924
|
+
};
|
|
4925
|
+
} catch (error51) {
|
|
4926
|
+
if (error51 instanceof DelegationControlError) {
|
|
4927
|
+
const authentication = inspectCliAuthentication({
|
|
4928
|
+
environment: input.environment,
|
|
4929
|
+
parsed: input.parsed,
|
|
4930
|
+
clientId
|
|
4931
|
+
});
|
|
4932
|
+
const reason = error51.details?.reason;
|
|
4933
|
+
const recovery = enrollmentRecovery(reason, clientId);
|
|
4934
|
+
throw new DelegationControlError(error51.code, error51.message, {
|
|
4935
|
+
...error51.details,
|
|
4936
|
+
clientId,
|
|
4937
|
+
storePath,
|
|
4938
|
+
authentication,
|
|
4939
|
+
...recovery ? { recovery } : {}
|
|
4940
|
+
});
|
|
4941
|
+
}
|
|
4942
|
+
throw error51;
|
|
4746
4943
|
}
|
|
4747
|
-
return { storePath, view: { ...publicEnrollmentView(record6), storePath } };
|
|
4748
4944
|
}
|
|
4749
4945
|
async function runEnrollRevoke(input) {
|
|
4750
4946
|
rejectEnrollmentAttackOptions(input.environment, input.parsed);
|
|
4751
|
-
const clientId =
|
|
4752
|
-
option(input.parsed, "--client") ?? DEFAULT_ENROLLMENT_CLIENT_ID
|
|
4753
|
-
);
|
|
4947
|
+
const clientId = selectedEnrollmentClientId(input.parsed, input.environment);
|
|
4754
4948
|
const storePath = enrollmentStorePath(input.environment, clientId);
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4949
|
+
let record6;
|
|
4950
|
+
let liveEndpoint;
|
|
4951
|
+
try {
|
|
4952
|
+
[record6, liveEndpoint] = await Promise.all([
|
|
4953
|
+
readEnrollmentStore(storePath, input.nowMs, clientId),
|
|
4954
|
+
readLiveEnrollmentEndpoint(input.environment)
|
|
4955
|
+
]);
|
|
4956
|
+
} catch (error51) {
|
|
4957
|
+
annotateEnrollmentClientError(error51, { clientId, storePath });
|
|
4958
|
+
}
|
|
4759
4959
|
if (!record6) {
|
|
4760
4960
|
throw new DelegationControlError("ENROLLMENT_INVALID", "No enrollment store is present", {
|
|
4761
|
-
reason: "revoked"
|
|
4961
|
+
reason: "revoked",
|
|
4962
|
+
clientId,
|
|
4963
|
+
storePath
|
|
4762
4964
|
});
|
|
4763
4965
|
}
|
|
4764
4966
|
await input.request(
|
|
@@ -4896,7 +5098,8 @@ async function runEnrollmentTailnetServe(input) {
|
|
|
4896
5098
|
}
|
|
4897
5099
|
const record6 = await readEnrollmentStore(
|
|
4898
5100
|
enrollmentStorePath(input.environment, clientId),
|
|
4899
|
-
Date.now()
|
|
5101
|
+
Date.now(),
|
|
5102
|
+
clientId
|
|
4900
5103
|
);
|
|
4901
5104
|
if (!record6) throw new DelegationControlError("ENROLLMENT_INVALID", "Enroll this client first");
|
|
4902
5105
|
const server = createEnrollmentTailnetServer(
|
|
@@ -5007,6 +5210,9 @@ function rejectUnknown(parsed2, allowed) {
|
|
|
5007
5210
|
throw new DelegationControlError("INVALID_ARGUMENT", `Unknown option '${name}'`);
|
|
5008
5211
|
}
|
|
5009
5212
|
}
|
|
5213
|
+
function runtimeOptions(allowed) {
|
|
5214
|
+
return [...allowed, ENROLLED_CLIENT_OPTION];
|
|
5215
|
+
}
|
|
5010
5216
|
async function requestRuntime(input) {
|
|
5011
5217
|
const { endpoint, token } = input.connection;
|
|
5012
5218
|
let response;
|
|
@@ -5113,7 +5319,7 @@ async function runDelegationCli(input) {
|
|
|
5113
5319
|
"--from-pid",
|
|
5114
5320
|
"--from-env-file",
|
|
5115
5321
|
"--as-thread"
|
|
5116
|
-
] : ["--client", "--from-pid", "--from-env-file", "--as-thread"];
|
|
5322
|
+
] : ["--client", ENROLLED_CLIENT_OPTION, "--from-pid", "--from-env-file", "--as-thread"];
|
|
5117
5323
|
rejectUnknown(parsed3, enrollOptions);
|
|
5118
5324
|
if (parsed3.positionals.length > 0) {
|
|
5119
5325
|
throw new DelegationControlError(
|
|
@@ -5159,7 +5365,7 @@ async function runDelegationCli(input) {
|
|
|
5159
5365
|
...input.fetchImpl ? { fetchImpl: input.fetchImpl } : {}
|
|
5160
5366
|
});
|
|
5161
5367
|
if (group === "harness" && command === "list") {
|
|
5162
|
-
rejectUnknown(parsed2, []);
|
|
5368
|
+
rejectUnknown(parsed2, runtimeOptions([]));
|
|
5163
5369
|
if (parsed2.positionals.length > 0) {
|
|
5164
5370
|
throw new DelegationControlError(
|
|
5165
5371
|
"INVALID_ARGUMENT",
|
|
@@ -5170,7 +5376,7 @@ async function runDelegationCli(input) {
|
|
|
5170
5376
|
return 0;
|
|
5171
5377
|
}
|
|
5172
5378
|
if (group === "harness" && command === "inspect") {
|
|
5173
|
-
rejectUnknown(parsed2, ["--cwd", "--refresh"]);
|
|
5379
|
+
rejectUnknown(parsed2, runtimeOptions(["--cwd", "--refresh"]));
|
|
5174
5380
|
if (parsed2.positionals.length !== 1) {
|
|
5175
5381
|
throw new DelegationControlError(
|
|
5176
5382
|
"INVALID_ARGUMENT",
|
|
@@ -5196,19 +5402,22 @@ async function runDelegationCli(input) {
|
|
|
5196
5402
|
return 0;
|
|
5197
5403
|
}
|
|
5198
5404
|
if (group === "delegate" && command === "start") {
|
|
5199
|
-
rejectUnknown(
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5405
|
+
rejectUnknown(
|
|
5406
|
+
parsed2,
|
|
5407
|
+
runtimeOptions([
|
|
5408
|
+
"--harness",
|
|
5409
|
+
"--task",
|
|
5410
|
+
"--task-name",
|
|
5411
|
+
"--cwd",
|
|
5412
|
+
"--model",
|
|
5413
|
+
"--thinking",
|
|
5414
|
+
"--parent-thread",
|
|
5415
|
+
"--request-id",
|
|
5416
|
+
"--watch",
|
|
5417
|
+
"--watch-timeout-ms",
|
|
5418
|
+
"--fallback-default"
|
|
5419
|
+
])
|
|
5420
|
+
);
|
|
5212
5421
|
if (parsed2.positionals.length > 0)
|
|
5213
5422
|
throw new DelegationControlError(
|
|
5214
5423
|
"INVALID_ARGUMENT",
|
|
@@ -5248,7 +5457,7 @@ async function runDelegationCli(input) {
|
|
|
5248
5457
|
return 0;
|
|
5249
5458
|
}
|
|
5250
5459
|
if (group === "thread" && command === "send") {
|
|
5251
|
-
rejectUnknown(parsed2, ["--message"]);
|
|
5460
|
+
rejectUnknown(parsed2, runtimeOptions(["--message"]));
|
|
5252
5461
|
if (parsed2.positionals.length !== 1) {
|
|
5253
5462
|
throw new DelegationControlError(
|
|
5254
5463
|
"INVALID_ARGUMENT",
|
|
@@ -5270,7 +5479,7 @@ async function runDelegationCli(input) {
|
|
|
5270
5479
|
return 0;
|
|
5271
5480
|
}
|
|
5272
5481
|
if (group === "thread" && command === "cancel") {
|
|
5273
|
-
rejectUnknown(parsed2, []);
|
|
5482
|
+
rejectUnknown(parsed2, runtimeOptions([]));
|
|
5274
5483
|
if (parsed2.positionals.length !== 1) {
|
|
5275
5484
|
throw new DelegationControlError(
|
|
5276
5485
|
"INVALID_ARGUMENT",
|
|
@@ -5288,13 +5497,16 @@ async function runDelegationCli(input) {
|
|
|
5288
5497
|
return 0;
|
|
5289
5498
|
}
|
|
5290
5499
|
if (group === "thread" && (command === "read" || command === "wait")) {
|
|
5291
|
-
rejectUnknown(
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5500
|
+
rejectUnknown(
|
|
5501
|
+
parsed2,
|
|
5502
|
+
runtimeOptions([
|
|
5503
|
+
"--view",
|
|
5504
|
+
"--cursor",
|
|
5505
|
+
"--limit",
|
|
5506
|
+
"--timeout-ms",
|
|
5507
|
+
...command === "read" ? ["--host"] : []
|
|
5508
|
+
])
|
|
5509
|
+
);
|
|
5298
5510
|
if (parsed2.positionals.length !== 1)
|
|
5299
5511
|
throw new DelegationControlError(
|
|
5300
5512
|
"INVALID_ARGUMENT",
|
|
@@ -5344,7 +5556,7 @@ async function runDelegationCli(input) {
|
|
|
5344
5556
|
return 0;
|
|
5345
5557
|
}
|
|
5346
5558
|
if (group === "thread" && command === "watch") {
|
|
5347
|
-
rejectUnknown(parsed2, ["--notify", "--timeout-ms"]);
|
|
5559
|
+
rejectUnknown(parsed2, runtimeOptions(["--notify", "--timeout-ms"]));
|
|
5348
5560
|
if (parsed2.positionals.length !== 1)
|
|
5349
5561
|
throw new DelegationControlError(
|
|
5350
5562
|
"INVALID_ARGUMENT",
|
|
@@ -5370,7 +5582,7 @@ async function runDelegationCli(input) {
|
|
|
5370
5582
|
return 0;
|
|
5371
5583
|
}
|
|
5372
5584
|
if (group === "thread" && command === "watches") {
|
|
5373
|
-
rejectUnknown(parsed2, []);
|
|
5585
|
+
rejectUnknown(parsed2, runtimeOptions([]));
|
|
5374
5586
|
if (parsed2.positionals.length > 0)
|
|
5375
5587
|
throw new DelegationControlError(
|
|
5376
5588
|
"INVALID_ARGUMENT",
|
|
@@ -5380,7 +5592,7 @@ async function runDelegationCli(input) {
|
|
|
5380
5592
|
return 0;
|
|
5381
5593
|
}
|
|
5382
5594
|
if (group === "thread" && command === "list") {
|
|
5383
|
-
rejectUnknown(parsed2, ["--cwd", "--parent", "--limit", "--cursor", "--sort"]);
|
|
5595
|
+
rejectUnknown(parsed2, runtimeOptions(["--cwd", "--parent", "--limit", "--cursor", "--sort"]));
|
|
5384
5596
|
if (parsed2.positionals.length > 0)
|
|
5385
5597
|
throw new DelegationControlError(
|
|
5386
5598
|
"INVALID_ARGUMENT",
|
|
@@ -21310,7 +21522,7 @@ var ENROLLMENT_LIST_METHOD = "codexhost/enrollment/list";
|
|
|
21310
21522
|
var ENROLLMENT_REVOKE_METHOD = "codexhost/enrollment/revoke";
|
|
21311
21523
|
var enrollmentAllowlistEntrySchema = external_exports.strictObject({
|
|
21312
21524
|
threadId: external_exports.string().trim().min(1).max(128),
|
|
21313
|
-
verbs: external_exports.array(external_exports.enum(["read", "watch", "send"])).min(1).max(
|
|
21525
|
+
verbs: external_exports.array(external_exports.enum(["read", "watch", "send", "cancel"])).min(1).max(4)
|
|
21314
21526
|
});
|
|
21315
21527
|
var enrollmentPublicViewSchema = external_exports.strictObject({
|
|
21316
21528
|
enrollmentId: external_exports.string().trim().min(1).max(128),
|
|
@@ -40155,7 +40367,7 @@ var HarnessDelegationCoordinator = class {
|
|
|
40155
40367
|
});
|
|
40156
40368
|
}
|
|
40157
40369
|
if (this.#externalThreadBusy(thread) || thread.activeTurnId) {
|
|
40158
|
-
throw
|
|
40370
|
+
throw threadBusyError(input.threadId);
|
|
40159
40371
|
}
|
|
40160
40372
|
const turnId = hostTurnIdSchema.parse(randomUUID16());
|
|
40161
40373
|
try {
|
|
@@ -46646,7 +46858,7 @@ var AppServerHost = class {
|
|
|
46646
46858
|
throw new DelegationControlError("INVALID_ARGUMENT", "Message must not be empty");
|
|
46647
46859
|
}
|
|
46648
46860
|
if (this.#activeOfficialTurns.has(input.threadId)) {
|
|
46649
|
-
throw
|
|
46861
|
+
throw threadBusyError(input.threadId);
|
|
46650
46862
|
}
|
|
46651
46863
|
const current = await this.#requestOfficial("thread/read", {
|
|
46652
46864
|
threadId: input.threadId,
|
|
@@ -46658,7 +46870,7 @@ var AppServerHost = class {
|
|
|
46658
46870
|
}
|
|
46659
46871
|
const currentThread = isRecord21(current.result.thread) ? current.result.thread : null;
|
|
46660
46872
|
if (officialThreadBusy(currentThread)) {
|
|
46661
|
-
throw
|
|
46873
|
+
throw threadBusyError(input.threadId);
|
|
46662
46874
|
}
|
|
46663
46875
|
const resumed = await this.#requestOfficial("thread/resume", {
|
|
46664
46876
|
threadId: input.threadId,
|
|
@@ -46680,7 +46892,7 @@ var AppServerHost = class {
|
|
|
46680
46892
|
);
|
|
46681
46893
|
}
|
|
46682
46894
|
if (officialThreadBusy(resumedThread)) {
|
|
46683
|
-
throw
|
|
46895
|
+
throw threadBusyError(input.threadId);
|
|
46684
46896
|
}
|
|
46685
46897
|
if (!isRecord21(resumedThread.status) || resumedThread.status.type !== "idle") {
|
|
46686
46898
|
throw new DelegationControlError(
|
|
@@ -51642,6 +51854,15 @@ function installedHarnessPluginOptions(environment, managedRemoteHost = false, h
|
|
|
51642
51854
|
// packages/host-runtime/src/delegation-control-server.ts
|
|
51643
51855
|
import { createServer as createServer4 } from "node:http";
|
|
51644
51856
|
var MAX_REQUEST_BYTES2 = 2 * 1024 * 1024;
|
|
51857
|
+
function annotateEnrollmentBusy(error51, principal) {
|
|
51858
|
+
if (!(error51 instanceof DelegationControlError) || error51.code !== "THREAD_BUSY" || principal?.kind !== "enrollment") {
|
|
51859
|
+
return error51;
|
|
51860
|
+
}
|
|
51861
|
+
return new DelegationControlError(error51.code, error51.message, {
|
|
51862
|
+
...error51.details,
|
|
51863
|
+
authorized: true
|
|
51864
|
+
});
|
|
51865
|
+
}
|
|
51645
51866
|
function errorBody(error51) {
|
|
51646
51867
|
if (error51 instanceof DelegationControlError) {
|
|
51647
51868
|
return {
|
|
@@ -51747,6 +51968,7 @@ async function startWithWatch(api, watches, body) {
|
|
|
51747
51968
|
}
|
|
51748
51969
|
async function startDelegationControlServer(input) {
|
|
51749
51970
|
const server = createServer4((request, response) => {
|
|
51971
|
+
let principal;
|
|
51750
51972
|
void (async () => {
|
|
51751
51973
|
if (request.method !== "POST") {
|
|
51752
51974
|
writeJson2(response, 405, {
|
|
@@ -51781,7 +52003,7 @@ async function startDelegationControlServer(input) {
|
|
|
51781
52003
|
writeJson2(response, 200, record6);
|
|
51782
52004
|
return;
|
|
51783
52005
|
}
|
|
51784
|
-
|
|
52006
|
+
principal = authenticateControlRequest(
|
|
51785
52007
|
request.headers.authorization,
|
|
51786
52008
|
input.token,
|
|
51787
52009
|
input.enrollment
|
|
@@ -51869,7 +52091,8 @@ async function startDelegationControlServer(input) {
|
|
|
51869
52091
|
throw new DelegationControlError("INVALID_ARGUMENT", "Unknown Runtime control route");
|
|
51870
52092
|
}
|
|
51871
52093
|
})().catch((error51) => {
|
|
51872
|
-
|
|
52094
|
+
const annotated = annotateEnrollmentBusy(error51, principal);
|
|
52095
|
+
writeJson2(response, enrollmentHttpStatus(annotated), errorBody(annotated));
|
|
51873
52096
|
});
|
|
51874
52097
|
});
|
|
51875
52098
|
await new Promise((resolve, reject) => {
|
|
@@ -51892,18 +52115,13 @@ import { rm as rm17 } from "node:fs/promises";
|
|
|
51892
52115
|
import path40 from "node:path";
|
|
51893
52116
|
|
|
51894
52117
|
// packages/host-runtime/src/client-enrollment-consent.ts
|
|
51895
|
-
function
|
|
52118
|
+
function createUnavailableEnrollmentConsent() {
|
|
51896
52119
|
return {
|
|
51897
52120
|
async decide() {
|
|
51898
|
-
|
|
51899
|
-
await new Promise((resolve) => {
|
|
51900
|
-
setTimeout(resolve, input.timeoutMs);
|
|
51901
|
-
});
|
|
51902
|
-
return "timeout";
|
|
52121
|
+
return "unavailable";
|
|
51903
52122
|
}
|
|
51904
52123
|
};
|
|
51905
52124
|
}
|
|
51906
|
-
var DEFAULT_ENROLLMENT_CONSENT_TIMEOUT_MS = 6e4;
|
|
51907
52125
|
|
|
51908
52126
|
// packages/host-runtime/src/client-enrollment-authority.ts
|
|
51909
52127
|
var EnrollmentAuthority = class {
|
|
@@ -51921,9 +52139,7 @@ var EnrollmentAuthority = class {
|
|
|
51921
52139
|
constructor(input) {
|
|
51922
52140
|
this.#hostToken = input.hostToken;
|
|
51923
52141
|
this.#bootstrapToken = input.bootstrapToken ?? randomBytes4(32).toString("hex");
|
|
51924
|
-
this.#consent = input.consent ??
|
|
51925
|
-
timeoutMs: DEFAULT_ENROLLMENT_CONSENT_TIMEOUT_MS
|
|
51926
|
-
});
|
|
52142
|
+
this.#consent = input.consent ?? createUnavailableEnrollmentConsent();
|
|
51927
52143
|
this.#dataDirectory = input.dataDirectory;
|
|
51928
52144
|
this.#now = input.now ?? Date.now;
|
|
51929
52145
|
this.#createId = input.createId ?? randomUUID23;
|
|
@@ -52034,9 +52250,16 @@ var EnrollmentAuthority = class {
|
|
|
52034
52250
|
if (decision === "deny") {
|
|
52035
52251
|
throw enrollmentError("ENROLLMENT_DENIED", "Enrollment was denied", "denied");
|
|
52036
52252
|
}
|
|
52037
|
-
if (decision
|
|
52253
|
+
if (decision === "timeout") {
|
|
52038
52254
|
throw enrollmentError("ENROLLMENT_DENIED", "Enrollment timed out", "timeout");
|
|
52039
52255
|
}
|
|
52256
|
+
if (decision !== "approve") {
|
|
52257
|
+
throw enrollmentError(
|
|
52258
|
+
"ENROLLMENT_DENIED",
|
|
52259
|
+
"Desktop has no enrollment consent UI. Request enrollment from an authorized Host session.",
|
|
52260
|
+
"consent_ui_unavailable"
|
|
52261
|
+
);
|
|
52262
|
+
}
|
|
52040
52263
|
if (pairing === "machine") this.#revokeActiveForClient(clientId);
|
|
52041
52264
|
const enrollmentId = this.#createId();
|
|
52042
52265
|
const threadId2 = this.#createId();
|
|
@@ -54052,7 +54275,7 @@ async function prepareDelegationRuntime(input) {
|
|
|
54052
54275
|
const enrollment = new EnrollmentAuthority({
|
|
54053
54276
|
hostToken: token,
|
|
54054
54277
|
dataDirectory: codexhostDataDirectory(input.environment),
|
|
54055
|
-
consent:
|
|
54278
|
+
consent: createUnavailableEnrollmentConsent()
|
|
54056
54279
|
});
|
|
54057
54280
|
const server = await startDelegationControlServer({
|
|
54058
54281
|
token,
|