@f5-sales-demo/xcsh 19.51.2
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 +7073 -0
- package/README.md +14 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +109 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/custom-tools/todo/index.ts +206 -0
- package/examples/extensions/README.md +143 -0
- package/examples/extensions/api-demo.ts +89 -0
- package/examples/extensions/chalk-logger.ts +25 -0
- package/examples/extensions/hello.ts +32 -0
- package/examples/extensions/pirate.ts +43 -0
- package/examples/extensions/plan-mode.ts +551 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/todo.ts +296 -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 +16 -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 +43 -0
- package/examples/sdk/04-skills.ts +43 -0
- package/examples/sdk/06-extensions.ts +80 -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/README.md +172 -0
- package/package.json +539 -0
- package/scripts/build-info/resolvers.ts +51 -0
- package/scripts/capture-ax-fixture.ts +84 -0
- package/scripts/capture-login-fixture.ts +30 -0
- package/scripts/check-workflow-field-coverage.ts +101 -0
- package/scripts/extension-uat-harness.ts +340 -0
- package/scripts/format-prompts.ts +68 -0
- package/scripts/generate-api-spec-index.ts +580 -0
- package/scripts/generate-branding-index.ts +81 -0
- package/scripts/generate-build-info.ts +106 -0
- package/scripts/generate-console-catalog.ts +88 -0
- package/scripts/generate-console-field-metadata.ts +74 -0
- package/scripts/generate-docs-index.ts +40 -0
- package/scripts/generate-template.ts +32 -0
- package/scripts/generate-terraform-index.ts +81 -0
- package/scripts/mermaid-gallery.ts +132 -0
- package/scripts/uat-matrix-modalities.ts +451 -0
- package/scripts/uat-matrix-report.ts +175 -0
- package/scripts/uat-matrix.ts +353 -0
- package/src/async/index.ts +2 -0
- package/src/async/job-manager.ts +416 -0
- package/src/async/support.ts +5 -0
- package/src/autoresearch/apply-contract-to-state.ts +1 -0
- package/src/autoresearch/command-resume.md +17 -0
- package/src/autoresearch/contract.ts +205 -0
- package/src/autoresearch/dashboard.ts +374 -0
- package/src/autoresearch/git.ts +191 -0
- package/src/autoresearch/helpers.ts +328 -0
- package/src/autoresearch/index.ts +402 -0
- package/src/autoresearch/prompt.md +236 -0
- package/src/autoresearch/resume-message.md +16 -0
- package/src/autoresearch/state.ts +303 -0
- package/src/autoresearch/tools/init-experiment.ts +400 -0
- package/src/autoresearch/tools/log-experiment.ts +793 -0
- package/src/autoresearch/tools/run-experiment.ts +679 -0
- package/src/autoresearch/types.ts +114 -0
- package/src/browser/acquire.ts +249 -0
- package/src/browser/actions.ts +126 -0
- package/src/browser/auth.ts +176 -0
- package/src/browser/ax.ts +134 -0
- package/src/browser/cdp-core.ts +45 -0
- package/src/browser/cdp-page-actions.ts +51 -0
- package/src/browser/chrome-locate.ts +66 -0
- package/src/browser/dom-context.ts +89 -0
- package/src/browser/dt-context.ts +100 -0
- package/src/browser/extension-bridge.ts +182 -0
- package/src/browser/extension-page-actions.ts +397 -0
- package/src/browser/extension-provider.ts +373 -0
- package/src/browser/index.ts +17 -0
- package/src/browser/input-commit.ts +74 -0
- package/src/browser/native-messaging.ts +20 -0
- package/src/browser/page-actions.ts +18 -0
- package/src/browser/provider.ts +155 -0
- package/src/browser/resolver.ts +126 -0
- package/src/browser/selector.ts +40 -0
- package/src/bun-imports.d.ts +22 -0
- package/src/capability/context-file.ts +43 -0
- package/src/capability/extension-module.ts +34 -0
- package/src/capability/extension.ts +47 -0
- package/src/capability/fs.ts +107 -0
- package/src/capability/hook.ts +40 -0
- package/src/capability/index.ts +438 -0
- package/src/capability/instruction.ts +37 -0
- package/src/capability/mcp.ts +74 -0
- package/src/capability/prompt.ts +35 -0
- package/src/capability/rule.ts +224 -0
- package/src/capability/settings.ts +34 -0
- package/src/capability/skill.ts +50 -0
- package/src/capability/slash-command.ts +40 -0
- package/src/capability/ssh.ts +41 -0
- package/src/capability/system-prompt.ts +34 -0
- package/src/capability/tool.ts +38 -0
- package/src/capability/types.ts +168 -0
- package/src/cli/agents-cli.ts +138 -0
- package/src/cli/args.ts +286 -0
- package/src/cli/chrome-cli.ts +88 -0
- package/src/cli/classify-install-target.ts +50 -0
- package/src/cli/commands/init-xdg.ts +27 -0
- package/src/cli/config-cli.ts +418 -0
- package/src/cli/file-processor.ts +121 -0
- package/src/cli/grep-cli.ts +160 -0
- package/src/cli/grievances-cli.ts +78 -0
- package/src/cli/initial-message.ts +58 -0
- package/src/cli/jupyter-cli.ts +106 -0
- package/src/cli/list-models.ts +128 -0
- package/src/cli/plugin-cli.ts +964 -0
- package/src/cli/read-cli.ts +68 -0
- package/src/cli/session-picker.ts +52 -0
- package/src/cli/setup-cli.ts +479 -0
- package/src/cli/shell-cli.ts +174 -0
- package/src/cli/ssh-cli.ts +179 -0
- package/src/cli/stats-cli.ts +182 -0
- package/src/cli/update-cli.ts +446 -0
- package/src/cli/web-search-cli.ts +203 -0
- package/src/cli.ts +123 -0
- package/src/commands/agents.ts +57 -0
- package/src/commands/chrome-host.ts +71 -0
- package/src/commands/chrome.ts +28 -0
- package/src/commands/commit.ts +36 -0
- package/src/commands/config.ts +51 -0
- package/src/commands/grep.ts +48 -0
- package/src/commands/grievances.ts +20 -0
- package/src/commands/jupyter.ts +32 -0
- package/src/commands/launch.ts +144 -0
- package/src/commands/plugin.ts +78 -0
- package/src/commands/read.ts +33 -0
- package/src/commands/setup.ts +42 -0
- package/src/commands/shell.ts +29 -0
- package/src/commands/ssh.ts +60 -0
- package/src/commands/stats.ts +29 -0
- package/src/commands/update.ts +21 -0
- package/src/commands/web-search.ts +46 -0
- package/src/commit/agentic/agent.ts +314 -0
- package/src/commit/agentic/fallback.ts +96 -0
- package/src/commit/agentic/index.ts +354 -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 +127 -0
- package/src/commit/agentic/tools/git-file-diff.ts +191 -0
- package/src/commit/agentic/tools/git-hunk.ts +50 -0
- package/src/commit/agentic/tools/git-overview.ts +81 -0
- package/src/commit/agentic/tools/index.ts +54 -0
- package/src/commit/agentic/tools/propose-changelog.ts +139 -0
- package/src/commit/agentic/tools/propose-commit.ts +122 -0
- package/src/commit/agentic/tools/recent-commits.ts +81 -0
- package/src/commit/agentic/tools/schemas.ts +31 -0
- package/src/commit/agentic/tools/split-commit.ts +251 -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 +122 -0
- package/src/commit/analysis/index.ts +4 -0
- package/src/commit/analysis/scope.ts +242 -0
- package/src/commit/analysis/summary.ts +105 -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 +108 -0
- package/src/commit/map-reduce/utils.ts +9 -0
- package/src/commit/message.ts +11 -0
- package/src/commit/model-selection.ts +66 -0
- package/src/commit/pipeline.ts +242 -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/types.ts +118 -0
- package/src/commit/utils/exclusions.ts +42 -0
- package/src/commit/utils.ts +44 -0
- package/src/config/auto-config.ts +698 -0
- package/src/config/context-schema.json +115 -0
- package/src/config/file-lock.ts +121 -0
- package/src/config/keybindings.ts +493 -0
- package/src/config/mcp-schema.json +230 -0
- package/src/config/model-equivalence.ts +675 -0
- package/src/config/model-registry.ts +2265 -0
- package/src/config/model-resolver.ts +1289 -0
- package/src/config/prompt-templates.ts +271 -0
- package/src/config/resolve-config-value.ts +110 -0
- package/src/config/settings-schema.ts +2155 -0
- package/src/config/settings.ts +730 -0
- package/src/config.ts +418 -0
- package/src/cursor.ts +323 -0
- package/src/dap/client.ts +674 -0
- package/src/dap/config.ts +150 -0
- package/src/dap/defaults.json +211 -0
- package/src/dap/index.ts +4 -0
- package/src/dap/session.ts +1255 -0
- package/src/dap/types.ts +600 -0
- package/src/debug/index.ts +440 -0
- package/src/debug/log-formatting.ts +58 -0
- package/src/debug/log-viewer.ts +908 -0
- package/src/debug/profiler.ts +158 -0
- package/src/debug/report-bundle.ts +365 -0
- package/src/debug/system-info.ts +107 -0
- package/src/discovery/agents-md.ts +67 -0
- package/src/discovery/agents.ts +219 -0
- package/src/discovery/builtin.ts +851 -0
- package/src/discovery/claude-plugins.ts +297 -0
- package/src/discovery/claude.ts +543 -0
- package/src/discovery/cline.ts +83 -0
- package/src/discovery/codex.ts +535 -0
- package/src/discovery/cursor.ts +220 -0
- package/src/discovery/gemini.ts +396 -0
- package/src/discovery/github.ts +118 -0
- package/src/discovery/helpers.ts +934 -0
- package/src/discovery/index.ts +79 -0
- package/src/discovery/language.ts +46 -0
- package/src/discovery/mcp-json.ts +171 -0
- package/src/discovery/opencode.ts +393 -0
- package/src/discovery/plugin-dir-roots.ts +28 -0
- package/src/discovery/ssh.ts +153 -0
- package/src/discovery/substitute-plugin-root.ts +29 -0
- package/src/discovery/vscode.ts +105 -0
- package/src/discovery/windsurf.ts +147 -0
- package/src/edit/diff.ts +818 -0
- package/src/edit/index.ts +481 -0
- package/src/edit/line-hash.ts +67 -0
- package/src/edit/modes/chunk.ts +762 -0
- package/src/edit/modes/hashline.ts +1366 -0
- package/src/edit/modes/patch.ts +1791 -0
- package/src/edit/modes/replace.ts +1115 -0
- package/src/edit/normalize.ts +375 -0
- package/src/edit/renderer.ts +627 -0
- package/src/exa/factory.ts +61 -0
- package/src/exa/index.ts +27 -0
- package/src/exa/mcp-client.ts +293 -0
- package/src/exa/render.ts +232 -0
- package/src/exa/researcher.ts +47 -0
- package/src/exa/search.ts +86 -0
- package/src/exa/types.ts +166 -0
- package/src/exa/websets.ts +247 -0
- package/src/exec/bash-executor.ts +332 -0
- package/src/exec/exec.ts +53 -0
- package/src/exec/idle-timeout-watchdog.ts +126 -0
- package/src/exec/non-interactive-env.ts +48 -0
- package/src/export/custom-share.ts +65 -0
- package/src/export/html/index.ts +161 -0
- package/src/export/html/template.css +1001 -0
- package/src/export/html/template.generated.ts +2 -0
- package/src/export/html/template.html +46 -0
- package/src/export/html/template.js +1950 -0
- package/src/export/html/template.macro.ts +24 -0
- package/src/export/html/vendor/highlight.min.js +1213 -0
- package/src/export/html/vendor/marked.min.js +6 -0
- package/src/export/ttsr.ts +434 -0
- package/src/extensibility/custom-commands/bundled/ci-green/index.ts +25 -0
- package/src/extensibility/custom-commands/bundled/review/index.ts +456 -0
- package/src/extensibility/custom-commands/index.ts +2 -0
- package/src/extensibility/custom-commands/loader.ts +236 -0
- package/src/extensibility/custom-commands/types.ts +111 -0
- package/src/extensibility/custom-tools/index.ts +7 -0
- package/src/extensibility/custom-tools/loader.ts +238 -0
- package/src/extensibility/custom-tools/types.ts +251 -0
- package/src/extensibility/custom-tools/wrapper.ts +47 -0
- package/src/extensibility/extensions/index.ts +15 -0
- package/src/extensibility/extensions/loader.ts +572 -0
- package/src/extensibility/extensions/runner.ts +848 -0
- package/src/extensibility/extensions/types.ts +1394 -0
- package/src/extensibility/extensions/wrapper.ts +191 -0
- package/src/extensibility/hooks/index.ts +5 -0
- package/src/extensibility/hooks/loader.ts +255 -0
- package/src/extensibility/hooks/runner.ts +425 -0
- package/src/extensibility/hooks/tool-wrapper.ts +108 -0
- package/src/extensibility/hooks/types.ts +826 -0
- package/src/extensibility/plugins/doctor.ts +66 -0
- package/src/extensibility/plugins/git-url.ts +281 -0
- package/src/extensibility/plugins/index.ts +9 -0
- package/src/extensibility/plugins/installer.ts +192 -0
- package/src/extensibility/plugins/loader.ts +267 -0
- package/src/extensibility/plugins/manager.ts +731 -0
- package/src/extensibility/plugins/marketplace/cache.ts +136 -0
- package/src/extensibility/plugins/marketplace/fetcher.ts +318 -0
- package/src/extensibility/plugins/marketplace/index.ts +6 -0
- package/src/extensibility/plugins/marketplace/manager.ts +781 -0
- package/src/extensibility/plugins/marketplace/prerequisites.ts +255 -0
- package/src/extensibility/plugins/marketplace/registry.ts +196 -0
- package/src/extensibility/plugins/marketplace/source-resolver.ts +147 -0
- package/src/extensibility/plugins/marketplace/types.ts +201 -0
- package/src/extensibility/plugins/parser.ts +105 -0
- package/src/extensibility/plugins/types.ts +194 -0
- package/src/extensibility/skills.ts +269 -0
- package/src/extensibility/slash-commands.ts +246 -0
- package/src/extensibility/tool-proxy.ts +25 -0
- package/src/extensibility/utils.ts +38 -0
- package/src/index.ts +61 -0
- package/src/internal-urls/agent-protocol.ts +136 -0
- package/src/internal-urls/api-catalog-resolve.ts +495 -0
- package/src/internal-urls/api-catalog-types.ts +94 -0
- package/src/internal-urls/api-spec-resolve.ts +1036 -0
- package/src/internal-urls/api-spec-types.ts +239 -0
- package/src/internal-urls/artifact-protocol.ts +97 -0
- package/src/internal-urls/branding-index.generated.ts +88 -0
- package/src/internal-urls/build-info-runtime.ts +302 -0
- package/src/internal-urls/build-info.generated.ts +33 -0
- package/src/internal-urls/computer-profile.ts +692 -0
- package/src/internal-urls/console-catalog-types.ts +21 -0
- package/src/internal-urls/console-catalog.generated.ts +532 -0
- package/src/internal-urls/console-field-metadata-types.ts +59 -0
- package/src/internal-urls/console-field-metadata.generated.ts +4841 -0
- package/src/internal-urls/console-resolve.ts +178 -0
- package/src/internal-urls/docs-index.generated.ts +698 -0
- package/src/internal-urls/extension-api.md +147 -0
- package/src/internal-urls/index.ts +46 -0
- package/src/internal-urls/jobs-protocol.ts +119 -0
- package/src/internal-urls/json-query.ts +126 -0
- package/src/internal-urls/local-protocol.ts +206 -0
- package/src/internal-urls/mcp-protocol.ts +156 -0
- package/src/internal-urls/memory-protocol.ts +133 -0
- package/src/internal-urls/parse.ts +72 -0
- package/src/internal-urls/profile-collectors.ts +106 -0
- package/src/internal-urls/router.ts +55 -0
- package/src/internal-urls/rule-protocol.ts +55 -0
- package/src/internal-urls/skill-protocol.ts +111 -0
- package/src/internal-urls/terraform-index.generated.ts +1852 -0
- package/src/internal-urls/terraform-resolve.ts +184 -0
- package/src/internal-urls/terraform-types.ts +45 -0
- package/src/internal-urls/types.ts +52 -0
- package/src/internal-urls/user-profile.ts +363 -0
- package/src/internal-urls/xcsh-protocol.ts +644 -0
- package/src/ipy/cancellation.ts +28 -0
- package/src/ipy/executor.ts +1155 -0
- package/src/ipy/gateway-coordinator.ts +424 -0
- package/src/ipy/kernel.ts +1091 -0
- package/src/ipy/modules.ts +144 -0
- package/src/ipy/prelude.py +849 -0
- package/src/ipy/prelude.ts +3 -0
- package/src/ipy/runtime.ts +221 -0
- package/src/locales/ar.json +512 -0
- package/src/locales/de.json +512 -0
- package/src/locales/en.json +549 -0
- package/src/locales/es.json +512 -0
- package/src/locales/fr.json +512 -0
- package/src/locales/hi.json +512 -0
- package/src/locales/index.ts +29 -0
- package/src/locales/it.json +512 -0
- package/src/locales/ja.json +512 -0
- package/src/locales/ko.json +512 -0
- package/src/locales/pt-br.json +512 -0
- package/src/locales/th.json +512 -0
- package/src/locales/zh-cn.json +512 -0
- package/src/locales/zh-tw.json +512 -0
- package/src/lsp/client.ts +941 -0
- package/src/lsp/clients/biome-client.ts +202 -0
- package/src/lsp/clients/index.ts +50 -0
- package/src/lsp/clients/lsp-linter-client.ts +93 -0
- package/src/lsp/clients/swiftlint-client.ts +120 -0
- package/src/lsp/config.ts +418 -0
- package/src/lsp/defaults.json +999 -0
- package/src/lsp/edits.ts +109 -0
- package/src/lsp/index.ts +1746 -0
- package/src/lsp/lspmux.ts +233 -0
- package/src/lsp/render.ts +692 -0
- package/src/lsp/startup-events.ts +13 -0
- package/src/lsp/types.ts +444 -0
- package/src/lsp/utils.ts +691 -0
- package/src/main.ts +944 -0
- package/src/mcp/client.ts +482 -0
- package/src/mcp/config-writer.ts +225 -0
- package/src/mcp/config.ts +365 -0
- package/src/mcp/discoverable-tool-metadata.ts +202 -0
- package/src/mcp/index.ts +29 -0
- package/src/mcp/json-rpc.ts +84 -0
- package/src/mcp/loader.ts +124 -0
- package/src/mcp/manager.ts +1152 -0
- package/src/mcp/oauth-discovery.ts +349 -0
- package/src/mcp/oauth-flow.ts +387 -0
- package/src/mcp/render.ts +157 -0
- package/src/mcp/smithery-auth.ts +104 -0
- package/src/mcp/smithery-connect.ts +145 -0
- package/src/mcp/smithery-registry.ts +477 -0
- package/src/mcp/tool-bridge.ts +417 -0
- package/src/mcp/tool-cache.ts +117 -0
- package/src/mcp/transports/http.ts +475 -0
- package/src/mcp/transports/index.ts +6 -0
- package/src/mcp/transports/stdio.ts +325 -0
- package/src/mcp/types.ts +423 -0
- package/src/memories/index.ts +1115 -0
- package/src/memories/storage.ts +577 -0
- package/src/modes/acp/acp-agent.ts +1361 -0
- package/src/modes/acp/acp-event-mapper.ts +538 -0
- package/src/modes/acp/acp-mode.ts +15 -0
- package/src/modes/acp/index.ts +2 -0
- package/src/modes/components/agent-dashboard.ts +1124 -0
- package/src/modes/components/assistant-message.ts +213 -0
- package/src/modes/components/bash-execution.ts +345 -0
- package/src/modes/components/bordered-loader.ts +41 -0
- package/src/modes/components/branch-summary-message.ts +45 -0
- package/src/modes/components/btw-panel.ts +103 -0
- package/src/modes/components/compaction-summary-message.ts +51 -0
- package/src/modes/components/context-add-wizard.ts +534 -0
- package/src/modes/components/countdown-timer.ts +75 -0
- package/src/modes/components/custom-editor.ts +238 -0
- package/src/modes/components/custom-message.ts +91 -0
- package/src/modes/components/diff.ts +210 -0
- package/src/modes/components/dynamic-border.ts +25 -0
- package/src/modes/components/extensions/extension-dashboard.ts +326 -0
- package/src/modes/components/extensions/extension-list.ts +492 -0
- package/src/modes/components/extensions/index.ts +9 -0
- package/src/modes/components/extensions/inspector-panel.ts +317 -0
- package/src/modes/components/extensions/state-manager.ts +587 -0
- package/src/modes/components/extensions/types.ts +191 -0
- package/src/modes/components/footer.ts +262 -0
- package/src/modes/components/gutter-block.ts +315 -0
- package/src/modes/components/history-search.ts +158 -0
- package/src/modes/components/hook-editor.ts +151 -0
- package/src/modes/components/hook-input.ts +81 -0
- package/src/modes/components/hook-message.ts +100 -0
- package/src/modes/components/hook-selector.ts +192 -0
- package/src/modes/components/index.ts +36 -0
- package/src/modes/components/keybinding-hints.ts +65 -0
- package/src/modes/components/login-dialog.ts +164 -0
- package/src/modes/components/mcp-add-wizard.ts +1314 -0
- package/src/modes/components/model-selector.ts +946 -0
- package/src/modes/components/oauth-selector.ts +211 -0
- package/src/modes/components/plugin-selector.ts +95 -0
- package/src/modes/components/plugin-settings.ts +477 -0
- package/src/modes/components/plugins/index.ts +5 -0
- package/src/modes/components/plugins/plugin-dashboard.ts +523 -0
- package/src/modes/components/plugins/plugin-inspector-pane.ts +84 -0
- package/src/modes/components/plugins/plugin-list-pane.ts +109 -0
- package/src/modes/components/plugins/state-manager.ts +229 -0
- package/src/modes/components/plugins/types.ts +51 -0
- package/src/modes/components/plugins/utils.ts +6 -0
- package/src/modes/components/python-execution.ts +244 -0
- package/src/modes/components/queue-mode-selector.ts +56 -0
- package/src/modes/components/read-tool-group.ts +137 -0
- package/src/modes/components/session-observer-overlay.ts +483 -0
- package/src/modes/components/session-selector.ts +343 -0
- package/src/modes/components/settings-defs.ts +568 -0
- package/src/modes/components/settings-selector.ts +641 -0
- package/src/modes/components/show-images-selector.ts +45 -0
- package/src/modes/components/skill-message.ts +90 -0
- package/src/modes/components/status-line/context-gradient.ts +64 -0
- package/src/modes/components/status-line/git-utils.ts +42 -0
- package/src/modes/components/status-line/hex-ansi.ts +29 -0
- package/src/modes/components/status-line/index.ts +4 -0
- package/src/modes/components/status-line/presets.ts +174 -0
- package/src/modes/components/status-line/segments.ts +494 -0
- package/src/modes/components/status-line/separators.ts +55 -0
- package/src/modes/components/status-line/token-rate.ts +66 -0
- package/src/modes/components/status-line/types.ts +96 -0
- package/src/modes/components/status-line-segment-editor.ts +361 -0
- package/src/modes/components/status-line.ts +729 -0
- package/src/modes/components/theme-selector.ts +63 -0
- package/src/modes/components/thinking-selector.ts +52 -0
- package/src/modes/components/todo-reminder.ts +54 -0
- package/src/modes/components/tool-execution.ts +781 -0
- package/src/modes/components/tree-selector.ts +908 -0
- package/src/modes/components/ttsr-notification.ts +80 -0
- package/src/modes/components/user-message-selector.ts +141 -0
- package/src/modes/components/user-message.ts +100 -0
- package/src/modes/components/visual-truncate.ts +63 -0
- package/src/modes/components/welcome-checks.ts +313 -0
- package/src/modes/components/welcome.ts +270 -0
- package/src/modes/controllers/btw-controller.ts +193 -0
- package/src/modes/controllers/chord-routing.ts +37 -0
- package/src/modes/controllers/command-controller.ts +1293 -0
- package/src/modes/controllers/context-command-controller.ts +61 -0
- package/src/modes/controllers/event-controller.ts +743 -0
- package/src/modes/controllers/extension-ui-controller.ts +983 -0
- package/src/modes/controllers/input-controller.ts +877 -0
- package/src/modes/controllers/mcp-command-controller.ts +1940 -0
- package/src/modes/controllers/selector-controller.ts +1292 -0
- package/src/modes/controllers/ssh-command-controller.ts +421 -0
- package/src/modes/index.ts +34 -0
- package/src/modes/interactive-mode.ts +1781 -0
- package/src/modes/oauth-manual-input.ts +42 -0
- package/src/modes/print-mode.ts +196 -0
- package/src/modes/prompt-action-autocomplete.ts +231 -0
- package/src/modes/rpc/host-tools.ts +186 -0
- package/src/modes/rpc/rpc-client.ts +762 -0
- package/src/modes/rpc/rpc-mode.ts +877 -0
- package/src/modes/rpc/rpc-types.ts +322 -0
- package/src/modes/session-observer-registry.ts +146 -0
- package/src/modes/shared.ts +30 -0
- package/src/modes/theme/defaults/index.ts +7 -0
- package/src/modes/theme/defaults/xcsh-dark.json +113 -0
- package/src/modes/theme/defaults/xcsh-light.json +115 -0
- package/src/modes/theme/mermaid-cache.ts +151 -0
- package/src/modes/theme/mermaid-palette.ts +39 -0
- package/src/modes/theme/theme-schema.json +553 -0
- package/src/modes/theme/theme.ts +2563 -0
- package/src/modes/types.ts +273 -0
- package/src/modes/utils/hotkeys-markdown.ts +60 -0
- package/src/modes/utils/keybinding-matchers.ts +30 -0
- package/src/modes/utils/read-group-outcome-aggregator.ts +55 -0
- package/src/modes/utils/sanitize-error-message.ts +60 -0
- package/src/modes/utils/tools-markdown.ts +28 -0
- package/src/modes/utils/ui-helpers.ts +734 -0
- package/src/plan-mode/approved-plan.ts +55 -0
- package/src/plan-mode/state.ts +6 -0
- package/src/priority.json +37 -0
- package/src/prompts/agents/designer.md +67 -0
- package/src/prompts/agents/explore.md +61 -0
- package/src/prompts/agents/frontmatter.md +10 -0
- package/src/prompts/agents/init.md +36 -0
- package/src/prompts/agents/librarian.md +121 -0
- package/src/prompts/agents/plan.md +49 -0
- package/src/prompts/agents/reviewer.md +127 -0
- package/src/prompts/agents/task.md +16 -0
- package/src/prompts/ci-green-request.md +35 -0
- package/src/prompts/compaction/branch-summary-context.md +5 -0
- package/src/prompts/compaction/branch-summary-preamble.md +2 -0
- package/src/prompts/compaction/branch-summary.md +30 -0
- package/src/prompts/compaction/compaction-short-summary.md +9 -0
- package/src/prompts/compaction/compaction-summary-context.md +5 -0
- package/src/prompts/compaction/compaction-summary.md +38 -0
- package/src/prompts/compaction/compaction-turn-prefix.md +17 -0
- package/src/prompts/compaction/compaction-update-summary.md +45 -0
- package/src/prompts/memories/consolidation.md +30 -0
- package/src/prompts/memories/read-path.md +11 -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-request.md +70 -0
- package/src/prompts/system/agent-creation-architect.md +65 -0
- package/src/prompts/system/agent-creation-user.md +6 -0
- package/src/prompts/system/auto-handoff-threshold-focus.md +1 -0
- package/src/prompts/system/btw-user.md +8 -0
- package/src/prompts/system/commit-message-system.md +2 -0
- package/src/prompts/system/custom-system-prompt.md +82 -0
- package/src/prompts/system/eager-todo.md +13 -0
- package/src/prompts/system/file-operations.md +10 -0
- package/src/prompts/system/handoff-document.md +48 -0
- package/src/prompts/system/plan-mode-active.md +114 -0
- package/src/prompts/system/plan-mode-approved.md +23 -0
- package/src/prompts/system/plan-mode-reference.md +14 -0
- package/src/prompts/system/plan-mode-subagent.md +34 -0
- package/src/prompts/system/plan-mode-tool-decision-reminder.md +9 -0
- package/src/prompts/system/subagent-submit-reminder.md +7 -0
- package/src/prompts/system/subagent-system-prompt.md +36 -0
- package/src/prompts/system/subagent-user-prompt.md +12 -0
- package/src/prompts/system/summarization-system.md +3 -0
- package/src/prompts/system/system-prompt.md +698 -0
- package/src/prompts/system/title-system.md +2 -0
- package/src/prompts/system/ttsr-interrupt.md +7 -0
- package/src/prompts/system/web-search.md +28 -0
- package/src/prompts/tools/ask.md +28 -0
- package/src/prompts/tools/ast-edit.md +48 -0
- package/src/prompts/tools/ast-grep.md +54 -0
- package/src/prompts/tools/async-result.md +5 -0
- package/src/prompts/tools/bash.md +67 -0
- package/src/prompts/tools/browser.md +26 -0
- package/src/prompts/tools/calculator.md +10 -0
- package/src/prompts/tools/cancel-job.md +5 -0
- package/src/prompts/tools/catalog-workflow-runner.md +13 -0
- package/src/prompts/tools/checkpoint.md +16 -0
- package/src/prompts/tools/chunk-edit.md +279 -0
- package/src/prompts/tools/debug.md +43 -0
- package/src/prompts/tools/display-image.md +23 -0
- package/src/prompts/tools/exit-plan-mode.md +41 -0
- package/src/prompts/tools/find.md +26 -0
- package/src/prompts/tools/gemini-image.md +7 -0
- package/src/prompts/tools/grep.md +29 -0
- package/src/prompts/tools/hashline.md +131 -0
- package/src/prompts/tools/inspect-image-system.md +20 -0
- package/src/prompts/tools/inspect-image.md +32 -0
- package/src/prompts/tools/lsp.md +33 -0
- package/src/prompts/tools/patch.md +77 -0
- package/src/prompts/tools/poll.md +5 -0
- package/src/prompts/tools/python.md +60 -0
- package/src/prompts/tools/read-chunk.md +35 -0
- package/src/prompts/tools/read.md +63 -0
- package/src/prompts/tools/render-mermaid.md +9 -0
- package/src/prompts/tools/replace.md +36 -0
- package/src/prompts/tools/resolve.md +8 -0
- package/src/prompts/tools/rewind.md +13 -0
- package/src/prompts/tools/search-tool-bm25.md +34 -0
- package/src/prompts/tools/ssh.md +44 -0
- package/src/prompts/tools/task-summary.md +28 -0
- package/src/prompts/tools/task.md +131 -0
- package/src/prompts/tools/todo-write.md +89 -0
- package/src/prompts/tools/vim.md +98 -0
- package/src/prompts/tools/web-search.md +10 -0
- package/src/prompts/tools/write.md +14 -0
- package/src/prompts/tools/xcsh-api.md +283 -0
- package/src/resource-management/index.ts +42 -0
- package/src/sdk.ts +2123 -0
- package/src/secrets/index.ts +146 -0
- package/src/secrets/obfuscator.ts +290 -0
- package/src/secrets/regex.ts +21 -0
- package/src/services/context-env.ts +102 -0
- package/src/services/xcsh-api-client.ts +230 -0
- package/src/services/xcsh-context-command.ts +803 -0
- package/src/services/xcsh-context-display.ts +49 -0
- package/src/services/xcsh-context-indicators.ts +17 -0
- package/src/services/xcsh-context-segment.ts +39 -0
- package/src/services/xcsh-context.ts +1410 -0
- package/src/services/xcsh-env.ts +107 -0
- package/src/services/xcsh-knowledge.ts +177 -0
- package/src/services/xcsh-table.ts +164 -0
- package/src/session/agent-session.ts +6690 -0
- package/src/session/agent-storage.ts +451 -0
- package/src/session/artifacts.ts +132 -0
- package/src/session/auth-storage.ts +17 -0
- package/src/session/blob-store.ts +135 -0
- package/src/session/compaction/branch-summarization.ts +322 -0
- package/src/session/compaction/compaction.ts +1388 -0
- package/src/session/compaction/index.ts +7 -0
- package/src/session/compaction/pruning.ts +91 -0
- package/src/session/compaction/utils.ts +184 -0
- package/src/session/history-storage.ts +253 -0
- package/src/session/messages.ts +597 -0
- package/src/session/session-dump-format.ts +203 -0
- package/src/session/session-manager.ts +2816 -0
- package/src/session/session-storage.ts +370 -0
- package/src/session/streaming-output.ts +770 -0
- package/src/session/tool-choice-queue.ts +213 -0
- package/src/slash-commands/builtin-registry.ts +1614 -0
- package/src/slash-commands/export-command.ts +178 -0
- package/src/slash-commands/marketplace-install-parser.ts +99 -0
- package/src/slash-commands/resource-commands.ts +250 -0
- package/src/ssh/config-writer.ts +183 -0
- package/src/ssh/connection-manager.ts +445 -0
- package/src/ssh/ssh-executor.ts +131 -0
- package/src/ssh/sshfs-mount.ts +137 -0
- package/src/ssh/utils.ts +8 -0
- package/src/stt/downloader.ts +71 -0
- package/src/stt/index.ts +3 -0
- package/src/stt/recorder.ts +351 -0
- package/src/stt/setup.ts +52 -0
- package/src/stt/stt-controller.ts +160 -0
- package/src/stt/transcribe.py +70 -0
- package/src/stt/transcriber.ts +91 -0
- package/src/system-prompt.ts +688 -0
- package/src/task/agents.ts +166 -0
- package/src/task/commands.ts +131 -0
- package/src/task/discovery.ts +126 -0
- package/src/task/executor.ts +1324 -0
- package/src/task/index.ts +1197 -0
- package/src/task/isolation-backend.ts +72 -0
- package/src/task/name-generator.ts +1577 -0
- package/src/task/output-manager.ts +107 -0
- package/src/task/parallel.ts +116 -0
- package/src/task/render.ts +1035 -0
- package/src/task/subprocess-tool-registry.ts +88 -0
- package/src/task/template.ts +33 -0
- package/src/task/types.ts +230 -0
- package/src/task/worktree.ts +580 -0
- package/src/task/xcsh-command.ts +26 -0
- package/src/thinking.ts +87 -0
- package/src/tools/action-renderer.ts +198 -0
- package/src/tools/archive-reader.ts +315 -0
- package/src/tools/ask.ts +791 -0
- package/src/tools/ast-edit.ts +492 -0
- package/src/tools/ast-grep.ts +453 -0
- package/src/tools/auto-generated-guard.ts +305 -0
- package/src/tools/bash-interactive.ts +383 -0
- package/src/tools/bash-interceptor.ts +67 -0
- package/src/tools/bash-normalize.ts +107 -0
- package/src/tools/bash-skill-urls.ts +246 -0
- package/src/tools/bash.ts +878 -0
- package/src/tools/browser-renderer.ts +129 -0
- package/src/tools/browser.ts +1366 -0
- package/src/tools/calculator.ts +543 -0
- package/src/tools/cancel-job.ts +100 -0
- package/src/tools/catalog-workflow-runner.ts +718 -0
- package/src/tools/checkpoint.ts +133 -0
- package/src/tools/context.ts +39 -0
- package/src/tools/debug.ts +1004 -0
- package/src/tools/display-image-renderer.ts +96 -0
- package/src/tools/display-image.ts +109 -0
- package/src/tools/exit-plan-mode.ts +101 -0
- package/src/tools/fetch.ts +1462 -0
- package/src/tools/find.ts +437 -0
- package/src/tools/fs-cache-invalidation.ts +33 -0
- package/src/tools/gemini-image.ts +1004 -0
- package/src/tools/grep.ts +705 -0
- package/src/tools/index.ts +442 -0
- package/src/tools/inspect-image-renderer.ts +101 -0
- package/src/tools/inspect-image.ts +176 -0
- package/src/tools/json-tree.ts +266 -0
- package/src/tools/jtd-to-json-schema.ts +199 -0
- package/src/tools/jtd-to-typescript.ts +136 -0
- package/src/tools/jtd-utils.ts +102 -0
- package/src/tools/list-limit.ts +40 -0
- package/src/tools/mermaid-renderer.ts +127 -0
- package/src/tools/notebook.ts +288 -0
- package/src/tools/output-meta.ts +588 -0
- package/src/tools/path-utils.ts +560 -0
- package/src/tools/plan-mode-guard.ts +41 -0
- package/src/tools/poll-tool.ts +177 -0
- package/src/tools/puppeteer/00_stealth_tampering.txt +63 -0
- package/src/tools/puppeteer/01_stealth_activity.txt +20 -0
- package/src/tools/puppeteer/02_stealth_hairline.txt +11 -0
- package/src/tools/puppeteer/03_stealth_botd.txt +384 -0
- package/src/tools/puppeteer/04_stealth_iframe.txt +81 -0
- package/src/tools/puppeteer/05_stealth_webgl.txt +75 -0
- package/src/tools/puppeteer/06_stealth_screen.txt +72 -0
- package/src/tools/puppeteer/07_stealth_fonts.txt +97 -0
- package/src/tools/puppeteer/08_stealth_audio.txt +51 -0
- package/src/tools/puppeteer/09_stealth_locale.txt +46 -0
- package/src/tools/puppeteer/10_stealth_plugins.txt +206 -0
- package/src/tools/puppeteer/11_stealth_hardware.txt +8 -0
- package/src/tools/puppeteer/12_stealth_codecs.txt +40 -0
- package/src/tools/puppeteer/13_stealth_worker.txt +74 -0
- package/src/tools/python.ts +1184 -0
- package/src/tools/read.ts +1591 -0
- package/src/tools/render-mermaid.ts +93 -0
- package/src/tools/render-utils.ts +677 -0
- package/src/tools/renderers.ts +82 -0
- package/src/tools/report-tool-issue.ts +80 -0
- package/src/tools/resolve.ts +196 -0
- package/src/tools/review.ts +238 -0
- package/src/tools/search-tool-bm25.ts +288 -0
- package/src/tools/sqlite-reader.ts +623 -0
- package/src/tools/ssh.ts +322 -0
- package/src/tools/submit-result.ts +229 -0
- package/src/tools/todo-render.ts +33 -0
- package/src/tools/todo-write.ts +440 -0
- package/src/tools/tool-errors.ts +62 -0
- package/src/tools/tool-result.ts +93 -0
- package/src/tools/tool-timeouts.ts +30 -0
- package/src/tools/vim.ts +981 -0
- package/src/tools/write.ts +671 -0
- package/src/tools/xcsh-api-renderer.ts +402 -0
- package/src/tools/xcsh-api.ts +887 -0
- package/src/tui/code-cell.ts +101 -0
- package/src/tui/file-list.ts +47 -0
- package/src/tui/index.ts +11 -0
- package/src/tui/output-block.ts +175 -0
- package/src/tui/status-line.ts +39 -0
- package/src/tui/tree-list.ts +84 -0
- package/src/tui/types.ts +15 -0
- package/src/tui/utils.ts +103 -0
- package/src/utils/changelog.ts +98 -0
- package/src/utils/clipboard.ts +80 -0
- package/src/utils/command-args.ts +76 -0
- package/src/utils/commit-message-generator.ts +137 -0
- package/src/utils/edit-mode.ts +50 -0
- package/src/utils/event-bus.ts +33 -0
- package/src/utils/external-editor.ts +65 -0
- package/src/utils/file-display-mode.ts +37 -0
- package/src/utils/file-mentions.ts +376 -0
- package/src/utils/fuzzy.ts +108 -0
- package/src/utils/git.ts +1495 -0
- package/src/utils/gitstatus.ts +140 -0
- package/src/utils/image-convert.ts +27 -0
- package/src/utils/image-loading.ts +98 -0
- package/src/utils/image-passthrough.ts +118 -0
- package/src/utils/image-resize.ts +272 -0
- package/src/utils/image-viewer.ts +17 -0
- package/src/utils/lang-from-path.ts +239 -0
- package/src/utils/markit.ts +81 -0
- package/src/utils/open.ts +20 -0
- package/src/utils/session-color.ts +55 -0
- package/src/utils/shell-snapshot.ts +188 -0
- package/src/utils/title-generator.ts +193 -0
- package/src/utils/tool-choice.ts +28 -0
- package/src/utils/tools-manager.ts +356 -0
- package/src/vim/buffer.ts +309 -0
- package/src/vim/commands.ts +382 -0
- package/src/vim/engine.ts +2426 -0
- package/src/vim/parser.ts +151 -0
- package/src/vim/render.ts +252 -0
- package/src/vim/types.ts +197 -0
- package/src/web/kagi.ts +174 -0
- package/src/web/parallel.ts +346 -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 +110 -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 +653 -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 +452 -0
- package/src/web/scrapers/gitlab.ts +401 -0
- package/src/web/scrapers/go-pkg.ts +266 -0
- package/src/web/scrapers/hackage.ts +140 -0
- package/src/web/scrapers/hackernews.ts +189 -0
- package/src/web/scrapers/hex.ts +105 -0
- package/src/web/scrapers/huggingface.ts +321 -0
- package/src/web/scrapers/iacr.ts +89 -0
- package/src/web/scrapers/index.ts +252 -0
- package/src/web/scrapers/jetbrains-marketplace.ts +159 -0
- package/src/web/scrapers/lemmy.ts +203 -0
- package/src/web/scrapers/lobsters.ts +175 -0
- package/src/web/scrapers/mastodon.ts +292 -0
- package/src/web/scrapers/maven.ts +138 -0
- package/src/web/scrapers/mdn.ts +169 -0
- package/src/web/scrapers/metacpan.ts +222 -0
- package/src/web/scrapers/musicbrainz.ts +250 -0
- package/src/web/scrapers/npm.ts +98 -0
- package/src/web/scrapers/nuget.ts +183 -0
- package/src/web/scrapers/nvd.ts +222 -0
- package/src/web/scrapers/ollama.ts +239 -0
- package/src/web/scrapers/open-vsx.ts +106 -0
- package/src/web/scrapers/opencorporates.ts +292 -0
- package/src/web/scrapers/openlibrary.ts +336 -0
- package/src/web/scrapers/orcid.ts +286 -0
- package/src/web/scrapers/osv.ts +176 -0
- package/src/web/scrapers/packagist.ts +160 -0
- package/src/web/scrapers/pub-dev.ts +143 -0
- package/src/web/scrapers/pubmed.ts +211 -0
- package/src/web/scrapers/pypi.ts +112 -0
- package/src/web/scrapers/rawg.ts +110 -0
- package/src/web/scrapers/readthedocs.ts +120 -0
- package/src/web/scrapers/reddit.ts +95 -0
- package/src/web/scrapers/repology.ts +251 -0
- package/src/web/scrapers/rfc.ts +201 -0
- package/src/web/scrapers/rubygems.ts +103 -0
- package/src/web/scrapers/searchcode.ts +190 -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 +93 -0
- package/src/web/scrapers/types.ts +267 -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 +313 -0
- package/src/web/search/errors.ts +120 -0
- package/src/web/search/index.ts +346 -0
- package/src/web/search/params.ts +129 -0
- package/src/web/search/provider.ts +97 -0
- package/src/web/search/providers/anthropic.ts +339 -0
- package/src/web/search/providers/base.ts +35 -0
- package/src/web/search/providers/brave.ts +150 -0
- package/src/web/search/providers/codex.ts +402 -0
- package/src/web/search/providers/exa.ts +264 -0
- package/src/web/search/providers/firecrawl.ts +115 -0
- package/src/web/search/providers/gemini.ts +566 -0
- package/src/web/search/providers/jina.ts +99 -0
- package/src/web/search/providers/kagi.ts +70 -0
- package/src/web/search/providers/kimi.ts +157 -0
- package/src/web/search/providers/parallel.ts +63 -0
- package/src/web/search/providers/perplexity.ts +546 -0
- package/src/web/search/providers/synthetic.ts +113 -0
- package/src/web/search/providers/tavily.ts +162 -0
- package/src/web/search/providers/utils.ts +36 -0
- package/src/web/search/providers/zai.ts +311 -0
- package/src/web/search/render.ts +348 -0
- package/src/web/search/types.ts +438 -0
- package/src/web/search/utils.ts +17 -0
|
@@ -0,0 +1,1293 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
getEnvApiKey,
|
|
6
|
+
getProviderDetails,
|
|
7
|
+
type ProviderDetails,
|
|
8
|
+
type ToolCall,
|
|
9
|
+
type UsageLimit,
|
|
10
|
+
type UsageReport,
|
|
11
|
+
} from "@f5xc-salesdemos/pi-ai";
|
|
12
|
+
import { Loader, Markdown, padding, Spacer, Text, visibleWidth } from "@f5xc-salesdemos/pi-tui";
|
|
13
|
+
import { formatDuration, Snowflake, setProjectDir, setShellPwd, t } from "@f5xc-salesdemos/pi-utils";
|
|
14
|
+
import { $ } from "bun";
|
|
15
|
+
import { reset as resetCapabilities } from "../../capability";
|
|
16
|
+
import { clearXcshPluginRootsCache } from "../../discovery/helpers";
|
|
17
|
+
import { loadCustomShare } from "../../export/custom-share";
|
|
18
|
+
import type { CompactOptions } from "../../extensibility/extensions/types";
|
|
19
|
+
import { getGatewayStatus } from "../../ipy/gateway-coordinator";
|
|
20
|
+
import { buildMemoryToolDeveloperInstructions, clearMemoryData, enqueueMemoryConsolidation } from "../../memories";
|
|
21
|
+
import { BashExecutionComponent } from "../../modes/components/bash-execution";
|
|
22
|
+
import { BorderedLoader } from "../../modes/components/bordered-loader";
|
|
23
|
+
import { DynamicBorder } from "../../modes/components/dynamic-border";
|
|
24
|
+
import { createToolGutter } from "../../modes/components/gutter-block";
|
|
25
|
+
import { PythonExecutionComponent } from "../../modes/components/python-execution";
|
|
26
|
+
import { getMarkdownTheme, getSymbolTheme, theme } from "../../modes/theme/theme";
|
|
27
|
+
import type { InteractiveModeContext } from "../../modes/types";
|
|
28
|
+
import { buildHotkeysMarkdown } from "../../modes/utils/hotkeys-markdown";
|
|
29
|
+
import { buildToolsMarkdown } from "../../modes/utils/tools-markdown";
|
|
30
|
+
import type { AsyncJobSnapshotItem } from "../../session/agent-session";
|
|
31
|
+
import type { AuthStorage } from "../../session/auth-storage";
|
|
32
|
+
import { outputMeta } from "../../tools/output-meta";
|
|
33
|
+
import { resolveToCwd, stripOuterDoubleQuotes } from "../../tools/path-utils";
|
|
34
|
+
import { replaceTabs } from "../../tools/render-utils";
|
|
35
|
+
import { getChangelogPath, parseChangelog } from "../../utils/changelog";
|
|
36
|
+
import { copyToClipboard } from "../../utils/clipboard";
|
|
37
|
+
import { openPath } from "../../utils/open";
|
|
38
|
+
import { setSessionTerminalTitle } from "../../utils/title-generator";
|
|
39
|
+
|
|
40
|
+
function showMarkdownPanel(ctx: InteractiveModeContext, title: string, markdown: string): void {
|
|
41
|
+
ctx.chatContainer.addChild(new Spacer(1));
|
|
42
|
+
ctx.chatContainer.addChild(new DynamicBorder());
|
|
43
|
+
ctx.chatContainer.addChild(new Text(theme.bold(theme.fg("contentAccent", title)), 1, 0));
|
|
44
|
+
ctx.chatContainer.addChild(new Spacer(1));
|
|
45
|
+
ctx.chatContainer.addChild(new Markdown(markdown.trim(), 1, 1, getMarkdownTheme()));
|
|
46
|
+
ctx.chatContainer.addChild(new DynamicBorder());
|
|
47
|
+
ctx.ui.requestRender();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class CommandController {
|
|
51
|
+
constructor(private readonly ctx: InteractiveModeContext) {}
|
|
52
|
+
|
|
53
|
+
openInBrowser(urlOrPath: string): void {
|
|
54
|
+
openPath(urlOrPath);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async handleExportCommand(text: string): Promise<void> {
|
|
58
|
+
const parts = text.split(/\s+/);
|
|
59
|
+
const arg = parts.length > 1 ? parts[1] : undefined;
|
|
60
|
+
|
|
61
|
+
if (arg === "--copy" || arg === "clipboard" || arg === "copy") {
|
|
62
|
+
this.ctx.showWarning(t("controller.export.warnings.useDump"));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const filePath = await this.ctx.session.exportToHtml(arg);
|
|
68
|
+
this.ctx.showStatus(t("controller.export.status.exported", { path: filePath }));
|
|
69
|
+
this.openInBrowser(filePath);
|
|
70
|
+
} catch (error: unknown) {
|
|
71
|
+
this.ctx.showError(
|
|
72
|
+
t("controller.export.errors.failed", { message: error instanceof Error ? error.message : "Unknown error" }),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
handleDumpCommand() {
|
|
78
|
+
try {
|
|
79
|
+
const formatted = this.ctx.session.formatSessionAsText();
|
|
80
|
+
if (!formatted) {
|
|
81
|
+
this.ctx.showError(t("controller.dump.errors.noMessages"));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
copyToClipboard(formatted);
|
|
85
|
+
this.ctx.showStatus(t("controller.dump.status.copied"));
|
|
86
|
+
} catch (error: unknown) {
|
|
87
|
+
this.ctx.showError(
|
|
88
|
+
t("controller.dump.errors.failed", { message: error instanceof Error ? error.message : "Unknown error" }),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async handleDebugTranscriptCommand(): Promise<void> {
|
|
94
|
+
try {
|
|
95
|
+
const width = Math.max(1, this.ctx.ui.terminal.columns);
|
|
96
|
+
const renderedLines = this.ctx.chatContainer.render(width).map(line => replaceTabs(Bun.stripANSI(line)));
|
|
97
|
+
const rendered = renderedLines.join("\n").trimEnd();
|
|
98
|
+
if (!rendered) {
|
|
99
|
+
this.ctx.showError(t("controller.debug.errors.noMessages"));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const tmpPath = path.join(os.tmpdir(), `${Snowflake.next()}-tmp.txt`);
|
|
103
|
+
await Bun.write(tmpPath, `${rendered}\n`);
|
|
104
|
+
this.ctx.showStatus(t("controller.debug.status.written", { path: tmpPath }));
|
|
105
|
+
} catch (error: unknown) {
|
|
106
|
+
this.ctx.showError(
|
|
107
|
+
t("controller.debug.errors.failed", { message: error instanceof Error ? error.message : "Unknown error" }),
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async handleShareCommand(): Promise<void> {
|
|
113
|
+
const tmpFile = path.join(os.tmpdir(), `${Snowflake.next()}.html`);
|
|
114
|
+
const cleanupTempFile = async () => {
|
|
115
|
+
try {
|
|
116
|
+
await fs.rm(tmpFile, { force: true });
|
|
117
|
+
} catch {
|
|
118
|
+
// Ignore cleanup errors
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
await this.ctx.session.exportToHtml(tmpFile);
|
|
123
|
+
} catch (error: unknown) {
|
|
124
|
+
this.ctx.showError(
|
|
125
|
+
t("controller.export.errors.failed", { message: error instanceof Error ? error.message : "Unknown error" }),
|
|
126
|
+
);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const customShare = await loadCustomShare();
|
|
132
|
+
if (customShare) {
|
|
133
|
+
const loader = new BorderedLoader(this.ctx.ui, theme, t("controller.share.sharing"));
|
|
134
|
+
this.ctx.editorContainer.clear();
|
|
135
|
+
this.ctx.editorContainer.addChild(loader);
|
|
136
|
+
this.ctx.ui.setFocus(loader);
|
|
137
|
+
this.ctx.ui.requestRender();
|
|
138
|
+
|
|
139
|
+
const restoreEditor = async () => {
|
|
140
|
+
loader.dispose();
|
|
141
|
+
this.ctx.editorContainer.clear();
|
|
142
|
+
this.ctx.editorContainer.addChild(this.ctx.editor);
|
|
143
|
+
this.ctx.ui.setFocus(this.ctx.editor);
|
|
144
|
+
await cleanupTempFile();
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const result = await customShare.fn(tmpFile);
|
|
149
|
+
await restoreEditor();
|
|
150
|
+
|
|
151
|
+
if (typeof result === "string") {
|
|
152
|
+
this.ctx.showStatus(`Share URL: ${result}`);
|
|
153
|
+
this.openInBrowser(result);
|
|
154
|
+
} else if (result) {
|
|
155
|
+
const parts: string[] = [];
|
|
156
|
+
if (result.url) parts.push(`Share URL: ${result.url}`);
|
|
157
|
+
if (result.message) parts.push(result.message);
|
|
158
|
+
if (parts.length > 0) this.ctx.showStatus(parts.join("\n"));
|
|
159
|
+
if (result.url) this.openInBrowser(result.url);
|
|
160
|
+
} else {
|
|
161
|
+
this.ctx.showStatus(t("controller.share.sessionShared"));
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
} catch (err) {
|
|
165
|
+
await restoreEditor();
|
|
166
|
+
this.ctx.showError(
|
|
167
|
+
t("controller.share.customFailed", { message: err instanceof Error ? err.message : String(err) }),
|
|
168
|
+
);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} catch (err) {
|
|
173
|
+
await cleanupTempFile();
|
|
174
|
+
this.ctx.showError(err instanceof Error ? err.message : String(err));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
const authResult = await $`gh auth status`.quiet().nothrow();
|
|
180
|
+
if (authResult.exitCode !== 0) {
|
|
181
|
+
await cleanupTempFile();
|
|
182
|
+
this.ctx.showError(t("controller.share.ghNotLoggedIn"));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
} catch {
|
|
186
|
+
await cleanupTempFile();
|
|
187
|
+
this.ctx.showError(t("controller.share.ghNotInstalled"));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const loader = new BorderedLoader(this.ctx.ui, theme, t("controller.share.creatingGist"));
|
|
192
|
+
this.ctx.editorContainer.clear();
|
|
193
|
+
this.ctx.editorContainer.addChild(loader);
|
|
194
|
+
this.ctx.ui.setFocus(loader);
|
|
195
|
+
this.ctx.ui.requestRender();
|
|
196
|
+
|
|
197
|
+
const restoreEditor = async () => {
|
|
198
|
+
loader.dispose();
|
|
199
|
+
this.ctx.editorContainer.clear();
|
|
200
|
+
this.ctx.editorContainer.addChild(this.ctx.editor);
|
|
201
|
+
this.ctx.ui.setFocus(this.ctx.editor);
|
|
202
|
+
await cleanupTempFile();
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
loader.onAbort = () => {
|
|
206
|
+
void restoreEditor();
|
|
207
|
+
this.ctx.showStatus(t("controller.share.cancelled"));
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
const result = await $`gh gist create --public=false ${tmpFile}`.quiet().nothrow();
|
|
212
|
+
if (loader.signal.aborted) return;
|
|
213
|
+
|
|
214
|
+
await restoreEditor();
|
|
215
|
+
|
|
216
|
+
if (result.exitCode !== 0) {
|
|
217
|
+
const errorMsg = result.stderr.toString("utf-8").trim() || "Unknown error";
|
|
218
|
+
this.ctx.showError(t("controller.share.gistFailed", { message: errorMsg }));
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const gistUrl = result.stdout.toString("utf-8").trim();
|
|
223
|
+
const gistId = gistUrl.split("/").pop();
|
|
224
|
+
if (!gistId) {
|
|
225
|
+
this.ctx.showError(t("controller.share.gistParseFailed"));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const previewUrl = `https://gistpreview.github.io/?${gistId}`;
|
|
230
|
+
this.ctx.showStatus(`Share URL: ${previewUrl}\nGist: ${gistUrl}`);
|
|
231
|
+
this.openInBrowser(previewUrl);
|
|
232
|
+
} catch (error: unknown) {
|
|
233
|
+
if (!loader.signal.aborted) {
|
|
234
|
+
await restoreEditor();
|
|
235
|
+
this.ctx.showError(
|
|
236
|
+
t("controller.share.gistFailed", { message: error instanceof Error ? error.message : "Unknown error" }),
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
handleCopyCommand(sub?: string) {
|
|
243
|
+
switch (sub) {
|
|
244
|
+
case "code":
|
|
245
|
+
return this.#copyCode();
|
|
246
|
+
case "all":
|
|
247
|
+
return this.#copyAllCode();
|
|
248
|
+
case "cmd":
|
|
249
|
+
return this.#copyLastCommand();
|
|
250
|
+
case "last":
|
|
251
|
+
case undefined:
|
|
252
|
+
return this.#copyLastMessage();
|
|
253
|
+
default:
|
|
254
|
+
this.ctx.showError(t("controller.copy.errors.unknownSub", { sub: sub! }));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
#copyLastMessage() {
|
|
259
|
+
const text = this.ctx.session.getLastAssistantText();
|
|
260
|
+
if (!text) {
|
|
261
|
+
this.ctx.showError(t("controller.copy.errors.noMessages"));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
this.#doCopy(text, t("controller.copy.status.lastMessage"));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
#copyCode() {
|
|
268
|
+
const text = this.ctx.session.getLastAssistantText();
|
|
269
|
+
if (!text) {
|
|
270
|
+
this.ctx.showError(t("controller.copy.errors.noMessages"));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const matches = [...text.matchAll(/^```[^\n]*\n([\s\S]*?)^```/gm)];
|
|
274
|
+
const lastMatch = matches.at(-1);
|
|
275
|
+
if (!lastMatch) {
|
|
276
|
+
this.ctx.showWarning(t("controller.copy.warnings.noCodeBlock"));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
this.#doCopy(lastMatch[1].replace(/\n$/, ""), t("controller.copy.status.codeBlock"));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
#copyAllCode() {
|
|
283
|
+
const text = this.ctx.session.getLastAssistantText();
|
|
284
|
+
if (!text) {
|
|
285
|
+
this.ctx.showError(t("controller.copy.errors.noMessages"));
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const matches = [...text.matchAll(/^```[^\n]*\n([\s\S]*?)^```/gm)];
|
|
289
|
+
if (matches.length === 0) {
|
|
290
|
+
this.ctx.showWarning(t("controller.copy.warnings.noCodeBlocks"));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const combined = matches.map(m => m[1].replace(/\n$/, "")).join("\n\n");
|
|
294
|
+
this.#doCopy(combined, t("controller.copy.status.codeBlocks", { count: matches.length }));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
#copyLastCommand() {
|
|
298
|
+
const messages = this.ctx.session.messages;
|
|
299
|
+
// Walk backwards to find the last bash/python tool call
|
|
300
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
301
|
+
const msg = messages[i];
|
|
302
|
+
if (msg.role !== "assistant") continue;
|
|
303
|
+
const toolCalls = msg.content.filter((c): c is ToolCall => c.type === "toolCall");
|
|
304
|
+
for (let j = toolCalls.length - 1; j >= 0; j--) {
|
|
305
|
+
const tc = toolCalls[j];
|
|
306
|
+
if (tc.name === "bash" && typeof tc.arguments.command === "string") {
|
|
307
|
+
this.#doCopy(tc.arguments.command, t("controller.copy.status.bashCommand"));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (tc.name === "python" && typeof tc.arguments.code === "string") {
|
|
311
|
+
this.#doCopy(tc.arguments.code, t("controller.copy.status.pythonCode"));
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
this.ctx.showWarning(t("controller.copy.warnings.noCommand"));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
#doCopy(content: string, label: string) {
|
|
320
|
+
try {
|
|
321
|
+
copyToClipboard(content);
|
|
322
|
+
this.ctx.showStatus(label);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
this.ctx.showError(error instanceof Error ? error.message : String(error));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async handleSessionCommand(): Promise<void> {
|
|
329
|
+
const stats = this.ctx.session.getSessionStats();
|
|
330
|
+
const premiumRequests =
|
|
331
|
+
"premiumRequests" in stats && typeof stats.premiumRequests === "number"
|
|
332
|
+
? stats.premiumRequests
|
|
333
|
+
: this.ctx.session.sessionManager.getUsageStatistics().premiumRequests;
|
|
334
|
+
const normalizedPremiumRequests = Math.round((premiumRequests + Number.EPSILON) * 100) / 100;
|
|
335
|
+
|
|
336
|
+
let info = `${theme.bold(t("controller.session.title"))}\n\n`;
|
|
337
|
+
info += `${theme.fg("dim", t("controller.session.file"))} ${stats.sessionFile ?? t("controller.session.inMemory")}\n`;
|
|
338
|
+
info += `${theme.fg("dim", t("controller.session.id"))} ${stats.sessionId}\n\n`;
|
|
339
|
+
info += `\n${theme.bold(t("controller.session.provider"))}\n`;
|
|
340
|
+
const model = this.ctx.session.model;
|
|
341
|
+
if (!model) {
|
|
342
|
+
info += `${theme.fg("dim", t("controller.session.noModel"))}\n`;
|
|
343
|
+
} else {
|
|
344
|
+
const authMode = resolveProviderAuthMode(this.ctx.session.modelRegistry.authStorage, model.provider);
|
|
345
|
+
const openaiWebsocketSetting = this.ctx.settings.get("providers.openaiWebsockets") ?? "auto";
|
|
346
|
+
const preferOpenAICodexWebsockets =
|
|
347
|
+
openaiWebsocketSetting === "on" ? true : openaiWebsocketSetting === "off" ? false : undefined;
|
|
348
|
+
const providerDetails = getProviderDetails({
|
|
349
|
+
model,
|
|
350
|
+
sessionId: stats.sessionId,
|
|
351
|
+
authMode,
|
|
352
|
+
preferWebsockets: preferOpenAICodexWebsockets,
|
|
353
|
+
providerSessionState: this.ctx.session.providerSessionState,
|
|
354
|
+
});
|
|
355
|
+
info += renderProviderSection(providerDetails, theme);
|
|
356
|
+
}
|
|
357
|
+
info += `\n`;
|
|
358
|
+
info += `${theme.bold(t("controller.session.messages"))}\n`;
|
|
359
|
+
info += `${theme.fg("dim", t("controller.session.user"))} ${stats.userMessages}\n`;
|
|
360
|
+
info += `${theme.fg("dim", t("controller.session.assistant"))} ${stats.assistantMessages}\n`;
|
|
361
|
+
info += `${theme.fg("dim", t("controller.session.toolCalls"))} ${stats.toolCalls}\n`;
|
|
362
|
+
info += `${theme.fg("dim", t("controller.session.toolResults"))} ${stats.toolResults}\n`;
|
|
363
|
+
info += `${theme.fg("dim", t("controller.session.total"))} ${stats.totalMessages}\n\n`;
|
|
364
|
+
info += `${theme.bold(t("controller.session.tokens"))}\n`;
|
|
365
|
+
info += `${theme.fg("dim", t("controller.session.input"))} ${stats.tokens.input.toLocaleString()}\n`;
|
|
366
|
+
info += `${theme.fg("dim", t("controller.session.output"))} ${stats.tokens.output.toLocaleString()}\n`;
|
|
367
|
+
if (stats.tokens.cacheRead > 0) {
|
|
368
|
+
info += `${theme.fg("dim", t("controller.session.cacheRead"))} ${stats.tokens.cacheRead.toLocaleString()}\n`;
|
|
369
|
+
}
|
|
370
|
+
if (stats.tokens.cacheWrite > 0) {
|
|
371
|
+
info += `${theme.fg("dim", t("controller.session.cacheWrite"))} ${stats.tokens.cacheWrite.toLocaleString()}\n`;
|
|
372
|
+
}
|
|
373
|
+
info += `${theme.fg("dim", t("controller.session.total"))} ${stats.tokens.total.toLocaleString()}\n`;
|
|
374
|
+
|
|
375
|
+
if (stats.cost > 0 || normalizedPremiumRequests > 0) {
|
|
376
|
+
info += `\n${theme.bold(t("controller.session.cost"))}\n`;
|
|
377
|
+
if (stats.cost > 0) {
|
|
378
|
+
info += `${theme.fg("dim", t("controller.session.total"))} ${stats.cost.toFixed(4)}\n`;
|
|
379
|
+
}
|
|
380
|
+
if (normalizedPremiumRequests > 0) {
|
|
381
|
+
info += `${theme.fg("dim", t("controller.session.premiumRequests"))} ${normalizedPremiumRequests.toLocaleString()}\n`;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const gateway = await getGatewayStatus();
|
|
386
|
+
info += `\n${theme.bold(t("controller.session.pythonGateway"))}\n`;
|
|
387
|
+
if (gateway.active) {
|
|
388
|
+
info += `${theme.fg("dim", t("controller.session.status"))} ${theme.fg("success", t("controller.session.gatewayActive"))}\n`;
|
|
389
|
+
info += `${theme.fg("dim", t("controller.session.url"))} ${gateway.url}\n`;
|
|
390
|
+
info += `${theme.fg("dim", t("controller.session.pid"))} ${gateway.pid}\n`;
|
|
391
|
+
if (gateway.pythonPath) {
|
|
392
|
+
info += `${theme.fg("dim", t("controller.session.python"))} ${gateway.pythonPath}\n`;
|
|
393
|
+
}
|
|
394
|
+
if (gateway.venvPath) {
|
|
395
|
+
info += `${theme.fg("dim", t("controller.session.venv"))} ${gateway.venvPath}\n`;
|
|
396
|
+
}
|
|
397
|
+
if (gateway.uptime !== null) {
|
|
398
|
+
const uptimeSec = Math.floor(gateway.uptime / 1000);
|
|
399
|
+
const mins = Math.floor(uptimeSec / 60);
|
|
400
|
+
const secs = uptimeSec % 60;
|
|
401
|
+
info += `${theme.fg("dim", t("controller.session.uptime"))} ${mins}m ${secs}s\n`;
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
info += `${theme.fg("dim", t("controller.session.status"))} ${theme.fg("dim", t("controller.session.gatewayInactive"))}\n`;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (this.ctx.lspServers && this.ctx.lspServers.length > 0) {
|
|
408
|
+
info += `\n${theme.bold(t("controller.session.lspServers"))}\n`;
|
|
409
|
+
for (const server of this.ctx.lspServers) {
|
|
410
|
+
const statusColor =
|
|
411
|
+
server.status === "ready" ? "success" : server.status === "connecting" ? "warning" : "error";
|
|
412
|
+
const statusText =
|
|
413
|
+
server.status === "error" && server.error ? `${server.status}: ${server.error}` : server.status;
|
|
414
|
+
info += `${theme.fg("dim", `${server.name}:`)} ${theme.fg(statusColor, statusText)} ${theme.fg("dim", `(${server.fileTypes.join(", ")})`)}\n`;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (this.ctx.mcpManager) {
|
|
419
|
+
const mcpServers = this.ctx.mcpManager.getConnectedServers();
|
|
420
|
+
info += `\n${theme.bold(t("controller.session.mcpServers"))}\n`;
|
|
421
|
+
if (mcpServers.length === 0) {
|
|
422
|
+
info += `${theme.fg("dim", t("controller.session.noneConnected"))}\n`;
|
|
423
|
+
} else {
|
|
424
|
+
for (const name of mcpServers) {
|
|
425
|
+
const conn = this.ctx.mcpManager.getConnection(name);
|
|
426
|
+
const toolCount = conn?.tools?.length ?? 0;
|
|
427
|
+
info += `${theme.fg("dim", `${name}:`)} ${theme.fg("success", "connected")} ${theme.fg("dim", `(${toolCount} tools)`)}\n`;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
433
|
+
this.ctx.chatContainer.addChild(new Text(info, 1, 0));
|
|
434
|
+
this.ctx.ui.requestRender();
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
async handleJobsCommand(): Promise<void> {
|
|
438
|
+
const snapshot = this.ctx.session.getAsyncJobSnapshot({ recentLimit: 5 });
|
|
439
|
+
if (!snapshot) {
|
|
440
|
+
this.ctx.showWarning(t("controller.jobs.unavailable"));
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const now = Date.now();
|
|
445
|
+
const lineWidth = Math.max(24, (this.ctx.ui.terminal.columns ?? 100) - 24);
|
|
446
|
+
let info = `${theme.bold(t("controller.jobs.title"))}\n\n`;
|
|
447
|
+
info += `${theme.fg("dim", t("controller.jobs.running"))} ${snapshot.running.length}\n`;
|
|
448
|
+
|
|
449
|
+
if (snapshot.running.length === 0 && snapshot.recent.length === 0) {
|
|
450
|
+
info += `\n${theme.fg("dim", t("controller.jobs.noJobs"))}\n`;
|
|
451
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
452
|
+
this.ctx.chatContainer.addChild(new Text(info, 1, 0));
|
|
453
|
+
this.ctx.ui.requestRender();
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (snapshot.running.length > 0) {
|
|
458
|
+
info += `\n${theme.bold(t("controller.jobs.runningJobs"))}\n`;
|
|
459
|
+
for (const job of snapshot.running) {
|
|
460
|
+
info += `${renderJobLine(job, now)}\n`;
|
|
461
|
+
info += ` ${theme.fg("dim", truncateJobLabel(job.label, lineWidth))}\n`;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (snapshot.recent.length > 0) {
|
|
466
|
+
info += `\n${theme.bold(t("controller.jobs.recentJobs"))}\n`;
|
|
467
|
+
for (const job of snapshot.recent) {
|
|
468
|
+
info += `${renderJobLine(job, now)}\n`;
|
|
469
|
+
info += ` ${theme.fg("dim", truncateJobLabel(job.label, lineWidth))}\n`;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
474
|
+
this.ctx.chatContainer.addChild(new Text(info.trimEnd(), 1, 0));
|
|
475
|
+
this.ctx.ui.requestRender();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
async handleUsageCommand(reports?: UsageReport[] | null): Promise<void> {
|
|
479
|
+
let usageReports = reports ?? null;
|
|
480
|
+
if (!usageReports) {
|
|
481
|
+
const provider = this.ctx.session as { fetchUsageReports?: () => Promise<UsageReport[] | null> };
|
|
482
|
+
if (!provider.fetchUsageReports) {
|
|
483
|
+
this.ctx.showWarning(t("controller.usage.notConfigured"));
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
usageReports = await provider.fetchUsageReports();
|
|
488
|
+
} catch (error) {
|
|
489
|
+
this.ctx.showError(
|
|
490
|
+
t("controller.usage.fetchFailed", { message: error instanceof Error ? error.message : String(error) }),
|
|
491
|
+
);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (!usageReports || usageReports.length === 0) {
|
|
497
|
+
this.ctx.showWarning(t("controller.usage.noData"));
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const output = renderUsageReports(usageReports, theme, Date.now());
|
|
502
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
503
|
+
this.ctx.chatContainer.addChild(new Text(output, 1, 0));
|
|
504
|
+
this.ctx.ui.requestRender();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
async handleChangelogCommand(showFull = false): Promise<void> {
|
|
508
|
+
const changelogPath = getChangelogPath();
|
|
509
|
+
const allEntries = await parseChangelog(changelogPath);
|
|
510
|
+
// Default to showing only the latest 3 versions unless --full is specified
|
|
511
|
+
// allEntries comes from parseChangelog with newest first, reverse to show oldest->newest
|
|
512
|
+
const entriesToShow = showFull ? allEntries : allEntries.slice(0, 3);
|
|
513
|
+
const changelogMarkdown =
|
|
514
|
+
entriesToShow.length > 0
|
|
515
|
+
? [...entriesToShow]
|
|
516
|
+
.reverse()
|
|
517
|
+
.map(e => e.content)
|
|
518
|
+
.join("\n\n")
|
|
519
|
+
: t("controller.changelog.noEntries");
|
|
520
|
+
const title = showFull ? t("controller.changelog.fullTitle") : t("controller.changelog.recentTitle");
|
|
521
|
+
const hint = showFull
|
|
522
|
+
? ""
|
|
523
|
+
: `\n\n${theme.fg("dim", "Use")} ${theme.bold("/changelog full")} ${theme.fg("dim", "to view the complete changelog.")}`;
|
|
524
|
+
|
|
525
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
526
|
+
this.ctx.chatContainer.addChild(new DynamicBorder());
|
|
527
|
+
this.ctx.chatContainer.addChild(new Text(theme.bold(theme.fg("contentAccent", title)), 1, 0));
|
|
528
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
529
|
+
this.ctx.chatContainer.addChild(new Markdown(changelogMarkdown + hint, 1, 1, getMarkdownTheme()));
|
|
530
|
+
this.ctx.chatContainer.addChild(new DynamicBorder());
|
|
531
|
+
this.ctx.ui.requestRender();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
handleHotkeysCommand(): void {
|
|
535
|
+
const hotkeys = buildHotkeysMarkdown({ keybindings: this.ctx.keybindings });
|
|
536
|
+
showMarkdownPanel(this.ctx, t("controller.hotkeys.title"), hotkeys);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
handleToolsCommand(): void {
|
|
540
|
+
const tools = buildToolsMarkdown({ tools: this.ctx.session.agent.state.tools });
|
|
541
|
+
showMarkdownPanel(this.ctx, t("controller.tools.title"), tools);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
async handleMemoryCommand(text: string): Promise<void> {
|
|
545
|
+
const argumentText = text.slice(7).trim();
|
|
546
|
+
const action = argumentText.split(/\s+/, 1)[0]?.toLowerCase() || "view";
|
|
547
|
+
const agentDir = this.ctx.settings.getAgentDir();
|
|
548
|
+
|
|
549
|
+
if (action === "view") {
|
|
550
|
+
const payload = await buildMemoryToolDeveloperInstructions(agentDir, this.ctx.settings);
|
|
551
|
+
if (!payload) {
|
|
552
|
+
this.ctx.showWarning(t("controller.memory.empty"));
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
556
|
+
this.ctx.chatContainer.addChild(new DynamicBorder());
|
|
557
|
+
this.ctx.chatContainer.addChild(
|
|
558
|
+
new Text(theme.bold(theme.fg("contentAccent", t("controller.memory.title"))), 1, 0),
|
|
559
|
+
);
|
|
560
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
561
|
+
this.ctx.chatContainer.addChild(new Markdown(payload, 1, 1, getMarkdownTheme()));
|
|
562
|
+
this.ctx.chatContainer.addChild(new DynamicBorder());
|
|
563
|
+
this.ctx.ui.requestRender();
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (action === "reset" || action === "clear") {
|
|
568
|
+
try {
|
|
569
|
+
await clearMemoryData(agentDir, this.ctx.sessionManager.getCwd());
|
|
570
|
+
await this.ctx.session.refreshBaseSystemPrompt();
|
|
571
|
+
this.ctx.showStatus(t("controller.memory.cleared"));
|
|
572
|
+
} catch (error) {
|
|
573
|
+
this.ctx.showError(
|
|
574
|
+
t("controller.memory.clearFailed", { message: error instanceof Error ? error.message : String(error) }),
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (action === "enqueue" || action === "rebuild") {
|
|
581
|
+
try {
|
|
582
|
+
enqueueMemoryConsolidation(agentDir, this.ctx.sessionManager.getCwd());
|
|
583
|
+
this.ctx.showStatus(t("controller.memory.enqueued"));
|
|
584
|
+
} catch (error) {
|
|
585
|
+
this.ctx.showError(
|
|
586
|
+
t("controller.memory.enqueueFailed", {
|
|
587
|
+
message: error instanceof Error ? error.message : String(error),
|
|
588
|
+
}),
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
this.ctx.showError(t("controller.memory.usage"));
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
async handleClearCommand(): Promise<void> {
|
|
598
|
+
if (this.ctx.loadingAnimation) {
|
|
599
|
+
this.ctx.loadingAnimation.stop();
|
|
600
|
+
this.ctx.loadingAnimation = undefined;
|
|
601
|
+
}
|
|
602
|
+
this.ctx.statusContainer.clear();
|
|
603
|
+
|
|
604
|
+
if (this.ctx.session.isCompacting) {
|
|
605
|
+
this.ctx.session.abortCompaction();
|
|
606
|
+
while (this.ctx.session.isCompacting) {
|
|
607
|
+
await Bun.sleep(10);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
await this.ctx.session.newSession();
|
|
611
|
+
this.ctx.resetObserverRegistry();
|
|
612
|
+
setSessionTerminalTitle(
|
|
613
|
+
this.ctx.sessionManager.getSessionName(),
|
|
614
|
+
this.ctx.sessionManager.getCwd(),
|
|
615
|
+
this.ctx.sessionManager.titleSource,
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
this.ctx.statusLine.invalidate();
|
|
619
|
+
this.ctx.statusLine.setSessionStartTime(Date.now());
|
|
620
|
+
this.ctx.updateEditorTopBorder();
|
|
621
|
+
this.ctx.updateEditorBorderColor();
|
|
622
|
+
this.ctx.ui.requestRender();
|
|
623
|
+
|
|
624
|
+
this.ctx.chatContainer.clear();
|
|
625
|
+
this.ctx.pendingMessagesContainer.clear();
|
|
626
|
+
this.ctx.compactionQueuedMessages = [];
|
|
627
|
+
this.ctx.streamingComponent = undefined;
|
|
628
|
+
this.ctx.streamingMessage = undefined;
|
|
629
|
+
this.ctx.pendingTools.clear();
|
|
630
|
+
|
|
631
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
632
|
+
this.ctx.chatContainer.addChild(
|
|
633
|
+
new Text(`${theme.fg("contentAccent", `${theme.status.success} ${t("controller.newSession")}`)}`, 1, 1),
|
|
634
|
+
);
|
|
635
|
+
await this.ctx.reloadTodos();
|
|
636
|
+
this.ctx.ui.requestRender();
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
async handleForkCommand(): Promise<void> {
|
|
640
|
+
if (this.ctx.session.isStreaming) {
|
|
641
|
+
this.ctx.showWarning(t("controller.fork.streaming"));
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (this.ctx.loadingAnimation) {
|
|
645
|
+
this.ctx.loadingAnimation.stop();
|
|
646
|
+
this.ctx.loadingAnimation = undefined;
|
|
647
|
+
}
|
|
648
|
+
this.ctx.statusContainer.clear();
|
|
649
|
+
|
|
650
|
+
const success = await this.ctx.session.fork();
|
|
651
|
+
if (!success) {
|
|
652
|
+
this.ctx.showError(t("controller.fork.failed"));
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
this.ctx.statusLine.invalidate();
|
|
657
|
+
this.ctx.updateEditorTopBorder();
|
|
658
|
+
|
|
659
|
+
const sessionFile = this.ctx.session.sessionFile;
|
|
660
|
+
const shortPath = sessionFile ? sessionFile.split("/").pop() : "new session";
|
|
661
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
662
|
+
this.ctx.chatContainer.addChild(
|
|
663
|
+
new Text(
|
|
664
|
+
`${theme.fg("contentAccent", `${theme.status.success} ${t("controller.fork.success", { path: shortPath! })}`)}`,
|
|
665
|
+
1,
|
|
666
|
+
1,
|
|
667
|
+
),
|
|
668
|
+
);
|
|
669
|
+
this.ctx.ui.requestRender();
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
async handleMoveCommand(targetPath: string): Promise<void> {
|
|
673
|
+
if (this.ctx.session.isStreaming) {
|
|
674
|
+
this.ctx.showWarning(t("controller.move.streaming"));
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const unquoted = stripOuterDoubleQuotes(targetPath);
|
|
679
|
+
if (!unquoted) {
|
|
680
|
+
this.ctx.showError(t("controller.move.usage"));
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const cwd = this.ctx.sessionManager.getCwd();
|
|
685
|
+
const resolvedPath = resolveToCwd(unquoted, cwd);
|
|
686
|
+
|
|
687
|
+
try {
|
|
688
|
+
const stat = await fs.stat(resolvedPath);
|
|
689
|
+
if (!stat.isDirectory()) {
|
|
690
|
+
this.ctx.showError(t("controller.move.notDirectory", { path: resolvedPath }));
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
} catch {
|
|
694
|
+
this.ctx.showError(t("controller.move.notExists", { path: resolvedPath }));
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
try {
|
|
699
|
+
await this.ctx.sessionManager.flush();
|
|
700
|
+
await this.ctx.sessionManager.moveTo(resolvedPath);
|
|
701
|
+
setProjectDir(resolvedPath);
|
|
702
|
+
clearXcshPluginRootsCache(); // re-warms preloadedPluginRoots with new project dir (async)
|
|
703
|
+
resetCapabilities();
|
|
704
|
+
await this.ctx.refreshSlashCommandState(resolvedPath);
|
|
705
|
+
|
|
706
|
+
setShellPwd(resolvedPath);
|
|
707
|
+
this.ctx.statusLine.setCwd(resolvedPath);
|
|
708
|
+
this.ctx.updateEditorTopBorder();
|
|
709
|
+
|
|
710
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
711
|
+
this.ctx.chatContainer.addChild(
|
|
712
|
+
new Text(
|
|
713
|
+
`${theme.fg("contentAccent", `${theme.status.success} ${t("controller.move.success", { path: resolvedPath })}`)}`,
|
|
714
|
+
1,
|
|
715
|
+
1,
|
|
716
|
+
),
|
|
717
|
+
);
|
|
718
|
+
this.ctx.ui.requestRender();
|
|
719
|
+
} catch (err) {
|
|
720
|
+
this.ctx.showError(t("controller.move.failed", { message: err instanceof Error ? err.message : String(err) }));
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
async handleRenameCommand(title: string): Promise<void> {
|
|
725
|
+
try {
|
|
726
|
+
const stored = await this.ctx.sessionManager.setSessionName(title, "user");
|
|
727
|
+
if (!stored) {
|
|
728
|
+
this.ctx.showError(t("controller.rename.empty"));
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const name = this.ctx.sessionManager.getSessionName()!;
|
|
732
|
+
setSessionTerminalTitle(name, this.ctx.sessionManager.getCwd(), this.ctx.sessionManager.titleSource);
|
|
733
|
+
this.ctx.statusLine.invalidate();
|
|
734
|
+
this.ctx.updateEditorBorderColor();
|
|
735
|
+
this.ctx.showStatus(t("controller.rename.success", { name }));
|
|
736
|
+
} catch (err) {
|
|
737
|
+
this.ctx.showError(
|
|
738
|
+
t("controller.rename.failed", { message: err instanceof Error ? err.message : String(err) }),
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
async handleBashCommand(command: string, excludeFromContext = false): Promise<void> {
|
|
744
|
+
const isDeferred = this.ctx.session.isStreaming;
|
|
745
|
+
this.ctx.bashComponent = new BashExecutionComponent(command, this.ctx.ui, excludeFromContext);
|
|
746
|
+
let bashGutter: ReturnType<typeof createToolGutter> | undefined;
|
|
747
|
+
|
|
748
|
+
if (isDeferred) {
|
|
749
|
+
this.ctx.pendingMessagesContainer.addChild(this.ctx.bashComponent);
|
|
750
|
+
this.ctx.pendingBashComponents.push(this.ctx.bashComponent);
|
|
751
|
+
} else {
|
|
752
|
+
bashGutter = createToolGutter(this.ctx.ui, this.ctx.bashComponent);
|
|
753
|
+
this.ctx.chatContainer.addChild(bashGutter);
|
|
754
|
+
}
|
|
755
|
+
this.ctx.ui.requestRender();
|
|
756
|
+
|
|
757
|
+
let failed = false;
|
|
758
|
+
try {
|
|
759
|
+
const result = await this.ctx.session.executeBash(
|
|
760
|
+
command,
|
|
761
|
+
chunk => {
|
|
762
|
+
if (this.ctx.bashComponent) {
|
|
763
|
+
this.ctx.bashComponent.appendOutput(chunk);
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
{ excludeFromContext },
|
|
767
|
+
);
|
|
768
|
+
|
|
769
|
+
// Update CWD if the shell changed directory (e.g. via cd)
|
|
770
|
+
if (result.newCwd && result.newCwd !== this.ctx.sessionManager.getCwd()) {
|
|
771
|
+
setShellPwd(result.newCwd);
|
|
772
|
+
this.ctx.statusLine.setCwd(result.newCwd);
|
|
773
|
+
this.ctx.ui.requestRender();
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
if (this.ctx.bashComponent) {
|
|
777
|
+
const meta = outputMeta().truncationFromSummary(result, { direction: "tail" }).get();
|
|
778
|
+
this.ctx.bashComponent.setComplete(result.exitCode, result.cancelled, {
|
|
779
|
+
output: result.output,
|
|
780
|
+
truncation: meta?.truncation,
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
failed = result.cancelled || (typeof result.exitCode === "number" && result.exitCode !== 0);
|
|
784
|
+
} catch (error) {
|
|
785
|
+
failed = true;
|
|
786
|
+
if (this.ctx.bashComponent) {
|
|
787
|
+
this.ctx.bashComponent.setError(error instanceof Error ? error : String(error));
|
|
788
|
+
}
|
|
789
|
+
this.ctx.showError(
|
|
790
|
+
t("controller.bash.failed", { message: error instanceof Error ? error.message : "Unknown error" }),
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
bashGutter?.setDone(failed ? "error" : "success");
|
|
795
|
+
this.ctx.bashComponent = undefined;
|
|
796
|
+
this.ctx.ui.requestRender();
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
async handlePythonCommand(code: string, excludeFromContext = false): Promise<void> {
|
|
800
|
+
const isDeferred = this.ctx.session.isStreaming;
|
|
801
|
+
this.ctx.pythonComponent = new PythonExecutionComponent(code, this.ctx.ui, excludeFromContext);
|
|
802
|
+
let pythonGutter: ReturnType<typeof createToolGutter> | undefined;
|
|
803
|
+
|
|
804
|
+
if (isDeferred) {
|
|
805
|
+
this.ctx.pendingMessagesContainer.addChild(this.ctx.pythonComponent);
|
|
806
|
+
this.ctx.pendingPythonComponents.push(this.ctx.pythonComponent);
|
|
807
|
+
} else {
|
|
808
|
+
pythonGutter = createToolGutter(this.ctx.ui, this.ctx.pythonComponent);
|
|
809
|
+
this.ctx.chatContainer.addChild(pythonGutter);
|
|
810
|
+
}
|
|
811
|
+
this.ctx.ui.requestRender();
|
|
812
|
+
|
|
813
|
+
let failed = false;
|
|
814
|
+
try {
|
|
815
|
+
const result = await this.ctx.session.executePython(
|
|
816
|
+
code,
|
|
817
|
+
chunk => {
|
|
818
|
+
if (this.ctx.pythonComponent) {
|
|
819
|
+
this.ctx.pythonComponent.appendOutput(chunk);
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
{ excludeFromContext },
|
|
823
|
+
);
|
|
824
|
+
|
|
825
|
+
if (this.ctx.pythonComponent) {
|
|
826
|
+
const meta = outputMeta().truncationFromSummary(result, { direction: "tail" }).get();
|
|
827
|
+
this.ctx.pythonComponent.setComplete(result.exitCode, result.cancelled, {
|
|
828
|
+
output: result.output,
|
|
829
|
+
truncation: meta?.truncation,
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
failed = result.cancelled || (typeof result.exitCode === "number" && result.exitCode !== 0);
|
|
833
|
+
} catch (error) {
|
|
834
|
+
failed = true;
|
|
835
|
+
if (this.ctx.pythonComponent) {
|
|
836
|
+
this.ctx.pythonComponent.setError(error instanceof Error ? error : String(error));
|
|
837
|
+
}
|
|
838
|
+
this.ctx.showError(`Python execution failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
pythonGutter?.setDone(failed ? "error" : "success");
|
|
842
|
+
this.ctx.pythonComponent = undefined;
|
|
843
|
+
this.ctx.ui.requestRender();
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
async handleCompactCommand(customInstructions?: string): Promise<void> {
|
|
847
|
+
const entries = this.ctx.sessionManager.getEntries();
|
|
848
|
+
const messageCount = entries.filter(e => e.type === "message").length;
|
|
849
|
+
|
|
850
|
+
if (messageCount < 2) {
|
|
851
|
+
this.ctx.showWarning("Nothing to compact (no messages yet)");
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
await this.executeCompaction(customInstructions, false);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
async handleSkillCommand(skillPath: string, args: string): Promise<void> {
|
|
859
|
+
try {
|
|
860
|
+
const content = await Bun.file(skillPath).text();
|
|
861
|
+
const body = content.replace(/^---\n[\s\S]*?\n---\n/, "").trim();
|
|
862
|
+
const metaLines = [`Skill: ${skillPath}`];
|
|
863
|
+
if (args) {
|
|
864
|
+
metaLines.push(`User: ${args}`);
|
|
865
|
+
}
|
|
866
|
+
const message = `${body}\n\n---\n\n${metaLines.join("\n")}`;
|
|
867
|
+
await this.ctx.session.prompt(message);
|
|
868
|
+
} catch (err) {
|
|
869
|
+
this.ctx.showError(`Failed to load skill: ${err instanceof Error ? err.message : String(err)}`);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
async executeCompaction(customInstructionsOrOptions?: string | CompactOptions, isAuto = false): Promise<void> {
|
|
874
|
+
if (this.ctx.loadingAnimation) {
|
|
875
|
+
this.ctx.loadingAnimation.stop();
|
|
876
|
+
this.ctx.loadingAnimation = undefined;
|
|
877
|
+
}
|
|
878
|
+
this.ctx.statusContainer.clear();
|
|
879
|
+
|
|
880
|
+
const originalOnEscape = this.ctx.editor.onEscape;
|
|
881
|
+
this.ctx.editor.onEscape = () => {
|
|
882
|
+
this.ctx.session.abortCompaction();
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
886
|
+
const label = isAuto ? "Auto-compacting context... (esc to cancel)" : "Compacting context... (esc to cancel)";
|
|
887
|
+
const compactingLoader = new Loader(
|
|
888
|
+
this.ctx.ui,
|
|
889
|
+
spinner => theme.fg("spinnerAccent", spinner),
|
|
890
|
+
text => theme.fg("muted", text),
|
|
891
|
+
label,
|
|
892
|
+
getSymbolTheme().spinnerFrames,
|
|
893
|
+
);
|
|
894
|
+
this.ctx.statusContainer.addChild(compactingLoader);
|
|
895
|
+
this.ctx.ui.requestRender();
|
|
896
|
+
|
|
897
|
+
try {
|
|
898
|
+
const instructions = typeof customInstructionsOrOptions === "string" ? customInstructionsOrOptions : undefined;
|
|
899
|
+
const options =
|
|
900
|
+
customInstructionsOrOptions && typeof customInstructionsOrOptions === "object"
|
|
901
|
+
? customInstructionsOrOptions
|
|
902
|
+
: undefined;
|
|
903
|
+
await this.ctx.session.compact(instructions, options);
|
|
904
|
+
|
|
905
|
+
this.ctx.rebuildChatFromMessages();
|
|
906
|
+
|
|
907
|
+
this.ctx.statusLine.invalidate();
|
|
908
|
+
this.ctx.updateEditorTopBorder();
|
|
909
|
+
} catch (error) {
|
|
910
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
911
|
+
if (message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError")) {
|
|
912
|
+
this.ctx.showError("Compaction cancelled");
|
|
913
|
+
} else {
|
|
914
|
+
this.ctx.showError(`Compaction failed: ${message}`);
|
|
915
|
+
}
|
|
916
|
+
} finally {
|
|
917
|
+
compactingLoader.stop();
|
|
918
|
+
this.ctx.statusContainer.clear();
|
|
919
|
+
this.ctx.editor.onEscape = originalOnEscape;
|
|
920
|
+
}
|
|
921
|
+
await this.ctx.flushCompactionQueue({ willRetry: false });
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
async handleHandoffCommand(customInstructions?: string): Promise<void> {
|
|
925
|
+
const entries = this.ctx.sessionManager.getEntries();
|
|
926
|
+
const messageCount = entries.filter(e => e.type === "message").length;
|
|
927
|
+
|
|
928
|
+
if (messageCount < 2) {
|
|
929
|
+
this.ctx.showWarning("Nothing to hand off (no messages yet)");
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
try {
|
|
934
|
+
// The agent will visibly generate the handoff document in chat
|
|
935
|
+
const result = await this.ctx.session.handoff(customInstructions);
|
|
936
|
+
|
|
937
|
+
if (!result) {
|
|
938
|
+
this.ctx.showError("Handoff cancelled");
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// Rebuild chat from the new session (which now contains the handoff document)
|
|
943
|
+
this.ctx.rebuildChatFromMessages();
|
|
944
|
+
|
|
945
|
+
this.ctx.statusLine.invalidate();
|
|
946
|
+
this.ctx.updateEditorTopBorder();
|
|
947
|
+
this.ctx.updateEditorBorderColor();
|
|
948
|
+
await this.ctx.reloadTodos();
|
|
949
|
+
|
|
950
|
+
this.ctx.chatContainer.addChild(new Spacer(1));
|
|
951
|
+
this.ctx.chatContainer.addChild(
|
|
952
|
+
new Text(
|
|
953
|
+
`${theme.fg("contentAccent", `${theme.status.success} New session started with handoff context`)}`,
|
|
954
|
+
1,
|
|
955
|
+
1,
|
|
956
|
+
),
|
|
957
|
+
);
|
|
958
|
+
if (result.savedPath) {
|
|
959
|
+
this.ctx.showStatus(`Handoff document saved to: ${result.savedPath}`);
|
|
960
|
+
}
|
|
961
|
+
} catch (error) {
|
|
962
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
963
|
+
if (message === "Handoff cancelled" || (error instanceof Error && error.name === "AbortError")) {
|
|
964
|
+
this.ctx.showError("Handoff cancelled");
|
|
965
|
+
} else {
|
|
966
|
+
this.ctx.showError(`Handoff failed: ${message}`);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
this.ctx.ui.requestRender();
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
const BAR_WIDTH = 24;
|
|
974
|
+
const COLUMN_WIDTH = BAR_WIDTH + 2;
|
|
975
|
+
|
|
976
|
+
function renderJobLine(job: AsyncJobSnapshotItem, now: number): string {
|
|
977
|
+
const duration = formatDuration(Math.max(0, now - job.startTime));
|
|
978
|
+
const status = formatJobStatus(job.status);
|
|
979
|
+
return `${theme.fg("dim", job.id)} ${theme.fg("dim", `[${job.type}]`)} ${status} ${theme.fg("dim", `(${duration})`)}`;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function formatJobStatus(status: AsyncJobSnapshotItem["status"]): string {
|
|
983
|
+
if (status === "running") return theme.fg("warning", "running");
|
|
984
|
+
if (status === "completed") return theme.fg("success", "completed");
|
|
985
|
+
if (status === "cancelled") return theme.fg("dim", "cancelled");
|
|
986
|
+
return theme.fg("error", "failed");
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
function truncateJobLabel(label: string, maxWidth: number): string {
|
|
990
|
+
if (visibleWidth(label) <= maxWidth) return label;
|
|
991
|
+
if (maxWidth <= 1) return "…";
|
|
992
|
+
|
|
993
|
+
let out = "";
|
|
994
|
+
for (const char of label) {
|
|
995
|
+
const next = `${out}${char}`;
|
|
996
|
+
if (visibleWidth(`${next}…`) > maxWidth) break;
|
|
997
|
+
out = next;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
return `${out}…`;
|
|
1001
|
+
}
|
|
1002
|
+
function formatProviderName(provider: string): string {
|
|
1003
|
+
return provider
|
|
1004
|
+
.split(/[-_]/g)
|
|
1005
|
+
.map(part => (part ? part[0].toUpperCase() + part.slice(1) : ""))
|
|
1006
|
+
.join(" ");
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function formatNumber(value: number, maxFractionDigits = 1): string {
|
|
1010
|
+
return new Intl.NumberFormat("en-US", { maximumFractionDigits: maxFractionDigits }).format(value);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
function formatUsedAccounts(value: number): string {
|
|
1014
|
+
return `${value.toFixed(2)} used`;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
function resolveProviderAuthMode(authStorage: AuthStorage, provider: string): string {
|
|
1018
|
+
if (authStorage.hasOAuth(provider)) {
|
|
1019
|
+
return "oauth";
|
|
1020
|
+
}
|
|
1021
|
+
if (authStorage.has(provider)) {
|
|
1022
|
+
return "api key";
|
|
1023
|
+
}
|
|
1024
|
+
if (getEnvApiKey(provider)) {
|
|
1025
|
+
return "env api key";
|
|
1026
|
+
}
|
|
1027
|
+
if (authStorage.hasAuth(provider)) {
|
|
1028
|
+
return "runtime/fallback";
|
|
1029
|
+
}
|
|
1030
|
+
return "unknown";
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
export function renderProviderSection(details: ProviderDetails, uiTheme: Pick<typeof theme, "fg">): string {
|
|
1034
|
+
const lines: string[] = [];
|
|
1035
|
+
lines.push(`${uiTheme.fg("dim", "Name:")} ${details.provider}`);
|
|
1036
|
+
for (const field of details.fields) {
|
|
1037
|
+
lines.push(`${uiTheme.fg("dim", `${field.label}:`)} ${field.value}`);
|
|
1038
|
+
}
|
|
1039
|
+
return `${lines.join("\n")}\n`;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
function resolveFraction(limit: UsageLimit): number | undefined {
|
|
1043
|
+
const amount = limit.amount;
|
|
1044
|
+
if (amount.usedFraction !== undefined) return amount.usedFraction;
|
|
1045
|
+
if (amount.used !== undefined && amount.limit !== undefined && amount.limit > 0) {
|
|
1046
|
+
return amount.used / amount.limit;
|
|
1047
|
+
}
|
|
1048
|
+
if (amount.unit === "percent" && amount.used !== undefined) {
|
|
1049
|
+
return amount.used / 100;
|
|
1050
|
+
}
|
|
1051
|
+
return undefined;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
function resolveProviderUsageTotal(reports: UsageReport[]): number {
|
|
1055
|
+
return reports
|
|
1056
|
+
.flatMap(report => report.limits)
|
|
1057
|
+
.map(limit => resolveFraction(limit) ?? 0)
|
|
1058
|
+
.reduce((sum, value) => sum + value, 0);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function formatLimitTitle(limit: UsageLimit): string {
|
|
1062
|
+
const tier = limit.scope.tier;
|
|
1063
|
+
if (tier && !limit.label.toLowerCase().includes(tier.toLowerCase())) {
|
|
1064
|
+
return `${limit.label} (${tier})`;
|
|
1065
|
+
}
|
|
1066
|
+
return limit.label;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
function formatWindowSuffix(label: string, windowLabel: string, uiTheme: typeof theme): string {
|
|
1070
|
+
const normalizedLabel = label.toLowerCase();
|
|
1071
|
+
const normalizedWindow = windowLabel.toLowerCase();
|
|
1072
|
+
if (normalizedWindow === "quota window") return "";
|
|
1073
|
+
if (normalizedLabel.includes(normalizedWindow)) return "";
|
|
1074
|
+
return uiTheme.fg("dim", `(${windowLabel})`);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
function formatAccountLabel(limit: UsageLimit, report: UsageReport, index: number): string {
|
|
1078
|
+
const email = (report.metadata?.email as string | undefined) ?? limit.scope.accountId;
|
|
1079
|
+
if (email) return email;
|
|
1080
|
+
const accountId = (report.metadata?.accountId as string | undefined) ?? limit.scope.accountId;
|
|
1081
|
+
if (accountId) return accountId;
|
|
1082
|
+
return `account ${index + 1}`;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
function formatUnlimitedReportLabel(report: UsageReport, index: number): string {
|
|
1086
|
+
const email = report.metadata?.email as string | undefined;
|
|
1087
|
+
if (email) return email;
|
|
1088
|
+
const accountId = report.metadata?.accountId as string | undefined;
|
|
1089
|
+
if (accountId) return accountId;
|
|
1090
|
+
return `account ${index + 1}`;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
function formatResetShort(limit: UsageLimit, nowMs: number): string | undefined {
|
|
1094
|
+
if (limit.window?.resetsAt !== undefined) {
|
|
1095
|
+
return formatDuration(limit.window.resetsAt - nowMs);
|
|
1096
|
+
}
|
|
1097
|
+
return undefined;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
function formatAccountHeader(limit: UsageLimit, report: UsageReport, index: number, nowMs: number): string {
|
|
1101
|
+
const label = formatAccountLabel(limit, report, index);
|
|
1102
|
+
const reset = formatResetShort(limit, nowMs);
|
|
1103
|
+
if (!reset) return label;
|
|
1104
|
+
return `${label} (${reset})`;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function padColumn(text: string, width: number): string {
|
|
1108
|
+
const visible = visibleWidth(text);
|
|
1109
|
+
if (visible >= width) return text;
|
|
1110
|
+
return `${text}${padding(width - visible)}`;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
function resolveAggregateStatus(limits: UsageLimit[]): UsageLimit["status"] {
|
|
1114
|
+
const hasOk = limits.some(limit => limit.status === "ok");
|
|
1115
|
+
const hasWarning = limits.some(limit => limit.status === "warning");
|
|
1116
|
+
const hasExhausted = limits.some(limit => limit.status === "exhausted");
|
|
1117
|
+
if (!hasOk && !hasWarning && !hasExhausted) return "unknown";
|
|
1118
|
+
if (hasOk) {
|
|
1119
|
+
return hasWarning || hasExhausted ? "warning" : "ok";
|
|
1120
|
+
}
|
|
1121
|
+
if (hasWarning) return "warning";
|
|
1122
|
+
return "exhausted";
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
function formatAggregateAmount(limits: UsageLimit[]): string {
|
|
1126
|
+
const fractions = limits
|
|
1127
|
+
.map(limit => resolveFraction(limit))
|
|
1128
|
+
.filter((value): value is number => value !== undefined);
|
|
1129
|
+
if (fractions.length === limits.length && fractions.length > 0) {
|
|
1130
|
+
const sum = fractions.reduce((total, value) => total + value, 0);
|
|
1131
|
+
const usedPct = Math.max(sum * 100, 0);
|
|
1132
|
+
const remainingPct = Math.max(0, limits.length * 100 - usedPct);
|
|
1133
|
+
const avgRemaining = limits.length > 0 ? remainingPct / limits.length : remainingPct;
|
|
1134
|
+
return `${formatUsedAccounts(sum)} (${formatNumber(avgRemaining)}% left)`;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
const amounts = limits
|
|
1138
|
+
.map(limit => limit.amount)
|
|
1139
|
+
.filter(amount => amount.used !== undefined && amount.limit !== undefined && amount.limit > 0);
|
|
1140
|
+
if (amounts.length === limits.length && amounts.length > 0) {
|
|
1141
|
+
const totalUsed = amounts.reduce((sum, amount) => sum + (amount.used ?? 0), 0);
|
|
1142
|
+
const totalLimit = amounts.reduce((sum, amount) => sum + (amount.limit ?? 0), 0);
|
|
1143
|
+
const usedPct = totalLimit > 0 ? (totalUsed / totalLimit) * 100 : 0;
|
|
1144
|
+
const remainingPct = Math.max(0, 100 - usedPct);
|
|
1145
|
+
const usedAccounts = totalLimit > 0 ? (usedPct / 100) * limits.length : 0;
|
|
1146
|
+
return `${formatUsedAccounts(usedAccounts)} (${formatNumber(remainingPct)}% left)`;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return `Accounts: ${limits.length}`;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
function resolveResetRange(limits: UsageLimit[], nowMs: number): string | null {
|
|
1153
|
+
const absolute = limits
|
|
1154
|
+
.map(limit => limit.window?.resetsAt)
|
|
1155
|
+
.filter((value): value is number => value !== undefined && Number.isFinite(value) && value > nowMs);
|
|
1156
|
+
if (absolute.length === 0) return null;
|
|
1157
|
+
const offsets = absolute.map(value => value - nowMs);
|
|
1158
|
+
const minReset = Math.min(...offsets);
|
|
1159
|
+
const maxReset = Math.max(...offsets);
|
|
1160
|
+
if (maxReset - minReset > 60_000) {
|
|
1161
|
+
return `resets in ${formatDuration(minReset)}–${formatDuration(maxReset)}`;
|
|
1162
|
+
}
|
|
1163
|
+
return `resets in ${formatDuration(minReset)}`;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
export function resolveStatusIcon(status: UsageLimit["status"], uiTheme: typeof theme): string {
|
|
1167
|
+
if (status === "exhausted") return uiTheme.fg("error", uiTheme.status.error);
|
|
1168
|
+
if (status === "warning") return uiTheme.fg("warning", uiTheme.status.warning);
|
|
1169
|
+
if (status === "ok") return uiTheme.fg("success", uiTheme.status.success);
|
|
1170
|
+
return "";
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
function resolveStatusColor(status: UsageLimit["status"]): "success" | "warning" | "error" | "dim" {
|
|
1174
|
+
if (status === "exhausted") return "error";
|
|
1175
|
+
if (status === "warning") return "warning";
|
|
1176
|
+
if (status === "ok") return "success";
|
|
1177
|
+
return "dim";
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
function renderUsageBar(limit: UsageLimit, uiTheme: typeof theme): string {
|
|
1181
|
+
const fraction = resolveFraction(limit);
|
|
1182
|
+
if (fraction === undefined) {
|
|
1183
|
+
return uiTheme.fg("dim", `[${"·".repeat(BAR_WIDTH)}]`);
|
|
1184
|
+
}
|
|
1185
|
+
const clamped = Math.min(Math.max(fraction, 0), 1);
|
|
1186
|
+
const filled = Math.round(clamped * BAR_WIDTH);
|
|
1187
|
+
const filledBar = "█".repeat(filled);
|
|
1188
|
+
const emptyBar = "░".repeat(Math.max(0, BAR_WIDTH - filled));
|
|
1189
|
+
const color = resolveStatusColor(limit.status);
|
|
1190
|
+
return `${uiTheme.fg("dim", "[")}${uiTheme.fg(color, filledBar)}${uiTheme.fg("dim", emptyBar)}${uiTheme.fg("dim", "]")}`;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
function renderUsageReports(reports: UsageReport[], uiTheme: typeof theme, nowMs: number): string {
|
|
1194
|
+
const lines: string[] = [];
|
|
1195
|
+
const latestFetchedAt = Math.max(...reports.map(report => report.fetchedAt ?? 0));
|
|
1196
|
+
const headerSuffix = latestFetchedAt ? ` (${formatDuration(nowMs - latestFetchedAt)} ago)` : "";
|
|
1197
|
+
lines.push(uiTheme.bold(uiTheme.fg("contentAccent", `Usage${headerSuffix}`)));
|
|
1198
|
+
const grouped = new Map<string, UsageReport[]>();
|
|
1199
|
+
for (const report of reports) {
|
|
1200
|
+
const list = grouped.get(report.provider) ?? [];
|
|
1201
|
+
list.push(report);
|
|
1202
|
+
grouped.set(report.provider, list);
|
|
1203
|
+
}
|
|
1204
|
+
const providerEntries = Array.from(grouped.entries())
|
|
1205
|
+
.map(([provider, providerReports]) => ({
|
|
1206
|
+
provider,
|
|
1207
|
+
providerReports,
|
|
1208
|
+
totalUsage: resolveProviderUsageTotal(providerReports),
|
|
1209
|
+
}))
|
|
1210
|
+
.sort((a, b) => {
|
|
1211
|
+
if (a.totalUsage !== b.totalUsage) return a.totalUsage - b.totalUsage;
|
|
1212
|
+
return a.provider.localeCompare(b.provider);
|
|
1213
|
+
});
|
|
1214
|
+
|
|
1215
|
+
for (const { provider, providerReports } of providerEntries) {
|
|
1216
|
+
lines.push("");
|
|
1217
|
+
const providerName = formatProviderName(provider);
|
|
1218
|
+
|
|
1219
|
+
const limitGroups = new Map<
|
|
1220
|
+
string,
|
|
1221
|
+
{ label: string; windowLabel: string; limits: UsageLimit[]; reports: UsageReport[] }
|
|
1222
|
+
>();
|
|
1223
|
+
for (const report of providerReports) {
|
|
1224
|
+
for (const limit of report.limits) {
|
|
1225
|
+
const windowId = limit.window?.id ?? limit.scope.windowId ?? "default";
|
|
1226
|
+
const key = `${formatLimitTitle(limit)}|${windowId}`;
|
|
1227
|
+
const windowLabel = limit.window?.label ?? windowId;
|
|
1228
|
+
const entry = limitGroups.get(key) ?? {
|
|
1229
|
+
label: formatLimitTitle(limit),
|
|
1230
|
+
windowLabel,
|
|
1231
|
+
limits: [],
|
|
1232
|
+
reports: [],
|
|
1233
|
+
};
|
|
1234
|
+
entry.limits.push(limit);
|
|
1235
|
+
entry.reports.push(report);
|
|
1236
|
+
limitGroups.set(key, entry);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
lines.push(uiTheme.bold(uiTheme.fg("contentAccent", providerName)));
|
|
1241
|
+
|
|
1242
|
+
for (const group of limitGroups.values()) {
|
|
1243
|
+
const entries = group.limits.map((limit, index) => ({
|
|
1244
|
+
limit,
|
|
1245
|
+
report: group.reports[index],
|
|
1246
|
+
fraction: resolveFraction(limit),
|
|
1247
|
+
index,
|
|
1248
|
+
}));
|
|
1249
|
+
entries.sort((a, b) => {
|
|
1250
|
+
const aFraction = a.fraction ?? -1;
|
|
1251
|
+
const bFraction = b.fraction ?? -1;
|
|
1252
|
+
if (aFraction !== bFraction) return bFraction - aFraction;
|
|
1253
|
+
return a.index - b.index;
|
|
1254
|
+
});
|
|
1255
|
+
const sortedLimits = entries.map(entry => entry.limit);
|
|
1256
|
+
const sortedReports = entries.map(entry => entry.report);
|
|
1257
|
+
|
|
1258
|
+
const status = resolveAggregateStatus(sortedLimits);
|
|
1259
|
+
const statusIcon = resolveStatusIcon(status, uiTheme);
|
|
1260
|
+
|
|
1261
|
+
const windowSuffix = formatWindowSuffix(group.label, group.windowLabel, uiTheme);
|
|
1262
|
+
lines.push(`${statusIcon} ${uiTheme.bold(group.label)} ${windowSuffix}`.trim());
|
|
1263
|
+
const accountLabels = sortedLimits.map((limit, index) =>
|
|
1264
|
+
padColumn(formatAccountHeader(limit, sortedReports[index], index, nowMs), COLUMN_WIDTH),
|
|
1265
|
+
);
|
|
1266
|
+
lines.push(` ${accountLabels.join(" ")}`.trimEnd());
|
|
1267
|
+
const bars = sortedLimits.map(limit => padColumn(renderUsageBar(limit, uiTheme), COLUMN_WIDTH));
|
|
1268
|
+
lines.push(` ${bars.join(" ")} ${formatAggregateAmount(sortedLimits)}`.trimEnd());
|
|
1269
|
+
const resetText = sortedLimits.length <= 1 ? resolveResetRange(sortedLimits, nowMs) : null;
|
|
1270
|
+
if (resetText) {
|
|
1271
|
+
lines.push(` ${uiTheme.fg("dim", resetText)}`.trimEnd());
|
|
1272
|
+
}
|
|
1273
|
+
const notes = sortedLimits.flatMap(limit => limit.notes ?? []);
|
|
1274
|
+
if (notes.length > 0) {
|
|
1275
|
+
lines.push(` ${uiTheme.fg("dim", notes.join(" • "))}`.trimEnd());
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
// Render accounts with no rate limits (e.g. business/enterprise plans).
|
|
1280
|
+
const unlimitedReports = providerReports.filter(report => report.limits.length === 0);
|
|
1281
|
+
for (const report of unlimitedReports) {
|
|
1282
|
+
const label = formatUnlimitedReportLabel(report, 0);
|
|
1283
|
+
const tier = report.metadata?.planType as string | undefined;
|
|
1284
|
+
const tierSuffix = tier ? ` ${uiTheme.fg("dim", `(${tier})`)}` : "";
|
|
1285
|
+
lines.push(
|
|
1286
|
+
`${uiTheme.fg("success", uiTheme.status.success)} ${label}${tierSuffix} ${uiTheme.fg("dim", "-- no limits")}`,
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
// No per-provider footer; global header shows last check.
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
return lines.join("\n");
|
|
1293
|
+
}
|