@corca-org/ceal-host-win32-x64 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ceal-host.exe +0 -0
- package/libexec/ceal-host/ceal-host-background.exe +0 -0
- package/libexec/ceal-host/claude-hook.mjs +394 -81
- package/libexec/ceal-host/claude-invocation-authentication.mjs +394 -83
- package/libexec/ceal-host/claude-producer.mjs +383 -74
- package/libexec/ceal-host/codex-hook.mjs +334 -67
- package/libexec/ceal-host/codex-invocation-authentication.mjs +333 -66
- package/libexec/ceal-host/codex-producer.mjs +324 -57
- package/libexec/ceal-host/control.mjs +455 -126
- package/libexec/ceal-host/relay.mjs +53 -15
- package/package.json +1 -1
- package/share/ceal-host/bundle-manifest.json +13 -13
- package/share/ceal-host/bundle-manifest.sigstore.json +1 -1
|
@@ -91,7 +91,7 @@ var client_wire_contract_default = {
|
|
|
91
91
|
},
|
|
92
92
|
command_request: {
|
|
93
93
|
schema_name: "ceal.command_request",
|
|
94
|
-
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context"],
|
|
94
|
+
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context", "materialize_result"],
|
|
95
95
|
absolute_transport_max_bytes: 65536
|
|
96
96
|
},
|
|
97
97
|
command_resolution: {
|
|
@@ -137,7 +137,7 @@ var client_wire_contract_default = {
|
|
|
137
137
|
},
|
|
138
138
|
command_response: {
|
|
139
139
|
schema_name: "ceal.command_response",
|
|
140
|
-
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context"],
|
|
140
|
+
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context", "result_file"],
|
|
141
141
|
descriptor_field: "verified_artifact",
|
|
142
142
|
request_context_field: "request_context",
|
|
143
143
|
required_fields: [
|
|
@@ -150,7 +150,8 @@ var client_wire_contract_default = {
|
|
|
150
150
|
"visible_output_max_bytes",
|
|
151
151
|
"local_delivery",
|
|
152
152
|
"verified_artifact",
|
|
153
|
-
"request_context"
|
|
153
|
+
"request_context",
|
|
154
|
+
"result_file"
|
|
154
155
|
],
|
|
155
156
|
bare_document_fields: [
|
|
156
157
|
"invocation",
|
|
@@ -419,6 +420,9 @@ var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavaila
|
|
|
419
420
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
420
421
|
var CEAL_AUDIT_OUTCOMES = vocabulary(["succeeded", "denied", "failed"]);
|
|
421
422
|
var CEAL_GATEWAY_PROVIDER_STEP_OUTCOMES = vocabulary(["completed", "rejected", "throttled", "failed"]);
|
|
423
|
+
var CEAL_GATEWAY_CORPUS_READ_PROVIDERS = vocabulary(["slack", "google_drive", "notion"]);
|
|
424
|
+
var CEAL_GATEWAY_CORPUS_READ_OUTCOMES = vocabulary(["answered_from_corpus", "live_fallback"]);
|
|
425
|
+
var CEAL_GATEWAY_CORPUS_READ_FALLBACK_REASONS = vocabulary(["uncovered_window", "stale", "not_organization_public", "partition_missing"]);
|
|
422
426
|
var CEAL_GATEWAY_READ_REUSE_DISPOSITIONS = vocabulary(["response_cache_hit", "corpus_hit", "corpus_hit_after_revalidation", "corpus_partial_provider_supplement", "provider_direct", "provider_continuation", "reuse_unavailable"]);
|
|
423
427
|
var CEAL_GATEWAY_READ_REUSE_UNAVAILABLE_REASONS = vocabulary(["not_reported", "storage_unavailable", "coverage_incomplete", "freshness_refresh_required", "not_reusable", "bypassed"]);
|
|
424
428
|
var CEAL_GATEWAY_DERIVED_STORE_FAILURE_CLASSES = vocabulary(["storage_unavailable", "decode_mismatch", "write_conflict", "quota", "store_error"]);
|
|
@@ -459,6 +463,21 @@ var CEAL_GATEWAY_ORGANIZATION_ROUTE_FACT_CALL_KEYS = Object.freeze([
|
|
|
459
463
|
]);
|
|
460
464
|
|
|
461
465
|
// packages/ceal-client-protocol/src/gateway-validation-primitives.ts
|
|
466
|
+
var POSIX_HOME_ROOTS = [["/", "home"].join(""), ["/", "Users"].join("")];
|
|
467
|
+
var WINDOWS_HOME_ROOT = ["C:", "\\", "Users"].join("");
|
|
468
|
+
var USER_SEGMENT_BODY = "[^/\\\\ \\t\\r\\n\"'`${}]+";
|
|
469
|
+
var POSIX_SEGMENT_END = "(?:/|$|(?=[\\s\"'`]))";
|
|
470
|
+
var WINDOWS_SEGMENT_END = "(?:\\\\+|$|(?=[\\s\"'`]))";
|
|
471
|
+
var WINDOWS_USER_SEGMENT_BODY = "[^\\\\ \\t\\r\\n\"'`${}]+";
|
|
472
|
+
var ABSOLUTE_PATH_BOUNDARY = "(?<![A-Za-z0-9_])";
|
|
473
|
+
function escapePathPattern(value) {
|
|
474
|
+
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
475
|
+
}
|
|
476
|
+
function machineHomePathPatterns(flags) {
|
|
477
|
+
const posix5 = `${ABSOLUTE_PATH_BOUNDARY}(?:${POSIX_HOME_ROOTS.map(escapePathPattern).join("|")})/${USER_SEGMENT_BODY}${POSIX_SEGMENT_END}`;
|
|
478
|
+
const windows = `${ABSOLUTE_PATH_BOUNDARY}${escapePathPattern(WINDOWS_HOME_ROOT)}\\\\+${WINDOWS_USER_SEGMENT_BODY}${WINDOWS_SEGMENT_END}`;
|
|
479
|
+
return [new RegExp(posix5, flags), new RegExp(windows, flags)];
|
|
480
|
+
}
|
|
462
481
|
var CealProtocolValidationError = class extends Error {
|
|
463
482
|
name = "CealProtocolValidationError";
|
|
464
483
|
code;
|
|
@@ -814,6 +833,7 @@ var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Rel
|
|
|
814
833
|
var HOST_INSTALL_REPAIR = "The local Host or Relay is missing, stale, or unavailable. Run `ceal-host install`, then `ceal-host discovery sync`, and retry from a new producer conversation.";
|
|
815
834
|
var HOST_CONTEXT_UNAVAILABLE = "The Host could not select this turn; reason uncertain. Host mode is unavailable in an ephemeral side conversation. When you know you are in one, `ceal --standalone ...` uses your configured Ceal session/Gateway permissions, without Host session/turn correlation or Host usage attribution. Unknown-outcome `repeat_request` needs the same Host turn or explicit `--request-context`. Otherwise return to the original regular conversation. Host refusal never switches modes; report intended Host calls as a gap.";
|
|
816
835
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
836
|
+
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
817
837
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
818
838
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
819
839
|
}
|
|
@@ -834,13 +854,18 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
834
854
|
context_not_selected: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
835
855
|
context_store_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
836
856
|
context_store_conflict: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
837
|
-
refresh_invalid: guidance(
|
|
838
|
-
refresh_expired: guidance(
|
|
839
|
-
refresh_replayed: guidance(
|
|
840
|
-
refresh_revoked: guidance(
|
|
841
|
-
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
842
|
-
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
843
|
-
|
|
857
|
+
refresh_invalid: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
858
|
+
refresh_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
859
|
+
refresh_replayed: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
860
|
+
refresh_revoked: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
861
|
+
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family. Ask an Admin to reactivate the Person, then retry this same session refresh.", "ask_admin", 403),
|
|
862
|
+
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family. Ask an Admin to reactivate the Principal, then retry this same session refresh.", "ask_admin", 403),
|
|
863
|
+
authority_replaced: guidance("The Gateway authority has been replaced; this session is no longer valid here. Run `ceal session adopt --gateway <origin> --email <email>` against the current Gateway to complete mailbox-confirmed recovery.", "repair_or_adopt_session", 409),
|
|
864
|
+
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
865
|
+
refresh_recovery_unavailable: guidance("The Gateway's durable refresh-recovery key is unavailable. Retry the same refresh attempt after the key is available.", "retry", 503, true),
|
|
866
|
+
refresh_recovery_outcome_unavailable: guidance("The Gateway could not safely recover the outcome of a prior refresh. Ask an administrator to inspect the Gateway session state before retrying or adopting this session.", "ask_admin", 503),
|
|
867
|
+
refresh_state_unavailable: guidance("The Gateway session state store is temporarily unavailable; retry the same refresh attempt when it is available.", "retry", 503, true),
|
|
868
|
+
refresh_recovery_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
844
869
|
refresh_custody_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
845
870
|
session_store_unwritable: guidance("The Ceal client could not write its local session store; the operating system refused the write (EACCES, EPERM, or EROFS). rerun_outside_agent_sandbox reruns it with escalated execution.", "rerun_outside_agent_sandbox", 500),
|
|
846
871
|
local_output_exists: guidance("The selected local output path already exists; nothing was written to it.", "choose_new_output_path", 400),
|
|
@@ -855,10 +880,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
855
880
|
resource_stream_failed: guidance("The provider resource stream failed; ask an administrator to inspect the Gateway failure log.", "ask_admin", 500),
|
|
856
881
|
gateway_unavailable: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 503, true),
|
|
857
882
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
858
|
-
//
|
|
859
|
-
|
|
860
|
-
// when the wait ends still unserved, moved from the `localFailureText` default branch.
|
|
861
|
-
[CEAL_GATEWAY_STARTING_FAILURE_CODE]: guidance(LOCAL_TRANSPORT_INCOMPLETE, "answer_with_gap", 503, true),
|
|
883
|
+
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
884
|
+
[CEAL_GATEWAY_STARTING_FAILURE_CODE]: guidance("The Gateway is still starting; the refresh was not attempted and the refresh token was not consumed. Retry the same refresh attempt after the Gateway is serving.", "retry", 503, true),
|
|
862
885
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
863
886
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
864
887
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
@@ -870,6 +893,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
870
893
|
// The safe move varies by request. Keep the sentence conditional on the
|
|
871
894
|
// same `retryable` and `next_action` facts the response exposes.
|
|
872
895
|
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
896
|
+
// A provider write the Gateway command deadline cut after its dispatch: the write left and its receipt is still settling, so the caller reads the receipt instead of repeating the write.
|
|
897
|
+
write_in_progress: guidance("The provider write was dispatched but the Gateway command deadline cut the wait before its outcome settled. Do not repeat the write; read the durable receipt named by write_request_ref with write_receipt.get.", "write_receipt.get", 500),
|
|
873
898
|
// Restored verbatim from the retired `localFailureText`
|
|
874
899
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
875
900
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -1519,6 +1544,8 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1519
1544
|
"review_submitted",
|
|
1520
1545
|
"comment_created",
|
|
1521
1546
|
"reaction_created",
|
|
1547
|
+
"pull_request_merged",
|
|
1548
|
+
"release_published",
|
|
1522
1549
|
"ceal_write_completed",
|
|
1523
1550
|
"event_start",
|
|
1524
1551
|
"all_day_start",
|
|
@@ -1530,7 +1557,7 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1530
1557
|
"page_last_edited",
|
|
1531
1558
|
"resource_modified"
|
|
1532
1559
|
]);
|
|
1533
|
-
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "notion"]);
|
|
1560
|
+
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "google-mail", "notion"]);
|
|
1534
1561
|
var CEAL_ACTIVITY_UNSUPPORTED_EVENT_KIND_CODE = "unsupported_event_kind";
|
|
1535
1562
|
var CEAL_ACTIVITY_GAP_CODES = vocabulary([
|
|
1536
1563
|
"provider_page_budget",
|
|
@@ -1551,6 +1578,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1551
1578
|
"github.pull_request.opened",
|
|
1552
1579
|
"github.issue.edited",
|
|
1553
1580
|
"github.pull_request.edited",
|
|
1581
|
+
"github.pull_request.merged",
|
|
1582
|
+
"github.release.published",
|
|
1554
1583
|
"github.review.submitted",
|
|
1555
1584
|
"github.issue_comment.created",
|
|
1556
1585
|
"github.review_comment.created",
|
|
@@ -1564,6 +1593,7 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1564
1593
|
"drive.file.created",
|
|
1565
1594
|
"drive.file.modified",
|
|
1566
1595
|
"drive.file.viewed",
|
|
1596
|
+
"mail.sent",
|
|
1567
1597
|
"notion.page.created",
|
|
1568
1598
|
"notion.page.edited"
|
|
1569
1599
|
]);
|
|
@@ -1577,6 +1607,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1577
1607
|
"github.review_comment.created": "comment_created",
|
|
1578
1608
|
"github.issue.opened": "resource_created",
|
|
1579
1609
|
"github.pull_request.opened": "resource_created",
|
|
1610
|
+
"github.pull_request.merged": "pull_request_merged",
|
|
1611
|
+
"github.release.published": "release_published",
|
|
1580
1612
|
"github.issue.edited": "resource_modified",
|
|
1581
1613
|
"github.pull_request.edited": "resource_modified",
|
|
1582
1614
|
"github.reaction.created": "reaction_created",
|
|
@@ -1587,6 +1619,7 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1587
1619
|
"drive.file.created": "file_created",
|
|
1588
1620
|
"drive.file.modified": "file_modified_by_me",
|
|
1589
1621
|
"drive.file.viewed": "file_viewed_by_me",
|
|
1622
|
+
"mail.sent": "message_created",
|
|
1590
1623
|
"notion.page.created": "page_created",
|
|
1591
1624
|
"notion.page.edited": "page_last_edited"
|
|
1592
1625
|
});
|
|
@@ -1697,6 +1730,8 @@ var CEAL_REFRESH_FAILURE_CODES = vocabulary([
|
|
|
1697
1730
|
"principal_inactive",
|
|
1698
1731
|
"authority_replaced",
|
|
1699
1732
|
"refresh_recovery_unavailable",
|
|
1733
|
+
"refresh_recovery_outcome_unavailable",
|
|
1734
|
+
"refresh_state_unavailable",
|
|
1700
1735
|
"refresh_recovery_expired",
|
|
1701
1736
|
// The serving gate answers this while the Gateway is still starting and the
|
|
1702
1737
|
// refresh was never attempted; the same attempt stays retryable. It is never
|
|
@@ -2455,6 +2490,211 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
2455
2490
|
maximum: CEAL_PROTOCOL_VERSION
|
|
2456
2491
|
});
|
|
2457
2492
|
|
|
2493
|
+
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
2494
|
+
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
2495
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSES = 8;
|
|
2496
|
+
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
2497
|
+
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
2498
|
+
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
2499
|
+
var OPERATOR_DIAGNOSTIC_HOME_PATHS = machineHomePathPatterns("gu");
|
|
2500
|
+
function redactOperatorDiagnosticSecrets(value) {
|
|
2501
|
+
return value.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/giu, "Bearer [redacted]").replace(/(["']?(?:authorization|[A-Za-z0-9_-]*(?:token|secret|credential|password|key))["']?\s*[:=]\s*)(?!(?:"unknown"|'unknown'|unknown\b))(?:"[^"]*"|'[^']*'|[^\s,;}]+)/giu, "$1[redacted]");
|
|
2502
|
+
}
|
|
2503
|
+
function redactOperatorDiagnosticText(value) {
|
|
2504
|
+
const normalized = normalizeCealSingleLineText(value);
|
|
2505
|
+
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
2506
|
+
}
|
|
2507
|
+
function renderOperatorDiagnostic(value) {
|
|
2508
|
+
const state = collectDiagnosticState(value);
|
|
2509
|
+
const fields = [
|
|
2510
|
+
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
2511
|
+
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
2512
|
+
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
2513
|
+
state.stderr === void 0 ? void 0 : `stderr_tail=${JSON.stringify(tail(state.stderr))}`,
|
|
2514
|
+
state.causes.length === 0 ? void 0 : `causes=${state.causes.map(formatCause).join(" <- ")}`
|
|
2515
|
+
].filter((field) => field !== void 0);
|
|
2516
|
+
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
2517
|
+
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
2518
|
+
}
|
|
2519
|
+
function collectDiagnosticState(value) {
|
|
2520
|
+
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0 };
|
|
2521
|
+
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
2522
|
+
while (pending.length > 0 && state.causes.length < OPERATOR_DIAGNOSTIC_MAX_CAUSES) {
|
|
2523
|
+
const current = pending.shift();
|
|
2524
|
+
if (current !== void 0) visitDiagnosticNode(current, state, pending, visited);
|
|
2525
|
+
}
|
|
2526
|
+
return state;
|
|
2527
|
+
}
|
|
2528
|
+
function visitDiagnosticNode(current, state, pending, visited) {
|
|
2529
|
+
if (isObject(current)) {
|
|
2530
|
+
if (visited.has(current)) return;
|
|
2531
|
+
visited.add(current);
|
|
2532
|
+
}
|
|
2533
|
+
captureProcessEvidence(current, state);
|
|
2534
|
+
appendCause(current, state.causes);
|
|
2535
|
+
enqueueCauseChildren(current, state.causes.length, pending);
|
|
2536
|
+
}
|
|
2537
|
+
function captureProcessEvidence(current, state) {
|
|
2538
|
+
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
2539
|
+
if (state.exitCode === void 0) state.exitCode = safeExitCode(read(current, "exitCode")) ?? safeExitCode(read(current, "status")) ?? safeExitCode(read(current, "code"));
|
|
2540
|
+
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
2541
|
+
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
2542
|
+
}
|
|
2543
|
+
function appendCause(current, causes) {
|
|
2544
|
+
const errors = read(current, "errors");
|
|
2545
|
+
if (current instanceof Error && (!(current instanceof AggregateError) || !Array.isArray(errors) || errors.length === 0)) {
|
|
2546
|
+
causes.push(errorCause(current));
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
if (!isObject(current)) {
|
|
2550
|
+
const message = safeText(current);
|
|
2551
|
+
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
function errorCause(error) {
|
|
2555
|
+
const name = safeText(read(error, "name")) ?? "Error";
|
|
2556
|
+
const message = safeText(read(error, "message"));
|
|
2557
|
+
const codeValue = read(error, "code");
|
|
2558
|
+
const code = typeof codeValue === "number" && Number.isFinite(codeValue) ? codeValue : safeText(codeValue);
|
|
2559
|
+
const errnoValue = read(error, "errno");
|
|
2560
|
+
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
2561
|
+
const syscall = safeText(read(error, "syscall"));
|
|
2562
|
+
const path = safePath(read(error, "path"));
|
|
2563
|
+
return Object.freeze({ error_class: name, ...message === void 0 ? {} : { message }, ...code === void 0 ? {} : { code }, ...errno === void 0 ? {} : { errno }, ...syscall === void 0 ? {} : { syscall }, ...path === void 0 ? {} : { path } });
|
|
2564
|
+
}
|
|
2565
|
+
function enqueueCauseChildren(current, causeCount, pending) {
|
|
2566
|
+
const cause = read(current, "cause");
|
|
2567
|
+
if (cause !== void 0) pending.push(cause);
|
|
2568
|
+
const errors = read(current, "errors");
|
|
2569
|
+
if (Array.isArray(errors)) pending.push(...errors.slice(0, OPERATOR_DIAGNOSTIC_MAX_CAUSES - causeCount));
|
|
2570
|
+
}
|
|
2571
|
+
function isObject(value) {
|
|
2572
|
+
return typeof value === "object" && value !== null;
|
|
2573
|
+
}
|
|
2574
|
+
function formatCause(cause) {
|
|
2575
|
+
const fields = [
|
|
2576
|
+
cause.error_class,
|
|
2577
|
+
cause.code === void 0 ? void 0 : `code=${JSON.stringify(safeDiagnosticText(cause.code))}`,
|
|
2578
|
+
cause.errno === void 0 ? void 0 : `errno=${cause.errno}`,
|
|
2579
|
+
cause.syscall === void 0 ? void 0 : `syscall=${JSON.stringify(cause.syscall)}`,
|
|
2580
|
+
cause.path === void 0 ? void 0 : `path=${JSON.stringify(cause.path)}`,
|
|
2581
|
+
cause.message === void 0 ? void 0 : `message=${cause.message}`
|
|
2582
|
+
].filter((field) => field !== void 0);
|
|
2583
|
+
return fields.join(" ");
|
|
2584
|
+
}
|
|
2585
|
+
function tail(value) {
|
|
2586
|
+
const clipped = value.length <= OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT ? value : `…${value.slice(-OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT)}`;
|
|
2587
|
+
return safeDiagnosticText(clipped);
|
|
2588
|
+
}
|
|
2589
|
+
function safeText(value) {
|
|
2590
|
+
if (typeof value !== "string") return void 0;
|
|
2591
|
+
const safe = safeDiagnosticText(value);
|
|
2592
|
+
if (safe.length === 0) return void 0;
|
|
2593
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT) return safe;
|
|
2594
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT / 2);
|
|
2595
|
+
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
2596
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2597
|
+
}
|
|
2598
|
+
function safePath(value) {
|
|
2599
|
+
if (typeof value !== "string") return void 0;
|
|
2600
|
+
const safe = safeDiagnosticText(value);
|
|
2601
|
+
if (safe.length === 0) return void 0;
|
|
2602
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
2603
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
2604
|
+
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
2605
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2606
|
+
}
|
|
2607
|
+
function safeDiagnosticText(value) {
|
|
2608
|
+
return redactOperatorDiagnosticText(String(value));
|
|
2609
|
+
}
|
|
2610
|
+
function outputText(value) {
|
|
2611
|
+
if (typeof value === "string") return redactOperatorDiagnosticText(value);
|
|
2612
|
+
if (value instanceof Uint8Array) {
|
|
2613
|
+
try {
|
|
2614
|
+
return redactOperatorDiagnosticText(new TextDecoder().decode(value));
|
|
2615
|
+
} catch {
|
|
2616
|
+
return void 0;
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
return void 0;
|
|
2620
|
+
}
|
|
2621
|
+
function safeStatus(value) {
|
|
2622
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
2623
|
+
return typeof value === "string" ? safeText(value) : void 0;
|
|
2624
|
+
}
|
|
2625
|
+
function safeExitCode(value) {
|
|
2626
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
2627
|
+
}
|
|
2628
|
+
function read(value, key) {
|
|
2629
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) return void 0;
|
|
2630
|
+
try {
|
|
2631
|
+
return Reflect.get(value, key);
|
|
2632
|
+
} catch {
|
|
2633
|
+
return void 0;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
function redactHomePaths(value) {
|
|
2637
|
+
const paths = [
|
|
2638
|
+
...OPERATOR_DIAGNOSTIC_HOME_PATHS.flatMap((pattern) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, matchedHomePrefixLength(match[0])))),
|
|
2639
|
+
...configuredHomePathPatterns().flatMap(({ pattern, prefixLength }) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, prefixLength)))
|
|
2640
|
+
];
|
|
2641
|
+
paths.sort((left, right) => left.start - right.start || right.end - left.end);
|
|
2642
|
+
let output = "";
|
|
2643
|
+
let cursor = 0;
|
|
2644
|
+
for (const path of paths) {
|
|
2645
|
+
if (path.start < cursor) continue;
|
|
2646
|
+
output += `${value.slice(cursor, path.start)}[home path redacted]${value.slice(path.prefixEnd, path.end)}`;
|
|
2647
|
+
cursor = path.end;
|
|
2648
|
+
}
|
|
2649
|
+
return output + value.slice(cursor);
|
|
2650
|
+
}
|
|
2651
|
+
function configuredHomePathPatterns() {
|
|
2652
|
+
const homes = [...new Set([process.env.HOME, process.env.USERPROFILE].filter((home) => home !== void 0 && home.length > 0))];
|
|
2653
|
+
return homes.flatMap((home) => {
|
|
2654
|
+
const root = home.replace(/[\\/]+$/gu, "");
|
|
2655
|
+
if (root.length === 0 || root === "/" || /^[A-Za-z]:$/u.test(root)) return [];
|
|
2656
|
+
const pattern = new RegExp(`(?<![A-Za-z0-9_])${escapePathPattern(root)}(?=$|[\\\\/\\s"'\`<>(){}\\[\\],;])`, /^[A-Za-z]:[\\/]/u.test(root) ? "giu" : "gu");
|
|
2657
|
+
return [{ pattern, prefixLength: root.length }];
|
|
2658
|
+
});
|
|
2659
|
+
}
|
|
2660
|
+
function matchedHomePrefixLength(value) {
|
|
2661
|
+
let separators = 0;
|
|
2662
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
2663
|
+
if (value[index] !== "/" && value[index] !== "\\") continue;
|
|
2664
|
+
separators += 1;
|
|
2665
|
+
if (separators === 3) return index;
|
|
2666
|
+
}
|
|
2667
|
+
return value.length;
|
|
2668
|
+
}
|
|
2669
|
+
function redactUrls(value) {
|
|
2670
|
+
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
2671
|
+
}
|
|
2672
|
+
function redactFilePaths(value) {
|
|
2673
|
+
return value.replaceAll(/(?<![A-Za-z0-9._-]|\[home path redacted\])(?:[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/)[^:\r\n"'<>]*?(?=:\d+(?::\d+)?(?:[:\s]|$)|[\r\n]|["'])/gu, "[path redacted]");
|
|
2674
|
+
}
|
|
2675
|
+
function homePathRange(value, match, prefixLength) {
|
|
2676
|
+
const index = match.index;
|
|
2677
|
+
if (index === void 0) return { start: value.length, end: value.length, prefixEnd: value.length };
|
|
2678
|
+
const start = index;
|
|
2679
|
+
let end = start + match[0].length;
|
|
2680
|
+
const quote = start > 0 && (value[start - 1] === "'" || value[start - 1] === '"') ? value[start - 1] : void 0;
|
|
2681
|
+
if (quote !== void 0) {
|
|
2682
|
+
const closing = value.indexOf(quote, end);
|
|
2683
|
+
if (closing >= 0) end = closing;
|
|
2684
|
+
}
|
|
2685
|
+
while (end < value.length && !/[\s"'`<>(){}[\],;]/u.test(value[end] ?? "")) end += 1;
|
|
2686
|
+
return { start, end, prefixEnd: Math.min(start + prefixLength, end) };
|
|
2687
|
+
}
|
|
2688
|
+
function truncateUtf8(value, maxBytes) {
|
|
2689
|
+
if (byteLength(value) <= maxBytes) return value;
|
|
2690
|
+
let output = "";
|
|
2691
|
+
for (const character of value) {
|
|
2692
|
+
if (byteLength(`${output}${character}…`) > maxBytes) break;
|
|
2693
|
+
output += character;
|
|
2694
|
+
}
|
|
2695
|
+
return `${output}…`;
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2458
2698
|
// packages/ceal-client-protocol/src/admin-projection-vocabulary.ts
|
|
2459
2699
|
var ADMIN_PROJECTION_STATES = vocabulary(["ready", "empty", "partial", "unknown"]);
|
|
2460
2700
|
var ADMIN_VIEW_KINDS = vocabulary(["request_detail", "resource_access_timeline", "weekly_usage"]);
|
|
@@ -3119,9 +3359,9 @@ async function readTranscriptCompleteChunk(handle, offset, size) {
|
|
|
3119
3359
|
let lastNewline = -1;
|
|
3120
3360
|
while (position < size) {
|
|
3121
3361
|
const buffer = Buffer.alloc(Math.min(HOST_TRANSCRIPT_READ_CHUNK_BYTES, size - position));
|
|
3122
|
-
const
|
|
3123
|
-
if (
|
|
3124
|
-
const chunk = buffer.subarray(0,
|
|
3362
|
+
const read2 = await handle.read(buffer, 0, buffer.length, position);
|
|
3363
|
+
if (read2.bytesRead === 0) break;
|
|
3364
|
+
const chunk = buffer.subarray(0, read2.bytesRead);
|
|
3125
3365
|
chunks.push(chunk);
|
|
3126
3366
|
const newline = chunk.lastIndexOf(10);
|
|
3127
3367
|
if (newline >= 0) lastNewline = total + newline;
|
|
@@ -3294,15 +3534,15 @@ var HostProducerDrainCore = class {
|
|
|
3294
3534
|
return run;
|
|
3295
3535
|
}
|
|
3296
3536
|
async drainLocked() {
|
|
3297
|
-
const
|
|
3537
|
+
const read2 = await this.host.listEnvelopes();
|
|
3298
3538
|
let removed = 0;
|
|
3299
3539
|
let expired = 0;
|
|
3300
|
-
for (const envelope of
|
|
3540
|
+
for (const envelope of read2.entries) {
|
|
3301
3541
|
if (Date.parse(this.host.expiresAtOf(envelope)) <= this.now().getTime()) expired += 1;
|
|
3302
3542
|
else removed += 1;
|
|
3303
3543
|
await this.host.removeEnvelope(envelope);
|
|
3304
3544
|
}
|
|
3305
|
-
return { removed, expired, malformed:
|
|
3545
|
+
return { removed, expired, malformed: read2.malformed };
|
|
3306
3546
|
}
|
|
3307
3547
|
};
|
|
3308
3548
|
|
|
@@ -3752,14 +3992,14 @@ var HostUsageFactsStore = class {
|
|
|
3752
3992
|
const gate = new Promise((resolve3) => {
|
|
3753
3993
|
release = resolve3;
|
|
3754
3994
|
});
|
|
3755
|
-
const
|
|
3756
|
-
SESSION_TRANSITION_TAILS.set(key,
|
|
3995
|
+
const tail2 = previous.then(() => gate);
|
|
3996
|
+
SESSION_TRANSITION_TAILS.set(key, tail2);
|
|
3757
3997
|
await previous;
|
|
3758
3998
|
try {
|
|
3759
3999
|
return await run();
|
|
3760
4000
|
} finally {
|
|
3761
4001
|
release?.();
|
|
3762
|
-
if (SESSION_TRANSITION_TAILS.get(key) ===
|
|
4002
|
+
if (SESSION_TRANSITION_TAILS.get(key) === tail2) SESSION_TRANSITION_TAILS.delete(key);
|
|
3763
4003
|
}
|
|
3764
4004
|
}
|
|
3765
4005
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
@@ -4020,29 +4260,46 @@ var HostUsageTranscriptSourceError = class extends Error {
|
|
|
4020
4260
|
this.name = "HostUsageTranscriptSourceError";
|
|
4021
4261
|
}
|
|
4022
4262
|
};
|
|
4023
|
-
async function readHostUsageTranscriptSource(
|
|
4263
|
+
async function readHostUsageTranscriptSource(read2) {
|
|
4024
4264
|
try {
|
|
4025
|
-
return await
|
|
4265
|
+
return await read2();
|
|
4026
4266
|
} catch (error) {
|
|
4027
4267
|
throw new HostUsageTranscriptSourceError({ cause: error });
|
|
4028
4268
|
}
|
|
4029
4269
|
}
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4270
|
+
var HostUsageRegistrationCapture = class {
|
|
4271
|
+
nextIndex = 0;
|
|
4272
|
+
producer;
|
|
4273
|
+
diagnosticSink;
|
|
4274
|
+
constructor(producer, diagnosticSink) {
|
|
4275
|
+
this.producer = producer;
|
|
4276
|
+
this.diagnosticSink = diagnosticSink;
|
|
4277
|
+
}
|
|
4278
|
+
async captureNext(registrations, capture) {
|
|
4279
|
+
let failed = false;
|
|
4280
|
+
let captured = false;
|
|
4281
|
+
const onFailure = () => {
|
|
4041
4282
|
failed = true;
|
|
4283
|
+
};
|
|
4284
|
+
for (let attempt = 0; attempt < registrations.length; attempt += 1) {
|
|
4285
|
+
const index = (this.nextIndex + attempt) % registrations.length;
|
|
4286
|
+
const registration = registrations[index];
|
|
4287
|
+
if (registration === void 0) continue;
|
|
4288
|
+
try {
|
|
4289
|
+
captured = await capture(registration, onFailure);
|
|
4290
|
+
if (captured) {
|
|
4291
|
+
this.nextIndex = (index + 1) % registrations.length;
|
|
4292
|
+
break;
|
|
4293
|
+
}
|
|
4294
|
+
} catch (error) {
|
|
4295
|
+
if (!(error instanceof HostUsageTranscriptSourceError)) throw error;
|
|
4296
|
+
onFailure();
|
|
4297
|
+
}
|
|
4042
4298
|
}
|
|
4299
|
+
if (failed) writeHostServiceDiagnostic(this.producer, "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
4300
|
+
return captured;
|
|
4043
4301
|
}
|
|
4044
|
-
|
|
4045
|
-
}
|
|
4302
|
+
};
|
|
4046
4303
|
async function openHostUsageTranscriptCursor(input) {
|
|
4047
4304
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants3.O_RDONLY));
|
|
4048
4305
|
let source;
|
|
@@ -4562,6 +4819,13 @@ var CodexOutboxStore = class {
|
|
|
4562
4819
|
await removeOwnerState(this.registrationPath(registration.host_source_ref, registration.host_session_ref), "registration");
|
|
4563
4820
|
await removeOwnerState(this.cursorPath(registration.host_source_ref, registration.host_session_ref), "cursor");
|
|
4564
4821
|
}
|
|
4822
|
+
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
4823
|
+
const path = this.registrationPath(hostSourceRef, hostSessionRef);
|
|
4824
|
+
await this.prepare();
|
|
4825
|
+
const registration = await readOptionalJson2(path, validateRegistration);
|
|
4826
|
+
if (registration !== null && (registration.host_source_ref !== hostSourceRef || registration.host_session_ref !== hostSessionRef)) throw storageError("Codex transcript registration identity does not match its session.");
|
|
4827
|
+
return registration;
|
|
4828
|
+
}
|
|
4565
4829
|
async listTranscriptRegistrations() {
|
|
4566
4830
|
await this.prepare();
|
|
4567
4831
|
const registrations = [];
|
|
@@ -4588,16 +4852,16 @@ var CodexOutboxStore = class {
|
|
|
4588
4852
|
}
|
|
4589
4853
|
async findByAlias(sourceRef, sessionRef, alias) {
|
|
4590
4854
|
if (!SAFE_REF3.test(sourceRef) || !SAFE_REF3.test(sessionRef) || !SAFE_REF3.test(alias)) return null;
|
|
4591
|
-
const
|
|
4592
|
-
const envelope = findEnvelopeByAlias(
|
|
4855
|
+
const read2 = await this.list();
|
|
4856
|
+
const envelope = findEnvelopeByAlias(read2.entries, sourceRef, sessionRef, alias);
|
|
4593
4857
|
if (envelope !== null) return envelopeMatch(envelope);
|
|
4594
4858
|
await this.prepare();
|
|
4595
4859
|
return null;
|
|
4596
4860
|
}
|
|
4597
4861
|
async hasPriorTurn(sourceRef, sessionRef) {
|
|
4598
4862
|
if (!SAFE_REF3.test(sourceRef) || !SAFE_REF3.test(sessionRef)) return false;
|
|
4599
|
-
const
|
|
4600
|
-
if (
|
|
4863
|
+
const read2 = await this.list();
|
|
4864
|
+
if (read2.entries.some((entry) => entry.identity.host_source_ref === sourceRef && entry.identity.host_session_ref === sessionRef)) return true;
|
|
4601
4865
|
return false;
|
|
4602
4866
|
}
|
|
4603
4867
|
entryPath(submissionRef) {
|
|
@@ -4653,7 +4917,7 @@ async function writeAtomicJson(path, value) {
|
|
|
4653
4917
|
if (text === void 0) throw storageError("Codex owner state cannot be serialized.");
|
|
4654
4918
|
const temp = `${path}.${process.pid}.${Math.random().toString(16).slice(2)}.tmp`;
|
|
4655
4919
|
try {
|
|
4656
|
-
const handle = await open4(temp, "wx");
|
|
4920
|
+
const handle = await open4(temp, "wx", 384);
|
|
4657
4921
|
try {
|
|
4658
4922
|
await handle.writeFile(text, "utf8");
|
|
4659
4923
|
await handle.sync();
|
|
@@ -4695,13 +4959,20 @@ async function readOptionalJson2(path, validate) {
|
|
|
4695
4959
|
}
|
|
4696
4960
|
async function ensureOwnerDirectory(path) {
|
|
4697
4961
|
try {
|
|
4698
|
-
|
|
4962
|
+
try {
|
|
4963
|
+
const stats2 = await stat2(path);
|
|
4964
|
+
if (!stats2.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
4965
|
+
return;
|
|
4966
|
+
} catch (error) {
|
|
4967
|
+
if (!isNotFound(error)) throw error;
|
|
4968
|
+
}
|
|
4969
|
+
await mkdir4(path, { recursive: true, mode: 448 });
|
|
4970
|
+
const stats = await stat2(path);
|
|
4971
|
+
if (!stats.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
4699
4972
|
} catch (error) {
|
|
4700
|
-
if (
|
|
4701
|
-
|
|
4973
|
+
if (error instanceof CodexHostAdapterError) throw error;
|
|
4974
|
+
throw storageError("Codex owner state directory is unavailable.");
|
|
4702
4975
|
}
|
|
4703
|
-
const stats = await stat2(path);
|
|
4704
|
-
if (!stats.isDirectory()) throw storageError("Codex owner state path is not a directory.");
|
|
4705
4976
|
}
|
|
4706
4977
|
async function readOwnerStateFile(path) {
|
|
4707
4978
|
let handle;
|
|
@@ -5111,9 +5382,9 @@ async function firstCompleteLine(handle, size) {
|
|
|
5111
5382
|
let total = 0;
|
|
5112
5383
|
while (position < size) {
|
|
5113
5384
|
const buffer = Buffer.alloc(Math.min(BASELINE_READ_CHUNK_BYTES, size - position));
|
|
5114
|
-
const
|
|
5115
|
-
if (
|
|
5116
|
-
const chunk = buffer.subarray(0,
|
|
5385
|
+
const read2 = await handle.read(buffer, 0, buffer.length, position);
|
|
5386
|
+
if (read2.bytesRead === 0) break;
|
|
5387
|
+
const chunk = buffer.subarray(0, read2.bytesRead);
|
|
5117
5388
|
const newline = chunk.indexOf(10);
|
|
5118
5389
|
if (newline >= 0) {
|
|
5119
5390
|
chunks.push(chunk.subarray(0, newline));
|
|
@@ -5130,8 +5401,8 @@ async function lastCompleteRecordOffset(handle, size) {
|
|
|
5130
5401
|
while (end > 0) {
|
|
5131
5402
|
const start = Math.max(0, end - BASELINE_READ_CHUNK_BYTES);
|
|
5132
5403
|
const buffer = Buffer.alloc(end - start);
|
|
5133
|
-
const
|
|
5134
|
-
const newline = buffer.subarray(0,
|
|
5404
|
+
const read2 = await handle.read(buffer, 0, buffer.length, start);
|
|
5405
|
+
const newline = buffer.subarray(0, read2.bytesRead).lastIndexOf(10);
|
|
5135
5406
|
if (newline >= 0) return start + newline + 1;
|
|
5136
5407
|
end = start;
|
|
5137
5408
|
}
|
|
@@ -5174,8 +5445,8 @@ async function* completeLinesBackward(handle, end) {
|
|
|
5174
5445
|
while (position > 0) {
|
|
5175
5446
|
const start = Math.max(0, position - BASELINE_READ_CHUNK_BYTES);
|
|
5176
5447
|
const buffer = Buffer.alloc(position - start);
|
|
5177
|
-
const
|
|
5178
|
-
if (
|
|
5448
|
+
const read2 = await handle.read(buffer, 0, buffer.length, start);
|
|
5449
|
+
if (read2.bytesRead !== buffer.length) throw new CodexHostAdapterError("storage", "Codex transcript changed size during baseline capture.");
|
|
5179
5450
|
let lineEnd = buffer.length;
|
|
5180
5451
|
for (let newline = buffer.lastIndexOf(10, lineEnd - 1); newline >= 0; newline = lineEnd > 0 ? buffer.lastIndexOf(10, lineEnd - 1) : -1) {
|
|
5181
5452
|
yield { start: start + newline + 1, bytes: Buffer.concat([buffer.subarray(newline + 1, lineEnd), ...carry]) };
|
|
@@ -5242,12 +5513,12 @@ async function registerSession(event, options, store, now, retentionMs) {
|
|
|
5242
5513
|
expires_at: expiresAt
|
|
5243
5514
|
};
|
|
5244
5515
|
const currentTurn = await selectCurrentTurn(event, options, store, hostSessionRef);
|
|
5245
|
-
const existing =
|
|
5246
|
-
if (existing ===
|
|
5516
|
+
const existing = await store.readTranscriptRegistration(registration.host_source_ref, registration.host_session_ref);
|
|
5517
|
+
if (existing === null) {
|
|
5247
5518
|
await store.writeTranscriptCursor(await captureCodexTranscriptBaseline(registration, now));
|
|
5248
5519
|
}
|
|
5249
5520
|
await store.registerTranscript(registration);
|
|
5250
|
-
if (existing !==
|
|
5521
|
+
if (existing !== null && currentTurn !== void 0 && (await store.readTranscriptCursor(registration))?.status === "quarantined") {
|
|
5251
5522
|
await store.writeTranscriptCursor(await captureCodexTranscriptBaseline(registration, now));
|
|
5252
5523
|
}
|
|
5253
5524
|
if (event.event === "SessionStart") {
|
|
@@ -5516,7 +5787,7 @@ function parseCanonicalJson(text, error) {
|
|
|
5516
5787
|
if (canonical !== text.trim()) throw new Error(`noncanonical: ${refusalFacts([{ name: "config_bytes", value: Buffer.byteLength(text.trim(), "utf8"), expected: `the ${Buffer.byteLength(canonical, "utf8")} bytes of its canonical form` }, { name: "first_difference_index", value: firstDifferenceIndex(text.trim(), canonical) }])}`);
|
|
5517
5788
|
return value;
|
|
5518
5789
|
} catch (parseError) {
|
|
5519
|
-
throw error("invalid_config",
|
|
5790
|
+
throw error("invalid_config", `parse_error=${renderOperatorDiagnostic(parseError)}; ${refusalFact("config_bytes", Buffer.byteLength(text, "utf8"), "canonical JSON")}`);
|
|
5520
5791
|
}
|
|
5521
5792
|
}
|
|
5522
5793
|
function firstDifferenceIndex(left, right) {
|
|
@@ -5957,20 +6228,16 @@ var CodexUsageFactsCapturer = class {
|
|
|
5957
6228
|
sources;
|
|
5958
6229
|
usage;
|
|
5959
6230
|
now;
|
|
5960
|
-
|
|
5961
|
-
nextRegistrationIndex = 0;
|
|
6231
|
+
registrations;
|
|
5962
6232
|
constructor(options) {
|
|
5963
6233
|
this.sources = new CodexOutboxStore(options.outbox_dir);
|
|
5964
6234
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
5965
6235
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
5966
|
-
this.
|
|
6236
|
+
this.registrations = new HostUsageRegistrationCapture("codex", options.diagnostic_sink);
|
|
5967
6237
|
}
|
|
5968
6238
|
async captureNext() {
|
|
5969
6239
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
5970
|
-
|
|
5971
|
-
this.nextRegistrationIndex = result.nextIndex;
|
|
5972
|
-
if (result.failed) writeHostServiceDiagnostic("codex", "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
5973
|
-
return result.captured;
|
|
6240
|
+
return await this.registrations.captureNext(registrations, (registration) => this.captureRegistration(registration));
|
|
5974
6241
|
}
|
|
5975
6242
|
async captureRegistration(registration) {
|
|
5976
6243
|
const prepared = await openHostUsageTranscriptCursor({
|