@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
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
import { createRequire as __cealCreateRequire } from "node:module";
|
|
3
3
|
const require = __cealCreateRequire(import.meta.url);
|
|
4
4
|
|
|
5
|
+
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
6
|
+
function vocabulary(words) {
|
|
7
|
+
return Object.freeze(words);
|
|
8
|
+
}
|
|
9
|
+
function isVocabularyWord(words, value) {
|
|
10
|
+
return words.some((word) => word === value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// packages/ceal-client-protocol/src/host-usage-fields.ts
|
|
14
|
+
var CEAL_CODEX_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"]);
|
|
15
|
+
var CEAL_CLAUDE_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "output_tokens"]);
|
|
16
|
+
|
|
5
17
|
// packages/ceal-client-protocol/src/canonical-json.ts
|
|
6
18
|
function cealCanonicalJson(value) {
|
|
7
19
|
if (value === null || typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
@@ -176,8 +188,11 @@ var client_wire_contract_default = {
|
|
|
176
188
|
"ok",
|
|
177
189
|
"code",
|
|
178
190
|
"reason",
|
|
179
|
-
"gateway_status"
|
|
191
|
+
"gateway_status",
|
|
192
|
+
"retry_after_ms"
|
|
180
193
|
],
|
|
194
|
+
refusal_required_fields: ["schema_version", "ok", "code", "reason"],
|
|
195
|
+
refusal_optional_fields: ["gateway_status", "retry_after_ms"],
|
|
181
196
|
client_nonce: {
|
|
182
197
|
character_class_source: "A-Za-z0-9_-",
|
|
183
198
|
encoded_characters: 43
|
|
@@ -396,14 +411,6 @@ var CEAL_OPERATION_WITHHELD_NEXT_ACTIONS = Object.freeze({
|
|
|
396
411
|
personal_authorization_required: "connect_personal_account"
|
|
397
412
|
});
|
|
398
413
|
|
|
399
|
-
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
400
|
-
function vocabulary(words) {
|
|
401
|
-
return Object.freeze(words);
|
|
402
|
-
}
|
|
403
|
-
function isVocabularyWord(words, value) {
|
|
404
|
-
return words.some((word) => word === value);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
414
|
// packages/ceal-client-protocol/src/gateway-response-types.ts
|
|
408
415
|
var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavailable", "unknown"]);
|
|
409
416
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
@@ -807,7 +814,7 @@ var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask a
|
|
|
807
814
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
808
815
|
var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Relay to the same release as the Gateway, then retry.";
|
|
809
816
|
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.";
|
|
810
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select
|
|
817
|
+
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.";
|
|
811
818
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
812
819
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
813
820
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
@@ -859,14 +866,12 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
859
866
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
860
867
|
internal_error: guidance("The Gateway failed without exposing internal state.", "answer_with_gap", 500),
|
|
861
868
|
// Owned by the Gateway canonical adapter (`gateway/core/src/gateway-canonical-operation-http-adapter.ts`):
|
|
862
|
-
// the client variant
|
|
869
|
+
// the static client variant was retired when the client started reading this table.
|
|
863
870
|
request_body_too_large: guidance("The Gateway request body exceeds its bounded limit.", "reduce_request_size", 413),
|
|
864
871
|
gateway_response_too_large: guidance("The Gateway response exceeds its bounded limit; reduce the requested page or result size.", "reduce_request_size", 500),
|
|
865
|
-
//
|
|
866
|
-
//
|
|
867
|
-
|
|
868
|
-
// forbids the safe read retry the sentence exists to allow.
|
|
869
|
-
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),
|
|
872
|
+
// The safe move varies by request. Keep the sentence conditional on the
|
|
873
|
+
// same `retryable` and `next_action` facts the response exposes.
|
|
874
|
+
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
870
875
|
// Restored verbatim from the retired `localFailureText`
|
|
871
876
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
872
877
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -947,8 +952,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
947
952
|
// Host mint classifications. The CLI emits `invocation_authentication_unavailable` with the classification
|
|
948
953
|
// in its detail fact; rows without their own sentence share that code's moved sentence, while `next_action`
|
|
949
954
|
// is moved from `canonicalHostAuthenticationNextActions` (generated from `CEAL_HOST_AUTHENTICATION_POLICY`)
|
|
950
|
-
// and `retryable` from `hostAuthenticationFailureForCause` (
|
|
951
|
-
// sentences carry the
|
|
955
|
+
// and `retryable` from `hostAuthenticationFailureForCause` (the table's explicit retry verdict). Cause-specific
|
|
956
|
+
// sentences carry only remedies proved by the Host or Relay cause; generic Gateway refusals do not prove a release mismatch.
|
|
952
957
|
// Statuses are the
|
|
953
958
|
// Gateway-owned mapping decided with the operator 2026-10-13. This covers every wire cause the maps at
|
|
954
959
|
// `host/invocation-authentication-command.ts:217-242` emit, through their policy classifications.
|
|
@@ -958,21 +963,23 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
958
963
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
959
964
|
// changes mode; standalone remains the separate Client authority path.
|
|
960
965
|
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "answer_with_gap", 401),
|
|
961
|
-
|
|
962
|
-
|
|
966
|
+
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),
|
|
967
|
+
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),
|
|
968
|
+
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),
|
|
963
969
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
964
970
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
965
971
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
966
972
|
host_mint_gateway_rate_limited: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 429),
|
|
967
|
-
host_mint_gateway_refused: guidance(
|
|
973
|
+
host_mint_gateway_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
968
974
|
host_mint_gateway_response_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
975
|
+
host_contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 502),
|
|
969
976
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
970
977
|
// producer-frame fault names the administrator repair step.
|
|
971
978
|
host_producer_frame_invalid: guidance("Ask an administrator to inspect and repair the producer frame, then start a fresh Host turn.", "ask_admin", 400),
|
|
972
979
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
973
980
|
// sandboxed Relay socket names the run-alone retry.
|
|
974
981
|
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),
|
|
975
|
-
host_relay_unavailable: guidance(
|
|
982
|
+
host_relay_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 503),
|
|
976
983
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
977
984
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
978
985
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -1015,7 +1022,7 @@ var UNKNOWN_OUTCOMES = vocabulary(["reconcile", "operator_action", "excluded"]);
|
|
|
1015
1022
|
var RECOVERY_OWNERS = vocabulary(["gateway", "connector", "operator"]);
|
|
1016
1023
|
var CEAL_OPERATION_ADMISSION_STATES = vocabulary(["proposed", "refused", "admitted"]);
|
|
1017
1024
|
var CEAL_OPERATION_EXECUTION_STATES = vocabulary(["not_started", "started", "completed"]);
|
|
1018
|
-
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1025
|
+
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_applicable", "not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1019
1026
|
var CEAL_OPERATION_EFFECT_STATES = vocabulary(["none", "applied", "failed", "unknown", "compensated"]);
|
|
1020
1027
|
var CEAL_OPERATION_OBSERVATION_STATES = vocabulary(["not_started", "not_required", "pending", "observed", "unavailable"]);
|
|
1021
1028
|
var CEAL_OPERATION_RECOVERY_KINDS = vocabulary(["none", "reconcile", "compensate", "operator_action"]);
|
|
@@ -1198,6 +1205,7 @@ var CEAL_OPERATION_ACCESS_CLASSES = vocabulary(["read", "write"]);
|
|
|
1198
1205
|
// packages/ceal-client-protocol/src/domain-vocabulary.ts
|
|
1199
1206
|
var CEAL_CONNECTOR_STATUSES = vocabulary(["active", "disabled", "disconnected"]);
|
|
1200
1207
|
var CEAL_CONNECTOR_CUSTODIES = vocabulary(["organization", "personal"]);
|
|
1208
|
+
var CEAL_PROVIDER_BOUNDARY_FIELDS = vocabulary(["provider_boundary_ref", "provider_boundary_kind", "provider_boundary_label", "provider_native_id", "provider_boundary_evidence"]);
|
|
1201
1209
|
var CEAL_PERSONAL_ACCESS_CEILINGS = vocabulary(["disabled", "read", "read_write"]);
|
|
1202
1210
|
var CEAL_TARGET_REF_PATTERN = "^[^\\p{Cc}]+$";
|
|
1203
1211
|
var TARGET_REF = new RegExp(CEAL_TARGET_REF_PATTERN, "u");
|
|
@@ -1243,7 +1251,7 @@ var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
|
1243
1251
|
var CEAL_OPERATION_AUTHORITY_POLICY_KEYS = Object.freeze(["access_group", "instance_binding", "target", "admission_recheck"]);
|
|
1244
1252
|
var MAX_OPERATION_INPUT_RESOLVER_BINDINGS = 96;
|
|
1245
1253
|
var CEAL_OPERATION_DESCRIPTOR_REQUIRED_ENVELOPE_KEYS = Object.freeze(["schema_version", "id", "input_contract", "result_contract", "policy"]);
|
|
1246
|
-
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary"]);
|
|
1254
|
+
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary", "standard_names"]);
|
|
1247
1255
|
|
|
1248
1256
|
// packages/ceal-client-protocol/src/operation-catalog.ts
|
|
1249
1257
|
var CEAL_OPERATION_CATALOG_SCHEMA_VERSION = "ceal.catalog.v3";
|
|
@@ -1339,6 +1347,7 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
1339
1347
|
gateway_access_group_connector_activity_scope_audit: (root) => join(root, "profile-connector-activity-scope-audit.jsonl"),
|
|
1340
1348
|
gateway_access_group_connector_calendar_scope_audit: (root) => join(root, "profile-connector-calendar-scope-audit.jsonl"),
|
|
1341
1349
|
gateway_access_group_connector_readiness_audit: (root) => join(root, "profile-connector-readiness.audit.jsonl"),
|
|
1350
|
+
gateway_deployment_events: (root) => join(root, "gateway-deployments.jsonl"),
|
|
1342
1351
|
gateway_organization_audit_ledger: (root) => join(root, "organization-ledger.jsonl"),
|
|
1343
1352
|
gateway_personal_client_audit: (root) => join(root, "audit.jsonl"),
|
|
1344
1353
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
@@ -1368,6 +1377,11 @@ var CEAL_HOST_INSTALLATION_REF_PATTERN = new RegExp(`^host-installation:${CEAL_L
|
|
|
1368
1377
|
var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUID_PATTERN}$`, "u");
|
|
1369
1378
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
1370
1379
|
|
|
1380
|
+
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1381
|
+
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
1382
|
+
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
1383
|
+
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1384
|
+
|
|
1371
1385
|
// packages/ceal-client-protocol/src/operation-result-completeness.ts
|
|
1372
1386
|
var CEAL_READ_VALUE_CONTINUATION_KEYS = vocabulary(["continuation", "continuation_ref", "next_cursor"]);
|
|
1373
1387
|
|
|
@@ -1452,6 +1466,7 @@ var PROVIDER_LINK_CONFORMANCE_TABLE = Object.freeze([
|
|
|
1452
1466
|
{ 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" },
|
|
1453
1467
|
{ 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" },
|
|
1454
1468
|
{ 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" },
|
|
1469
|
+
{ 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" },
|
|
1455
1470
|
{ 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" },
|
|
1456
1471
|
{ 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" },
|
|
1457
1472
|
{ 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" },
|
|
@@ -1621,6 +1636,7 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
1621
1636
|
created_at: { required: false, timestamp: true },
|
|
1622
1637
|
created_at_local: { required: false, timestamp: true },
|
|
1623
1638
|
modified_at: { required: false, timestamp: true },
|
|
1639
|
+
observed_at: { required: false, timestamp: true },
|
|
1624
1640
|
modified_at_local: { required: false, timestamp: true },
|
|
1625
1641
|
viewed_by_me_at: { required: false, timestamp: true },
|
|
1626
1642
|
modified_by_me_at: { required: false, timestamp: true },
|
|
@@ -1648,9 +1664,6 @@ var RESOURCE_ROW_REQUIRED_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(
|
|
|
1648
1664
|
var RESOURCE_ROW_KEYS = new Set(Object.keys(RESOURCE_ROW_KEY_RULES));
|
|
1649
1665
|
var RESOURCE_ROW_TIMESTAMP_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(([key, rule]) => rule.timestamp ? [key] : []);
|
|
1650
1666
|
|
|
1651
|
-
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1652
|
-
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1653
|
-
|
|
1654
1667
|
// packages/ceal-client-protocol/src/excluded-target-coverage.ts
|
|
1655
1668
|
var CEAL_EXCLUDED_TARGET_COVERAGE_MAX_ENTRIES = 64;
|
|
1656
1669
|
function cealExcludedTargetCoverageJsonSchema() {
|
|
@@ -1957,7 +1970,7 @@ function validateBatchContents(value) {
|
|
|
1957
1970
|
if (facts.length === 0 && gaps.length === 0 || facts.length > 0 && value.source_ranges.length === 0) invalid("Ceal Host usage coverage is invalid.");
|
|
1958
1971
|
const sourceFiles = new Set(value.source_ranges.map((range) => sourceRangeFileRef(range)));
|
|
1959
1972
|
for (const fact of facts) {
|
|
1960
|
-
|
|
1973
|
+
validateCealHostUsageFact(fact, value.host_session_ref);
|
|
1961
1974
|
if (!sourceFiles.has(fact.source_file_ref)) invalid("Ceal Host usage fact is outside its source ranges.");
|
|
1962
1975
|
}
|
|
1963
1976
|
for (const gap of gaps) {
|
|
@@ -1990,7 +2003,7 @@ function hostUsageSourceFileReference(producer, hostSourceRef, hostSessionRef, d
|
|
|
1990
2003
|
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.");
|
|
1991
2004
|
return `host-source-file:${sha256(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef, device, inode }))}`;
|
|
1992
2005
|
}
|
|
1993
|
-
function
|
|
2006
|
+
function validateCealHostUsageFact(value, sessionRef) {
|
|
1994
2007
|
if (!isOperationRecord(value)) invalid("Ceal Host usage fact is invalid.");
|
|
1995
2008
|
requireFactByteLimit(value);
|
|
1996
2009
|
if (value.producer === "codex_transcript") validateCodexFact(value);
|
|
@@ -2054,7 +2067,7 @@ function validCorrectionSemantics(value) {
|
|
|
2054
2067
|
}
|
|
2055
2068
|
function validateCodexUsageCounts(value) {
|
|
2056
2069
|
if (!isOperationRecord(value)) invalid("Ceal Codex usage fields are invalid.");
|
|
2057
|
-
requireExactOperationKeys(value,
|
|
2070
|
+
requireExactOperationKeys(value, CEAL_CODEX_USAGE_COUNT_FIELDS);
|
|
2058
2071
|
for (const key of Object.keys(value)) if (!safeInteger(value[key])) invalid("Ceal Codex usage fields are invalid.");
|
|
2059
2072
|
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.");
|
|
2060
2073
|
}
|
|
@@ -2374,6 +2387,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
2374
2387
|
"options_invalid",
|
|
2375
2388
|
"session_unavailable",
|
|
2376
2389
|
"context_unavailable",
|
|
2390
|
+
"activation_wait_exhausted",
|
|
2377
2391
|
"context_replaced",
|
|
2378
2392
|
"no_binding",
|
|
2379
2393
|
"context_expired",
|
|
@@ -2409,22 +2423,23 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
2409
2423
|
// This reason cannot distinguish a Codex side conversation from a missing
|
|
2410
2424
|
// context in a regular session, so guidance must leave that choice to the caller.
|
|
2411
2425
|
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "answer_with_gap" }),
|
|
2412
|
-
|
|
2426
|
+
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
2427
|
+
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
2413
2428
|
// `no_binding` now means the producer has no real current Host session. The
|
|
2414
2429
|
// Host Relay never uses it for an uncreated Gateway Request; there is no
|
|
2415
2430
|
// useful retry until the consumer is running inside a Host session.
|
|
2416
2431
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
2417
|
-
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "
|
|
2432
|
+
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
2418
2433
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
2419
2434
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
2420
2435
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
2421
2436
|
gateway_rate_limited: Object.freeze({ classification: "host_mint_gateway_rate_limited", next_action: "answer_with_gap" }),
|
|
2422
|
-
contract_mismatch: Object.freeze({ classification: "
|
|
2423
|
-
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "
|
|
2437
|
+
contract_mismatch: Object.freeze({ classification: "host_contract_mismatch", next_action: "upgrade_ceal_client" }),
|
|
2438
|
+
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "answer_with_gap" }),
|
|
2424
2439
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
2425
2440
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
2426
2441
|
relay_permission_denied: Object.freeze({ classification: "host_relay_permission_denied", next_action: "rerun_outside_agent_sandbox" }),
|
|
2427
|
-
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "
|
|
2442
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "answer_with_gap" }),
|
|
2428
2443
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
2429
2444
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
2430
2445
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -2507,7 +2522,7 @@ function isCealHostServiceDiagnosticCause(value, event) {
|
|
|
2507
2522
|
// packages/ceal-client-protocol/src/client-result-materialization.ts
|
|
2508
2523
|
var CEAL_UNREAD_REASONS = vocabulary(["blocked", "unavailable", "too_large", "unsupported", "download_failed", "permission_denied"]);
|
|
2509
2524
|
var REQUIRED_FIELDS2 = Object.freeze(["schema_version", "operation_id", "path", "sha256"]);
|
|
2510
|
-
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "
|
|
2525
|
+
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "local_result_root", "request_context_argv", "how_to_read"]);
|
|
2511
2526
|
|
|
2512
2527
|
// packages/ceal-client-protocol/src/discovery-manifest.ts
|
|
2513
2528
|
var DISCOVERY_MANIFEST_KEYS = CEAL_CLIENT_WIRE_CONTRACT.command_response.discovery_manifest_fields;
|
|
@@ -2835,7 +2850,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
2835
2850
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
2836
2851
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
2837
2852
|
return await new Promise((resolve, reject) => {
|
|
2838
|
-
const child = execFile(executable, processArgs, { encoding: "buffer", timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
2853
|
+
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
2839
2854
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
2840
2855
|
if (exitCode === null) {
|
|
2841
2856
|
reject(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -2886,6 +2901,185 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
2886
2901
|
return entry.isDirectory() && !entry.isSymbolicLink() && isSelfOwned(entry.uid, platform) && isPrivateFileMode(entry.mode, platform);
|
|
2887
2902
|
}
|
|
2888
2903
|
|
|
2904
|
+
// host/service-log.ts
|
|
2905
|
+
import { copyFile, mkdir, stat, truncate, appendFile } from "node:fs/promises";
|
|
2906
|
+
import { dirname as dirname2, isAbsolute, posix, win32 as win322 } from "node:path";
|
|
2907
|
+
|
|
2908
|
+
// host/service-log-delivery.ts
|
|
2909
|
+
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
2910
|
+
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
2911
|
+
setImmediate(flush);
|
|
2912
|
+
}, onDeliveryGap = () => void 0) {
|
|
2913
|
+
const pending = [];
|
|
2914
|
+
const highWaterMark = stream.writableHighWaterMark;
|
|
2915
|
+
const byteBudget = highWaterMark + highWaterMark;
|
|
2916
|
+
let pendingBytes = 0;
|
|
2917
|
+
let droppedLines = 0;
|
|
2918
|
+
let flushScheduled = false;
|
|
2919
|
+
let waitingForDrain = false;
|
|
2920
|
+
let closed = !stream.writable;
|
|
2921
|
+
function stop() {
|
|
2922
|
+
if (closed) return;
|
|
2923
|
+
closed = true;
|
|
2924
|
+
pending.length = 0;
|
|
2925
|
+
pendingBytes = 0;
|
|
2926
|
+
stream.off("drain", onDrain);
|
|
2927
|
+
stream.off("close", onTerminal);
|
|
2928
|
+
stream.off("finish", onTerminal);
|
|
2929
|
+
stream.off("error", onError);
|
|
2930
|
+
}
|
|
2931
|
+
function onTerminal() {
|
|
2932
|
+
stop();
|
|
2933
|
+
}
|
|
2934
|
+
function onError() {
|
|
2935
|
+
stop();
|
|
2936
|
+
}
|
|
2937
|
+
function onDrain() {
|
|
2938
|
+
waitingForDrain = false;
|
|
2939
|
+
scheduleFlush();
|
|
2940
|
+
}
|
|
2941
|
+
function scheduleFlush() {
|
|
2942
|
+
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
2943
|
+
flushScheduled = true;
|
|
2944
|
+
let scheduling = true;
|
|
2945
|
+
let invokedSynchronously = false;
|
|
2946
|
+
try {
|
|
2947
|
+
schedule(() => {
|
|
2948
|
+
if (scheduling) {
|
|
2949
|
+
invokedSynchronously = true;
|
|
2950
|
+
return;
|
|
2951
|
+
}
|
|
2952
|
+
flushScheduled = false;
|
|
2953
|
+
flush();
|
|
2954
|
+
});
|
|
2955
|
+
} catch {
|
|
2956
|
+
flushScheduled = false;
|
|
2957
|
+
stop();
|
|
2958
|
+
return;
|
|
2959
|
+
}
|
|
2960
|
+
scheduling = false;
|
|
2961
|
+
if (invokedSynchronously) {
|
|
2962
|
+
flushScheduled = false;
|
|
2963
|
+
stop();
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
function flush() {
|
|
2967
|
+
if (closed) return;
|
|
2968
|
+
if (!stream.writable) {
|
|
2969
|
+
stop();
|
|
2970
|
+
return;
|
|
2971
|
+
}
|
|
2972
|
+
while (pending.length > 0) {
|
|
2973
|
+
if (stream.writableNeedDrain) {
|
|
2974
|
+
if (!waitingForDrain) {
|
|
2975
|
+
waitingForDrain = true;
|
|
2976
|
+
stream.once("drain", onDrain);
|
|
2977
|
+
}
|
|
2978
|
+
return;
|
|
2979
|
+
}
|
|
2980
|
+
const next = pending.shift();
|
|
2981
|
+
if (next === void 0) return;
|
|
2982
|
+
pendingBytes -= next.bytes;
|
|
2983
|
+
let accepted;
|
|
2984
|
+
try {
|
|
2985
|
+
accepted = stream.write(next.line);
|
|
2986
|
+
} catch {
|
|
2987
|
+
stop();
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
if (!accepted) {
|
|
2991
|
+
waitingForDrain = true;
|
|
2992
|
+
stream.once("drain", onDrain);
|
|
2993
|
+
return;
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
if (droppedLines > 0) {
|
|
2997
|
+
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
2998
|
+
`;
|
|
2999
|
+
droppedLines = 0;
|
|
3000
|
+
try {
|
|
3001
|
+
onDeliveryGap(line);
|
|
3002
|
+
} catch {
|
|
3003
|
+
}
|
|
3004
|
+
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
3005
|
+
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
3006
|
+
flush();
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
stream.on("close", onTerminal);
|
|
3010
|
+
stream.on("finish", onTerminal);
|
|
3011
|
+
stream.on("error", onError);
|
|
3012
|
+
return (line) => {
|
|
3013
|
+
if (closed) return;
|
|
3014
|
+
const bytes = Buffer.byteLength(line, "utf8");
|
|
3015
|
+
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
3016
|
+
droppedLines += 1;
|
|
3017
|
+
scheduleFlush();
|
|
3018
|
+
return;
|
|
3019
|
+
}
|
|
3020
|
+
pending.push({ line, bytes });
|
|
3021
|
+
pendingBytes += bytes;
|
|
3022
|
+
scheduleFlush();
|
|
3023
|
+
};
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
// host/service-log.ts
|
|
3027
|
+
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
3028
|
+
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
3029
|
+
void persistHostServiceLogLine(line);
|
|
3030
|
+
});
|
|
3031
|
+
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
3032
|
+
const details = diagnosticDetails(event, failure_kind, cause);
|
|
3033
|
+
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
3034
|
+
`;
|
|
3035
|
+
try {
|
|
3036
|
+
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
3037
|
+
} catch {
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
function diagnosticDetails(event, failureKind, cause) {
|
|
3041
|
+
if (event === "watcher_scan_failed") return {
|
|
3042
|
+
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
3043
|
+
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
3044
|
+
};
|
|
3045
|
+
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
3046
|
+
}
|
|
3047
|
+
function validDiagnosticCause(cause, event) {
|
|
3048
|
+
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
3049
|
+
}
|
|
3050
|
+
function defaultHostServiceDiagnosticSink(line) {
|
|
3051
|
+
writeHostServiceLogLine(line);
|
|
3052
|
+
}
|
|
3053
|
+
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
3054
|
+
function writeHostServiceLogLine(line, environment = process.env) {
|
|
3055
|
+
void persistHostServiceLogLine(line, environment);
|
|
3056
|
+
defaultHostServiceLogDelivery(line);
|
|
3057
|
+
}
|
|
3058
|
+
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
3059
|
+
if (process.platform !== "win32") return;
|
|
3060
|
+
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
3061
|
+
if (path === void 0 || !win322.isAbsolute(path) || win322.normalize(path) !== path) return;
|
|
3062
|
+
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
3063
|
+
}
|
|
3064
|
+
async function appendHostServiceLogLine(path, line) {
|
|
3065
|
+
if (!isAbsolute(path)) return;
|
|
3066
|
+
await ensureHostServiceLogDirectory(path);
|
|
3067
|
+
await appendFile(path, line);
|
|
3068
|
+
}
|
|
3069
|
+
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
3070
|
+
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
3071
|
+
function ensureHostServiceLogDirectory(path) {
|
|
3072
|
+
const directory = dirname2(path);
|
|
3073
|
+
const existing = hostServiceLogDirectories.get(directory);
|
|
3074
|
+
if (existing !== void 0) return existing;
|
|
3075
|
+
const pending = mkdir(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
3076
|
+
hostServiceLogDirectories.delete(directory);
|
|
3077
|
+
throw error;
|
|
3078
|
+
});
|
|
3079
|
+
hostServiceLogDirectories.set(directory, pending);
|
|
3080
|
+
return pending;
|
|
3081
|
+
}
|
|
3082
|
+
|
|
2889
3083
|
// host/relay/src/host-producer-core.ts
|
|
2890
3084
|
var HOST_TRANSCRIPT_CURSOR_REASONS = vocabulary(["transcript_replaced", "transcript_truncated", "transcript_rewritten", "transcript_malformed"]);
|
|
2891
3085
|
function isHostTranscriptCursorReason(value) {
|
|
@@ -3047,7 +3241,7 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
3047
3241
|
outboxRetentionMs: options.retention_ms ?? owner.default_retention_ms,
|
|
3048
3242
|
now: options.now ?? (() => /* @__PURE__ */ new Date()),
|
|
3049
3243
|
log: options.log ?? ((line) => {
|
|
3050
|
-
|
|
3244
|
+
writeHostServiceLogLine(`${line}
|
|
3051
3245
|
`);
|
|
3052
3246
|
}),
|
|
3053
3247
|
producerInstallationRef: options.producer_installation_ref
|
|
@@ -3087,7 +3281,13 @@ var HostTranscriptWatcher = class {
|
|
|
3087
3281
|
}
|
|
3088
3282
|
async scanRegistration(registration) {
|
|
3089
3283
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
3090
|
-
missing: () =>
|
|
3284
|
+
missing: async () => {
|
|
3285
|
+
try {
|
|
3286
|
+
return await this.retireMissing(registration);
|
|
3287
|
+
} catch (error) {
|
|
3288
|
+
return this.scanFailed(void 0, registration, error);
|
|
3289
|
+
}
|
|
3290
|
+
},
|
|
3091
3291
|
failed: (handle, error) => this.scanFailed(handle, registration, error)
|
|
3092
3292
|
});
|
|
3093
3293
|
}
|
|
@@ -3170,8 +3370,8 @@ var HostProducerDrainCore = class {
|
|
|
3170
3370
|
};
|
|
3171
3371
|
|
|
3172
3372
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3173
|
-
import { lstat as lstat2, mkdir, open as open2, rename, unlink } from "node:fs/promises";
|
|
3174
|
-
import { dirname as
|
|
3373
|
+
import { lstat as lstat2, mkdir as mkdir2, open as open2, rename, unlink } from "node:fs/promises";
|
|
3374
|
+
import { dirname as dirname3 } from "node:path";
|
|
3175
3375
|
|
|
3176
3376
|
// host/windows-rename-retry.ts
|
|
3177
3377
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
@@ -3224,7 +3424,7 @@ function isRetryableRenameError(error) {
|
|
|
3224
3424
|
// host/relay/src/durable-atomic-replacement.ts
|
|
3225
3425
|
var DEFAULT_PORT = {
|
|
3226
3426
|
platform: process.platform,
|
|
3227
|
-
mkdir: (path, options) =>
|
|
3427
|
+
mkdir: (path, options) => mkdir2(path, options),
|
|
3228
3428
|
lstat: (path) => lstat2(path),
|
|
3229
3429
|
open_file: (path) => open2(path, "wx", 384),
|
|
3230
3430
|
rename,
|
|
@@ -3233,7 +3433,7 @@ var DEFAULT_PORT = {
|
|
|
3233
3433
|
unique_ref: () => `${process.pid}.${crypto.randomUUID()}`
|
|
3234
3434
|
};
|
|
3235
3435
|
async function durableAtomicReplace(target, data, port = DEFAULT_PORT) {
|
|
3236
|
-
const parent =
|
|
3436
|
+
const parent = dirname3(target);
|
|
3237
3437
|
await port.mkdir(parent, { recursive: true, mode: 448 });
|
|
3238
3438
|
const parentStats = await port.lstat(parent);
|
|
3239
3439
|
const expectedUid = typeof process.geteuid === "function" ? process.geteuid() : parentStats.uid;
|
|
@@ -3303,8 +3503,8 @@ function errorCode2(error) {
|
|
|
3303
3503
|
// host/relay/src/host-usage-facts-store.ts
|
|
3304
3504
|
import { createHash as createHash5 } from "node:crypto";
|
|
3305
3505
|
import { constants as constants2 } from "node:fs";
|
|
3306
|
-
import { mkdir as
|
|
3307
|
-
import { dirname as
|
|
3506
|
+
import { mkdir as mkdir3, open as open3, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
3507
|
+
import { dirname as dirname4, join as join3 } from "node:path";
|
|
3308
3508
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
3309
3509
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
3310
3510
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -3553,7 +3753,7 @@ var HostUsageFactsStore = class {
|
|
|
3553
3753
|
}
|
|
3554
3754
|
async writeImmutableBatch(state, batch, bytes) {
|
|
3555
3755
|
const path = this.batchPath(state, batch.batch_ref);
|
|
3556
|
-
await preparePrivateDirectory(
|
|
3756
|
+
await preparePrivateDirectory(dirname4(path), this.platform, this.custody);
|
|
3557
3757
|
const existing = await readOptionalBytes(path, CEAL_HOST_USAGE_BATCH_MAX_BYTES, this.platform, this.custody);
|
|
3558
3758
|
if (existing !== null) {
|
|
3559
3759
|
if (!existing.equals(bytes)) throw new Error("Host usage facts batch reference conflicts with existing bytes.");
|
|
@@ -3571,7 +3771,7 @@ var HostUsageFactsStore = class {
|
|
|
3571
3771
|
await handle.sync();
|
|
3572
3772
|
await handle.close();
|
|
3573
3773
|
handle = void 0;
|
|
3574
|
-
await syncDirectory(
|
|
3774
|
+
await syncDirectory(dirname4(path), this.platform);
|
|
3575
3775
|
} catch (error) {
|
|
3576
3776
|
await handle?.close().catch(() => void 0);
|
|
3577
3777
|
if (errorCode3(error) === "EEXIST") {
|
|
@@ -3825,7 +4025,7 @@ async function preparePrivateDirectory(path, platform, custody) {
|
|
|
3825
4025
|
await ensurePrivateDirectoryWithSecurefs(path, custody);
|
|
3826
4026
|
return;
|
|
3827
4027
|
}
|
|
3828
|
-
await
|
|
4028
|
+
await mkdir3(path, { recursive: true, mode: 448 });
|
|
3829
4029
|
if (!await isPrivateDirectory(path, platform)) throw new Error("Host usage facts directory is not owner private.");
|
|
3830
4030
|
}
|
|
3831
4031
|
async function syncExistingFile(path, platform) {
|
|
@@ -3835,7 +4035,7 @@ async function syncExistingFile(path, platform) {
|
|
|
3835
4035
|
} finally {
|
|
3836
4036
|
await handle.close();
|
|
3837
4037
|
}
|
|
3838
|
-
await syncDirectory(
|
|
4038
|
+
await syncDirectory(dirname4(path), platform);
|
|
3839
4039
|
}
|
|
3840
4040
|
async function syncDirectory(path, platform) {
|
|
3841
4041
|
if (platform === "win32") return;
|
|
@@ -3976,16 +4176,16 @@ function completeLinePrefix(bytes, baseOffset) {
|
|
|
3976
4176
|
|
|
3977
4177
|
// host/relay/src/host-registration-state.ts
|
|
3978
4178
|
import { constants as constants4 } from "node:fs";
|
|
3979
|
-
import { dirname as
|
|
4179
|
+
import { dirname as dirname5 } from "node:path";
|
|
3980
4180
|
|
|
3981
4181
|
// host/runtime-source-paths.ts
|
|
3982
4182
|
import { createHash as createHash6 } from "node:crypto";
|
|
3983
|
-
import { posix as
|
|
4183
|
+
import { posix as posix3, win32 as win324 } from "node:path";
|
|
3984
4184
|
|
|
3985
4185
|
// host/absolute-path.ts
|
|
3986
|
-
import { posix, win32 as
|
|
4186
|
+
import { posix as posix2, win32 as win323 } from "node:path";
|
|
3987
4187
|
function isAbsoluteNormalizedNonRootPath(value, flavor = process.platform, allowRoot = false) {
|
|
3988
|
-
const pathApi = flavor === "win32" || flavor === "windows" ?
|
|
4188
|
+
const pathApi = flavor === "win32" || flavor === "windows" ? win323 : posix2;
|
|
3989
4189
|
return typeof value === "string" && value.length <= 4096 && !value.includes("\0") && pathApi.isAbsolute(value) && pathApi.normalize(value) === value && (allowRoot || pathApi.parse(value).root !== value);
|
|
3990
4190
|
}
|
|
3991
4191
|
|
|
@@ -4029,7 +4229,7 @@ function macosHostRelayIpcDirectory(uid = process.geteuid?.() ?? -1) {
|
|
|
4029
4229
|
function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platform, uid = process.geteuid?.() ?? -1) {
|
|
4030
4230
|
const sourceId = hostSourceUuid(sourceRef);
|
|
4031
4231
|
if (!isAbsoluteNormalizedNonRootPath(stateRoot, platform) || sourceId === null) throw new TypeError("Host runtime source identity is invalid.");
|
|
4032
|
-
const path = platform === "win32" ?
|
|
4232
|
+
const path = platform === "win32" ? win324 : posix3;
|
|
4033
4233
|
const sourcesRoot = path.join(stateRoot, "sources");
|
|
4034
4234
|
const sourceRoot = path.join(sourcesRoot, sourceId);
|
|
4035
4235
|
const runtimeRoot = path.join(stateRoot, "run");
|
|
@@ -4040,7 +4240,7 @@ function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platfor
|
|
|
4040
4240
|
function projectRelayEndpoint(stateRoot, sourceRef, rooted, platform, uid) {
|
|
4041
4241
|
if (platform !== "win32" && (platform !== "darwin" || Buffer.byteLength(rooted, "utf8") <= PORTABLE_UNIX_SOCKET_PATH_MAX_BYTES)) return rooted;
|
|
4042
4242
|
const digest2 = createHash6("sha256").update(`${stateRoot}\0${sourceRef}`).digest("hex");
|
|
4043
|
-
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` :
|
|
4243
|
+
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` : posix3.join(macosHostRelayIpcDirectory(uid), `${digest2}.sock`);
|
|
4044
4244
|
}
|
|
4045
4245
|
function assertHostProducerSourcePaths(stateRoot, config, producer, platform = process.platform) {
|
|
4046
4246
|
const paths = hostRuntimeSourcePaths(stateRoot, config.host_source_ref, platform);
|
|
@@ -4068,7 +4268,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
4068
4268
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
4069
4269
|
let raw;
|
|
4070
4270
|
try {
|
|
4071
|
-
await assertPrivateRegistrationDirectory(
|
|
4271
|
+
await assertPrivateRegistrationDirectory(dirname5(path), platform, custody);
|
|
4072
4272
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
4073
4273
|
} catch (error) {
|
|
4074
4274
|
throw registrationReadError(error);
|
|
@@ -4173,185 +4373,6 @@ function waitForAbort(signal, milliseconds) {
|
|
|
4173
4373
|
});
|
|
4174
4374
|
}
|
|
4175
4375
|
|
|
4176
|
-
// host/service-log.ts
|
|
4177
|
-
import { copyFile, mkdir as mkdir3, stat, truncate, appendFile } from "node:fs/promises";
|
|
4178
|
-
import { dirname as dirname5, isAbsolute, posix as posix3, win32 as win324 } from "node:path";
|
|
4179
|
-
|
|
4180
|
-
// host/service-log-delivery.ts
|
|
4181
|
-
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
4182
|
-
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
4183
|
-
setImmediate(flush);
|
|
4184
|
-
}, onDeliveryGap = () => void 0) {
|
|
4185
|
-
const pending = [];
|
|
4186
|
-
const highWaterMark = stream.writableHighWaterMark;
|
|
4187
|
-
const byteBudget = highWaterMark + highWaterMark;
|
|
4188
|
-
let pendingBytes = 0;
|
|
4189
|
-
let droppedLines = 0;
|
|
4190
|
-
let flushScheduled = false;
|
|
4191
|
-
let waitingForDrain = false;
|
|
4192
|
-
let closed = !stream.writable;
|
|
4193
|
-
function stop() {
|
|
4194
|
-
if (closed) return;
|
|
4195
|
-
closed = true;
|
|
4196
|
-
pending.length = 0;
|
|
4197
|
-
pendingBytes = 0;
|
|
4198
|
-
stream.off("drain", onDrain);
|
|
4199
|
-
stream.off("close", onTerminal);
|
|
4200
|
-
stream.off("finish", onTerminal);
|
|
4201
|
-
stream.off("error", onError);
|
|
4202
|
-
}
|
|
4203
|
-
function onTerminal() {
|
|
4204
|
-
stop();
|
|
4205
|
-
}
|
|
4206
|
-
function onError() {
|
|
4207
|
-
stop();
|
|
4208
|
-
}
|
|
4209
|
-
function onDrain() {
|
|
4210
|
-
waitingForDrain = false;
|
|
4211
|
-
scheduleFlush();
|
|
4212
|
-
}
|
|
4213
|
-
function scheduleFlush() {
|
|
4214
|
-
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
4215
|
-
flushScheduled = true;
|
|
4216
|
-
let scheduling = true;
|
|
4217
|
-
let invokedSynchronously = false;
|
|
4218
|
-
try {
|
|
4219
|
-
schedule(() => {
|
|
4220
|
-
if (scheduling) {
|
|
4221
|
-
invokedSynchronously = true;
|
|
4222
|
-
return;
|
|
4223
|
-
}
|
|
4224
|
-
flushScheduled = false;
|
|
4225
|
-
flush();
|
|
4226
|
-
});
|
|
4227
|
-
} catch {
|
|
4228
|
-
flushScheduled = false;
|
|
4229
|
-
stop();
|
|
4230
|
-
return;
|
|
4231
|
-
}
|
|
4232
|
-
scheduling = false;
|
|
4233
|
-
if (invokedSynchronously) {
|
|
4234
|
-
flushScheduled = false;
|
|
4235
|
-
stop();
|
|
4236
|
-
}
|
|
4237
|
-
}
|
|
4238
|
-
function flush() {
|
|
4239
|
-
if (closed) return;
|
|
4240
|
-
if (!stream.writable) {
|
|
4241
|
-
stop();
|
|
4242
|
-
return;
|
|
4243
|
-
}
|
|
4244
|
-
while (pending.length > 0) {
|
|
4245
|
-
if (stream.writableNeedDrain) {
|
|
4246
|
-
if (!waitingForDrain) {
|
|
4247
|
-
waitingForDrain = true;
|
|
4248
|
-
stream.once("drain", onDrain);
|
|
4249
|
-
}
|
|
4250
|
-
return;
|
|
4251
|
-
}
|
|
4252
|
-
const next = pending.shift();
|
|
4253
|
-
if (next === void 0) return;
|
|
4254
|
-
pendingBytes -= next.bytes;
|
|
4255
|
-
let accepted;
|
|
4256
|
-
try {
|
|
4257
|
-
accepted = stream.write(next.line);
|
|
4258
|
-
} catch {
|
|
4259
|
-
stop();
|
|
4260
|
-
return;
|
|
4261
|
-
}
|
|
4262
|
-
if (!accepted) {
|
|
4263
|
-
waitingForDrain = true;
|
|
4264
|
-
stream.once("drain", onDrain);
|
|
4265
|
-
return;
|
|
4266
|
-
}
|
|
4267
|
-
}
|
|
4268
|
-
if (droppedLines > 0) {
|
|
4269
|
-
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
4270
|
-
`;
|
|
4271
|
-
droppedLines = 0;
|
|
4272
|
-
try {
|
|
4273
|
-
onDeliveryGap(line);
|
|
4274
|
-
} catch {
|
|
4275
|
-
}
|
|
4276
|
-
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
4277
|
-
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
4278
|
-
flush();
|
|
4279
|
-
}
|
|
4280
|
-
}
|
|
4281
|
-
stream.on("close", onTerminal);
|
|
4282
|
-
stream.on("finish", onTerminal);
|
|
4283
|
-
stream.on("error", onError);
|
|
4284
|
-
return (line) => {
|
|
4285
|
-
if (closed) return;
|
|
4286
|
-
const bytes = Buffer.byteLength(line, "utf8");
|
|
4287
|
-
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
4288
|
-
droppedLines += 1;
|
|
4289
|
-
scheduleFlush();
|
|
4290
|
-
return;
|
|
4291
|
-
}
|
|
4292
|
-
pending.push({ line, bytes });
|
|
4293
|
-
pendingBytes += bytes;
|
|
4294
|
-
scheduleFlush();
|
|
4295
|
-
};
|
|
4296
|
-
}
|
|
4297
|
-
|
|
4298
|
-
// host/service-log.ts
|
|
4299
|
-
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
4300
|
-
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
4301
|
-
void persistHostServiceLogLine(line);
|
|
4302
|
-
});
|
|
4303
|
-
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
4304
|
-
const details = diagnosticDetails(event, failure_kind, cause);
|
|
4305
|
-
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
4306
|
-
`;
|
|
4307
|
-
try {
|
|
4308
|
-
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
4309
|
-
} catch {
|
|
4310
|
-
}
|
|
4311
|
-
}
|
|
4312
|
-
function diagnosticDetails(event, failureKind, cause) {
|
|
4313
|
-
if (event === "watcher_scan_failed") return {
|
|
4314
|
-
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
4315
|
-
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
4316
|
-
};
|
|
4317
|
-
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
4318
|
-
}
|
|
4319
|
-
function validDiagnosticCause(cause, event) {
|
|
4320
|
-
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
4321
|
-
}
|
|
4322
|
-
function defaultHostServiceDiagnosticSink(line) {
|
|
4323
|
-
writeHostServiceLogLine(line);
|
|
4324
|
-
}
|
|
4325
|
-
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
4326
|
-
function writeHostServiceLogLine(line, environment = process.env) {
|
|
4327
|
-
void persistHostServiceLogLine(line, environment);
|
|
4328
|
-
defaultHostServiceLogDelivery(line);
|
|
4329
|
-
}
|
|
4330
|
-
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
4331
|
-
if (process.platform !== "win32") return;
|
|
4332
|
-
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
4333
|
-
if (path === void 0 || !win324.isAbsolute(path) || win324.normalize(path) !== path) return;
|
|
4334
|
-
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
4335
|
-
}
|
|
4336
|
-
async function appendHostServiceLogLine(path, line) {
|
|
4337
|
-
if (!isAbsolute(path)) return;
|
|
4338
|
-
await ensureHostServiceLogDirectory(path);
|
|
4339
|
-
await appendFile(path, line);
|
|
4340
|
-
}
|
|
4341
|
-
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
4342
|
-
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
4343
|
-
function ensureHostServiceLogDirectory(path) {
|
|
4344
|
-
const directory = dirname5(path);
|
|
4345
|
-
const existing = hostServiceLogDirectories.get(directory);
|
|
4346
|
-
if (existing !== void 0) return existing;
|
|
4347
|
-
const pending = mkdir3(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
4348
|
-
hostServiceLogDirectories.delete(directory);
|
|
4349
|
-
throw error;
|
|
4350
|
-
});
|
|
4351
|
-
hostServiceLogDirectories.set(directory, pending);
|
|
4352
|
-
return pending;
|
|
4353
|
-
}
|
|
4354
|
-
|
|
4355
4376
|
// host/relay/src/host-usage-facts-uploader.ts
|
|
4356
4377
|
var HostUsageFactsUploader = class {
|
|
4357
4378
|
options;
|
|
@@ -4370,7 +4391,7 @@ var HostUsageFactsUploader = class {
|
|
|
4370
4391
|
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);
|
|
4371
4392
|
const timeout = AbortSignal.timeout(this.options.timeout_ms ?? 5e3);
|
|
4372
4393
|
const requestSignal = signal === void 0 ? timeout : AbortSignal.any([signal, timeout]);
|
|
4373
|
-
const response2 = await
|
|
4394
|
+
const response2 = await this.options.fetch(`${registration.gateway_request_origin}${CEAL_HOST_USAGE_INGRESS_PATH}`, {
|
|
4374
4395
|
method: "POST",
|
|
4375
4396
|
headers: { authorization: `Bearer ${registration.host_access_token}`, "content-type": "application/json" },
|
|
4376
4397
|
body: JSON.stringify(candidate.batch),
|
|
@@ -4937,36 +4958,67 @@ var HostInvocationAuthenticationRefusal = class extends Error {
|
|
|
4937
4958
|
if (diagnosticCause !== void 0) this.diagnostic_cause = diagnosticCause;
|
|
4938
4959
|
}
|
|
4939
4960
|
};
|
|
4940
|
-
|
|
4961
|
+
var INSTALLED_HOST_INVOCATION_AUTHENTICATION_DEPENDENCIES = {
|
|
4962
|
+
process_elapsed_ms: () => performance.now(),
|
|
4963
|
+
load_pipe_key: async (outboxDirectory) => process.platform === "win32" ? loadRelayPipeKey(relayPipeStateRootForOutboxDir(outboxDirectory)) : void 0,
|
|
4964
|
+
create_relay_port: (endpoint, pipeKey, timeoutMs) => new HostRelayInvocationContextPort(endpoint, pipeKey, timeoutMs)
|
|
4965
|
+
};
|
|
4966
|
+
function installedHostInvocationAuthenticationCommandOptions(config, contextBudgetMs, maxContextWaitMs, dependencies) {
|
|
4941
4967
|
let pipeKey;
|
|
4942
4968
|
const loadPipeKey = () => {
|
|
4943
|
-
if (pipeKey === void 0) pipeKey =
|
|
4969
|
+
if (pipeKey === void 0) pipeKey = dependencies.load_pipe_key(config.outbox_dir);
|
|
4944
4970
|
return pipeKey;
|
|
4945
4971
|
};
|
|
4972
|
+
const remainingBudget = () => remainingAuthenticationBudget(contextBudgetMs, dependencies.process_elapsed_ms());
|
|
4946
4973
|
return {
|
|
4947
4974
|
host_source_ref: config.host_source_ref,
|
|
4948
4975
|
outbox_dir: config.outbox_dir,
|
|
4949
4976
|
producer_installation_ref: config.producer_installation_ref,
|
|
4950
|
-
context_activation_wait_ms: boundedContextActivationWait(
|
|
4951
|
-
|
|
4977
|
+
context_activation_wait_ms: boundedContextActivationWait(remainingBudget() ?? 0, config.ipc_timeout_ms, maxContextWaitMs),
|
|
4978
|
+
monotonic_now: dependencies.process_elapsed_ms,
|
|
4979
|
+
...dependencies.wait === void 0 ? {} : { wait: dependencies.wait },
|
|
4980
|
+
...dependencies.output_sink === void 0 ? {} : { output_sink: dependencies.output_sink },
|
|
4981
|
+
...dependencies.diagnostic_sink === void 0 ? {} : { diagnostic_sink: dependencies.diagnostic_sink },
|
|
4982
|
+
mint_invocation_context: async (input) => {
|
|
4983
|
+
requireMintExchangeTimeout(remainingBudget(), config.ipc_timeout_ms);
|
|
4984
|
+
const loadedPipeKey = await loadPipeKey();
|
|
4985
|
+
const timeoutMs = requireMintExchangeTimeout(remainingBudget(), config.ipc_timeout_ms);
|
|
4986
|
+
return dependencies.create_relay_port(config.relay_endpoint, loadedPipeKey, timeoutMs).mintInvocationContext(input);
|
|
4987
|
+
}
|
|
4952
4988
|
};
|
|
4953
4989
|
}
|
|
4954
|
-
|
|
4990
|
+
function remainingAuthenticationBudget(contextBudgetMs, processElapsedMs) {
|
|
4991
|
+
if (contextBudgetMs === void 0) return void 0;
|
|
4992
|
+
return Math.max(0, Math.floor(contextBudgetMs - processElapsedMs));
|
|
4993
|
+
}
|
|
4994
|
+
function requireMintExchangeTimeout(remainingBudgetMs, directTimeoutMs) {
|
|
4995
|
+
if (remainingBudgetMs === void 0) return directTimeoutMs;
|
|
4996
|
+
const timeoutMs = remainingBudgetMs - HOST_AUTHENTICATION_COMPLETION_RESERVE_MS;
|
|
4997
|
+
if (timeoutMs <= 0) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC timed out before minting could start.", "timed_out");
|
|
4998
|
+
return timeoutMs;
|
|
4999
|
+
}
|
|
5000
|
+
async function runHostInvocationAuthenticationCommand(descriptor, args, options, installedDependencies = INSTALLED_HOST_INVOCATION_AUTHENTICATION_DEPENDENCIES) {
|
|
4955
5001
|
let sink = options?.output_sink;
|
|
5002
|
+
let diagnosticSink = options?.diagnostic_sink;
|
|
4956
5003
|
try {
|
|
4957
|
-
const resolved = await resolveOptions(descriptor, args, options);
|
|
5004
|
+
const resolved = await resolveOptions(descriptor, args, options, installedDependencies);
|
|
4958
5005
|
sink = resolved.options.output_sink;
|
|
5006
|
+
diagnosticSink = resolved.options.diagnostic_sink;
|
|
4959
5007
|
writeResult(await authenticateHostInvocation(descriptor, resolved.input, resolved.options), sink);
|
|
4960
5008
|
return 0;
|
|
4961
5009
|
} catch (error) {
|
|
4962
|
-
|
|
4963
|
-
const refusal = error instanceof HostInvocationAuthenticationRefusal ? error : void 0;
|
|
4964
|
-
const gatewayStatus = refusal?.reason === "gateway_refused" && validGenericGatewayRefusalStatus2(refusal.gateway_status) ? refusal.gateway_status : void 0;
|
|
4965
|
-
writeHostServiceDiagnostic(descriptor.producer_id, "invocation_authentication_failed", void 0, refusal?.diagnostic_cause ?? reason, options?.diagnostic_sink);
|
|
4966
|
-
writeResult({ schema_version: CEAL_HOST_INVOCATION_AUTHENTICATION_REFUSAL_SCHEMA, ok: false, code: "invocation_authentication_unavailable", reason, ...gatewayStatus === void 0 ? {} : { gateway_status: gatewayStatus } }, sink);
|
|
4967
|
-
return 2;
|
|
5010
|
+
return writeAuthenticationFailure(descriptor.producer_id, error, sink, diagnosticSink);
|
|
4968
5011
|
}
|
|
4969
5012
|
}
|
|
5013
|
+
function writeAuthenticationFailure(producerId, error, sink, diagnosticSink) {
|
|
5014
|
+
const reason = authenticationRefusalReason(error);
|
|
5015
|
+
const refusal = error instanceof HostInvocationAuthenticationRefusal ? error : void 0;
|
|
5016
|
+
const gatewayStatus = refusal?.reason === "gateway_refused" && validGenericGatewayRefusalStatus2(refusal.gateway_status) ? refusal.gateway_status : void 0;
|
|
5017
|
+
const retryAfterMs = reason === "activation_wait_exhausted" ? INVOCATION_CONTEXT_POLL_INTERVAL_MS : void 0;
|
|
5018
|
+
writeHostServiceDiagnostic(producerId, "invocation_authentication_failed", void 0, refusal?.diagnostic_cause ?? reason, diagnosticSink);
|
|
5019
|
+
writeResult({ schema_version: CEAL_HOST_INVOCATION_AUTHENTICATION_REFUSAL_SCHEMA, ok: false, code: "invocation_authentication_unavailable", reason, ...gatewayStatus === void 0 ? {} : { gateway_status: gatewayStatus }, ...retryAfterMs === void 0 ? {} : { retry_after_ms: retryAfterMs } }, sink);
|
|
5020
|
+
return 2;
|
|
5021
|
+
}
|
|
4970
5022
|
function authenticationRefusalReason(error) {
|
|
4971
5023
|
const message = error instanceof Error ? error.message : "";
|
|
4972
5024
|
if (!REFUSAL_REASON_PATTERN.test(message)) return "host_refusal_invalid";
|
|
@@ -5030,8 +5082,7 @@ async function currentInvocation(descriptor, config, now) {
|
|
|
5030
5082
|
let waitEngaged = false;
|
|
5031
5083
|
while (true) {
|
|
5032
5084
|
if (!firstCheck && monotonicNow() >= deadline) {
|
|
5033
|
-
|
|
5034
|
-
throw new TypeError("context_unavailable");
|
|
5085
|
+
throw activationWaitExhausted(descriptor.producer_id, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
5035
5086
|
}
|
|
5036
5087
|
firstCheck = false;
|
|
5037
5088
|
const observedAt = now();
|
|
@@ -5043,8 +5094,7 @@ async function currentInvocation(descriptor, config, now) {
|
|
|
5043
5094
|
await rejectWhenActivationWaitIsUnavailable(descriptor, store, identity.identity, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
5044
5095
|
const remainingMs = deadline - monotonicNow();
|
|
5045
5096
|
if (remainingMs <= 0) {
|
|
5046
|
-
|
|
5047
|
-
throw new TypeError("context_unavailable");
|
|
5097
|
+
throw activationWaitExhausted(descriptor.producer_id, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
5048
5098
|
}
|
|
5049
5099
|
recordActivationWaitEngagement(descriptor.producer_id, waitEngaged, config.diagnostic_sink);
|
|
5050
5100
|
waitEngaged = true;
|
|
@@ -5052,9 +5102,13 @@ async function currentInvocation(descriptor, config, now) {
|
|
|
5052
5102
|
await (config.wait ?? waitForContextActivation)(intervalMs);
|
|
5053
5103
|
}
|
|
5054
5104
|
}
|
|
5105
|
+
function activationWaitExhausted(producerId, waitEngaged, waitBudgetMs, diagnosticSink) {
|
|
5106
|
+
recordActivationWaitExhaustion(producerId, waitEngaged, waitBudgetMs, diagnosticSink);
|
|
5107
|
+
return new TypeError(waitEngaged ? "activation_wait_exhausted" : "context_unavailable");
|
|
5108
|
+
}
|
|
5055
5109
|
async function rejectWhenActivationWaitIsUnavailable(descriptor, store, identity, waitEngaged, waitBudgetMs, sink) {
|
|
5056
|
-
if (waitEngaged || waitBudgetMs <= 0
|
|
5057
|
-
if (await descriptor.can_wait_for_context_activation({ store, identity })) return;
|
|
5110
|
+
if (waitEngaged || waitBudgetMs <= 0) return;
|
|
5111
|
+
if (descriptor.can_wait_for_context_activation !== void 0 && await descriptor.can_wait_for_context_activation({ store, identity })) return;
|
|
5058
5112
|
writeHostServiceDiagnostic(descriptor.producer_id, "activation_wait_skipped", void 0, void 0, sink);
|
|
5059
5113
|
throw new TypeError("context_unavailable");
|
|
5060
5114
|
}
|
|
@@ -5083,18 +5137,18 @@ function resolveIdentity(descriptor, options) {
|
|
|
5083
5137
|
if (isHostSessionId(sessionId)) return { status: "ready", identity: { host_source_ref: options.host_source_ref, host_session_ref: descriptor.session_ref(options.host_source_ref, sessionId) } };
|
|
5084
5138
|
return { status: "session_unavailable" };
|
|
5085
5139
|
}
|
|
5086
|
-
async function resolveOptions(descriptor, args, options) {
|
|
5140
|
+
async function resolveOptions(descriptor, args, options, installedDependencies) {
|
|
5087
5141
|
if (options !== void 0) return { input: [...args], options };
|
|
5088
5142
|
const configPath = descriptor.parse_config_flag(args);
|
|
5089
5143
|
const config = await descriptor.read_producer_config(configPath);
|
|
5090
5144
|
return {
|
|
5091
5145
|
input: args.filter((argument) => !argument.startsWith(`${descriptor.config_flag}=`)),
|
|
5092
|
-
options: installedHostInvocationAuthenticationCommandOptions(config, authenticationBudgetMsFromEnvironment(), descriptor.context_activation_wait_max_ms)
|
|
5146
|
+
options: installedHostInvocationAuthenticationCommandOptions(config, authenticationBudgetMsFromEnvironment(), descriptor.context_activation_wait_max_ms, installedDependencies)
|
|
5093
5147
|
};
|
|
5094
5148
|
}
|
|
5095
5149
|
function authenticationBudgetMsFromEnvironment() {
|
|
5096
5150
|
const value = process.env[CEAL_HOST_AUTHENTICATION_BUDGET_ENVIRONMENT];
|
|
5097
|
-
if (value === void 0) return 0;
|
|
5151
|
+
if (value === void 0) return void 0;
|
|
5098
5152
|
if (!CEAL_HOST_AUTHENTICATION_BUDGET_PATTERN.test(value)) throw new TypeError("invalid_arguments");
|
|
5099
5153
|
return Number(value);
|
|
5100
5154
|
}
|
|
@@ -6013,11 +6067,13 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6013
6067
|
}
|
|
6014
6068
|
async scanOpened(handle, registration) {
|
|
6015
6069
|
const { size, device, inode } = await ownedClaudeTranscriptFile(handle);
|
|
6016
|
-
const
|
|
6070
|
+
const preflight = await this.preflight(registration, handle, size, device, inode);
|
|
6071
|
+
const cursor = preflight.cursor;
|
|
6017
6072
|
if (cursor === null) return { records: 0, enqueued: 0, quarantined: true };
|
|
6018
6073
|
if (cursor.status === "quarantined") {
|
|
6019
6074
|
return { records: 0, enqueued: 0, quarantined: true };
|
|
6020
6075
|
}
|
|
6076
|
+
if (preflight.checkpointPending) await this.store.writeTranscriptCursor({ ...cursor, updated_at: this.stamp() });
|
|
6021
6077
|
const draft = mutableCursor(cursor);
|
|
6022
6078
|
await this.scanOpenedTranscript(registration, handle, draft, size, device, inode);
|
|
6023
6079
|
return { records: draft.consumed, enqueued: draft.enqueued, quarantined: false };
|
|
@@ -6030,6 +6086,15 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6030
6086
|
return { records: 0, enqueued: 0, quarantined: true };
|
|
6031
6087
|
}
|
|
6032
6088
|
async retireMissing(registration) {
|
|
6089
|
+
const observedAt = this.stamp();
|
|
6090
|
+
if (Date.parse(registration.expires_at) <= Date.parse(observedAt)) return this.retireTranscript(registration);
|
|
6091
|
+
const cursor = await this.store.readTranscriptCursor(registration);
|
|
6092
|
+
if (cursor !== null && isUnmaterializedCursor(cursor, this.sha(Buffer.alloc(0)))) {
|
|
6093
|
+
return { records: 0, enqueued: 0, quarantined: false };
|
|
6094
|
+
}
|
|
6095
|
+
return this.retireTranscript(registration);
|
|
6096
|
+
}
|
|
6097
|
+
retireTranscript(registration) {
|
|
6033
6098
|
return this.retireMissingTranscript(registration.transcript_path, "Claude", () => this.store.retireTranscriptRegistration(registration));
|
|
6034
6099
|
}
|
|
6035
6100
|
initialCursor(registration) {
|
|
@@ -6059,16 +6124,18 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6059
6124
|
}
|
|
6060
6125
|
async preflight(registration, handle, size, device, inode) {
|
|
6061
6126
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
6062
|
-
if (existing?.status === "quarantined") return existing;
|
|
6127
|
+
if (existing?.status === "quarantined") return { cursor: existing, checkpointPending: false };
|
|
6063
6128
|
const cursor = existing ?? this.initialCursor(registration);
|
|
6064
6129
|
if (cursor.device === void 0) {
|
|
6065
|
-
|
|
6066
|
-
|
|
6130
|
+
const pinned = { ...cursor, device, inode, human_message_window: cursor.human_message_window ?? { messages: [], truncated: false } };
|
|
6131
|
+
const reason2 = this.cursorIdentityReason(pinned, registration.transcript_path, device, inode);
|
|
6132
|
+
if (cursor.offset !== 0 || reason2 !== null) return { cursor: await this.quarantineStored(cursor, device, inode, "transcript_replaced"), checkpointPending: false };
|
|
6133
|
+
return { cursor: pinned, checkpointPending: true };
|
|
6067
6134
|
}
|
|
6068
6135
|
const reason = this.cursorIdentityReason(cursor, registration.transcript_path, device, inode) ?? await this.cursorBoundsReason(handle, cursor, size);
|
|
6069
|
-
if (reason !== null) return await this.quarantineStored(cursor, device, inode, reason);
|
|
6070
|
-
if (cursor.human_message_window !== void 0) return cursor;
|
|
6071
|
-
return { ...cursor, human_message_window: await this.readHumanMessageProjection(registration, handle, cursor.offset) };
|
|
6136
|
+
if (reason !== null) return { cursor: await this.quarantineStored(cursor, device, inode, reason), checkpointPending: false };
|
|
6137
|
+
if (cursor.human_message_window !== void 0) return { cursor, checkpointPending: false };
|
|
6138
|
+
return { cursor: { ...cursor, human_message_window: await this.readHumanMessageProjection(registration, handle, cursor.offset) }, checkpointPending: true };
|
|
6072
6139
|
}
|
|
6073
6140
|
async readHumanMessageProjection(registration, handle, watermark) {
|
|
6074
6141
|
let offset = 0;
|
|
@@ -6365,6 +6432,9 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6365
6432
|
return await this.store.readTranscriptCursor(registration).catch(() => null) ?? this.initialCursor(registration);
|
|
6366
6433
|
}
|
|
6367
6434
|
};
|
|
6435
|
+
function isUnmaterializedCursor(cursor, emptyAnchorSha256) {
|
|
6436
|
+
return cursor.status === "active" && cursor.device === void 0 && cursor.inode === void 0 && cursor.offset === 0 && cursor.anchor_start === 0 && cursor.anchor_sha256 === emptyAnchorSha256;
|
|
6437
|
+
}
|
|
6368
6438
|
function mutableCursor(cursor) {
|
|
6369
6439
|
return {
|
|
6370
6440
|
offset: cursor.offset,
|
|
@@ -6900,9 +6970,9 @@ var CLAUDE_PRODUCER_DESCRIPTOR = {
|
|
|
6900
6970
|
config: (shared, extras) => ({ ...shared, claude_transcripts_root: hostProducerExtraPath(extras, CLAUDE_TRANSCRIPTS_ROOT) }),
|
|
6901
6971
|
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir }),
|
|
6902
6972
|
drain: drainClaudeProducerOnce,
|
|
6903
|
-
background: (config, signal) => {
|
|
6973
|
+
background: (config, signal, dependencies) => {
|
|
6904
6974
|
const capturer = new ClaudeUsageFactsCapturer({ outbox_dir: config.outbox_dir });
|
|
6905
|
-
return runHostUsageFactsUploader({ producer: "claude", outbox_dir: config.outbox_dir, host_source_ref: config.host_source_ref, registration_state_file: hostProducerRegistrationStateFile(config.outbox_dir), capture_next: () => capturer.captureNext() }, signal);
|
|
6975
|
+
return runHostUsageFactsUploader({ producer: "claude", 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);
|
|
6906
6976
|
}
|
|
6907
6977
|
};
|
|
6908
6978
|
|