@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
|
@@ -2307,6 +2307,12 @@ var CALLER_RECOVERABLE_NEXT_ACTION_VALUES = [
|
|
|
2307
2307
|
// (never connected, revoked, or expired). The caller runs that exact
|
|
2308
2308
|
// Operation, completes the consent it hands back, and retries the same call.
|
|
2309
2309
|
"connect_personal_account",
|
|
2310
|
+
// The refusal names the caller's own preferences update step: the read
|
|
2311
|
+
// needs a personal connection the caller holds but has not selected in
|
|
2312
|
+
// Ceal preferences, or has not confirmed through the initial review. The
|
|
2313
|
+
// caller reads personal.preferences.get, runs personal.preferences.update
|
|
2314
|
+
// at the current revision to select it, and retries the same call.
|
|
2315
|
+
"update_personal_preferences",
|
|
2310
2316
|
// The provider or Gateway named a bounded wait; the caller waits that long
|
|
2311
2317
|
// and submits the same read again.
|
|
2312
2318
|
"retry_after",
|
|
@@ -2861,9 +2867,11 @@ var LOCAL_COMMAND_INVALID = "The local command or argument is invalid.";
|
|
|
2861
2867
|
var LOCAL_TRANSPORT_INCOMPLETE = "The local Ceal transport could not complete; report this as a gap.";
|
|
2862
2868
|
var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask an administrator to restore Gateway availability.";
|
|
2863
2869
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
2864
|
-
var
|
|
2870
|
+
var CEAL_CLIENT_UPGRADE_COMMAND = "npm install -g @corca-org/ceal";
|
|
2871
|
+
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}\`.`;
|
|
2865
2872
|
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.";
|
|
2866
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select this turn;
|
|
2873
|
+
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.";
|
|
2874
|
+
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.";
|
|
2867
2875
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
2868
2876
|
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
2869
2877
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
@@ -2893,6 +2901,9 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
2893
2901
|
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),
|
|
2894
2902
|
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),
|
|
2895
2903
|
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),
|
|
2904
|
+
// A stored session that predates the authority-epoch commitment carries no
|
|
2905
|
+
// epoch to compare, so it can never refresh: adopt a fresh session instead.
|
|
2906
|
+
authority_epoch_unknown: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
2896
2907
|
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
2897
2908
|
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),
|
|
2898
2909
|
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),
|
|
@@ -3017,7 +3028,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
3017
3028
|
host_session_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 401),
|
|
3018
3029
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
3019
3030
|
// changes mode; standalone remains the separate Client authority path.
|
|
3020
|
-
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "
|
|
3031
|
+
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "retry", 401, true),
|
|
3021
3032
|
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),
|
|
3022
3033
|
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),
|
|
3023
3034
|
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),
|
|
@@ -3034,7 +3045,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
3034
3045
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
3035
3046
|
// sandboxed Relay socket names the run-alone retry.
|
|
3036
3047
|
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),
|
|
3037
|
-
host_relay_unavailable: guidance(
|
|
3048
|
+
host_relay_unavailable: guidance(HOST_RELAY_RESTARTING, "retry", 503, true),
|
|
3038
3049
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
3039
3050
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
3040
3051
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -3299,7 +3310,7 @@ var CEAL_OPERATION_JSON_SCHEMA_BUDGET = Object.freeze({
|
|
|
3299
3310
|
max_literal_nodes: 512
|
|
3300
3311
|
});
|
|
3301
3312
|
|
|
3302
|
-
// packages/ceal-client-protocol/src/operation-json-schema.ts
|
|
3313
|
+
// packages/ceal-client-protocol/src/operation-json-schema-leaf-validators.ts
|
|
3303
3314
|
var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
3304
3315
|
|
|
3305
3316
|
// packages/ceal-client-protocol/src/operation-contract-validation.ts
|
|
@@ -3449,7 +3460,8 @@ var CEAL_OPERATION_ID_PLACEHOLDER = "<operation-id>";
|
|
|
3449
3460
|
var CEAL_OPERATION_INPUT_PLACEHOLDER = "<json-object>";
|
|
3450
3461
|
var MODEL_INVOCATION_BASE_ARGUMENTS = [CEAL_OPERATION_INVOKE_COMMAND, CEAL_OPERATION_ID_PLACEHOLDER].join(" ");
|
|
3451
3462
|
var CEAL_MODEL_INVOCATION_ARGUMENTS = [MODEL_INVOCATION_BASE_ARGUMENTS, CEAL_OPERATION_INPUT_FLAG, shellSingleQuoted(CEAL_OPERATION_INPUT_PLACEHOLDER)].join(" ");
|
|
3452
|
-
var
|
|
3463
|
+
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.`;
|
|
3464
|
+
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.`;
|
|
3453
3465
|
function shellSingleQuoted(value) {
|
|
3454
3466
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
3455
3467
|
}
|
|
@@ -4485,9 +4497,11 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
4485
4497
|
invalid_arguments: Object.freeze({ classification: "host_arguments_invalid", next_action: "answer_with_gap" }),
|
|
4486
4498
|
options_invalid: Object.freeze({ classification: "host_configuration_invalid", next_action: "answer_with_gap" }),
|
|
4487
4499
|
session_unavailable: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
4488
|
-
//
|
|
4489
|
-
//
|
|
4490
|
-
|
|
4500
|
+
// A missing turn right after a Host restart clears by itself once the
|
|
4501
|
+
// watcher reactivates the turn, so the caller waits briefly and retries;
|
|
4502
|
+
// a caller that knows it is in an ephemeral side conversation keeps the
|
|
4503
|
+
// standalone fallback the guidance names second.
|
|
4504
|
+
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "retry" }),
|
|
4491
4505
|
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
4492
4506
|
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
4493
4507
|
// `no_binding` now means the producer has no real current Host session. The
|
|
@@ -4504,7 +4518,7 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
4504
4518
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
4505
4519
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
4506
4520
|
relay_permission_denied: Object.freeze({ classification: "host_relay_permission_denied", next_action: "rerun_outside_agent_sandbox" }),
|
|
4507
|
-
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "
|
|
4521
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "retry" }),
|
|
4508
4522
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
4509
4523
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
4510
4524
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -4991,7 +5005,7 @@ function hostClientProbeRefusal(probe, subject) {
|
|
|
4991
5005
|
import { createHash as createHash4 } from "node:crypto";
|
|
4992
5006
|
import { execFile } from "node:child_process";
|
|
4993
5007
|
import { access, open, readFile, realpath, stat } from "node:fs/promises";
|
|
4994
|
-
import { delimiter, extname, isAbsolute, join as
|
|
5008
|
+
import { delimiter, extname, isAbsolute as isAbsolute2, join as join3 } from "node:path";
|
|
4995
5009
|
import { promisify } from "node:util";
|
|
4996
5010
|
|
|
4997
5011
|
// host/environment.ts
|
|
@@ -5073,6 +5087,76 @@ function quoteWindowsExecArgument(value) {
|
|
|
5073
5087
|
return `"${escaped}"`;
|
|
5074
5088
|
}
|
|
5075
5089
|
|
|
5090
|
+
// host/spawn-working-directory.ts
|
|
5091
|
+
import { mkdirSync } from "node:fs";
|
|
5092
|
+
import { tmpdir } from "node:os";
|
|
5093
|
+
import { isAbsolute, join as join2, normalize, parse, sep } from "node:path";
|
|
5094
|
+
function resolveCealSpawnWorkingDirectory(stateRoot, keepOutside = []) {
|
|
5095
|
+
const candidates = [];
|
|
5096
|
+
const explicit = candidateDir(stateRoot);
|
|
5097
|
+
if (explicit !== void 0) candidates.push(explicit);
|
|
5098
|
+
const fallback = defaultHostStateRoot();
|
|
5099
|
+
if (fallback !== void 0 && !candidates.some((candidate) => sameDir(candidate, fallback))) candidates.push(fallback);
|
|
5100
|
+
const temporary = candidateDir(join2(tmpdir(), "ceal-spawn-cwd"));
|
|
5101
|
+
if (temporary !== void 0 && !candidates.some((candidate) => sameDir(candidate, temporary))) candidates.push(temporary);
|
|
5102
|
+
for (const dir of candidates) {
|
|
5103
|
+
if (!keptOutside(dir, keepOutside)) continue;
|
|
5104
|
+
try {
|
|
5105
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
5106
|
+
return dir;
|
|
5107
|
+
} catch {
|
|
5108
|
+
continue;
|
|
5109
|
+
}
|
|
5110
|
+
}
|
|
5111
|
+
return tmpdir();
|
|
5112
|
+
}
|
|
5113
|
+
function candidateDir(dir) {
|
|
5114
|
+
if (dir === void 0 || dir === "") return void 0;
|
|
5115
|
+
if (!isAbsolute(dir) || normalize(dir) !== dir || parse(dir).root === dir) return void 0;
|
|
5116
|
+
return normalize(dir);
|
|
5117
|
+
}
|
|
5118
|
+
function defaultHostStateRoot() {
|
|
5119
|
+
if (process.platform === "win32") {
|
|
5120
|
+
const localAppData = nonEmptyEnv("LOCALAPPDATA");
|
|
5121
|
+
if (localAppData === void 0) return void 0;
|
|
5122
|
+
return candidateDir(join2(localAppData, "Ceal", "Host"));
|
|
5123
|
+
}
|
|
5124
|
+
if (process.platform === "darwin") {
|
|
5125
|
+
const home2 = nonEmptyEnv("HOME");
|
|
5126
|
+
if (home2 === void 0) return void 0;
|
|
5127
|
+
return candidateDir(join2(home2, "Library", "Application Support", "Ceal", "Host"));
|
|
5128
|
+
}
|
|
5129
|
+
const xdg = nonEmptyEnv("XDG_STATE_HOME");
|
|
5130
|
+
if (xdg !== void 0) {
|
|
5131
|
+
const root = candidateDir(join2(xdg, "ceal", "host"));
|
|
5132
|
+
if (root !== void 0) return root;
|
|
5133
|
+
}
|
|
5134
|
+
const home = nonEmptyEnv("HOME");
|
|
5135
|
+
if (home === void 0) return void 0;
|
|
5136
|
+
return candidateDir(join2(home, ".local", "state", "ceal", "host"));
|
|
5137
|
+
}
|
|
5138
|
+
function nonEmptyEnv(name) {
|
|
5139
|
+
const value = process.env[name];
|
|
5140
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
5141
|
+
}
|
|
5142
|
+
function keptOutside(dir, keepOutside) {
|
|
5143
|
+
for (const tree of keepOutside) {
|
|
5144
|
+
const clean = candidateDir(tree);
|
|
5145
|
+
if (clean === void 0) continue;
|
|
5146
|
+
if (insideDir(dir, clean)) return false;
|
|
5147
|
+
}
|
|
5148
|
+
return true;
|
|
5149
|
+
}
|
|
5150
|
+
function insideDir(dir, tree) {
|
|
5151
|
+
if (sameDir(dir, tree)) return true;
|
|
5152
|
+
if (process.platform === "win32") return dir.toLowerCase().startsWith(tree.toLowerCase() + sep);
|
|
5153
|
+
return dir.startsWith(tree + sep);
|
|
5154
|
+
}
|
|
5155
|
+
function sameDir(left, right) {
|
|
5156
|
+
if (process.platform === "win32") return left.toLowerCase() === right.toLowerCase();
|
|
5157
|
+
return left === right;
|
|
5158
|
+
}
|
|
5159
|
+
|
|
5076
5160
|
// host/client-doctor.ts
|
|
5077
5161
|
var execFileAsync = promisify(execFile);
|
|
5078
5162
|
var GIT_OID = /^[a-f0-9]{40}$/u;
|
|
@@ -5158,7 +5242,7 @@ async function resolveCealExecutable(command, environment, platform = process.pl
|
|
|
5158
5242
|
if (!metadata.isFile()) continue;
|
|
5159
5243
|
const launcherKind = await inspectLauncherKind(path);
|
|
5160
5244
|
if (launcherKind !== void 0) return resolveLauncherBinary(path, launcherKind, environment, platform);
|
|
5161
|
-
if (platform === "win32" && !
|
|
5245
|
+
if (platform === "win32" && !isAbsolute2(command) && extname(path) === "") continue;
|
|
5162
5246
|
return { path, sha256: createHash4("sha256").update(await readFile(path)).digest("hex") };
|
|
5163
5247
|
} catch {
|
|
5164
5248
|
}
|
|
@@ -5181,7 +5265,7 @@ async function inspectLauncherKind(path) {
|
|
|
5181
5265
|
}
|
|
5182
5266
|
async function resolveLauncherBinary(launcherPath, kind, environment, platform) {
|
|
5183
5267
|
const invocation = hostScriptLauncherInvocation(launcherPath, CEAL_CLIENT_DOCTOR_COMMAND, kind, platform, environment);
|
|
5184
|
-
const result = await execFileAsync(invocation.executable, [...invocation.args], { env: { ...environment, ...invocation.environment }, timeout: 15e3, encoding: "utf8", windowsHide: false, ...invocation.windowsVerbatimArguments === void 0 ? {} : { windowsVerbatimArguments: invocation.windowsVerbatimArguments } });
|
|
5268
|
+
const result = await execFileAsync(invocation.executable, [...invocation.args], { env: { ...environment, ...invocation.environment }, timeout: 15e3, encoding: "utf8", windowsHide: false, cwd: resolveCealSpawnWorkingDirectory(), ...invocation.windowsVerbatimArguments === void 0 ? {} : { windowsVerbatimArguments: invocation.windowsVerbatimArguments } });
|
|
5185
5269
|
let parsed;
|
|
5186
5270
|
try {
|
|
5187
5271
|
parsed = JSON.parse(result.stdout);
|
|
@@ -5195,15 +5279,15 @@ async function resolveLauncherBinary(launcherPath, kind, environment, platform)
|
|
|
5195
5279
|
return { path: binaryPath, sha256: createHash4("sha256").update(await readFile(binaryPath)).digest("hex") };
|
|
5196
5280
|
}
|
|
5197
5281
|
function executableCandidates(command, environment, platform) {
|
|
5198
|
-
if (
|
|
5282
|
+
if (isAbsolute2(command)) return [command];
|
|
5199
5283
|
const pathValue = environmentValue(environment, "PATH", platform) ?? "";
|
|
5200
5284
|
const directories = pathValue.split(delimiter).filter((entry) => entry.length > 0);
|
|
5201
|
-
if (platform !== "win32" || extname(command) !== "") return directories.map((entry) =>
|
|
5202
|
-
return directories.flatMap((entry) => [".exe", ".ps1", ".cmd", ".bat", ""].map((suffix) =>
|
|
5285
|
+
if (platform !== "win32" || extname(command) !== "") return directories.map((entry) => join3(entry, command));
|
|
5286
|
+
return directories.flatMap((entry) => [".exe", ".ps1", ".cmd", ".bat", ""].map((suffix) => join3(entry, `${command}${suffix}`)));
|
|
5203
5287
|
}
|
|
5204
5288
|
async function executeCealCommand(executable, args, environment) {
|
|
5205
5289
|
try {
|
|
5206
|
-
const result = await execFileAsync(executable, [...args], { env: environment, timeout: 15e3, encoding: "utf8" });
|
|
5290
|
+
const result = await execFileAsync(executable, [...args], { env: environment, timeout: 15e3, encoding: "utf8", cwd: resolveCealSpawnWorkingDirectory() });
|
|
5207
5291
|
return { exit_code: 0, stdout: result.stdout, stderr: result.stderr };
|
|
5208
5292
|
} catch (error) {
|
|
5209
5293
|
if (isRecord(error)) return { exit_code: typeof error.code === "number" ? error.code : 1, stdout: typeof error.stdout === "string" ? error.stdout : "", stderr: typeof error.stderr === "string" ? error.stderr : "" };
|
|
@@ -5255,6 +5339,7 @@ async function doctorCodexClient(options = {}) {
|
|
|
5255
5339
|
}
|
|
5256
5340
|
|
|
5257
5341
|
// host/invocation-authentication-command.ts
|
|
5342
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
5258
5343
|
import { performance } from "node:perf_hooks";
|
|
5259
5344
|
|
|
5260
5345
|
// host/relay/src/producer-frame.ts
|
|
@@ -5273,12 +5358,13 @@ var HOST_PRODUCER_FRAME_ERROR_CODES = [
|
|
|
5273
5358
|
|
|
5274
5359
|
// host/relay/src/host-producer-core.ts
|
|
5275
5360
|
import { createHash as createHash5 } from "node:crypto";
|
|
5361
|
+
import { readdir } from "node:fs/promises";
|
|
5276
5362
|
|
|
5277
5363
|
// host/secure-file.ts
|
|
5278
5364
|
import { execFile as execFile2 } from "node:child_process";
|
|
5279
5365
|
import { constants } from "node:fs";
|
|
5280
5366
|
import { lstat, open as open2 } from "node:fs/promises";
|
|
5281
|
-
import { dirname, join as
|
|
5367
|
+
import { dirname, join as join4, win32 as win322 } from "node:path";
|
|
5282
5368
|
import { fileURLToPath } from "node:url";
|
|
5283
5369
|
var SecureFileCustodyError = class extends Error {
|
|
5284
5370
|
name = "SecureFileCustodyError";
|
|
@@ -5387,7 +5473,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
5387
5473
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
5388
5474
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
5389
5475
|
return await new Promise((resolve, reject2) => {
|
|
5390
|
-
const child = execFile2(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
5476
|
+
const child = execFile2(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES, cwd: resolveCealSpawnWorkingDirectory() }, (error, stdout, stderr) => {
|
|
5391
5477
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
5392
5478
|
if (exitCode === null) {
|
|
5393
5479
|
reject2(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -5416,7 +5502,7 @@ function securefsRefusal(stderr) {
|
|
|
5416
5502
|
}
|
|
5417
5503
|
function resolveInstalledHostExecutable(platform) {
|
|
5418
5504
|
const privateRuntimeRoot = dirname(fileURLToPath(import.meta.url));
|
|
5419
|
-
return platform === "win32" ? win322.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") :
|
|
5505
|
+
return platform === "win32" ? win322.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") : join4(privateRuntimeRoot, "..", "..", "bin", "ceal-host");
|
|
5420
5506
|
}
|
|
5421
5507
|
function isRecord2(value) {
|
|
5422
5508
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -5440,7 +5526,7 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
5440
5526
|
|
|
5441
5527
|
// host/service-log.ts
|
|
5442
5528
|
import { copyFile, mkdir, stat as stat2, truncate, appendFile } from "node:fs/promises";
|
|
5443
|
-
import { dirname as dirname2, isAbsolute as
|
|
5529
|
+
import { dirname as dirname2, isAbsolute as isAbsolute3, posix, win32 as win323 } from "node:path";
|
|
5444
5530
|
|
|
5445
5531
|
// host/service-log-delivery.ts
|
|
5446
5532
|
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
@@ -5599,7 +5685,7 @@ async function persistHostServiceLogLine(line, environment = process.env) {
|
|
|
5599
5685
|
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
5600
5686
|
}
|
|
5601
5687
|
async function appendHostServiceLogLine(path, line) {
|
|
5602
|
-
if (!
|
|
5688
|
+
if (!isAbsolute3(path)) return;
|
|
5603
5689
|
await ensureHostServiceLogDirectory(path);
|
|
5604
5690
|
await appendFile(path, line);
|
|
5605
5691
|
}
|
|
@@ -5880,6 +5966,14 @@ var HostTranscriptWatcher = class {
|
|
|
5880
5966
|
return transcriptCursorBoundsReason(handle, cursor, size);
|
|
5881
5967
|
}
|
|
5882
5968
|
};
|
|
5969
|
+
async function listHostOutboxDirectoryNames(directory) {
|
|
5970
|
+
try {
|
|
5971
|
+
return await readdir(directory);
|
|
5972
|
+
} catch (error) {
|
|
5973
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return [];
|
|
5974
|
+
throw error;
|
|
5975
|
+
}
|
|
5976
|
+
}
|
|
5883
5977
|
var HostProducerDrainCore = class {
|
|
5884
5978
|
host;
|
|
5885
5979
|
now;
|
|
@@ -6041,7 +6135,7 @@ function errorCode2(error) {
|
|
|
6041
6135
|
import { createHash as createHash6 } from "node:crypto";
|
|
6042
6136
|
import { constants as constants2 } from "node:fs";
|
|
6043
6137
|
import { mkdir as mkdir3, open as open4, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
6044
|
-
import { dirname as dirname4, join as
|
|
6138
|
+
import { dirname as dirname4, join as join5 } from "node:path";
|
|
6045
6139
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
6046
6140
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
6047
6141
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -6061,9 +6155,9 @@ var HostUsageFactsStore = class {
|
|
|
6061
6155
|
afterBatchPublish;
|
|
6062
6156
|
sessionDirectoryCursor;
|
|
6063
6157
|
constructor(options) {
|
|
6064
|
-
this.root =
|
|
6065
|
-
this.sessions =
|
|
6066
|
-
this.batches =
|
|
6158
|
+
this.root = join5(options.outbox_dir, "usage-facts");
|
|
6159
|
+
this.sessions = join5(this.root, "sessions");
|
|
6160
|
+
this.batches = join5(this.root, "batches");
|
|
6067
6161
|
this.platform = options.platform ?? process.platform;
|
|
6068
6162
|
this.custody = options.secure_file_custody ?? {};
|
|
6069
6163
|
this.afterPendingWrite = options.afterPendingWrite;
|
|
@@ -6080,7 +6174,6 @@ var HostUsageFactsStore = class {
|
|
|
6080
6174
|
await cursor?.close();
|
|
6081
6175
|
}
|
|
6082
6176
|
async readState(producer, hostSourceRef, hostSessionRef) {
|
|
6083
|
-
await this.prepare();
|
|
6084
6177
|
const path = this.sessionPath(producer, hostSourceRef, hostSessionRef);
|
|
6085
6178
|
const value = await readOptionalJson(path, HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
6086
6179
|
if (value === null) return null;
|
|
@@ -6138,11 +6231,15 @@ var HostUsageFactsStore = class {
|
|
|
6138
6231
|
}
|
|
6139
6232
|
/** Remove unreferenced local batch objects in bounded pieces after settling any exact pending transition. */
|
|
6140
6233
|
async sweepOrphanedBatches(state) {
|
|
6141
|
-
await this.prepare();
|
|
6142
6234
|
const directoryPath = this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref);
|
|
6143
|
-
await preparePrivateDirectory(directoryPath, this.platform, this.custody);
|
|
6144
6235
|
const expected = expectedBatchNames(state);
|
|
6145
|
-
|
|
6236
|
+
let directory;
|
|
6237
|
+
try {
|
|
6238
|
+
directory = await opendir(directoryPath);
|
|
6239
|
+
} catch (error) {
|
|
6240
|
+
if (errorCode3(error) === "ENOENT") return 0;
|
|
6241
|
+
throw error;
|
|
6242
|
+
}
|
|
6146
6243
|
let inspected = 0;
|
|
6147
6244
|
let deleted = 0;
|
|
6148
6245
|
try {
|
|
@@ -6151,7 +6248,7 @@ var HostUsageFactsStore = class {
|
|
|
6151
6248
|
if (entry === null) break;
|
|
6152
6249
|
inspected += 1;
|
|
6153
6250
|
if (!isOrphanBatchEntry(entry, expected)) continue;
|
|
6154
|
-
await unlink2(
|
|
6251
|
+
await unlink2(join5(directoryPath, entry.name));
|
|
6155
6252
|
deleted += 1;
|
|
6156
6253
|
}
|
|
6157
6254
|
} finally {
|
|
@@ -6179,10 +6276,9 @@ var HostUsageFactsStore = class {
|
|
|
6179
6276
|
});
|
|
6180
6277
|
}
|
|
6181
6278
|
async nextUploadCandidate(producer, hostSourceRef) {
|
|
6182
|
-
await this.prepare();
|
|
6183
6279
|
const names = await this.readNextSessionNames();
|
|
6184
6280
|
for (const name of names) {
|
|
6185
|
-
const state = await readOptionalJson(
|
|
6281
|
+
const state = await readOptionalJson(join5(this.sessions, name), HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
6186
6282
|
if (state === null) continue;
|
|
6187
6283
|
validateStateOwner(state, producer, hostSourceRef);
|
|
6188
6284
|
let validated = state;
|
|
@@ -6197,7 +6293,14 @@ var HostUsageFactsStore = class {
|
|
|
6197
6293
|
return null;
|
|
6198
6294
|
}
|
|
6199
6295
|
async readNextSessionNames() {
|
|
6200
|
-
this.sessionDirectoryCursor
|
|
6296
|
+
if (this.sessionDirectoryCursor === void 0) {
|
|
6297
|
+
try {
|
|
6298
|
+
this.sessionDirectoryCursor = await opendir(this.sessions);
|
|
6299
|
+
} catch (error) {
|
|
6300
|
+
if (errorCode3(error) === "ENOENT") return [];
|
|
6301
|
+
throw error;
|
|
6302
|
+
}
|
|
6303
|
+
}
|
|
6201
6304
|
const names = [];
|
|
6202
6305
|
let inspected = 0;
|
|
6203
6306
|
while (inspected < HOST_USAGE_FACTS_UPLOAD_SCAN_SESSIONS) {
|
|
@@ -6363,14 +6466,14 @@ var HostUsageFactsStore = class {
|
|
|
6363
6466
|
}
|
|
6364
6467
|
}
|
|
6365
6468
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
6366
|
-
return
|
|
6469
|
+
return join5(this.sessions, `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`);
|
|
6367
6470
|
}
|
|
6368
6471
|
batchSessionDirectory(producer, hostSourceRef, hostSessionRef) {
|
|
6369
6472
|
const sessionName = `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`;
|
|
6370
|
-
return
|
|
6473
|
+
return join5(this.batches, sessionName.slice(0, -5));
|
|
6371
6474
|
}
|
|
6372
6475
|
batchPath(state, batchRef) {
|
|
6373
|
-
return
|
|
6476
|
+
return join5(this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref), batchFileName(batchRef));
|
|
6374
6477
|
}
|
|
6375
6478
|
};
|
|
6376
6479
|
function serializeBatch(batch) {
|
|
@@ -6939,6 +7042,10 @@ var HostUsageFactsUploader = class {
|
|
|
6939
7042
|
async close() {
|
|
6940
7043
|
await this.store.close();
|
|
6941
7044
|
}
|
|
7045
|
+
/** The start owner prepares the store once, so idle ticks below never re-prepare. */
|
|
7046
|
+
async prepare() {
|
|
7047
|
+
await this.store.prepare();
|
|
7048
|
+
}
|
|
6942
7049
|
async uploadOne(signal) {
|
|
6943
7050
|
const candidate = await this.store.nextUploadCandidate(this.options.producer, this.options.host_source_ref);
|
|
6944
7051
|
if (candidate === null) return false;
|
|
@@ -6961,6 +7068,11 @@ var HostUsageFactsUploader = class {
|
|
|
6961
7068
|
};
|
|
6962
7069
|
async function runHostUsageFactsUploader(options, signal, wait = waitForAbort) {
|
|
6963
7070
|
const uploader = new HostUsageFactsUploader(options);
|
|
7071
|
+
try {
|
|
7072
|
+
await uploader.prepare();
|
|
7073
|
+
} catch {
|
|
7074
|
+
writeHostServiceDiagnostic(options.producer, "usage_upload_failed", void 0, "upload_failed");
|
|
7075
|
+
}
|
|
6964
7076
|
let delay = 500;
|
|
6965
7077
|
let failures = 0;
|
|
6966
7078
|
try {
|
|
@@ -7050,7 +7162,7 @@ import { createConnection, createServer } from "node:net";
|
|
|
7050
7162
|
import { createHmac, randomBytes } from "node:crypto";
|
|
7051
7163
|
import { constants as constants5 } from "node:fs";
|
|
7052
7164
|
import { link, unlink as unlink4 } from "node:fs/promises";
|
|
7053
|
-
import { dirname as dirname7, join as
|
|
7165
|
+
import { dirname as dirname7, join as join6 } from "node:path";
|
|
7054
7166
|
var RELAY_PIPE_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
7055
7167
|
var RELAY_PIPE_KEY_BYTES = 32;
|
|
7056
7168
|
var RELAY_PIPE_KEY_FILENAME = "relay-pipe.key";
|
|
@@ -7070,10 +7182,10 @@ var RelayPipeHandshakeError = class extends Error {
|
|
|
7070
7182
|
}
|
|
7071
7183
|
};
|
|
7072
7184
|
function relayPipeStateRootForOutboxDir(outboxDir) {
|
|
7073
|
-
return
|
|
7185
|
+
return join6(dirname7(dirname7(dirname7(outboxDir))), "relay");
|
|
7074
7186
|
}
|
|
7075
7187
|
function relayPipeKeyPath(relayStateRoot) {
|
|
7076
|
-
return
|
|
7188
|
+
return join6(relayStateRoot, RELAY_PIPE_KEY_FILENAME);
|
|
7077
7189
|
}
|
|
7078
7190
|
async function loadRelayPipeKey(relayStateRoot, platform = process.platform, custody = {}) {
|
|
7079
7191
|
const path = relayPipeKeyPath(relayStateRoot);
|
|
@@ -7583,17 +7695,133 @@ async function authenticateHostInvocation(descriptor2, input, options) {
|
|
|
7583
7695
|
const request2 = decodeCealHostInvocationAuthenticationRequest({ schema_version: CEAL_HOST_INVOCATION_AUTHENTICATION_REQUEST_SCHEMA, client_nonce: input[2] });
|
|
7584
7696
|
const config = validateOptions(options);
|
|
7585
7697
|
const now = config.now ?? (() => /* @__PURE__ */ new Date());
|
|
7586
|
-
const
|
|
7698
|
+
const store = descriptor2.create_store(config.outbox_dir);
|
|
7699
|
+
const resolved = resolveIdentity(descriptor2, config);
|
|
7700
|
+
if (resolved.status === "session_unavailable") throw new TypeError("no_binding");
|
|
7701
|
+
const toolCallId = resolveToolCallId(descriptor2, config);
|
|
7702
|
+
const selection = await readHookSelection(store, resolved.identity);
|
|
7703
|
+
if (selection === null) {
|
|
7704
|
+
const callTime = await trySelectionlessCallTimeBinding(descriptor2, store, resolved.identity, config, toolCallId);
|
|
7705
|
+
if (callTime !== null) return authenticateCallTimeBinding(descriptor2, store, callTime, request2.client_nonce, config, now);
|
|
7706
|
+
} else if (!waitPossible(config) && !await hasLiveInvocationContext(store, resolved.identity, now)) {
|
|
7707
|
+
const direct = await tryDirectCallTimeBinding(descriptor2, store, resolved.identity, selection, config, toolCallId);
|
|
7708
|
+
if (direct !== null) return authenticateCallTimeBinding(descriptor2, store, direct, request2.client_nonce, config, now);
|
|
7709
|
+
}
|
|
7710
|
+
return authenticateHookGated(descriptor2, store, request2.client_nonce, config, now, toolCallId);
|
|
7711
|
+
}
|
|
7712
|
+
function selectCallTimeBinding(window, toolCallId) {
|
|
7713
|
+
const newest = window.messages[0];
|
|
7714
|
+
if (newest === void 0) return null;
|
|
7715
|
+
return { message: newest, mode: toolCallId === void 0 ? "newest_message" : "tool_call" };
|
|
7716
|
+
}
|
|
7717
|
+
async function authenticateCallTimeBinding(descriptor2, store, callTime, clientNonce, config, now) {
|
|
7718
|
+
if (config.mint_invocation_context === void 0) throw new TypeError("relay_failed");
|
|
7719
|
+
const query = await invocationMintQuery(descriptor2, store, { identity: callTime.binding, expires_at: callTime.expires_at }, clientNonce, config, callTime.window);
|
|
7720
|
+
const response2 = await mintedResult(config.mint_invocation_context, query);
|
|
7721
|
+
const completedAt = now();
|
|
7722
|
+
const newest = await rereadCallTimeNewest(descriptor2, store, callTime.binding, config);
|
|
7723
|
+
if (newest === null || newest.host_turn_ref !== callTime.binding.host_turn_ref || newest.host_input_ref !== callTime.window.messages[0]?.host_input_ref) throw new TypeError("context_replaced");
|
|
7724
|
+
return decodeCealHostInvocationAuthenticationResult(response2.result, completedAt);
|
|
7725
|
+
}
|
|
7726
|
+
async function authenticateHookGated(descriptor2, store, clientNonce, config, now, toolCallId) {
|
|
7727
|
+
const { current } = await currentInvocation(descriptor2, config, now, store);
|
|
7587
7728
|
if (config.mint_invocation_context === void 0) throw new TypeError("relay_failed");
|
|
7588
|
-
const
|
|
7729
|
+
const window = await readCallTimeWindow(descriptor2, store, current.identity, config);
|
|
7730
|
+
const selected = selectCallTimeBinding(window, toolCallId);
|
|
7731
|
+
if (selected !== null && selected.message.host_turn_ref !== current.identity.host_turn_ref) {
|
|
7732
|
+
const selection = await readHookSelection(store, current.identity);
|
|
7733
|
+
if (selection === null || transcriptCatchesHookSelection(selection, selected.message)) {
|
|
7734
|
+
return authenticateCallTimeBinding(descriptor2, store, {
|
|
7735
|
+
binding: { ...current.identity, host_turn_ref: selected.message.host_turn_ref },
|
|
7736
|
+
expires_at: current.expires_at,
|
|
7737
|
+
window,
|
|
7738
|
+
mode: selected.mode
|
|
7739
|
+
}, clientNonce, config, now);
|
|
7740
|
+
}
|
|
7741
|
+
}
|
|
7742
|
+
const query = await invocationMintQuery(descriptor2, store, current, clientNonce, config, window);
|
|
7589
7743
|
const response2 = await mintedResult(config.mint_invocation_context, query);
|
|
7590
7744
|
const completedAt = now();
|
|
7591
7745
|
const rechecked = await store.readInvocationContext(current.identity.host_source_ref, current.identity.host_session_ref, completedAt);
|
|
7592
7746
|
if (rechecked === null || !sameTurn(current, rechecked)) throw new TypeError("context_replaced");
|
|
7593
7747
|
return decodeCealHostInvocationAuthenticationResult(response2.result, completedAt);
|
|
7594
7748
|
}
|
|
7595
|
-
async function
|
|
7596
|
-
const
|
|
7749
|
+
async function trySelectionlessCallTimeBinding(descriptor2, store, identity, config, toolCallId) {
|
|
7750
|
+
const registration = await liveTranscriptRegistration(store, identity);
|
|
7751
|
+
if (registration === null) return null;
|
|
7752
|
+
let window;
|
|
7753
|
+
try {
|
|
7754
|
+
window = await readCallTimeWindow(descriptor2, store, identity, config);
|
|
7755
|
+
} catch {
|
|
7756
|
+
throw new TypeError("transient_retryable");
|
|
7757
|
+
}
|
|
7758
|
+
const selected = selectCallTimeBinding(window, toolCallId);
|
|
7759
|
+
if (selected === null) return null;
|
|
7760
|
+
return { binding: { ...identity, host_turn_ref: selected.message.host_turn_ref }, expires_at: registration.expires_at, window, mode: selected.mode };
|
|
7761
|
+
}
|
|
7762
|
+
async function tryDirectCallTimeBinding(descriptor2, store, identity, selection, config, toolCallId) {
|
|
7763
|
+
let window;
|
|
7764
|
+
try {
|
|
7765
|
+
window = await readCallTimeWindow(descriptor2, store, identity, config);
|
|
7766
|
+
} catch {
|
|
7767
|
+
return null;
|
|
7768
|
+
}
|
|
7769
|
+
const selected = selectCallTimeBinding(window, toolCallId);
|
|
7770
|
+
if (selected === null || !transcriptCatchesHookSelection(selection, selected.message)) return null;
|
|
7771
|
+
const registration = await liveTranscriptRegistration(store, identity);
|
|
7772
|
+
if (registration === null) return null;
|
|
7773
|
+
return { binding: { ...identity, host_turn_ref: selected.message.host_turn_ref }, expires_at: registration.expires_at, window, mode: selected.mode };
|
|
7774
|
+
}
|
|
7775
|
+
async function readCallTimeWindow(descriptor2, store, identity, config) {
|
|
7776
|
+
return await (config.read_human_message_window?.(identity) ?? descriptor2.read_human_message_window?.({ store, identity }) ?? Promise.resolve({ messages: [], truncated: false }));
|
|
7777
|
+
}
|
|
7778
|
+
function transcriptCatchesHookSelection(selection, newest) {
|
|
7779
|
+
if (newest.text_truncated === true) return false;
|
|
7780
|
+
return hostProducerPromptRef(createHash8("sha256").update(newest.text, "utf8").digest("hex")) === selection.prompt_ref;
|
|
7781
|
+
}
|
|
7782
|
+
async function readHookSelection(store, identity) {
|
|
7783
|
+
try {
|
|
7784
|
+
return await store.readInvocationTurnSelection?.(identity.host_source_ref, identity.host_session_ref) ?? null;
|
|
7785
|
+
} catch {
|
|
7786
|
+
return null;
|
|
7787
|
+
}
|
|
7788
|
+
}
|
|
7789
|
+
async function hasLiveInvocationContext(store, identity, now) {
|
|
7790
|
+
try {
|
|
7791
|
+
return await store.readInvocationContext(identity.host_source_ref, identity.host_session_ref, now()) !== null;
|
|
7792
|
+
} catch {
|
|
7793
|
+
return false;
|
|
7794
|
+
}
|
|
7795
|
+
}
|
|
7796
|
+
function waitPossible(config) {
|
|
7797
|
+
return (config.context_activation_wait_ms ?? 0) > 0;
|
|
7798
|
+
}
|
|
7799
|
+
async function liveTranscriptRegistration(store, identity) {
|
|
7800
|
+
try {
|
|
7801
|
+
const registration = await store.readTranscriptRegistration?.(identity.host_source_ref, identity.host_session_ref) ?? null;
|
|
7802
|
+
if (registration !== null && Date.parse(registration.expires_at) > Date.now()) return registration;
|
|
7803
|
+
} catch {
|
|
7804
|
+
}
|
|
7805
|
+
return null;
|
|
7806
|
+
}
|
|
7807
|
+
async function rereadCallTimeNewest(descriptor2, store, identity, config) {
|
|
7808
|
+
try {
|
|
7809
|
+
return (await readCallTimeWindow(descriptor2, store, identity, config)).messages[0] ?? null;
|
|
7810
|
+
} catch {
|
|
7811
|
+
return null;
|
|
7812
|
+
}
|
|
7813
|
+
}
|
|
7814
|
+
function resolveToolCallId(descriptor2, options) {
|
|
7815
|
+
if (options.tool_call_id !== void 0) return validToolCallId(options.tool_call_id) ? options.tool_call_id : void 0;
|
|
7816
|
+
if (descriptor2.tool_call_id_env === void 0) return void 0;
|
|
7817
|
+
const value = process.env[descriptor2.tool_call_id_env];
|
|
7818
|
+
return validToolCallId(value) ? value : void 0;
|
|
7819
|
+
}
|
|
7820
|
+
function validToolCallId(value) {
|
|
7821
|
+
return typeof value === "string" && value.length > 0 && value.length <= 256 && !value.includes("\0");
|
|
7822
|
+
}
|
|
7823
|
+
async function invocationMintQuery(descriptor2, store, current, clientNonce, options, windowOverride) {
|
|
7824
|
+
const readWindow = windowOverride === void 0 ? options.read_human_message_window?.(current.identity) ?? descriptor2.read_human_message_window?.({ store, identity: current.identity }) ?? Promise.resolve({ messages: [], truncated: false }) : Promise.resolve(windowOverride);
|
|
7597
7825
|
return {
|
|
7598
7826
|
producer_id: descriptor2.producer_id,
|
|
7599
7827
|
producer_installation_ref: options.producer_installation_ref,
|
|
@@ -7625,8 +7853,7 @@ async function mintedResult(mint, query) {
|
|
|
7625
7853
|
function validGenericGatewayRefusalStatus2(value) {
|
|
7626
7854
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 400 && value < 500 && value !== 401 && value !== 429;
|
|
7627
7855
|
}
|
|
7628
|
-
async function currentInvocation(descriptor2, config, now) {
|
|
7629
|
-
const store = descriptor2.create_store(config.outbox_dir);
|
|
7856
|
+
async function currentInvocation(descriptor2, config, now, store) {
|
|
7630
7857
|
const identity = resolveIdentity(descriptor2, config);
|
|
7631
7858
|
if (identity.status === "session_unavailable") throw new TypeError("no_binding");
|
|
7632
7859
|
const waitBudgetMs = config.context_activation_wait_ms ?? 0;
|
|
@@ -7643,7 +7870,7 @@ async function currentInvocation(descriptor2, config, now) {
|
|
|
7643
7870
|
const current = await readLiveSessionContext(store, identity.identity.host_source_ref, identity.identity.host_session_ref, observedAt);
|
|
7644
7871
|
if (current !== null) {
|
|
7645
7872
|
recordActivationWaitCompletion(descriptor2.producer_id, waitEngaged, config.diagnostic_sink);
|
|
7646
|
-
return {
|
|
7873
|
+
return { current };
|
|
7647
7874
|
}
|
|
7648
7875
|
await rejectWhenActivationWaitIsUnavailable(descriptor2, store, identity.identity, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
7649
7876
|
const remainingMs = deadline - monotonicNow();
|
|
@@ -7717,7 +7944,7 @@ function waitForContextActivation(milliseconds) {
|
|
|
7717
7944
|
});
|
|
7718
7945
|
}
|
|
7719
7946
|
function validateOptions(options) {
|
|
7720
|
-
if (typeof options.outbox_dir !== "string" || options.outbox_dir.length === 0 || typeof options.host_source_ref !== "string" || !SAFE_REF.test(options.host_source_ref) || typeof options.producer_installation_ref !== "string" || !SAFE_REF.test(options.producer_installation_ref) || !validContextActivationWait(options.context_activation_wait_ms) || !validOptionalSession(options.session_id)) {
|
|
7947
|
+
if (typeof options.outbox_dir !== "string" || options.outbox_dir.length === 0 || typeof options.host_source_ref !== "string" || !SAFE_REF.test(options.host_source_ref) || typeof options.producer_installation_ref !== "string" || !SAFE_REF.test(options.producer_installation_ref) || !validContextActivationWait(options.context_activation_wait_ms) || options.tool_call_id !== void 0 && typeof options.tool_call_id !== "string" || !validOptionalSession(options.session_id)) {
|
|
7721
7948
|
throw new TypeError("options_invalid");
|
|
7722
7949
|
}
|
|
7723
7950
|
return options;
|
|
@@ -7970,10 +8197,11 @@ function boundedMilliseconds(value) {
|
|
|
7970
8197
|
}
|
|
7971
8198
|
|
|
7972
8199
|
// host/codex/src/codex-decoder.ts
|
|
7973
|
-
import { createHash as
|
|
8200
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
7974
8201
|
|
|
7975
8202
|
// host/codex/src/codex-types.ts
|
|
7976
8203
|
var CODEX_THREAD_ID_ENVIRONMENT = "CODEX_THREAD_ID";
|
|
8204
|
+
var CODEX_TOOL_CALL_ID_ENVIRONMENT = "CODEX_TOOL_CALL_ID";
|
|
7977
8205
|
var CODEX_OUTBOX_SCHEMA_VERSION = "ceal.codex_observation_outbox.v1";
|
|
7978
8206
|
var CODEX_SESSION_SCHEMA_VERSION = "ceal.codex_session.v1";
|
|
7979
8207
|
var CODEX_INVOCATION_CONTEXT_SCHEMA_VERSION = "ceal.codex_invocation_context.v1";
|
|
@@ -8015,14 +8243,14 @@ function turnObservationValue(sessionId, turnRef, status) {
|
|
|
8015
8243
|
return { status, host_session_id_sha256: sha2563(sessionId), host_turn_ref: turnRef };
|
|
8016
8244
|
}
|
|
8017
8245
|
function sha2563(value) {
|
|
8018
|
-
return
|
|
8246
|
+
return createHash9("sha256").update(value, "utf8").digest("hex");
|
|
8019
8247
|
}
|
|
8020
8248
|
function shortDigest(value) {
|
|
8021
8249
|
return cealRequestSha256(value);
|
|
8022
8250
|
}
|
|
8023
8251
|
|
|
8024
8252
|
// host/codex/src/codex-transcript-baseline.ts
|
|
8025
|
-
import { createHash as
|
|
8253
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
8026
8254
|
|
|
8027
8255
|
// host/codex/src/codex-transcript-decoder.ts
|
|
8028
8256
|
var SAFE_REF5 = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u;
|
|
@@ -8246,7 +8474,7 @@ function assertCodexTranscriptHeader(registration, record3) {
|
|
|
8246
8474
|
])}).`);
|
|
8247
8475
|
}
|
|
8248
8476
|
function digest(value) {
|
|
8249
|
-
return
|
|
8477
|
+
return createHash10("sha256").update(value).digest("hex");
|
|
8250
8478
|
}
|
|
8251
8479
|
function timestamp(now) {
|
|
8252
8480
|
const value = now();
|
|
@@ -8255,8 +8483,8 @@ function timestamp(now) {
|
|
|
8255
8483
|
}
|
|
8256
8484
|
|
|
8257
8485
|
// host/codex/src/codex-outbox.ts
|
|
8258
|
-
import { mkdir as mkdir5, open as open5,
|
|
8259
|
-
import { dirname as dirname8, isAbsolute as
|
|
8486
|
+
import { mkdir as mkdir5, open as open5, rename as rename2, stat as stat3, unlink as unlink5 } from "node:fs/promises";
|
|
8487
|
+
import { dirname as dirname8, isAbsolute as isAbsolute4, join as join7 } from "node:path";
|
|
8260
8488
|
|
|
8261
8489
|
// host/invocation-context.ts
|
|
8262
8490
|
var HOST_INVOCATION_TURN_SELECTION_SCHEMA = "ceal.host_invocation_turn_selection.v1";
|
|
@@ -8363,12 +8591,12 @@ var CodexOutboxStore = class {
|
|
|
8363
8591
|
constructor(directory) {
|
|
8364
8592
|
if (typeof directory !== "string" || directory.length === 0) throw new CodexHostAdapterError("configuration", "Codex outbox directory is required.");
|
|
8365
8593
|
this.directory = directory;
|
|
8366
|
-
this.entriesDirectory =
|
|
8367
|
-
this.sessionsDirectory =
|
|
8368
|
-
this.activeContextsDirectory =
|
|
8369
|
-
this.turnSelectionsDirectory =
|
|
8370
|
-
this.registrationsDirectory =
|
|
8371
|
-
this.cursorsDirectory =
|
|
8594
|
+
this.entriesDirectory = join7(directory, "entries");
|
|
8595
|
+
this.sessionsDirectory = join7(directory, "sessions");
|
|
8596
|
+
this.activeContextsDirectory = join7(directory, "active-contexts");
|
|
8597
|
+
this.turnSelectionsDirectory = join7(directory, "turn-selections");
|
|
8598
|
+
this.registrationsDirectory = join7(directory, "transcript-registrations");
|
|
8599
|
+
this.cursorsDirectory = join7(directory, "transcript-cursors");
|
|
8372
8600
|
}
|
|
8373
8601
|
async prepare() {
|
|
8374
8602
|
for (const path of [this.directory, this.entriesDirectory, this.sessionsDirectory, this.activeContextsDirectory, this.turnSelectionsDirectory, this.registrationsDirectory, this.cursorsDirectory]) {
|
|
@@ -8381,13 +8609,12 @@ var CodexOutboxStore = class {
|
|
|
8381
8609
|
await writeAtomicJson(this.entryPath(entry.submission_ref), entry);
|
|
8382
8610
|
}
|
|
8383
8611
|
async list() {
|
|
8384
|
-
await this.prepare();
|
|
8385
8612
|
const entries = [];
|
|
8386
8613
|
let malformed = 0;
|
|
8387
|
-
for (const name of await
|
|
8614
|
+
for (const name of await listHostOutboxDirectoryNames(this.entriesDirectory)) {
|
|
8388
8615
|
if (!name.endsWith(".json")) continue;
|
|
8389
8616
|
try {
|
|
8390
|
-
const value = JSON.parse(await readOwnerStateFile(
|
|
8617
|
+
const value = JSON.parse(await readOwnerStateFile(join7(this.entriesDirectory, name)));
|
|
8391
8618
|
validateEnvelope(value);
|
|
8392
8619
|
entries.push(value);
|
|
8393
8620
|
} catch {
|
|
@@ -8432,7 +8659,6 @@ var CodexOutboxStore = class {
|
|
|
8432
8659
|
}
|
|
8433
8660
|
async readInvocationTurnSelection(hostSourceRef, hostSessionRef) {
|
|
8434
8661
|
if (!SAFE_REF6.test(hostSourceRef) || !SAFE_REF6.test(hostSessionRef)) throw new CodexHostAdapterError("invalid_input", "Codex Host turn selection identity is invalid.");
|
|
8435
|
-
await this.prepare();
|
|
8436
8662
|
return readOptionalJson2(this.turnSelectionPath(hostSourceRef, hostSessionRef), validateTurnSelection);
|
|
8437
8663
|
}
|
|
8438
8664
|
async attachInvocationTurnGeneration(identity, promptRef, turnGenerationRef) {
|
|
@@ -8441,6 +8667,7 @@ var CodexOutboxStore = class {
|
|
|
8441
8667
|
const path = this.activeContextPath(identity);
|
|
8442
8668
|
const active = await readOptionalJson2(path, validateCodexHostInvocationContext);
|
|
8443
8669
|
if (active === null || active.prompt_ref !== promptRef || !sameIdentity(active.identity, identity)) return false;
|
|
8670
|
+
await this.prepare();
|
|
8444
8671
|
await writeAtomicJson(path, { ...active, turn_generation_ref: turnGenerationRef });
|
|
8445
8672
|
return true;
|
|
8446
8673
|
}
|
|
@@ -8457,7 +8684,6 @@ var CodexOutboxStore = class {
|
|
|
8457
8684
|
*/
|
|
8458
8685
|
async readRawInvocationContext(hostSourceRef, hostSessionRef) {
|
|
8459
8686
|
if (!SAFE_REF6.test(hostSourceRef) || !SAFE_REF6.test(hostSessionRef)) throw new CodexHostAdapterError("invalid_input", "Codex Host session identity is invalid.");
|
|
8460
|
-
await this.prepare();
|
|
8461
8687
|
const context = await readLatestSessionProjection(this.activeContextPath({ host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }), hostSourceRef, hostSessionRef, (file) => readOptionalJson2(file, validateCodexHostInvocationContext));
|
|
8462
8688
|
return context;
|
|
8463
8689
|
}
|
|
@@ -8481,7 +8707,6 @@ var CodexOutboxStore = class {
|
|
|
8481
8707
|
async readSession(sourceRef, sessionRef) {
|
|
8482
8708
|
const identity = { host_source_ref: sourceRef, host_session_ref: sessionRef };
|
|
8483
8709
|
if (!SAFE_REF6.test(sourceRef) || !SAFE_REF6.test(sessionRef)) throw new CodexHostAdapterError("invalid_input", "Codex session identity is invalid.");
|
|
8484
|
-
await this.prepare();
|
|
8485
8710
|
return readOptionalJson2(this.sessionPath(identity.host_source_ref, identity.host_session_ref), validateSession);
|
|
8486
8711
|
}
|
|
8487
8712
|
async registerTranscript(registration) {
|
|
@@ -8509,18 +8734,16 @@ var CodexOutboxStore = class {
|
|
|
8509
8734
|
}
|
|
8510
8735
|
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
8511
8736
|
const path = this.registrationPath(hostSourceRef, hostSessionRef);
|
|
8512
|
-
await this.prepare();
|
|
8513
8737
|
const registration = await readOptionalJson2(path, validateRegistration);
|
|
8514
8738
|
if (registration !== null && (registration.host_source_ref !== hostSourceRef || registration.host_session_ref !== hostSessionRef)) throw storageError("Codex transcript registration identity does not match its session.");
|
|
8515
8739
|
return registration;
|
|
8516
8740
|
}
|
|
8517
8741
|
async listTranscriptRegistrations() {
|
|
8518
|
-
await this.prepare();
|
|
8519
8742
|
const registrations = [];
|
|
8520
|
-
for (const name of await
|
|
8743
|
+
for (const name of await listHostOutboxDirectoryNames(this.registrationsDirectory)) {
|
|
8521
8744
|
if (!name.endsWith(".json")) continue;
|
|
8522
8745
|
try {
|
|
8523
|
-
const value = JSON.parse(await readOwnerStateFile(
|
|
8746
|
+
const value = JSON.parse(await readOwnerStateFile(join7(this.registrationsDirectory, name)));
|
|
8524
8747
|
validateRegistration(value);
|
|
8525
8748
|
registrations.push(value);
|
|
8526
8749
|
} catch {
|
|
@@ -8530,7 +8753,6 @@ var CodexOutboxStore = class {
|
|
|
8530
8753
|
}
|
|
8531
8754
|
async readTranscriptCursor(registration) {
|
|
8532
8755
|
validateRegistration(registration);
|
|
8533
|
-
await this.prepare();
|
|
8534
8756
|
return readOptionalJson2(this.cursorPath(registration.host_source_ref, registration.host_session_ref), validateCursor);
|
|
8535
8757
|
}
|
|
8536
8758
|
async writeTranscriptCursor(cursor) {
|
|
@@ -8543,7 +8765,6 @@ var CodexOutboxStore = class {
|
|
|
8543
8765
|
const read2 = await this.list();
|
|
8544
8766
|
const envelope = findEnvelopeByAlias(read2.entries, sourceRef, sessionRef, alias);
|
|
8545
8767
|
if (envelope !== null) return envelopeMatch(envelope);
|
|
8546
|
-
await this.prepare();
|
|
8547
8768
|
return null;
|
|
8548
8769
|
}
|
|
8549
8770
|
async hasPriorTurn(sourceRef, sessionRef) {
|
|
@@ -8554,22 +8775,22 @@ var CodexOutboxStore = class {
|
|
|
8554
8775
|
}
|
|
8555
8776
|
entryPath(submissionRef) {
|
|
8556
8777
|
if (!SAFE_REF6.test(submissionRef)) throw storageError("Codex submission identity is malformed.");
|
|
8557
|
-
return
|
|
8778
|
+
return join7(this.entriesDirectory, `${cealRequestSha256(submissionRef)}.json`);
|
|
8558
8779
|
}
|
|
8559
8780
|
sessionPath(sourceRef, sessionRef) {
|
|
8560
|
-
return
|
|
8781
|
+
return join7(this.sessionsDirectory, `${identityKey({ host_source_ref: sourceRef, host_session_ref: sessionRef, host_turn_ref: "session" })}.json`);
|
|
8561
8782
|
}
|
|
8562
8783
|
activeContextPath(identity) {
|
|
8563
|
-
return
|
|
8784
|
+
return join7(this.activeContextsDirectory, `${invocationContextKey(identity)}.json`);
|
|
8564
8785
|
}
|
|
8565
8786
|
turnSelectionPath(sourceRef, sessionRef) {
|
|
8566
|
-
return
|
|
8787
|
+
return join7(this.turnSelectionsDirectory, `${invocationContextKey({ host_source_ref: sourceRef, host_session_ref: sessionRef })}.json`);
|
|
8567
8788
|
}
|
|
8568
8789
|
registrationPath(sourceRef, sessionRef) {
|
|
8569
|
-
return
|
|
8790
|
+
return join7(this.registrationsDirectory, `${sessionStateKey(sourceRef, sessionRef)}.json`);
|
|
8570
8791
|
}
|
|
8571
8792
|
cursorPath(sourceRef, sessionRef) {
|
|
8572
|
-
return
|
|
8793
|
+
return join7(this.cursorsDirectory, `${sessionStateKey(sourceRef, sessionRef)}.json`);
|
|
8573
8794
|
}
|
|
8574
8795
|
};
|
|
8575
8796
|
async function removeOwnerState(path, what) {
|
|
@@ -8703,7 +8924,7 @@ function validateRegistrationFields(value) {
|
|
|
8703
8924
|
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 }])}).`);
|
|
8704
8925
|
}
|
|
8705
8926
|
function validRegistrationCwd(value) {
|
|
8706
|
-
return value === void 0 || typeof value === "string" &&
|
|
8927
|
+
return value === void 0 || typeof value === "string" && isAbsolute4(value) && value.length <= CODEX_TRANSCRIPT_PATH_MAX_CHARACTERS && !value.includes("\0");
|
|
8707
8928
|
}
|
|
8708
8929
|
function validateCursor(value) {
|
|
8709
8930
|
if (!isRecord9(value)) throw storageError("Codex transcript cursor is malformed.");
|
|
@@ -8832,11 +9053,11 @@ var CodexProducer = class {
|
|
|
8832
9053
|
};
|
|
8833
9054
|
|
|
8834
9055
|
// host/codex/src/codex-runtime-paths.ts
|
|
8835
|
-
import { join as
|
|
9056
|
+
import { join as join8 } from "node:path";
|
|
8836
9057
|
var CODEX_HOME_ENVIRONMENT = "CODEX_HOME";
|
|
8837
9058
|
var CODEX_HOME_DEFAULT_DIRECTORY = ".codex";
|
|
8838
9059
|
function resolveCodexHome(environment, home) {
|
|
8839
|
-
return environment[CODEX_HOME_ENVIRONMENT] ||
|
|
9060
|
+
return environment[CODEX_HOME_ENVIRONMENT] || join8(home, CODEX_HOME_DEFAULT_DIRECTORY);
|
|
8840
9061
|
}
|
|
8841
9062
|
|
|
8842
9063
|
// host/codex/src/codex-adapter.ts
|
|
@@ -9206,7 +9427,7 @@ async function drainCodexProducerOnce(options) {
|
|
|
9206
9427
|
}
|
|
9207
9428
|
|
|
9208
9429
|
// host/codex/src/codex-usage-facts-capturer.ts
|
|
9209
|
-
import { createHash as
|
|
9430
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
9210
9431
|
var CodexUsageFactsCapturer = class {
|
|
9211
9432
|
sources;
|
|
9212
9433
|
usage;
|
|
@@ -9401,7 +9622,7 @@ function coverageGap(reason, sourceFileRef, startOffset, endOffset, omittedCount
|
|
|
9401
9622
|
return { reason, source_file_ref: sourceFileRef, start_offset: startOffset, end_offset: endOffset, omitted_count: omittedCount };
|
|
9402
9623
|
}
|
|
9403
9624
|
function sha2564(value) {
|
|
9404
|
-
return
|
|
9625
|
+
return createHash11("sha256").update(value).digest("hex");
|
|
9405
9626
|
}
|
|
9406
9627
|
async function anchorMatches(handle, cursor) {
|
|
9407
9628
|
const bytes = Buffer.alloc(cursor.offset - cursor.anchor_start);
|
|
@@ -9450,7 +9671,7 @@ var CODEX_PRODUCER_DESCRIPTOR = {
|
|
|
9450
9671
|
// host/codex/src/codex-visible-output-budget.ts
|
|
9451
9672
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
9452
9673
|
import { homedir } from "node:os";
|
|
9453
|
-
import { join as
|
|
9674
|
+
import { join as join9 } from "node:path";
|
|
9454
9675
|
var import_toml = __toESM(require_toml(), 1);
|
|
9455
9676
|
var CODEX_DEFAULT_TOOL_OUTPUT_TOKEN_LIMIT = 5e3;
|
|
9456
9677
|
var CODEX_UTF8_BYTES_PER_OUTPUT_TOKEN = 4;
|
|
@@ -9458,7 +9679,7 @@ async function resolveCodexVisibleOutputMaxBytes(environment = process.env) {
|
|
|
9458
9679
|
const codexHome = resolveCodexHome(environment, homedir());
|
|
9459
9680
|
let source;
|
|
9460
9681
|
try {
|
|
9461
|
-
source = await readFile2(
|
|
9682
|
+
source = await readFile2(join9(codexHome, "config.toml"), "utf8");
|
|
9462
9683
|
} catch (error) {
|
|
9463
9684
|
return isNotFound2(error) ? codexBytes(CODEX_DEFAULT_TOOL_OUTPUT_TOKEN_LIMIT) : void 0;
|
|
9464
9685
|
}
|
|
@@ -9489,6 +9710,7 @@ var CODEX_INVOCATION_AUTHENTICATION_DESCRIPTOR = {
|
|
|
9489
9710
|
create_store: (directory) => new CodexOutboxStore(directory),
|
|
9490
9711
|
can_wait_for_context_activation: async ({ store, identity }) => await store.readInvocationTurnSelection(identity.host_source_ref, identity.host_session_ref) !== null,
|
|
9491
9712
|
session_id_env: CODEX_THREAD_ID_ENVIRONMENT,
|
|
9713
|
+
tool_call_id_env: CODEX_TOOL_CALL_ID_ENVIRONMENT,
|
|
9492
9714
|
session_ref: hostSessionReference,
|
|
9493
9715
|
config_flag: HOST_PRODUCER_CONFIG_FLAG,
|
|
9494
9716
|
parse_config_flag: parseHostProducerConfigFlag,
|