mixdog 0.9.174 → 1.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/README.md +11 -12
- package/package.json +2 -2
- package/scripts/agent-turn-trace-probe.mjs +1 -1
- package/scripts/build-ffmpeg-runtime.sh +16 -0
- package/scripts/build-runtime-linux.sh +8 -2
- package/scripts/build-runtime-macos.sh +8 -2
- package/scripts/computer-task-cost-report.mjs +1 -9
- package/scripts/context-renewal-live-check.mjs +2 -1
- package/scripts/graph-parity.mjs +78 -55
- package/scripts/lib/bench-sandbox.mjs +67 -0
- package/scripts/lib/bench-sandbox.test.mjs +54 -0
- package/scripts/lib/coverage.mjs +2 -4
- package/scripts/lib/run-node-tests.mjs +24 -1
- package/scripts/lib/session-bench-fmt.mjs +65 -0
- package/scripts/lib/session-bench-render.mjs +394 -0
- package/scripts/lib/smoke-loop-shared.mjs +28 -0
- package/scripts/lib/smoke-loop-shared.test.mjs +22 -0
- package/scripts/lib/trace-row.mjs +40 -0
- package/scripts/lib/trace-row.test.mjs +47 -0
- package/scripts/lib/trace-stats.mjs +7 -0
- package/scripts/lib/trace-stats.test.mjs +7 -1
- package/scripts/llm-trace-summary.mjs +2 -44
- package/scripts/memory-chunk-quality.mjs +1 -1
- package/scripts/memory-layer2-check.mjs +1 -1
- package/scripts/pg-memory-diet.mjs +1 -1
- package/scripts/plan-runtime-release-tag.mjs +57 -0
- package/scripts/prepare-native-assets.mjs +1 -1
- package/scripts/provider-contract-test-env.mjs +21 -0
- package/scripts/release-paths.mjs +1 -0
- package/scripts/routing-corpus.mjs +1 -11
- package/scripts/session-diag.mjs +2 -44
- package/scripts/smoke-runtime-negative.sh +7 -1
- package/scripts/test-data-dir.mjs +19 -0
- package/scripts/tidy/sync-engines-manifest.mjs +8 -10
- package/scripts/tool-efficiency-diag.mjs +1 -4
- package/scripts/voice-runtime-config.json +1 -1
- package/src/app.mjs +1 -1
- package/src/defaults/skills/code-tidy/SKILL.md +5 -2
- package/src/defaults/skills/pptx/SKILL.md +1 -1
- package/src/defaults/skills/pptx/references/pictures.md +1 -1
- package/src/defaults/skills/pptx/scripts/review-deck.mjs +13 -4
- package/src/defaults/skills/skill-creator/scripts/validate-skill.mjs +40 -40
- package/src/defaults/skills/xlsx/SKILL.md +1 -0
- package/src/headless-exec.mjs +4 -2
- package/src/headless-role.mjs +81 -68
- package/src/lib/keychain-cjs.cjs +26 -49
- package/src/lib/mixdog-debug.cjs +1 -1
- package/src/lib/rules-builder.cjs +4 -3
- package/src/mixdog-session-runtime.mjs +2 -2
- package/src/repl/slash-commands.mjs +1 -1
- package/src/repl/stream-sink.mjs +1 -1
- package/src/repl/turn-output.mjs +2 -2
- package/src/repl.mjs +1 -1
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/session-prep.mjs +1 -1
- package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +20 -16
- package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +0 -3
- package/src/runtime/agent/orchestrator/agent-trace-format.mjs +23 -22
- package/src/runtime/agent/orchestrator/context/skill-catalog.mjs +2 -2
- package/src/runtime/{shared/llm/index.mjs → agent/orchestrator/maintenance-preset.mjs} +2 -2
- package/src/runtime/agent/orchestrator/mcp/client-config.mjs +2 -1
- package/src/runtime/agent/orchestrator/mcp/client-transport.mjs +7 -36
- package/src/runtime/agent/orchestrator/mcp/client.mjs +28 -2
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-api-transport.mjs +6 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-betas.mjs +1 -47
- package/src/runtime/agent/orchestrator/providers/anthropic-effort.mjs +1 -383
- package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +2 -59
- package/src/runtime/agent/orchestrator/providers/anthropic-midstream-recovery.mjs +32 -31
- package/src/runtime/agent/orchestrator/providers/anthropic-model-resolve.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +10 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-credentials.mjs +12 -61
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request/gzip-post.mjs +2 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-request.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +30 -67
- package/src/runtime/agent/orchestrator/providers/anthropic-recovery-guards.mjs +9 -12
- package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.mjs +3 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/leak-guard.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events/content-block-stop.mjs +20 -12
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-events.mjs +12 -2
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +4 -3
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn.mjs +5 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-watchdogs.mjs +18 -10
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +20 -16
- package/src/runtime/agent/orchestrator/providers/anthropic-thinking-contract.mjs +1 -26
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +9 -13
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth-catalog.mjs +8 -3
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth-login.mjs +4 -8
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth-tokens.mjs +21 -30
- package/src/runtime/agent/orchestrator/providers/antigravity-response.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/antigravity-stream.mjs +4 -2
- package/src/runtime/agent/orchestrator/providers/api-usage.mjs +10 -8
- package/src/runtime/agent/orchestrator/providers/cursor-auth.mjs +13 -10
- package/src/runtime/agent/orchestrator/providers/cursor-client-version.mjs +29 -0
- package/src/runtime/agent/orchestrator/providers/cursor-wire-guards.mjs +0 -1
- package/src/runtime/agent/orchestrator/providers/cursor-wire-protobuf.mjs +10 -26
- package/src/runtime/agent/orchestrator/providers/cursor-wire-stream-bridge.mjs +2 -3
- package/src/runtime/agent/orchestrator/providers/cursor-wire-transport.mjs +7 -3
- package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +9 -15
- package/src/runtime/agent/orchestrator/providers/cursor.mjs +31 -5
- package/src/runtime/agent/orchestrator/providers/gemini-cache-policy.mjs +1 -2
- package/src/runtime/agent/orchestrator/providers/gemini-cache.mjs +1 -4
- package/src/runtime/agent/orchestrator/providers/gemini-response.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +48 -46
- package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +18 -19
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +3 -26
- package/src/runtime/agent/orchestrator/providers/grok-client-version.mjs +41 -0
- package/src/runtime/agent/orchestrator/providers/grok-oauth-login.mjs +5 -19
- package/src/runtime/agent/orchestrator/providers/grok-oauth-tokens.mjs +16 -83
- package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +26 -8
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-models.mjs +8 -0
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +30 -1
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-stream-labels.mjs +6 -0
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-system-blocks.mjs +17 -0
- package/src/runtime/agent/orchestrator/providers/{anthropic-leaked-toolcall.mjs → lib/leaked-toolcall.mjs} +7 -7
- package/src/runtime/agent/orchestrator/providers/lib/oauth-token-utils.mjs +44 -0
- package/src/runtime/agent/orchestrator/providers/lib/send-callbacks.mjs +12 -0
- package/src/runtime/agent/orchestrator/providers/lib/sse-framing.mjs +9 -8
- package/src/runtime/agent/orchestrator/providers/lib/transport-fallback-trace.mjs +25 -0
- package/src/runtime/agent/orchestrator/providers/model-catalog-projection.mjs +1 -181
- package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +1 -796
- package/src/runtime/agent/orchestrator/providers/model-pricing-rates.mjs +1 -71
- package/src/runtime/agent/orchestrator/providers/npm-cli-version.mjs +87 -0
- package/src/runtime/agent/orchestrator/providers/oauth-usage.mjs +4 -5
- package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +4 -5
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +2 -21
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +2 -3
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/tool-call-acc.mjs +1 -2
- package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +4 -8
- package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +45 -32
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses-events.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses-state.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +6 -12
- package/src/runtime/agent/orchestrator/providers/openai-compat-stream-common.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/openai-compat-trace.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +14 -22
- package/src/runtime/agent/orchestrator/providers/openai-compat-xai-send.mjs +25 -34
- package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +14 -14
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-request.mjs +3 -1
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events/terminal-frames.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-items.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +2 -13
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-state.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/text-relay.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-oauth-login.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/openai-oauth-tokens.mjs +2 -44
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +2 -16
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +6 -5
- package/src/runtime/agent/orchestrator/providers/openai-responses-input.mjs +4 -1
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +3 -2
- package/src/runtime/agent/orchestrator/providers/openai-ws-response-state/tool-calls.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/openai-ws-text-relay.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +6 -4
- package/src/runtime/agent/orchestrator/providers/opencode-go-usage.mjs +2 -1
- package/src/runtime/agent/orchestrator/providers/opencode-go.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/provider-catalog-cache.mjs +1 -130
- package/src/runtime/agent/orchestrator/providers/registry.mjs +20 -16
- package/src/runtime/agent/orchestrator/providers/retry-classification.mjs +21 -20
- package/src/runtime/agent/orchestrator/providers/retry-executor.mjs +17 -17
- package/src/runtime/agent/orchestrator/runtime-core/builtin-features.mjs +193 -0
- package/src/runtime/agent/orchestrator/runtime-core/config-helpers.mjs +421 -0
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/context-inspection.mjs +17 -17
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/context-status-inspection.mjs +1 -1
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/context-status-shape.mjs +3 -3
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/context-status.mjs +1 -1
- package/src/runtime/agent/orchestrator/runtime-core/deferred-tool-delta.mjs +101 -0
- package/src/runtime/agent/orchestrator/runtime-core/effort.mjs +145 -0
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/extension-scopes.mjs +5 -5
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/fs-utils.mjs +1 -1
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-control.mjs +2 -2
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-mutations.mjs +2 -2
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-reminder.mjs +1 -1
- package/src/runtime/agent/orchestrator/runtime-core/goal-state.mjs +326 -0
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-storage.mjs +2 -2
- package/src/runtime/agent/orchestrator/runtime-core/goal-tasks.mjs +148 -0
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-title.mjs +2 -2
- package/src/runtime/agent/orchestrator/runtime-core/goal-tool-defs.mjs +140 -0
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-turns.mjs +1 -1
- package/src/runtime/agent/orchestrator/runtime-core/model-capabilities.mjs +140 -0
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/orchestration.mjs +1 -1
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/plugin-mcp.mjs +2 -2
- package/src/runtime/agent/orchestrator/runtime-core/session-id.mjs +2 -0
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/session-route-policy.mjs +2 -2
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/session-text.mjs +3 -3
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/session-title.mjs +1 -2
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/skill-tool-loading.mjs +1 -1
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/tool-catalog-schema.mjs +1 -1
- package/src/runtime/agent/orchestrator/runtime-core/tool-catalog.mjs +747 -0
- package/src/runtime/agent/orchestrator/runtime-core/tool-defs.mjs +149 -0
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/workflow/agents.mjs +11 -7
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/workflow/context.mjs +6 -4
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/workflow/packs.mjs +2 -3
- package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/workflow-ids.mjs +1 -1
- package/src/runtime/agent/orchestrator/runtime-core/workflow.mjs +255 -0
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +3 -4
- package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.mjs +2 -4
- package/src/runtime/agent/orchestrator/session/cache/read-cache.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/context-identity-writer.mjs +162 -0
- package/src/runtime/agent/orchestrator/session/context-tool-pairs.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/context-tool-schema.mjs +87 -0
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +3 -245
- package/src/runtime/agent/orchestrator/session/eager-dispatch/admission.mjs +2 -3
- package/src/runtime/agent/orchestrator/session/eager-dispatch/mutation-paths.mjs +54 -0
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/lifecycle-scan.mjs +1 -16
- package/src/runtime/agent/orchestrator/session/loop/arg-schema-coerce.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +13 -1
- package/src/runtime/agent/orchestrator/session/loop/completion-guards.mjs +3 -3
- package/src/runtime/agent/orchestrator/session/loop/deferred-call-through.mjs +4 -4
- package/src/runtime/agent/orchestrator/session/loop/fresh-context.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/loop/loop-state.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/continuation.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +2 -3
- package/src/runtime/agent/orchestrator/session/loop/request-boundary.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/loop/send-phase.mjs +6 -3
- package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/loop/tool-exec/call-prep.mjs +3 -2
- package/src/runtime/agent/orchestrator/session/loop/tool-exec/dispatch.mjs +6 -10
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/loop.mjs +5 -6
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-commit.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-prepare.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +5 -5
- package/src/runtime/agent/orchestrator/session/manager/foreign-pending-messages.mjs +40 -64
- package/src/runtime/agent/orchestrator/session/manager/pending-lifecycle-epoch.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +24 -16
- package/src/runtime/agent/orchestrator/session/manager/pending-persist-queue.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/pending-spool-file.mjs +7 -13
- package/src/runtime/agent/orchestrator/session/manager/pending-spool-path.mjs +17 -2
- package/src/runtime/agent/orchestrator/session/manager/pending-spool-shard.mjs +139 -0
- package/src/runtime/agent/orchestrator/session/manager/pending-spool-sweep.mjs +34 -14
- package/src/runtime/agent/orchestrator/session/manager/prefetch-bridge/file-prefetch.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/prompt-utils.mjs +4 -18
- package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +10 -18
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/session-record.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/manager/session-tool-surface.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +6 -10
- package/src/runtime/agent/orchestrator/session/manager.mjs +1 -2
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +11 -6
- package/src/runtime/agent/orchestrator/session/result-classification.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/send-instrumentation.mjs +194 -0
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +6 -198
- package/src/runtime/agent/orchestrator/session/store/canonical-reader.mjs +7 -7
- package/src/runtime/agent/orchestrator/session/store/fs-probe.mjs +0 -19
- package/src/runtime/agent/orchestrator/session/store/lifecycle-barriers.mjs +15 -8
- package/src/runtime/agent/orchestrator/session/store/listing.mjs +18 -29
- package/src/runtime/agent/orchestrator/session/store/load-cache.mjs +6 -36
- package/src/runtime/agent/orchestrator/session/store/save-delta.mjs +148 -0
- package/src/runtime/agent/orchestrator/session/store/save-fault.mjs +3 -3
- package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +15 -142
- package/src/runtime/agent/orchestrator/session/store/summary-cache.mjs +3 -3
- package/src/runtime/agent/orchestrator/session/store/sweep/stale-sweep.mjs +4 -2
- package/src/runtime/agent/orchestrator/session/store/sweep/sweep-finish.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/store/sweep/sweep-row.mjs +3 -2
- package/src/runtime/agent/orchestrator/session/store/write-admission.mjs +9 -22
- package/src/runtime/agent/orchestrator/session/store-agent-worker-rows.mjs +14 -6
- package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +200 -52
- package/src/runtime/agent/orchestrator/session/store-summary-log.mjs +81 -0
- package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +38 -4
- package/src/runtime/agent/orchestrator/session/store-transcript-cache.mjs +5 -2
- package/src/runtime/agent/orchestrator/session/store-transcript-projection.mjs +3 -5
- package/src/runtime/agent/orchestrator/session/store-transcript-worker.mjs +54 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +5 -9
- package/src/runtime/agent/orchestrator/session/tool-batch/execute-call.mjs +19 -8
- package/src/runtime/agent/orchestrator/session/tool-batch/flush.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/tool-batch/pre-dispatch.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/tool-batch/record-outcome.mjs +2 -1
- package/src/runtime/agent/orchestrator/session/transcript-restore/agent-envelope.mjs +489 -0
- package/src/runtime/agent/orchestrator/session/transcript-restore/restore.mjs +419 -0
- package/src/runtime/agent/orchestrator/session/transcript-restore/tool-result-status.mjs +358 -0
- package/src/runtime/agent/orchestrator/session/transcript-restore/tool-result-text.mjs +157 -0
- package/src/runtime/agent/orchestrator/tools/bash-policy-scan.mjs +2 -3
- package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +32 -11
- package/src/runtime/agent/orchestrator/tools/builtin/atomic-write.mjs +1 -31
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/benign-exit.mjs +7 -3
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/deadline-plan.mjs +11 -3
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool/spawn-env.mjs +4 -0
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +13 -7
- package/src/runtime/agent/orchestrator/tools/builtin/binary-file.mjs +6 -3
- package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +11 -5
- package/src/runtime/agent/orchestrator/tools/builtin/device-paths.mjs +1 -206
- package/src/runtime/agent/orchestrator/tools/builtin/find-files-tool.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +39 -3
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-path-fanout.mjs +5 -7
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-request.mjs +7 -25
- package/src/runtime/agent/orchestrator/tools/builtin/lib/list-helpers.mjs +27 -1
- package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +37 -0
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-insights.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool.mjs +28 -18
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +6 -10
- package/src/runtime/agent/orchestrator/tools/builtin/path-utils.mjs +15 -17
- package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +3 -3
- package/src/runtime/agent/orchestrator/tools/builtin/read-image-resize.mjs +1 -399
- package/src/runtime/agent/orchestrator/tools/builtin/read-line-collector.mjs +3 -2
- package/src/runtime/agent/orchestrator/tools/builtin/read-office-files.mjs +8 -15
- package/src/runtime/agent/orchestrator/tools/builtin/read-range-index.mjs +5 -8
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-render.mjs +3 -2
- package/src/runtime/agent/orchestrator/tools/builtin/read-source-windows.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +6 -5
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-dispatch.mjs +50 -5
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-render.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-snapshot.mjs +2 -5
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +11 -1
- package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/search-glob-tool.mjs +3 -35
- package/src/runtime/agent/orchestrator/tools/builtin/search-grep-tool.mjs +0 -12
- package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +50 -0
- package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +9 -26
- package/src/runtime/agent/orchestrator/tools/builtin/shell-lossless-compact.mjs +2 -1
- package/src/runtime/agent/orchestrator/tools/builtin/shell-output.mjs +6 -5
- package/src/runtime/agent/orchestrator/tools/builtin/snapshot-helpers.mjs +8 -3
- package/src/runtime/agent/orchestrator/tools/builtin/snapshot-store.mjs +6 -14
- package/src/runtime/agent/orchestrator/tools/builtin/snapshot-validation.mjs +3 -9
- package/src/runtime/agent/orchestrator/tools/builtin/tool-output-limit.mjs +1 -60
- package/src/runtime/agent/orchestrator/tools/builtin.mjs +10 -32
- package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +3 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/project-root.mjs +3 -7
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +15 -10
- package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +6 -10
- package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +4 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/text-columns.mjs +3 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/trusted-roots.mjs +3 -7
- package/src/runtime/agent/orchestrator/tools/code-graph-state.mjs +1 -84
- package/src/runtime/agent/orchestrator/tools/destructive-warning.mjs +11 -11
- package/src/runtime/agent/orchestrator/tools/graph-manifest.json +13 -13
- package/src/runtime/agent/orchestrator/tools/io-trace.mjs +28 -0
- package/src/runtime/agent/orchestrator/tools/lib/shell-run-spawn.mjs +38 -5
- package/src/runtime/agent/orchestrator/tools/lib/shell-warm-standby.mjs +10 -4
- package/src/runtime/agent/orchestrator/tools/patch/apply-patch/codex-batch.mjs +6 -26
- package/src/runtime/agent/orchestrator/tools/patch/apply-patch/request.mjs +0 -3
- package/src/runtime/agent/orchestrator/tools/patch/dispatch/native-report.mjs +2 -1
- package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +3 -10
- package/src/runtime/agent/orchestrator/tools/patch/matcher.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/patch/mutation-output.mjs +6 -19
- package/src/runtime/agent/orchestrator/tools/patch/native-server.mjs +5 -15
- package/src/runtime/agent/orchestrator/tools/patch/orchestrator.mjs +1 -3
- package/src/runtime/agent/orchestrator/tools/patch/paths.mjs +4 -0
- package/src/runtime/agent/orchestrator/tools/patch/sequence/run.mjs +1 -3
- package/src/runtime/agent/orchestrator/tools/patch/sequence/units.mjs +4 -10
- package/src/runtime/agent/orchestrator/tools/patch/sequence.mjs +1 -2
- package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +5 -11
- package/src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs +1 -2
- package/src/runtime/agent/orchestrator/tools/patch-manifest-path.mjs +3 -0
- package/src/runtime/agent/orchestrator/tools/patch-manifest.json +12 -12
- package/src/runtime/agent/orchestrator/tools/shell-command.mjs +87 -12
- package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +6 -3
- package/src/runtime/agent/orchestrator/tools/shell-exec-policy.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/shell-policy.mjs +15 -25
- package/src/runtime/agent/orchestrator/tools/spawn-manifest.json +13 -13
- package/src/runtime/{shared/llm → agent/orchestrator}/usage-log.mjs +1 -1
- package/src/runtime/attachments/pdf-extract.mjs +32 -29
- package/src/runtime/attachments/store.mjs +2 -1
- package/src/runtime/browser-bridge/browser-action-contract.d.mts +0 -2
- package/src/runtime/browser-bridge/client.mjs +30 -9
- package/src/runtime/channels/data/voice-runtime-manifest.json +21 -21
- package/src/runtime/channels/lib/config.mjs +4 -4
- package/src/runtime/channels/lib/event-pipeline.mjs +3 -3
- package/src/runtime/channels/lib/event-queue.mjs +1 -0
- package/src/runtime/channels/lib/executor.mjs +3 -25
- package/src/runtime/channels/lib/runtime-paths.mjs +36 -41
- package/src/runtime/channels/lib/scheduler.mjs +28 -44
- package/src/runtime/{shared → channels/lib}/schedules-db.mjs +3 -3
- package/src/runtime/channels/lib/tool-dispatch.mjs +3 -8
- package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +19 -23
- package/src/runtime/channels/lib/voice-transcription.mjs +13 -9
- package/src/runtime/channels/lib/webhook/log.mjs +2 -29
- package/src/runtime/channels/lib/webhook/request-handler.mjs +4 -5
- package/src/runtime/channels/lib/webhook/session-dispatch.mjs +8 -12
- package/src/runtime/channels/lib/webhook/signature.mjs +15 -19
- package/src/runtime/channels/lib/webhook/untrusted-fence.mjs +9 -0
- package/src/runtime/channels/lib/webhook.mjs +1 -1
- package/src/runtime/{shared → channels/lib}/webhooks-db.mjs +3 -3
- package/src/runtime/channels/lib/whisper-server.mjs +3 -2
- package/src/runtime/channels/lib/worker-bootstrap.mjs +19 -21
- package/src/runtime/channels/lib/worker-main.mjs +49 -58
- package/src/runtime/computer-bridge/client.mjs +7 -10
- package/src/runtime/computer-bridge/core-actions.mjs +1 -1
- package/src/runtime/computer-bridge/limits.d.mts +0 -1
- package/src/runtime/github/client.mjs +11 -6
- package/src/runtime/github/commands.mjs +4 -2
- package/src/runtime/github/contract.mjs +3 -1
- package/src/runtime/local-provider/hugging-face.mjs +3 -3
- package/src/runtime/local-provider/registered-models.mjs +3 -1
- package/src/runtime/local-provider/request-queue.mjs +24 -29
- package/src/runtime/local-provider/serial-chain.mjs +19 -0
- package/src/runtime/local-provider/server-process.mjs +2 -10
- package/src/runtime/media/adapters/antigravity-image.mjs +2 -2
- package/src/runtime/media/adapters/codex-image.mjs +2 -2
- package/src/runtime/media/adapters/gemini-image.mjs +2 -1
- package/src/runtime/media/adapters/gemini-video.mjs +3 -7
- package/src/runtime/media/adapters/xai-media.mjs +3 -7
- package/src/runtime/media/bounded-signal.mjs +13 -0
- package/src/runtime/media/store.mjs +9 -3
- package/src/runtime/memory/data/runtime-manifest.json +11 -11
- package/src/runtime/memory/index.mjs +6 -21
- package/src/runtime/memory/lib/core-memory-file.mjs +1 -1
- package/src/runtime/memory/lib/cycle-scheduler/backlog-probe.mjs +2 -1
- package/src/runtime/memory/lib/cycle1/cycle1-plan.mjs +1 -1
- package/src/runtime/memory/lib/embedding-idle-lease.mjs +18 -0
- package/src/runtime/memory/lib/embedding-provider.mjs +13 -0
- package/src/runtime/memory/lib/embedding-worker.mjs +12 -1
- package/src/runtime/memory/lib/http-router/ingest-routes.mjs +1 -1
- package/src/runtime/memory/lib/http-router/session-routes.mjs +1 -1
- package/src/runtime/memory/lib/ingest/transcript-discovery.mjs +1 -1
- package/src/runtime/memory/lib/memory-action-handlers/manage-actions.mjs +1 -1
- package/src/runtime/memory/lib/memory-cycle1.mjs +24 -1
- package/src/runtime/memory/lib/memory-cycle2-quarantine.mjs +99 -0
- package/src/runtime/memory/lib/memory-cycle2-review.mjs +8 -2
- package/src/runtime/memory/lib/memory-cycle2.mjs +49 -9
- package/src/runtime/memory/lib/memory-embed.mjs +3 -2
- package/src/runtime/memory/lib/memory-extraction.mjs +1 -2
- package/src/runtime/memory/lib/memory-fingerprint.mjs +1 -1
- package/src/runtime/memory/lib/memory-ops-policy.mjs +18 -2
- package/src/runtime/memory/lib/memory-retrievers.mjs +2 -2
- package/src/runtime/memory/lib/memory-text-utils.mjs +1 -1
- package/src/runtime/memory/lib/pg/adapter.mjs +3 -3
- package/src/runtime/memory/lib/pg/process.mjs +2 -2
- package/src/runtime/memory/lib/pg/supervisor.mjs +1 -2
- package/src/runtime/memory/lib/query-ranking.mjs +2 -2
- package/src/runtime/memory/lib/query-search-plan.mjs +1 -1
- package/src/runtime/memory/lib/recall-format.mjs +3 -4
- package/src/runtime/memory/lib/runtime-fetcher.mjs +94 -23
- package/src/runtime/memory/lib/session-ingest-runtime.mjs +1 -1
- package/src/runtime/memory/lib/trace-store.mjs +6 -2
- package/src/runtime/office/authoring/pptx-author-action.mjs +8 -3
- package/src/runtime/office/authoring/pptx-brief.mjs +3 -3
- package/src/runtime/office/authoring/pptx-html-build.mjs +109 -37
- package/src/runtime/office/authoring/pptx-html-geometry.mjs +188 -46
- package/src/runtime/office/authoring/pptx-html-measure.mjs +60 -21
- package/src/runtime/office/authoring/pptx-html-runner.mjs +83 -29
- package/src/runtime/office/authoring/pptx-script-normalize.mjs +156 -16
- package/src/runtime/office/bench/polish-benchmark.mjs +204 -201
- package/src/runtime/office/bench/quality-live-benchmark.mjs +8 -4
- package/src/runtime/office/capabilities-catalog.mjs +12 -1
- package/src/runtime/office/capabilities-signatures.mjs +31 -11
- package/src/runtime/office/capabilities.mjs +39 -20
- package/src/runtime/office/com/com-adapter.mjs +16 -14
- package/src/runtime/office/com/office-com-host.ps1 +118 -140
- package/src/runtime/office/core/excel-snapshot-normalize.mjs +149 -0
- package/src/runtime/office/core/office-actions-batch.mjs +4 -7
- package/src/runtime/office/core/office-actions-inspect.mjs +17 -14
- package/src/runtime/office/core/office-actions-open.mjs +1 -6
- package/src/runtime/office/core/office-core.mjs +107 -49
- package/src/runtime/office/core/office-finalize/review-stage.mjs +4 -1
- package/src/runtime/office/core/office-qa/design-review-stage.mjs +2 -9
- package/src/runtime/office/core/office-qa/review-assembly.mjs +9 -7
- package/src/runtime/office/core/office-sessions.mjs +10 -149
- package/src/runtime/office/design/composition-system.mjs +5 -10
- package/src/runtime/office/design/design-system.mjs +1 -2
- package/src/runtime/office/design/docx/design-docx/section.mjs +1 -1
- package/src/runtime/office/design/docx/design-docx-components.mjs +2 -1
- package/src/runtime/office/design/docx/design-docx.mjs +2 -2
- package/src/runtime/office/design/xlsx/design-xlsx.mjs +6 -2
- package/src/runtime/office/pdf/pdf-analysis.mjs +39 -32
- package/src/runtime/office/pdf/pdf-batch-content.mjs +1 -1
- package/src/runtime/office/pdf/pdf-writer.mjs +26 -22
- package/src/runtime/office/portable/docx-tracked-edits.mjs +6 -6
- package/src/runtime/office/portable/font-provisioner.mjs +37 -11
- package/src/runtime/office/portable/portable-cells.mjs +2 -6
- package/src/runtime/office/portable/portable-chart.mjs +6 -6
- package/src/runtime/office/portable/portable-docx-edits.mjs +4 -9
- package/src/runtime/office/portable/portable-docx-operations.mjs +16 -13
- package/src/runtime/office/portable/portable-docx-parts.mjs +7 -2
- package/src/runtime/office/portable/portable-docx-xml.mjs +36 -28
- package/src/runtime/office/portable/portable-opc.mjs +11 -13
- package/src/runtime/office/portable/portable-package.mjs +3 -4
- package/src/runtime/office/portable/portable-pivot.mjs +7 -3
- package/src/runtime/office/portable/portable-pptx-charts.mjs +59 -42
- package/src/runtime/office/portable/portable-pptx-core.mjs +14 -4
- package/src/runtime/office/portable/portable-pptx-package.mjs +5 -4
- package/src/runtime/office/portable/portable-pptx-shapes.mjs +25 -8
- package/src/runtime/office/portable/portable-sheet-audits.mjs +4 -8
- package/src/runtime/office/portable/portable-sheet-page.mjs +2 -2
- package/src/runtime/office/portable/portable-sheet-xml.mjs +1 -1
- package/src/runtime/office/portable/portable-snapshot-docx.mjs +2 -3
- package/src/runtime/office/portable/portable-snapshot-pptx.mjs +3 -1
- package/src/runtime/office/portable/portable-soffice.mjs +27 -22
- package/src/runtime/office/portable/portable-validation-package.mjs +1 -2
- package/src/runtime/office/portable/portable-validation.mjs +9 -3
- package/src/runtime/office/portable/portable-xlsx-operations.mjs +2 -49
- package/src/runtime/office/portable/portable-xlsx-pivot-ops.mjs +10 -5
- package/src/runtime/office/portable/portable-xlsx-range-layout.mjs +3 -2
- package/src/runtime/office/portable/portable-xlsx-reference-shift.mjs +189 -98
- package/src/runtime/office/portable/portable-xlsx-sheet-edits.mjs +26 -6
- package/src/runtime/office/portable/portable-xml.mjs +1 -4
- package/src/runtime/office/portable/text-metrics.mjs +14 -17
- package/src/runtime/office/portable/xlsx-contract.mjs +37 -3
- package/src/runtime/office/portable/xlsx-formula-engine.mjs +7 -1
- package/src/runtime/office/quality/assurance-checklist.mjs +1 -1
- package/src/runtime/office/quality/assurance-rendered.mjs +1 -1
- package/src/runtime/office/quality/assurance-structure-pptx.mjs +17 -8
- package/src/runtime/office/quality/assurance-structure.mjs +0 -2
- package/src/runtime/office/quality/design-aesthetics.mjs +2 -9
- package/src/runtime/office/quality/design-deck-diversity.mjs +2 -9
- package/src/runtime/office/quality/design-review.mjs +3 -3
- package/src/runtime/office/quality/pptx-slide-roles.mjs +3 -3
- package/src/runtime/office/shared/line-breaks.mjs +3 -1
- package/src/runtime/office/tool-defs.mjs +2 -2
- package/src/runtime/shared/async-log-appender.mjs +83 -0
- package/src/runtime/shared/automation-presence.mjs +9 -0
- package/src/runtime/shared/buffered-appender.mjs +10 -7
- package/src/runtime/shared/child-spawn-gate.mjs +2 -37
- package/src/runtime/shared/code-graph-state.mjs +84 -0
- package/src/runtime/shared/config.mjs +71 -89
- package/src/runtime/shared/context-inspection.mjs +56 -0
- package/src/runtime/shared/context-measurement.mjs +83 -0
- package/src/runtime/shared/device-paths.mjs +206 -0
- package/src/{standalone → runtime/shared}/fair-call-scheduler/owner-groups.mjs +1 -1
- package/src/runtime/shared/fair-call-scheduler.mjs +198 -0
- package/src/runtime/shared/file-lock.mjs +85 -55
- package/src/runtime/shared/http-request-body.mjs +3 -1
- package/src/runtime/shared/llm/anthropic-betas.mjs +46 -0
- package/src/runtime/shared/llm/anthropic-effort.mjs +378 -0
- package/src/runtime/shared/llm/anthropic-thinking-contract.mjs +29 -0
- package/src/runtime/shared/llm/cost.mjs +19 -10
- package/src/runtime/shared/llm/model-catalog-projection.mjs +182 -0
- package/src/runtime/shared/llm/model-catalog.mjs +799 -0
- package/src/runtime/shared/llm/model-pricing-rates.mjs +78 -0
- package/src/runtime/shared/llm/provider-catalog-cache.mjs +130 -0
- package/src/runtime/shared/llm/usage-accounting.mjs +12 -11
- package/src/runtime/shared/llm/usage-context.mjs +7 -0
- package/src/runtime/shared/llm/usage-ledger-import.mjs +14 -3
- package/src/runtime/shared/llm/usage-ledger-quota.mjs +97 -37
- package/src/runtime/shared/llm/usage-ledger-repair.mjs +3 -1
- package/src/runtime/shared/llm/usage-ledger-rollup.mjs +6 -10
- package/src/runtime/shared/llm/usage-ledger.mjs +6 -7
- package/src/runtime/shared/llm/usage-pricing-refresh.mjs +1 -1
- package/src/runtime/shared/llm/usage-rollup.mjs +0 -1
- package/src/runtime/shared/model-display.mjs +178 -0
- package/src/runtime/shared/notify-trace.mjs +14 -3
- package/src/runtime/shared/owner-fair-gate.mjs +1 -1
- package/src/runtime/shared/pending-json-projection.mjs +17 -0
- package/src/runtime/shared/pristine-execution.mjs +4 -3
- package/src/runtime/shared/process-lifecycle.mjs +18 -7
- package/src/runtime/shared/read-image-resize.mjs +399 -0
- package/src/runtime/shared/schedule-model-ref.mjs +2 -2
- package/src/runtime/shared/staged-update.mjs +7 -36
- package/src/runtime/shared/statusline/ansi.mjs +161 -0
- package/src/{ui → runtime/shared/statusline}/statusline-format.mjs +5 -5
- package/src/{ui → runtime/shared/statusline}/statusline-segments.mjs +54 -50
- package/src/runtime/shared/tool-card-model/background-task.mjs +1 -1
- package/src/runtime/shared/tool-card-model/card-detail.mjs +2 -2
- package/src/runtime/shared/tool-card-model/card-status.mjs +7 -5
- package/src/runtime/shared/tool-card-model/git-result.mjs +10 -0
- package/src/runtime/shared/tool-card-model/terminal-status.mjs +6 -2
- package/src/runtime/shared/tool-card-model.golden-cases.mjs +2 -1
- package/src/runtime/shared/tool-output-limit.mjs +60 -0
- package/src/runtime/shared/tool-primitives.mjs +1 -1
- package/src/runtime/shared/tool-result-summary.mjs +1 -0
- package/src/runtime/shared/tool-status.mjs +35 -2
- package/src/runtime/shared/transcript-metadata.mjs +1 -1
- package/src/runtime/shared/transcript-writer/transcript-file.mjs +1 -2
- package/src/runtime/shared/turn-snapshot-store.mjs +23 -17
- package/src/runtime/shared/turn-worktree-snapshot.mjs +8 -4
- package/src/runtime/shared/update-checker.mjs +1 -3
- package/src/runtime/tidy/apply.mjs +2 -2
- package/src/runtime/tidy/function-length.mjs +63 -0
- package/src/runtime/tidy/report.mjs +6 -3
- package/src/runtime/tidy/runners/shared.mjs +1 -0
- package/src/runtime/tidy/runners/shellcheck.mjs +1 -1
- package/src/runtime/tidy/tool.mjs +10 -3
- package/src/runtime/web-search/index.mjs +6 -17
- package/src/runtime/web-search/lib/cache.mjs +8 -54
- package/src/runtime/web-search/lib/config.mjs +2 -6
- package/src/runtime/web-search/lib/debounced-json-writer.mjs +62 -0
- package/src/runtime/web-search/lib/http-fetch.mjs +24 -112
- package/src/runtime/web-search/lib/package-version.mjs +10 -0
- package/src/runtime/web-search/lib/ssrf-guard.mjs +34 -28
- package/src/runtime/web-search/lib/state.mjs +8 -53
- package/src/runtime/web-search/lib/web-tools.mjs +5 -5
- package/src/session-runtime/agent-tool-routing.mjs +3 -9
- package/src/{runtime/shared → session-runtime}/automation-workflow.mjs +4 -4
- package/src/session-runtime/boot/apis.mjs +4 -5
- package/src/session-runtime/boot/begin.mjs +1 -1
- package/src/session-runtime/boot/config.mjs +2 -2
- package/src/session-runtime/boot/facade.mjs +2 -2
- package/src/session-runtime/boot/infrastructure.mjs +4 -4
- package/src/session-runtime/boot/providers.mjs +6 -6
- package/src/session-runtime/boot/session.mjs +1 -1
- package/src/session-runtime/boot/shared.mjs +5 -7
- package/src/session-runtime/boot/tools.mjs +6 -6
- package/src/session-runtime/bridge-first-use-gate.mjs +1 -1
- package/src/session-runtime/builtin-features.mjs +1 -193
- package/src/session-runtime/channel-config-api.mjs +3 -3
- package/src/session-runtime/config-helpers.mjs +1 -420
- package/src/session-runtime/config-lifecycle.mjs +2 -2
- package/src/session-runtime/cwd-plugins/core-memory-context.mjs +2 -2
- package/src/session-runtime/cwd-plugins/plugin-status.mjs +1 -1
- package/src/session-runtime/deferred-tool-delta.mjs +1 -101
- package/src/session-runtime/effort.mjs +1 -145
- package/src/session-runtime/goal-facade-api.mjs +1 -1
- package/src/session-runtime/goal-state.mjs +1 -325
- package/src/session-runtime/goal-tasks.mjs +1 -137
- package/src/session-runtime/goal-tool-defs.mjs +1 -140
- package/src/session-runtime/hook-payload.mjs +4 -5
- package/src/session-runtime/internal-tool-executor/bridge-tools.mjs +3 -3
- package/src/session-runtime/internal-tool-executor/caller-context.mjs +8 -0
- package/src/session-runtime/internal-tool-executor/feature-tools.mjs +3 -2
- package/src/session-runtime/internal-tool-executor/knowledge-tools.mjs +4 -6
- package/src/session-runtime/internal-tool-executor/workspace-tools.mjs +2 -2
- package/src/session-runtime/internal-tool-executor.mjs +1 -1
- package/src/session-runtime/lifecycle/inheritance.mjs +1 -1
- package/src/session-runtime/lifecycle/session-catalog.mjs +3 -3
- package/src/session-runtime/lifecycle/session-switch/resume.mjs +2 -2
- package/src/session-runtime/lifecycle/session-switch/session-delete.mjs +1 -1
- package/src/session-runtime/lifecycle/session-switch.mjs +1 -1
- package/src/session-runtime/lifecycle/shared.mjs +1 -1
- package/src/session-runtime/mcp-glue/connect.mjs +1 -1
- package/src/session-runtime/mcp-glue/server-catalog.mjs +1 -1
- package/src/session-runtime/mcp-glue/server-input.mjs +1 -1
- package/src/session-runtime/model-capabilities.mjs +1 -140
- package/src/session-runtime/model-recency.mjs +1 -1
- package/src/session-runtime/model-route/route-persist.mjs +2 -2
- package/src/session-runtime/model-route/route-tuning.mjs +3 -3
- package/src/session-runtime/model-route/set-route.mjs +6 -6
- package/src/session-runtime/model-route/web-search-route.mjs +5 -5
- package/src/session-runtime/model-route-api.mjs +1 -1
- package/src/session-runtime/native-web-search/routes.mjs +1 -1
- package/src/session-runtime/native-web-search/tool-shape.mjs +2 -2
- package/src/session-runtime/output-styles.mjs +2 -2
- package/src/session-runtime/prewarm/channel-start.mjs +1 -0
- package/src/session-runtime/provider-auth/accounts.mjs +7 -2
- package/src/session-runtime/provider-auth/login.mjs +1 -1
- package/src/session-runtime/provider-auth-api.mjs +1 -1
- package/src/session-runtime/provider-models/model-meta.mjs +1 -1
- package/src/session-runtime/provider-models/row-hydration.mjs +3 -3
- package/src/session-runtime/provider-usage.mjs +2 -2
- package/src/session-runtime/quick-model-rows/model-meta.mjs +1 -1
- package/src/session-runtime/quick-model-rows/provider-rows.mjs +1 -1
- package/src/session-runtime/quick-model-rows/web-search-rows.mjs +2 -2
- package/src/session-runtime/resource-api.mjs +2 -2
- package/src/session-runtime/resource-mcp-api.mjs +3 -3
- package/src/session-runtime/resource-plugins-api.mjs +3 -3
- package/src/session-runtime/resource-recall-api.mjs +2 -2
- package/src/session-runtime/resource-scope-decorate.mjs +2 -2
- package/src/session-runtime/route-resolution.mjs +3 -3
- package/src/session-runtime/route-state.mjs +4 -4
- package/src/session-runtime/runtime-bootstrap.mjs +1 -1
- package/src/session-runtime/runtime-facade.mjs +1 -1
- package/src/session-runtime/runtime-feature-gates.mjs +2 -2
- package/src/session-runtime/runtime-modules.mjs +3 -3
- package/src/session-runtime/runtime-paths.mjs +6 -2
- package/src/session-runtime/runtime-tool-routing.mjs +2 -2
- package/src/{runtime/shared → session-runtime}/schedule-session-run.mjs +5 -5
- package/src/{standalone → session-runtime/services}/agent-task-status.mjs +1 -1
- package/src/{standalone → session-runtime/services}/agent-tool/close-flow/close-all.mjs +2 -2
- package/src/{standalone → session-runtime/services}/agent-tool/close-flow.mjs +1 -1
- package/src/{standalone → session-runtime/services}/agent-tool/execute.mjs +1 -1
- package/src/{standalone → session-runtime/services}/agent-tool/helpers.mjs +6 -6
- package/src/session-runtime/services/agent-tool/index-write-queue.mjs +209 -0
- package/src/{standalone → session-runtime/services}/agent-tool/job-task-reconcile.mjs +2 -2
- package/src/{standalone → session-runtime/services}/agent-tool/job-views/job-lookup.mjs +5 -1
- package/src/{standalone → session-runtime/services}/agent-tool/job-views/job-render.mjs +1 -1
- package/src/session-runtime/services/agent-tool/job-views/session-progress.mjs +101 -0
- package/src/{standalone → session-runtime/services}/agent-tool/job-views/spawn-meta.mjs +1 -1
- package/src/session-runtime/services/agent-tool/job-views.mjs +59 -0
- package/src/session-runtime/services/agent-tool/lead-worker-index/index-file.mjs +48 -0
- package/src/{standalone → session-runtime/services}/agent-tool/lead-worker-index/row-settlement.mjs +3 -3
- package/src/{standalone → session-runtime/services}/agent-tool/lead-worker-index.mjs +10 -2
- package/src/{standalone → session-runtime/services}/agent-tool/notify/early-completion.mjs +2 -2
- package/src/{standalone → session-runtime/services}/agent-tool/notify.mjs +4 -4
- package/src/{standalone → session-runtime/services}/agent-tool/render.mjs +2 -2
- package/src/{standalone → session-runtime/services}/agent-tool/send-flow.mjs +6 -2
- package/src/{standalone → session-runtime/services}/agent-tool/spawn-flow/job-start.mjs +2 -2
- package/src/{standalone → session-runtime/services}/agent-tool/spawn-flow/spawn-plan.mjs +3 -3
- package/src/{standalone → session-runtime/services}/agent-tool/spawn-flow/spawn-prep.mjs +3 -3
- package/src/{standalone → session-runtime/services}/agent-tool/spawn-flow/spawn-run.mjs +3 -3
- package/src/{standalone → session-runtime/services}/agent-tool/spawn-preset.mjs +1 -1
- package/src/session-runtime/services/agent-tool/tag-registry.mjs +121 -0
- package/src/{standalone → session-runtime/services}/agent-tool/terminal-reaper/reap-timers.mjs +1 -1
- package/src/{standalone → session-runtime/services}/agent-tool/terminal-reaper/scan-admission.mjs +1 -1
- package/src/{standalone → session-runtime/services}/agent-tool/terminal-reaper/stale-rows.mjs +1 -1
- package/src/{standalone → session-runtime/services}/agent-tool/terminal-reaper/tombstones.mjs +5 -2
- package/src/session-runtime/services/agent-tool/tool-def.mjs +60 -0
- package/src/{standalone → session-runtime/services}/agent-tool/turn-review.mjs +1 -1
- package/src/{standalone → session-runtime/services}/agent-tool/worker-index/row-liveness.mjs +1 -1
- package/src/{standalone → session-runtime/services}/agent-tool/worker-index/row-store.mjs +46 -20
- package/src/{standalone → session-runtime/services}/agent-tool/worker-index.mjs +8 -1
- package/src/{standalone → session-runtime/services}/agent-tool/worker-rows.mjs +1 -1
- package/src/session-runtime/services/agent-tool.mjs +151 -0
- package/src/{standalone → session-runtime/services}/agent-watchdog-registry.mjs +1 -1
- package/src/{standalone → session-runtime/services}/channel-admin.mjs +8 -10
- package/src/{standalone → session-runtime/services}/channel-client.mjs +1 -1
- package/src/{standalone → session-runtime/services}/channel-session-router.mjs +1 -1
- package/src/{standalone → session-runtime/services}/channel-worker/client-heartbeat.mjs +1 -1
- package/src/{standalone → session-runtime/services}/channel-worker/daemon-attach.mjs +1 -1
- package/src/{standalone → session-runtime/services}/channel-worker/daemon-spawn.mjs +5 -5
- package/src/session-runtime/services/channel-worker.mjs +140 -0
- package/src/session-runtime/services/daemon-crash-capture/daemon-exit-record.mjs +189 -0
- package/src/{standalone → session-runtime/services}/daemon-crash-capture/retention.mjs +1 -1
- package/src/{standalone → session-runtime/services}/daemon-crash-capture/spawn-capture.mjs +12 -1
- package/src/{standalone → session-runtime/services}/daemon-crash-capture.mjs +6 -0
- package/src/{standalone → session-runtime/services}/hook-bus/command-handler.mjs +1 -1
- package/src/{standalone → session-runtime/services}/hook-bus/event-runner.mjs +1 -1
- package/src/{standalone → session-runtime/services}/hook-bus/handler-dispatch.mjs +1 -1
- package/src/{standalone → session-runtime/services}/hook-bus/handlers.mjs +5 -4
- package/src/{standalone → session-runtime/services}/hook-bus/rule-file.mjs +2 -2
- package/src/{standalone → session-runtime/services}/hook-bus/tool-gate.mjs +1 -1
- package/src/{standalone → session-runtime/services}/memory-runtime-proxy/client-registry.mjs +1 -1
- package/src/{standalone → session-runtime/services}/memory-runtime-proxy/daemon-spawn.mjs +4 -4
- package/src/{standalone → session-runtime/services}/memory-runtime-proxy/discovery.mjs +5 -5
- package/src/{standalone → session-runtime/services}/memory-runtime-proxy/owner-claim.mjs +2 -2
- package/src/{standalone → session-runtime/services}/memory-runtime-proxy/rpc.mjs +0 -4
- package/src/{standalone → session-runtime/services}/memory-runtime-proxy/start.mjs +1 -1
- package/src/{standalone → session-runtime/services}/memory-runtime-proxy/tool-wire.mjs +1 -1
- package/src/session-runtime/services/memory-runtime-proxy.mjs +130 -0
- package/src/{standalone → session-runtime/services}/plugin-admin.mjs +6 -6
- package/src/session-runtime/services/provider-admin.mjs +576 -0
- package/src/{standalone → session-runtime/services}/seeds.mjs +3 -3
- package/src/{standalone → session-runtime/services}/usage-dashboard-model.mjs +1 -1
- package/src/session-runtime/services/usage-dashboard.mjs +278 -0
- package/src/{standalone → session-runtime/services}/usage-stats-hours.mjs +1 -1
- package/src/session-runtime/services/usage-stats-model.mjs +657 -0
- package/src/session-runtime/services/usage-stats-period.mjs +178 -0
- package/src/session-runtime/session-create/materialize.mjs +3 -3
- package/src/session-runtime/session-create/session-options.mjs +14 -7
- package/src/session-runtime/session-lifecycle.mjs +2 -2
- package/src/session-runtime/settings-builtin-tools-api.mjs +1 -1
- package/src/session-runtime/setup-tool/executor.mjs +2 -2
- package/src/session-runtime/skills-api.mjs +2 -2
- package/src/session-runtime/statusline-route.mjs +1 -1
- package/src/session-runtime/tool-catalog.mjs +1 -753
- package/src/session-runtime/tool-defs.mjs +1 -149
- package/src/session-runtime/tool-policy-refresh.mjs +7 -5
- package/src/session-runtime/tool-surface.mjs +5 -5
- package/src/session-runtime/turn/agent-ops.mjs +2 -2
- package/src/session-runtime/turn/session-ops.mjs +2 -2
- package/src/session-runtime/turn/share-ops.mjs +4 -3
- package/src/session-runtime/turn/turn-run/turn-prepare.mjs +1 -1
- package/src/session-runtime/turn/turn-run/turn-settle.mjs +4 -4
- package/src/session-runtime/usage-stats-api.mjs +18 -2
- package/src/session-runtime/warmup/statusline-usage-warmup.mjs +2 -2
- package/src/{runtime/shared → session-runtime}/webhook-session-run.mjs +5 -5
- package/src/session-runtime/workflow-agents-api/agent-editor.mjs +2 -2
- package/src/session-runtime/workflow-agents-api/agent-route.mjs +4 -4
- package/src/session-runtime/workflow-agents-api/onboarding.mjs +2 -2
- package/src/session-runtime/workflow-agents-api/shared.mjs +4 -6
- package/src/session-runtime/workflow-agents-api/workflow-packs.mjs +1 -1
- package/src/session-runtime/workflow.mjs +1 -255
- package/src/standalone/agent-tool/job-views/session-progress.mjs +1 -101
- package/src/standalone/agent-tool/job-views.mjs +1 -59
- package/src/standalone/agent-tool/tag-registry.mjs +1 -121
- package/src/standalone/agent-tool/tool-def.mjs +1 -60
- package/src/standalone/agent-tool.mjs +1 -151
- package/src/standalone/channel-worker.mjs +1 -140
- package/src/standalone/daemon-agent-control.mjs +1 -1
- package/src/standalone/daemon-desktop-runtime.mjs +2 -2
- package/src/standalone/daemon-stored-session-views.mjs +1 -1
- package/src/standalone/daemon.mjs +38 -5
- package/src/standalone/fair-call-scheduler.mjs +1 -198
- package/src/standalone/folder-dialog.mjs +12 -8
- package/src/standalone/memory-runtime-proxy.mjs +1 -130
- package/src/standalone/provider-admin.mjs +1 -576
- package/src/standalone/session-client/frame-stream.mjs +1 -1
- package/src/standalone/session-client.mjs +2 -2
- package/src/standalone/session-service/agent-tree/agent-child.mjs +1 -1
- package/src/standalone/session-service/projection/transcript-window.mjs +2 -2
- package/src/standalone/usage-dashboard.mjs +1 -278
- package/src/standalone/usage-stats-model.mjs +1 -653
- package/src/standalone/usage-stats-period.mjs +1 -178
- package/src/tui/App.jsx +107 -256
- package/src/tui/app/app-view/floating-panel.jsx +3 -12
- package/src/tui/app/app-view/welcome-banner.jsx +36 -0
- package/src/tui/app/app-view.jsx +18 -45
- package/src/tui/app/create-app-pickers.mjs +1 -1
- package/src/tui/app/doctor.mjs +15 -1
- package/src/tui/app/extension-pickers/mcp-servers-picker.mjs +7 -3
- package/src/tui/app/maintenance-pickers/auto-clear-picker.mjs +5 -8
- package/src/tui/app/model-options.mjs +2 -3
- package/src/tui/app/model-picker/model-footer.mjs +1 -1
- package/src/tui/app/model-picker/route-selection.mjs +1 -3
- package/src/tui/app/mouse-input/button-gestures.mjs +13 -31
- package/src/tui/app/mouse-input/wheel-router.mjs +22 -32
- package/src/tui/app/picker-enter-latch.mjs +21 -0
- package/src/tui/app/picker-index-mode.mjs +34 -0
- package/src/tui/app/shell-layout/panel-transition.mjs +7 -12
- package/src/tui/app/shell-layout/row-budgets.mjs +4 -9
- package/src/tui/app/slash-palette.mjs +31 -0
- package/src/tui/app/text-layout.mjs +1 -1
- package/src/tui/app/theme-effort-pickers.mjs +1 -1
- package/src/tui/app/transcript-window.mjs +1 -5
- package/src/tui/app/usage-context-panels/context-model.mjs +1 -1
- package/src/tui/app/use-global-key-input.mjs +0 -1
- package/src/tui/app/use-interaction-refs.mjs +55 -0
- package/src/tui/app/use-onboarding-start.mjs +45 -0
- package/src/tui/app/use-panel-transition.mjs +40 -0
- package/src/tui/app/use-prompt-draft-flow.mjs +4 -13
- package/src/tui/app/use-prompt-layout-rows.mjs +39 -0
- package/src/tui/app/use-prompt-queue-history/prompt-history.mjs +1 -1
- package/src/tui/app/use-prompt-state.mjs +40 -0
- package/src/tui/app/use-selection-paint.mjs +9 -5
- package/src/tui/app/use-transcript-scroll-state.mjs +61 -0
- package/src/tui/app/use-transcript-window.mjs +0 -1
- package/src/tui/app/use-ui-open-request.mjs +18 -0
- package/src/tui/app/use-workflow-tab-cycle.mjs +39 -0
- package/src/tui/components/ContextInspector.jsx +1 -1
- package/src/tui/components/ContextPanel.jsx +1 -1
- package/src/tui/components/Picker.jsx +41 -322
- package/src/tui/components/PromptInput.jsx +34 -468
- package/src/tui/components/StatusLine.jsx +8 -555
- package/src/tui/components/TextEntryPanel.jsx +25 -211
- package/src/tui/components/ToolExecution.jsx +43 -328
- package/src/tui/components/UsagePanel.jsx +1 -1
- package/src/tui/components/picker/PickerItemRow.jsx +85 -0
- package/src/tui/components/picker/picker-layout.mjs +46 -0
- package/src/tui/components/picker/use-picker-input.mjs +165 -0
- package/src/tui/components/picker/use-picker-selection.mjs +67 -0
- package/src/tui/components/prompt-input/edit-chords.mjs +87 -0
- package/src/tui/components/prompt-input/edit-helpers.mjs +15 -12
- package/src/tui/components/prompt-input/escape-key.mjs +87 -0
- package/src/tui/components/prompt-input/key-handler.mjs +364 -0
- package/src/tui/components/status-line/boot-schedule.mjs +83 -0
- package/src/tui/components/status-line/local-line.mjs +213 -0
- package/src/tui/components/status-line/use-statusline-text.mjs +319 -0
- package/src/tui/components/statusline-module-loader.mjs +21 -0
- package/src/tui/components/text-entry-layout.mjs +104 -0
- package/src/tui/components/text-entry-value.jsx +47 -0
- package/src/tui/components/tool-execution/aggregate-card.jsx +141 -0
- package/src/tui/components/tool-execution/pending-placeholder.jsx +24 -0
- package/src/tui/components/tool-execution/standard-card.jsx +229 -0
- package/src/tui/components/tool-output-format.mjs +3 -5
- package/src/tui/dist/index.mjs +3616 -3022
- package/src/tui/index.jsx +85 -66
- package/src/tui/markdown/format-token.mjs +3 -3
- package/src/tui/paste-attachments.mjs +1 -1
- package/src/tui/prompt-history-store.mjs +17 -6
- package/src/tui/session/agent-envelope.mjs +1 -489
- package/src/tui/session/context-state.mjs +2 -2
- package/src/tui/session/goal-continuation/continuation-queue.mjs +1 -1
- package/src/tui/session/goal-continuation/deadline-delivery.mjs +1 -1
- package/src/tui/session/goal-continuation/goal-visibility.mjs +1 -1
- package/src/tui/session/initial-state.mjs +1 -1
- package/src/tui/session/live-share/wire.mjs +3 -0
- package/src/tui/session/oauth-flows.mjs +1 -7
- package/src/tui/session/session-api/commands.mjs +5 -3
- package/src/tui/session/session-api/controls.mjs +1 -1
- package/src/tui/session/session-api/intake/submission.mjs +8 -3
- package/src/tui/session/session-api/integrations.mjs +1 -1
- package/src/tui/session/session-api/routes.mjs +9 -8
- package/src/tui/session/session-api/settings.mjs +24 -23
- package/src/tui/session/session-api/shared.mjs +13 -2
- package/src/tui/session/session-api-ext.mjs +7 -415
- package/src/tui/session/session-flow/drain.mjs +86 -82
- package/src/tui/session/session-flow/queue.mjs +3 -1
- package/src/tui/session/tool-result-status.mjs +1 -354
- package/src/tui/session/tool-result-text.mjs +1 -157
- package/src/tui/session/transcript-intake.mjs +1 -1
- package/src/tui/session/transcript-spill/spill-dir.mjs +4 -1
- package/src/tui/session/transcript-spill/spill-writer.mjs +1 -1
- package/src/tui/session/tui-steering-persist.mjs +44 -86
- package/src/tui/session-local.mjs +8 -5
- package/src/tui/statusline-ansi-bridge.mjs +1 -1
- package/src/tui/theme.mjs +1 -1
- package/src/ui/ansi.mjs +1 -161
- package/src/ui/context-inspection.mjs +1 -56
- package/src/ui/context-measurement.mjs +1 -83
- package/src/ui/markdown.mjs +3 -3
- package/src/ui/model-display.mjs +1 -173
- package/src/ui/statusline-agents.mjs +22 -21
- package/src/ui/statusline.mjs +21 -24
- package/src/ui/stream-finalize.mjs +1 -1
- package/src/ui/tool-card.mjs +1 -1
- package/src/vendor/statusline/src/gateway/route-meta.mjs +157 -29
- package/scripts/fixtures/spawn-lease-child-harness.mjs +0 -8
- package/scripts/fixtures/spawn-lease-fixture-worker.mjs +0 -37
- package/src/runtime/agent/orchestrator/activity-bus.mjs +0 -31
- package/src/runtime/shared/child-spawn-remote.mjs +0 -210
- package/src/runtime/shared/session-runtime-health.mjs +0 -201
- package/src/standalone/agent-tool/lead-worker-index/index-file.mjs +0 -45
- package/src/standalone/session-runtime-agent-control-client.mjs +0 -117
- package/src/standalone/session-runtime-agent-control.mjs +0 -85
- package/src/standalone/session-runtime-host-factory.mjs +0 -22
- package/src/standalone/session-runtime-host.mjs +0 -742
- package/src/standalone/session-runtime-provider-cooldown.mjs +0 -78
- package/src/standalone/session-runtime-proxy.mjs +0 -164
- package/src/standalone/session-runtime-record.mjs +0 -18
- package/src/standalone/session-runtime-shard-router.mjs +0 -151
- package/src/standalone/session-runtime-spawn-leases.mjs +0 -82
- package/src/standalone/session-runtime-worker.mjs +0 -678
- package/src/standalone/session-runtime-workload.mjs +0 -98
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/context-status-cache.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/deferred-tool-availability.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-deadlines.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-runtime.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-store.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-text.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/goal-tool-exec.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/provider-request-snapshot.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/provider-request-tools.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/tool-catalog-data.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/tool-profile.mjs +0 -0
- /package/src/{session-runtime → runtime/agent/orchestrator/runtime-core}/workflow/shared-scan-cache.mjs +0 -0
- /package/src/{standalone → runtime/shared}/fair-call-scheduler/queue-item.mjs +0 -0
- /package/src/runtime/{agent/orchestrator/providers → shared/llm}/provider-model-identities.mjs +0 -0
- /package/src/{standalone → runtime/shared}/projects.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/execute-send.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/execute-spawn.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/job-views/agent-list.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/lead-worker-index/lead-rows.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/lead-worker-index/reap-timers.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/provider-init.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/spawn-flow/deferred-spawn.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/spawn-flow.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/tag-maps.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/tag-registry/tag-lookup.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/tag-registry/tag-refresh.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/terminal-reaper/row-helpers.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/terminal-reaper.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/terminal-trace.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/worker-index/mutation-batch.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/agent-tool/worker-index/row-shape.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/channel-client/daemon-request.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/channel-client/notify-stream.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/channel-client/reconnect.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/channel-client/registration.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/daemon-candidate.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/daemon-crash-capture/paths.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus/config-loader.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus/config.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus/constants.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus/event-log.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus/handler-timeout.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus/payload.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus/rule-store.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus/rules.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/hook-bus.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/memory-runtime-proxy/calls.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/memory-runtime-proxy/state.mjs +0 -0
- /package/src/{standalone → session-runtime/services}/sse-frames.mjs +0 -0
|
@@ -1,653 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Token/cost aggregation by provider, with a per-model drill-down.
|
|
3
|
-
*
|
|
4
|
-
* Two stores answer the same question over different horizons: the raw gateway
|
|
5
|
-
* event list is complete but bounded to a recent window, while the daily rollup
|
|
6
|
-
* survives indefinitely. A day that exists in the rollup is owned by the rollup
|
|
7
|
-
* and the events it already contains are skipped by timestamp, so the events on
|
|
8
|
-
* either side of that span still count and no turn counts twice. Days that
|
|
9
|
-
* predate the rollup are recovered from the events alone.
|
|
10
|
-
*
|
|
11
|
-
* Both stores start at the day they were introduced, and the event list is
|
|
12
|
-
* additionally capped by row count, so neither reaches the months already on
|
|
13
|
-
* disk as session transcripts. A third source rebuilds those days from the
|
|
14
|
-
* transcripts; it is consulted only where the other two have nothing, which is
|
|
15
|
-
* what keeps a recovered day from landing on top of a recorded one.
|
|
16
|
-
*
|
|
17
|
-
* By default only the user's own turns are reported. Background runners spend
|
|
18
|
-
* several times more tokens than the conversation does on this machine, so
|
|
19
|
-
* folding them into the same number answers a question nobody asked.
|
|
20
|
-
*
|
|
21
|
-
* Pure module: callers pass both stores in, which keeps the arithmetic testable
|
|
22
|
-
* and keeps disk access at the runtime boundary.
|
|
23
|
-
*/
|
|
24
|
-
import { billableInputTokensForProvider } from '../runtime/shared/llm/cost.mjs';
|
|
25
|
-
import { hourlySeries } from './usage-stats-hours.mjs';
|
|
26
|
-
import { isConversationUsageSource, knownCostTurns, usageRollupDayKey } from '../runtime/shared/llm/usage-rollup.mjs';
|
|
27
|
-
|
|
28
|
-
function num(value) {
|
|
29
|
-
const n = Number(value);
|
|
30
|
-
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function text(value) {
|
|
34
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** `numerator / denominator` rounded; null while any turn is unmeasured, 0 without a denominator. */
|
|
38
|
-
function measuredRatio(unmeasuredTurns, numerator, denominator, digits) {
|
|
39
|
-
if (unmeasuredTurns > 0) return null;
|
|
40
|
-
return denominator > 0 ? round(numerator / denominator, digits) : 0;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function round(value, digits) {
|
|
44
|
-
const factor = 10 ** digits;
|
|
45
|
-
return Math.round(value * factor) / factor;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* `days === null` is all time, `0` is today, and N is N calendar dates including
|
|
50
|
-
* today. Day buckets cannot truthfully answer partial historical-day windows.
|
|
51
|
-
*/
|
|
52
|
-
function resolveWindow(days, now) {
|
|
53
|
-
if (days === 0) {
|
|
54
|
-
const midnight = new Date(now);
|
|
55
|
-
midnight.setHours(0, 0, 0, 0);
|
|
56
|
-
return { days: 0, fromMs: midnight.getTime(), toMs: now };
|
|
57
|
-
}
|
|
58
|
-
const span = Number(days);
|
|
59
|
-
if (!Number.isFinite(span) || span <= 0) return { days: null, fromMs: 0, toMs: now };
|
|
60
|
-
const first = new Date(now);
|
|
61
|
-
first.setHours(0, 0, 0, 0);
|
|
62
|
-
first.setDate(first.getDate() - Math.floor(span) + 1);
|
|
63
|
-
return { days: Math.floor(span), fromMs: first.getTime(), toMs: now };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** The same-length window immediately before this one, for a change figure. */
|
|
67
|
-
function previousWindow(window) {
|
|
68
|
-
if (window.days === null) return null;
|
|
69
|
-
// No misleading full-yesterday comparison against an unfinished today.
|
|
70
|
-
if (window.days === 0) return null;
|
|
71
|
-
const first = new Date(window.fromMs);
|
|
72
|
-
first.setDate(first.getDate() - window.days);
|
|
73
|
-
return { days: window.days, fromMs: first.getTime(), toMs: window.fromMs - 1 };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function createState() {
|
|
77
|
-
return {
|
|
78
|
-
turns: 0,
|
|
79
|
-
input: 0,
|
|
80
|
-
output: 0,
|
|
81
|
-
cacheRead: 0,
|
|
82
|
-
cacheWrite: 0,
|
|
83
|
-
costUsd: 0,
|
|
84
|
-
costBilled: 0,
|
|
85
|
-
costEstimated: 0,
|
|
86
|
-
costKnownTurns: 0,
|
|
87
|
-
unmeasuredTurns: 0,
|
|
88
|
-
durationMs: 0,
|
|
89
|
-
durationTurns: 0,
|
|
90
|
-
providers: new Map(),
|
|
91
|
-
sessions: new Map(),
|
|
92
|
-
sessionsComplete: true,
|
|
93
|
-
anonymousSessions: [],
|
|
94
|
-
sessionsDropped: 0,
|
|
95
|
-
dayKeys: new Set(),
|
|
96
|
-
daily: new Map(),
|
|
97
|
-
rollupDays: 0,
|
|
98
|
-
eventDays: 0,
|
|
99
|
-
// Days rebuilt from the session transcripts because neither store holds
|
|
100
|
-
// them any more.
|
|
101
|
-
historyDays: 0,
|
|
102
|
-
// Days written before turns carried a source cannot answer "mine only".
|
|
103
|
-
unclassifiedDays: 0,
|
|
104
|
-
unclassifiedTurns: 0,
|
|
105
|
-
partialDays: 0,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function providerBucket(state, provider, kind) {
|
|
110
|
-
let bucket = state.providers.get(provider);
|
|
111
|
-
if (!bucket) {
|
|
112
|
-
bucket = {
|
|
113
|
-
provider,
|
|
114
|
-
providerKind: '',
|
|
115
|
-
turns: 0,
|
|
116
|
-
input: 0,
|
|
117
|
-
output: 0,
|
|
118
|
-
cacheRead: 0,
|
|
119
|
-
cacheWrite: 0,
|
|
120
|
-
costUsd: 0,
|
|
121
|
-
models: new Map(),
|
|
122
|
-
sessions: new Set(),
|
|
123
|
-
sessionsComplete: true,
|
|
124
|
-
};
|
|
125
|
-
state.providers.set(provider, bucket);
|
|
126
|
-
}
|
|
127
|
-
if (kind && !bucket.providerKind) bucket.providerKind = kind;
|
|
128
|
-
return bucket;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function modelBucket(provider, model) {
|
|
132
|
-
let bucket = provider.models.get(model);
|
|
133
|
-
if (!bucket) {
|
|
134
|
-
bucket = {
|
|
135
|
-
model,
|
|
136
|
-
turns: 0,
|
|
137
|
-
input: 0,
|
|
138
|
-
output: 0,
|
|
139
|
-
cacheRead: 0,
|
|
140
|
-
cacheWrite: 0,
|
|
141
|
-
costUsd: 0,
|
|
142
|
-
sessions: new Set(),
|
|
143
|
-
sessionsComplete: true,
|
|
144
|
-
};
|
|
145
|
-
provider.models.set(model, bucket);
|
|
146
|
-
}
|
|
147
|
-
return bucket;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function addUsage(target, usage) {
|
|
151
|
-
target.turns += usage.turns;
|
|
152
|
-
target.input += usage.input;
|
|
153
|
-
target.output += usage.output;
|
|
154
|
-
target.cacheRead += usage.cacheRead;
|
|
155
|
-
target.cacheWrite += usage.cacheWrite;
|
|
156
|
-
target.costUsd += usage.costUsd;
|
|
157
|
-
target.costKnownTurns = (target.costKnownTurns || 0) + (usage.costKnownTurns || 0);
|
|
158
|
-
target.costBilled = (target.costBilled || 0) + (usage.costBilled || 0);
|
|
159
|
-
target.costEstimated = (target.costEstimated || 0) + (usage.costEstimated || 0);
|
|
160
|
-
target.unmeasuredTurns = (target.unmeasuredTurns || 0) + (usage.unmeasuredTurns || 0);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function foldRoute(state, providerId, modelId, kind, usage) {
|
|
164
|
-
const provider = providerBucket(state, providerId, kind);
|
|
165
|
-
const model = modelBucket(provider, modelId);
|
|
166
|
-
for (const bucket of [provider, model]) {
|
|
167
|
-
addUsage(bucket, usage);
|
|
168
|
-
if (usage.turns > 0 && (!usage.sessions || usage.sessionsComplete === false)) {
|
|
169
|
-
bucket.sessionsComplete = false;
|
|
170
|
-
}
|
|
171
|
-
for (const id of Object.keys(usage.sessions || {})) bucket.sessions.add(id);
|
|
172
|
-
}
|
|
173
|
-
addUsage(state, usage);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function addDaily(state, key, usage, providerId) {
|
|
177
|
-
let bucket = state.daily.get(key);
|
|
178
|
-
if (!bucket) {
|
|
179
|
-
bucket = {
|
|
180
|
-
day: key,
|
|
181
|
-
turns: 0,
|
|
182
|
-
input: 0,
|
|
183
|
-
output: 0,
|
|
184
|
-
cacheRead: 0,
|
|
185
|
-
cacheWrite: 0,
|
|
186
|
-
costUsd: 0,
|
|
187
|
-
// Per-provider split of this day, so a chart can show WHICH provider a
|
|
188
|
-
// day's spend went to instead of one anonymous total.
|
|
189
|
-
providers: new Map(),
|
|
190
|
-
};
|
|
191
|
-
state.daily.set(key, bucket);
|
|
192
|
-
}
|
|
193
|
-
addUsage(bucket, usage);
|
|
194
|
-
const id = text(providerId);
|
|
195
|
-
if (!id) return;
|
|
196
|
-
let slice = bucket.providers.get(id);
|
|
197
|
-
if (!slice) {
|
|
198
|
-
slice = { provider: id, turns: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, costUsd: 0 };
|
|
199
|
-
bucket.providers.set(id, slice);
|
|
200
|
-
}
|
|
201
|
-
addUsage(slice, usage);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function foldRollupDay(state, key, day, conversationOnly) {
|
|
205
|
-
const totals = conversationOnly ? day?.conversation : day;
|
|
206
|
-
if (!totals) {
|
|
207
|
-
// The whole day predates source attribution. Leaving it out is the only
|
|
208
|
-
// honest answer for a conversation-only view; the count reports the gap.
|
|
209
|
-
state.unclassifiedDays += 1;
|
|
210
|
-
state.unclassifiedTurns += num(day?.turns);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
state.dayKeys.add(key);
|
|
214
|
-
// A rebuilt day keeps saying so after it is frozen into the rollup, which is
|
|
215
|
-
// the only thing left distinguishing it from a recorded one.
|
|
216
|
-
if (day?.restored === true) state.historyDays += 1;
|
|
217
|
-
if (day?.importedPartial === true) state.partialDays += 1;
|
|
218
|
-
if (conversationOnly && day?.conversationPartial === true) state.partialDays += 1;
|
|
219
|
-
state.durationMs += num(totals.durationMs);
|
|
220
|
-
state.durationTurns += num(totals.durationTurns);
|
|
221
|
-
state.sessionsDropped += num(day?.sessionsDropped);
|
|
222
|
-
if (totals.sessionsComplete === false || num(day?.sessionsDropped) > 0) state.sessionsComplete = false;
|
|
223
|
-
|
|
224
|
-
const models = day?.models && typeof day.models === 'object' ? day.models : {};
|
|
225
|
-
for (const [routeKey, raw] of Object.entries(models)) {
|
|
226
|
-
const route = conversationOnly ? raw?.conversation : raw;
|
|
227
|
-
if (!route) continue;
|
|
228
|
-
const slash = routeKey.indexOf('/');
|
|
229
|
-
const providerId = text(raw?.provider) || (slash > 0 ? routeKey.slice(0, slash) : '');
|
|
230
|
-
const modelId = text(raw?.model) || (slash > 0 ? routeKey.slice(slash + 1) : '');
|
|
231
|
-
if (!providerId || !modelId) continue;
|
|
232
|
-
const usage = {
|
|
233
|
-
turns: num(route.turns),
|
|
234
|
-
input: num(route.input),
|
|
235
|
-
output: num(route.output),
|
|
236
|
-
cacheRead: num(route.cacheRead),
|
|
237
|
-
cacheWrite: num(route.cacheWrite),
|
|
238
|
-
costUsd: num(route.costUsd),
|
|
239
|
-
costKnownTurns: knownCostTurns(route, num),
|
|
240
|
-
costBilled: num(route.costBilled),
|
|
241
|
-
costEstimated:
|
|
242
|
-
route.costEstimated == null
|
|
243
|
-
? Math.max(0, num(route.costUsd) - num(route.costBilled))
|
|
244
|
-
: num(route.costEstimated),
|
|
245
|
-
sessions: route.sessions,
|
|
246
|
-
sessionsComplete: route.sessionsComplete,
|
|
247
|
-
unmeasuredTurns: num(route.unmeasuredTurns),
|
|
248
|
-
};
|
|
249
|
-
foldRoute(state, providerId, modelId, text(raw?.kind), usage);
|
|
250
|
-
addDaily(state, key, usage, providerId);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Session ids are recorded for conversation turns only, so both views read
|
|
254
|
-
// the same map: a background cycle has no session worth counting. The one
|
|
255
|
-
// exception is a day whose ids were collected while cycles still counted and
|
|
256
|
-
// never cleared — keeping those would inflate the count by an order of
|
|
257
|
-
// magnitude. The raw events still cover such a recent day.
|
|
258
|
-
const partial = conversationOnly && day?.conversationPartial === true && day?.sessionsPurged !== true;
|
|
259
|
-
const sessions = !partial && day?.sessions && typeof day.sessions === 'object' ? day.sessions : {};
|
|
260
|
-
for (const [id, tokens] of Object.entries(sessions)) {
|
|
261
|
-
// One session can span midnight; its totals are summed across days.
|
|
262
|
-
state.sessions.set(id, (state.sessions.get(id) || 0) + num(tokens));
|
|
263
|
-
}
|
|
264
|
-
if (!partial && Array.isArray(day?.sessionTokens)) {
|
|
265
|
-
for (const tokens of day.sessionTokens) state.anonymousSessions.push(num(tokens));
|
|
266
|
-
if (day.sessionTokens.length) state.sessionsComplete = false;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function foldEvent(state, key, event, conversationOnly) {
|
|
271
|
-
const conversation = isConversationUsageSource(event?.sourceType);
|
|
272
|
-
if (conversationOnly && !conversation) return;
|
|
273
|
-
const providerId = text(event?.provider);
|
|
274
|
-
const modelId = text(event?.model);
|
|
275
|
-
if (!providerId || !modelId) return;
|
|
276
|
-
state.dayKeys.add(key);
|
|
277
|
-
|
|
278
|
-
const cacheRead = num(event?.cacheReadTokens);
|
|
279
|
-
const cacheWrite = num(event?.cacheWriteTokens);
|
|
280
|
-
const sessionId = conversation ? text(event?.sessionId) : '';
|
|
281
|
-
const costSource = text(event?.costSource);
|
|
282
|
-
const priced =
|
|
283
|
-
event?.costUsd != null && Number.isFinite(Number(event.costUsd)) && !['', 'none', 'unpriced'].includes(costSource);
|
|
284
|
-
const usage = {
|
|
285
|
-
turns: 1,
|
|
286
|
-
// Same normalization the rollup applies: a provider that reports the whole
|
|
287
|
-
// prompt as input would otherwise have its cache counted twice.
|
|
288
|
-
input: billableInputTokensForProvider(providerId, num(event?.inputTokens), cacheRead, cacheWrite),
|
|
289
|
-
output: num(event?.outputTokens),
|
|
290
|
-
cacheRead,
|
|
291
|
-
cacheWrite,
|
|
292
|
-
costUsd: num(event?.costUsd),
|
|
293
|
-
costKnownTurns: priced ? 1 : 0,
|
|
294
|
-
costBilled: priced && costSource === 'provider' ? num(event.costUsd) : 0,
|
|
295
|
-
costEstimated: priced && costSource !== 'provider' ? num(event.costUsd) : 0,
|
|
296
|
-
sessions: sessionId ? { [sessionId]: 1 } : {},
|
|
297
|
-
sessionsComplete: !conversation || Boolean(sessionId),
|
|
298
|
-
};
|
|
299
|
-
foldRoute(state, providerId, modelId, text(event?.providerKind), usage);
|
|
300
|
-
addDaily(state, key, usage, providerId);
|
|
301
|
-
|
|
302
|
-
const durationMs = num(event?.durationMs);
|
|
303
|
-
if (durationMs > 0) {
|
|
304
|
-
state.durationMs += durationMs;
|
|
305
|
-
state.durationTurns += 1;
|
|
306
|
-
}
|
|
307
|
-
if (sessionId) {
|
|
308
|
-
const tokens = usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
309
|
-
state.sessions.set(sessionId, (state.sessions.get(sessionId) || 0) + tokens);
|
|
310
|
-
} else if (conversation) state.sessionsComplete = false;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function collect({ events, rollupDays, historyDays, window, conversationOnly }) {
|
|
314
|
-
const fromKey = window.fromMs > 0 ? usageRollupDayKey(window.fromMs) : '';
|
|
315
|
-
const toKey = usageRollupDayKey(window.toMs);
|
|
316
|
-
const state = createState();
|
|
317
|
-
|
|
318
|
-
const eventsByDay = new Map();
|
|
319
|
-
for (const event of events) {
|
|
320
|
-
const ts = Number(event?.ts);
|
|
321
|
-
if (!Number.isFinite(ts) || ts < window.fromMs || ts > window.toMs) continue;
|
|
322
|
-
const key = usageRollupDayKey(ts);
|
|
323
|
-
const group = eventsByDay.get(key);
|
|
324
|
-
if (group) group.push(event);
|
|
325
|
-
else eventsByDay.set(key, [event]);
|
|
326
|
-
}
|
|
327
|
-
// The event list is bounded by row count, and the cap evicts the oldest rows
|
|
328
|
-
// first, so its earliest day is the one arriving half-eaten. Every later day
|
|
329
|
-
// is whole. Naming it here lets the rebuild step below take that one day back
|
|
330
|
-
// without second-guessing the days the store really does cover.
|
|
331
|
-
const truncatedEventDay = eventsByDay.size ? [...eventsByDay.keys()].sort()[0] : '';
|
|
332
|
-
|
|
333
|
-
// The rollup owns every day it holds, because it outlives the event cap.
|
|
334
|
-
// firstTs/lastTs say which turns it already contains, so only the events
|
|
335
|
-
// outside that span are added on top — the turns of the day before rolling
|
|
336
|
-
// up began, and anything written after the last fold. A bucket from before
|
|
337
|
-
// those bounds existed carries no span: there the fuller store is taken
|
|
338
|
-
// whole, since nothing distinguishes an overlapping turn from a new one.
|
|
339
|
-
for (const [key, day] of Object.entries(rollupDays)) {
|
|
340
|
-
if (key < fromKey || key > toKey) continue;
|
|
341
|
-
const group = eventsByDay.get(key);
|
|
342
|
-
// A bucket written before turns carried a source cannot answer "mine
|
|
343
|
-
// only". Where the raw events still cover that day they can, so they are
|
|
344
|
-
// used instead of dropping the day entirely.
|
|
345
|
-
if (conversationOnly && !day?.conversation && group?.length) continue;
|
|
346
|
-
const firstTs = num(day?.firstTs);
|
|
347
|
-
const lastTs = num(day?.lastTs);
|
|
348
|
-
if (firstTs > 0 && lastTs > 0) {
|
|
349
|
-
const extra = group
|
|
350
|
-
? group.filter((event) => {
|
|
351
|
-
const ts = Number(event?.ts);
|
|
352
|
-
return Number.isFinite(ts) && (ts < firstTs || ts > lastTs);
|
|
353
|
-
})
|
|
354
|
-
: [];
|
|
355
|
-
if (extra.length) eventsByDay.set(key, extra);
|
|
356
|
-
else eventsByDay.delete(key);
|
|
357
|
-
} else {
|
|
358
|
-
if (group && group.length > num(day?.turns)) continue;
|
|
359
|
-
eventsByDay.delete(key);
|
|
360
|
-
}
|
|
361
|
-
state.rollupDays += 1;
|
|
362
|
-
foldRollupDay(state, key, day, conversationOnly);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Transcript-derived days are the last resort: a recorded day always wins,
|
|
366
|
-
// whether it came from the rollup or from the events still on disk. Only the
|
|
367
|
-
// days neither store reaches — everything before recording began, and
|
|
368
|
-
// everything the event cap evicted — are taken from here.
|
|
369
|
-
for (const [key, day] of Object.entries(historyDays || {})) {
|
|
370
|
-
if (key < fromKey || key > toKey) continue;
|
|
371
|
-
if (rollupDays[key]) continue;
|
|
372
|
-
const group = eventsByDay.get(key);
|
|
373
|
-
if (group?.length) {
|
|
374
|
-
// A whole day of events outranks a rebuild of it.
|
|
375
|
-
if (key !== truncatedEventDay) continue;
|
|
376
|
-
// On the truncated day the two sources are compared as wholes and the
|
|
377
|
-
// fuller one takes the day: the surviving rows would otherwise report a
|
|
378
|
-
// full day of work as the handful of turns the cap happened to spare.
|
|
379
|
-
if (num(day?.turns) <= group.length) continue;
|
|
380
|
-
eventsByDay.delete(key);
|
|
381
|
-
}
|
|
382
|
-
foldRollupDay(state, key, day, conversationOnly);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
state.eventDays = eventsByDay.size;
|
|
386
|
-
for (const [key, group] of eventsByDay) {
|
|
387
|
-
for (const event of group) foldEvent(state, key, event, conversationOnly);
|
|
388
|
-
}
|
|
389
|
-
return state;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/** Every calendar day from `first` to `last`, inclusive. */
|
|
393
|
-
function calendarDays(first, last) {
|
|
394
|
-
if (!first || !last) return [];
|
|
395
|
-
const out = [];
|
|
396
|
-
const cursor = new Date(`${first}T00:00:00`);
|
|
397
|
-
const end = Date.parse(`${last}T00:00:00`);
|
|
398
|
-
if (Number.isNaN(cursor.getTime()) || Number.isNaN(end)) return [];
|
|
399
|
-
// Walking the Date itself (rather than adding 24h) keeps a daylight-saving
|
|
400
|
-
// boundary from shifting the key by a day.
|
|
401
|
-
while (cursor.getTime() <= end) {
|
|
402
|
-
out.push(usageRollupDayKey(cursor.getTime()));
|
|
403
|
-
cursor.setDate(cursor.getDate() + 1);
|
|
404
|
-
if (out.length > 4000) break;
|
|
405
|
-
}
|
|
406
|
-
return out;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
function median(values) {
|
|
410
|
-
if (!values.length) return 0;
|
|
411
|
-
const sorted = [...values].sort((a, b) => a - b);
|
|
412
|
-
const middle = Math.floor(sorted.length / 2);
|
|
413
|
-
return sorted.length % 2 === 0 ? (sorted[middle - 1] + sorted[middle]) / 2 : sorted[middle];
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// "tokens" is everything a turn moved: fresh input, output, and the cached
|
|
417
|
-
// prompt it read or wrote. Cached providers re-read the whole context every
|
|
418
|
-
// turn, so counting only the fresh part made a cached route look idle beside
|
|
419
|
-
// an uncached one doing the same work. The split stays in input/output/cache.
|
|
420
|
-
function tokensOf(bucket) {
|
|
421
|
-
return bucket.input + bucket.output + bucket.cacheRead + bucket.cacheWrite;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function exportRoute(bucket, totalTokens) {
|
|
425
|
-
const tokens = tokensOf(bucket);
|
|
426
|
-
const fresh = bucket.input + bucket.output;
|
|
427
|
-
const prompt = bucket.input + bucket.cacheRead + bucket.cacheWrite;
|
|
428
|
-
const unmeasuredTurns = num(bucket.unmeasuredTurns);
|
|
429
|
-
const unknown = unmeasuredTurns > 0 && unmeasuredTurns === bucket.turns;
|
|
430
|
-
return {
|
|
431
|
-
turns: bucket.turns,
|
|
432
|
-
// Ids that were seen are counted even when some turns carried none: the
|
|
433
|
-
// figure is then a floor, and the flag says so, rather than an unknown.
|
|
434
|
-
sessions: bucket.sessions.size,
|
|
435
|
-
sessionsComplete: bucket.sessionsComplete,
|
|
436
|
-
input: unknown ? null : bucket.input,
|
|
437
|
-
output: bucket.output,
|
|
438
|
-
cacheRead: unknown ? null : bucket.cacheRead,
|
|
439
|
-
cacheWrite: unknown ? null : bucket.cacheWrite,
|
|
440
|
-
cacheTokens: bucket.cacheRead + bucket.cacheWrite,
|
|
441
|
-
tokens,
|
|
442
|
-
unmeasuredTurns,
|
|
443
|
-
costUsd: round(bucket.costUsd, 6),
|
|
444
|
-
costBilled: round(num(bucket.costBilled), 6),
|
|
445
|
-
costEstimated: round(num(bucket.costEstimated), 6),
|
|
446
|
-
costKnownTurns: num(bucket.costKnownTurns),
|
|
447
|
-
costUnpricedTurns: Math.max(0, bucket.turns - num(bucket.costKnownTurns)),
|
|
448
|
-
costCoverage: bucket.turns > 0 ? num(bucket.costKnownTurns) / bucket.turns : 0,
|
|
449
|
-
share: measuredRatio(unmeasuredTurns, tokens, totalTokens, 6),
|
|
450
|
-
// How much of this route's prompt arrived from cache instead of being read
|
|
451
|
-
// again. Cache writes are misses, so belong in the denominator, not the
|
|
452
|
-
// numerator.
|
|
453
|
-
cacheHitRate: measuredRatio(unmeasuredTurns, bucket.cacheRead, prompt, 4),
|
|
454
|
-
// What a million fresh tokens actually cost on this route. Cache is excluded
|
|
455
|
-
// from the divisor: including it would divide real spend by a number two
|
|
456
|
-
// orders of magnitude larger and rank every route as free.
|
|
457
|
-
costPerMTokens: fresh > 0 ? round(bucket.costUsd / (fresh / 1_000_000), 4) : 0,
|
|
458
|
-
// Answer length, which is what separates a terse route from a verbose one
|
|
459
|
-
// at the same price.
|
|
460
|
-
outputPerTurn: bucket.turns > 0 ? Math.round(bucket.output / bucket.turns) : 0,
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/** Provider rows for the window: each provider's route totals plus its
|
|
465
|
-
* per-model split, both ordered by tokens then cost. `modelLimit` truncates
|
|
466
|
-
* only the model list, never the provider list. */
|
|
467
|
-
function exportProviders(state, { totalTokens, modelLimit }) {
|
|
468
|
-
return [...state.providers.values()]
|
|
469
|
-
.map((bucket) => {
|
|
470
|
-
const models = [...bucket.models.values()]
|
|
471
|
-
.map((model) => ({ model: model.model, ...exportRoute(model, totalTokens) }))
|
|
472
|
-
.sort((a, b) => b.tokens - a.tokens || b.costUsd - a.costUsd);
|
|
473
|
-
return {
|
|
474
|
-
provider: bucket.provider,
|
|
475
|
-
providerKind: bucket.providerKind,
|
|
476
|
-
...exportRoute(bucket, totalTokens),
|
|
477
|
-
modelCount: models.length,
|
|
478
|
-
models: modelLimit > 0 ? models.slice(0, modelLimit) : models,
|
|
479
|
-
};
|
|
480
|
-
})
|
|
481
|
-
.sort((a, b) => b.tokens - a.tokens || b.costUsd - a.costUsd);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/** One row per calendar day in the window, with its per-provider split.
|
|
485
|
-
* A day with no traffic is still a day. Only the days that HAD usage are
|
|
486
|
-
* collected upstream, so an idle stretch would otherwise vanish and pull the
|
|
487
|
-
* surrounding days together — a fortnight off would read as continuous work.
|
|
488
|
-
* Filling the calendar keeps a quiet day visible as a quiet day. */
|
|
489
|
-
function exportDailySeries(state, { window, period, firstDay, endDay }) {
|
|
490
|
-
return calendarDays(window.days === null ? firstDay : usageRollupDayKey(window.fromMs), period?.endDay || endDay).map(
|
|
491
|
-
(day) => {
|
|
492
|
-
const bucket = state.daily.get(day);
|
|
493
|
-
const future = period ? { future: day > endDay } : {};
|
|
494
|
-
if (!bucket) {
|
|
495
|
-
return { day, turns: 0, tokens: 0, cacheTokens: 0, costUsd: 0, costKnownTurns: 0, providers: [], ...future };
|
|
496
|
-
}
|
|
497
|
-
return {
|
|
498
|
-
day: bucket.day,
|
|
499
|
-
turns: bucket.turns,
|
|
500
|
-
tokens: tokensOf(bucket),
|
|
501
|
-
cacheTokens: bucket.cacheRead + bucket.cacheWrite,
|
|
502
|
-
costUsd: round(bucket.costUsd, 6),
|
|
503
|
-
costKnownTurns: num(bucket.costKnownTurns),
|
|
504
|
-
unmeasuredTurns: num(bucket.unmeasuredTurns),
|
|
505
|
-
...future,
|
|
506
|
-
providers: [...bucket.providers.values()]
|
|
507
|
-
.map((slice) => ({
|
|
508
|
-
provider: slice.provider,
|
|
509
|
-
turns: slice.turns,
|
|
510
|
-
tokens: tokensOf(slice),
|
|
511
|
-
costUsd: round(slice.costUsd, 6),
|
|
512
|
-
costKnownTurns: num(slice.costKnownTurns),
|
|
513
|
-
unmeasuredTurns: num(slice.unmeasuredTurns),
|
|
514
|
-
}))
|
|
515
|
-
.sort((a, b) => b.tokens - a.tokens),
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
/** Window totals: volume, spend and the derived per-day/per-session rates. */
|
|
522
|
-
function exportTotals(state, { sessionTotals, totalTokens, cacheTokens, effectiveDays }) {
|
|
523
|
-
return {
|
|
524
|
-
sessions: sessionTotals.length,
|
|
525
|
-
sessionsComplete: state.sessionsComplete,
|
|
526
|
-
turns: state.turns,
|
|
527
|
-
days: effectiveDays,
|
|
528
|
-
input: state.input,
|
|
529
|
-
output: state.output,
|
|
530
|
-
tokens: totalTokens,
|
|
531
|
-
unmeasuredTurns: state.unmeasuredTurns,
|
|
532
|
-
cacheRead: state.cacheRead,
|
|
533
|
-
cacheWrite: state.cacheWrite,
|
|
534
|
-
cacheTokens,
|
|
535
|
-
totalTokens,
|
|
536
|
-
// How much of the prompt arrived from cache instead of being read again.
|
|
537
|
-
cacheHitRate: measuredRatio(
|
|
538
|
-
state.unmeasuredTurns,
|
|
539
|
-
state.cacheRead,
|
|
540
|
-
state.input + state.cacheRead + state.cacheWrite,
|
|
541
|
-
4
|
|
542
|
-
),
|
|
543
|
-
costUsd: round(state.costUsd, 6),
|
|
544
|
-
costKnownTurns: state.costKnownTurns,
|
|
545
|
-
costUnpricedTurns: Math.max(0, state.turns - state.costKnownTurns),
|
|
546
|
-
// Priced by the provider vs derived from the catalog. A subscription turn
|
|
547
|
-
// lands in the second: real spend, but never an invoice line.
|
|
548
|
-
costBilled: round(state.costBilled, 6),
|
|
549
|
-
costEstimated: round(state.costEstimated, 6),
|
|
550
|
-
costPerDay: effectiveDays > 0 ? round(state.costUsd / effectiveDays, 6) : 0,
|
|
551
|
-
tokensPerSession: sessionTotals.length ? Math.round(totalTokens / sessionTotals.length) : 0,
|
|
552
|
-
medianTokensPerSession: Math.round(median(sessionTotals)),
|
|
553
|
-
avgDurationMs: state.durationTurns > 0 ? Math.round(state.durationMs / state.durationTurns) : 0,
|
|
554
|
-
// 1 = every turn carries a real price; below that some rows are unpriced.
|
|
555
|
-
costCoverage: state.turns > 0 ? round(state.costKnownTurns / state.turns, 4) : 0,
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/** How much of the window the figures actually saw, and what they had to skip. */
|
|
560
|
-
function exportCoverage(state, historyPending) {
|
|
561
|
-
return {
|
|
562
|
-
rollupDays: state.rollupDays,
|
|
563
|
-
eventDays: state.eventDays,
|
|
564
|
-
// Days rebuilt from transcripts, and whether that rebuild is still
|
|
565
|
-
// running — a surface can then say the older figures may still grow.
|
|
566
|
-
historyDays: state.historyDays,
|
|
567
|
-
historyPending: historyPending === true,
|
|
568
|
-
sessionsDropped: state.sessionsDropped,
|
|
569
|
-
// Days the rollup holds without a source split; excluded from a
|
|
570
|
-
// conversation-only view rather than guessed at.
|
|
571
|
-
unclassifiedDays: state.unclassifiedDays,
|
|
572
|
-
unclassifiedTurns: state.unclassifiedTurns,
|
|
573
|
-
partialDays: state.partialDays,
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* @param {object} options
|
|
579
|
-
* @param {Array} [options.events] raw gateway usage events
|
|
580
|
-
* @param {object} [options.rollup] normalized daily rollup document
|
|
581
|
-
* @param {number} [options.now]
|
|
582
|
-
* @param {number|null} [options.days] null = all time, 0 = today, N = last N days
|
|
583
|
-
* @param {number} [options.modelLimit] 0 = every model
|
|
584
|
-
* @param {'conversation'|'all'} [options.source] default: the user's own turns
|
|
585
|
-
* @param {object|null} [options.period] calendar selection from resolveUsageStatsPeriod
|
|
586
|
-
*/
|
|
587
|
-
export function usageStatsSnapshot({
|
|
588
|
-
events = [],
|
|
589
|
-
rollup = null,
|
|
590
|
-
history = null,
|
|
591
|
-
historyPending = false,
|
|
592
|
-
now = Date.now(),
|
|
593
|
-
days = null,
|
|
594
|
-
period = null,
|
|
595
|
-
modelLimit = 0,
|
|
596
|
-
source = 'conversation',
|
|
597
|
-
} = {}) {
|
|
598
|
-
const conversationOnly = source !== 'all';
|
|
599
|
-
const window = period ? { days: period.days, fromMs: period.fromMs, toMs: period.toMs } : resolveWindow(days, now);
|
|
600
|
-
const rollupDays = rollup?.days && typeof rollup.days === 'object' ? rollup.days : {};
|
|
601
|
-
let historyDays = {};
|
|
602
|
-
if (history?.days && typeof history.days === 'object') historyDays = history.days;
|
|
603
|
-
else if (history && typeof history === 'object') historyDays = history;
|
|
604
|
-
const eventList = Array.isArray(events) ? events : [];
|
|
605
|
-
const state = collect({ events: eventList, rollupDays, historyDays, window, conversationOnly });
|
|
606
|
-
|
|
607
|
-
const cacheTokens = state.cacheRead + state.cacheWrite;
|
|
608
|
-
const totalTokens = state.input + state.output + cacheTokens;
|
|
609
|
-
const sessionTotals = [...state.sessions.values(), ...state.anonymousSessions];
|
|
610
|
-
const dayKeys = [...state.dayKeys].sort();
|
|
611
|
-
const firstDay = dayKeys[0] || '';
|
|
612
|
-
const lastDay = dayKeys[dayKeys.length - 1] || '';
|
|
613
|
-
// Cost per day is read against the calendar span, not the days that happened
|
|
614
|
-
// to have traffic — an idle day still spends nothing and must dilute it.
|
|
615
|
-
const endDay = usageRollupDayKey(window.toMs);
|
|
616
|
-
const spanDays = firstDay ? calendarDays(firstDay, endDay).length : 0;
|
|
617
|
-
const effectiveDays = window.days === null ? spanDays : Math.max(1, window.days || 1);
|
|
618
|
-
|
|
619
|
-
const providers = exportProviders(state, { totalTokens, modelLimit });
|
|
620
|
-
const daily = exportDailySeries(state, { window, period, firstDay, endDay });
|
|
621
|
-
|
|
622
|
-
// "All time" has nothing before it to compare against.
|
|
623
|
-
const earlier = period ? null : previousWindow(window);
|
|
624
|
-
const prior = earlier
|
|
625
|
-
? collect({ events: eventList, rollupDays, historyDays, window: earlier, conversationOnly })
|
|
626
|
-
: null;
|
|
627
|
-
|
|
628
|
-
return {
|
|
629
|
-
generatedAt: now,
|
|
630
|
-
...(period ? { period } : {}),
|
|
631
|
-
...(period?.view === 'hour' ? { hourly: hourlySeries(rollup?.hourly, period, conversationOnly) } : {}),
|
|
632
|
-
source: conversationOnly ? 'conversation' : 'all',
|
|
633
|
-
range: {
|
|
634
|
-
days: window.days,
|
|
635
|
-
fromMs: window.fromMs,
|
|
636
|
-
toMs: window.toMs,
|
|
637
|
-
firstDay,
|
|
638
|
-
lastDay,
|
|
639
|
-
activeDays: dayKeys.length,
|
|
640
|
-
},
|
|
641
|
-
totals: exportTotals(state, { sessionTotals, totalTokens, cacheTokens, effectiveDays }),
|
|
642
|
-
previous: prior
|
|
643
|
-
? {
|
|
644
|
-
turns: prior.turns,
|
|
645
|
-
tokens: tokensOf(prior),
|
|
646
|
-
costUsd: round(prior.costUsd, 6),
|
|
647
|
-
}
|
|
648
|
-
: null,
|
|
649
|
-
daily,
|
|
650
|
-
providers,
|
|
651
|
-
coverage: exportCoverage(state, historyPending),
|
|
652
|
-
};
|
|
653
|
-
}
|
|
1
|
+
export * from '../session-runtime/services/usage-stats-model.mjs';
|