@corca-org/ceal-host-win32-x64 1.0.24 → 1.0.25
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 +2 -2
- package/bin/ceal-host.exe +0 -0
- package/libexec/ceal-host/ceal-host-background.exe +0 -0
- package/libexec/ceal-host/claude-hook.mjs +183 -77
- package/libexec/ceal-host/claude-invocation-authentication.mjs +322 -100
- package/libexec/ceal-host/claude-producer.mjs +175 -69
- package/libexec/ceal-host/codex-hook.mjs +170 -64
- package/libexec/ceal-host/codex-invocation-authentication.mjs +307 -85
- package/libexec/ceal-host/codex-producer.mjs +164 -58
- package/libexec/ceal-host/control.mjs +563 -210
- package/libexec/ceal-host/relay.mjs +115 -29
- package/package.json +1 -1
- package/share/ceal-host/bundle-manifest.json +13 -13
- package/share/ceal-host/bundle-manifest.sigstore.json +1 -1
|
@@ -328,6 +328,12 @@ var CALLER_RECOVERABLE_NEXT_ACTION_VALUES = [
|
|
|
328
328
|
// (never connected, revoked, or expired). The caller runs that exact
|
|
329
329
|
// Operation, completes the consent it hands back, and retries the same call.
|
|
330
330
|
"connect_personal_account",
|
|
331
|
+
// The refusal names the caller's own preferences update step: the read
|
|
332
|
+
// needs a personal connection the caller holds but has not selected in
|
|
333
|
+
// Ceal preferences, or has not confirmed through the initial review. The
|
|
334
|
+
// caller reads personal.preferences.get, runs personal.preferences.update
|
|
335
|
+
// at the current revision to select it, and retries the same call.
|
|
336
|
+
"update_personal_preferences",
|
|
331
337
|
// The provider or Gateway named a bounded wait; the caller waits that long
|
|
332
338
|
// and submits the same read again.
|
|
333
339
|
"retry_after",
|
|
@@ -877,9 +883,11 @@ var LOCAL_COMMAND_INVALID = "The local command or argument is invalid.";
|
|
|
877
883
|
var LOCAL_TRANSPORT_INCOMPLETE = "The local Ceal transport could not complete; report this as a gap.";
|
|
878
884
|
var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask an administrator to restore Gateway availability.";
|
|
879
885
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
880
|
-
var
|
|
886
|
+
var CEAL_CLIENT_UPGRADE_COMMAND = "npm install -g @corca-org/ceal";
|
|
887
|
+
var CLIENT_HOST_RELEASE_MISMATCH = `Install or upgrade the Ceal CLI and Host Relay to the same release as the Gateway, then retry. Update with \`${CEAL_CLIENT_UPGRADE_COMMAND}\`.`;
|
|
881
888
|
var HOST_INSTALL_REPAIR = "The local Host or Relay is missing, stale, or unavailable. Run `ceal-host install`, then `ceal-host discovery sync`, and retry from a new producer conversation.";
|
|
882
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select this turn;
|
|
889
|
+
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select this turn right now; the Host may be restarting. Wait briefly and retry the same command. If you know you are in an ephemeral side conversation, `ceal --standalone ...` uses your configured Ceal session/Gateway permissions without Host session/turn correlation. Otherwise return to the original regular conversation. Host refusal never switches modes. If the retry still fails, report intended Host calls as a gap.";
|
|
890
|
+
var HOST_RELAY_RESTARTING = "The Host Relay is temporarily unavailable while the Host restarts; wait briefly and retry the same command. If the retry still fails, report this as a gap.";
|
|
883
891
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
884
892
|
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
885
893
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
@@ -909,6 +917,9 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
909
917
|
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family. Ask an Admin to reactivate the Person, then retry this same session refresh.", "ask_admin", 403),
|
|
910
918
|
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family. Ask an Admin to reactivate the Principal, then retry this same session refresh.", "ask_admin", 403),
|
|
911
919
|
authority_replaced: guidance("The Gateway authority has been replaced; this session is no longer valid here. Run `ceal session adopt --gateway <origin> --email <email>` against the current Gateway to complete mailbox-confirmed recovery.", "repair_or_adopt_session", 409),
|
|
920
|
+
// A stored session that predates the authority-epoch commitment carries no
|
|
921
|
+
// epoch to compare, so it can never refresh: adopt a fresh session instead.
|
|
922
|
+
authority_epoch_unknown: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
912
923
|
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
913
924
|
refresh_recovery_unavailable: guidance("The Gateway's durable refresh-recovery key is unavailable. Retry the same refresh attempt after the key is available.", "retry", 503, true),
|
|
914
925
|
refresh_recovery_outcome_unavailable: guidance("The Gateway could not safely recover the outcome of a prior refresh. Ask an administrator to inspect the Gateway session state before retrying or adopting this session.", "ask_admin", 503),
|
|
@@ -1033,7 +1044,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1033
1044
|
host_session_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 401),
|
|
1034
1045
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
1035
1046
|
// changes mode; standalone remains the separate Client authority path.
|
|
1036
|
-
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "
|
|
1047
|
+
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "retry", 401, true),
|
|
1037
1048
|
host_context_activation_wait_exhausted: guidance("The Host selected this turn, but its invocation context did not activate before the bounded wait ended. Wait for the supplied retry_after_ms value, then retry the same command.", "retry_after", 401, true),
|
|
1038
1049
|
host_invocation_context_stale: guidance("The Host turn changed while this invocation was authenticating. Its command cannot be rebound safely; report this invocation as a gap.", "answer_with_gap", 401),
|
|
1039
1050
|
host_invocation_context_expired: guidance("The Host invocation context expired before authentication completed. This invocation cannot be retried in the expired turn; report it as a gap.", "answer_with_gap", 401),
|
|
@@ -1050,7 +1061,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1050
1061
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
1051
1062
|
// sandboxed Relay socket names the run-alone retry.
|
|
1052
1063
|
host_relay_permission_denied: guidance("An agent sandbox denied the Host Relay socket; run `ceal` as the only command, with no pipe, redirect, or `&&`, so the Host allow rule runs it outside the sandbox.", "rerun_outside_agent_sandbox", 403),
|
|
1053
|
-
host_relay_unavailable: guidance(
|
|
1064
|
+
host_relay_unavailable: guidance(HOST_RELAY_RESTARTING, "retry", 503, true),
|
|
1054
1065
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
1055
1066
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
1056
1067
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -1298,7 +1309,7 @@ var CEAL_OPERATION_JSON_SCHEMA_BUDGET = Object.freeze({
|
|
|
1298
1309
|
max_literal_nodes: 512
|
|
1299
1310
|
});
|
|
1300
1311
|
|
|
1301
|
-
// packages/ceal-client-protocol/src/operation-json-schema.ts
|
|
1312
|
+
// packages/ceal-client-protocol/src/operation-json-schema-leaf-validators.ts
|
|
1302
1313
|
var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
1303
1314
|
|
|
1304
1315
|
// packages/ceal-client-protocol/src/operation-contract-validation.ts
|
|
@@ -1445,7 +1456,8 @@ var CEAL_OPERATION_ID_PLACEHOLDER = "<operation-id>";
|
|
|
1445
1456
|
var CEAL_OPERATION_INPUT_PLACEHOLDER = "<json-object>";
|
|
1446
1457
|
var MODEL_INVOCATION_BASE_ARGUMENTS = [CEAL_OPERATION_INVOKE_COMMAND, CEAL_OPERATION_ID_PLACEHOLDER].join(" ");
|
|
1447
1458
|
var CEAL_MODEL_INVOCATION_ARGUMENTS = [MODEL_INVOCATION_BASE_ARGUMENTS, CEAL_OPERATION_INPUT_FLAG, shellSingleQuoted(CEAL_OPERATION_INPUT_PLACEHOLDER)].join(" ");
|
|
1448
|
-
var
|
|
1459
|
+
var CEAL_MODEL_INPUT_SOURCE_BASE_GUIDANCE = `For caller-owned fields, add ${CEAL_OPERATION_INPUT_FLAG} ${shellSingleQuoted(CEAL_OPERATION_INPUT_PLACEHOLDER)}. Use inline JSON for short input; for longer or generated input, put exactly one JSON object in a caller-owned regular non-symlink UTF-8 JSON file and pass --input @path; relative paths resolve from the command working directory.`;
|
|
1460
|
+
var CEAL_MODEL_INPUT_SOURCE_GUIDANCE = `${CEAL_MODEL_INPUT_SOURCE_BASE_GUIDANCE} On Windows, write the JSON file first; use the program's .cmd launcher with --input and only one quoted @path argument.`;
|
|
1449
1461
|
function shellSingleQuoted(value) {
|
|
1450
1462
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
1451
1463
|
}
|
|
@@ -2429,9 +2441,11 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2429
2441
|
invalid_arguments: Object.freeze({ classification: "host_arguments_invalid", next_action: "answer_with_gap" }),
|
|
2430
2442
|
options_invalid: Object.freeze({ classification: "host_configuration_invalid", next_action: "answer_with_gap" }),
|
|
2431
2443
|
session_unavailable: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2432
|
-
//
|
|
2433
|
-
//
|
|
2434
|
-
|
|
2444
|
+
// A missing turn right after a Host restart clears by itself once the
|
|
2445
|
+
// watcher reactivates the turn, so the caller waits briefly and retries;
|
|
2446
|
+
// a caller that knows it is in an ephemeral side conversation keeps the
|
|
2447
|
+
// standalone fallback the guidance names second.
|
|
2448
|
+
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "retry" }),
|
|
2435
2449
|
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
2436
2450
|
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
2437
2451
|
// `no_binding` now means the producer has no real current Host session. The
|
|
@@ -2448,7 +2462,7 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2448
2462
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
2449
2463
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
2450
2464
|
relay_permission_denied: Object.freeze({ classification: "host_relay_permission_denied", next_action: "rerun_outside_agent_sandbox" }),
|
|
2451
|
-
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "
|
|
2465
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "retry" }),
|
|
2452
2466
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
2453
2467
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
2454
2468
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -2829,8 +2843,80 @@ function waitForAbort(signal, milliseconds) {
|
|
|
2829
2843
|
import { execFile } from "node:child_process";
|
|
2830
2844
|
import { constants } from "node:fs";
|
|
2831
2845
|
import { lstat, open } from "node:fs/promises";
|
|
2832
|
-
import { dirname, join as
|
|
2846
|
+
import { dirname, join as join3, win32 as win323 } from "node:path";
|
|
2833
2847
|
import { fileURLToPath } from "node:url";
|
|
2848
|
+
|
|
2849
|
+
// host/spawn-working-directory.ts
|
|
2850
|
+
import { mkdirSync } from "node:fs";
|
|
2851
|
+
import { tmpdir } from "node:os";
|
|
2852
|
+
import { isAbsolute, join as join2, normalize, parse, sep } from "node:path";
|
|
2853
|
+
function resolveCealSpawnWorkingDirectory(stateRoot, keepOutside = []) {
|
|
2854
|
+
const candidates = [];
|
|
2855
|
+
const explicit = candidateDir(stateRoot);
|
|
2856
|
+
if (explicit !== void 0) candidates.push(explicit);
|
|
2857
|
+
const fallback = defaultHostStateRoot();
|
|
2858
|
+
if (fallback !== void 0 && !candidates.some((candidate) => sameDir(candidate, fallback))) candidates.push(fallback);
|
|
2859
|
+
const temporary = candidateDir(join2(tmpdir(), "ceal-spawn-cwd"));
|
|
2860
|
+
if (temporary !== void 0 && !candidates.some((candidate) => sameDir(candidate, temporary))) candidates.push(temporary);
|
|
2861
|
+
for (const dir of candidates) {
|
|
2862
|
+
if (!keptOutside(dir, keepOutside)) continue;
|
|
2863
|
+
try {
|
|
2864
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2865
|
+
return dir;
|
|
2866
|
+
} catch {
|
|
2867
|
+
continue;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
return tmpdir();
|
|
2871
|
+
}
|
|
2872
|
+
function candidateDir(dir) {
|
|
2873
|
+
if (dir === void 0 || dir === "") return void 0;
|
|
2874
|
+
if (!isAbsolute(dir) || normalize(dir) !== dir || parse(dir).root === dir) return void 0;
|
|
2875
|
+
return normalize(dir);
|
|
2876
|
+
}
|
|
2877
|
+
function defaultHostStateRoot() {
|
|
2878
|
+
if (process.platform === "win32") {
|
|
2879
|
+
const localAppData = nonEmptyEnv("LOCALAPPDATA");
|
|
2880
|
+
if (localAppData === void 0) return void 0;
|
|
2881
|
+
return candidateDir(join2(localAppData, "Ceal", "Host"));
|
|
2882
|
+
}
|
|
2883
|
+
if (process.platform === "darwin") {
|
|
2884
|
+
const home2 = nonEmptyEnv("HOME");
|
|
2885
|
+
if (home2 === void 0) return void 0;
|
|
2886
|
+
return candidateDir(join2(home2, "Library", "Application Support", "Ceal", "Host"));
|
|
2887
|
+
}
|
|
2888
|
+
const xdg = nonEmptyEnv("XDG_STATE_HOME");
|
|
2889
|
+
if (xdg !== void 0) {
|
|
2890
|
+
const root = candidateDir(join2(xdg, "ceal", "host"));
|
|
2891
|
+
if (root !== void 0) return root;
|
|
2892
|
+
}
|
|
2893
|
+
const home = nonEmptyEnv("HOME");
|
|
2894
|
+
if (home === void 0) return void 0;
|
|
2895
|
+
return candidateDir(join2(home, ".local", "state", "ceal", "host"));
|
|
2896
|
+
}
|
|
2897
|
+
function nonEmptyEnv(name) {
|
|
2898
|
+
const value = process.env[name];
|
|
2899
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
2900
|
+
}
|
|
2901
|
+
function keptOutside(dir, keepOutside) {
|
|
2902
|
+
for (const tree of keepOutside) {
|
|
2903
|
+
const clean = candidateDir(tree);
|
|
2904
|
+
if (clean === void 0) continue;
|
|
2905
|
+
if (insideDir(dir, clean)) return false;
|
|
2906
|
+
}
|
|
2907
|
+
return true;
|
|
2908
|
+
}
|
|
2909
|
+
function insideDir(dir, tree) {
|
|
2910
|
+
if (sameDir(dir, tree)) return true;
|
|
2911
|
+
if (process.platform === "win32") return dir.toLowerCase().startsWith(tree.toLowerCase() + sep);
|
|
2912
|
+
return dir.startsWith(tree + sep);
|
|
2913
|
+
}
|
|
2914
|
+
function sameDir(left, right) {
|
|
2915
|
+
if (process.platform === "win32") return left.toLowerCase() === right.toLowerCase();
|
|
2916
|
+
return left === right;
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2919
|
+
// host/secure-file.ts
|
|
2834
2920
|
var SecureFileCustodyError = class extends Error {
|
|
2835
2921
|
name = "SecureFileCustodyError";
|
|
2836
2922
|
reason;
|
|
@@ -2929,7 +3015,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
2929
3015
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
2930
3016
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
2931
3017
|
return await new Promise((resolve, reject2) => {
|
|
2932
|
-
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
3018
|
+
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES, cwd: resolveCealSpawnWorkingDirectory() }, (error, stdout, stderr) => {
|
|
2933
3019
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
2934
3020
|
if (exitCode === null) {
|
|
2935
3021
|
reject2(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -2958,7 +3044,7 @@ function securefsRefusal(stderr) {
|
|
|
2958
3044
|
}
|
|
2959
3045
|
function resolveInstalledHostExecutable(platform) {
|
|
2960
3046
|
const privateRuntimeRoot = dirname(fileURLToPath(import.meta.url));
|
|
2961
|
-
return platform === "win32" ? win323.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") :
|
|
3047
|
+
return platform === "win32" ? win323.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") : join3(privateRuntimeRoot, "..", "..", "bin", "ceal-host");
|
|
2962
3048
|
}
|
|
2963
3049
|
function isRecord(value) {
|
|
2964
3050
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -3345,7 +3431,7 @@ function record(value) {
|
|
|
3345
3431
|
import { createHash as createHash5 } from "node:crypto";
|
|
3346
3432
|
import { constants as constants4 } from "node:fs";
|
|
3347
3433
|
import { mkdir as mkdir2, open as open3, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
3348
|
-
import { dirname as dirname4, join as
|
|
3434
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
3349
3435
|
|
|
3350
3436
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3351
3437
|
import { lstat as lstat3, mkdir, open as open2, rename, unlink } from "node:fs/promises";
|
|
@@ -3498,9 +3584,9 @@ var HostUsageFactsStore = class {
|
|
|
3498
3584
|
afterBatchPublish;
|
|
3499
3585
|
sessionDirectoryCursor;
|
|
3500
3586
|
constructor(options) {
|
|
3501
|
-
this.root =
|
|
3502
|
-
this.sessions =
|
|
3503
|
-
this.batches =
|
|
3587
|
+
this.root = join4(options.outbox_dir, "usage-facts");
|
|
3588
|
+
this.sessions = join4(this.root, "sessions");
|
|
3589
|
+
this.batches = join4(this.root, "batches");
|
|
3504
3590
|
this.platform = options.platform ?? process.platform;
|
|
3505
3591
|
this.custody = options.secure_file_custody ?? {};
|
|
3506
3592
|
this.afterPendingWrite = options.afterPendingWrite;
|
|
@@ -3517,7 +3603,6 @@ var HostUsageFactsStore = class {
|
|
|
3517
3603
|
await cursor?.close();
|
|
3518
3604
|
}
|
|
3519
3605
|
async readState(producer, hostSourceRef, hostSessionRef) {
|
|
3520
|
-
await this.prepare();
|
|
3521
3606
|
const path = this.sessionPath(producer, hostSourceRef, hostSessionRef);
|
|
3522
3607
|
const value = await readOptionalJson(path, HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
3523
3608
|
if (value === null) return null;
|
|
@@ -3575,11 +3660,15 @@ var HostUsageFactsStore = class {
|
|
|
3575
3660
|
}
|
|
3576
3661
|
/** Remove unreferenced local batch objects in bounded pieces after settling any exact pending transition. */
|
|
3577
3662
|
async sweepOrphanedBatches(state) {
|
|
3578
|
-
await this.prepare();
|
|
3579
3663
|
const directoryPath = this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref);
|
|
3580
|
-
await preparePrivateDirectory(directoryPath, this.platform, this.custody);
|
|
3581
3664
|
const expected = expectedBatchNames(state);
|
|
3582
|
-
|
|
3665
|
+
let directory;
|
|
3666
|
+
try {
|
|
3667
|
+
directory = await opendir(directoryPath);
|
|
3668
|
+
} catch (error) {
|
|
3669
|
+
if (errorCode2(error) === "ENOENT") return 0;
|
|
3670
|
+
throw error;
|
|
3671
|
+
}
|
|
3583
3672
|
let inspected = 0;
|
|
3584
3673
|
let deleted = 0;
|
|
3585
3674
|
try {
|
|
@@ -3588,7 +3677,7 @@ var HostUsageFactsStore = class {
|
|
|
3588
3677
|
if (entry === null) break;
|
|
3589
3678
|
inspected += 1;
|
|
3590
3679
|
if (!isOrphanBatchEntry(entry, expected)) continue;
|
|
3591
|
-
await unlink2(
|
|
3680
|
+
await unlink2(join4(directoryPath, entry.name));
|
|
3592
3681
|
deleted += 1;
|
|
3593
3682
|
}
|
|
3594
3683
|
} finally {
|
|
@@ -3616,10 +3705,9 @@ var HostUsageFactsStore = class {
|
|
|
3616
3705
|
});
|
|
3617
3706
|
}
|
|
3618
3707
|
async nextUploadCandidate(producer, hostSourceRef) {
|
|
3619
|
-
await this.prepare();
|
|
3620
3708
|
const names = await this.readNextSessionNames();
|
|
3621
3709
|
for (const name of names) {
|
|
3622
|
-
const state = await readOptionalJson(
|
|
3710
|
+
const state = await readOptionalJson(join4(this.sessions, name), HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
3623
3711
|
if (state === null) continue;
|
|
3624
3712
|
validateStateOwner(state, producer, hostSourceRef);
|
|
3625
3713
|
let validated = state;
|
|
@@ -3634,7 +3722,14 @@ var HostUsageFactsStore = class {
|
|
|
3634
3722
|
return null;
|
|
3635
3723
|
}
|
|
3636
3724
|
async readNextSessionNames() {
|
|
3637
|
-
this.sessionDirectoryCursor
|
|
3725
|
+
if (this.sessionDirectoryCursor === void 0) {
|
|
3726
|
+
try {
|
|
3727
|
+
this.sessionDirectoryCursor = await opendir(this.sessions);
|
|
3728
|
+
} catch (error) {
|
|
3729
|
+
if (errorCode2(error) === "ENOENT") return [];
|
|
3730
|
+
throw error;
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3638
3733
|
const names = [];
|
|
3639
3734
|
let inspected = 0;
|
|
3640
3735
|
while (inspected < HOST_USAGE_FACTS_UPLOAD_SCAN_SESSIONS) {
|
|
@@ -3800,14 +3895,14 @@ var HostUsageFactsStore = class {
|
|
|
3800
3895
|
}
|
|
3801
3896
|
}
|
|
3802
3897
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
3803
|
-
return
|
|
3898
|
+
return join4(this.sessions, `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`);
|
|
3804
3899
|
}
|
|
3805
3900
|
batchSessionDirectory(producer, hostSourceRef, hostSessionRef) {
|
|
3806
3901
|
const sessionName = `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`;
|
|
3807
|
-
return
|
|
3902
|
+
return join4(this.batches, sessionName.slice(0, -5));
|
|
3808
3903
|
}
|
|
3809
3904
|
batchPath(state, batchRef) {
|
|
3810
|
-
return
|
|
3905
|
+
return join4(this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref), batchFileName(batchRef));
|
|
3811
3906
|
}
|
|
3812
3907
|
};
|
|
3813
3908
|
function serializeBatch(batch) {
|
|
@@ -4048,7 +4143,7 @@ function sha2562(value) {
|
|
|
4048
4143
|
|
|
4049
4144
|
// host/service-log.ts
|
|
4050
4145
|
import { copyFile, mkdir as mkdir3, stat, truncate, appendFile } from "node:fs/promises";
|
|
4051
|
-
import { dirname as dirname5, isAbsolute, posix as posix4, win32 as win325 } from "node:path";
|
|
4146
|
+
import { dirname as dirname5, isAbsolute as isAbsolute2, posix as posix4, win32 as win325 } from "node:path";
|
|
4052
4147
|
|
|
4053
4148
|
// host/service-log-delivery.ts
|
|
4054
4149
|
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
@@ -4243,7 +4338,7 @@ async function rotateHostServiceLog(path, maxBytes = HOST_SERVICE_LOG_MAX_BYTES)
|
|
|
4243
4338
|
}
|
|
4244
4339
|
function boundHostServiceLog(environment = process.env) {
|
|
4245
4340
|
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
4246
|
-
if (path === void 0 || !
|
|
4341
|
+
if (path === void 0 || !isAbsolute2(path)) return () => void 0;
|
|
4247
4342
|
let reported = false;
|
|
4248
4343
|
const ready = ensureHostServiceLogDirectory(path);
|
|
4249
4344
|
const check = () => {
|
|
@@ -4278,7 +4373,7 @@ async function persistHostServiceLogLine(line, environment = process.env) {
|
|
|
4278
4373
|
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
4279
4374
|
}
|
|
4280
4375
|
async function appendHostServiceLogLine(path, line) {
|
|
4281
|
-
if (!
|
|
4376
|
+
if (!isAbsolute2(path)) return;
|
|
4282
4377
|
await ensureHostServiceLogDirectory(path);
|
|
4283
4378
|
await appendFile(path, line);
|
|
4284
4379
|
}
|
|
@@ -4314,6 +4409,10 @@ var HostUsageFactsUploader = class {
|
|
|
4314
4409
|
async close() {
|
|
4315
4410
|
await this.store.close();
|
|
4316
4411
|
}
|
|
4412
|
+
/** The start owner prepares the store once, so idle ticks below never re-prepare. */
|
|
4413
|
+
async prepare() {
|
|
4414
|
+
await this.store.prepare();
|
|
4415
|
+
}
|
|
4317
4416
|
async uploadOne(signal) {
|
|
4318
4417
|
const candidate = await this.store.nextUploadCandidate(this.options.producer, this.options.host_source_ref);
|
|
4319
4418
|
if (candidate === null) return false;
|
|
@@ -4336,6 +4435,11 @@ var HostUsageFactsUploader = class {
|
|
|
4336
4435
|
};
|
|
4337
4436
|
async function runHostUsageFactsUploader(options, signal, wait = waitForAbort) {
|
|
4338
4437
|
const uploader = new HostUsageFactsUploader(options);
|
|
4438
|
+
try {
|
|
4439
|
+
await uploader.prepare();
|
|
4440
|
+
} catch {
|
|
4441
|
+
writeHostServiceDiagnostic(options.producer, "usage_upload_failed", void 0, "upload_failed");
|
|
4442
|
+
}
|
|
4339
4443
|
let delay = 500;
|
|
4340
4444
|
let failures = 0;
|
|
4341
4445
|
try {
|
|
@@ -4365,6 +4469,7 @@ async function runHostUsageFactsUploader(options, signal, wait = waitForAbort) {
|
|
|
4365
4469
|
|
|
4366
4470
|
// host/relay/src/host-producer-core.ts
|
|
4367
4471
|
import { createHash as createHash6 } from "node:crypto";
|
|
4472
|
+
import { readdir } from "node:fs/promises";
|
|
4368
4473
|
var HOST_TRANSCRIPT_CURSOR_REASONS = vocabulary(["transcript_replaced", "transcript_truncated", "transcript_rewritten", "transcript_malformed"]);
|
|
4369
4474
|
function isHostTranscriptCursorReason(value) {
|
|
4370
4475
|
return typeof value === "string" && HOST_TRANSCRIPT_CURSOR_REASONS.some((reason) => reason === value);
|
|
@@ -4570,6 +4675,14 @@ var HostTranscriptWatcher = class {
|
|
|
4570
4675
|
return transcriptCursorBoundsReason(handle, cursor, size);
|
|
4571
4676
|
}
|
|
4572
4677
|
};
|
|
4678
|
+
async function listHostOutboxDirectoryNames(directory) {
|
|
4679
|
+
try {
|
|
4680
|
+
return await readdir(directory);
|
|
4681
|
+
} catch (error) {
|
|
4682
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return [];
|
|
4683
|
+
throw error;
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4573
4686
|
var HostProducerDrainCore = class {
|
|
4574
4687
|
host;
|
|
4575
4688
|
now;
|
|
@@ -4597,8 +4710,8 @@ var HostProducerDrainCore = class {
|
|
|
4597
4710
|
};
|
|
4598
4711
|
|
|
4599
4712
|
// host/codex/src/codex-outbox.ts
|
|
4600
|
-
import { mkdir as mkdir4, open as open4,
|
|
4601
|
-
import { dirname as dirname6, isAbsolute as
|
|
4713
|
+
import { mkdir as mkdir4, open as open4, rename as rename2, stat as stat2, unlink as unlink3 } from "node:fs/promises";
|
|
4714
|
+
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join5 } from "node:path";
|
|
4602
4715
|
|
|
4603
4716
|
// host/invocation-context.ts
|
|
4604
4717
|
var HOST_INVOCATION_TURN_SELECTION_SCHEMA = "ceal.host_invocation_turn_selection.v1";
|
|
@@ -4870,12 +4983,12 @@ var CodexOutboxStore = class {
|
|
|
4870
4983
|
constructor(directory) {
|
|
4871
4984
|
if (typeof directory !== "string" || directory.length === 0) throw new CodexHostAdapterError("configuration", "Codex outbox directory is required.");
|
|
4872
4985
|
this.directory = directory;
|
|
4873
|
-
this.entriesDirectory =
|
|
4874
|
-
this.sessionsDirectory =
|
|
4875
|
-
this.activeContextsDirectory =
|
|
4876
|
-
this.turnSelectionsDirectory =
|
|
4877
|
-
this.registrationsDirectory =
|
|
4878
|
-
this.cursorsDirectory =
|
|
4986
|
+
this.entriesDirectory = join5(directory, "entries");
|
|
4987
|
+
this.sessionsDirectory = join5(directory, "sessions");
|
|
4988
|
+
this.activeContextsDirectory = join5(directory, "active-contexts");
|
|
4989
|
+
this.turnSelectionsDirectory = join5(directory, "turn-selections");
|
|
4990
|
+
this.registrationsDirectory = join5(directory, "transcript-registrations");
|
|
4991
|
+
this.cursorsDirectory = join5(directory, "transcript-cursors");
|
|
4879
4992
|
}
|
|
4880
4993
|
async prepare() {
|
|
4881
4994
|
for (const path of [this.directory, this.entriesDirectory, this.sessionsDirectory, this.activeContextsDirectory, this.turnSelectionsDirectory, this.registrationsDirectory, this.cursorsDirectory]) {
|
|
@@ -4888,13 +5001,12 @@ var CodexOutboxStore = class {
|
|
|
4888
5001
|
await writeAtomicJson(this.entryPath(entry.submission_ref), entry);
|
|
4889
5002
|
}
|
|
4890
5003
|
async list() {
|
|
4891
|
-
await this.prepare();
|
|
4892
5004
|
const entries = [];
|
|
4893
5005
|
let malformed = 0;
|
|
4894
|
-
for (const name of await
|
|
5006
|
+
for (const name of await listHostOutboxDirectoryNames(this.entriesDirectory)) {
|
|
4895
5007
|
if (!name.endsWith(".json")) continue;
|
|
4896
5008
|
try {
|
|
4897
|
-
const value = JSON.parse(await readOwnerStateFile(
|
|
5009
|
+
const value = JSON.parse(await readOwnerStateFile(join5(this.entriesDirectory, name)));
|
|
4898
5010
|
validateEnvelope(value);
|
|
4899
5011
|
entries.push(value);
|
|
4900
5012
|
} catch {
|
|
@@ -4939,7 +5051,6 @@ var CodexOutboxStore = class {
|
|
|
4939
5051
|
}
|
|
4940
5052
|
async readInvocationTurnSelection(hostSourceRef, hostSessionRef) {
|
|
4941
5053
|
if (!SAFE_REF3.test(hostSourceRef) || !SAFE_REF3.test(hostSessionRef)) throw new CodexHostAdapterError("invalid_input", "Codex Host turn selection identity is invalid.");
|
|
4942
|
-
await this.prepare();
|
|
4943
5054
|
return readOptionalJson2(this.turnSelectionPath(hostSourceRef, hostSessionRef), validateTurnSelection);
|
|
4944
5055
|
}
|
|
4945
5056
|
async attachInvocationTurnGeneration(identity, promptRef, turnGenerationRef) {
|
|
@@ -4948,6 +5059,7 @@ var CodexOutboxStore = class {
|
|
|
4948
5059
|
const path = this.activeContextPath(identity);
|
|
4949
5060
|
const active = await readOptionalJson2(path, validateCodexHostInvocationContext);
|
|
4950
5061
|
if (active === null || active.prompt_ref !== promptRef || !sameIdentity(active.identity, identity)) return false;
|
|
5062
|
+
await this.prepare();
|
|
4951
5063
|
await writeAtomicJson(path, { ...active, turn_generation_ref: turnGenerationRef });
|
|
4952
5064
|
return true;
|
|
4953
5065
|
}
|
|
@@ -4964,7 +5076,6 @@ var CodexOutboxStore = class {
|
|
|
4964
5076
|
*/
|
|
4965
5077
|
async readRawInvocationContext(hostSourceRef, hostSessionRef) {
|
|
4966
5078
|
if (!SAFE_REF3.test(hostSourceRef) || !SAFE_REF3.test(hostSessionRef)) throw new CodexHostAdapterError("invalid_input", "Codex Host session identity is invalid.");
|
|
4967
|
-
await this.prepare();
|
|
4968
5079
|
const context = await readLatestSessionProjection(this.activeContextPath({ host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }), hostSourceRef, hostSessionRef, (file) => readOptionalJson2(file, validateCodexHostInvocationContext));
|
|
4969
5080
|
return context;
|
|
4970
5081
|
}
|
|
@@ -4988,7 +5099,6 @@ var CodexOutboxStore = class {
|
|
|
4988
5099
|
async readSession(sourceRef, sessionRef) {
|
|
4989
5100
|
const identity = { host_source_ref: sourceRef, host_session_ref: sessionRef };
|
|
4990
5101
|
if (!SAFE_REF3.test(sourceRef) || !SAFE_REF3.test(sessionRef)) throw new CodexHostAdapterError("invalid_input", "Codex session identity is invalid.");
|
|
4991
|
-
await this.prepare();
|
|
4992
5102
|
return readOptionalJson2(this.sessionPath(identity.host_source_ref, identity.host_session_ref), validateSession);
|
|
4993
5103
|
}
|
|
4994
5104
|
async registerTranscript(registration) {
|
|
@@ -5016,18 +5126,16 @@ var CodexOutboxStore = class {
|
|
|
5016
5126
|
}
|
|
5017
5127
|
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
5018
5128
|
const path = this.registrationPath(hostSourceRef, hostSessionRef);
|
|
5019
|
-
await this.prepare();
|
|
5020
5129
|
const registration = await readOptionalJson2(path, validateRegistration);
|
|
5021
5130
|
if (registration !== null && (registration.host_source_ref !== hostSourceRef || registration.host_session_ref !== hostSessionRef)) throw storageError("Codex transcript registration identity does not match its session.");
|
|
5022
5131
|
return registration;
|
|
5023
5132
|
}
|
|
5024
5133
|
async listTranscriptRegistrations() {
|
|
5025
|
-
await this.prepare();
|
|
5026
5134
|
const registrations = [];
|
|
5027
|
-
for (const name of await
|
|
5135
|
+
for (const name of await listHostOutboxDirectoryNames(this.registrationsDirectory)) {
|
|
5028
5136
|
if (!name.endsWith(".json")) continue;
|
|
5029
5137
|
try {
|
|
5030
|
-
const value = JSON.parse(await readOwnerStateFile(
|
|
5138
|
+
const value = JSON.parse(await readOwnerStateFile(join5(this.registrationsDirectory, name)));
|
|
5031
5139
|
validateRegistration(value);
|
|
5032
5140
|
registrations.push(value);
|
|
5033
5141
|
} catch {
|
|
@@ -5037,7 +5145,6 @@ var CodexOutboxStore = class {
|
|
|
5037
5145
|
}
|
|
5038
5146
|
async readTranscriptCursor(registration) {
|
|
5039
5147
|
validateRegistration(registration);
|
|
5040
|
-
await this.prepare();
|
|
5041
5148
|
return readOptionalJson2(this.cursorPath(registration.host_source_ref, registration.host_session_ref), validateCursor);
|
|
5042
5149
|
}
|
|
5043
5150
|
async writeTranscriptCursor(cursor) {
|
|
@@ -5050,7 +5157,6 @@ var CodexOutboxStore = class {
|
|
|
5050
5157
|
const read2 = await this.list();
|
|
5051
5158
|
const envelope = findEnvelopeByAlias(read2.entries, sourceRef, sessionRef, alias);
|
|
5052
5159
|
if (envelope !== null) return envelopeMatch(envelope);
|
|
5053
|
-
await this.prepare();
|
|
5054
5160
|
return null;
|
|
5055
5161
|
}
|
|
5056
5162
|
async hasPriorTurn(sourceRef, sessionRef) {
|
|
@@ -5061,22 +5167,22 @@ var CodexOutboxStore = class {
|
|
|
5061
5167
|
}
|
|
5062
5168
|
entryPath(submissionRef) {
|
|
5063
5169
|
if (!SAFE_REF3.test(submissionRef)) throw storageError("Codex submission identity is malformed.");
|
|
5064
|
-
return
|
|
5170
|
+
return join5(this.entriesDirectory, `${cealRequestSha256(submissionRef)}.json`);
|
|
5065
5171
|
}
|
|
5066
5172
|
sessionPath(sourceRef, sessionRef) {
|
|
5067
|
-
return
|
|
5173
|
+
return join5(this.sessionsDirectory, `${identityKey({ host_source_ref: sourceRef, host_session_ref: sessionRef, host_turn_ref: "session" })}.json`);
|
|
5068
5174
|
}
|
|
5069
5175
|
activeContextPath(identity) {
|
|
5070
|
-
return
|
|
5176
|
+
return join5(this.activeContextsDirectory, `${invocationContextKey(identity)}.json`);
|
|
5071
5177
|
}
|
|
5072
5178
|
turnSelectionPath(sourceRef, sessionRef) {
|
|
5073
|
-
return
|
|
5179
|
+
return join5(this.turnSelectionsDirectory, `${invocationContextKey({ host_source_ref: sourceRef, host_session_ref: sessionRef })}.json`);
|
|
5074
5180
|
}
|
|
5075
5181
|
registrationPath(sourceRef, sessionRef) {
|
|
5076
|
-
return
|
|
5182
|
+
return join5(this.registrationsDirectory, `${sessionStateKey(sourceRef, sessionRef)}.json`);
|
|
5077
5183
|
}
|
|
5078
5184
|
cursorPath(sourceRef, sessionRef) {
|
|
5079
|
-
return
|
|
5185
|
+
return join5(this.cursorsDirectory, `${sessionStateKey(sourceRef, sessionRef)}.json`);
|
|
5080
5186
|
}
|
|
5081
5187
|
};
|
|
5082
5188
|
async function removeOwnerState(path, what) {
|
|
@@ -5210,7 +5316,7 @@ function validateRegistrationFields(value) {
|
|
|
5210
5316
|
if (!isTimestamp(value.registered_at) || !isTimestamp(value.expires_at)) throw storageError(`Codex transcript registration timestamps are malformed (${refusalFacts([{ name: "registered_at", value: value.registered_at }, { name: "expires_at", value: value.expires_at }])}).`);
|
|
5211
5317
|
}
|
|
5212
5318
|
function validRegistrationCwd(value) {
|
|
5213
|
-
return value === void 0 || typeof value === "string" &&
|
|
5319
|
+
return value === void 0 || typeof value === "string" && isAbsolute3(value) && value.length <= CODEX_TRANSCRIPT_PATH_MAX_CHARACTERS && !value.includes("\0");
|
|
5214
5320
|
}
|
|
5215
5321
|
function validateCursor(value) {
|
|
5216
5322
|
if (!isRecord6(value)) throw storageError("Codex transcript cursor is malformed.");
|