@corca-org/ceal-host-win32-x64 1.0.21 → 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 +2508 -483
- package/libexec/ceal-host/claude-invocation-authentication.mjs +2775 -634
- package/libexec/ceal-host/claude-producer.mjs +2510 -487
- package/libexec/ceal-host/codex-hook.mjs +2533 -530
- package/libexec/ceal-host/codex-invocation-authentication.mjs +3099 -954
- package/libexec/ceal-host/codex-producer.mjs +2450 -448
- package/libexec/ceal-host/control.mjs +5867 -2751
- package/libexec/ceal-host/relay.mjs +899 -420
- 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);
|
|
@@ -30,7 +42,7 @@ function isPlainRecord(value) {
|
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
// packages/ceal-client-protocol/src/client-wire-contract.ts
|
|
33
|
-
import { createHash } from "node:crypto";
|
|
45
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
34
46
|
|
|
35
47
|
// packages/ceal-client-protocol/client-wire-contract.json
|
|
36
48
|
var client_wire_contract_default = {
|
|
@@ -51,7 +63,7 @@ var client_wire_contract_default = {
|
|
|
51
63
|
ordering: "utf16_code_unit_ascending"
|
|
52
64
|
},
|
|
53
65
|
artifact_descriptor: {
|
|
54
|
-
operation_contract_bundle_schema_name: "ceal.
|
|
66
|
+
operation_contract_bundle_schema_name: "ceal.operation_contract_bundle_v2",
|
|
55
67
|
operation_contract_bundle_fields: ["schema_version", "catalog_revision", "operations", "failure_guidance"],
|
|
56
68
|
schema_name: "ceal.verified_artifact_descriptor",
|
|
57
69
|
fields: ["schema_version", "kind", "media_type", "byte_count", "sha256", "binding"],
|
|
@@ -76,7 +88,7 @@ var client_wire_contract_default = {
|
|
|
76
88
|
},
|
|
77
89
|
command_request: {
|
|
78
90
|
schema_name: "ceal.command_request",
|
|
79
|
-
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token"],
|
|
91
|
+
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context"],
|
|
80
92
|
absolute_transport_max_bytes: 65536
|
|
81
93
|
},
|
|
82
94
|
command_resolution: {
|
|
@@ -122,8 +134,9 @@ var client_wire_contract_default = {
|
|
|
122
134
|
},
|
|
123
135
|
command_response: {
|
|
124
136
|
schema_name: "ceal.command_response",
|
|
125
|
-
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact"],
|
|
137
|
+
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context"],
|
|
126
138
|
descriptor_field: "verified_artifact",
|
|
139
|
+
request_context_field: "request_context",
|
|
127
140
|
required_fields: [
|
|
128
141
|
"schema_version",
|
|
129
142
|
"exit_code",
|
|
@@ -133,7 +146,8 @@ var client_wire_contract_default = {
|
|
|
133
146
|
"operation_id",
|
|
134
147
|
"visible_output_max_bytes",
|
|
135
148
|
"local_delivery",
|
|
136
|
-
"verified_artifact"
|
|
149
|
+
"verified_artifact",
|
|
150
|
+
"request_context"
|
|
137
151
|
],
|
|
138
152
|
bare_document_fields: [
|
|
139
153
|
"invocation",
|
|
@@ -154,7 +168,7 @@ var client_wire_contract_default = {
|
|
|
154
168
|
],
|
|
155
169
|
exit_code_max: 125,
|
|
156
170
|
bare_document_max_bytes: 65536,
|
|
157
|
-
complete_max_bytes:
|
|
171
|
+
complete_max_bytes: 66195
|
|
158
172
|
},
|
|
159
173
|
host_invocation_authentication: {
|
|
160
174
|
request_schema_name: "ceal.host_invocation_authentication_request",
|
|
@@ -168,6 +182,17 @@ var client_wire_contract_default = {
|
|
|
168
182
|
"context_token",
|
|
169
183
|
"expires_at"
|
|
170
184
|
],
|
|
185
|
+
refusal_schema_name: "ceal.host_invocation_authentication_refusal",
|
|
186
|
+
refusal_fields: [
|
|
187
|
+
"schema_version",
|
|
188
|
+
"ok",
|
|
189
|
+
"code",
|
|
190
|
+
"reason",
|
|
191
|
+
"gateway_status",
|
|
192
|
+
"retry_after_ms"
|
|
193
|
+
],
|
|
194
|
+
refusal_required_fields: ["schema_version", "ok", "code", "reason"],
|
|
195
|
+
refusal_optional_fields: ["gateway_status", "retry_after_ms"],
|
|
171
196
|
client_nonce: {
|
|
172
197
|
character_class_source: "A-Za-z0-9_-",
|
|
173
198
|
encoded_characters: 43
|
|
@@ -206,6 +231,8 @@ var CALLER_RECOVERABLE_NEXT_ACTION_VALUES = [
|
|
|
206
231
|
"choose_new_output_path",
|
|
207
232
|
"choose_new_idempotency_key",
|
|
208
233
|
"restart_search",
|
|
234
|
+
// The requested temporal key is absent on some observed rows; repeating the same interval without `order` can return those rows.
|
|
235
|
+
"search_without_order",
|
|
209
236
|
"repeat_original_arguments",
|
|
210
237
|
// The occurrence this call addressed is settled and cannot move again -- a
|
|
211
238
|
// denied effect approval, an expired continuation -- so the caller runs the
|
|
@@ -264,6 +291,12 @@ var CALLER_RECOVERABLE_NEXT_ACTION_VALUES = [
|
|
|
264
291
|
// The command needs caller-owned local materialization (for example an
|
|
265
292
|
// @path file) before the Gateway can receive the argument.
|
|
266
293
|
"materialize_local_argument",
|
|
294
|
+
// A missing or stale local Host bundle is repaired through its installed lifecycle and discovery owners.
|
|
295
|
+
"install_ceal_host",
|
|
296
|
+
// An explicit Client store override points at a missing file; unsetting it selects the one canonical default store without creating a second credential store.
|
|
297
|
+
"unset_context_store_path",
|
|
298
|
+
// The producer app must reload its installed Host hook before it can start a conversation with invocation context.
|
|
299
|
+
"restart_producer_app",
|
|
267
300
|
// A peer's derived schema identifier changed with its field set; install or
|
|
268
301
|
// upgrade the CLI and Host Relay to the Gateway's release before retrying.
|
|
269
302
|
"upgrade_ceal_client"
|
|
@@ -372,21 +405,12 @@ var NON_MODEL_ACTION_TO_MODEL_ACTION = Object.freeze({
|
|
|
372
405
|
});
|
|
373
406
|
var RETRY_PROMISE_NEXT_ACTIONS = ["retry", "retry_after"];
|
|
374
407
|
var RETRY_PROMISE = new Set(RETRY_PROMISE_NEXT_ACTIONS);
|
|
375
|
-
var RECOVERABLE = new Set(CEAL_CALLER_RECOVERABLE_NEXT_ACTIONS);
|
|
376
408
|
var CEAL_OPERATION_WITHHELD_NEXT_ACTIONS = Object.freeze({
|
|
377
409
|
provider_permission: "ask_admin",
|
|
378
410
|
access_level: "ask_admin",
|
|
379
411
|
personal_authorization_required: "connect_personal_account"
|
|
380
412
|
});
|
|
381
413
|
|
|
382
|
-
// packages/ceal-client-protocol/src/vocabulary.ts
|
|
383
|
-
function vocabulary(words) {
|
|
384
|
-
return Object.freeze(words);
|
|
385
|
-
}
|
|
386
|
-
function isVocabularyWord(words, value) {
|
|
387
|
-
return words.some((word) => word === value);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
414
|
// packages/ceal-client-protocol/src/gateway-response-types.ts
|
|
391
415
|
var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavailable", "unknown"]);
|
|
392
416
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
@@ -397,9 +421,9 @@ var CEAL_GATEWAY_READ_REUSE_UNAVAILABLE_REASONS = vocabulary(["not_reported", "s
|
|
|
397
421
|
var CEAL_GATEWAY_DERIVED_STORE_FAILURE_CLASSES = vocabulary(["storage_unavailable", "decode_mismatch", "write_conflict", "quota", "store_error"]);
|
|
398
422
|
var CEAL_POLICY_DECISIONS = vocabulary(["allowed", "denied", "not_evaluated"]);
|
|
399
423
|
var CEAL_CONNECTOR_ROUTE_PHASES = vocabulary(["scope_observation", "target_selection", "route_resolution"]);
|
|
400
|
-
var CEAL_CONNECTOR_ROUTE_CAUSES = vocabulary(["provider_throttled", "provider_unavailable", "binding_invalid", "scope_limit_exceeded"]);
|
|
424
|
+
var CEAL_CONNECTOR_ROUTE_CAUSES = vocabulary(["provider_throttled", "provider_unavailable", "binding_invalid", "personal_binding_unproven", "scope_limit_exceeded"]);
|
|
401
425
|
var CEAL_WRITE_SOURCE_KINDS = vocabulary(["authenticated_registered_client", "provider_authenticated_event"]);
|
|
402
|
-
var CEAL_REFRESH_DELIVERIES = vocabulary(["initial", "recovery", "replay", "terminal_failure", "recovery_unavailable"]);
|
|
426
|
+
var CEAL_REFRESH_DELIVERIES = vocabulary(["initial", "recovery", "replay", "terminal_failure", "recovery_unavailable", "authority_inactive"]);
|
|
403
427
|
var CEAL_CLIENT_OPERATIONS = vocabulary(["handshake", "discover", "call", "readback"]);
|
|
404
428
|
var CEAL_WRITE_IDEMPOTENCY_POSTURES = vocabulary(["required", "optional", "not_required"]);
|
|
405
429
|
var CEAL_WRITE_PROVIDER_READBACK_POSTURES = vocabulary(["required", "best_effort", "not_available"]);
|
|
@@ -523,11 +547,13 @@ function isSafeExternalHttpsUrl(value) {
|
|
|
523
547
|
return false;
|
|
524
548
|
}
|
|
525
549
|
}
|
|
550
|
+
var SAFE_EXTERNAL_HTTPS_URL_WITH_FRAGMENT_PATTERN_SOURCE = "^https://[^\\s/@?#]+(?:[/?#][^\\s]*)?$";
|
|
551
|
+
var SAFE_EXTERNAL_HTTPS_URL_WITH_FRAGMENT_PATTERN = new RegExp(SAFE_EXTERNAL_HTTPS_URL_WITH_FRAGMENT_PATTERN_SOURCE, "u");
|
|
526
552
|
function isSafeExternalHttpsUrlInput(value) {
|
|
527
553
|
return typeof value === "string" && byteLength(value) <= 2048;
|
|
528
554
|
}
|
|
529
|
-
function isSafeExternalHttpsUrlShape(url) {
|
|
530
|
-
return url.protocol === "https:" && url.username === "" && url.password === "" && url.hash === "";
|
|
555
|
+
function isSafeExternalHttpsUrlShape(url, allowFragment = false) {
|
|
556
|
+
return url.protocol === "https:" && url.hostname.length > 0 && url.username === "" && url.password === "" && (allowFragment || url.hash === "");
|
|
531
557
|
}
|
|
532
558
|
function isSafeResultContent(value, key) {
|
|
533
559
|
const maximum = key === "text" ? 8192 : 1024;
|
|
@@ -649,6 +675,7 @@ function cut(text) {
|
|
|
649
675
|
|
|
650
676
|
// packages/ceal-client-protocol/src/operation-validation-primitives.ts
|
|
651
677
|
var ISO_TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?([Zz]|([+-])(\d{2}):(\d{2}))$/u;
|
|
678
|
+
var EXPANDED_CANONICAL_ISO_TIMESTAMP = /^([+-])(\d{6})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?Z$/u;
|
|
652
679
|
var CEAL_CALENDAR_DATE_PATTERN_SOURCE = "^\\d{4}-\\d{2}-\\d{2}$";
|
|
653
680
|
var CEAL_CALENDAR_DATE = new RegExp(CEAL_CALENDAR_DATE_PATTERN_SOURCE, "u");
|
|
654
681
|
function isOperationRecord(value) {
|
|
@@ -665,7 +692,35 @@ function requireClosedValue(value, members, message) {
|
|
|
665
692
|
function isCealIsoTimestamp(value) {
|
|
666
693
|
return typeof value === "string" && parseCealIsoTimestamp(value) !== null;
|
|
667
694
|
}
|
|
695
|
+
function canonicalCealIsoTimestamp(epochNanoseconds) {
|
|
696
|
+
const wholeSeconds = floorDivide(epochNanoseconds, 1000000000n);
|
|
697
|
+
const fractionalNanoseconds = epochNanoseconds - wholeSeconds * 1000000000n;
|
|
698
|
+
const utc = new Date(Number(wholeSeconds * 1000n));
|
|
699
|
+
const date = utc.toISOString().split(".")[0];
|
|
700
|
+
if (date === void 0) throw new TypeError("Ceal timestamp formatter returned an invalid ISO string");
|
|
701
|
+
const fraction = fractionalNanoseconds.toString().padStart(9, "0").replace(/0+$/u, "").padEnd(3, "0");
|
|
702
|
+
return date + "." + fraction + "Z";
|
|
703
|
+
}
|
|
704
|
+
var CEAL_TIMESTAMP_DOMAIN_MIN_SOURCE = "0000-01-01T00:00:00.000000000+23:59";
|
|
705
|
+
var CEAL_TIMESTAMP_DOMAIN_MAX_SOURCE = "9999-12-31T23:59:59.999999999-23:59";
|
|
706
|
+
var CEAL_TIMESTAMP_DOMAIN_MIN_EPOCH_NS = requiredTimestampEpochNanoseconds(CEAL_TIMESTAMP_DOMAIN_MIN_SOURCE);
|
|
707
|
+
var CEAL_TIMESTAMP_DOMAIN_MAX_EPOCH_NS = requiredTimestampEpochNanoseconds(CEAL_TIMESTAMP_DOMAIN_MAX_SOURCE);
|
|
708
|
+
var CEAL_INSTANT_INDEX_SPAN = CEAL_TIMESTAMP_DOMAIN_MAX_EPOCH_NS - CEAL_TIMESTAMP_DOMAIN_MIN_EPOCH_NS;
|
|
709
|
+
var CEAL_INSTANT_INDEX_KEY_WIDTH = CEAL_INSTANT_INDEX_SPAN.toString().length;
|
|
710
|
+
var CEAL_INSTANT_INDEX_KEY_PATTERN = new RegExp(`^\\d{${CEAL_INSTANT_INDEX_KEY_WIDTH}}$`, "u");
|
|
711
|
+
function requiredTimestampEpochNanoseconds(value) {
|
|
712
|
+
const parsed = parseFourDigitCealIsoTimestamp(value);
|
|
713
|
+
if (parsed === null) throw new Error("Ceal instant-index range basis is outside the timestamp grammar");
|
|
714
|
+
return parsed.epochNanoseconds;
|
|
715
|
+
}
|
|
668
716
|
function parseCealIsoTimestamp(value) {
|
|
717
|
+
const ordinary = parseFourDigitCealIsoTimestamp(value);
|
|
718
|
+
if (ordinary !== null) return ordinary;
|
|
719
|
+
const expanded = parseExpandedCanonicalCealIsoTimestamp(value);
|
|
720
|
+
if (expanded === null || expanded.epochNanoseconds < CEAL_TIMESTAMP_DOMAIN_MIN_EPOCH_NS || expanded.epochNanoseconds > CEAL_TIMESTAMP_DOMAIN_MAX_EPOCH_NS) return null;
|
|
721
|
+
return canonicalCealIsoTimestamp(expanded.epochNanoseconds) === value ? expanded : null;
|
|
722
|
+
}
|
|
723
|
+
function parseFourDigitCealIsoTimestamp(value) {
|
|
669
724
|
const fields = parseCealIsoTimestampFields(value);
|
|
670
725
|
if (fields === null || !validCalendarDate(fields) || !validClockTime(fields) || !validUtcOffset(fields)) return null;
|
|
671
726
|
const epochMilliseconds = cealFieldsEpochMilliseconds(fields);
|
|
@@ -674,6 +729,28 @@ function parseCealIsoTimestamp(value) {
|
|
|
674
729
|
epochNanoseconds: BigInt(epochMilliseconds) * 1000000n + BigInt(fields.fraction.padEnd(9, "0") || "0")
|
|
675
730
|
};
|
|
676
731
|
}
|
|
732
|
+
function parseExpandedCanonicalCealIsoTimestamp(value) {
|
|
733
|
+
const match = EXPANDED_CANONICAL_ISO_TIMESTAMP.exec(value);
|
|
734
|
+
if (match === null) return null;
|
|
735
|
+
const fields = {
|
|
736
|
+
year: (match[1] === "-" ? -1 : 1) * Number(match[2]),
|
|
737
|
+
month: Number(match[3]),
|
|
738
|
+
day: Number(match[4]),
|
|
739
|
+
hour: Number(match[5]),
|
|
740
|
+
minute: Number(match[6]),
|
|
741
|
+
second: Number(match[7]),
|
|
742
|
+
fraction: match[8] ?? "",
|
|
743
|
+
offsetSign: 0,
|
|
744
|
+
offsetHour: 0,
|
|
745
|
+
offsetMinute: 0
|
|
746
|
+
};
|
|
747
|
+
if (!validCalendarDate(fields) || !validClockTime(fields)) return null;
|
|
748
|
+
const epochMilliseconds = cealFieldsEpochMilliseconds(fields);
|
|
749
|
+
if (!Number.isFinite(epochMilliseconds)) return null;
|
|
750
|
+
return {
|
|
751
|
+
epochNanoseconds: BigInt(epochMilliseconds) * 1000000n + BigInt(fields.fraction.padEnd(9, "0") || "0")
|
|
752
|
+
};
|
|
753
|
+
}
|
|
677
754
|
function parseCealIsoTimestampFields(value) {
|
|
678
755
|
const match = ISO_TIMESTAMP.exec(value);
|
|
679
756
|
if (match === null) return null;
|
|
@@ -706,6 +783,10 @@ function cealFieldsEpochMilliseconds(fields) {
|
|
|
706
783
|
const offsetMilliseconds = fields.offsetSign * (fields.offsetHour * 60 + fields.offsetMinute) * 6e4;
|
|
707
784
|
return localMilliseconds - offsetMilliseconds;
|
|
708
785
|
}
|
|
786
|
+
function floorDivide(value, divisor) {
|
|
787
|
+
const quotient = value / divisor;
|
|
788
|
+
return value % divisor < 0n ? quotient - 1n : quotient;
|
|
789
|
+
}
|
|
709
790
|
function daysInMonth(year, month) {
|
|
710
791
|
const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
711
792
|
return [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1] ?? 0;
|
|
@@ -723,6 +804,9 @@ var LOCAL_COMMAND_INVALID = "The local command or argument is invalid.";
|
|
|
723
804
|
var LOCAL_TRANSPORT_INCOMPLETE = "The local Ceal transport could not complete; report this as a gap.";
|
|
724
805
|
var GATEWAY_TRANSPORT_UNAVAILABLE = "The Gateway transport is unavailable; ask an administrator to restore Gateway availability.";
|
|
725
806
|
var HOST_AUTHENTICATION_UNAVAILABLE = "The Host could not authenticate this invocation; report this as a gap.";
|
|
807
|
+
var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Relay to the same release as the Gateway, then retry.";
|
|
808
|
+
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.";
|
|
809
|
+
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.";
|
|
726
810
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
727
811
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
728
812
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
@@ -748,6 +832,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
748
832
|
refresh_expired: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
749
833
|
refresh_replayed: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
750
834
|
refresh_revoked: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
835
|
+
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
836
|
+
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
751
837
|
refresh_recovery_unavailable: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
752
838
|
refresh_custody_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
753
839
|
session_store_unwritable: guidance("The Ceal client could not write its local session store; the operating system refused the write (EACCES, EPERM, or EROFS). rerun_outside_agent_sandbox reruns it with escalated execution.", "rerun_outside_agent_sandbox", 500),
|
|
@@ -760,8 +846,9 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
760
846
|
response_encoding_failed: guidance("The local response could not be encoded; report this as a gap.", "answer_with_gap", 500),
|
|
761
847
|
request_timeout: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 504),
|
|
762
848
|
request_failed: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 502),
|
|
849
|
+
resource_stream_failed: guidance("The provider resource stream failed; ask an administrator to inspect the Gateway failure log.", "ask_admin", 500),
|
|
763
850
|
gateway_unavailable: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 503, true),
|
|
764
|
-
contract_mismatch: guidance(
|
|
851
|
+
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
765
852
|
// `gateway_starting` is the one retryable envelope the serving gate answers on every route while starting
|
|
766
853
|
// (`cli/internal/client/gateway_startup_wait.go` re-drives it); the sentence is the client default that renders
|
|
767
854
|
// when the wait ends still unserved, moved from the `localFailureText` default branch.
|
|
@@ -771,13 +858,12 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
771
858
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
772
859
|
internal_error: guidance("The Gateway failed without exposing internal state.", "answer_with_gap", 500),
|
|
773
860
|
// Owned by the Gateway canonical adapter (`gateway/core/src/gateway-canonical-operation-http-adapter.ts`):
|
|
774
|
-
// the client variant
|
|
861
|
+
// the static client variant was retired when the client started reading this table.
|
|
775
862
|
request_body_too_large: guidance("The Gateway request body exceeds its bounded limit.", "reduce_request_size", 413),
|
|
776
|
-
|
|
777
|
-
//
|
|
778
|
-
//
|
|
779
|
-
|
|
780
|
-
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),
|
|
863
|
+
gateway_response_too_large: guidance("The Gateway response exceeds its bounded limit; reduce the requested page or result size.", "reduce_request_size", 500),
|
|
864
|
+
// The safe move varies by request. Keep the sentence conditional on the
|
|
865
|
+
// same `retryable` and `next_action` facts the response exposes.
|
|
866
|
+
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
781
867
|
// Restored verbatim from the retired `localFailureText`
|
|
782
868
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
783
869
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -858,24 +944,27 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
858
944
|
// Host mint classifications. The CLI emits `invocation_authentication_unavailable` with the classification
|
|
859
945
|
// in its detail fact; rows without their own sentence share that code's moved sentence, while `next_action`
|
|
860
946
|
// is moved from `canonicalHostAuthenticationNextActions` (generated from `CEAL_HOST_AUTHENTICATION_POLICY`)
|
|
861
|
-
// and `retryable` from `hostAuthenticationFailureForCause` (
|
|
862
|
-
//
|
|
947
|
+
// and `retryable` from `hostAuthenticationFailureForCause` (the table's explicit retry verdict). Cause-specific
|
|
948
|
+
// sentences carry only remedies proved by the Host or Relay cause; generic Gateway refusals do not prove a release mismatch.
|
|
949
|
+
// Statuses are the
|
|
863
950
|
// Gateway-owned mapping decided with the operator 2026-10-13. This covers every wire cause the maps at
|
|
864
951
|
// `host/invocation-authentication-command.ts:217-242` emit, through their policy classifications.
|
|
865
952
|
host_arguments_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 400),
|
|
866
953
|
host_configuration_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
867
954
|
host_session_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 401),
|
|
868
|
-
//
|
|
869
|
-
//
|
|
870
|
-
host_context_unavailable: guidance(
|
|
871
|
-
|
|
872
|
-
|
|
955
|
+
// The bounded Host reason does not prove ephemerality. A Host refusal never
|
|
956
|
+
// changes mode; standalone remains the separate Client authority path.
|
|
957
|
+
host_context_unavailable: guidance(HOST_CONTEXT_UNAVAILABLE, "answer_with_gap", 401),
|
|
958
|
+
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),
|
|
959
|
+
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),
|
|
960
|
+
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),
|
|
873
961
|
host_source_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 403),
|
|
874
962
|
host_registration_credential_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 403),
|
|
875
963
|
host_mint_gateway_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "ask_admin", 503),
|
|
876
964
|
host_mint_gateway_rate_limited: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 429),
|
|
877
965
|
host_mint_gateway_refused: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
878
966
|
host_mint_gateway_response_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 502),
|
|
967
|
+
host_contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 502),
|
|
879
968
|
// Moved from the retired `CEAL_HOST_AUTHENTICATION_POLICY` remedy: the
|
|
880
969
|
// producer-frame fault names the administrator repair step.
|
|
881
970
|
host_producer_frame_invalid: guidance("Ask an administrator to inspect and repair the producer frame, then start a fresh Host turn.", "ask_admin", 400),
|
|
@@ -885,7 +974,7 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
885
974
|
host_relay_unavailable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 503),
|
|
886
975
|
host_mint_transient_retryable: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "retry", 503, true),
|
|
887
976
|
host_mint_failed: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500),
|
|
888
|
-
host_relay_failed: guidance(
|
|
977
|
+
host_relay_failed: guidance(HOST_INSTALL_REPAIR, "install_ceal_host", 502),
|
|
889
978
|
host_refusal_invalid: guidance(HOST_AUTHENTICATION_UNAVAILABLE, "answer_with_gap", 500)
|
|
890
979
|
});
|
|
891
980
|
function cealFailureGuidanceForCode(code) {
|
|
@@ -895,6 +984,147 @@ function cealFailureGuidanceForCode(code) {
|
|
|
895
984
|
}
|
|
896
985
|
var FAILURE_GUIDANCE_ENTRY_KEYS = Object.freeze(["message", "next_action", "http_status", "retryable", "redaction_class"]);
|
|
897
986
|
|
|
987
|
+
// packages/ceal-client-protocol/src/request-validation-primitives.ts
|
|
988
|
+
import { createHash } from "node:crypto";
|
|
989
|
+
|
|
990
|
+
// packages/ceal-client-protocol/src/operation-withheld-cause.ts
|
|
991
|
+
var CEAL_OPERATION_WITHHELD_CAUSES = vocabulary(["provider_permission", "access_level", "personal_authorization_required"]);
|
|
992
|
+
|
|
993
|
+
// packages/ceal-client-protocol/src/operation-contract-types.ts
|
|
994
|
+
var CEAL_JSON_SCHEMA_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
995
|
+
var CEAL_OPERATION_DESCRIPTOR_SCHEMA_VERSION = "ceal.operation_descriptor.v1";
|
|
996
|
+
var CEAL_OPERATION_ERROR_SCHEMA_VERSION = "ceal.operation_error.v1";
|
|
997
|
+
var CEAL_ARTIFACT_STAGE_TERMINALS = vocabulary(["chunk_accepted", "artifact_ready", "idempotency_replayed"]);
|
|
998
|
+
var CEAL_RETRY_AFTER_MAX_MS = 60 * 60 * 1e3;
|
|
999
|
+
var CEAL_JSON_SCHEMA_TYPES = vocabulary(["object", "array", "string", "integer", "number", "boolean", "null"]);
|
|
1000
|
+
var OBSERVATION_POSTURES = vocabulary(["direct_readback", "approved_no_readback", "operator_mediated", "excluded"]);
|
|
1001
|
+
var EFFECT_DOMAINS = vocabulary(["none", "gateway_state", "provider", "external_world"]);
|
|
1002
|
+
var SAFETY_CLASSES = vocabulary(["routine", "sensitive", "high_impact"]);
|
|
1003
|
+
var IDEMPOTENCY_CLASSES = vocabulary(["idempotent", "conditionally_idempotent", "non_idempotent"]);
|
|
1004
|
+
var REVERSIBILITY_CLASSES = vocabulary(["none", "reversible", "compensatable", "irreversible"]);
|
|
1005
|
+
var COMPENSATION_OWNERS = vocabulary(["none", "connector", "operator"]);
|
|
1006
|
+
var CANCELLATION_BOUNDARIES = vocabulary(["before_admission", "before_handoff", "after_handoff_reconcile"]);
|
|
1007
|
+
var HANDOFF_CLASSES = vocabulary(["not_applicable", "submission", "effect"]);
|
|
1008
|
+
var AUTHORITATIVE_READBACK_CLASSES = vocabulary(["required", "unavailable"]);
|
|
1009
|
+
var PROVIDER_READBACK_CLASSES = vocabulary(["required", "not_available", "not_applicable"]);
|
|
1010
|
+
var RECONCILIATION_CLASSES = vocabulary(["none", "automatic", "operator"]);
|
|
1011
|
+
var NO_READBACK_APPROVAL_CLASSES = vocabulary(["not_applicable", "explicit", "operator"]);
|
|
1012
|
+
var REPLAY_PREREQUISITES = vocabulary(["never", "fresh_admission", "reconciled_non_application", "operator_approval"]);
|
|
1013
|
+
var UNKNOWN_OUTCOMES = vocabulary(["reconcile", "operator_action", "excluded"]);
|
|
1014
|
+
var RECOVERY_OWNERS = vocabulary(["gateway", "connector", "operator"]);
|
|
1015
|
+
var CEAL_OPERATION_ADMISSION_STATES = vocabulary(["proposed", "refused", "admitted"]);
|
|
1016
|
+
var CEAL_OPERATION_EXECUTION_STATES = vocabulary(["not_started", "started", "completed"]);
|
|
1017
|
+
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_applicable", "not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
1018
|
+
var CEAL_OPERATION_EFFECT_STATES = vocabulary(["none", "applied", "failed", "unknown", "compensated"]);
|
|
1019
|
+
var CEAL_OPERATION_OBSERVATION_STATES = vocabulary(["not_started", "not_required", "pending", "observed", "unavailable"]);
|
|
1020
|
+
var CEAL_OPERATION_RECOVERY_KINDS = vocabulary(["none", "reconcile", "compensate", "operator_action"]);
|
|
1021
|
+
var CEAL_OPERATION_RECOVERY_STATUSES = vocabulary(["not_started", "active", "completed"]);
|
|
1022
|
+
var CEAL_OPERATION_PROVIDER_READBACK_AVAILABILITY = vocabulary(["not_started", "not_applicable", "not_available", "pending", "available"]);
|
|
1023
|
+
var CEAL_OPERATION_OFFERED_HANDOFF_STATES = vocabulary(["accepted", "rejected", "unknown"]);
|
|
1024
|
+
var CEAL_OPERATION_RECEIPT_AUTHORITY_KEYS = Object.freeze(["instance_ref", "access_group_ref", "principal_ref", "execution_subject_ref", "authority_revision_ref"]);
|
|
1025
|
+
var CEAL_OPERATION_APPROVAL_DISPOSITIONS = vocabulary([
|
|
1026
|
+
"approval_not_required_by_policy",
|
|
1027
|
+
"interactive_pending",
|
|
1028
|
+
"interactive_granted",
|
|
1029
|
+
"interactive_denied",
|
|
1030
|
+
"interactive_expired",
|
|
1031
|
+
"interactive_unavailable"
|
|
1032
|
+
]);
|
|
1033
|
+
|
|
1034
|
+
// packages/ceal-client-protocol/src/request-validation-primitives.ts
|
|
1035
|
+
var DIGEST = /^[a-f0-9]{64}$/u;
|
|
1036
|
+
var CEAL_SHA256_DIGEST_PATTERN = DIGEST.source;
|
|
1037
|
+
function isCealDigest(value) {
|
|
1038
|
+
return typeof value === "string" && DIGEST.test(value);
|
|
1039
|
+
}
|
|
1040
|
+
function cealRequestSha256(value) {
|
|
1041
|
+
return createHash("sha256").update(cealCanonicalJson(value), "utf8").digest("hex");
|
|
1042
|
+
}
|
|
1043
|
+
function operationRecord(value, message) {
|
|
1044
|
+
requireOperationRecord(value, message);
|
|
1045
|
+
return value;
|
|
1046
|
+
}
|
|
1047
|
+
function invalid(message) {
|
|
1048
|
+
throw new TypeError(message);
|
|
1049
|
+
}
|
|
1050
|
+
function requirePrefixedRef(value, prefix, message) {
|
|
1051
|
+
if (typeof value !== "string" || !SAFE_REF.test(value) || !value.startsWith(prefix)) invalid(message);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
// packages/ceal-client-protocol/src/request-authority.ts
|
|
1055
|
+
var CEAL_REQUEST_SCHEMA_VERSION = "ceal.request.v1";
|
|
1056
|
+
var CEAL_REQUEST_REF_MAX_CHARACTERS = 128;
|
|
1057
|
+
var CEAL_REQUEST_REF_PATTERN_SOURCE = "^ceal-request:[A-Za-z0-9][A-Za-z0-9._:-]{0,114}$";
|
|
1058
|
+
var CEAL_REQUEST_REF_PATTERN = new RegExp(CEAL_REQUEST_REF_PATTERN_SOURCE, "u");
|
|
1059
|
+
var CEAL_REQUEST_ARTIFACT_OWNERS = vocabulary(["gateway", "host", "connector"]);
|
|
1060
|
+
var CEAL_HOST_INVOCATION_IDENTITY_KEYS = vocabulary(["host_session_ref", "host_turn_ref", "host_source_ref"]);
|
|
1061
|
+
var CEAL_REQUEST_ARTIFACT_RETENTION_CLASSES = vocabulary(["request", "source", "result"]);
|
|
1062
|
+
var CANCELLATION_STATES = vocabulary(["requested", "cancelled"]);
|
|
1063
|
+
var CEAL_REQUEST_KEYS = Object.freeze(["schema_version", "ceal_request_ref", "created_at", "authority"]);
|
|
1064
|
+
var CEAL_REQUEST_COMMON_PROPERTIES = Object.freeze({
|
|
1065
|
+
schema_version: { type: "string", const: CEAL_REQUEST_SCHEMA_VERSION, maxLength: 32 },
|
|
1066
|
+
ceal_request_ref: { type: "string", minLength: 1, maxLength: CEAL_REQUEST_REF_MAX_CHARACTERS, pattern: CEAL_REQUEST_REF_PATTERN_SOURCE },
|
|
1067
|
+
created_at: { type: "string", minLength: 1, maxLength: 64 },
|
|
1068
|
+
authority: {
|
|
1069
|
+
type: "object",
|
|
1070
|
+
maxProperties: 5,
|
|
1071
|
+
additionalProperties: false,
|
|
1072
|
+
properties: {
|
|
1073
|
+
instance_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1074
|
+
access_group_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1075
|
+
principal_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1076
|
+
execution_subject_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1077
|
+
authority_revision_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source }
|
|
1078
|
+
},
|
|
1079
|
+
required: ["instance_ref", "access_group_ref", "principal_ref", "execution_subject_ref", "authority_revision_ref"]
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
var CEAL_REQUEST_HOST_PROPERTIES = Object.freeze({
|
|
1083
|
+
prompt_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1084
|
+
host_session_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1085
|
+
host_turn_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1086
|
+
host_source_turn_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source, description: "Original authenticated Host turn reference before Gateway Request call-group identity is derived; absent for older Requests." },
|
|
1087
|
+
host_input_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1088
|
+
host_source_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source }
|
|
1089
|
+
});
|
|
1090
|
+
var CEAL_REQUEST_CALLER_PROPERTIES = Object.freeze({
|
|
1091
|
+
caller_call_group_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source, description: "Gateway-minted call-group identity for a non-Host caller." },
|
|
1092
|
+
caller_call_input_sha256: { type: "string", minLength: 64, maxLength: 64, pattern: "^[a-f0-9]{64}$", description: "Commitment to the exact input for active non-Host identity-reuse checks; a migrated legacy call group commits to its legacy group key because the original input may no longer exist." }
|
|
1093
|
+
});
|
|
1094
|
+
var CEAL_REQUEST_OPTIONAL_PROPERTIES = Object.freeze({
|
|
1095
|
+
requester_timezone: { type: "string", minLength: 1, maxLength: 128, description: "IANA timezone observed for the requester on this Request." },
|
|
1096
|
+
device_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source, description: "Device that submitted this Request through its client session, including Host turns when the authenticated Host registration carries the device; absent for older records." }
|
|
1097
|
+
});
|
|
1098
|
+
var CEAL_REQUEST_HOST_REQUIRED_KEYS = Object.freeze([...CEAL_REQUEST_KEYS, ...CEAL_HOST_INVOCATION_IDENTITY_KEYS, "prompt_ref"]);
|
|
1099
|
+
var CEAL_REQUEST_CALLER_REQUIRED_KEYS = Object.freeze([...CEAL_REQUEST_KEYS, "caller_call_group_ref", "caller_call_input_sha256"]);
|
|
1100
|
+
var CEAL_REQUEST_JSON_SCHEMA = {
|
|
1101
|
+
type: "object",
|
|
1102
|
+
description: "A Request has exactly one creation identity: the complete Host tuple and prompt reference, or a caller call-group identity. Caller Requests retain no prompt reference or prompt body.",
|
|
1103
|
+
maxProperties: 14,
|
|
1104
|
+
additionalProperties: false,
|
|
1105
|
+
properties: {
|
|
1106
|
+
...CEAL_REQUEST_COMMON_PROPERTIES,
|
|
1107
|
+
...CEAL_REQUEST_HOST_PROPERTIES,
|
|
1108
|
+
...CEAL_REQUEST_CALLER_PROPERTIES,
|
|
1109
|
+
...CEAL_REQUEST_OPTIONAL_PROPERTIES
|
|
1110
|
+
},
|
|
1111
|
+
required: CEAL_REQUEST_KEYS,
|
|
1112
|
+
anyOf: [
|
|
1113
|
+
{
|
|
1114
|
+
type: "object",
|
|
1115
|
+
required: CEAL_REQUEST_HOST_REQUIRED_KEYS,
|
|
1116
|
+
properties: { ...CEAL_REQUEST_COMMON_PROPERTIES, ...CEAL_REQUEST_HOST_PROPERTIES, ...CEAL_REQUEST_OPTIONAL_PROPERTIES },
|
|
1117
|
+
additionalProperties: false
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
type: "object",
|
|
1121
|
+
required: CEAL_REQUEST_CALLER_REQUIRED_KEYS,
|
|
1122
|
+
properties: { ...CEAL_REQUEST_COMMON_PROPERTIES, ...CEAL_REQUEST_CALLER_PROPERTIES, ...CEAL_REQUEST_OPTIONAL_PROPERTIES },
|
|
1123
|
+
additionalProperties: false
|
|
1124
|
+
}
|
|
1125
|
+
]
|
|
1126
|
+
};
|
|
1127
|
+
|
|
898
1128
|
// packages/ceal-client-protocol/src/client-wire-contract.ts
|
|
899
1129
|
var CEAL_CLIENT_WIRE_CONTRACT = Object.freeze(client_wire_contract_default);
|
|
900
1130
|
var CEAL_CLIENT_DOCTOR_SCHEMA_VERSION = CEAL_CLIENT_WIRE_CONTRACT.doctor.schema_version;
|
|
@@ -907,7 +1137,7 @@ function deriveCealClientWireSchemaVersion(schema) {
|
|
|
907
1137
|
throw new TypeError("Client wire schema name or field set is invalid.");
|
|
908
1138
|
}
|
|
909
1139
|
const fields = schema.fields.filter((field) => field !== "schema_version").sort();
|
|
910
|
-
const hash8 =
|
|
1140
|
+
const hash8 = createHash2("sha256").update(cealCanonicalJson(fields), "utf8").digest("hex").slice(0, 8);
|
|
911
1141
|
return `${schema.schema_name}.v1.${hash8}`;
|
|
912
1142
|
}
|
|
913
1143
|
var CealClientWireContractMismatchError = class extends Error {
|
|
@@ -945,57 +1175,14 @@ var CEAL_COMMAND_REQUEST_SCHEMA_VERSION = deriveCealClientWireSchemaVersion(requ
|
|
|
945
1175
|
var CEAL_COMMAND_REQUEST_MAX_BYTES = request.absolute_transport_max_bytes;
|
|
946
1176
|
var CEAL_COMMAND_RESPONSE_BARE_DOCUMENT_MAX_BYTES = response.bare_document_max_bytes;
|
|
947
1177
|
var CEAL_COMMAND_RESPONSE_BARE_DOCUMENT_OPTIONAL_FIELDS = Object.freeze([...response.bare_document_optional_fields]);
|
|
948
|
-
var CEAL_COMMAND_RESPONSE_DISCOVERY_COMMAND = response.discovery_command;
|
|
949
1178
|
var CEAL_COMMAND_RESPONSE_DISCOVERY_MANIFEST_SCHEMA_VERSION = deriveCealClientWireSchemaVersion({ schema_name: response.discovery_manifest_schema_name, fields: response.discovery_manifest_fields });
|
|
950
1179
|
var CEAL_COMMAND_RESPONSE_SCHEMA_VERSION = deriveCealClientWireSchemaVersion(response);
|
|
951
|
-
var CEAL_COMMAND_RESPONSE_DISCOVERY_MANIFEST_DOCUMENT_FIELDS = Object.freeze([...response.discovery_manifest_document_fields]);
|
|
952
1180
|
var CEAL_COMMAND_RESPONSE_MAX_BYTES = CEAL_ENCODED_JSON_DOCUMENT_MAX_BYTES;
|
|
953
1181
|
var CEAL_RESOURCE_STREAM_REQUEST_SCHEMA_VERSION = deriveCealClientWireSchemaVersion({ schema_name: CEAL_CLIENT_WIRE_CONTRACT.resource_stream.request_schema_name, fields: CEAL_CLIENT_WIRE_CONTRACT.resource_stream.request_fields });
|
|
954
1182
|
var CEAL_RESOURCE_STREAM_REQUEST_FIELDS = Object.freeze([...CEAL_CLIENT_WIRE_CONTRACT.resource_stream.request_fields]);
|
|
955
1183
|
|
|
956
|
-
// packages/ceal-client-protocol/src/
|
|
957
|
-
var
|
|
958
|
-
|
|
959
|
-
// packages/ceal-client-protocol/src/operation-contract-types.ts
|
|
960
|
-
var CEAL_JSON_SCHEMA_2020_12 = "https://json-schema.org/draft/2020-12/schema";
|
|
961
|
-
var CEAL_OPERATION_DESCRIPTOR_SCHEMA_VERSION = "ceal.operation_descriptor.v1";
|
|
962
|
-
var CEAL_OPERATION_ERROR_SCHEMA_VERSION = "ceal.operation_error.v1";
|
|
963
|
-
var CEAL_ARTIFACT_STAGE_TERMINALS = vocabulary(["chunk_accepted", "artifact_ready", "idempotency_replayed"]);
|
|
964
|
-
var CEAL_RETRY_AFTER_MAX_MS = 60 * 60 * 1e3;
|
|
965
|
-
var CEAL_JSON_SCHEMA_TYPES = vocabulary(["object", "array", "string", "integer", "number", "boolean", "null"]);
|
|
966
|
-
var OBSERVATION_POSTURES = vocabulary(["direct_readback", "approved_no_readback", "operator_mediated", "excluded"]);
|
|
967
|
-
var EFFECT_DOMAINS = vocabulary(["none", "gateway_state", "provider", "external_world"]);
|
|
968
|
-
var SAFETY_CLASSES = vocabulary(["routine", "sensitive", "high_impact"]);
|
|
969
|
-
var IDEMPOTENCY_CLASSES = vocabulary(["idempotent", "conditionally_idempotent", "non_idempotent"]);
|
|
970
|
-
var REVERSIBILITY_CLASSES = vocabulary(["none", "reversible", "compensatable", "irreversible"]);
|
|
971
|
-
var COMPENSATION_OWNERS = vocabulary(["none", "connector", "operator"]);
|
|
972
|
-
var CANCELLATION_BOUNDARIES = vocabulary(["before_admission", "before_handoff", "after_handoff_reconcile"]);
|
|
973
|
-
var HANDOFF_CLASSES = vocabulary(["not_applicable", "submission", "effect"]);
|
|
974
|
-
var AUTHORITATIVE_READBACK_CLASSES = vocabulary(["required", "unavailable"]);
|
|
975
|
-
var PROVIDER_READBACK_CLASSES = vocabulary(["required", "not_available", "not_applicable"]);
|
|
976
|
-
var RECONCILIATION_CLASSES = vocabulary(["none", "automatic", "operator"]);
|
|
977
|
-
var NO_READBACK_APPROVAL_CLASSES = vocabulary(["not_applicable", "explicit", "operator"]);
|
|
978
|
-
var REPLAY_PREREQUISITES = vocabulary(["never", "fresh_admission", "reconciled_non_application", "operator_approval"]);
|
|
979
|
-
var UNKNOWN_OUTCOMES = vocabulary(["reconcile", "operator_action", "excluded"]);
|
|
980
|
-
var RECOVERY_OWNERS = vocabulary(["gateway", "connector", "operator"]);
|
|
981
|
-
var CEAL_OPERATION_ADMISSION_STATES = vocabulary(["proposed", "refused", "admitted"]);
|
|
982
|
-
var CEAL_OPERATION_EXECUTION_STATES = vocabulary(["not_started", "started", "completed"]);
|
|
983
|
-
var CEAL_OPERATION_PROVIDER_HANDOFF_STATES = vocabulary(["not_offered", "offered", "accepted", "rejected", "unknown"]);
|
|
984
|
-
var CEAL_OPERATION_EFFECT_STATES = vocabulary(["none", "applied", "failed", "unknown", "compensated"]);
|
|
985
|
-
var CEAL_OPERATION_OBSERVATION_STATES = vocabulary(["not_started", "not_required", "pending", "observed", "unavailable"]);
|
|
986
|
-
var CEAL_OPERATION_RECOVERY_KINDS = vocabulary(["none", "reconcile", "compensate", "operator_action"]);
|
|
987
|
-
var CEAL_OPERATION_RECOVERY_STATUSES = vocabulary(["not_started", "active", "completed"]);
|
|
988
|
-
var CEAL_OPERATION_PROVIDER_READBACK_AVAILABILITY = vocabulary(["not_started", "not_applicable", "not_available", "pending", "available"]);
|
|
989
|
-
var CEAL_OPERATION_OFFERED_HANDOFF_STATES = vocabulary(["accepted", "rejected", "unknown"]);
|
|
990
|
-
var CEAL_OPERATION_RECEIPT_AUTHORITY_KEYS = Object.freeze(["instance_ref", "access_group_ref", "principal_ref", "execution_subject_ref", "authority_revision_ref"]);
|
|
991
|
-
var CEAL_OPERATION_APPROVAL_DISPOSITIONS = vocabulary([
|
|
992
|
-
"approval_not_required_by_policy",
|
|
993
|
-
"interactive_pending",
|
|
994
|
-
"interactive_granted",
|
|
995
|
-
"interactive_denied",
|
|
996
|
-
"interactive_expired",
|
|
997
|
-
"interactive_unavailable"
|
|
998
|
-
]);
|
|
1184
|
+
// packages/ceal-client-protocol/src/access-level-vocabulary.ts
|
|
1185
|
+
var CEAL_ACCESS_LEVELS = vocabulary(["none", "read", "read_write"]);
|
|
999
1186
|
|
|
1000
1187
|
// packages/ceal-client-protocol/src/operation-access-class.ts
|
|
1001
1188
|
var CEAL_OPERATION_ACCESS_CLASSES = vocabulary(["read", "write"]);
|
|
@@ -1003,7 +1190,7 @@ var CEAL_OPERATION_ACCESS_CLASSES = vocabulary(["read", "write"]);
|
|
|
1003
1190
|
// packages/ceal-client-protocol/src/domain-vocabulary.ts
|
|
1004
1191
|
var CEAL_CONNECTOR_STATUSES = vocabulary(["active", "disabled", "disconnected"]);
|
|
1005
1192
|
var CEAL_CONNECTOR_CUSTODIES = vocabulary(["organization", "personal"]);
|
|
1006
|
-
var
|
|
1193
|
+
var CEAL_PROVIDER_BOUNDARY_FIELDS = vocabulary(["provider_boundary_ref", "provider_boundary_kind", "provider_boundary_label", "provider_native_id", "provider_boundary_evidence"]);
|
|
1007
1194
|
var CEAL_PERSONAL_ACCESS_CEILINGS = vocabulary(["disabled", "read", "read_write"]);
|
|
1008
1195
|
var CEAL_TARGET_REF_PATTERN = "^[^\\p{Cc}]+$";
|
|
1009
1196
|
var TARGET_REF = new RegExp(CEAL_TARGET_REF_PATTERN, "u");
|
|
@@ -1049,7 +1236,7 @@ var JSON_DESCRIPTION_CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
|
1049
1236
|
var CEAL_OPERATION_AUTHORITY_POLICY_KEYS = Object.freeze(["access_group", "instance_binding", "target", "admission_recheck"]);
|
|
1050
1237
|
var MAX_OPERATION_INPUT_RESOLVER_BINDINGS = 96;
|
|
1051
1238
|
var CEAL_OPERATION_DESCRIPTOR_REQUIRED_ENVELOPE_KEYS = Object.freeze(["schema_version", "id", "input_contract", "result_contract", "policy"]);
|
|
1052
|
-
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary"]);
|
|
1239
|
+
var CEAL_OPERATION_DESCRIPTOR_OPTIONAL_ENVELOPE_KEYS = Object.freeze(["input_resolution", "summary", "standard_names"]);
|
|
1053
1240
|
|
|
1054
1241
|
// packages/ceal-client-protocol/src/operation-catalog.ts
|
|
1055
1242
|
var CEAL_OPERATION_CATALOG_SCHEMA_VERSION = "ceal.catalog.v3";
|
|
@@ -1111,6 +1298,7 @@ var CEAL_SCHEMA_LITERALS = [
|
|
|
1111
1298
|
"ceal.gateway_write_receipt_readback.v1",
|
|
1112
1299
|
"ceal.gateway_write_request_receipt.v1",
|
|
1113
1300
|
"ceal.host_observation.v1",
|
|
1301
|
+
"ceal.host_usage_batch.v1",
|
|
1114
1302
|
"ceal.host_registration_request.v1",
|
|
1115
1303
|
"ceal.host_registration_result.v1",
|
|
1116
1304
|
CEAL_OPERATION_DESCRIPTOR_SCHEMA_VERSION,
|
|
@@ -1139,18 +1327,22 @@ var CEAL_SCHEMA_LITERAL_SET = new Set(CEAL_SCHEMA_LITERALS);
|
|
|
1139
1327
|
import { join } from "node:path";
|
|
1140
1328
|
var CEAL_BOUNDED_SERIES_CATALOG = Object.freeze({
|
|
1141
1329
|
bounded_store_sidecar: (root) => `${root}.jsonl`,
|
|
1142
|
-
gateway_audit_archive: (root) => `${root}.jsonl`,
|
|
1143
1330
|
gateway_access_group_connector_control_audit: (root) => `${root}.audit.jsonl`,
|
|
1144
1331
|
gateway_access_group_connector_scope_audit: (root) => join(root, "profile-connector-scope-audit.jsonl"),
|
|
1145
1332
|
gateway_access_group_connector_activity_scope_audit: (root) => join(root, "profile-connector-activity-scope-audit.jsonl"),
|
|
1146
1333
|
gateway_access_group_connector_calendar_scope_audit: (root) => join(root, "profile-connector-calendar-scope-audit.jsonl"),
|
|
1147
1334
|
gateway_access_group_connector_readiness_audit: (root) => join(root, "profile-connector-readiness.audit.jsonl"),
|
|
1335
|
+
gateway_deployment_events: (root) => join(root, "gateway-deployments.jsonl"),
|
|
1148
1336
|
gateway_organization_audit_ledger: (root) => join(root, "organization-ledger.jsonl"),
|
|
1149
1337
|
gateway_personal_client_audit: (root) => join(root, "audit.jsonl"),
|
|
1150
1338
|
gateway_personal_client_access_audit: (root) => join(root, "access-audit.jsonl")
|
|
1151
1339
|
});
|
|
1152
1340
|
|
|
1153
1341
|
// packages/ceal-client-protocol/src/canonical-http-boundary.ts
|
|
1342
|
+
var CEAL_HTTP_CLIENT_EXCHANGE_REF_HEADER = "x-ceal-client-exchange-ref";
|
|
1343
|
+
var CEAL_HTTP_GATEWAY_REQUEST_REF_HEADER = "x-ceal-gateway-http-request-ref";
|
|
1344
|
+
var CEAL_HTTP_CLIENT_EXCHANGE_REF_PATTERN_SOURCE = "^client-exchange:[a-f0-9]{32}$";
|
|
1345
|
+
var CEAL_HTTP_GATEWAY_REQUEST_REF_PATTERN_SOURCE = "^http-request:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
|
1154
1346
|
var CEAL_CANONICAL_HTTP_MAX_RESPONSE_BYTES = CEAL_COMMAND_RESPONSE_MAX_BYTES;
|
|
1155
1347
|
|
|
1156
1348
|
// packages/ceal-client-protocol/src/gateway-installation-activation.ts
|
|
@@ -1174,6 +1366,11 @@ var CEAL_HOST_INSTALLATION_REF_PATTERN = new RegExp(`^host-installation:${CEAL_L
|
|
|
1174
1366
|
var CEAL_HOST_SOURCE_REF_PATTERN = new RegExp(`^host-source:${CEAL_LOWERCASE_UUID_PATTERN}$`, "u");
|
|
1175
1367
|
var CEAL_HOST_ACCESS_TOKEN_PATTERN = /^ceal_host_[A-Za-z0-9_-]{43}$/u;
|
|
1176
1368
|
|
|
1369
|
+
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1370
|
+
var CEAL_RESOURCE_GET_NOTION_CONTENT_GAP_KINDS = Object.freeze(["subtree", "media", "property_schema", "properties"]);
|
|
1371
|
+
var CEAL_RESOURCE_SEARCH_PROVIDER_STATUSES = vocabulary(["done", "pending", "deferred"]);
|
|
1372
|
+
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1373
|
+
|
|
1177
1374
|
// packages/ceal-client-protocol/src/operation-result-completeness.ts
|
|
1178
1375
|
var CEAL_READ_VALUE_CONTINUATION_KEYS = vocabulary(["continuation", "continuation_ref", "next_cursor"]);
|
|
1179
1376
|
|
|
@@ -1191,7 +1388,7 @@ function shellSingleQuoted(value) {
|
|
|
1191
1388
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
1192
1389
|
}
|
|
1193
1390
|
var CEAL_OPERATION_CONTRACT_REQUIRED_FIELDS = Object.freeze(["input_schema", "result_schema"]);
|
|
1194
|
-
var CEAL_OPERATION_CONTRACT_OPTIONAL_FIELDS = Object.freeze(["summary", "input_resolution"]);
|
|
1391
|
+
var CEAL_OPERATION_CONTRACT_OPTIONAL_FIELDS = Object.freeze(["branches", "summary", "input_resolution"]);
|
|
1195
1392
|
var CEAL_VERIFIED_ARTIFACT_DESCRIPTOR_JSON_SCHEMA = Object.freeze({
|
|
1196
1393
|
$schema: CEAL_JSON_SCHEMA_2020_12,
|
|
1197
1394
|
$id: "https://ceal.dev/schemas/verified-artifact-descriptor.v1.schema.json",
|
|
@@ -1236,11 +1433,93 @@ var OPTIONAL_FIELDS = CEAL_CLIENT_WIRE_CONTRACT.command_response.bare_document_o
|
|
|
1236
1433
|
// packages/ceal-client-protocol/src/actor-kind.ts
|
|
1237
1434
|
var CEAL_ACTOR_KINDS = vocabulary(["human", "bot", "app", "unknown"]);
|
|
1238
1435
|
|
|
1436
|
+
// packages/ceal-client-protocol/src/provider-link-policy.ts
|
|
1437
|
+
var PROVIDER_LINK_RESULT_FIELDS = Object.freeze({
|
|
1438
|
+
read_row: Object.freeze({ human_link: "source_url", parent_context: Object.freeze(["thread_ref"]) }),
|
|
1439
|
+
write_result: Object.freeze({ human_links: Object.freeze(["user_openable_url", "url", "spreadsheet_url", "meet_url"]) })
|
|
1440
|
+
});
|
|
1441
|
+
var PROVIDER_LINK_CONFORMANCE_TABLE = Object.freeze([
|
|
1442
|
+
{ provider: "slack", result_kind: "message_read_row", field: "source_url", status: "required_when_provider_supplies", provider_shape: "message permalink or the existing canonical workspace/channel/timestamp permalink", source: "https://docs.slack.dev/reference/methods/chat.getPermalink/" },
|
|
1443
|
+
{ provider: "slack", result_kind: "message_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "chat.getPermalink result permalink", source: "https://docs.slack.dev/reference/methods/chat.getPermalink/" },
|
|
1444
|
+
{ provider: "slack", result_kind: "message_update_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "chat.getPermalink result permalink after verified readback", source: "https://docs.slack.dev/reference/methods/chat.getPermalink/" },
|
|
1445
|
+
{ provider: "slack", result_kind: "file_read_row", field: "source_url", status: "required_when_provider_supplies", provider_shape: "file permalink; url_private and url_private_download are excluded", source: "https://docs.slack.dev/reference/objects/file-object/" },
|
|
1446
|
+
{ provider: "slack", result_kind: "file_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "file permalink; url_private and url_private_download are excluded", source: "https://docs.slack.dev/reference/objects/file-object/" },
|
|
1447
|
+
{ provider: "notion", result_kind: "page_read_row", field: "source_url", status: "required_when_provider_supplies", provider_shape: "page url matching the returned page id", source: "https://developers.notion.com/reference/page" },
|
|
1448
|
+
{ provider: "notion", result_kind: "page_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "page url matching the verified page id", source: "https://developers.notion.com/reference/page" },
|
|
1449
|
+
{ provider: "github", result_kind: "issue_pull_request_code_release_read_row", field: "source_url", status: "required_when_provider_supplies", provider_shape: "html_url", source: "https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28" },
|
|
1450
|
+
{ provider: "github", result_kind: "issue_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "verified readback html_url", source: "https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28" },
|
|
1451
|
+
{ provider: "github", result_kind: "issue_update_write_result", field: "url", status: "required_when_provider_supplies", provider_shape: "verified readback html_url; replay receipts omit links without provider readback", source: "https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28" },
|
|
1452
|
+
{ provider: "github", result_kind: "pull_request_review_write_result", field: "url", status: "required_when_provider_supplies", provider_shape: "submitted review html_url", source: "https://docs.github.com/en/rest/pulls/reviews" },
|
|
1453
|
+
{ provider: "github", result_kind: "comment_write_result", field: "user_openable_url", status: "required_when_provider_supplies", provider_shape: "issue comment html_url from provider readback", source: "https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28" },
|
|
1454
|
+
{ provider: "google-workspace", result_kind: "drive_file_read_row", field: "source_url", status: "required_when_provider_supplies", provider_shape: "webViewLink", source: "https://developers.google.com/workspace/drive/api/reference/rest/v3/files" },
|
|
1455
|
+
{ 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" },
|
|
1456
|
+
{ 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" },
|
|
1457
|
+
{ 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" },
|
|
1458
|
+
{ 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" },
|
|
1459
|
+
{ 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" },
|
|
1460
|
+
{ 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" },
|
|
1461
|
+
{ 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" },
|
|
1462
|
+
{ provider: "google-workspace", result_kind: "gmail_message_write_result", field: "user_openable_url", status: "not_available", reason: "The Gmail API Message representation exposes id and threadId but no human UI URL; no URL is reconstructed.", source: "https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages#Message" }
|
|
1463
|
+
]);
|
|
1464
|
+
var PROVIDER_LINK_HOSTS = Object.freeze({
|
|
1465
|
+
notion: Object.freeze(["notion.so", "www.notion.so", "notion.com", "www.notion.com", "app.notion.com"]),
|
|
1466
|
+
google_workspace: Object.freeze([
|
|
1467
|
+
"calendar.google.com",
|
|
1468
|
+
"contacts.google.com",
|
|
1469
|
+
"docs.google.com",
|
|
1470
|
+
"drive.google.com",
|
|
1471
|
+
"forms.google.com",
|
|
1472
|
+
"mail.google.com",
|
|
1473
|
+
"meet.google.com",
|
|
1474
|
+
"sites.google.com",
|
|
1475
|
+
"www.google.com"
|
|
1476
|
+
])
|
|
1477
|
+
});
|
|
1478
|
+
var NOTION_SOURCE_HOSTS = new Set(PROVIDER_LINK_HOSTS.notion);
|
|
1479
|
+
var GOOGLE_WORKSPACE_SOURCE_HOSTS = new Set(PROVIDER_LINK_HOSTS.google_workspace);
|
|
1480
|
+
var PROVIDER_RESOURCE_SOURCE_URL_SCHEMA = Object.freeze({
|
|
1481
|
+
type: "string",
|
|
1482
|
+
minLength: 1,
|
|
1483
|
+
maxLength: 2048,
|
|
1484
|
+
pattern: SAFE_EXTERNAL_HTTPS_URL_WITH_FRAGMENT_PATTERN_SOURCE,
|
|
1485
|
+
description: "A provider-owned human link for this exact resource; include it when available. Rows without a provider UI link, such as Gmail messages, are cited by title and date."
|
|
1486
|
+
});
|
|
1487
|
+
var PROVIDER_USER_OPENABLE_URL_SCHEMA = Object.freeze({
|
|
1488
|
+
type: "string",
|
|
1489
|
+
minLength: 1,
|
|
1490
|
+
maxLength: 2048,
|
|
1491
|
+
pattern: SAFE_EXTERNAL_HTTPS_URL_WITH_FRAGMENT_PATTERN_SOURCE,
|
|
1492
|
+
description: "The provider-owned human URL for the written resource, when the provider response or verified readback supplies one. Ceal does not construct a fallback URL."
|
|
1493
|
+
});
|
|
1494
|
+
|
|
1239
1495
|
// packages/ceal-client-protocol/src/resource-row.ts
|
|
1240
1496
|
var CEAL_RESOURCE_ROW_TITLE_MATCH_DISPOSITIONS = vocabulary(["exact", "not_exact", "unknown"]);
|
|
1241
1497
|
var CEAL_RESOURCE_SEARCH_ORDERS = vocabulary(["relevance", "modified", "viewed", "created"]);
|
|
1242
1498
|
var CEAL_RESOURCE_SEARCH_DIRECTIONS = vocabulary(["ascending", "descending"]);
|
|
1243
|
-
var CEAL_RESOURCE_SEARCH_FILTERS = vocabulary([
|
|
1499
|
+
var CEAL_RESOURCE_SEARCH_FILTERS = vocabulary([
|
|
1500
|
+
"query",
|
|
1501
|
+
"modified_since",
|
|
1502
|
+
"since",
|
|
1503
|
+
"until",
|
|
1504
|
+
"filetype",
|
|
1505
|
+
"authored_by_me",
|
|
1506
|
+
"authored_by",
|
|
1507
|
+
"edited_by",
|
|
1508
|
+
"include_replies",
|
|
1509
|
+
"kinds",
|
|
1510
|
+
"container_ref",
|
|
1511
|
+
"container_refs",
|
|
1512
|
+
"container_names",
|
|
1513
|
+
"addressed_to_me",
|
|
1514
|
+
"unread",
|
|
1515
|
+
"archived",
|
|
1516
|
+
"state",
|
|
1517
|
+
"event_types",
|
|
1518
|
+
"starred",
|
|
1519
|
+
"trashed",
|
|
1520
|
+
"permission"
|
|
1521
|
+
]);
|
|
1522
|
+
var CEAL_RESOURCE_SEARCH_STATES = vocabulary(["open", "closed", "draft", "prerelease", "confirmed", "tentative", "cancelled"]);
|
|
1244
1523
|
var CEAL_RESOURCE_TIME_BASES = vocabulary(["created", "modified", "viewed"]);
|
|
1245
1524
|
var CEAL_REPOSITORY_VISIBILITIES = vocabulary(["public", "private", "internal"]);
|
|
1246
1525
|
var CEAL_ACTIVITY_V3_KINDS = vocabulary(["authored", "edited", "messaged", "responded"]);
|
|
@@ -1336,6 +1615,8 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
1336
1615
|
container_label: { required: true, timestamp: false },
|
|
1337
1616
|
container_ref: { required: false, timestamp: false },
|
|
1338
1617
|
source_url: { required: false, timestamp: false },
|
|
1618
|
+
thread_ref: { required: false, timestamp: false },
|
|
1619
|
+
reply_count: { required: false, timestamp: false },
|
|
1339
1620
|
source: { required: true, timestamp: false },
|
|
1340
1621
|
owner: { required: false, timestamp: false },
|
|
1341
1622
|
actor_kind: { required: false, timestamp: false },
|
|
@@ -1344,6 +1625,7 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
1344
1625
|
created_at: { required: false, timestamp: true },
|
|
1345
1626
|
created_at_local: { required: false, timestamp: true },
|
|
1346
1627
|
modified_at: { required: false, timestamp: true },
|
|
1628
|
+
observed_at: { required: false, timestamp: true },
|
|
1347
1629
|
modified_at_local: { required: false, timestamp: true },
|
|
1348
1630
|
viewed_by_me_at: { required: false, timestamp: true },
|
|
1349
1631
|
modified_by_me_at: { required: false, timestamp: true },
|
|
@@ -1361,6 +1643,7 @@ var RESOURCE_ROW_KEY_RULES = Object.freeze({
|
|
|
1361
1643
|
start: { required: false, timestamp: false },
|
|
1362
1644
|
end: { required: false, timestamp: false },
|
|
1363
1645
|
status: { required: false, timestamp: false },
|
|
1646
|
+
event_type: { required: false, timestamp: false },
|
|
1364
1647
|
snippet: { required: false, timestamp: false },
|
|
1365
1648
|
dated_notes: { required: false, timestamp: false },
|
|
1366
1649
|
state: { required: true, timestamp: false },
|
|
@@ -1370,9 +1653,6 @@ var RESOURCE_ROW_REQUIRED_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(
|
|
|
1370
1653
|
var RESOURCE_ROW_KEYS = new Set(Object.keys(RESOURCE_ROW_KEY_RULES));
|
|
1371
1654
|
var RESOURCE_ROW_TIMESTAMP_KEYS = Object.entries(RESOURCE_ROW_KEY_RULES).flatMap(([key, rule]) => rule.timestamp ? [key] : []);
|
|
1372
1655
|
|
|
1373
|
-
// packages/ceal-client-protocol/src/resource-read-result.ts
|
|
1374
|
-
var CEAL_RESOURCE_GET_COVERAGE_NEXT_ACTIONS = vocabulary(["reduce_request_size", "read_resource_again"]);
|
|
1375
|
-
|
|
1376
1656
|
// packages/ceal-client-protocol/src/excluded-target-coverage.ts
|
|
1377
1657
|
var CEAL_EXCLUDED_TARGET_COVERAGE_MAX_ENTRIES = 64;
|
|
1378
1658
|
function cealExcludedTargetCoverageJsonSchema() {
|
|
@@ -1424,6 +1704,8 @@ var CEAL_REFRESH_FAILURE_CODES = vocabulary([
|
|
|
1424
1704
|
"refresh_inactive",
|
|
1425
1705
|
"refresh_replayed",
|
|
1426
1706
|
"refresh_revoked",
|
|
1707
|
+
"person_inactive",
|
|
1708
|
+
"principal_inactive",
|
|
1427
1709
|
"authority_replaced",
|
|
1428
1710
|
"refresh_recovery_unavailable",
|
|
1429
1711
|
"refresh_recovery_expired",
|
|
@@ -1444,97 +1726,6 @@ var PERSONAL_CLIENT_TOKEN_SUFFIX_PATTERN = "[A-Za-z0-9_-]{43}";
|
|
|
1444
1726
|
var CEAL_PERSONAL_CLIENT_ACCESS_TOKEN = new RegExp(`^${CEAL_PERSONAL_CLIENT_ACCESS_TOKEN_PREFIX}${PERSONAL_CLIENT_TOKEN_SUFFIX_PATTERN}$`, "u");
|
|
1445
1727
|
var CEAL_PERSONAL_CLIENT_REFRESH_TOKEN = new RegExp(`^${CEAL_PERSONAL_CLIENT_REFRESH_TOKEN_PREFIX}${PERSONAL_CLIENT_TOKEN_SUFFIX_PATTERN}$`, "u");
|
|
1446
1728
|
|
|
1447
|
-
// packages/ceal-client-protocol/src/request-validation-primitives.ts
|
|
1448
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
1449
|
-
var DIGEST = /^[a-f0-9]{64}$/u;
|
|
1450
|
-
var CEAL_SHA256_DIGEST_PATTERN = DIGEST.source;
|
|
1451
|
-
function isCealDigest(value) {
|
|
1452
|
-
return typeof value === "string" && DIGEST.test(value);
|
|
1453
|
-
}
|
|
1454
|
-
function cealRequestSha256(value) {
|
|
1455
|
-
return createHash2("sha256").update(cealCanonicalJson(value), "utf8").digest("hex");
|
|
1456
|
-
}
|
|
1457
|
-
function operationRecord(value, message) {
|
|
1458
|
-
requireOperationRecord(value, message);
|
|
1459
|
-
return value;
|
|
1460
|
-
}
|
|
1461
|
-
function invalid(message) {
|
|
1462
|
-
throw new TypeError(message);
|
|
1463
|
-
}
|
|
1464
|
-
function requirePrefixedRef(value, prefix, message) {
|
|
1465
|
-
if (typeof value !== "string" || !SAFE_REF.test(value) || !value.startsWith(prefix)) invalid(message);
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
// packages/ceal-client-protocol/src/request-authority.ts
|
|
1469
|
-
var CEAL_REQUEST_SCHEMA_VERSION = "ceal.request.v1";
|
|
1470
|
-
var CEAL_REQUEST_ARTIFACT_OWNERS = vocabulary(["gateway", "host", "connector"]);
|
|
1471
|
-
var CEAL_HOST_INVOCATION_IDENTITY_KEYS = vocabulary(["host_session_ref", "host_turn_ref", "host_source_ref"]);
|
|
1472
|
-
var CEAL_REQUEST_ARTIFACT_RETENTION_CLASSES = vocabulary(["request", "source", "result"]);
|
|
1473
|
-
var CANCELLATION_STATES = vocabulary(["requested", "cancelled"]);
|
|
1474
|
-
var CEAL_REQUEST_KEYS = Object.freeze(["schema_version", "ceal_request_ref", "created_at", "authority"]);
|
|
1475
|
-
var CEAL_REQUEST_COMMON_PROPERTIES = Object.freeze({
|
|
1476
|
-
schema_version: { type: "string", const: CEAL_REQUEST_SCHEMA_VERSION, maxLength: 32 },
|
|
1477
|
-
ceal_request_ref: { type: "string", minLength: 1, maxLength: 128, pattern: "^ceal-request:[A-Za-z0-9][A-Za-z0-9._:-]{0,114}$" },
|
|
1478
|
-
created_at: { type: "string", minLength: 1, maxLength: 64 },
|
|
1479
|
-
authority: {
|
|
1480
|
-
type: "object",
|
|
1481
|
-
maxProperties: 5,
|
|
1482
|
-
additionalProperties: false,
|
|
1483
|
-
properties: {
|
|
1484
|
-
instance_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1485
|
-
access_group_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1486
|
-
principal_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1487
|
-
execution_subject_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1488
|
-
authority_revision_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source }
|
|
1489
|
-
},
|
|
1490
|
-
required: ["instance_ref", "access_group_ref", "principal_ref", "execution_subject_ref", "authority_revision_ref"]
|
|
1491
|
-
}
|
|
1492
|
-
});
|
|
1493
|
-
var CEAL_REQUEST_HOST_PROPERTIES = Object.freeze({
|
|
1494
|
-
prompt_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1495
|
-
host_session_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1496
|
-
host_turn_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1497
|
-
host_input_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source },
|
|
1498
|
-
host_source_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source }
|
|
1499
|
-
});
|
|
1500
|
-
var CEAL_REQUEST_CALLER_PROPERTIES = Object.freeze({
|
|
1501
|
-
caller_call_group_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source, description: "Gateway-minted call-group identity for a non-Host caller." },
|
|
1502
|
-
caller_call_input_sha256: { type: "string", minLength: 64, maxLength: 64, pattern: "^[a-f0-9]{64}$", description: "Commitment to the exact input for active non-Host identity-reuse checks; a migrated legacy call group commits to its legacy group key because the original input may no longer exist." }
|
|
1503
|
-
});
|
|
1504
|
-
var CEAL_REQUEST_OPTIONAL_PROPERTIES = Object.freeze({
|
|
1505
|
-
requester_timezone: { type: "string", minLength: 1, maxLength: 128, description: "IANA timezone observed for the requester on this Request." },
|
|
1506
|
-
device_ref: { type: "string", minLength: 1, maxLength: 128, pattern: SAFE_REF.source, description: "Device that submitted this Request through its client session, including Host turns when the authenticated Host registration carries the device; absent for older records." }
|
|
1507
|
-
});
|
|
1508
|
-
var CEAL_REQUEST_HOST_REQUIRED_KEYS = Object.freeze([...CEAL_REQUEST_KEYS, ...CEAL_HOST_INVOCATION_IDENTITY_KEYS, "prompt_ref"]);
|
|
1509
|
-
var CEAL_REQUEST_CALLER_REQUIRED_KEYS = Object.freeze([...CEAL_REQUEST_KEYS, "caller_call_group_ref", "caller_call_input_sha256"]);
|
|
1510
|
-
var CEAL_REQUEST_JSON_SCHEMA = {
|
|
1511
|
-
type: "object",
|
|
1512
|
-
description: "A Request has exactly one creation identity: the complete Host tuple and prompt reference, or a caller call-group identity. Caller Requests retain no prompt reference or prompt body.",
|
|
1513
|
-
maxProperties: 13,
|
|
1514
|
-
additionalProperties: false,
|
|
1515
|
-
properties: {
|
|
1516
|
-
...CEAL_REQUEST_COMMON_PROPERTIES,
|
|
1517
|
-
...CEAL_REQUEST_HOST_PROPERTIES,
|
|
1518
|
-
...CEAL_REQUEST_CALLER_PROPERTIES,
|
|
1519
|
-
...CEAL_REQUEST_OPTIONAL_PROPERTIES
|
|
1520
|
-
},
|
|
1521
|
-
required: CEAL_REQUEST_KEYS,
|
|
1522
|
-
anyOf: [
|
|
1523
|
-
{
|
|
1524
|
-
type: "object",
|
|
1525
|
-
required: CEAL_REQUEST_HOST_REQUIRED_KEYS,
|
|
1526
|
-
properties: { ...CEAL_REQUEST_COMMON_PROPERTIES, ...CEAL_REQUEST_HOST_PROPERTIES, ...CEAL_REQUEST_OPTIONAL_PROPERTIES },
|
|
1527
|
-
additionalProperties: false
|
|
1528
|
-
},
|
|
1529
|
-
{
|
|
1530
|
-
type: "object",
|
|
1531
|
-
required: CEAL_REQUEST_CALLER_REQUIRED_KEYS,
|
|
1532
|
-
properties: { ...CEAL_REQUEST_COMMON_PROPERTIES, ...CEAL_REQUEST_CALLER_PROPERTIES, ...CEAL_REQUEST_OPTIONAL_PROPERTIES },
|
|
1533
|
-
additionalProperties: false
|
|
1534
|
-
}
|
|
1535
|
-
]
|
|
1536
|
-
};
|
|
1537
|
-
|
|
1538
1729
|
// packages/ceal-client-protocol/src/request-operands.ts
|
|
1539
1730
|
var CEAL_REQUEST_MAX_RESOLVER_SELECTIONS = 128;
|
|
1540
1731
|
var CEAL_REQUEST_MAX_SELECTOR_PROPERTIES = 16;
|
|
@@ -1642,6 +1833,27 @@ var CEAL_REQUEST_RUN_BATCH_JSON_SCHEMA = {
|
|
|
1642
1833
|
required: ["schema_version", "order", "nodes", "call_budget"]
|
|
1643
1834
|
};
|
|
1644
1835
|
|
|
1836
|
+
// packages/ceal-client-protocol/src/host-observation-validation.ts
|
|
1837
|
+
var CEAL_REQUEST_MAX_OBSERVATION_VALUE_BYTES = 64 * 1024;
|
|
1838
|
+
var HOST_RESERVED_KEY = /^(?:access_group|admission|approval|audit|authorization|cancellation|capability|effect|grant|occurrence|operation|policy|profile|provider_readback|receipt|reconciliation|replay|target|write_request)(?:_|$)/iu;
|
|
1839
|
+
function validateCealHostObservationValue(value) {
|
|
1840
|
+
if (value === void 0) throw new TypeError("Ceal Host observation value is invalid.");
|
|
1841
|
+
assertSafeJsonValue(value, { forbidAuthorityKeys: true, maxNodes: 512 });
|
|
1842
|
+
if (byteLength(JSON.stringify(value) ?? "") > CEAL_REQUEST_MAX_OBSERVATION_VALUE_BYTES) throw new TypeError("Ceal Host observation value is oversized.");
|
|
1843
|
+
inspectHostKeys(value);
|
|
1844
|
+
}
|
|
1845
|
+
function inspectHostKeys(value) {
|
|
1846
|
+
if (Array.isArray(value)) {
|
|
1847
|
+
for (const entry2 of value) inspectHostKeys(entry2);
|
|
1848
|
+
return;
|
|
1849
|
+
}
|
|
1850
|
+
if (value === null || typeof value !== "object") return;
|
|
1851
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1852
|
+
if (HOST_RESERVED_KEY.test(key)) throw new TypeError("Ceal Host observation cannot restate Gateway-owned facts.");
|
|
1853
|
+
inspectHostKeys(child);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1645
1857
|
// packages/ceal-client-protocol/src/host-observation.ts
|
|
1646
1858
|
var CEAL_HOST_OBSERVATION_REF_PREFIX = "host-observation:";
|
|
1647
1859
|
var HOST_TOKEN_OBSERVATION_BREAKDOWN_KEYS = vocabulary(["cached_input", "cache_write_input", "reasoning_output"]);
|
|
@@ -1652,31 +1864,20 @@ function validateCealHostObservationDraft(value) {
|
|
|
1652
1864
|
requireIsoTimestamp(record6.observed_at, "Ceal Host observation time is invalid.");
|
|
1653
1865
|
assertHostObservationValue(record6.value, record6.observation_kind);
|
|
1654
1866
|
}
|
|
1655
|
-
var CEAL_REQUEST_MAX_OBSERVATION_VALUE_BYTES = 64 * 1024;
|
|
1656
1867
|
var CEAL_HOST_OBSERVATION_KINDS = vocabulary(["prompt", "session", "turn", "model", "token", "timing"]);
|
|
1657
1868
|
function isCealHostPromptObservationValue(value) {
|
|
1658
1869
|
return isOperationRecord(value) && Object.keys(value).length === 1 && isCealDigest(value.body_sha256);
|
|
1659
1870
|
}
|
|
1660
|
-
var HOST_RESERVED_KEY = /^(?:access_group|admission|approval|audit|authorization|cancellation|capability|effect|grant|occurrence|operation|policy|profile|provider_readback|receipt|reconciliation|replay|target|write_request)(?:_|$)/iu;
|
|
1661
1871
|
function assertHostObservationValue(value, kind) {
|
|
1662
1872
|
if (value === void 0) invalid("Ceal Host observation value is invalid.");
|
|
1663
1873
|
if (kind === "prompt" && !isCealHostPromptObservationValue(value)) invalid("Ceal Host prompt observation must contain only its body digest.");
|
|
1664
|
-
|
|
1665
|
-
if (byteLength(JSON.stringify(value) ?? "") > CEAL_REQUEST_MAX_OBSERVATION_VALUE_BYTES) invalid("Ceal Host observation value is oversized.");
|
|
1666
|
-
inspectHostKeys(value);
|
|
1667
|
-
}
|
|
1668
|
-
function inspectHostKeys(value) {
|
|
1669
|
-
if (Array.isArray(value)) {
|
|
1670
|
-
for (const entry2 of value) inspectHostKeys(entry2);
|
|
1671
|
-
return;
|
|
1672
|
-
}
|
|
1673
|
-
if (value === null || typeof value !== "object") return;
|
|
1674
|
-
for (const [key, child] of Object.entries(value)) {
|
|
1675
|
-
if (HOST_RESERVED_KEY.test(key)) invalid("Ceal Host observation cannot restate Gateway-owned facts.");
|
|
1676
|
-
inspectHostKeys(child);
|
|
1677
|
-
}
|
|
1874
|
+
validateCealHostObservationValue(value);
|
|
1678
1875
|
}
|
|
1679
1876
|
|
|
1877
|
+
// packages/ceal-client-protocol/src/host-usage-facts.ts
|
|
1878
|
+
var CEAL_HOST_USAGE_BATCH_MAX_BYTES = 1024 * 1024;
|
|
1879
|
+
var CEAL_HOST_USAGE_FACT_MAX_BYTES = 64 * 1024;
|
|
1880
|
+
|
|
1680
1881
|
// packages/ceal-client-protocol/src/host-prompt-ref.ts
|
|
1681
1882
|
var CEAL_HOST_PROMPT_DIGEST_PATTERN = "^[a-f0-9]{64}$";
|
|
1682
1883
|
var PROMPT_DIGEST = new RegExp(CEAL_HOST_PROMPT_DIGEST_PATTERN, "u");
|
|
@@ -1777,6 +1978,7 @@ var CEAL_HOST_INVOCATION_AUTHENTICATION_REQUEST_SCHEMA = deriveCealClientWireSch
|
|
|
1777
1978
|
var CEAL_HOST_INVOCATION_AUTHENTICATION_REQUEST_FIELDS = Object.freeze([...hostInvocationAuthenticationContract.request_fields]);
|
|
1778
1979
|
var CEAL_HOST_INVOCATION_AUTHENTICATION_RESULT_SCHEMA = deriveCealClientWireSchemaVersion({ schema_name: hostInvocationAuthenticationContract.result_schema_name, fields: hostInvocationAuthenticationContract.result_fields });
|
|
1779
1980
|
var CEAL_HOST_INVOCATION_AUTHENTICATION_RESULT_FIELDS = Object.freeze([...hostInvocationAuthenticationContract.result_fields]);
|
|
1981
|
+
var CEAL_HOST_INVOCATION_AUTHENTICATION_REFUSAL_SCHEMA = deriveCealClientWireSchemaVersion({ schema_name: hostInvocationAuthenticationContract.refusal_schema_name, fields: hostInvocationAuthenticationContract.refusal_fields });
|
|
1780
1982
|
var CEAL_HOST_AUTHENTICATION_BUDGET_PATTERN_SOURCE = "^(?:0|[1-9][0-9]{0,8})$";
|
|
1781
1983
|
var CEAL_HOST_AUTHENTICATION_BUDGET_PATTERN = new RegExp(CEAL_HOST_AUTHENTICATION_BUDGET_PATTERN_SOURCE, "u");
|
|
1782
1984
|
var CEAL_HOST_INVOCATION_CONTEXT_PATH = "/api/ceal/v2/host-invocation-context";
|
|
@@ -1794,7 +1996,7 @@ function decodeCealHostInvocationContextRequest(value) {
|
|
|
1794
1996
|
const clientNonce = requireClientNonce(value.client_nonce);
|
|
1795
1997
|
const expiresAt = requireContextExpiration(value.context_expires_at);
|
|
1796
1998
|
const hostBinding = requireHostBinding(value.host_binding);
|
|
1797
|
-
const messageWindow =
|
|
1999
|
+
const messageWindow = decodeCealHostInvocationHumanMessageWindow(value.human_message_window);
|
|
1798
2000
|
const lastRequestRef = optionalSafeReference(value.last_seen_request_ref);
|
|
1799
2001
|
const visibleOutputMaxBytes = optionalVisibleOutputBudget(value.visible_output_max_bytes);
|
|
1800
2002
|
return Object.freeze({
|
|
@@ -1825,7 +2027,7 @@ function requireHostBinding(value) {
|
|
|
1825
2027
|
if (!isCealJsonRecord(value) || !exactOptionalKeys(value, ["host_source_ref", "host_session_ref", "host_turn_ref"], []) || !safeReference(value.host_source_ref) || !safeReference(value.host_session_ref) || !safeReference(value.host_turn_ref)) throw invalidInvocationContextRequest();
|
|
1826
2028
|
return { host_source_ref: value.host_source_ref, host_session_ref: value.host_session_ref, host_turn_ref: value.host_turn_ref };
|
|
1827
2029
|
}
|
|
1828
|
-
function
|
|
2030
|
+
function decodeCealHostInvocationHumanMessageWindow(value) {
|
|
1829
2031
|
if (!isCealJsonRecord(value) || !exactOptionalKeys(value, ["messages", "truncated"], []) || !Array.isArray(value.messages) || value.messages.length > CEAL_HOST_INVOCATION_HUMAN_MESSAGE_WINDOW_MAX_MESSAGES || typeof value.truncated !== "boolean") throw invalidInvocationContextRequest();
|
|
1830
2032
|
const messages = value.messages.map(decodeHumanMessage);
|
|
1831
2033
|
const bytes2 = new TextEncoder().encode(JSON.stringify(messages)).byteLength;
|
|
@@ -1833,8 +2035,9 @@ function requireHumanMessageWindow(value) {
|
|
|
1833
2035
|
return Object.freeze({ messages: Object.freeze(messages), truncated: value.truncated });
|
|
1834
2036
|
}
|
|
1835
2037
|
function decodeHumanMessage(candidate) {
|
|
1836
|
-
if (!isCealJsonRecord(candidate) || !exactOptionalKeys(candidate, ["host_turn_ref", "host_input_ref", "text"], []) || !safeReference(candidate.host_turn_ref) || !safeReference(candidate.host_input_ref) || typeof candidate.text !== "string") throw invalidInvocationContextRequest();
|
|
1837
|
-
|
|
2038
|
+
if (!isCealJsonRecord(candidate) || !exactOptionalKeys(candidate, ["host_turn_ref", "host_input_ref", "text"], ["text_truncated"]) || !safeReference(candidate.host_turn_ref) || !safeReference(candidate.host_input_ref) || typeof candidate.text !== "string") throw invalidInvocationContextRequest();
|
|
2039
|
+
if (candidate.text_truncated !== void 0 && candidate.text_truncated !== true) throw invalidInvocationContextRequest();
|
|
2040
|
+
return Object.freeze({ host_turn_ref: candidate.host_turn_ref, host_input_ref: candidate.host_input_ref, text: candidate.text, ...candidate.text_truncated === true ? { text_truncated: candidate.text_truncated } : {} });
|
|
1838
2041
|
}
|
|
1839
2042
|
function optionalSafeReference(value) {
|
|
1840
2043
|
if (value === void 0) return void 0;
|
|
@@ -1865,40 +2068,20 @@ function deriveCealHostInvocationNonceContract(contract = CEAL_CLIENT_WIRE_CONTR
|
|
|
1865
2068
|
};
|
|
1866
2069
|
}
|
|
1867
2070
|
var hostNonceContract = deriveCealHostInvocationNonceContract();
|
|
1868
|
-
var CEAL_HOST_NONCE_ENCODED_CHARACTERS = hostNonceContract.encoded_characters;
|
|
1869
2071
|
var CEAL_HOST_CLIENT_NONCE_PATTERN = new RegExp(hostNonceContract.client_nonce_pattern_source, "u");
|
|
1870
2072
|
var CEAL_HOST_CONTEXT_TOKEN_PATTERN = new RegExp(hostNonceContract.context_token_pattern_source, "u");
|
|
1871
|
-
var CEAL_HOST_INVOCATION_AUTHENTICATION_RESULT_MAX_BYTES = deriveCealHostInvocationAuthenticationResultMaxBytes();
|
|
1872
|
-
function deriveCealHostInvocationAuthenticationResultMaxBytes(contract = CEAL_CLIENT_WIRE_CONTRACT) {
|
|
1873
|
-
const hostAuthentication = contract.host_invocation_authentication;
|
|
1874
|
-
const values = {
|
|
1875
|
-
schema_version: deriveCealClientWireSchemaVersion({ schema_name: hostAuthentication.result_schema_name, fields: hostAuthentication.result_fields }),
|
|
1876
|
-
context_token: `${CEAL_HOST_CONTEXT_TOKEN_PREFIX}${"A".repeat(hostAuthentication.client_nonce.encoded_characters)}`,
|
|
1877
|
-
expires_at: (/* @__PURE__ */ new Date("+010000-01-01T00:00:00.000Z")).toISOString()
|
|
1878
|
-
};
|
|
1879
|
-
const fields = hostAuthentication.result_fields;
|
|
1880
|
-
if (fields.some((field) => !Object.hasOwn(values, field))) throw new TypeError("Host invocation result fields have no bounded sample value.");
|
|
1881
|
-
return new TextEncoder().encode(`${JSON.stringify(Object.fromEntries(fields.map((field) => [field, values[field]])))}
|
|
1882
|
-
`).byteLength;
|
|
1883
|
-
}
|
|
1884
2073
|
var CEAL_HOST_MINT_REQUEST_CONTEXT_REFUSAL_REASONS = vocabulary([
|
|
1885
2074
|
"request_authority_unavailable",
|
|
1886
|
-
"
|
|
1887
|
-
"authority_mismatch",
|
|
1888
|
-
"host_source_mismatch",
|
|
1889
|
-
"host_session_mismatch",
|
|
1890
|
-
"host_turn_mismatch",
|
|
1891
|
-
"host_input_mismatch",
|
|
1892
|
-
"host_prompt_mismatch"
|
|
2075
|
+
"request_creation_refused"
|
|
1893
2076
|
]);
|
|
1894
2077
|
var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
1895
2078
|
"invalid_arguments",
|
|
1896
2079
|
"options_invalid",
|
|
1897
2080
|
"session_unavailable",
|
|
1898
2081
|
"context_unavailable",
|
|
2082
|
+
"activation_wait_exhausted",
|
|
1899
2083
|
"context_replaced",
|
|
1900
2084
|
"no_binding",
|
|
1901
|
-
"context_stale",
|
|
1902
2085
|
"context_expired",
|
|
1903
2086
|
"host_source_refused",
|
|
1904
2087
|
"host_credential_refused",
|
|
@@ -1915,23 +2098,35 @@ var CEAL_HOST_AUTHENTICATION_CAUSES = vocabulary([
|
|
|
1915
2098
|
"relay_failed",
|
|
1916
2099
|
"host_refusal_invalid"
|
|
1917
2100
|
]);
|
|
2101
|
+
var CEAL_HOST_RELAY_EXCHANGE_FAILURES = vocabulary([
|
|
2102
|
+
"permission_denied",
|
|
2103
|
+
"socket_missing",
|
|
2104
|
+
"connection_refused",
|
|
2105
|
+
"closed_early",
|
|
2106
|
+
"response_invalid",
|
|
2107
|
+
"timed_out",
|
|
2108
|
+
"cancelled",
|
|
2109
|
+
"unavailable"
|
|
2110
|
+
]);
|
|
1918
2111
|
var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
1919
2112
|
invalid_arguments: Object.freeze({ classification: "host_arguments_invalid", next_action: "answer_with_gap" }),
|
|
1920
2113
|
options_invalid: Object.freeze({ classification: "host_configuration_invalid", next_action: "answer_with_gap" }),
|
|
1921
2114
|
session_unavailable: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
1922
|
-
|
|
1923
|
-
|
|
2115
|
+
// This reason cannot distinguish a Codex side conversation from a missing
|
|
2116
|
+
// context in a regular session, so guidance must leave that choice to the caller.
|
|
2117
|
+
context_unavailable: Object.freeze({ classification: "host_context_unavailable", next_action: "answer_with_gap" }),
|
|
2118
|
+
activation_wait_exhausted: Object.freeze({ classification: "host_context_activation_wait_exhausted", next_action: "retry_after" }),
|
|
2119
|
+
context_replaced: Object.freeze({ classification: "host_invocation_context_stale", next_action: "answer_with_gap" }),
|
|
1924
2120
|
// `no_binding` now means the producer has no real current Host session. The
|
|
1925
2121
|
// Host Relay never uses it for an uncreated Gateway Request; there is no
|
|
1926
2122
|
// useful retry until the consumer is running inside a Host session.
|
|
1927
2123
|
no_binding: Object.freeze({ classification: "host_session_unavailable", next_action: "answer_with_gap" }),
|
|
1928
|
-
|
|
1929
|
-
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "retry" }),
|
|
2124
|
+
context_expired: Object.freeze({ classification: "host_invocation_context_expired", next_action: "answer_with_gap" }),
|
|
1930
2125
|
host_source_refused: Object.freeze({ classification: "host_source_refused", next_action: "answer_with_gap" }),
|
|
1931
2126
|
host_credential_refused: Object.freeze({ classification: "host_registration_credential_refused", next_action: "ask_admin" }),
|
|
1932
2127
|
gateway_unavailable: Object.freeze({ classification: "host_mint_gateway_unavailable", next_action: "ask_admin" }),
|
|
1933
2128
|
gateway_rate_limited: Object.freeze({ classification: "host_mint_gateway_rate_limited", next_action: "answer_with_gap" }),
|
|
1934
|
-
contract_mismatch: Object.freeze({ classification: "
|
|
2129
|
+
contract_mismatch: Object.freeze({ classification: "host_contract_mismatch", next_action: "upgrade_ceal_client" }),
|
|
1935
2130
|
gateway_refused: Object.freeze({ classification: "host_mint_gateway_refused", next_action: "answer_with_gap" }),
|
|
1936
2131
|
gateway_response_invalid: Object.freeze({ classification: "host_mint_gateway_response_invalid", next_action: "answer_with_gap" }),
|
|
1937
2132
|
producer_frame_invalid: Object.freeze({ classification: "host_producer_frame_invalid", next_action: "ask_admin" }),
|
|
@@ -1939,7 +2134,7 @@ var CEAL_HOST_AUTHENTICATION_POLICY = Object.freeze({
|
|
|
1939
2134
|
relay_unavailable: Object.freeze({ classification: "host_relay_unavailable", next_action: "answer_with_gap" }),
|
|
1940
2135
|
transient_retryable: Object.freeze({ classification: "host_mint_transient_retryable", next_action: "retry" }),
|
|
1941
2136
|
mint_failed: Object.freeze({ classification: "host_mint_failed", next_action: "answer_with_gap" }),
|
|
1942
|
-
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "
|
|
2137
|
+
relay_failed: Object.freeze({ classification: "host_relay_failed", next_action: "install_ceal_host" }),
|
|
1943
2138
|
host_refusal_invalid: Object.freeze({ classification: "host_refusal_invalid", next_action: "answer_with_gap" })
|
|
1944
2139
|
});
|
|
1945
2140
|
function decodeCealHostInvocationAuthenticationResult(value, now = /* @__PURE__ */ new Date()) {
|
|
@@ -1971,10 +2166,13 @@ var CEAL_HOST_SERVICE_DIAGNOSTIC_EVENTS = vocabulary([
|
|
|
1971
2166
|
"activation_recorded",
|
|
1972
2167
|
"activation_failed",
|
|
1973
2168
|
"watcher_scan_failed",
|
|
2169
|
+
"usage_capture_failed",
|
|
2170
|
+
"usage_upload_failed",
|
|
1974
2171
|
"activation_wait_skipped",
|
|
1975
2172
|
"activation_wait_engaged",
|
|
1976
2173
|
"activation_wait_completed",
|
|
1977
|
-
"activation_wait_exhausted"
|
|
2174
|
+
"activation_wait_exhausted",
|
|
2175
|
+
"invocation_authentication_failed"
|
|
1978
2176
|
]);
|
|
1979
2177
|
var CEAL_HOST_SERVICE_DIAGNOSTIC_FAILURE_KINDS = vocabulary([
|
|
1980
2178
|
"malformed_line",
|
|
@@ -1984,11 +2182,19 @@ var CEAL_HOST_SERVICE_DIAGNOSTIC_FAILURE_KINDS = vocabulary([
|
|
|
1984
2182
|
"size_budget",
|
|
1985
2183
|
"symlink"
|
|
1986
2184
|
]);
|
|
2185
|
+
var CEAL_HOST_SERVICE_DIAGNOSTIC_WATCHER_OPTIONAL_FIELDS = vocabulary(["failure_kind", "cause"]);
|
|
2186
|
+
var CEAL_HOST_SERVICE_DIAGNOSTIC_AUTHENTICATION_OPTIONAL_FIELDS = vocabulary(["cause"]);
|
|
2187
|
+
var CEAL_HOST_SERVICE_DIAGNOSTIC_CAUSE_PATTERN_SOURCE = "^[a-z][a-z0-9_]{0,63}(?::[A-Za-z][A-Za-z0-9_]{0,63})?$";
|
|
2188
|
+
var CEAL_HOST_SERVICE_DIAGNOSTIC_AUTHENTICATION_CAUSES = Object.freeze([
|
|
2189
|
+
...CEAL_HOST_AUTHENTICATION_CAUSES,
|
|
2190
|
+
...CEAL_HOST_RELAY_EXCHANGE_FAILURES.map((failure) => `relay_exchange:${failure}`)
|
|
2191
|
+
]);
|
|
2192
|
+
var hostServiceDiagnosticCausePattern = new RegExp(CEAL_HOST_SERVICE_DIAGNOSTIC_CAUSE_PATTERN_SOURCE, "u");
|
|
1987
2193
|
|
|
1988
2194
|
// packages/ceal-client-protocol/src/client-result-materialization.ts
|
|
1989
2195
|
var CEAL_UNREAD_REASONS = vocabulary(["blocked", "unavailable", "too_large", "unsupported", "download_failed", "permission_denied"]);
|
|
1990
2196
|
var REQUIRED_FIELDS2 = Object.freeze(["schema_version", "operation_id", "path", "sha256"]);
|
|
1991
|
-
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "
|
|
2197
|
+
var FIELDS = /* @__PURE__ */ new Set([...REQUIRED_FIELDS2, "local_result_root", "request_context_argv", "how_to_read"]);
|
|
1992
2198
|
|
|
1993
2199
|
// packages/ceal-client-protocol/src/discovery-manifest.ts
|
|
1994
2200
|
var DISCOVERY_MANIFEST_KEYS = CEAL_CLIENT_WIRE_CONTRACT.command_response.discovery_manifest_fields;
|
|
@@ -2070,12 +2276,14 @@ var ADMIN_SOURCE_OWNERS = vocabulary([
|
|
|
2070
2276
|
"resource",
|
|
2071
2277
|
"prompt",
|
|
2072
2278
|
"usage",
|
|
2279
|
+
"provider_request_lifecycle",
|
|
2073
2280
|
"connector",
|
|
2074
2281
|
"session",
|
|
2075
2282
|
"knowledge",
|
|
2076
2283
|
"policy"
|
|
2077
2284
|
]);
|
|
2078
2285
|
var ADMIN_COMPLETENESS_STATES = vocabulary(["complete", "partial", "unknown"]);
|
|
2286
|
+
var ADMIN_PROVIDER_REQUEST_CAPTURE_HEALTH_STATES = vocabulary(["available", "missing", "invalid", "unreadable"]);
|
|
2079
2287
|
var ADMIN_OPERATION_OUTCOMES = vocabulary(["completed", "failed", "denied", "cancelled", "unknown"]);
|
|
2080
2288
|
var ADMIN_APPROVAL_DISPOSITIONS = CEAL_OPERATION_APPROVAL_DISPOSITIONS;
|
|
2081
2289
|
var ADMIN_APPROVAL_POSTURES = vocabulary([...ADMIN_APPROVAL_DISPOSITIONS, "not_applicable"]);
|
|
@@ -2099,13 +2307,16 @@ var FAILURE_RESPONSE_KEYS = Object.freeze(["error", "ok", "proof_ref_or_unavaila
|
|
|
2099
2307
|
// host/invocation-authentication-client-command.ts
|
|
2100
2308
|
var MAX_DETAIL_CHARACTERS = 240;
|
|
2101
2309
|
var HOST_OWNED_CODE = /^[a-z][a-z0-9]*(?:_[a-z0-9]+){0,7}$/u;
|
|
2310
|
+
function isHostOwnedFailureCode(value) {
|
|
2311
|
+
return typeof value === "string" && HOST_OWNED_CODE.test(value);
|
|
2312
|
+
}
|
|
2102
2313
|
function hostTerminalFailure(error, component) {
|
|
2103
2314
|
const code = errorCode(error);
|
|
2104
2315
|
const detail = failureDetail(error);
|
|
2105
2316
|
if (code === "ENOENT") return { code: "host_dependency_unavailable", message: `A command or file the ${component} Host needs is unavailable: ${detail}`, next_action: "Install the missing dependency or restore the missing file, then rerun this command." };
|
|
2106
2317
|
if (code === "EACCES" || code === "EPERM") return { code: "host_permission_denied", message: `The ${component} Host was refused access to a local path: ${detail}`, next_action: "Repair the ownership or mode of the named path, then rerun this command." };
|
|
2107
2318
|
if (code === "ENOSPC") return { code: "host_storage_unavailable", message: `The ${component} Host could not write local state: ${detail}`, next_action: "Free local disk space, then rerun this command." };
|
|
2108
|
-
if (
|
|
2319
|
+
if (isHostOwnedFailureCode(code)) return { code, message: `The ${component} Host command failed: ${detail}`, next_action: `Resolve the named failure above; run \`ceal-host doctor\` only if it reports installed ${component} Host drift.` };
|
|
2109
2320
|
return { code: "host_failure_unclassified", message: `The ${component} Host command failed for a cause it cannot classify: ${detail}`, next_action: `Run \`ceal-host doctor\`; if it reports no drift then the ${component} Host configuration is not the cause, and the message above is the only evidence of what is.` };
|
|
2110
2321
|
}
|
|
2111
2322
|
var DOCTOR_FLAGS = Object.freeze({
|
|
@@ -2130,7 +2341,7 @@ import { dirname as dirname2, isAbsolute, posix, win32 as win322 } from "node:pa
|
|
|
2130
2341
|
import { execFile } from "node:child_process";
|
|
2131
2342
|
import { constants } from "node:fs";
|
|
2132
2343
|
import { lstat, open } from "node:fs/promises";
|
|
2133
|
-
import { dirname, win32 } from "node:path";
|
|
2344
|
+
import { dirname, join as join2, win32 } from "node:path";
|
|
2134
2345
|
import { fileURLToPath } from "node:url";
|
|
2135
2346
|
var SecureFileCustodyError = class extends Error {
|
|
2136
2347
|
name = "SecureFileCustodyError";
|
|
@@ -2191,7 +2402,7 @@ async function assertWindowsIdentityStable(handle, first, path) {
|
|
|
2191
2402
|
}
|
|
2192
2403
|
async function readPrivateFileWithSecurefs(path, maxBytes, custody = {}) {
|
|
2193
2404
|
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) throw new TypeError("The securefs read bound must be a positive safe integer.");
|
|
2194
|
-
const result2 = await
|
|
2405
|
+
const result2 = await runSecurefsCommand(["internal", "securefs", "read-private-file", path, String(maxBytes)], maxBytes, custody);
|
|
2195
2406
|
if (result2.exit_code === 0 && result2.stderr.length === 0 && result2.stdout.length <= maxBytes) return result2.stdout;
|
|
2196
2407
|
if (result2.stdout.length !== 0) throw new SecureFileCustodyError("unavailable", "The Windows Host securefs command returned bytes with a refusal.");
|
|
2197
2408
|
if (result2.exit_code === 0) throw new SecureFileCustodyError("unavailable", "The Windows Host securefs command exceeded its output contract.");
|
|
@@ -2199,16 +2410,22 @@ async function readPrivateFileWithSecurefs(path, maxBytes, custody = {}) {
|
|
|
2199
2410
|
}
|
|
2200
2411
|
async function createRandomPrivateFileWithSecurefs(path, byteLength2, custody = {}) {
|
|
2201
2412
|
if (!Number.isSafeInteger(byteLength2) || byteLength2 < 1 || byteLength2 > WINDOWS_SECUREFS_MAX_RANDOM_FILE_BYTES) throw new TypeError(`The securefs random-file size must be between 1 and ${WINDOWS_SECUREFS_MAX_RANDOM_FILE_BYTES} bytes.`);
|
|
2202
|
-
const result2 = await
|
|
2413
|
+
const result2 = await runSecurefsCommand(["internal", "securefs", "create-random-private-file", path, String(byteLength2)], 0, custody);
|
|
2203
2414
|
if (result2.exit_code === 0 && result2.stdout.length === 0 && result2.stderr.length === 0) return;
|
|
2204
2415
|
if (result2.stdout.length !== 0) throw new SecureFileCustodyError("unavailable", "The Windows Host securefs command returned unexpected creation bytes.");
|
|
2205
2416
|
if (result2.exit_code === 0) throw new SecureFileCustodyError("unavailable", "The Windows Host securefs command returned an invalid creation result.");
|
|
2206
2417
|
throw securefsRefusal(result2.stderr);
|
|
2207
2418
|
}
|
|
2419
|
+
async function ensurePrivateDirectoryWithSecurefs(path, custody = {}) {
|
|
2420
|
+
const result2 = await runSecurefsCommand(["internal", "securefs", "ensure-private-dir", path], 0, custody);
|
|
2421
|
+
if (result2.exit_code === 0 && result2.stdout.length === 0 && result2.stderr.length === 0) return;
|
|
2422
|
+
if (result2.stdout.length !== 0 || result2.exit_code === 0) throw new SecureFileCustodyError("unavailable", "The Windows Host securefs command returned an invalid directory result.");
|
|
2423
|
+
throw securefsRefusal(result2.stderr);
|
|
2424
|
+
}
|
|
2208
2425
|
async function isPrivateWindowsDirectory(path, custody = {}) {
|
|
2209
2426
|
await lstat(path);
|
|
2210
2427
|
try {
|
|
2211
|
-
const result2 = await
|
|
2428
|
+
const result2 = await runSecurefsCommand(["internal", "securefs", "verify-private-dir", path], 0, custody);
|
|
2212
2429
|
if (result2.exit_code === 0 && result2.stdout.length === 0 && result2.stderr.length === 0) return true;
|
|
2213
2430
|
if (result2.stdout.length !== 0) throw new SecureFileCustodyError("unavailable", "The Windows Host directory proof returned unexpected bytes.");
|
|
2214
2431
|
if (result2.exit_code === 0) throw new SecureFileCustodyError("unavailable", "The Windows Host directory proof returned an invalid result.");
|
|
@@ -2220,12 +2437,12 @@ async function isPrivateWindowsDirectory(path, custody = {}) {
|
|
|
2220
2437
|
throw new SecureFileCustodyError("unavailable", "The Windows Host directory custody proof is unavailable.");
|
|
2221
2438
|
}
|
|
2222
2439
|
}
|
|
2223
|
-
async function
|
|
2224
|
-
if (custody.run_securefs_command !== void 0) return await custody.run_securefs_command(args);
|
|
2225
|
-
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable();
|
|
2440
|
+
async function runSecurefsCommand(args, maxBytes, custody, stdin) {
|
|
2441
|
+
if (custody.run_securefs_command !== void 0) return await custody.run_securefs_command(args, stdin);
|
|
2442
|
+
const executable = custody.securefs_executable ?? resolveInstalledHostExecutable(process.platform);
|
|
2226
2443
|
const processArgs = [...custody.securefs_args_prefix ?? [], ...args];
|
|
2227
2444
|
return await new Promise((resolve, reject) => {
|
|
2228
|
-
execFile(executable, processArgs, { encoding: "buffer", timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
2445
|
+
const child = execFile(executable, processArgs, { encoding: "buffer", windowsHide: true, timeout: WINDOWS_SECUREFS_TIMEOUT_MS, maxBuffer: maxBytes + WINDOWS_SECUREFS_DIAGNOSTIC_BYTES }, (error, stdout, stderr) => {
|
|
2229
2446
|
const exitCode = error === null ? 0 : typeof error.code === "number" ? error.code : null;
|
|
2230
2447
|
if (exitCode === null) {
|
|
2231
2448
|
reject(new SecureFileCustodyError("unavailable", "The installed Windows Host securefs command could not run."));
|
|
@@ -2233,6 +2450,8 @@ async function runWindowsSecurefs(args, maxBytes, custody) {
|
|
|
2233
2450
|
}
|
|
2234
2451
|
resolve({ exit_code: exitCode, stdout: Buffer.from(stdout), stderr: Buffer.from(stderr) });
|
|
2235
2452
|
});
|
|
2453
|
+
child.stdin?.on("error", () => void 0);
|
|
2454
|
+
child.stdin?.end(stdin);
|
|
2236
2455
|
});
|
|
2237
2456
|
}
|
|
2238
2457
|
function securefsRefusal(stderr) {
|
|
@@ -2250,9 +2469,9 @@ function securefsRefusal(stderr) {
|
|
|
2250
2469
|
if (value.code === "not_private") return new SecureFileCustodyError("not_private", "The Windows Host securefs file is not private to the current user.");
|
|
2251
2470
|
return new SecureFileCustodyError("unavailable", "The Windows Host securefs command refused the file read.");
|
|
2252
2471
|
}
|
|
2253
|
-
function resolveInstalledHostExecutable() {
|
|
2472
|
+
function resolveInstalledHostExecutable(platform) {
|
|
2254
2473
|
const privateRuntimeRoot = dirname(fileURLToPath(import.meta.url));
|
|
2255
|
-
return win32.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe");
|
|
2474
|
+
return platform === "win32" ? win32.join(privateRuntimeRoot, "..", "..", "bin", "ceal-host.exe") : join2(privateRuntimeRoot, "..", "..", "bin", "ceal-host");
|
|
2256
2475
|
}
|
|
2257
2476
|
function isRecord(value) {
|
|
2258
2477
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -2274,6 +2493,124 @@ async function isPrivateDirectory(path, platform = process.platform, custody = {
|
|
|
2274
2493
|
return entry2.isDirectory() && !entry2.isSymbolicLink() && isSelfOwned(entry2.uid, platform) && isPrivateFileMode(entry2.mode, platform);
|
|
2275
2494
|
}
|
|
2276
2495
|
|
|
2496
|
+
// host/service-log-delivery.ts
|
|
2497
|
+
var HOST_SERVICE_LOG_DELIVERY_SCHEMA = "ceal.host_service_log_delivery.v1";
|
|
2498
|
+
function createHostServiceLogDelivery(stream, schedule = (flush) => {
|
|
2499
|
+
setImmediate(flush);
|
|
2500
|
+
}, onDeliveryGap = () => void 0) {
|
|
2501
|
+
const pending = [];
|
|
2502
|
+
const highWaterMark = stream.writableHighWaterMark;
|
|
2503
|
+
const byteBudget = highWaterMark + highWaterMark;
|
|
2504
|
+
let pendingBytes = 0;
|
|
2505
|
+
let droppedLines = 0;
|
|
2506
|
+
let flushScheduled = false;
|
|
2507
|
+
let waitingForDrain = false;
|
|
2508
|
+
let closed = !stream.writable;
|
|
2509
|
+
function stop2() {
|
|
2510
|
+
if (closed) return;
|
|
2511
|
+
closed = true;
|
|
2512
|
+
pending.length = 0;
|
|
2513
|
+
pendingBytes = 0;
|
|
2514
|
+
stream.off("drain", onDrain);
|
|
2515
|
+
stream.off("close", onTerminal);
|
|
2516
|
+
stream.off("finish", onTerminal);
|
|
2517
|
+
stream.off("error", onError);
|
|
2518
|
+
}
|
|
2519
|
+
function onTerminal() {
|
|
2520
|
+
stop2();
|
|
2521
|
+
}
|
|
2522
|
+
function onError() {
|
|
2523
|
+
stop2();
|
|
2524
|
+
}
|
|
2525
|
+
function onDrain() {
|
|
2526
|
+
waitingForDrain = false;
|
|
2527
|
+
scheduleFlush();
|
|
2528
|
+
}
|
|
2529
|
+
function scheduleFlush() {
|
|
2530
|
+
if (closed || flushScheduled || pending.length === 0 && droppedLines === 0) return;
|
|
2531
|
+
flushScheduled = true;
|
|
2532
|
+
let scheduling = true;
|
|
2533
|
+
let invokedSynchronously = false;
|
|
2534
|
+
try {
|
|
2535
|
+
schedule(() => {
|
|
2536
|
+
if (scheduling) {
|
|
2537
|
+
invokedSynchronously = true;
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
flushScheduled = false;
|
|
2541
|
+
flush();
|
|
2542
|
+
});
|
|
2543
|
+
} catch {
|
|
2544
|
+
flushScheduled = false;
|
|
2545
|
+
stop2();
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
scheduling = false;
|
|
2549
|
+
if (invokedSynchronously) {
|
|
2550
|
+
flushScheduled = false;
|
|
2551
|
+
stop2();
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
function flush() {
|
|
2555
|
+
if (closed) return;
|
|
2556
|
+
if (!stream.writable) {
|
|
2557
|
+
stop2();
|
|
2558
|
+
return;
|
|
2559
|
+
}
|
|
2560
|
+
while (pending.length > 0) {
|
|
2561
|
+
if (stream.writableNeedDrain) {
|
|
2562
|
+
if (!waitingForDrain) {
|
|
2563
|
+
waitingForDrain = true;
|
|
2564
|
+
stream.once("drain", onDrain);
|
|
2565
|
+
}
|
|
2566
|
+
return;
|
|
2567
|
+
}
|
|
2568
|
+
const next = pending.shift();
|
|
2569
|
+
if (next === void 0) return;
|
|
2570
|
+
pendingBytes -= next.bytes;
|
|
2571
|
+
let accepted;
|
|
2572
|
+
try {
|
|
2573
|
+
accepted = stream.write(next.line);
|
|
2574
|
+
} catch {
|
|
2575
|
+
stop2();
|
|
2576
|
+
return;
|
|
2577
|
+
}
|
|
2578
|
+
if (!accepted) {
|
|
2579
|
+
waitingForDrain = true;
|
|
2580
|
+
stream.once("drain", onDrain);
|
|
2581
|
+
return;
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
if (droppedLines > 0) {
|
|
2585
|
+
const line = `${JSON.stringify({ schema_version: HOST_SERVICE_LOG_DELIVERY_SCHEMA, omitted_line_count: droppedLines })}
|
|
2586
|
+
`;
|
|
2587
|
+
droppedLines = 0;
|
|
2588
|
+
try {
|
|
2589
|
+
onDeliveryGap(line);
|
|
2590
|
+
} catch {
|
|
2591
|
+
}
|
|
2592
|
+
pending.push({ line, bytes: Buffer.byteLength(line, "utf8") });
|
|
2593
|
+
pendingBytes += Buffer.byteLength(line, "utf8");
|
|
2594
|
+
flush();
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
stream.on("close", onTerminal);
|
|
2598
|
+
stream.on("finish", onTerminal);
|
|
2599
|
+
stream.on("error", onError);
|
|
2600
|
+
return (line) => {
|
|
2601
|
+
if (closed) return;
|
|
2602
|
+
const bytes2 = Buffer.byteLength(line, "utf8");
|
|
2603
|
+
if (bytes2 > highWaterMark || stream.writableLength + pendingBytes + bytes2 > byteBudget) {
|
|
2604
|
+
droppedLines += 1;
|
|
2605
|
+
scheduleFlush();
|
|
2606
|
+
return;
|
|
2607
|
+
}
|
|
2608
|
+
pending.push({ line, bytes: bytes2 });
|
|
2609
|
+
pendingBytes += bytes2;
|
|
2610
|
+
scheduleFlush();
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2277
2614
|
// host/service-log.ts
|
|
2278
2615
|
var HOST_SERVICE_LOG_ENVIRONMENT = "CEAL_HOST_SERVICE_LOG";
|
|
2279
2616
|
var HOST_SERVICE_LOG_ARGUMENT = "--ceal-host-service-log";
|
|
@@ -2293,6 +2630,9 @@ function consumeHostServiceLogArgument(args, platform = process.platform) {
|
|
|
2293
2630
|
if (indexes.length !== 1 || path === void 0 || !pathApi.isAbsolute(path) || pathApi.normalize(path) !== path) throw new HostServiceLogArgumentError();
|
|
2294
2631
|
return { args: [...args.slice(0, index), ...args.slice(index + 2)], path };
|
|
2295
2632
|
}
|
|
2633
|
+
var defaultHostServiceLogDelivery = createHostServiceLogDelivery(process.stderr, void 0, (line) => {
|
|
2634
|
+
void persistHostServiceLogLine(line);
|
|
2635
|
+
});
|
|
2296
2636
|
var HOST_SERVICE_LOG_MAX_BYTES = 1024 * 1024;
|
|
2297
2637
|
var HOST_SERVICE_LOG_CHECK_INTERVAL_MS = 6e4;
|
|
2298
2638
|
function hostServiceLogPreviousPath(path) {
|
|
@@ -2320,7 +2660,7 @@ function boundHostServiceLog(environment = process.env) {
|
|
|
2320
2660
|
ready.then(() => rotateHostServiceLog(path)).catch((error) => {
|
|
2321
2661
|
if (reported) return;
|
|
2322
2662
|
reported = true;
|
|
2323
|
-
|
|
2663
|
+
writeHostServiceLogLine(`[host-service-log] rotation_failed code=${errorCode2(error)}
|
|
2324
2664
|
`);
|
|
2325
2665
|
});
|
|
2326
2666
|
};
|
|
@@ -2330,10 +2670,22 @@ function boundHostServiceLog(environment = process.env) {
|
|
|
2330
2670
|
return () => clearInterval(timer);
|
|
2331
2671
|
}
|
|
2332
2672
|
function writeHostServiceLogLine(line, environment = process.env) {
|
|
2673
|
+
void persistHostServiceLogLine(line, environment);
|
|
2674
|
+
defaultHostServiceLogDelivery(line);
|
|
2675
|
+
}
|
|
2676
|
+
async function writeHostServiceCommandResult(schemaVersion, result2, sink) {
|
|
2677
|
+
const line = `${JSON.stringify({ schema_version: schemaVersion, ...result2 })}
|
|
2678
|
+
`;
|
|
2679
|
+
const serviceLine = `${JSON.stringify({ schema_version: schemaVersion, ok: result2.ok, ...!result2.ok ? { code: isHostOwnedFailureCode(result2.code) ? result2.code : "host_failure_unclassified" } : {} })}
|
|
2680
|
+
`;
|
|
2681
|
+
await persistHostServiceLogLine(serviceLine);
|
|
2682
|
+
sink(line);
|
|
2683
|
+
}
|
|
2684
|
+
async function persistHostServiceLogLine(line, environment = process.env) {
|
|
2333
2685
|
if (process.platform !== "win32") return;
|
|
2334
2686
|
const path = environment[HOST_SERVICE_LOG_ENVIRONMENT];
|
|
2335
2687
|
if (path === void 0 || !win322.isAbsolute(path) || win322.normalize(path) !== path) return;
|
|
2336
|
-
|
|
2688
|
+
await appendHostServiceLogLine(path, line).catch(() => void 0);
|
|
2337
2689
|
}
|
|
2338
2690
|
async function appendHostServiceLogLine(path, line) {
|
|
2339
2691
|
if (!isAbsolute(path)) return;
|
|
@@ -2371,21 +2723,59 @@ function isAbsoluteNormalizedNonRootPath(value, flavor = process.platform, allow
|
|
|
2371
2723
|
return typeof value === "string" && value.length <= 4096 && !value.includes("\0") && pathApi.isAbsolute(value) && pathApi.normalize(value) === value && (allowRoot || pathApi.parse(value).root !== value);
|
|
2372
2724
|
}
|
|
2373
2725
|
|
|
2726
|
+
// host/unix-socket-path.ts
|
|
2727
|
+
var PORTABLE_UNIX_SOCKET_PATH_MAX_BYTES = 103;
|
|
2728
|
+
var LINUX_UNIX_SOCKET_PATH_MAX_BYTES = 107;
|
|
2729
|
+
var HostUnixSocketPathError = class extends Error {
|
|
2730
|
+
code = "ipc_endpoint_too_long";
|
|
2731
|
+
role;
|
|
2732
|
+
bytes;
|
|
2733
|
+
maximum_bytes;
|
|
2734
|
+
constructor(role, bytes2, maximum_bytes) {
|
|
2735
|
+
super(`ipc_endpoint_too_long: Host IPC ${role} has ${bytes2} UTF-8 bytes; maximum is ${maximum_bytes}.`);
|
|
2736
|
+
this.name = "HostUnixSocketPathError";
|
|
2737
|
+
this.role = role;
|
|
2738
|
+
this.bytes = bytes2;
|
|
2739
|
+
this.maximum_bytes = maximum_bytes;
|
|
2740
|
+
}
|
|
2741
|
+
};
|
|
2742
|
+
function assertHostUnixSocketPath(endpoint, role, platform = process.platform) {
|
|
2743
|
+
if (platform === "win32") return;
|
|
2744
|
+
const maximum = platform === "linux" ? LINUX_UNIX_SOCKET_PATH_MAX_BYTES : PORTABLE_UNIX_SOCKET_PATH_MAX_BYTES;
|
|
2745
|
+
const bytes2 = Buffer.byteLength(endpoint, "utf8");
|
|
2746
|
+
if (bytes2 > maximum) throw new HostUnixSocketPathError(role, bytes2, maximum);
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2374
2749
|
// host/runtime-source-paths.ts
|
|
2375
2750
|
var HOST_SOURCE_ID = /^host-source:([0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})$/u;
|
|
2376
2751
|
function hostSourceUuid(sourceRef) {
|
|
2377
2752
|
return HOST_SOURCE_ID.exec(sourceRef)?.[1] ?? null;
|
|
2378
2753
|
}
|
|
2379
|
-
|
|
2754
|
+
var DARWIN_UID_MAX = 4294967295;
|
|
2755
|
+
var MACOS_HOST_RELAY_IPC_ROOT_PREFIX = "/private/tmp/ceal-host-";
|
|
2756
|
+
function isMacosHostRelayIpcDirectory(path) {
|
|
2757
|
+
return path.startsWith(MACOS_HOST_RELAY_IPC_ROOT_PREFIX) && /^[0-9]+$/u.test(path.slice(MACOS_HOST_RELAY_IPC_ROOT_PREFIX.length));
|
|
2758
|
+
}
|
|
2759
|
+
function macosHostRelayIpcDirectory(uid = process.geteuid?.() ?? -1) {
|
|
2760
|
+
if (!Number.isInteger(uid) || uid < 0 || uid > DARWIN_UID_MAX) throw new TypeError("Host runtime effective user identity is invalid.");
|
|
2761
|
+
return `${MACOS_HOST_RELAY_IPC_ROOT_PREFIX}${uid}`;
|
|
2762
|
+
}
|
|
2763
|
+
function hostRuntimeSourcePaths(stateRoot, sourceRef, platform = process.platform, uid = process.geteuid?.() ?? -1) {
|
|
2380
2764
|
const sourceId = hostSourceUuid(sourceRef);
|
|
2381
2765
|
if (!isAbsoluteNormalizedNonRootPath(stateRoot, platform) || sourceId === null) throw new TypeError("Host runtime source identity is invalid.");
|
|
2382
2766
|
const path = platform === "win32" ? win324 : posix3;
|
|
2383
2767
|
const sourcesRoot = path.join(stateRoot, "sources");
|
|
2384
2768
|
const sourceRoot = path.join(sourcesRoot, sourceId);
|
|
2385
2769
|
const runtimeRoot = path.join(stateRoot, "run");
|
|
2386
|
-
const
|
|
2770
|
+
const rootedEndpoint = path.join(runtimeRoot, `${sourceId}.sock`);
|
|
2771
|
+
const endpoint = projectRelayEndpoint(stateRoot, sourceRef, rootedEndpoint, platform, uid);
|
|
2387
2772
|
return { sourceId, sourcesRoot, sourceRoot, relayRoot: path.join(sourceRoot, "relay"), codexOutbox: path.join(sourceRoot, "producers", "codex", "outbox"), claudeOutbox: path.join(sourceRoot, "producers", "claude", "outbox"), endpoint, runtimeRoot };
|
|
2388
2773
|
}
|
|
2774
|
+
function projectRelayEndpoint(stateRoot, sourceRef, rooted, platform, uid) {
|
|
2775
|
+
if (platform !== "win32" && (platform !== "darwin" || Buffer.byteLength(rooted, "utf8") <= PORTABLE_UNIX_SOCKET_PATH_MAX_BYTES)) return rooted;
|
|
2776
|
+
const digest = createHash3("sha256").update(`${stateRoot}\0${sourceRef}`).digest("hex");
|
|
2777
|
+
return platform === "win32" ? `\\\\.\\pipe\\ceal-host-${digest.slice(0, 24)}` : posix3.join(macosHostRelayIpcDirectory(uid), `${digest}.sock`);
|
|
2778
|
+
}
|
|
2389
2779
|
function assertHostRelaySourcePaths(stateRoot, config, platform = process.platform) {
|
|
2390
2780
|
const paths = hostRuntimeSourcePaths(stateRoot, config.host_source_ref, platform);
|
|
2391
2781
|
if (config.state_root !== paths.relayRoot || platform !== "win32" && config.ipc_endpoint !== paths.endpoint) throw new TypeError("Host Relay state and IPC must belong to its configured source.");
|
|
@@ -2393,8 +2783,9 @@ function assertHostRelaySourcePaths(stateRoot, config, platform = process.platfo
|
|
|
2393
2783
|
}
|
|
2394
2784
|
|
|
2395
2785
|
// host/relay/src/host-relay-runtime.ts
|
|
2786
|
+
import { randomUUID } from "node:crypto";
|
|
2396
2787
|
import { constants as constants4 } from "node:fs";
|
|
2397
|
-
import { dirname as
|
|
2788
|
+
import { dirname as dirname8, join as join7 } from "node:path";
|
|
2398
2789
|
|
|
2399
2790
|
// host/abortable-wait.ts
|
|
2400
2791
|
function waitForAbort(signal, milliseconds) {
|
|
@@ -2647,7 +3038,7 @@ function exactOptional(value, required, optional) {
|
|
|
2647
3038
|
|
|
2648
3039
|
// host/relay/src/relay-admission-store.ts
|
|
2649
3040
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
2650
|
-
import { join as
|
|
3041
|
+
import { join as join4 } from "node:path";
|
|
2651
3042
|
|
|
2652
3043
|
// host/relay/src/durable-atomic-replacement.ts
|
|
2653
3044
|
import { lstat as lstat2, mkdir as mkdir2, open as open2, rename, unlink } from "node:fs/promises";
|
|
@@ -2783,7 +3174,7 @@ function errorCode3(error) {
|
|
|
2783
3174
|
// host/relay/src/relay-quarantine-store.ts
|
|
2784
3175
|
import { createHash as createHash5 } from "node:crypto";
|
|
2785
3176
|
import { readFile } from "node:fs/promises";
|
|
2786
|
-
import { join as
|
|
3177
|
+
import { join as join3 } from "node:path";
|
|
2787
3178
|
var RELAY_QUARANTINE_SCHEMA = "ceal.host_relay_quarantine_state.v1";
|
|
2788
3179
|
var RELAY_QUARANTINE_MAX_RECORDS = 512;
|
|
2789
3180
|
var RELAY_QUARANTINE_MAX_BYTES = 16 * 1024 * 1024;
|
|
@@ -2837,14 +3228,14 @@ var RelayQuarantineStore = class {
|
|
|
2837
3228
|
const records = state.producers[producerId];
|
|
2838
3229
|
records.push(record6);
|
|
2839
3230
|
while (records.length > this.maxRecords || totalBytes(records) > this.maxBytes) records.shift();
|
|
2840
|
-
await durableAtomicReplace(
|
|
3231
|
+
await durableAtomicReplace(join3(this.root, "quarantine.json"), JSON.stringify(state));
|
|
2841
3232
|
});
|
|
2842
3233
|
this.tail = run.then(() => void 0, () => void 0);
|
|
2843
3234
|
await run;
|
|
2844
3235
|
}
|
|
2845
3236
|
async readState() {
|
|
2846
3237
|
try {
|
|
2847
|
-
return decodeState(JSON.parse(await readFile(
|
|
3238
|
+
return decodeState(JSON.parse(await readFile(join3(this.root, "quarantine.json"), "utf8")));
|
|
2848
3239
|
} catch (error) {
|
|
2849
3240
|
if (errorCode4(error) === "ENOENT") return emptyState();
|
|
2850
3241
|
throw error;
|
|
@@ -2909,7 +3300,7 @@ var RelayAdmissionStore = class {
|
|
|
2909
3300
|
quarantine;
|
|
2910
3301
|
limits;
|
|
2911
3302
|
faultHooks;
|
|
2912
|
-
constructor(root, limits = DEFAULT_LIMITS, faultHooks = {}, quarantine = new RelayQuarantineStore(
|
|
3303
|
+
constructor(root, limits = DEFAULT_LIMITS, faultHooks = {}, quarantine = new RelayQuarantineStore(join4(root, "quarantine"))) {
|
|
2913
3304
|
this.root = root;
|
|
2914
3305
|
this.quarantine = quarantine;
|
|
2915
3306
|
this.limits = limits;
|
|
@@ -3021,14 +3412,14 @@ var RelayAdmissionStore = class {
|
|
|
3021
3412
|
}
|
|
3022
3413
|
async read() {
|
|
3023
3414
|
try {
|
|
3024
|
-
return decodeState2(JSON.parse(await readFile2(
|
|
3415
|
+
return decodeState2(JSON.parse(await readFile2(join4(this.root, "admission.json"), "utf8")));
|
|
3025
3416
|
} catch (error) {
|
|
3026
3417
|
if (errorCode5(error) === "ENOENT") return { schema_version: "ceal.host_relay_admission_state.v1", installations: {}, entries: [] };
|
|
3027
3418
|
throw error;
|
|
3028
3419
|
}
|
|
3029
3420
|
}
|
|
3030
3421
|
async write(state) {
|
|
3031
|
-
await durableAtomicReplace(
|
|
3422
|
+
await durableAtomicReplace(join4(this.root, "admission.json"), JSON.stringify(state));
|
|
3032
3423
|
}
|
|
3033
3424
|
};
|
|
3034
3425
|
function installationKey(frame) {
|
|
@@ -3171,7 +3562,7 @@ function poisonSequenceInRange(entryValue, installation2) {
|
|
|
3171
3562
|
import { createHmac, randomBytes } from "node:crypto";
|
|
3172
3563
|
import { constants as constants2 } from "node:fs";
|
|
3173
3564
|
import { link, unlink as unlink2 } from "node:fs/promises";
|
|
3174
|
-
import { dirname as dirname4, join as
|
|
3565
|
+
import { dirname as dirname4, join as join5 } from "node:path";
|
|
3175
3566
|
var RELAY_PIPE_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
3176
3567
|
var RELAY_PIPE_KEY_BYTES = 32;
|
|
3177
3568
|
var RELAY_PIPE_KEY_FILENAME = "relay-pipe.key";
|
|
@@ -3191,7 +3582,7 @@ var RelayPipeHandshakeError = class extends Error {
|
|
|
3191
3582
|
}
|
|
3192
3583
|
};
|
|
3193
3584
|
function relayPipeKeyPath(relayStateRoot) {
|
|
3194
|
-
return
|
|
3585
|
+
return join5(relayStateRoot, RELAY_PIPE_KEY_FILENAME);
|
|
3195
3586
|
}
|
|
3196
3587
|
async function loadRelayPipeKey(relayStateRoot, platform = process.platform, custody = {}) {
|
|
3197
3588
|
const path = relayPipeKeyPath(relayStateRoot);
|
|
@@ -3201,9 +3592,10 @@ async function loadRelayPipeKey(relayStateRoot, platform = process.platform, cus
|
|
|
3201
3592
|
return await createPosixRelayPipeKey(path, platform, custody);
|
|
3202
3593
|
}
|
|
3203
3594
|
async function loadWindowsRelayPipeKey(path, custody) {
|
|
3204
|
-
const existing = await readRelayPipeKey(path, "win32", custody);
|
|
3205
|
-
if (existing !== null) return existing;
|
|
3206
3595
|
try {
|
|
3596
|
+
await ensurePrivateDirectoryWithSecurefs(dirname4(path), custody);
|
|
3597
|
+
const existing = await readRelayPipeKey(path, "win32", custody);
|
|
3598
|
+
if (existing !== null) return existing;
|
|
3207
3599
|
await createRandomPrivateFileWithSecurefs(path, RELAY_PIPE_KEY_BYTES, custody);
|
|
3208
3600
|
} catch (error) {
|
|
3209
3601
|
if (errorCode6(error) === "EEXIST") return await readWinnerPipeKey(path, "win32", custody);
|
|
@@ -3428,24 +3820,7 @@ function errorCode6(error) {
|
|
|
3428
3820
|
return typeof error === "object" && error !== null && "code" in error ? String(error.code) : null;
|
|
3429
3821
|
}
|
|
3430
3822
|
|
|
3431
|
-
// host/relay/src/relay-ipc.ts
|
|
3432
|
-
import { chmod, lstat as lstat3, rename as rename2, unlink as unlink3 } from "node:fs/promises";
|
|
3433
|
-
import { createConnection, createServer } from "node:net";
|
|
3434
|
-
import { dirname as dirname5, join as join5 } from "node:path";
|
|
3435
|
-
var HOST_RELAY_IPC_RESPONSE_SCHEMA = "ceal.host_relay_admission.v1";
|
|
3436
|
-
var HOST_RELAY_INVOCATION_CONTEXT_QUERY_SCHEMA = "ceal.host_relay_invocation_context_query.v2";
|
|
3437
|
-
var HOST_RELAY_INVOCATION_CONTEXT_RESULT_SCHEMA = "ceal.host_relay_invocation_context_result.v2";
|
|
3438
|
-
var HOST_RELAY_IPC_LENGTH_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
3439
|
-
var HOST_RELAY_EXCHANGE_FAILURES = vocabulary([
|
|
3440
|
-
"permission_denied",
|
|
3441
|
-
"socket_missing",
|
|
3442
|
-
"connection_refused",
|
|
3443
|
-
"closed_early",
|
|
3444
|
-
"response_invalid",
|
|
3445
|
-
"timed_out",
|
|
3446
|
-
"cancelled",
|
|
3447
|
-
"unavailable"
|
|
3448
|
-
]);
|
|
3823
|
+
// host/relay/src/relay-ipc-error.ts
|
|
3449
3824
|
var HostRelayIpcError = class extends Error {
|
|
3450
3825
|
code;
|
|
3451
3826
|
/** Set only when the client-side socket exchange itself failed. */
|
|
@@ -3456,17 +3831,165 @@ var HostRelayIpcError = class extends Error {
|
|
|
3456
3831
|
this.failure = failure;
|
|
3457
3832
|
}
|
|
3458
3833
|
};
|
|
3834
|
+
function relayIpcErrorCode(error) {
|
|
3835
|
+
return error !== null && typeof error === "object" && !Array.isArray(error) && "code" in error && typeof error.code === "string" ? error.code : null;
|
|
3836
|
+
}
|
|
3837
|
+
|
|
3838
|
+
// host/relay/src/relay-endpoint-ownership.ts
|
|
3839
|
+
import { lstat as lstat3, mkdir as mkdir3, unlink as unlink3 } from "node:fs/promises";
|
|
3840
|
+
import { createConnection } from "node:net";
|
|
3841
|
+
import { dirname as dirname5 } from "node:path";
|
|
3842
|
+
var relayEndpointLocks = /* @__PURE__ */ new Map();
|
|
3843
|
+
function withRelayEndpointLock(endpoint, run) {
|
|
3844
|
+
const prior = relayEndpointLocks.get(endpoint) ?? Promise.resolve();
|
|
3845
|
+
let release;
|
|
3846
|
+
const gate = new Promise((resolve) => {
|
|
3847
|
+
release = resolve;
|
|
3848
|
+
});
|
|
3849
|
+
const tail = prior.then(() => gate);
|
|
3850
|
+
relayEndpointLocks.set(endpoint, tail);
|
|
3851
|
+
return prior.then(run).finally(() => {
|
|
3852
|
+
release?.();
|
|
3853
|
+
if (relayEndpointLocks.get(endpoint) === tail) relayEndpointLocks.delete(endpoint);
|
|
3854
|
+
});
|
|
3855
|
+
}
|
|
3856
|
+
function currentUid(fallback) {
|
|
3857
|
+
return typeof process.geteuid === "function" ? process.geteuid() : fallback;
|
|
3858
|
+
}
|
|
3859
|
+
async function assertTrustedEndpointParent(endpoint, createManagedParent = false) {
|
|
3860
|
+
const parent = dirname5(endpoint);
|
|
3861
|
+
if (process.platform === "darwin" && isMacosHostRelayIpcDirectory(parent)) {
|
|
3862
|
+
if (parent !== macosHostRelayIpcDirectory()) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC directory does not belong to the effective user; leaving it untouched.");
|
|
3863
|
+
await assertMacosIpcSystemAnchor();
|
|
3864
|
+
if (createManagedParent) {
|
|
3865
|
+
try {
|
|
3866
|
+
await mkdir3(parent, { mode: 448 });
|
|
3867
|
+
} catch (error) {
|
|
3868
|
+
if (relayIpcErrorCode(error) !== "EEXIST") throw endpointInspectionError(error, "Host Relay IPC private directory could not be created.");
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
await assertPrivateEndpointDirectory(parent);
|
|
3873
|
+
}
|
|
3874
|
+
async function assertPrivateEndpointDirectory(parent) {
|
|
3875
|
+
let stats;
|
|
3876
|
+
try {
|
|
3877
|
+
stats = await lstat3(parent);
|
|
3878
|
+
} catch (error) {
|
|
3879
|
+
throw endpointInspectionError(error, "Host Relay IPC endpoint parent is unavailable; leaving it untouched.");
|
|
3880
|
+
}
|
|
3881
|
+
if (!stats.isDirectory() || stats.uid !== currentUid(stats.uid) || (stats.mode & 63) !== 0) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint parent is not an owner-private directory; leaving it untouched.");
|
|
3882
|
+
}
|
|
3883
|
+
async function assertMacosIpcSystemAnchor() {
|
|
3884
|
+
for (const path of ["/", "/private", "/private/tmp"]) {
|
|
3885
|
+
const stats = await lstat3(path);
|
|
3886
|
+
const permissionsSafe = path === "/private/tmp" ? (stats.mode & 512) !== 0 : (stats.mode & 18) === 0;
|
|
3887
|
+
if (!stats.isDirectory() || stats.uid !== 0 || !permissionsSafe) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC system anchor is not a root-owned physical directory with safe permissions; leaving it untouched.");
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3890
|
+
async function assertTrustedEndpointSocket(endpoint, allowMissing = false) {
|
|
3891
|
+
assertHostUnixSocketPath(endpoint, "endpoint");
|
|
3892
|
+
await assertTrustedEndpointParent(endpoint);
|
|
3893
|
+
const observed = await readEndpointStats(endpoint);
|
|
3894
|
+
if (observed === null) {
|
|
3895
|
+
if (allowMissing) return null;
|
|
3896
|
+
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC is unavailable: socket_missing.", "socket_missing");
|
|
3897
|
+
}
|
|
3898
|
+
if (!observed.isSocket()) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint is not a socket; leaving it untouched.");
|
|
3899
|
+
if (observed.uid !== currentUid(observed.uid)) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint is not owned by the current uid; leaving it untouched.");
|
|
3900
|
+
return observed;
|
|
3901
|
+
}
|
|
3902
|
+
function endpointInspectionError(error, message) {
|
|
3903
|
+
const code = relayIpcErrorCode(error);
|
|
3904
|
+
const failure = code === "ENOENT" ? "socket_missing" : code === "EACCES" || code === "EPERM" ? "permission_denied" : "unavailable";
|
|
3905
|
+
return new HostRelayIpcError("relay_unavailable", message, failure);
|
|
3906
|
+
}
|
|
3907
|
+
var HOST_RELAY_ENDPOINT_PROBE_TIMEOUT_MS = 1e3;
|
|
3908
|
+
async function probeRelayEndpoint(endpoint) {
|
|
3909
|
+
if (await assertTrustedEndpointSocket(endpoint, true) === null) return "missing";
|
|
3910
|
+
return new Promise((resolve) => {
|
|
3911
|
+
let settled = false;
|
|
3912
|
+
const socket = createConnection(endpoint);
|
|
3913
|
+
const finish = (outcome) => {
|
|
3914
|
+
if (settled) return;
|
|
3915
|
+
settled = true;
|
|
3916
|
+
clearTimeout(timer);
|
|
3917
|
+
socket.destroy();
|
|
3918
|
+
resolve(outcome);
|
|
3919
|
+
};
|
|
3920
|
+
const timer = setTimeout(() => finish("ambiguous"), HOST_RELAY_ENDPOINT_PROBE_TIMEOUT_MS);
|
|
3921
|
+
timer.unref?.();
|
|
3922
|
+
socket.once("connect", () => finish("live"));
|
|
3923
|
+
socket.once("error", (error) => {
|
|
3924
|
+
const code = relayIpcErrorCode(error);
|
|
3925
|
+
if (code === "ECONNREFUSED") finish("stale");
|
|
3926
|
+
else if (code === "ENOENT") finish("missing");
|
|
3927
|
+
else finish("ambiguous");
|
|
3928
|
+
});
|
|
3929
|
+
});
|
|
3930
|
+
}
|
|
3931
|
+
async function removeStaleRelayEndpoint(endpoint, testHooks) {
|
|
3932
|
+
const observed = await assertTrustedEndpointSocket(endpoint, true);
|
|
3933
|
+
if (observed === null) return;
|
|
3934
|
+
const captured = { uid: observed.uid, dev: observed.dev, ino: observed.ino };
|
|
3935
|
+
await requireStaleEndpoint(endpoint);
|
|
3936
|
+
await testHooks?.beforeRemoveStaleEndpoint?.(endpoint);
|
|
3937
|
+
const current = await readEndpointStats(endpoint);
|
|
3938
|
+
if (current === null) return;
|
|
3939
|
+
requireSameEndpointIdentity(current, captured, "Host Relay IPC endpoint changed before cleanup; leaving it untouched.");
|
|
3940
|
+
await unlinkRelayEndpoint(endpoint);
|
|
3941
|
+
}
|
|
3942
|
+
async function requireStaleEndpoint(endpoint) {
|
|
3943
|
+
switch (await probeRelayEndpoint(endpoint)) {
|
|
3944
|
+
case "missing":
|
|
3945
|
+
case "stale":
|
|
3946
|
+
return;
|
|
3947
|
+
case "live":
|
|
3948
|
+
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint is already served by a live Relay; leaving it untouched.");
|
|
3949
|
+
case "ambiguous":
|
|
3950
|
+
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint liveness is ambiguous; leaving it untouched.");
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
async function readEndpointStats(endpoint) {
|
|
3954
|
+
try {
|
|
3955
|
+
return await lstat3(endpoint);
|
|
3956
|
+
} catch (error) {
|
|
3957
|
+
if (relayIpcErrorCode(error) === "ENOENT") return null;
|
|
3958
|
+
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint identity is ambiguous; leaving it untouched.");
|
|
3959
|
+
}
|
|
3960
|
+
}
|
|
3961
|
+
function requireSameEndpointIdentity(current, owned, message) {
|
|
3962
|
+
if (!current.isSocket() || current.uid !== owned.uid || current.dev !== owned.dev || current.ino !== owned.ino) throw new HostRelayIpcError("relay_unavailable", message);
|
|
3963
|
+
}
|
|
3964
|
+
async function unlinkRelayEndpoint(endpoint) {
|
|
3965
|
+
try {
|
|
3966
|
+
await unlink3(endpoint);
|
|
3967
|
+
} catch (error) {
|
|
3968
|
+
if (relayIpcErrorCode(error) !== "ENOENT") throw error;
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3971
|
+
|
|
3972
|
+
// host/relay/src/relay-ipc.ts
|
|
3973
|
+
import { chmod, lstat as lstat4, rename as rename2, unlink as unlink4 } from "node:fs/promises";
|
|
3974
|
+
import { createConnection as createConnection2, createServer } from "node:net";
|
|
3975
|
+
import { dirname as dirname6, join as join6 } from "node:path";
|
|
3976
|
+
var HOST_RELAY_IPC_RESPONSE_SCHEMA = "ceal.host_relay_admission.v1";
|
|
3977
|
+
var HOST_RELAY_INVOCATION_CONTEXT_QUERY_SCHEMA = "ceal.host_relay_invocation_context_query.v2";
|
|
3978
|
+
var HOST_RELAY_INVOCATION_CONTEXT_RESULT_SCHEMA = "ceal.host_relay_invocation_context_result.v3";
|
|
3979
|
+
var HOST_RELAY_IPC_LENGTH_BYTES = Uint32Array.BYTES_PER_ELEMENT;
|
|
3459
3980
|
async function startHostRelayIpcServer(options) {
|
|
3981
|
+
assertHostUnixSocketPath(options.endpoint, "endpoint");
|
|
3460
3982
|
return withRelayEndpointLock(options.endpoint, async () => {
|
|
3461
3983
|
const lastSeenRequestBySession = /* @__PURE__ */ new Map();
|
|
3462
3984
|
if (process.platform === "win32") return startWindowsPipeServer(options, lastSeenRequestBySession);
|
|
3463
|
-
|
|
3985
|
+
const staging = stagingRelayEndpoint(options.endpoint);
|
|
3986
|
+
assertHostUnixSocketPath(staging, "staging");
|
|
3987
|
+
await assertTrustedEndpointParent(options.endpoint, true);
|
|
3464
3988
|
await removeStaleRelayEndpoint(options.endpoint, options.testHooks);
|
|
3465
3989
|
const active = /* @__PURE__ */ new Map();
|
|
3466
3990
|
const sockets = /* @__PURE__ */ new Set();
|
|
3467
3991
|
const quarantine = options.quarantine ?? options.admission.quarantine;
|
|
3468
3992
|
const server = createServer((socket) => serveSocket(socket, options, quarantine, active, sockets, Buffer.alloc(0), lastSeenRequestBySession));
|
|
3469
|
-
const staging = stagingRelayEndpoint(options.endpoint);
|
|
3470
3993
|
await listenStagingRelayEndpoint(server, sockets, staging);
|
|
3471
3994
|
let owned;
|
|
3472
3995
|
try {
|
|
@@ -3528,7 +4051,7 @@ async function resolveWindowsPipeListenOutcome(endpoint, error, probe = windowsP
|
|
|
3528
4051
|
return mapWindowsPipeListenError(endpoint, error);
|
|
3529
4052
|
}
|
|
3530
4053
|
function pipeNameHeldError(error) {
|
|
3531
|
-
const code =
|
|
4054
|
+
const code = relayIpcErrorCode(error);
|
|
3532
4055
|
return code === "EADDRINUSE" || code === "EACCES";
|
|
3533
4056
|
}
|
|
3534
4057
|
function windowsPipeHolderIsLive(endpoint) {
|
|
@@ -3537,7 +4060,7 @@ function windowsPipeHolderIsLive(endpoint) {
|
|
|
3537
4060
|
probe.destroy();
|
|
3538
4061
|
resolve(false);
|
|
3539
4062
|
}, RELAY_PIPE_HANDSHAKE_TIMEOUT_MS);
|
|
3540
|
-
const probe =
|
|
4063
|
+
const probe = createConnection2(endpoint);
|
|
3541
4064
|
probe.once("connect", () => {
|
|
3542
4065
|
clearTimeout(timer);
|
|
3543
4066
|
probe.destroy();
|
|
@@ -3551,7 +4074,7 @@ function windowsPipeHolderIsLive(endpoint) {
|
|
|
3551
4074
|
});
|
|
3552
4075
|
}
|
|
3553
4076
|
function mapWindowsPipeListenError(endpoint, error) {
|
|
3554
|
-
const code =
|
|
4077
|
+
const code = relayIpcErrorCode(error);
|
|
3555
4078
|
if (pipeNameHeldError(error)) {
|
|
3556
4079
|
return new HostRelayIpcError("relay_unavailable", `relay pipe name held by another process: the Host Relay pipe name ${endpoint} is already served (error ${code}); stop the process holding it, then restart the Host Relay.`);
|
|
3557
4080
|
}
|
|
@@ -3757,111 +4280,19 @@ function listen(server, endpoint) {
|
|
|
3757
4280
|
async function closeServer(server, sockets, endpoint) {
|
|
3758
4281
|
for (const socket of sockets) socket.destroy();
|
|
3759
4282
|
await new Promise((resolve) => server.close(() => resolve()));
|
|
3760
|
-
if (process.platform !== "win32") await
|
|
3761
|
-
}
|
|
3762
|
-
var relayEndpointLocks = /* @__PURE__ */ new Map();
|
|
3763
|
-
function withRelayEndpointLock(endpoint, run) {
|
|
3764
|
-
const prior = relayEndpointLocks.get(endpoint) ?? Promise.resolve();
|
|
3765
|
-
let release;
|
|
3766
|
-
const gate = new Promise((resolve) => {
|
|
3767
|
-
release = resolve;
|
|
3768
|
-
});
|
|
3769
|
-
const tail = prior.then(() => gate);
|
|
3770
|
-
relayEndpointLocks.set(endpoint, tail);
|
|
3771
|
-
return prior.then(run).finally(() => {
|
|
3772
|
-
release?.();
|
|
3773
|
-
if (relayEndpointLocks.get(endpoint) === tail) relayEndpointLocks.delete(endpoint);
|
|
3774
|
-
});
|
|
3775
|
-
}
|
|
3776
|
-
function currentUid(fallback) {
|
|
3777
|
-
return typeof process.geteuid === "function" ? process.geteuid() : fallback;
|
|
3778
|
-
}
|
|
3779
|
-
async function assertTrustedEndpointParent(endpoint) {
|
|
3780
|
-
const parent = dirname5(endpoint);
|
|
3781
|
-
let stats;
|
|
3782
|
-
try {
|
|
3783
|
-
stats = await lstat3(parent);
|
|
3784
|
-
} catch {
|
|
3785
|
-
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint parent is unavailable; leaving it untouched.");
|
|
3786
|
-
}
|
|
3787
|
-
if (!stats.isDirectory() || stats.uid !== currentUid(stats.uid) || (stats.mode & 63) !== 0) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint parent is not an owner-private directory; leaving it untouched.");
|
|
3788
|
-
}
|
|
3789
|
-
var HOST_RELAY_ENDPOINT_PROBE_TIMEOUT_MS = 1e3;
|
|
3790
|
-
function probeRelayEndpoint(endpoint) {
|
|
3791
|
-
return new Promise((resolve) => {
|
|
3792
|
-
let settled = false;
|
|
3793
|
-
const socket = createConnection(endpoint);
|
|
3794
|
-
const finish = (outcome) => {
|
|
3795
|
-
if (settled) return;
|
|
3796
|
-
settled = true;
|
|
3797
|
-
clearTimeout(timer);
|
|
3798
|
-
socket.destroy();
|
|
3799
|
-
resolve(outcome);
|
|
3800
|
-
};
|
|
3801
|
-
const timer = setTimeout(() => finish("ambiguous"), HOST_RELAY_ENDPOINT_PROBE_TIMEOUT_MS);
|
|
3802
|
-
timer.unref?.();
|
|
3803
|
-
socket.once("connect", () => finish("live"));
|
|
3804
|
-
socket.once("error", (error) => {
|
|
3805
|
-
const code = errorCode7(error);
|
|
3806
|
-
if (code === "ECONNREFUSED") finish("stale");
|
|
3807
|
-
else if (code === "ENOENT") finish("missing");
|
|
3808
|
-
else finish("ambiguous");
|
|
3809
|
-
});
|
|
3810
|
-
});
|
|
3811
|
-
}
|
|
3812
|
-
async function removeStaleRelayEndpoint(endpoint, testHooks) {
|
|
3813
|
-
const observed = await readEndpointStats(endpoint);
|
|
3814
|
-
if (observed === null) return;
|
|
3815
|
-
if (!observed.isSocket()) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint is already present and is not a socket; leaving it untouched.");
|
|
3816
|
-
if (observed.uid !== currentUid(observed.uid)) throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint is not owned by the current uid; leaving it untouched.");
|
|
3817
|
-
const captured = { uid: observed.uid, dev: observed.dev, ino: observed.ino };
|
|
3818
|
-
await requireStaleEndpoint(endpoint);
|
|
3819
|
-
await testHooks?.beforeRemoveStaleEndpoint?.(endpoint);
|
|
3820
|
-
const current = await readEndpointStats(endpoint);
|
|
3821
|
-
if (current === null) return;
|
|
3822
|
-
requireSameEndpointIdentity(current, captured, "Host Relay IPC endpoint changed before cleanup; leaving it untouched.");
|
|
3823
|
-
await unlinkRelayEndpoint(endpoint);
|
|
3824
|
-
}
|
|
3825
|
-
async function requireStaleEndpoint(endpoint) {
|
|
3826
|
-
switch (await probeRelayEndpoint(endpoint)) {
|
|
3827
|
-
case "missing":
|
|
3828
|
-
case "stale":
|
|
3829
|
-
return;
|
|
3830
|
-
case "live":
|
|
3831
|
-
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint is already served by a live Relay; leaving it untouched.");
|
|
3832
|
-
case "ambiguous":
|
|
3833
|
-
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint liveness is ambiguous; leaving it untouched.");
|
|
3834
|
-
}
|
|
3835
|
-
}
|
|
3836
|
-
async function readEndpointStats(endpoint) {
|
|
3837
|
-
try {
|
|
3838
|
-
return await lstat3(endpoint);
|
|
3839
|
-
} catch (error) {
|
|
3840
|
-
if (errorCode7(error) === "ENOENT") return null;
|
|
3841
|
-
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint identity is ambiguous; leaving it untouched.");
|
|
3842
|
-
}
|
|
3843
|
-
}
|
|
3844
|
-
function requireSameEndpointIdentity(current, owned, message) {
|
|
3845
|
-
if (!current.isSocket() || current.uid !== owned.uid || current.dev !== owned.dev || current.ino !== owned.ino) throw new HostRelayIpcError("relay_unavailable", message);
|
|
3846
|
-
}
|
|
3847
|
-
async function unlinkRelayEndpoint(endpoint) {
|
|
3848
|
-
try {
|
|
3849
|
-
await unlink3(endpoint);
|
|
3850
|
-
} catch (error) {
|
|
3851
|
-
if (errorCode7(error) !== "ENOENT") throw error;
|
|
3852
|
-
}
|
|
4283
|
+
if (process.platform !== "win32") await unlink4(endpoint).catch(() => void 0);
|
|
3853
4284
|
}
|
|
3854
4285
|
var relayStagingSequence = 0;
|
|
3855
4286
|
function stagingRelayEndpoint(canonical) {
|
|
3856
|
-
const parent =
|
|
4287
|
+
const parent = dirname6(canonical);
|
|
3857
4288
|
const pid = process.pid.toString(36);
|
|
3858
4289
|
const sequence = (relayStagingSequence++ % (36 * 36)).toString(36);
|
|
3859
|
-
return
|
|
4290
|
+
return join6(parent, `.r${pid}${sequence}`);
|
|
3860
4291
|
}
|
|
3861
4292
|
async function readStagingRelayEndpointIdentity(staging) {
|
|
3862
4293
|
let created;
|
|
3863
4294
|
try {
|
|
3864
|
-
created = await
|
|
4295
|
+
created = await lstat4(staging);
|
|
3865
4296
|
} catch {
|
|
3866
4297
|
throw new HostRelayIpcError("relay_unavailable", "Host Relay IPC endpoint is unavailable after listen; leaving it untouched.");
|
|
3867
4298
|
}
|
|
@@ -3913,13 +4344,10 @@ async function abandonRelayServer(server, sockets) {
|
|
|
3913
4344
|
server.close(() => resolve());
|
|
3914
4345
|
});
|
|
3915
4346
|
}
|
|
3916
|
-
function errorCode7(error) {
|
|
3917
|
-
return record3(error) && typeof error.code === "string" ? error.code : null;
|
|
3918
|
-
}
|
|
3919
4347
|
|
|
3920
4348
|
// host/relay/src/host-registration-state.ts
|
|
3921
4349
|
import { constants as constants3 } from "node:fs";
|
|
3922
|
-
import { dirname as
|
|
4350
|
+
import { dirname as dirname7 } from "node:path";
|
|
3923
4351
|
var HOST_REGISTRATION_STATE_SCHEMA = "ceal.host_registration_state.v1";
|
|
3924
4352
|
var HOST_REGISTRATION_STATE_KEYS = Object.freeze([
|
|
3925
4353
|
"credential_generation",
|
|
@@ -3939,7 +4367,7 @@ var HostRegistrationStateError = class extends Error {
|
|
|
3939
4367
|
async function readHostRegistrationAuthority(path, expectedHostSourceRef, platform = process.platform, custody = {}) {
|
|
3940
4368
|
let raw;
|
|
3941
4369
|
try {
|
|
3942
|
-
await assertPrivateRegistrationDirectory(
|
|
4370
|
+
await assertPrivateRegistrationDirectory(dirname7(path), platform, custody);
|
|
3943
4371
|
raw = platform === "win32" ? await readWindowsRegistration(path, custody) : await readPosixRegistration(path, platform, custody);
|
|
3944
4372
|
} catch (error) {
|
|
3945
4373
|
throw registrationReadError(error);
|
|
@@ -4047,7 +4475,7 @@ async function readHostRelayConfig(path, platform = process.platform, custody =
|
|
|
4047
4475
|
if (!isAbsoluteNormalizedNonRootPath(path, process.platform, true)) throw new HostRelayConfigError("invalid_config_path", `invalid_config_path: Host Relay config path is invalid: ${refusalFact("config_path", path, "absolute, normalized, and non-root")}.`);
|
|
4048
4476
|
let handle;
|
|
4049
4477
|
try {
|
|
4050
|
-
await assertPrivateRelayConfigDirectory(
|
|
4478
|
+
await assertPrivateRelayConfigDirectory(dirname8(path), platform, custody);
|
|
4051
4479
|
let text;
|
|
4052
4480
|
if (platform === "win32") {
|
|
4053
4481
|
const bytes2 = await readPrivateFileWithSecurefs(path, HOST_RELAY_CONFIG_MAX_BYTES, custody);
|
|
@@ -4070,7 +4498,6 @@ async function readHostRelayConfig(path, platform = process.platform, custody =
|
|
|
4070
4498
|
}
|
|
4071
4499
|
const decoded = decodeHostRelayConfig(value);
|
|
4072
4500
|
const config = resolveRelayIpcEndpoint(decoded);
|
|
4073
|
-
validateHostRelaySourcePaths(config);
|
|
4074
4501
|
return config;
|
|
4075
4502
|
} catch (error) {
|
|
4076
4503
|
throw relayConfigReadError(error);
|
|
@@ -4105,13 +4532,9 @@ async function assertPrivateRelayConfigDirectory(path, platform, custody) {
|
|
|
4105
4532
|
}
|
|
4106
4533
|
}
|
|
4107
4534
|
function resolveRelayIpcEndpoint(decoded) {
|
|
4108
|
-
if (process.platform !== "win32") return decoded;
|
|
4109
|
-
const endpoint = assertHostRelaySourcePaths(dirname7(decoded.registration_state_file), decoded);
|
|
4110
|
-
return endpoint === decoded.ipc_endpoint ? decoded : { ...decoded, ipc_endpoint: endpoint };
|
|
4111
|
-
}
|
|
4112
|
-
function validateHostRelaySourcePaths(config) {
|
|
4113
4535
|
try {
|
|
4114
|
-
assertHostRelaySourcePaths(
|
|
4536
|
+
const endpoint = assertHostRelaySourcePaths(dirname8(decoded.registration_state_file), decoded);
|
|
4537
|
+
return endpoint === decoded.ipc_endpoint ? decoded : { ...decoded, ipc_endpoint: endpoint };
|
|
4115
4538
|
} catch (error) {
|
|
4116
4539
|
throw new HostRelayConfigError("invalid_config", error instanceof Error ? error.message : "Host Relay source tuple is invalid.");
|
|
4117
4540
|
}
|
|
@@ -4158,21 +4581,51 @@ function validConfigRuntime(value, platform) {
|
|
|
4158
4581
|
return isAbsoluteNormalizedNonRootPath(value.state_root, platform, true) && (platform === "win32" || isAbsoluteNormalizedNonRootPath(value.ipc_endpoint, platform, true)) && boundedInteger(value.drain_interval_ms, 50, 3e4, true);
|
|
4159
4582
|
}
|
|
4160
4583
|
var HOST_RELAY_INVOCATION_MINT_LOG_TAG = "[host-relay-invocation-mint]";
|
|
4161
|
-
|
|
4162
|
-
|
|
4584
|
+
var HOST_RELAY_INVOCATION_MINT_LOG_LINE = new RegExp(String.raw`^\[host-relay-invocation-mint\] timestamp=(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[.]\d{3}Z) outcome=(completed|failed) stage=(registration|gateway_request|gateway_response) latency_ms=(\d{1,16})(?: gateway_origin_host=([A-Za-z0-9.:[\]-]{1,255}))?(?: client_exchange_ref=(${CEAL_HTTP_CLIENT_EXCHANGE_REF_PATTERN_SOURCE.slice(1, -1)}))?(?: gateway_http_request_ref=(${CEAL_HTTP_GATEWAY_REQUEST_REF_PATTERN_SOURCE.slice(1, -1)}))?(?: reason=([a-z][a-z0-9_]{0,63}))?(?: gateway_status=([1-5][0-9]{2}))?$`, "u");
|
|
4585
|
+
var HOST_RELAY_INVOCATION_MINT_REASON_PATTERN = /^[a-z][a-z0-9_]{0,63}$/u;
|
|
4586
|
+
var HOST_RELAY_INVOCATION_MINT_ORIGIN_HOST_PATTERN = /^[A-Za-z0-9.:[\]-]{1,255}$/u;
|
|
4587
|
+
var HOST_RELAY_CLIENT_EXCHANGE_REF_PATTERN = new RegExp(CEAL_HTTP_CLIENT_EXCHANGE_REF_PATTERN_SOURCE, "u");
|
|
4588
|
+
var HOST_RELAY_GATEWAY_HTTP_REQUEST_REF_PATTERN = new RegExp(CEAL_HTTP_GATEWAY_REQUEST_REF_PATTERN_SOURCE, "u");
|
|
4589
|
+
function formatHostRelayInvocationMintLine(result2, context) {
|
|
4590
|
+
const gatewayStatus = context.stage === "gateway_response" ? boundedGatewayStatus(context.gateway_status) : void 0;
|
|
4591
|
+
const originHost = boundedOriginHost(context.gateway_origin_host);
|
|
4592
|
+
const clientExchangeRef = boundedDiagnosticRef(context.client_exchange_ref, HOST_RELAY_CLIENT_EXCHANGE_REF_PATTERN);
|
|
4593
|
+
const gatewayHttpRequestRef = boundedDiagnosticRef(context.gateway_http_request_ref, HOST_RELAY_GATEWAY_HTTP_REQUEST_REF_PATTERN);
|
|
4594
|
+
const latency = boundedLatency(context.latency_ms);
|
|
4595
|
+
const reason = relayRefusalReason(result2);
|
|
4596
|
+
const outcome = result2.status === "ready" ? "completed" : "failed";
|
|
4597
|
+
return `${HOST_RELAY_INVOCATION_MINT_LOG_TAG} timestamp=${context.timestamp} outcome=${outcome} stage=${context.stage} latency_ms=${latency}${optionalField("gateway_origin_host", originHost)}${optionalField("client_exchange_ref", clientExchangeRef)}${optionalField("gateway_http_request_ref", gatewayHttpRequestRef)}${optionalField("reason", reason)}${optionalField("gateway_status", gatewayStatus)}`;
|
|
4598
|
+
}
|
|
4599
|
+
function boundedGatewayStatus(value) {
|
|
4600
|
+
return Number.isSafeInteger(value) && Number(value) >= 100 && Number(value) <= 599 ? value : void 0;
|
|
4601
|
+
}
|
|
4602
|
+
function boundedOriginHost(value) {
|
|
4603
|
+
if (value === void 0 || !HOST_RELAY_INVOCATION_MINT_ORIGIN_HOST_PATTERN.test(value)) return void 0;
|
|
4604
|
+
return value;
|
|
4605
|
+
}
|
|
4606
|
+
function boundedDiagnosticRef(value, pattern) {
|
|
4607
|
+
if (value === void 0 || !pattern.test(value)) return void 0;
|
|
4608
|
+
return value;
|
|
4609
|
+
}
|
|
4610
|
+
function boundedLatency(value) {
|
|
4611
|
+
if (!Number.isSafeInteger(value) || value < 0) return 0;
|
|
4612
|
+
return value;
|
|
4613
|
+
}
|
|
4614
|
+
function relayRefusalReason(result2) {
|
|
4615
|
+
if (result2.status !== "refused") return void 0;
|
|
4616
|
+
return HOST_RELAY_INVOCATION_MINT_REASON_PATTERN.test(result2.reason) ? result2.reason : "host_refusal_invalid";
|
|
4617
|
+
}
|
|
4618
|
+
function optionalField(name, value) {
|
|
4619
|
+
return value === void 0 ? "" : ` ${name}=${value}`;
|
|
4163
4620
|
}
|
|
4164
4621
|
function reportInvocationMintLine(line) {
|
|
4165
|
-
try {
|
|
4166
|
-
process.stderr.write(line);
|
|
4167
|
-
} catch {
|
|
4168
|
-
}
|
|
4169
4622
|
writeHostServiceLogLine(line);
|
|
4170
4623
|
}
|
|
4171
|
-
async function serveHostRelay(config, signal, dependencies
|
|
4172
|
-
const admission = new RelayAdmissionStore(
|
|
4624
|
+
async function serveHostRelay(config, signal, dependencies) {
|
|
4625
|
+
const admission = new RelayAdmissionStore(join7(config.state_root, "admission"));
|
|
4173
4626
|
let server;
|
|
4174
4627
|
try {
|
|
4175
|
-
const pipeKey = process.platform === "win32" ? await loadRelayPipeKey(config.state_root) : void 0;
|
|
4628
|
+
const pipeKey = process.platform === "win32" ? await loadRelayPipeKey(config.state_root, process.platform, dependencies.custody) : void 0;
|
|
4176
4629
|
server = await startHostRelayRuntimeIpc(config, admission, dependencies, pipeKey);
|
|
4177
4630
|
await waitForRelayShutdown(config, signal, dependencies);
|
|
4178
4631
|
} catch (error) {
|
|
@@ -4191,38 +4644,59 @@ async function startHostRelayRuntimeIpc(config, admission, dependencies, pipeKey
|
|
|
4191
4644
|
admission,
|
|
4192
4645
|
...pipeKey === void 0 ? {} : { pipeKey },
|
|
4193
4646
|
mintInvocationContext: async (input, signal) => {
|
|
4647
|
+
const started = performance.now();
|
|
4648
|
+
const observation = { stage: "registration" };
|
|
4649
|
+
const logResult = (result3) => {
|
|
4650
|
+
const context = { timestamp: (/* @__PURE__ */ new Date()).toISOString(), stage: observation.stage, latency_ms: Math.max(0, Math.round(performance.now() - started)), ...observation.gateway_origin_host === void 0 ? {} : { gateway_origin_host: observation.gateway_origin_host }, ...observation.client_exchange_ref === void 0 ? {} : { client_exchange_ref: observation.client_exchange_ref }, ...observation.gateway_http_request_ref === void 0 ? {} : { gateway_http_request_ref: observation.gateway_http_request_ref }, ...observation.gateway_status === void 0 ? {} : { gateway_status: observation.gateway_status } };
|
|
4651
|
+
(dependencies.logInvocationMint ?? reportInvocationMintLine)(`${formatHostRelayInvocationMintLine(result3, context)}
|
|
4652
|
+
`);
|
|
4653
|
+
};
|
|
4194
4654
|
let result2;
|
|
4195
4655
|
try {
|
|
4196
|
-
result2 = await mintInvocationContextAtGateway(config, input, signal, dependencies.fetch
|
|
4656
|
+
result2 = await mintInvocationContextAtGateway(config, input, signal, dependencies.fetch, observation, dependencies.custody);
|
|
4197
4657
|
} catch (error) {
|
|
4198
|
-
const refused = { schema_version:
|
|
4199
|
-
(
|
|
4200
|
-
`);
|
|
4658
|
+
const refused = { schema_version: HOST_RELAY_INVOCATION_CONTEXT_RESULT_SCHEMA, status: "refused", reason: "gateway_unavailable" };
|
|
4659
|
+
logResult(refused);
|
|
4201
4660
|
throw error;
|
|
4202
4661
|
}
|
|
4203
|
-
(
|
|
4204
|
-
`);
|
|
4662
|
+
logResult(result2);
|
|
4205
4663
|
return result2;
|
|
4206
4664
|
}
|
|
4207
4665
|
});
|
|
4208
4666
|
}
|
|
4209
|
-
async function mintInvocationContextAtGateway(config, input, signal, fetchGateway) {
|
|
4667
|
+
async function mintInvocationContextAtGateway(config, input, signal, fetchGateway, observation, custody = {}) {
|
|
4668
|
+
let registration;
|
|
4669
|
+
try {
|
|
4670
|
+
registration = await readHostRegistrationAuthority(config.registration_state_file, config.host_source_ref, process.platform, custody);
|
|
4671
|
+
} catch {
|
|
4672
|
+
return mintRefusal("relay_unavailable");
|
|
4673
|
+
}
|
|
4210
4674
|
try {
|
|
4211
|
-
|
|
4212
|
-
|
|
4675
|
+
observation.gateway_origin_host = new URL(registration.gateway_request_origin).hostname;
|
|
4676
|
+
observation.stage = "gateway_request";
|
|
4677
|
+
return await gatewayMintPost(registration, input, signal, fetchGateway, observation);
|
|
4213
4678
|
} catch (error) {
|
|
4214
4679
|
return gatewayMintFailure(signal, error);
|
|
4215
4680
|
}
|
|
4216
4681
|
}
|
|
4217
|
-
async function gatewayMintPost(registration, input, signal, fetchGateway) {
|
|
4682
|
+
async function gatewayMintPost(registration, input, signal, fetchGateway, observation) {
|
|
4218
4683
|
const serialized = JSON.stringify(gatewayMintBody(input));
|
|
4219
4684
|
if (Buffer.byteLength(serialized, "utf8") > CEAL_HOST_INVOCATION_CONTEXT_REQUEST_MAX_BYTES) return mintRefusal("producer_frame_invalid");
|
|
4685
|
+
const clientExchangeRef = `client-exchange:${randomUUID().replaceAll("-", "")}`;
|
|
4686
|
+
observation.client_exchange_ref = clientExchangeRef;
|
|
4220
4687
|
const response2 = await fetchGateway(`${registration.gateway_request_origin}${CEAL_HOST_INVOCATION_CONTEXT_PATH}`, {
|
|
4221
4688
|
method: "POST",
|
|
4222
|
-
headers: { authorization: `Bearer ${registration.host_access_token}`, "content-type": "application/json" },
|
|
4689
|
+
headers: { authorization: `Bearer ${registration.host_access_token}`, "content-type": "application/json", [CEAL_HTTP_CLIENT_EXCHANGE_REF_HEADER]: clientExchangeRef },
|
|
4223
4690
|
body: serialized,
|
|
4224
4691
|
signal
|
|
4225
4692
|
});
|
|
4693
|
+
observation.stage = "gateway_response";
|
|
4694
|
+
observation.gateway_status = boundedGatewayStatus(response2.status);
|
|
4695
|
+
try {
|
|
4696
|
+
const gatewayHttpRequestRef = response2.headers.get(CEAL_HTTP_GATEWAY_REQUEST_REF_HEADER);
|
|
4697
|
+
if (gatewayHttpRequestRef !== null && HOST_RELAY_GATEWAY_HTTP_REQUEST_REF_PATTERN.test(gatewayHttpRequestRef)) observation.gateway_http_request_ref = gatewayHttpRequestRef;
|
|
4698
|
+
} catch {
|
|
4699
|
+
}
|
|
4226
4700
|
const raw = await readBoundedResponseText(response2, 8192);
|
|
4227
4701
|
return decodeGatewayMintResponse(response2, raw);
|
|
4228
4702
|
}
|
|
@@ -4245,18 +4719,21 @@ function decodeGatewayMintResponse(response2, raw) {
|
|
|
4245
4719
|
} catch {
|
|
4246
4720
|
value = null;
|
|
4247
4721
|
}
|
|
4248
|
-
if (!response2.ok)
|
|
4722
|
+
if (!response2.ok) {
|
|
4723
|
+
const reason = gatewayMintRefusal(response2.status, value);
|
|
4724
|
+
return mintRefusal(reason, reason === "gateway_refused" ? response2.status : void 0);
|
|
4725
|
+
}
|
|
4249
4726
|
if (!isMintResult(value)) return mintRefusal("gateway_response_invalid");
|
|
4250
4727
|
const requestRef = response2.headers.get("ceal-request-ref");
|
|
4251
4728
|
if (requestRef === null || !/^ceal-request:[a-f0-9-]{36}$/u.test(requestRef)) return mintRefusal("gateway_response_invalid");
|
|
4252
4729
|
const result2 = decodeCealHostInvocationAuthenticationResult(value, /* @__PURE__ */ new Date());
|
|
4253
|
-
return { schema_version:
|
|
4730
|
+
return { schema_version: HOST_RELAY_INVOCATION_CONTEXT_RESULT_SCHEMA, status: "ready", request_ref: requestRef, result: result2 };
|
|
4254
4731
|
}
|
|
4255
4732
|
function gatewayMintFailure(signal, _error) {
|
|
4256
4733
|
return mintRefusal(signal.aborted ? "transient_retryable" : "gateway_unavailable");
|
|
4257
4734
|
}
|
|
4258
|
-
function mintRefusal(reason) {
|
|
4259
|
-
return { schema_version:
|
|
4735
|
+
function mintRefusal(reason, gatewayStatus) {
|
|
4736
|
+
return { schema_version: HOST_RELAY_INVOCATION_CONTEXT_RESULT_SCHEMA, status: "refused", reason, ...gatewayStatus === void 0 ? {} : { gateway_status: gatewayStatus } };
|
|
4260
4737
|
}
|
|
4261
4738
|
async function readBoundedResponseText(response2, maximumBytes) {
|
|
4262
4739
|
if (response2.body === null) return null;
|
|
@@ -4293,13 +4770,16 @@ function gatewayMintRefusal(status, value) {
|
|
|
4293
4770
|
if (status === 403 && record5(value)) {
|
|
4294
4771
|
if (value.error_code === "host_source_refused") return "host_source_refused";
|
|
4295
4772
|
if (value.error_code === "context_expired") return "context_expired";
|
|
4296
|
-
if (value.error_code === "request_context_refused")
|
|
4773
|
+
if (value.error_code === "request_context_refused") {
|
|
4774
|
+
if (isVocabularyWord(CEAL_HOST_MINT_REQUEST_CONTEXT_REFUSAL_REASONS, value.reason) && value.reason === "request_authority_unavailable") return "gateway_unavailable";
|
|
4775
|
+
return "mint_failed";
|
|
4776
|
+
}
|
|
4297
4777
|
}
|
|
4298
4778
|
if (status === 429) return "gateway_rate_limited";
|
|
4299
4779
|
if (status >= 500) return "gateway_unavailable";
|
|
4300
4780
|
return "gateway_refused";
|
|
4301
4781
|
}
|
|
4302
|
-
async function runHostRelayCli(args, signal, dependencies
|
|
4782
|
+
async function runHostRelayCli(args, signal, dependencies) {
|
|
4303
4783
|
try {
|
|
4304
4784
|
const configPath = parseServeArgs(args);
|
|
4305
4785
|
const config = await (dependencies.readConfig ?? readHostRelayConfig)(configPath);
|
|
@@ -4334,6 +4814,7 @@ function exactOptionalKeys2(value, required, optional) {
|
|
|
4334
4814
|
}
|
|
4335
4815
|
|
|
4336
4816
|
// host/relay/bin/ceal-host-relay.ts
|
|
4817
|
+
var RELAY_COMMAND_SCHEMA = "ceal.host_relay_command.v1";
|
|
4337
4818
|
var serviceArguments = consumeHostServiceLogArgument(process.argv.slice(2));
|
|
4338
4819
|
if (serviceArguments.path !== void 0) process.env[HOST_SERVICE_LOG_ENVIRONMENT] = serviceArguments.path;
|
|
4339
4820
|
var controller = new AbortController();
|
|
@@ -4341,13 +4822,11 @@ var stop = () => controller.abort();
|
|
|
4341
4822
|
process.once("SIGINT", stop);
|
|
4342
4823
|
process.once("SIGTERM", stop);
|
|
4343
4824
|
var stopLogBound = boundHostServiceLog();
|
|
4344
|
-
void runHostRelayCli(serviceArguments.args, controller.signal).then((result2) => {
|
|
4345
|
-
process.stdout.write(
|
|
4346
|
-
`);
|
|
4825
|
+
void runHostRelayCli(serviceArguments.args, controller.signal, { fetch: globalThis.fetch }).then(async (result2) => {
|
|
4826
|
+
await writeHostServiceCommandResult(RELAY_COMMAND_SCHEMA, result2, (line) => process.stdout.write(line));
|
|
4347
4827
|
process.exitCode = result2.ok ? 0 : 1;
|
|
4348
|
-
}).catch((error) => {
|
|
4349
|
-
|
|
4350
|
-
`);
|
|
4828
|
+
}).catch(async (error) => {
|
|
4829
|
+
await writeHostServiceCommandResult(RELAY_COMMAND_SCHEMA, { ok: false, ...hostTerminalFailure(error, "Relay") }, (line) => process.stdout.write(line));
|
|
4351
4830
|
process.exitCode = 1;
|
|
4352
4831
|
}).finally(() => {
|
|
4353
4832
|
stopLogBound();
|