@corca-org/ceal-host-win32-x64 1.0.25 → 1.0.26
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/bin/ceal-host.exe +0 -0
- package/libexec/ceal-host/ceal-host-background.exe +0 -0
- package/libexec/ceal-host/claude-hook.mjs +488 -203
- package/libexec/ceal-host/claude-invocation-authentication.mjs +648 -220
- package/libexec/ceal-host/claude-producer.mjs +1460 -1186
- package/libexec/ceal-host/codex-hook.mjs +436 -196
- package/libexec/ceal-host/codex-invocation-authentication.mjs +697 -304
- package/libexec/ceal-host/codex-producer.mjs +1415 -1180
- package/libexec/ceal-host/control.mjs +2345 -1682
- package/libexec/ceal-host/node/bin/node.exe +2 -2
- package/package.json +1 -1
- package/share/ceal-host/bundle-manifest.json +15 -22
- package/share/ceal-host/bundle-manifest.sigstore.json +1 -1
- package/libexec/ceal-host/relay.mjs +0 -4959
|
@@ -465,7 +465,7 @@ var CEAL_POLICY_DECISIONS = vocabulary(["allowed", "denied", "not_evaluated"]);
|
|
|
465
465
|
var CEAL_CONNECTOR_ROUTE_PHASES = vocabulary(["scope_observation", "target_selection", "route_resolution"]);
|
|
466
466
|
var CEAL_CONNECTOR_ROUTE_CAUSES = vocabulary(["provider_throttled", "provider_unavailable", "binding_invalid", "personal_binding_unproven", "scope_limit_exceeded"]);
|
|
467
467
|
var CEAL_WRITE_SOURCE_KINDS = vocabulary(["authenticated_registered_client", "provider_authenticated_event"]);
|
|
468
|
-
var CEAL_REFRESH_DELIVERIES = vocabulary(["initial", "recovery", "replay", "terminal_failure", "recovery_unavailable", "authority_inactive"]);
|
|
468
|
+
var CEAL_REFRESH_DELIVERIES = vocabulary(["initial", "recovery", "race_recovery", "replay", "terminal_failure", "recovery_unavailable", "authority_inactive"]);
|
|
469
469
|
var CEAL_CLIENT_OPERATIONS = vocabulary(["handshake", "discover", "call", "readback"]);
|
|
470
470
|
var CEAL_WRITE_IDEMPOTENCY_POSTURES = vocabulary(["required", "optional", "not_required"]);
|
|
471
471
|
var CEAL_WRITE_PROVIDER_READBACK_POSTURES = vocabulary(["required", "best_effort", "not_available"]);
|
|
@@ -858,6 +858,7 @@ function requireIsoTimestamp(value, message) {
|
|
|
858
858
|
// packages/ceal-client-protocol/src/failure-guidance-table.ts
|
|
859
859
|
var CEAL_FAILURE_REDACTION_CLASSES = vocabulary(["model_safe", "withheld"]);
|
|
860
860
|
var CEAL_GATEWAY_STARTING_FAILURE_CODE = "gateway_starting";
|
|
861
|
+
var CEAL_GATEWAY_RESTARTING_FAILURE_CODE = "gateway_restarting";
|
|
861
862
|
var CEAL_OWNER_BOOTSTRAP_ABSENT_FAILURE_CODE = "bootstrap_absent";
|
|
862
863
|
var CEAL_OWNER_BOOTSTRAP_UNAVAILABLE_FAILURE_CODE = "bootstrap_unavailable";
|
|
863
864
|
var LOCAL_COMMAND_INVALID = "The local command or argument is invalid.";
|
|
@@ -868,6 +869,7 @@ var CEAL_CLIENT_UPGRADE_COMMAND = "npm install -g @corca-org/ceal";
|
|
|
868
869
|
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}\`.`;
|
|
869
870
|
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.";
|
|
870
871
|
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.";
|
|
872
|
+
var HOST_TRANSCRIPT_UNAVAILABLE = "The Host found no human message in the registered transcript for this turn, so this call has nothing to bind to. Send a new message in the current conversation so the Host re-registers the transcript, then retry the same command. If it still fails, start a new conversation and report intended Host calls as a gap. Host refusal never switches modes.";
|
|
871
873
|
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.";
|
|
872
874
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
873
875
|
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
@@ -922,6 +924,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
922
924
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
923
925
|
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
924
926
|
[CEAL_GATEWAY_STARTING_FAILURE_CODE]: guidance("The Gateway is still starting; the refresh was not attempted and the refresh token was not consumed. Retry the same refresh attempt after the Gateway is serving.", "retry", 503, true),
|
|
927
|
+
// The serving gate answers before execution while the Gateway is stopping, so retrying the same request is safe.
|
|
928
|
+
[CEAL_GATEWAY_RESTARTING_FAILURE_CODE]: guidance("The Gateway is restarting; the request was not attempted. Retry the same request after the Gateway is serving.", "retry", 503, true),
|
|
925
929
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
926
930
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
927
931
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
@@ -1029,6 +1033,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1029
1033
|
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),
|
|
1030
1034
|
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),
|
|
1031
1035
|
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),
|
|
1036
|
+
host_transcript_unavailable: guidance(HOST_TRANSCRIPT_UNAVAILABLE, "retry", 401, true),
|
|
1032
1037
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
1033
1038
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
1034
1039
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
@@ -1399,6 +1404,10 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
1399
1404
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
1400
1405
|
});
|
|
1401
1406
|
|
|
1407
|
+
// packages/ceal-client-protocol/src/canonical-http-boundary.ts
|
|
1408
|
+
var CEAL_HTTP_CLIENT_EXCHANGE_REF_PATTERN_SOURCE = "^client-exchange:[a-f0-9]{32}$";
|
|
1409
|
+
var CEAL_HTTP_GATEWAY_REQUEST_REF_PATTERN_SOURCE = "^http-request:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
|
1410
|
+
|
|
1402
1411
|
// packages/ceal-client-protocol/src/gateway-installation-activation.ts
|
|
1403
1412
|
var CEAL_GATEWAY_INSTALLATION_ACTIVATION_CODE_DATA_CHARACTERS = 32;
|
|
1404
1413
|
var CEAL_GATEWAY_INSTALLATION_ACTIVATION_CODE_CHECK_CHARACTERS = 8;
|
|
@@ -1421,6 +1430,7 @@ var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUI
|
|
|
1421
1430
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
1422
1431
|
|
|
1423
1432
|
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1433
|
+
var CEAL_RESOURCE_GET_CHILD_REF_KINDS = Object.freeze(["section", "slide", "question"]);
|
|
1424
1434
|
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
1425
1435
|
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
1426
1436
|
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
@@ -1624,6 +1634,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1624
1634
|
"github.review.submitted",
|
|
1625
1635
|
"github.issue_comment.created",
|
|
1626
1636
|
"github.review_comment.created",
|
|
1637
|
+
"github.issue_comment.edited",
|
|
1638
|
+
"github.review_comment.edited",
|
|
1627
1639
|
"github.reaction.created",
|
|
1628
1640
|
"github.reaction.deleted",
|
|
1629
1641
|
"github.pull_request.review_requested",
|
|
@@ -1652,6 +1664,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1652
1664
|
"github.release.published": "release_published",
|
|
1653
1665
|
"github.issue.edited": "resource_modified",
|
|
1654
1666
|
"github.pull_request.edited": "resource_modified",
|
|
1667
|
+
"github.issue_comment.edited": "resource_modified",
|
|
1668
|
+
"github.review_comment.edited": "resource_modified",
|
|
1655
1669
|
"github.reaction.created": "reaction_created",
|
|
1656
1670
|
"github.reaction.deleted": "ceal_write_completed",
|
|
1657
1671
|
"github.pull_request.review_requested": "ceal_write_completed",
|
|
@@ -2310,6 +2324,8 @@ var CEAL_HOST_INVOCATION_CONTEXT_REQUEST_MAX_BYTES = 16 * 1024;
|
|
|
2310
2324
|
var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_BYTES = 2 * 1024;
|
|
2311
2325
|
var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_MESSAGES = 32;
|
|
2312
2326
|
var CEAL_HOST_CONTEXT_TOKEN_PREFIX = "ceal_context_";
|
|
2327
|
+
var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_ENTRY_KEYS = vocabulary(["host_turn_ref", "host_input_ref", "text", "text_truncated"]);
|
|
2328
|
+
var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_REQUIRED_KEYS = vocabulary(["host_turn_ref", "host_input_ref", "text"]);
|
|
2313
2329
|
function boundCealHostInvocationHumanMessageWindow(newestFirst, sourceTruncated = false) {
|
|
2314
2330
|
const messages = [];
|
|
2315
2331
|
let truncated = sourceTruncated || newestFirst.length > CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_MESSAGES;
|
|
@@ -2393,6 +2409,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
2393
2409
|
"context_replaced",
|
|
2394
2410
|
"no_binding",
|
|
2395
2411
|
"context_expired",
|
|
2412
|
+
"transcript_unavailable",
|
|
2396
2413
|
"host_source_refused",
|
|
2397
2414
|
"host_credential_refused",
|
|
2398
2415
|
"gateway_unavailable",
|
|
@@ -2434,6 +2451,11 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2434
2451
|
// useful retry until the consumer is running inside a Host session.
|
|
2435
2452
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2436
2453
|
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
2454
|
+
// The registered transcript is readable but names no human message for
|
|
2455
|
+
// this turn, so a Gateway mint could only be refused. The caller sends a
|
|
2456
|
+
// new message so the turn hook re-registers the transcript, then retries;
|
|
2457
|
+
// a retry with no new turn cannot bind anything new.
|
|
2458
|
+
transcript_unavailable: Object.freeze({ classification: "host_transcript_unavailable", next_action: "retry" }),
|
|
2437
2459
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
2438
2460
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
2439
2461
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
@@ -2538,11 +2560,15 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
2538
2560
|
|
|
2539
2561
|
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
2540
2562
|
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
2541
|
-
var
|
|
2563
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSE_NODES = 8;
|
|
2542
2564
|
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
2543
2565
|
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
2544
2566
|
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
2545
2567
|
var OPERATOR_DIAGNOSTIC_HOME_PATHS = machineHomePathPatterns("gu");
|
|
2568
|
+
var LOCAL_OPERATOR_DIAGNOSTIC_PATHS = /* @__PURE__ */ Symbol.for("ceal.local-operator-diagnostic-paths");
|
|
2569
|
+
var OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_PREFIX = /(?:[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/)/u;
|
|
2570
|
+
var OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_START = new RegExp(`^${OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_PREFIX.source}`, "u");
|
|
2571
|
+
var OPERATOR_DIAGNOSTIC_FREEFORM_PATH_PATTERN = new RegExp(String.raw`(?<![A-Za-z0-9._-]|\[home path redacted\])${OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_PREFIX.source}((?:(?!; stdout=|; stderr=)[^:\r\n"'<>])*?)( exited \d+)?(?=; stdout=|; stderr=|:\d+(?::\d+)?(?:[:\s]|$)|[\r\n]|["'])`, "gu");
|
|
2546
2572
|
function redactOperatorDiagnosticSecrets(value) {
|
|
2547
2573
|
return value.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/giu, "Bearer [redacted]").replace(/(["']?(?:authorization|[A-Za-z0-9_-]*(?:token|secret|credential|password|key))["']?\s*[:=]\s*)(?!(?:"unknown"|'unknown'|unknown\b))(?:"[^"]*"|'[^']*'|[^\s,;}]+)/giu, "$1[redacted]");
|
|
2548
2574
|
}
|
|
@@ -2551,8 +2577,9 @@ function redactOperatorDiagnosticText(value) {
|
|
|
2551
2577
|
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
2552
2578
|
}
|
|
2553
2579
|
function renderOperatorDiagnostic(value) {
|
|
2554
|
-
const state = collectDiagnosticState(value);
|
|
2580
|
+
const state = collectDiagnosticState(value, read(value, LOCAL_OPERATOR_DIAGNOSTIC_PATHS) === true);
|
|
2555
2581
|
const fields = [
|
|
2582
|
+
state.truncated ? "causes_truncated=true" : void 0,
|
|
2556
2583
|
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
2557
2584
|
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
2558
2585
|
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
@@ -2562,23 +2589,27 @@ function renderOperatorDiagnostic(value) {
|
|
|
2562
2589
|
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
2563
2590
|
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
2564
2591
|
}
|
|
2565
|
-
function collectDiagnosticState(value) {
|
|
2566
|
-
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0 };
|
|
2592
|
+
function collectDiagnosticState(value, preserveLocalAbsolutePaths) {
|
|
2593
|
+
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0, truncated: false };
|
|
2567
2594
|
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
2568
|
-
|
|
2595
|
+
let inspected = 0;
|
|
2596
|
+
while (pending.length > 0 && inspected < OPERATOR_DIAGNOSTIC_MAX_CAUSE_NODES) {
|
|
2569
2597
|
const current = pending.shift();
|
|
2570
|
-
if (current
|
|
2598
|
+
if (current === void 0 || isObject(current) && visited.has(current)) continue;
|
|
2599
|
+
inspected += 1;
|
|
2600
|
+
visitDiagnosticNode(current, state, pending, visited, preserveLocalAbsolutePaths);
|
|
2571
2601
|
}
|
|
2602
|
+
state.truncated ||= pending.length > 0;
|
|
2572
2603
|
return state;
|
|
2573
2604
|
}
|
|
2574
|
-
function visitDiagnosticNode(current, state, pending, visited) {
|
|
2605
|
+
function visitDiagnosticNode(current, state, pending, visited, preserveLocalAbsolutePaths) {
|
|
2575
2606
|
if (isObject(current)) {
|
|
2576
2607
|
if (visited.has(current)) return;
|
|
2577
2608
|
visited.add(current);
|
|
2578
2609
|
}
|
|
2579
2610
|
captureProcessEvidence(current, state);
|
|
2580
|
-
appendCause(current, state.causes);
|
|
2581
|
-
enqueueCauseChildren(current, state
|
|
2611
|
+
appendCause(current, state.causes, preserveLocalAbsolutePaths);
|
|
2612
|
+
enqueueCauseChildren(current, state, pending);
|
|
2582
2613
|
}
|
|
2583
2614
|
function captureProcessEvidence(current, state) {
|
|
2584
2615
|
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
@@ -2586,10 +2617,9 @@ function captureProcessEvidence(current, state) {
|
|
|
2586
2617
|
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
2587
2618
|
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
2588
2619
|
}
|
|
2589
|
-
function appendCause(current, causes) {
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
causes.push(errorCause(current));
|
|
2620
|
+
function appendCause(current, causes, preserveLocalAbsolutePaths) {
|
|
2621
|
+
if (current instanceof Error) {
|
|
2622
|
+
causes.push(errorCause(current, preserveLocalAbsolutePaths));
|
|
2593
2623
|
return;
|
|
2594
2624
|
}
|
|
2595
2625
|
if (!isObject(current)) {
|
|
@@ -2597,7 +2627,7 @@ function appendCause(current, causes) {
|
|
|
2597
2627
|
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
2598
2628
|
}
|
|
2599
2629
|
}
|
|
2600
|
-
function errorCause(error) {
|
|
2630
|
+
function errorCause(error, preserveLocalAbsolutePaths) {
|
|
2601
2631
|
const name = safeText(read(error, "name")) ?? "Error";
|
|
2602
2632
|
const message = safeText(read(error, "message"));
|
|
2603
2633
|
const codeValue = read(error, "code");
|
|
@@ -2605,14 +2635,29 @@ function errorCause(error) {
|
|
|
2605
2635
|
const errnoValue = read(error, "errno");
|
|
2606
2636
|
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
2607
2637
|
const syscall = safeText(read(error, "syscall"));
|
|
2608
|
-
const path = safePath(read(error, "path"));
|
|
2638
|
+
const path = safePath(read(error, "path"), preserveLocalAbsolutePaths);
|
|
2609
2639
|
return Object.freeze({ error_class: name, ...message === void 0 ? {} : { message }, ...code2 === void 0 ? {} : { code: code2 }, ...errno === void 0 ? {} : { errno }, ...syscall === void 0 ? {} : { syscall }, ...path === void 0 ? {} : { path } });
|
|
2610
2640
|
}
|
|
2611
|
-
function enqueueCauseChildren(current,
|
|
2641
|
+
function enqueueCauseChildren(current, state, pending) {
|
|
2612
2642
|
const cause = read(current, "cause");
|
|
2613
2643
|
if (cause !== void 0) pending.push(cause);
|
|
2614
2644
|
const errors = read(current, "errors");
|
|
2615
|
-
if (Array.isArray(errors))
|
|
2645
|
+
if (Array.isArray(errors)) {
|
|
2646
|
+
const remaining = OPERATOR_DIAGNOSTIC_MAX_CAUSE_NODES - state.causes.length;
|
|
2647
|
+
const length = read(errors, "length");
|
|
2648
|
+
if (typeof length !== "number") {
|
|
2649
|
+
state.truncated = true;
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
state.truncated ||= length > remaining;
|
|
2653
|
+
for (let index = 0; index < Math.min(length, remaining); index += 1) {
|
|
2654
|
+
try {
|
|
2655
|
+
pending.push(errors[index]);
|
|
2656
|
+
} catch {
|
|
2657
|
+
state.truncated = true;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2616
2661
|
}
|
|
2617
2662
|
function isObject(value) {
|
|
2618
2663
|
return typeof value === "object" && value !== null;
|
|
@@ -2641,10 +2686,11 @@ function safeText(value) {
|
|
|
2641
2686
|
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
2642
2687
|
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2643
2688
|
}
|
|
2644
|
-
function safePath(value) {
|
|
2689
|
+
function safePath(value, preserveLocalAbsolutePaths) {
|
|
2645
2690
|
if (typeof value !== "string") return void 0;
|
|
2646
2691
|
const safe = safeDiagnosticText(value);
|
|
2647
2692
|
if (safe.length === 0) return void 0;
|
|
2693
|
+
if (!preserveLocalAbsolutePaths && hasAbsolutePathPrefix(value) && !safe.startsWith("[home path redacted]")) return "[path redacted]";
|
|
2648
2694
|
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
2649
2695
|
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
2650
2696
|
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
@@ -2716,7 +2762,10 @@ function redactUrls(value) {
|
|
|
2716
2762
|
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
2717
2763
|
}
|
|
2718
2764
|
function redactFilePaths(value) {
|
|
2719
|
-
return value.replaceAll(
|
|
2765
|
+
return value.replaceAll(OPERATOR_DIAGNOSTIC_FREEFORM_PATH_PATTERN, "[path redacted]$2");
|
|
2766
|
+
}
|
|
2767
|
+
function hasAbsolutePathPrefix(value) {
|
|
2768
|
+
return OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_START.test(value);
|
|
2720
2769
|
}
|
|
2721
2770
|
function homePathRange(value, match, prefixLength) {
|
|
2722
2771
|
const index = match.index;
|
|
@@ -2943,8 +2992,8 @@ function invalid2(message) {
|
|
|
2943
2992
|
}
|
|
2944
2993
|
|
|
2945
2994
|
// host/claude/src/claude-outbox.ts
|
|
2946
|
-
import { mkdir as mkdir4, readFile, unlink as unlink3 } from "node:fs/promises";
|
|
2947
|
-
import { isAbsolute as
|
|
2995
|
+
import { mkdir as mkdir4, readFile, stat as stat3, unlink as unlink3 } from "node:fs/promises";
|
|
2996
|
+
import { isAbsolute as isAbsolute4, join as join4 } from "node:path";
|
|
2948
2997
|
|
|
2949
2998
|
// host/invocation-context.ts
|
|
2950
2999
|
var HOST_INVOCATION_TURN_SELECTION_SCHEMA = "ceal.host_invocation_turn_selection.v1";
|
|
@@ -3001,98 +3050,18 @@ function safeRef(value) {
|
|
|
3001
3050
|
var HOST_PRODUCER_FRAME_LENGTH_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
3002
3051
|
var HOST_PRODUCER_FRAME_KINDS = ["session_started", "turn_started", "turn_terminal", "producer_status"];
|
|
3003
3052
|
var FRAME_KINDS = new Set(HOST_PRODUCER_FRAME_KINDS);
|
|
3004
|
-
var HOST_PRODUCER_FRAME_ERROR_CODES = [
|
|
3005
|
-
"invalid_frame_encoding",
|
|
3006
|
-
"invalid_frame_length",
|
|
3007
|
-
"frame_truncated",
|
|
3008
|
-
"unsupported_frame_schema",
|
|
3009
|
-
"invalid_frame_shape",
|
|
3010
|
-
"invalid_producer_identity",
|
|
3011
|
-
"frame_too_large"
|
|
3012
|
-
];
|
|
3013
3053
|
|
|
3014
3054
|
// host/relay/src/host-producer-core.ts
|
|
3015
3055
|
import { createHash as createHash5 } from "node:crypto";
|
|
3016
|
-
import {
|
|
3056
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3057
|
+
import { lstat as lstat2, readdir, stat as stat2 } from "node:fs/promises";
|
|
3017
3058
|
|
|
3018
3059
|
// host/secure-file.ts
|
|
3019
3060
|
import { execFile } from "node:child_process";
|
|
3020
3061
|
import { constants } from "node:fs";
|
|
3021
3062
|
import { lstat, open } from "node:fs/promises";
|
|
3022
|
-
import { dirname, join as
|
|
3063
|
+
import { dirname, join as join2, parse, win32 } from "node:path";
|
|
3023
3064
|
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
|
|
3096
3065
|
var SecureFileCustodyError = class extends Error {
|
|
3097
3066
|
name = "SecureFileCustodyError";
|
|
3098
3067
|
reason;
|
|
@@ -3191,7 +3160,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
3191
3160
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
3192
3161
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
3193
3162
|
return await new Promise((resolve2, reject) => {
|
|
3194
|
-
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES, cwd:
|
|
3163
|
+
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES, cwd: parse(executable).root }, (error, stdout, stderr) => {
|
|
3195
3164
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
3196
3165
|
if (exitCode === null) {
|
|
3197
3166
|
reject(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -3220,7 +3189,7 @@ function securefsRefusal(stderr) {
|
|
|
3220
3189
|
}
|
|
3221
3190
|
function resolveInstalledHostExecutable(platform) {
|
|
3222
3191
|
const privateRuntimeRoot = dirname(fileURLToPath(import.meta.url));
|
|
3223
|
-
return platform === "win32" ? win32.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") :
|
|
3192
|
+
return platform === "win32" ? win32.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") : join2(privateRuntimeRoot, "..", "..", "bin", "ceal-host");
|
|
3224
3193
|
}
|
|
3225
3194
|
function isRecord2(value) {
|
|
3226
3195
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -3244,7 +3213,7 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
3244
3213
|
|
|
3245
3214
|
// host/service-log.ts
|
|
3246
3215
|
import { copyFile, mkdir, stat, truncate, appendFile } from "node:fs/promises";
|
|
3247
|
-
import { dirname as dirname2, isAbsolute as
|
|
3216
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, posix, win32 as win322 } from "node:path";
|
|
3248
3217
|
|
|
3249
3218
|
// host/service-log-delivery.ts
|
|
3250
3219
|
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
@@ -3410,7 +3379,7 @@ async function persistHostServiceLogLine(line, environment = process.env) {
|
|
|
3410
3379
|
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
3411
3380
|
}
|
|
3412
3381
|
async function appendHostServiceLogLine(path, line) {
|
|
3413
|
-
if (!
|
|
3382
|
+
if (!isAbsolute2(path)) return;
|
|
3414
3383
|
await ensureHostServiceLogDirectory(path);
|
|
3415
3384
|
await appendFile(path, line);
|
|
3416
3385
|
}
|
|
@@ -3449,7 +3418,9 @@ function mergeHostInvocationHumanMessageWindow(existing, chronological) {
|
|
|
3449
3418
|
seen.add(message.host_input_ref);
|
|
3450
3419
|
newestFirst.push(message);
|
|
3451
3420
|
}
|
|
3452
|
-
|
|
3421
|
+
const currentTurn = newestFirst[0]?.host_turn_ref;
|
|
3422
|
+
const currentTurnFirst = currentTurn === void 0 ? newestFirst : newestFirst.filter((message) => message.host_turn_ref === currentTurn);
|
|
3423
|
+
return boundCealHostInvocationHumanMessageWindow(currentTurnFirst, existing?.truncated ?? false);
|
|
3453
3424
|
}
|
|
3454
3425
|
function transcriptScanFailureKind(error, adapterFailureKind) {
|
|
3455
3426
|
if (transcriptErrorCode(error) === "ELOOP") return "symlink";
|
|
@@ -3506,6 +3477,15 @@ async function transcriptCursorBoundsReason(handle, cursor, size) {
|
|
|
3506
3477
|
if (cursor.offset > 0 && !await transcriptAnchorMatches(handle, cursor)) return "transcript_rewritten";
|
|
3507
3478
|
return null;
|
|
3508
3479
|
}
|
|
3480
|
+
async function statObservedPathSignature(path) {
|
|
3481
|
+
try {
|
|
3482
|
+
const info = await lstat2(path, { bigint: true });
|
|
3483
|
+
if (info.isSymbolicLink() || !info.isFile() && !info.isDirectory()) return null;
|
|
3484
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
3485
|
+
} catch {
|
|
3486
|
+
return null;
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3509
3489
|
function transcriptSha256(value) {
|
|
3510
3490
|
return createHash5("sha256").update(value).digest("hex");
|
|
3511
3491
|
}
|
|
@@ -3538,27 +3518,71 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
3538
3518
|
producerInstallationRef: options.producer_installation_ref
|
|
3539
3519
|
};
|
|
3540
3520
|
}
|
|
3541
|
-
async function scanTranscriptRegistrations(registrations, scanOne) {
|
|
3521
|
+
async function scanTranscriptRegistrations(registrations, scanOne, totalRegistrations, signal) {
|
|
3542
3522
|
let records = 0;
|
|
3543
3523
|
let enqueued = 0;
|
|
3544
3524
|
let quarantined = 0;
|
|
3525
|
+
let scanned = 0;
|
|
3545
3526
|
for (const registration of registrations) {
|
|
3527
|
+
if (signal?.aborted) break;
|
|
3528
|
+
scanned += 1;
|
|
3546
3529
|
const result = await scanOne(registration);
|
|
3547
3530
|
records += result.records;
|
|
3548
3531
|
enqueued += result.enqueued;
|
|
3549
3532
|
if (result.quarantined) quarantined += 1;
|
|
3550
3533
|
}
|
|
3551
|
-
return { registrations:
|
|
3534
|
+
return { registrations: totalRegistrations ?? scanned, records, enqueued, quarantined };
|
|
3535
|
+
}
|
|
3536
|
+
var HOST_REGISTRATION_DIRECTORY_RACY_WINDOW_NS = 1000000000n;
|
|
3537
|
+
var HostRegistrationInventory = class {
|
|
3538
|
+
signature;
|
|
3539
|
+
registrations;
|
|
3540
|
+
nowNs;
|
|
3541
|
+
observeDirectory;
|
|
3542
|
+
constructor(options = {}) {
|
|
3543
|
+
this.nowNs = options.nowNs ?? (() => BigInt(Date.now()) * 1000000n);
|
|
3544
|
+
this.observeDirectory = options.observeDirectory ?? hostRegistrationDirectorySignature;
|
|
3545
|
+
}
|
|
3546
|
+
async read(directory, load) {
|
|
3547
|
+
const observation = await this.observeDirectory(directory);
|
|
3548
|
+
const nowNs = this.nowNs();
|
|
3549
|
+
const racy = nowNs - observation.mtimeNs <= HOST_REGISTRATION_DIRECTORY_RACY_WINDOW_NS || nowNs - observation.ctimeNs <= HOST_REGISTRATION_DIRECTORY_RACY_WINDOW_NS;
|
|
3550
|
+
if (this.registrations !== void 0 && this.signature === observation.signature && !racy) return this.registrations;
|
|
3551
|
+
const registrations = await load();
|
|
3552
|
+
this.signature = observation.signature;
|
|
3553
|
+
this.registrations = registrations;
|
|
3554
|
+
return registrations;
|
|
3555
|
+
}
|
|
3556
|
+
};
|
|
3557
|
+
async function hostRegistrationDirectorySignature(directory) {
|
|
3558
|
+
try {
|
|
3559
|
+
const info = await stat2(directory, { bigint: true });
|
|
3560
|
+
return {
|
|
3561
|
+
signature: `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`,
|
|
3562
|
+
mtimeNs: info.mtimeNs,
|
|
3563
|
+
ctimeNs: info.ctimeNs
|
|
3564
|
+
};
|
|
3565
|
+
} catch (error) {
|
|
3566
|
+
if (isMissingTranscriptError(error)) return { signature: "missing", mtimeNs: 0n, ctimeNs: 0n };
|
|
3567
|
+
throw error;
|
|
3568
|
+
}
|
|
3552
3569
|
}
|
|
3553
3570
|
function formatRetiredTranscriptLog(producerLabel, transcriptPath) {
|
|
3554
3571
|
return `${producerLabel} retired a transcript registration: transcript_path=${JSON.stringify(transcriptPath)}, reason=${TRANSCRIPT_MISSING_REASON}.`;
|
|
3555
3572
|
}
|
|
3573
|
+
var HOST_TRANSCRIPT_RECONCILIATION_BATCH = 100;
|
|
3556
3574
|
var HostTranscriptWatcher = class {
|
|
3557
3575
|
outboxRetentionMs;
|
|
3558
3576
|
now;
|
|
3559
3577
|
log;
|
|
3560
3578
|
producerInstallationRef;
|
|
3561
3579
|
clockFailure;
|
|
3580
|
+
transcriptObservations = /* @__PURE__ */ new Map();
|
|
3581
|
+
registrationSnapshot;
|
|
3582
|
+
// Advisory scheduling only: listRegistrations remains the registration authority.
|
|
3583
|
+
hotRegistrations = /* @__PURE__ */ new Set();
|
|
3584
|
+
reconciliation;
|
|
3585
|
+
reconciliationRemaining = 0;
|
|
3562
3586
|
constructor(options, owner) {
|
|
3563
3587
|
const base = createTranscriptWatcherBase(options, owner);
|
|
3564
3588
|
this.outboxRetentionMs = base.outboxRetentionMs;
|
|
@@ -3567,8 +3591,97 @@ var HostTranscriptWatcher = class {
|
|
|
3567
3591
|
this.producerInstallationRef = base.producerInstallationRef;
|
|
3568
3592
|
this.clockFailure = owner.clock_failure;
|
|
3569
3593
|
}
|
|
3570
|
-
async scanOnce() {
|
|
3571
|
-
|
|
3594
|
+
async scanOnce(signal) {
|
|
3595
|
+
if (signal?.aborted) return { registrations: this.registrationSnapshot?.length ?? 0, records: 0, enqueued: 0, quarantined: 0 };
|
|
3596
|
+
const registrations = await this.listRegistrations();
|
|
3597
|
+
this.reconcileSnapshot(registrations);
|
|
3598
|
+
return scanTranscriptRegistrations(this.scanCandidates(), (observation) => this.observeRegistration(observation, signal), registrations.length, signal);
|
|
3599
|
+
}
|
|
3600
|
+
async observeRegistration(observation, signal) {
|
|
3601
|
+
const registration = observation.registration;
|
|
3602
|
+
const signature = await this.scanFingerprint(registration);
|
|
3603
|
+
if (signal?.aborted) return { records: 0, enqueued: 0, quarantined: false };
|
|
3604
|
+
this.hotRegistrations.delete(observation);
|
|
3605
|
+
if (signature !== null && observation.signature === signature) return { records: 0, enqueued: 0, quarantined: false };
|
|
3606
|
+
this.hotRegistrations.add(observation);
|
|
3607
|
+
const result = await this.scanRegistration(registration);
|
|
3608
|
+
if (result.quarantined || result.retry === true) observation.signature = void 0;
|
|
3609
|
+
else {
|
|
3610
|
+
observation.signature = signature ?? void 0;
|
|
3611
|
+
if (result.records === 0) this.hotRegistrations.delete(observation);
|
|
3612
|
+
}
|
|
3613
|
+
return result;
|
|
3614
|
+
}
|
|
3615
|
+
*scanCandidates() {
|
|
3616
|
+
const hotSlice = [];
|
|
3617
|
+
for (const observation of this.hotRegistrations) {
|
|
3618
|
+
hotSlice.push(observation);
|
|
3619
|
+
if (hotSlice.length === HOST_TRANSCRIPT_RECONCILIATION_BATCH) break;
|
|
3620
|
+
}
|
|
3621
|
+
const observed = /* @__PURE__ */ new Set();
|
|
3622
|
+
for (let count = 0; count < Math.min(this.transcriptObservations.size, HOST_TRANSCRIPT_RECONCILIATION_BATCH); count += 1) {
|
|
3623
|
+
const observation = this.nextReconciliation();
|
|
3624
|
+
if (observation === void 0) break;
|
|
3625
|
+
observed.add(observation);
|
|
3626
|
+
yield observation;
|
|
3627
|
+
}
|
|
3628
|
+
for (const observation of hotSlice) if (!observed.has(observation)) yield observation;
|
|
3629
|
+
}
|
|
3630
|
+
nextReconciliation() {
|
|
3631
|
+
if (this.reconciliationRemaining === 0 || this.reconciliation === void 0) {
|
|
3632
|
+
this.reconciliation = this.transcriptObservations.values();
|
|
3633
|
+
this.reconciliationRemaining = this.transcriptObservations.size;
|
|
3634
|
+
}
|
|
3635
|
+
let next = this.reconciliation.next();
|
|
3636
|
+
if (next.done) {
|
|
3637
|
+
this.reconciliation = this.transcriptObservations.values();
|
|
3638
|
+
this.reconciliationRemaining = this.transcriptObservations.size;
|
|
3639
|
+
next = this.reconciliation.next();
|
|
3640
|
+
}
|
|
3641
|
+
this.reconciliationRemaining -= 1;
|
|
3642
|
+
return next.value;
|
|
3643
|
+
}
|
|
3644
|
+
reconcileSnapshot(registrations) {
|
|
3645
|
+
if (this.registrationSnapshot === registrations) return;
|
|
3646
|
+
const retained = /* @__PURE__ */ new Set();
|
|
3647
|
+
const hot = /* @__PURE__ */ new Set();
|
|
3648
|
+
for (const registration of registrations) {
|
|
3649
|
+
const key = this.registrationKey(registration);
|
|
3650
|
+
retained.add(key);
|
|
3651
|
+
let observation = this.transcriptObservations.get(key);
|
|
3652
|
+
if (observation === void 0) {
|
|
3653
|
+
observation = { registration, signature: void 0 };
|
|
3654
|
+
this.transcriptObservations.set(key, observation);
|
|
3655
|
+
hot.add(observation);
|
|
3656
|
+
} else {
|
|
3657
|
+
if (!isDeepStrictEqual(observation.registration, registration)) {
|
|
3658
|
+
observation.signature = void 0;
|
|
3659
|
+
hot.add(observation);
|
|
3660
|
+
}
|
|
3661
|
+
observation.registration = registration;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
for (const [key, observation] of this.transcriptObservations) {
|
|
3665
|
+
if (!retained.has(key)) {
|
|
3666
|
+
this.transcriptObservations.delete(key);
|
|
3667
|
+
this.hotRegistrations.delete(observation);
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
for (const observation of this.hotRegistrations) hot.add(observation);
|
|
3671
|
+
this.hotRegistrations = hot;
|
|
3672
|
+
this.registrationSnapshot = registrations;
|
|
3673
|
+
}
|
|
3674
|
+
async scanFingerprint(registration) {
|
|
3675
|
+
return this.transcriptSignature(registration);
|
|
3676
|
+
}
|
|
3677
|
+
async transcriptSignature(registration) {
|
|
3678
|
+
try {
|
|
3679
|
+
const info = await lstat2(this.transcriptPathOf(registration), { bigint: true });
|
|
3680
|
+
if (!info.isFile() || info.isSymbolicLink()) return null;
|
|
3681
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}:${info.mode}:${info.uid}`;
|
|
3682
|
+
} catch {
|
|
3683
|
+
return null;
|
|
3684
|
+
}
|
|
3572
3685
|
}
|
|
3573
3686
|
async scanRegistration(registration) {
|
|
3574
3687
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
@@ -3669,7 +3782,7 @@ var HostProducerDrainCore = class {
|
|
|
3669
3782
|
};
|
|
3670
3783
|
|
|
3671
3784
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3672
|
-
import { lstat as
|
|
3785
|
+
import { lstat as lstat3, mkdir as mkdir2, open as open2, rename, unlink } from "node:fs/promises";
|
|
3673
3786
|
import { dirname as dirname3 } from "node:path";
|
|
3674
3787
|
|
|
3675
3788
|
// host/windows-rename-retry.ts
|
|
@@ -3691,7 +3804,7 @@ function resolveRetrySchedule(tuning) {
|
|
|
3691
3804
|
startDelayMs: tuning.startDelayMs ?? RETRY_START_DELAY_MS,
|
|
3692
3805
|
maxDelayMs: tuning.maxDelayMs ?? RETRY_MAX_DELAY_MS,
|
|
3693
3806
|
sleep: tuning.sleep ?? ((ms) => setTimeout2(ms)),
|
|
3694
|
-
now: tuning.now ?? (() =>
|
|
3807
|
+
now: tuning.now ?? (() => performance.now())
|
|
3695
3808
|
};
|
|
3696
3809
|
}
|
|
3697
3810
|
async function renameWithWindowsRetry(operation, tuning) {
|
|
@@ -3724,7 +3837,7 @@ function isRetryableRenameError(error) {
|
|
|
3724
3837
|
var DEFAULT_PORT = {
|
|
3725
3838
|
platform: process.platform,
|
|
3726
3839
|
mkdir: (path, options) => mkdir2(path, options),
|
|
3727
|
-
lstat: (path) =>
|
|
3840
|
+
lstat: (path) => lstat3(path),
|
|
3728
3841
|
open_file: (path) => open2(path, "wx", 384),
|
|
3729
3842
|
rename,
|
|
3730
3843
|
unlink,
|
|
@@ -3803,7 +3916,7 @@ function errorCode(error) {
|
|
|
3803
3916
|
import { createHash as createHash6 } from "node:crypto";
|
|
3804
3917
|
import { constants as constants2 } from "node:fs";
|
|
3805
3918
|
import { mkdir as mkdir3, open as open3, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
3806
|
-
import { dirname as dirname4, join as
|
|
3919
|
+
import { dirname as dirname4, join as join3 } from "node:path";
|
|
3807
3920
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
3808
3921
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
3809
3922
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -3822,10 +3935,12 @@ var HostUsageFactsStore = class {
|
|
|
3822
3935
|
afterPendingWrite;
|
|
3823
3936
|
afterBatchPublish;
|
|
3824
3937
|
sessionDirectoryCursor;
|
|
3938
|
+
uploadScanSignature;
|
|
3939
|
+
uploadScanEmpty = false;
|
|
3825
3940
|
constructor(options) {
|
|
3826
|
-
this.root =
|
|
3827
|
-
this.sessions =
|
|
3828
|
-
this.batches =
|
|
3941
|
+
this.root = join3(options.outbox_dir, "usage-facts");
|
|
3942
|
+
this.sessions = join3(this.root, "sessions");
|
|
3943
|
+
this.batches = join3(this.root, "batches");
|
|
3829
3944
|
this.platform = options.platform ?? process.platform;
|
|
3830
3945
|
this.custody = options.secure_file_custody ?? {};
|
|
3831
3946
|
this.afterPendingWrite = options.afterPendingWrite;
|
|
@@ -3841,6 +3956,10 @@ var HostUsageFactsStore = class {
|
|
|
3841
3956
|
this.sessionDirectoryCursor = void 0;
|
|
3842
3957
|
await cursor?.close();
|
|
3843
3958
|
}
|
|
3959
|
+
/** The durable path behind one session's usage state, so idle fast paths can poll it without reading it. */
|
|
3960
|
+
statePath(producer, hostSourceRef, hostSessionRef) {
|
|
3961
|
+
return this.sessionPath(producer, hostSourceRef, hostSessionRef);
|
|
3962
|
+
}
|
|
3844
3963
|
async readState(producer, hostSourceRef, hostSessionRef) {
|
|
3845
3964
|
const path = this.sessionPath(producer, hostSourceRef, hostSessionRef);
|
|
3846
3965
|
const value = await readOptionalJson(path, HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
@@ -3916,7 +4035,7 @@ var HostUsageFactsStore = class {
|
|
|
3916
4035
|
if (entry === null) break;
|
|
3917
4036
|
inspected += 1;
|
|
3918
4037
|
if (!isOrphanBatchEntry(entry, expected)) continue;
|
|
3919
|
-
await unlink2(
|
|
4038
|
+
await unlink2(join3(directoryPath, entry.name));
|
|
3920
4039
|
deleted += 1;
|
|
3921
4040
|
}
|
|
3922
4041
|
} finally {
|
|
@@ -3944,9 +4063,17 @@ var HostUsageFactsStore = class {
|
|
|
3944
4063
|
});
|
|
3945
4064
|
}
|
|
3946
4065
|
async nextUploadCandidate(producer, hostSourceRef) {
|
|
4066
|
+
const signature = await statObservedPathSignature(this.sessions);
|
|
4067
|
+
if (signature !== null && signature === this.uploadScanSignature && this.uploadScanEmpty) return null;
|
|
4068
|
+
const candidate = await this.scanUploadCandidates(producer, hostSourceRef);
|
|
4069
|
+
this.uploadScanSignature = signature ?? void 0;
|
|
4070
|
+
this.uploadScanEmpty = candidate === null;
|
|
4071
|
+
return candidate;
|
|
4072
|
+
}
|
|
4073
|
+
async scanUploadCandidates(producer, hostSourceRef) {
|
|
3947
4074
|
const names = await this.readNextSessionNames();
|
|
3948
4075
|
for (const name of names) {
|
|
3949
|
-
const state = await readOptionalJson(
|
|
4076
|
+
const state = await readOptionalJson(join3(this.sessions, name), HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
3950
4077
|
if (state === null) continue;
|
|
3951
4078
|
validateStateOwner(state, producer, hostSourceRef);
|
|
3952
4079
|
let validated = state;
|
|
@@ -4134,14 +4261,14 @@ var HostUsageFactsStore = class {
|
|
|
4134
4261
|
}
|
|
4135
4262
|
}
|
|
4136
4263
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
4137
|
-
return
|
|
4264
|
+
return join3(this.sessions, `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`);
|
|
4138
4265
|
}
|
|
4139
4266
|
batchSessionDirectory(producer, hostSourceRef, hostSessionRef) {
|
|
4140
4267
|
const sessionName = `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`;
|
|
4141
|
-
return
|
|
4268
|
+
return join3(this.batches, sessionName.slice(0, -5));
|
|
4142
4269
|
}
|
|
4143
4270
|
batchPath(state, batchRef) {
|
|
4144
|
-
return
|
|
4271
|
+
return join3(this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref), batchFileName(batchRef));
|
|
4145
4272
|
}
|
|
4146
4273
|
};
|
|
4147
4274
|
function serializeBatch(batch) {
|
|
@@ -4382,6 +4509,8 @@ function sha2562(value) {
|
|
|
4382
4509
|
|
|
4383
4510
|
// host/relay/src/host-usage-facts-capture.ts
|
|
4384
4511
|
import { constants as constants3 } from "node:fs";
|
|
4512
|
+
import { lstat as lstat4 } from "node:fs/promises";
|
|
4513
|
+
import { dirname as dirname5 } from "node:path";
|
|
4385
4514
|
var HOST_USAGE_FACTS_SCAN_MAX_BYTES = 1024 * 1024;
|
|
4386
4515
|
var HOST_USAGE_FACTS_SCAN_MAX_ROWS = 256;
|
|
4387
4516
|
var HOST_USAGE_FACTS_SOURCE_ROW_MAX_BYTES = 64 * 1024;
|
|
@@ -4431,6 +4560,55 @@ var HostUsageRegistrationCapture = class {
|
|
|
4431
4560
|
return captured;
|
|
4432
4561
|
}
|
|
4433
4562
|
};
|
|
4563
|
+
var HostUsageIdleGate = class {
|
|
4564
|
+
seen = /* @__PURE__ */ new Map();
|
|
4565
|
+
statPath;
|
|
4566
|
+
constructor(options = {}) {
|
|
4567
|
+
this.statPath = options.statPath ?? statIdleGatePath;
|
|
4568
|
+
}
|
|
4569
|
+
/**
|
|
4570
|
+
* Check whether the path is unchanged since the last confirmed check, without recording anything.
|
|
4571
|
+
* The caller confirms the returned signature only after the capture for it succeeded without a
|
|
4572
|
+
* source error, so a failed read leaves the source eligible on the next tick while a fully-read,
|
|
4573
|
+
* unchanged source keeps skipping its open plus state-read probe.
|
|
4574
|
+
*/
|
|
4575
|
+
async checkUnchanged(key, path) {
|
|
4576
|
+
const signature = await this.statPath(path);
|
|
4577
|
+
if (signature === null) {
|
|
4578
|
+
this.seen.delete(key);
|
|
4579
|
+
return { unchanged: false, signature };
|
|
4580
|
+
}
|
|
4581
|
+
if (this.seen.get(key) === signature) return { unchanged: true, signature };
|
|
4582
|
+
return { unchanged: false, signature };
|
|
4583
|
+
}
|
|
4584
|
+
/** Remember a signature only after its capture succeeded, so failures stay eligible. */
|
|
4585
|
+
confirmUnchanged(key, signature) {
|
|
4586
|
+
if (signature === null) return;
|
|
4587
|
+
this.seen.set(key, signature);
|
|
4588
|
+
}
|
|
4589
|
+
};
|
|
4590
|
+
async function statIdleGatePath(path) {
|
|
4591
|
+
const direct = await statObservedPathSignature(path);
|
|
4592
|
+
if (direct !== null) return direct;
|
|
4593
|
+
try {
|
|
4594
|
+
await lstat4(path);
|
|
4595
|
+
return null;
|
|
4596
|
+
} catch (error) {
|
|
4597
|
+
const code2 = transcriptErrorCode(error);
|
|
4598
|
+
if (code2 !== "ENOENT" && code2 !== "ENOTDIR") return null;
|
|
4599
|
+
return await missingPathAnchor(path);
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
async function missingPathAnchor(path) {
|
|
4603
|
+
let ancestor = dirname5(path);
|
|
4604
|
+
for (let depth = 0; depth < 4; depth += 1) {
|
|
4605
|
+
if (ancestor === dirname5(ancestor)) return null;
|
|
4606
|
+
const anchor = await statObservedPathSignature(ancestor);
|
|
4607
|
+
if (anchor !== null) return `missing:${anchor}`;
|
|
4608
|
+
ancestor = dirname5(ancestor);
|
|
4609
|
+
}
|
|
4610
|
+
return null;
|
|
4611
|
+
}
|
|
4434
4612
|
async function openHostUsageTranscriptCursor(input) {
|
|
4435
4613
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants3.O_RDONLY));
|
|
4436
4614
|
let source;
|
|
@@ -4501,7 +4679,7 @@ function completeLinePrefix(bytes, baseOffset) {
|
|
|
4501
4679
|
|
|
4502
4680
|
// host/relay/src/host-registration-state.ts
|
|
4503
4681
|
import { constants as constants4 } from "node:fs";
|
|
4504
|
-
import { dirname as
|
|
4682
|
+
import { dirname as dirname6 } from "node:path";
|
|
4505
4683
|
|
|
4506
4684
|
// host/runtime-source-paths.ts
|
|
4507
4685
|
import { createHash as createHash7 } from "node:crypto";
|
|
@@ -4570,7 +4748,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
4570
4748
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
4571
4749
|
let raw;
|
|
4572
4750
|
try {
|
|
4573
|
-
await assertPrivateRegistrationDirectory(
|
|
4751
|
+
await assertPrivateRegistrationDirectory(dirname6(path), platform, custody);
|
|
4574
4752
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
4575
4753
|
} catch (error) {
|
|
4576
4754
|
throw registrationReadError(error);
|
|
@@ -4745,15 +4923,12 @@ async function runHostUsageFactsUploader(options, signal, wait = waitForAbort) {
|
|
|
4745
4923
|
}
|
|
4746
4924
|
}
|
|
4747
4925
|
|
|
4748
|
-
// host/relay/src/relay-quarantine-store.ts
|
|
4749
|
-
var RELAY_QUARANTINE_MAX_BYTES = 16 * 1024 * 1024;
|
|
4750
|
-
var RELAY_QUARANTINE_FRAME_REASONS = ["frame_identity_conflict", "sequence_gap", "gateway_refused"];
|
|
4751
|
-
var RELAY_QUARANTINE_REASONS = [...RELAY_QUARANTINE_FRAME_REASONS, ...HOST_PRODUCER_FRAME_ERROR_CODES];
|
|
4752
|
-
|
|
4753
4926
|
// host/relay/src/relay-admission-store.ts
|
|
4754
|
-
var
|
|
4755
|
-
|
|
4756
|
-
|
|
4927
|
+
var RELAY_ADMISSION_CODES = vocabulary(["admitted", "already_admitted", "producer_epoch_stale", "sequence_gap", "frame_identity_conflict", "producer_queue_full", "relay_queue_full", "producer_already_connected", "invalid_producer_identity"]);
|
|
4928
|
+
|
|
4929
|
+
// host/relay/src/host-relay-config.ts
|
|
4930
|
+
var HOST_RELAY_CONFIG_MIN_BYTES = Buffer.byteLength("{}", "utf8");
|
|
4931
|
+
var HOST_RELAY_INVOCATION_MINT_LOG_LINE = new RegExp(String.raw`^\[host-relay-invocation-mint\] timestamp=(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[.]\d{3}Z) outcome=(completed|failed) stage=(registration|gateway_request|gateway_response) latency_ms=(\d{1,16})(?: gateway_origin_host=([A-Za-z0-9.:[\]-]{1,255}))?(?: client_exchange_ref=(${CEAL_HTTP_CLIENT_EXCHANGE_REF_PATTERN_SOURCE.slice(1, -1)}))?(?: gateway_http_request_ref=(${CEAL_HTTP_GATEWAY_REQUEST_REF_PATTERN_SOURCE.slice(1, -1)}))?(?: reason=([a-z][a-z0-9_]{0,63}))?(?: gateway_status=([1-5][0-9]{2}))?$`, "u");
|
|
4757
4932
|
|
|
4758
4933
|
// host/relay/src/relay-pipe-handshake.ts
|
|
4759
4934
|
var RELAY_PIPE_FRAME_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
@@ -4762,7 +4937,7 @@ var RELAY_PIPE_FRAME_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
|
4762
4937
|
var HOST_RELAY_IPC_LENGTH_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
4763
4938
|
|
|
4764
4939
|
// host/claude/src/claude-invocation-context.ts
|
|
4765
|
-
import { isAbsolute as
|
|
4940
|
+
import { isAbsolute as isAbsolute3 } from "node:path";
|
|
4766
4941
|
function claudeInvocationContextFromTurn(identity, promptRef, expiresAt, workingDirectory, turnGenerationRef) {
|
|
4767
4942
|
return invocationContextFromTurn(identity, promptRef, expiresAt, { schema_version: CLAUDE_INVOCATION_CONTEXT_SCHEMA_VERSION, validate: validateClaudeHostInvocationContext, working_directory: workingDirectory, turn_generation_ref: turnGenerationRef });
|
|
4768
4943
|
}
|
|
@@ -4791,7 +4966,7 @@ function optionalSafeRef(value) {
|
|
|
4791
4966
|
return value === void 0 || safeRef2(value);
|
|
4792
4967
|
}
|
|
4793
4968
|
function optionalDirectory(value) {
|
|
4794
|
-
return value === void 0 || typeof value === "string" &&
|
|
4969
|
+
return value === void 0 || typeof value === "string" && isAbsolute3(value) && !value.includes("\0") && value.length <= 4096;
|
|
4795
4970
|
}
|
|
4796
4971
|
function safeRef2(value) {
|
|
4797
4972
|
return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u.test(value);
|
|
@@ -4815,15 +4990,16 @@ var ClaudeOutboxStore = class {
|
|
|
4815
4990
|
directory;
|
|
4816
4991
|
activeContexts;
|
|
4817
4992
|
turnSelections;
|
|
4993
|
+
registrationInventory = new HostRegistrationInventory();
|
|
4818
4994
|
constructor(directory) {
|
|
4819
|
-
if (!
|
|
4995
|
+
if (!isAbsolute4(directory)) throw new ClaudeHostError("configuration", "Claude outbox directory must be absolute.");
|
|
4820
4996
|
this.directory = directory;
|
|
4821
|
-
this.envelopes =
|
|
4822
|
-
this.sessions =
|
|
4823
|
-
this.registrations =
|
|
4824
|
-
this.cursors =
|
|
4825
|
-
this.activeContexts =
|
|
4826
|
-
this.turnSelections =
|
|
4997
|
+
this.envelopes = join4(directory, "envelopes");
|
|
4998
|
+
this.sessions = join4(directory, "sessions");
|
|
4999
|
+
this.registrations = join4(directory, "transcript-registrations");
|
|
5000
|
+
this.cursors = join4(directory, "transcript-cursors");
|
|
5001
|
+
this.activeContexts = join4(directory, "active-contexts");
|
|
5002
|
+
this.turnSelections = join4(directory, "turn-selections");
|
|
4827
5003
|
}
|
|
4828
5004
|
async prepare() {
|
|
4829
5005
|
for (const path of [this.envelopes, this.sessions, this.registrations, this.cursors, this.activeContexts, this.turnSelections]) {
|
|
@@ -4872,7 +5048,7 @@ var ClaudeOutboxStore = class {
|
|
|
4872
5048
|
for (const name of await listHostOutboxDirectoryNames(this.activeContexts)) {
|
|
4873
5049
|
if (!name.endsWith(".json")) continue;
|
|
4874
5050
|
try {
|
|
4875
|
-
const value = JSON.parse(await readFile(
|
|
5051
|
+
const value = JSON.parse(await readFile(join4(this.activeContexts, name), "utf8"));
|
|
4876
5052
|
validateClaudeHostInvocationContext(value);
|
|
4877
5053
|
if (Date.parse(value.expires_at) > now.getTime()) contexts.push(value);
|
|
4878
5054
|
} catch {
|
|
@@ -4891,7 +5067,7 @@ var ClaudeOutboxStore = class {
|
|
|
4891
5067
|
for (const name of await listHostOutboxDirectoryNames(this.envelopes)) {
|
|
4892
5068
|
if (!name.endsWith(".json")) continue;
|
|
4893
5069
|
try {
|
|
4894
|
-
const value = JSON.parse(await readFile(
|
|
5070
|
+
const value = JSON.parse(await readFile(join4(this.envelopes, name), "utf8"));
|
|
4895
5071
|
validateEnvelope(value);
|
|
4896
5072
|
entries.push(value);
|
|
4897
5073
|
} catch {
|
|
@@ -4912,17 +5088,18 @@ var ClaudeOutboxStore = class {
|
|
|
4912
5088
|
async saveSession(snapshot) {
|
|
4913
5089
|
validateSession(snapshot);
|
|
4914
5090
|
await this.prepare();
|
|
4915
|
-
await durableAtomicReplace(
|
|
5091
|
+
await durableAtomicReplace(join4(this.sessions, `${cealRequestSha256({ source: snapshot.host_source_ref, session: snapshot.host_session_ref })}.json`), JSON.stringify(snapshot));
|
|
4916
5092
|
}
|
|
4917
5093
|
async readSession(sourceRef, sessionRef) {
|
|
4918
5094
|
if (!SAFE_REF2.test(sourceRef) || !SAFE_REF2.test(sessionRef)) throw new ClaudeHostError("invalid_input", "Claude session identity is invalid.");
|
|
4919
5095
|
try {
|
|
4920
|
-
const value = JSON.parse(await readFile(
|
|
5096
|
+
const value = JSON.parse(await readFile(join4(this.sessions, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`), "utf8"));
|
|
4921
5097
|
validateSession(value);
|
|
4922
5098
|
return value;
|
|
4923
5099
|
} catch (error) {
|
|
4924
5100
|
if (code(error) === "ENOENT") return null;
|
|
4925
|
-
|
|
5101
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
5102
|
+
throw new ClaudeHostError("storage", "Claude session snapshot is malformed.");
|
|
4926
5103
|
}
|
|
4927
5104
|
}
|
|
4928
5105
|
async registerTranscript(registration) {
|
|
@@ -4953,17 +5130,19 @@ var ClaudeOutboxStore = class {
|
|
|
4953
5130
|
return registration;
|
|
4954
5131
|
}
|
|
4955
5132
|
async listTranscriptRegistrations() {
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
5133
|
+
return this.registrationInventory.read(this.registrations, async () => {
|
|
5134
|
+
const registrations = [];
|
|
5135
|
+
for (const name of await listHostOutboxDirectoryNames(this.registrations)) {
|
|
5136
|
+
if (!name.endsWith(".json")) continue;
|
|
5137
|
+
try {
|
|
5138
|
+
const value = JSON.parse(await readFile(join4(this.registrations, name), "utf8"));
|
|
5139
|
+
validateRegistration(value);
|
|
5140
|
+
registrations.push(value);
|
|
5141
|
+
} catch {
|
|
5142
|
+
}
|
|
4964
5143
|
}
|
|
4965
|
-
|
|
4966
|
-
|
|
5144
|
+
return registrations.sort((left, right) => left.registered_at.localeCompare(right.registered_at));
|
|
5145
|
+
});
|
|
4967
5146
|
}
|
|
4968
5147
|
async readInvocationTurnSelection(hostSourceRef, hostSessionRef) {
|
|
4969
5148
|
if (!SAFE_REF2.test(hostSourceRef) || !SAFE_REF2.test(hostSessionRef)) throw new ClaudeHostError("invalid_input", "Claude Host turn selection identity is invalid.");
|
|
@@ -4973,7 +5152,8 @@ var ClaudeOutboxStore = class {
|
|
|
4973
5152
|
return value;
|
|
4974
5153
|
} catch (error) {
|
|
4975
5154
|
if (code(error) === "ENOENT") return null;
|
|
4976
|
-
|
|
5155
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
5156
|
+
throw new ClaudeHostError("storage", "Unable to read the Claude Host turn selection.");
|
|
4977
5157
|
}
|
|
4978
5158
|
}
|
|
4979
5159
|
async readTranscriptCursor(registration) {
|
|
@@ -4984,7 +5164,17 @@ var ClaudeOutboxStore = class {
|
|
|
4984
5164
|
return value;
|
|
4985
5165
|
} catch (error) {
|
|
4986
5166
|
if (code(error) === "ENOENT") return null;
|
|
4987
|
-
|
|
5167
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
5168
|
+
throw new ClaudeHostError("storage", "Claude transcript cursor is malformed.");
|
|
5169
|
+
}
|
|
5170
|
+
}
|
|
5171
|
+
async transcriptCursorFingerprint(registration) {
|
|
5172
|
+
validateRegistration(registration);
|
|
5173
|
+
try {
|
|
5174
|
+
const info = await stat3(this.cursorPath(registration.host_source_ref, registration.host_session_ref), { bigint: true });
|
|
5175
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
5176
|
+
} catch {
|
|
5177
|
+
return "missing";
|
|
4988
5178
|
}
|
|
4989
5179
|
}
|
|
4990
5180
|
async writeTranscriptCursor(cursor) {
|
|
@@ -4993,16 +5183,16 @@ var ClaudeOutboxStore = class {
|
|
|
4993
5183
|
await durableAtomicReplace(this.cursorPath(cursor.host_source_ref, cursor.host_session_ref), JSON.stringify(cursor));
|
|
4994
5184
|
}
|
|
4995
5185
|
envelopePath(ref) {
|
|
4996
|
-
return
|
|
5186
|
+
return join4(this.envelopes, `${cealRequestSha256(ref)}.json`);
|
|
4997
5187
|
}
|
|
4998
5188
|
registrationPath(sourceRef, sessionRef) {
|
|
4999
|
-
return
|
|
5189
|
+
return join4(this.registrations, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
5000
5190
|
}
|
|
5001
5191
|
turnSelectionPath(sourceRef, sessionRef) {
|
|
5002
|
-
return
|
|
5192
|
+
return join4(this.turnSelections, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
5003
5193
|
}
|
|
5004
5194
|
cursorPath(sourceRef, sessionRef) {
|
|
5005
|
-
return
|
|
5195
|
+
return join4(this.cursors, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
5006
5196
|
}
|
|
5007
5197
|
async readRegistrationFile(path) {
|
|
5008
5198
|
try {
|
|
@@ -5011,7 +5201,8 @@ var ClaudeOutboxStore = class {
|
|
|
5011
5201
|
return value;
|
|
5012
5202
|
} catch (error) {
|
|
5013
5203
|
if (code(error) === "ENOENT") return null;
|
|
5014
|
-
|
|
5204
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
5205
|
+
throw new ClaudeHostError("storage", "Claude transcript registration is malformed.");
|
|
5015
5206
|
}
|
|
5016
5207
|
}
|
|
5017
5208
|
async removeStateFile(path) {
|
|
@@ -5022,7 +5213,7 @@ var ClaudeOutboxStore = class {
|
|
|
5022
5213
|
}
|
|
5023
5214
|
}
|
|
5024
5215
|
activeContextPath(identity) {
|
|
5025
|
-
return
|
|
5216
|
+
return join4(this.activeContexts, `${invocationContextKey(identity)}.json`);
|
|
5026
5217
|
}
|
|
5027
5218
|
};
|
|
5028
5219
|
function validateInvocationContextReadArguments(hostSourceRef, hostSessionRef, now) {
|
|
@@ -5035,7 +5226,7 @@ async function readProjectionFile(file) {
|
|
|
5035
5226
|
return context;
|
|
5036
5227
|
} catch (error) {
|
|
5037
5228
|
if (code(error) === "ENOENT") return null;
|
|
5038
|
-
if (error instanceof ClaudeHostError) throw error;
|
|
5229
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
5039
5230
|
throw new ClaudeHostError("storage", "Unable to read the Claude Host invocation context.");
|
|
5040
5231
|
}
|
|
5041
5232
|
}
|
|
@@ -5098,7 +5289,7 @@ function validateRegistration(value) {
|
|
|
5098
5289
|
if (!timestamp2(value.registered_at) || !timestamp2(value.expires_at)) throw new ClaudeHostError("storage", "Claude transcript registration timestamps are malformed.");
|
|
5099
5290
|
}
|
|
5100
5291
|
function validateRegistrationPaths(cwd, transcriptPath) {
|
|
5101
|
-
if (cwd !== void 0 && (typeof cwd !== "string" || !
|
|
5292
|
+
if (cwd !== void 0 && (typeof cwd !== "string" || !isAbsolute4(cwd) || cwd.length > CLAUDE_TRANSCRIPT_PATH_MAX_CHARACTERS || cwd.includes("\0"))) {
|
|
5102
5293
|
throw new ClaudeHostError("storage", "Claude transcript registration working directory is malformed.");
|
|
5103
5294
|
}
|
|
5104
5295
|
if (typeof transcriptPath !== "string" || transcriptPath.length === 0 || transcriptPath.length > CLAUDE_TRANSCRIPT_PATH_MAX_CHARACTERS) {
|
|
@@ -5195,9 +5386,9 @@ function sameKeys2(value, required, optional = []) {
|
|
|
5195
5386
|
}
|
|
5196
5387
|
|
|
5197
5388
|
// host/claude/src/claude-transcript-watcher.ts
|
|
5198
|
-
import { readdir as readdir2 } from "node:fs/promises";
|
|
5199
|
-
import { isDeepStrictEqual } from "node:util";
|
|
5200
|
-
import { join as
|
|
5389
|
+
import { readdir as readdir2, stat as stat4 } from "node:fs/promises";
|
|
5390
|
+
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
5391
|
+
import { join as join5 } from "node:path";
|
|
5201
5392
|
|
|
5202
5393
|
// host/claude/src/claude-subagent-overflow-checkpoint.ts
|
|
5203
5394
|
var ClaudeSubagentOverflowCheckpoint = class {
|
|
@@ -5232,6 +5423,7 @@ var TOKEN_OBSERVATION_SOURCE = "claude_transcript.message.usage";
|
|
|
5232
5423
|
var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
5233
5424
|
store;
|
|
5234
5425
|
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
5426
|
+
prunedRegistrations;
|
|
5235
5427
|
diagnostic;
|
|
5236
5428
|
constructor(options) {
|
|
5237
5429
|
super(options, {
|
|
@@ -5245,9 +5437,21 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5245
5437
|
transcriptPathOf(registration) {
|
|
5246
5438
|
return registration.transcript_path;
|
|
5247
5439
|
}
|
|
5440
|
+
registrationKey(registration) {
|
|
5441
|
+
return `${registration.host_source_ref}\0${registration.host_session_ref}`;
|
|
5442
|
+
}
|
|
5443
|
+
async scanFingerprint(registration) {
|
|
5444
|
+
const transcript = await super.scanFingerprint(registration);
|
|
5445
|
+
if (transcript === null) return null;
|
|
5446
|
+
const subagents = await subagentsFingerprint(registration.transcript_path);
|
|
5447
|
+
return subagents === null ? null : `${transcript}|${subagents}|${await this.store.transcriptCursorFingerprint(registration)}`;
|
|
5448
|
+
}
|
|
5248
5449
|
async listRegistrations() {
|
|
5249
5450
|
const registrations = await this.store.listTranscriptRegistrations();
|
|
5250
|
-
this.
|
|
5451
|
+
if (registrations !== this.prunedRegistrations) {
|
|
5452
|
+
this.overflow.prune(registrations);
|
|
5453
|
+
this.prunedRegistrations = registrations;
|
|
5454
|
+
}
|
|
5251
5455
|
return registrations;
|
|
5252
5456
|
}
|
|
5253
5457
|
async scanOpened(handle, registration) {
|
|
@@ -5260,13 +5464,14 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5260
5464
|
}
|
|
5261
5465
|
if (preflight.checkpointPending) await this.store.writeTranscriptCursor({ ...cursor, updated_at: this.stamp() });
|
|
5262
5466
|
const draft = mutableCursor(cursor);
|
|
5263
|
-
await this.scanOpenedTranscript(registration, handle, cursor, draft, size, device, inode);
|
|
5264
|
-
return { records: draft.consumed, enqueued: draft.enqueued, quarantined: false };
|
|
5467
|
+
const retry = await this.scanOpenedTranscript(registration, handle, cursor, draft, size, device, inode);
|
|
5468
|
+
return { records: draft.consumed, enqueued: draft.enqueued, quarantined: false, ...retry ? { retry: true } : {} };
|
|
5265
5469
|
}
|
|
5266
5470
|
async scanFailed(handle, registration, error) {
|
|
5267
5471
|
this.diagnostic("watcher_scan_failed", claudeTranscriptScanFailureKind(error), claudeTranscriptScanCause(handle, error));
|
|
5268
5472
|
if (handle === void 0 && isSymlinkTranscript(error)) return await this.quarantineUnopened(registration, "transcript_malformed");
|
|
5269
5473
|
if (error instanceof ClaudeHostError && error.code === "payload_rejected") return await this.quarantineDraft(await this.preservedCursor(registration));
|
|
5474
|
+
if (!(error instanceof ClaudeHostError) && transcriptErrorCode(error) !== null) return { records: 0, enqueued: 0, quarantined: false, retry: true };
|
|
5270
5475
|
await this.quarantineFailure(registration, handle);
|
|
5271
5476
|
return { records: 0, enqueued: 0, quarantined: true };
|
|
5272
5477
|
}
|
|
@@ -5303,9 +5508,12 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5303
5508
|
await this.consumeMainChunk(registration, main2, draft);
|
|
5304
5509
|
draft.offset += main2.length;
|
|
5305
5510
|
}
|
|
5306
|
-
|
|
5511
|
+
const mainRetry = main2 !== "empty" && main2 !== "partial" && draft.offset < size;
|
|
5512
|
+
const subagents = await this.consumeSubagents(registration, draft);
|
|
5513
|
+
draft.consumed += subagents.consumed;
|
|
5307
5514
|
await this.emitOpenTerminal(registration, draft);
|
|
5308
5515
|
await this.commitCursor(registration, handle, previous, draft, device, inode);
|
|
5516
|
+
return mainRetry || subagents.retry;
|
|
5309
5517
|
}
|
|
5310
5518
|
async preflight(registration, handle, size, device, inode) {
|
|
5311
5519
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
@@ -5467,13 +5675,15 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5467
5675
|
} catch (error) {
|
|
5468
5676
|
if (isMissingTranscriptError(error) || isNotDirectory(error)) {
|
|
5469
5677
|
this.overflow.clear(registration);
|
|
5470
|
-
return 0;
|
|
5678
|
+
return { consumed: 0, retry: false };
|
|
5471
5679
|
}
|
|
5680
|
+
if (transcriptErrorCode(error) !== null) throw error;
|
|
5472
5681
|
throw new ClaudeHostError("payload_rejected", "Claude subagent transcript directory is unavailable.");
|
|
5473
5682
|
}
|
|
5474
5683
|
const listed = new Set(names);
|
|
5475
5684
|
for (const name of Object.keys(draft.subagents)) if (!listed.has(name)) delete draft.subagents[name];
|
|
5476
|
-
|
|
5685
|
+
const overflow = names.length > CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES;
|
|
5686
|
+
const reported = await this.overflow.observe(registration, names, () => {
|
|
5477
5687
|
const line = `Claude ignored subagent transcripts past its file bound: transcript_path=${JSON.stringify(registration.transcript_path)}, files=${names.length}.`;
|
|
5478
5688
|
try {
|
|
5479
5689
|
this.log(line);
|
|
@@ -5482,15 +5692,18 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5482
5692
|
}
|
|
5483
5693
|
return true;
|
|
5484
5694
|
});
|
|
5695
|
+
let retry = overflow && !reported;
|
|
5485
5696
|
names = names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES);
|
|
5486
5697
|
let consumed = 0;
|
|
5487
5698
|
for (const name of names) {
|
|
5488
|
-
|
|
5699
|
+
const result = await this.consumeSubagentFile(draft, directory, name);
|
|
5700
|
+
consumed += result.consumed;
|
|
5701
|
+
retry ||= result.retry;
|
|
5489
5702
|
}
|
|
5490
|
-
return consumed;
|
|
5703
|
+
return { consumed, retry };
|
|
5491
5704
|
}
|
|
5492
5705
|
async consumeSubagentFile(draft, directory, name) {
|
|
5493
|
-
const path =
|
|
5706
|
+
const path = join5(directory, name);
|
|
5494
5707
|
let handle;
|
|
5495
5708
|
try {
|
|
5496
5709
|
handle = await openNoFollow(path);
|
|
@@ -5500,19 +5713,20 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5500
5713
|
const chunk = await this.readChunk(handle, pinned.offset, size);
|
|
5501
5714
|
if (chunk === "empty" || chunk === "partial") {
|
|
5502
5715
|
draft.subagents[name] = pinned;
|
|
5503
|
-
return 0;
|
|
5716
|
+
return { consumed: 0, retry: false };
|
|
5504
5717
|
}
|
|
5505
5718
|
const consumed = this.consumeSubagentLines(draft, chunk);
|
|
5506
5719
|
const offset = pinned.offset + chunk.length;
|
|
5507
5720
|
const anchor = await this.readAnchor(handle, offset, CLAUDE_TRANSCRIPT_ANCHOR_BYTES);
|
|
5508
5721
|
draft.subagents[name] = { device, inode, offset, anchor_start: anchor.start, anchor_sha256: anchor.sha256 };
|
|
5509
|
-
return consumed;
|
|
5722
|
+
return { consumed, retry: offset < size };
|
|
5510
5723
|
} catch (error) {
|
|
5511
5724
|
if (isMissingTranscriptError(error)) {
|
|
5512
5725
|
delete draft.subagents[name];
|
|
5513
|
-
return 0;
|
|
5726
|
+
return { consumed: 0, retry: false };
|
|
5514
5727
|
}
|
|
5515
|
-
|
|
5728
|
+
if (error instanceof ClaudeHostError || transcriptErrorCode(error) !== null) throw error;
|
|
5729
|
+
throw new ClaudeHostError("payload_rejected", "Claude subagent transcript is unavailable.");
|
|
5516
5730
|
} finally {
|
|
5517
5731
|
await handle?.close();
|
|
5518
5732
|
}
|
|
@@ -5644,7 +5858,7 @@ function mutableCursor(cursor) {
|
|
|
5644
5858
|
};
|
|
5645
5859
|
}
|
|
5646
5860
|
function sameCursorContent(left, right) {
|
|
5647
|
-
return
|
|
5861
|
+
return isDeepStrictEqual2({ ...left, updated_at: void 0 }, { ...right, updated_at: void 0 });
|
|
5648
5862
|
}
|
|
5649
5863
|
function zeroCounts() {
|
|
5650
5864
|
return { input: 0, cached_input: 0, cache_write_input: 0, output: 0 };
|
|
@@ -5737,9 +5951,23 @@ function isAssistantUsageLine(record5) {
|
|
|
5737
5951
|
if (identity === null || !isTranscriptRecord(record5.message.usage)) throw new ClaudeHostError("payload_rejected", "Claude transcript usage line is malformed.");
|
|
5738
5952
|
return true;
|
|
5739
5953
|
}
|
|
5954
|
+
async function subagentsFingerprint(transcriptPath) {
|
|
5955
|
+
const directory = subagentsDirectory(transcriptPath);
|
|
5956
|
+
try {
|
|
5957
|
+
const names = (await readdir2(directory)).filter((name) => name.endsWith(".jsonl") && !name.endsWith(".meta.json")).sort();
|
|
5958
|
+
const entries = [];
|
|
5959
|
+
for (const name of names) {
|
|
5960
|
+
const info = await stat4(join5(directory, name), { bigint: true });
|
|
5961
|
+
entries.push(`${name}:${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`);
|
|
5962
|
+
}
|
|
5963
|
+
return entries.join("|");
|
|
5964
|
+
} catch (error) {
|
|
5965
|
+
return isMissingTranscriptError(error) || isNotDirectory(error) ? "missing" : null;
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5740
5968
|
function subagentsDirectory(transcriptPath) {
|
|
5741
5969
|
const stem = transcriptPath.endsWith(".jsonl") ? transcriptPath.slice(0, -".jsonl".length) : transcriptPath;
|
|
5742
|
-
return
|
|
5970
|
+
return join5(stem, "subagents");
|
|
5743
5971
|
}
|
|
5744
5972
|
function observationRef(hostSourceRef, event, identity, value) {
|
|
5745
5973
|
return cealHostObservationRef("claude", transcriptObjectSha256({ host_source_ref: hostSourceRef, event, identity, value }));
|
|
@@ -5779,12 +6007,13 @@ function isSymlinkTranscript(error) {
|
|
|
5779
6007
|
import { createHash as createHash8 } from "node:crypto";
|
|
5780
6008
|
import { constants as constants5 } from "node:fs";
|
|
5781
6009
|
import { readdir as readdir3 } from "node:fs/promises";
|
|
5782
|
-
import { join as
|
|
6010
|
+
import { join as join6 } from "node:path";
|
|
5783
6011
|
var ClaudeUsageFactsCapturer = class {
|
|
5784
6012
|
sources;
|
|
5785
6013
|
usage;
|
|
5786
6014
|
now;
|
|
5787
6015
|
registrations;
|
|
6016
|
+
idleGate;
|
|
5788
6017
|
nextSourceSlot = "main";
|
|
5789
6018
|
nextSubagentIndex = 0;
|
|
5790
6019
|
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
@@ -5793,6 +6022,7 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5793
6022
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
5794
6023
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
5795
6024
|
this.registrations = new HostUsageRegistrationCapture("claude", options.diagnostic_sink);
|
|
6025
|
+
this.idleGate = new HostUsageIdleGate();
|
|
5796
6026
|
}
|
|
5797
6027
|
async captureNext() {
|
|
5798
6028
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
@@ -5817,6 +6047,20 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5817
6047
|
return false;
|
|
5818
6048
|
}
|
|
5819
6049
|
async captureMain(registration) {
|
|
6050
|
+
const transcriptKey = claudeUsageIdleKey(registration, "main");
|
|
6051
|
+
const stateKey = claudeUsageIdleKey(registration, "state");
|
|
6052
|
+
const transcriptCheck = await this.idleGate.checkUnchanged(transcriptKey, registration.transcript_path);
|
|
6053
|
+
let stateCheck;
|
|
6054
|
+
if (transcriptCheck.unchanged) {
|
|
6055
|
+
stateCheck = await this.idleGate.checkUnchanged(stateKey, this.usage.statePath("claude", registration.host_source_ref, registration.host_session_ref));
|
|
6056
|
+
if (stateCheck.unchanged) return false;
|
|
6057
|
+
}
|
|
6058
|
+
const captured = await this.scanMain(registration);
|
|
6059
|
+
this.idleGate.confirmUnchanged(transcriptKey, transcriptCheck.signature);
|
|
6060
|
+
if (stateCheck !== void 0) this.idleGate.confirmUnchanged(stateKey, stateCheck.signature);
|
|
6061
|
+
return captured;
|
|
6062
|
+
}
|
|
6063
|
+
async scanMain(registration) {
|
|
5820
6064
|
const prepared = await openHostUsageTranscriptCursor({
|
|
5821
6065
|
path: registration.transcript_path,
|
|
5822
6066
|
producer: "claude",
|
|
@@ -5845,6 +6089,13 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5845
6089
|
async captureSubagent(registration, onFailure) {
|
|
5846
6090
|
const names = await readSubagentNames(registration);
|
|
5847
6091
|
if (names.length <= CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES) this.overflow.clear(registration);
|
|
6092
|
+
const idle = await this.checkSubagentsUnchanged(registration, names);
|
|
6093
|
+
if (idle.unchanged) return false;
|
|
6094
|
+
const captured = await this.scanSubagents(registration, names, onFailure);
|
|
6095
|
+
for (const pending of idle.pending) this.idleGate.confirmUnchanged(pending.key, pending.signature);
|
|
6096
|
+
return captured;
|
|
6097
|
+
}
|
|
6098
|
+
async scanSubagents(registration, names, onFailure) {
|
|
5848
6099
|
let state = await this.usage.readState("claude", registration.host_source_ref, registration.host_session_ref);
|
|
5849
6100
|
if (state === null) return false;
|
|
5850
6101
|
state = await this.usage.recoverPending(state);
|
|
@@ -5853,6 +6104,24 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5853
6104
|
if (await this.captureListedSubagents(registration, names, state, onFailure)) return true;
|
|
5854
6105
|
return await this.recordExcessSubagentGap(registration, state, names);
|
|
5855
6106
|
}
|
|
6107
|
+
async checkSubagentsUnchanged(registration, names) {
|
|
6108
|
+
const pending = [];
|
|
6109
|
+
if (names.length > CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES) return { unchanged: false, pending };
|
|
6110
|
+
const check = async (slot, path) => {
|
|
6111
|
+
const key = claudeUsageIdleKey(registration, slot);
|
|
6112
|
+
const result = await this.idleGate.checkUnchanged(key, path);
|
|
6113
|
+
if (result.unchanged) return true;
|
|
6114
|
+
pending.push({ key, signature: result.signature });
|
|
6115
|
+
return false;
|
|
6116
|
+
};
|
|
6117
|
+
if (!await check("state", this.usage.statePath("claude", registration.host_source_ref, registration.host_session_ref))) return { unchanged: false, pending };
|
|
6118
|
+
const directory = subagentsDirectory(registration.transcript_path);
|
|
6119
|
+
if (!await check("subagents", directory)) return { unchanged: false, pending };
|
|
6120
|
+
for (const name of names) {
|
|
6121
|
+
if (!await check(subagentSlot(name), join6(directory, name))) return { unchanged: false, pending };
|
|
6122
|
+
}
|
|
6123
|
+
return { unchanged: true, pending };
|
|
6124
|
+
}
|
|
5856
6125
|
async retireMissingSubagent(state, names) {
|
|
5857
6126
|
const liveSlots = new Set(names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES).map(subagentSlot));
|
|
5858
6127
|
for (const [slot, cursor] of Object.entries(state.cursors)) {
|
|
@@ -5892,7 +6161,7 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5892
6161
|
async captureSubagentFile(registration, name, state) {
|
|
5893
6162
|
let handle;
|
|
5894
6163
|
try {
|
|
5895
|
-
const opened = await readHostUsageTranscriptSource(() => openNoFollow(
|
|
6164
|
+
const opened = await readHostUsageTranscriptSource(() => openNoFollow(join6(subagentsDirectory(registration.transcript_path), name), constants5.O_RDONLY));
|
|
5896
6165
|
handle = opened;
|
|
5897
6166
|
const file = await readHostUsageTranscriptSource(() => ownedClaudeTranscriptFile(opened));
|
|
5898
6167
|
const sourceRef = sourceFileRef(registration, file.device, file.inode);
|
|
@@ -6083,6 +6352,9 @@ function sourceFileRef(registration, device, inode) {
|
|
|
6083
6352
|
function subagentSlot(name) {
|
|
6084
6353
|
return `subagent:${sha2563(name)}`;
|
|
6085
6354
|
}
|
|
6355
|
+
function claudeUsageIdleKey(registration, slot) {
|
|
6356
|
+
return `${registration.host_source_ref}\0${registration.host_session_ref}\0${slot}`;
|
|
6357
|
+
}
|
|
6086
6358
|
function unscopedGap(reason) {
|
|
6087
6359
|
return { reason, source_file_ref: null, start_offset: null, end_offset: null, omitted_count: null };
|
|
6088
6360
|
}
|
|
@@ -6147,18 +6419,18 @@ import { createHash as createHash9, randomUUID } from "node:crypto";
|
|
|
6147
6419
|
import { readdir as readdir4 } from "node:fs/promises";
|
|
6148
6420
|
import { constants as constants6 } from "node:fs";
|
|
6149
6421
|
import { homedir } from "node:os";
|
|
6150
|
-
import { isAbsolute as
|
|
6422
|
+
import { isAbsolute as isAbsolute5, join as join8, relative, resolve } from "node:path";
|
|
6151
6423
|
|
|
6152
6424
|
// host/claude/src/claude-runtime-paths.ts
|
|
6153
|
-
import { join as
|
|
6425
|
+
import { join as join7 } from "node:path";
|
|
6154
6426
|
var CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT = "CLAUDE_CONFIG_DIR";
|
|
6155
6427
|
var CLAUDE_HOME_DEFAULT_DIRECTORY = ".claude";
|
|
6156
6428
|
var CLAUDE_PROJECTS_DIRECTORY = "projects";
|
|
6157
6429
|
function resolveClaudeConfigHome(environment, home) {
|
|
6158
|
-
return environment[CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT] ||
|
|
6430
|
+
return environment[CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT] || join7(home, CLAUDE_HOME_DEFAULT_DIRECTORY);
|
|
6159
6431
|
}
|
|
6160
6432
|
function resolveClaudeProjectsRoot(environment, home) {
|
|
6161
|
-
return
|
|
6433
|
+
return join7(resolveClaudeConfigHome(environment, home), CLAUDE_PROJECTS_DIRECTORY);
|
|
6162
6434
|
}
|
|
6163
6435
|
|
|
6164
6436
|
// host/claude/src/claude-adapter.ts
|
|
@@ -6256,11 +6528,11 @@ function sessionObservationValue(input) {
|
|
|
6256
6528
|
return { status: "started", host_kind: "claude", source: input.source, model: input.model ?? "unavailable", decoder_evidence_version: "claude-code-2.1.258" };
|
|
6257
6529
|
}
|
|
6258
6530
|
function sourceBoundTranscriptPath(path, transcriptsRoot, platform = process.platform) {
|
|
6259
|
-
if (!
|
|
6531
|
+
if (!isAbsolute5(path) || !isAbsolute5(transcriptsRoot)) throw new ClaudeHostError("configuration", "Claude transcript registration paths must be absolute.");
|
|
6260
6532
|
const transcript = resolve(path);
|
|
6261
6533
|
const root = resolve(transcriptsRoot);
|
|
6262
6534
|
const child = relative(root, transcript);
|
|
6263
|
-
if (child === "" || child === ".." || child.startsWith(`..${platform === "win32" ? "\\" : "/"}`) ||
|
|
6535
|
+
if (child === "" || child === ".." || child.startsWith(`..${platform === "win32" ? "\\" : "/"}`) || isAbsolute5(child)) {
|
|
6264
6536
|
throw new ClaudeHostError("invalid_input", "Claude transcript path is outside the configured transcripts root.");
|
|
6265
6537
|
}
|
|
6266
6538
|
return transcript;
|
|
@@ -6395,7 +6667,7 @@ async function readClaudeSubagentBaseline(transcriptPath, platform, custody) {
|
|
|
6395
6667
|
async function readClaudeSubagentSeed(directory, name, platform, custody) {
|
|
6396
6668
|
let handle;
|
|
6397
6669
|
try {
|
|
6398
|
-
handle = await openNoFollow(
|
|
6670
|
+
handle = await openNoFollow(join8(directory, name), constants6.O_RDONLY, void 0, platform, custody);
|
|
6399
6671
|
const stats = await handle.stat();
|
|
6400
6672
|
if (!stats.isFile()) throw new ClaudeHostError("storage", "Claude subagent baseline source is not a regular file.");
|
|
6401
6673
|
if (platform !== "win32" && !isSelfOwned(stats.uid, platform, handle)) throw new ClaudeHostError("storage", "Claude subagent baseline source is owned by another user.");
|
|
@@ -6478,8 +6750,8 @@ function createClaudeProducerWatcher(outboxDir) {
|
|
|
6478
6750
|
diagnostic: (event, failure_kind, cause) => writeHostServiceDiagnostic("claude", event, failure_kind, cause)
|
|
6479
6751
|
});
|
|
6480
6752
|
}
|
|
6481
|
-
async function drainClaudeProducerOnce(options) {
|
|
6482
|
-
const scan = await (options.watcher ?? createClaudeProducerWatcher(options.outbox_dir)).scanOnce().catch((error) => {
|
|
6753
|
+
async function drainClaudeProducerOnce(options, signal) {
|
|
6754
|
+
const scan = await (options.watcher ?? createClaudeProducerWatcher(options.outbox_dir)).scanOnce(signal).catch((error) => {
|
|
6483
6755
|
writeHostServiceDiagnostic("claude", "watcher_scan_failed", claudeTranscriptScanFailureKind(error), claudeTranscriptScanCause(void 0, error));
|
|
6484
6756
|
throw error;
|
|
6485
6757
|
});
|
|
@@ -6489,12 +6761,12 @@ async function drainClaudeProducerOnce(options) {
|
|
|
6489
6761
|
|
|
6490
6762
|
// host/claude/src/claude-hook-runner.ts
|
|
6491
6763
|
import { homedir as homedir2 } from "node:os";
|
|
6492
|
-
import { join as
|
|
6764
|
+
import { join as join9 } from "node:path";
|
|
6493
6765
|
|
|
6494
6766
|
// host/producer-service.ts
|
|
6495
6767
|
import { posix as posix4, win32 as win325 } from "node:path";
|
|
6496
6768
|
import { constants as constants7 } from "node:fs";
|
|
6497
|
-
import { lstat as
|
|
6769
|
+
import { lstat as lstat5 } from "node:fs/promises";
|
|
6498
6770
|
var SAFE_REF3 = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
|
|
6499
6771
|
var HOST_PRODUCER_CONFIG_FLAG = "--ceal-host-config";
|
|
6500
6772
|
var HostProducerServiceError = class extends Error {
|
|
@@ -6623,7 +6895,7 @@ function assertProducerAbsolutePath(value, platform, kind, error) {
|
|
|
6623
6895
|
}
|
|
6624
6896
|
async function configPathStat(configPath, error) {
|
|
6625
6897
|
try {
|
|
6626
|
-
return await
|
|
6898
|
+
return await lstat5(configPath);
|
|
6627
6899
|
} catch {
|
|
6628
6900
|
throw error("config_unavailable");
|
|
6629
6901
|
}
|
|
@@ -6778,7 +7050,7 @@ async function installedClaudeHookRunnerOptions(args, custody = {}) {
|
|
|
6778
7050
|
}
|
|
6779
7051
|
function standaloneClaudeHookRunnerOptions(overrides) {
|
|
6780
7052
|
const claudeHome = resolveClaudeConfigHome(process.env, homedir2());
|
|
6781
|
-
return { outbox_dir: overrides?.outbox_dir ??
|
|
7053
|
+
return { outbox_dir: overrides?.outbox_dir ?? join9(claudeHome, ".ceal", "claude-observation-outbox"), claude_transcripts_root: resolveClaudeProjectsRoot(process.env, homedir2()) };
|
|
6782
7054
|
}
|
|
6783
7055
|
function hasHostConfigArgument(args) {
|
|
6784
7056
|
return args.some((argument) => argument === HOST_PRODUCER_CONFIG_FLAG || argument.startsWith(`${HOST_PRODUCER_CONFIG_FLAG}=`));
|
|
@@ -6815,6 +7087,19 @@ var WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET = "A-Za-z0-9._=-";
|
|
|
6815
7087
|
var WINDOWS_FIXED_CMD_ARGUMENT_REFUSAL_PATTERN = `[^${WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET}]`;
|
|
6816
7088
|
var WINDOWS_FIXED_CMD_ARGUMENT = new RegExp(`^[${WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET}]+$`, "u");
|
|
6817
7089
|
|
|
7090
|
+
// host/lifecycle/src/host-bundle-manifest.ts
|
|
7091
|
+
var HOST_BUNDLE_MAX_SELECTED_BYTES = 256 * 1024 * 1024;
|
|
7092
|
+
var HOST_BUNDLE_MAX_SIGSTORE_BYTES = 16 * 1024 * 1024;
|
|
7093
|
+
var HOST_BUNDLE_TARGETS = Object.freeze(["linux-x64", "linux-arm64", "darwin-arm64", "windows-x64"]);
|
|
7094
|
+
var HOST_BUNDLE_COMPONENTS = Object.freeze(["lifecycle", "relay", "codex", "claude"]);
|
|
7095
|
+
var HOST_BUNDLE_PRODUCERS = Object.freeze(["codex", "claude"]);
|
|
7096
|
+
var HOST_RUNTIME_COMPONENTS = Object.freeze(["relay", "codex", "claude"]);
|
|
7097
|
+
var HOST_BUNDLE_PRIVATE_RUNTIME_ROOT = "libexec/ceal-host";
|
|
7098
|
+
var HOST_WINDOWS_BACKGROUND_RELATIVE_PATH = `${HOST_BUNDLE_PRIVATE_RUNTIME_ROOT}/ceal-host-background.exe`;
|
|
7099
|
+
var HOST_BUNDLE_FILE_KEYS = Object.freeze(["executable", "owners", "path", "sha256"]);
|
|
7100
|
+
var HOST_BUNDLE_SUPPORTED_REQUIRED_FEATURES = Object.freeze([]);
|
|
7101
|
+
var HOST_BUNDLE_REFERENCE_STATUS = Object.freeze({ authority: "non_authoritative", transaction: "incomplete" });
|
|
7102
|
+
|
|
6818
7103
|
// host/client-doctor.ts
|
|
6819
7104
|
var execFileAsync = promisify(execFile2);
|
|
6820
7105
|
|