@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
|
@@ -56,6 +56,15 @@ function assertHostProducerSourcePaths(stateRoot, config, producer, platform = p
|
|
|
56
56
|
import { constants as constants2 } from "node:fs";
|
|
57
57
|
import { lstat as lstat2 } from "node:fs/promises";
|
|
58
58
|
|
|
59
|
+
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
60
|
+
function vocabulary(words) {
|
|
61
|
+
return Object.freeze(words);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// packages/ceal-client-protocol/src/host-usage-fields.ts
|
|
65
|
+
var CEAL_CODEX_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"]);
|
|
66
|
+
var CEAL_CLAUDE_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "output_tokens"]);
|
|
67
|
+
|
|
59
68
|
// packages/ceal-client-protocol/src/canonical-json.ts
|
|
60
69
|
function cealCanonicalJson(value) {
|
|
61
70
|
if (value === null || typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
@@ -130,7 +139,7 @@ var client_wire_contract_default = {
|
|
|
130
139
|
},
|
|
131
140
|
command_request: {
|
|
132
141
|
schema_name: "ceal.command_request",
|
|
133
|
-
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context"],
|
|
142
|
+
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context", "materialize_result"],
|
|
134
143
|
absolute_transport_max_bytes: 65536
|
|
135
144
|
},
|
|
136
145
|
command_resolution: {
|
|
@@ -176,7 +185,7 @@ var client_wire_contract_default = {
|
|
|
176
185
|
},
|
|
177
186
|
command_response: {
|
|
178
187
|
schema_name: "ceal.command_response",
|
|
179
|
-
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context"],
|
|
188
|
+
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context", "result_file"],
|
|
180
189
|
descriptor_field: "verified_artifact",
|
|
181
190
|
request_context_field: "request_context",
|
|
182
191
|
required_fields: [
|
|
@@ -189,7 +198,8 @@ var client_wire_contract_default = {
|
|
|
189
198
|
"visible_output_max_bytes",
|
|
190
199
|
"local_delivery",
|
|
191
200
|
"verified_artifact",
|
|
192
|
-
"request_context"
|
|
201
|
+
"request_context",
|
|
202
|
+
"result_file"
|
|
193
203
|
],
|
|
194
204
|
bare_document_fields: [
|
|
195
205
|
"invocation",
|
|
@@ -230,8 +240,11 @@ var client_wire_contract_default = {
|
|
|
230
240
|
"ok",
|
|
231
241
|
"code",
|
|
232
242
|
"reason",
|
|
233
|
-
"gateway_status"
|
|
243
|
+
"gateway_status",
|
|
244
|
+
"retry_after_ms"
|
|
234
245
|
],
|
|
246
|
+
refusal_required_fields: ["schema_version", "ok", "code", "reason"],
|
|
247
|
+
refusal_optional_fields: ["gateway_status", "retry_after_ms"],
|
|
235
248
|
client_nonce: {
|
|
236
249
|
character_class_source: "A-Za-z0-9_-",
|
|
237
250
|
encoded_characters: 43
|
|
@@ -450,16 +463,14 @@ var CEAL_OPERATION_WITHHELD_NEXT_ACTIONS = Object.freeze({
|
|
|
450
463
|
personal_authorization_required: "connect_personal_account"
|
|
451
464
|
});
|
|
452
465
|
|
|
453
|
-
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
454
|
-
function vocabulary(words) {
|
|
455
|
-
return Object.freeze(words);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
466
|
// packages/ceal-client-protocol/src/gateway-response-types.ts
|
|
459
467
|
var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavailable", "unknown"]);
|
|
460
468
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
461
469
|
var CEAL_AUDIT_OUTCOMES = vocabulary(["succeeded", "denied", "failed"]);
|
|
462
470
|
var CEAL_GATEWAY_PROVIDER_STEP_OUTCOMES = vocabulary(["completed", "rejected", "throttled", "failed"]);
|
|
471
|
+
var CEAL_GATEWAY_CORPUS_READ_PROVIDERS = vocabulary(["slack", "google_drive", "notion"]);
|
|
472
|
+
var CEAL_GATEWAY_CORPUS_READ_OUTCOMES = vocabulary(["answered_from_corpus", "live_fallback"]);
|
|
473
|
+
var CEAL_GATEWAY_CORPUS_READ_FALLBACK_REASONS = vocabulary(["uncovered_window", "stale", "not_organization_public", "partition_missing"]);
|
|
463
474
|
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"]);
|
|
464
475
|
var CEAL_GATEWAY_READ_REUSE_UNAVAILABLE_REASONS = vocabulary(["not_reported", "storage_unavailable", "coverage_incomplete", "freshness_refresh_required", "not_reusable", "bypassed"]);
|
|
465
476
|
var CEAL_GATEWAY_DERIVED_STORE_FAILURE_CLASSES = vocabulary(["storage_unavailable", "decode_mismatch", "write_conflict", "quota", "store_error"]);
|
|
@@ -500,6 +511,21 @@ var CEAL_GATEWAY_ORGANIZATION_ROUTE_FACT_CALL_KEYS = Object.freeze([
|
|
|
500
511
|
]);
|
|
501
512
|
|
|
502
513
|
// packages/ceal-client-protocol/src/gateway-validation-primitives.ts
|
|
514
|
+
var POSIX_HOME_ROOTS = [["/", "home"].join(""), ["/", "Users"].join("")];
|
|
515
|
+
var WINDOWS_HOME_ROOT = ["C:", "\\", "Users"].join("");
|
|
516
|
+
var USER_SEGMENT_BODY = "[^/\\\\ \\t\\r\\n\"'`${}]+";
|
|
517
|
+
var POSIX_SEGMENT_END = "(?:/|$|(?=[\\s\"'`]))";
|
|
518
|
+
var WINDOWS_SEGMENT_END = "(?:\\\\+|$|(?=[\\s\"'`]))";
|
|
519
|
+
var WINDOWS_USER_SEGMENT_BODY = "[^\\\\ \\t\\r\\n\"'`${}]+";
|
|
520
|
+
var ABSOLUTE_PATH_BOUNDARY = "(?<![A-Za-z0-9_])";
|
|
521
|
+
function escapePathPattern(value) {
|
|
522
|
+
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
523
|
+
}
|
|
524
|
+
function machineHomePathPatterns(flags) {
|
|
525
|
+
const posix5 = `${ABSOLUTE_PATH_BOUNDARY}(?:${POSIX_HOME_ROOTS.map(escapePathPattern).join("|")})/${USER_SEGMENT_BODY}${POSIX_SEGMENT_END}`;
|
|
526
|
+
const windows = `${ABSOLUTE_PATH_BOUNDARY}${escapePathPattern(WINDOWS_HOME_ROOT)}\\\\+${WINDOWS_USER_SEGMENT_BODY}${WINDOWS_SEGMENT_END}`;
|
|
527
|
+
return [new RegExp(posix5, flags), new RegExp(windows, flags)];
|
|
528
|
+
}
|
|
503
529
|
var CealProtocolValidationError = class extends Error {
|
|
504
530
|
name = "CealProtocolValidationError";
|
|
505
531
|
code;
|
|
@@ -853,8 +879,9 @@ var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask a
|
|
|
853
879
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
854
880
|
var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Relay to the same release as the Gateway, then retry.";
|
|
855
881
|
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.";
|
|
856
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select
|
|
882
|
+
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.";
|
|
857
883
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
884
|
+
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
858
885
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
859
886
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
860
887
|
}
|
|
@@ -875,13 +902,18 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
875
902
|
context_not_selected: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
876
903
|
context_store_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
877
904
|
context_store_conflict: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
878
|
-
refresh_invalid: guidance(
|
|
879
|
-
refresh_expired: guidance(
|
|
880
|
-
refresh_replayed: guidance(
|
|
881
|
-
refresh_revoked: guidance(
|
|
882
|
-
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
883
|
-
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
884
|
-
|
|
905
|
+
refresh_invalid: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
906
|
+
refresh_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
907
|
+
refresh_replayed: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
908
|
+
refresh_revoked: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
909
|
+
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),
|
|
910
|
+
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),
|
|
911
|
+
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),
|
|
912
|
+
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
913
|
+
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),
|
|
914
|
+
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),
|
|
915
|
+
refresh_state_unavailable: guidance("The Gateway session state store is temporarily unavailable; retry the same refresh attempt when it is available.", "retry", 503, true),
|
|
916
|
+
refresh_recovery_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
885
917
|
refresh_custody_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
886
918
|
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),
|
|
887
919
|
local_output_exists: guidance("The selected local output path already exists; nothing was written to it.", "choose_new_output_path", 400),
|
|
@@ -896,23 +928,21 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
896
928
|
resource_stream_failed: guidance("The provider resource stream failed; ask an administrator to inspect the Gateway failure log.", "ask_admin", 500),
|
|
897
929
|
gateway_unavailable: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 503, true),
|
|
898
930
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
899
|
-
//
|
|
900
|
-
|
|
901
|
-
// when the wait ends still unserved, moved from the `localFailureText` default branch.
|
|
902
|
-
[CEAL_GATEWAY_STARTING_FAILURE_CODE]: guidance(LOCAL_TRANSPORT_INCOMPLETE, "answer_with_gap", 503, true),
|
|
931
|
+
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
932
|
+
[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),
|
|
903
933
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
904
934
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
905
935
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
906
936
|
internal_error: guidance("The Gateway failed without exposing internal state.", "answer_with_gap", 500),
|
|
907
937
|
// Owned by the Gateway canonical adapter (`gateway/core/src/gateway-canonical-operation-http-adapter.ts`):
|
|
908
|
-
// the client variant
|
|
938
|
+
// the static client variant was retired when the client started reading this table.
|
|
909
939
|
request_body_too_large: guidance("The Gateway request body exceeds its bounded limit.", "reduce_request_size", 413),
|
|
910
940
|
gateway_response_too_large: guidance("The Gateway response exceeds its bounded limit; reduce the requested page or result size.", "reduce_request_size", 500),
|
|
911
|
-
//
|
|
912
|
-
//
|
|
913
|
-
|
|
914
|
-
//
|
|
915
|
-
|
|
941
|
+
// The safe move varies by request. Keep the sentence conditional on the
|
|
942
|
+
// same `retryable` and `next_action` facts the response exposes.
|
|
943
|
+
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
944
|
+
// 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.
|
|
945
|
+
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),
|
|
916
946
|
// Restored verbatim from the retired `localFailureText`
|
|
917
947
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
918
948
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -993,8 +1023,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
993
1023
|
// Host mint classifications. The CLI emits `invocation_authentication_unavailable` with the classification
|
|
994
1024
|
// in its detail fact; rows without their own sentence share that code's moved sentence, while `next_action`
|
|
995
1025
|
// is moved from `canonicalHostAuthenticationNextActions` (generated from `CEAL_HOST_AUTHENTICATION_POLICY`)
|
|
996
|
-
// and `retryable` from `hostAuthenticationFailureForCause` (
|
|
997
|
-
// sentences carry the
|
|
1026
|
+
// and `retryable` from `hostAuthenticationFailureForCause` (the table's explicit retry verdict). Cause-specific
|
|
1027
|
+
// sentences carry only remedies proved by the Host or Relay cause; generic Gateway refusals do not prove a release mismatch.
|
|
998
1028
|
// Statuses are the
|
|
999
1029
|
// Gateway-owned mapping decided with the operator 2026-10-13. This covers every wire cause the maps at
|
|
1000
1030
|
// `host/invocation-authentication-command.ts:217-242` emit, through their policy classifications.
|
|
@@ -1004,21 +1034,23 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
1004
1034
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
1005
1035
|
// changes mode; standalone remains the separate Client authority path.
|
|
1006
1036
|
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "answer_with_gap", 401),
|
|
1007
|
-
|
|
1008
|
-
|
|
1037
|
+
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),
|
|
1038
|
+
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),
|
|
1039
|
+
host_invocation_context_expired: guidance("The Host invocation context expired before authentication completed. This invocation cannot be retried in the expired turn; report it as a gap.", "answer_with_gap", 401),
|
|
1009
1040
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
1010
1041
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
1011
1042
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
1012
1043
|
host_mint_gateway_rate_limited: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 429),
|
|
1013
|
-
host_mint_gateway_refused: guidance(
|
|
1044
|
+
host_mint_gateway_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
1014
1045
|
host_mint_gateway_response_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
1046
|
+
host_contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 502),
|
|
1015
1047
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
1016
1048
|
// producer-frame fault names the administrator repair step.
|
|
1017
1049
|
host_producer_frame_invalid: guidance("Ask an administrator to inspect and repair the producer frame, then start a fresh Host turn.", "ask_admin", 400),
|
|
1018
1050
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
1019
1051
|
// sandboxed Relay socket names the run-alone retry.
|
|
1020
1052
|
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),
|
|
1021
|
-
host_relay_unavailable: guidance(
|
|
1053
|
+
host_relay_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 503),
|
|
1022
1054
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
1023
1055
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
1024
1056
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -1056,7 +1088,7 @@ var UNKNOWN_OUTCOMES = vocabulary(["reconcile", "operator_action", "excluded"]);
|
|
|
1056
1088
|
var RECOVERY_OWNERS = vocabulary(["gateway", "connector", "operator"]);
|
|
1057
1089
|
var CEAL_OPERATION_ADMISSION_STATES = vocabulary(["proposed", "refused", "admitted"]);
|
|
1058
1090
|
var CEAL_OPERATION_EXECUTION_STATES = vocabulary(["not_started", "started", "completed"]);
|
|
1059
|
-
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1091
|
+
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_applicable", "not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1060
1092
|
var CEAL_OPERATION_EFFECT_STATES = vocabulary(["none", "applied", "failed", "unknown", "compensated"]);
|
|
1061
1093
|
var CEAL_OPERATION_OBSERVATION_STATES = vocabulary(["not_started", "not_required", "pending", "observed", "unavailable"]);
|
|
1062
1094
|
var CEAL_OPERATION_RECOVERY_KINDS = vocabulary(["none", "reconcile", "compensate", "operator_action"]);
|
|
@@ -1227,6 +1259,7 @@ var CEAL_OPERATION_ACCESS_CLASSES = vocabulary(["read", "write"]);
|
|
|
1227
1259
|
// packages/ceal-client-protocol/src/domain-vocabulary.ts
|
|
1228
1260
|
var CEAL_CONNECTOR_STATUSES = vocabulary(["active", "disabled", "disconnected"]);
|
|
1229
1261
|
var CEAL_CONNECTOR_CUSTODIES = vocabulary(["organization", "personal"]);
|
|
1262
|
+
var CEAL_PROVIDER_BOUNDARY_FIELDS = vocabulary(["provider_boundary_ref", "provider_boundary_kind", "provider_boundary_label", "provider_native_id", "provider_boundary_evidence"]);
|
|
1230
1263
|
var CEAL_PERSONAL_ACCESS_CEILINGS = vocabulary(["disabled", "read", "read_write"]);
|
|
1231
1264
|
var CEAL_TARGET_REF_PATTERN = "^[^\\p{Cc}]+$";
|
|
1232
1265
|
var TARGET_REF = new RegExp(CEAL_TARGET_REF_PATTERN, "u");
|
|
@@ -1272,7 +1305,7 @@ var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
|
1272
1305
|
var CEAL_OPERATION_AUTHORITY_POLICY_KEYS = Object.freeze(["access_group", "instance_binding", "target", "admission_recheck"]);
|
|
1273
1306
|
var MAX_OPERATION_INPUT_RESOLVER_BINDINGS = 96;
|
|
1274
1307
|
var CEAL_OPERATION_DESCRIPTOR_REQUIRED_ENVELOPE_KEYS = Object.freeze(["schema_version", "id", "input_contract", "result_contract", "policy"]);
|
|
1275
|
-
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary"]);
|
|
1308
|
+
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary", "standard_names"]);
|
|
1276
1309
|
|
|
1277
1310
|
// packages/ceal-client-protocol/src/operation-catalog.ts
|
|
1278
1311
|
var CEAL_OPERATION_CATALOG_SCHEMA_VERSION = "ceal.catalog.v3";
|
|
@@ -1368,6 +1401,7 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
1368
1401
|
gateway_access_group_connector_activity_scope_audit: (root) => join(root, "profile-connector-activity-scope-audit.jsonl"),
|
|
1369
1402
|
gateway_access_group_connector_calendar_scope_audit: (root) => join(root, "profile-connector-calendar-scope-audit.jsonl"),
|
|
1370
1403
|
gateway_access_group_connector_readiness_audit: (root) => join(root, "profile-connector-readiness.audit.jsonl"),
|
|
1404
|
+
gateway_deployment_events: (root) => join(root, "gateway-deployments.jsonl"),
|
|
1371
1405
|
gateway_organization_audit_ledger: (root) => join(root, "organization-ledger.jsonl"),
|
|
1372
1406
|
gateway_personal_client_audit: (root) => join(root, "audit.jsonl"),
|
|
1373
1407
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
@@ -1394,6 +1428,11 @@ var CEAL_HOST_INSTALLATION_REF_PATTERN = new RegExp(`^host-installation:${CEAL_L
|
|
|
1394
1428
|
var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUID_PATTERN}$`, "u");
|
|
1395
1429
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
1396
1430
|
|
|
1431
|
+
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1432
|
+
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
1433
|
+
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
1434
|
+
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1435
|
+
|
|
1397
1436
|
// packages/ceal-client-protocol/src/operation-result-completeness.ts
|
|
1398
1437
|
var CEAL_READ_VALUE_CONTINUATION_KEYS = vocabulary(["continuation", "continuation_ref", "next_cursor"]);
|
|
1399
1438
|
|
|
@@ -1478,6 +1517,7 @@ var PROVIDER_LINK_CONFORMANCE_TABLE = Object.freeze([
|
|
|
1478
1517
|
{ 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" },
|
|
1479
1518
|
{ 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" },
|
|
1480
1519
|
{ 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" },
|
|
1520
|
+
{ 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" },
|
|
1481
1521
|
{ 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" },
|
|
1482
1522
|
{ 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" },
|
|
1483
1523
|
{ 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" },
|
|
@@ -1552,6 +1592,8 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1552
1592
|
"review_submitted",
|
|
1553
1593
|
"comment_created",
|
|
1554
1594
|
"reaction_created",
|
|
1595
|
+
"pull_request_merged",
|
|
1596
|
+
"release_published",
|
|
1555
1597
|
"ceal_write_completed",
|
|
1556
1598
|
"event_start",
|
|
1557
1599
|
"all_day_start",
|
|
@@ -1563,7 +1605,7 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1563
1605
|
"page_last_edited",
|
|
1564
1606
|
"resource_modified"
|
|
1565
1607
|
]);
|
|
1566
|
-
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "notion"]);
|
|
1608
|
+
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "google-mail", "notion"]);
|
|
1567
1609
|
var CEAL_ACTIVITY_UNSUPPORTED_EVENT_KIND_CODE = "unsupported_event_kind";
|
|
1568
1610
|
var CEAL_ACTIVITY_GAP_CODES = vocabulary([
|
|
1569
1611
|
"provider_page_budget",
|
|
@@ -1584,6 +1626,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1584
1626
|
"github.pull_request.opened",
|
|
1585
1627
|
"github.issue.edited",
|
|
1586
1628
|
"github.pull_request.edited",
|
|
1629
|
+
"github.pull_request.merged",
|
|
1630
|
+
"github.release.published",
|
|
1587
1631
|
"github.review.submitted",
|
|
1588
1632
|
"github.issue_comment.created",
|
|
1589
1633
|
"github.review_comment.created",
|
|
@@ -1597,6 +1641,7 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1597
1641
|
"drive.file.created",
|
|
1598
1642
|
"drive.file.modified",
|
|
1599
1643
|
"drive.file.viewed",
|
|
1644
|
+
"mail.sent",
|
|
1600
1645
|
"notion.page.created",
|
|
1601
1646
|
"notion.page.edited"
|
|
1602
1647
|
]);
|
|
@@ -1610,6 +1655,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1610
1655
|
"github.review_comment.created": "comment_created",
|
|
1611
1656
|
"github.issue.opened": "resource_created",
|
|
1612
1657
|
"github.pull_request.opened": "resource_created",
|
|
1658
|
+
"github.pull_request.merged": "pull_request_merged",
|
|
1659
|
+
"github.release.published": "release_published",
|
|
1613
1660
|
"github.issue.edited": "resource_modified",
|
|
1614
1661
|
"github.pull_request.edited": "resource_modified",
|
|
1615
1662
|
"github.reaction.created": "reaction_created",
|
|
@@ -1620,6 +1667,7 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1620
1667
|
"drive.file.created": "file_created",
|
|
1621
1668
|
"drive.file.modified": "file_modified_by_me",
|
|
1622
1669
|
"drive.file.viewed": "file_viewed_by_me",
|
|
1670
|
+
"mail.sent": "message_created",
|
|
1623
1671
|
"notion.page.created": "page_created",
|
|
1624
1672
|
"notion.page.edited": "page_last_edited"
|
|
1625
1673
|
});
|
|
@@ -1647,6 +1695,7 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
1647
1695
|
created_at: { required: false, timestamp: true },
|
|
1648
1696
|
created_at_local: { required: false, timestamp: true },
|
|
1649
1697
|
modified_at: { required: false, timestamp: true },
|
|
1698
|
+
observed_at: { required: false, timestamp: true },
|
|
1650
1699
|
modified_at_local: { required: false, timestamp: true },
|
|
1651
1700
|
viewed_by_me_at: { required: false, timestamp: true },
|
|
1652
1701
|
modified_by_me_at: { required: false, timestamp: true },
|
|
@@ -1674,9 +1723,6 @@ var RESOURCE_ROW_REQUIRED_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(
|
|
|
1674
1723
|
var RESOURCE_ROW_KEYS = new Set(Object.keys(RESOURCE_ROW_KEY_RULES));
|
|
1675
1724
|
var RESOURCE_ROW_TIMESTAMP_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(([key, rule]) => rule.timestamp ? [key] : []);
|
|
1676
1725
|
|
|
1677
|
-
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1678
|
-
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1679
|
-
|
|
1680
1726
|
// packages/ceal-client-protocol/src/excluded-target-coverage.ts
|
|
1681
1727
|
var CEAL_EXCLUDED_TARGET_COVERAGE_MAX_ENTRIES = 64;
|
|
1682
1728
|
function cealExcludedTargetCoverageJsonSchema() {
|
|
@@ -1732,6 +1778,8 @@ var CEAL_REFRESH_FAILURE_CODES = vocabulary([
|
|
|
1732
1778
|
"principal_inactive",
|
|
1733
1779
|
"authority_replaced",
|
|
1734
1780
|
"refresh_recovery_unavailable",
|
|
1781
|
+
"refresh_recovery_outcome_unavailable",
|
|
1782
|
+
"refresh_state_unavailable",
|
|
1735
1783
|
"refresh_recovery_expired",
|
|
1736
1784
|
// The serving gate answers this while the Gateway is still starting and the
|
|
1737
1785
|
// refresh was never attempted; the same attempt stays retryable. It is never
|
|
@@ -1983,7 +2031,7 @@ function validateBatchContents(value) {
|
|
|
1983
2031
|
if (facts.length === 0 && gaps.length === 0 || facts.length > 0 && value.source_ranges.length === 0) invalid("Ceal Host usage coverage is invalid.");
|
|
1984
2032
|
const sourceFiles = new Set(value.source_ranges.map((range) => sourceRangeFileRef(range)));
|
|
1985
2033
|
for (const fact of facts) {
|
|
1986
|
-
|
|
2034
|
+
validateCealHostUsageFact(fact, value.host_session_ref);
|
|
1987
2035
|
if (!sourceFiles.has(fact.source_file_ref)) invalid("Ceal Host usage fact is outside its source ranges.");
|
|
1988
2036
|
}
|
|
1989
2037
|
for (const gap of gaps) {
|
|
@@ -2016,7 +2064,7 @@ function hostUsageSourceFileReference(producer, hostSourceRef, hostSessionRef, d
|
|
|
2016
2064
|
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.");
|
|
2017
2065
|
return `host-source-file:${sha256(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef, device, inode }))}`;
|
|
2018
2066
|
}
|
|
2019
|
-
function
|
|
2067
|
+
function validateCealHostUsageFact(value, sessionRef) {
|
|
2020
2068
|
if (!isOperationRecord(value)) invalid("Ceal Host usage fact is invalid.");
|
|
2021
2069
|
requireFactByteLimit(value);
|
|
2022
2070
|
if (value.producer === "codex_transcript") validateCodexFact(value);
|
|
@@ -2080,7 +2128,7 @@ function validCorrectionSemantics(value) {
|
|
|
2080
2128
|
}
|
|
2081
2129
|
function validateCodexUsageCounts(value) {
|
|
2082
2130
|
if (!isOperationRecord(value)) invalid("Ceal Codex usage fields are invalid.");
|
|
2083
|
-
requireExactOperationKeys(value,
|
|
2131
|
+
requireExactOperationKeys(value, CEAL_CODEX_USAGE_COUNT_FIELDS);
|
|
2084
2132
|
for (const key of Object.keys(value)) if (!safeInteger(value[key])) invalid("Ceal Codex usage fields are invalid.");
|
|
2085
2133
|
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.");
|
|
2086
2134
|
}
|
|
@@ -2348,6 +2396,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
2348
2396
|
"options_invalid",
|
|
2349
2397
|
"session_unavailable",
|
|
2350
2398
|
"context_unavailable",
|
|
2399
|
+
"activation_wait_exhausted",
|
|
2351
2400
|
"context_replaced",
|
|
2352
2401
|
"no_binding",
|
|
2353
2402
|
"context_expired",
|
|
@@ -2383,22 +2432,23 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2383
2432
|
// This reason cannot distinguish a Codex side conversation from a missing
|
|
2384
2433
|
// context in a regular session, so guidance must leave that choice to the caller.
|
|
2385
2434
|
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "answer_with_gap" }),
|
|
2386
|
-
|
|
2435
|
+
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
2436
|
+
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
2387
2437
|
// `no_binding` now means the producer has no real current Host session. The
|
|
2388
2438
|
// Host Relay never uses it for an uncreated Gateway Request; there is no
|
|
2389
2439
|
// useful retry until the consumer is running inside a Host session.
|
|
2390
2440
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2391
|
-
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "
|
|
2441
|
+
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
2392
2442
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
2393
2443
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
2394
2444
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
2395
2445
|
gateway_rate_limited: Object.freeze({ classification: "host_mint_gateway_rate_limited", next_action: "answer_with_gap" }),
|
|
2396
|
-
contract_mismatch: Object.freeze({ classification: "
|
|
2397
|
-
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "
|
|
2446
|
+
contract_mismatch: Object.freeze({ classification: "host_contract_mismatch", next_action: "upgrade_ceal_client" }),
|
|
2447
|
+
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "answer_with_gap" }),
|
|
2398
2448
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
2399
2449
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
2400
2450
|
relay_permission_denied: Object.freeze({ classification: "host_relay_permission_denied", next_action: "rerun_outside_agent_sandbox" }),
|
|
2401
|
-
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "
|
|
2451
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "answer_with_gap" }),
|
|
2402
2452
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
2403
2453
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
2404
2454
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -2446,7 +2496,7 @@ function isCealHostServiceDiagnosticCause(value, event) {
|
|
|
2446
2496
|
// packages/ceal-client-protocol/src/client-result-materialization.ts
|
|
2447
2497
|
var CEAL_UNREAD_REASONS = vocabulary(["blocked", "unavailable", "too_large", "unsupported", "download_failed", "permission_denied"]);
|
|
2448
2498
|
var REQUIRED_FIELDS2 = Object.freeze(["schema_version", "operation_id", "path", "sha256"]);
|
|
2449
|
-
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "
|
|
2499
|
+
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "local_result_root", "request_context_argv", "how_to_read"]);
|
|
2450
2500
|
|
|
2451
2501
|
// packages/ceal-client-protocol/src/discovery-manifest.ts
|
|
2452
2502
|
var DISCOVERY_MANIFEST_KEYS = CEAL_CLIENT_WIRE_CONTRACT.command_response.discovery_manifest_fields;
|
|
@@ -2488,6 +2538,211 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
2488
2538
|
maximum: CEAL_PROTOCOL_VERSION
|
|
2489
2539
|
});
|
|
2490
2540
|
|
|
2541
|
+
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
2542
|
+
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
2543
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSES = 8;
|
|
2544
|
+
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
2545
|
+
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
2546
|
+
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
2547
|
+
var OPERATOR_DIAGNOSTIC_HOME_PATHS = machineHomePathPatterns("gu");
|
|
2548
|
+
function redactOperatorDiagnosticSecrets(value) {
|
|
2549
|
+
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]");
|
|
2550
|
+
}
|
|
2551
|
+
function redactOperatorDiagnosticText(value) {
|
|
2552
|
+
const normalized = normalizeCealSingleLineText(value);
|
|
2553
|
+
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
2554
|
+
}
|
|
2555
|
+
function renderOperatorDiagnostic(value) {
|
|
2556
|
+
const state = collectDiagnosticState(value);
|
|
2557
|
+
const fields = [
|
|
2558
|
+
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
2559
|
+
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
2560
|
+
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
2561
|
+
state.stderr === void 0 ? void 0 : `stderr_tail=${JSON.stringify(tail(state.stderr))}`,
|
|
2562
|
+
state.causes.length === 0 ? void 0 : `causes=${state.causes.map(formatCause).join(" <- ")}`
|
|
2563
|
+
].filter((field) => field !== void 0);
|
|
2564
|
+
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
2565
|
+
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
2566
|
+
}
|
|
2567
|
+
function collectDiagnosticState(value) {
|
|
2568
|
+
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0 };
|
|
2569
|
+
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
2570
|
+
while (pending.length > 0 && state.causes.length < OPERATOR_DIAGNOSTIC_MAX_CAUSES) {
|
|
2571
|
+
const current = pending.shift();
|
|
2572
|
+
if (current !== void 0) visitDiagnosticNode(current, state, pending, visited);
|
|
2573
|
+
}
|
|
2574
|
+
return state;
|
|
2575
|
+
}
|
|
2576
|
+
function visitDiagnosticNode(current, state, pending, visited) {
|
|
2577
|
+
if (isObject(current)) {
|
|
2578
|
+
if (visited.has(current)) return;
|
|
2579
|
+
visited.add(current);
|
|
2580
|
+
}
|
|
2581
|
+
captureProcessEvidence(current, state);
|
|
2582
|
+
appendCause(current, state.causes);
|
|
2583
|
+
enqueueCauseChildren(current, state.causes.length, pending);
|
|
2584
|
+
}
|
|
2585
|
+
function captureProcessEvidence(current, state) {
|
|
2586
|
+
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
2587
|
+
if (state.exitCode === void 0) state.exitCode = safeExitCode(read(current, "exitCode")) ?? safeExitCode(read(current, "status")) ?? safeExitCode(read(current, "code"));
|
|
2588
|
+
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
2589
|
+
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
2590
|
+
}
|
|
2591
|
+
function appendCause(current, causes) {
|
|
2592
|
+
const errors = read(current, "errors");
|
|
2593
|
+
if (current instanceof Error && (!(current instanceof AggregateError) || !Array.isArray(errors) || errors.length === 0)) {
|
|
2594
|
+
causes.push(errorCause(current));
|
|
2595
|
+
return;
|
|
2596
|
+
}
|
|
2597
|
+
if (!isObject(current)) {
|
|
2598
|
+
const message = safeText(current);
|
|
2599
|
+
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
function errorCause(error) {
|
|
2603
|
+
const name = safeText(read(error, "name")) ?? "Error";
|
|
2604
|
+
const message = safeText(read(error, "message"));
|
|
2605
|
+
const codeValue = read(error, "code");
|
|
2606
|
+
const code = typeof codeValue === "number" && Number.isFinite(codeValue) ? codeValue : safeText(codeValue);
|
|
2607
|
+
const errnoValue = read(error, "errno");
|
|
2608
|
+
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
2609
|
+
const syscall = safeText(read(error, "syscall"));
|
|
2610
|
+
const path = safePath(read(error, "path"));
|
|
2611
|
+
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 } });
|
|
2612
|
+
}
|
|
2613
|
+
function enqueueCauseChildren(current, causeCount, pending) {
|
|
2614
|
+
const cause = read(current, "cause");
|
|
2615
|
+
if (cause !== void 0) pending.push(cause);
|
|
2616
|
+
const errors = read(current, "errors");
|
|
2617
|
+
if (Array.isArray(errors)) pending.push(...errors.slice(0, OPERATOR_DIAGNOSTIC_MAX_CAUSES - causeCount));
|
|
2618
|
+
}
|
|
2619
|
+
function isObject(value) {
|
|
2620
|
+
return typeof value === "object" && value !== null;
|
|
2621
|
+
}
|
|
2622
|
+
function formatCause(cause) {
|
|
2623
|
+
const fields = [
|
|
2624
|
+
cause.error_class,
|
|
2625
|
+
cause.code === void 0 ? void 0 : `code=${JSON.stringify(safeDiagnosticText(cause.code))}`,
|
|
2626
|
+
cause.errno === void 0 ? void 0 : `errno=${cause.errno}`,
|
|
2627
|
+
cause.syscall === void 0 ? void 0 : `syscall=${JSON.stringify(cause.syscall)}`,
|
|
2628
|
+
cause.path === void 0 ? void 0 : `path=${JSON.stringify(cause.path)}`,
|
|
2629
|
+
cause.message === void 0 ? void 0 : `message=${cause.message}`
|
|
2630
|
+
].filter((field) => field !== void 0);
|
|
2631
|
+
return fields.join(" ");
|
|
2632
|
+
}
|
|
2633
|
+
function tail(value) {
|
|
2634
|
+
const clipped = value.length <= OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT ? value : `…${value.slice(-OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT)}`;
|
|
2635
|
+
return safeDiagnosticText(clipped);
|
|
2636
|
+
}
|
|
2637
|
+
function safeText(value) {
|
|
2638
|
+
if (typeof value !== "string") return void 0;
|
|
2639
|
+
const safe = safeDiagnosticText(value);
|
|
2640
|
+
if (safe.length === 0) return void 0;
|
|
2641
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT) return safe;
|
|
2642
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT / 2);
|
|
2643
|
+
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
2644
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2645
|
+
}
|
|
2646
|
+
function safePath(value) {
|
|
2647
|
+
if (typeof value !== "string") return void 0;
|
|
2648
|
+
const safe = safeDiagnosticText(value);
|
|
2649
|
+
if (safe.length === 0) return void 0;
|
|
2650
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
2651
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
2652
|
+
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
2653
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2654
|
+
}
|
|
2655
|
+
function safeDiagnosticText(value) {
|
|
2656
|
+
return redactOperatorDiagnosticText(String(value));
|
|
2657
|
+
}
|
|
2658
|
+
function outputText(value) {
|
|
2659
|
+
if (typeof value === "string") return redactOperatorDiagnosticText(value);
|
|
2660
|
+
if (value instanceof Uint8Array) {
|
|
2661
|
+
try {
|
|
2662
|
+
return redactOperatorDiagnosticText(new TextDecoder().decode(value));
|
|
2663
|
+
} catch {
|
|
2664
|
+
return void 0;
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
return void 0;
|
|
2668
|
+
}
|
|
2669
|
+
function safeStatus(value) {
|
|
2670
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
2671
|
+
return typeof value === "string" ? safeText(value) : void 0;
|
|
2672
|
+
}
|
|
2673
|
+
function safeExitCode(value) {
|
|
2674
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
2675
|
+
}
|
|
2676
|
+
function read(value, key) {
|
|
2677
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) return void 0;
|
|
2678
|
+
try {
|
|
2679
|
+
return Reflect.get(value, key);
|
|
2680
|
+
} catch {
|
|
2681
|
+
return void 0;
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
function redactHomePaths(value) {
|
|
2685
|
+
const paths = [
|
|
2686
|
+
...OPERATOR_DIAGNOSTIC_HOME_PATHS.flatMap((pattern) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, matchedHomePrefixLength(match[0])))),
|
|
2687
|
+
...configuredHomePathPatterns().flatMap(({ pattern, prefixLength }) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, prefixLength)))
|
|
2688
|
+
];
|
|
2689
|
+
paths.sort((left, right) => left.start - right.start || right.end - left.end);
|
|
2690
|
+
let output = "";
|
|
2691
|
+
let cursor = 0;
|
|
2692
|
+
for (const path of paths) {
|
|
2693
|
+
if (path.start < cursor) continue;
|
|
2694
|
+
output += `${value.slice(cursor, path.start)}[home path redacted]${value.slice(path.prefixEnd, path.end)}`;
|
|
2695
|
+
cursor = path.end;
|
|
2696
|
+
}
|
|
2697
|
+
return output + value.slice(cursor);
|
|
2698
|
+
}
|
|
2699
|
+
function configuredHomePathPatterns() {
|
|
2700
|
+
const homes = [...new Set([process.env.HOME, process.env.USERPROFILE].filter((home) => home !== void 0 && home.length > 0))];
|
|
2701
|
+
return homes.flatMap((home) => {
|
|
2702
|
+
const root = home.replace(/[\\/]+$/gu, "");
|
|
2703
|
+
if (root.length === 0 || root === "/" || /^[A-Za-z]:$/u.test(root)) return [];
|
|
2704
|
+
const pattern = new RegExp(`(?<![A-Za-z0-9_])${escapePathPattern(root)}(?=$|[\\\\/\\s"'\`<>(){}\\[\\],;])`, /^[A-Za-z]:[\\/]/u.test(root) ? "giu" : "gu");
|
|
2705
|
+
return [{ pattern, prefixLength: root.length }];
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
function matchedHomePrefixLength(value) {
|
|
2709
|
+
let separators = 0;
|
|
2710
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
2711
|
+
if (value[index] !== "/" && value[index] !== "\\") continue;
|
|
2712
|
+
separators += 1;
|
|
2713
|
+
if (separators === 3) return index;
|
|
2714
|
+
}
|
|
2715
|
+
return value.length;
|
|
2716
|
+
}
|
|
2717
|
+
function redactUrls(value) {
|
|
2718
|
+
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
2719
|
+
}
|
|
2720
|
+
function redactFilePaths(value) {
|
|
2721
|
+
return value.replaceAll(/(?<![A-Za-z0-9._-]|\[home path redacted\])(?:[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/)[^:\r\n"'<>]*?(?=:\d+(?::\d+)?(?:[:\s]|$)|[\r\n]|["'])/gu, "[path redacted]");
|
|
2722
|
+
}
|
|
2723
|
+
function homePathRange(value, match, prefixLength) {
|
|
2724
|
+
const index = match.index;
|
|
2725
|
+
if (index === void 0) return { start: value.length, end: value.length, prefixEnd: value.length };
|
|
2726
|
+
const start = index;
|
|
2727
|
+
let end = start + match[0].length;
|
|
2728
|
+
const quote = start > 0 && (value[start - 1] === "'" || value[start - 1] === '"') ? value[start - 1] : void 0;
|
|
2729
|
+
if (quote !== void 0) {
|
|
2730
|
+
const closing = value.indexOf(quote, end);
|
|
2731
|
+
if (closing >= 0) end = closing;
|
|
2732
|
+
}
|
|
2733
|
+
while (end < value.length && !/[\s"'`<>(){}[\],;]/u.test(value[end] ?? "")) end += 1;
|
|
2734
|
+
return { start, end, prefixEnd: Math.min(start + prefixLength, end) };
|
|
2735
|
+
}
|
|
2736
|
+
function truncateUtf8(value, maxBytes) {
|
|
2737
|
+
if (byteLength(value) <= maxBytes) return value;
|
|
2738
|
+
let output = "";
|
|
2739
|
+
for (const character of value) {
|
|
2740
|
+
if (byteLength(`${output}${character}…`) > maxBytes) break;
|
|
2741
|
+
output += character;
|
|
2742
|
+
}
|
|
2743
|
+
return `${output}…`;
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2491
2746
|
// packages/ceal-client-protocol/src/admin-projection-vocabulary.ts
|
|
2492
2747
|
var ADMIN_PROJECTION_STATES = vocabulary(["ready", "empty", "partial", "unknown"]);
|
|
2493
2748
|
var ADMIN_VIEW_KINDS = vocabulary(["request_detail", "resource_access_timeline", "weekly_usage"]);
|
|
@@ -2674,7 +2929,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
2674
2929
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
2675
2930
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
2676
2931
|
return await new Promise((resolve, reject2) => {
|
|
2677
|
-
const child = execFile(executable, processArgs, { encoding: "buffer", timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
2932
|
+
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
2678
2933
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
2679
2934
|
if (exitCode === null) {
|
|
2680
2935
|
reject2(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -2765,21 +3020,21 @@ function decodeHostProducerConfigText(descriptor, text, platform = process.platf
|
|
|
2765
3020
|
const { extra_paths: extras, ...core } = decoded;
|
|
2766
3021
|
return Object.freeze(descriptor.config({ schema_version: descriptor.schema, ...core }, extras));
|
|
2767
3022
|
}
|
|
2768
|
-
async function serveHostProducer(descriptor, config, signal, dependencies
|
|
3023
|
+
async function serveHostProducer(descriptor, config, signal, dependencies) {
|
|
2769
3024
|
const runtimeOptions = descriptor.runtime_options(config);
|
|
2770
3025
|
const serving = serveProducer(runtimeOptions, config, signal, dependencies.drain ?? descriptor.drain, dependencies.wait);
|
|
2771
3026
|
if (descriptor.background === void 0 || dependencies.drain !== void 0) {
|
|
2772
3027
|
await serving;
|
|
2773
3028
|
return;
|
|
2774
3029
|
}
|
|
2775
|
-
const background = descriptor.background(config, signal);
|
|
3030
|
+
const background = descriptor.background(config, signal, dependencies);
|
|
2776
3031
|
await Promise.all([serving, background]);
|
|
2777
3032
|
}
|
|
2778
3033
|
function hostProducerRegistrationStateFile(outboxDirectory, platform = process.platform) {
|
|
2779
3034
|
const path = platform === "win32" ? win324 : posix3;
|
|
2780
3035
|
return path.join(path.resolve(outboxDirectory, "../../../../.."), "registration.json");
|
|
2781
3036
|
}
|
|
2782
|
-
async function runHostProducerCli(descriptor, args, signal, dependencies
|
|
3037
|
+
async function runHostProducerCli(descriptor, args, signal, dependencies) {
|
|
2783
3038
|
await serveHostProducer(descriptor, await readHostProducerConfig(descriptor, parseHostProducerServeArgs(args)), signal, dependencies);
|
|
2784
3039
|
}
|
|
2785
3040
|
function hostProducerError(code, message = code) {
|
|
@@ -2919,7 +3174,7 @@ function parseCanonicalJson(text, error) {
|
|
|
2919
3174
|
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) }])}`);
|
|
2920
3175
|
return value;
|
|
2921
3176
|
} catch (parseError) {
|
|
2922
|
-
throw error("invalid_config",
|
|
3177
|
+
throw error("invalid_config", `parse_error=${renderOperatorDiagnostic(parseError)}; ${refusalFact("config_bytes", Buffer.byteLength(text, "utf8"), "canonical JSON")}`);
|
|
2923
3178
|
}
|
|
2924
3179
|
}
|
|
2925
3180
|
function firstDifferenceIndex(left, right) {
|
|
@@ -3534,14 +3789,14 @@ var HostUsageFactsStore = class {
|
|
|
3534
3789
|
const gate = new Promise((resolve) => {
|
|
3535
3790
|
release = resolve;
|
|
3536
3791
|
});
|
|
3537
|
-
const
|
|
3538
|
-
SESSION_TRANSITION_TAILS.set(key,
|
|
3792
|
+
const tail2 = previous.then(() => gate);
|
|
3793
|
+
SESSION_TRANSITION_TAILS.set(key, tail2);
|
|
3539
3794
|
await previous;
|
|
3540
3795
|
try {
|
|
3541
3796
|
return await run();
|
|
3542
3797
|
} finally {
|
|
3543
3798
|
release?.();
|
|
3544
|
-
if (SESSION_TRANSITION_TAILS.get(key) ===
|
|
3799
|
+
if (SESSION_TRANSITION_TAILS.get(key) === tail2) SESSION_TRANSITION_TAILS.delete(key);
|
|
3545
3800
|
}
|
|
3546
3801
|
}
|
|
3547
3802
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
@@ -4065,7 +4320,7 @@ var HostUsageFactsUploader = class {
|
|
|
4065
4320
|
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);
|
|
4066
4321
|
const timeout = AbortSignal.timeout(this.options.timeout_ms ?? 5e3);
|
|
4067
4322
|
const requestSignal = signal === void 0 ? timeout : AbortSignal.any([signal, timeout]);
|
|
4068
|
-
const response2 = await
|
|
4323
|
+
const response2 = await this.options.fetch(`${registration.gateway_request_origin}${CEAL_HOST_USAGE_INGRESS_PATH}`, {
|
|
4069
4324
|
method: "POST",
|
|
4070
4325
|
headers: { authorization: `Bearer ${registration.host_access_token}`, "content-type": "application/json" },
|
|
4071
4326
|
body: JSON.stringify(candidate.batch),
|
|
@@ -4154,9 +4409,9 @@ async function readTranscriptCompleteChunk(handle, offset, size) {
|
|
|
4154
4409
|
let lastNewline = -1;
|
|
4155
4410
|
while (position < size) {
|
|
4156
4411
|
const buffer = Buffer.alloc(Math.min(HOST_TRANSCRIPT_READ_CHUNK_BYTES, size - position));
|
|
4157
|
-
const
|
|
4158
|
-
if (
|
|
4159
|
-
const chunk = buffer.subarray(0,
|
|
4412
|
+
const read2 = await handle.read(buffer, 0, buffer.length, position);
|
|
4413
|
+
if (read2.bytesRead === 0) break;
|
|
4414
|
+
const chunk = buffer.subarray(0, read2.bytesRead);
|
|
4160
4415
|
chunks.push(chunk);
|
|
4161
4416
|
const newline = chunk.lastIndexOf(10);
|
|
4162
4417
|
if (newline >= 0) lastNewline = total + newline;
|
|
@@ -4213,7 +4468,7 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
4213
4468
|
outboxRetentionMs: options.retention_ms ?? owner.default_retention_ms,
|
|
4214
4469
|
now: options.now ?? (() => /* @__PURE__ */ new Date()),
|
|
4215
4470
|
log: options.log ?? ((line) => {
|
|
4216
|
-
|
|
4471
|
+
writeHostServiceLogLine(`${line}
|
|
4217
4472
|
`);
|
|
4218
4473
|
}),
|
|
4219
4474
|
producerInstallationRef: options.producer_installation_ref
|
|
@@ -4253,7 +4508,13 @@ var HostTranscriptWatcher = class {
|
|
|
4253
4508
|
}
|
|
4254
4509
|
async scanRegistration(registration) {
|
|
4255
4510
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
4256
|
-
missing: () =>
|
|
4511
|
+
missing: async () => {
|
|
4512
|
+
try {
|
|
4513
|
+
return await this.retireMissing(registration);
|
|
4514
|
+
} catch (error) {
|
|
4515
|
+
return this.scanFailed(void 0, registration, error);
|
|
4516
|
+
}
|
|
4517
|
+
},
|
|
4257
4518
|
failed: (handle, error) => this.scanFailed(handle, registration, error)
|
|
4258
4519
|
});
|
|
4259
4520
|
}
|
|
@@ -4323,15 +4584,15 @@ var HostProducerDrainCore = class {
|
|
|
4323
4584
|
return run;
|
|
4324
4585
|
}
|
|
4325
4586
|
async drainLocked() {
|
|
4326
|
-
const
|
|
4587
|
+
const read2 = await this.host.listEnvelopes();
|
|
4327
4588
|
let removed = 0;
|
|
4328
4589
|
let expired = 0;
|
|
4329
|
-
for (const envelope of
|
|
4590
|
+
for (const envelope of read2.entries) {
|
|
4330
4591
|
if (Date.parse(this.host.expiresAtOf(envelope)) <= this.now().getTime()) expired += 1;
|
|
4331
4592
|
else removed += 1;
|
|
4332
4593
|
await this.host.removeEnvelope(envelope);
|
|
4333
4594
|
}
|
|
4334
|
-
return { removed, expired, malformed:
|
|
4595
|
+
return { removed, expired, malformed: read2.malformed };
|
|
4335
4596
|
}
|
|
4336
4597
|
};
|
|
4337
4598
|
|
|
@@ -4415,29 +4676,46 @@ var HostUsageTranscriptSourceError = class extends Error {
|
|
|
4415
4676
|
this.name = "HostUsageTranscriptSourceError";
|
|
4416
4677
|
}
|
|
4417
4678
|
};
|
|
4418
|
-
async function readHostUsageTranscriptSource(
|
|
4679
|
+
async function readHostUsageTranscriptSource(read2) {
|
|
4419
4680
|
try {
|
|
4420
|
-
return await
|
|
4681
|
+
return await read2();
|
|
4421
4682
|
} catch (error) {
|
|
4422
4683
|
throw new HostUsageTranscriptSourceError({ cause: error });
|
|
4423
4684
|
}
|
|
4424
4685
|
}
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4686
|
+
var HostUsageRegistrationCapture = class {
|
|
4687
|
+
nextIndex = 0;
|
|
4688
|
+
producer;
|
|
4689
|
+
diagnosticSink;
|
|
4690
|
+
constructor(producer, diagnosticSink) {
|
|
4691
|
+
this.producer = producer;
|
|
4692
|
+
this.diagnosticSink = diagnosticSink;
|
|
4693
|
+
}
|
|
4694
|
+
async captureNext(registrations, capture) {
|
|
4695
|
+
let failed = false;
|
|
4696
|
+
let captured = false;
|
|
4697
|
+
const onFailure = () => {
|
|
4436
4698
|
failed = true;
|
|
4699
|
+
};
|
|
4700
|
+
for (let attempt = 0; attempt < registrations.length; attempt += 1) {
|
|
4701
|
+
const index = (this.nextIndex + attempt) % registrations.length;
|
|
4702
|
+
const registration = registrations[index];
|
|
4703
|
+
if (registration === void 0) continue;
|
|
4704
|
+
try {
|
|
4705
|
+
captured = await capture(registration, onFailure);
|
|
4706
|
+
if (captured) {
|
|
4707
|
+
this.nextIndex = (index + 1) % registrations.length;
|
|
4708
|
+
break;
|
|
4709
|
+
}
|
|
4710
|
+
} catch (error) {
|
|
4711
|
+
if (!(error instanceof HostUsageTranscriptSourceError)) throw error;
|
|
4712
|
+
onFailure();
|
|
4713
|
+
}
|
|
4437
4714
|
}
|
|
4715
|
+
if (failed) writeHostServiceDiagnostic(this.producer, "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
4716
|
+
return captured;
|
|
4438
4717
|
}
|
|
4439
|
-
|
|
4440
|
-
}
|
|
4718
|
+
};
|
|
4441
4719
|
async function openHostUsageTranscriptCursor(input) {
|
|
4442
4720
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants5.O_RDONLY));
|
|
4443
4721
|
let source;
|
|
@@ -4736,6 +5014,13 @@ var CodexOutboxStore = class {
|
|
|
4736
5014
|
await removeOwnerState(this.registrationPath(registration.host_source_ref, registration.host_session_ref), "registration");
|
|
4737
5015
|
await removeOwnerState(this.cursorPath(registration.host_source_ref, registration.host_session_ref), "cursor");
|
|
4738
5016
|
}
|
|
5017
|
+
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
5018
|
+
const path = this.registrationPath(hostSourceRef, hostSessionRef);
|
|
5019
|
+
await this.prepare();
|
|
5020
|
+
const registration = await readOptionalJson2(path, validateRegistration);
|
|
5021
|
+
if (registration !== null && (registration.host_source_ref !== hostSourceRef || registration.host_session_ref !== hostSessionRef)) throw storageError("Codex transcript registration identity does not match its session.");
|
|
5022
|
+
return registration;
|
|
5023
|
+
}
|
|
4739
5024
|
async listTranscriptRegistrations() {
|
|
4740
5025
|
await this.prepare();
|
|
4741
5026
|
const registrations = [];
|
|
@@ -4762,16 +5047,16 @@ var CodexOutboxStore = class {
|
|
|
4762
5047
|
}
|
|
4763
5048
|
async findByAlias(sourceRef, sessionRef, alias) {
|
|
4764
5049
|
if (!SAFE_REF3.test(sourceRef) || !SAFE_REF3.test(sessionRef) || !SAFE_REF3.test(alias)) return null;
|
|
4765
|
-
const
|
|
4766
|
-
const envelope = findEnvelopeByAlias(
|
|
5050
|
+
const read2 = await this.list();
|
|
5051
|
+
const envelope = findEnvelopeByAlias(read2.entries, sourceRef, sessionRef, alias);
|
|
4767
5052
|
if (envelope !== null) return envelopeMatch(envelope);
|
|
4768
5053
|
await this.prepare();
|
|
4769
5054
|
return null;
|
|
4770
5055
|
}
|
|
4771
5056
|
async hasPriorTurn(sourceRef, sessionRef) {
|
|
4772
5057
|
if (!SAFE_REF3.test(sourceRef) || !SAFE_REF3.test(sessionRef)) return false;
|
|
4773
|
-
const
|
|
4774
|
-
if (
|
|
5058
|
+
const read2 = await this.list();
|
|
5059
|
+
if (read2.entries.some((entry) => entry.identity.host_source_ref === sourceRef && entry.identity.host_session_ref === sessionRef)) return true;
|
|
4775
5060
|
return false;
|
|
4776
5061
|
}
|
|
4777
5062
|
entryPath(submissionRef) {
|
|
@@ -4827,7 +5112,7 @@ async function writeAtomicJson(path, value) {
|
|
|
4827
5112
|
if (text === void 0) throw storageError("Codex owner state cannot be serialized.");
|
|
4828
5113
|
const temp = `${path}.${process.pid}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
4829
5114
|
try {
|
|
4830
|
-
const handle = await open4(temp, "wx");
|
|
5115
|
+
const handle = await open4(temp, "wx", 384);
|
|
4831
5116
|
try {
|
|
4832
5117
|
await handle.writeFile(text, "utf8");
|
|
4833
5118
|
await handle.sync();
|
|
@@ -4869,13 +5154,20 @@ async function readOptionalJson2(path, validate) {
|
|
|
4869
5154
|
}
|
|
4870
5155
|
async function ensureOwnerDirectory(path) {
|
|
4871
5156
|
try {
|
|
4872
|
-
|
|
5157
|
+
try {
|
|
5158
|
+
const stats2 = await stat2(path);
|
|
5159
|
+
if (!stats2.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
5160
|
+
return;
|
|
5161
|
+
} catch (error) {
|
|
5162
|
+
if (!isNotFound2(error)) throw error;
|
|
5163
|
+
}
|
|
5164
|
+
await mkdir4(path, { recursive: true, mode: 448 });
|
|
5165
|
+
const stats = await stat2(path);
|
|
5166
|
+
if (!stats.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
4873
5167
|
} catch (error) {
|
|
4874
|
-
if (
|
|
4875
|
-
|
|
5168
|
+
if (error instanceof CodexHostAdapterError) throw error;
|
|
5169
|
+
throw storageError("Codex owner state directory is unavailable.");
|
|
4876
5170
|
}
|
|
4877
|
-
const stats = await stat2(path);
|
|
4878
|
-
if (!stats.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
4879
5171
|
}
|
|
4880
5172
|
async function readOwnerStateFile(path) {
|
|
4881
5173
|
let handle;
|
|
@@ -5339,9 +5631,9 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5339
5631
|
const { size, device, inode } = await ownedCodexTranscriptFile(handle);
|
|
5340
5632
|
const preflight = await this.preflight(registration, handle, size, device, inode);
|
|
5341
5633
|
if (preflight.cursor === null) return preflight.result;
|
|
5634
|
+
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 });
|
|
5342
5635
|
const complete = await this.readChunk(handle, preflight.cursor.offset, size);
|
|
5343
5636
|
if (complete === "empty" || complete === "partial") {
|
|
5344
|
-
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 });
|
|
5345
5637
|
return { records: 0, enqueued: 0, quarantined: false };
|
|
5346
5638
|
}
|
|
5347
5639
|
return await this.consumeCompleteChunk(registration, handle, preflight.cursor, complete, device, inode);
|
|
@@ -5358,17 +5650,17 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5358
5650
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
5359
5651
|
let cursor = existing ?? codexTranscriptInitialCursor(registration, device, inode, this.now);
|
|
5360
5652
|
if (cursor.status === "quarantined") {
|
|
5361
|
-
return { cursor: null,
|
|
5653
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
5362
5654
|
}
|
|
5363
5655
|
const reason = this.cursorIdentityReason(cursor, registration.transcript_path, device, inode) ?? await this.cursorBoundsReason(handle, cursor, size);
|
|
5364
5656
|
if (reason === null) {
|
|
5365
|
-
if (cursor.human_message_window !== void 0) return { cursor,
|
|
5657
|
+
if (cursor.human_message_window !== void 0) return { cursor, checkpointPending: existing === null, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
5366
5658
|
const humanWindow = await this.readHumanMessageProjection(handle, registration, cursor);
|
|
5367
|
-
return { cursor: { ...cursor, human_message_window: humanWindow },
|
|
5659
|
+
return { cursor: { ...cursor, human_message_window: humanWindow }, checkpointPending: true, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
5368
5660
|
}
|
|
5369
5661
|
await this.quarantine(registration, cursor, device, inode, reason);
|
|
5370
5662
|
this.diagnostic("watcher_scan_failed", "other", `cursor_${reason}`);
|
|
5371
|
-
return { cursor: null,
|
|
5663
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
5372
5664
|
}
|
|
5373
5665
|
async readHumanMessageProjection(handle, registration, cursor) {
|
|
5374
5666
|
return readCodexHumanMessageProjection(registration, cursor, (offset, size) => this.readChunk(handle, offset, size));
|
|
@@ -5681,20 +5973,16 @@ var CodexUsageFactsCapturer = class {
|
|
|
5681
5973
|
sources;
|
|
5682
5974
|
usage;
|
|
5683
5975
|
now;
|
|
5684
|
-
|
|
5685
|
-
nextRegistrationIndex = 0;
|
|
5976
|
+
registrations;
|
|
5686
5977
|
constructor(options) {
|
|
5687
5978
|
this.sources = new CodexOutboxStore(options.outbox_dir);
|
|
5688
5979
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
5689
5980
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
5690
|
-
this.
|
|
5981
|
+
this.registrations = new HostUsageRegistrationCapture("codex", options.diagnostic_sink);
|
|
5691
5982
|
}
|
|
5692
5983
|
async captureNext() {
|
|
5693
5984
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
5694
|
-
|
|
5695
|
-
this.nextRegistrationIndex = result.nextIndex;
|
|
5696
|
-
if (result.failed) writeHostServiceDiagnostic("codex", "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
5697
|
-
return result.captured;
|
|
5985
|
+
return await this.registrations.captureNext(registrations, (registration) => this.captureRegistration(registration));
|
|
5698
5986
|
}
|
|
5699
5987
|
async captureRegistration(registration) {
|
|
5700
5988
|
const prepared = await openHostUsageTranscriptCursor({
|
|
@@ -5862,12 +6150,11 @@ function normalizedCounts(selected) {
|
|
|
5862
6150
|
function nullCounts() {
|
|
5863
6151
|
return { input: null, output: null, total: null, cached_input: null, cache_write_input: null, reasoning_output: null };
|
|
5864
6152
|
}
|
|
5865
|
-
var USAGE_COUNT_FIELDS = ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"];
|
|
5866
6153
|
function isRegression(current, previous) {
|
|
5867
|
-
return
|
|
6154
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.some((key) => current[key] < previous[key]);
|
|
5868
6155
|
}
|
|
5869
6156
|
function sameCounts(left, right) {
|
|
5870
|
-
return
|
|
6157
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.every((key) => left[key] === right[key]);
|
|
5871
6158
|
}
|
|
5872
6159
|
function buildCoverageGaps(sourceFileRef, startOffset, endOffset, counts) {
|
|
5873
6160
|
return [...counts].map(([reason, omittedCount]) => coverageGap(reason, sourceFileRef, startOffset, endOffset, omittedCount));
|
|
@@ -5916,12 +6203,12 @@ var CODEX_PRODUCER_DESCRIPTOR = {
|
|
|
5916
6203
|
config: (shared, extras) => ({ ...shared, codex_sessions_root: hostProducerExtraPath(extras, CODEX_SESSIONS_ROOT) }),
|
|
5917
6204
|
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir }),
|
|
5918
6205
|
drain: drainCodexProducerOnce,
|
|
5919
|
-
background: (config, signal) => {
|
|
6206
|
+
background: (config, signal, dependencies) => {
|
|
5920
6207
|
const capturer = new CodexUsageFactsCapturer({ outbox_dir: config.outbox_dir });
|
|
5921
|
-
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);
|
|
6208
|
+
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);
|
|
5922
6209
|
}
|
|
5923
6210
|
};
|
|
5924
|
-
function runCodexProducerCli(args, signal, dependencies
|
|
6211
|
+
function runCodexProducerCli(args, signal, dependencies) {
|
|
5925
6212
|
return runHostProducerCli(CODEX_PRODUCER_DESCRIPTOR, args, signal, dependencies);
|
|
5926
6213
|
}
|
|
5927
6214
|
|
|
@@ -5948,4 +6235,4 @@ async function runProducerCommand(schemaVersion, run) {
|
|
|
5948
6235
|
}
|
|
5949
6236
|
|
|
5950
6237
|
// host/codex/bin/ceal-codex-producer.ts
|
|
5951
|
-
await runProducerCommand("ceal.codex_producer_command.v1", runCodexProducerCli);
|
|
6238
|
+
await runProducerCommand("ceal.codex_producer_command.v1", (args, signal) => runCodexProducerCli(args, signal, { fetch: globalThis.fetch }));
|