@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
|
@@ -433,7 +433,7 @@ var CEAL_POLICY_DECISIONS = vocabulary(["allowed", "denied", "not_evaluated"]);
|
|
|
433
433
|
var CEAL_CONNECTOR_ROUTE_PHASES = vocabulary(["scope_observation", "target_selection", "route_resolution"]);
|
|
434
434
|
var CEAL_CONNECTOR_ROUTE_CAUSES = vocabulary(["provider_throttled", "provider_unavailable", "binding_invalid", "personal_binding_unproven", "scope_limit_exceeded"]);
|
|
435
435
|
var CEAL_WRITE_SOURCE_KINDS = vocabulary(["authenticated_registered_client", "provider_authenticated_event"]);
|
|
436
|
-
var CEAL_REFRESH_DELIVERIES = vocabulary(["initial", "recovery", "replay", "terminal_failure", "recovery_unavailable", "authority_inactive"]);
|
|
436
|
+
var CEAL_REFRESH_DELIVERIES = vocabulary(["initial", "recovery", "race_recovery", "replay", "terminal_failure", "recovery_unavailable", "authority_inactive"]);
|
|
437
437
|
var CEAL_CLIENT_OPERATIONS = vocabulary(["handshake", "discover", "call", "readback"]);
|
|
438
438
|
var CEAL_WRITE_IDEMPOTENCY_POSTURES = vocabulary(["required", "optional", "not_required"]);
|
|
439
439
|
var CEAL_WRITE_PROVIDER_READBACK_POSTURES = vocabulary(["required", "best_effort", "not_available"]);
|
|
@@ -831,6 +831,7 @@ function requireIsoTimestamp(value, message) {
|
|
|
831
831
|
// packages/ceal-client-protocol/src/failure-guidance-table.ts
|
|
832
832
|
var CEAL_FAILURE_REDACTION_CLASSES = vocabulary(["model_safe", "withheld"]);
|
|
833
833
|
var CEAL_GATEWAY_STARTING_FAILURE_CODE = "gateway_starting";
|
|
834
|
+
var CEAL_GATEWAY_RESTARTING_FAILURE_CODE = "gateway_restarting";
|
|
834
835
|
var CEAL_OWNER_BOOTSTRAP_ABSENT_FAILURE_CODE = "bootstrap_absent";
|
|
835
836
|
var CEAL_OWNER_BOOTSTRAP_UNAVAILABLE_FAILURE_CODE = "bootstrap_unavailable";
|
|
836
837
|
var LOCAL_COMMAND_INVALID = "The local command or argument is invalid.";
|
|
@@ -841,6 +842,7 @@ var CEAL_CLIENT_UPGRADE_COMMAND = "npm install -g @corca-org/ceal";
|
|
|
841
842
|
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}\`.`;
|
|
842
843
|
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.";
|
|
843
844
|
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.";
|
|
845
|
+
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.";
|
|
844
846
|
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.";
|
|
845
847
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
846
848
|
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
@@ -895,6 +897,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
895
897
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
896
898
|
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
897
899
|
[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),
|
|
900
|
+
// The serving gate answers before execution while the Gateway is stopping, so retrying the same request is safe.
|
|
901
|
+
[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),
|
|
898
902
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
899
903
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
900
904
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
@@ -1002,6 +1006,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1002
1006
|
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),
|
|
1003
1007
|
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),
|
|
1004
1008
|
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),
|
|
1009
|
+
host_transcript_unavailable: guidance(HOST_TRANSCRIPT_UNAVAILABLE, "retry", 401, true),
|
|
1005
1010
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
1006
1011
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
1007
1012
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
@@ -1390,6 +1395,8 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
1390
1395
|
});
|
|
1391
1396
|
|
|
1392
1397
|
// packages/ceal-client-protocol/src/canonical-http-boundary.ts
|
|
1398
|
+
var CEAL_HTTP_CLIENT_EXCHANGE_REF_PATTERN_SOURCE = "^client-exchange:[a-f0-9]{32}$";
|
|
1399
|
+
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}$";
|
|
1393
1400
|
var CEAL_CANONICAL_HTTP_MAX_RESPONSE_BYTES = CEAL_COMMAND_RESPONSE_MAX_BYTES;
|
|
1394
1401
|
|
|
1395
1402
|
// packages/ceal-client-protocol/src/gateway-installation-activation.ts
|
|
@@ -1414,6 +1421,7 @@ var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUI
|
|
|
1414
1421
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
1415
1422
|
|
|
1416
1423
|
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1424
|
+
var CEAL_RESOURCE_GET_CHILD_REF_KINDS = Object.freeze(["section", "slide", "question"]);
|
|
1417
1425
|
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
1418
1426
|
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
1419
1427
|
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
@@ -1617,6 +1625,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1617
1625
|
"github.review.submitted",
|
|
1618
1626
|
"github.issue_comment.created",
|
|
1619
1627
|
"github.review_comment.created",
|
|
1628
|
+
"github.issue_comment.edited",
|
|
1629
|
+
"github.review_comment.edited",
|
|
1620
1630
|
"github.reaction.created",
|
|
1621
1631
|
"github.reaction.deleted",
|
|
1622
1632
|
"github.pull_request.review_requested",
|
|
@@ -1645,6 +1655,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1645
1655
|
"github.release.published": "release_published",
|
|
1646
1656
|
"github.issue.edited": "resource_modified",
|
|
1647
1657
|
"github.pull_request.edited": "resource_modified",
|
|
1658
|
+
"github.issue_comment.edited": "resource_modified",
|
|
1659
|
+
"github.review_comment.edited": "resource_modified",
|
|
1648
1660
|
"github.reaction.created": "reaction_created",
|
|
1649
1661
|
"github.reaction.deleted": "ceal_write_completed",
|
|
1650
1662
|
"github.pull_request.review_requested": "ceal_write_completed",
|
|
@@ -2307,6 +2319,8 @@ var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_MESSAGES = 32;
|
|
|
2307
2319
|
var HOST_CONTEXT_EXPIRY_MAX_CHARS = 64;
|
|
2308
2320
|
var CEAL_HOST_INVOCATION_CONTEXT_VISIBLE_OUTPUT_MAX_BYTES = CEAL_CANONICAL_HTTP_MAX_RESPONSE_BYTES;
|
|
2309
2321
|
var CEAL_HOST_CONTEXT_TOKEN_PREFIX = "ceal_context_";
|
|
2322
|
+
var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_ENTRY_KEYS = vocabulary(["host_turn_ref", "host_input_ref", "text", "text_truncated"]);
|
|
2323
|
+
var CEAL_HOST_INVOCATION_HUMAN_MESSAGE_REQUIRED_KEYS = vocabulary(["host_turn_ref", "host_input_ref", "text"]);
|
|
2310
2324
|
function boundCealHostInvocationHumanMessageWindow(newestFirst, sourceTruncated = false) {
|
|
2311
2325
|
const messages = [];
|
|
2312
2326
|
let truncated = sourceTruncated || newestFirst.length > CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_MESSAGES;
|
|
@@ -2438,6 +2452,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
2438
2452
|
"context_replaced",
|
|
2439
2453
|
"no_binding",
|
|
2440
2454
|
"context_expired",
|
|
2455
|
+
"transcript_unavailable",
|
|
2441
2456
|
"host_source_refused",
|
|
2442
2457
|
"host_credential_refused",
|
|
2443
2458
|
"gateway_unavailable",
|
|
@@ -2479,6 +2494,11 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2479
2494
|
// useful retry until the consumer is running inside a Host session.
|
|
2480
2495
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2481
2496
|
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
2497
|
+
// The registered transcript is readable but names no human message for
|
|
2498
|
+
// this turn, so a Gateway mint could only be refused. The caller sends a
|
|
2499
|
+
// new message so the turn hook re-registers the transcript, then retries;
|
|
2500
|
+
// a retry with no new turn cannot bind anything new.
|
|
2501
|
+
transcript_unavailable: Object.freeze({ classification: "host_transcript_unavailable", next_action: "retry" }),
|
|
2482
2502
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
2483
2503
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
2484
2504
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
@@ -2615,11 +2635,15 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
2615
2635
|
|
|
2616
2636
|
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
2617
2637
|
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
2618
|
-
var
|
|
2638
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSE_NODES = 8;
|
|
2619
2639
|
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
2620
2640
|
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
2621
2641
|
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
2622
2642
|
var OPERATOR_DIAGNOSTIC_HOME_PATHS = machineHomePathPatterns("gu");
|
|
2643
|
+
var LOCAL_OPERATOR_DIAGNOSTIC_PATHS = /* @__PURE__ */ Symbol.for("ceal.local-operator-diagnostic-paths");
|
|
2644
|
+
var OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_PREFIX = /(?:[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/)/u;
|
|
2645
|
+
var OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_START = new RegExp(`^${OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_PREFIX.source}`, "u");
|
|
2646
|
+
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");
|
|
2623
2647
|
function redactOperatorDiagnosticSecrets(value) {
|
|
2624
2648
|
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]");
|
|
2625
2649
|
}
|
|
@@ -2628,8 +2652,9 @@ function redactOperatorDiagnosticText(value) {
|
|
|
2628
2652
|
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
2629
2653
|
}
|
|
2630
2654
|
function renderOperatorDiagnostic(value) {
|
|
2631
|
-
const state = collectDiagnosticState(value);
|
|
2655
|
+
const state = collectDiagnosticState(value, read(value, LOCAL_OPERATOR_DIAGNOSTIC_PATHS) === true);
|
|
2632
2656
|
const fields = [
|
|
2657
|
+
state.truncated ? "causes_truncated=true" : void 0,
|
|
2633
2658
|
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
2634
2659
|
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
2635
2660
|
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
@@ -2639,23 +2664,27 @@ function renderOperatorDiagnostic(value) {
|
|
|
2639
2664
|
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
2640
2665
|
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
2641
2666
|
}
|
|
2642
|
-
function collectDiagnosticState(value) {
|
|
2643
|
-
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0 };
|
|
2667
|
+
function collectDiagnosticState(value, preserveLocalAbsolutePaths) {
|
|
2668
|
+
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0, truncated: false };
|
|
2644
2669
|
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
2645
|
-
|
|
2670
|
+
let inspected = 0;
|
|
2671
|
+
while (pending.length > 0 && inspected < OPERATOR_DIAGNOSTIC_MAX_CAUSE_NODES) {
|
|
2646
2672
|
const current = pending.shift();
|
|
2647
|
-
if (current
|
|
2673
|
+
if (current === void 0 || isObject(current) && visited.has(current)) continue;
|
|
2674
|
+
inspected += 1;
|
|
2675
|
+
visitDiagnosticNode(current, state, pending, visited, preserveLocalAbsolutePaths);
|
|
2648
2676
|
}
|
|
2677
|
+
state.truncated ||= pending.length > 0;
|
|
2649
2678
|
return state;
|
|
2650
2679
|
}
|
|
2651
|
-
function visitDiagnosticNode(current, state, pending, visited) {
|
|
2680
|
+
function visitDiagnosticNode(current, state, pending, visited, preserveLocalAbsolutePaths) {
|
|
2652
2681
|
if (isObject(current)) {
|
|
2653
2682
|
if (visited.has(current)) return;
|
|
2654
2683
|
visited.add(current);
|
|
2655
2684
|
}
|
|
2656
2685
|
captureProcessEvidence(current, state);
|
|
2657
|
-
appendCause(current, state.causes);
|
|
2658
|
-
enqueueCauseChildren(current, state
|
|
2686
|
+
appendCause(current, state.causes, preserveLocalAbsolutePaths);
|
|
2687
|
+
enqueueCauseChildren(current, state, pending);
|
|
2659
2688
|
}
|
|
2660
2689
|
function captureProcessEvidence(current, state) {
|
|
2661
2690
|
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
@@ -2663,10 +2692,9 @@ function captureProcessEvidence(current, state) {
|
|
|
2663
2692
|
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
2664
2693
|
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
2665
2694
|
}
|
|
2666
|
-
function appendCause(current, causes) {
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
causes.push(errorCause(current));
|
|
2695
|
+
function appendCause(current, causes, preserveLocalAbsolutePaths) {
|
|
2696
|
+
if (current instanceof Error) {
|
|
2697
|
+
causes.push(errorCause(current, preserveLocalAbsolutePaths));
|
|
2670
2698
|
return;
|
|
2671
2699
|
}
|
|
2672
2700
|
if (!isObject(current)) {
|
|
@@ -2674,7 +2702,7 @@ function appendCause(current, causes) {
|
|
|
2674
2702
|
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
2675
2703
|
}
|
|
2676
2704
|
}
|
|
2677
|
-
function errorCause(error) {
|
|
2705
|
+
function errorCause(error, preserveLocalAbsolutePaths) {
|
|
2678
2706
|
const name = safeText(read(error, "name")) ?? "Error";
|
|
2679
2707
|
const message = safeText(read(error, "message"));
|
|
2680
2708
|
const codeValue = read(error, "code");
|
|
@@ -2682,14 +2710,29 @@ function errorCause(error) {
|
|
|
2682
2710
|
const errnoValue = read(error, "errno");
|
|
2683
2711
|
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
2684
2712
|
const syscall = safeText(read(error, "syscall"));
|
|
2685
|
-
const path = safePath(read(error, "path"));
|
|
2713
|
+
const path = safePath(read(error, "path"), preserveLocalAbsolutePaths);
|
|
2686
2714
|
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 } });
|
|
2687
2715
|
}
|
|
2688
|
-
function enqueueCauseChildren(current,
|
|
2716
|
+
function enqueueCauseChildren(current, state, pending) {
|
|
2689
2717
|
const cause = read(current, "cause");
|
|
2690
2718
|
if (cause !== void 0) pending.push(cause);
|
|
2691
2719
|
const errors = read(current, "errors");
|
|
2692
|
-
if (Array.isArray(errors))
|
|
2720
|
+
if (Array.isArray(errors)) {
|
|
2721
|
+
const remaining = OPERATOR_DIAGNOSTIC_MAX_CAUSE_NODES - state.causes.length;
|
|
2722
|
+
const length = read(errors, "length");
|
|
2723
|
+
if (typeof length !== "number") {
|
|
2724
|
+
state.truncated = true;
|
|
2725
|
+
return;
|
|
2726
|
+
}
|
|
2727
|
+
state.truncated ||= length > remaining;
|
|
2728
|
+
for (let index = 0; index < Math.min(length, remaining); index += 1) {
|
|
2729
|
+
try {
|
|
2730
|
+
pending.push(errors[index]);
|
|
2731
|
+
} catch {
|
|
2732
|
+
state.truncated = true;
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2693
2736
|
}
|
|
2694
2737
|
function isObject(value) {
|
|
2695
2738
|
return typeof value === "object" && value !== null;
|
|
@@ -2718,10 +2761,11 @@ function safeText(value) {
|
|
|
2718
2761
|
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
2719
2762
|
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2720
2763
|
}
|
|
2721
|
-
function safePath(value) {
|
|
2764
|
+
function safePath(value, preserveLocalAbsolutePaths) {
|
|
2722
2765
|
if (typeof value !== "string") return void 0;
|
|
2723
2766
|
const safe = safeDiagnosticText(value);
|
|
2724
2767
|
if (safe.length === 0) return void 0;
|
|
2768
|
+
if (!preserveLocalAbsolutePaths && hasAbsolutePathPrefix(value) && !safe.startsWith("[home path redacted]")) return "[path redacted]";
|
|
2725
2769
|
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
2726
2770
|
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
2727
2771
|
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
@@ -2793,7 +2837,10 @@ function redactUrls(value) {
|
|
|
2793
2837
|
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
2794
2838
|
}
|
|
2795
2839
|
function redactFilePaths(value) {
|
|
2796
|
-
return value.replaceAll(
|
|
2840
|
+
return value.replaceAll(OPERATOR_DIAGNOSTIC_FREEFORM_PATH_PATTERN, "[path redacted]$2");
|
|
2841
|
+
}
|
|
2842
|
+
function hasAbsolutePathPrefix(value) {
|
|
2843
|
+
return OPERATOR_DIAGNOSTIC_ABSOLUTE_PATH_START.test(value);
|
|
2797
2844
|
}
|
|
2798
2845
|
function homePathRange(value, match, prefixLength) {
|
|
2799
2846
|
const index = match.index;
|
|
@@ -2973,104 +3020,24 @@ function hostClientProbeRefusal(probe, subject) {
|
|
|
2973
3020
|
|
|
2974
3021
|
// host/invocation-authentication-command.ts
|
|
2975
3022
|
import { createHash as createHash7 } from "node:crypto";
|
|
2976
|
-
import { performance } from "node:perf_hooks";
|
|
3023
|
+
import { performance as performance2 } from "node:perf_hooks";
|
|
2977
3024
|
|
|
2978
3025
|
// host/relay/src/producer-frame.ts
|
|
2979
3026
|
var HOST_PRODUCER_FRAME_LENGTH_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
2980
3027
|
var HOST_PRODUCER_FRAME_KINDS = ["session_started", "turn_started", "turn_terminal", "producer_status"];
|
|
2981
3028
|
var FRAME_KINDS = new Set(HOST_PRODUCER_FRAME_KINDS);
|
|
2982
|
-
var HOST_PRODUCER_FRAME_ERROR_CODES = [
|
|
2983
|
-
"invalid_frame_encoding",
|
|
2984
|
-
"invalid_frame_length",
|
|
2985
|
-
"frame_truncated",
|
|
2986
|
-
"unsupported_frame_schema",
|
|
2987
|
-
"invalid_frame_shape",
|
|
2988
|
-
"invalid_producer_identity",
|
|
2989
|
-
"frame_too_large"
|
|
2990
|
-
];
|
|
2991
3029
|
|
|
2992
3030
|
// host/relay/src/host-producer-core.ts
|
|
2993
3031
|
import { createHash as createHash4 } from "node:crypto";
|
|
2994
|
-
import {
|
|
3032
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3033
|
+
import { lstat as lstat2, readdir, stat as stat2 } from "node:fs/promises";
|
|
2995
3034
|
|
|
2996
3035
|
// host/secure-file.ts
|
|
2997
3036
|
import { execFile } from "node:child_process";
|
|
2998
3037
|
import { constants } from "node:fs";
|
|
2999
3038
|
import { lstat, open } from "node:fs/promises";
|
|
3000
|
-
import { dirname, join as
|
|
3039
|
+
import { dirname, join as join2, parse, win32 } from "node:path";
|
|
3001
3040
|
import { fileURLToPath } from "node:url";
|
|
3002
|
-
|
|
3003
|
-
// host/spawn-working-directory.ts
|
|
3004
|
-
import { mkdirSync } from "node:fs";
|
|
3005
|
-
import { tmpdir } from "node:os";
|
|
3006
|
-
import { isAbsolute, join as join2, normalize, parse, sep } from "node:path";
|
|
3007
|
-
function resolveCealSpawnWorkingDirectory(stateRoot, keepOutside = []) {
|
|
3008
|
-
const candidates = [];
|
|
3009
|
-
const explicit = candidateDir(stateRoot);
|
|
3010
|
-
if (explicit !== void 0) candidates.push(explicit);
|
|
3011
|
-
const fallback = defaultHostStateRoot();
|
|
3012
|
-
if (fallback !== void 0 && !candidates.some((candidate) => sameDir(candidate, fallback))) candidates.push(fallback);
|
|
3013
|
-
const temporary = candidateDir(join2(tmpdir(), "ceal-spawn-cwd"));
|
|
3014
|
-
if (temporary !== void 0 && !candidates.some((candidate) => sameDir(candidate, temporary))) candidates.push(temporary);
|
|
3015
|
-
for (const dir of candidates) {
|
|
3016
|
-
if (!keptOutside(dir, keepOutside)) continue;
|
|
3017
|
-
try {
|
|
3018
|
-
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
3019
|
-
return dir;
|
|
3020
|
-
} catch {
|
|
3021
|
-
continue;
|
|
3022
|
-
}
|
|
3023
|
-
}
|
|
3024
|
-
return tmpdir();
|
|
3025
|
-
}
|
|
3026
|
-
function candidateDir(dir) {
|
|
3027
|
-
if (dir === void 0 || dir === "") return void 0;
|
|
3028
|
-
if (!isAbsolute(dir) || normalize(dir) !== dir || parse(dir).root === dir) return void 0;
|
|
3029
|
-
return normalize(dir);
|
|
3030
|
-
}
|
|
3031
|
-
function defaultHostStateRoot() {
|
|
3032
|
-
if (process.platform === "win32") {
|
|
3033
|
-
const localAppData = nonEmptyEnv("LOCALAPPDATA");
|
|
3034
|
-
if (localAppData === void 0) return void 0;
|
|
3035
|
-
return candidateDir(join2(localAppData, "Ceal", "Host"));
|
|
3036
|
-
}
|
|
3037
|
-
if (process.platform === "darwin") {
|
|
3038
|
-
const home2 = nonEmptyEnv("HOME");
|
|
3039
|
-
if (home2 === void 0) return void 0;
|
|
3040
|
-
return candidateDir(join2(home2, "Library", "Application Support", "Ceal", "Host"));
|
|
3041
|
-
}
|
|
3042
|
-
const xdg = nonEmptyEnv("XDG_STATE_HOME");
|
|
3043
|
-
if (xdg !== void 0) {
|
|
3044
|
-
const root = candidateDir(join2(xdg, "ceal", "host"));
|
|
3045
|
-
if (root !== void 0) return root;
|
|
3046
|
-
}
|
|
3047
|
-
const home = nonEmptyEnv("HOME");
|
|
3048
|
-
if (home === void 0) return void 0;
|
|
3049
|
-
return candidateDir(join2(home, ".local", "state", "ceal", "host"));
|
|
3050
|
-
}
|
|
3051
|
-
function nonEmptyEnv(name) {
|
|
3052
|
-
const value = process.env[name];
|
|
3053
|
-
return value === void 0 || value === "" ? void 0 : value;
|
|
3054
|
-
}
|
|
3055
|
-
function keptOutside(dir, keepOutside) {
|
|
3056
|
-
for (const tree of keepOutside) {
|
|
3057
|
-
const clean = candidateDir(tree);
|
|
3058
|
-
if (clean === void 0) continue;
|
|
3059
|
-
if (insideDir(dir, clean)) return false;
|
|
3060
|
-
}
|
|
3061
|
-
return true;
|
|
3062
|
-
}
|
|
3063
|
-
function insideDir(dir, tree) {
|
|
3064
|
-
if (sameDir(dir, tree)) return true;
|
|
3065
|
-
if (process.platform === "win32") return dir.toLowerCase().startsWith(tree.toLowerCase() + sep);
|
|
3066
|
-
return dir.startsWith(tree + sep);
|
|
3067
|
-
}
|
|
3068
|
-
function sameDir(left, right) {
|
|
3069
|
-
if (process.platform === "win32") return left.toLowerCase() === right.toLowerCase();
|
|
3070
|
-
return left === right;
|
|
3071
|
-
}
|
|
3072
|
-
|
|
3073
|
-
// host/secure-file.ts
|
|
3074
3041
|
var SecureFileCustodyError = class extends Error {
|
|
3075
3042
|
name = "SecureFileCustodyError";
|
|
3076
3043
|
reason;
|
|
@@ -3178,7 +3145,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
3178
3145
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
3179
3146
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
3180
3147
|
return await new Promise((resolve, reject) => {
|
|
3181
|
-
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES, cwd:
|
|
3148
|
+
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) => {
|
|
3182
3149
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
3183
3150
|
if (exitCode === null) {
|
|
3184
3151
|
reject(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -3207,7 +3174,7 @@ function securefsRefusal(stderr) {
|
|
|
3207
3174
|
}
|
|
3208
3175
|
function resolveInstalledHostExecutable(platform) {
|
|
3209
3176
|
const privateRuntimeRoot = dirname(fileURLToPath(import.meta.url));
|
|
3210
|
-
return platform === "win32" ? win32.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") :
|
|
3177
|
+
return platform === "win32" ? win32.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") : join2(privateRuntimeRoot, "..", "..", "bin", "ceal-host");
|
|
3211
3178
|
}
|
|
3212
3179
|
function isRecord(value) {
|
|
3213
3180
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -3231,7 +3198,7 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
3231
3198
|
|
|
3232
3199
|
// host/service-log.ts
|
|
3233
3200
|
import { copyFile, mkdir, stat, truncate, appendFile } from "node:fs/promises";
|
|
3234
|
-
import { dirname as dirname2, isAbsolute
|
|
3201
|
+
import { dirname as dirname2, isAbsolute, posix, win32 as win322 } from "node:path";
|
|
3235
3202
|
|
|
3236
3203
|
// host/service-log-delivery.ts
|
|
3237
3204
|
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
@@ -3390,7 +3357,7 @@ async function persistHostServiceLogLine(line, environment = process.env) {
|
|
|
3390
3357
|
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
3391
3358
|
}
|
|
3392
3359
|
async function appendHostServiceLogLine(path, line) {
|
|
3393
|
-
if (!
|
|
3360
|
+
if (!isAbsolute(path)) return;
|
|
3394
3361
|
await ensureHostServiceLogDirectory(path);
|
|
3395
3362
|
await appendFile(path, line);
|
|
3396
3363
|
}
|
|
@@ -3429,7 +3396,9 @@ function mergeHostInvocationHumanMessageWindow(existing, chronological) {
|
|
|
3429
3396
|
seen.add(message.host_input_ref);
|
|
3430
3397
|
newestFirst.push(message);
|
|
3431
3398
|
}
|
|
3432
|
-
|
|
3399
|
+
const currentTurn = newestFirst[0]?.host_turn_ref;
|
|
3400
|
+
const currentTurnFirst = currentTurn === void 0 ? newestFirst : newestFirst.filter((message) => message.host_turn_ref === currentTurn);
|
|
3401
|
+
return boundCealHostInvocationHumanMessageWindow(currentTurnFirst, existing?.truncated ?? false);
|
|
3433
3402
|
}
|
|
3434
3403
|
async function readRegisteredHostInvocationHumanMessageWindow(readRegistration, readCursor, identity, decodeLine) {
|
|
3435
3404
|
try {
|
|
@@ -3543,6 +3512,15 @@ async function transcriptCursorBoundsReason(handle, cursor, size) {
|
|
|
3543
3512
|
if (cursor.offset > 0 && !await transcriptAnchorMatches(handle, cursor)) return "transcript_rewritten";
|
|
3544
3513
|
return null;
|
|
3545
3514
|
}
|
|
3515
|
+
async function statObservedPathSignature(path) {
|
|
3516
|
+
try {
|
|
3517
|
+
const info = await lstat2(path, { bigint: true });
|
|
3518
|
+
if (info.isSymbolicLink() || !info.isFile() && !info.isDirectory()) return null;
|
|
3519
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
3520
|
+
} catch {
|
|
3521
|
+
return null;
|
|
3522
|
+
}
|
|
3523
|
+
}
|
|
3546
3524
|
function transcriptSha256(value) {
|
|
3547
3525
|
return createHash4("sha256").update(value).digest("hex");
|
|
3548
3526
|
}
|
|
@@ -3575,27 +3553,71 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
3575
3553
|
producerInstallationRef: options.producer_installation_ref
|
|
3576
3554
|
};
|
|
3577
3555
|
}
|
|
3578
|
-
async function scanTranscriptRegistrations(registrations, scanOne) {
|
|
3556
|
+
async function scanTranscriptRegistrations(registrations, scanOne, totalRegistrations, signal) {
|
|
3579
3557
|
let records = 0;
|
|
3580
3558
|
let enqueued = 0;
|
|
3581
3559
|
let quarantined = 0;
|
|
3560
|
+
let scanned = 0;
|
|
3582
3561
|
for (const registration of registrations) {
|
|
3562
|
+
if (signal?.aborted) break;
|
|
3563
|
+
scanned += 1;
|
|
3583
3564
|
const result = await scanOne(registration);
|
|
3584
3565
|
records += result.records;
|
|
3585
3566
|
enqueued += result.enqueued;
|
|
3586
3567
|
if (result.quarantined) quarantined += 1;
|
|
3587
3568
|
}
|
|
3588
|
-
return { registrations:
|
|
3569
|
+
return { registrations: totalRegistrations ?? scanned, records, enqueued, quarantined };
|
|
3570
|
+
}
|
|
3571
|
+
var HOST_REGISTRATION_DIRECTORY_RACY_WINDOW_NS = 1000000000n;
|
|
3572
|
+
var HostRegistrationInventory = class {
|
|
3573
|
+
signature;
|
|
3574
|
+
registrations;
|
|
3575
|
+
nowNs;
|
|
3576
|
+
observeDirectory;
|
|
3577
|
+
constructor(options = {}) {
|
|
3578
|
+
this.nowNs = options.nowNs ?? (() => BigInt(Date.now()) * 1000000n);
|
|
3579
|
+
this.observeDirectory = options.observeDirectory ?? hostRegistrationDirectorySignature;
|
|
3580
|
+
}
|
|
3581
|
+
async read(directory, load) {
|
|
3582
|
+
const observation = await this.observeDirectory(directory);
|
|
3583
|
+
const nowNs = this.nowNs();
|
|
3584
|
+
const racy = nowNs - observation.mtimeNs <= HOST_REGISTRATION_DIRECTORY_RACY_WINDOW_NS || nowNs - observation.ctimeNs <= HOST_REGISTRATION_DIRECTORY_RACY_WINDOW_NS;
|
|
3585
|
+
if (this.registrations !== void 0 && this.signature === observation.signature && !racy) return this.registrations;
|
|
3586
|
+
const registrations = await load();
|
|
3587
|
+
this.signature = observation.signature;
|
|
3588
|
+
this.registrations = registrations;
|
|
3589
|
+
return registrations;
|
|
3590
|
+
}
|
|
3591
|
+
};
|
|
3592
|
+
async function hostRegistrationDirectorySignature(directory) {
|
|
3593
|
+
try {
|
|
3594
|
+
const info = await stat2(directory, { bigint: true });
|
|
3595
|
+
return {
|
|
3596
|
+
signature: `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`,
|
|
3597
|
+
mtimeNs: info.mtimeNs,
|
|
3598
|
+
ctimeNs: info.ctimeNs
|
|
3599
|
+
};
|
|
3600
|
+
} catch (error) {
|
|
3601
|
+
if (isMissingTranscriptError(error)) return { signature: "missing", mtimeNs: 0n, ctimeNs: 0n };
|
|
3602
|
+
throw error;
|
|
3603
|
+
}
|
|
3589
3604
|
}
|
|
3590
3605
|
function formatRetiredTranscriptLog(producerLabel, transcriptPath) {
|
|
3591
3606
|
return `${producerLabel} retired a transcript registration: transcript_path=${JSON.stringify(transcriptPath)}, reason=${TRANSCRIPT_MISSING_REASON}.`;
|
|
3592
3607
|
}
|
|
3608
|
+
var HOST_TRANSCRIPT_RECONCILIATION_BATCH = 100;
|
|
3593
3609
|
var HostTranscriptWatcher = class {
|
|
3594
3610
|
outboxRetentionMs;
|
|
3595
3611
|
now;
|
|
3596
3612
|
log;
|
|
3597
3613
|
producerInstallationRef;
|
|
3598
3614
|
clockFailure;
|
|
3615
|
+
transcriptObservations = /* @__PURE__ */ new Map();
|
|
3616
|
+
registrationSnapshot;
|
|
3617
|
+
// Advisory scheduling only: listRegistrations remains the registration authority.
|
|
3618
|
+
hotRegistrations = /* @__PURE__ */ new Set();
|
|
3619
|
+
reconciliation;
|
|
3620
|
+
reconciliationRemaining = 0;
|
|
3599
3621
|
constructor(options, owner) {
|
|
3600
3622
|
const base = createTranscriptWatcherBase(options, owner);
|
|
3601
3623
|
this.outboxRetentionMs = base.outboxRetentionMs;
|
|
@@ -3604,8 +3626,97 @@ var HostTranscriptWatcher = class {
|
|
|
3604
3626
|
this.producerInstallationRef = base.producerInstallationRef;
|
|
3605
3627
|
this.clockFailure = owner.clock_failure;
|
|
3606
3628
|
}
|
|
3607
|
-
async scanOnce() {
|
|
3608
|
-
|
|
3629
|
+
async scanOnce(signal) {
|
|
3630
|
+
if (signal?.aborted) return { registrations: this.registrationSnapshot?.length ?? 0, records: 0, enqueued: 0, quarantined: 0 };
|
|
3631
|
+
const registrations = await this.listRegistrations();
|
|
3632
|
+
this.reconcileSnapshot(registrations);
|
|
3633
|
+
return scanTranscriptRegistrations(this.scanCandidates(), (observation) => this.observeRegistration(observation, signal), registrations.length, signal);
|
|
3634
|
+
}
|
|
3635
|
+
async observeRegistration(observation, signal) {
|
|
3636
|
+
const registration = observation.registration;
|
|
3637
|
+
const signature = await this.scanFingerprint(registration);
|
|
3638
|
+
if (signal?.aborted) return { records: 0, enqueued: 0, quarantined: false };
|
|
3639
|
+
this.hotRegistrations.delete(observation);
|
|
3640
|
+
if (signature !== null && observation.signature === signature) return { records: 0, enqueued: 0, quarantined: false };
|
|
3641
|
+
this.hotRegistrations.add(observation);
|
|
3642
|
+
const result = await this.scanRegistration(registration);
|
|
3643
|
+
if (result.quarantined || result.retry === true) observation.signature = void 0;
|
|
3644
|
+
else {
|
|
3645
|
+
observation.signature = signature ?? void 0;
|
|
3646
|
+
if (result.records === 0) this.hotRegistrations.delete(observation);
|
|
3647
|
+
}
|
|
3648
|
+
return result;
|
|
3649
|
+
}
|
|
3650
|
+
*scanCandidates() {
|
|
3651
|
+
const hotSlice = [];
|
|
3652
|
+
for (const observation of this.hotRegistrations) {
|
|
3653
|
+
hotSlice.push(observation);
|
|
3654
|
+
if (hotSlice.length === HOST_TRANSCRIPT_RECONCILIATION_BATCH) break;
|
|
3655
|
+
}
|
|
3656
|
+
const observed = /* @__PURE__ */ new Set();
|
|
3657
|
+
for (let count = 0; count < Math.min(this.transcriptObservations.size, HOST_TRANSCRIPT_RECONCILIATION_BATCH); count += 1) {
|
|
3658
|
+
const observation = this.nextReconciliation();
|
|
3659
|
+
if (observation === void 0) break;
|
|
3660
|
+
observed.add(observation);
|
|
3661
|
+
yield observation;
|
|
3662
|
+
}
|
|
3663
|
+
for (const observation of hotSlice) if (!observed.has(observation)) yield observation;
|
|
3664
|
+
}
|
|
3665
|
+
nextReconciliation() {
|
|
3666
|
+
if (this.reconciliationRemaining === 0 || this.reconciliation === void 0) {
|
|
3667
|
+
this.reconciliation = this.transcriptObservations.values();
|
|
3668
|
+
this.reconciliationRemaining = this.transcriptObservations.size;
|
|
3669
|
+
}
|
|
3670
|
+
let next = this.reconciliation.next();
|
|
3671
|
+
if (next.done) {
|
|
3672
|
+
this.reconciliation = this.transcriptObservations.values();
|
|
3673
|
+
this.reconciliationRemaining = this.transcriptObservations.size;
|
|
3674
|
+
next = this.reconciliation.next();
|
|
3675
|
+
}
|
|
3676
|
+
this.reconciliationRemaining -= 1;
|
|
3677
|
+
return next.value;
|
|
3678
|
+
}
|
|
3679
|
+
reconcileSnapshot(registrations) {
|
|
3680
|
+
if (this.registrationSnapshot === registrations) return;
|
|
3681
|
+
const retained = /* @__PURE__ */ new Set();
|
|
3682
|
+
const hot = /* @__PURE__ */ new Set();
|
|
3683
|
+
for (const registration of registrations) {
|
|
3684
|
+
const key = this.registrationKey(registration);
|
|
3685
|
+
retained.add(key);
|
|
3686
|
+
let observation = this.transcriptObservations.get(key);
|
|
3687
|
+
if (observation === void 0) {
|
|
3688
|
+
observation = { registration, signature: void 0 };
|
|
3689
|
+
this.transcriptObservations.set(key, observation);
|
|
3690
|
+
hot.add(observation);
|
|
3691
|
+
} else {
|
|
3692
|
+
if (!isDeepStrictEqual(observation.registration, registration)) {
|
|
3693
|
+
observation.signature = void 0;
|
|
3694
|
+
hot.add(observation);
|
|
3695
|
+
}
|
|
3696
|
+
observation.registration = registration;
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
for (const [key, observation] of this.transcriptObservations) {
|
|
3700
|
+
if (!retained.has(key)) {
|
|
3701
|
+
this.transcriptObservations.delete(key);
|
|
3702
|
+
this.hotRegistrations.delete(observation);
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
for (const observation of this.hotRegistrations) hot.add(observation);
|
|
3706
|
+
this.hotRegistrations = hot;
|
|
3707
|
+
this.registrationSnapshot = registrations;
|
|
3708
|
+
}
|
|
3709
|
+
async scanFingerprint(registration) {
|
|
3710
|
+
return this.transcriptSignature(registration);
|
|
3711
|
+
}
|
|
3712
|
+
async transcriptSignature(registration) {
|
|
3713
|
+
try {
|
|
3714
|
+
const info = await lstat2(this.transcriptPathOf(registration), { bigint: true });
|
|
3715
|
+
if (!info.isFile() || info.isSymbolicLink()) return null;
|
|
3716
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}:${info.mode}:${info.uid}`;
|
|
3717
|
+
} catch {
|
|
3718
|
+
return null;
|
|
3719
|
+
}
|
|
3609
3720
|
}
|
|
3610
3721
|
async scanRegistration(registration) {
|
|
3611
3722
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
@@ -3706,7 +3817,7 @@ var HostProducerDrainCore = class {
|
|
|
3706
3817
|
};
|
|
3707
3818
|
|
|
3708
3819
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3709
|
-
import { lstat as
|
|
3820
|
+
import { lstat as lstat3, mkdir as mkdir2, open as open2, rename, unlink } from "node:fs/promises";
|
|
3710
3821
|
import { dirname as dirname3 } from "node:path";
|
|
3711
3822
|
|
|
3712
3823
|
// host/windows-rename-retry.ts
|
|
@@ -3728,7 +3839,7 @@ function resolveRetrySchedule(tuning) {
|
|
|
3728
3839
|
startDelayMs: tuning.startDelayMs ?? RETRY_START_DELAY_MS,
|
|
3729
3840
|
maxDelayMs: tuning.maxDelayMs ?? RETRY_MAX_DELAY_MS,
|
|
3730
3841
|
sleep: tuning.sleep ?? ((ms) => setTimeout2(ms)),
|
|
3731
|
-
now: tuning.now ?? (() =>
|
|
3842
|
+
now: tuning.now ?? (() => performance.now())
|
|
3732
3843
|
};
|
|
3733
3844
|
}
|
|
3734
3845
|
async function renameWithWindowsRetry(operation, tuning) {
|
|
@@ -3761,7 +3872,7 @@ function isRetryableRenameError(error) {
|
|
|
3761
3872
|
var DEFAULT_PORT = {
|
|
3762
3873
|
platform: process.platform,
|
|
3763
3874
|
mkdir: (path, options) => mkdir2(path, options),
|
|
3764
|
-
lstat: (path) =>
|
|
3875
|
+
lstat: (path) => lstat3(path),
|
|
3765
3876
|
open_file: (path) => open2(path, "wx", 384),
|
|
3766
3877
|
rename,
|
|
3767
3878
|
unlink,
|
|
@@ -3840,7 +3951,7 @@ function errorCode2(error) {
|
|
|
3840
3951
|
import { createHash as createHash5 } from "node:crypto";
|
|
3841
3952
|
import { constants as constants2 } from "node:fs";
|
|
3842
3953
|
import { mkdir as mkdir3, open as open3, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
3843
|
-
import { dirname as dirname4, join as
|
|
3954
|
+
import { dirname as dirname4, join as join3 } from "node:path";
|
|
3844
3955
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
3845
3956
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
3846
3957
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -3859,10 +3970,12 @@ var HostUsageFactsStore = class {
|
|
|
3859
3970
|
afterPendingWrite;
|
|
3860
3971
|
afterBatchPublish;
|
|
3861
3972
|
sessionDirectoryCursor;
|
|
3973
|
+
uploadScanSignature;
|
|
3974
|
+
uploadScanEmpty = false;
|
|
3862
3975
|
constructor(options) {
|
|
3863
|
-
this.root =
|
|
3864
|
-
this.sessions =
|
|
3865
|
-
this.batches =
|
|
3976
|
+
this.root = join3(options.outbox_dir, "usage-facts");
|
|
3977
|
+
this.sessions = join3(this.root, "sessions");
|
|
3978
|
+
this.batches = join3(this.root, "batches");
|
|
3866
3979
|
this.platform = options.platform ?? process.platform;
|
|
3867
3980
|
this.custody = options.secure_file_custody ?? {};
|
|
3868
3981
|
this.afterPendingWrite = options.afterPendingWrite;
|
|
@@ -3878,6 +3991,10 @@ var HostUsageFactsStore = class {
|
|
|
3878
3991
|
this.sessionDirectoryCursor = void 0;
|
|
3879
3992
|
await cursor?.close();
|
|
3880
3993
|
}
|
|
3994
|
+
/** The durable path behind one session's usage state, so idle fast paths can poll it without reading it. */
|
|
3995
|
+
statePath(producer, hostSourceRef, hostSessionRef) {
|
|
3996
|
+
return this.sessionPath(producer, hostSourceRef, hostSessionRef);
|
|
3997
|
+
}
|
|
3881
3998
|
async readState(producer, hostSourceRef, hostSessionRef) {
|
|
3882
3999
|
const path = this.sessionPath(producer, hostSourceRef, hostSessionRef);
|
|
3883
4000
|
const value = await readOptionalJson(path, HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
@@ -3953,7 +4070,7 @@ var HostUsageFactsStore = class {
|
|
|
3953
4070
|
if (entry === null) break;
|
|
3954
4071
|
inspected += 1;
|
|
3955
4072
|
if (!isOrphanBatchEntry(entry, expected)) continue;
|
|
3956
|
-
await unlink2(
|
|
4073
|
+
await unlink2(join3(directoryPath, entry.name));
|
|
3957
4074
|
deleted += 1;
|
|
3958
4075
|
}
|
|
3959
4076
|
} finally {
|
|
@@ -3981,9 +4098,17 @@ var HostUsageFactsStore = class {
|
|
|
3981
4098
|
});
|
|
3982
4099
|
}
|
|
3983
4100
|
async nextUploadCandidate(producer, hostSourceRef) {
|
|
4101
|
+
const signature = await statObservedPathSignature(this.sessions);
|
|
4102
|
+
if (signature !== null && signature === this.uploadScanSignature && this.uploadScanEmpty) return null;
|
|
4103
|
+
const candidate = await this.scanUploadCandidates(producer, hostSourceRef);
|
|
4104
|
+
this.uploadScanSignature = signature ?? void 0;
|
|
4105
|
+
this.uploadScanEmpty = candidate === null;
|
|
4106
|
+
return candidate;
|
|
4107
|
+
}
|
|
4108
|
+
async scanUploadCandidates(producer, hostSourceRef) {
|
|
3984
4109
|
const names = await this.readNextSessionNames();
|
|
3985
4110
|
for (const name of names) {
|
|
3986
|
-
const state = await readOptionalJson(
|
|
4111
|
+
const state = await readOptionalJson(join3(this.sessions, name), HOST_USAGE_FACTS_STATE_MAX_BYTES, this.platform, this.custody);
|
|
3987
4112
|
if (state === null) continue;
|
|
3988
4113
|
validateStateOwner(state, producer, hostSourceRef);
|
|
3989
4114
|
let validated = state;
|
|
@@ -4171,14 +4296,14 @@ var HostUsageFactsStore = class {
|
|
|
4171
4296
|
}
|
|
4172
4297
|
}
|
|
4173
4298
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
4174
|
-
return
|
|
4299
|
+
return join3(this.sessions, `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`);
|
|
4175
4300
|
}
|
|
4176
4301
|
batchSessionDirectory(producer, hostSourceRef, hostSessionRef) {
|
|
4177
4302
|
const sessionName = `${sha2562(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef }))}.json`;
|
|
4178
|
-
return
|
|
4303
|
+
return join3(this.batches, sessionName.slice(0, -5));
|
|
4179
4304
|
}
|
|
4180
4305
|
batchPath(state, batchRef) {
|
|
4181
|
-
return
|
|
4306
|
+
return join3(this.batchSessionDirectory(state.producer, state.host_source_ref, state.host_session_ref), batchFileName(batchRef));
|
|
4182
4307
|
}
|
|
4183
4308
|
};
|
|
4184
4309
|
function serializeBatch(batch) {
|
|
@@ -4419,6 +4544,8 @@ function sha2562(value) {
|
|
|
4419
4544
|
|
|
4420
4545
|
// host/relay/src/host-usage-facts-capture.ts
|
|
4421
4546
|
import { constants as constants3 } from "node:fs";
|
|
4547
|
+
import { lstat as lstat4 } from "node:fs/promises";
|
|
4548
|
+
import { dirname as dirname5 } from "node:path";
|
|
4422
4549
|
var HOST_USAGE_FACTS_SCAN_MAX_BYTES = 1024 * 1024;
|
|
4423
4550
|
var HOST_USAGE_FACTS_SCAN_MAX_ROWS = 256;
|
|
4424
4551
|
var HOST_USAGE_FACTS_SOURCE_ROW_MAX_BYTES = 64 * 1024;
|
|
@@ -4468,6 +4595,55 @@ var HostUsageRegistrationCapture = class {
|
|
|
4468
4595
|
return captured;
|
|
4469
4596
|
}
|
|
4470
4597
|
};
|
|
4598
|
+
var HostUsageIdleGate = class {
|
|
4599
|
+
seen = /* @__PURE__ */ new Map();
|
|
4600
|
+
statPath;
|
|
4601
|
+
constructor(options = {}) {
|
|
4602
|
+
this.statPath = options.statPath ?? statIdleGatePath;
|
|
4603
|
+
}
|
|
4604
|
+
/**
|
|
4605
|
+
* Check whether the path is unchanged since the last confirmed check, without recording anything.
|
|
4606
|
+
* The caller confirms the returned signature only after the capture for it succeeded without a
|
|
4607
|
+
* source error, so a failed read leaves the source eligible on the next tick while a fully-read,
|
|
4608
|
+
* unchanged source keeps skipping its open plus state-read probe.
|
|
4609
|
+
*/
|
|
4610
|
+
async checkUnchanged(key, path) {
|
|
4611
|
+
const signature = await this.statPath(path);
|
|
4612
|
+
if (signature === null) {
|
|
4613
|
+
this.seen.delete(key);
|
|
4614
|
+
return { unchanged: false, signature };
|
|
4615
|
+
}
|
|
4616
|
+
if (this.seen.get(key) === signature) return { unchanged: true, signature };
|
|
4617
|
+
return { unchanged: false, signature };
|
|
4618
|
+
}
|
|
4619
|
+
/** Remember a signature only after its capture succeeded, so failures stay eligible. */
|
|
4620
|
+
confirmUnchanged(key, signature) {
|
|
4621
|
+
if (signature === null) return;
|
|
4622
|
+
this.seen.set(key, signature);
|
|
4623
|
+
}
|
|
4624
|
+
};
|
|
4625
|
+
async function statIdleGatePath(path) {
|
|
4626
|
+
const direct = await statObservedPathSignature(path);
|
|
4627
|
+
if (direct !== null) return direct;
|
|
4628
|
+
try {
|
|
4629
|
+
await lstat4(path);
|
|
4630
|
+
return null;
|
|
4631
|
+
} catch (error) {
|
|
4632
|
+
const code2 = transcriptErrorCode(error);
|
|
4633
|
+
if (code2 !== "ENOENT" && code2 !== "ENOTDIR") return null;
|
|
4634
|
+
return await missingPathAnchor(path);
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
async function missingPathAnchor(path) {
|
|
4638
|
+
let ancestor = dirname5(path);
|
|
4639
|
+
for (let depth = 0; depth < 4; depth += 1) {
|
|
4640
|
+
if (ancestor === dirname5(ancestor)) return null;
|
|
4641
|
+
const anchor = await statObservedPathSignature(ancestor);
|
|
4642
|
+
if (anchor !== null) return `missing:${anchor}`;
|
|
4643
|
+
ancestor = dirname5(ancestor);
|
|
4644
|
+
}
|
|
4645
|
+
return null;
|
|
4646
|
+
}
|
|
4471
4647
|
async function openHostUsageTranscriptCursor(input) {
|
|
4472
4648
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants3.O_RDONLY));
|
|
4473
4649
|
let source;
|
|
@@ -4538,7 +4714,7 @@ function completeLinePrefix(bytes, baseOffset) {
|
|
|
4538
4714
|
|
|
4539
4715
|
// host/relay/src/host-registration-state.ts
|
|
4540
4716
|
import { constants as constants4 } from "node:fs";
|
|
4541
|
-
import { dirname as
|
|
4717
|
+
import { dirname as dirname6 } from "node:path";
|
|
4542
4718
|
|
|
4543
4719
|
// host/runtime-source-paths.ts
|
|
4544
4720
|
import { createHash as createHash6 } from "node:crypto";
|
|
@@ -4630,7 +4806,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
4630
4806
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
4631
4807
|
let raw;
|
|
4632
4808
|
try {
|
|
4633
|
-
await assertPrivateRegistrationDirectory(
|
|
4809
|
+
await assertPrivateRegistrationDirectory(dirname6(path), platform, custody);
|
|
4634
4810
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
4635
4811
|
} catch (error) {
|
|
4636
4812
|
throw registrationReadError(error);
|
|
@@ -4805,15 +4981,16 @@ async function runHostUsageFactsUploader(options, signal, wait = waitForAbort) {
|
|
|
4805
4981
|
}
|
|
4806
4982
|
}
|
|
4807
4983
|
|
|
4808
|
-
// host/relay/src/relay-quarantine-store.ts
|
|
4809
|
-
var RELAY_QUARANTINE_MAX_BYTES = 16 * 1024 * 1024;
|
|
4810
|
-
var RELAY_QUARANTINE_FRAME_REASONS = ["frame_identity_conflict", "sequence_gap", "gateway_refused"];
|
|
4811
|
-
var RELAY_QUARANTINE_REASONS = [...RELAY_QUARANTINE_FRAME_REASONS, ...HOST_PRODUCER_FRAME_ERROR_CODES];
|
|
4812
|
-
|
|
4813
4984
|
// host/relay/src/relay-admission-store.ts
|
|
4814
|
-
var
|
|
4815
|
-
|
|
4816
|
-
|
|
4985
|
+
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"]);
|
|
4986
|
+
|
|
4987
|
+
// host/relay/src/host-relay-config.ts
|
|
4988
|
+
var HOST_RELAY_CONFIG_MIN_BYTES = Buffer.byteLength("{}", "utf8");
|
|
4989
|
+
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");
|
|
4990
|
+
|
|
4991
|
+
// host/relay/src/relay-endpoint-ownership.ts
|
|
4992
|
+
import { lstat as lstat5, mkdir as mkdir4, unlink as unlink3 } from "node:fs/promises";
|
|
4993
|
+
import { dirname as dirname7 } from "node:path";
|
|
4817
4994
|
|
|
4818
4995
|
// host/relay/src/relay-ipc-error.ts
|
|
4819
4996
|
var HostRelayIpcError = class extends Error {
|
|
@@ -4834,13 +5011,11 @@ function relayIpcErrorCode(error) {
|
|
|
4834
5011
|
}
|
|
4835
5012
|
|
|
4836
5013
|
// host/relay/src/relay-endpoint-ownership.ts
|
|
4837
|
-
import { lstat as lstat3, mkdir as mkdir4, unlink as unlink3 } from "node:fs/promises";
|
|
4838
|
-
import { dirname as dirname6 } from "node:path";
|
|
4839
5014
|
function currentUid(fallback) {
|
|
4840
5015
|
return typeof process.geteuid === "function" ? process.geteuid() : fallback;
|
|
4841
5016
|
}
|
|
4842
5017
|
async function assertCompactRelayClientParent(endpoint) {
|
|
4843
|
-
const parent =
|
|
5018
|
+
const parent = dirname7(endpoint);
|
|
4844
5019
|
if (process.platform !== "darwin" || !isMacosHostRelayIpcDirectory(parent)) return;
|
|
4845
5020
|
if (parent !== macosHostRelayIpcDirectory()) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC directory does not belong to the effective user.");
|
|
4846
5021
|
await assertPrivateEndpointDirectory(parent);
|
|
@@ -4848,7 +5023,7 @@ async function assertCompactRelayClientParent(endpoint) {
|
|
|
4848
5023
|
async function assertPrivateEndpointDirectory(parent) {
|
|
4849
5024
|
let stats;
|
|
4850
5025
|
try {
|
|
4851
|
-
stats = await
|
|
5026
|
+
stats = await lstat5(parent);
|
|
4852
5027
|
} catch (error) {
|
|
4853
5028
|
throw endpointInspectionError(error, "Host Relay IPC endpoint parent is unavailable; leaving it untouched.");
|
|
4854
5029
|
}
|
|
@@ -4861,13 +5036,13 @@ function endpointInspectionError(error, message) {
|
|
|
4861
5036
|
}
|
|
4862
5037
|
|
|
4863
5038
|
// host/relay/src/relay-ipc.ts
|
|
4864
|
-
import { createConnection
|
|
5039
|
+
import { createConnection } from "node:net";
|
|
4865
5040
|
|
|
4866
5041
|
// host/relay/src/relay-pipe-handshake.ts
|
|
4867
5042
|
import { createHmac, randomBytes } from "node:crypto";
|
|
4868
5043
|
import { constants as constants5 } from "node:fs";
|
|
4869
5044
|
import { link, unlink as unlink4 } from "node:fs/promises";
|
|
4870
|
-
import { dirname as
|
|
5045
|
+
import { dirname as dirname8, join as join4 } from "node:path";
|
|
4871
5046
|
var RELAY_PIPE_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
4872
5047
|
var RELAY_PIPE_KEY_BYTES = 32;
|
|
4873
5048
|
var RELAY_PIPE_KEY_FILENAME = "relay-pipe.key";
|
|
@@ -4887,10 +5062,10 @@ var RelayPipeHandshakeError = class extends Error {
|
|
|
4887
5062
|
}
|
|
4888
5063
|
};
|
|
4889
5064
|
function relayPipeStateRootForOutboxDir(outboxDir) {
|
|
4890
|
-
return
|
|
5065
|
+
return join4(dirname8(dirname8(dirname8(outboxDir))), "relay");
|
|
4891
5066
|
}
|
|
4892
5067
|
function relayPipeKeyPath(relayStateRoot) {
|
|
4893
|
-
return
|
|
5068
|
+
return join4(relayStateRoot, RELAY_PIPE_KEY_FILENAME);
|
|
4894
5069
|
}
|
|
4895
5070
|
async function loadRelayPipeKey(relayStateRoot, platform = process.platform, custody = {}) {
|
|
4896
5071
|
const path = relayPipeKeyPath(relayStateRoot);
|
|
@@ -4901,7 +5076,7 @@ async function loadRelayPipeKey(relayStateRoot, platform = process.platform, cus
|
|
|
4901
5076
|
}
|
|
4902
5077
|
async function loadWindowsRelayPipeKey(path, custody) {
|
|
4903
5078
|
try {
|
|
4904
|
-
await ensurePrivateDirectoryWithSecurefs(
|
|
5079
|
+
await ensurePrivateDirectoryWithSecurefs(dirname8(path), custody);
|
|
4905
5080
|
const existing = await readRelayPipeKey(path, "win32", custody);
|
|
4906
5081
|
if (existing !== null) return existing;
|
|
4907
5082
|
await createRandomPrivateFileWithSecurefs(path, RELAY_PIPE_KEY_BYTES, custody);
|
|
@@ -5330,7 +5505,7 @@ var HostInvocationAuthenticationRefusal = class extends Error {
|
|
|
5330
5505
|
}
|
|
5331
5506
|
};
|
|
5332
5507
|
var INSTALLED_HOST_INVOCATION_AUTHENTICATION_DEPENDENCIES = {
|
|
5333
|
-
process_elapsed_ms: () =>
|
|
5508
|
+
process_elapsed_ms: () => performance2.now(),
|
|
5334
5509
|
load_pipe_key: async (outboxDirectory) => process.platform === "win32" ? loadRelayPipeKey(relayPipeStateRootForOutboxDir(outboxDirectory)) : void 0,
|
|
5335
5510
|
create_relay_port: (endpoint, pipeKey, timeoutMs) => new HostRelayInvocationContextPort(endpoint, pipeKey, timeoutMs)
|
|
5336
5511
|
};
|
|
@@ -5527,13 +5702,15 @@ function validToolCallId(value) {
|
|
|
5527
5702
|
}
|
|
5528
5703
|
async function invocationMintQuery(descriptor, store, current, clientNonce, options, windowOverride) {
|
|
5529
5704
|
const readWindow = windowOverride === void 0 ? options.read_human_message_window?.(current.identity) ?? descriptor.read_human_message_window?.({ store, identity: current.identity }) ?? Promise.resolve({ messages: [], truncated: false }) : Promise.resolve(windowOverride);
|
|
5705
|
+
const window = await readWindow;
|
|
5706
|
+
if (window.messages.length === 0) throw new TypeError("transcript_unavailable");
|
|
5530
5707
|
return {
|
|
5531
5708
|
producer_id: descriptor.producer_id,
|
|
5532
5709
|
producer_installation_ref: options.producer_installation_ref,
|
|
5533
5710
|
client_nonce: clientNonce,
|
|
5534
5711
|
context_expires_at: current.expires_at,
|
|
5535
5712
|
host_binding: { ...current.identity },
|
|
5536
|
-
human_message_window:
|
|
5713
|
+
human_message_window: window,
|
|
5537
5714
|
...await visibleOutputBudget(descriptor)
|
|
5538
5715
|
};
|
|
5539
5716
|
}
|
|
@@ -5562,7 +5739,7 @@ async function currentInvocation(descriptor, config, now, store) {
|
|
|
5562
5739
|
const identity = resolveIdentity(descriptor, config);
|
|
5563
5740
|
if (identity.status === "session_unavailable") throw new TypeError("no_binding");
|
|
5564
5741
|
const waitBudgetMs = config.context_activation_wait_ms ?? 0;
|
|
5565
|
-
const monotonicNow = config.monotonic_now ?? (() =>
|
|
5742
|
+
const monotonicNow = config.monotonic_now ?? (() => performance2.now());
|
|
5566
5743
|
const deadline = monotonicNow() + waitBudgetMs;
|
|
5567
5744
|
let firstCheck = true;
|
|
5568
5745
|
let waitEngaged = false;
|
|
@@ -5674,7 +5851,7 @@ function writeResult(value, sink) {
|
|
|
5674
5851
|
// host/producer-service.ts
|
|
5675
5852
|
import { posix as posix4, win32 as win325 } from "node:path";
|
|
5676
5853
|
import { constants as constants6 } from "node:fs";
|
|
5677
|
-
import { lstat as
|
|
5854
|
+
import { lstat as lstat6 } from "node:fs/promises";
|
|
5678
5855
|
var SAFE_REF2 = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
|
|
5679
5856
|
var HOST_PRODUCER_CONFIG_FLAG = "--ceal-host-config";
|
|
5680
5857
|
var HostProducerServiceError = class extends Error {
|
|
@@ -5803,7 +5980,7 @@ function assertProducerAbsolutePath(value, platform, kind, error) {
|
|
|
5803
5980
|
}
|
|
5804
5981
|
async function configPathStat(configPath, error) {
|
|
5805
5982
|
try {
|
|
5806
|
-
return await
|
|
5983
|
+
return await lstat6(configPath);
|
|
5807
5984
|
} catch {
|
|
5808
5985
|
throw error("config_unavailable");
|
|
5809
5986
|
}
|
|
@@ -6020,8 +6197,8 @@ function record3(value) {
|
|
|
6020
6197
|
}
|
|
6021
6198
|
|
|
6022
6199
|
// host/claude/src/claude-outbox.ts
|
|
6023
|
-
import { mkdir as mkdir5, readFile, unlink as unlink5 } from "node:fs/promises";
|
|
6024
|
-
import { isAbsolute as
|
|
6200
|
+
import { mkdir as mkdir5, readFile, stat as stat3, unlink as unlink5 } from "node:fs/promises";
|
|
6201
|
+
import { isAbsolute as isAbsolute3, join as join5 } from "node:path";
|
|
6025
6202
|
|
|
6026
6203
|
// host/invocation-context.ts
|
|
6027
6204
|
var HOST_INVOCATION_TURN_SELECTION_SCHEMA = "ceal.host_invocation_turn_selection.v1";
|
|
@@ -6075,7 +6252,7 @@ function safeRef2(value) {
|
|
|
6075
6252
|
}
|
|
6076
6253
|
|
|
6077
6254
|
// host/claude/src/claude-invocation-context.ts
|
|
6078
|
-
import { isAbsolute as
|
|
6255
|
+
import { isAbsolute as isAbsolute2 } from "node:path";
|
|
6079
6256
|
function claudeInvocationContextFromTurn(identity, promptRef, expiresAt, workingDirectory, turnGenerationRef) {
|
|
6080
6257
|
return invocationContextFromTurn(identity, promptRef, expiresAt, { schema_version: CLAUDE_INVOCATION_CONTEXT_SCHEMA_VERSION, validate: validateClaudeHostInvocationContext, working_directory: workingDirectory, turn_generation_ref: turnGenerationRef });
|
|
6081
6258
|
}
|
|
@@ -6104,7 +6281,7 @@ function optionalSafeRef(value) {
|
|
|
6104
6281
|
return value === void 0 || safeRef3(value);
|
|
6105
6282
|
}
|
|
6106
6283
|
function optionalDirectory(value) {
|
|
6107
|
-
return value === void 0 || typeof value === "string" &&
|
|
6284
|
+
return value === void 0 || typeof value === "string" && isAbsolute2(value) && !value.includes("\0") && value.length <= 4096;
|
|
6108
6285
|
}
|
|
6109
6286
|
function safeRef3(value) {
|
|
6110
6287
|
return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u.test(value);
|
|
@@ -6128,15 +6305,16 @@ var ClaudeOutboxStore = class {
|
|
|
6128
6305
|
directory;
|
|
6129
6306
|
activeContexts;
|
|
6130
6307
|
turnSelections;
|
|
6308
|
+
registrationInventory = new HostRegistrationInventory();
|
|
6131
6309
|
constructor(directory) {
|
|
6132
|
-
if (!
|
|
6310
|
+
if (!isAbsolute3(directory)) throw new ClaudeHostError("configuration", "Claude outbox directory must be absolute.");
|
|
6133
6311
|
this.directory = directory;
|
|
6134
|
-
this.envelopes =
|
|
6135
|
-
this.sessions =
|
|
6136
|
-
this.registrations =
|
|
6137
|
-
this.cursors =
|
|
6138
|
-
this.activeContexts =
|
|
6139
|
-
this.turnSelections =
|
|
6312
|
+
this.envelopes = join5(directory, "envelopes");
|
|
6313
|
+
this.sessions = join5(directory, "sessions");
|
|
6314
|
+
this.registrations = join5(directory, "transcript-registrations");
|
|
6315
|
+
this.cursors = join5(directory, "transcript-cursors");
|
|
6316
|
+
this.activeContexts = join5(directory, "active-contexts");
|
|
6317
|
+
this.turnSelections = join5(directory, "turn-selections");
|
|
6140
6318
|
}
|
|
6141
6319
|
async prepare() {
|
|
6142
6320
|
for (const path of [this.envelopes, this.sessions, this.registrations, this.cursors, this.activeContexts, this.turnSelections]) {
|
|
@@ -6185,7 +6363,7 @@ var ClaudeOutboxStore = class {
|
|
|
6185
6363
|
for (const name of await listHostOutboxDirectoryNames(this.activeContexts)) {
|
|
6186
6364
|
if (!name.endsWith(".json")) continue;
|
|
6187
6365
|
try {
|
|
6188
|
-
const value = JSON.parse(await readFile(
|
|
6366
|
+
const value = JSON.parse(await readFile(join5(this.activeContexts, name), "utf8"));
|
|
6189
6367
|
validateClaudeHostInvocationContext(value);
|
|
6190
6368
|
if (Date.parse(value.expires_at) > now.getTime()) contexts.push(value);
|
|
6191
6369
|
} catch {
|
|
@@ -6204,7 +6382,7 @@ var ClaudeOutboxStore = class {
|
|
|
6204
6382
|
for (const name of await listHostOutboxDirectoryNames(this.envelopes)) {
|
|
6205
6383
|
if (!name.endsWith(".json")) continue;
|
|
6206
6384
|
try {
|
|
6207
|
-
const value = JSON.parse(await readFile(
|
|
6385
|
+
const value = JSON.parse(await readFile(join5(this.envelopes, name), "utf8"));
|
|
6208
6386
|
validateEnvelope(value);
|
|
6209
6387
|
entries.push(value);
|
|
6210
6388
|
} catch {
|
|
@@ -6225,17 +6403,18 @@ var ClaudeOutboxStore = class {
|
|
|
6225
6403
|
async saveSession(snapshot) {
|
|
6226
6404
|
validateSession(snapshot);
|
|
6227
6405
|
await this.prepare();
|
|
6228
|
-
await durableAtomicReplace(
|
|
6406
|
+
await durableAtomicReplace(join5(this.sessions, `${cealRequestSha256({ source: snapshot.host_source_ref, session: snapshot.host_session_ref })}.json`), JSON.stringify(snapshot));
|
|
6229
6407
|
}
|
|
6230
6408
|
async readSession(sourceRef, sessionRef) {
|
|
6231
6409
|
if (!SAFE_REF3.test(sourceRef) || !SAFE_REF3.test(sessionRef)) throw new ClaudeHostError("invalid_input", "Claude session identity is invalid.");
|
|
6232
6410
|
try {
|
|
6233
|
-
const value = JSON.parse(await readFile(
|
|
6411
|
+
const value = JSON.parse(await readFile(join5(this.sessions, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`), "utf8"));
|
|
6234
6412
|
validateSession(value);
|
|
6235
6413
|
return value;
|
|
6236
6414
|
} catch (error) {
|
|
6237
6415
|
if (code(error) === "ENOENT") return null;
|
|
6238
|
-
|
|
6416
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
6417
|
+
throw new ClaudeHostError("storage", "Claude session snapshot is malformed.");
|
|
6239
6418
|
}
|
|
6240
6419
|
}
|
|
6241
6420
|
async registerTranscript(registration) {
|
|
@@ -6266,17 +6445,19 @@ var ClaudeOutboxStore = class {
|
|
|
6266
6445
|
return registration;
|
|
6267
6446
|
}
|
|
6268
6447
|
async listTranscriptRegistrations() {
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6448
|
+
return this.registrationInventory.read(this.registrations, async () => {
|
|
6449
|
+
const registrations = [];
|
|
6450
|
+
for (const name of await listHostOutboxDirectoryNames(this.registrations)) {
|
|
6451
|
+
if (!name.endsWith(".json")) continue;
|
|
6452
|
+
try {
|
|
6453
|
+
const value = JSON.parse(await readFile(join5(this.registrations, name), "utf8"));
|
|
6454
|
+
validateRegistration(value);
|
|
6455
|
+
registrations.push(value);
|
|
6456
|
+
} catch {
|
|
6457
|
+
}
|
|
6277
6458
|
}
|
|
6278
|
-
|
|
6279
|
-
|
|
6459
|
+
return registrations.sort((left, right) => left.registered_at.localeCompare(right.registered_at));
|
|
6460
|
+
});
|
|
6280
6461
|
}
|
|
6281
6462
|
async readInvocationTurnSelection(hostSourceRef, hostSessionRef) {
|
|
6282
6463
|
if (!SAFE_REF3.test(hostSourceRef) || !SAFE_REF3.test(hostSessionRef)) throw new ClaudeHostError("invalid_input", "Claude Host turn selection identity is invalid.");
|
|
@@ -6286,7 +6467,8 @@ var ClaudeOutboxStore = class {
|
|
|
6286
6467
|
return value;
|
|
6287
6468
|
} catch (error) {
|
|
6288
6469
|
if (code(error) === "ENOENT") return null;
|
|
6289
|
-
|
|
6470
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
6471
|
+
throw new ClaudeHostError("storage", "Unable to read the Claude Host turn selection.");
|
|
6290
6472
|
}
|
|
6291
6473
|
}
|
|
6292
6474
|
async readTranscriptCursor(registration) {
|
|
@@ -6297,7 +6479,17 @@ var ClaudeOutboxStore = class {
|
|
|
6297
6479
|
return value;
|
|
6298
6480
|
} catch (error) {
|
|
6299
6481
|
if (code(error) === "ENOENT") return null;
|
|
6300
|
-
|
|
6482
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
6483
|
+
throw new ClaudeHostError("storage", "Claude transcript cursor is malformed.");
|
|
6484
|
+
}
|
|
6485
|
+
}
|
|
6486
|
+
async transcriptCursorFingerprint(registration) {
|
|
6487
|
+
validateRegistration(registration);
|
|
6488
|
+
try {
|
|
6489
|
+
const info = await stat3(this.cursorPath(registration.host_source_ref, registration.host_session_ref), { bigint: true });
|
|
6490
|
+
return `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`;
|
|
6491
|
+
} catch {
|
|
6492
|
+
return "missing";
|
|
6301
6493
|
}
|
|
6302
6494
|
}
|
|
6303
6495
|
async writeTranscriptCursor(cursor) {
|
|
@@ -6306,16 +6498,16 @@ var ClaudeOutboxStore = class {
|
|
|
6306
6498
|
await durableAtomicReplace(this.cursorPath(cursor.host_source_ref, cursor.host_session_ref), JSON.stringify(cursor));
|
|
6307
6499
|
}
|
|
6308
6500
|
envelopePath(ref) {
|
|
6309
|
-
return
|
|
6501
|
+
return join5(this.envelopes, `${cealRequestSha256(ref)}.json`);
|
|
6310
6502
|
}
|
|
6311
6503
|
registrationPath(sourceRef, sessionRef) {
|
|
6312
|
-
return
|
|
6504
|
+
return join5(this.registrations, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
6313
6505
|
}
|
|
6314
6506
|
turnSelectionPath(sourceRef, sessionRef) {
|
|
6315
|
-
return
|
|
6507
|
+
return join5(this.turnSelections, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
6316
6508
|
}
|
|
6317
6509
|
cursorPath(sourceRef, sessionRef) {
|
|
6318
|
-
return
|
|
6510
|
+
return join5(this.cursors, `${cealRequestSha256({ source: sourceRef, session: sessionRef })}.json`);
|
|
6319
6511
|
}
|
|
6320
6512
|
async readRegistrationFile(path) {
|
|
6321
6513
|
try {
|
|
@@ -6324,7 +6516,8 @@ var ClaudeOutboxStore = class {
|
|
|
6324
6516
|
return value;
|
|
6325
6517
|
} catch (error) {
|
|
6326
6518
|
if (code(error) === "ENOENT") return null;
|
|
6327
|
-
|
|
6519
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
6520
|
+
throw new ClaudeHostError("storage", "Claude transcript registration is malformed.");
|
|
6328
6521
|
}
|
|
6329
6522
|
}
|
|
6330
6523
|
async removeStateFile(path) {
|
|
@@ -6335,7 +6528,7 @@ var ClaudeOutboxStore = class {
|
|
|
6335
6528
|
}
|
|
6336
6529
|
}
|
|
6337
6530
|
activeContextPath(identity) {
|
|
6338
|
-
return
|
|
6531
|
+
return join5(this.activeContexts, `${invocationContextKey(identity)}.json`);
|
|
6339
6532
|
}
|
|
6340
6533
|
};
|
|
6341
6534
|
function validateInvocationContextReadArguments(hostSourceRef, hostSessionRef, now) {
|
|
@@ -6348,7 +6541,7 @@ async function readProjectionFile(file) {
|
|
|
6348
6541
|
return context;
|
|
6349
6542
|
} catch (error) {
|
|
6350
6543
|
if (code(error) === "ENOENT") return null;
|
|
6351
|
-
if (error instanceof ClaudeHostError) throw error;
|
|
6544
|
+
if (error instanceof ClaudeHostError || code(error) !== null) throw error;
|
|
6352
6545
|
throw new ClaudeHostError("storage", "Unable to read the Claude Host invocation context.");
|
|
6353
6546
|
}
|
|
6354
6547
|
}
|
|
@@ -6411,7 +6604,7 @@ function validateRegistration(value) {
|
|
|
6411
6604
|
if (!timestamp2(value.registered_at) || !timestamp2(value.expires_at)) throw new ClaudeHostError("storage", "Claude transcript registration timestamps are malformed.");
|
|
6412
6605
|
}
|
|
6413
6606
|
function validateRegistrationPaths(cwd, transcriptPath) {
|
|
6414
|
-
if (cwd !== void 0 && (typeof cwd !== "string" || !
|
|
6607
|
+
if (cwd !== void 0 && (typeof cwd !== "string" || !isAbsolute3(cwd) || cwd.length > CLAUDE_TRANSCRIPT_PATH_MAX_CHARACTERS || cwd.includes("\0"))) {
|
|
6415
6608
|
throw new ClaudeHostError("storage", "Claude transcript registration working directory is malformed.");
|
|
6416
6609
|
}
|
|
6417
6610
|
if (typeof transcriptPath !== "string" || transcriptPath.length === 0 || transcriptPath.length > CLAUDE_TRANSCRIPT_PATH_MAX_CHARACTERS) {
|
|
@@ -6530,9 +6723,9 @@ var ClaudeProducer = class {
|
|
|
6530
6723
|
};
|
|
6531
6724
|
|
|
6532
6725
|
// host/claude/src/claude-transcript-watcher.ts
|
|
6533
|
-
import { readdir as readdir2 } from "node:fs/promises";
|
|
6534
|
-
import { isDeepStrictEqual } from "node:util";
|
|
6535
|
-
import { join as
|
|
6726
|
+
import { readdir as readdir2, stat as stat4 } from "node:fs/promises";
|
|
6727
|
+
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
6728
|
+
import { join as join6 } from "node:path";
|
|
6536
6729
|
|
|
6537
6730
|
// host/claude/src/claude-subagent-overflow-checkpoint.ts
|
|
6538
6731
|
var ClaudeSubagentOverflowCheckpoint = class {
|
|
@@ -6567,6 +6760,7 @@ var TOKEN_OBSERVATION_SOURCE = "claude_transcript.message.usage";
|
|
|
6567
6760
|
var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
6568
6761
|
store;
|
|
6569
6762
|
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
6763
|
+
prunedRegistrations;
|
|
6570
6764
|
diagnostic;
|
|
6571
6765
|
constructor(options) {
|
|
6572
6766
|
super(options, {
|
|
@@ -6580,9 +6774,21 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6580
6774
|
transcriptPathOf(registration) {
|
|
6581
6775
|
return registration.transcript_path;
|
|
6582
6776
|
}
|
|
6777
|
+
registrationKey(registration) {
|
|
6778
|
+
return `${registration.host_source_ref}\0${registration.host_session_ref}`;
|
|
6779
|
+
}
|
|
6780
|
+
async scanFingerprint(registration) {
|
|
6781
|
+
const transcript = await super.scanFingerprint(registration);
|
|
6782
|
+
if (transcript === null) return null;
|
|
6783
|
+
const subagents = await subagentsFingerprint(registration.transcript_path);
|
|
6784
|
+
return subagents === null ? null : `${transcript}|${subagents}|${await this.store.transcriptCursorFingerprint(registration)}`;
|
|
6785
|
+
}
|
|
6583
6786
|
async listRegistrations() {
|
|
6584
6787
|
const registrations = await this.store.listTranscriptRegistrations();
|
|
6585
|
-
this.
|
|
6788
|
+
if (registrations !== this.prunedRegistrations) {
|
|
6789
|
+
this.overflow.prune(registrations);
|
|
6790
|
+
this.prunedRegistrations = registrations;
|
|
6791
|
+
}
|
|
6586
6792
|
return registrations;
|
|
6587
6793
|
}
|
|
6588
6794
|
async scanOpened(handle, registration) {
|
|
@@ -6595,13 +6801,14 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6595
6801
|
}
|
|
6596
6802
|
if (preflight.checkpointPending) await this.store.writeTranscriptCursor({ ...cursor, updated_at: this.stamp() });
|
|
6597
6803
|
const draft = mutableCursor(cursor);
|
|
6598
|
-
await this.scanOpenedTranscript(registration, handle, cursor, draft, size, device, inode);
|
|
6599
|
-
return { records: draft.consumed, enqueued: draft.enqueued, quarantined: false };
|
|
6804
|
+
const retry = await this.scanOpenedTranscript(registration, handle, cursor, draft, size, device, inode);
|
|
6805
|
+
return { records: draft.consumed, enqueued: draft.enqueued, quarantined: false, ...retry ? { retry: true } : {} };
|
|
6600
6806
|
}
|
|
6601
6807
|
async scanFailed(handle, registration, error) {
|
|
6602
6808
|
this.diagnostic("watcher_scan_failed", claudeTranscriptScanFailureKind(error), claudeTranscriptScanCause(handle, error));
|
|
6603
6809
|
if (handle === void 0 && isSymlinkTranscript(error)) return await this.quarantineUnopened(registration, "transcript_malformed");
|
|
6604
6810
|
if (error instanceof ClaudeHostError && error.code === "payload_rejected") return await this.quarantineDraft(await this.preservedCursor(registration));
|
|
6811
|
+
if (!(error instanceof ClaudeHostError) && transcriptErrorCode(error) !== null) return { records: 0, enqueued: 0, quarantined: false, retry: true };
|
|
6605
6812
|
await this.quarantineFailure(registration, handle);
|
|
6606
6813
|
return { records: 0, enqueued: 0, quarantined: true };
|
|
6607
6814
|
}
|
|
@@ -6638,9 +6845,12 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6638
6845
|
await this.consumeMainChunk(registration, main2, draft);
|
|
6639
6846
|
draft.offset += main2.length;
|
|
6640
6847
|
}
|
|
6641
|
-
|
|
6848
|
+
const mainRetry = main2 !== "empty" && main2 !== "partial" && draft.offset < size;
|
|
6849
|
+
const subagents = await this.consumeSubagents(registration, draft);
|
|
6850
|
+
draft.consumed += subagents.consumed;
|
|
6642
6851
|
await this.emitOpenTerminal(registration, draft);
|
|
6643
6852
|
await this.commitCursor(registration, handle, previous, draft, device, inode);
|
|
6853
|
+
return mainRetry || subagents.retry;
|
|
6644
6854
|
}
|
|
6645
6855
|
async preflight(registration, handle, size, device, inode) {
|
|
6646
6856
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
@@ -6802,13 +7012,15 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6802
7012
|
} catch (error) {
|
|
6803
7013
|
if (isMissingTranscriptError(error) || isNotDirectory(error)) {
|
|
6804
7014
|
this.overflow.clear(registration);
|
|
6805
|
-
return 0;
|
|
7015
|
+
return { consumed: 0, retry: false };
|
|
6806
7016
|
}
|
|
7017
|
+
if (transcriptErrorCode(error) !== null) throw error;
|
|
6807
7018
|
throw new ClaudeHostError("payload_rejected", "Claude subagent transcript directory is unavailable.");
|
|
6808
7019
|
}
|
|
6809
7020
|
const listed = new Set(names);
|
|
6810
7021
|
for (const name of Object.keys(draft.subagents)) if (!listed.has(name)) delete draft.subagents[name];
|
|
6811
|
-
|
|
7022
|
+
const overflow = names.length > CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES;
|
|
7023
|
+
const reported = await this.overflow.observe(registration, names, () => {
|
|
6812
7024
|
const line = `Claude ignored subagent transcripts past its file bound: transcript_path=${JSON.stringify(registration.transcript_path)}, files=${names.length}.`;
|
|
6813
7025
|
try {
|
|
6814
7026
|
this.log(line);
|
|
@@ -6817,15 +7029,18 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6817
7029
|
}
|
|
6818
7030
|
return true;
|
|
6819
7031
|
});
|
|
7032
|
+
let retry = overflow && !reported;
|
|
6820
7033
|
names = names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES);
|
|
6821
7034
|
let consumed = 0;
|
|
6822
7035
|
for (const name of names) {
|
|
6823
|
-
|
|
7036
|
+
const result = await this.consumeSubagentFile(draft, directory, name);
|
|
7037
|
+
consumed += result.consumed;
|
|
7038
|
+
retry ||= result.retry;
|
|
6824
7039
|
}
|
|
6825
|
-
return consumed;
|
|
7040
|
+
return { consumed, retry };
|
|
6826
7041
|
}
|
|
6827
7042
|
async consumeSubagentFile(draft, directory, name) {
|
|
6828
|
-
const path =
|
|
7043
|
+
const path = join6(directory, name);
|
|
6829
7044
|
let handle;
|
|
6830
7045
|
try {
|
|
6831
7046
|
handle = await openNoFollow(path);
|
|
@@ -6835,19 +7050,20 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6835
7050
|
const chunk = await this.readChunk(handle, pinned.offset, size);
|
|
6836
7051
|
if (chunk === "empty" || chunk === "partial") {
|
|
6837
7052
|
draft.subagents[name] = pinned;
|
|
6838
|
-
return 0;
|
|
7053
|
+
return { consumed: 0, retry: false };
|
|
6839
7054
|
}
|
|
6840
7055
|
const consumed = this.consumeSubagentLines(draft, chunk);
|
|
6841
7056
|
const offset = pinned.offset + chunk.length;
|
|
6842
7057
|
const anchor = await this.readAnchor(handle, offset, CLAUDE_TRANSCRIPT_ANCHOR_BYTES);
|
|
6843
7058
|
draft.subagents[name] = { device, inode, offset, anchor_start: anchor.start, anchor_sha256: anchor.sha256 };
|
|
6844
|
-
return consumed;
|
|
7059
|
+
return { consumed, retry: offset < size };
|
|
6845
7060
|
} catch (error) {
|
|
6846
7061
|
if (isMissingTranscriptError(error)) {
|
|
6847
7062
|
delete draft.subagents[name];
|
|
6848
|
-
return 0;
|
|
7063
|
+
return { consumed: 0, retry: false };
|
|
6849
7064
|
}
|
|
6850
|
-
|
|
7065
|
+
if (error instanceof ClaudeHostError || transcriptErrorCode(error) !== null) throw error;
|
|
7066
|
+
throw new ClaudeHostError("payload_rejected", "Claude subagent transcript is unavailable.");
|
|
6851
7067
|
} finally {
|
|
6852
7068
|
await handle?.close();
|
|
6853
7069
|
}
|
|
@@ -6979,7 +7195,7 @@ function mutableCursor(cursor) {
|
|
|
6979
7195
|
};
|
|
6980
7196
|
}
|
|
6981
7197
|
function sameCursorContent(left, right) {
|
|
6982
|
-
return
|
|
7198
|
+
return isDeepStrictEqual2({ ...left, updated_at: void 0 }, { ...right, updated_at: void 0 });
|
|
6983
7199
|
}
|
|
6984
7200
|
function zeroCounts() {
|
|
6985
7201
|
return { input: 0, cached_input: 0, cache_write_input: 0, output: 0 };
|
|
@@ -7072,9 +7288,23 @@ function isAssistantUsageLine(record6) {
|
|
|
7072
7288
|
if (identity === null || !isTranscriptRecord(record6.message.usage)) throw new ClaudeHostError("payload_rejected", "Claude transcript usage line is malformed.");
|
|
7073
7289
|
return true;
|
|
7074
7290
|
}
|
|
7291
|
+
async function subagentsFingerprint(transcriptPath) {
|
|
7292
|
+
const directory = subagentsDirectory(transcriptPath);
|
|
7293
|
+
try {
|
|
7294
|
+
const names = (await readdir2(directory)).filter((name) => name.endsWith(".jsonl") && !name.endsWith(".meta.json")).sort();
|
|
7295
|
+
const entries = [];
|
|
7296
|
+
for (const name of names) {
|
|
7297
|
+
const info = await stat4(join6(directory, name), { bigint: true });
|
|
7298
|
+
entries.push(`${name}:${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`);
|
|
7299
|
+
}
|
|
7300
|
+
return entries.join("|");
|
|
7301
|
+
} catch (error) {
|
|
7302
|
+
return isMissingTranscriptError(error) || isNotDirectory(error) ? "missing" : null;
|
|
7303
|
+
}
|
|
7304
|
+
}
|
|
7075
7305
|
function subagentsDirectory(transcriptPath) {
|
|
7076
7306
|
const stem = transcriptPath.endsWith(".jsonl") ? transcriptPath.slice(0, -".jsonl".length) : transcriptPath;
|
|
7077
|
-
return
|
|
7307
|
+
return join6(stem, "subagents");
|
|
7078
7308
|
}
|
|
7079
7309
|
function observationRef(hostSourceRef, event, identity, value) {
|
|
7080
7310
|
return cealHostObservationRef("claude", transcriptObjectSha256({ host_source_ref: hostSourceRef, event, identity, value }));
|
|
@@ -7117,8 +7347,8 @@ function createClaudeProducerWatcher(outboxDir) {
|
|
|
7117
7347
|
diagnostic: (event, failure_kind, cause) => writeHostServiceDiagnostic("claude", event, failure_kind, cause)
|
|
7118
7348
|
});
|
|
7119
7349
|
}
|
|
7120
|
-
async function drainClaudeProducerOnce(options) {
|
|
7121
|
-
const scan = await (options.watcher ?? createClaudeProducerWatcher(options.outbox_dir)).scanOnce().catch((error) => {
|
|
7350
|
+
async function drainClaudeProducerOnce(options, signal) {
|
|
7351
|
+
const scan = await (options.watcher ?? createClaudeProducerWatcher(options.outbox_dir)).scanOnce(signal).catch((error) => {
|
|
7122
7352
|
writeHostServiceDiagnostic("claude", "watcher_scan_failed", claudeTranscriptScanFailureKind(error), claudeTranscriptScanCause(void 0, error));
|
|
7123
7353
|
throw error;
|
|
7124
7354
|
});
|
|
@@ -7130,12 +7360,13 @@ async function drainClaudeProducerOnce(options) {
|
|
|
7130
7360
|
import { createHash as createHash9 } from "node:crypto";
|
|
7131
7361
|
import { constants as constants7 } from "node:fs";
|
|
7132
7362
|
import { readdir as readdir3 } from "node:fs/promises";
|
|
7133
|
-
import { join as
|
|
7363
|
+
import { join as join7 } from "node:path";
|
|
7134
7364
|
var ClaudeUsageFactsCapturer = class {
|
|
7135
7365
|
sources;
|
|
7136
7366
|
usage;
|
|
7137
7367
|
now;
|
|
7138
7368
|
registrations;
|
|
7369
|
+
idleGate;
|
|
7139
7370
|
nextSourceSlot = "main";
|
|
7140
7371
|
nextSubagentIndex = 0;
|
|
7141
7372
|
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
@@ -7144,6 +7375,7 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
7144
7375
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
7145
7376
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
7146
7377
|
this.registrations = new HostUsageRegistrationCapture("claude", options.diagnostic_sink);
|
|
7378
|
+
this.idleGate = new HostUsageIdleGate();
|
|
7147
7379
|
}
|
|
7148
7380
|
async captureNext() {
|
|
7149
7381
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
@@ -7168,6 +7400,20 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
7168
7400
|
return false;
|
|
7169
7401
|
}
|
|
7170
7402
|
async captureMain(registration) {
|
|
7403
|
+
const transcriptKey = claudeUsageIdleKey(registration, "main");
|
|
7404
|
+
const stateKey = claudeUsageIdleKey(registration, "state");
|
|
7405
|
+
const transcriptCheck = await this.idleGate.checkUnchanged(transcriptKey, registration.transcript_path);
|
|
7406
|
+
let stateCheck;
|
|
7407
|
+
if (transcriptCheck.unchanged) {
|
|
7408
|
+
stateCheck = await this.idleGate.checkUnchanged(stateKey, this.usage.statePath("claude", registration.host_source_ref, registration.host_session_ref));
|
|
7409
|
+
if (stateCheck.unchanged) return false;
|
|
7410
|
+
}
|
|
7411
|
+
const captured = await this.scanMain(registration);
|
|
7412
|
+
this.idleGate.confirmUnchanged(transcriptKey, transcriptCheck.signature);
|
|
7413
|
+
if (stateCheck !== void 0) this.idleGate.confirmUnchanged(stateKey, stateCheck.signature);
|
|
7414
|
+
return captured;
|
|
7415
|
+
}
|
|
7416
|
+
async scanMain(registration) {
|
|
7171
7417
|
const prepared = await openHostUsageTranscriptCursor({
|
|
7172
7418
|
path: registration.transcript_path,
|
|
7173
7419
|
producer: "claude",
|
|
@@ -7196,6 +7442,13 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
7196
7442
|
async captureSubagent(registration, onFailure) {
|
|
7197
7443
|
const names = await readSubagentNames(registration);
|
|
7198
7444
|
if (names.length <= CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES) this.overflow.clear(registration);
|
|
7445
|
+
const idle = await this.checkSubagentsUnchanged(registration, names);
|
|
7446
|
+
if (idle.unchanged) return false;
|
|
7447
|
+
const captured = await this.scanSubagents(registration, names, onFailure);
|
|
7448
|
+
for (const pending of idle.pending) this.idleGate.confirmUnchanged(pending.key, pending.signature);
|
|
7449
|
+
return captured;
|
|
7450
|
+
}
|
|
7451
|
+
async scanSubagents(registration, names, onFailure) {
|
|
7199
7452
|
let state = await this.usage.readState("claude", registration.host_source_ref, registration.host_session_ref);
|
|
7200
7453
|
if (state === null) return false;
|
|
7201
7454
|
state = await this.usage.recoverPending(state);
|
|
@@ -7204,6 +7457,24 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
7204
7457
|
if (await this.captureListedSubagents(registration, names, state, onFailure)) return true;
|
|
7205
7458
|
return await this.recordExcessSubagentGap(registration, state, names);
|
|
7206
7459
|
}
|
|
7460
|
+
async checkSubagentsUnchanged(registration, names) {
|
|
7461
|
+
const pending = [];
|
|
7462
|
+
if (names.length > CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES) return { unchanged: false, pending };
|
|
7463
|
+
const check = async (slot, path) => {
|
|
7464
|
+
const key = claudeUsageIdleKey(registration, slot);
|
|
7465
|
+
const result = await this.idleGate.checkUnchanged(key, path);
|
|
7466
|
+
if (result.unchanged) return true;
|
|
7467
|
+
pending.push({ key, signature: result.signature });
|
|
7468
|
+
return false;
|
|
7469
|
+
};
|
|
7470
|
+
if (!await check("state", this.usage.statePath("claude", registration.host_source_ref, registration.host_session_ref))) return { unchanged: false, pending };
|
|
7471
|
+
const directory = subagentsDirectory(registration.transcript_path);
|
|
7472
|
+
if (!await check("subagents", directory)) return { unchanged: false, pending };
|
|
7473
|
+
for (const name of names) {
|
|
7474
|
+
if (!await check(subagentSlot(name), join7(directory, name))) return { unchanged: false, pending };
|
|
7475
|
+
}
|
|
7476
|
+
return { unchanged: true, pending };
|
|
7477
|
+
}
|
|
7207
7478
|
async retireMissingSubagent(state, names) {
|
|
7208
7479
|
const liveSlots = new Set(names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES).map(subagentSlot));
|
|
7209
7480
|
for (const [slot, cursor] of Object.entries(state.cursors)) {
|
|
@@ -7243,7 +7514,7 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
7243
7514
|
async captureSubagentFile(registration, name, state) {
|
|
7244
7515
|
let handle;
|
|
7245
7516
|
try {
|
|
7246
|
-
const opened = await readHostUsageTranscriptSource(() => openNoFollow(
|
|
7517
|
+
const opened = await readHostUsageTranscriptSource(() => openNoFollow(join7(subagentsDirectory(registration.transcript_path), name), constants7.O_RDONLY));
|
|
7247
7518
|
handle = opened;
|
|
7248
7519
|
const file = await readHostUsageTranscriptSource(() => ownedClaudeTranscriptFile(opened));
|
|
7249
7520
|
const sourceRef = sourceFileRef(registration, file.device, file.inode);
|
|
@@ -7434,6 +7705,9 @@ function sourceFileRef(registration, device, inode) {
|
|
|
7434
7705
|
function subagentSlot(name) {
|
|
7435
7706
|
return `subagent:${sha2563(name)}`;
|
|
7436
7707
|
}
|
|
7708
|
+
function claudeUsageIdleKey(registration, slot) {
|
|
7709
|
+
return `${registration.host_source_ref}\0${registration.host_session_ref}\0${slot}`;
|
|
7710
|
+
}
|
|
7437
7711
|
function unscopedGap(reason) {
|
|
7438
7712
|
return { reason, source_file_ref: null, start_offset: null, end_offset: null, omitted_count: null };
|
|
7439
7713
|
}
|
|
@@ -7512,14 +7786,14 @@ var CLAUDE_PRODUCER_DESCRIPTOR = {
|
|
|
7512
7786
|
// host/claude/src/claude-visible-output-budget.ts
|
|
7513
7787
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
7514
7788
|
import { homedir } from "node:os";
|
|
7515
|
-
import { join as
|
|
7789
|
+
import { join as join9 } from "node:path";
|
|
7516
7790
|
|
|
7517
7791
|
// host/claude/src/claude-runtime-paths.ts
|
|
7518
|
-
import { join as
|
|
7792
|
+
import { join as join8 } from "node:path";
|
|
7519
7793
|
var CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT = "CLAUDE_CONFIG_DIR";
|
|
7520
7794
|
var CLAUDE_HOME_DEFAULT_DIRECTORY = ".claude";
|
|
7521
7795
|
function resolveClaudeConfigHome(environment, home) {
|
|
7522
|
-
return environment[CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT] ||
|
|
7796
|
+
return environment[CLAUDE_CONFIG_DIRECTORY_ENVIRONMENT] || join8(home, CLAUDE_HOME_DEFAULT_DIRECTORY);
|
|
7523
7797
|
}
|
|
7524
7798
|
|
|
7525
7799
|
// host/claude/src/claude-visible-output-budget.ts
|
|
@@ -7533,9 +7807,9 @@ async function resolveClaudeVisibleOutputMaxBytes(environment = process.env, wor
|
|
|
7533
7807
|
}
|
|
7534
7808
|
async function projectOrUserInlineLimit(environment, workingDirectory) {
|
|
7535
7809
|
const configHome = resolveClaudeConfigHome(environment, homedir());
|
|
7536
|
-
const userLimit = await settingsInlineLimit(
|
|
7537
|
-
const projectLimit = await settingsInlineLimit(
|
|
7538
|
-
const localLimit = await settingsInlineLimit(
|
|
7810
|
+
const userLimit = await settingsInlineLimit(join9(configHome, "settings.json"));
|
|
7811
|
+
const projectLimit = await settingsInlineLimit(join9(workingDirectory, ".claude", "settings.json"));
|
|
7812
|
+
const localLimit = await settingsInlineLimit(join9(workingDirectory, ".claude", "settings.local.json"));
|
|
7539
7813
|
const candidate = localLimit ?? projectLimit ?? userLimit;
|
|
7540
7814
|
return candidate === void 0 ? void 0 : Math.min(candidate, CLAUDE_MAX_INLINE_OUTPUT_MAX_CHARS);
|
|
7541
7815
|
}
|
|
@@ -7592,9 +7866,8 @@ async function readClaudeInvocationHumanMessageWindow(input) {
|
|
|
7592
7866
|
}
|
|
7593
7867
|
|
|
7594
7868
|
// host/client-doctor.ts
|
|
7595
|
-
import { createHash as createHash10 } from "node:crypto";
|
|
7596
7869
|
import { execFile as execFile2 } from "node:child_process";
|
|
7597
|
-
import { access, open as open4,
|
|
7870
|
+
import { access, open as open4, realpath, stat as stat5 } from "node:fs/promises";
|
|
7598
7871
|
import { delimiter, extname, isAbsolute as isAbsolute5, join as join11 } from "node:path";
|
|
7599
7872
|
import { promisify } from "node:util";
|
|
7600
7873
|
|
|
@@ -7614,7 +7887,7 @@ var WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET = "A-Za-z0-9._=-";
|
|
|
7614
7887
|
var WINDOWS_FIXED_CMD_ARGUMENT_REFUSAL_PATTERN = `[^${WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET}]`;
|
|
7615
7888
|
var WINDOWS_FIXED_CMD_ARGUMENT = new RegExp(`^[${WINDOWS_FIXED_CMD_ARGUMENT_ALPHABET}]+$`, "u");
|
|
7616
7889
|
function validateHostCommandVector(vector, windowsConsumer = "cmd") {
|
|
7617
|
-
if (typeof vector.executable !== "string" || invalidText(vector.executable)) throw new TypeError(`Host command vector executable is invalid (${refusalFact("executable_kind", typeof vector.executable, "non-empty text without a NUL, newline or control character")}).`);
|
|
7890
|
+
if (typeof vector.executable !== "string" || vector.executable === "" || invalidText(vector.executable)) throw new TypeError(`Host command vector executable is invalid (${refusalFact("executable_kind", typeof vector.executable, "non-empty text without a NUL, newline or control character")}).`);
|
|
7618
7891
|
if (vector.args.length > HOST_COMMAND_ARGUMENT_MAX) throw new TypeError(`Host command vector has too many arguments (${refusalFact("argument_count", vector.args.length, `at most ${HOST_COMMAND_ARGUMENT_MAX}`)}).`);
|
|
7619
7892
|
const offending = vector.args.findIndex((argument) => typeof argument !== "string" || invalidText(argument));
|
|
7620
7893
|
if (offending >= 0) throw new TypeError(`Host command vector argument is invalid (${refusalFact("argument_index", offending, "no argument with a NUL, newline or control character")}).`);
|
|
@@ -7677,6 +7950,161 @@ function quoteWindowsExecArgument(value) {
|
|
|
7677
7950
|
return `"${escaped}"`;
|
|
7678
7951
|
}
|
|
7679
7952
|
|
|
7953
|
+
// host/lifecycle/src/host-bundle-manifest.ts
|
|
7954
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
7955
|
+
var HOST_BUNDLE_MAX_SELECTED_BYTES = 256 * 1024 * 1024;
|
|
7956
|
+
var HOST_BUNDLE_MAX_SIGSTORE_BYTES = 16 * 1024 * 1024;
|
|
7957
|
+
var HOST_BUNDLE_TARGETS = Object.freeze(["linux-x64", "linux-arm64", "darwin-arm64", "windows-x64"]);
|
|
7958
|
+
var HOST_BUNDLE_COMPONENTS = Object.freeze(["lifecycle", "relay", "codex", "claude"]);
|
|
7959
|
+
var HOST_BUNDLE_PRODUCERS = Object.freeze(["codex", "claude"]);
|
|
7960
|
+
var HOST_RUNTIME_COMPONENTS = Object.freeze(["relay", "codex", "claude"]);
|
|
7961
|
+
var HOST_BUNDLE_PRIVATE_RUNTIME_ROOT = "libexec/ceal-host";
|
|
7962
|
+
var HOST_WINDOWS_BACKGROUND_RELATIVE_PATH = `${HOST_BUNDLE_PRIVATE_RUNTIME_ROOT}/ceal-host-background.exe`;
|
|
7963
|
+
var HOST_BUNDLE_FILE_KEYS = Object.freeze(["executable", "owners", "path", "sha256"]);
|
|
7964
|
+
var HOST_BUNDLE_SUPPORTED_REQUIRED_FEATURES = Object.freeze([]);
|
|
7965
|
+
var HOST_BUNDLE_REFERENCE_STATUS = Object.freeze({ authority: "non_authoritative", transaction: "incomplete" });
|
|
7966
|
+
async function digestOpenHandleSha256(handle) {
|
|
7967
|
+
const hash = createHash10("sha256");
|
|
7968
|
+
let bytes = 0;
|
|
7969
|
+
for await (const chunk of handle.createReadStream({ autoClose: false })) {
|
|
7970
|
+
bytes += chunk.length;
|
|
7971
|
+
hash.update(chunk);
|
|
7972
|
+
}
|
|
7973
|
+
return { sha256: hash.digest("hex"), bytes };
|
|
7974
|
+
}
|
|
7975
|
+
async function digestFileSha256(path) {
|
|
7976
|
+
let handle;
|
|
7977
|
+
try {
|
|
7978
|
+
handle = await openNoFollow(path);
|
|
7979
|
+
return await digestOpenHandleSha256(handle);
|
|
7980
|
+
} finally {
|
|
7981
|
+
await handle?.close().catch(() => void 0);
|
|
7982
|
+
}
|
|
7983
|
+
}
|
|
7984
|
+
|
|
7985
|
+
// host/spawn-working-directory.ts
|
|
7986
|
+
import { lstatSync, mkdirSync, realpathSync } from "node:fs";
|
|
7987
|
+
import { tmpdir } from "node:os";
|
|
7988
|
+
import { basename, dirname as dirname9, isAbsolute as isAbsolute4, join as join10, normalize, parse as parse2, sep } from "node:path";
|
|
7989
|
+
function resolveCealSpawnWorkingDirectory(stateRoot, keepOutside = []) {
|
|
7990
|
+
const candidates = [];
|
|
7991
|
+
const explicit = candidateDir(stateRoot);
|
|
7992
|
+
if (explicit !== void 0) candidates.push(explicit);
|
|
7993
|
+
const fallback = defaultHostStateRoot();
|
|
7994
|
+
if (fallback !== void 0 && !candidates.some((candidate) => sameDir(candidate, fallback))) candidates.push(fallback);
|
|
7995
|
+
const temporary = candidateDir(join10(tmpdir(), "ceal-spawn-cwd"));
|
|
7996
|
+
if (temporary !== void 0 && !candidates.some((candidate) => sameDir(candidate, temporary))) candidates.push(temporary);
|
|
7997
|
+
const usable = firstKeptOutside(candidates, keepOutside);
|
|
7998
|
+
if (usable.directory !== void 0) return usable.directory;
|
|
7999
|
+
const osFallback = candidateDir(tmpdir());
|
|
8000
|
+
if (osFallback !== void 0 && keptOutside(osFallback, keepOutside)) return osFallback;
|
|
8001
|
+
throw new SpawnWorkingDirectoryRefusedError(keepOutside, usable.lastCreationError);
|
|
8002
|
+
}
|
|
8003
|
+
function firstKeptOutside(candidates, keepOutside) {
|
|
8004
|
+
let lastCreationError;
|
|
8005
|
+
for (const dir of candidates) {
|
|
8006
|
+
if (!keptOutside(dir, keepOutside)) continue;
|
|
8007
|
+
try {
|
|
8008
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
8009
|
+
return { directory: dir };
|
|
8010
|
+
} catch (error) {
|
|
8011
|
+
lastCreationError = error;
|
|
8012
|
+
}
|
|
8013
|
+
}
|
|
8014
|
+
return { lastCreationError };
|
|
8015
|
+
}
|
|
8016
|
+
var SpawnWorkingDirectoryRefusedError = class extends Error {
|
|
8017
|
+
avoided;
|
|
8018
|
+
constructor(keepOutside, lastCreationError) {
|
|
8019
|
+
super(lastCreationError === void 0 ? `spawn working directory: every candidate lies inside avoided tree(s) ${JSON.stringify(keepOutside.join(", "))}; refusing a working directory that would block the activation rename` : `spawn working directory: no usable candidate; last creation error: ${lastCreationError instanceof Error ? lastCreationError.message : String(lastCreationError)}`, { cause: lastCreationError });
|
|
8020
|
+
this.name = "SpawnWorkingDirectoryRefusedError";
|
|
8021
|
+
this.avoided = [...keepOutside];
|
|
8022
|
+
}
|
|
8023
|
+
};
|
|
8024
|
+
function candidateDir(dir) {
|
|
8025
|
+
if (dir === void 0 || dir === "") return void 0;
|
|
8026
|
+
if (!isAbsolute4(dir) || normalize(dir) !== dir || parse2(dir).root === dir) return void 0;
|
|
8027
|
+
return normalize(dir);
|
|
8028
|
+
}
|
|
8029
|
+
function defaultHostStateRoot() {
|
|
8030
|
+
if (process.platform === "win32") {
|
|
8031
|
+
const localAppData = nonEmptyEnv("LOCALAPPDATA");
|
|
8032
|
+
if (localAppData === void 0) return void 0;
|
|
8033
|
+
return candidateDir(join10(localAppData, "Ceal", "Host"));
|
|
8034
|
+
}
|
|
8035
|
+
if (process.platform === "darwin") {
|
|
8036
|
+
const home2 = nonEmptyEnv("HOME");
|
|
8037
|
+
if (home2 === void 0) return void 0;
|
|
8038
|
+
return candidateDir(join10(home2, "Library", "Application Support", "Ceal", "Host"));
|
|
8039
|
+
}
|
|
8040
|
+
const xdg = nonEmptyEnv("XDG_STATE_HOME");
|
|
8041
|
+
if (xdg !== void 0) {
|
|
8042
|
+
const root = candidateDir(join10(xdg, "ceal", "host"));
|
|
8043
|
+
if (root !== void 0) return root;
|
|
8044
|
+
}
|
|
8045
|
+
const home = nonEmptyEnv("HOME");
|
|
8046
|
+
if (home === void 0) return void 0;
|
|
8047
|
+
return candidateDir(join10(home, ".local", "state", "ceal", "host"));
|
|
8048
|
+
}
|
|
8049
|
+
function nonEmptyEnv(name) {
|
|
8050
|
+
const value = process.env[name];
|
|
8051
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
8052
|
+
}
|
|
8053
|
+
function keptOutside(dir, keepOutside) {
|
|
8054
|
+
const resolvedDir = resolveExistingPrefix(dir);
|
|
8055
|
+
if (resolvedDir === void 0) return false;
|
|
8056
|
+
for (const tree of keepOutside) {
|
|
8057
|
+
const clean = candidateDir(tree);
|
|
8058
|
+
if (clean === void 0) continue;
|
|
8059
|
+
const resolvedTree = resolveExistingPrefix(clean);
|
|
8060
|
+
if (resolvedTree === void 0) return false;
|
|
8061
|
+
if (insideDir(resolvedDir, resolvedTree)) return false;
|
|
8062
|
+
}
|
|
8063
|
+
return true;
|
|
8064
|
+
}
|
|
8065
|
+
function isMissingError(error) {
|
|
8066
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
8067
|
+
}
|
|
8068
|
+
function resolveExistingPrefix(path) {
|
|
8069
|
+
let probe = normalize(path);
|
|
8070
|
+
const missing = [];
|
|
8071
|
+
for (; ; ) {
|
|
8072
|
+
let exists = false;
|
|
8073
|
+
try {
|
|
8074
|
+
lstatSync(probe);
|
|
8075
|
+
exists = true;
|
|
8076
|
+
} catch (error) {
|
|
8077
|
+
if (!isMissingError(error)) return void 0;
|
|
8078
|
+
}
|
|
8079
|
+
if (exists) {
|
|
8080
|
+
let resolved;
|
|
8081
|
+
try {
|
|
8082
|
+
resolved = realpathSync.native(probe);
|
|
8083
|
+
} catch {
|
|
8084
|
+
return void 0;
|
|
8085
|
+
}
|
|
8086
|
+
for (let index = missing.length - 1; index >= 0; index -= 1) {
|
|
8087
|
+
const segment = missing[index];
|
|
8088
|
+
if (segment !== void 0) resolved = join10(resolved, segment);
|
|
8089
|
+
}
|
|
8090
|
+
return normalize(resolved);
|
|
8091
|
+
}
|
|
8092
|
+
const parent = dirname9(probe);
|
|
8093
|
+
if (parent === probe) return void 0;
|
|
8094
|
+
missing.push(basename(probe));
|
|
8095
|
+
probe = parent;
|
|
8096
|
+
}
|
|
8097
|
+
}
|
|
8098
|
+
function insideDir(dir, tree) {
|
|
8099
|
+
if (sameDir(dir, tree)) return true;
|
|
8100
|
+
if (process.platform === "win32") return dir.toLowerCase().startsWith(tree.toLowerCase() + sep);
|
|
8101
|
+
return dir.startsWith(tree + sep);
|
|
8102
|
+
}
|
|
8103
|
+
function sameDir(left, right) {
|
|
8104
|
+
if (process.platform === "win32") return left.toLowerCase() === right.toLowerCase();
|
|
8105
|
+
return left === right;
|
|
8106
|
+
}
|
|
8107
|
+
|
|
7680
8108
|
// host/client-doctor.ts
|
|
7681
8109
|
var execFileAsync = promisify(execFile2);
|
|
7682
8110
|
var GIT_OID = /^[a-f0-9]{40}$/u;
|
|
@@ -7758,12 +8186,12 @@ async function resolveCealExecutable(command, environment, platform = process.pl
|
|
|
7758
8186
|
try {
|
|
7759
8187
|
await access(candidate);
|
|
7760
8188
|
const path = await realpath(candidate);
|
|
7761
|
-
const metadata = await
|
|
8189
|
+
const metadata = await stat5(path);
|
|
7762
8190
|
if (!metadata.isFile()) continue;
|
|
7763
8191
|
const launcherKind = await inspectLauncherKind(path);
|
|
7764
8192
|
if (launcherKind !== void 0) return resolveLauncherBinary(path, launcherKind, environment, platform);
|
|
7765
8193
|
if (platform === "win32" && !isAbsolute5(command) && extname(path) === "") continue;
|
|
7766
|
-
return { path, sha256:
|
|
8194
|
+
return { path, sha256: (await digestFileSha256(path)).sha256 };
|
|
7767
8195
|
} catch {
|
|
7768
8196
|
}
|
|
7769
8197
|
}
|
|
@@ -7794,9 +8222,9 @@ async function resolveLauncherBinary(launcherPath, kind, environment, platform)
|
|
|
7794
8222
|
}
|
|
7795
8223
|
if (!isRecord8(parsed) || parsed.schema_version !== CEAL_CLIENT_DOCTOR_SCHEMA_VERSION || parsed.ok !== true || typeof parsed.binary_path !== "string" || parsed.binary_path.length === 0) throw new Error("launcher doctor did not report a binary path");
|
|
7796
8224
|
const binaryPath = await realpath(parsed.binary_path);
|
|
7797
|
-
const metadata = await
|
|
8225
|
+
const metadata = await stat5(binaryPath);
|
|
7798
8226
|
if (!metadata.isFile()) throw new Error("launcher doctor reported a non-file binary path");
|
|
7799
|
-
return { path: binaryPath, sha256:
|
|
8227
|
+
return { path: binaryPath, sha256: (await digestFileSha256(binaryPath)).sha256 };
|
|
7800
8228
|
}
|
|
7801
8229
|
function executableCandidates(command, environment, platform) {
|
|
7802
8230
|
if (isAbsolute5(command)) return [command];
|