@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
|
@@ -309,6 +309,12 @@ var CALLER_RECOVERABLE_NEXT_ACTION_VALUES = [
|
|
|
309
309
|
// (never connected, revoked, or expired). The caller runs that exact
|
|
310
310
|
// Operation, completes the consent it hands back, and retries the same call.
|
|
311
311
|
"connect_personal_account",
|
|
312
|
+
// The refusal names the caller's own preferences update step: the read
|
|
313
|
+
// needs a personal connection the caller holds but has not selected in
|
|
314
|
+
// Ceal preferences, or has not confirmed through the initial review. The
|
|
315
|
+
// caller reads personal.preferences.get, runs personal.preferences.update
|
|
316
|
+
// at the current revision to select it, and retries the same call.
|
|
317
|
+
"update_personal_preferences",
|
|
312
318
|
// The provider or Gateway named a bounded wait; the caller waits that long
|
|
313
319
|
// and submits the same read again.
|
|
314
320
|
"retry_after",
|
|
@@ -858,9 +864,11 @@ var LOCAL_COMMAND_INVALID = "The local command or argument is invalid.";
|
|
|
858
864
|
var LOCAL_TRANSPORT_INCOMPLETE = "The local Ceal transport could not complete; report this as a gap.";
|
|
859
865
|
var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask an administrator to restore Gateway availability.";
|
|
860
866
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
861
|
-
var
|
|
867
|
+
var CEAL_CLIENT_UPGRADE_COMMAND = "npm install -g @corca-org/ceal";
|
|
868
|
+
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}\`.`;
|
|
862
869
|
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.";
|
|
863
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select this turn;
|
|
870
|
+
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.";
|
|
871
|
+
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.";
|
|
864
872
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
865
873
|
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
866
874
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
@@ -890,6 +898,9 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
890
898
|
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),
|
|
891
899
|
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),
|
|
892
900
|
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),
|
|
901
|
+
// A stored session that predates the authority-epoch commitment carries no
|
|
902
|
+
// epoch to compare, so it can never refresh: adopt a fresh session instead.
|
|
903
|
+
authority_epoch_unknown: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
893
904
|
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
894
905
|
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),
|
|
895
906
|
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),
|
|
@@ -1014,7 +1025,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1014
1025
|
host_session_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 401),
|
|
1015
1026
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
1016
1027
|
// changes mode; standalone remains the separate Client authority path.
|
|
1017
|
-
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "
|
|
1028
|
+
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "retry", 401, true),
|
|
1018
1029
|
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),
|
|
1019
1030
|
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),
|
|
1020
1031
|
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),
|
|
@@ -1031,7 +1042,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1031
1042
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
1032
1043
|
// sandboxed Relay socket names the run-alone retry.
|
|
1033
1044
|
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),
|
|
1034
|
-
host_relay_unavailable: guidance(
|
|
1045
|
+
host_relay_unavailable: guidance(HOST_RELAY_RESTARTING, "retry", 503, true),
|
|
1035
1046
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
1036
1047
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
1037
1048
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -1279,7 +1290,7 @@ var CEAL_OPERATION_JSON_SCHEMA_BUDGET = Object.freeze({
|
|
|
1279
1290
|
max_literal_nodes: 512
|
|
1280
1291
|
});
|
|
1281
1292
|
|
|
1282
|
-
// packages/ceal-client-protocol/src/operation-json-schema.ts
|
|
1293
|
+
// packages/ceal-client-protocol/src/operation-json-schema-leaf-validators.ts
|
|
1283
1294
|
var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
1284
1295
|
|
|
1285
1296
|
// packages/ceal-client-protocol/src/operation-contract-validation.ts
|
|
@@ -1426,7 +1437,8 @@ var CEAL_OPERATION_ID_PLACEHOLDER = "<operation-id>";
|
|
|
1426
1437
|
var CEAL_OPERATION_INPUT_PLACEHOLDER = "<json-object>";
|
|
1427
1438
|
var MODEL_INVOCATION_BASE_ARGUMENTS = [CEAL_OPERATION_INVOKE_COMMAND, CEAL_OPERATION_ID_PLACEHOLDER].join(" ");
|
|
1428
1439
|
var CEAL_MODEL_INVOCATION_ARGUMENTS = [MODEL_INVOCATION_BASE_ARGUMENTS, CEAL_OPERATION_INPUT_FLAG, shellSingleQuoted(CEAL_OPERATION_INPUT_PLACEHOLDER)].join(" ");
|
|
1429
|
-
var
|
|
1440
|
+
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.`;
|
|
1441
|
+
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.`;
|
|
1430
1442
|
function shellSingleQuoted(value) {
|
|
1431
1443
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
1432
1444
|
}
|
|
@@ -2410,9 +2422,11 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2410
2422
|
invalid_arguments: Object.freeze({ classification: "host_arguments_invalid", next_action: "answer_with_gap" }),
|
|
2411
2423
|
options_invalid: Object.freeze({ classification: "host_configuration_invalid", next_action: "answer_with_gap" }),
|
|
2412
2424
|
session_unavailable: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2413
|
-
//
|
|
2414
|
-
//
|
|
2415
|
-
|
|
2425
|
+
// A missing turn right after a Host restart clears by itself once the
|
|
2426
|
+
// watcher reactivates the turn, so the caller waits briefly and retries;
|
|
2427
|
+
// a caller that knows it is in an ephemeral side conversation keeps the
|
|
2428
|
+
// standalone fallback the guidance names second.
|
|
2429
|
+
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "retry" }),
|
|
2416
2430
|
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
2417
2431
|
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
2418
2432
|
// `no_binding` now means the producer has no real current Host session. The
|
|
@@ -2429,7 +2443,7 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2429
2443
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
2430
2444
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
2431
2445
|
relay_permission_denied: Object.freeze({ classification: "host_relay_permission_denied", next_action: "rerun_outside_agent_sandbox" }),
|
|
2432
|
-
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "
|
|
2446
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "retry" }),
|
|
2433
2447
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
2434
2448
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
2435
2449
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -2929,8 +2943,8 @@ function invalid2(message) {
|
|
|
2929
2943
|
}
|
|
2930
2944
|
|
|
2931
2945
|
// host/claude/src/claude-outbox.ts
|
|
2932
|
-
import { mkdir as mkdir4,
|
|
2933
|
-
import { isAbsolute as
|
|
2946
|
+
import { mkdir as mkdir4, readFile, unlink as unlink3 } from "node:fs/promises";
|
|
2947
|
+
import { isAbsolute as isAbsolute5, join as join5 } from "node:path";
|
|
2934
2948
|
|
|
2935
2949
|
// host/invocation-context.ts
|
|
2936
2950
|
var HOST_INVOCATION_TURN_SELECTION_SCHEMA = "ceal.host_invocation_turn_selection.v1";
|
|
@@ -2999,13 +3013,86 @@ var HOST_PRODUCER_FRAME_ERROR_CODES = [
|
|
|
2999
3013
|
|
|
3000
3014
|
// host/relay/src/host-producer-core.ts
|
|
3001
3015
|
import { createHash as createHash5 } from "node:crypto";
|
|
3016
|
+
import { readdir } from "node:fs/promises";
|
|
3002
3017
|
|
|
3003
3018
|
// host/secure-file.ts
|
|
3004
3019
|
import { execFile } from "node:child_process";
|
|
3005
3020
|
import { constants } from "node:fs";
|
|
3006
3021
|
import { lstat, open } from "node:fs/promises";
|
|
3007
|
-
import { dirname, join as
|
|
3022
|
+
import { dirname, join as join3, win32 } from "node:path";
|
|
3008
3023
|
import { fileURLToPath } from "node:url";
|
|
3024
|
+
|
|
3025
|
+
// host/spawn-working-directory.ts
|
|
3026
|
+
import { mkdirSync } from "node:fs";
|
|
3027
|
+
import { tmpdir } from "node:os";
|
|
3028
|
+
import { isAbsolute as isAbsolute2, join as join2, normalize, parse, sep } from "node:path";
|
|
3029
|
+
function resolveCealSpawnWorkingDirectory(stateRoot, keepOutside = []) {
|
|
3030
|
+
const candidates = [];
|
|
3031
|
+
const explicit = candidateDir(stateRoot);
|
|
3032
|
+
if (explicit !== void 0) candidates.push(explicit);
|
|
3033
|
+
const fallback = defaultHostStateRoot();
|
|
3034
|
+
if (fallback !== void 0 && !candidates.some((candidate) => sameDir(candidate, fallback))) candidates.push(fallback);
|
|
3035
|
+
const temporary = candidateDir(join2(tmpdir(), "ceal-spawn-cwd"));
|
|
3036
|
+
if (temporary !== void 0 && !candidates.some((candidate) => sameDir(candidate, temporary))) candidates.push(temporary);
|
|
3037
|
+
for (const dir of candidates) {
|
|
3038
|
+
if (!keptOutside(dir, keepOutside)) continue;
|
|
3039
|
+
try {
|
|
3040
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
3041
|
+
return dir;
|
|
3042
|
+
} catch {
|
|
3043
|
+
continue;
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
return tmpdir();
|
|
3047
|
+
}
|
|
3048
|
+
function candidateDir(dir) {
|
|
3049
|
+
if (dir === void 0 || dir === "") return void 0;
|
|
3050
|
+
if (!isAbsolute2(dir) || normalize(dir) !== dir || parse(dir).root === dir) return void 0;
|
|
3051
|
+
return normalize(dir);
|
|
3052
|
+
}
|
|
3053
|
+
function defaultHostStateRoot() {
|
|
3054
|
+
if (process.platform === "win32") {
|
|
3055
|
+
const localAppData = nonEmptyEnv("LOCALAPPDATA");
|
|
3056
|
+
if (localAppData === void 0) return void 0;
|
|
3057
|
+
return candidateDir(join2(localAppData, "Ceal", "Host"));
|
|
3058
|
+
}
|
|
3059
|
+
if (process.platform === "darwin") {
|
|
3060
|
+
const home2 = nonEmptyEnv("HOME");
|
|
3061
|
+
if (home2 === void 0) return void 0;
|
|
3062
|
+
return candidateDir(join2(home2, "Library", "Application Support", "Ceal", "Host"));
|
|
3063
|
+
}
|
|
3064
|
+
const xdg = nonEmptyEnv("XDG_STATE_HOME");
|
|
3065
|
+
if (xdg !== void 0) {
|
|
3066
|
+
const root = candidateDir(join2(xdg, "ceal", "host"));
|
|
3067
|
+
if (root !== void 0) return root;
|
|
3068
|
+
}
|
|
3069
|
+
const home = nonEmptyEnv("HOME");
|
|
3070
|
+
if (home === void 0) return void 0;
|
|
3071
|
+
return candidateDir(join2(home, ".local", "state", "ceal", "host"));
|
|
3072
|
+
}
|
|
3073
|
+
function nonEmptyEnv(name) {
|
|
3074
|
+
const value = process.env[name];
|
|
3075
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
3076
|
+
}
|
|
3077
|
+
function keptOutside(dir, keepOutside) {
|
|
3078
|
+
for (const tree of keepOutside) {
|
|
3079
|
+
const clean = candidateDir(tree);
|
|
3080
|
+
if (clean === void 0) continue;
|
|
3081
|
+
if (insideDir(dir, clean)) return false;
|
|
3082
|
+
}
|
|
3083
|
+
return true;
|
|
3084
|
+
}
|
|
3085
|
+
function insideDir(dir, tree) {
|
|
3086
|
+
if (sameDir(dir, tree)) return true;
|
|
3087
|
+
if (process.platform === "win32") return dir.toLowerCase().startsWith(tree.toLowerCase() + sep);
|
|
3088
|
+
return dir.startsWith(tree + sep);
|
|
3089
|
+
}
|
|
3090
|
+
function sameDir(left, right) {
|
|
3091
|
+
if (process.platform === "win32") return left.toLowerCase() === right.toLowerCase();
|
|
3092
|
+
return left === right;
|
|
3093
|
+
}
|
|
3094
|
+
|
|
3095
|
+
// host/secure-file.ts
|
|
3009
3096
|
var SecureFileCustodyError = class extends Error {
|
|
3010
3097
|
name = "SecureFileCustodyError";
|
|
3011
3098
|
reason;
|
|
@@ -3104,7 +3191,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
3104
3191
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
3105
3192
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
3106
3193
|
return await new Promise((resolve2, reject) => {
|
|
3107
|
-
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
3194
|
+
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) => {
|
|
3108
3195
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
3109
3196
|
if (exitCode === null) {
|
|
3110
3197
|
reject(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -3133,7 +3220,7 @@ function securefsRefusal(stderr) {
|
|
|
3133
3220
|
}
|
|
3134
3221
|
function resolveInstalledHostExecutable(platform) {
|
|
3135
3222
|
const privateRuntimeRoot = dirname(fileURLToPath(import.meta.url));
|
|
3136
|
-
return platform === "win32" ? win32.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") :
|
|
3223
|
+
return platform === "win32" ? win32.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") : join3(privateRuntimeRoot, "..", "..", "bin", "ceal-host");
|
|
3137
3224
|
}
|
|
3138
3225
|
function isRecord2(value) {
|
|
3139
3226
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -3157,7 +3244,7 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
3157
3244
|
|
|
3158
3245
|
// host/service-log.ts
|
|
3159
3246
|
import { copyFile, mkdir, stat, truncate, appendFile } from "node:fs/promises";
|
|
3160
|
-
import { dirname as dirname2, isAbsolute as
|
|
3247
|
+
import { dirname as dirname2, isAbsolute as isAbsolute3, posix, win32 as win322 } from "node:path";
|
|
3161
3248
|
|
|
3162
3249
|
// host/service-log-delivery.ts
|
|
3163
3250
|
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
@@ -3323,7 +3410,7 @@ async function persistHostServiceLogLine(line, environment = process.env) {
|
|
|
3323
3410
|
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
3324
3411
|
}
|
|
3325
3412
|
async function appendHostServiceLogLine(path, line) {
|
|
3326
|
-
if (!
|
|
3413
|
+
if (!isAbsolute3(path)) return;
|
|
3327
3414
|
await ensureHostServiceLogDirectory(path);
|
|
3328
3415
|
await appendFile(path, line);
|
|
3329
3416
|
}
|
|
@@ -3547,6 +3634,14 @@ var HostTranscriptWatcher = class {
|
|
|
3547
3634
|
return transcriptCursorBoundsReason(handle, cursor, size);
|
|
3548
3635
|
}
|
|
3549
3636
|
};
|
|
3637
|
+
async function listHostOutboxDirectoryNames(directory) {
|
|
3638
|
+
try {
|
|
3639
|
+
return await readdir(directory);
|
|
3640
|
+
} catch (error) {
|
|
3641
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return [];
|
|
3642
|
+
throw error;
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3550
3645
|
var HostProducerDrainCore = class {
|
|
3551
3646
|
host;
|
|
3552
3647
|
now;
|
|
@@ -3708,7 +3803,7 @@ function errorCode(error) {
|
|
|
3708
3803
|
import { createHash as createHash6 } from "node:crypto";
|
|
3709
3804
|
import { constants as constants2 } from "node:fs";
|
|
3710
3805
|
import { mkdir as mkdir3, open as open3, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
3711
|
-
import { dirname as dirname4, join as
|
|
3806
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
3712
3807
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
3713
3808
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
3714
3809
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -3728,9 +3823,9 @@ var HostUsageFactsStore = class {
|
|
|
3728
3823
|
afterBatchPublish;
|
|
3729
3824
|
sessionDirectoryCursor;
|
|
3730
3825
|
constructor(options) {
|
|
3731
|
-
this.root =
|
|
3732
|
-
this.sessions =
|
|
3733
|
-
this.batches =
|
|
3826
|
+
this.root = join4(options.outbox_dir, "usage-facts");
|
|
3827
|
+
this.sessions = join4(this.root, "sessions");
|
|
3828
|
+
this.batches = join4(this.root, "batches");
|
|
3734
3829
|
this.platform = options.platform ?? process.platform;
|
|
3735
3830
|
this.custody = options.secure_file_custody ?? {};
|
|
3736
3831
|
this.afterPendingWrite = options.afterPendingWrite;
|
|
@@ -3747,7 +3842,6 @@ var HostUsageFactsStore = class {
|
|
|
3747
3842
|
await cursor?.close();
|
|
3748
3843
|
}
|
|
3749
3844
|
async readState(producer, hostSourceRef, hostSessionRef) {
|
|
3750
|
-
await this.prepare();
|
|
3751
3845
|
const path = this.sessionPath(producer, hostSourceRef, hostSessionRef);
|
|
3752
3846
|
const value = await readOptionalJson(path, HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
3753
3847
|
if (value === null) return null;
|
|
@@ -3805,11 +3899,15 @@ var HostUsageFactsStore = class {
|
|
|
3805
3899
|
}
|
|
3806
3900
|
/** Remove unreferenced local batch objects in bounded pieces after settling any exact pending transition. */
|
|
3807
3901
|
async sweepOrphanedBatches(state) {
|
|
3808
|
-
await this.prepare();
|
|
3809
3902
|
const directoryPath = this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref);
|
|
3810
|
-
await preparePrivateDirectory(directoryPath, this.platform, this.custody);
|
|
3811
3903
|
const expected = expectedBatchNames(state);
|
|
3812
|
-
|
|
3904
|
+
let directory;
|
|
3905
|
+
try {
|
|
3906
|
+
directory = await opendir(directoryPath);
|
|
3907
|
+
} catch (error) {
|
|
3908
|
+
if (errorCode2(error) === "ENOENT") return 0;
|
|
3909
|
+
throw error;
|
|
3910
|
+
}
|
|
3813
3911
|
let inspected = 0;
|
|
3814
3912
|
let deleted = 0;
|
|
3815
3913
|
try {
|
|
@@ -3818,7 +3916,7 @@ var HostUsageFactsStore = class {
|
|
|
3818
3916
|
if (entry === null) break;
|
|
3819
3917
|
inspected += 1;
|
|
3820
3918
|
if (!isOrphanBatchEntry(entry, expected)) continue;
|
|
3821
|
-
await unlink2(
|
|
3919
|
+
await unlink2(join4(directoryPath, entry.name));
|
|
3822
3920
|
deleted += 1;
|
|
3823
3921
|
}
|
|
3824
3922
|
} finally {
|
|
@@ -3846,10 +3944,9 @@ var HostUsageFactsStore = class {
|
|
|
3846
3944
|
});
|
|
3847
3945
|
}
|
|
3848
3946
|
async nextUploadCandidate(producer, hostSourceRef) {
|
|
3849
|
-
await this.prepare();
|
|
3850
3947
|
const names = await this.readNextSessionNames();
|
|
3851
3948
|
for (const name of names) {
|
|
3852
|
-
const state = await readOptionalJson(
|
|
3949
|
+
const state = await readOptionalJson(join4(this.sessions, name), HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
3853
3950
|
if (state === null) continue;
|
|
3854
3951
|
validateStateOwner(state, producer, hostSourceRef);
|
|
3855
3952
|
let validated = state;
|
|
@@ -3864,7 +3961,14 @@ var HostUsageFactsStore = class {
|
|
|
3864
3961
|
return null;
|
|
3865
3962
|
}
|
|
3866
3963
|
async readNextSessionNames() {
|
|
3867
|
-
this.sessionDirectoryCursor
|
|
3964
|
+
if (this.sessionDirectoryCursor === void 0) {
|
|
3965
|
+
try {
|
|
3966
|
+
this.sessionDirectoryCursor = await opendir(this.sessions);
|
|
3967
|
+
} catch (error) {
|
|
3968
|
+
if (errorCode2(error) === "ENOENT") return [];
|
|
3969
|
+
throw error;
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3868
3972
|
const names = [];
|
|
3869
3973
|
let inspected = 0;
|
|
3870
3974
|
while (inspected < HOST_USAGE_FACTS_UPLOAD_SCAN_SESSIONS) {
|
|
@@ -4030,14 +4134,14 @@ var HostUsageFactsStore = class {
|
|
|
4030
4134
|
}
|
|
4031
4135
|
}
|
|
4032
4136
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
4033
|
-
return
|
|
4137
|
+
return join4(this.sessions, `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`);
|
|
4034
4138
|
}
|
|
4035
4139
|
batchSessionDirectory(producer, hostSourceRef, hostSessionRef) {
|
|
4036
4140
|
const sessionName = `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`;
|
|
4037
|
-
return
|
|
4141
|
+
return join4(this.batches, sessionName.slice(0, -5));
|
|
4038
4142
|
}
|
|
4039
4143
|
batchPath(state, batchRef) {
|
|
4040
|
-
return
|
|
4144
|
+
return join4(this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref), batchFileName(batchRef));
|
|
4041
4145
|
}
|
|
4042
4146
|
};
|
|
4043
4147
|
function serializeBatch(batch) {
|
|
@@ -4583,6 +4687,10 @@ var HostUsageFactsUploader = class {
|
|
|
4583
4687
|
async close() {
|
|
4584
4688
|
await this.store.close();
|
|
4585
4689
|
}
|
|
4690
|
+
/** The start owner prepares the store once, so idle ticks below never re-prepare. */
|
|
4691
|
+
async prepare() {
|
|
4692
|
+
await this.store.prepare();
|
|
4693
|
+
}
|
|
4586
4694
|
async uploadOne(signal) {
|
|
4587
4695
|
const candidate = await this.store.nextUploadCandidate(this.options.producer, this.options.host_source_ref);
|
|
4588
4696
|
if (candidate === null) return false;
|
|
@@ -4605,6 +4713,11 @@ var HostUsageFactsUploader = class {
|
|
|
4605
4713
|
};
|
|
4606
4714
|
async function runHostUsageFactsUploader(options, signal, wait = waitForAbort) {
|
|
4607
4715
|
const uploader = new HostUsageFactsUploader(options);
|
|
4716
|
+
try {
|
|
4717
|
+
await uploader.prepare();
|
|
4718
|
+
} catch {
|
|
4719
|
+
writeHostServiceDiagnostic(options.producer, "usage_upload_failed", void 0, "upload_failed");
|
|
4720
|
+
}
|
|
4608
4721
|
let delay = 500;
|
|
4609
4722
|
let failures = 0;
|
|
4610
4723
|
try {
|
|
@@ -4649,7 +4762,7 @@ var RELAY_PIPE_FRAME_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
|
4649
4762
|
var HOST_RELAY_IPC_LENGTH_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
4650
4763
|
|
|
4651
4764
|
// host/claude/src/claude-invocation-context.ts
|
|
4652
|
-
import { isAbsolute as
|
|
4765
|
+
import { isAbsolute as isAbsolute4 } from "node:path";
|
|
4653
4766
|
function claudeInvocationContextFromTurn(identity, promptRef, expiresAt, workingDirectory, turnGenerationRef) {
|
|
4654
4767
|
return invocationContextFromTurn(identity, promptRef, expiresAt, { schema_version: CLAUDE_INVOCATION_CONTEXT_SCHEMA_VERSION, validate: validateClaudeHostInvocationContext, working_directory: workingDirectory, turn_generation_ref: turnGenerationRef });
|
|
4655
4768
|
}
|
|
@@ -4678,7 +4791,7 @@ function optionalSafeRef(value) {
|
|
|
4678
4791
|
return value === void 0 || safeRef2(value);
|
|
4679
4792
|
}
|
|
4680
4793
|
function optionalDirectory(value) {
|
|
4681
|
-
return value === void 0 || typeof value === "string" &&
|
|
4794
|
+
return value === void 0 || typeof value === "string" && isAbsolute4(value) && !value.includes("\0") && value.length <= 4096;
|
|
4682
4795
|
}
|
|
4683
4796
|
function safeRef2(value) {
|
|
4684
4797
|
return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u.test(value);
|
|
@@ -4703,14 +4816,14 @@ var ClaudeOutboxStore = class {
|
|
|
4703
4816
|
activeContexts;
|
|
4704
4817
|
turnSelections;
|
|
4705
4818
|
constructor(directory) {
|
|
4706
|
-
if (!
|
|
4819
|
+
if (!isAbsolute5(directory)) throw new ClaudeHostError("configuration", "Claude outbox directory must be absolute.");
|
|
4707
4820
|
this.directory = directory;
|
|
4708
|
-
this.envelopes =
|
|
4709
|
-
this.sessions =
|
|
4710
|
-
this.registrations =
|
|
4711
|
-
this.cursors =
|
|
4712
|
-
this.activeContexts =
|
|
4713
|
-
this.turnSelections =
|
|
4821
|
+
this.envelopes = join5(directory, "envelopes");
|
|
4822
|
+
this.sessions = join5(directory, "sessions");
|
|
4823
|
+
this.registrations = join5(directory, "transcript-registrations");
|
|
4824
|
+
this.cursors = join5(directory, "transcript-cursors");
|
|
4825
|
+
this.activeContexts = join5(directory, "active-contexts");
|
|
4826
|
+
this.turnSelections = join5(directory, "turn-selections");
|
|
4714
4827
|
}
|
|
4715
4828
|
async prepare() {
|
|
4716
4829
|
for (const path of [this.envelopes, this.sessions, this.registrations, this.cursors, this.activeContexts, this.turnSelections]) {
|
|
@@ -4738,6 +4851,7 @@ var ClaudeOutboxStore = class {
|
|
|
4738
4851
|
const path = this.activeContextPath(identity);
|
|
4739
4852
|
const active = await readProjectionFile(path);
|
|
4740
4853
|
if (active === null || active.prompt_ref !== promptRef || active.identity.host_turn_ref !== identity.host_turn_ref) return false;
|
|
4854
|
+
await this.prepare();
|
|
4741
4855
|
const updated = { ...active, turn_generation_ref: turnGenerationRef };
|
|
4742
4856
|
validateClaudeHostInvocationContext(updated);
|
|
4743
4857
|
await durableAtomicReplace(path, JSON.stringify(updated));
|
|
@@ -4750,17 +4864,15 @@ var ClaudeOutboxStore = class {
|
|
|
4750
4864
|
*/
|
|
4751
4865
|
async readRawInvocationContext(hostSourceRef, hostSessionRef) {
|
|
4752
4866
|
if (!SAFE_REF2.test(hostSourceRef) || !SAFE_REF2.test(hostSessionRef)) throw new ClaudeHostError("invalid_input", "Claude Host context identity or clock is invalid.");
|
|
4753
|
-
await this.prepare();
|
|
4754
4867
|
const context = await readLatestSessionProjection(this.activeContextPath({ host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }), hostSourceRef, hostSessionRef, readProjectionFile);
|
|
4755
4868
|
return context;
|
|
4756
4869
|
}
|
|
4757
4870
|
async listInvocationContexts(now = /* @__PURE__ */ new Date()) {
|
|
4758
|
-
await this.prepare();
|
|
4759
4871
|
const contexts = [];
|
|
4760
|
-
for (const name of await
|
|
4872
|
+
for (const name of await listHostOutboxDirectoryNames(this.activeContexts)) {
|
|
4761
4873
|
if (!name.endsWith(".json")) continue;
|
|
4762
4874
|
try {
|
|
4763
|
-
const value = JSON.parse(await readFile(
|
|
4875
|
+
const value = JSON.parse(await readFile(join5(this.activeContexts, name), "utf8"));
|
|
4764
4876
|
validateClaudeHostInvocationContext(value);
|
|
4765
4877
|
if (Date.parse(value.expires_at) > now.getTime()) contexts.push(value);
|
|
4766
4878
|
} catch {
|
|
@@ -4774,13 +4886,12 @@ var ClaudeOutboxStore = class {
|
|
|
4774
4886
|
await durableAtomicReplace(this.envelopePath(entry.submission_ref), JSON.stringify(entry));
|
|
4775
4887
|
}
|
|
4776
4888
|
async listEnvelopes() {
|
|
4777
|
-
await this.prepare();
|
|
4778
4889
|
const entries = [];
|
|
4779
4890
|
let malformed = 0;
|
|
4780
|
-
for (const name of await
|
|
4891
|
+
for (const name of await listHostOutboxDirectoryNames(this.envelopes)) {
|
|
4781
4892
|
if (!name.endsWith(".json")) continue;
|
|
4782
4893
|
try {
|
|
4783
|
-
const value = JSON.parse(await readFile(
|
|
4894
|
+
const value = JSON.parse(await readFile(join5(this.envelopes, name), "utf8"));
|
|
4784
4895
|
validateEnvelope(value);
|
|
4785
4896
|
entries.push(value);
|
|
4786
4897
|
} catch {
|
|
@@ -4801,13 +4912,12 @@ var ClaudeOutboxStore = class {
|
|
|
4801
4912
|
async saveSession(snapshot) {
|
|
4802
4913
|
validateSession(snapshot);
|
|
4803
4914
|
await this.prepare();
|
|
4804
|
-
await durableAtomicReplace(
|
|
4915
|
+
await durableAtomicReplace(join5(this.sessions, `${cealRequestSha256({ source: snapshot.host_source_ref, session: snapshot.host_session_ref })}.json`), JSON.stringify(snapshot));
|
|
4805
4916
|
}
|
|
4806
4917
|
async readSession(sourceRef, sessionRef) {
|
|
4807
4918
|
if (!SAFE_REF2.test(sourceRef) || !SAFE_REF2.test(sessionRef)) throw new ClaudeHostError("invalid_input", "Claude session identity is invalid.");
|
|
4808
|
-
await this.prepare();
|
|
4809
4919
|
try {
|
|
4810
|
-
const value = JSON.parse(await readFile(
|
|
4920
|
+
const value = JSON.parse(await readFile(join5(this.sessions, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`), "utf8"));
|
|
4811
4921
|
validateSession(value);
|
|
4812
4922
|
return value;
|
|
4813
4923
|
} catch (error) {
|
|
@@ -4838,18 +4948,16 @@ var ClaudeOutboxStore = class {
|
|
|
4838
4948
|
}
|
|
4839
4949
|
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
4840
4950
|
if (!SAFE_REF2.test(hostSourceRef) || !SAFE_REF2.test(hostSessionRef)) throw new ClaudeHostError("invalid_input", "Claude transcript session identity is invalid.");
|
|
4841
|
-
await this.prepare();
|
|
4842
4951
|
const registration = await this.readRegistrationFile(this.registrationPath(hostSourceRef, hostSessionRef));
|
|
4843
4952
|
if (registration !== null && (registration.host_source_ref !== hostSourceRef || registration.host_session_ref !== hostSessionRef)) throw new ClaudeHostError("storage", "Claude transcript registration identity does not match its session.");
|
|
4844
4953
|
return registration;
|
|
4845
4954
|
}
|
|
4846
4955
|
async listTranscriptRegistrations() {
|
|
4847
|
-
await this.prepare();
|
|
4848
4956
|
const registrations = [];
|
|
4849
|
-
for (const name of await
|
|
4957
|
+
for (const name of await listHostOutboxDirectoryNames(this.registrations)) {
|
|
4850
4958
|
if (!name.endsWith(".json")) continue;
|
|
4851
4959
|
try {
|
|
4852
|
-
const value = JSON.parse(await readFile(
|
|
4960
|
+
const value = JSON.parse(await readFile(join5(this.registrations, name), "utf8"));
|
|
4853
4961
|
validateRegistration(value);
|
|
4854
4962
|
registrations.push(value);
|
|
4855
4963
|
} catch {
|
|
@@ -4859,7 +4967,6 @@ var ClaudeOutboxStore = class {
|
|
|
4859
4967
|
}
|
|
4860
4968
|
async readInvocationTurnSelection(hostSourceRef, hostSessionRef) {
|
|
4861
4969
|
if (!SAFE_REF2.test(hostSourceRef) || !SAFE_REF2.test(hostSessionRef)) throw new ClaudeHostError("invalid_input", "Claude Host turn selection identity is invalid.");
|
|
4862
|
-
await this.prepare();
|
|
4863
4970
|
try {
|
|
4864
4971
|
const value = JSON.parse(await readFile(this.turnSelectionPath(hostSourceRef, hostSessionRef), "utf8"));
|
|
4865
4972
|
if (!isHostInvocationTurnSelection(value) || value.host_source_ref !== hostSourceRef || value.host_session_ref !== hostSessionRef) throw new ClaudeHostError("storage", "Claude Host turn selection is malformed.");
|
|
@@ -4871,7 +4978,6 @@ var ClaudeOutboxStore = class {
|
|
|
4871
4978
|
}
|
|
4872
4979
|
async readTranscriptCursor(registration) {
|
|
4873
4980
|
validateRegistration(registration);
|
|
4874
|
-
await this.prepare();
|
|
4875
4981
|
try {
|
|
4876
4982
|
const value = JSON.parse(await readFile(this.cursorPath(registration.host_source_ref, registration.host_session_ref), "utf8"));
|
|
4877
4983
|
validateCursor(value);
|
|
@@ -4887,16 +4993,16 @@ var ClaudeOutboxStore = class {
|
|
|
4887
4993
|
await durableAtomicReplace(this.cursorPath(cursor.host_source_ref, cursor.host_session_ref), JSON.stringify(cursor));
|
|
4888
4994
|
}
|
|
4889
4995
|
envelopePath(ref) {
|
|
4890
|
-
return
|
|
4996
|
+
return join5(this.envelopes, `${cealRequestSha256(ref)}.json`);
|
|
4891
4997
|
}
|
|
4892
4998
|
registrationPath(sourceRef, sessionRef) {
|
|
4893
|
-
return
|
|
4999
|
+
return join5(this.registrations, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
4894
5000
|
}
|
|
4895
5001
|
turnSelectionPath(sourceRef, sessionRef) {
|
|
4896
|
-
return
|
|
5002
|
+
return join5(this.turnSelections, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
4897
5003
|
}
|
|
4898
5004
|
cursorPath(sourceRef, sessionRef) {
|
|
4899
|
-
return
|
|
5005
|
+
return join5(this.cursors, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
4900
5006
|
}
|
|
4901
5007
|
async readRegistrationFile(path) {
|
|
4902
5008
|
try {
|
|
@@ -4916,7 +5022,7 @@ var ClaudeOutboxStore = class {
|
|
|
4916
5022
|
}
|
|
4917
5023
|
}
|
|
4918
5024
|
activeContextPath(identity) {
|
|
4919
|
-
return
|
|
5025
|
+
return join5(this.activeContexts, `${invocationContextKey(identity)}.json`);
|
|
4920
5026
|
}
|
|
4921
5027
|
};
|
|
4922
5028
|
function validateInvocationContextReadArguments(hostSourceRef, hostSessionRef, now) {
|
|
@@ -4992,7 +5098,7 @@ function validateRegistration(value) {
|
|
|
4992
5098
|
if (!timestamp2(value.registered_at) || !timestamp2(value.expires_at)) throw new ClaudeHostError("storage", "Claude transcript registration timestamps are malformed.");
|
|
4993
5099
|
}
|
|
4994
5100
|
function validateRegistrationPaths(cwd, transcriptPath) {
|
|
4995
|
-
if (cwd !== void 0 && (typeof cwd !== "string" || !
|
|
5101
|
+
if (cwd !== void 0 && (typeof cwd !== "string" || !isAbsolute5(cwd) || cwd.length > CLAUDE_TRANSCRIPT_PATH_MAX_CHARACTERS || cwd.includes("\0"))) {
|
|
4996
5102
|
throw new ClaudeHostError("storage", "Claude transcript registration working directory is malformed.");
|
|
4997
5103
|
}
|
|
4998
5104
|
if (typeof transcriptPath !== "string" || transcriptPath.length === 0 || transcriptPath.length > CLAUDE_TRANSCRIPT_PATH_MAX_CHARACTERS) {
|
|
@@ -5091,7 +5197,7 @@ function sameKeys2(value, required, optional = []) {
|
|
|
5091
5197
|
// host/claude/src/claude-transcript-watcher.ts
|
|
5092
5198
|
import { readdir as readdir2 } from "node:fs/promises";
|
|
5093
5199
|
import { isDeepStrictEqual } from "node:util";
|
|
5094
|
-
import { join as
|
|
5200
|
+
import { join as join6 } from "node:path";
|
|
5095
5201
|
|
|
5096
5202
|
// host/claude/src/claude-subagent-overflow-checkpoint.ts
|
|
5097
5203
|
var ClaudeSubagentOverflowCheckpoint = class {
|
|
@@ -5384,7 +5490,7 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5384
5490
|
return consumed;
|
|
5385
5491
|
}
|
|
5386
5492
|
async consumeSubagentFile(draft, directory, name) {
|
|
5387
|
-
const path =
|
|
5493
|
+
const path = join6(directory, name);
|
|
5388
5494
|
let handle;
|
|
5389
5495
|
try {
|
|
5390
5496
|
handle = await openNoFollow(path);
|
|
@@ -5633,7 +5739,7 @@ function isAssistantUsageLine(record5) {
|
|
|
5633
5739
|
}
|
|
5634
5740
|
function subagentsDirectory(transcriptPath) {
|
|
5635
5741
|
const stem = transcriptPath.endsWith(".jsonl") ? transcriptPath.slice(0, -".jsonl".length) : transcriptPath;
|
|
5636
|
-
return
|
|
5742
|
+
return join6(stem, "subagents");
|
|
5637
5743
|
}
|
|
5638
5744
|
function observationRef(hostSourceRef, event, identity, value) {
|
|
5639
5745
|
return cealHostObservationRef("claude", transcriptObjectSha256({ host_source_ref: hostSourceRef, event, identity, value }));
|
|
@@ -5673,7 +5779,7 @@ function isSymlinkTranscript(error) {
|
|
|
5673
5779
|
import { createHash as createHash8 } from "node:crypto";
|
|
5674
5780
|
import { constants as constants5 } from "node:fs";
|
|
5675
5781
|
import { readdir as readdir3 } from "node:fs/promises";
|
|
5676
|
-
import { join as
|
|
5782
|
+
import { join as join7 } from "node:path";
|
|
5677
5783
|
var ClaudeUsageFactsCapturer = class {
|
|
5678
5784
|
sources;
|
|
5679
5785
|
usage;
|
|
@@ -5786,7 +5892,7 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5786
5892
|
async captureSubagentFile(registration, name, state) {
|
|
5787
5893
|
let handle;
|
|
5788
5894
|
try {
|
|
5789
|
-
const opened = await readHostUsageTranscriptSource(() => openNoFollow(
|
|
5895
|
+
const opened = await readHostUsageTranscriptSource(() => openNoFollow(join7(subagentsDirectory(registration.transcript_path), name), constants5.O_RDONLY));
|
|
5790
5896
|
handle = opened;
|
|
5791
5897
|
const file = await readHostUsageTranscriptSource(() => ownedClaudeTranscriptFile(opened));
|
|
5792
5898
|
const sourceRef = sourceFileRef(registration, file.device, file.inode);
|
|
@@ -6041,18 +6147,18 @@ import { createHash as createHash9, randomUUID } from "node:crypto";
|
|
|
6041
6147
|
import { readdir as readdir4 } from "node:fs/promises";
|
|
6042
6148
|
import { constants as constants6 } from "node:fs";
|
|
6043
6149
|
import { homedir } from "node:os";
|
|
6044
|
-
import { isAbsolute as
|
|
6150
|
+
import { isAbsolute as isAbsolute6, join as join9, relative, resolve } from "node:path";
|
|
6045
6151
|
|
|
6046
6152
|
// host/claude/src/claude-runtime-paths.ts
|
|
6047
|
-
import { join as
|
|
6153
|
+
import { join as join8 } from "node:path";
|
|
6048
6154
|
var CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT = "CLAUDE_CONFIG_DIR";
|
|
6049
6155
|
var CLAUDE_HOME_DEFAULT_DIRECTORY = ".claude";
|
|
6050
6156
|
var CLAUDE_PROJECTS_DIRECTORY = "projects";
|
|
6051
6157
|
function resolveClaudeConfigHome(environment, home) {
|
|
6052
|
-
return environment[CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT] ||
|
|
6158
|
+
return environment[CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT] || join8(home, CLAUDE_HOME_DEFAULT_DIRECTORY);
|
|
6053
6159
|
}
|
|
6054
6160
|
function resolveClaudeProjectsRoot(environment, home) {
|
|
6055
|
-
return
|
|
6161
|
+
return join8(resolveClaudeConfigHome(environment, home), CLAUDE_PROJECTS_DIRECTORY);
|
|
6056
6162
|
}
|
|
6057
6163
|
|
|
6058
6164
|
// host/claude/src/claude-adapter.ts
|
|
@@ -6150,11 +6256,11 @@ function sessionObservationValue(input) {
|
|
|
6150
6256
|
return { status: "started", host_kind: "claude", source: input.source, model: input.model ?? "unavailable", decoder_evidence_version: "claude-code-2.1.258" };
|
|
6151
6257
|
}
|
|
6152
6258
|
function sourceBoundTranscriptPath(path, transcriptsRoot, platform = process.platform) {
|
|
6153
|
-
if (!
|
|
6259
|
+
if (!isAbsolute6(path) || !isAbsolute6(transcriptsRoot)) throw new ClaudeHostError("configuration", "Claude transcript registration paths must be absolute.");
|
|
6154
6260
|
const transcript = resolve(path);
|
|
6155
6261
|
const root = resolve(transcriptsRoot);
|
|
6156
6262
|
const child = relative(root, transcript);
|
|
6157
|
-
if (child === "" || child === ".." || child.startsWith(`..${platform === "win32" ? "\\" : "/"}`) ||
|
|
6263
|
+
if (child === "" || child === ".." || child.startsWith(`..${platform === "win32" ? "\\" : "/"}`) || isAbsolute6(child)) {
|
|
6158
6264
|
throw new ClaudeHostError("invalid_input", "Claude transcript path is outside the configured transcripts root.");
|
|
6159
6265
|
}
|
|
6160
6266
|
return transcript;
|
|
@@ -6289,7 +6395,7 @@ async function readClaudeSubagentBaseline(transcriptPath, platform, custody) {
|
|
|
6289
6395
|
async function readClaudeSubagentSeed(directory, name, platform, custody) {
|
|
6290
6396
|
let handle;
|
|
6291
6397
|
try {
|
|
6292
|
-
handle = await openNoFollow(
|
|
6398
|
+
handle = await openNoFollow(join9(directory, name), constants6.O_RDONLY, void 0, platform, custody);
|
|
6293
6399
|
const stats = await handle.stat();
|
|
6294
6400
|
if (!stats.isFile()) throw new ClaudeHostError("storage", "Claude subagent baseline source is not a regular file.");
|
|
6295
6401
|
if (platform !== "win32" && !isSelfOwned(stats.uid, platform, handle)) throw new ClaudeHostError("storage", "Claude subagent baseline source is owned by another user.");
|
|
@@ -6383,7 +6489,7 @@ async function drainClaudeProducerOnce(options) {
|
|
|
6383
6489
|
|
|
6384
6490
|
// host/claude/src/claude-hook-runner.ts
|
|
6385
6491
|
import { homedir as homedir2 } from "node:os";
|
|
6386
|
-
import { join as
|
|
6492
|
+
import { join as join10 } from "node:path";
|
|
6387
6493
|
|
|
6388
6494
|
// host/producer-service.ts
|
|
6389
6495
|
import { posix as posix4, win32 as win325 } from "node:path";
|
|
@@ -6672,7 +6778,7 @@ async function installedClaudeHookRunnerOptions(args, custody = {}) {
|
|
|
6672
6778
|
}
|
|
6673
6779
|
function standaloneClaudeHookRunnerOptions(overrides) {
|
|
6674
6780
|
const claudeHome = resolveClaudeConfigHome(process.env, homedir2());
|
|
6675
|
-
return { outbox_dir: overrides?.outbox_dir ??
|
|
6781
|
+
return { outbox_dir: overrides?.outbox_dir ?? join10(claudeHome, ".ceal", "claude-observation-outbox"), claude_transcripts_root: resolveClaudeProjectsRoot(process.env, homedir2()) };
|
|
6676
6782
|
}
|
|
6677
6783
|
function hasHostConfigArgument(args) {
|
|
6678
6784
|
return args.some((argument) => argument === HOST_PRODUCER_CONFIG_FLAG || argument.startsWith(`${HOST_PRODUCER_CONFIG_FLAG}=`));
|