@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
|
@@ -8,6 +8,15 @@ import { realpath } from "node:fs/promises";
|
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { isAbsolute as isAbsolute4, relative, resolve as resolve2 } from "node:path";
|
|
10
10
|
|
|
11
|
+
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
12
|
+
function vocabulary(words) {
|
|
13
|
+
return Object.freeze(words);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// packages/ceal-client-protocol/src/host-usage-fields.ts
|
|
17
|
+
var CEAL_CODEX_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"]);
|
|
18
|
+
var CEAL_CLAUDE_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "output_tokens"]);
|
|
19
|
+
|
|
11
20
|
// packages/ceal-client-protocol/src/canonical-json.ts
|
|
12
21
|
function cealCanonicalJson(value) {
|
|
13
22
|
if (value === null || typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
@@ -82,7 +91,7 @@ var client_wire_contract_default = {
|
|
|
82
91
|
},
|
|
83
92
|
command_request: {
|
|
84
93
|
schema_name: "ceal.command_request",
|
|
85
|
-
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context"],
|
|
94
|
+
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context", "materialize_result"],
|
|
86
95
|
absolute_transport_max_bytes: 65536
|
|
87
96
|
},
|
|
88
97
|
command_resolution: {
|
|
@@ -128,7 +137,7 @@ var client_wire_contract_default = {
|
|
|
128
137
|
},
|
|
129
138
|
command_response: {
|
|
130
139
|
schema_name: "ceal.command_response",
|
|
131
|
-
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context"],
|
|
140
|
+
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context", "result_file"],
|
|
132
141
|
descriptor_field: "verified_artifact",
|
|
133
142
|
request_context_field: "request_context",
|
|
134
143
|
required_fields: [
|
|
@@ -141,7 +150,8 @@ var client_wire_contract_default = {
|
|
|
141
150
|
"visible_output_max_bytes",
|
|
142
151
|
"local_delivery",
|
|
143
152
|
"verified_artifact",
|
|
144
|
-
"request_context"
|
|
153
|
+
"request_context",
|
|
154
|
+
"result_file"
|
|
145
155
|
],
|
|
146
156
|
bare_document_fields: [
|
|
147
157
|
"invocation",
|
|
@@ -182,8 +192,11 @@ var client_wire_contract_default = {
|
|
|
182
192
|
"ok",
|
|
183
193
|
"code",
|
|
184
194
|
"reason",
|
|
185
|
-
"gateway_status"
|
|
195
|
+
"gateway_status",
|
|
196
|
+
"retry_after_ms"
|
|
186
197
|
],
|
|
198
|
+
refusal_required_fields: ["schema_version", "ok", "code", "reason"],
|
|
199
|
+
refusal_optional_fields: ["gateway_status", "retry_after_ms"],
|
|
187
200
|
client_nonce: {
|
|
188
201
|
character_class_source: "A-Za-z0-9_-",
|
|
189
202
|
encoded_characters: 43
|
|
@@ -402,16 +415,14 @@ var CEAL_OPERATION_WITHHELD_NEXT_ACTIONS = Object.freeze({
|
|
|
402
415
|
personal_authorization_required: "connect_personal_account"
|
|
403
416
|
});
|
|
404
417
|
|
|
405
|
-
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
406
|
-
function vocabulary(words) {
|
|
407
|
-
return Object.freeze(words);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
418
|
// packages/ceal-client-protocol/src/gateway-response-types.ts
|
|
411
419
|
var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavailable", "unknown"]);
|
|
412
420
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
413
421
|
var CEAL_AUDIT_OUTCOMES = vocabulary(["succeeded", "denied", "failed"]);
|
|
414
422
|
var CEAL_GATEWAY_PROVIDER_STEP_OUTCOMES = vocabulary(["completed", "rejected", "throttled", "failed"]);
|
|
423
|
+
var CEAL_GATEWAY_CORPUS_READ_PROVIDERS = vocabulary(["slack", "google_drive", "notion"]);
|
|
424
|
+
var CEAL_GATEWAY_CORPUS_READ_OUTCOMES = vocabulary(["answered_from_corpus", "live_fallback"]);
|
|
425
|
+
var CEAL_GATEWAY_CORPUS_READ_FALLBACK_REASONS = vocabulary(["uncovered_window", "stale", "not_organization_public", "partition_missing"]);
|
|
415
426
|
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"]);
|
|
416
427
|
var CEAL_GATEWAY_READ_REUSE_UNAVAILABLE_REASONS = vocabulary(["not_reported", "storage_unavailable", "coverage_incomplete", "freshness_refresh_required", "not_reusable", "bypassed"]);
|
|
417
428
|
var CEAL_GATEWAY_DERIVED_STORE_FAILURE_CLASSES = vocabulary(["storage_unavailable", "decode_mismatch", "write_conflict", "quota", "store_error"]);
|
|
@@ -452,6 +463,21 @@ var CEAL_GATEWAY_ORGANIZATION_ROUTE_FACT_CALL_KEYS = Object.freeze([
|
|
|
452
463
|
]);
|
|
453
464
|
|
|
454
465
|
// packages/ceal-client-protocol/src/gateway-validation-primitives.ts
|
|
466
|
+
var POSIX_HOME_ROOTS = [["/", "home"].join(""), ["/", "Users"].join("")];
|
|
467
|
+
var WINDOWS_HOME_ROOT = ["C:", "\\", "Users"].join("");
|
|
468
|
+
var USER_SEGMENT_BODY = "[^/\\\\ \\t\\r\\n\"'`${}]+";
|
|
469
|
+
var POSIX_SEGMENT_END = "(?:/|$|(?=[\\s\"'`]))";
|
|
470
|
+
var WINDOWS_SEGMENT_END = "(?:\\\\+|$|(?=[\\s\"'`]))";
|
|
471
|
+
var WINDOWS_USER_SEGMENT_BODY = "[^\\\\ \\t\\r\\n\"'`${}]+";
|
|
472
|
+
var ABSOLUTE_PATH_BOUNDARY = "(?<![A-Za-z0-9_])";
|
|
473
|
+
function escapePathPattern(value) {
|
|
474
|
+
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
475
|
+
}
|
|
476
|
+
function machineHomePathPatterns(flags) {
|
|
477
|
+
const posix5 = `${ABSOLUTE_PATH_BOUNDARY}(?:${POSIX_HOME_ROOTS.map(escapePathPattern).join("|")})/${USER_SEGMENT_BODY}${POSIX_SEGMENT_END}`;
|
|
478
|
+
const windows = `${ABSOLUTE_PATH_BOUNDARY}${escapePathPattern(WINDOWS_HOME_ROOT)}\\\\+${WINDOWS_USER_SEGMENT_BODY}${WINDOWS_SEGMENT_END}`;
|
|
479
|
+
return [new RegExp(posix5, flags), new RegExp(windows, flags)];
|
|
480
|
+
}
|
|
455
481
|
var CealProtocolValidationError = class extends Error {
|
|
456
482
|
name = "CealProtocolValidationError";
|
|
457
483
|
code;
|
|
@@ -805,8 +831,9 @@ var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask a
|
|
|
805
831
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
806
832
|
var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Relay to the same release as the Gateway, then retry.";
|
|
807
833
|
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.";
|
|
808
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select
|
|
834
|
+
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.";
|
|
809
835
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
836
|
+
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
810
837
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
811
838
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
812
839
|
}
|
|
@@ -827,13 +854,18 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
827
854
|
context_not_selected: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
828
855
|
context_store_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
829
856
|
context_store_conflict: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
830
|
-
refresh_invalid: guidance(
|
|
831
|
-
refresh_expired: guidance(
|
|
832
|
-
refresh_replayed: guidance(
|
|
833
|
-
refresh_revoked: guidance(
|
|
834
|
-
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
835
|
-
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
836
|
-
|
|
857
|
+
refresh_invalid: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
858
|
+
refresh_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
859
|
+
refresh_replayed: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
860
|
+
refresh_revoked: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
861
|
+
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),
|
|
862
|
+
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),
|
|
863
|
+
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),
|
|
864
|
+
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
865
|
+
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),
|
|
866
|
+
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),
|
|
867
|
+
refresh_state_unavailable: guidance("The Gateway session state store is temporarily unavailable; retry the same refresh attempt when it is available.", "retry", 503, true),
|
|
868
|
+
refresh_recovery_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
837
869
|
refresh_custody_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
838
870
|
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),
|
|
839
871
|
local_output_exists: guidance("The selected local output path already exists; nothing was written to it.", "choose_new_output_path", 400),
|
|
@@ -848,23 +880,21 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
848
880
|
resource_stream_failed: guidance("The provider resource stream failed; ask an administrator to inspect the Gateway failure log.", "ask_admin", 500),
|
|
849
881
|
gateway_unavailable: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 503, true),
|
|
850
882
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
851
|
-
//
|
|
852
|
-
|
|
853
|
-
// when the wait ends still unserved, moved from the `localFailureText` default branch.
|
|
854
|
-
[CEAL_GATEWAY_STARTING_FAILURE_CODE]: guidance(LOCAL_TRANSPORT_INCOMPLETE, "answer_with_gap", 503, true),
|
|
883
|
+
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
884
|
+
[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),
|
|
855
885
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
856
886
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
857
887
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
858
888
|
internal_error: guidance("The Gateway failed without exposing internal state.", "answer_with_gap", 500),
|
|
859
889
|
// Owned by the Gateway canonical adapter (`gateway/core/src/gateway-canonical-operation-http-adapter.ts`):
|
|
860
|
-
// the client variant
|
|
890
|
+
// the static client variant was retired when the client started reading this table.
|
|
861
891
|
request_body_too_large: guidance("The Gateway request body exceeds its bounded limit.", "reduce_request_size", 413),
|
|
862
892
|
gateway_response_too_large: guidance("The Gateway response exceeds its bounded limit; reduce the requested page or result size.", "reduce_request_size", 500),
|
|
863
|
-
//
|
|
864
|
-
//
|
|
865
|
-
|
|
866
|
-
//
|
|
867
|
-
|
|
893
|
+
// The safe move varies by request. Keep the sentence conditional on the
|
|
894
|
+
// same `retryable` and `next_action` facts the response exposes.
|
|
895
|
+
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
896
|
+
// 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.
|
|
897
|
+
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),
|
|
868
898
|
// Restored verbatim from the retired `localFailureText`
|
|
869
899
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
870
900
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -945,8 +975,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
945
975
|
// Host mint classifications. The CLI emits `invocation_authentication_unavailable` with the classification
|
|
946
976
|
// in its detail fact; rows without their own sentence share that code's moved sentence, while `next_action`
|
|
947
977
|
// is moved from `canonicalHostAuthenticationNextActions` (generated from `CEAL_HOST_AUTHENTICATION_POLICY`)
|
|
948
|
-
// and `retryable` from `hostAuthenticationFailureForCause` (
|
|
949
|
-
// sentences carry the
|
|
978
|
+
// and `retryable` from `hostAuthenticationFailureForCause` (the table's explicit retry verdict). Cause-specific
|
|
979
|
+
// sentences carry only remedies proved by the Host or Relay cause; generic Gateway refusals do not prove a release mismatch.
|
|
950
980
|
// Statuses are the
|
|
951
981
|
// Gateway-owned mapping decided with the operator 2026-10-13. This covers every wire cause the maps at
|
|
952
982
|
// `host/invocation-authentication-command.ts:217-242` emit, through their policy classifications.
|
|
@@ -956,21 +986,23 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
956
986
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
957
987
|
// changes mode; standalone remains the separate Client authority path.
|
|
958
988
|
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "answer_with_gap", 401),
|
|
959
|
-
|
|
960
|
-
|
|
989
|
+
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),
|
|
990
|
+
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),
|
|
991
|
+
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),
|
|
961
992
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
962
993
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
963
994
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
964
995
|
host_mint_gateway_rate_limited: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 429),
|
|
965
|
-
host_mint_gateway_refused: guidance(
|
|
996
|
+
host_mint_gateway_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
966
997
|
host_mint_gateway_response_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
998
|
+
host_contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 502),
|
|
967
999
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
968
1000
|
// producer-frame fault names the administrator repair step.
|
|
969
1001
|
host_producer_frame_invalid: guidance("Ask an administrator to inspect and repair the producer frame, then start a fresh Host turn.", "ask_admin", 400),
|
|
970
1002
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
971
1003
|
// sandboxed Relay socket names the run-alone retry.
|
|
972
1004
|
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),
|
|
973
|
-
host_relay_unavailable: guidance(
|
|
1005
|
+
host_relay_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 503),
|
|
974
1006
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
975
1007
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
976
1008
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -1008,7 +1040,7 @@ var UNKNOWN_OUTCOMES = vocabulary(["reconcile", "operator_action", "excluded"]);
|
|
|
1008
1040
|
var RECOVERY_OWNERS = vocabulary(["gateway", "connector", "operator"]);
|
|
1009
1041
|
var CEAL_OPERATION_ADMISSION_STATES = vocabulary(["proposed", "refused", "admitted"]);
|
|
1010
1042
|
var CEAL_OPERATION_EXECUTION_STATES = vocabulary(["not_started", "started", "completed"]);
|
|
1011
|
-
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1043
|
+
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_applicable", "not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1012
1044
|
var CEAL_OPERATION_EFFECT_STATES = vocabulary(["none", "applied", "failed", "unknown", "compensated"]);
|
|
1013
1045
|
var CEAL_OPERATION_OBSERVATION_STATES = vocabulary(["not_started", "not_required", "pending", "observed", "unavailable"]);
|
|
1014
1046
|
var CEAL_OPERATION_RECOVERY_KINDS = vocabulary(["none", "reconcile", "compensate", "operator_action"]);
|
|
@@ -1179,6 +1211,7 @@ var CEAL_OPERATION_ACCESS_CLASSES = vocabulary(["read", "write"]);
|
|
|
1179
1211
|
// packages/ceal-client-protocol/src/domain-vocabulary.ts
|
|
1180
1212
|
var CEAL_CONNECTOR_STATUSES = vocabulary(["active", "disabled", "disconnected"]);
|
|
1181
1213
|
var CEAL_CONNECTOR_CUSTODIES = vocabulary(["organization", "personal"]);
|
|
1214
|
+
var CEAL_PROVIDER_BOUNDARY_FIELDS = vocabulary(["provider_boundary_ref", "provider_boundary_kind", "provider_boundary_label", "provider_native_id", "provider_boundary_evidence"]);
|
|
1182
1215
|
var CEAL_PERSONAL_ACCESS_CEILINGS = vocabulary(["disabled", "read", "read_write"]);
|
|
1183
1216
|
var CEAL_TARGET_REF_PATTERN = "^[^\\p{Cc}]+$";
|
|
1184
1217
|
var TARGET_REF = new RegExp(CEAL_TARGET_REF_PATTERN, "u");
|
|
@@ -1224,7 +1257,7 @@ var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
|
1224
1257
|
var CEAL_OPERATION_AUTHORITY_POLICY_KEYS = Object.freeze(["access_group", "instance_binding", "target", "admission_recheck"]);
|
|
1225
1258
|
var MAX_OPERATION_INPUT_RESOLVER_BINDINGS = 96;
|
|
1226
1259
|
var CEAL_OPERATION_DESCRIPTOR_REQUIRED_ENVELOPE_KEYS = Object.freeze(["schema_version", "id", "input_contract", "result_contract", "policy"]);
|
|
1227
|
-
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary"]);
|
|
1260
|
+
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary", "standard_names"]);
|
|
1228
1261
|
|
|
1229
1262
|
// packages/ceal-client-protocol/src/operation-catalog.ts
|
|
1230
1263
|
var CEAL_OPERATION_CATALOG_SCHEMA_VERSION = "ceal.catalog.v3";
|
|
@@ -1320,6 +1353,7 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
1320
1353
|
gateway_access_group_connector_activity_scope_audit: (root) => join(root, "profile-connector-activity-scope-audit.jsonl"),
|
|
1321
1354
|
gateway_access_group_connector_calendar_scope_audit: (root) => join(root, "profile-connector-calendar-scope-audit.jsonl"),
|
|
1322
1355
|
gateway_access_group_connector_readiness_audit: (root) => join(root, "profile-connector-readiness.audit.jsonl"),
|
|
1356
|
+
gateway_deployment_events: (root) => join(root, "gateway-deployments.jsonl"),
|
|
1323
1357
|
gateway_organization_audit_ledger: (root) => join(root, "organization-ledger.jsonl"),
|
|
1324
1358
|
gateway_personal_client_audit: (root) => join(root, "audit.jsonl"),
|
|
1325
1359
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
@@ -1346,6 +1380,11 @@ var CEAL_HOST_INSTALLATION_REF_PATTERN = new RegExp(`^host-installation:${CEAL_L
|
|
|
1346
1380
|
var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUID_PATTERN}$`, "u");
|
|
1347
1381
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
1348
1382
|
|
|
1383
|
+
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1384
|
+
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
1385
|
+
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
1386
|
+
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1387
|
+
|
|
1349
1388
|
// packages/ceal-client-protocol/src/operation-result-completeness.ts
|
|
1350
1389
|
var CEAL_READ_VALUE_CONTINUATION_KEYS = vocabulary(["continuation", "continuation_ref", "next_cursor"]);
|
|
1351
1390
|
|
|
@@ -1430,6 +1469,7 @@ var PROVIDER_LINK_CONFORMANCE_TABLE = Object.freeze([
|
|
|
1430
1469
|
{ 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" },
|
|
1431
1470
|
{ 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" },
|
|
1432
1471
|
{ 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" },
|
|
1472
|
+
{ 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" },
|
|
1433
1473
|
{ 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" },
|
|
1434
1474
|
{ 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" },
|
|
1435
1475
|
{ 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" },
|
|
@@ -1504,6 +1544,8 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1504
1544
|
"review_submitted",
|
|
1505
1545
|
"comment_created",
|
|
1506
1546
|
"reaction_created",
|
|
1547
|
+
"pull_request_merged",
|
|
1548
|
+
"release_published",
|
|
1507
1549
|
"ceal_write_completed",
|
|
1508
1550
|
"event_start",
|
|
1509
1551
|
"all_day_start",
|
|
@@ -1515,7 +1557,7 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1515
1557
|
"page_last_edited",
|
|
1516
1558
|
"resource_modified"
|
|
1517
1559
|
]);
|
|
1518
|
-
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "notion"]);
|
|
1560
|
+
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "google-mail", "notion"]);
|
|
1519
1561
|
var CEAL_ACTIVITY_UNSUPPORTED_EVENT_KIND_CODE = "unsupported_event_kind";
|
|
1520
1562
|
var CEAL_ACTIVITY_GAP_CODES = vocabulary([
|
|
1521
1563
|
"provider_page_budget",
|
|
@@ -1536,6 +1578,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1536
1578
|
"github.pull_request.opened",
|
|
1537
1579
|
"github.issue.edited",
|
|
1538
1580
|
"github.pull_request.edited",
|
|
1581
|
+
"github.pull_request.merged",
|
|
1582
|
+
"github.release.published",
|
|
1539
1583
|
"github.review.submitted",
|
|
1540
1584
|
"github.issue_comment.created",
|
|
1541
1585
|
"github.review_comment.created",
|
|
@@ -1549,6 +1593,7 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1549
1593
|
"drive.file.created",
|
|
1550
1594
|
"drive.file.modified",
|
|
1551
1595
|
"drive.file.viewed",
|
|
1596
|
+
"mail.sent",
|
|
1552
1597
|
"notion.page.created",
|
|
1553
1598
|
"notion.page.edited"
|
|
1554
1599
|
]);
|
|
@@ -1562,6 +1607,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1562
1607
|
"github.review_comment.created": "comment_created",
|
|
1563
1608
|
"github.issue.opened": "resource_created",
|
|
1564
1609
|
"github.pull_request.opened": "resource_created",
|
|
1610
|
+
"github.pull_request.merged": "pull_request_merged",
|
|
1611
|
+
"github.release.published": "release_published",
|
|
1565
1612
|
"github.issue.edited": "resource_modified",
|
|
1566
1613
|
"github.pull_request.edited": "resource_modified",
|
|
1567
1614
|
"github.reaction.created": "reaction_created",
|
|
@@ -1572,6 +1619,7 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1572
1619
|
"drive.file.created": "file_created",
|
|
1573
1620
|
"drive.file.modified": "file_modified_by_me",
|
|
1574
1621
|
"drive.file.viewed": "file_viewed_by_me",
|
|
1622
|
+
"mail.sent": "message_created",
|
|
1575
1623
|
"notion.page.created": "page_created",
|
|
1576
1624
|
"notion.page.edited": "page_last_edited"
|
|
1577
1625
|
});
|
|
@@ -1599,6 +1647,7 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
1599
1647
|
created_at: { required: false, timestamp: true },
|
|
1600
1648
|
created_at_local: { required: false, timestamp: true },
|
|
1601
1649
|
modified_at: { required: false, timestamp: true },
|
|
1650
|
+
observed_at: { required: false, timestamp: true },
|
|
1602
1651
|
modified_at_local: { required: false, timestamp: true },
|
|
1603
1652
|
viewed_by_me_at: { required: false, timestamp: true },
|
|
1604
1653
|
modified_by_me_at: { required: false, timestamp: true },
|
|
@@ -1626,9 +1675,6 @@ var RESOURCE_ROW_REQUIRED_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(
|
|
|
1626
1675
|
var RESOURCE_ROW_KEYS = new Set(Object.keys(RESOURCE_ROW_KEY_RULES));
|
|
1627
1676
|
var RESOURCE_ROW_TIMESTAMP_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(([key, rule]) => rule.timestamp ? [key] : []);
|
|
1628
1677
|
|
|
1629
|
-
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1630
|
-
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1631
|
-
|
|
1632
1678
|
// packages/ceal-client-protocol/src/excluded-target-coverage.ts
|
|
1633
1679
|
var CEAL_EXCLUDED_TARGET_COVERAGE_MAX_ENTRIES = 64;
|
|
1634
1680
|
function cealExcludedTargetCoverageJsonSchema() {
|
|
@@ -1684,6 +1730,8 @@ var CEAL_REFRESH_FAILURE_CODES = vocabulary([
|
|
|
1684
1730
|
"principal_inactive",
|
|
1685
1731
|
"authority_replaced",
|
|
1686
1732
|
"refresh_recovery_unavailable",
|
|
1733
|
+
"refresh_recovery_outcome_unavailable",
|
|
1734
|
+
"refresh_state_unavailable",
|
|
1687
1735
|
"refresh_recovery_expired",
|
|
1688
1736
|
// The serving gate answers this while the Gateway is still starting and the
|
|
1689
1737
|
// refresh was never attempted; the same attempt stays retryable. It is never
|
|
@@ -1935,7 +1983,7 @@ function validateBatchContents(value) {
|
|
|
1935
1983
|
if (facts.length === 0 && gaps.length === 0 || facts.length > 0 && value.source_ranges.length === 0) invalid("Ceal Host usage coverage is invalid.");
|
|
1936
1984
|
const sourceFiles = new Set(value.source_ranges.map((range) => sourceRangeFileRef(range)));
|
|
1937
1985
|
for (const fact of facts) {
|
|
1938
|
-
|
|
1986
|
+
validateCealHostUsageFact(fact, value.host_session_ref);
|
|
1939
1987
|
if (!sourceFiles.has(fact.source_file_ref)) invalid("Ceal Host usage fact is outside its source ranges.");
|
|
1940
1988
|
}
|
|
1941
1989
|
for (const gap of gaps) {
|
|
@@ -1968,7 +2016,7 @@ function hostUsageSourceFileReference(producer, hostSourceRef, hostSessionRef, d
|
|
|
1968
2016
|
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.");
|
|
1969
2017
|
return `host-source-file:${sha256(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef, device, inode }))}`;
|
|
1970
2018
|
}
|
|
1971
|
-
function
|
|
2019
|
+
function validateCealHostUsageFact(value, sessionRef) {
|
|
1972
2020
|
if (!isOperationRecord(value)) invalid("Ceal Host usage fact is invalid.");
|
|
1973
2021
|
requireFactByteLimit(value);
|
|
1974
2022
|
if (value.producer === "codex_transcript") validateCodexFact(value);
|
|
@@ -2032,7 +2080,7 @@ function validCorrectionSemantics(value) {
|
|
|
2032
2080
|
}
|
|
2033
2081
|
function validateCodexUsageCounts(value) {
|
|
2034
2082
|
if (!isOperationRecord(value)) invalid("Ceal Codex usage fields are invalid.");
|
|
2035
|
-
requireExactOperationKeys(value,
|
|
2083
|
+
requireExactOperationKeys(value, CEAL_CODEX_USAGE_COUNT_FIELDS);
|
|
2036
2084
|
for (const key of Object.keys(value)) if (!safeInteger(value[key])) invalid("Ceal Codex usage fields are invalid.");
|
|
2037
2085
|
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.");
|
|
2038
2086
|
}
|
|
@@ -2300,6 +2348,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
2300
2348
|
"options_invalid",
|
|
2301
2349
|
"session_unavailable",
|
|
2302
2350
|
"context_unavailable",
|
|
2351
|
+
"activation_wait_exhausted",
|
|
2303
2352
|
"context_replaced",
|
|
2304
2353
|
"no_binding",
|
|
2305
2354
|
"context_expired",
|
|
@@ -2335,22 +2384,23 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2335
2384
|
// This reason cannot distinguish a Codex side conversation from a missing
|
|
2336
2385
|
// context in a regular session, so guidance must leave that choice to the caller.
|
|
2337
2386
|
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "answer_with_gap" }),
|
|
2338
|
-
|
|
2387
|
+
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
2388
|
+
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
2339
2389
|
// `no_binding` now means the producer has no real current Host session. The
|
|
2340
2390
|
// Host Relay never uses it for an uncreated Gateway Request; there is no
|
|
2341
2391
|
// useful retry until the consumer is running inside a Host session.
|
|
2342
2392
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2343
|
-
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "
|
|
2393
|
+
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
2344
2394
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
2345
2395
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
2346
2396
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
2347
2397
|
gateway_rate_limited: Object.freeze({ classification: "host_mint_gateway_rate_limited", next_action: "answer_with_gap" }),
|
|
2348
|
-
contract_mismatch: Object.freeze({ classification: "
|
|
2349
|
-
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "
|
|
2398
|
+
contract_mismatch: Object.freeze({ classification: "host_contract_mismatch", next_action: "upgrade_ceal_client" }),
|
|
2399
|
+
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "answer_with_gap" }),
|
|
2350
2400
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
2351
2401
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
2352
2402
|
relay_permission_denied: Object.freeze({ classification: "host_relay_permission_denied", next_action: "rerun_outside_agent_sandbox" }),
|
|
2353
|
-
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "
|
|
2403
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "answer_with_gap" }),
|
|
2354
2404
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
2355
2405
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
2356
2406
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -2398,7 +2448,7 @@ function isCealHostServiceDiagnosticCause(value, event) {
|
|
|
2398
2448
|
// packages/ceal-client-protocol/src/client-result-materialization.ts
|
|
2399
2449
|
var CEAL_UNREAD_REASONS = vocabulary(["blocked", "unavailable", "too_large", "unsupported", "download_failed", "permission_denied"]);
|
|
2400
2450
|
var REQUIRED_FIELDS2 = Object.freeze(["schema_version", "operation_id", "path", "sha256"]);
|
|
2401
|
-
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "
|
|
2451
|
+
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "local_result_root", "request_context_argv", "how_to_read"]);
|
|
2402
2452
|
|
|
2403
2453
|
// packages/ceal-client-protocol/src/discovery-manifest.ts
|
|
2404
2454
|
var DISCOVERY_MANIFEST_KEYS = CEAL_CLIENT_WIRE_CONTRACT.command_response.discovery_manifest_fields;
|
|
@@ -2440,6 +2490,211 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
2440
2490
|
maximum: CEAL_PROTOCOL_VERSION
|
|
2441
2491
|
});
|
|
2442
2492
|
|
|
2493
|
+
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
2494
|
+
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
2495
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSES = 8;
|
|
2496
|
+
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
2497
|
+
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
2498
|
+
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
2499
|
+
var OPERATOR_DIAGNOSTIC_HOME_PATHS = machineHomePathPatterns("gu");
|
|
2500
|
+
function redactOperatorDiagnosticSecrets(value) {
|
|
2501
|
+
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]");
|
|
2502
|
+
}
|
|
2503
|
+
function redactOperatorDiagnosticText(value) {
|
|
2504
|
+
const normalized = normalizeCealSingleLineText(value);
|
|
2505
|
+
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
2506
|
+
}
|
|
2507
|
+
function renderOperatorDiagnostic(value) {
|
|
2508
|
+
const state = collectDiagnosticState(value);
|
|
2509
|
+
const fields = [
|
|
2510
|
+
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
2511
|
+
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
2512
|
+
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
2513
|
+
state.stderr === void 0 ? void 0 : `stderr_tail=${JSON.stringify(tail(state.stderr))}`,
|
|
2514
|
+
state.causes.length === 0 ? void 0 : `causes=${state.causes.map(formatCause).join(" <- ")}`
|
|
2515
|
+
].filter((field) => field !== void 0);
|
|
2516
|
+
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
2517
|
+
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
2518
|
+
}
|
|
2519
|
+
function collectDiagnosticState(value) {
|
|
2520
|
+
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0 };
|
|
2521
|
+
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
2522
|
+
while (pending.length > 0 && state.causes.length < OPERATOR_DIAGNOSTIC_MAX_CAUSES) {
|
|
2523
|
+
const current = pending.shift();
|
|
2524
|
+
if (current !== void 0) visitDiagnosticNode(current, state, pending, visited);
|
|
2525
|
+
}
|
|
2526
|
+
return state;
|
|
2527
|
+
}
|
|
2528
|
+
function visitDiagnosticNode(current, state, pending, visited) {
|
|
2529
|
+
if (isObject(current)) {
|
|
2530
|
+
if (visited.has(current)) return;
|
|
2531
|
+
visited.add(current);
|
|
2532
|
+
}
|
|
2533
|
+
captureProcessEvidence(current, state);
|
|
2534
|
+
appendCause(current, state.causes);
|
|
2535
|
+
enqueueCauseChildren(current, state.causes.length, pending);
|
|
2536
|
+
}
|
|
2537
|
+
function captureProcessEvidence(current, state) {
|
|
2538
|
+
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
2539
|
+
if (state.exitCode === void 0) state.exitCode = safeExitCode(read(current, "exitCode")) ?? safeExitCode(read(current, "status")) ?? safeExitCode(read(current, "code"));
|
|
2540
|
+
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
2541
|
+
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
2542
|
+
}
|
|
2543
|
+
function appendCause(current, causes) {
|
|
2544
|
+
const errors = read(current, "errors");
|
|
2545
|
+
if (current instanceof Error && (!(current instanceof AggregateError) || !Array.isArray(errors) || errors.length === 0)) {
|
|
2546
|
+
causes.push(errorCause(current));
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
if (!isObject(current)) {
|
|
2550
|
+
const message = safeText(current);
|
|
2551
|
+
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
function errorCause(error) {
|
|
2555
|
+
const name = safeText(read(error, "name")) ?? "Error";
|
|
2556
|
+
const message = safeText(read(error, "message"));
|
|
2557
|
+
const codeValue = read(error, "code");
|
|
2558
|
+
const code = typeof codeValue === "number" && Number.isFinite(codeValue) ? codeValue : safeText(codeValue);
|
|
2559
|
+
const errnoValue = read(error, "errno");
|
|
2560
|
+
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
2561
|
+
const syscall = safeText(read(error, "syscall"));
|
|
2562
|
+
const path = safePath(read(error, "path"));
|
|
2563
|
+
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 } });
|
|
2564
|
+
}
|
|
2565
|
+
function enqueueCauseChildren(current, causeCount, pending) {
|
|
2566
|
+
const cause = read(current, "cause");
|
|
2567
|
+
if (cause !== void 0) pending.push(cause);
|
|
2568
|
+
const errors = read(current, "errors");
|
|
2569
|
+
if (Array.isArray(errors)) pending.push(...errors.slice(0, OPERATOR_DIAGNOSTIC_MAX_CAUSES - causeCount));
|
|
2570
|
+
}
|
|
2571
|
+
function isObject(value) {
|
|
2572
|
+
return typeof value === "object" && value !== null;
|
|
2573
|
+
}
|
|
2574
|
+
function formatCause(cause) {
|
|
2575
|
+
const fields = [
|
|
2576
|
+
cause.error_class,
|
|
2577
|
+
cause.code === void 0 ? void 0 : `code=${JSON.stringify(safeDiagnosticText(cause.code))}`,
|
|
2578
|
+
cause.errno === void 0 ? void 0 : `errno=${cause.errno}`,
|
|
2579
|
+
cause.syscall === void 0 ? void 0 : `syscall=${JSON.stringify(cause.syscall)}`,
|
|
2580
|
+
cause.path === void 0 ? void 0 : `path=${JSON.stringify(cause.path)}`,
|
|
2581
|
+
cause.message === void 0 ? void 0 : `message=${cause.message}`
|
|
2582
|
+
].filter((field) => field !== void 0);
|
|
2583
|
+
return fields.join(" ");
|
|
2584
|
+
}
|
|
2585
|
+
function tail(value) {
|
|
2586
|
+
const clipped = value.length <= OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT ? value : `…${value.slice(-OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT)}`;
|
|
2587
|
+
return safeDiagnosticText(clipped);
|
|
2588
|
+
}
|
|
2589
|
+
function safeText(value) {
|
|
2590
|
+
if (typeof value !== "string") return void 0;
|
|
2591
|
+
const safe = safeDiagnosticText(value);
|
|
2592
|
+
if (safe.length === 0) return void 0;
|
|
2593
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT) return safe;
|
|
2594
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT / 2);
|
|
2595
|
+
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
2596
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2597
|
+
}
|
|
2598
|
+
function safePath(value) {
|
|
2599
|
+
if (typeof value !== "string") return void 0;
|
|
2600
|
+
const safe = safeDiagnosticText(value);
|
|
2601
|
+
if (safe.length === 0) return void 0;
|
|
2602
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
2603
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
2604
|
+
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
2605
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2606
|
+
}
|
|
2607
|
+
function safeDiagnosticText(value) {
|
|
2608
|
+
return redactOperatorDiagnosticText(String(value));
|
|
2609
|
+
}
|
|
2610
|
+
function outputText(value) {
|
|
2611
|
+
if (typeof value === "string") return redactOperatorDiagnosticText(value);
|
|
2612
|
+
if (value instanceof Uint8Array) {
|
|
2613
|
+
try {
|
|
2614
|
+
return redactOperatorDiagnosticText(new TextDecoder().decode(value));
|
|
2615
|
+
} catch {
|
|
2616
|
+
return void 0;
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
return void 0;
|
|
2620
|
+
}
|
|
2621
|
+
function safeStatus(value) {
|
|
2622
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
2623
|
+
return typeof value === "string" ? safeText(value) : void 0;
|
|
2624
|
+
}
|
|
2625
|
+
function safeExitCode(value) {
|
|
2626
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
2627
|
+
}
|
|
2628
|
+
function read(value, key) {
|
|
2629
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) return void 0;
|
|
2630
|
+
try {
|
|
2631
|
+
return Reflect.get(value, key);
|
|
2632
|
+
} catch {
|
|
2633
|
+
return void 0;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
function redactHomePaths(value) {
|
|
2637
|
+
const paths = [
|
|
2638
|
+
...OPERATOR_DIAGNOSTIC_HOME_PATHS.flatMap((pattern) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, matchedHomePrefixLength(match[0])))),
|
|
2639
|
+
...configuredHomePathPatterns().flatMap(({ pattern, prefixLength }) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, prefixLength)))
|
|
2640
|
+
];
|
|
2641
|
+
paths.sort((left, right) => left.start - right.start || right.end - left.end);
|
|
2642
|
+
let output = "";
|
|
2643
|
+
let cursor = 0;
|
|
2644
|
+
for (const path of paths) {
|
|
2645
|
+
if (path.start < cursor) continue;
|
|
2646
|
+
output += `${value.slice(cursor, path.start)}[home path redacted]${value.slice(path.prefixEnd, path.end)}`;
|
|
2647
|
+
cursor = path.end;
|
|
2648
|
+
}
|
|
2649
|
+
return output + value.slice(cursor);
|
|
2650
|
+
}
|
|
2651
|
+
function configuredHomePathPatterns() {
|
|
2652
|
+
const homes = [...new Set([process.env.HOME, process.env.USERPROFILE].filter((home) => home !== void 0 && home.length > 0))];
|
|
2653
|
+
return homes.flatMap((home) => {
|
|
2654
|
+
const root = home.replace(/[\\/]+$/gu, "");
|
|
2655
|
+
if (root.length === 0 || root === "/" || /^[A-Za-z]:$/u.test(root)) return [];
|
|
2656
|
+
const pattern = new RegExp(`(?<![A-Za-z0-9_])${escapePathPattern(root)}(?=$|[\\\\/\\s"'\`<>(){}\\[\\],;])`, /^[A-Za-z]:[\\/]/u.test(root) ? "giu" : "gu");
|
|
2657
|
+
return [{ pattern, prefixLength: root.length }];
|
|
2658
|
+
});
|
|
2659
|
+
}
|
|
2660
|
+
function matchedHomePrefixLength(value) {
|
|
2661
|
+
let separators = 0;
|
|
2662
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
2663
|
+
if (value[index] !== "/" && value[index] !== "\\") continue;
|
|
2664
|
+
separators += 1;
|
|
2665
|
+
if (separators === 3) return index;
|
|
2666
|
+
}
|
|
2667
|
+
return value.length;
|
|
2668
|
+
}
|
|
2669
|
+
function redactUrls(value) {
|
|
2670
|
+
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
2671
|
+
}
|
|
2672
|
+
function redactFilePaths(value) {
|
|
2673
|
+
return value.replaceAll(/(?<![A-Za-z0-9._-]|\[home path redacted\])(?:[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/)[^:\r\n"'<>]*?(?=:\d+(?::\d+)?(?:[:\s]|$)|[\r\n]|["'])/gu, "[path redacted]");
|
|
2674
|
+
}
|
|
2675
|
+
function homePathRange(value, match, prefixLength) {
|
|
2676
|
+
const index = match.index;
|
|
2677
|
+
if (index === void 0) return { start: value.length, end: value.length, prefixEnd: value.length };
|
|
2678
|
+
const start = index;
|
|
2679
|
+
let end = start + match[0].length;
|
|
2680
|
+
const quote = start > 0 && (value[start - 1] === "'" || value[start - 1] === '"') ? value[start - 1] : void 0;
|
|
2681
|
+
if (quote !== void 0) {
|
|
2682
|
+
const closing = value.indexOf(quote, end);
|
|
2683
|
+
if (closing >= 0) end = closing;
|
|
2684
|
+
}
|
|
2685
|
+
while (end < value.length && !/[\s"'`<>(){}[\],;]/u.test(value[end] ?? "")) end += 1;
|
|
2686
|
+
return { start, end, prefixEnd: Math.min(start + prefixLength, end) };
|
|
2687
|
+
}
|
|
2688
|
+
function truncateUtf8(value, maxBytes) {
|
|
2689
|
+
if (byteLength(value) <= maxBytes) return value;
|
|
2690
|
+
let output = "";
|
|
2691
|
+
for (const character of value) {
|
|
2692
|
+
if (byteLength(`${output}${character}…`) > maxBytes) break;
|
|
2693
|
+
output += character;
|
|
2694
|
+
}
|
|
2695
|
+
return `${output}…`;
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2443
2698
|
// packages/ceal-client-protocol/src/admin-projection-vocabulary.ts
|
|
2444
2699
|
var ADMIN_PROJECTION_STATES = vocabulary(["ready", "empty", "partial", "unknown"]);
|
|
2445
2700
|
var ADMIN_VIEW_KINDS = vocabulary(["request_detail", "resource_access_timeline", "weekly_usage"]);
|
|
@@ -2822,7 +3077,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
2822
3077
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
2823
3078
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
2824
3079
|
return await new Promise((resolve3, reject3) => {
|
|
2825
|
-
const child = execFile(executable, processArgs, { encoding: "buffer", timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
3080
|
+
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
2826
3081
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
2827
3082
|
if (exitCode === null) {
|
|
2828
3083
|
reject3(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -2873,6 +3128,192 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
2873
3128
|
return entry.isDirectory() && !entry.isSymbolicLink() && isSelfOwned(entry.uid, platform) && isPrivateFileMode(entry.mode, platform);
|
|
2874
3129
|
}
|
|
2875
3130
|
|
|
3131
|
+
// host/service-log.ts
|
|
3132
|
+
import { copyFile, mkdir, stat, truncate, appendFile } from "node:fs/promises";
|
|
3133
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, posix, win32 as win322 } from "node:path";
|
|
3134
|
+
|
|
3135
|
+
// host/service-log-delivery.ts
|
|
3136
|
+
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
3137
|
+
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
3138
|
+
setImmediate(flush);
|
|
3139
|
+
}, onDeliveryGap = () => void 0) {
|
|
3140
|
+
const pending = [];
|
|
3141
|
+
const highWaterMark = stream.writableHighWaterMark;
|
|
3142
|
+
const byteBudget = highWaterMark + highWaterMark;
|
|
3143
|
+
let pendingBytes = 0;
|
|
3144
|
+
let droppedLines = 0;
|
|
3145
|
+
let flushScheduled = false;
|
|
3146
|
+
let waitingForDrain = false;
|
|
3147
|
+
let closed = !stream.writable;
|
|
3148
|
+
function stop() {
|
|
3149
|
+
if (closed) return;
|
|
3150
|
+
closed = true;
|
|
3151
|
+
pending.length = 0;
|
|
3152
|
+
pendingBytes = 0;
|
|
3153
|
+
stream.off("drain", onDrain);
|
|
3154
|
+
stream.off("close", onTerminal);
|
|
3155
|
+
stream.off("finish", onTerminal);
|
|
3156
|
+
stream.off("error", onError);
|
|
3157
|
+
}
|
|
3158
|
+
function onTerminal() {
|
|
3159
|
+
stop();
|
|
3160
|
+
}
|
|
3161
|
+
function onError() {
|
|
3162
|
+
stop();
|
|
3163
|
+
}
|
|
3164
|
+
function onDrain() {
|
|
3165
|
+
waitingForDrain = false;
|
|
3166
|
+
scheduleFlush();
|
|
3167
|
+
}
|
|
3168
|
+
function scheduleFlush() {
|
|
3169
|
+
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
3170
|
+
flushScheduled = true;
|
|
3171
|
+
let scheduling = true;
|
|
3172
|
+
let invokedSynchronously = false;
|
|
3173
|
+
try {
|
|
3174
|
+
schedule(() => {
|
|
3175
|
+
if (scheduling) {
|
|
3176
|
+
invokedSynchronously = true;
|
|
3177
|
+
return;
|
|
3178
|
+
}
|
|
3179
|
+
flushScheduled = false;
|
|
3180
|
+
flush();
|
|
3181
|
+
});
|
|
3182
|
+
} catch {
|
|
3183
|
+
flushScheduled = false;
|
|
3184
|
+
stop();
|
|
3185
|
+
return;
|
|
3186
|
+
}
|
|
3187
|
+
scheduling = false;
|
|
3188
|
+
if (invokedSynchronously) {
|
|
3189
|
+
flushScheduled = false;
|
|
3190
|
+
stop();
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
function flush() {
|
|
3194
|
+
if (closed) return;
|
|
3195
|
+
if (!stream.writable) {
|
|
3196
|
+
stop();
|
|
3197
|
+
return;
|
|
3198
|
+
}
|
|
3199
|
+
while (pending.length > 0) {
|
|
3200
|
+
if (stream.writableNeedDrain) {
|
|
3201
|
+
if (!waitingForDrain) {
|
|
3202
|
+
waitingForDrain = true;
|
|
3203
|
+
stream.once("drain", onDrain);
|
|
3204
|
+
}
|
|
3205
|
+
return;
|
|
3206
|
+
}
|
|
3207
|
+
const next = pending.shift();
|
|
3208
|
+
if (next === void 0) return;
|
|
3209
|
+
pendingBytes -= next.bytes;
|
|
3210
|
+
let accepted;
|
|
3211
|
+
try {
|
|
3212
|
+
accepted = stream.write(next.line);
|
|
3213
|
+
} catch {
|
|
3214
|
+
stop();
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3217
|
+
if (!accepted) {
|
|
3218
|
+
waitingForDrain = true;
|
|
3219
|
+
stream.once("drain", onDrain);
|
|
3220
|
+
return;
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
if (droppedLines > 0) {
|
|
3224
|
+
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
3225
|
+
`;
|
|
3226
|
+
droppedLines = 0;
|
|
3227
|
+
try {
|
|
3228
|
+
onDeliveryGap(line);
|
|
3229
|
+
} catch {
|
|
3230
|
+
}
|
|
3231
|
+
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
3232
|
+
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
3233
|
+
flush();
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
stream.on("close", onTerminal);
|
|
3237
|
+
stream.on("finish", onTerminal);
|
|
3238
|
+
stream.on("error", onError);
|
|
3239
|
+
return (line) => {
|
|
3240
|
+
if (closed) return;
|
|
3241
|
+
const bytes = Buffer.byteLength(line, "utf8");
|
|
3242
|
+
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
3243
|
+
droppedLines += 1;
|
|
3244
|
+
scheduleFlush();
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
pending.push({ line, bytes });
|
|
3248
|
+
pendingBytes += bytes;
|
|
3249
|
+
scheduleFlush();
|
|
3250
|
+
};
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3253
|
+
// host/invocation-authentication-client-command.ts
|
|
3254
|
+
var DOCTOR_FLAGS = Object.freeze({
|
|
3255
|
+
"--expected-sha256": "expected_sha256",
|
|
3256
|
+
"--expected-source-commit": "expected_source_commit",
|
|
3257
|
+
"--expected-instance-ref": "expected_instance_ref"
|
|
3258
|
+
});
|
|
3259
|
+
|
|
3260
|
+
// host/service-log.ts
|
|
3261
|
+
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
3262
|
+
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
3263
|
+
void persistHostServiceLogLine(line);
|
|
3264
|
+
});
|
|
3265
|
+
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
3266
|
+
const details = diagnosticDetails(event, failure_kind, cause);
|
|
3267
|
+
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
3268
|
+
`;
|
|
3269
|
+
try {
|
|
3270
|
+
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
3271
|
+
} catch {
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
function diagnosticDetails(event, failureKind, cause) {
|
|
3275
|
+
if (event === "watcher_scan_failed") return {
|
|
3276
|
+
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
3277
|
+
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
3278
|
+
};
|
|
3279
|
+
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
3280
|
+
}
|
|
3281
|
+
function validDiagnosticCause(cause, event) {
|
|
3282
|
+
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
3283
|
+
}
|
|
3284
|
+
function defaultHostServiceDiagnosticSink(line) {
|
|
3285
|
+
writeHostServiceLogLine(line);
|
|
3286
|
+
}
|
|
3287
|
+
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
3288
|
+
function writeHostServiceLogLine(line, environment = process.env) {
|
|
3289
|
+
void persistHostServiceLogLine(line, environment);
|
|
3290
|
+
defaultHostServiceLogDelivery(line);
|
|
3291
|
+
}
|
|
3292
|
+
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
3293
|
+
if (process.platform !== "win32") return;
|
|
3294
|
+
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
3295
|
+
if (path === void 0 || !win322.isAbsolute(path) || win322.normalize(path) !== path) return;
|
|
3296
|
+
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
3297
|
+
}
|
|
3298
|
+
async function appendHostServiceLogLine(path, line) {
|
|
3299
|
+
if (!isAbsolute2(path)) return;
|
|
3300
|
+
await ensureHostServiceLogDirectory(path);
|
|
3301
|
+
await appendFile(path, line);
|
|
3302
|
+
}
|
|
3303
|
+
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
3304
|
+
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
3305
|
+
function ensureHostServiceLogDirectory(path) {
|
|
3306
|
+
const directory = dirname2(path);
|
|
3307
|
+
const existing = hostServiceLogDirectories.get(directory);
|
|
3308
|
+
if (existing !== void 0) return existing;
|
|
3309
|
+
const pending = mkdir(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
3310
|
+
hostServiceLogDirectories.delete(directory);
|
|
3311
|
+
throw error;
|
|
3312
|
+
});
|
|
3313
|
+
hostServiceLogDirectories.set(directory, pending);
|
|
3314
|
+
return pending;
|
|
3315
|
+
}
|
|
3316
|
+
|
|
2876
3317
|
// host/relay/src/host-producer-core.ts
|
|
2877
3318
|
var HOST_TRANSCRIPT_CURSOR_REASONS = vocabulary(["transcript_replaced", "transcript_truncated", "transcript_rewritten", "transcript_malformed"]);
|
|
2878
3319
|
function isHostTranscriptCursorReason(value) {
|
|
@@ -2918,9 +3359,9 @@ async function readTranscriptCompleteChunk(handle, offset, size) {
|
|
|
2918
3359
|
let lastNewline = -1;
|
|
2919
3360
|
while (position < size) {
|
|
2920
3361
|
const buffer = Buffer.alloc(Math.min(HOST_TRANSCRIPT_READ_CHUNK_BYTES, size - position));
|
|
2921
|
-
const
|
|
2922
|
-
if (
|
|
2923
|
-
const chunk = buffer.subarray(0,
|
|
3362
|
+
const read2 = await handle.read(buffer, 0, buffer.length, position);
|
|
3363
|
+
if (read2.bytesRead === 0) break;
|
|
3364
|
+
const chunk = buffer.subarray(0, read2.bytesRead);
|
|
2924
3365
|
chunks.push(chunk);
|
|
2925
3366
|
const newline = chunk.lastIndexOf(10);
|
|
2926
3367
|
if (newline >= 0) lastNewline = total + newline;
|
|
@@ -2977,7 +3418,7 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
2977
3418
|
outboxRetentionMs: options.retention_ms ?? owner.default_retention_ms,
|
|
2978
3419
|
now: options.now ?? (() => /* @__PURE__ */ new Date()),
|
|
2979
3420
|
log: options.log ?? ((line) => {
|
|
2980
|
-
|
|
3421
|
+
writeHostServiceLogLine(`${line}
|
|
2981
3422
|
`);
|
|
2982
3423
|
}),
|
|
2983
3424
|
producerInstallationRef: options.producer_installation_ref
|
|
@@ -3017,7 +3458,13 @@ var HostTranscriptWatcher = class {
|
|
|
3017
3458
|
}
|
|
3018
3459
|
async scanRegistration(registration) {
|
|
3019
3460
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
3020
|
-
missing: () =>
|
|
3461
|
+
missing: async () => {
|
|
3462
|
+
try {
|
|
3463
|
+
return await this.retireMissing(registration);
|
|
3464
|
+
} catch (error) {
|
|
3465
|
+
return this.scanFailed(void 0, registration, error);
|
|
3466
|
+
}
|
|
3467
|
+
},
|
|
3021
3468
|
failed: (handle, error) => this.scanFailed(handle, registration, error)
|
|
3022
3469
|
});
|
|
3023
3470
|
}
|
|
@@ -3087,21 +3534,21 @@ var HostProducerDrainCore = class {
|
|
|
3087
3534
|
return run;
|
|
3088
3535
|
}
|
|
3089
3536
|
async drainLocked() {
|
|
3090
|
-
const
|
|
3537
|
+
const read2 = await this.host.listEnvelopes();
|
|
3091
3538
|
let removed = 0;
|
|
3092
3539
|
let expired = 0;
|
|
3093
|
-
for (const envelope of
|
|
3540
|
+
for (const envelope of read2.entries) {
|
|
3094
3541
|
if (Date.parse(this.host.expiresAtOf(envelope)) <= this.now().getTime()) expired += 1;
|
|
3095
3542
|
else removed += 1;
|
|
3096
3543
|
await this.host.removeEnvelope(envelope);
|
|
3097
3544
|
}
|
|
3098
|
-
return { removed, expired, malformed:
|
|
3545
|
+
return { removed, expired, malformed: read2.malformed };
|
|
3099
3546
|
}
|
|
3100
3547
|
};
|
|
3101
3548
|
|
|
3102
3549
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3103
|
-
import { lstat as lstat2, mkdir, open as open2, rename, unlink } from "node:fs/promises";
|
|
3104
|
-
import { dirname as
|
|
3550
|
+
import { lstat as lstat2, mkdir as mkdir2, open as open2, rename, unlink } from "node:fs/promises";
|
|
3551
|
+
import { dirname as dirname3 } from "node:path";
|
|
3105
3552
|
|
|
3106
3553
|
// host/windows-rename-retry.ts
|
|
3107
3554
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
@@ -3154,7 +3601,7 @@ function isRetryableRenameError(error) {
|
|
|
3154
3601
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3155
3602
|
var DEFAULT_PORT = {
|
|
3156
3603
|
platform: process.platform,
|
|
3157
|
-
mkdir: (path, options) =>
|
|
3604
|
+
mkdir: (path, options) => mkdir2(path, options),
|
|
3158
3605
|
lstat: (path) => lstat2(path),
|
|
3159
3606
|
open_file: (path) => open2(path, "wx", 384),
|
|
3160
3607
|
rename,
|
|
@@ -3163,7 +3610,7 @@ var DEFAULT_PORT = {
|
|
|
3163
3610
|
unique_ref: () => `${process.pid}.${crypto.randomUUID()}`
|
|
3164
3611
|
};
|
|
3165
3612
|
async function durableAtomicReplace(target, data, port = DEFAULT_PORT) {
|
|
3166
|
-
const parent =
|
|
3613
|
+
const parent = dirname3(target);
|
|
3167
3614
|
await port.mkdir(parent, { recursive: true, mode: 448 });
|
|
3168
3615
|
const parentStats = await port.lstat(parent);
|
|
3169
3616
|
const expectedUid = typeof process.geteuid === "function" ? process.geteuid() : parentStats.uid;
|
|
@@ -3233,8 +3680,8 @@ function errorCode(error) {
|
|
|
3233
3680
|
// host/relay/src/host-usage-facts-store.ts
|
|
3234
3681
|
import { createHash as createHash6 } from "node:crypto";
|
|
3235
3682
|
import { constants as constants2 } from "node:fs";
|
|
3236
|
-
import { mkdir as
|
|
3237
|
-
import { dirname as
|
|
3683
|
+
import { mkdir as mkdir3, open as open3, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
3684
|
+
import { dirname as dirname4, join as join3 } from "node:path";
|
|
3238
3685
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
3239
3686
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
3240
3687
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -3483,7 +3930,7 @@ var HostUsageFactsStore = class {
|
|
|
3483
3930
|
}
|
|
3484
3931
|
async writeImmutableBatch(state, batch, bytes) {
|
|
3485
3932
|
const path = this.batchPath(state, batch.batch_ref);
|
|
3486
|
-
await preparePrivateDirectory(
|
|
3933
|
+
await preparePrivateDirectory(dirname4(path), this.platform, this.custody);
|
|
3487
3934
|
const existing = await readOptionalBytes(path, CEAL_HOST_USAGE_BATCH_MAX_BYTES, this.platform, this.custody);
|
|
3488
3935
|
if (existing !== null) {
|
|
3489
3936
|
if (!existing.equals(bytes)) throw new Error("Host usage facts batch reference conflicts with existing bytes.");
|
|
@@ -3501,7 +3948,7 @@ var HostUsageFactsStore = class {
|
|
|
3501
3948
|
await handle.sync();
|
|
3502
3949
|
await handle.close();
|
|
3503
3950
|
handle = void 0;
|
|
3504
|
-
await syncDirectory(
|
|
3951
|
+
await syncDirectory(dirname4(path), this.platform);
|
|
3505
3952
|
} catch (error) {
|
|
3506
3953
|
await handle?.close().catch(() => void 0);
|
|
3507
3954
|
if (errorCode2(error) === "EEXIST") {
|
|
@@ -3545,14 +3992,14 @@ var HostUsageFactsStore = class {
|
|
|
3545
3992
|
const gate = new Promise((resolve3) => {
|
|
3546
3993
|
release = resolve3;
|
|
3547
3994
|
});
|
|
3548
|
-
const
|
|
3549
|
-
SESSION_TRANSITION_TAILS.set(key,
|
|
3995
|
+
const tail2 = previous.then(() => gate);
|
|
3996
|
+
SESSION_TRANSITION_TAILS.set(key, tail2);
|
|
3550
3997
|
await previous;
|
|
3551
3998
|
try {
|
|
3552
3999
|
return await run();
|
|
3553
4000
|
} finally {
|
|
3554
4001
|
release?.();
|
|
3555
|
-
if (SESSION_TRANSITION_TAILS.get(key) ===
|
|
4002
|
+
if (SESSION_TRANSITION_TAILS.get(key) === tail2) SESSION_TRANSITION_TAILS.delete(key);
|
|
3556
4003
|
}
|
|
3557
4004
|
}
|
|
3558
4005
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
@@ -3755,7 +4202,7 @@ async function preparePrivateDirectory(path, platform, custody) {
|
|
|
3755
4202
|
await ensurePrivateDirectoryWithSecurefs(path, custody);
|
|
3756
4203
|
return;
|
|
3757
4204
|
}
|
|
3758
|
-
await
|
|
4205
|
+
await mkdir3(path, { recursive: true, mode: 448 });
|
|
3759
4206
|
if (!await isPrivateDirectory(path, platform)) throw new Error("Host usage facts directory is not owner private.");
|
|
3760
4207
|
}
|
|
3761
4208
|
async function syncExistingFile(path, platform) {
|
|
@@ -3765,7 +4212,7 @@ async function syncExistingFile(path, platform) {
|
|
|
3765
4212
|
} finally {
|
|
3766
4213
|
await handle.close();
|
|
3767
4214
|
}
|
|
3768
|
-
await syncDirectory(
|
|
4215
|
+
await syncDirectory(dirname4(path), platform);
|
|
3769
4216
|
}
|
|
3770
4217
|
async function syncDirectory(path, platform) {
|
|
3771
4218
|
if (platform === "win32") return;
|
|
@@ -3813,29 +4260,46 @@ var HostUsageTranscriptSourceError = class extends Error {
|
|
|
3813
4260
|
this.name = "HostUsageTranscriptSourceError";
|
|
3814
4261
|
}
|
|
3815
4262
|
};
|
|
3816
|
-
async function readHostUsageTranscriptSource(
|
|
4263
|
+
async function readHostUsageTranscriptSource(read2) {
|
|
3817
4264
|
try {
|
|
3818
|
-
return await
|
|
4265
|
+
return await read2();
|
|
3819
4266
|
} catch (error) {
|
|
3820
4267
|
throw new HostUsageTranscriptSourceError({ cause: error });
|
|
3821
4268
|
}
|
|
3822
4269
|
}
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
4270
|
+
var HostUsageRegistrationCapture = class {
|
|
4271
|
+
nextIndex = 0;
|
|
4272
|
+
producer;
|
|
4273
|
+
diagnosticSink;
|
|
4274
|
+
constructor(producer, diagnosticSink) {
|
|
4275
|
+
this.producer = producer;
|
|
4276
|
+
this.diagnosticSink = diagnosticSink;
|
|
4277
|
+
}
|
|
4278
|
+
async captureNext(registrations, capture) {
|
|
4279
|
+
let failed = false;
|
|
4280
|
+
let captured = false;
|
|
4281
|
+
const onFailure = () => {
|
|
3834
4282
|
failed = true;
|
|
4283
|
+
};
|
|
4284
|
+
for (let attempt = 0; attempt < registrations.length; attempt += 1) {
|
|
4285
|
+
const index = (this.nextIndex + attempt) % registrations.length;
|
|
4286
|
+
const registration = registrations[index];
|
|
4287
|
+
if (registration === void 0) continue;
|
|
4288
|
+
try {
|
|
4289
|
+
captured = await capture(registration, onFailure);
|
|
4290
|
+
if (captured) {
|
|
4291
|
+
this.nextIndex = (index + 1) % registrations.length;
|
|
4292
|
+
break;
|
|
4293
|
+
}
|
|
4294
|
+
} catch (error) {
|
|
4295
|
+
if (!(error instanceof HostUsageTranscriptSourceError)) throw error;
|
|
4296
|
+
onFailure();
|
|
4297
|
+
}
|
|
3835
4298
|
}
|
|
4299
|
+
if (failed) writeHostServiceDiagnostic(this.producer, "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
4300
|
+
return captured;
|
|
3836
4301
|
}
|
|
3837
|
-
|
|
3838
|
-
}
|
|
4302
|
+
};
|
|
3839
4303
|
async function openHostUsageTranscriptCursor(input) {
|
|
3840
4304
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants3.O_RDONLY));
|
|
3841
4305
|
let source;
|
|
@@ -3906,16 +4370,16 @@ function completeLinePrefix(bytes, baseOffset) {
|
|
|
3906
4370
|
|
|
3907
4371
|
// host/relay/src/host-registration-state.ts
|
|
3908
4372
|
import { constants as constants4 } from "node:fs";
|
|
3909
|
-
import { dirname as
|
|
4373
|
+
import { dirname as dirname5 } from "node:path";
|
|
3910
4374
|
|
|
3911
4375
|
// host/runtime-source-paths.ts
|
|
3912
4376
|
import { createHash as createHash7 } from "node:crypto";
|
|
3913
|
-
import { posix as
|
|
4377
|
+
import { posix as posix3, win32 as win324 } from "node:path";
|
|
3914
4378
|
|
|
3915
4379
|
// host/absolute-path.ts
|
|
3916
|
-
import { posix, win32 as
|
|
4380
|
+
import { posix as posix2, win32 as win323 } from "node:path";
|
|
3917
4381
|
function isAbsoluteNormalizedNonRootPath(value, flavor = process.platform, allowRoot = false) {
|
|
3918
|
-
const pathApi = flavor === "win32" || flavor === "windows" ?
|
|
4382
|
+
const pathApi = flavor === "win32" || flavor === "windows" ? win323 : posix2;
|
|
3919
4383
|
return typeof value === "string" && value.length <= 4096 && !value.includes("\0") && pathApi.isAbsolute(value) && pathApi.normalize(value) === value && (allowRoot || pathApi.parse(value).root !== value);
|
|
3920
4384
|
}
|
|
3921
4385
|
|
|
@@ -3936,7 +4400,7 @@ function macosHostRelayIpcDirectory(uid = process.geteuid?.() ?? -1) {
|
|
|
3936
4400
|
function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platform, uid = process.geteuid?.() ?? -1) {
|
|
3937
4401
|
const sourceId = hostSourceUuid(sourceRef);
|
|
3938
4402
|
if (!isAbsoluteNormalizedNonRootPath(stateRoot, platform) || sourceId === null) throw new TypeError("Host runtime source identity is invalid.");
|
|
3939
|
-
const path = platform === "win32" ?
|
|
4403
|
+
const path = platform === "win32" ? win324 : posix3;
|
|
3940
4404
|
const sourcesRoot = path.join(stateRoot, "sources");
|
|
3941
4405
|
const sourceRoot = path.join(sourcesRoot, sourceId);
|
|
3942
4406
|
const runtimeRoot = path.join(stateRoot, "run");
|
|
@@ -3947,7 +4411,7 @@ function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platfor
|
|
|
3947
4411
|
function projectRelayEndpoint(stateRoot, sourceRef, rooted, platform, uid) {
|
|
3948
4412
|
if (platform !== "win32" && (platform !== "darwin" || Buffer.byteLength(rooted, "utf8") <= PORTABLE_UNIX_SOCKET_PATH_MAX_BYTES)) return rooted;
|
|
3949
4413
|
const digest2 = createHash7("sha256").update(`${stateRoot}\0${sourceRef}`).digest("hex");
|
|
3950
|
-
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` :
|
|
4414
|
+
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` : posix3.join(macosHostRelayIpcDirectory(uid), `${digest2}.sock`);
|
|
3951
4415
|
}
|
|
3952
4416
|
function assertHostProducerSourcePaths(stateRoot, config, producer, platform = process.platform) {
|
|
3953
4417
|
const paths = hostRuntimeSourcePaths(stateRoot, config.host_source_ref, platform);
|
|
@@ -3975,7 +4439,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
3975
4439
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
3976
4440
|
let raw;
|
|
3977
4441
|
try {
|
|
3978
|
-
await assertPrivateRegistrationDirectory(
|
|
4442
|
+
await assertPrivateRegistrationDirectory(dirname5(path), platform, custody);
|
|
3979
4443
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
3980
4444
|
} catch (error) {
|
|
3981
4445
|
throw registrationReadError(error);
|
|
@@ -4080,192 +4544,6 @@ function waitForAbort(signal, milliseconds) {
|
|
|
4080
4544
|
});
|
|
4081
4545
|
}
|
|
4082
4546
|
|
|
4083
|
-
// host/service-log.ts
|
|
4084
|
-
import { copyFile, mkdir as mkdir3, stat, truncate, appendFile } from "node:fs/promises";
|
|
4085
|
-
import { dirname as dirname5, isAbsolute as isAbsolute2, posix as posix3, win32 as win324 } from "node:path";
|
|
4086
|
-
|
|
4087
|
-
// host/service-log-delivery.ts
|
|
4088
|
-
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
4089
|
-
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
4090
|
-
setImmediate(flush);
|
|
4091
|
-
}, onDeliveryGap = () => void 0) {
|
|
4092
|
-
const pending = [];
|
|
4093
|
-
const highWaterMark = stream.writableHighWaterMark;
|
|
4094
|
-
const byteBudget = highWaterMark + highWaterMark;
|
|
4095
|
-
let pendingBytes = 0;
|
|
4096
|
-
let droppedLines = 0;
|
|
4097
|
-
let flushScheduled = false;
|
|
4098
|
-
let waitingForDrain = false;
|
|
4099
|
-
let closed = !stream.writable;
|
|
4100
|
-
function stop() {
|
|
4101
|
-
if (closed) return;
|
|
4102
|
-
closed = true;
|
|
4103
|
-
pending.length = 0;
|
|
4104
|
-
pendingBytes = 0;
|
|
4105
|
-
stream.off("drain", onDrain);
|
|
4106
|
-
stream.off("close", onTerminal);
|
|
4107
|
-
stream.off("finish", onTerminal);
|
|
4108
|
-
stream.off("error", onError);
|
|
4109
|
-
}
|
|
4110
|
-
function onTerminal() {
|
|
4111
|
-
stop();
|
|
4112
|
-
}
|
|
4113
|
-
function onError() {
|
|
4114
|
-
stop();
|
|
4115
|
-
}
|
|
4116
|
-
function onDrain() {
|
|
4117
|
-
waitingForDrain = false;
|
|
4118
|
-
scheduleFlush();
|
|
4119
|
-
}
|
|
4120
|
-
function scheduleFlush() {
|
|
4121
|
-
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
4122
|
-
flushScheduled = true;
|
|
4123
|
-
let scheduling = true;
|
|
4124
|
-
let invokedSynchronously = false;
|
|
4125
|
-
try {
|
|
4126
|
-
schedule(() => {
|
|
4127
|
-
if (scheduling) {
|
|
4128
|
-
invokedSynchronously = true;
|
|
4129
|
-
return;
|
|
4130
|
-
}
|
|
4131
|
-
flushScheduled = false;
|
|
4132
|
-
flush();
|
|
4133
|
-
});
|
|
4134
|
-
} catch {
|
|
4135
|
-
flushScheduled = false;
|
|
4136
|
-
stop();
|
|
4137
|
-
return;
|
|
4138
|
-
}
|
|
4139
|
-
scheduling = false;
|
|
4140
|
-
if (invokedSynchronously) {
|
|
4141
|
-
flushScheduled = false;
|
|
4142
|
-
stop();
|
|
4143
|
-
}
|
|
4144
|
-
}
|
|
4145
|
-
function flush() {
|
|
4146
|
-
if (closed) return;
|
|
4147
|
-
if (!stream.writable) {
|
|
4148
|
-
stop();
|
|
4149
|
-
return;
|
|
4150
|
-
}
|
|
4151
|
-
while (pending.length > 0) {
|
|
4152
|
-
if (stream.writableNeedDrain) {
|
|
4153
|
-
if (!waitingForDrain) {
|
|
4154
|
-
waitingForDrain = true;
|
|
4155
|
-
stream.once("drain", onDrain);
|
|
4156
|
-
}
|
|
4157
|
-
return;
|
|
4158
|
-
}
|
|
4159
|
-
const next = pending.shift();
|
|
4160
|
-
if (next === void 0) return;
|
|
4161
|
-
pendingBytes -= next.bytes;
|
|
4162
|
-
let accepted;
|
|
4163
|
-
try {
|
|
4164
|
-
accepted = stream.write(next.line);
|
|
4165
|
-
} catch {
|
|
4166
|
-
stop();
|
|
4167
|
-
return;
|
|
4168
|
-
}
|
|
4169
|
-
if (!accepted) {
|
|
4170
|
-
waitingForDrain = true;
|
|
4171
|
-
stream.once("drain", onDrain);
|
|
4172
|
-
return;
|
|
4173
|
-
}
|
|
4174
|
-
}
|
|
4175
|
-
if (droppedLines > 0) {
|
|
4176
|
-
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
4177
|
-
`;
|
|
4178
|
-
droppedLines = 0;
|
|
4179
|
-
try {
|
|
4180
|
-
onDeliveryGap(line);
|
|
4181
|
-
} catch {
|
|
4182
|
-
}
|
|
4183
|
-
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
4184
|
-
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
4185
|
-
flush();
|
|
4186
|
-
}
|
|
4187
|
-
}
|
|
4188
|
-
stream.on("close", onTerminal);
|
|
4189
|
-
stream.on("finish", onTerminal);
|
|
4190
|
-
stream.on("error", onError);
|
|
4191
|
-
return (line) => {
|
|
4192
|
-
if (closed) return;
|
|
4193
|
-
const bytes = Buffer.byteLength(line, "utf8");
|
|
4194
|
-
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
4195
|
-
droppedLines += 1;
|
|
4196
|
-
scheduleFlush();
|
|
4197
|
-
return;
|
|
4198
|
-
}
|
|
4199
|
-
pending.push({ line, bytes });
|
|
4200
|
-
pendingBytes += bytes;
|
|
4201
|
-
scheduleFlush();
|
|
4202
|
-
};
|
|
4203
|
-
}
|
|
4204
|
-
|
|
4205
|
-
// host/invocation-authentication-client-command.ts
|
|
4206
|
-
var DOCTOR_FLAGS = Object.freeze({
|
|
4207
|
-
"--expected-sha256": "expected_sha256",
|
|
4208
|
-
"--expected-source-commit": "expected_source_commit",
|
|
4209
|
-
"--expected-instance-ref": "expected_instance_ref"
|
|
4210
|
-
});
|
|
4211
|
-
|
|
4212
|
-
// host/service-log.ts
|
|
4213
|
-
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
4214
|
-
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
4215
|
-
void persistHostServiceLogLine(line);
|
|
4216
|
-
});
|
|
4217
|
-
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
4218
|
-
const details = diagnosticDetails(event, failure_kind, cause);
|
|
4219
|
-
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
4220
|
-
`;
|
|
4221
|
-
try {
|
|
4222
|
-
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
4223
|
-
} catch {
|
|
4224
|
-
}
|
|
4225
|
-
}
|
|
4226
|
-
function diagnosticDetails(event, failureKind, cause) {
|
|
4227
|
-
if (event === "watcher_scan_failed") return {
|
|
4228
|
-
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
4229
|
-
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
4230
|
-
};
|
|
4231
|
-
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
4232
|
-
}
|
|
4233
|
-
function validDiagnosticCause(cause, event) {
|
|
4234
|
-
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
4235
|
-
}
|
|
4236
|
-
function defaultHostServiceDiagnosticSink(line) {
|
|
4237
|
-
writeHostServiceLogLine(line);
|
|
4238
|
-
}
|
|
4239
|
-
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
4240
|
-
function writeHostServiceLogLine(line, environment = process.env) {
|
|
4241
|
-
void persistHostServiceLogLine(line, environment);
|
|
4242
|
-
defaultHostServiceLogDelivery(line);
|
|
4243
|
-
}
|
|
4244
|
-
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
4245
|
-
if (process.platform !== "win32") return;
|
|
4246
|
-
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
4247
|
-
if (path === void 0 || !win324.isAbsolute(path) || win324.normalize(path) !== path) return;
|
|
4248
|
-
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
4249
|
-
}
|
|
4250
|
-
async function appendHostServiceLogLine(path, line) {
|
|
4251
|
-
if (!isAbsolute2(path)) return;
|
|
4252
|
-
await ensureHostServiceLogDirectory(path);
|
|
4253
|
-
await appendFile(path, line);
|
|
4254
|
-
}
|
|
4255
|
-
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
4256
|
-
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
4257
|
-
function ensureHostServiceLogDirectory(path) {
|
|
4258
|
-
const directory = dirname5(path);
|
|
4259
|
-
const existing = hostServiceLogDirectories.get(directory);
|
|
4260
|
-
if (existing !== void 0) return existing;
|
|
4261
|
-
const pending = mkdir3(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
4262
|
-
hostServiceLogDirectories.delete(directory);
|
|
4263
|
-
throw error;
|
|
4264
|
-
});
|
|
4265
|
-
hostServiceLogDirectories.set(directory, pending);
|
|
4266
|
-
return pending;
|
|
4267
|
-
}
|
|
4268
|
-
|
|
4269
4547
|
// host/relay/src/host-usage-facts-uploader.ts
|
|
4270
4548
|
var HostUsageFactsUploader = class {
|
|
4271
4549
|
options;
|
|
@@ -4284,7 +4562,7 @@ var HostUsageFactsUploader = class {
|
|
|
4284
4562
|
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);
|
|
4285
4563
|
const timeout = AbortSignal.timeout(this.options.timeout_ms ?? 5e3);
|
|
4286
4564
|
const requestSignal = signal === void 0 ? timeout : AbortSignal.any([signal, timeout]);
|
|
4287
|
-
const response2 = await
|
|
4565
|
+
const response2 = await this.options.fetch(`${registration.gateway_request_origin}${CEAL_HOST_USAGE_INGRESS_PATH}`, {
|
|
4288
4566
|
method: "POST",
|
|
4289
4567
|
headers: { authorization: `Bearer ${registration.host_access_token}`, "content-type": "application/json" },
|
|
4290
4568
|
body: JSON.stringify(candidate.batch),
|
|
@@ -4541,6 +4819,13 @@ var CodexOutboxStore = class {
|
|
|
4541
4819
|
await removeOwnerState(this.registrationPath(registration.host_source_ref, registration.host_session_ref), "registration");
|
|
4542
4820
|
await removeOwnerState(this.cursorPath(registration.host_source_ref, registration.host_session_ref), "cursor");
|
|
4543
4821
|
}
|
|
4822
|
+
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
4823
|
+
const path = this.registrationPath(hostSourceRef, hostSessionRef);
|
|
4824
|
+
await this.prepare();
|
|
4825
|
+
const registration = await readOptionalJson2(path, validateRegistration);
|
|
4826
|
+
if (registration !== null && (registration.host_source_ref !== hostSourceRef || registration.host_session_ref !== hostSessionRef)) throw storageError("Codex transcript registration identity does not match its session.");
|
|
4827
|
+
return registration;
|
|
4828
|
+
}
|
|
4544
4829
|
async listTranscriptRegistrations() {
|
|
4545
4830
|
await this.prepare();
|
|
4546
4831
|
const registrations = [];
|
|
@@ -4567,16 +4852,16 @@ var CodexOutboxStore = class {
|
|
|
4567
4852
|
}
|
|
4568
4853
|
async findByAlias(sourceRef, sessionRef, alias) {
|
|
4569
4854
|
if (!SAFE_REF3.test(sourceRef) || !SAFE_REF3.test(sessionRef) || !SAFE_REF3.test(alias)) return null;
|
|
4570
|
-
const
|
|
4571
|
-
const envelope = findEnvelopeByAlias(
|
|
4855
|
+
const read2 = await this.list();
|
|
4856
|
+
const envelope = findEnvelopeByAlias(read2.entries, sourceRef, sessionRef, alias);
|
|
4572
4857
|
if (envelope !== null) return envelopeMatch(envelope);
|
|
4573
4858
|
await this.prepare();
|
|
4574
4859
|
return null;
|
|
4575
4860
|
}
|
|
4576
4861
|
async hasPriorTurn(sourceRef, sessionRef) {
|
|
4577
4862
|
if (!SAFE_REF3.test(sourceRef) || !SAFE_REF3.test(sessionRef)) return false;
|
|
4578
|
-
const
|
|
4579
|
-
if (
|
|
4863
|
+
const read2 = await this.list();
|
|
4864
|
+
if (read2.entries.some((entry) => entry.identity.host_source_ref === sourceRef && entry.identity.host_session_ref === sessionRef)) return true;
|
|
4580
4865
|
return false;
|
|
4581
4866
|
}
|
|
4582
4867
|
entryPath(submissionRef) {
|
|
@@ -4632,7 +4917,7 @@ async function writeAtomicJson(path, value) {
|
|
|
4632
4917
|
if (text === void 0) throw storageError("Codex owner state cannot be serialized.");
|
|
4633
4918
|
const temp = `${path}.${process.pid}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
4634
4919
|
try {
|
|
4635
|
-
const handle = await open4(temp, "wx");
|
|
4920
|
+
const handle = await open4(temp, "wx", 384);
|
|
4636
4921
|
try {
|
|
4637
4922
|
await handle.writeFile(text, "utf8");
|
|
4638
4923
|
await handle.sync();
|
|
@@ -4674,13 +4959,20 @@ async function readOptionalJson2(path, validate) {
|
|
|
4674
4959
|
}
|
|
4675
4960
|
async function ensureOwnerDirectory(path) {
|
|
4676
4961
|
try {
|
|
4677
|
-
|
|
4962
|
+
try {
|
|
4963
|
+
const stats2 = await stat2(path);
|
|
4964
|
+
if (!stats2.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
4965
|
+
return;
|
|
4966
|
+
} catch (error) {
|
|
4967
|
+
if (!isNotFound(error)) throw error;
|
|
4968
|
+
}
|
|
4969
|
+
await mkdir4(path, { recursive: true, mode: 448 });
|
|
4970
|
+
const stats = await stat2(path);
|
|
4971
|
+
if (!stats.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
4678
4972
|
} catch (error) {
|
|
4679
|
-
if (
|
|
4680
|
-
|
|
4973
|
+
if (error instanceof CodexHostAdapterError) throw error;
|
|
4974
|
+
throw storageError("Codex owner state directory is unavailable.");
|
|
4681
4975
|
}
|
|
4682
|
-
const stats = await stat2(path);
|
|
4683
|
-
if (!stats.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
4684
4976
|
}
|
|
4685
4977
|
async function readOwnerStateFile(path) {
|
|
4686
4978
|
let handle;
|
|
@@ -5090,9 +5382,9 @@ async function firstCompleteLine(handle, size) {
|
|
|
5090
5382
|
let total = 0;
|
|
5091
5383
|
while (position < size) {
|
|
5092
5384
|
const buffer = Buffer.alloc(Math.min(BASELINE_READ_CHUNK_BYTES, size - position));
|
|
5093
|
-
const
|
|
5094
|
-
if (
|
|
5095
|
-
const chunk = buffer.subarray(0,
|
|
5385
|
+
const read2 = await handle.read(buffer, 0, buffer.length, position);
|
|
5386
|
+
if (read2.bytesRead === 0) break;
|
|
5387
|
+
const chunk = buffer.subarray(0, read2.bytesRead);
|
|
5096
5388
|
const newline = chunk.indexOf(10);
|
|
5097
5389
|
if (newline >= 0) {
|
|
5098
5390
|
chunks.push(chunk.subarray(0, newline));
|
|
@@ -5109,8 +5401,8 @@ async function lastCompleteRecordOffset(handle, size) {
|
|
|
5109
5401
|
while (end > 0) {
|
|
5110
5402
|
const start = Math.max(0, end - BASELINE_READ_CHUNK_BYTES);
|
|
5111
5403
|
const buffer = Buffer.alloc(end - start);
|
|
5112
|
-
const
|
|
5113
|
-
const newline = buffer.subarray(0,
|
|
5404
|
+
const read2 = await handle.read(buffer, 0, buffer.length, start);
|
|
5405
|
+
const newline = buffer.subarray(0, read2.bytesRead).lastIndexOf(10);
|
|
5114
5406
|
if (newline >= 0) return start + newline + 1;
|
|
5115
5407
|
end = start;
|
|
5116
5408
|
}
|
|
@@ -5153,8 +5445,8 @@ async function* completeLinesBackward(handle, end) {
|
|
|
5153
5445
|
while (position > 0) {
|
|
5154
5446
|
const start = Math.max(0, position - BASELINE_READ_CHUNK_BYTES);
|
|
5155
5447
|
const buffer = Buffer.alloc(position - start);
|
|
5156
|
-
const
|
|
5157
|
-
if (
|
|
5448
|
+
const read2 = await handle.read(buffer, 0, buffer.length, start);
|
|
5449
|
+
if (read2.bytesRead !== buffer.length) throw new CodexHostAdapterError("storage", "Codex transcript changed size during baseline capture.");
|
|
5158
5450
|
let lineEnd = buffer.length;
|
|
5159
5451
|
for (let newline = buffer.lastIndexOf(10, lineEnd - 1); newline >= 0; newline = lineEnd > 0 ? buffer.lastIndexOf(10, lineEnd - 1) : -1) {
|
|
5160
5452
|
yield { start: start + newline + 1, bytes: Buffer.concat([buffer.subarray(newline + 1, lineEnd), ...carry]) };
|
|
@@ -5221,12 +5513,12 @@ async function registerSession(event, options, store, now, retentionMs) {
|
|
|
5221
5513
|
expires_at: expiresAt
|
|
5222
5514
|
};
|
|
5223
5515
|
const currentTurn = await selectCurrentTurn(event, options, store, hostSessionRef);
|
|
5224
|
-
const existing =
|
|
5225
|
-
if (existing ===
|
|
5516
|
+
const existing = await store.readTranscriptRegistration(registration.host_source_ref, registration.host_session_ref);
|
|
5517
|
+
if (existing === null) {
|
|
5226
5518
|
await store.writeTranscriptCursor(await captureCodexTranscriptBaseline(registration, now));
|
|
5227
5519
|
}
|
|
5228
5520
|
await store.registerTranscript(registration);
|
|
5229
|
-
if (existing !==
|
|
5521
|
+
if (existing !== null && currentTurn !== void 0 && (await store.readTranscriptCursor(registration))?.status === "quarantined") {
|
|
5230
5522
|
await store.writeTranscriptCursor(await captureCodexTranscriptBaseline(registration, now));
|
|
5231
5523
|
}
|
|
5232
5524
|
if (event.event === "SessionStart") {
|
|
@@ -5495,7 +5787,7 @@ function parseCanonicalJson(text, error) {
|
|
|
5495
5787
|
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) }])}`);
|
|
5496
5788
|
return value;
|
|
5497
5789
|
} catch (parseError) {
|
|
5498
|
-
throw error("invalid_config",
|
|
5790
|
+
throw error("invalid_config", `parse_error=${renderOperatorDiagnostic(parseError)}; ${refusalFact("config_bytes", Buffer.byteLength(text, "utf8"), "canonical JSON")}`);
|
|
5499
5791
|
}
|
|
5500
5792
|
}
|
|
5501
5793
|
function firstDifferenceIndex(left, right) {
|
|
@@ -5594,9 +5886,9 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5594
5886
|
const { size, device, inode } = await ownedCodexTranscriptFile(handle);
|
|
5595
5887
|
const preflight = await this.preflight(registration, handle, size, device, inode);
|
|
5596
5888
|
if (preflight.cursor === null) return preflight.result;
|
|
5889
|
+
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 });
|
|
5597
5890
|
const complete = await this.readChunk(handle, preflight.cursor.offset, size);
|
|
5598
5891
|
if (complete === "empty" || complete === "partial") {
|
|
5599
|
-
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 });
|
|
5600
5892
|
return { records: 0, enqueued: 0, quarantined: false };
|
|
5601
5893
|
}
|
|
5602
5894
|
return await this.consumeCompleteChunk(registration, handle, preflight.cursor, complete, device, inode);
|
|
@@ -5613,17 +5905,17 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5613
5905
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
5614
5906
|
let cursor = existing ?? codexTranscriptInitialCursor(registration, device, inode, this.now);
|
|
5615
5907
|
if (cursor.status === "quarantined") {
|
|
5616
|
-
return { cursor: null,
|
|
5908
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
5617
5909
|
}
|
|
5618
5910
|
const reason = this.cursorIdentityReason(cursor, registration.transcript_path, device, inode) ?? await this.cursorBoundsReason(handle, cursor, size);
|
|
5619
5911
|
if (reason === null) {
|
|
5620
|
-
if (cursor.human_message_window !== void 0) return { cursor,
|
|
5912
|
+
if (cursor.human_message_window !== void 0) return { cursor, checkpointPending: existing === null, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
5621
5913
|
const humanWindow = await this.readHumanMessageProjection(handle, registration, cursor);
|
|
5622
|
-
return { cursor: { ...cursor, human_message_window: humanWindow },
|
|
5914
|
+
return { cursor: { ...cursor, human_message_window: humanWindow }, checkpointPending: true, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
5623
5915
|
}
|
|
5624
5916
|
await this.quarantine(registration, cursor, device, inode, reason);
|
|
5625
5917
|
this.diagnostic("watcher_scan_failed", "other", `cursor_${reason}`);
|
|
5626
|
-
return { cursor: null,
|
|
5918
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
5627
5919
|
}
|
|
5628
5920
|
async readHumanMessageProjection(handle, registration, cursor) {
|
|
5629
5921
|
return readCodexHumanMessageProjection(registration, cursor, (offset, size) => this.readChunk(handle, offset, size));
|
|
@@ -5936,20 +6228,16 @@ var CodexUsageFactsCapturer = class {
|
|
|
5936
6228
|
sources;
|
|
5937
6229
|
usage;
|
|
5938
6230
|
now;
|
|
5939
|
-
|
|
5940
|
-
nextRegistrationIndex = 0;
|
|
6231
|
+
registrations;
|
|
5941
6232
|
constructor(options) {
|
|
5942
6233
|
this.sources = new CodexOutboxStore(options.outbox_dir);
|
|
5943
6234
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
5944
6235
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
5945
|
-
this.
|
|
6236
|
+
this.registrations = new HostUsageRegistrationCapture("codex", options.diagnostic_sink);
|
|
5946
6237
|
}
|
|
5947
6238
|
async captureNext() {
|
|
5948
6239
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
5949
|
-
|
|
5950
|
-
this.nextRegistrationIndex = result.nextIndex;
|
|
5951
|
-
if (result.failed) writeHostServiceDiagnostic("codex", "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
5952
|
-
return result.captured;
|
|
6240
|
+
return await this.registrations.captureNext(registrations, (registration) => this.captureRegistration(registration));
|
|
5953
6241
|
}
|
|
5954
6242
|
async captureRegistration(registration) {
|
|
5955
6243
|
const prepared = await openHostUsageTranscriptCursor({
|
|
@@ -6117,12 +6405,11 @@ function normalizedCounts(selected) {
|
|
|
6117
6405
|
function nullCounts() {
|
|
6118
6406
|
return { input: null, output: null, total: null, cached_input: null, cache_write_input: null, reasoning_output: null };
|
|
6119
6407
|
}
|
|
6120
|
-
var USAGE_COUNT_FIELDS = ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"];
|
|
6121
6408
|
function isRegression(current, previous) {
|
|
6122
|
-
return
|
|
6409
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.some((key) => current[key] < previous[key]);
|
|
6123
6410
|
}
|
|
6124
6411
|
function sameCounts(left, right) {
|
|
6125
|
-
return
|
|
6412
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.every((key) => left[key] === right[key]);
|
|
6126
6413
|
}
|
|
6127
6414
|
function buildCoverageGaps(sourceFileRef, startOffset, endOffset, counts) {
|
|
6128
6415
|
return [...counts].map(([reason, omittedCount]) => coverageGap(reason, sourceFileRef, startOffset, endOffset, omittedCount));
|
|
@@ -6171,9 +6458,9 @@ var CODEX_PRODUCER_DESCRIPTOR = {
|
|
|
6171
6458
|
config: (shared, extras) => ({ ...shared, codex_sessions_root: hostProducerExtraPath(extras, CODEX_SESSIONS_ROOT) }),
|
|
6172
6459
|
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir }),
|
|
6173
6460
|
drain: drainCodexProducerOnce,
|
|
6174
|
-
background: (config, signal) => {
|
|
6461
|
+
background: (config, signal, dependencies) => {
|
|
6175
6462
|
const capturer = new CodexUsageFactsCapturer({ outbox_dir: config.outbox_dir });
|
|
6176
|
-
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);
|
|
6463
|
+
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);
|
|
6177
6464
|
}
|
|
6178
6465
|
};
|
|
6179
6466
|
|