@corca-org/ceal-host-win32-x64 1.0.24 → 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/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 +501 -110
- package/libexec/ceal-host/claude-invocation-authentication.mjs +799 -149
- package/libexec/ceal-host/claude-producer.mjs +1467 -1087
- package/libexec/ceal-host/codex-hook.mjs +461 -115
- package/libexec/ceal-host/codex-invocation-authentication.mjs +1021 -406
- package/libexec/ceal-host/codex-producer.mjs +1429 -1088
- package/libexec/ceal-host/control.mjs +2312 -1296
- 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 -4873
|
@@ -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",
|
|
@@ -459,7 +465,7 @@ var CEAL_POLICY_DECISIONS = vocabulary(["allowed", "denied", "not_evaluated"]);
|
|
|
459
465
|
var CEAL_CONNECTOR_ROUTE_PHASES = vocabulary(["scope_observation", "target_selection", "route_resolution"]);
|
|
460
466
|
var CEAL_CONNECTOR_ROUTE_CAUSES = vocabulary(["provider_throttled", "provider_unavailable", "binding_invalid", "personal_binding_unproven", "scope_limit_exceeded"]);
|
|
461
467
|
var CEAL_WRITE_SOURCE_KINDS = vocabulary(["authenticated_registered_client", "provider_authenticated_event"]);
|
|
462
|
-
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"]);
|
|
463
469
|
var CEAL_CLIENT_OPERATIONS = vocabulary(["handshake", "discover", "call", "readback"]);
|
|
464
470
|
var CEAL_WRITE_IDEMPOTENCY_POSTURES = vocabulary(["required", "optional", "not_required"]);
|
|
465
471
|
var CEAL_WRITE_PROVIDER_READBACK_POSTURES = vocabulary(["required", "best_effort", "not_available"]);
|
|
@@ -852,15 +858,19 @@ function requireIsoTimestamp(value, message) {
|
|
|
852
858
|
// packages/ceal-client-protocol/src/failure-guidance-table.ts
|
|
853
859
|
var CEAL_FAILURE_REDACTION_CLASSES = vocabulary(["model_safe", "withheld"]);
|
|
854
860
|
var CEAL_GATEWAY_STARTING_FAILURE_CODE = "gateway_starting";
|
|
861
|
+
var CEAL_GATEWAY_RESTARTING_FAILURE_CODE = "gateway_restarting";
|
|
855
862
|
var CEAL_OWNER_BOOTSTRAP_ABSENT_FAILURE_CODE = "bootstrap_absent";
|
|
856
863
|
var CEAL_OWNER_BOOTSTRAP_UNAVAILABLE_FAILURE_CODE = "bootstrap_unavailable";
|
|
857
864
|
var LOCAL_COMMAND_INVALID = "The local command or argument is invalid.";
|
|
858
865
|
var LOCAL_TRANSPORT_INCOMPLETE = "The local Ceal transport could not complete; report this as a gap.";
|
|
859
866
|
var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask an administrator to restore Gateway availability.";
|
|
860
867
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
861
|
-
var
|
|
868
|
+
var CEAL_CLIENT_UPGRADE_COMMAND = "npm install -g @corca-org/ceal";
|
|
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}\`.`;
|
|
862
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.";
|
|
863
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select this turn;
|
|
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.";
|
|
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.";
|
|
864
874
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
865
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.";
|
|
866
876
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
@@ -890,6 +900,9 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
890
900
|
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
901
|
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
902
|
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),
|
|
903
|
+
// A stored session that predates the authority-epoch commitment carries no
|
|
904
|
+
// epoch to compare, so it can never refresh: adopt a fresh session instead.
|
|
905
|
+
authority_epoch_unknown: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
893
906
|
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
894
907
|
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
908
|
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),
|
|
@@ -911,6 +924,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
911
924
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
912
925
|
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
913
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),
|
|
914
929
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
915
930
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
916
931
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
@@ -1014,10 +1029,11 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1014
1029
|
host_session_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 401),
|
|
1015
1030
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
1016
1031
|
// changes mode; standalone remains the separate Client authority path.
|
|
1017
|
-
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "
|
|
1032
|
+
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "retry", 401, true),
|
|
1018
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),
|
|
1019
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),
|
|
1020
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),
|
|
1021
1037
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
1022
1038
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
1023
1039
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
@@ -1031,7 +1047,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1031
1047
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
1032
1048
|
// sandboxed Relay socket names the run-alone retry.
|
|
1033
1049
|
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(
|
|
1050
|
+
host_relay_unavailable: guidance(HOST_RELAY_RESTARTING, "retry", 503, true),
|
|
1035
1051
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
1036
1052
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
1037
1053
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -1279,7 +1295,7 @@ var CEAL_OPERATION_JSON_SCHEMA_BUDGET = Object.freeze({
|
|
|
1279
1295
|
max_literal_nodes: 512
|
|
1280
1296
|
});
|
|
1281
1297
|
|
|
1282
|
-
// packages/ceal-client-protocol/src/operation-json-schema.ts
|
|
1298
|
+
// packages/ceal-client-protocol/src/operation-json-schema-leaf-validators.ts
|
|
1283
1299
|
var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
1284
1300
|
|
|
1285
1301
|
// packages/ceal-client-protocol/src/operation-contract-validation.ts
|
|
@@ -1388,6 +1404,10 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
1388
1404
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
1389
1405
|
});
|
|
1390
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
|
+
|
|
1391
1411
|
// packages/ceal-client-protocol/src/gateway-installation-activation.ts
|
|
1392
1412
|
var CEAL_GATEWAY_INSTALLATION_ACTIVATION_CODE_DATA_CHARACTERS = 32;
|
|
1393
1413
|
var CEAL_GATEWAY_INSTALLATION_ACTIVATION_CODE_CHECK_CHARACTERS = 8;
|
|
@@ -1410,6 +1430,7 @@ var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUI
|
|
|
1410
1430
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
1411
1431
|
|
|
1412
1432
|
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1433
|
+
var CEAL_RESOURCE_GET_CHILD_REF_KINDS = Object.freeze(["section", "slide", "question"]);
|
|
1413
1434
|
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
1414
1435
|
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
1415
1436
|
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
@@ -1426,7 +1447,8 @@ var CEAL_OPERATION_ID_PLACEHOLDER = "<operation-id>";
|
|
|
1426
1447
|
var CEAL_OPERATION_INPUT_PLACEHOLDER = "<json-object>";
|
|
1427
1448
|
var MODEL_INVOCATION_BASE_ARGUMENTS = [CEAL_OPERATION_INVOKE_COMMAND, CEAL_OPERATION_ID_PLACEHOLDER].join(" ");
|
|
1428
1449
|
var CEAL_MODEL_INVOCATION_ARGUMENTS = [MODEL_INVOCATION_BASE_ARGUMENTS, CEAL_OPERATION_INPUT_FLAG, shellSingleQuoted(CEAL_OPERATION_INPUT_PLACEHOLDER)].join(" ");
|
|
1429
|
-
var
|
|
1450
|
+
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.`;
|
|
1451
|
+
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
1452
|
function shellSingleQuoted(value) {
|
|
1431
1453
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
1432
1454
|
}
|
|
@@ -1612,6 +1634,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1612
1634
|
"github.review.submitted",
|
|
1613
1635
|
"github.issue_comment.created",
|
|
1614
1636
|
"github.review_comment.created",
|
|
1637
|
+
"github.issue_comment.edited",
|
|
1638
|
+
"github.review_comment.edited",
|
|
1615
1639
|
"github.reaction.created",
|
|
1616
1640
|
"github.reaction.deleted",
|
|
1617
1641
|
"github.pull_request.review_requested",
|
|
@@ -1640,6 +1664,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1640
1664
|
"github.release.published": "release_published",
|
|
1641
1665
|
"github.issue.edited": "resource_modified",
|
|
1642
1666
|
"github.pull_request.edited": "resource_modified",
|
|
1667
|
+
"github.issue_comment.edited": "resource_modified",
|
|
1668
|
+
"github.review_comment.edited": "resource_modified",
|
|
1643
1669
|
"github.reaction.created": "reaction_created",
|
|
1644
1670
|
"github.reaction.deleted": "ceal_write_completed",
|
|
1645
1671
|
"github.pull_request.review_requested": "ceal_write_completed",
|
|
@@ -2298,6 +2324,8 @@ var CEAL_HOST_INVOCATION_CONTEXT_REQUEST_MAX_BYTES = 16 * 1024;
|
|
|
2298
2324
|
var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_BYTES = 2 * 1024;
|
|
2299
2325
|
var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_MESSAGES = 32;
|
|
2300
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"]);
|
|
2301
2329
|
function boundCealHostInvocationHumanMessageWindow(newestFirst, sourceTruncated = false) {
|
|
2302
2330
|
const messages = [];
|
|
2303
2331
|
let truncated = sourceTruncated || newestFirst.length > CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_MESSAGES;
|
|
@@ -2381,6 +2409,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
2381
2409
|
"context_replaced",
|
|
2382
2410
|
"no_binding",
|
|
2383
2411
|
"context_expired",
|
|
2412
|
+
"transcript_unavailable",
|
|
2384
2413
|
"host_source_refused",
|
|
2385
2414
|
"host_credential_refused",
|
|
2386
2415
|
"gateway_unavailable",
|
|
@@ -2410,9 +2439,11 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2410
2439
|
invalid_arguments: Object.freeze({ classification: "host_arguments_invalid", next_action: "answer_with_gap" }),
|
|
2411
2440
|
options_invalid: Object.freeze({ classification: "host_configuration_invalid", next_action: "answer_with_gap" }),
|
|
2412
2441
|
session_unavailable: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2413
|
-
//
|
|
2414
|
-
//
|
|
2415
|
-
|
|
2442
|
+
// A missing turn right after a Host restart clears by itself once the
|
|
2443
|
+
// watcher reactivates the turn, so the caller waits briefly and retries;
|
|
2444
|
+
// a caller that knows it is in an ephemeral side conversation keeps the
|
|
2445
|
+
// standalone fallback the guidance names second.
|
|
2446
|
+
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "retry" }),
|
|
2416
2447
|
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
2417
2448
|
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
2418
2449
|
// `no_binding` now means the producer has no real current Host session. The
|
|
@@ -2420,6 +2451,11 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2420
2451
|
// useful retry until the consumer is running inside a Host session.
|
|
2421
2452
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2422
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" }),
|
|
2423
2459
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
2424
2460
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
2425
2461
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
@@ -2429,7 +2465,7 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2429
2465
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
2430
2466
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
2431
2467
|
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: "
|
|
2468
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "retry" }),
|
|
2433
2469
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
2434
2470
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
2435
2471
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -2524,11 +2560,15 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
2524
2560
|
|
|
2525
2561
|
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
2526
2562
|
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
2527
|
-
var
|
|
2563
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSE_NODES = 8;
|
|
2528
2564
|
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
2529
2565
|
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
2530
2566
|
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
2531
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");
|
|
2532
2572
|
function redactOperatorDiagnosticSecrets(value) {
|
|
2533
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]");
|
|
2534
2574
|
}
|
|
@@ -2537,8 +2577,9 @@ function redactOperatorDiagnosticText(value) {
|
|
|
2537
2577
|
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
2538
2578
|
}
|
|
2539
2579
|
function renderOperatorDiagnostic(value) {
|
|
2540
|
-
const state = collectDiagnosticState(value);
|
|
2580
|
+
const state = collectDiagnosticState(value, read(value, LOCAL_OPERATOR_DIAGNOSTIC_PATHS) === true);
|
|
2541
2581
|
const fields = [
|
|
2582
|
+
state.truncated ? "causes_truncated=true" : void 0,
|
|
2542
2583
|
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
2543
2584
|
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
2544
2585
|
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
@@ -2548,23 +2589,27 @@ function renderOperatorDiagnostic(value) {
|
|
|
2548
2589
|
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
2549
2590
|
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
2550
2591
|
}
|
|
2551
|
-
function collectDiagnosticState(value) {
|
|
2552
|
-
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 };
|
|
2553
2594
|
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
2554
|
-
|
|
2595
|
+
let inspected = 0;
|
|
2596
|
+
while (pending.length > 0 && inspected < OPERATOR_DIAGNOSTIC_MAX_CAUSE_NODES) {
|
|
2555
2597
|
const current = pending.shift();
|
|
2556
|
-
if (current
|
|
2598
|
+
if (current === void 0 || isObject(current) && visited.has(current)) continue;
|
|
2599
|
+
inspected += 1;
|
|
2600
|
+
visitDiagnosticNode(current, state, pending, visited, preserveLocalAbsolutePaths);
|
|
2557
2601
|
}
|
|
2602
|
+
state.truncated ||= pending.length > 0;
|
|
2558
2603
|
return state;
|
|
2559
2604
|
}
|
|
2560
|
-
function visitDiagnosticNode(current, state, pending, visited) {
|
|
2605
|
+
function visitDiagnosticNode(current, state, pending, visited, preserveLocalAbsolutePaths) {
|
|
2561
2606
|
if (isObject(current)) {
|
|
2562
2607
|
if (visited.has(current)) return;
|
|
2563
2608
|
visited.add(current);
|
|
2564
2609
|
}
|
|
2565
2610
|
captureProcessEvidence(current, state);
|
|
2566
|
-
appendCause(current, state.causes);
|
|
2567
|
-
enqueueCauseChildren(current, state
|
|
2611
|
+
appendCause(current, state.causes, preserveLocalAbsolutePaths);
|
|
2612
|
+
enqueueCauseChildren(current, state, pending);
|
|
2568
2613
|
}
|
|
2569
2614
|
function captureProcessEvidence(current, state) {
|
|
2570
2615
|
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
@@ -2572,10 +2617,9 @@ function captureProcessEvidence(current, state) {
|
|
|
2572
2617
|
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
2573
2618
|
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
2574
2619
|
}
|
|
2575
|
-
function appendCause(current, causes) {
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
causes.push(errorCause(current));
|
|
2620
|
+
function appendCause(current, causes, preserveLocalAbsolutePaths) {
|
|
2621
|
+
if (current instanceof Error) {
|
|
2622
|
+
causes.push(errorCause(current, preserveLocalAbsolutePaths));
|
|
2579
2623
|
return;
|
|
2580
2624
|
}
|
|
2581
2625
|
if (!isObject(current)) {
|
|
@@ -2583,7 +2627,7 @@ function appendCause(current, causes) {
|
|
|
2583
2627
|
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
2584
2628
|
}
|
|
2585
2629
|
}
|
|
2586
|
-
function errorCause(error) {
|
|
2630
|
+
function errorCause(error, preserveLocalAbsolutePaths) {
|
|
2587
2631
|
const name = safeText(read(error, "name")) ?? "Error";
|
|
2588
2632
|
const message = safeText(read(error, "message"));
|
|
2589
2633
|
const codeValue = read(error, "code");
|
|
@@ -2591,14 +2635,29 @@ function errorCause(error) {
|
|
|
2591
2635
|
const errnoValue = read(error, "errno");
|
|
2592
2636
|
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
2593
2637
|
const syscall = safeText(read(error, "syscall"));
|
|
2594
|
-
const path = safePath(read(error, "path"));
|
|
2638
|
+
const path = safePath(read(error, "path"), preserveLocalAbsolutePaths);
|
|
2595
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 } });
|
|
2596
2640
|
}
|
|
2597
|
-
function enqueueCauseChildren(current,
|
|
2641
|
+
function enqueueCauseChildren(current, state, pending) {
|
|
2598
2642
|
const cause = read(current, "cause");
|
|
2599
2643
|
if (cause !== void 0) pending.push(cause);
|
|
2600
2644
|
const errors = read(current, "errors");
|
|
2601
|
-
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
|
+
}
|
|
2602
2661
|
}
|
|
2603
2662
|
function isObject(value) {
|
|
2604
2663
|
return typeof value === "object" && value !== null;
|
|
@@ -2627,10 +2686,11 @@ function safeText(value) {
|
|
|
2627
2686
|
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
2628
2687
|
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2629
2688
|
}
|
|
2630
|
-
function safePath(value) {
|
|
2689
|
+
function safePath(value, preserveLocalAbsolutePaths) {
|
|
2631
2690
|
if (typeof value !== "string") return void 0;
|
|
2632
2691
|
const safe = safeDiagnosticText(value);
|
|
2633
2692
|
if (safe.length === 0) return void 0;
|
|
2693
|
+
if (!preserveLocalAbsolutePaths && hasAbsolutePathPrefix(value) && !safe.startsWith("[home path redacted]")) return "[path redacted]";
|
|
2634
2694
|
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
2635
2695
|
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
2636
2696
|
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
@@ -2702,7 +2762,10 @@ function redactUrls(value) {
|
|
|
2702
2762
|
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
2703
2763
|
}
|
|
2704
2764
|
function redactFilePaths(value) {
|
|
2705
|
-
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);
|
|
2706
2769
|
}
|
|
2707
2770
|
function homePathRange(value, match, prefixLength) {
|
|
2708
2771
|
const index = match.index;
|
|
@@ -2929,7 +2992,7 @@ function invalid2(message) {
|
|
|
2929
2992
|
}
|
|
2930
2993
|
|
|
2931
2994
|
// host/claude/src/claude-outbox.ts
|
|
2932
|
-
import { mkdir as mkdir4,
|
|
2995
|
+
import { mkdir as mkdir4, readFile, stat as stat3, unlink as unlink3 } from "node:fs/promises";
|
|
2933
2996
|
import { isAbsolute as isAbsolute4, join as join4 } from "node:path";
|
|
2934
2997
|
|
|
2935
2998
|
// host/invocation-context.ts
|
|
@@ -2987,24 +3050,17 @@ function safeRef(value) {
|
|
|
2987
3050
|
var HOST_PRODUCER_FRAME_LENGTH_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
2988
3051
|
var HOST_PRODUCER_FRAME_KINDS = ["session_started", "turn_started", "turn_terminal", "producer_status"];
|
|
2989
3052
|
var FRAME_KINDS = new Set(HOST_PRODUCER_FRAME_KINDS);
|
|
2990
|
-
var HOST_PRODUCER_FRAME_ERROR_CODES = [
|
|
2991
|
-
"invalid_frame_encoding",
|
|
2992
|
-
"invalid_frame_length",
|
|
2993
|
-
"frame_truncated",
|
|
2994
|
-
"unsupported_frame_schema",
|
|
2995
|
-
"invalid_frame_shape",
|
|
2996
|
-
"invalid_producer_identity",
|
|
2997
|
-
"frame_too_large"
|
|
2998
|
-
];
|
|
2999
3053
|
|
|
3000
3054
|
// host/relay/src/host-producer-core.ts
|
|
3001
3055
|
import { createHash as createHash5 } from "node:crypto";
|
|
3056
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3057
|
+
import { lstat as lstat2, readdir, stat as stat2 } from "node:fs/promises";
|
|
3002
3058
|
|
|
3003
3059
|
// host/secure-file.ts
|
|
3004
3060
|
import { execFile } from "node:child_process";
|
|
3005
3061
|
import { constants } from "node:fs";
|
|
3006
3062
|
import { lstat, open } from "node:fs/promises";
|
|
3007
|
-
import { dirname, join as join2, win32 } from "node:path";
|
|
3063
|
+
import { dirname, join as join2, parse, win32 } from "node:path";
|
|
3008
3064
|
import { fileURLToPath } from "node:url";
|
|
3009
3065
|
var SecureFileCustodyError = class extends Error {
|
|
3010
3066
|
name = "SecureFileCustodyError";
|
|
@@ -3104,7 +3160,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
3104
3160
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
3105
3161
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
3106
3162
|
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) => {
|
|
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) => {
|
|
3108
3164
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
3109
3165
|
if (exitCode === null) {
|
|
3110
3166
|
reject(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -3362,7 +3418,9 @@ function mergeHostInvocationHumanMessageWindow(existing, chronological) {
|
|
|
3362
3418
|
seen.add(message.host_input_ref);
|
|
3363
3419
|
newestFirst.push(message);
|
|
3364
3420
|
}
|
|
3365
|
-
|
|
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);
|
|
3366
3424
|
}
|
|
3367
3425
|
function transcriptScanFailureKind(error, adapterFailureKind) {
|
|
3368
3426
|
if (transcriptErrorCode(error) === "ELOOP") return "symlink";
|
|
@@ -3419,6 +3477,15 @@ async function transcriptCursorBoundsReason(handle, cursor, size) {
|
|
|
3419
3477
|
if (cursor.offset > 0 && !await transcriptAnchorMatches(handle, cursor)) return "transcript_rewritten";
|
|
3420
3478
|
return null;
|
|
3421
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
|
+
}
|
|
3422
3489
|
function transcriptSha256(value) {
|
|
3423
3490
|
return createHash5("sha256").update(value).digest("hex");
|
|
3424
3491
|
}
|
|
@@ -3451,27 +3518,71 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
3451
3518
|
producerInstallationRef: options.producer_installation_ref
|
|
3452
3519
|
};
|
|
3453
3520
|
}
|
|
3454
|
-
async function scanTranscriptRegistrations(registrations, scanOne) {
|
|
3521
|
+
async function scanTranscriptRegistrations(registrations, scanOne, totalRegistrations, signal) {
|
|
3455
3522
|
let records = 0;
|
|
3456
3523
|
let enqueued = 0;
|
|
3457
3524
|
let quarantined = 0;
|
|
3525
|
+
let scanned = 0;
|
|
3458
3526
|
for (const registration of registrations) {
|
|
3527
|
+
if (signal?.aborted) break;
|
|
3528
|
+
scanned += 1;
|
|
3459
3529
|
const result = await scanOne(registration);
|
|
3460
3530
|
records += result.records;
|
|
3461
3531
|
enqueued += result.enqueued;
|
|
3462
3532
|
if (result.quarantined) quarantined += 1;
|
|
3463
3533
|
}
|
|
3464
|
-
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
|
+
}
|
|
3465
3569
|
}
|
|
3466
3570
|
function formatRetiredTranscriptLog(producerLabel, transcriptPath) {
|
|
3467
3571
|
return `${producerLabel} retired a transcript registration: transcript_path=${JSON.stringify(transcriptPath)}, reason=${TRANSCRIPT_MISSING_REASON}.`;
|
|
3468
3572
|
}
|
|
3573
|
+
var HOST_TRANSCRIPT_RECONCILIATION_BATCH = 100;
|
|
3469
3574
|
var HostTranscriptWatcher = class {
|
|
3470
3575
|
outboxRetentionMs;
|
|
3471
3576
|
now;
|
|
3472
3577
|
log;
|
|
3473
3578
|
producerInstallationRef;
|
|
3474
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;
|
|
3475
3586
|
constructor(options, owner) {
|
|
3476
3587
|
const base = createTranscriptWatcherBase(options, owner);
|
|
3477
3588
|
this.outboxRetentionMs = base.outboxRetentionMs;
|
|
@@ -3480,8 +3591,97 @@ var HostTranscriptWatcher = class {
|
|
|
3480
3591
|
this.producerInstallationRef = base.producerInstallationRef;
|
|
3481
3592
|
this.clockFailure = owner.clock_failure;
|
|
3482
3593
|
}
|
|
3483
|
-
async scanOnce() {
|
|
3484
|
-
|
|
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
|
+
}
|
|
3485
3685
|
}
|
|
3486
3686
|
async scanRegistration(registration) {
|
|
3487
3687
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
@@ -3547,6 +3747,14 @@ var HostTranscriptWatcher = class {
|
|
|
3547
3747
|
return transcriptCursorBoundsReason(handle, cursor, size);
|
|
3548
3748
|
}
|
|
3549
3749
|
};
|
|
3750
|
+
async function listHostOutboxDirectoryNames(directory) {
|
|
3751
|
+
try {
|
|
3752
|
+
return await readdir(directory);
|
|
3753
|
+
} catch (error) {
|
|
3754
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return [];
|
|
3755
|
+
throw error;
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3550
3758
|
var HostProducerDrainCore = class {
|
|
3551
3759
|
host;
|
|
3552
3760
|
now;
|
|
@@ -3574,7 +3782,7 @@ var HostProducerDrainCore = class {
|
|
|
3574
3782
|
};
|
|
3575
3783
|
|
|
3576
3784
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3577
|
-
import { lstat as
|
|
3785
|
+
import { lstat as lstat3, mkdir as mkdir2, open as open2, rename, unlink } from "node:fs/promises";
|
|
3578
3786
|
import { dirname as dirname3 } from "node:path";
|
|
3579
3787
|
|
|
3580
3788
|
// host/windows-rename-retry.ts
|
|
@@ -3596,7 +3804,7 @@ function resolveRetrySchedule(tuning) {
|
|
|
3596
3804
|
startDelayMs: tuning.startDelayMs ?? RETRY_START_DELAY_MS,
|
|
3597
3805
|
maxDelayMs: tuning.maxDelayMs ?? RETRY_MAX_DELAY_MS,
|
|
3598
3806
|
sleep: tuning.sleep ?? ((ms) => setTimeout2(ms)),
|
|
3599
|
-
now: tuning.now ?? (() =>
|
|
3807
|
+
now: tuning.now ?? (() => performance.now())
|
|
3600
3808
|
};
|
|
3601
3809
|
}
|
|
3602
3810
|
async function renameWithWindowsRetry(operation, tuning) {
|
|
@@ -3629,7 +3837,7 @@ function isRetryableRenameError(error) {
|
|
|
3629
3837
|
var DEFAULT_PORT = {
|
|
3630
3838
|
platform: process.platform,
|
|
3631
3839
|
mkdir: (path, options) => mkdir2(path, options),
|
|
3632
|
-
lstat: (path) =>
|
|
3840
|
+
lstat: (path) => lstat3(path),
|
|
3633
3841
|
open_file: (path) => open2(path, "wx", 384),
|
|
3634
3842
|
rename,
|
|
3635
3843
|
unlink,
|
|
@@ -3727,6 +3935,8 @@ var HostUsageFactsStore = class {
|
|
|
3727
3935
|
afterPendingWrite;
|
|
3728
3936
|
afterBatchPublish;
|
|
3729
3937
|
sessionDirectoryCursor;
|
|
3938
|
+
uploadScanSignature;
|
|
3939
|
+
uploadScanEmpty = false;
|
|
3730
3940
|
constructor(options) {
|
|
3731
3941
|
this.root = join3(options.outbox_dir, "usage-facts");
|
|
3732
3942
|
this.sessions = join3(this.root, "sessions");
|
|
@@ -3746,8 +3956,11 @@ var HostUsageFactsStore = class {
|
|
|
3746
3956
|
this.sessionDirectoryCursor = void 0;
|
|
3747
3957
|
await cursor?.close();
|
|
3748
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
|
+
}
|
|
3749
3963
|
async readState(producer, hostSourceRef, hostSessionRef) {
|
|
3750
|
-
await this.prepare();
|
|
3751
3964
|
const path = this.sessionPath(producer, hostSourceRef, hostSessionRef);
|
|
3752
3965
|
const value = await readOptionalJson(path, HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
3753
3966
|
if (value === null) return null;
|
|
@@ -3805,11 +4018,15 @@ var HostUsageFactsStore = class {
|
|
|
3805
4018
|
}
|
|
3806
4019
|
/** Remove unreferenced local batch objects in bounded pieces after settling any exact pending transition. */
|
|
3807
4020
|
async sweepOrphanedBatches(state) {
|
|
3808
|
-
await this.prepare();
|
|
3809
4021
|
const directoryPath = this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref);
|
|
3810
|
-
await preparePrivateDirectory(directoryPath, this.platform, this.custody);
|
|
3811
4022
|
const expected = expectedBatchNames(state);
|
|
3812
|
-
|
|
4023
|
+
let directory;
|
|
4024
|
+
try {
|
|
4025
|
+
directory = await opendir(directoryPath);
|
|
4026
|
+
} catch (error) {
|
|
4027
|
+
if (errorCode2(error) === "ENOENT") return 0;
|
|
4028
|
+
throw error;
|
|
4029
|
+
}
|
|
3813
4030
|
let inspected = 0;
|
|
3814
4031
|
let deleted = 0;
|
|
3815
4032
|
try {
|
|
@@ -3846,7 +4063,14 @@ var HostUsageFactsStore = class {
|
|
|
3846
4063
|
});
|
|
3847
4064
|
}
|
|
3848
4065
|
async nextUploadCandidate(producer, hostSourceRef) {
|
|
3849
|
-
await this.
|
|
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) {
|
|
3850
4074
|
const names = await this.readNextSessionNames();
|
|
3851
4075
|
for (const name of names) {
|
|
3852
4076
|
const state = await readOptionalJson(join3(this.sessions, name), HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
@@ -3864,7 +4088,14 @@ var HostUsageFactsStore = class {
|
|
|
3864
4088
|
return null;
|
|
3865
4089
|
}
|
|
3866
4090
|
async readNextSessionNames() {
|
|
3867
|
-
this.sessionDirectoryCursor
|
|
4091
|
+
if (this.sessionDirectoryCursor === void 0) {
|
|
4092
|
+
try {
|
|
4093
|
+
this.sessionDirectoryCursor = await opendir(this.sessions);
|
|
4094
|
+
} catch (error) {
|
|
4095
|
+
if (errorCode2(error) === "ENOENT") return [];
|
|
4096
|
+
throw error;
|
|
4097
|
+
}
|
|
4098
|
+
}
|
|
3868
4099
|
const names = [];
|
|
3869
4100
|
let inspected = 0;
|
|
3870
4101
|
while (inspected < HOST_USAGE_FACTS_UPLOAD_SCAN_SESSIONS) {
|
|
@@ -4278,6 +4509,8 @@ function sha2562(value) {
|
|
|
4278
4509
|
|
|
4279
4510
|
// host/relay/src/host-usage-facts-capture.ts
|
|
4280
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";
|
|
4281
4514
|
var HOST_USAGE_FACTS_SCAN_MAX_BYTES = 1024 * 1024;
|
|
4282
4515
|
var HOST_USAGE_FACTS_SCAN_MAX_ROWS = 256;
|
|
4283
4516
|
var HOST_USAGE_FACTS_SOURCE_ROW_MAX_BYTES = 64 * 1024;
|
|
@@ -4327,6 +4560,55 @@ var HostUsageRegistrationCapture = class {
|
|
|
4327
4560
|
return captured;
|
|
4328
4561
|
}
|
|
4329
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
|
+
}
|
|
4330
4612
|
async function openHostUsageTranscriptCursor(input) {
|
|
4331
4613
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants3.O_RDONLY));
|
|
4332
4614
|
let source;
|
|
@@ -4397,7 +4679,7 @@ function completeLinePrefix(bytes, baseOffset) {
|
|
|
4397
4679
|
|
|
4398
4680
|
// host/relay/src/host-registration-state.ts
|
|
4399
4681
|
import { constants as constants4 } from "node:fs";
|
|
4400
|
-
import { dirname as
|
|
4682
|
+
import { dirname as dirname6 } from "node:path";
|
|
4401
4683
|
|
|
4402
4684
|
// host/runtime-source-paths.ts
|
|
4403
4685
|
import { createHash as createHash7 } from "node:crypto";
|
|
@@ -4466,7 +4748,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
4466
4748
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
4467
4749
|
let raw;
|
|
4468
4750
|
try {
|
|
4469
|
-
await assertPrivateRegistrationDirectory(
|
|
4751
|
+
await assertPrivateRegistrationDirectory(dirname6(path), platform, custody);
|
|
4470
4752
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
4471
4753
|
} catch (error) {
|
|
4472
4754
|
throw registrationReadError(error);
|
|
@@ -4583,6 +4865,10 @@ var HostUsageFactsUploader = class {
|
|
|
4583
4865
|
async close() {
|
|
4584
4866
|
await this.store.close();
|
|
4585
4867
|
}
|
|
4868
|
+
/** The start owner prepares the store once, so idle ticks below never re-prepare. */
|
|
4869
|
+
async prepare() {
|
|
4870
|
+
await this.store.prepare();
|
|
4871
|
+
}
|
|
4586
4872
|
async uploadOne(signal) {
|
|
4587
4873
|
const candidate = await this.store.nextUploadCandidate(this.options.producer, this.options.host_source_ref);
|
|
4588
4874
|
if (candidate === null) return false;
|
|
@@ -4605,6 +4891,11 @@ var HostUsageFactsUploader = class {
|
|
|
4605
4891
|
};
|
|
4606
4892
|
async function runHostUsageFactsUploader(options, signal, wait = waitForAbort) {
|
|
4607
4893
|
const uploader = new HostUsageFactsUploader(options);
|
|
4894
|
+
try {
|
|
4895
|
+
await uploader.prepare();
|
|
4896
|
+
} catch {
|
|
4897
|
+
writeHostServiceDiagnostic(options.producer, "usage_upload_failed", void 0, "upload_failed");
|
|
4898
|
+
}
|
|
4608
4899
|
let delay = 500;
|
|
4609
4900
|
let failures = 0;
|
|
4610
4901
|
try {
|
|
@@ -4632,15 +4923,12 @@ async function runHostUsageFactsUploader(options, signal, wait = waitForAbort) {
|
|
|
4632
4923
|
}
|
|
4633
4924
|
}
|
|
4634
4925
|
|
|
4635
|
-
// host/relay/src/relay-quarantine-store.ts
|
|
4636
|
-
var RELAY_QUARANTINE_MAX_BYTES = 16 * 1024 * 1024;
|
|
4637
|
-
var RELAY_QUARANTINE_FRAME_REASONS = ["frame_identity_conflict", "sequence_gap", "gateway_refused"];
|
|
4638
|
-
var RELAY_QUARANTINE_REASONS = [...RELAY_QUARANTINE_FRAME_REASONS, ...HOST_PRODUCER_FRAME_ERROR_CODES];
|
|
4639
|
-
|
|
4640
4926
|
// host/relay/src/relay-admission-store.ts
|
|
4641
|
-
var
|
|
4642
|
-
|
|
4643
|
-
|
|
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");
|
|
4644
4932
|
|
|
4645
4933
|
// host/relay/src/relay-pipe-handshake.ts
|
|
4646
4934
|
var RELAY_PIPE_FRAME_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
@@ -4702,6 +4990,7 @@ var ClaudeOutboxStore = class {
|
|
|
4702
4990
|
directory;
|
|
4703
4991
|
activeContexts;
|
|
4704
4992
|
turnSelections;
|
|
4993
|
+
registrationInventory = new HostRegistrationInventory();
|
|
4705
4994
|
constructor(directory) {
|
|
4706
4995
|
if (!isAbsolute4(directory)) throw new ClaudeHostError("configuration", "Claude outbox directory must be absolute.");
|
|
4707
4996
|
this.directory = directory;
|
|
@@ -4738,6 +5027,7 @@ var ClaudeOutboxStore = class {
|
|
|
4738
5027
|
const path = this.activeContextPath(identity);
|
|
4739
5028
|
const active = await readProjectionFile(path);
|
|
4740
5029
|
if (active === null || active.prompt_ref !== promptRef || active.identity.host_turn_ref !== identity.host_turn_ref) return false;
|
|
5030
|
+
await this.prepare();
|
|
4741
5031
|
const updated = { ...active, turn_generation_ref: turnGenerationRef };
|
|
4742
5032
|
validateClaudeHostInvocationContext(updated);
|
|
4743
5033
|
await durableAtomicReplace(path, JSON.stringify(updated));
|
|
@@ -4750,14 +5040,12 @@ var ClaudeOutboxStore = class {
|
|
|
4750
5040
|
*/
|
|
4751
5041
|
async readRawInvocationContext(hostSourceRef, hostSessionRef) {
|
|
4752
5042
|
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
5043
|
const context = await readLatestSessionProjection(this.activeContextPath({ host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }), hostSourceRef, hostSessionRef, readProjectionFile);
|
|
4755
5044
|
return context;
|
|
4756
5045
|
}
|
|
4757
5046
|
async listInvocationContexts(now = /* @__PURE__ */ new Date()) {
|
|
4758
|
-
await this.prepare();
|
|
4759
5047
|
const contexts = [];
|
|
4760
|
-
for (const name of await
|
|
5048
|
+
for (const name of await listHostOutboxDirectoryNames(this.activeContexts)) {
|
|
4761
5049
|
if (!name.endsWith(".json")) continue;
|
|
4762
5050
|
try {
|
|
4763
5051
|
const value = JSON.parse(await readFile(join4(this.activeContexts, name), "utf8"));
|
|
@@ -4774,10 +5062,9 @@ var ClaudeOutboxStore = class {
|
|
|
4774
5062
|
await durableAtomicReplace(this.envelopePath(entry.submission_ref), JSON.stringify(entry));
|
|
4775
5063
|
}
|
|
4776
5064
|
async listEnvelopes() {
|
|
4777
|
-
await this.prepare();
|
|
4778
5065
|
const entries = [];
|
|
4779
5066
|
let malformed = 0;
|
|
4780
|
-
for (const name of await
|
|
5067
|
+
for (const name of await listHostOutboxDirectoryNames(this.envelopes)) {
|
|
4781
5068
|
if (!name.endsWith(".json")) continue;
|
|
4782
5069
|
try {
|
|
4783
5070
|
const value = JSON.parse(await readFile(join4(this.envelopes, name), "utf8"));
|
|
@@ -4805,14 +5092,14 @@ var ClaudeOutboxStore = class {
|
|
|
4805
5092
|
}
|
|
4806
5093
|
async readSession(sourceRef, sessionRef) {
|
|
4807
5094
|
if (!SAFE_REF2.test(sourceRef) || !SAFE_REF2.test(sessionRef)) throw new ClaudeHostError("invalid_input", "Claude session identity is invalid.");
|
|
4808
|
-
await this.prepare();
|
|
4809
5095
|
try {
|
|
4810
5096
|
const value = JSON.parse(await readFile(join4(this.sessions, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`), "utf8"));
|
|
4811
5097
|
validateSession(value);
|
|
4812
5098
|
return value;
|
|
4813
5099
|
} catch (error) {
|
|
4814
5100
|
if (code(error) === "ENOENT") return null;
|
|
4815
|
-
|
|
5101
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
5102
|
+
throw new ClaudeHostError("storage", "Claude session snapshot is malformed.");
|
|
4816
5103
|
}
|
|
4817
5104
|
}
|
|
4818
5105
|
async registerTranscript(registration) {
|
|
@@ -4838,47 +5125,56 @@ var ClaudeOutboxStore = class {
|
|
|
4838
5125
|
}
|
|
4839
5126
|
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
4840
5127
|
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
5128
|
const registration = await this.readRegistrationFile(this.registrationPath(hostSourceRef, hostSessionRef));
|
|
4843
5129
|
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
5130
|
return registration;
|
|
4845
5131
|
}
|
|
4846
5132
|
async listTranscriptRegistrations() {
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
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
|
+
}
|
|
4856
5143
|
}
|
|
4857
|
-
|
|
4858
|
-
|
|
5144
|
+
return registrations.sort((left, right) => left.registered_at.localeCompare(right.registered_at));
|
|
5145
|
+
});
|
|
4859
5146
|
}
|
|
4860
5147
|
async readInvocationTurnSelection(hostSourceRef, hostSessionRef) {
|
|
4861
5148
|
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
5149
|
try {
|
|
4864
5150
|
const value = JSON.parse(await readFile(this.turnSelectionPath(hostSourceRef, hostSessionRef), "utf8"));
|
|
4865
5151
|
if (!isHostInvocationTurnSelection(value) || value.host_source_ref !== hostSourceRef || value.host_session_ref !== hostSessionRef) throw new ClaudeHostError("storage", "Claude Host turn selection is malformed.");
|
|
4866
5152
|
return value;
|
|
4867
5153
|
} catch (error) {
|
|
4868
5154
|
if (code(error) === "ENOENT") return null;
|
|
4869
|
-
|
|
5155
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
5156
|
+
throw new ClaudeHostError("storage", "Unable to read the Claude Host turn selection.");
|
|
4870
5157
|
}
|
|
4871
5158
|
}
|
|
4872
5159
|
async readTranscriptCursor(registration) {
|
|
4873
5160
|
validateRegistration(registration);
|
|
4874
|
-
await this.prepare();
|
|
4875
5161
|
try {
|
|
4876
5162
|
const value = JSON.parse(await readFile(this.cursorPath(registration.host_source_ref, registration.host_session_ref), "utf8"));
|
|
4877
5163
|
validateCursor(value);
|
|
4878
5164
|
return value;
|
|
4879
5165
|
} catch (error) {
|
|
4880
5166
|
if (code(error) === "ENOENT") return null;
|
|
4881
|
-
|
|
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";
|
|
4882
5178
|
}
|
|
4883
5179
|
}
|
|
4884
5180
|
async writeTranscriptCursor(cursor) {
|
|
@@ -4905,7 +5201,8 @@ var ClaudeOutboxStore = class {
|
|
|
4905
5201
|
return value;
|
|
4906
5202
|
} catch (error) {
|
|
4907
5203
|
if (code(error) === "ENOENT") return null;
|
|
4908
|
-
|
|
5204
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
5205
|
+
throw new ClaudeHostError("storage", "Claude transcript registration is malformed.");
|
|
4909
5206
|
}
|
|
4910
5207
|
}
|
|
4911
5208
|
async removeStateFile(path) {
|
|
@@ -4929,7 +5226,7 @@ async function readProjectionFile(file) {
|
|
|
4929
5226
|
return context;
|
|
4930
5227
|
} catch (error) {
|
|
4931
5228
|
if (code(error) === "ENOENT") return null;
|
|
4932
|
-
if (error instanceof ClaudeHostError) throw error;
|
|
5229
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
4933
5230
|
throw new ClaudeHostError("storage", "Unable to read the Claude Host invocation context.");
|
|
4934
5231
|
}
|
|
4935
5232
|
}
|
|
@@ -5089,8 +5386,8 @@ function sameKeys2(value, required, optional = []) {
|
|
|
5089
5386
|
}
|
|
5090
5387
|
|
|
5091
5388
|
// host/claude/src/claude-transcript-watcher.ts
|
|
5092
|
-
import { readdir as readdir2 } from "node:fs/promises";
|
|
5093
|
-
import { isDeepStrictEqual } from "node:util";
|
|
5389
|
+
import { readdir as readdir2, stat as stat4 } from "node:fs/promises";
|
|
5390
|
+
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
5094
5391
|
import { join as join5 } from "node:path";
|
|
5095
5392
|
|
|
5096
5393
|
// host/claude/src/claude-subagent-overflow-checkpoint.ts
|
|
@@ -5126,6 +5423,7 @@ var TOKEN_OBSERVATION_SOURCE = "claude_transcript.message.usage";
|
|
|
5126
5423
|
var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
5127
5424
|
store;
|
|
5128
5425
|
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
5426
|
+
prunedRegistrations;
|
|
5129
5427
|
diagnostic;
|
|
5130
5428
|
constructor(options) {
|
|
5131
5429
|
super(options, {
|
|
@@ -5139,9 +5437,21 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5139
5437
|
transcriptPathOf(registration) {
|
|
5140
5438
|
return registration.transcript_path;
|
|
5141
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
|
+
}
|
|
5142
5449
|
async listRegistrations() {
|
|
5143
5450
|
const registrations = await this.store.listTranscriptRegistrations();
|
|
5144
|
-
this.
|
|
5451
|
+
if (registrations !== this.prunedRegistrations) {
|
|
5452
|
+
this.overflow.prune(registrations);
|
|
5453
|
+
this.prunedRegistrations = registrations;
|
|
5454
|
+
}
|
|
5145
5455
|
return registrations;
|
|
5146
5456
|
}
|
|
5147
5457
|
async scanOpened(handle, registration) {
|
|
@@ -5154,13 +5464,14 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5154
5464
|
}
|
|
5155
5465
|
if (preflight.checkpointPending) await this.store.writeTranscriptCursor({ ...cursor, updated_at: this.stamp() });
|
|
5156
5466
|
const draft = mutableCursor(cursor);
|
|
5157
|
-
await this.scanOpenedTranscript(registration, handle, cursor, draft, size, device, inode);
|
|
5158
|
-
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 } : {} };
|
|
5159
5469
|
}
|
|
5160
5470
|
async scanFailed(handle, registration, error) {
|
|
5161
5471
|
this.diagnostic("watcher_scan_failed", claudeTranscriptScanFailureKind(error), claudeTranscriptScanCause(handle, error));
|
|
5162
5472
|
if (handle === void 0 && isSymlinkTranscript(error)) return await this.quarantineUnopened(registration, "transcript_malformed");
|
|
5163
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 };
|
|
5164
5475
|
await this.quarantineFailure(registration, handle);
|
|
5165
5476
|
return { records: 0, enqueued: 0, quarantined: true };
|
|
5166
5477
|
}
|
|
@@ -5197,9 +5508,12 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5197
5508
|
await this.consumeMainChunk(registration, main2, draft);
|
|
5198
5509
|
draft.offset += main2.length;
|
|
5199
5510
|
}
|
|
5200
|
-
|
|
5511
|
+
const mainRetry = main2 !== "empty" && main2 !== "partial" && draft.offset < size;
|
|
5512
|
+
const subagents = await this.consumeSubagents(registration, draft);
|
|
5513
|
+
draft.consumed += subagents.consumed;
|
|
5201
5514
|
await this.emitOpenTerminal(registration, draft);
|
|
5202
5515
|
await this.commitCursor(registration, handle, previous, draft, device, inode);
|
|
5516
|
+
return mainRetry || subagents.retry;
|
|
5203
5517
|
}
|
|
5204
5518
|
async preflight(registration, handle, size, device, inode) {
|
|
5205
5519
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
@@ -5361,13 +5675,15 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5361
5675
|
} catch (error) {
|
|
5362
5676
|
if (isMissingTranscriptError(error) || isNotDirectory(error)) {
|
|
5363
5677
|
this.overflow.clear(registration);
|
|
5364
|
-
return 0;
|
|
5678
|
+
return { consumed: 0, retry: false };
|
|
5365
5679
|
}
|
|
5680
|
+
if (transcriptErrorCode(error) !== null) throw error;
|
|
5366
5681
|
throw new ClaudeHostError("payload_rejected", "Claude subagent transcript directory is unavailable.");
|
|
5367
5682
|
}
|
|
5368
5683
|
const listed = new Set(names);
|
|
5369
5684
|
for (const name of Object.keys(draft.subagents)) if (!listed.has(name)) delete draft.subagents[name];
|
|
5370
|
-
|
|
5685
|
+
const overflow = names.length > CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES;
|
|
5686
|
+
const reported = await this.overflow.observe(registration, names, () => {
|
|
5371
5687
|
const line = `Claude ignored subagent transcripts past its file bound: transcript_path=${JSON.stringify(registration.transcript_path)}, files=${names.length}.`;
|
|
5372
5688
|
try {
|
|
5373
5689
|
this.log(line);
|
|
@@ -5376,12 +5692,15 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5376
5692
|
}
|
|
5377
5693
|
return true;
|
|
5378
5694
|
});
|
|
5695
|
+
let retry = overflow && !reported;
|
|
5379
5696
|
names = names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES);
|
|
5380
5697
|
let consumed = 0;
|
|
5381
5698
|
for (const name of names) {
|
|
5382
|
-
|
|
5699
|
+
const result = await this.consumeSubagentFile(draft, directory, name);
|
|
5700
|
+
consumed += result.consumed;
|
|
5701
|
+
retry ||= result.retry;
|
|
5383
5702
|
}
|
|
5384
|
-
return consumed;
|
|
5703
|
+
return { consumed, retry };
|
|
5385
5704
|
}
|
|
5386
5705
|
async consumeSubagentFile(draft, directory, name) {
|
|
5387
5706
|
const path = join5(directory, name);
|
|
@@ -5394,19 +5713,20 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5394
5713
|
const chunk = await this.readChunk(handle, pinned.offset, size);
|
|
5395
5714
|
if (chunk === "empty" || chunk === "partial") {
|
|
5396
5715
|
draft.subagents[name] = pinned;
|
|
5397
|
-
return 0;
|
|
5716
|
+
return { consumed: 0, retry: false };
|
|
5398
5717
|
}
|
|
5399
5718
|
const consumed = this.consumeSubagentLines(draft, chunk);
|
|
5400
5719
|
const offset = pinned.offset + chunk.length;
|
|
5401
5720
|
const anchor = await this.readAnchor(handle, offset, CLAUDE_TRANSCRIPT_ANCHOR_BYTES);
|
|
5402
5721
|
draft.subagents[name] = { device, inode, offset, anchor_start: anchor.start, anchor_sha256: anchor.sha256 };
|
|
5403
|
-
return consumed;
|
|
5722
|
+
return { consumed, retry: offset < size };
|
|
5404
5723
|
} catch (error) {
|
|
5405
5724
|
if (isMissingTranscriptError(error)) {
|
|
5406
5725
|
delete draft.subagents[name];
|
|
5407
|
-
return 0;
|
|
5726
|
+
return { consumed: 0, retry: false };
|
|
5408
5727
|
}
|
|
5409
|
-
|
|
5728
|
+
if (error instanceof ClaudeHostError || transcriptErrorCode(error) !== null) throw error;
|
|
5729
|
+
throw new ClaudeHostError("payload_rejected", "Claude subagent transcript is unavailable.");
|
|
5410
5730
|
} finally {
|
|
5411
5731
|
await handle?.close();
|
|
5412
5732
|
}
|
|
@@ -5538,7 +5858,7 @@ function mutableCursor(cursor) {
|
|
|
5538
5858
|
};
|
|
5539
5859
|
}
|
|
5540
5860
|
function sameCursorContent(left, right) {
|
|
5541
|
-
return
|
|
5861
|
+
return isDeepStrictEqual2({ ...left, updated_at: void 0 }, { ...right, updated_at: void 0 });
|
|
5542
5862
|
}
|
|
5543
5863
|
function zeroCounts() {
|
|
5544
5864
|
return { input: 0, cached_input: 0, cache_write_input: 0, output: 0 };
|
|
@@ -5631,6 +5951,20 @@ function isAssistantUsageLine(record5) {
|
|
|
5631
5951
|
if (identity === null || !isTranscriptRecord(record5.message.usage)) throw new ClaudeHostError("payload_rejected", "Claude transcript usage line is malformed.");
|
|
5632
5952
|
return true;
|
|
5633
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
|
+
}
|
|
5634
5968
|
function subagentsDirectory(transcriptPath) {
|
|
5635
5969
|
const stem = transcriptPath.endsWith(".jsonl") ? transcriptPath.slice(0, -".jsonl".length) : transcriptPath;
|
|
5636
5970
|
return join5(stem, "subagents");
|
|
@@ -5679,6 +6013,7 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5679
6013
|
usage;
|
|
5680
6014
|
now;
|
|
5681
6015
|
registrations;
|
|
6016
|
+
idleGate;
|
|
5682
6017
|
nextSourceSlot = "main";
|
|
5683
6018
|
nextSubagentIndex = 0;
|
|
5684
6019
|
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
@@ -5687,6 +6022,7 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5687
6022
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
5688
6023
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
5689
6024
|
this.registrations = new HostUsageRegistrationCapture("claude", options.diagnostic_sink);
|
|
6025
|
+
this.idleGate = new HostUsageIdleGate();
|
|
5690
6026
|
}
|
|
5691
6027
|
async captureNext() {
|
|
5692
6028
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
@@ -5711,6 +6047,20 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5711
6047
|
return false;
|
|
5712
6048
|
}
|
|
5713
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) {
|
|
5714
6064
|
const prepared = await openHostUsageTranscriptCursor({
|
|
5715
6065
|
path: registration.transcript_path,
|
|
5716
6066
|
producer: "claude",
|
|
@@ -5739,6 +6089,13 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5739
6089
|
async captureSubagent(registration, onFailure) {
|
|
5740
6090
|
const names = await readSubagentNames(registration);
|
|
5741
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) {
|
|
5742
6099
|
let state = await this.usage.readState("claude", registration.host_source_ref, registration.host_session_ref);
|
|
5743
6100
|
if (state === null) return false;
|
|
5744
6101
|
state = await this.usage.recoverPending(state);
|
|
@@ -5747,6 +6104,24 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5747
6104
|
if (await this.captureListedSubagents(registration, names, state, onFailure)) return true;
|
|
5748
6105
|
return await this.recordExcessSubagentGap(registration, state, names);
|
|
5749
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
|
+
}
|
|
5750
6125
|
async retireMissingSubagent(state, names) {
|
|
5751
6126
|
const liveSlots = new Set(names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES).map(subagentSlot));
|
|
5752
6127
|
for (const [slot, cursor] of Object.entries(state.cursors)) {
|
|
@@ -5977,6 +6352,9 @@ function sourceFileRef(registration, device, inode) {
|
|
|
5977
6352
|
function subagentSlot(name) {
|
|
5978
6353
|
return `subagent:${sha2563(name)}`;
|
|
5979
6354
|
}
|
|
6355
|
+
function claudeUsageIdleKey(registration, slot) {
|
|
6356
|
+
return `${registration.host_source_ref}\0${registration.host_session_ref}\0${slot}`;
|
|
6357
|
+
}
|
|
5980
6358
|
function unscopedGap(reason) {
|
|
5981
6359
|
return { reason, source_file_ref: null, start_offset: null, end_offset: null, omitted_count: null };
|
|
5982
6360
|
}
|
|
@@ -6372,8 +6750,8 @@ function createClaudeProducerWatcher(outboxDir) {
|
|
|
6372
6750
|
diagnostic: (event, failure_kind, cause) => writeHostServiceDiagnostic("claude", event, failure_kind, cause)
|
|
6373
6751
|
});
|
|
6374
6752
|
}
|
|
6375
|
-
async function drainClaudeProducerOnce(options) {
|
|
6376
|
-
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) => {
|
|
6377
6755
|
writeHostServiceDiagnostic("claude", "watcher_scan_failed", claudeTranscriptScanFailureKind(error), claudeTranscriptScanCause(void 0, error));
|
|
6378
6756
|
throw error;
|
|
6379
6757
|
});
|
|
@@ -6388,7 +6766,7 @@ import { join as join9 } from "node:path";
|
|
|
6388
6766
|
// host/producer-service.ts
|
|
6389
6767
|
import { posix as posix4, win32 as win325 } from "node:path";
|
|
6390
6768
|
import { constants as constants7 } from "node:fs";
|
|
6391
|
-
import { lstat as
|
|
6769
|
+
import { lstat as lstat5 } from "node:fs/promises";
|
|
6392
6770
|
var SAFE_REF3 = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
|
|
6393
6771
|
var HOST_PRODUCER_CONFIG_FLAG = "--ceal-host-config";
|
|
6394
6772
|
var HostProducerServiceError = class extends Error {
|
|
@@ -6517,7 +6895,7 @@ function assertProducerAbsolutePath(value, platform, kind, error) {
|
|
|
6517
6895
|
}
|
|
6518
6896
|
async function configPathStat(configPath, error) {
|
|
6519
6897
|
try {
|
|
6520
|
-
return await
|
|
6898
|
+
return await lstat5(configPath);
|
|
6521
6899
|
} catch {
|
|
6522
6900
|
throw error("config_unavailable");
|
|
6523
6901
|
}
|
|
@@ -6709,6 +7087,19 @@ var WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET = "A-Za-z0-9._=-";
|
|
|
6709
7087
|
var WINDOWS_FIXED_CMD_ARGUMENT_REFUSAL_PATTERN = `[^${WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET}]`;
|
|
6710
7088
|
var WINDOWS_FIXED_CMD_ARGUMENT = new RegExp(`^[${WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET}]+$`, "u");
|
|
6711
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
|
+
|
|
6712
7103
|
// host/client-doctor.ts
|
|
6713
7104
|
var execFileAsync = promisify(execFile2);
|
|
6714
7105
|
|