@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
|
@@ -88,7 +88,7 @@ var client_wire_contract_default = {
|
|
|
88
88
|
},
|
|
89
89
|
command_request: {
|
|
90
90
|
schema_name: "ceal.command_request",
|
|
91
|
-
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context"],
|
|
91
|
+
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context", "materialize_result"],
|
|
92
92
|
absolute_transport_max_bytes: 65536
|
|
93
93
|
},
|
|
94
94
|
command_resolution: {
|
|
@@ -134,7 +134,7 @@ var client_wire_contract_default = {
|
|
|
134
134
|
},
|
|
135
135
|
command_response: {
|
|
136
136
|
schema_name: "ceal.command_response",
|
|
137
|
-
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context"],
|
|
137
|
+
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context", "result_file"],
|
|
138
138
|
descriptor_field: "verified_artifact",
|
|
139
139
|
request_context_field: "request_context",
|
|
140
140
|
required_fields: [
|
|
@@ -147,7 +147,8 @@ var client_wire_contract_default = {
|
|
|
147
147
|
"visible_output_max_bytes",
|
|
148
148
|
"local_delivery",
|
|
149
149
|
"verified_artifact",
|
|
150
|
-
"request_context"
|
|
150
|
+
"request_context",
|
|
151
|
+
"result_file"
|
|
151
152
|
],
|
|
152
153
|
bare_document_fields: [
|
|
153
154
|
"invocation",
|
|
@@ -416,6 +417,9 @@ var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavaila
|
|
|
416
417
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
417
418
|
var CEAL_AUDIT_OUTCOMES = vocabulary(["succeeded", "denied", "failed"]);
|
|
418
419
|
var CEAL_GATEWAY_PROVIDER_STEP_OUTCOMES = vocabulary(["completed", "rejected", "throttled", "failed"]);
|
|
420
|
+
var CEAL_GATEWAY_CORPUS_READ_PROVIDERS = vocabulary(["slack", "google_drive", "notion"]);
|
|
421
|
+
var CEAL_GATEWAY_CORPUS_READ_OUTCOMES = vocabulary(["answered_from_corpus", "live_fallback"]);
|
|
422
|
+
var CEAL_GATEWAY_CORPUS_READ_FALLBACK_REASONS = vocabulary(["uncovered_window", "stale", "not_organization_public", "partition_missing"]);
|
|
419
423
|
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"]);
|
|
420
424
|
var CEAL_GATEWAY_READ_REUSE_UNAVAILABLE_REASONS = vocabulary(["not_reported", "storage_unavailable", "coverage_incomplete", "freshness_refresh_required", "not_reusable", "bypassed"]);
|
|
421
425
|
var CEAL_GATEWAY_DERIVED_STORE_FAILURE_CLASSES = vocabulary(["storage_unavailable", "decode_mismatch", "write_conflict", "quota", "store_error"]);
|
|
@@ -456,6 +460,21 @@ var CEAL_GATEWAY_ORGANIZATION_ROUTE_FACT_CALL_KEYS = Object.freeze([
|
|
|
456
460
|
]);
|
|
457
461
|
|
|
458
462
|
// packages/ceal-client-protocol/src/gateway-validation-primitives.ts
|
|
463
|
+
var POSIX_HOME_ROOTS = [["/", "home"].join(""), ["/", "Users"].join("")];
|
|
464
|
+
var WINDOWS_HOME_ROOT = ["C:", "\\", "Users"].join("");
|
|
465
|
+
var USER_SEGMENT_BODY = "[^/\\\\ \\t\\r\\n\"'`${}]+";
|
|
466
|
+
var POSIX_SEGMENT_END = "(?:/|$|(?=[\\s\"'`]))";
|
|
467
|
+
var WINDOWS_SEGMENT_END = "(?:\\\\+|$|(?=[\\s\"'`]))";
|
|
468
|
+
var WINDOWS_USER_SEGMENT_BODY = "[^\\\\ \\t\\r\\n\"'`${}]+";
|
|
469
|
+
var ABSOLUTE_PATH_BOUNDARY = "(?<![A-Za-z0-9_])";
|
|
470
|
+
function escapePathPattern(value) {
|
|
471
|
+
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
472
|
+
}
|
|
473
|
+
function machineHomePathPatterns(flags) {
|
|
474
|
+
const posix5 = `${ABSOLUTE_PATH_BOUNDARY}(?:${POSIX_HOME_ROOTS.map(escapePathPattern).join("|")})/${USER_SEGMENT_BODY}${POSIX_SEGMENT_END}`;
|
|
475
|
+
const windows = `${ABSOLUTE_PATH_BOUNDARY}${escapePathPattern(WINDOWS_HOME_ROOT)}\\\\+${WINDOWS_USER_SEGMENT_BODY}${WINDOWS_SEGMENT_END}`;
|
|
476
|
+
return [new RegExp(posix5, flags), new RegExp(windows, flags)];
|
|
477
|
+
}
|
|
459
478
|
var CealProtocolValidationError = class extends Error {
|
|
460
479
|
name = "CealProtocolValidationError";
|
|
461
480
|
code;
|
|
@@ -816,6 +835,7 @@ var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Rel
|
|
|
816
835
|
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.";
|
|
817
836
|
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.";
|
|
818
837
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
838
|
+
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
819
839
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
820
840
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
821
841
|
}
|
|
@@ -836,13 +856,18 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
836
856
|
context_not_selected: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
837
857
|
context_store_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
838
858
|
context_store_conflict: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
839
|
-
refresh_invalid: guidance(
|
|
840
|
-
refresh_expired: guidance(
|
|
841
|
-
refresh_replayed: guidance(
|
|
842
|
-
refresh_revoked: guidance(
|
|
843
|
-
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
844
|
-
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
845
|
-
|
|
859
|
+
refresh_invalid: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
860
|
+
refresh_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
861
|
+
refresh_replayed: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
862
|
+
refresh_revoked: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
863
|
+
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),
|
|
864
|
+
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),
|
|
865
|
+
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),
|
|
866
|
+
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
867
|
+
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),
|
|
868
|
+
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),
|
|
869
|
+
refresh_state_unavailable: guidance("The Gateway session state store is temporarily unavailable; retry the same refresh attempt when it is available.", "retry", 503, true),
|
|
870
|
+
refresh_recovery_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
846
871
|
refresh_custody_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
847
872
|
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),
|
|
848
873
|
local_output_exists: guidance("The selected local output path already exists; nothing was written to it.", "choose_new_output_path", 400),
|
|
@@ -857,10 +882,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
857
882
|
resource_stream_failed: guidance("The provider resource stream failed; ask an administrator to inspect the Gateway failure log.", "ask_admin", 500),
|
|
858
883
|
gateway_unavailable: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 503, true),
|
|
859
884
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
860
|
-
//
|
|
861
|
-
|
|
862
|
-
// when the wait ends still unserved, moved from the `localFailureText` default branch.
|
|
863
|
-
[CEAL_GATEWAY_STARTING_FAILURE_CODE]: guidance(LOCAL_TRANSPORT_INCOMPLETE, "answer_with_gap", 503, true),
|
|
885
|
+
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
886
|
+
[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),
|
|
864
887
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
865
888
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
866
889
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
@@ -872,6 +895,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
872
895
|
// The safe move varies by request. Keep the sentence conditional on the
|
|
873
896
|
// same `retryable` and `next_action` facts the response exposes.
|
|
874
897
|
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
898
|
+
// 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.
|
|
899
|
+
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),
|
|
875
900
|
// Restored verbatim from the retired `localFailureText`
|
|
876
901
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
877
902
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -1541,6 +1566,8 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1541
1566
|
"review_submitted",
|
|
1542
1567
|
"comment_created",
|
|
1543
1568
|
"reaction_created",
|
|
1569
|
+
"pull_request_merged",
|
|
1570
|
+
"release_published",
|
|
1544
1571
|
"ceal_write_completed",
|
|
1545
1572
|
"event_start",
|
|
1546
1573
|
"all_day_start",
|
|
@@ -1552,7 +1579,7 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1552
1579
|
"page_last_edited",
|
|
1553
1580
|
"resource_modified"
|
|
1554
1581
|
]);
|
|
1555
|
-
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "notion"]);
|
|
1582
|
+
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "google-mail", "notion"]);
|
|
1556
1583
|
var CEAL_ACTIVITY_UNSUPPORTED_EVENT_KIND_CODE = "unsupported_event_kind";
|
|
1557
1584
|
var CEAL_ACTIVITY_GAP_CODES = vocabulary([
|
|
1558
1585
|
"provider_page_budget",
|
|
@@ -1573,6 +1600,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1573
1600
|
"github.pull_request.opened",
|
|
1574
1601
|
"github.issue.edited",
|
|
1575
1602
|
"github.pull_request.edited",
|
|
1603
|
+
"github.pull_request.merged",
|
|
1604
|
+
"github.release.published",
|
|
1576
1605
|
"github.review.submitted",
|
|
1577
1606
|
"github.issue_comment.created",
|
|
1578
1607
|
"github.review_comment.created",
|
|
@@ -1586,6 +1615,7 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1586
1615
|
"drive.file.created",
|
|
1587
1616
|
"drive.file.modified",
|
|
1588
1617
|
"drive.file.viewed",
|
|
1618
|
+
"mail.sent",
|
|
1589
1619
|
"notion.page.created",
|
|
1590
1620
|
"notion.page.edited"
|
|
1591
1621
|
]);
|
|
@@ -1599,6 +1629,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1599
1629
|
"github.review_comment.created": "comment_created",
|
|
1600
1630
|
"github.issue.opened": "resource_created",
|
|
1601
1631
|
"github.pull_request.opened": "resource_created",
|
|
1632
|
+
"github.pull_request.merged": "pull_request_merged",
|
|
1633
|
+
"github.release.published": "release_published",
|
|
1602
1634
|
"github.issue.edited": "resource_modified",
|
|
1603
1635
|
"github.pull_request.edited": "resource_modified",
|
|
1604
1636
|
"github.reaction.created": "reaction_created",
|
|
@@ -1609,6 +1641,7 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1609
1641
|
"drive.file.created": "file_created",
|
|
1610
1642
|
"drive.file.modified": "file_modified_by_me",
|
|
1611
1643
|
"drive.file.viewed": "file_viewed_by_me",
|
|
1644
|
+
"mail.sent": "message_created",
|
|
1612
1645
|
"notion.page.created": "page_created",
|
|
1613
1646
|
"notion.page.edited": "page_last_edited"
|
|
1614
1647
|
});
|
|
@@ -1719,6 +1752,8 @@ var CEAL_REFRESH_FAILURE_CODES = vocabulary([
|
|
|
1719
1752
|
"principal_inactive",
|
|
1720
1753
|
"authority_replaced",
|
|
1721
1754
|
"refresh_recovery_unavailable",
|
|
1755
|
+
"refresh_recovery_outcome_unavailable",
|
|
1756
|
+
"refresh_state_unavailable",
|
|
1722
1757
|
"refresh_recovery_expired",
|
|
1723
1758
|
// The serving gate answers this while the Gateway is still starting and the
|
|
1724
1759
|
// refresh was never attempted; the same attempt stays retryable. It is never
|
|
@@ -2564,6 +2599,211 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
2564
2599
|
maximum: CEAL_PROTOCOL_VERSION
|
|
2565
2600
|
});
|
|
2566
2601
|
|
|
2602
|
+
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
2603
|
+
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
2604
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSES = 8;
|
|
2605
|
+
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
2606
|
+
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
2607
|
+
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
2608
|
+
var OPERATOR_DIAGNOSTIC_HOME_PATHS = machineHomePathPatterns("gu");
|
|
2609
|
+
function redactOperatorDiagnosticSecrets(value) {
|
|
2610
|
+
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]");
|
|
2611
|
+
}
|
|
2612
|
+
function redactOperatorDiagnosticText(value) {
|
|
2613
|
+
const normalized = normalizeCealSingleLineText(value);
|
|
2614
|
+
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
2615
|
+
}
|
|
2616
|
+
function renderOperatorDiagnostic(value) {
|
|
2617
|
+
const state = collectDiagnosticState(value);
|
|
2618
|
+
const fields = [
|
|
2619
|
+
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
2620
|
+
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
2621
|
+
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
2622
|
+
state.stderr === void 0 ? void 0 : `stderr_tail=${JSON.stringify(tail(state.stderr))}`,
|
|
2623
|
+
state.causes.length === 0 ? void 0 : `causes=${state.causes.map(formatCause).join(" <- ")}`
|
|
2624
|
+
].filter((field) => field !== void 0);
|
|
2625
|
+
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
2626
|
+
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
2627
|
+
}
|
|
2628
|
+
function collectDiagnosticState(value) {
|
|
2629
|
+
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0 };
|
|
2630
|
+
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
2631
|
+
while (pending.length > 0 && state.causes.length < OPERATOR_DIAGNOSTIC_MAX_CAUSES) {
|
|
2632
|
+
const current = pending.shift();
|
|
2633
|
+
if (current !== void 0) visitDiagnosticNode(current, state, pending, visited);
|
|
2634
|
+
}
|
|
2635
|
+
return state;
|
|
2636
|
+
}
|
|
2637
|
+
function visitDiagnosticNode(current, state, pending, visited) {
|
|
2638
|
+
if (isObject(current)) {
|
|
2639
|
+
if (visited.has(current)) return;
|
|
2640
|
+
visited.add(current);
|
|
2641
|
+
}
|
|
2642
|
+
captureProcessEvidence(current, state);
|
|
2643
|
+
appendCause(current, state.causes);
|
|
2644
|
+
enqueueCauseChildren(current, state.causes.length, pending);
|
|
2645
|
+
}
|
|
2646
|
+
function captureProcessEvidence(current, state) {
|
|
2647
|
+
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
2648
|
+
if (state.exitCode === void 0) state.exitCode = safeExitCode(read(current, "exitCode")) ?? safeExitCode(read(current, "status")) ?? safeExitCode(read(current, "code"));
|
|
2649
|
+
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
2650
|
+
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
2651
|
+
}
|
|
2652
|
+
function appendCause(current, causes) {
|
|
2653
|
+
const errors = read(current, "errors");
|
|
2654
|
+
if (current instanceof Error && (!(current instanceof AggregateError) || !Array.isArray(errors) || errors.length === 0)) {
|
|
2655
|
+
causes.push(errorCause(current));
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
if (!isObject(current)) {
|
|
2659
|
+
const message = safeText(current);
|
|
2660
|
+
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
function errorCause(error) {
|
|
2664
|
+
const name = safeText(read(error, "name")) ?? "Error";
|
|
2665
|
+
const message = safeText(read(error, "message"));
|
|
2666
|
+
const codeValue = read(error, "code");
|
|
2667
|
+
const code2 = typeof codeValue === "number" && Number.isFinite(codeValue) ? codeValue : safeText(codeValue);
|
|
2668
|
+
const errnoValue = read(error, "errno");
|
|
2669
|
+
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
2670
|
+
const syscall = safeText(read(error, "syscall"));
|
|
2671
|
+
const path = safePath(read(error, "path"));
|
|
2672
|
+
return Object.freeze({ error_class: name, ...message === void 0 ? {} : { message }, ...code2 === void 0 ? {} : { code: code2 }, ...errno === void 0 ? {} : { errno }, ...syscall === void 0 ? {} : { syscall }, ...path === void 0 ? {} : { path } });
|
|
2673
|
+
}
|
|
2674
|
+
function enqueueCauseChildren(current, causeCount, pending) {
|
|
2675
|
+
const cause = read(current, "cause");
|
|
2676
|
+
if (cause !== void 0) pending.push(cause);
|
|
2677
|
+
const errors = read(current, "errors");
|
|
2678
|
+
if (Array.isArray(errors)) pending.push(...errors.slice(0, OPERATOR_DIAGNOSTIC_MAX_CAUSES - causeCount));
|
|
2679
|
+
}
|
|
2680
|
+
function isObject(value) {
|
|
2681
|
+
return typeof value === "object" && value !== null;
|
|
2682
|
+
}
|
|
2683
|
+
function formatCause(cause) {
|
|
2684
|
+
const fields = [
|
|
2685
|
+
cause.error_class,
|
|
2686
|
+
cause.code === void 0 ? void 0 : `code=${JSON.stringify(safeDiagnosticText(cause.code))}`,
|
|
2687
|
+
cause.errno === void 0 ? void 0 : `errno=${cause.errno}`,
|
|
2688
|
+
cause.syscall === void 0 ? void 0 : `syscall=${JSON.stringify(cause.syscall)}`,
|
|
2689
|
+
cause.path === void 0 ? void 0 : `path=${JSON.stringify(cause.path)}`,
|
|
2690
|
+
cause.message === void 0 ? void 0 : `message=${cause.message}`
|
|
2691
|
+
].filter((field) => field !== void 0);
|
|
2692
|
+
return fields.join(" ");
|
|
2693
|
+
}
|
|
2694
|
+
function tail(value) {
|
|
2695
|
+
const clipped = value.length <= OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT ? value : `…${value.slice(-OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT)}`;
|
|
2696
|
+
return safeDiagnosticText(clipped);
|
|
2697
|
+
}
|
|
2698
|
+
function safeText(value) {
|
|
2699
|
+
if (typeof value !== "string") return void 0;
|
|
2700
|
+
const safe = safeDiagnosticText(value);
|
|
2701
|
+
if (safe.length === 0) return void 0;
|
|
2702
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT) return safe;
|
|
2703
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT / 2);
|
|
2704
|
+
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
2705
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2706
|
+
}
|
|
2707
|
+
function safePath(value) {
|
|
2708
|
+
if (typeof value !== "string") return void 0;
|
|
2709
|
+
const safe = safeDiagnosticText(value);
|
|
2710
|
+
if (safe.length === 0) return void 0;
|
|
2711
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
2712
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
2713
|
+
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
2714
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2715
|
+
}
|
|
2716
|
+
function safeDiagnosticText(value) {
|
|
2717
|
+
return redactOperatorDiagnosticText(String(value));
|
|
2718
|
+
}
|
|
2719
|
+
function outputText(value) {
|
|
2720
|
+
if (typeof value === "string") return redactOperatorDiagnosticText(value);
|
|
2721
|
+
if (value instanceof Uint8Array) {
|
|
2722
|
+
try {
|
|
2723
|
+
return redactOperatorDiagnosticText(new TextDecoder().decode(value));
|
|
2724
|
+
} catch {
|
|
2725
|
+
return void 0;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
return void 0;
|
|
2729
|
+
}
|
|
2730
|
+
function safeStatus(value) {
|
|
2731
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
2732
|
+
return typeof value === "string" ? safeText(value) : void 0;
|
|
2733
|
+
}
|
|
2734
|
+
function safeExitCode(value) {
|
|
2735
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
2736
|
+
}
|
|
2737
|
+
function read(value, key) {
|
|
2738
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) return void 0;
|
|
2739
|
+
try {
|
|
2740
|
+
return Reflect.get(value, key);
|
|
2741
|
+
} catch {
|
|
2742
|
+
return void 0;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
function redactHomePaths(value) {
|
|
2746
|
+
const paths = [
|
|
2747
|
+
...OPERATOR_DIAGNOSTIC_HOME_PATHS.flatMap((pattern) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, matchedHomePrefixLength(match[0])))),
|
|
2748
|
+
...configuredHomePathPatterns().flatMap(({ pattern, prefixLength }) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, prefixLength)))
|
|
2749
|
+
];
|
|
2750
|
+
paths.sort((left, right) => left.start - right.start || right.end - left.end);
|
|
2751
|
+
let output = "";
|
|
2752
|
+
let cursor = 0;
|
|
2753
|
+
for (const path of paths) {
|
|
2754
|
+
if (path.start < cursor) continue;
|
|
2755
|
+
output += `${value.slice(cursor, path.start)}[home path redacted]${value.slice(path.prefixEnd, path.end)}`;
|
|
2756
|
+
cursor = path.end;
|
|
2757
|
+
}
|
|
2758
|
+
return output + value.slice(cursor);
|
|
2759
|
+
}
|
|
2760
|
+
function configuredHomePathPatterns() {
|
|
2761
|
+
const homes = [...new Set([process.env.HOME, process.env.USERPROFILE].filter((home) => home !== void 0 && home.length > 0))];
|
|
2762
|
+
return homes.flatMap((home) => {
|
|
2763
|
+
const root = home.replace(/[\\/]+$/gu, "");
|
|
2764
|
+
if (root.length === 0 || root === "/" || /^[A-Za-z]:$/u.test(root)) return [];
|
|
2765
|
+
const pattern = new RegExp(`(?<![A-Za-z0-9_])${escapePathPattern(root)}(?=$|[\\\\/\\s"'\`<>(){}\\[\\],;])`, /^[A-Za-z]:[\\/]/u.test(root) ? "giu" : "gu");
|
|
2766
|
+
return [{ pattern, prefixLength: root.length }];
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
function matchedHomePrefixLength(value) {
|
|
2770
|
+
let separators = 0;
|
|
2771
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
2772
|
+
if (value[index] !== "/" && value[index] !== "\\") continue;
|
|
2773
|
+
separators += 1;
|
|
2774
|
+
if (separators === 3) return index;
|
|
2775
|
+
}
|
|
2776
|
+
return value.length;
|
|
2777
|
+
}
|
|
2778
|
+
function redactUrls(value) {
|
|
2779
|
+
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
2780
|
+
}
|
|
2781
|
+
function redactFilePaths(value) {
|
|
2782
|
+
return value.replaceAll(/(?<![A-Za-z0-9._-]|\[home path redacted\])(?:[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/)[^:\r\n"'<>]*?(?=:\d+(?::\d+)?(?:[:\s]|$)|[\r\n]|["'])/gu, "[path redacted]");
|
|
2783
|
+
}
|
|
2784
|
+
function homePathRange(value, match, prefixLength) {
|
|
2785
|
+
const index = match.index;
|
|
2786
|
+
if (index === void 0) return { start: value.length, end: value.length, prefixEnd: value.length };
|
|
2787
|
+
const start = index;
|
|
2788
|
+
let end = start + match[0].length;
|
|
2789
|
+
const quote = start > 0 && (value[start - 1] === "'" || value[start - 1] === '"') ? value[start - 1] : void 0;
|
|
2790
|
+
if (quote !== void 0) {
|
|
2791
|
+
const closing = value.indexOf(quote, end);
|
|
2792
|
+
if (closing >= 0) end = closing;
|
|
2793
|
+
}
|
|
2794
|
+
while (end < value.length && !/[\s"'`<>(){}[\],;]/u.test(value[end] ?? "")) end += 1;
|
|
2795
|
+
return { start, end, prefixEnd: Math.min(start + prefixLength, end) };
|
|
2796
|
+
}
|
|
2797
|
+
function truncateUtf8(value, maxBytes) {
|
|
2798
|
+
if (byteLength(value) <= maxBytes) return value;
|
|
2799
|
+
let output = "";
|
|
2800
|
+
for (const character of value) {
|
|
2801
|
+
if (byteLength(`${output}${character}…`) > maxBytes) break;
|
|
2802
|
+
output += character;
|
|
2803
|
+
}
|
|
2804
|
+
return `${output}…`;
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2567
2807
|
// packages/ceal-client-protocol/src/admin-projection-vocabulary.ts
|
|
2568
2808
|
var ADMIN_PROJECTION_STATES = vocabulary(["ready", "empty", "partial", "unknown"]);
|
|
2569
2809
|
var ADMIN_VIEW_KINDS = vocabulary(["request_detail", "resource_access_timeline", "weekly_usage"]);
|
|
@@ -2704,10 +2944,10 @@ function failureDetail(error) {
|
|
|
2704
2944
|
function errorCode(error) {
|
|
2705
2945
|
return typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : null;
|
|
2706
2946
|
}
|
|
2707
|
-
function hostClientProbe(result,
|
|
2947
|
+
function hostClientProbe(result, read2) {
|
|
2708
2948
|
if (result === null) return { kind: "unreachable" };
|
|
2709
2949
|
if (result.exit_code !== 0) return { kind: "refused", exit_code: result.exit_code };
|
|
2710
|
-
const value =
|
|
2950
|
+
const value = read2(result);
|
|
2711
2951
|
return value === null ? { kind: "unreadable" } : { kind: "value", value };
|
|
2712
2952
|
}
|
|
2713
2953
|
function hostClientProbeRefusal(probe, subject) {
|
|
@@ -3103,9 +3343,9 @@ function mergeHostInvocationHumanMessageWindow(existing, chronological) {
|
|
|
3103
3343
|
}
|
|
3104
3344
|
return boundCealHostInvocationHumanMessageWindow(newestFirst, existing?.truncated ?? false);
|
|
3105
3345
|
}
|
|
3106
|
-
async function readRegisteredHostInvocationHumanMessageWindow(
|
|
3346
|
+
async function readRegisteredHostInvocationHumanMessageWindow(readRegistration, readCursor, identity, decodeLine) {
|
|
3107
3347
|
try {
|
|
3108
|
-
const registration = await findLiveHostInvocationRegistration(
|
|
3348
|
+
const registration = await findLiveHostInvocationRegistration(readRegistration, identity);
|
|
3109
3349
|
const cursor = await readCursor(registration);
|
|
3110
3350
|
assertUsableHostInvocationHumanMessageCursor(cursor, registration);
|
|
3111
3351
|
return await readHostInvocationHumanMessageWindow(registration, cursor, (line) => decodeLine(line, registration, cursor));
|
|
@@ -3113,9 +3353,9 @@ async function readRegisteredHostInvocationHumanMessageWindow(listRegistrations,
|
|
|
3113
3353
|
throw new TypeError("context_unavailable");
|
|
3114
3354
|
}
|
|
3115
3355
|
}
|
|
3116
|
-
async function findLiveHostInvocationRegistration(
|
|
3117
|
-
const registration =
|
|
3118
|
-
if (registration ===
|
|
3356
|
+
async function findLiveHostInvocationRegistration(readRegistration, identity) {
|
|
3357
|
+
const registration = await readRegistration(identity);
|
|
3358
|
+
if (registration === null || registration.host_source_ref !== identity.host_source_ref || registration.host_session_ref !== identity.host_session_ref || !(Date.parse(registration.expires_at) > Date.now())) throw new TypeError("context_unavailable");
|
|
3119
3359
|
return registration;
|
|
3120
3360
|
}
|
|
3121
3361
|
function assertUsableHostInvocationHumanMessageCursor(cursor, registration) {
|
|
@@ -3182,9 +3422,9 @@ async function readTranscriptCompleteChunk(handle, offset, size) {
|
|
|
3182
3422
|
let lastNewline = -1;
|
|
3183
3423
|
while (position < size) {
|
|
3184
3424
|
const buffer = Buffer.alloc(Math.min(HOST_TRANSCRIPT_READ_CHUNK_BYTES, size - position));
|
|
3185
|
-
const
|
|
3186
|
-
if (
|
|
3187
|
-
const chunk = buffer.subarray(0,
|
|
3425
|
+
const read2 = await handle.read(buffer, 0, buffer.length, position);
|
|
3426
|
+
if (read2.bytesRead === 0) break;
|
|
3427
|
+
const chunk = buffer.subarray(0, read2.bytesRead);
|
|
3188
3428
|
chunks.push(chunk);
|
|
3189
3429
|
const newline = chunk.lastIndexOf(10);
|
|
3190
3430
|
if (newline >= 0) lastNewline = total + newline;
|
|
@@ -3357,15 +3597,15 @@ var HostProducerDrainCore = class {
|
|
|
3357
3597
|
return run;
|
|
3358
3598
|
}
|
|
3359
3599
|
async drainLocked() {
|
|
3360
|
-
const
|
|
3600
|
+
const read2 = await this.host.listEnvelopes();
|
|
3361
3601
|
let removed = 0;
|
|
3362
3602
|
let expired = 0;
|
|
3363
|
-
for (const envelope of
|
|
3603
|
+
for (const envelope of read2.entries) {
|
|
3364
3604
|
if (Date.parse(this.host.expiresAtOf(envelope)) <= this.now().getTime()) expired += 1;
|
|
3365
3605
|
else removed += 1;
|
|
3366
3606
|
await this.host.removeEnvelope(envelope);
|
|
3367
3607
|
}
|
|
3368
|
-
return { removed, expired, malformed:
|
|
3608
|
+
return { removed, expired, malformed: read2.malformed };
|
|
3369
3609
|
}
|
|
3370
3610
|
};
|
|
3371
3611
|
|
|
@@ -3815,14 +4055,14 @@ var HostUsageFactsStore = class {
|
|
|
3815
4055
|
const gate = new Promise((resolve) => {
|
|
3816
4056
|
release = resolve;
|
|
3817
4057
|
});
|
|
3818
|
-
const
|
|
3819
|
-
SESSION_TRANSITION_TAILS.set(key,
|
|
4058
|
+
const tail2 = previous.then(() => gate);
|
|
4059
|
+
SESSION_TRANSITION_TAILS.set(key, tail2);
|
|
3820
4060
|
await previous;
|
|
3821
4061
|
try {
|
|
3822
4062
|
return await run();
|
|
3823
4063
|
} finally {
|
|
3824
4064
|
release?.();
|
|
3825
|
-
if (SESSION_TRANSITION_TAILS.get(key) ===
|
|
4065
|
+
if (SESSION_TRANSITION_TAILS.get(key) === tail2) SESSION_TRANSITION_TAILS.delete(key);
|
|
3826
4066
|
}
|
|
3827
4067
|
}
|
|
3828
4068
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
@@ -4083,29 +4323,46 @@ var HostUsageTranscriptSourceError = class extends Error {
|
|
|
4083
4323
|
this.name = "HostUsageTranscriptSourceError";
|
|
4084
4324
|
}
|
|
4085
4325
|
};
|
|
4086
|
-
async function readHostUsageTranscriptSource(
|
|
4326
|
+
async function readHostUsageTranscriptSource(read2) {
|
|
4087
4327
|
try {
|
|
4088
|
-
return await
|
|
4328
|
+
return await read2();
|
|
4089
4329
|
} catch (error) {
|
|
4090
4330
|
throw new HostUsageTranscriptSourceError({ cause: error });
|
|
4091
4331
|
}
|
|
4092
4332
|
}
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4333
|
+
var HostUsageRegistrationCapture = class {
|
|
4334
|
+
nextIndex = 0;
|
|
4335
|
+
producer;
|
|
4336
|
+
diagnosticSink;
|
|
4337
|
+
constructor(producer, diagnosticSink) {
|
|
4338
|
+
this.producer = producer;
|
|
4339
|
+
this.diagnosticSink = diagnosticSink;
|
|
4340
|
+
}
|
|
4341
|
+
async captureNext(registrations, capture) {
|
|
4342
|
+
let failed = false;
|
|
4343
|
+
let captured = false;
|
|
4344
|
+
const onFailure = () => {
|
|
4104
4345
|
failed = true;
|
|
4346
|
+
};
|
|
4347
|
+
for (let attempt = 0; attempt < registrations.length; attempt += 1) {
|
|
4348
|
+
const index = (this.nextIndex + attempt) % registrations.length;
|
|
4349
|
+
const registration = registrations[index];
|
|
4350
|
+
if (registration === void 0) continue;
|
|
4351
|
+
try {
|
|
4352
|
+
captured = await capture(registration, onFailure);
|
|
4353
|
+
if (captured) {
|
|
4354
|
+
this.nextIndex = (index + 1) % registrations.length;
|
|
4355
|
+
break;
|
|
4356
|
+
}
|
|
4357
|
+
} catch (error) {
|
|
4358
|
+
if (!(error instanceof HostUsageTranscriptSourceError)) throw error;
|
|
4359
|
+
onFailure();
|
|
4360
|
+
}
|
|
4105
4361
|
}
|
|
4362
|
+
if (failed) writeHostServiceDiagnostic(this.producer, "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
4363
|
+
return captured;
|
|
4106
4364
|
}
|
|
4107
|
-
|
|
4108
|
-
}
|
|
4365
|
+
};
|
|
4109
4366
|
async function openHostUsageTranscriptCursor(input) {
|
|
4110
4367
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants3.O_RDONLY));
|
|
4111
4368
|
let source;
|
|
@@ -5361,7 +5618,7 @@ function parseCanonicalJson(text, error) {
|
|
|
5361
5618
|
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) }])}`);
|
|
5362
5619
|
return value;
|
|
5363
5620
|
} catch (parseError) {
|
|
5364
|
-
throw error("invalid_config",
|
|
5621
|
+
throw error("invalid_config", `parse_error=${renderOperatorDiagnostic(parseError)}; ${refusalFact("config_bytes", Buffer.byteLength(text, "utf8"), "canonical JSON")}`);
|
|
5365
5622
|
}
|
|
5366
5623
|
}
|
|
5367
5624
|
function firstDifferenceIndex(left, right) {
|
|
@@ -5776,6 +6033,13 @@ var ClaudeOutboxStore = class {
|
|
|
5776
6033
|
await this.removeStateFile(this.registrationPath(registration.host_source_ref, registration.host_session_ref));
|
|
5777
6034
|
await this.removeStateFile(this.cursorPath(registration.host_source_ref, registration.host_session_ref));
|
|
5778
6035
|
}
|
|
6036
|
+
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
6037
|
+
if (!SAFE_REF3.test(hostSourceRef) || !SAFE_REF3.test(hostSessionRef)) throw new ClaudeHostError("invalid_input", "Claude transcript session identity is invalid.");
|
|
6038
|
+
await this.prepare();
|
|
6039
|
+
const registration = await this.readRegistrationFile(this.registrationPath(hostSourceRef, hostSessionRef));
|
|
6040
|
+
if (registration !== null && (registration.host_source_ref !== hostSourceRef || registration.host_session_ref !== hostSessionRef)) throw new ClaudeHostError("storage", "Claude transcript registration identity does not match its session.");
|
|
6041
|
+
return registration;
|
|
6042
|
+
}
|
|
5779
6043
|
async listTranscriptRegistrations() {
|
|
5780
6044
|
await this.prepare();
|
|
5781
6045
|
const registrations = [];
|
|
@@ -6045,10 +6309,42 @@ var ClaudeProducer = class {
|
|
|
6045
6309
|
|
|
6046
6310
|
// host/claude/src/claude-transcript-watcher.ts
|
|
6047
6311
|
import { readdir as readdir2 } from "node:fs/promises";
|
|
6312
|
+
import { isDeepStrictEqual } from "node:util";
|
|
6048
6313
|
import { join as join6 } from "node:path";
|
|
6314
|
+
|
|
6315
|
+
// host/claude/src/claude-subagent-overflow-checkpoint.ts
|
|
6316
|
+
var ClaudeSubagentOverflowCheckpoint = class {
|
|
6317
|
+
observed = /* @__PURE__ */ new Map();
|
|
6318
|
+
prune(registrations) {
|
|
6319
|
+
const current = new Set(registrations.map(registrationKey));
|
|
6320
|
+
for (const key of this.observed.keys()) if (!current.has(key)) this.observed.delete(key);
|
|
6321
|
+
}
|
|
6322
|
+
clear(registration) {
|
|
6323
|
+
this.observed.delete(registrationKey(registration));
|
|
6324
|
+
}
|
|
6325
|
+
/** Names follow the producer's sorted inventory; only omitted names define overflow. */
|
|
6326
|
+
async observe(registration, names, report) {
|
|
6327
|
+
const key = registrationKey(registration);
|
|
6328
|
+
if (names.length <= CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES) {
|
|
6329
|
+
this.clear(registration);
|
|
6330
|
+
return false;
|
|
6331
|
+
}
|
|
6332
|
+
const digest2 = transcriptObjectSha256(names.slice(CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES));
|
|
6333
|
+
if (this.observed.get(key) === digest2) return false;
|
|
6334
|
+
if (!await report()) return false;
|
|
6335
|
+
this.observed.set(key, digest2);
|
|
6336
|
+
return true;
|
|
6337
|
+
}
|
|
6338
|
+
};
|
|
6339
|
+
function registrationKey(registration) {
|
|
6340
|
+
return JSON.stringify([registration.host_source_ref, registration.host_session_ref, registration.transcript_path]);
|
|
6341
|
+
}
|
|
6342
|
+
|
|
6343
|
+
// host/claude/src/claude-transcript-watcher.ts
|
|
6049
6344
|
var TOKEN_OBSERVATION_SOURCE = "claude_transcript.message.usage";
|
|
6050
6345
|
var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
6051
6346
|
store;
|
|
6347
|
+
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
6052
6348
|
diagnostic;
|
|
6053
6349
|
constructor(options) {
|
|
6054
6350
|
super(options, {
|
|
@@ -6063,7 +6359,9 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6063
6359
|
return registration.transcript_path;
|
|
6064
6360
|
}
|
|
6065
6361
|
async listRegistrations() {
|
|
6066
|
-
|
|
6362
|
+
const registrations = await this.store.listTranscriptRegistrations();
|
|
6363
|
+
this.overflow.prune(registrations);
|
|
6364
|
+
return registrations;
|
|
6067
6365
|
}
|
|
6068
6366
|
async scanOpened(handle, registration) {
|
|
6069
6367
|
const { size, device, inode } = await ownedClaudeTranscriptFile(handle);
|
|
@@ -6075,7 +6373,7 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6075
6373
|
}
|
|
6076
6374
|
if (preflight.checkpointPending) await this.store.writeTranscriptCursor({ ...cursor, updated_at: this.stamp() });
|
|
6077
6375
|
const draft = mutableCursor(cursor);
|
|
6078
|
-
await this.scanOpenedTranscript(registration, handle, draft, size, device, inode);
|
|
6376
|
+
await this.scanOpenedTranscript(registration, handle, cursor, draft, size, device, inode);
|
|
6079
6377
|
return { records: draft.consumed, enqueued: draft.enqueued, quarantined: false };
|
|
6080
6378
|
}
|
|
6081
6379
|
async scanFailed(handle, registration, error) {
|
|
@@ -6112,7 +6410,7 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6112
6410
|
updated_at: this.stamp()
|
|
6113
6411
|
};
|
|
6114
6412
|
}
|
|
6115
|
-
async scanOpenedTranscript(registration, handle, draft, size, device, inode) {
|
|
6413
|
+
async scanOpenedTranscript(registration, handle, previous, draft, size, device, inode) {
|
|
6116
6414
|
const main2 = await this.readChunk(handle, draft.offset, size);
|
|
6117
6415
|
if (main2 !== "empty" && main2 !== "partial") {
|
|
6118
6416
|
await this.consumeMainChunk(registration, main2, draft);
|
|
@@ -6120,7 +6418,7 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6120
6418
|
}
|
|
6121
6419
|
draft.consumed += await this.consumeSubagents(registration, draft);
|
|
6122
6420
|
await this.emitOpenTerminal(registration, draft);
|
|
6123
|
-
await this.commitCursor(registration, handle, draft, device, inode);
|
|
6421
|
+
await this.commitCursor(registration, handle, previous, draft, device, inode);
|
|
6124
6422
|
}
|
|
6125
6423
|
async preflight(registration, handle, size, device, inode) {
|
|
6126
6424
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
@@ -6280,15 +6578,24 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6280
6578
|
try {
|
|
6281
6579
|
names = (await readdir2(directory)).filter((name) => name.endsWith(".jsonl") && !name.endsWith(".meta.json")).sort();
|
|
6282
6580
|
} catch (error) {
|
|
6283
|
-
if (isMissingTranscriptError(error) || isNotDirectory(error))
|
|
6581
|
+
if (isMissingTranscriptError(error) || isNotDirectory(error)) {
|
|
6582
|
+
this.overflow.clear(registration);
|
|
6583
|
+
return 0;
|
|
6584
|
+
}
|
|
6284
6585
|
throw new ClaudeHostError("payload_rejected", "Claude subagent transcript directory is unavailable.");
|
|
6285
6586
|
}
|
|
6286
6587
|
const listed = new Set(names);
|
|
6287
6588
|
for (const name of Object.keys(draft.subagents)) if (!listed.has(name)) delete draft.subagents[name];
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6589
|
+
await this.overflow.observe(registration, names, () => {
|
|
6590
|
+
const line = `Claude ignored subagent transcripts past its file bound: transcript_path=${JSON.stringify(registration.transcript_path)}, files=${names.length}.`;
|
|
6591
|
+
try {
|
|
6592
|
+
this.log(line);
|
|
6593
|
+
} catch {
|
|
6594
|
+
return false;
|
|
6595
|
+
}
|
|
6596
|
+
return true;
|
|
6597
|
+
});
|
|
6598
|
+
names = names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES);
|
|
6292
6599
|
let consumed = 0;
|
|
6293
6600
|
for (const name of names) {
|
|
6294
6601
|
consumed += await this.consumeSubagentFile(draft, directory, name);
|
|
@@ -6377,9 +6684,9 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6377
6684
|
expires_at: this.expire(this.outboxRetentionMs)
|
|
6378
6685
|
});
|
|
6379
6686
|
}
|
|
6380
|
-
async commitCursor(registration, handle, draft, device, inode) {
|
|
6687
|
+
async commitCursor(registration, handle, previous, draft, device, inode) {
|
|
6381
6688
|
const anchor = await this.readAnchor(handle, draft.offset, CLAUDE_TRANSCRIPT_ANCHOR_BYTES);
|
|
6382
|
-
|
|
6689
|
+
const cursor = {
|
|
6383
6690
|
schema_version: CLAUDE_TRANSCRIPT_CURSOR_SCHEMA_VERSION,
|
|
6384
6691
|
host_source_ref: registration.host_source_ref,
|
|
6385
6692
|
host_session_ref: registration.host_session_ref,
|
|
@@ -6396,7 +6703,9 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
6396
6703
|
...draft.session_observed ? { session_observed: true } : {},
|
|
6397
6704
|
status: "active",
|
|
6398
6705
|
updated_at: this.stamp()
|
|
6399
|
-
}
|
|
6706
|
+
};
|
|
6707
|
+
if (sameCursorContent(cursor, previous)) return;
|
|
6708
|
+
await this.store.writeTranscriptCursor(cursor);
|
|
6400
6709
|
}
|
|
6401
6710
|
async activateContext(identity, promptRef, turnGenerationRef, expiresAt) {
|
|
6402
6711
|
try {
|
|
@@ -6447,6 +6756,9 @@ function mutableCursor(cursor) {
|
|
|
6447
6756
|
enqueued: 0
|
|
6448
6757
|
};
|
|
6449
6758
|
}
|
|
6759
|
+
function sameCursorContent(left, right) {
|
|
6760
|
+
return isDeepStrictEqual({ ...left, updated_at: void 0 }, { ...right, updated_at: void 0 });
|
|
6761
|
+
}
|
|
6450
6762
|
function zeroCounts() {
|
|
6451
6763
|
return { input: 0, cached_input: 0, cache_write_input: 0, output: 0 };
|
|
6452
6764
|
}
|
|
@@ -6577,11 +6889,14 @@ function isSymlinkTranscript(error) {
|
|
|
6577
6889
|
}
|
|
6578
6890
|
|
|
6579
6891
|
// host/claude/src/claude-producer-runtime.ts
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
outbox_dir:
|
|
6892
|
+
function createClaudeProducerWatcher(outboxDir) {
|
|
6893
|
+
return new ClaudeTranscriptWatcher({
|
|
6894
|
+
outbox_dir: outboxDir,
|
|
6583
6895
|
diagnostic: (event, failure_kind, cause) => writeHostServiceDiagnostic("claude", event, failure_kind, cause)
|
|
6584
|
-
})
|
|
6896
|
+
});
|
|
6897
|
+
}
|
|
6898
|
+
async function drainClaudeProducerOnce(options) {
|
|
6899
|
+
const scan = await (options.watcher ?? createClaudeProducerWatcher(options.outbox_dir)).scanOnce().catch((error) => {
|
|
6585
6900
|
writeHostServiceDiagnostic("claude", "watcher_scan_failed", claudeTranscriptScanFailureKind(error), claudeTranscriptScanCause(void 0, error));
|
|
6586
6901
|
throw error;
|
|
6587
6902
|
});
|
|
@@ -6598,25 +6913,20 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
6598
6913
|
sources;
|
|
6599
6914
|
usage;
|
|
6600
6915
|
now;
|
|
6601
|
-
|
|
6602
|
-
nextRegistrationIndex = 0;
|
|
6916
|
+
registrations;
|
|
6603
6917
|
nextSourceSlot = "main";
|
|
6604
6918
|
nextSubagentIndex = 0;
|
|
6919
|
+
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
6605
6920
|
constructor(options) {
|
|
6606
6921
|
this.sources = new ClaudeOutboxStore(options.outbox_dir);
|
|
6607
6922
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
6608
6923
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
6609
|
-
this.
|
|
6924
|
+
this.registrations = new HostUsageRegistrationCapture("claude", options.diagnostic_sink);
|
|
6610
6925
|
}
|
|
6611
6926
|
async captureNext() {
|
|
6612
6927
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
failed = true;
|
|
6616
|
-
}));
|
|
6617
|
-
this.nextRegistrationIndex = result.nextIndex;
|
|
6618
|
-
if (failed || result.failed) writeHostServiceDiagnostic("claude", "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
6619
|
-
return result.captured;
|
|
6928
|
+
this.overflow.prune(registrations);
|
|
6929
|
+
return await this.registrations.captureNext(registrations, (registration, onFailure) => this.captureRegistration(registration, onFailure));
|
|
6620
6930
|
}
|
|
6621
6931
|
async captureRegistration(registration, onFailure) {
|
|
6622
6932
|
const sources = this.nextSourceSlot === "main" ? ["main", "subagent"] : ["subagent", "main"];
|
|
@@ -6663,13 +6973,14 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
6663
6973
|
}
|
|
6664
6974
|
async captureSubagent(registration, onFailure) {
|
|
6665
6975
|
const names = await readSubagentNames(registration);
|
|
6976
|
+
if (names.length <= CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES) this.overflow.clear(registration);
|
|
6666
6977
|
let state = await this.usage.readState("claude", registration.host_source_ref, registration.host_session_ref);
|
|
6667
6978
|
if (state === null) return false;
|
|
6668
6979
|
state = await this.usage.recoverPending(state);
|
|
6669
6980
|
if (state.quarantined_reason !== void 0) return false;
|
|
6670
6981
|
if (await this.retireMissingSubagent(state, names)) return true;
|
|
6671
6982
|
if (await this.captureListedSubagents(registration, names, state, onFailure)) return true;
|
|
6672
|
-
return await this.recordExcessSubagentGap(state, names);
|
|
6983
|
+
return await this.recordExcessSubagentGap(registration, state, names);
|
|
6673
6984
|
}
|
|
6674
6985
|
async retireMissingSubagent(state, names) {
|
|
6675
6986
|
const liveSlots = new Set(names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES).map(subagentSlot));
|
|
@@ -6680,14 +6991,14 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
6680
6991
|
}
|
|
6681
6992
|
return false;
|
|
6682
6993
|
}
|
|
6683
|
-
async recordExcessSubagentGap(state, names) {
|
|
6684
|
-
const excessCount = names.length - CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES;
|
|
6685
|
-
if (excessCount <= 0) return false;
|
|
6994
|
+
async recordExcessSubagentGap(registration, state, names) {
|
|
6686
6995
|
const mainCursor = state.cursors.main;
|
|
6687
6996
|
if (mainCursor === void 0) return false;
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6997
|
+
return await this.overflow.observe(registration, names, async () => {
|
|
6998
|
+
const gap = { reason: "unsupported_source_shape", source_file_ref: null, start_offset: null, end_offset: null, omitted_count: names.length - CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES };
|
|
6999
|
+
await this.usage.commitScanTransition(state, "main", mainCursor, mainCursor, null, [gap]);
|
|
7000
|
+
return true;
|
|
7001
|
+
});
|
|
6691
7002
|
}
|
|
6692
7003
|
async captureListedSubagents(registration, names, state, onFailure) {
|
|
6693
7004
|
const candidates = names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES);
|
|
@@ -6968,7 +7279,7 @@ var CLAUDE_PRODUCER_DESCRIPTOR = {
|
|
|
6968
7279
|
producer_id: "claude",
|
|
6969
7280
|
extra_paths: [CLAUDE_TRANSCRIPTS_ROOT],
|
|
6970
7281
|
config: (shared, extras) => ({ ...shared, claude_transcripts_root: hostProducerExtraPath(extras, CLAUDE_TRANSCRIPTS_ROOT) }),
|
|
6971
|
-
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir }),
|
|
7282
|
+
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir, watcher: createClaudeProducerWatcher(config.outbox_dir) }),
|
|
6972
7283
|
drain: drainClaudeProducerOnce,
|
|
6973
7284
|
background: (config, signal, dependencies) => {
|
|
6974
7285
|
const capturer = new ClaudeUsageFactsCapturer({ outbox_dir: config.outbox_dir });
|
|
@@ -7042,7 +7353,7 @@ function runClaudeInvocationAuthenticationCommand(args, options) {
|
|
|
7042
7353
|
return runHostInvocationAuthenticationCommand(CLAUDE_INVOCATION_AUTHENTICATION_DESCRIPTOR, args, options);
|
|
7043
7354
|
}
|
|
7044
7355
|
async function readClaudeInvocationHumanMessageWindow(input) {
|
|
7045
|
-
return readRegisteredHostInvocationHumanMessageWindow(() => input.store.
|
|
7356
|
+
return readRegisteredHostInvocationHumanMessageWindow((identity) => input.store.readTranscriptRegistration(identity.host_source_ref, identity.host_session_ref), (registration) => input.store.readTranscriptCursor(registration), input.identity, (line, registration) => {
|
|
7046
7357
|
let row;
|
|
7047
7358
|
try {
|
|
7048
7359
|
row = JSON.parse(line);
|
|
@@ -7180,7 +7491,7 @@ async function inspectExecutable(options, environment, component) {
|
|
|
7180
7491
|
try {
|
|
7181
7492
|
executable = await (options.resolve_executable ?? resolveCealExecutable)(options.executable ?? "ceal", environment);
|
|
7182
7493
|
} catch (error) {
|
|
7183
|
-
return inspectedFailure("ceal_unavailable", `The ${component} Host cannot resolve an executable Ceal client from its current environment (${
|
|
7494
|
+
return inspectedFailure("ceal_unavailable", `The ${component} Host cannot resolve an executable Ceal client from its current environment (${renderOperatorDiagnostic(error)}).`, `Install the intended Ceal client in the Host PATH, restart ${component}, and run this doctor again.`);
|
|
7184
7495
|
}
|
|
7185
7496
|
if (!validExpectations(options) || options.expected_sha256 !== void 0 && executable.sha256 !== options.expected_sha256) return inspectedFailure("ceal_identity_mismatch", `The Ceal executable visible to the ${component} Host does not match the intended candidate.`, `Install the exact candidate bytes, restart ${component}, and run this doctor with the expected identity.`);
|
|
7186
7497
|
return { ok: true, value: executable };
|