@prometheus-ai/agent 0.5.3 → 0.5.8
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 +39 -0
- package/dist/cli.js +25110 -0
- package/dist/types/async/index.d.ts +0 -1
- package/dist/types/async/job-manager.d.ts +33 -0
- package/dist/types/autolearn/controller.d.ts +25 -0
- package/dist/types/autolearn/managed-skills.d.ts +45 -0
- package/dist/types/autoresearch/state.d.ts +1 -1
- package/dist/types/autoresearch/tools/init-experiment.d.ts +1 -1
- package/dist/types/autoresearch/tools/log-experiment.d.ts +1 -1
- package/dist/types/autoresearch/tools/run-experiment.d.ts +1 -1
- package/dist/types/autoresearch/tools/update-notes.d.ts +1 -1
- package/dist/types/autoresearch/types.d.ts +1 -1
- package/dist/types/capability/context-file.d.ts +0 -13
- package/dist/types/capability/mcp.d.ts +1 -0
- package/dist/types/capability/rule-buckets.d.ts +1 -1
- package/dist/types/capability/rule.d.ts +6 -1
- package/dist/types/capability/types.d.ts +0 -4
- package/dist/types/cli/args.d.ts +23 -3
- package/dist/types/cli/bench-cli.d.ts +78 -0
- package/dist/types/cli/claude-trace-cli.d.ts +7 -0
- package/dist/types/cli/dry-balance-cli.d.ts +16 -2
- package/dist/types/cli/gallery-cli.d.ts +43 -0
- package/dist/types/cli/gallery-fixtures/agentic.d.ts +2 -0
- package/dist/types/cli/gallery-fixtures/codeintel.d.ts +3 -0
- package/dist/types/cli/gallery-fixtures/edit.d.ts +3 -0
- package/dist/types/cli/gallery-fixtures/fs.d.ts +2 -0
- package/dist/types/cli/gallery-fixtures/index.d.ts +4 -0
- package/dist/types/cli/gallery-fixtures/interaction.d.ts +3 -0
- package/dist/types/cli/gallery-fixtures/memory.d.ts +2 -0
- package/dist/types/cli/gallery-fixtures/misc.d.ts +3 -0
- package/dist/types/cli/gallery-fixtures/search.d.ts +3 -0
- package/dist/types/cli/gallery-fixtures/shell.d.ts +3 -0
- package/dist/types/cli/gallery-fixtures/types.d.ts +55 -0
- package/dist/types/cli/gallery-fixtures/web.d.ts +2 -0
- package/dist/types/cli/gallery-screenshot.d.ts +35 -0
- package/dist/types/cli/gateway-cli.d.ts +4 -0
- package/dist/types/cli/grievances-cli.d.ts +1 -1
- package/dist/types/cli/list-models.d.ts +6 -14
- package/dist/types/cli/models-cli.d.ts +49 -0
- package/dist/types/cli/session-picker.d.ts +1 -1
- package/dist/types/cli/setup-cli.d.ts +1 -1
- package/dist/types/cli/setup-model-picker.d.ts +14 -0
- package/dist/types/cli/startup-cwd.d.ts +2 -0
- package/dist/types/cli/update-cli.d.ts +13 -40
- package/dist/types/cli/usage-cli.d.ts +81 -0
- package/dist/types/cli-commands.d.ts +12 -0
- package/dist/types/collab/crypto.d.ts +7 -0
- package/dist/types/collab/guest.d.ts +37 -0
- package/dist/types/collab/host.d.ts +29 -0
- package/dist/types/collab/protocol.d.ts +119 -0
- package/dist/types/collab/relay-client.d.ts +22 -0
- package/dist/types/commands/bench.d.ts +29 -0
- package/dist/types/commands/gallery.d.ts +47 -0
- package/dist/types/commands/gateway.d.ts +3 -0
- package/dist/types/commands/install.d.ts +1 -1
- package/dist/types/commands/join.d.ts +12 -0
- package/dist/types/commands/launch.d.ts +8 -4
- package/dist/types/commands/models.d.ts +33 -0
- package/dist/types/commands/read.d.ts +1 -1
- package/dist/types/commands/say.d.ts +24 -0
- package/dist/types/commands/token.d.ts +25 -0
- package/dist/types/commands/usage.d.ts +34 -0
- package/dist/types/commit/agentic/tools/analyze-file.d.ts +1 -1
- package/dist/types/commit/agentic/tools/git-file-diff.d.ts +1 -1
- package/dist/types/commit/agentic/tools/git-hunk.d.ts +1 -1
- package/dist/types/commit/agentic/tools/git-overview.d.ts +1 -1
- package/dist/types/commit/agentic/tools/propose-changelog.d.ts +1 -1
- package/dist/types/commit/agentic/tools/propose-commit.d.ts +1 -1
- package/dist/types/commit/agentic/tools/recent-commits.d.ts +1 -1
- package/dist/types/commit/agentic/tools/schemas.d.ts +1 -1
- package/dist/types/commit/agentic/tools/split-commit.d.ts +1 -1
- package/dist/types/commit/analysis/conventional.d.ts +2 -2
- package/dist/types/commit/analysis/summary.d.ts +2 -2
- package/dist/types/commit/changelog/generate.d.ts +3 -3
- package/dist/types/commit/changelog/index.d.ts +2 -2
- package/dist/types/commit/map-reduce/index.d.ts +3 -3
- package/dist/types/commit/map-reduce/map-phase.d.ts +2 -2
- package/dist/types/commit/map-reduce/reduce-phase.d.ts +2 -2
- package/dist/types/commit/model-selection.d.ts +10 -4
- package/dist/types/commit/shared-llm.d.ts +1 -1
- package/dist/types/config/api-key-resolver.d.ts +43 -0
- package/dist/types/config/append-only-context-mode.d.ts +2 -1
- package/dist/types/config/keybindings.d.ts +12 -7
- package/dist/types/config/model-discovery.d.ts +57 -0
- package/dist/types/config/model-equivalence.d.ts +1 -1
- package/dist/types/config/model-registry.d.ts +86 -222
- package/dist/types/config/model-resolver.d.ts +43 -12
- package/dist/types/config/model-roles.d.ts +29 -0
- package/dist/types/config/models-config-schema.d.ts +536 -43
- package/dist/types/config/models-config.d.ts +391 -0
- package/dist/types/config/settings-schema.d.ts +1211 -324
- package/dist/types/config/settings.d.ts +15 -3
- package/dist/types/dap/config.d.ts +14 -1
- package/dist/types/dap/types.d.ts +10 -0
- package/dist/types/debug/log-viewer.d.ts +1 -1
- package/dist/types/debug/raw-sse.d.ts +1 -1
- package/dist/types/debug/report-bundle.d.ts +3 -0
- package/dist/types/debug/terminal-info.d.ts +0 -1
- package/dist/types/discovery/at-imports.d.ts +15 -0
- package/dist/types/discovery/prometheus-extension-roots.d.ts +7 -7
- package/dist/types/edit/diff.d.ts +3 -2
- package/dist/types/edit/file-snapshot-store.d.ts +18 -0
- package/dist/types/edit/hashline/noop-loop-guard.d.ts +72 -0
- package/dist/types/edit/hashline/params.d.ts +1 -1
- package/dist/types/edit/index.d.ts +0 -1
- package/dist/types/edit/modes/apply-patch.d.ts +1 -1
- package/dist/types/edit/modes/patch.d.ts +1 -1
- package/dist/types/edit/modes/replace.d.ts +1 -1
- package/dist/types/edit/renderer.d.ts +1 -0
- package/dist/types/eval/__tests__/completion-bridge.test.d.ts +1 -0
- package/dist/types/eval/__tests__/helpers-local-roots.test.d.ts +1 -0
- package/dist/types/eval/__tests__/js-context-manager.test.d.ts +1 -0
- package/dist/types/eval/backend.d.ts +7 -2
- package/dist/types/eval/bridge-timeout.d.ts +1 -1
- package/dist/types/eval/completion-bridge.d.ts +25 -0
- package/dist/types/eval/idle-timeout.d.ts +1 -5
- package/dist/types/eval/js/context-manager.d.ts +1 -0
- package/dist/types/eval/js/executor.d.ts +2 -0
- package/dist/types/eval/js/index.d.ts +1 -1
- package/dist/types/eval/js/shared/helpers.d.ts +7 -1
- package/dist/types/eval/js/shared/rewrite-imports.d.ts +6 -6
- package/dist/types/eval/js/shared/runtime.d.ts +6 -1
- package/dist/types/eval/js/worker-protocol.d.ts +6 -0
- package/dist/types/eval/py/__tests__/prelude.test.d.ts +1 -0
- package/dist/types/eval/py/executor.d.ts +12 -0
- package/dist/types/eval/py/index.d.ts +1 -1
- package/dist/types/eval/py/kernel.d.ts +6 -1
- package/dist/types/eval/py/runtime.d.ts +9 -0
- package/dist/types/exa/index.d.ts +1 -19
- package/dist/types/exa/mcp-client.d.ts +10 -3
- package/dist/types/exa/types.d.ts +0 -83
- package/dist/types/exec/bash-executor.d.ts +7 -0
- package/dist/types/export/custom-share.d.ts +1 -2
- package/dist/types/export/html/index.d.ts +39 -0
- package/dist/types/export/html/template-js.d.ts +2 -0
- package/dist/types/export/share.d.ts +61 -0
- package/dist/types/export/ttsr.d.ts +14 -0
- package/dist/types/extensibility/custom-commands/types.d.ts +9 -4
- package/dist/types/extensibility/custom-tools/loader.d.ts +30 -4
- package/dist/types/extensibility/custom-tools/types.d.ts +16 -8
- package/dist/types/extensibility/extensions/index.d.ts +1 -1
- package/dist/types/extensibility/extensions/loader.d.ts +20 -1
- package/dist/types/extensibility/extensions/model-api.d.ts +17 -0
- package/dist/types/extensibility/extensions/runner.d.ts +5 -2
- package/dist/types/extensibility/extensions/types.d.ts +72 -11
- package/dist/types/extensibility/hooks/index.d.ts +2 -1
- package/dist/types/extensibility/hooks/loader.d.ts +1 -1
- package/dist/types/extensibility/hooks/types.d.ts +11 -5
- package/dist/types/extensibility/{legacy-pi-ai-shim.d.ts → legacy-package-ai-shim.d.ts} +2 -2
- package/dist/types/extensibility/plugins/{legacy-pi-compat.d.ts → legacy-package-compat.d.ts} +20 -3
- package/dist/types/extensibility/plugins/loader.d.ts +11 -0
- package/dist/types/extensibility/plugins/marketplace-auto-update.d.ts +8 -0
- package/dist/types/extensibility/plugins/types.d.ts +2 -2
- package/dist/types/extensibility/shared-events.d.ts +3 -3
- package/dist/types/extensibility/skills.d.ts +10 -0
- package/dist/types/extensibility/slash-commands.d.ts +1 -11
- package/dist/types/gateway/adapters/telegram/access.d.ts +4 -1
- package/dist/types/gateway/adapters/telegram/setup-api.d.ts +1 -1
- package/dist/types/gateway/adapters/telegram/webhook.d.ts +1 -1
- package/dist/types/gateway/types.d.ts +1 -1
- package/dist/types/goals/guided-setup.d.ts +18 -0
- package/dist/types/goals/state.d.ts +1 -1
- package/dist/types/goals/tools/goal-tool.d.ts +1 -1
- package/dist/types/hindsight/mental-models.d.ts +17 -8
- package/dist/types/hindsight/transcript.d.ts +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/internal-urls/artifact-protocol.d.ts +2 -2
- package/dist/types/internal-urls/history-protocol.d.ts +14 -0
- package/dist/types/internal-urls/index.d.ts +1 -0
- package/dist/types/internal-urls/local-protocol.d.ts +14 -2
- package/dist/types/internal-urls/types.d.ts +1 -1
- package/dist/types/irc/bus.d.ts +79 -0
- package/dist/types/lib/xai-http.d.ts +1 -1
- package/dist/types/lsp/client.d.ts +10 -0
- package/dist/types/lsp/config.d.ts +2 -2
- package/dist/types/lsp/edits.d.ts +9 -0
- package/dist/types/lsp/format-options.d.ts +32 -0
- package/dist/types/lsp/index.d.ts +2 -7
- package/dist/types/lsp/types.d.ts +13 -1
- package/dist/types/lsp/utils.d.ts +6 -2
- package/dist/types/main.d.ts +23 -8
- package/dist/types/mcp/json-rpc.d.ts +5 -0
- package/dist/types/mcp/manager.d.ts +8 -0
- package/dist/types/mcp/oauth-discovery.d.ts +6 -1
- package/dist/types/mcp/oauth-flow.d.ts +13 -3
- package/dist/types/mcp/startup-events.d.ts +11 -0
- package/dist/types/mcp/tool-bridge.d.ts +2 -0
- package/dist/types/mcp/transports/stdio.d.ts +13 -0
- package/dist/types/mcp/types.d.ts +2 -0
- package/dist/types/memories/index.d.ts +7 -15
- package/dist/types/memories/storage.d.ts +0 -10
- package/dist/types/memory-backend/index.d.ts +3 -1
- package/dist/types/memory-backend/local-backend.d.ts +4 -3
- package/dist/types/memory-backend/resolve.d.ts +2 -2
- package/dist/types/memory-backend/runtime.d.ts +4 -0
- package/dist/types/memory-backend/types.d.ts +67 -2
- package/dist/types/mnemopi/config.d.ts +31 -1
- package/dist/types/mnemopi/state.d.ts +40 -2
- package/dist/types/modes/acp/acp-agent.d.ts +1 -2
- package/dist/types/modes/components/agent-dashboard.d.ts +17 -1
- package/dist/types/modes/components/agent-hub.d.ts +82 -0
- package/dist/types/modes/components/assistant-message.d.ts +5 -12
- package/dist/types/modes/components/bash-execution.d.ts +1 -1
- package/dist/types/modes/components/chat-block.d.ts +64 -0
- package/dist/types/modes/components/collab-prompt-message.d.ts +10 -0
- package/dist/types/modes/components/compaction-summary-message.d.ts +25 -5
- package/dist/types/modes/components/copy-selector.d.ts +1 -1
- package/dist/types/modes/components/custom-editor.d.ts +49 -2
- package/dist/types/modes/components/custom-editor.test.d.ts +1 -0
- package/dist/types/modes/components/dynamic-border.d.ts +1 -1
- package/dist/types/modes/components/extensions/extension-dashboard.d.ts +1 -1
- package/dist/types/modes/components/extensions/extension-list.d.ts +1 -1
- package/dist/types/modes/components/extensions/inspector-panel.d.ts +1 -1
- package/dist/types/modes/components/footer.d.ts +1 -1
- package/dist/types/modes/components/hook-editor.d.ts +5 -0
- package/dist/types/modes/components/hook-input.d.ts +4 -0
- package/dist/types/modes/components/hook-selector.d.ts +5 -7
- package/dist/types/modes/components/index.d.ts +1 -0
- package/dist/types/modes/components/late-diagnostics-message.d.ts +20 -0
- package/dist/types/modes/components/logout-account-selector.d.ts +8 -0
- package/dist/types/modes/components/mcp-add-wizard.d.ts +2 -1
- package/dist/types/modes/components/model-selector.d.ts +1 -1
- package/dist/types/modes/components/oauth-selector.d.ts +10 -1
- package/dist/types/modes/components/overlay-box.d.ts +17 -0
- package/dist/types/modes/components/plan-review-overlay.d.ts +61 -0
- package/dist/types/modes/components/plan-toc.d.ts +41 -0
- package/dist/types/modes/components/read-tool-group.d.ts +8 -0
- package/dist/types/modes/components/reset-usage-selector.d.ts +12 -0
- package/dist/types/modes/components/segment-track.d.ts +11 -6
- package/dist/types/modes/components/session-selector.d.ts +18 -9
- package/dist/types/modes/components/settings-defs.d.ts +9 -2
- package/dist/types/modes/components/settings-selector.d.ts +17 -4
- package/dist/types/modes/components/snapcompact-shape-preview.d.ts +31 -0
- package/dist/types/modes/components/status-line/component.d.ts +61 -0
- package/dist/types/modes/components/status-line/index.d.ts +1 -0
- package/dist/types/modes/components/status-line/types.d.ts +47 -3
- package/dist/types/modes/components/tiny-title-download-progress.d.ts +1 -1
- package/dist/types/modes/components/tool-execution.d.ts +49 -2
- package/dist/types/modes/components/transcript-container.d.ts +76 -26
- package/dist/types/modes/components/tree-selector.d.ts +2 -2
- package/dist/types/modes/components/ttsr-notification.d.ts +5 -1
- package/dist/types/modes/components/usage-row.d.ts +3 -0
- package/dist/types/modes/components/user-message-selector.d.ts +1 -1
- package/dist/types/modes/components/user-message.d.ts +2 -1
- package/dist/types/modes/components/visual-truncate.d.ts +1 -1
- package/dist/types/modes/components/welcome.d.ts +12 -2
- package/dist/types/modes/controllers/command-controller.d.ts +3 -2
- package/dist/types/modes/controllers/event-controller.d.ts +7 -1
- package/dist/types/modes/controllers/extension-ui-controller.d.ts +0 -1
- package/dist/types/modes/controllers/input-controller.d.ts +25 -3
- package/dist/types/modes/controllers/mcp-command-controller.d.ts +8 -0
- package/dist/types/modes/controllers/selector-controller.d.ts +5 -2
- package/dist/types/modes/controllers/session-focus-controller.d.ts +31 -0
- package/dist/types/modes/controllers/streaming-reveal.d.ts +22 -0
- package/dist/types/modes/controllers/tan-command-controller.d.ts +6 -0
- package/dist/types/modes/controllers/tool-args-reveal.d.ts +43 -0
- package/dist/types/modes/gradient-highlight.d.ts +9 -4
- package/dist/types/modes/image-references.d.ts +14 -3
- package/dist/types/modes/index.d.ts +8 -7
- package/dist/types/modes/interactive-mode.d.ts +92 -16
- package/dist/types/modes/magic-keywords.d.ts +14 -2
- package/dist/types/modes/markdown-prose.d.ts +1 -1
- package/dist/types/modes/oauth-manual-input.d.ts +7 -0
- package/dist/types/modes/rpc/rpc-client.d.ts +48 -2
- package/dist/types/modes/rpc/rpc-mode.d.ts +67 -2
- package/dist/types/modes/rpc/rpc-subagents.d.ts +24 -0
- package/dist/types/modes/rpc/rpc-types.d.ts +113 -1
- package/dist/types/modes/runtime-init.d.ts +4 -0
- package/dist/types/modes/session-observer-registry.d.ts +9 -0
- package/dist/types/modes/setup-version.d.ts +11 -0
- package/dist/types/modes/setup-wizard/index.d.ts +7 -2
- package/dist/types/modes/setup-wizard/lazy.d.ts +2 -0
- package/dist/types/modes/setup-wizard/scenes/sign-in.d.ts +4 -1
- package/dist/types/modes/setup-wizard/scenes/types.d.ts +11 -2
- package/dist/types/modes/setup-wizard/scenes/web-search.d.ts +6 -2
- package/dist/types/modes/setup-wizard/wizard-overlay.d.ts +1 -1
- package/dist/types/modes/theme/theme.d.ts +42 -7
- package/dist/types/modes/types.d.ts +62 -13
- package/dist/types/modes/utils/context-usage.d.ts +6 -1
- package/dist/types/modes/utils/copy-targets.d.ts +21 -1
- package/dist/types/modes/utils/ui-helpers.d.ts +4 -4
- package/dist/types/modes/workflow.d.ts +3 -3
- package/dist/types/plan-mode/approved-plan.d.ts +27 -8
- package/dist/types/plan-mode/plan-protection.d.ts +4 -4
- package/dist/types/registry/agent-lifecycle.d.ts +51 -0
- package/dist/types/registry/agent-registry.d.ts +33 -5
- package/dist/types/sdk.d.ts +46 -4
- package/dist/types/secrets/index.d.ts +1 -1
- package/dist/types/secrets/obfuscator.d.ts +9 -3
- package/dist/types/session/agent-session.d.ts +136 -66
- package/dist/types/session/agent-storage.d.ts +2 -1
- package/dist/types/session/auth-broker-config.d.ts +4 -0
- package/dist/types/session/auth-storage.d.ts +1 -1
- package/dist/types/session/codex-auto-reset.d.ts +111 -0
- package/dist/types/session/indexed-session-storage.d.ts +3 -3
- package/dist/types/session/messages.d.ts +26 -15
- package/dist/types/session/session-context.d.ts +39 -0
- package/dist/types/session/session-entries.d.ts +159 -0
- package/dist/types/session/session-history-format.d.ts +12 -0
- package/dist/types/session/session-listing.d.ts +69 -0
- package/dist/types/session/session-loader.d.ts +16 -0
- package/dist/types/session/session-manager.d.ts +107 -440
- package/dist/types/session/session-migrations.d.ts +12 -0
- package/dist/types/session/session-paths.d.ts +25 -0
- package/dist/types/session/session-persistence.d.ts +8 -0
- package/dist/types/session/session-storage.d.ts +11 -7
- package/dist/types/session/snapcompact-inline.d.ts +145 -0
- package/dist/types/session/snapcompact-savings-journal.d.ts +46 -0
- package/dist/types/session/streaming-output.d.ts +46 -0
- package/dist/types/session/tool-choice-queue.d.ts +6 -6
- package/dist/types/session/yield-queue.d.ts +10 -1
- package/dist/types/slash-commands/acp-builtins.d.ts +16 -0
- package/dist/types/slash-commands/available-commands.d.ts +34 -0
- package/dist/types/slash-commands/builtin-registry.d.ts +10 -0
- package/dist/types/slash-commands/helpers/active-oauth-account.d.ts +14 -0
- package/dist/types/slash-commands/helpers/logout.d.ts +15 -0
- package/dist/types/slash-commands/helpers/reset-usage.d.ts +27 -0
- package/dist/types/slash-commands/helpers/stats-dashboard.d.ts +13 -0
- package/dist/types/slash-commands/types.d.ts +5 -9
- package/dist/types/ssh/connection-manager.d.ts +8 -0
- package/dist/types/stt/asr-client.d.ts +90 -0
- package/dist/types/stt/asr-protocol.d.ts +97 -0
- package/dist/types/stt/asr-worker.d.ts +2 -0
- package/dist/types/stt/downloader.d.ts +38 -0
- package/dist/types/stt/endpointer.d.ts +59 -0
- package/dist/types/stt/index.d.ts +5 -1
- package/dist/types/stt/models.d.ts +120 -0
- package/dist/types/stt/recorder.d.ts +17 -0
- package/dist/types/stt/stt-controller.d.ts +6 -0
- package/dist/types/stt/transcriber.d.ts +5 -7
- package/dist/types/stt/wav.d.ts +29 -0
- package/dist/types/system-prompt.d.ts +9 -1
- package/dist/types/task/commands.d.ts +1 -1
- package/dist/types/task/discovery.d.ts +1 -2
- package/dist/types/task/executor.d.ts +61 -2
- package/dist/types/task/index.d.ts +37 -6
- package/dist/types/task/output-manager.d.ts +0 -7
- package/dist/types/task/parallel.d.ts +2 -2
- package/dist/types/task/prometheus-command.d.ts +2 -2
- package/dist/types/task/render.d.ts +20 -7
- package/dist/types/task/repair-args.d.ts +8 -7
- package/dist/types/task/types.d.ts +109 -52
- package/dist/types/task/worktree.d.ts +2 -0
- package/dist/types/telemetry-export.d.ts +2 -2
- package/dist/types/thinking.d.ts +4 -0
- package/dist/types/tiny/models.d.ts +1 -1
- package/dist/types/tiny/title-client.d.ts +12 -1
- package/dist/types/tiny/title-protocol.d.ts +1 -0
- package/dist/types/tools/archive-reader.d.ts +5 -0
- package/dist/types/tools/ask.d.ts +6 -1
- package/dist/types/tools/ast-edit.d.ts +4 -1
- package/dist/types/tools/ast-grep.d.ts +4 -1
- package/dist/types/tools/bash.d.ts +5 -2
- package/dist/types/tools/browser/attach.d.ts +4 -4
- package/dist/types/tools/browser/cmux/cmux-tab.d.ts +202 -0
- package/dist/types/tools/browser/cmux/rpc.d.ts +70 -0
- package/dist/types/tools/browser/cmux/socket-client.d.ts +19 -0
- package/dist/types/tools/browser/registry.d.ts +17 -3
- package/dist/types/tools/browser/render.d.ts +2 -0
- package/dist/types/tools/browser/tab-protocol.d.ts +2 -0
- package/dist/types/tools/browser/tab-supervisor.d.ts +16 -4
- package/dist/types/tools/browser/tab-worker.d.ts +18 -1
- package/dist/types/tools/browser.d.ts +3 -1
- package/dist/types/tools/checkpoint.d.ts +1 -1
- package/dist/types/tools/conflict-detect.d.ts +16 -0
- package/dist/types/tools/debug.d.ts +1 -1
- package/dist/types/tools/eval-render.d.ts +1 -8
- package/dist/types/tools/eval.d.ts +9 -1
- package/dist/types/tools/fetch.d.ts +17 -8
- package/dist/types/tools/find.d.ts +1 -8
- package/dist/types/tools/gh-cache-invalidation.d.ts +6 -0
- package/dist/types/tools/gh.d.ts +4 -1
- package/dist/types/tools/github-cache.d.ts +19 -0
- package/dist/types/tools/grouped-file-output.d.ts +46 -12
- package/dist/types/tools/image-gen.d.ts +1 -1
- package/dist/types/tools/index.d.ts +89 -8
- package/dist/types/tools/inspect-image.d.ts +1 -1
- package/dist/types/tools/irc.d.ts +79 -39
- package/dist/types/tools/job.d.ts +8 -2
- package/dist/types/tools/learn.d.ts +51 -0
- package/dist/types/tools/manage-skill.d.ts +40 -0
- package/dist/types/tools/memory-edit.d.ts +2 -2
- package/dist/types/tools/memory-recall.d.ts +1 -1
- package/dist/types/tools/memory-reflect.d.ts +1 -1
- package/dist/types/tools/memory-render.d.ts +4 -1
- package/dist/types/tools/memory-retain.d.ts +1 -1
- package/dist/types/tools/path-utils.d.ts +17 -5
- package/dist/types/tools/plan-mode-guard.d.ts +18 -9
- package/dist/types/tools/read.d.ts +3 -2
- package/dist/types/tools/render-mermaid.d.ts +1 -1
- package/dist/types/tools/render-utils.d.ts +47 -27
- package/dist/types/tools/renderers.d.ts +10 -2
- package/dist/types/tools/report-tool-issue.d.ts +6 -1
- package/dist/types/tools/resolve.d.ts +1 -1
- package/dist/types/tools/review.d.ts +1 -1
- package/dist/types/tools/search-tool-bm25.d.ts +1 -1
- package/dist/types/tools/search.d.ts +7 -3
- package/dist/types/tools/sqlite-reader.d.ts +4 -0
- package/dist/types/tools/ssh.d.ts +2 -1
- package/dist/types/tools/todo.d.ts +7 -15
- package/dist/types/tools/tool-result.d.ts +2 -0
- package/dist/types/tools/tool-timeouts.d.ts +1 -1
- package/dist/types/tools/tts.d.ts +26 -1
- package/dist/types/tools/write.d.ts +6 -3
- package/dist/types/tools/yield.d.ts +8 -0
- package/dist/types/tts/downloader.d.ts +20 -0
- package/dist/types/tts/index.d.ts +8 -0
- package/dist/types/tts/models.d.ts +82 -0
- package/dist/types/tts/player.d.ts +32 -0
- package/dist/types/tts/runtime.d.ts +6 -0
- package/dist/types/tts/streaming-player.d.ts +41 -0
- package/dist/types/tts/tts-client.d.ts +93 -0
- package/dist/types/tts/tts-protocol.d.ts +95 -0
- package/dist/types/tts/tts-worker.d.ts +2 -0
- package/dist/types/tts/vocalizer.d.ts +41 -0
- package/dist/types/tts/wav.d.ts +8 -0
- package/dist/types/tui/code-cell.d.ts +0 -2
- package/dist/types/tui/hyperlink.d.ts +13 -7
- package/dist/types/tui/output-block.d.ts +16 -22
- package/dist/types/tui/status-line.d.ts +3 -0
- package/dist/types/utils/block-context.d.ts +35 -0
- package/dist/types/utils/changelog.d.ts +8 -0
- package/dist/types/utils/clipboard.d.ts +4 -3
- package/dist/types/utils/enhanced-paste.d.ts +20 -0
- package/dist/types/utils/file-mentions.d.ts +7 -0
- package/dist/types/utils/git.d.ts +22 -3
- package/dist/types/utils/image-loading.d.ts +30 -1
- package/dist/types/utils/session-color.d.ts +15 -3
- package/dist/types/utils/thinking-display.d.ts +17 -0
- package/dist/types/utils/title-generator.d.ts +3 -2
- package/dist/types/utils/tool-choice.d.ts +8 -0
- package/dist/types/utils/tools-manager.d.ts +2 -1
- package/dist/types/web/kagi.d.ts +2 -2
- package/dist/types/web/parallel.d.ts +3 -0
- package/dist/types/web/scrapers/github.d.ts +22 -0
- package/dist/types/web/scrapers/readthedocs.d.ts +3 -0
- package/dist/types/web/scrapers/types.d.ts +12 -0
- package/dist/types/web/search/index.d.ts +1 -1
- package/dist/types/web/search/providers/anthropic.d.ts +2 -1
- package/dist/types/web/search/providers/base.d.ts +2 -1
- package/dist/types/web/search/providers/brave.d.ts +2 -1
- package/dist/types/web/search/providers/codex.d.ts +2 -1
- package/dist/types/web/search/providers/exa.d.ts +2 -1
- package/dist/types/web/search/providers/gemini.d.ts +10 -6
- package/dist/types/web/search/providers/jina.d.ts +7 -2
- package/dist/types/web/search/providers/kagi.d.ts +7 -2
- package/dist/types/web/search/providers/kimi.d.ts +7 -2
- package/dist/types/web/search/providers/parallel.d.ts +2 -1
- package/dist/types/web/search/providers/perplexity.d.ts +10 -2
- package/dist/types/web/search/providers/searxng.d.ts +2 -1
- package/dist/types/web/search/providers/synthetic.d.ts +7 -3
- package/dist/types/web/search/providers/tavily.d.ts +2 -1
- package/dist/types/web/search/providers/zai.d.ts +2 -1
- package/dist/types/web/search/types.d.ts +1 -1
- package/examples/extensions/api-demo.ts +2 -2
- package/package.json +41 -15
- package/scripts/bench-guard.ts +71 -0
- package/scripts/build-binary.ts +24 -25
- package/scripts/bundle-dist.ts +97 -0
- package/scripts/generate-share-viewer.ts +34 -0
- package/scripts/prometheus +42 -0
- package/scripts/prometheus.ts +20 -0
- package/src/async/index.ts +0 -1
- package/src/async/job-manager.ts +106 -3
- package/src/auto-thinking/classifier.ts +2 -1
- package/src/autolearn/controller.ts +139 -0
- package/src/autolearn/managed-skills.ts +257 -0
- package/src/autoresearch/dashboard.ts +1 -1
- package/src/autoresearch/prompt-setup.md +6 -6
- package/src/autoresearch/prompt.md +6 -6
- package/src/autoresearch/state.ts +1 -1
- package/src/autoresearch/storage.ts +2 -1
- package/src/autoresearch/tools/init-experiment.ts +1 -1
- package/src/autoresearch/tools/log-experiment.ts +1 -1
- package/src/autoresearch/tools/run-experiment.ts +1 -1
- package/src/autoresearch/tools/update-notes.ts +1 -1
- package/src/autoresearch/types.ts +1 -1
- package/src/capability/context-file.ts +0 -14
- package/src/capability/fs.ts +10 -0
- package/src/capability/index.ts +1 -6
- package/src/capability/mcp.ts +1 -0
- package/src/capability/rule-buckets.ts +4 -2
- package/src/capability/rule.ts +10 -1
- package/src/capability/types.ts +0 -4
- package/src/cli/args.ts +66 -13
- package/src/cli/auth-broker-cli.ts +6 -7
- package/src/cli/auth-gateway-cli.ts +8 -9
- package/src/cli/bench-cli.ts +437 -0
- package/src/cli/claude-trace-cli.ts +28 -50
- package/src/cli/completion-gen.ts +28 -28
- package/src/cli/dry-balance-cli.ts +56 -23
- package/src/cli/gallery-cli.ts +231 -0
- package/src/cli/gallery-fixtures/agentic.ts +407 -0
- package/src/cli/gallery-fixtures/codeintel.ts +187 -0
- package/src/cli/gallery-fixtures/edit.ts +194 -0
- package/src/cli/gallery-fixtures/fs.ts +220 -0
- package/src/cli/gallery-fixtures/index.ts +40 -0
- package/src/cli/gallery-fixtures/interaction.ts +49 -0
- package/src/cli/gallery-fixtures/memory.ts +81 -0
- package/src/cli/gallery-fixtures/misc.ts +250 -0
- package/src/cli/gallery-fixtures/search.ts +213 -0
- package/src/cli/gallery-fixtures/shell.ts +167 -0
- package/src/cli/gallery-fixtures/types.ts +57 -0
- package/src/cli/gallery-fixtures/web.ts +158 -0
- package/src/cli/gallery-screenshot.ts +279 -0
- package/src/cli/gateway-cli.ts +32 -2
- package/src/cli/grievances-cli.ts +1 -1
- package/src/cli/list-models.ts +16 -174
- package/src/cli/models-cli.ts +429 -0
- package/src/cli/session-picker.ts +2 -1
- package/src/cli/setup-cli.ts +148 -47
- package/src/cli/setup-model-picker.ts +43 -0
- package/src/cli/startup-cwd.ts +68 -0
- package/src/cli/update-cli.ts +144 -272
- package/src/cli/usage-cli.ts +774 -0
- package/src/cli-commands.ts +36 -0
- package/src/cli.ts +141 -32
- package/src/collab/crypto.ts +63 -0
- package/src/collab/guest.ts +451 -0
- package/src/collab/host.ts +565 -0
- package/src/collab/protocol.ts +241 -0
- package/src/collab/relay-client.ts +216 -0
- package/src/commands/bench.ts +42 -0
- package/src/commands/complete.ts +1 -1
- package/src/commands/gallery.ts +52 -0
- package/src/commands/gateway.ts +4 -0
- package/src/commands/install.ts +1 -1
- package/src/commands/join.ts +39 -0
- package/src/commands/launch.ts +8 -4
- package/src/commands/models.ts +61 -0
- package/src/commands/read.ts +6 -3
- package/src/commands/say.ts +102 -0
- package/src/commands/setup.ts +1 -1
- package/src/commands/token.ts +89 -0
- package/src/commands/usage.ts +43 -0
- package/src/commit/agentic/agent.ts +2 -1
- package/src/commit/agentic/tools/analyze-file.ts +42 -20
- package/src/commit/agentic/tools/git-file-diff.ts +1 -1
- package/src/commit/agentic/tools/git-hunk.ts +1 -1
- package/src/commit/agentic/tools/git-overview.ts +1 -1
- package/src/commit/agentic/tools/propose-changelog.ts +1 -1
- package/src/commit/agentic/tools/propose-commit.ts +1 -1
- package/src/commit/agentic/tools/recent-commits.ts +1 -1
- package/src/commit/agentic/tools/schemas.ts +1 -1
- package/src/commit/agentic/tools/split-commit.ts +9 -2
- package/src/commit/analysis/conventional.ts +2 -2
- package/src/commit/analysis/summary.ts +3 -3
- package/src/commit/changelog/generate.ts +3 -3
- package/src/commit/changelog/index.ts +2 -2
- package/src/commit/map-reduce/index.ts +3 -3
- package/src/commit/map-reduce/map-phase.ts +2 -2
- package/src/commit/map-reduce/reduce-phase.ts +2 -2
- package/src/commit/model-selection.ts +35 -12
- package/src/commit/pipeline.ts +4 -4
- package/src/commit/shared-llm.ts +1 -1
- package/src/config/api-key-resolver.ts +67 -0
- package/src/config/append-only-context-mode.ts +6 -12
- package/src/config/keybindings.ts +9 -4
- package/src/config/mcp-schema.json +4 -0
- package/src/config/model-discovery.ts +574 -0
- package/src/config/model-equivalence.ts +5 -4
- package/src/config/model-registry.ts +659 -1093
- package/src/config/model-resolver.ts +374 -174
- package/src/config/model-roles.ts +88 -0
- package/src/config/models-config-schema.ts +61 -9
- package/src/config/models-config.ts +130 -0
- package/src/config/settings-schema.ts +1445 -382
- package/src/config/settings.ts +261 -69
- package/src/dap/client.ts +138 -53
- package/src/dap/config.ts +41 -2
- package/src/dap/defaults.json +1 -0
- package/src/dap/session.ts +263 -161
- package/src/dap/types.ts +10 -0
- package/src/debug/index.ts +50 -60
- package/src/debug/log-viewer.ts +1 -1
- package/src/debug/protocol-probe.ts +1 -1
- package/src/debug/raw-sse-buffer.ts +7 -4
- package/src/debug/raw-sse.ts +1 -1
- package/src/debug/report-bundle.ts +9 -0
- package/src/debug/terminal-info.ts +0 -3
- package/src/discovery/agents-md.ts +25 -21
- package/src/discovery/agents.ts +9 -15
- package/src/discovery/at-imports.ts +273 -0
- package/src/discovery/builtin-rules/index.ts +4 -0
- package/src/discovery/builtin-rules/ts-no-test-timers.md +55 -0
- package/src/discovery/builtin-rules/ts-redundant-clear-guard.md +75 -0
- package/src/discovery/builtin.ts +45 -23
- package/src/discovery/claude-plugins.ts +44 -5
- package/src/discovery/helpers.ts +50 -9
- package/src/discovery/prometheus-extension-roots.ts +10 -10
- package/src/discovery/prometheus-plugins.ts +10 -10
- package/src/edit/diff.ts +191 -4
- package/src/edit/file-snapshot-store.ts +34 -1
- package/src/edit/hashline/block-resolver.ts +20 -1
- package/src/edit/hashline/diff.ts +123 -2
- package/src/edit/hashline/execute.ts +60 -4
- package/src/edit/hashline/filesystem.ts +2 -1
- package/src/edit/hashline/noop-loop-guard.ts +99 -0
- package/src/edit/hashline/params.ts +1 -1
- package/src/edit/index.ts +47 -18
- package/src/edit/modes/apply-patch.ts +1 -1
- package/src/edit/modes/patch.ts +59 -3
- package/src/edit/modes/replace.ts +58 -24
- package/src/edit/notebook.ts +22 -2
- package/src/edit/renderer.ts +315 -151
- package/src/eval/__tests__/agent-bridge.test.ts +105 -39
- package/src/eval/__tests__/budget-bridge.test.ts +1 -1
- package/src/eval/__tests__/completion-bridge.test.ts +412 -0
- package/src/eval/__tests__/helpers-local-roots.test.ts +58 -0
- package/src/eval/__tests__/js-context-manager.test.ts +241 -0
- package/src/eval/__tests__/llm-bridge.test.ts +6 -4
- package/src/eval/__tests__/shared-executors.test.ts +34 -92
- package/src/eval/agent-bridge.ts +39 -23
- package/src/eval/backend.ts +15 -2
- package/src/eval/bridge-timeout.ts +1 -1
- package/src/eval/completion-bridge.ts +203 -0
- package/src/eval/idle-timeout.ts +3 -10
- package/src/eval/js/context-manager.ts +108 -31
- package/src/eval/js/executor.ts +9 -2
- package/src/eval/js/index.ts +7 -3
- package/src/eval/js/shared/helpers.ts +59 -13
- package/src/eval/js/shared/local-module-loader.ts +2 -2
- package/src/eval/js/shared/prelude.txt +167 -30
- package/src/eval/js/shared/rewrite-imports.ts +58 -34
- package/src/eval/js/shared/runtime.ts +24 -16
- package/src/eval/js/tool-bridge.ts +4 -0
- package/src/eval/js/worker-core.ts +1 -0
- package/src/eval/js/worker-entry.ts +6 -0
- package/src/eval/js/worker-protocol.ts +6 -0
- package/src/eval/llm-bridge.ts +2 -1
- package/src/eval/py/__tests__/prelude.test.ts +19 -0
- package/src/eval/py/executor.ts +70 -26
- package/src/eval/py/index.ts +13 -4
- package/src/eval/py/kernel.ts +48 -9
- package/src/eval/py/prelude.py +73 -24
- package/src/eval/py/runner.py +133 -28
- package/src/eval/py/runtime.ts +38 -1
- package/src/exa/index.ts +1 -26
- package/src/exa/mcp-client.ts +10 -10
- package/src/exa/types.ts +0 -97
- package/src/exec/bash-executor.ts +104 -7
- package/src/export/custom-share.ts +1 -1
- package/src/export/html/index.ts +119 -17
- package/src/export/html/share-loader.js +102 -0
- package/src/export/html/template-js.ts +6 -0
- package/src/export/html/template.css +745 -459
- package/src/export/html/template.css.d.ts +2 -0
- package/src/export/html/template.html +6 -3
- package/src/export/html/template.js +277 -891
- package/src/export/html/tool-views.generated.d.ts +2 -0
- package/src/export/html/tool-views.generated.js +38 -0
- package/src/export/share.ts +269 -0
- package/src/export/ttsr.ts +122 -1
- package/src/extensibility/custom-commands/loader.ts +7 -4
- package/src/extensibility/custom-commands/types.ts +9 -4
- package/src/extensibility/custom-tools/loader.ts +51 -23
- package/src/extensibility/custom-tools/types.ts +16 -8
- package/src/extensibility/extensions/get-commands-handler.ts +2 -1
- package/src/extensibility/extensions/index.ts +1 -0
- package/src/extensibility/extensions/loader.ts +70 -20
- package/src/extensibility/extensions/model-api.ts +41 -0
- package/src/extensibility/extensions/runner.ts +12 -2
- package/src/extensibility/extensions/types.ts +83 -11
- package/src/extensibility/extensions/wrapper.ts +41 -5
- package/src/extensibility/hooks/index.ts +2 -1
- package/src/extensibility/hooks/loader.ts +6 -3
- package/src/extensibility/hooks/types.ts +11 -5
- package/src/extensibility/{legacy-pi-ai-shim.ts → legacy-package-ai-shim.ts} +2 -2
- package/src/extensibility/plugins/doctor.ts +1 -2
- package/src/extensibility/plugins/installer.ts +2 -2
- package/src/extensibility/plugins/{legacy-pi-compat.ts → legacy-package-compat.ts} +165 -77
- package/src/extensibility/plugins/loader.ts +34 -23
- package/src/extensibility/plugins/manager.ts +226 -95
- package/src/extensibility/plugins/marketplace-auto-update.ts +49 -0
- package/src/extensibility/plugins/types.ts +3 -3
- package/src/extensibility/shared-events.ts +3 -3
- package/src/extensibility/skills.ts +113 -9
- package/src/extensibility/slash-commands.ts +1 -97
- package/src/gateway/adapters/telegram/access.ts +39 -4
- package/src/gateway/adapters/telegram/normalize.ts +16 -1
- package/src/gateway/adapters/telegram/setup-api.ts +7 -1
- package/src/gateway/adapters/telegram/webhook.ts +26 -5
- package/src/gateway/context.ts +9 -1
- package/src/gateway/types.ts +1 -1
- package/src/goals/guided-setup.ts +133 -0
- package/src/goals/state.ts +1 -1
- package/src/goals/tools/goal-tool.ts +38 -28
- package/src/hindsight/bank.ts +17 -2
- package/src/hindsight/client.ts +27 -2
- package/src/hindsight/mental-models.ts +59 -12
- package/src/hindsight/state.ts +12 -3
- package/src/hindsight/transcript.ts +1 -1
- package/src/index.ts +5 -0
- package/src/internal-urls/artifact-protocol.ts +11 -2
- package/src/internal-urls/docs-index.generated.ts +11 -9
- package/src/internal-urls/history-protocol.ts +113 -0
- package/src/internal-urls/index.ts +1 -0
- package/src/internal-urls/issue-pr-protocol.ts +22 -9
- package/src/internal-urls/local-protocol.ts +42 -7
- package/src/internal-urls/memory-protocol.ts +4 -31
- package/src/internal-urls/router.ts +3 -1
- package/src/internal-urls/types.ts +1 -1
- package/src/irc/bus.ts +303 -0
- package/src/lib/xai-http.ts +3 -3
- package/src/lsp/client.ts +245 -104
- package/src/lsp/clients/biome-client.ts +101 -39
- package/src/lsp/clients/lsp-linter-client.ts +2 -10
- package/src/lsp/config.ts +15 -5
- package/src/lsp/defaults.json +6 -0
- package/src/lsp/edits.ts +143 -95
- package/src/lsp/format-options.ts +119 -0
- package/src/lsp/index.ts +233 -93
- package/src/lsp/render.ts +11 -35
- package/src/lsp/types.ts +13 -1
- package/src/lsp/utils.ts +31 -12
- package/src/main.ts +396 -216
- package/src/mcp/config-writer.ts +7 -3
- package/src/mcp/json-rpc.ts +35 -5
- package/src/mcp/manager.ts +31 -16
- package/src/mcp/oauth-discovery.ts +34 -4
- package/src/mcp/oauth-flow.ts +61 -8
- package/src/mcp/render.ts +7 -1
- package/src/mcp/startup-events.ts +21 -0
- package/src/mcp/tool-bridge.ts +2 -0
- package/src/mcp/transports/stdio.ts +224 -4
- package/src/mcp/types.ts +2 -0
- package/src/memories/index.ts +174 -1128
- package/src/memories/storage.ts +2 -41
- package/src/memory-backend/index.ts +14 -1
- package/src/memory-backend/local-backend.ts +18 -3
- package/src/memory-backend/off-backend.ts +9 -0
- package/src/memory-backend/resolve.ts +4 -6
- package/src/memory-backend/runtime.ts +66 -0
- package/src/memory-backend/types.ts +82 -2
- package/src/mnemopi/backend.ts +220 -28
- package/src/mnemopi/config.ts +138 -33
- package/src/mnemopi/state.ts +91 -11
- package/src/modes/acp/acp-agent.ts +149 -142
- package/src/modes/acp/acp-event-mapper.ts +5 -1
- package/src/modes/components/agent-dashboard.ts +17 -11
- package/src/modes/components/agent-hub.ts +1346 -0
- package/src/modes/components/assistant-message.ts +190 -80
- package/src/modes/components/bash-execution.ts +1 -1
- package/src/modes/components/btw-panel.ts +5 -1
- package/src/modes/components/chat-block.ts +111 -0
- package/src/modes/components/collab-prompt-message.ts +30 -0
- package/src/modes/components/compaction-summary-message.ts +168 -33
- package/src/modes/components/copy-selector.ts +2 -45
- package/src/modes/components/custom-editor.test.ts +96 -0
- package/src/modes/components/custom-editor.ts +405 -118
- package/src/modes/components/custom-message.ts +1 -3
- package/src/modes/components/diff.ts +13 -2
- package/src/modes/components/dynamic-border.ts +12 -3
- package/src/modes/components/execution-shared.ts +1 -2
- package/src/modes/components/extensions/extension-dashboard.ts +8 -5
- package/src/modes/components/extensions/extension-list.ts +1 -1
- package/src/modes/components/extensions/inspector-panel.ts +7 -3
- package/src/modes/components/extensions/state-manager.ts +36 -41
- package/src/modes/components/footer.ts +4 -2
- package/src/modes/components/history-search.ts +1 -1
- package/src/modes/components/hook-editor.ts +8 -0
- package/src/modes/components/hook-input.ts +8 -0
- package/src/modes/components/hook-message.ts +1 -3
- package/src/modes/components/hook-selector.ts +6 -7
- package/src/modes/components/index.ts +1 -0
- package/src/modes/components/late-diagnostics-message.ts +60 -0
- package/src/modes/components/login-dialog.ts +1 -1
- package/src/modes/components/logout-account-selector.ts +130 -0
- package/src/modes/components/mcp-add-wizard.ts +14 -1
- package/src/modes/components/model-selector.ts +177 -75
- package/src/modes/components/oauth-selector.ts +102 -16
- package/src/modes/components/overlay-box.ts +108 -0
- package/src/modes/components/plan-review-overlay.ts +845 -0
- package/src/modes/components/plan-toc.ts +138 -0
- package/src/modes/components/plugin-settings.ts +22 -5
- package/src/modes/components/read-tool-group.ts +442 -39
- package/src/modes/components/reset-usage-selector.ts +161 -0
- package/src/modes/components/segment-track.ts +44 -7
- package/src/modes/components/session-selector.ts +97 -37
- package/src/modes/components/settings-defs.ts +28 -6
- package/src/modes/components/settings-selector.ts +541 -93
- package/src/modes/components/skill-message.ts +0 -1
- package/src/modes/components/snapcompact-shape-preview-doc.md +11 -0
- package/src/modes/components/snapcompact-shape-preview.ts +193 -0
- package/src/modes/components/{status-line.ts → status-line/component.ts} +205 -168
- package/src/modes/components/status-line/index.ts +1 -0
- package/src/modes/components/status-line/presets.ts +3 -3
- package/src/modes/components/status-line/segments.ts +26 -7
- package/src/modes/components/status-line/types.ts +40 -9
- package/src/modes/components/tiny-title-download-progress.ts +1 -1
- package/src/modes/components/tips.txt +7 -3
- package/src/modes/components/todo-reminder.ts +0 -2
- package/src/modes/components/tool-execution.ts +236 -103
- package/src/modes/components/transcript-container.ts +724 -99
- package/src/modes/components/tree-selector.ts +19 -4
- package/src/modes/components/ttsr-notification.ts +72 -30
- package/src/modes/components/usage-row.ts +18 -0
- package/src/modes/components/user-message-selector.ts +1 -1
- package/src/modes/components/user-message.ts +28 -12
- package/src/modes/components/visual-truncate.ts +1 -1
- package/src/modes/components/welcome.ts +80 -22
- package/src/modes/controllers/command-controller-shared.ts +7 -6
- package/src/modes/controllers/command-controller.ts +210 -180
- package/src/modes/controllers/event-controller.ts +352 -142
- package/src/modes/controllers/extension-ui-controller.ts +167 -208
- package/src/modes/controllers/input-controller.ts +778 -162
- package/src/modes/controllers/mcp-command-controller.ts +232 -80
- package/src/modes/controllers/selector-controller.ts +284 -145
- package/src/modes/controllers/session-focus-controller.ts +112 -0
- package/src/modes/controllers/ssh-command-controller.ts +2 -2
- package/src/modes/controllers/streaming-reveal.ts +295 -0
- package/src/modes/controllers/tan-command-controller.ts +173 -0
- package/src/modes/controllers/tool-args-reveal.ts +174 -0
- package/src/modes/gradient-highlight.ts +21 -9
- package/src/modes/image-references.ts +33 -7
- package/src/modes/index.ts +8 -25
- package/src/modes/interactive-mode.ts +840 -186
- package/src/modes/magic-keywords.ts +28 -6
- package/src/modes/markdown-prose.ts +1 -1
- package/src/modes/oauth-manual-input.ts +30 -3
- package/src/modes/rpc/rpc-client.ts +186 -3
- package/src/modes/rpc/rpc-mode.ts +318 -24
- package/src/modes/rpc/rpc-subagents.ts +265 -0
- package/src/modes/rpc/rpc-types.ts +111 -2
- package/src/modes/runtime-init.ts +28 -3
- package/src/modes/session-observer-registry.ts +72 -3
- package/src/modes/setup-version.ts +11 -0
- package/src/modes/setup-wizard/index.ts +16 -4
- package/src/modes/setup-wizard/lazy.ts +16 -0
- package/src/modes/setup-wizard/scenes/glyph.ts +25 -7
- package/src/modes/setup-wizard/scenes/providers.ts +45 -12
- package/src/modes/setup-wizard/scenes/sign-in.ts +14 -13
- package/src/modes/setup-wizard/scenes/splash.ts +1 -1
- package/src/modes/setup-wizard/scenes/telegram.ts +77 -22
- package/src/modes/setup-wizard/scenes/theme.ts +29 -2
- package/src/modes/setup-wizard/scenes/types.ts +11 -2
- package/src/modes/setup-wizard/scenes/web-search.ts +26 -9
- package/src/modes/setup-wizard/wizard-overlay.ts +40 -3
- package/src/modes/shared.ts +2 -0
- package/src/modes/theme/defaults/dark-poimandres.json +1 -1
- package/src/modes/theme/defaults/light-poimandres.json +1 -1
- package/src/modes/theme/shimmer.ts +20 -9
- package/src/modes/theme/theme-schema.json +1 -1
- package/src/modes/theme/theme.ts +342 -82
- package/src/modes/types.ts +60 -18
- package/src/modes/utils/context-usage.ts +88 -8
- package/src/modes/utils/copy-targets.ts +133 -27
- package/src/modes/utils/hotkeys-markdown.ts +3 -2
- package/src/modes/utils/ui-helpers.ts +191 -110
- package/src/modes/workflow.ts +10 -10
- package/src/plan-mode/approved-plan.ts +66 -43
- package/src/plan-mode/plan-protection.ts +4 -4
- package/src/priority.json +5 -1
- package/src/prompts/agents/designer.md +1 -1
- package/src/prompts/agents/explore.md +3 -3
- package/src/prompts/agents/librarian.md +2 -3
- package/src/prompts/agents/oracle.md +2 -2
- package/src/prompts/agents/plan.md +6 -6
- package/src/prompts/agents/reviewer.md +1 -1
- package/src/prompts/agents/task.md +6 -5
- package/src/prompts/bench.md +12 -0
- package/src/prompts/ci-green-request.md +5 -7
- package/src/prompts/goals/goal-budget-limit.md +2 -2
- package/src/prompts/goals/goal-continuation.md +4 -4
- package/src/prompts/goals/goal-mode-active.md +1 -1
- package/src/prompts/goals/guided-goal-interview.md +8 -0
- package/src/prompts/goals/guided-goal-system.md +12 -0
- package/src/prompts/memories/consolidation.md +2 -7
- package/src/prompts/memories/consolidation_system.md +4 -0
- package/src/prompts/memories/identity_review.md +2 -2
- package/src/prompts/memories/read-path.md +11 -10
- package/src/prompts/memories/stage_one_system.md +2 -2
- package/src/prompts/review-custom-request.md +1 -1
- package/src/prompts/system/agent-creation-architect.md +2 -2
- package/src/prompts/system/auto-continue.md +1 -1
- package/src/prompts/system/autolearn-guidance-learn.md +1 -0
- package/src/prompts/system/autolearn-guidance.md +7 -0
- package/src/prompts/system/autolearn-nudge.md +3 -0
- package/src/prompts/system/background-tan-dispatch.md +8 -0
- package/src/prompts/system/btw-user.md +2 -2
- package/src/prompts/system/commit-message-system.md +13 -1
- package/src/prompts/system/custom-system-prompt.md +1 -1
- package/src/prompts/system/eager-task.md +7 -0
- package/src/prompts/system/eager-todo.md +11 -6
- package/src/prompts/system/empty-stop-retry.md +4 -6
- package/src/prompts/system/irc-autoreply.md +6 -0
- package/src/prompts/system/irc-incoming.md +3 -4
- package/src/prompts/system/manual-continue.md +7 -0
- package/src/prompts/system/omfg-user.md +3 -4
- package/src/prompts/system/orchestrate-notice.md +10 -10
- package/src/prompts/system/personalities/default.md +26 -0
- package/src/prompts/system/personalities/friendly.md +17 -0
- package/src/prompts/system/personalities/pragmatic.md +15 -0
- package/src/prompts/system/plan-mode-active.md +70 -77
- package/src/prompts/system/plan-mode-approved.md +1 -1
- package/src/prompts/system/plan-mode-subagent.md +4 -5
- package/src/prompts/system/plan-mode-tool-decision-reminder.md +1 -1
- package/src/prompts/system/project-prompt.md +2 -2
- package/src/prompts/system/snapcompact-context-frames-note.md +1 -0
- package/src/prompts/system/snapcompact-context-stub.md +1 -0
- package/src/prompts/system/snapcompact-system-frames-note.md +1 -0
- package/src/prompts/system/snapcompact-system-stub.md +1 -0
- package/src/prompts/system/snapcompact-toolresult-note.md +1 -0
- package/src/prompts/system/subagent-system-prompt.md +7 -8
- package/src/prompts/system/system-prompt.md +28 -57
- package/src/prompts/system/tiny-title-system.md +1 -1
- package/src/prompts/system/title-marker-instruction.md +1 -0
- package/src/prompts/system/title-system-marker.md +16 -0
- package/src/prompts/system/title-system.md +16 -3
- package/src/prompts/system/ttsr-tool-reminder.md +1 -1
- package/src/prompts/system/workflow-notice.md +4 -4
- package/src/prompts/tools/ast-edit.md +1 -1
- package/src/prompts/tools/ast-grep.md +2 -2
- package/src/prompts/tools/bash.md +16 -8
- package/src/prompts/tools/browser.md +33 -43
- package/src/prompts/tools/debug.md +1 -1
- package/src/prompts/tools/eval.md +31 -51
- package/src/prompts/tools/find.md +0 -1
- package/src/prompts/tools/github.md +8 -7
- package/src/prompts/tools/goal.md +1 -1
- package/src/prompts/tools/image-gen.md +1 -1
- package/src/prompts/tools/inspect-image-system.md +1 -1
- package/src/prompts/tools/irc.md +39 -31
- package/src/prompts/tools/job.md +2 -1
- package/src/prompts/tools/learn.md +7 -0
- package/src/prompts/tools/lsp-late-diagnostic.md +8 -0
- package/src/prompts/tools/lsp.md +2 -2
- package/src/prompts/tools/manage-skill.md +9 -0
- package/src/prompts/tools/memory-edit.md +1 -1
- package/src/prompts/tools/patch.md +2 -2
- package/src/prompts/tools/read.md +31 -39
- package/src/prompts/tools/recall.md +1 -1
- package/src/prompts/tools/reflect.md +1 -1
- package/src/prompts/tools/render-mermaid.md +2 -2
- package/src/prompts/tools/replace.md +4 -10
- package/src/prompts/tools/rewind.md +2 -2
- package/src/prompts/tools/search-tool-bm25.md +1 -9
- package/src/prompts/tools/search.md +0 -1
- package/src/prompts/tools/ssh.md +0 -4
- package/src/prompts/tools/task-summary.md +5 -16
- package/src/prompts/tools/task.md +47 -31
- package/src/prompts/tools/todo.md +6 -3
- package/src/registry/agent-lifecycle.ts +218 -0
- package/src/registry/agent-registry.ts +46 -5
- package/src/sdk.ts +692 -219
- package/src/secrets/index.ts +8 -1
- package/src/secrets/obfuscator.ts +40 -19
- package/src/session/agent-session.ts +1577 -806
- package/src/session/agent-storage.ts +18 -9
- package/src/session/auth-broker-config.ts +30 -1
- package/src/session/auth-storage.ts +6 -0
- package/src/session/codex-auto-reset.ts +202 -0
- package/src/session/history-storage.ts +3 -2
- package/src/session/indexed-session-storage.ts +7 -10
- package/src/session/messages.ts +59 -95
- package/src/session/session-context.ts +352 -0
- package/src/session/session-dump-format.ts +12 -3
- package/src/session/session-entries.ts +194 -0
- package/src/session/session-history-format.ts +246 -0
- package/src/session/session-listing.ts +588 -0
- package/src/session/session-loader.ts +106 -0
- package/src/session/session-manager.ts +1003 -2920
- package/src/session/session-migrations.ts +78 -0
- package/src/session/session-paths.ts +193 -0
- package/src/session/session-persistence.ts +131 -0
- package/src/session/session-storage.ts +91 -30
- package/src/session/snapcompact-inline.ts +542 -0
- package/src/session/snapcompact-savings-journal.ts +113 -0
- package/src/session/streaming-output.ts +248 -11
- package/src/session/tool-choice-queue.ts +23 -11
- package/src/session/yield-queue.ts +20 -2
- package/src/slash-commands/acp-builtins.ts +25 -1
- package/src/slash-commands/available-commands.ts +105 -0
- package/src/slash-commands/builtin-registry.ts +575 -49
- package/src/slash-commands/helpers/active-oauth-account.ts +44 -0
- package/src/slash-commands/helpers/context-report.ts +28 -1
- package/src/slash-commands/helpers/logout.ts +88 -0
- package/src/slash-commands/helpers/reset-usage.ts +66 -0
- package/src/slash-commands/helpers/stats-dashboard.ts +85 -0
- package/src/slash-commands/helpers/usage-report.ts +38 -3
- package/src/slash-commands/types.ts +5 -9
- package/src/ssh/connection-manager.ts +27 -0
- package/src/ssh/ssh-executor.ts +60 -4
- package/src/stt/asr-client.ts +520 -0
- package/src/stt/asr-protocol.ts +65 -0
- package/src/stt/asr-worker.ts +790 -0
- package/src/stt/downloader.ts +107 -47
- package/src/stt/endpointer.ts +259 -0
- package/src/stt/index.ts +5 -1
- package/src/stt/models.ts +150 -0
- package/src/stt/recorder.ts +254 -67
- package/src/stt/stt-controller.ts +201 -22
- package/src/stt/transcriber.ts +37 -68
- package/src/stt/wav.ts +173 -0
- package/src/system-prompt.ts +52 -10
- package/src/task/agents.ts +3 -4
- package/src/task/commands.ts +3 -2
- package/src/task/discovery.ts +17 -24
- package/src/task/executor.ts +1054 -529
- package/src/task/index.ts +862 -757
- package/src/task/output-manager.ts +0 -11
- package/src/task/parallel.ts +3 -3
- package/src/task/prometheus-command.ts +2 -2
- package/src/task/render.ts +529 -182
- package/src/task/repair-args.ts +21 -9
- package/src/task/types.ts +144 -66
- package/src/task/worktree.ts +64 -56
- package/src/telemetry-export.ts +27 -9
- package/src/thinking.ts +9 -7
- package/src/tiny/models.ts +2 -2
- package/src/tiny/text.ts +5 -1
- package/src/tiny/title-client.ts +72 -20
- package/src/tiny/title-protocol.ts +1 -1
- package/src/tiny/worker.ts +23 -99
- package/src/tool-discovery/tool-index.ts +2 -0
- package/src/tools/archive-reader.ts +94 -2
- package/src/tools/ask.ts +234 -177
- package/src/tools/ast-edit.ts +136 -80
- package/src/tools/ast-grep.ts +41 -45
- package/src/tools/auto-generated-guard.ts +20 -3
- package/src/tools/bash-interactive.ts +28 -8
- package/src/tools/bash.ts +198 -35
- package/src/tools/browser/attach.ts +26 -7
- package/src/tools/browser/cmux/cmux-tab.ts +1264 -0
- package/src/tools/browser/cmux/rpc.ts +156 -0
- package/src/tools/browser/cmux/socket-client.ts +309 -0
- package/src/tools/browser/launch.ts +11 -2
- package/src/tools/browser/readable.ts +19 -2
- package/src/tools/browser/registry.ts +52 -5
- package/src/tools/browser/render.ts +13 -5
- package/src/tools/browser/tab-protocol.ts +2 -0
- package/src/tools/browser/tab-supervisor.ts +256 -34
- package/src/tools/browser/tab-worker.ts +259 -91
- package/src/tools/browser.ts +44 -2
- package/src/tools/checkpoint.ts +1 -1
- package/src/tools/conflict-detect.ts +50 -4
- package/src/tools/debug.ts +27 -12
- package/src/tools/eval-render.ts +32 -35
- package/src/tools/eval.ts +26 -12
- package/src/tools/fetch.ts +450 -99
- package/src/tools/find.ts +182 -142
- package/src/tools/gh-cache-invalidation.ts +255 -0
- package/src/tools/gh-renderer.ts +104 -51
- package/src/tools/gh.ts +232 -37
- package/src/tools/github-cache.ts +97 -7
- package/src/tools/grouped-file-output.ts +159 -52
- package/src/tools/image-gen.ts +237 -132
- package/src/tools/index.ts +147 -26
- package/src/tools/inspect-image-renderer.ts +74 -45
- package/src/tools/inspect-image.ts +12 -6
- package/src/tools/irc.ts +626 -173
- package/src/tools/job.ts +106 -29
- package/src/tools/learn.ts +144 -0
- package/src/tools/manage-skill.ts +104 -0
- package/src/tools/memory-edit.ts +4 -4
- package/src/tools/memory-recall.ts +7 -9
- package/src/tools/memory-reflect.ts +5 -9
- package/src/tools/memory-render.ts +23 -6
- package/src/tools/memory-retain.ts +4 -4
- package/src/tools/path-utils.ts +102 -48
- package/src/tools/plan-mode-guard.ts +101 -40
- package/src/tools/read.ts +475 -120
- package/src/tools/render-mermaid.ts +1 -1
- package/src/tools/render-utils.ts +132 -76
- package/src/tools/renderers.ts +12 -1
- package/src/tools/report-tool-issue.ts +14 -6
- package/src/tools/resolve.ts +20 -3
- package/src/tools/review.ts +2 -2
- package/src/tools/search-tool-bm25.ts +37 -24
- package/src/tools/search.ts +233 -115
- package/src/tools/sqlite-reader.ts +26 -17
- package/src/tools/ssh.ts +20 -14
- package/src/tools/todo.ts +197 -191
- package/src/tools/tool-result.ts +8 -0
- package/src/tools/tool-timeouts.ts +1 -1
- package/src/tools/tts.ts +205 -74
- package/src/tools/write.ts +291 -155
- package/src/tools/yield.ts +10 -1
- package/src/tts/downloader.ts +64 -0
- package/src/tts/index.ts +8 -0
- package/src/tts/models.ts +137 -0
- package/src/tts/player.ts +137 -0
- package/src/tts/runtime.ts +21 -0
- package/src/tts/streaming-player.ts +266 -0
- package/src/tts/tts-client.ts +647 -0
- package/src/tts/tts-protocol.ts +60 -0
- package/src/tts/tts-worker.ts +505 -0
- package/src/tts/vocalizer.ts +162 -0
- package/src/tts/wav.ts +58 -0
- package/src/tui/code-cell.ts +2 -7
- package/src/tui/hyperlink.ts +40 -26
- package/src/tui/output-block.ts +60 -108
- package/src/tui/status-line.ts +5 -1
- package/src/utils/block-context.ts +312 -0
- package/src/utils/changelog.ts +27 -1
- package/src/utils/clipboard.ts +91 -22
- package/src/utils/commit-message-generator.ts +8 -3
- package/src/utils/enhanced-paste.ts +230 -0
- package/src/utils/file-mentions.ts +3 -1
- package/src/utils/git.ts +315 -15
- package/src/utils/image-loading.ts +65 -4
- package/src/utils/session-color.ts +83 -9
- package/src/utils/thinking-display.ts +37 -0
- package/src/utils/title-generator.ts +73 -10
- package/src/utils/tool-choice.ts +16 -0
- package/src/utils/tools-manager.ts +19 -1
- package/src/web/kagi.ts +28 -26
- package/src/web/parallel.ts +7 -3
- package/src/web/scrapers/arxiv.ts +1 -1
- package/src/web/scrapers/github.ts +351 -3
- package/src/web/scrapers/go-pkg.ts +1 -1
- package/src/web/scrapers/iacr.ts +1 -1
- package/src/web/scrapers/readthedocs.ts +1 -1
- package/src/web/scrapers/twitter.ts +2 -1
- package/src/web/scrapers/types.ts +87 -8
- package/src/web/scrapers/wikipedia.ts +1 -1
- package/src/web/scrapers/youtube.ts +9 -3
- package/src/web/search/index.ts +15 -2
- package/src/web/search/providers/anthropic.ts +62 -21
- package/src/web/search/providers/base.ts +2 -1
- package/src/web/search/providers/brave.ts +5 -2
- package/src/web/search/providers/codex.ts +87 -51
- package/src/web/search/providers/exa.ts +101 -10
- package/src/web/search/providers/gemini.ts +49 -24
- package/src/web/search/providers/jina.ts +15 -5
- package/src/web/search/providers/kagi.ts +9 -2
- package/src/web/search/providers/kimi.ts +45 -20
- package/src/web/search/providers/parallel.ts +39 -24
- package/src/web/search/providers/perplexity.ts +226 -63
- package/src/web/search/providers/searxng.ts +19 -3
- package/src/web/search/providers/synthetic.ts +16 -11
- package/src/web/search/providers/tavily.ts +12 -9
- package/src/web/search/providers/zai.ts +22 -9
- package/src/web/search/render.ts +59 -64
- package/src/web/search/types.ts +5 -1
- package/dist/types/discovery/context-files.d.ts +0 -17
- package/dist/types/exa/factory.d.ts +0 -13
- package/dist/types/exa/render.d.ts +0 -19
- package/dist/types/exa/researcher.d.ts +0 -9
- package/dist/types/exa/search.d.ts +0 -9
- package/dist/types/exa/websets.d.ts +0 -9
- package/dist/types/export/html/template.generated.d.ts +0 -1
- package/dist/types/modes/components/session-observer-overlay.d.ts +0 -11
- package/dist/types/modes/components/status-line.d.ts +0 -77
- package/dist/types/slash-commands/headless-plan.d.ts +0 -3
- package/dist/types/stt/setup.d.ts +0 -18
- package/scripts/generate-template.ts +0 -33
- package/src/discovery/context-files.ts +0 -49
- package/src/exa/factory.ts +0 -60
- package/src/exa/render.ts +0 -244
- package/src/exa/researcher.ts +0 -36
- package/src/exa/search.ts +0 -47
- package/src/exa/websets.ts +0 -248
- package/src/export/html/template.generated.ts +0 -2
- package/src/modes/components/session-observer-overlay.ts +0 -852
- package/src/slash-commands/headless-plan.ts +0 -142
- package/src/stt/setup.ts +0 -52
- package/src/stt/transcribe.py +0 -70
- /package/dist/types/extensibility/{legacy-pi-coding-agent-shim.d.ts → legacy-package-agent-shim.d.ts} +0 -0
- /package/src/extensibility/{legacy-pi-coding-agent-shim.ts → legacy-package-agent-shim.ts} +0 -0
package/src/sdk.ts
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
type ThinkingLevel,
|
|
10
10
|
} from "@prometheus-ai/agent-core";
|
|
11
11
|
import {
|
|
12
|
+
type Context,
|
|
12
13
|
type CredentialDisabledEvent,
|
|
13
|
-
isUsageLimitError,
|
|
14
14
|
type Message,
|
|
15
15
|
type Model,
|
|
16
16
|
type SimpleStreamOptions,
|
|
@@ -20,11 +20,11 @@ import {
|
|
|
20
20
|
getOpenAICodexTransportDetails,
|
|
21
21
|
prewarmOpenAICodexResponses,
|
|
22
22
|
} from "@prometheus-ai/ai/providers/openai-codex-responses";
|
|
23
|
+
import { DEFAULT_MODEL_PER_PROVIDER } from "@prometheus-ai/catalog/provider-models";
|
|
23
24
|
import type { Component } from "@prometheus-ai/tui";
|
|
24
25
|
import {
|
|
25
26
|
$env,
|
|
26
27
|
$flag,
|
|
27
|
-
extractRetryHint,
|
|
28
28
|
getAgentDbPath,
|
|
29
29
|
getAgentDir,
|
|
30
30
|
getAuthBrokerSnapshotCachePath,
|
|
@@ -34,16 +34,17 @@ import {
|
|
|
34
34
|
prompt,
|
|
35
35
|
Snowflake,
|
|
36
36
|
} from "@prometheus-ai/utils";
|
|
37
|
-
import
|
|
38
|
-
import {
|
|
39
|
-
import { createAutoresearchExtension } from "./autoresearch";
|
|
37
|
+
import { type AsyncJob, AsyncJobManager } from "./async";
|
|
38
|
+
import { AutoLearnController, buildAutoLearnInstructions } from "./autolearn/controller";
|
|
40
39
|
import { loadCapability } from "./capability";
|
|
41
40
|
import { type Rule, ruleCapability, setActiveRules } from "./capability/rule";
|
|
42
41
|
import { bucketRules } from "./capability/rule-buckets";
|
|
42
|
+
import { createApiKeyResolver } from "./config/api-key-resolver";
|
|
43
43
|
import { shouldEnableAppendOnlyContext } from "./config/append-only-context-mode";
|
|
44
44
|
import { ModelRegistry } from "./config/model-registry";
|
|
45
45
|
import {
|
|
46
46
|
formatModelString,
|
|
47
|
+
getModelMatchPreferences,
|
|
47
48
|
parseModelPattern,
|
|
48
49
|
parseModelString,
|
|
49
50
|
resolveAllowedModels,
|
|
@@ -57,16 +58,16 @@ import { resolveConfigValue } from "./config/resolve-config-value";
|
|
|
57
58
|
import { initializeWithSettings } from "./discovery";
|
|
58
59
|
import { disposeAllKernelSessions, disposeKernelSessionsByOwner } from "./eval/py/executor";
|
|
59
60
|
import { defaultEvalSessionId } from "./eval/session-id";
|
|
60
|
-
import { TtsrManager } from "./export/ttsr";
|
|
61
61
|
import {
|
|
62
62
|
type CustomCommandsLoadResult,
|
|
63
63
|
type LoadedCustomCommand,
|
|
64
64
|
loadCustomCommands as loadCustomCommandsInternal,
|
|
65
65
|
} from "./extensibility/custom-commands";
|
|
66
|
-
import {
|
|
66
|
+
import { discoverCustomToolPaths, loadCustomTools, type ToolPathWithSource } from "./extensibility/custom-tools";
|
|
67
67
|
import type { CustomTool, CustomToolContext, CustomToolSessionEvent } from "./extensibility/custom-tools/types";
|
|
68
68
|
import {
|
|
69
69
|
discoverAndLoadExtensions,
|
|
70
|
+
discoverExtensionPaths,
|
|
70
71
|
type ExtensionContext,
|
|
71
72
|
type ExtensionFactory,
|
|
72
73
|
ExtensionRunner,
|
|
@@ -88,16 +89,27 @@ import { type FileSlashCommand, loadSlashCommands as loadSlashCommandsInternal }
|
|
|
88
89
|
import type { HindsightSessionState } from "./hindsight/state";
|
|
89
90
|
import { LocalProtocolHandler, type LocalProtocolOptions } from "./internal-urls";
|
|
90
91
|
import { LSP_STARTUP_EVENT_CHANNEL, type LspStartupEvent } from "./lsp/startup-events";
|
|
91
|
-
import {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
import {
|
|
93
|
+
discoverAndLoadMCPTools,
|
|
94
|
+
type MCPLoadResult,
|
|
95
|
+
MCPManager,
|
|
96
|
+
MCPToolCache,
|
|
97
|
+
type MCPToolsLoadResult,
|
|
98
|
+
parseMCPToolName,
|
|
99
|
+
} from "./mcp";
|
|
100
|
+
import { MCP_CONNECTING_EVENT_CHANNEL, type McpConnectingEvent } from "./mcp/startup-events";
|
|
101
|
+
import { createSessionMemoryRuntimeContext, resolveMemoryBackend } from "./memory-backend";
|
|
102
|
+
import type { MnemopiSessionState } from "./mnemopi/state";
|
|
94
103
|
import asyncResultTemplate from "./prompts/tools/async-result.md" with { type: "text" };
|
|
104
|
+
import lateDiagnosticTemplate from "./prompts/tools/lsp-late-diagnostic.md" with { type: "text" };
|
|
105
|
+
import { AgentLifecycleManager } from "./registry/agent-lifecycle";
|
|
95
106
|
import { AgentRegistry, MAIN_AGENT_ID } from "./registry/agent-registry";
|
|
96
107
|
import {
|
|
97
108
|
collectEnvSecrets,
|
|
98
109
|
deobfuscateSessionContext,
|
|
99
110
|
loadSecrets,
|
|
100
111
|
obfuscateMessages,
|
|
112
|
+
obfuscateProviderContext,
|
|
101
113
|
SecretObfuscator,
|
|
102
114
|
} from "./secrets";
|
|
103
115
|
import { AgentSession } from "./session/agent-session";
|
|
@@ -111,8 +123,16 @@ import {
|
|
|
111
123
|
type SnapshotResponse,
|
|
112
124
|
writeAuthBrokerSnapshotCache,
|
|
113
125
|
} from "./session/auth-storage";
|
|
114
|
-
import {
|
|
115
|
-
|
|
126
|
+
import {
|
|
127
|
+
type CustomMessage,
|
|
128
|
+
convertToLlm,
|
|
129
|
+
LSP_LATE_DIAGNOSTIC_MESSAGE_TYPE,
|
|
130
|
+
wrapSteeringForModel,
|
|
131
|
+
} from "./session/messages";
|
|
132
|
+
import { getRestorableSessionModels } from "./session/session-context";
|
|
133
|
+
import { SessionManager } from "./session/session-manager";
|
|
134
|
+
import { SnapcompactInlineTransformer } from "./session/snapcompact-inline";
|
|
135
|
+
import { createSnapcompactSavingsRecorder } from "./session/snapcompact-savings-journal";
|
|
116
136
|
import { closeAllConnections } from "./ssh/connection-manager";
|
|
117
137
|
import { unmountAll } from "./ssh/sshfs-mount";
|
|
118
138
|
import {
|
|
@@ -128,6 +148,7 @@ import {
|
|
|
128
148
|
parseThinkingLevel,
|
|
129
149
|
resolveProvisionalAutoLevel,
|
|
130
150
|
resolveThinkingLevelForModel,
|
|
151
|
+
shouldDisableReasoning,
|
|
131
152
|
toReasoningEffort,
|
|
132
153
|
} from "./thinking";
|
|
133
154
|
import { countToolsForAutoDiscovery, resolveEffectiveToolDiscoveryMode } from "./tool-discovery/mode";
|
|
@@ -136,6 +157,7 @@ import {
|
|
|
136
157
|
type DiscoverableTool,
|
|
137
158
|
filterBySource,
|
|
138
159
|
formatDiscoverableToolServerSummary,
|
|
160
|
+
isMCPToolName,
|
|
139
161
|
selectDiscoverableToolNamesByServer,
|
|
140
162
|
summarizeDiscoverableTools,
|
|
141
163
|
} from "./tool-discovery/tool-index";
|
|
@@ -144,10 +166,12 @@ import {
|
|
|
144
166
|
BUILTIN_TOOLS,
|
|
145
167
|
computeEssentialBuiltinNames,
|
|
146
168
|
createTools,
|
|
169
|
+
type DeferredDiagnosticsEntry,
|
|
147
170
|
discoverStartupLspServers,
|
|
148
171
|
EditTool,
|
|
149
172
|
EvalTool,
|
|
150
173
|
FindTool,
|
|
174
|
+
filterInitialToolsForDiscoveryAll,
|
|
151
175
|
getSearchTools,
|
|
152
176
|
HIDDEN_TOOLS,
|
|
153
177
|
isImageProviderPreference,
|
|
@@ -230,6 +254,42 @@ function buildAsyncResultBatchMessage(entries: AsyncResultEntry[]): CustomMessag
|
|
|
230
254
|
};
|
|
231
255
|
}
|
|
232
256
|
|
|
257
|
+
type LateDiagnosticsDetails = {
|
|
258
|
+
files: Array<{ path: string; summary: string; errored: boolean; messages: string[] }>;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
function buildLateDiagnosticsBatchMessage(
|
|
262
|
+
entries: DeferredDiagnosticsEntry[],
|
|
263
|
+
): CustomMessage<LateDiagnosticsDetails> | null {
|
|
264
|
+
if (entries.length === 0) return null;
|
|
265
|
+
const files = entries.map(entry => ({
|
|
266
|
+
path: entry.path,
|
|
267
|
+
summary: entry.summary,
|
|
268
|
+
messages: entry.messages,
|
|
269
|
+
errored: entry.errored,
|
|
270
|
+
}));
|
|
271
|
+
const details: LateDiagnosticsDetails = {
|
|
272
|
+
files: files.map(file => ({
|
|
273
|
+
path: file.path,
|
|
274
|
+
summary: file.summary,
|
|
275
|
+
errored: file.errored,
|
|
276
|
+
messages: file.messages,
|
|
277
|
+
})),
|
|
278
|
+
};
|
|
279
|
+
return {
|
|
280
|
+
role: "custom",
|
|
281
|
+
customType: LSP_LATE_DIAGNOSTIC_MESSAGE_TYPE,
|
|
282
|
+
content: prompt.render(lateDiagnosticTemplate, {
|
|
283
|
+
multiple: files.length > 1,
|
|
284
|
+
files,
|
|
285
|
+
}),
|
|
286
|
+
display: true,
|
|
287
|
+
attribution: "agent",
|
|
288
|
+
details,
|
|
289
|
+
timestamp: Date.now(),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
233
293
|
function buildMcpNotificationBatchMessage(entries: McpNotificationEntry[]): AgentMessage | null {
|
|
234
294
|
const resources: McpNotificationEntry[] = [];
|
|
235
295
|
const seen = new Set<string>();
|
|
@@ -253,6 +313,72 @@ function buildMcpNotificationBatchMessage(entries: McpNotificationEntry[]): Agen
|
|
|
253
313
|
};
|
|
254
314
|
}
|
|
255
315
|
|
|
316
|
+
type DeferredMCPActivation = {
|
|
317
|
+
mcpDiscoveryEnabled: boolean;
|
|
318
|
+
explicitlyRequestedMCPToolNames: string[];
|
|
319
|
+
activateAllMCPTools: boolean;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
function createPendingMCPTool(name: string): Tool {
|
|
323
|
+
const parsed = parseMCPToolName(name);
|
|
324
|
+
const serverName = parsed?.serverName;
|
|
325
|
+
const mcpToolName = parsed?.toolName ?? name;
|
|
326
|
+
const label = serverName ? `${serverName}/${mcpToolName}` : name;
|
|
327
|
+
const message = serverName
|
|
328
|
+
? `MCP server "${serverName}" is still connecting; tool "${name}" is not yet available. Retry after the MCP connection completes.`
|
|
329
|
+
: `MCP discovery is still in progress; tool "${name}" is not yet available. Retry after MCP connection completes.`;
|
|
330
|
+
const tool: Tool & { mcpServerName?: string; mcpToolName?: string } = {
|
|
331
|
+
name,
|
|
332
|
+
label,
|
|
333
|
+
description: `Pending MCP tool. ${message}`,
|
|
334
|
+
parameters: {
|
|
335
|
+
type: "object",
|
|
336
|
+
properties: {},
|
|
337
|
+
additionalProperties: true,
|
|
338
|
+
},
|
|
339
|
+
approval: "write",
|
|
340
|
+
intent: "omit",
|
|
341
|
+
mcpServerName: serverName,
|
|
342
|
+
mcpToolName,
|
|
343
|
+
async execute() {
|
|
344
|
+
return {
|
|
345
|
+
content: [{ type: "text", text: message }],
|
|
346
|
+
details: { serverName, mcpToolName, isError: true },
|
|
347
|
+
isError: true,
|
|
348
|
+
};
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
return tool;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function collectPendingMCPToolNames(
|
|
355
|
+
explicitToolNames: readonly string[] | undefined,
|
|
356
|
+
restoredSelectedToolNames: readonly string[],
|
|
357
|
+
): string[] {
|
|
358
|
+
const names = new Set<string>();
|
|
359
|
+
for (const name of explicitToolNames ?? []) {
|
|
360
|
+
const normalized = name.toLowerCase();
|
|
361
|
+
if (isMCPToolName(normalized)) names.add(normalized);
|
|
362
|
+
}
|
|
363
|
+
for (const name of restoredSelectedToolNames) {
|
|
364
|
+
const normalized = name.toLowerCase();
|
|
365
|
+
if (isMCPToolName(normalized)) names.add(normalized);
|
|
366
|
+
}
|
|
367
|
+
return [...names];
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function logMCPLoadErrors(errors: MCPLoadResult["errors"]): void {
|
|
371
|
+
for (const [serverName, error] of errors) {
|
|
372
|
+
logger.error("MCP tool load failed", { path: `mcp:${serverName}`, error });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function applyMCPEnvironment(result: { exaApiKeys: string[] }): void {
|
|
377
|
+
if (result.exaApiKeys.length > 0 && !$env.EXA_API_KEY) {
|
|
378
|
+
Bun.env.EXA_API_KEY = result.exaApiKeys[0];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
256
382
|
// Types
|
|
257
383
|
export interface CreateAgentSessionOptions {
|
|
258
384
|
/** Working directory for project-local discovery. Default: getProjectDir() */
|
|
@@ -278,10 +404,12 @@ export interface CreateAgentSessionOptions {
|
|
|
278
404
|
scopedModels?: Array<{ model: Model; thinkingLevel?: ThinkingLevel }>;
|
|
279
405
|
|
|
280
406
|
/** System prompt blocks. Array replaces default, function receives default blocks and returns final blocks. */
|
|
281
|
-
systemPrompt?: string[] | ((defaultPrompt: string[]) => string[]);
|
|
407
|
+
systemPrompt?: string | string[] | ((defaultPrompt: string[]) => string | string[]);
|
|
282
408
|
/** Optional provider-facing session identifier for prompt caches and sticky auth selection.
|
|
283
409
|
* Keeps persisted session files isolated while reusing provider-side caches. */
|
|
284
410
|
providerSessionId?: string;
|
|
411
|
+
/** Optional provider-facing prompt cache key, distinct from request lineage. */
|
|
412
|
+
providerPromptCacheKey?: string;
|
|
285
413
|
|
|
286
414
|
/** Custom tools to register (in addition to built-in tools). Accepts both CustomTool and ToolDefinition. */
|
|
287
415
|
customTools?: (CustomTool | ToolDefinition)[];
|
|
@@ -292,10 +420,41 @@ export interface CreateAgentSessionOptions {
|
|
|
292
420
|
/** Disable extension discovery (explicit paths still load). */
|
|
293
421
|
disableExtensionDiscovery?: boolean;
|
|
294
422
|
/**
|
|
295
|
-
* Pre-loaded extensions (skips file discovery
|
|
296
|
-
*
|
|
423
|
+
* Pre-loaded extensions (skips file discovery and the per-session factory
|
|
424
|
+
* call). Used by the CLI when extensions are loaded early to parse custom
|
|
425
|
+
* flags — the same process owns the returned instances, so reusing them is
|
|
426
|
+
* safe.
|
|
427
|
+
*
|
|
428
|
+
* NEVER pass this across session boundaries (e.g. parent → subagent).
|
|
429
|
+
* `Extension` instances close over a parent-bound `ExtensionAPI` (cwd,
|
|
430
|
+
* eventBus, runtime), and reusing them would route tools/handlers/commands
|
|
431
|
+
* back through the parent. For subagents, forward
|
|
432
|
+
* {@link preloadedExtensionPaths} instead.
|
|
433
|
+
*
|
|
434
|
+
* @internal
|
|
297
435
|
*/
|
|
298
436
|
preloadedExtensions?: LoadExtensionsResult;
|
|
437
|
+
/**
|
|
438
|
+
* Pre-discovered extension source paths. When provided, the filesystem-scan
|
|
439
|
+
* inside `discoverExtensionPaths()` is skipped — the session still calls
|
|
440
|
+
* `loadExtensions()` itself so each `Extension` is bound to THIS session's
|
|
441
|
+
* `ExtensionAPI` (cwd, eventBus, runtime).
|
|
442
|
+
*
|
|
443
|
+
* This is the safe pass-through for parent → subagent forwarding.
|
|
444
|
+
*/
|
|
445
|
+
preloadedExtensionPaths?: string[];
|
|
446
|
+
/**
|
|
447
|
+
* Pre-discovered custom-tool source paths from `.prometheus/tools/`, `.claude/tools/`,
|
|
448
|
+
* plugins, etc. When provided, the filesystem-scan inside
|
|
449
|
+
* `discoverCustomToolPaths()` is skipped — subagents inherit the parent's
|
|
450
|
+
* scan result and call `loadCustomTools()` themselves so each session binds
|
|
451
|
+
* tools to its OWN `CustomToolAPI` (cwd, exec, pushPendingAction, UI).
|
|
452
|
+
*
|
|
453
|
+
* Forwarding the loaded `LoadedCustomTool[]` instances directly would reuse
|
|
454
|
+
* the parent's session-bound API and route tool execution back through the
|
|
455
|
+
* parent — wrong for isolated tasks and for pending-action routing.
|
|
456
|
+
*/
|
|
457
|
+
preloadedCustomToolPaths?: ToolPathWithSource[];
|
|
299
458
|
|
|
300
459
|
/** Shared event bus for tool/extension communication. Default: creates new bus. */
|
|
301
460
|
eventBus?: EventBus;
|
|
@@ -454,11 +613,18 @@ function resolveSnapshotTtlMs(): number {
|
|
|
454
613
|
* override to re-mint access tokens when needed.
|
|
455
614
|
*/
|
|
456
615
|
export async function discoverAuthStorage(agentDir: string = getDefaultAgentDir()): Promise<AuthStorage> {
|
|
457
|
-
const
|
|
616
|
+
const brokerConfigPromise = resolveAuthBrokerConfig();
|
|
617
|
+
const cachePath = getAuthBrokerSnapshotCachePath();
|
|
618
|
+
// Warm the encrypted snapshot cache into the page cache while the broker
|
|
619
|
+
// config resolves (it may shell out for a `!command` token). Decryption
|
|
620
|
+
// needs the resolved token, so the real cache read cannot start earlier.
|
|
621
|
+
void Bun.file(cachePath)
|
|
622
|
+
.arrayBuffer()
|
|
623
|
+
.catch(() => undefined);
|
|
624
|
+
const brokerConfig = await brokerConfigPromise;
|
|
458
625
|
if (brokerConfig) {
|
|
459
626
|
const client = new AuthBrokerClient({ url: brokerConfig.url, token: brokerConfig.token });
|
|
460
627
|
const ttlMs = resolveSnapshotTtlMs();
|
|
461
|
-
const cachePath = getAuthBrokerSnapshotCachePath();
|
|
462
628
|
const persist =
|
|
463
629
|
ttlMs > 0
|
|
464
630
|
? (snapshot: SnapshotResponse): void => {
|
|
@@ -520,6 +686,26 @@ export async function discoverExtensions(cwd?: string): Promise<LoadExtensionsRe
|
|
|
520
686
|
return discoverAndLoadExtensions([], resolvedCwd);
|
|
521
687
|
}
|
|
522
688
|
|
|
689
|
+
/**
|
|
690
|
+
* Path-only counterpart of {@link loadSessionExtensions}: the FS-heavy scan
|
|
691
|
+
* without the per-session module load. Subagents reuse the parent's path list
|
|
692
|
+
* (cached on {@link ToolSession.extensionPaths}) and rebuild Extension
|
|
693
|
+
* instances themselves so each session's `ExtensionAPI` (cwd, eventBus,
|
|
694
|
+
* runtime) is its own.
|
|
695
|
+
*/
|
|
696
|
+
export async function discoverSessionExtensionPaths(
|
|
697
|
+
options: Pick<CreateAgentSessionOptions, "disableExtensionDiscovery" | "additionalExtensionPaths">,
|
|
698
|
+
cwd: string,
|
|
699
|
+
settings: Settings,
|
|
700
|
+
): Promise<string[]> {
|
|
701
|
+
if (options.disableExtensionDiscovery) {
|
|
702
|
+
return options.additionalExtensionPaths ?? [];
|
|
703
|
+
}
|
|
704
|
+
const configuredPaths = [...(options.additionalExtensionPaths ?? []), ...(settings.get("extensions") ?? [])];
|
|
705
|
+
const disabledExtensionIds = settings.get("disabledExtensions") ?? [];
|
|
706
|
+
return discoverExtensionPaths(configuredPaths, cwd, disabledExtensionIds);
|
|
707
|
+
}
|
|
708
|
+
|
|
523
709
|
/**
|
|
524
710
|
* Load the discovered/configured extensions for a session — everything {@link
|
|
525
711
|
* createAgentSession} would load except the inline factory extensions it appends
|
|
@@ -535,23 +721,8 @@ export async function loadSessionExtensions(
|
|
|
535
721
|
settings: Settings,
|
|
536
722
|
eventBus: EventBus,
|
|
537
723
|
): Promise<LoadExtensionsResult> {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const configuredPaths = options.additionalExtensionPaths ?? [];
|
|
541
|
-
result = await logger.time("loadExtensions", loadExtensions, configuredPaths, cwd, eventBus);
|
|
542
|
-
} else {
|
|
543
|
-
// Merge CLI extension paths with settings extension paths.
|
|
544
|
-
const configuredPaths = [...(options.additionalExtensionPaths ?? []), ...(settings.get("extensions") ?? [])];
|
|
545
|
-
const disabledExtensionIds = settings.get("disabledExtensions") ?? [];
|
|
546
|
-
result = await logger.time(
|
|
547
|
-
"discoverAndLoadExtensions",
|
|
548
|
-
discoverAndLoadExtensions,
|
|
549
|
-
configuredPaths,
|
|
550
|
-
cwd,
|
|
551
|
-
eventBus,
|
|
552
|
-
disabledExtensionIds,
|
|
553
|
-
);
|
|
554
|
-
}
|
|
724
|
+
const paths = await discoverSessionExtensionPaths(options, cwd, settings);
|
|
725
|
+
const result = await logger.time("loadExtensions", loadExtensions, paths, cwd, eventBus);
|
|
555
726
|
for (const { path, error } of result.errors) {
|
|
556
727
|
logger.error("Failed to load extension", { path, error });
|
|
557
728
|
}
|
|
@@ -710,6 +881,7 @@ function customToolToDefinition(tool: CustomTool): ToolDefinition {
|
|
|
710
881
|
parameters: tool.parameters,
|
|
711
882
|
hidden: tool.hidden,
|
|
712
883
|
deferrable: tool.deferrable,
|
|
884
|
+
approval: typeof tool.approval === "function" ? tool.approval.bind(tool) : tool.approval,
|
|
713
885
|
mcpServerName: tool.mcpServerName,
|
|
714
886
|
mcpToolName: tool.mcpToolName,
|
|
715
887
|
execute: (toolCallId, params, signal, onUpdate, ctx) =>
|
|
@@ -993,20 +1165,15 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
993
1165
|
SessionManager.create(cwd, SessionManager.getDefaultSessionDir(cwd, agentDir)),
|
|
994
1166
|
);
|
|
995
1167
|
const providerSessionId = options.providerSessionId ?? sessionManager.getSessionId();
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
const hasKey = !!(await modelRegistry.getApiKey(candidate, providerSessionId));
|
|
1007
|
-
modelApiKeyAvailability.set(availabilityKey, hasKey);
|
|
1008
|
-
return hasKey;
|
|
1009
|
-
};
|
|
1168
|
+
// Startup model *selection* only needs to know whether auth is configured for
|
|
1169
|
+
// a candidate's provider — never the resolved key bytes. Use the synchronous,
|
|
1170
|
+
// side-effect-free probe (`hasConfiguredAuth`): it refreshes no OAuth tokens,
|
|
1171
|
+
// executes no `!command` keys, and issues no auth-broker requests. Resolving the
|
|
1172
|
+
// real key here (`getApiKey`) blocks resume on those network paths — a slow or
|
|
1173
|
+
// unreachable OAuth/broker endpoint stalls startup for the full ~10s refresh
|
|
1174
|
+
// timeout per candidate (observed as a hang in `restoreSessionModel`). The real
|
|
1175
|
+
// key is resolved lazily per request via ModelRegistry.resolver.
|
|
1176
|
+
const hasModelAuth = (candidate: Model): boolean => modelRegistry.hasConfiguredAuth(candidate);
|
|
1010
1177
|
|
|
1011
1178
|
// Load and create secret obfuscator early so resumed session state and prompt warnings
|
|
1012
1179
|
// reflect actual loaded secrets, not just the setting toggle.
|
|
@@ -1031,9 +1198,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1031
1198
|
const hasServiceTierEntry = existingBranch.some(entry => entry.type === "service_tier_change");
|
|
1032
1199
|
|
|
1033
1200
|
const hasExplicitModel = options.model !== undefined || options.modelPattern !== undefined;
|
|
1034
|
-
const modelMatchPreferences =
|
|
1035
|
-
usageOrder: settings.getStorage()?.getModelUsageOrder(),
|
|
1036
|
-
};
|
|
1201
|
+
const modelMatchPreferences = getModelMatchPreferences(settings);
|
|
1037
1202
|
const allowedModels = await logger.time("resolveAllowedModels", () =>
|
|
1038
1203
|
resolveAllowedModels(modelRegistry, settings, modelMatchPreferences),
|
|
1039
1204
|
);
|
|
@@ -1057,7 +1222,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1057
1222
|
: [];
|
|
1058
1223
|
let restoredSessionModelIndex = -1;
|
|
1059
1224
|
if (!hasExplicitModel && !model && sessionModelStrings.length > 0) {
|
|
1060
|
-
|
|
1225
|
+
logger.time("restoreSessionModel", () => {
|
|
1061
1226
|
let failedSessionModel: string | undefined;
|
|
1062
1227
|
for (let i = 0; i < sessionModelStrings.length; i++) {
|
|
1063
1228
|
const sessionModelStr = sessionModelStrings[i];
|
|
@@ -1068,7 +1233,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1068
1233
|
}
|
|
1069
1234
|
|
|
1070
1235
|
const restoredModel = modelRegistry.find(parsedModel.provider, parsedModel.id);
|
|
1071
|
-
if (restoredModel && (
|
|
1236
|
+
if (restoredModel && hasModelAuth(restoredModel)) {
|
|
1072
1237
|
model = restoredModel;
|
|
1073
1238
|
restoredSessionModelIndex = i;
|
|
1074
1239
|
break;
|
|
@@ -1149,22 +1314,26 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1149
1314
|
}
|
|
1150
1315
|
|
|
1151
1316
|
// Discover rules and bucket them in one pass to avoid repeated scans over large rule sets.
|
|
1152
|
-
const { ttsrManager, rulebookRules, alwaysApplyRules } = await logger.time(
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1317
|
+
const { ttsrManager, rulebookRules, alwaysApplyRules, allRules } = await logger.time(
|
|
1318
|
+
"discoverTtsrRules",
|
|
1319
|
+
async () => {
|
|
1320
|
+
const { TtsrManager } = await import("./export/ttsr");
|
|
1321
|
+
const ttsrSettings = settings.getGroup("ttsr");
|
|
1322
|
+
const ttsrManager = new TtsrManager(ttsrSettings);
|
|
1323
|
+
const rulesResult =
|
|
1324
|
+
options.rules !== undefined
|
|
1325
|
+
? { items: options.rules, warnings: undefined }
|
|
1326
|
+
: await loadCapability<Rule>(ruleCapability.id, { cwd });
|
|
1327
|
+
const { rulebookRules, alwaysApplyRules } = bucketRules(rulesResult.items, ttsrManager, {
|
|
1328
|
+
builtinRules: ttsrSettings.builtinRules,
|
|
1329
|
+
disabledRules: ttsrSettings.disabledRules,
|
|
1330
|
+
});
|
|
1331
|
+
if (existingSession.injectedTtsrRules.length > 0) {
|
|
1332
|
+
ttsrManager.restoreInjected(existingSession.injectedTtsrRules);
|
|
1333
|
+
}
|
|
1334
|
+
return { ttsrManager, rulebookRules, alwaysApplyRules, allRules: rulesResult.items };
|
|
1335
|
+
},
|
|
1336
|
+
);
|
|
1168
1337
|
|
|
1169
1338
|
// Resolve contextFiles up-front (it's needed before tool creation). The
|
|
1170
1339
|
// workspace tree scan is slow on large repos and we MUST NOT block startup on
|
|
@@ -1199,7 +1368,6 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1199
1368
|
let hasSession = false;
|
|
1200
1369
|
let hasRegistered = false;
|
|
1201
1370
|
const enableLsp = options.enableLsp ?? true;
|
|
1202
|
-
const backgroundJobsEnabled = isBackgroundJobSupportEnabled(settings);
|
|
1203
1371
|
const asyncMaxJobs = Math.min(100, Math.max(1, settings.get("async.maxJobs") ?? 100));
|
|
1204
1372
|
const ASYNC_INLINE_RESULT_MAX_CHARS = 12_000;
|
|
1205
1373
|
const ASYNC_PREVIEW_MAX_CHARS = 4_000;
|
|
@@ -1232,7 +1400,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1232
1400
|
// (issue #1923). The `instance()` guard means later sessions also skip
|
|
1233
1401
|
// constructing an orphaned manager that nothing would ever route to.
|
|
1234
1402
|
const asyncJobManager =
|
|
1235
|
-
|
|
1403
|
+
!options.parentTaskPrefix && !AsyncJobManager.instance()
|
|
1236
1404
|
? new AsyncJobManager({
|
|
1237
1405
|
maxRunningJobs: asyncMaxJobs,
|
|
1238
1406
|
onJobComplete: async (jobId, result, job) => {
|
|
@@ -1257,6 +1425,17 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1257
1425
|
const resolvedAgentId = options.agentId ?? options.parentTaskPrefix ?? MAIN_AGENT_ID;
|
|
1258
1426
|
const resolvedAgentDisplayName =
|
|
1259
1427
|
options.agentDisplayName ?? ((options.taskDepth ?? 0) > 0 || options.parentTaskPrefix ? "sub" : "main");
|
|
1428
|
+
const agentKind = (options.taskDepth ?? 0) > 0 || options.parentTaskPrefix ? ("sub" as const) : ("main" as const);
|
|
1429
|
+
/**
|
|
1430
|
+
* Forget the agent ref on teardown — unless the agent is being parked (or is
|
|
1431
|
+
* already parked). Parking disposes the session but keeps the ref addressable
|
|
1432
|
+
* (history://, revive); only process teardown / explicit kill unregisters.
|
|
1433
|
+
*/
|
|
1434
|
+
const unregisterUnlessParked = (): void => {
|
|
1435
|
+
if (agentRegistry.get(resolvedAgentId)?.status === "parked") return;
|
|
1436
|
+
if (AgentLifecycleManager.global().isParking(resolvedAgentId)) return;
|
|
1437
|
+
agentRegistry.unregister(resolvedAgentId);
|
|
1438
|
+
};
|
|
1260
1439
|
const evalKernelOwnerId = `agent-session:${Snowflake.next()}`;
|
|
1261
1440
|
|
|
1262
1441
|
try {
|
|
@@ -1266,6 +1445,10 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1266
1445
|
if (model) return formatModelString(model);
|
|
1267
1446
|
return undefined;
|
|
1268
1447
|
};
|
|
1448
|
+
// Per-path mutation counter shared across edit/write tools. Late-diagnostics
|
|
1449
|
+
// entries capture it at fetch time and are dropped at injection if a newer
|
|
1450
|
+
// mutation (any tool) bumped it in the meantime.
|
|
1451
|
+
const fileMutationVersions = new Map<string, number>();
|
|
1269
1452
|
const toolSession: ToolSession = {
|
|
1270
1453
|
get cwd() {
|
|
1271
1454
|
return sessionManager.getCwd();
|
|
@@ -1282,6 +1465,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1282
1465
|
contextFiles,
|
|
1283
1466
|
workspaceTree: resolvedWorkspaceTree,
|
|
1284
1467
|
skills,
|
|
1468
|
+
rules: allRules,
|
|
1285
1469
|
eventBus,
|
|
1286
1470
|
outputSchema: options.outputSchema,
|
|
1287
1471
|
requireYieldTool: options.requireYieldTool,
|
|
@@ -1295,13 +1479,14 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1295
1479
|
session ? session.trackEvalExecution(execution, abortController) : execution,
|
|
1296
1480
|
getSessionId: () => sessionManager.getSessionId?.() ?? null,
|
|
1297
1481
|
getHindsightSessionState: () => session?.getHindsightSessionState(),
|
|
1298
|
-
getMnemopiSessionState: () => getMnemopiSessionState(
|
|
1482
|
+
getMnemopiSessionState: () => session?.getMnemopiSessionState(),
|
|
1299
1483
|
getAgentId: () => resolvedAgentId,
|
|
1300
1484
|
getToolByName: name => session?.getToolByName(name),
|
|
1301
1485
|
agentRegistry,
|
|
1302
1486
|
getSessionSpawns: () => options.spawns ?? "*",
|
|
1303
1487
|
getModelString: () => (hasExplicitModel && model ? formatModelString(model) : undefined),
|
|
1304
1488
|
getActiveModelString,
|
|
1489
|
+
getActiveModel: () => agent?.state.model ?? model,
|
|
1305
1490
|
getPlanModeState: () => session?.getPlanModeState(),
|
|
1306
1491
|
getPlanReferencePath: () => session?.getPlanReferencePath() ?? "local://PLAN.md",
|
|
1307
1492
|
getGoalModeState: () => session?.getGoalModeState(),
|
|
@@ -1310,7 +1495,13 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1310
1495
|
getTurnBudget: () => sessionManager.getTurnBudget(),
|
|
1311
1496
|
recordEvalSubagentUsage: output => sessionManager.recordEvalSubagentOutput(output),
|
|
1312
1497
|
getClientBridge: () => session?.clientBridge,
|
|
1313
|
-
|
|
1498
|
+
queueDeferredDiagnostics: entry => session?.yieldQueue.enqueue(LSP_LATE_DIAGNOSTIC_MESSAGE_TYPE, entry),
|
|
1499
|
+
bumpFileMutationVersion: path => {
|
|
1500
|
+
const next = (fileMutationVersions.get(path) ?? 0) + 1;
|
|
1501
|
+
fileMutationVersions.set(path, next);
|
|
1502
|
+
return next;
|
|
1503
|
+
},
|
|
1504
|
+
getFileMutationVersion: path => fileMutationVersions.get(path) ?? 0,
|
|
1314
1505
|
getTodoPhases: () => session.getTodoPhases(),
|
|
1315
1506
|
setTodoPhases: phases => session.setTodoPhases(phases),
|
|
1316
1507
|
isMCPDiscoveryEnabled: () => session.isMCPDiscoveryEnabled(),
|
|
@@ -1372,7 +1563,11 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1372
1563
|
const getArtifactsDir = () => sessionManager.getArtifactsDir();
|
|
1373
1564
|
if (!options.parentTaskPrefix) {
|
|
1374
1565
|
setActiveSkills(skills);
|
|
1375
|
-
|
|
1566
|
+
// Include TTSR rules so `rule://<name>` can resolve them too. They are
|
|
1567
|
+
// registered with the manager and bucketed out before rulebook/always,
|
|
1568
|
+
// so without this a TTSR-only rule (e.g. a triggered builtin) is not
|
|
1569
|
+
// addressable and `rule://` reports "Available: none".
|
|
1570
|
+
setActiveRules([...rulebookRules, ...alwaysApplyRules, ...ttsrManager.getRules()]);
|
|
1376
1571
|
if (asyncJobManager) AsyncJobManager.setInstance(asyncJobManager);
|
|
1377
1572
|
}
|
|
1378
1573
|
const localProtocolOptions = options.localProtocolOptions ?? {
|
|
@@ -1396,46 +1591,131 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1396
1591
|
let mcpManager: MCPManager | undefined = options.mcpManager;
|
|
1397
1592
|
toolSession.mcpManager = mcpManager;
|
|
1398
1593
|
const enableMCP = options.enableMCP ?? true;
|
|
1594
|
+
const deferMCPDiscoveryForUI = enableMCP && !mcpManager && options.hasUI === true;
|
|
1399
1595
|
const customTools: CustomTool[] = [];
|
|
1596
|
+
let startDeferredMCPDiscovery:
|
|
1597
|
+
| ((liveSession: AgentSession, activation: DeferredMCPActivation) => void)
|
|
1598
|
+
| undefined;
|
|
1599
|
+
const onMCPConnecting = (serverNames: string[]) => {
|
|
1600
|
+
if (!options.hasUI || serverNames.length === 0) return;
|
|
1601
|
+
eventBus.emit(MCP_CONNECTING_EVENT_CHANNEL, { serverNames } satisfies McpConnectingEvent);
|
|
1602
|
+
};
|
|
1603
|
+
const mcpDiscoverOptions = {
|
|
1604
|
+
onConnecting: onMCPConnecting,
|
|
1605
|
+
enableProjectConfig: settings.get("mcp.enableProjectConfig") ?? true,
|
|
1606
|
+
// Always filter Exa - we have native integration
|
|
1607
|
+
filterExa: true,
|
|
1608
|
+
// Filter browser MCP servers when builtin browser tool is active
|
|
1609
|
+
filterBrowser: settings.get("browser.enabled") ?? false,
|
|
1610
|
+
};
|
|
1400
1611
|
if (enableMCP && !mcpManager) {
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
// Filter browser MCP servers when builtin browser tool is active
|
|
1411
|
-
filterBrowser: settings.get("browser.enabled") ?? false,
|
|
1412
|
-
cacheStorage: settings.getStorage(),
|
|
1413
|
-
authStorage,
|
|
1414
|
-
});
|
|
1415
|
-
mcpManager = mcpResult.manager;
|
|
1416
|
-
toolSession.mcpManager = mcpManager;
|
|
1612
|
+
if (deferMCPDiscoveryForUI) {
|
|
1613
|
+
const cacheStorage = settings.getStorage();
|
|
1614
|
+
mcpManager = new MCPManager(cwd, cacheStorage ? new MCPToolCache(cacheStorage) : null);
|
|
1615
|
+
mcpManager.setAuthStorage(authStorage);
|
|
1616
|
+
toolSession.mcpManager = mcpManager;
|
|
1617
|
+
|
|
1618
|
+
if (settings.get("mcp.notifications")) {
|
|
1619
|
+
mcpManager.setNotificationsEnabled(true);
|
|
1620
|
+
}
|
|
1417
1621
|
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1622
|
+
const deferredMCPManager = mcpManager;
|
|
1623
|
+
startDeferredMCPDiscovery = (liveSession, activation) => {
|
|
1624
|
+
void (async () => {
|
|
1625
|
+
try {
|
|
1626
|
+
const mcpResult = await logger.time("discoverAndLoadMCPTools", () =>
|
|
1627
|
+
deferredMCPManager.discoverAndConnect(mcpDiscoverOptions),
|
|
1628
|
+
);
|
|
1629
|
+
// The session can be torn down while servers are still connecting.
|
|
1630
|
+
// Don't resurrect tools on a disposed session, and don't leak the
|
|
1631
|
+
// transports/subprocesses the connect just spawned.
|
|
1632
|
+
if (liveSession.isDisposed) {
|
|
1633
|
+
await deferredMCPManager.disconnectAll();
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
applyMCPEnvironment(mcpResult);
|
|
1637
|
+
logMCPLoadErrors(mcpResult.errors);
|
|
1638
|
+
// `tools.discoveryMode: "auto"` was resolved against a registry that
|
|
1639
|
+
// held only built-ins plus persisted placeholder names. Recompute with
|
|
1640
|
+
// the real MCP tool count: a large toolset must flip discovery on
|
|
1641
|
+
// BEFORE the refresh, or activateAll would dump every MCP tool into
|
|
1642
|
+
// the active set with no search_tool_bm25 registered.
|
|
1643
|
+
let discoveryEnabled = activation.mcpDiscoveryEnabled;
|
|
1644
|
+
let activateAll = activation.activateAllMCPTools;
|
|
1645
|
+
if (!discoveryEnabled) {
|
|
1646
|
+
const nonMCPToolNames = [...toolRegistry.keys()].filter(name => !isMCPToolName(name));
|
|
1647
|
+
const projectedMode = resolveEffectiveToolDiscoveryMode(
|
|
1648
|
+
settings,
|
|
1649
|
+
countToolsForAutoDiscovery([...nonMCPToolNames, ...mcpResult.tools.map(tool => tool.name)]),
|
|
1650
|
+
);
|
|
1651
|
+
if (projectedMode !== "off") {
|
|
1652
|
+
effectiveDiscoveryMode = projectedMode;
|
|
1653
|
+
mcpDiscoveryEnabled = true;
|
|
1654
|
+
discoveryEnabled = true;
|
|
1655
|
+
activateAll = false;
|
|
1656
|
+
liveSession.enableMCPDiscovery();
|
|
1657
|
+
if (!toolRegistry.has("search_tool_bm25")) {
|
|
1658
|
+
const searchTool: Tool = new SearchToolBm25Tool(toolSession);
|
|
1659
|
+
toolRegistry.set(
|
|
1660
|
+
searchTool.name,
|
|
1661
|
+
new ExtensionToolWrapper(wrapToolWithMetaNotice(searchTool), extensionRunner) as Tool,
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
await liveSession.setActiveToolsByName([
|
|
1665
|
+
...liveSession.getActiveToolNames(),
|
|
1666
|
+
"search_tool_bm25",
|
|
1667
|
+
]);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
await liveSession.refreshMCPTools(mcpResult.tools, { activateAll });
|
|
1671
|
+
if (activation.explicitlyRequestedMCPToolNames.length > 0) {
|
|
1672
|
+
if (discoveryEnabled && !activation.mcpDiscoveryEnabled) {
|
|
1673
|
+
// Discovery flipped on mid-flight: route the explicit request
|
|
1674
|
+
// through discovery-aware activation so selection persists.
|
|
1675
|
+
await liveSession.activateDiscoveredMCPTools(activation.explicitlyRequestedMCPToolNames);
|
|
1676
|
+
} else if (!discoveryEnabled) {
|
|
1677
|
+
await liveSession.setActiveToolsByName([
|
|
1678
|
+
...liveSession.getActiveToolNames(),
|
|
1679
|
+
...activation.explicitlyRequestedMCPToolNames,
|
|
1680
|
+
]);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
} catch (error) {
|
|
1684
|
+
logger.error("MCP tool load failed", {
|
|
1685
|
+
path: ".mcp.json",
|
|
1686
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
})();
|
|
1690
|
+
};
|
|
1691
|
+
} else {
|
|
1692
|
+
const mcpResult = await logger.time("discoverAndLoadMCPTools", discoverAndLoadMCPTools, cwd, {
|
|
1693
|
+
...mcpDiscoverOptions,
|
|
1694
|
+
cacheStorage: settings.getStorage(),
|
|
1695
|
+
authStorage,
|
|
1696
|
+
});
|
|
1697
|
+
mcpManager = mcpResult.manager;
|
|
1698
|
+
toolSession.mcpManager = mcpManager;
|
|
1425
1699
|
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1700
|
+
if (settings.get("mcp.notifications")) {
|
|
1701
|
+
mcpManager.setNotificationsEnabled(true);
|
|
1702
|
+
}
|
|
1703
|
+
applyMCPEnvironment(mcpResult);
|
|
1430
1704
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1705
|
+
// Log MCP errors
|
|
1706
|
+
for (const { path, error } of mcpResult.errors) {
|
|
1707
|
+
logger.error("MCP tool load failed", { path, error });
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
if (mcpResult.tools.length > 0) {
|
|
1711
|
+
// MCP tools are LoadedCustomTool, extract the tool property
|
|
1712
|
+
customTools.push(...mcpResult.tools.map(loaded => loaded.tool));
|
|
1713
|
+
}
|
|
1434
1714
|
}
|
|
1435
1715
|
}
|
|
1436
1716
|
// Only top-level sessions own the global MCPManager. Subagents already
|
|
1437
1717
|
// receive the parent's manager via `options.mcpManager`, and reassigning
|
|
1438
|
-
// the singleton to the same value is a no-op
|
|
1718
|
+
// the singleton to the same value is a no-op — keep the gate explicit
|
|
1439
1719
|
// to mirror the AsyncJobManager ownership rule.
|
|
1440
1720
|
if (mcpManager && !options.parentTaskPrefix) MCPManager.setInstance(mcpManager);
|
|
1441
1721
|
|
|
@@ -1445,7 +1725,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1445
1725
|
customTools.push(...(imageGenTools as unknown as CustomTool[]));
|
|
1446
1726
|
}
|
|
1447
1727
|
|
|
1448
|
-
if (settings.get("
|
|
1728
|
+
if (settings.get("speechgen.enabled")) {
|
|
1449
1729
|
customTools.push(ttsTool as unknown as CustomTool);
|
|
1450
1730
|
}
|
|
1451
1731
|
|
|
@@ -1454,37 +1734,78 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1454
1734
|
customTools.push(...getSearchTools());
|
|
1455
1735
|
}
|
|
1456
1736
|
|
|
1457
|
-
// Discover
|
|
1737
|
+
// Discover custom tools from `.prometheus/tools/`, `.claude/tools/`, plugins, etc.
|
|
1738
|
+
// Subagents reuse the parent's scan via `preloadedCustomToolPaths` to skip
|
|
1739
|
+
// the FS walk, but ALWAYS re-call `loadCustomTools` here so factories bind
|
|
1740
|
+
// to THIS session's `CustomToolAPI` (cwd, exec, pushPendingAction, UI).
|
|
1741
|
+
// Forwarding the parent's `LoadedCustomTool[]` directly would route tool
|
|
1742
|
+
// execution back through the parent — wrong for isolated tasks and for
|
|
1743
|
+
// pending-action queueing.
|
|
1458
1744
|
const builtInToolNames = builtinTools.map(t => t.name);
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
cwd,
|
|
1464
|
-
builtInToolNames,
|
|
1465
|
-
action => queueResolveHandler(toolSession, action),
|
|
1745
|
+
const customToolPaths: ToolPathWithSource[] =
|
|
1746
|
+
options.preloadedCustomToolPaths ??
|
|
1747
|
+
(await logger.time("discoverCustomToolPaths", () => discoverCustomToolPaths([], cwd)));
|
|
1748
|
+
const customToolsLoadResult = await logger.time("loadCustomTools", () =>
|
|
1749
|
+
loadCustomTools(customToolPaths, cwd, builtInToolNames, action => queueResolveHandler(toolSession, action)),
|
|
1466
1750
|
);
|
|
1467
|
-
for (const { path, error } of
|
|
1751
|
+
for (const { path, error } of customToolsLoadResult.errors) {
|
|
1468
1752
|
logger.error("Custom tool load failed", { path, error });
|
|
1469
1753
|
}
|
|
1470
|
-
if (
|
|
1471
|
-
customTools.push(...
|
|
1754
|
+
if (customToolsLoadResult.tools.length > 0) {
|
|
1755
|
+
customTools.push(...customToolsLoadResult.tools.map(loaded => loaded.tool));
|
|
1472
1756
|
}
|
|
1757
|
+
// Forward the path list (NOT the loaded tools) to subagents so they
|
|
1758
|
+
// re-bind under their own `CustomToolAPI` while skipping the FS scan.
|
|
1759
|
+
toolSession.customToolPaths = customToolPaths;
|
|
1473
1760
|
|
|
1474
1761
|
const inlineExtensions: ExtensionFactory[] = options.extensions ? [...options.extensions] : [];
|
|
1475
|
-
inlineExtensions.push(createAutoresearchExtension);
|
|
1762
|
+
inlineExtensions.push((await import("./autoresearch")).createAutoresearchExtension);
|
|
1476
1763
|
if (customTools.length > 0) {
|
|
1477
1764
|
inlineExtensions.push(createCustomToolsExtension(customTools));
|
|
1478
1765
|
}
|
|
1479
1766
|
|
|
1480
|
-
// Load extensions.
|
|
1481
|
-
//
|
|
1482
|
-
//
|
|
1483
|
-
//
|
|
1484
|
-
//
|
|
1485
|
-
//
|
|
1486
|
-
|
|
1487
|
-
|
|
1767
|
+
// Load extensions. Three paths:
|
|
1768
|
+
// 1. `preloadedExtensions` (CLI): caller already loaded — reuse the
|
|
1769
|
+
// Extension instances. Shallow-clone `extensions` so the inline
|
|
1770
|
+
// push below cannot mutate the caller's array. `runtime` is shared
|
|
1771
|
+
// so flag values set pre-creation flow into the live session.
|
|
1772
|
+
// 2. `preloadedExtensionPaths` (subagent): caller resolved paths;
|
|
1773
|
+
// skip the FS scan but always re-call `loadExtensions` here so
|
|
1774
|
+
// each `Extension` binds to THIS session's `ExtensionAPI`
|
|
1775
|
+
// (cwd, eventBus, runtime).
|
|
1776
|
+
// 3. No preload: run the full session discovery.
|
|
1777
|
+
// `disableExtensionDiscovery` is honored implicitly: a caller that set
|
|
1778
|
+
// the flag and pre-resolved the result already reflects that choice.
|
|
1779
|
+
let extensionPaths: string[];
|
|
1780
|
+
let extensionsResult: LoadExtensionsResult;
|
|
1781
|
+
if (options.preloadedExtensions) {
|
|
1782
|
+
extensionsResult = {
|
|
1783
|
+
...options.preloadedExtensions,
|
|
1784
|
+
extensions: [...options.preloadedExtensions.extensions],
|
|
1785
|
+
};
|
|
1786
|
+
// Capture paths for downstream forwarding; filter inline-factory
|
|
1787
|
+
// entries (`<inline-N>`) — those are per-session, not source paths.
|
|
1788
|
+
extensionPaths = extensionsResult.extensions
|
|
1789
|
+
.map(ext => ext.resolvedPath)
|
|
1790
|
+
.filter(p => !p.startsWith("<inline"));
|
|
1791
|
+
} else if (options.preloadedExtensionPaths) {
|
|
1792
|
+
extensionPaths = options.preloadedExtensionPaths;
|
|
1793
|
+
extensionsResult = await logger.time("loadExtensions", loadExtensions, extensionPaths, cwd, eventBus);
|
|
1794
|
+
for (const { path, error } of extensionsResult.errors) {
|
|
1795
|
+
logger.error("Failed to load extension", { path, error });
|
|
1796
|
+
}
|
|
1797
|
+
} else {
|
|
1798
|
+
extensionPaths = await logger.time("discoverSessionExtensionPaths", () =>
|
|
1799
|
+
discoverSessionExtensionPaths(options, cwd, settings),
|
|
1800
|
+
);
|
|
1801
|
+
extensionsResult = await logger.time("loadExtensions", loadExtensions, extensionPaths, cwd, eventBus);
|
|
1802
|
+
for (const { path, error } of extensionsResult.errors) {
|
|
1803
|
+
logger.error("Failed to load extension", { path, error });
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
// Forward the source-path list (NOT the loaded instances) so subagents
|
|
1807
|
+
// rebuild their own session-scoped extensions.
|
|
1808
|
+
toolSession.extensionPaths = extensionPaths;
|
|
1488
1809
|
|
|
1489
1810
|
// Load inline extensions from factories
|
|
1490
1811
|
if (inlineExtensions.length > 0) {
|
|
@@ -1515,6 +1836,16 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1515
1836
|
}
|
|
1516
1837
|
extensionsResult.runtime.pendingProviderRegistrations = [];
|
|
1517
1838
|
}
|
|
1839
|
+
// Discover runtime (extension) provider catalogs now that they are
|
|
1840
|
+
// registered. The startup refreshInBackground() ran before extensions
|
|
1841
|
+
// loaded, so dynamic extension providers are only discovered here. Runs in
|
|
1842
|
+
// the background (cache-aware) so startup is never blocked on the fetch; the
|
|
1843
|
+
// model list re-renders when the catalog arrives, like other dynamic providers.
|
|
1844
|
+
void modelRegistry.refreshRuntimeProviders().catch(error => {
|
|
1845
|
+
logger.warn("runtime provider discovery failed", {
|
|
1846
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1847
|
+
});
|
|
1848
|
+
});
|
|
1518
1849
|
|
|
1519
1850
|
// Retry session-model candidates now that extension providers are
|
|
1520
1851
|
// registered. The initial restore runs before extensions load, so a role
|
|
@@ -1530,7 +1861,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1530
1861
|
const parsedModel = parseModelString(sessionModelStr);
|
|
1531
1862
|
if (!parsedModel) continue;
|
|
1532
1863
|
const restoredModel = modelRegistry.find(parsedModel.provider, parsedModel.id);
|
|
1533
|
-
if (restoredModel && (
|
|
1864
|
+
if (restoredModel && hasModelAuth(restoredModel)) {
|
|
1534
1865
|
model = restoredModel;
|
|
1535
1866
|
modelFallbackMessage = undefined;
|
|
1536
1867
|
restoredSessionModelIndex = i;
|
|
@@ -1553,9 +1884,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1553
1884
|
// Resolve deferred --model pattern now that extension models are registered.
|
|
1554
1885
|
if (!model && options.modelPattern) {
|
|
1555
1886
|
const availableModels = modelRegistry.getAll();
|
|
1556
|
-
const matchPreferences =
|
|
1557
|
-
usageOrder: settings.getStorage()?.getModelUsageOrder(),
|
|
1558
|
-
};
|
|
1887
|
+
const matchPreferences = getModelMatchPreferences(settings);
|
|
1559
1888
|
const { model: resolved } = parseModelPattern(options.modelPattern, availableModels, matchPreferences, {
|
|
1560
1889
|
modelRegistry,
|
|
1561
1890
|
});
|
|
@@ -1574,12 +1903,30 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1574
1903
|
// Re-resolve the allowed set: extension factories above may have
|
|
1575
1904
|
// registered providers/models that weren't visible at startup.
|
|
1576
1905
|
const fallbackCandidates = await resolveAllowedModels(modelRegistry, settings, modelMatchPreferences);
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1906
|
+
// Prefer each provider's configured default model
|
|
1907
|
+
// (DEFAULT_MODEL_PER_PROVIDER) over raw catalog order. Without this the
|
|
1908
|
+
// first-run fallback picks whatever model sorts first in models.json for
|
|
1909
|
+
// the winning provider (e.g. anthropic's claude-3-5-sonnet-20240620)
|
|
1910
|
+
// instead of the intended provider default (claude-sonnet-4-6). Mirrors
|
|
1911
|
+
// findInitialModel's precedence.
|
|
1912
|
+
for (const [provider, defaultId] of Object.entries(DEFAULT_MODEL_PER_PROVIDER)) {
|
|
1913
|
+
const preferred = fallbackCandidates.find(
|
|
1914
|
+
candidate => candidate.provider === provider && candidate.id === defaultId,
|
|
1915
|
+
);
|
|
1916
|
+
if (preferred && hasModelAuth(preferred)) {
|
|
1917
|
+
model = preferred;
|
|
1580
1918
|
break;
|
|
1581
1919
|
}
|
|
1582
1920
|
}
|
|
1921
|
+
// Otherwise, first available model with a valid API key.
|
|
1922
|
+
if (!model) {
|
|
1923
|
+
for (const candidate of fallbackCandidates) {
|
|
1924
|
+
if (hasModelAuth(candidate)) {
|
|
1925
|
+
model = candidate;
|
|
1926
|
+
break;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1583
1930
|
if (model) {
|
|
1584
1931
|
if (modelFallbackMessage) {
|
|
1585
1932
|
modelFallbackMessage += `. Using ${model.provider}/${model.id}`;
|
|
@@ -1607,15 +1954,17 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1607
1954
|
// `ExtensionToolWrapper` installed below is the only place the per-tool approval gate runs.
|
|
1608
1955
|
// A conditional runner means the approval system silently disappears for users with no
|
|
1609
1956
|
// extensions, contradicting non-yolo `tools.approvalMode` settings without feedback.
|
|
1610
|
-
// (
|
|
1611
|
-
// is unreachable;
|
|
1612
|
-
//
|
|
1957
|
+
// (The builtin autoresearch extension is unconditionally loaded above, so this scenario
|
|
1958
|
+
// is unreachable; unconditional runner construction keeps that invariant explicit and
|
|
1959
|
+
// prevents future optional extensions from silently re-opening the hole.)
|
|
1613
1960
|
const extensionRunner: ExtensionRunner = new ExtensionRunner(
|
|
1614
1961
|
extensionsResult.extensions,
|
|
1615
1962
|
extensionsResult.runtime,
|
|
1616
1963
|
cwd,
|
|
1617
1964
|
sessionManager,
|
|
1618
1965
|
modelRegistry,
|
|
1966
|
+
() => (hasSession ? createSessionMemoryRuntimeContext(session, agentDir, cwd) : undefined),
|
|
1967
|
+
settings,
|
|
1619
1968
|
);
|
|
1620
1969
|
|
|
1621
1970
|
credentialDisabledTarget = extensionRunner;
|
|
@@ -1662,6 +2011,14 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1662
2011
|
for (const tool of wrappedExtensionTools) {
|
|
1663
2012
|
toolRegistry.set(tool.name, tool);
|
|
1664
2013
|
}
|
|
2014
|
+
if (deferMCPDiscoveryForUI && mcpManager) {
|
|
2015
|
+
for (const name of collectPendingMCPToolNames(options.toolNames, existingSession.selectedMCPToolNames)) {
|
|
2016
|
+
if (!toolRegistry.has(name)) {
|
|
2017
|
+
toolRegistry.set(name, createPendingMCPTool(name));
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
1665
2022
|
// Wrap every tool with `ExtensionToolWrapper` so the per-tool approval gate runs on every
|
|
1666
2023
|
// call site, regardless of whether any user extensions are loaded. See the runner-construction
|
|
1667
2024
|
// comment above for the safety invariant this enforces.
|
|
@@ -1689,7 +2046,10 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1689
2046
|
}
|
|
1690
2047
|
}
|
|
1691
2048
|
|
|
1692
|
-
|
|
2049
|
+
// `let`: the deferred MCP discovery closure upgrades these when the real
|
|
2050
|
+
// MCP tool count pushes `auto` past its threshold; `rebuildSystemPrompt`
|
|
2051
|
+
// below reads the live bindings.
|
|
2052
|
+
let effectiveDiscoveryMode = resolveEffectiveToolDiscoveryMode(
|
|
1693
2053
|
settings,
|
|
1694
2054
|
countToolsForAutoDiscovery(toolRegistry.keys()),
|
|
1695
2055
|
);
|
|
@@ -1700,7 +2060,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1700
2060
|
new ExtensionToolWrapper(wrapToolWithMetaNotice(searchTool), extensionRunner) as Tool,
|
|
1701
2061
|
);
|
|
1702
2062
|
}
|
|
1703
|
-
|
|
2063
|
+
let mcpDiscoveryEnabled = effectiveDiscoveryMode !== "off"; // back-compat: true when any discovery active
|
|
1704
2064
|
|
|
1705
2065
|
const reloadSshTool = async (): Promise<AgentTool | null> => {
|
|
1706
2066
|
if (!requestedToolNameSet.has("ssh")) return null;
|
|
@@ -1722,7 +2082,8 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1722
2082
|
});
|
|
1723
2083
|
|
|
1724
2084
|
const repeatToolDescriptions = settings.get("repeatToolDescriptions");
|
|
1725
|
-
const eagerTasks = settings.get("task.eager");
|
|
2085
|
+
const eagerTasks = settings.get("task.eager") !== "default";
|
|
2086
|
+
const eagerTasksAlways = settings.get("task.eager") === "always";
|
|
1726
2087
|
const intentField = $flag("PROMETHEUS_INTENT_TRACING", settings.get("tools.intentTracing"))
|
|
1727
2088
|
? INTENT_FIELD
|
|
1728
2089
|
: undefined;
|
|
@@ -1751,12 +2112,30 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1751
2112
|
const promptTools = buildSystemPromptToolMetadata(tools, {
|
|
1752
2113
|
search_tool_bm25: { description: renderSearchToolBm25Description(discoverableToolsForDesc) },
|
|
1753
2114
|
});
|
|
1754
|
-
const memoryBackend = resolveMemoryBackend(settings);
|
|
2115
|
+
const memoryBackend = await resolveMemoryBackend(settings);
|
|
1755
2116
|
const memoryInstructions = await memoryBackend.buildDeveloperInstructions(agentDir, settings, session);
|
|
1756
2117
|
|
|
1757
|
-
// Build combined append prompt: memory instructions +
|
|
2118
|
+
// Build combined append prompt: memory instructions + auto-learn guidance
|
|
2119
|
+
// + MCP server instructions. For UI sessions MCP discovery is deferred, so
|
|
2120
|
+
// `getServerInstructions()` is empty until the background connect completes;
|
|
2121
|
+
// the rebuild that `refreshMCPTools` triggers post-discovery then picks up
|
|
2122
|
+
// the now-connected servers' instructions, so they join the prompt for the
|
|
2123
|
+
// rest of the session.
|
|
1758
2124
|
const serverInstructions = mcpManager?.getServerInstructions();
|
|
1759
|
-
|
|
2125
|
+
// Drive guidance off the auto-learn BUILTINS that createTools actually built
|
|
2126
|
+
// (provenance, not just an active name): `builtInToolNames` excludes a
|
|
2127
|
+
// custom/extension tool that merely shares the name, and reflects the
|
|
2128
|
+
// session-start build — so a subagent that filtered them out, a mid-session
|
|
2129
|
+
// enable that never built them, or a same-named custom tool while auto-learn
|
|
2130
|
+
// is off all get no guidance.
|
|
2131
|
+
const autoLearnInstructions = buildAutoLearnInstructions({
|
|
2132
|
+
manageSkill: builtInToolNames.includes("manage_skill"),
|
|
2133
|
+
learn: builtInToolNames.includes("learn"),
|
|
2134
|
+
});
|
|
2135
|
+
const appendParts: string[] = [];
|
|
2136
|
+
if (memoryInstructions) appendParts.push(memoryInstructions);
|
|
2137
|
+
if (autoLearnInstructions) appendParts.push(autoLearnInstructions);
|
|
2138
|
+
let appendPrompt: string | undefined = appendParts.length > 0 ? appendParts.join("\n\n") : undefined;
|
|
1760
2139
|
if (serverInstructions && serverInstructions.size > 0) {
|
|
1761
2140
|
const parts: string[] = [];
|
|
1762
2141
|
if (appendPrompt) parts.push(appendPrompt);
|
|
@@ -1787,20 +2166,24 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1787
2166
|
mcpDiscoveryMode: hasDiscoverableTools,
|
|
1788
2167
|
mcpDiscoveryServerSummaries: discoverableToolSummary.servers.map(formatDiscoverableToolServerSummary),
|
|
1789
2168
|
eagerTasks,
|
|
2169
|
+
eagerTasksAlways,
|
|
2170
|
+
taskBatch: settings.get("task.batch"),
|
|
1790
2171
|
secretsEnabled,
|
|
1791
2172
|
workspaceTree: workspaceTreePromise,
|
|
1792
2173
|
memoryRootEnabled: memoryBackend.id === "local",
|
|
1793
2174
|
model: settings.get("includeModelInPrompt") ? getActiveModelString() : undefined,
|
|
2175
|
+
personality: agentKind === "sub" ? "none" : settings.get("personality"),
|
|
1794
2176
|
});
|
|
1795
2177
|
|
|
1796
2178
|
if (options.systemPrompt === undefined) {
|
|
1797
2179
|
return defaultPrompt;
|
|
1798
2180
|
}
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
2181
|
+
const customPrompt =
|
|
2182
|
+
typeof options.systemPrompt === "function"
|
|
2183
|
+
? options.systemPrompt(defaultPrompt.systemPrompt)
|
|
2184
|
+
: options.systemPrompt;
|
|
1802
2185
|
return {
|
|
1803
|
-
systemPrompt:
|
|
2186
|
+
systemPrompt: typeof customPrompt === "string" ? [customPrompt] : customPrompt,
|
|
1804
2187
|
};
|
|
1805
2188
|
};
|
|
1806
2189
|
|
|
@@ -1820,6 +2203,20 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1820
2203
|
) {
|
|
1821
2204
|
explicitlyRequestedToolNames.push("yield");
|
|
1822
2205
|
}
|
|
2206
|
+
// Auto-learn builtins are force-included into the registry by `createTools`
|
|
2207
|
+
// for enabled top-level sessions (tools/index.ts), but — like `yield` above —
|
|
2208
|
+
// an explicit `toolNames` list would otherwise drop them from the ACTIVE set,
|
|
2209
|
+
// leaving the nudge/guidance pointing at tools the model cannot call. Activate
|
|
2210
|
+
// exactly the builtins createTools built (`builtInToolNames` — provenance, so a
|
|
2211
|
+
// same-named custom/extension tool is never force-activated when auto-learn is
|
|
2212
|
+
// off) to keep guidance, controller, and the active set consistent.
|
|
2213
|
+
if (explicitlyRequestedToolNames) {
|
|
2214
|
+
for (const name of ["manage_skill", "learn"]) {
|
|
2215
|
+
if (builtInToolNames.includes(name) && !explicitlyRequestedToolNames.includes(name)) {
|
|
2216
|
+
explicitlyRequestedToolNames.push(name);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
1823
2220
|
const requestedToolNames = explicitlyRequestedToolNames ?? toolNamesFromRegistry;
|
|
1824
2221
|
const normalizedRequested = requestedToolNames.filter(name => toolRegistry.has(name));
|
|
1825
2222
|
const requestedToolNameSet = new Set(normalizedRequested);
|
|
@@ -1882,19 +2279,27 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1882
2279
|
// from the initial set unless they were explicitly requested or restored from persistence.
|
|
1883
2280
|
// The model finds them via search_tool_bm25 and activates them on demand.
|
|
1884
2281
|
if (effectiveDiscoveryMode === "all") {
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
//
|
|
1888
|
-
//
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
2282
|
+
// Tools a forced tool_choice will target must stay active, or the named
|
|
2283
|
+
// choice references a tool absent from the request (provider 400). Eager
|
|
2284
|
+
// todos force a named `todo` choice on the first turn. `task` is also kept
|
|
2285
|
+
// active under discovery-all when `task.eager` is not `default`, so eager delegation is
|
|
2286
|
+
// possible and the Eager Tasks prompt section renders, even though nothing
|
|
2287
|
+
// forces a `task` tool_choice.
|
|
2288
|
+
const forceActive = new Set<string>();
|
|
2289
|
+
if (settings.get("todo.eager") !== "default" && settings.get("todo.enabled") && toolRegistry.has("todo")) {
|
|
2290
|
+
forceActive.add("todo");
|
|
2291
|
+
}
|
|
2292
|
+
if (settings.get("task.eager") !== "default" && toolRegistry.has("task")) {
|
|
2293
|
+
forceActive.add("task");
|
|
2294
|
+
}
|
|
2295
|
+
initialToolNames = filterInitialToolsForDiscoveryAll(initialToolNames, {
|
|
2296
|
+
loadModeOf: name => toolRegistry.get(name)?.loadMode,
|
|
2297
|
+
essentialNames: new Set(computeEssentialBuiltinNames(settings)),
|
|
2298
|
+
explicitlyRequested: new Set(options.toolNames?.map(name => name.toLowerCase()) ?? []),
|
|
2299
|
+
// Back-compat: persisted activations live under selectedMCPToolNames today (built-in
|
|
2300
|
+
// activation persistence is a follow-up). MCP names won't collide with built-in names.
|
|
2301
|
+
restored: new Set(existingSession.selectedMCPToolNames),
|
|
2302
|
+
forceActive,
|
|
1898
2303
|
});
|
|
1899
2304
|
}
|
|
1900
2305
|
|
|
@@ -1905,7 +2310,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1905
2310
|
agentRegistry.register({
|
|
1906
2311
|
id: resolvedAgentId,
|
|
1907
2312
|
displayName: resolvedAgentDisplayName,
|
|
1908
|
-
kind:
|
|
2313
|
+
kind: agentKind,
|
|
1909
2314
|
parentId: options.parentTaskPrefix,
|
|
1910
2315
|
session: null,
|
|
1911
2316
|
sessionFile: sessionManager.getSessionFile() ?? null,
|
|
@@ -1963,10 +2368,36 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1963
2368
|
if (!obfuscator?.hasSecrets()) return converted;
|
|
1964
2369
|
return obfuscateMessages(obfuscator, converted);
|
|
1965
2370
|
};
|
|
2371
|
+
|
|
1966
2372
|
const transformContext = async (messages: AgentMessage[], _signal?: AbortSignal) => {
|
|
1967
2373
|
const withContext = await extensionRunner.emitContext(messages);
|
|
1968
2374
|
return wrapSteeringForModel(withContext);
|
|
1969
2375
|
};
|
|
2376
|
+
// Per-request provider-context transforms. Obfuscate FIRST so secrets are
|
|
2377
|
+
// redacted from text before snapcompact rasterizes it into PNG frames.
|
|
2378
|
+
// Both operate on the transient outgoing Context only — never persisted.
|
|
2379
|
+
const snapcompactSystemPromptMode = settings.get("snapcompact.systemPrompt");
|
|
2380
|
+
const snapcompactInline =
|
|
2381
|
+
snapcompactSystemPromptMode !== "none" || settings.get("snapcompact.toolResults")
|
|
2382
|
+
? new SnapcompactInlineTransformer(
|
|
2383
|
+
{
|
|
2384
|
+
renderSystemPrompt: snapcompactSystemPromptMode,
|
|
2385
|
+
renderToolResults: settings.get("snapcompact.toolResults"),
|
|
2386
|
+
shape: settings.get("snapcompact.shape"),
|
|
2387
|
+
},
|
|
2388
|
+
// Journal the tokens each imaged tool result keeps off the wire
|
|
2389
|
+
// (frames never reach session.jsonl, so this is their only trace).
|
|
2390
|
+
createSnapcompactSavingsRecorder(() => sessionManager.getSessionFile() ?? null),
|
|
2391
|
+
)
|
|
2392
|
+
: undefined;
|
|
2393
|
+
const transformProviderContext =
|
|
2394
|
+
obfuscator || snapcompactInline
|
|
2395
|
+
? (context: Context, transformModel: Model): Context => {
|
|
2396
|
+
let transformed = obfuscator ? obfuscateProviderContext(obfuscator, context) : context;
|
|
2397
|
+
if (snapcompactInline) transformed = snapcompactInline.transform(transformed, transformModel);
|
|
2398
|
+
return transformed;
|
|
2399
|
+
}
|
|
2400
|
+
: undefined;
|
|
1970
2401
|
const onPayload = async (payload: unknown, _model?: Model) => {
|
|
1971
2402
|
return await extensionRunner.emitBeforeProviderRequest(payload);
|
|
1972
2403
|
};
|
|
@@ -1998,13 +2429,16 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1998
2429
|
systemPrompt,
|
|
1999
2430
|
model,
|
|
2000
2431
|
thinkingLevel: toReasoningEffort(effectiveThinkingLevel),
|
|
2432
|
+
disableReasoning: shouldDisableReasoning(effectiveThinkingLevel),
|
|
2001
2433
|
tools: initialTools,
|
|
2002
2434
|
},
|
|
2003
2435
|
convertToLlm: convertToLlmFinal,
|
|
2004
2436
|
onPayload,
|
|
2005
2437
|
onResponse,
|
|
2006
2438
|
sessionId: providerSessionId,
|
|
2439
|
+
promptCacheKey: options.providerPromptCacheKey,
|
|
2007
2440
|
transformContext,
|
|
2441
|
+
transformProviderContext,
|
|
2008
2442
|
steeringMode: settings.get("steeringMode") ?? "one-at-a-time",
|
|
2009
2443
|
followUpMode: settings.get("followUpMode") ?? "one-at-a-time",
|
|
2010
2444
|
interruptMode: settings.get("interruptMode") ?? "immediate",
|
|
@@ -2020,9 +2454,15 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2020
2454
|
kimiApiFormat: settings.get("providers.kimiApiFormat") ?? "anthropic",
|
|
2021
2455
|
preferWebsockets: preferOpenAICodexWebsockets,
|
|
2022
2456
|
getToolContext: tc => toolContextStore.getContext(tc),
|
|
2023
|
-
getApiKey: async provider => {
|
|
2457
|
+
getApiKey: async (provider, ctx) => {
|
|
2024
2458
|
// Read agent.sessionId at call time so credential selection stays aligned
|
|
2025
2459
|
// with metadataResolver after /new, fork, resume, or branch switches.
|
|
2460
|
+
// Retry steps (ctx carries an auth error) drive the central a/b/c
|
|
2461
|
+
// policy — force-refresh the same account, then rotate to a sibling —
|
|
2462
|
+
// and may legitimately yield no key when every account is exhausted.
|
|
2463
|
+
if (ctx?.error !== undefined) {
|
|
2464
|
+
return createApiKeyResolver(modelRegistry, provider, { sessionId: agent.sessionId })(ctx);
|
|
2465
|
+
}
|
|
2026
2466
|
const key = await modelRegistry.getApiKeyForProvider(provider, agent.sessionId);
|
|
2027
2467
|
if (!key) {
|
|
2028
2468
|
throw new Error(`No API key found for provider "${provider}"`);
|
|
@@ -2036,40 +2476,6 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2036
2476
|
return streamSimple(streamModel, context, {
|
|
2037
2477
|
...streamOptions,
|
|
2038
2478
|
openrouterVariant: streamOptions?.openrouterVariant ?? openrouterVariant,
|
|
2039
|
-
onAuthError: async (provider, oldKey, error) => {
|
|
2040
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
2041
|
-
// streamSimple invokes this for both 401 auth failures AND
|
|
2042
|
-
// rotatable usage-limit errors (Codex usage_limit_reached,
|
|
2043
|
-
// Anthropic usage_limit_reached, etc.). The two need
|
|
2044
|
-
// different storage actions: a real 401 means the credential
|
|
2045
|
-
// is bad and should be marked suspect; a usage limit just
|
|
2046
|
-
// means this account is parked until reset and should be
|
|
2047
|
-
// temporarily blocked so a sibling can pick the request up.
|
|
2048
|
-
if (isUsageLimitError(message)) {
|
|
2049
|
-
const retryAfterMs = extractRetryHint(undefined, message);
|
|
2050
|
-
const switched = await modelRegistry.authStorage.markUsageLimitReached(provider, agent.sessionId, {
|
|
2051
|
-
retryAfterMs,
|
|
2052
|
-
signal: streamOptions?.signal,
|
|
2053
|
-
});
|
|
2054
|
-
logger.debug("Retrying provider request after usage-limit block", {
|
|
2055
|
-
provider,
|
|
2056
|
-
switched,
|
|
2057
|
-
retryAfterMs,
|
|
2058
|
-
error: message,
|
|
2059
|
-
});
|
|
2060
|
-
if (!switched) return undefined;
|
|
2061
|
-
return modelRegistry.getApiKeyForProvider(provider, agent.sessionId);
|
|
2062
|
-
}
|
|
2063
|
-
await modelRegistry.authStorage.invalidateCredentialMatching(provider, oldKey, {
|
|
2064
|
-
signal: streamOptions?.signal,
|
|
2065
|
-
sessionId: agent.sessionId,
|
|
2066
|
-
});
|
|
2067
|
-
logger.debug("Retrying provider request after credential invalidation", {
|
|
2068
|
-
provider,
|
|
2069
|
-
error: message,
|
|
2070
|
-
});
|
|
2071
|
-
return modelRegistry.getApiKeyForProvider(provider, agent.sessionId);
|
|
2072
|
-
},
|
|
2073
2479
|
});
|
|
2074
2480
|
},
|
|
2075
2481
|
cursorExecHandlers,
|
|
@@ -2119,6 +2525,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2119
2525
|
thinkingLevel: autoThinking ? AUTO_THINKING : effectiveThinkingLevel,
|
|
2120
2526
|
sessionManager,
|
|
2121
2527
|
settings,
|
|
2528
|
+
autoApprove: options.autoApprove,
|
|
2122
2529
|
evalKernelOwnerId,
|
|
2123
2530
|
// Defined only for top-level sessions (creation is gated above).
|
|
2124
2531
|
// AgentSession uses this to decide whether it may dispose the global
|
|
@@ -2165,7 +2572,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2165
2572
|
ttsrManager,
|
|
2166
2573
|
obfuscator,
|
|
2167
2574
|
agentId: resolvedAgentId,
|
|
2168
|
-
|
|
2575
|
+
agentKind,
|
|
2169
2576
|
providerSessionId: options.providerSessionId,
|
|
2170
2577
|
parentEvalSessionId: options.parentEvalSessionId,
|
|
2171
2578
|
});
|
|
@@ -2179,25 +2586,41 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2179
2586
|
session.yieldQueue.register<McpNotificationEntry>("mcp-notification", {
|
|
2180
2587
|
build: buildMcpNotificationBatchMessage,
|
|
2181
2588
|
});
|
|
2589
|
+
session.yieldQueue.register<DeferredDiagnosticsEntry>(LSP_LATE_DIAGNOSTIC_MESSAGE_TYPE, {
|
|
2590
|
+
isStale: entry => entry.isStale(),
|
|
2591
|
+
build: buildLateDiagnosticsBatchMessage,
|
|
2592
|
+
});
|
|
2182
2593
|
|
|
2183
2594
|
// Attach the live session to the pre-registered ref so peers can route IRC
|
|
2184
2595
|
// messages here. Refresh sessionFile in case it was unavailable at pre-register
|
|
2185
|
-
// time. The dispose wrapper below unregisters on teardown.
|
|
2596
|
+
// time. The dispose wrapper below unregisters on teardown (unless parked).
|
|
2186
2597
|
agentRegistry.attachSession(resolvedAgentId, session, sessionManager.getSessionFile() ?? null);
|
|
2187
2598
|
{
|
|
2188
2599
|
const originalDispose = session.dispose.bind(session);
|
|
2189
2600
|
session.dispose = async () => {
|
|
2190
2601
|
try {
|
|
2602
|
+
// Reject new session work (Python/eval starts) the moment disposal
|
|
2603
|
+
// begins — the lifecycle await below opens an async gap before
|
|
2604
|
+
// AgentSession.dispose() would otherwise set its guards.
|
|
2605
|
+
session.beginDispose();
|
|
2606
|
+
if (agentKind === "main") {
|
|
2607
|
+
// Top-level teardown owns the global agent lifecycle: park timers,
|
|
2608
|
+
// adopted subagent sessions, revivers. Tear it down while shared
|
|
2609
|
+
// resources (kernels, MCP, LSP) are still live. Subagent disposal
|
|
2610
|
+
// must NOT touch the global lifecycle.
|
|
2611
|
+
await AgentLifecycleManager.global().dispose();
|
|
2612
|
+
}
|
|
2191
2613
|
await originalDispose();
|
|
2192
2614
|
} finally {
|
|
2193
|
-
|
|
2615
|
+
unregisterUnlessParked();
|
|
2194
2616
|
unsubscribeCredentialDisabled?.();
|
|
2195
2617
|
}
|
|
2196
2618
|
};
|
|
2197
2619
|
}
|
|
2198
2620
|
|
|
2199
2621
|
if (model?.api === "openai-codex-responses") {
|
|
2200
|
-
|
|
2622
|
+
// `.api` equality doesn't narrow the generic; the guard makes this cast sound.
|
|
2623
|
+
const codexModel = model as Model<"openai-codex-responses">;
|
|
2201
2624
|
const codexTransport = getOpenAICodexTransportDetails(codexModel, {
|
|
2202
2625
|
sessionId: providerSessionId,
|
|
2203
2626
|
baseUrl: codexModel.baseUrl,
|
|
@@ -2228,12 +2651,17 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2228
2651
|
}
|
|
2229
2652
|
|
|
2230
2653
|
// Start LSP warmup in the background so startup does not block on language server initialization.
|
|
2231
|
-
//
|
|
2232
|
-
//
|
|
2233
|
-
//
|
|
2234
|
-
//
|
|
2654
|
+
// With `lsp.lazy` (the default) the warmup is skipped: recognized servers are still discovered and
|
|
2655
|
+
// surfaced in the UI as "available", but cold-start on first use — the lsp tool or an edit/write
|
|
2656
|
+
// touching a matching file type — through `getOrCreateClient`.
|
|
2657
|
+
// Print/script invocations (`hasUI=false`) skip it regardless: they don't render the warmup status
|
|
2658
|
+
// indicator AND typically finish before LSP servers would have stabilized — warming them just spends
|
|
2659
|
+
// CPU parsing big `initialize` responses concurrently with the LLM stream consumer, jittering
|
|
2660
|
+
// perceived latency.
|
|
2235
2661
|
let lspServers: CreateAgentSessionResult["lspServers"];
|
|
2236
|
-
if (enableLsp && options.hasUI && settings.get("lsp.
|
|
2662
|
+
if (enableLsp && options.hasUI && settings.get("lsp.lazy")) {
|
|
2663
|
+
lspServers = discoverStartupLspServers(cwd, "available");
|
|
2664
|
+
} else if (enableLsp && options.hasUI) {
|
|
2237
2665
|
lspServers = discoverStartupLspServers(cwd);
|
|
2238
2666
|
if (lspServers.length > 0) {
|
|
2239
2667
|
void (async () => {
|
|
@@ -2269,25 +2697,64 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2269
2697
|
}
|
|
2270
2698
|
}
|
|
2271
2699
|
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2700
|
+
const startMemoryBackend = async () => {
|
|
2701
|
+
const memoryBackend = await resolveMemoryBackend(settings);
|
|
2702
|
+
await memoryBackend.start({
|
|
2703
|
+
session,
|
|
2704
|
+
settings,
|
|
2705
|
+
modelRegistry,
|
|
2706
|
+
agentDir,
|
|
2707
|
+
taskDepth,
|
|
2708
|
+
parentHindsightSessionState: options.parentHindsightSessionState,
|
|
2709
|
+
parentMnemopiSessionState: options.parentMnemopiSessionState,
|
|
2710
|
+
});
|
|
2711
|
+
};
|
|
2712
|
+
|
|
2713
|
+
// Auto-learn can immediately trigger a synthetic capture turn after the
|
|
2714
|
+
// first real stop. When a memory backend is selected, install that backend's
|
|
2715
|
+
// per-session state first so the capture turn's `learn` tool observes the
|
|
2716
|
+
// same initialized state as normal memory tools. Other sessions keep memory
|
|
2717
|
+
// startup in the background to preserve the existing startup profile.
|
|
2718
|
+
//
|
|
2719
|
+
// Gated on `autolearn.enabled` to match the tools: `createTools` builds the
|
|
2720
|
+
// `learn`/`manage_skill` registry ONCE at session start and no settings
|
|
2721
|
+
// change rebuilds it, so installing the controller while disabled would let a
|
|
2722
|
+
// mid-session enable fire a nudge pointing at tools the session never built.
|
|
2723
|
+
// Activation is therefore a session-start decision for BOTH the controller
|
|
2724
|
+
// and the tools; the fire-time re-check in `#onAgentEnd` still handles a
|
|
2725
|
+
// mid-session DISABLE. The subscription lives for the session's lifetime; the
|
|
2726
|
+
// reference is intentionally discarded (the listener retains it).
|
|
2727
|
+
if (settings.get("autolearn.enabled") && taskDepth === 0) {
|
|
2728
|
+
await logger.time("startMemoryStartupTask", startMemoryBackend);
|
|
2729
|
+
new AutoLearnController({ session, settings });
|
|
2730
|
+
} else {
|
|
2731
|
+
void logger.time("startMemoryStartupTask", startMemoryBackend);
|
|
2732
|
+
}
|
|
2285
2733
|
|
|
2286
2734
|
// Wire MCP manager callbacks to session for reactive tool updates.
|
|
2287
2735
|
// Skip when reusing a parent's manager — the parent owns the callbacks.
|
|
2288
2736
|
if (mcpManager && !options.mcpManager) {
|
|
2289
2737
|
mcpManager.setOnToolsChanged(tools => {
|
|
2290
|
-
void
|
|
2738
|
+
void (async () => {
|
|
2739
|
+
try {
|
|
2740
|
+
await session.refreshMCPTools(
|
|
2741
|
+
tools,
|
|
2742
|
+
deferMCPDiscoveryForUI && !mcpDiscoveryEnabled && options.toolNames === undefined
|
|
2743
|
+
? { activateAll: true }
|
|
2744
|
+
: undefined,
|
|
2745
|
+
);
|
|
2746
|
+
if (deferMCPDiscoveryForUI && !mcpDiscoveryEnabled && explicitlyRequestedMCPToolNames.length > 0) {
|
|
2747
|
+
await session.setActiveToolsByName([
|
|
2748
|
+
...session.getActiveToolNames(),
|
|
2749
|
+
...explicitlyRequestedMCPToolNames,
|
|
2750
|
+
]);
|
|
2751
|
+
}
|
|
2752
|
+
} catch (error) {
|
|
2753
|
+
logger.warn("MCP tool refresh failed", {
|
|
2754
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
})();
|
|
2291
2758
|
});
|
|
2292
2759
|
// Wire prompt refresh → rebuild MCP prompt slash commands
|
|
2293
2760
|
mcpManager.setOnPromptsChanged(serverName => {
|
|
@@ -2320,6 +2787,12 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2320
2787
|
});
|
|
2321
2788
|
}
|
|
2322
2789
|
|
|
2790
|
+
startDeferredMCPDiscovery?.(session, {
|
|
2791
|
+
mcpDiscoveryEnabled,
|
|
2792
|
+
explicitlyRequestedMCPToolNames,
|
|
2793
|
+
activateAllMCPTools: !mcpDiscoveryEnabled && options.toolNames === undefined,
|
|
2794
|
+
});
|
|
2795
|
+
|
|
2323
2796
|
return {
|
|
2324
2797
|
session,
|
|
2325
2798
|
extensionsResult,
|
|
@@ -2338,7 +2811,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2338
2811
|
if (hasSession) {
|
|
2339
2812
|
await session.dispose();
|
|
2340
2813
|
} else {
|
|
2341
|
-
if (hasRegistered)
|
|
2814
|
+
if (hasRegistered) unregisterUnlessParked();
|
|
2342
2815
|
if (asyncJobManager) {
|
|
2343
2816
|
if (AsyncJobManager.instance() === asyncJobManager) {
|
|
2344
2817
|
AsyncJobManager.setInstance(undefined);
|