muonroi-cli 1.3.4 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +122 -122
- package/dist/packages/agent-harness-core/src/predicate.d.ts +2 -2
- package/dist/packages/agent-harness-core/src/protocol.d.ts +8 -0
- package/dist/src/__test-helpers__/catalog-fixtures.d.ts +22 -0
- package/dist/src/__test-helpers__/catalog-fixtures.js +55 -0
- package/dist/src/agent-harness/index.js +1 -1
- package/dist/src/agent-harness/mock-model.d.ts +5 -0
- package/dist/src/agent-harness/mock-model.js +68 -23
- package/dist/src/agent-harness/test-spawn.d.ts +7 -1
- package/dist/src/agent-harness/test-spawn.js +19 -4
- package/dist/src/chat/__tests__/broadcast-bus.test.js +2 -2
- package/dist/src/chat/__tests__/client.test.js +1 -1
- package/dist/src/chat/broadcast-bus.js +2 -2
- package/dist/src/chat/chat-keychain.js +11 -2
- package/dist/src/chat/providers/discord/client.d.ts +1 -1
- package/dist/src/chat/providers/discord/client.js +1 -1
- package/dist/src/cli/config/screen-council.js +1 -1
- package/dist/src/cli/config/screen-models.js +2 -2
- package/dist/src/cli/config/screen-providers.js +2 -2
- package/dist/src/cli/config/tui.js +1 -1
- package/dist/src/cli/cost-forensics.d.ts +31 -0
- package/dist/src/cli/cost-forensics.js +58 -12
- package/dist/src/cli/cost-forensics.test.js +125 -2
- package/dist/src/cli/keys.d.ts +5 -1
- package/dist/src/cli/keys.js +48 -20
- package/dist/src/cli/keys.test.js +1 -1
- package/dist/src/cli/reporter-cmd.d.ts +15 -0
- package/dist/src/cli/reporter-cmd.js +120 -0
- package/dist/src/cli/usage-report.d.ts +38 -1
- package/dist/src/cli/usage-report.js +133 -0
- package/dist/src/council/__tests__/audit-replay.test.js +1 -1
- package/dist/src/council/__tests__/clarifier-max-rounds.test.js +5 -5
- package/dist/src/council/__tests__/clarifier-ready-gate.test.js +233 -0
- package/dist/src/council/__tests__/debate-planner-structured.test.js +2 -2
- package/dist/src/council/__tests__/decisions-lock.test.d.ts +6 -0
- package/dist/src/council/__tests__/decisions-lock.test.js +336 -0
- package/dist/src/council/__tests__/tool-trace.test.js +2 -2
- package/dist/src/council/clarifier.d.ts +19 -2
- package/dist/src/council/clarifier.js +84 -6
- package/dist/src/council/context.js +3 -3
- package/dist/src/council/debate-planner.d.ts +1 -1
- package/dist/src/council/debate-planner.js +40 -7
- package/dist/src/council/debate.js +1 -1
- package/dist/src/council/decisions-lock.d.ts +76 -0
- package/dist/src/council/decisions-lock.js +239 -0
- package/dist/src/council/index.d.ts +5 -0
- package/dist/src/council/index.js +50 -18
- package/dist/src/council/leader.d.ts +1 -1
- package/dist/src/council/leader.js +14 -1
- package/dist/src/council/llm.js +33 -61
- package/dist/src/council/phase-events.d.ts +5 -0
- package/dist/src/council/phase-events.js +1 -0
- package/dist/src/council/planner.js +1 -1
- package/dist/src/council/prompts.d.ts +24 -0
- package/dist/src/council/prompts.js +112 -22
- package/dist/src/council/types.d.ts +18 -0
- package/dist/src/ee/__tests__/export-transcripts.test.d.ts +11 -0
- package/dist/src/ee/__tests__/export-transcripts.test.js +200 -0
- package/dist/src/ee/__tests__/recall-format.test.d.ts +10 -0
- package/dist/src/ee/__tests__/recall-format.test.js +57 -0
- package/dist/src/ee/__tests__/recall-ledger.test.d.ts +1 -0
- package/dist/src/ee/__tests__/recall-ledger.test.js +45 -0
- package/dist/src/ee/auth.test.js +2 -2
- package/dist/src/ee/client.js +59 -0
- package/dist/src/ee/client.test.js +30 -0
- package/dist/src/ee/council-bridge.js +3 -3
- package/dist/src/ee/export-transcripts.d.ts +26 -0
- package/dist/src/ee/export-transcripts.js +115 -0
- package/dist/src/ee/intercept.d.ts +9 -0
- package/dist/src/ee/intercept.js +19 -0
- package/dist/src/ee/offline-queue.test.js +3 -3
- package/dist/src/ee/phase-tracker.js +1 -1
- package/dist/src/ee/recall-ledger.d.ts +32 -0
- package/dist/src/ee/recall-ledger.js +52 -0
- package/dist/src/ee/recall-mirror.test.d.ts +1 -0
- package/dist/src/ee/recall-mirror.test.js +65 -0
- package/dist/src/ee/scope.js +1 -1
- package/dist/src/ee/scope.test.js +1 -1
- package/dist/src/ee/search.d.ts +99 -0
- package/dist/src/ee/search.js +220 -0
- package/dist/src/ee/session-trajectory.js +1 -1
- package/dist/src/ee/session-trajectory.test.js +1 -1
- package/dist/src/ee/transcript-emit.d.ts +51 -0
- package/dist/src/ee/transcript-emit.js +140 -0
- package/dist/src/ee/types.d.ts +37 -1
- package/dist/src/flow/__tests__/migration.test.js +1 -1
- package/dist/src/flow/__tests__/run-manager-product.test.js +1 -1
- package/dist/src/flow/__tests__/run-manager.test.js +1 -1
- package/dist/src/flow/__tests__/scaffold-checkpoint.test.js +2 -2
- package/dist/src/flow/__tests__/scaffold.test.js +1 -1
- package/dist/src/flow/__tests__/warning-persist.test.js +1 -1
- package/dist/src/generated/version.d.ts +1 -1
- package/dist/src/generated/version.js +1 -1
- package/dist/src/gsd/__tests__/directives.test.js +35 -0
- package/dist/src/gsd/__tests__/types.test.js +14 -1
- package/dist/src/gsd/directives.d.ts +10 -0
- package/dist/src/gsd/directives.js +38 -2
- package/dist/src/gsd/gray-areas.js +1 -1
- package/dist/src/gsd/types.d.ts +1 -1
- package/dist/src/gsd/types.js +20 -6
- package/dist/src/headless/__tests__/council-answers.test.js +26 -1
- package/dist/src/headless/council-answers.d.ts +17 -2
- package/dist/src/headless/council-answers.js +21 -0
- package/dist/src/hooks/index.js +74 -49
- package/dist/src/index.js +180 -16
- package/dist/src/lsp/builtins.js +44 -0
- package/dist/src/lsp/builtins.test.js +22 -1
- package/dist/src/lsp/manager.js +40 -9
- package/dist/src/lsp/manager.test.js +23 -1
- package/dist/src/lsp/npm-cache.js +2 -1
- package/dist/src/lsp/npm-cache.test.js +1 -1
- package/dist/src/lsp/smoke.test.js +1 -1
- package/dist/src/lsp/types.d.ts +3 -1
- package/dist/src/maintain/__tests__/codebase-intel.test.d.ts +5 -0
- package/dist/src/maintain/__tests__/codebase-intel.test.js +237 -0
- package/dist/src/maintain/__tests__/gh-create-pr.test.d.ts +11 -0
- package/dist/src/maintain/__tests__/gh-create-pr.test.js +156 -0
- package/dist/src/maintain/__tests__/pr-builder.test.d.ts +10 -0
- package/dist/src/maintain/__tests__/pr-builder.test.js +225 -0
- package/dist/src/maintain/__tests__/repo-map.test.d.ts +5 -0
- package/dist/src/maintain/__tests__/repo-map.test.js +90 -0
- package/dist/src/maintain/__tests__/task-runner.test.d.ts +11 -0
- package/dist/src/maintain/__tests__/task-runner.test.js +281 -0
- package/dist/src/maintain/codebase-intel.d.ts +22 -0
- package/dist/src/maintain/codebase-intel.js +548 -0
- package/dist/src/maintain/gh-create-pr.d.ts +24 -0
- package/dist/src/maintain/gh-create-pr.js +111 -0
- package/dist/src/maintain/index.d.ts +12 -0
- package/dist/src/maintain/index.js +10 -0
- package/dist/src/maintain/pr-builder.d.ts +35 -0
- package/dist/src/maintain/pr-builder.js +305 -0
- package/dist/src/maintain/repo-map.d.ts +25 -0
- package/dist/src/maintain/repo-map.js +189 -0
- package/dist/src/maintain/task-runner.d.ts +45 -0
- package/dist/src/maintain/task-runner.js +401 -0
- package/dist/src/maintain/types.d.ts +45 -0
- package/dist/src/maintain/types.js +7 -0
- package/dist/src/mcp/__tests__/auto-setup.test.js +1 -1
- package/dist/src/mcp/__tests__/cap-tool-result.test.d.ts +1 -0
- package/dist/src/mcp/__tests__/cap-tool-result.test.js +58 -0
- package/dist/src/mcp/__tests__/ee-tools.test.d.ts +1 -0
- package/dist/src/mcp/__tests__/ee-tools.test.js +198 -0
- package/dist/src/mcp/__tests__/forensics-tools.test.d.ts +1 -0
- package/dist/src/mcp/__tests__/forensics-tools.test.js +53 -0
- package/dist/src/mcp/__tests__/harness-driver-action-tools.spec.js +3 -1
- package/dist/src/mcp/__tests__/harness-driver-async-tools.spec.js +3 -1
- package/dist/src/mcp/__tests__/lsp-tools.test.d.ts +1 -0
- package/dist/src/mcp/__tests__/lsp-tools.test.js +56 -0
- package/dist/src/mcp/__tests__/runtime-output-cap.test.d.ts +1 -0
- package/dist/src/mcp/__tests__/runtime-output-cap.test.js +42 -0
- package/dist/src/mcp/__tests__/self-verify-jobs.test.d.ts +1 -0
- package/dist/src/mcp/__tests__/self-verify-jobs.test.js +92 -0
- package/dist/src/mcp/__tests__/smart-filter.test.d.ts +1 -0
- package/dist/src/mcp/__tests__/smart-filter.test.js +121 -0
- package/dist/src/mcp/__tests__/tools-server.smoke.test.d.ts +1 -0
- package/dist/src/mcp/__tests__/tools-server.smoke.test.js +42 -0
- package/dist/src/mcp/cap-tool-result.d.ts +1 -0
- package/dist/src/mcp/cap-tool-result.js +35 -0
- package/dist/src/mcp/ee-tools.d.ts +36 -0
- package/dist/src/mcp/ee-tools.js +159 -0
- package/dist/src/mcp/forensics-tools.d.ts +13 -0
- package/dist/src/mcp/forensics-tools.js +52 -0
- package/dist/src/mcp/lsp-tools.d.ts +16 -0
- package/dist/src/mcp/lsp-tools.js +65 -0
- package/dist/src/mcp/mcp-keychain.js +11 -2
- package/dist/src/mcp/oauth-callback.js +2 -2
- package/dist/src/mcp/opentui-spawn.js +1 -1
- package/dist/src/mcp/parse-headers.test.js +14 -14
- package/dist/src/mcp/runtime.js +11 -0
- package/dist/src/mcp/self-verify-jobs.d.ts +55 -0
- package/dist/src/mcp/self-verify-jobs.js +86 -0
- package/dist/src/mcp/smart-filter.d.ts +48 -0
- package/dist/src/mcp/smart-filter.js +115 -0
- package/dist/src/mcp/smoke.test.js +44 -44
- package/dist/src/mcp/tools-server.d.ts +14 -0
- package/dist/src/mcp/tools-server.js +147 -0
- package/dist/src/models/catalog-client.d.ts +22 -0
- package/dist/src/models/catalog-client.js +95 -9
- package/dist/src/models/catalog-gemini.test.d.ts +1 -0
- package/dist/src/models/catalog-gemini.test.js +46 -0
- package/dist/src/models/catalog-url.test.d.ts +1 -0
- package/dist/src/models/catalog-url.test.js +26 -0
- package/dist/src/models/catalog-validation.test.d.ts +1 -0
- package/dist/src/models/catalog-validation.test.js +63 -0
- package/dist/src/models/catalog.json +349 -177
- package/dist/src/models/classify-tier.d.ts +1 -1
- package/dist/src/models/classify-tier.js +1 -1
- package/dist/src/models/registry.d.ts +2 -0
- package/dist/src/models/registry.js +9 -0
- package/dist/src/ops/__tests__/doctor-ee-health.test.js +1 -1
- package/dist/src/ops/doctor.js +7 -7
- package/dist/src/orchestrator/__tests__/agent-base-url-switch.test.d.ts +1 -0
- package/dist/src/orchestrator/__tests__/agent-base-url-switch.test.js +77 -0
- package/dist/src/orchestrator/__tests__/batch-turn-runner.test.js +10 -3
- package/dist/src/orchestrator/__tests__/cross-turn-dedup.test.js +38 -16
- package/dist/src/orchestrator/__tests__/error-forensics.test.d.ts +1 -0
- package/dist/src/orchestrator/__tests__/error-forensics.test.js +93 -0
- package/dist/src/orchestrator/__tests__/flow-resume.test.js +1 -1
- package/dist/src/orchestrator/__tests__/humanize-api-error.test.d.ts +1 -0
- package/dist/src/orchestrator/__tests__/humanize-api-error.test.js +68 -0
- package/dist/src/orchestrator/__tests__/message-processor.test.js +6 -1
- package/dist/src/orchestrator/__tests__/read-path-budget.test.js +62 -4
- package/dist/src/orchestrator/__tests__/retry-classifier.test.js +10 -0
- package/dist/src/orchestrator/__tests__/stream-runner.test.js +77 -4
- package/dist/src/orchestrator/__tests__/sub-agent-model-tier.test.d.ts +1 -0
- package/dist/src/orchestrator/__tests__/sub-agent-model-tier.test.js +45 -0
- package/dist/src/orchestrator/__tests__/usage-shape-threading.test.d.ts +1 -0
- package/dist/src/orchestrator/__tests__/usage-shape-threading.test.js +98 -0
- package/dist/src/orchestrator/agent.test.js +33 -18
- package/dist/src/orchestrator/batch-turn-runner.d.ts +1 -1
- package/dist/src/orchestrator/batch-turn-runner.js +3 -2
- package/dist/src/orchestrator/compaction.js +99 -87
- package/dist/src/orchestrator/compaction.test.js +17 -0
- package/dist/src/orchestrator/council-manager.d.ts +1 -1
- package/dist/src/orchestrator/council-manager.js +3 -10
- package/dist/src/orchestrator/cross-turn-dedup.js +21 -1
- package/dist/src/orchestrator/delegations.js +7 -1
- package/dist/src/orchestrator/delegations.test.js +1 -1
- package/dist/src/orchestrator/error-utils.d.ts +27 -1
- package/dist/src/orchestrator/error-utils.js +63 -1
- package/dist/src/orchestrator/grounding-check.d.ts +50 -0
- package/dist/src/orchestrator/grounding-check.js +123 -0
- package/dist/src/orchestrator/grounding-check.test.d.ts +1 -0
- package/dist/src/orchestrator/grounding-check.test.js +94 -0
- package/dist/src/orchestrator/interrupted-turn.d.ts +19 -0
- package/dist/src/orchestrator/interrupted-turn.js +28 -0
- package/dist/src/orchestrator/interrupted-turn.test.d.ts +1 -0
- package/dist/src/orchestrator/interrupted-turn.test.js +34 -0
- package/dist/src/orchestrator/message-processor.d.ts +11 -10
- package/dist/src/orchestrator/message-processor.js +1367 -93
- package/dist/src/orchestrator/orchestrator.d.ts +7 -3
- package/dist/src/orchestrator/orchestrator.js +158 -43
- package/dist/src/orchestrator/pending-calls.test.js +1 -1
- package/dist/src/orchestrator/prompts.d.ts +1 -1
- package/dist/src/orchestrator/prompts.js +237 -154
- package/dist/src/orchestrator/read-path-budget.d.ts +22 -2
- package/dist/src/orchestrator/read-path-budget.js +96 -18
- package/dist/src/orchestrator/reasoning.js +43 -1
- package/dist/src/orchestrator/reasoning.test.js +75 -0
- package/dist/src/orchestrator/repair-tool-call.d.ts +32 -0
- package/dist/src/orchestrator/repair-tool-call.js +50 -0
- package/dist/src/orchestrator/repetition-detector.d.ts +58 -0
- package/dist/src/orchestrator/repetition-detector.js +126 -0
- package/dist/src/orchestrator/repetition-detector.test.d.ts +1 -0
- package/dist/src/orchestrator/repetition-detector.test.js +103 -0
- package/dist/src/orchestrator/retry-classifier.js +8 -0
- package/dist/src/orchestrator/sandbox.test.js +3 -1
- package/dist/src/orchestrator/scope-ceiling.d.ts +86 -0
- package/dist/src/orchestrator/scope-ceiling.js +161 -0
- package/dist/src/orchestrator/scope-ceiling.test.d.ts +13 -0
- package/dist/src/orchestrator/scope-ceiling.test.js +181 -0
- package/dist/src/orchestrator/scope-reminder.d.ts +102 -0
- package/dist/src/orchestrator/scope-reminder.js +221 -0
- package/dist/src/orchestrator/scope-reminder.test.d.ts +15 -0
- package/dist/src/orchestrator/scope-reminder.test.js +204 -0
- package/dist/src/orchestrator/stall-rescue.d.ts +67 -0
- package/dist/src/orchestrator/stall-rescue.js +72 -0
- package/dist/src/orchestrator/stall-rescue.test.d.ts +1 -0
- package/dist/src/orchestrator/stall-rescue.test.js +88 -0
- package/dist/src/orchestrator/stall-watchdog.d.ts +34 -0
- package/dist/src/orchestrator/stall-watchdog.js +72 -0
- package/dist/src/orchestrator/stall-watchdog.test.d.ts +1 -0
- package/dist/src/orchestrator/stall-watchdog.test.js +73 -0
- package/dist/src/orchestrator/stream-runner.d.ts +18 -2
- package/dist/src/orchestrator/stream-runner.js +248 -77
- package/dist/src/orchestrator/sub-agent-cap.js +21 -1
- package/dist/src/orchestrator/sub-agent-cap.test.js +41 -3
- package/dist/src/orchestrator/sub-agent-model-tier.d.ts +13 -0
- package/dist/src/orchestrator/sub-agent-model-tier.js +45 -0
- package/dist/src/orchestrator/subagent-compactor.d.ts +49 -0
- package/dist/src/orchestrator/subagent-compactor.js +184 -11
- package/dist/src/orchestrator/subagent-compactor.spec.js +187 -2
- package/dist/src/orchestrator/text-tool-call-detector.d.ts +61 -0
- package/dist/src/orchestrator/text-tool-call-detector.js +163 -0
- package/dist/src/orchestrator/text-tool-call-detector.test.d.ts +1 -0
- package/dist/src/orchestrator/text-tool-call-detector.test.js +89 -0
- package/dist/src/orchestrator/tool-args-hash.d.ts +51 -0
- package/dist/src/orchestrator/tool-args-hash.js +219 -0
- package/dist/src/orchestrator/tool-args-hash.test.d.ts +1 -0
- package/dist/src/orchestrator/tool-args-hash.test.js +105 -0
- package/dist/src/orchestrator/tool-args-repair.d.ts +93 -0
- package/dist/src/orchestrator/tool-args-repair.js +219 -0
- package/dist/src/orchestrator/tool-args-repair.test.d.ts +1 -0
- package/dist/src/orchestrator/tool-args-repair.test.js +136 -0
- package/dist/src/orchestrator/tool-loop-cap.d.ts +66 -0
- package/dist/src/orchestrator/tool-loop-cap.js +138 -0
- package/dist/src/orchestrator/tool-loop-cap.test.d.ts +1 -0
- package/dist/src/orchestrator/tool-loop-cap.test.js +176 -0
- package/dist/src/orchestrator/tool-repetition-detector.d.ts +64 -0
- package/dist/src/orchestrator/tool-repetition-detector.js +0 -0
- package/dist/src/orchestrator/tool-repetition-detector.test.d.ts +1 -0
- package/dist/src/orchestrator/tool-repetition-detector.test.js +101 -0
- package/dist/src/orchestrator/turn-runner-deps.d.ts +3 -1
- package/dist/src/pil/__tests__/clarity-gate.test.d.ts +1 -0
- package/dist/src/pil/__tests__/clarity-gate.test.js +228 -0
- package/dist/src/pil/__tests__/config.test.js +44 -1
- package/dist/src/pil/__tests__/discovery-cache.test.d.ts +1 -0
- package/dist/src/pil/__tests__/discovery-cache.test.js +38 -0
- package/dist/src/pil/__tests__/discovery-types.test.d.ts +1 -0
- package/dist/src/pil/__tests__/discovery-types.test.js +54 -0
- package/dist/src/pil/__tests__/discovery.test.d.ts +1 -0
- package/dist/src/pil/__tests__/discovery.test.js +101 -0
- package/dist/src/pil/__tests__/layer1-intent-trace.test.js +5 -3
- package/dist/src/pil/__tests__/layer1-intent.test.js +25 -7
- package/dist/src/pil/__tests__/layer15-context-scan.test.d.ts +1 -0
- package/dist/src/pil/__tests__/layer15-context-scan.test.js +64 -0
- package/dist/src/pil/__tests__/layer16-clarity.test.d.ts +1 -0
- package/dist/src/pil/__tests__/layer16-clarity.test.js +153 -0
- package/dist/src/pil/__tests__/layer17-feasibility.test.d.ts +1 -0
- package/dist/src/pil/__tests__/layer17-feasibility.test.js +36 -0
- package/dist/src/pil/__tests__/layer18-acceptance.test.d.ts +1 -0
- package/dist/src/pil/__tests__/layer18-acceptance.test.js +95 -0
- package/dist/src/pil/__tests__/layer3-ee-injection.test.js +4 -1
- package/dist/src/pil/__tests__/layer3-injected-chunk.test.js +3 -3
- package/dist/src/pil/__tests__/layer6-output.test.js +69 -9
- package/dist/src/pil/__tests__/llm-classify.test.d.ts +1 -0
- package/dist/src/pil/__tests__/llm-classify.test.js +113 -0
- package/dist/src/pil/__tests__/native-capabilities-workbook.test.d.ts +1 -0
- package/dist/src/pil/__tests__/native-capabilities-workbook.test.js +40 -0
- package/dist/src/pil/__tests__/pipeline.test.js +3 -2
- package/dist/src/pil/__tests__/renderer-coverage.test.js +1 -1
- package/dist/src/pil/__tests__/response-tools.test.js +49 -1
- package/dist/src/pil/__tests__/scoreComplexity.test.js +2 -2
- package/dist/src/pil/agent-operating-contract.d.ts +51 -0
- package/dist/src/pil/agent-operating-contract.js +66 -0
- package/dist/src/pil/agent-operating-contract.test.d.ts +1 -0
- package/dist/src/pil/agent-operating-contract.test.js +75 -0
- package/dist/src/pil/budget-log.js +1 -1
- package/dist/src/pil/cheap-model-playbook.d.ts +80 -0
- package/dist/src/pil/cheap-model-playbook.js +147 -0
- package/dist/src/pil/cheap-model-playbook.test.d.ts +1 -0
- package/dist/src/pil/cheap-model-playbook.test.js +160 -0
- package/dist/src/pil/cheap-model-workbooks.d.ts +55 -0
- package/dist/src/pil/cheap-model-workbooks.js +102 -0
- package/dist/src/pil/cheap-model-workbooks.test.d.ts +1 -0
- package/dist/src/pil/cheap-model-workbooks.test.js +129 -0
- package/dist/src/pil/clarity-gate.d.ts +22 -0
- package/dist/src/pil/clarity-gate.js +162 -0
- package/dist/src/pil/config.d.ts +3 -0
- package/dist/src/pil/config.js +11 -0
- package/dist/src/pil/discovery-cache.d.ts +4 -0
- package/dist/src/pil/discovery-cache.js +18 -0
- package/dist/src/pil/discovery-types.d.ts +94 -0
- package/dist/src/pil/discovery-types.js +2 -0
- package/dist/src/pil/discovery.d.ts +18 -0
- package/dist/src/pil/discovery.js +341 -0
- package/dist/src/pil/index.d.ts +3 -1
- package/dist/src/pil/index.js +2 -1
- package/dist/src/pil/layer1-intent.d.ts +37 -1
- package/dist/src/pil/layer1-intent.js +675 -39
- package/dist/src/pil/layer1-intent.test.js +333 -1
- package/dist/src/pil/layer15-context-scan.d.ts +9 -0
- package/dist/src/pil/layer15-context-scan.js +164 -0
- package/dist/src/pil/layer16-clarity.d.ts +19 -0
- package/dist/src/pil/layer16-clarity.js +394 -0
- package/dist/src/pil/layer16-clarity.test.d.ts +1 -0
- package/dist/src/pil/layer16-clarity.test.js +31 -0
- package/dist/src/pil/layer17-feasibility.d.ts +4 -0
- package/dist/src/pil/layer17-feasibility.js +30 -0
- package/dist/src/pil/layer18-acceptance.d.ts +4 -0
- package/dist/src/pil/layer18-acceptance.js +84 -0
- package/dist/src/pil/layer1_5-complexity-size.d.ts +23 -0
- package/dist/src/pil/layer1_5-complexity-size.js +152 -0
- package/dist/src/pil/layer1_5-complexity-size.test.d.ts +10 -0
- package/dist/src/pil/layer1_5-complexity-size.test.js +248 -0
- package/dist/src/pil/layer3-ee-injection.js +63 -6
- package/dist/src/pil/layer4-gsd.js +7 -1
- package/dist/src/pil/layer5-context.js +15 -5
- package/dist/src/pil/layer6-output.d.ts +2 -0
- package/dist/src/pil/layer6-output.js +110 -18
- package/dist/src/pil/llm-classify.d.ts +16 -0
- package/dist/src/pil/llm-classify.js +179 -0
- package/dist/src/pil/native-capabilities-workbook.d.ts +39 -0
- package/dist/src/pil/native-capabilities-workbook.js +112 -0
- package/dist/src/pil/pipeline.d.ts +21 -0
- package/dist/src/pil/pipeline.js +89 -13
- package/dist/src/pil/response-tools.d.ts +56 -0
- package/dist/src/pil/response-tools.js +76 -2
- package/dist/src/pil/schema.d.ts +10 -1
- package/dist/src/pil/schema.js +8 -0
- package/dist/src/pil/session-state.d.ts +44 -0
- package/dist/src/pil/session-state.js +143 -0
- package/dist/src/pil/session-state.test.d.ts +1 -0
- package/dist/src/pil/session-state.test.js +73 -0
- package/dist/src/pil/task-tier-map.d.ts +6 -1
- package/dist/src/pil/task-tier-map.js +13 -6
- package/dist/src/pil/types.d.ts +18 -0
- package/dist/src/product-loop/__tests__/artifact-io.test.js +1 -1
- package/dist/src/product-loop/__tests__/assumption-ledger.test.js +1 -1
- package/dist/src/product-loop/__tests__/backlog-builder.test.d.ts +10 -0
- package/dist/src/product-loop/__tests__/backlog-builder.test.js +175 -0
- package/dist/src/product-loop/__tests__/backlog-store.test.d.ts +4 -0
- package/dist/src/product-loop/__tests__/backlog-store.test.js +96 -0
- package/dist/src/product-loop/__tests__/cb2-retry-bonus.test.js +1 -1
- package/dist/src/product-loop/__tests__/complexity-routing.spec.js +113 -7
- package/dist/src/product-loop/__tests__/context-policy.test.js +3 -3
- package/dist/src/product-loop/__tests__/cost-scoper.test.js +1 -1
- package/dist/src/product-loop/__tests__/discovery-context-format.test.d.ts +13 -0
- package/dist/src/product-loop/__tests__/discovery-context-format.test.js +100 -0
- package/dist/src/product-loop/__tests__/discovery-ecosystem.test.js +100 -1
- package/dist/src/product-loop/__tests__/discovery-prompt-specificity.test.d.ts +1 -0
- package/dist/src/product-loop/__tests__/discovery-prompt-specificity.test.js +55 -0
- package/dist/src/product-loop/__tests__/discovery-recommender-ecosystem.test.js +92 -0
- package/dist/src/product-loop/__tests__/ee-extract-wiring.test.js +8 -3
- package/dist/src/product-loop/__tests__/extract-to-ee.test.js +2 -2
- package/dist/src/product-loop/__tests__/gather-selectable-alts.test.d.ts +15 -0
- package/dist/src/product-loop/__tests__/gather-selectable-alts.test.js +109 -0
- package/dist/src/product-loop/__tests__/integration.test.js +7 -2
- package/dist/src/product-loop/__tests__/loop-driver-audit.test.js +7 -2
- package/dist/src/product-loop/__tests__/loop-driver.test.js +7 -2
- package/dist/src/product-loop/__tests__/maintenance-task-synthesis.test.d.ts +8 -0
- package/dist/src/product-loop/__tests__/maintenance-task-synthesis.test.js +67 -0
- package/dist/src/product-loop/__tests__/phase-a1-a3-sprint-runner.test.d.ts +13 -0
- package/dist/src/product-loop/__tests__/phase-a1-a3-sprint-runner.test.js +268 -0
- package/dist/src/product-loop/__tests__/phase-a2-backlog-build.test.d.ts +8 -0
- package/dist/src/product-loop/__tests__/phase-a2-backlog-build.test.js +162 -0
- package/dist/src/product-loop/__tests__/phase-rituals.test.js +1 -1
- package/dist/src/product-loop/__tests__/pick-backend-stack.test.d.ts +11 -0
- package/dist/src/product-loop/__tests__/pick-backend-stack.test.js +95 -0
- package/dist/src/product-loop/__tests__/progress-snapshot.test.d.ts +8 -0
- package/dist/src/product-loop/__tests__/progress-snapshot.test.js +152 -0
- package/dist/src/product-loop/__tests__/repo-audit.test.js +1 -1
- package/dist/src/product-loop/__tests__/repo-brief.test.d.ts +9 -0
- package/dist/src/product-loop/__tests__/repo-brief.test.js +132 -0
- package/dist/src/product-loop/__tests__/route-decision-emit.test.js +51 -2
- package/dist/src/product-loop/__tests__/ship-polish.test.js +1 -1
- package/dist/src/product-loop/__tests__/sprint-planner.test.d.ts +6 -0
- package/dist/src/product-loop/__tests__/sprint-planner.test.js +140 -0
- package/dist/src/product-loop/__tests__/sprint-runner-backlog.test.d.ts +8 -0
- package/dist/src/product-loop/__tests__/sprint-runner-backlog.test.js +221 -0
- package/dist/src/product-loop/__tests__/sprint-runner-phase-chunks.test.d.ts +14 -0
- package/dist/src/product-loop/__tests__/sprint-runner-phase-chunks.test.js +193 -0
- package/dist/src/product-loop/__tests__/sprint-self-verify.test.d.ts +8 -0
- package/dist/src/product-loop/__tests__/sprint-self-verify.test.js +73 -0
- package/dist/src/product-loop/__tests__/sprint-store.test.d.ts +7 -0
- package/dist/src/product-loop/__tests__/sprint-store.test.js +84 -0
- package/dist/src/product-loop/__tests__/sufficiency-routing.spec.js +6 -0
- package/dist/src/product-loop/__tests__/types.test.js +7 -7
- package/dist/src/product-loop/__tests__/verify-failure-threshold.test.js +3 -2
- package/dist/src/product-loop/__tests__/verify-failure-tracking.test.js +2 -2
- package/dist/src/product-loop/assumption-ledger.js +6 -6
- package/dist/src/product-loop/backlog-builder.d.ts +32 -0
- package/dist/src/product-loop/backlog-builder.js +198 -0
- package/dist/src/product-loop/backlog-store.d.ts +22 -0
- package/dist/src/product-loop/backlog-store.js +49 -0
- package/dist/src/product-loop/context-policy.js +1 -1
- package/dist/src/product-loop/cost-preview.js +17 -1
- package/dist/src/product-loop/cross-run-memory.js +11 -11
- package/dist/src/product-loop/discover.js +6 -6
- package/dist/src/product-loop/discovery-context-format.d.ts +16 -0
- package/dist/src/product-loop/discovery-context-format.js +45 -13
- package/dist/src/product-loop/discovery-council-runner.js +5 -10
- package/dist/src/product-loop/discovery-detection.js +3 -3
- package/dist/src/product-loop/discovery-ecosystem.d.ts +23 -0
- package/dist/src/product-loop/discovery-ecosystem.js +104 -0
- package/dist/src/product-loop/discovery-interview.d.ts +6 -0
- package/dist/src/product-loop/discovery-interview.js +38 -2
- package/dist/src/product-loop/discovery-recommender.d.ts +29 -0
- package/dist/src/product-loop/discovery-recommender.js +126 -7
- package/dist/src/product-loop/done-gate.js +5 -5
- package/dist/src/product-loop/gather.d.ts +12 -1
- package/dist/src/product-loop/gather.js +93 -12
- package/dist/src/product-loop/index.d.ts +23 -0
- package/dist/src/product-loop/index.js +502 -9
- package/dist/src/product-loop/loop-driver.js +27 -28
- package/dist/src/product-loop/phase-budget.js +2 -2
- package/dist/src/product-loop/progress-snapshot.d.ts +25 -0
- package/dist/src/product-loop/progress-snapshot.js +180 -0
- package/dist/src/product-loop/repo-brief.d.ts +40 -0
- package/dist/src/product-loop/repo-brief.js +212 -0
- package/dist/src/product-loop/role-registry.js +1 -1
- package/dist/src/product-loop/sprint-planner.d.ts +39 -0
- package/dist/src/product-loop/sprint-planner.js +189 -0
- package/dist/src/product-loop/sprint-runner.js +201 -9
- package/dist/src/product-loop/sprint-self-verify.d.ts +54 -0
- package/dist/src/product-loop/sprint-self-verify.js +145 -0
- package/dist/src/product-loop/sprint-store.d.ts +27 -0
- package/dist/src/product-loop/sprint-store.js +81 -0
- package/dist/src/product-loop/typed-artifacts.js +5 -5
- package/dist/src/product-loop/types.d.ts +113 -2
- package/dist/src/product-loop/verify-failure-tracking.js +1 -1
- package/dist/src/providers/__tests__/adapter-oauth-wiring.test.js +18 -2
- package/dist/src/providers/__tests__/capabilities-provider-options.test.js +23 -1
- package/dist/src/providers/__tests__/capabilities-sanitize.test.js +46 -61
- package/dist/src/providers/__tests__/reasoning-roundtrip.test.d.ts +1 -0
- package/dist/src/providers/__tests__/reasoning-roundtrip.test.js +135 -0
- package/dist/src/providers/__tests__/runtime-integration.test.js +19 -12
- package/dist/src/providers/__tests__/runtime.test.js +3 -6
- package/dist/src/providers/__tests__/siliconflow-sse-repair.test.d.ts +1 -0
- package/dist/src/providers/__tests__/siliconflow-sse-repair.test.js +267 -0
- package/dist/src/providers/auth/__tests__/browser-flow.test.js +1 -1
- package/dist/src/providers/auth/__tests__/gemini-oauth.test.js +1 -1
- package/dist/src/providers/auth/__tests__/grok-oauth.test.d.ts +8 -0
- package/dist/src/providers/auth/__tests__/grok-oauth.test.js +236 -0
- package/dist/src/providers/auth/__tests__/token-store.test.js +7 -7
- package/dist/src/providers/auth/gemini-oauth.js +2 -2
- package/dist/src/providers/auth/grok-oauth.d.ts +63 -0
- package/dist/src/providers/auth/grok-oauth.js +341 -0
- package/dist/src/providers/auth/registry.js +17 -0
- package/dist/src/providers/auth/token-store.js +1 -1
- package/dist/src/providers/capabilities.js +9 -15
- package/dist/src/providers/keychain.js +14 -2
- package/dist/src/providers/mcp-vision-bridge.js +49 -49
- package/dist/src/providers/mcp-vision-bridge.test.js +12 -12
- package/dist/src/providers/openai-compatible.js +5 -1
- package/dist/src/providers/pricing.d.ts +7 -4
- package/dist/src/providers/pricing.js +21 -5
- package/dist/src/providers/pricing.test.js +35 -9
- package/dist/src/providers/runtime.d.ts +1 -0
- package/dist/src/providers/runtime.js +39 -13
- package/dist/src/providers/siliconflow-sse-repair.d.ts +58 -0
- package/dist/src/providers/siliconflow-sse-repair.js +177 -0
- package/dist/src/providers/strategies/deepseek.strategy.js +28 -0
- package/dist/src/providers/strategies/siliconflow.strategy.js +2 -0
- package/dist/src/providers/strategies/xai.strategy.js +8 -1
- package/dist/src/providers/wire-debug.js +2 -2
- package/dist/src/reporter/__tests__/acl-check.test.d.ts +6 -0
- package/dist/src/reporter/__tests__/acl-check.test.js +59 -0
- package/dist/src/reporter/__tests__/auto-fire.test.d.ts +10 -0
- package/dist/src/reporter/__tests__/auto-fire.test.js +140 -0
- package/dist/src/reporter/__tests__/budget.test.d.ts +7 -0
- package/dist/src/reporter/__tests__/budget.test.js +60 -0
- package/dist/src/reporter/__tests__/handlers.test.d.ts +7 -0
- package/dist/src/reporter/__tests__/handlers.test.js +163 -0
- package/dist/src/reporter/__tests__/query-router.test.d.ts +6 -0
- package/dist/src/reporter/__tests__/query-router.test.js +90 -0
- package/dist/src/reporter/acl-check.d.ts +23 -0
- package/dist/src/reporter/acl-check.js +43 -0
- package/dist/src/reporter/auto-fire.d.ts +59 -0
- package/dist/src/reporter/auto-fire.js +126 -0
- package/dist/src/reporter/budget.d.ts +17 -0
- package/dist/src/reporter/budget.js +52 -0
- package/dist/src/reporter/handlers.d.ts +32 -0
- package/dist/src/reporter/handlers.js +180 -0
- package/dist/src/reporter/index.d.ts +44 -0
- package/dist/src/reporter/index.js +167 -0
- package/dist/src/reporter/query-router.d.ts +21 -0
- package/dist/src/reporter/query-router.js +32 -0
- package/dist/src/router/__tests__/step-router.test.js +3 -3
- package/dist/src/router/classifier/regex.js +49 -2
- package/dist/src/router/classifier/regex.test.js +3 -1
- package/dist/src/router/decide.d.ts +18 -0
- package/dist/src/router/decide.js +39 -7
- package/dist/src/router/decide.test.js +58 -8
- package/dist/src/router/role-override.test.d.ts +1 -0
- package/dist/src/router/role-override.test.js +26 -0
- package/dist/src/router/step-router.js +1 -1
- package/dist/src/router/warm.d.ts +2 -0
- package/dist/src/router/warm.js +42 -12
- package/dist/src/router/warm.test.js +59 -1
- package/dist/src/scaffold/__tests__/init-new.spec.js +3 -3
- package/dist/src/scaffold/bb-ecosystem-apply.js +51 -49
- package/dist/src/scaffold/bb-quality-gate.js +5 -5
- package/dist/src/scaffold/continuation-prompt.js +60 -60
- package/dist/src/scaffold/init-new.js +454 -454
- package/dist/src/self-qa/__tests__/agentic-context.test.d.ts +1 -0
- package/dist/src/self-qa/__tests__/agentic-context.test.js +98 -0
- package/dist/src/self-qa/__tests__/agentic-loop.test.d.ts +1 -0
- package/dist/src/self-qa/__tests__/agentic-loop.test.js +62 -0
- package/dist/src/self-qa/__tests__/delta-encoder.test.d.ts +1 -0
- package/dist/src/self-qa/__tests__/delta-encoder.test.js +97 -0
- package/dist/src/self-qa/__tests__/judge.test.d.ts +1 -0
- package/dist/src/self-qa/__tests__/judge.test.js +131 -0
- package/dist/src/self-qa/__tests__/scenario-planner.test.d.ts +1 -0
- package/dist/src/self-qa/__tests__/scenario-planner.test.js +79 -0
- package/dist/src/self-qa/__tests__/spec-emitter.test.d.ts +1 -0
- package/dist/src/self-qa/__tests__/spec-emitter.test.js +62 -0
- package/dist/src/self-qa/agentic-context.d.ts +29 -0
- package/dist/src/self-qa/agentic-context.js +189 -0
- package/dist/src/self-qa/agentic-loop.d.ts +96 -0
- package/dist/src/self-qa/agentic-loop.js +516 -0
- package/dist/src/self-qa/delta-encoder.d.ts +35 -0
- package/dist/src/self-qa/delta-encoder.js +138 -0
- package/dist/src/self-qa/index.d.ts +43 -0
- package/dist/src/self-qa/index.js +65 -0
- package/dist/src/self-qa/judge.d.ts +25 -0
- package/dist/src/self-qa/judge.js +233 -0
- package/dist/src/self-qa/orchestrator.d.ts +31 -0
- package/dist/src/self-qa/orchestrator.js +236 -0
- package/dist/src/self-qa/scenario-planner.d.ts +39 -0
- package/dist/src/self-qa/scenario-planner.js +262 -0
- package/dist/src/self-qa/spec-emitter.d.ts +25 -0
- package/dist/src/self-qa/spec-emitter.js +138 -0
- package/dist/src/self-qa/types.d.ts +113 -0
- package/dist/src/self-qa/types.js +11 -0
- package/dist/src/storage/__tests__/migrations.test.js +2 -2
- package/dist/src/storage/__tests__/sweep-stale-pending.test.d.ts +10 -0
- package/dist/src/storage/__tests__/sweep-stale-pending.test.js +97 -0
- package/dist/src/storage/__tests__/ui-interaction-log.test.js +30 -0
- package/dist/src/storage/atomic-io.test.js +2 -2
- package/dist/src/storage/config.test.js +1 -1
- package/dist/src/storage/interaction-log.d.ts +1 -1
- package/dist/src/storage/interaction-log.js +5 -5
- package/dist/src/storage/migrations.js +122 -122
- package/dist/src/storage/sessions.js +57 -42
- package/dist/src/storage/transcript-response-entry.test.d.ts +1 -0
- package/dist/src/storage/transcript-response-entry.test.js +98 -0
- package/dist/src/storage/transcript.d.ts +22 -0
- package/dist/src/storage/transcript.js +149 -74
- package/dist/src/storage/ui-interaction-log.d.ts +11 -1
- package/dist/src/storage/usage-cap.test.js +1 -1
- package/dist/src/storage/usage.js +14 -14
- package/dist/src/storage/workspaces.js +12 -12
- package/dist/src/tools/__tests__/vision-gate.test.d.ts +1 -0
- package/dist/src/tools/__tests__/vision-gate.test.js +56 -0
- package/dist/src/tools/bash-output-cache.d.ts +59 -0
- package/dist/src/tools/bash-output-cache.js +108 -0
- package/dist/src/tools/bash-output-cache.test.d.ts +1 -0
- package/dist/src/tools/bash-output-cache.test.js +89 -0
- package/dist/src/tools/bash-output-integration.test.d.ts +10 -0
- package/dist/src/tools/bash-output-integration.test.js +30 -0
- package/dist/src/tools/bash.d.ts +12 -0
- package/dist/src/tools/bash.js +114 -21
- package/dist/src/tools/bash.test.js +80 -3
- package/dist/src/tools/computer.test.js +1 -1
- package/dist/src/tools/file-tracker.test.js +1 -1
- package/dist/src/tools/file.js +23 -2
- package/dist/src/tools/file.test.js +49 -1
- package/dist/src/tools/registry-bash-empty-command.test.d.ts +13 -0
- package/dist/src/tools/registry-bash-empty-command.test.js +56 -0
- package/dist/src/tools/registry-bash-footer.test.d.ts +7 -0
- package/dist/src/tools/registry-bash-footer.test.js +82 -0
- package/dist/src/tools/registry-ee-query.test.d.ts +11 -0
- package/dist/src/tools/registry-ee-query.test.js +48 -0
- package/dist/src/tools/registry-session-repeat.test.d.ts +12 -0
- package/dist/src/tools/registry-session-repeat.test.js +87 -0
- package/dist/src/tools/registry.d.ts +38 -0
- package/dist/src/tools/registry.js +262 -4
- package/dist/src/tools/schedule.test.js +1 -1
- package/dist/src/tools/todo-write-snapshot.d.ts +18 -0
- package/dist/src/tools/todo-write-snapshot.js +66 -0
- package/dist/src/tools/todo-write-snapshot.test.d.ts +1 -0
- package/dist/src/tools/todo-write-snapshot.test.js +43 -0
- package/dist/src/tools/vision-gate.d.ts +41 -0
- package/dist/src/tools/vision-gate.js +67 -0
- package/dist/src/types/index.d.ts +65 -4
- package/dist/src/ui/__tests__/picker-providers.test.d.ts +1 -0
- package/dist/src/ui/__tests__/picker-providers.test.js +31 -0
- package/dist/src/ui/agents-modal.js +2 -0
- package/dist/src/ui/app.d.ts +1 -0
- package/dist/src/ui/app.js +0 -0
- package/dist/src/ui/components/__tests__/task-list-panel.test.d.ts +1 -0
- package/dist/src/ui/components/__tests__/task-list-panel.test.js +31 -0
- package/dist/src/ui/components/council-info-card.d.ts +1 -2
- package/dist/src/ui/components/council-leader-bubble.d.ts +1 -2
- package/dist/src/ui/components/council-message-bubble.d.ts +1 -2
- package/dist/src/ui/components/council-phase-timeline.js +20 -1
- package/dist/src/ui/components/council-placeholder-bubble.d.ts +1 -2
- package/dist/src/ui/components/council-question-card.js +3 -0
- package/dist/src/ui/components/council-synthesis-banner.d.ts +1 -2
- package/dist/src/ui/components/halt-recovery-card.js +1 -0
- package/dist/src/ui/components/message-view.d.ts +11 -1
- package/dist/src/ui/components/message-view.js +65 -3
- package/dist/src/ui/components/point-to-existing-form-card.js +5 -1
- package/dist/src/ui/components/task-list-panel.d.ts +32 -0
- package/dist/src/ui/components/task-list-panel.js +84 -0
- package/dist/src/ui/components/tool-group.d.ts +22 -0
- package/dist/src/ui/components/tool-group.js +85 -0
- package/dist/src/ui/hooks/use-agent-editor.js +2 -3
- package/dist/src/ui/hooks/use-model-picker.d.ts +2 -2
- package/dist/src/ui/modals/model-picker-modal.d.ts +2 -0
- package/dist/src/ui/modals/model-picker-modal.js +2 -4
- package/dist/src/ui/picker-providers.d.ts +21 -0
- package/dist/src/ui/picker-providers.js +39 -0
- package/dist/src/ui/slash/__tests__/clear.test.js +1 -1
- package/dist/src/ui/slash/__tests__/compact.test.js +1 -1
- package/dist/src/ui/slash/__tests__/discuss.test.js +1 -1
- package/dist/src/ui/slash/__tests__/execute.test.js +1 -1
- package/dist/src/ui/slash/__tests__/expand.test.js +1 -1
- package/dist/src/ui/slash/__tests__/ideal.test.js +41 -0
- package/dist/src/ui/slash/__tests__/menu-parity.test.d.ts +1 -0
- package/dist/src/ui/slash/__tests__/menu-parity.test.js +1 -0
- package/dist/src/ui/slash/__tests__/plan.test.js +4 -1
- package/dist/src/ui/slash/__tests__/status-render.test.d.ts +7 -0
- package/dist/src/ui/slash/__tests__/status-render.test.js +77 -0
- package/dist/src/ui/slash/council-inspect.js +4 -4
- package/dist/src/ui/slash/export.js +32 -5
- package/dist/src/ui/slash/ideal.d.ts +9 -0
- package/dist/src/ui/slash/ideal.js +27 -1
- package/dist/src/ui/slash/menu-items.js +1 -0
- package/dist/src/ui/slash/status.d.ts +12 -0
- package/dist/src/ui/slash/status.js +32 -0
- package/dist/src/ui/state/active-run.d.ts +26 -0
- package/dist/src/ui/state/active-run.js +44 -0
- package/dist/src/ui/status-bar/index.d.ts +6 -1
- package/dist/src/ui/status-bar/index.js +21 -2
- package/dist/src/ui/status-bar/index.test.js +60 -1
- package/dist/src/ui/status-bar/store.d.ts +16 -0
- package/dist/src/ui/status-bar/store.js +120 -1
- package/dist/src/ui/utils/__tests__/format.test.d.ts +1 -0
- package/dist/src/ui/utils/__tests__/format.test.js +50 -0
- package/dist/src/ui/utils/__tests__/tools.test.d.ts +1 -0
- package/dist/src/ui/utils/__tests__/tools.test.js +48 -0
- package/dist/src/ui/utils/format.d.ts +17 -0
- package/dist/src/ui/utils/format.js +45 -2
- package/dist/src/ui/utils/text.js +2 -1
- package/dist/src/ui/utils/tools.d.ts +2 -0
- package/dist/src/ui/utils/tools.js +58 -9
- package/dist/src/usage/__tests__/product-ledger.test.js +5 -4
- package/dist/src/usage/decision-log.d.ts +1 -1
- package/dist/src/usage/downgrade.d.ts +3 -2
- package/dist/src/usage/downgrade.js +25 -9
- package/dist/src/usage/downgrade.test.js +40 -37
- package/dist/src/usage/product-ledger.d.ts +4 -0
- package/dist/src/usage/product-ledger.js +8 -1
- package/dist/src/utils/__tests__/llm-deadline.test.d.ts +1 -0
- package/dist/src/utils/__tests__/llm-deadline.test.js +56 -0
- package/dist/src/utils/__tests__/settings-disabled-models.test.js +1 -1
- package/dist/src/utils/__tests__/settings-web-research.test.js +1 -1
- package/dist/src/utils/__tests__/visible-retry.test.js +1 -1
- package/dist/src/utils/clipboard-image.js +23 -23
- package/dist/src/utils/install-manager.test.js +1 -1
- package/dist/src/utils/llm-deadline.d.ts +44 -0
- package/dist/src/utils/llm-deadline.js +80 -0
- package/dist/src/utils/permission-mode.d.ts +16 -9
- package/dist/src/utils/permission-mode.js +55 -4
- package/dist/src/utils/settings.d.ts +22 -0
- package/dist/src/utils/settings.js +47 -6
- package/dist/src/utils/shell.d.ts +12 -0
- package/dist/src/utils/shell.js +23 -12
- package/dist/src/utils/shell.test.js +27 -1
- package/dist/src/utils/side-question.js +2 -2
- package/dist/src/utils/skills.js +3 -3
- package/dist/src/utils/skills.test.js +1 -1
- package/dist/src/utils/subagents-settings.test.js +9 -3
- package/dist/src/verify/__tests__/coverage-parsers.test.js +30 -30
- package/dist/src/verify/__tests__/dotnet-recipe.test.js +1 -1
- package/dist/src/verify/checkpoint.test.js +1 -1
- package/dist/src/verify/entrypoint.d.ts +8 -8
- package/dist/src/verify/entrypoint.js +69 -32
- package/dist/src/verify/entrypoint.test.js +1 -1
- package/dist/src/verify/environment.test.js +1 -1
- package/dist/src/verify/orchestrator.test.js +1 -1
- package/dist/src/verify/runtime-prep.test.js +1 -1
- package/package.json +125 -122
- package/scripts/postinstall.cjs +76 -73
- package/dist/packages/agent-harness-core/src/driver.js.map +0 -1
- package/dist/packages/agent-harness-core/src/event-filter.js.map +0 -1
- package/dist/packages/agent-harness-core/src/event-redact.js.map +0 -1
- package/dist/packages/agent-harness-core/src/idle.js.map +0 -1
- package/dist/packages/agent-harness-core/src/index.js.map +0 -1
- package/dist/packages/agent-harness-core/src/mcp-server.js.map +0 -1
- package/dist/packages/agent-harness-core/src/mock-llm.js.map +0 -1
- package/dist/packages/agent-harness-core/src/predicate.js.map +0 -1
- package/dist/packages/agent-harness-core/src/protocol.js.map +0 -1
- package/dist/packages/agent-harness-core/src/registry.js.map +0 -1
- package/dist/packages/agent-harness-core/src/selector.js.map +0 -1
- package/dist/packages/agent-harness-core/src/spec-helpers.js.map +0 -1
- package/dist/packages/agent-harness-core/src/transports/sidechannel.js.map +0 -1
- package/dist/packages/agent-harness-core/src/transports/ws.js.map +0 -1
- package/dist/packages/agent-harness-opentui/src/agent-mode.js.map +0 -1
- package/dist/packages/agent-harness-opentui/src/index.js.map +0 -1
- package/dist/packages/agent-harness-opentui/src/input-bridge.js.map +0 -1
- package/dist/packages/agent-harness-opentui/src/install.js.map +0 -1
- package/dist/packages/agent-harness-opentui/src/reconciler-hook.js.map +0 -1
- package/dist/packages/agent-harness-opentui/src/semantic.js.map +0 -1
- package/dist/src/__test-stubs__/ee-server.js.map +0 -1
- package/dist/src/__test-stubs__/vitest-setup.js.map +0 -1
- package/dist/src/__tests__/council/bubble-layout.test.js.map +0 -1
- package/dist/src/__tests__/council/code-block-truncate.test.js.map +0 -1
- package/dist/src/__tests__/council/role-palette.test.js.map +0 -1
- package/dist/src/__tests__/first-run-wizard.test.js.map +0 -1
- package/dist/src/agent-harness/__tests__/cli-flags.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/driver.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/idle.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/mock-llm.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/mock-model.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/predicate.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/protocol.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/schema.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/selector.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/sidechannel.spec.js.map +0 -1
- package/dist/src/agent-harness/__tests__/spec-helpers.spec.js.map +0 -1
- package/dist/src/agent-harness/index.js.map +0 -1
- package/dist/src/agent-harness/mock-model.js.map +0 -1
- package/dist/src/agent-harness/test-spawn.js.map +0 -1
- package/dist/src/billing/index.js.map +0 -1
- package/dist/src/chat/__tests__/broadcast-bus.test.js.map +0 -1
- package/dist/src/chat/__tests__/channel-manager.test.js.map +0 -1
- package/dist/src/chat/__tests__/client.test.js.map +0 -1
- package/dist/src/chat/__tests__/discord-integration.test.js.map +0 -1
- package/dist/src/chat/__tests__/intent-prompt.test.js.map +0 -1
- package/dist/src/chat/__tests__/verdict-resolver.test.js.map +0 -1
- package/dist/src/chat/broadcast-bus.js.map +0 -1
- package/dist/src/chat/channel-manager.js.map +0 -1
- package/dist/src/chat/chat-keychain.js.map +0 -1
- package/dist/src/chat/factory.js.map +0 -1
- package/dist/src/chat/intent-prompt.js.map +0 -1
- package/dist/src/chat/providers/discord/client.js.map +0 -1
- package/dist/src/chat/types.js.map +0 -1
- package/dist/src/chat/verdict-constants.js.map +0 -1
- package/dist/src/chat/verdict-resolver.js.map +0 -1
- package/dist/src/cli/__tests__/bw-vault.test.js.map +0 -1
- package/dist/src/cli/__tests__/keys-bundle.test.js.map +0 -1
- package/dist/src/cli/__tests__/share-cmd.test.js.map +0 -1
- package/dist/src/cli/bw-vault.js.map +0 -1
- package/dist/src/cli/config/__tests__/model-picker.test.js.map +0 -1
- package/dist/src/cli/config/__tests__/provider-fetch.test.js.map +0 -1
- package/dist/src/cli/config/index.js.map +0 -1
- package/dist/src/cli/config/model-picker.js.map +0 -1
- package/dist/src/cli/config/provider-fetch.js.map +0 -1
- package/dist/src/cli/config/screen-council.js.map +0 -1
- package/dist/src/cli/config/screen-models.js.map +0 -1
- package/dist/src/cli/config/screen-providers.js.map +0 -1
- package/dist/src/cli/config/tui.js.map +0 -1
- package/dist/src/cli/cost-forensics.js.map +0 -1
- package/dist/src/cli/cost-forensics.test.js.map +0 -1
- package/dist/src/cli/keys-bundle.js.map +0 -1
- package/dist/src/cli/keys.js.map +0 -1
- package/dist/src/cli/keys.test.js.map +0 -1
- package/dist/src/cli/pil-report.js.map +0 -1
- package/dist/src/cli/share-cmd.js.map +0 -1
- package/dist/src/cli/usage-report.js.map +0 -1
- package/dist/src/cloud/index.js.map +0 -1
- package/dist/src/council/__tests__/accounting.test.js.map +0 -1
- package/dist/src/council/__tests__/audit-replay.test.js.map +0 -1
- package/dist/src/council/__tests__/clarifier-max-rounds.test.js.map +0 -1
- package/dist/src/council/__tests__/clarifier-options.test.js.map +0 -1
- package/dist/src/council/__tests__/cost-aware.test.js.map +0 -1
- package/dist/src/council/__tests__/debate-planner-structured.test.js.map +0 -1
- package/dist/src/council/__tests__/evaluator-metrics.test.js.map +0 -1
- package/dist/src/council/__tests__/parse-outcome-fallback.test.js.map +0 -1
- package/dist/src/council/__tests__/research-tools.test.js.map +0 -1
- package/dist/src/council/__tests__/round-tools.test.js.map +0 -1
- package/dist/src/council/__tests__/tool-trace.test.js.map +0 -1
- package/dist/src/council/__tests__/types-contract.test.js.map +0 -1
- package/dist/src/council/clarifier.js.map +0 -1
- package/dist/src/council/context.js.map +0 -1
- package/dist/src/council/debate-planner.js.map +0 -1
- package/dist/src/council/debate.js.map +0 -1
- package/dist/src/council/executor.js.map +0 -1
- package/dist/src/council/index.js.map +0 -1
- package/dist/src/council/leader.js.map +0 -1
- package/dist/src/council/llm.js.map +0 -1
- package/dist/src/council/phase-events.js.map +0 -1
- package/dist/src/council/planner.js.map +0 -1
- package/dist/src/council/preflight.js.map +0 -1
- package/dist/src/council/prompts.js.map +0 -1
- package/dist/src/council/types.js.map +0 -1
- package/dist/src/daemon/scheduler.js.map +0 -1
- package/dist/src/daemon/scheduler.test.js.map +0 -1
- package/dist/src/ee/__tests__/bb-design.test.js.map +0 -1
- package/dist/src/ee/__tests__/pil-context-bridge.test.js.map +0 -1
- package/dist/src/ee/__tests__/pipeline.integration.test.js.map +0 -1
- package/dist/src/ee/__tests__/render-sink-wiring.test.js.map +0 -1
- package/dist/src/ee/auth.js.map +0 -1
- package/dist/src/ee/auth.test.js.map +0 -1
- package/dist/src/ee/bb-design.js.map +0 -1
- package/dist/src/ee/bb-retrieval.js.map +0 -1
- package/dist/src/ee/bridge.js.map +0 -1
- package/dist/src/ee/bridge.test.js.map +0 -1
- package/dist/src/ee/client-mode.js.map +0 -1
- package/dist/src/ee/client.js.map +0 -1
- package/dist/src/ee/client.test.js.map +0 -1
- package/dist/src/ee/council-bridge.js.map +0 -1
- package/dist/src/ee/embedding-cache.js.map +0 -1
- package/dist/src/ee/extract-session.js.map +0 -1
- package/dist/src/ee/extract-session.test.js.map +0 -1
- package/dist/src/ee/health.js.map +0 -1
- package/dist/src/ee/index.js.map +0 -1
- package/dist/src/ee/intercept.js.map +0 -1
- package/dist/src/ee/intercept.test.js.map +0 -1
- package/dist/src/ee/judge.js.map +0 -1
- package/dist/src/ee/judge.test.js.map +0 -1
- package/dist/src/ee/mistake-detector.js.map +0 -1
- package/dist/src/ee/mistake-detector.test.js.map +0 -1
- package/dist/src/ee/offline-queue.js.map +0 -1
- package/dist/src/ee/offline-queue.test.js.map +0 -1
- package/dist/src/ee/phase-outcome.js.map +0 -1
- package/dist/src/ee/phase-outcome.test.js.map +0 -1
- package/dist/src/ee/phase-tracker.js.map +0 -1
- package/dist/src/ee/phase-tracker.test.js.map +0 -1
- package/dist/src/ee/posttool.js.map +0 -1
- package/dist/src/ee/posttool.test.js.map +0 -1
- package/dist/src/ee/prompt-stale.js.map +0 -1
- package/dist/src/ee/prompt-stale.test.js.map +0 -1
- package/dist/src/ee/render.js.map +0 -1
- package/dist/src/ee/render.test.js.map +0 -1
- package/dist/src/ee/scope.js.map +0 -1
- package/dist/src/ee/scope.test.js.map +0 -1
- package/dist/src/ee/session-trajectory.js.map +0 -1
- package/dist/src/ee/session-trajectory.test.js.map +0 -1
- package/dist/src/ee/tenant.js.map +0 -1
- package/dist/src/ee/touch.test.js.map +0 -1
- package/dist/src/ee/types.js.map +0 -1
- package/dist/src/flow/__tests__/migration.test.js.map +0 -1
- package/dist/src/flow/__tests__/parser.test.js.map +0 -1
- package/dist/src/flow/__tests__/run-manager-product.test.js.map +0 -1
- package/dist/src/flow/__tests__/run-manager.test.js.map +0 -1
- package/dist/src/flow/__tests__/scaffold-checkpoint.test.js.map +0 -1
- package/dist/src/flow/__tests__/scaffold.test.js.map +0 -1
- package/dist/src/flow/__tests__/warning-persist.test.js.map +0 -1
- package/dist/src/flow/artifact-io.js.map +0 -1
- package/dist/src/flow/compaction/__tests__/compress.test.js.map +0 -1
- package/dist/src/flow/compaction/__tests__/extract.test.js.map +0 -1
- package/dist/src/flow/compaction/__tests__/preserve.test.js.map +0 -1
- package/dist/src/flow/compaction/compress.js.map +0 -1
- package/dist/src/flow/compaction/extract.js.map +0 -1
- package/dist/src/flow/compaction/index.js.map +0 -1
- package/dist/src/flow/compaction/preserve.js.map +0 -1
- package/dist/src/flow/index.js.map +0 -1
- package/dist/src/flow/migration.js.map +0 -1
- package/dist/src/flow/parser.js.map +0 -1
- package/dist/src/flow/run-manager.js.map +0 -1
- package/dist/src/flow/scaffold-checkpoint.js.map +0 -1
- package/dist/src/flow/scaffold.js.map +0 -1
- package/dist/src/flow/warning-persist.js.map +0 -1
- package/dist/src/generated/version.js.map +0 -1
- package/dist/src/gsd/__tests__/complexity.test.js.map +0 -1
- package/dist/src/gsd/__tests__/directives.test.js.map +0 -1
- package/dist/src/gsd/__tests__/gray-areas.test.js.map +0 -1
- package/dist/src/gsd/__tests__/types.test.js.map +0 -1
- package/dist/src/gsd/complexity.js.map +0 -1
- package/dist/src/gsd/directives.js.map +0 -1
- package/dist/src/gsd/gray-areas.js.map +0 -1
- package/dist/src/gsd/index.js.map +0 -1
- package/dist/src/gsd/types.js.map +0 -1
- package/dist/src/headless/__tests__/council-answers.test.js.map +0 -1
- package/dist/src/headless/council-answers.js.map +0 -1
- package/dist/src/headless/output.js.map +0 -1
- package/dist/src/headless/output.test.js.map +0 -1
- package/dist/src/hooks/config.js.map +0 -1
- package/dist/src/hooks/index.js.map +0 -1
- package/dist/src/hooks/types.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/lsp/builtins.js.map +0 -1
- package/dist/src/lsp/builtins.test.js.map +0 -1
- package/dist/src/lsp/client.js.map +0 -1
- package/dist/src/lsp/manager.js.map +0 -1
- package/dist/src/lsp/manager.test.js.map +0 -1
- package/dist/src/lsp/npm-cache.js.map +0 -1
- package/dist/src/lsp/npm-cache.test.js.map +0 -1
- package/dist/src/lsp/runtime.js.map +0 -1
- package/dist/src/lsp/smoke.test.js.map +0 -1
- package/dist/src/lsp/types.js.map +0 -1
- package/dist/src/mcp/__tests__/auto-setup.test.js.map +0 -1
- package/dist/src/mcp/__tests__/harness-driver-action-tools.spec.js.map +0 -1
- package/dist/src/mcp/__tests__/harness-driver-async-tools.spec.js.map +0 -1
- package/dist/src/mcp/__tests__/harness-driver-read-tools.spec.js.map +0 -1
- package/dist/src/mcp/__tests__/harness-driver-security.spec.js.map +0 -1
- package/dist/src/mcp/__tests__/harness-driver.spec.js.map +0 -1
- package/dist/src/mcp/__tests__/lazy-schema.spec.js.map +0 -1
- package/dist/src/mcp/__tests__/mcp-keychain.test.js.map +0 -1
- package/dist/src/mcp/__tests__/research-onboarding.test.js.map +0 -1
- package/dist/src/mcp/__tests__/runtime-hydration.test.js.map +0 -1
- package/dist/src/mcp/__tests__/runtime-sanitize.test.js.map +0 -1
- package/dist/src/mcp/auto-setup.js.map +0 -1
- package/dist/src/mcp/catalog.js.map +0 -1
- package/dist/src/mcp/mcp-keychain.js.map +0 -1
- package/dist/src/mcp/oauth-callback.js.map +0 -1
- package/dist/src/mcp/oauth-provider.js.map +0 -1
- package/dist/src/mcp/opentui-spawn.js.map +0 -1
- package/dist/src/mcp/parse-headers.js.map +0 -1
- package/dist/src/mcp/parse-headers.test.js.map +0 -1
- package/dist/src/mcp/research-onboarding.js.map +0 -1
- package/dist/src/mcp/runtime.js.map +0 -1
- package/dist/src/mcp/smoke.test.js.map +0 -1
- package/dist/src/mcp/validate.js.map +0 -1
- package/dist/src/models/__tests__/registry.test.js.map +0 -1
- package/dist/src/models/catalog-client.js.map +0 -1
- package/dist/src/models/classify-tier.js.map +0 -1
- package/dist/src/models/index.js.map +0 -1
- package/dist/src/models/registry.js.map +0 -1
- package/dist/src/ops/__tests__/doctor-council-mcp.test.js.map +0 -1
- package/dist/src/ops/__tests__/doctor-ee-health.test.js.map +0 -1
- package/dist/src/ops/bug-report.js.map +0 -1
- package/dist/src/ops/bug-report.test.js.map +0 -1
- package/dist/src/ops/doctor.js.map +0 -1
- package/dist/src/ops/doctor.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/batch-turn-runner.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/council-manager.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/cross-turn-dedup.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/current-call-id.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/flow-resume.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/message-processor.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/message-write-ahead.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/read-path-budget.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/retry-classifier.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/retry-stream.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/route-feedback.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/stream-runner.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/usage-events-shape.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/usage-normalizer-c1.test.js.map +0 -1
- package/dist/src/orchestrator/__tests__/write-ahead.test.js.map +0 -1
- package/dist/src/orchestrator/abort.js.map +0 -1
- package/dist/src/orchestrator/abort.test.js.map +0 -1
- package/dist/src/orchestrator/agent-options.js.map +0 -1
- package/dist/src/orchestrator/agent.test.js.map +0 -1
- package/dist/src/orchestrator/batch-turn-runner.js.map +0 -1
- package/dist/src/orchestrator/batch-utils.js.map +0 -1
- package/dist/src/orchestrator/cleanup.test.js.map +0 -1
- package/dist/src/orchestrator/compaction.js.map +0 -1
- package/dist/src/orchestrator/compaction.test.js.map +0 -1
- package/dist/src/orchestrator/council-manager.js.map +0 -1
- package/dist/src/orchestrator/cross-turn-dedup.js.map +0 -1
- package/dist/src/orchestrator/delegations.js.map +0 -1
- package/dist/src/orchestrator/delegations.test.js.map +0 -1
- package/dist/src/orchestrator/error-utils.js.map +0 -1
- package/dist/src/orchestrator/flow-resume.js.map +0 -1
- package/dist/src/orchestrator/message-processor.js.map +0 -1
- package/dist/src/orchestrator/message-seq.js.map +0 -1
- package/dist/src/orchestrator/message-seq.test.js.map +0 -1
- package/dist/src/orchestrator/orchestrator.js.map +0 -1
- package/dist/src/orchestrator/pending-calls.js.map +0 -1
- package/dist/src/orchestrator/pending-calls.test.js.map +0 -1
- package/dist/src/orchestrator/prompts.js.map +0 -1
- package/dist/src/orchestrator/provider-options-shape.js.map +0 -1
- package/dist/src/orchestrator/provider-options-shape.spec.js.map +0 -1
- package/dist/src/orchestrator/read-path-budget.js.map +0 -1
- package/dist/src/orchestrator/reasoning.js.map +0 -1
- package/dist/src/orchestrator/reasoning.test.js.map +0 -1
- package/dist/src/orchestrator/retry-classifier.js.map +0 -1
- package/dist/src/orchestrator/retry-stream.js.map +0 -1
- package/dist/src/orchestrator/sandbox.test.js.map +0 -1
- package/dist/src/orchestrator/stream-runner.js.map +0 -1
- package/dist/src/orchestrator/sub-agent-cap.js.map +0 -1
- package/dist/src/orchestrator/sub-agent-cap.test.js.map +0 -1
- package/dist/src/orchestrator/subagent-compactor.js.map +0 -1
- package/dist/src/orchestrator/subagent-compactor.spec.js.map +0 -1
- package/dist/src/orchestrator/token-counter.js.map +0 -1
- package/dist/src/orchestrator/token-counter.test.js.map +0 -1
- package/dist/src/orchestrator/tool-utils.js.map +0 -1
- package/dist/src/orchestrator/turn-runner-deps.js.map +0 -1
- package/dist/src/pil/__tests__/budget.test.js.map +0 -1
- package/dist/src/pil/__tests__/config.test.js.map +0 -1
- package/dist/src/pil/__tests__/dual-run.test.js.map +0 -1
- package/dist/src/pil/__tests__/layer1-intent-trace.test.js.map +0 -1
- package/dist/src/pil/__tests__/layer1-intent.test.js.map +0 -1
- package/dist/src/pil/__tests__/layer2-personality.test.js.map +0 -1
- package/dist/src/pil/__tests__/layer3-ee-injection.test.js.map +0 -1
- package/dist/src/pil/__tests__/layer3-injected-chunk.test.js.map +0 -1
- package/dist/src/pil/__tests__/layer4-gsd.test.js.map +0 -1
- package/dist/src/pil/__tests__/layer5-context.test.js.map +0 -1
- package/dist/src/pil/__tests__/layer6-output.test.js.map +0 -1
- package/dist/src/pil/__tests__/ollama-classify.test.js.map +0 -1
- package/dist/src/pil/__tests__/orchestrator-integration.test.js.map +0 -1
- package/dist/src/pil/__tests__/pipeline.test.js.map +0 -1
- package/dist/src/pil/__tests__/renderer-coverage.test.js.map +0 -1
- package/dist/src/pil/__tests__/response-tools.test.js.map +0 -1
- package/dist/src/pil/__tests__/schema.test.js.map +0 -1
- package/dist/src/pil/__tests__/scoreComplexity.test.js.map +0 -1
- package/dist/src/pil/__tests__/scoreSufficiency.test.js.map +0 -1
- package/dist/src/pil/__tests__/store.test.js.map +0 -1
- package/dist/src/pil/__tests__/task-tier-map.test.js.map +0 -1
- package/dist/src/pil/budget-log.js.map +0 -1
- package/dist/src/pil/budget.js.map +0 -1
- package/dist/src/pil/config.js.map +0 -1
- package/dist/src/pil/index.js.map +0 -1
- package/dist/src/pil/layer1-intent.js.map +0 -1
- package/dist/src/pil/layer1-intent.test.js.map +0 -1
- package/dist/src/pil/layer2-personality.js.map +0 -1
- package/dist/src/pil/layer3-ee-injection.js.map +0 -1
- package/dist/src/pil/layer4-gsd.js.map +0 -1
- package/dist/src/pil/layer5-context.js.map +0 -1
- package/dist/src/pil/layer6-output.js.map +0 -1
- package/dist/src/pil/ollama-classify.js.map +0 -1
- package/dist/src/pil/pipeline.js.map +0 -1
- package/dist/src/pil/response-tools.js.map +0 -1
- package/dist/src/pil/schema.js.map +0 -1
- package/dist/src/pil/store.js.map +0 -1
- package/dist/src/pil/task-tier-map.js.map +0 -1
- package/dist/src/pil/timeout.js.map +0 -1
- package/dist/src/pil/types.js.map +0 -1
- package/dist/src/product-loop/__tests__/artifact-io.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/assumption-ledger.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/cb2-retry-bonus.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/circuit-breakers-coverage.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/circuit-breakers.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/complexity-routing.spec.js.map +0 -1
- package/dist/src/product-loop/__tests__/context-policy.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/cost-preview.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/cost-scoper.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/cross-run-memory.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/design-output.spec.js.map +0 -1
- package/dist/src/product-loop/__tests__/discover.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-council-runner.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-detection.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-ecosystem.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-integration.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-interview.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-migrations.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-persistence.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-prompt-parser.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-recommender-ecosystem.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-recommender.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/discovery-schema.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/done-gate-coverage.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/done-gate.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/ee-extract-wiring.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/extract-to-ee.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/feedback-routing.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/hot-path.spec.js.map +0 -1
- package/dist/src/product-loop/__tests__/integration.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/loop-driver-audit.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/loop-driver.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/phase-budget.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/phase-orchestrator-integration.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/phase-plan.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/phase-rituals.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/phase-runner.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/phase-tracker-bridge.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/product-identity.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/reality-anchor.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/repo-audit.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/role-memory.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/role-registry.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/role-routing-ee.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/route-decision-emit.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/seed-questions.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/ship-polish.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/sprint-runner-emit.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/sprint-runner.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/stakeholder-acl.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/state-md-ee-injections.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/sufficiency-routing.spec.js.map +0 -1
- package/dist/src/product-loop/__tests__/typed-artifacts.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/types.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/verify-failure-threshold.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/verify-failure-tracking.test.js.map +0 -1
- package/dist/src/product-loop/__tests__/verify-result.test.js.map +0 -1
- package/dist/src/product-loop/artifact-io.js.map +0 -1
- package/dist/src/product-loop/assumption-ledger.js.map +0 -1
- package/dist/src/product-loop/circuit-breakers.js.map +0 -1
- package/dist/src/product-loop/context-policy.js.map +0 -1
- package/dist/src/product-loop/cost-preview.js.map +0 -1
- package/dist/src/product-loop/cost-scoper.js.map +0 -1
- package/dist/src/product-loop/cross-run-memory.js.map +0 -1
- package/dist/src/product-loop/design-output.js.map +0 -1
- package/dist/src/product-loop/discover.js.map +0 -1
- package/dist/src/product-loop/discovery-context-format.js.map +0 -1
- package/dist/src/product-loop/discovery-council-runner.js.map +0 -1
- package/dist/src/product-loop/discovery-detection.js.map +0 -1
- package/dist/src/product-loop/discovery-ecosystem.js.map +0 -1
- package/dist/src/product-loop/discovery-interview.js.map +0 -1
- package/dist/src/product-loop/discovery-migrations.js.map +0 -1
- package/dist/src/product-loop/discovery-persistence.js.map +0 -1
- package/dist/src/product-loop/discovery-prompt-parser.js.map +0 -1
- package/dist/src/product-loop/discovery-recommender.js.map +0 -1
- package/dist/src/product-loop/discovery-schema.js.map +0 -1
- package/dist/src/product-loop/done-gate.js.map +0 -1
- package/dist/src/product-loop/feedback-routing.js.map +0 -1
- package/dist/src/product-loop/gather.js.map +0 -1
- package/dist/src/product-loop/index.js.map +0 -1
- package/dist/src/product-loop/loop-driver.js.map +0 -1
- package/dist/src/product-loop/phase-budget.js.map +0 -1
- package/dist/src/product-loop/phase-plan.js.map +0 -1
- package/dist/src/product-loop/phase-rituals.js.map +0 -1
- package/dist/src/product-loop/phase-runner.js.map +0 -1
- package/dist/src/product-loop/phase-tracker-bridge.js.map +0 -1
- package/dist/src/product-loop/product-identity.js.map +0 -1
- package/dist/src/product-loop/reality-anchor.js.map +0 -1
- package/dist/src/product-loop/repo-audit.js.map +0 -1
- package/dist/src/product-loop/role-memory.js.map +0 -1
- package/dist/src/product-loop/role-registry.js.map +0 -1
- package/dist/src/product-loop/seed-questions.js.map +0 -1
- package/dist/src/product-loop/ship-polish.js.map +0 -1
- package/dist/src/product-loop/sprint-runner.js.map +0 -1
- package/dist/src/product-loop/stakeholder-acl.js.map +0 -1
- package/dist/src/product-loop/typed-artifacts.js.map +0 -1
- package/dist/src/product-loop/types.js.map +0 -1
- package/dist/src/product-loop/verify-failure-tracking.js.map +0 -1
- package/dist/src/product-loop/verify-result.js.map +0 -1
- package/dist/src/providers/__test-utils__/load-fixture.js.map +0 -1
- package/dist/src/providers/__tests__/adapter-oauth-wiring.test.js.map +0 -1
- package/dist/src/providers/__tests__/capabilities-cosmetic.test.js.map +0 -1
- package/dist/src/providers/__tests__/capabilities-flags.test.js.map +0 -1
- package/dist/src/providers/__tests__/capabilities-provider-options.test.js.map +0 -1
- package/dist/src/providers/__tests__/capabilities-sanitize.test.js.map +0 -1
- package/dist/src/providers/__tests__/capabilities.test.js.map +0 -1
- package/dist/src/providers/__tests__/provider-coverage.test.js.map +0 -1
- package/dist/src/providers/__tests__/runtime-integration.test.js.map +0 -1
- package/dist/src/providers/__tests__/runtime.test.js.map +0 -1
- package/dist/src/providers/__tests__/siliconflow-history.test.js +0 -76
- package/dist/src/providers/__tests__/siliconflow-history.test.js.map +0 -1
- package/dist/src/providers/__tests__/strategies-registry.test.js.map +0 -1
- package/dist/src/providers/__tests__/strategies-resolve.test.js.map +0 -1
- package/dist/src/providers/__tests__/wire-debug.test.js.map +0 -1
- package/dist/src/providers/adapter.js.map +0 -1
- package/dist/src/providers/adapter.test.js.map +0 -1
- package/dist/src/providers/anthropic.js.map +0 -1
- package/dist/src/providers/auth/__tests__/browser-flow.test.js.map +0 -1
- package/dist/src/providers/auth/__tests__/device-flow.test.js.map +0 -1
- package/dist/src/providers/auth/__tests__/gemini-oauth.test.js.map +0 -1
- package/dist/src/providers/auth/__tests__/openai-oauth.test.js.map +0 -1
- package/dist/src/providers/auth/__tests__/token-store.test.js.map +0 -1
- package/dist/src/providers/auth/browser-flow.js.map +0 -1
- package/dist/src/providers/auth/device-flow.js.map +0 -1
- package/dist/src/providers/auth/gemini-oauth.js.map +0 -1
- package/dist/src/providers/auth/openai-oauth.js.map +0 -1
- package/dist/src/providers/auth/registry.js.map +0 -1
- package/dist/src/providers/auth/token-store.js.map +0 -1
- package/dist/src/providers/auth/types.js.map +0 -1
- package/dist/src/providers/capabilities.js.map +0 -1
- package/dist/src/providers/endpoints.js.map +0 -1
- package/dist/src/providers/errors.js.map +0 -1
- package/dist/src/providers/errors.test.js.map +0 -1
- package/dist/src/providers/gemini.js.map +0 -1
- package/dist/src/providers/gemini.test.js.map +0 -1
- package/dist/src/providers/index.js.map +0 -1
- package/dist/src/providers/keychain.js.map +0 -1
- package/dist/src/providers/keychain.test.js.map +0 -1
- package/dist/src/providers/mcp-vision-bridge.js.map +0 -1
- package/dist/src/providers/mcp-vision-bridge.test.js.map +0 -1
- package/dist/src/providers/ollama.js.map +0 -1
- package/dist/src/providers/ollama.test.js.map +0 -1
- package/dist/src/providers/openai-compatible.js.map +0 -1
- package/dist/src/providers/openai-compatible.test.js.map +0 -1
- package/dist/src/providers/openai.js.map +0 -1
- package/dist/src/providers/openai.test.js.map +0 -1
- package/dist/src/providers/patch-zod-schema.js.map +0 -1
- package/dist/src/providers/pricing.js.map +0 -1
- package/dist/src/providers/pricing.test.js.map +0 -1
- package/dist/src/providers/prompt-cache-key.spec.js.map +0 -1
- package/dist/src/providers/runtime-mock.spec.js.map +0 -1
- package/dist/src/providers/runtime.js.map +0 -1
- package/dist/src/providers/siliconflow-history.d.ts +0 -50
- package/dist/src/providers/siliconflow-history.js +0 -64
- package/dist/src/providers/siliconflow-history.js.map +0 -1
- package/dist/src/providers/strategies/anthropic.strategy.js.map +0 -1
- package/dist/src/providers/strategies/base.strategy.js.map +0 -1
- package/dist/src/providers/strategies/deepseek.strategy.js.map +0 -1
- package/dist/src/providers/strategies/google.strategy.js.map +0 -1
- package/dist/src/providers/strategies/ollama.strategy.js.map +0 -1
- package/dist/src/providers/strategies/openai.strategy.js.map +0 -1
- package/dist/src/providers/strategies/registry.js.map +0 -1
- package/dist/src/providers/strategies/siliconflow.strategy.js.map +0 -1
- package/dist/src/providers/strategies/xai.strategy.js.map +0 -1
- package/dist/src/providers/stream-loop.js.map +0 -1
- package/dist/src/providers/types.js.map +0 -1
- package/dist/src/providers/vision-proxy.js.map +0 -1
- package/dist/src/providers/vision-proxy.test.js.map +0 -1
- package/dist/src/providers/wire-debug.js.map +0 -1
- package/dist/src/router/__tests__/step-router.test.js.map +0 -1
- package/dist/src/router/classifier/grammars.js.map +0 -1
- package/dist/src/router/classifier/index.js.map +0 -1
- package/dist/src/router/classifier/index.test.js.map +0 -1
- package/dist/src/router/classifier/regex.js.map +0 -1
- package/dist/src/router/classifier/regex.test.js.map +0 -1
- package/dist/src/router/classifier/tree-sitter.js.map +0 -1
- package/dist/src/router/classifier/tree-sitter.test.js.map +0 -1
- package/dist/src/router/cold.js.map +0 -1
- package/dist/src/router/cold.test.js.map +0 -1
- package/dist/src/router/decide.js.map +0 -1
- package/dist/src/router/decide.test.js.map +0 -1
- package/dist/src/router/health.js.map +0 -1
- package/dist/src/router/health.test.js.map +0 -1
- package/dist/src/router/provider-sentinel.js.map +0 -1
- package/dist/src/router/provider-sentinel.test.js.map +0 -1
- package/dist/src/router/step-router.js.map +0 -1
- package/dist/src/router/store.js.map +0 -1
- package/dist/src/router/types.js.map +0 -1
- package/dist/src/router/warm.js.map +0 -1
- package/dist/src/router/warm.test.js.map +0 -1
- package/dist/src/scaffold/__tests__/continuation-prompt.test.js.map +0 -1
- package/dist/src/scaffold/__tests__/continue-as-council.spec.js.map +0 -1
- package/dist/src/scaffold/__tests__/dotnet-assembly-name.test.js.map +0 -1
- package/dist/src/scaffold/__tests__/fe-scaffold-contents.test.js.map +0 -1
- package/dist/src/scaffold/__tests__/init-new.smoke.spec.js.map +0 -1
- package/dist/src/scaffold/__tests__/init-new.spec.js.map +0 -1
- package/dist/src/scaffold/__tests__/install-bb-templates.spec.js.map +0 -1
- package/dist/src/scaffold/__tests__/point-to-existing.spec.js.map +0 -1
- package/dist/src/scaffold/bb-ecosystem-apply.js.map +0 -1
- package/dist/src/scaffold/bb-quality-gate.js.map +0 -1
- package/dist/src/scaffold/continuation-prompt.js.map +0 -1
- package/dist/src/scaffold/continue-as-council.js.map +0 -1
- package/dist/src/scaffold/init-new.js.map +0 -1
- package/dist/src/scaffold/point-to-existing.js.map +0 -1
- package/dist/src/scaffold/resume-from-gate-failures.js.map +0 -1
- package/dist/src/storage/__tests__/migrations.test.js.map +0 -1
- package/dist/src/storage/__tests__/ui-interaction-log.test.js.map +0 -1
- package/dist/src/storage/atomic-io.js.map +0 -1
- package/dist/src/storage/atomic-io.test.js.map +0 -1
- package/dist/src/storage/config.js.map +0 -1
- package/dist/src/storage/config.test.js.map +0 -1
- package/dist/src/storage/db.js.map +0 -1
- package/dist/src/storage/index.js.map +0 -1
- package/dist/src/storage/interaction-log.js.map +0 -1
- package/dist/src/storage/migrations.js.map +0 -1
- package/dist/src/storage/session-dir.js.map +0 -1
- package/dist/src/storage/sessions.js.map +0 -1
- package/dist/src/storage/tool-results.js.map +0 -1
- package/dist/src/storage/transcript-view.js.map +0 -1
- package/dist/src/storage/transcript.js.map +0 -1
- package/dist/src/storage/transcript.test.js.map +0 -1
- package/dist/src/storage/ui-interaction-log.js.map +0 -1
- package/dist/src/storage/usage-cap.js.map +0 -1
- package/dist/src/storage/usage-cap.test.js.map +0 -1
- package/dist/src/storage/usage.js.map +0 -1
- package/dist/src/storage/workspaces.js.map +0 -1
- package/dist/src/tools/bash.js.map +0 -1
- package/dist/src/tools/bash.test.js.map +0 -1
- package/dist/src/tools/computer.js.map +0 -1
- package/dist/src/tools/computer.test.js.map +0 -1
- package/dist/src/tools/file-tracker.js.map +0 -1
- package/dist/src/tools/file-tracker.test.js.map +0 -1
- package/dist/src/tools/file.js.map +0 -1
- package/dist/src/tools/file.test.js.map +0 -1
- package/dist/src/tools/grep.js.map +0 -1
- package/dist/src/tools/registry.js.map +0 -1
- package/dist/src/tools/registry.test.js.map +0 -1
- package/dist/src/tools/schedule.js.map +0 -1
- package/dist/src/tools/schedule.test.js.map +0 -1
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/ui/agents-modal.js.map +0 -1
- package/dist/src/ui/app.js.map +0 -1
- package/dist/src/ui/cards/__tests__/product-status-card.test.js.map +0 -1
- package/dist/src/ui/cards/product-status-card.js.map +0 -1
- package/dist/src/ui/components/SuggestionOverlay.js.map +0 -1
- package/dist/src/ui/components/Toast.js.map +0 -1
- package/dist/src/ui/components/__tests__/council-leader-bubble.test.js.map +0 -1
- package/dist/src/ui/components/__tests__/council-message-bubble.test.js.map +0 -1
- package/dist/src/ui/components/__tests__/council-phase-timeline.test.js.map +0 -1
- package/dist/src/ui/components/__tests__/council-placeholder-bubble.test.js.map +0 -1
- package/dist/src/ui/components/__tests__/council-question-card.test.js.map +0 -1
- package/dist/src/ui/components/__tests__/council-synthesis-banner.test.js.map +0 -1
- package/dist/src/ui/components/__tests__/use-pair-quote-buffer.test.js.map +0 -1
- package/dist/src/ui/components/btw-overlay.js.map +0 -1
- package/dist/src/ui/components/bubble-layout.js.map +0 -1
- package/dist/src/ui/components/code-block-truncate.js.map +0 -1
- package/dist/src/ui/components/copy-flash-banner.js.map +0 -1
- package/dist/src/ui/components/council-info-card.js.map +0 -1
- package/dist/src/ui/components/council-leader-bubble.js.map +0 -1
- package/dist/src/ui/components/council-message-bubble.js.map +0 -1
- package/dist/src/ui/components/council-phase-timeline.js.map +0 -1
- package/dist/src/ui/components/council-placeholder-bubble.js.map +0 -1
- package/dist/src/ui/components/council-question-card.js.map +0 -1
- package/dist/src/ui/components/council-status-list.js.map +0 -1
- package/dist/src/ui/components/council-synthesis-banner.js.map +0 -1
- package/dist/src/ui/components/diff-view.js.map +0 -1
- package/dist/src/ui/components/halt-recovery-card.js.map +0 -1
- package/dist/src/ui/components/hero-logo.js.map +0 -1
- package/dist/src/ui/components/init-new-form-card.js.map +0 -1
- package/dist/src/ui/components/lsp-views.js.map +0 -1
- package/dist/src/ui/components/media-views.js.map +0 -1
- package/dist/src/ui/components/message-view.js.map +0 -1
- package/dist/src/ui/components/point-to-existing-form-card.js.map +0 -1
- package/dist/src/ui/components/prompt-box.js.map +0 -1
- package/dist/src/ui/components/role-palette.js.map +0 -1
- package/dist/src/ui/components/session-header.js.map +0 -1
- package/dist/src/ui/components/slash-inline-menu.js.map +0 -1
- package/dist/src/ui/components/structured-response-view.js.map +0 -1
- package/dist/src/ui/components/tool-result-views.js.map +0 -1
- package/dist/src/ui/components/use-pair-quote-buffer.js.map +0 -1
- package/dist/src/ui/constants.js.map +0 -1
- package/dist/src/ui/hooks/use-agent-editor.js.map +0 -1
- package/dist/src/ui/hooks/use-mcp-editor.js.map +0 -1
- package/dist/src/ui/hooks/use-model-picker.js.map +0 -1
- package/dist/src/ui/hooks/useTypeahead.js.map +0 -1
- package/dist/src/ui/markdown.js.map +0 -1
- package/dist/src/ui/mcp-modal-types.js.map +0 -1
- package/dist/src/ui/mcp-modal.js.map +0 -1
- package/dist/src/ui/modals/api-key-modal.js.map +0 -1
- package/dist/src/ui/modals/connect-modal.js.map +0 -1
- package/dist/src/ui/modals/model-picker-modal.js.map +0 -1
- package/dist/src/ui/modals/sandbox-picker-modal.js.map +0 -1
- package/dist/src/ui/modals/update-modal.js.map +0 -1
- package/dist/src/ui/modals/wallet-picker-modal.js.map +0 -1
- package/dist/src/ui/plan.js.map +0 -1
- package/dist/src/ui/schedule-modal.js.map +0 -1
- package/dist/src/ui/slash/__tests__/clear.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/compact.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/cost.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/discuss.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/execute.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/expand.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/ideal.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/menu-parity.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/optimize.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/pin.test.js.map +0 -1
- package/dist/src/ui/slash/__tests__/plan.test.js.map +0 -1
- package/dist/src/ui/slash/clear.js.map +0 -1
- package/dist/src/ui/slash/compact.js.map +0 -1
- package/dist/src/ui/slash/cost.js.map +0 -1
- package/dist/src/ui/slash/council-inspect.js.map +0 -1
- package/dist/src/ui/slash/council.js.map +0 -1
- package/dist/src/ui/slash/debug.js.map +0 -1
- package/dist/src/ui/slash/discuss.js.map +0 -1
- package/dist/src/ui/slash/ee.js.map +0 -1
- package/dist/src/ui/slash/execute.js.map +0 -1
- package/dist/src/ui/slash/expand.js.map +0 -1
- package/dist/src/ui/slash/export.js.map +0 -1
- package/dist/src/ui/slash/ideal.js.map +0 -1
- package/dist/src/ui/slash/menu-items.js.map +0 -1
- package/dist/src/ui/slash/optimize.js.map +0 -1
- package/dist/src/ui/slash/pin.js.map +0 -1
- package/dist/src/ui/slash/plan.js.map +0 -1
- package/dist/src/ui/slash/registry.js.map +0 -1
- package/dist/src/ui/slash/route.js.map +0 -1
- package/dist/src/ui/slash/route.test.js.map +0 -1
- package/dist/src/ui/status-bar/index.js.map +0 -1
- package/dist/src/ui/status-bar/index.test.js.map +0 -1
- package/dist/src/ui/status-bar/store.js.map +0 -1
- package/dist/src/ui/status-bar/store.test.js.map +0 -1
- package/dist/src/ui/status-bar/tier-badge.js.map +0 -1
- package/dist/src/ui/status-bar/tier-badge.test.js.map +0 -1
- package/dist/src/ui/status-bar/usd-meter.js.map +0 -1
- package/dist/src/ui/status-bar/usd-meter.test.js.map +0 -1
- package/dist/src/ui/syntax-highlight.js.map +0 -1
- package/dist/src/ui/terminal-selection-text.js.map +0 -1
- package/dist/src/ui/theme.js.map +0 -1
- package/dist/src/ui/types.js.map +0 -1
- package/dist/src/ui/utils/color.js.map +0 -1
- package/dist/src/ui/utils/format.js.map +0 -1
- package/dist/src/ui/utils/modal.js.map +0 -1
- package/dist/src/ui/utils/text.js.map +0 -1
- package/dist/src/ui/utils/tools.js.map +0 -1
- package/dist/src/usage/__tests__/product-ledger.test.js.map +0 -1
- package/dist/src/usage/cost-log.js.map +0 -1
- package/dist/src/usage/decision-log.js.map +0 -1
- package/dist/src/usage/downgrade.js.map +0 -1
- package/dist/src/usage/downgrade.test.js.map +0 -1
- package/dist/src/usage/estimator.js.map +0 -1
- package/dist/src/usage/estimator.test.js.map +0 -1
- package/dist/src/usage/ledger.js.map +0 -1
- package/dist/src/usage/ledger.test.js.map +0 -1
- package/dist/src/usage/midstream.js.map +0 -1
- package/dist/src/usage/midstream.test.js.map +0 -1
- package/dist/src/usage/product-ledger.js.map +0 -1
- package/dist/src/usage/thresholds.js.map +0 -1
- package/dist/src/usage/thresholds.test.js.map +0 -1
- package/dist/src/usage/types.js.map +0 -1
- package/dist/src/utils/__tests__/auto-council-settings.test.js.map +0 -1
- package/dist/src/utils/__tests__/ee-logger.test.js.map +0 -1
- package/dist/src/utils/__tests__/file-lock.test.js.map +0 -1
- package/dist/src/utils/__tests__/rate-limit.test.js.map +0 -1
- package/dist/src/utils/__tests__/settings-disabled-models.test.js.map +0 -1
- package/dist/src/utils/__tests__/settings-web-research.test.js.map +0 -1
- package/dist/src/utils/__tests__/slugify.test.js.map +0 -1
- package/dist/src/utils/__tests__/visible-retry.test.js.map +0 -1
- package/dist/src/utils/at-mentions.js.map +0 -1
- package/dist/src/utils/clipboard-image.js.map +0 -1
- package/dist/src/utils/ee-logger.js.map +0 -1
- package/dist/src/utils/file-index.js.map +0 -1
- package/dist/src/utils/file-lock.js.map +0 -1
- package/dist/src/utils/git-root.js.map +0 -1
- package/dist/src/utils/host-clipboard.js.map +0 -1
- package/dist/src/utils/install-manager.js.map +0 -1
- package/dist/src/utils/install-manager.test.js.map +0 -1
- package/dist/src/utils/instructions.js.map +0 -1
- package/dist/src/utils/instructions.test.js.map +0 -1
- package/dist/src/utils/permission-mode.js.map +0 -1
- package/dist/src/utils/permission-mode.test.js.map +0 -1
- package/dist/src/utils/rate-limit.js.map +0 -1
- package/dist/src/utils/redactor.js.map +0 -1
- package/dist/src/utils/redactor.test.js.map +0 -1
- package/dist/src/utils/settings.js.map +0 -1
- package/dist/src/utils/settings.test.js.map +0 -1
- package/dist/src/utils/shell.js.map +0 -1
- package/dist/src/utils/shell.test.js.map +0 -1
- package/dist/src/utils/side-question.js.map +0 -1
- package/dist/src/utils/skills.js.map +0 -1
- package/dist/src/utils/skills.test.js.map +0 -1
- package/dist/src/utils/slugify.js.map +0 -1
- package/dist/src/utils/subagent-display.js.map +0 -1
- package/dist/src/utils/subagent-display.test.js.map +0 -1
- package/dist/src/utils/subagents-settings.test.js.map +0 -1
- package/dist/src/utils/telegram-audio-settings.test.js.map +0 -1
- package/dist/src/utils/update-checker.js.map +0 -1
- package/dist/src/utils/update-checker.test.js.map +0 -1
- package/dist/src/utils/visible-retry.js.map +0 -1
- package/dist/src/verify/__tests__/coverage-parsers.test.js.map +0 -1
- package/dist/src/verify/__tests__/dotnet-recipe.test.js.map +0 -1
- package/dist/src/verify/checkpoint.js.map +0 -1
- package/dist/src/verify/checkpoint.test.js.map +0 -1
- package/dist/src/verify/coverage-parsers.js.map +0 -1
- package/dist/src/verify/entrypoint.js.map +0 -1
- package/dist/src/verify/entrypoint.test.js.map +0 -1
- package/dist/src/verify/environment.js.map +0 -1
- package/dist/src/verify/environment.test.js.map +0 -1
- package/dist/src/verify/evidence.js.map +0 -1
- package/dist/src/verify/orchestrator.js.map +0 -1
- package/dist/src/verify/orchestrator.test.js.map +0 -1
- package/dist/src/verify/recipes.js.map +0 -1
- package/dist/src/verify/retry.js.map +0 -1
- package/dist/src/verify/runtime-prep.test.js.map +0 -1
- package/src/__test-stubs__/ee-server.ts +0 -173
- package/src/__test-stubs__/vitest-setup.ts +0 -36
- package/src/__tests__/council/bubble-layout.test.ts +0 -45
- package/src/__tests__/council/code-block-truncate.test.ts +0 -50
- package/src/__tests__/council/role-palette.test.ts +0 -66
- package/src/__tests__/first-run-wizard.test.ts +0 -9
- package/src/agent-harness/__tests__/cli-flags.spec.ts +0 -35
- package/src/agent-harness/__tests__/driver.spec.ts +0 -154
- package/src/agent-harness/__tests__/idle.spec.ts +0 -90
- package/src/agent-harness/__tests__/mock-llm.spec.ts +0 -126
- package/src/agent-harness/__tests__/mock-model.spec.ts +0 -195
- package/src/agent-harness/__tests__/predicate.spec.ts +0 -33
- package/src/agent-harness/__tests__/protocol.spec.ts +0 -62
- package/src/agent-harness/__tests__/schema.spec.ts +0 -81
- package/src/agent-harness/__tests__/selector.spec.ts +0 -82
- package/src/agent-harness/__tests__/sidechannel.spec.ts +0 -40
- package/src/agent-harness/__tests__/spec-helpers.spec.ts +0 -76
- package/src/agent-harness/index.ts +0 -24
- package/src/agent-harness/mock-model.ts +0 -394
- package/src/agent-harness/test-spawn.ts +0 -200
- package/src/billing/index.ts +0 -5
- package/src/bun-sqlite.d.ts +0 -15
- package/src/chat/__tests__/broadcast-bus.test.ts +0 -90
- package/src/chat/__tests__/channel-manager.test.ts +0 -149
- package/src/chat/__tests__/client.test.ts +0 -118
- package/src/chat/__tests__/discord-integration.test.ts +0 -162
- package/src/chat/__tests__/intent-prompt.test.ts +0 -92
- package/src/chat/__tests__/verdict-resolver.test.ts +0 -336
- package/src/chat/broadcast-bus.ts +0 -53
- package/src/chat/channel-manager.ts +0 -146
- package/src/chat/chat-keychain.ts +0 -129
- package/src/chat/factory.ts +0 -37
- package/src/chat/intent-prompt.ts +0 -72
- package/src/chat/providers/discord/client.ts +0 -91
- package/src/chat/types.ts +0 -42
- package/src/chat/verdict-constants.ts +0 -26
- package/src/chat/verdict-resolver.ts +0 -231
- package/src/cli/__tests__/bw-vault.test.ts +0 -97
- package/src/cli/__tests__/keys-bundle.test.ts +0 -46
- package/src/cli/__tests__/share-cmd.test.ts +0 -197
- package/src/cli/bw-vault.ts +0 -184
- package/src/cli/config/__tests__/model-picker.test.ts +0 -59
- package/src/cli/config/__tests__/provider-fetch.test.ts +0 -38
- package/src/cli/config/index.ts +0 -112
- package/src/cli/config/model-picker.ts +0 -193
- package/src/cli/config/provider-fetch.ts +0 -75
- package/src/cli/config/screen-council.ts +0 -245
- package/src/cli/config/screen-models.ts +0 -104
- package/src/cli/config/screen-providers.ts +0 -197
- package/src/cli/config/tui.ts +0 -153
- package/src/cli/cost-forensics.test.ts +0 -128
- package/src/cli/cost-forensics.ts +0 -264
- package/src/cli/keys-bundle.ts +0 -91
- package/src/cli/keys.test.ts +0 -104
- package/src/cli/keys.ts +0 -787
- package/src/cli/pil-report.ts +0 -202
- package/src/cli/share-cmd.ts +0 -132
- package/src/cli/usage-report.ts +0 -266
- package/src/cloud/index.ts +0 -5
- package/src/council/__tests__/accounting.test.ts +0 -72
- package/src/council/__tests__/audit-replay.test.ts +0 -344
- package/src/council/__tests__/clarifier-max-rounds.test.ts +0 -91
- package/src/council/__tests__/clarifier-options.test.ts +0 -63
- package/src/council/__tests__/cost-aware.test.ts +0 -60
- package/src/council/__tests__/debate-planner-structured.test.ts +0 -236
- package/src/council/__tests__/evaluator-metrics.test.ts +0 -513
- package/src/council/__tests__/parse-outcome-fallback.test.ts +0 -125
- package/src/council/__tests__/research-tools.test.ts +0 -239
- package/src/council/__tests__/round-tools.test.ts +0 -334
- package/src/council/__tests__/tool-trace.test.ts +0 -152
- package/src/council/__tests__/types-contract.test.ts +0 -88
- package/src/council/clarifier.ts +0 -409
- package/src/council/context.ts +0 -250
- package/src/council/debate-planner.ts +0 -264
- package/src/council/debate.ts +0 -1179
- package/src/council/executor.ts +0 -27
- package/src/council/index.ts +0 -916
- package/src/council/leader.ts +0 -262
- package/src/council/llm.ts +0 -967
- package/src/council/phase-events.ts +0 -58
- package/src/council/planner.ts +0 -303
- package/src/council/preflight.ts +0 -86
- package/src/council/prompts.ts +0 -600
- package/src/council/types.ts +0 -286
- package/src/daemon/scheduler.test.ts +0 -128
- package/src/daemon/scheduler.ts +0 -152
- package/src/ee/.gitkeep +0 -0
- package/src/ee/__tests__/bb-design.test.ts +0 -223
- package/src/ee/__tests__/pil-context-bridge.test.ts +0 -59
- package/src/ee/__tests__/pipeline.integration.test.ts +0 -193
- package/src/ee/__tests__/render-sink-wiring.test.ts +0 -89
- package/src/ee/auth.test.ts +0 -76
- package/src/ee/auth.ts +0 -80
- package/src/ee/bb-design.ts +0 -284
- package/src/ee/bb-retrieval.ts +0 -467
- package/src/ee/bridge.test.ts +0 -283
- package/src/ee/bridge.ts +0 -443
- package/src/ee/client-mode.ts +0 -161
- package/src/ee/client.test.ts +0 -171
- package/src/ee/client.ts +0 -620
- package/src/ee/council-bridge.ts +0 -89
- package/src/ee/embedding-cache.ts +0 -42
- package/src/ee/extract-session.test.ts +0 -231
- package/src/ee/extract-session.ts +0 -71
- package/src/ee/health.ts +0 -83
- package/src/ee/index.ts +0 -33
- package/src/ee/intercept.test.ts +0 -197
- package/src/ee/intercept.ts +0 -143
- package/src/ee/judge.test.ts +0 -213
- package/src/ee/judge.ts +0 -126
- package/src/ee/mistake-detector.test.ts +0 -252
- package/src/ee/mistake-detector.ts +0 -297
- package/src/ee/offline-queue.test.ts +0 -302
- package/src/ee/offline-queue.ts +0 -205
- package/src/ee/phase-outcome.test.ts +0 -107
- package/src/ee/phase-outcome.ts +0 -165
- package/src/ee/phase-tracker.test.ts +0 -175
- package/src/ee/phase-tracker.ts +0 -180
- package/src/ee/posttool.test.ts +0 -81
- package/src/ee/posttool.ts +0 -16
- package/src/ee/prompt-stale.test.ts +0 -92
- package/src/ee/prompt-stale.ts +0 -39
- package/src/ee/render.test.ts +0 -74
- package/src/ee/render.ts +0 -68
- package/src/ee/scope.test.ts +0 -112
- package/src/ee/scope.ts +0 -93
- package/src/ee/session-trajectory.test.ts +0 -139
- package/src/ee/session-trajectory.ts +0 -226
- package/src/ee/tenant.ts +0 -14
- package/src/ee/touch.test.ts +0 -73
- package/src/ee/types.ts +0 -387
- package/src/flow/.gitkeep +0 -0
- package/src/flow/__tests__/migration.test.ts +0 -133
- package/src/flow/__tests__/parser.test.ts +0 -77
- package/src/flow/__tests__/run-manager-product.test.ts +0 -59
- package/src/flow/__tests__/run-manager.test.ts +0 -95
- package/src/flow/__tests__/scaffold-checkpoint.test.ts +0 -113
- package/src/flow/__tests__/scaffold.test.ts +0 -57
- package/src/flow/__tests__/warning-persist.test.ts +0 -112
- package/src/flow/artifact-io.ts +0 -41
- package/src/flow/compaction/__tests__/compress.test.ts +0 -69
- package/src/flow/compaction/__tests__/extract.test.ts +0 -74
- package/src/flow/compaction/__tests__/preserve.test.ts +0 -69
- package/src/flow/compaction/compress.ts +0 -67
- package/src/flow/compaction/extract.ts +0 -60
- package/src/flow/compaction/index.ts +0 -86
- package/src/flow/compaction/preserve.ts +0 -48
- package/src/flow/index.ts +0 -18
- package/src/flow/migration.ts +0 -139
- package/src/flow/parser.ts +0 -78
- package/src/flow/run-manager.ts +0 -162
- package/src/flow/scaffold-checkpoint.ts +0 -132
- package/src/flow/scaffold.ts +0 -52
- package/src/flow/warning-persist.ts +0 -84
- package/src/generated/version.ts +0 -4
- package/src/gsd/.gitkeep +0 -0
- package/src/gsd/__tests__/complexity.test.ts +0 -0
- package/src/gsd/__tests__/directives.test.ts +0 -49
- package/src/gsd/__tests__/gray-areas.test.ts +0 -33
- package/src/gsd/__tests__/types.test.ts +0 -77
- package/src/gsd/complexity.ts +0 -124
- package/src/gsd/directives.ts +0 -94
- package/src/gsd/gray-areas.ts +0 -144
- package/src/gsd/index.ts +0 -1
- package/src/gsd/types.ts +0 -49
- package/src/headless/__tests__/council-answers.test.ts +0 -266
- package/src/headless/council-answers.ts +0 -130
- package/src/headless/output.test.ts +0 -201
- package/src/headless/output.ts +0 -312
- package/src/hooks/config.ts +0 -41
- package/src/hooks/index.ts +0 -547
- package/src/hooks/types.ts +0 -263
- package/src/index.ts +0 -1570
- package/src/lsp/builtins.test.ts +0 -104
- package/src/lsp/builtins.ts +0 -409
- package/src/lsp/client.ts +0 -342
- package/src/lsp/manager.test.ts +0 -164
- package/src/lsp/manager.ts +0 -293
- package/src/lsp/npm-cache.test.ts +0 -68
- package/src/lsp/npm-cache.ts +0 -108
- package/src/lsp/runtime.ts +0 -70
- package/src/lsp/smoke.test.ts +0 -74
- package/src/lsp/types.ts +0 -116
- package/src/mcp/__tests__/auto-setup.test.ts +0 -88
- package/src/mcp/__tests__/harness-driver-action-tools.spec.ts +0 -114
- package/src/mcp/__tests__/harness-driver-async-tools.spec.ts +0 -127
- package/src/mcp/__tests__/harness-driver-read-tools.spec.ts +0 -140
- package/src/mcp/__tests__/harness-driver-security.spec.ts +0 -71
- package/src/mcp/__tests__/harness-driver.spec.ts +0 -21
- package/src/mcp/__tests__/lazy-schema.spec.ts +0 -173
- package/src/mcp/__tests__/mcp-keychain.test.ts +0 -46
- package/src/mcp/__tests__/research-onboarding.test.ts +0 -163
- package/src/mcp/__tests__/runtime-hydration.test.ts +0 -86
- package/src/mcp/__tests__/runtime-sanitize.test.ts +0 -44
- package/src/mcp/auto-setup.ts +0 -99
- package/src/mcp/catalog.ts +0 -155
- package/src/mcp/mcp-keychain.ts +0 -77
- package/src/mcp/oauth-callback.ts +0 -75
- package/src/mcp/oauth-provider.ts +0 -128
- package/src/mcp/opentui-spawn.ts +0 -64
- package/src/mcp/parse-headers.test.ts +0 -54
- package/src/mcp/parse-headers.ts +0 -35
- package/src/mcp/research-onboarding.ts +0 -143
- package/src/mcp/runtime.ts +0 -171
- package/src/mcp/smoke.test.ts +0 -170
- package/src/mcp/validate.ts +0 -48
- package/src/models/__tests__/registry.test.ts +0 -95
- package/src/models/catalog-client.ts +0 -140
- package/src/models/catalog.README.md +0 -136
- package/src/models/catalog.json +0 -177
- package/src/models/classify-tier.ts +0 -48
- package/src/models/index.ts +0 -9
- package/src/models/registry.ts +0 -77
- package/src/ops/__tests__/doctor-council-mcp.test.ts +0 -161
- package/src/ops/__tests__/doctor-ee-health.test.ts +0 -129
- package/src/ops/bug-report.test.ts +0 -172
- package/src/ops/bug-report.ts +0 -80
- package/src/ops/doctor.test.ts +0 -108
- package/src/ops/doctor.ts +0 -366
- package/src/orchestrator/__tests__/batch-turn-runner.test.ts +0 -178
- package/src/orchestrator/__tests__/council-manager.test.ts +0 -171
- package/src/orchestrator/__tests__/cross-turn-dedup.test.ts +0 -174
- package/src/orchestrator/__tests__/current-call-id.test.ts +0 -160
- package/src/orchestrator/__tests__/flow-resume.test.ts +0 -71
- package/src/orchestrator/__tests__/message-processor.test.ts +0 -196
- package/src/orchestrator/__tests__/message-write-ahead.test.ts +0 -170
- package/src/orchestrator/__tests__/read-path-budget.test.ts +0 -107
- package/src/orchestrator/__tests__/retry-classifier.test.ts +0 -120
- package/src/orchestrator/__tests__/retry-stream.test.ts +0 -186
- package/src/orchestrator/__tests__/route-feedback.test.ts +0 -55
- package/src/orchestrator/__tests__/stream-runner.test.ts +0 -123
- package/src/orchestrator/__tests__/usage-events-shape.test.ts +0 -80
- package/src/orchestrator/__tests__/usage-normalizer-c1.test.ts +0 -172
- package/src/orchestrator/__tests__/write-ahead.test.ts +0 -162
- package/src/orchestrator/abort.test.ts +0 -37
- package/src/orchestrator/abort.ts +0 -51
- package/src/orchestrator/agent-options.ts +0 -168
- package/src/orchestrator/agent.test.ts +0 -184
- package/src/orchestrator/batch-turn-runner.ts +0 -425
- package/src/orchestrator/batch-utils.ts +0 -340
- package/src/orchestrator/cleanup.test.ts +0 -86
- package/src/orchestrator/compaction.test.ts +0 -181
- package/src/orchestrator/compaction.ts +0 -613
- package/src/orchestrator/council-manager.ts +0 -580
- package/src/orchestrator/cross-turn-dedup.ts +0 -187
- package/src/orchestrator/delegations.test.ts +0 -145
- package/src/orchestrator/delegations.ts +0 -364
- package/src/orchestrator/error-utils.ts +0 -72
- package/src/orchestrator/flow-resume.ts +0 -54
- package/src/orchestrator/message-processor.ts +0 -1985
- package/src/orchestrator/message-seq.test.ts +0 -29
- package/src/orchestrator/message-seq.ts +0 -19
- package/src/orchestrator/orchestrator.ts +0 -2641
- package/src/orchestrator/pending-calls.test.ts +0 -226
- package/src/orchestrator/pending-calls.ts +0 -240
- package/src/orchestrator/prompts.ts +0 -482
- package/src/orchestrator/provider-options-shape.spec.ts +0 -67
- package/src/orchestrator/provider-options-shape.ts +0 -70
- package/src/orchestrator/read-path-budget.ts +0 -128
- package/src/orchestrator/reasoning.test.ts +0 -29
- package/src/orchestrator/reasoning.ts +0 -69
- package/src/orchestrator/retry-classifier.ts +0 -131
- package/src/orchestrator/retry-stream.ts +0 -159
- package/src/orchestrator/sandbox.test.ts +0 -115
- package/src/orchestrator/stream-runner.ts +0 -729
- package/src/orchestrator/sub-agent-cap.test.ts +0 -186
- package/src/orchestrator/sub-agent-cap.ts +0 -218
- package/src/orchestrator/subagent-compactor.spec.ts +0 -144
- package/src/orchestrator/subagent-compactor.ts +0 -242
- package/src/orchestrator/token-counter.test.ts +0 -69
- package/src/orchestrator/token-counter.ts +0 -81
- package/src/orchestrator/tool-utils.ts +0 -214
- package/src/orchestrator/turn-runner-deps.ts +0 -83
- package/src/pil/__tests__/budget.test.ts +0 -39
- package/src/pil/__tests__/config.test.ts +0 -32
- package/src/pil/__tests__/dual-run.test.ts +0 -53
- package/src/pil/__tests__/layer1-intent-trace.test.ts +0 -140
- package/src/pil/__tests__/layer1-intent.test.ts +0 -346
- package/src/pil/__tests__/layer2-personality.test.ts +0 -63
- package/src/pil/__tests__/layer3-ee-injection.test.ts +0 -181
- package/src/pil/__tests__/layer3-injected-chunk.test.ts +0 -122
- package/src/pil/__tests__/layer4-gsd.test.ts +0 -109
- package/src/pil/__tests__/layer5-context.test.ts +0 -157
- package/src/pil/__tests__/layer6-output.test.ts +0 -284
- package/src/pil/__tests__/ollama-classify.test.ts +0 -81
- package/src/pil/__tests__/orchestrator-integration.test.ts +0 -107
- package/src/pil/__tests__/pipeline.test.ts +0 -190
- package/src/pil/__tests__/renderer-coverage.test.ts +0 -46
- package/src/pil/__tests__/response-tools.test.ts +0 -174
- package/src/pil/__tests__/schema.test.ts +0 -233
- package/src/pil/__tests__/scoreComplexity.test.ts +0 -134
- package/src/pil/__tests__/scoreSufficiency.test.ts +0 -104
- package/src/pil/__tests__/store.test.ts +0 -49
- package/src/pil/__tests__/task-tier-map.test.ts +0 -41
- package/src/pil/budget-log.ts +0 -86
- package/src/pil/budget.ts +0 -18
- package/src/pil/config.ts +0 -11
- package/src/pil/index.ts +0 -12
- package/src/pil/layer1-intent.test.ts +0 -127
- package/src/pil/layer1-intent.ts +0 -580
- package/src/pil/layer2-personality.ts +0 -46
- package/src/pil/layer3-ee-injection.ts +0 -345
- package/src/pil/layer4-gsd.ts +0 -118
- package/src/pil/layer5-context.ts +0 -160
- package/src/pil/layer6-output.ts +0 -260
- package/src/pil/ollama-classify.ts +0 -49
- package/src/pil/pipeline.ts +0 -207
- package/src/pil/response-tools.ts +0 -110
- package/src/pil/schema.ts +0 -103
- package/src/pil/store.ts +0 -29
- package/src/pil/task-tier-map.ts +0 -90
- package/src/pil/timeout.ts +0 -10
- package/src/pil/types.ts +0 -150
- package/src/product-loop/__tests__/artifact-io.test.ts +0 -97
- package/src/product-loop/__tests__/assumption-ledger.test.ts +0 -292
- package/src/product-loop/__tests__/cb2-retry-bonus.test.ts +0 -182
- package/src/product-loop/__tests__/circuit-breakers-coverage.test.ts +0 -82
- package/src/product-loop/__tests__/circuit-breakers.test.ts +0 -90
- package/src/product-loop/__tests__/complexity-routing.spec.ts +0 -169
- package/src/product-loop/__tests__/context-policy.test.ts +0 -280
- package/src/product-loop/__tests__/cost-preview.test.ts +0 -118
- package/src/product-loop/__tests__/cost-scoper.test.ts +0 -76
- package/src/product-loop/__tests__/cross-run-memory.test.ts +0 -195
- package/src/product-loop/__tests__/design-output.spec.ts +0 -39
- package/src/product-loop/__tests__/discover.test.ts +0 -98
- package/src/product-loop/__tests__/discovery-council-runner.test.ts +0 -13
- package/src/product-loop/__tests__/discovery-detection.test.ts +0 -180
- package/src/product-loop/__tests__/discovery-ecosystem.test.ts +0 -132
- package/src/product-loop/__tests__/discovery-integration.test.ts +0 -133
- package/src/product-loop/__tests__/discovery-interview.test.ts +0 -305
- package/src/product-loop/__tests__/discovery-migrations.test.ts +0 -75
- package/src/product-loop/__tests__/discovery-persistence.test.ts +0 -171
- package/src/product-loop/__tests__/discovery-prompt-parser.test.ts +0 -77
- package/src/product-loop/__tests__/discovery-recommender-ecosystem.test.ts +0 -94
- package/src/product-loop/__tests__/discovery-recommender.test.ts +0 -382
- package/src/product-loop/__tests__/discovery-schema.test.ts +0 -102
- package/src/product-loop/__tests__/done-gate-coverage.test.ts +0 -151
- package/src/product-loop/__tests__/done-gate.test.ts +0 -140
- package/src/product-loop/__tests__/ee-extract-wiring.test.ts +0 -216
- package/src/product-loop/__tests__/extract-to-ee.test.ts +0 -205
- package/src/product-loop/__tests__/feedback-routing.test.ts +0 -93
- package/src/product-loop/__tests__/hot-path.spec.ts +0 -177
- package/src/product-loop/__tests__/integration.test.ts +0 -344
- package/src/product-loop/__tests__/loop-driver-audit.test.ts +0 -321
- package/src/product-loop/__tests__/loop-driver.test.ts +0 -247
- package/src/product-loop/__tests__/phase-budget.test.ts +0 -172
- package/src/product-loop/__tests__/phase-orchestrator-integration.test.ts +0 -143
- package/src/product-loop/__tests__/phase-plan.test.ts +0 -241
- package/src/product-loop/__tests__/phase-rituals.test.ts +0 -211
- package/src/product-loop/__tests__/phase-runner.test.ts +0 -454
- package/src/product-loop/__tests__/phase-tracker-bridge.test.ts +0 -85
- package/src/product-loop/__tests__/product-identity.test.ts +0 -47
- package/src/product-loop/__tests__/reality-anchor.test.ts +0 -58
- package/src/product-loop/__tests__/repo-audit.test.ts +0 -103
- package/src/product-loop/__tests__/role-memory.test.ts +0 -70
- package/src/product-loop/__tests__/role-registry.test.ts +0 -235
- package/src/product-loop/__tests__/role-routing-ee.test.ts +0 -90
- package/src/product-loop/__tests__/route-decision-emit.test.ts +0 -207
- package/src/product-loop/__tests__/seed-questions.test.ts +0 -33
- package/src/product-loop/__tests__/ship-polish.test.ts +0 -109
- package/src/product-loop/__tests__/sprint-runner-emit.test.ts +0 -324
- package/src/product-loop/__tests__/sprint-runner.test.ts +0 -501
- package/src/product-loop/__tests__/stakeholder-acl.test.ts +0 -94
- package/src/product-loop/__tests__/state-md-ee-injections.test.ts +0 -229
- package/src/product-loop/__tests__/sufficiency-routing.spec.ts +0 -177
- package/src/product-loop/__tests__/typed-artifacts.test.ts +0 -261
- package/src/product-loop/__tests__/types.test.ts +0 -103
- package/src/product-loop/__tests__/verify-failure-threshold.test.ts +0 -177
- package/src/product-loop/__tests__/verify-failure-tracking.test.ts +0 -154
- package/src/product-loop/__tests__/verify-result.test.ts +0 -60
- package/src/product-loop/artifact-io.ts +0 -239
- package/src/product-loop/assumption-ledger.ts +0 -270
- package/src/product-loop/circuit-breakers.ts +0 -76
- package/src/product-loop/context-policy.ts +0 -180
- package/src/product-loop/cost-preview.ts +0 -124
- package/src/product-loop/cost-scoper.ts +0 -49
- package/src/product-loop/cross-run-memory.ts +0 -450
- package/src/product-loop/design-output.ts +0 -24
- package/src/product-loop/discover.ts +0 -159
- package/src/product-loop/discovery-context-format.ts +0 -32
- package/src/product-loop/discovery-council-runner.ts +0 -82
- package/src/product-loop/discovery-detection.ts +0 -161
- package/src/product-loop/discovery-ecosystem.ts +0 -124
- package/src/product-loop/discovery-interview.ts +0 -237
- package/src/product-loop/discovery-migrations.ts +0 -40
- package/src/product-loop/discovery-persistence.ts +0 -219
- package/src/product-loop/discovery-prompt-parser.ts +0 -80
- package/src/product-loop/discovery-recommender.ts +0 -366
- package/src/product-loop/discovery-schema.ts +0 -143
- package/src/product-loop/done-gate.ts +0 -224
- package/src/product-loop/feedback-routing.ts +0 -82
- package/src/product-loop/gather.ts +0 -304
- package/src/product-loop/index.ts +0 -1305
- package/src/product-loop/loop-driver.ts +0 -901
- package/src/product-loop/phase-budget.ts +0 -182
- package/src/product-loop/phase-plan.ts +0 -158
- package/src/product-loop/phase-rituals.ts +0 -158
- package/src/product-loop/phase-runner.ts +0 -455
- package/src/product-loop/phase-tracker-bridge.ts +0 -60
- package/src/product-loop/product-identity.ts +0 -11
- package/src/product-loop/reality-anchor.ts +0 -45
- package/src/product-loop/repo-audit.ts +0 -314
- package/src/product-loop/role-memory.ts +0 -72
- package/src/product-loop/role-registry.ts +0 -175
- package/src/product-loop/seed-questions.ts +0 -51
- package/src/product-loop/ship-polish.ts +0 -164
- package/src/product-loop/sprint-runner.ts +0 -610
- package/src/product-loop/stakeholder-acl.ts +0 -82
- package/src/product-loop/typed-artifacts.ts +0 -332
- package/src/product-loop/types.ts +0 -443
- package/src/product-loop/verify-failure-tracking.ts +0 -225
- package/src/product-loop/verify-result.ts +0 -39
- package/src/providers/.gitkeep +0 -0
- package/src/providers/__test-utils__/load-fixture.ts +0 -36
- package/src/providers/__tests__/adapter-oauth-wiring.test.ts +0 -129
- package/src/providers/__tests__/capabilities-cosmetic.test.ts +0 -119
- package/src/providers/__tests__/capabilities-flags.test.ts +0 -166
- package/src/providers/__tests__/capabilities-provider-options.test.ts +0 -203
- package/src/providers/__tests__/capabilities-sanitize.test.ts +0 -82
- package/src/providers/__tests__/capabilities.test.ts +0 -44
- package/src/providers/__tests__/provider-coverage.test.ts +0 -48
- package/src/providers/__tests__/runtime-integration.test.ts +0 -97
- package/src/providers/__tests__/runtime.test.ts +0 -96
- package/src/providers/__tests__/siliconflow-history.test.ts +0 -82
- package/src/providers/__tests__/strategies-registry.test.ts +0 -55
- package/src/providers/__tests__/strategies-resolve.test.ts +0 -137
- package/src/providers/__tests__/wire-debug.test.ts +0 -42
- package/src/providers/adapter.test.ts +0 -21
- package/src/providers/adapter.ts +0 -156
- package/src/providers/anthropic.ts +0 -174
- package/src/providers/auth/__tests__/browser-flow.test.ts +0 -235
- package/src/providers/auth/__tests__/device-flow.test.ts +0 -263
- package/src/providers/auth/__tests__/gemini-oauth.test.ts +0 -387
- package/src/providers/auth/__tests__/openai-oauth.test.ts +0 -378
- package/src/providers/auth/__tests__/token-store.test.ts +0 -152
- package/src/providers/auth/browser-flow.ts +0 -140
- package/src/providers/auth/device-flow.ts +0 -221
- package/src/providers/auth/gemini-oauth.ts +0 -351
- package/src/providers/auth/openai-oauth.ts +0 -455
- package/src/providers/auth/registry.ts +0 -121
- package/src/providers/auth/token-store.ts +0 -154
- package/src/providers/auth/types.ts +0 -111
- package/src/providers/capabilities.ts +0 -351
- package/src/providers/endpoints.ts +0 -68
- package/src/providers/errors.test.ts +0 -76
- package/src/providers/errors.ts +0 -46
- package/src/providers/gemini.test.ts +0 -46
- package/src/providers/gemini.ts +0 -42
- package/src/providers/index.ts +0 -28
- package/src/providers/keychain.test.ts +0 -100
- package/src/providers/keychain.ts +0 -267
- package/src/providers/mcp-vision-bridge.test.ts +0 -513
- package/src/providers/mcp-vision-bridge.ts +0 -1020
- package/src/providers/ollama.test.ts +0 -46
- package/src/providers/ollama.ts +0 -36
- package/src/providers/openai-compatible.test.ts +0 -63
- package/src/providers/openai-compatible.ts +0 -58
- package/src/providers/openai.test.ts +0 -65
- package/src/providers/openai.ts +0 -56
- package/src/providers/patch-zod-schema.ts +0 -126
- package/src/providers/pricing.test.ts +0 -65
- package/src/providers/pricing.ts +0 -111
- package/src/providers/prompt-cache-key.spec.ts +0 -28
- package/src/providers/runtime-mock.spec.ts +0 -86
- package/src/providers/runtime.ts +0 -283
- package/src/providers/siliconflow-history.ts +0 -74
- package/src/providers/strategies/anthropic.strategy.ts +0 -25
- package/src/providers/strategies/base.strategy.ts +0 -76
- package/src/providers/strategies/deepseek.strategy.ts +0 -26
- package/src/providers/strategies/google.strategy.ts +0 -28
- package/src/providers/strategies/ollama.strategy.ts +0 -22
- package/src/providers/strategies/openai.strategy.ts +0 -55
- package/src/providers/strategies/registry.ts +0 -43
- package/src/providers/strategies/siliconflow.strategy.ts +0 -26
- package/src/providers/strategies/xai.strategy.ts +0 -26
- package/src/providers/stream-loop.ts +0 -83
- package/src/providers/types.ts +0 -145
- package/src/providers/vision-proxy.test.ts +0 -252
- package/src/providers/vision-proxy.ts +0 -317
- package/src/providers/wire-debug.ts +0 -163
- package/src/router/.gitkeep +0 -0
- package/src/router/__tests__/step-router.test.ts +0 -150
- package/src/router/classifier/grammars.ts +0 -17
- package/src/router/classifier/index.test.ts +0 -33
- package/src/router/classifier/index.ts +0 -21
- package/src/router/classifier/regex.test.ts +0 -49
- package/src/router/classifier/regex.ts +0 -113
- package/src/router/classifier/tree-sitter.test.ts +0 -26
- package/src/router/classifier/tree-sitter.ts +0 -87
- package/src/router/cold.test.ts +0 -62
- package/src/router/cold.ts +0 -27
- package/src/router/decide.test.ts +0 -147
- package/src/router/decide.ts +0 -472
- package/src/router/health.test.ts +0 -59
- package/src/router/health.ts +0 -49
- package/src/router/provider-sentinel.test.ts +0 -22
- package/src/router/provider-sentinel.ts +0 -20
- package/src/router/step-router.ts +0 -194
- package/src/router/store.ts +0 -47
- package/src/router/types.ts +0 -20
- package/src/router/warm.test.ts +0 -168
- package/src/router/warm.ts +0 -53
- package/src/scaffold/__tests__/continuation-prompt.test.ts +0 -93
- package/src/scaffold/__tests__/continue-as-council.spec.ts +0 -124
- package/src/scaffold/__tests__/dotnet-assembly-name.test.ts +0 -28
- package/src/scaffold/__tests__/fe-scaffold-contents.test.ts +0 -127
- package/src/scaffold/__tests__/init-new.smoke.spec.ts +0 -99
- package/src/scaffold/__tests__/init-new.spec.ts +0 -450
- package/src/scaffold/__tests__/install-bb-templates.spec.ts +0 -86
- package/src/scaffold/__tests__/point-to-existing.spec.ts +0 -114
- package/src/scaffold/bb-ecosystem-apply.ts +0 -454
- package/src/scaffold/bb-quality-gate.ts +0 -287
- package/src/scaffold/continuation-prompt.ts +0 -80
- package/src/scaffold/continue-as-council.ts +0 -99
- package/src/scaffold/init-new.ts +0 -1691
- package/src/scaffold/point-to-existing.ts +0 -83
- package/src/scaffold/resume-from-gate-failures.ts +0 -167
- package/src/storage/__tests__/migrations.test.ts +0 -395
- package/src/storage/__tests__/ui-interaction-log.test.ts +0 -105
- package/src/storage/atomic-io.test.ts +0 -92
- package/src/storage/atomic-io.ts +0 -160
- package/src/storage/config.test.ts +0 -33
- package/src/storage/config.ts +0 -53
- package/src/storage/db.ts +0 -184
- package/src/storage/index.ts +0 -26
- package/src/storage/interaction-log.ts +0 -121
- package/src/storage/migrations.ts +0 -205
- package/src/storage/session-dir.ts +0 -37
- package/src/storage/sessions.ts +0 -206
- package/src/storage/tool-results.ts +0 -56
- package/src/storage/transcript-view.ts +0 -45
- package/src/storage/transcript.test.ts +0 -24
- package/src/storage/transcript.ts +0 -561
- package/src/storage/ui-interaction-log.ts +0 -160
- package/src/storage/usage-cap.test.ts +0 -59
- package/src/storage/usage-cap.ts +0 -81
- package/src/storage/usage.ts +0 -117
- package/src/storage/workspaces.ts +0 -84
- package/src/tools/bash.test.ts +0 -363
- package/src/tools/bash.ts +0 -668
- package/src/tools/computer.test.ts +0 -187
- package/src/tools/computer.ts +0 -632
- package/src/tools/file-tracker.test.ts +0 -99
- package/src/tools/file-tracker.ts +0 -70
- package/src/tools/file.test.ts +0 -95
- package/src/tools/file.ts +0 -182
- package/src/tools/grep.ts +0 -187
- package/src/tools/registry.test.ts +0 -38
- package/src/tools/registry.ts +0 -388
- package/src/tools/schedule.test.ts +0 -143
- package/src/tools/schedule.ts +0 -610
- package/src/types/index.ts +0 -474
- package/src/ui/agents-modal.tsx +0 -292
- package/src/ui/app.tsx +0 -6464
- package/src/ui/cards/__tests__/product-status-card.test.ts +0 -30
- package/src/ui/cards/product-status-card.tsx +0 -117
- package/src/ui/components/SuggestionOverlay.tsx +0 -38
- package/src/ui/components/Toast.tsx +0 -100
- package/src/ui/components/__tests__/council-leader-bubble.test.ts +0 -16
- package/src/ui/components/__tests__/council-message-bubble.test.ts +0 -85
- package/src/ui/components/__tests__/council-phase-timeline.test.ts +0 -57
- package/src/ui/components/__tests__/council-placeholder-bubble.test.ts +0 -16
- package/src/ui/components/__tests__/council-question-card.test.ts +0 -133
- package/src/ui/components/__tests__/council-synthesis-banner.test.ts +0 -12
- package/src/ui/components/__tests__/use-pair-quote-buffer.test.ts +0 -41
- package/src/ui/components/btw-overlay.tsx +0 -66
- package/src/ui/components/bubble-layout.ts +0 -66
- package/src/ui/components/code-block-truncate.ts +0 -24
- package/src/ui/components/copy-flash-banner.tsx +0 -31
- package/src/ui/components/council-info-card.tsx +0 -45
- package/src/ui/components/council-leader-bubble.tsx +0 -41
- package/src/ui/components/council-message-bubble.tsx +0 -111
- package/src/ui/components/council-phase-timeline.tsx +0 -91
- package/src/ui/components/council-placeholder-bubble.tsx +0 -65
- package/src/ui/components/council-question-card.tsx +0 -253
- package/src/ui/components/council-status-list.tsx +0 -111
- package/src/ui/components/council-synthesis-banner.tsx +0 -37
- package/src/ui/components/diff-view.tsx +0 -225
- package/src/ui/components/halt-recovery-card.tsx +0 -83
- package/src/ui/components/hero-logo.tsx +0 -62
- package/src/ui/components/init-new-form-card.tsx +0 -470
- package/src/ui/components/lsp-views.tsx +0 -104
- package/src/ui/components/media-views.tsx +0 -66
- package/src/ui/components/message-view.tsx +0 -343
- package/src/ui/components/point-to-existing-form-card.tsx +0 -136
- package/src/ui/components/prompt-box.tsx +0 -306
- package/src/ui/components/role-palette.ts +0 -62
- package/src/ui/components/session-header.tsx +0 -68
- package/src/ui/components/slash-inline-menu.tsx +0 -63
- package/src/ui/components/structured-response-view.tsx +0 -191
- package/src/ui/components/tool-result-views.tsx +0 -258
- package/src/ui/components/use-pair-quote-buffer.ts +0 -23
- package/src/ui/constants.ts +0 -242
- package/src/ui/hooks/use-agent-editor.ts +0 -64
- package/src/ui/hooks/use-mcp-editor.ts +0 -39
- package/src/ui/hooks/use-model-picker.ts +0 -50
- package/src/ui/hooks/useTypeahead.ts +0 -160
- package/src/ui/markdown.tsx +0 -49
- package/src/ui/mcp-modal-types.ts +0 -33
- package/src/ui/mcp-modal.tsx +0 -484
- package/src/ui/modals/api-key-modal.tsx +0 -99
- package/src/ui/modals/connect-modal.tsx +0 -259
- package/src/ui/modals/model-picker-modal.tsx +0 -323
- package/src/ui/modals/sandbox-picker-modal.tsx +0 -99
- package/src/ui/modals/update-modal.tsx +0 -67
- package/src/ui/modals/wallet-picker-modal.tsx +0 -186
- package/src/ui/plan.tsx +0 -346
- package/src/ui/schedule-modal.tsx +0 -138
- package/src/ui/slash/__tests__/clear.test.ts +0 -86
- package/src/ui/slash/__tests__/compact.test.ts +0 -56
- package/src/ui/slash/__tests__/cost.test.ts +0 -62
- package/src/ui/slash/__tests__/discuss.test.ts +0 -101
- package/src/ui/slash/__tests__/execute.test.ts +0 -86
- package/src/ui/slash/__tests__/expand.test.ts +0 -86
- package/src/ui/slash/__tests__/ideal.test.ts +0 -134
- package/src/ui/slash/__tests__/menu-parity.test.ts +0 -43
- package/src/ui/slash/__tests__/optimize.test.ts +0 -155
- package/src/ui/slash/__tests__/pin.test.ts +0 -47
- package/src/ui/slash/__tests__/plan.test.ts +0 -95
- package/src/ui/slash/clear.ts +0 -89
- package/src/ui/slash/compact.ts +0 -46
- package/src/ui/slash/cost.ts +0 -63
- package/src/ui/slash/council-inspect.ts +0 -188
- package/src/ui/slash/council.ts +0 -30
- package/src/ui/slash/debug.ts +0 -153
- package/src/ui/slash/discuss.ts +0 -71
- package/src/ui/slash/ee.ts +0 -304
- package/src/ui/slash/execute.ts +0 -44
- package/src/ui/slash/expand.ts +0 -51
- package/src/ui/slash/export.ts +0 -281
- package/src/ui/slash/ideal.ts +0 -254
- package/src/ui/slash/menu-items.ts +0 -106
- package/src/ui/slash/optimize.ts +0 -47
- package/src/ui/slash/pin.ts +0 -41
- package/src/ui/slash/plan.ts +0 -62
- package/src/ui/slash/registry.ts +0 -47
- package/src/ui/slash/route.test.ts +0 -82
- package/src/ui/slash/route.ts +0 -43
- package/src/ui/status-bar/index.test.tsx +0 -90
- package/src/ui/status-bar/index.tsx +0 -98
- package/src/ui/status-bar/store.test.ts +0 -131
- package/src/ui/status-bar/store.ts +0 -186
- package/src/ui/status-bar/tier-badge.test.tsx +0 -38
- package/src/ui/status-bar/tier-badge.tsx +0 -29
- package/src/ui/status-bar/usd-meter.test.tsx +0 -37
- package/src/ui/status-bar/usd-meter.tsx +0 -22
- package/src/ui/syntax-highlight.ts +0 -627
- package/src/ui/terminal-selection-text.ts +0 -72
- package/src/ui/theme.ts +0 -95
- package/src/ui/types.ts +0 -83
- package/src/ui/utils/color.ts +0 -19
- package/src/ui/utils/format.ts +0 -86
- package/src/ui/utils/modal.ts +0 -9
- package/src/ui/utils/text.ts +0 -31
- package/src/ui/utils/tools.ts +0 -95
- package/src/usage/.gitkeep +0 -0
- package/src/usage/__tests__/product-ledger.test.ts +0 -85
- package/src/usage/cost-log.ts +0 -158
- package/src/usage/decision-log.ts +0 -86
- package/src/usage/downgrade.test.ts +0 -82
- package/src/usage/downgrade.ts +0 -70
- package/src/usage/estimator.test.ts +0 -43
- package/src/usage/estimator.ts +0 -58
- package/src/usage/ledger.test.ts +0 -200
- package/src/usage/ledger.ts +0 -253
- package/src/usage/midstream.test.ts +0 -55
- package/src/usage/midstream.ts +0 -51
- package/src/usage/product-ledger.ts +0 -111
- package/src/usage/thresholds.test.ts +0 -83
- package/src/usage/thresholds.ts +0 -74
- package/src/usage/types.ts +0 -41
- package/src/utils/__tests__/auto-council-settings.test.ts +0 -46
- package/src/utils/__tests__/ee-logger.test.ts +0 -197
- package/src/utils/__tests__/file-lock.test.ts +0 -74
- package/src/utils/__tests__/rate-limit.test.ts +0 -42
- package/src/utils/__tests__/settings-disabled-models.test.ts +0 -113
- package/src/utils/__tests__/settings-web-research.test.ts +0 -45
- package/src/utils/__tests__/slugify.test.ts +0 -45
- package/src/utils/__tests__/visible-retry.test.ts +0 -195
- package/src/utils/at-mentions.ts +0 -120
- package/src/utils/clipboard-image.ts +0 -139
- package/src/utils/ee-logger.ts +0 -163
- package/src/utils/file-index.ts +0 -152
- package/src/utils/file-lock.ts +0 -66
- package/src/utils/git-root.ts +0 -17
- package/src/utils/host-clipboard.ts +0 -68
- package/src/utils/install-manager.test.ts +0 -167
- package/src/utils/install-manager.ts +0 -429
- package/src/utils/instructions.test.ts +0 -112
- package/src/utils/instructions.ts +0 -149
- package/src/utils/permission-mode.test.ts +0 -121
- package/src/utils/permission-mode.ts +0 -37
- package/src/utils/rate-limit.ts +0 -21
- package/src/utils/redactor.test.ts +0 -100
- package/src/utils/redactor.ts +0 -223
- package/src/utils/settings.test.ts +0 -181
- package/src/utils/settings.ts +0 -1108
- package/src/utils/shell.test.ts +0 -72
- package/src/utils/shell.ts +0 -193
- package/src/utils/side-question.ts +0 -39
- package/src/utils/skills.test.ts +0 -58
- package/src/utils/skills.ts +0 -207
- package/src/utils/slugify.ts +0 -9
- package/src/utils/subagent-display.test.ts +0 -23
- package/src/utils/subagent-display.ts +0 -11
- package/src/utils/subagents-settings.test.ts +0 -77
- package/src/utils/telegram-audio-settings.test.ts +0 -44
- package/src/utils/update-checker.test.ts +0 -182
- package/src/utils/update-checker.ts +0 -33
- package/src/utils/visible-retry.ts +0 -56
- package/src/verify/__tests__/coverage-parsers.test.ts +0 -86
- package/src/verify/__tests__/dotnet-recipe.test.ts +0 -88
- package/src/verify/checkpoint.test.ts +0 -186
- package/src/verify/checkpoint.ts +0 -239
- package/src/verify/coverage-parsers.ts +0 -76
- package/src/verify/entrypoint.test.ts +0 -293
- package/src/verify/entrypoint.ts +0 -439
- package/src/verify/environment.test.ts +0 -119
- package/src/verify/environment.ts +0 -115
- package/src/verify/evidence.ts +0 -104
- package/src/verify/orchestrator.test.ts +0 -159
- package/src/verify/orchestrator.ts +0 -129
- package/src/verify/recipes.ts +0 -592
- package/src/verify/retry.ts +0 -62
- package/src/verify/runtime-prep.test.ts +0 -47
- /package/dist/src/{providers/__tests__/siliconflow-history.test.d.ts → council/__tests__/clarifier-ready-gate.test.d.ts} +0 -0
|
@@ -1,2641 +0,0 @@
|
|
|
1
|
-
// Multi-provider wired — runtime dispatch via providers/runtime.ts.
|
|
2
|
-
|
|
3
|
-
import type { ModelMessage, ToolSet } from "ai";
|
|
4
|
-
import { extractSession } from "../ee/extract-session.js";
|
|
5
|
-
import { bootstrapEEClient, getDefaultEEClient, getLastSurfacedState } from "../ee/intercept.js";
|
|
6
|
-
import { getTenantId } from "../ee/tenant.js";
|
|
7
|
-
import { createRun, getActiveRunId, setActiveRunId } from "../flow/run-manager.js";
|
|
8
|
-
import { ensureFlowDir } from "../flow/scaffold.js";
|
|
9
|
-
import { executeEventHooks } from "../hooks/index";
|
|
10
|
-
import type {
|
|
11
|
-
NotificationHookInput,
|
|
12
|
-
PostCompactHookInput,
|
|
13
|
-
PreCompactHookInput,
|
|
14
|
-
SessionEndHookInput,
|
|
15
|
-
SubagentStartHookInput,
|
|
16
|
-
SubagentStopHookInput,
|
|
17
|
-
TaskCompletedHookInput,
|
|
18
|
-
TaskCreatedHookInput,
|
|
19
|
-
} from "../hooks/types";
|
|
20
|
-
import { shutdownWorkspaceLspManager } from "../lsp/runtime";
|
|
21
|
-
import { ensureDefaultMcpServers } from "../mcp/auto-setup.js";
|
|
22
|
-
import { getModelByTier, getModelInfo, normalizeModelId } from "../models/registry.js";
|
|
23
|
-
import { getProviderCapabilities } from "../providers/capabilities.js";
|
|
24
|
-
import { apiBaseFor } from "../providers/endpoints.js";
|
|
25
|
-
import { loadKeyForProvider } from "../providers/keychain.js";
|
|
26
|
-
import {
|
|
27
|
-
createProviderFactory,
|
|
28
|
-
createProviderFactoryAsync,
|
|
29
|
-
detectProviderForModel,
|
|
30
|
-
resolveModelRuntime as resolveRuntime,
|
|
31
|
-
} from "../providers/runtime.js";
|
|
32
|
-
import type { ProviderId } from "../providers/types.js";
|
|
33
|
-
import {
|
|
34
|
-
appendCompaction,
|
|
35
|
-
appendMessages,
|
|
36
|
-
appendSystemMessage,
|
|
37
|
-
buildChatEntries,
|
|
38
|
-
getNextMessageSequence,
|
|
39
|
-
getSessionTotalTokens,
|
|
40
|
-
loadTranscript,
|
|
41
|
-
loadTranscriptState,
|
|
42
|
-
logInteraction,
|
|
43
|
-
markMessageCompleted,
|
|
44
|
-
recordUsageEvent,
|
|
45
|
-
SessionStore,
|
|
46
|
-
} from "../storage/index";
|
|
47
|
-
import { BashTool } from "../tools/bash";
|
|
48
|
-
import { createBuiltinTools } from "../tools/registry.js";
|
|
49
|
-
import { type ScheduleDaemonStatus, ScheduleManager, type StoredSchedule } from "../tools/schedule";
|
|
50
|
-
import type {
|
|
51
|
-
AgentMode,
|
|
52
|
-
ChatEntry,
|
|
53
|
-
SessionInfo,
|
|
54
|
-
SessionSnapshot,
|
|
55
|
-
StreamChunk,
|
|
56
|
-
SubagentStatus,
|
|
57
|
-
TaskRequest,
|
|
58
|
-
ToolCall,
|
|
59
|
-
ToolResult,
|
|
60
|
-
UsageSource,
|
|
61
|
-
VerifyRecipe,
|
|
62
|
-
WorkspaceInfo,
|
|
63
|
-
} from "../types/index";
|
|
64
|
-
import { statusBarStore } from "../ui/status-bar/store.js";
|
|
65
|
-
import { appendCostLog } from "../usage/cost-log.js";
|
|
66
|
-
import { appendDecisionLog } from "../usage/decision-log.js";
|
|
67
|
-
import { projectCostUSD } from "../usage/estimator.js";
|
|
68
|
-
import type { PermissionMode } from "../utils/permission-mode.js";
|
|
69
|
-
import {
|
|
70
|
-
type CustomSubagentConfig,
|
|
71
|
-
getAutoCompactThresholdPct,
|
|
72
|
-
getCouncilRounds,
|
|
73
|
-
getCurrentModel,
|
|
74
|
-
getCurrentShellSettings,
|
|
75
|
-
getModeSpecificModel,
|
|
76
|
-
getRoleModel,
|
|
77
|
-
getRoleModels,
|
|
78
|
-
isAutoCompactAfterTurnEnabled,
|
|
79
|
-
isCouncilMultiProviderPreferred,
|
|
80
|
-
isProviderDisabled,
|
|
81
|
-
type ModelRole,
|
|
82
|
-
type SandboxMode,
|
|
83
|
-
type SandboxSettings,
|
|
84
|
-
} from "../utils/settings";
|
|
85
|
-
import { runSideQuestion, type SideQuestionResult } from "../utils/side-question";
|
|
86
|
-
import { buildVerifyDetectPrompt, normalizeVerifyRecipe } from "../verify/entrypoint";
|
|
87
|
-
import { runVerifyOrchestration } from "../verify/orchestrator";
|
|
88
|
-
import {
|
|
89
|
-
type AgentOptions,
|
|
90
|
-
type BatchChatCompletionResponse,
|
|
91
|
-
type BatchClientOptions,
|
|
92
|
-
type BatchFunctionTool,
|
|
93
|
-
COUNCIL_COLOR_BG,
|
|
94
|
-
COUNCIL_COLOR_RESET,
|
|
95
|
-
COUNCIL_ROLE_COLORS,
|
|
96
|
-
type LegacyProvider,
|
|
97
|
-
type ProcessMessageObserver,
|
|
98
|
-
type ProcessMessageUsage,
|
|
99
|
-
type ResolvedModelRuntime,
|
|
100
|
-
} from "./agent-options";
|
|
101
|
-
import { BatchTurnRunner, type BatchTurnRunnerDeps } from "./batch-turn-runner.js";
|
|
102
|
-
import {
|
|
103
|
-
accumulateUsage,
|
|
104
|
-
buildAssistantBatchMessage,
|
|
105
|
-
buildBatchChatCompletionRequest,
|
|
106
|
-
buildBatchName,
|
|
107
|
-
buildToolBatchMessage,
|
|
108
|
-
type ExecutedBatchTool,
|
|
109
|
-
extractJsonObject,
|
|
110
|
-
getBatchFinishReason,
|
|
111
|
-
getBatchUsage,
|
|
112
|
-
hasUsage,
|
|
113
|
-
parseToolArgumentsOrRaw,
|
|
114
|
-
toLocalToolCall,
|
|
115
|
-
} from "./batch-utils";
|
|
116
|
-
import {
|
|
117
|
-
type CompactionSettings,
|
|
118
|
-
createCompactionSummaryMessage,
|
|
119
|
-
DEFAULT_KEEP_RECENT_TOKENS,
|
|
120
|
-
DEFAULT_RESERVE_TOKENS,
|
|
121
|
-
estimateConversationTokens,
|
|
122
|
-
extractUserContent,
|
|
123
|
-
generateCompactionSummary,
|
|
124
|
-
POST_TURN_MIN_TOKENS,
|
|
125
|
-
prepareCompaction,
|
|
126
|
-
shouldCompactContext,
|
|
127
|
-
} from "./compaction";
|
|
128
|
-
import { CouncilManager } from "./council-manager.js";
|
|
129
|
-
import { CrossTurnDedup, isCrossTurnDedupEnabled } from "./cross-turn-dedup.js";
|
|
130
|
-
import { DelegationManager } from "./delegations";
|
|
131
|
-
import { loadFlowResumeDigest } from "./flow-resume.js";
|
|
132
|
-
import { MessageProcessor, type MessageProcessorDeps } from "./message-processor.js";
|
|
133
|
-
import { lastPersistedSeq } from "./message-seq.js";
|
|
134
|
-
import { buildSystemPrompt, MAX_TOOL_ROUNDS } from "./prompts";
|
|
135
|
-
import { getReadPathBudgetCap, ReadPathBudget } from "./read-path-budget.js";
|
|
136
|
-
import { withStreamRetry } from "./retry-stream.js";
|
|
137
|
-
import { StreamRunner, type StreamRunnerDeps } from "./stream-runner.js";
|
|
138
|
-
import { setProviderHint } from "./token-counter.js";
|
|
139
|
-
import { firstLine, formatSubagentActivity, toToolResult } from "./tool-utils";
|
|
140
|
-
|
|
141
|
-
// ---------------------------------------------------------------------------
|
|
142
|
-
// Provider implementations
|
|
143
|
-
// ---------------------------------------------------------------------------
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Create a provider factory for the given provider ID using the shared runtime module.
|
|
147
|
-
*/
|
|
148
|
-
function createProvider(providerId: ProviderId, apiKey: string, baseURL?: string): LegacyProvider {
|
|
149
|
-
return createProviderFactory(providerId, { apiKey, baseURL }).factory;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Generate a session title using the Anthropic provider.
|
|
154
|
-
* Kept as a lightweight stub for Phase 0 — title generation ships in Phase 1.
|
|
155
|
-
*/
|
|
156
|
-
function genTitle(
|
|
157
|
-
_provider: LegacyProvider,
|
|
158
|
-
userMessage: string,
|
|
159
|
-
): Promise<{ title: string; modelId: string; usage?: { totalTokens?: number } }> {
|
|
160
|
-
// Phase 0 stub: return a truncated version of the first user message as title.
|
|
161
|
-
// Phase 1 will replace this with a real LLM-based title generation call.
|
|
162
|
-
const title = userMessage.slice(0, 60).trim() || "New session";
|
|
163
|
-
return Promise.resolve({ title, modelId: DEFAULT_MODEL });
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Resolve a model ID to a runnable AI SDK LanguageModel.
|
|
168
|
-
* Uses the Anthropic provider factory created by createProvider().
|
|
169
|
-
*/
|
|
170
|
-
function resolveModelRuntime(provider: LegacyProvider, modelId: string): ResolvedModelRuntime {
|
|
171
|
-
return resolveRuntime(provider, modelId);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const DEFAULT_MODEL = "claude-sonnet-4-6";
|
|
175
|
-
|
|
176
|
-
async function toolSetToBatchTools(_tools: ToolSet): Promise<BatchFunctionTool[]> {
|
|
177
|
-
// Batch API not supported with Anthropic in Phase 0. Phase 1 may add this.
|
|
178
|
-
throw new Error("Batch API not available in Phase 0. Use standard streaming mode.");
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async function createBatch(_opts: BatchClientOptions & { name?: string }): Promise<{ batch_id: string }> {
|
|
182
|
-
throw new Error("Batch API not available in Phase 0. Use standard streaming mode.");
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async function addBatchRequests(
|
|
186
|
-
_opts: BatchClientOptions & { batchId: string; batchRequests: unknown[] },
|
|
187
|
-
): Promise<void> {
|
|
188
|
-
throw new Error("Batch API not available in Phase 0. Use standard streaming mode.");
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async function pollBatchRequestResult(
|
|
192
|
-
_opts: BatchClientOptions & { batchId: string; batchRequestId: string },
|
|
193
|
-
): Promise<unknown> {
|
|
194
|
-
throw new Error("Batch API not available in Phase 0. Use standard streaming mode.");
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function getBatchChatCompletion(_result: unknown): BatchChatCompletionResponse {
|
|
198
|
-
throw new Error("Batch API not available in Phase 0. Use standard streaming mode.");
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function createTools(
|
|
202
|
-
_bash: unknown,
|
|
203
|
-
_provider: LegacyProvider,
|
|
204
|
-
_mode: unknown,
|
|
205
|
-
_opts?: {
|
|
206
|
-
runTask?: (request: TaskRequest, abortSignal?: AbortSignal) => Promise<ToolResult>;
|
|
207
|
-
runDelegation?: (request: TaskRequest, abortSignal?: AbortSignal) => Promise<ToolResult>;
|
|
208
|
-
readDelegation?: (id: string) => Promise<ToolResult>;
|
|
209
|
-
listDelegations?: () => Promise<ToolResult>;
|
|
210
|
-
scheduleManager?: unknown;
|
|
211
|
-
subagents?: unknown[];
|
|
212
|
-
sendTelegramFile?: (filePath: string) => Promise<ToolResult>;
|
|
213
|
-
sessionId?: string;
|
|
214
|
-
modelId?: string;
|
|
215
|
-
},
|
|
216
|
-
): ToolSet {
|
|
217
|
-
return createBuiltinTools(_bash as BashTool, (_mode ?? "agent") as AgentMode, {
|
|
218
|
-
runTask: _opts?.runTask,
|
|
219
|
-
runDelegation: _opts?.runDelegation,
|
|
220
|
-
readDelegation: _opts?.readDelegation,
|
|
221
|
-
listDelegations: _opts?.listDelegations,
|
|
222
|
-
modelId: _opts?.modelId,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// ---------------------------------------------------------------------------
|
|
227
|
-
// END Plan 00-05 provider implementations
|
|
228
|
-
// (Phase 12.3 — `buildVisionUserMessages` was inlined into StreamRunner;
|
|
229
|
-
// vision is an anti-feature per PROJECT.md Out-of-Scope so the helper is gone.)
|
|
230
|
-
// ---------------------------------------------------------------------------
|
|
231
|
-
|
|
232
|
-
// ============================================================================
|
|
233
|
-
// Agent class — fields, constructor, session management, core processing loop
|
|
234
|
-
// ============================================================================
|
|
235
|
-
|
|
236
|
-
export class Agent {
|
|
237
|
-
private provider: LegacyProvider | null = null;
|
|
238
|
-
private providerId: ProviderId = "anthropic";
|
|
239
|
-
private apiKey: string | null = null;
|
|
240
|
-
private baseURL: string | null = null;
|
|
241
|
-
private bash: BashTool;
|
|
242
|
-
private delegations: DelegationManager;
|
|
243
|
-
private schedules: ScheduleManager;
|
|
244
|
-
private sessionStore: SessionStore | null = null;
|
|
245
|
-
private workspace: WorkspaceInfo | null = null;
|
|
246
|
-
private session: SessionInfo | null = null;
|
|
247
|
-
private messages: ModelMessage[] = [];
|
|
248
|
-
private messageSeqs: Array<number | null> = [];
|
|
249
|
-
private abortController: AbortController | null = null;
|
|
250
|
-
private maxToolRounds: number;
|
|
251
|
-
private mode: AgentMode = "agent";
|
|
252
|
-
private modelId: string;
|
|
253
|
-
private maxTokens: number;
|
|
254
|
-
private planContext: string | null = null;
|
|
255
|
-
private subagentStatusListeners = new Set<(status: SubagentStatus | null) => void>();
|
|
256
|
-
private sendTelegramFile: ((filePath: string) => Promise<ToolResult>) | null = null;
|
|
257
|
-
private batchApi = false;
|
|
258
|
-
private sessionStartHookFired = false;
|
|
259
|
-
/** PIL context for current turn — set after runPipeline, cleared after recordUsage. */
|
|
260
|
-
private _pilActive = false;
|
|
261
|
-
private _pilEnrichmentDelta = 0;
|
|
262
|
-
/**
|
|
263
|
-
* Breakdown of the system prompt + messages + tools sent on the last call.
|
|
264
|
-
* Captured immediately before streamText and consumed by recordUsage to
|
|
265
|
-
* attach to the cost-log entry. Cleared after recordUsage so subsequent
|
|
266
|
-
* non-message calls don't reuse stale data.
|
|
267
|
-
*/
|
|
268
|
-
private _lastPromptBreakdown: Record<string, number> | null = null;
|
|
269
|
-
/**
|
|
270
|
-
* Phase O1 — JSON-shape of the providerOptions object on the most
|
|
271
|
-
* recent streamText call. Captured immediately before streamText and
|
|
272
|
-
* consumed by recordUsage; cleared after. Cost-leak forensics surfaces
|
|
273
|
-
* this so we can answer "did this billed call carry store=true?" etc.
|
|
274
|
-
*/
|
|
275
|
-
private _lastProviderOptionsShape: string | null = null;
|
|
276
|
-
/** External abort context from src/index.ts SIGINT handler (TUI-04). */
|
|
277
|
-
private externalAbortContext: import("./abort.js").AbortContext | null = null;
|
|
278
|
-
/** Pending calls log for Pitfall 9 staged-write tracking. */
|
|
279
|
-
private pendingCalls: import("./pending-calls.js").PendingCallsLog | null = null;
|
|
280
|
-
/** Active permission mode — controls which tool calls auto-approve vs require user confirmation. */
|
|
281
|
-
private permissionMode: PermissionMode = "safe";
|
|
282
|
-
/** Flow run init promise — awaited before first message turn. */
|
|
283
|
-
private _flowReady: Promise<void> | null = null;
|
|
284
|
-
/** Active .muonroi-flow/ run ID for this session. */
|
|
285
|
-
private _activeRunId: string | null = null;
|
|
286
|
-
/** Resume digest loaded from active flow run state.md. */
|
|
287
|
-
private _resumeDigest: string | null = null;
|
|
288
|
-
/**
|
|
289
|
-
* Phase 12.1-02: All council state (synthesis/continuation flags, resolver
|
|
290
|
-
* + buffer maps, stats) lives inside CouncilManager. Agent holds one ref.
|
|
291
|
-
*/
|
|
292
|
-
private councilManager: CouncilManager;
|
|
293
|
-
/** Whether compaction already ran during the current turn (prevents double-compact). */
|
|
294
|
-
private _compactedThisTurn = false;
|
|
295
|
-
/** Guard: OAuth provider init runs at most once per Agent instance. */
|
|
296
|
-
private _oauthInitDone = false;
|
|
297
|
-
/** P0 native observation: warning IDs surfaced earlier in this session — sent as intent_context.priorWarningIdsInSession. */
|
|
298
|
-
private _priorWarningIdsInSession = new Set<string>();
|
|
299
|
-
/** EE session guidance: structured warnings accumulated across turns — injected into model context at turn start. Keyed by principle_uuid to deduplicate. */
|
|
300
|
-
private _sessionEEGuidance = new Map<
|
|
301
|
-
string,
|
|
302
|
-
{ toolName: string; message: string; why: string; confidence: number }
|
|
303
|
-
>();
|
|
304
|
-
/** P0 native observation: rolling buffer of assistant reasoning text in current turn — last 200 chars sent as intent_context.assistantReasoningExcerpt. */
|
|
305
|
-
private _turnAssistantReasoning = "";
|
|
306
|
-
/** Per-call correlation id for top-level streamText; set in MessageProcessor, consumed by recordUsage / onFinish llm-done. */
|
|
307
|
-
private _currentCallId = "";
|
|
308
|
-
/** P0 native observation: first 200 chars of the user's current turn — sent as intent_context.userGoalExcerpt to PreToolUse. */
|
|
309
|
-
private _turnUserGoalExcerpt = "";
|
|
310
|
-
/** Compaction statistics tracking count and total tokens saved. */
|
|
311
|
-
private _compactionStats: { count: number; totalSaved: number } = { count: 0, totalSaved: 0 };
|
|
312
|
-
/**
|
|
313
|
-
* Pinned message sequences. A pinned user message is preserved verbatim across
|
|
314
|
-
* compaction — it is re-injected as a system note immediately after the
|
|
315
|
-
* compaction summary, so the model still sees the original wording.
|
|
316
|
-
* V1 only supports user messages (avoids splitting tool-call/result pairs).
|
|
317
|
-
*/
|
|
318
|
-
private _pinnedSeqs = new Set<number>();
|
|
319
|
-
/** One-shot cwd note injected at the start of the next processMessage turn after setCwd(). Cleared after injection. */
|
|
320
|
-
private _pendingCwdNote: string | null = null;
|
|
321
|
-
|
|
322
|
-
// Phase C3: cross-turn tool-output dedup. One instance per session; bumped
|
|
323
|
-
// on each user turn. Lazily initialized so disabled-via-env path stays cheap.
|
|
324
|
-
private _crossTurnDedup: CrossTurnDedup | null = isCrossTurnDedupEnabled() ? new CrossTurnDedup() : null;
|
|
325
|
-
// Phase C4 — input-keyed read-path budget. Complements C3 (output hash) by
|
|
326
|
-
// catching re-reads of files the agent edited between rounds. Disabled
|
|
327
|
-
// when MUONROI_MAX_READS_PER_PATH=0.
|
|
328
|
-
private _readBudget: ReadPathBudget | null = (() => {
|
|
329
|
-
const cap = getReadPathBudgetCap();
|
|
330
|
-
return cap > 0 ? new ReadPathBudget(cap) : null;
|
|
331
|
-
})();
|
|
332
|
-
|
|
333
|
-
constructor(
|
|
334
|
-
apiKey: string | undefined,
|
|
335
|
-
baseURL?: string,
|
|
336
|
-
model?: string,
|
|
337
|
-
maxToolRounds?: number,
|
|
338
|
-
options: AgentOptions = {},
|
|
339
|
-
) {
|
|
340
|
-
this.baseURL = baseURL || null;
|
|
341
|
-
this.bash = new BashTool(process.cwd(), {
|
|
342
|
-
sandboxMode: options.sandboxMode ?? "off",
|
|
343
|
-
sandboxSettings: options.sandboxSettings,
|
|
344
|
-
shellSettings: options.shellSettings ?? getCurrentShellSettings(),
|
|
345
|
-
});
|
|
346
|
-
this.delegations = new DelegationManager(() => this.bash.getCwd());
|
|
347
|
-
// Phase 12.1-02: council state + helpers live in CouncilManager. DI via
|
|
348
|
-
// getter callbacks so the manager reads live Agent state without holding
|
|
349
|
-
// a circular reference to the Agent instance.
|
|
350
|
-
this.councilManager = new CouncilManager({
|
|
351
|
-
getModelId: () => this.modelId,
|
|
352
|
-
getSessionId: () => this.session?.id ?? null,
|
|
353
|
-
hasSessionStore: () => this.sessionStore !== null,
|
|
354
|
-
getMessages: () => this.messages,
|
|
355
|
-
getBash: () => this.bash,
|
|
356
|
-
getMode: () => this.mode,
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
const initialMode: AgentMode = "agent";
|
|
360
|
-
this.modelId = normalizeModelId(model || getCurrentModel(initialMode));
|
|
361
|
-
this.providerId = detectProviderForModel(this.modelId);
|
|
362
|
-
setProviderHint(this.providerId);
|
|
363
|
-
if (apiKey) {
|
|
364
|
-
this.setApiKey(apiKey, baseURL);
|
|
365
|
-
}
|
|
366
|
-
this.schedules = new ScheduleManager(
|
|
367
|
-
() => this.bash.getCwd(),
|
|
368
|
-
() => this.modelId,
|
|
369
|
-
);
|
|
370
|
-
this.maxToolRounds = maxToolRounds || MAX_TOOL_ROUNDS;
|
|
371
|
-
const envMax = Number(process.env.MUONROI_MAX_TOKENS);
|
|
372
|
-
this.maxTokens = Number.isFinite(envMax) && envMax > 0 ? envMax : 16_384;
|
|
373
|
-
this.batchApi = options.batchApi ?? false;
|
|
374
|
-
// TUI-04: wire external abort context and pending calls log if provided.
|
|
375
|
-
this.externalAbortContext = options.abortContext ?? null;
|
|
376
|
-
this.pendingCalls = options.pendingCalls ?? null;
|
|
377
|
-
this.permissionMode = options.permissionMode ?? "safe";
|
|
378
|
-
ensureDefaultMcpServers();
|
|
379
|
-
|
|
380
|
-
if (options.persistSession !== false) {
|
|
381
|
-
this.sessionStore = new SessionStore(this.bash.getCwd());
|
|
382
|
-
this.workspace = this.sessionStore.getWorkspace();
|
|
383
|
-
this.session = this.sessionStore.openSession(options.session, this.modelId, this.mode, this.bash.getCwd());
|
|
384
|
-
this.mode = this.session.mode;
|
|
385
|
-
const transcript = loadTranscriptState(this.session.id);
|
|
386
|
-
this.messages = transcript.messages;
|
|
387
|
-
this.messageSeqs = transcript.seqs;
|
|
388
|
-
this.sessionStore.setModel(this.session.id, this.modelId);
|
|
389
|
-
|
|
390
|
-
// Flow run setup — fire-and-forget, awaited before first message turn.
|
|
391
|
-
this._flowReady = this._initFlow();
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Initialize .muonroi-flow/ run for this session.
|
|
397
|
-
* Fail-open: any error sets _activeRunId = null silently.
|
|
398
|
-
*/
|
|
399
|
-
private async _initFlow(): Promise<void> {
|
|
400
|
-
await bootstrapEEClient().catch(() => {});
|
|
401
|
-
try {
|
|
402
|
-
const flowDir = await ensureFlowDir(this.bash.getCwd());
|
|
403
|
-
const existing = await getActiveRunId(flowDir);
|
|
404
|
-
if (existing) {
|
|
405
|
-
this._activeRunId = existing;
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
const run = await createRun(flowDir);
|
|
409
|
-
await setActiveRunId(flowDir, run.id);
|
|
410
|
-
this._activeRunId = run.id;
|
|
411
|
-
} catch {
|
|
412
|
-
this._activeRunId = null;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// Load resume digest for PIL context injection (fail-open).
|
|
416
|
-
try {
|
|
417
|
-
this._resumeDigest = await loadFlowResumeDigest(this.bash.getCwd());
|
|
418
|
-
} catch {
|
|
419
|
-
this._resumeDigest = null;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
getModel(): string {
|
|
424
|
-
return this.modelId;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
getActiveRunId(): string | null {
|
|
428
|
-
return this._activeRunId;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
setModel(model: string): void {
|
|
432
|
-
this.modelId = normalizeModelId(model);
|
|
433
|
-
const newProviderId = detectProviderForModel(this.modelId);
|
|
434
|
-
if (newProviderId !== this.providerId && this.apiKey) {
|
|
435
|
-
this.providerId = newProviderId;
|
|
436
|
-
setProviderHint(this.providerId);
|
|
437
|
-
const effectiveBaseURL =
|
|
438
|
-
this.providerId !== "anthropic" && this.baseURL === apiBaseFor("anthropic")
|
|
439
|
-
? undefined
|
|
440
|
-
: (this.baseURL ?? undefined);
|
|
441
|
-
this.provider = createProvider(this.providerId, this.apiKey, effectiveBaseURL);
|
|
442
|
-
}
|
|
443
|
-
if (this.sessionStore && this.session) {
|
|
444
|
-
this.sessionStore.setModel(this.session.id, this.modelId);
|
|
445
|
-
this.session = this.sessionStore.getRequiredSession(this.session.id);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
getMode(): AgentMode {
|
|
450
|
-
return this.mode;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
getSandboxMode(): SandboxMode {
|
|
454
|
-
return this.bash.getSandboxMode();
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
setSandboxMode(mode: SandboxMode): void {
|
|
458
|
-
this.bash.setSandboxMode(mode);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
getSandboxSettings(): SandboxSettings {
|
|
462
|
-
return this.bash.getSandboxSettings();
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
setSandboxSettings(settings: SandboxSettings): void {
|
|
466
|
-
this.bash.setSandboxSettings(settings);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
setMode(mode: AgentMode): void {
|
|
470
|
-
if (mode !== this.mode) {
|
|
471
|
-
this.mode = mode;
|
|
472
|
-
const modeModel = getModeSpecificModel(mode);
|
|
473
|
-
if (modeModel) {
|
|
474
|
-
this.modelId = normalizeModelId(modeModel);
|
|
475
|
-
}
|
|
476
|
-
if (this.sessionStore && this.session) {
|
|
477
|
-
this.sessionStore.setMode(this.session.id, mode);
|
|
478
|
-
this.sessionStore.setModel(this.session.id, this.modelId);
|
|
479
|
-
this.session = this.sessionStore.getRequiredSession(this.session.id);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
setPlanContext(ctx: string | null): void {
|
|
485
|
-
this.planContext = ctx;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
setSendTelegramFile(fn: ((filePath: string) => Promise<ToolResult>) | null): void {
|
|
489
|
-
this.sendTelegramFile = fn;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
hasApiKey(): boolean {
|
|
493
|
-
return !!this.apiKey;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
setApiKey(apiKey: string, baseURL?: string): void {
|
|
497
|
-
this.apiKey = apiKey;
|
|
498
|
-
this.baseURL = baseURL || null;
|
|
499
|
-
// Only pass baseURL to provider factory if it's an explicit override,
|
|
500
|
-
// not the default Anthropic URL (which would break non-Anthropic providers).
|
|
501
|
-
const effectiveBaseURL =
|
|
502
|
-
this.providerId !== "anthropic" && baseURL === apiBaseFor("anthropic") ? undefined : baseURL;
|
|
503
|
-
this.provider = createProvider(this.providerId, apiKey, effectiveBaseURL);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
setProviderAndKey(providerId: ProviderId, apiKey: string, baseURL?: string): void {
|
|
507
|
-
this.providerId = providerId;
|
|
508
|
-
setProviderHint(this.providerId);
|
|
509
|
-
this.setApiKey(apiKey, baseURL);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
getProviderId(): ProviderId {
|
|
513
|
-
return this.providerId;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
getCwd(): string {
|
|
517
|
-
return this.bash.getCwd();
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
setCwd(dir: string): void {
|
|
521
|
-
this.bash.setCwd(dir);
|
|
522
|
-
this._pendingCwdNote = `(system: working directory has been changed to ${dir} — subsequent shell commands run from there; do NOT cd to that path again)`;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
getMessages(): ModelMessage[] {
|
|
526
|
-
return this.messages;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
async listSchedules(): Promise<StoredSchedule[]> {
|
|
530
|
-
return this.schedules.list();
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
async removeSchedule(id: string): Promise<string> {
|
|
534
|
-
const removed = await this.schedules.remove(id);
|
|
535
|
-
return removed ? `Removed schedule "${removed.name}".` : `Schedule "${id}" not found.`;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
async getScheduleDaemonStatus(): Promise<ScheduleDaemonStatus> {
|
|
539
|
-
return this.schedules.getDaemonStatus();
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
getContextStats(
|
|
543
|
-
contextWindow: number,
|
|
544
|
-
inFlightText = "",
|
|
545
|
-
): {
|
|
546
|
-
contextWindow: number;
|
|
547
|
-
usedTokens: number;
|
|
548
|
-
remainingTokens: number;
|
|
549
|
-
ratioUsed: number;
|
|
550
|
-
ratioRemaining: number;
|
|
551
|
-
} {
|
|
552
|
-
const system = buildSystemPrompt(
|
|
553
|
-
this.bash.getCwd(),
|
|
554
|
-
this.mode,
|
|
555
|
-
this.bash.getSandboxMode(),
|
|
556
|
-
this.planContext,
|
|
557
|
-
undefined,
|
|
558
|
-
this.bash.getSandboxSettings(),
|
|
559
|
-
this.providerId,
|
|
560
|
-
);
|
|
561
|
-
const usedTokens = Math.min(contextWindow, estimateConversationTokens(system, this.messages, inFlightText));
|
|
562
|
-
const remainingTokens = Math.max(0, contextWindow - usedTokens);
|
|
563
|
-
|
|
564
|
-
return {
|
|
565
|
-
contextWindow,
|
|
566
|
-
usedTokens,
|
|
567
|
-
remainingTokens,
|
|
568
|
-
ratioUsed: usedTokens / contextWindow,
|
|
569
|
-
ratioRemaining: remainingTokens / contextWindow,
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
async generateTitle(userMessage: string): Promise<string> {
|
|
574
|
-
const provider = this.provider;
|
|
575
|
-
if (!provider) {
|
|
576
|
-
return "New session";
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
const generated = await genTitle(provider, userMessage);
|
|
580
|
-
this.recordUsage(generated.usage, "title", generated.modelId);
|
|
581
|
-
if (this.sessionStore && this.session && !this.session.title && generated.title) {
|
|
582
|
-
this.sessionStore.setTitle(this.session.id, generated.title);
|
|
583
|
-
this.session = this.sessionStore.getRequiredSession(this.session.id);
|
|
584
|
-
}
|
|
585
|
-
return generated.title;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
async askSideQuestion(question: string, signal?: AbortSignal): Promise<SideQuestionResult> {
|
|
589
|
-
if (!this.provider) {
|
|
590
|
-
return { response: "No API key configured." };
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
const contextParts: string[] = [];
|
|
594
|
-
let charBudget = 2000;
|
|
595
|
-
for (let i = this.messages.length - 1; i >= 0 && charBudget > 0; i--) {
|
|
596
|
-
const msg = this.messages[i];
|
|
597
|
-
if (msg.role !== "user" && msg.role !== "assistant") continue;
|
|
598
|
-
const text =
|
|
599
|
-
typeof msg.content === "string"
|
|
600
|
-
? msg.content
|
|
601
|
-
: Array.isArray(msg.content)
|
|
602
|
-
? msg.content
|
|
603
|
-
.filter((p: { type: string }) => p.type === "text")
|
|
604
|
-
.map((p: { type: string; text?: string }) => p.text ?? "")
|
|
605
|
-
.join("")
|
|
606
|
-
: "";
|
|
607
|
-
if (!text) continue;
|
|
608
|
-
const snippet = text.length > 400 ? `${text.slice(0, 400)}…` : text;
|
|
609
|
-
contextParts.unshift(`[${msg.role}]: ${snippet}`);
|
|
610
|
-
charBudget -= snippet.length;
|
|
611
|
-
}
|
|
612
|
-
const conversationContext = contextParts.join("\n\n");
|
|
613
|
-
|
|
614
|
-
const result = await runSideQuestion(question, this.provider, this.modelId, conversationContext, signal);
|
|
615
|
-
this.recordUsage(result.usage, "other");
|
|
616
|
-
return result;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
abort(): void {
|
|
620
|
-
this.abortController?.abort();
|
|
621
|
-
this.emitSubagentStatus(null);
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
async cleanup(): Promise<void> {
|
|
625
|
-
await Promise.allSettled([
|
|
626
|
-
this.bash.cleanup(),
|
|
627
|
-
shutdownWorkspaceLspManager(this.bash.getCwd()),
|
|
628
|
-
extractSession(this.messages, this.bash.getCwd(), "cli-exit", this.getSessionId()),
|
|
629
|
-
]);
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
respondToToolApproval(approvalId: string, approved: boolean): void {
|
|
633
|
-
const toolApprovalResponse: ModelMessage = {
|
|
634
|
-
role: "tool",
|
|
635
|
-
content: [
|
|
636
|
-
{
|
|
637
|
-
type: "tool-approval-response" as const,
|
|
638
|
-
approvalId,
|
|
639
|
-
approved,
|
|
640
|
-
},
|
|
641
|
-
],
|
|
642
|
-
};
|
|
643
|
-
this.messages.push(toolApprovalResponse);
|
|
644
|
-
this.messageSeqs.push(null);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
async clearHistory(): Promise<void> {
|
|
648
|
-
// D-09: Extract messages accumulated since last clear BEFORE reset
|
|
649
|
-
await extractSession(this.messages, this.bash.getCwd(), "cli-clear", this.getSessionId()).catch(() => {}); // D-05: redundant safety — extractSession already swallows
|
|
650
|
-
this.startNewSession();
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
startNewSession(): SessionSnapshot | null {
|
|
654
|
-
if (this.sessionStartHookFired) {
|
|
655
|
-
const endInput: SessionEndHookInput = {
|
|
656
|
-
hook_event_name: "SessionEnd",
|
|
657
|
-
session_id: this.session?.id,
|
|
658
|
-
cwd: this.bash.getCwd(),
|
|
659
|
-
};
|
|
660
|
-
this.fireHook(endInput).catch(() => {});
|
|
661
|
-
this.sessionStartHookFired = false;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
// Reset token counters, cost, and compaction state for the new session
|
|
665
|
-
statusBarStore.setState({
|
|
666
|
-
in_tokens: 0,
|
|
667
|
-
out_tokens: 0,
|
|
668
|
-
cache_read_tokens: 0,
|
|
669
|
-
cache_creation_tokens: 0,
|
|
670
|
-
session_usd: 0,
|
|
671
|
-
ctx_tokens: 0,
|
|
672
|
-
compaction_summary: undefined,
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
this._compactionStats = { count: 0, totalSaved: 0 };
|
|
676
|
-
this._pinnedSeqs.clear();
|
|
677
|
-
|
|
678
|
-
if (!this.sessionStore) {
|
|
679
|
-
this.messages = [];
|
|
680
|
-
this.messageSeqs = [];
|
|
681
|
-
return null;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
this.sessionStore = new SessionStore(this.bash.getCwd());
|
|
685
|
-
this.workspace = this.sessionStore.getWorkspace();
|
|
686
|
-
this.session = this.sessionStore.createSession(this.modelId, this.mode, this.bash.getCwd());
|
|
687
|
-
this.messages = [];
|
|
688
|
-
this.messageSeqs = [];
|
|
689
|
-
return this.getSessionSnapshot();
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
getSessionInfo(): SessionInfo | null {
|
|
693
|
-
return this.session;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
getSessionId(): string | null {
|
|
697
|
-
return this.session?.id || null;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
getSessionTitle(): string | null {
|
|
701
|
-
return this.session?.title || null;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
getCompactionStats(): { count: number; totalSaved: number } {
|
|
705
|
-
return { ...this._compactionStats };
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Pin a user message by its sequence number. Pinned messages survive
|
|
710
|
-
* compaction verbatim — re-injected as a system note after the summary.
|
|
711
|
-
* Returns true if the message was found, is a user message, and got pinned.
|
|
712
|
-
*/
|
|
713
|
-
pinMessageBySeq(seq: number): boolean {
|
|
714
|
-
const idx = this.messageSeqs.indexOf(seq);
|
|
715
|
-
if (idx < 0) return false;
|
|
716
|
-
if (this.messages[idx]?.role !== "user") return false;
|
|
717
|
-
this._pinnedSeqs.add(seq);
|
|
718
|
-
return true;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
/** Pin the most recent user message in the live conversation. Returns its seq, or null. */
|
|
722
|
-
pinLastUserMessage(): number | null {
|
|
723
|
-
for (let i = this.messages.length - 1; i >= 0; i--) {
|
|
724
|
-
if (this.messages[i]?.role !== "user") continue;
|
|
725
|
-
const seq = this.messageSeqs[i];
|
|
726
|
-
if (typeof seq === "number") {
|
|
727
|
-
this._pinnedSeqs.add(seq);
|
|
728
|
-
return seq;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
return null;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
unpinMessageBySeq(seq: number): boolean {
|
|
735
|
-
return this._pinnedSeqs.delete(seq);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
getPinnedSeqs(): number[] {
|
|
739
|
-
return [...this._pinnedSeqs].sort((a, b) => a - b);
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
getChatEntries(): ChatEntry[] {
|
|
743
|
-
if (!this.session) return [];
|
|
744
|
-
return buildChatEntries(this.session.id);
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
getSessionSnapshot(): SessionSnapshot | null {
|
|
748
|
-
if (!this.session || !this.workspace) return null;
|
|
749
|
-
return {
|
|
750
|
-
workspace: this.workspace,
|
|
751
|
-
session: this.session,
|
|
752
|
-
messages: loadTranscript(this.session.id),
|
|
753
|
-
entries: buildChatEntries(this.session.id),
|
|
754
|
-
totalTokens: getSessionTotalTokens(this.session.id),
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
onSubagentStatus(listener: (status: SubagentStatus | null) => void): () => void {
|
|
759
|
-
this.subagentStatusListeners.add(listener);
|
|
760
|
-
return () => {
|
|
761
|
-
this.subagentStatusListeners.delete(listener);
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
private emitSubagentStatus(status: SubagentStatus | null): void {
|
|
766
|
-
for (const listener of this.subagentStatusListeners) {
|
|
767
|
-
listener(status);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
private discardAbortedTurn(userMessage: ModelMessage): void {
|
|
772
|
-
const idx = this.messages.lastIndexOf(userMessage);
|
|
773
|
-
if (idx >= 0) {
|
|
774
|
-
// Keep the user message but add a stub assistant response so the
|
|
775
|
-
// conversation remains valid for follow-up messages after ESC.
|
|
776
|
-
const alreadyHasResponse = idx < this.messages.length - 1 && this.messages[idx + 1]?.role === "assistant";
|
|
777
|
-
if (!alreadyHasResponse) {
|
|
778
|
-
this.messages.splice(idx + 1, 0, { role: "assistant", content: "[Interrupted]" });
|
|
779
|
-
this.messageSeqs.splice(idx + 1, 0, null);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
private recordUsage(
|
|
785
|
-
usage?: {
|
|
786
|
-
totalTokens?: number;
|
|
787
|
-
inputTokens?: number;
|
|
788
|
-
outputTokens?: number;
|
|
789
|
-
cacheReadTokens?: number;
|
|
790
|
-
cacheCreationTokens?: number;
|
|
791
|
-
},
|
|
792
|
-
source: UsageSource = "message",
|
|
793
|
-
model = this.modelId,
|
|
794
|
-
): void {
|
|
795
|
-
if (!usage) return;
|
|
796
|
-
if (this.session) {
|
|
797
|
-
const pilActive = source === "message" ? this._pilActive : false;
|
|
798
|
-
const enrichmentDelta = source === "message" ? this._pilEnrichmentDelta : 0;
|
|
799
|
-
// Attribute usage to the most recent persisted message — this lets
|
|
800
|
-
// per-prompt cost analysis work (was null hardcoded → impossible).
|
|
801
|
-
const lastSeq = lastPersistedSeq(this.messageSeqs);
|
|
802
|
-
// Phase O1 — providerOptions shape (types only, no values) attached
|
|
803
|
-
// to every usage event so post-mortem can answer "what provider
|
|
804
|
-
// options did this billed call carry?". Cleared below for "message"
|
|
805
|
-
// sources so non-message calls don't reuse stale data.
|
|
806
|
-
const providerOptionsShape = this._lastProviderOptionsShape;
|
|
807
|
-
recordUsageEvent(
|
|
808
|
-
this.session.id,
|
|
809
|
-
source,
|
|
810
|
-
model,
|
|
811
|
-
usage,
|
|
812
|
-
lastSeq,
|
|
813
|
-
pilActive,
|
|
814
|
-
enrichmentDelta,
|
|
815
|
-
providerOptionsShape,
|
|
816
|
-
);
|
|
817
|
-
if (source === "message") {
|
|
818
|
-
this._pilActive = false;
|
|
819
|
-
this._pilEnrichmentDelta = 0;
|
|
820
|
-
this._lastProviderOptionsShape = null;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
// Phase D — surfaced for harness E2E verification. Mirror the recorded usage
|
|
824
|
-
// event onto the agent-mode sidechannel so spec processes can assert on
|
|
825
|
-
// cacheReadTokens / cacheCreationTokens normalization without poking at the
|
|
826
|
-
// child's sqlite. Best-effort, only fires when agent-mode runtime is set.
|
|
827
|
-
try {
|
|
828
|
-
const rt = (globalThis as Record<string, unknown>).__muonroiAgentRuntime as
|
|
829
|
-
| { emitEvent?: (e: unknown) => void }
|
|
830
|
-
| undefined;
|
|
831
|
-
if (rt?.emitEvent) {
|
|
832
|
-
const lastSeqForEvent = this.session ? lastPersistedSeq(this.messageSeqs) : null;
|
|
833
|
-
rt.emitEvent({
|
|
834
|
-
t: "event",
|
|
835
|
-
kind: "usage",
|
|
836
|
-
source,
|
|
837
|
-
model,
|
|
838
|
-
inputTokens: usage.inputTokens,
|
|
839
|
-
outputTokens: usage.outputTokens,
|
|
840
|
-
cacheReadTokens: usage.cacheReadTokens,
|
|
841
|
-
cacheCreationTokens: usage.cacheCreationTokens,
|
|
842
|
-
messageSeq: lastSeqForEvent,
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
} catch {
|
|
846
|
-
// best-effort: do not let sidechannel failures interrupt usage recording
|
|
847
|
-
}
|
|
848
|
-
// Update status bar token counters + provider/model + cache metrics + cost
|
|
849
|
-
const prev = statusBarStore.getState();
|
|
850
|
-
const info = getModelInfo(model);
|
|
851
|
-
const totalInput = usage.inputTokens ?? 0;
|
|
852
|
-
const cacheRead = usage.cacheReadTokens ?? 0;
|
|
853
|
-
const cacheCreate = usage.cacheCreationTokens ?? 0;
|
|
854
|
-
const output = usage.outputTokens ?? 0;
|
|
855
|
-
const priceIn = info?.inputPrice ?? 0;
|
|
856
|
-
const priceCached = info?.cachedInputPrice ?? priceIn * 0.1;
|
|
857
|
-
const priceOut = info?.outputPrice ?? 0;
|
|
858
|
-
// API inputTokens includes cacheRead — subtract to get non-cached portion
|
|
859
|
-
const nonCachedInput = Math.max(0, totalInput - cacheRead - cacheCreate);
|
|
860
|
-
const turnCostMicros =
|
|
861
|
-
nonCachedInput * priceIn + cacheRead * priceCached + cacheCreate * priceIn + output * priceOut;
|
|
862
|
-
statusBarStore.setState({
|
|
863
|
-
in_tokens: prev.in_tokens + totalInput,
|
|
864
|
-
out_tokens: prev.out_tokens + output,
|
|
865
|
-
cache_read_tokens: (prev.cache_read_tokens ?? 0) + cacheRead,
|
|
866
|
-
cache_creation_tokens: (prev.cache_creation_tokens ?? 0) + cacheCreate,
|
|
867
|
-
session_usd: prev.session_usd + turnCostMicros / 1_000_000,
|
|
868
|
-
provider: this.providerId,
|
|
869
|
-
model,
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
// Append to cost-log JSONL so `usage report --by callsite` can surface
|
|
873
|
-
// where orchestrator/task/title traffic is actually spending.
|
|
874
|
-
// Best-effort: failures inside appendCostLog are swallowed (see cost-log.ts).
|
|
875
|
-
const breakdown = source === "message" ? (this._lastPromptBreakdown ?? undefined) : undefined;
|
|
876
|
-
appendCostLog({
|
|
877
|
-
ts: Date.now(),
|
|
878
|
-
provider: this.providerId,
|
|
879
|
-
model,
|
|
880
|
-
estimatedUsd: turnCostMicros / 1_000_000,
|
|
881
|
-
callsite: `orchestrator.${source}`,
|
|
882
|
-
phase: source,
|
|
883
|
-
actualInputTokens: totalInput,
|
|
884
|
-
actualOutputTokens: output,
|
|
885
|
-
cachedInputTokens: cacheRead,
|
|
886
|
-
systemChars: breakdown?.systemChars,
|
|
887
|
-
promptChars: breakdown?.messagesChars,
|
|
888
|
-
breakdown,
|
|
889
|
-
}).catch(() => undefined);
|
|
890
|
-
// Don't clear breakdown — onStepFinish fires recordUsage per step within
|
|
891
|
-
// the same streamText call, and they all share the same prompt structure.
|
|
892
|
-
// It is overwritten on the next streamText setup, which is the right scope.
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
async consumeBackgroundNotifications(): Promise<string[]> {
|
|
896
|
-
try {
|
|
897
|
-
const notifications = await this.delegations.consumeNotifications();
|
|
898
|
-
for (const notification of notifications) {
|
|
899
|
-
this.messages.push({ role: "system", content: notification.message });
|
|
900
|
-
let seq: number | null = null;
|
|
901
|
-
if (this.session) {
|
|
902
|
-
seq = appendSystemMessage(this.session.id, notification.message);
|
|
903
|
-
}
|
|
904
|
-
this.messageSeqs.push(seq);
|
|
905
|
-
|
|
906
|
-
const notifInput: NotificationHookInput = {
|
|
907
|
-
hook_event_name: "Notification",
|
|
908
|
-
message: notification.message,
|
|
909
|
-
session_id: this.session?.id,
|
|
910
|
-
cwd: this.bash.getCwd(),
|
|
911
|
-
};
|
|
912
|
-
this.fireHook(notifInput).catch(() => {});
|
|
913
|
-
}
|
|
914
|
-
return notifications.map((notification) => notification.message);
|
|
915
|
-
} catch {
|
|
916
|
-
return [];
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
private getBatchClientOptions(signal?: AbortSignal): BatchClientOptions {
|
|
921
|
-
if (!this.apiKey) {
|
|
922
|
-
throw new Error("API key required. Add an API key to continue.");
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
return {
|
|
926
|
-
apiKey: this.apiKey,
|
|
927
|
-
baseURL: this.baseURL ?? undefined,
|
|
928
|
-
signal,
|
|
929
|
-
};
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
private async executeBatchToolCall(
|
|
933
|
-
tools: ToolSet,
|
|
934
|
-
toolCall: ToolCall,
|
|
935
|
-
messages: ModelMessage[],
|
|
936
|
-
signal?: AbortSignal,
|
|
937
|
-
): Promise<{ input: unknown; result: ToolResult }> {
|
|
938
|
-
const tool = tools[toolCall.function.name];
|
|
939
|
-
if (!tool || tool.type === "provider" || typeof tool.execute !== "function") {
|
|
940
|
-
return {
|
|
941
|
-
input: parseToolArgumentsOrRaw(toolCall.function.arguments),
|
|
942
|
-
result: {
|
|
943
|
-
success: false,
|
|
944
|
-
output: `Tool "${toolCall.function.name}" is unavailable in batch mode.`,
|
|
945
|
-
},
|
|
946
|
-
};
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
let parsedInput: unknown;
|
|
950
|
-
try {
|
|
951
|
-
parsedInput = toolCall.function.arguments.trim() ? JSON.parse(toolCall.function.arguments) : {};
|
|
952
|
-
} catch (error) {
|
|
953
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
954
|
-
return {
|
|
955
|
-
input: toolCall.function.arguments,
|
|
956
|
-
result: {
|
|
957
|
-
success: false,
|
|
958
|
-
output: `Tool "${toolCall.function.name}" received invalid JSON arguments: ${message}`,
|
|
959
|
-
},
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
try {
|
|
964
|
-
const output = await tool.execute(parsedInput as never, {
|
|
965
|
-
toolCallId: toolCall.id,
|
|
966
|
-
messages,
|
|
967
|
-
abortSignal: signal,
|
|
968
|
-
});
|
|
969
|
-
return {
|
|
970
|
-
input: parsedInput,
|
|
971
|
-
result: toToolResult(output),
|
|
972
|
-
};
|
|
973
|
-
} catch (error) {
|
|
974
|
-
if (signal?.aborted) {
|
|
975
|
-
throw error;
|
|
976
|
-
}
|
|
977
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
978
|
-
return {
|
|
979
|
-
input: parsedInput,
|
|
980
|
-
result: {
|
|
981
|
-
success: false,
|
|
982
|
-
output: `Tool "${toolCall.function.name}" failed: ${message}`,
|
|
983
|
-
},
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
private async runTaskRequestBatch(args: {
|
|
989
|
-
request: TaskRequest;
|
|
990
|
-
childMessages: ModelMessage[];
|
|
991
|
-
childSystem: string;
|
|
992
|
-
childRuntime: ReturnType<typeof resolveModelRuntime>;
|
|
993
|
-
childTools: ToolSet;
|
|
994
|
-
maxSteps: number;
|
|
995
|
-
initialDetail: string;
|
|
996
|
-
onActivity?: (detail: string) => void;
|
|
997
|
-
signal?: AbortSignal;
|
|
998
|
-
}): Promise<ToolResult> {
|
|
999
|
-
const {
|
|
1000
|
-
request,
|
|
1001
|
-
childMessages,
|
|
1002
|
-
childSystem,
|
|
1003
|
-
childRuntime,
|
|
1004
|
-
childTools,
|
|
1005
|
-
maxSteps,
|
|
1006
|
-
initialDetail,
|
|
1007
|
-
onActivity,
|
|
1008
|
-
signal,
|
|
1009
|
-
} = args;
|
|
1010
|
-
|
|
1011
|
-
const childCaps = getProviderCapabilities(childRuntime.modelInfo?.provider ?? "anthropic");
|
|
1012
|
-
if (childCaps.usesResponsesAPI(childRuntime.modelInfo)) {
|
|
1013
|
-
throw new Error("Batch mode currently supports chat-completions models only.");
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
const batchTools = !childCaps.supportsClientTools(childRuntime.modelInfo)
|
|
1017
|
-
? []
|
|
1018
|
-
: await toolSetToBatchTools(childTools);
|
|
1019
|
-
const batch = await createBatch({
|
|
1020
|
-
...this.getBatchClientOptions(signal),
|
|
1021
|
-
name: buildBatchName(`task-${request.agent}`, request.description),
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
const turnMessages: ModelMessage[] = [];
|
|
1025
|
-
const totalUsage: ProcessMessageUsage = {};
|
|
1026
|
-
let assistantText = "";
|
|
1027
|
-
let lastActivity = initialDetail;
|
|
1028
|
-
|
|
1029
|
-
for (let round = 0; round < maxSteps; round++) {
|
|
1030
|
-
const batchRequestId = `task-${Date.now()}-${round + 1}`;
|
|
1031
|
-
await addBatchRequests({
|
|
1032
|
-
...this.getBatchClientOptions(signal),
|
|
1033
|
-
batchId: batch.batch_id,
|
|
1034
|
-
batchRequests: [
|
|
1035
|
-
{
|
|
1036
|
-
batch_request_id: batchRequestId,
|
|
1037
|
-
batch_request: {
|
|
1038
|
-
chat_get_completion: buildBatchChatCompletionRequest({
|
|
1039
|
-
modelId: childRuntime.modelId,
|
|
1040
|
-
system: childSystem,
|
|
1041
|
-
messages: [...childMessages, ...turnMessages],
|
|
1042
|
-
temperature: request.agent === "explore" ? 0.2 : 0.5,
|
|
1043
|
-
maxOutputTokens: !childCaps.acceptsParam("maxOutputTokens", childRuntime.modelInfo)
|
|
1044
|
-
? undefined
|
|
1045
|
-
: Math.min(this.maxTokens, 8_192),
|
|
1046
|
-
reasoningEffort: childRuntime.providerOptions?.xai.reasoningEffort,
|
|
1047
|
-
tools: batchTools,
|
|
1048
|
-
}),
|
|
1049
|
-
},
|
|
1050
|
-
},
|
|
1051
|
-
],
|
|
1052
|
-
});
|
|
1053
|
-
|
|
1054
|
-
const result = await pollBatchRequestResult({
|
|
1055
|
-
...this.getBatchClientOptions(signal),
|
|
1056
|
-
batchId: batch.batch_id,
|
|
1057
|
-
batchRequestId,
|
|
1058
|
-
});
|
|
1059
|
-
const response = getBatchChatCompletion(result);
|
|
1060
|
-
accumulateUsage(totalUsage, getBatchUsage(response));
|
|
1061
|
-
|
|
1062
|
-
const choice = response.choices[0];
|
|
1063
|
-
if (!choice) {
|
|
1064
|
-
throw new Error("Batch response did not contain any choices.");
|
|
1065
|
-
}
|
|
1066
|
-
const content = choice?.message.content ?? "";
|
|
1067
|
-
if (content) {
|
|
1068
|
-
assistantText += content;
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
const requestMessages = [...childMessages, ...turnMessages];
|
|
1072
|
-
const toolCalls = (choice?.message.tool_calls ?? []).map(toLocalToolCall);
|
|
1073
|
-
const assistantMessage = buildAssistantBatchMessage(content, toolCalls);
|
|
1074
|
-
if (assistantMessage) {
|
|
1075
|
-
turnMessages.push(assistantMessage);
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
if (toolCalls.length === 0) {
|
|
1079
|
-
if (hasUsage(totalUsage)) {
|
|
1080
|
-
this.recordUsage(totalUsage, "task", childRuntime.modelId);
|
|
1081
|
-
}
|
|
1082
|
-
const output = assistantText.trim() || `Task completed. Last action: ${lastActivity}`;
|
|
1083
|
-
return {
|
|
1084
|
-
success: true,
|
|
1085
|
-
output,
|
|
1086
|
-
task: {
|
|
1087
|
-
agent: request.agent,
|
|
1088
|
-
description: request.description,
|
|
1089
|
-
summary: firstLine(output),
|
|
1090
|
-
activity: lastActivity,
|
|
1091
|
-
},
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
const toolParts: ExecutedBatchTool[] = [];
|
|
1096
|
-
for (const toolCall of toolCalls) {
|
|
1097
|
-
const nextActivity = formatSubagentActivity(
|
|
1098
|
-
toolCall.function.name,
|
|
1099
|
-
parseToolArgumentsOrRaw(toolCall.function.arguments),
|
|
1100
|
-
);
|
|
1101
|
-
lastActivity = nextActivity;
|
|
1102
|
-
onActivity?.(nextActivity);
|
|
1103
|
-
|
|
1104
|
-
const executed = await this.executeBatchToolCall(childTools, toolCall, requestMessages, signal);
|
|
1105
|
-
toolParts.push({
|
|
1106
|
-
toolCall,
|
|
1107
|
-
input: executed.input,
|
|
1108
|
-
toolResult: executed.result,
|
|
1109
|
-
});
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
const toolMessage = buildToolBatchMessage(toolParts);
|
|
1113
|
-
if (toolMessage) {
|
|
1114
|
-
turnMessages.push(toolMessage);
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
if (hasUsage(totalUsage)) {
|
|
1119
|
-
this.recordUsage(totalUsage, "task", childRuntime.modelId);
|
|
1120
|
-
}
|
|
1121
|
-
const output = assistantText.trim() || `Task stopped after ${maxSteps} batch rounds. Last action: ${lastActivity}`;
|
|
1122
|
-
return {
|
|
1123
|
-
success: false,
|
|
1124
|
-
output,
|
|
1125
|
-
task: {
|
|
1126
|
-
agent: request.agent,
|
|
1127
|
-
description: request.description,
|
|
1128
|
-
summary: output,
|
|
1129
|
-
activity: lastActivity,
|
|
1130
|
-
},
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
/**
|
|
1135
|
-
* Run a sub-agent task by spawning a child `streamText` session.
|
|
1136
|
-
*
|
|
1137
|
-
* Phase 12.3 — body extracted to `StreamRunner` (`./stream-runner.ts`).
|
|
1138
|
-
* This method now builds the DI dep set and delegates to
|
|
1139
|
-
* `StreamRunner.run()`. Public signature is unchanged so all callers
|
|
1140
|
-
* (`runTask`, `tools/registry`, batch path, council path) work as before.
|
|
1141
|
-
*/
|
|
1142
|
-
async runTaskRequest(
|
|
1143
|
-
request: TaskRequest,
|
|
1144
|
-
onActivity?: (detail: string) => void,
|
|
1145
|
-
abortSignal?: AbortSignal,
|
|
1146
|
-
): Promise<ToolResult> {
|
|
1147
|
-
const provider = this.requireProvider();
|
|
1148
|
-
const deps: StreamRunnerDeps = {
|
|
1149
|
-
getProvider: () => provider,
|
|
1150
|
-
resolveModelForTask: (task) => this._resolveModelForTask(task),
|
|
1151
|
-
getModelId: () => this.modelId,
|
|
1152
|
-
getProviderId: () => this.providerId,
|
|
1153
|
-
getBash: () => this.bash,
|
|
1154
|
-
getMaxToolRounds: () => this.maxToolRounds,
|
|
1155
|
-
getMaxTokens: () => this.maxTokens,
|
|
1156
|
-
isBatchApiEnabled: () => this.batchApi,
|
|
1157
|
-
getCrossTurnDedup: () => this._crossTurnDedup,
|
|
1158
|
-
getReadBudget: () => this._readBudget,
|
|
1159
|
-
recordUsage: (usage, source, model) => this.recordUsage(usage, source, model),
|
|
1160
|
-
setCurrentCallId: (id) => {
|
|
1161
|
-
this._currentCallId = id;
|
|
1162
|
-
},
|
|
1163
|
-
setLastProviderOptionsShape: (shape) => {
|
|
1164
|
-
this._lastProviderOptionsShape = shape;
|
|
1165
|
-
},
|
|
1166
|
-
runTaskRequestBatch: (args) => this.runTaskRequestBatch(args),
|
|
1167
|
-
};
|
|
1168
|
-
const runner = new StreamRunner(deps);
|
|
1169
|
-
return runner.run(request, onActivity, abortSignal);
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
private async runTask(request: TaskRequest, abortSignal?: AbortSignal): Promise<ToolResult> {
|
|
1173
|
-
const startInput: SubagentStartHookInput = {
|
|
1174
|
-
hook_event_name: "SubagentStart",
|
|
1175
|
-
agent_type: request.agent,
|
|
1176
|
-
description: request.description,
|
|
1177
|
-
session_id: this.session?.id,
|
|
1178
|
-
cwd: this.bash.getCwd(),
|
|
1179
|
-
};
|
|
1180
|
-
await this.fireHook(startInput, abortSignal).catch(() => {});
|
|
1181
|
-
|
|
1182
|
-
let result: ToolResult;
|
|
1183
|
-
try {
|
|
1184
|
-
result = await withStreamRetry(
|
|
1185
|
-
() =>
|
|
1186
|
-
this.runTaskRequest(
|
|
1187
|
-
request,
|
|
1188
|
-
(detail) => {
|
|
1189
|
-
if (abortSignal?.aborted) return;
|
|
1190
|
-
this.emitSubagentStatus({
|
|
1191
|
-
agent: request.agent,
|
|
1192
|
-
description: request.description,
|
|
1193
|
-
detail,
|
|
1194
|
-
});
|
|
1195
|
-
},
|
|
1196
|
-
abortSignal,
|
|
1197
|
-
),
|
|
1198
|
-
{
|
|
1199
|
-
signal: abortSignal,
|
|
1200
|
-
onRetry: (info) => {
|
|
1201
|
-
// Emit harness telemetry
|
|
1202
|
-
try {
|
|
1203
|
-
const _ar = (globalThis as Record<string, unknown>).__muonroiAgentRuntime as
|
|
1204
|
-
| { emitEvent: (e: unknown) => void }
|
|
1205
|
-
| undefined;
|
|
1206
|
-
_ar?.emitEvent({
|
|
1207
|
-
t: "event",
|
|
1208
|
-
kind: "stream-retry",
|
|
1209
|
-
...info,
|
|
1210
|
-
});
|
|
1211
|
-
} catch {
|
|
1212
|
-
/* best-effort */
|
|
1213
|
-
}
|
|
1214
|
-
try {
|
|
1215
|
-
if (this.session) {
|
|
1216
|
-
logInteraction(this.session.id, "stream_retry", {
|
|
1217
|
-
data: {
|
|
1218
|
-
attempt: info.attempt,
|
|
1219
|
-
maxAttempts: info.maxAttempts,
|
|
1220
|
-
errorName: info.errorName,
|
|
1221
|
-
errorMessage: info.errorMessage.slice(0, 200),
|
|
1222
|
-
nextDelayMs: info.nextDelayMs,
|
|
1223
|
-
},
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
} catch {
|
|
1227
|
-
/* fail-open */
|
|
1228
|
-
}
|
|
1229
|
-
},
|
|
1230
|
-
},
|
|
1231
|
-
);
|
|
1232
|
-
} finally {
|
|
1233
|
-
this.emitSubagentStatus(null);
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
const stopInput: SubagentStopHookInput = {
|
|
1237
|
-
hook_event_name: "SubagentStop",
|
|
1238
|
-
agent_type: request.agent,
|
|
1239
|
-
description: request.description,
|
|
1240
|
-
success: result.success,
|
|
1241
|
-
session_id: this.session?.id,
|
|
1242
|
-
cwd: this.bash.getCwd(),
|
|
1243
|
-
};
|
|
1244
|
-
await this.fireHook(stopInput, abortSignal).catch(() => {});
|
|
1245
|
-
|
|
1246
|
-
return result;
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
private async runDelegation(request: TaskRequest, abortSignal?: AbortSignal): Promise<ToolResult> {
|
|
1250
|
-
const taskCreatedInput: TaskCreatedHookInput = {
|
|
1251
|
-
hook_event_name: "TaskCreated",
|
|
1252
|
-
agent_type: request.agent,
|
|
1253
|
-
description: request.description,
|
|
1254
|
-
session_id: this.session?.id,
|
|
1255
|
-
cwd: this.bash.getCwd(),
|
|
1256
|
-
};
|
|
1257
|
-
await this.fireHook(taskCreatedInput, abortSignal).catch(() => {});
|
|
1258
|
-
|
|
1259
|
-
let result: ToolResult;
|
|
1260
|
-
try {
|
|
1261
|
-
if (abortSignal?.aborted) {
|
|
1262
|
-
return { success: false, output: "[Cancelled]" };
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
result = await this.delegations.start(request, {
|
|
1266
|
-
model: this.modelId,
|
|
1267
|
-
sandboxMode: this.bash.getSandboxMode(),
|
|
1268
|
-
sandboxSettings: this.bash.getSandboxSettings(),
|
|
1269
|
-
maxToolRounds: this.maxToolRounds,
|
|
1270
|
-
maxTokens: this.maxTokens,
|
|
1271
|
-
batchApi: this.batchApi,
|
|
1272
|
-
});
|
|
1273
|
-
} catch (err: unknown) {
|
|
1274
|
-
if (abortSignal?.aborted) throw err;
|
|
1275
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1276
|
-
result = {
|
|
1277
|
-
success: false,
|
|
1278
|
-
output: `Delegation failed: ${msg}`,
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
const taskCompletedInput: TaskCompletedHookInput = {
|
|
1283
|
-
hook_event_name: "TaskCompleted",
|
|
1284
|
-
agent_type: request.agent,
|
|
1285
|
-
description: request.description,
|
|
1286
|
-
success: result.success,
|
|
1287
|
-
session_id: this.session?.id,
|
|
1288
|
-
cwd: this.bash.getCwd(),
|
|
1289
|
-
};
|
|
1290
|
-
await this.fireHook(taskCompletedInput, abortSignal).catch(() => {});
|
|
1291
|
-
|
|
1292
|
-
return result;
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
private async readDelegation(id: string): Promise<ToolResult> {
|
|
1296
|
-
try {
|
|
1297
|
-
return {
|
|
1298
|
-
success: true,
|
|
1299
|
-
output: await this.delegations.read(id),
|
|
1300
|
-
};
|
|
1301
|
-
} catch (err: unknown) {
|
|
1302
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1303
|
-
return {
|
|
1304
|
-
success: false,
|
|
1305
|
-
output: `Failed to read delegation: ${msg}`,
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
private async listDelegations(): Promise<ToolResult> {
|
|
1311
|
-
try {
|
|
1312
|
-
const delegations = await this.delegations.list();
|
|
1313
|
-
if (delegations.length === 0) {
|
|
1314
|
-
return {
|
|
1315
|
-
success: true,
|
|
1316
|
-
output: "No delegations found for this project.",
|
|
1317
|
-
};
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
const lines = delegations.map((delegation) => {
|
|
1321
|
-
const title = delegation.description || delegation.id;
|
|
1322
|
-
return `- \`${delegation.id}\` [${delegation.status}] ${title}\n ${delegation.summary}`;
|
|
1323
|
-
});
|
|
1324
|
-
|
|
1325
|
-
return {
|
|
1326
|
-
success: true,
|
|
1327
|
-
output: `## Delegations\n\n${lines.join("\n")}`,
|
|
1328
|
-
};
|
|
1329
|
-
} catch (err: unknown) {
|
|
1330
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
1331
|
-
return {
|
|
1332
|
-
success: false,
|
|
1333
|
-
output: `Failed to list delegations: ${msg}`,
|
|
1334
|
-
};
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
private getCompactionSettings(contextWindow?: number): CompactionSettings {
|
|
1339
|
-
let keepRecentTokens = DEFAULT_KEEP_RECENT_TOKENS;
|
|
1340
|
-
|
|
1341
|
-
// For models with very large context windows, keep more recent tokens
|
|
1342
|
-
if (contextWindow && contextWindow > 200_000) {
|
|
1343
|
-
keepRecentTokens = Math.min(100_000, Math.max(20_000, Math.floor(contextWindow * 0.1)));
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
// Compact more aggressively for long sessions to prevent runaway token growth
|
|
1347
|
-
if (this._compactionStats.count >= 2) {
|
|
1348
|
-
keepRecentTokens = Math.floor(keepRecentTokens * 0.75);
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
return {
|
|
1352
|
-
reserveTokens: Math.max(this.maxTokens, DEFAULT_RESERVE_TOKENS),
|
|
1353
|
-
keepRecentTokens,
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
private _resolveCompactModel(): string {
|
|
1358
|
-
return this._resolveModelForTask("compact");
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
private _resolveModelForTask(task: "compact" | "explore" | "general" | "title"): string {
|
|
1362
|
-
const tierPrefs: Record<string, Array<"fast" | "balanced" | "premium">> = {
|
|
1363
|
-
compact: ["fast", "balanced"],
|
|
1364
|
-
title: ["fast", "balanced"],
|
|
1365
|
-
explore: ["balanced", "fast"],
|
|
1366
|
-
general: ["premium", "balanced"],
|
|
1367
|
-
};
|
|
1368
|
-
for (const tier of tierPrefs[task] ?? ["balanced"]) {
|
|
1369
|
-
const m = getModelByTier(tier, this.providerId);
|
|
1370
|
-
if (m?.provider === this.providerId) return m.id;
|
|
1371
|
-
}
|
|
1372
|
-
return this.modelId;
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
private async compactForContext(
|
|
1376
|
-
provider: LegacyProvider,
|
|
1377
|
-
system: string,
|
|
1378
|
-
contextWindow: number,
|
|
1379
|
-
signal: AbortSignal,
|
|
1380
|
-
settings = this.getCompactionSettings(contextWindow),
|
|
1381
|
-
force = false,
|
|
1382
|
-
): Promise<boolean> {
|
|
1383
|
-
if (!this.session) return false;
|
|
1384
|
-
|
|
1385
|
-
const preparation = prepareCompaction(this.messages, system, settings);
|
|
1386
|
-
if (!preparation) return false;
|
|
1387
|
-
if (!force && !shouldCompactContext(preparation.tokensBefore, contextWindow, settings)) {
|
|
1388
|
-
return false;
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
const trigger = force ? "manual" : "auto";
|
|
1392
|
-
|
|
1393
|
-
// Fire-and-forget: notify EE of stale suggestions before compaction
|
|
1394
|
-
const { surfacedIds, timestamp } = getLastSurfacedState();
|
|
1395
|
-
if (surfacedIds.length > 0) {
|
|
1396
|
-
getDefaultEEClient()
|
|
1397
|
-
.promptStale({
|
|
1398
|
-
state: { surfacedIds, timestamp },
|
|
1399
|
-
nextPromptMeta: { trigger: "auto-compact", cwd: this.bash.getCwd(), tenantId: getTenantId() },
|
|
1400
|
-
})
|
|
1401
|
-
.catch(() => {});
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
const preCompactInput: PreCompactHookInput = {
|
|
1405
|
-
hook_event_name: "PreCompact",
|
|
1406
|
-
trigger,
|
|
1407
|
-
session_id: this.session?.id,
|
|
1408
|
-
cwd: this.bash.getCwd(),
|
|
1409
|
-
};
|
|
1410
|
-
await this.fireHook(preCompactInput, signal).catch(() => {});
|
|
1411
|
-
|
|
1412
|
-
const keptSeqs = this.messageSeqs.slice(preparation.firstKeptIndex);
|
|
1413
|
-
const firstKeptSeq = keptSeqs.find((seq): seq is number => seq !== null) ?? getNextMessageSequence(this.session.id);
|
|
1414
|
-
const compactModelId = this._resolveCompactModel();
|
|
1415
|
-
const compactStartedAt = Date.now();
|
|
1416
|
-
const { summary, usage: compactUsage } = await generateCompactionSummary(
|
|
1417
|
-
provider,
|
|
1418
|
-
compactModelId,
|
|
1419
|
-
preparation,
|
|
1420
|
-
undefined,
|
|
1421
|
-
signal,
|
|
1422
|
-
);
|
|
1423
|
-
|
|
1424
|
-
// Record compaction call in cost-log — bypasses recordUsage because
|
|
1425
|
-
// compaction returns usage separately and isn't routed through the
|
|
1426
|
-
// status-bar / usage event pipeline (intentional: it's overhead, not user spend).
|
|
1427
|
-
const compactProvider = detectProviderForModel(compactModelId);
|
|
1428
|
-
appendCostLog({
|
|
1429
|
-
ts: compactStartedAt,
|
|
1430
|
-
provider: compactProvider,
|
|
1431
|
-
model: compactModelId,
|
|
1432
|
-
estimatedUsd: projectCostUSD(
|
|
1433
|
-
compactProvider,
|
|
1434
|
-
compactModelId,
|
|
1435
|
-
compactUsage.promptTokens,
|
|
1436
|
-
compactUsage.completionTokens,
|
|
1437
|
-
),
|
|
1438
|
-
callsite: "orchestrator.compaction",
|
|
1439
|
-
phase: "compaction",
|
|
1440
|
-
iteration: this._compactionStats.count + 1,
|
|
1441
|
-
actualInputTokens: compactUsage.promptTokens,
|
|
1442
|
-
actualOutputTokens: compactUsage.completionTokens,
|
|
1443
|
-
durationMs: Date.now() - compactStartedAt,
|
|
1444
|
-
}).catch(() => undefined);
|
|
1445
|
-
|
|
1446
|
-
appendCompaction(this.session.id, firstKeptSeq, summary, preparation.tokensBefore);
|
|
1447
|
-
|
|
1448
|
-
// Re-inject pinned user messages that were about to be summarized away.
|
|
1449
|
-
// Pinned seqs that are still inside keptMessages don't need re-injection.
|
|
1450
|
-
const keptSeqSet = new Set(keptSeqs.filter((s): s is number => s !== null));
|
|
1451
|
-
const pinnedReinjections: ModelMessage[] = [];
|
|
1452
|
-
const pinnedReinjectionSeqs: Array<number | null> = [];
|
|
1453
|
-
for (const seq of [...this._pinnedSeqs].sort((a, b) => a - b)) {
|
|
1454
|
-
if (keptSeqSet.has(seq)) continue;
|
|
1455
|
-
const idx = this.messageSeqs.indexOf(seq);
|
|
1456
|
-
if (idx < 0) {
|
|
1457
|
-
// Pinned seq no longer present (shouldn't happen, but stay defensive).
|
|
1458
|
-
this._pinnedSeqs.delete(seq);
|
|
1459
|
-
continue;
|
|
1460
|
-
}
|
|
1461
|
-
const original = this.messages[idx];
|
|
1462
|
-
if (!original || original.role !== "user") continue;
|
|
1463
|
-
const text = extractUserContent(original.content).trim();
|
|
1464
|
-
if (!text) continue;
|
|
1465
|
-
pinnedReinjections.push({
|
|
1466
|
-
role: "system",
|
|
1467
|
-
content: `[Pinned user message — kept verbatim across compaction]\n${text}`,
|
|
1468
|
-
});
|
|
1469
|
-
pinnedReinjectionSeqs.push(null);
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
this.messages = [createCompactionSummaryMessage(summary), ...pinnedReinjections, ...preparation.keptMessages];
|
|
1473
|
-
this.messageSeqs = [null, ...pinnedReinjectionSeqs, ...keptSeqs];
|
|
1474
|
-
|
|
1475
|
-
// Track compaction stats — net of the tokens spent ON compaction itself.
|
|
1476
|
-
const tokensAfter = estimateConversationTokens(system, this.messages);
|
|
1477
|
-
const grossSaved = Math.max(0, preparation.tokensBefore - tokensAfter);
|
|
1478
|
-
const compactCost = compactUsage.promptTokens + compactUsage.completionTokens;
|
|
1479
|
-
const saved = Math.max(0, grossSaved - compactCost);
|
|
1480
|
-
const pct = preparation.tokensBefore > 0 ? ((saved / preparation.tokensBefore) * 100).toFixed(1) : "0.0";
|
|
1481
|
-
this._compactionStats.count++;
|
|
1482
|
-
this._compactionStats.totalSaved += saved;
|
|
1483
|
-
|
|
1484
|
-
// Update status bar with current context size and compaction summary
|
|
1485
|
-
const fmtCompact = (n: number) => (n >= 1000 ? `${(n / 1000).toFixed(1)}K` : String(n));
|
|
1486
|
-
const modelSuffix = compactModelId !== this.modelId ? ` via ${compactModelId}` : "";
|
|
1487
|
-
const userMsgCount = this.messages.filter((m) => m.role === "user").length;
|
|
1488
|
-
const isLongSession = this._compactionStats.count >= 3 || userMsgCount >= 200;
|
|
1489
|
-
const sessionHint = isLongSession ? " ⚠ long session — consider /clear" : "";
|
|
1490
|
-
const compactLabel = `${this._compactionStats.count} cmp, ${fmtCompact(this._compactionStats.totalSaved)} saved${modelSuffix}${sessionHint}`;
|
|
1491
|
-
statusBarStore.setState({ ctx_tokens: tokensAfter, compaction_summary: compactLabel });
|
|
1492
|
-
|
|
1493
|
-
const postCompactInput: PostCompactHookInput = {
|
|
1494
|
-
hook_event_name: "PostCompact",
|
|
1495
|
-
trigger,
|
|
1496
|
-
session_id: this.session?.id,
|
|
1497
|
-
cwd: this.bash.getCwd(),
|
|
1498
|
-
};
|
|
1499
|
-
await this.fireHook(postCompactInput, signal).catch(() => {});
|
|
1500
|
-
|
|
1501
|
-
// Interaction log: compaction
|
|
1502
|
-
try {
|
|
1503
|
-
if (this.session) {
|
|
1504
|
-
logInteraction(this.session.id, "compaction", {
|
|
1505
|
-
data: {
|
|
1506
|
-
count: this._compactionStats.count,
|
|
1507
|
-
tokensBefore: preparation.tokensBefore,
|
|
1508
|
-
tokensAfter,
|
|
1509
|
-
saved,
|
|
1510
|
-
grossSaved,
|
|
1511
|
-
compactCost,
|
|
1512
|
-
pct,
|
|
1513
|
-
isLongSession,
|
|
1514
|
-
},
|
|
1515
|
-
});
|
|
1516
|
-
}
|
|
1517
|
-
} catch {
|
|
1518
|
-
/* fail-open */
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
this._compactedThisTurn = true;
|
|
1522
|
-
return true;
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
private async postTurnCompact(
|
|
1526
|
-
provider: LegacyProvider,
|
|
1527
|
-
system: string,
|
|
1528
|
-
contextWindow: number,
|
|
1529
|
-
signal: AbortSignal,
|
|
1530
|
-
): Promise<void> {
|
|
1531
|
-
const log = (taken: boolean, reason: string, extra?: Record<string, unknown>): void => {
|
|
1532
|
-
appendDecisionLog({
|
|
1533
|
-
ts: Date.now(),
|
|
1534
|
-
sessionId: this.session?.id ?? null,
|
|
1535
|
-
kind: "post-turn-compact",
|
|
1536
|
-
taken,
|
|
1537
|
-
reason,
|
|
1538
|
-
meta: { contextWindow, ...extra },
|
|
1539
|
-
}).catch(() => undefined);
|
|
1540
|
-
};
|
|
1541
|
-
|
|
1542
|
-
if (this._compactedThisTurn) return log(false, "already-compacted-this-turn");
|
|
1543
|
-
if (!isAutoCompactAfterTurnEnabled()) return log(false, "feature-disabled");
|
|
1544
|
-
const tokens = estimateConversationTokens(system, this.messages);
|
|
1545
|
-
const thresholdPct = getAutoCompactThresholdPct();
|
|
1546
|
-
const minMeaningfulTokens = Math.max(POST_TURN_MIN_TOKENS, Math.floor(contextWindow * thresholdPct));
|
|
1547
|
-
if (tokens < minMeaningfulTokens) {
|
|
1548
|
-
return log(false, `under-threshold (${tokens} < ${minMeaningfulTokens})`, {
|
|
1549
|
-
tokens,
|
|
1550
|
-
thresholdPct,
|
|
1551
|
-
minMeaningfulTokens,
|
|
1552
|
-
});
|
|
1553
|
-
}
|
|
1554
|
-
log(true, `over-threshold (${tokens} >= ${minMeaningfulTokens})`, { tokens, thresholdPct, minMeaningfulTokens });
|
|
1555
|
-
await this.compactForContext(
|
|
1556
|
-
provider,
|
|
1557
|
-
system,
|
|
1558
|
-
contextWindow,
|
|
1559
|
-
signal,
|
|
1560
|
-
this.getCompactionSettings(contextWindow),
|
|
1561
|
-
true,
|
|
1562
|
-
).catch((err) => console.warn("[compact] failed:", (err as Error)?.message));
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
// ========================================================================
|
|
1566
|
-
// Council system — delegated to CouncilManager (Phase 12.1-02)
|
|
1567
|
-
//
|
|
1568
|
-
// All council state + sub-call helpers (generate/research/prompt builders/
|
|
1569
|
-
// outcome parser/executor/candidate resolution) live in CouncilManager.
|
|
1570
|
-
// The thin facade below preserves the public API the UI + tests rely on
|
|
1571
|
-
// (respondToCouncilQuestion/Preflight + the internal _create*Responder
|
|
1572
|
-
// hooks used by orchestrator.agent.test.ts).
|
|
1573
|
-
// ========================================================================
|
|
1574
|
-
|
|
1575
|
-
respondToCouncilQuestion(questionId: string, answer: string): void {
|
|
1576
|
-
this.councilManager.respondToQuestion(questionId, answer);
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
respondToCouncilPreflight(preflightId: string, approved: boolean): void {
|
|
1580
|
-
this.councilManager.respondToPreflight(preflightId, approved);
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
// Internal hooks used by orchestrator.agent.test.ts to exercise buffered
|
|
1584
|
-
// question / preflight delivery through CouncilManager. They are reached
|
|
1585
|
-
// through `as unknown as` casts in the test; keep them private but stable.
|
|
1586
|
-
private _createQuestionResponder(): (questionId: string) => Promise<string> {
|
|
1587
|
-
return this.councilManager.createQuestionResponder();
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
private _createPreflightResponder(): (preflightId: string) => Promise<boolean> {
|
|
1591
|
-
return this.councilManager.createPreflightResponder();
|
|
1592
|
-
}
|
|
1593
|
-
|
|
1594
|
-
// ========================================================================
|
|
1595
|
-
// Council v2 — Clarify → Confirm → Debate → Plan → Execute
|
|
1596
|
-
// ========================================================================
|
|
1597
|
-
|
|
1598
|
-
async *runCouncilV2(
|
|
1599
|
-
topic: string,
|
|
1600
|
-
options?: {
|
|
1601
|
-
skipClarification?: boolean;
|
|
1602
|
-
observer?: ProcessMessageObserver;
|
|
1603
|
-
userModelMessage?: ModelMessage;
|
|
1604
|
-
},
|
|
1605
|
-
): AsyncGenerator<StreamChunk, void, unknown> {
|
|
1606
|
-
const { runCouncil } = await import("../council/index.js");
|
|
1607
|
-
const { createCouncilLLM } = await import("../council/llm.js");
|
|
1608
|
-
const councilStats = { calls: 0, startMs: Date.now(), phases: [] as Array<{ name: string; durationMs: number }> };
|
|
1609
|
-
const llm = createCouncilLLM(this.bash, this.mode, this.session?.id, councilStats);
|
|
1610
|
-
|
|
1611
|
-
const processMessageFn = (message: string) => this.processMessage(message, options?.observer);
|
|
1612
|
-
|
|
1613
|
-
const gen = runCouncil(
|
|
1614
|
-
topic,
|
|
1615
|
-
this.modelId,
|
|
1616
|
-
this.messages as Array<{ role: string; content: string | unknown }>,
|
|
1617
|
-
this.session?.id,
|
|
1618
|
-
llm,
|
|
1619
|
-
this.councilManager.createQuestionResponder(),
|
|
1620
|
-
this.councilManager.createPreflightResponder(),
|
|
1621
|
-
processMessageFn,
|
|
1622
|
-
{
|
|
1623
|
-
skipClarification: options?.skipClarification,
|
|
1624
|
-
userModelMessage: options?.userModelMessage,
|
|
1625
|
-
cwd: this.bash.getCwd(),
|
|
1626
|
-
councilStats, // NEW — share orchestrator's stats object with runCouncil (Phase 14 CQ-01)
|
|
1627
|
-
},
|
|
1628
|
-
);
|
|
1629
|
-
|
|
1630
|
-
let result: IteratorResult<StreamChunk, string | null>;
|
|
1631
|
-
do {
|
|
1632
|
-
result = await gen.next();
|
|
1633
|
-
if (!result.done && result.value) {
|
|
1634
|
-
yield result.value;
|
|
1635
|
-
}
|
|
1636
|
-
} while (!result.done);
|
|
1637
|
-
|
|
1638
|
-
const synthesis = result.value;
|
|
1639
|
-
this.councilManager.setLastSynthesis(synthesis);
|
|
1640
|
-
|
|
1641
|
-
if (options?.userModelMessage && synthesis) {
|
|
1642
|
-
this.appendCompletedTurn(options.userModelMessage, [{ role: "assistant", content: synthesis }]);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
// ========================================================================
|
|
1647
|
-
// Product Ideal Loop (Phase 13) — mirror of runCouncilV2 wiring.
|
|
1648
|
-
// ========================================================================
|
|
1649
|
-
|
|
1650
|
-
async *runProductLoopV1(
|
|
1651
|
-
payload: {
|
|
1652
|
-
subcommand: "start" | "status" | "resume" | "abort" | "ship";
|
|
1653
|
-
idea?: string;
|
|
1654
|
-
runId?: string;
|
|
1655
|
-
flags: {
|
|
1656
|
-
maxCost: number;
|
|
1657
|
-
maxSprints: number;
|
|
1658
|
-
doneThreshold: number;
|
|
1659
|
-
stack?: string;
|
|
1660
|
-
noCustomerDebate?: boolean;
|
|
1661
|
-
noPriorContext?: boolean;
|
|
1662
|
-
forceCouncil?: boolean;
|
|
1663
|
-
};
|
|
1664
|
-
},
|
|
1665
|
-
options?: {
|
|
1666
|
-
observer?: ProcessMessageObserver;
|
|
1667
|
-
userModelMessage?: ModelMessage;
|
|
1668
|
-
},
|
|
1669
|
-
): AsyncGenerator<StreamChunk, void, unknown> {
|
|
1670
|
-
const { runProductLoop } = await import("../product-loop/index.js");
|
|
1671
|
-
const { createCouncilLLM } = await import("../council/llm.js");
|
|
1672
|
-
const nodePath = await import("node:path");
|
|
1673
|
-
|
|
1674
|
-
const productStats = {
|
|
1675
|
-
calls: 0,
|
|
1676
|
-
startMs: Date.now(),
|
|
1677
|
-
phases: [] as Array<{ name: string; durationMs: number }>,
|
|
1678
|
-
};
|
|
1679
|
-
const llm = createCouncilLLM(this.bash, this.mode, this.session?.id, productStats);
|
|
1680
|
-
const processMessageFn = (m: string) => this.processMessage(m, options?.observer);
|
|
1681
|
-
const flowDir = nodePath.join(this.bash.getCwd(), ".muonroi-flow");
|
|
1682
|
-
|
|
1683
|
-
// P2.7: compute complexity from the idea using PIL Layer 1 heuristics (cheap,
|
|
1684
|
-
// no LLM calls). Only meaningful for "start"; other subcommands ignore it.
|
|
1685
|
-
let complexity: "low" | "medium" | "high" | undefined;
|
|
1686
|
-
let sufficiencyMissing: readonly import("../pil/layer1-intent.js").SufficiencyMissing[] | undefined;
|
|
1687
|
-
if (payload.subcommand === "start" && payload.idea) {
|
|
1688
|
-
const { scoreComplexity, scoreSufficiency } = await import("../pil/layer1-intent.js");
|
|
1689
|
-
const result = scoreComplexity({
|
|
1690
|
-
rawText: payload.idea,
|
|
1691
|
-
taskType: null,
|
|
1692
|
-
t0HitCount: 0,
|
|
1693
|
-
hasMaxSprintsOne: payload.flags.maxSprints === 1,
|
|
1694
|
-
});
|
|
1695
|
-
complexity = result.complexity;
|
|
1696
|
-
// Sufficiency gate — vague briefs ("todo app") force Council so the
|
|
1697
|
-
// discovery AskCard can fill in persona/MVP/architecture/verify before
|
|
1698
|
-
// any code is scaffolded.
|
|
1699
|
-
const suff = scoreSufficiency({ rawText: payload.idea });
|
|
1700
|
-
sufficiencyMissing = suff.sufficient ? undefined : suff.missing;
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
const gen = runProductLoop({
|
|
1704
|
-
subcommand: payload.subcommand,
|
|
1705
|
-
idea: payload.idea ?? "",
|
|
1706
|
-
runId: payload.runId,
|
|
1707
|
-
flowDir,
|
|
1708
|
-
sessionModelId: this.modelId,
|
|
1709
|
-
llm,
|
|
1710
|
-
flags: {
|
|
1711
|
-
maxCost: payload.flags.maxCost,
|
|
1712
|
-
maxSprints: payload.flags.maxSprints,
|
|
1713
|
-
doneThreshold: payload.flags.doneThreshold,
|
|
1714
|
-
stack: payload.flags.stack,
|
|
1715
|
-
forceCouncil: payload.flags.forceCouncil,
|
|
1716
|
-
},
|
|
1717
|
-
respondToQuestion: this.councilManager.createQuestionResponder(),
|
|
1718
|
-
respondToPreflight: this.councilManager.createPreflightResponder(),
|
|
1719
|
-
cwd: this.bash.getCwd(),
|
|
1720
|
-
processMessageFn,
|
|
1721
|
-
skipPriorContext: payload.flags.noPriorContext === true,
|
|
1722
|
-
complexity,
|
|
1723
|
-
sufficiencyMissing,
|
|
1724
|
-
// Chat session id — used as the FK key for interaction_logs telemetry.
|
|
1725
|
-
// The /ideal runId is NOT a sessions.id and would silently fail FK insert.
|
|
1726
|
-
sessionId: this.session?.id,
|
|
1727
|
-
} as Parameters<typeof runProductLoop>[0]);
|
|
1728
|
-
|
|
1729
|
-
for await (const chunk of gen) {
|
|
1730
|
-
yield chunk;
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
// ========================================================================
|
|
1735
|
-
// Legacy council — kept for backward compatibility, will be removed
|
|
1736
|
-
// ========================================================================
|
|
1737
|
-
|
|
1738
|
-
async *runCouncilRound(
|
|
1739
|
-
topic: string,
|
|
1740
|
-
_observer?: ProcessMessageObserver,
|
|
1741
|
-
rounds?: number,
|
|
1742
|
-
userModelMessage?: ModelMessage,
|
|
1743
|
-
): AsyncGenerator<StreamChunk, void, unknown> {
|
|
1744
|
-
const maxRounds = rounds ?? getCouncilRounds();
|
|
1745
|
-
const ALL_ROLES: ModelRole[] = ["implement", "verify", "research"];
|
|
1746
|
-
this.councilManager.resetStats(Date.now());
|
|
1747
|
-
|
|
1748
|
-
// Resolve council participants: same-provider by default, multi-provider only when configured
|
|
1749
|
-
const candidates: Array<{ role: ModelRole; model: string }> = [];
|
|
1750
|
-
const configuredRoleModels = getRoleModels();
|
|
1751
|
-
const hasExplicitMultiProvider = this.councilManager.hasMultiProviderConfig(configuredRoleModels);
|
|
1752
|
-
|
|
1753
|
-
if (hasExplicitMultiProvider && isCouncilMultiProviderPreferred()) {
|
|
1754
|
-
// Multi-provider path: use explicitly configured role models across providers
|
|
1755
|
-
for (const role of ALL_ROLES) {
|
|
1756
|
-
const modelId = getRoleModel(role);
|
|
1757
|
-
if (!modelId) continue;
|
|
1758
|
-
const provider = detectProviderForModel(modelId);
|
|
1759
|
-
if (isProviderDisabled(provider as ProviderId)) continue;
|
|
1760
|
-
const canReach = await loadKeyForProvider(provider)
|
|
1761
|
-
.then(() => true)
|
|
1762
|
-
.catch(() => false);
|
|
1763
|
-
if (canReach) candidates.push({ role, model: modelId });
|
|
1764
|
-
}
|
|
1765
|
-
if (candidates.length >= 2) {
|
|
1766
|
-
const providers = new Set(candidates.map((c) => detectProviderForModel(c.model)));
|
|
1767
|
-
yield {
|
|
1768
|
-
type: "content",
|
|
1769
|
-
content: `\n[Multi-provider mode: ${candidates.length} roles across ${providers.size} provider(s)]\n`,
|
|
1770
|
-
};
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
// Default: same-provider mode — pick diverse models from the session's provider
|
|
1775
|
-
if (candidates.length < 2) {
|
|
1776
|
-
const mainProviderId = detectProviderForModel(this.modelId);
|
|
1777
|
-
// Skip same-provider resolution if the session's provider is disabled
|
|
1778
|
-
if (!isProviderDisabled(mainProviderId as ProviderId)) {
|
|
1779
|
-
const sameCandidates = await this.councilManager.resolveSameProviderCandidates(mainProviderId, ALL_ROLES);
|
|
1780
|
-
if (sameCandidates.length >= 2) {
|
|
1781
|
-
candidates.length = 0;
|
|
1782
|
-
candidates.push(...sameCandidates);
|
|
1783
|
-
const uniqueModels = new Set(sameCandidates.map((c) => c.model));
|
|
1784
|
-
yield {
|
|
1785
|
-
type: "content",
|
|
1786
|
-
content: `\n[Same-provider mode: ${uniqueModels.size} ${mainProviderId} model(s) for ${sameCandidates.length} roles]\n`,
|
|
1787
|
-
};
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
// Final fallback: use main model for all roles
|
|
1793
|
-
if (candidates.length < 2) {
|
|
1794
|
-
const mainProviderId = detectProviderForModel(this.modelId);
|
|
1795
|
-
const mainDisabled = isProviderDisabled(mainProviderId as ProviderId);
|
|
1796
|
-
const mainCanReach =
|
|
1797
|
-
!mainDisabled &&
|
|
1798
|
-
(await loadKeyForProvider(mainProviderId)
|
|
1799
|
-
.then(() => true)
|
|
1800
|
-
.catch(() => false));
|
|
1801
|
-
if (mainCanReach) {
|
|
1802
|
-
candidates.length = 0;
|
|
1803
|
-
for (const role of ALL_ROLES) {
|
|
1804
|
-
candidates.push({ role, model: this.modelId });
|
|
1805
|
-
}
|
|
1806
|
-
yield {
|
|
1807
|
-
type: "content",
|
|
1808
|
-
content: `\n[Fallback: using \x1b[36m${this.modelId}\x1b[0m for all roles]\n`,
|
|
1809
|
-
};
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1813
|
-
if (candidates.length < 2) {
|
|
1814
|
-
yield {
|
|
1815
|
-
type: "content",
|
|
1816
|
-
content: "\nNo reachable provider. Check API keys in user-settings.json or environment.\n",
|
|
1817
|
-
};
|
|
1818
|
-
yield { type: "done" };
|
|
1819
|
-
return;
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
// Build conversation context for all participants
|
|
1823
|
-
const conversationContext = this.councilManager.buildContext();
|
|
1824
|
-
|
|
1825
|
-
// ── Phase 0: Research — gather facts from codebase before discussion ──
|
|
1826
|
-
const p0Start = Date.now();
|
|
1827
|
-
yield { type: "content", content: `\n## Phase 0 — Codebase Research\n` };
|
|
1828
|
-
|
|
1829
|
-
// Find the research candidate (prefer configured research role, fallback to first available)
|
|
1830
|
-
const researchCandidate = candidates.find((c) => c.role === "research") ?? candidates[0];
|
|
1831
|
-
yield { type: "content", content: `\n### \x1b[35m[research]\x1b[0m ${researchCandidate.model}\n` };
|
|
1832
|
-
|
|
1833
|
-
const researchFindings = await this.councilManager.research(researchCandidate.model, topic, conversationContext);
|
|
1834
|
-
yield { type: "content", content: `${researchFindings}\n` };
|
|
1835
|
-
yield { type: "content", content: `\n> Phase 0: ${((Date.now() - p0Start) / 1000).toFixed(1)}s\n` };
|
|
1836
|
-
|
|
1837
|
-
// Inject research findings into conversation context for subsequent phases
|
|
1838
|
-
const enrichedContext = conversationContext
|
|
1839
|
-
? `${conversationContext}\n\n---\n\n## Research Findings (Phase 0)\n${researchFindings}`
|
|
1840
|
-
: `## Research Findings (Phase 0)\n${researchFindings}`;
|
|
1841
|
-
|
|
1842
|
-
// ── Phase 1: Parallel opening statements ──
|
|
1843
|
-
const p1Start = Date.now();
|
|
1844
|
-
yield { type: "content", content: "\n## Phase 1 — Opening Analysis\n" };
|
|
1845
|
-
|
|
1846
|
-
const openingPromises = candidates.map(({ role, model }) => {
|
|
1847
|
-
const { system, prompt } = this.councilManager.buildDiscussPrompt("open", {
|
|
1848
|
-
speakerRole: role,
|
|
1849
|
-
partnerRole: candidates.find((c) => c.role !== role)?.role ?? "colleague",
|
|
1850
|
-
topic,
|
|
1851
|
-
conversationContext: enrichedContext,
|
|
1852
|
-
});
|
|
1853
|
-
return this.councilManager
|
|
1854
|
-
.generate(model, system, prompt)
|
|
1855
|
-
.then((text) => ({ role, model, position: text, error: null as string | null }))
|
|
1856
|
-
.catch((err: unknown) => ({
|
|
1857
|
-
role,
|
|
1858
|
-
model,
|
|
1859
|
-
position: "",
|
|
1860
|
-
error: err instanceof Error ? err.message : String(err),
|
|
1861
|
-
}));
|
|
1862
|
-
});
|
|
1863
|
-
|
|
1864
|
-
const openings = await Promise.all(openingPromises);
|
|
1865
|
-
const active: Array<{ role: ModelRole; model: string; position: string }> = [];
|
|
1866
|
-
|
|
1867
|
-
for (const o of openings) {
|
|
1868
|
-
const roleColor = COUNCIL_ROLE_COLORS[o.role] ?? "";
|
|
1869
|
-
yield { type: "content", content: `\n### ${roleColor}[${o.role}]${COUNCIL_COLOR_RESET} ${o.model}\n` };
|
|
1870
|
-
if (o.error) {
|
|
1871
|
-
yield { type: "content", content: `[Error: ${o.error}]\n` };
|
|
1872
|
-
} else {
|
|
1873
|
-
active.push({ role: o.role, model: o.model, position: o.position });
|
|
1874
|
-
const bgColor = COUNCIL_COLOR_BG[o.role] ?? "";
|
|
1875
|
-
yield { type: "content", content: `${bgColor} ${o.role.toUpperCase()} ${COUNCIL_COLOR_RESET} ${o.position}\n` };
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1879
|
-
yield {
|
|
1880
|
-
type: "content",
|
|
1881
|
-
content: `\n> Phase 1: ${active.length} participants, ${((Date.now() - p1Start) / 1000).toFixed(1)}s (parallel)\n`,
|
|
1882
|
-
};
|
|
1883
|
-
|
|
1884
|
-
if (active.length < 2) {
|
|
1885
|
-
yield { type: "content", content: "\nNot enough successful openings for discussion.\n" };
|
|
1886
|
-
yield { type: "done" };
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
|
|
1890
|
-
// ── Phase 2: Discussion rounds with parallel pair debates ──
|
|
1891
|
-
const exchangeLogs: Map<string, string[]> = new Map();
|
|
1892
|
-
const pairConverged: Map<string, boolean> = new Map();
|
|
1893
|
-
let runningSummary = "";
|
|
1894
|
-
|
|
1895
|
-
for (let round = 1; round <= maxRounds; round++) {
|
|
1896
|
-
const p2Start = Date.now();
|
|
1897
|
-
yield { type: "content", content: `\n## Phase 2 — Discussion Round ${round}/${maxRounds}\n` };
|
|
1898
|
-
|
|
1899
|
-
// Build independent pairs
|
|
1900
|
-
const pairs: Array<{ a: (typeof active)[0]; b: (typeof active)[0]; key: string }> = [];
|
|
1901
|
-
for (let i = 0; i < active.length; i++) {
|
|
1902
|
-
const a = active[i];
|
|
1903
|
-
const b = active[(i + 1) % active.length];
|
|
1904
|
-
const key = `${a.role}<>${b.role}`;
|
|
1905
|
-
if (pairConverged.get(key)) continue;
|
|
1906
|
-
if (!exchangeLogs.has(key)) exchangeLogs.set(key, []);
|
|
1907
|
-
pairs.push({ a, b, key });
|
|
1908
|
-
}
|
|
1909
|
-
|
|
1910
|
-
if (pairs.length === 0) break;
|
|
1911
|
-
|
|
1912
|
-
// Run pair debates in parallel
|
|
1913
|
-
const pairResults = await Promise.all(
|
|
1914
|
-
pairs.map(async ({ a, b, key }) => {
|
|
1915
|
-
const log = exchangeLogs.get(key)!;
|
|
1916
|
-
const chunks: Array<{ label: string; text: string }> = [];
|
|
1917
|
-
|
|
1918
|
-
try {
|
|
1919
|
-
let aResponse: string;
|
|
1920
|
-
let bResponse: string;
|
|
1921
|
-
|
|
1922
|
-
if (round === 1) {
|
|
1923
|
-
const aPrompt = this.councilManager.buildDiscussPrompt("respond", {
|
|
1924
|
-
speakerRole: a.role,
|
|
1925
|
-
partnerRole: b.role,
|
|
1926
|
-
topic,
|
|
1927
|
-
speakerPosition: a.position,
|
|
1928
|
-
partnerPosition: b.position,
|
|
1929
|
-
conversationContext: enrichedContext,
|
|
1930
|
-
});
|
|
1931
|
-
aResponse = await this.councilManager.generate(a.model, aPrompt.system, aPrompt.prompt);
|
|
1932
|
-
log.push(`[${a.role}]: ${aResponse}`);
|
|
1933
|
-
chunks.push({ label: `[${a.role}] → [${b.role}]`, text: aResponse });
|
|
1934
|
-
|
|
1935
|
-
const bPrompt = this.councilManager.buildDiscussPrompt("respond", {
|
|
1936
|
-
speakerRole: b.role,
|
|
1937
|
-
partnerRole: a.role,
|
|
1938
|
-
topic,
|
|
1939
|
-
speakerPosition: b.position,
|
|
1940
|
-
partnerPosition: aResponse,
|
|
1941
|
-
conversationContext: enrichedContext,
|
|
1942
|
-
});
|
|
1943
|
-
bResponse = await this.councilManager.generate(b.model, bPrompt.system, bPrompt.prompt);
|
|
1944
|
-
log.push(`[${b.role}]: ${bResponse}`);
|
|
1945
|
-
chunks.push({ label: `[${b.role}] → [${a.role}]`, text: bResponse });
|
|
1946
|
-
} else {
|
|
1947
|
-
const historyText = log.join("\n\n");
|
|
1948
|
-
const aPrompt = this.councilManager.buildDiscussPrompt("followup", {
|
|
1949
|
-
speakerRole: a.role,
|
|
1950
|
-
partnerRole: b.role,
|
|
1951
|
-
topic,
|
|
1952
|
-
partnerPosition: b.position,
|
|
1953
|
-
exchangeHistory: historyText,
|
|
1954
|
-
round,
|
|
1955
|
-
conversationContext: enrichedContext,
|
|
1956
|
-
runningSummary,
|
|
1957
|
-
});
|
|
1958
|
-
aResponse = await this.councilManager.generate(a.model, aPrompt.system, aPrompt.prompt, 1024);
|
|
1959
|
-
log.push(`[${a.role}] (round ${round}): ${aResponse}`);
|
|
1960
|
-
chunks.push({ label: `[${a.role}] → [${b.role}]`, text: aResponse });
|
|
1961
|
-
|
|
1962
|
-
const bPrompt = this.councilManager.buildDiscussPrompt("followup", {
|
|
1963
|
-
speakerRole: b.role,
|
|
1964
|
-
partnerRole: a.role,
|
|
1965
|
-
topic,
|
|
1966
|
-
partnerPosition: aResponse,
|
|
1967
|
-
exchangeHistory: historyText,
|
|
1968
|
-
round,
|
|
1969
|
-
conversationContext: enrichedContext,
|
|
1970
|
-
runningSummary,
|
|
1971
|
-
});
|
|
1972
|
-
bResponse = await this.councilManager.generate(b.model, bPrompt.system, bPrompt.prompt, 1024);
|
|
1973
|
-
log.push(`[${b.role}] (round ${round}): ${bResponse}`);
|
|
1974
|
-
chunks.push({ label: `[${b.role}] → [${a.role}]`, text: bResponse });
|
|
1975
|
-
}
|
|
1976
|
-
|
|
1977
|
-
b.position = bResponse;
|
|
1978
|
-
a.position = aResponse;
|
|
1979
|
-
|
|
1980
|
-
// Convergence check
|
|
1981
|
-
const convPrompt = this.councilManager.buildDiscussPrompt("convergence-check", {
|
|
1982
|
-
speakerRole: a.role,
|
|
1983
|
-
partnerRole: b.role,
|
|
1984
|
-
topic,
|
|
1985
|
-
exchangeHistory: log.slice(-4).join("\n\n"),
|
|
1986
|
-
conversationContext: enrichedContext,
|
|
1987
|
-
});
|
|
1988
|
-
let converged = false;
|
|
1989
|
-
let convReason = "";
|
|
1990
|
-
try {
|
|
1991
|
-
const raw = await this.councilManager.generate(a.model, convPrompt.system, convPrompt.prompt, 256);
|
|
1992
|
-
const match = raw.match(/\{[\s\S]*\}/);
|
|
1993
|
-
if (match) {
|
|
1994
|
-
const parsed = JSON.parse(match[0]) as { converged?: boolean; reason?: string };
|
|
1995
|
-
converged = parsed.converged === true;
|
|
1996
|
-
convReason = parsed.reason ?? "";
|
|
1997
|
-
}
|
|
1998
|
-
} catch {
|
|
1999
|
-
/* not converged */
|
|
2000
|
-
}
|
|
2001
|
-
|
|
2002
|
-
return { key, chunks, converged, convReason, error: null as string | null };
|
|
2003
|
-
} catch (err: unknown) {
|
|
2004
|
-
return {
|
|
2005
|
-
key,
|
|
2006
|
-
chunks,
|
|
2007
|
-
converged: false,
|
|
2008
|
-
convReason: "",
|
|
2009
|
-
error: err instanceof Error ? err.message : String(err),
|
|
2010
|
-
};
|
|
2011
|
-
}
|
|
2012
|
-
}),
|
|
2013
|
-
);
|
|
2014
|
-
|
|
2015
|
-
// Emit results (sequential yield — maintains readable order)
|
|
2016
|
-
let allConverged = true;
|
|
2017
|
-
for (const pr of pairResults) {
|
|
2018
|
-
for (const chunk of pr.chunks) {
|
|
2019
|
-
const labelParts = chunk.label.match(/\[(\w+)\] → \[(\w+)\]/);
|
|
2020
|
-
let coloredLabel = chunk.label;
|
|
2021
|
-
if (labelParts) {
|
|
2022
|
-
const fromColor = COUNCIL_ROLE_COLORS[labelParts[1]] ?? "";
|
|
2023
|
-
const toColor = COUNCIL_ROLE_COLORS[labelParts[2]] ?? "";
|
|
2024
|
-
coloredLabel = `${fromColor}[${labelParts[1]}]${COUNCIL_COLOR_RESET} → ${toColor}[${labelParts[2]}]${COUNCIL_COLOR_RESET}`;
|
|
2025
|
-
}
|
|
2026
|
-
yield { type: "content", content: `\n### ${coloredLabel}\n${chunk.text}\n` };
|
|
2027
|
-
}
|
|
2028
|
-
if (pr.error) {
|
|
2029
|
-
yield { type: "content", content: `[Discussion error: ${pr.error}]\n` };
|
|
2030
|
-
allConverged = false;
|
|
2031
|
-
} else if (pr.converged) {
|
|
2032
|
-
pairConverged.set(pr.key, true);
|
|
2033
|
-
yield { type: "content", content: `\n> ✓ ${pr.key.replace("<>", " ↔ ")} converged: ${pr.convReason}\n` };
|
|
2034
|
-
} else {
|
|
2035
|
-
allConverged = false;
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
yield {
|
|
2040
|
-
type: "content",
|
|
2041
|
-
content: `\n> Round ${round}: ${((Date.now() - p2Start) / 1000).toFixed(1)}s (${pairs.length} pairs parallel)\n`,
|
|
2042
|
-
};
|
|
2043
|
-
|
|
2044
|
-
if (allConverged) {
|
|
2045
|
-
yield { type: "content", content: `\n> All pairs converged at round ${round}. Moving to synthesis.\n` };
|
|
2046
|
-
break;
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
// Generate inter-round summary for next round's focus
|
|
2050
|
-
if (round < maxRounds) {
|
|
2051
|
-
try {
|
|
2052
|
-
runningSummary = await this.councilManager.generateRoundSummary(exchangeLogs, topic, round, active[0].model);
|
|
2053
|
-
yield {
|
|
2054
|
-
type: "content",
|
|
2055
|
-
content: `\n> **Discussion state:** ${runningSummary
|
|
2056
|
-
.split("\n")
|
|
2057
|
-
.filter((l) => l.trim())
|
|
2058
|
-
.slice(0, 3)
|
|
2059
|
-
.join(" | ")}\n`,
|
|
2060
|
-
};
|
|
2061
|
-
} catch {
|
|
2062
|
-
// Non-critical — continue without summary
|
|
2063
|
-
}
|
|
2064
|
-
}
|
|
2065
|
-
}
|
|
2066
|
-
|
|
2067
|
-
// ── Phase 3: Leader synthesis ──
|
|
2068
|
-
const p3Start = Date.now();
|
|
2069
|
-
yield { type: "content", content: "\n## Phase 3 — Leader Synthesis\n" };
|
|
2070
|
-
|
|
2071
|
-
const leaderModelId = getRoleModel("leader") ?? this.modelId;
|
|
2072
|
-
yield { type: "content", content: `\n### \x1b[32m[leader]\x1b[0m ${leaderModelId}\n` };
|
|
2073
|
-
|
|
2074
|
-
const allExchanges = [...exchangeLogs.entries()]
|
|
2075
|
-
.map(([pair, log]) => `### Discussion: ${pair}\n${log.join("\n\n")}`)
|
|
2076
|
-
.join("\n\n---\n\n");
|
|
2077
|
-
|
|
2078
|
-
const finalPositions = active.map((p) => `**${p.role}** (${p.model}): ${p.position.slice(0, 500)}...`).join("\n\n");
|
|
2079
|
-
|
|
2080
|
-
let synthesisText = "";
|
|
2081
|
-
try {
|
|
2082
|
-
synthesisText = await this.councilManager.generate(
|
|
2083
|
-
leaderModelId,
|
|
2084
|
-
"You are the team lead. Multiple specialists just had a structured discussion about a topic.\n\n" +
|
|
2085
|
-
"Output TWO parts separated by the exact line `---READABLE---`:\n\n" +
|
|
2086
|
-
"**Part 1: JSON** — a single JSON object:\n" +
|
|
2087
|
-
"```\n" +
|
|
2088
|
-
'{ "type": "decision"|"action_items"|"plan_update"|"resolve_question",\n' +
|
|
2089
|
-
' "summary": "1-2 sentence executive summary",\n' +
|
|
2090
|
-
' "agreed": ["point 1", "point 2"],\n' +
|
|
2091
|
-
' "tradeoffs": ["trade-off 1"],\n' +
|
|
2092
|
-
' "recommendation": "Your decisive recommendation",\n' +
|
|
2093
|
-
' "actionItems": ["step 1", "step 2"],\n' +
|
|
2094
|
-
' "planUpdate": "paragraph for plan update (only if type=plan_update)",\n' +
|
|
2095
|
-
' "resolvedQuestion": {"question": "...", "answer": "..."} }\n' +
|
|
2096
|
-
"```\n" +
|
|
2097
|
-
"Choose type: decision (general), action_items (concrete steps), plan_update (modify active plan), resolve_question (answer a specific question).\n\n" +
|
|
2098
|
-
"**Part 2: Human-readable** — after `---READABLE---`, write the synthesis in markdown:\n" +
|
|
2099
|
-
"## AGREED\n## TRADE-OFFS\n## RECOMMENDATION\n## NEXT STEPS\n\n" +
|
|
2100
|
-
"Be decisive. Output Part 1 JSON first, then ---READABLE---, then Part 2.",
|
|
2101
|
-
`Topic: ${topic}\n\nFinal positions:\n${finalPositions}\n\nFull discussion:\n${allExchanges}`,
|
|
2102
|
-
4096,
|
|
2103
|
-
);
|
|
2104
|
-
|
|
2105
|
-
// Display human-readable part
|
|
2106
|
-
const readablePart = synthesisText.includes("---READABLE---")
|
|
2107
|
-
? synthesisText.split("---READABLE---")[1]?.trim()
|
|
2108
|
-
: synthesisText;
|
|
2109
|
-
yield { type: "content", content: `${readablePart || synthesisText}\n` };
|
|
2110
|
-
|
|
2111
|
-
// Parse structured outcome and execute actions
|
|
2112
|
-
const structuredOutcome = this.councilManager.parseOutcome(synthesisText, topic);
|
|
2113
|
-
if (structuredOutcome) {
|
|
2114
|
-
yield* this.councilManager.executeOutcome(structuredOutcome, topic);
|
|
2115
|
-
if (this.session) {
|
|
2116
|
-
try {
|
|
2117
|
-
appendSystemMessage(this.session.id, `[Council Outcome]\n${JSON.stringify(structuredOutcome)}`);
|
|
2118
|
-
} catch {
|
|
2119
|
-
/* non-critical */
|
|
2120
|
-
}
|
|
2121
|
-
}
|
|
2122
|
-
} else {
|
|
2123
|
-
// Fallback: store text-only outcome (backward compatible)
|
|
2124
|
-
if (this.session) {
|
|
2125
|
-
try {
|
|
2126
|
-
appendSystemMessage(this.session.id, `[Council Outcome]\nTopic: ${topic}\n${synthesisText.slice(0, 2000)}`);
|
|
2127
|
-
} catch {
|
|
2128
|
-
/* non-critical */
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
} catch (err: unknown) {
|
|
2133
|
-
yield { type: "content", content: `[Synthesis error: ${err instanceof Error ? err.message : err}]\n` };
|
|
2134
|
-
}
|
|
2135
|
-
|
|
2136
|
-
// ── Stats + Memory ──
|
|
2137
|
-
const councilStats = this.councilManager.stats;
|
|
2138
|
-
const totalMs = Date.now() - councilStats.startMs;
|
|
2139
|
-
yield {
|
|
2140
|
-
type: "content",
|
|
2141
|
-
content:
|
|
2142
|
-
`\n---\n` +
|
|
2143
|
-
`> Council stats: ${councilStats.calls} API calls, ${(totalMs / 1000).toFixed(1)}s total, ` +
|
|
2144
|
-
`${active.length} participants, synthesis ${((Date.now() - p3Start) / 1000).toFixed(1)}s\n`,
|
|
2145
|
-
};
|
|
2146
|
-
|
|
2147
|
-
// Save council result to session for memory across conversations
|
|
2148
|
-
if (this.session && this.sessionStore) {
|
|
2149
|
-
const councilRecord = {
|
|
2150
|
-
topic,
|
|
2151
|
-
participants: active.map((a) => ({ role: a.role, model: a.model })),
|
|
2152
|
-
finalPositions: active.map((a) => ({ role: a.role, position: a.position.slice(0, 1000) })),
|
|
2153
|
-
synthesis: synthesisText.slice(0, 2000),
|
|
2154
|
-
convergedPairs: [...pairConverged.entries()].filter(([, v]) => v).map(([k]) => k),
|
|
2155
|
-
stats: { calls: councilStats.calls, durationMs: totalMs },
|
|
2156
|
-
timestamp: new Date().toISOString(),
|
|
2157
|
-
};
|
|
2158
|
-
try {
|
|
2159
|
-
appendSystemMessage(this.session.id, `[Council Memory] ${JSON.stringify(councilRecord)}`);
|
|
2160
|
-
} catch {
|
|
2161
|
-
/* non-critical */
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
|
-
// Store council output as assistant message so the conversation history
|
|
2166
|
-
// stays valid (user→assistant alternation required by most APIs).
|
|
2167
|
-
const councilResponse = synthesisText || "[Council completed — see discussion above]";
|
|
2168
|
-
if (userModelMessage) {
|
|
2169
|
-
this.appendCompletedTurn(userModelMessage, [{ role: "assistant", content: councilResponse }]);
|
|
2170
|
-
}
|
|
2171
|
-
this.councilManager.setLastSynthesis(councilResponse);
|
|
2172
|
-
|
|
2173
|
-
yield { type: "done" };
|
|
2174
|
-
}
|
|
2175
|
-
|
|
2176
|
-
// ========================================================================
|
|
2177
|
-
// processMessageBatchTurn — batch API message processing loop.
|
|
2178
|
-
// Body extracted into BatchTurnRunner (Phase 12.5). Thin wrapper preserved
|
|
2179
|
-
// so MessageProcessorDeps' `processMessageBatchTurn` callback continues to
|
|
2180
|
-
// dispatch through `Agent.processMessageBatchTurn` unchanged.
|
|
2181
|
-
// ========================================================================
|
|
2182
|
-
|
|
2183
|
-
private async *processMessageBatchTurn(args: {
|
|
2184
|
-
userModelMessage: ModelMessage;
|
|
2185
|
-
observer?: ProcessMessageObserver;
|
|
2186
|
-
provider: LegacyProvider;
|
|
2187
|
-
subagents: CustomSubagentConfig[];
|
|
2188
|
-
system: string;
|
|
2189
|
-
runtime: ReturnType<typeof resolveModelRuntime>;
|
|
2190
|
-
modelInfo: ReturnType<typeof getModelInfo>;
|
|
2191
|
-
signal: AbortSignal;
|
|
2192
|
-
}): AsyncGenerator<StreamChunk, void, unknown> {
|
|
2193
|
-
const runner = new BatchTurnRunner(this._buildBatchTurnRunnerDeps());
|
|
2194
|
-
yield* runner.run(args);
|
|
2195
|
-
}
|
|
2196
|
-
|
|
2197
|
-
/**
|
|
2198
|
-
* Build the DI surface BatchTurnRunner (Phase 12.5) needs to reach back
|
|
2199
|
-
* into Agent state without holding a circular reference. Callback names
|
|
2200
|
-
* align with `MessageProcessorDeps` where the signature matches so a
|
|
2201
|
-
* future `TurnRunnerDepsBase` hoist is mechanical. Built per call —
|
|
2202
|
-
* allocation cost is negligible against the batch polling spend.
|
|
2203
|
-
*/
|
|
2204
|
-
private _buildBatchTurnRunnerDeps(): BatchTurnRunnerDeps {
|
|
2205
|
-
const self = this;
|
|
2206
|
-
return {
|
|
2207
|
-
get messages() {
|
|
2208
|
-
return self.messages;
|
|
2209
|
-
},
|
|
2210
|
-
get bash() {
|
|
2211
|
-
return self.bash;
|
|
2212
|
-
},
|
|
2213
|
-
get mode() {
|
|
2214
|
-
return self.mode;
|
|
2215
|
-
},
|
|
2216
|
-
get maxToolRounds() {
|
|
2217
|
-
return self.maxToolRounds;
|
|
2218
|
-
},
|
|
2219
|
-
get maxTokens() {
|
|
2220
|
-
return self.maxTokens;
|
|
2221
|
-
},
|
|
2222
|
-
get schedules() {
|
|
2223
|
-
return self.schedules;
|
|
2224
|
-
},
|
|
2225
|
-
get sendTelegramFile() {
|
|
2226
|
-
return self.sendTelegramFile;
|
|
2227
|
-
},
|
|
2228
|
-
getSessionId: () => self.session?.id ?? null,
|
|
2229
|
-
getCompactedThisTurn: () => self._compactedThisTurn,
|
|
2230
|
-
setCompactedThisTurn: (v) => {
|
|
2231
|
-
self._compactedThisTurn = v;
|
|
2232
|
-
},
|
|
2233
|
-
setLastProviderOptionsShape: (shape) => {
|
|
2234
|
-
self._lastProviderOptionsShape = shape;
|
|
2235
|
-
},
|
|
2236
|
-
getBatchClientOptions: (signal) => self.getBatchClientOptions(signal),
|
|
2237
|
-
getCompactionSettings: (cw) => self.getCompactionSettings(cw),
|
|
2238
|
-
compactForContext: (provider, system, cw, signal, settings, overflow) =>
|
|
2239
|
-
self.compactForContext(provider, system, cw, signal, settings, overflow),
|
|
2240
|
-
postTurnCompact: (provider, system, cw, signal) => self.postTurnCompact(provider, system, cw, signal),
|
|
2241
|
-
createTools: (bash, provider, mode, opts) => createTools(bash, provider, mode, opts),
|
|
2242
|
-
runTask: (request, signal) => self.runTask(request, signal),
|
|
2243
|
-
runDelegation: (request, signal) => self.runDelegation(request, signal),
|
|
2244
|
-
readDelegation: (id) => self.readDelegation(id),
|
|
2245
|
-
listDelegations: () => self.listDelegations(),
|
|
2246
|
-
executeBatchToolCall: (tools, toolCall, messages, signal) =>
|
|
2247
|
-
self.executeBatchToolCall(tools, toolCall, messages, signal),
|
|
2248
|
-
appendCompletedTurn: (user, asst) => self.appendCompletedTurn(user, asst),
|
|
2249
|
-
discardAbortedTurn: (user) => self.discardAbortedTurn(user),
|
|
2250
|
-
recordUsage: (usage, source, model) => self.recordUsage(usage, source, model),
|
|
2251
|
-
};
|
|
2252
|
-
}
|
|
2253
|
-
|
|
2254
|
-
private appendCompletedTurn(userMessage: ModelMessage, newMessages: ModelMessage[]): void {
|
|
2255
|
-
if (newMessages.length === 0) return;
|
|
2256
|
-
|
|
2257
|
-
const userIndex = this.messages.lastIndexOf(userMessage);
|
|
2258
|
-
if (!this.sessionStore || !this.session) {
|
|
2259
|
-
if (userIndex >= 0 && this.messageSeqs[userIndex] == null) {
|
|
2260
|
-
this.messageSeqs[userIndex] = null;
|
|
2261
|
-
}
|
|
2262
|
-
this.messages.push(...newMessages);
|
|
2263
|
-
this.messageSeqs.push(...newMessages.map(() => null));
|
|
2264
|
-
return;
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
// Phase A5 — if the user message already has a persisted seq (set by
|
|
2268
|
-
// the write-ahead path), skip re-inserting it. The write-ahead row
|
|
2269
|
-
// will be upserted to status='completed' on the next `appendMessages`
|
|
2270
|
-
// call that sees it via ON CONFLICT, but here we only need to insert
|
|
2271
|
-
// the *new* assistant/tool messages so they get fresh sequence
|
|
2272
|
-
// numbers contiguous with the user row.
|
|
2273
|
-
const existingUserSeq = userIndex >= 0 ? this.messageSeqs[userIndex] : null;
|
|
2274
|
-
if (typeof existingUserSeq === "number") {
|
|
2275
|
-
// User row is already persisted (write-ahead). Insert only the new
|
|
2276
|
-
// assistant/tool messages so they get fresh sequence numbers
|
|
2277
|
-
// contiguous with the user row. Then flip the user row's status
|
|
2278
|
-
// from 'pending' to 'completed' so forensics + replay tooling can
|
|
2279
|
-
// tell the turn settled cleanly.
|
|
2280
|
-
const insertedSeqs = appendMessages(this.session.id, newMessages);
|
|
2281
|
-
markMessageCompleted(this.session.id, existingUserSeq);
|
|
2282
|
-
this.messages.push(...newMessages);
|
|
2283
|
-
this.messageSeqs.push(...insertedSeqs);
|
|
2284
|
-
this.sessionStore.touchSession(this.session.id, this.bash.getCwd());
|
|
2285
|
-
this.session = this.sessionStore.getRequiredSession(this.session.id);
|
|
2286
|
-
return;
|
|
2287
|
-
}
|
|
2288
|
-
|
|
2289
|
-
const insertedSeqs = appendMessages(this.session.id, [userMessage, ...newMessages]);
|
|
2290
|
-
if (userIndex >= 0) {
|
|
2291
|
-
this.messageSeqs[userIndex] = insertedSeqs[0] ?? this.messageSeqs[userIndex];
|
|
2292
|
-
}
|
|
2293
|
-
this.messages.push(...newMessages);
|
|
2294
|
-
this.messageSeqs.push(...insertedSeqs.slice(1));
|
|
2295
|
-
this.sessionStore.touchSession(this.session.id, this.bash.getCwd());
|
|
2296
|
-
this.session = this.sessionStore.getRequiredSession(this.session.id);
|
|
2297
|
-
}
|
|
2298
|
-
|
|
2299
|
-
private fireHook(
|
|
2300
|
-
input: Parameters<typeof executeEventHooks>[0],
|
|
2301
|
-
signal?: AbortSignal,
|
|
2302
|
-
): Promise<Awaited<ReturnType<typeof executeEventHooks>>> {
|
|
2303
|
-
return executeEventHooks(input, this.bash.getCwd(), signal);
|
|
2304
|
-
}
|
|
2305
|
-
|
|
2306
|
-
// ========================================================================
|
|
2307
|
-
// processMessage — main streaming turn loop (PIL enrichment, routing, LLM
|
|
2308
|
-
// stream, tool execution, compaction, hooks, observer notifications)
|
|
2309
|
-
// ========================================================================
|
|
2310
|
-
|
|
2311
|
-
async *processMessage(
|
|
2312
|
-
userMessage: string,
|
|
2313
|
-
observer?: ProcessMessageObserver,
|
|
2314
|
-
images?: Array<{ path: string; mediaType: string; base64: string }>,
|
|
2315
|
-
): AsyncGenerator<StreamChunk, void, unknown> {
|
|
2316
|
-
const processor = new MessageProcessor(this._buildMessageProcessorDeps());
|
|
2317
|
-
yield* processor.run(userMessage, observer, images);
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
/**
|
|
2321
|
-
* Build the DI surface MessageProcessor (Phase 12.4) needs to reach back
|
|
2322
|
-
* into Agent state without holding a circular reference. Exposes array
|
|
2323
|
-
* references for in-place mutation (messages/messageSeqs) and bound
|
|
2324
|
-
* callbacks for behavior. Built per call — allocation cost is negligible
|
|
2325
|
-
* against the streamText spend.
|
|
2326
|
-
*/
|
|
2327
|
-
private _buildMessageProcessorDeps(): MessageProcessorDeps {
|
|
2328
|
-
const self = this;
|
|
2329
|
-
return {
|
|
2330
|
-
get messages() {
|
|
2331
|
-
return self.messages;
|
|
2332
|
-
},
|
|
2333
|
-
get messageSeqs() {
|
|
2334
|
-
return self.messageSeqs;
|
|
2335
|
-
},
|
|
2336
|
-
get session() {
|
|
2337
|
-
return self.session;
|
|
2338
|
-
},
|
|
2339
|
-
get sessionStore() {
|
|
2340
|
-
return self.sessionStore;
|
|
2341
|
-
},
|
|
2342
|
-
get bash() {
|
|
2343
|
-
return self.bash;
|
|
2344
|
-
},
|
|
2345
|
-
get mode() {
|
|
2346
|
-
return self.mode;
|
|
2347
|
-
},
|
|
2348
|
-
get modelId() {
|
|
2349
|
-
return self.modelId;
|
|
2350
|
-
},
|
|
2351
|
-
get providerId() {
|
|
2352
|
-
return self.providerId;
|
|
2353
|
-
},
|
|
2354
|
-
get maxToolRounds() {
|
|
2355
|
-
return self.maxToolRounds;
|
|
2356
|
-
},
|
|
2357
|
-
get batchApi() {
|
|
2358
|
-
return self.batchApi;
|
|
2359
|
-
},
|
|
2360
|
-
get permissionMode() {
|
|
2361
|
-
return self.permissionMode;
|
|
2362
|
-
},
|
|
2363
|
-
get schedules() {
|
|
2364
|
-
return self.schedules;
|
|
2365
|
-
},
|
|
2366
|
-
get sendTelegramFile() {
|
|
2367
|
-
return self.sendTelegramFile;
|
|
2368
|
-
},
|
|
2369
|
-
get externalAbortContext() {
|
|
2370
|
-
return self.externalAbortContext;
|
|
2371
|
-
},
|
|
2372
|
-
get pendingCalls() {
|
|
2373
|
-
return self.pendingCalls;
|
|
2374
|
-
},
|
|
2375
|
-
get councilManager() {
|
|
2376
|
-
return self.councilManager;
|
|
2377
|
-
},
|
|
2378
|
-
get crossTurnDedup() {
|
|
2379
|
-
return self._crossTurnDedup;
|
|
2380
|
-
},
|
|
2381
|
-
get readBudget() {
|
|
2382
|
-
return self._readBudget;
|
|
2383
|
-
},
|
|
2384
|
-
get priorWarningIdsInSession() {
|
|
2385
|
-
return self._priorWarningIdsInSession;
|
|
2386
|
-
},
|
|
2387
|
-
get sessionEEGuidance() {
|
|
2388
|
-
return self._sessionEEGuidance;
|
|
2389
|
-
},
|
|
2390
|
-
get flowReady() {
|
|
2391
|
-
return self._flowReady;
|
|
2392
|
-
},
|
|
2393
|
-
getAbortController: () => self.abortController,
|
|
2394
|
-
setAbortController: (c) => {
|
|
2395
|
-
self.abortController = c;
|
|
2396
|
-
},
|
|
2397
|
-
getSessionStartHookFired: () => self.sessionStartHookFired,
|
|
2398
|
-
setSessionStartHookFired: (v) => {
|
|
2399
|
-
self.sessionStartHookFired = v;
|
|
2400
|
-
},
|
|
2401
|
-
getPlanContext: () => self.planContext,
|
|
2402
|
-
setPlanContext: (v) => {
|
|
2403
|
-
self.planContext = v;
|
|
2404
|
-
},
|
|
2405
|
-
getResumeDigest: () => self._resumeDigest,
|
|
2406
|
-
setResumeDigest: (v) => {
|
|
2407
|
-
self._resumeDigest = v;
|
|
2408
|
-
},
|
|
2409
|
-
getActiveRunId: () => self._activeRunId,
|
|
2410
|
-
getPendingCwdNote: () => self._pendingCwdNote,
|
|
2411
|
-
setPendingCwdNote: (v) => {
|
|
2412
|
-
self._pendingCwdNote = v;
|
|
2413
|
-
},
|
|
2414
|
-
setPilActive: (v) => {
|
|
2415
|
-
self._pilActive = v;
|
|
2416
|
-
},
|
|
2417
|
-
setPilEnrichmentDelta: (n) => {
|
|
2418
|
-
self._pilEnrichmentDelta = n;
|
|
2419
|
-
},
|
|
2420
|
-
setCurrentCallId: (id) => {
|
|
2421
|
-
self._currentCallId = id;
|
|
2422
|
-
},
|
|
2423
|
-
setLastProviderOptionsShape: (shape) => {
|
|
2424
|
-
self._lastProviderOptionsShape = shape;
|
|
2425
|
-
},
|
|
2426
|
-
setLastPromptBreakdown: (b) => {
|
|
2427
|
-
self._lastPromptBreakdown = b;
|
|
2428
|
-
},
|
|
2429
|
-
setCompactedThisTurn: (v) => {
|
|
2430
|
-
self._compactedThisTurn = v;
|
|
2431
|
-
},
|
|
2432
|
-
getCompactedThisTurn: () => self._compactedThisTurn,
|
|
2433
|
-
setTurnUserGoalExcerpt: (v) => {
|
|
2434
|
-
self._turnUserGoalExcerpt = v;
|
|
2435
|
-
},
|
|
2436
|
-
setTurnAssistantReasoning: (v) => {
|
|
2437
|
-
self._turnAssistantReasoning = v;
|
|
2438
|
-
},
|
|
2439
|
-
appendTurnAssistantReasoning: (delta) => {
|
|
2440
|
-
self._turnAssistantReasoning = (self._turnAssistantReasoning + delta).slice(-400);
|
|
2441
|
-
},
|
|
2442
|
-
getTurnAssistantReasoning: () => self._turnAssistantReasoning,
|
|
2443
|
-
setPriorWarningIdsInSession: (s) => {
|
|
2444
|
-
self._priorWarningIdsInSession = s;
|
|
2445
|
-
},
|
|
2446
|
-
setMessages: (m) => {
|
|
2447
|
-
self.messages = m;
|
|
2448
|
-
},
|
|
2449
|
-
requireProvider: () => self.requireProvider(),
|
|
2450
|
-
emitSubagentStatus: (s) => self.emitSubagentStatus(s),
|
|
2451
|
-
fireHook: (input, signal) =>
|
|
2452
|
-
self.fireHook(input as Parameters<Agent["fireHook"]>[0], signal) as ReturnType<
|
|
2453
|
-
MessageProcessorDeps["fireHook"]
|
|
2454
|
-
>,
|
|
2455
|
-
consumeBackgroundNotifications: () => self.consumeBackgroundNotifications(),
|
|
2456
|
-
initOAuthProvider: () => self._initOAuthProvider(),
|
|
2457
|
-
buildRecentTurnsSummary: () => self._buildRecentTurnsSummary(),
|
|
2458
|
-
estimateProjectSize: () => self._estimateProjectSize(),
|
|
2459
|
-
countFilesTouched: () => self._countFilesTouched(),
|
|
2460
|
-
getCompactionSettings: (cw) => self.getCompactionSettings(cw),
|
|
2461
|
-
compactForContext: (provider, system, cw, signal, settings, overflow) =>
|
|
2462
|
-
self.compactForContext(provider, system, cw, signal, settings, overflow),
|
|
2463
|
-
postTurnCompact: (provider, system, cw, signal) => self.postTurnCompact(provider, system, cw, signal),
|
|
2464
|
-
runTask: (request, signal) => self.runTask(request, signal),
|
|
2465
|
-
runDelegation: (request, signal) => self.runDelegation(request, signal),
|
|
2466
|
-
readDelegation: (id) => self.readDelegation(id),
|
|
2467
|
-
listDelegations: () => self.listDelegations(),
|
|
2468
|
-
appendCompletedTurn: (user, asst) => self.appendCompletedTurn(user, asst),
|
|
2469
|
-
discardAbortedTurn: (user) => self.discardAbortedTurn(user),
|
|
2470
|
-
recordUsage: (usage, source, model) => self.recordUsage(usage, source, model),
|
|
2471
|
-
respondToToolApproval: (id, ok) => self.respondToToolApproval(id, ok),
|
|
2472
|
-
runCouncilV2: (msg, opts) => self.runCouncilV2(msg, opts),
|
|
2473
|
-
processMessage: (msg, obs, imgs) => self.processMessage(msg, obs, imgs),
|
|
2474
|
-
processMessageBatchTurn: (args) => self.processMessageBatchTurn(args),
|
|
2475
|
-
};
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
// ========================================================================
|
|
2479
|
-
// processMessage body extracted into MessageProcessor (Phase 12.4).
|
|
2480
|
-
// The single original implementation now lives in
|
|
2481
|
-
// `src/orchestrator/message-processor.ts`. The thin wrapper above is the
|
|
2482
|
-
// only entry point.
|
|
2483
|
-
// ========================================================================
|
|
2484
|
-
|
|
2485
|
-
// ========================================================================
|
|
2486
|
-
// Private helper methods — summary, estimation, verify
|
|
2487
|
-
// ========================================================================
|
|
2488
|
-
|
|
2489
|
-
private _buildRecentTurnsSummary(): string | null {
|
|
2490
|
-
if (this.messages.length < 2) return null;
|
|
2491
|
-
const recent = this.messages.slice(-6);
|
|
2492
|
-
const parts: string[] = [];
|
|
2493
|
-
for (const msg of recent) {
|
|
2494
|
-
if (msg.role !== "user" && msg.role !== "assistant") continue;
|
|
2495
|
-
const text =
|
|
2496
|
-
typeof msg.content === "string"
|
|
2497
|
-
? msg.content
|
|
2498
|
-
: Array.isArray(msg.content)
|
|
2499
|
-
? msg.content
|
|
2500
|
-
.filter((p: { type: string }) => p.type === "text")
|
|
2501
|
-
.map((p: { type: string; text?: string }) => p.text ?? "")
|
|
2502
|
-
.join("")
|
|
2503
|
-
: "";
|
|
2504
|
-
if (!text) continue;
|
|
2505
|
-
const snippet = text.length > 80 ? `${text.slice(0, 77)}...` : text;
|
|
2506
|
-
parts.push(`[${msg.role}]: ${snippet}`);
|
|
2507
|
-
}
|
|
2508
|
-
return parts.length > 0 ? parts.join(" | ") : null;
|
|
2509
|
-
}
|
|
2510
|
-
|
|
2511
|
-
private _estimateProjectSize(): "small" | "medium" | "large" | null {
|
|
2512
|
-
try {
|
|
2513
|
-
const fs = require("fs");
|
|
2514
|
-
const path = require("path");
|
|
2515
|
-
const cwd = this.bash.getCwd();
|
|
2516
|
-
const srcDir = path.join(cwd, "src");
|
|
2517
|
-
if (!fs.existsSync(srcDir)) return null;
|
|
2518
|
-
let count = 0;
|
|
2519
|
-
const walk = (dir: string) => {
|
|
2520
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
2521
|
-
if (entry.name === "node_modules" || entry.name === ".git") continue;
|
|
2522
|
-
if (entry.isDirectory()) walk(path.join(dir, entry.name));
|
|
2523
|
-
else if (/\.(ts|tsx|js|jsx|py|go|rs)$/.test(entry.name)) count++;
|
|
2524
|
-
if (count > 200) return;
|
|
2525
|
-
}
|
|
2526
|
-
};
|
|
2527
|
-
walk(srcDir);
|
|
2528
|
-
if (count <= 20) return "small";
|
|
2529
|
-
if (count <= 100) return "medium";
|
|
2530
|
-
return "large";
|
|
2531
|
-
} catch {
|
|
2532
|
-
return null;
|
|
2533
|
-
}
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
|
-
private _countFilesTouched(): number {
|
|
2537
|
-
let count = 0;
|
|
2538
|
-
for (const msg of this.messages) {
|
|
2539
|
-
if (msg.role !== "assistant" || !Array.isArray(msg.content)) continue;
|
|
2540
|
-
for (const part of msg.content) {
|
|
2541
|
-
if ((part as { type: string }).type === "tool-call") {
|
|
2542
|
-
const tc = part as { type: string; toolName?: string; args?: Record<string, unknown> };
|
|
2543
|
-
if (tc.toolName === "write_file" || tc.toolName === "edit_file" || tc.toolName === "bash") count++;
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
}
|
|
2547
|
-
return count;
|
|
2548
|
-
}
|
|
2549
|
-
|
|
2550
|
-
private requireProvider(): LegacyProvider {
|
|
2551
|
-
if (!this.provider) {
|
|
2552
|
-
throw new Error("API key required. Add an API key to continue.");
|
|
2553
|
-
}
|
|
2554
|
-
|
|
2555
|
-
return this.provider;
|
|
2556
|
-
}
|
|
2557
|
-
|
|
2558
|
-
/**
|
|
2559
|
-
* One-shot async init: upgrades the OpenAI provider to use OAuth tokens when
|
|
2560
|
-
* stored tokens are available and no explicit API key was supplied by the user.
|
|
2561
|
-
* Called at the start of processMessage so the first real LLM call benefits
|
|
2562
|
-
* from OAuth without requiring a sync constructor change.
|
|
2563
|
-
*
|
|
2564
|
-
* Idempotent: skips on second call and for non-OpenAI providers.
|
|
2565
|
-
* Fail-open: any error leaves the existing provider untouched.
|
|
2566
|
-
*/
|
|
2567
|
-
private async _initOAuthProvider(): Promise<void> {
|
|
2568
|
-
if (this._oauthInitDone) return;
|
|
2569
|
-
this._oauthInitDone = true;
|
|
2570
|
-
|
|
2571
|
-
// Only upgrade when there is no explicit API key — OAuth is an alternative
|
|
2572
|
-
// auth path, not an override when the user deliberately passed a key.
|
|
2573
|
-
// The boot wizard in src/index.ts uses the literal "oauth" as a sentinel
|
|
2574
|
-
// to signal "no API key but OAuth tokens exist", so treat that as "no
|
|
2575
|
-
// key" here.
|
|
2576
|
-
if (this.apiKey && this.apiKey !== "oauth") return;
|
|
2577
|
-
|
|
2578
|
-
try {
|
|
2579
|
-
const { listOAuthProviderIds } = await import("../providers/auth/registry.js");
|
|
2580
|
-
const ids = await listOAuthProviderIds();
|
|
2581
|
-
if (!ids.includes(this.providerId)) return;
|
|
2582
|
-
|
|
2583
|
-
const effectiveBaseURL =
|
|
2584
|
-
this.baseURL &&
|
|
2585
|
-
this.baseURL !== (await import("../providers/endpoints.js").then((m) => m.apiBaseFor("anthropic")))
|
|
2586
|
-
? this.baseURL
|
|
2587
|
-
: undefined;
|
|
2588
|
-
const result = await createProviderFactoryAsync(this.providerId, {
|
|
2589
|
-
baseURL: effectiveBaseURL ?? undefined,
|
|
2590
|
-
});
|
|
2591
|
-
this.provider = result.factory;
|
|
2592
|
-
} catch {
|
|
2593
|
-
// Fail-open — provider remains null; requireProvider() will surface the error
|
|
2594
|
-
}
|
|
2595
|
-
}
|
|
2596
|
-
|
|
2597
|
-
async detectVerifyRecipe(settings?: SandboxSettings, abortSignal?: AbortSignal): Promise<VerifyRecipe | null> {
|
|
2598
|
-
try {
|
|
2599
|
-
const result = await this.runTaskRequest(
|
|
2600
|
-
{
|
|
2601
|
-
agent: "verify-detect",
|
|
2602
|
-
description: "Detect verification recipe",
|
|
2603
|
-
prompt: buildVerifyDetectPrompt(this.bash.getCwd(), settings ?? this.bash.getSandboxSettings()),
|
|
2604
|
-
},
|
|
2605
|
-
undefined,
|
|
2606
|
-
abortSignal,
|
|
2607
|
-
);
|
|
2608
|
-
if (!result.success || !result.output) return null;
|
|
2609
|
-
const maybeJson = extractJsonObject(result.output);
|
|
2610
|
-
if (!maybeJson) return null;
|
|
2611
|
-
return normalizeVerifyRecipe(JSON.parse(maybeJson));
|
|
2612
|
-
} catch {
|
|
2613
|
-
return null;
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
|
|
2617
|
-
async runVerify(onProgress?: (detail: string) => void, abortSignal?: AbortSignal): Promise<ToolResult> {
|
|
2618
|
-
this.abortController = new AbortController();
|
|
2619
|
-
const signal = abortSignal ?? this.abortController.signal;
|
|
2620
|
-
const userModelMessage: ModelMessage = { role: "user", content: "/verify" };
|
|
2621
|
-
this.messages.push(userModelMessage);
|
|
2622
|
-
this.messageSeqs.push(null);
|
|
2623
|
-
|
|
2624
|
-
try {
|
|
2625
|
-
await this.consumeBackgroundNotifications();
|
|
2626
|
-
const result = await runVerifyOrchestration(this, { onProgress, abortSignal: signal });
|
|
2627
|
-
const assistantText = result.output || result.error || "Verification completed.";
|
|
2628
|
-
this.appendCompletedTurn(userModelMessage, [{ role: "assistant", content: assistantText }]);
|
|
2629
|
-
return result;
|
|
2630
|
-
} catch (err: unknown) {
|
|
2631
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
2632
|
-
const failureText = signal.aborted ? "Verification aborted." : `Verification failed: ${msg}`;
|
|
2633
|
-
this.appendCompletedTurn(userModelMessage, [{ role: "assistant", content: failureText }]);
|
|
2634
|
-
return { success: false, output: failureText };
|
|
2635
|
-
} finally {
|
|
2636
|
-
if (this.abortController?.signal === signal) {
|
|
2637
|
-
this.abortController = null;
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
}
|