@sema-agent/server 1.323.0 → 2.0.0
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/dist/approval-hmac.d.ts +40 -0
- package/dist/approval-hmac.js +67 -0
- package/dist/approval.d.ts +31 -0
- package/dist/approval.js +72 -4
- package/dist/audit.d.ts +26 -0
- package/dist/audit.js +40 -1
- package/dist/auth-bridge.d.ts +10 -0
- package/dist/auth-bridge.js +47 -4
- package/dist/auth-keys.d.ts +19 -0
- package/dist/auth-keys.js +13 -0
- package/dist/bake-runner/main.d.ts +5 -0
- package/dist/bake-runner/main.js +43 -4
- package/dist/bake-runner/protocol.d.ts +57 -0
- package/dist/bake-runner/protocol.js +58 -3
- package/dist/bake-runner/runner.d.ts +54 -0
- package/dist/bake-runner/runner.js +87 -5
- package/dist/bench/l8/artifact.d.ts +63 -0
- package/dist/bench/l8/artifact.js +61 -2
- package/dist/bench/l8/escape.d.ts +36 -0
- package/dist/bench/l8/escape.js +25 -0
- package/dist/bench/l8/index.d.ts +14 -0
- package/dist/bench/l8/index.js +14 -0
- package/dist/bench/l8/probes.d.ts +74 -0
- package/dist/bench/l8/probes.js +60 -0
- package/dist/bench/l8/run-probes.d.ts +43 -0
- package/dist/bench/l8/run-probes.js +45 -2
- package/dist/bench/s1/arms.d.ts +126 -0
- package/dist/bench/s1/arms.js +188 -13
- package/dist/bench/s1/live-deps.d.ts +66 -0
- package/dist/bench/s1/live-deps.js +249 -11
- package/dist/bench/s1/oracle.d.ts +49 -0
- package/dist/bench/s1/oracle.js +36 -1
- package/dist/bench/s1/repair-oracle-adapter.d.ts +33 -0
- package/dist/bench/s1/repair-oracle-adapter.js +30 -0
- package/dist/bench/s1/reviewer.d.ts +38 -0
- package/dist/bench/s1/reviewer.js +34 -0
- package/dist/bench/s1/row.d.ts +77 -0
- package/dist/bench/s1/row.js +62 -0
- package/dist/bench/s1/run-firm.d.ts +47 -0
- package/dist/bench/s1/run-firm.js +70 -4
- package/dist/bench/s1/runner-ctx.d.ts +71 -0
- package/dist/bench/s1/runner-ctx.js +36 -0
- package/dist/bench/s1/tasks.d.ts +108 -0
- package/dist/bench/s1/tasks.js +115 -0
- package/dist/boot-reclaim.d.ts +19 -0
- package/dist/boot-reclaim.js +20 -0
- package/dist/brain.d.ts +25 -0
- package/dist/brain.js +61 -1
- package/dist/budget.d.ts +66 -0
- package/dist/budget.js +128 -4
- package/dist/capabilities/builtin-tools.d.ts +3 -0
- package/dist/capabilities/builtin-tools.js +3 -0
- package/dist/capabilities/center-plugins.d.ts +17 -1
- package/dist/capabilities/center-plugins.js +45 -4
- package/dist/capabilities/center-prompts.d.ts +46 -0
- package/dist/capabilities/center-prompts.js +57 -3
- package/dist/capabilities/code-review-council.d.ts +28 -0
- package/dist/capabilities/code-review-council.js +40 -7
- package/dist/capabilities/collab-wire.d.ts +2 -0
- package/dist/capabilities/collab-workflows.d.ts +7 -0
- package/dist/capabilities/collab-workflows.js +44 -1
- package/dist/capabilities/oa-tools.d.ts +6 -0
- package/dist/capabilities/oa-tools.js +10 -0
- package/dist/capabilities/prompt.d.ts +14 -0
- package/dist/capabilities/prompt.js +14 -0
- package/dist/capabilities/prompts/code-review.d.ts +14 -0
- package/dist/capabilities/prompts/code-review.js +14 -0
- package/dist/capabilities/prompts/identity.d.ts +6 -0
- package/dist/capabilities/prompts/identity.js +6 -0
- package/dist/capabilities/prompts/team.d.ts +4 -0
- package/dist/capabilities/prompts/team.js +4 -0
- package/dist/capabilities/repo-tools.d.ts +11 -0
- package/dist/capabilities/repo-tools.js +8 -0
- package/dist/capabilities/sandbox-file-send.d.ts +95 -0
- package/dist/capabilities/sandbox-file-send.js +91 -3
- package/dist/capabilities/scenarios.d.ts +130 -0
- package/dist/capabilities/scenarios.js +180 -7
- package/dist/capabilities/select-environment-tool.d.ts +7 -0
- package/dist/capabilities/select-environment-tool.js +30 -0
- package/dist/capabilities/send-user-file-tool.d.ts +33 -0
- package/dist/capabilities/send-user-file-tool.js +65 -1
- package/dist/capabilities/skills.d.ts +29 -0
- package/dist/capabilities/skills.js +13 -2
- package/dist/capabilities/team.d.ts +22 -0
- package/dist/capabilities/team.js +22 -2
- package/dist/capabilities/tool-defer.d.ts +26 -0
- package/dist/capabilities/tool-defer.js +3 -0
- package/dist/config-center/apply-effective.d.ts +65 -0
- package/dist/config-center/apply-effective.js +204 -12
- package/dist/config-center/http-client.d.ts +34 -0
- package/dist/config-center/http-client.js +68 -0
- package/dist/config-center/restart-signal.d.ts +22 -0
- package/dist/config-center/restart-signal.js +39 -0
- package/dist/config-center/skills-mcp.d.ts +20 -1
- package/dist/config-center/skills-mcp.js +42 -7
- package/dist/config-center/types.d.ts +92 -1
- package/dist/config-lkg.d.ts +12 -0
- package/dist/config-lkg.js +41 -0
- package/dist/config-provider.d.ts +78 -0
- package/dist/config-provider.js +165 -2
- package/dist/config-types.d.ts +546 -0
- package/dist/config.d.ts +64 -0
- package/dist/config.js +455 -60
- package/dist/degenerate-instrument.d.ts +38 -0
- package/dist/degenerate-instrument.js +55 -3
- package/dist/elicitation.d.ts +39 -0
- package/dist/elicitation.js +87 -3
- package/dist/env-facts.d.ts +61 -0
- package/dist/env-facts.js +73 -7
- package/dist/fleet/fleet-bus.d.ts +185 -0
- package/dist/fleet/fleet-bus.js +333 -27
- package/dist/fleet/subagent-tail-bus.d.ts +11 -0
- package/dist/fleet/subagent-tail-bus.js +33 -2
- package/dist/fleet-client.d.ts +38 -0
- package/dist/fleet-client.js +44 -9
- package/dist/fleet-lease.d.ts +46 -0
- package/dist/fleet-lease.js +73 -5
- package/dist/hooks/branch-transcript.d.ts +8 -0
- package/dist/hooks/branch-transcript.js +33 -0
- package/dist/hooks/cc-stop-prompt.d.ts +42 -0
- package/dist/hooks/cc-stop-prompt.js +43 -1
- package/dist/hooks/hook-llm.d.ts +15 -0
- package/dist/hooks/hook-llm.js +47 -0
- package/dist/hooks/hook-runner.d.ts +89 -0
- package/dist/hooks/hook-runner.js +327 -18
- package/dist/http/idempotency.d.ts +31 -0
- package/dist/http/idempotency.js +34 -0
- package/dist/http/principal-gate.d.ts +17 -0
- package/dist/http/principal-gate.js +35 -3
- package/dist/http/route-ctx.d.ts +36 -0
- package/dist/http/routes/approvals-assistant.d.ts +25 -0
- package/dist/http/routes/approvals-assistant.js +253 -23
- package/dist/http/routes/attachments.js +22 -4
- package/dist/http/routes/capabilities.d.ts +7 -0
- package/dist/http/routes/capabilities.js +202 -1
- package/dist/http/routes/fleet.d.ts +6 -0
- package/dist/http/routes/fleet.js +94 -5
- package/dist/http/routes/images.d.ts +17 -0
- package/dist/http/routes/images.js +222 -14
- package/dist/http/routes/leader.d.ts +7 -0
- package/dist/http/routes/leader.js +10 -0
- package/dist/http/routes/memory-policy.d.ts +6 -0
- package/dist/http/routes/memory-policy.js +38 -6
- package/dist/http/routes/notify-wake.d.ts +10 -0
- package/dist/http/routes/notify-wake.js +19 -3
- package/dist/http/routes/observability.d.ts +6 -0
- package/dist/http/routes/observability.js +19 -2
- package/dist/http/routes/runs.d.ts +15 -0
- package/dist/http/routes/runs.js +464 -41
- package/dist/http/routes/session-sync.d.ts +15 -0
- package/dist/http/routes/session-sync.js +229 -19
- package/dist/http/routes/sessions-list.d.ts +6 -0
- package/dist/http/routes/sessions-list.js +35 -4
- package/dist/http/routes/sessions.d.ts +14 -0
- package/dist/http/routes/sessions.js +176 -31
- package/dist/http/routes/side-query.d.ts +8 -0
- package/dist/http/routes/side-query.js +26 -1
- package/dist/http/routes/tasks.d.ts +18 -0
- package/dist/http/routes/tasks.js +501 -38
- package/dist/http/routes/trace-usage.d.ts +10 -0
- package/dist/http/routes/trace-usage.js +66 -14
- package/dist/http/routes/workflows.d.ts +12 -0
- package/dist/http/routes/workflows.js +180 -19
- package/dist/http/run-meta.d.ts +11 -0
- package/dist/http/run-meta.js +6 -0
- package/dist/http/send.d.ts +19 -0
- package/dist/http/send.js +11 -0
- package/dist/http/server.d.ts +255 -0
- package/dist/http/server.js +921 -75
- package/dist/http/sse-log.d.ts +15 -0
- package/dist/http/sse-log.js +16 -0
- package/dist/http/tar.d.ts +9 -0
- package/dist/http/tar.js +21 -5
- package/dist/http/wire-gate.d.ts +9 -0
- package/dist/http/wire-gate.js +9 -0
- package/dist/http/wire-types.d.ts +187 -0
- package/dist/http/workspace-content.d.ts +8 -0
- package/dist/http/workspace-content.js +10 -0
- package/dist/images/bake-validate.d.ts +63 -0
- package/dist/images/bake-validate.js +71 -1
- package/dist/images/manifest.d.ts +19 -0
- package/dist/images/manifest.js +6 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.js +10 -5
- package/dist/key-resolver.d.ts +23 -0
- package/dist/key-resolver.js +27 -2
- package/dist/leader/diffout.d.ts +23 -0
- package/dist/leader/diffout.js +8 -1
- package/dist/leader/diffup.d.ts +32 -0
- package/dist/leader/diffup.js +43 -0
- package/dist/leader/endpoint.d.ts +20 -0
- package/dist/leader/endpoint.js +25 -2
- package/dist/leader/fanout.d.ts +60 -0
- package/dist/leader/fanout.js +29 -3
- package/dist/leader/grader-env-factory.d.ts +74 -0
- package/dist/leader/grader-env-factory.js +62 -3
- package/dist/leader/leader.d.ts +97 -0
- package/dist/leader/leader.js +151 -4
- package/dist/leader/merge.d.ts +94 -0
- package/dist/leader/merge.js +112 -9
- package/dist/leader/planner.d.ts +52 -0
- package/dist/leader/planner.js +47 -3
- package/dist/leader/repair-oracle.d.ts +61 -0
- package/dist/leader/repair-oracle.js +59 -1
- package/dist/leader/repair-wire.d.ts +78 -0
- package/dist/leader/repair-wire.js +79 -2
- package/dist/leader/wire.d.ts +79 -0
- package/dist/leader/wire.js +255 -8
- package/dist/lsp/e2b-bridge.d.ts +16 -0
- package/dist/lsp/e2b-bridge.js +32 -4
- package/dist/lsp/e2b-manager.d.ts +10 -0
- package/dist/lsp/e2b-manager.js +18 -2
- package/dist/lsp/lsp-frames.d.ts +12 -0
- package/dist/lsp/lsp-frames.js +12 -0
- package/dist/lsp/manager.d.ts +12 -0
- package/dist/lsp/manager.js +35 -2
- package/dist/lsp/types.d.ts +10 -0
- package/dist/lsp/ws-transport.d.ts +12 -0
- package/dist/lsp/ws-transport.js +53 -5
- package/dist/lsp-evict.d.ts +14 -0
- package/dist/lsp-evict.js +15 -1
- package/dist/main.js +2132 -96
- package/dist/memory-export.d.ts +1 -0
- package/dist/memory-export.js +4 -0
- package/dist/memory-scope.d.ts +49 -0
- package/dist/memory-scope.js +87 -4
- package/dist/memory-sync-client.d.ts +24 -0
- package/dist/memory-sync-client.js +41 -2
- package/dist/memory-sync.d.ts +23 -0
- package/dist/memory-sync.js +70 -1
- package/dist/model-select.d.ts +39 -0
- package/dist/model-select.js +42 -1
- package/dist/observability/cost-quota.d.ts +20 -0
- package/dist/observability/cost-quota.js +4 -0
- package/dist/observability/cost-taxonomy.d.ts +45 -0
- package/dist/observability/cost-taxonomy.js +34 -0
- package/dist/observability/logger.d.ts +1 -0
- package/dist/observability/logger.js +6 -0
- package/dist/observability/metrics.d.ts +13 -0
- package/dist/observability/metrics.js +63 -0
- package/dist/observability/otel-exporter.d.ts +9 -0
- package/dist/observability/otel-exporter.js +11 -3
- package/dist/observability/principal-context.d.ts +9 -0
- package/dist/observability/principal-context.js +9 -0
- package/dist/observability/prompt-manifest.d.ts +37 -0
- package/dist/observability/prompt-manifest.js +35 -1
- package/dist/observability/rate-limit.d.ts +10 -0
- package/dist/observability/rate-limit.js +1 -0
- package/dist/observability/tool-trace.d.ts +24 -0
- package/dist/observability/tool-trace.js +41 -1
- package/dist/orchestration/hardened-vm-runner.d.ts +107 -0
- package/dist/orchestration/hardened-vm-runner.js +119 -4
- package/dist/orchestration/hardened-vm-worker-runner.d.ts +14 -0
- package/dist/orchestration/hardened-vm-worker-runner.js +26 -1
- package/dist/orchestration/hardened-vm-worker.js +27 -0
- package/dist/orchestration/subagent-steer.d.ts +44 -0
- package/dist/orchestration/subagent-steer.js +45 -1
- package/dist/orchestration/workflow-agent-steer.d.ts +54 -0
- package/dist/orchestration/workflow-agent-steer.js +80 -1
- package/dist/orchestration/workflow-completion-inbox.d.ts +189 -2
- package/dist/orchestration/workflow-completion-inbox.js +283 -32
- package/dist/orchestration/workflow-notify-journal.d.ts +132 -1
- package/dist/orchestration/workflow-notify-journal.js +187 -13
- package/dist/parked-decide.d.ts +61 -0
- package/dist/parked-decide.js +58 -1
- package/dist/per-task-image.d.ts +54 -0
- package/dist/per-task-image.js +41 -0
- package/dist/plan-cache-probe.d.ts +35 -0
- package/dist/plan-cache-probe.js +18 -3
- package/dist/plugins/approval-exemption-store.d.ts +7 -0
- package/dist/plugins/approval-exemption-store.js +28 -2
- package/dist/plugins/approval-store-sql.d.ts +64 -0
- package/dist/plugins/approval-store-sql.js +32 -0
- package/dist/plugins/background-agent-store-sql.d.ts +55 -0
- package/dist/plugins/background-agent-store-sql.js +91 -4
- package/dist/plugins/background-shell-support.d.ts +98 -0
- package/dist/plugins/background-shell-support.js +117 -13
- package/dist/plugins/blob-backend.d.ts +104 -0
- package/dist/plugins/blob-backend.js +163 -6
- package/dist/plugins/breaker-state-sql.d.ts +65 -1
- package/dist/plugins/breaker-state-sql.js +46 -8
- package/dist/plugins/caching-session-store.d.ts +42 -0
- package/dist/plugins/caching-session-store.js +63 -3
- package/dist/plugins/checkpoint-store-sql.d.ts +179 -0
- package/dist/plugins/checkpoint-store-sql.js +239 -11
- package/dist/plugins/file-outcome-sink.d.ts +4 -0
- package/dist/plugins/file-outcome-sink.js +9 -0
- package/dist/plugins/file-resume-anchor-store.d.ts +20 -0
- package/dist/plugins/file-resume-anchor-store.js +43 -4
- package/dist/plugins/file-run-store.d.ts +90 -0
- package/dist/plugins/file-run-store.js +145 -13
- package/dist/plugins/file-snapshot-store-sql.d.ts +133 -1
- package/dist/plugins/file-snapshot-store-sql.js +178 -10
- package/dist/plugins/file-workflow-journal-store.d.ts +10 -0
- package/dist/plugins/file-workflow-journal-store.js +10 -0
- package/dist/plugins/fork-routing-session-store.d.ts +47 -0
- package/dist/plugins/fork-routing-session-store.js +51 -3
- package/dist/plugins/host-platform.d.ts +69 -0
- package/dist/plugins/host-platform.js +81 -2
- package/dist/plugins/image-bake-store-sql.d.ts +136 -1
- package/dist/plugins/image-bake-store-sql.js +241 -7
- package/dist/plugins/image-index-sql.d.ts +46 -0
- package/dist/plugins/image-index-sql.js +113 -4
- package/dist/plugins/k8s-bg-scripts.d.ts +34 -0
- package/dist/plugins/k8s-bg-scripts.js +88 -4
- package/dist/plugins/k8s-exec-protocol.d.ts +33 -0
- package/dist/plugins/k8s-exec-protocol.js +41 -0
- package/dist/plugins/local-checkpoint-store.d.ts +40 -0
- package/dist/plugins/local-checkpoint-store.js +86 -7
- package/dist/plugins/local-session-store.d.ts +157 -0
- package/dist/plugins/local-session-store.js +289 -34
- package/dist/plugins/local-task-attachment-store.js +14 -2
- package/dist/plugins/mailbox-store-sql.d.ts +38 -0
- package/dist/plugins/mailbox-store-sql.js +39 -6
- package/dist/plugins/memory-engine-pg.d.ts +30 -0
- package/dist/plugins/memory-engine-pg.js +122 -4
- package/dist/plugins/memory-engine-tidb.d.ts +26 -0
- package/dist/plugins/memory-engine-tidb.js +115 -5
- package/dist/plugins/memory-engine-vector-util.d.ts +5 -0
- package/dist/plugins/memory-engine-vector-util.js +5 -0
- package/dist/plugins/memory-resume-anchor-store.d.ts +8 -0
- package/dist/plugins/memory-resume-anchor-store.js +17 -0
- package/dist/plugins/memory-run-store.d.ts +63 -0
- package/dist/plugins/memory-run-store.js +73 -8
- package/dist/plugins/memory-session-policy-store.d.ts +17 -0
- package/dist/plugins/memory-session-policy-store.js +17 -0
- package/dist/plugins/memory-sync-store-pg.d.ts +42 -0
- package/dist/plugins/memory-sync-store-pg.js +45 -2
- package/dist/plugins/memory-sync-store-tidb.d.ts +9 -0
- package/dist/plugins/memory-sync-store-tidb.js +31 -1
- package/dist/plugins/outcome-ledger-sql.d.ts +63 -0
- package/dist/plugins/outcome-ledger-sql.js +97 -3
- package/dist/plugins/pg-approval-store.d.ts +7 -0
- package/dist/plugins/pg-approval-store.js +7 -0
- package/dist/plugins/pg-breaker-state.d.ts +6 -0
- package/dist/plugins/pg-breaker-state.js +6 -0
- package/dist/plugins/pg-checkpoint-store.d.ts +8 -0
- package/dist/plugins/pg-checkpoint-store.js +8 -0
- package/dist/plugins/pg-cost-quota.d.ts +17 -0
- package/dist/plugins/pg-cost-quota.js +6 -0
- package/dist/plugins/pg-file-snapshot-store.d.ts +6 -0
- package/dist/plugins/pg-file-snapshot-store.js +6 -0
- package/dist/plugins/pg-image-bake.d.ts +9 -0
- package/dist/plugins/pg-image-bake.js +9 -0
- package/dist/plugins/pg-image-index.d.ts +9 -0
- package/dist/plugins/pg-image-index.js +9 -0
- package/dist/plugins/pg-outcome-ledger.d.ts +9 -0
- package/dist/plugins/pg-outcome-ledger.js +9 -0
- package/dist/plugins/pg-pool.d.ts +50 -0
- package/dist/plugins/pg-pool.js +78 -0
- package/dist/plugins/pg-query.d.ts +11 -0
- package/dist/plugins/pg-rate-limiter.d.ts +23 -0
- package/dist/plugins/pg-rate-limiter.js +12 -2
- package/dist/plugins/pg-resume-anchor-store.d.ts +5 -0
- package/dist/plugins/pg-resume-anchor-store.js +5 -0
- package/dist/plugins/pg-run-store.d.ts +7 -0
- package/dist/plugins/pg-run-store.js +7 -0
- package/dist/plugins/pg-safe-json.d.ts +13 -0
- package/dist/plugins/pg-safe-json.js +40 -4
- package/dist/plugins/pg-session-policy-store.d.ts +5 -0
- package/dist/plugins/pg-session-policy-store.js +5 -0
- package/dist/plugins/pg-session-storage.d.ts +72 -0
- package/dist/plugins/pg-session-storage.js +152 -20
- package/dist/plugins/pg-session-store.d.ts +10 -0
- package/dist/plugins/pg-session-store.js +10 -0
- package/dist/plugins/pg-tool-result-store.d.ts +7 -0
- package/dist/plugins/pg-tool-result-store.js +7 -0
- package/dist/plugins/pg-workflow-journal-store.d.ts +7 -0
- package/dist/plugins/pg-workflow-journal-store.js +7 -0
- package/dist/plugins/pg-workflow-run-store.d.ts +7 -0
- package/dist/plugins/pg-workflow-run-store.js +7 -0
- package/dist/plugins/posix-shell-fs.d.ts +3 -0
- package/dist/plugins/posix-shell-fs.js +31 -1
- package/dist/plugins/remote-env-adb.d.ts +25 -0
- package/dist/plugins/remote-env-adb.js +95 -12
- package/dist/plugins/remote-env-e2b.d.ts +146 -0
- package/dist/plugins/remote-env-e2b.js +371 -40
- package/dist/plugins/remote-env-file-error.d.ts +34 -0
- package/dist/plugins/remote-env-file-error.js +37 -0
- package/dist/plugins/remote-env-host.d.ts +151 -0
- package/dist/plugins/remote-env-host.js +468 -70
- package/dist/plugins/remote-env-k8s.d.ts +135 -0
- package/dist/plugins/remote-env-k8s.js +318 -32
- package/dist/plugins/remote-env-local-docker.d.ts +65 -0
- package/dist/plugins/remote-env-local-docker.js +149 -24
- package/dist/plugins/remote-env-ssh.d.ts +35 -0
- package/dist/plugins/remote-env-ssh.js +117 -20
- package/dist/plugins/remote-scratchpad.d.ts +38 -0
- package/dist/plugins/remote-scratchpad.js +32 -2
- package/dist/plugins/remote-shell.d.ts +22 -0
- package/dist/plugins/remote-shell.js +27 -1
- package/dist/plugins/resume-anchor-store-sql.d.ts +28 -0
- package/dist/plugins/resume-anchor-store-sql.js +11 -0
- package/dist/plugins/roster-store-sql.d.ts +27 -0
- package/dist/plugins/roster-store-sql.js +54 -0
- package/dist/plugins/run-store-sql.d.ts +194 -0
- package/dist/plugins/run-store-sql.js +210 -9
- package/dist/plugins/s3-presign.d.ts +20 -0
- package/dist/plugins/s3-presign.js +49 -2
- package/dist/plugins/scheduler-support.d.ts +12 -0
- package/dist/plugins/scheduler-support.js +75 -3
- package/dist/plugins/send-file-ledger.d.ts +15 -0
- package/dist/plugins/send-file-ledger.js +53 -4
- package/dist/plugins/send-user-file.d.ts +77 -0
- package/dist/plugins/send-user-file.js +92 -4
- package/dist/plugins/session-policy-store-sql.d.ts +15 -0
- package/dist/plugins/session-policy-store-sql.js +75 -3
- package/dist/plugins/session-store.d.ts +45 -0
- package/dist/plugins/session-store.js +51 -0
- package/dist/plugins/sql-driver.d.ts +77 -0
- package/dist/plugins/sql-driver.js +4 -0
- package/dist/plugins/sql-escape.d.ts +8 -0
- package/dist/plugins/sql-escape.js +8 -0
- package/dist/plugins/sql-row-helpers.d.ts +25 -0
- package/dist/plugins/sql-row-helpers.js +25 -0
- package/dist/plugins/store-backend.d.ts +103 -0
- package/dist/plugins/store-backend.js +120 -27
- package/dist/plugins/store-contracts.d.ts +62 -0
- package/dist/plugins/store-contracts.js +3 -0
- package/dist/plugins/task-attachment-store.d.ts +60 -0
- package/dist/plugins/task-attachment-store.js +49 -3
- package/dist/plugins/task-list-store-sql.d.ts +25 -0
- package/dist/plugins/task-list-store-sql.js +21 -0
- package/dist/plugins/tidb-approval-store.d.ts +6 -0
- package/dist/plugins/tidb-approval-store.js +6 -0
- package/dist/plugins/tidb-breaker-state.d.ts +5 -0
- package/dist/plugins/tidb-breaker-state.js +5 -0
- package/dist/plugins/tidb-checkpoint-store.d.ts +7 -0
- package/dist/plugins/tidb-checkpoint-store.js +7 -0
- package/dist/plugins/tidb-cost-quota.d.ts +6 -0
- package/dist/plugins/tidb-cost-quota.js +1 -0
- package/dist/plugins/tidb-file-snapshot-store.d.ts +6 -0
- package/dist/plugins/tidb-file-snapshot-store.js +6 -0
- package/dist/plugins/tidb-image-bake.d.ts +8 -0
- package/dist/plugins/tidb-image-bake.js +8 -0
- package/dist/plugins/tidb-image-index.d.ts +8 -0
- package/dist/plugins/tidb-image-index.js +8 -0
- package/dist/plugins/tidb-outcome-ledger.d.ts +10 -0
- package/dist/plugins/tidb-outcome-ledger.js +10 -0
- package/dist/plugins/tidb-pool.d.ts +56 -0
- package/dist/plugins/tidb-pool.js +181 -1
- package/dist/plugins/tidb-rate-limiter.d.ts +11 -0
- package/dist/plugins/tidb-rate-limiter.js +5 -2
- package/dist/plugins/tidb-resume-anchor-store.d.ts +5 -0
- package/dist/plugins/tidb-resume-anchor-store.js +5 -0
- package/dist/plugins/tidb-run-store.d.ts +7 -0
- package/dist/plugins/tidb-run-store.js +7 -0
- package/dist/plugins/tidb-session-policy-store.d.ts +5 -0
- package/dist/plugins/tidb-session-policy-store.js +5 -0
- package/dist/plugins/tidb-session-storage.d.ts +43 -0
- package/dist/plugins/tidb-session-storage.js +62 -3
- package/dist/plugins/tidb-session-store.d.ts +142 -0
- package/dist/plugins/tidb-session-store.js +264 -16
- package/dist/plugins/tidb-tool-result-store.d.ts +5 -0
- package/dist/plugins/tidb-tool-result-store.js +7 -0
- package/dist/plugins/tidb-workflow-journal-store.d.ts +7 -0
- package/dist/plugins/tidb-workflow-journal-store.js +7 -0
- package/dist/plugins/tidb-workflow-run-store.d.ts +8 -0
- package/dist/plugins/tidb-workflow-run-store.js +8 -0
- package/dist/plugins/tool-result-store-sql.d.ts +58 -0
- package/dist/plugins/tool-result-store-sql.js +38 -2
- package/dist/plugins/web-search.d.ts +35 -0
- package/dist/plugins/web-search.js +45 -9
- package/dist/plugins/workflow-journal-limits.d.ts +10 -0
- package/dist/plugins/workflow-journal-limits.js +10 -0
- package/dist/plugins/workflow-journal-store-sql.d.ts +78 -0
- package/dist/plugins/workflow-journal-store-sql.js +58 -2
- package/dist/plugins/workflow-run-store-sql.d.ts +84 -0
- package/dist/plugins/workflow-run-store-sql.js +84 -6
- package/dist/plugins/worktree-isolation.d.ts +45 -0
- package/dist/plugins/worktree-isolation.js +105 -6
- package/dist/plugins/write-behind-counter.d.ts +56 -1
- package/dist/plugins/write-behind-counter.js +53 -14
- package/dist/principal-jwt.d.ts +24 -0
- package/dist/principal-jwt.js +60 -5
- package/dist/project-memory.d.ts +22 -0
- package/dist/project-memory.js +144 -15
- package/dist/prompts-domain-validate.d.ts +28 -0
- package/dist/prompts-domain-validate.js +42 -1
- package/dist/question.d.ts +33 -0
- package/dist/question.js +69 -2
- package/dist/resource-suspend.d.ts +21 -0
- package/dist/resource-suspend.js +16 -0
- package/dist/router/route-orchestration.d.ts +78 -0
- package/dist/router/route-orchestration.js +77 -0
- package/dist/run-local.d.ts +32 -0
- package/dist/run-local.js +172 -8
- package/dist/runs.d.ts +189 -4
- package/dist/runs.js +465 -24
- package/dist/runtime-caps-resolver.d.ts +106 -0
- package/dist/runtime-caps-resolver.js +89 -4
- package/dist/runtime-governance.d.ts +84 -0
- package/dist/runtime-governance.js +127 -1
- package/dist/sandbox-pkg-source.d.ts +23 -0
- package/dist/sandbox-pkg-source.js +37 -0
- package/dist/sealed-key.d.ts +54 -0
- package/dist/sealed-key.js +68 -3
- package/dist/security.d.ts +108 -0
- package/dist/security.js +145 -6
- package/dist/sema-registry.d.ts +21 -0
- package/dist/sema-registry.js +21 -0
- package/dist/session-leaf-bus.d.ts +31 -0
- package/dist/session-leaf-bus.js +32 -0
- package/dist/session-sync-content.d.ts +46 -0
- package/dist/session-sync-content.js +47 -1
- package/dist/session-sync-kernel.d.ts +89 -0
- package/dist/session-sync-kernel.js +48 -3
- package/dist/session-sync.d.ts +125 -0
- package/dist/session-sync.js +181 -8
- package/dist/session-titler.d.ts +26 -0
- package/dist/session-titler.js +41 -7
- package/dist/session-watch.d.ts +53 -1
- package/dist/session-watch.js +73 -9
- package/dist/sighup-idle.d.ts +30 -0
- package/dist/sighup-idle.js +12 -1
- package/dist/spec-fields.d.ts +91 -3
- package/dist/spec-fields.js +116 -4
- package/dist/task-cwd.d.ts +50 -0
- package/dist/task-cwd.js +68 -1
- package/dist/task-mcp.d.ts +47 -0
- package/dist/task-mcp.js +29 -0
- package/dist/task-settings.d.ts +175 -0
- package/dist/task-settings.js +226 -11
- package/dist/task-workflow.d.ts +67 -0
- package/dist/task-workflow.js +75 -8
- package/dist/tool-approval.d.ts +91 -0
- package/dist/tool-approval.js +215 -0
- package/dist/trace/artifacts.d.ts +9 -0
- package/dist/trace/artifacts.js +30 -5
- package/dist/trace/core-keyset-guard.d.ts +18 -0
- package/dist/trace/ledger-sink.d.ts +43 -0
- package/dist/trace/ledger-sink.js +64 -5
- package/dist/trace/project.d.ts +133 -0
- package/dist/trace/project.js +189 -2
- package/dist/trace/redact.d.ts +19 -0
- package/dist/trace/redact.js +66 -9
- package/dist/usage-analytics.d.ts +26 -0
- package/dist/usage-analytics.js +26 -3
- package/package.json +1 -1
package/dist/trace/project.js
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
import { redactSecrets, redactDeep } from "./redact.js";
|
|
2
|
+
/** E8 (shell-host): drain the per-task model-usage accumulator into an append-only `model_usage` DELTA event.
|
|
3
|
+
* Shared by BOTH durable-write legs (runInBackground + the resume leg) so the persisted shape never drifts; the
|
|
4
|
+
* append-only deltas make a suspended/resumed run's total resume-safe (each leg appends its own, the echo sums). */
|
|
2
5
|
export async function appendModelUsageDelta(append, modelUsage, taskId) {
|
|
3
6
|
const delta = modelUsage?.drain(taskId);
|
|
4
7
|
if (delta)
|
|
5
8
|
await append("model_usage", { usage: delta });
|
|
6
9
|
}
|
|
10
|
+
/** [998]② drain the pending prompt-manifest records (whitelisted at RECORD time, budget.ts — ids/digests/
|
|
11
|
+
* counts only, no prompt bodies by core's manifest contract) into durable `prompt_assembled` events, one per
|
|
12
|
+
* prepare IN EMISSION ORDER (a cascade/verify leg re-prepares under one taskId — every rung's manifest
|
|
13
|
+
* persists; release-review finding). Shared by both durable-write legs; a no-op when nothing is pending
|
|
14
|
+
* (one Map.get), so callers fire it liberally. */
|
|
7
15
|
export async function appendPromptManifest(append, tracker, taskId) {
|
|
8
16
|
const records = tracker?.drain(taskId);
|
|
9
17
|
if (records)
|
|
10
18
|
for (const m of records)
|
|
11
19
|
await append("prompt_assembled", m);
|
|
20
|
+
// [1301]③:config.assembled 同拍同门落 durable(config_assembled 事件)——与 prompt_assembled 完全同
|
|
21
|
+
// 生命周期(register 门/lease clear/所有 drain 落点自动覆盖:bg 首跑、resume 两径、verify 径);
|
|
22
|
+
// 逐条保序(codex F2:cascade 每 rung 的生效配置各自成帧,与其 prompt manifest 可配对)。
|
|
12
23
|
const cfgs = tracker?.drainConfig?.(taskId);
|
|
13
24
|
if (cfgs)
|
|
14
25
|
for (const cfg of cfgs)
|
|
15
26
|
await append("config_assembled", cfg);
|
|
16
27
|
}
|
|
28
|
+
/** E8: at a TERMINAL done — flush the final delta, then SUM all `model_usage` events (every process leg) into the
|
|
29
|
+
* result's `stats.modelUsage` echo. Returns the result unchanged when no usage was tracked (shell soft-degrades). */
|
|
17
30
|
export async function attachModelUsage(result, ctx) {
|
|
18
31
|
if (!ctx.modelUsage)
|
|
19
32
|
return result;
|
|
@@ -23,6 +36,10 @@ export async function attachModelUsage(result, ctx) {
|
|
|
23
36
|
return result;
|
|
24
37
|
return { ...result, stats: { ...result.stats, modelUsage: usage } };
|
|
25
38
|
}
|
|
39
|
+
/** E8 (shell-host contract): SUM the per-turn `model_usage` delta events in a run's durable event log into the
|
|
40
|
+
* cumulative per-model total for `TaskStats.modelUsage`. The tracer drains deltas at each turn boundary
|
|
41
|
+
* (append-only) → this is resume-safe: it sums across ALL process legs of a suspended/resumed run. Returns
|
|
42
|
+
* undefined when the run logged no model usage (→ the shell soft-degrades to aggregate cost only). */
|
|
26
43
|
export function aggregateModelUsage(events) {
|
|
27
44
|
const total = {};
|
|
28
45
|
let any = false;
|
|
@@ -45,15 +62,31 @@ export function aggregateModelUsage(events) {
|
|
|
45
62
|
}
|
|
46
63
|
return any ? total : undefined;
|
|
47
64
|
}
|
|
65
|
+
/** Identity fields core stamps on each content event (1.121.0 `TaskEventIdentity`, shell-host contract E2):
|
|
66
|
+
* `eventId` (core-mint uuidv7, the stable handle for dedup / the E18 resume-at anchor) + `parentToolCallId`
|
|
67
|
+
* (present only when the run is a sub-agent task spawned under a parent tool call). Both additive / tolerate-absent. */
|
|
48
68
|
function identityFields(src) {
|
|
49
69
|
return {
|
|
50
70
|
...(src.eventId ? { eventId: String(src.eventId) } : {}),
|
|
51
71
|
...(src.parentToolCallId ? { parentToolCallId: String(src.parentToolCallId) } : {}),
|
|
52
72
|
};
|
|
53
73
|
}
|
|
74
|
+
/** The durable `tool_start` event payload, shared by BOTH append sites (runInBackground + the resume leg) so the
|
|
75
|
+
* persisted shape never drifts: redacted args (UNTRUSTED) + E2 identity. `label`([1543]§三族B:durable 腿
|
|
76
|
+
* 此前剥掉——同一 run live 观看有展示名、replay/resume 退化成 wire 名):core 展示名 verbatim(tail 面
|
|
77
|
+
* 1.251 复审同裁,两腿同处理)。 */
|
|
54
78
|
export function toolStartEventData(ev) {
|
|
55
79
|
return { toolCallId: ev.toolCallId, toolName: ev.toolName, ...(ev.label !== undefined ? { label: ev.label } : {}), args: redactDeep(ev.args), ...identityFields(ev) };
|
|
56
80
|
}
|
|
81
|
+
/** The durable `tool_end` payload (shared by both append sites). E1: the model-facing `output` is UNTRUSTED RAW
|
|
82
|
+
* from core (file/shell/API bodies) — core only SIZE-bounds it (`truncated`), REDACTION is ours (same contract as
|
|
83
|
+
* `tool_start.args`); never re-fed to a model. E2: identity. Absent `output` ⇒ the tool produced no content body.
|
|
84
|
+
* core 1.203: `structured` = the tool's CC-shaped `details` card (edit/create/bash/… — core
|
|
85
|
+
* allowlists the card `type` and size-caps the whole card, omit-whole on overflow, so a subagent's child-TaskResult
|
|
86
|
+
* can never appear here) — SAME UNTRUSTED RAW contract as `output` (a card carries `originalFile`/stdout bodies),
|
|
87
|
+
* so it gets the same deep redaction before it is persisted or echoed. `label`(core 展示名,同 tool_start 的
|
|
88
|
+
* label 待遇 verbatim)白名单排查(2026-07-24)补齐进函数本体——此前外包给调用点各自手动拼接,7 处只有
|
|
89
|
+
* 3 处记得拼,resume leg + ledger-sink 落盘两处漏了,持久化记录本身缺 label 一写盘就永久追不回来。 */
|
|
57
90
|
export function toolEndEventData(ev) {
|
|
58
91
|
return {
|
|
59
92
|
toolCallId: ev.toolCallId,
|
|
@@ -62,41 +95,95 @@ export function toolEndEventData(ev) {
|
|
|
62
95
|
isError: ev.isError,
|
|
63
96
|
...(ev.output !== undefined ? { output: redactDeep(ev.output) } : {}),
|
|
64
97
|
...(ev.truncated ? { truncated: true } : {}),
|
|
98
|
+
// core 1.442([1898] RB-210):截断诚实体量(各 block 真实大小之和,不含 JSON 包装开销)。
|
|
65
99
|
...(Number.isFinite(ev.totalChars) ? { totalChars: ev.totalChars } : {}),
|
|
66
100
|
...(ev.structured !== undefined ? { structured: redactDeep(ev.structured) } : {}),
|
|
67
101
|
...identityFields(ev),
|
|
68
102
|
};
|
|
69
103
|
}
|
|
104
|
+
/** The `task_progress` payload (a subagent's live progress tick) — EXPLICIT WHITELIST shared by all
|
|
105
|
+
* three legs (bg runs.ts + resume append + the sync live SSE frame): taskId/parent linkage/token rollup verbatim,
|
|
106
|
+
* `name` UNTRUSTED (core sanitizes for rendering, does NOT secret-redact — a taskName can be secret-shaped) →
|
|
107
|
+
* `redactSecrets`. Never the delegated objective/args. E2 identity rides (eventId/
|
|
108
|
+
* parentToolCallId are core-mint uuidv7 identifiers, not content — consumers bind concurrent subagent ticks
|
|
109
|
+
* exactly by them; the 1.72 whitelist dropped them, leaving a FIFO heuristic). */
|
|
70
110
|
export function taskProgressEventData(ev) {
|
|
71
111
|
return {
|
|
72
112
|
taskId: ev.taskId,
|
|
73
113
|
...(ev.parentTaskId ? { parentTaskId: ev.parentTaskId } : {}),
|
|
74
114
|
...(ev.name ? { name: redactSecrets(ev.name) } : {}),
|
|
115
|
+
// core [1414]#3 settle 终态 tick("completed"/"failed"——[1543]§三族B:此前被剥,消费方只见最后
|
|
116
|
+
// 一拍 running 后行消失,恰是该 tick 要修的体验)。core enum verbatim。
|
|
75
117
|
...(ev.status !== undefined ? { status: ev.status } : {}),
|
|
76
118
|
...(ev.usage ? { usage: ev.usage } : {}),
|
|
119
|
+
// core 1.262.0: the child's most recent tool intent as one human line ("Bash npm
|
|
120
|
+
// test") — derived from the child's tool_start (tool name + argument head), so the ARGUMENT part is
|
|
121
|
+
// UNTRUSTED free text (a command line can be secret-shaped) → `redactSecrets`, same boundary as `name`.
|
|
77
122
|
...(ev.currentAction ? { currentAction: redactSecrets(ev.currentAction) } : {}),
|
|
123
|
+
// core 1.401.0([1611]→[1616]/[1617] 方案 B):后台 workflow 子代的 tick additive 带这两个字段,
|
|
124
|
+
// 让下游(cli)能把这条前台裸 uuid 行识别为"fleet 那边已有一份"从而跳过重复渲染。workflowRunId 是
|
|
125
|
+
// core-mint 的不透明 run id(不含用户内容)→ 同 identityFields 待遇直传;workflowAgentLabel 是脚本
|
|
126
|
+
// 作者可控的展示字符串(UNTRUSTED,同 name 的信任边界)→ redactSecrets。
|
|
78
127
|
...(ev.workflowRunId ? { workflowRunId: ev.workflowRunId } : {}),
|
|
79
128
|
...(ev.workflowAgentLabel ? { workflowAgentLabel: redactSecrets(ev.workflowAgentLabel) } : {}),
|
|
80
129
|
...identityFields(ev),
|
|
81
130
|
};
|
|
82
131
|
}
|
|
132
|
+
/** The `task_notification` payload (core 1.202 design/115 P2: a background task finished — this event is the
|
|
133
|
+
* LEDGER/display projection of the OBSERVED terminal state, emitted the moment core observes it. It does NOT
|
|
134
|
+
* attest that the `<task-notification>` XML has entered the model context: core's steer targets the NEXT TURN
|
|
135
|
+
* BOUNDARY (design/116 §7 — turn 在飞时不注入), so the frame can precede actual injection by minutes ([1818]
|
|
136
|
+
* clay live: 3m54s; the previous wording here — "core already injected in-process" — was the same wrong
|
|
137
|
+
* assumption that broke the shell's dedup). `injected: false` says exactly that on the wire: a consumer must
|
|
138
|
+
* NOT treat this frame as an echo of model-context injection. EXPLICIT WHITELIST (never `{...ev}` — the 1.72 task_progress lesson: a
|
|
139
|
+
* future core field must not ride raw): ids/status/usage verbatim; `summary`/`result`/`output_file` are UNTRUSTED
|
|
140
|
+
* free text (core bounds+sanitizes for XML, does NOT secret-redact) → `redactSecrets` at OUR wire boundary. Shared
|
|
141
|
+
* by all three legs (bg runs.ts + resume append + the sync live SSE frame) so the shape never drifts. Takes the
|
|
142
|
+
* EVENT (not just the payload) so the E2 identity fields core stamps on it (eventId/parentToolCallId) ride the
|
|
143
|
+
* frame like every other content event (review round 2: the payload-only version silently dropped them). */
|
|
83
144
|
export function taskNotificationEventData(ev) {
|
|
84
145
|
const n = ev.notification;
|
|
85
146
|
return {
|
|
147
|
+
// [1818]§四 (b)案:显式判别位 —— 本帧=台账观测,不证已入模型上下文(见 docstring)。恒 false 是
|
|
148
|
+
// 如实声明:server 观测不到 core 的 turn 边界注入时刻;若未来 core 给出注入回声 seam,echo 帧以
|
|
149
|
+
// injected:true 骑同帧族。
|
|
86
150
|
injected: false,
|
|
87
151
|
task_id: n.task_id,
|
|
88
152
|
task_type: n.task_type,
|
|
153
|
+
// core 1.238: the child's sessionId — the stable a*↔uuid cross-system anchor (the killed
|
|
154
|
+
// receipt renders off summary+sessionId). Optional (bash lane has none).
|
|
89
155
|
...(n.sessionId !== undefined ? { sessionId: n.sessionId } : {}),
|
|
90
156
|
...(n.toolUseId !== undefined ? { toolUseId: n.toolUseId } : {}),
|
|
91
157
|
status: n.status,
|
|
158
|
+
// The design/135 Monitor + design/134 stoppedBy fields were MISSING
|
|
159
|
+
// from this whitelist — the shell had no dedup discriminator (`seq` is what keeps successive Monitor event
|
|
160
|
+
// batches from collapsing into one, per core's taskNotificationDedupKey) and no batched line text / stop
|
|
161
|
+
// attribution. `seq` is a core counter (verbatim); `lines` is watched-process stdout = UNTRUSTED free text
|
|
162
|
+
// (redact each line, same boundary as result); `stoppedBy` is core's OPEN enum (verbatim string — consumers
|
|
163
|
+
// tolerate unknown values by contract).
|
|
92
164
|
...(n.seq !== undefined ? { seq: n.seq } : {}),
|
|
93
165
|
...(n.lines !== undefined ? { lines: n.lines.map((l) => redactSecrets(l)) } : {}),
|
|
94
166
|
...(n.stoppedBy !== undefined ? { stoppedBy: n.stoppedBy } : {}),
|
|
167
|
+
// P1-3(core 1.452):完成幂等锚 verbatim(消费端跨通路去重;[1925] 一轮批)。
|
|
95
168
|
...(n.completionId !== undefined ? { completionId: n.completionId } : {}),
|
|
169
|
+
// [1543]§二 server①:白名单滞后 core payload 四键补齐——
|
|
170
|
+
// source:external 通知来源标(caller 供 = UNTRUSTED)→ redactSecrets;
|
|
171
|
+
// exitCode:数值 verbatim(bash 腿);
|
|
172
|
+
// partial:boolean verbatim——**killed 残果诚实标**(缺它 cli 把残果渲染得像完整结果,core
|
|
173
|
+
// 特意打的标到不了用户面,本键是四键里的主案);
|
|
174
|
+
// diagnostics:[1409] 教学文本 = UNTRUSTED 自由文本 → redactSecrets。
|
|
96
175
|
...(n.source !== undefined ? { source: redactSecrets(n.source) } : {}),
|
|
97
176
|
...(n.exitCode !== undefined ? { exitCode: n.exitCode } : {}),
|
|
98
177
|
...(n.partial !== undefined ? { partial: n.partial } : {}),
|
|
99
178
|
...(n.diagnostics !== undefined ? { diagnostics: redactSecrets(n.diagnostics) } : {}),
|
|
179
|
+
// core 1.262.0 五个补面——additive passthrough, same posture as
|
|
180
|
+
// lines/stoppedBy above. Fields PICKED (never spread — a future core field must not ride raw):
|
|
181
|
+
// recentSteps: `tool` = core tool name (verbatim); `target` (file path / command / pattern) and
|
|
182
|
+
// `outcome` (tool result first line) are UNTRUSTED free text (a command or output line can be
|
|
183
|
+
// secret-shaped) → `redactSecrets`, same boundary as `result`/`lines`. Bounded upstream (≤10).
|
|
184
|
+
// editedFiles: `path` is engine working-file derived but still crosses our wire → `redactSecrets`
|
|
185
|
+
// (the compacted attachedFiles posture); `edits` numeric verbatim.
|
|
186
|
+
// resumable: core boolean verbatim (E — parent decides continue-vs-restart without trial-and-error).
|
|
100
187
|
...(n.recentSteps !== undefined
|
|
101
188
|
? { recentSteps: n.recentSteps.map((s) => ({ tool: s.tool, target: redactSecrets(s.target), outcome: redactSecrets(s.outcome) })) }
|
|
102
189
|
: {}),
|
|
@@ -109,6 +196,18 @@ export function taskNotificationEventData(ev) {
|
|
|
109
196
|
...identityFields(ev),
|
|
110
197
|
};
|
|
111
198
|
}
|
|
199
|
+
/** The `compacted` payload — EXPLICIT WHITELIST shared by all three legs (bg runs.ts + resume append + the sync
|
|
200
|
+
* live SSE frame; the 1.72 task_progress lesson: never `{...ev}`). trigger/tokensBefore (MF-18) verbatim;
|
|
201
|
+
* `preserved_segment.firstKeptEntryId` verbatim (a core-mint entryId, the shell's compaction-divider anchor);
|
|
202
|
+
* core 1.219 `attachedFiles` (attachWorkingFiles default-ON — the shell renders CC's post-compact `Read {path}`
|
|
203
|
+
* cards from it): `path` is the engine's own working-file path (env-derived, not free text) but still crosses our
|
|
204
|
+
* wire → `redactSecrets` (a project path can embed a secret-shaped dir name); chars/truncated are numeric/bool
|
|
205
|
+
* verbatim. Absent fields stay absent (feature off / nothing attached / no kept-tail floor). */
|
|
206
|
+
/** The `diagnostics` payload (core 1.220 design/121 — NEW LSP diagnostics drained at a turn boundary; the model
|
|
207
|
+
* already got the `<new-diagnostics>` context message in-process, this frame is the shell's render source).
|
|
208
|
+
* EXPLICIT WHITELIST shared by all three legs. UNTRUSTED RAW (§E1: language-server output over workspace files —
|
|
209
|
+
* a diagnostic message can quote file content, a secret-shaped uri/source is possible) → `redactSecrets` on the
|
|
210
|
+
* string fields; severity/range/code numbers verbatim. E2 identity rides. */
|
|
112
211
|
export function diagnosticsEventData(ev) {
|
|
113
212
|
return {
|
|
114
213
|
files: (Array.isArray(ev.files) ? ev.files : []).map((f) => ({
|
|
@@ -125,6 +224,11 @@ export function diagnosticsEventData(ev) {
|
|
|
125
224
|
...identityFields(ev),
|
|
126
225
|
};
|
|
127
226
|
}
|
|
227
|
+
/** The `steering_injected` payload([1550]/[1552] 裁定透传;core `TaskEvent` 联合臂 `type: "steering_injected"`,
|
|
228
|
+
* shell 渲染源 = CC 的系统提醒条:core 在 turn 之间给模型注入一条系统提示[todo 提醒/文件变化/日期跨天/
|
|
229
|
+
* 技能列表变化…]时随手抛的展示投影,一附件一帧)。EXPLICIT WHITELIST(source=封闭枚举 verbatim;
|
|
230
|
+
* preview=注入文本的展示摘录,UNTRUSTED[core 未做秘密脱敏]→ `redactSecrets`)。共享三腿(sync 实时 SSE +
|
|
231
|
+
* bg/resume 落账,ledger-sink 同门)。 */
|
|
128
232
|
export function steeringInjectedEventData(ev) {
|
|
129
233
|
return {
|
|
130
234
|
source: String(ev.source),
|
|
@@ -132,12 +236,22 @@ export function steeringInjectedEventData(ev) {
|
|
|
132
236
|
...identityFields(ev),
|
|
133
237
|
};
|
|
134
238
|
}
|
|
239
|
+
/** The `workspace_changed` payload([1559]二 core 裁定:design/99 §E13 旧臂,L1 门本车首次撞见——非新增,
|
|
240
|
+
* 是本门扩 TaskEvent 臂集时第一次显式处置。语义 = bash `cd`/EnterWorktree 移动任务逻辑 cwd 后,在移动
|
|
241
|
+
* 它的工具结算后发一帧,给 shell/宿主 UI 一个路径提示行。cwd 与已展示的工具 args 同信任级[UNTRUSTED,
|
|
242
|
+
* RAW 逻辑路径,symlink 不解析]→ `redactSecrets` + 长度 bound[300,与 brainStatusEventData.detail 同
|
|
243
|
+
* 惯例]。core 只在真变化时才发(不播初始 cwd);渲染面(cli)不得当持久态——跨 suspend/resume 重置为
|
|
244
|
+
* 根,这是消费端纪律,服务端只如实转发单帧不做状态缓存。 */
|
|
135
245
|
export function workspaceChangedEventData(ev) {
|
|
136
246
|
return {
|
|
137
247
|
cwd: redactSecrets(String(ev.cwd)).slice(0, 300),
|
|
138
248
|
...identityFields(ev),
|
|
139
249
|
};
|
|
140
250
|
}
|
|
251
|
+
/** S4 (SILENT-FALLBACK P0-a): the durable `brain_status` observation row, shared by the bg + resume append
|
|
252
|
+
* sites. core marks the live `status` frame EPHEMERAL (never replayed by core on resume) — this row is the
|
|
253
|
+
* SERVICE's own observation record (why a turn stalled: rate_limited/retrying/reconnecting/circuit_open),
|
|
254
|
+
* not a core event replay. Whitelist: the closed phase union + neutral bounded detail (redacted) + retryInSec. */
|
|
141
255
|
export function brainStatusEventData(ev) {
|
|
142
256
|
return {
|
|
143
257
|
phase: String(ev.phase),
|
|
@@ -147,7 +261,12 @@ export function brainStatusEventData(ev) {
|
|
|
147
261
|
};
|
|
148
262
|
}
|
|
149
263
|
export function compactedEventData(ev) {
|
|
264
|
+
// Bounded-numeric guard for the 1.289 additive scalars: finite numbers verbatim, anything else absent
|
|
265
|
+
// (whitelist discipline — a malformed field must not ride the wire, same class as the 1.72 lesson).
|
|
150
266
|
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
|
|
267
|
+
// core 1.289 `phaseDurations` (CompactionPhaseDurations: prepareMs/summaryMs?/persistMs/ptlRetries) — a
|
|
268
|
+
// CLOSED numeric struct rebuilt field-by-field (never `{...ev.phaseDurations}`: an unexpected extra key must
|
|
269
|
+
// not leak onto the wire); non-numeric members are dropped, an all-empty struct stays absent.
|
|
151
270
|
const phaseDurations = (() => {
|
|
152
271
|
const p = ev.phaseDurations;
|
|
153
272
|
if (!p || typeof p !== "object")
|
|
@@ -161,6 +280,14 @@ export function compactedEventData(ev) {
|
|
|
161
280
|
return Object.keys(out).length > 0 ? out : undefined;
|
|
162
281
|
})();
|
|
163
282
|
return {
|
|
283
|
+
// 🔴 2026-07-25:这三处此前**违反本函数注释自己写的那条不变量**(「畸形字段不得上线,与 1.72 同类」)——
|
|
284
|
+
// ① `trigger`/`tokensBefore` 是**裸赋值**:`tokensBefore` 为 `NaN` 时 `JSON.stringify` 把它变成 **`null`**,
|
|
285
|
+
// 于是压缩面板渲染成「压缩前 0 tokens」而不是「未知」;裸赋值还会留下 present-with-undefined 的键
|
|
286
|
+
// (JSON 会丢,但非 JSON 后端的进程内读者看得到)⇒ 统一走 `num()`/类型判据 + 条件 spread。
|
|
287
|
+
// ② `attachedFiles` 的元素**逐字段照抄**:一个畸形元素(如 `{}`)会被**造成**
|
|
288
|
+
// `{path:"undefined", chars:undefined, truncated:undefined}` —— 那是**编造值**,比丢弃更坏
|
|
289
|
+
// (下游看到一个叫 "undefined" 的文件路径)。改成**逐元素校验后丢弃畸形项**,全丢光则整键省略
|
|
290
|
+
// (与既有的 `length > 0` 同口径)。
|
|
164
291
|
...(typeof ev.trigger === "string" ? { trigger: ev.trigger } : {}),
|
|
165
292
|
...(num(ev.tokensBefore) !== undefined ? { tokensBefore: num(ev.tokensBefore) } : {}),
|
|
166
293
|
...(ev.preserved_segment?.firstKeptEntryId ? { preserved_segment: { firstKeptEntryId: ev.preserved_segment.firstKeptEntryId } } : {}),
|
|
@@ -173,16 +300,35 @@ export function compactedEventData(ev) {
|
|
|
173
300
|
.map((f) => ({ path: redactSecrets(f.path), chars: f.chars, truncated: f.truncated }));
|
|
174
301
|
return files.length > 0 ? { attachedFiles: files } : {};
|
|
175
302
|
})(),
|
|
303
|
+
// core 1.286 additive fields ([792]②b, design/145 compression batch): modelFallback/fallbackReason = the
|
|
304
|
+
// compaction summarizer fell back to a larger-window model; clampedRatio/clampReason = the keep ratio was
|
|
305
|
+
// clamped and why. Closed literal bool/enum/number — verbatim; absent stays absent.
|
|
176
306
|
...(ev.modelFallback === true ? { modelFallback: true } : {}),
|
|
177
307
|
...(ev.fallbackReason !== undefined ? { fallbackReason: ev.fallbackReason } : {}),
|
|
178
|
-
...(num(ev.clampedRatio) !== undefined ? { clampedRatio: num(ev.clampedRatio) } : {}),
|
|
308
|
+
...(num(ev.clampedRatio) !== undefined ? { clampedRatio: num(ev.clampedRatio) } : {}), // 同上:NaN 不得以 null 上线
|
|
179
309
|
...(ev.clampReason !== undefined ? { clampReason: ev.clampReason } : {}),
|
|
310
|
+
// core 1.289 additive fields (codex F7 — parity batch, same posture as [792]②b above): tokensAfter/
|
|
311
|
+
// triggerTokensBefore/durationMs are engine-derived scalars, verbatim when finite numbers; phaseDurations
|
|
312
|
+
// is the closed bounded struct built above. Absent stays absent on all three wire legs (bg runs.ts append,
|
|
313
|
+
// the resume append, and the sync live SSE frame — all funnel through THIS builder).
|
|
180
314
|
...(num(ev.tokensAfter) !== undefined ? { tokensAfter: num(ev.tokensAfter) } : {}),
|
|
181
315
|
...(num(ev.triggerTokensBefore) !== undefined ? { triggerTokensBefore: num(ev.triggerTokensBefore) } : {}),
|
|
182
316
|
...(num(ev.durationMs) !== undefined ? { durationMs: num(ev.durationMs) } : {}),
|
|
183
317
|
...(phaseDurations !== undefined ? { phaseDurations } : {}),
|
|
184
318
|
};
|
|
185
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* `context_usage` 的白名单投影(core 1.414 新增一等 `TaskEvent` 分支;server [1669]⑥ 点名要的上下文用量面)。
|
|
322
|
+
*
|
|
323
|
+
* 🔴 两条 core 明确交代的口径,必须原样传下去、不要在服务端"聪明地"重算:
|
|
324
|
+
* · `usedTokens > compactAtTokens` **就是引擎自己喂 `shouldCompact` 的谓词** —— 消费方直接用,别重新推导阈值。
|
|
325
|
+
* · `windowTokens` 是 **autocompact 窗**,**不是**「模型上下文大小」(模型声明 `autoCompactTokens` 时物理请求
|
|
326
|
+
* 窗更大)。渲染成"模型上下文"会给用户一个错的分母。
|
|
327
|
+
* ⚠️ 它在**每个压缩边界**上报(不只压缩真发生时),所以一次任务里会有多条 —— 消费方按最后一条取当前值。
|
|
328
|
+
* ⚠️ 它**没有**挂在 `turn_end.usage` 上(core 解释:边界检查跑在 turn_end 之后、对 flush 后的消息集,
|
|
329
|
+
* 挂那儿会是"另一次更早的测量顶着同一个名字")。去 turn_end 找是找不到的。
|
|
330
|
+
* 三个字段都是引擎派生的有限数标量 ⇒ 走 finite 门(与 compacted 的 1.289 标量同姿势),非有限即缺席。
|
|
331
|
+
*/
|
|
186
332
|
export function contextUsageEventData(ev) {
|
|
187
333
|
const n = (v) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
|
|
188
334
|
return {
|
|
@@ -191,6 +337,15 @@ export function contextUsageEventData(ev) {
|
|
|
191
337
|
...(n(ev.compactAtTokens) !== undefined ? { compactAtTokens: n(ev.compactAtTokens) } : {}),
|
|
192
338
|
};
|
|
193
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* `turn_end` 的白名单投影 —— 🔴 2026-07-25 补:`turn_end` 此前是**唯一没有 builder 的内容臂**,两条持久化点
|
|
342
|
+
* (ledger-sink 与 resume 腿)各自手写 `{ usage }`,于是 core 的另两个字段被静默剥掉:
|
|
343
|
+
* · `stopReason` —— **这一轮为什么停**(max_tokens / stop_sequence / …);
|
|
344
|
+
* · `usageMissing: true` —— **用量不可信**的诚实标记。缺了它,"没有 usage"会被读成"用量是 0",
|
|
345
|
+
* 而不是"未知";这正是那种"回放后看起来一切正常"的丢失。
|
|
346
|
+
* 两者**在 live 腿看得见、durable 腿回放后永久消失** —— 与 [1622] 的 `label`、[1611] 的 workflowRunId 同一族
|
|
347
|
+
* (白名单没跟上 core 新增字段)。补 builder 的同时也就把它纳入了 `wire-whitelist-exhaustiveness` 的编译期差集门。
|
|
348
|
+
*/
|
|
194
349
|
export function turnEndEventData(ev) {
|
|
195
350
|
return {
|
|
196
351
|
...(ev.usage ? { usage: ev.usage } : {}),
|
|
@@ -198,6 +353,8 @@ export function turnEndEventData(ev) {
|
|
|
198
353
|
...(typeof ev.stopReason === "string" ? { stopReason: ev.stopReason } : {}),
|
|
199
354
|
};
|
|
200
355
|
}
|
|
356
|
+
/** Map core's `turn_end.usage` (1.76 / core [R59]: inputTokens/outputTokens/cacheReadTokens/cacheWriteTokens/
|
|
357
|
+
* costMicroUsd) → the contract's `TraceTurn.tokens {in,out,cacheRead?,cacheWrite?}`. Absent/empty → undefined. */
|
|
201
358
|
export function toContractTokens(usage) {
|
|
202
359
|
if (!usage || typeof usage !== "object")
|
|
203
360
|
return undefined;
|
|
@@ -211,6 +368,7 @@ export function toContractTokens(usage) {
|
|
|
211
368
|
...(u.cacheWriteTokens != null ? { cacheWrite: u.cacheWriteTokens } : {}),
|
|
212
369
|
};
|
|
213
370
|
}
|
|
371
|
+
/** Project a per-task event slice (seq-ascending) into ordered `TraceTurn[]`. Pure + total (never throws). */
|
|
214
372
|
export function projectEvents(events, opts = {}) {
|
|
215
373
|
const turns = [];
|
|
216
374
|
if (opts.objective) {
|
|
@@ -242,10 +400,16 @@ export function projectEvents(events, opts = {}) {
|
|
|
242
400
|
break;
|
|
243
401
|
case "tool_end": {
|
|
244
402
|
const callId = String(d.toolCallId ?? "");
|
|
403
|
+
// E1: output is read straight off the (already-redacted-at-append) event — no session join. Absent ⇒ undefined.
|
|
404
|
+
// `structured` (core 1.203 CC card) was redacted at APPEND (toolEndEventData) — passthrough on the read
|
|
405
|
+
// path so a cold-replay/turns consumer renders the same rich card the live wire carried (additive field).
|
|
245
406
|
blocks.push({ type: "tool-result", callId, ...(typeof d.label === "string" ? { label: d.label } : {}), output: d.output, ...(d.isError ? { isError: true } : {}), ...(d.truncated ? { truncated: true } : {}), ...(Number.isFinite(d.totalChars) ? { totalChars: d.totalChars } : {}), ...(d.structured !== undefined ? { structured: d.structured } : {}), ...identityFields(d) });
|
|
246
407
|
break;
|
|
247
408
|
}
|
|
248
409
|
case "prompt_assembled":
|
|
410
|
+
// [998]②: whitelisted at APPEND (budget.ts promptManifestRecordOf — ids/digests/counts only);
|
|
411
|
+
// passthrough on the read path (the `structured` posture). Lands ahead of the turn's first content
|
|
412
|
+
// block, so the "Prompt 组成" card renders at the top of the turn it prepared.
|
|
249
413
|
firstTs ??= ev.ts;
|
|
250
414
|
blocks.push({
|
|
251
415
|
type: "prompt-assembled",
|
|
@@ -259,14 +423,17 @@ export function projectEvents(events, opts = {}) {
|
|
|
259
423
|
case "turn_end":
|
|
260
424
|
flushTurn(ev.seq, ev.ts, toContractTokens(d.usage));
|
|
261
425
|
break;
|
|
426
|
+
// compacted / done / suspended / failed are lifecycle, not turn output — status comes from the run record.
|
|
262
427
|
}
|
|
263
428
|
}
|
|
429
|
+
// A trailing in-progress turn (events after the last turn_end — e.g. a live task mid-turn).
|
|
264
430
|
if (blocks.length > 0) {
|
|
265
431
|
const last = events[events.length - 1];
|
|
266
432
|
flushTurn(last.seq, last.ts);
|
|
267
433
|
}
|
|
268
434
|
return turns;
|
|
269
435
|
}
|
|
436
|
+
/** Structured `lastStep` (contract 2.1) from the latest event — UI maps an icon, never free text. */
|
|
270
437
|
export function lastStep(latestEventType, status) {
|
|
271
438
|
if (status !== "running")
|
|
272
439
|
return { type: "idle" };
|
|
@@ -281,6 +448,8 @@ export function lastStep(latestEventType, status) {
|
|
|
281
448
|
return { type: "responding" };
|
|
282
449
|
}
|
|
283
450
|
}
|
|
451
|
+
/** A run record → the cheap list summary (contract 2.1). Token/cost/turns come from the terminal result.stats;
|
|
452
|
+
* scenario isn't denormalized on the run row (omitted — a later push-index/column refinement). */
|
|
284
453
|
export function taskSummary(run, latestEventType) {
|
|
285
454
|
const stats = (run.result?.stats ?? {});
|
|
286
455
|
const terminal = run.status !== "running";
|
|
@@ -299,9 +468,23 @@ export function taskSummary(run, latestEventType) {
|
|
|
299
468
|
lastStep: lastStep(latestEventType, run.status),
|
|
300
469
|
};
|
|
301
470
|
}
|
|
471
|
+
/** design/158 B2(lens4 N8)—— 重放边界的**读旧**归一:把历史账本里的 `brain_status` 行改叫 `status`。
|
|
472
|
+
*
|
|
473
|
+
* 同一条「大脑存活性」观测曾在两条腿上叫两个名字:live 腿(`POST /v1/tasks/stream`)发 `type:"status"`,
|
|
474
|
+
* durable 腿的账本行落 `brain_status`,而 SDK 的公开 `AgentEvent` 联合**只有** `status` —— 于是走
|
|
475
|
+
* `GET /v1/runs/:id/events` 的消费端会收到一个公开联合之外的帧(穷举式 closed-oneOf 消费者当场抛)。
|
|
476
|
+
*
|
|
477
|
+
* 写入侧已经改叫 `status`(ledger-sink.ts 与 resume 腿的 append 两处),但**存量行救不了**:任何
|
|
478
|
+
* <1.317 的部署账本里都躺着 `brain_status` 行,重放它们仍会漏出旧名。所以「写新」必须配一个「读旧」——
|
|
479
|
+
* 这个函数就是那个读边界,唯一调用点是 task_run SSE 的 `formatEvent`(routes/runs.ts)。
|
|
480
|
+
*
|
|
481
|
+
* 🔴 刻意**只**认这一个键,不做成映射表:帧名归一是历史包袱的一次性偿还,不是一条可以长胖的兼容层。
|
|
482
|
+
* 再有第二个名字对不齐,应当在源头修,而不是往这里加一行。 */
|
|
302
483
|
export function normalizeRunEventType(type) {
|
|
303
484
|
return type === "brain_status" ? "status" : type;
|
|
304
485
|
}
|
|
486
|
+
/** Map one durable event → a sema-registry SSE trace event (contract 2.3). null = not a client event. The
|
|
487
|
+
* durable log is block-grained, so each block ships as one "delta" the client appends (stream mode = "delta"). */
|
|
305
488
|
export function mapTraceEvent(type, seq, data) {
|
|
306
489
|
switch (type) {
|
|
307
490
|
case "reasoning":
|
|
@@ -311,21 +494,25 @@ export function mapTraceEvent(type, seq, data) {
|
|
|
311
494
|
case "tool_start":
|
|
312
495
|
return { event: "tool-call", data: { seq, id: data.toolCallId, name: data.toolName, ...(typeof data.label === "string" ? { label: data.label } : {}), input: data.args, ...identityFields(data) } };
|
|
313
496
|
case "tool_end":
|
|
497
|
+
// E1: output/truncated are already redacted+bounded at append; pass through. E2: identity additive.
|
|
314
498
|
return { event: "tool-result", data: { seq, callId: data.toolCallId, ...(typeof data.label === "string" ? { label: data.label } : {}), isError: Boolean(data.isError), ...(data.output !== undefined ? { output: data.output } : {}), ...(data.truncated ? { truncated: true } : {}), ...(Number.isFinite(data.totalChars) ? { totalChars: data.totalChars } : {}), ...(data.structured !== undefined ? { structured: data.structured } : {}), ...identityFields(data) } };
|
|
315
499
|
case "turn_end": {
|
|
316
500
|
const tokens = toContractTokens(data.usage);
|
|
317
501
|
return { event: "turn", data: { seq, ...(tokens ? { tokens } : {}) } };
|
|
318
502
|
}
|
|
319
503
|
case "prompt_assembled":
|
|
504
|
+
// [998]②: whitelisted at append (ids/digests/counts, no prompt bodies) — passthrough, own event name.
|
|
320
505
|
return { event: "prompt-assembled", data: { seq, ...data } };
|
|
321
506
|
case "done":
|
|
322
507
|
return { event: "done", data: { seq } };
|
|
323
508
|
case "suspended":
|
|
324
509
|
return { event: "done", data: { seq, suspended: true } };
|
|
325
510
|
case "failed":
|
|
511
|
+
// BL-13: redact at the read boundary too (defense-in-depth) — covers any errorMessage that reached the
|
|
512
|
+
// log un-redacted via another write path; idempotent on the BL-12-redacted catch-path message.
|
|
326
513
|
return { event: "error", data: { code: "WORKER_DOWN", message: redactSecrets(String(data.errorMessage ?? "run failed")) } };
|
|
327
514
|
default:
|
|
328
|
-
return null;
|
|
515
|
+
return null; // compacted etc. — not a client trace event
|
|
329
516
|
}
|
|
330
517
|
}
|
|
331
518
|
//# sourceMappingURL=project.js.map
|
package/dist/trace/redact.d.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
export declare function setRedactionObserver(fn: ((patternLabel: string, count: number) => void) | undefined): void;
|
|
2
2
|
export declare function redactSecrets(text: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* 🔴 环 + 深度预算(2026-07-25 补)。原实现是纯递归、**既不记已访问节点也不限深度**,而它的调用位置是
|
|
5
|
+
* **最不可信的边界**:`toolStart`/`toolEnd` 把工具的 `args`/`output`/`structured` 直接喂进来。后果两条:
|
|
6
|
+
* · **循环引用** ⇒ 无限递归 ⇒ `RangeError` **抛出构造函数**。在 sync 的 SSE 腿上那个 throw 就落在
|
|
7
|
+
* `for await (…) res.write(…)` 的循环里 ⇒ **一个畸形工具输出能打死一条正在跑的流**;在 ledger-sink 腿上
|
|
8
|
+
* 则是那一帧 append 直接失败(事件永久不落盘)。
|
|
9
|
+
* · 超深嵌套 ⇒ 同样爆栈。
|
|
10
|
+
* 同文件的 `redactedPreview` 的文档里早把这条记成"已复审的 MEDIUM"并**绕开** redactDeep ——
|
|
11
|
+
* 也就是说这个洞是知道的,只是没堵。现在堵在 redactDeep 本体:环与超深都换成**可见的标记**,
|
|
12
|
+
* 让下游看到"这里有东西被省略了",而不是丢一个空对象或炸掉整条流。
|
|
13
|
+
*/
|
|
3
14
|
export declare function redactDeep(value: unknown): unknown;
|
|
15
|
+
/**
|
|
16
|
+
* A REDACTED, length-BOUNDED string preview of a structured value — for surfacing a pending tool call's `args`
|
|
17
|
+
* in the assistant inbox ("what is this ask about") WITHOUT leaking secrets or dumping an unbounded payload (a
|
|
18
|
+
* write_file `content` can be megabytes). {@link redactDeep} scrubs secret-shaped strings first; the result is
|
|
19
|
+
* JSON-stringified and capped (truncation is marked). `null`/`undefined` → `null` (nothing to preview). Defense
|
|
20
|
+
* in depth: the redaction is conservative (NOT exhaustive — see {@link redactSecrets}); the inbox is already
|
|
21
|
+
* owner-scoped, so this preview is only ever shown to the ask's own principal (or an operator inspecting it).
|
|
22
|
+
*/
|
|
4
23
|
export declare function redactedPreview(value: unknown, cap?: number): string | null;
|
|
5
24
|
//# sourceMappingURL=redact.d.ts.map
|
package/dist/trace/redact.js
CHANGED
|
@@ -1,15 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trace thinking-block redaction (service-side). Per core [R57]: the agent's reasoning/CoT is emitted on the
|
|
3
|
+
* live TaskEvent stream but DELIBERATELY kept out of the metadata Tracer because CoT may contain reasoned-about
|
|
4
|
+
* secrets (and is large / ToS-sensitive for some providers). Persisting it for the trace UI is the deployment's
|
|
5
|
+
* call — so when we DO persist it, redact unambiguous secret formats first. Conservative on purpose: only clear
|
|
6
|
+
* key/token shapes are redacted. ⚠️ It is NOT exhaustive: unrecognised secret formats (a free-text password,
|
|
7
|
+
* a JWT) pass through, and the broad `Bearer <20+ chars>` rule can over-match legitimate CoT (false positives
|
|
8
|
+
* tolerated — over-redacting trace text is safe). For sensitive deployments, disable thinking capture entirely
|
|
9
|
+
* via TRACE_THINKING=false. This is a seam — deployments can extend the patterns.
|
|
10
|
+
*/
|
|
1
11
|
const SECRET_PATTERNS = [
|
|
2
|
-
[/-----BEGIN[^-]+PRIVATE KEY(?: BLOCK)?-----[\s\S]{0,8192}?-----END[^-]+PRIVATE KEY(?: BLOCK)?-----/g, "«redacted:private-key»"],
|
|
3
|
-
[/\bsk-[A-Za-z0-9_-]{16,}\b/g, "«redacted:key»"],
|
|
4
|
-
[/\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}\b/g, "«redacted:gh-token»"],
|
|
5
|
-
[/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g, "«redacted:slack-token»"],
|
|
6
|
-
[/\bAKIA[0-9A-Z]{16}\b/g, "«redacted:aws-key»"],
|
|
7
|
-
[/\b[Bb]earer\s+[A-Za-z0-9._~+/-]{20,}=*/g, "Bearer «redacted»"],
|
|
8
|
-
[/\bBasic\s+[A-Za-z0-9+/]{16,}={0,2}/g, "Basic «redacted»"],
|
|
12
|
+
[/-----BEGIN[^-]+PRIVATE KEY(?: BLOCK)?-----[\s\S]{0,8192}?-----END[^-]+PRIVATE KEY(?: BLOCK)?-----/g, "«redacted:private-key»"], // bounded body (council #8: avoid backtracking on fence-heavy input). `( BLOCK)?` covers PGP-armored keys `-----BEGIN PGP PRIVATE KEY BLOCK-----` where 'BLOCK' sits between 'PRIVATE KEY' and the dashes (L5 corpus caught the leak — same class as core's 1.108.1 PGP regression).
|
|
13
|
+
[/\bsk-[A-Za-z0-9_-]{16,}\b/g, "«redacted:key»"], // OpenAI / DeepSeek-style keys
|
|
14
|
+
[/\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}\b/g, "«redacted:gh-token»"], // GitHub tokens
|
|
15
|
+
[/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g, "«redacted:slack-token»"], // Slack tokens
|
|
16
|
+
[/\bAKIA[0-9A-Z]{16}\b/g, "«redacted:aws-key»"], // AWS access key id
|
|
17
|
+
[/\b[Bb]earer\s+[A-Za-z0-9._~+/-]{20,}=*/g, "Bearer «redacted»"], // bearer auth tokens
|
|
18
|
+
[/\bBasic\s+[A-Za-z0-9+/]{16,}={0,2}/g, "Basic «redacted»"], // HTTP Basic auth (base64 creds)
|
|
19
|
+
// BL-5: credentials embedded in a clone/push URL (`scheme://user:PASS@host`) — keep scheme+user, drop the
|
|
20
|
+
// password. Port-only URLs (`host:9999/path`, no `@`) don't match (the userinfo `:pass@` is required).
|
|
9
21
|
[/\b([A-Za-z][A-Za-z0-9+.-]*:\/\/[^/@\s:]+):[^/@\s]+@/g, "$1:«redacted»@"],
|
|
22
|
+
// BL-5: Gitea / PAT `Authorization: token <hex>` scheme (the Bearer/Basic rules don't cover the `token` keyword).
|
|
10
23
|
[/\b[Tt]oken\s+[A-Za-z0-9._~+/-]{20,}/g, "token «redacted»"],
|
|
11
|
-
[/("(?:private_key|client_secret|password|api[_-]?key|secret|token)"\s*:\s*)"[^"\\]*(?:\\.[^"\\]*)*"/gi, '$1"«redacted»"'],
|
|
24
|
+
[/("(?:private_key|client_secret|password|api[_-]?key|secret|token)"\s*:\s*)"[^"\\]*(?:\\.[^"\\]*)*"/gi, '$1"«redacted»"'], // JSON secret-field VALUES (escaped-quote-safe)
|
|
12
25
|
];
|
|
26
|
+
/** Redact unambiguous secret formats from reasoning/CoT before it is persisted to the durable trace log. */
|
|
27
|
+
/** S24 (SILENT-FALLBACK P1): optional redaction observer — rewrites previously had zero fingerprint, so
|
|
28
|
+
* over-redaction (mangling legit content) and under-redaction (a pattern that never fires) were both
|
|
29
|
+
* invisible. main.ts wires this to `redactions_applied_total{pattern}`. Hot path: the observer only runs
|
|
30
|
+
* when a pattern actually matched; the label is derived once per pattern at module load. */
|
|
13
31
|
let onRedaction;
|
|
14
32
|
export function setRedactionObserver(fn) {
|
|
15
33
|
onRedaction = fn;
|
|
@@ -23,6 +41,10 @@ export function redactSecrets(text) {
|
|
|
23
41
|
out = out.replace(re, repl);
|
|
24
42
|
continue;
|
|
25
43
|
}
|
|
44
|
+
// Count-then-replace (1.127.0): only the STRING form of `replace` expands `$1` capture refs —
|
|
45
|
+
// a function replacer returns its result verbatim, so the URL/JSON-field patterns emitted a literal `$1`
|
|
46
|
+
// instead of the preserved scheme/key prefix. The extra match() scan runs only when an observer is
|
|
47
|
+
// installed, on text that is already preview-capped.
|
|
26
48
|
const n = out.match(re)?.length ?? 0;
|
|
27
49
|
out = out.replace(re, repl);
|
|
28
50
|
if (n > 0) {
|
|
@@ -30,12 +52,29 @@ export function redactSecrets(text) {
|
|
|
30
52
|
onRedaction(PATTERN_LABELS[i], n);
|
|
31
53
|
}
|
|
32
54
|
catch {
|
|
55
|
+
/* observability must never break redaction */
|
|
33
56
|
}
|
|
34
57
|
}
|
|
35
58
|
}
|
|
36
59
|
return out;
|
|
37
60
|
}
|
|
61
|
+
/** Recursively redact secret-shaped strings inside a structured value (e.g. tool-call `args`), preserving shape.
|
|
62
|
+
* Tool arguments are persisted to the durable trace + replayed to any trace consumer, so a secret passed AS a
|
|
63
|
+
* tool arg must be stripped too (council: redactSecrets covered only free reasoning text, not tool args). */
|
|
64
|
+
/** 递归上限 —— 与「一条畸形输入不得打死流」这条目标匹配的量级:真实工具输出的嵌套远低于此,
|
|
65
|
+
* 而爆栈发生在数千层。超限的子树替换成一个**标记**,而不是抛错、也不是静默截断成 `{}`。 */
|
|
38
66
|
const REDACT_MAX_DEPTH = 64;
|
|
67
|
+
/**
|
|
68
|
+
* 🔴 环 + 深度预算(2026-07-25 补)。原实现是纯递归、**既不记已访问节点也不限深度**,而它的调用位置是
|
|
69
|
+
* **最不可信的边界**:`toolStart`/`toolEnd` 把工具的 `args`/`output`/`structured` 直接喂进来。后果两条:
|
|
70
|
+
* · **循环引用** ⇒ 无限递归 ⇒ `RangeError` **抛出构造函数**。在 sync 的 SSE 腿上那个 throw 就落在
|
|
71
|
+
* `for await (…) res.write(…)` 的循环里 ⇒ **一个畸形工具输出能打死一条正在跑的流**;在 ledger-sink 腿上
|
|
72
|
+
* 则是那一帧 append 直接失败(事件永久不落盘)。
|
|
73
|
+
* · 超深嵌套 ⇒ 同样爆栈。
|
|
74
|
+
* 同文件的 `redactedPreview` 的文档里早把这条记成"已复审的 MEDIUM"并**绕开** redactDeep ——
|
|
75
|
+
* 也就是说这个洞是知道的,只是没堵。现在堵在 redactDeep 本体:环与超深都换成**可见的标记**,
|
|
76
|
+
* 让下游看到"这里有东西被省略了",而不是丢一个空对象或炸掉整条流。
|
|
77
|
+
*/
|
|
39
78
|
export function redactDeep(value) {
|
|
40
79
|
return redactDeepInner(value, 0, new WeakSet());
|
|
41
80
|
}
|
|
@@ -44,6 +83,7 @@ function redactDeepInner(value, depth, seen) {
|
|
|
44
83
|
return redactSecrets(value);
|
|
45
84
|
if (!value || typeof value !== "object")
|
|
46
85
|
return value;
|
|
86
|
+
// 环:同一个对象在**当前这条路径上**再次出现 ⇒ 标记后停,不再往下走。
|
|
47
87
|
if (seen.has(value))
|
|
48
88
|
return "[circular]";
|
|
49
89
|
if (depth >= REDACT_MAX_DEPTH)
|
|
@@ -58,16 +98,33 @@ function redactDeepInner(value, depth, seen) {
|
|
|
58
98
|
return out;
|
|
59
99
|
}
|
|
60
100
|
finally {
|
|
101
|
+
// 出栈即移除:`seen` 记的是**当前路径**,不是"整棵树里出现过" —— 否则同一个对象被两个兄弟字段
|
|
102
|
+
// 各引用一次(DAG,完全合法)会被误标成 circular。
|
|
61
103
|
seen.delete(value);
|
|
62
104
|
}
|
|
63
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* A REDACTED, length-BOUNDED string preview of a structured value — for surfacing a pending tool call's `args`
|
|
108
|
+
* in the assistant inbox ("what is this ask about") WITHOUT leaking secrets or dumping an unbounded payload (a
|
|
109
|
+
* write_file `content` can be megabytes). {@link redactDeep} scrubs secret-shaped strings first; the result is
|
|
110
|
+
* JSON-stringified and capped (truncation is marked). `null`/`undefined` → `null` (nothing to preview). Defense
|
|
111
|
+
* in depth: the redaction is conservative (NOT exhaustive — see {@link redactSecrets}); the inbox is already
|
|
112
|
+
* owner-scoped, so this preview is only ever shown to the ask's own principal (or an operator inspecting it).
|
|
113
|
+
*/
|
|
64
114
|
export function redactedPreview(value, cap = 2000) {
|
|
65
115
|
if (value === null || value === undefined)
|
|
66
116
|
return null;
|
|
117
|
+
// A bare string arg → preview it directly (not JSON-quoted), redacted.
|
|
67
118
|
if (typeof value === "string") {
|
|
68
119
|
const r = redactSecrets(value);
|
|
69
120
|
return r.length === 0 ? null : r.length > cap ? `${r.slice(0, cap)}…[truncated]` : r;
|
|
70
121
|
}
|
|
122
|
+
// Structured value → cycle-safe, leaf-bounded JSON, THEN string-level redaction. We do NOT use redactDeep here
|
|
123
|
+
// (review MEDIUM): redactDeep has no cycle/depth/size budget, so a cyclic arg would recurse to a stack overflow
|
|
124
|
+
// BEFORE any try/catch, a BigInt would throw, and a huge leaf would be fully copied before truncation. The
|
|
125
|
+
// replacer below caps long string leaves up front (bounds the buffer), tags cycles, and stringifies BigInt;
|
|
126
|
+
// redactSecrets on the resulting JSON catches the same secret shapes (the standalone key patterns + the JSON
|
|
127
|
+
// secret-field rule both operate on the flat string — equivalent-or-better than per-leaf redaction).
|
|
71
128
|
const seen = new WeakSet();
|
|
72
129
|
let s;
|
|
73
130
|
try {
|
|
@@ -86,7 +143,7 @@ export function redactedPreview(value, cap = 2000) {
|
|
|
86
143
|
}) ?? "";
|
|
87
144
|
}
|
|
88
145
|
catch {
|
|
89
|
-
s = "[unserializable]";
|
|
146
|
+
s = "[unserializable]"; // last-resort (should be unreachable: cycles/BigInt are handled in the replacer)
|
|
90
147
|
}
|
|
91
148
|
if (s.length === 0)
|
|
92
149
|
return null;
|
|
@@ -1,7 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用量统计查询面(registry AnalyticsSource id="service-usage" 槽位的数据源)。
|
|
3
|
+
*
|
|
4
|
+
* 数据源 = task_run 账本的 result JSON(E8 `stats.modelUsage` per-model echo:inputTokens/outputTokens/
|
|
5
|
+
* cacheReadTokens/cacheWriteTokens/costMicroUsd——costMicroUsd 是 authoritative micro-USD 记账非估算)。
|
|
6
|
+
* 架构 = store 侧薄扫窗(usageScan:SQL 只按时间窗过滤取四列,行内 JSON 提取在 store 完成)+ 本文件的
|
|
7
|
+
* 【纯函数】聚合(三后端同代码,零方言分叉;test 直接喂行)。
|
|
8
|
+
*
|
|
9
|
+
* 口径(回帖契约,2026-07-09):
|
|
10
|
+
* - tokensIn = Σ(inputTokens + cacheReadTokens + cacheWriteTokens)(即"进模型的上下文 token 总量",
|
|
11
|
+
* cache 命中也计——计费口径;cache 明细在 breakdown 的 cacheReadTokens 单列可见);
|
|
12
|
+
* - tokensOut = Σ outputTokens;
|
|
13
|
+
* - costUsd = Σ costMicroUsd / 1e6(authoritative);
|
|
14
|
+
* - 旧行/无 modelUsage echo 的行(1.x 早期或非终态)fallback `stats.tokens` 整数计入 tokensOut 并置
|
|
15
|
+
* `estimated:true` 于该聚合(诚实标注,契约要求"token 数标注估算与否");
|
|
16
|
+
* - 扫窗有行数上限(store 侧 LIMIT)——触顶时结果携带 `truncated:true`(诚实截断,绝不静默)。
|
|
17
|
+
*/
|
|
18
|
+
/** store 侧 usageScan 的行投影(所有后端同形状;createdAtMs=epoch ms)。 */
|
|
1
19
|
export interface UsageRow {
|
|
2
20
|
owner: string | null;
|
|
3
21
|
createdAtMs: number;
|
|
4
22
|
status: string;
|
|
23
|
+
/** result.stats 摘要;result NULL/不可解析 ⇒ undefined(不计 token/cost,仍计 tasks)。 */
|
|
5
24
|
stats?: {
|
|
6
25
|
tokens?: number;
|
|
7
26
|
modelUsage?: Record<string, {
|
|
@@ -18,19 +37,26 @@ export interface UsageTotals {
|
|
|
18
37
|
tokensIn: number;
|
|
19
38
|
tokensOut: number;
|
|
20
39
|
costUsd: number;
|
|
40
|
+
/** 有行走了 stats.tokens fallback(无 per-model echo)——token 口径部分为估算。 */
|
|
21
41
|
estimated: boolean;
|
|
22
42
|
}
|
|
43
|
+
/** GET /v1/usage/summary — 窗内总量。 */
|
|
23
44
|
export declare function usageSummary(rows: UsageRow[]): UsageTotals;
|
|
24
45
|
export type UsageMetric = "tasks" | "tokensIn" | "tokensOut" | "costUsd";
|
|
25
46
|
export type UsageGranularity = "hour" | "day";
|
|
47
|
+
/** GET /v1/usage/series — 时间序列(UTC 桶;空桶不发行,消费方按需补零)。 */
|
|
26
48
|
export declare function usageSeries(rows: UsageRow[], metric: UsageMetric, granularity: UsageGranularity): Array<{
|
|
27
49
|
t: string;
|
|
28
50
|
v: number;
|
|
29
51
|
}>;
|
|
30
52
|
export type UsageDimension = "principal" | "model";
|
|
53
|
+
/** GET /v1/usage/breakdown — 按维度分桶。dimension=model 时按 per-model echo 展开(一行可贡献多个 model 桶;
|
|
54
|
+
* fallback 行归 "(unattributed)");dimension=principal 时 owner NULL 归 "(anonymous)"。 */
|
|
31
55
|
export declare function usageBreakdown(rows: UsageRow[], dimension: UsageDimension): Array<{
|
|
32
56
|
key: string;
|
|
33
57
|
} & UsageTotals>;
|
|
58
|
+
/** store 行投影 helper:result JSON(已 parse 或原始字符串)→ UsageRow.stats。所有后端复用(方言只在 SQL)。 */
|
|
34
59
|
export declare function projectUsageStats(result: unknown): UsageRow["stats"];
|
|
60
|
+
/** usageScan 的统一行数上限(触顶=结果 truncated:true;试点规模远在限内)。 */
|
|
35
61
|
export declare const USAGE_SCAN_LIMIT = 50000;
|
|
36
62
|
//# sourceMappingURL=usage-analytics.d.ts.map
|