attocode 0.2.3 → 0.2.5
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/CHANGELOG.md +122 -1
- package/README.md +65 -5
- package/dist/src/adapters.d.ts +2 -1
- package/dist/src/adapters.d.ts.map +1 -1
- package/dist/src/adapters.js +74 -12
- package/dist/src/adapters.js.map +1 -1
- package/dist/src/agent/agent-builder.d.ts +117 -0
- package/dist/src/agent/agent-builder.d.ts.map +1 -0
- package/dist/src/agent/agent-builder.js +204 -0
- package/dist/src/agent/agent-builder.js.map +1 -0
- package/dist/src/agent/feature-initializer.d.ts +80 -0
- package/dist/src/agent/feature-initializer.d.ts.map +1 -0
- package/dist/src/agent/feature-initializer.js +677 -0
- package/dist/src/agent/feature-initializer.js.map +1 -0
- package/dist/src/agent/index.d.ts +13 -0
- package/dist/src/agent/index.d.ts.map +1 -0
- package/dist/src/agent/index.js +13 -0
- package/dist/src/agent/index.js.map +1 -0
- package/dist/src/agent/message-builder.d.ts +50 -0
- package/dist/src/agent/message-builder.d.ts.map +1 -0
- package/dist/src/agent/message-builder.js +173 -0
- package/dist/src/agent/message-builder.js.map +1 -0
- package/dist/src/agent/session-api.d.ts +94 -0
- package/dist/src/agent/session-api.d.ts.map +1 -0
- package/dist/src/agent/session-api.js +262 -0
- package/dist/src/agent/session-api.js.map +1 -0
- package/dist/src/agent-tools/lsp-file-tools.d.ts +1 -1
- package/dist/src/agent-tools/lsp-file-tools.d.ts.map +1 -1
- package/dist/src/agent.d.ts +52 -213
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +544 -4072
- package/dist/src/agent.js.map +1 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +2 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands/handler.d.ts.map +1 -1
- package/dist/src/commands/handler.js +18 -9
- package/dist/src/commands/handler.js.map +1 -1
- package/dist/src/commands/init-commands.d.ts.map +1 -1
- package/dist/src/commands/init-commands.js +16 -1
- package/dist/src/commands/init-commands.js.map +1 -1
- package/dist/src/commands/init.d.ts.map +1 -1
- package/dist/src/commands/init.js +31 -0
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/config/base-types.d.ts +45 -0
- package/dist/src/config/base-types.d.ts.map +1 -0
- package/dist/src/config/base-types.js +9 -0
- package/dist/src/config/base-types.js.map +1 -0
- package/dist/src/config/config-manager.d.ts +35 -0
- package/dist/src/config/config-manager.d.ts.map +1 -0
- package/dist/src/config/config-manager.js +108 -0
- package/dist/src/config/config-manager.js.map +1 -0
- package/dist/src/config/index.d.ts +4 -0
- package/dist/src/config/index.d.ts.map +1 -0
- package/dist/src/config/index.js +3 -0
- package/dist/src/config/index.js.map +1 -0
- package/dist/src/config/schema.d.ts +1546 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +268 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/config.d.ts +4 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +8 -12
- package/dist/src/config.js.map +1 -1
- package/dist/src/core/agent-state-machine.d.ts +131 -0
- package/dist/src/core/agent-state-machine.d.ts.map +1 -0
- package/dist/src/core/agent-state-machine.js +302 -0
- package/dist/src/core/agent-state-machine.js.map +1 -0
- package/dist/src/core/base-manager.d.ts +79 -0
- package/dist/src/core/base-manager.d.ts.map +1 -0
- package/dist/src/core/base-manager.js +170 -0
- package/dist/src/core/base-manager.js.map +1 -0
- package/dist/src/core/completion-analyzer.d.ts +15 -0
- package/dist/src/core/completion-analyzer.d.ts.map +1 -0
- package/dist/src/core/completion-analyzer.js +53 -0
- package/dist/src/core/completion-analyzer.js.map +1 -0
- package/dist/src/core/execution-loop.d.ts +46 -0
- package/dist/src/core/execution-loop.d.ts.map +1 -0
- package/dist/src/core/execution-loop.js +1397 -0
- package/dist/src/core/execution-loop.js.map +1 -0
- package/dist/src/core/index.d.ts +7 -0
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +9 -0
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/process-handlers.d.ts.map +1 -1
- package/dist/src/core/process-handlers.js +14 -0
- package/dist/src/core/process-handlers.js.map +1 -1
- package/dist/src/core/protocol/types.d.ts +12 -12
- package/dist/src/core/response-handler.d.ts +16 -0
- package/dist/src/core/response-handler.d.ts.map +1 -0
- package/dist/src/core/response-handler.js +235 -0
- package/dist/src/core/response-handler.js.map +1 -0
- package/dist/src/core/subagent-spawner.d.ts +43 -0
- package/dist/src/core/subagent-spawner.d.ts.map +1 -0
- package/dist/src/core/subagent-spawner.js +973 -0
- package/dist/src/core/subagent-spawner.js.map +1 -0
- package/dist/src/core/tool-executor.d.ts +59 -0
- package/dist/src/core/tool-executor.d.ts.map +1 -0
- package/dist/src/core/tool-executor.js +682 -0
- package/dist/src/core/tool-executor.js.map +1 -0
- package/dist/src/core/types.d.ts +134 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +12 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/defaults.d.ts +2 -2
- package/dist/src/defaults.d.ts.map +1 -1
- package/dist/src/defaults.js +29 -1
- package/dist/src/defaults.js.map +1 -1
- package/dist/src/integrations/agents/agent-registry.d.ts +262 -0
- package/dist/src/integrations/agents/agent-registry.d.ts.map +1 -0
- package/dist/src/integrations/agents/agent-registry.js +686 -0
- package/dist/src/integrations/agents/agent-registry.js.map +1 -0
- package/dist/src/integrations/agents/async-subagent.d.ts +135 -0
- package/dist/src/integrations/agents/async-subagent.d.ts.map +1 -0
- package/dist/src/integrations/agents/async-subagent.js +213 -0
- package/dist/src/integrations/agents/async-subagent.js.map +1 -0
- package/dist/src/integrations/agents/complexity-classifier.d.ts +86 -0
- package/dist/src/integrations/agents/complexity-classifier.d.ts.map +1 -0
- package/dist/src/integrations/agents/complexity-classifier.js +233 -0
- package/dist/src/integrations/agents/complexity-classifier.js.map +1 -0
- package/dist/src/integrations/agents/delegation-protocol.d.ts +86 -0
- package/dist/src/integrations/agents/delegation-protocol.d.ts.map +1 -0
- package/dist/src/integrations/agents/delegation-protocol.js +127 -0
- package/dist/src/integrations/agents/delegation-protocol.js.map +1 -0
- package/dist/src/integrations/agents/multi-agent.d.ts +150 -0
- package/dist/src/integrations/agents/multi-agent.d.ts.map +1 -0
- package/dist/src/integrations/agents/multi-agent.js +306 -0
- package/dist/src/integrations/agents/multi-agent.js.map +1 -0
- package/dist/src/integrations/agents/result-synthesizer.d.ts +389 -0
- package/dist/src/integrations/agents/result-synthesizer.d.ts.map +1 -0
- package/dist/src/integrations/agents/result-synthesizer.js +951 -0
- package/dist/src/integrations/agents/result-synthesizer.js.map +1 -0
- package/dist/src/integrations/agents/shared-blackboard.d.ts +406 -0
- package/dist/src/integrations/agents/shared-blackboard.d.ts.map +1 -0
- package/dist/src/integrations/agents/shared-blackboard.js +757 -0
- package/dist/src/integrations/agents/shared-blackboard.js.map +1 -0
- package/dist/src/integrations/agents/subagent-output-store.d.ts +91 -0
- package/dist/src/integrations/agents/subagent-output-store.d.ts.map +1 -0
- package/dist/src/integrations/agents/subagent-output-store.js +257 -0
- package/dist/src/integrations/agents/subagent-output-store.js.map +1 -0
- package/dist/src/integrations/auto-compaction.d.ts.map +1 -1
- package/dist/src/integrations/auto-compaction.js +3 -2
- package/dist/src/integrations/auto-compaction.js.map +1 -1
- package/dist/src/integrations/budget/budget-pool.d.ts +115 -0
- package/dist/src/integrations/budget/budget-pool.d.ts.map +1 -0
- package/dist/src/integrations/budget/budget-pool.js +205 -0
- package/dist/src/integrations/budget/budget-pool.js.map +1 -0
- package/dist/src/integrations/budget/cancellation.d.ts +229 -0
- package/dist/src/integrations/budget/cancellation.d.ts.map +1 -0
- package/dist/src/integrations/budget/cancellation.js +520 -0
- package/dist/src/integrations/budget/cancellation.js.map +1 -0
- package/dist/src/integrations/budget/dynamic-budget.d.ts +81 -0
- package/dist/src/integrations/budget/dynamic-budget.d.ts.map +1 -0
- package/dist/src/integrations/budget/dynamic-budget.js +151 -0
- package/dist/src/integrations/budget/dynamic-budget.js.map +1 -0
- package/dist/src/integrations/budget/economics.d.ts +435 -0
- package/dist/src/integrations/budget/economics.d.ts.map +1 -0
- package/dist/src/integrations/budget/economics.js +1007 -0
- package/dist/src/integrations/budget/economics.js.map +1 -0
- package/dist/src/integrations/budget/injection-budget.d.ts +71 -0
- package/dist/src/integrations/budget/injection-budget.d.ts.map +1 -0
- package/dist/src/integrations/budget/injection-budget.js +137 -0
- package/dist/src/integrations/budget/injection-budget.js.map +1 -0
- package/dist/src/integrations/budget/loop-detector.d.ts +105 -0
- package/dist/src/integrations/budget/loop-detector.d.ts.map +1 -0
- package/dist/src/integrations/budget/loop-detector.js +287 -0
- package/dist/src/integrations/budget/loop-detector.js.map +1 -0
- package/dist/src/integrations/budget/phase-tracker.d.ts +114 -0
- package/dist/src/integrations/budget/phase-tracker.d.ts.map +1 -0
- package/dist/src/integrations/budget/phase-tracker.js +262 -0
- package/dist/src/integrations/budget/phase-tracker.js.map +1 -0
- package/dist/src/integrations/budget/resources.d.ts +182 -0
- package/dist/src/integrations/budget/resources.d.ts.map +1 -0
- package/dist/src/integrations/budget/resources.js +318 -0
- package/dist/src/integrations/budget/resources.js.map +1 -0
- package/dist/src/integrations/budget-pool.d.ts +7 -0
- package/dist/src/integrations/budget-pool.d.ts.map +1 -1
- package/dist/src/integrations/budget-pool.js +43 -0
- package/dist/src/integrations/budget-pool.js.map +1 -1
- package/dist/src/integrations/codebase-ast.d.ts +52 -0
- package/dist/src/integrations/codebase-ast.d.ts.map +1 -0
- package/dist/src/integrations/codebase-ast.js +457 -0
- package/dist/src/integrations/codebase-ast.js.map +1 -0
- package/dist/src/integrations/codebase-context.d.ts +18 -0
- package/dist/src/integrations/codebase-context.d.ts.map +1 -1
- package/dist/src/integrations/codebase-context.js +197 -17
- package/dist/src/integrations/codebase-context.js.map +1 -1
- package/dist/src/integrations/compaction.d.ts.map +1 -1
- package/dist/src/integrations/compaction.js +14 -6
- package/dist/src/integrations/compaction.js.map +1 -1
- package/dist/src/integrations/context/auto-compaction.d.ts +210 -0
- package/dist/src/integrations/context/auto-compaction.d.ts.map +1 -0
- package/dist/src/integrations/context/auto-compaction.js +477 -0
- package/dist/src/integrations/context/auto-compaction.js.map +1 -0
- package/dist/src/integrations/context/code-analyzer.d.ts +71 -0
- package/dist/src/integrations/context/code-analyzer.d.ts.map +1 -0
- package/dist/src/integrations/context/code-analyzer.js +448 -0
- package/dist/src/integrations/context/code-analyzer.js.map +1 -0
- package/dist/src/integrations/context/code-selector.d.ts +78 -0
- package/dist/src/integrations/context/code-selector.d.ts.map +1 -0
- package/dist/src/integrations/context/code-selector.js +649 -0
- package/dist/src/integrations/context/code-selector.js.map +1 -0
- package/dist/src/integrations/context/codebase-ast.d.ts +138 -0
- package/dist/src/integrations/context/codebase-ast.d.ts.map +1 -0
- package/dist/src/integrations/context/codebase-ast.js +818 -0
- package/dist/src/integrations/context/codebase-ast.js.map +1 -0
- package/dist/src/integrations/context/codebase-context.d.ts +473 -0
- package/dist/src/integrations/context/codebase-context.d.ts.map +1 -0
- package/dist/src/integrations/context/codebase-context.js +685 -0
- package/dist/src/integrations/context/codebase-context.js.map +1 -0
- package/dist/src/integrations/context/compaction.d.ts +191 -0
- package/dist/src/integrations/context/compaction.d.ts.map +1 -0
- package/dist/src/integrations/context/compaction.js +384 -0
- package/dist/src/integrations/context/compaction.js.map +1 -0
- package/dist/src/integrations/context/context-engineering.d.ts +274 -0
- package/dist/src/integrations/context/context-engineering.d.ts.map +1 -0
- package/dist/src/integrations/context/context-engineering.js +437 -0
- package/dist/src/integrations/context/context-engineering.js.map +1 -0
- package/dist/src/integrations/context/file-cache.d.ts +97 -0
- package/dist/src/integrations/context/file-cache.d.ts.map +1 -0
- package/dist/src/integrations/context/file-cache.js +218 -0
- package/dist/src/integrations/context/file-cache.js.map +1 -0
- package/dist/src/integrations/context/semantic-cache.d.ts +178 -0
- package/dist/src/integrations/context/semantic-cache.d.ts.map +1 -0
- package/dist/src/integrations/context/semantic-cache.js +372 -0
- package/dist/src/integrations/context/semantic-cache.js.map +1 -0
- package/dist/src/integrations/context-engineering.d.ts +8 -0
- package/dist/src/integrations/context-engineering.d.ts.map +1 -1
- package/dist/src/integrations/context-engineering.js +19 -0
- package/dist/src/integrations/context-engineering.js.map +1 -1
- package/dist/src/integrations/economics.d.ts +25 -1
- package/dist/src/integrations/economics.d.ts.map +1 -1
- package/dist/src/integrations/economics.js +217 -38
- package/dist/src/integrations/economics.js.map +1 -1
- package/dist/src/integrations/edit-validator.d.ts +30 -0
- package/dist/src/integrations/edit-validator.d.ts.map +1 -0
- package/dist/src/integrations/edit-validator.js +85 -0
- package/dist/src/integrations/edit-validator.js.map +1 -0
- package/dist/src/integrations/file-cache.d.ts +7 -0
- package/dist/src/integrations/file-cache.d.ts.map +1 -1
- package/dist/src/integrations/file-cache.js +54 -0
- package/dist/src/integrations/file-cache.js.map +1 -1
- package/dist/src/integrations/health-check.d.ts.map +1 -1
- package/dist/src/integrations/health-check.js +3 -2
- package/dist/src/integrations/health-check.js.map +1 -1
- package/dist/src/integrations/hierarchical-config.d.ts +3 -0
- package/dist/src/integrations/hierarchical-config.d.ts.map +1 -1
- package/dist/src/integrations/hierarchical-config.js +3 -0
- package/dist/src/integrations/hierarchical-config.js.map +1 -1
- package/dist/src/integrations/hooks.d.ts +2 -0
- package/dist/src/integrations/hooks.d.ts.map +1 -1
- package/dist/src/integrations/hooks.js +99 -15
- package/dist/src/integrations/hooks.js.map +1 -1
- package/dist/src/integrations/index.d.ts +77 -66
- package/dist/src/integrations/index.d.ts.map +1 -1
- package/dist/src/integrations/index.js +83 -67
- package/dist/src/integrations/index.js.map +1 -1
- package/dist/src/integrations/logger.d.ts +104 -0
- package/dist/src/integrations/logger.d.ts.map +1 -0
- package/dist/src/integrations/logger.js +219 -0
- package/dist/src/integrations/logger.js.map +1 -0
- package/dist/src/integrations/lsp/lsp.d.ts +196 -0
- package/dist/src/integrations/lsp/lsp.d.ts.map +1 -0
- package/dist/src/integrations/lsp/lsp.js +583 -0
- package/dist/src/integrations/lsp/lsp.js.map +1 -0
- package/dist/src/integrations/lsp.d.ts.map +1 -1
- package/dist/src/integrations/lsp.js +5 -4
- package/dist/src/integrations/lsp.js.map +1 -1
- package/dist/src/integrations/mcp/mcp-client.d.ts +279 -0
- package/dist/src/integrations/mcp/mcp-client.d.ts.map +1 -0
- package/dist/src/integrations/mcp/mcp-client.js +755 -0
- package/dist/src/integrations/mcp/mcp-client.js.map +1 -0
- package/dist/src/integrations/mcp/mcp-custom-tools.d.ts +102 -0
- package/dist/src/integrations/mcp/mcp-custom-tools.d.ts.map +1 -0
- package/dist/src/integrations/mcp/mcp-custom-tools.js +232 -0
- package/dist/src/integrations/mcp/mcp-custom-tools.js.map +1 -0
- package/dist/src/integrations/mcp/mcp-tool-search.d.ts +77 -0
- package/dist/src/integrations/mcp/mcp-tool-search.d.ts.map +1 -0
- package/dist/src/integrations/mcp/mcp-tool-search.js +220 -0
- package/dist/src/integrations/mcp/mcp-tool-search.js.map +1 -0
- package/dist/src/integrations/mcp/mcp-tool-validator.d.ts +60 -0
- package/dist/src/integrations/mcp/mcp-tool-validator.d.ts.map +1 -0
- package/dist/src/integrations/mcp/mcp-tool-validator.js +141 -0
- package/dist/src/integrations/mcp/mcp-tool-validator.js.map +1 -0
- package/dist/src/integrations/mcp-client.d.ts.map +1 -1
- package/dist/src/integrations/mcp-client.js +8 -7
- package/dist/src/integrations/mcp-client.js.map +1 -1
- package/dist/src/integrations/observability.d.ts.map +1 -1
- package/dist/src/integrations/observability.js +5 -4
- package/dist/src/integrations/observability.js.map +1 -1
- package/dist/src/integrations/openrouter-pricing.d.ts.map +1 -1
- package/dist/src/integrations/openrouter-pricing.js +4 -3
- package/dist/src/integrations/openrouter-pricing.js.map +1 -1
- package/dist/src/integrations/persistence/codebase-repository.d.ts +45 -0
- package/dist/src/integrations/persistence/codebase-repository.d.ts.map +1 -0
- package/dist/src/integrations/persistence/codebase-repository.js +81 -0
- package/dist/src/integrations/persistence/codebase-repository.js.map +1 -0
- package/dist/src/integrations/persistence/goal-repository.d.ts +71 -0
- package/dist/src/integrations/persistence/goal-repository.d.ts.map +1 -0
- package/dist/src/integrations/persistence/goal-repository.js +184 -0
- package/dist/src/integrations/persistence/goal-repository.js.map +1 -0
- package/dist/src/integrations/persistence/history.d.ts +72 -0
- package/dist/src/integrations/persistence/history.d.ts.map +1 -0
- package/dist/src/integrations/persistence/history.js +165 -0
- package/dist/src/integrations/persistence/history.js.map +1 -0
- package/dist/src/integrations/persistence/persistence.d.ts +49 -0
- package/dist/src/integrations/persistence/persistence.d.ts.map +1 -0
- package/dist/src/integrations/persistence/persistence.js +197 -0
- package/dist/src/integrations/persistence/persistence.js.map +1 -0
- package/dist/src/integrations/persistence/session-repository.d.ts +212 -0
- package/dist/src/integrations/persistence/session-repository.d.ts.map +1 -0
- package/dist/src/integrations/persistence/session-repository.js +770 -0
- package/dist/src/integrations/persistence/session-repository.js.map +1 -0
- package/dist/src/integrations/persistence/session-store.d.ts +184 -0
- package/dist/src/integrations/persistence/session-store.d.ts.map +1 -0
- package/dist/src/integrations/persistence/session-store.js +346 -0
- package/dist/src/integrations/persistence/session-store.js.map +1 -0
- package/dist/src/integrations/persistence/sqlite-store.d.ts +453 -0
- package/dist/src/integrations/persistence/sqlite-store.d.ts.map +1 -0
- package/dist/src/integrations/persistence/sqlite-store.js +676 -0
- package/dist/src/integrations/persistence/sqlite-store.js.map +1 -0
- package/dist/src/integrations/persistence/worker-repository.d.ts +65 -0
- package/dist/src/integrations/persistence/worker-repository.d.ts.map +1 -0
- package/dist/src/integrations/persistence/worker-repository.js +183 -0
- package/dist/src/integrations/persistence/worker-repository.js.map +1 -0
- package/dist/src/integrations/persistence.d.ts.map +1 -1
- package/dist/src/integrations/persistence.js +5 -4
- package/dist/src/integrations/persistence.js.map +1 -1
- package/dist/src/integrations/planning.d.ts.map +1 -1
- package/dist/src/integrations/planning.js +5 -4
- package/dist/src/integrations/planning.js.map +1 -1
- package/dist/src/integrations/quality/auto-checkpoint.d.ts +98 -0
- package/dist/src/integrations/quality/auto-checkpoint.d.ts.map +1 -0
- package/dist/src/integrations/quality/auto-checkpoint.js +252 -0
- package/dist/src/integrations/quality/auto-checkpoint.js.map +1 -0
- package/dist/src/integrations/quality/dead-letter-queue.d.ts +233 -0
- package/dist/src/integrations/quality/dead-letter-queue.d.ts.map +1 -0
- package/dist/src/integrations/quality/dead-letter-queue.js +543 -0
- package/dist/src/integrations/quality/dead-letter-queue.js.map +1 -0
- package/dist/src/integrations/quality/health-check.d.ts +218 -0
- package/dist/src/integrations/quality/health-check.d.ts.map +1 -0
- package/dist/src/integrations/quality/health-check.js +415 -0
- package/dist/src/integrations/quality/health-check.js.map +1 -0
- package/dist/src/integrations/quality/learning-store.d.ts +291 -0
- package/dist/src/integrations/quality/learning-store.d.ts.map +1 -0
- package/dist/src/integrations/quality/learning-store.js +646 -0
- package/dist/src/integrations/quality/learning-store.js.map +1 -0
- package/dist/src/integrations/quality/self-improvement.d.ts +90 -0
- package/dist/src/integrations/quality/self-improvement.d.ts.map +1 -0
- package/dist/src/integrations/quality/self-improvement.js +229 -0
- package/dist/src/integrations/quality/self-improvement.js.map +1 -0
- package/dist/src/integrations/quality/tool-recommendation.d.ts +61 -0
- package/dist/src/integrations/quality/tool-recommendation.d.ts.map +1 -0
- package/dist/src/integrations/quality/tool-recommendation.js +268 -0
- package/dist/src/integrations/quality/tool-recommendation.js.map +1 -0
- package/dist/src/integrations/retry.d.ts +1 -0
- package/dist/src/integrations/retry.d.ts.map +1 -1
- package/dist/src/integrations/retry.js.map +1 -1
- package/dist/src/integrations/routing.d.ts.map +1 -1
- package/dist/src/integrations/routing.js +2 -1
- package/dist/src/integrations/routing.js.map +1 -1
- package/dist/src/integrations/safety/bash-policy.d.ts +33 -0
- package/dist/src/integrations/safety/bash-policy.d.ts.map +1 -0
- package/dist/src/integrations/safety/bash-policy.js +144 -0
- package/dist/src/integrations/safety/bash-policy.js.map +1 -0
- package/dist/src/integrations/safety/edit-validator.d.ts +30 -0
- package/dist/src/integrations/safety/edit-validator.d.ts.map +1 -0
- package/dist/src/integrations/safety/edit-validator.js +87 -0
- package/dist/src/integrations/safety/edit-validator.js.map +1 -0
- package/dist/src/integrations/safety/execution-policy.d.ts +189 -0
- package/dist/src/integrations/safety/execution-policy.d.ts.map +1 -0
- package/dist/src/integrations/safety/execution-policy.js +352 -0
- package/dist/src/integrations/safety/execution-policy.js.map +1 -0
- package/dist/src/integrations/safety/policy-engine.d.ts +55 -0
- package/dist/src/integrations/safety/policy-engine.d.ts.map +1 -0
- package/dist/src/integrations/safety/policy-engine.js +247 -0
- package/dist/src/integrations/safety/policy-engine.js.map +1 -0
- package/dist/src/integrations/safety/safety.d.ts +174 -0
- package/dist/src/integrations/safety/safety.d.ts.map +1 -0
- package/dist/src/integrations/safety/safety.js +470 -0
- package/dist/src/integrations/safety/safety.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/basic.d.ts +81 -0
- package/dist/src/integrations/safety/sandbox/basic.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/basic.js +335 -0
- package/dist/src/integrations/safety/sandbox/basic.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/docker.d.ts +94 -0
- package/dist/src/integrations/safety/sandbox/docker.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/docker.js +294 -0
- package/dist/src/integrations/safety/sandbox/docker.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/index.d.ts +188 -0
- package/dist/src/integrations/safety/sandbox/index.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/index.js +386 -0
- package/dist/src/integrations/safety/sandbox/index.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/landlock.d.ts +59 -0
- package/dist/src/integrations/safety/sandbox/landlock.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/landlock.js +329 -0
- package/dist/src/integrations/safety/sandbox/landlock.js.map +1 -0
- package/dist/src/integrations/safety/sandbox/seatbelt.d.ts +68 -0
- package/dist/src/integrations/safety/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/src/integrations/safety/sandbox/seatbelt.js +298 -0
- package/dist/src/integrations/safety/sandbox/seatbelt.js.map +1 -0
- package/dist/src/integrations/safety/type-checker.d.ts +53 -0
- package/dist/src/integrations/safety/type-checker.d.ts.map +1 -0
- package/dist/src/integrations/safety/type-checker.js +142 -0
- package/dist/src/integrations/safety/type-checker.js.map +1 -0
- package/dist/src/integrations/safety.d.ts.map +1 -1
- package/dist/src/integrations/safety.js +13 -13
- package/dist/src/integrations/safety.js.map +1 -1
- package/dist/src/integrations/sandbox/docker.d.ts.map +1 -1
- package/dist/src/integrations/sandbox/docker.js +2 -1
- package/dist/src/integrations/sandbox/docker.js.map +1 -1
- package/dist/src/integrations/sandbox/index.d.ts.map +1 -1
- package/dist/src/integrations/sandbox/index.js +5 -4
- package/dist/src/integrations/sandbox/index.js.map +1 -1
- package/dist/src/integrations/session-store.d.ts +1 -0
- package/dist/src/integrations/session-store.d.ts.map +1 -1
- package/dist/src/integrations/session-store.js +1 -0
- package/dist/src/integrations/session-store.js.map +1 -1
- package/dist/src/integrations/shared-blackboard.d.ts +3 -0
- package/dist/src/integrations/shared-blackboard.d.ts.map +1 -1
- package/dist/src/integrations/shared-blackboard.js +47 -0
- package/dist/src/integrations/shared-blackboard.js.map +1 -1
- package/dist/src/integrations/skills/skill-executor.d.ts +113 -0
- package/dist/src/integrations/skills/skill-executor.d.ts.map +1 -0
- package/dist/src/integrations/skills/skill-executor.js +270 -0
- package/dist/src/integrations/skills/skill-executor.js.map +1 -0
- package/dist/src/integrations/skills/skills.d.ts +262 -0
- package/dist/src/integrations/skills/skills.d.ts.map +1 -0
- package/dist/src/integrations/skills/skills.js +602 -0
- package/dist/src/integrations/skills/skills.js.map +1 -0
- package/dist/src/integrations/smart-decomposer.d.ts +27 -0
- package/dist/src/integrations/smart-decomposer.d.ts.map +1 -1
- package/dist/src/integrations/smart-decomposer.js +414 -30
- package/dist/src/integrations/smart-decomposer.js.map +1 -1
- package/dist/src/integrations/sqlite-store.d.ts +2 -0
- package/dist/src/integrations/sqlite-store.d.ts.map +1 -1
- package/dist/src/integrations/sqlite-store.js +18 -6
- package/dist/src/integrations/sqlite-store.js.map +1 -1
- package/dist/src/integrations/streaming/pty-shell.d.ts +169 -0
- package/dist/src/integrations/streaming/pty-shell.d.ts.map +1 -0
- package/dist/src/integrations/streaming/pty-shell.js +367 -0
- package/dist/src/integrations/streaming/pty-shell.js.map +1 -0
- package/dist/src/integrations/streaming/streaming.d.ts +102 -0
- package/dist/src/integrations/streaming/streaming.d.ts.map +1 -0
- package/dist/src/integrations/streaming/streaming.js +362 -0
- package/dist/src/integrations/streaming/streaming.js.map +1 -0
- package/dist/src/integrations/swarm/failure-classifier.d.ts +11 -0
- package/dist/src/integrations/swarm/failure-classifier.d.ts.map +1 -0
- package/dist/src/integrations/swarm/failure-classifier.js +95 -0
- package/dist/src/integrations/swarm/failure-classifier.js.map +1 -0
- package/dist/src/integrations/swarm/index.d.ts +2 -1
- package/dist/src/integrations/swarm/index.d.ts.map +1 -1
- package/dist/src/integrations/swarm/index.js +2 -0
- package/dist/src/integrations/swarm/index.js.map +1 -1
- package/dist/src/integrations/swarm/model-selector.d.ts.map +1 -1
- package/dist/src/integrations/swarm/model-selector.js +2 -1
- package/dist/src/integrations/swarm/model-selector.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-budget.d.ts +1 -1
- package/dist/src/integrations/swarm/swarm-budget.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-budget.js +1 -1
- package/dist/src/integrations/swarm/swarm-budget.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-config-loader.d.ts +8 -0
- package/dist/src/integrations/swarm/swarm-config-loader.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-config-loader.js +102 -0
- package/dist/src/integrations/swarm/swarm-config-loader.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-event-bridge.d.ts +74 -0
- package/dist/src/integrations/swarm/swarm-event-bridge.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-event-bridge.js +37 -0
- package/dist/src/integrations/swarm/swarm-event-bridge.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-events.d.ts +4 -1
- package/dist/src/integrations/swarm/swarm-events.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-events.js +1 -1
- package/dist/src/integrations/swarm/swarm-events.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-execution.d.ts +27 -0
- package/dist/src/integrations/swarm/swarm-execution.d.ts.map +1 -0
- package/dist/src/integrations/swarm/swarm-execution.js +1021 -0
- package/dist/src/integrations/swarm/swarm-execution.js.map +1 -0
- package/dist/src/integrations/swarm/swarm-helpers.d.ts +26 -0
- package/dist/src/integrations/swarm/swarm-helpers.d.ts.map +1 -0
- package/dist/src/integrations/swarm/swarm-helpers.js +95 -0
- package/dist/src/integrations/swarm/swarm-helpers.js.map +1 -0
- package/dist/src/integrations/swarm/swarm-lifecycle.d.ts +100 -0
- package/dist/src/integrations/swarm/swarm-lifecycle.d.ts.map +1 -0
- package/dist/src/integrations/swarm/swarm-lifecycle.js +922 -0
- package/dist/src/integrations/swarm/swarm-lifecycle.js.map +1 -0
- package/dist/src/integrations/swarm/swarm-orchestrator.d.ts +96 -192
- package/dist/src/integrations/swarm/swarm-orchestrator.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-orchestrator.js +384 -2528
- package/dist/src/integrations/swarm/swarm-orchestrator.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-quality-gate.js +1 -1
- package/dist/src/integrations/swarm/swarm-quality-gate.js.map +1 -1
- package/dist/src/integrations/swarm/swarm-recovery.d.ts +75 -0
- package/dist/src/integrations/swarm/swarm-recovery.d.ts.map +1 -0
- package/dist/src/integrations/swarm/swarm-recovery.js +550 -0
- package/dist/src/integrations/swarm/swarm-recovery.js.map +1 -0
- package/dist/src/integrations/swarm/swarm-state-store.d.ts +4 -1
- package/dist/src/integrations/swarm/swarm-state-store.d.ts.map +1 -1
- package/dist/src/integrations/swarm/swarm-state-store.js +14 -1
- package/dist/src/integrations/swarm/swarm-state-store.js.map +1 -1
- package/dist/src/integrations/swarm/task-queue.d.ts +11 -1
- package/dist/src/integrations/swarm/task-queue.d.ts.map +1 -1
- package/dist/src/integrations/swarm/task-queue.js +64 -2
- package/dist/src/integrations/swarm/task-queue.js.map +1 -1
- package/dist/src/integrations/swarm/types.d.ts +57 -4
- package/dist/src/integrations/swarm/types.d.ts.map +1 -1
- package/dist/src/integrations/swarm/types.js +9 -0
- package/dist/src/integrations/swarm/types.js.map +1 -1
- package/dist/src/integrations/swarm/worker-pool.d.ts +13 -3
- package/dist/src/integrations/swarm/worker-pool.d.ts.map +1 -1
- package/dist/src/integrations/swarm/worker-pool.js +66 -13
- package/dist/src/integrations/swarm/worker-pool.js.map +1 -1
- package/dist/src/integrations/task-manager.d.ts +33 -1
- package/dist/src/integrations/task-manager.d.ts.map +1 -1
- package/dist/src/integrations/task-manager.js +78 -4
- package/dist/src/integrations/task-manager.js.map +1 -1
- package/dist/src/integrations/tasks/dependency-analyzer.d.ts +34 -0
- package/dist/src/integrations/tasks/dependency-analyzer.d.ts.map +1 -0
- package/dist/src/integrations/tasks/dependency-analyzer.js +232 -0
- package/dist/src/integrations/tasks/dependency-analyzer.js.map +1 -0
- package/dist/src/integrations/tasks/interactive-planning.d.ts +322 -0
- package/dist/src/integrations/tasks/interactive-planning.d.ts.map +1 -0
- package/dist/src/integrations/tasks/interactive-planning.js +655 -0
- package/dist/src/integrations/tasks/interactive-planning.js.map +1 -0
- package/dist/src/integrations/tasks/pending-plan.d.ts +196 -0
- package/dist/src/integrations/tasks/pending-plan.d.ts.map +1 -0
- package/dist/src/integrations/tasks/pending-plan.js +431 -0
- package/dist/src/integrations/tasks/pending-plan.js.map +1 -0
- package/dist/src/integrations/tasks/planning.d.ts +115 -0
- package/dist/src/integrations/tasks/planning.d.ts.map +1 -0
- package/dist/src/integrations/tasks/planning.js +413 -0
- package/dist/src/integrations/tasks/planning.js.map +1 -0
- package/dist/src/integrations/tasks/smart-decomposer.d.ts +316 -0
- package/dist/src/integrations/tasks/smart-decomposer.d.ts.map +1 -0
- package/dist/src/integrations/tasks/smart-decomposer.js +661 -0
- package/dist/src/integrations/tasks/smart-decomposer.js.map +1 -0
- package/dist/src/integrations/tasks/task-manager.d.ts +164 -0
- package/dist/src/integrations/tasks/task-manager.d.ts.map +1 -0
- package/dist/src/integrations/tasks/task-manager.js +383 -0
- package/dist/src/integrations/tasks/task-manager.js.map +1 -0
- package/dist/src/integrations/tasks/task-splitter.d.ts +56 -0
- package/dist/src/integrations/tasks/task-splitter.d.ts.map +1 -0
- package/dist/src/integrations/tasks/task-splitter.js +537 -0
- package/dist/src/integrations/tasks/task-splitter.js.map +1 -0
- package/dist/src/integrations/tasks/verification-gate.d.ts +103 -0
- package/dist/src/integrations/tasks/verification-gate.d.ts.map +1 -0
- package/dist/src/integrations/tasks/verification-gate.js +193 -0
- package/dist/src/integrations/tasks/verification-gate.js.map +1 -0
- package/dist/src/integrations/tasks/work-log.d.ts +87 -0
- package/dist/src/integrations/tasks/work-log.d.ts.map +1 -0
- package/dist/src/integrations/tasks/work-log.js +275 -0
- package/dist/src/integrations/tasks/work-log.js.map +1 -0
- package/dist/src/integrations/utilities/capabilities.d.ts +160 -0
- package/dist/src/integrations/utilities/capabilities.d.ts.map +1 -0
- package/dist/src/integrations/utilities/capabilities.js +426 -0
- package/dist/src/integrations/utilities/capabilities.js.map +1 -0
- package/dist/src/integrations/utilities/diff-utils.d.ts +105 -0
- package/dist/src/integrations/utilities/diff-utils.d.ts.map +1 -0
- package/dist/src/integrations/utilities/diff-utils.js +497 -0
- package/dist/src/integrations/utilities/diff-utils.js.map +1 -0
- package/dist/src/integrations/utilities/environment-facts.d.ts +52 -0
- package/dist/src/integrations/utilities/environment-facts.d.ts.map +1 -0
- package/dist/src/integrations/utilities/environment-facts.js +84 -0
- package/dist/src/integrations/utilities/environment-facts.js.map +1 -0
- package/dist/src/integrations/utilities/file-change-tracker.d.ts +162 -0
- package/dist/src/integrations/utilities/file-change-tracker.d.ts.map +1 -0
- package/dist/src/integrations/utilities/file-change-tracker.js +538 -0
- package/dist/src/integrations/utilities/file-change-tracker.js.map +1 -0
- package/dist/src/integrations/utilities/graph-visualization.d.ts +72 -0
- package/dist/src/integrations/utilities/graph-visualization.d.ts.map +1 -0
- package/dist/src/integrations/utilities/graph-visualization.js +383 -0
- package/dist/src/integrations/utilities/graph-visualization.js.map +1 -0
- package/dist/src/integrations/utilities/hierarchical-config.d.ts +215 -0
- package/dist/src/integrations/utilities/hierarchical-config.d.ts.map +1 -0
- package/dist/src/integrations/utilities/hierarchical-config.js +504 -0
- package/dist/src/integrations/utilities/hierarchical-config.js.map +1 -0
- package/dist/src/integrations/utilities/hooks.d.ts +116 -0
- package/dist/src/integrations/utilities/hooks.d.ts.map +1 -0
- package/dist/src/integrations/utilities/hooks.js +410 -0
- package/dist/src/integrations/utilities/hooks.js.map +1 -0
- package/dist/src/integrations/utilities/ignore.d.ts +143 -0
- package/dist/src/integrations/utilities/ignore.d.ts.map +1 -0
- package/dist/src/integrations/utilities/ignore.js +417 -0
- package/dist/src/integrations/utilities/ignore.js.map +1 -0
- package/dist/src/integrations/utilities/image-renderer.d.ts +119 -0
- package/dist/src/integrations/utilities/image-renderer.d.ts.map +1 -0
- package/dist/src/integrations/utilities/image-renderer.js +306 -0
- package/dist/src/integrations/utilities/image-renderer.js.map +1 -0
- package/dist/src/integrations/utilities/logger.d.ts +104 -0
- package/dist/src/integrations/utilities/logger.d.ts.map +1 -0
- package/dist/src/integrations/utilities/logger.js +219 -0
- package/dist/src/integrations/utilities/logger.js.map +1 -0
- package/dist/src/integrations/utilities/memory.d.ts +116 -0
- package/dist/src/integrations/utilities/memory.d.ts.map +1 -0
- package/dist/src/integrations/utilities/memory.js +311 -0
- package/dist/src/integrations/utilities/memory.js.map +1 -0
- package/dist/src/integrations/utilities/observability.d.ts +162 -0
- package/dist/src/integrations/utilities/observability.d.ts.map +1 -0
- package/dist/src/integrations/utilities/observability.js +407 -0
- package/dist/src/integrations/utilities/observability.js.map +1 -0
- package/dist/src/integrations/utilities/openrouter-pricing.d.ts +67 -0
- package/dist/src/integrations/utilities/openrouter-pricing.d.ts.map +1 -0
- package/dist/src/integrations/utilities/openrouter-pricing.js +166 -0
- package/dist/src/integrations/utilities/openrouter-pricing.js.map +1 -0
- package/dist/src/integrations/utilities/react.d.ts +139 -0
- package/dist/src/integrations/utilities/react.d.ts.map +1 -0
- package/dist/src/integrations/utilities/react.js +273 -0
- package/dist/src/integrations/utilities/react.js.map +1 -0
- package/dist/src/integrations/utilities/retry.d.ts +132 -0
- package/dist/src/integrations/utilities/retry.d.ts.map +1 -0
- package/dist/src/integrations/utilities/retry.js +233 -0
- package/dist/src/integrations/utilities/retry.js.map +1 -0
- package/dist/src/integrations/utilities/routing.d.ts +118 -0
- package/dist/src/integrations/utilities/routing.d.ts.map +1 -0
- package/dist/src/integrations/utilities/routing.js +348 -0
- package/dist/src/integrations/utilities/routing.js.map +1 -0
- package/dist/src/integrations/utilities/rules.d.ts +131 -0
- package/dist/src/integrations/utilities/rules.d.ts.map +1 -0
- package/dist/src/integrations/utilities/rules.js +284 -0
- package/dist/src/integrations/utilities/rules.js.map +1 -0
- package/dist/src/integrations/utilities/sourcegraph.d.ts +169 -0
- package/dist/src/integrations/utilities/sourcegraph.d.ts.map +1 -0
- package/dist/src/integrations/utilities/sourcegraph.js +379 -0
- package/dist/src/integrations/utilities/sourcegraph.js.map +1 -0
- package/dist/src/integrations/utilities/thinking-strategy.d.ts +52 -0
- package/dist/src/integrations/utilities/thinking-strategy.d.ts.map +1 -0
- package/dist/src/integrations/utilities/thinking-strategy.js +129 -0
- package/dist/src/integrations/utilities/thinking-strategy.js.map +1 -0
- package/dist/src/integrations/utilities/thread-manager.d.ts +199 -0
- package/dist/src/integrations/utilities/thread-manager.d.ts.map +1 -0
- package/dist/src/integrations/utilities/thread-manager.js +357 -0
- package/dist/src/integrations/utilities/thread-manager.js.map +1 -0
- package/dist/src/integrations/utilities/token-estimate.d.ts +11 -0
- package/dist/src/integrations/utilities/token-estimate.d.ts.map +1 -0
- package/dist/src/integrations/utilities/token-estimate.js +14 -0
- package/dist/src/integrations/utilities/token-estimate.js.map +1 -0
- package/dist/src/main.js +92 -35
- package/dist/src/main.js.map +1 -1
- package/dist/src/modes/repl.d.ts.map +1 -1
- package/dist/src/modes/repl.js +60 -11
- package/dist/src/modes/repl.js.map +1 -1
- package/dist/src/modes/tui.d.ts.map +1 -1
- package/dist/src/modes/tui.js +57 -10
- package/dist/src/modes/tui.js.map +1 -1
- package/dist/src/modes.js +1 -1
- package/dist/src/modes.js.map +1 -1
- package/dist/src/observability/tracer.d.ts.map +1 -1
- package/dist/src/observability/tracer.js +2 -1
- package/dist/src/observability/tracer.js.map +1 -1
- package/dist/src/persistence/schema.d.ts +2 -0
- package/dist/src/persistence/schema.d.ts.map +1 -1
- package/dist/src/persistence/schema.js +42 -0
- package/dist/src/persistence/schema.js.map +1 -1
- package/dist/src/providers/adapters/anthropic.d.ts +6 -0
- package/dist/src/providers/adapters/anthropic.d.ts.map +1 -1
- package/dist/src/providers/adapters/anthropic.js +101 -16
- package/dist/src/providers/adapters/anthropic.js.map +1 -1
- package/dist/src/providers/adapters/azure.d.ts +74 -0
- package/dist/src/providers/adapters/azure.d.ts.map +1 -0
- package/dist/src/providers/adapters/azure.js +354 -0
- package/dist/src/providers/adapters/azure.js.map +1 -0
- package/dist/src/providers/adapters/mock.d.ts +16 -2
- package/dist/src/providers/adapters/mock.d.ts.map +1 -1
- package/dist/src/providers/adapters/mock.js +44 -3
- package/dist/src/providers/adapters/mock.js.map +1 -1
- package/dist/src/providers/adapters/openai.d.ts +6 -1
- package/dist/src/providers/adapters/openai.d.ts.map +1 -1
- package/dist/src/providers/adapters/openai.js +41 -9
- package/dist/src/providers/adapters/openai.js.map +1 -1
- package/dist/src/providers/adapters/openrouter.d.ts +6 -0
- package/dist/src/providers/adapters/openrouter.d.ts.map +1 -1
- package/dist/src/providers/adapters/openrouter.js +83 -13
- package/dist/src/providers/adapters/openrouter.js.map +1 -1
- package/dist/src/providers/circuit-breaker.d.ts +1 -0
- package/dist/src/providers/circuit-breaker.d.ts.map +1 -1
- package/dist/src/providers/circuit-breaker.js.map +1 -1
- package/dist/src/providers/provider.d.ts.map +1 -1
- package/dist/src/providers/provider.js +2 -1
- package/dist/src/providers/provider.js.map +1 -1
- package/dist/src/providers/resilient-provider.d.ts.map +1 -1
- package/dist/src/providers/resilient-provider.js +2 -1
- package/dist/src/providers/resilient-provider.js.map +1 -1
- package/dist/src/providers/types.d.ts +23 -2
- package/dist/src/providers/types.d.ts.map +1 -1
- package/dist/src/session-picker.d.ts +1 -1
- package/dist/src/session-picker.d.ts.map +1 -1
- package/dist/src/session-picker.js +40 -5
- package/dist/src/session-picker.js.map +1 -1
- package/dist/src/shared/budget-tracker.d.ts +65 -0
- package/dist/src/shared/budget-tracker.d.ts.map +1 -0
- package/dist/src/shared/budget-tracker.js +128 -0
- package/dist/src/shared/budget-tracker.js.map +1 -0
- package/dist/src/shared/context-engine.d.ts +64 -0
- package/dist/src/shared/context-engine.d.ts.map +1 -0
- package/dist/src/shared/context-engine.js +117 -0
- package/dist/src/shared/context-engine.js.map +1 -0
- package/dist/src/shared/index.d.ts +12 -0
- package/dist/src/shared/index.d.ts.map +1 -0
- package/dist/src/shared/index.js +12 -0
- package/dist/src/shared/index.js.map +1 -0
- package/dist/src/shared/persistence.d.ts +57 -0
- package/dist/src/shared/persistence.d.ts.map +1 -0
- package/dist/src/shared/persistence.js +168 -0
- package/dist/src/shared/persistence.js.map +1 -0
- package/dist/src/shared/shared-context-state.d.ts +89 -0
- package/dist/src/shared/shared-context-state.d.ts.map +1 -0
- package/dist/src/shared/shared-context-state.js +175 -0
- package/dist/src/shared/shared-context-state.js.map +1 -0
- package/dist/src/shared/shared-economics-state.d.ts +61 -0
- package/dist/src/shared/shared-economics-state.d.ts.map +1 -0
- package/dist/src/shared/shared-economics-state.js +100 -0
- package/dist/src/shared/shared-economics-state.js.map +1 -0
- package/dist/src/tools/agent.d.ts +1 -1
- package/dist/src/tools/agent.d.ts.map +1 -1
- package/dist/src/tools/bash.d.ts +3 -3
- package/dist/src/tools/bash.d.ts.map +1 -1
- package/dist/src/tools/bash.js +2 -1
- package/dist/src/tools/bash.js.map +1 -1
- package/dist/src/tools/file.d.ts +3 -3
- package/dist/src/tools/file.js +1 -1
- package/dist/src/tools/file.js.map +1 -1
- package/dist/src/tools/permission.d.ts.map +1 -1
- package/dist/src/tools/permission.js +7 -6
- package/dist/src/tools/permission.js.map +1 -1
- package/dist/src/tools/registry.d.ts +1 -1
- package/dist/src/tools/registry.d.ts.map +1 -1
- package/dist/src/tools/registry.js +1 -1
- package/dist/src/tools/registry.js.map +1 -1
- package/dist/src/tools/tasks.d.ts +1 -1
- package/dist/src/tools/tasks.d.ts.map +1 -1
- package/dist/src/tools/types.d.ts +1 -0
- package/dist/src/tools/types.d.ts.map +1 -1
- package/dist/src/tools/types.js.map +1 -1
- package/dist/src/tools/undo.d.ts +1 -1
- package/dist/src/tools/undo.d.ts.map +1 -1
- package/dist/src/tracing/cache-boundary-tracker.d.ts.map +1 -1
- package/dist/src/tracing/cache-boundary-tracker.js +2 -2
- package/dist/src/tracing/cache-boundary-tracker.js.map +1 -1
- package/dist/src/tracing/trace-collector.d.ts +147 -0
- package/dist/src/tracing/trace-collector.d.ts.map +1 -1
- package/dist/src/tracing/trace-collector.js +138 -7
- package/dist/src/tracing/trace-collector.js.map +1 -1
- package/dist/src/tracing/types.d.ts +112 -1
- package/dist/src/tracing/types.d.ts.map +1 -1
- package/dist/src/tracing/types.js.map +1 -1
- package/dist/src/tricks/failure-evidence.d.ts.map +1 -1
- package/dist/src/tricks/failure-evidence.js +2 -1
- package/dist/src/tricks/failure-evidence.js.map +1 -1
- package/dist/src/tricks/recitation.d.ts.map +1 -1
- package/dist/src/tricks/recitation.js +2 -1
- package/dist/src/tricks/recitation.js.map +1 -1
- package/dist/src/tricks/recursive-context.d.ts.map +1 -1
- package/dist/src/tricks/recursive-context.js +2 -2
- package/dist/src/tricks/recursive-context.js.map +1 -1
- package/dist/src/tricks/reversible-compaction.d.ts.map +1 -1
- package/dist/src/tricks/reversible-compaction.js +6 -2
- package/dist/src/tricks/reversible-compaction.js.map +1 -1
- package/dist/src/tui/app.d.ts +16 -3
- package/dist/src/tui/app.d.ts.map +1 -1
- package/dist/src/tui/app.js +211 -25
- package/dist/src/tui/app.js.map +1 -1
- package/dist/src/tui/components/CollapsibleDiffView.d.ts +1 -1
- package/dist/src/tui/components/CollapsibleDiffView.d.ts.map +1 -1
- package/dist/src/tui/components/DiagnosticsPanel.d.ts +24 -0
- package/dist/src/tui/components/DiagnosticsPanel.d.ts.map +1 -0
- package/dist/src/tui/components/DiagnosticsPanel.js +47 -0
- package/dist/src/tui/components/DiagnosticsPanel.js.map +1 -0
- package/dist/src/tui/components/DiffView.d.ts +1 -1
- package/dist/src/tui/components/DiffView.d.ts.map +1 -1
- package/dist/src/tui/components/ErrorBoundary.d.ts.map +1 -1
- package/dist/src/tui/components/ErrorBoundary.js +3 -2
- package/dist/src/tui/components/ErrorBoundary.js.map +1 -1
- package/dist/src/tui/components/TasksPanel.d.ts +1 -1
- package/dist/src/tui/components/TasksPanel.d.ts.map +1 -1
- package/dist/src/tui/event-display.d.ts.map +1 -1
- package/dist/src/tui/event-display.js +36 -62
- package/dist/src/tui/event-display.js.map +1 -1
- package/dist/src/tui/index.d.ts +4 -0
- package/dist/src/tui/index.d.ts.map +1 -1
- package/dist/src/tui/index.js +17 -0
- package/dist/src/tui/index.js.map +1 -1
- package/dist/src/tui/transparency-aggregator.d.ts +13 -0
- package/dist/src/tui/transparency-aggregator.d.ts.map +1 -1
- package/dist/src/tui/transparency-aggregator.js +21 -0
- package/dist/src/tui/transparency-aggregator.js.map +1 -1
- package/dist/src/types.d.ts +170 -3
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +18 -3
|
@@ -0,0 +1,1007 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lesson 25: Execution Economics System
|
|
3
|
+
*
|
|
4
|
+
* Replaces hard-coded iteration limits with intelligent budget management:
|
|
5
|
+
* - Token budgets (primary constraint)
|
|
6
|
+
* - Cost budgets (maps to real API costs)
|
|
7
|
+
* - Time budgets (wall-clock limits)
|
|
8
|
+
* - Progress detection (stuck vs productive)
|
|
9
|
+
* - Adaptive limits with extension requests
|
|
10
|
+
*
|
|
11
|
+
* Phase 3b: Core manager + presets. Loop detection and phase tracking
|
|
12
|
+
* are extracted into loop-detector.ts and phase-tracker.ts respectively.
|
|
13
|
+
*/
|
|
14
|
+
import { stableStringify } from '../context/context-engineering.js';
|
|
15
|
+
import { calculateCost } from '../utilities/openrouter-pricing.js';
|
|
16
|
+
// Re-export from extracted modules for backward compatibility
|
|
17
|
+
export { computeToolFingerprint, extractBashResult, extractBashFileTarget, LoopDetector, } from './loop-detector.js';
|
|
18
|
+
export { PhaseTracker } from './phase-tracker.js';
|
|
19
|
+
// Import from extracted modules for internal use
|
|
20
|
+
import { computeToolFingerprint, extractBashResult, LoopDetector, DOOM_LOOP_PROMPT, GLOBAL_DOOM_LOOP_PROMPT, TEST_FIX_RETHINK_PROMPT, BASH_FAILURE_CASCADE_PROMPT, SUMMARY_LOOP_PROMPT, } from './loop-detector.js';
|
|
21
|
+
import { PhaseTracker, EXPLORATION_NUDGE_PROMPT, EXPLORATION_BUDGET_EXCEEDED_PROMPT, VERIFICATION_RESERVE_PROMPT, } from './phase-tracker.js';
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// PROMPT CONSTANTS (kept in manager for budget-level prompts)
|
|
24
|
+
// =============================================================================
|
|
25
|
+
/**
|
|
26
|
+
* Max steps prompt - injected when iteration limit reached.
|
|
27
|
+
* Forces a summary response instead of more tool calls.
|
|
28
|
+
*/
|
|
29
|
+
const MAX_STEPS_PROMPT = `[System] Maximum steps reached. You must now:
|
|
30
|
+
1. Summarize what you've accomplished
|
|
31
|
+
2. List any remaining work
|
|
32
|
+
3. Explain any blockers encountered
|
|
33
|
+
|
|
34
|
+
Do NOT call any more tools. Respond with text only.`;
|
|
35
|
+
/**
|
|
36
|
+
* Timeout wrapup prompt - injected when a subagent is about to be stopped due to timeout.
|
|
37
|
+
* Forces a structured JSON summary so the parent agent can make intelligent follow-up decisions.
|
|
38
|
+
*/
|
|
39
|
+
export const TIMEOUT_WRAPUP_PROMPT = `[System] You are about to be stopped due to timeout. You MUST respond with a structured summary NOW.
|
|
40
|
+
|
|
41
|
+
Respond with ONLY this JSON (no tool calls):
|
|
42
|
+
{
|
|
43
|
+
"findings": ["what you discovered or accomplished"],
|
|
44
|
+
"actionsTaken": ["files read, modifications made, commands run"],
|
|
45
|
+
"failures": ["what failed or was blocked"],
|
|
46
|
+
"remainingWork": ["what you didn't finish"],
|
|
47
|
+
"suggestedNextSteps": ["what the parent agent should do next"]
|
|
48
|
+
}`;
|
|
49
|
+
const BUDGET_ADVISORY_PROMPT = (reason) => `[System] Budget advisory (${reason}) detected. Continue execution and focus on concrete tool actions to complete the task.`;
|
|
50
|
+
// =============================================================================
|
|
51
|
+
// ECONOMICS MANAGER
|
|
52
|
+
// =============================================================================
|
|
53
|
+
/**
|
|
54
|
+
* ExecutionEconomicsManager handles budget tracking and progress detection.
|
|
55
|
+
*
|
|
56
|
+
* Delegates loop detection to LoopDetector and phase tracking to PhaseTracker.
|
|
57
|
+
*/
|
|
58
|
+
export class ExecutionEconomicsManager {
|
|
59
|
+
budget;
|
|
60
|
+
usage;
|
|
61
|
+
progress;
|
|
62
|
+
loopDetector;
|
|
63
|
+
phaseTracker;
|
|
64
|
+
phaseBudget = null;
|
|
65
|
+
startTime;
|
|
66
|
+
pausedDuration = 0;
|
|
67
|
+
pauseStart = null;
|
|
68
|
+
listeners = [];
|
|
69
|
+
extensionHandler;
|
|
70
|
+
// Shared economics state for cross-worker doom loop aggregation
|
|
71
|
+
sharedEconomics;
|
|
72
|
+
workerId;
|
|
73
|
+
// Adaptive budget: stores original maxIterations for reversible reduction
|
|
74
|
+
originalMaxIterations = null;
|
|
75
|
+
// Incremental token accounting
|
|
76
|
+
baseline = 0;
|
|
77
|
+
lastInputTokens = 0;
|
|
78
|
+
constructor(budget, sharedEconomics, workerId) {
|
|
79
|
+
this.sharedEconomics = sharedEconomics ?? null;
|
|
80
|
+
this.workerId = workerId ?? 'root';
|
|
81
|
+
const tuning = budget?.tuning;
|
|
82
|
+
this.budget = {
|
|
83
|
+
enforcementMode: budget?.enforcementMode ?? 'strict',
|
|
84
|
+
// Hard limits
|
|
85
|
+
maxTokens: budget?.maxTokens ?? 200000,
|
|
86
|
+
maxCost: budget?.maxCost ?? 1.00,
|
|
87
|
+
maxDuration: budget?.maxDuration ?? 900000, // 15 minutes (up from 5min to support subagent tasks)
|
|
88
|
+
// Soft limits (80% of hard limits)
|
|
89
|
+
softTokenLimit: budget?.softTokenLimit ?? 150000,
|
|
90
|
+
softCostLimit: budget?.softCostLimit ?? 0.75,
|
|
91
|
+
softDurationLimit: budget?.softDurationLimit ?? 720000, // 12 minutes
|
|
92
|
+
// Iteration guidance
|
|
93
|
+
targetIterations: budget?.targetIterations ?? 20,
|
|
94
|
+
maxIterations: budget?.maxIterations ?? 100,
|
|
95
|
+
// Tuning
|
|
96
|
+
tuning,
|
|
97
|
+
};
|
|
98
|
+
this.usage = {
|
|
99
|
+
tokens: 0,
|
|
100
|
+
inputTokens: 0,
|
|
101
|
+
outputTokens: 0,
|
|
102
|
+
cost: 0,
|
|
103
|
+
duration: 0,
|
|
104
|
+
iterations: 0,
|
|
105
|
+
toolCalls: 0,
|
|
106
|
+
llmCalls: 0,
|
|
107
|
+
baselineContextTokens: 0,
|
|
108
|
+
cumulativeInputTokens: 0,
|
|
109
|
+
};
|
|
110
|
+
this.progress = {
|
|
111
|
+
filesRead: new Set(),
|
|
112
|
+
filesModified: new Set(),
|
|
113
|
+
commandsRun: [],
|
|
114
|
+
recentToolCalls: [],
|
|
115
|
+
lastMeaningfulProgress: Date.now(),
|
|
116
|
+
stuckCount: 0,
|
|
117
|
+
};
|
|
118
|
+
// Initialize extracted modules
|
|
119
|
+
this.loopDetector = new LoopDetector(tuning);
|
|
120
|
+
this.phaseTracker = new PhaseTracker(tuning, (event) => this.emit(event));
|
|
121
|
+
this.startTime = Date.now();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Pause duration tracking (e.g., while subagents are running).
|
|
125
|
+
* Prevents the parent agent's wall-clock timer from advancing
|
|
126
|
+
* during subagent execution.
|
|
127
|
+
*/
|
|
128
|
+
pauseDuration() {
|
|
129
|
+
if (this.pauseStart === null) {
|
|
130
|
+
this.pauseStart = Date.now();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Resume duration tracking after subagent completes.
|
|
135
|
+
*/
|
|
136
|
+
resumeDuration() {
|
|
137
|
+
if (this.pauseStart !== null) {
|
|
138
|
+
this.pausedDuration += Date.now() - this.pauseStart;
|
|
139
|
+
this.pauseStart = null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Get the effective duration accounting for paused time.
|
|
144
|
+
*/
|
|
145
|
+
getEffectiveDuration() {
|
|
146
|
+
const currentPaused = this.pauseStart !== null ? Date.now() - this.pauseStart : 0;
|
|
147
|
+
return Date.now() - this.startTime - this.pausedDuration - currentPaused;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Configure phase-aware budget allocation.
|
|
151
|
+
* Only active when enabled=true (eval mode). TUI mode leaves it off.
|
|
152
|
+
*/
|
|
153
|
+
setPhaseBudget(config) {
|
|
154
|
+
this.phaseBudget = config;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Set baseline context tokens for incremental accounting.
|
|
158
|
+
* Tokens up to this baseline are not counted toward the budget.
|
|
159
|
+
*/
|
|
160
|
+
setBaseline(tokens) {
|
|
161
|
+
this.baseline = tokens;
|
|
162
|
+
this.usage.baselineContextTokens = tokens;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get current baseline context tokens.
|
|
166
|
+
*/
|
|
167
|
+
getBaseline() {
|
|
168
|
+
return this.baseline;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Update baseline after compaction reduces context size.
|
|
172
|
+
*/
|
|
173
|
+
updateBaseline(tokens) {
|
|
174
|
+
this.baseline = tokens;
|
|
175
|
+
this.usage.baselineContextTokens = tokens;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Estimate the incremental cost of the next LLM call.
|
|
179
|
+
* Subtracts baseline from input tokens to give incremental cost.
|
|
180
|
+
*/
|
|
181
|
+
estimateNextCallCost(inputTokens, outputTokens) {
|
|
182
|
+
const incrementalInput = Math.max(0, inputTokens - this.baseline);
|
|
183
|
+
return incrementalInput + outputTokens;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Set the extension request handler.
|
|
187
|
+
*/
|
|
188
|
+
setExtensionHandler(handler) {
|
|
189
|
+
this.extensionHandler = handler;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Record token usage from an LLM call.
|
|
193
|
+
* When a baseline is set, uses incremental accounting: only tokens beyond what
|
|
194
|
+
* was seen in the previous call are counted toward the budget.
|
|
195
|
+
* @param inputTokens - Number of input tokens
|
|
196
|
+
* @param outputTokens - Number of output tokens
|
|
197
|
+
* @param model - Model name (for fallback pricing calculation)
|
|
198
|
+
* @param actualCost - Actual cost from provider (e.g., OpenRouter returns this directly)
|
|
199
|
+
* @param cacheReadTokens - Tokens served from cache (deducted from incremental input)
|
|
200
|
+
*/
|
|
201
|
+
recordLLMUsage(inputTokens, outputTokens, model, actualCost, cacheReadTokens) {
|
|
202
|
+
// Track cumulative input for debugging (always the full input)
|
|
203
|
+
this.usage.cumulativeInputTokens += inputTokens;
|
|
204
|
+
// On the very first LLM call, refine the baseline from the actual
|
|
205
|
+
// API-reported input tokens. The initial estimate (from systemPrompt
|
|
206
|
+
// char count) may miss tool definitions, rules, etc. Using the real
|
|
207
|
+
// value makes the first call "free" (all context is baseline) and
|
|
208
|
+
// subsequent calls only pay the marginal token growth.
|
|
209
|
+
if (this.baseline > 0 && this.usage.llmCalls === 0) {
|
|
210
|
+
this.baseline = inputTokens;
|
|
211
|
+
this.usage.baselineContextTokens = inputTokens;
|
|
212
|
+
}
|
|
213
|
+
// Incremental accounting: only count new tokens since last call
|
|
214
|
+
let effectiveInput;
|
|
215
|
+
if (this.baseline > 0) {
|
|
216
|
+
const incrementalInput = Math.max(0, inputTokens - this.lastInputTokens);
|
|
217
|
+
effectiveInput = Math.max(0, incrementalInput - (cacheReadTokens ?? 0));
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
// No baseline: cumulative mode (backward compat)
|
|
221
|
+
effectiveInput = cacheReadTokens ? Math.max(0, inputTokens - cacheReadTokens) : inputTokens;
|
|
222
|
+
}
|
|
223
|
+
this.lastInputTokens = inputTokens;
|
|
224
|
+
this.usage.inputTokens += effectiveInput;
|
|
225
|
+
this.usage.outputTokens += outputTokens;
|
|
226
|
+
this.usage.tokens += effectiveInput + outputTokens;
|
|
227
|
+
this.usage.llmCalls++;
|
|
228
|
+
// Use actual cost from provider if available, otherwise calculate
|
|
229
|
+
if (actualCost !== undefined && actualCost !== null) {
|
|
230
|
+
this.usage.cost += actualCost;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// Fallback: Calculate cost using model pricing (less accurate for unknown models)
|
|
234
|
+
this.usage.cost += calculateCost(model || '', inputTokens, outputTokens);
|
|
235
|
+
}
|
|
236
|
+
// Update duration
|
|
237
|
+
this.usage.duration = this.getEffectiveDuration();
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Record a text-only turn (LLM response with no tool calls).
|
|
241
|
+
* Increments the consecutive text-only turn counter for summary-loop detection.
|
|
242
|
+
*/
|
|
243
|
+
recordTextOnlyTurn() {
|
|
244
|
+
this.phaseTracker.recordTextOnlyTurn();
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Record a tool call for progress tracking and loop detection.
|
|
248
|
+
*/
|
|
249
|
+
recordToolCall(toolName, args, _result) {
|
|
250
|
+
this.usage.toolCalls++;
|
|
251
|
+
this.usage.iterations++;
|
|
252
|
+
const now = Date.now();
|
|
253
|
+
// Track for loop detection (stableStringify ensures consistent ordering for comparison)
|
|
254
|
+
const argsStr = stableStringify(args);
|
|
255
|
+
this.progress.recentToolCalls.push({ tool: toolName, args: argsStr, timestamp: now });
|
|
256
|
+
// Keep only last 10 for loop detection
|
|
257
|
+
if (this.progress.recentToolCalls.length > 10) {
|
|
258
|
+
this.progress.recentToolCalls.shift();
|
|
259
|
+
}
|
|
260
|
+
// =========================================================================
|
|
261
|
+
// DOOM LOOP DETECTION (delegated to LoopDetector)
|
|
262
|
+
// =========================================================================
|
|
263
|
+
const newDoomLoop = this.loopDetector.updateDoomLoopState(toolName, argsStr, this.progress.recentToolCalls);
|
|
264
|
+
if (newDoomLoop) {
|
|
265
|
+
this.emit({
|
|
266
|
+
type: 'doom_loop.detected',
|
|
267
|
+
tool: toolName,
|
|
268
|
+
consecutiveCount: this.loopDetector.consecutiveCount,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
// Report to shared economics for cross-worker doom loop aggregation
|
|
272
|
+
if (this.sharedEconomics) {
|
|
273
|
+
const fingerprint = computeToolFingerprint(toolName, argsStr);
|
|
274
|
+
this.sharedEconomics.recordToolCall(this.workerId, fingerprint);
|
|
275
|
+
}
|
|
276
|
+
// =========================================================================
|
|
277
|
+
// PHASE TRACKING (delegated to PhaseTracker)
|
|
278
|
+
// =========================================================================
|
|
279
|
+
this.phaseTracker.onToolCall();
|
|
280
|
+
// Track file operations
|
|
281
|
+
if (toolName === 'read_file' && args.path) {
|
|
282
|
+
const path = String(args.path);
|
|
283
|
+
const isNewFile = !this.progress.filesRead.has(path);
|
|
284
|
+
this.progress.filesRead.add(path);
|
|
285
|
+
this.phaseTracker.trackFileRead(path);
|
|
286
|
+
// Only count reads as progress during initial exploration (first 5 iterations)
|
|
287
|
+
if (this.usage.iterations <= 5) {
|
|
288
|
+
this.progress.lastMeaningfulProgress = now;
|
|
289
|
+
this.progress.stuckCount = 0;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Track search operations
|
|
293
|
+
if (['grep', 'search', 'glob', 'find_files', 'search_files'].includes(toolName)) {
|
|
294
|
+
const query = String(args.pattern || args.query || args.path || '');
|
|
295
|
+
this.phaseTracker.trackSearch(query);
|
|
296
|
+
}
|
|
297
|
+
if (['write_file', 'edit_file'].includes(toolName) && args.path) {
|
|
298
|
+
this.progress.filesModified.add(String(args.path));
|
|
299
|
+
this.phaseTracker.trackFileModified(String(args.path));
|
|
300
|
+
this.progress.lastMeaningfulProgress = now;
|
|
301
|
+
this.progress.stuckCount = 0;
|
|
302
|
+
}
|
|
303
|
+
if (toolName === 'bash' && args.command) {
|
|
304
|
+
const command = String(args.command);
|
|
305
|
+
this.progress.commandsRun.push(command);
|
|
306
|
+
this.progress.lastMeaningfulProgress = now;
|
|
307
|
+
this.progress.stuckCount = 0;
|
|
308
|
+
// Extract result from bash tool output (object or string)
|
|
309
|
+
const bashResult = extractBashResult(_result);
|
|
310
|
+
// Track bash result in phase tracker (handles failures, test outcomes)
|
|
311
|
+
if (_result !== undefined) {
|
|
312
|
+
this.phaseTracker.trackBashResult(command, bashResult.success, bashResult.output);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
// Detect test runs even without result (for phase transition)
|
|
316
|
+
if (command.includes('test') || command.includes('pytest') || command.includes('npm test') || command.includes('jest')) {
|
|
317
|
+
this.phaseTracker.trackBashResult(command, true, '');
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// Update exploration saturation check
|
|
322
|
+
this.phaseTracker.checkExplorationSaturation();
|
|
323
|
+
// Check for stuck state
|
|
324
|
+
if (this.isStuck()) {
|
|
325
|
+
this.progress.stuckCount++;
|
|
326
|
+
this.emit({ type: 'progress.stuck', stuckCount: this.progress.stuckCount, lastProgress: this.progress.lastMeaningfulProgress });
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
this.emit({
|
|
330
|
+
type: 'progress.made',
|
|
331
|
+
filesRead: this.progress.filesRead.size,
|
|
332
|
+
filesModified: this.progress.filesModified.size,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Check if execution can continue.
|
|
338
|
+
*/
|
|
339
|
+
checkBudget() {
|
|
340
|
+
this.usage.duration = this.getEffectiveDuration();
|
|
341
|
+
const strictBudgetEnforcement = (this.budget.enforcementMode ?? 'strict') === 'strict';
|
|
342
|
+
const phaseState = this.phaseTracker.rawState;
|
|
343
|
+
// Check hard limits first
|
|
344
|
+
if (this.usage.tokens >= this.budget.maxTokens) {
|
|
345
|
+
this.emit({ type: 'budget.exceeded', budgetType: 'tokens', limit: this.budget.maxTokens, actual: this.usage.tokens });
|
|
346
|
+
if (!strictBudgetEnforcement) {
|
|
347
|
+
return {
|
|
348
|
+
canContinue: true,
|
|
349
|
+
reason: `Token budget exceeded (${this.usage.tokens.toLocaleString()} / ${this.budget.maxTokens.toLocaleString()})`,
|
|
350
|
+
budgetType: 'tokens',
|
|
351
|
+
isHardLimit: false,
|
|
352
|
+
isSoftLimit: true,
|
|
353
|
+
percentUsed: (this.usage.tokens / this.budget.maxTokens) * 100,
|
|
354
|
+
suggestedAction: 'warn',
|
|
355
|
+
injectedPrompt: BUDGET_ADVISORY_PROMPT('tokens'),
|
|
356
|
+
budgetMode: 'warn',
|
|
357
|
+
allowTaskContinuation: true,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
canContinue: false,
|
|
362
|
+
reason: `Token budget exceeded (${this.usage.tokens.toLocaleString()} / ${this.budget.maxTokens.toLocaleString()})`,
|
|
363
|
+
budgetType: 'tokens',
|
|
364
|
+
isHardLimit: true,
|
|
365
|
+
isSoftLimit: false,
|
|
366
|
+
percentUsed: (this.usage.tokens / this.budget.maxTokens) * 100,
|
|
367
|
+
suggestedAction: 'stop',
|
|
368
|
+
budgetMode: 'hard',
|
|
369
|
+
allowTaskContinuation: false,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (this.usage.cost >= this.budget.maxCost) {
|
|
373
|
+
this.emit({ type: 'budget.exceeded', budgetType: 'cost', limit: this.budget.maxCost, actual: this.usage.cost });
|
|
374
|
+
if (!strictBudgetEnforcement) {
|
|
375
|
+
return {
|
|
376
|
+
canContinue: true,
|
|
377
|
+
reason: `Cost budget exceeded ($${this.usage.cost.toFixed(2)} / $${this.budget.maxCost.toFixed(2)})`,
|
|
378
|
+
budgetType: 'cost',
|
|
379
|
+
isHardLimit: false,
|
|
380
|
+
isSoftLimit: true,
|
|
381
|
+
percentUsed: (this.usage.cost / this.budget.maxCost) * 100,
|
|
382
|
+
suggestedAction: 'warn',
|
|
383
|
+
injectedPrompt: BUDGET_ADVISORY_PROMPT('cost'),
|
|
384
|
+
budgetMode: 'warn',
|
|
385
|
+
allowTaskContinuation: true,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
canContinue: false,
|
|
390
|
+
reason: `Cost budget exceeded ($${this.usage.cost.toFixed(2)} / $${this.budget.maxCost.toFixed(2)})`,
|
|
391
|
+
budgetType: 'cost',
|
|
392
|
+
isHardLimit: true,
|
|
393
|
+
isSoftLimit: false,
|
|
394
|
+
percentUsed: (this.usage.cost / this.budget.maxCost) * 100,
|
|
395
|
+
suggestedAction: 'stop',
|
|
396
|
+
budgetMode: 'hard',
|
|
397
|
+
allowTaskContinuation: false,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
if (this.usage.duration >= this.budget.maxDuration) {
|
|
401
|
+
this.emit({ type: 'budget.exceeded', budgetType: 'duration', limit: this.budget.maxDuration, actual: this.usage.duration });
|
|
402
|
+
if (!strictBudgetEnforcement) {
|
|
403
|
+
return {
|
|
404
|
+
canContinue: true,
|
|
405
|
+
reason: `Duration limit exceeded (${Math.round(this.usage.duration / 1000)}s / ${Math.round(this.budget.maxDuration / 1000)}s)`,
|
|
406
|
+
budgetType: 'duration',
|
|
407
|
+
isHardLimit: false,
|
|
408
|
+
isSoftLimit: true,
|
|
409
|
+
percentUsed: (this.usage.duration / this.budget.maxDuration) * 100,
|
|
410
|
+
suggestedAction: 'warn',
|
|
411
|
+
injectedPrompt: BUDGET_ADVISORY_PROMPT('duration'),
|
|
412
|
+
budgetMode: 'warn',
|
|
413
|
+
allowTaskContinuation: true,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
canContinue: false,
|
|
418
|
+
reason: `Duration limit exceeded (${Math.round(this.usage.duration / 1000)}s / ${Math.round(this.budget.maxDuration / 1000)}s)`,
|
|
419
|
+
budgetType: 'duration',
|
|
420
|
+
isHardLimit: true,
|
|
421
|
+
isSoftLimit: false,
|
|
422
|
+
percentUsed: (this.usage.duration / this.budget.maxDuration) * 100,
|
|
423
|
+
suggestedAction: 'stop',
|
|
424
|
+
budgetMode: 'hard',
|
|
425
|
+
allowTaskContinuation: false,
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
// Max iterations reached -- allow exactly ONE more turn for summary, then terminate.
|
|
429
|
+
if (this.usage.iterations >= this.budget.maxIterations) {
|
|
430
|
+
const isFirstOverage = this.usage.iterations === this.budget.maxIterations;
|
|
431
|
+
return {
|
|
432
|
+
canContinue: isFirstOverage, // Only allow one summary turn
|
|
433
|
+
reason: `Maximum iterations reached (${this.usage.iterations} / ${this.budget.maxIterations})`,
|
|
434
|
+
budgetType: 'iterations',
|
|
435
|
+
isHardLimit: true,
|
|
436
|
+
isSoftLimit: false,
|
|
437
|
+
percentUsed: 100,
|
|
438
|
+
suggestedAction: 'stop',
|
|
439
|
+
forceTextOnly: true, // No more tool calls
|
|
440
|
+
injectedPrompt: MAX_STEPS_PROMPT,
|
|
441
|
+
budgetMode: 'hard',
|
|
442
|
+
allowTaskContinuation: false,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
// =========================================================================
|
|
446
|
+
// ZERO PROGRESS DETECTION (D1)
|
|
447
|
+
// =========================================================================
|
|
448
|
+
const zeroProgressThreshold = this.budget.tuning?.zeroProgressThreshold ?? 10;
|
|
449
|
+
if (this.usage.iterations >= zeroProgressThreshold && this.usage.toolCalls === 0) {
|
|
450
|
+
const isCompleteStall = this.usage.iterations >= zeroProgressThreshold * 2;
|
|
451
|
+
return {
|
|
452
|
+
canContinue: true,
|
|
453
|
+
reason: `Zero tool calls in ${this.usage.iterations} iterations`,
|
|
454
|
+
budgetType: 'iterations',
|
|
455
|
+
isHardLimit: false,
|
|
456
|
+
isSoftLimit: true,
|
|
457
|
+
percentUsed: (this.usage.iterations / this.budget.maxIterations) * 100,
|
|
458
|
+
suggestedAction: isCompleteStall ? 'stop' : 'warn',
|
|
459
|
+
forceTextOnly: isCompleteStall,
|
|
460
|
+
injectedPrompt: `[System] WARNING: You have completed ${this.usage.iterations} iterations without making a single tool call. ` +
|
|
461
|
+
`You MUST use your tools (read_file, write_file, grep, bash, etc.) to accomplish your task. ` +
|
|
462
|
+
`Start by reading a relevant file or running a command NOW.` +
|
|
463
|
+
(isCompleteStall ? ` This is your LAST chance — respond with a summary if you cannot proceed.` : ''),
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
// =========================================================================
|
|
467
|
+
// ADAPTIVE ITERATION BUDGET (D4)
|
|
468
|
+
// =========================================================================
|
|
469
|
+
const checkpoint = this.budget.tuning?.progressCheckpoint ?? 10;
|
|
470
|
+
if (this.usage.iterations === checkpoint && this.usage.toolCalls === 0) {
|
|
471
|
+
if (!this.originalMaxIterations) {
|
|
472
|
+
this.originalMaxIterations = this.budget.maxIterations;
|
|
473
|
+
}
|
|
474
|
+
const reducedMax = checkpoint + 5;
|
|
475
|
+
if (this.budget.maxIterations > reducedMax) {
|
|
476
|
+
this.budget.maxIterations = reducedMax;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
// Restore original maxIterations if tools start being used after reduction
|
|
480
|
+
if (this.originalMaxIterations && this.usage.toolCalls > 0 && this.budget.maxIterations < this.originalMaxIterations) {
|
|
481
|
+
this.budget.maxIterations = this.originalMaxIterations;
|
|
482
|
+
this.originalMaxIterations = null;
|
|
483
|
+
}
|
|
484
|
+
// =========================================================================
|
|
485
|
+
// DOOM LOOP DETECTION - Strong intervention (delegated to LoopDetector)
|
|
486
|
+
// =========================================================================
|
|
487
|
+
if (this.loopDetector.isDoomLoop) {
|
|
488
|
+
return {
|
|
489
|
+
canContinue: true,
|
|
490
|
+
reason: `Doom loop detected: ${this.loopDetector.lastTool} called ${this.loopDetector.consecutiveCount} times`,
|
|
491
|
+
budgetType: 'iterations',
|
|
492
|
+
isHardLimit: false,
|
|
493
|
+
isSoftLimit: true,
|
|
494
|
+
percentUsed: (this.usage.iterations / this.budget.targetIterations) * 100,
|
|
495
|
+
suggestedAction: 'warn',
|
|
496
|
+
injectedPrompt: DOOM_LOOP_PROMPT(this.loopDetector.lastTool || 'unknown', this.loopDetector.consecutiveCount),
|
|
497
|
+
budgetMode: 'warn',
|
|
498
|
+
allowTaskContinuation: true,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
// =========================================================================
|
|
502
|
+
// GLOBAL DOOM LOOP DETECTION - Cross-worker stuck pattern
|
|
503
|
+
// =========================================================================
|
|
504
|
+
if (this.sharedEconomics && this.progress.recentToolCalls.length > 0) {
|
|
505
|
+
const lastCall = this.progress.recentToolCalls[this.progress.recentToolCalls.length - 1];
|
|
506
|
+
const fingerprint = computeToolFingerprint(lastCall.tool, lastCall.args);
|
|
507
|
+
if (this.sharedEconomics.isGlobalDoomLoop(fingerprint)) {
|
|
508
|
+
const info = this.sharedEconomics.getGlobalLoopInfo(fingerprint);
|
|
509
|
+
return {
|
|
510
|
+
canContinue: true,
|
|
511
|
+
reason: `Global doom loop: ${lastCall.tool} repeated across ${info?.workerCount ?? 0} workers`,
|
|
512
|
+
budgetType: 'iterations',
|
|
513
|
+
isHardLimit: false,
|
|
514
|
+
isSoftLimit: true,
|
|
515
|
+
percentUsed: (this.usage.iterations / this.budget.targetIterations) * 100,
|
|
516
|
+
suggestedAction: 'warn',
|
|
517
|
+
injectedPrompt: GLOBAL_DOOM_LOOP_PROMPT(lastCall.tool, info?.workerCount ?? 0, info?.count ?? 0),
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
// =========================================================================
|
|
522
|
+
// EXPLORATION SATURATION - Gentle nudge (delegated to PhaseTracker)
|
|
523
|
+
// =========================================================================
|
|
524
|
+
if (phaseState.shouldTransition) {
|
|
525
|
+
return {
|
|
526
|
+
canContinue: true,
|
|
527
|
+
reason: `Exploration saturation: ${phaseState.uniqueFilesRead.size} files read`,
|
|
528
|
+
budgetType: 'iterations',
|
|
529
|
+
isHardLimit: false,
|
|
530
|
+
isSoftLimit: true,
|
|
531
|
+
percentUsed: (this.usage.iterations / this.budget.targetIterations) * 100,
|
|
532
|
+
suggestedAction: 'warn',
|
|
533
|
+
injectedPrompt: EXPLORATION_NUDGE_PROMPT(phaseState.uniqueFilesRead.size, phaseState.iterationsInPhase),
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
// =========================================================================
|
|
537
|
+
// TEST-FIX CYCLE - Nudge to rethink after 3+ consecutive failures
|
|
538
|
+
// =========================================================================
|
|
539
|
+
if (phaseState.consecutiveTestFailures >= 3) {
|
|
540
|
+
return {
|
|
541
|
+
canContinue: true,
|
|
542
|
+
reason: `${phaseState.consecutiveTestFailures} consecutive test failures`,
|
|
543
|
+
budgetType: 'iterations',
|
|
544
|
+
isHardLimit: false,
|
|
545
|
+
isSoftLimit: true,
|
|
546
|
+
percentUsed: (this.usage.iterations / this.budget.targetIterations) * 100,
|
|
547
|
+
suggestedAction: 'warn',
|
|
548
|
+
injectedPrompt: TEST_FIX_RETHINK_PROMPT(phaseState.consecutiveTestFailures),
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
// =========================================================================
|
|
552
|
+
// BASH FAILURE CASCADE - Strong intervention after 3+ consecutive failures
|
|
553
|
+
// =========================================================================
|
|
554
|
+
if (phaseState.consecutiveBashFailures >= 3) {
|
|
555
|
+
const lastBashCommand = this.loopDetector.extractLastBashCommand(this.progress.recentToolCalls);
|
|
556
|
+
return {
|
|
557
|
+
canContinue: true,
|
|
558
|
+
reason: `${phaseState.consecutiveBashFailures} consecutive bash failures`,
|
|
559
|
+
budgetType: 'iterations',
|
|
560
|
+
isHardLimit: false,
|
|
561
|
+
isSoftLimit: true,
|
|
562
|
+
percentUsed: (this.usage.iterations / this.budget.targetIterations) * 100,
|
|
563
|
+
suggestedAction: 'warn',
|
|
564
|
+
injectedPrompt: BASH_FAILURE_CASCADE_PROMPT(phaseState.consecutiveBashFailures, lastBashCommand),
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
// =========================================================================
|
|
568
|
+
// SUMMARY LOOP DETECTION - Nudge after 2+ consecutive text-only turns
|
|
569
|
+
// =========================================================================
|
|
570
|
+
if (phaseState.consecutiveTextOnlyTurns >= 2) {
|
|
571
|
+
const nearBudgetLimit = this.usage.iterations >= this.budget.maxIterations - 1;
|
|
572
|
+
if (!nearBudgetLimit) {
|
|
573
|
+
return {
|
|
574
|
+
canContinue: true,
|
|
575
|
+
reason: `${phaseState.consecutiveTextOnlyTurns} consecutive text-only turns (summary loop)`,
|
|
576
|
+
budgetType: 'iterations',
|
|
577
|
+
isHardLimit: false,
|
|
578
|
+
isSoftLimit: true,
|
|
579
|
+
percentUsed: (this.usage.iterations / this.budget.targetIterations) * 100,
|
|
580
|
+
suggestedAction: 'warn',
|
|
581
|
+
injectedPrompt: SUMMARY_LOOP_PROMPT,
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
// Near budget limit: skip nudge, let MAX_STEPS_PROMPT handle it next turn
|
|
585
|
+
}
|
|
586
|
+
// =========================================================================
|
|
587
|
+
// PHASE-AWARE BUDGET ALLOCATION (opt-in, used in eval mode)
|
|
588
|
+
// =========================================================================
|
|
589
|
+
if (this.phaseBudget?.enabled) {
|
|
590
|
+
const iterPct = (this.usage.iterations / this.budget.maxIterations) * 100;
|
|
591
|
+
const explorationPct = phaseState.phase === 'exploring'
|
|
592
|
+
? (phaseState.iterationsInPhase / this.budget.maxIterations) * 100
|
|
593
|
+
: 0;
|
|
594
|
+
// Too much time in exploration
|
|
595
|
+
if (explorationPct > this.phaseBudget.maxExplorationPercent && phaseState.filesModified.size === 0) {
|
|
596
|
+
return {
|
|
597
|
+
canContinue: true,
|
|
598
|
+
reason: `Exploration exceeds ${this.phaseBudget.maxExplorationPercent}% of budget`,
|
|
599
|
+
budgetType: 'iterations',
|
|
600
|
+
isHardLimit: false,
|
|
601
|
+
isSoftLimit: true,
|
|
602
|
+
percentUsed: iterPct,
|
|
603
|
+
suggestedAction: 'warn',
|
|
604
|
+
injectedPrompt: EXPLORATION_BUDGET_EXCEEDED_PROMPT(Math.round(explorationPct)),
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
// Only verification-reserve iterations remain
|
|
608
|
+
const remainingPct = 100 - iterPct;
|
|
609
|
+
if (remainingPct <= this.phaseBudget.reservedVerificationPercent
|
|
610
|
+
&& phaseState.phase !== 'verifying'
|
|
611
|
+
&& phaseState.filesModified.size > 0
|
|
612
|
+
&& phaseState.testsRun === 0) {
|
|
613
|
+
return {
|
|
614
|
+
canContinue: true,
|
|
615
|
+
reason: `Only ${Math.round(remainingPct)}% budget remaining, verification needed`,
|
|
616
|
+
budgetType: 'iterations',
|
|
617
|
+
isHardLimit: false,
|
|
618
|
+
isSoftLimit: true,
|
|
619
|
+
percentUsed: iterPct,
|
|
620
|
+
suggestedAction: 'warn',
|
|
621
|
+
injectedPrompt: VERIFICATION_RESERVE_PROMPT,
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
// Check soft limits (warnings)
|
|
626
|
+
if (this.usage.tokens >= this.budget.softTokenLimit) {
|
|
627
|
+
const remaining = this.budget.maxTokens - this.usage.tokens;
|
|
628
|
+
const percentUsed = Math.round((this.usage.tokens / this.budget.maxTokens) * 100);
|
|
629
|
+
this.emit({ type: 'budget.warning', budgetType: 'tokens', percentUsed, remaining });
|
|
630
|
+
// Only force text-only in strict mode. In doomloop_only mode,
|
|
631
|
+
// soft limits warn but do not kill the agent.
|
|
632
|
+
const forceTextOnly = strictBudgetEnforcement && percentUsed >= 80;
|
|
633
|
+
return {
|
|
634
|
+
canContinue: true,
|
|
635
|
+
reason: `Token budget at ${percentUsed}%`,
|
|
636
|
+
budgetType: 'tokens',
|
|
637
|
+
isHardLimit: false,
|
|
638
|
+
isSoftLimit: true,
|
|
639
|
+
percentUsed,
|
|
640
|
+
suggestedAction: forceTextOnly ? 'stop' : 'request_extension',
|
|
641
|
+
forceTextOnly,
|
|
642
|
+
budgetMode: forceTextOnly ? 'restricted' : 'warn',
|
|
643
|
+
allowTaskContinuation: true,
|
|
644
|
+
injectedPrompt: forceTextOnly
|
|
645
|
+
? `\u26a0\ufe0f **BUDGET CRITICAL**: ${percentUsed}% used (${this.usage.tokens.toLocaleString()}/${this.budget.maxTokens.toLocaleString()}). ` +
|
|
646
|
+
`WRAP UP IMMEDIATELY. Return a concise summary. Do NOT call any tools.`
|
|
647
|
+
: `\u26a0\ufe0f **BUDGET WARNING**: You have used ${percentUsed}% of your token budget (${this.usage.tokens.toLocaleString()}/${this.budget.maxTokens.toLocaleString()} tokens). ` +
|
|
648
|
+
`Only ~${remaining.toLocaleString()} tokens remaining. Focus on completing current work. ` +
|
|
649
|
+
`Do not start new explorations.`,
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
if (this.usage.cost >= this.budget.softCostLimit) {
|
|
653
|
+
const remaining = this.budget.maxCost - this.usage.cost;
|
|
654
|
+
this.emit({ type: 'budget.warning', budgetType: 'cost', percentUsed: (this.usage.cost / this.budget.maxCost) * 100, remaining });
|
|
655
|
+
return {
|
|
656
|
+
canContinue: true,
|
|
657
|
+
reason: `Cost budget at ${Math.round((this.usage.cost / this.budget.maxCost) * 100)}%`,
|
|
658
|
+
budgetType: 'cost',
|
|
659
|
+
isHardLimit: false,
|
|
660
|
+
isSoftLimit: true,
|
|
661
|
+
percentUsed: (this.usage.cost / this.budget.maxCost) * 100,
|
|
662
|
+
suggestedAction: 'warn',
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
// Check if stuck
|
|
666
|
+
if (this.progress.stuckCount >= 3) {
|
|
667
|
+
return {
|
|
668
|
+
canContinue: true,
|
|
669
|
+
reason: `Agent appears stuck (${this.progress.stuckCount} iterations without progress)`,
|
|
670
|
+
budgetType: 'iterations',
|
|
671
|
+
isHardLimit: false,
|
|
672
|
+
isSoftLimit: true,
|
|
673
|
+
percentUsed: (this.usage.iterations / this.budget.targetIterations) * 100,
|
|
674
|
+
suggestedAction: 'request_extension',
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
// All good
|
|
678
|
+
return {
|
|
679
|
+
canContinue: true,
|
|
680
|
+
isHardLimit: false,
|
|
681
|
+
isSoftLimit: false,
|
|
682
|
+
percentUsed: Math.max((this.usage.tokens / this.budget.maxTokens) * 100, (this.usage.cost / this.budget.maxCost) * 100, (this.usage.duration / this.budget.maxDuration) * 100),
|
|
683
|
+
budgetMode: 'none',
|
|
684
|
+
allowTaskContinuation: true,
|
|
685
|
+
suggestedAction: 'continue',
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Request a budget extension.
|
|
690
|
+
*/
|
|
691
|
+
async requestExtension(reason) {
|
|
692
|
+
if (!this.extensionHandler) {
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
const request = {
|
|
696
|
+
currentUsage: { ...this.usage },
|
|
697
|
+
budget: { ...this.budget },
|
|
698
|
+
reason,
|
|
699
|
+
suggestedExtension: {
|
|
700
|
+
maxTokens: Math.round(this.budget.maxTokens * 1.5),
|
|
701
|
+
maxCost: this.budget.maxCost * 1.5,
|
|
702
|
+
maxDuration: this.budget.maxDuration * 1.5,
|
|
703
|
+
maxIterations: Math.round(this.budget.maxIterations * 1.5),
|
|
704
|
+
},
|
|
705
|
+
};
|
|
706
|
+
this.emit({ type: 'extension.requested', request });
|
|
707
|
+
try {
|
|
708
|
+
const extension = await this.extensionHandler(request);
|
|
709
|
+
if (extension) {
|
|
710
|
+
this.extendBudget(extension);
|
|
711
|
+
this.emit({ type: 'extension.granted', extension });
|
|
712
|
+
return true;
|
|
713
|
+
}
|
|
714
|
+
else {
|
|
715
|
+
this.emit({ type: 'extension.denied', reason: 'User declined' });
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
catch (err) {
|
|
720
|
+
this.emit({ type: 'extension.denied', reason: String(err) });
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Extend the budget.
|
|
726
|
+
*/
|
|
727
|
+
extendBudget(extension) {
|
|
728
|
+
if (extension.maxTokens)
|
|
729
|
+
this.budget.maxTokens = extension.maxTokens;
|
|
730
|
+
if (extension.maxCost)
|
|
731
|
+
this.budget.maxCost = extension.maxCost;
|
|
732
|
+
if (extension.maxDuration)
|
|
733
|
+
this.budget.maxDuration = extension.maxDuration;
|
|
734
|
+
if (extension.maxIterations)
|
|
735
|
+
this.budget.maxIterations = extension.maxIterations;
|
|
736
|
+
if (extension.softTokenLimit)
|
|
737
|
+
this.budget.softTokenLimit = extension.softTokenLimit;
|
|
738
|
+
if (extension.softCostLimit)
|
|
739
|
+
this.budget.softCostLimit = extension.softCostLimit;
|
|
740
|
+
if (extension.softDurationLimit)
|
|
741
|
+
this.budget.softDurationLimit = extension.softDurationLimit;
|
|
742
|
+
if (extension.targetIterations)
|
|
743
|
+
this.budget.targetIterations = extension.targetIterations;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Get current usage.
|
|
747
|
+
*/
|
|
748
|
+
getUsage() {
|
|
749
|
+
this.usage.duration = this.getEffectiveDuration();
|
|
750
|
+
return { ...this.usage };
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Get current budget.
|
|
754
|
+
*/
|
|
755
|
+
getBudget() {
|
|
756
|
+
return { ...this.budget };
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Get a formatted budget status string for context awareness.
|
|
760
|
+
* Used by subagents to understand their remaining resources.
|
|
761
|
+
*/
|
|
762
|
+
getBudgetStatusString() {
|
|
763
|
+
const usage = this.getUsage();
|
|
764
|
+
const budget = this.budget;
|
|
765
|
+
const tokenPct = Math.round((usage.tokens / budget.maxTokens) * 100);
|
|
766
|
+
const remainingTokens = budget.maxTokens - usage.tokens;
|
|
767
|
+
const remainingSec = budget.maxDuration === Infinity
|
|
768
|
+
? Infinity
|
|
769
|
+
: Math.max(0, Math.round((budget.maxDuration - usage.duration) / 1000));
|
|
770
|
+
// Determine urgency level
|
|
771
|
+
let urgency = '';
|
|
772
|
+
if (tokenPct >= 90) {
|
|
773
|
+
urgency = '\u26a0\ufe0f CRITICAL: ';
|
|
774
|
+
}
|
|
775
|
+
else if (tokenPct >= 70) {
|
|
776
|
+
urgency = '\u26a1 WARNING: ';
|
|
777
|
+
}
|
|
778
|
+
const timeStr = remainingSec === Infinity ? 'no time limit' : `~${remainingSec}s remaining`;
|
|
779
|
+
return `${urgency}Budget: ${usage.tokens.toLocaleString()}/${budget.maxTokens.toLocaleString()} tokens (${tokenPct}%), ${timeStr}. ${tokenPct >= 70 ? 'Wrap up soon!' : ''}`.trim();
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Check if approaching budget limit (for proactive warnings).
|
|
783
|
+
*/
|
|
784
|
+
isApproachingLimit() {
|
|
785
|
+
const usage = this.getUsage();
|
|
786
|
+
const budget = this.budget;
|
|
787
|
+
const tokenPct = (usage.tokens / budget.maxTokens) * 100;
|
|
788
|
+
const durationPct = (usage.duration / budget.maxDuration) * 100;
|
|
789
|
+
if (tokenPct >= 80) {
|
|
790
|
+
return { approaching: true, metric: 'tokens', percentUsed: tokenPct };
|
|
791
|
+
}
|
|
792
|
+
if (durationPct >= 80) {
|
|
793
|
+
return { approaching: true, metric: 'duration', percentUsed: durationPct };
|
|
794
|
+
}
|
|
795
|
+
return { approaching: false, metric: '', percentUsed: Math.max(tokenPct, durationPct) };
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Get progress state.
|
|
799
|
+
*/
|
|
800
|
+
getProgress() {
|
|
801
|
+
return {
|
|
802
|
+
filesRead: this.progress.filesRead.size,
|
|
803
|
+
filesModified: this.progress.filesModified.size,
|
|
804
|
+
commandsRun: this.progress.commandsRun.length,
|
|
805
|
+
isStuck: this.isStuck(),
|
|
806
|
+
stuckCount: this.progress.stuckCount,
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Get actual file paths modified during this session.
|
|
811
|
+
*/
|
|
812
|
+
getModifiedFilePaths() {
|
|
813
|
+
return [...this.progress.filesModified];
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Get doom loop detection state.
|
|
817
|
+
*/
|
|
818
|
+
getLoopState() {
|
|
819
|
+
return this.loopDetector.getState();
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Get exploration phase state.
|
|
823
|
+
*/
|
|
824
|
+
getPhaseState() {
|
|
825
|
+
return this.phaseTracker.getSnapshot();
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Subscribe to events.
|
|
829
|
+
*/
|
|
830
|
+
on(listener) {
|
|
831
|
+
this.listeners.push(listener);
|
|
832
|
+
return () => {
|
|
833
|
+
const idx = this.listeners.indexOf(listener);
|
|
834
|
+
if (idx >= 0)
|
|
835
|
+
this.listeners.splice(idx, 1);
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Reset usage (start new task).
|
|
840
|
+
*/
|
|
841
|
+
reset() {
|
|
842
|
+
this.baseline = 0;
|
|
843
|
+
this.lastInputTokens = 0;
|
|
844
|
+
this.usage = {
|
|
845
|
+
tokens: 0,
|
|
846
|
+
inputTokens: 0,
|
|
847
|
+
outputTokens: 0,
|
|
848
|
+
cost: 0,
|
|
849
|
+
duration: 0,
|
|
850
|
+
iterations: 0,
|
|
851
|
+
toolCalls: 0,
|
|
852
|
+
llmCalls: 0,
|
|
853
|
+
baselineContextTokens: 0,
|
|
854
|
+
cumulativeInputTokens: 0,
|
|
855
|
+
};
|
|
856
|
+
this.progress = {
|
|
857
|
+
filesRead: new Set(),
|
|
858
|
+
filesModified: new Set(),
|
|
859
|
+
commandsRun: [],
|
|
860
|
+
recentToolCalls: [],
|
|
861
|
+
lastMeaningfulProgress: Date.now(),
|
|
862
|
+
stuckCount: 0,
|
|
863
|
+
};
|
|
864
|
+
// Reset extracted modules (preserve tuning thresholds)
|
|
865
|
+
this.loopDetector.reset(this.budget.tuning);
|
|
866
|
+
this.phaseTracker.reset();
|
|
867
|
+
this.startTime = Date.now();
|
|
868
|
+
this.pausedDuration = 0;
|
|
869
|
+
this.pauseStart = null;
|
|
870
|
+
this.originalMaxIterations = null;
|
|
871
|
+
}
|
|
872
|
+
// -------------------------------------------------------------------------
|
|
873
|
+
// PRIVATE METHODS
|
|
874
|
+
// -------------------------------------------------------------------------
|
|
875
|
+
emit(event) {
|
|
876
|
+
for (const listener of this.listeners) {
|
|
877
|
+
try {
|
|
878
|
+
listener(event);
|
|
879
|
+
}
|
|
880
|
+
catch {
|
|
881
|
+
// Ignore listener errors
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
isStuck() {
|
|
886
|
+
// Delegate repetition check to loop detector
|
|
887
|
+
if (this.loopDetector.isStuckByRepetition(this.progress.recentToolCalls)) {
|
|
888
|
+
return true;
|
|
889
|
+
}
|
|
890
|
+
// Check for no progress in time
|
|
891
|
+
const timeSinceProgress = Date.now() - this.progress.lastMeaningfulProgress;
|
|
892
|
+
if (timeSinceProgress > 60000 && this.usage.iterations > 5) {
|
|
893
|
+
return true; // No progress for 1 minute with 5+ iterations
|
|
894
|
+
}
|
|
895
|
+
return false;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
// =============================================================================
|
|
899
|
+
// FACTORY
|
|
900
|
+
// =============================================================================
|
|
901
|
+
/**
|
|
902
|
+
* Create an economics manager with optional budget configuration.
|
|
903
|
+
*/
|
|
904
|
+
export function createEconomicsManager(budget) {
|
|
905
|
+
return new ExecutionEconomicsManager(budget);
|
|
906
|
+
}
|
|
907
|
+
// =============================================================================
|
|
908
|
+
// PRESET BUDGETS
|
|
909
|
+
// =============================================================================
|
|
910
|
+
/**
|
|
911
|
+
* Quick task budget - for simple queries.
|
|
912
|
+
*/
|
|
913
|
+
export const QUICK_BUDGET = {
|
|
914
|
+
maxTokens: 50000,
|
|
915
|
+
maxCost: 0.10,
|
|
916
|
+
maxDuration: 60000, // 1 minute
|
|
917
|
+
targetIterations: 5,
|
|
918
|
+
maxIterations: 20,
|
|
919
|
+
};
|
|
920
|
+
/**
|
|
921
|
+
* Standard task budget - for typical development tasks.
|
|
922
|
+
*/
|
|
923
|
+
export const STANDARD_BUDGET = {
|
|
924
|
+
maxTokens: 200000,
|
|
925
|
+
maxCost: 0.50,
|
|
926
|
+
maxDuration: 600000, // 10 minutes (supports subagent workflows)
|
|
927
|
+
targetIterations: 20,
|
|
928
|
+
maxIterations: 50,
|
|
929
|
+
};
|
|
930
|
+
/**
|
|
931
|
+
* Subagent budget - constrained budget for spawned subagents.
|
|
932
|
+
* Smaller than STANDARD to ensure subagents don't consume all parent's resources.
|
|
933
|
+
* The 100k token limit gives subagents room to work while leaving budget for the parent
|
|
934
|
+
* and other parallel subagents.
|
|
935
|
+
*/
|
|
936
|
+
export const SUBAGENT_BUDGET = {
|
|
937
|
+
maxTokens: 250000, // 250k tokens -- coders need room for explore + code
|
|
938
|
+
softTokenLimit: 180000, // Warn at 180k
|
|
939
|
+
maxCost: 0.75, // Increased ceiling for heavier workloads
|
|
940
|
+
maxDuration: 480000, // 8 minutes
|
|
941
|
+
softDurationLimit: 420000, // Warn at 7 minutes
|
|
942
|
+
targetIterations: 30,
|
|
943
|
+
maxIterations: 60,
|
|
944
|
+
};
|
|
945
|
+
/**
|
|
946
|
+
* Large task budget - for complex multi-step tasks.
|
|
947
|
+
*/
|
|
948
|
+
export const LARGE_BUDGET = {
|
|
949
|
+
maxTokens: 500000,
|
|
950
|
+
maxCost: 2.00,
|
|
951
|
+
maxDuration: 900000, // 15 minutes
|
|
952
|
+
targetIterations: 50,
|
|
953
|
+
maxIterations: 200,
|
|
954
|
+
};
|
|
955
|
+
/**
|
|
956
|
+
* TUI root agent budget - no time limit, high iteration cap.
|
|
957
|
+
* The TUI root agent must be able to run as long as needed (swarm tasks,
|
|
958
|
+
* multi-step workflows). Duration is effectively unlimited; token/cost
|
|
959
|
+
* limits still apply as a safety net.
|
|
960
|
+
*/
|
|
961
|
+
export const TUI_ROOT_BUDGET = {
|
|
962
|
+
enforcementMode: 'doomloop_only',
|
|
963
|
+
maxTokens: 500000,
|
|
964
|
+
softTokenLimit: 400000,
|
|
965
|
+
maxCost: 5.00,
|
|
966
|
+
softCostLimit: 4.00,
|
|
967
|
+
maxDuration: Infinity, // No time limit -- run as long as tasks remain
|
|
968
|
+
softDurationLimit: Infinity,
|
|
969
|
+
targetIterations: 100,
|
|
970
|
+
maxIterations: 500,
|
|
971
|
+
};
|
|
972
|
+
/**
|
|
973
|
+
* Unlimited budget - no limits (use with caution).
|
|
974
|
+
*/
|
|
975
|
+
export const UNLIMITED_BUDGET = {
|
|
976
|
+
maxTokens: Infinity,
|
|
977
|
+
maxCost: Infinity,
|
|
978
|
+
maxDuration: Infinity,
|
|
979
|
+
targetIterations: Infinity,
|
|
980
|
+
maxIterations: Infinity,
|
|
981
|
+
};
|
|
982
|
+
/**
|
|
983
|
+
* Swarm worker budget - tight constraints for small specialist models.
|
|
984
|
+
* Each worker gets a small slice of the total swarm budget.
|
|
985
|
+
*/
|
|
986
|
+
export const SWARM_WORKER_BUDGET = {
|
|
987
|
+
maxTokens: 30000,
|
|
988
|
+
softTokenLimit: 25000,
|
|
989
|
+
maxCost: 0.08,
|
|
990
|
+
maxDuration: 180000, // 3 minutes
|
|
991
|
+
softDurationLimit: 150000, // Warn at 2.5 min
|
|
992
|
+
targetIterations: 15,
|
|
993
|
+
maxIterations: 25,
|
|
994
|
+
};
|
|
995
|
+
/**
|
|
996
|
+
* Swarm orchestrator budget - moderate budget for decomposition and quality gates.
|
|
997
|
+
*/
|
|
998
|
+
export const SWARM_ORCHESTRATOR_BUDGET = {
|
|
999
|
+
maxTokens: 100000,
|
|
1000
|
+
softTokenLimit: 80000,
|
|
1001
|
+
maxCost: 0.25,
|
|
1002
|
+
maxDuration: 300000, // 5 minutes
|
|
1003
|
+
softDurationLimit: 240000,
|
|
1004
|
+
targetIterations: 30,
|
|
1005
|
+
maxIterations: 50,
|
|
1006
|
+
};
|
|
1007
|
+
//# sourceMappingURL=economics.js.map
|