@karlorz/codexhost-cli-win32-x64 0.17.4-3 → 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 +30 -0
- package/app/console-web.js +302 -2
- package/app/cpa-live-voice-hook.js +30 -0
- package/app/desktop-controller.mjs +30 -0
- package/app/host-runtime.mjs +452 -105
- package/app/plugins/antigravity/plugin.mjs +30 -0
- package/app/plugins/claude-code/plugin.mjs +30 -0
- package/app/plugins/codebuddy/plugin.mjs +30 -0
- package/app/plugins/codex-usage/plugin.mjs +30 -0
- package/app/plugins/copilot/plugin.mjs +30 -0
- package/app/plugins/cursor-cli/plugin.mjs +30 -0
- package/app/plugins/deepseek-harness/plugin.mjs +30 -0
- package/app/plugins/devin/plugin.mjs +30 -0
- package/app/plugins/grok/plugin.mjs +30 -0
- package/app/plugins/hermes/plugin.mjs +30 -0
- package/app/plugins/kimi-code/plugin.mjs +30 -0
- package/app/plugins/kiro-cli/plugin.mjs +30 -0
- package/app/plugins/omp/plugin.mjs +30 -0
- package/app/plugins/opencode/plugin.mjs +30 -0
- package/app/plugins/pi/plugin.mjs +30 -0
- package/app/plugins/qoder/plugin.mjs +30 -0
- package/app/plugins/qoder-cn/plugin.mjs +30 -0
- package/app/plugins/qwen-code/plugin.mjs +30 -0
- package/app/plugins/workbuddy/plugin.mjs +30 -0
- package/app/plugins/zcode/plugin.mjs +30 -0
- package/app/renderer-extension.js +300 -2
- 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) {
|
|
@@ -4380,7 +4406,9 @@ function publicEnrollmentView(record6) {
|
|
|
4380
4406
|
enrollmentId: record6.enrollmentId,
|
|
4381
4407
|
threadId: record6.threadId,
|
|
4382
4408
|
clientId: record6.clientId,
|
|
4409
|
+
executablePath: record6.executablePath,
|
|
4383
4410
|
endpoint: record6.endpoint,
|
|
4411
|
+
issuedAt: record6.issuedAt,
|
|
4384
4412
|
expiresAt: record6.expiresAt,
|
|
4385
4413
|
pairing: record6.pairing ?? "session",
|
|
4386
4414
|
allowlist: record6.allowlist
|
|
@@ -4417,6 +4445,9 @@ function isPrivateFileMode(mode) {
|
|
|
4417
4445
|
if (process.platform === "win32") return true;
|
|
4418
4446
|
return (mode & 511) === 384;
|
|
4419
4447
|
}
|
|
4448
|
+
function posixFileMode(mode) {
|
|
4449
|
+
return (mode & 511).toString(8).padStart(3, "0");
|
|
4450
|
+
}
|
|
4420
4451
|
async function writePrivateJsonFile(filePath, value2) {
|
|
4421
4452
|
await mkdir(path.dirname(filePath), { recursive: true, mode: 448 });
|
|
4422
4453
|
if (process.platform !== "win32") await chmod(path.dirname(filePath), 448);
|
|
@@ -4477,7 +4508,8 @@ async function readRuntimeEnrollmentRecords(filePath) {
|
|
|
4477
4508
|
throw enrollmentError(
|
|
4478
4509
|
"ENROLLMENT_INVALID",
|
|
4479
4510
|
"Runtime enrollment records are not user-private mode 600",
|
|
4480
|
-
"insecure_store_mode"
|
|
4511
|
+
"insecure_store_mode",
|
|
4512
|
+
{ observedMode: posixFileMode(mode), requiredMode: "600" }
|
|
4481
4513
|
);
|
|
4482
4514
|
}
|
|
4483
4515
|
let parsed2;
|
|
@@ -4499,7 +4531,7 @@ async function writeEnrollmentStore(filePath, record6) {
|
|
|
4499
4531
|
assertEnrollmentBindings(record6);
|
|
4500
4532
|
await writePrivateJsonFile(filePath, record6);
|
|
4501
4533
|
}
|
|
4502
|
-
async function readEnrollmentStore(filePath, nowMs) {
|
|
4534
|
+
async function readEnrollmentStore(filePath, nowMs, expectedClientId) {
|
|
4503
4535
|
let text;
|
|
4504
4536
|
let mode;
|
|
4505
4537
|
try {
|
|
@@ -4522,7 +4554,8 @@ async function readEnrollmentStore(filePath, nowMs) {
|
|
|
4522
4554
|
throw enrollmentError(
|
|
4523
4555
|
"ENROLLMENT_INVALID",
|
|
4524
4556
|
"Enrollment store is not user-private mode 600",
|
|
4525
|
-
"insecure_store_mode"
|
|
4557
|
+
"insecure_store_mode",
|
|
4558
|
+
{ observedMode: posixFileMode(mode), requiredMode: "600" }
|
|
4526
4559
|
);
|
|
4527
4560
|
}
|
|
4528
4561
|
let parsed2;
|
|
@@ -4539,6 +4572,14 @@ async function readEnrollmentStore(filePath, nowMs) {
|
|
|
4539
4572
|
throw enrollmentError("ENROLLMENT_INVALID", "Enrollment store is invalid", "allowlist_tamper");
|
|
4540
4573
|
}
|
|
4541
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
|
+
}
|
|
4542
4583
|
return parsed2;
|
|
4543
4584
|
}
|
|
4544
4585
|
async function deleteEnrollmentStore(filePath) {
|
|
@@ -4569,7 +4610,8 @@ async function readEnrollmentBootstrap(filePath) {
|
|
|
4569
4610
|
throw enrollmentError(
|
|
4570
4611
|
"ENROLLMENT_INVALID",
|
|
4571
4612
|
"Enrollment bootstrap is not user-private mode 600",
|
|
4572
|
-
"insecure_store_mode"
|
|
4613
|
+
"insecure_store_mode",
|
|
4614
|
+
{ observedMode: posixFileMode(mode), requiredMode: "600" }
|
|
4573
4615
|
);
|
|
4574
4616
|
}
|
|
4575
4617
|
let parsed2;
|
|
@@ -4596,6 +4638,13 @@ async function readEnrollmentBootstrap(filePath) {
|
|
|
4596
4638
|
|
|
4597
4639
|
// packages/host-runtime/src/delegation-cli-enrollment.ts
|
|
4598
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
|
+
];
|
|
4599
4648
|
function missingRuntimeEnvironmentError(endpoint, token) {
|
|
4600
4649
|
const missingEnvironmentVariables = [
|
|
4601
4650
|
...!endpoint ? [DELEGATION_RUNTIME_ENDPOINT_ENV] : [],
|
|
@@ -4620,6 +4669,29 @@ function missingRuntimeEnvironmentError(endpoint, token) {
|
|
|
4620
4669
|
function option(parsed2, name) {
|
|
4621
4670
|
return parsed2.options.get(name);
|
|
4622
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
|
+
}
|
|
4623
4695
|
function rejectEnrollmentAttackOptions(environment, parsed2) {
|
|
4624
4696
|
const fromPid = option(parsed2, "--from-pid");
|
|
4625
4697
|
const fromEnvFile = option(parsed2, "--from-env-file");
|
|
@@ -4631,8 +4703,108 @@ function rejectEnrollmentAttackOptions(environment, parsed2) {
|
|
|
4631
4703
|
...asThread ? { asThread } : {}
|
|
4632
4704
|
});
|
|
4633
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
|
+
}
|
|
4634
4797
|
async function resolveCliRuntimeConnection(input) {
|
|
4635
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
|
+
}
|
|
4636
4808
|
const endpoint = input.environment[DELEGATION_RUNTIME_ENDPOINT_ENV];
|
|
4637
4809
|
const token = input.environment[DELEGATION_RUNTIME_TOKEN_ENV];
|
|
4638
4810
|
if (endpoint && token) {
|
|
@@ -4645,20 +4817,13 @@ async function resolveCliRuntimeConnection(input) {
|
|
|
4645
4817
|
};
|
|
4646
4818
|
}
|
|
4647
4819
|
if (endpoint || token) throw missingRuntimeEnvironmentError(endpoint, token);
|
|
4648
|
-
const clientId =
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
if (!record6) throw missingRuntimeEnvironmentError(void 0, void 0);
|
|
4656
|
-
return {
|
|
4657
|
-
endpoint: enrollmentClientEndpoint(record6, liveEndpoint),
|
|
4658
|
-
token: record6.token,
|
|
4659
|
-
callerThreadId: record6.threadId,
|
|
4660
|
-
source: "enrollment"
|
|
4661
|
-
};
|
|
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
|
+
});
|
|
4662
4827
|
}
|
|
4663
4828
|
function enrollmentClientEndpoint(record6, liveEndpoint) {
|
|
4664
4829
|
return record6.networkScope === "tailnet" ? record6.endpoint : liveEndpoint ?? record6.endpoint;
|
|
@@ -4732,31 +4897,70 @@ async function runEnrollRequest(input) {
|
|
|
4732
4897
|
}
|
|
4733
4898
|
async function runEnrollStatus(input) {
|
|
4734
4899
|
rejectEnrollmentAttackOptions(input.environment, input.parsed);
|
|
4735
|
-
const clientId =
|
|
4736
|
-
option(input.parsed, "--client") ?? DEFAULT_ENROLLMENT_CLIENT_ID
|
|
4737
|
-
);
|
|
4900
|
+
const clientId = selectedEnrollmentClientId(input.parsed, input.environment);
|
|
4738
4901
|
const storePath = enrollmentStorePath(input.environment, clientId);
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
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
|
|
4743
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;
|
|
4744
4943
|
}
|
|
4745
|
-
return { storePath, view: { ...publicEnrollmentView(record6), storePath } };
|
|
4746
4944
|
}
|
|
4747
4945
|
async function runEnrollRevoke(input) {
|
|
4748
4946
|
rejectEnrollmentAttackOptions(input.environment, input.parsed);
|
|
4749
|
-
const clientId =
|
|
4750
|
-
option(input.parsed, "--client") ?? DEFAULT_ENROLLMENT_CLIENT_ID
|
|
4751
|
-
);
|
|
4947
|
+
const clientId = selectedEnrollmentClientId(input.parsed, input.environment);
|
|
4752
4948
|
const storePath = enrollmentStorePath(input.environment, clientId);
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
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
|
+
}
|
|
4757
4959
|
if (!record6) {
|
|
4758
4960
|
throw new DelegationControlError("ENROLLMENT_INVALID", "No enrollment store is present", {
|
|
4759
|
-
reason: "revoked"
|
|
4961
|
+
reason: "revoked",
|
|
4962
|
+
clientId,
|
|
4963
|
+
storePath
|
|
4760
4964
|
});
|
|
4761
4965
|
}
|
|
4762
4966
|
await input.request(
|
|
@@ -4894,7 +5098,8 @@ async function runEnrollmentTailnetServe(input) {
|
|
|
4894
5098
|
}
|
|
4895
5099
|
const record6 = await readEnrollmentStore(
|
|
4896
5100
|
enrollmentStorePath(input.environment, clientId),
|
|
4897
|
-
Date.now()
|
|
5101
|
+
Date.now(),
|
|
5102
|
+
clientId
|
|
4898
5103
|
);
|
|
4899
5104
|
if (!record6) throw new DelegationControlError("ENROLLMENT_INVALID", "Enroll this client first");
|
|
4900
5105
|
const server = createEnrollmentTailnetServer(
|
|
@@ -5005,6 +5210,9 @@ function rejectUnknown(parsed2, allowed) {
|
|
|
5005
5210
|
throw new DelegationControlError("INVALID_ARGUMENT", `Unknown option '${name}'`);
|
|
5006
5211
|
}
|
|
5007
5212
|
}
|
|
5213
|
+
function runtimeOptions(allowed) {
|
|
5214
|
+
return [...allowed, ENROLLED_CLIENT_OPTION];
|
|
5215
|
+
}
|
|
5008
5216
|
async function requestRuntime(input) {
|
|
5009
5217
|
const { endpoint, token } = input.connection;
|
|
5010
5218
|
let response;
|
|
@@ -5111,7 +5319,7 @@ async function runDelegationCli(input) {
|
|
|
5111
5319
|
"--from-pid",
|
|
5112
5320
|
"--from-env-file",
|
|
5113
5321
|
"--as-thread"
|
|
5114
|
-
] : ["--client", "--from-pid", "--from-env-file", "--as-thread"];
|
|
5322
|
+
] : ["--client", ENROLLED_CLIENT_OPTION, "--from-pid", "--from-env-file", "--as-thread"];
|
|
5115
5323
|
rejectUnknown(parsed3, enrollOptions);
|
|
5116
5324
|
if (parsed3.positionals.length > 0) {
|
|
5117
5325
|
throw new DelegationControlError(
|
|
@@ -5157,7 +5365,7 @@ async function runDelegationCli(input) {
|
|
|
5157
5365
|
...input.fetchImpl ? { fetchImpl: input.fetchImpl } : {}
|
|
5158
5366
|
});
|
|
5159
5367
|
if (group === "harness" && command === "list") {
|
|
5160
|
-
rejectUnknown(parsed2, []);
|
|
5368
|
+
rejectUnknown(parsed2, runtimeOptions([]));
|
|
5161
5369
|
if (parsed2.positionals.length > 0) {
|
|
5162
5370
|
throw new DelegationControlError(
|
|
5163
5371
|
"INVALID_ARGUMENT",
|
|
@@ -5168,7 +5376,7 @@ async function runDelegationCli(input) {
|
|
|
5168
5376
|
return 0;
|
|
5169
5377
|
}
|
|
5170
5378
|
if (group === "harness" && command === "inspect") {
|
|
5171
|
-
rejectUnknown(parsed2, ["--cwd", "--refresh"]);
|
|
5379
|
+
rejectUnknown(parsed2, runtimeOptions(["--cwd", "--refresh"]));
|
|
5172
5380
|
if (parsed2.positionals.length !== 1) {
|
|
5173
5381
|
throw new DelegationControlError(
|
|
5174
5382
|
"INVALID_ARGUMENT",
|
|
@@ -5194,19 +5402,22 @@ async function runDelegationCli(input) {
|
|
|
5194
5402
|
return 0;
|
|
5195
5403
|
}
|
|
5196
5404
|
if (group === "delegate" && command === "start") {
|
|
5197
|
-
rejectUnknown(
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
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
|
+
);
|
|
5210
5421
|
if (parsed2.positionals.length > 0)
|
|
5211
5422
|
throw new DelegationControlError(
|
|
5212
5423
|
"INVALID_ARGUMENT",
|
|
@@ -5246,7 +5457,7 @@ async function runDelegationCli(input) {
|
|
|
5246
5457
|
return 0;
|
|
5247
5458
|
}
|
|
5248
5459
|
if (group === "thread" && command === "send") {
|
|
5249
|
-
rejectUnknown(parsed2, ["--message"]);
|
|
5460
|
+
rejectUnknown(parsed2, runtimeOptions(["--message"]));
|
|
5250
5461
|
if (parsed2.positionals.length !== 1) {
|
|
5251
5462
|
throw new DelegationControlError(
|
|
5252
5463
|
"INVALID_ARGUMENT",
|
|
@@ -5268,7 +5479,7 @@ async function runDelegationCli(input) {
|
|
|
5268
5479
|
return 0;
|
|
5269
5480
|
}
|
|
5270
5481
|
if (group === "thread" && command === "cancel") {
|
|
5271
|
-
rejectUnknown(parsed2, []);
|
|
5482
|
+
rejectUnknown(parsed2, runtimeOptions([]));
|
|
5272
5483
|
if (parsed2.positionals.length !== 1) {
|
|
5273
5484
|
throw new DelegationControlError(
|
|
5274
5485
|
"INVALID_ARGUMENT",
|
|
@@ -5286,13 +5497,16 @@ async function runDelegationCli(input) {
|
|
|
5286
5497
|
return 0;
|
|
5287
5498
|
}
|
|
5288
5499
|
if (group === "thread" && (command === "read" || command === "wait")) {
|
|
5289
|
-
rejectUnknown(
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5500
|
+
rejectUnknown(
|
|
5501
|
+
parsed2,
|
|
5502
|
+
runtimeOptions([
|
|
5503
|
+
"--view",
|
|
5504
|
+
"--cursor",
|
|
5505
|
+
"--limit",
|
|
5506
|
+
"--timeout-ms",
|
|
5507
|
+
...command === "read" ? ["--host"] : []
|
|
5508
|
+
])
|
|
5509
|
+
);
|
|
5296
5510
|
if (parsed2.positionals.length !== 1)
|
|
5297
5511
|
throw new DelegationControlError(
|
|
5298
5512
|
"INVALID_ARGUMENT",
|
|
@@ -5342,7 +5556,7 @@ async function runDelegationCli(input) {
|
|
|
5342
5556
|
return 0;
|
|
5343
5557
|
}
|
|
5344
5558
|
if (group === "thread" && command === "watch") {
|
|
5345
|
-
rejectUnknown(parsed2, ["--notify", "--timeout-ms"]);
|
|
5559
|
+
rejectUnknown(parsed2, runtimeOptions(["--notify", "--timeout-ms"]));
|
|
5346
5560
|
if (parsed2.positionals.length !== 1)
|
|
5347
5561
|
throw new DelegationControlError(
|
|
5348
5562
|
"INVALID_ARGUMENT",
|
|
@@ -5368,7 +5582,7 @@ async function runDelegationCli(input) {
|
|
|
5368
5582
|
return 0;
|
|
5369
5583
|
}
|
|
5370
5584
|
if (group === "thread" && command === "watches") {
|
|
5371
|
-
rejectUnknown(parsed2, []);
|
|
5585
|
+
rejectUnknown(parsed2, runtimeOptions([]));
|
|
5372
5586
|
if (parsed2.positionals.length > 0)
|
|
5373
5587
|
throw new DelegationControlError(
|
|
5374
5588
|
"INVALID_ARGUMENT",
|
|
@@ -5378,7 +5592,7 @@ async function runDelegationCli(input) {
|
|
|
5378
5592
|
return 0;
|
|
5379
5593
|
}
|
|
5380
5594
|
if (group === "thread" && command === "list") {
|
|
5381
|
-
rejectUnknown(parsed2, ["--cwd", "--parent", "--limit", "--cursor", "--sort"]);
|
|
5595
|
+
rejectUnknown(parsed2, runtimeOptions(["--cwd", "--parent", "--limit", "--cursor", "--sort"]));
|
|
5382
5596
|
if (parsed2.positionals.length > 0)
|
|
5383
5597
|
throw new DelegationControlError(
|
|
5384
5598
|
"INVALID_ARGUMENT",
|
|
@@ -21303,6 +21517,36 @@ var realtimeCallResponseSchema = external_exports.object({
|
|
|
21303
21517
|
headers: external_exports.record(external_exports.string(), external_exports.string())
|
|
21304
21518
|
});
|
|
21305
21519
|
|
|
21520
|
+
// packages/shared-contracts/dist/enrollment.js
|
|
21521
|
+
var ENROLLMENT_LIST_METHOD = "codexhost/enrollment/list";
|
|
21522
|
+
var ENROLLMENT_REVOKE_METHOD = "codexhost/enrollment/revoke";
|
|
21523
|
+
var enrollmentAllowlistEntrySchema = external_exports.strictObject({
|
|
21524
|
+
threadId: external_exports.string().trim().min(1).max(128),
|
|
21525
|
+
verbs: external_exports.array(external_exports.enum(["read", "watch", "send", "cancel"])).min(1).max(4)
|
|
21526
|
+
});
|
|
21527
|
+
var enrollmentPublicViewSchema = external_exports.strictObject({
|
|
21528
|
+
enrollmentId: external_exports.string().trim().min(1).max(128),
|
|
21529
|
+
threadId: external_exports.string().trim().min(1).max(128),
|
|
21530
|
+
clientId: external_exports.string().trim().min(1).max(64),
|
|
21531
|
+
executablePath: external_exports.string().min(1).max(4096),
|
|
21532
|
+
endpoint: external_exports.string().min(1).max(2048),
|
|
21533
|
+
issuedAt: external_exports.string().min(1).max(64),
|
|
21534
|
+
expiresAt: external_exports.string().min(1).max(64),
|
|
21535
|
+
pairing: external_exports.enum(["session", "machine"]),
|
|
21536
|
+
allowlist: external_exports.array(enrollmentAllowlistEntrySchema).max(64)
|
|
21537
|
+
});
|
|
21538
|
+
var enrollmentListParamsSchema = external_exports.strictObject({});
|
|
21539
|
+
var enrollmentListResultSchema = external_exports.strictObject({
|
|
21540
|
+
enrollments: external_exports.array(enrollmentPublicViewSchema).max(256)
|
|
21541
|
+
});
|
|
21542
|
+
var enrollmentRevokeParamsSchema = external_exports.strictObject({
|
|
21543
|
+
enrollmentId: external_exports.string().trim().min(1).max(128)
|
|
21544
|
+
});
|
|
21545
|
+
var enrollmentRevokeResultSchema = external_exports.strictObject({
|
|
21546
|
+
enrollmentId: external_exports.string().trim().min(1).max(128),
|
|
21547
|
+
revoked: external_exports.literal(true)
|
|
21548
|
+
});
|
|
21549
|
+
|
|
21306
21550
|
// packages/shared-contracts/dist/console.js
|
|
21307
21551
|
var consoleAnnouncementSchema = external_exports.strictObject({
|
|
21308
21552
|
title: external_exports.string().trim().min(1).max(200),
|
|
@@ -21317,6 +21561,8 @@ var consoleOpenResultSchema = external_exports.strictObject({
|
|
|
21317
21561
|
});
|
|
21318
21562
|
var CONSOLE_HOST_METHODS = Object.freeze([
|
|
21319
21563
|
"codexhost/voice/gateway-status",
|
|
21564
|
+
"codexhost/enrollment/list",
|
|
21565
|
+
"codexhost/enrollment/revoke",
|
|
21320
21566
|
"codexhost/console/remote-connections",
|
|
21321
21567
|
"codexhost/runtime/status",
|
|
21322
21568
|
"codexhost/remote/ssh-setup",
|
|
@@ -35081,6 +35327,43 @@ var HarnessDisplaySettingsStore = class {
|
|
|
35081
35327
|
}
|
|
35082
35328
|
};
|
|
35083
35329
|
|
|
35330
|
+
// packages/host-runtime/src/client-enrollment-host.ts
|
|
35331
|
+
function isEnrollmentHostMethod(method) {
|
|
35332
|
+
return method === ENROLLMENT_LIST_METHOD || method === ENROLLMENT_REVOKE_METHOD;
|
|
35333
|
+
}
|
|
35334
|
+
async function handleEnrollmentHostRequest(input) {
|
|
35335
|
+
if (!input.enrollment) {
|
|
35336
|
+
return { error: { code: -32e3, message: "Enrollment is unavailable on this Host" } };
|
|
35337
|
+
}
|
|
35338
|
+
if (input.method === ENROLLMENT_LIST_METHOD) {
|
|
35339
|
+
const parsed3 = enrollmentListParamsSchema.safeParse(input.params ?? {});
|
|
35340
|
+
if (!parsed3.success) {
|
|
35341
|
+
return { error: { code: -32602, message: "Invalid enrollment list request" } };
|
|
35342
|
+
}
|
|
35343
|
+
return {
|
|
35344
|
+
result: enrollmentListResultSchema.parse({ enrollments: input.enrollment.listPublic() })
|
|
35345
|
+
};
|
|
35346
|
+
}
|
|
35347
|
+
const parsed2 = enrollmentRevokeParamsSchema.safeParse(input.params ?? {});
|
|
35348
|
+
if (!parsed2.success) {
|
|
35349
|
+
return { error: { code: -32602, message: "Invalid enrollment revoke request" } };
|
|
35350
|
+
}
|
|
35351
|
+
try {
|
|
35352
|
+
return {
|
|
35353
|
+
result: enrollmentRevokeResultSchema.parse(
|
|
35354
|
+
await input.enrollment.revokeEnrollment(parsed2.data.enrollmentId)
|
|
35355
|
+
)
|
|
35356
|
+
};
|
|
35357
|
+
} catch (error51) {
|
|
35358
|
+
return {
|
|
35359
|
+
error: {
|
|
35360
|
+
code: -32e3,
|
|
35361
|
+
message: error51 instanceof Error ? error51.message : "Enrollment is not active"
|
|
35362
|
+
}
|
|
35363
|
+
};
|
|
35364
|
+
}
|
|
35365
|
+
}
|
|
35366
|
+
|
|
35084
35367
|
// packages/host-runtime/src/model-price-overrides-file.ts
|
|
35085
35368
|
import { randomUUID as randomUUID10 } from "node:crypto";
|
|
35086
35369
|
import { mkdir as mkdir14, readFile as readFile17, rename as rename11, rm as rm12, writeFile as writeFile11 } from "node:fs/promises";
|
|
@@ -40084,7 +40367,7 @@ var HarnessDelegationCoordinator = class {
|
|
|
40084
40367
|
});
|
|
40085
40368
|
}
|
|
40086
40369
|
if (this.#externalThreadBusy(thread) || thread.activeTurnId) {
|
|
40087
|
-
throw
|
|
40370
|
+
throw threadBusyError(input.threadId);
|
|
40088
40371
|
}
|
|
40089
40372
|
const turnId = hostTurnIdSchema.parse(randomUUID16());
|
|
40090
40373
|
try {
|
|
@@ -45403,6 +45686,17 @@ var AppServerHost = class {
|
|
|
45403
45686
|
await this.#handleSharedQuestionRequest(request);
|
|
45404
45687
|
return;
|
|
45405
45688
|
}
|
|
45689
|
+
if (isEnrollmentHostMethod(request.method)) {
|
|
45690
|
+
const reply2 = await handleEnrollmentHostRequest({
|
|
45691
|
+
enrollment: this.#options.enrollment,
|
|
45692
|
+
method: request.method,
|
|
45693
|
+
params: request.params ?? {}
|
|
45694
|
+
});
|
|
45695
|
+
await this.#writer.json(
|
|
45696
|
+
"error" in reply2 ? rpcError(request, reply2.error.code, reply2.error.message) : rpcEnvelope(request, { result: jsonValueSchema.parse(reply2.result) })
|
|
45697
|
+
);
|
|
45698
|
+
return;
|
|
45699
|
+
}
|
|
45406
45700
|
if (request.method === HARNESS_DISPLAY_GET_METHOD || request.method === HARNESS_DISPLAY_SET_METHOD) {
|
|
45407
45701
|
const parsed2 = (request.method === HARNESS_DISPLAY_SET_METHOD ? harnessDisplaySetSchema : harnessDisplayGetSchema).safeParse(request.params ?? {});
|
|
45408
45702
|
if (!parsed2.success) {
|
|
@@ -46564,7 +46858,7 @@ var AppServerHost = class {
|
|
|
46564
46858
|
throw new DelegationControlError("INVALID_ARGUMENT", "Message must not be empty");
|
|
46565
46859
|
}
|
|
46566
46860
|
if (this.#activeOfficialTurns.has(input.threadId)) {
|
|
46567
|
-
throw
|
|
46861
|
+
throw threadBusyError(input.threadId);
|
|
46568
46862
|
}
|
|
46569
46863
|
const current = await this.#requestOfficial("thread/read", {
|
|
46570
46864
|
threadId: input.threadId,
|
|
@@ -46576,7 +46870,7 @@ var AppServerHost = class {
|
|
|
46576
46870
|
}
|
|
46577
46871
|
const currentThread = isRecord21(current.result.thread) ? current.result.thread : null;
|
|
46578
46872
|
if (officialThreadBusy(currentThread)) {
|
|
46579
|
-
throw
|
|
46873
|
+
throw threadBusyError(input.threadId);
|
|
46580
46874
|
}
|
|
46581
46875
|
const resumed = await this.#requestOfficial("thread/resume", {
|
|
46582
46876
|
threadId: input.threadId,
|
|
@@ -46598,7 +46892,7 @@ var AppServerHost = class {
|
|
|
46598
46892
|
);
|
|
46599
46893
|
}
|
|
46600
46894
|
if (officialThreadBusy(resumedThread)) {
|
|
46601
|
-
throw
|
|
46895
|
+
throw threadBusyError(input.threadId);
|
|
46602
46896
|
}
|
|
46603
46897
|
if (!isRecord21(resumedThread.status) || resumedThread.status.type !== "idle") {
|
|
46604
46898
|
throw new DelegationControlError(
|
|
@@ -51560,6 +51854,15 @@ function installedHarnessPluginOptions(environment, managedRemoteHost = false, h
|
|
|
51560
51854
|
// packages/host-runtime/src/delegation-control-server.ts
|
|
51561
51855
|
import { createServer as createServer4 } from "node:http";
|
|
51562
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
|
+
}
|
|
51563
51866
|
function errorBody(error51) {
|
|
51564
51867
|
if (error51 instanceof DelegationControlError) {
|
|
51565
51868
|
return {
|
|
@@ -51665,6 +51968,7 @@ async function startWithWatch(api, watches, body) {
|
|
|
51665
51968
|
}
|
|
51666
51969
|
async function startDelegationControlServer(input) {
|
|
51667
51970
|
const server = createServer4((request, response) => {
|
|
51971
|
+
let principal;
|
|
51668
51972
|
void (async () => {
|
|
51669
51973
|
if (request.method !== "POST") {
|
|
51670
51974
|
writeJson2(response, 405, {
|
|
@@ -51699,7 +52003,7 @@ async function startDelegationControlServer(input) {
|
|
|
51699
52003
|
writeJson2(response, 200, record6);
|
|
51700
52004
|
return;
|
|
51701
52005
|
}
|
|
51702
|
-
|
|
52006
|
+
principal = authenticateControlRequest(
|
|
51703
52007
|
request.headers.authorization,
|
|
51704
52008
|
input.token,
|
|
51705
52009
|
input.enrollment
|
|
@@ -51787,7 +52091,8 @@ async function startDelegationControlServer(input) {
|
|
|
51787
52091
|
throw new DelegationControlError("INVALID_ARGUMENT", "Unknown Runtime control route");
|
|
51788
52092
|
}
|
|
51789
52093
|
})().catch((error51) => {
|
|
51790
|
-
|
|
52094
|
+
const annotated = annotateEnrollmentBusy(error51, principal);
|
|
52095
|
+
writeJson2(response, enrollmentHttpStatus(annotated), errorBody(annotated));
|
|
51791
52096
|
});
|
|
51792
52097
|
});
|
|
51793
52098
|
await new Promise((resolve, reject) => {
|
|
@@ -51810,18 +52115,13 @@ import { rm as rm17 } from "node:fs/promises";
|
|
|
51810
52115
|
import path40 from "node:path";
|
|
51811
52116
|
|
|
51812
52117
|
// packages/host-runtime/src/client-enrollment-consent.ts
|
|
51813
|
-
function
|
|
52118
|
+
function createUnavailableEnrollmentConsent() {
|
|
51814
52119
|
return {
|
|
51815
52120
|
async decide() {
|
|
51816
|
-
|
|
51817
|
-
await new Promise((resolve) => {
|
|
51818
|
-
setTimeout(resolve, input.timeoutMs);
|
|
51819
|
-
});
|
|
51820
|
-
return "timeout";
|
|
52121
|
+
return "unavailable";
|
|
51821
52122
|
}
|
|
51822
52123
|
};
|
|
51823
52124
|
}
|
|
51824
|
-
var DEFAULT_ENROLLMENT_CONSENT_TIMEOUT_MS = 6e4;
|
|
51825
52125
|
|
|
51826
52126
|
// packages/host-runtime/src/client-enrollment-authority.ts
|
|
51827
52127
|
var EnrollmentAuthority = class {
|
|
@@ -51839,9 +52139,7 @@ var EnrollmentAuthority = class {
|
|
|
51839
52139
|
constructor(input) {
|
|
51840
52140
|
this.#hostToken = input.hostToken;
|
|
51841
52141
|
this.#bootstrapToken = input.bootstrapToken ?? randomBytes4(32).toString("hex");
|
|
51842
|
-
this.#consent = input.consent ??
|
|
51843
|
-
timeoutMs: DEFAULT_ENROLLMENT_CONSENT_TIMEOUT_MS
|
|
51844
|
-
});
|
|
52142
|
+
this.#consent = input.consent ?? createUnavailableEnrollmentConsent();
|
|
51845
52143
|
this.#dataDirectory = input.dataDirectory;
|
|
51846
52144
|
this.#now = input.now ?? Date.now;
|
|
51847
52145
|
this.#createId = input.createId ?? randomUUID23;
|
|
@@ -51952,9 +52250,16 @@ var EnrollmentAuthority = class {
|
|
|
51952
52250
|
if (decision === "deny") {
|
|
51953
52251
|
throw enrollmentError("ENROLLMENT_DENIED", "Enrollment was denied", "denied");
|
|
51954
52252
|
}
|
|
51955
|
-
if (decision
|
|
52253
|
+
if (decision === "timeout") {
|
|
51956
52254
|
throw enrollmentError("ENROLLMENT_DENIED", "Enrollment timed out", "timeout");
|
|
51957
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
|
+
}
|
|
51958
52263
|
if (pairing === "machine") this.#revokeActiveForClient(clientId);
|
|
51959
52264
|
const enrollmentId = this.#createId();
|
|
51960
52265
|
const threadId2 = this.#createId();
|
|
@@ -52011,6 +52316,39 @@ var EnrollmentAuthority = class {
|
|
|
52011
52316
|
verifyEnrollmentRecord(principal.record, this.#now());
|
|
52012
52317
|
return publicEnrollmentView(principal.record);
|
|
52013
52318
|
}
|
|
52319
|
+
listPublic() {
|
|
52320
|
+
return [...this.#byToken.values()].filter((record6) => this.#verified(record6)).map((record6) => publicEnrollmentView(record6)).sort((left, right) => {
|
|
52321
|
+
const client = left.clientId.localeCompare(right.clientId);
|
|
52322
|
+
return client === 0 ? right.issuedAt.localeCompare(left.issuedAt) : client;
|
|
52323
|
+
});
|
|
52324
|
+
}
|
|
52325
|
+
async revokeEnrollment(enrollmentId) {
|
|
52326
|
+
const id2 = enrollmentId.trim();
|
|
52327
|
+
let target;
|
|
52328
|
+
for (const record6 of this.#byToken.values()) {
|
|
52329
|
+
if (record6.enrollmentId === id2 && !record6.revokedAt) {
|
|
52330
|
+
target = record6;
|
|
52331
|
+
break;
|
|
52332
|
+
}
|
|
52333
|
+
}
|
|
52334
|
+
if (!target) {
|
|
52335
|
+
throw enrollmentError("ENROLLMENT_INVALID", "Enrollment is not active", "revoked");
|
|
52336
|
+
}
|
|
52337
|
+
this.#byToken.set(target.token, {
|
|
52338
|
+
...target,
|
|
52339
|
+
revokedAt: new Date(this.#now()).toISOString()
|
|
52340
|
+
});
|
|
52341
|
+
await this.#saveRecords();
|
|
52342
|
+
const remaining = [...this.#byToken.values()].some(
|
|
52343
|
+
(record6) => record6.clientId === target.clientId && this.#verified(record6)
|
|
52344
|
+
);
|
|
52345
|
+
if (!remaining) {
|
|
52346
|
+
await deleteEnrollmentStore(
|
|
52347
|
+
enrollmentStorePath({ CODEXHOST_DATA_DIR: this.#dataDirectory }, target.clientId)
|
|
52348
|
+
);
|
|
52349
|
+
}
|
|
52350
|
+
return { enrollmentId: target.enrollmentId, revoked: true };
|
|
52351
|
+
}
|
|
52014
52352
|
authorize(record6, action) {
|
|
52015
52353
|
authorizeEnrollment(record6, action, this.#now());
|
|
52016
52354
|
}
|
|
@@ -53937,7 +54275,7 @@ async function prepareDelegationRuntime(input) {
|
|
|
53937
54275
|
const enrollment = new EnrollmentAuthority({
|
|
53938
54276
|
hostToken: token,
|
|
53939
54277
|
dataDirectory: codexhostDataDirectory(input.environment),
|
|
53940
|
-
consent:
|
|
54278
|
+
consent: createUnavailableEnrollmentConsent()
|
|
53941
54279
|
});
|
|
53942
54280
|
const server = await startDelegationControlServer({
|
|
53943
54281
|
token,
|
|
@@ -53962,7 +54300,12 @@ async function prepareDelegationRuntime(input) {
|
|
|
53962
54300
|
await installManagedHomeFiles(installDelegationSkills, "delegation Skill");
|
|
53963
54301
|
await installManagedHomeFiles(retireCodexhostDesktopRules, "Desktop rule retirement");
|
|
53964
54302
|
try {
|
|
53965
|
-
return await input.createHost(
|
|
54303
|
+
return await input.createHost(
|
|
54304
|
+
environment,
|
|
54305
|
+
(value2) => registry2.register(value2),
|
|
54306
|
+
registry2,
|
|
54307
|
+
enrollment
|
|
54308
|
+
);
|
|
53966
54309
|
} finally {
|
|
53967
54310
|
registry2.close();
|
|
53968
54311
|
await enrollment.close();
|
|
@@ -54021,7 +54364,7 @@ async function runHostRuntime(input) {
|
|
|
54021
54364
|
return prepareDelegationRuntime({
|
|
54022
54365
|
environment,
|
|
54023
54366
|
...hostRuntimePath ? { hostRuntimePath } : {},
|
|
54024
|
-
createHost: async (delegationEnvironment, onDelegationApi, registry2) => {
|
|
54367
|
+
createHost: async (delegationEnvironment, onDelegationApi, registry2, enrollment) => {
|
|
54025
54368
|
const official = await prepareLocalCodex({
|
|
54026
54369
|
stockCodexPath,
|
|
54027
54370
|
arguments: remoteControlPlan?.officialArguments ?? input.arguments,
|
|
@@ -54052,6 +54395,7 @@ async function runHostRuntime(input) {
|
|
|
54052
54395
|
...shared,
|
|
54053
54396
|
...installedHarnessPluginOptions(delegationEnvironment, false, input.hostRuntimeUrl),
|
|
54054
54397
|
onDelegationApi,
|
|
54398
|
+
enrollment,
|
|
54055
54399
|
...updateCoordinator ? { updateCoordinator } : {},
|
|
54056
54400
|
...consoleOpener ? { consoleOpener } : {}
|
|
54057
54401
|
});
|
|
@@ -54075,6 +54419,7 @@ async function runHostRuntime(input) {
|
|
|
54075
54419
|
...installedHarnessPluginOptions(delegationEnvironment, false, input.hostRuntimeUrl),
|
|
54076
54420
|
mappingStore,
|
|
54077
54421
|
closeMappingStoreOnExit: false,
|
|
54422
|
+
enrollment,
|
|
54078
54423
|
...updateCoordinator ? { updateCoordinator } : {},
|
|
54079
54424
|
...consoleOpener ? { consoleOpener } : {}
|
|
54080
54425
|
};
|
|
@@ -54131,7 +54476,7 @@ async function runHostRuntime(input) {
|
|
|
54131
54476
|
return prepareDelegationRuntime({
|
|
54132
54477
|
environment: input.environment,
|
|
54133
54478
|
...hostRuntimePath ? { hostRuntimePath } : {},
|
|
54134
|
-
createHost: async (delegationEnvironment, _onDelegationApi, registry2) => {
|
|
54479
|
+
createHost: async (delegationEnvironment, _onDelegationApi, registry2, enrollment) => {
|
|
54135
54480
|
const socketPath = remoteAppServerSocketPath(delegationEnvironment, listenUrl);
|
|
54136
54481
|
const officialPlan = createRemoteOfficialAppServerPlan(input.arguments, socketPath);
|
|
54137
54482
|
const officialRuntimeScope = new OfficialRuntimeScope({
|
|
@@ -54165,6 +54510,7 @@ async function runHostRuntime(input) {
|
|
|
54165
54510
|
...runtimeMaintenance ? { runtimeMaintenance } : {},
|
|
54166
54511
|
modelPrices,
|
|
54167
54512
|
usageStatistics,
|
|
54513
|
+
enrollment,
|
|
54168
54514
|
stockCodexPath,
|
|
54169
54515
|
arguments: [],
|
|
54170
54516
|
environment: delegationEnvironment,
|
|
@@ -54196,6 +54542,7 @@ async function runHostRuntime(input) {
|
|
|
54196
54542
|
...runtimeMaintenance ? { runtimeMaintenance } : {},
|
|
54197
54543
|
modelPrices,
|
|
54198
54544
|
usageStatistics,
|
|
54545
|
+
enrollment,
|
|
54199
54546
|
...sharedDelegation ? { sharedDelegation } : {},
|
|
54200
54547
|
sharedThreads: new SharedThreadBridge({
|
|
54201
54548
|
connect: async () => sharedOwner.connect(),
|