@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/model-select.js
CHANGED
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
import { parseModelMention } from "@sema-agent/core";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the model ref for a task spec from the request (CLI `/model` picker + `run --model`).
|
|
4
|
+
*
|
|
5
|
+
* Priority (a deliberate selection beats incidental free text):
|
|
6
|
+
* 1) an explicit, allow-listed `body.model` (the picker / `--model <ref>` flag),
|
|
7
|
+
* 2) an inline `@name` mention in the objective (core's `parseModelMention`),
|
|
8
|
+
* 3) the `default` role.
|
|
9
|
+
*
|
|
10
|
+
* Security: BOTH the explicit field and the @mention are gated by the SAME catalog (`config.models` keys), so
|
|
11
|
+
* untrusted body/text can pick WHICH configured model but can never inject a baseUrl/apiKey (parseModelMention
|
|
12
|
+
* only ever returns an allow-listed catalog name).
|
|
13
|
+
*
|
|
14
|
+
* [865]②(clay 生产实锤:onboard 选 kimi 实跑 Qwen):
|
|
15
|
+
* - explicit ref 走 name+id 双键索引({@link matchCatalogModel})——壳 boot 回读的 mainLoopModel 是 **id 形**,
|
|
16
|
+
* 目录键是 **name 形**,单键索引把 id 形请求当「未知」静默落 default = session 中途静默换模型(最恶性的
|
|
17
|
+
* 上下文污染路径)。
|
|
18
|
+
* - 真未知不再无声:FRESH submit 在 HTTP 门 400 fail-loud(带 available 列表,http/server.ts);本函数保持
|
|
19
|
+
* 不 throw(RESUME 重放持久化 body 不过 400 门——模型可能事后被移出目录,砖死 resume 比降级更糟),但把
|
|
20
|
+
* 未知 ref 透出给调用方(`unknownExplicit`),resolveSpec 记 warn——降级永远可见,绝不静默。
|
|
21
|
+
*
|
|
22
|
+
* Returns the chosen model ref AND the objective with any `@mention` stripped (parseModelMention's cleanedText).
|
|
23
|
+
*
|
|
24
|
+
* 🔴 Was a real defect: resolveSpec previously read ONLY the inline @mention, so `body.model` (the picker + the
|
|
25
|
+
* `--model` flag) was SILENTLY DROPPED — the picker UX was a no-op server-side. This restores it.
|
|
26
|
+
*/
|
|
2
27
|
export function resolveTaskModel(bodyModel, objective, catalog) {
|
|
3
28
|
const mention = parseModelMention(objective, Object.keys(catalog));
|
|
4
29
|
const explicit = typeof bodyModel === "string" ? matchCatalogModel(bodyModel, catalog) : undefined;
|
|
30
|
+
// 未匹配的「在场」ref 一律透出(codex L1:历史 checkpoint 里的空串/非字符串 model 在 RESUME 重放也不许
|
|
31
|
+
// 静默降级——非字符串给类型表示,不 stringify 值本体防日志泄内容)。
|
|
5
32
|
const present = bodyModel !== undefined && bodyModel !== null;
|
|
6
33
|
const unknown = present && explicit === undefined;
|
|
7
34
|
const repr = typeof bodyModel !== "string" ? `<non-string:${typeof bodyModel}>` : bodyModel === "" ? "<empty-string>" : bodyModel;
|
|
@@ -11,6 +38,13 @@ export function resolveTaskModel(bodyModel, objective, catalog) {
|
|
|
11
38
|
...(unknown ? { unknownExplicit: repr } : {}),
|
|
12
39
|
};
|
|
13
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* [865]② name+id 双键目录索引:返回 ref 命中的目录 **name 键**(spec.model 的规范形),未知 → undefined。
|
|
43
|
+
* - name 命中用 Object.hasOwn(🔴 不用真值索引:Object.prototype 继承键 "constructor"/"__proto__" 等在裸
|
|
44
|
+
* 索引下是真值,会绕过 allow-list——沿袭原实现的纪律)。
|
|
45
|
+
* - id 命中扫目录值(`Model.id`),跳过 "default" 别名键(它与其指向的真身共享 id,解析到别名会让 /model
|
|
46
|
+
* 面板与实际路由再度撕裂);同 id 多 name 时取目录序第一个(与 /v1/models 列表序一致,确定性)。
|
|
47
|
+
*/
|
|
14
48
|
export function matchCatalogModel(ref, catalog) {
|
|
15
49
|
if (Object.hasOwn(catalog, ref))
|
|
16
50
|
return ref;
|
|
@@ -22,9 +56,16 @@ export function matchCatalogModel(ref, catalog) {
|
|
|
22
56
|
}
|
|
23
57
|
return undefined;
|
|
24
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* vision precheck: a catalog model can read images iff its `input` modality list
|
|
61
|
+
* includes `"image"` (the SAME test as the vision capability on GET /v1/models — `server.ts`). FALSE-SAFE on
|
|
62
|
+
* missing/unknown modality info: returns `true` (do NOT block) — only an EXPLICIT text-only `input` triggers the
|
|
63
|
+
* precheck, so a model that never declared its modalities is never wrongly 422'd. Lets a request with images 422
|
|
64
|
+
* up-front instead of hitting the downstream gateway as an opaque deserialize 400 on a text-only model.
|
|
65
|
+
*/
|
|
25
66
|
export function modelSupportsImages(model) {
|
|
26
67
|
if (!model || !Array.isArray(model.input))
|
|
27
|
-
return true;
|
|
68
|
+
return true; // no modality info → fail-open (don't block)
|
|
28
69
|
return model.input.includes("image");
|
|
29
70
|
}
|
|
30
71
|
//# sourceMappingURL=model-select.js.map
|
|
@@ -1,9 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-principal CUMULATIVE cost quota (design/21/27 follow-up). The per-task `maxCostUsd` gate caps a
|
|
3
|
+
* SINGLE task; this caps a principal's spend ACROSS tasks within a rolling fixed window. Spend is the
|
|
4
|
+
* authoritative integer `costMicroUsd` accumulated by the tracer (so it includes council/team
|
|
5
|
+
* sub-tasks, via the principal ALS context). A new task is REFUSED once the window's accumulated cost
|
|
6
|
+
* has crossed the ceiling — the in-flight task that crossed it still finishes (the per-task gate is the
|
|
7
|
+
* single-task guard); the quota blocks the NEXT one until the window rolls over.
|
|
8
|
+
*
|
|
9
|
+
* In-memory, per-replica — same trade as the request rate limiter. A multi-replica deployment under-
|
|
10
|
+
* counts across replicas (each tracks its own slice); a shared (TiDB) quota is the hardening step,
|
|
11
|
+
* mirroring TiDBBreakerState. Documented, not silently wrong.
|
|
12
|
+
*/
|
|
1
13
|
export interface QuotaDecision {
|
|
2
14
|
allowed: boolean;
|
|
3
15
|
usedMicroUsd: number;
|
|
4
16
|
limitMicroUsd: number;
|
|
17
|
+
/** Seconds until the current window rolls over (only meaningful when !allowed). */
|
|
5
18
|
retryAfterSec: number;
|
|
6
19
|
}
|
|
20
|
+
/** The hot-path surface shared by the in-memory {@link CostQuota} (single replica) and the cross-replica
|
|
21
|
+
* {@link import("../plugins/tidb-cost-quota.js").TiDBCostQuota}. `key` is opaque (principal today;
|
|
22
|
+
* principal/team/feature later — design/30 N3), so both stores are key-based. */
|
|
7
23
|
export interface QuotaTracker {
|
|
8
24
|
check(key: string): QuotaDecision;
|
|
9
25
|
add(key: string, micro: number): void;
|
|
@@ -13,9 +29,13 @@ export declare class CostQuota implements QuotaTracker {
|
|
|
13
29
|
private readonly windowMs;
|
|
14
30
|
private readonly now;
|
|
15
31
|
private windows;
|
|
32
|
+
/** @param limitMicroUsd ceiling per window (integer micro-USD). @param windowMs rolling window. */
|
|
16
33
|
constructor(limitMicroUsd: number, windowMs: number, now?: () => number);
|
|
34
|
+
/** Is this principal under quota right now? (Reads only — does not consume.) */
|
|
17
35
|
check(key: string): QuotaDecision;
|
|
36
|
+
/** Add spend for a principal, starting a fresh window if the prior one expired. */
|
|
18
37
|
add(key: string, micro: number): void;
|
|
38
|
+
/** Drop expired windows (called from the background reaper) to bound memory. */
|
|
19
39
|
reap(): number;
|
|
20
40
|
}
|
|
21
41
|
//# sourceMappingURL=cost-quota.d.ts.map
|
|
@@ -3,11 +3,13 @@ export class CostQuota {
|
|
|
3
3
|
windowMs;
|
|
4
4
|
now;
|
|
5
5
|
windows = new Map();
|
|
6
|
+
/** @param limitMicroUsd ceiling per window (integer micro-USD). @param windowMs rolling window. */
|
|
6
7
|
constructor(limitMicroUsd, windowMs, now = () => Date.now()) {
|
|
7
8
|
this.limitMicroUsd = limitMicroUsd;
|
|
8
9
|
this.windowMs = windowMs;
|
|
9
10
|
this.now = now;
|
|
10
11
|
}
|
|
12
|
+
/** Is this principal under quota right now? (Reads only — does not consume.) */
|
|
11
13
|
check(key) {
|
|
12
14
|
const t = this.now();
|
|
13
15
|
const w = this.windows.get(key);
|
|
@@ -17,6 +19,7 @@ export class CostQuota {
|
|
|
17
19
|
const retryAfterSec = !allowed && live ? Math.ceil((w.start + this.windowMs - t) / 1000) : 0;
|
|
18
20
|
return { allowed, usedMicroUsd: used, limitMicroUsd: this.limitMicroUsd, retryAfterSec };
|
|
19
21
|
}
|
|
22
|
+
/** Add spend for a principal, starting a fresh window if the prior one expired. */
|
|
20
23
|
add(key, micro) {
|
|
21
24
|
if (micro <= 0)
|
|
22
25
|
return;
|
|
@@ -27,6 +30,7 @@ export class CostQuota {
|
|
|
27
30
|
else
|
|
28
31
|
w.micro += micro;
|
|
29
32
|
}
|
|
33
|
+
/** Drop expired windows (called from the background reaper) to bound memory. */
|
|
30
34
|
reap() {
|
|
31
35
|
const t = this.now();
|
|
32
36
|
let dropped = 0;
|
|
@@ -1,33 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* design/80 b (item 3) — the INFRA cost axes the SERVICE owns, composed with core's LLM-family `costBreakdown`
|
|
3
|
+
* for the supervisor cost surface.
|
|
4
|
+
*
|
|
5
|
+
* (design/158 N24: moved here from the single-file `src/finance/` directory — lens4 §4.4 flagged the "cost"
|
|
6
|
+
* concept as split across `finance/cost-taxonomy.ts` + `observability/cost-quota.ts` + `budget.ts`. Chose
|
|
7
|
+
* "dissolve finance/, fold into observability/" over "collect all three into finance/": this module + the
|
|
8
|
+
* quota tracker are both cost REPORT/GUARD layers that feed metrics/decisions (observability's existing
|
|
9
|
+
* job), and budget.ts stays put — it has ~19 import sites and was already the N18 move target this same
|
|
10
|
+
* batch; stacking a second wide-fanout move on it in one session was the higher-risk option for no added
|
|
11
|
+
* clarity.)
|
|
12
|
+
*
|
|
13
|
+
* The engine prices ONLY LLM tokens (core's `Stats.costBreakdown` = llmRoot / nestedSubagent / memoryConsolidation
|
|
14
|
+
* / compaction). It has NO $ for tool calls, sandbox wall-clock, or network egress — those are INFRA/service costs
|
|
15
|
+
* the service owns the data + rates for. This module is the thin report layer: it turns a
|
|
16
|
+
* per-run infra USAGE + the deployment's RATES into an infra breakdown, then composes it with the core LLM
|
|
17
|
+
* breakdown into one supervisor-facing total. Pure + rate-driven (rates default 0 ⇒ infra reads $0, exactly like
|
|
18
|
+
* MODEL_COST_* — opt-in pricing). The per-run usage extraction (sandbox wall-clock from the run's remote-env
|
|
19
|
+
* spans, tool-call count from the trace) is the data-source wiring fed in by the caller; this layer is the math.
|
|
20
|
+
*/
|
|
21
|
+
/** Deployment infra pricing (config; default 0 = not priced, mirrors MODEL_COST_*). */
|
|
1
22
|
export interface InfraCostRates {
|
|
23
|
+
/** $ (micro-USD) per tool invocation. */
|
|
2
24
|
toolCallMicroUsd: number;
|
|
25
|
+
/** $ (micro-USD) per sandbox wall-clock SECOND (the run's remote-env connected lifetime). */
|
|
3
26
|
sandboxSecMicroUsd: number;
|
|
27
|
+
/** $ (micro-USD) per GB of network egress. */
|
|
4
28
|
egressGbMicroUsd: number;
|
|
5
29
|
}
|
|
30
|
+
/** Per-run infra USAGE (fed by the caller from the run's trace / remote-env spans). */
|
|
6
31
|
export interface InfraUsage {
|
|
7
32
|
toolCalls: number;
|
|
8
33
|
sandboxWalltimeMs: number;
|
|
9
34
|
egressBytes: number;
|
|
10
35
|
}
|
|
36
|
+
/** The service's infra cost axes (micro-USD), the complement to core's LLM-family breakdown. */
|
|
11
37
|
export interface InfraCostBreakdown {
|
|
12
38
|
toolCallMicroUsd: number;
|
|
13
39
|
sandboxWalltimeMicroUsd: number;
|
|
14
40
|
egressMicroUsd: number;
|
|
15
41
|
totalMicroUsd: number;
|
|
16
42
|
}
|
|
43
|
+
/** Core's LLM-family breakdown (mirror of core `Stats.costBreakdown`), accepted read-only for composition. */
|
|
17
44
|
export interface LlmCostBreakdown {
|
|
18
45
|
llmRootMicroUsd: number;
|
|
19
46
|
nestedSubagentMicroUsd: number;
|
|
20
47
|
memoryConsolidationMicroUsd: number;
|
|
21
48
|
compactionMicroUsd: number;
|
|
22
49
|
}
|
|
50
|
+
/** The combined supervisor cost surface: core's LLM axes + the service's infra axes + a reconciled grand total. */
|
|
23
51
|
export interface SupervisorCostBreakdown {
|
|
24
52
|
llm: LlmCostBreakdown | null;
|
|
25
53
|
infra: InfraCostBreakdown;
|
|
54
|
+
/** llm.total (the engine's priced LLM $) + infra.total. `llmTotalMicroUsd` is supplied explicitly (core's
|
|
55
|
+
* authoritative `stats.costMicroUsd`) rather than re-summed from the breakdown, so a category drift in the
|
|
56
|
+
* breakdown can never silently inflate/deflate the grand total. */
|
|
26
57
|
totalMicroUsd: number;
|
|
27
58
|
}
|
|
59
|
+
/** Price a run's infra usage. Every term clamps negatives to 0 (a bad usage/rate never produces a negative cost). */
|
|
28
60
|
export declare function infraCost(usage: InfraUsage, rates: InfraCostRates): InfraCostBreakdown;
|
|
61
|
+
/**
|
|
62
|
+
* Compose the supervisor cost surface from core's LLM breakdown + total and the service's infra breakdown.
|
|
63
|
+
* `llmTotalMicroUsd` is core's authoritative priced-LLM total (`stats.costMicroUsd`) — the grand total is that +
|
|
64
|
+
* infra, NOT a re-sum of the LLM sub-categories (so a breakdown category bug can't move the grand total).
|
|
65
|
+
*/
|
|
29
66
|
export declare function composeSupervisorCost(llm: LlmCostBreakdown | null, llmTotalMicroUsd: number, infra: InfraCostBreakdown): SupervisorCostBreakdown;
|
|
67
|
+
/** True iff ANY infra axis is priced — the gate for surfacing the composed supervisor cost (when all rates are 0
|
|
68
|
+
* the infra contribution is always $0, so the client just reads core's `stats.costBreakdown` directly). */
|
|
30
69
|
export declare function hasInfraPricing(r: InfraCostRates): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Extract a run's infra USAGE from its event log + wall-clock span. `toolCalls` = the `tool_start` events (one per
|
|
72
|
+
* tool invocation). `sandboxWalltimeMs` ≈ the run's wall-clock duration (the remote-env is connected for ~the
|
|
73
|
+
* run's active life; the precise per-span sum lives in logs, not the event trace — the run duration is the
|
|
74
|
+
* faithful per-run proxy). `egressBytes` = 0 (not yet metered per run).
|
|
75
|
+
*/
|
|
31
76
|
export declare function infraUsageFromEvents(events: ReadonlyArray<{
|
|
32
77
|
type?: string;
|
|
33
78
|
}>, runDurationMs: number): InfraUsage;
|
|
@@ -1,4 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* design/80 b (item 3) — the INFRA cost axes the SERVICE owns, composed with core's LLM-family `costBreakdown`
|
|
3
|
+
* for the supervisor cost surface.
|
|
4
|
+
*
|
|
5
|
+
* (design/158 N24: moved here from the single-file `src/finance/` directory — lens4 §4.4 flagged the "cost"
|
|
6
|
+
* concept as split across `finance/cost-taxonomy.ts` + `observability/cost-quota.ts` + `budget.ts`. Chose
|
|
7
|
+
* "dissolve finance/, fold into observability/" over "collect all three into finance/": this module + the
|
|
8
|
+
* quota tracker are both cost REPORT/GUARD layers that feed metrics/decisions (observability's existing
|
|
9
|
+
* job), and budget.ts stays put — it has ~19 import sites and was already the N18 move target this same
|
|
10
|
+
* batch; stacking a second wide-fanout move on it in one session was the higher-risk option for no added
|
|
11
|
+
* clarity.)
|
|
12
|
+
*
|
|
13
|
+
* The engine prices ONLY LLM tokens (core's `Stats.costBreakdown` = llmRoot / nestedSubagent / memoryConsolidation
|
|
14
|
+
* / compaction). It has NO $ for tool calls, sandbox wall-clock, or network egress — those are INFRA/service costs
|
|
15
|
+
* the service owns the data + rates for. This module is the thin report layer: it turns a
|
|
16
|
+
* per-run infra USAGE + the deployment's RATES into an infra breakdown, then composes it with the core LLM
|
|
17
|
+
* breakdown into one supervisor-facing total. Pure + rate-driven (rates default 0 ⇒ infra reads $0, exactly like
|
|
18
|
+
* MODEL_COST_* — opt-in pricing). The per-run usage extraction (sandbox wall-clock from the run's remote-env
|
|
19
|
+
* spans, tool-call count from the trace) is the data-source wiring fed in by the caller; this layer is the math.
|
|
20
|
+
*/
|
|
1
21
|
const nonNeg = (n) => (Number.isFinite(n) && n > 0 ? n : 0);
|
|
22
|
+
/** Price a run's infra usage. Every term clamps negatives to 0 (a bad usage/rate never produces a negative cost). */
|
|
2
23
|
export function infraCost(usage, rates) {
|
|
3
24
|
const toolCallMicroUsd = nonNeg(usage.toolCalls) * nonNeg(rates.toolCallMicroUsd);
|
|
4
25
|
const sandboxWalltimeMicroUsd = (nonNeg(usage.sandboxWalltimeMs) / 1000) * nonNeg(rates.sandboxSecMicroUsd);
|
|
@@ -10,12 +31,25 @@ export function infraCost(usage, rates) {
|
|
|
10
31
|
totalMicroUsd: toolCallMicroUsd + sandboxWalltimeMicroUsd + egressMicroUsd,
|
|
11
32
|
};
|
|
12
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Compose the supervisor cost surface from core's LLM breakdown + total and the service's infra breakdown.
|
|
36
|
+
* `llmTotalMicroUsd` is core's authoritative priced-LLM total (`stats.costMicroUsd`) — the grand total is that +
|
|
37
|
+
* infra, NOT a re-sum of the LLM sub-categories (so a breakdown category bug can't move the grand total).
|
|
38
|
+
*/
|
|
13
39
|
export function composeSupervisorCost(llm, llmTotalMicroUsd, infra) {
|
|
14
40
|
return { llm, infra, totalMicroUsd: nonNeg(llmTotalMicroUsd) + infra.totalMicroUsd };
|
|
15
41
|
}
|
|
42
|
+
/** True iff ANY infra axis is priced — the gate for surfacing the composed supervisor cost (when all rates are 0
|
|
43
|
+
* the infra contribution is always $0, so the client just reads core's `stats.costBreakdown` directly). */
|
|
16
44
|
export function hasInfraPricing(r) {
|
|
17
45
|
return r.toolCallMicroUsd > 0 || r.sandboxSecMicroUsd > 0 || r.egressGbMicroUsd > 0;
|
|
18
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Extract a run's infra USAGE from its event log + wall-clock span. `toolCalls` = the `tool_start` events (one per
|
|
49
|
+
* tool invocation). `sandboxWalltimeMs` ≈ the run's wall-clock duration (the remote-env is connected for ~the
|
|
50
|
+
* run's active life; the precise per-span sum lives in logs, not the event trace — the run duration is the
|
|
51
|
+
* faithful per-run proxy). `egressBytes` = 0 (not yet metered per run).
|
|
52
|
+
*/
|
|
19
53
|
export function infraUsageFromEvents(events, runDurationMs) {
|
|
20
54
|
return {
|
|
21
55
|
toolCalls: events.reduce((n, e) => (e.type === "tool_start" ? n + 1 : n), 0),
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
const ORDER = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
2
|
+
// EPIPE hardening (live catch): a host that feeds this engine's stdout through a
|
|
3
|
+
// PIPE and exits first leaves the fd broken — the NEXT log write raises EPIPE. Without a listener
|
|
4
|
+
// that async 'error' event on process.stdout is fatal, which killed drainThenShutdown ON ITS FIRST
|
|
5
|
+
// LOG LINE (the SIGHUP reap never ran). Logs are droppable; the process is not — swallow both the
|
|
6
|
+
// sync throw (try/catch below) and the async 'error' event (no-op listener, attached once).
|
|
2
7
|
let stdioErrorsSwallowed = false;
|
|
3
8
|
function swallowStdioErrors() {
|
|
4
9
|
if (stdioErrorsSwallowed)
|
|
@@ -23,6 +28,7 @@ export function createLogger(minLevel = "info") {
|
|
|
23
28
|
(level === "error" || level === "warn" ? process.stderr : process.stdout).write(line + "\n");
|
|
24
29
|
}
|
|
25
30
|
catch {
|
|
31
|
+
// Broken/destroyed stream (EPIPE family): drop the line, never the process.
|
|
26
32
|
}
|
|
27
33
|
};
|
|
28
34
|
return {
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny in-process metrics registry with Prometheus text exposition — no dependency.
|
|
3
|
+
*
|
|
4
|
+
* Per-instance (each container exposes its own counters); aggregate across instances at the scraper.
|
|
5
|
+
* Supports labeled counters, gauges (static + dynamic), and duration histograms.
|
|
6
|
+
*/
|
|
1
7
|
export type Labels = Record<string, string>;
|
|
2
8
|
export declare class Metrics {
|
|
3
9
|
private counters;
|
|
@@ -12,8 +18,14 @@ export declare class Metrics {
|
|
|
12
18
|
setGauge(name: string, value: number, labels?: Labels): void;
|
|
13
19
|
addGauge(name: string, delta: number, labels?: Labels): void;
|
|
14
20
|
observe(name: string, value: number, labels?: Labels): void;
|
|
21
|
+
/** Prometheus text exposition (content-type text/plain; version=0.0.4). */
|
|
15
22
|
render(): string;
|
|
23
|
+
/** Structured snapshot of the whole registry — the OTLP exporter maps this to OTel data points
|
|
24
|
+
* (counters→Sum monotonic, gauges/dynamic→Gauge, histograms→Histogram). Read-only copy. */
|
|
16
25
|
snapshot(): MetricSnapshot;
|
|
26
|
+
/** Curated health summary (friendly JSON) for a lightweight fleet dashboard — the sema-registry's
|
|
27
|
+
* fleet page fetches this per worker and renders cards + computes rates over polls (no Prometheus
|
|
28
|
+
* needed). Counters are cumulative totals; histograms are reported as averages (sum/count). */
|
|
17
29
|
summarize(): MetricsSummary;
|
|
18
30
|
}
|
|
19
31
|
export interface MetricsSummary {
|
|
@@ -72,5 +84,6 @@ export interface MetricSnapshot {
|
|
|
72
84
|
}>;
|
|
73
85
|
}>;
|
|
74
86
|
}
|
|
87
|
+
/** Register the service's standard metric set. */
|
|
75
88
|
export declare function createMetrics(): Metrics;
|
|
76
89
|
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
const DEFAULT_BUCKETS = [0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60];
|
|
2
2
|
function labelKey(labels) {
|
|
3
|
+
// Escape the delimiters (`\` `,` `=`) IN THE VALUE so distinct label sets can't collide onto one series:
|
|
4
|
+
// without this, {a:"1,b=2"} and {a:"1",b:"2"} both key to "a=1,b=2" and silently merge (tool names come from
|
|
5
|
+
// MCP, model ids from config — not strongly constrained). This key is internal series identity only;
|
|
6
|
+
// Prometheus rendering escapes separately via renderLabels/esc.
|
|
3
7
|
return Object.keys(labels)
|
|
4
8
|
.sort()
|
|
5
9
|
.map((k) => `${k}=${String(labels[k]).replace(/\\/g, "\\\\").replace(/,/g, "\\,").replace(/=/g, "\\=")}`)
|
|
@@ -35,6 +39,11 @@ export class Metrics {
|
|
|
35
39
|
if (!this.histos.has(name))
|
|
36
40
|
this.histos.set(name, { help, buckets, series: new Map() });
|
|
37
41
|
}
|
|
42
|
+
// 根因升类:inc 对未注册名曾是静默 no-op — 15 个只 inc 未 counter() 的计数器
|
|
43
|
+
// (permission_denied_total / compaction_events_total / hook_llm_calls_total / fleet_lease_* /
|
|
44
|
+
// metric_label_overflow_total[溢出护栏自己的计数器!]等)整批从未出现在 /metrics。观测面的
|
|
45
|
+
// fail-silent 正是观测要消灭的东西 → inc/setGauge/addGauge 改为首用自动注册(help 标注
|
|
46
|
+
// auto-registered,提醒补显式注册拿正经 HELP 文案);已知 15 名已在 createMetrics 补显式注册。
|
|
38
47
|
inc(name, labels = {}, n = 1) {
|
|
39
48
|
let c = this.counters.get(name);
|
|
40
49
|
if (!c) {
|
|
@@ -78,6 +87,7 @@ export class Metrics {
|
|
|
78
87
|
s.count += 1;
|
|
79
88
|
h.series.set(k, s);
|
|
80
89
|
}
|
|
90
|
+
/** Prometheus text exposition (content-type text/plain; version=0.0.4). */
|
|
81
91
|
render() {
|
|
82
92
|
const out = [];
|
|
83
93
|
for (const [name, c] of this.counters) {
|
|
@@ -106,6 +116,8 @@ export class Metrics {
|
|
|
106
116
|
}
|
|
107
117
|
return out.join("\n") + "\n";
|
|
108
118
|
}
|
|
119
|
+
/** Structured snapshot of the whole registry — the OTLP exporter maps this to OTel data points
|
|
120
|
+
* (counters→Sum monotonic, gauges/dynamic→Gauge, histograms→Histogram). Read-only copy. */
|
|
109
121
|
snapshot() {
|
|
110
122
|
const counters = [...this.counters].map(([name, c]) => ({
|
|
111
123
|
name,
|
|
@@ -127,6 +139,9 @@ export class Metrics {
|
|
|
127
139
|
}));
|
|
128
140
|
return { counters, gauges, histograms };
|
|
129
141
|
}
|
|
142
|
+
/** Curated health summary (friendly JSON) for a lightweight fleet dashboard — the sema-registry's
|
|
143
|
+
* fleet page fetches this per worker and renders cards + computes rates over polls (no Prometheus
|
|
144
|
+
* needed). Counters are cumulative totals; histograms are reported as averages (sum/count). */
|
|
130
145
|
summarize() {
|
|
131
146
|
const ctotal = (name) => [...(this.counters.get(name)?.series.values() ?? [])].reduce((a, s) => a + s.value, 0);
|
|
132
147
|
const cby = (name, label) => {
|
|
@@ -180,6 +195,7 @@ function safe(fn) {
|
|
|
180
195
|
return 0;
|
|
181
196
|
}
|
|
182
197
|
}
|
|
198
|
+
/** Register the service's standard metric set. */
|
|
183
199
|
export function createMetrics() {
|
|
184
200
|
const m = new Metrics();
|
|
185
201
|
m.counter("http_requests_total", "HTTP requests by route/method/status");
|
|
@@ -191,10 +207,15 @@ export function createMetrics() {
|
|
|
191
207
|
m.gauge("runs_active", "Async runs currently executing");
|
|
192
208
|
m.counter("council_runs_total", "Code-review council runs (L1+L3)");
|
|
193
209
|
m.histogram("council_tokens", "Total model tokens per council review (lenses + arbiter)");
|
|
210
|
+
// Prefix-cache effectiveness (core 1.22): per-task hit rate (cost-critical) + a count of tasks the
|
|
211
|
+
// Runner flagged as low-hit (unstable/poisoned prefix) so it can be alerted on.
|
|
194
212
|
m.histogram("task_cache_hit_rate", "Prefix-cache hit rate per task (cachedTokens/promptTokens, 0..1)", [
|
|
195
213
|
0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 1,
|
|
196
214
|
]);
|
|
197
215
|
m.counter("prompt_cache_low_hit_total", "Tasks the Runner flagged with a low prefix-cache hit rate");
|
|
216
|
+
// Cost & trace observability (core 1.37). Spend = the integer micro-USD `costMicroUsd` summed over
|
|
217
|
+
// ALL brain calls (top-level + async + council sub-tasks) via the tracer — the authoritative billing
|
|
218
|
+
// counter. firstTokenMs is the gateway-hang early signal; tool calls + budget cutoffs round it out.
|
|
198
219
|
m.counter("model_cost_micro_usd_total", "Authoritative model spend (integer micro-USD) over all brain calls, by model");
|
|
199
220
|
m.histogram("brain_first_token_ms", "Time to first content token per brain call (gateway-hang signal)", [
|
|
200
221
|
50, 100, 250, 500, 1000, 2000, 5000, 10000, 30000,
|
|
@@ -210,38 +231,79 @@ export function createMetrics() {
|
|
|
210
231
|
m.counter("rewind_snapshot_failed_total", "Per-turn rewind file snapshots that failed, by code (too_large = big working tree, expected/benign; other codes warrant eyes)");
|
|
211
232
|
m.counter("verifications_total", "Tasks run through the verification gate (1.44), by final verdict");
|
|
212
233
|
m.counter("cascade_total", "Tasks run through the model cascade (1.45), by outcome (passed/exhausted)");
|
|
234
|
+
// Degenerate-repetition salvage classifier (core 1.59): on errorCode=output.degenerate, where was the
|
|
235
|
+
// useful answer? a=in the degenerate turn itself, b=in an earlier turn, unknown=nowhere. Frequencies
|
|
236
|
+
// feed back to core's decision on whether the "last-substantive-turn" salvage (②) is worth building.
|
|
213
237
|
m.counter("degenerate_total", "Degenerate-output failures (1.59), by salvage class (a/b/unknown)");
|
|
238
|
+
// Plan-cache recurrence probe (INSTRUMENT-FIRST, core design/42): does a tenant re-pose near-duplicate
|
|
239
|
+
// task objectives? Fleet-level totals; per-scope detail is at GET /metrics/plan-cache (not a label, to
|
|
240
|
+
// avoid high tenant cardinality). Decides whether core builds the plan-caching producer hook.
|
|
214
241
|
m.counter("plan_cache_recurrence_total", "Finished tasks whose objective recurs vs scope history, by hit (true/false)");
|
|
215
242
|
m.histogram("plan_cache_qsig", "Significant-token count of task objectives (qSig length)", [1, 2, 3, 5, 10, 20]);
|
|
243
|
+
// Memory consolidation (1.62 B-full): the reconcile-LLM store writes, by op. A spike in update/delete is
|
|
244
|
+
// the prod signal for over-merging / a mis-calibrated band. Recorded by the store on each call, so it does
|
|
245
|
+
// NOT need the fire-and-forget consolidation() to be awaited.
|
|
216
246
|
m.counter("memory_consolidation_ops_total", "Memory consolidation store ops (1.62 B-full), by op (update/delete)");
|
|
217
247
|
m.counter("mcp_server_unavailable_total", "MCP servers skipped fail-open at task start (1.68), unreachable/misconfigured");
|
|
248
|
+
// Remote execution env (design/48 E2B adapter): lifecycle outcomes by provider/result.
|
|
218
249
|
m.counter("remote_env_connect_total", "E2B remote-env connect outcomes (provider/result)");
|
|
219
250
|
m.counter("remote_env_destroy_total", "E2B remote-env destroy outcomes (provider/result)");
|
|
220
251
|
m.counter("remote_env_suspend_total", "E2B remote-env suspendVM outcomes (v1.5, provider/result)");
|
|
221
252
|
m.counter("remote_env_resume_total", "E2B remote-env resumeVM outcomes (v1.5, provider/result)");
|
|
222
253
|
m.counter("remote_env_exec_stream_read_timeout_total", "E2B execStream idle read-timeouts (#1128, provider)");
|
|
254
|
+
// E18 resume-at: a per-turn anchor capture (getLeafId→put) failed (e.g. an un-migrated DB missing resume_anchor) —
|
|
255
|
+
// best-effort, never fails the run; this surfaces a SYSTEMATIC capture outage instead of a silent feature stoppage.
|
|
223
256
|
m.counter("resume_anchor_capture_failed", "E18 resume-at per-turn anchor captures that failed (best-effort, run unaffected)");
|
|
257
|
+
// Silent-fallback telemetry P0 batch (docs/design/SILENT-FALLBACK-TELEMETRY.md, service half):
|
|
258
|
+
// S4 — brain-layer liveness phases (rate_limited/retrying/reconnecting/circuit_open) were previously visible
|
|
259
|
+
// only on the live SSE stream; count them so upstream throttling/outage is graphable per phase.
|
|
224
260
|
m.counter("brain_retry_total", "Brain-layer status events (S4), by phase (rate_limited/retrying/reconnecting/circuit_open)");
|
|
261
|
+
// S5 — the auto store-backend probe degraded this replica to in-memory at boot (configured DB unreachable).
|
|
262
|
+
// 1 = degraded (this replica is NOT persisting); scrape-level alert target. /health carries the twin flag.
|
|
225
263
|
m.gauge("store_backend_degraded", "1 when the auto DB probe failed at boot and this replica degraded to in-memory (S5)");
|
|
264
|
+
// S6 — images submitted to a model whose declared input has no "image": core degrades them to text
|
|
265
|
+
// placeholders (1.233.1). Counted at submit so the silent modality drop is visible per model.
|
|
226
266
|
m.counter("images_omitted_total", "Tasks whose images will be degraded to text placeholders (no-vision model), by model (S6)");
|
|
267
|
+
// S7 — background reapers: how many rows each sweep actually flipped (previously discarded), by kind.
|
|
268
|
+
// A spike = an instance died and its orphans were batch-failed (distinguishable from organic failures).
|
|
227
269
|
m.counter("runs_reaped_total", "Run rows flipped by the background reapers (S7), by kind (stale/suspended/expired_checkpoint)");
|
|
228
270
|
m.counter("checkpoints_reaped_total", "Durable checkpoints expired by the backstop reaper (S7)");
|
|
229
271
|
m.counter("bakes_reaped_total", "Image bakes failed by the stale-lease reaper (S7)");
|
|
272
|
+
// S9 — cross-replica write-behind counters (rate limit / cost quota): flush/refresh failures previously
|
|
273
|
+
// vanished in a bare catch → the fleet silently degrades to per-replica counting. Streak gauge = current
|
|
274
|
+
// consecutive failures (0 = healthy); the total counts every failed attempt.
|
|
230
275
|
m.counter("counter_flush_failed_total", "Write-behind counter flush/refresh failures (S9), by table and kind");
|
|
231
276
|
m.gauge("counter_flush_fail_streak", "Current consecutive write-behind flush/refresh failures (S9), by table and kind");
|
|
277
|
+
// S14 — near-budget degrade was configured but DROPPED for this task (e.g. image task + text-only degrade
|
|
278
|
+
// target): the task keeps its main model and will hard-fail on cost instead. Previously undetectable.
|
|
232
279
|
m.counter("degrade_dropped_total", "Tasks whose near-budget degrade was dropped at submit (S14), by reason");
|
|
280
|
+
// Silent-fallback P1 batch (second sweep, same doc §P1):
|
|
281
|
+
// S18 — every brain call by provider+model; provider="unknown" = the routing layer fell through to the
|
|
282
|
+
// gateway default without a recognized provider (previously invisible).
|
|
233
283
|
m.counter("brain_calls_total", "Brain calls by provider/model (S18); provider=unknown = unrecognized routing fallthrough");
|
|
284
|
+
// S10 — DB wall-clock minus local wall-clock (ms, can be negative). The write-behind counters bucket on
|
|
285
|
+
// LOCAL floor(now/windowMs); replica clock skew splits a fleet window into disjoint buckets (soft-limit leak).
|
|
234
286
|
m.gauge("fleet_counter_bucket_skew_ms", "DB clock minus local clock in ms (S10) — skew splits cross-replica counter windows");
|
|
235
287
|
m.gauge("fleet_clock_probe_ok", "1 = last DB clock probe succeeded, 0 = failing (skew gauge is stale while 0)");
|
|
288
|
+
// S21 — which backend snapshot blobs actually land on (minio|sql). Partial MINIO_* config silently falls to sql.
|
|
236
289
|
m.gauge("snapshot_blob_backend", "1 on the active snapshot-blob backend series (S21), by backend (minio|sql)");
|
|
290
|
+
// S22 — memory embed/KNN runtime failures (boot said vector; runtime silently degrades to lexical).
|
|
237
291
|
m.counter("memory_embed_failed_total", "Memory embedding calls that failed at runtime (S22), by where (add/recall/consolidation)");
|
|
238
292
|
m.counter("memory_knn_query_failed_total", "Memory KNN searchScored queries that failed at runtime (S22)");
|
|
293
|
+
// LOW — dedup fold vs new insert (a fold UPDATEs the existing row; previously indistinguishable), and the
|
|
294
|
+
// dedup probe failing over to a plain INSERT.
|
|
239
295
|
m.counter("memory_dedup_folded_total", "Memory writes folded into an existing near-duplicate row (LOW)");
|
|
240
296
|
m.counter("memory_dedup_probe_failed_total", "Memory dedup KNN probes that failed and fell through to INSERT (LOW)");
|
|
297
|
+
// S24 — redaction rewrites by pattern (over/under-redaction previously had zero fingerprint).
|
|
241
298
|
m.counter("redactions_applied_total", "redactSecrets rewrites (S24), by pattern label");
|
|
299
|
+
// S25 — warm session-cache entries evicted by a cross-instance write (import/replace) while still cached.
|
|
242
300
|
m.counter("stale_cache_conflict_total", "Warm session-cache entries evicted by a cross-instance write while cached (S25)");
|
|
301
|
+
// LOW — cross-replica breaker write-through failures (advisory swallow previously silent).
|
|
243
302
|
m.counter("breaker_writethrough_failed_total", "Circuit-breaker cross-replica write-through failures (LOW), by backend");
|
|
303
|
+
// LOW — web-search provider returned a non-array payload (model silently gets zero results).
|
|
244
304
|
m.counter("web_search_bad_payload_total", "Web-search provider responses whose results field was not an array (LOW), by provider");
|
|
305
|
+
// 收账批(2026-07-08):这 15 个计数器一直只有 inc 没注册 — 在 auto-register 落地前
|
|
306
|
+
// 整批从未上过 /metrics(inc 曾对未注册名静默 no-op)。补显式注册拿正经 HELP 文案。
|
|
245
307
|
m.counter("permission_denied_total", "Tool-gate denials by source (policy/hook/plan-mode; goal B4 always-on deny meter)");
|
|
246
308
|
m.counter("compaction_events_total", "Compaction lifecycle events by outcome (started/completed/failed/skipped) and trigger");
|
|
247
309
|
m.counter("hook_llm_calls_total", "prompt/agent hook entries that completed a model call (hooks 3b), by type");
|
|
@@ -257,6 +319,7 @@ export function createMetrics() {
|
|
|
257
319
|
m.counter("remote_env_rpc_timeout_total", "Remote-env RPC timeouts, by provider");
|
|
258
320
|
m.counter("task_outcomes_total", "Task outcome-ledger rows recorded, by status and oracle green flag");
|
|
259
321
|
m.counter("workflow_runs_total", "Self-orchestration workflow runs, by status");
|
|
322
|
+
// 鉴权桥 verify 延迟:热路径(kid 命中)亚毫秒;冷路径(JWKS 拉取)带网络 RTT——首请求/轮换尾延迟可见。
|
|
260
323
|
m.histogram("auth_bridge_verify_seconds", "Registry SSO JWT verify latency (hot path sub-ms; cold path includes a JWKS fetch)", [0.001, 0.005, 0.02, 0.1, 0.5, 2, 10]);
|
|
261
324
|
return m;
|
|
262
325
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OTLP/HTTP metrics exporter (core 1.37 observability seam) — DEPENDENCY-FREE. core stays SDK-free and
|
|
3
|
+
* the deployment owns export; rather than pull in the OpenTelemetry SDK (a concern for the intranet
|
|
4
|
+
* mirror + the bun-compiled binary), we periodically snapshot the in-process registry and POST it to an
|
|
5
|
+
* OTLP collector as OTLP/JSON `ExportMetricsServiceRequest`. Enabled only when `OTEL_EXPORTER_OTLP_ENDPOINT`
|
|
6
|
+
* is set; otherwise zero overhead. Prometheus /metrics is unaffected — both can run side by side.
|
|
7
|
+
*/
|
|
1
8
|
import type { MetricSnapshot } from "./metrics.js";
|
|
9
|
+
/** Build the OTLP/JSON metrics payload from a registry snapshot. Pure → unit-testable. */
|
|
2
10
|
export declare function buildOtlpPayload(snap: MetricSnapshot, opts: {
|
|
3
11
|
serviceName: string;
|
|
4
12
|
startMs: number;
|
|
@@ -29,6 +37,7 @@ export interface OtlpExporterOptions {
|
|
|
29
37
|
fetchImpl?: typeof fetch;
|
|
30
38
|
onError?: (err: unknown) => void;
|
|
31
39
|
}
|
|
40
|
+
/** Start the periodic push loop (unref'd so it never holds the process open). Returns a stop handle. */
|
|
32
41
|
export declare function startOtlpExporter(metrics: {
|
|
33
42
|
snapshot(): MetricSnapshot;
|
|
34
43
|
}, opts: OtlpExporterOptions): {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
const CUMULATIVE = 2;
|
|
1
|
+
const CUMULATIVE = 2; // OTel AggregationTemporality.CUMULATIVE
|
|
2
|
+
/** uint64 nanos as a string (OTLP/JSON encodes 64-bit ints as strings; ms×1e6 overflows Number). */
|
|
2
3
|
const nano = (ms) => (BigInt(ms) * 1000000n).toString();
|
|
3
4
|
const attrs = (labels) => Object.entries(labels).map(([key, v]) => ({ key, value: { stringValue: String(v) } }));
|
|
5
|
+
/** Build the OTLP/JSON metrics payload from a registry snapshot. Pure → unit-testable. */
|
|
4
6
|
export function buildOtlpPayload(snap, opts) {
|
|
5
7
|
const start = nano(opts.startMs);
|
|
6
8
|
const now = nano(opts.nowMs);
|
|
@@ -35,13 +37,15 @@ export function buildOtlpPayload(snap, opts) {
|
|
|
35
37
|
description: h.help,
|
|
36
38
|
histogram: {
|
|
37
39
|
dataPoints: h.series.map((s) => {
|
|
40
|
+
// our buckets are CUMULATIVE (Prometheus-style: counts[i] = #obs ≤ bounds[i]); OTLP wants
|
|
41
|
+
// PER-bucket counts with a trailing +Inf overflow bucket (length = bounds.length + 1).
|
|
38
42
|
const bucketCounts = [];
|
|
39
43
|
let prev = 0;
|
|
40
44
|
for (let i = 0; i < h.buckets.length; i++) {
|
|
41
45
|
bucketCounts.push(String(s.counts[i] - prev));
|
|
42
46
|
prev = s.counts[i];
|
|
43
47
|
}
|
|
44
|
-
bucketCounts.push(String(s.count - prev));
|
|
48
|
+
bucketCounts.push(String(s.count - prev)); // +Inf
|
|
45
49
|
return { attributes: attrs(s.labels), startTimeUnixNano: start, timeUnixNano: now, count: String(s.count), sum: s.sum, bucketCounts, explicitBounds: h.buckets };
|
|
46
50
|
}),
|
|
47
51
|
aggregationTemporality: CUMULATIVE,
|
|
@@ -57,10 +61,14 @@ export function buildOtlpPayload(snap, opts) {
|
|
|
57
61
|
],
|
|
58
62
|
};
|
|
59
63
|
}
|
|
64
|
+
/** Start the periodic push loop (unref'd so it never holds the process open). Returns a stop handle. */
|
|
60
65
|
export function startOtlpExporter(metrics, opts) {
|
|
61
66
|
const startMs = Date.now();
|
|
62
67
|
const url = `${opts.endpoint}/v1/metrics`;
|
|
63
68
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
69
|
+
// A collector that accepts the connection but never responds would otherwise let one fetch per tick pile
|
|
70
|
+
// up (each holding a full snapshot payload + socket) — bound each request and skip a tick while one is
|
|
71
|
+
// still in flight, so a half-dead collector can never accumulate back-pressure inside the process.
|
|
64
72
|
let inFlight = false;
|
|
65
73
|
const exportOnce = async () => {
|
|
66
74
|
if (inFlight)
|
|
@@ -78,7 +86,7 @@ export function startOtlpExporter(metrics, opts) {
|
|
|
78
86
|
opts.onError?.(new Error(`OTLP export HTTP ${res.status}`));
|
|
79
87
|
}
|
|
80
88
|
catch (err) {
|
|
81
|
-
opts.onError?.(err);
|
|
89
|
+
opts.onError?.(err); // export is best-effort — a collector hiccup must never affect serving
|
|
82
90
|
}
|
|
83
91
|
finally {
|
|
84
92
|
inFlight = false;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-principal execution context (AsyncLocalStorage). The brain-call tracer fires for EVERY model
|
|
3
|
+
* call — including council/team sub-tasks that run on the shared `subRunner` (a per-task tracer can't
|
|
4
|
+
* reach those). To attribute spend to the right principal we wrap a task's execution in this ALS:
|
|
5
|
+
* `node:async_hooks` propagates the store through every `await`, so a sub-task spawned inside a tool
|
|
6
|
+
* call still reads the originating principal. Absent store = unattributed (dev / no principal).
|
|
7
|
+
*/
|
|
1
8
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
9
|
export declare const principalContext: AsyncLocalStorage<string>;
|
|
10
|
+
/** Run `fn` with `principal` as the ambient context (no-op wrapper when principal is undefined). */
|
|
3
11
|
export declare function withPrincipal<T>(principal: string | undefined, fn: () => T): T;
|
|
12
|
+
/** The principal attributed to the current async execution, if any. */
|
|
4
13
|
export declare function currentPrincipal(): string | undefined;
|
|
5
14
|
//# sourceMappingURL=principal-context.d.ts.map
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-principal execution context (AsyncLocalStorage). The brain-call tracer fires for EVERY model
|
|
3
|
+
* call — including council/team sub-tasks that run on the shared `subRunner` (a per-task tracer can't
|
|
4
|
+
* reach those). To attribute spend to the right principal we wrap a task's execution in this ALS:
|
|
5
|
+
* `node:async_hooks` propagates the store through every `await`, so a sub-task spawned inside a tool
|
|
6
|
+
* call still reads the originating principal. Absent store = unattributed (dev / no principal).
|
|
7
|
+
*/
|
|
1
8
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
9
|
export const principalContext = new AsyncLocalStorage();
|
|
10
|
+
/** Run `fn` with `principal` as the ambient context (no-op wrapper when principal is undefined). */
|
|
3
11
|
export function withPrincipal(principal, fn) {
|
|
4
12
|
return principal ? principalContext.run(principal, fn) : fn();
|
|
5
13
|
}
|
|
14
|
+
/** The principal attributed to the current async execution, if any. */
|
|
6
15
|
export function currentPrincipal() {
|
|
7
16
|
return principalContext.getStore();
|
|
8
17
|
}
|