@kr78/pi-coding-agent 17.2.10
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 +14861 -0
- package/README.md +35 -0
- package/dist/CHANGELOG-chtdxh1z.md +14861 -0
- package/dist/cli.js +20483 -0
- package/dist/template-c2hyaytt.js +1653 -0
- package/dist/template-f8wx9vfn.css +1355 -0
- package/dist/template-qat058wr.html +55 -0
- package/dist/tool-views.generated-jdfmzwmn.js +35 -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 +78 -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 +169 -0
- package/package.json +587 -0
- package/scripts/bench-guard.ts +71 -0
- package/scripts/bench-title-models.ts +332 -0
- package/scripts/build-binary.ts +117 -0
- package/scripts/bundle-dist.ts +123 -0
- package/scripts/compile-binary.ts +69 -0
- package/scripts/embed-mupdf-wasm.ts +67 -0
- package/scripts/format-prompts.ts +68 -0
- package/scripts/generate-aria-snapshot.ts +134 -0
- package/scripts/generate-docs-index.ts +58 -0
- package/scripts/generate-share-viewer.ts +34 -0
- package/scripts/legacy-pi-virtual-module.ts +205 -0
- package/scripts/measure-prompt-tokens.ts +63 -0
- package/scripts/omp +51 -0
- package/scripts/omp.ts +19 -0
- package/scripts/security-compare.ts +40 -0
- package/src/advisor/advise-tool.ts +234 -0
- package/src/advisor/config.ts +341 -0
- package/src/advisor/emission-guard.ts +172 -0
- package/src/advisor/index.ts +6 -0
- package/src/advisor/runtime.ts +1412 -0
- package/src/advisor/transcript-recorder.ts +215 -0
- package/src/advisor/watchdog.ts +135 -0
- package/src/async/index.ts +1 -0
- package/src/async/job-manager.ts +847 -0
- package/src/auto-thinking/classifier.ts +220 -0
- package/src/autolearn/controller.ts +152 -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 +331 -0
- package/src/autoresearch/helpers.ts +218 -0
- package/src/autoresearch/index.ts +541 -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 +268 -0
- package/src/autoresearch/tools/log-experiment.ts +520 -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 +467 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +115 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule-buckets.ts +66 -0
- package/src/capability/rule.ts +298 -0
- package/src/capability/settings.ts +34 -0
- package/src/capability/skill.ts +69 -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 +187 -0
- package/src/cleanse/agent.ts +226 -0
- package/src/cleanse/balance.ts +79 -0
- package/src/cleanse/checkers.ts +996 -0
- package/src/cleanse/index.ts +190 -0
- package/src/cleanse/loop.ts +51 -0
- package/src/cleanse/parsers.ts +726 -0
- package/src/cleanse/progress.ts +50 -0
- package/src/cleanse/prompts/assignment.md +47 -0
- package/src/cleanse/types.ts +72 -0
- package/src/cli/agents-cli.ts +138 -0
- package/src/cli/args.ts +368 -0
- package/src/cli/auth-broker-cli.ts +940 -0
- package/src/cli/auth-gateway-cli.ts +674 -0
- package/src/cli/bench-cli.ts +990 -0
- package/src/cli/browser-relay-cli.ts +119 -0
- package/src/cli/classify-install-target.ts +76 -0
- package/src/cli/claude-trace-cli.ts +795 -0
- package/src/cli/command-help.ts +107 -0
- package/src/cli/commands/init-xdg.ts +27 -0
- package/src/cli/completion-gen.ts +550 -0
- package/src/cli/config-cli.ts +459 -0
- package/src/cli/dry-balance-cli.ts +864 -0
- package/src/cli/extension-flags.ts +48 -0
- package/src/cli/file-processor.ts +132 -0
- package/src/cli/flag-tables.ts +367 -0
- package/src/cli/gallery-cli.ts +272 -0
- package/src/cli/gallery-fixtures/agentic.ts +420 -0
- package/src/cli/gallery-fixtures/codeintel.ts +187 -0
- package/src/cli/gallery-fixtures/edit.ts +254 -0
- package/src/cli/gallery-fixtures/fs.ts +245 -0
- package/src/cli/gallery-fixtures/index.ts +40 -0
- package/src/cli/gallery-fixtures/interaction.ts +46 -0
- package/src/cli/gallery-fixtures/memory.ts +81 -0
- package/src/cli/gallery-fixtures/misc.ts +177 -0
- package/src/cli/gallery-fixtures/search.ts +135 -0
- package/src/cli/gallery-fixtures/shell.ts +241 -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/gc-cli.ts +1566 -0
- package/src/cli/grep-cli.ts +161 -0
- package/src/cli/grievances-cli.ts +256 -0
- package/src/cli/help-extra.ts +89 -0
- package/src/cli/initial-message.ts +58 -0
- package/src/cli/models-cli.ts +385 -0
- package/src/cli/plugin-cli.ts +996 -0
- package/src/cli/profile-alias.ts +369 -0
- package/src/cli/profile-bootstrap.ts +233 -0
- package/src/cli/read-cli.ts +99 -0
- package/src/cli/session-picker.ts +110 -0
- package/src/cli/setup-cli.ts +312 -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/thinking-levels.ts +7 -0
- package/src/cli/tiny-models-cli.ts +153 -0
- package/src/cli/ttsr-cli.ts +1013 -0
- package/src/cli/update-cli.ts +1184 -0
- package/src/cli/usage-cli.ts +1084 -0
- package/src/cli/usage-error.ts +7 -0
- package/src/cli/web-search-cli.ts +144 -0
- package/src/cli/worktree-cli.ts +311 -0
- package/src/cli-commands.ts +308 -0
- package/src/cli.ts +428 -0
- package/src/collab/crypto.ts +63 -0
- package/src/collab/display-name.ts +13 -0
- package/src/collab/guest.ts +764 -0
- package/src/collab/host.ts +692 -0
- package/src/collab/protocol.ts +296 -0
- package/src/collab/relay-client.ts +282 -0
- package/src/collab/replication-shrink.ts +111 -0
- package/src/commands/acp.ts +35 -0
- package/src/commands/agents.ts +58 -0
- package/src/commands/auth-broker.ts +100 -0
- package/src/commands/auth-gateway.ts +70 -0
- package/src/commands/bench.ts +64 -0
- package/src/commands/browser-relay.ts +53 -0
- package/src/commands/cleanse.ts +45 -0
- package/src/commands/commit.ts +47 -0
- package/src/commands/complete.ts +67 -0
- package/src/commands/completions.ts +61 -0
- package/src/commands/config.ts +52 -0
- package/src/commands/dry-balance.ts +43 -0
- package/src/commands/gallery.ts +61 -0
- package/src/commands/gc.ts +47 -0
- package/src/commands/grep.ts +49 -0
- package/src/commands/grievances.ts +52 -0
- package/src/commands/install.ts +107 -0
- package/src/commands/join.ts +40 -0
- package/src/commands/launch-help.ts +116 -0
- package/src/commands/launch.ts +34 -0
- package/src/commands/models.ts +61 -0
- package/src/commands/plugin.ts +79 -0
- package/src/commands/read.ts +39 -0
- package/src/commands/say.ts +146 -0
- package/src/commands/setup.ts +68 -0
- package/src/commands/share.ts +71 -0
- package/src/commands/shell.ts +30 -0
- package/src/commands/ssh.ts +61 -0
- package/src/commands/stats.ts +30 -0
- package/src/commands/tiny-models.ts +36 -0
- package/src/commands/token.ts +164 -0
- package/src/commands/ttsr.ts +125 -0
- package/src/commands/update.ts +34 -0
- package/src/commands/usage.ts +55 -0
- package/src/commands/web-search.ts +43 -0
- package/src/commands/worktree.ts +63 -0
- package/src/commit/agentic/agent.ts +322 -0
- package/src/commit/agentic/fallback.ts +96 -0
- package/src/commit/agentic/index.ts +383 -0
- package/src/commit/agentic/lock-files.ts +107 -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 +148 -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 +62 -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 +95 -0
- package/src/commit/pipeline.ts +244 -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 +81 -0
- package/src/config/append-only-context-mode.ts +76 -0
- package/src/config/config-file.ts +347 -0
- package/src/config/inline-tool-descriptors-mode.ts +26 -0
- package/src/config/keybindings.ts +703 -0
- package/src/config/mcp-schema.json +252 -0
- package/src/config/model-discovery.ts +1077 -0
- package/src/config/model-registry.ts +2822 -0
- package/src/config/model-resolver.ts +2115 -0
- package/src/config/model-roles.ts +113 -0
- package/src/config/models-config-schema-bundle.ts +315 -0
- package/src/config/models-config-schema.ts +14 -0
- package/src/config/models-config.ts +130 -0
- package/src/config/prompt-templates.ts +205 -0
- package/src/config/provider-globals.ts +25 -0
- package/src/config/resolve-config-value.ts +95 -0
- package/src/config/service-tier.ts +146 -0
- package/src/config/settings-schema.ts +5887 -0
- package/src/config/settings.ts +2394 -0
- package/src/config.ts +242 -0
- package/src/cursor-bridge-tools.ts +81 -0
- package/src/cursor.ts +960 -0
- package/src/dap/client.ts +1043 -0
- package/src/dap/config.ts +480 -0
- package/src/dap/defaults.json +212 -0
- package/src/dap/index.ts +4 -0
- package/src/dap/session.ts +1841 -0
- package/src/dap/types.ts +611 -0
- package/src/debug/index.ts +584 -0
- package/src/debug/log-formatting.ts +58 -0
- package/src/debug/log-viewer.ts +966 -0
- package/src/debug/profiler.ts +168 -0
- package/src/debug/protocol-probe.ts +267 -0
- package/src/debug/raw-sse-buffer.ts +421 -0
- package/src/debug/raw-sse.ts +312 -0
- package/src/debug/remote-debugger.ts +151 -0
- package/src/debug/report-bundle.ts +411 -0
- package/src/debug/system-info.ts +111 -0
- package/src/debug/terminal-info.ts +124 -0
- package/src/discovery/agent-plugin-format.ts +551 -0
- package/src/discovery/agent-plugins.ts +341 -0
- package/src/discovery/agents-md.ts +67 -0
- package/src/discovery/agents.ts +300 -0
- package/src/discovery/at-imports.ts +273 -0
- package/src/discovery/builtin-defaults.ts +39 -0
- package/src/discovery/builtin-rules/go-add-cleanup.md +33 -0
- package/src/discovery/builtin-rules/go-bench-loop.md +36 -0
- package/src/discovery/builtin-rules/go-exp-promoted.md +40 -0
- package/src/discovery/builtin-rules/go-ioutil.md +37 -0
- package/src/discovery/builtin-rules/go-join-hostport.md +30 -0
- package/src/discovery/builtin-rules/go-new-expr.md +44 -0
- package/src/discovery/builtin-rules/go-rand-v2.md +41 -0
- package/src/discovery/builtin-rules/go-range-int.md +45 -0
- package/src/discovery/builtin-rules/index.ts +74 -0
- package/src/discovery/builtin-rules/rs-box-leak.md +49 -0
- package/src/discovery/builtin-rules/rs-future-prelude.md +24 -0
- package/src/discovery/builtin-rules/rs-lazylock.md +52 -0
- package/src/discovery/builtin-rules/rs-match-ergonomics.md +68 -0
- package/src/discovery/builtin-rules/rs-parking-lot.md +45 -0
- package/src/discovery/builtin-rules/rs-result-type.md +20 -0
- package/src/discovery/builtin-rules/ts-bare-catch.md +39 -0
- package/src/discovery/builtin-rules/ts-import-type.md +43 -0
- package/src/discovery/builtin-rules/ts-no-any.md +66 -0
- package/src/discovery/builtin-rules/ts-no-deprecated-leftovers.md +45 -0
- package/src/discovery/builtin-rules/ts-no-dynamic-import.md +40 -0
- package/src/discovery/builtin-rules/ts-no-inline-cast-access.md +56 -0
- package/src/discovery/builtin-rules/ts-no-local-is-record.md +48 -0
- package/src/discovery/builtin-rules/ts-no-return-type.md +45 -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 +66 -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 +945 -0
- package/src/discovery/claude-plugins.ts +640 -0
- package/src/discovery/claude.ts +591 -0
- package/src/discovery/cline.ts +83 -0
- package/src/discovery/codex.ts +553 -0
- package/src/discovery/contained-path.ts +78 -0
- package/src/discovery/cursor.ts +223 -0
- package/src/discovery/gemini.ts +386 -0
- package/src/discovery/github.ts +337 -0
- package/src/discovery/helpers.ts +1183 -0
- package/src/discovery/index.ts +82 -0
- package/src/discovery/mcp-json.ts +182 -0
- package/src/discovery/omp-extension-roots.ts +272 -0
- package/src/discovery/omp-plugins.ts +409 -0
- package/src/discovery/opencode.ts +441 -0
- package/src/discovery/plugin-dir-roots.ts +28 -0
- package/src/discovery/ssh.ts +153 -0
- package/src/discovery/substitute-plugin-root.ts +77 -0
- package/src/discovery/vscode.ts +106 -0
- package/src/discovery/windsurf.ts +149 -0
- package/src/edit/apply-patch/index.ts +87 -0
- package/src/edit/apply-patch/parser.ts +174 -0
- package/src/edit/diff.ts +1008 -0
- package/src/edit/edit-clipboard.ts +23 -0
- package/src/edit/file-snapshot-store.ts +148 -0
- package/src/edit/hashline/block-resolver.ts +33 -0
- package/src/edit/hashline/diff.ts +402 -0
- package/src/edit/hashline/execute.ts +313 -0
- package/src/edit/hashline/filesystem.ts +247 -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 +12 -0
- package/src/edit/index.ts +699 -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 +1958 -0
- package/src/edit/modes/replace.ts +1191 -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 +998 -0
- package/src/edit/snapshot-details.ts +77 -0
- package/src/edit/streaming.ts +710 -0
- package/src/eval/agent-bridge.ts +224 -0
- package/src/eval/backend-helpers.ts +48 -0
- package/src/eval/backend.ts +71 -0
- package/src/eval/bridge-timeout.ts +65 -0
- package/src/eval/budget-bridge.ts +48 -0
- package/src/eval/completion-bridge.ts +212 -0
- package/src/eval/concurrency-bridge.ts +34 -0
- package/src/eval/executor-base.ts +562 -0
- package/src/eval/idle-timeout.ts +91 -0
- package/src/eval/index.ts +6 -0
- package/src/eval/jl/executor.ts +551 -0
- package/src/eval/jl/index.ts +54 -0
- package/src/eval/jl/kernel.ts +236 -0
- package/src/eval/jl/prelude.jl +736 -0
- package/src/eval/jl/prelude.ts +3 -0
- package/src/eval/jl/runner.jl +666 -0
- package/src/eval/jl/runtime.ts +118 -0
- package/src/eval/js/context-manager.ts +872 -0
- package/src/eval/js/executor.ts +178 -0
- package/src/eval/js/index.ts +41 -0
- package/src/eval/js/process-entry.ts +31 -0
- package/src/eval/js/shared/helpers.ts +170 -0
- package/src/eval/js/shared/indirect-eval.ts +30 -0
- package/src/eval/js/shared/local-module-loader.ts +364 -0
- package/src/eval/js/shared/prelude.ts +2 -0
- package/src/eval/js/shared/prelude.txt +294 -0
- package/src/eval/js/shared/rewrite-imports.ts +550 -0
- package/src/eval/js/shared/runtime.ts +590 -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 +380 -0
- package/src/eval/js/worker-entry.ts +37 -0
- package/src/eval/js/worker-protocol.ts +47 -0
- package/src/eval/kernel-base.ts +569 -0
- package/src/eval/py/display.ts +71 -0
- package/src/eval/py/executor.ts +643 -0
- package/src/eval/py/index.ts +57 -0
- package/src/eval/py/kernel.ts +235 -0
- package/src/eval/py/prelude.py +673 -0
- package/src/eval/py/prelude.ts +3 -0
- package/src/eval/py/runner.py +1425 -0
- package/src/eval/py/runtime.ts +276 -0
- package/src/eval/py/spawn-options.ts +134 -0
- package/src/eval/py/tool-bridge.ts +201 -0
- package/src/eval/rb/executor.ts +511 -0
- package/src/eval/rb/index.ts +54 -0
- package/src/eval/rb/kernel.ts +231 -0
- package/src/eval/rb/prelude.rb +551 -0
- package/src/eval/rb/prelude.ts +3 -0
- package/src/eval/rb/runner.rb +581 -0
- package/src/eval/rb/runtime.ts +132 -0
- package/src/eval/runtime-env.ts +104 -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 +627 -0
- package/src/exec/direnv.ts +145 -0
- package/src/exec/exec.ts +53 -0
- package/src/exec/non-interactive-env.ts +118 -0
- package/src/export/custom-share.ts +65 -0
- package/src/export/html/args.ts +20 -0
- package/src/export/html/index.ts +320 -0
- package/src/export/html/share-loader.js +102 -0
- package/src/export/html/template.css +1355 -0
- package/src/export/html/template.html +55 -0
- package/src/export/html/template.js +1653 -0
- package/src/export/html/tool-views.generated.js +35 -0
- package/src/export/html/vendor/highlight.min.js +1213 -0
- package/src/export/html/vendor/marked.min.js +6 -0
- package/src/export/html/web-palette.ts +126 -0
- package/src/export/share.ts +686 -0
- package/src/export/ttsr.ts +590 -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 +301 -0
- package/src/extensibility/custom-tools/types.ts +287 -0
- package/src/extensibility/custom-tools/wrapper.ts +50 -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/load-errors.ts +13 -0
- package/src/extensibility/extensions/loader.ts +663 -0
- package/src/extensibility/extensions/managed-timers.ts +83 -0
- package/src/extensibility/extensions/model-api.ts +39 -0
- package/src/extensibility/extensions/runner.ts +1396 -0
- package/src/extensibility/extensions/types.ts +1603 -0
- package/src/extensibility/extensions/wrapper.ts +395 -0
- package/src/extensibility/hooks/index.ts +6 -0
- package/src/extensibility/hooks/loader.ts +243 -0
- package/src/extensibility/hooks/runner.ts +425 -0
- package/src/extensibility/hooks/tool-wrapper.ts +124 -0
- package/src/extensibility/hooks/types.ts +612 -0
- package/src/extensibility/legacy-pi-ai-shim.ts +161 -0
- package/src/extensibility/legacy-pi-coding-agent-shim.ts +1460 -0
- package/src/extensibility/legacy-pi-tui-shim.ts +43 -0
- package/src/extensibility/legacy-typebox.ts +101 -0
- package/src/extensibility/plugins/bun-git-cache.ts +91 -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 +201 -0
- package/src/extensibility/plugins/legacy-pi-compat.ts +2643 -0
- package/src/extensibility/plugins/legacy-pi-virtual-modules.d.ts +4 -0
- package/src/extensibility/plugins/loader.ts +535 -0
- package/src/extensibility/plugins/manager.ts +1142 -0
- package/src/extensibility/plugins/marketplace/cache.ts +136 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +316 -0
- package/src/extensibility/plugins/marketplace/index.ts +6 -0
- package/src/extensibility/plugins/marketplace/manager.ts +927 -0
- package/src/extensibility/plugins/marketplace/registry.ts +192 -0
- package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
- package/src/extensibility/plugins/marketplace/types.ts +192 -0
- package/src/extensibility/plugins/marketplace-auto-update.ts +49 -0
- package/src/extensibility/plugins/parser.ts +107 -0
- package/src/extensibility/plugins/runtime-config.ts +9 -0
- package/src/extensibility/plugins/types.ts +194 -0
- package/src/extensibility/session-handler-types.ts +21 -0
- package/src/extensibility/shared-events.ts +401 -0
- package/src/extensibility/skills.ts +531 -0
- package/src/extensibility/slash-commands.ts +131 -0
- package/src/extensibility/tool-event-input.ts +80 -0
- package/src/extensibility/tool-proxy.ts +28 -0
- package/src/extensibility/utils.ts +192 -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 +680 -0
- package/src/hindsight/config.ts +193 -0
- package/src/hindsight/content.ts +266 -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 +530 -0
- package/src/hindsight/transcript.ts +71 -0
- package/src/index.ts +66 -0
- package/src/internal-urls/agent-protocol.ts +180 -0
- package/src/internal-urls/artifact-protocol.ts +151 -0
- package/src/internal-urls/docs-index.ts +102 -0
- package/src/internal-urls/filesystem-resource.ts +34 -0
- package/src/internal-urls/history-protocol.ts +198 -0
- package/src/internal-urls/index.ts +28 -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 +471 -0
- package/src/internal-urls/mcp-protocol.ts +168 -0
- package/src/internal-urls/memory-protocol.ts +380 -0
- package/src/internal-urls/omp-protocol.ts +94 -0
- package/src/internal-urls/parse.ts +103 -0
- package/src/internal-urls/registry-helpers.ts +132 -0
- package/src/internal-urls/router.ts +153 -0
- package/src/internal-urls/rule-protocol.ts +45 -0
- package/src/internal-urls/security-protocol.ts +261 -0
- package/src/internal-urls/skill-protocol.ts +131 -0
- package/src/internal-urls/ssh-protocol.ts +368 -0
- package/src/internal-urls/types.ts +196 -0
- package/src/internal-urls/vault-protocol.ts +940 -0
- package/src/internal-urls/xd-protocol.ts +46 -0
- package/src/irc/bus.ts +380 -0
- package/src/jsonrpc/message-framing.ts +142 -0
- package/src/launch/broker.ts +1368 -0
- package/src/launch/client.ts +521 -0
- package/src/launch/ensure.ts +73 -0
- package/src/launch/paths.ts +14 -0
- package/src/launch/presence.ts +82 -0
- package/src/launch/protocol.ts +448 -0
- package/src/launch/spawn-options.ts +17 -0
- package/src/launch/terminal-output-worker-client.ts +53 -0
- package/src/launch/terminal-output-worker-protocol.ts +11 -0
- package/src/launch/terminal-output-worker.ts +23 -0
- package/src/launch/terminal-output.ts +46 -0
- package/src/lib/xai-http.ts +150 -0
- package/src/live/attestation.ts +91 -0
- package/src/live/controller.ts +517 -0
- package/src/live/prompts/agent-final-message.md +3 -0
- package/src/live/prompts/live-instructions.md +23 -0
- package/src/live/protocol.ts +233 -0
- package/src/live/transport.ts +422 -0
- package/src/live/visualizer.ts +221 -0
- package/src/live/voices.ts +18 -0
- package/src/lsp/client.ts +1465 -0
- package/src/lsp/clients/biome-client.ts +263 -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 +549 -0
- package/src/lsp/defaults.json +499 -0
- package/src/lsp/deferred-diagnostics.ts +66 -0
- package/src/lsp/diagnostics-ledger.ts +51 -0
- package/src/lsp/edits.ts +288 -0
- package/src/lsp/format-options.ts +119 -0
- package/src/lsp/index.ts +2821 -0
- package/src/lsp/lspmux.ts +233 -0
- package/src/lsp/mux/daemon.ts +348 -0
- package/src/lsp/mux/protocol.ts +96 -0
- package/src/lsp/mux/server.ts +797 -0
- package/src/lsp/render.ts +668 -0
- package/src/lsp/startup-events.ts +13 -0
- package/src/lsp/types.ts +479 -0
- package/src/lsp/utils.ts +747 -0
- package/src/main.ts +1799 -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/pdf/columns.ts +103 -0
- package/src/markit/converters/pdf/extract.ts +598 -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 +511 -0
- package/src/mcp/config-writer.ts +377 -0
- package/src/mcp/config.ts +385 -0
- package/src/mcp/index.ts +29 -0
- package/src/mcp/json-rpc.ts +122 -0
- package/src/mcp/loader.ts +125 -0
- package/src/mcp/manager.ts +1524 -0
- package/src/mcp/oauth-credentials.ts +104 -0
- package/src/mcp/oauth-discovery.ts +587 -0
- package/src/mcp/oauth-flow.ts +830 -0
- package/src/mcp/render.ts +214 -0
- package/src/mcp/request-id.ts +24 -0
- package/src/mcp/smithery-auth.ts +108 -0
- package/src/mcp/smithery-connect.ts +154 -0
- package/src/mcp/smithery-registry.ts +500 -0
- package/src/mcp/startup-events.ts +116 -0
- package/src/mcp/timeout.ts +59 -0
- package/src/mcp/tool-bridge.ts +691 -0
- package/src/mcp/tool-cache.ts +117 -0
- package/src/mcp/transports/header-policy.ts +95 -0
- package/src/mcp/transports/http.ts +508 -0
- package/src/mcp/transports/index.ts +7 -0
- package/src/mcp/transports/sse.ts +372 -0
- package/src/mcp/transports/stdio.ts +905 -0
- package/src/mcp/types.ts +467 -0
- package/src/memories/index.ts +1434 -0
- package/src/memories/storage.ts +578 -0
- package/src/memory-backend/index.ts +19 -0
- package/src/memory-backend/local-backend.ts +47 -0
- package/src/memory-backend/messages.ts +19 -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/tool-names.ts +2 -0
- package/src/memory-backend/types.ts +166 -0
- package/src/mnemopi/backend.ts +629 -0
- package/src/mnemopi/config.ts +267 -0
- package/src/mnemopi/embed-client.ts +293 -0
- package/src/mnemopi/embed-protocol.ts +35 -0
- package/src/mnemopi/embed-worker.ts +114 -0
- package/src/mnemopi/index.ts +3 -0
- package/src/mnemopi/state.ts +940 -0
- package/src/modes/acp/acp-agent.ts +2595 -0
- package/src/modes/acp/acp-client-bridge.ts +154 -0
- package/src/modes/acp/acp-event-mapper.ts +1084 -0
- package/src/modes/acp/acp-mode.ts +48 -0
- package/src/modes/acp/index.ts +2 -0
- package/src/modes/acp/terminal-auth.ts +37 -0
- package/src/modes/components/advisor-config.ts +635 -0
- package/src/modes/components/advisor-message.ts +109 -0
- package/src/modes/components/agent-dashboard.ts +1252 -0
- package/src/modes/components/agent-hub-projection.ts +248 -0
- package/src/modes/components/agent-hub-renderer.ts +194 -0
- package/src/modes/components/agent-hub.ts +1126 -0
- package/src/modes/components/agent-transcript-viewer.ts +647 -0
- package/src/modes/components/ask-dialog.ts +1017 -0
- package/src/modes/components/assistant-message.ts +978 -0
- package/src/modes/components/background-tan-message.ts +36 -0
- package/src/modes/components/bash-execution.ts +233 -0
- package/src/modes/components/bordered-loader.ts +41 -0
- package/src/modes/components/btw-panel.ts +161 -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 +518 -0
- package/src/modes/components/codex-reset-fireworks.ts +369 -0
- package/src/modes/components/collab-prompt-message.ts +32 -0
- package/src/modes/components/compaction-summary-message.ts +221 -0
- package/src/modes/components/copy-selector.ts +218 -0
- package/src/modes/components/countdown-timer.ts +75 -0
- package/src/modes/components/custom-editor.ts +1036 -0
- package/src/modes/components/custom-message.ts +70 -0
- package/src/modes/components/diff.ts +254 -0
- package/src/modes/components/dynamic-border.ts +37 -0
- package/src/modes/components/error-banner.ts +33 -0
- package/src/modes/components/eval-execution.ts +169 -0
- package/src/modes/components/execution-shared.ts +101 -0
- package/src/modes/components/extensions/extension-dashboard.ts +492 -0
- package/src/modes/components/extensions/extension-list.ts +507 -0
- package/src/modes/components/extensions/index.ts +9 -0
- package/src/modes/components/extensions/inspector-panel.ts +326 -0
- package/src/modes/components/extensions/state-manager.ts +648 -0
- package/src/modes/components/extensions/types.ts +186 -0
- package/src/modes/components/footer.ts +274 -0
- package/src/modes/components/history-search.ts +268 -0
- package/src/modes/components/hook-editor.ts +213 -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 +691 -0
- package/src/modes/components/index.ts +42 -0
- package/src/modes/components/keybinding-hints.ts +56 -0
- package/src/modes/components/late-diagnostics-message.ts +60 -0
- package/src/modes/components/login-dialog.ts +197 -0
- package/src/modes/components/logout-account-selector.ts +130 -0
- package/src/modes/components/mcp-add-wizard.ts +1413 -0
- package/src/modes/components/message-frame.ts +98 -0
- package/src/modes/components/model-browser.ts +888 -0
- package/src/modes/components/model-hub.ts +2014 -0
- package/src/modes/components/model-picker.ts +237 -0
- package/src/modes/components/move-overlay.ts +293 -0
- package/src/modes/components/oauth-selector.ts +474 -0
- package/src/modes/components/omfg-panel.ts +141 -0
- package/src/modes/components/overlay-box.ts +109 -0
- package/src/modes/components/pause-screen.ts +208 -0
- package/src/modes/components/plan-review-overlay.ts +1226 -0
- package/src/modes/components/plan-toc.ts +138 -0
- package/src/modes/components/plugin-selector.ts +100 -0
- package/src/modes/components/plugin-settings.ts +745 -0
- package/src/modes/components/queue-mode-selector.ts +61 -0
- package/src/modes/components/read-tool-group.ts +856 -0
- package/src/modes/components/reset-usage-selector.ts +161 -0
- package/src/modes/components/segment-track.ts +89 -0
- package/src/modes/components/select-list-mouse-routing.ts +35 -0
- package/src/modes/components/selector-helpers.ts +129 -0
- package/src/modes/components/session-account-selector.ts +62 -0
- package/src/modes/components/session-selector.ts +1035 -0
- package/src/modes/components/settings-defs.ts +267 -0
- package/src/modes/components/settings-selector.ts +1445 -0
- package/src/modes/components/show-images-selector.ts +50 -0
- package/src/modes/components/skill-message.ts +110 -0
- package/src/modes/components/snapcompact-shape-preview-doc.md +14 -0
- package/src/modes/components/snapcompact-shape-preview.ts +192 -0
- package/src/modes/components/status-line/component.ts +1843 -0
- package/src/modes/components/status-line/context-thresholds.ts +86 -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 +710 -0
- package/src/modes/components/status-line/separators.ts +55 -0
- package/src/modes/components/status-line/types.ts +159 -0
- package/src/modes/components/stripped-tool-calls-placeholder.ts +35 -0
- package/src/modes/components/theme-selector.ts +68 -0
- package/src/modes/components/thinking-selector.ts +57 -0
- package/src/modes/components/tiny-title-download-progress.ts +90 -0
- package/src/modes/components/tips.txt +26 -0
- package/src/modes/components/todo-reminder.ts +43 -0
- package/src/modes/components/tool-execution.ts +1467 -0
- package/src/modes/components/transcript-container.ts +527 -0
- package/src/modes/components/tree-selector.ts +1006 -0
- package/src/modes/components/ttsr-notification.ts +123 -0
- package/src/modes/components/usage-row.ts +52 -0
- package/src/modes/components/user-message-selector.ts +227 -0
- package/src/modes/components/user-message.ts +167 -0
- package/src/modes/components/visual-truncate.ts +63 -0
- package/src/modes/components/welcome.ts +578 -0
- package/src/modes/controllers/btw-controller.ts +246 -0
- package/src/modes/controllers/command-controller-shared.ts +109 -0
- package/src/modes/controllers/command-controller.ts +2024 -0
- package/src/modes/controllers/event-controller.ts +2173 -0
- package/src/modes/controllers/extension-ui-controller.ts +1243 -0
- package/src/modes/controllers/input-controller.ts +2037 -0
- package/src/modes/controllers/live-command-controller.ts +261 -0
- package/src/modes/controllers/mcp-command-controller.ts +2552 -0
- package/src/modes/controllers/omfg-controller.ts +287 -0
- package/src/modes/controllers/omfg-rule.ts +647 -0
- package/src/modes/controllers/selector-controller.ts +2058 -0
- package/src/modes/controllers/session-focus-controller.ts +117 -0
- package/src/modes/controllers/ssh-command-controller.ts +385 -0
- package/src/modes/controllers/streaming-reveal.ts +399 -0
- package/src/modes/controllers/tan-command-controller.ts +243 -0
- package/src/modes/controllers/todo-command-controller.ts +487 -0
- package/src/modes/controllers/tool-args-reveal.ts +591 -0
- package/src/modes/data/emojis.json +1 -0
- package/src/modes/emoji-autocomplete.ts +285 -0
- package/src/modes/github-ref-autocomplete.ts +75 -0
- package/src/modes/gradient-highlight.ts +99 -0
- package/src/modes/image-references.ts +137 -0
- package/src/modes/index.ts +10 -0
- package/src/modes/interactive-mode.ts +5055 -0
- package/src/modes/internal-url-autocomplete.ts +158 -0
- package/src/modes/loop-limit.ts +192 -0
- package/src/modes/magic-keyword-boundary.ts +23 -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 +43 -0
- package/src/modes/print-mode.ts +282 -0
- package/src/modes/prompt-action-autocomplete.ts +322 -0
- package/src/modes/queue-input.ts +132 -0
- package/src/modes/rpc/host-tools.ts +204 -0
- package/src/modes/rpc/host-uris.ts +241 -0
- package/src/modes/rpc/rpc-client.ts +1213 -0
- package/src/modes/rpc/rpc-frame.ts +316 -0
- package/src/modes/rpc/rpc-input.ts +38 -0
- package/src/modes/rpc/rpc-messages.ts +127 -0
- package/src/modes/rpc/rpc-mode.ts +1519 -0
- package/src/modes/rpc/rpc-subagents.ts +265 -0
- package/src/modes/rpc/rpc-types.ts +544 -0
- package/src/modes/running-subagent-badge.ts +13 -0
- package/src/modes/runtime-init.ts +144 -0
- package/src/modes/session-observer-registry.ts +223 -0
- package/src/modes/session-teardown.ts +82 -0
- package/src/modes/setup-version.ts +11 -0
- package/src/modes/setup-wizard/index.ts +103 -0
- package/src/modes/setup-wizard/lazy.ts +16 -0
- package/src/modes/setup-wizard/scenes/glyph.ts +103 -0
- package/src/modes/setup-wizard/scenes/model.ts +132 -0
- package/src/modes/setup-wizard/scenes/outro.ts +35 -0
- package/src/modes/setup-wizard/scenes/providers.ts +105 -0
- package/src/modes/setup-wizard/scenes/sign-in.ts +312 -0
- package/src/modes/setup-wizard/scenes/splash.ts +201 -0
- package/src/modes/setup-wizard/scenes/theme.ts +330 -0
- package/src/modes/setup-wizard/scenes/types.ts +65 -0
- package/src/modes/setup-wizard/scenes/web-search.ts +153 -0
- package/src/modes/setup-wizard/startup-splash.ts +107 -0
- package/src/modes/setup-wizard/wizard-overlay.ts +335 -0
- package/src/modes/shared.ts +49 -0
- package/src/modes/skill-command.ts +91 -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 +143 -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 +143 -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 +305 -0
- package/src/modes/theme/theme-schema.json +463 -0
- package/src/modes/theme/theme.ts +3171 -0
- package/src/modes/turn-budget.ts +31 -0
- package/src/modes/types.ts +494 -0
- package/src/modes/ultrathink.ts +42 -0
- package/src/modes/utils/context-usage.ts +518 -0
- package/src/modes/utils/copy-targets.ts +378 -0
- package/src/modes/utils/hotkeys-markdown.ts +65 -0
- package/src/modes/utils/interactive-context-helpers.ts +31 -0
- package/src/modes/utils/keybinding-matchers.ts +86 -0
- package/src/modes/utils/tools-markdown.ts +31 -0
- package/src/modes/utils/transcript-render-helpers.ts +253 -0
- package/src/modes/utils/ui-helpers.ts +976 -0
- package/src/modes/warp-events.ts +232 -0
- package/src/modes/workflow.ts +55 -0
- package/src/plan-mode/approved-plan.ts +194 -0
- package/src/plan-mode/model-transition.ts +51 -0
- package/src/plan-mode/plan-files.ts +40 -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 +60 -0
- package/src/prompts/advisor/active-repo-watchdog.md +6 -0
- package/src/prompts/advisor/advise-tool.md +3 -0
- package/src/prompts/advisor/context-files.md +8 -0
- package/src/prompts/advisor/system.md +98 -0
- package/src/prompts/agents/designer.md +74 -0
- package/src/prompts/agents/frontmatter.md +12 -0
- package/src/prompts/agents/init.md +33 -0
- package/src/prompts/agents/librarian.md +119 -0
- package/src/prompts/agents/reviewer.md +139 -0
- package/src/prompts/agents/scout.md +58 -0
- package/src/prompts/agents/security-reviewer.md +75 -0
- package/src/prompts/agents/task.md +17 -0
- package/src/prompts/bench/cache-prefix-chunk.md +1 -0
- package/src/prompts/bench/cache-prefix.md +3 -0
- package/src/prompts/bench/cache-suffix.md +1 -0
- package/src/prompts/bench.md +6 -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/goal-mode-context.md +4 -0
- package/src/prompts/goals/goal-todo-context.md +12 -0
- package/src/prompts/goals/guided-goal-interview.md +43 -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 +21 -0
- package/src/prompts/review-headless-request.md +16 -0
- package/src/prompts/review-request.md +68 -0
- package/src/prompts/security/scan-coordinator.md +7 -0
- package/src/prompts/security/scan-request.md +21 -0
- package/src/prompts/security/validate-request.md +8 -0
- package/src/prompts/session/launch-completion.md +1 -0
- package/src/prompts/skills/autoload.md +8 -0
- package/src/prompts/skills/user-invocation.md +11 -0
- package/src/prompts/steering/parent-irc.md +5 -0
- package/src/prompts/steering/user-interjection.md +6 -0
- package/src/prompts/system/active-repo-context.md +4 -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 +14 -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-autocontinue.md +5 -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/computer-safety.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/gemini-tool-call-reminder.md +9 -0
- package/src/prompts/system/interrupted-thinking.md +7 -0
- package/src/prompts/system/irc-autoreply.md +6 -0
- package/src/prompts/system/irc-incoming.md +9 -0
- package/src/prompts/system/manual-continue.md +7 -0
- package/src/prompts/system/mcp-xdev-guidance.md +11 -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/mid-run-todo-nudge.md +3 -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 +125 -0
- package/src/prompts/system/plan-mode-approved.md +22 -0
- package/src/prompts/system/plan-mode-compact-instructions.md +17 -0
- package/src/prompts/system/plan-mode-reference.md +10 -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/plan-yolo-handoff.md +5 -0
- package/src/prompts/system/prewalk-checklist.md +7 -0
- package/src/prompts/system/prewalk-continue.md +1 -0
- package/src/prompts/system/prewalk-plan.md +13 -0
- package/src/prompts/system/project-prompt.md +61 -0
- package/src/prompts/system/recap-user.md +9 -0
- package/src/prompts/system/resolve-device-reminder.md +3 -0
- package/src/prompts/system/rewind-report.md +6 -0
- package/src/prompts/system/side-channel-no-tools.md +3 -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/speech-rewrite.md +15 -0
- package/src/prompts/system/subagent-async-pending.md +6 -0
- package/src/prompts/system/subagent-system-prompt.md +73 -0
- package/src/prompts/system/subagent-user-prompt.md +3 -0
- package/src/prompts/system/subagent-yield-reminder.md +23 -0
- package/src/prompts/system/system-prompt.md +263 -0
- package/src/prompts/system/tan-context-switch.md +17 -0
- package/src/prompts/system/task-label.md +23 -0
- package/src/prompts/system/thinking-loop-redirect.md +10 -0
- package/src/prompts/system/title-marker-instruction.md +1 -0
- package/src/prompts/system/title-system.md +16 -0
- package/src/prompts/system/tool-call-loop-redirect.md +8 -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/vibe-mode-active.md +26 -0
- package/src/prompts/system/web-search.md +25 -0
- package/src/prompts/system/workflow-notice.md +112 -0
- package/src/prompts/system/xdev-mount-notice.md +20 -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 +11 -0
- package/src/prompts/tools/ast-grep.md +19 -0
- package/src/prompts/tools/async-result.md +8 -0
- package/src/prompts/tools/bash.md +23 -0
- package/src/prompts/tools/browser.md +29 -0
- package/src/prompts/tools/checkpoint.md +15 -0
- package/src/prompts/tools/computer.md +26 -0
- package/src/prompts/tools/debug.md +3 -0
- package/src/prompts/tools/eval.md +45 -0
- package/src/prompts/tools/github.md +22 -0
- package/src/prompts/tools/glob.md +16 -0
- package/src/prompts/tools/goal.md +11 -0
- package/src/prompts/tools/grep.md +13 -0
- package/src/prompts/tools/hub.md +34 -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/learn.md +7 -0
- package/src/prompts/tools/lsp-late-diagnostic.md +8 -0
- package/src/prompts/tools/lsp.md +19 -0
- package/src/prompts/tools/manage-skill.md +9 -0
- package/src/prompts/tools/memory-edit.md +12 -0
- package/src/prompts/tools/patch.md +57 -0
- package/src/prompts/tools/read.md +27 -0
- package/src/prompts/tools/recall.md +7 -0
- package/src/prompts/tools/reflect.md +5 -0
- package/src/prompts/tools/replace.md +30 -0
- package/src/prompts/tools/retain.md +6 -0
- package/src/prompts/tools/rewind.md +14 -0
- package/src/prompts/tools/security-publish.md +1 -0
- package/src/prompts/tools/security-scan.md +1 -0
- package/src/prompts/tools/task-async-contract.md +1 -0
- package/src/prompts/tools/task-summary.md +20 -0
- package/src/prompts/tools/task.md +83 -0
- package/src/prompts/tools/todo.md +42 -0
- package/src/prompts/tools/vibe-kill.md +3 -0
- package/src/prompts/tools/vibe-list.md +3 -0
- package/src/prompts/tools/vibe-send.md +9 -0
- package/src/prompts/tools/vibe-spawn.md +10 -0
- package/src/prompts/tools/vibe-turn-result.md +19 -0
- package/src/prompts/tools/vibe-wait.md +8 -0
- package/src/prompts/tools/web-search.md +8 -0
- package/src/prompts/tools/write.md +14 -0
- package/src/registry/agent-lifecycle.ts +505 -0
- package/src/registry/agent-registry.ts +287 -0
- package/src/registry/persisted-agents.ts +423 -0
- package/src/sdk.ts +3820 -0
- package/src/secrets/index.ts +375 -0
- package/src/secrets/obfuscator.ts +2629 -0
- package/src/secrets/regex.ts +21 -0
- package/src/security/auth.ts +98 -0
- package/src/security/cloud.ts +686 -0
- package/src/security/comparison.ts +255 -0
- package/src/security/contracts/ids.ts +111 -0
- package/src/security/contracts/index.ts +4 -0
- package/src/security/contracts/schemas.ts +219 -0
- package/src/security/contracts/types.ts +254 -0
- package/src/security/contracts/validation.ts +69 -0
- package/src/security/coordinator.ts +708 -0
- package/src/security/importers/codex-security.ts +387 -0
- package/src/security/importers/index.ts +2 -0
- package/src/security/importers/sarif.ts +357 -0
- package/src/security/index.ts +13 -0
- package/src/security/preflight.ts +405 -0
- package/src/security/provenance.ts +106 -0
- package/src/security/publication.ts +326 -0
- package/src/security/remediation.ts +93 -0
- package/src/security/resource-output.ts +50 -0
- package/src/security/sarif.ts +78 -0
- package/src/security/store.ts +430 -0
- package/src/session/acp-permission-gate.ts +165 -0
- package/src/session/agent-session-events.ts +67 -0
- package/src/session/agent-session-types.ts +407 -0
- package/src/session/agent-session.ts +9000 -0
- package/src/session/agent-storage.ts +807 -0
- package/src/session/artifacts.ts +154 -0
- package/src/session/async-job-delivery.ts +82 -0
- package/src/session/auth-broker-config.ts +92 -0
- package/src/session/auth-storage.ts +25 -0
- package/src/session/bash-runner.ts +326 -0
- package/src/session/blob-store.ts +295 -0
- package/src/session/checkpoint-entries.ts +81 -0
- package/src/session/claude-session-store.ts +426 -0
- package/src/session/client-bridge.ts +85 -0
- package/src/session/codex-auto-reset.ts +673 -0
- package/src/session/codex-session-store.ts +673 -0
- package/src/session/compact-modes.ts +105 -0
- package/src/session/credential-pin.ts +93 -0
- package/src/session/eval-runner.ts +219 -0
- package/src/session/exit-diagnostics.ts +310 -0
- package/src/session/foreign-session-import.ts +52 -0
- package/src/session/foreign-session-jsonl.ts +29 -0
- package/src/session/foreign-session-store.ts +26 -0
- package/src/session/history-storage.ts +329 -0
- package/src/session/indexed-session-storage.ts +553 -0
- package/src/session/irc-bridge.ts +203 -0
- package/src/session/launch-completion.ts +37 -0
- package/src/session/messages.ts +1304 -0
- package/src/session/model-controls.ts +757 -0
- package/src/session/prewalk.ts +279 -0
- package/src/session/provider-image-budget.ts +86 -0
- package/src/session/queued-messages.ts +99 -0
- package/src/session/redis-session-storage.ts +257 -0
- package/src/session/retry-fallback-chains.ts +455 -0
- package/src/session/role-models.ts +85 -0
- package/src/session/session-advisors.ts +1896 -0
- package/src/session/session-context.ts +584 -0
- package/src/session/session-dump-format.ts +216 -0
- package/src/session/session-entries.ts +306 -0
- package/src/session/session-handoff.ts +325 -0
- package/src/session/session-history-format.ts +459 -0
- package/src/session/session-listing.ts +715 -0
- package/src/session/session-loader.ts +362 -0
- package/src/session/session-maintenance.ts +3115 -0
- package/src/session/session-manager.ts +2747 -0
- package/src/session/session-memory.ts +222 -0
- package/src/session/session-metadata.ts +53 -0
- package/src/session/session-migrations.ts +78 -0
- package/src/session/session-paths.ts +280 -0
- package/src/session/session-persistence.ts +293 -0
- package/src/session/session-provider-boundary.ts +306 -0
- package/src/session/session-stats.ts +349 -0
- package/src/session/session-storage.ts +774 -0
- package/src/session/session-title-slot.ts +141 -0
- package/src/session/session-tools.ts +1385 -0
- package/src/session/session-workspace.ts +53 -0
- package/src/session/settings-stream-fn.ts +79 -0
- package/src/session/shake-types.ts +43 -0
- package/src/session/snapcompact-inline.ts +545 -0
- package/src/session/snapcompact-savings-journal.ts +113 -0
- package/src/session/sql-session-storage.ts +374 -0
- package/src/session/stream-guards.ts +417 -0
- package/src/session/streaming-output.ts +1459 -0
- package/src/session/todo-tracker.ts +380 -0
- package/src/session/tool-choice-queue.ts +305 -0
- package/src/session/ttsr-coordinator.ts +496 -0
- package/src/session/turn-persistence.ts +142 -0
- package/src/session/turn-recovery.ts +2005 -0
- package/src/session/unexpected-stop-classifier.ts +141 -0
- package/src/session/yield-queue.ts +288 -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 +3149 -0
- package/src/slash-commands/helpers/active-oauth-account.ts +80 -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 +108 -0
- package/src/slash-commands/helpers/marketplace-manager.ts +25 -0
- package/src/slash-commands/helpers/mcp.ts +533 -0
- package/src/slash-commands/helpers/parse.ts +85 -0
- package/src/slash-commands/helpers/reset-usage.ts +68 -0
- package/src/slash-commands/helpers/security.ts +451 -0
- package/src/slash-commands/helpers/session-pin.ts +44 -0
- package/src/slash-commands/helpers/ssh.ts +196 -0
- package/src/slash-commands/helpers/stats-dashboard.ts +86 -0
- package/src/slash-commands/helpers/todo.ts +285 -0
- package/src/slash-commands/helpers/usage-report.ts +198 -0
- package/src/slash-commands/marketplace-install-parser.ts +99 -0
- package/src/slash-commands/types.ts +139 -0
- package/src/ssh/config-writer.ts +183 -0
- package/src/ssh/connection-manager.ts +667 -0
- package/src/ssh/file-transfer.ts +214 -0
- package/src/ssh/sshfs-mount.ts +163 -0
- package/src/ssh/utils.ts +51 -0
- package/src/startup-splash.ts +19 -0
- package/src/stt/asr-client.ts +401 -0
- package/src/stt/asr-protocol.ts +65 -0
- package/src/stt/asr-worker.ts +603 -0
- package/src/stt/downloader.ts +142 -0
- package/src/stt/endpointer.ts +259 -0
- package/src/stt/index.ts +6 -0
- package/src/stt/models.ts +150 -0
- package/src/stt/sherpa-runtime.ts +71 -0
- package/src/stt/stt-controller.ts +320 -0
- package/src/stt/submit-trigger.ts +74 -0
- package/src/subprocess/worker-client.ts +463 -0
- package/src/subprocess/worker-runtime.ts +494 -0
- package/src/system-prompt.ts +921 -0
- package/src/task/agents.ts +170 -0
- package/src/task/commands.ts +132 -0
- package/src/task/discovery.ts +145 -0
- package/src/task/executor.ts +3431 -0
- package/src/task/index.ts +1515 -0
- package/src/task/isolation-ownership.ts +106 -0
- package/src/task/isolation-runner.ts +444 -0
- package/src/task/label.ts +40 -0
- package/src/task/name-generator.ts +1577 -0
- package/src/task/omp-command.ts +26 -0
- package/src/task/output-manager.ts +115 -0
- package/src/task/parallel.ts +221 -0
- package/src/task/persisted-revive.ts +173 -0
- package/src/task/prewalk.ts +6 -0
- package/src/task/prompt-policy.ts +8 -0
- package/src/task/provider-concurrency.ts +100 -0
- package/src/task/read-only-policy.ts +27 -0
- package/src/task/render.ts +1830 -0
- package/src/task/renderer.ts +14 -0
- package/src/task/repair-args.ts +118 -0
- package/src/task/spawn-policy.ts +72 -0
- package/src/task/structured-subagent.ts +676 -0
- package/src/task/subprocess-tool-registry.ts +88 -0
- package/src/task/types.ts +555 -0
- package/src/task/worktree.ts +967 -0
- package/src/task/yield-assembly.ts +198 -0
- package/src/telemetry-export.ts +504 -0
- package/src/thinking.ts +377 -0
- package/src/tiny/device.ts +111 -0
- package/src/tiny/dtype.ts +101 -0
- package/src/tiny/message-preproc.ts +155 -0
- package/src/tiny/models.ts +268 -0
- package/src/tiny/text.ts +290 -0
- package/src/tiny/title-client.ts +460 -0
- package/src/tiny/title-protocol.ts +56 -0
- package/src/tiny/worker.ts +354 -0
- package/src/tools/acp-bridge.ts +125 -0
- package/src/tools/approval.ts +245 -0
- package/src/tools/ask.ts +1459 -0
- package/src/tools/ast-edit.ts +718 -0
- package/src/tools/ast-grep.ts +526 -0
- package/src/tools/auto-generated-guard.ts +335 -0
- package/src/tools/bash-interactive.ts +435 -0
- package/src/tools/bash-interceptor.ts +148 -0
- package/src/tools/bash-pty-selection.ts +14 -0
- package/src/tools/bash-skill-urls.ts +350 -0
- package/src/tools/bash.ts +1826 -0
- package/src/tools/browser/aria/aria-snapshot.bundle.txt +7 -0
- package/src/tools/browser/aria/aria-snapshot.ts +131 -0
- package/src/tools/browser/attach.ts +219 -0
- package/src/tools/browser/cmux/cmux-tab.ts +1531 -0
- package/src/tools/browser/cmux/rpc.ts +200 -0
- package/src/tools/browser/cmux/socket-client.ts +445 -0
- package/src/tools/browser/launch.ts +939 -0
- package/src/tools/browser/readable.ts +112 -0
- package/src/tools/browser/registry.ts +447 -0
- package/src/tools/browser/relay/bridge.ts +945 -0
- package/src/tools/browser/relay/daemon.ts +117 -0
- package/src/tools/browser/relay/extension-assets/background.js.txt +242 -0
- package/src/tools/browser/relay/extension-assets/manifest.json.txt +14 -0
- package/src/tools/browser/relay/extension-assets/options.html.txt +53 -0
- package/src/tools/browser/relay/extension-assets/options.js.txt +23 -0
- package/src/tools/browser/relay/kind.ts +41 -0
- package/src/tools/browser/relay/protocol.ts +54 -0
- package/src/tools/browser/relay/server.ts +141 -0
- package/src/tools/browser/render.ts +229 -0
- package/src/tools/browser/run-output.ts +76 -0
- package/src/tools/browser/shared-daemon.ts +139 -0
- package/src/tools/browser/tab-protocol.ts +123 -0
- package/src/tools/browser/tab-supervisor.ts +1077 -0
- package/src/tools/browser/tab-worker-entry.ts +29 -0
- package/src/tools/browser/tab-worker.ts +1982 -0
- package/src/tools/browser.ts +487 -0
- package/src/tools/builtin-names.ts +67 -0
- package/src/tools/checkpoint.ts +137 -0
- package/src/tools/computer/exposure.ts +14 -0
- package/src/tools/computer/protocol.ts +69 -0
- package/src/tools/computer/supervisor.ts +409 -0
- package/src/tools/computer/worker-entry.ts +39 -0
- package/src/tools/computer/worker.ts +745 -0
- package/src/tools/computer-renderer.ts +147 -0
- package/src/tools/computer.ts +222 -0
- package/src/tools/conflict-detect.ts +815 -0
- package/src/tools/context.ts +49 -0
- package/src/tools/debug.ts +1121 -0
- package/src/tools/default-renderer.ts +154 -0
- package/src/tools/essential-tools.ts +46 -0
- package/src/tools/eval-backends.ts +34 -0
- package/src/tools/eval-format/index.ts +24 -0
- package/src/tools/eval-format/javascript.ts +952 -0
- package/src/tools/eval-format/julia.ts +446 -0
- package/src/tools/eval-format/python.ts +544 -0
- package/src/tools/eval-format/ruby.ts +380 -0
- package/src/tools/eval-render.ts +784 -0
- package/src/tools/eval.ts +774 -0
- package/src/tools/fetch.ts +1889 -0
- package/src/tools/file-recorder.ts +35 -0
- package/src/tools/fs-cache-invalidation.ts +28 -0
- package/src/tools/gh-cache-invalidation.ts +175 -0
- package/src/tools/gh-format.ts +12 -0
- package/src/tools/gh-renderer.ts +484 -0
- package/src/tools/gh.ts +3958 -0
- package/src/tools/github-cache.ts +663 -0
- package/src/tools/glob.ts +691 -0
- package/src/tools/grep.ts +1920 -0
- package/src/tools/grouped-file-output.ts +210 -0
- package/src/tools/hub/index.ts +579 -0
- package/src/tools/hub/jobs.ts +714 -0
- package/src/tools/hub/launch.ts +690 -0
- package/src/tools/hub/messaging.ts +735 -0
- package/src/tools/hub/types.ts +117 -0
- package/src/tools/image-gen.ts +1689 -0
- package/src/tools/image-providers.ts +50 -0
- package/src/tools/index.ts +736 -0
- package/src/tools/inspect-image-renderer.ts +133 -0
- package/src/tools/inspect-image.ts +316 -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 +102 -0
- package/src/tools/match-line-format.ts +20 -0
- package/src/tools/memory-edit.ts +61 -0
- package/src/tools/memory-recall.ts +102 -0
- package/src/tools/memory-reflect.ts +88 -0
- package/src/tools/memory-render.ts +211 -0
- package/src/tools/memory-retain.ts +89 -0
- package/src/tools/output-meta.ts +860 -0
- package/src/tools/output-schema-validator.ts +307 -0
- package/src/tools/path-utils.ts +1489 -0
- package/src/tools/plan-mode-guard.ts +155 -0
- package/src/tools/puppeteer/00_stealth_tampering.txt +44 -0
- package/src/tools/puppeteer/01_stealth_activity.txt +80 -0
- package/src/tools/puppeteer/02_stealth_hairline.txt +57 -0
- package/src/tools/puppeteer/03_stealth_botd.txt +380 -0
- package/src/tools/puppeteer/04_stealth_iframe.txt +174 -0
- package/src/tools/puppeteer/05_stealth_webgl.txt +233 -0
- package/src/tools/puppeteer/06_stealth_screen.txt +260 -0
- package/src/tools/puppeteer/07_stealth_fonts.txt +99 -0
- package/src/tools/puppeteer/08_stealth_audio.txt +63 -0
- package/src/tools/puppeteer/09_stealth_locale.txt +51 -0
- package/src/tools/puppeteer/10_stealth_plugins.txt +212 -0
- package/src/tools/puppeteer/11_stealth_hardware.txt +59 -0
- package/src/tools/puppeteer/12_stealth_codecs.txt +42 -0
- package/src/tools/puppeteer/13_stealth_worker.txt +235 -0
- package/src/tools/read.ts +3762 -0
- package/src/tools/render-utils.ts +926 -0
- package/src/tools/renderers.ts +133 -0
- package/src/tools/report-tool-issue.ts +568 -0
- package/src/tools/resolve.ts +423 -0
- package/src/tools/review.ts +103 -0
- package/src/tools/run-scope.ts +417 -0
- package/src/tools/security-scan.ts +287 -0
- package/src/tools/shell-tokenize.ts +213 -0
- package/src/tools/sqlite-reader.ts +884 -0
- package/src/tools/terminal-output.ts +141 -0
- package/src/tools/todo.ts +1226 -0
- package/src/tools/tool-errors.ts +62 -0
- package/src/tools/tool-result.ts +102 -0
- package/src/tools/tool-timeouts.ts +38 -0
- package/src/tools/tts.ts +266 -0
- package/src/tools/vibe.ts +608 -0
- package/src/tools/write.ts +1646 -0
- package/src/tools/xdev.ts +560 -0
- package/src/tools/yield.ts +486 -0
- package/src/tts/downloader.ts +64 -0
- package/src/tts/index.ts +10 -0
- package/src/tts/models.ts +137 -0
- package/src/tts/runtime.ts +21 -0
- package/src/tts/speakable.ts +392 -0
- package/src/tts/speech-enhancer.ts +206 -0
- package/src/tts/streaming-player.ts +120 -0
- package/src/tts/tts-client.ts +475 -0
- package/src/tts/tts-protocol.ts +69 -0
- package/src/tts/tts-worker.ts +434 -0
- package/src/tts/vocalizer.ts +419 -0
- package/src/tts/wav.ts +58 -0
- package/src/tui/code-cell.ts +268 -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 +268 -0
- package/src/tui/status-line.ts +54 -0
- package/src/tui/tree-list.ts +172 -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/active-repo-context.ts +143 -0
- package/src/utils/block-context.ts +312 -0
- package/src/utils/changelog.ts +373 -0
- package/src/utils/clipboard.ts +361 -0
- package/src/utils/command-args.ts +74 -0
- package/src/utils/commit-message-generator.ts +148 -0
- package/src/utils/cpuprofile.ts +235 -0
- package/src/utils/edit-mode.ts +61 -0
- package/src/utils/enhanced-paste.ts +230 -0
- package/src/utils/event-bus.ts +33 -0
- package/src/utils/external-editor.ts +80 -0
- package/src/utils/fetch-timeout.ts +10 -0
- package/src/utils/file-display-mode.ts +44 -0
- package/src/utils/file-mentions.ts +293 -0
- package/src/utils/git.ts +2472 -0
- package/src/utils/image-loading.ts +236 -0
- package/src/utils/image-resize.ts +420 -0
- package/src/utils/image-vision-fallback.ts +196 -0
- package/src/utils/inspect-image-mode.ts +39 -0
- package/src/utils/ipc.ts +38 -0
- package/src/utils/jj.ts +422 -0
- package/src/utils/lang-from-path.ts +251 -0
- package/src/utils/late-cleanup.ts +17 -0
- package/src/utils/local-date.ts +7 -0
- package/src/utils/mac-file-urls.applescript +37 -0
- package/src/utils/markit-cache.ts +166 -0
- package/src/utils/markit.ts +223 -0
- package/src/utils/mupdf-wasm-embed.ts +12 -0
- package/src/utils/open.ts +126 -0
- package/src/utils/profile-tree.ts +111 -0
- package/src/utils/prompt-path.ts +3 -0
- package/src/utils/qrcode.ts +535 -0
- package/src/utils/sample-profile.ts +437 -0
- package/src/utils/session-color.ts +142 -0
- package/src/utils/shell-snapshot-fn-env.sh +63 -0
- package/src/utils/shell-snapshot.ts +326 -0
- package/src/utils/sixel.ts +69 -0
- package/src/utils/thinking-display.ts +163 -0
- package/src/utils/title-generator.ts +597 -0
- package/src/utils/token-rate.ts +72 -0
- package/src/utils/tool-choice.ts +50 -0
- package/src/utils/tools-manager.ts +411 -0
- package/src/utils/turndown.ts +82 -0
- package/src/utils/zip.ts +1106 -0
- package/src/vibe/runtime.ts +1684 -0
- package/src/vibe/state.ts +4 -0
- package/src/web/kagi.ts +305 -0
- package/src/web/parallel.ts +354 -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 +663 -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 +129 -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 +121 -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 +393 -0
- package/src/web/search/provider.ts +272 -0
- package/src/web/search/providers/anthropic.ts +406 -0
- package/src/web/search/providers/base.ts +112 -0
- package/src/web/search/providers/brave.ts +181 -0
- package/src/web/search/providers/browser-headers.ts +82 -0
- package/src/web/search/providers/browser-page.ts +125 -0
- package/src/web/search/providers/codex.ts +788 -0
- package/src/web/search/providers/duckduckgo.ts +382 -0
- package/src/web/search/providers/ecosia.ts +183 -0
- package/src/web/search/providers/exa.ts +513 -0
- package/src/web/search/providers/firecrawl.ts +213 -0
- package/src/web/search/providers/gemini.ts +634 -0
- package/src/web/search/providers/google.ts +195 -0
- package/src/web/search/providers/jina.ts +144 -0
- package/src/web/search/providers/kagi.ts +98 -0
- package/src/web/search/providers/kimi.ts +221 -0
- package/src/web/search/providers/mojeek.ts +220 -0
- package/src/web/search/providers/parallel.ts +186 -0
- package/src/web/search/providers/perplexity-auth.ts +142 -0
- package/src/web/search/providers/perplexity.ts +997 -0
- package/src/web/search/providers/public.ts +199 -0
- package/src/web/search/providers/searxng.ts +467 -0
- package/src/web/search/providers/startpage.ts +225 -0
- package/src/web/search/providers/synthetic.ts +126 -0
- package/src/web/search/providers/tavily.ts +244 -0
- package/src/web/search/providers/tinyfish.ts +166 -0
- package/src/web/search/providers/utils.ts +130 -0
- package/src/web/search/providers/xai.ts +372 -0
- package/src/web/search/providers/zai.ts +452 -0
- package/src/web/search/query.ts +850 -0
- package/src/web/search/render.ts +262 -0
- package/src/web/search/types.ts +518 -0
- package/src/web/search/utils.ts +17 -0
- package/src/workspace-tree.ts +326 -0
|
@@ -0,0 +1,2014 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fullscreen /models hub, shown on the alternate screen like /settings.
|
|
3
|
+
*
|
|
4
|
+
* Layout: a sidebar of scopes (recently used, role management, all models,
|
|
5
|
+
* one entry per provider — locked providers included, dimmed) beside a
|
|
6
|
+
* {@link ModelBrowser} body. The Roles view manages assignments directly:
|
|
7
|
+
* pick a role, pick a model, adjust thinking in an inline strip, or clear the
|
|
8
|
+
* role back to auto-selection. Locked providers forward to the /login flow.
|
|
9
|
+
* Fully mouse-navigable (hover, wheel, click). Session-only switching lives
|
|
10
|
+
* in the compact alt+p picker ({@link ./model-picker}).
|
|
11
|
+
*/
|
|
12
|
+
import { ThinkingLevel } from "@oh-my-pi/pi-agent-core";
|
|
13
|
+
import type { Model } from "@oh-my-pi/pi-ai";
|
|
14
|
+
import { getOAuthProviders } from "@oh-my-pi/pi-ai/oauth";
|
|
15
|
+
import { getSupportedEfforts } from "@oh-my-pi/pi-catalog/model-thinking";
|
|
16
|
+
import { getCatalogProviderEntry } from "@oh-my-pi/pi-catalog/provider-models";
|
|
17
|
+
import {
|
|
18
|
+
type Component,
|
|
19
|
+
extractPrintableText,
|
|
20
|
+
fuzzyFilter,
|
|
21
|
+
getKeybindings,
|
|
22
|
+
Input,
|
|
23
|
+
matchesKey,
|
|
24
|
+
routeSgrMouseInput,
|
|
25
|
+
type SgrMouseEvent,
|
|
26
|
+
type TUI,
|
|
27
|
+
truncateToWidth,
|
|
28
|
+
visibleWidth,
|
|
29
|
+
} from "@oh-my-pi/pi-tui";
|
|
30
|
+
import type { ModelRegistry } from "../../config/model-registry";
|
|
31
|
+
import { type ModelRoleLookup, type ResolvedModelRoleValue, resolveModelRoleValue } from "../../config/model-resolver";
|
|
32
|
+
import { getKnownRoleIds, getRoleInfo } from "../../config/model-roles";
|
|
33
|
+
import type { Settings } from "../../config/settings";
|
|
34
|
+
import { AUTO_THINKING, type ConfiguredThinkingLevel, getConfiguredThinkingLevelMetadata } from "../../thinking";
|
|
35
|
+
import { theme } from "../theme/theme";
|
|
36
|
+
import { matchesSelectCancel, matchesSelectDown, matchesSelectUp } from "../utils/keybinding-matchers";
|
|
37
|
+
import {
|
|
38
|
+
buildBrowserItems,
|
|
39
|
+
ModelBrowser,
|
|
40
|
+
type ModelBrowserItem,
|
|
41
|
+
type RoleAssignments,
|
|
42
|
+
resolveRoleAssignments,
|
|
43
|
+
sortModelItems,
|
|
44
|
+
thinkingLevelGlyph,
|
|
45
|
+
} from "./model-browser";
|
|
46
|
+
import { bottomBorder, dividerSplit, row, splitBodyWidth, splitRow, topBorderSplit } from "./overlay-box";
|
|
47
|
+
import { renderSegmentTrack } from "./segment-track";
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A row of the Roles view: a role, a model/wildcard chain-key header, one of a
|
|
51
|
+
* chain's fallback entries, or the trailing "+ New role…". Fallback rows under
|
|
52
|
+
* a chain-key header carry the key in `role` — `retry.fallbackChains` treats
|
|
53
|
+
* roles, `provider/model-id`, and `provider/*` keys uniformly.
|
|
54
|
+
*/
|
|
55
|
+
type RolesRow =
|
|
56
|
+
| { kind: "role"; role: string }
|
|
57
|
+
| { kind: "chainKey"; role: string }
|
|
58
|
+
| { kind: "fallback"; role: string; chainIndex: number; selector: string }
|
|
59
|
+
| { kind: "separator" }
|
|
60
|
+
| { kind: "newFallback" }
|
|
61
|
+
| { kind: "newRole" };
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* What the model browser is currently picking for: a role's model, a slot in
|
|
65
|
+
* a fallback chain (`role` may be a role name, model selector, or `provider/*`
|
|
66
|
+
* key), or the primary model a brand-new fallback chain protects.
|
|
67
|
+
*/
|
|
68
|
+
type AssignTarget =
|
|
69
|
+
| { kind: "role"; role: string }
|
|
70
|
+
| { kind: "fallback"; role: string; index: number | null }
|
|
71
|
+
| { kind: "fallbackKey" };
|
|
72
|
+
|
|
73
|
+
/** A `--models` scope entry (mirrors the session's scoped model list). */
|
|
74
|
+
export interface ScopedModelItem {
|
|
75
|
+
model: Model;
|
|
76
|
+
thinkingLevel?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type ModelRoleSelectionScope = "global" | "project";
|
|
80
|
+
|
|
81
|
+
export interface ModelHubCallbacks {
|
|
82
|
+
/** Persist a role assignment. */
|
|
83
|
+
onAssign: (
|
|
84
|
+
model: Model,
|
|
85
|
+
role: string,
|
|
86
|
+
thinkingLevel: ConfiguredThinkingLevel | undefined,
|
|
87
|
+
selector: string,
|
|
88
|
+
scope?: ModelRoleSelectionScope,
|
|
89
|
+
) => void;
|
|
90
|
+
/** Clear a configured role back to auto-selection. */
|
|
91
|
+
onUnassign: (role: string, scope?: ModelRoleSelectionScope) => void;
|
|
92
|
+
/** Persist a `retry.fallbackChains` entry — keyed by a role, `provider/model-id`, or `provider/*`; an empty chain clears the key. */
|
|
93
|
+
onFallbackChainChange?: (role: string, chain: string[]) => void;
|
|
94
|
+
/** Locked provider activation: forward to the /login flow. */
|
|
95
|
+
onLoginRequest?: (providerId: string) => void;
|
|
96
|
+
/** Persist a new quick-switch cycle order (the ctrl+p role cycle). */
|
|
97
|
+
onCycleOrderChange?: (order: string[]) => void;
|
|
98
|
+
onCancel: () => void;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface ModelHubOptions {
|
|
102
|
+
/** Preselect this provider's sidebar entry (e.g. when reopening after /login). */
|
|
103
|
+
initialProviderId?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface SidebarEntry {
|
|
107
|
+
id: string;
|
|
108
|
+
kind: "recent" | "roles" | "all" | "separator" | "provider";
|
|
109
|
+
label: string;
|
|
110
|
+
providerId?: string;
|
|
111
|
+
locked?: boolean;
|
|
112
|
+
/** Right-aligned annotation: model count, `assigned/total`, or `login`. */
|
|
113
|
+
annotation?: string;
|
|
114
|
+
oauth?: boolean;
|
|
115
|
+
catalogCount?: number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface StripChip {
|
|
119
|
+
label: string;
|
|
120
|
+
/** Pre-styled label body (without selection decoration). */
|
|
121
|
+
styled: string;
|
|
122
|
+
role?: string;
|
|
123
|
+
action: "assign" | "unassign" | "fallback" | "fallbackModel" | "fallbackProvider" | "scope" | "thinking";
|
|
124
|
+
thinkingLevel?: ConfiguredThinkingLevel;
|
|
125
|
+
scope?: ModelRoleSelectionScope;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type StripState =
|
|
129
|
+
| {
|
|
130
|
+
kind: "role" | "scope" | "thinking";
|
|
131
|
+
item: ModelBrowserItem;
|
|
132
|
+
role?: string;
|
|
133
|
+
scope?: ModelRoleSelectionScope;
|
|
134
|
+
chips: StripChip[];
|
|
135
|
+
index: number;
|
|
136
|
+
/** Where to land when a scope or thinking strip closes. */
|
|
137
|
+
returnToRoles: boolean;
|
|
138
|
+
}
|
|
139
|
+
| {
|
|
140
|
+
/** Footer text input naming a new custom role. */
|
|
141
|
+
kind: "roleName";
|
|
142
|
+
input: Input;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** Recorded chip hit-range on the footer row (columns relative to frame col 0). */
|
|
146
|
+
interface ChipRange {
|
|
147
|
+
start: number;
|
|
148
|
+
end: number;
|
|
149
|
+
index: number;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const PROVIDER_REFRESH_DEBOUNCE_MS = 120;
|
|
153
|
+
const RECENT_LIMIT = 15;
|
|
154
|
+
const SIDEBAR_MIN_WIDTH = 18;
|
|
155
|
+
const SIDEBAR_MAX_WIDTH = 26;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Providers already auto-refreshed this process. Selecting a provider fetches
|
|
159
|
+
* its live model list at most once per application lifetime (surviving hub
|
|
160
|
+
* close/reopen); F5 re-fetches on demand.
|
|
161
|
+
*/
|
|
162
|
+
const autoRefreshedProviders = new Set<string>();
|
|
163
|
+
|
|
164
|
+
/** Test hook: forget which providers were auto-refreshed this process. */
|
|
165
|
+
export function resetProviderAutoRefreshGuard(): void {
|
|
166
|
+
autoRefreshedProviders.clear();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The fullscreen model hub component. Hosted via `ui.showOverlay(..., { fullscreen: true })`;
|
|
171
|
+
* the host must call {@link ModelHubComponent.dispose} when the overlay closes.
|
|
172
|
+
*/
|
|
173
|
+
export class ModelHubComponent implements Component {
|
|
174
|
+
#tui: TUI;
|
|
175
|
+
#settings: Settings;
|
|
176
|
+
#registry: ModelRegistry;
|
|
177
|
+
#scopedModels: ReadonlyArray<ScopedModelItem>;
|
|
178
|
+
#callbacks: ModelHubCallbacks;
|
|
179
|
+
|
|
180
|
+
#browser: ModelBrowser;
|
|
181
|
+
#roles: RoleAssignments = {};
|
|
182
|
+
#availableItems: ModelBrowserItem[] = [];
|
|
183
|
+
#recentItems: ModelBrowserItem[] = [];
|
|
184
|
+
#configError: string | undefined;
|
|
185
|
+
|
|
186
|
+
#entries: SidebarEntry[] = [];
|
|
187
|
+
// Sidebar sections from the last registry sync; #composeEntries assembles
|
|
188
|
+
// #entries from these (reordered while searching).
|
|
189
|
+
#fixedEntries: SidebarEntry[] = [];
|
|
190
|
+
#unlockedProviderEntries: SidebarEntry[] = [];
|
|
191
|
+
#lockedProviderEntries: SidebarEntry[] = [];
|
|
192
|
+
/** Fuzzy match totals while searching: recent-scope hits and overall hits. */
|
|
193
|
+
#recentSearchCount = 0;
|
|
194
|
+
#searchTotal = 0;
|
|
195
|
+
#activeEntryId = "all";
|
|
196
|
+
#sidebarScroll = 0;
|
|
197
|
+
/** Snap the sidebar viewport to the active entry on the next render; wheel panning leaves it free. */
|
|
198
|
+
#sidebarFollowActive = true;
|
|
199
|
+
#sidebarHover: number | null = null;
|
|
200
|
+
/**
|
|
201
|
+
* Arrow-key ownership: `scope` (default) hops the sidebar even while the
|
|
202
|
+
* search bar holds the caret; `list` navigates rows (browser models or
|
|
203
|
+
* role rows). Tab toggles.
|
|
204
|
+
*/
|
|
205
|
+
#focus: "scope" | "list" = "scope";
|
|
206
|
+
|
|
207
|
+
#rolesRows: RolesRow[] = [];
|
|
208
|
+
#roleIndex = 0;
|
|
209
|
+
#roleHover: number | null = null;
|
|
210
|
+
|
|
211
|
+
#assigning: AssignTarget | null = null;
|
|
212
|
+
#strip: StripState | null = null;
|
|
213
|
+
/** Per-provider fuzzy match counts while a query is active; null when not searching. */
|
|
214
|
+
#searchCounts: Map<string, number> | null = null;
|
|
215
|
+
|
|
216
|
+
// Provider discovery refresh (debounced per sidebar selection, with spinner).
|
|
217
|
+
#refreshingProviders = new Set<string>();
|
|
218
|
+
#scheduledProviderRefreshes = new Map<string, Timer>();
|
|
219
|
+
#refreshSpinnerFrame = 0;
|
|
220
|
+
#refreshSpinnerInterval?: Timer;
|
|
221
|
+
|
|
222
|
+
// Frame geometry from the last render, for mouse hit-testing (the
|
|
223
|
+
// fullscreen overlay paints from screen row 0, so mouse rows map 1:1).
|
|
224
|
+
#contentRowStart = 1;
|
|
225
|
+
#contentRowCount = 0;
|
|
226
|
+
#sidebarWidthLast = SIDEBAR_MIN_WIDTH;
|
|
227
|
+
#footerRow = 0;
|
|
228
|
+
#chipRanges: ChipRange[] = [];
|
|
229
|
+
#lockedLoginLine: number | null = null;
|
|
230
|
+
#rolesRowStart = 1;
|
|
231
|
+
|
|
232
|
+
constructor(
|
|
233
|
+
tui: TUI,
|
|
234
|
+
settings: Settings,
|
|
235
|
+
registry: ModelRegistry,
|
|
236
|
+
scopedModels: ReadonlyArray<ScopedModelItem>,
|
|
237
|
+
callbacks: ModelHubCallbacks,
|
|
238
|
+
options: ModelHubOptions = {},
|
|
239
|
+
) {
|
|
240
|
+
this.#tui = tui;
|
|
241
|
+
this.#settings = settings;
|
|
242
|
+
this.#registry = registry;
|
|
243
|
+
this.#scopedModels = scopedModels;
|
|
244
|
+
this.#callbacks = callbacks;
|
|
245
|
+
|
|
246
|
+
this.#browser = new ModelBrowser(settings, {
|
|
247
|
+
emptyText: () => this.#emptyStateMessage(),
|
|
248
|
+
});
|
|
249
|
+
this.#browser.onActivate = item => this.#activateItem(item);
|
|
250
|
+
this.#browser.onCancel = () => this.#callbacks.onCancel();
|
|
251
|
+
this.#browser.onQueryChange = query => this.#onQueryChanged(query);
|
|
252
|
+
|
|
253
|
+
// Hydrate synchronously from the current registry snapshot so the first
|
|
254
|
+
// Enter after opening acts on cached models instead of being dropped
|
|
255
|
+
// while the offline refresh promise is still pending.
|
|
256
|
+
this.#syncFromRegistryState();
|
|
257
|
+
|
|
258
|
+
const initialProvider = options.initialProviderId;
|
|
259
|
+
if (initialProvider && this.#entries.some(entry => entry.providerId === initialProvider)) {
|
|
260
|
+
this.#setActiveEntry(`provider:${initialProvider}`);
|
|
261
|
+
} else {
|
|
262
|
+
this.#setActiveEntry("all");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Reconcile with cached discovery state in the background. A --models
|
|
266
|
+
// scope is registry-independent, so the offline reload would only repeat
|
|
267
|
+
// the synchronous hydration above.
|
|
268
|
+
if (this.#scopedModels.length === 0) {
|
|
269
|
+
this.#registry
|
|
270
|
+
.refresh("offline")
|
|
271
|
+
.then(() => this.#syncFromRegistryState())
|
|
272
|
+
.catch(error => {
|
|
273
|
+
this.#configError = error instanceof Error ? error.message : String(error);
|
|
274
|
+
})
|
|
275
|
+
.finally(() => this.#tui.requestRender());
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Cancel pending provider refresh timers and the spinner. Host calls this on overlay close. */
|
|
280
|
+
dispose(): void {
|
|
281
|
+
for (const [, timer] of this.#scheduledProviderRefreshes) clearTimeout(timer);
|
|
282
|
+
this.#scheduledProviderRefreshes.clear();
|
|
283
|
+
this.#refreshingProviders.clear();
|
|
284
|
+
if (this.#refreshSpinnerInterval) {
|
|
285
|
+
clearInterval(this.#refreshSpinnerInterval);
|
|
286
|
+
this.#refreshSpinnerInterval = undefined;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
invalidate(): void {}
|
|
291
|
+
|
|
292
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
293
|
+
// Data pipeline
|
|
294
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
295
|
+
|
|
296
|
+
#visibleRoleIds(): string[] {
|
|
297
|
+
return getKnownRoleIds(this.#settings).filter(role => !getRoleInfo(role, this.#settings).hidden);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Resolve every known role: configured values first, auto-selection for the rest. */
|
|
301
|
+
#reloadRoles(autoCandidates: ReadonlyArray<Model>): void {
|
|
302
|
+
const allModels = this.#scopedModels.length > 0 ? autoCandidates : this.#registry.getAll();
|
|
303
|
+
this.#roles = resolveRoleAssignments(this.#settings, allModels, autoCandidates);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Rebuild items, roles, and the sidebar from the registry's in-memory state. */
|
|
307
|
+
#syncFromRegistryState(): void {
|
|
308
|
+
let allModels: ReadonlyArray<Model>;
|
|
309
|
+
let availableModels: ReadonlyArray<Model>;
|
|
310
|
+
if (this.#scopedModels.length > 0) {
|
|
311
|
+
allModels = this.#scopedModels.map(scoped => scoped.model);
|
|
312
|
+
availableModels = allModels;
|
|
313
|
+
this.#configError = undefined;
|
|
314
|
+
} else {
|
|
315
|
+
const loadError = this.#registry.getError();
|
|
316
|
+
this.#configError = loadError ? String(loadError) : undefined;
|
|
317
|
+
allModels = this.#registry.getAll();
|
|
318
|
+
try {
|
|
319
|
+
availableModels = this.#registry.getAvailable();
|
|
320
|
+
} catch (error) {
|
|
321
|
+
this.#configError = error instanceof Error ? error.message : String(error);
|
|
322
|
+
availableModels = [];
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
this.#reloadRoles(availableModels);
|
|
327
|
+
this.#buildRolesRows();
|
|
328
|
+
|
|
329
|
+
const storage = this.#settings.getStorage();
|
|
330
|
+
const mruOrder = storage?.getModelUsageOrder() ?? [];
|
|
331
|
+
this.#availableItems = buildBrowserItems(availableModels);
|
|
332
|
+
sortModelItems(this.#availableItems, { roles: this.#roles, mruOrder });
|
|
333
|
+
this.#browser.setRoles(this.#roles);
|
|
334
|
+
this.#browser.setMruOrder(mruOrder);
|
|
335
|
+
this.#browser.setPerfStats(storage?.getModelPerf() ?? new Map());
|
|
336
|
+
|
|
337
|
+
const bySelector = new Map(this.#availableItems.map(item => [item.selector, item]));
|
|
338
|
+
this.#recentItems = [];
|
|
339
|
+
for (const key of mruOrder) {
|
|
340
|
+
const item = bySelector.get(key);
|
|
341
|
+
if (item) this.#recentItems.push(item);
|
|
342
|
+
if (this.#recentItems.length >= RECENT_LIMIT) break;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
this.#buildSidebar(allModels, availableModels);
|
|
346
|
+
this.#applyScope();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
#buildSidebar(allModels: ReadonlyArray<Model>, availableModels: ReadonlyArray<Model>): void {
|
|
350
|
+
const scoped = this.#scopedModels.length > 0;
|
|
351
|
+
let disabledProviders: ReadonlySet<string>;
|
|
352
|
+
try {
|
|
353
|
+
disabledProviders = new Set(this.#settings.get("disabledProviders"));
|
|
354
|
+
} catch {
|
|
355
|
+
disabledProviders = new Set();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const availableCounts = new Map<string, number>();
|
|
359
|
+
for (const model of availableModels) {
|
|
360
|
+
availableCounts.set(model.provider, (availableCounts.get(model.provider) ?? 0) + 1);
|
|
361
|
+
}
|
|
362
|
+
const catalogCounts = new Map<string, number>();
|
|
363
|
+
for (const model of allModels) {
|
|
364
|
+
catalogCounts.set(model.provider, (catalogCounts.get(model.provider) ?? 0) + 1);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const unlocked = new Set<string>(availableCounts.keys());
|
|
368
|
+
const locked = new Set<string>();
|
|
369
|
+
if (!scoped) {
|
|
370
|
+
const authStorage = this.#registry.authStorage;
|
|
371
|
+
for (const provider of catalogCounts.keys()) {
|
|
372
|
+
if (!unlocked.has(provider) && !disabledProviders.has(provider)) {
|
|
373
|
+
locked.add(provider);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
for (const provider of this.#registry.getDiscoverableProviders()) {
|
|
377
|
+
if (unlocked.has(provider) || disabledProviders.has(provider)) continue;
|
|
378
|
+
// Discoverable without stored auth: catalog-backed providers stay
|
|
379
|
+
// locked; keyless/custom endpoints (ollama, vllm, …) surface as
|
|
380
|
+
// selectable so discovery can populate them.
|
|
381
|
+
if (authStorage.hasAuth(provider) || !locked.has(provider)) {
|
|
382
|
+
locked.delete(provider);
|
|
383
|
+
unlocked.add(provider);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const oauthIds = new Set(getOAuthProviders().map(provider => provider.id));
|
|
389
|
+
const providerEntry = (providerId: string, isLocked: boolean): SidebarEntry => ({
|
|
390
|
+
id: `provider:${providerId}`,
|
|
391
|
+
kind: "provider",
|
|
392
|
+
label: providerId,
|
|
393
|
+
providerId,
|
|
394
|
+
locked: isLocked,
|
|
395
|
+
annotation: isLocked ? undefined : String(availableCounts.get(providerId) ?? 0),
|
|
396
|
+
oauth: oauthIds.has(providerId),
|
|
397
|
+
catalogCount: catalogCounts.get(providerId) ?? 0,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const visibleRoles = this.#visibleRoleIds();
|
|
401
|
+
let assignedCount = 0;
|
|
402
|
+
for (const role of visibleRoles) {
|
|
403
|
+
const assignment = this.#roles[role];
|
|
404
|
+
if (assignment && !assignment.autoSelected) assignedCount++;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Roles leads the fixed section so downward hops from Recent head into
|
|
408
|
+
// model scopes instead of being captured by the roles view.
|
|
409
|
+
const fixed: SidebarEntry[] = [
|
|
410
|
+
{
|
|
411
|
+
id: "roles",
|
|
412
|
+
kind: "roles",
|
|
413
|
+
label: "Roles",
|
|
414
|
+
annotation: `${assignedCount}/${visibleRoles.length}`,
|
|
415
|
+
},
|
|
416
|
+
{ id: "all", kind: "all", label: "All models", annotation: String(availableModels.length) },
|
|
417
|
+
];
|
|
418
|
+
|
|
419
|
+
this.#fixedEntries = fixed;
|
|
420
|
+
this.#unlockedProviderEntries = [...unlocked]
|
|
421
|
+
.sort((a, b) => a.localeCompare(b))
|
|
422
|
+
.map(provider => providerEntry(provider, false));
|
|
423
|
+
this.#lockedProviderEntries = [...locked]
|
|
424
|
+
.sort((a, b) => a.localeCompare(b))
|
|
425
|
+
.map(provider => providerEntry(provider, true));
|
|
426
|
+
this.#composeEntries();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Assemble `#entries` from the stored sections. While a search is active,
|
|
431
|
+
* providers with matches float to the top of the provider section (each
|
|
432
|
+
* group stays alphabetical) so the hop order, mouse hit-testing, and the
|
|
433
|
+
* paint all agree.
|
|
434
|
+
*/
|
|
435
|
+
#composeEntries(): void {
|
|
436
|
+
const counts = this.#searchCounts;
|
|
437
|
+
let providers = this.#unlockedProviderEntries;
|
|
438
|
+
if (counts) {
|
|
439
|
+
providers = [...providers].sort((a, b) => {
|
|
440
|
+
const aMatched = (counts.get(a.providerId ?? "") ?? 0) > 0;
|
|
441
|
+
const bMatched = (counts.get(b.providerId ?? "") ?? 0) > 0;
|
|
442
|
+
if (aMatched !== bMatched) return aMatched ? -1 : 1;
|
|
443
|
+
return a.label.localeCompare(b.label);
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const entries: SidebarEntry[] = [...this.#fixedEntries];
|
|
448
|
+
if (providers.length > 0) {
|
|
449
|
+
entries.push({ id: "sep:providers", kind: "separator", label: "" }, ...providers);
|
|
450
|
+
}
|
|
451
|
+
if (this.#lockedProviderEntries.length > 0) {
|
|
452
|
+
entries.push({ id: "sep:locked", kind: "separator", label: "" }, ...this.#lockedProviderEntries);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
this.#entries = entries;
|
|
456
|
+
if (!entries.some(entry => entry.id === this.#activeEntryId)) {
|
|
457
|
+
this.#activeEntryId = "all";
|
|
458
|
+
this.#sidebarFollowActive = true;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
#activeEntry(): SidebarEntry {
|
|
463
|
+
return this.#entries.find(entry => entry.id === this.#activeEntryId) ?? this.#entries[0];
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
#setActiveEntry(id: string): void {
|
|
467
|
+
if (!this.#entries.some(entry => entry.id === id)) return;
|
|
468
|
+
this.#activeEntryId = id;
|
|
469
|
+
this.#sidebarFollowActive = true;
|
|
470
|
+
this.#applyScope();
|
|
471
|
+
const entry = this.#activeEntry();
|
|
472
|
+
// Hops must never steal arrow focus: landing on a scope keeps provider
|
|
473
|
+
// navigation active. Diving into the roles rows is explicit (Enter, →,
|
|
474
|
+
// or a click on the Roles entry).
|
|
475
|
+
this.#focus = "scope";
|
|
476
|
+
if (entry.kind === "provider" && !entry.locked) {
|
|
477
|
+
this.#scheduleProviderRefresh(entry.providerId ?? "");
|
|
478
|
+
}
|
|
479
|
+
this.#cancelScheduledRefreshesExcept(entry.kind === "provider" ? entry.providerId : undefined);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** Push the active scope's items into the browser. */
|
|
483
|
+
#applyScope(): void {
|
|
484
|
+
const entry = this.#activeEntry();
|
|
485
|
+
switch (entry.kind) {
|
|
486
|
+
case "recent":
|
|
487
|
+
this.#browser.setShowProvider(true);
|
|
488
|
+
this.#browser.setItems([...this.#recentItems]);
|
|
489
|
+
break;
|
|
490
|
+
case "provider": {
|
|
491
|
+
if (entry.locked) {
|
|
492
|
+
// Assign-mode renders the browser regardless of scope; a locked
|
|
493
|
+
// provider contributes nothing selectable.
|
|
494
|
+
this.#browser.setItems([]);
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
const providerId = entry.providerId;
|
|
498
|
+
this.#browser.setShowProvider(false);
|
|
499
|
+
this.#browser.setItems(this.#availableItems.filter(item => item.provider === providerId));
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
case "roles":
|
|
503
|
+
this.#roleIndex = Math.min(this.#roleIndex, Math.max(0, this.#rolesRowCount - 1));
|
|
504
|
+
break;
|
|
505
|
+
default:
|
|
506
|
+
this.#browser.setShowProvider(true);
|
|
507
|
+
this.#browser.setItems([...this.#availableItems]);
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* The configured `retry.fallbackChains` record with malformed keys/entries
|
|
514
|
+
* dropped: non-array chains and non-string selectors never reach the rows
|
|
515
|
+
* or chain editors, so an edit through the hub replaces them wholesale.
|
|
516
|
+
*/
|
|
517
|
+
#fallbackChains(): Record<string, string[]> {
|
|
518
|
+
try {
|
|
519
|
+
const chains = this.#settings.get("retry.fallbackChains");
|
|
520
|
+
if (!chains || typeof chains !== "object" || Array.isArray(chains)) return {};
|
|
521
|
+
const sanitized: Record<string, string[]> = {};
|
|
522
|
+
for (const key in chains) {
|
|
523
|
+
const chain = (chains as Record<string, unknown>)[key];
|
|
524
|
+
if (!Array.isArray(chain)) continue;
|
|
525
|
+
sanitized[key] = chain.filter((entry): entry is string => typeof entry === "string");
|
|
526
|
+
}
|
|
527
|
+
return sanitized;
|
|
528
|
+
} catch {
|
|
529
|
+
return {};
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Rebuild the Roles view rows: each visible role followed by its
|
|
535
|
+
* fallback-chain entries, then model-oriented chains (`provider/model-id`
|
|
536
|
+
* and `provider/*` keys) as headed groups.
|
|
537
|
+
*/
|
|
538
|
+
#buildRolesRows(): void {
|
|
539
|
+
const rows: RolesRow[] = [];
|
|
540
|
+
const chains = this.#fallbackChains();
|
|
541
|
+
for (const role of this.#visibleRoleIds()) {
|
|
542
|
+
rows.push({ kind: "role", role });
|
|
543
|
+
const chain = chains[role] ?? [];
|
|
544
|
+
for (let i = 0; i < chain.length; i++) {
|
|
545
|
+
rows.push({ kind: "fallback", role, chainIndex: i, selector: chain[i] });
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
rows.push({ kind: "newRole" });
|
|
549
|
+
rows.push({ kind: "separator" });
|
|
550
|
+
const modelKeys = Object.keys(chains)
|
|
551
|
+
.filter(key => key.includes("/"))
|
|
552
|
+
.sort();
|
|
553
|
+
for (const key of modelKeys) {
|
|
554
|
+
const chain = chains[key] ?? [];
|
|
555
|
+
rows.push({ kind: "chainKey", role: key });
|
|
556
|
+
for (let i = 0; i < chain.length; i++) {
|
|
557
|
+
rows.push({ kind: "fallback", role: key, chainIndex: i, selector: chain[i] });
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
rows.push({ kind: "newFallback" });
|
|
561
|
+
this.#rolesRows = rows;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** Refresh roles + dependent state after a settings mutation (assign/unassign). */
|
|
565
|
+
#refreshAfterMutation(): void {
|
|
566
|
+
this.#syncFromRegistryState();
|
|
567
|
+
this.#tui.requestRender();
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/** Re-sync after an asynchronous callback finishes mutating settings. */
|
|
571
|
+
refreshAfterExternalMutation(): void {
|
|
572
|
+
this.#refreshAfterMutation();
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Recompute per-provider match counts for the active query. Providers
|
|
577
|
+
* without matches gray out and the scope hop skips them; a provider scope
|
|
578
|
+
* that just lost its last match falls back to All models so the results
|
|
579
|
+
* never silently vanish.
|
|
580
|
+
*/
|
|
581
|
+
#onQueryChanged(query: string): void {
|
|
582
|
+
if (!query.trim()) {
|
|
583
|
+
this.#searchCounts = null;
|
|
584
|
+
this.#composeEntries();
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const matches = fuzzyFilter(this.#availableItems, query, ({ provider, id }) => `${provider}/${id}`);
|
|
588
|
+
const counts = new Map<string, number>();
|
|
589
|
+
for (const item of matches) {
|
|
590
|
+
counts.set(item.provider, (counts.get(item.provider) ?? 0) + 1);
|
|
591
|
+
}
|
|
592
|
+
const recentSelectors = new Set(this.#recentItems.map(item => item.selector));
|
|
593
|
+
this.#recentSearchCount = matches.reduce(
|
|
594
|
+
(total, item) => total + (recentSelectors.has(item.selector) ? 1 : 0),
|
|
595
|
+
0,
|
|
596
|
+
);
|
|
597
|
+
this.#searchTotal = matches.length;
|
|
598
|
+
this.#searchCounts = counts;
|
|
599
|
+
this.#composeEntries();
|
|
600
|
+
const entry = this.#activeEntry();
|
|
601
|
+
if (
|
|
602
|
+
this.#assigning === null &&
|
|
603
|
+
entry.kind === "provider" &&
|
|
604
|
+
(entry.locked || (counts.get(entry.providerId ?? "") ?? 0) === 0)
|
|
605
|
+
) {
|
|
606
|
+
this.#setActiveEntry("all");
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Entries the scope hop skips: separators always; while searching, also
|
|
612
|
+
* the Roles view (not a model scope), an empty Recent, locked providers,
|
|
613
|
+
* and providers without matches.
|
|
614
|
+
*/
|
|
615
|
+
#isHopSkipped(entry: SidebarEntry): boolean {
|
|
616
|
+
if (entry.kind === "separator") return true;
|
|
617
|
+
if (!this.#searchCounts) return false;
|
|
618
|
+
if (entry.kind === "roles") return true;
|
|
619
|
+
if (entry.kind === "recent") return this.#recentSearchCount === 0;
|
|
620
|
+
if (entry.kind === "provider") {
|
|
621
|
+
if (entry.locked) return true;
|
|
622
|
+
return (this.#searchCounts.get(entry.providerId ?? "") ?? 0) === 0;
|
|
623
|
+
}
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
628
|
+
// Provider discovery refresh
|
|
629
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
630
|
+
|
|
631
|
+
#startRefreshSpinner(): void {
|
|
632
|
+
if (this.#refreshSpinnerInterval) return;
|
|
633
|
+
this.#refreshSpinnerInterval = setInterval(() => {
|
|
634
|
+
const frameCount = theme.spinnerFrames.length;
|
|
635
|
+
if (frameCount > 0) {
|
|
636
|
+
this.#refreshSpinnerFrame = (this.#refreshSpinnerFrame + 1) % frameCount;
|
|
637
|
+
}
|
|
638
|
+
this.#tui.requestRender();
|
|
639
|
+
}, 80);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
#stopRefreshSpinnerIfIdle(): void {
|
|
643
|
+
if (this.#refreshingProviders.size > 0) return;
|
|
644
|
+
if (this.#refreshSpinnerInterval) {
|
|
645
|
+
clearInterval(this.#refreshSpinnerInterval);
|
|
646
|
+
this.#refreshSpinnerInterval = undefined;
|
|
647
|
+
}
|
|
648
|
+
this.#refreshSpinnerFrame = 0;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
#setProviderRefreshing(providerId: string, refreshing: boolean): void {
|
|
652
|
+
if (refreshing) {
|
|
653
|
+
this.#refreshingProviders.add(providerId);
|
|
654
|
+
this.#startRefreshSpinner();
|
|
655
|
+
} else {
|
|
656
|
+
this.#refreshingProviders.delete(providerId);
|
|
657
|
+
this.#stopRefreshSpinnerIfIdle();
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
#cancelScheduledRefreshesExcept(keepProviderId?: string): void {
|
|
662
|
+
for (const [providerId, timer] of this.#scheduledProviderRefreshes) {
|
|
663
|
+
if (providerId === keepProviderId) continue;
|
|
664
|
+
clearTimeout(timer);
|
|
665
|
+
this.#scheduledProviderRefreshes.delete(providerId);
|
|
666
|
+
this.#setProviderRefreshing(providerId, false);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
#scheduleProviderRefresh(providerId: string, options?: { force?: boolean }): void {
|
|
671
|
+
if (this.#scopedModels.length > 0 || !providerId) return;
|
|
672
|
+
if (this.#scheduledProviderRefreshes.has(providerId) || this.#refreshingProviders.has(providerId)) return;
|
|
673
|
+
// Hovering a provider must not re-fetch on every visit: auto-refresh runs
|
|
674
|
+
// at most once per provider for the process lifetime. F5 forces a re-fetch.
|
|
675
|
+
if (!options?.force && autoRefreshedProviders.has(providerId)) return;
|
|
676
|
+
this.#setProviderRefreshing(providerId, true);
|
|
677
|
+
const timer = setTimeout(() => {
|
|
678
|
+
// Consume the once-guard only when the fetch actually starts: hopping
|
|
679
|
+
// through a provider cancels the debounce and must not burn its slot.
|
|
680
|
+
autoRefreshedProviders.add(providerId);
|
|
681
|
+
this.#scheduledProviderRefreshes.delete(providerId);
|
|
682
|
+
void this.#refreshProviderInBackground(providerId);
|
|
683
|
+
}, PROVIDER_REFRESH_DEBOUNCE_MS);
|
|
684
|
+
this.#scheduledProviderRefreshes.set(providerId, timer);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
async #refreshProviderInBackground(providerId: string): Promise<void> {
|
|
688
|
+
try {
|
|
689
|
+
await this.#registry.refreshProvider(providerId, "online");
|
|
690
|
+
// The provider refresh already updated the registry snapshot;
|
|
691
|
+
// re-reading it here stays purely in-memory.
|
|
692
|
+
this.#syncFromRegistryState();
|
|
693
|
+
} catch (error) {
|
|
694
|
+
this.#configError = error instanceof Error ? error.message : String(error);
|
|
695
|
+
} finally {
|
|
696
|
+
this.#setProviderRefreshing(providerId, false);
|
|
697
|
+
this.#tui.requestRender();
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
#formatDiscoveryAge(fetchedAt: number | undefined): string | undefined {
|
|
702
|
+
if (!fetchedAt) return undefined;
|
|
703
|
+
const ageMs = Math.max(0, Date.now() - fetchedAt);
|
|
704
|
+
if (ageMs < 60_000) return "less than a minute ago";
|
|
705
|
+
return `${Math.round(ageMs / 60_000)}m ago`;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
#emptyStateMessage(): string | undefined {
|
|
709
|
+
if (this.#configError) return ` ${this.#configError}`;
|
|
710
|
+
const entry = this.#activeEntry();
|
|
711
|
+
if (entry.kind === "recent") return " No recently used models yet";
|
|
712
|
+
if (entry.kind !== "provider" || entry.locked) return undefined;
|
|
713
|
+
if (this.#browser.query.trim()) {
|
|
714
|
+
return ` No matching models in ${entry.label}. Switch to All models to search every provider.`;
|
|
715
|
+
}
|
|
716
|
+
const providerId = entry.providerId ?? "";
|
|
717
|
+
const state = this.#registry.getProviderDiscoveryState(providerId);
|
|
718
|
+
if (!state) return undefined;
|
|
719
|
+
const age = this.#formatDiscoveryAge(state.fetchedAt);
|
|
720
|
+
switch (state.status) {
|
|
721
|
+
case "cached":
|
|
722
|
+
return age
|
|
723
|
+
? ` Using cached model list from ${age}. Live refresh is still pending.`
|
|
724
|
+
: " Using cached model list. Live refresh is still pending.";
|
|
725
|
+
case "unavailable": {
|
|
726
|
+
const httpMatch = state.error?.match(/^HTTP (\d+) from (.+)$/);
|
|
727
|
+
if (httpMatch?.[1] === "404") {
|
|
728
|
+
return ` Discovery endpoint ${httpMatch[2]} returned 404. Point baseUrl at the host that serves /models (usually .../v1).`;
|
|
729
|
+
}
|
|
730
|
+
if (state.error) return ` Discovery failed: ${state.error}`;
|
|
731
|
+
return age ? ` Provider unavailable. Using cached model list from ${age}.` : " Provider unavailable.";
|
|
732
|
+
}
|
|
733
|
+
case "unauthenticated":
|
|
734
|
+
return " Provider requires authentication before models can be discovered.";
|
|
735
|
+
case "idle":
|
|
736
|
+
return " Provider has not been refreshed yet.";
|
|
737
|
+
case "empty":
|
|
738
|
+
return " Discovery succeeded but returned 0 models. Check that /models returns { data: [{ id }] }.";
|
|
739
|
+
case "ok":
|
|
740
|
+
return undefined;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
745
|
+
// Assignment flow
|
|
746
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
747
|
+
|
|
748
|
+
#activateItem(item: ModelBrowserItem): void {
|
|
749
|
+
if (this.#assigning) {
|
|
750
|
+
const target = this.#assigning;
|
|
751
|
+
this.#assigning = null;
|
|
752
|
+
if (target.kind === "role") {
|
|
753
|
+
this.#assignRole(item, target.role, true);
|
|
754
|
+
} else if (target.kind === "fallbackKey") {
|
|
755
|
+
this.#openFallbackKeyStrip(item);
|
|
756
|
+
} else {
|
|
757
|
+
this.#commitFallback(item, target);
|
|
758
|
+
}
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
this.#openRoleStrip(item);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
#roleForScope(role: string, scope: ModelRoleSelectionScope): ResolvedModelRoleValue {
|
|
765
|
+
const roleValue =
|
|
766
|
+
scope === "project" ? this.#settings.getProjectModelRole(role) : this.#settings.getGlobalModelRole(role);
|
|
767
|
+
const allModels =
|
|
768
|
+
this.#scopedModels.length > 0 ? this.#scopedModels.map(scoped => scoped.model) : this.#registry.getAll();
|
|
769
|
+
const roleLookup: ModelRoleLookup = {
|
|
770
|
+
getModelRole: scopedRole =>
|
|
771
|
+
scope === "project"
|
|
772
|
+
? (this.#settings.getProjectModelRole(scopedRole) ?? this.#settings.getGlobalModelRole(scopedRole))
|
|
773
|
+
: this.#settings.getGlobalModelRole(scopedRole),
|
|
774
|
+
};
|
|
775
|
+
return resolveModelRoleValue(roleValue, allModels, { settings: this.#settings, roleLookup });
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
#thinkingLevelForScope(role: string, scope: ModelRoleSelectionScope): ConfiguredThinkingLevel {
|
|
779
|
+
const resolved = this.#roleForScope(role, scope);
|
|
780
|
+
return resolved.explicitThinkingLevel ? (resolved.thinkingLevel ?? ThinkingLevel.Inherit) : ThinkingLevel.Inherit;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/** Persist `role → item`, preserving a still-supported thinking level, then open the thinking strip. */
|
|
784
|
+
#assignRole(item: ModelBrowserItem, role: string, returnToRoles: boolean, scope?: ModelRoleSelectionScope): void {
|
|
785
|
+
if (this.#settings.get("modelRoleStorage") === "project" && scope === undefined) {
|
|
786
|
+
this.#openScopeStrip(item, role, returnToRoles);
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const current = this.#roles[role];
|
|
791
|
+
let level: ConfiguredThinkingLevel = ThinkingLevel.Inherit;
|
|
792
|
+
if (this.#settings.get("modelRoleStorage") === "project" && scope !== undefined) {
|
|
793
|
+
level = this.#thinkingLevelForScope(role, scope);
|
|
794
|
+
} else if (current && !current.autoSelected) {
|
|
795
|
+
level = current.thinkingLevel;
|
|
796
|
+
}
|
|
797
|
+
const supported = this.#thinkingOptionsFor(item.model);
|
|
798
|
+
if (!supported.includes(level)) level = ThinkingLevel.Inherit;
|
|
799
|
+
this.#callbacks.onAssign(item.model, role, level, item.selector, scope);
|
|
800
|
+
this.#refreshAfterMutation();
|
|
801
|
+
this.#openThinkingStrip(item, role, returnToRoles, scope);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
#unassignRole(role: string): void {
|
|
805
|
+
const assignment = this.#roles[role];
|
|
806
|
+
if (!assignment || assignment.autoSelected) return;
|
|
807
|
+
if (this.#settings.get("modelRoleStorage") === "project") {
|
|
808
|
+
const source = this.#settings.getModelRoleSource(role);
|
|
809
|
+
this.#callbacks.onUnassign(role, source === "default" ? undefined : source);
|
|
810
|
+
} else {
|
|
811
|
+
this.#callbacks.onUnassign(role);
|
|
812
|
+
}
|
|
813
|
+
this.#refreshAfterMutation();
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
#thinkingOptionsFor(model: Model): ConfiguredThinkingLevel[] {
|
|
817
|
+
return [ThinkingLevel.Inherit, ThinkingLevel.Off, AUTO_THINKING, ...getSupportedEfforts(model)];
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
#openRoleStrip(item: ModelBrowserItem): void {
|
|
821
|
+
const chips: StripChip[] = [];
|
|
822
|
+
const scopedStorage = this.#settings.get("modelRoleStorage") === "project";
|
|
823
|
+
const scopes: readonly ModelRoleSelectionScope[] = scopedStorage ? ["project", "global"] : ["global"];
|
|
824
|
+
for (const role of this.#visibleRoleIds()) {
|
|
825
|
+
const info = getRoleInfo(role, this.#settings);
|
|
826
|
+
const assignment = this.#roles[role];
|
|
827
|
+
for (const scope of scopes) {
|
|
828
|
+
const scopedModel = scopedStorage
|
|
829
|
+
? this.#roleForScope(role, scope).model
|
|
830
|
+
: assignment && !assignment.autoSelected
|
|
831
|
+
? assignment.model
|
|
832
|
+
: undefined;
|
|
833
|
+
const assignedHere =
|
|
834
|
+
!!scopedModel && scopedModel.provider === item.model.provider && scopedModel.id === item.model.id;
|
|
835
|
+
const roleLabel = (info.tag ?? info.name ?? role).toLowerCase();
|
|
836
|
+
const label = scopedStorage ? `${scope} ${roleLabel}` : roleLabel;
|
|
837
|
+
chips.push({
|
|
838
|
+
label,
|
|
839
|
+
styled: assignedHere
|
|
840
|
+
? // Separator required: under the `nerd` preset this glyph is a
|
|
841
|
+
// two-cell-wide PUA icon that `visibleWidth` counts as one, so
|
|
842
|
+
// without it the icon overhangs and eats `label`'s first char.
|
|
843
|
+
theme.fg(info.color ?? "muted", `${theme.status.enabled} ${label}`) +
|
|
844
|
+
theme.fg("dim", ` ${theme.status.success}`)
|
|
845
|
+
: theme.fg(info.color ?? "muted", label),
|
|
846
|
+
role,
|
|
847
|
+
scope,
|
|
848
|
+
action: assignedHere ? "unassign" : "assign",
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
chips.push({
|
|
853
|
+
label: `fallbacks:${item.model.id}`,
|
|
854
|
+
styled: theme.fg("muted", `fallbacks:${item.model.id}`),
|
|
855
|
+
action: "fallbackModel",
|
|
856
|
+
});
|
|
857
|
+
chips.push({
|
|
858
|
+
label: `fallbacks:${item.model.provider}/*`,
|
|
859
|
+
styled: theme.fg("muted", `fallbacks:${item.model.provider}/*`),
|
|
860
|
+
action: "fallbackProvider",
|
|
861
|
+
});
|
|
862
|
+
chips.push({ label: "fallback", styled: theme.fg("muted", "retry-fallback"), action: "fallback" });
|
|
863
|
+
this.#strip = { kind: "role", item, chips, index: 0, returnToRoles: false };
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
#openScopeStrip(item: ModelBrowserItem, role: string, returnToRoles: boolean): void {
|
|
867
|
+
const chips: StripChip[] = [
|
|
868
|
+
{ label: "project", styled: theme.fg("accent", "project"), action: "scope", scope: "project" },
|
|
869
|
+
{ label: "global", styled: theme.fg("muted", "global"), action: "scope", scope: "global" },
|
|
870
|
+
];
|
|
871
|
+
this.#strip = { kind: "scope", item, role, chips, index: 0, returnToRoles };
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
#openThinkingStrip(
|
|
875
|
+
item: ModelBrowserItem,
|
|
876
|
+
role: string,
|
|
877
|
+
returnToRoles: boolean,
|
|
878
|
+
scope?: ModelRoleSelectionScope,
|
|
879
|
+
): void {
|
|
880
|
+
const options = this.#thinkingOptionsFor(item.model);
|
|
881
|
+
const current =
|
|
882
|
+
this.#settings.get("modelRoleStorage") === "project" && scope !== undefined
|
|
883
|
+
? this.#thinkingLevelForScope(role, scope)
|
|
884
|
+
: (this.#roles[role]?.thinkingLevel ?? ThinkingLevel.Inherit);
|
|
885
|
+
const chips: StripChip[] = options.map(level => {
|
|
886
|
+
const label = getConfiguredThinkingLevelMetadata(level).label;
|
|
887
|
+
const glyph = thinkingLevelGlyph(level);
|
|
888
|
+
return {
|
|
889
|
+
label,
|
|
890
|
+
styled: glyph ? `${theme.fg("accent", glyph)} ${label}` : label,
|
|
891
|
+
action: "thinking",
|
|
892
|
+
thinkingLevel: level,
|
|
893
|
+
};
|
|
894
|
+
});
|
|
895
|
+
const preselect = options.indexOf(current);
|
|
896
|
+
this.#strip = {
|
|
897
|
+
kind: "thinking",
|
|
898
|
+
item,
|
|
899
|
+
role,
|
|
900
|
+
scope,
|
|
901
|
+
chips,
|
|
902
|
+
index: preselect >= 0 ? preselect : 0,
|
|
903
|
+
returnToRoles,
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
#closeStrip(): void {
|
|
908
|
+
const strip = this.#strip;
|
|
909
|
+
this.#strip = null;
|
|
910
|
+
this.#chipRanges = [];
|
|
911
|
+
if ((strip?.kind === "scope" || strip?.kind === "thinking") && strip.returnToRoles) {
|
|
912
|
+
this.#setActiveEntry("roles");
|
|
913
|
+
this.#focus = "list";
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
#activateStripChip(): void {
|
|
918
|
+
const strip = this.#strip;
|
|
919
|
+
if (!strip || strip.kind === "roleName") return;
|
|
920
|
+
const chip = strip.chips[strip.index];
|
|
921
|
+
if (!chip) return;
|
|
922
|
+
switch (chip.action) {
|
|
923
|
+
case "assign":
|
|
924
|
+
if (chip.role) {
|
|
925
|
+
this.#strip = null;
|
|
926
|
+
this.#assignRole(strip.item, chip.role, false, chip.scope);
|
|
927
|
+
}
|
|
928
|
+
return;
|
|
929
|
+
case "unassign":
|
|
930
|
+
if (chip.role) {
|
|
931
|
+
if (this.#settings.get("modelRoleStorage") === "project") {
|
|
932
|
+
this.#callbacks.onUnassign(chip.role, chip.scope);
|
|
933
|
+
} else {
|
|
934
|
+
this.#callbacks.onUnassign(chip.role);
|
|
935
|
+
}
|
|
936
|
+
this.#refreshAfterMutation();
|
|
937
|
+
}
|
|
938
|
+
this.#closeStrip();
|
|
939
|
+
return;
|
|
940
|
+
case "fallback":
|
|
941
|
+
this.#appendFallback(strip.item, "default");
|
|
942
|
+
this.#closeStrip();
|
|
943
|
+
return;
|
|
944
|
+
case "fallbackModel":
|
|
945
|
+
this.#closeStrip();
|
|
946
|
+
this.#startAssignFallback(strip.item.selector, null);
|
|
947
|
+
return;
|
|
948
|
+
case "fallbackProvider":
|
|
949
|
+
this.#closeStrip();
|
|
950
|
+
this.#startAssignFallback(`${strip.item.model.provider}/*`, null);
|
|
951
|
+
return;
|
|
952
|
+
case "scope":
|
|
953
|
+
if (strip.role && chip.scope) {
|
|
954
|
+
this.#strip = null;
|
|
955
|
+
this.#assignRole(strip.item, strip.role, strip.returnToRoles, chip.scope);
|
|
956
|
+
}
|
|
957
|
+
return;
|
|
958
|
+
case "thinking":
|
|
959
|
+
if (strip.role && chip.thinkingLevel !== undefined) {
|
|
960
|
+
this.#callbacks.onAssign(
|
|
961
|
+
strip.item.model,
|
|
962
|
+
strip.role,
|
|
963
|
+
chip.thinkingLevel,
|
|
964
|
+
strip.item.selector,
|
|
965
|
+
strip.scope,
|
|
966
|
+
);
|
|
967
|
+
this.#refreshAfterMutation();
|
|
968
|
+
}
|
|
969
|
+
this.#closeStrip();
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/** Switch the body into assign mode for `role`: full catalog, cleared query, current model preselected. */
|
|
975
|
+
#startAssign(role: string): void {
|
|
976
|
+
this.#assigning = { kind: "role", role };
|
|
977
|
+
this.#focus = "scope";
|
|
978
|
+
this.#browser.setShowProvider(true);
|
|
979
|
+
this.#browser.setItems([...this.#availableItems]);
|
|
980
|
+
this.#browser.setQuery("");
|
|
981
|
+
const current = this.#roles[role];
|
|
982
|
+
if (current) {
|
|
983
|
+
this.#browser.selectSelector(`${current.model.provider}/${current.model.id}`);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/** Browse the catalog to fill a fallback-chain slot: `index` replaces an entry, `null` appends. */
|
|
988
|
+
#startAssignFallback(role: string, index: number | null): void {
|
|
989
|
+
this.#assigning = { kind: "fallback", role, index };
|
|
990
|
+
this.#focus = "scope";
|
|
991
|
+
this.#browser.setShowProvider(true);
|
|
992
|
+
this.#browser.setItems([...this.#availableItems]);
|
|
993
|
+
this.#browser.setQuery("");
|
|
994
|
+
if (index !== null) {
|
|
995
|
+
const selector = this.#fallbackChains()[role]?.[index];
|
|
996
|
+
if (selector) this.#browser.selectSelector(selector);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/** Browse the catalog for the primary model a brand-new fallback chain protects. */
|
|
1001
|
+
#startAssignFallbackKey(): void {
|
|
1002
|
+
this.#assigning = { kind: "fallbackKey" };
|
|
1003
|
+
this.#focus = "scope";
|
|
1004
|
+
this.#browser.setShowProvider(true);
|
|
1005
|
+
this.#browser.setItems([...this.#availableItems]);
|
|
1006
|
+
this.#browser.setQuery("");
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/** Second step of "+ New fallback…": key the chain by the picked model or its whole provider. */
|
|
1010
|
+
#openFallbackKeyStrip(item: ModelBrowserItem): void {
|
|
1011
|
+
const chips: StripChip[] = [
|
|
1012
|
+
{
|
|
1013
|
+
label: `for ${item.selector}`,
|
|
1014
|
+
styled: theme.fg("muted", `for ${item.selector}`),
|
|
1015
|
+
action: "fallbackModel",
|
|
1016
|
+
},
|
|
1017
|
+
{
|
|
1018
|
+
label: `for ${item.model.provider}/*`,
|
|
1019
|
+
styled: theme.fg("muted", `for ${item.model.provider}/*`),
|
|
1020
|
+
action: "fallbackProvider",
|
|
1021
|
+
},
|
|
1022
|
+
];
|
|
1023
|
+
this.#strip = { kind: "role", item, chips, index: 0, returnToRoles: false };
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/** Write the picked model into the target chain slot, dedupe, and land back on its Roles row. */
|
|
1027
|
+
#commitFallback(item: ModelBrowserItem, target: { role: string; index: number | null }): void {
|
|
1028
|
+
const chain = [...(this.#fallbackChains()[target.role] ?? [])];
|
|
1029
|
+
const selector = item.selector;
|
|
1030
|
+
if (target.index !== null && target.index < chain.length) {
|
|
1031
|
+
chain[target.index] = selector;
|
|
1032
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
1033
|
+
if (i !== target.index && chain[i] === selector) chain.splice(i, 1);
|
|
1034
|
+
}
|
|
1035
|
+
} else if (!chain.includes(selector)) {
|
|
1036
|
+
chain.push(selector);
|
|
1037
|
+
}
|
|
1038
|
+
this.#setFallbackChain(target.role, chain);
|
|
1039
|
+
this.#browser.setQuery("");
|
|
1040
|
+
this.#setActiveEntry("roles");
|
|
1041
|
+
this.#focus = "list";
|
|
1042
|
+
const rowIndex = this.#rolesRows.findIndex(
|
|
1043
|
+
row => row.kind === "fallback" && row.role === target.role && row.selector === selector,
|
|
1044
|
+
);
|
|
1045
|
+
if (rowIndex >= 0) this.#roleIndex = rowIndex;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/** Persist `role`'s chain through the host callback and rebuild dependent state. */
|
|
1049
|
+
#setFallbackChain(role: string, chain: string[]): void {
|
|
1050
|
+
this.#callbacks.onFallbackChainChange?.(role, chain);
|
|
1051
|
+
this.#refreshAfterMutation();
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
/** Append `item` to `role`'s fallback chain (no-op when already present). */
|
|
1055
|
+
#appendFallback(item: ModelBrowserItem, role: string): void {
|
|
1056
|
+
const chain = [...(this.#fallbackChains()[role] ?? [])];
|
|
1057
|
+
if (chain.includes(item.selector)) return;
|
|
1058
|
+
chain.push(item.selector);
|
|
1059
|
+
this.#setFallbackChain(role, chain);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
/** Remove one chain entry; the cursor stays on the nearest surviving row. */
|
|
1063
|
+
#removeFallback(row: { role: string; chainIndex: number }): void {
|
|
1064
|
+
const chain = [...(this.#fallbackChains()[row.role] ?? [])];
|
|
1065
|
+
if (row.chainIndex >= chain.length) return;
|
|
1066
|
+
chain.splice(row.chainIndex, 1);
|
|
1067
|
+
this.#setFallbackChain(row.role, chain);
|
|
1068
|
+
this.#roleIndex = Math.min(this.#roleIndex, Math.max(0, this.#rolesRows.length - 1));
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
/** Move a chain entry one slot earlier/later; the cursor follows the moved entry. */
|
|
1072
|
+
#moveFallback(row: { role: string; chainIndex: number }, delta: -1 | 1): void {
|
|
1073
|
+
const chain = [...(this.#fallbackChains()[row.role] ?? [])];
|
|
1074
|
+
const target = row.chainIndex + delta;
|
|
1075
|
+
if (row.chainIndex >= chain.length || target < 0 || target >= chain.length) return;
|
|
1076
|
+
[chain[row.chainIndex], chain[target]] = [chain[target], chain[row.chainIndex]];
|
|
1077
|
+
this.#setFallbackChain(row.role, chain);
|
|
1078
|
+
this.#roleIndex += delta;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
#cancelAssign(): void {
|
|
1082
|
+
this.#assigning = null;
|
|
1083
|
+
this.#browser.setQuery("");
|
|
1084
|
+
this.#setActiveEntry("roles");
|
|
1085
|
+
this.#focus = "list";
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1089
|
+
// Quick-switch cycle (ctrl+p) editing
|
|
1090
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1091
|
+
|
|
1092
|
+
#cycleOrder(): string[] {
|
|
1093
|
+
try {
|
|
1094
|
+
return [...this.#settings.get("cycleOrder")];
|
|
1095
|
+
} catch {
|
|
1096
|
+
return [];
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/** Toggle `role`'s membership in the quick-switch cycle (appended at the end). */
|
|
1101
|
+
#toggleCycleMembership(role: string): void {
|
|
1102
|
+
const order = this.#cycleOrder();
|
|
1103
|
+
const index = order.indexOf(role);
|
|
1104
|
+
if (index >= 0) {
|
|
1105
|
+
order.splice(index, 1);
|
|
1106
|
+
} else {
|
|
1107
|
+
order.push(role);
|
|
1108
|
+
}
|
|
1109
|
+
this.#callbacks.onCycleOrderChange?.(order);
|
|
1110
|
+
this.#refreshAfterMutation();
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/** Move `role` one slot earlier/later within the cycle order. */
|
|
1114
|
+
#moveCycleMembership(role: string, delta: -1 | 1): void {
|
|
1115
|
+
const order = this.#cycleOrder();
|
|
1116
|
+
const index = order.indexOf(role);
|
|
1117
|
+
const target = index + delta;
|
|
1118
|
+
if (index < 0 || target < 0 || target >= order.length) return;
|
|
1119
|
+
[order[index], order[target]] = [order[target], order[index]];
|
|
1120
|
+
this.#callbacks.onCycleOrderChange?.(order);
|
|
1121
|
+
this.#refreshAfterMutation();
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
/** Open the footer name input that creates a new custom role. */
|
|
1125
|
+
#openRoleNameStrip(): void {
|
|
1126
|
+
this.#strip = { kind: "roleName", input: new Input() };
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/** Validate and commit the new-role name: jump straight into assigning it. */
|
|
1130
|
+
#submitRoleName(): void {
|
|
1131
|
+
const strip = this.#strip;
|
|
1132
|
+
if (strip?.kind !== "roleName") return;
|
|
1133
|
+
const name = strip.input.getValue().trim();
|
|
1134
|
+
if (!/^[a-zA-Z][\w-]*$/.test(name)) return;
|
|
1135
|
+
if (this.#visibleRoleIds().includes(name)) return;
|
|
1136
|
+
this.#strip = null;
|
|
1137
|
+
this.#chipRanges = [];
|
|
1138
|
+
this.#startAssign(name);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1142
|
+
// Input
|
|
1143
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1144
|
+
|
|
1145
|
+
handleInput(data: string): void {
|
|
1146
|
+
if (data.startsWith("\x1b[<")) {
|
|
1147
|
+
routeSgrMouseInput(data, event => this.#routeMouseEvent(event));
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
if (this.#strip) {
|
|
1152
|
+
this.#handleStripInput(data);
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
if (matchesSelectCancel(data)) {
|
|
1157
|
+
if (this.#assigning !== null) {
|
|
1158
|
+
this.#cancelAssign();
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
const entry = this.#activeEntry();
|
|
1162
|
+
if (this.#isBrowserView(entry) && this.#browser.query.length > 0) {
|
|
1163
|
+
this.#browser.handleCancel();
|
|
1164
|
+
return;
|
|
1165
|
+
}
|
|
1166
|
+
this.#callbacks.onCancel();
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
const entry = this.#activeEntry();
|
|
1171
|
+
const rolesView = entry.kind === "roles" && this.#assigning === null;
|
|
1172
|
+
const lockedView = entry.kind === "provider" && entry.locked && this.#assigning === null;
|
|
1173
|
+
|
|
1174
|
+
if (matchesKey(data, "tab") || matchesKey(data, "shift+tab")) {
|
|
1175
|
+
this.#focus = this.#focus === "scope" ? "list" : "scope";
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
if (matchesKey(data, "f5")) {
|
|
1179
|
+
if (entry.kind === "provider" && !entry.locked) {
|
|
1180
|
+
this.#scheduleProviderRefresh(entry.providerId ?? "", { force: true });
|
|
1181
|
+
}
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
// ←/→ are spatial pane switches: the sidebar sits left of the rows.
|
|
1186
|
+
// They never reach the search caret — fuzzy queries don't need one.
|
|
1187
|
+
if (matchesKey(data, "left")) {
|
|
1188
|
+
this.#focus = "scope";
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
if (matchesKey(data, "right")) {
|
|
1192
|
+
// Only views with rows can take list focus (not the locked pane).
|
|
1193
|
+
if (rolesView || this.#isBrowserView(entry)) {
|
|
1194
|
+
this.#focus = "list";
|
|
1195
|
+
}
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// Arrow ownership: scope mode hops the sidebar even while the search
|
|
1200
|
+
// bar holds the caret; list mode navigates rows.
|
|
1201
|
+
if (this.#focus === "scope") {
|
|
1202
|
+
if (matchesSelectUp(data)) {
|
|
1203
|
+
this.#moveSidebar(-1);
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
if (matchesSelectDown(data)) {
|
|
1207
|
+
this.#moveSidebar(1);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
if (rolesView) {
|
|
1213
|
+
this.#handleRolesViewInput(data);
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
if (lockedView) {
|
|
1217
|
+
if (matchesKey(data, "enter") || matchesKey(data, "return") || data === "\n") {
|
|
1218
|
+
this.#requestLogin(entry);
|
|
1219
|
+
}
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
this.#browser.handleInput(data);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
#isBrowserView(entry: SidebarEntry): boolean {
|
|
1226
|
+
if (this.#assigning !== null) return true;
|
|
1227
|
+
return entry.kind === "recent" || entry.kind === "all" || (entry.kind === "provider" && !entry.locked);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
#handleStripInput(data: string): void {
|
|
1231
|
+
const strip = this.#strip;
|
|
1232
|
+
if (!strip) return;
|
|
1233
|
+
if (matchesSelectCancel(data)) {
|
|
1234
|
+
this.#closeStrip();
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
if (strip.kind === "roleName") {
|
|
1238
|
+
if (matchesKey(data, "enter") || matchesKey(data, "return") || data === "\n") {
|
|
1239
|
+
this.#submitRoleName();
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
strip.input.handleInput(data);
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
if (matchesKey(data, "left") || matchesKey(data, "up") || matchesKey(data, "shift+tab")) {
|
|
1246
|
+
strip.index = (strip.index - 1 + strip.chips.length) % strip.chips.length;
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1249
|
+
if (matchesKey(data, "right") || matchesKey(data, "down") || matchesKey(data, "tab")) {
|
|
1250
|
+
strip.index = (strip.index + 1) % strip.chips.length;
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
if (matchesKey(data, "enter") || matchesKey(data, "return") || data === "\n") {
|
|
1254
|
+
this.#activateStripChip();
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
#moveSidebar(delta: number): void {
|
|
1260
|
+
const count = this.#entries.length;
|
|
1261
|
+
if (count === 0) return;
|
|
1262
|
+
let index = this.#entries.findIndex(entry => entry.id === this.#activeEntryId);
|
|
1263
|
+
if (index < 0) index = 0;
|
|
1264
|
+
for (let step = 0; step < count; step++) {
|
|
1265
|
+
index = (index + delta + count) % count;
|
|
1266
|
+
const entry = this.#entries[index];
|
|
1267
|
+
if (entry && !this.#isHopSkipped(entry)) {
|
|
1268
|
+
// Scope changes keep an active assignment (scoping helps find the
|
|
1269
|
+
// model); landing on the Roles view cancels it.
|
|
1270
|
+
if (entry.kind === "roles") this.#assigning = null;
|
|
1271
|
+
this.#setActiveEntry(entry.id);
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/** Row count of the roles view (roles, their fallback entries, and the trailing "+ New role…" row). */
|
|
1278
|
+
get #rolesRowCount(): number {
|
|
1279
|
+
return this.#rolesRows.length;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/** Enter/click activation for a Roles-view row. */
|
|
1283
|
+
#activateRolesRow(row: RolesRow): void {
|
|
1284
|
+
switch (row.kind) {
|
|
1285
|
+
case "role":
|
|
1286
|
+
this.#startAssign(row.role);
|
|
1287
|
+
return;
|
|
1288
|
+
case "chainKey":
|
|
1289
|
+
this.#startAssignFallback(row.role, null);
|
|
1290
|
+
return;
|
|
1291
|
+
case "fallback":
|
|
1292
|
+
this.#startAssignFallback(row.role, row.chainIndex);
|
|
1293
|
+
return;
|
|
1294
|
+
case "newFallback":
|
|
1295
|
+
this.#startAssignFallbackKey();
|
|
1296
|
+
return;
|
|
1297
|
+
case "newRole":
|
|
1298
|
+
this.#openRoleNameStrip();
|
|
1299
|
+
return;
|
|
1300
|
+
case "separator":
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
/** Step the roles cursor by one row, skipping separator rows. Wraps at the ends unless `wrap: false` (then the cursor stays put). */
|
|
1306
|
+
#stepRoleIndex(from: number, delta: -1 | 1, options: { wrap?: boolean } = {}): number {
|
|
1307
|
+
const wrap = options.wrap ?? true;
|
|
1308
|
+
const count = this.#rolesRows.length;
|
|
1309
|
+
if (count === 0) return 0;
|
|
1310
|
+
let index = from;
|
|
1311
|
+
for (let i = 0; i < count; i++) {
|
|
1312
|
+
const next = index + delta;
|
|
1313
|
+
if (next < 0 || next >= count) {
|
|
1314
|
+
if (!wrap) return from;
|
|
1315
|
+
index = (next + count) % count;
|
|
1316
|
+
} else {
|
|
1317
|
+
index = next;
|
|
1318
|
+
}
|
|
1319
|
+
if (this.#rolesRows[index]?.kind !== "separator") return index;
|
|
1320
|
+
}
|
|
1321
|
+
return from;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
#handleRolesViewInput(data: string): void {
|
|
1325
|
+
// Scope focus treats the roles view as a preview: Enter/Space dives
|
|
1326
|
+
// into the rows, everything else is inert (arrows already hop).
|
|
1327
|
+
if (this.#focus === "scope") {
|
|
1328
|
+
if (matchesKey(data, "enter") || matchesKey(data, "return") || data === "\n" || matchesKey(data, "space")) {
|
|
1329
|
+
this.#focus = "list";
|
|
1330
|
+
}
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
if (matchesSelectUp(data)) {
|
|
1334
|
+
this.#roleIndex = this.#stepRoleIndex(this.#roleIndex, -1);
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
if (matchesSelectDown(data)) {
|
|
1338
|
+
this.#roleIndex = this.#stepRoleIndex(this.#roleIndex, 1);
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
const row = this.#rolesRows[this.#roleIndex];
|
|
1342
|
+
const role = row?.kind === "role" ? row.role : undefined;
|
|
1343
|
+
if (matchesKey(data, "enter") || matchesKey(data, "return") || data === "\n") {
|
|
1344
|
+
if (row) this.#activateRolesRow(row);
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
if (matchesKey(data, "backspace") || matchesKey(data, "delete")) {
|
|
1348
|
+
if (role) this.#unassignRole(role);
|
|
1349
|
+
else if (row?.kind === "fallback") this.#removeFallback(row);
|
|
1350
|
+
else if (row?.kind === "chainKey") this.#setFallbackChain(row.role, []);
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
// Reordering: [ / shift+↑ moves the row earlier, ] / shift+↓ later —
|
|
1354
|
+
// cycle order on a role row, chain order on a fallback row.
|
|
1355
|
+
if (matchesKey(data, "shift+up")) {
|
|
1356
|
+
if (role) this.#moveCycleMembership(role, -1);
|
|
1357
|
+
else if (row?.kind === "fallback") this.#moveFallback(row, -1);
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
if (matchesKey(data, "shift+down")) {
|
|
1361
|
+
if (role) this.#moveCycleMembership(role, 1);
|
|
1362
|
+
else if (row?.kind === "fallback") this.#moveFallback(row, 1);
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
const printable = extractPrintableText(data);
|
|
1366
|
+
if (printable === "x") {
|
|
1367
|
+
if (role) this.#unassignRole(role);
|
|
1368
|
+
else if (row?.kind === "fallback") this.#removeFallback(row);
|
|
1369
|
+
else if (row?.kind === "chainKey") this.#setFallbackChain(row.role, []);
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
if (printable === "f") {
|
|
1373
|
+
if (row?.kind === "newFallback") this.#startAssignFallbackKey();
|
|
1374
|
+
else if (row && row.kind !== "newRole" && row.kind !== "separator") {
|
|
1375
|
+
this.#startAssignFallback(row.role, null);
|
|
1376
|
+
}
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
if (printable === "c") {
|
|
1380
|
+
if (role) this.#toggleCycleMembership(role);
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
if (printable === "[") {
|
|
1384
|
+
if (role) this.#moveCycleMembership(role, -1);
|
|
1385
|
+
else if (row?.kind === "fallback") this.#moveFallback(row, -1);
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
if (printable === "]") {
|
|
1389
|
+
if (role) this.#moveCycleMembership(role, 1);
|
|
1390
|
+
else if (row?.kind === "fallback") this.#moveFallback(row, 1);
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
if (printable === "n") {
|
|
1394
|
+
this.#openRoleNameStrip();
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1397
|
+
if (printable === "t") {
|
|
1398
|
+
const assignment = role ? this.#roles[role] : undefined;
|
|
1399
|
+
if (role && assignment) {
|
|
1400
|
+
const source =
|
|
1401
|
+
this.#settings.get("modelRoleStorage") === "project"
|
|
1402
|
+
? this.#settings.getModelRoleSource(role)
|
|
1403
|
+
: "default";
|
|
1404
|
+
const scope = source === "project" || source === "global" ? source : undefined;
|
|
1405
|
+
const scopedModel = scope ? this.#roleForScope(role, scope).model : assignment.model;
|
|
1406
|
+
if (!scopedModel) return;
|
|
1407
|
+
const item: ModelBrowserItem = {
|
|
1408
|
+
provider: scopedModel.provider,
|
|
1409
|
+
id: scopedModel.id,
|
|
1410
|
+
model: scopedModel,
|
|
1411
|
+
selector: `${scopedModel.provider}/${scopedModel.id}`,
|
|
1412
|
+
};
|
|
1413
|
+
this.#openThinkingStrip(item, role, true, scope);
|
|
1414
|
+
}
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
#requestLogin(entry: SidebarEntry): void {
|
|
1420
|
+
if (!entry.providerId) return;
|
|
1421
|
+
if (entry.oauth) {
|
|
1422
|
+
this.#callbacks.onLoginRequest?.(entry.providerId);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1427
|
+
// Mouse
|
|
1428
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1429
|
+
|
|
1430
|
+
#routeMouseEvent(event: SgrMouseEvent): boolean {
|
|
1431
|
+
const contentLine = event.row - this.#contentRowStart;
|
|
1432
|
+
const overContent = contentLine >= 0 && contentLine < this.#contentRowCount;
|
|
1433
|
+
const sidebarColStart = 2;
|
|
1434
|
+
const sidebarColEnd = sidebarColStart + this.#sidebarWidthLast;
|
|
1435
|
+
const bodyColStart = this.#sidebarWidthLast + 5;
|
|
1436
|
+
const overSidebar = overContent && event.col >= 0 && event.col < sidebarColEnd;
|
|
1437
|
+
const overBody = overContent && event.col >= bodyColStart;
|
|
1438
|
+
const bodyLine = contentLine - 1; // body row 0 is the status row
|
|
1439
|
+
const entry = this.#activeEntry();
|
|
1440
|
+
|
|
1441
|
+
// Footer strip chips.
|
|
1442
|
+
if (event.row === this.#footerRow && this.#strip) {
|
|
1443
|
+
const strip = this.#strip;
|
|
1444
|
+
if (event.leftClick && strip.kind !== "roleName") {
|
|
1445
|
+
for (const range of this.#chipRanges) {
|
|
1446
|
+
if (event.col >= range.start && event.col < range.end) {
|
|
1447
|
+
strip.index = range.index;
|
|
1448
|
+
this.#activateStripChip();
|
|
1449
|
+
return true;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
return true;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
if (event.wheel !== null) {
|
|
1457
|
+
if (overSidebar) {
|
|
1458
|
+
// Wheel pans the sidebar viewport; picking a scope is click/keys only.
|
|
1459
|
+
const maxScroll = Math.max(0, this.#entries.length - this.#contentRowCount);
|
|
1460
|
+
this.#sidebarScroll = Math.max(0, Math.min(this.#sidebarScroll + event.wheel, maxScroll));
|
|
1461
|
+
this.#sidebarHover = this.#sidebarEntryIndexAt(contentLine);
|
|
1462
|
+
} else if (overBody) {
|
|
1463
|
+
if (entry.kind === "roles" && this.#assigning === null) {
|
|
1464
|
+
this.#roleIndex = this.#stepRoleIndex(this.#roleIndex, event.wheel > 0 ? 1 : -1, { wrap: false });
|
|
1465
|
+
} else if (this.#isBrowserView(entry)) {
|
|
1466
|
+
this.#browser.routeMouse(event, bodyLine);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
return true;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
if (event.motion) {
|
|
1473
|
+
this.#sidebarHover = overSidebar ? this.#sidebarEntryIndexAt(contentLine) : null;
|
|
1474
|
+
if (overBody && entry.kind === "roles" && this.#assigning === null) {
|
|
1475
|
+
const roleLine = bodyLine - this.#rolesRowStart;
|
|
1476
|
+
this.#roleHover = roleLine >= 0 && roleLine < this.#rolesRowCount ? roleLine : null;
|
|
1477
|
+
} else {
|
|
1478
|
+
this.#roleHover = null;
|
|
1479
|
+
if (overBody && this.#isBrowserView(entry)) {
|
|
1480
|
+
this.#browser.routeMouse(event, bodyLine);
|
|
1481
|
+
} else {
|
|
1482
|
+
// Pointer left the browser pane: without this, the last
|
|
1483
|
+
// hovered row keeps its band while the sidebar hovers too.
|
|
1484
|
+
this.#browser.clearHover();
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
return true;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
if (!event.leftClick) return true;
|
|
1491
|
+
|
|
1492
|
+
if (overSidebar) {
|
|
1493
|
+
const index = this.#sidebarEntryIndexAt(contentLine);
|
|
1494
|
+
const clicked = index !== null ? this.#entries[index] : undefined;
|
|
1495
|
+
if (clicked && clicked.kind !== "separator") {
|
|
1496
|
+
const already = clicked.id === this.#activeEntryId;
|
|
1497
|
+
if (clicked.kind === "roles") this.#assigning = null;
|
|
1498
|
+
this.#setActiveEntry(clicked.id);
|
|
1499
|
+
// A click on Roles is a deliberate dive into the rows.
|
|
1500
|
+
if (clicked.kind === "roles") this.#focus = "list";
|
|
1501
|
+
if (already && clicked.kind === "provider" && clicked.locked) {
|
|
1502
|
+
this.#requestLogin(clicked);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
return true;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
if (overBody) {
|
|
1509
|
+
if (entry.kind === "roles" && this.#assigning === null) {
|
|
1510
|
+
this.#focus = "list";
|
|
1511
|
+
const roleLine = bodyLine - this.#rolesRowStart;
|
|
1512
|
+
if (roleLine >= 0 && roleLine < this.#rolesRowCount) {
|
|
1513
|
+
const rowDef = this.#rolesRows[roleLine];
|
|
1514
|
+
if (rowDef && rowDef.kind !== "separator") {
|
|
1515
|
+
if (roleLine === this.#roleIndex) {
|
|
1516
|
+
this.#activateRolesRow(rowDef);
|
|
1517
|
+
} else {
|
|
1518
|
+
this.#roleIndex = roleLine;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
} else if (entry.kind === "provider" && entry.locked && this.#assigning === null) {
|
|
1523
|
+
if (this.#lockedLoginLine !== null && bodyLine === this.#lockedLoginLine) {
|
|
1524
|
+
this.#requestLogin(entry);
|
|
1525
|
+
}
|
|
1526
|
+
} else if (this.#isBrowserView(entry)) {
|
|
1527
|
+
this.#browser.routeMouse(event, bodyLine);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return true;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
/** Map a content-line index to a sidebar entry index (accounting for scroll). */
|
|
1534
|
+
#sidebarEntryIndexAt(contentLine: number): number | null {
|
|
1535
|
+
const index = this.#sidebarScroll + contentLine;
|
|
1536
|
+
if (index < 0 || index >= this.#entries.length) return null;
|
|
1537
|
+
return index;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1541
|
+
// Rendering
|
|
1542
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
1543
|
+
|
|
1544
|
+
#sidebarWidth(): number {
|
|
1545
|
+
let longest = 0;
|
|
1546
|
+
for (const entry of this.#entries) {
|
|
1547
|
+
const annotation = entry.annotation ?? "";
|
|
1548
|
+
longest = Math.max(longest, visibleWidth(entry.label) + visibleWidth(annotation) + 5);
|
|
1549
|
+
}
|
|
1550
|
+
return Math.max(SIDEBAR_MIN_WIDTH, Math.min(SIDEBAR_MAX_WIDTH, longest));
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
#renderSidebar(width: number, rows: number): string[] {
|
|
1554
|
+
// The scroll offset is persistent: the wheel pans it freely. Only an
|
|
1555
|
+
// activation (keys, click, programmatic) snaps the viewport to the
|
|
1556
|
+
// active entry, and only far enough to reveal it.
|
|
1557
|
+
if (this.#sidebarFollowActive) {
|
|
1558
|
+
const activeIndex = Math.max(
|
|
1559
|
+
0,
|
|
1560
|
+
this.#entries.findIndex(entry => entry.id === this.#activeEntryId),
|
|
1561
|
+
);
|
|
1562
|
+
if (activeIndex < this.#sidebarScroll) {
|
|
1563
|
+
this.#sidebarScroll = activeIndex;
|
|
1564
|
+
} else if (activeIndex >= this.#sidebarScroll + rows) {
|
|
1565
|
+
this.#sidebarScroll = activeIndex - rows + 1;
|
|
1566
|
+
}
|
|
1567
|
+
this.#sidebarFollowActive = false;
|
|
1568
|
+
}
|
|
1569
|
+
this.#sidebarScroll = Math.max(0, Math.min(this.#sidebarScroll, Math.max(0, this.#entries.length - rows)));
|
|
1570
|
+
|
|
1571
|
+
const lines: string[] = [];
|
|
1572
|
+
for (let i = this.#sidebarScroll; i < Math.min(this.#entries.length, this.#sidebarScroll + rows); i++) {
|
|
1573
|
+
const entry = this.#entries[i];
|
|
1574
|
+
if (!entry) continue;
|
|
1575
|
+
if (entry.kind === "separator") {
|
|
1576
|
+
lines.push(theme.fg("border", "─".repeat(width)));
|
|
1577
|
+
continue;
|
|
1578
|
+
}
|
|
1579
|
+
const active = entry.id === this.#activeEntryId;
|
|
1580
|
+
const hovered = i === this.#sidebarHover;
|
|
1581
|
+
const searching = this.#searchCounts !== null;
|
|
1582
|
+
let matchCount: number | undefined;
|
|
1583
|
+
if (searching) {
|
|
1584
|
+
if (entry.kind === "provider" && !entry.locked) {
|
|
1585
|
+
matchCount = this.#searchCounts?.get(entry.providerId ?? "") ?? 0;
|
|
1586
|
+
} else if (entry.kind === "recent") {
|
|
1587
|
+
matchCount = this.#recentSearchCount;
|
|
1588
|
+
} else if (entry.kind === "all") {
|
|
1589
|
+
matchCount = this.#searchTotal;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
// While searching, entries the hop skips gray out: locked and
|
|
1593
|
+
// zero-match providers, an empty Recent, and the Roles view.
|
|
1594
|
+
const muted = entry.locked || matchCount === 0 || (searching && entry.kind === "roles");
|
|
1595
|
+
// The sidebar's active entry is state, not a cursor: accent label
|
|
1596
|
+
// plus a cursor glyph while the sidebar owns the arrows. The band
|
|
1597
|
+
// stays in the body pane so the two never look alike.
|
|
1598
|
+
const cursor = active && this.#focus === "scope" ? theme.fg("accent", theme.nav.cursor) : " ";
|
|
1599
|
+
|
|
1600
|
+
let icon: string;
|
|
1601
|
+
if (entry.kind === "recent") {
|
|
1602
|
+
icon = theme.icon.time;
|
|
1603
|
+
} else if (entry.kind === "roles") {
|
|
1604
|
+
icon = theme.icon.extensionSkill;
|
|
1605
|
+
} else if (entry.kind === "all") {
|
|
1606
|
+
icon = theme.icon.model;
|
|
1607
|
+
} else {
|
|
1608
|
+
icon = muted ? theme.status.shadowed : theme.status.enabled;
|
|
1609
|
+
}
|
|
1610
|
+
const labelStyled = muted
|
|
1611
|
+
? theme.fg("dim", entry.label)
|
|
1612
|
+
: active
|
|
1613
|
+
? theme.bold(theme.fg("accent", entry.label))
|
|
1614
|
+
: entry.label;
|
|
1615
|
+
|
|
1616
|
+
const refreshing = entry.providerId ? this.#refreshingProviders.has(entry.providerId) : false;
|
|
1617
|
+
const annotationText = matchCount !== undefined ? String(matchCount) : (entry.annotation ?? "");
|
|
1618
|
+
const annotationStyled = refreshing
|
|
1619
|
+
? theme.fg("warning", theme.spinnerFrames[this.#refreshSpinnerFrame % theme.spinnerFrames.length] ?? "")
|
|
1620
|
+
: theme.fg("dim", annotationText);
|
|
1621
|
+
|
|
1622
|
+
const left = `${cursor} ${muted ? theme.fg("dim", icon) : theme.fg(entry.kind === "provider" ? "success" : "accent", icon)} ${labelStyled}`;
|
|
1623
|
+
const leftWidth = visibleWidth(left);
|
|
1624
|
+
const annWidth = visibleWidth(annotationStyled);
|
|
1625
|
+
let line: string;
|
|
1626
|
+
if (leftWidth + annWidth + 1 <= width) {
|
|
1627
|
+
line = `${left}${" ".repeat(width - leftWidth - annWidth)}${annotationStyled}`;
|
|
1628
|
+
} else {
|
|
1629
|
+
line = truncateToWidth(left, width);
|
|
1630
|
+
const lineWidth = visibleWidth(line);
|
|
1631
|
+
if (lineWidth < width) line += " ".repeat(width - lineWidth);
|
|
1632
|
+
}
|
|
1633
|
+
if (hovered) {
|
|
1634
|
+
line = theme.bg("selectedBg", line);
|
|
1635
|
+
}
|
|
1636
|
+
lines.push(line);
|
|
1637
|
+
}
|
|
1638
|
+
return lines;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
#statusRow(width: number): string {
|
|
1642
|
+
if (this.#assigning !== null) {
|
|
1643
|
+
if (this.#assigning.kind === "fallbackKey") {
|
|
1644
|
+
return truncateToWidth(
|
|
1645
|
+
theme.fg("accent", " New fallback chain — Enter picks the model it protects, Esc cancels"),
|
|
1646
|
+
width,
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
const info = getRoleInfo(this.#assigning.role, this.#settings);
|
|
1650
|
+
const label = info.tag ?? info.name ?? this.#assigning.role;
|
|
1651
|
+
if (this.#assigning.kind === "fallback") {
|
|
1652
|
+
const verb = this.#assigning.index === null ? "Adding fallback for" : "Replacing fallback of";
|
|
1653
|
+
return truncateToWidth(
|
|
1654
|
+
theme.fg("accent", ` ${verb} ${theme.bold(label)} — Enter picks the fallback model, Esc cancels`),
|
|
1655
|
+
width,
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
return truncateToWidth(
|
|
1659
|
+
theme.fg("accent", ` Assigning ${theme.bold(label)} — Enter assigns, Esc cancels`),
|
|
1660
|
+
width,
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
const entry = this.#activeEntry();
|
|
1664
|
+
const scopedSuffix = this.#scopedModels.length > 0 ? " · --models scope" : "";
|
|
1665
|
+
let text: string;
|
|
1666
|
+
switch (entry.kind) {
|
|
1667
|
+
case "recent":
|
|
1668
|
+
text = `Recently used models${scopedSuffix}`;
|
|
1669
|
+
break;
|
|
1670
|
+
case "roles":
|
|
1671
|
+
text = "Model roles — f adds a retry fallback, cleared roles fall back to auto-selection";
|
|
1672
|
+
break;
|
|
1673
|
+
case "provider":
|
|
1674
|
+
if (entry.locked) {
|
|
1675
|
+
text = `${entry.label} · not configured`;
|
|
1676
|
+
} else if (entry.providerId && this.#refreshingProviders.has(entry.providerId)) {
|
|
1677
|
+
text = `${entry.label} · refreshing model list…`;
|
|
1678
|
+
} else {
|
|
1679
|
+
text = `${entry.label} · ${entry.annotation ?? "0"} models${scopedSuffix}`;
|
|
1680
|
+
}
|
|
1681
|
+
break;
|
|
1682
|
+
default:
|
|
1683
|
+
text = `All available models${scopedSuffix}`;
|
|
1684
|
+
break;
|
|
1685
|
+
}
|
|
1686
|
+
if (this.#configError && entry.kind !== "provider") {
|
|
1687
|
+
text = this.#configError;
|
|
1688
|
+
return truncateToWidth(theme.fg("error", ` ${text}`), width);
|
|
1689
|
+
}
|
|
1690
|
+
return truncateToWidth(theme.fg("muted", ` ${text}`), width);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
/** Clamp a roles row to `width`; the bg band is reserved for mouse hover. */
|
|
1694
|
+
#finishRolesRow(line: string, width: number, hovered: boolean): string {
|
|
1695
|
+
let out = truncateToWidth(line, width);
|
|
1696
|
+
if (hovered) {
|
|
1697
|
+
const w = visibleWidth(out);
|
|
1698
|
+
if (w < width) out += " ".repeat(width - w);
|
|
1699
|
+
return theme.bg("selectedBg", out);
|
|
1700
|
+
}
|
|
1701
|
+
return out;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
#renderRolesView(width: number, rows: number): string[] {
|
|
1705
|
+
const lines: string[] = [];
|
|
1706
|
+
lines.push("");
|
|
1707
|
+
// First row's offset in bodyLine coordinates: the mouse router's
|
|
1708
|
+
// `bodyLine` has already dropped the status row, so this is just the
|
|
1709
|
+
// leading blank line — no extra status-row offset here.
|
|
1710
|
+
this.#rolesRowStart = lines.length;
|
|
1711
|
+
|
|
1712
|
+
let tagWidth = 0;
|
|
1713
|
+
for (const rowDef of this.#rolesRows) {
|
|
1714
|
+
if (rowDef.kind !== "role") continue;
|
|
1715
|
+
const info = getRoleInfo(rowDef.role, this.#settings);
|
|
1716
|
+
tagWidth = Math.max(tagWidth, visibleWidth(info.tag ?? info.name ?? rowDef.role));
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
const cycleOrder = this.#cycleOrder();
|
|
1720
|
+
const listFocused = this.#focus === "list";
|
|
1721
|
+
for (let i = 0; i < this.#rolesRows.length && lines.length < rows - 2; i++) {
|
|
1722
|
+
const rowDef = this.#rolesRows[i];
|
|
1723
|
+
if (!rowDef) continue;
|
|
1724
|
+
const selected = i === this.#roleIndex;
|
|
1725
|
+
const hovered = i === this.#roleHover;
|
|
1726
|
+
// The unfocused pane draws no cursor; accent text still marks the row.
|
|
1727
|
+
const cursor = selected && listFocused ? theme.fg("accent", theme.nav.cursor) : " ";
|
|
1728
|
+
|
|
1729
|
+
if (rowDef.kind === "separator") {
|
|
1730
|
+
lines.push(` ${theme.fg("border", "─".repeat(Math.max(1, width - 6)))}`);
|
|
1731
|
+
continue;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
if (rowDef.kind === "newRole" || rowDef.kind === "newFallback") {
|
|
1735
|
+
const label = rowDef.kind === "newRole" ? "+ New role…" : "+ New fallback…";
|
|
1736
|
+
let line = ` ${cursor} ${theme.fg(selected ? "accent" : "dim", label)}`;
|
|
1737
|
+
line = this.#finishRolesRow(line, width, hovered);
|
|
1738
|
+
lines.push(line);
|
|
1739
|
+
continue;
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
if (rowDef.kind === "chainKey") {
|
|
1743
|
+
const key = rowDef.role;
|
|
1744
|
+
const slash = key.lastIndexOf("/");
|
|
1745
|
+
const tail = key.slice(slash + 1);
|
|
1746
|
+
const keyStyled = theme.fg("dim", key.slice(0, slash + 1)) + (selected ? theme.fg("accent", tail) : tail);
|
|
1747
|
+
let line = ` ${cursor} ${theme.fg("dim", theme.status.shadowed)} ${keyStyled}`;
|
|
1748
|
+
line = this.#finishRolesRow(line, width, hovered);
|
|
1749
|
+
lines.push(line);
|
|
1750
|
+
continue;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
if (rowDef.kind === "fallback") {
|
|
1754
|
+
const branch = theme.fg("dim", `${"".padEnd(tagWidth + 3)}↳`);
|
|
1755
|
+
const selector = selected ? theme.fg("accent", rowDef.selector) : theme.fg("muted", rowDef.selector);
|
|
1756
|
+
let line = ` ${cursor} ${branch} ${selector}`;
|
|
1757
|
+
line = this.#finishRolesRow(line, width, hovered);
|
|
1758
|
+
lines.push(line);
|
|
1759
|
+
continue;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
const role = rowDef.role;
|
|
1763
|
+
const info = getRoleInfo(role, this.#settings);
|
|
1764
|
+
const assignment = this.#roles[role];
|
|
1765
|
+
const tag = (info.tag ?? info.name ?? role).padEnd(tagWidth);
|
|
1766
|
+
|
|
1767
|
+
let dot: string;
|
|
1768
|
+
let tagStyled: string;
|
|
1769
|
+
let value: string;
|
|
1770
|
+
let levelStyled = "";
|
|
1771
|
+
if (assignment && !assignment.autoSelected) {
|
|
1772
|
+
dot = theme.fg(info.color ?? "muted", theme.status.enabled);
|
|
1773
|
+
tagStyled = theme.fg(info.color ?? "muted", tag);
|
|
1774
|
+
value = `${theme.fg("dim", `${assignment.model.provider}/`)}${selected ? theme.fg("accent", assignment.model.id) : assignment.model.id}`;
|
|
1775
|
+
const glyph = thinkingLevelGlyph(assignment.thinkingLevel);
|
|
1776
|
+
const label = getConfiguredThinkingLevelMetadata(assignment.thinkingLevel).label;
|
|
1777
|
+
if (assignment.thinkingLevel !== ThinkingLevel.Inherit) {
|
|
1778
|
+
levelStyled = theme.fg("dim", glyph ? `${glyph} ${label}` : label);
|
|
1779
|
+
}
|
|
1780
|
+
} else if (assignment) {
|
|
1781
|
+
dot = theme.fg("dim", theme.status.shadowed);
|
|
1782
|
+
tagStyled = theme.fg("dim", tag);
|
|
1783
|
+
value = theme.fg("dim", `auto → ${assignment.model.provider}/${assignment.model.id}`);
|
|
1784
|
+
} else {
|
|
1785
|
+
dot = theme.fg("dim", theme.status.shadowed);
|
|
1786
|
+
tagStyled = theme.fg("dim", tag);
|
|
1787
|
+
value = theme.fg("dim", "—");
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
// Quick-cycle membership badge (`⟳2` = second stop of the ctrl+p cycle).
|
|
1791
|
+
const cycleIndex = cycleOrder.indexOf(role);
|
|
1792
|
+
const cycleStyled = cycleIndex >= 0 ? theme.fg("accent", `${theme.icon.loop}${cycleIndex + 1}`) : "";
|
|
1793
|
+
|
|
1794
|
+
let line = ` ${cursor} ${dot} ${tagStyled} ${value}`;
|
|
1795
|
+
const right = [levelStyled, cycleStyled].filter(part => part.length > 0).join(" ");
|
|
1796
|
+
const rightWidth = visibleWidth(right);
|
|
1797
|
+
const lineWidth = visibleWidth(line);
|
|
1798
|
+
if (rightWidth > 0 && lineWidth + rightWidth + 2 <= width) {
|
|
1799
|
+
line = `${line}${" ".repeat(width - lineWidth - rightWidth - 1)}${right}`;
|
|
1800
|
+
}
|
|
1801
|
+
line = this.#finishRolesRow(line, width, hovered);
|
|
1802
|
+
lines.push(line);
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
// Live preview of the quick-switch cycle, rendered with the exact
|
|
1806
|
+
// segment track the ctrl+p status uses; the selected role's chip fills.
|
|
1807
|
+
while (lines.length < rows - 1) lines.push("");
|
|
1808
|
+
if (rows >= 2) {
|
|
1809
|
+
const cycleKey = getKeybindings().getKeys("app.model.cycleForward")[0] ?? "ctrl+p";
|
|
1810
|
+
if (cycleOrder.length > 0) {
|
|
1811
|
+
const selectedRow = this.#rolesRows[this.#roleIndex];
|
|
1812
|
+
const selectedRole =
|
|
1813
|
+
selectedRow && (selectedRow.kind === "role" || selectedRow.kind === "fallback") ? selectedRow.role : "";
|
|
1814
|
+
const activeIndex = cycleOrder.indexOf(selectedRole);
|
|
1815
|
+
const track = renderSegmentTrack(
|
|
1816
|
+
cycleOrder.map(role => ({ label: role })),
|
|
1817
|
+
activeIndex,
|
|
1818
|
+
);
|
|
1819
|
+
lines[rows - 1] = truncateToWidth(` ${theme.fg("dim", `${cycleKey} cycle:`)} ${track}`, width);
|
|
1820
|
+
} else {
|
|
1821
|
+
lines[rows - 1] = truncateToWidth(
|
|
1822
|
+
theme.fg("dim", ` ${cycleKey} cycle is empty — press c on a role to add it`),
|
|
1823
|
+
width,
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
return lines;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
#renderLockedView(entry: SidebarEntry, width: number, rows: number): string[] {
|
|
1831
|
+
const lines: string[] = [];
|
|
1832
|
+
this.#lockedLoginLine = null;
|
|
1833
|
+
lines.push("");
|
|
1834
|
+
lines.push(truncateToWidth(theme.fg("warning", ` ${entry.label} has no credentials configured`), width));
|
|
1835
|
+
lines.push("");
|
|
1836
|
+
const envVars = entry.providerId ? (getCatalogProviderEntry(entry.providerId)?.envVars ?? []) : [];
|
|
1837
|
+
if (envVars.length > 0) {
|
|
1838
|
+
lines.push(
|
|
1839
|
+
truncateToWidth(
|
|
1840
|
+
theme.fg("muted", ` Set ${envVars.join(" or ")} in your environment, or add a key in config.`),
|
|
1841
|
+
width,
|
|
1842
|
+
),
|
|
1843
|
+
);
|
|
1844
|
+
} else {
|
|
1845
|
+
lines.push(truncateToWidth(theme.fg("muted", " Add an API key for this provider in config."), width));
|
|
1846
|
+
}
|
|
1847
|
+
if (entry.oauth) {
|
|
1848
|
+
this.#lockedLoginLine = lines.length + 1; // +1 for the status row offset handled by caller
|
|
1849
|
+
lines.push(truncateToWidth(theme.fg("accent", ` ${theme.nav.cursor} Log in with OAuth (Enter)`), width));
|
|
1850
|
+
}
|
|
1851
|
+
lines.push("");
|
|
1852
|
+
const catalogCount = entry.catalogCount ?? 0;
|
|
1853
|
+
if (catalogCount > 0) {
|
|
1854
|
+
lines.push(truncateToWidth(theme.fg("dim", ` ${catalogCount} models in catalog:`), width));
|
|
1855
|
+
const preview = this.#scopedModels.length > 0 ? [] : this.#registry.getAll();
|
|
1856
|
+
for (const model of preview) {
|
|
1857
|
+
if (model.provider !== entry.providerId) continue;
|
|
1858
|
+
if (lines.length >= rows) break;
|
|
1859
|
+
lines.push(truncateToWidth(theme.fg("dim", ` ${model.id}`), width));
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
while (lines.length < rows) lines.push("");
|
|
1863
|
+
return lines.slice(0, rows);
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
#footerHint(): string {
|
|
1867
|
+
const strip = this.#strip;
|
|
1868
|
+
if (strip) {
|
|
1869
|
+
if (strip.kind === "roleName") {
|
|
1870
|
+
return "Enter create + pick model · Esc cancel";
|
|
1871
|
+
}
|
|
1872
|
+
if (strip.kind === "role") return "←/→ choose · Enter assign/clear · Esc cancel";
|
|
1873
|
+
if (strip.kind === "scope") return "←/→ save scope · Enter choose · Esc cancel";
|
|
1874
|
+
return "←/→ thinking level · Enter apply · Esc keep";
|
|
1875
|
+
}
|
|
1876
|
+
if (this.#assigning !== null) {
|
|
1877
|
+
switch (this.#assigning.kind) {
|
|
1878
|
+
case "fallback":
|
|
1879
|
+
return "Enter pick fallback · ↑/↓ providers · type to search · Esc cancel";
|
|
1880
|
+
case "fallbackKey":
|
|
1881
|
+
return "Enter pick the protected model · ↑/↓ providers · type to search · Esc cancel";
|
|
1882
|
+
default:
|
|
1883
|
+
return "Enter assign · ↑/↓ providers · type to search · Esc cancel";
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
const entry = this.#activeEntry();
|
|
1887
|
+
if (entry.kind === "roles") {
|
|
1888
|
+
if (this.#focus !== "list") {
|
|
1889
|
+
return "↑/↓ providers · → roles · Esc close";
|
|
1890
|
+
}
|
|
1891
|
+
const row = this.#rolesRows[this.#roleIndex];
|
|
1892
|
+
if (row?.kind === "fallback") {
|
|
1893
|
+
return "↑/↓ rows · Enter replace · f add another · x remove · [/] reorder · ← providers";
|
|
1894
|
+
}
|
|
1895
|
+
if (row?.kind === "chainKey") {
|
|
1896
|
+
return "↑/↓ rows · Enter/f add fallback · x clear chain · ← providers";
|
|
1897
|
+
}
|
|
1898
|
+
if (row?.kind === "newFallback") {
|
|
1899
|
+
return "↑/↓ rows · Enter new model/provider fallback chain · ← providers";
|
|
1900
|
+
}
|
|
1901
|
+
return "↑/↓ rows · Enter pick · f fallback · x clear · t thinking · c cycle · [/] reorder · n new";
|
|
1902
|
+
}
|
|
1903
|
+
if (entry.kind === "provider" && entry.locked) {
|
|
1904
|
+
return entry.oauth ? "Enter log in · ↑/↓ providers · Esc close" : "↑/↓ providers · Esc close";
|
|
1905
|
+
}
|
|
1906
|
+
const arrows = this.#focus === "scope" ? "↑/↓ providers · → models" : "↑/↓ models · ← providers";
|
|
1907
|
+
const refresh = entry.kind === "provider" ? " · F5 refresh" : "";
|
|
1908
|
+
return `Enter assign roles · ${arrows} · type to search${refresh} · Esc close`;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
/** Footer row: active strip (chips) or the contextual hint line. */
|
|
1912
|
+
#renderFooter(width: number): string {
|
|
1913
|
+
this.#chipRanges = [];
|
|
1914
|
+
const strip = this.#strip;
|
|
1915
|
+
if (!strip) {
|
|
1916
|
+
return truncateToWidth(theme.fg("dim", this.#footerHint()), width);
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
if (strip.kind === "roleName") {
|
|
1920
|
+
const label = theme.fg("accent", "New role name:");
|
|
1921
|
+
const inputWidth = Math.max(8, Math.min(32, width - visibleWidth("New role name:") - 24));
|
|
1922
|
+
const inputLine = strip.input.render(inputWidth)[0] ?? "";
|
|
1923
|
+
return truncateToWidth(`${label} ${inputLine} ${theme.fg("dim", "(letters, digits, - and _)")}`, width);
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
const prefix =
|
|
1927
|
+
strip.kind === "role"
|
|
1928
|
+
? `${theme.fg("accent", strip.item.id)}${theme.fg("dim", " →")} `
|
|
1929
|
+
: `${theme.fg(getRoleInfo(strip.role ?? "", this.#settings).color ?? "muted", (getRoleInfo(strip.role ?? "", this.#settings).tag ?? strip.role ?? "").toLowerCase())}${theme.fg("dim", ` · ${strip.item.id} →`)} `;
|
|
1930
|
+
|
|
1931
|
+
// Horizontal window: once the strip overflows, drop leading chips behind
|
|
1932
|
+
// a dim ellipsis so the selected chip (plus one chip of lookahead when it
|
|
1933
|
+
// fits) stays visible while cycling right.
|
|
1934
|
+
const prefixWidth = visibleWidth(prefix);
|
|
1935
|
+
const available = Math.max(1, width - prefixWidth);
|
|
1936
|
+
const chipWidths = strip.chips.map(
|
|
1937
|
+
(chip, i) => visibleWidth(` ${chip.styled} `) + (i === strip.index ? 2 : 0) + 1,
|
|
1938
|
+
);
|
|
1939
|
+
// Smallest start index whose window [start..target] (with its "… " lead-in
|
|
1940
|
+
// when start > 0) fits in the available width; `target` itself may still
|
|
1941
|
+
// overflow when a single chip is wider than the row.
|
|
1942
|
+
const startFor = (target: number): number => {
|
|
1943
|
+
let start = 0;
|
|
1944
|
+
while (start < target) {
|
|
1945
|
+
let sum = start > 0 ? 2 : 0;
|
|
1946
|
+
for (let i = start; i <= target; i++) sum += chipWidths[i] ?? 0;
|
|
1947
|
+
if (sum <= available) break;
|
|
1948
|
+
start++;
|
|
1949
|
+
}
|
|
1950
|
+
return start;
|
|
1951
|
+
};
|
|
1952
|
+
let start = startFor(Math.min(strip.index + 1, strip.chips.length - 1));
|
|
1953
|
+
if (start > strip.index) start = startFor(strip.index);
|
|
1954
|
+
|
|
1955
|
+
let line = prefix;
|
|
1956
|
+
// Columns are relative to the frame: row() insets content by 2.
|
|
1957
|
+
let col = 2 + prefixWidth;
|
|
1958
|
+
if (start > 0) {
|
|
1959
|
+
line += theme.fg("dim", "… ");
|
|
1960
|
+
col += 2;
|
|
1961
|
+
}
|
|
1962
|
+
for (let i = start; i < strip.chips.length; i++) {
|
|
1963
|
+
const chip = strip.chips[i];
|
|
1964
|
+
if (!chip) continue;
|
|
1965
|
+
const selected = i === strip.index;
|
|
1966
|
+
const body = ` ${chip.styled} `;
|
|
1967
|
+
const rendered = selected
|
|
1968
|
+
? theme.bg("selectedBg", `${theme.fg("accent", "[")}${body}${theme.fg("accent", "]")}`)
|
|
1969
|
+
: body;
|
|
1970
|
+
const w = visibleWidth(body) + (selected ? 2 : 0);
|
|
1971
|
+
this.#chipRanges.push({ start: col, end: col + w, index: i });
|
|
1972
|
+
line += rendered;
|
|
1973
|
+
col += w;
|
|
1974
|
+
line += " ";
|
|
1975
|
+
col += 1;
|
|
1976
|
+
}
|
|
1977
|
+
return truncateToWidth(line, width);
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
render(width: number): string[] {
|
|
1981
|
+
const height = Math.max(16, this.#tui.terminal?.rows || process.stdout.rows || 40);
|
|
1982
|
+
const sidebarWidth = this.#sidebarWidth();
|
|
1983
|
+
this.#sidebarWidthLast = sidebarWidth;
|
|
1984
|
+
const bodyWidth = splitBodyWidth(width, sidebarWidth);
|
|
1985
|
+
const contentRows = Math.max(10, height - 4);
|
|
1986
|
+
this.#contentRowCount = contentRows;
|
|
1987
|
+
|
|
1988
|
+
const entry = this.#activeEntry();
|
|
1989
|
+
const bodyLines: string[] = [this.#statusRow(bodyWidth)];
|
|
1990
|
+
if (entry.kind === "roles" && this.#assigning === null) {
|
|
1991
|
+
bodyLines.push(...this.#renderRolesView(bodyWidth, contentRows - 1));
|
|
1992
|
+
} else if (entry.kind === "provider" && entry.locked && this.#assigning === null) {
|
|
1993
|
+
bodyLines.push(...this.#renderLockedView(entry, bodyWidth, contentRows - 1));
|
|
1994
|
+
} else {
|
|
1995
|
+
this.#browser.setMaxVisible(contentRows - 1 - 5);
|
|
1996
|
+
this.#browser.setFocused(this.#focus === "list");
|
|
1997
|
+
bodyLines.push(...this.#browser.render(bodyWidth));
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
const sidebarLines = this.#renderSidebar(sidebarWidth, contentRows);
|
|
2001
|
+
|
|
2002
|
+
const out: string[] = [];
|
|
2003
|
+
out.push(topBorderSplit(width, "Models", sidebarWidth));
|
|
2004
|
+
this.#contentRowStart = out.length;
|
|
2005
|
+
for (let i = 0; i < contentRows; i++) {
|
|
2006
|
+
out.push(splitRow(sidebarLines[i] ?? "", bodyLines[i] ?? "", width, sidebarWidth));
|
|
2007
|
+
}
|
|
2008
|
+
out.push(dividerSplit(width, sidebarWidth));
|
|
2009
|
+
this.#footerRow = out.length;
|
|
2010
|
+
out.push(row(this.#renderFooter(width - 4), width));
|
|
2011
|
+
out.push(bottomBorder(width));
|
|
2012
|
+
return out;
|
|
2013
|
+
}
|
|
2014
|
+
}
|