@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
|
@@ -139,7 +139,7 @@ var client_wire_contract_default = {
|
|
|
139
139
|
},
|
|
140
140
|
command_request: {
|
|
141
141
|
schema_name: "ceal.command_request",
|
|
142
|
-
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context"],
|
|
142
|
+
fields: ["schema_version", "argv", "operation", "client_nonce", "context_token", "request_context", "materialize_result"],
|
|
143
143
|
absolute_transport_max_bytes: 65536
|
|
144
144
|
},
|
|
145
145
|
command_resolution: {
|
|
@@ -185,7 +185,7 @@ var client_wire_contract_default = {
|
|
|
185
185
|
},
|
|
186
186
|
command_response: {
|
|
187
187
|
schema_name: "ceal.command_response",
|
|
188
|
-
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context"],
|
|
188
|
+
fields: ["schema_version", "exit_code", "document", "operation_id", "visible_output_max_bytes", "local_delivery", "verified_artifact", "request_context", "result_file"],
|
|
189
189
|
descriptor_field: "verified_artifact",
|
|
190
190
|
request_context_field: "request_context",
|
|
191
191
|
required_fields: [
|
|
@@ -198,7 +198,8 @@ var client_wire_contract_default = {
|
|
|
198
198
|
"visible_output_max_bytes",
|
|
199
199
|
"local_delivery",
|
|
200
200
|
"verified_artifact",
|
|
201
|
-
"request_context"
|
|
201
|
+
"request_context",
|
|
202
|
+
"result_file"
|
|
202
203
|
],
|
|
203
204
|
bare_document_fields: [
|
|
204
205
|
"invocation",
|
|
@@ -467,6 +468,9 @@ var CEAL_OPERATION_READINESS_VALUES = vocabulary(["ready", "degraded", "unavaila
|
|
|
467
468
|
var CEAL_TARGET_REQUIREMENTS = vocabulary(["required", "optional", "none"]);
|
|
468
469
|
var CEAL_AUDIT_OUTCOMES = vocabulary(["succeeded", "denied", "failed"]);
|
|
469
470
|
var CEAL_GATEWAY_PROVIDER_STEP_OUTCOMES = vocabulary(["completed", "rejected", "throttled", "failed"]);
|
|
471
|
+
var CEAL_GATEWAY_CORPUS_READ_PROVIDERS = vocabulary(["slack", "google_drive", "notion"]);
|
|
472
|
+
var CEAL_GATEWAY_CORPUS_READ_OUTCOMES = vocabulary(["answered_from_corpus", "live_fallback"]);
|
|
473
|
+
var CEAL_GATEWAY_CORPUS_READ_FALLBACK_REASONS = vocabulary(["uncovered_window", "stale", "not_organization_public", "partition_missing"]);
|
|
470
474
|
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"]);
|
|
471
475
|
var CEAL_GATEWAY_READ_REUSE_UNAVAILABLE_REASONS = vocabulary(["not_reported", "storage_unavailable", "coverage_incomplete", "freshness_refresh_required", "not_reusable", "bypassed"]);
|
|
472
476
|
var CEAL_GATEWAY_DERIVED_STORE_FAILURE_CLASSES = vocabulary(["storage_unavailable", "decode_mismatch", "write_conflict", "quota", "store_error"]);
|
|
@@ -507,6 +511,21 @@ var CEAL_GATEWAY_ORGANIZATION_ROUTE_FACT_CALL_KEYS = Object.freeze([
|
|
|
507
511
|
]);
|
|
508
512
|
|
|
509
513
|
// packages/ceal-client-protocol/src/gateway-validation-primitives.ts
|
|
514
|
+
var POSIX_HOME_ROOTS = [["/", "home"].join(""), ["/", "Users"].join("")];
|
|
515
|
+
var WINDOWS_HOME_ROOT = ["C:", "\\", "Users"].join("");
|
|
516
|
+
var USER_SEGMENT_BODY = "[^/\\\\ \\t\\r\\n\"'`${}]+";
|
|
517
|
+
var POSIX_SEGMENT_END = "(?:/|$|(?=[\\s\"'`]))";
|
|
518
|
+
var WINDOWS_SEGMENT_END = "(?:\\\\+|$|(?=[\\s\"'`]))";
|
|
519
|
+
var WINDOWS_USER_SEGMENT_BODY = "[^\\\\ \\t\\r\\n\"'`${}]+";
|
|
520
|
+
var ABSOLUTE_PATH_BOUNDARY = "(?<![A-Za-z0-9_])";
|
|
521
|
+
function escapePathPattern(value) {
|
|
522
|
+
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
523
|
+
}
|
|
524
|
+
function machineHomePathPatterns(flags) {
|
|
525
|
+
const posix5 = `${ABSOLUTE_PATH_BOUNDARY}(?:${POSIX_HOME_ROOTS.map(escapePathPattern).join("|")})/${USER_SEGMENT_BODY}${POSIX_SEGMENT_END}`;
|
|
526
|
+
const windows = `${ABSOLUTE_PATH_BOUNDARY}${escapePathPattern(WINDOWS_HOME_ROOT)}\\\\+${WINDOWS_USER_SEGMENT_BODY}${WINDOWS_SEGMENT_END}`;
|
|
527
|
+
return [new RegExp(posix5, flags), new RegExp(windows, flags)];
|
|
528
|
+
}
|
|
510
529
|
var CealProtocolValidationError = class extends Error {
|
|
511
530
|
name = "CealProtocolValidationError";
|
|
512
531
|
code;
|
|
@@ -862,6 +881,7 @@ var CLIENT_HOST_RELEASE_MISMATCH = "Install or upgrade the Ceal CLI and Host Rel
|
|
|
862
881
|
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.";
|
|
863
882
|
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.";
|
|
864
883
|
var SESSION_CONTEXT_UNAVAILABLE = "The local Gateway session context is unavailable.";
|
|
884
|
+
var SESSION_ADOPT_RECOVERY = "The refresh Session is no longer usable. Run `ceal session adopt --gateway <origin> --email <email>` to complete mailbox-confirmed recovery.";
|
|
865
885
|
function guidance(message, next_action, http_status, retryable = false, redaction_class = "model_safe") {
|
|
866
886
|
return Object.freeze({ message, next_action, http_status, retryable, redaction_class });
|
|
867
887
|
}
|
|
@@ -882,13 +902,18 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
882
902
|
context_not_selected: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
883
903
|
context_store_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
884
904
|
context_store_conflict: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
885
|
-
refresh_invalid: guidance(
|
|
886
|
-
refresh_expired: guidance(
|
|
887
|
-
refresh_replayed: guidance(
|
|
888
|
-
refresh_revoked: guidance(
|
|
889
|
-
person_inactive: guidance("The Person is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
890
|
-
principal_inactive: guidance("The Principal is inactive, so the Gateway refused this refresh without revoking the Session family.", "ask_admin", 403),
|
|
891
|
-
|
|
905
|
+
refresh_invalid: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
906
|
+
refresh_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
907
|
+
refresh_replayed: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
908
|
+
refresh_revoked: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 401),
|
|
909
|
+
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),
|
|
910
|
+
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),
|
|
911
|
+
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),
|
|
912
|
+
refresh_inactive: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
913
|
+
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),
|
|
914
|
+
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),
|
|
915
|
+
refresh_state_unavailable: guidance("The Gateway session state store is temporarily unavailable; retry the same refresh attempt when it is available.", "retry", 503, true),
|
|
916
|
+
refresh_recovery_expired: guidance(SESSION_ADOPT_RECOVERY, "repair_or_adopt_session", 410),
|
|
892
917
|
refresh_custody_invalid: guidance(SESSION_CONTEXT_UNAVAILABLE, "repair_or_adopt_session", 401),
|
|
893
918
|
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),
|
|
894
919
|
local_output_exists: guidance("The selected local output path already exists; nothing was written to it.", "choose_new_output_path", 400),
|
|
@@ -903,10 +928,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
903
928
|
resource_stream_failed: guidance("The provider resource stream failed; ask an administrator to inspect the Gateway failure log.", "ask_admin", 500),
|
|
904
929
|
gateway_unavailable: guidance(GATEWAY_TRANSPORT_UNAVAILABLE, "ask_admin", 503, true),
|
|
905
930
|
contract_mismatch: guidance(CLIENT_HOST_RELEASE_MISMATCH, "upgrade_ceal_client", 409),
|
|
906
|
-
//
|
|
907
|
-
|
|
908
|
-
// when the wait ends still unserved, moved from the `localFailureText` default branch.
|
|
909
|
-
[CEAL_GATEWAY_STARTING_FAILURE_CODE]: guidance(LOCAL_TRANSPORT_INCOMPLETE, "answer_with_gap", 503, true),
|
|
931
|
+
// The serving gate answers before refresh execution, so retrying the same attempt is safe.
|
|
932
|
+
[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),
|
|
910
933
|
gateway_internal_error: guidance("The Gateway failed without exposing internal state; report this as a gap.", "answer_with_gap", 500),
|
|
911
934
|
// The serving gate emits this code with no message; the sentence is the owner-normalized form of the
|
|
912
935
|
// `gateway_internal_error` guidance (decided with the operator 2026-10-13).
|
|
@@ -918,6 +941,8 @@ var CEAL_FAILURE_GUIDANCE_TABLE = Object.freeze({
|
|
|
918
941
|
// The safe move varies by request. Keep the sentence conditional on the
|
|
919
942
|
// same `retryable` and `next_action` facts the response exposes.
|
|
920
943
|
unknown_outcome: guidance("The transport outcome is unknown; use retryable and next_action to decide whether it can be repeated.", "answer_with_gap", 500),
|
|
944
|
+
// 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.
|
|
945
|
+
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),
|
|
921
946
|
// Restored verbatim from the retired `localFailureText`
|
|
922
947
|
// `refresh_unknown_outcome` case: a refresh that ends unknown leaves the
|
|
923
948
|
// session context unavailable, so the caller repairs or adopts the
|
|
@@ -1567,6 +1592,8 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1567
1592
|
"review_submitted",
|
|
1568
1593
|
"comment_created",
|
|
1569
1594
|
"reaction_created",
|
|
1595
|
+
"pull_request_merged",
|
|
1596
|
+
"release_published",
|
|
1570
1597
|
"ceal_write_completed",
|
|
1571
1598
|
"event_start",
|
|
1572
1599
|
"all_day_start",
|
|
@@ -1578,7 +1605,7 @@ var CEAL_ACTIVITY_TIMESTAMP_BASES = vocabulary([
|
|
|
1578
1605
|
"page_last_edited",
|
|
1579
1606
|
"resource_modified"
|
|
1580
1607
|
]);
|
|
1581
|
-
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "notion"]);
|
|
1608
|
+
var CEAL_ACTIVITY_CONNECTOR_KINDS = vocabulary(["slack", "github", "google-calendar", "google-drive", "google-mail", "notion"]);
|
|
1582
1609
|
var CEAL_ACTIVITY_UNSUPPORTED_EVENT_KIND_CODE = "unsupported_event_kind";
|
|
1583
1610
|
var CEAL_ACTIVITY_GAP_CODES = vocabulary([
|
|
1584
1611
|
"provider_page_budget",
|
|
@@ -1599,6 +1626,8 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1599
1626
|
"github.pull_request.opened",
|
|
1600
1627
|
"github.issue.edited",
|
|
1601
1628
|
"github.pull_request.edited",
|
|
1629
|
+
"github.pull_request.merged",
|
|
1630
|
+
"github.release.published",
|
|
1602
1631
|
"github.review.submitted",
|
|
1603
1632
|
"github.issue_comment.created",
|
|
1604
1633
|
"github.review_comment.created",
|
|
@@ -1612,6 +1641,7 @@ var CEAL_ACTIVITY_EVENT_KINDS = vocabulary([
|
|
|
1612
1641
|
"drive.file.created",
|
|
1613
1642
|
"drive.file.modified",
|
|
1614
1643
|
"drive.file.viewed",
|
|
1644
|
+
"mail.sent",
|
|
1615
1645
|
"notion.page.created",
|
|
1616
1646
|
"notion.page.edited"
|
|
1617
1647
|
]);
|
|
@@ -1625,6 +1655,8 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1625
1655
|
"github.review_comment.created": "comment_created",
|
|
1626
1656
|
"github.issue.opened": "resource_created",
|
|
1627
1657
|
"github.pull_request.opened": "resource_created",
|
|
1658
|
+
"github.pull_request.merged": "pull_request_merged",
|
|
1659
|
+
"github.release.published": "release_published",
|
|
1628
1660
|
"github.issue.edited": "resource_modified",
|
|
1629
1661
|
"github.pull_request.edited": "resource_modified",
|
|
1630
1662
|
"github.reaction.created": "reaction_created",
|
|
@@ -1635,6 +1667,7 @@ var CEAL_ACTIVITY_EVENT_TIMESTAMP_BASIS_MAP = Object.freeze({
|
|
|
1635
1667
|
"drive.file.created": "file_created",
|
|
1636
1668
|
"drive.file.modified": "file_modified_by_me",
|
|
1637
1669
|
"drive.file.viewed": "file_viewed_by_me",
|
|
1670
|
+
"mail.sent": "message_created",
|
|
1638
1671
|
"notion.page.created": "page_created",
|
|
1639
1672
|
"notion.page.edited": "page_last_edited"
|
|
1640
1673
|
});
|
|
@@ -1745,6 +1778,8 @@ var CEAL_REFRESH_FAILURE_CODES = vocabulary([
|
|
|
1745
1778
|
"principal_inactive",
|
|
1746
1779
|
"authority_replaced",
|
|
1747
1780
|
"refresh_recovery_unavailable",
|
|
1781
|
+
"refresh_recovery_outcome_unavailable",
|
|
1782
|
+
"refresh_state_unavailable",
|
|
1748
1783
|
"refresh_recovery_expired",
|
|
1749
1784
|
// The serving gate answers this while the Gateway is still starting and the
|
|
1750
1785
|
// refresh was never attempted; the same attempt stays retryable. It is never
|
|
@@ -2503,6 +2538,211 @@ var CEAL_SUPPORTED_GATEWAY_PROTOCOL_RANGE = Object.freeze({
|
|
|
2503
2538
|
maximum: CEAL_PROTOCOL_VERSION
|
|
2504
2539
|
});
|
|
2505
2540
|
|
|
2541
|
+
// packages/ceal-client-protocol/src/operator-diagnostic.ts
|
|
2542
|
+
var OPERATOR_DIAGNOSTIC_MAX_BYTES = 2048;
|
|
2543
|
+
var OPERATOR_DIAGNOSTIC_MAX_CAUSES = 8;
|
|
2544
|
+
var OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT = 512;
|
|
2545
|
+
var OPERATOR_DIAGNOSTIC_PATH_LIMIT = 1024;
|
|
2546
|
+
var OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT = 256;
|
|
2547
|
+
var OPERATOR_DIAGNOSTIC_HOME_PATHS = machineHomePathPatterns("gu");
|
|
2548
|
+
function redactOperatorDiagnosticSecrets(value) {
|
|
2549
|
+
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]");
|
|
2550
|
+
}
|
|
2551
|
+
function redactOperatorDiagnosticText(value) {
|
|
2552
|
+
const normalized = normalizeCealSingleLineText(value);
|
|
2553
|
+
return normalizeCealSingleLineText(redactOperatorDiagnosticSecrets(redactFilePaths(redactHomePaths(redactUrls(normalized)))));
|
|
2554
|
+
}
|
|
2555
|
+
function renderOperatorDiagnostic(value) {
|
|
2556
|
+
const state = collectDiagnosticState(value);
|
|
2557
|
+
const fields = [
|
|
2558
|
+
state.status === void 0 ? void 0 : `status=${JSON.stringify(safeDiagnosticText(state.status))}`,
|
|
2559
|
+
state.exitCode === void 0 ? void 0 : `exit_code=${state.exitCode}`,
|
|
2560
|
+
state.stdout === void 0 ? void 0 : `stdout_tail=${JSON.stringify(tail(state.stdout))}`,
|
|
2561
|
+
state.stderr === void 0 ? void 0 : `stderr_tail=${JSON.stringify(tail(state.stderr))}`,
|
|
2562
|
+
state.causes.length === 0 ? void 0 : `causes=${state.causes.map(formatCause).join(" <- ")}`
|
|
2563
|
+
].filter((field) => field !== void 0);
|
|
2564
|
+
const rendered = fields.length === 0 ? "unknown_failure" : fields.join(" ");
|
|
2565
|
+
return truncateUtf8(rendered, OPERATOR_DIAGNOSTIC_MAX_BYTES);
|
|
2566
|
+
}
|
|
2567
|
+
function collectDiagnosticState(value) {
|
|
2568
|
+
const state = { causes: [], status: void 0, exitCode: void 0, stdout: void 0, stderr: void 0 };
|
|
2569
|
+
const visited = /* @__PURE__ */ new Set(), pending = [value];
|
|
2570
|
+
while (pending.length > 0 && state.causes.length < OPERATOR_DIAGNOSTIC_MAX_CAUSES) {
|
|
2571
|
+
const current = pending.shift();
|
|
2572
|
+
if (current !== void 0) visitDiagnosticNode(current, state, pending, visited);
|
|
2573
|
+
}
|
|
2574
|
+
return state;
|
|
2575
|
+
}
|
|
2576
|
+
function visitDiagnosticNode(current, state, pending, visited) {
|
|
2577
|
+
if (isObject(current)) {
|
|
2578
|
+
if (visited.has(current)) return;
|
|
2579
|
+
visited.add(current);
|
|
2580
|
+
}
|
|
2581
|
+
captureProcessEvidence(current, state);
|
|
2582
|
+
appendCause(current, state.causes);
|
|
2583
|
+
enqueueCauseChildren(current, state.causes.length, pending);
|
|
2584
|
+
}
|
|
2585
|
+
function captureProcessEvidence(current, state) {
|
|
2586
|
+
if (state.status === void 0) state.status = safeStatus(read(current, "status"));
|
|
2587
|
+
if (state.exitCode === void 0) state.exitCode = safeExitCode(read(current, "exitCode")) ?? safeExitCode(read(current, "status")) ?? safeExitCode(read(current, "code"));
|
|
2588
|
+
if (state.stdout === void 0) state.stdout = outputText(read(current, "stdout"));
|
|
2589
|
+
if (state.stderr === void 0) state.stderr = outputText(read(current, "stderr"));
|
|
2590
|
+
}
|
|
2591
|
+
function appendCause(current, causes) {
|
|
2592
|
+
const errors = read(current, "errors");
|
|
2593
|
+
if (current instanceof Error && (!(current instanceof AggregateError) || !Array.isArray(errors) || errors.length === 0)) {
|
|
2594
|
+
causes.push(errorCause(current));
|
|
2595
|
+
return;
|
|
2596
|
+
}
|
|
2597
|
+
if (!isObject(current)) {
|
|
2598
|
+
const message = safeText(current);
|
|
2599
|
+
if (message !== void 0) causes.push(Object.freeze({ error_class: typeof current, message }));
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
function errorCause(error) {
|
|
2603
|
+
const name = safeText(read(error, "name")) ?? "Error";
|
|
2604
|
+
const message = safeText(read(error, "message"));
|
|
2605
|
+
const codeValue = read(error, "code");
|
|
2606
|
+
const code2 = typeof codeValue === "number" && Number.isFinite(codeValue) ? codeValue : safeText(codeValue);
|
|
2607
|
+
const errnoValue = read(error, "errno");
|
|
2608
|
+
const errno = typeof errnoValue === "number" && Number.isSafeInteger(errnoValue) ? errnoValue : void 0;
|
|
2609
|
+
const syscall = safeText(read(error, "syscall"));
|
|
2610
|
+
const path = safePath(read(error, "path"));
|
|
2611
|
+
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 } });
|
|
2612
|
+
}
|
|
2613
|
+
function enqueueCauseChildren(current, causeCount, pending) {
|
|
2614
|
+
const cause = read(current, "cause");
|
|
2615
|
+
if (cause !== void 0) pending.push(cause);
|
|
2616
|
+
const errors = read(current, "errors");
|
|
2617
|
+
if (Array.isArray(errors)) pending.push(...errors.slice(0, OPERATOR_DIAGNOSTIC_MAX_CAUSES - causeCount));
|
|
2618
|
+
}
|
|
2619
|
+
function isObject(value) {
|
|
2620
|
+
return typeof value === "object" && value !== null;
|
|
2621
|
+
}
|
|
2622
|
+
function formatCause(cause) {
|
|
2623
|
+
const fields = [
|
|
2624
|
+
cause.error_class,
|
|
2625
|
+
cause.code === void 0 ? void 0 : `code=${JSON.stringify(safeDiagnosticText(cause.code))}`,
|
|
2626
|
+
cause.errno === void 0 ? void 0 : `errno=${cause.errno}`,
|
|
2627
|
+
cause.syscall === void 0 ? void 0 : `syscall=${JSON.stringify(cause.syscall)}`,
|
|
2628
|
+
cause.path === void 0 ? void 0 : `path=${JSON.stringify(cause.path)}`,
|
|
2629
|
+
cause.message === void 0 ? void 0 : `message=${cause.message}`
|
|
2630
|
+
].filter((field) => field !== void 0);
|
|
2631
|
+
return fields.join(" ");
|
|
2632
|
+
}
|
|
2633
|
+
function tail(value) {
|
|
2634
|
+
const clipped = value.length <= OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT ? value : `…${value.slice(-OPERATOR_DIAGNOSTIC_STREAM_TAIL_LIMIT)}`;
|
|
2635
|
+
return safeDiagnosticText(clipped);
|
|
2636
|
+
}
|
|
2637
|
+
function safeText(value) {
|
|
2638
|
+
if (typeof value !== "string") return void 0;
|
|
2639
|
+
const safe = safeDiagnosticText(value);
|
|
2640
|
+
if (safe.length === 0) return void 0;
|
|
2641
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT) return safe;
|
|
2642
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT / 2);
|
|
2643
|
+
const tail2 = OPERATOR_DIAGNOSTIC_CAUSE_MESSAGE_LIMIT - head - 1;
|
|
2644
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2645
|
+
}
|
|
2646
|
+
function safePath(value) {
|
|
2647
|
+
if (typeof value !== "string") return void 0;
|
|
2648
|
+
const safe = safeDiagnosticText(value);
|
|
2649
|
+
if (safe.length === 0) return void 0;
|
|
2650
|
+
if (safe.length <= OPERATOR_DIAGNOSTIC_PATH_LIMIT) return safe;
|
|
2651
|
+
const head = Math.floor(OPERATOR_DIAGNOSTIC_PATH_LIMIT / 2);
|
|
2652
|
+
const tail2 = OPERATOR_DIAGNOSTIC_PATH_LIMIT - head - 1;
|
|
2653
|
+
return `${safe.slice(0, head)}…${safe.slice(-tail2)}`;
|
|
2654
|
+
}
|
|
2655
|
+
function safeDiagnosticText(value) {
|
|
2656
|
+
return redactOperatorDiagnosticText(String(value));
|
|
2657
|
+
}
|
|
2658
|
+
function outputText(value) {
|
|
2659
|
+
if (typeof value === "string") return redactOperatorDiagnosticText(value);
|
|
2660
|
+
if (value instanceof Uint8Array) {
|
|
2661
|
+
try {
|
|
2662
|
+
return redactOperatorDiagnosticText(new TextDecoder().decode(value));
|
|
2663
|
+
} catch {
|
|
2664
|
+
return void 0;
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
return void 0;
|
|
2668
|
+
}
|
|
2669
|
+
function safeStatus(value) {
|
|
2670
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
2671
|
+
return typeof value === "string" ? safeText(value) : void 0;
|
|
2672
|
+
}
|
|
2673
|
+
function safeExitCode(value) {
|
|
2674
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : void 0;
|
|
2675
|
+
}
|
|
2676
|
+
function read(value, key) {
|
|
2677
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) return void 0;
|
|
2678
|
+
try {
|
|
2679
|
+
return Reflect.get(value, key);
|
|
2680
|
+
} catch {
|
|
2681
|
+
return void 0;
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
function redactHomePaths(value) {
|
|
2685
|
+
const paths = [
|
|
2686
|
+
...OPERATOR_DIAGNOSTIC_HOME_PATHS.flatMap((pattern) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, matchedHomePrefixLength(match[0])))),
|
|
2687
|
+
...configuredHomePathPatterns().flatMap(({ pattern, prefixLength }) => [...value.matchAll(pattern)].map((match) => homePathRange(value, match, prefixLength)))
|
|
2688
|
+
];
|
|
2689
|
+
paths.sort((left, right) => left.start - right.start || right.end - left.end);
|
|
2690
|
+
let output = "";
|
|
2691
|
+
let cursor = 0;
|
|
2692
|
+
for (const path of paths) {
|
|
2693
|
+
if (path.start < cursor) continue;
|
|
2694
|
+
output += `${value.slice(cursor, path.start)}[home path redacted]${value.slice(path.prefixEnd, path.end)}`;
|
|
2695
|
+
cursor = path.end;
|
|
2696
|
+
}
|
|
2697
|
+
return output + value.slice(cursor);
|
|
2698
|
+
}
|
|
2699
|
+
function configuredHomePathPatterns() {
|
|
2700
|
+
const homes = [...new Set([process.env.HOME, process.env.USERPROFILE].filter((home) => home !== void 0 && home.length > 0))];
|
|
2701
|
+
return homes.flatMap((home) => {
|
|
2702
|
+
const root = home.replace(/[\\/]+$/gu, "");
|
|
2703
|
+
if (root.length === 0 || root === "/" || /^[A-Za-z]:$/u.test(root)) return [];
|
|
2704
|
+
const pattern = new RegExp(`(?<![A-Za-z0-9_])${escapePathPattern(root)}(?=$|[\\\\/\\s"'\`<>(){}\\[\\],;])`, /^[A-Za-z]:[\\/]/u.test(root) ? "giu" : "gu");
|
|
2705
|
+
return [{ pattern, prefixLength: root.length }];
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
function matchedHomePrefixLength(value) {
|
|
2709
|
+
let separators = 0;
|
|
2710
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
2711
|
+
if (value[index] !== "/" && value[index] !== "\\") continue;
|
|
2712
|
+
separators += 1;
|
|
2713
|
+
if (separators === 3) return index;
|
|
2714
|
+
}
|
|
2715
|
+
return value.length;
|
|
2716
|
+
}
|
|
2717
|
+
function redactUrls(value) {
|
|
2718
|
+
return value.replaceAll(/https?:\/\/[^\s"'<>]+/giu, "[url redacted]");
|
|
2719
|
+
}
|
|
2720
|
+
function redactFilePaths(value) {
|
|
2721
|
+
return value.replaceAll(/(?<![A-Za-z0-9._-]|\[home path redacted\])(?:[A-Za-z]:[\\/]|\\\\[^\\\s]+\\|\/)[^:\r\n"'<>]*?(?=:\d+(?::\d+)?(?:[:\s]|$)|[\r\n]|["'])/gu, "[path redacted]");
|
|
2722
|
+
}
|
|
2723
|
+
function homePathRange(value, match, prefixLength) {
|
|
2724
|
+
const index = match.index;
|
|
2725
|
+
if (index === void 0) return { start: value.length, end: value.length, prefixEnd: value.length };
|
|
2726
|
+
const start = index;
|
|
2727
|
+
let end = start + match[0].length;
|
|
2728
|
+
const quote = start > 0 && (value[start - 1] === "'" || value[start - 1] === '"') ? value[start - 1] : void 0;
|
|
2729
|
+
if (quote !== void 0) {
|
|
2730
|
+
const closing = value.indexOf(quote, end);
|
|
2731
|
+
if (closing >= 0) end = closing;
|
|
2732
|
+
}
|
|
2733
|
+
while (end < value.length && !/[\s"'`<>(){}[\],;]/u.test(value[end] ?? "")) end += 1;
|
|
2734
|
+
return { start, end, prefixEnd: Math.min(start + prefixLength, end) };
|
|
2735
|
+
}
|
|
2736
|
+
function truncateUtf8(value, maxBytes) {
|
|
2737
|
+
if (byteLength(value) <= maxBytes) return value;
|
|
2738
|
+
let output = "";
|
|
2739
|
+
for (const character of value) {
|
|
2740
|
+
if (byteLength(`${output}${character}…`) > maxBytes) break;
|
|
2741
|
+
output += character;
|
|
2742
|
+
}
|
|
2743
|
+
return `${output}…`;
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2506
2746
|
// packages/ceal-client-protocol/src/admin-projection-vocabulary.ts
|
|
2507
2747
|
var ADMIN_PROJECTION_STATES = vocabulary(["ready", "empty", "partial", "unknown"]);
|
|
2508
2748
|
var ADMIN_VIEW_KINDS = vocabulary(["request_detail", "resource_access_timeline", "weekly_usage"]);
|
|
@@ -2934,7 +3174,7 @@ function parseCanonicalJson(text, error) {
|
|
|
2934
3174
|
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) }])}`);
|
|
2935
3175
|
return value;
|
|
2936
3176
|
} catch (parseError) {
|
|
2937
|
-
throw error("invalid_config",
|
|
3177
|
+
throw error("invalid_config", `parse_error=${renderOperatorDiagnostic(parseError)}; ${refusalFact("config_bytes", Buffer.byteLength(text, "utf8"), "canonical JSON")}`);
|
|
2938
3178
|
}
|
|
2939
3179
|
}
|
|
2940
3180
|
function firstDifferenceIndex(left, right) {
|
|
@@ -3549,14 +3789,14 @@ var HostUsageFactsStore = class {
|
|
|
3549
3789
|
const gate = new Promise((resolve) => {
|
|
3550
3790
|
release = resolve;
|
|
3551
3791
|
});
|
|
3552
|
-
const
|
|
3553
|
-
SESSION_TRANSITION_TAILS.set(key,
|
|
3792
|
+
const tail2 = previous.then(() => gate);
|
|
3793
|
+
SESSION_TRANSITION_TAILS.set(key, tail2);
|
|
3554
3794
|
await previous;
|
|
3555
3795
|
try {
|
|
3556
3796
|
return await run();
|
|
3557
3797
|
} finally {
|
|
3558
3798
|
release?.();
|
|
3559
|
-
if (SESSION_TRANSITION_TAILS.get(key) ===
|
|
3799
|
+
if (SESSION_TRANSITION_TAILS.get(key) === tail2) SESSION_TRANSITION_TAILS.delete(key);
|
|
3560
3800
|
}
|
|
3561
3801
|
}
|
|
3562
3802
|
sessionPath(producer, hostSourceRef, hostSessionRef) {
|
|
@@ -4169,9 +4409,9 @@ async function readTranscriptCompleteChunk(handle, offset, size) {
|
|
|
4169
4409
|
let lastNewline = -1;
|
|
4170
4410
|
while (position < size) {
|
|
4171
4411
|
const buffer = Buffer.alloc(Math.min(HOST_TRANSCRIPT_READ_CHUNK_BYTES, size - position));
|
|
4172
|
-
const
|
|
4173
|
-
if (
|
|
4174
|
-
const chunk = buffer.subarray(0,
|
|
4412
|
+
const read2 = await handle.read(buffer, 0, buffer.length, position);
|
|
4413
|
+
if (read2.bytesRead === 0) break;
|
|
4414
|
+
const chunk = buffer.subarray(0, read2.bytesRead);
|
|
4175
4415
|
chunks.push(chunk);
|
|
4176
4416
|
const newline = chunk.lastIndexOf(10);
|
|
4177
4417
|
if (newline >= 0) lastNewline = total + newline;
|
|
@@ -4344,15 +4584,15 @@ var HostProducerDrainCore = class {
|
|
|
4344
4584
|
return run;
|
|
4345
4585
|
}
|
|
4346
4586
|
async drainLocked() {
|
|
4347
|
-
const
|
|
4587
|
+
const read2 = await this.host.listEnvelopes();
|
|
4348
4588
|
let removed = 0;
|
|
4349
4589
|
let expired = 0;
|
|
4350
|
-
for (const envelope of
|
|
4590
|
+
for (const envelope of read2.entries) {
|
|
4351
4591
|
if (Date.parse(this.host.expiresAtOf(envelope)) <= this.now().getTime()) expired += 1;
|
|
4352
4592
|
else removed += 1;
|
|
4353
4593
|
await this.host.removeEnvelope(envelope);
|
|
4354
4594
|
}
|
|
4355
|
-
return { removed, expired, malformed:
|
|
4595
|
+
return { removed, expired, malformed: read2.malformed };
|
|
4356
4596
|
}
|
|
4357
4597
|
};
|
|
4358
4598
|
|
|
@@ -4436,29 +4676,46 @@ var HostUsageTranscriptSourceError = class extends Error {
|
|
|
4436
4676
|
this.name = "HostUsageTranscriptSourceError";
|
|
4437
4677
|
}
|
|
4438
4678
|
};
|
|
4439
|
-
async function readHostUsageTranscriptSource(
|
|
4679
|
+
async function readHostUsageTranscriptSource(read2) {
|
|
4440
4680
|
try {
|
|
4441
|
-
return await
|
|
4681
|
+
return await read2();
|
|
4442
4682
|
} catch (error) {
|
|
4443
4683
|
throw new HostUsageTranscriptSourceError({ cause: error });
|
|
4444
4684
|
}
|
|
4445
4685
|
}
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4686
|
+
var HostUsageRegistrationCapture = class {
|
|
4687
|
+
nextIndex = 0;
|
|
4688
|
+
producer;
|
|
4689
|
+
diagnosticSink;
|
|
4690
|
+
constructor(producer, diagnosticSink) {
|
|
4691
|
+
this.producer = producer;
|
|
4692
|
+
this.diagnosticSink = diagnosticSink;
|
|
4693
|
+
}
|
|
4694
|
+
async captureNext(registrations, capture) {
|
|
4695
|
+
let failed = false;
|
|
4696
|
+
let captured = false;
|
|
4697
|
+
const onFailure = () => {
|
|
4457
4698
|
failed = true;
|
|
4699
|
+
};
|
|
4700
|
+
for (let attempt = 0; attempt < registrations.length; attempt += 1) {
|
|
4701
|
+
const index = (this.nextIndex + attempt) % registrations.length;
|
|
4702
|
+
const registration = registrations[index];
|
|
4703
|
+
if (registration === void 0) continue;
|
|
4704
|
+
try {
|
|
4705
|
+
captured = await capture(registration, onFailure);
|
|
4706
|
+
if (captured) {
|
|
4707
|
+
this.nextIndex = (index + 1) % registrations.length;
|
|
4708
|
+
break;
|
|
4709
|
+
}
|
|
4710
|
+
} catch (error) {
|
|
4711
|
+
if (!(error instanceof HostUsageTranscriptSourceError)) throw error;
|
|
4712
|
+
onFailure();
|
|
4713
|
+
}
|
|
4458
4714
|
}
|
|
4715
|
+
if (failed) writeHostServiceDiagnostic(this.producer, "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
4716
|
+
return captured;
|
|
4459
4717
|
}
|
|
4460
|
-
|
|
4461
|
-
}
|
|
4718
|
+
};
|
|
4462
4719
|
async function openHostUsageTranscriptCursor(input) {
|
|
4463
4720
|
const handle = await readHostUsageTranscriptSource(() => openNoFollow(input.path, constants5.O_RDONLY));
|
|
4464
4721
|
let source;
|
|
@@ -4757,6 +5014,13 @@ var ClaudeOutboxStore = class {
|
|
|
4757
5014
|
await this.removeStateFile(this.registrationPath(registration.host_source_ref, registration.host_session_ref));
|
|
4758
5015
|
await this.removeStateFile(this.cursorPath(registration.host_source_ref, registration.host_session_ref));
|
|
4759
5016
|
}
|
|
5017
|
+
async readTranscriptRegistration(hostSourceRef, hostSessionRef) {
|
|
5018
|
+
if (!SAFE_REF3.test(hostSourceRef) || !SAFE_REF3.test(hostSessionRef)) throw new ClaudeHostError("invalid_input", "Claude transcript session identity is invalid.");
|
|
5019
|
+
await this.prepare();
|
|
5020
|
+
const registration = await this.readRegistrationFile(this.registrationPath(hostSourceRef, hostSessionRef));
|
|
5021
|
+
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.");
|
|
5022
|
+
return registration;
|
|
5023
|
+
}
|
|
4760
5024
|
async listTranscriptRegistrations() {
|
|
4761
5025
|
await this.prepare();
|
|
4762
5026
|
const registrations = [];
|
|
@@ -5026,6 +5290,7 @@ var ClaudeProducer = class {
|
|
|
5026
5290
|
|
|
5027
5291
|
// host/claude/src/claude-transcript-watcher.ts
|
|
5028
5292
|
import { readdir as readdir2 } from "node:fs/promises";
|
|
5293
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5029
5294
|
import { join as join5 } from "node:path";
|
|
5030
5295
|
|
|
5031
5296
|
// host/claude/src/claude-decoder.ts
|
|
@@ -5111,10 +5376,39 @@ function record4(value) {
|
|
|
5111
5376
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5112
5377
|
}
|
|
5113
5378
|
|
|
5379
|
+
// host/claude/src/claude-subagent-overflow-checkpoint.ts
|
|
5380
|
+
var ClaudeSubagentOverflowCheckpoint = class {
|
|
5381
|
+
observed = /* @__PURE__ */ new Map();
|
|
5382
|
+
prune(registrations) {
|
|
5383
|
+
const current = new Set(registrations.map(registrationKey));
|
|
5384
|
+
for (const key of this.observed.keys()) if (!current.has(key)) this.observed.delete(key);
|
|
5385
|
+
}
|
|
5386
|
+
clear(registration) {
|
|
5387
|
+
this.observed.delete(registrationKey(registration));
|
|
5388
|
+
}
|
|
5389
|
+
/** Names follow the producer's sorted inventory; only omitted names define overflow. */
|
|
5390
|
+
async observe(registration, names, report) {
|
|
5391
|
+
const key = registrationKey(registration);
|
|
5392
|
+
if (names.length <= CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES) {
|
|
5393
|
+
this.clear(registration);
|
|
5394
|
+
return false;
|
|
5395
|
+
}
|
|
5396
|
+
const digest = transcriptObjectSha256(names.slice(CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES));
|
|
5397
|
+
if (this.observed.get(key) === digest) return false;
|
|
5398
|
+
if (!await report()) return false;
|
|
5399
|
+
this.observed.set(key, digest);
|
|
5400
|
+
return true;
|
|
5401
|
+
}
|
|
5402
|
+
};
|
|
5403
|
+
function registrationKey(registration) {
|
|
5404
|
+
return JSON.stringify([registration.host_source_ref, registration.host_session_ref, registration.transcript_path]);
|
|
5405
|
+
}
|
|
5406
|
+
|
|
5114
5407
|
// host/claude/src/claude-transcript-watcher.ts
|
|
5115
5408
|
var TOKEN_OBSERVATION_SOURCE = "claude_transcript.message.usage";
|
|
5116
5409
|
var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
5117
5410
|
store;
|
|
5411
|
+
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
5118
5412
|
diagnostic;
|
|
5119
5413
|
constructor(options) {
|
|
5120
5414
|
super(options, {
|
|
@@ -5129,7 +5423,9 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5129
5423
|
return registration.transcript_path;
|
|
5130
5424
|
}
|
|
5131
5425
|
async listRegistrations() {
|
|
5132
|
-
|
|
5426
|
+
const registrations = await this.store.listTranscriptRegistrations();
|
|
5427
|
+
this.overflow.prune(registrations);
|
|
5428
|
+
return registrations;
|
|
5133
5429
|
}
|
|
5134
5430
|
async scanOpened(handle, registration) {
|
|
5135
5431
|
const { size, device, inode } = await ownedClaudeTranscriptFile(handle);
|
|
@@ -5141,7 +5437,7 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5141
5437
|
}
|
|
5142
5438
|
if (preflight.checkpointPending) await this.store.writeTranscriptCursor({ ...cursor, updated_at: this.stamp() });
|
|
5143
5439
|
const draft = mutableCursor(cursor);
|
|
5144
|
-
await this.scanOpenedTranscript(registration, handle, draft, size, device, inode);
|
|
5440
|
+
await this.scanOpenedTranscript(registration, handle, cursor, draft, size, device, inode);
|
|
5145
5441
|
return { records: draft.consumed, enqueued: draft.enqueued, quarantined: false };
|
|
5146
5442
|
}
|
|
5147
5443
|
async scanFailed(handle, registration, error) {
|
|
@@ -5178,7 +5474,7 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5178
5474
|
updated_at: this.stamp()
|
|
5179
5475
|
};
|
|
5180
5476
|
}
|
|
5181
|
-
async scanOpenedTranscript(registration, handle, draft, size, device, inode) {
|
|
5477
|
+
async scanOpenedTranscript(registration, handle, previous, draft, size, device, inode) {
|
|
5182
5478
|
const main = await this.readChunk(handle, draft.offset, size);
|
|
5183
5479
|
if (main !== "empty" && main !== "partial") {
|
|
5184
5480
|
await this.consumeMainChunk(registration, main, draft);
|
|
@@ -5186,7 +5482,7 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5186
5482
|
}
|
|
5187
5483
|
draft.consumed += await this.consumeSubagents(registration, draft);
|
|
5188
5484
|
await this.emitOpenTerminal(registration, draft);
|
|
5189
|
-
await this.commitCursor(registration, handle, draft, device, inode);
|
|
5485
|
+
await this.commitCursor(registration, handle, previous, draft, device, inode);
|
|
5190
5486
|
}
|
|
5191
5487
|
async preflight(registration, handle, size, device, inode) {
|
|
5192
5488
|
const existing = await this.store.readTranscriptCursor(registration);
|
|
@@ -5346,15 +5642,24 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5346
5642
|
try {
|
|
5347
5643
|
names = (await readdir2(directory)).filter((name) => name.endsWith(".jsonl") && !name.endsWith(".meta.json")).sort();
|
|
5348
5644
|
} catch (error) {
|
|
5349
|
-
if (isMissingTranscriptError(error) || isNotDirectory(error))
|
|
5645
|
+
if (isMissingTranscriptError(error) || isNotDirectory(error)) {
|
|
5646
|
+
this.overflow.clear(registration);
|
|
5647
|
+
return 0;
|
|
5648
|
+
}
|
|
5350
5649
|
throw new ClaudeHostError("payload_rejected", "Claude subagent transcript directory is unavailable.");
|
|
5351
5650
|
}
|
|
5352
5651
|
const listed = new Set(names);
|
|
5353
5652
|
for (const name of Object.keys(draft.subagents)) if (!listed.has(name)) delete draft.subagents[name];
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5653
|
+
await this.overflow.observe(registration, names, () => {
|
|
5654
|
+
const line = `Claude ignored subagent transcripts past its file bound: transcript_path=${JSON.stringify(registration.transcript_path)}, files=${names.length}.`;
|
|
5655
|
+
try {
|
|
5656
|
+
this.log(line);
|
|
5657
|
+
} catch {
|
|
5658
|
+
return false;
|
|
5659
|
+
}
|
|
5660
|
+
return true;
|
|
5661
|
+
});
|
|
5662
|
+
names = names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES);
|
|
5358
5663
|
let consumed = 0;
|
|
5359
5664
|
for (const name of names) {
|
|
5360
5665
|
consumed += await this.consumeSubagentFile(draft, directory, name);
|
|
@@ -5443,9 +5748,9 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5443
5748
|
expires_at: this.expire(this.outboxRetentionMs)
|
|
5444
5749
|
});
|
|
5445
5750
|
}
|
|
5446
|
-
async commitCursor(registration, handle, draft, device, inode) {
|
|
5751
|
+
async commitCursor(registration, handle, previous, draft, device, inode) {
|
|
5447
5752
|
const anchor = await this.readAnchor(handle, draft.offset, CLAUDE_TRANSCRIPT_ANCHOR_BYTES);
|
|
5448
|
-
|
|
5753
|
+
const cursor = {
|
|
5449
5754
|
schema_version: CLAUDE_TRANSCRIPT_CURSOR_SCHEMA_VERSION,
|
|
5450
5755
|
host_source_ref: registration.host_source_ref,
|
|
5451
5756
|
host_session_ref: registration.host_session_ref,
|
|
@@ -5462,7 +5767,9 @@ var ClaudeTranscriptWatcher = class extends HostTranscriptWatcher {
|
|
|
5462
5767
|
...draft.session_observed ? { session_observed: true } : {},
|
|
5463
5768
|
status: "active",
|
|
5464
5769
|
updated_at: this.stamp()
|
|
5465
|
-
}
|
|
5770
|
+
};
|
|
5771
|
+
if (sameCursorContent(cursor, previous)) return;
|
|
5772
|
+
await this.store.writeTranscriptCursor(cursor);
|
|
5466
5773
|
}
|
|
5467
5774
|
async activateContext(identity, promptRef, turnGenerationRef, expiresAt) {
|
|
5468
5775
|
try {
|
|
@@ -5513,6 +5820,9 @@ function mutableCursor(cursor) {
|
|
|
5513
5820
|
enqueued: 0
|
|
5514
5821
|
};
|
|
5515
5822
|
}
|
|
5823
|
+
function sameCursorContent(left, right) {
|
|
5824
|
+
return isDeepStrictEqual({ ...left, updated_at: void 0 }, { ...right, updated_at: void 0 });
|
|
5825
|
+
}
|
|
5516
5826
|
function zeroCounts() {
|
|
5517
5827
|
return { input: 0, cached_input: 0, cache_write_input: 0, output: 0 };
|
|
5518
5828
|
}
|
|
@@ -5643,11 +5953,14 @@ function isSymlinkTranscript(error) {
|
|
|
5643
5953
|
}
|
|
5644
5954
|
|
|
5645
5955
|
// host/claude/src/claude-producer-runtime.ts
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
outbox_dir:
|
|
5956
|
+
function createClaudeProducerWatcher(outboxDir) {
|
|
5957
|
+
return new ClaudeTranscriptWatcher({
|
|
5958
|
+
outbox_dir: outboxDir,
|
|
5649
5959
|
diagnostic: (event, failure_kind, cause) => writeHostServiceDiagnostic("claude", event, failure_kind, cause)
|
|
5650
|
-
})
|
|
5960
|
+
});
|
|
5961
|
+
}
|
|
5962
|
+
async function drainClaudeProducerOnce(options) {
|
|
5963
|
+
const scan = await (options.watcher ?? createClaudeProducerWatcher(options.outbox_dir)).scanOnce().catch((error) => {
|
|
5651
5964
|
writeHostServiceDiagnostic("claude", "watcher_scan_failed", claudeTranscriptScanFailureKind(error), claudeTranscriptScanCause(void 0, error));
|
|
5652
5965
|
throw error;
|
|
5653
5966
|
});
|
|
@@ -5664,25 +5977,20 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5664
5977
|
sources;
|
|
5665
5978
|
usage;
|
|
5666
5979
|
now;
|
|
5667
|
-
|
|
5668
|
-
nextRegistrationIndex = 0;
|
|
5980
|
+
registrations;
|
|
5669
5981
|
nextSourceSlot = "main";
|
|
5670
5982
|
nextSubagentIndex = 0;
|
|
5983
|
+
overflow = new ClaudeSubagentOverflowCheckpoint();
|
|
5671
5984
|
constructor(options) {
|
|
5672
5985
|
this.sources = new ClaudeOutboxStore(options.outbox_dir);
|
|
5673
5986
|
this.usage = new HostUsageFactsStore({ outbox_dir: options.outbox_dir, ...options.store_options });
|
|
5674
5987
|
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
5675
|
-
this.
|
|
5988
|
+
this.registrations = new HostUsageRegistrationCapture("claude", options.diagnostic_sink);
|
|
5676
5989
|
}
|
|
5677
5990
|
async captureNext() {
|
|
5678
5991
|
const registrations = await this.sources.listTranscriptRegistrations();
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
failed = true;
|
|
5682
|
-
}));
|
|
5683
|
-
this.nextRegistrationIndex = result.nextIndex;
|
|
5684
|
-
if (failed || result.failed) writeHostServiceDiagnostic("claude", "usage_capture_failed", void 0, "capture_failed", this.diagnosticSink);
|
|
5685
|
-
return result.captured;
|
|
5992
|
+
this.overflow.prune(registrations);
|
|
5993
|
+
return await this.registrations.captureNext(registrations, (registration, onFailure) => this.captureRegistration(registration, onFailure));
|
|
5686
5994
|
}
|
|
5687
5995
|
async captureRegistration(registration, onFailure) {
|
|
5688
5996
|
const sources = this.nextSourceSlot === "main" ? ["main", "subagent"] : ["subagent", "main"];
|
|
@@ -5729,13 +6037,14 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5729
6037
|
}
|
|
5730
6038
|
async captureSubagent(registration, onFailure) {
|
|
5731
6039
|
const names = await readSubagentNames(registration);
|
|
6040
|
+
if (names.length <= CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES) this.overflow.clear(registration);
|
|
5732
6041
|
let state = await this.usage.readState("claude", registration.host_source_ref, registration.host_session_ref);
|
|
5733
6042
|
if (state === null) return false;
|
|
5734
6043
|
state = await this.usage.recoverPending(state);
|
|
5735
6044
|
if (state.quarantined_reason !== void 0) return false;
|
|
5736
6045
|
if (await this.retireMissingSubagent(state, names)) return true;
|
|
5737
6046
|
if (await this.captureListedSubagents(registration, names, state, onFailure)) return true;
|
|
5738
|
-
return await this.recordExcessSubagentGap(state, names);
|
|
6047
|
+
return await this.recordExcessSubagentGap(registration, state, names);
|
|
5739
6048
|
}
|
|
5740
6049
|
async retireMissingSubagent(state, names) {
|
|
5741
6050
|
const liveSlots = new Set(names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES).map(subagentSlot));
|
|
@@ -5746,14 +6055,14 @@ var ClaudeUsageFactsCapturer = class {
|
|
|
5746
6055
|
}
|
|
5747
6056
|
return false;
|
|
5748
6057
|
}
|
|
5749
|
-
async recordExcessSubagentGap(state, names) {
|
|
5750
|
-
const excessCount = names.length - CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES;
|
|
5751
|
-
if (excessCount <= 0) return false;
|
|
6058
|
+
async recordExcessSubagentGap(registration, state, names) {
|
|
5752
6059
|
const mainCursor = state.cursors.main;
|
|
5753
6060
|
if (mainCursor === void 0) return false;
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
6061
|
+
return await this.overflow.observe(registration, names, async () => {
|
|
6062
|
+
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 };
|
|
6063
|
+
await this.usage.commitScanTransition(state, "main", mainCursor, mainCursor, null, [gap]);
|
|
6064
|
+
return true;
|
|
6065
|
+
});
|
|
5757
6066
|
}
|
|
5758
6067
|
async captureListedSubagents(registration, names, state, onFailure) {
|
|
5759
6068
|
const candidates = names.slice(0, CLAUDE_TRANSCRIPT_MAX_SUBAGENT_FILES);
|
|
@@ -6035,7 +6344,7 @@ var CLAUDE_PRODUCER_DESCRIPTOR = {
|
|
|
6035
6344
|
producer_id: "claude",
|
|
6036
6345
|
extra_paths: [CLAUDE_TRANSCRIPTS_ROOT],
|
|
6037
6346
|
config: (shared, extras) => ({ ...shared, claude_transcripts_root: hostProducerExtraPath(extras, CLAUDE_TRANSCRIPTS_ROOT) }),
|
|
6038
|
-
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir }),
|
|
6347
|
+
runtime_options: (config) => Object.freeze({ outbox_dir: config.outbox_dir, watcher: createClaudeProducerWatcher(config.outbox_dir) }),
|
|
6039
6348
|
drain: drainClaudeProducerOnce,
|
|
6040
6349
|
background: (config, signal, dependencies) => {
|
|
6041
6350
|
const capturer = new ClaudeUsageFactsCapturer({ outbox_dir: config.outbox_dir });
|