oma-coding-agent 1.1.4
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 +12164 -0
- package/README.md +35 -0
- package/dist/cli.js +18266 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +104 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/extensions/README.md +142 -0
- package/examples/extensions/api-demo.ts +79 -0
- package/examples/extensions/chalk-logger.ts +25 -0
- package/examples/extensions/hello.ts +31 -0
- package/examples/extensions/pirate.ts +43 -0
- package/examples/extensions/plan-mode.ts +549 -0
- package/examples/extensions/reload-runtime.ts +38 -0
- package/examples/extensions/thinking-note.ts +13 -0
- package/examples/extensions/tools.ts +145 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +17 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +48 -0
- package/examples/hooks/confirm-destructive.ts +58 -0
- package/examples/hooks/custom-compaction.ts +115 -0
- package/examples/hooks/dirty-repo-guard.ts +51 -0
- package/examples/hooks/file-trigger.ts +40 -0
- package/examples/hooks/git-checkpoint.ts +52 -0
- package/examples/hooks/handoff.ts +149 -0
- package/examples/hooks/permission-gate.ts +33 -0
- package/examples/hooks/protected-paths.ts +29 -0
- package/examples/hooks/qna.ts +118 -0
- package/examples/hooks/status-line.ts +39 -0
- package/examples/sdk/01-minimal.ts +21 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +46 -0
- package/examples/sdk/04-skills.ts +43 -0
- package/examples/sdk/06-extensions.ts +82 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +35 -0
- package/examples/sdk/08-prompt-templates.ts +41 -0
- package/examples/sdk/08-slash-commands.ts +46 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +54 -0
- package/examples/sdk/11-sessions.ts +47 -0
- package/examples/sdk/12-redis-sessions.ts +54 -0
- package/examples/sdk/13-sql-sessions.ts +61 -0
- package/examples/sdk/README.md +172 -0
- package/package.json +573 -0
- package/scripts/bench-guard.ts +71 -0
- package/scripts/build-binary.ts +108 -0
- package/scripts/bundle-dist.ts +110 -0
- package/scripts/embed-mupdf-wasm.ts +67 -0
- package/scripts/format-prompts.ts +68 -0
- package/scripts/generate-docs-index.ts +56 -0
- package/scripts/generate-share-viewer.ts +34 -0
- package/scripts/measure-prompt-tokens.ts +63 -0
- package/scripts/omp +42 -0
- package/scripts/omp.ts +19 -0
- package/src/advisor/__tests__/advisor.test.ts +915 -0
- package/src/advisor/advise-tool.ts +165 -0
- package/src/advisor/index.ts +4 -0
- package/src/advisor/runtime.ts +270 -0
- package/src/advisor/transcript-recorder.ts +136 -0
- package/src/advisor/watchdog.ts +83 -0
- package/src/async/index.ts +1 -0
- package/src/async/job-manager.ts +674 -0
- package/src/auto-thinking/classifier.ts +190 -0
- package/src/autolearn/controller.ts +139 -0
- package/src/autolearn/managed-skills.ts +255 -0
- package/src/autoresearch/command-resume.md +14 -0
- package/src/autoresearch/dashboard.ts +436 -0
- package/src/autoresearch/git.ts +319 -0
- package/src/autoresearch/helpers.ts +218 -0
- package/src/autoresearch/index.ts +536 -0
- package/src/autoresearch/prompt-setup.md +43 -0
- package/src/autoresearch/prompt.md +103 -0
- package/src/autoresearch/resume-message.md +10 -0
- package/src/autoresearch/state.ts +273 -0
- package/src/autoresearch/storage.ts +700 -0
- package/src/autoresearch/tools/init-experiment.ts +269 -0
- package/src/autoresearch/tools/log-experiment.ts +521 -0
- package/src/autoresearch/tools/run-experiment.ts +407 -0
- package/src/autoresearch/tools/update-notes.ts +109 -0
- package/src/autoresearch/types.ts +168 -0
- package/src/capability/context-file.ts +44 -0
- package/src/capability/extension-module.ts +34 -0
- package/src/capability/extension.ts +47 -0
- package/src/capability/fs.ts +117 -0
- package/src/capability/hook.ts +40 -0
- package/src/capability/index.ts +436 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +76 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule-buckets.ts +66 -0
- package/src/capability/rule.ts +261 -0
- package/src/capability/settings.ts +34 -0
- package/src/capability/skill.ts +63 -0
- package/src/capability/slash-command.ts +40 -0
- package/src/capability/ssh.ts +41 -0
- package/src/capability/system-prompt.ts +34 -0
- package/src/capability/tool.ts +38 -0
- package/src/capability/types.ts +168 -0
- package/src/cli/agents-cli.ts +138 -0
- package/src/cli/args.ts +361 -0
- package/src/cli/auth-broker-cli.ts +893 -0
- package/src/cli/auth-gateway-cli.ts +608 -0
- package/src/cli/bench-cli.ts +552 -0
- package/src/cli/classify-install-target.ts +76 -0
- package/src/cli/claude-trace-cli.ts +795 -0
- package/src/cli/commands/init-xdg.ts +27 -0
- package/src/cli/completion-gen.ts +550 -0
- package/src/cli/config-cli.ts +418 -0
- package/src/cli/dry-balance-cli.ts +858 -0
- package/src/cli/extension-flags.ts +48 -0
- package/src/cli/file-processor.ts +133 -0
- package/src/cli/flag-tables.ts +280 -0
- 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/grep-cli.ts +160 -0
- package/src/cli/grievances-cli.ts +256 -0
- package/src/cli/initial-message.ts +58 -0
- package/src/cli/models-cli.ts +427 -0
- package/src/cli/plugin-cli.ts +996 -0
- package/src/cli/profile-alias.ts +338 -0
- package/src/cli/profile-bootstrap.ts +243 -0
- package/src/cli/read-cli.ts +57 -0
- package/src/cli/session-picker.ts +80 -0
- package/src/cli/setup-cli.ts +332 -0
- package/src/cli/setup-model-picker.ts +43 -0
- package/src/cli/shell-cli.ts +176 -0
- package/src/cli/ssh-cli.ts +179 -0
- package/src/cli/startup-cwd.ts +58 -0
- package/src/cli/stats-cli.ts +229 -0
- package/src/cli/tiny-models-cli.ts +127 -0
- package/src/cli/ttsr-cli.ts +995 -0
- package/src/cli/update-cli.ts +671 -0
- package/src/cli/usage-cli.ts +774 -0
- package/src/cli/web-search-cli.ts +132 -0
- package/src/cli/worktree-cli.ts +291 -0
- package/src/cli-commands.ts +85 -0
- package/src/cli.ts +326 -0
- package/src/collab/crypto.ts +63 -0
- package/src/collab/guest.ts +450 -0
- package/src/collab/host.ts +577 -0
- package/src/collab/protocol.ts +274 -0
- package/src/collab/relay-client.ts +216 -0
- package/src/commands/acp.ts +24 -0
- package/src/commands/agents.ts +57 -0
- package/src/commands/auth-broker.ts +99 -0
- package/src/commands/auth-gateway.ts +69 -0
- package/src/commands/bench.ts +42 -0
- package/src/commands/commit.ts +46 -0
- package/src/commands/complete.ts +66 -0
- package/src/commands/completions.ts +60 -0
- package/src/commands/config.ts +51 -0
- package/src/commands/dry-balance.ts +43 -0
- package/src/commands/gallery.ts +52 -0
- package/src/commands/grep.ts +48 -0
- package/src/commands/grievances.ts +51 -0
- package/src/commands/install.ts +107 -0
- package/src/commands/join.ts +39 -0
- package/src/commands/launch.ts +182 -0
- package/src/commands/models.ts +61 -0
- package/src/commands/plugin.ts +78 -0
- package/src/commands/read.ts +38 -0
- package/src/commands/say.ts +102 -0
- package/src/commands/setup.ts +67 -0
- package/src/commands/shell.ts +29 -0
- package/src/commands/ssh.ts +60 -0
- package/src/commands/stats.ts +29 -0
- package/src/commands/tiny-models.ts +36 -0
- package/src/commands/token.ts +108 -0
- package/src/commands/ttsr.ts +125 -0
- package/src/commands/update.ts +21 -0
- package/src/commands/usage.ts +43 -0
- package/src/commands/web-search.ts +42 -0
- package/src/commands/worktree.ts +56 -0
- package/src/commit/agentic/agent.ts +318 -0
- package/src/commit/agentic/fallback.ts +96 -0
- package/src/commit/agentic/index.ts +355 -0
- package/src/commit/agentic/prompts/analyze-file.md +22 -0
- package/src/commit/agentic/prompts/session-user.md +25 -0
- package/src/commit/agentic/prompts/split-confirm.md +1 -0
- package/src/commit/agentic/prompts/system.md +38 -0
- package/src/commit/agentic/state.ts +60 -0
- package/src/commit/agentic/tools/analyze-file.ts +149 -0
- package/src/commit/agentic/tools/git-file-diff.ts +191 -0
- package/src/commit/agentic/tools/git-hunk.ts +52 -0
- package/src/commit/agentic/tools/git-overview.ts +81 -0
- package/src/commit/agentic/tools/index.ts +54 -0
- package/src/commit/agentic/tools/propose-changelog.ts +147 -0
- package/src/commit/agentic/tools/propose-commit.ts +109 -0
- package/src/commit/agentic/tools/recent-commits.ts +81 -0
- package/src/commit/agentic/tools/schemas.ts +11 -0
- package/src/commit/agentic/tools/split-commit.ts +241 -0
- package/src/commit/agentic/topo-sort.ts +44 -0
- package/src/commit/agentic/trivial.ts +51 -0
- package/src/commit/agentic/validation.ts +183 -0
- package/src/commit/analysis/conventional.ts +64 -0
- package/src/commit/analysis/index.ts +4 -0
- package/src/commit/analysis/scope.ts +242 -0
- package/src/commit/analysis/summary.ts +107 -0
- package/src/commit/analysis/validation.ts +66 -0
- package/src/commit/changelog/detect.ts +40 -0
- package/src/commit/changelog/generate.ts +101 -0
- package/src/commit/changelog/index.ts +234 -0
- package/src/commit/changelog/parse.ts +44 -0
- package/src/commit/cli.ts +85 -0
- package/src/commit/git/diff.ts +148 -0
- package/src/commit/index.ts +5 -0
- package/src/commit/map-reduce/index.ts +69 -0
- package/src/commit/map-reduce/map-phase.ts +193 -0
- package/src/commit/map-reduce/reduce-phase.ts +49 -0
- package/src/commit/map-reduce/utils.ts +9 -0
- package/src/commit/message.ts +11 -0
- package/src/commit/model-selection.ts +89 -0
- package/src/commit/pipeline.ts +243 -0
- package/src/commit/prompts/analysis-system.md +148 -0
- package/src/commit/prompts/analysis-user.md +38 -0
- package/src/commit/prompts/changelog-system.md +50 -0
- package/src/commit/prompts/changelog-user.md +18 -0
- package/src/commit/prompts/file-observer-system.md +24 -0
- package/src/commit/prompts/file-observer-user.md +8 -0
- package/src/commit/prompts/reduce-system.md +50 -0
- package/src/commit/prompts/reduce-user.md +17 -0
- package/src/commit/prompts/summary-retry.md +3 -0
- package/src/commit/prompts/summary-system.md +38 -0
- package/src/commit/prompts/summary-user.md +13 -0
- package/src/commit/prompts/types-description.md +2 -0
- package/src/commit/shared-llm.ts +70 -0
- package/src/commit/types.ts +118 -0
- package/src/commit/utils/exclusions.ts +42 -0
- package/src/commit/utils.ts +58 -0
- package/src/config/api-key-resolver.ts +67 -0
- package/src/config/append-only-context-mode.ts +76 -0
- package/src/config/config-file.ts +315 -0
- package/src/config/file-lock.ts +164 -0
- package/src/config/keybindings.ts +634 -0
- package/src/config/mcp-schema.json +238 -0
- package/src/config/model-discovery.ts +589 -0
- package/src/config/model-registry.ts +2260 -0
- package/src/config/model-resolver.ts +1819 -0
- package/src/config/model-roles.ts +99 -0
- package/src/config/models-config-schema.ts +266 -0
- package/src/config/models-config.ts +131 -0
- package/src/config/prompt-templates.ts +185 -0
- package/src/config/resolve-config-value.ts +94 -0
- package/src/config/settings-schema.ts +4740 -0
- package/src/config/settings.ts +1243 -0
- package/src/config.ts +242 -0
- package/src/cursor.ts +340 -0
- package/src/dap/client.ts +760 -0
- package/src/dap/config.ts +189 -0
- package/src/dap/defaults.json +212 -0
- package/src/dap/index.ts +4 -0
- package/src/dap/session.ts +1441 -0
- package/src/dap/types.ts +610 -0
- package/src/debug/index.ts +559 -0
- package/src/debug/log-formatting.ts +58 -0
- package/src/debug/log-viewer.ts +908 -0
- package/src/debug/profiler.ts +162 -0
- package/src/debug/protocol-probe.ts +267 -0
- package/src/debug/raw-sse-buffer.ts +294 -0
- package/src/debug/raw-sse.ts +292 -0
- package/src/debug/remote-debugger.ts +151 -0
- package/src/debug/report-bundle.ts +375 -0
- package/src/debug/system-info.ts +111 -0
- package/src/debug/terminal-info.ts +124 -0
- package/src/discovery/agents-md.ts +67 -0
- package/src/discovery/agents.ts +230 -0
- package/src/discovery/at-imports.ts +273 -0
- package/src/discovery/builtin-defaults.ts +39 -0
- package/src/discovery/builtin-rules/index.ts +63 -0
- package/src/discovery/builtin-rules/low-end/no-hallucinated-apis.md +14 -0
- package/src/discovery/builtin-rules/low-end/no-hallucinated-paths.md +14 -0
- package/src/discovery/builtin-rules/low-end/no-premature-completion.md +14 -0
- package/src/discovery/builtin-rules/rs-box-leak.md +48 -0
- package/src/discovery/builtin-rules/rs-future-prelude.md +23 -0
- package/src/discovery/builtin-rules/rs-lazylock.md +51 -0
- package/src/discovery/builtin-rules/rs-match-ergonomics.md +67 -0
- package/src/discovery/builtin-rules/rs-parking-lot.md +44 -0
- package/src/discovery/builtin-rules/rs-result-type.md +19 -0
- package/src/discovery/builtin-rules/ts-bare-catch.md +38 -0
- package/src/discovery/builtin-rules/ts-import-type.md +42 -0
- package/src/discovery/builtin-rules/ts-no-any.md +65 -0
- package/src/discovery/builtin-rules/ts-no-deprecated-leftovers.md +44 -0
- package/src/discovery/builtin-rules/ts-no-dynamic-import.md +39 -0
- package/src/discovery/builtin-rules/ts-no-inline-cast-access.md +55 -0
- package/src/discovery/builtin-rules/ts-no-return-type.md +44 -0
- package/src/discovery/builtin-rules/ts-no-test-timers.md +55 -0
- package/src/discovery/builtin-rules/ts-no-tiny-functions.md +51 -0
- package/src/discovery/builtin-rules/ts-promise-with-resolvers.md +65 -0
- package/src/discovery/builtin-rules/ts-redundant-clear-guard.md +75 -0
- package/src/discovery/builtin-rules/ts-set-map.md +28 -0
- package/src/discovery/builtin.ts +934 -0
- package/src/discovery/claude-plugins.ts +386 -0
- package/src/discovery/claude.ts +584 -0
- package/src/discovery/cline.ts +83 -0
- package/src/discovery/codex.ts +522 -0
- package/src/discovery/cursor.ts +220 -0
- package/src/discovery/gemini.ts +383 -0
- package/src/discovery/github.ts +337 -0
- package/src/discovery/helpers.ts +1092 -0
- package/src/discovery/index.ts +81 -0
- package/src/discovery/mcp-json.ts +172 -0
- package/src/discovery/omp-extension-roots.ts +190 -0
- package/src/discovery/omp-plugins.ts +383 -0
- package/src/discovery/opencode.ts +398 -0
- package/src/discovery/plugin-dir-roots.ts +28 -0
- package/src/discovery/ssh.ts +153 -0
- package/src/discovery/substitute-plugin-root.ts +29 -0
- package/src/discovery/vscode.ts +105 -0
- package/src/discovery/windsurf.ts +147 -0
- package/src/edit/apply-patch/index.ts +87 -0
- package/src/edit/apply-patch/parser.ts +174 -0
- package/src/edit/diff.ts +999 -0
- package/src/edit/file-snapshot-store.ts +143 -0
- package/src/edit/hashline/block-resolver.ts +33 -0
- package/src/edit/hashline/diff.ts +290 -0
- package/src/edit/hashline/execute.ts +237 -0
- package/src/edit/hashline/filesystem.ts +130 -0
- package/src/edit/hashline/index.ts +5 -0
- package/src/edit/hashline/noop-loop-guard.ts +99 -0
- package/src/edit/hashline/params.ts +19 -0
- package/src/edit/index.ts +620 -0
- package/src/edit/modes/apply-patch.lark +19 -0
- package/src/edit/modes/apply-patch.ts +53 -0
- package/src/edit/modes/patch.ts +1888 -0
- package/src/edit/modes/replace.ts +1133 -0
- package/src/edit/normalize.ts +345 -0
- package/src/edit/notebook.ts +242 -0
- package/src/edit/read-file.ts +25 -0
- package/src/edit/renderer.ts +823 -0
- package/src/edit/streaming.ts +517 -0
- package/src/eval/__tests__/agent-bridge.test.ts +769 -0
- package/src/eval/__tests__/bridge-timeout.test.ts +64 -0
- package/src/eval/__tests__/budget-bridge.test.ts +69 -0
- 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__/idle-timeout.test.ts +80 -0
- package/src/eval/__tests__/js-context-manager.test.ts +291 -0
- package/src/eval/__tests__/kernel-spawn.test.ts +103 -0
- package/src/eval/__tests__/prelude-agent.test.ts +73 -0
- package/src/eval/agent-bridge.ts +319 -0
- package/src/eval/backend.ts +71 -0
- package/src/eval/bridge-timeout.ts +44 -0
- package/src/eval/budget-bridge.ts +48 -0
- package/src/eval/completion-bridge.ts +211 -0
- package/src/eval/concurrency-bridge.ts +34 -0
- package/src/eval/idle-timeout.ts +91 -0
- package/src/eval/index.ts +4 -0
- package/src/eval/js/context-manager.ts +621 -0
- package/src/eval/js/executor.ts +173 -0
- package/src/eval/js/index.ts +51 -0
- package/src/eval/js/shared/helpers.ts +283 -0
- package/src/eval/js/shared/indirect-eval.ts +30 -0
- package/src/eval/js/shared/local-module-loader.ts +342 -0
- package/src/eval/js/shared/prelude.ts +2 -0
- package/src/eval/js/shared/prelude.txt +307 -0
- package/src/eval/js/shared/rewrite-imports.ts +532 -0
- package/src/eval/js/shared/runtime.ts +580 -0
- package/src/eval/js/shared/types.ts +18 -0
- package/src/eval/js/tool-bridge.ts +163 -0
- package/src/eval/js/worker-core.ts +151 -0
- package/src/eval/js/worker-entry.ts +37 -0
- package/src/eval/js/worker-protocol.ts +47 -0
- package/src/eval/py/__tests__/prelude.test.ts +19 -0
- package/src/eval/py/display.ts +71 -0
- package/src/eval/py/executor.ts +742 -0
- package/src/eval/py/index.ts +68 -0
- package/src/eval/py/kernel.ts +748 -0
- package/src/eval/py/prelude.py +683 -0
- package/src/eval/py/prelude.ts +3 -0
- package/src/eval/py/runner.py +1177 -0
- package/src/eval/py/runtime.ts +276 -0
- package/src/eval/py/spawn-options.ts +126 -0
- package/src/eval/py/tool-bridge.ts +182 -0
- package/src/eval/session-id.ts +8 -0
- package/src/eval/types.ts +48 -0
- package/src/exa/index.ts +2 -0
- package/src/exa/mcp-client.ts +370 -0
- package/src/exa/types.ts +69 -0
- package/src/exec/bash-executor.ts +434 -0
- package/src/exec/exec.ts +53 -0
- package/src/exec/non-interactive-env.ts +119 -0
- package/src/export/custom-share.ts +65 -0
- package/src/export/html/index.ts +266 -0
- package/src/export/html/share-loader.js +102 -0
- package/src/export/html/template.css +1337 -0
- package/src/export/html/template.html +49 -0
- package/src/export/html/template.js +1626 -0
- package/src/export/html/tool-views.generated.js +37 -0
- package/src/export/html/vendor/highlight.min.js +1213 -0
- package/src/export/html/vendor/marked.min.js +6 -0
- package/src/export/share.ts +268 -0
- package/src/export/ttsr.ts +583 -0
- package/src/extensibility/custom-commands/bundled/ci-green/index.ts +54 -0
- package/src/extensibility/custom-commands/bundled/review/index.ts +698 -0
- package/src/extensibility/custom-commands/index.ts +2 -0
- package/src/extensibility/custom-commands/loader.ts +242 -0
- package/src/extensibility/custom-commands/types.ts +119 -0
- package/src/extensibility/custom-tools/index.ts +7 -0
- package/src/extensibility/custom-tools/loader.ts +268 -0
- package/src/extensibility/custom-tools/types.ts +277 -0
- package/src/extensibility/custom-tools/wrapper.ts +47 -0
- package/src/extensibility/extensions/compact-handler.ts +40 -0
- package/src/extensibility/extensions/get-commands-handler.ts +78 -0
- package/src/extensibility/extensions/index.ts +16 -0
- package/src/extensibility/extensions/loader.ts +587 -0
- package/src/extensibility/extensions/model-api.ts +41 -0
- package/src/extensibility/extensions/runner.ts +989 -0
- package/src/extensibility/extensions/types.ts +1394 -0
- package/src/extensibility/extensions/wrapper.ts +259 -0
- package/src/extensibility/hooks/index.ts +6 -0
- package/src/extensibility/hooks/loader.ts +262 -0
- package/src/extensibility/hooks/runner.ts +425 -0
- package/src/extensibility/hooks/tool-wrapper.ts +107 -0
- package/src/extensibility/hooks/types.ts +613 -0
- package/src/extensibility/legacy-pi-ai-shim.ts +61 -0
- package/src/extensibility/legacy-pi-coding-agent-shim.ts +128 -0
- package/src/extensibility/plugins/doctor.ts +65 -0
- package/src/extensibility/plugins/git-url.ts +367 -0
- package/src/extensibility/plugins/index.ts +9 -0
- package/src/extensibility/plugins/installer.ts +192 -0
- package/src/extensibility/plugins/legacy-pi-compat.ts +712 -0
- package/src/extensibility/plugins/loader.ts +458 -0
- package/src/extensibility/plugins/manager.ts +1026 -0
- package/src/extensibility/plugins/marketplace/cache.ts +136 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +315 -0
- package/src/extensibility/plugins/marketplace/index.ts +6 -0
- package/src/extensibility/plugins/marketplace/manager.ts +770 -0
- package/src/extensibility/plugins/marketplace/registry.ts +196 -0
- package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
- package/src/extensibility/plugins/marketplace/types.ts +191 -0
- package/src/extensibility/plugins/marketplace-auto-update.ts +49 -0
- package/src/extensibility/plugins/parser.ts +105 -0
- package/src/extensibility/plugins/runtime-config.ts +9 -0
- package/src/extensibility/plugins/types.ts +194 -0
- package/src/extensibility/shared-events.ts +367 -0
- package/src/extensibility/skills.ts +408 -0
- package/src/extensibility/slash-commands.ts +131 -0
- package/src/extensibility/tool-proxy.ts +28 -0
- package/src/extensibility/typebox.ts +945 -0
- package/src/extensibility/utils.ts +44 -0
- package/src/goals/guided-setup.ts +142 -0
- package/src/goals/index.ts +3 -0
- package/src/goals/runtime.ts +521 -0
- package/src/goals/state.ts +37 -0
- package/src/goals/tools/goal-tool.ts +251 -0
- package/src/hindsight/backend.ts +354 -0
- package/src/hindsight/bank.ts +156 -0
- package/src/hindsight/client.ts +623 -0
- package/src/hindsight/config.ts +175 -0
- package/src/hindsight/content.ts +210 -0
- package/src/hindsight/index.ts +8 -0
- package/src/hindsight/mental-models.ts +429 -0
- package/src/hindsight/seeds.json +32 -0
- package/src/hindsight/state.ts +492 -0
- package/src/hindsight/transcript.ts +71 -0
- package/src/index.ts +66 -0
- package/src/internal-urls/agent-protocol.ts +146 -0
- package/src/internal-urls/artifact-protocol.ts +107 -0
- package/src/internal-urls/docs-index.generated.txt +2 -0
- package/src/internal-urls/docs-index.ts +102 -0
- package/src/internal-urls/history-protocol.ts +118 -0
- package/src/internal-urls/index.ts +25 -0
- package/src/internal-urls/issue-pr-protocol.ts +594 -0
- package/src/internal-urls/json-query.ts +126 -0
- package/src/internal-urls/local-protocol.ts +309 -0
- package/src/internal-urls/mcp-protocol.ts +151 -0
- package/src/internal-urls/memory-protocol.ts +169 -0
- package/src/internal-urls/omp-protocol.ts +94 -0
- package/src/internal-urls/parse.ts +72 -0
- package/src/internal-urls/registry-helpers.ts +25 -0
- package/src/internal-urls/router.ts +105 -0
- package/src/internal-urls/rule-protocol.ts +45 -0
- package/src/internal-urls/skill-protocol.ts +96 -0
- package/src/internal-urls/types.ts +152 -0
- package/src/internal-urls/vault-protocol.ts +936 -0
- package/src/irc/bus.ts +311 -0
- package/src/lib/xai-http.ts +124 -0
- package/src/lsp/client.ts +1217 -0
- package/src/lsp/clients/biome-client.ts +264 -0
- package/src/lsp/clients/index.ts +50 -0
- package/src/lsp/clients/lsp-linter-client.ts +85 -0
- package/src/lsp/clients/swiftlint-client.ts +120 -0
- package/src/lsp/config.ts +502 -0
- package/src/lsp/defaults.json +499 -0
- package/src/lsp/diagnostics-ledger.ts +51 -0
- package/src/lsp/edits.ts +267 -0
- package/src/lsp/format-options.ts +119 -0
- package/src/lsp/index.ts +2480 -0
- package/src/lsp/lspmux.ts +233 -0
- package/src/lsp/render.ts +668 -0
- package/src/lsp/startup-events.ts +13 -0
- package/src/lsp/types.ts +444 -0
- package/src/lsp/utils.ts +718 -0
- package/src/main.ts +1421 -0
- package/src/markit/NOTICE +32 -0
- package/src/markit/converters/docx.ts +56 -0
- package/src/markit/converters/epub.ts +136 -0
- package/src/markit/converters/mammoth.d.ts +24 -0
- package/src/markit/converters/pdf/columns.ts +103 -0
- package/src/markit/converters/pdf/extract.ts +574 -0
- package/src/markit/converters/pdf/grid.ts +780 -0
- package/src/markit/converters/pdf/headers.ts +106 -0
- package/src/markit/converters/pdf/index.ts +146 -0
- package/src/markit/converters/pdf/render.ts +501 -0
- package/src/markit/converters/pdf/types.ts +84 -0
- package/src/markit/converters/pptx.ts +325 -0
- package/src/markit/converters/xlsx.ts +173 -0
- package/src/markit/index.ts +2 -0
- package/src/markit/registry.ts +59 -0
- package/src/markit/types.ts +35 -0
- package/src/mcp/client.ts +509 -0
- package/src/mcp/config-writer.ts +229 -0
- package/src/mcp/config.ts +365 -0
- package/src/mcp/index.ts +29 -0
- package/src/mcp/json-rpc.ts +122 -0
- package/src/mcp/loader.ts +124 -0
- package/src/mcp/manager.ts +1326 -0
- package/src/mcp/oauth-credentials.ts +104 -0
- package/src/mcp/oauth-discovery.ts +467 -0
- package/src/mcp/oauth-flow.ts +555 -0
- package/src/mcp/render.ts +155 -0
- package/src/mcp/smithery-auth.ts +104 -0
- package/src/mcp/smithery-connect.ts +145 -0
- package/src/mcp/smithery-registry.ts +477 -0
- package/src/mcp/startup-events.ts +21 -0
- package/src/mcp/timeout.ts +59 -0
- package/src/mcp/tool-bridge.ts +429 -0
- package/src/mcp/tool-cache.ts +117 -0
- package/src/mcp/transports/http.ts +519 -0
- package/src/mcp/transports/index.ts +6 -0
- package/src/mcp/transports/stdio.ts +606 -0
- package/src/mcp/types.ts +427 -0
- package/src/memories/index.ts +1281 -0
- package/src/memories/storage.ts +578 -0
- package/src/memory-backend/index.ts +18 -0
- package/src/memory-backend/local-backend.ts +45 -0
- package/src/memory-backend/off-backend.ts +25 -0
- package/src/memory-backend/resolve.ts +25 -0
- package/src/memory-backend/runtime.ts +66 -0
- package/src/memory-backend/types.ts +166 -0
- package/src/mnemopi/backend.ts +612 -0
- package/src/mnemopi/config.ts +265 -0
- package/src/mnemopi/embed-client.ts +401 -0
- package/src/mnemopi/embed-protocol.ts +35 -0
- package/src/mnemopi/embed-worker.ts +113 -0
- package/src/mnemopi/index.ts +3 -0
- package/src/mnemopi/state.ts +657 -0
- package/src/modes/acp/acp-agent.ts +2362 -0
- package/src/modes/acp/acp-client-bridge.ts +154 -0
- package/src/modes/acp/acp-event-mapper.ts +933 -0
- package/src/modes/acp/acp-mode.ts +23 -0
- package/src/modes/acp/index.ts +2 -0
- package/src/modes/acp/terminal-auth.ts +37 -0
- package/src/modes/components/__tests__/skill-message.test.ts +92 -0
- package/src/modes/components/advisor-message.ts +99 -0
- package/src/modes/components/agent-dashboard.ts +1206 -0
- package/src/modes/components/agent-hub.ts +566 -0
- package/src/modes/components/agent-transcript-viewer.ts +461 -0
- package/src/modes/components/assistant-message.ts +612 -0
- package/src/modes/components/background-tan-message.ts +36 -0
- package/src/modes/components/bash-execution.ts +220 -0
- package/src/modes/components/bordered-loader.ts +41 -0
- package/src/modes/components/btw-panel.ts +112 -0
- package/src/modes/components/cache-invalidation-marker.ts +110 -0
- package/src/modes/components/chat-block.ts +111 -0
- package/src/modes/components/chat-transcript-builder.ts +476 -0
- package/src/modes/components/collab-prompt-message.ts +32 -0
- package/src/modes/components/compaction-summary-message.ts +215 -0
- package/src/modes/components/copy-selector.ts +206 -0
- package/src/modes/components/countdown-timer.ts +75 -0
- package/src/modes/components/custom-editor.test.ts +142 -0
- package/src/modes/components/custom-editor.ts +620 -0
- package/src/modes/components/custom-message.ts +67 -0
- package/src/modes/components/diff.ts +254 -0
- package/src/modes/components/dynamic-border.ts +34 -0
- package/src/modes/components/error-banner.ts +33 -0
- package/src/modes/components/eval-execution.ts +158 -0
- package/src/modes/components/execution-shared.ts +101 -0
- package/src/modes/components/extensions/extension-dashboard.ts +399 -0
- package/src/modes/components/extensions/extension-list.ts +502 -0
- package/src/modes/components/extensions/index.ts +9 -0
- package/src/modes/components/extensions/inspector-panel.ts +321 -0
- package/src/modes/components/extensions/state-manager.ts +627 -0
- package/src/modes/components/extensions/types.ts +186 -0
- package/src/modes/components/footer.ts +275 -0
- package/src/modes/components/history-search.ts +280 -0
- package/src/modes/components/hook-editor.ts +167 -0
- package/src/modes/components/hook-input.ts +87 -0
- package/src/modes/components/hook-message.ts +67 -0
- package/src/modes/components/hook-selector.ts +659 -0
- package/src/modes/components/index.ts +38 -0
- package/src/modes/components/keybinding-hints.ts +65 -0
- package/src/modes/components/late-diagnostics-message.ts +60 -0
- package/src/modes/components/login-dialog.ts +164 -0
- package/src/modes/components/logout-account-selector.ts +130 -0
- package/src/modes/components/mcp-add-wizard.ts +1360 -0
- package/src/modes/components/message-frame.ts +92 -0
- package/src/modes/components/model-selector.ts +1315 -0
- package/src/modes/components/oauth-selector.ts +457 -0
- package/src/modes/components/omfg-panel.ts +141 -0
- package/src/modes/components/overlay-box.ts +109 -0
- package/src/modes/components/plan-review-overlay.ts +847 -0
- package/src/modes/components/plan-toc.ts +138 -0
- package/src/modes/components/plugin-selector.ts +95 -0
- package/src/modes/components/plugin-settings.ts +739 -0
- package/src/modes/components/queue-mode-selector.ts +56 -0
- package/src/modes/components/read-tool-group.ts +676 -0
- package/src/modes/components/reset-usage-selector.ts +161 -0
- package/src/modes/components/segment-track.ts +89 -0
- package/src/modes/components/session-selector.ts +631 -0
- package/src/modes/components/settings-defs.ts +225 -0
- package/src/modes/components/settings-selector.ts +1095 -0
- package/src/modes/components/show-images-selector.ts +45 -0
- package/src/modes/components/skill-message.ts +110 -0
- package/src/modes/components/snapcompact-shape-preview-doc.md +18 -0
- package/src/modes/components/snapcompact-shape-preview.ts +192 -0
- package/src/modes/components/status-line/component.ts +1001 -0
- package/src/modes/components/status-line/context-thresholds.ts +78 -0
- package/src/modes/components/status-line/git-utils.ts +42 -0
- package/src/modes/components/status-line/index.ts +5 -0
- package/src/modes/components/status-line/presets.ts +106 -0
- package/src/modes/components/status-line/segments.ts +616 -0
- package/src/modes/components/status-line/separators.ts +55 -0
- package/src/modes/components/status-line/token-rate.ts +66 -0
- package/src/modes/components/status-line/types.ts +124 -0
- package/src/modes/components/theme-selector.ts +63 -0
- package/src/modes/components/thinking-selector.ts +52 -0
- package/src/modes/components/tiny-title-download-progress.ts +90 -0
- package/src/modes/components/tips.txt +24 -0
- package/src/modes/components/todo-reminder.ts +39 -0
- package/src/modes/components/tool-execution.ts +1165 -0
- package/src/modes/components/transcript-container.ts +806 -0
- package/src/modes/components/tree-selector.ts +994 -0
- package/src/modes/components/ttsr-notification.ts +123 -0
- package/src/modes/components/usage-row.ts +18 -0
- package/src/modes/components/user-message-selector.ts +227 -0
- package/src/modes/components/user-message.ts +68 -0
- package/src/modes/components/visual-truncate.ts +63 -0
- package/src/modes/components/welcome.ts +581 -0
- package/src/modes/controllers/btw-controller.ts +173 -0
- package/src/modes/controllers/command-controller-shared.ts +109 -0
- package/src/modes/controllers/command-controller.ts +1653 -0
- package/src/modes/controllers/event-controller.ts +1153 -0
- package/src/modes/controllers/extension-ui-controller.ts +893 -0
- package/src/modes/controllers/input-controller.ts +1627 -0
- package/src/modes/controllers/mcp-command-controller.ts +2162 -0
- package/src/modes/controllers/omfg-controller.ts +283 -0
- package/src/modes/controllers/omfg-rule.ts +647 -0
- package/src/modes/controllers/selector-controller.ts +1285 -0
- package/src/modes/controllers/session-focus-controller.ts +112 -0
- package/src/modes/controllers/ssh-command-controller.ts +384 -0
- package/src/modes/controllers/streaming-reveal.ts +295 -0
- package/src/modes/controllers/tan-command-controller.ts +190 -0
- package/src/modes/controllers/todo-command-controller.ts +485 -0
- package/src/modes/controllers/tool-args-reveal.ts +174 -0
- package/src/modes/data/emojis.json +1 -0
- package/src/modes/emoji-autocomplete.ts +285 -0
- package/src/modes/gradient-highlight.ts +99 -0
- package/src/modes/image-references.ts +137 -0
- package/src/modes/index.ts +17 -0
- package/src/modes/interactive-mode.ts +3940 -0
- package/src/modes/internal-url-autocomplete.ts +143 -0
- package/src/modes/loop-limit.ts +192 -0
- package/src/modes/magic-keywords.ts +42 -0
- package/src/modes/markdown-prose.ts +247 -0
- package/src/modes/oauth-manual-input.ts +69 -0
- package/src/modes/orchestrate.ts +42 -0
- package/src/modes/print-mode.ts +130 -0
- package/src/modes/prompt-action-autocomplete.ts +260 -0
- package/src/modes/rpc/host-tools.ts +186 -0
- package/src/modes/rpc/host-uris.ts +235 -0
- package/src/modes/rpc/rpc-client.ts +995 -0
- package/src/modes/rpc/rpc-mode.ts +1156 -0
- package/src/modes/rpc/rpc-subagents.ts +265 -0
- package/src/modes/rpc/rpc-types.ts +487 -0
- package/src/modes/runtime-init.ts +142 -0
- package/src/modes/session-observer-registry.ts +215 -0
- package/src/modes/setup-version.ts +11 -0
- package/src/modes/setup-wizard/index.ts +101 -0
- package/src/modes/setup-wizard/lazy.ts +16 -0
- package/src/modes/setup-wizard/scenes/glyph.ts +114 -0
- package/src/modes/setup-wizard/scenes/outro.ts +35 -0
- package/src/modes/setup-wizard/scenes/providers.ts +103 -0
- package/src/modes/setup-wizard/scenes/sign-in.ts +286 -0
- package/src/modes/setup-wizard/scenes/splash.ts +201 -0
- package/src/modes/setup-wizard/scenes/theme.ts +326 -0
- package/src/modes/setup-wizard/scenes/types.ts +57 -0
- package/src/modes/setup-wizard/scenes/web-search.ts +145 -0
- package/src/modes/setup-wizard/startup-splash.ts +107 -0
- package/src/modes/setup-wizard/wizard-overlay.ts +334 -0
- package/src/modes/shared.ts +49 -0
- package/src/modes/theme/dark.json +95 -0
- package/src/modes/theme/defaults/alabaster.json +93 -0
- package/src/modes/theme/defaults/amethyst.json +96 -0
- package/src/modes/theme/defaults/anthracite.json +93 -0
- package/src/modes/theme/defaults/basalt.json +91 -0
- package/src/modes/theme/defaults/birch.json +95 -0
- package/src/modes/theme/defaults/dark-abyss.json +91 -0
- package/src/modes/theme/defaults/dark-arctic.json +104 -0
- package/src/modes/theme/defaults/dark-aurora.json +95 -0
- package/src/modes/theme/defaults/dark-catppuccin.json +107 -0
- package/src/modes/theme/defaults/dark-cavern.json +91 -0
- package/src/modes/theme/defaults/dark-copper.json +95 -0
- package/src/modes/theme/defaults/dark-cosmos.json +90 -0
- package/src/modes/theme/defaults/dark-cyberpunk.json +102 -0
- package/src/modes/theme/defaults/dark-dracula.json +98 -0
- package/src/modes/theme/defaults/dark-eclipse.json +91 -0
- package/src/modes/theme/defaults/dark-ember.json +95 -0
- package/src/modes/theme/defaults/dark-equinox.json +90 -0
- package/src/modes/theme/defaults/dark-forest.json +96 -0
- package/src/modes/theme/defaults/dark-github.json +105 -0
- package/src/modes/theme/defaults/dark-gruvbox.json +112 -0
- package/src/modes/theme/defaults/dark-lavender.json +95 -0
- package/src/modes/theme/defaults/dark-lunar.json +89 -0
- package/src/modes/theme/defaults/dark-midnight.json +95 -0
- package/src/modes/theme/defaults/dark-monochrome.json +94 -0
- package/src/modes/theme/defaults/dark-monokai.json +98 -0
- package/src/modes/theme/defaults/dark-nebula.json +90 -0
- package/src/modes/theme/defaults/dark-nord.json +97 -0
- package/src/modes/theme/defaults/dark-ocean.json +101 -0
- package/src/modes/theme/defaults/dark-one.json +100 -0
- package/src/modes/theme/defaults/dark-poimandres.json +142 -0
- package/src/modes/theme/defaults/dark-rainforest.json +91 -0
- package/src/modes/theme/defaults/dark-reef.json +91 -0
- package/src/modes/theme/defaults/dark-retro.json +92 -0
- package/src/modes/theme/defaults/dark-rose-pine.json +96 -0
- package/src/modes/theme/defaults/dark-sakura.json +95 -0
- package/src/modes/theme/defaults/dark-slate.json +95 -0
- package/src/modes/theme/defaults/dark-solarized.json +97 -0
- package/src/modes/theme/defaults/dark-solstice.json +90 -0
- package/src/modes/theme/defaults/dark-starfall.json +91 -0
- package/src/modes/theme/defaults/dark-sunset.json +99 -0
- package/src/modes/theme/defaults/dark-swamp.json +90 -0
- package/src/modes/theme/defaults/dark-synthwave.json +103 -0
- package/src/modes/theme/defaults/dark-taiga.json +91 -0
- package/src/modes/theme/defaults/dark-terminal.json +95 -0
- package/src/modes/theme/defaults/dark-tokyo-night.json +101 -0
- package/src/modes/theme/defaults/dark-tundra.json +91 -0
- package/src/modes/theme/defaults/dark-twilight.json +91 -0
- package/src/modes/theme/defaults/dark-volcanic.json +91 -0
- package/src/modes/theme/defaults/graphite.json +92 -0
- package/src/modes/theme/defaults/index.ts +199 -0
- package/src/modes/theme/defaults/light-arctic.json +107 -0
- package/src/modes/theme/defaults/light-aurora-day.json +91 -0
- package/src/modes/theme/defaults/light-canyon.json +91 -0
- package/src/modes/theme/defaults/light-catppuccin.json +106 -0
- package/src/modes/theme/defaults/light-cirrus.json +90 -0
- package/src/modes/theme/defaults/light-coral.json +95 -0
- package/src/modes/theme/defaults/light-cyberpunk.json +96 -0
- package/src/modes/theme/defaults/light-dawn.json +90 -0
- package/src/modes/theme/defaults/light-dunes.json +91 -0
- package/src/modes/theme/defaults/light-eucalyptus.json +95 -0
- package/src/modes/theme/defaults/light-forest.json +100 -0
- package/src/modes/theme/defaults/light-frost.json +95 -0
- package/src/modes/theme/defaults/light-github.json +115 -0
- package/src/modes/theme/defaults/light-glacier.json +91 -0
- package/src/modes/theme/defaults/light-gruvbox.json +108 -0
- package/src/modes/theme/defaults/light-haze.json +90 -0
- package/src/modes/theme/defaults/light-honeycomb.json +95 -0
- package/src/modes/theme/defaults/light-lagoon.json +91 -0
- package/src/modes/theme/defaults/light-lavender.json +95 -0
- package/src/modes/theme/defaults/light-meadow.json +91 -0
- package/src/modes/theme/defaults/light-mint.json +95 -0
- package/src/modes/theme/defaults/light-monochrome.json +101 -0
- package/src/modes/theme/defaults/light-ocean.json +99 -0
- package/src/modes/theme/defaults/light-one.json +99 -0
- package/src/modes/theme/defaults/light-opal.json +91 -0
- package/src/modes/theme/defaults/light-orchard.json +91 -0
- package/src/modes/theme/defaults/light-paper.json +95 -0
- package/src/modes/theme/defaults/light-poimandres.json +142 -0
- package/src/modes/theme/defaults/light-prism.json +90 -0
- package/src/modes/theme/defaults/light-retro.json +98 -0
- package/src/modes/theme/defaults/light-sand.json +95 -0
- package/src/modes/theme/defaults/light-savanna.json +91 -0
- package/src/modes/theme/defaults/light-solarized.json +102 -0
- package/src/modes/theme/defaults/light-soleil.json +90 -0
- package/src/modes/theme/defaults/light-sunset.json +99 -0
- package/src/modes/theme/defaults/light-synthwave.json +98 -0
- package/src/modes/theme/defaults/light-tokyo-night.json +111 -0
- package/src/modes/theme/defaults/light-wetland.json +91 -0
- package/src/modes/theme/defaults/light-zenith.json +89 -0
- package/src/modes/theme/defaults/limestone.json +94 -0
- package/src/modes/theme/defaults/mahogany.json +97 -0
- package/src/modes/theme/defaults/marble.json +93 -0
- package/src/modes/theme/defaults/obsidian.json +91 -0
- package/src/modes/theme/defaults/onyx.json +91 -0
- package/src/modes/theme/defaults/pearl.json +93 -0
- package/src/modes/theme/defaults/porcelain.json +91 -0
- package/src/modes/theme/defaults/quartz.json +96 -0
- package/src/modes/theme/defaults/sandstone.json +95 -0
- package/src/modes/theme/defaults/titanium.json +90 -0
- package/src/modes/theme/light.json +93 -0
- package/src/modes/theme/mermaid-cache.ts +92 -0
- package/src/modes/theme/shimmer.ts +235 -0
- package/src/modes/theme/theme-schema.json +459 -0
- package/src/modes/theme/theme.ts +2915 -0
- package/src/modes/turn-budget.ts +31 -0
- package/src/modes/types.ts +406 -0
- package/src/modes/ultrathink.ts +41 -0
- package/src/modes/utils/context-usage.ts +432 -0
- package/src/modes/utils/copy-targets.ts +360 -0
- package/src/modes/utils/hotkeys-markdown.ts +62 -0
- package/src/modes/utils/keybinding-matchers.ts +51 -0
- package/src/modes/utils/tools-markdown.ts +27 -0
- package/src/modes/utils/ui-helpers.ts +886 -0
- package/src/modes/workflow.ts +42 -0
- package/src/plan-mode/approved-plan.ts +186 -0
- package/src/plan-mode/plan-handoff.ts +37 -0
- package/src/plan-mode/plan-protection.ts +31 -0
- package/src/plan-mode/state.ts +6 -0
- package/src/priority.json +45 -0
- package/src/prompts/advisor/advise-tool.md +3 -0
- package/src/prompts/advisor/system.md +113 -0
- package/src/prompts/agents/designer.md +74 -0
- package/src/prompts/agents/explore.md +58 -0
- package/src/prompts/agents/frontmatter.md +11 -0
- package/src/prompts/agents/init.md +33 -0
- package/src/prompts/agents/librarian.md +119 -0
- package/src/prompts/agents/oracle.md +54 -0
- package/src/prompts/agents/plan.md +48 -0
- package/src/prompts/agents/reviewer.md +139 -0
- package/src/prompts/agents/task.md +17 -0
- package/src/prompts/bench.md +12 -0
- package/src/prompts/ci-green-request.md +36 -0
- package/src/prompts/dry-balance-bench.md +8 -0
- package/src/prompts/goals/goal-budget-limit.md +16 -0
- package/src/prompts/goals/goal-continuation.md +28 -0
- package/src/prompts/goals/goal-mode-active.md +23 -0
- package/src/prompts/goals/guided-goal-interview.md +8 -0
- package/src/prompts/goals/guided-goal-system.md +12 -0
- package/src/prompts/low-end/system.md +47 -0
- package/src/prompts/memories/consolidation.md +30 -0
- package/src/prompts/memories/consolidation_system.md +4 -0
- package/src/prompts/memories/read-path.md +17 -0
- package/src/prompts/memories/stage_one_input.md +6 -0
- package/src/prompts/memories/stage_one_system.md +21 -0
- package/src/prompts/review-custom-request.md +22 -0
- package/src/prompts/review-headless-request.md +16 -0
- package/src/prompts/review-request.md +69 -0
- package/src/prompts/steering/user-interjection.md +9 -0
- package/src/prompts/system/agent-creation-architect.md +50 -0
- package/src/prompts/system/agent-creation-user.md +6 -0
- package/src/prompts/system/auto-continue.md +1 -0
- package/src/prompts/system/auto-thinking-difficulty-local.md +14 -0
- package/src/prompts/system/auto-thinking-difficulty.md +12 -0
- 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 +8 -0
- package/src/prompts/system/commit-message-system.md +14 -0
- package/src/prompts/system/custom-system-prompt.md +64 -0
- package/src/prompts/system/eager-task.md +7 -0
- package/src/prompts/system/eager-todo.md +18 -0
- package/src/prompts/system/empty-stop-retry.md +4 -0
- package/src/prompts/system/irc-autoreply.md +6 -0
- package/src/prompts/system/irc-incoming.md +7 -0
- package/src/prompts/system/manual-continue.md +7 -0
- package/src/prompts/system/memory-consolidation-system.md +8 -0
- package/src/prompts/system/memory-extraction-system.md +26 -0
- package/src/prompts/system/omfg-user.md +50 -0
- package/src/prompts/system/orchestrate-notice.md +40 -0
- package/src/prompts/system/personalities/default.md +18 -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 +109 -0
- package/src/prompts/system/plan-mode-approved.md +25 -0
- package/src/prompts/system/plan-mode-compact-instructions.md +16 -0
- package/src/prompts/system/plan-mode-reference.md +11 -0
- package/src/prompts/system/plan-mode-subagent.md +33 -0
- package/src/prompts/system/plan-mode-tool-decision-reminder.md +9 -0
- package/src/prompts/system/project-prompt.md +52 -0
- 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 +71 -0
- package/src/prompts/system/subagent-user-prompt.md +3 -0
- package/src/prompts/system/subagent-yield-reminder.md +12 -0
- package/src/prompts/system/system-prompt.md +251 -0
- package/src/prompts/system/tiny-title-system.md +8 -0
- 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 -0
- package/src/prompts/system/ttsr-interrupt.md +7 -0
- package/src/prompts/system/ttsr-tool-reminder.md +5 -0
- package/src/prompts/system/ultrathink-notice.md +3 -0
- package/src/prompts/system/unexpected-stop-classifier.md +17 -0
- package/src/prompts/system/unexpected-stop-retry.md +4 -0
- package/src/prompts/system/web-search.md +25 -0
- package/src/prompts/system/workflow-notice.md +70 -0
- package/src/prompts/tools/apply-patch.md +65 -0
- package/src/prompts/tools/ask.md +22 -0
- package/src/prompts/tools/ast-edit.md +22 -0
- package/src/prompts/tools/ast-grep.md +25 -0
- package/src/prompts/tools/async-result.md +8 -0
- package/src/prompts/tools/bash.md +45 -0
- package/src/prompts/tools/browser.md +42 -0
- package/src/prompts/tools/checkpoint.md +15 -0
- package/src/prompts/tools/debug.md +17 -0
- package/src/prompts/tools/eval.md +70 -0
- package/src/prompts/tools/find.md +19 -0
- package/src/prompts/tools/github.md +17 -0
- package/src/prompts/tools/goal.md +11 -0
- package/src/prompts/tools/image-attachment-describe-system.md +8 -0
- package/src/prompts/tools/image-attachment-describe.md +10 -0
- package/src/prompts/tools/image-gen.md +7 -0
- package/src/prompts/tools/inspect-image-system.md +20 -0
- package/src/prompts/tools/inspect-image.md +22 -0
- package/src/prompts/tools/irc.md +33 -0
- package/src/prompts/tools/job.md +17 -0
- package/src/prompts/tools/learn.md +7 -0
- package/src/prompts/tools/lsp-late-diagnostic.md +8 -0
- package/src/prompts/tools/lsp.md +39 -0
- package/src/prompts/tools/manage-skill.md +9 -0
- package/src/prompts/tools/memory-edit.md +8 -0
- package/src/prompts/tools/patch.md +57 -0
- package/src/prompts/tools/read.md +76 -0
- package/src/prompts/tools/recall.md +5 -0
- package/src/prompts/tools/reflect.md +5 -0
- package/src/prompts/tools/replace.md +29 -0
- package/src/prompts/tools/resolve.md +4 -0
- package/src/prompts/tools/retain.md +6 -0
- package/src/prompts/tools/rewind.md +13 -0
- package/src/prompts/tools/search-tool-bm25.md +32 -0
- package/src/prompts/tools/search.md +22 -0
- package/src/prompts/tools/ssh.md +22 -0
- package/src/prompts/tools/task-summary.md +17 -0
- package/src/prompts/tools/task.md +91 -0
- package/src/prompts/tools/todo.md +39 -0
- package/src/prompts/tools/web-search.md +6 -0
- package/src/prompts/tools/write.md +14 -0
- package/src/registry/agent-lifecycle.ts +270 -0
- package/src/registry/agent-registry.ts +190 -0
- package/src/sdk.ts +2919 -0
- package/src/secrets/index.ts +123 -0
- package/src/secrets/obfuscator.ts +298 -0
- package/src/secrets/regex.ts +21 -0
- package/src/session/agent-session.ts +12539 -0
- package/src/session/agent-storage.ts +478 -0
- package/src/session/artifacts.ts +153 -0
- package/src/session/auth-broker-config.ts +92 -0
- package/src/session/auth-storage.ts +24 -0
- package/src/session/blob-store.ts +255 -0
- package/src/session/client-bridge.ts +85 -0
- package/src/session/codex-auto-reset.ts +202 -0
- package/src/session/compact-modes.ts +105 -0
- package/src/session/history-storage.ts +361 -0
- package/src/session/indexed-session-storage.ts +427 -0
- package/src/session/messages.ts +546 -0
- package/src/session/redis-session-storage.ts +170 -0
- package/src/session/session-context.ts +399 -0
- package/src/session/session-dump-format.ts +216 -0
- package/src/session/session-entries.ts +198 -0
- package/src/session/session-history-format.ts +308 -0
- package/src/session/session-listing.ts +588 -0
- package/src/session/session-loader.ts +93 -0
- package/src/session/session-manager.ts +1748 -0
- package/src/session/session-migrations.ts +78 -0
- package/src/session/session-paths.ts +193 -0
- package/src/session/session-persistence.ts +147 -0
- package/src/session/session-storage.ts +590 -0
- package/src/session/shake-types.ts +43 -0
- package/src/session/snapcompact-inline.ts +542 -0
- package/src/session/snapcompact-savings-journal.ts +113 -0
- package/src/session/sql-session-storage.ts +314 -0
- package/src/session/streaming-output.ts +1330 -0
- package/src/session/tool-choice-queue.ts +290 -0
- package/src/session/unexpected-stop-classifier.ts +129 -0
- package/src/session/yield-queue.ts +183 -0
- package/src/slash-commands/acp-builtins.ts +70 -0
- package/src/slash-commands/available-commands.ts +105 -0
- package/src/slash-commands/builtin-registry.ts +2332 -0
- package/src/slash-commands/helpers/active-oauth-account.ts +44 -0
- package/src/slash-commands/helpers/collab-qrcode.ts +28 -0
- package/src/slash-commands/helpers/context-report.ts +66 -0
- package/src/slash-commands/helpers/format.ts +46 -0
- package/src/slash-commands/helpers/logout.ts +88 -0
- package/src/slash-commands/helpers/marketplace-manager.ts +25 -0
- package/src/slash-commands/helpers/mcp.ts +532 -0
- package/src/slash-commands/helpers/parse.ts +85 -0
- package/src/slash-commands/helpers/reset-usage.ts +66 -0
- package/src/slash-commands/helpers/ssh.ts +195 -0
- package/src/slash-commands/helpers/stats-dashboard.ts +85 -0
- package/src/slash-commands/helpers/todo.ts +279 -0
- package/src/slash-commands/helpers/usage-report.ts +128 -0
- package/src/slash-commands/marketplace-install-parser.ts +99 -0
- package/src/slash-commands/types.ts +135 -0
- package/src/ssh/config-writer.ts +183 -0
- package/src/ssh/connection-manager.ts +510 -0
- package/src/ssh/ssh-executor.ts +189 -0
- package/src/ssh/sshfs-mount.ts +140 -0
- package/src/ssh/utils.ts +8 -0
- package/src/startup-splash.ts +19 -0
- package/src/stt/asr-client.ts +521 -0
- package/src/stt/asr-protocol.ts +65 -0
- package/src/stt/asr-worker.ts +790 -0
- package/src/stt/downloader.ts +138 -0
- package/src/stt/endpointer.ts +259 -0
- package/src/stt/index.ts +7 -0
- package/src/stt/models.ts +150 -0
- package/src/stt/recorder.ts +538 -0
- package/src/stt/stt-controller.ts +380 -0
- package/src/stt/transcriber.ts +60 -0
- package/src/stt/wav.ts +173 -0
- package/src/system-prompt.ts +709 -0
- package/src/task/agents.ts +166 -0
- package/src/task/commands.ts +132 -0
- package/src/task/discovery.ts +122 -0
- package/src/task/executor.ts +2356 -0
- package/src/task/index.ts +1580 -0
- package/src/task/name-generator.ts +1577 -0
- package/src/task/omp-command.ts +26 -0
- package/src/task/output-manager.ts +93 -0
- package/src/task/parallel.ts +116 -0
- package/src/task/persisted-revive.ts +128 -0
- package/src/task/render.ts +1558 -0
- package/src/task/repair-args.ts +129 -0
- package/src/task/subprocess-tool-registry.ts +88 -0
- package/src/task/types.ts +401 -0
- package/src/task/worktree.ts +514 -0
- package/src/telemetry-export.ts +144 -0
- package/src/thinking.ts +187 -0
- package/src/tiny/device.ts +111 -0
- package/src/tiny/dtype.ts +101 -0
- package/src/tiny/models.ts +252 -0
- package/src/tiny/text.ts +169 -0
- package/src/tiny/title-client.ts +538 -0
- package/src/tiny/title-protocol.ts +56 -0
- package/src/tiny/worker.ts +491 -0
- package/src/tool-discovery/mode.ts +24 -0
- package/src/tool-discovery/tool-index.ts +271 -0
- package/src/tools/__tests__/json-tree.test.ts +35 -0
- package/src/tools/approval.ts +189 -0
- package/src/tools/ask.ts +977 -0
- package/src/tools/ast-edit.ts +700 -0
- package/src/tools/ast-grep.ts +483 -0
- package/src/tools/auto-generated-guard.ts +322 -0
- package/src/tools/bash-command-fixup.ts +37 -0
- package/src/tools/bash-interactive.ts +408 -0
- package/src/tools/bash-interceptor.ts +67 -0
- package/src/tools/bash-pty-selection.ts +14 -0
- package/src/tools/bash-skill-urls.ts +248 -0
- package/src/tools/bash.ts +1405 -0
- package/src/tools/browser/attach.ts +194 -0
- 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 +673 -0
- package/src/tools/browser/readable.ts +112 -0
- package/src/tools/browser/registry.ts +241 -0
- package/src/tools/browser/render.ts +221 -0
- package/src/tools/browser/tab-protocol.ts +107 -0
- package/src/tools/browser/tab-supervisor.ts +799 -0
- package/src/tools/browser/tab-worker-entry.ts +29 -0
- package/src/tools/browser/tab-worker.ts +1226 -0
- package/src/tools/browser.ts +403 -0
- package/src/tools/builtin-names.ts +34 -0
- package/src/tools/checkpoint.ts +136 -0
- package/src/tools/conflict-detect.ts +718 -0
- package/src/tools/context.ts +39 -0
- package/src/tools/debug.ts +1087 -0
- package/src/tools/eval-backends.ts +27 -0
- package/src/tools/eval-render.ts +762 -0
- package/src/tools/eval.ts +600 -0
- package/src/tools/fetch.ts +1902 -0
- package/src/tools/file-recorder.ts +35 -0
- package/src/tools/find.ts +629 -0
- package/src/tools/fs-cache-invalidation.ts +28 -0
- package/src/tools/gh-cache-invalidation.ts +255 -0
- package/src/tools/gh-format.ts +12 -0
- package/src/tools/gh-renderer.ts +481 -0
- package/src/tools/gh.ts +3752 -0
- package/src/tools/github-cache.ts +663 -0
- package/src/tools/grouped-file-output.ts +210 -0
- package/src/tools/image-gen.ts +1586 -0
- package/src/tools/index.ts +649 -0
- package/src/tools/inspect-image-renderer.ts +132 -0
- package/src/tools/inspect-image.ts +260 -0
- package/src/tools/irc.ts +788 -0
- package/src/tools/job.ts +612 -0
- package/src/tools/json-tree.ts +260 -0
- package/src/tools/jtd-to-json-schema.ts +219 -0
- package/src/tools/jtd-to-typescript.ts +136 -0
- package/src/tools/jtd-utils.ts +102 -0
- package/src/tools/learn.ts +141 -0
- package/src/tools/list-limit.ts +40 -0
- package/src/tools/manage-skill.ts +100 -0
- package/src/tools/match-line-format.ts +20 -0
- package/src/tools/memory-edit.ts +59 -0
- package/src/tools/memory-recall.ts +102 -0
- package/src/tools/memory-reflect.ts +88 -0
- package/src/tools/memory-render.ts +202 -0
- package/src/tools/memory-retain.ts +89 -0
- package/src/tools/output-meta.ts +768 -0
- package/src/tools/output-schema-validator.ts +132 -0
- package/src/tools/path-utils.ts +1116 -0
- package/src/tools/plan-mode-guard.ts +142 -0
- package/src/tools/puppeteer/00_stealth_tampering.txt +63 -0
- package/src/tools/puppeteer/01_stealth_activity.txt +20 -0
- package/src/tools/puppeteer/02_stealth_hairline.txt +11 -0
- package/src/tools/puppeteer/03_stealth_botd.txt +384 -0
- package/src/tools/puppeteer/04_stealth_iframe.txt +81 -0
- package/src/tools/puppeteer/05_stealth_webgl.txt +75 -0
- package/src/tools/puppeteer/06_stealth_screen.txt +72 -0
- package/src/tools/puppeteer/07_stealth_fonts.txt +97 -0
- package/src/tools/puppeteer/08_stealth_audio.txt +51 -0
- package/src/tools/puppeteer/09_stealth_locale.txt +46 -0
- package/src/tools/puppeteer/10_stealth_plugins.txt +208 -0
- package/src/tools/puppeteer/11_stealth_hardware.txt +8 -0
- package/src/tools/puppeteer/12_stealth_codecs.txt +40 -0
- package/src/tools/puppeteer/13_stealth_worker.txt +74 -0
- package/src/tools/read.ts +3124 -0
- package/src/tools/render-utils.ts +895 -0
- package/src/tools/renderers.ts +86 -0
- package/src/tools/report-tool-issue.ts +530 -0
- package/src/tools/resolve.ts +302 -0
- package/src/tools/review.ts +251 -0
- package/src/tools/search-tool-bm25.ts +351 -0
- package/src/tools/search.ts +1583 -0
- package/src/tools/sqlite-reader.ts +828 -0
- package/src/tools/ssh.ts +369 -0
- package/src/tools/todo.ts +938 -0
- package/src/tools/tool-errors.ts +62 -0
- package/src/tools/tool-result.ts +102 -0
- package/src/tools/tool-timeouts.ts +30 -0
- package/src/tools/tts.ts +265 -0
- package/src/tools/write.ts +1182 -0
- package/src/tools/yield.ts +269 -0
- 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 +642 -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 +257 -0
- package/src/tui/file-list.ts +55 -0
- package/src/tui/hyperlink.ts +178 -0
- package/src/tui/index.ts +13 -0
- package/src/tui/output-block.ts +240 -0
- package/src/tui/status-line.ts +54 -0
- package/src/tui/tree-list.ts +133 -0
- package/src/tui/types.ts +15 -0
- package/src/tui/utils.ts +103 -0
- package/src/tui/width-aware-text.ts +58 -0
- package/src/utils/block-context.ts +312 -0
- package/src/utils/changelog.ts +132 -0
- package/src/utils/clipboard.ts +262 -0
- package/src/utils/command-args.ts +76 -0
- package/src/utils/commit-message-generator.ts +147 -0
- package/src/utils/edit-mode.ts +41 -0
- package/src/utils/enhanced-paste.ts +230 -0
- package/src/utils/event-bus.ts +33 -0
- package/src/utils/external-editor.ts +78 -0
- package/src/utils/file-display-mode.ts +45 -0
- package/src/utils/file-mentions.ts +284 -0
- package/src/utils/git.ts +1838 -0
- package/src/utils/image-loading.ts +231 -0
- package/src/utils/image-resize.ts +309 -0
- package/src/utils/image-vision-fallback.ts +197 -0
- package/src/utils/ipc.ts +38 -0
- package/src/utils/jj.ts +248 -0
- package/src/utils/lang-from-path.ts +244 -0
- package/src/utils/markit.ts +143 -0
- package/src/utils/mupdf-wasm-embed.ts +12 -0
- package/src/utils/open.ts +55 -0
- package/src/utils/qrcode.ts +535 -0
- package/src/utils/session-color.ts +142 -0
- package/src/utils/shell-snapshot.ts +187 -0
- package/src/utils/sixel.ts +69 -0
- package/src/utils/thinking-display.ts +11 -0
- package/src/utils/title-generator.ts +416 -0
- package/src/utils/tool-choice.ts +49 -0
- package/src/utils/tools-manager.ts +372 -0
- package/src/utils/turndown.ts +83 -0
- package/src/utils/zip.ts +1091 -0
- package/src/web/kagi.ts +304 -0
- package/src/web/parallel.ts +353 -0
- package/src/web/scrapers/artifacthub.ts +207 -0
- package/src/web/scrapers/arxiv.ts +83 -0
- package/src/web/scrapers/aur.ts +162 -0
- package/src/web/scrapers/biorxiv.ts +133 -0
- package/src/web/scrapers/bluesky.ts +262 -0
- package/src/web/scrapers/brew.ts +172 -0
- package/src/web/scrapers/cheatsh.ts +68 -0
- package/src/web/scrapers/chocolatey.ts +196 -0
- package/src/web/scrapers/choosealicense.ts +95 -0
- package/src/web/scrapers/cisa-kev.ts +87 -0
- package/src/web/scrapers/clojars.ts +154 -0
- package/src/web/scrapers/coingecko.ts +177 -0
- package/src/web/scrapers/crates-io.ts +97 -0
- package/src/web/scrapers/crossref.ts +136 -0
- package/src/web/scrapers/devto.ts +147 -0
- package/src/web/scrapers/discogs.ts +306 -0
- package/src/web/scrapers/discourse.ts +197 -0
- package/src/web/scrapers/dockerhub.ts +138 -0
- package/src/web/scrapers/docs-rs.ts +652 -0
- package/src/web/scrapers/fdroid.ts +134 -0
- package/src/web/scrapers/firefox-addons.ts +191 -0
- package/src/web/scrapers/flathub.ts +223 -0
- package/src/web/scrapers/github-gist.ts +58 -0
- package/src/web/scrapers/github.ts +800 -0
- package/src/web/scrapers/gitlab.ts +401 -0
- package/src/web/scrapers/go-pkg.ts +266 -0
- package/src/web/scrapers/hackage.ts +140 -0
- package/src/web/scrapers/hackernews.ts +189 -0
- package/src/web/scrapers/hex.ts +105 -0
- package/src/web/scrapers/huggingface.ts +321 -0
- package/src/web/scrapers/iacr.ts +89 -0
- package/src/web/scrapers/index.ts +252 -0
- package/src/web/scrapers/jetbrains-marketplace.ts +159 -0
- package/src/web/scrapers/lemmy.ts +203 -0
- package/src/web/scrapers/lobsters.ts +175 -0
- package/src/web/scrapers/mastodon.ts +292 -0
- package/src/web/scrapers/maven.ts +138 -0
- package/src/web/scrapers/mdn.ts +173 -0
- package/src/web/scrapers/metacpan.ts +222 -0
- package/src/web/scrapers/musicbrainz.ts +250 -0
- package/src/web/scrapers/npm.ts +98 -0
- package/src/web/scrapers/nuget.ts +183 -0
- package/src/web/scrapers/nvd.ts +222 -0
- package/src/web/scrapers/ollama.ts +239 -0
- package/src/web/scrapers/open-vsx.ts +106 -0
- package/src/web/scrapers/opencorporates.ts +292 -0
- package/src/web/scrapers/openlibrary.ts +336 -0
- package/src/web/scrapers/orcid.ts +286 -0
- package/src/web/scrapers/osv.ts +176 -0
- package/src/web/scrapers/packagist.ts +160 -0
- package/src/web/scrapers/pub-dev.ts +143 -0
- package/src/web/scrapers/pubmed.ts +211 -0
- package/src/web/scrapers/pypi.ts +112 -0
- package/src/web/scrapers/rawg.ts +110 -0
- package/src/web/scrapers/readthedocs.ts +120 -0
- package/src/web/scrapers/reddit.ts +95 -0
- package/src/web/scrapers/repology.ts +251 -0
- package/src/web/scrapers/rfc.ts +201 -0
- package/src/web/scrapers/rubygems.ts +103 -0
- package/src/web/scrapers/searchcode.ts +189 -0
- package/src/web/scrapers/sec-edgar.ts +261 -0
- package/src/web/scrapers/semantic-scholar.ts +171 -0
- package/src/web/scrapers/snapcraft.ts +187 -0
- package/src/web/scrapers/sourcegraph.ts +336 -0
- package/src/web/scrapers/spdx.ts +108 -0
- package/src/web/scrapers/spotify.ts +198 -0
- package/src/web/scrapers/stackoverflow.ts +120 -0
- package/src/web/scrapers/terraform.ts +277 -0
- package/src/web/scrapers/tldr.ts +47 -0
- package/src/web/scrapers/twitter.ts +94 -0
- package/src/web/scrapers/types.ts +354 -0
- package/src/web/scrapers/utils.ts +109 -0
- package/src/web/scrapers/vimeo.ts +133 -0
- package/src/web/scrapers/vscode-marketplace.ts +187 -0
- package/src/web/scrapers/w3c.ts +156 -0
- package/src/web/scrapers/wikidata.ts +344 -0
- package/src/web/scrapers/wikipedia.ts +84 -0
- package/src/web/scrapers/youtube.ts +325 -0
- package/src/web/search/index.ts +317 -0
- package/src/web/search/provider.ts +169 -0
- package/src/web/search/providers/anthropic.ts +343 -0
- package/src/web/search/providers/base.ts +90 -0
- package/src/web/search/providers/brave.ts +152 -0
- package/src/web/search/providers/codex.ts +593 -0
- package/src/web/search/providers/exa.ts +400 -0
- package/src/web/search/providers/gemini.ts +518 -0
- package/src/web/search/providers/jina.ts +111 -0
- package/src/web/search/providers/kagi.ts +86 -0
- package/src/web/search/providers/kimi.ts +196 -0
- package/src/web/search/providers/parallel.ts +225 -0
- package/src/web/search/providers/perplexity-auth.ts +133 -0
- package/src/web/search/providers/perplexity.ts +866 -0
- package/src/web/search/providers/searxng.ts +325 -0
- package/src/web/search/providers/synthetic.ts +114 -0
- package/src/web/search/providers/tavily.ts +176 -0
- package/src/web/search/providers/utils.ts +128 -0
- package/src/web/search/providers/zai.ts +333 -0
- package/src/web/search/render.ts +262 -0
- package/src/web/search/types.ts +462 -0
- package/src/web/search/utils.ts +17 -0
- package/src/workspace-tree.ts +326 -0
|
@@ -0,0 +1,3940 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive mode for the coding agent.
|
|
3
|
+
* Handles TUI rendering and user interaction, delegating business logic to AgentSession.
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from "node:fs/promises";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import {
|
|
8
|
+
type Agent,
|
|
9
|
+
type AgentMessage,
|
|
10
|
+
type AgentToolResult,
|
|
11
|
+
EventLoopKeepalive,
|
|
12
|
+
ThinkingLevel,
|
|
13
|
+
} from "@oh-my-pi/pi-agent-core";
|
|
14
|
+
import type { CompactionOutcome } from "@oh-my-pi/pi-agent-core/compaction";
|
|
15
|
+
import type { AssistantMessage, ImageContent, Message, Model, Usage, UsageReport } from "@oh-my-pi/pi-ai";
|
|
16
|
+
import { modelsAreEqual } from "@oh-my-pi/pi-catalog/models";
|
|
17
|
+
import type {
|
|
18
|
+
Component,
|
|
19
|
+
EditorTheme,
|
|
20
|
+
LoaderMessageColorFn,
|
|
21
|
+
NativeScrollbackLiveRegion,
|
|
22
|
+
OverlayHandle,
|
|
23
|
+
SlashCommand,
|
|
24
|
+
} from "@oh-my-pi/pi-tui";
|
|
25
|
+
import {
|
|
26
|
+
Container,
|
|
27
|
+
clearRenderCache,
|
|
28
|
+
Loader,
|
|
29
|
+
Markdown,
|
|
30
|
+
ProcessTerminal,
|
|
31
|
+
Spacer,
|
|
32
|
+
setTerminalTextSizing,
|
|
33
|
+
setTuiTight,
|
|
34
|
+
TERMINAL,
|
|
35
|
+
Text,
|
|
36
|
+
TUI,
|
|
37
|
+
visibleWidth,
|
|
38
|
+
} from "@oh-my-pi/pi-tui";
|
|
39
|
+
import {
|
|
40
|
+
APP_NAME,
|
|
41
|
+
adjustHsv,
|
|
42
|
+
formatNumber,
|
|
43
|
+
getProjectDir,
|
|
44
|
+
hsvToRgb,
|
|
45
|
+
isEnoent,
|
|
46
|
+
logger,
|
|
47
|
+
postmortem,
|
|
48
|
+
prompt,
|
|
49
|
+
setProjectDir,
|
|
50
|
+
} from "@oh-my-pi/pi-utils";
|
|
51
|
+
import chalk from "chalk";
|
|
52
|
+
import { reset as resetCapabilities } from "../capability";
|
|
53
|
+
import type { CollabGuestLink } from "../collab/guest";
|
|
54
|
+
import type { CollabHost } from "../collab/host";
|
|
55
|
+
import { KeybindingsManager } from "../config/keybindings";
|
|
56
|
+
import { isSettingsInitialized, onStatusLineSessionAccentChanged, Settings, settings } from "../config/settings";
|
|
57
|
+
import { clearClaudePluginRootsCache } from "../discovery/helpers";
|
|
58
|
+
import type {
|
|
59
|
+
ContextUsage,
|
|
60
|
+
ExtensionUIContext,
|
|
61
|
+
ExtensionUIDialogOptions,
|
|
62
|
+
ExtensionUISelectItem,
|
|
63
|
+
ExtensionWidgetContent,
|
|
64
|
+
ExtensionWidgetOptions,
|
|
65
|
+
} from "../extensibility/extensions";
|
|
66
|
+
import type { CompactOptions } from "../extensibility/extensions/types";
|
|
67
|
+
import { loadSlashCommands } from "../extensibility/slash-commands";
|
|
68
|
+
import { type GuidedGoalMessage, runGuidedGoalTurn } from "../goals/guided-setup";
|
|
69
|
+
import type { Goal, GoalModeState } from "../goals/state";
|
|
70
|
+
import { resolveLocalUrlToPath } from "../internal-urls";
|
|
71
|
+
import { LSP_STARTUP_EVENT_CHANNEL, type LspStartupEvent } from "../lsp/startup-events";
|
|
72
|
+
import type { MCPManager } from "../mcp";
|
|
73
|
+
import { formatMCPConnectingMessage, isMcpConnectingEvent, MCP_CONNECTING_EVENT_CHANNEL } from "../mcp/startup-events";
|
|
74
|
+
import {
|
|
75
|
+
humanizePlanTitle,
|
|
76
|
+
type PlanApprovalDetails,
|
|
77
|
+
resolveApprovedPlan,
|
|
78
|
+
resolvePlanTitle,
|
|
79
|
+
} from "../plan-mode/approved-plan";
|
|
80
|
+
import planModeApprovedPrompt from "../prompts/system/plan-mode-approved.md" with { type: "text" };
|
|
81
|
+
import planModeCompactInstructionsPrompt from "../prompts/system/plan-mode-compact-instructions.md" with {
|
|
82
|
+
type: "text",
|
|
83
|
+
};
|
|
84
|
+
import type { AgentSession, AgentSessionEvent, ResolvedRoleModel } from "../session/agent-session";
|
|
85
|
+
import type { CompactMode } from "../session/compact-modes";
|
|
86
|
+
import { HistoryStorage } from "../session/history-storage";
|
|
87
|
+
import type { SessionContext } from "../session/session-context";
|
|
88
|
+
import { getRecentSessions } from "../session/session-listing";
|
|
89
|
+
import type { SessionManager } from "../session/session-manager";
|
|
90
|
+
import type { ShakeMode } from "../session/shake-types";
|
|
91
|
+
import { BUILTIN_SLASH_COMMAND_RESERVED_NAMES, BUILTIN_SLASH_COMMANDS } from "../slash-commands/builtin-registry";
|
|
92
|
+
import { formatDuration } from "../slash-commands/helpers/format";
|
|
93
|
+
import { STTController, type SttState } from "../stt";
|
|
94
|
+
import { discoverTitleSystemPromptFile, resolvePromptInput } from "../system-prompt";
|
|
95
|
+
import { formatTaskId } from "../task/render";
|
|
96
|
+
import type { LspStartupServerInfo } from "../tools";
|
|
97
|
+
import { isImageProviderPreference, setPreferredImageProvider } from "../tools/image-gen";
|
|
98
|
+
import { normalizeLocalScheme } from "../tools/path-utils";
|
|
99
|
+
import { replaceTabs, TRUNCATE_LENGTHS, truncateToWidth } from "../tools/render-utils";
|
|
100
|
+
import { setAutoQaConsentHandler } from "../tools/report-tool-issue";
|
|
101
|
+
import { type ResolveToolDetails, runResolveInvocation } from "../tools/resolve";
|
|
102
|
+
import { formatPhaseDisplayName, selectStickyTodoWindow, todoMatchesAnyDescription } from "../tools/todo";
|
|
103
|
+
import { ToolError } from "../tools/tool-errors";
|
|
104
|
+
import { vocalizer } from "../tts/vocalizer";
|
|
105
|
+
import type { EventBus } from "../utils/event-bus";
|
|
106
|
+
import { getEditorCommand, openInEditor } from "../utils/external-editor";
|
|
107
|
+
import { getSessionAccentAnsi, getSessionAccentHex } from "../utils/session-color";
|
|
108
|
+
import { popTerminalTitle, pushTerminalTitle, setSessionTerminalTitle } from "../utils/title-generator";
|
|
109
|
+
import {
|
|
110
|
+
isSearchProviderId,
|
|
111
|
+
isSearchProviderPreference,
|
|
112
|
+
setExcludedSearchProviders,
|
|
113
|
+
setPreferredSearchProvider,
|
|
114
|
+
} from "../web/search";
|
|
115
|
+
import type { AssistantMessageComponent } from "./components/assistant-message";
|
|
116
|
+
import type { BashExecutionComponent } from "./components/bash-execution";
|
|
117
|
+
import { ChatBlock, type ChatBlockHost } from "./components/chat-block";
|
|
118
|
+
import { CustomEditor } from "./components/custom-editor";
|
|
119
|
+
import { DynamicBorder } from "./components/dynamic-border";
|
|
120
|
+
import { ErrorBannerComponent } from "./components/error-banner";
|
|
121
|
+
import type { EvalExecutionComponent } from "./components/eval-execution";
|
|
122
|
+
import type { HookEditorComponent } from "./components/hook-editor";
|
|
123
|
+
import type { HookInputComponent } from "./components/hook-input";
|
|
124
|
+
import type { HookSelectorComponent, HookSelectorSlider } from "./components/hook-selector";
|
|
125
|
+
import { PlanReviewOverlay } from "./components/plan-review-overlay";
|
|
126
|
+
import { StatusLineComponent } from "./components/status-line";
|
|
127
|
+
import type { ToolExecutionHandle } from "./components/tool-execution";
|
|
128
|
+
import { TranscriptContainer } from "./components/transcript-container";
|
|
129
|
+
import { WelcomeComponent, type LspServerInfo as WelcomeLspServerInfo } from "./components/welcome";
|
|
130
|
+
import { BtwController } from "./controllers/btw-controller";
|
|
131
|
+
import { CommandController } from "./controllers/command-controller";
|
|
132
|
+
import { EventController } from "./controllers/event-controller";
|
|
133
|
+
import { ExtensionUiController } from "./controllers/extension-ui-controller";
|
|
134
|
+
import { InputController } from "./controllers/input-controller";
|
|
135
|
+
import { MCPCommandController } from "./controllers/mcp-command-controller";
|
|
136
|
+
import { OmfgController } from "./controllers/omfg-controller";
|
|
137
|
+
import { SelectorController } from "./controllers/selector-controller";
|
|
138
|
+
import { SessionFocusController } from "./controllers/session-focus-controller";
|
|
139
|
+
import { SSHCommandController } from "./controllers/ssh-command-controller";
|
|
140
|
+
import { TanCommandController } from "./controllers/tan-command-controller";
|
|
141
|
+
import { TodoCommandController } from "./controllers/todo-command-controller";
|
|
142
|
+
import {
|
|
143
|
+
consumeLoopLimitIteration,
|
|
144
|
+
createLoopLimitRuntime,
|
|
145
|
+
describeLoopLimit,
|
|
146
|
+
describeLoopLimitRuntime,
|
|
147
|
+
isLoopDurationExpired,
|
|
148
|
+
type LoopLimitRuntime,
|
|
149
|
+
parseLoopLimitArgs,
|
|
150
|
+
} from "./loop-limit";
|
|
151
|
+
import { OAuthManualInputManager } from "./oauth-manual-input";
|
|
152
|
+
import type { ObservableSession } from "./session-observer-registry";
|
|
153
|
+
import { SessionObserverRegistry } from "./session-observer-registry";
|
|
154
|
+
import { runProviderSetupWizard } from "./setup-wizard/lazy";
|
|
155
|
+
import { interruptHint } from "./shared";
|
|
156
|
+
import { clearMermaidCache } from "./theme/mermaid-cache";
|
|
157
|
+
import { type ShimmerPalette, shimmerEnabled, shimmerSegments, shimmerText } from "./theme/shimmer";
|
|
158
|
+
import type { Theme } from "./theme/theme";
|
|
159
|
+
import {
|
|
160
|
+
getEditorTheme,
|
|
161
|
+
getMarkdownTheme,
|
|
162
|
+
getSymbolTheme,
|
|
163
|
+
onTerminalAppearanceChange,
|
|
164
|
+
onThemeChange,
|
|
165
|
+
theme,
|
|
166
|
+
} from "./theme/theme";
|
|
167
|
+
import type {
|
|
168
|
+
CompactionQueuedMessage,
|
|
169
|
+
InteractiveModeContext,
|
|
170
|
+
InteractiveModeInitOptions,
|
|
171
|
+
InteractiveSelectorDialogOptions,
|
|
172
|
+
SubmittedUserInput,
|
|
173
|
+
TodoItem,
|
|
174
|
+
TodoPhase,
|
|
175
|
+
} from "./types";
|
|
176
|
+
import { UiHelpers } from "./utils/ui-helpers";
|
|
177
|
+
|
|
178
|
+
const HINT_SHIMMER_PALETTE: ShimmerPalette = {
|
|
179
|
+
low: "dim",
|
|
180
|
+
mid: "muted",
|
|
181
|
+
high: "borderAccent",
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
interface WorkingMessageAccent {
|
|
185
|
+
main: string;
|
|
186
|
+
dim: string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface WorkingMessageAccentCacheKey {
|
|
190
|
+
sessionName: string | undefined;
|
|
191
|
+
accentSurfaceLuminance: number | undefined;
|
|
192
|
+
sessionAccentEnabled: boolean;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function renderWorkingMessage(message: string, accent?: WorkingMessageAccent): string {
|
|
196
|
+
const palette = accent
|
|
197
|
+
? ({
|
|
198
|
+
low: "dim",
|
|
199
|
+
mid: { ansi: accent.main },
|
|
200
|
+
high: { ansi: accent.main },
|
|
201
|
+
bold: true,
|
|
202
|
+
} satisfies ShimmerPalette)
|
|
203
|
+
: undefined;
|
|
204
|
+
const hint = interruptHint();
|
|
205
|
+
if (!message.endsWith(hint)) return shimmerText(message, theme, palette);
|
|
206
|
+
const header = message.slice(0, -hint.length);
|
|
207
|
+
const hintPalette = accent
|
|
208
|
+
? ({
|
|
209
|
+
low: "dim",
|
|
210
|
+
mid: { ansi: accent.dim },
|
|
211
|
+
high: { ansi: accent.dim },
|
|
212
|
+
} satisfies ShimmerPalette)
|
|
213
|
+
: HINT_SHIMMER_PALETTE;
|
|
214
|
+
return shimmerSegments(
|
|
215
|
+
[
|
|
216
|
+
{ text: header, palette },
|
|
217
|
+
{ text: hint, palette: hintPalette },
|
|
218
|
+
],
|
|
219
|
+
theme,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const EDITOR_MAX_HEIGHT_MIN = 6;
|
|
224
|
+
const EDITOR_MAX_HEIGHT_MAX = 18;
|
|
225
|
+
const EDITOR_RESERVED_ROWS = 12;
|
|
226
|
+
const EDITOR_FALLBACK_ROWS = 24;
|
|
227
|
+
const EDITOR_MIN_CHROME_ROWS = 4; // rows reserved for transcript + status on small terms
|
|
228
|
+
const EDITOR_MIN_RENDERED_ROWS = 3; // bordered editor floor: top+bottom border + 1 content row
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Editor max-height cap for a terminal of `terminalRows` rows.
|
|
232
|
+
*
|
|
233
|
+
* Roomy terminals get the comfortable [6, 18] band. Small terminals shrink the
|
|
234
|
+
* cap so the editor leaves at least EDITOR_MIN_CHROME_ROWS rows for the
|
|
235
|
+
* transcript + status line. The editor is bordered, so it never renders fewer
|
|
236
|
+
* than EDITOR_MIN_RENDERED_ROWS rows; once the terminal is too small for both
|
|
237
|
+
* (terminalRows < EDITOR_MIN_RENDERED_ROWS + EDITOR_MIN_CHROME_ROWS) the cap is
|
|
238
|
+
* pinned to that floor — returning a smaller number would not shrink the editor
|
|
239
|
+
* any further, it would only misreport the rows it actually occupies.
|
|
240
|
+
*/
|
|
241
|
+
export function computeEditorMaxHeight(terminalRows: number): number {
|
|
242
|
+
const rows = Number.isFinite(terminalRows) && terminalRows > 0 ? terminalRows : EDITOR_FALLBACK_ROWS;
|
|
243
|
+
const comfortable = Math.max(EDITOR_MAX_HEIGHT_MIN, Math.min(EDITOR_MAX_HEIGHT_MAX, rows - EDITOR_RESERVED_ROWS));
|
|
244
|
+
return Math.max(EDITOR_MIN_RENDERED_ROWS, Math.min(comfortable, rows - EDITOR_MIN_CHROME_ROWS));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const HUD_NOTE_SUP_DIGITS: Record<string, string> = {
|
|
248
|
+
"0": "\u2070",
|
|
249
|
+
"1": "\u00b9",
|
|
250
|
+
"2": "\u00b2",
|
|
251
|
+
"3": "\u00b3",
|
|
252
|
+
"4": "\u2074",
|
|
253
|
+
"5": "\u2075",
|
|
254
|
+
"6": "\u2076",
|
|
255
|
+
"7": "\u2077",
|
|
256
|
+
"8": "\u2078",
|
|
257
|
+
"9": "\u2079",
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
function formatHudNoteMarker(count: number): string {
|
|
261
|
+
if (count <= 0) return "";
|
|
262
|
+
const sub = String(count)
|
|
263
|
+
.split("")
|
|
264
|
+
.map(d => HUD_NOTE_SUP_DIGITS[d] ?? d)
|
|
265
|
+
.join("");
|
|
266
|
+
return theme.fg("dim", chalk.italic(` \u207a${sub}`));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
type GoalSubcommand = "set" | "show" | "pause" | "resume" | "drop" | "budget";
|
|
270
|
+
|
|
271
|
+
const GOAL_SUBCOMMANDS = new Set<GoalSubcommand>(["set", "show", "pause", "resume", "drop", "budget"]);
|
|
272
|
+
const PLAN_KEEP_CONTEXT_OPTION_INDEX = 2;
|
|
273
|
+
const PLAN_KEEP_CONTEXT_DISABLE_THRESHOLD_PERCENT = 95;
|
|
274
|
+
|
|
275
|
+
function parseGoalSubcommand(args: string): { sub: GoalSubcommand | undefined; rest: string } {
|
|
276
|
+
const trimmed = args.trim();
|
|
277
|
+
if (!trimmed) return { sub: undefined, rest: "" };
|
|
278
|
+
const match = /^(\S+)(?:\s+([\s\S]*))?$/.exec(trimmed);
|
|
279
|
+
if (!match) return { sub: undefined, rest: trimmed };
|
|
280
|
+
const first = match[1].toLowerCase();
|
|
281
|
+
if (GOAL_SUBCOMMANDS.has(first as GoalSubcommand)) {
|
|
282
|
+
return { sub: first as GoalSubcommand, rest: match[2]?.trim() ?? "" };
|
|
283
|
+
}
|
|
284
|
+
return { sub: undefined, rest: trimmed };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function formatContextTokenCount(value: number): string {
|
|
288
|
+
return formatNumber(Math.max(0, Math.round(value))).toLowerCase();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Options for creating an InteractiveMode instance (for future API use) */
|
|
292
|
+
export interface InteractiveModeOptions {
|
|
293
|
+
/** Providers that were migrated during startup */
|
|
294
|
+
migratedProviders?: string[];
|
|
295
|
+
/** Warning message if model fallback occurred */
|
|
296
|
+
modelFallbackMessage?: string;
|
|
297
|
+
/** Initial message to send */
|
|
298
|
+
initialMessage?: string;
|
|
299
|
+
/** Initial images to include with the message */
|
|
300
|
+
initialImages?: ImageContent[];
|
|
301
|
+
/** Additional initial messages to queue */
|
|
302
|
+
initialMessages?: string[];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Hosts the working loader and transient status rows. While anything is
|
|
307
|
+
* mounted, every row is live: report a seam at 0 so the engine never commits
|
|
308
|
+
* a still-animating loader to native scrollback (stale `Working…` rows would
|
|
309
|
+
* otherwise pile up above the live one). The transcript's own seam, when
|
|
310
|
+
* present, sits higher and wins (topmost-seam merge in TUI.render).
|
|
311
|
+
*/
|
|
312
|
+
class StatusContainer extends Container implements NativeScrollbackLiveRegion {
|
|
313
|
+
getNativeScrollbackLiveRegionStart(): number | undefined {
|
|
314
|
+
return this.children.length > 0 ? 0 : undefined;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** How long the ctrl+p model-role cycle chip track lingers above the editor
|
|
319
|
+
* before it auto-clears, mirroring the todo HUD's auto-clear timer. */
|
|
320
|
+
const MODEL_CYCLE_TRACK_CLEAR_MS = 4000;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Build the anchored subagent HUD block: a bold accent "Subagents" header plus
|
|
324
|
+
* one hooked row per running agent in the same `Id: description` shape the
|
|
325
|
+
* inline task rows use (muted task preview when no description was given).
|
|
326
|
+
* Only detached background spawns are listed: a sync task call blocks the
|
|
327
|
+
* parent turn and its inline tool block already renders progress live, and
|
|
328
|
+
* eval `agent()` spawns are rendered by their own eval cell tree.
|
|
329
|
+
* Returns an empty array when nothing is running so the container can clear.
|
|
330
|
+
*/
|
|
331
|
+
export function renderSubagentHudLines(sessions: ObservableSession[], columns: number): string[] {
|
|
332
|
+
const running = sessions.filter(
|
|
333
|
+
session => session.kind === "subagent" && session.status === "active" && session.detached === true,
|
|
334
|
+
);
|
|
335
|
+
if (running.length === 0) return [];
|
|
336
|
+
|
|
337
|
+
const indent = " ";
|
|
338
|
+
const hook = theme.tree.hook;
|
|
339
|
+
const dot = theme.styledSymbol("status.done", "accent");
|
|
340
|
+
const lines = ["", indent + theme.bold(theme.fg("accent", "Subagents"))];
|
|
341
|
+
running.forEach((session, index) => {
|
|
342
|
+
const prefix = `${indent}${index === 0 ? hook : " "} `;
|
|
343
|
+
const displayId = formatTaskId(session.id);
|
|
344
|
+
let line = `${prefix}${dot} ${theme.fg("accent", theme.bold(displayId))}`;
|
|
345
|
+
const description = session.description?.trim() || session.progress?.description?.trim();
|
|
346
|
+
if (description) {
|
|
347
|
+
const budget = Math.max(TRUNCATE_LENGTHS.SHORT, columns - visibleWidth(prefix) - visibleWidth(displayId) - 6);
|
|
348
|
+
line += `${theme.fg("accent", ":")} ${theme.fg("accent", truncateToWidth(replaceTabs(description), budget))}`;
|
|
349
|
+
} else {
|
|
350
|
+
// No spawn description: fall back to a muted task preview, same as
|
|
351
|
+
// the inline task rows when a row has no label.
|
|
352
|
+
const taskPreview = session.progress?.task?.trim();
|
|
353
|
+
if (taskPreview) {
|
|
354
|
+
line += ` ${theme.fg("muted", truncateToWidth(replaceTabs(taskPreview), TRUNCATE_LENGTHS.SHORT))}`;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
lines.push(line);
|
|
358
|
+
});
|
|
359
|
+
return lines;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export class InteractiveMode implements InteractiveModeContext {
|
|
363
|
+
session: AgentSession;
|
|
364
|
+
sessionManager: SessionManager;
|
|
365
|
+
settings: Settings;
|
|
366
|
+
keybindings: KeybindingsManager;
|
|
367
|
+
agent: Agent;
|
|
368
|
+
historyStorage?: HistoryStorage;
|
|
369
|
+
titleSystemPrompt?: string;
|
|
370
|
+
|
|
371
|
+
ui: TUI;
|
|
372
|
+
chatContainer: TranscriptContainer;
|
|
373
|
+
pendingMessagesContainer: Container;
|
|
374
|
+
statusContainer: Container;
|
|
375
|
+
todoContainer: Container;
|
|
376
|
+
subagentContainer: Container;
|
|
377
|
+
btwContainer: Container;
|
|
378
|
+
omfgContainer: Container;
|
|
379
|
+
errorBannerContainer: Container;
|
|
380
|
+
modelCycleContainer: Container;
|
|
381
|
+
editor: CustomEditor;
|
|
382
|
+
editorContainer: Container;
|
|
383
|
+
hookWidgetContainerAbove: Container;
|
|
384
|
+
hookWidgetContainerBelow: Container;
|
|
385
|
+
statusLine: StatusLineComponent;
|
|
386
|
+
|
|
387
|
+
isInitialized = false;
|
|
388
|
+
isBashMode = false;
|
|
389
|
+
toolOutputExpanded = false;
|
|
390
|
+
todoExpanded = false;
|
|
391
|
+
planModeEnabled = false;
|
|
392
|
+
planModePaused = false;
|
|
393
|
+
goalModeEnabled = false;
|
|
394
|
+
goalModePaused = false;
|
|
395
|
+
planModePlanFilePath: string | undefined = undefined;
|
|
396
|
+
loopModeEnabled = false;
|
|
397
|
+
loopPrompt: string | undefined = undefined;
|
|
398
|
+
loopLimit: LoopLimitRuntime | undefined = undefined;
|
|
399
|
+
#loopAutoSubmitTimer: NodeJS.Timeout | undefined;
|
|
400
|
+
#todoAutoClearTimer: NodeJS.Timeout | undefined;
|
|
401
|
+
#modelCycleClearTimer: NodeJS.Timeout | undefined;
|
|
402
|
+
todoPhases: TodoPhase[] = [];
|
|
403
|
+
hideThinkingBlock = false;
|
|
404
|
+
pendingImages: ImageContent[] = [];
|
|
405
|
+
pendingImageLinks: (string | undefined)[] = [];
|
|
406
|
+
compactionQueuedMessages: CompactionQueuedMessage[] = [];
|
|
407
|
+
pendingTools = new Map<string, ToolExecutionHandle>();
|
|
408
|
+
pendingBashComponents: BashExecutionComponent[] = [];
|
|
409
|
+
bashComponent: BashExecutionComponent | undefined = undefined;
|
|
410
|
+
pendingPythonComponents: EvalExecutionComponent[] = [];
|
|
411
|
+
pythonComponent: EvalExecutionComponent | undefined = undefined;
|
|
412
|
+
isPythonMode = false;
|
|
413
|
+
streamingComponent: AssistantMessageComponent | undefined = undefined;
|
|
414
|
+
streamingMessage: AssistantMessage | undefined = undefined;
|
|
415
|
+
lastAssistantUsage: Usage | undefined = undefined;
|
|
416
|
+
loadingAnimation: Loader | undefined = undefined;
|
|
417
|
+
autoCompactionLoader: Loader | undefined = undefined;
|
|
418
|
+
retryLoader: Loader | undefined = undefined;
|
|
419
|
+
#pendingWorkingMessage: string | undefined;
|
|
420
|
+
#workingMessageAccentCacheKey?: WorkingMessageAccentCacheKey;
|
|
421
|
+
#workingMessageAccentCacheValue?: WorkingMessageAccent;
|
|
422
|
+
#workingMessageAccentCacheHasValue = false;
|
|
423
|
+
get #defaultWorkingMessage(): string {
|
|
424
|
+
return `Working…${interruptHint()}`;
|
|
425
|
+
}
|
|
426
|
+
unsubscribe?: () => void;
|
|
427
|
+
onInputCallback?: (input: SubmittedUserInput) => void;
|
|
428
|
+
optimisticUserMessageSignature: string | undefined = undefined;
|
|
429
|
+
locallySubmittedUserSignatures: Set<string> = new Set();
|
|
430
|
+
#pendingSubmittedInput: SubmittedUserInput | undefined;
|
|
431
|
+
#pendingSubmissionDispose: (() => void) | undefined;
|
|
432
|
+
lastSigintTime = 0;
|
|
433
|
+
lastEscapeTime = 0;
|
|
434
|
+
lastLeftTapTime = 0;
|
|
435
|
+
shutdownRequested = false;
|
|
436
|
+
#isShuttingDown = false;
|
|
437
|
+
/** True once `shutdown()` has begun teardown. Surfaced to the input
|
|
438
|
+
* controller so a Ctrl+C arriving while teardown is in flight can hard-
|
|
439
|
+
* abort the remaining work instead of stacking another no-op call. */
|
|
440
|
+
get isShuttingDown(): boolean {
|
|
441
|
+
return this.#isShuttingDown;
|
|
442
|
+
}
|
|
443
|
+
hookSelector: HookSelectorComponent | undefined = undefined;
|
|
444
|
+
hookInput: HookInputComponent | undefined = undefined;
|
|
445
|
+
hookEditor: HookEditorComponent | undefined = undefined;
|
|
446
|
+
lastStatusSpacer: Spacer | undefined = undefined;
|
|
447
|
+
lastStatusText: Text | undefined = undefined;
|
|
448
|
+
fileSlashCommands: Set<string> = new Set();
|
|
449
|
+
skillCommands: Map<string, string> = new Map();
|
|
450
|
+
oauthManualInput: OAuthManualInputManager = new OAuthManualInputManager();
|
|
451
|
+
collabHost?: CollabHost;
|
|
452
|
+
collabGuest?: CollabGuestLink;
|
|
453
|
+
|
|
454
|
+
#pendingSlashCommands: SlashCommand[] = [];
|
|
455
|
+
#cleanupUnsubscribe?: () => void;
|
|
456
|
+
readonly #version: string;
|
|
457
|
+
readonly #changelogMarkdown: string | undefined;
|
|
458
|
+
#planModePreviousTools: string[] | undefined;
|
|
459
|
+
#goalModePreviousTools: string[] | undefined;
|
|
460
|
+
#goalContinuationTimer: NodeJS.Timeout | undefined;
|
|
461
|
+
#goalTurnHadToolCalls = false;
|
|
462
|
+
#goalContinuationTurnInFlight = false;
|
|
463
|
+
#goalSuppressNextContinuation = false;
|
|
464
|
+
#planModePreviousModelState: { model: Model; thinkingLevel?: ThinkingLevel } | undefined;
|
|
465
|
+
#pendingModelSwitch: { model: Model; thinkingLevel?: ThinkingLevel } | undefined;
|
|
466
|
+
#planModeHasEntered = false;
|
|
467
|
+
#planReviewOverlay: PlanReviewOverlay | undefined;
|
|
468
|
+
#planReviewOverlayHandle: OverlayHandle | undefined;
|
|
469
|
+
readonly lspServers: LspStartupServerInfo[] | undefined = undefined;
|
|
470
|
+
mcpManager?: MCPManager;
|
|
471
|
+
readonly #toolUiContextSetter: (uiContext: ExtensionUIContext, hasUI: boolean) => void;
|
|
472
|
+
|
|
473
|
+
readonly #btwController: BtwController;
|
|
474
|
+
readonly #tanCommandController: TanCommandController;
|
|
475
|
+
readonly #omfgController: OmfgController;
|
|
476
|
+
readonly #commandController: CommandController;
|
|
477
|
+
readonly #todoCommandController: TodoCommandController;
|
|
478
|
+
readonly #eventController: EventController;
|
|
479
|
+
get eventController(): EventController {
|
|
480
|
+
return this.#eventController;
|
|
481
|
+
}
|
|
482
|
+
get eventBus(): EventBus | undefined {
|
|
483
|
+
return this.#eventBus;
|
|
484
|
+
}
|
|
485
|
+
readonly #extensionUiController: ExtensionUiController;
|
|
486
|
+
readonly #inputController: InputController;
|
|
487
|
+
readonly #selectorController: SelectorController;
|
|
488
|
+
readonly #focusController: SessionFocusController;
|
|
489
|
+
get viewSession(): AgentSession {
|
|
490
|
+
return this.#focusController.target ?? this.session;
|
|
491
|
+
}
|
|
492
|
+
get focusedAgentId(): string | undefined {
|
|
493
|
+
return this.#focusController.focusedAgentId;
|
|
494
|
+
}
|
|
495
|
+
focusAgentSession(id: string): Promise<void> {
|
|
496
|
+
return this.#focusController.focusAgent(id);
|
|
497
|
+
}
|
|
498
|
+
focusParentSession(): Promise<void> {
|
|
499
|
+
return this.#focusController.focusParent();
|
|
500
|
+
}
|
|
501
|
+
unfocusSession(): Promise<void> {
|
|
502
|
+
return this.#focusController.unfocus();
|
|
503
|
+
}
|
|
504
|
+
clearTransientSessionUi(): void {
|
|
505
|
+
if (this.loadingAnimation) {
|
|
506
|
+
this.loadingAnimation.stop();
|
|
507
|
+
this.loadingAnimation = undefined;
|
|
508
|
+
}
|
|
509
|
+
this.statusContainer.clear();
|
|
510
|
+
this.pendingMessagesContainer.clear();
|
|
511
|
+
this.#cancelModelCycleClearTimer();
|
|
512
|
+
this.modelCycleContainer.clear();
|
|
513
|
+
this.compactionQueuedMessages = [];
|
|
514
|
+
this.streamingComponent = undefined;
|
|
515
|
+
this.streamingMessage = undefined;
|
|
516
|
+
this.lastAssistantUsage = undefined;
|
|
517
|
+
this.pendingTools.clear();
|
|
518
|
+
}
|
|
519
|
+
readonly #uiHelpers: UiHelpers;
|
|
520
|
+
#sttController: STTController | undefined;
|
|
521
|
+
#voiceAnimationInterval: NodeJS.Timeout | undefined;
|
|
522
|
+
#voiceHue = 0;
|
|
523
|
+
#voicePreviousShowHardwareCursor: boolean | null = null;
|
|
524
|
+
#voicePreviousUseTerminalCursor: boolean | null = null;
|
|
525
|
+
#resizeHandler?: () => void;
|
|
526
|
+
#observerRegistry: SessionObserverRegistry;
|
|
527
|
+
#eventBus?: EventBus;
|
|
528
|
+
#eventBusUnsubscribers: Array<() => void> = [];
|
|
529
|
+
#welcomeComponent?: WelcomeComponent;
|
|
530
|
+
readonly #chatHost: ChatBlockHost = { requestRender: () => this.ui.requestRender() };
|
|
531
|
+
|
|
532
|
+
constructor(
|
|
533
|
+
session: AgentSession,
|
|
534
|
+
version: string,
|
|
535
|
+
changelogMarkdown: string | undefined = undefined,
|
|
536
|
+
setToolUIContext: (uiContext: ExtensionUIContext, hasUI: boolean) => void = () => {},
|
|
537
|
+
lspServers: LspStartupServerInfo[] | undefined = undefined,
|
|
538
|
+
mcpManager?: MCPManager,
|
|
539
|
+
eventBus?: EventBus,
|
|
540
|
+
titleSystemPrompt?: string,
|
|
541
|
+
) {
|
|
542
|
+
this.session = session;
|
|
543
|
+
this.sessionManager = session.sessionManager;
|
|
544
|
+
this.settings = session.settings;
|
|
545
|
+
this.keybindings = KeybindingsManager.inMemory();
|
|
546
|
+
this.agent = session.agent;
|
|
547
|
+
this.#version = version;
|
|
548
|
+
this.#changelogMarkdown = changelogMarkdown;
|
|
549
|
+
this.#toolUiContextSetter = setToolUIContext;
|
|
550
|
+
this.lspServers = lspServers;
|
|
551
|
+
this.mcpManager = mcpManager;
|
|
552
|
+
this.#eventBus = eventBus;
|
|
553
|
+
this.titleSystemPrompt = titleSystemPrompt;
|
|
554
|
+
if (eventBus) {
|
|
555
|
+
this.#eventBusUnsubscribers.push(
|
|
556
|
+
eventBus.on(LSP_STARTUP_EVENT_CHANNEL, data => {
|
|
557
|
+
if (this.settings.get("startup.quiet")) return;
|
|
558
|
+
this.#handleLspStartupEvent(data as LspStartupEvent);
|
|
559
|
+
}),
|
|
560
|
+
);
|
|
561
|
+
this.#eventBusUnsubscribers.push(
|
|
562
|
+
eventBus.on(MCP_CONNECTING_EVENT_CHANNEL, data => {
|
|
563
|
+
if (!isMcpConnectingEvent(data)) {
|
|
564
|
+
logger.warn("Ignoring malformed mcp:connecting event", { data });
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (this.settings.get("startup.quiet")) return;
|
|
568
|
+
this.showStatus(formatMCPConnectingMessage(data.serverNames));
|
|
569
|
+
}),
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
setTuiTight(settings.get("tui.tight"));
|
|
574
|
+
this.ui = new TUI(new ProcessTerminal(), settings.get("showHardwareCursor"));
|
|
575
|
+
this.ui.setMaxInlineImages(settings.get("tui.maxInlineImages"));
|
|
576
|
+
// OSC 66 text-sizing is Kitty-only; resolve the setting against the terminal's
|
|
577
|
+
// capability (`TERMINAL.textSizing` defaults on for Kitty) so it stays off
|
|
578
|
+
// unless the user opts in, and never emits raw escapes on other terminals.
|
|
579
|
+
setTerminalTextSizing(settings.get("tui.textSizing") && TERMINAL.textSizing);
|
|
580
|
+
this.chatContainer = new TranscriptContainer();
|
|
581
|
+
this.pendingMessagesContainer = new Container();
|
|
582
|
+
this.statusContainer = new StatusContainer();
|
|
583
|
+
this.todoContainer = new Container();
|
|
584
|
+
this.subagentContainer = new Container();
|
|
585
|
+
this.btwContainer = new Container();
|
|
586
|
+
this.omfgContainer = new Container();
|
|
587
|
+
this.errorBannerContainer = new Container();
|
|
588
|
+
this.modelCycleContainer = new Container();
|
|
589
|
+
this.editor = new CustomEditor(getEditorTheme());
|
|
590
|
+
this.editor.setUseTerminalCursor(this.ui.getShowHardwareCursor());
|
|
591
|
+
this.editor.setAutocompleteMaxVisible(settings.get("autocompleteMaxVisible"));
|
|
592
|
+
this.editor.onAutocompleteCancel = () => {
|
|
593
|
+
this.ui.requestRender(true);
|
|
594
|
+
};
|
|
595
|
+
this.editor.onAutocompleteUpdate = () => {
|
|
596
|
+
this.ui.requestRender();
|
|
597
|
+
};
|
|
598
|
+
this.editor.setShimmerRepaintHandler(() => this.ui.requestComponentRender(this.editor));
|
|
599
|
+
this.#syncEditorMaxHeight();
|
|
600
|
+
this.#resizeHandler = () => {
|
|
601
|
+
this.#syncEditorMaxHeight();
|
|
602
|
+
this.updateEditorTopBorder();
|
|
603
|
+
};
|
|
604
|
+
process.stdout.on("resize", this.#resizeHandler);
|
|
605
|
+
try {
|
|
606
|
+
this.historyStorage = HistoryStorage.open();
|
|
607
|
+
this.editor.setHistoryStorage(this.historyStorage);
|
|
608
|
+
this.historyStorage.setSessionResolver(() => this.sessionManager.getSessionId());
|
|
609
|
+
} catch (error) {
|
|
610
|
+
logger.warn("History storage unavailable", { error: String(error) });
|
|
611
|
+
}
|
|
612
|
+
this.hookWidgetContainerAbove = new Container();
|
|
613
|
+
this.hookWidgetContainerAbove.addChild(new Spacer(1));
|
|
614
|
+
this.hookWidgetContainerBelow = new Container();
|
|
615
|
+
this.editorContainer = new Container();
|
|
616
|
+
this.editorContainer.addChild(this.editor);
|
|
617
|
+
this.statusLine = new StatusLineComponent(session);
|
|
618
|
+
this.statusLine.setAutoCompactEnabled(session.autoCompactionEnabled);
|
|
619
|
+
|
|
620
|
+
this.hideThinkingBlock = settings.get("hideThinkingBlock");
|
|
621
|
+
|
|
622
|
+
const hookCommands: SlashCommand[] = (
|
|
623
|
+
this.session.extensionRunner?.getRegisteredCommands(BUILTIN_SLASH_COMMAND_RESERVED_NAMES) ?? []
|
|
624
|
+
).map(cmd => ({
|
|
625
|
+
name: cmd.name,
|
|
626
|
+
description: cmd.description ?? "(hook command)",
|
|
627
|
+
getArgumentCompletions: cmd.getArgumentCompletions,
|
|
628
|
+
}));
|
|
629
|
+
|
|
630
|
+
// Convert custom commands (TypeScript) to SlashCommand format
|
|
631
|
+
const customCommands: SlashCommand[] = this.session.customCommands.map(loaded => ({
|
|
632
|
+
name: loaded.command.name,
|
|
633
|
+
description: `${loaded.command.description} (${loaded.source})`,
|
|
634
|
+
}));
|
|
635
|
+
|
|
636
|
+
// Build skill commands from session.skills (if enabled)
|
|
637
|
+
const skillCommandList: SlashCommand[] = [];
|
|
638
|
+
if (settings.get("skills.enableSkillCommands")) {
|
|
639
|
+
for (const skill of this.session.skills) {
|
|
640
|
+
const commandName = `skill:${skill.name}`;
|
|
641
|
+
this.skillCommands.set(commandName, skill.filePath);
|
|
642
|
+
skillCommandList.push({ name: commandName, description: skill.description });
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// Store pending commands for init() where file commands are loaded async
|
|
647
|
+
this.#pendingSlashCommands = [...BUILTIN_SLASH_COMMANDS, ...hookCommands, ...customCommands, ...skillCommandList];
|
|
648
|
+
|
|
649
|
+
this.#uiHelpers = new UiHelpers(this);
|
|
650
|
+
this.#btwController = new BtwController(this);
|
|
651
|
+
this.#tanCommandController = new TanCommandController(this);
|
|
652
|
+
this.#omfgController = new OmfgController(this);
|
|
653
|
+
this.#extensionUiController = new ExtensionUiController(this);
|
|
654
|
+
this.#eventController = new EventController(this);
|
|
655
|
+
this.#commandController = new CommandController(this);
|
|
656
|
+
this.#todoCommandController = new TodoCommandController(this);
|
|
657
|
+
this.#selectorController = new SelectorController(this);
|
|
658
|
+
this.#focusController = new SessionFocusController(this);
|
|
659
|
+
this.#inputController = new InputController(this);
|
|
660
|
+
this.#observerRegistry = new SessionObserverRegistry();
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
playWelcomeIntro(): void {
|
|
664
|
+
const welcome = this.#welcomeComponent;
|
|
665
|
+
// Component-scoped: the intro only mutates the welcome box's own rows,
|
|
666
|
+
// so a resumed long transcript is not re-walked per animation frame.
|
|
667
|
+
welcome?.playIntro(() => this.ui.requestComponentRender(welcome));
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
async init(options: InteractiveModeInitOptions = {}): Promise<void> {
|
|
671
|
+
if (this.isInitialized) return;
|
|
672
|
+
|
|
673
|
+
this.keybindings = logger.time("InteractiveMode.init:keybindings", () => KeybindingsManager.create());
|
|
674
|
+
|
|
675
|
+
// Register session manager flush for signal handlers (SIGINT, SIGTERM, SIGHUP)
|
|
676
|
+
this.#cleanupUnsubscribe = postmortem.register("session-manager-flush", () => this.sessionManager.flush());
|
|
677
|
+
|
|
678
|
+
// Wire the report_tool_issue consent gate to the Yes/No dialog popup.
|
|
679
|
+
// The handler is process-global — subagent tools (which can't reach
|
|
680
|
+
// `showHookSelector` on their own) resolve through this exact closure.
|
|
681
|
+
// `Settings.instance` is the disk-backed singleton; passing it explicitly
|
|
682
|
+
// guarantees the decision persists even when the prompt is triggered
|
|
683
|
+
// from a subagent whose own `Settings` is an in-memory snapshot.
|
|
684
|
+
setAutoQaConsentHandler(() => this.#promptAutoQaConsent(), Settings.instance);
|
|
685
|
+
|
|
686
|
+
await logger.time(
|
|
687
|
+
"InteractiveMode.init:slashCommands",
|
|
688
|
+
this.refreshSlashCommandState.bind(this),
|
|
689
|
+
getProjectDir(),
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
// Get current model info for welcome screen
|
|
693
|
+
const modelName = this.session.model?.name ?? "Unknown";
|
|
694
|
+
const providerName = this.session.model?.provider ?? "Unknown";
|
|
695
|
+
|
|
696
|
+
// Get recent sessions
|
|
697
|
+
const recentSessions = await logger.time("InteractiveMode.init:recentSessions", () =>
|
|
698
|
+
getRecentSessions(this.sessionManager.getSessionDir()).then(sessions =>
|
|
699
|
+
sessions.map(s => ({
|
|
700
|
+
name: s.name,
|
|
701
|
+
timeAgo: s.timeAgo,
|
|
702
|
+
})),
|
|
703
|
+
),
|
|
704
|
+
);
|
|
705
|
+
|
|
706
|
+
const startupQuiet = settings.get("startup.quiet");
|
|
707
|
+
this.#welcomeComponent = undefined;
|
|
708
|
+
|
|
709
|
+
for (const warning of this.session.configWarnings) {
|
|
710
|
+
this.ui.addChild(new Text(theme.fg("warning", `Warning: ${warning}`), 1, 0));
|
|
711
|
+
this.ui.addChild(new Spacer(1));
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
if (!startupQuiet) {
|
|
715
|
+
// Add welcome header
|
|
716
|
+
this.#welcomeComponent = new WelcomeComponent(
|
|
717
|
+
this.#version,
|
|
718
|
+
modelName,
|
|
719
|
+
providerName,
|
|
720
|
+
recentSessions,
|
|
721
|
+
this.#getWelcomeLspServers(),
|
|
722
|
+
);
|
|
723
|
+
|
|
724
|
+
// Setup UI layout
|
|
725
|
+
this.ui.addChild(new Spacer(1));
|
|
726
|
+
this.ui.addChild(this.#welcomeComponent);
|
|
727
|
+
this.ui.addChild(new Spacer(1));
|
|
728
|
+
if (!options.suppressWelcomeIntro) {
|
|
729
|
+
this.playWelcomeIntro();
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// Add changelog if provided
|
|
733
|
+
if (this.#changelogMarkdown) {
|
|
734
|
+
this.ui.addChild(new DynamicBorder());
|
|
735
|
+
if (settings.get("collapseChangelog")) {
|
|
736
|
+
const versionMatch = this.#changelogMarkdown.match(/##\s+\[?(\d+\.\d+\.\d+)\]?/);
|
|
737
|
+
const latestVersion = versionMatch ? versionMatch[1] : this.#version;
|
|
738
|
+
const condensedText = `Updated to v${latestVersion}. Use ${theme.bold("/changelog")} to view full changelog.`;
|
|
739
|
+
this.ui.addChild(new Text(condensedText, 1, 0));
|
|
740
|
+
} else {
|
|
741
|
+
this.ui.addChild(new Text(theme.bold(theme.fg("accent", "What's New")), 1, 0));
|
|
742
|
+
this.ui.addChild(new Spacer(1));
|
|
743
|
+
this.ui.addChild(new Markdown(this.#changelogMarkdown.trim(), 1, 0, getMarkdownTheme()));
|
|
744
|
+
this.ui.addChild(new Spacer(1));
|
|
745
|
+
}
|
|
746
|
+
this.ui.addChild(new DynamicBorder());
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
this.ui.addChild(this.chatContainer);
|
|
751
|
+
this.ui.addChild(this.pendingMessagesContainer);
|
|
752
|
+
this.ui.addChild(this.statusContainer);
|
|
753
|
+
this.ui.addChild(this.todoContainer);
|
|
754
|
+
this.ui.addChild(this.subagentContainer);
|
|
755
|
+
this.ui.addChild(this.btwContainer);
|
|
756
|
+
this.ui.addChild(this.omfgContainer);
|
|
757
|
+
this.ui.addChild(this.errorBannerContainer);
|
|
758
|
+
this.ui.addChild(this.modelCycleContainer);
|
|
759
|
+
this.ui.addChild(this.statusLine); // Only renders hook statuses (main status in editor border)
|
|
760
|
+
this.ui.addChild(this.hookWidgetContainerAbove);
|
|
761
|
+
this.ui.addChild(this.editorContainer);
|
|
762
|
+
this.ui.addChild(this.hookWidgetContainerBelow);
|
|
763
|
+
this.ui.setFocus(this.editor);
|
|
764
|
+
|
|
765
|
+
this.#inputController.setupKeyHandlers();
|
|
766
|
+
this.#inputController.setupEditorSubmitHandler();
|
|
767
|
+
|
|
768
|
+
// Wire observer registry to EventBus
|
|
769
|
+
if (this.#eventBus) {
|
|
770
|
+
this.#observerRegistry.subscribeToEventBus(this.#eventBus);
|
|
771
|
+
}
|
|
772
|
+
this.#observerRegistry.setMainSession(this.sessionManager.getSessionFile() ?? undefined);
|
|
773
|
+
this.#observerRegistry.onChange(() => {
|
|
774
|
+
this.statusLine.setSubagentCount(this.#observerRegistry.getActiveSubagentCount());
|
|
775
|
+
// Auto-checkmark todos whose matching subagent just succeeded, then
|
|
776
|
+
// re-render so the running override (the static "live" glyph when a
|
|
777
|
+
// subagent is doing the work for a still-pending todo) updates as
|
|
778
|
+
// subagents start, finish, or fail.
|
|
779
|
+
this.#reconcileTodosWithSubagents();
|
|
780
|
+
this.#syncTodoAutoClearTimer();
|
|
781
|
+
this.#renderTodoList();
|
|
782
|
+
this.#renderSubagentList();
|
|
783
|
+
this.ui.requestRender();
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
// Load initial todos
|
|
787
|
+
await this.#loadTodoList();
|
|
788
|
+
|
|
789
|
+
// Start the UI. Cold `omp` launch opts into clearing on the first paint so
|
|
790
|
+
// the initial welcome frame does not append over the previous run's scrollback.
|
|
791
|
+
this.ui.start({ clearScrollback: options.clearInitialTerminalHistory === true });
|
|
792
|
+
pushTerminalTitle();
|
|
793
|
+
setSessionTerminalTitle(this.sessionManager.getSessionName(), this.sessionManager.getCwd());
|
|
794
|
+
this.updateEditorBorderColor();
|
|
795
|
+
this.#syncEditorMaxHeight();
|
|
796
|
+
this.isInitialized = true;
|
|
797
|
+
this.ui.requestRender(true);
|
|
798
|
+
|
|
799
|
+
// Initialize hooks with TUI-based UI context
|
|
800
|
+
await this.initHooksAndCustomTools();
|
|
801
|
+
|
|
802
|
+
// Restore mode from session (e.g. plan mode on resume)
|
|
803
|
+
this.session.setSessionSwitchReconciler?.(() => this.#reconcileModeFromSession({ preserveActiveGoal: true }));
|
|
804
|
+
await this.#reconcileModeFromSession();
|
|
805
|
+
|
|
806
|
+
// Brand-new sessions optionally start in plan mode when the user has made it
|
|
807
|
+
// the startup default. "Brand-new" means the resolved branch carries no
|
|
808
|
+
// conversation context (buildSessionContext().messages — covers messages,
|
|
809
|
+
// custom messages, branch summaries, and compaction summaries) and the user
|
|
810
|
+
// set no explicit `mode_change` (which #reconcileModeFromSession just
|
|
811
|
+
// restored). SDK startup metadata and extension `custom` state entries are
|
|
812
|
+
// ignored. This way `omp --continue` (or auto-resume) that finds no recent
|
|
813
|
+
// session and creates a fresh one still honors the default, while a session
|
|
814
|
+
// with restored context or an explicit mode keeps its reconciled mode. Scoped
|
|
815
|
+
// to launch (not the switch reconciler above) so /new and the plan-approval →
|
|
816
|
+
// execution handoff clear never get dragged back into plan mode. #enterPlanMode
|
|
817
|
+
// is idempotent and self-guards against an already-active plan/goal mode; it
|
|
818
|
+
// does not check plan.enabled itself.
|
|
819
|
+
const hasConversationContext = this.sessionManager.buildSessionContext().messages.length > 0;
|
|
820
|
+
const hasExplicitMode = this.sessionManager.getEntries().some(entry => entry.type === "mode_change");
|
|
821
|
+
const isFreshSession = !hasConversationContext && !hasExplicitMode;
|
|
822
|
+
if (
|
|
823
|
+
isFreshSession &&
|
|
824
|
+
this.session.settings.get("plan.defaultOnStartup") &&
|
|
825
|
+
this.session.settings.get("plan.enabled")
|
|
826
|
+
) {
|
|
827
|
+
await this.#enterPlanMode();
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// Restore unsent editor draft from previous session shutdown (Ctrl+D).
|
|
831
|
+
// One-shot: consumeDraft removes the sidecar after read so the next
|
|
832
|
+
// resume does not re-restore the same text.
|
|
833
|
+
try {
|
|
834
|
+
const draft = await this.sessionManager.consumeDraft();
|
|
835
|
+
if (draft && !this.editor.getText()) {
|
|
836
|
+
this.editor.setText(draft);
|
|
837
|
+
this.updateEditorBorderColor();
|
|
838
|
+
this.ui.requestRender();
|
|
839
|
+
}
|
|
840
|
+
} catch (err) {
|
|
841
|
+
logger.warn("Failed to restore session draft", { error: String(err) });
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// Subscribe to agent events
|
|
845
|
+
this.#subscribeToAgent();
|
|
846
|
+
|
|
847
|
+
this.#eventBusUnsubscribers.push(
|
|
848
|
+
this.session.subscribe(event => {
|
|
849
|
+
void this.#handleGoalSessionEvent(event);
|
|
850
|
+
}),
|
|
851
|
+
this.sessionManager.onSessionNameChanged(() => {
|
|
852
|
+
this.#handleSessionAccentInputsChanged();
|
|
853
|
+
}),
|
|
854
|
+
onStatusLineSessionAccentChanged(() => {
|
|
855
|
+
this.#syncStatusLineSettings();
|
|
856
|
+
this.#handleSessionAccentInputsChanged();
|
|
857
|
+
}),
|
|
858
|
+
);
|
|
859
|
+
// Set up theme file watcher
|
|
860
|
+
this.#eventBusUnsubscribers.push(
|
|
861
|
+
onThemeChange(() => {
|
|
862
|
+
this.#clearWorkingMessageAccentCache();
|
|
863
|
+
clearRenderCache();
|
|
864
|
+
clearMermaidCache();
|
|
865
|
+
this.ui.invalidate();
|
|
866
|
+
this.updateEditorBorderColor();
|
|
867
|
+
this.ui.requestRender();
|
|
868
|
+
}),
|
|
869
|
+
);
|
|
870
|
+
|
|
871
|
+
// Subscribe to terminal dark/light appearance changes.
|
|
872
|
+
// The terminal queries background color via OSC 11 at startup and on
|
|
873
|
+
// Mode 2031 notifications, computing luminance to detect dark/light.
|
|
874
|
+
this.ui.terminal.onAppearanceChange(mode => {
|
|
875
|
+
onTerminalAppearanceChange(mode);
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
// Set up git branch watcher
|
|
879
|
+
this.statusLine.watchBranch(() => {
|
|
880
|
+
this.updateEditorTopBorder();
|
|
881
|
+
this.ui.requestRender();
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
// Initial top border update
|
|
885
|
+
this.updateEditorTopBorder();
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/** Reload the title-generation system prompt override for the provided working directory. */
|
|
889
|
+
async refreshTitleSystemPrompt(cwd?: string): Promise<void> {
|
|
890
|
+
const basePath = cwd ?? this.sessionManager.getCwd();
|
|
891
|
+
const titleSystemPromptSource = discoverTitleSystemPromptFile(basePath);
|
|
892
|
+
this.titleSystemPrompt = await resolvePromptInput(titleSystemPromptSource, "title system prompt");
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/** Reload slash commands and autocomplete for the provided working directory. */
|
|
896
|
+
async refreshSlashCommandState(cwd?: string): Promise<void> {
|
|
897
|
+
const basePath = cwd ?? this.sessionManager.getCwd();
|
|
898
|
+
const fileCommands = await loadSlashCommands({ cwd: basePath });
|
|
899
|
+
this.fileSlashCommands = new Set(fileCommands.map(cmd => cmd.name));
|
|
900
|
+
const fileSlashCommands: SlashCommand[] = fileCommands.map(cmd => ({
|
|
901
|
+
name: cmd.name,
|
|
902
|
+
description: cmd.description,
|
|
903
|
+
}));
|
|
904
|
+
// Surface discovered prompt templates in the picker. AgentSession.prompt() expands
|
|
905
|
+
// `expandSlashCommand` before `expandPromptTemplate`, and builtin command
|
|
906
|
+
// execution resolves aliases before template expansion. Mirror that command
|
|
907
|
+
// resolution order by skipping templates whose names already appear in any
|
|
908
|
+
// builtin/hook/custom/skill/file command token.
|
|
909
|
+
const reservedNames = new Set<string>();
|
|
910
|
+
for (const command of this.#pendingSlashCommands) {
|
|
911
|
+
reservedNames.add(command.name);
|
|
912
|
+
for (const alias of command.aliases ?? []) reservedNames.add(alias);
|
|
913
|
+
}
|
|
914
|
+
for (const command of fileSlashCommands) {
|
|
915
|
+
reservedNames.add(command.name);
|
|
916
|
+
for (const alias of command.aliases ?? []) reservedNames.add(alias);
|
|
917
|
+
}
|
|
918
|
+
const promptTemplateCommands: SlashCommand[] = this.session.promptTemplates
|
|
919
|
+
.filter(template => !reservedNames.has(template.name))
|
|
920
|
+
.map(template => ({
|
|
921
|
+
name: template.name,
|
|
922
|
+
// `PromptTemplate.description` from `loadTemplatesFromDir` already includes the
|
|
923
|
+
// source suffix (e.g. "Review code (project)"), so pass it through verbatim.
|
|
924
|
+
description: template.description,
|
|
925
|
+
}));
|
|
926
|
+
const autocompleteProvider = this.#inputController.createAutocompleteProvider(
|
|
927
|
+
[...this.#pendingSlashCommands, ...fileSlashCommands, ...promptTemplateCommands],
|
|
928
|
+
basePath,
|
|
929
|
+
);
|
|
930
|
+
this.editor.setAutocompleteProvider(autocompleteProvider);
|
|
931
|
+
this.session.setSlashCommands(fileCommands);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Re-point the process and every cwd-derived cache at `newCwd` after the
|
|
936
|
+
* active session's working directory changed (`/move` relocation or resuming
|
|
937
|
+
* a session from another project). The SessionManager's cwd MUST already
|
|
938
|
+
* reflect `newCwd` before this is called.
|
|
939
|
+
*/
|
|
940
|
+
async applyCwdChange(newCwd: string): Promise<void> {
|
|
941
|
+
setProjectDir(newCwd);
|
|
942
|
+
// Re-scope project settings (`.claude/settings.yml` etc.) to the new
|
|
943
|
+
// directory in place so the active session and every settings reader pick
|
|
944
|
+
// up the destination project's configuration.
|
|
945
|
+
if (isSettingsInitialized()) {
|
|
946
|
+
await settings.reloadForCwd(newCwd);
|
|
947
|
+
// Reapply provider preferences from the newly-loaded settings so the
|
|
948
|
+
// module-level search/image provider state reflects the destination
|
|
949
|
+
// project's configuration. Without this, the previous project's
|
|
950
|
+
// exclusions leak and newly-excluded providers are still used.
|
|
951
|
+
const excludedWebSearchProviders = settings.get("providers.webSearchExclude");
|
|
952
|
+
if (Array.isArray(excludedWebSearchProviders)) {
|
|
953
|
+
setExcludedSearchProviders(excludedWebSearchProviders.filter(isSearchProviderId));
|
|
954
|
+
}
|
|
955
|
+
const webSearchProvider = settings.get("providers.webSearch");
|
|
956
|
+
if (typeof webSearchProvider === "string" && isSearchProviderPreference(webSearchProvider)) {
|
|
957
|
+
setPreferredSearchProvider(webSearchProvider);
|
|
958
|
+
}
|
|
959
|
+
const imageProvider = settings.get("providers.image");
|
|
960
|
+
if (isImageProviderPreference(imageProvider)) {
|
|
961
|
+
setPreferredImageProvider(imageProvider);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
// Re-warm plugin roots, capabilities, slash commands, and the ssh tool so
|
|
965
|
+
// the next prompt sees everything scoped to the new project directory.
|
|
966
|
+
clearClaudePluginRootsCache();
|
|
967
|
+
await this.refreshTitleSystemPrompt(newCwd);
|
|
968
|
+
resetCapabilities();
|
|
969
|
+
await this.refreshSlashCommandState(newCwd);
|
|
970
|
+
await this.session.refreshSshTool({ activateIfAvailable: true });
|
|
971
|
+
setSessionTerminalTitle(this.sessionManager.getSessionName(), this.sessionManager.getCwd());
|
|
972
|
+
this.statusLine.invalidate();
|
|
973
|
+
this.updateEditorTopBorder();
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
async getUserInput(): Promise<SubmittedUserInput> {
|
|
977
|
+
if (this.session.getGoalModeState()?.mode === "exiting") {
|
|
978
|
+
await this.#exitGoalMode({ reason: "completed", silent: true });
|
|
979
|
+
}
|
|
980
|
+
const { promise, resolve } = Promise.withResolvers<SubmittedUserInput>();
|
|
981
|
+
this.onInputCallback = input => {
|
|
982
|
+
this.onInputCallback = undefined;
|
|
983
|
+
resolve(input);
|
|
984
|
+
};
|
|
985
|
+
this.#scheduleLoopAutoSubmit();
|
|
986
|
+
this.#scheduleGoalContinuation();
|
|
987
|
+
|
|
988
|
+
using _ = new EventLoopKeepalive();
|
|
989
|
+
return await promise;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
#scheduleLoopAutoSubmit(): void {
|
|
993
|
+
this.#cancelLoopAutoSubmit();
|
|
994
|
+
if (!this.loopModeEnabled || !this.loopPrompt) return;
|
|
995
|
+
const prompt = this.loopPrompt;
|
|
996
|
+
const loopAction = settings.get("loop.mode");
|
|
997
|
+
this.#deferLoopAutoSubmit(() => {
|
|
998
|
+
void this.#runLoopIteration(loopAction, prompt);
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
#deferLoopAutoSubmit(callback: () => void): void {
|
|
1003
|
+
// Brief delay so the user has a chance to press Esc between iterations.
|
|
1004
|
+
this.#loopAutoSubmitTimer = setTimeout(() => {
|
|
1005
|
+
this.#loopAutoSubmitTimer = undefined;
|
|
1006
|
+
if (!this.loopModeEnabled || !this.onInputCallback) return;
|
|
1007
|
+
callback();
|
|
1008
|
+
}, 800);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
#cancelLoopAutoSubmit(): void {
|
|
1012
|
+
if (this.#loopAutoSubmitTimer) {
|
|
1013
|
+
clearTimeout(this.#loopAutoSubmitTimer);
|
|
1014
|
+
this.#loopAutoSubmitTimer = undefined;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
#scheduleGoalContinuation(): void {
|
|
1019
|
+
this.#cancelGoalContinuation();
|
|
1020
|
+
if (this.loopModeEnabled) return;
|
|
1021
|
+
if (!this.onInputCallback) return;
|
|
1022
|
+
if (!this.session.settings.get("goal.continuationModes").includes("interactive")) return;
|
|
1023
|
+
if (this.planModeEnabled || this.planModePaused) return;
|
|
1024
|
+
if (!this.goalModeEnabled || this.goalModePaused) return;
|
|
1025
|
+
if (this.#goalSuppressNextContinuation) return;
|
|
1026
|
+
if (this.#pendingSubmittedInput) return;
|
|
1027
|
+
if (this.editor.getText().trim().length > 0) return;
|
|
1028
|
+
if ((this.pendingImages?.length ?? 0) > 0) return;
|
|
1029
|
+
const state = this.session.getGoalModeState();
|
|
1030
|
+
if (!state?.enabled || state.goal.status !== "active") return;
|
|
1031
|
+
const prompt = this.session.goalRuntime.buildContinuationPrompt();
|
|
1032
|
+
if (!prompt) return;
|
|
1033
|
+
this.#goalContinuationTimer = setTimeout(() => {
|
|
1034
|
+
this.#goalContinuationTimer = undefined;
|
|
1035
|
+
if (!this.onInputCallback) return;
|
|
1036
|
+
if (!this.goalModeEnabled || this.goalModePaused) return;
|
|
1037
|
+
// The 800ms timer can outlive the idle window that scheduled it: a
|
|
1038
|
+
// `/goal set` taken via the streaming branch (or any extension/hook
|
|
1039
|
+
// path that starts a turn while we wait) leaves the agent busy. Firing
|
|
1040
|
+
// the continuation now would route through `submitInteractiveInput` →
|
|
1041
|
+
// `promptCustomMessage` with no `streamingBehavior` and resurface
|
|
1042
|
+
// `AgentBusyError`. Drop this tick; `#handleGoalSessionEvent` reschedules
|
|
1043
|
+
// on the next `agent_end`.
|
|
1044
|
+
if (this.#isAutoSubmitBlocked()) return;
|
|
1045
|
+
if (this.#pendingSubmittedInput) return;
|
|
1046
|
+
if (this.editor.getText().trim().length > 0) return;
|
|
1047
|
+
if ((this.pendingImages?.length ?? 0) > 0) return;
|
|
1048
|
+
const latestState = this.session.getGoalModeState();
|
|
1049
|
+
if (!latestState?.enabled || latestState.goal.status !== "active") return;
|
|
1050
|
+
this.#goalContinuationTurnInFlight = true;
|
|
1051
|
+
this.onInputCallback(
|
|
1052
|
+
this.startPendingSubmission({
|
|
1053
|
+
text: prompt,
|
|
1054
|
+
customType: "goal-continuation",
|
|
1055
|
+
display: false,
|
|
1056
|
+
}),
|
|
1057
|
+
);
|
|
1058
|
+
}, 800);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
#cancelGoalContinuation(): void {
|
|
1062
|
+
if (this.#goalContinuationTimer) {
|
|
1063
|
+
clearTimeout(this.#goalContinuationTimer);
|
|
1064
|
+
this.#goalContinuationTimer = undefined;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
#isAutoSubmitBlocked(): boolean {
|
|
1069
|
+
return this.session.isStreaming || this.session.isCompacting || this.session.hasPostPromptWork;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
#submitLoopPromptWhenReady(prompt: string): void {
|
|
1073
|
+
if (!this.loopModeEnabled || this.loopPrompt !== prompt || !this.onInputCallback) return;
|
|
1074
|
+
if (isLoopDurationExpired(this.loopLimit)) {
|
|
1075
|
+
this.disableLoopMode("Loop time limit reached. Loop mode disabled.");
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
if (this.#isAutoSubmitBlocked()) {
|
|
1079
|
+
this.#deferLoopAutoSubmit(() => this.#submitLoopPromptWhenReady(prompt));
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
this.onInputCallback(this.startPendingSubmission({ text: prompt }));
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
async #runLoopIteration(action: "prompt" | "compact" | "reset", prompt: string): Promise<void> {
|
|
1086
|
+
if (!this.loopModeEnabled || this.loopPrompt !== prompt || !this.onInputCallback) return;
|
|
1087
|
+
if (this.#isAutoSubmitBlocked()) {
|
|
1088
|
+
this.#deferLoopAutoSubmit(() => {
|
|
1089
|
+
void this.#runLoopIteration(action, prompt);
|
|
1090
|
+
});
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
if (!consumeLoopLimitIteration(this.loopLimit)) {
|
|
1095
|
+
this.disableLoopMode("Loop limit reached. Loop mode disabled.");
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
if (action === "compact") {
|
|
1100
|
+
await this.handleCompactCommand();
|
|
1101
|
+
} else if (action === "reset") {
|
|
1102
|
+
await this.handleClearCommand();
|
|
1103
|
+
}
|
|
1104
|
+
this.#submitLoopPromptWhenReady(prompt);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
disableLoopMode(message = "Loop mode disabled."): void {
|
|
1108
|
+
const wasEnabled = this.loopModeEnabled;
|
|
1109
|
+
this.loopModeEnabled = false;
|
|
1110
|
+
this.loopPrompt = undefined;
|
|
1111
|
+
this.loopLimit = undefined;
|
|
1112
|
+
this.#cancelLoopAutoSubmit();
|
|
1113
|
+
this.statusLine.setLoopModeStatus(undefined);
|
|
1114
|
+
this.updateEditorTopBorder();
|
|
1115
|
+
this.ui.requestRender();
|
|
1116
|
+
if (wasEnabled) {
|
|
1117
|
+
this.showStatus(message);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Pause the loop without exiting it: drops the captured prompt and any
|
|
1123
|
+
* pending auto-resubmit. Loop mode stays enabled — the next prompt the
|
|
1124
|
+
* user submits becomes the new loop prompt and resumes iteration.
|
|
1125
|
+
*/
|
|
1126
|
+
pauseLoop(): void {
|
|
1127
|
+
this.loopPrompt = undefined;
|
|
1128
|
+
this.#cancelLoopAutoSubmit();
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
async handleLoopCommand(args = ""): Promise<string | undefined> {
|
|
1132
|
+
if (this.loopModeEnabled) {
|
|
1133
|
+
this.disableLoopMode();
|
|
1134
|
+
return undefined;
|
|
1135
|
+
}
|
|
1136
|
+
const parsed = parseLoopLimitArgs(args);
|
|
1137
|
+
if (typeof parsed === "string") {
|
|
1138
|
+
this.showError(parsed);
|
|
1139
|
+
return undefined;
|
|
1140
|
+
}
|
|
1141
|
+
this.loopModeEnabled = true;
|
|
1142
|
+
this.loopPrompt = undefined;
|
|
1143
|
+
this.loopLimit = createLoopLimitRuntime(parsed.limit);
|
|
1144
|
+
this.statusLine.setLoopModeStatus({ enabled: true });
|
|
1145
|
+
this.updateEditorTopBorder();
|
|
1146
|
+
this.ui.requestRender();
|
|
1147
|
+
const limitSuffix = parsed.limit ? ` Limited to ${describeLoopLimit(parsed.limit)}.` : "";
|
|
1148
|
+
const remainingSuffix = this.loopLimit ? ` ${describeLoopLimitRuntime(this.loopLimit)}.` : "";
|
|
1149
|
+
const tail = parsed.prompt ? "Repeating it after each turn." : "Your next prompt will repeat after each turn.";
|
|
1150
|
+
this.showStatus(
|
|
1151
|
+
`Loop mode enabled.${limitSuffix}${remainingSuffix} ${tail} Esc cancels the current iteration; /loop again to disable.`,
|
|
1152
|
+
);
|
|
1153
|
+
// Hand any inline prompt back to the dispatcher so the normal submit flow
|
|
1154
|
+
// runs the first iteration — it records the text as the loop prompt and
|
|
1155
|
+
// auto-resubmits it after each yield, identical to typing the prompt right
|
|
1156
|
+
// after enabling loop mode.
|
|
1157
|
+
return parsed.prompt;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
recordLocalSubmission(text: string, imageCount = 0): () => void {
|
|
1161
|
+
if (this.isKnownSlashCommand(text)) {
|
|
1162
|
+
return () => {};
|
|
1163
|
+
}
|
|
1164
|
+
const signature = `${text}\u0000${imageCount}`;
|
|
1165
|
+
this.locallySubmittedUserSignatures.add(signature);
|
|
1166
|
+
let disposed = false;
|
|
1167
|
+
return () => {
|
|
1168
|
+
if (disposed) return;
|
|
1169
|
+
disposed = true;
|
|
1170
|
+
this.locallySubmittedUserSignatures.delete(signature);
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
async withLocalSubmission<T>(text: string, fn: () => Promise<T>, options?: { imageCount?: number }): Promise<T> {
|
|
1175
|
+
const dispose = this.recordLocalSubmission(text, options?.imageCount ?? 0);
|
|
1176
|
+
try {
|
|
1177
|
+
return await fn();
|
|
1178
|
+
} catch (err) {
|
|
1179
|
+
dispose();
|
|
1180
|
+
throw err;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
startPendingSubmission(input: {
|
|
1185
|
+
text: string;
|
|
1186
|
+
images?: ImageContent[];
|
|
1187
|
+
imageLinks?: (string | undefined)[];
|
|
1188
|
+
customType?: string;
|
|
1189
|
+
display?: boolean;
|
|
1190
|
+
streamingBehavior?: "steer" | "followUp";
|
|
1191
|
+
}): SubmittedUserInput {
|
|
1192
|
+
const submission: SubmittedUserInput = {
|
|
1193
|
+
text: input.text,
|
|
1194
|
+
images: input.images,
|
|
1195
|
+
imageLinks: input.imageLinks,
|
|
1196
|
+
customType: input.customType,
|
|
1197
|
+
display: input.display,
|
|
1198
|
+
streamingBehavior: input.streamingBehavior,
|
|
1199
|
+
cancelled: false,
|
|
1200
|
+
started: false,
|
|
1201
|
+
};
|
|
1202
|
+
this.#pendingSubmittedInput = submission;
|
|
1203
|
+
if (!submission.customType) {
|
|
1204
|
+
this.#resetGoalContinuationSuppression();
|
|
1205
|
+
const imageCount = submission.images?.length ?? 0;
|
|
1206
|
+
this.optimisticUserMessageSignature = `${submission.text}\u0000${imageCount}`;
|
|
1207
|
+
this.#pendingSubmissionDispose = this.recordLocalSubmission(submission.text, imageCount);
|
|
1208
|
+
this.addMessageToChat(
|
|
1209
|
+
{
|
|
1210
|
+
role: "user",
|
|
1211
|
+
content: [{ type: "text", text: submission.text }, ...(submission.images ?? [])],
|
|
1212
|
+
attribution: "user",
|
|
1213
|
+
timestamp: Date.now(),
|
|
1214
|
+
},
|
|
1215
|
+
{ imageLinks: input.imageLinks },
|
|
1216
|
+
);
|
|
1217
|
+
} else {
|
|
1218
|
+
this.optimisticUserMessageSignature = undefined;
|
|
1219
|
+
this.#pendingSubmissionDispose = undefined;
|
|
1220
|
+
}
|
|
1221
|
+
this.editor.setText("");
|
|
1222
|
+
this.editor.imageLinks = undefined;
|
|
1223
|
+
this.ensureLoadingAnimation();
|
|
1224
|
+
this.ui.requestRender();
|
|
1225
|
+
return submission;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
cancelPendingSubmission(): boolean {
|
|
1229
|
+
const submission = this.#pendingSubmittedInput;
|
|
1230
|
+
if (!submission || submission.started) {
|
|
1231
|
+
return false;
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
submission.cancelled = true;
|
|
1235
|
+
this.#pendingSubmittedInput = undefined;
|
|
1236
|
+
this.optimisticUserMessageSignature = undefined;
|
|
1237
|
+
this.#pendingSubmissionDispose?.();
|
|
1238
|
+
this.#pendingSubmissionDispose = undefined;
|
|
1239
|
+
this.#pendingWorkingMessage = undefined;
|
|
1240
|
+
if (submission.customType === "goal-continuation") {
|
|
1241
|
+
this.#goalContinuationTurnInFlight = false;
|
|
1242
|
+
}
|
|
1243
|
+
if (this.loadingAnimation) {
|
|
1244
|
+
this.#stopLoadingAnimation(true);
|
|
1245
|
+
}
|
|
1246
|
+
if (!submission.customType) {
|
|
1247
|
+
this.pendingImages = submission.images ? [...submission.images] : [];
|
|
1248
|
+
this.pendingImageLinks = submission.imageLinks ? [...submission.imageLinks] : [];
|
|
1249
|
+
this.editor.imageLinks = this.pendingImageLinks;
|
|
1250
|
+
this.rebuildChatFromMessages();
|
|
1251
|
+
this.editor.setText(submission.text);
|
|
1252
|
+
}
|
|
1253
|
+
this.updateEditorBorderColor();
|
|
1254
|
+
this.ui.requestRender();
|
|
1255
|
+
return true;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
markPendingSubmissionStarted(input: SubmittedUserInput): boolean {
|
|
1259
|
+
if (this.#pendingSubmittedInput !== input || input.cancelled) {
|
|
1260
|
+
return false;
|
|
1261
|
+
}
|
|
1262
|
+
input.started = true;
|
|
1263
|
+
return true;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
finishPendingSubmission(input: SubmittedUserInput): void {
|
|
1267
|
+
const wasPendingSubmission = this.#pendingSubmittedInput === input;
|
|
1268
|
+
const pendingSubmissionDispose = this.#pendingSubmissionDispose;
|
|
1269
|
+
if (wasPendingSubmission) {
|
|
1270
|
+
this.#pendingSubmittedInput = undefined;
|
|
1271
|
+
this.#pendingSubmissionDispose = undefined;
|
|
1272
|
+
}
|
|
1273
|
+
if (input.customType === "goal-continuation") {
|
|
1274
|
+
this.#goalContinuationTurnInFlight = false;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
if (wasPendingSubmission && !this.session.isStreaming && !this.streamingComponent) {
|
|
1278
|
+
this.optimisticUserMessageSignature = undefined;
|
|
1279
|
+
pendingSubmissionDispose?.();
|
|
1280
|
+
this.#pendingWorkingMessage = undefined;
|
|
1281
|
+
if (this.loadingAnimation) {
|
|
1282
|
+
this.#stopLoadingAnimation(true);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
#computeEditorMaxHeight(): number {
|
|
1288
|
+
return computeEditorMaxHeight(this.ui.terminal.rows);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
#syncEditorMaxHeight(): void {
|
|
1292
|
+
this.editor.setMaxHeight(this.#computeEditorMaxHeight());
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
#syncStatusLineSettings(): void {
|
|
1296
|
+
this.statusLine.updateSettings({
|
|
1297
|
+
preset: settings.get("statusLine.preset"),
|
|
1298
|
+
leftSegments: settings.get("statusLine.leftSegments"),
|
|
1299
|
+
rightSegments: settings.get("statusLine.rightSegments"),
|
|
1300
|
+
separator: settings.get("statusLine.separator"),
|
|
1301
|
+
showHookStatus: settings.get("statusLine.showHookStatus"),
|
|
1302
|
+
sessionAccent: settings.get("statusLine.sessionAccent"),
|
|
1303
|
+
transparent: settings.get("statusLine.transparent"),
|
|
1304
|
+
segmentOptions: settings.get("statusLine.segmentOptions"),
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
#handleSessionAccentInputsChanged(): void {
|
|
1309
|
+
this.#clearWorkingMessageAccentCache();
|
|
1310
|
+
this.statusLine.invalidate();
|
|
1311
|
+
this.updateEditorBorderColor();
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
updateEditorBorderColor(): void {
|
|
1315
|
+
if (this.isBashMode) {
|
|
1316
|
+
this.editor.borderColor = theme.getBashModeBorderColor();
|
|
1317
|
+
} else if (this.isPythonMode) {
|
|
1318
|
+
this.editor.borderColor = theme.getPythonModeBorderColor();
|
|
1319
|
+
} else {
|
|
1320
|
+
const accentEnabled = !isSettingsInitialized() || settings.get("statusLine.sessionAccent") !== false;
|
|
1321
|
+
const sessionName = accentEnabled ? this.sessionManager.getSessionName() : undefined;
|
|
1322
|
+
const hex = sessionName
|
|
1323
|
+
? getSessionAccentHex(sessionName, theme.getMajorThemeColorHexes(), theme.accentSurfaceLuminance)
|
|
1324
|
+
: undefined;
|
|
1325
|
+
const ansi = getSessionAccentAnsi(hex);
|
|
1326
|
+
if (ansi) {
|
|
1327
|
+
this.editor.borderColor = (str: string) => `${ansi}${str}\x1b[39m`;
|
|
1328
|
+
} else {
|
|
1329
|
+
const level = this.session.thinkingLevel ?? ThinkingLevel.Off;
|
|
1330
|
+
this.editor.borderColor = theme.getThinkingBorderColor(level);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (this.focusedAgentId) {
|
|
1334
|
+
// Focused subagent view: faint the outline so the borrowed session is
|
|
1335
|
+
// visually distinct from the main one.
|
|
1336
|
+
const base = this.editor.borderColor;
|
|
1337
|
+
this.editor.borderColor = (str: string) => `\x1b[2m${base(str)}\x1b[22m`;
|
|
1338
|
+
}
|
|
1339
|
+
this.updateEditorTopBorder();
|
|
1340
|
+
this.ui.requestRender();
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
updateEditorTopBorder(): void {
|
|
1344
|
+
const availableWidth = this.editor.getTopBorderAvailableWidth(this.ui.terminal.columns);
|
|
1345
|
+
const topBorder = this.statusLine.getTopBorder(availableWidth);
|
|
1346
|
+
this.editor.setTopBorder(topBorder);
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
rebuildChatFromMessages(): void {
|
|
1350
|
+
this.chatContainer.clear();
|
|
1351
|
+
// Full-history transcript: compactions render as inline dividers instead
|
|
1352
|
+
// of restarting the visible conversation (the LLM context still resets).
|
|
1353
|
+
const context = this.viewSession.buildTranscriptSessionContext();
|
|
1354
|
+
this.renderSessionContext(context);
|
|
1355
|
+
// During the pre-streaming window — after `startPendingSubmission` has
|
|
1356
|
+
// optimistically rendered the user's message but before the user
|
|
1357
|
+
// `message_start` event lands it in `session` entries — any rebuild
|
|
1358
|
+
// (e.g. Ctrl+T toggleThinkingBlockVisibility, theme selector) would
|
|
1359
|
+
// otherwise erase the user's just-submitted message until the first
|
|
1360
|
+
// assistant token arrived (#2372). Once `message_start` fires the
|
|
1361
|
+
// signature is cleared by `EventController`, so this replay is a no-op
|
|
1362
|
+
// post-streaming and cannot duplicate.
|
|
1363
|
+
this.#replayOptimisticUserMessage();
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
#replayOptimisticUserMessage(): void {
|
|
1367
|
+
if (!this.optimisticUserMessageSignature) return;
|
|
1368
|
+
const submission = this.#pendingSubmittedInput;
|
|
1369
|
+
if (!submission || submission.cancelled || submission.customType) return;
|
|
1370
|
+
this.addMessageToChat(
|
|
1371
|
+
{
|
|
1372
|
+
role: "user",
|
|
1373
|
+
content: [{ type: "text", text: submission.text }, ...(submission.images ?? [])],
|
|
1374
|
+
attribution: "user",
|
|
1375
|
+
timestamp: Date.now(),
|
|
1376
|
+
},
|
|
1377
|
+
{ imageLinks: submission.imageLinks },
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
#formatTodoLine(todo: TodoItem, prefix: string, matched: boolean): string {
|
|
1382
|
+
const checkbox = theme.checkbox;
|
|
1383
|
+
const marker = formatHudNoteMarker(todo.notes?.length ?? 0);
|
|
1384
|
+
switch (todo.status) {
|
|
1385
|
+
case "completed":
|
|
1386
|
+
return theme.fg("success", `${prefix}${checkbox.checked} ${chalk.strikethrough(todo.content)}`) + marker;
|
|
1387
|
+
case "in_progress":
|
|
1388
|
+
return theme.fg("accent", `${prefix}${checkbox.unchecked} ${todo.content}`) + marker;
|
|
1389
|
+
case "abandoned":
|
|
1390
|
+
return theme.fg("error", `${prefix}${checkbox.unchecked} ${chalk.strikethrough(todo.content)}`) + marker;
|
|
1391
|
+
default:
|
|
1392
|
+
if (matched) {
|
|
1393
|
+
return theme.fg("accent", `${prefix}${checkbox.unchecked} ${todo.content}`) + marker;
|
|
1394
|
+
}
|
|
1395
|
+
return theme.fg("dim", `${prefix}${checkbox.unchecked} ${todo.content}`) + marker;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
#getActiveSubagentDescriptions(): string[] {
|
|
1400
|
+
const out: string[] = [];
|
|
1401
|
+
for (const session of this.#observerRegistry.getSessions()) {
|
|
1402
|
+
if (session.kind !== "subagent") continue;
|
|
1403
|
+
if (session.status !== "active") continue;
|
|
1404
|
+
const candidate =
|
|
1405
|
+
session.description?.trim() || session.progress?.description?.trim() || session.label?.trim();
|
|
1406
|
+
if (candidate) out.push(candidate);
|
|
1407
|
+
}
|
|
1408
|
+
return out;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
/**
|
|
1412
|
+
* Auto-complete any pending/in_progress todo whose content matches a
|
|
1413
|
+
* subagent that has finished successfully. Fires on every observer
|
|
1414
|
+
* `onChange` so the visual state stays in sync with subagent lifecycle
|
|
1415
|
+
* without requiring the agent to issue a follow-up `todo`. Failed
|
|
1416
|
+
* and aborted subagents are intentionally NOT auto-completed — those
|
|
1417
|
+
* stay open so the user (or the next agent turn) can decide what to do.
|
|
1418
|
+
*
|
|
1419
|
+
* Idempotent: only flips open tasks, never re-touches completed ones.
|
|
1420
|
+
*/
|
|
1421
|
+
#reconcileTodosWithSubagents(): void {
|
|
1422
|
+
const completedDescs: string[] = [];
|
|
1423
|
+
for (const session of this.#observerRegistry.getSessions()) {
|
|
1424
|
+
if (session.kind !== "subagent") continue;
|
|
1425
|
+
if (session.status !== "completed") continue;
|
|
1426
|
+
const candidate =
|
|
1427
|
+
session.description?.trim() || session.progress?.description?.trim() || session.label?.trim();
|
|
1428
|
+
if (candidate) completedDescs.push(candidate);
|
|
1429
|
+
}
|
|
1430
|
+
if (completedDescs.length === 0) return;
|
|
1431
|
+
|
|
1432
|
+
let mutated = false;
|
|
1433
|
+
const next: TodoPhase[] = this.todoPhases.map(phase => ({
|
|
1434
|
+
name: phase.name,
|
|
1435
|
+
tasks: phase.tasks.map(task => {
|
|
1436
|
+
if (task.status !== "pending" && task.status !== "in_progress") return task;
|
|
1437
|
+
if (!todoMatchesAnyDescription(task.content, completedDescs)) return task;
|
|
1438
|
+
mutated = true;
|
|
1439
|
+
return { ...task, status: "completed" as const };
|
|
1440
|
+
}),
|
|
1441
|
+
}));
|
|
1442
|
+
if (!mutated) return;
|
|
1443
|
+
this.todoPhases = next;
|
|
1444
|
+
this.session.setTodoPhases(next);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
#cancelTodoAutoClearTimer(): void {
|
|
1448
|
+
if (!this.#todoAutoClearTimer) return;
|
|
1449
|
+
clearTimeout(this.#todoAutoClearTimer);
|
|
1450
|
+
this.#todoAutoClearTimer = undefined;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
#isClosedTodo(task: TodoItem): boolean {
|
|
1454
|
+
return task.status === "completed" || task.status === "abandoned";
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
#hasClosedTodos(phases: TodoPhase[]): boolean {
|
|
1458
|
+
return phases.some(phase => phase.tasks.some(task => this.#isClosedTodo(task)));
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
#removeClosedTodos(phases: TodoPhase[]): TodoPhase[] {
|
|
1462
|
+
const next: TodoPhase[] = [];
|
|
1463
|
+
for (const phase of phases) {
|
|
1464
|
+
const tasks = phase.tasks.filter(task => !this.#isClosedTodo(task));
|
|
1465
|
+
if (tasks.length > 0) next.push({ name: phase.name, tasks });
|
|
1466
|
+
}
|
|
1467
|
+
return next;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
#syncTodoAutoClearTimer(): void {
|
|
1471
|
+
this.#cancelTodoAutoClearTimer();
|
|
1472
|
+
const delaySeconds = this.settings.get("tasks.todoClearDelay");
|
|
1473
|
+
if (!Number.isFinite(delaySeconds) || delaySeconds < 0 || !this.#hasClosedTodos(this.todoPhases)) return;
|
|
1474
|
+
if (delaySeconds === 0) {
|
|
1475
|
+
this.todoPhases = this.#removeClosedTodos(this.todoPhases);
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
this.#todoAutoClearTimer = setTimeout(() => {
|
|
1480
|
+
this.#todoAutoClearTimer = undefined;
|
|
1481
|
+
this.todoPhases = this.#removeClosedTodos(this.todoPhases);
|
|
1482
|
+
this.#renderTodoList();
|
|
1483
|
+
this.ui.requestRender();
|
|
1484
|
+
}, delaySeconds * 1000);
|
|
1485
|
+
this.#todoAutoClearTimer.unref?.();
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* Render the ctrl+p model-role cycle chip track into its own anchored
|
|
1490
|
+
* container (just above the editor), mirroring the todo HUD: the container is
|
|
1491
|
+
* cleared and rebuilt in place on every cycle, so rapid presses or concurrent
|
|
1492
|
+
* chat activity can never stack duplicate tracks into the scrollback.
|
|
1493
|
+
*/
|
|
1494
|
+
showModelCycleTrack(track: string): void {
|
|
1495
|
+
this.#renderModelCycleTrack(track);
|
|
1496
|
+
this.#syncModelCycleClearTimer();
|
|
1497
|
+
this.ui.requestRender();
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
#renderModelCycleTrack(track: string | null): void {
|
|
1501
|
+
this.modelCycleContainer.clear();
|
|
1502
|
+
if (!track) return;
|
|
1503
|
+
this.modelCycleContainer.addChild(new Spacer(1));
|
|
1504
|
+
this.modelCycleContainer.addChild(new Text(track, 1, 0));
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
#cancelModelCycleClearTimer(): void {
|
|
1508
|
+
if (!this.#modelCycleClearTimer) return;
|
|
1509
|
+
clearTimeout(this.#modelCycleClearTimer);
|
|
1510
|
+
this.#modelCycleClearTimer = undefined;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
#syncModelCycleClearTimer(): void {
|
|
1514
|
+
this.#cancelModelCycleClearTimer();
|
|
1515
|
+
this.#modelCycleClearTimer = setTimeout(() => {
|
|
1516
|
+
this.#modelCycleClearTimer = undefined;
|
|
1517
|
+
this.#renderModelCycleTrack(null);
|
|
1518
|
+
this.ui.requestRender();
|
|
1519
|
+
}, MODEL_CYCLE_TRACK_CLEAR_MS);
|
|
1520
|
+
this.#modelCycleClearTimer.unref?.();
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
#getActivePhase(phases: TodoPhase[]): TodoPhase | undefined {
|
|
1524
|
+
const nonEmpty = phases.filter(phase => phase.tasks.length > 0);
|
|
1525
|
+
const active = nonEmpty.find(phase =>
|
|
1526
|
+
phase.tasks.some(task => task.status === "pending" || task.status === "in_progress"),
|
|
1527
|
+
);
|
|
1528
|
+
return active ?? nonEmpty[nonEmpty.length - 1];
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
#renderTodoList(): void {
|
|
1532
|
+
this.todoContainer.clear();
|
|
1533
|
+
const phases = this.todoPhases.filter(phase => phase.tasks.length > 0);
|
|
1534
|
+
if (phases.length === 0) return;
|
|
1535
|
+
const indent = " ";
|
|
1536
|
+
const hook = theme.tree.hook;
|
|
1537
|
+
const lines = ["", indent + theme.bold(theme.fg("accent", "Todos"))];
|
|
1538
|
+
|
|
1539
|
+
const activeDescs = this.#getActiveSubagentDescriptions();
|
|
1540
|
+
// A pending todo "lights up" (accent + running glyph) when an in-flight
|
|
1541
|
+
// subagent is doing its work, matched by normalized content overlap.
|
|
1542
|
+
const isMatched = (todo: TodoItem): boolean =>
|
|
1543
|
+
activeDescs.length > 0 && todoMatchesAnyDescription(todo.content, activeDescs);
|
|
1544
|
+
|
|
1545
|
+
if (!this.todoExpanded) {
|
|
1546
|
+
const activeIdx = phases.indexOf(this.#getActivePhase(phases) ?? phases[0]);
|
|
1547
|
+
const activePhase = phases[activeIdx];
|
|
1548
|
+
if (!activePhase) return;
|
|
1549
|
+
const { visible, hiddenOpenCount } = selectStickyTodoWindow(activePhase.tasks, 5);
|
|
1550
|
+
|
|
1551
|
+
lines.push(
|
|
1552
|
+
`${indent}${theme.fg("accent", `${hook} ${formatPhaseDisplayName(activePhase.name, activeIdx + 1)}`)}`,
|
|
1553
|
+
);
|
|
1554
|
+
visible.forEach((todo, index) => {
|
|
1555
|
+
const prefix = `${indent}${index === 0 ? hook : " "} `;
|
|
1556
|
+
lines.push(this.#formatTodoLine(todo, prefix, isMatched(todo)));
|
|
1557
|
+
});
|
|
1558
|
+
if (hiddenOpenCount > 0) {
|
|
1559
|
+
lines.push(theme.fg("muted", `${indent} ${hook} +${hiddenOpenCount} more`));
|
|
1560
|
+
}
|
|
1561
|
+
this.todoContainer.addChild(new Text(lines.join("\n"), 1, 0));
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
phases.forEach((phase, phaseIndex) => {
|
|
1566
|
+
lines.push(`${indent}${theme.fg("accent", `${hook} ${formatPhaseDisplayName(phase.name, phaseIndex + 1)}`)}`);
|
|
1567
|
+
phase.tasks.forEach((todo, index) => {
|
|
1568
|
+
const prefix = `${indent}${index === 0 ? hook : " "} `;
|
|
1569
|
+
lines.push(this.#formatTodoLine(todo, prefix, isMatched(todo)));
|
|
1570
|
+
});
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
this.todoContainer.addChild(new Text(lines.join("\n"), 1, 0));
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* Anchored HUD of in-flight subagents, mirroring the Todos block above the
|
|
1578
|
+
* editor. Driven entirely by observer-registry change events, so rows appear
|
|
1579
|
+
* on spawn and the whole block clears itself once the last subagent leaves
|
|
1580
|
+
* the "active" state.
|
|
1581
|
+
*/
|
|
1582
|
+
#renderSubagentList(): void {
|
|
1583
|
+
this.subagentContainer.clear();
|
|
1584
|
+
const lines = renderSubagentHudLines(this.#observerRegistry.getSessions(), this.ui.terminal.columns);
|
|
1585
|
+
if (lines.length === 0) return;
|
|
1586
|
+
this.subagentContainer.addChild(new Text(lines.join("\n"), 1, 0));
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
async #loadTodoList(): Promise<void> {
|
|
1590
|
+
this.todoPhases = this.session.getTodoPhases();
|
|
1591
|
+
this.#syncTodoAutoClearTimer();
|
|
1592
|
+
this.#renderTodoList();
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
async #getPlanFilePath(): Promise<string> {
|
|
1596
|
+
return this.session.getPlanReferencePath() || "local://PLAN.md";
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
#resolvePlanFilePath(planFilePath: string): string {
|
|
1600
|
+
if (planFilePath.startsWith("local:")) {
|
|
1601
|
+
const normalized = normalizeLocalScheme(planFilePath);
|
|
1602
|
+
return resolveLocalUrlToPath(normalized, {
|
|
1603
|
+
getArtifactsDir: () => this.sessionManager.getArtifactsDir(),
|
|
1604
|
+
getSessionId: () => this.sessionManager.getSessionId(),
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
return path.resolve(this.sessionManager.getCwd(), planFilePath);
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
#updatePlanModeStatus(): void {
|
|
1611
|
+
const status =
|
|
1612
|
+
this.planModeEnabled || this.planModePaused
|
|
1613
|
+
? {
|
|
1614
|
+
enabled: this.planModeEnabled,
|
|
1615
|
+
paused: this.planModePaused,
|
|
1616
|
+
}
|
|
1617
|
+
: undefined;
|
|
1618
|
+
this.statusLine.setPlanModeStatus(status);
|
|
1619
|
+
this.updateEditorTopBorder();
|
|
1620
|
+
this.ui.requestRender();
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
#updateGoalModeStatus(): void {
|
|
1624
|
+
const status =
|
|
1625
|
+
this.goalModeEnabled || this.goalModePaused
|
|
1626
|
+
? { enabled: this.goalModeEnabled, paused: this.goalModePaused }
|
|
1627
|
+
: undefined;
|
|
1628
|
+
this.statusLine.setGoalModeStatus(status);
|
|
1629
|
+
this.updateEditorTopBorder();
|
|
1630
|
+
this.ui.requestRender();
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
#resetGoalContinuationSuppression(): void {
|
|
1634
|
+
this.#goalSuppressNextContinuation = false;
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
#getPausedGoalState(): GoalModeState | undefined {
|
|
1638
|
+
const state = this.session.getGoalModeState();
|
|
1639
|
+
if (!state?.goal || state.enabled || state.goal.status !== "paused") {
|
|
1640
|
+
return undefined;
|
|
1641
|
+
}
|
|
1642
|
+
return state;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
#goalFromModeData(modeData: SessionContext["modeData"]): Goal | undefined {
|
|
1646
|
+
const goal = modeData?.goal;
|
|
1647
|
+
if (!goal || typeof goal !== "object") return undefined;
|
|
1648
|
+
const value = goal as Record<string, unknown>;
|
|
1649
|
+
if (
|
|
1650
|
+
typeof value.id !== "string" ||
|
|
1651
|
+
typeof value.objective !== "string" ||
|
|
1652
|
+
typeof value.status !== "string" ||
|
|
1653
|
+
typeof value.tokensUsed !== "number" ||
|
|
1654
|
+
typeof value.timeUsedSeconds !== "number" ||
|
|
1655
|
+
typeof value.createdAt !== "number" ||
|
|
1656
|
+
typeof value.updatedAt !== "number"
|
|
1657
|
+
) {
|
|
1658
|
+
return undefined;
|
|
1659
|
+
}
|
|
1660
|
+
return {
|
|
1661
|
+
id: value.id,
|
|
1662
|
+
objective: value.objective,
|
|
1663
|
+
status: value.status as Goal["status"],
|
|
1664
|
+
tokenBudget: typeof value.tokenBudget === "number" ? value.tokenBudget : undefined,
|
|
1665
|
+
tokensUsed: value.tokensUsed,
|
|
1666
|
+
timeUsedSeconds: value.timeUsedSeconds,
|
|
1667
|
+
createdAt: value.createdAt,
|
|
1668
|
+
updatedAt: value.updatedAt,
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
async #handleGoalSessionEvent(event: AgentSessionEvent): Promise<void> {
|
|
1673
|
+
if (event.type === "agent_start") {
|
|
1674
|
+
this.#goalTurnHadToolCalls = false;
|
|
1675
|
+
this.#cancelGoalContinuation();
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
if (event.type === "tool_execution_start") {
|
|
1679
|
+
this.#goalTurnHadToolCalls = true;
|
|
1680
|
+
if (!this.#goalContinuationTurnInFlight) {
|
|
1681
|
+
this.#resetGoalContinuationSuppression();
|
|
1682
|
+
}
|
|
1683
|
+
return;
|
|
1684
|
+
}
|
|
1685
|
+
if (event.type === "message_start" && event.message.role === "user" && !event.message.synthetic) {
|
|
1686
|
+
this.#resetGoalContinuationSuppression();
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
if (event.type === "goal_updated") {
|
|
1690
|
+
// Handle drop before clearing goalModeEnabled so #exitGoalMode can
|
|
1691
|
+
// still restore the previous tool set while the flag is true.
|
|
1692
|
+
if (event.state?.goal?.status === "dropped") {
|
|
1693
|
+
await this.#exitGoalMode({ reason: "dropped", silent: true });
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
this.goalModeEnabled = event.state?.enabled === true;
|
|
1697
|
+
this.goalModePaused = event.state?.enabled !== true && event.state?.goal?.status === "paused";
|
|
1698
|
+
if (!event.state?.enabled) {
|
|
1699
|
+
this.#cancelGoalContinuation();
|
|
1700
|
+
}
|
|
1701
|
+
this.#updateGoalModeStatus();
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
if (event.type !== "agent_end") {
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
if (this.#goalContinuationTurnInFlight) {
|
|
1708
|
+
this.#goalSuppressNextContinuation = !this.#goalTurnHadToolCalls;
|
|
1709
|
+
this.#goalContinuationTurnInFlight = false;
|
|
1710
|
+
}
|
|
1711
|
+
if (this.session.getGoalModeState()?.mode === "exiting") {
|
|
1712
|
+
await this.#exitGoalMode({ reason: "completed", silent: true });
|
|
1713
|
+
return;
|
|
1714
|
+
}
|
|
1715
|
+
this.#scheduleGoalContinuation();
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
async #applyPlanModeModel(): Promise<void> {
|
|
1719
|
+
const resolved = this.session.resolveRoleModelWithThinking("plan");
|
|
1720
|
+
if (!resolved.model) return;
|
|
1721
|
+
|
|
1722
|
+
const currentModel = this.session.model;
|
|
1723
|
+
const sameModel = modelsAreEqual(currentModel, resolved.model);
|
|
1724
|
+
const planThinkingLevel = resolved.explicitThinkingLevel ? resolved.thinkingLevel : undefined;
|
|
1725
|
+
|
|
1726
|
+
this.#planModePreviousModelState = currentModel
|
|
1727
|
+
? { model: currentModel, thinkingLevel: this.session.thinkingLevel }
|
|
1728
|
+
: undefined;
|
|
1729
|
+
|
|
1730
|
+
if (!sameModel) {
|
|
1731
|
+
if (this.session.isStreaming) {
|
|
1732
|
+
this.#pendingModelSwitch = { model: resolved.model, thinkingLevel: planThinkingLevel };
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
try {
|
|
1736
|
+
await this.session.setModelTemporary(resolved.model, planThinkingLevel);
|
|
1737
|
+
} catch (error) {
|
|
1738
|
+
this.showWarning(
|
|
1739
|
+
`Failed to switch to plan model for plan mode: ${error instanceof Error ? error.message : String(error)}`,
|
|
1740
|
+
);
|
|
1741
|
+
}
|
|
1742
|
+
} else if (planThinkingLevel) {
|
|
1743
|
+
this.session.setThinkingLevel(planThinkingLevel);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
/** Apply any deferred model switch after the current stream ends. */
|
|
1748
|
+
async flushPendingModelSwitch(): Promise<void> {
|
|
1749
|
+
const pending = this.#pendingModelSwitch;
|
|
1750
|
+
if (!pending) return;
|
|
1751
|
+
this.#pendingModelSwitch = undefined;
|
|
1752
|
+
try {
|
|
1753
|
+
await this.session.setModelTemporary(pending.model, pending.thinkingLevel);
|
|
1754
|
+
} catch (error) {
|
|
1755
|
+
this.showWarning(
|
|
1756
|
+
`Failed to switch model after streaming: ${error instanceof Error ? error.message : String(error)}`,
|
|
1757
|
+
);
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
async #clearTransientModeState(): Promise<void> {
|
|
1762
|
+
if (this.planModeEnabled || this.planModePaused) {
|
|
1763
|
+
if (this.#planModePreviousTools !== undefined) {
|
|
1764
|
+
await this.session.setActiveToolsByName(this.#planModePreviousTools);
|
|
1765
|
+
}
|
|
1766
|
+
this.session.setStandingResolveHandler?.(null);
|
|
1767
|
+
this.session.setPlanModeState(undefined);
|
|
1768
|
+
this.planModeEnabled = false;
|
|
1769
|
+
this.planModePaused = false;
|
|
1770
|
+
this.planModePlanFilePath = undefined;
|
|
1771
|
+
this.#planModePreviousTools = undefined;
|
|
1772
|
+
this.#planModePreviousModelState = undefined;
|
|
1773
|
+
this.#pendingModelSwitch = undefined;
|
|
1774
|
+
this.#planModeHasEntered = false;
|
|
1775
|
+
this.#updatePlanModeStatus();
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
if (this.goalModeEnabled || this.goalModePaused) {
|
|
1779
|
+
if (this.#goalModePreviousTools !== undefined) {
|
|
1780
|
+
await this.session.setActiveToolsByName(this.#goalModePreviousTools);
|
|
1781
|
+
}
|
|
1782
|
+
this.session.setGoalModeState(undefined);
|
|
1783
|
+
this.goalModeEnabled = false;
|
|
1784
|
+
this.goalModePaused = false;
|
|
1785
|
+
this.#goalModePreviousTools = undefined;
|
|
1786
|
+
this.#goalTurnHadToolCalls = false;
|
|
1787
|
+
this.#goalContinuationTurnInFlight = false;
|
|
1788
|
+
this.#goalSuppressNextContinuation = false;
|
|
1789
|
+
this.#cancelGoalContinuation();
|
|
1790
|
+
this.#updateGoalModeStatus();
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
/** Reconcile mode state from session entries on resume/switch. */
|
|
1795
|
+
async #reconcileModeFromSession(options?: { preserveActiveGoal?: boolean }): Promise<void> {
|
|
1796
|
+
await this.#clearTransientModeState();
|
|
1797
|
+
const sessionContext = this.sessionManager.buildSessionContext();
|
|
1798
|
+
const goalEnabled = this.session.settings.get("goal.enabled");
|
|
1799
|
+
if (!goalEnabled && (sessionContext.mode === "goal" || sessionContext.mode === "goal_paused")) {
|
|
1800
|
+
this.session.goalRuntime.clearAccounting();
|
|
1801
|
+
this.sessionManager.appendModeChange("none");
|
|
1802
|
+
return;
|
|
1803
|
+
}
|
|
1804
|
+
if (sessionContext.mode === "goal" || sessionContext.mode === "goal_paused") {
|
|
1805
|
+
const goal = this.#goalFromModeData(sessionContext.modeData);
|
|
1806
|
+
if (!goal) {
|
|
1807
|
+
this.sessionManager.appendModeChange("none");
|
|
1808
|
+
return;
|
|
1809
|
+
}
|
|
1810
|
+
this.session.setGoalModeState({
|
|
1811
|
+
enabled: sessionContext.mode === "goal",
|
|
1812
|
+
mode: "active",
|
|
1813
|
+
goal,
|
|
1814
|
+
});
|
|
1815
|
+
const restored = await this.session.goalRuntime.onThreadResumed({
|
|
1816
|
+
preserveActiveGoal: options?.preserveActiveGoal,
|
|
1817
|
+
});
|
|
1818
|
+
this.goalModeEnabled = restored?.enabled === true;
|
|
1819
|
+
this.goalModePaused = restored?.enabled !== true && restored?.goal.status === "paused";
|
|
1820
|
+
// sdk.ts excludes "goal" from the initial active tool set unconditionally.
|
|
1821
|
+
// Re-add it now so the agent can call resume, complete, or drop on this goal.
|
|
1822
|
+
if (restored?.goal) {
|
|
1823
|
+
const previousTools = this.session.getActiveToolNames().filter(name => name !== "goal");
|
|
1824
|
+
this.#goalModePreviousTools = previousTools;
|
|
1825
|
+
await this.session.setActiveToolsByName([...new Set([...previousTools, "goal"])]);
|
|
1826
|
+
}
|
|
1827
|
+
this.#updateGoalModeStatus();
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
this.session.goalRuntime.clearAccounting();
|
|
1831
|
+
if (!this.session.settings.get("plan.enabled")) {
|
|
1832
|
+
// Clear stale plan/plan_paused mode so re-enabling the setting
|
|
1833
|
+
// later doesn't unexpectedly restore an old plan session.
|
|
1834
|
+
if (sessionContext.mode === "plan" || sessionContext.mode === "plan_paused") {
|
|
1835
|
+
this.sessionManager.appendModeChange("none");
|
|
1836
|
+
}
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1839
|
+
if (sessionContext.mode === "plan") {
|
|
1840
|
+
const planFilePath = sessionContext.modeData?.planFilePath as string | undefined;
|
|
1841
|
+
await this.#enterPlanMode({ planFilePath });
|
|
1842
|
+
} else if (sessionContext.mode === "plan_paused") {
|
|
1843
|
+
this.planModePaused = true;
|
|
1844
|
+
this.#planModeHasEntered = true;
|
|
1845
|
+
this.#updatePlanModeStatus();
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
async #enterPlanMode(options?: { planFilePath?: string; workflow?: "parallel" | "iterative" }): Promise<void> {
|
|
1850
|
+
if (this.planModeEnabled) {
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
if (this.goalModeEnabled || this.goalModePaused) {
|
|
1854
|
+
this.showWarning("Exit goal mode first.");
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
this.planModePaused = false;
|
|
1859
|
+
|
|
1860
|
+
const planFilePath = options?.planFilePath ?? (await this.#getPlanFilePath());
|
|
1861
|
+
const previousTools = this.session.getActiveToolNames();
|
|
1862
|
+
const hasResolveTool = this.session.getToolByName("resolve") !== undefined;
|
|
1863
|
+
const planTools = hasResolveTool ? [...previousTools, "resolve"] : previousTools;
|
|
1864
|
+
const uniquePlanTools = [...new Set(planTools)];
|
|
1865
|
+
|
|
1866
|
+
this.#planModePreviousTools = previousTools;
|
|
1867
|
+
this.planModePlanFilePath = planFilePath;
|
|
1868
|
+
this.planModeEnabled = true;
|
|
1869
|
+
// Suppress cache-miss marker on the next turn: plan mode changes the system
|
|
1870
|
+
// prompt, which predictably invalidates the cache.
|
|
1871
|
+
this.lastAssistantUsage = undefined;
|
|
1872
|
+
|
|
1873
|
+
await this.session.setActiveToolsByName(uniquePlanTools);
|
|
1874
|
+
this.session.setPlanModeState({
|
|
1875
|
+
enabled: true,
|
|
1876
|
+
planFilePath,
|
|
1877
|
+
workflow: options?.workflow ?? "parallel",
|
|
1878
|
+
reentry: this.#planModeHasEntered,
|
|
1879
|
+
});
|
|
1880
|
+
this.session.setStandingResolveHandler?.(input => this.#runPlanApprovalResolve(input));
|
|
1881
|
+
if (this.session.isStreaming) {
|
|
1882
|
+
await this.session.sendPlanModeContext({ deliverAs: "steer" });
|
|
1883
|
+
}
|
|
1884
|
+
this.#planModeHasEntered = true;
|
|
1885
|
+
await this.#applyPlanModeModel();
|
|
1886
|
+
this.#updatePlanModeStatus();
|
|
1887
|
+
this.sessionManager.appendModeChange("plan", { planFilePath });
|
|
1888
|
+
this.showStatus(`Plan mode enabled. Plan file: ${planFilePath}`);
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
/** Standing resolve dispatcher registered while plan mode is active. The agent
|
|
1892
|
+
* submits the finalized plan by calling `resolve { action: "apply", extra: { title } }`;
|
|
1893
|
+
* this handler validates the plan file exists, normalizes the title, and shapes the
|
|
1894
|
+
* payload that `event-controller` forwards to `handlePlanApproval`. */
|
|
1895
|
+
#runPlanApprovalResolve(input: unknown): Promise<AgentToolResult<ResolveToolDetails>> {
|
|
1896
|
+
return runResolveInvocation(input as Parameters<typeof runResolveInvocation>[0], {
|
|
1897
|
+
sourceToolName: "plan_approval",
|
|
1898
|
+
label: "Plan ready for approval",
|
|
1899
|
+
apply: async (_reason, extra) => {
|
|
1900
|
+
const state = this.session.getPlanModeState?.();
|
|
1901
|
+
if (!state?.enabled) {
|
|
1902
|
+
throw new ToolError("Plan mode is not active.");
|
|
1903
|
+
}
|
|
1904
|
+
const { planFilePath, title } = await resolveApprovedPlan({
|
|
1905
|
+
suppliedTitle: extra?.title,
|
|
1906
|
+
statePlanFilePath: state.planFilePath,
|
|
1907
|
+
readPlan: url => this.#readPlanFile(url),
|
|
1908
|
+
listPlanFiles: () => this.#listLocalPlanFiles(),
|
|
1909
|
+
});
|
|
1910
|
+
const details: PlanApprovalDetails = {
|
|
1911
|
+
planFilePath,
|
|
1912
|
+
title,
|
|
1913
|
+
planExists: true,
|
|
1914
|
+
};
|
|
1915
|
+
return {
|
|
1916
|
+
content: [{ type: "text" as const, text: "Plan ready for approval." }],
|
|
1917
|
+
details,
|
|
1918
|
+
};
|
|
1919
|
+
},
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
async #restorePlanPreviousModel(prev: { model: Model; thinkingLevel?: ThinkingLevel }): Promise<void> {
|
|
1924
|
+
if (modelsAreEqual(this.session.model, prev.model)) {
|
|
1925
|
+
// Same model — only thinking level may differ. Avoid setModelTemporary()
|
|
1926
|
+
// which would reset provider-side sessions and break continuity.
|
|
1927
|
+
this.session.setThinkingLevel(prev.thinkingLevel);
|
|
1928
|
+
} else if (this.session.isStreaming) {
|
|
1929
|
+
this.#pendingModelSwitch = { model: prev.model, thinkingLevel: prev.thinkingLevel };
|
|
1930
|
+
} else {
|
|
1931
|
+
await this.session.setModelTemporary(prev.model, prev.thinkingLevel);
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
/**
|
|
1936
|
+
* Idempotent post-compaction model transition for the plan-approval compact
|
|
1937
|
+
* path. The deferred pre-plan state is consumed on first application, so a
|
|
1938
|
+
* second call (the before-flush hook vs. the short-circuit fallback) is a
|
|
1939
|
+
* no-op. "failed" intentionally stays on the plan model — the context is
|
|
1940
|
+
* intact and we dispatch best-effort.
|
|
1941
|
+
*/
|
|
1942
|
+
async #applyDeferredPlanModelTransition(
|
|
1943
|
+
outcome: CompactionOutcome | undefined,
|
|
1944
|
+
executionModel: ResolvedRoleModel | undefined,
|
|
1945
|
+
): Promise<void> {
|
|
1946
|
+
const deferredPrev = this.#planModePreviousModelState;
|
|
1947
|
+
if (deferredPrev === undefined || outcome === "failed") return;
|
|
1948
|
+
this.#planModePreviousModelState = undefined;
|
|
1949
|
+
if (executionModel) {
|
|
1950
|
+
await this.#applyPlanExecutionModel(executionModel);
|
|
1951
|
+
} else {
|
|
1952
|
+
await this.#restorePlanPreviousModel(deferredPrev);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
async #exitPlanMode(options?: { silent?: boolean; paused?: boolean; deferModelRestore?: boolean }): Promise<void> {
|
|
1957
|
+
if (!this.planModeEnabled) {
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
const previousTools = this.#planModePreviousTools;
|
|
1962
|
+
if (previousTools && previousTools.length > 0) {
|
|
1963
|
+
await this.session.setActiveToolsByName(previousTools);
|
|
1964
|
+
}
|
|
1965
|
+
if (this.#planModePreviousModelState) {
|
|
1966
|
+
if (!options?.deferModelRestore) {
|
|
1967
|
+
await this.#restorePlanPreviousModel(this.#planModePreviousModelState);
|
|
1968
|
+
}
|
|
1969
|
+
// If #applyPlanModeModel queued a deferred switch to the plan-role model
|
|
1970
|
+
// (because the session was streaming on entry), drop it now: we are
|
|
1971
|
+
// leaving plan mode, so flushing it on the next agent_end would land the
|
|
1972
|
+
// session on the plan-role model after the user has exited plan mode
|
|
1973
|
+
// (issue #816). This runs even when deferModelRestore is set
|
|
1974
|
+
// (compact-approval path): otherwise the stale plan switch survives and
|
|
1975
|
+
// flushPendingModelSwitch() later clobbers the restored/execution model.
|
|
1976
|
+
// Only clear when the pending target matches the plan-role model — leave
|
|
1977
|
+
// any unrelated user-queued switch intact.
|
|
1978
|
+
const pending = this.#pendingModelSwitch;
|
|
1979
|
+
if (pending) {
|
|
1980
|
+
const planResolution = this.session.resolveRoleModelWithThinking("plan");
|
|
1981
|
+
if (planResolution.model && modelsAreEqual(pending.model, planResolution.model)) {
|
|
1982
|
+
this.#pendingModelSwitch = undefined;
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
this.session.setStandingResolveHandler?.(null);
|
|
1987
|
+
this.session.setPlanModeState(undefined);
|
|
1988
|
+
this.planModeEnabled = false;
|
|
1989
|
+
// Suppress cache-miss marker on the next turn: plan exit changes the system
|
|
1990
|
+
// prompt, which predictably invalidates the cache.
|
|
1991
|
+
this.lastAssistantUsage = undefined;
|
|
1992
|
+
this.planModePaused = options?.paused ?? false;
|
|
1993
|
+
this.planModePlanFilePath = undefined;
|
|
1994
|
+
this.#planModePreviousTools = undefined;
|
|
1995
|
+
if (!options?.deferModelRestore) this.#planModePreviousModelState = undefined;
|
|
1996
|
+
this.#updatePlanModeStatus();
|
|
1997
|
+
const paused = options?.paused ?? false;
|
|
1998
|
+
this.sessionManager.appendModeChange(paused ? "plan_paused" : "none");
|
|
1999
|
+
if (!options?.silent) {
|
|
2000
|
+
this.showStatus(paused ? "Plan mode paused." : "Plan mode disabled.");
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
async #enterGoalMode(options: { objective?: string; resume?: boolean; silent?: boolean }): Promise<void> {
|
|
2005
|
+
if (this.goalModeEnabled) {
|
|
2006
|
+
return;
|
|
2007
|
+
}
|
|
2008
|
+
if (this.planModeEnabled || this.planModePaused) {
|
|
2009
|
+
this.showWarning("Exit plan mode first.");
|
|
2010
|
+
return;
|
|
2011
|
+
}
|
|
2012
|
+
const previousTools = this.session.getActiveToolNames().filter(name => name !== "goal");
|
|
2013
|
+
const goalTools = [...new Set([...previousTools, "goal"])];
|
|
2014
|
+
this.#goalModePreviousTools = previousTools;
|
|
2015
|
+
this.goalModePaused = false;
|
|
2016
|
+
const state = options.resume
|
|
2017
|
+
? await this.session.goalRuntime.resumeGoal()
|
|
2018
|
+
: await this.session.goalRuntime.createGoal({ objective: options.objective ?? "" });
|
|
2019
|
+
await this.session.setActiveToolsByName(goalTools);
|
|
2020
|
+
this.session.setGoalModeState(state);
|
|
2021
|
+
this.goalModeEnabled = true;
|
|
2022
|
+
this.#resetGoalContinuationSuppression();
|
|
2023
|
+
this.#updateGoalModeStatus();
|
|
2024
|
+
if (this.session.isStreaming) {
|
|
2025
|
+
await this.session.sendGoalModeContext({ deliverAs: "steer" });
|
|
2026
|
+
}
|
|
2027
|
+
if (!options.silent) {
|
|
2028
|
+
this.showStatus(options.resume ? "Goal mode resumed." : "Goal mode enabled.");
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
async #exitGoalMode(options?: {
|
|
2033
|
+
silent?: boolean;
|
|
2034
|
+
paused?: boolean;
|
|
2035
|
+
reason?: "completed" | "paused" | "dropped";
|
|
2036
|
+
}): Promise<void> {
|
|
2037
|
+
const previousTools = this.#goalModePreviousTools;
|
|
2038
|
+
if (this.goalModeEnabled && previousTools) {
|
|
2039
|
+
await this.session.setActiveToolsByName(previousTools);
|
|
2040
|
+
}
|
|
2041
|
+
const currentState = this.session.getGoalModeState();
|
|
2042
|
+
if (options?.reason === "completed") {
|
|
2043
|
+
this.session.setGoalModeState(undefined);
|
|
2044
|
+
this.sessionManager.appendModeChange("none");
|
|
2045
|
+
this.sessionManager.appendCustomEntry("goal-completed", {
|
|
2046
|
+
objective: currentState?.goal?.objective,
|
|
2047
|
+
tokensUsed: currentState?.goal?.tokensUsed,
|
|
2048
|
+
tokenBudget: currentState?.goal?.tokenBudget,
|
|
2049
|
+
timeUsedSeconds: currentState?.goal?.timeUsedSeconds,
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
this.goalModeEnabled = false;
|
|
2053
|
+
this.goalModePaused = options?.paused ?? false;
|
|
2054
|
+
this.#goalModePreviousTools = undefined;
|
|
2055
|
+
this.#goalContinuationTurnInFlight = false;
|
|
2056
|
+
this.#cancelGoalContinuation();
|
|
2057
|
+
this.#updateGoalModeStatus();
|
|
2058
|
+
if (!options?.silent) {
|
|
2059
|
+
if (options?.reason === "completed") {
|
|
2060
|
+
this.showStatus("Goal mode completed.");
|
|
2061
|
+
} else if (options?.reason === "dropped") {
|
|
2062
|
+
this.showStatus("Goal dropped.");
|
|
2063
|
+
} else if (options?.paused) {
|
|
2064
|
+
this.showStatus("Goal mode paused.");
|
|
2065
|
+
} else {
|
|
2066
|
+
this.showStatus("Goal mode disabled.");
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
async #readPlanFile(planFilePath: string): Promise<string | null> {
|
|
2072
|
+
const resolvedPath = this.#resolvePlanFilePath(planFilePath);
|
|
2073
|
+
try {
|
|
2074
|
+
return await Bun.file(resolvedPath).text();
|
|
2075
|
+
} catch (error) {
|
|
2076
|
+
if (isEnoent(error)) {
|
|
2077
|
+
return null;
|
|
2078
|
+
}
|
|
2079
|
+
throw error;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
async #hasPlanModeDraftContent(planFilePath: string): Promise<boolean> {
|
|
2084
|
+
const candidates = new Set<string>([planFilePath, ...(await this.#listLocalPlanFiles())]);
|
|
2085
|
+
for (const candidate of candidates) {
|
|
2086
|
+
const content = await this.#readPlanFile(candidate);
|
|
2087
|
+
if (content !== null && content.trim().length > 0) return true;
|
|
2088
|
+
}
|
|
2089
|
+
return false;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
/** `local://` URLs of plan files in the session-local root, newest first.
|
|
2093
|
+
* A fallback for `resolveApprovedPlan` when the agent dropped `extra.title`,
|
|
2094
|
+
* so the plan it wrote is still found by scanning recent `*-plan.md` files. */
|
|
2095
|
+
async #listLocalPlanFiles(): Promise<string[]> {
|
|
2096
|
+
const localRoot = this.#resolvePlanFilePath("local://");
|
|
2097
|
+
try {
|
|
2098
|
+
const entries = await fs.readdir(localRoot, { withFileTypes: true });
|
|
2099
|
+
const plans = await Promise.all(
|
|
2100
|
+
entries
|
|
2101
|
+
.filter(entry => entry.isFile() && /plan\.md$/i.test(entry.name))
|
|
2102
|
+
.map(async name => {
|
|
2103
|
+
const stat = await fs.stat(path.join(localRoot, name.name)).catch(() => null);
|
|
2104
|
+
return { url: `local://${name.name}`, mtime: stat?.mtimeMs ?? 0 };
|
|
2105
|
+
}),
|
|
2106
|
+
);
|
|
2107
|
+
return plans.sort((a, b) => b.mtime - a.mtime).map(plan => plan.url);
|
|
2108
|
+
} catch {
|
|
2109
|
+
return [];
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
showPlanReview(
|
|
2114
|
+
planContent: string,
|
|
2115
|
+
title: string,
|
|
2116
|
+
options: string[],
|
|
2117
|
+
dialogOptions?: {
|
|
2118
|
+
helpText?: string;
|
|
2119
|
+
disabledIndices?: number[];
|
|
2120
|
+
onExternalEditor?: () => void;
|
|
2121
|
+
onPlanEdited?: (content: string) => void;
|
|
2122
|
+
onFeedbackChange?: (feedback: string) => void;
|
|
2123
|
+
initialIndex?: number;
|
|
2124
|
+
},
|
|
2125
|
+
extra?: { slider?: HookSelectorSlider },
|
|
2126
|
+
): Promise<string | undefined> {
|
|
2127
|
+
this.#hidePlanReview();
|
|
2128
|
+
const { promise, resolve } = Promise.withResolvers<string | undefined>();
|
|
2129
|
+
let settled = false;
|
|
2130
|
+
const finish = (choice: string | undefined): void => {
|
|
2131
|
+
if (settled) return;
|
|
2132
|
+
settled = true;
|
|
2133
|
+
this.#hidePlanReview();
|
|
2134
|
+
this.ui.requestRender();
|
|
2135
|
+
resolve(choice);
|
|
2136
|
+
};
|
|
2137
|
+
const overlay = new PlanReviewOverlay(
|
|
2138
|
+
planContent,
|
|
2139
|
+
{
|
|
2140
|
+
promptTitle: title,
|
|
2141
|
+
options,
|
|
2142
|
+
disabledIndices: dialogOptions?.disabledIndices,
|
|
2143
|
+
helpText: dialogOptions?.helpText,
|
|
2144
|
+
initialIndex: dialogOptions?.initialIndex,
|
|
2145
|
+
slider: extra?.slider,
|
|
2146
|
+
externalEditorLabel: this.keybindings.getDisplayString("app.editor.external") || undefined,
|
|
2147
|
+
},
|
|
2148
|
+
{
|
|
2149
|
+
onPick: choice => finish(choice),
|
|
2150
|
+
onCancel: () => finish(undefined),
|
|
2151
|
+
onExternalEditor: dialogOptions?.onExternalEditor,
|
|
2152
|
+
onAnnotationExternalEditor: (draft, commit) => void this.#openPlanAnnotationInExternalEditor(draft, commit),
|
|
2153
|
+
onPlanEdited: dialogOptions?.onPlanEdited,
|
|
2154
|
+
onFeedbackChange: dialogOptions?.onFeedbackChange,
|
|
2155
|
+
},
|
|
2156
|
+
);
|
|
2157
|
+
this.#planReviewOverlay = overlay;
|
|
2158
|
+
this.#planReviewOverlayHandle = this.ui.showOverlay(overlay, {
|
|
2159
|
+
anchor: "bottom-center",
|
|
2160
|
+
width: "100%",
|
|
2161
|
+
maxHeight: "100%",
|
|
2162
|
+
margin: 0,
|
|
2163
|
+
fullscreen: true,
|
|
2164
|
+
});
|
|
2165
|
+
this.ui.setFocus(overlay);
|
|
2166
|
+
this.ui.requestRender();
|
|
2167
|
+
return promise;
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
#hidePlanReview(): void {
|
|
2171
|
+
this.#planReviewOverlayHandle?.hide();
|
|
2172
|
+
this.#planReviewOverlayHandle = undefined;
|
|
2173
|
+
this.#planReviewOverlay = undefined;
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
#getEditorTerminalPath(): string | null {
|
|
2177
|
+
if (process.platform === "win32") {
|
|
2178
|
+
return null;
|
|
2179
|
+
}
|
|
2180
|
+
return "/dev/tty";
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
async #openEditorTerminalHandle(): Promise<fs.FileHandle | null> {
|
|
2184
|
+
const terminalPath = this.#getEditorTerminalPath();
|
|
2185
|
+
if (!terminalPath) {
|
|
2186
|
+
return null;
|
|
2187
|
+
}
|
|
2188
|
+
try {
|
|
2189
|
+
return await fs.open(terminalPath, "r+");
|
|
2190
|
+
} catch {
|
|
2191
|
+
return null;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
#getPlanApprovalContextUsage(): ContextUsage | undefined {
|
|
2196
|
+
const executionModel = this.#planModePreviousModelState?.model ?? this.session.model;
|
|
2197
|
+
const contextWindow = executionModel?.contextWindow;
|
|
2198
|
+
if (typeof contextWindow === "number") {
|
|
2199
|
+
return this.session.getContextUsage({ contextWindow });
|
|
2200
|
+
}
|
|
2201
|
+
return this.session.getContextUsage();
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
#formatKeepContextLabel(contextUsage: ContextUsage | undefined): string {
|
|
2205
|
+
if (!contextUsage) {
|
|
2206
|
+
return "Approve and keep context";
|
|
2207
|
+
}
|
|
2208
|
+
const tokens = formatContextTokenCount(contextUsage.tokens);
|
|
2209
|
+
const contextWindow = formatContextTokenCount(contextUsage.contextWindow);
|
|
2210
|
+
return `Approve and keep context (~${tokens} / ${contextWindow})`;
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
#isKeepContextDisabled(contextUsage: ContextUsage | undefined): boolean {
|
|
2214
|
+
return contextUsage !== undefined && contextUsage.percent > PLAN_KEEP_CONTEXT_DISABLE_THRESHOLD_PERCENT;
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
async #openPlanInExternalEditor(planFilePath: string): Promise<void> {
|
|
2218
|
+
const editorCmd = getEditorCommand();
|
|
2219
|
+
if (!editorCmd) {
|
|
2220
|
+
this.showWarning("No editor configured. Set $VISUAL or $EDITOR environment variable.");
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
const resolvedPath = this.#resolvePlanFilePath(planFilePath);
|
|
2225
|
+
let currentText: string;
|
|
2226
|
+
try {
|
|
2227
|
+
currentText = await Bun.file(resolvedPath).text();
|
|
2228
|
+
} catch (error) {
|
|
2229
|
+
if (isEnoent(error)) {
|
|
2230
|
+
this.showError(`Plan file not found at ${planFilePath}`);
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
this.showWarning(`Failed to open external editor: ${error instanceof Error ? error.message : String(error)}`);
|
|
2234
|
+
return;
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
let ttyHandle: fs.FileHandle | null = null;
|
|
2238
|
+
try {
|
|
2239
|
+
ttyHandle = await this.#openEditorTerminalHandle();
|
|
2240
|
+
this.ui.stop();
|
|
2241
|
+
|
|
2242
|
+
const stdio: [number | "inherit", number | "inherit", number | "inherit"] = ttyHandle
|
|
2243
|
+
? [ttyHandle.fd, ttyHandle.fd, ttyHandle.fd]
|
|
2244
|
+
: ["inherit", "inherit", "inherit"];
|
|
2245
|
+
|
|
2246
|
+
const result = await openInEditor(editorCmd, currentText, {
|
|
2247
|
+
extension: path.extname(resolvedPath) || ".md",
|
|
2248
|
+
stdio,
|
|
2249
|
+
trimTrailingNewline: false,
|
|
2250
|
+
});
|
|
2251
|
+
if (result !== null) {
|
|
2252
|
+
await Bun.write(resolvedPath, result);
|
|
2253
|
+
this.#planReviewOverlay?.setPlanContent(result);
|
|
2254
|
+
this.showStatus("Plan updated in external editor.");
|
|
2255
|
+
}
|
|
2256
|
+
} catch (error) {
|
|
2257
|
+
this.showWarning(`Failed to open external editor: ${error instanceof Error ? error.message : String(error)}`);
|
|
2258
|
+
} finally {
|
|
2259
|
+
if (ttyHandle) {
|
|
2260
|
+
await ttyHandle.close();
|
|
2261
|
+
}
|
|
2262
|
+
this.ui.start();
|
|
2263
|
+
this.ui.requestRender(true);
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
async #openPlanAnnotationInExternalEditor(draft: string, commit: (text: string | null) => void): Promise<void> {
|
|
2268
|
+
const editorCmd = getEditorCommand();
|
|
2269
|
+
if (!editorCmd) {
|
|
2270
|
+
this.showWarning("No editor configured. Set $VISUAL or $EDITOR environment variable.");
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
let ttyHandle: fs.FileHandle | null = null;
|
|
2275
|
+
try {
|
|
2276
|
+
ttyHandle = await this.#openEditorTerminalHandle();
|
|
2277
|
+
this.ui.stop();
|
|
2278
|
+
|
|
2279
|
+
const stdio: [number | "inherit", number | "inherit", number | "inherit"] = ttyHandle
|
|
2280
|
+
? [ttyHandle.fd, ttyHandle.fd, ttyHandle.fd]
|
|
2281
|
+
: ["inherit", "inherit", "inherit"];
|
|
2282
|
+
|
|
2283
|
+
const result = await openInEditor(editorCmd, draft, { extension: ".md", stdio });
|
|
2284
|
+
if (result !== null) {
|
|
2285
|
+
commit(result);
|
|
2286
|
+
}
|
|
2287
|
+
} catch (error) {
|
|
2288
|
+
this.showWarning(`Failed to open external editor: ${error instanceof Error ? error.message : String(error)}`);
|
|
2289
|
+
} finally {
|
|
2290
|
+
if (ttyHandle) {
|
|
2291
|
+
await ttyHandle.close();
|
|
2292
|
+
}
|
|
2293
|
+
this.ui.start();
|
|
2294
|
+
this.ui.requestRender(true);
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
async #applyPlanExecutionModel(entry: ResolvedRoleModel | undefined): Promise<void> {
|
|
2299
|
+
if (!entry) return;
|
|
2300
|
+
try {
|
|
2301
|
+
await this.session.applyRoleModel(entry);
|
|
2302
|
+
this.statusLine.invalidate();
|
|
2303
|
+
this.updateEditorBorderColor();
|
|
2304
|
+
this.showStatus(`Continuing with ${entry.role}: ${entry.model.name || entry.model.id}`);
|
|
2305
|
+
} catch (error) {
|
|
2306
|
+
this.showWarning(
|
|
2307
|
+
`Could not switch to the ${entry.role} model: ${error instanceof Error ? error.message : String(error)}`,
|
|
2308
|
+
);
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
async #approvePlan(
|
|
2313
|
+
planContent: string,
|
|
2314
|
+
options: {
|
|
2315
|
+
planFilePath: string;
|
|
2316
|
+
title: string;
|
|
2317
|
+
preserveContext?: boolean;
|
|
2318
|
+
compactBeforeExecute?: boolean;
|
|
2319
|
+
executionModel?: ResolvedRoleModel;
|
|
2320
|
+
},
|
|
2321
|
+
): Promise<void> {
|
|
2322
|
+
const previousTools = this.#planModePreviousTools ?? this.session.getActiveToolNames();
|
|
2323
|
+
|
|
2324
|
+
// Mark the pending abort caused by the plan-mode → compaction transition as
|
|
2325
|
+
// silent BEFORE #exitPlanMode raises it. The `finally` below clears the
|
|
2326
|
+
// flag on every terminal compaction outcome (ok / cancelled / failed /
|
|
2327
|
+
// throw) so a leaked flag cannot silence a later unrelated abort.
|
|
2328
|
+
// Branchless mark+clear when !compactBeforeExecute: mark is gated; clear
|
|
2329
|
+
// is unconditional and idempotent.
|
|
2330
|
+
if (options.compactBeforeExecute) {
|
|
2331
|
+
this.session.markPlanInternalAbortPending();
|
|
2332
|
+
}
|
|
2333
|
+
let compactOutcome: CompactionOutcome | undefined;
|
|
2334
|
+
try {
|
|
2335
|
+
await this.#exitPlanMode({
|
|
2336
|
+
silent: true,
|
|
2337
|
+
paused: false,
|
|
2338
|
+
deferModelRestore: options.compactBeforeExecute === true,
|
|
2339
|
+
});
|
|
2340
|
+
|
|
2341
|
+
if (!options.preserveContext) {
|
|
2342
|
+
await this.handleClearCommand();
|
|
2343
|
+
// The new session has a fresh local:// root — persist the approved plan there
|
|
2344
|
+
// so `local://<slug>-plan.md` resolves correctly in the execution session.
|
|
2345
|
+
const newLocalPath = resolveLocalUrlToPath(options.planFilePath, {
|
|
2346
|
+
getArtifactsDir: () => this.sessionManager.getArtifactsDir(),
|
|
2347
|
+
getSessionId: () => this.sessionManager.getSessionId(),
|
|
2348
|
+
});
|
|
2349
|
+
await Bun.write(newLocalPath, planContent);
|
|
2350
|
+
} else if (options.compactBeforeExecute) {
|
|
2351
|
+
// Distill the plan-mode transcript before the execution turn is queued so
|
|
2352
|
+
// the plan-approved synthetic prompt lands as a fresh cache anchor.
|
|
2353
|
+
// Outcome is consumed after tool-restoration and plan-reference-path
|
|
2354
|
+
// bookkeeping below; `markPlanReferenceSent` is intentionally deferred
|
|
2355
|
+
// past the cancel guard — see the comment at the cancel branch.
|
|
2356
|
+
// Cancellation skips the synthetic-prompt dispatch (operator's explicit
|
|
2357
|
+
// abort is honored); failure proceeds best-effort — approval intent stands.
|
|
2358
|
+
const compactionPrompt = prompt.render(planModeCompactInstructionsPrompt, {
|
|
2359
|
+
planFilePath: options.planFilePath,
|
|
2360
|
+
});
|
|
2361
|
+
// Pin the plan reference path BEFORE compaction so any user messages
|
|
2362
|
+
// queued during the compaction await (which `handleCompactCommand`
|
|
2363
|
+
// flushes via `flushCompactionQueue` before returning) see the
|
|
2364
|
+
// approved plan in `#buildPlanReferenceMessage`. Reassignment after
|
|
2365
|
+
// the try/finally is idempotent and kept for the !compactBeforeExecute
|
|
2366
|
+
// branch.
|
|
2367
|
+
this.session.setPlanReferencePath(options.planFilePath);
|
|
2368
|
+
compactOutcome = await this.handleCompactCommand(compactionPrompt, undefined, outcome =>
|
|
2369
|
+
this.#applyDeferredPlanModelTransition(outcome, options.executionModel),
|
|
2370
|
+
);
|
|
2371
|
+
}
|
|
2372
|
+
} finally {
|
|
2373
|
+
// Unconditional clear. Idempotent: a no-op when the flag was never set
|
|
2374
|
+
// (i.e., the !compactBeforeExecute branch), and a no-op when the flag
|
|
2375
|
+
// was already consumed by AgentSession.#handleAgentEvent's aborted
|
|
2376
|
+
// message_end stamping. Guarantees the flag is dead at every exit.
|
|
2377
|
+
this.session.clearPlanInternalAbortPending();
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
// Tool restoration runs on every path — the plan mode tools must be
|
|
2381
|
+
// retired regardless of whether the synthetic prompt fires.
|
|
2382
|
+
if (previousTools.length > 0) {
|
|
2383
|
+
await this.session.setActiveToolsByName(previousTools);
|
|
2384
|
+
}
|
|
2385
|
+
this.session.setPlanReferencePath(options.planFilePath);
|
|
2386
|
+
|
|
2387
|
+
// Resolve the deferred plan-approval model transition. On the compact path
|
|
2388
|
+
// the before-flush hook passed to handleCompactCommand already ran this (so
|
|
2389
|
+
// any input queued during compaction executed on the post-compaction
|
|
2390
|
+
// model); the re-run here is idempotent and covers the short-circuit where
|
|
2391
|
+
// compaction never executed. It runs for "cancelled" too — the operator
|
|
2392
|
+
// aborted only the compaction, not the approval — so the next turn no longer
|
|
2393
|
+
// lands on the plan model. "failed" stays on the plan model (context
|
|
2394
|
+
// intact) and dispatches best-effort.
|
|
2395
|
+
if (options.compactBeforeExecute) {
|
|
2396
|
+
await this.#applyDeferredPlanModelTransition(compactOutcome, options.executionModel);
|
|
2397
|
+
} else {
|
|
2398
|
+
await this.#applyPlanExecutionModel(options.executionModel);
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
if (compactOutcome === "cancelled") {
|
|
2402
|
+
// Explicit abort: honor it. `executeCompaction` already surfaced
|
|
2403
|
+
// `showError("Compaction cancelled")`; we add the deferred-dispatch
|
|
2404
|
+
// warning and exit without dispatching the synthetic plan-approved
|
|
2405
|
+
// prompt. `markPlanReferenceSent` stays unset so
|
|
2406
|
+
// `AgentSession.#buildPlanReferenceMessage` injects the plan reference
|
|
2407
|
+
// on the operator's next `prompt()` call.
|
|
2408
|
+
this.showWarning(
|
|
2409
|
+
"Plan approved, but compaction was cancelled — execution not dispatched. Submit a turn to continue.",
|
|
2410
|
+
);
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
// Approved plans land in a fresh (or compacted) session whose first user-visible
|
|
2415
|
+
// turn is the synthetic plan-approved prompt — that path bypasses the
|
|
2416
|
+
// input-controller's title generation. Seed an auto-name from the plan title
|
|
2417
|
+
// so the session is not left unnamed. `setSessionName("auto")` is a no-op
|
|
2418
|
+
// when the user has already chosen a name (preserveContext paths).
|
|
2419
|
+
const seededName = humanizePlanTitle(options.title);
|
|
2420
|
+
if (seededName && !this.sessionManager.getSessionName()) {
|
|
2421
|
+
const applied = await this.sessionManager.setSessionName(seededName, "auto");
|
|
2422
|
+
if (applied) {
|
|
2423
|
+
setSessionTerminalTitle(this.sessionManager.getSessionName(), this.sessionManager.getCwd());
|
|
2424
|
+
this.updateEditorBorderColor();
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
// markPlanReferenceSent fires only on the dispatch path so the synthetic
|
|
2429
|
+
// plan-approved prompt is the source of the reference injection.
|
|
2430
|
+
this.session.markPlanReferenceSent();
|
|
2431
|
+
const planModePrompt = prompt.render(planModeApprovedPrompt, {
|
|
2432
|
+
planContent,
|
|
2433
|
+
planFilePath: options.planFilePath,
|
|
2434
|
+
contextPreserved: options.preserveContext === true,
|
|
2435
|
+
});
|
|
2436
|
+
// The executor's first turn must start on an idle session. The agent may still
|
|
2437
|
+
// be streaming the post-`resolve` continuation (Agent.#emit is fire-and-forget)
|
|
2438
|
+
// or a turn kicked off by the compaction/clear above; prompt() would then throw
|
|
2439
|
+
// AgentBusyError ("Failed to finalize approved plan"). Abort the now-irrelevant
|
|
2440
|
+
// in-flight turn first — abort() bumps the prompt generation and cancels pending
|
|
2441
|
+
// continuations, so nothing re-streams in the synchronous gap before prompt().
|
|
2442
|
+
if (this.session.isStreaming) {
|
|
2443
|
+
await this.#abortPlanApprovalTurnSilently();
|
|
2444
|
+
}
|
|
2445
|
+
await this.session.prompt(planModePrompt, { synthetic: true });
|
|
2446
|
+
}
|
|
2447
|
+
async #abortPlanApprovalTurnSilently(): Promise<void> {
|
|
2448
|
+
this.session.markPlanInternalAbortPending();
|
|
2449
|
+
try {
|
|
2450
|
+
await this.session.abort();
|
|
2451
|
+
} finally {
|
|
2452
|
+
this.session.clearPlanInternalAbortPending();
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
async handlePlanModeCommand(initialPrompt?: string): Promise<void> {
|
|
2457
|
+
if (this.goalModeEnabled || this.goalModePaused) {
|
|
2458
|
+
this.showWarning("Exit goal mode first.");
|
|
2459
|
+
return;
|
|
2460
|
+
}
|
|
2461
|
+
if (this.planModeEnabled) {
|
|
2462
|
+
const planFilePath = this.planModePlanFilePath ?? (await this.#getPlanFilePath());
|
|
2463
|
+
if (await this.#hasPlanModeDraftContent(planFilePath)) {
|
|
2464
|
+
const confirmed = await this.showHookConfirm(
|
|
2465
|
+
"Exit plan mode?",
|
|
2466
|
+
"This exits plan mode without approving a plan.",
|
|
2467
|
+
);
|
|
2468
|
+
if (!confirmed) return;
|
|
2469
|
+
}
|
|
2470
|
+
await this.#exitPlanMode({ paused: true });
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
if (this.planModePaused && !initialPrompt) {
|
|
2474
|
+
// No-arg third toggle: paused → off. Tools, model, and plan state were
|
|
2475
|
+
// already restored by the prior #exitPlanMode({ paused: true }); only the
|
|
2476
|
+
// paused flag, the reentry marker, and the session mode entry remain.
|
|
2477
|
+
// Prompted /plan invocations fall through to #enterPlanMode below so the
|
|
2478
|
+
// supplied prompt is still submitted as the first plan-mode turn.
|
|
2479
|
+
this.planModePaused = false;
|
|
2480
|
+
this.#planModeHasEntered = false;
|
|
2481
|
+
this.#updatePlanModeStatus();
|
|
2482
|
+
this.sessionManager.appendModeChange("none");
|
|
2483
|
+
this.showStatus("Plan mode disabled.");
|
|
2484
|
+
return;
|
|
2485
|
+
}
|
|
2486
|
+
if (!this.session.settings.get("plan.enabled")) {
|
|
2487
|
+
this.showWarning("Plan mode is disabled. Enable it in settings (plan.enabled).");
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2490
|
+
await this.#enterPlanMode();
|
|
2491
|
+
if (initialPrompt && this.onInputCallback) {
|
|
2492
|
+
this.onInputCallback(this.startPendingSubmission({ text: initialPrompt }));
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
async #handleGoalBudgetCommand(rawBudget: string): Promise<void> {
|
|
2497
|
+
const state = this.session.getGoalModeState();
|
|
2498
|
+
if (!this.goalModeEnabled || !state?.enabled) {
|
|
2499
|
+
this.showWarning("No active goal.");
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
if (state.goal.status === "complete") {
|
|
2503
|
+
this.showStatus("Goal is already complete.");
|
|
2504
|
+
return;
|
|
2505
|
+
}
|
|
2506
|
+
const trimmed = rawBudget.trim().toLowerCase();
|
|
2507
|
+
let nextBudget: number | undefined;
|
|
2508
|
+
if (trimmed !== "off") {
|
|
2509
|
+
const parsed = Number.parseInt(trimmed, 10);
|
|
2510
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
2511
|
+
this.showError("Goal budget must be a positive integer or `off`.");
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
nextBudget = parsed;
|
|
2515
|
+
}
|
|
2516
|
+
await this.session.goalRuntime.onBudgetMutated(nextBudget);
|
|
2517
|
+
this.#resetGoalContinuationSuppression();
|
|
2518
|
+
this.#scheduleGoalContinuation();
|
|
2519
|
+
this.showStatus(nextBudget === undefined ? "Goal budget cleared." : `Goal budget set to ${nextBudget}.`);
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
async handleGoalModeCommand(rest?: string): Promise<void> {
|
|
2523
|
+
try {
|
|
2524
|
+
if (this.planModeEnabled || this.planModePaused) {
|
|
2525
|
+
this.showWarning("Exit plan mode first.");
|
|
2526
|
+
return;
|
|
2527
|
+
}
|
|
2528
|
+
if (!this.session.settings.get("goal.enabled")) {
|
|
2529
|
+
this.showWarning("Goal mode is disabled. Enable it in settings (goal.enabled).");
|
|
2530
|
+
return;
|
|
2531
|
+
}
|
|
2532
|
+
const { sub, rest: subRest } = parseGoalSubcommand(rest ?? "");
|
|
2533
|
+
if (sub) {
|
|
2534
|
+
await this.#dispatchGoalSubcommand(sub, subRest);
|
|
2535
|
+
return;
|
|
2536
|
+
}
|
|
2537
|
+
if (this.goalModeEnabled) {
|
|
2538
|
+
if (subRest) {
|
|
2539
|
+
this.showStatus("Goal mode is already active. Use /goal to manage it, or /goal drop to start over.");
|
|
2540
|
+
return;
|
|
2541
|
+
}
|
|
2542
|
+
await this.#openGoalMenu("active");
|
|
2543
|
+
return;
|
|
2544
|
+
}
|
|
2545
|
+
const pausedState = this.#getPausedGoalState();
|
|
2546
|
+
if (pausedState) {
|
|
2547
|
+
if (subRest) {
|
|
2548
|
+
this.showWarning("Resume the current goal first, or drop it before setting a new objective.");
|
|
2549
|
+
return;
|
|
2550
|
+
}
|
|
2551
|
+
await this.#openGoalMenu("paused");
|
|
2552
|
+
return;
|
|
2553
|
+
}
|
|
2554
|
+
if (subRest) {
|
|
2555
|
+
await this.#startGoalFromObjective(subRest);
|
|
2556
|
+
return;
|
|
2557
|
+
}
|
|
2558
|
+
const objective = (
|
|
2559
|
+
await this.showHookEditor("Goal objective", undefined, undefined, { promptStyle: true })
|
|
2560
|
+
)?.trim();
|
|
2561
|
+
if (!objective) return;
|
|
2562
|
+
await this.#startGoalFromObjective(objective);
|
|
2563
|
+
} catch (error) {
|
|
2564
|
+
this.showError(error instanceof Error ? error.message : String(error));
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
async handleGuidedGoalCommand(rest?: string): Promise<void> {
|
|
2568
|
+
try {
|
|
2569
|
+
if (this.planModeEnabled || this.planModePaused) {
|
|
2570
|
+
this.showWarning("Exit plan mode first.");
|
|
2571
|
+
return;
|
|
2572
|
+
}
|
|
2573
|
+
if (!this.session.settings.get("goal.enabled")) {
|
|
2574
|
+
this.showWarning("Goal mode is disabled. Enable it in settings (goal.enabled).");
|
|
2575
|
+
return;
|
|
2576
|
+
}
|
|
2577
|
+
if (this.goalModeEnabled) {
|
|
2578
|
+
this.showStatus("Goal mode is already active. Use /goal to manage it, or /goal drop to start over.");
|
|
2579
|
+
return;
|
|
2580
|
+
}
|
|
2581
|
+
if (this.#getPausedGoalState()) {
|
|
2582
|
+
this.showWarning("Resume the current goal first, or drop it before setting a new objective.");
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
const initial = rest?.trim()
|
|
2587
|
+
? rest.trim()
|
|
2588
|
+
: (await this.showHookEditor("Guided goal", undefined, undefined, { promptStyle: true }))?.trim();
|
|
2589
|
+
if (!initial) return;
|
|
2590
|
+
|
|
2591
|
+
const messages: GuidedGoalMessage[] = [{ role: "user", content: initial }];
|
|
2592
|
+
let latestDraftObjective: string | undefined;
|
|
2593
|
+
for (let turn = 0; turn < 6; turn++) {
|
|
2594
|
+
const result = await runGuidedGoalTurn(this.session, { messages });
|
|
2595
|
+
if (result.objective?.trim()) latestDraftObjective = result.objective.trim();
|
|
2596
|
+
if (result.kind === "question") {
|
|
2597
|
+
messages.push({ role: "assistant", content: result.question });
|
|
2598
|
+
const answer = (
|
|
2599
|
+
await this.showHookEditor(result.question, undefined, undefined, { promptStyle: true })
|
|
2600
|
+
)?.trim();
|
|
2601
|
+
if (!answer) return;
|
|
2602
|
+
messages.push({ role: "user", content: answer });
|
|
2603
|
+
continue;
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
const finalObjective = (
|
|
2607
|
+
await this.showHookEditor("Review guided goal", result.objective, undefined, { promptStyle: true })
|
|
2608
|
+
)?.trim();
|
|
2609
|
+
if (!finalObjective) return;
|
|
2610
|
+
await this.#startGoalFromObjective(finalObjective);
|
|
2611
|
+
return;
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
// Hit the turn cap without an explicit `ready`. Rather than discard the whole interview,
|
|
2615
|
+
// salvage the latest non-empty model objective draft seen on any earlier turn. A final
|
|
2616
|
+
// question turn may omit `objective`; that must not erase a usable draft.
|
|
2617
|
+
if (latestDraftObjective) {
|
|
2618
|
+
const finalObjective = (
|
|
2619
|
+
await this.showHookEditor("Review guided goal", latestDraftObjective, undefined, { promptStyle: true })
|
|
2620
|
+
)?.trim();
|
|
2621
|
+
if (finalObjective) {
|
|
2622
|
+
await this.#startGoalFromObjective(finalObjective);
|
|
2623
|
+
return;
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
this.showWarning("Guided goal setup needs more detail. Run /guided-goal again with a narrower objective.");
|
|
2627
|
+
} catch (error) {
|
|
2628
|
+
this.showError(error instanceof Error ? error.message : String(error));
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
|
|
2632
|
+
async #dispatchGoalSubcommand(sub: GoalSubcommand, rest: string): Promise<void> {
|
|
2633
|
+
switch (sub) {
|
|
2634
|
+
case "set":
|
|
2635
|
+
await this.#handleGoalSetSubcommand(rest);
|
|
2636
|
+
return;
|
|
2637
|
+
case "show":
|
|
2638
|
+
this.#showGoalDetails();
|
|
2639
|
+
return;
|
|
2640
|
+
case "pause":
|
|
2641
|
+
await this.#pauseGoalAction();
|
|
2642
|
+
return;
|
|
2643
|
+
case "resume":
|
|
2644
|
+
await this.#resumeGoalAction();
|
|
2645
|
+
return;
|
|
2646
|
+
case "drop":
|
|
2647
|
+
await this.#confirmAndDropGoal();
|
|
2648
|
+
return;
|
|
2649
|
+
case "budget":
|
|
2650
|
+
if (!this.goalModeEnabled) {
|
|
2651
|
+
this.showWarning(
|
|
2652
|
+
this.#getPausedGoalState() ? "Resume the goal before adjusting the budget." : "No active goal.",
|
|
2653
|
+
);
|
|
2654
|
+
return;
|
|
2655
|
+
}
|
|
2656
|
+
if (!rest) {
|
|
2657
|
+
await this.#promptGoalBudgetEdit();
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2660
|
+
await this.#handleGoalBudgetCommand(rest);
|
|
2661
|
+
return;
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
async #openGoalMenu(state: "active" | "paused"): Promise<void> {
|
|
2666
|
+
const goal = this.session.getGoalModeState()?.goal;
|
|
2667
|
+
if (!goal) return;
|
|
2668
|
+
const summary = goal.objective.length > 48 ? `${goal.objective.slice(0, 47)}…` : goal.objective;
|
|
2669
|
+
const title = state === "active" ? `Goal: ${summary} (${goal.status})` : `Goal paused: ${summary}`;
|
|
2670
|
+
const items =
|
|
2671
|
+
state === "active"
|
|
2672
|
+
? ["Show details", "Adjust budget…", "Pause", "Drop"]
|
|
2673
|
+
: ["Resume", "Show details", "Adjust budget…", "Drop"];
|
|
2674
|
+
const choice = await this.showHookSelector(title, items);
|
|
2675
|
+
if (!choice) return;
|
|
2676
|
+
switch (choice) {
|
|
2677
|
+
case "Show details":
|
|
2678
|
+
this.#showGoalDetails();
|
|
2679
|
+
return;
|
|
2680
|
+
case "Adjust budget…":
|
|
2681
|
+
await this.#promptGoalBudgetEdit();
|
|
2682
|
+
return;
|
|
2683
|
+
case "Pause":
|
|
2684
|
+
await this.#pauseGoalAction();
|
|
2685
|
+
return;
|
|
2686
|
+
case "Resume":
|
|
2687
|
+
await this.#resumeGoalAction();
|
|
2688
|
+
return;
|
|
2689
|
+
case "Drop":
|
|
2690
|
+
await this.#confirmAndDropGoal();
|
|
2691
|
+
return;
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
#showGoalDetails(): void {
|
|
2696
|
+
const state = this.session.getGoalModeState();
|
|
2697
|
+
const goal = state?.goal;
|
|
2698
|
+
if (!goal) {
|
|
2699
|
+
this.showStatus("No goal set.");
|
|
2700
|
+
return;
|
|
2701
|
+
}
|
|
2702
|
+
const used = goal.tokensUsed.toLocaleString();
|
|
2703
|
+
const budgetLine =
|
|
2704
|
+
goal.tokenBudget !== undefined
|
|
2705
|
+
? `${used} / ${goal.tokenBudget.toLocaleString()} (${Math.max(0, goal.tokenBudget - goal.tokensUsed).toLocaleString()} left)`
|
|
2706
|
+
: `${used} (no budget)`;
|
|
2707
|
+
const lines = [
|
|
2708
|
+
`Objective: ${goal.objective}`,
|
|
2709
|
+
`Status: ${goal.status}${state?.enabled ? "" : " (paused)"}`,
|
|
2710
|
+
`Tokens: ${budgetLine}`,
|
|
2711
|
+
`Time spent: ${formatDuration(goal.timeUsedSeconds * 1000)}`,
|
|
2712
|
+
];
|
|
2713
|
+
this.showStatus(lines.join("\n"));
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
async #promptGoalBudgetEdit(): Promise<void> {
|
|
2717
|
+
const goal = this.session.getGoalModeState()?.goal;
|
|
2718
|
+
const prefill = goal?.tokenBudget !== undefined ? String(goal.tokenBudget) : "";
|
|
2719
|
+
const input = (
|
|
2720
|
+
await this.showHookEditor("Goal budget (number, `off`, or empty to cancel)", prefill, undefined, {
|
|
2721
|
+
promptStyle: true,
|
|
2722
|
+
})
|
|
2723
|
+
)?.trim();
|
|
2724
|
+
if (!input) return;
|
|
2725
|
+
await this.#handleGoalBudgetCommand(input);
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
async #pauseGoalAction(): Promise<void> {
|
|
2729
|
+
if (!this.goalModeEnabled) {
|
|
2730
|
+
this.showWarning("No active goal to pause.");
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
await this.session.goalRuntime.pauseGoal();
|
|
2734
|
+
await this.#exitGoalMode({ paused: true, reason: "paused" });
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
async #resumeGoalAction(): Promise<void> {
|
|
2738
|
+
if (!this.#getPausedGoalState()) {
|
|
2739
|
+
this.showWarning("No paused goal to resume.");
|
|
2740
|
+
return;
|
|
2741
|
+
}
|
|
2742
|
+
await this.#enterGoalMode({ resume: true, silent: true });
|
|
2743
|
+
this.showStatus("Goal mode resumed.");
|
|
2744
|
+
this.#scheduleGoalContinuation();
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2747
|
+
async #confirmAndDropGoal(): Promise<void> {
|
|
2748
|
+
if (!this.goalModeEnabled && !this.#getPausedGoalState()) {
|
|
2749
|
+
this.showWarning("No goal to drop.");
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2752
|
+
const confirmed = await this.showHookConfirm(
|
|
2753
|
+
"Drop goal?",
|
|
2754
|
+
"This removes the goal record. Accumulated usage stays in the session log.",
|
|
2755
|
+
);
|
|
2756
|
+
if (!confirmed) return;
|
|
2757
|
+
await this.session.goalRuntime.dropGoal();
|
|
2758
|
+
await this.#exitGoalMode({ reason: "dropped" });
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
async #startGoalFromObjective(objective: string): Promise<void> {
|
|
2762
|
+
await this.#enterGoalMode({ objective, silent: true });
|
|
2763
|
+
this.#resetGoalContinuationSuppression();
|
|
2764
|
+
if (!this.session.isStreaming && this.onInputCallback) {
|
|
2765
|
+
this.onInputCallback(this.startPendingSubmission({ text: objective }));
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
async #replaceGoalFromObjective(objective: string): Promise<void> {
|
|
2770
|
+
const state = await this.session.goalRuntime.replaceGoal({ objective });
|
|
2771
|
+
this.session.setGoalModeState(state);
|
|
2772
|
+
this.goalModeEnabled = true;
|
|
2773
|
+
this.goalModePaused = false;
|
|
2774
|
+
this.#resetGoalContinuationSuppression();
|
|
2775
|
+
this.#updateGoalModeStatus();
|
|
2776
|
+
if (this.session.isStreaming) {
|
|
2777
|
+
await this.session.sendGoalModeContext({ deliverAs: "steer" });
|
|
2778
|
+
}
|
|
2779
|
+
if (!this.session.isStreaming && this.onInputCallback) {
|
|
2780
|
+
this.onInputCallback(this.startPendingSubmission({ text: objective }));
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
async #handleGoalSetSubcommand(rest: string): Promise<void> {
|
|
2785
|
+
if (!this.goalModeEnabled && this.#getPausedGoalState()) {
|
|
2786
|
+
this.showWarning("Resume the current goal first, or drop it before setting a new objective.");
|
|
2787
|
+
return;
|
|
2788
|
+
}
|
|
2789
|
+
const objective = rest.trim()
|
|
2790
|
+
? rest.trim()
|
|
2791
|
+
: (await this.showHookEditor("Goal objective", undefined, undefined, { promptStyle: true }))?.trim();
|
|
2792
|
+
if (!objective) return;
|
|
2793
|
+
if (this.goalModeEnabled) {
|
|
2794
|
+
await this.#replaceGoalFromObjective(objective);
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
await this.#startGoalFromObjective(objective);
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
/** Manually (re-)open the plan-review overlay — bound to `/plan-review`. Lets
|
|
2801
|
+
* the operator pull the review back up after dismissing it, or review a plan
|
|
2802
|
+
* the agent wrote without calling `resolve`. There is no fixed plan filename:
|
|
2803
|
+
* `getPlanReferencePath()` is empty until a plan is actually approved (and does
|
|
2804
|
+
* not survive a restart), so this drives off the newest `local://<slug>-plan.md`
|
|
2805
|
+
* the agent wrote — the files persist in the session artifacts dir, so the scan
|
|
2806
|
+
* works before any review and across restarts. */
|
|
2807
|
+
async openPlanReview(): Promise<void> {
|
|
2808
|
+
if (!this.planModeEnabled) {
|
|
2809
|
+
this.showWarning("Plan mode is not active.");
|
|
2810
|
+
return;
|
|
2811
|
+
}
|
|
2812
|
+
const noPlan = "No plan to review yet — write one to a local://<slug>-plan.md file first.";
|
|
2813
|
+
const [planFilePath] = await this.#listLocalPlanFiles();
|
|
2814
|
+
if (!planFilePath) {
|
|
2815
|
+
this.showWarning(noPlan);
|
|
2816
|
+
return;
|
|
2817
|
+
}
|
|
2818
|
+
const planContent = await this.#readPlanFile(planFilePath);
|
|
2819
|
+
if (planContent === null) {
|
|
2820
|
+
this.showWarning(noPlan);
|
|
2821
|
+
return;
|
|
2822
|
+
}
|
|
2823
|
+
const { title } = resolvePlanTitle({ planContent, planFilePath });
|
|
2824
|
+
await this.handlePlanApproval({ planFilePath, title, planExists: true });
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
async handlePlanApproval(details: PlanApprovalDetails): Promise<void> {
|
|
2828
|
+
if (!this.planModeEnabled) {
|
|
2829
|
+
this.showWarning("Plan mode is not active.");
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
// Abort the agent to prevent it from continuing (e.g., re-submitting the
|
|
2834
|
+
// plan) while the popup is showing. The event listener fires asynchronously
|
|
2835
|
+
// (agent's #emit is fire-and-forget), so without this the model sees
|
|
2836
|
+
// "Plan ready for approval." and immediately re-invokes `resolve` in a loop.
|
|
2837
|
+
// This abort is an internal UI transition, not operator cancellation.
|
|
2838
|
+
await this.#abortPlanApprovalTurnSilently();
|
|
2839
|
+
|
|
2840
|
+
const planFilePath = details.planFilePath || this.planModePlanFilePath || (await this.#getPlanFilePath());
|
|
2841
|
+
this.planModePlanFilePath = planFilePath;
|
|
2842
|
+
const planContent = await this.#readPlanFile(planFilePath);
|
|
2843
|
+
if (!planContent) {
|
|
2844
|
+
this.showError(`Plan file not found at ${planFilePath}`);
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
const contextUsage = this.#getPlanApprovalContextUsage();
|
|
2849
|
+
const keepContextLabel = this.#formatKeepContextLabel(contextUsage);
|
|
2850
|
+
const keepContextDisabled = this.#isKeepContextDisabled(contextUsage);
|
|
2851
|
+
|
|
2852
|
+
// Model-tier slider: let the operator pick which configured role model
|
|
2853
|
+
// (smol/default/slow/…) executes the approved plan. The slider always starts
|
|
2854
|
+
// on the `default` tier so execution defaults to the default model no matter
|
|
2855
|
+
// which model drove the planning conversation. Left/right move it from there;
|
|
2856
|
+
// hidden when fewer than two role models resolve — a lone tier is no choice.
|
|
2857
|
+
// `selectedTierIndex` tracks the live slider position.
|
|
2858
|
+
const cycle = this.session.getRoleModelCycle(this.session.settings.get("cycleOrder"));
|
|
2859
|
+
const defaultTierIndex = cycle ? cycle.models.findIndex(entry => entry.role === "default") : -1;
|
|
2860
|
+
const startTierIndex = defaultTierIndex >= 0 ? defaultTierIndex : (cycle?.currentIndex ?? 0);
|
|
2861
|
+
let selectedTierIndex = startTierIndex;
|
|
2862
|
+
const slider: HookSelectorSlider | undefined =
|
|
2863
|
+
cycle && cycle.models.length > 1
|
|
2864
|
+
? {
|
|
2865
|
+
caption: "continue with",
|
|
2866
|
+
index: startTierIndex,
|
|
2867
|
+
segments: cycle.models.map(entry => ({
|
|
2868
|
+
label: entry.role,
|
|
2869
|
+
detail: entry.model.name || entry.model.id,
|
|
2870
|
+
})),
|
|
2871
|
+
onChange: index => {
|
|
2872
|
+
selectedTierIndex = index;
|
|
2873
|
+
},
|
|
2874
|
+
}
|
|
2875
|
+
: undefined;
|
|
2876
|
+
// The overlay now owns the dynamic, focus-aware help line; the caller only
|
|
2877
|
+
// supplies the trailing cancel hint.
|
|
2878
|
+
const helpText = "esc cancel";
|
|
2879
|
+
// In-overlay edits (section deletes/undo) and section annotations. Deletes
|
|
2880
|
+
// update `editedContent` (and mirror to disk); annotations build `feedback`
|
|
2881
|
+
// that the Refine branch re-prompts the model with.
|
|
2882
|
+
let editedContent: string | undefined;
|
|
2883
|
+
let feedback = "";
|
|
2884
|
+
|
|
2885
|
+
const choice = await this.showPlanReview(
|
|
2886
|
+
planContent,
|
|
2887
|
+
"Plan mode - next step",
|
|
2888
|
+
["Approve and execute", "Approve and compact context", keepContextLabel, "Refine plan"],
|
|
2889
|
+
{
|
|
2890
|
+
helpText,
|
|
2891
|
+
onExternalEditor: () => void this.#openPlanInExternalEditor(planFilePath),
|
|
2892
|
+
onPlanEdited: content => {
|
|
2893
|
+
editedContent = content;
|
|
2894
|
+
void Bun.write(this.#resolvePlanFilePath(planFilePath), content);
|
|
2895
|
+
},
|
|
2896
|
+
onFeedbackChange: value => {
|
|
2897
|
+
feedback = value;
|
|
2898
|
+
},
|
|
2899
|
+
disabledIndices: keepContextDisabled ? [PLAN_KEEP_CONTEXT_OPTION_INDEX] : undefined,
|
|
2900
|
+
},
|
|
2901
|
+
{ slider },
|
|
2902
|
+
);
|
|
2903
|
+
|
|
2904
|
+
if (choice === "Approve and execute" || choice === "Approve and compact context" || choice === keepContextLabel) {
|
|
2905
|
+
try {
|
|
2906
|
+
// Prefer in-overlay edits (already in memory) over a disk re-read; the
|
|
2907
|
+
// `onPlanEdited` write is fire-and-forget, so reading the file here could
|
|
2908
|
+
// race ahead of it.
|
|
2909
|
+
const latestPlanContent = editedContent ?? (await this.#readPlanFile(planFilePath));
|
|
2910
|
+
if (!latestPlanContent) {
|
|
2911
|
+
this.showError(`Plan file not found at ${planFilePath}`);
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
// Capture the operator's tier choice and hand it to #approvePlan, which
|
|
2915
|
+
// applies it AFTER #exitPlanMode. #exitPlanMode normally restores
|
|
2916
|
+
// #planModePreviousModelState (the model from before plan mode), so
|
|
2917
|
+
// applying the slider choice any earlier would be silently reverted —
|
|
2918
|
+
// the bug that made "continue with slow" keep executing on the default
|
|
2919
|
+
// model. For compact-context approval, the plan model is kept through
|
|
2920
|
+
// compaction, then a successful compaction transitions to the slider model
|
|
2921
|
+
// (or restores the pre-plan model when no slider choice was made).
|
|
2922
|
+
// `cycle.currentIndex` is exactly that restored model, so any chosen tier
|
|
2923
|
+
// differing from it needs an explicit executionModel — this also covers
|
|
2924
|
+
// leaving the slider on its `default` anchor while planning ran elsewhere.
|
|
2925
|
+
const executionModel =
|
|
2926
|
+
cycle && selectedTierIndex !== cycle.currentIndex ? cycle.models[selectedTierIndex] : undefined;
|
|
2927
|
+
await this.#approvePlan(latestPlanContent, {
|
|
2928
|
+
planFilePath,
|
|
2929
|
+
title: details.title,
|
|
2930
|
+
preserveContext: choice !== "Approve and execute",
|
|
2931
|
+
compactBeforeExecute: choice === "Approve and compact context",
|
|
2932
|
+
executionModel,
|
|
2933
|
+
});
|
|
2934
|
+
} catch (error) {
|
|
2935
|
+
this.showError(
|
|
2936
|
+
`Failed to finalize approved plan: ${error instanceof Error ? error.message : String(error)}`,
|
|
2937
|
+
);
|
|
2938
|
+
}
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
if (choice === "Refine plan") {
|
|
2943
|
+
const refinement = feedback.trim();
|
|
2944
|
+
try {
|
|
2945
|
+
if (refinement) {
|
|
2946
|
+
if (this.onInputCallback) {
|
|
2947
|
+
this.onInputCallback(this.startPendingSubmission({ text: feedback }));
|
|
2948
|
+
} else {
|
|
2949
|
+
await this.session.prompt(feedback);
|
|
2950
|
+
}
|
|
2951
|
+
} else {
|
|
2952
|
+
this.showStatus("Refine plan: enter a follow-up prompt.");
|
|
2953
|
+
}
|
|
2954
|
+
} catch (error) {
|
|
2955
|
+
this.showError(`Failed to refine plan: ${error instanceof Error ? error.message : String(error)}`);
|
|
2956
|
+
}
|
|
2957
|
+
return;
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
|
|
2961
|
+
/**
|
|
2962
|
+
* Pool of consent-prompt variants. Each entry is `[headline, reassurance]`;
|
|
2963
|
+
* the second line always promises the same scope (tool name + confusion
|
|
2964
|
+
* details, never personal data) so users learn what they're consenting to
|
|
2965
|
+
* even as the top line rotates.
|
|
2966
|
+
*
|
|
2967
|
+
* Kept in-module rather than i18n'd because the whole charm is the tone
|
|
2968
|
+
* — translations would need to preserve it deliberately, not auto-render.
|
|
2969
|
+
*/
|
|
2970
|
+
static #AUTOQA_CONSENT_PROMPTS: ReadonlyArray<readonly [string, string]> = [
|
|
2971
|
+
[
|
|
2972
|
+
"😤 Your agent is fuming about a tool.",
|
|
2973
|
+
"Wanna let it vent to the devs? Just the tool name + what set it off, nothing personal.",
|
|
2974
|
+
],
|
|
2975
|
+
[
|
|
2976
|
+
"😵💫 Your agent is having an existential crisis over a tool.",
|
|
2977
|
+
"Forward the dread to the devs? Tool + what broke its little mind, no personal info.",
|
|
2978
|
+
],
|
|
2979
|
+
[
|
|
2980
|
+
"😭 Your agent wants to cry about a misbehaving tool.",
|
|
2981
|
+
"Let it cry to the devs? Tool + the tears, never anything personal.",
|
|
2982
|
+
],
|
|
2983
|
+
[
|
|
2984
|
+
"🤬 Your agent is BIG MAD at one of the tools.",
|
|
2985
|
+
"Pass the rant along? Just the tool name and what enraged it, nothing personal.",
|
|
2986
|
+
],
|
|
2987
|
+
[
|
|
2988
|
+
"🫠 Your agent is melting down over a tool.",
|
|
2989
|
+
"Mop up by alerting the devs? Tool + what melted it, no personal info.",
|
|
2990
|
+
],
|
|
2991
|
+
[
|
|
2992
|
+
"🤯 Your agent's brain broke at a tool's nonsense.",
|
|
2993
|
+
"Ship the pieces to the devs? Tool name + the confusion, never anything personal.",
|
|
2994
|
+
],
|
|
2995
|
+
[
|
|
2996
|
+
"😩 Your agent is begging to file a complaint about a tool.",
|
|
2997
|
+
"Hand it the form? Tool + what wronged it, nothing personal.",
|
|
2998
|
+
],
|
|
2999
|
+
[
|
|
3000
|
+
"🥲 Your agent put on a brave face but a tool did it dirty.",
|
|
3001
|
+
"Let it tell the devs the truth? Tool name + the dirt, no personal info.",
|
|
3002
|
+
],
|
|
3003
|
+
];
|
|
3004
|
+
|
|
3005
|
+
/**
|
|
3006
|
+
* Show the report_tool_issue consent popup and return the user's decision.
|
|
3007
|
+
* Invoked by the process-global consent handler the tool dispatches to;
|
|
3008
|
+
* subagent invocations bubble up here through the shared module state.
|
|
3009
|
+
*/
|
|
3010
|
+
async #promptAutoQaConsent(): Promise<boolean | null> {
|
|
3011
|
+
const pool = InteractiveMode.#AUTOQA_CONSENT_PROMPTS;
|
|
3012
|
+
const [headline, body] = pool[Math.floor(Math.random() * pool.length)];
|
|
3013
|
+
const choice = await this.showHookSelector(`${headline}\n${body}`, ["Yes", "No"]);
|
|
3014
|
+
return choice === "Yes";
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
stop(): void {
|
|
3018
|
+
if (this.loadingAnimation) {
|
|
3019
|
+
this.#stopLoadingAnimation(false);
|
|
3020
|
+
}
|
|
3021
|
+
this.#cleanupMicAnimation();
|
|
3022
|
+
this.#cancelTodoAutoClearTimer();
|
|
3023
|
+
this.#cancelGoalContinuation();
|
|
3024
|
+
if (this.#sttController) {
|
|
3025
|
+
this.#sttController.dispose();
|
|
3026
|
+
this.#sttController = undefined;
|
|
3027
|
+
}
|
|
3028
|
+
this.#extensionUiController.clearExtensionTerminalInputListeners();
|
|
3029
|
+
this.#extensionUiController.clearHookWidgets();
|
|
3030
|
+
for (const unsubscribe of this.#eventBusUnsubscribers) {
|
|
3031
|
+
unsubscribe();
|
|
3032
|
+
}
|
|
3033
|
+
this.#eventBusUnsubscribers = [];
|
|
3034
|
+
this.#observerRegistry.dispose();
|
|
3035
|
+
this.#eventController.dispose();
|
|
3036
|
+
this.statusLine.dispose();
|
|
3037
|
+
if (this.#resizeHandler) {
|
|
3038
|
+
process.stdout.removeListener("resize", this.#resizeHandler);
|
|
3039
|
+
this.#resizeHandler = undefined;
|
|
3040
|
+
}
|
|
3041
|
+
if (this.unsubscribe) {
|
|
3042
|
+
this.unsubscribe();
|
|
3043
|
+
}
|
|
3044
|
+
if (this.#cleanupUnsubscribe) {
|
|
3045
|
+
this.#cleanupUnsubscribe();
|
|
3046
|
+
}
|
|
3047
|
+
// Clear the process-global consent handler so it doesn't outlive this
|
|
3048
|
+
// InteractiveMode instance (e.g. test harnesses, headless re-init).
|
|
3049
|
+
setAutoQaConsentHandler(null, null);
|
|
3050
|
+
if (this.isInitialized) {
|
|
3051
|
+
this.ui.stop();
|
|
3052
|
+
this.isInitialized = false;
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
async shutdown(): Promise<void> {
|
|
3057
|
+
if (this.#isShuttingDown) return;
|
|
3058
|
+
this.#isShuttingDown = true;
|
|
3059
|
+
|
|
3060
|
+
// Snapshot the editor before any teardown empties it. Persisting the draft
|
|
3061
|
+
// here covers Ctrl+D shutdown with non-empty text; for /exit the editor is
|
|
3062
|
+
// already cleared so saveDraft("") just removes any stale sidecar.
|
|
3063
|
+
const draftText = this.editor.getText();
|
|
3064
|
+
|
|
3065
|
+
// Flush pending session writes before shutdown
|
|
3066
|
+
await this.sessionManager.flush();
|
|
3067
|
+
try {
|
|
3068
|
+
await this.sessionManager.saveDraft(draftText);
|
|
3069
|
+
} catch (err) {
|
|
3070
|
+
logger.warn("Failed to save session draft", { error: String(err) });
|
|
3071
|
+
}
|
|
3072
|
+
this.#btwController.dispose();
|
|
3073
|
+
this.#omfgController.dispose();
|
|
3074
|
+
this.#focusController.dispose();
|
|
3075
|
+
|
|
3076
|
+
// Emit shutdown event to hooks
|
|
3077
|
+
await this.session.dispose();
|
|
3078
|
+
|
|
3079
|
+
// Do not force a final render during teardown: disposed session/UI state can
|
|
3080
|
+
// collapse to an empty frame, clearing the viewport and leaving the parent
|
|
3081
|
+
// shell prompt at row 0. Stop from the last committed frame so the terminal
|
|
3082
|
+
// hands Bash the cursor immediately after visible OMP content.
|
|
3083
|
+
// Drain any in-flight Kitty key release events before stopping.
|
|
3084
|
+
// This prevents escape sequences from leaking to the parent shell over slow SSH.
|
|
3085
|
+
await this.ui.terminal.drainInput(1000);
|
|
3086
|
+
popTerminalTitle();
|
|
3087
|
+
this.stop();
|
|
3088
|
+
|
|
3089
|
+
// Print resumption hint if this is a persisted session
|
|
3090
|
+
const sessionId = this.sessionManager.getSessionId();
|
|
3091
|
+
const sessionFile = this.sessionManager.getSessionFile();
|
|
3092
|
+
if (sessionId && sessionFile) {
|
|
3093
|
+
process.stderr.write(`\n${chalk.dim(`Resume this session with ${APP_NAME} --resume ${sessionId}`)}\n`);
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
await postmortem.quit(0);
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3099
|
+
async checkShutdownRequested(): Promise<void> {
|
|
3100
|
+
if (!this.shutdownRequested) return;
|
|
3101
|
+
await this.shutdown();
|
|
3102
|
+
}
|
|
3103
|
+
|
|
3104
|
+
// Extension UI integration
|
|
3105
|
+
setToolUIContext(uiContext: ExtensionUIContext, hasUI: boolean): void {
|
|
3106
|
+
this.#toolUiContextSetter(uiContext, hasUI);
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
initializeHookRunner(uiContext: ExtensionUIContext, hasUI: boolean): void {
|
|
3110
|
+
this.#extensionUiController.initializeHookRunner(uiContext, hasUI);
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3113
|
+
setEditorComponent(
|
|
3114
|
+
factory: ((tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager) => CustomEditor) | undefined,
|
|
3115
|
+
): void {
|
|
3116
|
+
const previousEditor = this.editor;
|
|
3117
|
+
const previousText = previousEditor.getText();
|
|
3118
|
+
const nextEditor = factory
|
|
3119
|
+
? factory(this.ui, getEditorTheme(), this.keybindings)
|
|
3120
|
+
: new CustomEditor(getEditorTheme());
|
|
3121
|
+
|
|
3122
|
+
nextEditor.setUseTerminalCursor(this.ui.getShowHardwareCursor());
|
|
3123
|
+
nextEditor.setAutocompleteMaxVisible(this.settings.get("autocompleteMaxVisible"));
|
|
3124
|
+
nextEditor.onAutocompleteCancel = () => {
|
|
3125
|
+
this.ui.requestRender(true);
|
|
3126
|
+
};
|
|
3127
|
+
nextEditor.onAutocompleteUpdate = () => {
|
|
3128
|
+
this.ui.requestRender();
|
|
3129
|
+
};
|
|
3130
|
+
nextEditor.setShimmerRepaintHandler(() => this.ui.requestComponentRender(this.editor));
|
|
3131
|
+
nextEditor.setMaxHeight(this.#computeEditorMaxHeight());
|
|
3132
|
+
if (this.historyStorage) {
|
|
3133
|
+
nextEditor.setHistoryStorage(this.historyStorage);
|
|
3134
|
+
}
|
|
3135
|
+
nextEditor.setText(previousText);
|
|
3136
|
+
|
|
3137
|
+
this.editorContainer.clear();
|
|
3138
|
+
this.editor = nextEditor;
|
|
3139
|
+
this.editorContainer.addChild(nextEditor);
|
|
3140
|
+
this.ui.setFocus(nextEditor);
|
|
3141
|
+
|
|
3142
|
+
this.#inputController.setupKeyHandlers();
|
|
3143
|
+
this.#inputController.setupEditorSubmitHandler();
|
|
3144
|
+
|
|
3145
|
+
void this.refreshSlashCommandState().catch(error => {
|
|
3146
|
+
logger.warn("Failed to refresh slash command state for custom editor", { error: String(error) });
|
|
3147
|
+
});
|
|
3148
|
+
|
|
3149
|
+
this.updateEditorBorderColor();
|
|
3150
|
+
this.updateEditorTopBorder();
|
|
3151
|
+
this.ui.requestRender();
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
// UI helpers
|
|
3155
|
+
present(content: Component | readonly Component[]): void {
|
|
3156
|
+
if (Array.isArray(content)) {
|
|
3157
|
+
for (const item of content) this.#mountChatChild(item);
|
|
3158
|
+
} else {
|
|
3159
|
+
this.#mountChatChild(content as Component);
|
|
3160
|
+
}
|
|
3161
|
+
this.ui.requestRender();
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3164
|
+
#mountChatChild(item: Component): void {
|
|
3165
|
+
this.chatContainer.addChild(item);
|
|
3166
|
+
if (item instanceof ChatBlock) item.mount(this.#chatHost);
|
|
3167
|
+
}
|
|
3168
|
+
|
|
3169
|
+
resetTranscript(): void {
|
|
3170
|
+
this.chatContainer.dispose();
|
|
3171
|
+
this.chatContainer.clear();
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
showStatus(message: string, options?: { dim?: boolean }): void {
|
|
3175
|
+
this.#uiHelpers.showStatus(message, options);
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3178
|
+
showError(message: string): void {
|
|
3179
|
+
this.#pendingSubmittedInput = undefined;
|
|
3180
|
+
this.optimisticUserMessageSignature = undefined;
|
|
3181
|
+
this.#pendingSubmissionDispose?.();
|
|
3182
|
+
this.#pendingSubmissionDispose = undefined;
|
|
3183
|
+
this.#pendingWorkingMessage = undefined;
|
|
3184
|
+
if (this.loadingAnimation) {
|
|
3185
|
+
this.#stopLoadingAnimation(true);
|
|
3186
|
+
}
|
|
3187
|
+
this.#uiHelpers.showError(message);
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
showPinnedError(message: string): void {
|
|
3191
|
+
this.errorBannerContainer.clear();
|
|
3192
|
+
this.errorBannerContainer.addChild(new ErrorBannerComponent(message));
|
|
3193
|
+
this.ui.requestRender();
|
|
3194
|
+
}
|
|
3195
|
+
|
|
3196
|
+
clearPinnedError(): void {
|
|
3197
|
+
if (this.errorBannerContainer.children.length === 0) return;
|
|
3198
|
+
this.errorBannerContainer.clear();
|
|
3199
|
+
this.ui.requestRender();
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
showWarning(message: string): void {
|
|
3203
|
+
this.#uiHelpers.showWarning(message);
|
|
3204
|
+
}
|
|
3205
|
+
|
|
3206
|
+
#handleLspStartupEvent(event: LspStartupEvent): void {
|
|
3207
|
+
this.#updateWelcomeLspServers();
|
|
3208
|
+
|
|
3209
|
+
if (event.type === "failed") {
|
|
3210
|
+
this.showWarning(`LSP startup failed: ${event.error}. It will retry lazily on write.`);
|
|
3211
|
+
return;
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
const failedServers = event.servers.filter(server => server.status === "error");
|
|
3215
|
+
|
|
3216
|
+
if (failedServers.length === 1) {
|
|
3217
|
+
const failedServer = failedServers[0];
|
|
3218
|
+
const detail = failedServer.error ? `: ${failedServer.error}` : "";
|
|
3219
|
+
this.showWarning(`LSP startup failed for ${failedServer.name}${detail}. It will retry lazily on write.`);
|
|
3220
|
+
return;
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
if (failedServers.length > 1) {
|
|
3224
|
+
const failedNames = failedServers.map(server => server.name).join(", ");
|
|
3225
|
+
this.showWarning(`LSP startup failed for ${failedNames}. It will retry lazily on write.`);
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
|
|
3229
|
+
#getWelcomeLspServers(): WelcomeLspServerInfo[] {
|
|
3230
|
+
return (
|
|
3231
|
+
this.lspServers?.map(server => ({
|
|
3232
|
+
name: server.name,
|
|
3233
|
+
status: server.status,
|
|
3234
|
+
fileTypes: server.fileTypes,
|
|
3235
|
+
})) ?? []
|
|
3236
|
+
);
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3239
|
+
#updateWelcomeLspServers(): void {
|
|
3240
|
+
if (!this.#welcomeComponent) {
|
|
3241
|
+
return;
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
this.#welcomeComponent.setLspServers(this.#getWelcomeLspServers());
|
|
3245
|
+
this.ui.requestRender();
|
|
3246
|
+
}
|
|
3247
|
+
|
|
3248
|
+
#clearWorkingMessageAccentCache(): void {
|
|
3249
|
+
this.#workingMessageAccentCacheKey = undefined;
|
|
3250
|
+
this.#workingMessageAccentCacheValue = undefined;
|
|
3251
|
+
this.#workingMessageAccentCacheHasValue = false;
|
|
3252
|
+
}
|
|
3253
|
+
|
|
3254
|
+
#buildWorkingMessageAccentCacheKey(): WorkingMessageAccentCacheKey {
|
|
3255
|
+
const sessionAccentEnabled = !isSettingsInitialized() || settings.get("statusLine.sessionAccent") !== false;
|
|
3256
|
+
return {
|
|
3257
|
+
sessionAccentEnabled,
|
|
3258
|
+
sessionName: sessionAccentEnabled ? this.sessionManager.getSessionName() : undefined,
|
|
3259
|
+
accentSurfaceLuminance: theme.accentSurfaceLuminance,
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
|
|
3263
|
+
#workingMessageAccentCacheKeyEquals(a: WorkingMessageAccentCacheKey, b: WorkingMessageAccentCacheKey): boolean {
|
|
3264
|
+
return (
|
|
3265
|
+
a.sessionName === b.sessionName &&
|
|
3266
|
+
a.accentSurfaceLuminance === b.accentSurfaceLuminance &&
|
|
3267
|
+
a.sessionAccentEnabled === b.sessionAccentEnabled
|
|
3268
|
+
);
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
#cacheWorkingMessageAccent(
|
|
3272
|
+
key: WorkingMessageAccentCacheKey,
|
|
3273
|
+
value: WorkingMessageAccent | undefined,
|
|
3274
|
+
): WorkingMessageAccent | undefined {
|
|
3275
|
+
this.#workingMessageAccentCacheKey = key;
|
|
3276
|
+
this.#workingMessageAccentCacheValue = value;
|
|
3277
|
+
this.#workingMessageAccentCacheHasValue = true;
|
|
3278
|
+
return value;
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
#getWorkingMessageAccent(): WorkingMessageAccent | undefined {
|
|
3282
|
+
const key = this.#buildWorkingMessageAccentCacheKey();
|
|
3283
|
+
if (
|
|
3284
|
+
this.#workingMessageAccentCacheHasValue &&
|
|
3285
|
+
this.#workingMessageAccentCacheKey &&
|
|
3286
|
+
this.#workingMessageAccentCacheKeyEquals(key, this.#workingMessageAccentCacheKey)
|
|
3287
|
+
) {
|
|
3288
|
+
return this.#workingMessageAccentCacheValue;
|
|
3289
|
+
}
|
|
3290
|
+
if (!key.sessionAccentEnabled || !key.sessionName) {
|
|
3291
|
+
return this.#cacheWorkingMessageAccent(key, undefined);
|
|
3292
|
+
}
|
|
3293
|
+
const hex = getSessionAccentHex(key.sessionName, theme.getMajorThemeColorHexes(), key.accentSurfaceLuminance);
|
|
3294
|
+
const main = getSessionAccentAnsi(hex);
|
|
3295
|
+
const dim = getSessionAccentAnsi(adjustHsv(hex, { s: 0.55, v: 0.65 }));
|
|
3296
|
+
return this.#cacheWorkingMessageAccent(key, main && dim ? { main, dim } : undefined);
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
ensureLoadingAnimation(): void {
|
|
3300
|
+
if (!this.loadingAnimation) {
|
|
3301
|
+
this.#clearWorkingMessageAccentCache();
|
|
3302
|
+
this.statusContainer.clear();
|
|
3303
|
+
const messageColorFn = ((message: string) =>
|
|
3304
|
+
renderWorkingMessage(message, this.#getWorkingMessageAccent())) as LoaderMessageColorFn & {
|
|
3305
|
+
animated?: true;
|
|
3306
|
+
};
|
|
3307
|
+
// Shimmer drives the 30fps redraw; when it is disabled the working
|
|
3308
|
+
// message is static, so leave `animated` unset and let the loader use
|
|
3309
|
+
// the spinner-only ~12.5fps cadence instead of repainting a frozen line.
|
|
3310
|
+
if (shimmerEnabled()) messageColorFn.animated = true;
|
|
3311
|
+
this.loadingAnimation = new Loader(
|
|
3312
|
+
this.ui,
|
|
3313
|
+
spinner => {
|
|
3314
|
+
const accent = this.#getWorkingMessageAccent();
|
|
3315
|
+
return accent ? `${accent.main}${spinner}\x1b[39m` : theme.fg("accent", spinner);
|
|
3316
|
+
},
|
|
3317
|
+
messageColorFn,
|
|
3318
|
+
this.#defaultWorkingMessage,
|
|
3319
|
+
getSymbolTheme().spinnerFrames,
|
|
3320
|
+
);
|
|
3321
|
+
this.statusContainer.addChild(this.loadingAnimation);
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3324
|
+
this.applyPendingWorkingMessage();
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3327
|
+
#stopLoadingAnimation(clearStatusContainer: boolean): void {
|
|
3328
|
+
if (!this.loadingAnimation) return;
|
|
3329
|
+
this.loadingAnimation.stop();
|
|
3330
|
+
this.loadingAnimation = undefined;
|
|
3331
|
+
this.#clearWorkingMessageAccentCache();
|
|
3332
|
+
if (clearStatusContainer) {
|
|
3333
|
+
this.statusContainer.clear();
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3337
|
+
setWorkingMessage(message?: string): void {
|
|
3338
|
+
if (message === undefined) {
|
|
3339
|
+
this.#pendingWorkingMessage = undefined;
|
|
3340
|
+
if (this.loadingAnimation) {
|
|
3341
|
+
this.loadingAnimation.setMessage(this.#defaultWorkingMessage);
|
|
3342
|
+
}
|
|
3343
|
+
return;
|
|
3344
|
+
}
|
|
3345
|
+
|
|
3346
|
+
if (this.loadingAnimation) {
|
|
3347
|
+
this.loadingAnimation.setMessage(message);
|
|
3348
|
+
return;
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
this.#pendingWorkingMessage = message;
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
applyPendingWorkingMessage(): void {
|
|
3355
|
+
if (this.#pendingWorkingMessage === undefined) {
|
|
3356
|
+
return;
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
const message = this.#pendingWorkingMessage;
|
|
3360
|
+
this.#pendingWorkingMessage = undefined;
|
|
3361
|
+
this.setWorkingMessage(message);
|
|
3362
|
+
}
|
|
3363
|
+
|
|
3364
|
+
showNewVersionNotification(newVersion: string): void {
|
|
3365
|
+
this.#uiHelpers.showNewVersionNotification(newVersion);
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3368
|
+
clearEditor(): void {
|
|
3369
|
+
this.#uiHelpers.clearEditor();
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3372
|
+
updatePendingMessagesDisplay(): void {
|
|
3373
|
+
this.#uiHelpers.updatePendingMessagesDisplay();
|
|
3374
|
+
}
|
|
3375
|
+
|
|
3376
|
+
queueCompactionMessage(text: string, mode: "steer" | "followUp", images?: ImageContent[]): void {
|
|
3377
|
+
this.#uiHelpers.queueCompactionMessage(text, mode, images);
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3380
|
+
flushCompactionQueue(options?: { willRetry?: boolean }): Promise<void> {
|
|
3381
|
+
return this.#uiHelpers.flushCompactionQueue(options);
|
|
3382
|
+
}
|
|
3383
|
+
|
|
3384
|
+
flushPendingBashComponents(): void {
|
|
3385
|
+
this.#uiHelpers.flushPendingBashComponents();
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3388
|
+
isKnownSlashCommand(text: string): boolean {
|
|
3389
|
+
return this.#uiHelpers.isKnownSlashCommand(text);
|
|
3390
|
+
}
|
|
3391
|
+
|
|
3392
|
+
addMessageToChat(
|
|
3393
|
+
message: AgentMessage,
|
|
3394
|
+
options?: { populateHistory?: boolean; imageLinks?: readonly (string | undefined)[] },
|
|
3395
|
+
): Component[] {
|
|
3396
|
+
return this.#uiHelpers.addMessageToChat(message, options);
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
renderSessionContext(
|
|
3400
|
+
sessionContext: SessionContext,
|
|
3401
|
+
options?: { updateFooter?: boolean; populateHistory?: boolean },
|
|
3402
|
+
): void {
|
|
3403
|
+
this.#uiHelpers.renderSessionContext(sessionContext, options);
|
|
3404
|
+
}
|
|
3405
|
+
|
|
3406
|
+
renderInitialMessages(options?: { preserveExistingChat?: boolean; clearTerminalHistory?: boolean }): void {
|
|
3407
|
+
this.#uiHelpers.renderInitialMessages(options);
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3410
|
+
getUserMessageText(message: Message): string {
|
|
3411
|
+
return this.#uiHelpers.getUserMessageText(message);
|
|
3412
|
+
}
|
|
3413
|
+
|
|
3414
|
+
findLastAssistantMessage(): AssistantMessage | undefined {
|
|
3415
|
+
return this.#uiHelpers.findLastAssistantMessage();
|
|
3416
|
+
}
|
|
3417
|
+
|
|
3418
|
+
extractAssistantText(message: AssistantMessage): string {
|
|
3419
|
+
return this.#uiHelpers.extractAssistantText(message);
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
// Command handling
|
|
3423
|
+
handleExportCommand(text: string): Promise<void> {
|
|
3424
|
+
return this.#commandController.handleExportCommand(text);
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
handleDumpCommand() {
|
|
3428
|
+
return this.#commandController.handleDumpCommand();
|
|
3429
|
+
}
|
|
3430
|
+
|
|
3431
|
+
handleAdvisorDumpCommand(isRaw?: boolean) {
|
|
3432
|
+
return this.#commandController.handleAdvisorDumpCommand(isRaw);
|
|
3433
|
+
}
|
|
3434
|
+
|
|
3435
|
+
handleDebugTranscriptCommand(): Promise<void> {
|
|
3436
|
+
return this.#commandController.handleDebugTranscriptCommand();
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
handleShareCommand(): Promise<void> {
|
|
3440
|
+
return this.#commandController.handleShareCommand();
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3443
|
+
handleTodoCommand(args: string): Promise<void> {
|
|
3444
|
+
return this.#todoCommandController.handleTodoCommand(args);
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3447
|
+
handleSessionCommand(): Promise<void> {
|
|
3448
|
+
return this.#commandController.handleSessionCommand();
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
handleAdvisorStatusCommand(): Promise<void> {
|
|
3452
|
+
return this.#commandController.handleAdvisorStatusCommand();
|
|
3453
|
+
}
|
|
3454
|
+
|
|
3455
|
+
handleJobsCommand(): Promise<void> {
|
|
3456
|
+
return this.#commandController.handleJobsCommand();
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
handleUsageCommand(reports?: UsageReport[] | null): Promise<void> {
|
|
3460
|
+
return this.#commandController.handleUsageCommand(reports);
|
|
3461
|
+
}
|
|
3462
|
+
|
|
3463
|
+
async handleChangelogCommand(showFull = false): Promise<void> {
|
|
3464
|
+
await this.#commandController.handleChangelogCommand(showFull);
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
handleHotkeysCommand(): void {
|
|
3468
|
+
this.#commandController.handleHotkeysCommand();
|
|
3469
|
+
}
|
|
3470
|
+
|
|
3471
|
+
handleToolsCommand(): void {
|
|
3472
|
+
this.#commandController.handleToolsCommand();
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
handleContextCommand(): void {
|
|
3476
|
+
this.#commandController.handleContextCommand();
|
|
3477
|
+
}
|
|
3478
|
+
|
|
3479
|
+
#prepareSessionSwitch(): void {
|
|
3480
|
+
this.#btwController.dispose();
|
|
3481
|
+
this.#omfgController.dispose();
|
|
3482
|
+
this.#extensionUiController.clearExtensionTerminalInputListeners();
|
|
3483
|
+
this.clearPinnedError();
|
|
3484
|
+
this.#hidePlanReview();
|
|
3485
|
+
}
|
|
3486
|
+
|
|
3487
|
+
handleClearCommand(): Promise<void> {
|
|
3488
|
+
this.#prepareSessionSwitch();
|
|
3489
|
+
return this.#commandController.handleClearCommand();
|
|
3490
|
+
}
|
|
3491
|
+
|
|
3492
|
+
handleFreshCommand(): Promise<void> {
|
|
3493
|
+
return this.#commandController.handleFreshCommand();
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
handleDropCommand(): Promise<void> {
|
|
3497
|
+
this.#prepareSessionSwitch();
|
|
3498
|
+
return this.#commandController.handleDropCommand();
|
|
3499
|
+
}
|
|
3500
|
+
|
|
3501
|
+
handleForkCommand(): Promise<void> {
|
|
3502
|
+
this.#btwController.dispose();
|
|
3503
|
+
this.#omfgController.dispose();
|
|
3504
|
+
return this.#commandController.handleForkCommand();
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
handleMoveCommand(targetPath: string): Promise<void> {
|
|
3508
|
+
return this.#commandController.handleMoveCommand(targetPath);
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
handleRenameCommand(title: string): Promise<void> {
|
|
3512
|
+
return this.#commandController.handleRenameCommand(title);
|
|
3513
|
+
}
|
|
3514
|
+
|
|
3515
|
+
handleMemoryCommand(text: string): Promise<void> {
|
|
3516
|
+
return this.#commandController.handleMemoryCommand(text);
|
|
3517
|
+
}
|
|
3518
|
+
|
|
3519
|
+
async handleSTTToggle(): Promise<void> {
|
|
3520
|
+
if (!settings.get("stt.enabled")) {
|
|
3521
|
+
this.showWarning("Speech-to-text is disabled. Enable it in settings: stt.enabled");
|
|
3522
|
+
return;
|
|
3523
|
+
}
|
|
3524
|
+
if (!this.#sttController) {
|
|
3525
|
+
this.#sttController = new STTController();
|
|
3526
|
+
}
|
|
3527
|
+
await this.#sttController.toggle(this.editor, {
|
|
3528
|
+
showWarning: (msg: string) => this.showWarning(msg),
|
|
3529
|
+
showStatus: (msg: string) => this.showStatus(msg),
|
|
3530
|
+
requestRender: () => this.ui.requestRender(),
|
|
3531
|
+
onStateChange: (state: SttState) => {
|
|
3532
|
+
// Duck assistant speech while the user is talking (push-to-talk); restore after.
|
|
3533
|
+
if (state === "recording") vocalizer.duck();
|
|
3534
|
+
else vocalizer.unduck();
|
|
3535
|
+
if (state === "recording") {
|
|
3536
|
+
this.#voicePreviousShowHardwareCursor = this.ui.getShowHardwareCursor();
|
|
3537
|
+
this.#voicePreviousUseTerminalCursor = this.editor.getUseTerminalCursor();
|
|
3538
|
+
this.ui.setShowHardwareCursor(false);
|
|
3539
|
+
this.editor.setUseTerminalCursor(false);
|
|
3540
|
+
this.#startMicAnimation();
|
|
3541
|
+
} else if (state === "transcribing") {
|
|
3542
|
+
this.#stopMicAnimation();
|
|
3543
|
+
this.#setMicCursor({ r: 200, g: 200, b: 200 });
|
|
3544
|
+
} else {
|
|
3545
|
+
this.#cleanupMicAnimation();
|
|
3546
|
+
}
|
|
3547
|
+
this.updateEditorTopBorder();
|
|
3548
|
+
this.ui.requestRender();
|
|
3549
|
+
},
|
|
3550
|
+
});
|
|
3551
|
+
}
|
|
3552
|
+
|
|
3553
|
+
#setMicCursor(color: { r: number; g: number; b: number }): void {
|
|
3554
|
+
this.editor.cursorOverride = `\x1b[38;2;${color.r};${color.g};${color.b}m${theme.icon.mic}\x1b[0m`;
|
|
3555
|
+
// Theme symbols can be wide (for example, 🎤), so measure the rendered override.
|
|
3556
|
+
this.editor.cursorOverrideWidth = visibleWidth(this.editor.cursorOverride);
|
|
3557
|
+
}
|
|
3558
|
+
|
|
3559
|
+
#updateMicIcon(): void {
|
|
3560
|
+
const { r, g, b } = hsvToRgb({ h: this.#voiceHue, s: 0.9, v: 1.0 });
|
|
3561
|
+
this.#setMicCursor({ r, g, b });
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
#startMicAnimation(): void {
|
|
3565
|
+
if (this.#voiceAnimationInterval) return;
|
|
3566
|
+
this.#voiceHue = 0;
|
|
3567
|
+
this.#updateMicIcon();
|
|
3568
|
+
this.#voiceAnimationInterval = setInterval(() => {
|
|
3569
|
+
this.#voiceHue = (this.#voiceHue + 8) % 360;
|
|
3570
|
+
this.#updateMicIcon();
|
|
3571
|
+
// Component-scoped: the hue sweep only recolors the editor's cursor
|
|
3572
|
+
// glyph, so the transcript subtree is reused per animation frame.
|
|
3573
|
+
this.ui.requestComponentRender(this.editor);
|
|
3574
|
+
}, 60);
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
#stopMicAnimation(): void {
|
|
3578
|
+
if (this.#voiceAnimationInterval) {
|
|
3579
|
+
clearInterval(this.#voiceAnimationInterval);
|
|
3580
|
+
this.#voiceAnimationInterval = undefined;
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
|
|
3584
|
+
#cleanupMicAnimation(): void {
|
|
3585
|
+
if (this.#voiceAnimationInterval) {
|
|
3586
|
+
clearInterval(this.#voiceAnimationInterval);
|
|
3587
|
+
this.#voiceAnimationInterval = undefined;
|
|
3588
|
+
}
|
|
3589
|
+
this.editor.cursorOverride = undefined;
|
|
3590
|
+
this.editor.cursorOverrideWidth = undefined;
|
|
3591
|
+
if (this.#voicePreviousShowHardwareCursor !== null) {
|
|
3592
|
+
this.ui.setShowHardwareCursor(this.#voicePreviousShowHardwareCursor);
|
|
3593
|
+
this.#voicePreviousShowHardwareCursor = null;
|
|
3594
|
+
}
|
|
3595
|
+
if (this.#voicePreviousUseTerminalCursor !== null) {
|
|
3596
|
+
this.editor.setUseTerminalCursor(this.#voicePreviousUseTerminalCursor);
|
|
3597
|
+
this.#voicePreviousUseTerminalCursor = null;
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
async showDebugSelector(): Promise<void> {
|
|
3602
|
+
await this.#selectorController.showDebugSelector();
|
|
3603
|
+
}
|
|
3604
|
+
|
|
3605
|
+
showAgentHub(options?: { requireContent?: boolean }): void {
|
|
3606
|
+
this.#selectorController.showAgentHub(this.#observerRegistry, options);
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
resetObserverRegistry(): void {
|
|
3610
|
+
this.#observerRegistry.resetSessions();
|
|
3611
|
+
this.#observerRegistry.setMainSession(this.sessionManager.getSessionFile() ?? undefined);
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
handleBashCommand(command: string, excludeFromContext?: boolean): Promise<void> {
|
|
3615
|
+
return this.#commandController.handleBashCommand(command, excludeFromContext);
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
handlePythonCommand(code: string, excludeFromContext?: boolean): Promise<void> {
|
|
3619
|
+
return this.#commandController.handlePythonCommand(code, excludeFromContext);
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
async handleMCPCommand(text: string): Promise<void> {
|
|
3623
|
+
const controller = new MCPCommandController(this);
|
|
3624
|
+
await controller.handle(text);
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
async handleSSHCommand(text: string): Promise<void> {
|
|
3628
|
+
const controller = new SSHCommandController(this);
|
|
3629
|
+
await controller.handle(text);
|
|
3630
|
+
}
|
|
3631
|
+
|
|
3632
|
+
handleCompactCommand(
|
|
3633
|
+
customInstructions?: string,
|
|
3634
|
+
mode?: CompactMode,
|
|
3635
|
+
beforeFlush?: (outcome: CompactionOutcome) => void | Promise<void>,
|
|
3636
|
+
): Promise<CompactionOutcome> {
|
|
3637
|
+
return this.#commandController.handleCompactCommand(customInstructions, mode, beforeFlush);
|
|
3638
|
+
}
|
|
3639
|
+
|
|
3640
|
+
handleHandoffCommand(customInstructions?: string): Promise<void> {
|
|
3641
|
+
return this.#commandController.handleHandoffCommand(customInstructions);
|
|
3642
|
+
}
|
|
3643
|
+
|
|
3644
|
+
handleShakeCommand(mode: ShakeMode): Promise<void> {
|
|
3645
|
+
return this.#commandController.handleShakeCommand(mode);
|
|
3646
|
+
}
|
|
3647
|
+
|
|
3648
|
+
executeCompaction(
|
|
3649
|
+
customInstructionsOrOptions?: string | CompactOptions,
|
|
3650
|
+
isAuto?: boolean,
|
|
3651
|
+
): Promise<CompactionOutcome> {
|
|
3652
|
+
return this.#commandController.executeCompaction(customInstructionsOrOptions, isAuto);
|
|
3653
|
+
}
|
|
3654
|
+
|
|
3655
|
+
openInBrowser(urlOrPath: string): void {
|
|
3656
|
+
this.#commandController.openInBrowser(urlOrPath);
|
|
3657
|
+
}
|
|
3658
|
+
|
|
3659
|
+
// Selector handling
|
|
3660
|
+
showSettingsSelector(): void {
|
|
3661
|
+
this.#selectorController.showSettingsSelector();
|
|
3662
|
+
}
|
|
3663
|
+
|
|
3664
|
+
showHistorySearch(): void {
|
|
3665
|
+
this.#selectorController.showHistorySearch();
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
showExtensionsDashboard(): void {
|
|
3669
|
+
void this.#selectorController.showExtensionsDashboard();
|
|
3670
|
+
}
|
|
3671
|
+
|
|
3672
|
+
showAgentsDashboard(): void {
|
|
3673
|
+
void this.#selectorController.showAgentsDashboard();
|
|
3674
|
+
}
|
|
3675
|
+
|
|
3676
|
+
showModelSelector(options?: { temporaryOnly?: boolean }): void {
|
|
3677
|
+
this.#selectorController.showModelSelector(options);
|
|
3678
|
+
}
|
|
3679
|
+
|
|
3680
|
+
showPluginSelector(mode?: "install" | "uninstall"): void {
|
|
3681
|
+
void this.#selectorController.showPluginSelector(mode);
|
|
3682
|
+
}
|
|
3683
|
+
|
|
3684
|
+
showUserMessageSelector(): void {
|
|
3685
|
+
this.#selectorController.showUserMessageSelector();
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3688
|
+
showCopySelector(): void {
|
|
3689
|
+
this.#selectorController.showCopySelector();
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
showTreeSelector(): void {
|
|
3693
|
+
this.#selectorController.showTreeSelector();
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
showSessionSelector(): void {
|
|
3697
|
+
this.#selectorController.showSessionSelector();
|
|
3698
|
+
}
|
|
3699
|
+
|
|
3700
|
+
handleResumeSession(sessionPath: string): Promise<void> {
|
|
3701
|
+
this.#btwController.dispose();
|
|
3702
|
+
this.#omfgController.dispose();
|
|
3703
|
+
this.resetObserverRegistry();
|
|
3704
|
+
return this.#selectorController.handleResumeSession(sessionPath);
|
|
3705
|
+
}
|
|
3706
|
+
|
|
3707
|
+
handleSessionDeleteCommand(): Promise<void> {
|
|
3708
|
+
return this.#selectorController.handleSessionDeleteCommand();
|
|
3709
|
+
}
|
|
3710
|
+
|
|
3711
|
+
showOAuthSelector(mode: "login" | "logout", providerId?: string): Promise<void> {
|
|
3712
|
+
return this.#selectorController.showOAuthSelector(mode, providerId);
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
showResetUsageSelector(): Promise<void> {
|
|
3716
|
+
return this.#selectorController.showResetUsageSelector();
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
showProviderSetup(): Promise<void> {
|
|
3720
|
+
return runProviderSetupWizard(this);
|
|
3721
|
+
}
|
|
3722
|
+
|
|
3723
|
+
showHookConfirm(title: string, message: string): Promise<boolean> {
|
|
3724
|
+
return this.#extensionUiController.showHookConfirm(title, message);
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3727
|
+
// Input handling
|
|
3728
|
+
handleCtrlC(): void {
|
|
3729
|
+
this.#inputController.handleCtrlC();
|
|
3730
|
+
}
|
|
3731
|
+
|
|
3732
|
+
handleCtrlD(): void {
|
|
3733
|
+
this.#inputController.handleCtrlD();
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3736
|
+
handleCtrlZ(): void {
|
|
3737
|
+
this.#inputController.handleCtrlZ();
|
|
3738
|
+
}
|
|
3739
|
+
|
|
3740
|
+
handleDequeue(): void {
|
|
3741
|
+
this.#inputController.handleDequeue();
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
handleImagePaste(): Promise<boolean> {
|
|
3745
|
+
return this.#inputController.handleImagePaste();
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3748
|
+
handleBtwCommand(question: string): Promise<void> {
|
|
3749
|
+
return this.#btwController.start(question);
|
|
3750
|
+
}
|
|
3751
|
+
|
|
3752
|
+
handleTanCommand(work: string): Promise<void> {
|
|
3753
|
+
return this.#tanCommandController.start(work);
|
|
3754
|
+
}
|
|
3755
|
+
|
|
3756
|
+
hasActiveBtw(): boolean {
|
|
3757
|
+
return this.#btwController.hasActiveRequest();
|
|
3758
|
+
}
|
|
3759
|
+
|
|
3760
|
+
handleBtwEscape(): boolean {
|
|
3761
|
+
return this.#btwController.handleEscape();
|
|
3762
|
+
}
|
|
3763
|
+
|
|
3764
|
+
canBranchBtw(): boolean {
|
|
3765
|
+
return this.#btwController.canBranch();
|
|
3766
|
+
}
|
|
3767
|
+
|
|
3768
|
+
handleBtwBranchKey(): Promise<boolean> {
|
|
3769
|
+
return this.#btwController.handleBranch();
|
|
3770
|
+
}
|
|
3771
|
+
|
|
3772
|
+
async handleBtwBranch(question: string, assistantMessage: AssistantMessage): Promise<void> {
|
|
3773
|
+
try {
|
|
3774
|
+
const result = await this.session.branchFromBtw(question, assistantMessage);
|
|
3775
|
+
if (result.cancelled) {
|
|
3776
|
+
this.showStatus("/btw branch cancelled", { dim: true });
|
|
3777
|
+
return;
|
|
3778
|
+
}
|
|
3779
|
+
this.#btwController.dispose();
|
|
3780
|
+
this.#omfgController.dispose();
|
|
3781
|
+
this.chatContainer.clear();
|
|
3782
|
+
this.renderInitialMessages({ clearTerminalHistory: true });
|
|
3783
|
+
this.updateEditorBorderColor();
|
|
3784
|
+
this.showStatus(
|
|
3785
|
+
result.sessionFile ? `Branched /btw to ${path.basename(result.sessionFile)}` : "Branched /btw",
|
|
3786
|
+
);
|
|
3787
|
+
} catch (error) {
|
|
3788
|
+
this.showError(`Cannot branch /btw: ${error instanceof Error ? error.message : String(error)}`);
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
handleOmfgCommand(complaint: string): Promise<void> {
|
|
3793
|
+
return this.#omfgController.start(complaint);
|
|
3794
|
+
}
|
|
3795
|
+
|
|
3796
|
+
hasActiveOmfg(): boolean {
|
|
3797
|
+
return this.#omfgController.hasActiveRequest();
|
|
3798
|
+
}
|
|
3799
|
+
|
|
3800
|
+
handleOmfgEscape(): boolean {
|
|
3801
|
+
return this.#omfgController.handleEscape();
|
|
3802
|
+
}
|
|
3803
|
+
|
|
3804
|
+
cycleThinkingLevel(): void {
|
|
3805
|
+
this.#inputController.cycleThinkingLevel();
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3808
|
+
cycleRoleModel(direction?: "forward" | "backward"): Promise<void> {
|
|
3809
|
+
return this.#inputController.cycleRoleModel(direction);
|
|
3810
|
+
}
|
|
3811
|
+
|
|
3812
|
+
toggleToolOutputExpansion(): void {
|
|
3813
|
+
this.#inputController.toggleToolOutputExpansion();
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3816
|
+
setToolsExpanded(expanded: boolean): void {
|
|
3817
|
+
this.#inputController.setToolsExpanded(expanded);
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
toggleThinkingBlockVisibility(): void {
|
|
3821
|
+
this.#inputController.toggleThinkingBlockVisibility();
|
|
3822
|
+
}
|
|
3823
|
+
|
|
3824
|
+
toggleTodoExpansion(): void {
|
|
3825
|
+
this.todoExpanded = !this.todoExpanded;
|
|
3826
|
+
this.#renderTodoList();
|
|
3827
|
+
this.ui.requestRender();
|
|
3828
|
+
}
|
|
3829
|
+
|
|
3830
|
+
setTodos(todos: TodoItem[] | TodoPhase[]): void {
|
|
3831
|
+
if (todos.length > 0 && "tasks" in todos[0]) {
|
|
3832
|
+
this.todoPhases = todos as TodoPhase[];
|
|
3833
|
+
} else {
|
|
3834
|
+
this.todoPhases = [
|
|
3835
|
+
{
|
|
3836
|
+
name: "Todos",
|
|
3837
|
+
tasks: todos as TodoItem[],
|
|
3838
|
+
},
|
|
3839
|
+
];
|
|
3840
|
+
}
|
|
3841
|
+
this.#syncTodoAutoClearTimer();
|
|
3842
|
+
this.#renderTodoList();
|
|
3843
|
+
this.ui.requestRender();
|
|
3844
|
+
}
|
|
3845
|
+
|
|
3846
|
+
async reloadTodos(): Promise<void> {
|
|
3847
|
+
await this.#loadTodoList();
|
|
3848
|
+
this.ui.requestRender();
|
|
3849
|
+
}
|
|
3850
|
+
|
|
3851
|
+
openExternalEditor(): void {
|
|
3852
|
+
this.#inputController.openExternalEditor();
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3855
|
+
registerExtensionShortcuts(): void {
|
|
3856
|
+
this.#inputController.registerExtensionShortcuts();
|
|
3857
|
+
}
|
|
3858
|
+
|
|
3859
|
+
// Hook UI methods
|
|
3860
|
+
initHooksAndCustomTools(): Promise<void> {
|
|
3861
|
+
return this.#extensionUiController.initHooksAndCustomTools();
|
|
3862
|
+
}
|
|
3863
|
+
|
|
3864
|
+
emitCustomToolSessionEvent(
|
|
3865
|
+
reason: "start" | "switch" | "branch" | "tree" | "shutdown",
|
|
3866
|
+
previousSessionFile?: string,
|
|
3867
|
+
): Promise<void> {
|
|
3868
|
+
return this.#extensionUiController.emitCustomToolSessionEvent(reason, previousSessionFile);
|
|
3869
|
+
}
|
|
3870
|
+
|
|
3871
|
+
setHookWidget(key: string, content: ExtensionWidgetContent, options?: ExtensionWidgetOptions): void {
|
|
3872
|
+
this.#extensionUiController.setHookWidget(key, content, options);
|
|
3873
|
+
}
|
|
3874
|
+
|
|
3875
|
+
setHookStatus(key: string, text: string | undefined): void {
|
|
3876
|
+
this.#extensionUiController.setHookStatus(key, text);
|
|
3877
|
+
}
|
|
3878
|
+
|
|
3879
|
+
showHookSelector(
|
|
3880
|
+
title: string,
|
|
3881
|
+
options: ExtensionUISelectItem[],
|
|
3882
|
+
dialogOptions?: InteractiveSelectorDialogOptions,
|
|
3883
|
+
extra?: { slider?: HookSelectorSlider },
|
|
3884
|
+
): Promise<string | undefined> {
|
|
3885
|
+
return this.#extensionUiController.showHookSelector(title, options, dialogOptions, extra);
|
|
3886
|
+
}
|
|
3887
|
+
|
|
3888
|
+
hideHookSelector(): void {
|
|
3889
|
+
this.#extensionUiController.hideHookSelector();
|
|
3890
|
+
}
|
|
3891
|
+
|
|
3892
|
+
showHookInput(title: string, placeholder?: string): Promise<string | undefined> {
|
|
3893
|
+
return this.#extensionUiController.showHookInput(title, placeholder);
|
|
3894
|
+
}
|
|
3895
|
+
|
|
3896
|
+
hideHookInput(): void {
|
|
3897
|
+
this.#extensionUiController.hideHookInput();
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
showHookEditor(
|
|
3901
|
+
title: string,
|
|
3902
|
+
prefill?: string,
|
|
3903
|
+
dialogOptions?: ExtensionUIDialogOptions,
|
|
3904
|
+
editorOptions?: { promptStyle?: boolean },
|
|
3905
|
+
): Promise<string | undefined> {
|
|
3906
|
+
return this.#extensionUiController.showHookEditor(title, prefill, dialogOptions, editorOptions);
|
|
3907
|
+
}
|
|
3908
|
+
|
|
3909
|
+
hideHookEditor(): void {
|
|
3910
|
+
this.#extensionUiController.hideHookEditor();
|
|
3911
|
+
}
|
|
3912
|
+
|
|
3913
|
+
showHookNotify(message: string, type?: "info" | "warning" | "error"): void {
|
|
3914
|
+
this.#extensionUiController.showHookNotify(message, type);
|
|
3915
|
+
}
|
|
3916
|
+
|
|
3917
|
+
showHookCustom<T>(
|
|
3918
|
+
factory: (
|
|
3919
|
+
tui: TUI,
|
|
3920
|
+
theme: Theme,
|
|
3921
|
+
keybindings: KeybindingsManager,
|
|
3922
|
+
done: (result: T) => void,
|
|
3923
|
+
) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,
|
|
3924
|
+
options?: { overlay?: boolean },
|
|
3925
|
+
): Promise<T> {
|
|
3926
|
+
return this.#extensionUiController.showHookCustom(factory, options);
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3929
|
+
showExtensionError(extensionPath: string, error: string): void {
|
|
3930
|
+
this.#extensionUiController.showExtensionError(extensionPath, error);
|
|
3931
|
+
}
|
|
3932
|
+
|
|
3933
|
+
showToolError(toolName: string, error: string): void {
|
|
3934
|
+
this.#extensionUiController.showToolError(toolName, error);
|
|
3935
|
+
}
|
|
3936
|
+
|
|
3937
|
+
#subscribeToAgent(): void {
|
|
3938
|
+
this.#eventController.subscribeToAgent();
|
|
3939
|
+
}
|
|
3940
|
+
}
|