@sema-agent/server 1.323.0 → 2.0.1
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/budget-tracing.d.ts +48 -0
- package/dist/boot/budget-tracing.js +86 -0
- package/dist/boot/config-center.d.ts +62 -0
- package/dist/boot/config-center.js +995 -0
- package/dist/boot/coordinators.d.ts +33 -0
- package/dist/boot/coordinators.js +97 -0
- package/dist/boot/execution-env.d.ts +26 -0
- package/dist/boot/execution-env.js +370 -0
- package/dist/boot/leader.d.ts +27 -0
- package/dist/boot/leader.js +81 -0
- package/dist/boot/reapers.d.ts +53 -0
- package/dist/boot/reapers.js +252 -0
- package/dist/boot/resolve-spec.d.ts +70 -0
- package/dist/boot/resolve-spec.js +1072 -0
- package/dist/boot/runner-deps.d.ts +101 -0
- package/dist/boot/runner-deps.js +343 -0
- package/dist/boot/runtime-caps.d.ts +21 -0
- package/dist/boot/runtime-caps.js +62 -0
- package/dist/boot/session-faces.d.ts +57 -0
- package/dist/boot/session-faces.js +157 -0
- package/dist/boot/shutdown.d.ts +50 -0
- package/dist/boot/shutdown.js +129 -0
- package/dist/boot/stores.d.ts +32 -0
- package/dist/boot/stores.js +361 -0
- package/dist/boot/workflow-orchestration.d.ts +46 -0
- package/dist/boot/workflow-orchestration.js +150 -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 +585 -1
- package/dist/config.d.ts +78 -2
- package/dist/config.js +874 -301
- 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 +530 -2129
- 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/brain.d.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import { type Brain, type BreakerState } from "@sema-agent/core";
|
|
2
2
|
import type { ServiceConfig } from "./config-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build the external "Brain" (LLM) from config.
|
|
5
|
+
*
|
|
6
|
+
* Composition (A1 + the 1.38 resilience stack, ordered timeout-innermost → breaker → failover-outermost):
|
|
7
|
+
* - **Tiered timeouts** (1.38, `connectTimeoutMs`/`firstTokenTimeoutMs`) are passed into each
|
|
8
|
+
* openai-compatible brain at creation — they bound "gateway never accepts the connection" and
|
|
9
|
+
* "stream opened but hangs without a token" as retryable `[network]` failures. Default ON
|
|
10
|
+
* (30s/120s, [880] fleet audit; env =0 disables).
|
|
11
|
+
* - **Circuit breaker** (`createCircuitBreakerBrain`) wraps the *primary* gateway route(s) when
|
|
12
|
+
* `MODEL_CIRCUIT_BREAKER=true`: after N transient failures it opens and fast-fails, so failover
|
|
13
|
+
* switches to the bare backup immediately instead of waiting out each timeout. The last gateway
|
|
14
|
+
* route stays bare (last-resort) — matching core design/20. State is core's in-process Map (each
|
|
15
|
+
* replica trips independently; cross-replica shared state via a TiDB adapter is a follow-up).
|
|
16
|
+
* - **Failover** (`createFailoverBrain`) stacks the primary gateway with optional
|
|
17
|
+
* `MODEL_GATEWAY_FALLBACK_URLS` — same protocol, same model id, tried in order.
|
|
18
|
+
* - **Routing** (`createRoutingBrain`, by `model.provider`) selects the cloud Anthropic Messages
|
|
19
|
+
* route for `provider:"anthropic"`, and the gateway/failover stack for everything else. (Anthropic
|
|
20
|
+
* ↔ vLLM is a *routing* choice, not failover.)
|
|
21
|
+
*
|
|
22
|
+
* When no fallback URL, no Anthropic key, and no resilience thresholds are configured, this returns the
|
|
23
|
+
* bare openai brain (carrying the default-on watchdog timeouts — set the three env knobs to 0 for the
|
|
24
|
+
* pre-[880] fully-bare shape). The Model itself (id / contextWindow / maxTokens / provider) flows
|
|
25
|
+
* per-request through `Runner({ models })`.
|
|
26
|
+
*/
|
|
3
27
|
export declare function createBrain(config: ServiceConfig, deps?: {
|
|
4
28
|
fetchImpl?: typeof fetch;
|
|
5
29
|
breakerState?: BreakerState;
|
|
6
30
|
}): Brain;
|
|
31
|
+
/** One-line summary of the active brain composition, for the startup log. */
|
|
7
32
|
export declare function brainSummary(config: ServiceConfig): Record<string, unknown>;
|
|
8
33
|
//# sourceMappingURL=brain.d.ts.map
|
package/dist/brain.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { createAnthropicBrain, createCircuitBreakerBrain, createDegradingBrain, createFailoverBrain, createOpenAIBrain, createRoutingBrain, } from "@sema-agent/core";
|
|
2
2
|
const DEFAULT_RESILIENCE = {
|
|
3
|
+
// Watchdog defaults ON — mirrors config.ts env defaults so a config object without a
|
|
4
|
+
// resilience block gets the same posture. connect/firstToken per the [880] fleet audit
|
|
5
|
+
// (core's idle timer only arms after the first token, so firstToken is the sole guard for a
|
|
6
|
+
// stream that opens and never emits); idle = CC 196 parity. 0 restores off.
|
|
3
7
|
connectTimeoutMs: 30_000,
|
|
4
8
|
firstTokenTimeoutMs: 120_000,
|
|
5
9
|
idleTimeoutMs: 300_000,
|
|
@@ -7,30 +11,70 @@ const DEFAULT_RESILIENCE = {
|
|
|
7
11
|
failureThreshold: 5,
|
|
8
12
|
cooldownMs: 30_000,
|
|
9
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Build the external "Brain" (LLM) from config.
|
|
16
|
+
*
|
|
17
|
+
* Composition (A1 + the 1.38 resilience stack, ordered timeout-innermost → breaker → failover-outermost):
|
|
18
|
+
* - **Tiered timeouts** (1.38, `connectTimeoutMs`/`firstTokenTimeoutMs`) are passed into each
|
|
19
|
+
* openai-compatible brain at creation — they bound "gateway never accepts the connection" and
|
|
20
|
+
* "stream opened but hangs without a token" as retryable `[network]` failures. Default ON
|
|
21
|
+
* (30s/120s, [880] fleet audit; env =0 disables).
|
|
22
|
+
* - **Circuit breaker** (`createCircuitBreakerBrain`) wraps the *primary* gateway route(s) when
|
|
23
|
+
* `MODEL_CIRCUIT_BREAKER=true`: after N transient failures it opens and fast-fails, so failover
|
|
24
|
+
* switches to the bare backup immediately instead of waiting out each timeout. The last gateway
|
|
25
|
+
* route stays bare (last-resort) — matching core design/20. State is core's in-process Map (each
|
|
26
|
+
* replica trips independently; cross-replica shared state via a TiDB adapter is a follow-up).
|
|
27
|
+
* - **Failover** (`createFailoverBrain`) stacks the primary gateway with optional
|
|
28
|
+
* `MODEL_GATEWAY_FALLBACK_URLS` — same protocol, same model id, tried in order.
|
|
29
|
+
* - **Routing** (`createRoutingBrain`, by `model.provider`) selects the cloud Anthropic Messages
|
|
30
|
+
* route for `provider:"anthropic"`, and the gateway/failover stack for everything else. (Anthropic
|
|
31
|
+
* ↔ vLLM is a *routing* choice, not failover.)
|
|
32
|
+
*
|
|
33
|
+
* When no fallback URL, no Anthropic key, and no resilience thresholds are configured, this returns the
|
|
34
|
+
* bare openai brain (carrying the default-on watchdog timeouts — set the three env knobs to 0 for the
|
|
35
|
+
* pre-[880] fully-bare shape). The Model itself (id / contextWindow / maxTokens / provider) flows
|
|
36
|
+
* per-request through `Runner({ models })`.
|
|
37
|
+
*/
|
|
10
38
|
export function createBrain(config, deps = {}) {
|
|
11
39
|
const { fetchImpl, breakerState } = deps;
|
|
12
40
|
const r = config.resilience ?? DEFAULT_RESILIENCE;
|
|
41
|
+
// [1.207 codex H4] pass 0 THROUGH (never map to undefined): core 1.296's wall-clock lane supplies per-call
|
|
42
|
+
// stall suggestions merged `configValue ?? suggested` — an undefined field silently re-arms the watchdog a
|
|
43
|
+
// task-timeout run (idle would come back at 90s). An explicit 0 is core's documented "constructor-explicit
|
|
44
|
+
// disable, wins over suggestions"; 0 also disarms the timer on pre-1.296 arming code (`value > 0` guards).
|
|
13
45
|
const timeouts = {
|
|
14
46
|
connectTimeoutMs: r.connectTimeoutMs,
|
|
15
47
|
firstTokenTimeoutMs: r.firstTokenTimeoutMs,
|
|
16
48
|
idleTimeoutMs: r.idleTimeoutMs,
|
|
17
49
|
};
|
|
50
|
+
// Local openai-compatible gateway stack: primary + optional same-protocol fallbacks (failover).
|
|
18
51
|
const routes = [config.gatewayBaseUrl, ...config.gatewayFallbackUrls];
|
|
19
52
|
const openaiBrains = routes.map((baseUrl, i) => {
|
|
20
53
|
const brain = createOpenAIBrain({ baseUrl, apiKey: config.gatewayApiKey, maxRetries: 2, fetchImpl, ...timeouts });
|
|
54
|
+
// Breaker on every route EXCEPT the last (the bare last-resort backup), and only with ≥2 routes —
|
|
55
|
+
// a breaker without a failover alternative would just hard-fail the only gateway during cooldown.
|
|
21
56
|
const isLast = i === routes.length - 1;
|
|
22
57
|
return r.circuitBreaker && !isLast
|
|
23
58
|
? createCircuitBreakerBrain(brain, {
|
|
24
59
|
failureThreshold: r.failureThreshold,
|
|
25
60
|
cooldownMs: r.cooldownMs,
|
|
26
|
-
state: breakerState,
|
|
61
|
+
state: breakerState, // shared cross-replica state when provided; else core's in-process Map
|
|
62
|
+
// L14(接入审计):core 默认 key=`<provider>:<id>`(与 baseUrl 无关)——≥3 路由时 routes[0..n-2]
|
|
63
|
+
// 命中同一 breaker 条目,一条网关的故障计入另一条的阈值(失 per-route 隔离)。key 掺入本路由
|
|
64
|
+
// baseUrl 恢复隔离;1-2 路由行为不变(只有一个带 breaker 的路由)。
|
|
27
65
|
key: (m) => `${m.provider ?? "openai"}:${m.id}@${baseUrl}`,
|
|
28
66
|
})
|
|
29
67
|
: brain;
|
|
30
68
|
});
|
|
31
69
|
const gatewayBrain = openaiBrains.length > 1 ? createFailoverBrain(openaiBrains) : openaiBrains[0];
|
|
70
|
+
// Route by model.provider: "anthropic" → cloud Messages API (prompt caching + thinking replay),
|
|
71
|
+
// everything else → the local gateway stack (also the fallback for an unrecognized provider).
|
|
32
72
|
const anthropicBrain = config.anthropic
|
|
33
73
|
? createAnthropicBrain({
|
|
74
|
+
// Anthropic-compatible Bearer auth: `ANTHROPIC_AUTH_TOKEN` → `Authorization: Bearer`
|
|
75
|
+
// via core's extra-`headers` seam, and apiKey is then NOT passed (x-api-key only emits when set) —
|
|
76
|
+
// 二选一, AUTH_TOKEN priority. Bearer-first providers in this ecosystem commonly accept only
|
|
77
|
+
// the Bearer form.
|
|
34
78
|
...(config.anthropic.authToken
|
|
35
79
|
? { headers: { Authorization: `Bearer ${config.anthropic.authToken}` } }
|
|
36
80
|
: { apiKey: config.anthropic.apiKey }),
|
|
@@ -42,12 +86,24 @@ export function createBrain(config, deps = {}) {
|
|
|
42
86
|
...timeouts,
|
|
43
87
|
})
|
|
44
88
|
: undefined;
|
|
89
|
+
// No cloud route + single gateway → bare brain (unchanged); else route by provider.
|
|
45
90
|
let brain = anthropicBrain
|
|
46
91
|
? createRoutingBrain({ anthropic: anthropicBrain }, { fallback: gatewayBrain })
|
|
47
92
|
: gatewayBrain;
|
|
93
|
+
// Reactive degradation (1.39) — wrapped OUTERMOST (core council #8): on rate_limit / breaker-open from
|
|
94
|
+
// the primary, serve a cheaper catalog model instead of failing. The fallback brain carries its own
|
|
95
|
+
// credentials (the decorator clears the primary's per-call apiKey so it can't leak to a different
|
|
96
|
+
// provider). fallbackModel resolved from the catalog.
|
|
48
97
|
if (config.degrade?.reactive) {
|
|
49
98
|
const fallbackModel = config.models[config.degrade.to];
|
|
50
99
|
if (fallbackModel) {
|
|
100
|
+
// Cross-gateway degrade (audit B, brain.ts): the degrading decorator clears the per-call apiKey
|
|
101
|
+
// (so the primary's key can't leak to another provider), which left the fallback authenticating
|
|
102
|
+
// with the PRIMARY gateway key even when the catalog points the target at a different gateway.
|
|
103
|
+
// Resolve the target's own key at construction via the existing per-model apiKeyEnv mechanism
|
|
104
|
+
// (sema-registry catalog); `model.baseUrl` already wins inside the openai brain — pass it
|
|
105
|
+
// explicitly so the route is visible here. Unset catalog baseUrl/apiKeyEnv = same-gateway degrade
|
|
106
|
+
// (unchanged), which stays meaningful for per-model limits (e.g. deepseek pro→flash).
|
|
51
107
|
const fbKeyEnv = config.modelApiKeyEnv?.[fallbackModel.name] ?? config.modelApiKeyEnv?.[config.degrade.to];
|
|
52
108
|
const fbApiKey = (fbKeyEnv ? process.env[fbKeyEnv] : undefined) || config.gatewayApiKey;
|
|
53
109
|
const fallback = fallbackModel.provider === "anthropic" && anthropicBrain
|
|
@@ -58,9 +114,11 @@ export function createBrain(config, deps = {}) {
|
|
|
58
114
|
}
|
|
59
115
|
return brain;
|
|
60
116
|
}
|
|
117
|
+
/** One-line summary of the active brain composition, for the startup log. */
|
|
61
118
|
export function brainSummary(config) {
|
|
62
119
|
const r = config.resilience ?? DEFAULT_RESILIENCE;
|
|
63
120
|
const hasFailover = config.gatewayFallbackUrls.length > 0;
|
|
121
|
+
// The breaker only does anything with ≥2 gateway routes (it pairs with failover); flag a no-op config.
|
|
64
122
|
const breakerActive = r.circuitBreaker && hasFailover;
|
|
65
123
|
return {
|
|
66
124
|
gateway: config.gatewayBaseUrl,
|
|
@@ -74,7 +132,9 @@ export function brainSummary(config) {
|
|
|
74
132
|
circuitBreaker: breakerActive,
|
|
75
133
|
circuitBreakerRequested: r.circuitBreaker,
|
|
76
134
|
circuitBreakerNoop: r.circuitBreaker && !hasFailover ? "needs ≥2 gateway routes" : null,
|
|
135
|
+
// reactive degrade is active only if a valid catalog target resolves
|
|
77
136
|
reactiveDegradeTo: config.degrade?.reactive && config.models?.[config.degrade.to] ? config.degrade.to : null,
|
|
137
|
+
// cross-gateway degrade visibility: the fallback's effective route (null = degrade off)
|
|
78
138
|
reactiveDegradeBaseUrl: config.degrade?.reactive && config.models?.[config.degrade.to]
|
|
79
139
|
? config.models[config.degrade.to].baseUrl || config.gatewayBaseUrl
|
|
80
140
|
: null,
|
package/dist/budget.d.ts
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost / budget / trace wiring for the Runner (core 1.37) — pure, testable helpers kept out of the
|
|
3
|
+
* auto-running main.ts:
|
|
4
|
+
* ③ buildPricing — Model.cost catalog → injected ModelPricing (authoritative costMicroUsd).
|
|
5
|
+
* ④ createTracer — core's content-free TraceEvents → /metrics (spend, first-token, tool calls).
|
|
6
|
+
* ⑤ cappedCeiling — clamp a caller's requested per-task budget DOWN to the operator ceiling.
|
|
7
|
+
*/
|
|
1
8
|
import { type Model, type ModelPricing, type TracerHook } from "@sema-agent/core";
|
|
2
9
|
import type { Metrics } from "./observability/metrics.js";
|
|
3
10
|
import type { QuotaTracker } from "./observability/cost-quota.js";
|
|
4
11
|
import type { FleetUsageAccumulator } from "./fleet-client.js";
|
|
5
12
|
import type { FleetLeaseManager } from "./fleet-lease.js";
|
|
6
13
|
import { type PromptManifestTracker } from "./observability/prompt-manifest.js";
|
|
14
|
+
/** ③ Per-model pricing keyed by model id (core falls back to each Model.cost when a model is absent). */
|
|
7
15
|
export declare function buildPricing(models: Record<string, Model>): Record<string, ModelPricing>;
|
|
16
|
+
/**
|
|
17
|
+
* Bound the cardinality of a free-form metric label value (BL-11/BL-21). A label fed by untrusted/unbounded
|
|
18
|
+
* input — MCP tool names (a misconfigured/malicious server can emit thousands of dynamic names) or center
|
|
19
|
+
* model ids (a malformed roster) — would otherwise mint an unbounded number of metric series: a slow memory
|
|
20
|
+
* leak in the registry + a /metrics scrape blow-up. We track the DISTINCT values seen; once the cap is hit,
|
|
21
|
+
* further NEW values collapse into one `__other__` bucket (already-seen values still report exactly). The
|
|
22
|
+
* cap is made observable (no silent truncation) via `onOverflow`, fired once when the cap is first crossed.
|
|
23
|
+
*/
|
|
8
24
|
export declare function cardinalityGuard(cap: number, onOverflow: () => void): (value: string) => string;
|
|
25
|
+
/** Per-model usage accumulated for one task (shell-host contract E8). Token names mirror `turn_end.usage` /
|
|
26
|
+
* the contract's per-model entry; `costMicroUsd` is micro-USD (÷1e6 for USD). */
|
|
9
27
|
export interface ModelUsageDelta {
|
|
10
28
|
inputTokens: number;
|
|
11
29
|
outputTokens: number;
|
|
@@ -13,16 +31,59 @@ export interface ModelUsageDelta {
|
|
|
13
31
|
cacheWriteTokens: number;
|
|
14
32
|
costMicroUsd: number;
|
|
15
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* E8 (shell-host contract): per-task × per-model usage accumulator, fed (synchronously) by the `brain.call`
|
|
36
|
+
* tracer. The `TracerHook` contract is SYNC / no-IO, so we cannot persist from the hook; instead we accumulate
|
|
37
|
+
* here in memory and the run lifecycle DRAINS us at each turn boundary, appending the delta to the durable run
|
|
38
|
+
* event log. The **append-only delta** model is what makes it resume-safe: a task that suspends and resumes in a
|
|
39
|
+
* different process appends only its own post-resume deltas; the result echo SUMS all `model_usage` events across
|
|
40
|
+
* the whole (possibly multi-process) run. Memory is bounded — a task's entry is dropped on {@link drain}/{@link clear}.
|
|
41
|
+
*/
|
|
16
42
|
export declare class ModelUsageTracker {
|
|
17
43
|
private readonly byTask;
|
|
18
44
|
private readonly active;
|
|
45
|
+
/** Mark a TOP-LEVEL run active so its `brain.call` usage is tracked. **Required** — `record` ignores any taskId
|
|
46
|
+
* that isn't registered. This is the leak fence: delegated SUB-TASKS (team members,
|
|
47
|
+
* adversarial verifiers) run on throwaway core-minted sessionIds that the run lifecycle never registers/drains,
|
|
48
|
+
* so without this gate their usage would accumulate under ids nothing ever clears → an unbounded process-lifetime
|
|
49
|
+
* leak. Sub-task spend is intentionally NOT in the per-run `modelUsage` echo (it lands in `TaskStats.nested`);
|
|
50
|
+
* `modelUsage` is the TOP-LEVEL run's own per-model usage. Call at run start; {@link clear} unregisters. */
|
|
19
51
|
register(taskId: string): void;
|
|
52
|
+
/** Accumulate one `brain.call`'s usage — ONLY for a registered top-level run (else a no-op; see {@link register}).
|
|
53
|
+
* Sync, never throws (TracerHook contract). */
|
|
20
54
|
record(taskId: string, model: string, d: ModelUsageDelta): void;
|
|
55
|
+
/** Return the usage accumulated for this task SINCE the last drain (per neutral model id), and RESET it.
|
|
56
|
+
* `undefined` when nothing accrued — callers skip the durable append then. */
|
|
21
57
|
drain(taskId: string): Record<string, ModelUsageDelta> | undefined;
|
|
58
|
+
/** Drop a task's pending accumulation AND unregister it (cleanup at run end / on an abandoned/errored leg). After
|
|
59
|
+
* this, further `record(taskId,…)` no-ops until a fresh {@link register}. `drain` deliberately does NOT unregister
|
|
60
|
+
* (the run continues across turns); only `clear` ends the run's tracking. */
|
|
22
61
|
clear(taskId: string): void;
|
|
23
62
|
}
|
|
24
63
|
export { type PromptManifestRecord, promptManifestRecordOf, configAssembledRecordOf, PromptManifestTracker, } from "./observability/prompt-manifest.js";
|
|
64
|
+
/**
|
|
65
|
+
* ④ Bridge core's fire-and-forget trace events to /metrics (+ the E8 per-task model-usage accumulator). The hook
|
|
66
|
+
* is void / never throws / does no sync IO (in-memory counters only), per the TracerHook contract. `brain.call`
|
|
67
|
+
* fires for EVERY call (top-level + async + council sub-tasks) → `model_cost_micro_usd_total` is the authoritative
|
|
68
|
+
* spend, and (when a {@link ModelUsageTracker} is supplied) the per-task `modelUsage` echo's source.
|
|
69
|
+
*/
|
|
25
70
|
export declare function createTracer(metrics: Pick<Metrics, "inc" | "observe">, costQuota?: QuotaTracker, modelUsage?: ModelUsageTracker, fleetUsage?: FleetUsageAccumulator, fleetLease?: FleetLeaseManager, quotaWeightFor?: (model: string) => number, promptManifests?: PromptManifestTracker): TracerHook;
|
|
71
|
+
/**
|
|
72
|
+
* [1469] side-query 记账 seam(codex R3 high:sideQuery 不走 core tracer——brain.stream 直调不发
|
|
73
|
+
* brain.call——createTracer 的四路 sink(costQuota/model_cost 指标/fleetUsage 批报/fleetLease 本地扣减)
|
|
74
|
+
* 全部旁路)。本 seam 与 createTracer 的 brain.call 臂**同语义**喂同一组 sink:weightedTokens 同式
|
|
75
|
+
* (tokens×quotaWeight,weight-at-burn 固化)、micro-USD 同轴。装配点与 createTracer 同一处(main.ts),
|
|
76
|
+
* 传同一组实例——两臂永不分家。
|
|
77
|
+
*
|
|
78
|
+
* 已知残差(codex R3 medium,记档):cost 源=core SideQueryResult.usage.cost.total(brain 层计价),
|
|
79
|
+
* OpenAI cache-heavy 输入按全价入账(tracer 的 e.costMicroUsd 是 cache-family-aware 价)——方向=多收
|
|
80
|
+
* (保守,绝不少收);根修=core 在 SideQueryResult 上回权威 costMicroUsd(已提货 core)。model 标签/
|
|
81
|
+
* weight 键用**路由身份 r.model**(池配置有界)非 servedModel(provider 上报,无界)。
|
|
82
|
+
*/
|
|
83
|
+
/** core `usage-accounting.cacheFamilyOf` 的私拷镜像(core exports map 只开 barrel,该函数未导出——
|
|
84
|
+
* 已提货 core barrel 导出,到货即换,normalizeAgentName 同款纪律)。逐字对拍源:
|
|
85
|
+
* dist/core/runner/usage-accounting.js(override 别名 anthropic/openai + api 判 anthropic-messages/
|
|
86
|
+
* bedrock-converse-stream)。undefined 入参(catalog 查不到)→ undefined,调用方走保守臂。 */
|
|
26
87
|
export declare function cacheFamilyOfMirror(model: {
|
|
27
88
|
api?: string;
|
|
28
89
|
params?: {
|
|
@@ -42,5 +103,10 @@ export declare function createSideQueryAccountant(metrics: Pick<Metrics, "inc">,
|
|
|
42
103
|
};
|
|
43
104
|
};
|
|
44
105
|
}) => void;
|
|
106
|
+
/**
|
|
107
|
+
* ⑤ Resolve a per-task budget: honor the caller's requested value but never let it EXCEED the operator
|
|
108
|
+
* ceiling. `0`/unset ceiling = no limit (returns the caller's value, or undefined). A non-positive /
|
|
109
|
+
* non-numeric request is ignored (falls back to the ceiling). Returns undefined = "no budget gate".
|
|
110
|
+
*/
|
|
45
111
|
export declare function cappedCeiling(requested: unknown, ceiling: number): number | undefined;
|
|
46
112
|
//# sourceMappingURL=budget.d.ts.map
|
package/dist/budget.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost / budget / trace wiring for the Runner (core 1.37) — pure, testable helpers kept out of the
|
|
3
|
+
* auto-running main.ts:
|
|
4
|
+
* ③ buildPricing — Model.cost catalog → injected ModelPricing (authoritative costMicroUsd).
|
|
5
|
+
* ④ createTracer — core's content-free TraceEvents → /metrics (spend, first-token, tool calls).
|
|
6
|
+
* ⑤ cappedCeiling — clamp a caller's requested per-task budget DOWN to the operator ceiling.
|
|
7
|
+
*/
|
|
1
8
|
import { modelCostToPricing } from "@sema-agent/core";
|
|
2
9
|
import { currentPrincipal } from "./observability/principal-context.js";
|
|
3
|
-
import { promptManifestRecordOf, configAssembledRecordOf } from "./observability/prompt-manifest.js";
|
|
10
|
+
import { promptManifestRecordOf, configAssembledRecordOf } from "./observability/prompt-manifest.js"; // design/158 N18: see re-export block below (moved to ./observability/prompt-manifest.js)
|
|
11
|
+
/** ③ Per-model pricing keyed by model id (core falls back to each Model.cost when a model is absent). */
|
|
4
12
|
export function buildPricing(models) {
|
|
5
13
|
const pricing = {};
|
|
6
14
|
for (const m of Object.values(models))
|
|
@@ -8,6 +16,14 @@ export function buildPricing(models) {
|
|
|
8
16
|
pricing[m.id] = modelCostToPricing(m.cost);
|
|
9
17
|
return pricing;
|
|
10
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Bound the cardinality of a free-form metric label value (BL-11/BL-21). A label fed by untrusted/unbounded
|
|
21
|
+
* input — MCP tool names (a misconfigured/malicious server can emit thousands of dynamic names) or center
|
|
22
|
+
* model ids (a malformed roster) — would otherwise mint an unbounded number of metric series: a slow memory
|
|
23
|
+
* leak in the registry + a /metrics scrape blow-up. We track the DISTINCT values seen; once the cap is hit,
|
|
24
|
+
* further NEW values collapse into one `__other__` bucket (already-seen values still report exactly). The
|
|
25
|
+
* cap is made observable (no silent truncation) via `onOverflow`, fired once when the cap is first crossed.
|
|
26
|
+
*/
|
|
11
27
|
export function cardinalityGuard(cap, onOverflow) {
|
|
12
28
|
const seen = new Set();
|
|
13
29
|
let overflowed = false;
|
|
@@ -25,11 +41,27 @@ export function cardinalityGuard(cap, onOverflow) {
|
|
|
25
41
|
return value;
|
|
26
42
|
};
|
|
27
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* E8 (shell-host contract): per-task × per-model usage accumulator, fed (synchronously) by the `brain.call`
|
|
46
|
+
* tracer. The `TracerHook` contract is SYNC / no-IO, so we cannot persist from the hook; instead we accumulate
|
|
47
|
+
* here in memory and the run lifecycle DRAINS us at each turn boundary, appending the delta to the durable run
|
|
48
|
+
* event log. The **append-only delta** model is what makes it resume-safe: a task that suspends and resumes in a
|
|
49
|
+
* different process appends only its own post-resume deltas; the result echo SUMS all `model_usage` events across
|
|
50
|
+
* the whole (possibly multi-process) run. Memory is bounded — a task's entry is dropped on {@link drain}/{@link clear}.
|
|
51
|
+
*/
|
|
28
52
|
export class ModelUsageTracker {
|
|
29
53
|
byTask = new Map();
|
|
30
54
|
active = new Set();
|
|
55
|
+
/** Mark a TOP-LEVEL run active so its `brain.call` usage is tracked. **Required** — `record` ignores any taskId
|
|
56
|
+
* that isn't registered. This is the leak fence: delegated SUB-TASKS (team members,
|
|
57
|
+
* adversarial verifiers) run on throwaway core-minted sessionIds that the run lifecycle never registers/drains,
|
|
58
|
+
* so without this gate their usage would accumulate under ids nothing ever clears → an unbounded process-lifetime
|
|
59
|
+
* leak. Sub-task spend is intentionally NOT in the per-run `modelUsage` echo (it lands in `TaskStats.nested`);
|
|
60
|
+
* `modelUsage` is the TOP-LEVEL run's own per-model usage. Call at run start; {@link clear} unregisters. */
|
|
31
61
|
register(taskId) { if (taskId)
|
|
32
62
|
this.active.add(taskId); }
|
|
63
|
+
/** Accumulate one `brain.call`'s usage — ONLY for a registered top-level run (else a no-op; see {@link register}).
|
|
64
|
+
* Sync, never throws (TracerHook contract). */
|
|
33
65
|
record(taskId, model, d) {
|
|
34
66
|
if (!taskId || !model || !this.active.has(taskId))
|
|
35
67
|
return;
|
|
@@ -50,6 +82,8 @@ export class ModelUsageTracker {
|
|
|
50
82
|
perModel.set(model, { ...d });
|
|
51
83
|
}
|
|
52
84
|
}
|
|
85
|
+
/** Return the usage accumulated for this task SINCE the last drain (per neutral model id), and RESET it.
|
|
86
|
+
* `undefined` when nothing accrued — callers skip the durable append then. */
|
|
53
87
|
drain(taskId) {
|
|
54
88
|
const perModel = this.byTask.get(taskId);
|
|
55
89
|
if (!perModel || perModel.size === 0)
|
|
@@ -60,27 +94,60 @@ export class ModelUsageTracker {
|
|
|
60
94
|
this.byTask.delete(taskId);
|
|
61
95
|
return out;
|
|
62
96
|
}
|
|
97
|
+
/** Drop a task's pending accumulation AND unregister it (cleanup at run end / on an abandoned/errored leg). After
|
|
98
|
+
* this, further `record(taskId,…)` no-ops until a fresh {@link register}. `drain` deliberately does NOT unregister
|
|
99
|
+
* (the run continues across turns); only `clear` ends the run's tracking. */
|
|
63
100
|
clear(taskId) { this.byTask.delete(taskId); this.active.delete(taskId); }
|
|
64
101
|
}
|
|
102
|
+
// design/158 N18: PromptManifestRecord / promptManifestRecordOf / configAssembledRecordOf / PromptManifestTracker
|
|
103
|
+
// moved VERBATIM to ./observability/prompt-manifest.js (budget.ts's name says cost/budget; this face is
|
|
104
|
+
// wire-observability projection of prompt.assembled/config.assembled, unrelated). Re-exported here so existing
|
|
105
|
+
// importers (main.ts, runs.ts, http/server.ts, trace/project.ts, tests) keep working untouched — createTracer
|
|
106
|
+
// below still consumes promptManifestRecordOf/configAssembledRecordOf/PromptManifestTracker.
|
|
65
107
|
export { promptManifestRecordOf, configAssembledRecordOf, PromptManifestTracker, } from "./observability/prompt-manifest.js";
|
|
108
|
+
/**
|
|
109
|
+
* ④ Bridge core's fire-and-forget trace events to /metrics (+ the E8 per-task model-usage accumulator). The hook
|
|
110
|
+
* is void / never throws / does no sync IO (in-memory counters only), per the TracerHook contract. `brain.call`
|
|
111
|
+
* fires for EVERY call (top-level + async + council sub-tasks) → `model_cost_micro_usd_total` is the authoritative
|
|
112
|
+
* spend, and (when a {@link ModelUsageTracker} is supplied) the per-task `modelUsage` echo's source.
|
|
113
|
+
*/
|
|
66
114
|
export function createTracer(metrics, costQuota, modelUsage, fleetUsage, fleetLease, quotaWeightFor, promptManifests) {
|
|
115
|
+
// Per-process cardinality guards for the two unbounded-input labels (BL-11/BL-21). 256 is generous for any
|
|
116
|
+
// real tool/model catalog; overflow bumps a counter so an over-cap deploy is observable, not silent.
|
|
67
117
|
const toolName = cardinalityGuard(256, () => metrics.inc("metric_label_overflow_total", { label: "tool_name" }));
|
|
68
118
|
const modelId = cardinalityGuard(256, () => metrics.inc("metric_label_overflow_total", { label: "model" }));
|
|
119
|
+
// provider flows from env/registry config (not a bounded enum) — guard it like modelId (1.127.0):
|
|
120
|
+
// a misconfigured registry entry must not explode Prometheus label cardinality. 64 is generous for real providers.
|
|
69
121
|
const providerName = cardinalityGuard(64, () => metrics.inc("metric_label_overflow_total", { label: "provider" }));
|
|
70
122
|
return (e) => {
|
|
71
123
|
if (e.kind === "brain.call") {
|
|
124
|
+
// S18 (SILENT-FALLBACK P1): count every call by provider+model. provider is optional on the trace event —
|
|
125
|
+
// "unknown" = the routing layer fell through without a recognized provider (previously unobservable).
|
|
72
126
|
metrics.inc("brain_calls_total", { provider: providerName(e.provider ?? "unknown"), model: modelId(e.model) });
|
|
73
127
|
if (e.costMicroUsd) {
|
|
74
128
|
metrics.inc("model_cost_micro_usd_total", { model: modelId(e.model) }, e.costMicroUsd);
|
|
129
|
+
// ⑤b attribute spend to the originating principal (ALS) — reaches council/team sub-tasks too.
|
|
75
130
|
const principal = currentPrincipal();
|
|
76
131
|
if (principal)
|
|
77
132
|
costQuota?.add(principal, e.costMicroUsd);
|
|
78
133
|
}
|
|
134
|
+
// E8 (shell-host): per-task × per-model usage for the `TaskStats.modelUsage` echo. `record` is a NO-OP unless
|
|
135
|
+
// e.taskId is a REGISTERED top-level run (the leak fence — sub-task/throwaway taskIds are never registered, so
|
|
136
|
+
// they neither leak nor enter the echo; their spend is in TaskStats.nested). Drained at turn boundaries into the
|
|
137
|
+
// durable log (resume-safe); the registered entry is dropped at run end (clear). NOT cardinality-guarded by
|
|
138
|
+
// model: bounded by a run's model set, and by the active-run set.
|
|
79
139
|
modelUsage?.record(e.taskId, e.model, { inputTokens: e.promptTokens, outputTokens: e.completionTokens, cacheReadTokens: e.cacheRead, cacheWriteTokens: e.cacheWrite, costMicroUsd: e.costMicroUsd ?? 0 });
|
|
140
|
+
// weight-at-burn:加权 tokens = (prompt+completion)×模型配额倍率,在记账点固化(此后改倍率
|
|
141
|
+
// 不回算历史,registry ModelEntry.quotaWeight 同句契约)。weight 源=config.modelQuotaWeights(registry
|
|
142
|
+
// hot-apply;env lane 空表 ⇒ 1 兜底);非法回调值防御性归 1(tracer 契约 never-throws,不让坏表毒记账)。
|
|
80
143
|
const qwRaw = quotaWeightFor?.(e.model);
|
|
81
144
|
const qw = typeof qwRaw === "number" && Number.isFinite(qwRaw) && qwRaw > 0 ? qwRaw : 1;
|
|
82
145
|
const weightedTokens = Math.round((e.promptTokens + e.completionTokens) * qw);
|
|
146
|
+
// P2 用量批报:principal×model 窗口累计(同 ⑤b 的 ALS 归因点 — 子任务花费也归到发起 principal),
|
|
147
|
+
// fleet-client 每窗口 drain→POST /api/fleet/usage。未配 fleet(accumulator 缺席)= 零行为。
|
|
83
148
|
fleetUsage?.record(currentPrincipal(), e.model, e.taskId, { inputTokens: e.promptTokens, outputTokens: e.completionTokens, costMicroUsd: e.costMicroUsd ?? 0, weightedTokens, quotaWeightAtUse: qw });
|
|
149
|
+
// lease 消费(D4 AP):同一 ALS 归因点做 lease 本地扣减 —— 只对当前持 lease 的 principal
|
|
150
|
+
// 生效(FleetLeaseManager 内部判),sync + never throws。双轴=weightedTokens(配额轴)+costMicroUsd($ 轴)。
|
|
84
151
|
fleetLease?.recordSpend(currentPrincipal(), { weightedTokens, costMicroUsd: e.costMicroUsd ?? 0 });
|
|
85
152
|
if (e.firstTokenMs !== undefined)
|
|
86
153
|
metrics.observe("brain_first_token_ms", e.firstTokenMs);
|
|
@@ -90,27 +157,75 @@ export function createTracer(metrics, costQuota, modelUsage, fleetUsage, fleetLe
|
|
|
90
157
|
metrics.inc("tool_calls_total", { name: toolName(e.name), ok: String(e.ok) });
|
|
91
158
|
}
|
|
92
159
|
else if (e.kind === "task.degraded") {
|
|
160
|
+
// 1.40: a task was switched to a cheaper model (near-budget / rate_limit / breaker-open). Quality
|
|
161
|
+
// dropped → alert-worthy operational signal, by reason.
|
|
93
162
|
metrics.inc("degraded_total", { reason: e.reason });
|
|
94
163
|
}
|
|
95
164
|
else if (e.kind === "prompt.assembled") {
|
|
165
|
+
// core 1.243(提示词主权批): who owned the constitution layer, per task. The
|
|
166
|
+
// steady state for EVERY service scenario is "core" (structural constitution — our providers all
|
|
167
|
+
// return role bases only). Anything else is worth eyes: "provider-assembled" = a pre-1.243-shaped
|
|
168
|
+
// provider tripped the migration guard (upgrade it); "replaced" = an explicit replaceAll opt-out
|
|
169
|
+
// (none exist in this repo today); "legacy" = a deprecated free-form `system` provider. Alert on
|
|
170
|
+
// `prompt_constitution_total{mode!="core"} > 0` — the "TOC lost its safety blocks and called it a
|
|
171
|
+
// config issue" failure class becomes a one-glance dashboard check.
|
|
96
172
|
metrics.inc("prompt_constitution_total", { mode: e.constitution });
|
|
173
|
+
// [998]② durable half: record the whitelisted manifest for the run lifecycle to drain into a
|
|
174
|
+
// `prompt_assembled` event (turns/stream). register-gated (top-level runs only), sync, never persists here.
|
|
97
175
|
promptManifests?.record(e.taskId, promptManifestRecordOf(e));
|
|
98
176
|
}
|
|
99
177
|
else if (e.kind === "config.assembled") {
|
|
178
|
+
// [1301]③:config catalog 观测半场——生效配置逐字段来源(default/spec/derived/host-declared+
|
|
179
|
+
// overrideReasons)随任务进 durable 事件日志(config_assembled),「谁设的 80」读帧不考古。
|
|
100
180
|
const rec = configAssembledRecordOf(e);
|
|
101
181
|
if (rec)
|
|
102
182
|
promptManifests?.recordConfig(e.taskId, rec);
|
|
103
183
|
}
|
|
104
184
|
else if (e.kind === "compaction.phase_timings") {
|
|
185
|
+
// codex F6: core 1.289's `compaction.phase_timings` fires on SUCCESS (per-phase timing telemetry) — it is
|
|
186
|
+
// NOT an outcome, so counting it into compaction_events_total would add a fake "phase_timings" failure
|
|
187
|
+
// outcome for every successful compaction (poisoning the "non-success outcomes" dashboard semantics
|
|
188
|
+
// documented below). Record the total duration on the existing observe face instead (the
|
|
189
|
+
// brain_call_latency_ms precedent); non-finite values are dropped (tracer never throws, never poisons).
|
|
190
|
+
// 三路复审修5 核查(workflow W5 报「histogram never」):duration 观测出口就在下一行(F6 起已在),
|
|
191
|
+
// event 契约(core trace.d.ts)带 `durationMs: number`,budget.test.ts 咬合断言 observe 只进
|
|
192
|
+
// compaction_duration_ms 不进失败计数器 —— W5 判 STALE,零改。per-phase 明细走 compacted 事件的
|
|
193
|
+
// phaseDurations(trace/project.ts compactedEventData)上 wire,不在 /metrics 重复开面(有界纪律)。
|
|
105
194
|
const d = e.durationMs;
|
|
106
195
|
if (typeof d === "number" && Number.isFinite(d))
|
|
107
196
|
metrics.observe("compaction_duration_ms", d);
|
|
108
197
|
}
|
|
109
198
|
else if (e.kind.startsWith("compaction.")) {
|
|
199
|
+
// core 1.257(压缩健康面): every NON-SUCCESS compaction outcome
|
|
200
|
+
// now emits a `compaction.*` trace frame (failed / mooted / blocked / noop / disabled / suppressed +
|
|
201
|
+
// the input_truncated disclosure and announce_dropped). Before these frames the only evidence of a
|
|
202
|
+
// failing compactor was `onError(phase:"compaction")` log lines — no aggregate, so "3 silent auto
|
|
203
|
+
// failures opened the breaker and manual verbs drain mooted" (the exact failure fingerprint)
|
|
204
|
+
// was invisible on a dashboard. Count by outcome+trigger: `compaction_events_total{outcome="failed"}`
|
|
205
|
+
// rising = the summarizer is failing; sustained `mooted`/`blocked` explains "202 → no compacted
|
|
206
|
+
// event" without log spelunking. Labels are bounded: 8 kinds × 3 triggers (frames without a trigger
|
|
207
|
+
// — noop/disabled/mooted/input_truncated/announce_dropped — label "none"). SUCCESS is deliberately
|
|
208
|
+
// not counted here: `compacted` is a TaskEvent riding the run stream, not a trace frame.
|
|
110
209
|
metrics.inc("compaction_events_total", { outcome: e.kind.slice("compaction.".length), trigger: e.trigger ?? "none" });
|
|
111
210
|
}
|
|
112
211
|
};
|
|
113
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* [1469] side-query 记账 seam(codex R3 high:sideQuery 不走 core tracer——brain.stream 直调不发
|
|
215
|
+
* brain.call——createTracer 的四路 sink(costQuota/model_cost 指标/fleetUsage 批报/fleetLease 本地扣减)
|
|
216
|
+
* 全部旁路)。本 seam 与 createTracer 的 brain.call 臂**同语义**喂同一组 sink:weightedTokens 同式
|
|
217
|
+
* (tokens×quotaWeight,weight-at-burn 固化)、micro-USD 同轴。装配点与 createTracer 同一处(main.ts),
|
|
218
|
+
* 传同一组实例——两臂永不分家。
|
|
219
|
+
*
|
|
220
|
+
* 已知残差(codex R3 medium,记档):cost 源=core SideQueryResult.usage.cost.total(brain 层计价),
|
|
221
|
+
* OpenAI cache-heavy 输入按全价入账(tracer 的 e.costMicroUsd 是 cache-family-aware 价)——方向=多收
|
|
222
|
+
* (保守,绝不少收);根修=core 在 SideQueryResult 上回权威 costMicroUsd(已提货 core)。model 标签/
|
|
223
|
+
* weight 键用**路由身份 r.model**(池配置有界)非 servedModel(provider 上报,无界)。
|
|
224
|
+
*/
|
|
225
|
+
/** core `usage-accounting.cacheFamilyOf` 的私拷镜像(core exports map 只开 barrel,该函数未导出——
|
|
226
|
+
* 已提货 core barrel 导出,到货即换,normalizeAgentName 同款纪律)。逐字对拍源:
|
|
227
|
+
* dist/core/runner/usage-accounting.js(override 别名 anthropic/openai + api 判 anthropic-messages/
|
|
228
|
+
* bedrock-converse-stream)。undefined 入参(catalog 查不到)→ undefined,调用方走保守臂。 */
|
|
114
229
|
export function cacheFamilyOfMirror(model) {
|
|
115
230
|
if (!model)
|
|
116
231
|
return undefined;
|
|
@@ -127,6 +242,10 @@ export function createSideQueryAccountant(metrics, costQuota, fleetUsage, fleetL
|
|
|
127
242
|
const output = typeof r.usage?.output === "number" ? r.usage.output : 0;
|
|
128
243
|
const cacheRead = typeof r.usage?.cacheRead === "number" ? r.usage.cacheRead : 0;
|
|
129
244
|
const cacheWrite = typeof r.usage?.cacheWrite === "number" ? r.usage.cacheWrite : 0;
|
|
245
|
+
// codex R4 high:prompt tokens 必须按 cache family 折算(core promptTokensOf 同式)——Anthropic 族
|
|
246
|
+
// (input-excludes-cached)的 cache 命中几乎全部在 input 之外,不加 cacheRead/cacheWrite 就是配额轴
|
|
247
|
+
// 大幅少收(lease 可被 cache-heavy side query 绕穿)。family 未知(catalog 查不到)走**保守臂**
|
|
248
|
+
// (含 cache——OpenAI 族此臂多收,方向与 cost 残差一致:宁多勿少,记档同一条)。
|
|
130
249
|
const promptTokens = r.family === "input-includes-cached" ? input : input + cacheRead + cacheWrite;
|
|
131
250
|
const micro = Math.round((typeof r.usage?.cost?.total === "number" ? r.usage.cost.total : 0) * 1_000_000);
|
|
132
251
|
if (micro > 0) {
|
|
@@ -138,15 +257,20 @@ export function createSideQueryAccountant(metrics, costQuota, fleetUsage, fleetL
|
|
|
138
257
|
const qw = typeof qwRaw === "number" && Number.isFinite(qwRaw) && qwRaw > 0 ? qwRaw : 1;
|
|
139
258
|
const weightedTokens = Math.round((promptTokens + output) * qw);
|
|
140
259
|
if (weightedTokens > 0 || micro > 0) {
|
|
141
|
-
fleetUsage?.record(principal, r.model, "", { inputTokens: promptTokens, outputTokens: output, costMicroUsd: micro, weightedTokens, quotaWeightAtUse: qw });
|
|
260
|
+
fleetUsage?.record(principal, r.model, "", { inputTokens: promptTokens, outputTokens: output, costMicroUsd: micro, weightedTokens, quotaWeightAtUse: qw }); // taskId ""(无 run 语义;accumulator 对 "" 不计 runsSeen);inputTokens=归一化总输入含 cache(fleet-bus 同口径)
|
|
142
261
|
fleetLease?.recordSpend(principal, { weightedTokens, costMicroUsd: micro });
|
|
143
262
|
}
|
|
144
263
|
};
|
|
145
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* ⑤ Resolve a per-task budget: honor the caller's requested value but never let it EXCEED the operator
|
|
267
|
+
* ceiling. `0`/unset ceiling = no limit (returns the caller's value, or undefined). A non-positive /
|
|
268
|
+
* non-numeric request is ignored (falls back to the ceiling). Returns undefined = "no budget gate".
|
|
269
|
+
*/
|
|
146
270
|
export function cappedCeiling(requested, ceiling) {
|
|
147
271
|
const req = typeof requested === "number" && requested > 0 ? requested : undefined;
|
|
148
272
|
if (!ceiling || ceiling <= 0)
|
|
149
|
-
return req;
|
|
150
|
-
return req === undefined ? ceiling : Math.min(req, ceiling);
|
|
273
|
+
return req; // no operator ceiling → honor caller (or none)
|
|
274
|
+
return req === undefined ? ceiling : Math.min(req, ceiling); // cap caller down to the ceiling
|
|
151
275
|
}
|
|
152
276
|
//# sourceMappingURL=budget.js.map
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import type { ToolSpec } from "@sema-agent/core";
|
|
2
|
+
/** Current time — the model has no clock; OA/most tasks need it. No side effects. CC-parity tool name `Now`
|
|
3
|
+
* (PascalCase, core 1.176 first-party rename wrap-up — the SERVICE owns this one; `nowTool` is not a core tool).
|
|
4
|
+
* effect:"read" so it never suspends → no durable-resume rename strand (no pending-tool checkpoint to canonicalize). */
|
|
2
5
|
export declare function nowTool(): ToolSpec;
|
|
3
6
|
//# sourceMappingURL=builtin-tools.d.ts.map
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
+
/** Current time — the model has no clock; OA/most tasks need it. No side effects. CC-parity tool name `Now`
|
|
3
|
+
* (PascalCase, core 1.176 first-party rename wrap-up — the SERVICE owns this one; `nowTool` is not a core tool).
|
|
4
|
+
* effect:"read" so it never suspends → no durable-resume rename strand (no pending-tool checkpoint to canonicalize). */
|
|
2
5
|
export function nowTool() {
|
|
3
6
|
return {
|
|
4
7
|
name: "Now",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Logger } from "../observability/logger.js";
|
|
2
2
|
import { type LoadedSkill } from "./skills.js";
|
|
3
|
+
/** 缺省 clone host 白名单(契约条款 1;国内镜像走本名单加 https 镜像域,不开 http 口)。 */
|
|
3
4
|
export declare const DEFAULT_PLUGIN_ALLOW_HOSTS: readonly string[];
|
|
5
|
+
/** wire 上的插件声明(registry-core PluginSpec 的宽读形——本模块只消费不裁决,未知键忽略)。 */
|
|
4
6
|
export interface PluginDeclWire {
|
|
5
7
|
name?: unknown;
|
|
6
8
|
source?: {
|
|
@@ -17,13 +19,17 @@ export type PluginValidation = {
|
|
|
17
19
|
name: string;
|
|
18
20
|
url: string;
|
|
19
21
|
sha?: string;
|
|
20
|
-
}
|
|
22
|
+
}
|
|
23
|
+
/** skip=true:不装但不算失败(enabled:false / marketplace 形 v1 暂缓);skip 缺席 = 真失败(计入 failures)。 */
|
|
24
|
+
| {
|
|
21
25
|
ok: false;
|
|
22
26
|
skip?: true;
|
|
23
27
|
name: string;
|
|
24
28
|
reason: string;
|
|
25
29
|
};
|
|
30
|
+
/** 条款 1/2/4:https-only、host 全等白名单、sha 40hex。纯函数,worker 侧纵深复验(不信任 wire 已验过)。 */
|
|
26
31
|
export declare function validatePluginDecl(decl: PluginDeclWire, allowHosts: readonly string[]): PluginValidation;
|
|
32
|
+
/** 条款 3/5:clone 计划(argv 序列 + 隔离 env)。纯数据,让"姿势"可被钉死。 */
|
|
27
33
|
export declare function gitClonePlan(o: {
|
|
28
34
|
url: string;
|
|
29
35
|
dest: string;
|
|
@@ -32,6 +38,9 @@ export declare function gitClonePlan(o: {
|
|
|
32
38
|
steps: string[][];
|
|
33
39
|
env: Record<string, string>;
|
|
34
40
|
};
|
|
41
|
+
/** 条款 5 的 manifest 半场:`.claude-plugin/plugin.json` 的 `skillsPath`(缺省 `skills/`;cli plugin
|
|
42
|
+
* 布局同族)。返回 ok:true+dir:undefined = 插件没有 skills 目录(可以只有 commands——那是 cli 壳的
|
|
43
|
+
* 半场,worker 装 0 个 skill 不算失败);ok:false = 路径逃逸,整条拒装。 */
|
|
35
44
|
export declare function resolvePluginSkillsRoot(cloneRoot: string): {
|
|
36
45
|
ok: true;
|
|
37
46
|
dir?: string;
|
|
@@ -41,22 +50,29 @@ export declare function resolvePluginSkillsRoot(cloneRoot: string): {
|
|
|
41
50
|
};
|
|
42
51
|
export interface ApplyPluginsResult {
|
|
43
52
|
skills: LoadedSkill[];
|
|
53
|
+
/** 真失败(validate 拒/clone 失败且无 LKG/装载抛):单条不连坐,逐条留痕。 */
|
|
44
54
|
failures: Array<{
|
|
45
55
|
plugin: string;
|
|
46
56
|
reason: string;
|
|
47
57
|
}>;
|
|
58
|
+
/** 撞名让位名单(收紧④)。 */
|
|
48
59
|
letGo: Array<{
|
|
49
60
|
plugin: string;
|
|
50
61
|
skill: string;
|
|
51
62
|
}>;
|
|
63
|
+
/** 本轮拉取失败、沿用上次成功物化的插件名。 */
|
|
52
64
|
lkgUsed: string[];
|
|
53
65
|
}
|
|
66
|
+
/** 总入口(条款 3/7/8):逐条物化 + 装载 + 让位合并。materialize 盘位 = `<cacheRoot>/<name>/live`
|
|
67
|
+
* (成功后原子 rename 替换,失败保留旧盘位 = LKG)。 */
|
|
54
68
|
export declare function applyCenterPlugins(baseline: LoadedSkill[], eff: {
|
|
55
69
|
plugins?: unknown;
|
|
56
70
|
}, opts: {
|
|
57
71
|
cacheRoot: string;
|
|
58
72
|
allowHosts: readonly string[];
|
|
59
73
|
logger?: Logger;
|
|
74
|
+
/** 测试口:跳过 validate(materialize 只接受已验声明;真 git 腿用本地 bare repo,validate 层的
|
|
75
|
+
* https-only 单独测——两层分开,谁也不掩护谁)。生产恒 false/缺席。 */
|
|
60
76
|
skipValidate?: boolean;
|
|
61
77
|
runGit?: (args: string[], env: Record<string, string>) => Promise<void>;
|
|
62
78
|
}): Promise<ApplyPluginsResult>;
|