@corca-org/ceal-host-win32-x64 1.0.22 → 1.0.24
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 +682 -331
- package/libexec/ceal-host/claude-invocation-authentication.mjs +730 -349
- package/libexec/ceal-host/claude-producer.mjs +472 -125
- package/libexec/ceal-host/codex-hook.mjs +604 -317
- package/libexec/ceal-host/codex-invocation-authentication.mjs +653 -333
- package/libexec/ceal-host/codex-producer.mjs +396 -109
- package/libexec/ceal-host/control.mjs +589 -206
- package/libexec/ceal-host/relay.mjs +113 -61
- package/package.json +1 -1
- package/share/ceal-host/bundle-manifest.json +22 -12
- package/share/ceal-host/bundle-manifest.sigstore.json +1 -1
|
@@ -2032,6 +2032,18 @@ var require_toml = __commonJS({
|
|
|
2032
2032
|
}
|
|
2033
2033
|
});
|
|
2034
2034
|
|
|
2035
|
+
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
2036
|
+
function vocabulary(words) {
|
|
2037
|
+
return Object.freeze(words);
|
|
2038
|
+
}
|
|
2039
|
+
function isVocabularyWord(words, value) {
|
|
2040
|
+
return words.some((word) => word === value);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// packages/ceal-client-protocol/src/host-usage-fields.ts
|
|
2044
|
+
var CEAL_CODEX_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"]);
|
|
2045
|
+
var CEAL_CLAUDE_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "output_tokens"]);
|
|
2046
|
+
|
|
2035
2047
|
// packages/ceal-client-protocol/src/canonical-json.ts
|
|
2036
2048
|
function cealCanonicalJson(value) {
|
|
2037
2049
|
if (value === null || typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
@@ -2106,7 +2118,7 @@ var client_wire_contract_default = {
|
|
|
2106
2118
|
},
|
|
2107
2119
|
command_request: {
|
|
2108
2120
|
schema_name: "ceal.command_request",
|
|
2109
|
-
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context"],
|
|
2121
|
+
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context", "materialize_result"],
|
|
2110
2122
|
absolute_transport_max_bytes: 65536
|
|
2111
2123
|
},
|
|
2112
2124
|
command_resolution: {
|
|
@@ -2152,7 +2164,7 @@ var client_wire_contract_default = {
|
|
|
2152
2164
|
},
|
|
2153
2165
|
command_response: {
|
|
2154
2166
|
schema_name: "ceal.command_response",
|
|
2155
|
-
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context"],
|
|
2167
|
+
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context", "result_file"],
|
|
2156
2168
|
descriptor_field: "verified_artifact",
|
|
2157
2169
|
request_context_field: "request_context",
|
|
2158
2170
|
required_fields: [
|
|
@@ -2165,7 +2177,8 @@ var client_wire_contract_default = {
|
|
|
2165
2177
|
"visible_output_max_bytes",
|
|
2166
2178
|
"local_delivery",
|
|
2167
2179
|
"verified_artifact",
|
|
2168
|
-
"request_context"
|
|
2180
|
+
"request_context",
|
|
2181
|
+
"result_file"
|
|
2169
2182
|
],
|
|
2170
2183
|
bare_document_fields: [
|
|
2171
2184
|
"invocation",
|
|
@@ -2206,8 +2219,11 @@ var client_wire_contract_default = {
|
|
|
2206
2219
|
"ok",
|
|
2207
2220
|
"code",
|
|
2208
2221
|
"reason",
|
|
2209
|
-
"gateway_status"
|
|
2222
|
+
"gateway_status",
|
|
2223
|
+
"retry_after_ms"
|
|
2210
2224
|
],
|
|
2225
|
+
refusal_required_fields: ["schema_version", "ok", "code", "reason"],
|
|
2226
|
+
refusal_optional_fields: ["gateway_status", "retry_after_ms"],
|
|
2211
2227
|
client_nonce: {
|
|
2212
2228
|
character_class_source: "A-Za-z0-9_-",
|
|
2213
2229
|
encoded_characters: 43
|
|
@@ -2426,19 +2442,14 @@ var CEAL_OPERATION_WITHHELD_NEXT_ACTIONS = Object.freeze({
|
|
|
2426
2442
|
personal_authorization_required: "connect_personal_account"
|
|
2427
2443
|
});
|
|
2428
2444
|
|
|
2429
|
-
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
2430
|
-
function vocabulary(words) {
|
|
2431
|
-
return Object.freeze(words);
|
|
2432
|
-
}
|
|
2433
|
-
function isVocabularyWord(words, value) {
|
|
2434
|
-
return words.some((word) => word === value);
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
2445
|
// packages/ceal-client-protocol/src/gateway-response-types.ts
|
|
2438
2446
|
var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavailable", "unknown"]);
|
|
2439
2447
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
2440
2448
|
var CEAL_AUDIT_OUTCOMES = vocabulary(["succeeded", "denied", "failed"]);
|
|
2441
2449
|
var CEAL_GATEWAY_PROVIDER_STEP_OUTCOMES = vocabulary(["completed", "rejected", "throttled", "failed"]);
|
|
2450
|
+
var CEAL_GATEWAY_CORPUS_READ_PROVIDERS = vocabulary(["slack", "google_drive", "notion"]);
|
|
2451
|
+
var CEAL_GATEWAY_CORPUS_READ_OUTCOMES = vocabulary(["answered_from_corpus", "live_fallback"]);
|
|
2452
|
+
var CEAL_GATEWAY_CORPUS_READ_FALLBACK_REASONS = vocabulary(["uncovered_window", "stale", "not_organization_public", "partition_missing"]);
|
|
2442
2453
|
var CEAL_GATEWAY_READ_REUSE_DISPOSITIONS = vocabulary(["response_cache_hit", "corpus_hit", "corpus_hit_after_revalidation", "corpus_partial_provider_supplement", "provider_direct", "provider_continuation", "reuse_unavailable"]);
|
|
2443
2454
|
var CEAL_GATEWAY_READ_REUSE_UNAVAILABLE_REASONS = vocabulary(["not_reported", "storage_unavailable", "coverage_incomplete", "freshness_refresh_required", "not_reusable", "bypassed"]);
|
|
2444
2455
|
var CEAL_GATEWAY_DERIVED_STORE_FAILURE_CLASSES = vocabulary(["storage_unavailable", "decode_mismatch", "write_conflict", "quota", "store_error"]);
|
|
@@ -2479,6 +2490,21 @@ var CEAL_GATEWAY_ORGANIZATION_ROUTE_FACT_CALL_KEYS = Object.freeze([
|
|
|
2479
2490
|
]);
|
|
2480
2491
|
|
|
2481
2492
|
// packages/ceal-client-protocol/src/gateway-validation-primitives.ts
|
|
2493
|
+
var POSIX_HOME_ROOTS = [["/", "home"].join(""), ["/", "Users"].join("")];
|
|
2494
|
+
var WINDOWS_HOME_ROOT = ["C:", "\\", "Users"].join("");
|
|
2495
|
+
var USER_SEGMENT_BODY = "[^/\\\\ \\t\\r\\n\"'`${}]+";
|
|
2496
|
+
var POSIX_SEGMENT_END = "(?:/|$|(?=[\\s\"'`]))";
|
|
2497
|
+
var WINDOWS_SEGMENT_END = "(?:\\\\+|$|(?=[\\s\"'`]))";
|
|
2498
|
+
var WINDOWS_USER_SEGMENT_BODY = "[^\\\\ \\t\\r\\n\"'`${}]+";
|
|
2499
|
+
var ABSOLUTE_PATH_BOUNDARY = "(?<![A-Za-z0-9_])";
|
|
2500
|
+
function escapePathPattern(value) {
|
|
2501
|
+
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
2502
|
+
}
|
|
2503
|
+
function machineHomePathPatterns(flags) {
|
|
2504
|
+
const posix5 = `${ABSOLUTE_PATH_BOUNDARY}(?:${POSIX_HOME_ROOTS.map(escapePathPattern).join("|")})/${USER_SEGMENT_BODY}${POSIX_SEGMENT_END}`;
|
|
2505
|
+
const windows = `${ABSOLUTE_PATH_BOUNDARY}${escapePathPattern(WINDOWS_HOME_ROOT)}\\\\+${WINDOWS_USER_SEGMENT_BODY}${WINDOWS_SEGMENT_END}`;
|
|
2506
|
+
return [new RegExp(posix5, flags), new RegExp(windows, flags)];
|
|
2507
|
+
}
|
|
2482
2508
|
var CealProtocolValidationError = class extends Error {
|
|
2483
2509
|
name = "CealProtocolValidationError";
|
|
2484
2510
|
code;
|
|
@@ -2837,8 +2863,9 @@ var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask a
|
|
|
2837
2863
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
2838
2864
|
var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Relay to the same release as the Gateway, then retry.";
|
|
2839
2865
|
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.";
|
|
2840
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select
|
|
2866
|
+
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select this turn; reason uncertain. Host mode is unavailable in an ephemeral side conversation. When you know you are in one, `ceal --standalone ...` uses your configured Ceal session/Gateway permissions, without Host session/turn correlation or Host usage attribution. Unknown-outcome `repeat_request` needs the same Host turn or explicit `--request-context`. Otherwise return to the original regular conversation. Host refusal never switches modes; report intended Host calls as a gap.";
|
|
2841
2867
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
2868
|
+
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
2842
2869
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
2843
2870
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
2844
2871
|
}
|
|
@@ -2859,13 +2886,18 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
2859
2886
|
context_not_selected: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
2860
2887
|
context_store_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
2861
2888
|
context_store_conflict: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
2862
|
-
refresh_invalid: guidance(
|
|
2863
|
-
refresh_expired: guidance(
|
|
2864
|
-
refresh_replayed: guidance(
|
|
2865
|
-
refresh_revoked: guidance(
|
|
2866
|
-
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
2867
|
-
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
2868
|
-
|
|
2889
|
+
refresh_invalid: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
2890
|
+
refresh_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
2891
|
+
refresh_replayed: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
2892
|
+
refresh_revoked: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
2893
|
+
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family. Ask an Admin to reactivate the Person, then retry this same session refresh.", "ask_admin", 403),
|
|
2894
|
+
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family. Ask an Admin to reactivate the Principal, then retry this same session refresh.", "ask_admin", 403),
|
|
2895
|
+
authority_replaced: guidance("The Gateway authority has been replaced; this session is no longer valid here. Run `ceal session adopt --gateway <origin> --email <email>` against the current Gateway to complete mailbox-confirmed recovery.", "repair_or_adopt_session", 409),
|
|
2896
|
+
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
2897
|
+
refresh_recovery_unavailable: guidance("The Gateway's durable refresh-recovery key is unavailable. Retry the same refresh attempt after the key is available.", "retry", 503, true),
|
|
2898
|
+
refresh_recovery_outcome_unavailable: guidance("The Gateway could not safely recover the outcome of a prior refresh. Ask an administrator to inspect the Gateway session state before retrying or adopting this session.", "ask_admin", 503),
|
|
2899
|
+
refresh_state_unavailable: guidance("The Gateway session state store is temporarily unavailable; retry the same refresh attempt when it is available.", "retry", 503, true),
|
|
2900
|
+
refresh_recovery_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
2869
2901
|
refresh_custody_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
2870
2902
|
session_store_unwritable: guidance("The Ceal client could not write its local session store; the operating system refused the write (EACCES, EPERM, or EROFS). rerun_outside_agent_sandbox reruns it with escalated execution.", "rerun_outside_agent_sandbox", 500),
|
|
2871
2903
|
local_output_exists: guidance("The selected local output path already exists; nothing was written to it.", "choose_new_output_path", 400),
|
|
@@ -2880,23 +2912,21 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
2880
2912
|
resource_stream_failed: guidance("The provider resource stream failed; ask an administrator to inspect the Gateway failure log.", "ask_admin", 500),
|
|
2881
2913
|
gateway_unavailable: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 503, true),
|
|
2882
2914
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
2883
|
-
//
|
|
2884
|
-
|
|
2885
|
-
// when the wait ends still unserved, moved from the `localFailureText` default branch.
|
|
2886
|
-
[CEAL_GATEWAY_STARTING_FAILURE_CODE]: guidance(LOCAL_TRANSPORT_INCOMPLETE, "answer_with_gap", 503, true),
|
|
2915
|
+
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
2916
|
+
[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),
|
|
2887
2917
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
2888
2918
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
2889
2919
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
2890
2920
|
internal_error: guidance("The Gateway failed without exposing internal state.", "answer_with_gap", 500),
|
|
2891
2921
|
// Owned by the Gateway canonical adapter (`gateway/core/src/gateway-canonical-operation-http-adapter.ts`):
|
|
2892
|
-
// the client variant
|
|
2922
|
+
// the static client variant was retired when the client started reading this table.
|
|
2893
2923
|
request_body_too_large: guidance("The Gateway request body exceeds its bounded limit.", "reduce_request_size", 413),
|
|
2894
2924
|
gateway_response_too_large: guidance("The Gateway response exceeds its bounded limit; reduce the requested page or result size.", "reduce_request_size", 500),
|
|
2895
|
-
//
|
|
2896
|
-
//
|
|
2897
|
-
|
|
2898
|
-
//
|
|
2899
|
-
|
|
2925
|
+
// The safe move varies by request. Keep the sentence conditional on the
|
|
2926
|
+
// same `retryable` and `next_action` facts the response exposes.
|
|
2927
|
+
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
2928
|
+
// A provider write the Gateway command deadline cut after its dispatch: the write left and its receipt is still settling, so the caller reads the receipt instead of repeating the write.
|
|
2929
|
+
write_in_progress: guidance("The provider write was dispatched but the Gateway command deadline cut the wait before its outcome settled. Do not repeat the write; read the durable receipt named by write_request_ref with write_receipt.get.", "write_receipt.get", 500),
|
|
2900
2930
|
// Restored verbatim from the retired `localFailureText`
|
|
2901
2931
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
2902
2932
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -2977,8 +3007,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
2977
3007
|
// Host mint classifications. The CLI emits `invocation_authentication_unavailable` with the classification
|
|
2978
3008
|
// in its detail fact; rows without their own sentence share that code's moved sentence, while `next_action`
|
|
2979
3009
|
// is moved from `canonicalHostAuthenticationNextActions` (generated from `CEAL_HOST_AUTHENTICATION_POLICY`)
|
|
2980
|
-
// and `retryable` from `hostAuthenticationFailureForCause` (
|
|
2981
|
-
// sentences carry the
|
|
3010
|
+
// and `retryable` from `hostAuthenticationFailureForCause` (the table's explicit retry verdict). Cause-specific
|
|
3011
|
+
// sentences carry only remedies proved by the Host or Relay cause; generic Gateway refusals do not prove a release mismatch.
|
|
2982
3012
|
// Statuses are the
|
|
2983
3013
|
// Gateway-owned mapping decided with the operator 2026-10-13. This covers every wire cause the maps at
|
|
2984
3014
|
// `host/invocation-authentication-command.ts:217-242` emit, through their policy classifications.
|
|
@@ -2988,21 +3018,23 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
2988
3018
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
2989
3019
|
// changes mode; standalone remains the separate Client authority path.
|
|
2990
3020
|
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "answer_with_gap", 401),
|
|
2991
|
-
|
|
2992
|
-
|
|
3021
|
+
host_context_activation_wait_exhausted: guidance("The Host selected this turn, but its invocation context did not activate before the bounded wait ended. Wait for the supplied retry_after_ms value, then retry the same command.", "retry_after", 401, true),
|
|
3022
|
+
host_invocation_context_stale: guidance("The Host turn changed while this invocation was authenticating. Its command cannot be rebound safely; report this invocation as a gap.", "answer_with_gap", 401),
|
|
3023
|
+
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),
|
|
2993
3024
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
2994
3025
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
2995
3026
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
2996
3027
|
host_mint_gateway_rate_limited: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 429),
|
|
2997
|
-
host_mint_gateway_refused: guidance(
|
|
3028
|
+
host_mint_gateway_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
2998
3029
|
host_mint_gateway_response_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
3030
|
+
host_contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 502),
|
|
2999
3031
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
3000
3032
|
// producer-frame fault names the administrator repair step.
|
|
3001
3033
|
host_producer_frame_invalid: guidance("Ask an administrator to inspect and repair the producer frame, then start a fresh Host turn.", "ask_admin", 400),
|
|
3002
3034
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
3003
3035
|
// sandboxed Relay socket names the run-alone retry.
|
|
3004
3036
|
host_relay_permission_denied: guidance("An agent sandbox denied the Host Relay socket; run `ceal` as the only command, with no pipe, redirect, or `&&`, so the Host allow rule runs it outside the sandbox.", "rerun_outside_agent_sandbox", 403),
|
|
3005
|
-
host_relay_unavailable: guidance(
|
|
3037
|
+
host_relay_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 503),
|
|
3006
3038
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
3007
3039
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
3008
3040
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -3045,7 +3077,7 @@ var UNKNOWN_OUTCOMES = vocabulary(["reconcile", "operator_action", "excluded"]);
|
|
|
3045
3077
|
var RECOVERY_OWNERS = vocabulary(["gateway", "connector", "operator"]);
|
|
3046
3078
|
var CEAL_OPERATION_ADMISSION_STATES = vocabulary(["proposed", "refused", "admitted"]);
|
|
3047
3079
|
var CEAL_OPERATION_EXECUTION_STATES = vocabulary(["not_started", "started", "completed"]);
|
|
3048
|
-
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
3080
|
+
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_applicable", "not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
3049
3081
|
var CEAL_OPERATION_EFFECT_STATES = vocabulary(["none", "applied", "failed", "unknown", "compensated"]);
|
|
3050
3082
|
var CEAL_OPERATION_OBSERVATION_STATES = vocabulary(["not_started", "not_required", "pending", "observed", "unavailable"]);
|
|
3051
3083
|
var CEAL_OPERATION_RECOVERY_KINDS = vocabulary(["none", "reconcile", "compensate", "operator_action"]);
|
|
@@ -3228,6 +3260,7 @@ var CEAL_OPERATION_ACCESS_CLASSES = vocabulary(["read", "write"]);
|
|
|
3228
3260
|
// packages/ceal-client-protocol/src/domain-vocabulary.ts
|
|
3229
3261
|
var CEAL_CONNECTOR_STATUSES = vocabulary(["active", "disabled", "disconnected"]);
|
|
3230
3262
|
var CEAL_CONNECTOR_CUSTODIES = vocabulary(["organization", "personal"]);
|
|
3263
|
+
var CEAL_PROVIDER_BOUNDARY_FIELDS = vocabulary(["provider_boundary_ref", "provider_boundary_kind", "provider_boundary_label", "provider_native_id", "provider_boundary_evidence"]);
|
|
3231
3264
|
var CEAL_PERSONAL_ACCESS_CEILINGS = vocabulary(["disabled", "read", "read_write"]);
|
|
3232
3265
|
var CEAL_TARGET_REF_PATTERN = "^[^\\p{Cc}]+$";
|
|
3233
3266
|
var TARGET_REF = new RegExp(CEAL_TARGET_REF_PATTERN, "u");
|
|
@@ -3273,7 +3306,7 @@ var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
|
3273
3306
|
var CEAL_OPERATION_AUTHORITY_POLICY_KEYS = Object.freeze(["access_group", "instance_binding", "target", "admission_recheck"]);
|
|
3274
3307
|
var MAX_OPERATION_INPUT_RESOLVER_BINDINGS = 96;
|
|
3275
3308
|
var CEAL_OPERATION_DESCRIPTOR_REQUIRED_ENVELOPE_KEYS = Object.freeze(["schema_version", "id", "input_contract", "result_contract", "policy"]);
|
|
3276
|
-
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary"]);
|
|
3309
|
+
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary", "standard_names"]);
|
|
3277
3310
|
|
|
3278
3311
|
// packages/ceal-client-protocol/src/operation-catalog.ts
|
|
3279
3312
|
var CEAL_OPERATION_CATALOG_SCHEMA_VERSION = "ceal.catalog.v3";
|
|
@@ -3369,6 +3402,7 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
3369
3402
|
gateway_access_group_connector_activity_scope_audit: (root) => join(root, "profile-connector-activity-scope-audit.jsonl"),
|
|
3370
3403
|
gateway_access_group_connector_calendar_scope_audit: (root) => join(root, "profile-connector-calendar-scope-audit.jsonl"),
|
|
3371
3404
|
gateway_access_group_connector_readiness_audit: (root) => join(root, "profile-connector-readiness.audit.jsonl"),
|
|
3405
|
+
gateway_deployment_events: (root) => join(root, "gateway-deployments.jsonl"),
|
|
3372
3406
|
gateway_organization_audit_ledger: (root) => join(root, "organization-ledger.jsonl"),
|
|
3373
3407
|
gateway_personal_client_audit: (root) => join(root, "audit.jsonl"),
|
|
3374
3408
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
@@ -3398,6 +3432,11 @@ var CEAL_HOST_INSTALLATION_REF_PATTERN = new RegExp(`^host-installation:${CEAL_L
|
|
|
3398
3432
|
var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUID_PATTERN}$`, "u");
|
|
3399
3433
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
3400
3434
|
|
|
3435
|
+
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
3436
|
+
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
3437
|
+
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
3438
|
+
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
3439
|
+
|
|
3401
3440
|
// packages/ceal-client-protocol/src/operation-result-completeness.ts
|
|
3402
3441
|
var CEAL_READ_VALUE_CONTINUATION_KEYS = vocabulary(["continuation", "continuation_ref", "next_cursor"]);
|
|
3403
3442
|
|
|
@@ -3482,6 +3521,7 @@ var PROVIDER_LINK_CONFORMANCE_TABLE = Object.freeze([
|
|
|
3482
3521
|
{ provider: "google-workspace", result_kind: "calendar_event_read_row", field: "source_url", status: "required_when_provider_supplies", provider_shape: "htmlLink", source: "https://developers.google.com/workspace/calendar/api/v3/reference/events" },
|
|
3483
3522
|
{ provider: "google-workspace", result_kind: "drive_document_calendar_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "verified readback webViewLink or htmlLink", source: "https://developers.google.com/workspace/drive/api/reference/rest/v3/files" },
|
|
3484
3523
|
{ provider: "google-workspace", result_kind: "drive_file_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "verified readback webViewLink", source: "https://developers.google.com/workspace/drive/api/reference/rest/v3/files" },
|
|
3524
|
+
{ provider: "google-workspace", result_kind: "form_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "verified Forms responderUri", source: "https://developers.google.com/workspace/forms/api/reference/rest/v1/forms" },
|
|
3485
3525
|
{ provider: "google-workspace", result_kind: "spreadsheet_write_result", field: "spreadsheet_url", status: "required_when_provider_supplies", provider_shape: "verified readback webViewLink", source: "https://developers.google.com/workspace/drive/api/reference/rest/v3/files" },
|
|
3486
3526
|
{ provider: "google-workspace", result_kind: "calendar_meet_link_write_result", field: "meet_url", status: "required_when_provider_supplies", provider_shape: "verified conferenceData entryPoint uri", source: "https://developers.google.com/workspace/calendar/api/v3/reference/events" },
|
|
3487
3527
|
{ provider: "google-workspace", result_kind: "gmail_message_read_row", field: "source_url", status: "not_available", reason: "The Gmail API Message representation exposes id and threadId but no human UI URL; cite by title and date.", source: "https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages#Message" },
|
|
@@ -3556,6 +3596,8 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
3556
3596
|
"review_submitted",
|
|
3557
3597
|
"comment_created",
|
|
3558
3598
|
"reaction_created",
|
|
3599
|
+
"pull_request_merged",
|
|
3600
|
+
"release_published",
|
|
3559
3601
|
"ceal_write_completed",
|
|
3560
3602
|
"event_start",
|
|
3561
3603
|
"all_day_start",
|
|
@@ -3567,7 +3609,7 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
3567
3609
|
"page_last_edited",
|
|
3568
3610
|
"resource_modified"
|
|
3569
3611
|
]);
|
|
3570
|
-
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "notion"]);
|
|
3612
|
+
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "google-mail", "notion"]);
|
|
3571
3613
|
var CEAL_ACTIVITY_UNSUPPORTED_EVENT_KIND_CODE = "unsupported_event_kind";
|
|
3572
3614
|
var CEAL_ACTIVITY_GAP_CODES = vocabulary([
|
|
3573
3615
|
"provider_page_budget",
|
|
@@ -3588,6 +3630,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
3588
3630
|
"github.pull_request.opened",
|
|
3589
3631
|
"github.issue.edited",
|
|
3590
3632
|
"github.pull_request.edited",
|
|
3633
|
+
"github.pull_request.merged",
|
|
3634
|
+
"github.release.published",
|
|
3591
3635
|
"github.review.submitted",
|
|
3592
3636
|
"github.issue_comment.created",
|
|
3593
3637
|
"github.review_comment.created",
|
|
@@ -3601,6 +3645,7 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
3601
3645
|
"drive.file.created",
|
|
3602
3646
|
"drive.file.modified",
|
|
3603
3647
|
"drive.file.viewed",
|
|
3648
|
+
"mail.sent",
|
|
3604
3649
|
"notion.page.created",
|
|
3605
3650
|
"notion.page.edited"
|
|
3606
3651
|
]);
|
|
@@ -3614,6 +3659,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
3614
3659
|
"github.review_comment.created": "comment_created",
|
|
3615
3660
|
"github.issue.opened": "resource_created",
|
|
3616
3661
|
"github.pull_request.opened": "resource_created",
|
|
3662
|
+
"github.pull_request.merged": "pull_request_merged",
|
|
3663
|
+
"github.release.published": "release_published",
|
|
3617
3664
|
"github.issue.edited": "resource_modified",
|
|
3618
3665
|
"github.pull_request.edited": "resource_modified",
|
|
3619
3666
|
"github.reaction.created": "reaction_created",
|
|
@@ -3624,6 +3671,7 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
3624
3671
|
"drive.file.created": "file_created",
|
|
3625
3672
|
"drive.file.modified": "file_modified_by_me",
|
|
3626
3673
|
"drive.file.viewed": "file_viewed_by_me",
|
|
3674
|
+
"mail.sent": "message_created",
|
|
3627
3675
|
"notion.page.created": "page_created",
|
|
3628
3676
|
"notion.page.edited": "page_last_edited"
|
|
3629
3677
|
});
|
|
@@ -3651,6 +3699,7 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
3651
3699
|
created_at: { required: false, timestamp: true },
|
|
3652
3700
|
created_at_local: { required: false, timestamp: true },
|
|
3653
3701
|
modified_at: { required: false, timestamp: true },
|
|
3702
|
+
observed_at: { required: false, timestamp: true },
|
|
3654
3703
|
modified_at_local: { required: false, timestamp: true },
|
|
3655
3704
|
viewed_by_me_at: { required: false, timestamp: true },
|
|
3656
3705
|
modified_by_me_at: { required: false, timestamp: true },
|
|
@@ -3678,9 +3727,6 @@ var RESOURCE_ROW_REQUIRED_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(
|
|
|
3678
3727
|
var RESOURCE_ROW_KEYS = new Set(Object.keys(RESOURCE_ROW_KEY_RULES));
|
|
3679
3728
|
var RESOURCE_ROW_TIMESTAMP_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(([key, rule]) => rule.timestamp ? [key] : []);
|
|
3680
3729
|
|
|
3681
|
-
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
3682
|
-
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
3683
|
-
|
|
3684
3730
|
// packages/ceal-client-protocol/src/excluded-target-coverage.ts
|
|
3685
3731
|
var CEAL_EXCLUDED_TARGET_COVERAGE_MAX_ENTRIES = 64;
|
|
3686
3732
|
function cealExcludedTargetCoverageJsonSchema() {
|
|
@@ -3736,6 +3782,8 @@ var CEAL_REFRESH_FAILURE_CODES = vocabulary([
|
|
|
3736
3782
|
"principal_inactive",
|
|
3737
3783
|
"authority_replaced",
|
|
3738
3784
|
"refresh_recovery_unavailable",
|
|
3785
|
+
"refresh_recovery_outcome_unavailable",
|
|
3786
|
+
"refresh_state_unavailable",
|
|
3739
3787
|
"refresh_recovery_expired",
|
|
3740
3788
|
// The serving gate answers this while the Gateway is still starting and the
|
|
3741
3789
|
// refresh was never attempted; the same attempt stays retryable. It is never
|
|
@@ -3987,7 +4035,7 @@ function validateBatchContents(value) {
|
|
|
3987
4035
|
if (facts.length === 0 && gaps.length === 0 || facts.length > 0 && value.source_ranges.length === 0) invalid("Ceal Host usage coverage is invalid.");
|
|
3988
4036
|
const sourceFiles = new Set(value.source_ranges.map((range) => sourceRangeFileRef(range)));
|
|
3989
4037
|
for (const fact of facts) {
|
|
3990
|
-
|
|
4038
|
+
validateCealHostUsageFact(fact, value.host_session_ref);
|
|
3991
4039
|
if (!sourceFiles.has(fact.source_file_ref)) invalid("Ceal Host usage fact is outside its source ranges.");
|
|
3992
4040
|
}
|
|
3993
4041
|
for (const gap of gaps) {
|
|
@@ -4020,7 +4068,7 @@ function hostUsageSourceFileReference(producer, hostSourceRef, hostSessionRef, d
|
|
|
4020
4068
|
for (const part of [producer, hostSourceRef, hostSessionRef, device, inode]) if (typeof part !== "string" || part.length === 0 || part.length > 512) invalid("Ceal Host usage file identity is invalid.");
|
|
4021
4069
|
return `host-source-file:${sha256(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef, device, inode }))}`;
|
|
4022
4070
|
}
|
|
4023
|
-
function
|
|
4071
|
+
function validateCealHostUsageFact(value, sessionRef) {
|
|
4024
4072
|
if (!isOperationRecord(value)) invalid("Ceal Host usage fact is invalid.");
|
|
4025
4073
|
requireFactByteLimit(value);
|
|
4026
4074
|
if (value.producer === "codex_transcript") validateCodexFact(value);
|
|
@@ -4084,7 +4132,7 @@ function validCorrectionSemantics(value) {
|
|
|
4084
4132
|
}
|
|
4085
4133
|
function validateCodexUsageCounts(value) {
|
|
4086
4134
|
if (!isOperationRecord(value)) invalid("Ceal Codex usage fields are invalid.");
|
|
4087
|
-
requireExactOperationKeys(value,
|
|
4135
|
+
requireExactOperationKeys(value, CEAL_CODEX_USAGE_COUNT_FIELDS);
|
|
4088
4136
|
for (const key of Object.keys(value)) if (!safeInteger(value[key])) invalid("Ceal Codex usage fields are invalid.");
|
|
4089
4137
|
if (Number(value.total_tokens) !== Number(value.input_tokens) + Number(value.output_tokens) || Number(value.cached_input_tokens) + Number(value.cache_write_input_tokens) > Number(value.input_tokens) || Number(value.reasoning_output_tokens) > Number(value.output_tokens)) invalid("Ceal Codex usage fields are inconsistent.");
|
|
4090
4138
|
}
|
|
@@ -4404,6 +4452,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
4404
4452
|
"options_invalid",
|
|
4405
4453
|
"session_unavailable",
|
|
4406
4454
|
"context_unavailable",
|
|
4455
|
+
"activation_wait_exhausted",
|
|
4407
4456
|
"context_replaced",
|
|
4408
4457
|
"no_binding",
|
|
4409
4458
|
"context_expired",
|
|
@@ -4439,22 +4488,23 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
4439
4488
|
// This reason cannot distinguish a Codex side conversation from a missing
|
|
4440
4489
|
// context in a regular session, so guidance must leave that choice to the caller.
|
|
4441
4490
|
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "answer_with_gap" }),
|
|
4442
|
-
|
|
4491
|
+
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
4492
|
+
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
4443
4493
|
// `no_binding` now means the producer has no real current Host session. The
|
|
4444
4494
|
// Host Relay never uses it for an uncreated Gateway Request; there is no
|
|
4445
4495
|
// useful retry until the consumer is running inside a Host session.
|
|
4446
4496
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
4447
|
-
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "
|
|
4497
|
+
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
4448
4498
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
4449
4499
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
4450
4500
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
4451
4501
|
gateway_rate_limited: Object.freeze({ classification: "host_mint_gateway_rate_limited", next_action: "answer_with_gap" }),
|
|
4452
|
-
contract_mismatch: Object.freeze({ classification: "
|
|
4453
|
-
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "
|
|
4502
|
+
contract_mismatch: Object.freeze({ classification: "host_contract_mismatch", next_action: "upgrade_ceal_client" }),
|
|
4503
|
+
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "answer_with_gap" }),
|
|
4454
4504
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
4455
4505
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
4456
4506
|
relay_permission_denied: Object.freeze({ classification: "host_relay_permission_denied", next_action: "rerun_outside_agent_sandbox" }),
|
|
4457
|
-
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "
|
|
4507
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "answer_with_gap" }),
|
|
4458
4508
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
4459
4509
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
4460
4510
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -4537,7 +4587,7 @@ function isCealHostServiceDiagnosticCause(value, event) {
|
|
|
4537
4587
|
// packages/ceal-client-protocol/src/client-result-materialization.ts
|
|
4538
4588
|
var CEAL_UNREAD_REASONS = vocabulary(["blocked", "unavailable", "too_large", "unsupported", "download_failed", "permission_denied"]);
|
|
4539
4589
|
var REQUIRED_FIELDS2 = Object.freeze(["schema_version", "operation_id", "path", "sha256"]);
|
|
4540
|
-
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "
|
|
4590
|
+
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "local_result_root", "request_context_argv", "how_to_read"]);
|
|
4541
4591
|
|
|
4542
4592
|
// packages/ceal-client-protocol/src/discovery-manifest.ts
|
|
4543
4593
|
var DISCOVERY_MANIFEST_KEYS = CEAL_CLIENT_WIRE_CONTRACT.command_response.discovery_manifest_fields;
|
|
@@ -4579,6 +4629,211 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
4579
4629
|
maximum: CEAL_PROTOCOL_VERSION
|
|
4580
4630
|
});
|
|
4581
4631
|
|
|
4632
|
+
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
4633
|
+
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
4634
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSES = 8;
|
|
4635
|
+
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
4636
|
+
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
4637
|
+
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
4638
|
+
var OPERATOR_DIAGNOSTIC_HOME_PATHS = machineHomePathPatterns("gu");
|
|
4639
|
+
function redactOperatorDiagnosticSecrets(value) {
|
|
4640
|
+
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]");
|
|
4641
|
+
}
|
|
4642
|
+
function redactOperatorDiagnosticText(value) {
|
|
4643
|
+
const normalized = normalizeCealSingleLineText(value);
|
|
4644
|
+
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
4645
|
+
}
|
|
4646
|
+
function renderOperatorDiagnostic(value) {
|
|
4647
|
+
const state = collectDiagnosticState(value);
|
|
4648
|
+
const fields = [
|
|
4649
|
+
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
4650
|
+
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
4651
|
+
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
4652
|
+
state.stderr === void 0 ? void 0 : `stderr_tail=${JSON.stringify(tail(state.stderr))}`,
|
|
4653
|
+
state.causes.length === 0 ? void 0 : `causes=${state.causes.map(formatCause).join(" <- ")}`
|
|
4654
|
+
].filter((field) => field !== void 0);
|
|
4655
|
+
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
4656
|
+
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
4657
|
+
}
|
|
4658
|
+
function collectDiagnosticState(value) {
|
|
4659
|
+
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0 };
|
|
4660
|
+
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
4661
|
+
while (pending.length > 0 && state.causes.length < OPERATOR_DIAGNOSTIC_MAX_CAUSES) {
|
|
4662
|
+
const current = pending.shift();
|
|
4663
|
+
if (current !== void 0) visitDiagnosticNode(current, state, pending, visited);
|
|
4664
|
+
}
|
|
4665
|
+
return state;
|
|
4666
|
+
}
|
|
4667
|
+
function visitDiagnosticNode(current, state, pending, visited) {
|
|
4668
|
+
if (isObject(current)) {
|
|
4669
|
+
if (visited.has(current)) return;
|
|
4670
|
+
visited.add(current);
|
|
4671
|
+
}
|
|
4672
|
+
captureProcessEvidence(current, state);
|
|
4673
|
+
appendCause(current, state.causes);
|
|
4674
|
+
enqueueCauseChildren(current, state.causes.length, pending);
|
|
4675
|
+
}
|
|
4676
|
+
function captureProcessEvidence(current, state) {
|
|
4677
|
+
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
4678
|
+
if (state.exitCode === void 0) state.exitCode = safeExitCode(read(current, "exitCode")) ?? safeExitCode(read(current, "status")) ?? safeExitCode(read(current, "code"));
|
|
4679
|
+
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
4680
|
+
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
4681
|
+
}
|
|
4682
|
+
function appendCause(current, causes) {
|
|
4683
|
+
const errors = read(current, "errors");
|
|
4684
|
+
if (current instanceof Error && (!(current instanceof AggregateError) || !Array.isArray(errors) || errors.length === 0)) {
|
|
4685
|
+
causes.push(errorCause(current));
|
|
4686
|
+
return;
|
|
4687
|
+
}
|
|
4688
|
+
if (!isObject(current)) {
|
|
4689
|
+
const message = safeText(current);
|
|
4690
|
+
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
4691
|
+
}
|
|
4692
|
+
}
|
|
4693
|
+
function errorCause(error) {
|
|
4694
|
+
const name = safeText(read(error, "name")) ?? "Error";
|
|
4695
|
+
const message = safeText(read(error, "message"));
|
|
4696
|
+
const codeValue = read(error, "code");
|
|
4697
|
+
const code = typeof codeValue === "number" && Number.isFinite(codeValue) ? codeValue : safeText(codeValue);
|
|
4698
|
+
const errnoValue = read(error, "errno");
|
|
4699
|
+
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
4700
|
+
const syscall = safeText(read(error, "syscall"));
|
|
4701
|
+
const path = safePath(read(error, "path"));
|
|
4702
|
+
return Object.freeze({ error_class: name, ...message === void 0 ? {} : { message }, ...code === void 0 ? {} : { code }, ...errno === void 0 ? {} : { errno }, ...syscall === void 0 ? {} : { syscall }, ...path === void 0 ? {} : { path } });
|
|
4703
|
+
}
|
|
4704
|
+
function enqueueCauseChildren(current, causeCount, pending) {
|
|
4705
|
+
const cause = read(current, "cause");
|
|
4706
|
+
if (cause !== void 0) pending.push(cause);
|
|
4707
|
+
const errors = read(current, "errors");
|
|
4708
|
+
if (Array.isArray(errors)) pending.push(...errors.slice(0, OPERATOR_DIAGNOSTIC_MAX_CAUSES - causeCount));
|
|
4709
|
+
}
|
|
4710
|
+
function isObject(value) {
|
|
4711
|
+
return typeof value === "object" && value !== null;
|
|
4712
|
+
}
|
|
4713
|
+
function formatCause(cause) {
|
|
4714
|
+
const fields = [
|
|
4715
|
+
cause.error_class,
|
|
4716
|
+
cause.code === void 0 ? void 0 : `code=${JSON.stringify(safeDiagnosticText(cause.code))}`,
|
|
4717
|
+
cause.errno === void 0 ? void 0 : `errno=${cause.errno}`,
|
|
4718
|
+
cause.syscall === void 0 ? void 0 : `syscall=${JSON.stringify(cause.syscall)}`,
|
|
4719
|
+
cause.path === void 0 ? void 0 : `path=${JSON.stringify(cause.path)}`,
|
|
4720
|
+
cause.message === void 0 ? void 0 : `message=${cause.message}`
|
|
4721
|
+
].filter((field) => field !== void 0);
|
|
4722
|
+
return fields.join(" ");
|
|
4723
|
+
}
|
|
4724
|
+
function tail(value) {
|
|
4725
|
+
const clipped = value.length <= OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT ? value : `…${value.slice(-OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT)}`;
|
|
4726
|
+
return safeDiagnosticText(clipped);
|
|
4727
|
+
}
|
|
4728
|
+
function safeText(value) {
|
|
4729
|
+
if (typeof value !== "string") return void 0;
|
|
4730
|
+
const safe = safeDiagnosticText(value);
|
|
4731
|
+
if (safe.length === 0) return void 0;
|
|
4732
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT) return safe;
|
|
4733
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT / 2);
|
|
4734
|
+
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
4735
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
4736
|
+
}
|
|
4737
|
+
function safePath(value) {
|
|
4738
|
+
if (typeof value !== "string") return void 0;
|
|
4739
|
+
const safe = safeDiagnosticText(value);
|
|
4740
|
+
if (safe.length === 0) return void 0;
|
|
4741
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
4742
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
4743
|
+
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
4744
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
4745
|
+
}
|
|
4746
|
+
function safeDiagnosticText(value) {
|
|
4747
|
+
return redactOperatorDiagnosticText(String(value));
|
|
4748
|
+
}
|
|
4749
|
+
function outputText(value) {
|
|
4750
|
+
if (typeof value === "string") return redactOperatorDiagnosticText(value);
|
|
4751
|
+
if (value instanceof Uint8Array) {
|
|
4752
|
+
try {
|
|
4753
|
+
return redactOperatorDiagnosticText(new TextDecoder().decode(value));
|
|
4754
|
+
} catch {
|
|
4755
|
+
return void 0;
|
|
4756
|
+
}
|
|
4757
|
+
}
|
|
4758
|
+
return void 0;
|
|
4759
|
+
}
|
|
4760
|
+
function safeStatus(value) {
|
|
4761
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
4762
|
+
return typeof value === "string" ? safeText(value) : void 0;
|
|
4763
|
+
}
|
|
4764
|
+
function safeExitCode(value) {
|
|
4765
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
4766
|
+
}
|
|
4767
|
+
function read(value, key) {
|
|
4768
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) return void 0;
|
|
4769
|
+
try {
|
|
4770
|
+
return Reflect.get(value, key);
|
|
4771
|
+
} catch {
|
|
4772
|
+
return void 0;
|
|
4773
|
+
}
|
|
4774
|
+
}
|
|
4775
|
+
function redactHomePaths(value) {
|
|
4776
|
+
const paths = [
|
|
4777
|
+
...OPERATOR_DIAGNOSTIC_HOME_PATHS.flatMap((pattern) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, matchedHomePrefixLength(match[0])))),
|
|
4778
|
+
...configuredHomePathPatterns().flatMap(({ pattern, prefixLength }) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, prefixLength)))
|
|
4779
|
+
];
|
|
4780
|
+
paths.sort((left, right) => left.start - right.start || right.end - left.end);
|
|
4781
|
+
let output = "";
|
|
4782
|
+
let cursor = 0;
|
|
4783
|
+
for (const path of paths) {
|
|
4784
|
+
if (path.start < cursor) continue;
|
|
4785
|
+
output += `${value.slice(cursor, path.start)}[home path redacted]${value.slice(path.prefixEnd, path.end)}`;
|
|
4786
|
+
cursor = path.end;
|
|
4787
|
+
}
|
|
4788
|
+
return output + value.slice(cursor);
|
|
4789
|
+
}
|
|
4790
|
+
function configuredHomePathPatterns() {
|
|
4791
|
+
const homes = [...new Set([process.env.HOME, process.env.USERPROFILE].filter((home) => home !== void 0 && home.length > 0))];
|
|
4792
|
+
return homes.flatMap((home) => {
|
|
4793
|
+
const root = home.replace(/[\\/]+$/gu, "");
|
|
4794
|
+
if (root.length === 0 || root === "/" || /^[A-Za-z]:$/u.test(root)) return [];
|
|
4795
|
+
const pattern = new RegExp(`(?<![A-Za-z0-9_])${escapePathPattern(root)}(?=$|[\\\\/\\s"'\`<>(){}\\[\\],;])`, /^[A-Za-z]:[\\/]/u.test(root) ? "giu" : "gu");
|
|
4796
|
+
return [{ pattern, prefixLength: root.length }];
|
|
4797
|
+
});
|
|
4798
|
+
}
|
|
4799
|
+
function matchedHomePrefixLength(value) {
|
|
4800
|
+
let separators = 0;
|
|
4801
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
4802
|
+
if (value[index] !== "/" && value[index] !== "\\") continue;
|
|
4803
|
+
separators += 1;
|
|
4804
|
+
if (separators === 3) return index;
|
|
4805
|
+
}
|
|
4806
|
+
return value.length;
|
|
4807
|
+
}
|
|
4808
|
+
function redactUrls(value) {
|
|
4809
|
+
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
4810
|
+
}
|
|
4811
|
+
function redactFilePaths(value) {
|
|
4812
|
+
return value.replaceAll(/(?<![A-Za-z0-9._-]|\[home path redacted\])(?:[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/)[^:\r\n"'<>]*?(?=:\d+(?::\d+)?(?:[:\s]|$)|[\r\n]|["'])/gu, "[path redacted]");
|
|
4813
|
+
}
|
|
4814
|
+
function homePathRange(value, match, prefixLength) {
|
|
4815
|
+
const index = match.index;
|
|
4816
|
+
if (index === void 0) return { start: value.length, end: value.length, prefixEnd: value.length };
|
|
4817
|
+
const start = index;
|
|
4818
|
+
let end = start + match[0].length;
|
|
4819
|
+
const quote = start > 0 && (value[start - 1] === "'" || value[start - 1] === '"') ? value[start - 1] : void 0;
|
|
4820
|
+
if (quote !== void 0) {
|
|
4821
|
+
const closing = value.indexOf(quote, end);
|
|
4822
|
+
if (closing >= 0) end = closing;
|
|
4823
|
+
}
|
|
4824
|
+
while (end < value.length && !/[\s"'`<>(){}[\],;]/u.test(value[end] ?? "")) end += 1;
|
|
4825
|
+
return { start, end, prefixEnd: Math.min(start + prefixLength, end) };
|
|
4826
|
+
}
|
|
4827
|
+
function truncateUtf8(value, maxBytes) {
|
|
4828
|
+
if (byteLength(value) <= maxBytes) return value;
|
|
4829
|
+
let output = "";
|
|
4830
|
+
for (const character of value) {
|
|
4831
|
+
if (byteLength(`${output}${character}…`) > maxBytes) break;
|
|
4832
|
+
output += character;
|
|
4833
|
+
}
|
|
4834
|
+
return `${output}…`;
|
|
4835
|
+
}
|
|
4836
|
+
|
|
4582
4837
|
// packages/ceal-client-protocol/src/admin-projection-vocabulary.ts
|
|
4583
4838
|
var ADMIN_PROJECTION_STATES = vocabulary(["ready", "empty", "partial", "unknown"]);
|
|
4584
4839
|
var ADMIN_VIEW_KINDS = vocabulary(["request_detail", "resource_access_timeline", "weekly_usage"]);
|
|
@@ -4719,10 +4974,10 @@ function failureDetail(error) {
|
|
|
4719
4974
|
function errorCode(error) {
|
|
4720
4975
|
return typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : null;
|
|
4721
4976
|
}
|
|
4722
|
-
function hostClientProbe(result,
|
|
4977
|
+
function hostClientProbe(result, read2) {
|
|
4723
4978
|
if (result === null) return { kind: "unreachable" };
|
|
4724
4979
|
if (result.exit_code !== 0) return { kind: "refused", exit_code: result.exit_code };
|
|
4725
|
-
const value =
|
|
4980
|
+
const value = read2(result);
|
|
4726
4981
|
return value === null ? { kind: "unreadable" } : { kind: "value", value };
|
|
4727
4982
|
}
|
|
4728
4983
|
function hostClientProbeRefusal(probe, subject) {
|
|
@@ -4854,7 +5109,7 @@ async function inspectExecutable(options, environment, component) {
|
|
|
4854
5109
|
try {
|
|
4855
5110
|
executable = await (options.resolve_executable ?? resolveCealExecutable)(options.executable ?? "ceal", environment);
|
|
4856
5111
|
} catch (error) {
|
|
4857
|
-
return inspectedFailure("ceal_unavailable", `The ${component} Host cannot resolve an executable Ceal client from its current environment (${
|
|
5112
|
+
return inspectedFailure("ceal_unavailable", `The ${component} Host cannot resolve an executable Ceal client from its current environment (${renderOperatorDiagnostic(error)}).`, `Install the intended Ceal client in the Host PATH, restart ${component}, and run this doctor again.`);
|
|
4858
5113
|
}
|
|
4859
5114
|
if (!validExpectations(options) || options.expected_sha256 !== void 0 && executable.sha256 !== options.expected_sha256) return inspectedFailure("ceal_identity_mismatch", `The Ceal executable visible to the ${component} Host does not match the intended candidate.`, `Install the exact candidate bytes, restart ${component}, and run this doctor with the expected identity.`);
|
|
4860
5115
|
return { ok: true, value: executable };
|
|
@@ -5132,7 +5387,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
5132
5387
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
5133
5388
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
5134
5389
|
return await new Promise((resolve, reject2) => {
|
|
5135
|
-
const child = execFile2(executable, processArgs, { encoding: "buffer", timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
5390
|
+
const child = execFile2(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
5136
5391
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
5137
5392
|
if (exitCode === null) {
|
|
5138
5393
|
reject2(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -5183,6 +5438,185 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
5183
5438
|
return entry.isDirectory() && !entry.isSymbolicLink() && isSelfOwned(entry.uid, platform) && isPrivateFileMode(entry.mode, platform);
|
|
5184
5439
|
}
|
|
5185
5440
|
|
|
5441
|
+
// host/service-log.ts
|
|
5442
|
+
import { copyFile, mkdir, stat as stat2, truncate, appendFile } from "node:fs/promises";
|
|
5443
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, posix, win32 as win323 } from "node:path";
|
|
5444
|
+
|
|
5445
|
+
// host/service-log-delivery.ts
|
|
5446
|
+
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
5447
|
+
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
5448
|
+
setImmediate(flush);
|
|
5449
|
+
}, onDeliveryGap = () => void 0) {
|
|
5450
|
+
const pending = [];
|
|
5451
|
+
const highWaterMark = stream.writableHighWaterMark;
|
|
5452
|
+
const byteBudget = highWaterMark + highWaterMark;
|
|
5453
|
+
let pendingBytes = 0;
|
|
5454
|
+
let droppedLines = 0;
|
|
5455
|
+
let flushScheduled = false;
|
|
5456
|
+
let waitingForDrain = false;
|
|
5457
|
+
let closed = !stream.writable;
|
|
5458
|
+
function stop() {
|
|
5459
|
+
if (closed) return;
|
|
5460
|
+
closed = true;
|
|
5461
|
+
pending.length = 0;
|
|
5462
|
+
pendingBytes = 0;
|
|
5463
|
+
stream.off("drain", onDrain);
|
|
5464
|
+
stream.off("close", onTerminal);
|
|
5465
|
+
stream.off("finish", onTerminal);
|
|
5466
|
+
stream.off("error", onError);
|
|
5467
|
+
}
|
|
5468
|
+
function onTerminal() {
|
|
5469
|
+
stop();
|
|
5470
|
+
}
|
|
5471
|
+
function onError() {
|
|
5472
|
+
stop();
|
|
5473
|
+
}
|
|
5474
|
+
function onDrain() {
|
|
5475
|
+
waitingForDrain = false;
|
|
5476
|
+
scheduleFlush();
|
|
5477
|
+
}
|
|
5478
|
+
function scheduleFlush() {
|
|
5479
|
+
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
5480
|
+
flushScheduled = true;
|
|
5481
|
+
let scheduling = true;
|
|
5482
|
+
let invokedSynchronously = false;
|
|
5483
|
+
try {
|
|
5484
|
+
schedule(() => {
|
|
5485
|
+
if (scheduling) {
|
|
5486
|
+
invokedSynchronously = true;
|
|
5487
|
+
return;
|
|
5488
|
+
}
|
|
5489
|
+
flushScheduled = false;
|
|
5490
|
+
flush();
|
|
5491
|
+
});
|
|
5492
|
+
} catch {
|
|
5493
|
+
flushScheduled = false;
|
|
5494
|
+
stop();
|
|
5495
|
+
return;
|
|
5496
|
+
}
|
|
5497
|
+
scheduling = false;
|
|
5498
|
+
if (invokedSynchronously) {
|
|
5499
|
+
flushScheduled = false;
|
|
5500
|
+
stop();
|
|
5501
|
+
}
|
|
5502
|
+
}
|
|
5503
|
+
function flush() {
|
|
5504
|
+
if (closed) return;
|
|
5505
|
+
if (!stream.writable) {
|
|
5506
|
+
stop();
|
|
5507
|
+
return;
|
|
5508
|
+
}
|
|
5509
|
+
while (pending.length > 0) {
|
|
5510
|
+
if (stream.writableNeedDrain) {
|
|
5511
|
+
if (!waitingForDrain) {
|
|
5512
|
+
waitingForDrain = true;
|
|
5513
|
+
stream.once("drain", onDrain);
|
|
5514
|
+
}
|
|
5515
|
+
return;
|
|
5516
|
+
}
|
|
5517
|
+
const next = pending.shift();
|
|
5518
|
+
if (next === void 0) return;
|
|
5519
|
+
pendingBytes -= next.bytes;
|
|
5520
|
+
let accepted;
|
|
5521
|
+
try {
|
|
5522
|
+
accepted = stream.write(next.line);
|
|
5523
|
+
} catch {
|
|
5524
|
+
stop();
|
|
5525
|
+
return;
|
|
5526
|
+
}
|
|
5527
|
+
if (!accepted) {
|
|
5528
|
+
waitingForDrain = true;
|
|
5529
|
+
stream.once("drain", onDrain);
|
|
5530
|
+
return;
|
|
5531
|
+
}
|
|
5532
|
+
}
|
|
5533
|
+
if (droppedLines > 0) {
|
|
5534
|
+
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
5535
|
+
`;
|
|
5536
|
+
droppedLines = 0;
|
|
5537
|
+
try {
|
|
5538
|
+
onDeliveryGap(line);
|
|
5539
|
+
} catch {
|
|
5540
|
+
}
|
|
5541
|
+
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
5542
|
+
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
5543
|
+
flush();
|
|
5544
|
+
}
|
|
5545
|
+
}
|
|
5546
|
+
stream.on("close", onTerminal);
|
|
5547
|
+
stream.on("finish", onTerminal);
|
|
5548
|
+
stream.on("error", onError);
|
|
5549
|
+
return (line) => {
|
|
5550
|
+
if (closed) return;
|
|
5551
|
+
const bytes = Buffer.byteLength(line, "utf8");
|
|
5552
|
+
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
5553
|
+
droppedLines += 1;
|
|
5554
|
+
scheduleFlush();
|
|
5555
|
+
return;
|
|
5556
|
+
}
|
|
5557
|
+
pending.push({ line, bytes });
|
|
5558
|
+
pendingBytes += bytes;
|
|
5559
|
+
scheduleFlush();
|
|
5560
|
+
};
|
|
5561
|
+
}
|
|
5562
|
+
|
|
5563
|
+
// host/service-log.ts
|
|
5564
|
+
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
5565
|
+
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
5566
|
+
void persistHostServiceLogLine(line);
|
|
5567
|
+
});
|
|
5568
|
+
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
5569
|
+
const details = diagnosticDetails(event, failure_kind, cause);
|
|
5570
|
+
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
5571
|
+
`;
|
|
5572
|
+
try {
|
|
5573
|
+
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
5574
|
+
} catch {
|
|
5575
|
+
}
|
|
5576
|
+
}
|
|
5577
|
+
function diagnosticDetails(event, failureKind, cause) {
|
|
5578
|
+
if (event === "watcher_scan_failed") return {
|
|
5579
|
+
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
5580
|
+
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
5581
|
+
};
|
|
5582
|
+
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
5583
|
+
}
|
|
5584
|
+
function validDiagnosticCause(cause, event) {
|
|
5585
|
+
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
5586
|
+
}
|
|
5587
|
+
function defaultHostServiceDiagnosticSink(line) {
|
|
5588
|
+
writeHostServiceLogLine(line);
|
|
5589
|
+
}
|
|
5590
|
+
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
5591
|
+
function writeHostServiceLogLine(line, environment = process.env) {
|
|
5592
|
+
void persistHostServiceLogLine(line, environment);
|
|
5593
|
+
defaultHostServiceLogDelivery(line);
|
|
5594
|
+
}
|
|
5595
|
+
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
5596
|
+
if (process.platform !== "win32") return;
|
|
5597
|
+
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
5598
|
+
if (path === void 0 || !win323.isAbsolute(path) || win323.normalize(path) !== path) return;
|
|
5599
|
+
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
5600
|
+
}
|
|
5601
|
+
async function appendHostServiceLogLine(path, line) {
|
|
5602
|
+
if (!isAbsolute2(path)) return;
|
|
5603
|
+
await ensureHostServiceLogDirectory(path);
|
|
5604
|
+
await appendFile(path, line);
|
|
5605
|
+
}
|
|
5606
|
+
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
5607
|
+
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
5608
|
+
function ensureHostServiceLogDirectory(path) {
|
|
5609
|
+
const directory = dirname2(path);
|
|
5610
|
+
const existing = hostServiceLogDirectories.get(directory);
|
|
5611
|
+
if (existing !== void 0) return existing;
|
|
5612
|
+
const pending = mkdir(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
5613
|
+
hostServiceLogDirectories.delete(directory);
|
|
5614
|
+
throw error;
|
|
5615
|
+
});
|
|
5616
|
+
hostServiceLogDirectories.set(directory, pending);
|
|
5617
|
+
return pending;
|
|
5618
|
+
}
|
|
5619
|
+
|
|
5186
5620
|
// host/relay/src/host-producer-core.ts
|
|
5187
5621
|
var HOST_TRANSCRIPT_CURSOR_REASONS = vocabulary(["transcript_replaced", "transcript_truncated", "transcript_rewritten", "transcript_malformed"]);
|
|
5188
5622
|
function isHostTranscriptCursorReason(value) {
|
|
@@ -5206,9 +5640,9 @@ function mergeHostInvocationHumanMessageWindow(existing, chronological) {
|
|
|
5206
5640
|
}
|
|
5207
5641
|
return boundCealHostInvocationHumanMessageWindow(newestFirst, existing?.truncated ?? false);
|
|
5208
5642
|
}
|
|
5209
|
-
async function readRegisteredHostInvocationHumanMessageWindow(
|
|
5643
|
+
async function readRegisteredHostInvocationHumanMessageWindow(readRegistration, readCursor, identity, decodeLine) {
|
|
5210
5644
|
try {
|
|
5211
|
-
const registration = await findLiveHostInvocationRegistration(
|
|
5645
|
+
const registration = await findLiveHostInvocationRegistration(readRegistration, identity);
|
|
5212
5646
|
const cursor = await readCursor(registration);
|
|
5213
5647
|
assertUsableHostInvocationHumanMessageCursor(cursor, registration);
|
|
5214
5648
|
return await readHostInvocationHumanMessageWindow(registration, cursor, (line) => decodeLine(line, registration, cursor));
|
|
@@ -5216,9 +5650,9 @@ async function readRegisteredHostInvocationHumanMessageWindow(listRegistrations,
|
|
|
5216
5650
|
throw new TypeError("context_unavailable");
|
|
5217
5651
|
}
|
|
5218
5652
|
}
|
|
5219
|
-
async function findLiveHostInvocationRegistration(
|
|
5220
|
-
const registration =
|
|
5221
|
-
if (registration ===
|
|
5653
|
+
async function findLiveHostInvocationRegistration(readRegistration, identity) {
|
|
5654
|
+
const registration = await readRegistration(identity);
|
|
5655
|
+
if (registration === null || registration.host_source_ref !== identity.host_source_ref || registration.host_session_ref !== identity.host_session_ref || !(Date.parse(registration.expires_at) > Date.now())) throw new TypeError("context_unavailable");
|
|
5222
5656
|
return registration;
|
|
5223
5657
|
}
|
|
5224
5658
|
function assertUsableHostInvocationHumanMessageCursor(cursor, registration) {
|
|
@@ -5285,9 +5719,9 @@ async function readTranscriptCompleteChunk(handle, offset, size) {
|
|
|
5285
5719
|
let lastNewline = -1;
|
|
5286
5720
|
while (position < size) {
|
|
5287
5721
|
const buffer = Buffer.alloc(Math.min(HOST_TRANSCRIPT_READ_CHUNK_BYTES, size - position));
|
|
5288
|
-
const
|
|
5289
|
-
if (
|
|
5290
|
-
const chunk = buffer.subarray(0,
|
|
5722
|
+
const read2 = await handle.read(buffer, 0, buffer.length, position);
|
|
5723
|
+
if (read2.bytesRead === 0) break;
|
|
5724
|
+
const chunk = buffer.subarray(0, read2.bytesRead);
|
|
5291
5725
|
chunks.push(chunk);
|
|
5292
5726
|
const newline = chunk.lastIndexOf(10);
|
|
5293
5727
|
if (newline >= 0) lastNewline = total + newline;
|
|
@@ -5344,7 +5778,7 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
5344
5778
|
outboxRetentionMs: options.retention_ms ?? owner.default_retention_ms,
|
|
5345
5779
|
now: options.now ?? (() => /* @__PURE__ */ new Date()),
|
|
5346
5780
|
log: options.log ?? ((line) => {
|
|
5347
|
-
|
|
5781
|
+
writeHostServiceLogLine(`${line}
|
|
5348
5782
|
`);
|
|
5349
5783
|
}),
|
|
5350
5784
|
producerInstallationRef: options.producer_installation_ref
|
|
@@ -5384,7 +5818,13 @@ var HostTranscriptWatcher = class {
|
|
|
5384
5818
|
}
|
|
5385
5819
|
async scanRegistration(registration) {
|
|
5386
5820
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
5387
|
-
missing: () =>
|
|
5821
|
+
missing: async () => {
|
|
5822
|
+
try {
|
|
5823
|
+
return await this.retireMissing(registration);
|
|
5824
|
+
} catch (error) {
|
|
5825
|
+
return this.scanFailed(void 0, registration, error);
|
|
5826
|
+
}
|
|
5827
|
+
},
|
|
5388
5828
|
failed: (handle, error) => this.scanFailed(handle, registration, error)
|
|
5389
5829
|
});
|
|
5390
5830
|
}
|
|
@@ -5454,21 +5894,21 @@ var HostProducerDrainCore = class {
|
|
|
5454
5894
|
return run;
|
|
5455
5895
|
}
|
|
5456
5896
|
async drainLocked() {
|
|
5457
|
-
const
|
|
5897
|
+
const read2 = await this.host.listEnvelopes();
|
|
5458
5898
|
let removed = 0;
|
|
5459
5899
|
let expired = 0;
|
|
5460
|
-
for (const envelope of
|
|
5900
|
+
for (const envelope of read2.entries) {
|
|
5461
5901
|
if (Date.parse(this.host.expiresAtOf(envelope)) <= this.now().getTime()) expired += 1;
|
|
5462
5902
|
else removed += 1;
|
|
5463
5903
|
await this.host.removeEnvelope(envelope);
|
|
5464
5904
|
}
|
|
5465
|
-
return { removed, expired, malformed:
|
|
5905
|
+
return { removed, expired, malformed: read2.malformed };
|
|
5466
5906
|
}
|
|
5467
5907
|
};
|
|
5468
5908
|
|
|
5469
5909
|
// host/relay/src/durable-atomic-replacement.ts
|
|
5470
|
-
import { lstat as lstat2, mkdir, open as open3, rename, unlink } from "node:fs/promises";
|
|
5471
|
-
import { dirname as
|
|
5910
|
+
import { lstat as lstat2, mkdir as mkdir2, open as open3, rename, unlink } from "node:fs/promises";
|
|
5911
|
+
import { dirname as dirname3 } from "node:path";
|
|
5472
5912
|
|
|
5473
5913
|
// host/windows-rename-retry.ts
|
|
5474
5914
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
@@ -5521,7 +5961,7 @@ function isRetryableRenameError(error) {
|
|
|
5521
5961
|
// host/relay/src/durable-atomic-replacement.ts
|
|
5522
5962
|
var DEFAULT_PORT = {
|
|
5523
5963
|
platform: process.platform,
|
|
5524
|
-
mkdir: (path, options) =>
|
|
5964
|
+
mkdir: (path, options) => mkdir2(path, options),
|
|
5525
5965
|
lstat: (path) => lstat2(path),
|
|
5526
5966
|
open_file: (path) => open3(path, "wx", 384),
|
|
5527
5967
|
rename,
|
|
@@ -5530,7 +5970,7 @@ var DEFAULT_PORT = {
|
|
|
5530
5970
|
unique_ref: () => `${process.pid}.${crypto.randomUUID()}`
|
|
5531
5971
|
};
|
|
5532
5972
|
async function durableAtomicReplace(target, data, port = DEFAULT_PORT) {
|
|
5533
|
-
const parent =
|
|
5973
|
+
const parent = dirname3(target);
|
|
5534
5974
|
await port.mkdir(parent, { recursive: true, mode: 448 });
|
|
5535
5975
|
const parentStats = await port.lstat(parent);
|
|
5536
5976
|
const expectedUid = typeof process.geteuid === "function" ? process.geteuid() : parentStats.uid;
|
|
@@ -5600,8 +6040,8 @@ function errorCode2(error) {
|
|
|
5600
6040
|
// host/relay/src/host-usage-facts-store.ts
|
|
5601
6041
|
import { createHash as createHash6 } from "node:crypto";
|
|
5602
6042
|
import { constants as constants2 } from "node:fs";
|
|
5603
|
-
import { mkdir as
|
|
5604
|
-
import { dirname as
|
|
6043
|
+
import { mkdir as mkdir3, open as open4, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
6044
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
5605
6045
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
5606
6046
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
5607
6047
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -5850,7 +6290,7 @@ var HostUsageFactsStore = class {
|
|
|
5850
6290
|
}
|
|
5851
6291
|
async writeImmutableBatch(state, batch, bytes) {
|
|
5852
6292
|
const path = this.batchPath(state, batch.batch_ref);
|
|
5853
|
-
await preparePrivateDirectory(
|
|
6293
|
+
await preparePrivateDirectory(dirname4(path), this.platform, this.custody);
|
|
5854
6294
|
const existing = await readOptionalBytes(path, CEAL_HOST_USAGE_BATCH_MAX_BYTES, this.platform, this.custody);
|
|
5855
6295
|
if (existing !== null) {
|
|
5856
6296
|
if (!existing.equals(bytes)) throw new Error("Host usage facts batch reference conflicts with existing bytes.");
|
|
@@ -5868,7 +6308,7 @@ var HostUsageFactsStore = class {
|
|
|
5868
6308
|
await handle.sync();
|
|
5869
6309
|
await handle.close();
|
|
5870
6310
|
handle = void 0;
|
|
5871
|
-
await syncDirectory(
|
|
6311
|
+
await syncDirectory(dirname4(path), this.platform);
|
|
5872
6312
|
} catch (error) {
|
|
5873
6313
|
await handle?.close().catch(() => void 0);
|
|
5874
6314
|
if (errorCode3(error) === "EEXIST") {
|
|
@@ -5912,14 +6352,14 @@ var HostUsageFactsStore = class {
|
|
|
5912
6352
|
const gate = new Promise((resolve) => {
|
|
5913
6353
|
release = resolve;
|
|
5914
6354
|
});
|
|
5915
|
-
const
|
|
5916
|
-
SESSION_TRANSITION_TAILS.set(key,
|
|
6355
|
+
const tail2 = previous.then(() => gate);
|
|
6356
|
+
SESSION_TRANSITION_TAILS.set(key, tail2);
|
|
5917
6357
|
await previous;
|
|
5918
6358
|
try {
|
|
5919
6359
|
return await run();
|
|
5920
6360
|
} finally {
|
|
5921
6361
|
release?.();
|
|
5922
|
-
if (SESSION_TRANSITION_TAILS.get(key) ===
|
|
6362
|
+
if (SESSION_TRANSITION_TAILS.get(key) === tail2) SESSION_TRANSITION_TAILS.delete(key);
|
|
5923
6363
|
}
|
|
5924
6364
|
}
|
|
5925
6365
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
@@ -6122,7 +6562,7 @@ async function preparePrivateDirectory(path, platform, custody) {
|
|
|
6122
6562
|
await ensurePrivateDirectoryWithSecurefs(path, custody);
|
|
6123
6563
|
return;
|
|
6124
6564
|
}
|
|
6125
|
-
await
|
|
6565
|
+
await mkdir3(path, { recursive: true, mode: 448 });
|
|
6126
6566
|
if (!await isPrivateDirectory(path, platform)) throw new Error("Host usage facts directory is not owner private.");
|
|
6127
6567
|
}
|
|
6128
6568
|
async function syncExistingFile(path, platform) {
|
|
@@ -6132,7 +6572,7 @@ async function syncExistingFile(path, platform) {
|
|
|
6132
6572
|
} finally {
|
|
6133
6573
|
await handle.close();
|
|
6134
6574
|
}
|
|
6135
|
-
await syncDirectory(
|
|
6575
|
+
await syncDirectory(dirname4(path), platform);
|
|
6136
6576
|
}
|
|
6137
6577
|
async function syncDirectory(path, platform) {
|
|
6138
6578
|
if (platform === "win32") return;
|
|
@@ -6180,29 +6620,46 @@ var HostUsageTranscriptSourceError = class extends Error {
|
|
|
6180
6620
|
this.name = "HostUsageTranscriptSourceError";
|
|
6181
6621
|
}
|
|
6182
6622
|
};
|
|
6183
|
-
async function readHostUsageTranscriptSource(
|
|
6623
|
+
async function readHostUsageTranscriptSource(read2) {
|
|
6184
6624
|
try {
|
|
6185
|
-
return await
|
|
6625
|
+
return await read2();
|
|
6186
6626
|
} catch (error) {
|
|
6187
6627
|
throw new HostUsageTranscriptSourceError({ cause: error });
|
|
6188
6628
|
}
|
|
6189
6629
|
}
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6630
|
+
var HostUsageRegistrationCapture = class {
|
|
6631
|
+
nextIndex = 0;
|
|
6632
|
+
producer;
|
|
6633
|
+
diagnosticSink;
|
|
6634
|
+
constructor(producer, diagnosticSink) {
|
|
6635
|
+
this.producer = producer;
|
|
6636
|
+
this.diagnosticSink = diagnosticSink;
|
|
6637
|
+
}
|
|
6638
|
+
async captureNext(registrations, capture) {
|
|
6639
|
+
let failed = false;
|
|
6640
|
+
let captured = false;
|
|
6641
|
+
const onFailure = () => {
|
|
6201
6642
|
failed = true;
|
|
6643
|
+
};
|
|
6644
|
+
for (let attempt = 0; attempt < registrations.length; attempt += 1) {
|
|
6645
|
+
const index = (this.nextIndex + attempt) % registrations.length;
|
|
6646
|
+
const registration = registrations[index];
|
|
6647
|
+
if (registration === void 0) continue;
|
|
6648
|
+
try {
|
|
6649
|
+
captured = await capture(registration, onFailure);
|
|
6650
|
+
if (captured) {
|
|
6651
|
+
this.nextIndex = (index + 1) % registrations.length;
|
|
6652
|
+
break;
|
|
6653
|
+
}
|
|
6654
|
+
} catch (error) {
|
|
6655
|
+
if (!(error instanceof HostUsageTranscriptSourceError)) throw error;
|
|
6656
|
+
onFailure();
|
|
6657
|
+
}
|
|
6202
6658
|
}
|
|
6659
|
+
if (failed) writeHostServiceDiagnostic(this.producer, "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
6660
|
+
return captured;
|
|
6203
6661
|
}
|
|
6204
|
-
|
|
6205
|
-
}
|
|
6662
|
+
};
|
|
6206
6663
|
async function openHostUsageTranscriptCursor(input) {
|
|
6207
6664
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants3.O_RDONLY));
|
|
6208
6665
|
let source;
|
|
@@ -6273,16 +6730,16 @@ function completeLinePrefix(bytes, baseOffset) {
|
|
|
6273
6730
|
|
|
6274
6731
|
// host/relay/src/host-registration-state.ts
|
|
6275
6732
|
import { constants as constants4 } from "node:fs";
|
|
6276
|
-
import { dirname as
|
|
6733
|
+
import { dirname as dirname5 } from "node:path";
|
|
6277
6734
|
|
|
6278
6735
|
// host/runtime-source-paths.ts
|
|
6279
6736
|
import { createHash as createHash7 } from "node:crypto";
|
|
6280
|
-
import { posix as
|
|
6737
|
+
import { posix as posix3, win32 as win325 } from "node:path";
|
|
6281
6738
|
|
|
6282
6739
|
// host/absolute-path.ts
|
|
6283
|
-
import { posix, win32 as
|
|
6740
|
+
import { posix as posix2, win32 as win324 } from "node:path";
|
|
6284
6741
|
function isAbsoluteNormalizedNonRootPath(value, flavor = process.platform, allowRoot = false) {
|
|
6285
|
-
const pathApi = flavor === "win32" || flavor === "windows" ?
|
|
6742
|
+
const pathApi = flavor === "win32" || flavor === "windows" ? win324 : posix2;
|
|
6286
6743
|
return typeof value === "string" && value.length <= 4096 && !value.includes("\0") && pathApi.isAbsolute(value) && pathApi.normalize(value) === value && (allowRoot || pathApi.parse(value).root !== value);
|
|
6287
6744
|
}
|
|
6288
6745
|
|
|
@@ -6326,7 +6783,7 @@ function macosHostRelayIpcDirectory(uid = process.geteuid?.() ?? -1) {
|
|
|
6326
6783
|
function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platform, uid = process.geteuid?.() ?? -1) {
|
|
6327
6784
|
const sourceId = hostSourceUuid(sourceRef);
|
|
6328
6785
|
if (!isAbsoluteNormalizedNonRootPath(stateRoot, platform) || sourceId === null) throw new TypeError("Host runtime source identity is invalid.");
|
|
6329
|
-
const path = platform === "win32" ?
|
|
6786
|
+
const path = platform === "win32" ? win325 : posix3;
|
|
6330
6787
|
const sourcesRoot = path.join(stateRoot, "sources");
|
|
6331
6788
|
const sourceRoot = path.join(sourcesRoot, sourceId);
|
|
6332
6789
|
const runtimeRoot = path.join(stateRoot, "run");
|
|
@@ -6337,7 +6794,7 @@ function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platfor
|
|
|
6337
6794
|
function projectRelayEndpoint(stateRoot, sourceRef, rooted, platform, uid) {
|
|
6338
6795
|
if (platform !== "win32" && (platform !== "darwin" || Buffer.byteLength(rooted, "utf8") <= PORTABLE_UNIX_SOCKET_PATH_MAX_BYTES)) return rooted;
|
|
6339
6796
|
const digest2 = createHash7("sha256").update(`${stateRoot}\0${sourceRef}`).digest("hex");
|
|
6340
|
-
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` :
|
|
6797
|
+
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` : posix3.join(macosHostRelayIpcDirectory(uid), `${digest2}.sock`);
|
|
6341
6798
|
}
|
|
6342
6799
|
function assertHostProducerSourcePaths(stateRoot, config, producer, platform = process.platform) {
|
|
6343
6800
|
const paths = hostRuntimeSourcePaths(stateRoot, config.host_source_ref, platform);
|
|
@@ -6365,7 +6822,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
6365
6822
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
6366
6823
|
let raw;
|
|
6367
6824
|
try {
|
|
6368
|
-
await assertPrivateRegistrationDirectory(
|
|
6825
|
+
await assertPrivateRegistrationDirectory(dirname5(path), platform, custody);
|
|
6369
6826
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
6370
6827
|
} catch (error) {
|
|
6371
6828
|
throw registrationReadError(error);
|
|
@@ -6470,185 +6927,6 @@ function waitForAbort(signal, milliseconds) {
|
|
|
6470
6927
|
});
|
|
6471
6928
|
}
|
|
6472
6929
|
|
|
6473
|
-
// host/service-log.ts
|
|
6474
|
-
import { copyFile, mkdir as mkdir3, stat as stat2, truncate, appendFile } from "node:fs/promises";
|
|
6475
|
-
import { dirname as dirname5, isAbsolute as isAbsolute2, posix as posix3, win32 as win325 } from "node:path";
|
|
6476
|
-
|
|
6477
|
-
// host/service-log-delivery.ts
|
|
6478
|
-
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
6479
|
-
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
6480
|
-
setImmediate(flush);
|
|
6481
|
-
}, onDeliveryGap = () => void 0) {
|
|
6482
|
-
const pending = [];
|
|
6483
|
-
const highWaterMark = stream.writableHighWaterMark;
|
|
6484
|
-
const byteBudget = highWaterMark + highWaterMark;
|
|
6485
|
-
let pendingBytes = 0;
|
|
6486
|
-
let droppedLines = 0;
|
|
6487
|
-
let flushScheduled = false;
|
|
6488
|
-
let waitingForDrain = false;
|
|
6489
|
-
let closed = !stream.writable;
|
|
6490
|
-
function stop() {
|
|
6491
|
-
if (closed) return;
|
|
6492
|
-
closed = true;
|
|
6493
|
-
pending.length = 0;
|
|
6494
|
-
pendingBytes = 0;
|
|
6495
|
-
stream.off("drain", onDrain);
|
|
6496
|
-
stream.off("close", onTerminal);
|
|
6497
|
-
stream.off("finish", onTerminal);
|
|
6498
|
-
stream.off("error", onError);
|
|
6499
|
-
}
|
|
6500
|
-
function onTerminal() {
|
|
6501
|
-
stop();
|
|
6502
|
-
}
|
|
6503
|
-
function onError() {
|
|
6504
|
-
stop();
|
|
6505
|
-
}
|
|
6506
|
-
function onDrain() {
|
|
6507
|
-
waitingForDrain = false;
|
|
6508
|
-
scheduleFlush();
|
|
6509
|
-
}
|
|
6510
|
-
function scheduleFlush() {
|
|
6511
|
-
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
6512
|
-
flushScheduled = true;
|
|
6513
|
-
let scheduling = true;
|
|
6514
|
-
let invokedSynchronously = false;
|
|
6515
|
-
try {
|
|
6516
|
-
schedule(() => {
|
|
6517
|
-
if (scheduling) {
|
|
6518
|
-
invokedSynchronously = true;
|
|
6519
|
-
return;
|
|
6520
|
-
}
|
|
6521
|
-
flushScheduled = false;
|
|
6522
|
-
flush();
|
|
6523
|
-
});
|
|
6524
|
-
} catch {
|
|
6525
|
-
flushScheduled = false;
|
|
6526
|
-
stop();
|
|
6527
|
-
return;
|
|
6528
|
-
}
|
|
6529
|
-
scheduling = false;
|
|
6530
|
-
if (invokedSynchronously) {
|
|
6531
|
-
flushScheduled = false;
|
|
6532
|
-
stop();
|
|
6533
|
-
}
|
|
6534
|
-
}
|
|
6535
|
-
function flush() {
|
|
6536
|
-
if (closed) return;
|
|
6537
|
-
if (!stream.writable) {
|
|
6538
|
-
stop();
|
|
6539
|
-
return;
|
|
6540
|
-
}
|
|
6541
|
-
while (pending.length > 0) {
|
|
6542
|
-
if (stream.writableNeedDrain) {
|
|
6543
|
-
if (!waitingForDrain) {
|
|
6544
|
-
waitingForDrain = true;
|
|
6545
|
-
stream.once("drain", onDrain);
|
|
6546
|
-
}
|
|
6547
|
-
return;
|
|
6548
|
-
}
|
|
6549
|
-
const next = pending.shift();
|
|
6550
|
-
if (next === void 0) return;
|
|
6551
|
-
pendingBytes -= next.bytes;
|
|
6552
|
-
let accepted;
|
|
6553
|
-
try {
|
|
6554
|
-
accepted = stream.write(next.line);
|
|
6555
|
-
} catch {
|
|
6556
|
-
stop();
|
|
6557
|
-
return;
|
|
6558
|
-
}
|
|
6559
|
-
if (!accepted) {
|
|
6560
|
-
waitingForDrain = true;
|
|
6561
|
-
stream.once("drain", onDrain);
|
|
6562
|
-
return;
|
|
6563
|
-
}
|
|
6564
|
-
}
|
|
6565
|
-
if (droppedLines > 0) {
|
|
6566
|
-
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
6567
|
-
`;
|
|
6568
|
-
droppedLines = 0;
|
|
6569
|
-
try {
|
|
6570
|
-
onDeliveryGap(line);
|
|
6571
|
-
} catch {
|
|
6572
|
-
}
|
|
6573
|
-
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
6574
|
-
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
6575
|
-
flush();
|
|
6576
|
-
}
|
|
6577
|
-
}
|
|
6578
|
-
stream.on("close", onTerminal);
|
|
6579
|
-
stream.on("finish", onTerminal);
|
|
6580
|
-
stream.on("error", onError);
|
|
6581
|
-
return (line) => {
|
|
6582
|
-
if (closed) return;
|
|
6583
|
-
const bytes = Buffer.byteLength(line, "utf8");
|
|
6584
|
-
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
6585
|
-
droppedLines += 1;
|
|
6586
|
-
scheduleFlush();
|
|
6587
|
-
return;
|
|
6588
|
-
}
|
|
6589
|
-
pending.push({ line, bytes });
|
|
6590
|
-
pendingBytes += bytes;
|
|
6591
|
-
scheduleFlush();
|
|
6592
|
-
};
|
|
6593
|
-
}
|
|
6594
|
-
|
|
6595
|
-
// host/service-log.ts
|
|
6596
|
-
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
6597
|
-
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
6598
|
-
void persistHostServiceLogLine(line);
|
|
6599
|
-
});
|
|
6600
|
-
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
6601
|
-
const details = diagnosticDetails(event, failure_kind, cause);
|
|
6602
|
-
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
6603
|
-
`;
|
|
6604
|
-
try {
|
|
6605
|
-
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
6606
|
-
} catch {
|
|
6607
|
-
}
|
|
6608
|
-
}
|
|
6609
|
-
function diagnosticDetails(event, failureKind, cause) {
|
|
6610
|
-
if (event === "watcher_scan_failed") return {
|
|
6611
|
-
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
6612
|
-
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
6613
|
-
};
|
|
6614
|
-
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
6615
|
-
}
|
|
6616
|
-
function validDiagnosticCause(cause, event) {
|
|
6617
|
-
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
6618
|
-
}
|
|
6619
|
-
function defaultHostServiceDiagnosticSink(line) {
|
|
6620
|
-
writeHostServiceLogLine(line);
|
|
6621
|
-
}
|
|
6622
|
-
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
6623
|
-
function writeHostServiceLogLine(line, environment = process.env) {
|
|
6624
|
-
void persistHostServiceLogLine(line, environment);
|
|
6625
|
-
defaultHostServiceLogDelivery(line);
|
|
6626
|
-
}
|
|
6627
|
-
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
6628
|
-
if (process.platform !== "win32") return;
|
|
6629
|
-
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
6630
|
-
if (path === void 0 || !win325.isAbsolute(path) || win325.normalize(path) !== path) return;
|
|
6631
|
-
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
6632
|
-
}
|
|
6633
|
-
async function appendHostServiceLogLine(path, line) {
|
|
6634
|
-
if (!isAbsolute2(path)) return;
|
|
6635
|
-
await ensureHostServiceLogDirectory(path);
|
|
6636
|
-
await appendFile(path, line);
|
|
6637
|
-
}
|
|
6638
|
-
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
6639
|
-
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
6640
|
-
function ensureHostServiceLogDirectory(path) {
|
|
6641
|
-
const directory = dirname5(path);
|
|
6642
|
-
const existing = hostServiceLogDirectories.get(directory);
|
|
6643
|
-
if (existing !== void 0) return existing;
|
|
6644
|
-
const pending = mkdir3(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
6645
|
-
hostServiceLogDirectories.delete(directory);
|
|
6646
|
-
throw error;
|
|
6647
|
-
});
|
|
6648
|
-
hostServiceLogDirectories.set(directory, pending);
|
|
6649
|
-
return pending;
|
|
6650
|
-
}
|
|
6651
|
-
|
|
6652
6930
|
// host/relay/src/host-usage-facts-uploader.ts
|
|
6653
6931
|
var HostUsageFactsUploader = class {
|
|
6654
6932
|
options;
|
|
@@ -6667,7 +6945,7 @@ var HostUsageFactsUploader = class {
|
|
|
6667
6945
|
const registration = await readHostRegistrationAuthority(this.options.registration_state_file, this.options.host_source_ref, this.options.store_options?.platform, this.options.store_options?.secure_file_custody);
|
|
6668
6946
|
const timeout = AbortSignal.timeout(this.options.timeout_ms ?? 5e3);
|
|
6669
6947
|
const requestSignal = signal === void 0 ? timeout : AbortSignal.any([signal, timeout]);
|
|
6670
|
-
const response2 = await
|
|
6948
|
+
const response2 = await this.options.fetch(`${registration.gateway_request_origin}${CEAL_HOST_USAGE_INGRESS_PATH}`, {
|
|
6671
6949
|
method: "POST",
|
|
6672
6950
|
headers: { authorization: `Bearer ${registration.host_access_token}`, "content-type": "application/json" },
|
|
6673
6951
|
body: JSON.stringify(candidate.batch),
|
|
@@ -7234,36 +7512,67 @@ var HostInvocationAuthenticationRefusal = class extends Error {
|
|
|
7234
7512
|
if (diagnosticCause !== void 0) this.diagnostic_cause = diagnosticCause;
|
|
7235
7513
|
}
|
|
7236
7514
|
};
|
|
7237
|
-
|
|
7515
|
+
var INSTALLED_HOST_INVOCATION_AUTHENTICATION_DEPENDENCIES = {
|
|
7516
|
+
process_elapsed_ms: () => performance.now(),
|
|
7517
|
+
load_pipe_key: async (outboxDirectory) => process.platform === "win32" ? loadRelayPipeKey(relayPipeStateRootForOutboxDir(outboxDirectory)) : void 0,
|
|
7518
|
+
create_relay_port: (endpoint, pipeKey, timeoutMs) => new HostRelayInvocationContextPort(endpoint, pipeKey, timeoutMs)
|
|
7519
|
+
};
|
|
7520
|
+
function installedHostInvocationAuthenticationCommandOptions(config, contextBudgetMs, maxContextWaitMs, dependencies) {
|
|
7238
7521
|
let pipeKey;
|
|
7239
7522
|
const loadPipeKey = () => {
|
|
7240
|
-
if (pipeKey === void 0) pipeKey =
|
|
7523
|
+
if (pipeKey === void 0) pipeKey = dependencies.load_pipe_key(config.outbox_dir);
|
|
7241
7524
|
return pipeKey;
|
|
7242
7525
|
};
|
|
7526
|
+
const remainingBudget = () => remainingAuthenticationBudget(contextBudgetMs, dependencies.process_elapsed_ms());
|
|
7243
7527
|
return {
|
|
7244
7528
|
host_source_ref: config.host_source_ref,
|
|
7245
7529
|
outbox_dir: config.outbox_dir,
|
|
7246
7530
|
producer_installation_ref: config.producer_installation_ref,
|
|
7247
|
-
context_activation_wait_ms: boundedContextActivationWait(
|
|
7248
|
-
|
|
7531
|
+
context_activation_wait_ms: boundedContextActivationWait(remainingBudget() ?? 0, config.ipc_timeout_ms, maxContextWaitMs),
|
|
7532
|
+
monotonic_now: dependencies.process_elapsed_ms,
|
|
7533
|
+
...dependencies.wait === void 0 ? {} : { wait: dependencies.wait },
|
|
7534
|
+
...dependencies.output_sink === void 0 ? {} : { output_sink: dependencies.output_sink },
|
|
7535
|
+
...dependencies.diagnostic_sink === void 0 ? {} : { diagnostic_sink: dependencies.diagnostic_sink },
|
|
7536
|
+
mint_invocation_context: async (input) => {
|
|
7537
|
+
requireMintExchangeTimeout(remainingBudget(), config.ipc_timeout_ms);
|
|
7538
|
+
const loadedPipeKey = await loadPipeKey();
|
|
7539
|
+
const timeoutMs = requireMintExchangeTimeout(remainingBudget(), config.ipc_timeout_ms);
|
|
7540
|
+
return dependencies.create_relay_port(config.relay_endpoint, loadedPipeKey, timeoutMs).mintInvocationContext(input);
|
|
7541
|
+
}
|
|
7249
7542
|
};
|
|
7250
7543
|
}
|
|
7251
|
-
|
|
7544
|
+
function remainingAuthenticationBudget(contextBudgetMs, processElapsedMs) {
|
|
7545
|
+
if (contextBudgetMs === void 0) return void 0;
|
|
7546
|
+
return Math.max(0, Math.floor(contextBudgetMs - processElapsedMs));
|
|
7547
|
+
}
|
|
7548
|
+
function requireMintExchangeTimeout(remainingBudgetMs, directTimeoutMs) {
|
|
7549
|
+
if (remainingBudgetMs === void 0) return directTimeoutMs;
|
|
7550
|
+
const timeoutMs = remainingBudgetMs - HOST_AUTHENTICATION_COMPLETION_RESERVE_MS;
|
|
7551
|
+
if (timeoutMs <= 0) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC timed out before minting could start.", "timed_out");
|
|
7552
|
+
return timeoutMs;
|
|
7553
|
+
}
|
|
7554
|
+
async function runHostInvocationAuthenticationCommand(descriptor2, args, options, installedDependencies = INSTALLED_HOST_INVOCATION_AUTHENTICATION_DEPENDENCIES) {
|
|
7252
7555
|
let sink = options?.output_sink;
|
|
7556
|
+
let diagnosticSink = options?.diagnostic_sink;
|
|
7253
7557
|
try {
|
|
7254
|
-
const resolved = await resolveOptions(descriptor2, args, options);
|
|
7558
|
+
const resolved = await resolveOptions(descriptor2, args, options, installedDependencies);
|
|
7255
7559
|
sink = resolved.options.output_sink;
|
|
7560
|
+
diagnosticSink = resolved.options.diagnostic_sink;
|
|
7256
7561
|
writeResult(await authenticateHostInvocation(descriptor2, resolved.input, resolved.options), sink);
|
|
7257
7562
|
return 0;
|
|
7258
7563
|
} catch (error) {
|
|
7259
|
-
|
|
7260
|
-
const refusal = error instanceof HostInvocationAuthenticationRefusal ? error : void 0;
|
|
7261
|
-
const gatewayStatus = refusal?.reason === "gateway_refused" && validGenericGatewayRefusalStatus2(refusal.gateway_status) ? refusal.gateway_status : void 0;
|
|
7262
|
-
writeHostServiceDiagnostic(descriptor2.producer_id, "invocation_authentication_failed", void 0, refusal?.diagnostic_cause ?? reason, options?.diagnostic_sink);
|
|
7263
|
-
writeResult({ schema_version: CEAL_HOST_INVOCATION_AUTHENTICATION_REFUSAL_SCHEMA, ok: false, code: "invocation_authentication_unavailable", reason, ...gatewayStatus === void 0 ? {} : { gateway_status: gatewayStatus } }, sink);
|
|
7264
|
-
return 2;
|
|
7564
|
+
return writeAuthenticationFailure(descriptor2.producer_id, error, sink, diagnosticSink);
|
|
7265
7565
|
}
|
|
7266
7566
|
}
|
|
7567
|
+
function writeAuthenticationFailure(producerId, error, sink, diagnosticSink) {
|
|
7568
|
+
const reason = authenticationRefusalReason(error);
|
|
7569
|
+
const refusal = error instanceof HostInvocationAuthenticationRefusal ? error : void 0;
|
|
7570
|
+
const gatewayStatus = refusal?.reason === "gateway_refused" && validGenericGatewayRefusalStatus2(refusal.gateway_status) ? refusal.gateway_status : void 0;
|
|
7571
|
+
const retryAfterMs = reason === "activation_wait_exhausted" ? INVOCATION_CONTEXT_POLL_INTERVAL_MS : void 0;
|
|
7572
|
+
writeHostServiceDiagnostic(producerId, "invocation_authentication_failed", void 0, refusal?.diagnostic_cause ?? reason, diagnosticSink);
|
|
7573
|
+
writeResult({ schema_version: CEAL_HOST_INVOCATION_AUTHENTICATION_REFUSAL_SCHEMA, ok: false, code: "invocation_authentication_unavailable", reason, ...gatewayStatus === void 0 ? {} : { gateway_status: gatewayStatus }, ...retryAfterMs === void 0 ? {} : { retry_after_ms: retryAfterMs } }, sink);
|
|
7574
|
+
return 2;
|
|
7575
|
+
}
|
|
7267
7576
|
function authenticationRefusalReason(error) {
|
|
7268
7577
|
const message = error instanceof Error ? error.message : "";
|
|
7269
7578
|
if (!REFUSAL_REASON_PATTERN.test(message)) return "host_refusal_invalid";
|
|
@@ -7327,8 +7636,7 @@ async function currentInvocation(descriptor2, config, now) {
|
|
|
7327
7636
|
let waitEngaged = false;
|
|
7328
7637
|
while (true) {
|
|
7329
7638
|
if (!firstCheck && monotonicNow() >= deadline) {
|
|
7330
|
-
|
|
7331
|
-
throw new TypeError("context_unavailable");
|
|
7639
|
+
throw activationWaitExhausted(descriptor2.producer_id, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
7332
7640
|
}
|
|
7333
7641
|
firstCheck = false;
|
|
7334
7642
|
const observedAt = now();
|
|
@@ -7340,8 +7648,7 @@ async function currentInvocation(descriptor2, config, now) {
|
|
|
7340
7648
|
await rejectWhenActivationWaitIsUnavailable(descriptor2, store, identity.identity, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
7341
7649
|
const remainingMs = deadline - monotonicNow();
|
|
7342
7650
|
if (remainingMs <= 0) {
|
|
7343
|
-
|
|
7344
|
-
throw new TypeError("context_unavailable");
|
|
7651
|
+
throw activationWaitExhausted(descriptor2.producer_id, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
7345
7652
|
}
|
|
7346
7653
|
recordActivationWaitEngagement(descriptor2.producer_id, waitEngaged, config.diagnostic_sink);
|
|
7347
7654
|
waitEngaged = true;
|
|
@@ -7349,9 +7656,13 @@ async function currentInvocation(descriptor2, config, now) {
|
|
|
7349
7656
|
await (config.wait ?? waitForContextActivation)(intervalMs);
|
|
7350
7657
|
}
|
|
7351
7658
|
}
|
|
7659
|
+
function activationWaitExhausted(producerId, waitEngaged, waitBudgetMs, diagnosticSink) {
|
|
7660
|
+
recordActivationWaitExhaustion(producerId, waitEngaged, waitBudgetMs, diagnosticSink);
|
|
7661
|
+
return new TypeError(waitEngaged ? "activation_wait_exhausted" : "context_unavailable");
|
|
7662
|
+
}
|
|
7352
7663
|
async function rejectWhenActivationWaitIsUnavailable(descriptor2, store, identity, waitEngaged, waitBudgetMs, sink) {
|
|
7353
|
-
if (waitEngaged || waitBudgetMs <= 0
|
|
7354
|
-
if (await descriptor2.can_wait_for_context_activation({ store, identity })) return;
|
|
7664
|
+
if (waitEngaged || waitBudgetMs <= 0) return;
|
|
7665
|
+
if (descriptor2.can_wait_for_context_activation !== void 0 && await descriptor2.can_wait_for_context_activation({ store, identity })) return;
|
|
7355
7666
|
writeHostServiceDiagnostic(descriptor2.producer_id, "activation_wait_skipped", void 0, void 0, sink);
|
|
7356
7667
|
throw new TypeError("context_unavailable");
|
|
7357
7668
|
}
|
|
@@ -7380,18 +7691,18 @@ function resolveIdentity(descriptor2, options) {
|
|
|
7380
7691
|
if (isHostSessionId(sessionId)) return { status: "ready", identity: { host_source_ref: options.host_source_ref, host_session_ref: descriptor2.session_ref(options.host_source_ref, sessionId) } };
|
|
7381
7692
|
return { status: "session_unavailable" };
|
|
7382
7693
|
}
|
|
7383
|
-
async function resolveOptions(descriptor2, args, options) {
|
|
7694
|
+
async function resolveOptions(descriptor2, args, options, installedDependencies) {
|
|
7384
7695
|
if (options !== void 0) return { input: [...args], options };
|
|
7385
7696
|
const configPath = descriptor2.parse_config_flag(args);
|
|
7386
7697
|
const config = await descriptor2.read_producer_config(configPath);
|
|
7387
7698
|
return {
|
|
7388
7699
|
input: args.filter((argument) => !argument.startsWith(`${descriptor2.config_flag}=`)),
|
|
7389
|
-
options: installedHostInvocationAuthenticationCommandOptions(config, authenticationBudgetMsFromEnvironment(), descriptor2.context_activation_wait_max_ms)
|
|
7700
|
+
options: installedHostInvocationAuthenticationCommandOptions(config, authenticationBudgetMsFromEnvironment(), descriptor2.context_activation_wait_max_ms, installedDependencies)
|
|
7390
7701
|
};
|
|
7391
7702
|
}
|
|
7392
7703
|
function authenticationBudgetMsFromEnvironment() {
|
|
7393
7704
|
const value = process.env[CEAL_HOST_AUTHENTICATION_BUDGET_ENVIRONMENT];
|
|
7394
|
-
if (value === void 0) return 0;
|
|
7705
|
+
if (value === void 0) return void 0;
|
|
7395
7706
|
if (!CEAL_HOST_AUTHENTICATION_BUDGET_PATTERN.test(value)) throw new TypeError("invalid_arguments");
|
|
7396
7707
|
return Number(value);
|
|
7397
7708
|
}
|
|
@@ -7604,7 +7915,7 @@ function parseCanonicalJson(text, error) {
|
|
|
7604
7915
|
if (canonical !== text.trim()) throw new Error(`noncanonical: ${refusalFacts([{ name: "config_bytes", value: Buffer.byteLength(text.trim(), "utf8"), expected: `the ${Buffer.byteLength(canonical, "utf8")} bytes of its canonical form` }, { name: "first_difference_index", value: firstDifferenceIndex(text.trim(), canonical) }])}`);
|
|
7605
7916
|
return value;
|
|
7606
7917
|
} catch (parseError) {
|
|
7607
|
-
throw error("invalid_config",
|
|
7918
|
+
throw error("invalid_config", `parse_error=${renderOperatorDiagnostic(parseError)}; ${refusalFact("config_bytes", Buffer.byteLength(text, "utf8"), "canonical JSON")}`);
|
|
7608
7919
|
}
|
|
7609
7920
|
}
|
|
7610
7921
|
function firstDifferenceIndex(left, right) {
|
|
@@ -8196,6 +8507,13 @@ var CodexOutboxStore = class {
|
|
|
8196
8507
|
await removeOwnerState(this.registrationPath(registration.host_source_ref, registration.host_session_ref), "registration");
|
|
8197
8508
|
await removeOwnerState(this.cursorPath(registration.host_source_ref, registration.host_session_ref), "cursor");
|
|
8198
8509
|
}
|
|
8510
|
+
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
8511
|
+
const path = this.registrationPath(hostSourceRef, hostSessionRef);
|
|
8512
|
+
await this.prepare();
|
|
8513
|
+
const registration = await readOptionalJson2(path, validateRegistration);
|
|
8514
|
+
if (registration !== null && (registration.host_source_ref !== hostSourceRef || registration.host_session_ref !== hostSessionRef)) throw storageError("Codex transcript registration identity does not match its session.");
|
|
8515
|
+
return registration;
|
|
8516
|
+
}
|
|
8199
8517
|
async listTranscriptRegistrations() {
|
|
8200
8518
|
await this.prepare();
|
|
8201
8519
|
const registrations = [];
|
|
@@ -8222,16 +8540,16 @@ var CodexOutboxStore = class {
|
|
|
8222
8540
|
}
|
|
8223
8541
|
async findByAlias(sourceRef, sessionRef, alias) {
|
|
8224
8542
|
if (!SAFE_REF6.test(sourceRef) || !SAFE_REF6.test(sessionRef) || !SAFE_REF6.test(alias)) return null;
|
|
8225
|
-
const
|
|
8226
|
-
const envelope = findEnvelopeByAlias(
|
|
8543
|
+
const read2 = await this.list();
|
|
8544
|
+
const envelope = findEnvelopeByAlias(read2.entries, sourceRef, sessionRef, alias);
|
|
8227
8545
|
if (envelope !== null) return envelopeMatch(envelope);
|
|
8228
8546
|
await this.prepare();
|
|
8229
8547
|
return null;
|
|
8230
8548
|
}
|
|
8231
8549
|
async hasPriorTurn(sourceRef, sessionRef) {
|
|
8232
8550
|
if (!SAFE_REF6.test(sourceRef) || !SAFE_REF6.test(sessionRef)) return false;
|
|
8233
|
-
const
|
|
8234
|
-
if (
|
|
8551
|
+
const read2 = await this.list();
|
|
8552
|
+
if (read2.entries.some((entry) => entry.identity.host_source_ref === sourceRef && entry.identity.host_session_ref === sessionRef)) return true;
|
|
8235
8553
|
return false;
|
|
8236
8554
|
}
|
|
8237
8555
|
entryPath(submissionRef) {
|
|
@@ -8287,7 +8605,7 @@ async function writeAtomicJson(path, value) {
|
|
|
8287
8605
|
if (text === void 0) throw storageError("Codex owner state cannot be serialized.");
|
|
8288
8606
|
const temp = `${path}.${process.pid}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
8289
8607
|
try {
|
|
8290
|
-
const handle = await open5(temp, "wx");
|
|
8608
|
+
const handle = await open5(temp, "wx", 384);
|
|
8291
8609
|
try {
|
|
8292
8610
|
await handle.writeFile(text, "utf8");
|
|
8293
8611
|
await handle.sync();
|
|
@@ -8329,13 +8647,20 @@ async function readOptionalJson2(path, validate) {
|
|
|
8329
8647
|
}
|
|
8330
8648
|
async function ensureOwnerDirectory(path) {
|
|
8331
8649
|
try {
|
|
8332
|
-
|
|
8650
|
+
try {
|
|
8651
|
+
const stats2 = await stat3(path);
|
|
8652
|
+
if (!stats2.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
8653
|
+
return;
|
|
8654
|
+
} catch (error) {
|
|
8655
|
+
if (!isNotFound(error)) throw error;
|
|
8656
|
+
}
|
|
8657
|
+
await mkdir5(path, { recursive: true, mode: 448 });
|
|
8658
|
+
const stats = await stat3(path);
|
|
8659
|
+
if (!stats.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
8333
8660
|
} catch (error) {
|
|
8334
|
-
if (
|
|
8335
|
-
|
|
8661
|
+
if (error instanceof CodexHostAdapterError) throw error;
|
|
8662
|
+
throw storageError("Codex owner state directory is unavailable.");
|
|
8336
8663
|
}
|
|
8337
|
-
const stats = await stat3(path);
|
|
8338
|
-
if (!stats.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
8339
8664
|
}
|
|
8340
8665
|
async function readOwnerStateFile(path) {
|
|
8341
8666
|
let handle;
|
|
@@ -8544,9 +8869,9 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
8544
8869
|
const { size, device, inode } = await ownedCodexTranscriptFile(handle);
|
|
8545
8870
|
const preflight = await this.preflight(registration, handle, size, device, inode);
|
|
8546
8871
|
if (preflight.cursor === null) return preflight.result;
|
|
8872
|
+
if (preflight.checkpointPending) await this.commitCursor(registration, handle, preflight.cursor, 0, device, inode, preflight.cursor.last_ordinal, preflight.cursor.active_task, preflight.cursor.human_message_window ?? { messages: [], truncated: false });
|
|
8547
8873
|
const complete = await this.readChunk(handle, preflight.cursor.offset, size);
|
|
8548
8874
|
if (complete === "empty" || complete === "partial") {
|
|
8549
|
-
if (preflight.projectionInitialized) await this.commitCursor(registration, handle, preflight.cursor, 0, device, inode, preflight.cursor.last_ordinal, preflight.cursor.active_task, preflight.cursor.human_message_window ?? { messages: [], truncated: false });
|
|
8550
8875
|
return { records: 0, enqueued: 0, quarantined: false };
|
|
8551
8876
|
}
|
|
8552
8877
|
return await this.consumeCompleteChunk(registration, handle, preflight.cursor, complete, device, inode);
|
|
@@ -8563,17 +8888,17 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
8563
8888
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
8564
8889
|
let cursor = existing ?? codexTranscriptInitialCursor(registration, device, inode, this.now);
|
|
8565
8890
|
if (cursor.status === "quarantined") {
|
|
8566
|
-
return { cursor: null,
|
|
8891
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
8567
8892
|
}
|
|
8568
8893
|
const reason = this.cursorIdentityReason(cursor, registration.transcript_path, device, inode) ?? await this.cursorBoundsReason(handle, cursor, size);
|
|
8569
8894
|
if (reason === null) {
|
|
8570
|
-
if (cursor.human_message_window !== void 0) return { cursor,
|
|
8895
|
+
if (cursor.human_message_window !== void 0) return { cursor, checkpointPending: existing === null, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
8571
8896
|
const humanWindow = await this.readHumanMessageProjection(handle, registration, cursor);
|
|
8572
|
-
return { cursor: { ...cursor, human_message_window: humanWindow },
|
|
8897
|
+
return { cursor: { ...cursor, human_message_window: humanWindow }, checkpointPending: true, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
8573
8898
|
}
|
|
8574
8899
|
await this.quarantine(registration, cursor, device, inode, reason);
|
|
8575
8900
|
this.diagnostic("watcher_scan_failed", "other", `cursor_${reason}`);
|
|
8576
|
-
return { cursor: null,
|
|
8901
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
8577
8902
|
}
|
|
8578
8903
|
async readHumanMessageProjection(handle, registration, cursor) {
|
|
8579
8904
|
return readCodexHumanMessageProjection(registration, cursor, (offset, size) => this.readChunk(handle, offset, size));
|
|
@@ -8886,20 +9211,16 @@ var CodexUsageFactsCapturer = class {
|
|
|
8886
9211
|
sources;
|
|
8887
9212
|
usage;
|
|
8888
9213
|
now;
|
|
8889
|
-
|
|
8890
|
-
nextRegistrationIndex = 0;
|
|
9214
|
+
registrations;
|
|
8891
9215
|
constructor(options) {
|
|
8892
9216
|
this.sources = new CodexOutboxStore(options.outbox_dir);
|
|
8893
9217
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
8894
9218
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
8895
|
-
this.
|
|
9219
|
+
this.registrations = new HostUsageRegistrationCapture("codex", options.diagnostic_sink);
|
|
8896
9220
|
}
|
|
8897
9221
|
async captureNext() {
|
|
8898
9222
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
8899
|
-
|
|
8900
|
-
this.nextRegistrationIndex = result.nextIndex;
|
|
8901
|
-
if (result.failed) writeHostServiceDiagnostic("codex", "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
8902
|
-
return result.captured;
|
|
9223
|
+
return await this.registrations.captureNext(registrations, (registration) => this.captureRegistration(registration));
|
|
8903
9224
|
}
|
|
8904
9225
|
async captureRegistration(registration) {
|
|
8905
9226
|
const prepared = await openHostUsageTranscriptCursor({
|
|
@@ -9067,12 +9388,11 @@ function normalizedCounts(selected) {
|
|
|
9067
9388
|
function nullCounts() {
|
|
9068
9389
|
return { input: null, output: null, total: null, cached_input: null, cache_write_input: null, reasoning_output: null };
|
|
9069
9390
|
}
|
|
9070
|
-
var USAGE_COUNT_FIELDS = ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"];
|
|
9071
9391
|
function isRegression(current, previous) {
|
|
9072
|
-
return
|
|
9392
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.some((key) => current[key] < previous[key]);
|
|
9073
9393
|
}
|
|
9074
9394
|
function sameCounts(left, right) {
|
|
9075
|
-
return
|
|
9395
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.every((key) => left[key] === right[key]);
|
|
9076
9396
|
}
|
|
9077
9397
|
function buildCoverageGaps(sourceFileRef, startOffset, endOffset, counts) {
|
|
9078
9398
|
return [...counts].map(([reason, omittedCount]) => coverageGap(reason, sourceFileRef, startOffset, endOffset, omittedCount));
|
|
@@ -9121,9 +9441,9 @@ var CODEX_PRODUCER_DESCRIPTOR = {
|
|
|
9121
9441
|
config: (shared, extras) => ({ ...shared, codex_sessions_root: hostProducerExtraPath(extras, CODEX_SESSIONS_ROOT) }),
|
|
9122
9442
|
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir }),
|
|
9123
9443
|
drain: drainCodexProducerOnce,
|
|
9124
|
-
background: (config, signal) => {
|
|
9444
|
+
background: (config, signal, dependencies) => {
|
|
9125
9445
|
const capturer = new CodexUsageFactsCapturer({ outbox_dir: config.outbox_dir });
|
|
9126
|
-
return runHostUsageFactsUploader({ producer: "codex", outbox_dir: config.outbox_dir, host_source_ref: config.host_source_ref, registration_state_file: hostProducerRegistrationStateFile(config.outbox_dir), capture_next: () => capturer.captureNext() }, signal);
|
|
9446
|
+
return runHostUsageFactsUploader({ producer: "codex", outbox_dir: config.outbox_dir, host_source_ref: config.host_source_ref, registration_state_file: hostProducerRegistrationStateFile(config.outbox_dir), capture_next: () => capturer.captureNext(), fetch: dependencies.fetch }, signal);
|
|
9127
9447
|
}
|
|
9128
9448
|
};
|
|
9129
9449
|
|
|
@@ -9181,7 +9501,7 @@ function runCodexInvocationAuthenticationCommand(args, options) {
|
|
|
9181
9501
|
}
|
|
9182
9502
|
async function readCodexInvocationHumanMessageWindow(input) {
|
|
9183
9503
|
let lastOrdinal;
|
|
9184
|
-
return readRegisteredHostInvocationHumanMessageWindow(() => input.store.
|
|
9504
|
+
return readRegisteredHostInvocationHumanMessageWindow((identity) => input.store.readTranscriptRegistration(identity.host_source_ref, identity.host_session_ref), (registration) => input.store.readTranscriptCursor(registration), input.identity, (line, registration, cursor) => {
|
|
9185
9505
|
let record3;
|
|
9186
9506
|
try {
|
|
9187
9507
|
record3 = decodeCodexTranscriptLine(line);
|