@corca-org/ceal-host-win32-x64 1.0.22 → 1.0.23
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 +288 -250
- package/libexec/ceal-host/claude-invocation-authentication.mjs +336 -266
- package/libexec/ceal-host/claude-producer.mjs +89 -51
- package/libexec/ceal-host/codex-hook.mjs +270 -250
- package/libexec/ceal-host/codex-invocation-authentication.mjs +320 -267
- package/libexec/ceal-host/codex-producer.mjs +72 -52
- package/libexec/ceal-host/control.mjs +134 -80
- package/libexec/ceal-host/relay.mjs +60 -46
- 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);
|
|
@@ -182,8 +191,11 @@ var client_wire_contract_default = {
|
|
|
182
191
|
"ok",
|
|
183
192
|
"code",
|
|
184
193
|
"reason",
|
|
185
|
-
"gateway_status"
|
|
194
|
+
"gateway_status",
|
|
195
|
+
"retry_after_ms"
|
|
186
196
|
],
|
|
197
|
+
refusal_required_fields: ["schema_version", "ok", "code", "reason"],
|
|
198
|
+
refusal_optional_fields: ["gateway_status", "retry_after_ms"],
|
|
187
199
|
client_nonce: {
|
|
188
200
|
character_class_source: "A-Za-z0-9_-",
|
|
189
201
|
encoded_characters: 43
|
|
@@ -402,11 +414,6 @@ var CEAL_OPERATION_WITHHELD_NEXT_ACTIONS = Object.freeze({
|
|
|
402
414
|
personal_authorization_required: "connect_personal_account"
|
|
403
415
|
});
|
|
404
416
|
|
|
405
|
-
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
406
|
-
function vocabulary(words) {
|
|
407
|
-
return Object.freeze(words);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
417
|
// packages/ceal-client-protocol/src/gateway-response-types.ts
|
|
411
418
|
var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavailable", "unknown"]);
|
|
412
419
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
@@ -805,7 +812,7 @@ var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask a
|
|
|
805
812
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
806
813
|
var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Relay to the same release as the Gateway, then retry.";
|
|
807
814
|
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
|
|
815
|
+
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
816
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
810
817
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
811
818
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
@@ -857,14 +864,12 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
857
864
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
858
865
|
internal_error: guidance("The Gateway failed without exposing internal state.", "answer_with_gap", 500),
|
|
859
866
|
// Owned by the Gateway canonical adapter (`gateway/core/src/gateway-canonical-operation-http-adapter.ts`):
|
|
860
|
-
// the client variant
|
|
867
|
+
// the static client variant was retired when the client started reading this table.
|
|
861
868
|
request_body_too_large: guidance("The Gateway request body exceeds its bounded limit.", "reduce_request_size", 413),
|
|
862
869
|
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
|
-
// forbids the safe read retry the sentence exists to allow.
|
|
867
|
-
unknown_outcome: guidance("The transport outcome is unknown: a read may be retried; for a write, check write_receipt.get before repeating.", "answer_with_gap", 500),
|
|
870
|
+
// The safe move varies by request. Keep the sentence conditional on the
|
|
871
|
+
// same `retryable` and `next_action` facts the response exposes.
|
|
872
|
+
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
868
873
|
// Restored verbatim from the retired `localFailureText`
|
|
869
874
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
870
875
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -945,8 +950,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
945
950
|
// Host mint classifications. The CLI emits `invocation_authentication_unavailable` with the classification
|
|
946
951
|
// in its detail fact; rows without their own sentence share that code's moved sentence, while `next_action`
|
|
947
952
|
// is moved from `canonicalHostAuthenticationNextActions` (generated from `CEAL_HOST_AUTHENTICATION_POLICY`)
|
|
948
|
-
// and `retryable` from `hostAuthenticationFailureForCause` (
|
|
949
|
-
// sentences carry the
|
|
953
|
+
// and `retryable` from `hostAuthenticationFailureForCause` (the table's explicit retry verdict). Cause-specific
|
|
954
|
+
// sentences carry only remedies proved by the Host or Relay cause; generic Gateway refusals do not prove a release mismatch.
|
|
950
955
|
// Statuses are the
|
|
951
956
|
// Gateway-owned mapping decided with the operator 2026-10-13. This covers every wire cause the maps at
|
|
952
957
|
// `host/invocation-authentication-command.ts:217-242` emit, through their policy classifications.
|
|
@@ -956,21 +961,23 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
956
961
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
957
962
|
// changes mode; standalone remains the separate Client authority path.
|
|
958
963
|
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "answer_with_gap", 401),
|
|
959
|
-
|
|
960
|
-
|
|
964
|
+
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),
|
|
965
|
+
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),
|
|
966
|
+
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
967
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
962
968
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
963
969
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
964
970
|
host_mint_gateway_rate_limited: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 429),
|
|
965
|
-
host_mint_gateway_refused: guidance(
|
|
971
|
+
host_mint_gateway_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
966
972
|
host_mint_gateway_response_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
973
|
+
host_contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 502),
|
|
967
974
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
968
975
|
// producer-frame fault names the administrator repair step.
|
|
969
976
|
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
977
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
971
978
|
// sandboxed Relay socket names the run-alone retry.
|
|
972
979
|
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(
|
|
980
|
+
host_relay_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 503),
|
|
974
981
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
975
982
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
976
983
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -1008,7 +1015,7 @@ var UNKNOWN_OUTCOMES = vocabulary(["reconcile", "operator_action", "excluded"]);
|
|
|
1008
1015
|
var RECOVERY_OWNERS = vocabulary(["gateway", "connector", "operator"]);
|
|
1009
1016
|
var CEAL_OPERATION_ADMISSION_STATES = vocabulary(["proposed", "refused", "admitted"]);
|
|
1010
1017
|
var CEAL_OPERATION_EXECUTION_STATES = vocabulary(["not_started", "started", "completed"]);
|
|
1011
|
-
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1018
|
+
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_applicable", "not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1012
1019
|
var CEAL_OPERATION_EFFECT_STATES = vocabulary(["none", "applied", "failed", "unknown", "compensated"]);
|
|
1013
1020
|
var CEAL_OPERATION_OBSERVATION_STATES = vocabulary(["not_started", "not_required", "pending", "observed", "unavailable"]);
|
|
1014
1021
|
var CEAL_OPERATION_RECOVERY_KINDS = vocabulary(["none", "reconcile", "compensate", "operator_action"]);
|
|
@@ -1179,6 +1186,7 @@ var CEAL_OPERATION_ACCESS_CLASSES = vocabulary(["read", "write"]);
|
|
|
1179
1186
|
// packages/ceal-client-protocol/src/domain-vocabulary.ts
|
|
1180
1187
|
var CEAL_CONNECTOR_STATUSES = vocabulary(["active", "disabled", "disconnected"]);
|
|
1181
1188
|
var CEAL_CONNECTOR_CUSTODIES = vocabulary(["organization", "personal"]);
|
|
1189
|
+
var CEAL_PROVIDER_BOUNDARY_FIELDS = vocabulary(["provider_boundary_ref", "provider_boundary_kind", "provider_boundary_label", "provider_native_id", "provider_boundary_evidence"]);
|
|
1182
1190
|
var CEAL_PERSONAL_ACCESS_CEILINGS = vocabulary(["disabled", "read", "read_write"]);
|
|
1183
1191
|
var CEAL_TARGET_REF_PATTERN = "^[^\\p{Cc}]+$";
|
|
1184
1192
|
var TARGET_REF = new RegExp(CEAL_TARGET_REF_PATTERN, "u");
|
|
@@ -1224,7 +1232,7 @@ var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
|
1224
1232
|
var CEAL_OPERATION_AUTHORITY_POLICY_KEYS = Object.freeze(["access_group", "instance_binding", "target", "admission_recheck"]);
|
|
1225
1233
|
var MAX_OPERATION_INPUT_RESOLVER_BINDINGS = 96;
|
|
1226
1234
|
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"]);
|
|
1235
|
+
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary", "standard_names"]);
|
|
1228
1236
|
|
|
1229
1237
|
// packages/ceal-client-protocol/src/operation-catalog.ts
|
|
1230
1238
|
var CEAL_OPERATION_CATALOG_SCHEMA_VERSION = "ceal.catalog.v3";
|
|
@@ -1320,6 +1328,7 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
1320
1328
|
gateway_access_group_connector_activity_scope_audit: (root) => join(root, "profile-connector-activity-scope-audit.jsonl"),
|
|
1321
1329
|
gateway_access_group_connector_calendar_scope_audit: (root) => join(root, "profile-connector-calendar-scope-audit.jsonl"),
|
|
1322
1330
|
gateway_access_group_connector_readiness_audit: (root) => join(root, "profile-connector-readiness.audit.jsonl"),
|
|
1331
|
+
gateway_deployment_events: (root) => join(root, "gateway-deployments.jsonl"),
|
|
1323
1332
|
gateway_organization_audit_ledger: (root) => join(root, "organization-ledger.jsonl"),
|
|
1324
1333
|
gateway_personal_client_audit: (root) => join(root, "audit.jsonl"),
|
|
1325
1334
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
@@ -1346,6 +1355,11 @@ var CEAL_HOST_INSTALLATION_REF_PATTERN = new RegExp(`^host-installation:${CEAL_L
|
|
|
1346
1355
|
var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUID_PATTERN}$`, "u");
|
|
1347
1356
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
1348
1357
|
|
|
1358
|
+
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1359
|
+
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
1360
|
+
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
1361
|
+
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1362
|
+
|
|
1349
1363
|
// packages/ceal-client-protocol/src/operation-result-completeness.ts
|
|
1350
1364
|
var CEAL_READ_VALUE_CONTINUATION_KEYS = vocabulary(["continuation", "continuation_ref", "next_cursor"]);
|
|
1351
1365
|
|
|
@@ -1430,6 +1444,7 @@ var PROVIDER_LINK_CONFORMANCE_TABLE = Object.freeze([
|
|
|
1430
1444
|
{ 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
1445
|
{ 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
1446
|
{ 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" },
|
|
1447
|
+
{ 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
1448
|
{ 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
1449
|
{ 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
1450
|
{ 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" },
|
|
@@ -1599,6 +1614,7 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
1599
1614
|
created_at: { required: false, timestamp: true },
|
|
1600
1615
|
created_at_local: { required: false, timestamp: true },
|
|
1601
1616
|
modified_at: { required: false, timestamp: true },
|
|
1617
|
+
observed_at: { required: false, timestamp: true },
|
|
1602
1618
|
modified_at_local: { required: false, timestamp: true },
|
|
1603
1619
|
viewed_by_me_at: { required: false, timestamp: true },
|
|
1604
1620
|
modified_by_me_at: { required: false, timestamp: true },
|
|
@@ -1626,9 +1642,6 @@ var RESOURCE_ROW_REQUIRED_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(
|
|
|
1626
1642
|
var RESOURCE_ROW_KEYS = new Set(Object.keys(RESOURCE_ROW_KEY_RULES));
|
|
1627
1643
|
var RESOURCE_ROW_TIMESTAMP_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(([key, rule]) => rule.timestamp ? [key] : []);
|
|
1628
1644
|
|
|
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
1645
|
// packages/ceal-client-protocol/src/excluded-target-coverage.ts
|
|
1633
1646
|
var CEAL_EXCLUDED_TARGET_COVERAGE_MAX_ENTRIES = 64;
|
|
1634
1647
|
function cealExcludedTargetCoverageJsonSchema() {
|
|
@@ -1935,7 +1948,7 @@ function validateBatchContents(value) {
|
|
|
1935
1948
|
if (facts.length === 0 && gaps.length === 0 || facts.length > 0 && value.source_ranges.length === 0) invalid("Ceal Host usage coverage is invalid.");
|
|
1936
1949
|
const sourceFiles = new Set(value.source_ranges.map((range) => sourceRangeFileRef(range)));
|
|
1937
1950
|
for (const fact of facts) {
|
|
1938
|
-
|
|
1951
|
+
validateCealHostUsageFact(fact, value.host_session_ref);
|
|
1939
1952
|
if (!sourceFiles.has(fact.source_file_ref)) invalid("Ceal Host usage fact is outside its source ranges.");
|
|
1940
1953
|
}
|
|
1941
1954
|
for (const gap of gaps) {
|
|
@@ -1968,7 +1981,7 @@ function hostUsageSourceFileReference(producer, hostSourceRef, hostSessionRef, d
|
|
|
1968
1981
|
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
1982
|
return `host-source-file:${sha256(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef, device, inode }))}`;
|
|
1970
1983
|
}
|
|
1971
|
-
function
|
|
1984
|
+
function validateCealHostUsageFact(value, sessionRef) {
|
|
1972
1985
|
if (!isOperationRecord(value)) invalid("Ceal Host usage fact is invalid.");
|
|
1973
1986
|
requireFactByteLimit(value);
|
|
1974
1987
|
if (value.producer === "codex_transcript") validateCodexFact(value);
|
|
@@ -2032,7 +2045,7 @@ function validCorrectionSemantics(value) {
|
|
|
2032
2045
|
}
|
|
2033
2046
|
function validateCodexUsageCounts(value) {
|
|
2034
2047
|
if (!isOperationRecord(value)) invalid("Ceal Codex usage fields are invalid.");
|
|
2035
|
-
requireExactOperationKeys(value,
|
|
2048
|
+
requireExactOperationKeys(value, CEAL_CODEX_USAGE_COUNT_FIELDS);
|
|
2036
2049
|
for (const key of Object.keys(value)) if (!safeInteger(value[key])) invalid("Ceal Codex usage fields are invalid.");
|
|
2037
2050
|
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
2051
|
}
|
|
@@ -2300,6 +2313,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
2300
2313
|
"options_invalid",
|
|
2301
2314
|
"session_unavailable",
|
|
2302
2315
|
"context_unavailable",
|
|
2316
|
+
"activation_wait_exhausted",
|
|
2303
2317
|
"context_replaced",
|
|
2304
2318
|
"no_binding",
|
|
2305
2319
|
"context_expired",
|
|
@@ -2335,22 +2349,23 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2335
2349
|
// This reason cannot distinguish a Codex side conversation from a missing
|
|
2336
2350
|
// context in a regular session, so guidance must leave that choice to the caller.
|
|
2337
2351
|
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "answer_with_gap" }),
|
|
2338
|
-
|
|
2352
|
+
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
2353
|
+
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
2339
2354
|
// `no_binding` now means the producer has no real current Host session. The
|
|
2340
2355
|
// Host Relay never uses it for an uncreated Gateway Request; there is no
|
|
2341
2356
|
// useful retry until the consumer is running inside a Host session.
|
|
2342
2357
|
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: "
|
|
2358
|
+
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
2344
2359
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
2345
2360
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
2346
2361
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
2347
2362
|
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: "
|
|
2363
|
+
contract_mismatch: Object.freeze({ classification: "host_contract_mismatch", next_action: "upgrade_ceal_client" }),
|
|
2364
|
+
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "answer_with_gap" }),
|
|
2350
2365
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
2351
2366
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
2352
2367
|
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: "
|
|
2368
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "answer_with_gap" }),
|
|
2354
2369
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
2355
2370
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
2356
2371
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -2398,7 +2413,7 @@ function isCealHostServiceDiagnosticCause(value, event) {
|
|
|
2398
2413
|
// packages/ceal-client-protocol/src/client-result-materialization.ts
|
|
2399
2414
|
var CEAL_UNREAD_REASONS = vocabulary(["blocked", "unavailable", "too_large", "unsupported", "download_failed", "permission_denied"]);
|
|
2400
2415
|
var REQUIRED_FIELDS2 = Object.freeze(["schema_version", "operation_id", "path", "sha256"]);
|
|
2401
|
-
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "
|
|
2416
|
+
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "local_result_root", "request_context_argv", "how_to_read"]);
|
|
2402
2417
|
|
|
2403
2418
|
// packages/ceal-client-protocol/src/discovery-manifest.ts
|
|
2404
2419
|
var DISCOVERY_MANIFEST_KEYS = CEAL_CLIENT_WIRE_CONTRACT.command_response.discovery_manifest_fields;
|
|
@@ -2822,7 +2837,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
2822
2837
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
2823
2838
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
2824
2839
|
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) => {
|
|
2840
|
+
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
2826
2841
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
2827
2842
|
if (exitCode === null) {
|
|
2828
2843
|
reject3(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -2873,6 +2888,192 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
2873
2888
|
return entry.isDirectory() && !entry.isSymbolicLink() && isSelfOwned(entry.uid, platform) && isPrivateFileMode(entry.mode, platform);
|
|
2874
2889
|
}
|
|
2875
2890
|
|
|
2891
|
+
// host/service-log.ts
|
|
2892
|
+
import { copyFile, mkdir, stat, truncate, appendFile } from "node:fs/promises";
|
|
2893
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, posix, win32 as win322 } from "node:path";
|
|
2894
|
+
|
|
2895
|
+
// host/service-log-delivery.ts
|
|
2896
|
+
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
2897
|
+
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
2898
|
+
setImmediate(flush);
|
|
2899
|
+
}, onDeliveryGap = () => void 0) {
|
|
2900
|
+
const pending = [];
|
|
2901
|
+
const highWaterMark = stream.writableHighWaterMark;
|
|
2902
|
+
const byteBudget = highWaterMark + highWaterMark;
|
|
2903
|
+
let pendingBytes = 0;
|
|
2904
|
+
let droppedLines = 0;
|
|
2905
|
+
let flushScheduled = false;
|
|
2906
|
+
let waitingForDrain = false;
|
|
2907
|
+
let closed = !stream.writable;
|
|
2908
|
+
function stop() {
|
|
2909
|
+
if (closed) return;
|
|
2910
|
+
closed = true;
|
|
2911
|
+
pending.length = 0;
|
|
2912
|
+
pendingBytes = 0;
|
|
2913
|
+
stream.off("drain", onDrain);
|
|
2914
|
+
stream.off("close", onTerminal);
|
|
2915
|
+
stream.off("finish", onTerminal);
|
|
2916
|
+
stream.off("error", onError);
|
|
2917
|
+
}
|
|
2918
|
+
function onTerminal() {
|
|
2919
|
+
stop();
|
|
2920
|
+
}
|
|
2921
|
+
function onError() {
|
|
2922
|
+
stop();
|
|
2923
|
+
}
|
|
2924
|
+
function onDrain() {
|
|
2925
|
+
waitingForDrain = false;
|
|
2926
|
+
scheduleFlush();
|
|
2927
|
+
}
|
|
2928
|
+
function scheduleFlush() {
|
|
2929
|
+
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
2930
|
+
flushScheduled = true;
|
|
2931
|
+
let scheduling = true;
|
|
2932
|
+
let invokedSynchronously = false;
|
|
2933
|
+
try {
|
|
2934
|
+
schedule(() => {
|
|
2935
|
+
if (scheduling) {
|
|
2936
|
+
invokedSynchronously = true;
|
|
2937
|
+
return;
|
|
2938
|
+
}
|
|
2939
|
+
flushScheduled = false;
|
|
2940
|
+
flush();
|
|
2941
|
+
});
|
|
2942
|
+
} catch {
|
|
2943
|
+
flushScheduled = false;
|
|
2944
|
+
stop();
|
|
2945
|
+
return;
|
|
2946
|
+
}
|
|
2947
|
+
scheduling = false;
|
|
2948
|
+
if (invokedSynchronously) {
|
|
2949
|
+
flushScheduled = false;
|
|
2950
|
+
stop();
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
function flush() {
|
|
2954
|
+
if (closed) return;
|
|
2955
|
+
if (!stream.writable) {
|
|
2956
|
+
stop();
|
|
2957
|
+
return;
|
|
2958
|
+
}
|
|
2959
|
+
while (pending.length > 0) {
|
|
2960
|
+
if (stream.writableNeedDrain) {
|
|
2961
|
+
if (!waitingForDrain) {
|
|
2962
|
+
waitingForDrain = true;
|
|
2963
|
+
stream.once("drain", onDrain);
|
|
2964
|
+
}
|
|
2965
|
+
return;
|
|
2966
|
+
}
|
|
2967
|
+
const next = pending.shift();
|
|
2968
|
+
if (next === void 0) return;
|
|
2969
|
+
pendingBytes -= next.bytes;
|
|
2970
|
+
let accepted;
|
|
2971
|
+
try {
|
|
2972
|
+
accepted = stream.write(next.line);
|
|
2973
|
+
} catch {
|
|
2974
|
+
stop();
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
if (!accepted) {
|
|
2978
|
+
waitingForDrain = true;
|
|
2979
|
+
stream.once("drain", onDrain);
|
|
2980
|
+
return;
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
if (droppedLines > 0) {
|
|
2984
|
+
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
2985
|
+
`;
|
|
2986
|
+
droppedLines = 0;
|
|
2987
|
+
try {
|
|
2988
|
+
onDeliveryGap(line);
|
|
2989
|
+
} catch {
|
|
2990
|
+
}
|
|
2991
|
+
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
2992
|
+
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
2993
|
+
flush();
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
stream.on("close", onTerminal);
|
|
2997
|
+
stream.on("finish", onTerminal);
|
|
2998
|
+
stream.on("error", onError);
|
|
2999
|
+
return (line) => {
|
|
3000
|
+
if (closed) return;
|
|
3001
|
+
const bytes = Buffer.byteLength(line, "utf8");
|
|
3002
|
+
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
3003
|
+
droppedLines += 1;
|
|
3004
|
+
scheduleFlush();
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
3007
|
+
pending.push({ line, bytes });
|
|
3008
|
+
pendingBytes += bytes;
|
|
3009
|
+
scheduleFlush();
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
// host/invocation-authentication-client-command.ts
|
|
3014
|
+
var DOCTOR_FLAGS = Object.freeze({
|
|
3015
|
+
"--expected-sha256": "expected_sha256",
|
|
3016
|
+
"--expected-source-commit": "expected_source_commit",
|
|
3017
|
+
"--expected-instance-ref": "expected_instance_ref"
|
|
3018
|
+
});
|
|
3019
|
+
|
|
3020
|
+
// host/service-log.ts
|
|
3021
|
+
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
3022
|
+
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
3023
|
+
void persistHostServiceLogLine(line);
|
|
3024
|
+
});
|
|
3025
|
+
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
3026
|
+
const details = diagnosticDetails(event, failure_kind, cause);
|
|
3027
|
+
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
3028
|
+
`;
|
|
3029
|
+
try {
|
|
3030
|
+
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
3031
|
+
} catch {
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
function diagnosticDetails(event, failureKind, cause) {
|
|
3035
|
+
if (event === "watcher_scan_failed") return {
|
|
3036
|
+
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
3037
|
+
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
3038
|
+
};
|
|
3039
|
+
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
3040
|
+
}
|
|
3041
|
+
function validDiagnosticCause(cause, event) {
|
|
3042
|
+
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
3043
|
+
}
|
|
3044
|
+
function defaultHostServiceDiagnosticSink(line) {
|
|
3045
|
+
writeHostServiceLogLine(line);
|
|
3046
|
+
}
|
|
3047
|
+
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
3048
|
+
function writeHostServiceLogLine(line, environment = process.env) {
|
|
3049
|
+
void persistHostServiceLogLine(line, environment);
|
|
3050
|
+
defaultHostServiceLogDelivery(line);
|
|
3051
|
+
}
|
|
3052
|
+
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
3053
|
+
if (process.platform !== "win32") return;
|
|
3054
|
+
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
3055
|
+
if (path === void 0 || !win322.isAbsolute(path) || win322.normalize(path) !== path) return;
|
|
3056
|
+
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
3057
|
+
}
|
|
3058
|
+
async function appendHostServiceLogLine(path, line) {
|
|
3059
|
+
if (!isAbsolute2(path)) return;
|
|
3060
|
+
await ensureHostServiceLogDirectory(path);
|
|
3061
|
+
await appendFile(path, line);
|
|
3062
|
+
}
|
|
3063
|
+
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
3064
|
+
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
3065
|
+
function ensureHostServiceLogDirectory(path) {
|
|
3066
|
+
const directory = dirname2(path);
|
|
3067
|
+
const existing = hostServiceLogDirectories.get(directory);
|
|
3068
|
+
if (existing !== void 0) return existing;
|
|
3069
|
+
const pending = mkdir(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
3070
|
+
hostServiceLogDirectories.delete(directory);
|
|
3071
|
+
throw error;
|
|
3072
|
+
});
|
|
3073
|
+
hostServiceLogDirectories.set(directory, pending);
|
|
3074
|
+
return pending;
|
|
3075
|
+
}
|
|
3076
|
+
|
|
2876
3077
|
// host/relay/src/host-producer-core.ts
|
|
2877
3078
|
var HOST_TRANSCRIPT_CURSOR_REASONS = vocabulary(["transcript_replaced", "transcript_truncated", "transcript_rewritten", "transcript_malformed"]);
|
|
2878
3079
|
function isHostTranscriptCursorReason(value) {
|
|
@@ -2977,7 +3178,7 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
2977
3178
|
outboxRetentionMs: options.retention_ms ?? owner.default_retention_ms,
|
|
2978
3179
|
now: options.now ?? (() => /* @__PURE__ */ new Date()),
|
|
2979
3180
|
log: options.log ?? ((line) => {
|
|
2980
|
-
|
|
3181
|
+
writeHostServiceLogLine(`${line}
|
|
2981
3182
|
`);
|
|
2982
3183
|
}),
|
|
2983
3184
|
producerInstallationRef: options.producer_installation_ref
|
|
@@ -3017,7 +3218,13 @@ var HostTranscriptWatcher = class {
|
|
|
3017
3218
|
}
|
|
3018
3219
|
async scanRegistration(registration) {
|
|
3019
3220
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
3020
|
-
missing: () =>
|
|
3221
|
+
missing: async () => {
|
|
3222
|
+
try {
|
|
3223
|
+
return await this.retireMissing(registration);
|
|
3224
|
+
} catch (error) {
|
|
3225
|
+
return this.scanFailed(void 0, registration, error);
|
|
3226
|
+
}
|
|
3227
|
+
},
|
|
3021
3228
|
failed: (handle, error) => this.scanFailed(handle, registration, error)
|
|
3022
3229
|
});
|
|
3023
3230
|
}
|
|
@@ -3100,8 +3307,8 @@ var HostProducerDrainCore = class {
|
|
|
3100
3307
|
};
|
|
3101
3308
|
|
|
3102
3309
|
// 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
|
|
3310
|
+
import { lstat as lstat2, mkdir as mkdir2, open as open2, rename, unlink } from "node:fs/promises";
|
|
3311
|
+
import { dirname as dirname3 } from "node:path";
|
|
3105
3312
|
|
|
3106
3313
|
// host/windows-rename-retry.ts
|
|
3107
3314
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
@@ -3154,7 +3361,7 @@ function isRetryableRenameError(error) {
|
|
|
3154
3361
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3155
3362
|
var DEFAULT_PORT = {
|
|
3156
3363
|
platform: process.platform,
|
|
3157
|
-
mkdir: (path, options) =>
|
|
3364
|
+
mkdir: (path, options) => mkdir2(path, options),
|
|
3158
3365
|
lstat: (path) => lstat2(path),
|
|
3159
3366
|
open_file: (path) => open2(path, "wx", 384),
|
|
3160
3367
|
rename,
|
|
@@ -3163,7 +3370,7 @@ var DEFAULT_PORT = {
|
|
|
3163
3370
|
unique_ref: () => `${process.pid}.${crypto.randomUUID()}`
|
|
3164
3371
|
};
|
|
3165
3372
|
async function durableAtomicReplace(target, data, port = DEFAULT_PORT) {
|
|
3166
|
-
const parent =
|
|
3373
|
+
const parent = dirname3(target);
|
|
3167
3374
|
await port.mkdir(parent, { recursive: true, mode: 448 });
|
|
3168
3375
|
const parentStats = await port.lstat(parent);
|
|
3169
3376
|
const expectedUid = typeof process.geteuid === "function" ? process.geteuid() : parentStats.uid;
|
|
@@ -3233,8 +3440,8 @@ function errorCode(error) {
|
|
|
3233
3440
|
// host/relay/src/host-usage-facts-store.ts
|
|
3234
3441
|
import { createHash as createHash6 } from "node:crypto";
|
|
3235
3442
|
import { constants as constants2 } from "node:fs";
|
|
3236
|
-
import { mkdir as
|
|
3237
|
-
import { dirname as
|
|
3443
|
+
import { mkdir as mkdir3, open as open3, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
3444
|
+
import { dirname as dirname4, join as join3 } from "node:path";
|
|
3238
3445
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
3239
3446
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
3240
3447
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -3483,7 +3690,7 @@ var HostUsageFactsStore = class {
|
|
|
3483
3690
|
}
|
|
3484
3691
|
async writeImmutableBatch(state, batch, bytes) {
|
|
3485
3692
|
const path = this.batchPath(state, batch.batch_ref);
|
|
3486
|
-
await preparePrivateDirectory(
|
|
3693
|
+
await preparePrivateDirectory(dirname4(path), this.platform, this.custody);
|
|
3487
3694
|
const existing = await readOptionalBytes(path, CEAL_HOST_USAGE_BATCH_MAX_BYTES, this.platform, this.custody);
|
|
3488
3695
|
if (existing !== null) {
|
|
3489
3696
|
if (!existing.equals(bytes)) throw new Error("Host usage facts batch reference conflicts with existing bytes.");
|
|
@@ -3501,7 +3708,7 @@ var HostUsageFactsStore = class {
|
|
|
3501
3708
|
await handle.sync();
|
|
3502
3709
|
await handle.close();
|
|
3503
3710
|
handle = void 0;
|
|
3504
|
-
await syncDirectory(
|
|
3711
|
+
await syncDirectory(dirname4(path), this.platform);
|
|
3505
3712
|
} catch (error) {
|
|
3506
3713
|
await handle?.close().catch(() => void 0);
|
|
3507
3714
|
if (errorCode2(error) === "EEXIST") {
|
|
@@ -3755,7 +3962,7 @@ async function preparePrivateDirectory(path, platform, custody) {
|
|
|
3755
3962
|
await ensurePrivateDirectoryWithSecurefs(path, custody);
|
|
3756
3963
|
return;
|
|
3757
3964
|
}
|
|
3758
|
-
await
|
|
3965
|
+
await mkdir3(path, { recursive: true, mode: 448 });
|
|
3759
3966
|
if (!await isPrivateDirectory(path, platform)) throw new Error("Host usage facts directory is not owner private.");
|
|
3760
3967
|
}
|
|
3761
3968
|
async function syncExistingFile(path, platform) {
|
|
@@ -3765,7 +3972,7 @@ async function syncExistingFile(path, platform) {
|
|
|
3765
3972
|
} finally {
|
|
3766
3973
|
await handle.close();
|
|
3767
3974
|
}
|
|
3768
|
-
await syncDirectory(
|
|
3975
|
+
await syncDirectory(dirname4(path), platform);
|
|
3769
3976
|
}
|
|
3770
3977
|
async function syncDirectory(path, platform) {
|
|
3771
3978
|
if (platform === "win32") return;
|
|
@@ -3906,16 +4113,16 @@ function completeLinePrefix(bytes, baseOffset) {
|
|
|
3906
4113
|
|
|
3907
4114
|
// host/relay/src/host-registration-state.ts
|
|
3908
4115
|
import { constants as constants4 } from "node:fs";
|
|
3909
|
-
import { dirname as
|
|
4116
|
+
import { dirname as dirname5 } from "node:path";
|
|
3910
4117
|
|
|
3911
4118
|
// host/runtime-source-paths.ts
|
|
3912
4119
|
import { createHash as createHash7 } from "node:crypto";
|
|
3913
|
-
import { posix as
|
|
4120
|
+
import { posix as posix3, win32 as win324 } from "node:path";
|
|
3914
4121
|
|
|
3915
4122
|
// host/absolute-path.ts
|
|
3916
|
-
import { posix, win32 as
|
|
4123
|
+
import { posix as posix2, win32 as win323 } from "node:path";
|
|
3917
4124
|
function isAbsoluteNormalizedNonRootPath(value, flavor = process.platform, allowRoot = false) {
|
|
3918
|
-
const pathApi = flavor === "win32" || flavor === "windows" ?
|
|
4125
|
+
const pathApi = flavor === "win32" || flavor === "windows" ? win323 : posix2;
|
|
3919
4126
|
return typeof value === "string" && value.length <= 4096 && !value.includes("\0") && pathApi.isAbsolute(value) && pathApi.normalize(value) === value && (allowRoot || pathApi.parse(value).root !== value);
|
|
3920
4127
|
}
|
|
3921
4128
|
|
|
@@ -3936,7 +4143,7 @@ function macosHostRelayIpcDirectory(uid = process.geteuid?.() ?? -1) {
|
|
|
3936
4143
|
function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platform, uid = process.geteuid?.() ?? -1) {
|
|
3937
4144
|
const sourceId = hostSourceUuid(sourceRef);
|
|
3938
4145
|
if (!isAbsoluteNormalizedNonRootPath(stateRoot, platform) || sourceId === null) throw new TypeError("Host runtime source identity is invalid.");
|
|
3939
|
-
const path = platform === "win32" ?
|
|
4146
|
+
const path = platform === "win32" ? win324 : posix3;
|
|
3940
4147
|
const sourcesRoot = path.join(stateRoot, "sources");
|
|
3941
4148
|
const sourceRoot = path.join(sourcesRoot, sourceId);
|
|
3942
4149
|
const runtimeRoot = path.join(stateRoot, "run");
|
|
@@ -3947,7 +4154,7 @@ function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platfor
|
|
|
3947
4154
|
function projectRelayEndpoint(stateRoot, sourceRef, rooted, platform, uid) {
|
|
3948
4155
|
if (platform !== "win32" && (platform !== "darwin" || Buffer.byteLength(rooted, "utf8") <= PORTABLE_UNIX_SOCKET_PATH_MAX_BYTES)) return rooted;
|
|
3949
4156
|
const digest2 = createHash7("sha256").update(`${stateRoot}\0${sourceRef}`).digest("hex");
|
|
3950
|
-
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` :
|
|
4157
|
+
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` : posix3.join(macosHostRelayIpcDirectory(uid), `${digest2}.sock`);
|
|
3951
4158
|
}
|
|
3952
4159
|
function assertHostProducerSourcePaths(stateRoot, config, producer, platform = process.platform) {
|
|
3953
4160
|
const paths = hostRuntimeSourcePaths(stateRoot, config.host_source_ref, platform);
|
|
@@ -3975,7 +4182,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
3975
4182
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
3976
4183
|
let raw;
|
|
3977
4184
|
try {
|
|
3978
|
-
await assertPrivateRegistrationDirectory(
|
|
4185
|
+
await assertPrivateRegistrationDirectory(dirname5(path), platform, custody);
|
|
3979
4186
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
3980
4187
|
} catch (error) {
|
|
3981
4188
|
throw registrationReadError(error);
|
|
@@ -4080,192 +4287,6 @@ function waitForAbort(signal, milliseconds) {
|
|
|
4080
4287
|
});
|
|
4081
4288
|
}
|
|
4082
4289
|
|
|
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
4290
|
// host/relay/src/host-usage-facts-uploader.ts
|
|
4270
4291
|
var HostUsageFactsUploader = class {
|
|
4271
4292
|
options;
|
|
@@ -4284,7 +4305,7 @@ var HostUsageFactsUploader = class {
|
|
|
4284
4305
|
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
4306
|
const timeout = AbortSignal.timeout(this.options.timeout_ms ?? 5e3);
|
|
4286
4307
|
const requestSignal = signal === void 0 ? timeout : AbortSignal.any([signal, timeout]);
|
|
4287
|
-
const response2 = await
|
|
4308
|
+
const response2 = await this.options.fetch(`${registration.gateway_request_origin}${CEAL_HOST_USAGE_INGRESS_PATH}`, {
|
|
4288
4309
|
method: "POST",
|
|
4289
4310
|
headers: { authorization: `Bearer ${registration.host_access_token}`, "content-type": "application/json" },
|
|
4290
4311
|
body: JSON.stringify(candidate.batch),
|
|
@@ -5594,9 +5615,9 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5594
5615
|
const { size, device, inode } = await ownedCodexTranscriptFile(handle);
|
|
5595
5616
|
const preflight = await this.preflight(registration, handle, size, device, inode);
|
|
5596
5617
|
if (preflight.cursor === null) return preflight.result;
|
|
5618
|
+
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
5619
|
const complete = await this.readChunk(handle, preflight.cursor.offset, size);
|
|
5598
5620
|
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
5621
|
return { records: 0, enqueued: 0, quarantined: false };
|
|
5601
5622
|
}
|
|
5602
5623
|
return await this.consumeCompleteChunk(registration, handle, preflight.cursor, complete, device, inode);
|
|
@@ -5613,17 +5634,17 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5613
5634
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
5614
5635
|
let cursor = existing ?? codexTranscriptInitialCursor(registration, device, inode, this.now);
|
|
5615
5636
|
if (cursor.status === "quarantined") {
|
|
5616
|
-
return { cursor: null,
|
|
5637
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
5617
5638
|
}
|
|
5618
5639
|
const reason = this.cursorIdentityReason(cursor, registration.transcript_path, device, inode) ?? await this.cursorBoundsReason(handle, cursor, size);
|
|
5619
5640
|
if (reason === null) {
|
|
5620
|
-
if (cursor.human_message_window !== void 0) return { cursor,
|
|
5641
|
+
if (cursor.human_message_window !== void 0) return { cursor, checkpointPending: existing === null, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
5621
5642
|
const humanWindow = await this.readHumanMessageProjection(handle, registration, cursor);
|
|
5622
|
-
return { cursor: { ...cursor, human_message_window: humanWindow },
|
|
5643
|
+
return { cursor: { ...cursor, human_message_window: humanWindow }, checkpointPending: true, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
5623
5644
|
}
|
|
5624
5645
|
await this.quarantine(registration, cursor, device, inode, reason);
|
|
5625
5646
|
this.diagnostic("watcher_scan_failed", "other", `cursor_${reason}`);
|
|
5626
|
-
return { cursor: null,
|
|
5647
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
5627
5648
|
}
|
|
5628
5649
|
async readHumanMessageProjection(handle, registration, cursor) {
|
|
5629
5650
|
return readCodexHumanMessageProjection(registration, cursor, (offset, size) => this.readChunk(handle, offset, size));
|
|
@@ -6117,12 +6138,11 @@ function normalizedCounts(selected) {
|
|
|
6117
6138
|
function nullCounts() {
|
|
6118
6139
|
return { input: null, output: null, total: null, cached_input: null, cache_write_input: null, reasoning_output: null };
|
|
6119
6140
|
}
|
|
6120
|
-
var USAGE_COUNT_FIELDS = ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"];
|
|
6121
6141
|
function isRegression(current, previous) {
|
|
6122
|
-
return
|
|
6142
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.some((key) => current[key] < previous[key]);
|
|
6123
6143
|
}
|
|
6124
6144
|
function sameCounts(left, right) {
|
|
6125
|
-
return
|
|
6145
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.every((key) => left[key] === right[key]);
|
|
6126
6146
|
}
|
|
6127
6147
|
function buildCoverageGaps(sourceFileRef, startOffset, endOffset, counts) {
|
|
6128
6148
|
return [...counts].map(([reason, omittedCount]) => coverageGap(reason, sourceFileRef, startOffset, endOffset, omittedCount));
|
|
@@ -6171,9 +6191,9 @@ var CODEX_PRODUCER_DESCRIPTOR = {
|
|
|
6171
6191
|
config: (shared, extras) => ({ ...shared, codex_sessions_root: hostProducerExtraPath(extras, CODEX_SESSIONS_ROOT) }),
|
|
6172
6192
|
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir }),
|
|
6173
6193
|
drain: drainCodexProducerOnce,
|
|
6174
|
-
background: (config, signal) => {
|
|
6194
|
+
background: (config, signal, dependencies) => {
|
|
6175
6195
|
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);
|
|
6196
|
+
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
6197
|
}
|
|
6178
6198
|
};
|
|
6179
6199
|
|