@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
|
@@ -2032,6 +2032,18 @@ var require_toml = __commonJS({
|
|
|
2032
2032
|
}
|
|
2033
2033
|
});
|
|
2034
2034
|
|
|
2035
|
+
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
2036
|
+
function vocabulary(words) {
|
|
2037
|
+
return Object.freeze(words);
|
|
2038
|
+
}
|
|
2039
|
+
function isVocabularyWord(words, value) {
|
|
2040
|
+
return words.some((word) => word === value);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// packages/ceal-client-protocol/src/host-usage-fields.ts
|
|
2044
|
+
var CEAL_CODEX_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"]);
|
|
2045
|
+
var CEAL_CLAUDE_USAGE_COUNT_FIELDS = vocabulary(["input_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "output_tokens"]);
|
|
2046
|
+
|
|
2035
2047
|
// packages/ceal-client-protocol/src/canonical-json.ts
|
|
2036
2048
|
function cealCanonicalJson(value) {
|
|
2037
2049
|
if (value === null || typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
@@ -2206,8 +2218,11 @@ var client_wire_contract_default = {
|
|
|
2206
2218
|
"ok",
|
|
2207
2219
|
"code",
|
|
2208
2220
|
"reason",
|
|
2209
|
-
"gateway_status"
|
|
2221
|
+
"gateway_status",
|
|
2222
|
+
"retry_after_ms"
|
|
2210
2223
|
],
|
|
2224
|
+
refusal_required_fields: ["schema_version", "ok", "code", "reason"],
|
|
2225
|
+
refusal_optional_fields: ["gateway_status", "retry_after_ms"],
|
|
2211
2226
|
client_nonce: {
|
|
2212
2227
|
character_class_source: "A-Za-z0-9_-",
|
|
2213
2228
|
encoded_characters: 43
|
|
@@ -2426,14 +2441,6 @@ var CEAL_OPERATION_WITHHELD_NEXT_ACTIONS = Object.freeze({
|
|
|
2426
2441
|
personal_authorization_required: "connect_personal_account"
|
|
2427
2442
|
});
|
|
2428
2443
|
|
|
2429
|
-
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
2430
|
-
function vocabulary(words) {
|
|
2431
|
-
return Object.freeze(words);
|
|
2432
|
-
}
|
|
2433
|
-
function isVocabularyWord(words, value) {
|
|
2434
|
-
return words.some((word) => word === value);
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
2444
|
// packages/ceal-client-protocol/src/gateway-response-types.ts
|
|
2438
2445
|
var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavailable", "unknown"]);
|
|
2439
2446
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
@@ -2837,7 +2844,7 @@ var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask a
|
|
|
2837
2844
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
2838
2845
|
var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Relay to the same release as the Gateway, then retry.";
|
|
2839
2846
|
var HOST_INSTALL_REPAIR = "The local Host or Relay is missing, stale, or unavailable. Run `ceal-host install`, then `ceal-host discovery sync`, and retry from a new producer conversation.";
|
|
2840
|
-
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select
|
|
2847
|
+
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select this turn; reason uncertain. Host mode is unavailable in an ephemeral side conversation. When you know you are in one, `ceal --standalone ...` uses your configured Ceal session/Gateway permissions, without Host session/turn correlation or Host usage attribution. Unknown-outcome `repeat_request` needs the same Host turn or explicit `--request-context`. Otherwise return to the original regular conversation. Host refusal never switches modes; report intended Host calls as a gap.";
|
|
2841
2848
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
2842
2849
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
2843
2850
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
@@ -2889,14 +2896,12 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
2889
2896
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
2890
2897
|
internal_error: guidance("The Gateway failed without exposing internal state.", "answer_with_gap", 500),
|
|
2891
2898
|
// Owned by the Gateway canonical adapter (`gateway/core/src/gateway-canonical-operation-http-adapter.ts`):
|
|
2892
|
-
// the client variant
|
|
2899
|
+
// the static client variant was retired when the client started reading this table.
|
|
2893
2900
|
request_body_too_large: guidance("The Gateway request body exceeds its bounded limit.", "reduce_request_size", 413),
|
|
2894
2901
|
gateway_response_too_large: guidance("The Gateway response exceeds its bounded limit; reduce the requested page or result size.", "reduce_request_size", 500),
|
|
2895
|
-
//
|
|
2896
|
-
//
|
|
2897
|
-
|
|
2898
|
-
// forbids the safe read retry the sentence exists to allow.
|
|
2899
|
-
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),
|
|
2902
|
+
// The safe move varies by request. Keep the sentence conditional on the
|
|
2903
|
+
// same `retryable` and `next_action` facts the response exposes.
|
|
2904
|
+
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
2900
2905
|
// Restored verbatim from the retired `localFailureText`
|
|
2901
2906
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
2902
2907
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -2977,8 +2982,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
2977
2982
|
// Host mint classifications. The CLI emits `invocation_authentication_unavailable` with the classification
|
|
2978
2983
|
// in its detail fact; rows without their own sentence share that code's moved sentence, while `next_action`
|
|
2979
2984
|
// is moved from `canonicalHostAuthenticationNextActions` (generated from `CEAL_HOST_AUTHENTICATION_POLICY`)
|
|
2980
|
-
// and `retryable` from `hostAuthenticationFailureForCause` (
|
|
2981
|
-
// sentences carry the
|
|
2985
|
+
// and `retryable` from `hostAuthenticationFailureForCause` (the table's explicit retry verdict). Cause-specific
|
|
2986
|
+
// sentences carry only remedies proved by the Host or Relay cause; generic Gateway refusals do not prove a release mismatch.
|
|
2982
2987
|
// Statuses are the
|
|
2983
2988
|
// Gateway-owned mapping decided with the operator 2026-10-13. This covers every wire cause the maps at
|
|
2984
2989
|
// `host/invocation-authentication-command.ts:217-242` emit, through their policy classifications.
|
|
@@ -2988,21 +2993,23 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
2988
2993
|
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
2989
2994
|
// changes mode; standalone remains the separate Client authority path.
|
|
2990
2995
|
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "answer_with_gap", 401),
|
|
2991
|
-
|
|
2992
|
-
|
|
2996
|
+
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),
|
|
2997
|
+
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),
|
|
2998
|
+
host_invocation_context_expired: guidance("The Host invocation context expired before authentication completed. This invocation cannot be retried in the expired turn; report it as a gap.", "answer_with_gap", 401),
|
|
2993
2999
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
2994
3000
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
2995
3001
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
2996
3002
|
host_mint_gateway_rate_limited: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 429),
|
|
2997
|
-
host_mint_gateway_refused: guidance(
|
|
3003
|
+
host_mint_gateway_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
2998
3004
|
host_mint_gateway_response_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
3005
|
+
host_contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 502),
|
|
2999
3006
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
3000
3007
|
// producer-frame fault names the administrator repair step.
|
|
3001
3008
|
host_producer_frame_invalid: guidance("Ask an administrator to inspect and repair the producer frame, then start a fresh Host turn.", "ask_admin", 400),
|
|
3002
3009
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
3003
3010
|
// sandboxed Relay socket names the run-alone retry.
|
|
3004
3011
|
host_relay_permission_denied: guidance("An agent sandbox denied the Host Relay socket; run `ceal` as the only command, with no pipe, redirect, or `&&`, so the Host allow rule runs it outside the sandbox.", "rerun_outside_agent_sandbox", 403),
|
|
3005
|
-
host_relay_unavailable: guidance(
|
|
3012
|
+
host_relay_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 503),
|
|
3006
3013
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
3007
3014
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
3008
3015
|
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
@@ -3045,7 +3052,7 @@ var UNKNOWN_OUTCOMES = vocabulary(["reconcile", "operator_action", "excluded"]);
|
|
|
3045
3052
|
var RECOVERY_OWNERS = vocabulary(["gateway", "connector", "operator"]);
|
|
3046
3053
|
var CEAL_OPERATION_ADMISSION_STATES = vocabulary(["proposed", "refused", "admitted"]);
|
|
3047
3054
|
var CEAL_OPERATION_EXECUTION_STATES = vocabulary(["not_started", "started", "completed"]);
|
|
3048
|
-
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
3055
|
+
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_applicable", "not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
3049
3056
|
var CEAL_OPERATION_EFFECT_STATES = vocabulary(["none", "applied", "failed", "unknown", "compensated"]);
|
|
3050
3057
|
var CEAL_OPERATION_OBSERVATION_STATES = vocabulary(["not_started", "not_required", "pending", "observed", "unavailable"]);
|
|
3051
3058
|
var CEAL_OPERATION_RECOVERY_KINDS = vocabulary(["none", "reconcile", "compensate", "operator_action"]);
|
|
@@ -3228,6 +3235,7 @@ var CEAL_OPERATION_ACCESS_CLASSES = vocabulary(["read", "write"]);
|
|
|
3228
3235
|
// packages/ceal-client-protocol/src/domain-vocabulary.ts
|
|
3229
3236
|
var CEAL_CONNECTOR_STATUSES = vocabulary(["active", "disabled", "disconnected"]);
|
|
3230
3237
|
var CEAL_CONNECTOR_CUSTODIES = vocabulary(["organization", "personal"]);
|
|
3238
|
+
var CEAL_PROVIDER_BOUNDARY_FIELDS = vocabulary(["provider_boundary_ref", "provider_boundary_kind", "provider_boundary_label", "provider_native_id", "provider_boundary_evidence"]);
|
|
3231
3239
|
var CEAL_PERSONAL_ACCESS_CEILINGS = vocabulary(["disabled", "read", "read_write"]);
|
|
3232
3240
|
var CEAL_TARGET_REF_PATTERN = "^[^\\p{Cc}]+$";
|
|
3233
3241
|
var TARGET_REF = new RegExp(CEAL_TARGET_REF_PATTERN, "u");
|
|
@@ -3273,7 +3281,7 @@ var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
|
3273
3281
|
var CEAL_OPERATION_AUTHORITY_POLICY_KEYS = Object.freeze(["access_group", "instance_binding", "target", "admission_recheck"]);
|
|
3274
3282
|
var MAX_OPERATION_INPUT_RESOLVER_BINDINGS = 96;
|
|
3275
3283
|
var CEAL_OPERATION_DESCRIPTOR_REQUIRED_ENVELOPE_KEYS = Object.freeze(["schema_version", "id", "input_contract", "result_contract", "policy"]);
|
|
3276
|
-
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary"]);
|
|
3284
|
+
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary", "standard_names"]);
|
|
3277
3285
|
|
|
3278
3286
|
// packages/ceal-client-protocol/src/operation-catalog.ts
|
|
3279
3287
|
var CEAL_OPERATION_CATALOG_SCHEMA_VERSION = "ceal.catalog.v3";
|
|
@@ -3369,6 +3377,7 @@ var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
|
3369
3377
|
gateway_access_group_connector_activity_scope_audit: (root) => join(root, "profile-connector-activity-scope-audit.jsonl"),
|
|
3370
3378
|
gateway_access_group_connector_calendar_scope_audit: (root) => join(root, "profile-connector-calendar-scope-audit.jsonl"),
|
|
3371
3379
|
gateway_access_group_connector_readiness_audit: (root) => join(root, "profile-connector-readiness.audit.jsonl"),
|
|
3380
|
+
gateway_deployment_events: (root) => join(root, "gateway-deployments.jsonl"),
|
|
3372
3381
|
gateway_organization_audit_ledger: (root) => join(root, "organization-ledger.jsonl"),
|
|
3373
3382
|
gateway_personal_client_audit: (root) => join(root, "audit.jsonl"),
|
|
3374
3383
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
@@ -3398,6 +3407,11 @@ var CEAL_HOST_INSTALLATION_REF_PATTERN = new RegExp(`^host-installation:${CEAL_L
|
|
|
3398
3407
|
var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUID_PATTERN}$`, "u");
|
|
3399
3408
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
3400
3409
|
|
|
3410
|
+
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
3411
|
+
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
3412
|
+
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
3413
|
+
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
3414
|
+
|
|
3401
3415
|
// packages/ceal-client-protocol/src/operation-result-completeness.ts
|
|
3402
3416
|
var CEAL_READ_VALUE_CONTINUATION_KEYS = vocabulary(["continuation", "continuation_ref", "next_cursor"]);
|
|
3403
3417
|
|
|
@@ -3482,6 +3496,7 @@ var PROVIDER_LINK_CONFORMANCE_TABLE = Object.freeze([
|
|
|
3482
3496
|
{ provider: "google-workspace", result_kind: "calendar_event_read_row", field: "source_url", status: "required_when_provider_supplies", provider_shape: "htmlLink", source: "https://developers.google.com/workspace/calendar/api/v3/reference/events" },
|
|
3483
3497
|
{ provider: "google-workspace", result_kind: "drive_document_calendar_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "verified readback webViewLink or htmlLink", source: "https://developers.google.com/workspace/drive/api/reference/rest/v3/files" },
|
|
3484
3498
|
{ 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" },
|
|
3499
|
+
{ provider: "google-workspace", result_kind: "form_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "verified Forms responderUri", source: "https://developers.google.com/workspace/forms/api/reference/rest/v1/forms" },
|
|
3485
3500
|
{ provider: "google-workspace", result_kind: "spreadsheet_write_result", field: "spreadsheet_url", status: "required_when_provider_supplies", provider_shape: "verified readback webViewLink", source: "https://developers.google.com/workspace/drive/api/reference/rest/v3/files" },
|
|
3486
3501
|
{ provider: "google-workspace", result_kind: "calendar_meet_link_write_result", field: "meet_url", status: "required_when_provider_supplies", provider_shape: "verified conferenceData entryPoint uri", source: "https://developers.google.com/workspace/calendar/api/v3/reference/events" },
|
|
3487
3502
|
{ 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" },
|
|
@@ -3651,6 +3666,7 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
3651
3666
|
created_at: { required: false, timestamp: true },
|
|
3652
3667
|
created_at_local: { required: false, timestamp: true },
|
|
3653
3668
|
modified_at: { required: false, timestamp: true },
|
|
3669
|
+
observed_at: { required: false, timestamp: true },
|
|
3654
3670
|
modified_at_local: { required: false, timestamp: true },
|
|
3655
3671
|
viewed_by_me_at: { required: false, timestamp: true },
|
|
3656
3672
|
modified_by_me_at: { required: false, timestamp: true },
|
|
@@ -3678,9 +3694,6 @@ var RESOURCE_ROW_REQUIRED_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(
|
|
|
3678
3694
|
var RESOURCE_ROW_KEYS = new Set(Object.keys(RESOURCE_ROW_KEY_RULES));
|
|
3679
3695
|
var RESOURCE_ROW_TIMESTAMP_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(([key, rule]) => rule.timestamp ? [key] : []);
|
|
3680
3696
|
|
|
3681
|
-
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
3682
|
-
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
3683
|
-
|
|
3684
3697
|
// packages/ceal-client-protocol/src/excluded-target-coverage.ts
|
|
3685
3698
|
var CEAL_EXCLUDED_TARGET_COVERAGE_MAX_ENTRIES = 64;
|
|
3686
3699
|
function cealExcludedTargetCoverageJsonSchema() {
|
|
@@ -3987,7 +4000,7 @@ function validateBatchContents(value) {
|
|
|
3987
4000
|
if (facts.length === 0 && gaps.length === 0 || facts.length > 0 && value.source_ranges.length === 0) invalid("Ceal Host usage coverage is invalid.");
|
|
3988
4001
|
const sourceFiles = new Set(value.source_ranges.map((range) => sourceRangeFileRef(range)));
|
|
3989
4002
|
for (const fact of facts) {
|
|
3990
|
-
|
|
4003
|
+
validateCealHostUsageFact(fact, value.host_session_ref);
|
|
3991
4004
|
if (!sourceFiles.has(fact.source_file_ref)) invalid("Ceal Host usage fact is outside its source ranges.");
|
|
3992
4005
|
}
|
|
3993
4006
|
for (const gap of gaps) {
|
|
@@ -4020,7 +4033,7 @@ function hostUsageSourceFileReference(producer, hostSourceRef, hostSessionRef, d
|
|
|
4020
4033
|
for (const part of [producer, hostSourceRef, hostSessionRef, device, inode]) if (typeof part !== "string" || part.length === 0 || part.length > 512) invalid("Ceal Host usage file identity is invalid.");
|
|
4021
4034
|
return `host-source-file:${sha256(JSON.stringify({ producer, host_source_ref: hostSourceRef, host_session_ref: hostSessionRef, device, inode }))}`;
|
|
4022
4035
|
}
|
|
4023
|
-
function
|
|
4036
|
+
function validateCealHostUsageFact(value, sessionRef) {
|
|
4024
4037
|
if (!isOperationRecord(value)) invalid("Ceal Host usage fact is invalid.");
|
|
4025
4038
|
requireFactByteLimit(value);
|
|
4026
4039
|
if (value.producer === "codex_transcript") validateCodexFact(value);
|
|
@@ -4084,7 +4097,7 @@ function validCorrectionSemantics(value) {
|
|
|
4084
4097
|
}
|
|
4085
4098
|
function validateCodexUsageCounts(value) {
|
|
4086
4099
|
if (!isOperationRecord(value)) invalid("Ceal Codex usage fields are invalid.");
|
|
4087
|
-
requireExactOperationKeys(value,
|
|
4100
|
+
requireExactOperationKeys(value, CEAL_CODEX_USAGE_COUNT_FIELDS);
|
|
4088
4101
|
for (const key of Object.keys(value)) if (!safeInteger(value[key])) invalid("Ceal Codex usage fields are invalid.");
|
|
4089
4102
|
if (Number(value.total_tokens) !== Number(value.input_tokens) + Number(value.output_tokens) || Number(value.cached_input_tokens) + Number(value.cache_write_input_tokens) > Number(value.input_tokens) || Number(value.reasoning_output_tokens) > Number(value.output_tokens)) invalid("Ceal Codex usage fields are inconsistent.");
|
|
4090
4103
|
}
|
|
@@ -4404,6 +4417,7 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
4404
4417
|
"options_invalid",
|
|
4405
4418
|
"session_unavailable",
|
|
4406
4419
|
"context_unavailable",
|
|
4420
|
+
"activation_wait_exhausted",
|
|
4407
4421
|
"context_replaced",
|
|
4408
4422
|
"no_binding",
|
|
4409
4423
|
"context_expired",
|
|
@@ -4439,22 +4453,23 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
4439
4453
|
// This reason cannot distinguish a Codex side conversation from a missing
|
|
4440
4454
|
// context in a regular session, so guidance must leave that choice to the caller.
|
|
4441
4455
|
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "answer_with_gap" }),
|
|
4442
|
-
|
|
4456
|
+
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
4457
|
+
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
4443
4458
|
// `no_binding` now means the producer has no real current Host session. The
|
|
4444
4459
|
// Host Relay never uses it for an uncreated Gateway Request; there is no
|
|
4445
4460
|
// useful retry until the consumer is running inside a Host session.
|
|
4446
4461
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
4447
|
-
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "
|
|
4462
|
+
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
4448
4463
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
4449
4464
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
4450
4465
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
4451
4466
|
gateway_rate_limited: Object.freeze({ classification: "host_mint_gateway_rate_limited", next_action: "answer_with_gap" }),
|
|
4452
|
-
contract_mismatch: Object.freeze({ classification: "
|
|
4453
|
-
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "
|
|
4467
|
+
contract_mismatch: Object.freeze({ classification: "host_contract_mismatch", next_action: "upgrade_ceal_client" }),
|
|
4468
|
+
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "answer_with_gap" }),
|
|
4454
4469
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
4455
4470
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
4456
4471
|
relay_permission_denied: Object.freeze({ classification: "host_relay_permission_denied", next_action: "rerun_outside_agent_sandbox" }),
|
|
4457
|
-
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "
|
|
4472
|
+
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "answer_with_gap" }),
|
|
4458
4473
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
4459
4474
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
4460
4475
|
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
@@ -4537,7 +4552,7 @@ function isCealHostServiceDiagnosticCause(value, event) {
|
|
|
4537
4552
|
// packages/ceal-client-protocol/src/client-result-materialization.ts
|
|
4538
4553
|
var CEAL_UNREAD_REASONS = vocabulary(["blocked", "unavailable", "too_large", "unsupported", "download_failed", "permission_denied"]);
|
|
4539
4554
|
var REQUIRED_FIELDS2 = Object.freeze(["schema_version", "operation_id", "path", "sha256"]);
|
|
4540
|
-
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "
|
|
4555
|
+
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "local_result_root", "request_context_argv", "how_to_read"]);
|
|
4541
4556
|
|
|
4542
4557
|
// packages/ceal-client-protocol/src/discovery-manifest.ts
|
|
4543
4558
|
var DISCOVERY_MANIFEST_KEYS = CEAL_CLIENT_WIRE_CONTRACT.command_response.discovery_manifest_fields;
|
|
@@ -5132,7 +5147,7 @@ async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
|
5132
5147
|
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
5133
5148
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
5134
5149
|
return await new Promise((resolve, reject2) => {
|
|
5135
|
-
const child = execFile2(executable, processArgs, { encoding: "buffer", timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
5150
|
+
const child = execFile2(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
5136
5151
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
5137
5152
|
if (exitCode === null) {
|
|
5138
5153
|
reject2(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -5183,6 +5198,185 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
5183
5198
|
return entry.isDirectory() && !entry.isSymbolicLink() && isSelfOwned(entry.uid, platform) && isPrivateFileMode(entry.mode, platform);
|
|
5184
5199
|
}
|
|
5185
5200
|
|
|
5201
|
+
// host/service-log.ts
|
|
5202
|
+
import { copyFile, mkdir, stat as stat2, truncate, appendFile } from "node:fs/promises";
|
|
5203
|
+
import { dirname as dirname2, isAbsolute as isAbsolute2, posix, win32 as win323 } from "node:path";
|
|
5204
|
+
|
|
5205
|
+
// host/service-log-delivery.ts
|
|
5206
|
+
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
5207
|
+
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
5208
|
+
setImmediate(flush);
|
|
5209
|
+
}, onDeliveryGap = () => void 0) {
|
|
5210
|
+
const pending = [];
|
|
5211
|
+
const highWaterMark = stream.writableHighWaterMark;
|
|
5212
|
+
const byteBudget = highWaterMark + highWaterMark;
|
|
5213
|
+
let pendingBytes = 0;
|
|
5214
|
+
let droppedLines = 0;
|
|
5215
|
+
let flushScheduled = false;
|
|
5216
|
+
let waitingForDrain = false;
|
|
5217
|
+
let closed = !stream.writable;
|
|
5218
|
+
function stop() {
|
|
5219
|
+
if (closed) return;
|
|
5220
|
+
closed = true;
|
|
5221
|
+
pending.length = 0;
|
|
5222
|
+
pendingBytes = 0;
|
|
5223
|
+
stream.off("drain", onDrain);
|
|
5224
|
+
stream.off("close", onTerminal);
|
|
5225
|
+
stream.off("finish", onTerminal);
|
|
5226
|
+
stream.off("error", onError);
|
|
5227
|
+
}
|
|
5228
|
+
function onTerminal() {
|
|
5229
|
+
stop();
|
|
5230
|
+
}
|
|
5231
|
+
function onError() {
|
|
5232
|
+
stop();
|
|
5233
|
+
}
|
|
5234
|
+
function onDrain() {
|
|
5235
|
+
waitingForDrain = false;
|
|
5236
|
+
scheduleFlush();
|
|
5237
|
+
}
|
|
5238
|
+
function scheduleFlush() {
|
|
5239
|
+
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
5240
|
+
flushScheduled = true;
|
|
5241
|
+
let scheduling = true;
|
|
5242
|
+
let invokedSynchronously = false;
|
|
5243
|
+
try {
|
|
5244
|
+
schedule(() => {
|
|
5245
|
+
if (scheduling) {
|
|
5246
|
+
invokedSynchronously = true;
|
|
5247
|
+
return;
|
|
5248
|
+
}
|
|
5249
|
+
flushScheduled = false;
|
|
5250
|
+
flush();
|
|
5251
|
+
});
|
|
5252
|
+
} catch {
|
|
5253
|
+
flushScheduled = false;
|
|
5254
|
+
stop();
|
|
5255
|
+
return;
|
|
5256
|
+
}
|
|
5257
|
+
scheduling = false;
|
|
5258
|
+
if (invokedSynchronously) {
|
|
5259
|
+
flushScheduled = false;
|
|
5260
|
+
stop();
|
|
5261
|
+
}
|
|
5262
|
+
}
|
|
5263
|
+
function flush() {
|
|
5264
|
+
if (closed) return;
|
|
5265
|
+
if (!stream.writable) {
|
|
5266
|
+
stop();
|
|
5267
|
+
return;
|
|
5268
|
+
}
|
|
5269
|
+
while (pending.length > 0) {
|
|
5270
|
+
if (stream.writableNeedDrain) {
|
|
5271
|
+
if (!waitingForDrain) {
|
|
5272
|
+
waitingForDrain = true;
|
|
5273
|
+
stream.once("drain", onDrain);
|
|
5274
|
+
}
|
|
5275
|
+
return;
|
|
5276
|
+
}
|
|
5277
|
+
const next = pending.shift();
|
|
5278
|
+
if (next === void 0) return;
|
|
5279
|
+
pendingBytes -= next.bytes;
|
|
5280
|
+
let accepted;
|
|
5281
|
+
try {
|
|
5282
|
+
accepted = stream.write(next.line);
|
|
5283
|
+
} catch {
|
|
5284
|
+
stop();
|
|
5285
|
+
return;
|
|
5286
|
+
}
|
|
5287
|
+
if (!accepted) {
|
|
5288
|
+
waitingForDrain = true;
|
|
5289
|
+
stream.once("drain", onDrain);
|
|
5290
|
+
return;
|
|
5291
|
+
}
|
|
5292
|
+
}
|
|
5293
|
+
if (droppedLines > 0) {
|
|
5294
|
+
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
5295
|
+
`;
|
|
5296
|
+
droppedLines = 0;
|
|
5297
|
+
try {
|
|
5298
|
+
onDeliveryGap(line);
|
|
5299
|
+
} catch {
|
|
5300
|
+
}
|
|
5301
|
+
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
5302
|
+
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
5303
|
+
flush();
|
|
5304
|
+
}
|
|
5305
|
+
}
|
|
5306
|
+
stream.on("close", onTerminal);
|
|
5307
|
+
stream.on("finish", onTerminal);
|
|
5308
|
+
stream.on("error", onError);
|
|
5309
|
+
return (line) => {
|
|
5310
|
+
if (closed) return;
|
|
5311
|
+
const bytes = Buffer.byteLength(line, "utf8");
|
|
5312
|
+
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
5313
|
+
droppedLines += 1;
|
|
5314
|
+
scheduleFlush();
|
|
5315
|
+
return;
|
|
5316
|
+
}
|
|
5317
|
+
pending.push({ line, bytes });
|
|
5318
|
+
pendingBytes += bytes;
|
|
5319
|
+
scheduleFlush();
|
|
5320
|
+
};
|
|
5321
|
+
}
|
|
5322
|
+
|
|
5323
|
+
// host/service-log.ts
|
|
5324
|
+
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
5325
|
+
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
5326
|
+
void persistHostServiceLogLine(line);
|
|
5327
|
+
});
|
|
5328
|
+
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
5329
|
+
const details = diagnosticDetails(event, failure_kind, cause);
|
|
5330
|
+
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
5331
|
+
`;
|
|
5332
|
+
try {
|
|
5333
|
+
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
5334
|
+
} catch {
|
|
5335
|
+
}
|
|
5336
|
+
}
|
|
5337
|
+
function diagnosticDetails(event, failureKind, cause) {
|
|
5338
|
+
if (event === "watcher_scan_failed") return {
|
|
5339
|
+
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
5340
|
+
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
5341
|
+
};
|
|
5342
|
+
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
5343
|
+
}
|
|
5344
|
+
function validDiagnosticCause(cause, event) {
|
|
5345
|
+
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
5346
|
+
}
|
|
5347
|
+
function defaultHostServiceDiagnosticSink(line) {
|
|
5348
|
+
writeHostServiceLogLine(line);
|
|
5349
|
+
}
|
|
5350
|
+
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
5351
|
+
function writeHostServiceLogLine(line, environment = process.env) {
|
|
5352
|
+
void persistHostServiceLogLine(line, environment);
|
|
5353
|
+
defaultHostServiceLogDelivery(line);
|
|
5354
|
+
}
|
|
5355
|
+
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
5356
|
+
if (process.platform !== "win32") return;
|
|
5357
|
+
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
5358
|
+
if (path === void 0 || !win323.isAbsolute(path) || win323.normalize(path) !== path) return;
|
|
5359
|
+
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
5360
|
+
}
|
|
5361
|
+
async function appendHostServiceLogLine(path, line) {
|
|
5362
|
+
if (!isAbsolute2(path)) return;
|
|
5363
|
+
await ensureHostServiceLogDirectory(path);
|
|
5364
|
+
await appendFile(path, line);
|
|
5365
|
+
}
|
|
5366
|
+
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
5367
|
+
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
5368
|
+
function ensureHostServiceLogDirectory(path) {
|
|
5369
|
+
const directory = dirname2(path);
|
|
5370
|
+
const existing = hostServiceLogDirectories.get(directory);
|
|
5371
|
+
if (existing !== void 0) return existing;
|
|
5372
|
+
const pending = mkdir(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
5373
|
+
hostServiceLogDirectories.delete(directory);
|
|
5374
|
+
throw error;
|
|
5375
|
+
});
|
|
5376
|
+
hostServiceLogDirectories.set(directory, pending);
|
|
5377
|
+
return pending;
|
|
5378
|
+
}
|
|
5379
|
+
|
|
5186
5380
|
// host/relay/src/host-producer-core.ts
|
|
5187
5381
|
var HOST_TRANSCRIPT_CURSOR_REASONS = vocabulary(["transcript_replaced", "transcript_truncated", "transcript_rewritten", "transcript_malformed"]);
|
|
5188
5382
|
function isHostTranscriptCursorReason(value) {
|
|
@@ -5344,7 +5538,7 @@ function createTranscriptWatcherBase(options, owner) {
|
|
|
5344
5538
|
outboxRetentionMs: options.retention_ms ?? owner.default_retention_ms,
|
|
5345
5539
|
now: options.now ?? (() => /* @__PURE__ */ new Date()),
|
|
5346
5540
|
log: options.log ?? ((line) => {
|
|
5347
|
-
|
|
5541
|
+
writeHostServiceLogLine(`${line}
|
|
5348
5542
|
`);
|
|
5349
5543
|
}),
|
|
5350
5544
|
producerInstallationRef: options.producer_installation_ref
|
|
@@ -5384,7 +5578,13 @@ var HostTranscriptWatcher = class {
|
|
|
5384
5578
|
}
|
|
5385
5579
|
async scanRegistration(registration) {
|
|
5386
5580
|
return this.openTranscript(registration, (handle) => this.scanOpened(handle, registration), {
|
|
5387
|
-
missing: () =>
|
|
5581
|
+
missing: async () => {
|
|
5582
|
+
try {
|
|
5583
|
+
return await this.retireMissing(registration);
|
|
5584
|
+
} catch (error) {
|
|
5585
|
+
return this.scanFailed(void 0, registration, error);
|
|
5586
|
+
}
|
|
5587
|
+
},
|
|
5388
5588
|
failed: (handle, error) => this.scanFailed(handle, registration, error)
|
|
5389
5589
|
});
|
|
5390
5590
|
}
|
|
@@ -5467,8 +5667,8 @@ var HostProducerDrainCore = class {
|
|
|
5467
5667
|
};
|
|
5468
5668
|
|
|
5469
5669
|
// host/relay/src/durable-atomic-replacement.ts
|
|
5470
|
-
import { lstat as lstat2, mkdir, open as open3, rename, unlink } from "node:fs/promises";
|
|
5471
|
-
import { dirname as
|
|
5670
|
+
import { lstat as lstat2, mkdir as mkdir2, open as open3, rename, unlink } from "node:fs/promises";
|
|
5671
|
+
import { dirname as dirname3 } from "node:path";
|
|
5472
5672
|
|
|
5473
5673
|
// host/windows-rename-retry.ts
|
|
5474
5674
|
import { setTimeout as setTimeout2 } from "node:timers/promises";
|
|
@@ -5521,7 +5721,7 @@ function isRetryableRenameError(error) {
|
|
|
5521
5721
|
// host/relay/src/durable-atomic-replacement.ts
|
|
5522
5722
|
var DEFAULT_PORT = {
|
|
5523
5723
|
platform: process.platform,
|
|
5524
|
-
mkdir: (path, options) =>
|
|
5724
|
+
mkdir: (path, options) => mkdir2(path, options),
|
|
5525
5725
|
lstat: (path) => lstat2(path),
|
|
5526
5726
|
open_file: (path) => open3(path, "wx", 384),
|
|
5527
5727
|
rename,
|
|
@@ -5530,7 +5730,7 @@ var DEFAULT_PORT = {
|
|
|
5530
5730
|
unique_ref: () => `${process.pid}.${crypto.randomUUID()}`
|
|
5531
5731
|
};
|
|
5532
5732
|
async function durableAtomicReplace(target, data, port = DEFAULT_PORT) {
|
|
5533
|
-
const parent =
|
|
5733
|
+
const parent = dirname3(target);
|
|
5534
5734
|
await port.mkdir(parent, { recursive: true, mode: 448 });
|
|
5535
5735
|
const parentStats = await port.lstat(parent);
|
|
5536
5736
|
const expectedUid = typeof process.geteuid === "function" ? process.geteuid() : parentStats.uid;
|
|
@@ -5600,8 +5800,8 @@ function errorCode2(error) {
|
|
|
5600
5800
|
// host/relay/src/host-usage-facts-store.ts
|
|
5601
5801
|
import { createHash as createHash6 } from "node:crypto";
|
|
5602
5802
|
import { constants as constants2 } from "node:fs";
|
|
5603
|
-
import { mkdir as
|
|
5604
|
-
import { dirname as
|
|
5803
|
+
import { mkdir as mkdir3, open as open4, opendir, unlink as unlink2 } from "node:fs/promises";
|
|
5804
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
5605
5805
|
var HOST_USAGE_FACTS_STATE_SCHEMA = "ceal.host_usage_facts_state.v1";
|
|
5606
5806
|
var HOST_USAGE_FACTS_STATE_MAX_BYTES = 256 * 1024;
|
|
5607
5807
|
var HOST_USAGE_FACTS_MAX_SOURCE_CURSORS = CEAL_HOST_USAGE_BATCH_MAX_SOURCE_RANGES;
|
|
@@ -5850,7 +6050,7 @@ var HostUsageFactsStore = class {
|
|
|
5850
6050
|
}
|
|
5851
6051
|
async writeImmutableBatch(state, batch, bytes) {
|
|
5852
6052
|
const path = this.batchPath(state, batch.batch_ref);
|
|
5853
|
-
await preparePrivateDirectory(
|
|
6053
|
+
await preparePrivateDirectory(dirname4(path), this.platform, this.custody);
|
|
5854
6054
|
const existing = await readOptionalBytes(path, CEAL_HOST_USAGE_BATCH_MAX_BYTES, this.platform, this.custody);
|
|
5855
6055
|
if (existing !== null) {
|
|
5856
6056
|
if (!existing.equals(bytes)) throw new Error("Host usage facts batch reference conflicts with existing bytes.");
|
|
@@ -5868,7 +6068,7 @@ var HostUsageFactsStore = class {
|
|
|
5868
6068
|
await handle.sync();
|
|
5869
6069
|
await handle.close();
|
|
5870
6070
|
handle = void 0;
|
|
5871
|
-
await syncDirectory(
|
|
6071
|
+
await syncDirectory(dirname4(path), this.platform);
|
|
5872
6072
|
} catch (error) {
|
|
5873
6073
|
await handle?.close().catch(() => void 0);
|
|
5874
6074
|
if (errorCode3(error) === "EEXIST") {
|
|
@@ -6122,7 +6322,7 @@ async function preparePrivateDirectory(path, platform, custody) {
|
|
|
6122
6322
|
await ensurePrivateDirectoryWithSecurefs(path, custody);
|
|
6123
6323
|
return;
|
|
6124
6324
|
}
|
|
6125
|
-
await
|
|
6325
|
+
await mkdir3(path, { recursive: true, mode: 448 });
|
|
6126
6326
|
if (!await isPrivateDirectory(path, platform)) throw new Error("Host usage facts directory is not owner private.");
|
|
6127
6327
|
}
|
|
6128
6328
|
async function syncExistingFile(path, platform) {
|
|
@@ -6132,7 +6332,7 @@ async function syncExistingFile(path, platform) {
|
|
|
6132
6332
|
} finally {
|
|
6133
6333
|
await handle.close();
|
|
6134
6334
|
}
|
|
6135
|
-
await syncDirectory(
|
|
6335
|
+
await syncDirectory(dirname4(path), platform);
|
|
6136
6336
|
}
|
|
6137
6337
|
async function syncDirectory(path, platform) {
|
|
6138
6338
|
if (platform === "win32") return;
|
|
@@ -6273,16 +6473,16 @@ function completeLinePrefix(bytes, baseOffset) {
|
|
|
6273
6473
|
|
|
6274
6474
|
// host/relay/src/host-registration-state.ts
|
|
6275
6475
|
import { constants as constants4 } from "node:fs";
|
|
6276
|
-
import { dirname as
|
|
6476
|
+
import { dirname as dirname5 } from "node:path";
|
|
6277
6477
|
|
|
6278
6478
|
// host/runtime-source-paths.ts
|
|
6279
6479
|
import { createHash as createHash7 } from "node:crypto";
|
|
6280
|
-
import { posix as
|
|
6480
|
+
import { posix as posix3, win32 as win325 } from "node:path";
|
|
6281
6481
|
|
|
6282
6482
|
// host/absolute-path.ts
|
|
6283
|
-
import { posix, win32 as
|
|
6483
|
+
import { posix as posix2, win32 as win324 } from "node:path";
|
|
6284
6484
|
function isAbsoluteNormalizedNonRootPath(value, flavor = process.platform, allowRoot = false) {
|
|
6285
|
-
const pathApi = flavor === "win32" || flavor === "windows" ?
|
|
6485
|
+
const pathApi = flavor === "win32" || flavor === "windows" ? win324 : posix2;
|
|
6286
6486
|
return typeof value === "string" && value.length <= 4096 && !value.includes("\0") && pathApi.isAbsolute(value) && pathApi.normalize(value) === value && (allowRoot || pathApi.parse(value).root !== value);
|
|
6287
6487
|
}
|
|
6288
6488
|
|
|
@@ -6326,7 +6526,7 @@ function macosHostRelayIpcDirectory(uid = process.geteuid?.() ?? -1) {
|
|
|
6326
6526
|
function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platform, uid = process.geteuid?.() ?? -1) {
|
|
6327
6527
|
const sourceId = hostSourceUuid(sourceRef);
|
|
6328
6528
|
if (!isAbsoluteNormalizedNonRootPath(stateRoot, platform) || sourceId === null) throw new TypeError("Host runtime source identity is invalid.");
|
|
6329
|
-
const path = platform === "win32" ?
|
|
6529
|
+
const path = platform === "win32" ? win325 : posix3;
|
|
6330
6530
|
const sourcesRoot = path.join(stateRoot, "sources");
|
|
6331
6531
|
const sourceRoot = path.join(sourcesRoot, sourceId);
|
|
6332
6532
|
const runtimeRoot = path.join(stateRoot, "run");
|
|
@@ -6337,7 +6537,7 @@ function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platfor
|
|
|
6337
6537
|
function projectRelayEndpoint(stateRoot, sourceRef, rooted, platform, uid) {
|
|
6338
6538
|
if (platform !== "win32" && (platform !== "darwin" || Buffer.byteLength(rooted, "utf8") <= PORTABLE_UNIX_SOCKET_PATH_MAX_BYTES)) return rooted;
|
|
6339
6539
|
const digest2 = createHash7("sha256").update(`${stateRoot}\0${sourceRef}`).digest("hex");
|
|
6340
|
-
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` :
|
|
6540
|
+
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest2.slice(0, 24)}` : posix3.join(macosHostRelayIpcDirectory(uid), `${digest2}.sock`);
|
|
6341
6541
|
}
|
|
6342
6542
|
function assertHostProducerSourcePaths(stateRoot, config, producer, platform = process.platform) {
|
|
6343
6543
|
const paths = hostRuntimeSourcePaths(stateRoot, config.host_source_ref, platform);
|
|
@@ -6365,7 +6565,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
6365
6565
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
6366
6566
|
let raw;
|
|
6367
6567
|
try {
|
|
6368
|
-
await assertPrivateRegistrationDirectory(
|
|
6568
|
+
await assertPrivateRegistrationDirectory(dirname5(path), platform, custody);
|
|
6369
6569
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
6370
6570
|
} catch (error) {
|
|
6371
6571
|
throw registrationReadError(error);
|
|
@@ -6470,185 +6670,6 @@ function waitForAbort(signal, milliseconds) {
|
|
|
6470
6670
|
});
|
|
6471
6671
|
}
|
|
6472
6672
|
|
|
6473
|
-
// host/service-log.ts
|
|
6474
|
-
import { copyFile, mkdir as mkdir3, stat as stat2, truncate, appendFile } from "node:fs/promises";
|
|
6475
|
-
import { dirname as dirname5, isAbsolute as isAbsolute2, posix as posix3, win32 as win325 } from "node:path";
|
|
6476
|
-
|
|
6477
|
-
// host/service-log-delivery.ts
|
|
6478
|
-
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
6479
|
-
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
6480
|
-
setImmediate(flush);
|
|
6481
|
-
}, onDeliveryGap = () => void 0) {
|
|
6482
|
-
const pending = [];
|
|
6483
|
-
const highWaterMark = stream.writableHighWaterMark;
|
|
6484
|
-
const byteBudget = highWaterMark + highWaterMark;
|
|
6485
|
-
let pendingBytes = 0;
|
|
6486
|
-
let droppedLines = 0;
|
|
6487
|
-
let flushScheduled = false;
|
|
6488
|
-
let waitingForDrain = false;
|
|
6489
|
-
let closed = !stream.writable;
|
|
6490
|
-
function stop() {
|
|
6491
|
-
if (closed) return;
|
|
6492
|
-
closed = true;
|
|
6493
|
-
pending.length = 0;
|
|
6494
|
-
pendingBytes = 0;
|
|
6495
|
-
stream.off("drain", onDrain);
|
|
6496
|
-
stream.off("close", onTerminal);
|
|
6497
|
-
stream.off("finish", onTerminal);
|
|
6498
|
-
stream.off("error", onError);
|
|
6499
|
-
}
|
|
6500
|
-
function onTerminal() {
|
|
6501
|
-
stop();
|
|
6502
|
-
}
|
|
6503
|
-
function onError() {
|
|
6504
|
-
stop();
|
|
6505
|
-
}
|
|
6506
|
-
function onDrain() {
|
|
6507
|
-
waitingForDrain = false;
|
|
6508
|
-
scheduleFlush();
|
|
6509
|
-
}
|
|
6510
|
-
function scheduleFlush() {
|
|
6511
|
-
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
6512
|
-
flushScheduled = true;
|
|
6513
|
-
let scheduling = true;
|
|
6514
|
-
let invokedSynchronously = false;
|
|
6515
|
-
try {
|
|
6516
|
-
schedule(() => {
|
|
6517
|
-
if (scheduling) {
|
|
6518
|
-
invokedSynchronously = true;
|
|
6519
|
-
return;
|
|
6520
|
-
}
|
|
6521
|
-
flushScheduled = false;
|
|
6522
|
-
flush();
|
|
6523
|
-
});
|
|
6524
|
-
} catch {
|
|
6525
|
-
flushScheduled = false;
|
|
6526
|
-
stop();
|
|
6527
|
-
return;
|
|
6528
|
-
}
|
|
6529
|
-
scheduling = false;
|
|
6530
|
-
if (invokedSynchronously) {
|
|
6531
|
-
flushScheduled = false;
|
|
6532
|
-
stop();
|
|
6533
|
-
}
|
|
6534
|
-
}
|
|
6535
|
-
function flush() {
|
|
6536
|
-
if (closed) return;
|
|
6537
|
-
if (!stream.writable) {
|
|
6538
|
-
stop();
|
|
6539
|
-
return;
|
|
6540
|
-
}
|
|
6541
|
-
while (pending.length > 0) {
|
|
6542
|
-
if (stream.writableNeedDrain) {
|
|
6543
|
-
if (!waitingForDrain) {
|
|
6544
|
-
waitingForDrain = true;
|
|
6545
|
-
stream.once("drain", onDrain);
|
|
6546
|
-
}
|
|
6547
|
-
return;
|
|
6548
|
-
}
|
|
6549
|
-
const next = pending.shift();
|
|
6550
|
-
if (next === void 0) return;
|
|
6551
|
-
pendingBytes -= next.bytes;
|
|
6552
|
-
let accepted;
|
|
6553
|
-
try {
|
|
6554
|
-
accepted = stream.write(next.line);
|
|
6555
|
-
} catch {
|
|
6556
|
-
stop();
|
|
6557
|
-
return;
|
|
6558
|
-
}
|
|
6559
|
-
if (!accepted) {
|
|
6560
|
-
waitingForDrain = true;
|
|
6561
|
-
stream.once("drain", onDrain);
|
|
6562
|
-
return;
|
|
6563
|
-
}
|
|
6564
|
-
}
|
|
6565
|
-
if (droppedLines > 0) {
|
|
6566
|
-
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
6567
|
-
`;
|
|
6568
|
-
droppedLines = 0;
|
|
6569
|
-
try {
|
|
6570
|
-
onDeliveryGap(line);
|
|
6571
|
-
} catch {
|
|
6572
|
-
}
|
|
6573
|
-
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
6574
|
-
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
6575
|
-
flush();
|
|
6576
|
-
}
|
|
6577
|
-
}
|
|
6578
|
-
stream.on("close", onTerminal);
|
|
6579
|
-
stream.on("finish", onTerminal);
|
|
6580
|
-
stream.on("error", onError);
|
|
6581
|
-
return (line) => {
|
|
6582
|
-
if (closed) return;
|
|
6583
|
-
const bytes = Buffer.byteLength(line, "utf8");
|
|
6584
|
-
if (bytes > highWaterMark || stream.writableLength + pendingBytes + bytes > byteBudget) {
|
|
6585
|
-
droppedLines += 1;
|
|
6586
|
-
scheduleFlush();
|
|
6587
|
-
return;
|
|
6588
|
-
}
|
|
6589
|
-
pending.push({ line, bytes });
|
|
6590
|
-
pendingBytes += bytes;
|
|
6591
|
-
scheduleFlush();
|
|
6592
|
-
};
|
|
6593
|
-
}
|
|
6594
|
-
|
|
6595
|
-
// host/service-log.ts
|
|
6596
|
-
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
6597
|
-
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
6598
|
-
void persistHostServiceLogLine(line);
|
|
6599
|
-
});
|
|
6600
|
-
function writeHostServiceDiagnostic(producer_id, event, failure_kind, cause, sink) {
|
|
6601
|
-
const details = diagnosticDetails(event, failure_kind, cause);
|
|
6602
|
-
const line = `${JSON.stringify({ schema_version: CEAL_HOST_SERVICE_DIAGNOSTIC_SCHEMA, producer_id, event, ...details })}
|
|
6603
|
-
`;
|
|
6604
|
-
try {
|
|
6605
|
-
(sink ?? defaultHostServiceDiagnosticSink)(line);
|
|
6606
|
-
} catch {
|
|
6607
|
-
}
|
|
6608
|
-
}
|
|
6609
|
-
function diagnosticDetails(event, failureKind, cause) {
|
|
6610
|
-
if (event === "watcher_scan_failed") return {
|
|
6611
|
-
...failureKind === void 0 ? {} : { failure_kind: failureKind },
|
|
6612
|
-
...validDiagnosticCause(cause, event) ? { cause } : {}
|
|
6613
|
-
};
|
|
6614
|
-
return validDiagnosticCause(cause, event) ? { cause } : {};
|
|
6615
|
-
}
|
|
6616
|
-
function validDiagnosticCause(cause, event) {
|
|
6617
|
-
return cause !== void 0 && isCealHostServiceDiagnosticCause(cause, event);
|
|
6618
|
-
}
|
|
6619
|
-
function defaultHostServiceDiagnosticSink(line) {
|
|
6620
|
-
writeHostServiceLogLine(line);
|
|
6621
|
-
}
|
|
6622
|
-
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
6623
|
-
function writeHostServiceLogLine(line, environment = process.env) {
|
|
6624
|
-
void persistHostServiceLogLine(line, environment);
|
|
6625
|
-
defaultHostServiceLogDelivery(line);
|
|
6626
|
-
}
|
|
6627
|
-
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
6628
|
-
if (process.platform !== "win32") return;
|
|
6629
|
-
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
6630
|
-
if (path === void 0 || !win325.isAbsolute(path) || win325.normalize(path) !== path) return;
|
|
6631
|
-
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
6632
|
-
}
|
|
6633
|
-
async function appendHostServiceLogLine(path, line) {
|
|
6634
|
-
if (!isAbsolute2(path)) return;
|
|
6635
|
-
await ensureHostServiceLogDirectory(path);
|
|
6636
|
-
await appendFile(path, line);
|
|
6637
|
-
}
|
|
6638
|
-
var HOST_SERVICE_LOG_TAIL_BYTES = 64 * 1024;
|
|
6639
|
-
var hostServiceLogDirectories = /* @__PURE__ */ new Map();
|
|
6640
|
-
function ensureHostServiceLogDirectory(path) {
|
|
6641
|
-
const directory = dirname5(path);
|
|
6642
|
-
const existing = hostServiceLogDirectories.get(directory);
|
|
6643
|
-
if (existing !== void 0) return existing;
|
|
6644
|
-
const pending = mkdir3(directory, { recursive: true, mode: 448 }).then(() => void 0).catch((error) => {
|
|
6645
|
-
hostServiceLogDirectories.delete(directory);
|
|
6646
|
-
throw error;
|
|
6647
|
-
});
|
|
6648
|
-
hostServiceLogDirectories.set(directory, pending);
|
|
6649
|
-
return pending;
|
|
6650
|
-
}
|
|
6651
|
-
|
|
6652
6673
|
// host/relay/src/host-usage-facts-uploader.ts
|
|
6653
6674
|
var HostUsageFactsUploader = class {
|
|
6654
6675
|
options;
|
|
@@ -6667,7 +6688,7 @@ var HostUsageFactsUploader = class {
|
|
|
6667
6688
|
const registration = await readHostRegistrationAuthority(this.options.registration_state_file, this.options.host_source_ref, this.options.store_options?.platform, this.options.store_options?.secure_file_custody);
|
|
6668
6689
|
const timeout = AbortSignal.timeout(this.options.timeout_ms ?? 5e3);
|
|
6669
6690
|
const requestSignal = signal === void 0 ? timeout : AbortSignal.any([signal, timeout]);
|
|
6670
|
-
const response2 = await
|
|
6691
|
+
const response2 = await this.options.fetch(`${registration.gateway_request_origin}${CEAL_HOST_USAGE_INGRESS_PATH}`, {
|
|
6671
6692
|
method: "POST",
|
|
6672
6693
|
headers: { authorization: `Bearer ${registration.host_access_token}`, "content-type": "application/json" },
|
|
6673
6694
|
body: JSON.stringify(candidate.batch),
|
|
@@ -7234,36 +7255,67 @@ var HostInvocationAuthenticationRefusal = class extends Error {
|
|
|
7234
7255
|
if (diagnosticCause !== void 0) this.diagnostic_cause = diagnosticCause;
|
|
7235
7256
|
}
|
|
7236
7257
|
};
|
|
7237
|
-
|
|
7258
|
+
var INSTALLED_HOST_INVOCATION_AUTHENTICATION_DEPENDENCIES = {
|
|
7259
|
+
process_elapsed_ms: () => performance.now(),
|
|
7260
|
+
load_pipe_key: async (outboxDirectory) => process.platform === "win32" ? loadRelayPipeKey(relayPipeStateRootForOutboxDir(outboxDirectory)) : void 0,
|
|
7261
|
+
create_relay_port: (endpoint, pipeKey, timeoutMs) => new HostRelayInvocationContextPort(endpoint, pipeKey, timeoutMs)
|
|
7262
|
+
};
|
|
7263
|
+
function installedHostInvocationAuthenticationCommandOptions(config, contextBudgetMs, maxContextWaitMs, dependencies) {
|
|
7238
7264
|
let pipeKey;
|
|
7239
7265
|
const loadPipeKey = () => {
|
|
7240
|
-
if (pipeKey === void 0) pipeKey =
|
|
7266
|
+
if (pipeKey === void 0) pipeKey = dependencies.load_pipe_key(config.outbox_dir);
|
|
7241
7267
|
return pipeKey;
|
|
7242
7268
|
};
|
|
7269
|
+
const remainingBudget = () => remainingAuthenticationBudget(contextBudgetMs, dependencies.process_elapsed_ms());
|
|
7243
7270
|
return {
|
|
7244
7271
|
host_source_ref: config.host_source_ref,
|
|
7245
7272
|
outbox_dir: config.outbox_dir,
|
|
7246
7273
|
producer_installation_ref: config.producer_installation_ref,
|
|
7247
|
-
context_activation_wait_ms: boundedContextActivationWait(
|
|
7248
|
-
|
|
7274
|
+
context_activation_wait_ms: boundedContextActivationWait(remainingBudget() ?? 0, config.ipc_timeout_ms, maxContextWaitMs),
|
|
7275
|
+
monotonic_now: dependencies.process_elapsed_ms,
|
|
7276
|
+
...dependencies.wait === void 0 ? {} : { wait: dependencies.wait },
|
|
7277
|
+
...dependencies.output_sink === void 0 ? {} : { output_sink: dependencies.output_sink },
|
|
7278
|
+
...dependencies.diagnostic_sink === void 0 ? {} : { diagnostic_sink: dependencies.diagnostic_sink },
|
|
7279
|
+
mint_invocation_context: async (input) => {
|
|
7280
|
+
requireMintExchangeTimeout(remainingBudget(), config.ipc_timeout_ms);
|
|
7281
|
+
const loadedPipeKey = await loadPipeKey();
|
|
7282
|
+
const timeoutMs = requireMintExchangeTimeout(remainingBudget(), config.ipc_timeout_ms);
|
|
7283
|
+
return dependencies.create_relay_port(config.relay_endpoint, loadedPipeKey, timeoutMs).mintInvocationContext(input);
|
|
7284
|
+
}
|
|
7249
7285
|
};
|
|
7250
7286
|
}
|
|
7251
|
-
|
|
7287
|
+
function remainingAuthenticationBudget(contextBudgetMs, processElapsedMs) {
|
|
7288
|
+
if (contextBudgetMs === void 0) return void 0;
|
|
7289
|
+
return Math.max(0, Math.floor(contextBudgetMs - processElapsedMs));
|
|
7290
|
+
}
|
|
7291
|
+
function requireMintExchangeTimeout(remainingBudgetMs, directTimeoutMs) {
|
|
7292
|
+
if (remainingBudgetMs === void 0) return directTimeoutMs;
|
|
7293
|
+
const timeoutMs = remainingBudgetMs - HOST_AUTHENTICATION_COMPLETION_RESERVE_MS;
|
|
7294
|
+
if (timeoutMs <= 0) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC timed out before minting could start.", "timed_out");
|
|
7295
|
+
return timeoutMs;
|
|
7296
|
+
}
|
|
7297
|
+
async function runHostInvocationAuthenticationCommand(descriptor2, args, options, installedDependencies = INSTALLED_HOST_INVOCATION_AUTHENTICATION_DEPENDENCIES) {
|
|
7252
7298
|
let sink = options?.output_sink;
|
|
7299
|
+
let diagnosticSink = options?.diagnostic_sink;
|
|
7253
7300
|
try {
|
|
7254
|
-
const resolved = await resolveOptions(descriptor2, args, options);
|
|
7301
|
+
const resolved = await resolveOptions(descriptor2, args, options, installedDependencies);
|
|
7255
7302
|
sink = resolved.options.output_sink;
|
|
7303
|
+
diagnosticSink = resolved.options.diagnostic_sink;
|
|
7256
7304
|
writeResult(await authenticateHostInvocation(descriptor2, resolved.input, resolved.options), sink);
|
|
7257
7305
|
return 0;
|
|
7258
7306
|
} catch (error) {
|
|
7259
|
-
|
|
7260
|
-
const refusal = error instanceof HostInvocationAuthenticationRefusal ? error : void 0;
|
|
7261
|
-
const gatewayStatus = refusal?.reason === "gateway_refused" && validGenericGatewayRefusalStatus2(refusal.gateway_status) ? refusal.gateway_status : void 0;
|
|
7262
|
-
writeHostServiceDiagnostic(descriptor2.producer_id, "invocation_authentication_failed", void 0, refusal?.diagnostic_cause ?? reason, options?.diagnostic_sink);
|
|
7263
|
-
writeResult({ schema_version: CEAL_HOST_INVOCATION_AUTHENTICATION_REFUSAL_SCHEMA, ok: false, code: "invocation_authentication_unavailable", reason, ...gatewayStatus === void 0 ? {} : { gateway_status: gatewayStatus } }, sink);
|
|
7264
|
-
return 2;
|
|
7307
|
+
return writeAuthenticationFailure(descriptor2.producer_id, error, sink, diagnosticSink);
|
|
7265
7308
|
}
|
|
7266
7309
|
}
|
|
7310
|
+
function writeAuthenticationFailure(producerId, error, sink, diagnosticSink) {
|
|
7311
|
+
const reason = authenticationRefusalReason(error);
|
|
7312
|
+
const refusal = error instanceof HostInvocationAuthenticationRefusal ? error : void 0;
|
|
7313
|
+
const gatewayStatus = refusal?.reason === "gateway_refused" && validGenericGatewayRefusalStatus2(refusal.gateway_status) ? refusal.gateway_status : void 0;
|
|
7314
|
+
const retryAfterMs = reason === "activation_wait_exhausted" ? INVOCATION_CONTEXT_POLL_INTERVAL_MS : void 0;
|
|
7315
|
+
writeHostServiceDiagnostic(producerId, "invocation_authentication_failed", void 0, refusal?.diagnostic_cause ?? reason, diagnosticSink);
|
|
7316
|
+
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);
|
|
7317
|
+
return 2;
|
|
7318
|
+
}
|
|
7267
7319
|
function authenticationRefusalReason(error) {
|
|
7268
7320
|
const message = error instanceof Error ? error.message : "";
|
|
7269
7321
|
if (!REFUSAL_REASON_PATTERN.test(message)) return "host_refusal_invalid";
|
|
@@ -7327,8 +7379,7 @@ async function currentInvocation(descriptor2, config, now) {
|
|
|
7327
7379
|
let waitEngaged = false;
|
|
7328
7380
|
while (true) {
|
|
7329
7381
|
if (!firstCheck && monotonicNow() >= deadline) {
|
|
7330
|
-
|
|
7331
|
-
throw new TypeError("context_unavailable");
|
|
7382
|
+
throw activationWaitExhausted(descriptor2.producer_id, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
7332
7383
|
}
|
|
7333
7384
|
firstCheck = false;
|
|
7334
7385
|
const observedAt = now();
|
|
@@ -7340,8 +7391,7 @@ async function currentInvocation(descriptor2, config, now) {
|
|
|
7340
7391
|
await rejectWhenActivationWaitIsUnavailable(descriptor2, store, identity.identity, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
7341
7392
|
const remainingMs = deadline - monotonicNow();
|
|
7342
7393
|
if (remainingMs <= 0) {
|
|
7343
|
-
|
|
7344
|
-
throw new TypeError("context_unavailable");
|
|
7394
|
+
throw activationWaitExhausted(descriptor2.producer_id, waitEngaged, waitBudgetMs, config.diagnostic_sink);
|
|
7345
7395
|
}
|
|
7346
7396
|
recordActivationWaitEngagement(descriptor2.producer_id, waitEngaged, config.diagnostic_sink);
|
|
7347
7397
|
waitEngaged = true;
|
|
@@ -7349,9 +7399,13 @@ async function currentInvocation(descriptor2, config, now) {
|
|
|
7349
7399
|
await (config.wait ?? waitForContextActivation)(intervalMs);
|
|
7350
7400
|
}
|
|
7351
7401
|
}
|
|
7402
|
+
function activationWaitExhausted(producerId, waitEngaged, waitBudgetMs, diagnosticSink) {
|
|
7403
|
+
recordActivationWaitExhaustion(producerId, waitEngaged, waitBudgetMs, diagnosticSink);
|
|
7404
|
+
return new TypeError(waitEngaged ? "activation_wait_exhausted" : "context_unavailable");
|
|
7405
|
+
}
|
|
7352
7406
|
async function rejectWhenActivationWaitIsUnavailable(descriptor2, store, identity, waitEngaged, waitBudgetMs, sink) {
|
|
7353
|
-
if (waitEngaged || waitBudgetMs <= 0
|
|
7354
|
-
if (await descriptor2.can_wait_for_context_activation({ store, identity })) return;
|
|
7407
|
+
if (waitEngaged || waitBudgetMs <= 0) return;
|
|
7408
|
+
if (descriptor2.can_wait_for_context_activation !== void 0 && await descriptor2.can_wait_for_context_activation({ store, identity })) return;
|
|
7355
7409
|
writeHostServiceDiagnostic(descriptor2.producer_id, "activation_wait_skipped", void 0, void 0, sink);
|
|
7356
7410
|
throw new TypeError("context_unavailable");
|
|
7357
7411
|
}
|
|
@@ -7380,18 +7434,18 @@ function resolveIdentity(descriptor2, options) {
|
|
|
7380
7434
|
if (isHostSessionId(sessionId)) return { status: "ready", identity: { host_source_ref: options.host_source_ref, host_session_ref: descriptor2.session_ref(options.host_source_ref, sessionId) } };
|
|
7381
7435
|
return { status: "session_unavailable" };
|
|
7382
7436
|
}
|
|
7383
|
-
async function resolveOptions(descriptor2, args, options) {
|
|
7437
|
+
async function resolveOptions(descriptor2, args, options, installedDependencies) {
|
|
7384
7438
|
if (options !== void 0) return { input: [...args], options };
|
|
7385
7439
|
const configPath = descriptor2.parse_config_flag(args);
|
|
7386
7440
|
const config = await descriptor2.read_producer_config(configPath);
|
|
7387
7441
|
return {
|
|
7388
7442
|
input: args.filter((argument) => !argument.startsWith(`${descriptor2.config_flag}=`)),
|
|
7389
|
-
options: installedHostInvocationAuthenticationCommandOptions(config, authenticationBudgetMsFromEnvironment(), descriptor2.context_activation_wait_max_ms)
|
|
7443
|
+
options: installedHostInvocationAuthenticationCommandOptions(config, authenticationBudgetMsFromEnvironment(), descriptor2.context_activation_wait_max_ms, installedDependencies)
|
|
7390
7444
|
};
|
|
7391
7445
|
}
|
|
7392
7446
|
function authenticationBudgetMsFromEnvironment() {
|
|
7393
7447
|
const value = process.env[CEAL_HOST_AUTHENTICATION_BUDGET_ENVIRONMENT];
|
|
7394
|
-
if (value === void 0) return 0;
|
|
7448
|
+
if (value === void 0) return void 0;
|
|
7395
7449
|
if (!CEAL_HOST_AUTHENTICATION_BUDGET_PATTERN.test(value)) throw new TypeError("invalid_arguments");
|
|
7396
7450
|
return Number(value);
|
|
7397
7451
|
}
|
|
@@ -8544,9 +8598,9 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
8544
8598
|
const { size, device, inode } = await ownedCodexTranscriptFile(handle);
|
|
8545
8599
|
const preflight = await this.preflight(registration, handle, size, device, inode);
|
|
8546
8600
|
if (preflight.cursor === null) return preflight.result;
|
|
8601
|
+
if (preflight.checkpointPending) await this.commitCursor(registration, handle, preflight.cursor, 0, device, inode, preflight.cursor.last_ordinal, preflight.cursor.active_task, preflight.cursor.human_message_window ?? { messages: [], truncated: false });
|
|
8547
8602
|
const complete = await this.readChunk(handle, preflight.cursor.offset, size);
|
|
8548
8603
|
if (complete === "empty" || complete === "partial") {
|
|
8549
|
-
if (preflight.projectionInitialized) await this.commitCursor(registration, handle, preflight.cursor, 0, device, inode, preflight.cursor.last_ordinal, preflight.cursor.active_task, preflight.cursor.human_message_window ?? { messages: [], truncated: false });
|
|
8550
8604
|
return { records: 0, enqueued: 0, quarantined: false };
|
|
8551
8605
|
}
|
|
8552
8606
|
return await this.consumeCompleteChunk(registration, handle, preflight.cursor, complete, device, inode);
|
|
@@ -8563,17 +8617,17 @@ var CodexTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
8563
8617
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
8564
8618
|
let cursor = existing ?? codexTranscriptInitialCursor(registration, device, inode, this.now);
|
|
8565
8619
|
if (cursor.status === "quarantined") {
|
|
8566
|
-
return { cursor: null,
|
|
8620
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
8567
8621
|
}
|
|
8568
8622
|
const reason = this.cursorIdentityReason(cursor, registration.transcript_path, device, inode) ?? await this.cursorBoundsReason(handle, cursor, size);
|
|
8569
8623
|
if (reason === null) {
|
|
8570
|
-
if (cursor.human_message_window !== void 0) return { cursor,
|
|
8624
|
+
if (cursor.human_message_window !== void 0) return { cursor, checkpointPending: existing === null, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
8571
8625
|
const humanWindow = await this.readHumanMessageProjection(handle, registration, cursor);
|
|
8572
|
-
return { cursor: { ...cursor, human_message_window: humanWindow },
|
|
8626
|
+
return { cursor: { ...cursor, human_message_window: humanWindow }, checkpointPending: true, result: { records: 0, enqueued: 0, quarantined: false } };
|
|
8573
8627
|
}
|
|
8574
8628
|
await this.quarantine(registration, cursor, device, inode, reason);
|
|
8575
8629
|
this.diagnostic("watcher_scan_failed", "other", `cursor_${reason}`);
|
|
8576
|
-
return { cursor: null,
|
|
8630
|
+
return { cursor: null, checkpointPending: false, result: { records: 0, enqueued: 0, quarantined: true } };
|
|
8577
8631
|
}
|
|
8578
8632
|
async readHumanMessageProjection(handle, registration, cursor) {
|
|
8579
8633
|
return readCodexHumanMessageProjection(registration, cursor, (offset, size) => this.readChunk(handle, offset, size));
|
|
@@ -9067,12 +9121,11 @@ function normalizedCounts(selected) {
|
|
|
9067
9121
|
function nullCounts() {
|
|
9068
9122
|
return { input: null, output: null, total: null, cached_input: null, cache_write_input: null, reasoning_output: null };
|
|
9069
9123
|
}
|
|
9070
|
-
var USAGE_COUNT_FIELDS = ["input_tokens", "cached_input_tokens", "cache_write_input_tokens", "output_tokens", "reasoning_output_tokens", "total_tokens"];
|
|
9071
9124
|
function isRegression(current, previous) {
|
|
9072
|
-
return
|
|
9125
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.some((key) => current[key] < previous[key]);
|
|
9073
9126
|
}
|
|
9074
9127
|
function sameCounts(left, right) {
|
|
9075
|
-
return
|
|
9128
|
+
return CEAL_CODEX_USAGE_COUNT_FIELDS.every((key) => left[key] === right[key]);
|
|
9076
9129
|
}
|
|
9077
9130
|
function buildCoverageGaps(sourceFileRef, startOffset, endOffset, counts) {
|
|
9078
9131
|
return [...counts].map(([reason, omittedCount]) => coverageGap(reason, sourceFileRef, startOffset, endOffset, omittedCount));
|
|
@@ -9121,9 +9174,9 @@ var CODEX_PRODUCER_DESCRIPTOR = {
|
|
|
9121
9174
|
config: (shared, extras) => ({ ...shared, codex_sessions_root: hostProducerExtraPath(extras, CODEX_SESSIONS_ROOT) }),
|
|
9122
9175
|
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir }),
|
|
9123
9176
|
drain: drainCodexProducerOnce,
|
|
9124
|
-
background: (config, signal) => {
|
|
9177
|
+
background: (config, signal, dependencies) => {
|
|
9125
9178
|
const capturer = new CodexUsageFactsCapturer({ outbox_dir: config.outbox_dir });
|
|
9126
|
-
return runHostUsageFactsUploader({ producer: "codex", outbox_dir: config.outbox_dir, host_source_ref: config.host_source_ref, registration_state_file: hostProducerRegistrationStateFile(config.outbox_dir), capture_next: () => capturer.captureNext() }, signal);
|
|
9179
|
+
return runHostUsageFactsUploader({ producer: "codex", outbox_dir: config.outbox_dir, host_source_ref: config.host_source_ref, registration_state_file: hostProducerRegistrationStateFile(config.outbox_dir), capture_next: () => capturer.captureNext(), fetch: dependencies.fetch }, signal);
|
|
9127
9180
|
}
|
|
9128
9181
|
};
|
|
9129
9182
|
|