gsd-pi 2.77.0-dev.538325aea → 2.77.0-dev.eaa4973bc
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/dist/cli-web-branch.d.ts +1 -0
- package/dist/cli-web-branch.js +3 -0
- package/dist/cli.js +59 -15
- package/dist/extension-discovery.d.ts +6 -0
- package/dist/extension-discovery.js +37 -0
- package/dist/extension-registry.d.ts +3 -0
- package/dist/extension-registry.js +1 -1
- package/dist/extension-sort.d.ts +18 -0
- package/dist/extension-sort.js +114 -0
- package/dist/extension-validator.d.ts +47 -0
- package/dist/extension-validator.js +127 -0
- package/dist/headless-ui.d.ts +1 -1
- package/dist/headless.js +4 -2
- package/dist/loader.js +36 -7
- package/dist/onboarding.js +5 -5
- package/dist/provider-migrations.d.ts +20 -2
- package/dist/provider-migrations.js +15 -2
- package/dist/remote-questions-config.js +1 -1
- package/dist/resources/extensions/async-jobs/async-bash-tool.js +1 -1
- package/dist/resources/extensions/aws-auth/index.js +1 -2
- package/dist/resources/extensions/bg-shell/bg-shell-lifecycle.js +9 -6
- package/dist/resources/extensions/bg-shell/process-manager.js +1 -2
- package/dist/resources/extensions/browser-tools/index.js +1 -0
- package/dist/resources/extensions/claude-code-cli/index.js +1 -1
- package/dist/resources/extensions/claude-code-cli/partial-builder.js +17 -106
- package/dist/resources/extensions/claude-code-cli/stream-adapter.js +71 -57
- package/dist/resources/extensions/cmux/index.js +20 -0
- package/dist/resources/extensions/google-search/extension-manifest.json +5 -4
- package/dist/resources/extensions/google-search/index.js +2 -375
- package/dist/resources/extensions/gsd/abandon-detect.js +44 -0
- package/dist/resources/extensions/gsd/auto/resolve.js +24 -0
- package/dist/resources/extensions/gsd/auto/run-unit.js +10 -2
- package/dist/resources/extensions/gsd/auto/turn-epoch.js +95 -0
- package/dist/resources/extensions/gsd/auto-dispatch.js +24 -0
- package/dist/resources/extensions/gsd/auto-loop.js +1 -1
- package/dist/resources/extensions/gsd/auto-post-unit.js +31 -0
- package/dist/resources/extensions/gsd/auto-timeout-recovery.js +11 -5
- package/dist/resources/extensions/gsd/auto-unit-closeout.js +11 -2
- package/dist/resources/extensions/gsd/auto-worktree.js +58 -8
- package/dist/resources/extensions/gsd/auto.js +31 -14
- package/dist/resources/extensions/gsd/bootstrap/provider-error-resume.js +4 -2
- package/dist/resources/extensions/gsd/bootstrap/register-extension.js +11 -0
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +11 -6
- package/dist/resources/extensions/gsd/commands/handlers/workflow.js +31 -4
- package/dist/resources/extensions/gsd/commands-cmux.js +9 -6
- package/dist/resources/extensions/gsd/commands-extensions.js +634 -43
- package/dist/resources/extensions/gsd/file-lock.js +49 -9
- package/dist/resources/extensions/gsd/git-service.js +1 -0
- package/dist/resources/extensions/gsd/gitignore.js +1 -0
- package/dist/resources/extensions/gsd/guided-flow-queue.js +4 -1
- package/dist/resources/extensions/gsd/guided-flow.js +1 -1
- package/dist/resources/extensions/gsd/journal.js +17 -2
- package/dist/resources/extensions/gsd/milestone-actions.js +15 -0
- package/dist/resources/extensions/gsd/notifications.js +30 -16
- package/dist/resources/extensions/gsd/reports.js +5 -4
- package/dist/resources/extensions/gsd/tools/complete-slice.js +21 -0
- package/dist/resources/extensions/gsd/tools/complete-task.js +31 -0
- package/dist/resources/extensions/gsd/uok/audit.js +18 -2
- package/dist/resources/extensions/gsd/workflow-logger.js +10 -2
- package/dist/resources/extensions/gsd/worktree-manager.js +1 -0
- package/dist/resources/extensions/mcp-client/auth.js +10 -1
- package/dist/resources/extensions/mcp-client/index.js +119 -10
- package/dist/resources/extensions/ollama/index.js +2 -1
- package/dist/resources/extensions/ollama/ollama-chat-provider.js +15 -5
- package/dist/resources/extensions/remote-questions/config.js +1 -12
- package/dist/resources/extensions/shared/cmux-events.js +12 -0
- package/dist/resources/extensions/shared/rtk-session-stats.js +1 -2
- package/dist/resources/extensions/universal-config/index.js +1 -1
- package/dist/resources/skills/create-skill/SKILL.md +2 -2
- package/dist/resources/skills/create-skill/references/gsd-skill-ecosystem.md +4 -4
- package/dist/resources/skills/create-skill/workflows/audit-skill.md +4 -4
- package/dist/resources/skills/create-skill/workflows/create-new-skill.md +5 -5
- package/dist/security-overrides.d.ts +1 -4
- package/dist/security-overrides.js +3 -16
- package/dist/tsconfig.extensions.tsbuildinfo +1 -1
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +11 -11
- package/dist/web/standalone/.next/build-manifest.json +3 -3
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/react-loadable-manifest.json +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/api/boot/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/boot/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/captures/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/cleanup/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/doctor/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/export-data/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/files/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/files/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/forensics/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/git/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/history/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/hooks/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/inspect/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/inspect/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/knowledge/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/knowledge/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/live-state/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/live-state/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/notifications/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/notifications/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/onboarding/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/projects/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/projects/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/recovery/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/session/browser/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/browser/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/session/command/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/command/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/session/events/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/events/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/session/manage/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/session/manage/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/settings-data/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/skill-health/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/steer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/steer/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/switch-root/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/switch-root/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/input/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/resize/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/undo/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
- package/dist/web/standalone/.next/server/app/api/visualizer/route.js.nft.json +1 -1
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +11 -11
- package/dist/web/standalone/.next/server/chunks/1926.js +1 -0
- package/dist/web/standalone/.next/server/chunks/6897.js +2 -2
- package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
- package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
- package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +1 -1
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/dist/web/standalone/.next/static/chunks/2826.e9f5195e91f9cad2.js +11 -0
- package/dist/web/standalone/.next/static/chunks/{webpack-1832629448831fdc.js → webpack-2e68521d7c82f7c2.js} +1 -1
- package/dist/web-mode.js +1 -1
- package/dist/welcome-screen.js +20 -19
- package/dist/wizard.js +5 -2
- package/package.json +16 -32
- package/packages/mcp-server/README.md +3 -3
- package/packages/mcp-server/dist/env-writer.d.ts +1 -0
- package/packages/mcp-server/dist/env-writer.d.ts.map +1 -1
- package/packages/mcp-server/dist/env-writer.js +74 -6
- package/packages/mcp-server/dist/env-writer.js.map +1 -1
- package/packages/mcp-server/dist/server.d.ts.map +1 -1
- package/packages/mcp-server/dist/server.js +36 -17
- package/packages/mcp-server/dist/server.js.map +1 -1
- package/packages/mcp-server/package.json +5 -0
- package/packages/mcp-server/src/env-writer.test.ts +79 -1
- package/packages/mcp-server/src/env-writer.ts +76 -6
- package/packages/mcp-server/src/readers/readers.test.ts +5 -1
- package/packages/mcp-server/src/server.ts +45 -19
- package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
- package/packages/native/package.json +5 -0
- package/packages/native/src/__tests__/clipboard.test.mjs +69 -23
- package/packages/native/tsconfig.json +1 -2
- package/packages/native/tsconfig.tsbuildinfo +1 -0
- package/packages/pi-agent-core/package.json +5 -0
- package/packages/pi-agent-core/src/agent-loop.test.ts +220 -15
- package/packages/pi-ai/package.json +5 -0
- package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts +25 -0
- package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js +105 -6
- package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/compaction.test.js +230 -28
- package/packages/pi-coding-agent/dist/core/compaction/compaction.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts +30 -2
- package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction/utils.js +113 -12
- package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts +1 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js +29 -18
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.test.js +130 -0
- package/packages/pi-coding-agent/dist/core/compaction-orchestrator.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/compaction-utils.test.js +56 -1
- package/packages/pi-coding-agent/dist/core/compaction-utils.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/discovery-cache.test.js +8 -15
- package/packages/pi-coding-agent/dist/core/discovery-cache.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/extension-discovery.d.ts +25 -0
- package/packages/pi-coding-agent/dist/core/extensions/extension-discovery.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/extension-discovery.js +109 -0
- package/packages/pi-coding-agent/dist/core/extensions/extension-discovery.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/extension-registry.d.ts +67 -0
- package/packages/pi-coding-agent/dist/core/extensions/extension-registry.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/extension-registry.js +167 -0
- package/packages/pi-coding-agent/dist/core/extensions/extension-registry.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts +3 -2
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +24 -8
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +7 -0
- package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lsp-integration.test.js +11 -0
- package/packages/pi-coding-agent/dist/core/lsp/lsp-integration.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry-auth-mode.test.js +2 -2
- package/packages/pi-coding-agent/dist/core/model-registry-auth-mode.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.js +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.d.ts +1 -0
- package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.js +4 -1
- package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/sdk.test.js +19 -1
- package/packages/pi-coding-agent/dist/core/sdk.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js +3 -3
- package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/tools/path-utils.test.js +2 -1
- package/packages/pi-coding-agent/dist/core/tools/path-utils.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/provider-display-name.test.js +15 -6
- package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/provider-display-name.test.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js +14 -5
- package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.d.ts +7 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.js +31 -9
- package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.test.js +14 -0
- package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.test.js.map +1 -1
- package/packages/pi-coding-agent/package.json +5 -0
- package/packages/pi-coding-agent/src/core/compaction/compaction.test.ts +368 -28
- package/packages/pi-coding-agent/src/core/compaction/compaction.ts +122 -6
- package/packages/pi-coding-agent/src/core/compaction/utils.ts +111 -13
- package/packages/pi-coding-agent/src/core/compaction-orchestrator.test.ts +154 -0
- package/packages/pi-coding-agent/src/core/compaction-orchestrator.ts +32 -18
- package/packages/pi-coding-agent/src/core/compaction-utils.test.ts +68 -1
- package/packages/pi-coding-agent/src/core/discovery-cache.test.ts +9 -18
- package/packages/pi-coding-agent/src/core/extensions/extension-discovery.ts +119 -0
- package/packages/pi-coding-agent/src/core/extensions/extension-registry.ts +222 -0
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +24 -11
- package/packages/pi-coding-agent/src/core/extensions/types.ts +8 -0
- package/packages/pi-coding-agent/src/core/lsp/lsp-integration.test.ts +13 -0
- package/packages/pi-coding-agent/src/core/model-registry-auth-mode.test.ts +2 -2
- package/packages/pi-coding-agent/src/core/resource-loader.ts +1 -1
- package/packages/pi-coding-agent/src/core/sdk.test.ts +25 -1
- package/packages/pi-coding-agent/src/core/sdk.ts +10 -3
- package/packages/pi-coding-agent/src/core/system-prompt.ts +3 -3
- package/packages/pi-coding-agent/src/core/tools/path-utils.test.ts +2 -1
- package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/provider-display-name.test.ts +17 -7
- package/packages/pi-coding-agent/src/modes/interactive/components/footer.ts +14 -5
- package/packages/pi-coding-agent/src/modes/interactive/components/model-selector.ts +45 -11
- package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.test.ts +14 -0
- package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
- package/packages/pi-tui/dist/__tests__/autocomplete.test.js +12 -5
- package/packages/pi-tui/dist/__tests__/autocomplete.test.js.map +1 -1
- package/packages/pi-tui/dist/__tests__/stdin-buffer.test.js +19 -0
- package/packages/pi-tui/dist/__tests__/stdin-buffer.test.js.map +1 -1
- package/packages/pi-tui/dist/stdin-buffer.d.ts +7 -0
- package/packages/pi-tui/dist/stdin-buffer.d.ts.map +1 -1
- package/packages/pi-tui/dist/stdin-buffer.js +20 -0
- package/packages/pi-tui/dist/stdin-buffer.js.map +1 -1
- package/packages/pi-tui/package.json +5 -0
- package/packages/pi-tui/src/__tests__/autocomplete.test.ts +20 -5
- package/packages/pi-tui/src/__tests__/stdin-buffer.test.ts +25 -0
- package/packages/pi-tui/src/stdin-buffer.ts +26 -0
- package/packages/pi-tui/tsconfig.tsbuildinfo +1 -1
- package/packages/rpc-client/package.json +5 -0
- package/pkg/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/pkg/dist/core/export-html/ansi-to-html.js +0 -1
- package/pkg/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/pkg/dist/core/export-html/index.d.ts +1 -1
- package/pkg/dist/core/export-html/index.d.ts.map +1 -1
- package/pkg/dist/core/export-html/index.js +5 -39
- package/pkg/dist/core/export-html/index.js.map +1 -1
- package/pkg/dist/core/export-html/tool-renderer.d.ts +2 -2
- package/pkg/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/pkg/dist/core/export-html/tool-renderer.js.map +1 -1
- package/scripts/ensure-workspace-builds.cjs +0 -2
- package/scripts/lib/workspace-manifest.cjs +86 -0
- package/scripts/link-workspace-packages.cjs +5 -19
- package/src/resources/extensions/async-jobs/async-bash-tool.ts +1 -1
- package/src/resources/extensions/aws-auth/index.ts +1 -2
- package/src/resources/extensions/bg-shell/bg-shell-lifecycle.ts +7 -4
- package/src/resources/extensions/bg-shell/index.ts +1 -2
- package/src/resources/extensions/bg-shell/process-manager.ts +1 -2
- package/src/resources/extensions/browser-tools/index.ts +1 -2
- package/src/resources/extensions/claude-code-cli/index.ts +1 -1
- package/src/resources/extensions/claude-code-cli/partial-builder.ts +23 -115
- package/src/resources/extensions/claude-code-cli/stream-adapter.ts +81 -61
- package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +91 -22
- package/src/resources/extensions/cmux/index.ts +35 -10
- package/src/resources/extensions/google-search/extension-manifest.json +5 -4
- package/src/resources/extensions/google-search/index.ts +8 -470
- package/src/resources/extensions/gsd/abandon-detect.ts +62 -0
- package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -1
- package/src/resources/extensions/gsd/auto/resolve.ts +29 -0
- package/src/resources/extensions/gsd/auto/run-unit.ts +16 -2
- package/src/resources/extensions/gsd/auto/turn-epoch.ts +108 -0
- package/src/resources/extensions/gsd/auto/types.ts +1 -1
- package/src/resources/extensions/gsd/auto-dispatch.ts +20 -0
- package/src/resources/extensions/gsd/auto-loop.ts +1 -1
- package/src/resources/extensions/gsd/auto-post-unit.ts +30 -0
- package/src/resources/extensions/gsd/auto-timeout-recovery.ts +12 -5
- package/src/resources/extensions/gsd/auto-unit-closeout.ts +14 -3
- package/src/resources/extensions/gsd/auto-worktree.ts +60 -5
- package/src/resources/extensions/gsd/auto.ts +37 -18
- package/src/resources/extensions/gsd/bootstrap/provider-error-resume.ts +6 -2
- package/src/resources/extensions/gsd/bootstrap/register-extension.ts +11 -0
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +13 -9
- package/src/resources/extensions/gsd/commands/handlers/workflow.ts +27 -8
- package/src/resources/extensions/gsd/commands-cmux.ts +10 -6
- package/src/resources/extensions/gsd/commands-extensions.ts +747 -41
- package/src/resources/extensions/gsd/file-lock.ts +84 -11
- package/src/resources/extensions/gsd/git-service.ts +1 -0
- package/src/resources/extensions/gsd/gitignore.ts +1 -0
- package/src/resources/extensions/gsd/guided-flow-queue.ts +4 -1
- package/src/resources/extensions/gsd/guided-flow.ts +1 -1
- package/src/resources/extensions/gsd/journal.ts +27 -2
- package/src/resources/extensions/gsd/milestone-actions.ts +18 -0
- package/src/resources/extensions/gsd/notifications.ts +27 -15
- package/src/resources/extensions/gsd/reports.ts +5 -4
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +11 -2
- package/src/resources/extensions/gsd/tests/auto-mode-guards.test.ts +79 -0
- package/src/resources/extensions/gsd/tests/cmux.test.ts +5 -9
- package/src/resources/extensions/gsd/tests/file-lock.test.ts +86 -12
- package/src/resources/extensions/gsd/tests/google-search-stub.test.ts +121 -0
- package/src/resources/extensions/gsd/tests/integration/auto-worktree-milestone-merge.test.ts +30 -0
- package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +3 -2
- package/src/resources/extensions/gsd/tests/mcp-client-security.test.ts +76 -0
- package/src/resources/extensions/gsd/tests/milestone-transition-state-rebuild.test.ts +4 -2
- package/src/resources/extensions/gsd/tests/parallel-commit-scope.test.ts +5 -0
- package/src/resources/extensions/gsd/tests/parallel-skill-prompt-integration.test.ts +150 -0
- package/src/resources/extensions/gsd/tests/provider-errors.test.ts +39 -25
- package/src/resources/extensions/gsd/tests/queue-auto-guard.test.ts +181 -0
- package/src/resources/extensions/gsd/tests/quick-auto-guard.test.ts +13 -7
- package/src/resources/extensions/gsd/tests/require-slice-discussion-dispatch.test.ts +170 -0
- package/src/resources/extensions/gsd/tests/rewrite-docs-abandon-detect.test.ts +195 -0
- package/src/resources/extensions/gsd/tests/stuck-detection-coverage.test.ts +2 -2
- package/src/resources/extensions/gsd/tests/triage-resolution.test.ts +50 -2
- package/src/resources/extensions/gsd/tests/turn-epoch.test.ts +162 -0
- package/src/resources/extensions/gsd/tests/validate-extension-package.test.ts +168 -0
- package/src/resources/extensions/gsd/tests/workflow-mcp.test.ts +25 -2
- package/src/resources/extensions/gsd/tools/complete-slice.ts +38 -0
- package/src/resources/extensions/gsd/tools/complete-task.ts +49 -0
- package/src/resources/extensions/gsd/uok/audit.ts +20 -2
- package/src/resources/extensions/gsd/workflow-logger.ts +22 -3
- package/src/resources/extensions/gsd/worktree-manager.ts +1 -0
- package/src/resources/extensions/mcp-client/auth.ts +12 -1
- package/src/resources/extensions/mcp-client/index.ts +130 -11
- package/src/resources/extensions/ollama/index.ts +3 -3
- package/src/resources/extensions/ollama/ollama-chat-provider.ts +18 -6
- package/src/resources/extensions/remote-questions/config.ts +4 -15
- package/src/resources/extensions/search-the-web/index.ts +1 -2
- package/src/resources/extensions/shared/cmux-events.ts +59 -0
- package/src/resources/extensions/shared/rtk-session-stats.ts +1 -2
- package/src/resources/extensions/shared/tests/format-utils.test.ts +3 -5
- package/src/resources/extensions/universal-config/index.ts +1 -1
- package/src/resources/skills/create-skill/SKILL.md +2 -2
- package/src/resources/skills/create-skill/references/gsd-skill-ecosystem.md +4 -4
- package/src/resources/skills/create-skill/workflows/audit-skill.md +4 -4
- package/src/resources/skills/create-skill/workflows/create-new-skill.md +5 -5
- package/dist/web/standalone/.next/server/chunks/7461.js +0 -1
- package/dist/web/standalone/.next/static/chunks/2826.d445fb428ef41fa1.js +0 -9
- package/packages/gsd-agent-core/dist/agent-session.d.ts +0 -716
- package/packages/gsd-agent-core/dist/agent-session.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/agent-session.js +0 -2595
- package/packages/gsd-agent-core/dist/agent-session.js.map +0 -1
- package/packages/gsd-agent-core/dist/artifact-manager.d.ts +0 -52
- package/packages/gsd-agent-core/dist/artifact-manager.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/artifact-manager.js +0 -118
- package/packages/gsd-agent-core/dist/artifact-manager.js.map +0 -1
- package/packages/gsd-agent-core/dist/bash-executor.d.ts +0 -57
- package/packages/gsd-agent-core/dist/bash-executor.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/bash-executor.js +0 -282
- package/packages/gsd-agent-core/dist/bash-executor.js.map +0 -1
- package/packages/gsd-agent-core/dist/blob-store.d.ts +0 -39
- package/packages/gsd-agent-core/dist/blob-store.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/blob-store.js +0 -151
- package/packages/gsd-agent-core/dist/blob-store.js.map +0 -1
- package/packages/gsd-agent-core/dist/compaction/branch-summarization.d.ts +0 -90
- package/packages/gsd-agent-core/dist/compaction/branch-summarization.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/compaction/branch-summarization.js +0 -207
- package/packages/gsd-agent-core/dist/compaction/branch-summarization.js.map +0 -1
- package/packages/gsd-agent-core/dist/compaction/compaction.d.ts +0 -137
- package/packages/gsd-agent-core/dist/compaction/compaction.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/compaction/compaction.js +0 -621
- package/packages/gsd-agent-core/dist/compaction/compaction.js.map +0 -1
- package/packages/gsd-agent-core/dist/compaction/index.d.ts +0 -7
- package/packages/gsd-agent-core/dist/compaction/index.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/compaction/index.js +0 -7
- package/packages/gsd-agent-core/dist/compaction/index.js.map +0 -1
- package/packages/gsd-agent-core/dist/compaction/utils.d.ts +0 -78
- package/packages/gsd-agent-core/dist/compaction/utils.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/compaction/utils.js +0 -263
- package/packages/gsd-agent-core/dist/compaction/utils.js.map +0 -1
- package/packages/gsd-agent-core/dist/compaction-orchestrator.d.ts +0 -90
- package/packages/gsd-agent-core/dist/compaction-orchestrator.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/compaction-orchestrator.js +0 -338
- package/packages/gsd-agent-core/dist/compaction-orchestrator.js.map +0 -1
- package/packages/gsd-agent-core/dist/contextual-tips.d.ts +0 -43
- package/packages/gsd-agent-core/dist/contextual-tips.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/contextual-tips.js +0 -208
- package/packages/gsd-agent-core/dist/contextual-tips.js.map +0 -1
- package/packages/gsd-agent-core/dist/export-html/ansi-to-html.d.ts +0 -18
- package/packages/gsd-agent-core/dist/export-html/ansi-to-html.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/export-html/ansi-to-html.js +0 -250
- package/packages/gsd-agent-core/dist/export-html/ansi-to-html.js.map +0 -1
- package/packages/gsd-agent-core/dist/export-html/index.d.ts +0 -37
- package/packages/gsd-agent-core/dist/export-html/index.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/export-html/index.js +0 -257
- package/packages/gsd-agent-core/dist/export-html/index.js.map +0 -1
- package/packages/gsd-agent-core/dist/export-html/template.css +0 -971
- package/packages/gsd-agent-core/dist/export-html/template.html +0 -54
- package/packages/gsd-agent-core/dist/export-html/template.js +0 -1583
- package/packages/gsd-agent-core/dist/export-html/tool-renderer.d.ts +0 -38
- package/packages/gsd-agent-core/dist/export-html/tool-renderer.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/export-html/tool-renderer.js +0 -70
- package/packages/gsd-agent-core/dist/export-html/tool-renderer.js.map +0 -1
- package/packages/gsd-agent-core/dist/export-html/vendor/highlight.min.js +0 -1213
- package/packages/gsd-agent-core/dist/export-html/vendor/marked.min.js +0 -6
- package/packages/gsd-agent-core/dist/fallback-resolver.d.ts +0 -75
- package/packages/gsd-agent-core/dist/fallback-resolver.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/fallback-resolver.js +0 -118
- package/packages/gsd-agent-core/dist/fallback-resolver.js.map +0 -1
- package/packages/gsd-agent-core/dist/image-overflow-recovery.d.ts +0 -44
- package/packages/gsd-agent-core/dist/image-overflow-recovery.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/image-overflow-recovery.js +0 -99
- package/packages/gsd-agent-core/dist/image-overflow-recovery.js.map +0 -1
- package/packages/gsd-agent-core/dist/index.d.ts +0 -14
- package/packages/gsd-agent-core/dist/index.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/index.js +0 -19
- package/packages/gsd-agent-core/dist/index.js.map +0 -1
- package/packages/gsd-agent-core/dist/keybindings.d.ts +0 -47
- package/packages/gsd-agent-core/dist/keybindings.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/keybindings.js +0 -156
- package/packages/gsd-agent-core/dist/keybindings.js.map +0 -1
- package/packages/gsd-agent-core/dist/lifecycle-hooks.d.ts +0 -42
- package/packages/gsd-agent-core/dist/lifecycle-hooks.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/lifecycle-hooks.js +0 -204
- package/packages/gsd-agent-core/dist/lifecycle-hooks.js.map +0 -1
- package/packages/gsd-agent-core/dist/retry-handler.d.ts +0 -128
- package/packages/gsd-agent-core/dist/retry-handler.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/retry-handler.js +0 -518
- package/packages/gsd-agent-core/dist/retry-handler.js.map +0 -1
- package/packages/gsd-agent-core/dist/sdk.d.ts +0 -159
- package/packages/gsd-agent-core/dist/sdk.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/sdk.js +0 -375
- package/packages/gsd-agent-core/dist/sdk.js.map +0 -1
- package/packages/gsd-agent-core/dist/system-prompt.d.ts +0 -28
- package/packages/gsd-agent-core/dist/system-prompt.d.ts.map +0 -1
- package/packages/gsd-agent-core/dist/system-prompt.js +0 -201
- package/packages/gsd-agent-core/dist/system-prompt.js.map +0 -1
- package/packages/gsd-agent-core/package.json +0 -25
- package/packages/gsd-agent-core/scripts/copy-assets.cjs +0 -43
- package/packages/gsd-agent-core/src/agent-session.test.ts +0 -169
- package/packages/gsd-agent-core/src/agent-session.ts +0 -3358
- package/packages/gsd-agent-core/src/artifact-manager.ts +0 -126
- package/packages/gsd-agent-core/src/bash-executor.ts +0 -352
- package/packages/gsd-agent-core/src/blob-store.ts +0 -154
- package/packages/gsd-agent-core/src/compaction/branch-summarization.ts +0 -317
- package/packages/gsd-agent-core/src/compaction/compaction.ts +0 -855
- package/packages/gsd-agent-core/src/compaction/index.ts +0 -7
- package/packages/gsd-agent-core/src/compaction/utils.ts +0 -312
- package/packages/gsd-agent-core/src/compaction-orchestrator.ts +0 -449
- package/packages/gsd-agent-core/src/contextual-tips.ts +0 -232
- package/packages/gsd-agent-core/src/export-html/ansi-to-html.ts +0 -259
- package/packages/gsd-agent-core/src/export-html/index.ts +0 -345
- package/packages/gsd-agent-core/src/export-html/template.css +0 -971
- package/packages/gsd-agent-core/src/export-html/template.html +0 -54
- package/packages/gsd-agent-core/src/export-html/template.js +0 -1583
- package/packages/gsd-agent-core/src/export-html/tool-renderer.ts +0 -114
- package/packages/gsd-agent-core/src/export-html/vendor/highlight.min.js +0 -1213
- package/packages/gsd-agent-core/src/export-html/vendor/marked.min.js +0 -6
- package/packages/gsd-agent-core/src/fallback-resolver.ts +0 -193
- package/packages/gsd-agent-core/src/image-overflow-recovery.ts +0 -120
- package/packages/gsd-agent-core/src/index.ts +0 -68
- package/packages/gsd-agent-core/src/keybindings.ts +0 -220
- package/packages/gsd-agent-core/src/lifecycle-hooks.ts +0 -284
- package/packages/gsd-agent-core/src/retry-handler.ts +0 -620
- package/packages/gsd-agent-core/src/sdk.ts +0 -550
- package/packages/gsd-agent-core/src/system-prompt.ts +0 -270
- package/packages/gsd-agent-core/tsconfig.json +0 -28
- package/packages/gsd-agent-core/tsconfig.tsbuildinfo +0 -1
- package/packages/gsd-agent-modes/dist/cli/args.d.ts +0 -58
- package/packages/gsd-agent-modes/dist/cli/args.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/args.js +0 -324
- package/packages/gsd-agent-modes/dist/cli/args.js.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/config-selector.d.ts +0 -13
- package/packages/gsd-agent-modes/dist/cli/config-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/config-selector.js +0 -32
- package/packages/gsd-agent-modes/dist/cli/config-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/file-processor.d.ts +0 -15
- package/packages/gsd-agent-modes/dist/cli/file-processor.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/file-processor.js +0 -86
- package/packages/gsd-agent-modes/dist/cli/file-processor.js.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/list-models.d.ts +0 -21
- package/packages/gsd-agent-modes/dist/cli/list-models.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/list-models.js +0 -114
- package/packages/gsd-agent-modes/dist/cli/list-models.js.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/session-picker.d.ts +0 -10
- package/packages/gsd-agent-modes/dist/cli/session-picker.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/cli/session-picker.js +0 -37
- package/packages/gsd-agent-modes/dist/cli/session-picker.js.map +0 -1
- package/packages/gsd-agent-modes/dist/index.d.ts +0 -7
- package/packages/gsd-agent-modes/dist/index.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/index.js +0 -7
- package/packages/gsd-agent-modes/dist/index.js.map +0 -1
- package/packages/gsd-agent-modes/dist/main.d.ts +0 -8
- package/packages/gsd-agent-modes/dist/main.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/main.js +0 -491
- package/packages/gsd-agent-modes/dist/main.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.d.ts +0 -34
- package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.js +0 -330
- package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.d.ts +0 -29
- package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.js +0 -141
- package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.d.ts +0 -36
- package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.js +0 -157
- package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.d.ts +0 -16
- package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.js +0 -48
- package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.d.ts +0 -16
- package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.js +0 -43
- package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.d.ts +0 -11
- package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.js +0 -47
- package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.d.ts +0 -16
- package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.js +0 -44
- package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.d.ts +0 -71
- package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.js +0 -474
- package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.d.ts +0 -15
- package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.js +0 -32
- package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.d.ts +0 -22
- package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.js +0 -70
- package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.d.ts +0 -20
- package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.js +0 -75
- package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.d.ts +0 -23
- package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.js +0 -140
- package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.d.ts +0 -12
- package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.js +0 -133
- package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.d.ts +0 -33
- package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.js +0 -82
- package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.d.ts +0 -20
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.js +0 -111
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.d.ts +0 -24
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.js +0 -63
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.d.ts +0 -33
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.js +0 -118
- package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.d.ts +0 -32
- package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.js +0 -230
- package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/index.d.ts +0 -34
- package/packages/gsd-agent-modes/dist/modes/interactive/components/index.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/index.js +0 -36
- package/packages/gsd-agent-modes/dist/modes/interactive/components/index.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.d.ts +0 -48
- package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.js +0 -72
- package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.d.ts +0 -63
- package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.js +0 -213
- package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.d.ts +0 -86
- package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.js +0 -536
- package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.d.ts +0 -19
- package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.js +0 -93
- package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.d.ts +0 -30
- package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.js +0 -169
- package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.d.ts +0 -49
- package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.js +0 -267
- package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.d.ts +0 -21
- package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.js +0 -155
- package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.d.ts +0 -97
- package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.js +0 -810
- package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts +0 -71
- package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js +0 -320
- package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.d.ts +0 -10
- package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.js +0 -34
- package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.d.ts +0 -17
- package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.js +0 -46
- package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.d.ts +0 -11
- package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.js +0 -45
- package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.d.ts +0 -11
- package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.js +0 -46
- package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.d.ts +0 -15
- package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.js +0 -40
- package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts +0 -111
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +0 -984
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.d.ts +0 -44
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.js +0 -61
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.d.ts +0 -109
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.js +0 -1035
- package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.d.ts +0 -30
- package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.js +0 -112
- package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.d.ts +0 -12
- package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.js +0 -38
- package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.d.ts +0 -24
- package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.js +0 -33
- package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts +0 -27
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +0 -793
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.d.ts +0 -4
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.js +0 -62
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.d.ts +0 -22
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.js +0 -118
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.d.ts +0 -7
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.js +0 -68
- package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts +0 -50
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js +0 -2
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts +0 -358
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js +0 -3409
- package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.d.ts +0 -77
- package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.js +0 -529
- package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.d.ts +0 -6
- package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.js +0 -15
- package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/print-mode.d.ts +0 -28
- package/packages/gsd-agent-modes/dist/modes/print-mode.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/print-mode.js +0 -84
- package/packages/gsd-agent-modes/dist/modes/print-mode.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.d.ts +0 -17
- package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.js +0 -49
- package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.d.ts +0 -37
- package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.js +0 -84
- package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.d.ts +0 -243
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.js +0 -464
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts +0 -25
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js +0 -750
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.d.ts +0 -511
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.js +0 -8
- package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.js.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.d.ts +0 -19
- package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.js +0 -45
- package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.js.map +0 -1
- package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.d.ts +0 -22
- package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.js +0 -21
- package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.js.map +0 -1
- package/packages/gsd-agent-modes/dist/pi-tui-compat.d.ts +0 -4
- package/packages/gsd-agent-modes/dist/pi-tui-compat.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/pi-tui-compat.js +0 -3
- package/packages/gsd-agent-modes/dist/pi-tui-compat.js.map +0 -1
- package/packages/gsd-agent-modes/dist/theme.d.ts +0 -15
- package/packages/gsd-agent-modes/dist/theme.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/theme.js +0 -23
- package/packages/gsd-agent-modes/dist/theme.js.map +0 -1
- package/packages/gsd-agent-modes/dist/utils/theme.d.ts +0 -16
- package/packages/gsd-agent-modes/dist/utils/theme.d.ts.map +0 -1
- package/packages/gsd-agent-modes/dist/utils/theme.js +0 -11
- package/packages/gsd-agent-modes/dist/utils/theme.js.map +0 -1
- package/packages/gsd-agent-modes/package.json +0 -23
- package/packages/gsd-agent-modes/src/cli/args.ts +0 -350
- package/packages/gsd-agent-modes/src/cli/config-selector.ts +0 -54
- package/packages/gsd-agent-modes/src/cli/file-processor.ts +0 -107
- package/packages/gsd-agent-modes/src/cli/list-models.ts +0 -141
- package/packages/gsd-agent-modes/src/cli/session-picker.ts +0 -59
- package/packages/gsd-agent-modes/src/index.ts +0 -6
- package/packages/gsd-agent-modes/src/main.ts +0 -614
- package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/login-dialog.test.ts +0 -24
- package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/provider-display-name.test.ts +0 -18
- package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/timestamp.test.ts +0 -38
- package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/tool-execution.test.ts +0 -171
- package/packages/gsd-agent-modes/src/modes/interactive/components/armin.ts +0 -382
- package/packages/gsd-agent-modes/src/modes/interactive/components/assistant-message.ts +0 -178
- package/packages/gsd-agent-modes/src/modes/interactive/components/bash-execution.ts +0 -212
- package/packages/gsd-agent-modes/src/modes/interactive/components/bordered-loader.ts +0 -66
- package/packages/gsd-agent-modes/src/modes/interactive/components/branch-summary-message.ts +0 -59
- package/packages/gsd-agent-modes/src/modes/interactive/components/chat-frame.ts +0 -67
- package/packages/gsd-agent-modes/src/modes/interactive/components/compaction-summary-message.ts +0 -60
- package/packages/gsd-agent-modes/src/modes/interactive/components/config-selector.ts +0 -597
- package/packages/gsd-agent-modes/src/modes/interactive/components/countdown-timer.ts +0 -41
- package/packages/gsd-agent-modes/src/modes/interactive/components/custom-editor.ts +0 -88
- package/packages/gsd-agent-modes/src/modes/interactive/components/custom-message.ts +0 -100
- package/packages/gsd-agent-modes/src/modes/interactive/components/daxnuts.ts +0 -165
- package/packages/gsd-agent-modes/src/modes/interactive/components/diff.ts +0 -147
- package/packages/gsd-agent-modes/src/modes/interactive/components/dynamic-border.test.ts +0 -73
- package/packages/gsd-agent-modes/src/modes/interactive/components/dynamic-border.ts +0 -89
- package/packages/gsd-agent-modes/src/modes/interactive/components/extension-editor.ts +0 -151
- package/packages/gsd-agent-modes/src/modes/interactive/components/extension-input.ts +0 -100
- package/packages/gsd-agent-modes/src/modes/interactive/components/extension-selector.ts +0 -156
- package/packages/gsd-agent-modes/src/modes/interactive/components/footer.ts +0 -257
- package/packages/gsd-agent-modes/src/modes/interactive/components/index.ts +0 -35
- package/packages/gsd-agent-modes/src/modes/interactive/components/keybinding-hints.ts +0 -84
- package/packages/gsd-agent-modes/src/modes/interactive/components/login-dialog.ts +0 -257
- package/packages/gsd-agent-modes/src/modes/interactive/components/model-selector.ts +0 -656
- package/packages/gsd-agent-modes/src/modes/interactive/components/oauth-selector.ts +0 -122
- package/packages/gsd-agent-modes/src/modes/interactive/components/provider-manager.ts +0 -210
- package/packages/gsd-agent-modes/src/modes/interactive/components/scoped-models-selector.ts +0 -342
- package/packages/gsd-agent-modes/src/modes/interactive/components/session-selector-search.ts +0 -194
- package/packages/gsd-agent-modes/src/modes/interactive/components/session-selector.ts +0 -1011
- package/packages/gsd-agent-modes/src/modes/interactive/components/settings-selector.ts +0 -452
- package/packages/gsd-agent-modes/src/modes/interactive/components/show-images-selector.ts +0 -45
- package/packages/gsd-agent-modes/src/modes/interactive/components/skill-invocation-message.ts +0 -56
- package/packages/gsd-agent-modes/src/modes/interactive/components/theme-selector.ts +0 -63
- package/packages/gsd-agent-modes/src/modes/interactive/components/thinking-selector.ts +0 -64
- package/packages/gsd-agent-modes/src/modes/interactive/components/timestamp.ts +0 -48
- package/packages/gsd-agent-modes/src/modes/interactive/components/tool-execution.ts +0 -1157
- package/packages/gsd-agent-modes/src/modes/interactive/components/tree-render-utils.ts +0 -81
- package/packages/gsd-agent-modes/src/modes/interactive/components/tree-selector.ts +0 -1208
- package/packages/gsd-agent-modes/src/modes/interactive/components/user-message-selector.ts +0 -145
- package/packages/gsd-agent-modes/src/modes/interactive/components/user-message.ts +0 -44
- package/packages/gsd-agent-modes/src/modes/interactive/components/visual-truncate.ts +0 -50
- package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller-ordering.test.ts +0 -1430
- package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller.test.ts +0 -71
- package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller.ts +0 -957
- package/packages/gsd-agent-modes/src/modes/interactive/controllers/extension-ui-controller.ts +0 -63
- package/packages/gsd-agent-modes/src/modes/interactive/controllers/input-controller.test.ts +0 -183
- package/packages/gsd-agent-modes/src/modes/interactive/controllers/input-controller.ts +0 -140
- package/packages/gsd-agent-modes/src/modes/interactive/controllers/model-controller.ts +0 -77
- package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode-ordering.test.ts +0 -44
- package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode-state.ts +0 -49
- package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode.ts +0 -4195
- package/packages/gsd-agent-modes/src/modes/interactive/slash-command-handlers.ts +0 -670
- package/packages/gsd-agent-modes/src/modes/interactive/utils/shorten-path.ts +0 -14
- package/packages/gsd-agent-modes/src/modes/print-mode.ts +0 -106
- package/packages/gsd-agent-modes/src/modes/rpc/jsonl.ts +0 -58
- package/packages/gsd-agent-modes/src/modes/rpc/remote-terminal.ts +0 -109
- package/packages/gsd-agent-modes/src/modes/rpc/rpc-client.ts +0 -572
- package/packages/gsd-agent-modes/src/modes/rpc/rpc-mode.ts +0 -902
- package/packages/gsd-agent-modes/src/modes/rpc/rpc-protocol-v2.test.ts +0 -971
- package/packages/gsd-agent-modes/src/modes/rpc/rpc-types.ts +0 -335
- package/packages/gsd-agent-modes/src/modes/shared/command-context-actions.ts +0 -53
- package/packages/gsd-agent-modes/src/pi-coding-agent-compat.ts +0 -42
- package/packages/gsd-agent-modes/src/pi-tui-compat.ts +0 -4
- package/packages/gsd-agent-modes/src/theme.ts +0 -25
- package/packages/gsd-agent-modes/src/utils/theme.ts +0 -24
- package/packages/gsd-agent-modes/tsconfig.json +0 -28
- package/packages/gsd-agent-modes/tsconfig.tsbuildinfo +0 -1
- package/packages/gsd-agent-types/dist/index.d.ts +0 -176
- package/packages/gsd-agent-types/dist/index.d.ts.map +0 -1
- package/packages/gsd-agent-types/dist/index.js +0 -24
- package/packages/gsd-agent-types/dist/index.js.map +0 -1
- package/packages/gsd-agent-types/package.json +0 -24
- package/packages/gsd-agent-types/src/index.ts +0 -206
- package/packages/gsd-agent-types/tsconfig.json +0 -25
- package/packages/gsd-agent-types/tsconfig.tsbuildinfo +0 -1
- package/packages/native/dist/tsconfig.tsbuildinfo +0 -1
- package/src/resources/extensions/claude-code-cli/tests/provider-registration.test.ts +0 -27
- /package/dist/web/standalone/.next/static/{gy6_foLMsEzdGBT19c3hr → 5wbu35_C2_MQ3Jj1lEVDx}/_buildManifest.js +0 -0
- /package/dist/web/standalone/.next/static/{gy6_foLMsEzdGBT19c3hr → 5wbu35_C2_MQ3Jj1lEVDx}/_ssgManifest.js +0 -0
|
@@ -1,4195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interactive mode for the coding agent.
|
|
3
|
-
* Handles TUI rendering and user interaction, delegating business logic to AgentSession.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as crypto from "node:crypto";
|
|
7
|
-
import * as fs from "node:fs";
|
|
8
|
-
import * as os from "node:os";
|
|
9
|
-
import * as path from "node:path";
|
|
10
|
-
import { listDescendants } from "@gsd/native";
|
|
11
|
-
import type { AgentMessage } from "@gsd/pi-agent-core";
|
|
12
|
-
import type { Api, AssistantMessage, ImageContent, Message, Model, OAuthProviderId } from "@gsd/pi-ai";
|
|
13
|
-
import type {
|
|
14
|
-
AutocompleteItem,
|
|
15
|
-
EditorComponent,
|
|
16
|
-
EditorTheme,
|
|
17
|
-
KeyId,
|
|
18
|
-
MarkdownTheme,
|
|
19
|
-
OverlayHandle,
|
|
20
|
-
OverlayOptions,
|
|
21
|
-
SlashCommand,
|
|
22
|
-
} from "@gsd/pi-tui";
|
|
23
|
-
import {
|
|
24
|
-
CombinedAutocompleteProvider,
|
|
25
|
-
type Component,
|
|
26
|
-
Container,
|
|
27
|
-
fuzzyFilter,
|
|
28
|
-
Loader,
|
|
29
|
-
Markdown,
|
|
30
|
-
matchesKey,
|
|
31
|
-
ProcessTerminal,
|
|
32
|
-
Spacer,
|
|
33
|
-
type Terminal as TuiTerminal,
|
|
34
|
-
Text,
|
|
35
|
-
TruncatedText,
|
|
36
|
-
TUI,
|
|
37
|
-
visibleWidth,
|
|
38
|
-
} from "@gsd/pi-tui";
|
|
39
|
-
import { spawn, spawnSync } from "child_process";
|
|
40
|
-
import { VERSION } from "@gsd/pi-coding-agent";
|
|
41
|
-
import type { AgentSession, AgentSessionEvent } from "@gsd/agent-core";
|
|
42
|
-
import { parseSkillBlock } from "@gsd/pi-coding-agent";
|
|
43
|
-
import type { CompactionResult } from "@gsd/agent-types";
|
|
44
|
-
import { isServerToolUseBlock, isWebSearchResultBlock } from "@gsd/agent-types";
|
|
45
|
-
import type {
|
|
46
|
-
ExtensionContext,
|
|
47
|
-
ExtensionRunner,
|
|
48
|
-
ExtensionUIContext,
|
|
49
|
-
ExtensionUIDialogOptions,
|
|
50
|
-
ExtensionWidgetOptions,
|
|
51
|
-
} from "@gsd/agent-types";
|
|
52
|
-
import type { ReadonlyFooterDataProvider } from "@gsd/agent-types";
|
|
53
|
-
import type { AppAction } from "@gsd/agent-types";
|
|
54
|
-
import { KeybindingsManager } from "@gsd/agent-core";
|
|
55
|
-
import type { ResourceDiagnostic } from "@gsd/agent-types";
|
|
56
|
-
import { SessionManager } from "@gsd/pi-coding-agent";
|
|
57
|
-
import type { SessionContext } from "@gsd/agent-types";
|
|
58
|
-
import type { TruncationResult } from "@gsd/agent-types";
|
|
59
|
-
import type { RegisteredCommand } from "@gsd/pi-coding-agent";
|
|
60
|
-
import { AssistantMessageComponent } from "./components/assistant-message.js";
|
|
61
|
-
import { BashExecutionComponent } from "./components/bash-execution.js";
|
|
62
|
-
import { BorderedLoader } from "./components/bordered-loader.js";
|
|
63
|
-
import { BranchSummaryMessageComponent } from "./components/branch-summary-message.js";
|
|
64
|
-
import { CompactionSummaryMessageComponent } from "./components/compaction-summary-message.js";
|
|
65
|
-
import { CustomEditor } from "./components/custom-editor.js";
|
|
66
|
-
import { CustomMessageComponent } from "./components/custom-message.js";
|
|
67
|
-
import { DaxnutsComponent } from "./components/daxnuts.js";
|
|
68
|
-
import { DynamicBorder } from "./components/dynamic-border.js";
|
|
69
|
-
import { ExtensionEditorComponent } from "./components/extension-editor.js";
|
|
70
|
-
import { ExtensionInputComponent } from "./components/extension-input.js";
|
|
71
|
-
import { ExtensionSelectorComponent } from "./components/extension-selector.js";
|
|
72
|
-
import { FooterComponent } from "./components/footer.js";
|
|
73
|
-
import { appKey, appKeyHint, keyHint, rawKeyHint } from "./components/keybinding-hints.js";
|
|
74
|
-
import { LoginDialogComponent } from "./components/login-dialog.js";
|
|
75
|
-
import { ModelSelectorComponent, providerDisplayName } from "./components/model-selector.js";
|
|
76
|
-
import { OAuthSelectorComponent } from "./components/oauth-selector.js";
|
|
77
|
-
import { ProviderManagerComponent } from "./components/provider-manager.js";
|
|
78
|
-
import { ScopedModelsSelectorComponent } from "./components/scoped-models-selector.js";
|
|
79
|
-
import { SessionSelectorComponent } from "./components/session-selector.js";
|
|
80
|
-
import { SettingsSelectorComponent } from "./components/settings-selector.js";
|
|
81
|
-
import { SkillInvocationMessageComponent } from "./components/skill-invocation-message.js";
|
|
82
|
-
import { ToolExecutionComponent } from "./components/tool-execution.js";
|
|
83
|
-
import type { TimestampFormat } from "./components/timestamp.js";
|
|
84
|
-
import { TreeSelectorComponent } from "./components/tree-selector.js";
|
|
85
|
-
import { UserMessageComponent } from "./components/user-message.js";
|
|
86
|
-
import { UserMessageSelectorComponent } from "./components/user-message-selector.js";
|
|
87
|
-
import {
|
|
88
|
-
APP_NAME,
|
|
89
|
-
BUILTIN_SLASH_COMMANDS,
|
|
90
|
-
ContextualTips,
|
|
91
|
-
FooterDataProvider,
|
|
92
|
-
createCompactionSummaryMessage,
|
|
93
|
-
ensureTool,
|
|
94
|
-
extensionForImageMimeType,
|
|
95
|
-
getAuthPath,
|
|
96
|
-
getChangelogPath,
|
|
97
|
-
getDebugLogPath,
|
|
98
|
-
getNewEntries,
|
|
99
|
-
getUpdateInstruction,
|
|
100
|
-
parseChangelog,
|
|
101
|
-
readClipboardImage,
|
|
102
|
-
resolveModelScope,
|
|
103
|
-
} from "../../pi-coding-agent-compat.js";
|
|
104
|
-
import type { InteractiveModeStateHost } from "./interactive-mode-state.js";
|
|
105
|
-
import { type SlashCommandContext, getAppKeyDisplay } from "./slash-command-handlers.js";
|
|
106
|
-
import { handleAgentEvent } from "./controllers/chat-controller.js";
|
|
107
|
-
import { createExtensionUIContext as buildExtensionUIContext } from "./controllers/extension-ui-controller.js";
|
|
108
|
-
import { setupEditorSubmitHandler as setupEditorSubmitHandlerController } from "./controllers/input-controller.js";
|
|
109
|
-
import {
|
|
110
|
-
findExactModelMatch as findExactModelMatchController,
|
|
111
|
-
getModelCandidates as getModelCandidatesController,
|
|
112
|
-
handleModelCommand as handleModelCommandController,
|
|
113
|
-
updateAvailableProviderCount as updateAvailableProviderCountController,
|
|
114
|
-
} from "./controllers/model-controller.js";
|
|
115
|
-
import {
|
|
116
|
-
getMarkdownTheme,
|
|
117
|
-
initTheme,
|
|
118
|
-
Theme,
|
|
119
|
-
type ThemeColor,
|
|
120
|
-
} from "@gsd/pi-coding-agent";
|
|
121
|
-
import { getAvailableThemes, getEditorTheme, onThemeChange, setRegisteredThemes, setTheme, stopThemeWatcher } from "../../pi-coding-agent-compat.js";
|
|
122
|
-
import { theme } from "../../theme.js";
|
|
123
|
-
|
|
124
|
-
/** Interface for components that can be expanded/collapsed */
|
|
125
|
-
interface Expandable {
|
|
126
|
-
setExpanded(expanded: boolean): void;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function isExpandable(obj: unknown): obj is Expandable {
|
|
130
|
-
return typeof obj === "object" && obj !== null && "setExpanded" in obj && typeof obj.setExpanded === "function";
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Extension interface for SettingsManager — covers optional GSD-specific methods
|
|
135
|
-
* that exist on the concrete runtime instance but are not in the base SettingsManager
|
|
136
|
-
* interface (added by GSD without modifying pi-coding-agent).
|
|
137
|
-
*/
|
|
138
|
-
interface GSDSettingsManager {
|
|
139
|
-
getTimestampFormat?(): TimestampFormat | undefined;
|
|
140
|
-
setTimestampFormat?(format: TimestampFormat): void;
|
|
141
|
-
getRespectGitignoreInPicker?(): boolean;
|
|
142
|
-
setRespectGitignoreInPicker?(enabled: boolean): void;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Extension interface for CombinedAutocompleteProvider — covers optional
|
|
147
|
-
* GSD-specific methods not in the public type.
|
|
148
|
-
*/
|
|
149
|
-
interface GSDAutocompleteProvider {
|
|
150
|
-
setRespectGitignore?(enabled: boolean): void;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Extension interface for ResourceLoader — covers getPathMetadata which exists
|
|
155
|
-
* on DefaultResourceLoader but not on the ResourceLoader interface.
|
|
156
|
-
*/
|
|
157
|
-
interface GSDResourceLoader {
|
|
158
|
-
getPathMetadata?(): import("@gsd/agent-types").PathMetadata | undefined;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Extension interface for SessionManager — covers wasInterrupted which exists
|
|
163
|
-
* on the concrete SessionManager but not on the type.
|
|
164
|
-
*/
|
|
165
|
-
interface GSDSessionManager {
|
|
166
|
-
wasInterrupted?(): boolean;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Extension interface for ExtensionUIDialogOptions — covers the secure flag used
|
|
171
|
-
* by showExtensionInput but absent from the base pi-coding-agent type.
|
|
172
|
-
*/
|
|
173
|
-
interface GSDExtensionUIDialogOptions extends ExtensionUIDialogOptions {
|
|
174
|
-
secure?: boolean;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Extension interface for Container — covers detachChildren() which exists on the
|
|
179
|
-
* concrete pi-tui Container at runtime but is not in the public interface type.
|
|
180
|
-
*/
|
|
181
|
-
interface GSDContainer {
|
|
182
|
-
detachChildren?(): void;
|
|
183
|
-
clear(): void;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Extension interface for ModelRegistry — covers optional GSD-specific methods
|
|
188
|
-
* (discoverModels, getApiKeyForProvider) that exist on the concrete runtime class
|
|
189
|
-
* but are not in the ModelRegistry interface type.
|
|
190
|
-
*/
|
|
191
|
-
interface GSDModelRegistry {
|
|
192
|
-
discoverModels?(providers: string[]): Promise<Array<{ error?: string; models?: Array<unknown> }>>;
|
|
193
|
-
getApiKeyForProvider?(provider: string): Promise<string | undefined>;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Extension callback error type — covers optional stack field on extension errors
|
|
198
|
-
* (present at runtime but not in ExtensionErrorListener callback type).
|
|
199
|
-
*/
|
|
200
|
-
interface GSDExtensionCallbackError {
|
|
201
|
-
extensionPath: string;
|
|
202
|
-
event: string;
|
|
203
|
-
error: string;
|
|
204
|
-
stack?: string;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export type AssistantReplaySegment =
|
|
208
|
-
| { kind: "assistant"; startIndex: number; endIndex: number }
|
|
209
|
-
| { kind: "tool"; contentIndex: number };
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Build replay segments for historical assistant messages so rebuild paths
|
|
213
|
-
* preserve the original content[] ordering between assistant prose and tools.
|
|
214
|
-
*/
|
|
215
|
-
export function buildAssistantReplaySegments(contentBlocks: Array<unknown>): AssistantReplaySegment[] {
|
|
216
|
-
const segments: AssistantReplaySegment[] = [];
|
|
217
|
-
let runStart = -1;
|
|
218
|
-
|
|
219
|
-
for (let i = 0; i < contentBlocks.length; i++) {
|
|
220
|
-
const block = contentBlocks[i];
|
|
221
|
-
const blockType = typeof block === "object" && block !== null && "type" in block ? (block as { type: unknown }).type : undefined;
|
|
222
|
-
const isAssistantText = blockType === "text" || blockType === "thinking";
|
|
223
|
-
const isTool = blockType === "toolCall" || blockType === "serverToolUse";
|
|
224
|
-
|
|
225
|
-
if (isAssistantText) {
|
|
226
|
-
if (runStart === -1) runStart = i;
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (runStart !== -1) {
|
|
231
|
-
segments.push({ kind: "assistant", startIndex: runStart, endIndex: i - 1 });
|
|
232
|
-
runStart = -1;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (isTool) {
|
|
236
|
-
segments.push({ kind: "tool", contentIndex: i });
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (runStart !== -1) {
|
|
241
|
-
segments.push({ kind: "assistant", startIndex: runStart, endIndex: contentBlocks.length - 1 });
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return segments;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
type CompactionQueuedMessage = {
|
|
248
|
-
text: string;
|
|
249
|
-
mode: "steer" | "followUp";
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Options for InteractiveMode initialization.
|
|
254
|
-
*/
|
|
255
|
-
export interface InteractiveModeOptions {
|
|
256
|
-
/** Providers that were migrated to auth.json (shows warning) */
|
|
257
|
-
migratedProviders?: string[];
|
|
258
|
-
/** Warning message if session model couldn't be restored */
|
|
259
|
-
modelFallbackMessage?: string;
|
|
260
|
-
/** Initial message to send on startup (can include @file content) */
|
|
261
|
-
initialMessage?: string;
|
|
262
|
-
/** Images to attach to the initial message */
|
|
263
|
-
initialImages?: ImageContent[];
|
|
264
|
-
/** Additional messages to send after the initial message */
|
|
265
|
-
initialMessages?: string[];
|
|
266
|
-
/** Force verbose startup (overrides quietStartup setting) */
|
|
267
|
-
verbose?: boolean;
|
|
268
|
-
/** Override the terminal implementation used by the TUI. */
|
|
269
|
-
terminal?: TuiTerminal;
|
|
270
|
-
/** When false, reuse the session's existing extension bindings instead of rebinding them for TUI mode. */
|
|
271
|
-
bindExtensions?: boolean;
|
|
272
|
-
/** Submit editor prompts directly to AgentSession instead of using the interactive prompt loop. */
|
|
273
|
-
submitPromptsDirectly?: boolean;
|
|
274
|
-
/** Control what happens when the user requests shutdown from the TUI. */
|
|
275
|
-
shutdownBehavior?: "exit_process" | "stop_ui" | "ignore";
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export class InteractiveMode {
|
|
279
|
-
// Cap rendered chat components to prevent unbounded memory/CPU growth.
|
|
280
|
-
// Only render-components are removed — session transcript stays on disk.
|
|
281
|
-
private static readonly MAX_CHAT_COMPONENTS = 100;
|
|
282
|
-
|
|
283
|
-
private session: AgentSession;
|
|
284
|
-
private ui: TUI;
|
|
285
|
-
private chatContainer: Container;
|
|
286
|
-
private pendingMessagesContainer: Container;
|
|
287
|
-
private statusContainer: Container;
|
|
288
|
-
private pinnedMessageContainer: Container;
|
|
289
|
-
private defaultEditor: CustomEditor;
|
|
290
|
-
private editor: EditorComponent;
|
|
291
|
-
private autocompleteProvider: CombinedAutocompleteProvider | undefined;
|
|
292
|
-
private editorContainer: Container;
|
|
293
|
-
private footer: FooterComponent;
|
|
294
|
-
private footerDataProvider: FooterDataProvider;
|
|
295
|
-
private keybindings: KeybindingsManager;
|
|
296
|
-
private version: string;
|
|
297
|
-
private isInitialized = false;
|
|
298
|
-
private onInputCallback?: (text: string) => void;
|
|
299
|
-
private loadingAnimation: Loader | undefined = undefined;
|
|
300
|
-
private pendingWorkingMessage: string | undefined = undefined;
|
|
301
|
-
private readonly defaultWorkingMessage = "Working...";
|
|
302
|
-
|
|
303
|
-
private lastSigintTime = 0;
|
|
304
|
-
private lastEscapeTime = 0;
|
|
305
|
-
private changelogMarkdown: string | undefined = undefined;
|
|
306
|
-
|
|
307
|
-
// Status line tracking (for mutating immediately-sequential status updates)
|
|
308
|
-
private lastStatusSpacer: Spacer | undefined = undefined;
|
|
309
|
-
private lastStatusText: Text | undefined = undefined;
|
|
310
|
-
|
|
311
|
-
// Streaming message tracking
|
|
312
|
-
private streamingComponent: AssistantMessageComponent | undefined = undefined;
|
|
313
|
-
private streamingMessage: AssistantMessage | undefined = undefined;
|
|
314
|
-
|
|
315
|
-
// Tool execution tracking: toolCallId -> component
|
|
316
|
-
private pendingTools = new Map<string, ToolExecutionComponent>();
|
|
317
|
-
|
|
318
|
-
// Tool output expansion state
|
|
319
|
-
private toolOutputExpanded = false;
|
|
320
|
-
|
|
321
|
-
// Thinking block visibility state
|
|
322
|
-
private hideThinkingBlock = false;
|
|
323
|
-
|
|
324
|
-
// Skill commands: command name -> skill file path
|
|
325
|
-
private skillCommands = new Map<string, string>();
|
|
326
|
-
|
|
327
|
-
// Agent subscription unsubscribe function
|
|
328
|
-
private unsubscribe?: () => void;
|
|
329
|
-
|
|
330
|
-
// Branch change listener unsubscribe function
|
|
331
|
-
private _branchChangeUnsub?: () => void;
|
|
332
|
-
|
|
333
|
-
// Track if editor is in bash mode (text starts with !)
|
|
334
|
-
private isBashMode = false;
|
|
335
|
-
|
|
336
|
-
// Contextual tips — session-scoped, non-intrusive hints
|
|
337
|
-
private contextualTips = new ContextualTips();
|
|
338
|
-
|
|
339
|
-
// Track current bash execution component
|
|
340
|
-
private bashComponent: BashExecutionComponent | undefined = undefined;
|
|
341
|
-
|
|
342
|
-
// Track pending bash components (shown in pending area, moved to chat on submit)
|
|
343
|
-
private pendingBashComponents: BashExecutionComponent[] = [];
|
|
344
|
-
|
|
345
|
-
// Auto-compaction state
|
|
346
|
-
private autoCompactionLoader: Loader | undefined = undefined;
|
|
347
|
-
private autoCompactionEscapeHandler?: () => void;
|
|
348
|
-
|
|
349
|
-
// Auto-retry state
|
|
350
|
-
private retryLoader: Loader | undefined = undefined;
|
|
351
|
-
private retryEscapeHandler?: () => void;
|
|
352
|
-
|
|
353
|
-
// Messages queued while compaction is running
|
|
354
|
-
private compactionQueuedMessages: CompactionQueuedMessage[] = [];
|
|
355
|
-
|
|
356
|
-
// Shutdown state
|
|
357
|
-
private shutdownRequested = false;
|
|
358
|
-
|
|
359
|
-
// Extension UI state
|
|
360
|
-
private extensionSelector: ExtensionSelectorComponent | undefined = undefined;
|
|
361
|
-
private extensionInput: ExtensionInputComponent | undefined = undefined;
|
|
362
|
-
private extensionEditor: ExtensionEditorComponent | undefined = undefined;
|
|
363
|
-
private extensionTerminalInputUnsubscribers = new Set<() => void>();
|
|
364
|
-
|
|
365
|
-
// Extension widgets (components rendered above/below the editor)
|
|
366
|
-
private extensionWidgetsAbove = new Map<string, Component & { dispose?(): void }>();
|
|
367
|
-
private extensionWidgetsBelow = new Map<string, Component & { dispose?(): void }>();
|
|
368
|
-
private widgetContainerAbove!: Container;
|
|
369
|
-
private widgetContainerBelow!: Container;
|
|
370
|
-
|
|
371
|
-
// Custom footer from extension (undefined = use built-in footer)
|
|
372
|
-
private customFooter: (Component & { dispose?(): void }) | undefined = undefined;
|
|
373
|
-
|
|
374
|
-
// Header container that holds the built-in or custom header
|
|
375
|
-
private headerContainer: Container;
|
|
376
|
-
|
|
377
|
-
// Built-in header (logo + keybinding hints + changelog)
|
|
378
|
-
private builtInHeader: Component | undefined = undefined;
|
|
379
|
-
|
|
380
|
-
// Custom header from extension (undefined = use built-in header)
|
|
381
|
-
private customHeader: (Component & { dispose?(): void }) | undefined = undefined;
|
|
382
|
-
|
|
383
|
-
// Convenience accessors
|
|
384
|
-
private get agent(): AgentSession["agent"] {
|
|
385
|
-
return this.session.agent;
|
|
386
|
-
}
|
|
387
|
-
private get sessionManager(): AgentSession["sessionManager"] {
|
|
388
|
-
return this.session.sessionManager;
|
|
389
|
-
}
|
|
390
|
-
private get settingsManager(): AgentSession["settingsManager"] {
|
|
391
|
-
return this.session.settingsManager;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
constructor(
|
|
395
|
-
session: AgentSession,
|
|
396
|
-
private options: InteractiveModeOptions = {},
|
|
397
|
-
) {
|
|
398
|
-
this.session = session;
|
|
399
|
-
this.version = VERSION;
|
|
400
|
-
this.ui = new TUI(options.terminal ?? new ProcessTerminal(), this.settingsManager.getShowHardwareCursor());
|
|
401
|
-
this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
|
|
402
|
-
this.headerContainer = new Container();
|
|
403
|
-
this.chatContainer = new Container();
|
|
404
|
-
this.pendingMessagesContainer = new Container();
|
|
405
|
-
this.statusContainer = new Container();
|
|
406
|
-
this.pinnedMessageContainer = new Container();
|
|
407
|
-
this.widgetContainerAbove = new Container();
|
|
408
|
-
this.widgetContainerBelow = new Container();
|
|
409
|
-
this.keybindings = KeybindingsManager.create();
|
|
410
|
-
const editorPaddingX = this.settingsManager.getEditorPaddingX();
|
|
411
|
-
const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
|
|
412
|
-
this.defaultEditor = new CustomEditor(this.ui, getEditorTheme(), this.keybindings, {
|
|
413
|
-
paddingX: editorPaddingX,
|
|
414
|
-
autocompleteMaxVisible,
|
|
415
|
-
});
|
|
416
|
-
this.editor = this.defaultEditor;
|
|
417
|
-
this.editorContainer = new Container();
|
|
418
|
-
this.editorContainer.addChild(this.editor as Component);
|
|
419
|
-
this.footerDataProvider = new FooterDataProvider();
|
|
420
|
-
/* vendor-seam: dual-module-path — AgentSession resolves to @gsd/pi-coding-agent in FooterComponent but @gsd/agent-core here */
|
|
421
|
-
this.footer = new FooterComponent(session as unknown as import("@gsd/pi-coding-agent").AgentSession, this.footerDataProvider);
|
|
422
|
-
this.footer.setAutoCompactEnabled(session.autoCompactionEnabled);
|
|
423
|
-
|
|
424
|
-
// Load hide thinking block setting
|
|
425
|
-
this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
|
|
426
|
-
|
|
427
|
-
// Register themes from resource loader and initialize
|
|
428
|
-
/* vendor-seam: dual-module-path — Theme resolves differently through ResourceLoader vs setRegisteredThemes import path */
|
|
429
|
-
setRegisteredThemes(this.session.resourceLoader.getThemes().themes as unknown as Parameters<typeof setRegisteredThemes>[0]);
|
|
430
|
-
initTheme(this.settingsManager.getTheme(), true);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
private setupAutocomplete(): void {
|
|
434
|
-
// Define commands for autocomplete
|
|
435
|
-
const slashCommands: SlashCommand[] = BUILTIN_SLASH_COMMANDS.map((command) => ({
|
|
436
|
-
name: command.name,
|
|
437
|
-
description: command.description,
|
|
438
|
-
}));
|
|
439
|
-
|
|
440
|
-
const modelCommand = slashCommands.find((command) => command.name === "model");
|
|
441
|
-
if (modelCommand) {
|
|
442
|
-
modelCommand.getArgumentCompletions = (prefix: string): AutocompleteItem[] | null => {
|
|
443
|
-
// Get available models (scoped or from registry)
|
|
444
|
-
const models =
|
|
445
|
-
this.session.scopedModels.length > 0
|
|
446
|
-
? this.session.scopedModels.map((s) => s.model)
|
|
447
|
-
: this.session.modelRegistry.getAvailable();
|
|
448
|
-
|
|
449
|
-
if (models.length === 0) return null;
|
|
450
|
-
|
|
451
|
-
// Create items with provider/id format
|
|
452
|
-
const items = models.map((m) => ({
|
|
453
|
-
id: m.id,
|
|
454
|
-
provider: m.provider,
|
|
455
|
-
label: `${m.provider}/${m.id}`,
|
|
456
|
-
}));
|
|
457
|
-
|
|
458
|
-
// Fuzzy filter by model ID + provider (allows "opus anthropic" to match)
|
|
459
|
-
const filtered = fuzzyFilter(items, prefix, (item) => `${item.id} ${item.provider}`);
|
|
460
|
-
|
|
461
|
-
if (filtered.length === 0) return null;
|
|
462
|
-
|
|
463
|
-
return filtered.map((item) => ({
|
|
464
|
-
value: item.label,
|
|
465
|
-
label: item.id,
|
|
466
|
-
description: providerDisplayName(item.provider),
|
|
467
|
-
}));
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// Add argument completions for /thinking
|
|
472
|
-
const thinkingCommand = slashCommands.find((command) => command.name === "thinking");
|
|
473
|
-
if (thinkingCommand) {
|
|
474
|
-
thinkingCommand.getArgumentCompletions = (prefix: string): AutocompleteItem[] | null => {
|
|
475
|
-
const levels = [
|
|
476
|
-
{ value: "off", label: "off", description: "Disable extended thinking" },
|
|
477
|
-
{ value: "minimal", label: "minimal", description: "Minimal thinking budget" },
|
|
478
|
-
{ value: "low", label: "low", description: "Low thinking budget" },
|
|
479
|
-
{ value: "medium", label: "medium", description: "Medium thinking budget" },
|
|
480
|
-
{ value: "high", label: "high", description: "High thinking budget" },
|
|
481
|
-
{ value: "xhigh", label: "xhigh", description: "Maximum thinking budget" },
|
|
482
|
-
];
|
|
483
|
-
const filtered = levels.filter((l) => l.value.startsWith(prefix.trim().toLowerCase()));
|
|
484
|
-
return filtered.length > 0 ? filtered : null;
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// Convert prompt templates to SlashCommand format for autocomplete
|
|
489
|
-
const templateCommands: SlashCommand[] = this.session.promptTemplates.map((cmd) => ({
|
|
490
|
-
name: cmd.name,
|
|
491
|
-
description: cmd.description,
|
|
492
|
-
}));
|
|
493
|
-
|
|
494
|
-
// Convert extension commands to SlashCommand format
|
|
495
|
-
const builtinCommandNames = new Set(slashCommands.map((c) => c.name));
|
|
496
|
-
const extensionCommands: SlashCommand[] = (
|
|
497
|
-
this.session.extensionRunner?.getRegisteredCommands() ?? []
|
|
498
|
-
).filter((cmd: RegisteredCommand) => !builtinCommandNames.has(cmd.name)).map((cmd: RegisteredCommand) => ({
|
|
499
|
-
name: cmd.name,
|
|
500
|
-
description: cmd.description ?? "(extension command)",
|
|
501
|
-
getArgumentCompletions: cmd.getArgumentCompletions,
|
|
502
|
-
}));
|
|
503
|
-
|
|
504
|
-
// Build skill commands from session.skills (if enabled)
|
|
505
|
-
this.skillCommands.clear();
|
|
506
|
-
const skillCommandList: SlashCommand[] = [];
|
|
507
|
-
if (this.settingsManager.getEnableSkillCommands()) {
|
|
508
|
-
for (const skill of this.session.resourceLoader.getSkills().skills) {
|
|
509
|
-
const commandName = `skill:${skill.name}`;
|
|
510
|
-
this.skillCommands.set(commandName, skill.filePath);
|
|
511
|
-
skillCommandList.push({ name: commandName, description: skill.description });
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// Setup autocomplete
|
|
516
|
-
this.autocompleteProvider = new CombinedAutocompleteProvider(
|
|
517
|
-
[...slashCommands, ...templateCommands, ...extensionCommands, ...skillCommandList],
|
|
518
|
-
process.cwd(),
|
|
519
|
-
);
|
|
520
|
-
this.defaultEditor.setAutocompleteProvider(this.autocompleteProvider);
|
|
521
|
-
if (this.editor !== this.defaultEditor) {
|
|
522
|
-
this.editor.setAutocompleteProvider?.(this.autocompleteProvider);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
async init(): Promise<void> {
|
|
527
|
-
if (this.isInitialized) return;
|
|
528
|
-
|
|
529
|
-
// Load changelog (only show new entries, skip for resumed sessions)
|
|
530
|
-
this.changelogMarkdown = this.getChangelogForDisplay();
|
|
531
|
-
|
|
532
|
-
// Ensure rg is available (downloads if missing, adds to PATH via getBinDir)
|
|
533
|
-
// rg is needed for grep tool and bash commands
|
|
534
|
-
await ensureTool("rg");
|
|
535
|
-
|
|
536
|
-
// Add header container as first child
|
|
537
|
-
this.ui.addChild(this.headerContainer);
|
|
538
|
-
|
|
539
|
-
// Add header with keybindings from config (unless silenced)
|
|
540
|
-
if (this.options.verbose || !this.settingsManager.getQuietStartup()) {
|
|
541
|
-
const logo = theme.bold(theme.fg("accent", APP_NAME)) + theme.fg("dim", ` v${this.version}`);
|
|
542
|
-
|
|
543
|
-
// Build startup instructions using keybinding hint helpers
|
|
544
|
-
const kb = this.keybindings;
|
|
545
|
-
const hint = (action: AppAction, desc: string): string => appKeyHint(kb, action, desc);
|
|
546
|
-
|
|
547
|
-
const instructions = [
|
|
548
|
-
hint("interrupt", "to interrupt"),
|
|
549
|
-
hint("clear", "to clear"),
|
|
550
|
-
rawKeyHint(`${appKey(kb, "clear")} twice`, "to exit"),
|
|
551
|
-
hint("exit", "to exit (empty)"),
|
|
552
|
-
hint("suspend", "to suspend"),
|
|
553
|
-
keyHint("deleteToLineEnd", "to delete to end"),
|
|
554
|
-
hint("cycleThinkingLevel", "to cycle thinking level"),
|
|
555
|
-
rawKeyHint(`${appKey(kb, "cycleModelForward")}/${appKey(kb, "cycleModelBackward")}`, "to cycle models"),
|
|
556
|
-
hint("selectModel", "to select model"),
|
|
557
|
-
hint("expandTools", "to expand tools"),
|
|
558
|
-
hint("toggleThinking", "to expand thinking"),
|
|
559
|
-
hint("externalEditor", "for external editor"),
|
|
560
|
-
rawKeyHint("/", "for commands"),
|
|
561
|
-
rawKeyHint("!", "to run bash"),
|
|
562
|
-
rawKeyHint("!!", "to run bash (no context)"),
|
|
563
|
-
hint("followUp", "to queue follow-up"),
|
|
564
|
-
hint("dequeue", "to edit all queued messages"),
|
|
565
|
-
hint("pasteImage", "to paste image"),
|
|
566
|
-
rawKeyHint("drop files", "to attach"),
|
|
567
|
-
].join("\n");
|
|
568
|
-
this.builtInHeader = new Text(`${logo}\n${instructions}`, 1, 0);
|
|
569
|
-
|
|
570
|
-
// Setup UI layout
|
|
571
|
-
this.headerContainer.addChild(new Spacer(1));
|
|
572
|
-
this.headerContainer.addChild(this.builtInHeader);
|
|
573
|
-
this.headerContainer.addChild(new Spacer(1));
|
|
574
|
-
|
|
575
|
-
// Add changelog if provided
|
|
576
|
-
if (this.changelogMarkdown) {
|
|
577
|
-
this.headerContainer.addChild(new DynamicBorder());
|
|
578
|
-
if (this.settingsManager.getCollapseChangelog()) {
|
|
579
|
-
const versionMatch = this.changelogMarkdown.match(/##\s+\[?(\d+\.\d+\.\d+)\]?/);
|
|
580
|
-
const latestVersion = versionMatch ? versionMatch[1] : this.version;
|
|
581
|
-
const condensedText = `Updated to v${latestVersion}. Use ${theme.bold("/changelog")} to view full changelog.`;
|
|
582
|
-
this.headerContainer.addChild(new Text(condensedText, 1, 0));
|
|
583
|
-
} else {
|
|
584
|
-
this.headerContainer.addChild(new Text(theme.bold(theme.fg("accent", "What's New")), 1, 0));
|
|
585
|
-
this.headerContainer.addChild(new Spacer(1));
|
|
586
|
-
this.headerContainer.addChild(
|
|
587
|
-
new Markdown(this.changelogMarkdown.trim(), 1, 0, this.getMarkdownThemeWithSettings()),
|
|
588
|
-
);
|
|
589
|
-
this.headerContainer.addChild(new Spacer(1));
|
|
590
|
-
}
|
|
591
|
-
this.headerContainer.addChild(new DynamicBorder());
|
|
592
|
-
}
|
|
593
|
-
} else {
|
|
594
|
-
// Minimal header when silenced
|
|
595
|
-
this.builtInHeader = new Text("", 0, 0);
|
|
596
|
-
this.headerContainer.addChild(this.builtInHeader);
|
|
597
|
-
if (this.changelogMarkdown) {
|
|
598
|
-
// Still show changelog notification even in silent mode
|
|
599
|
-
this.headerContainer.addChild(new Spacer(1));
|
|
600
|
-
const versionMatch = this.changelogMarkdown.match(/##\s+\[?(\d+\.\d+\.\d+)\]?/);
|
|
601
|
-
const latestVersion = versionMatch ? versionMatch[1] : this.version;
|
|
602
|
-
const condensedText = `Updated to v${latestVersion}. Use ${theme.bold("/changelog")} to view full changelog.`;
|
|
603
|
-
this.headerContainer.addChild(new Text(condensedText, 1, 0));
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
this.ui.addChild(this.chatContainer);
|
|
608
|
-
this.ui.addChild(this.pendingMessagesContainer);
|
|
609
|
-
this.ui.addChild(this.statusContainer);
|
|
610
|
-
this.ui.addChild(this.pinnedMessageContainer);
|
|
611
|
-
this.renderWidgets(); // Initialize with default spacer
|
|
612
|
-
this.ui.addChild(this.widgetContainerAbove);
|
|
613
|
-
this.ui.addChild(this.editorContainer);
|
|
614
|
-
this.ui.addChild(this.widgetContainerBelow);
|
|
615
|
-
this.ui.addChild(this.footer);
|
|
616
|
-
this.ui.setFocus(this.editor);
|
|
617
|
-
|
|
618
|
-
this.setupKeyHandlers();
|
|
619
|
-
this.setupEditorSubmitHandler();
|
|
620
|
-
|
|
621
|
-
// Initialize extensions first so resources are shown before messages
|
|
622
|
-
await this.initExtensions();
|
|
623
|
-
|
|
624
|
-
// Render initial messages AFTER showing loaded resources
|
|
625
|
-
this.renderInitialMessages();
|
|
626
|
-
|
|
627
|
-
// Start the UI
|
|
628
|
-
this.ui.start();
|
|
629
|
-
this.isInitialized = true;
|
|
630
|
-
|
|
631
|
-
// Set terminal title
|
|
632
|
-
this.updateTerminalTitle();
|
|
633
|
-
|
|
634
|
-
// Subscribe to agent events
|
|
635
|
-
this.subscribeToAgent();
|
|
636
|
-
|
|
637
|
-
// Set up theme file watcher
|
|
638
|
-
onThemeChange(() => {
|
|
639
|
-
this.ui.invalidate();
|
|
640
|
-
this.updateEditorBorderColor();
|
|
641
|
-
this.ui.requestRender();
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
// Set up git branch watcher (uses provider instead of footer)
|
|
645
|
-
this._branchChangeUnsub = this.footerDataProvider.onBranchChange(() => {
|
|
646
|
-
this.ui.requestRender();
|
|
647
|
-
});
|
|
648
|
-
|
|
649
|
-
// Initialize available provider count for footer display
|
|
650
|
-
await this.updateAvailableProviderCount();
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* Update terminal title with session name and cwd.
|
|
655
|
-
*/
|
|
656
|
-
private updateTerminalTitle(): void {
|
|
657
|
-
const cwdBasename = path.basename(process.cwd());
|
|
658
|
-
const sessionName = this.sessionManager.getSessionName();
|
|
659
|
-
if (sessionName) {
|
|
660
|
-
this.ui.terminal.setTitle(`π - ${sessionName} - ${cwdBasename}`);
|
|
661
|
-
} else {
|
|
662
|
-
this.ui.terminal.setTitle(`π - ${cwdBasename}`);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
/**
|
|
667
|
-
* Run the interactive mode. This is the main entry point.
|
|
668
|
-
* Initializes the UI, shows warnings, processes initial messages, and starts the interactive loop.
|
|
669
|
-
*/
|
|
670
|
-
async run(): Promise<void> {
|
|
671
|
-
await this.init();
|
|
672
|
-
|
|
673
|
-
// Start version check asynchronously
|
|
674
|
-
this.checkForNewVersion().then((newVersion) => {
|
|
675
|
-
if (newVersion) {
|
|
676
|
-
this.showNewVersionNotification(newVersion);
|
|
677
|
-
}
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
// Check tmux keyboard setup asynchronously
|
|
681
|
-
this.checkTmuxKeyboardSetup().then((warning) => {
|
|
682
|
-
if (warning) {
|
|
683
|
-
this.showWarning(warning);
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
// Show startup warnings
|
|
688
|
-
const { migratedProviders, modelFallbackMessage, initialMessage, initialImages, initialMessages } = this.options;
|
|
689
|
-
|
|
690
|
-
if (migratedProviders && migratedProviders.length > 0) {
|
|
691
|
-
this.showWarning(`Migrated credentials to auth.json: ${migratedProviders.join(", ")}`);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
const modelsJsonError = this.session.modelRegistry.getError();
|
|
695
|
-
if (modelsJsonError) {
|
|
696
|
-
this.showError(`models.json error: ${modelsJsonError}`);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
if (modelFallbackMessage) {
|
|
700
|
-
this.showWarning(modelFallbackMessage);
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// Process initial messages
|
|
704
|
-
if (initialMessage) {
|
|
705
|
-
try {
|
|
706
|
-
await this.session.prompt(initialMessage, { images: initialImages });
|
|
707
|
-
} catch (error: unknown) {
|
|
708
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
709
|
-
this.showError(errorMessage);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
if (initialMessages) {
|
|
714
|
-
for (const message of initialMessages) {
|
|
715
|
-
try {
|
|
716
|
-
await this.session.prompt(message);
|
|
717
|
-
} catch (error: unknown) {
|
|
718
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
719
|
-
this.showError(errorMessage);
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
// Main interactive loop
|
|
725
|
-
while (true) {
|
|
726
|
-
const userInput = await this.getUserInput();
|
|
727
|
-
try {
|
|
728
|
-
await this.session.prompt(userInput);
|
|
729
|
-
} catch (error: unknown) {
|
|
730
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
731
|
-
this.showError(errorMessage);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
/**
|
|
737
|
-
* Check npm registry for a newer version.
|
|
738
|
-
*/
|
|
739
|
-
private async checkForNewVersion(): Promise<string | undefined> {
|
|
740
|
-
if (process.env.PI_SKIP_VERSION_CHECK || process.env.PI_OFFLINE) return undefined;
|
|
741
|
-
|
|
742
|
-
try {
|
|
743
|
-
const response = await fetch("https://registry.npmjs.org/@gsd/pi-coding-agent/latest", {
|
|
744
|
-
signal: AbortSignal.timeout(10000),
|
|
745
|
-
});
|
|
746
|
-
if (!response.ok) return undefined;
|
|
747
|
-
|
|
748
|
-
const data = (await response.json()) as { version?: string };
|
|
749
|
-
const latestVersion = data.version;
|
|
750
|
-
|
|
751
|
-
if (latestVersion && latestVersion !== this.version) {
|
|
752
|
-
return latestVersion;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
return undefined;
|
|
756
|
-
} catch {
|
|
757
|
-
return undefined;
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
private async checkTmuxKeyboardSetup(): Promise<string | undefined> {
|
|
762
|
-
if (!process.env.TMUX) return undefined;
|
|
763
|
-
|
|
764
|
-
const runTmuxShow = (option: string): Promise<string | undefined> => {
|
|
765
|
-
return new Promise((resolve) => {
|
|
766
|
-
const proc = spawn("tmux", ["show", "-gv", option], {
|
|
767
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
768
|
-
});
|
|
769
|
-
let stdout = "";
|
|
770
|
-
const timer = setTimeout(() => {
|
|
771
|
-
proc.kill();
|
|
772
|
-
resolve(undefined);
|
|
773
|
-
}, 2000);
|
|
774
|
-
|
|
775
|
-
proc.stdout?.on("data", (data) => {
|
|
776
|
-
stdout += data.toString();
|
|
777
|
-
});
|
|
778
|
-
proc.on("error", () => {
|
|
779
|
-
clearTimeout(timer);
|
|
780
|
-
resolve(undefined);
|
|
781
|
-
});
|
|
782
|
-
proc.on("close", (code) => {
|
|
783
|
-
clearTimeout(timer);
|
|
784
|
-
resolve(code === 0 ? stdout.trim() : undefined);
|
|
785
|
-
});
|
|
786
|
-
});
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
const [extendedKeys, extendedKeysFormat] = await Promise.all([
|
|
790
|
-
runTmuxShow("extended-keys"),
|
|
791
|
-
runTmuxShow("extended-keys-format"),
|
|
792
|
-
]);
|
|
793
|
-
|
|
794
|
-
if (extendedKeys !== "on" && extendedKeys !== "always") {
|
|
795
|
-
return "tmux extended-keys is off. Modified Enter keys may not work. Add `set -g extended-keys on` to ~/.tmux.conf and restart tmux.";
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
if (extendedKeysFormat === "xterm") {
|
|
799
|
-
return "tmux extended-keys-format is xterm. Pi works best with csi-u. Add `set -g extended-keys-format csi-u` to ~/.tmux.conf and restart tmux.";
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
return undefined;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
/**
|
|
806
|
-
* Get changelog entries to display on startup.
|
|
807
|
-
* Only shows new entries since last seen version, skips for resumed sessions.
|
|
808
|
-
*/
|
|
809
|
-
private getChangelogForDisplay(): string | undefined {
|
|
810
|
-
// Skip changelog for resumed/continued sessions (already have messages)
|
|
811
|
-
if (this.session.state.messages.length > 0) {
|
|
812
|
-
return undefined;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
const lastVersion = this.settingsManager.getLastChangelogVersion();
|
|
816
|
-
const changelogPath = getChangelogPath();
|
|
817
|
-
const entries = parseChangelog(changelogPath);
|
|
818
|
-
|
|
819
|
-
if (!lastVersion) {
|
|
820
|
-
// Fresh install - just record the version, don't show changelog
|
|
821
|
-
this.settingsManager.setLastChangelogVersion(VERSION);
|
|
822
|
-
return undefined;
|
|
823
|
-
} else {
|
|
824
|
-
const newEntries = getNewEntries(entries, lastVersion);
|
|
825
|
-
if (newEntries.length > 0) {
|
|
826
|
-
this.settingsManager.setLastChangelogVersion(VERSION);
|
|
827
|
-
return newEntries.map((e) => e.content).join("\n\n");
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
return undefined;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
private getMarkdownThemeWithSettings(): MarkdownTheme {
|
|
835
|
-
return {
|
|
836
|
-
...getMarkdownTheme(),
|
|
837
|
-
codeBlockIndent: this.settingsManager.getCodeBlockIndent(),
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
// =========================================================================
|
|
842
|
-
// Extension System
|
|
843
|
-
// =========================================================================
|
|
844
|
-
|
|
845
|
-
private formatDisplayPath(p: string): string {
|
|
846
|
-
const home = os.homedir();
|
|
847
|
-
let result = p;
|
|
848
|
-
|
|
849
|
-
// Replace home directory with ~
|
|
850
|
-
if (result.startsWith(home)) {
|
|
851
|
-
result = `~${result.slice(home.length)}`;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
return result;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
/**
|
|
858
|
-
* Get a short path relative to the package root for display.
|
|
859
|
-
*/
|
|
860
|
-
private getShortPath(fullPath: string, source: string): string {
|
|
861
|
-
// For npm packages, show path relative to node_modules/pkg/
|
|
862
|
-
const npmMatch = fullPath.match(/node_modules\/(@?[^/]+(?:\/[^/]+)?)\/(.*)/);
|
|
863
|
-
if (npmMatch && source.startsWith("npm:")) {
|
|
864
|
-
return npmMatch[2];
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
// For git packages, show path relative to repo root
|
|
868
|
-
const gitMatch = fullPath.match(/git\/[^/]+\/[^/]+\/(.*)/);
|
|
869
|
-
if (gitMatch && source.startsWith("git:")) {
|
|
870
|
-
return gitMatch[1];
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
// For local/auto, just use formatDisplayPath
|
|
874
|
-
return this.formatDisplayPath(fullPath);
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
private getDisplaySourceInfo(
|
|
878
|
-
source: string,
|
|
879
|
-
scope: string,
|
|
880
|
-
): { label: string; scopeLabel?: string; color: "accent" | "muted" } {
|
|
881
|
-
if (source === "local") {
|
|
882
|
-
if (scope === "user") {
|
|
883
|
-
return { label: "user", color: "muted" };
|
|
884
|
-
}
|
|
885
|
-
if (scope === "project") {
|
|
886
|
-
return { label: "project", color: "muted" };
|
|
887
|
-
}
|
|
888
|
-
if (scope === "temporary") {
|
|
889
|
-
return { label: "path", scopeLabel: "temp", color: "muted" };
|
|
890
|
-
}
|
|
891
|
-
return { label: "path", color: "muted" };
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
if (source === "cli") {
|
|
895
|
-
return { label: "path", scopeLabel: scope === "temporary" ? "temp" : undefined, color: "muted" };
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
const scopeLabel =
|
|
899
|
-
scope === "user" ? "user" : scope === "project" ? "project" : scope === "temporary" ? "temp" : undefined;
|
|
900
|
-
return { label: source, scopeLabel, color: "accent" };
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
private getScopeGroup(source: string, scope: string): "user" | "project" | "path" {
|
|
904
|
-
if (source === "cli" || scope === "temporary") return "path";
|
|
905
|
-
if (scope === "user") return "user";
|
|
906
|
-
if (scope === "project") return "project";
|
|
907
|
-
return "path";
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
private isPackageSource(source: string): boolean {
|
|
911
|
-
return source.startsWith("npm:") || source.startsWith("git:");
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
private buildScopeGroups(
|
|
915
|
-
paths: string[],
|
|
916
|
-
metadata: Map<string, { source: string; scope: string; origin: string }>,
|
|
917
|
-
): Array<{ scope: "user" | "project" | "path"; paths: string[]; packages: Map<string, string[]> }> {
|
|
918
|
-
const groups: Record<
|
|
919
|
-
"user" | "project" | "path",
|
|
920
|
-
{ scope: "user" | "project" | "path"; paths: string[]; packages: Map<string, string[]> }
|
|
921
|
-
> = {
|
|
922
|
-
user: { scope: "user", paths: [], packages: new Map() },
|
|
923
|
-
project: { scope: "project", paths: [], packages: new Map() },
|
|
924
|
-
path: { scope: "path", paths: [], packages: new Map() },
|
|
925
|
-
};
|
|
926
|
-
|
|
927
|
-
for (const p of paths) {
|
|
928
|
-
const meta = this.findMetadata(p, metadata);
|
|
929
|
-
const source = meta?.source ?? "local";
|
|
930
|
-
const scope = meta?.scope ?? "project";
|
|
931
|
-
const groupKey = this.getScopeGroup(source, scope);
|
|
932
|
-
const group = groups[groupKey];
|
|
933
|
-
|
|
934
|
-
if (this.isPackageSource(source)) {
|
|
935
|
-
const list = group.packages.get(source) ?? [];
|
|
936
|
-
list.push(p);
|
|
937
|
-
group.packages.set(source, list);
|
|
938
|
-
} else {
|
|
939
|
-
group.paths.push(p);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
return [groups.project, groups.user, groups.path].filter(
|
|
944
|
-
(group) => group.paths.length > 0 || group.packages.size > 0,
|
|
945
|
-
);
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
private formatScopeGroups(
|
|
949
|
-
groups: Array<{ scope: "user" | "project" | "path"; paths: string[]; packages: Map<string, string[]> }>,
|
|
950
|
-
options: {
|
|
951
|
-
formatPath: (p: string) => string;
|
|
952
|
-
formatPackagePath: (p: string, source: string) => string;
|
|
953
|
-
},
|
|
954
|
-
): string {
|
|
955
|
-
const lines: string[] = [];
|
|
956
|
-
|
|
957
|
-
for (const group of groups) {
|
|
958
|
-
lines.push(` ${theme.fg("accent", group.scope)}`);
|
|
959
|
-
|
|
960
|
-
const sortedPaths = [...group.paths].sort((a, b) => a.localeCompare(b));
|
|
961
|
-
for (const p of sortedPaths) {
|
|
962
|
-
lines.push(theme.fg("dim", ` ${options.formatPath(p)}`));
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
const sortedPackages = Array.from(group.packages.entries()).sort(([a], [b]) => a.localeCompare(b));
|
|
966
|
-
for (const [source, paths] of sortedPackages) {
|
|
967
|
-
lines.push(` ${theme.fg("mdLink", source)}`);
|
|
968
|
-
const sortedPackagePaths = [...paths].sort((a, b) => a.localeCompare(b));
|
|
969
|
-
for (const p of sortedPackagePaths) {
|
|
970
|
-
lines.push(theme.fg("dim", ` ${options.formatPackagePath(p, source)}`));
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
return lines.join("\n");
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
/**
|
|
979
|
-
* Find metadata for a path, checking parent directories if exact match fails.
|
|
980
|
-
* Package manager stores metadata for directories, but we display file paths.
|
|
981
|
-
*/
|
|
982
|
-
private findMetadata(
|
|
983
|
-
p: string,
|
|
984
|
-
metadata: Map<string, { source: string; scope: string; origin: string }>,
|
|
985
|
-
): { source: string; scope: string; origin: string } | undefined {
|
|
986
|
-
// Try exact match first
|
|
987
|
-
const exact = metadata.get(p);
|
|
988
|
-
if (exact) return exact;
|
|
989
|
-
|
|
990
|
-
// Try parent directories (package manager stores directory paths)
|
|
991
|
-
let current = p;
|
|
992
|
-
let parent = path.dirname(current);
|
|
993
|
-
while (parent !== current) {
|
|
994
|
-
const meta = metadata.get(parent);
|
|
995
|
-
if (meta) return meta;
|
|
996
|
-
current = parent;
|
|
997
|
-
parent = path.dirname(current);
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
return undefined;
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
/**
|
|
1004
|
-
* Format a path with its source/scope info from metadata.
|
|
1005
|
-
*/
|
|
1006
|
-
private formatPathWithSource(
|
|
1007
|
-
p: string,
|
|
1008
|
-
metadata: Map<string, { source: string; scope: string; origin: string }>,
|
|
1009
|
-
): string {
|
|
1010
|
-
const meta = this.findMetadata(p, metadata);
|
|
1011
|
-
if (meta) {
|
|
1012
|
-
const shortPath = this.getShortPath(p, meta.source);
|
|
1013
|
-
const { label, scopeLabel } = this.getDisplaySourceInfo(meta.source, meta.scope);
|
|
1014
|
-
const labelText = scopeLabel ? `${label} (${scopeLabel})` : label;
|
|
1015
|
-
return `${labelText} ${shortPath}`;
|
|
1016
|
-
}
|
|
1017
|
-
return this.formatDisplayPath(p);
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
/**
|
|
1021
|
-
* Format resource diagnostics with nice collision display using metadata.
|
|
1022
|
-
*/
|
|
1023
|
-
private formatDiagnostics(
|
|
1024
|
-
diagnostics: readonly ResourceDiagnostic[],
|
|
1025
|
-
metadata: Map<string, { source: string; scope: string; origin: string }>,
|
|
1026
|
-
): string {
|
|
1027
|
-
const lines: string[] = [];
|
|
1028
|
-
|
|
1029
|
-
// Group collision diagnostics by name
|
|
1030
|
-
const collisions = new Map<string, ResourceDiagnostic[]>();
|
|
1031
|
-
const otherDiagnostics: ResourceDiagnostic[] = [];
|
|
1032
|
-
|
|
1033
|
-
for (const d of diagnostics) {
|
|
1034
|
-
if (d.type === "collision" && d.collision) {
|
|
1035
|
-
const list = collisions.get(d.collision.name) ?? [];
|
|
1036
|
-
list.push(d);
|
|
1037
|
-
collisions.set(d.collision.name, list);
|
|
1038
|
-
} else {
|
|
1039
|
-
otherDiagnostics.push(d);
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
// Format collision diagnostics grouped by name
|
|
1044
|
-
for (const [name, collisionList] of collisions) {
|
|
1045
|
-
const first = collisionList[0]?.collision;
|
|
1046
|
-
if (!first) continue;
|
|
1047
|
-
lines.push(theme.fg("warning", ` "${name}" collision:`));
|
|
1048
|
-
// Show winner
|
|
1049
|
-
lines.push(
|
|
1050
|
-
theme.fg("dim", ` ${theme.fg("success", "✓")} ${this.formatPathWithSource(first.winnerPath, metadata)}`),
|
|
1051
|
-
);
|
|
1052
|
-
// Show all losers
|
|
1053
|
-
for (const d of collisionList) {
|
|
1054
|
-
if (d.collision) {
|
|
1055
|
-
lines.push(
|
|
1056
|
-
theme.fg(
|
|
1057
|
-
"dim",
|
|
1058
|
-
` ${theme.fg("warning", "✗")} ${this.formatPathWithSource(d.collision.loserPath, metadata)} (skipped)`,
|
|
1059
|
-
),
|
|
1060
|
-
);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
// Format other diagnostics (skill name collisions, parse errors, etc.)
|
|
1066
|
-
for (const d of otherDiagnostics) {
|
|
1067
|
-
if (d.path) {
|
|
1068
|
-
// Use metadata-aware formatting for paths
|
|
1069
|
-
const sourceInfo = this.formatPathWithSource(d.path, metadata);
|
|
1070
|
-
lines.push(theme.fg(d.type === "error" ? "error" : "warning", ` ${sourceInfo}`));
|
|
1071
|
-
lines.push(theme.fg(d.type === "error" ? "error" : "warning", ` ${d.message}`));
|
|
1072
|
-
} else {
|
|
1073
|
-
lines.push(theme.fg(d.type === "error" ? "error" : "warning", ` ${d.message}`));
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
return lines.join("\n");
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
private showLoadedResources(options?: {
|
|
1081
|
-
extensionPaths?: string[];
|
|
1082
|
-
force?: boolean;
|
|
1083
|
-
showDiagnosticsWhenQuiet?: boolean;
|
|
1084
|
-
}): void {
|
|
1085
|
-
const showListing = options?.force || this.options.verbose || !this.settingsManager.getQuietStartup();
|
|
1086
|
-
const showDiagnostics = showListing || options?.showDiagnosticsWhenQuiet === true;
|
|
1087
|
-
if (!showListing && !showDiagnostics) {
|
|
1088
|
-
return;
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
const metadata = (
|
|
1092
|
-
(this.session.resourceLoader as unknown as GSDResourceLoader).getPathMetadata?.()
|
|
1093
|
-
?? new Map<string, { source: string; scope: string; origin: string }>()
|
|
1094
|
-
) as Map<string, { source: string; scope: string; origin: string }>;
|
|
1095
|
-
const sectionHeader = (name: string, color: ThemeColor = "mdHeading"): string => theme.fg(color, `[${name}]`);
|
|
1096
|
-
|
|
1097
|
-
const skillsResult = this.session.resourceLoader.getSkills();
|
|
1098
|
-
const promptsResult = this.session.resourceLoader.getPrompts();
|
|
1099
|
-
const themesResult = this.session.resourceLoader.getThemes();
|
|
1100
|
-
|
|
1101
|
-
if (showListing) {
|
|
1102
|
-
const contextFiles = this.session.resourceLoader.getAgentsFiles().agentsFiles;
|
|
1103
|
-
if (contextFiles.length > 0) {
|
|
1104
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1105
|
-
const contextList = contextFiles
|
|
1106
|
-
.map((f) => theme.fg("dim", ` ${this.formatDisplayPath(f.path)}`))
|
|
1107
|
-
.join("\n");
|
|
1108
|
-
this.chatContainer.addChild(new Text(`${sectionHeader("Context")}\n${contextList}`, 0, 0));
|
|
1109
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
const skills = skillsResult.skills;
|
|
1113
|
-
if (skills.length > 0) {
|
|
1114
|
-
const skillPaths = skills.map((s) => s.filePath);
|
|
1115
|
-
const groups = this.buildScopeGroups(skillPaths, metadata);
|
|
1116
|
-
const skillList = this.formatScopeGroups(groups, {
|
|
1117
|
-
formatPath: (p) => this.formatDisplayPath(p),
|
|
1118
|
-
formatPackagePath: (p, source) => this.getShortPath(p, source),
|
|
1119
|
-
});
|
|
1120
|
-
this.chatContainer.addChild(new Text(`${sectionHeader("Skills")}\n${skillList}`, 0, 0));
|
|
1121
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
const templates = this.session.promptTemplates;
|
|
1125
|
-
if (templates.length > 0) {
|
|
1126
|
-
const templatePaths = templates.map((t) => t.filePath);
|
|
1127
|
-
const groups = this.buildScopeGroups(templatePaths, metadata);
|
|
1128
|
-
const templateByPath = new Map(templates.map((t) => [t.filePath, t]));
|
|
1129
|
-
const templateList = this.formatScopeGroups(groups, {
|
|
1130
|
-
formatPath: (p) => {
|
|
1131
|
-
const template = templateByPath.get(p);
|
|
1132
|
-
return template ? `/${template.name}` : this.formatDisplayPath(p);
|
|
1133
|
-
},
|
|
1134
|
-
formatPackagePath: (p) => {
|
|
1135
|
-
const template = templateByPath.get(p);
|
|
1136
|
-
return template ? `/${template.name}` : this.formatDisplayPath(p);
|
|
1137
|
-
},
|
|
1138
|
-
});
|
|
1139
|
-
this.chatContainer.addChild(new Text(`${sectionHeader("Prompts")}\n${templateList}`, 0, 0));
|
|
1140
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
const extensionPaths = options?.extensionPaths ?? [];
|
|
1144
|
-
if (extensionPaths.length > 0) {
|
|
1145
|
-
const groups = this.buildScopeGroups(extensionPaths, metadata);
|
|
1146
|
-
const extList = this.formatScopeGroups(groups, {
|
|
1147
|
-
formatPath: (p) => this.formatDisplayPath(p),
|
|
1148
|
-
formatPackagePath: (p, source) => this.getShortPath(p, source),
|
|
1149
|
-
});
|
|
1150
|
-
this.chatContainer.addChild(new Text(`${sectionHeader("Extensions", "mdHeading")}\n${extList}`, 0, 0));
|
|
1151
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
// Show loaded themes (excluding built-in)
|
|
1155
|
-
const loadedThemes = themesResult.themes;
|
|
1156
|
-
const customThemes = loadedThemes.filter((t) => t.sourcePath);
|
|
1157
|
-
if (customThemes.length > 0) {
|
|
1158
|
-
const themePaths = customThemes.map((t) => t.sourcePath!);
|
|
1159
|
-
const groups = this.buildScopeGroups(themePaths, metadata);
|
|
1160
|
-
const themeList = this.formatScopeGroups(groups, {
|
|
1161
|
-
formatPath: (p) => this.formatDisplayPath(p),
|
|
1162
|
-
formatPackagePath: (p, source) => this.getShortPath(p, source),
|
|
1163
|
-
});
|
|
1164
|
-
this.chatContainer.addChild(new Text(`${sectionHeader("Themes")}\n${themeList}`, 0, 0));
|
|
1165
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
if (showDiagnostics) {
|
|
1170
|
-
const skillDiagnostics = skillsResult.diagnostics;
|
|
1171
|
-
if (skillDiagnostics.length > 0) {
|
|
1172
|
-
const collisionDiags = skillDiagnostics.filter(d => d.type === "collision");
|
|
1173
|
-
const issueDiags = skillDiagnostics.filter(d => d.type !== "collision");
|
|
1174
|
-
|
|
1175
|
-
if (collisionDiags.length > 0) {
|
|
1176
|
-
const collisionLines = this.formatDiagnostics(collisionDiags, metadata);
|
|
1177
|
-
this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Skill conflicts]")}\n${collisionLines}`, 0, 0));
|
|
1178
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
if (issueDiags.length > 0) {
|
|
1182
|
-
const issueLines = this.formatDiagnostics(issueDiags, metadata);
|
|
1183
|
-
this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Skill issues]")}\n${issueLines}`, 0, 0));
|
|
1184
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
const promptDiagnostics = promptsResult.diagnostics;
|
|
1189
|
-
if (promptDiagnostics.length > 0) {
|
|
1190
|
-
const warningLines = this.formatDiagnostics(promptDiagnostics, metadata);
|
|
1191
|
-
this.chatContainer.addChild(
|
|
1192
|
-
new Text(`${theme.fg("warning", "[Prompt conflicts]")}\n${warningLines}`, 0, 0),
|
|
1193
|
-
);
|
|
1194
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
const extensionDiagnostics: ResourceDiagnostic[] = [];
|
|
1198
|
-
const extensionErrors = this.session.resourceLoader.getExtensions().errors;
|
|
1199
|
-
if (extensionErrors.length > 0) {
|
|
1200
|
-
for (const error of extensionErrors) {
|
|
1201
|
-
extensionDiagnostics.push({ type: "error", message: error.error, path: error.path });
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
const commandDiagnostics = this.session.extensionRunner?.getCommandDiagnostics() ?? [];
|
|
1206
|
-
extensionDiagnostics.push(...commandDiagnostics);
|
|
1207
|
-
|
|
1208
|
-
const shortcutDiagnostics = this.session.extensionRunner?.getShortcutDiagnostics() ?? [];
|
|
1209
|
-
extensionDiagnostics.push(...shortcutDiagnostics);
|
|
1210
|
-
|
|
1211
|
-
if (extensionDiagnostics.length > 0) {
|
|
1212
|
-
const warningLines = this.formatDiagnostics(extensionDiagnostics, metadata);
|
|
1213
|
-
this.chatContainer.addChild(
|
|
1214
|
-
new Text(`${theme.fg("warning", "[Extension issues]")}\n${warningLines}`, 0, 0),
|
|
1215
|
-
);
|
|
1216
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
const themeDiagnostics = themesResult.diagnostics;
|
|
1220
|
-
if (themeDiagnostics.length > 0) {
|
|
1221
|
-
const warningLines = this.formatDiagnostics(themeDiagnostics, metadata);
|
|
1222
|
-
this.chatContainer.addChild(new Text(`${theme.fg("warning", "[Theme conflicts]")}\n${warningLines}`, 0, 0));
|
|
1223
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
/**
|
|
1229
|
-
* Initialize the extension system with TUI-based UI context.
|
|
1230
|
-
*/
|
|
1231
|
-
private async initExtensions(): Promise<void> {
|
|
1232
|
-
if (this.options.bindExtensions !== false) {
|
|
1233
|
-
const uiContext = this.createExtensionUIContext();
|
|
1234
|
-
await this.session.bindExtensions({
|
|
1235
|
-
uiContext,
|
|
1236
|
-
commandContextActions: {
|
|
1237
|
-
waitForIdle: () => this.session.agent.waitForIdle(),
|
|
1238
|
-
newSession: async (options) => {
|
|
1239
|
-
if (this.loadingAnimation) {
|
|
1240
|
-
this.loadingAnimation.stop();
|
|
1241
|
-
this.loadingAnimation = undefined;
|
|
1242
|
-
}
|
|
1243
|
-
this.statusContainer.clear();
|
|
1244
|
-
|
|
1245
|
-
// Delegate to AgentSession (handles setup + agent state sync)
|
|
1246
|
-
const success = await this.session.newSession(options);
|
|
1247
|
-
if (!success) {
|
|
1248
|
-
return { cancelled: true };
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
// Clear UI state
|
|
1252
|
-
this.chatContainer.clear();
|
|
1253
|
-
this.pendingMessagesContainer.clear();
|
|
1254
|
-
this.compactionQueuedMessages = [];
|
|
1255
|
-
this.streamingComponent = undefined;
|
|
1256
|
-
this.streamingMessage = undefined;
|
|
1257
|
-
this.pendingTools.clear();
|
|
1258
|
-
|
|
1259
|
-
// Render any messages added via setup, or show empty session
|
|
1260
|
-
this.renderInitialMessages();
|
|
1261
|
-
this.ui.requestRender();
|
|
1262
|
-
|
|
1263
|
-
return { cancelled: false };
|
|
1264
|
-
},
|
|
1265
|
-
fork: async (entryId) => {
|
|
1266
|
-
const result = await this.session.fork(entryId);
|
|
1267
|
-
if (result.cancelled) {
|
|
1268
|
-
return { cancelled: true };
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
this.chatContainer.clear();
|
|
1272
|
-
this.renderInitialMessages();
|
|
1273
|
-
this.editor.setText(result.selectedText);
|
|
1274
|
-
this.showStatus("Forked to new session");
|
|
1275
|
-
|
|
1276
|
-
return { cancelled: false };
|
|
1277
|
-
},
|
|
1278
|
-
navigateTree: async (targetId, options) => {
|
|
1279
|
-
const result = await this.session.navigateTree(targetId, {
|
|
1280
|
-
summarize: options?.summarize,
|
|
1281
|
-
customInstructions: options?.customInstructions,
|
|
1282
|
-
replaceInstructions: options?.replaceInstructions,
|
|
1283
|
-
label: options?.label,
|
|
1284
|
-
});
|
|
1285
|
-
if (result.cancelled) {
|
|
1286
|
-
return { cancelled: true };
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
this.chatContainer.clear();
|
|
1290
|
-
this.renderInitialMessages();
|
|
1291
|
-
if (result.editorText && !this.editor.getText().trim()) {
|
|
1292
|
-
this.editor.setText(result.editorText);
|
|
1293
|
-
}
|
|
1294
|
-
this.showStatus("Navigated to selected point");
|
|
1295
|
-
|
|
1296
|
-
return { cancelled: false };
|
|
1297
|
-
},
|
|
1298
|
-
switchSession: async (sessionPath) => {
|
|
1299
|
-
await this.handleResumeSession(sessionPath);
|
|
1300
|
-
return { cancelled: false };
|
|
1301
|
-
},
|
|
1302
|
-
reload: async () => {
|
|
1303
|
-
await this.handleReloadCommand();
|
|
1304
|
-
},
|
|
1305
|
-
},
|
|
1306
|
-
shutdownHandler: () => {
|
|
1307
|
-
this.shutdownRequested = true;
|
|
1308
|
-
if (!this.session.isStreaming) {
|
|
1309
|
-
void this.shutdown();
|
|
1310
|
-
}
|
|
1311
|
-
},
|
|
1312
|
-
onError: (error) => {
|
|
1313
|
-
const gsdError = error as unknown as GSDExtensionCallbackError;
|
|
1314
|
-
this.showExtensionError(gsdError.extensionPath, gsdError.error, gsdError.stack);
|
|
1315
|
-
},
|
|
1316
|
-
});
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
/* vendor-seam: dual-module-path — Theme resolves differently through ResourceLoader vs setRegisteredThemes import path */
|
|
1320
|
-
setRegisteredThemes(this.session.resourceLoader.getThemes().themes as unknown as Parameters<typeof setRegisteredThemes>[0]);
|
|
1321
|
-
this.setupAutocomplete();
|
|
1322
|
-
|
|
1323
|
-
const extensionRunner = this.session.extensionRunner;
|
|
1324
|
-
if (!extensionRunner) {
|
|
1325
|
-
this.showLoadedResources({ extensionPaths: [], force: false });
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
this.setupExtensionShortcuts(extensionRunner);
|
|
1330
|
-
this.showLoadedResources({ extensionPaths: extensionRunner.getExtensionPaths(), force: false });
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
/**
|
|
1334
|
-
* Get a tool definition by name (for custom rendering).
|
|
1335
|
-
*/
|
|
1336
|
-
private getRegisteredToolDefinition(toolName: string): ReturnType<AgentSession["getRenderableToolDefinition"]> {
|
|
1337
|
-
return this.session.getRenderableToolDefinition(toolName);
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
/**
|
|
1341
|
-
* Format web search result content for display in the TUI.
|
|
1342
|
-
*/
|
|
1343
|
-
private formatWebSearchResult(content: unknown): string {
|
|
1344
|
-
if (!content) return "Web search completed";
|
|
1345
|
-
|
|
1346
|
-
// Error result — web_search_tool_result_error is a runtime-only type not in pi-ai types
|
|
1347
|
-
if (typeof content === "object" && content !== null && "type" in content &&
|
|
1348
|
-
(content as { type: unknown }).type === "web_search_tool_result_error") {
|
|
1349
|
-
const error = content as { type: string; error_code?: string };
|
|
1350
|
-
return `Search error: ${error.error_code || "unknown"}`;
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
// Array of search results — items are runtime-only web_search_result objects
|
|
1354
|
-
if (Array.isArray(content)) {
|
|
1355
|
-
const results = (content as Array<{ type?: string; title?: string; url?: string }>)
|
|
1356
|
-
.filter((r) => r.type === "web_search_result");
|
|
1357
|
-
if (results.length === 0) return "No results found";
|
|
1358
|
-
return results
|
|
1359
|
-
.map((r) => {
|
|
1360
|
-
const title = r.title || "Untitled";
|
|
1361
|
-
const url = r.url || "";
|
|
1362
|
-
return `${title}\n ${url}`;
|
|
1363
|
-
})
|
|
1364
|
-
.join("\n");
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
return "Web search completed";
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
/**
|
|
1371
|
-
* Set up keyboard shortcuts registered by extensions.
|
|
1372
|
-
*/
|
|
1373
|
-
private setupExtensionShortcuts(extensionRunner: ExtensionRunner): void {
|
|
1374
|
-
const shortcuts = extensionRunner.getShortcuts(this.keybindings.getEffectiveConfig());
|
|
1375
|
-
if (shortcuts.size === 0) return;
|
|
1376
|
-
|
|
1377
|
-
// Create a context for shortcut handlers
|
|
1378
|
-
const createContext = (): ExtensionContext => ({
|
|
1379
|
-
ui: this.createExtensionUIContext(),
|
|
1380
|
-
hasUI: true,
|
|
1381
|
-
cwd: process.cwd(),
|
|
1382
|
-
sessionManager: this.sessionManager,
|
|
1383
|
-
modelRegistry: this.session.modelRegistry,
|
|
1384
|
-
model: this.session.model,
|
|
1385
|
-
isIdle: () => !this.session.isStreaming,
|
|
1386
|
-
abort: () => this.session.abort(),
|
|
1387
|
-
hasPendingMessages: () => this.session.pendingMessageCount > 0,
|
|
1388
|
-
shutdown: () => {
|
|
1389
|
-
this.shutdownRequested = true;
|
|
1390
|
-
},
|
|
1391
|
-
getContextUsage: () => this.session.getContextUsage(),
|
|
1392
|
-
compact: (options) => {
|
|
1393
|
-
void (async () => {
|
|
1394
|
-
try {
|
|
1395
|
-
const result = await this.executeCompaction(options?.customInstructions, false);
|
|
1396
|
-
if (result) {
|
|
1397
|
-
options?.onComplete?.(result);
|
|
1398
|
-
}
|
|
1399
|
-
} catch (error) {
|
|
1400
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
1401
|
-
options?.onError?.(err);
|
|
1402
|
-
}
|
|
1403
|
-
})();
|
|
1404
|
-
},
|
|
1405
|
-
getSystemPrompt: () => this.session.systemPrompt,
|
|
1406
|
-
});
|
|
1407
|
-
|
|
1408
|
-
// Set up the extension shortcut handler on the default editor
|
|
1409
|
-
this.defaultEditor.onExtensionShortcut = (data: string) => {
|
|
1410
|
-
for (const [shortcutStr, shortcut] of shortcuts) {
|
|
1411
|
-
// Cast to KeyId - extension shortcuts use the same format
|
|
1412
|
-
if (matchesKey(data, shortcutStr as KeyId)) {
|
|
1413
|
-
// Run handler async, don't block input
|
|
1414
|
-
Promise.resolve(shortcut.handler(createContext())).catch((err) => {
|
|
1415
|
-
this.showError(`Shortcut handler error: ${err instanceof Error ? err.message : String(err)}`);
|
|
1416
|
-
});
|
|
1417
|
-
return true;
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
return false;
|
|
1421
|
-
};
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
/**
|
|
1425
|
-
* Set extension status text in the footer.
|
|
1426
|
-
*/
|
|
1427
|
-
private setExtensionStatus(key: string, text: string | undefined): void {
|
|
1428
|
-
this.footerDataProvider.setExtensionStatus(key, text);
|
|
1429
|
-
this.ui.requestRender();
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
/**
|
|
1433
|
-
* Set an extension widget (string array or custom component).
|
|
1434
|
-
*/
|
|
1435
|
-
private setExtensionWidget(
|
|
1436
|
-
key: string,
|
|
1437
|
-
content: string[] | ((tui: TUI, thm: Theme) => Component & { dispose?(): void }) | undefined,
|
|
1438
|
-
options?: ExtensionWidgetOptions,
|
|
1439
|
-
): void {
|
|
1440
|
-
const placement = options?.placement ?? "aboveEditor";
|
|
1441
|
-
const removeExisting = (map: Map<string, Component & { dispose?(): void }>): void => {
|
|
1442
|
-
const existing = map.get(key);
|
|
1443
|
-
if (existing?.dispose) existing.dispose();
|
|
1444
|
-
map.delete(key);
|
|
1445
|
-
};
|
|
1446
|
-
|
|
1447
|
-
removeExisting(this.extensionWidgetsAbove);
|
|
1448
|
-
removeExisting(this.extensionWidgetsBelow);
|
|
1449
|
-
|
|
1450
|
-
if (content === undefined) {
|
|
1451
|
-
this.renderWidgets();
|
|
1452
|
-
return;
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
let component: Component & { dispose?(): void };
|
|
1456
|
-
|
|
1457
|
-
if (Array.isArray(content)) {
|
|
1458
|
-
// Wrap string array in a Container with Text components
|
|
1459
|
-
const container = new Container();
|
|
1460
|
-
for (const line of content.slice(0, InteractiveMode.MAX_WIDGET_LINES)) {
|
|
1461
|
-
container.addChild(new Text(line, 1, 0));
|
|
1462
|
-
}
|
|
1463
|
-
if (content.length > InteractiveMode.MAX_WIDGET_LINES) {
|
|
1464
|
-
container.addChild(new Text(theme.fg("muted", "... (widget truncated)"), 1, 0));
|
|
1465
|
-
}
|
|
1466
|
-
component = container;
|
|
1467
|
-
} else {
|
|
1468
|
-
// Factory function - create component
|
|
1469
|
-
component = content(this.ui, theme);
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
const targetMap = placement === "belowEditor" ? this.extensionWidgetsBelow : this.extensionWidgetsAbove;
|
|
1473
|
-
targetMap.set(key, component);
|
|
1474
|
-
this.renderWidgets();
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
private clearExtensionWidgets(): void {
|
|
1478
|
-
for (const widget of this.extensionWidgetsAbove.values()) {
|
|
1479
|
-
widget.dispose?.();
|
|
1480
|
-
}
|
|
1481
|
-
for (const widget of this.extensionWidgetsBelow.values()) {
|
|
1482
|
-
widget.dispose?.();
|
|
1483
|
-
}
|
|
1484
|
-
this.extensionWidgetsAbove.clear();
|
|
1485
|
-
this.extensionWidgetsBelow.clear();
|
|
1486
|
-
this.renderWidgets();
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
private resetExtensionUI(): void {
|
|
1490
|
-
if (this.extensionSelector) {
|
|
1491
|
-
this.hideExtensionSelector();
|
|
1492
|
-
}
|
|
1493
|
-
if (this.extensionInput) {
|
|
1494
|
-
this.hideExtensionInput();
|
|
1495
|
-
}
|
|
1496
|
-
if (this.extensionEditor) {
|
|
1497
|
-
this.hideExtensionEditor();
|
|
1498
|
-
}
|
|
1499
|
-
this.ui.hideOverlay();
|
|
1500
|
-
this.clearExtensionTerminalInputListeners();
|
|
1501
|
-
this.setExtensionFooter(undefined);
|
|
1502
|
-
this.setExtensionHeader(undefined);
|
|
1503
|
-
this.clearExtensionWidgets();
|
|
1504
|
-
this.footerDataProvider.clearExtensionStatuses();
|
|
1505
|
-
this.footer.invalidate();
|
|
1506
|
-
this.setCustomEditorComponent(undefined);
|
|
1507
|
-
this.defaultEditor.onExtensionShortcut = undefined;
|
|
1508
|
-
this.updateTerminalTitle();
|
|
1509
|
-
if (this.loadingAnimation) {
|
|
1510
|
-
this.loadingAnimation.setMessage(
|
|
1511
|
-
`${this.defaultWorkingMessage} (${appKey(this.keybindings, "interrupt")} to interrupt)`,
|
|
1512
|
-
);
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
// Maximum total widget lines to prevent viewport overflow
|
|
1517
|
-
private static readonly MAX_WIDGET_LINES = 10;
|
|
1518
|
-
|
|
1519
|
-
/**
|
|
1520
|
-
* Render all extension widgets to the widget container.
|
|
1521
|
-
*/
|
|
1522
|
-
private renderWidgets(): void {
|
|
1523
|
-
if (!this.widgetContainerAbove || !this.widgetContainerBelow) return;
|
|
1524
|
-
|
|
1525
|
-
// widgetContainerAbove: spacer collapses when pinned content is visible
|
|
1526
|
-
// so there's no extra blank line between pinned output and the editor border.
|
|
1527
|
-
// Use detachChildren() (not clear()) — the extensionWidgetsAbove map owns
|
|
1528
|
-
// disposal; clear() would dispose every mounted widget on every re-render.
|
|
1529
|
-
const aboveGSD = this.widgetContainerAbove as unknown as GSDContainer;
|
|
1530
|
-
if (aboveGSD.detachChildren) { aboveGSD.detachChildren(); } else { this.widgetContainerAbove.clear(); }
|
|
1531
|
-
const pinned = this.pinnedMessageContainer;
|
|
1532
|
-
this.widgetContainerAbove.addChild({
|
|
1533
|
-
render: () => pinned.children.length > 0 ? [] : [""],
|
|
1534
|
-
invalidate: () => {},
|
|
1535
|
-
});
|
|
1536
|
-
for (const component of this.extensionWidgetsAbove.values()) {
|
|
1537
|
-
this.widgetContainerAbove.addChild(component);
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
|
-
this.renderWidgetContainer(this.widgetContainerBelow, this.extensionWidgetsBelow, false, false);
|
|
1541
|
-
this.ui.requestRender();
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
private renderWidgetContainer(
|
|
1545
|
-
container: Container,
|
|
1546
|
-
widgets: Map<string, Component & { dispose?(): void }>,
|
|
1547
|
-
spacerWhenEmpty: boolean,
|
|
1548
|
-
leadingSpacer: boolean,
|
|
1549
|
-
): void {
|
|
1550
|
-
// Detach without disposing — the widgets map owns lifecycle; disposing
|
|
1551
|
-
// here would kill refresh timers and subscriptions on every re-render.
|
|
1552
|
-
const containerGSD = container as unknown as GSDContainer;
|
|
1553
|
-
if (containerGSD.detachChildren) { containerGSD.detachChildren(); } else { container.clear(); }
|
|
1554
|
-
|
|
1555
|
-
if (widgets.size === 0) {
|
|
1556
|
-
if (spacerWhenEmpty) {
|
|
1557
|
-
container.addChild(new Spacer(1));
|
|
1558
|
-
}
|
|
1559
|
-
return;
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
if (leadingSpacer) {
|
|
1563
|
-
container.addChild(new Spacer(1));
|
|
1564
|
-
}
|
|
1565
|
-
for (const component of widgets.values()) {
|
|
1566
|
-
container.addChild(component);
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
/**
|
|
1571
|
-
* Set a custom footer component, or restore the built-in footer.
|
|
1572
|
-
*/
|
|
1573
|
-
private setExtensionFooter(
|
|
1574
|
-
factory:
|
|
1575
|
-
| ((tui: TUI, thm: Theme, footerData: ReadonlyFooterDataProvider) => Component & { dispose?(): void })
|
|
1576
|
-
| undefined,
|
|
1577
|
-
): void {
|
|
1578
|
-
// Dispose existing custom footer
|
|
1579
|
-
if (this.customFooter?.dispose) {
|
|
1580
|
-
this.customFooter.dispose();
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
// Remove current footer from UI
|
|
1584
|
-
if (this.customFooter) {
|
|
1585
|
-
this.ui.removeChild(this.customFooter);
|
|
1586
|
-
} else {
|
|
1587
|
-
this.ui.removeChild(this.footer);
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
if (factory) {
|
|
1591
|
-
// Create and add custom footer, passing the data provider
|
|
1592
|
-
this.customFooter = factory(this.ui, theme, this.footerDataProvider);
|
|
1593
|
-
this.ui.addChild(this.customFooter);
|
|
1594
|
-
} else {
|
|
1595
|
-
// Restore built-in footer
|
|
1596
|
-
this.customFooter = undefined;
|
|
1597
|
-
this.ui.addChild(this.footer);
|
|
1598
|
-
}
|
|
1599
|
-
|
|
1600
|
-
this.ui.requestRender();
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
/**
|
|
1604
|
-
* Set a custom header component, or restore the built-in header.
|
|
1605
|
-
*/
|
|
1606
|
-
private setExtensionHeader(factory: ((tui: TUI, thm: Theme) => Component & { dispose?(): void }) | undefined): void {
|
|
1607
|
-
// Header may not be initialized yet if called during early initialization
|
|
1608
|
-
if (!this.builtInHeader) {
|
|
1609
|
-
return;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
// Dispose existing custom header
|
|
1613
|
-
if (this.customHeader?.dispose) {
|
|
1614
|
-
this.customHeader.dispose();
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
// Find the index of the current header in the header container
|
|
1618
|
-
const currentHeader = this.customHeader || this.builtInHeader;
|
|
1619
|
-
const index = this.headerContainer.children.indexOf(currentHeader);
|
|
1620
|
-
|
|
1621
|
-
if (factory) {
|
|
1622
|
-
// Create and add custom header
|
|
1623
|
-
this.customHeader = factory(this.ui, theme);
|
|
1624
|
-
if (index !== -1) {
|
|
1625
|
-
this.headerContainer.children[index] = this.customHeader;
|
|
1626
|
-
} else {
|
|
1627
|
-
// If not found (e.g. builtInHeader was never added), add at the top
|
|
1628
|
-
this.headerContainer.children.unshift(this.customHeader);
|
|
1629
|
-
}
|
|
1630
|
-
} else {
|
|
1631
|
-
// Restore built-in header
|
|
1632
|
-
this.customHeader = undefined;
|
|
1633
|
-
if (index !== -1) {
|
|
1634
|
-
this.headerContainer.children[index] = this.builtInHeader;
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
this.ui.requestRender();
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
private addExtensionTerminalInputListener(
|
|
1642
|
-
handler: (data: string) => { consume?: boolean; data?: string } | undefined,
|
|
1643
|
-
): () => void {
|
|
1644
|
-
const unsubscribe = this.ui.addInputListener(handler);
|
|
1645
|
-
this.extensionTerminalInputUnsubscribers.add(unsubscribe);
|
|
1646
|
-
return () => {
|
|
1647
|
-
unsubscribe();
|
|
1648
|
-
this.extensionTerminalInputUnsubscribers.delete(unsubscribe);
|
|
1649
|
-
};
|
|
1650
|
-
}
|
|
1651
|
-
|
|
1652
|
-
private clearExtensionTerminalInputListeners(): void {
|
|
1653
|
-
for (const unsubscribe of this.extensionTerminalInputUnsubscribers) {
|
|
1654
|
-
unsubscribe();
|
|
1655
|
-
}
|
|
1656
|
-
this.extensionTerminalInputUnsubscribers.clear();
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
/**
|
|
1660
|
-
* Create the ExtensionUIContext for extensions.
|
|
1661
|
-
*/
|
|
1662
|
-
private createExtensionUIContext(): ExtensionUIContext {
|
|
1663
|
-
return buildExtensionUIContext(this as unknown as InteractiveModeStateHost);
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
getExtensionUIContext(): ExtensionUIContext {
|
|
1667
|
-
return this.createExtensionUIContext();
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
/**
|
|
1671
|
-
* Show a selector for extensions.
|
|
1672
|
-
*/
|
|
1673
|
-
private showExtensionSelector(
|
|
1674
|
-
title: string,
|
|
1675
|
-
options: string[],
|
|
1676
|
-
opts?: ExtensionUIDialogOptions,
|
|
1677
|
-
): Promise<string | undefined> {
|
|
1678
|
-
// If a previous selector is still active, dispose it before creating a
|
|
1679
|
-
// new one. This avoids leaking the previous promise and DOM state when
|
|
1680
|
-
// showExtensionSelector is called rapidly.
|
|
1681
|
-
if (this.extensionSelector) {
|
|
1682
|
-
this.hideExtensionSelector();
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
return new Promise((resolve) => {
|
|
1686
|
-
if (opts?.signal?.aborted) {
|
|
1687
|
-
resolve(undefined);
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
const onAbort = (): void => {
|
|
1692
|
-
this.hideExtensionSelector();
|
|
1693
|
-
resolve(undefined);
|
|
1694
|
-
};
|
|
1695
|
-
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1696
|
-
|
|
1697
|
-
this.extensionSelector = new ExtensionSelectorComponent(
|
|
1698
|
-
title,
|
|
1699
|
-
options,
|
|
1700
|
-
(option) => {
|
|
1701
|
-
opts?.signal?.removeEventListener("abort", onAbort);
|
|
1702
|
-
this.hideExtensionSelector();
|
|
1703
|
-
resolve(option);
|
|
1704
|
-
},
|
|
1705
|
-
() => {
|
|
1706
|
-
opts?.signal?.removeEventListener("abort", onAbort);
|
|
1707
|
-
this.hideExtensionSelector();
|
|
1708
|
-
resolve(undefined);
|
|
1709
|
-
},
|
|
1710
|
-
{ tui: this.ui, timeout: opts?.timeout },
|
|
1711
|
-
);
|
|
1712
|
-
|
|
1713
|
-
this.editorContainer.clear();
|
|
1714
|
-
this.editorContainer.addChild(this.extensionSelector);
|
|
1715
|
-
this.ui.setFocus(this.extensionSelector);
|
|
1716
|
-
this.ui.requestRender();
|
|
1717
|
-
});
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
/**
|
|
1721
|
-
* Hide the extension selector.
|
|
1722
|
-
*/
|
|
1723
|
-
private hideExtensionSelector(): void {
|
|
1724
|
-
this.extensionSelector?.dispose();
|
|
1725
|
-
this.editorContainer.clear();
|
|
1726
|
-
this.editorContainer.addChild(this.editor);
|
|
1727
|
-
this.extensionSelector = undefined;
|
|
1728
|
-
this.ui.setFocus(this.editor);
|
|
1729
|
-
this.ui.requestRender();
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
/**
|
|
1733
|
-
* Show a confirmation dialog for extensions.
|
|
1734
|
-
*/
|
|
1735
|
-
private async showExtensionConfirm(
|
|
1736
|
-
title: string,
|
|
1737
|
-
message: string,
|
|
1738
|
-
opts?: ExtensionUIDialogOptions,
|
|
1739
|
-
): Promise<boolean> {
|
|
1740
|
-
const result = await this.showExtensionSelector(`${title}\n${message}`, ["Yes", "No"], opts);
|
|
1741
|
-
return result === "Yes";
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
/**
|
|
1745
|
-
* Show a text input for extensions.
|
|
1746
|
-
*/
|
|
1747
|
-
private showExtensionInput(
|
|
1748
|
-
title: string,
|
|
1749
|
-
placeholder?: string,
|
|
1750
|
-
opts?: ExtensionUIDialogOptions,
|
|
1751
|
-
): Promise<string | undefined> {
|
|
1752
|
-
return new Promise((resolve) => {
|
|
1753
|
-
if (opts?.signal?.aborted) {
|
|
1754
|
-
resolve(undefined);
|
|
1755
|
-
return;
|
|
1756
|
-
}
|
|
1757
|
-
|
|
1758
|
-
const onAbort = (): void => {
|
|
1759
|
-
this.hideExtensionInput();
|
|
1760
|
-
resolve(undefined);
|
|
1761
|
-
};
|
|
1762
|
-
opts?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
1763
|
-
|
|
1764
|
-
this.extensionInput = new ExtensionInputComponent(
|
|
1765
|
-
title,
|
|
1766
|
-
placeholder,
|
|
1767
|
-
(value) => {
|
|
1768
|
-
opts?.signal?.removeEventListener("abort", onAbort);
|
|
1769
|
-
this.hideExtensionInput();
|
|
1770
|
-
resolve(value);
|
|
1771
|
-
},
|
|
1772
|
-
() => {
|
|
1773
|
-
opts?.signal?.removeEventListener("abort", onAbort);
|
|
1774
|
-
this.hideExtensionInput();
|
|
1775
|
-
resolve(undefined);
|
|
1776
|
-
},
|
|
1777
|
-
{ tui: this.ui, timeout: opts?.timeout, secure: (opts as unknown as GSDExtensionUIDialogOptions)?.secure },
|
|
1778
|
-
);
|
|
1779
|
-
|
|
1780
|
-
this.editorContainer.clear();
|
|
1781
|
-
this.editorContainer.addChild(this.extensionInput);
|
|
1782
|
-
this.ui.setFocus(this.extensionInput);
|
|
1783
|
-
this.ui.requestRender();
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
/**
|
|
1788
|
-
* Hide the extension input.
|
|
1789
|
-
*/
|
|
1790
|
-
private hideExtensionInput(): void {
|
|
1791
|
-
this.extensionInput?.dispose();
|
|
1792
|
-
this.editorContainer.clear();
|
|
1793
|
-
this.editorContainer.addChild(this.editor);
|
|
1794
|
-
this.extensionInput = undefined;
|
|
1795
|
-
this.ui.setFocus(this.editor);
|
|
1796
|
-
this.ui.requestRender();
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
/**
|
|
1800
|
-
* Show a multi-line editor for extensions (with Ctrl+G support).
|
|
1801
|
-
*/
|
|
1802
|
-
private showExtensionEditor(title: string, prefill?: string): Promise<string | undefined> {
|
|
1803
|
-
return new Promise((resolve) => {
|
|
1804
|
-
this.extensionEditor = new ExtensionEditorComponent(
|
|
1805
|
-
this.ui,
|
|
1806
|
-
this.keybindings,
|
|
1807
|
-
title,
|
|
1808
|
-
prefill,
|
|
1809
|
-
(value) => {
|
|
1810
|
-
this.hideExtensionEditor();
|
|
1811
|
-
resolve(value);
|
|
1812
|
-
},
|
|
1813
|
-
() => {
|
|
1814
|
-
this.hideExtensionEditor();
|
|
1815
|
-
resolve(undefined);
|
|
1816
|
-
},
|
|
1817
|
-
);
|
|
1818
|
-
|
|
1819
|
-
this.editorContainer.clear();
|
|
1820
|
-
this.editorContainer.addChild(this.extensionEditor);
|
|
1821
|
-
this.ui.setFocus(this.extensionEditor);
|
|
1822
|
-
this.ui.requestRender();
|
|
1823
|
-
});
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
/**
|
|
1827
|
-
* Hide the extension editor.
|
|
1828
|
-
*/
|
|
1829
|
-
private hideExtensionEditor(): void {
|
|
1830
|
-
this.editorContainer.clear();
|
|
1831
|
-
this.editorContainer.addChild(this.editor);
|
|
1832
|
-
this.extensionEditor = undefined;
|
|
1833
|
-
this.ui.setFocus(this.editor);
|
|
1834
|
-
this.ui.requestRender();
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
/**
|
|
1838
|
-
* Set a custom editor component from an extension.
|
|
1839
|
-
* Pass undefined to restore the default editor.
|
|
1840
|
-
*/
|
|
1841
|
-
private setCustomEditorComponent(
|
|
1842
|
-
factory: ((tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager) => EditorComponent) | undefined,
|
|
1843
|
-
): void {
|
|
1844
|
-
// Save text from current editor before switching
|
|
1845
|
-
const currentText = this.editor.getText();
|
|
1846
|
-
|
|
1847
|
-
this.editorContainer.clear();
|
|
1848
|
-
|
|
1849
|
-
if (factory) {
|
|
1850
|
-
// Create the custom editor with tui, theme, and keybindings
|
|
1851
|
-
const newEditor = factory(this.ui, getEditorTheme(), this.keybindings);
|
|
1852
|
-
|
|
1853
|
-
// Wire up callbacks from the default editor
|
|
1854
|
-
newEditor.onSubmit = this.defaultEditor.onSubmit;
|
|
1855
|
-
newEditor.onChange = this.defaultEditor.onChange;
|
|
1856
|
-
|
|
1857
|
-
// Copy text from previous editor
|
|
1858
|
-
newEditor.setText(currentText);
|
|
1859
|
-
|
|
1860
|
-
// Copy appearance settings if supported
|
|
1861
|
-
if (newEditor.borderColor !== undefined) {
|
|
1862
|
-
newEditor.borderColor = this.defaultEditor.borderColor;
|
|
1863
|
-
}
|
|
1864
|
-
if (newEditor.setPaddingX !== undefined) {
|
|
1865
|
-
newEditor.setPaddingX(this.defaultEditor.getPaddingX());
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
// Set autocomplete if supported
|
|
1869
|
-
if (newEditor.setAutocompleteProvider && this.autocompleteProvider) {
|
|
1870
|
-
newEditor.setAutocompleteProvider(this.autocompleteProvider);
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
// If extending CustomEditor, copy app-level handlers
|
|
1874
|
-
// Use duck typing since instanceof fails across jiti module boundaries
|
|
1875
|
-
const customEditor = newEditor as unknown as Record<string, unknown>;
|
|
1876
|
-
if ("actionHandlers" in customEditor && customEditor.actionHandlers instanceof Map) {
|
|
1877
|
-
if (!customEditor.onEscape) {
|
|
1878
|
-
customEditor.onEscape = () => this.defaultEditor.onEscape?.();
|
|
1879
|
-
}
|
|
1880
|
-
if (!customEditor.onCtrlD) {
|
|
1881
|
-
customEditor.onCtrlD = () => this.defaultEditor.onCtrlD?.();
|
|
1882
|
-
}
|
|
1883
|
-
if (!customEditor.onPasteImage) {
|
|
1884
|
-
customEditor.onPasteImage = () => this.defaultEditor.onPasteImage?.();
|
|
1885
|
-
}
|
|
1886
|
-
if (!customEditor.onExtensionShortcut) {
|
|
1887
|
-
customEditor.onExtensionShortcut = (data: string) => this.defaultEditor.onExtensionShortcut?.(data);
|
|
1888
|
-
}
|
|
1889
|
-
// Copy action handlers (clear, suspend, model switching, etc.)
|
|
1890
|
-
for (const [action, handler] of this.defaultEditor.actionHandlers) {
|
|
1891
|
-
(customEditor.actionHandlers as Map<string, () => void>).set(action, handler);
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
this.editor = newEditor;
|
|
1896
|
-
} else {
|
|
1897
|
-
// Restore default editor with text from custom editor
|
|
1898
|
-
this.defaultEditor.setText(currentText);
|
|
1899
|
-
this.editor = this.defaultEditor;
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
this.editorContainer.addChild(this.editor as Component);
|
|
1903
|
-
this.ui.setFocus(this.editor as Component);
|
|
1904
|
-
this.ui.requestRender();
|
|
1905
|
-
}
|
|
1906
|
-
|
|
1907
|
-
/**
|
|
1908
|
-
* Show a notification for extensions.
|
|
1909
|
-
*/
|
|
1910
|
-
private showExtensionNotify(message: string, type?: "info" | "warning" | "error" | "success"): void {
|
|
1911
|
-
if (type === "error") {
|
|
1912
|
-
this.showError(message);
|
|
1913
|
-
} else if (type === "warning") {
|
|
1914
|
-
this.showWarning(message);
|
|
1915
|
-
} else if (type === "success") {
|
|
1916
|
-
this.showSuccess(message);
|
|
1917
|
-
} else {
|
|
1918
|
-
this.showStatus(message, { append: true });
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
/** Show a custom component with keyboard focus. Overlay mode renders on top of existing content. */
|
|
1923
|
-
private async showExtensionCustom<T>(
|
|
1924
|
-
factory: (
|
|
1925
|
-
tui: TUI,
|
|
1926
|
-
theme: Theme,
|
|
1927
|
-
keybindings: KeybindingsManager,
|
|
1928
|
-
done: (result: T) => void,
|
|
1929
|
-
) => (Component & { dispose?(): void }) | Promise<Component & { dispose?(): void }>,
|
|
1930
|
-
options?: {
|
|
1931
|
-
overlay?: boolean;
|
|
1932
|
-
overlayOptions?: OverlayOptions | (() => OverlayOptions);
|
|
1933
|
-
onHandle?: (handle: OverlayHandle) => void;
|
|
1934
|
-
},
|
|
1935
|
-
): Promise<T> {
|
|
1936
|
-
const savedText = this.editor.getText();
|
|
1937
|
-
const isOverlay = options?.overlay ?? false;
|
|
1938
|
-
|
|
1939
|
-
const restoreEditor = (): void => {
|
|
1940
|
-
this.editorContainer.clear();
|
|
1941
|
-
this.editorContainer.addChild(this.editor);
|
|
1942
|
-
this.editor.setText(savedText);
|
|
1943
|
-
this.ui.setFocus(this.editor);
|
|
1944
|
-
this.ui.requestRender();
|
|
1945
|
-
};
|
|
1946
|
-
|
|
1947
|
-
return new Promise((resolve, reject) => {
|
|
1948
|
-
let component: Component & { dispose?(): void };
|
|
1949
|
-
let closed = false;
|
|
1950
|
-
|
|
1951
|
-
const close = (result: T): void => {
|
|
1952
|
-
if (closed) return;
|
|
1953
|
-
closed = true;
|
|
1954
|
-
if (isOverlay) this.ui.hideOverlay();
|
|
1955
|
-
else restoreEditor();
|
|
1956
|
-
// Note: both branches above already call requestRender
|
|
1957
|
-
resolve(result);
|
|
1958
|
-
try {
|
|
1959
|
-
component?.dispose?.();
|
|
1960
|
-
} catch {
|
|
1961
|
-
/* ignore dispose errors */
|
|
1962
|
-
}
|
|
1963
|
-
};
|
|
1964
|
-
|
|
1965
|
-
Promise.resolve(factory(this.ui, theme, this.keybindings, close))
|
|
1966
|
-
.then((c) => {
|
|
1967
|
-
if (closed) return;
|
|
1968
|
-
component = c;
|
|
1969
|
-
if (isOverlay) {
|
|
1970
|
-
// Resolve overlay options - can be static or dynamic function
|
|
1971
|
-
const resolveOptions = (): OverlayOptions | undefined => {
|
|
1972
|
-
if (options?.overlayOptions) {
|
|
1973
|
-
const opts =
|
|
1974
|
-
typeof options.overlayOptions === "function"
|
|
1975
|
-
? options.overlayOptions()
|
|
1976
|
-
: options.overlayOptions;
|
|
1977
|
-
return opts;
|
|
1978
|
-
}
|
|
1979
|
-
// Fallback: use component's width property if available
|
|
1980
|
-
const w = (component as { width?: number }).width;
|
|
1981
|
-
return w ? { width: w } : undefined;
|
|
1982
|
-
};
|
|
1983
|
-
const handle = this.ui.showOverlay(component, resolveOptions());
|
|
1984
|
-
// Expose handle to caller for visibility control
|
|
1985
|
-
options?.onHandle?.(handle);
|
|
1986
|
-
} else {
|
|
1987
|
-
this.editorContainer.clear();
|
|
1988
|
-
this.editorContainer.addChild(component);
|
|
1989
|
-
this.ui.setFocus(component);
|
|
1990
|
-
this.ui.requestRender();
|
|
1991
|
-
}
|
|
1992
|
-
})
|
|
1993
|
-
.catch((err) => {
|
|
1994
|
-
if (closed) return;
|
|
1995
|
-
if (!isOverlay) restoreEditor();
|
|
1996
|
-
reject(err);
|
|
1997
|
-
});
|
|
1998
|
-
});
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
|
-
/**
|
|
2002
|
-
* Show an extension error in the UI.
|
|
2003
|
-
*/
|
|
2004
|
-
private showExtensionError(extensionPath: string, error: string, stack?: string): void {
|
|
2005
|
-
const errorMsg = `Extension "${extensionPath}" error: ${error}`;
|
|
2006
|
-
const errorText = new Text(theme.fg("error", errorMsg), 1, 0);
|
|
2007
|
-
this.chatContainer.addChild(errorText);
|
|
2008
|
-
if (stack) {
|
|
2009
|
-
// Show stack trace in dim color, indented
|
|
2010
|
-
const stackLines = stack
|
|
2011
|
-
.split("\n")
|
|
2012
|
-
.slice(1) // Skip first line (duplicates error message)
|
|
2013
|
-
.map((line) => theme.fg("dim", ` ${line.trim()}`))
|
|
2014
|
-
.join("\n");
|
|
2015
|
-
if (stackLines) {
|
|
2016
|
-
this.chatContainer.addChild(new Text(stackLines, 1, 0));
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
this.ui.requestRender();
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
|
-
// =========================================================================
|
|
2023
|
-
// Key Handlers
|
|
2024
|
-
// =========================================================================
|
|
2025
|
-
|
|
2026
|
-
private setupKeyHandlers(): void {
|
|
2027
|
-
// Set up handlers on defaultEditor - they use this.editor for text access
|
|
2028
|
-
// so they work correctly regardless of which editor is active
|
|
2029
|
-
this.defaultEditor.onEscape = () => {
|
|
2030
|
-
if (this.loadingAnimation) {
|
|
2031
|
-
this.restoreQueuedMessagesToEditor({ abort: true });
|
|
2032
|
-
} else if (this.session.isBashRunning) {
|
|
2033
|
-
this.session.abortBash();
|
|
2034
|
-
} else if (this.isBashMode) {
|
|
2035
|
-
this.editor.setText("");
|
|
2036
|
-
this.isBashMode = false;
|
|
2037
|
-
this.updateEditorBorderColor();
|
|
2038
|
-
} else if (!this.editor.getText().trim()) {
|
|
2039
|
-
// Double-escape with empty editor triggers /tree, /fork, or nothing based on setting
|
|
2040
|
-
const action = this.settingsManager.getDoubleEscapeAction();
|
|
2041
|
-
if (action !== "none") {
|
|
2042
|
-
const now = Date.now();
|
|
2043
|
-
if (now - this.lastEscapeTime < 500) {
|
|
2044
|
-
if (action === "tree") {
|
|
2045
|
-
this.showTreeSelector();
|
|
2046
|
-
} else {
|
|
2047
|
-
this.showUserMessageSelector();
|
|
2048
|
-
}
|
|
2049
|
-
this.lastEscapeTime = 0;
|
|
2050
|
-
} else {
|
|
2051
|
-
this.lastEscapeTime = now;
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
}
|
|
2055
|
-
};
|
|
2056
|
-
|
|
2057
|
-
// Register app action handlers
|
|
2058
|
-
this.defaultEditor.onAction("clear", () => this.handleCtrlC());
|
|
2059
|
-
this.defaultEditor.onCtrlD = () => this.handleCtrlD();
|
|
2060
|
-
this.defaultEditor.onAction("suspend", () => this.handleCtrlZ());
|
|
2061
|
-
this.defaultEditor.onAction("cycleThinkingLevel", () => this.cycleThinkingLevel());
|
|
2062
|
-
this.defaultEditor.onAction("cycleModelForward", () => this.cycleModel("forward"));
|
|
2063
|
-
this.defaultEditor.onAction("cycleModelBackward", () => this.cycleModel("backward"));
|
|
2064
|
-
|
|
2065
|
-
// Global debug handler on TUI (works regardless of focus)
|
|
2066
|
-
this.ui.onDebug = () => this.handleDebugCommand();
|
|
2067
|
-
this.defaultEditor.onAction("selectModel", () => this.showModelSelector());
|
|
2068
|
-
this.defaultEditor.onAction("expandTools", () => this.toggleToolOutputExpansion());
|
|
2069
|
-
this.defaultEditor.onAction("toggleThinking", () => this.toggleThinkingBlockVisibility());
|
|
2070
|
-
this.defaultEditor.onAction("externalEditor", () => this.openExternalEditor());
|
|
2071
|
-
this.defaultEditor.onAction("followUp", () => this.handleFollowUp());
|
|
2072
|
-
this.defaultEditor.onAction("dequeue", () => this.handleDequeue());
|
|
2073
|
-
this.defaultEditor.onAction("newSession", () => this.handleClearCommand());
|
|
2074
|
-
this.defaultEditor.onAction("tree", () => this.showTreeSelector());
|
|
2075
|
-
this.defaultEditor.onAction("fork", () => this.showUserMessageSelector());
|
|
2076
|
-
this.defaultEditor.onAction("resume", () => this.showSessionSelector());
|
|
2077
|
-
|
|
2078
|
-
this.defaultEditor.onChange = (text: string) => {
|
|
2079
|
-
const wasBashMode = this.isBashMode;
|
|
2080
|
-
this.isBashMode = text.trimStart().startsWith("!");
|
|
2081
|
-
if (wasBashMode !== this.isBashMode) {
|
|
2082
|
-
this.updateEditorBorderColor();
|
|
2083
|
-
}
|
|
2084
|
-
};
|
|
2085
|
-
|
|
2086
|
-
// Handle clipboard image paste (triggered on Ctrl+V)
|
|
2087
|
-
this.defaultEditor.onPasteImage = () => {
|
|
2088
|
-
this.handleClipboardImagePaste();
|
|
2089
|
-
};
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
|
-
private async handleClipboardImagePaste(): Promise<void> {
|
|
2093
|
-
try {
|
|
2094
|
-
const image = await readClipboardImage();
|
|
2095
|
-
if (!image) {
|
|
2096
|
-
return;
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
// Write to temp file
|
|
2100
|
-
const tmpDir = os.tmpdir();
|
|
2101
|
-
const ext = extensionForImageMimeType(image.mimeType) ?? "png";
|
|
2102
|
-
const fileName = `pi-clipboard-${crypto.randomUUID()}.${ext}`;
|
|
2103
|
-
const filePath = path.join(tmpDir, fileName);
|
|
2104
|
-
fs.writeFileSync(filePath, Buffer.from(image.bytes));
|
|
2105
|
-
|
|
2106
|
-
// Insert file path directly
|
|
2107
|
-
this.editor.insertTextAtCursor?.(filePath);
|
|
2108
|
-
this.ui.requestRender();
|
|
2109
|
-
} catch {
|
|
2110
|
-
// Silently ignore clipboard errors (may not have permission, etc.)
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
private getSlashCommandContext(): SlashCommandContext {
|
|
2115
|
-
return {
|
|
2116
|
-
session: this.session,
|
|
2117
|
-
ui: this.ui,
|
|
2118
|
-
keybindings: this.keybindings,
|
|
2119
|
-
chatContainer: this.chatContainer,
|
|
2120
|
-
statusContainer: this.statusContainer,
|
|
2121
|
-
editorContainer: this.editorContainer,
|
|
2122
|
-
headerContainer: this.headerContainer,
|
|
2123
|
-
pendingMessagesContainer: this.pendingMessagesContainer,
|
|
2124
|
-
editor: this.editor,
|
|
2125
|
-
defaultEditor: this.defaultEditor,
|
|
2126
|
-
sessionManager: this.sessionManager,
|
|
2127
|
-
settingsManager: this.settingsManager,
|
|
2128
|
-
invalidateFooter: () => this.footer.invalidate(),
|
|
2129
|
-
showStatus: (msg) => this.showStatus(msg),
|
|
2130
|
-
showError: (msg) => this.showError(msg),
|
|
2131
|
-
showWarning: (msg) => this.showWarning(msg),
|
|
2132
|
-
showSelector: (create) => this.showSelector(create),
|
|
2133
|
-
updateEditorBorderColor: () => this.updateEditorBorderColor(),
|
|
2134
|
-
getMarkdownThemeWithSettings: () => this.getMarkdownThemeWithSettings(),
|
|
2135
|
-
requestRender: () => this.ui.requestRender(),
|
|
2136
|
-
updateTerminalTitle: () => this.updateTerminalTitle(),
|
|
2137
|
-
showSettingsSelector: () => this.showSettingsSelector(),
|
|
2138
|
-
showModelsSelector: () => this.showModelsSelector(),
|
|
2139
|
-
handleModelCommand: (searchTerm) => this.handleModelCommand(searchTerm),
|
|
2140
|
-
showUserMessageSelector: () => this.showUserMessageSelector(),
|
|
2141
|
-
showTreeSelector: () => this.showTreeSelector(),
|
|
2142
|
-
showProviderManager: () => this.showProviderManager(),
|
|
2143
|
-
showOAuthSelector: (mode) => this.showOAuthSelector(mode),
|
|
2144
|
-
showSessionSelector: () => this.showSessionSelector(),
|
|
2145
|
-
handleClearCommand: () => this.handleClearCommand(),
|
|
2146
|
-
handleReloadCommand: () => this.handleReloadCommand(),
|
|
2147
|
-
handleDebugCommand: () => this.handleDebugCommand(),
|
|
2148
|
-
shutdown: () => this.shutdown(),
|
|
2149
|
-
executeCompaction: (instructions, isAuto) => this.executeCompaction(instructions, isAuto),
|
|
2150
|
-
handleBashCommand: (command, options) => this.handleBashCommand(command, options?.excludeFromContext, options?.displayCommand, options?.loginShell),
|
|
2151
|
-
};
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
private setupEditorSubmitHandler(): void {
|
|
2155
|
-
setupEditorSubmitHandlerController(this as unknown as Parameters<typeof setupEditorSubmitHandlerController>[0]);
|
|
2156
|
-
}
|
|
2157
|
-
|
|
2158
|
-
private subscribeToAgent(): void {
|
|
2159
|
-
let eventQueue: Promise<void> = Promise.resolve();
|
|
2160
|
-
this.unsubscribe = this.session.subscribe((event) => {
|
|
2161
|
-
eventQueue = eventQueue.then(() => this.handleEvent(event)).catch(() => {});
|
|
2162
|
-
});
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
|
-
private async handleEvent(event: AgentSessionEvent): Promise<void> {
|
|
2166
|
-
await handleAgentEvent(this as unknown as Parameters<typeof handleAgentEvent>[0], event);
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
|
-
/** Extract text content from a user message */
|
|
2170
|
-
private getUserMessageText(message: Message): string {
|
|
2171
|
-
if (message.role !== "user") return "";
|
|
2172
|
-
const textBlocks =
|
|
2173
|
-
typeof message.content === "string"
|
|
2174
|
-
? [{ type: "text", text: message.content }]
|
|
2175
|
-
: message.content.filter((c: { type: string }) => c.type === "text");
|
|
2176
|
-
return textBlocks.map((c) => (c as { text: string }).text).join("");
|
|
2177
|
-
}
|
|
2178
|
-
|
|
2179
|
-
/**
|
|
2180
|
-
* Show a status message in the chat.
|
|
2181
|
-
*
|
|
2182
|
-
* If multiple status messages are emitted back-to-back (without anything else being added to the chat),
|
|
2183
|
-
* we update the previous status line instead of appending new ones to avoid log spam.
|
|
2184
|
-
*/
|
|
2185
|
-
private showStatus(message: string, options?: { append?: boolean }): void {
|
|
2186
|
-
const append = options?.append ?? false;
|
|
2187
|
-
const children = this.chatContainer.children;
|
|
2188
|
-
const last = children.length > 0 ? children[children.length - 1] : undefined;
|
|
2189
|
-
const secondLast = children.length > 1 ? children[children.length - 2] : undefined;
|
|
2190
|
-
|
|
2191
|
-
if (!append && last && secondLast && last === this.lastStatusText && secondLast === this.lastStatusSpacer) {
|
|
2192
|
-
this.lastStatusText.setText(theme.fg("dim", message));
|
|
2193
|
-
this.ui.requestRender();
|
|
2194
|
-
return;
|
|
2195
|
-
}
|
|
2196
|
-
|
|
2197
|
-
const spacer = new Spacer(1);
|
|
2198
|
-
const text = new Text(theme.fg("dim", message), 1, 0);
|
|
2199
|
-
this.chatContainer.addChild(spacer);
|
|
2200
|
-
this.chatContainer.addChild(text);
|
|
2201
|
-
this.lastStatusSpacer = spacer;
|
|
2202
|
-
this.lastStatusText = text;
|
|
2203
|
-
this.ui.requestRender();
|
|
2204
|
-
}
|
|
2205
|
-
|
|
2206
|
-
private getTimestampFormat(): TimestampFormat {
|
|
2207
|
-
return (this.settingsManager as unknown as GSDSettingsManager).getTimestampFormat?.() ?? "date-time-iso";
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
private addMessageToChat(message: AgentMessage, options?: { populateHistory?: boolean }): void {
|
|
2211
|
-
const timestampFormat = this.getTimestampFormat();
|
|
2212
|
-
switch (message.role) {
|
|
2213
|
-
case "bashExecution": {
|
|
2214
|
-
const component = new BashExecutionComponent(message.command, this.ui, message.excludeFromContext);
|
|
2215
|
-
if (message.output) {
|
|
2216
|
-
component.appendOutput(message.output);
|
|
2217
|
-
}
|
|
2218
|
-
component.setComplete(
|
|
2219
|
-
message.exitCode,
|
|
2220
|
-
message.cancelled,
|
|
2221
|
-
message.truncated ? ({ truncated: true } as TruncationResult) : undefined,
|
|
2222
|
-
message.fullOutputPath,
|
|
2223
|
-
);
|
|
2224
|
-
this.chatContainer.addChild(component);
|
|
2225
|
-
break;
|
|
2226
|
-
}
|
|
2227
|
-
case "custom": {
|
|
2228
|
-
if (message.display) {
|
|
2229
|
-
const renderer = this.session.extensionRunner?.getMessageRenderer(message.customType);
|
|
2230
|
-
const component = new CustomMessageComponent(message, renderer, this.getMarkdownThemeWithSettings());
|
|
2231
|
-
component.setExpanded(this.toolOutputExpanded);
|
|
2232
|
-
this.chatContainer.addChild(component);
|
|
2233
|
-
}
|
|
2234
|
-
break;
|
|
2235
|
-
}
|
|
2236
|
-
case "compactionSummary": {
|
|
2237
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2238
|
-
const component = new CompactionSummaryMessageComponent(message, this.getMarkdownThemeWithSettings());
|
|
2239
|
-
component.setExpanded(this.toolOutputExpanded);
|
|
2240
|
-
this.chatContainer.addChild(component);
|
|
2241
|
-
break;
|
|
2242
|
-
}
|
|
2243
|
-
case "branchSummary": {
|
|
2244
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2245
|
-
const component = new BranchSummaryMessageComponent(message, this.getMarkdownThemeWithSettings());
|
|
2246
|
-
component.setExpanded(this.toolOutputExpanded);
|
|
2247
|
-
this.chatContainer.addChild(component);
|
|
2248
|
-
break;
|
|
2249
|
-
}
|
|
2250
|
-
case "user": {
|
|
2251
|
-
const textContent = this.getUserMessageText(message);
|
|
2252
|
-
if (textContent) {
|
|
2253
|
-
const skillBlock = parseSkillBlock(textContent);
|
|
2254
|
-
if (skillBlock) {
|
|
2255
|
-
// Render skill block (collapsible)
|
|
2256
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2257
|
-
const component = new SkillInvocationMessageComponent(
|
|
2258
|
-
skillBlock,
|
|
2259
|
-
this.getMarkdownThemeWithSettings(),
|
|
2260
|
-
);
|
|
2261
|
-
component.setExpanded(this.toolOutputExpanded);
|
|
2262
|
-
this.chatContainer.addChild(component);
|
|
2263
|
-
// Render user message separately if present
|
|
2264
|
-
if (skillBlock.userMessage) {
|
|
2265
|
-
const userComponent = new UserMessageComponent(
|
|
2266
|
-
skillBlock.userMessage,
|
|
2267
|
-
this.getMarkdownThemeWithSettings(),
|
|
2268
|
-
message.timestamp,
|
|
2269
|
-
timestampFormat,
|
|
2270
|
-
);
|
|
2271
|
-
this.chatContainer.addChild(userComponent);
|
|
2272
|
-
}
|
|
2273
|
-
} else {
|
|
2274
|
-
const userComponent = new UserMessageComponent(textContent, this.getMarkdownThemeWithSettings(), message.timestamp, timestampFormat);
|
|
2275
|
-
this.chatContainer.addChild(userComponent);
|
|
2276
|
-
}
|
|
2277
|
-
if (options?.populateHistory) {
|
|
2278
|
-
this.editor.addToHistory?.(textContent);
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
break;
|
|
2282
|
-
}
|
|
2283
|
-
case "assistant": {
|
|
2284
|
-
const assistantComponent = new AssistantMessageComponent(
|
|
2285
|
-
message,
|
|
2286
|
-
this.hideThinkingBlock,
|
|
2287
|
-
this.getMarkdownThemeWithSettings(),
|
|
2288
|
-
timestampFormat,
|
|
2289
|
-
);
|
|
2290
|
-
this.chatContainer.addChild(assistantComponent);
|
|
2291
|
-
break;
|
|
2292
|
-
}
|
|
2293
|
-
case "toolResult": {
|
|
2294
|
-
// Tool results are rendered inline with tool calls, handled separately
|
|
2295
|
-
break;
|
|
2296
|
-
}
|
|
2297
|
-
default: {
|
|
2298
|
-
const _exhaustive: never = message;
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
this.trimChatHistory();
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
/**
|
|
2305
|
-
* Remove oldest components when chat exceeds MAX_CHAT_COMPONENTS.
|
|
2306
|
-
* Only render-components are removed — session data stays in SessionManager.
|
|
2307
|
-
*/
|
|
2308
|
-
private trimChatHistory(): void {
|
|
2309
|
-
while (this.chatContainer.children.length > InteractiveMode.MAX_CHAT_COMPONENTS) {
|
|
2310
|
-
const oldest = this.chatContainer.children[0];
|
|
2311
|
-
this.chatContainer.removeChild(oldest);
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
|
|
2315
|
-
/**
|
|
2316
|
-
* Render session context to chat. Used for initial load and rebuild after compaction.
|
|
2317
|
-
* @param sessionContext Session context to render
|
|
2318
|
-
* @param options.updateFooter Update footer state
|
|
2319
|
-
* @param options.populateHistory Add user messages to editor history
|
|
2320
|
-
*/
|
|
2321
|
-
private renderSessionContext(
|
|
2322
|
-
sessionContext: SessionContext,
|
|
2323
|
-
options: { updateFooter?: boolean; populateHistory?: boolean } = {},
|
|
2324
|
-
): void {
|
|
2325
|
-
this.pendingTools.clear();
|
|
2326
|
-
const timestampFormat = this.getTimestampFormat();
|
|
2327
|
-
|
|
2328
|
-
if (options.updateFooter) {
|
|
2329
|
-
this.footer.invalidate();
|
|
2330
|
-
this.updateEditorBorderColor();
|
|
2331
|
-
}
|
|
2332
|
-
|
|
2333
|
-
for (const message of sessionContext.messages) {
|
|
2334
|
-
// Assistant messages need special handling for tool calls
|
|
2335
|
-
if (message.role === "assistant") {
|
|
2336
|
-
const hasToolBlocks = message.content.some((c) => c.type === "toolCall" || isServerToolUseBlock(c));
|
|
2337
|
-
if (!hasToolBlocks) {
|
|
2338
|
-
this.addMessageToChat(message);
|
|
2339
|
-
continue;
|
|
2340
|
-
}
|
|
2341
|
-
|
|
2342
|
-
const assistantSegments: AssistantMessageComponent[] = [];
|
|
2343
|
-
const replaySegments = buildAssistantReplaySegments(message.content);
|
|
2344
|
-
|
|
2345
|
-
for (const segment of replaySegments) {
|
|
2346
|
-
if (segment.kind === "assistant") {
|
|
2347
|
-
const assistantComponent = new AssistantMessageComponent(
|
|
2348
|
-
message,
|
|
2349
|
-
this.hideThinkingBlock,
|
|
2350
|
-
this.getMarkdownThemeWithSettings(),
|
|
2351
|
-
timestampFormat,
|
|
2352
|
-
{ startIndex: segment.startIndex, endIndex: segment.endIndex },
|
|
2353
|
-
);
|
|
2354
|
-
this.chatContainer.addChild(assistantComponent);
|
|
2355
|
-
assistantSegments.push(assistantComponent);
|
|
2356
|
-
continue;
|
|
2357
|
-
}
|
|
2358
|
-
|
|
2359
|
-
const content = message.content[segment.contentIndex];
|
|
2360
|
-
if (content.type === "toolCall") {
|
|
2361
|
-
const component = new ToolExecutionComponent(
|
|
2362
|
-
content.name,
|
|
2363
|
-
content.arguments,
|
|
2364
|
-
{ showImages: this.settingsManager.getShowImages() },
|
|
2365
|
-
this.getRegisteredToolDefinition(content.name),
|
|
2366
|
-
this.ui,
|
|
2367
|
-
);
|
|
2368
|
-
component.setExpanded(this.toolOutputExpanded);
|
|
2369
|
-
this.chatContainer.addChild(component);
|
|
2370
|
-
|
|
2371
|
-
if (message.stopReason === "aborted" || message.stopReason === "error") {
|
|
2372
|
-
let errorMessage: string;
|
|
2373
|
-
if (message.stopReason === "aborted") {
|
|
2374
|
-
const retryAttempt = this.session.retryAttempt;
|
|
2375
|
-
errorMessage =
|
|
2376
|
-
retryAttempt > 0
|
|
2377
|
-
? `Aborted after ${retryAttempt} retry attempt${retryAttempt > 1 ? "s" : ""}`
|
|
2378
|
-
: "Operation aborted";
|
|
2379
|
-
} else {
|
|
2380
|
-
errorMessage = message.errorMessage || "Error";
|
|
2381
|
-
}
|
|
2382
|
-
component.updateResult({ content: [{ type: "text", text: errorMessage }], isError: true });
|
|
2383
|
-
} else {
|
|
2384
|
-
this.pendingTools.set(content.id, component);
|
|
2385
|
-
}
|
|
2386
|
-
} else if (isServerToolUseBlock(content)) {
|
|
2387
|
-
// Server-side tool (e.g., native web search)
|
|
2388
|
-
const component = new ToolExecutionComponent(
|
|
2389
|
-
content.name,
|
|
2390
|
-
content.input,
|
|
2391
|
-
{ showImages: this.settingsManager.getShowImages() },
|
|
2392
|
-
undefined,
|
|
2393
|
-
this.ui,
|
|
2394
|
-
);
|
|
2395
|
-
component.setExpanded(this.toolOutputExpanded);
|
|
2396
|
-
this.chatContainer.addChild(component);
|
|
2397
|
-
// Find matching webSearchResult in this message's content
|
|
2398
|
-
const resultBlock = message.content.find(
|
|
2399
|
-
(c) => isWebSearchResultBlock(c) && c.toolUseId === content.id,
|
|
2400
|
-
);
|
|
2401
|
-
if (resultBlock && isWebSearchResultBlock(resultBlock)) {
|
|
2402
|
-
const searchContent = resultBlock.content;
|
|
2403
|
-
const isError = searchContent && typeof searchContent === "object" && "type" in searchContent && (searchContent as { type: unknown }).type === "web_search_tool_result_error";
|
|
2404
|
-
const resultText = this.formatWebSearchResult(searchContent);
|
|
2405
|
-
component.updateResult({
|
|
2406
|
-
content: [{ type: "text", text: resultText }],
|
|
2407
|
-
isError: !!isError,
|
|
2408
|
-
});
|
|
2409
|
-
} else {
|
|
2410
|
-
// No result yet (aborted stream?) — show as pending
|
|
2411
|
-
if (content.id) {
|
|
2412
|
-
this.pendingTools.set(content.id, component);
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
|
-
// Match streaming-mode behavior: show metadata once on the final
|
|
2419
|
-
// assistant prose segment for this message.
|
|
2420
|
-
const lastAssistantSegment = assistantSegments[assistantSegments.length - 1];
|
|
2421
|
-
lastAssistantSegment?.setShowMetadata(true);
|
|
2422
|
-
} else if (message.role === "toolResult") {
|
|
2423
|
-
// Match tool results to pending tool components
|
|
2424
|
-
const component = this.pendingTools.get(message.toolCallId);
|
|
2425
|
-
if (component) {
|
|
2426
|
-
component.updateResult(message);
|
|
2427
|
-
this.pendingTools.delete(message.toolCallId);
|
|
2428
|
-
}
|
|
2429
|
-
} else {
|
|
2430
|
-
// All other messages use standard rendering
|
|
2431
|
-
this.addMessageToChat(message, options);
|
|
2432
|
-
}
|
|
2433
|
-
}
|
|
2434
|
-
|
|
2435
|
-
// Any pendingTools entries left over after replay are historical tool
|
|
2436
|
-
// calls whose results were squashed out of session context (commonly by
|
|
2437
|
-
// compaction). Mark them finished so the frame stops showing "Running".
|
|
2438
|
-
for (const component of this.pendingTools.values()) {
|
|
2439
|
-
component.markHistoricalNoResult();
|
|
2440
|
-
}
|
|
2441
|
-
this.pendingTools.clear();
|
|
2442
|
-
this.trimChatHistory();
|
|
2443
|
-
this.ui.requestRender();
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
renderInitialMessages(): void {
|
|
2447
|
-
// Get aligned messages and entries from session context
|
|
2448
|
-
const context = this.sessionManager.buildSessionContext();
|
|
2449
|
-
this.renderSessionContext(context, {
|
|
2450
|
-
updateFooter: true,
|
|
2451
|
-
populateHistory: true,
|
|
2452
|
-
});
|
|
2453
|
-
this.populatePinnedFromMessages(context.messages);
|
|
2454
|
-
|
|
2455
|
-
// Show compaction info if session was compacted
|
|
2456
|
-
const allEntries = this.sessionManager.getEntries();
|
|
2457
|
-
const compactionCount = allEntries.filter((e) => e.type === "compaction").length;
|
|
2458
|
-
if (compactionCount > 0) {
|
|
2459
|
-
const times = compactionCount === 1 ? "1 time" : `${compactionCount} times`;
|
|
2460
|
-
this.showStatus(`Session compacted ${times}`);
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
async getUserInput(): Promise<string> {
|
|
2465
|
-
return new Promise((resolve) => {
|
|
2466
|
-
this.onInputCallback = (text: string) => {
|
|
2467
|
-
this.onInputCallback = undefined;
|
|
2468
|
-
resolve(text);
|
|
2469
|
-
};
|
|
2470
|
-
});
|
|
2471
|
-
}
|
|
2472
|
-
|
|
2473
|
-
private rebuildChatFromMessages(): void {
|
|
2474
|
-
this.chatContainer.clear();
|
|
2475
|
-
this.pinnedMessageContainer.clear();
|
|
2476
|
-
const context = this.sessionManager.buildSessionContext();
|
|
2477
|
-
this.renderSessionContext(context);
|
|
2478
|
-
// Pinned content NOT re-populated here — the streaming lifecycle in
|
|
2479
|
-
// chat-controller.ts manages the pinned zone during active work.
|
|
2480
|
-
// populatePinnedFromMessages() remains in renderInitialMessages()
|
|
2481
|
-
// for the session-resume case at startup.
|
|
2482
|
-
}
|
|
2483
|
-
|
|
2484
|
-
/**
|
|
2485
|
-
* After rebuilding chat from messages, pin the last assistant text above the
|
|
2486
|
-
* editor if tool results would otherwise push it out of the viewport.
|
|
2487
|
-
*/
|
|
2488
|
-
private populatePinnedFromMessages(messages: AgentMessage[]): void {
|
|
2489
|
-
this.pinnedMessageContainer.clear();
|
|
2490
|
-
|
|
2491
|
-
// Walk backwards to find the last assistant message
|
|
2492
|
-
let lastAssistant: AssistantMessage | undefined;
|
|
2493
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
2494
|
-
const msg = messages[i];
|
|
2495
|
-
if (msg && "role" in msg && msg.role === "assistant") {
|
|
2496
|
-
lastAssistant = msg as AssistantMessage;
|
|
2497
|
-
break;
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
if (!lastAssistant) return;
|
|
2501
|
-
|
|
2502
|
-
// Check if any tool calls follow the last text block
|
|
2503
|
-
const content = lastAssistant.content;
|
|
2504
|
-
let lastTextIndex = -1;
|
|
2505
|
-
let hasToolAfterText = false;
|
|
2506
|
-
for (let i = 0; i < content.length; i++) {
|
|
2507
|
-
if (content[i].type === "text") lastTextIndex = i;
|
|
2508
|
-
}
|
|
2509
|
-
if (lastTextIndex >= 0) {
|
|
2510
|
-
for (let i = lastTextIndex + 1; i < content.length; i++) {
|
|
2511
|
-
const block = content[i];
|
|
2512
|
-
if (block.type === "toolCall" || isServerToolUseBlock(block)) {
|
|
2513
|
-
hasToolAfterText = true;
|
|
2514
|
-
break;
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
if (!hasToolAfterText || lastTextIndex < 0) return;
|
|
2519
|
-
|
|
2520
|
-
const textBlock = content[lastTextIndex] as { type: "text"; text: string };
|
|
2521
|
-
const text = textBlock.text?.trim();
|
|
2522
|
-
if (!text) return;
|
|
2523
|
-
|
|
2524
|
-
this.pinnedMessageContainer.addChild(
|
|
2525
|
-
new DynamicBorder((str: string) => theme.fg("dim", str), "Latest Output"),
|
|
2526
|
-
);
|
|
2527
|
-
this.pinnedMessageContainer.addChild(
|
|
2528
|
-
new Markdown(text, 1, 0, this.getMarkdownThemeWithSettings()),
|
|
2529
|
-
);
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
// =========================================================================
|
|
2533
|
-
// Key handlers
|
|
2534
|
-
// =========================================================================
|
|
2535
|
-
|
|
2536
|
-
private handleCtrlC(): void {
|
|
2537
|
-
const now = Date.now();
|
|
2538
|
-
if (now - this.lastSigintTime < 500) {
|
|
2539
|
-
void this.shutdown();
|
|
2540
|
-
} else {
|
|
2541
|
-
this.clearEditor();
|
|
2542
|
-
this.lastSigintTime = now;
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
|
|
2546
|
-
private handleCtrlD(): void {
|
|
2547
|
-
// Only called when editor is empty (enforced by CustomEditor)
|
|
2548
|
-
void this.shutdown();
|
|
2549
|
-
}
|
|
2550
|
-
|
|
2551
|
-
/**
|
|
2552
|
-
* Gracefully shutdown the agent.
|
|
2553
|
-
* Emits shutdown event to extensions, then exits.
|
|
2554
|
-
*/
|
|
2555
|
-
private isShuttingDown = false;
|
|
2556
|
-
|
|
2557
|
-
private async shutdown(): Promise<void> {
|
|
2558
|
-
const shutdownBehavior = this.options.shutdownBehavior ?? "exit_process";
|
|
2559
|
-
if (shutdownBehavior === "ignore") {
|
|
2560
|
-
this.showStatus("Quit is unavailable in the browser-attached terminal");
|
|
2561
|
-
return;
|
|
2562
|
-
}
|
|
2563
|
-
|
|
2564
|
-
if (this.isShuttingDown) return;
|
|
2565
|
-
this.isShuttingDown = true;
|
|
2566
|
-
|
|
2567
|
-
// Flush any queued settings writes before shutdown
|
|
2568
|
-
await this.settingsManager.flush();
|
|
2569
|
-
|
|
2570
|
-
// Emit shutdown event to extensions
|
|
2571
|
-
const extensionRunner = this.session.extensionRunner;
|
|
2572
|
-
if (extensionRunner?.hasHandlers("session_shutdown")) {
|
|
2573
|
-
await extensionRunner.emit({
|
|
2574
|
-
type: "session_shutdown",
|
|
2575
|
-
});
|
|
2576
|
-
}
|
|
2577
|
-
|
|
2578
|
-
// Wait for any pending renders to complete
|
|
2579
|
-
// requestRender() uses process.nextTick(), so we wait one tick
|
|
2580
|
-
await new Promise((resolve) => process.nextTick(resolve));
|
|
2581
|
-
|
|
2582
|
-
// Drain any in-flight Kitty key release events before stopping.
|
|
2583
|
-
// This prevents escape sequences from leaking to the parent shell over slow SSH.
|
|
2584
|
-
await this.ui.terminal.drainInput(1000);
|
|
2585
|
-
|
|
2586
|
-
this.stop();
|
|
2587
|
-
if (shutdownBehavior === "stop_ui") {
|
|
2588
|
-
return;
|
|
2589
|
-
}
|
|
2590
|
-
|
|
2591
|
-
// Kill ALL descendant processes to prevent orphans (next-server, pnpm dev, etc.)
|
|
2592
|
-
try {
|
|
2593
|
-
const descendants = listDescendants(process.pid);
|
|
2594
|
-
for (const childPid of descendants) {
|
|
2595
|
-
try { process.kill(childPid, "SIGTERM"); } catch (_e: unknown) { /* ignore — process may have already exited */ }
|
|
2596
|
-
}
|
|
2597
|
-
if (descendants.length > 0) {
|
|
2598
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
2599
|
-
for (const childPid of descendants) {
|
|
2600
|
-
try { process.kill(childPid, "SIGKILL"); } catch (_e: unknown) { /* ignore — process may have already exited */ }
|
|
2601
|
-
}
|
|
2602
|
-
}
|
|
2603
|
-
} catch (_e: unknown) { /* ignore — listDescendants may fail on some platforms */ }
|
|
2604
|
-
|
|
2605
|
-
process.exit(0);
|
|
2606
|
-
}
|
|
2607
|
-
|
|
2608
|
-
/**
|
|
2609
|
-
* Check if shutdown was requested and perform shutdown if so.
|
|
2610
|
-
*/
|
|
2611
|
-
private async checkShutdownRequested(): Promise<void> {
|
|
2612
|
-
if (!this.shutdownRequested) return;
|
|
2613
|
-
await this.shutdown();
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
private handleCtrlZ(): void {
|
|
2617
|
-
// On Windows, SIGTSTP doesn't exist - Ctrl+Z is not supported
|
|
2618
|
-
if (process.platform === "win32") {
|
|
2619
|
-
return;
|
|
2620
|
-
}
|
|
2621
|
-
|
|
2622
|
-
// Ignore SIGINT while suspended so Ctrl+C in the terminal does not
|
|
2623
|
-
// kill the backgrounded process. The handler is removed on resume.
|
|
2624
|
-
const ignoreSigint = (): void => {};
|
|
2625
|
-
process.on("SIGINT", ignoreSigint);
|
|
2626
|
-
|
|
2627
|
-
try {
|
|
2628
|
-
// Set up handler to restore TUI when resumed
|
|
2629
|
-
process.once("SIGCONT", () => {
|
|
2630
|
-
process.removeListener("SIGINT", ignoreSigint);
|
|
2631
|
-
this.ui.start();
|
|
2632
|
-
this.ui.requestRender(true);
|
|
2633
|
-
});
|
|
2634
|
-
|
|
2635
|
-
// Stop the TUI (restore terminal to normal mode)
|
|
2636
|
-
this.ui.stop();
|
|
2637
|
-
|
|
2638
|
-
// Send SIGTSTP to process group (pid=0 means all processes in group)
|
|
2639
|
-
process.kill(0, "SIGTSTP");
|
|
2640
|
-
} catch {
|
|
2641
|
-
// If suspend fails (e.g. SIGTSTP not supported), ensure the
|
|
2642
|
-
// SIGINT listener doesn't leak.
|
|
2643
|
-
process.removeListener("SIGINT", ignoreSigint);
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
|
|
2647
|
-
private async handleFollowUp(): Promise<void> {
|
|
2648
|
-
const text = (this.editor.getExpandedText?.() ?? this.editor.getText()).trim();
|
|
2649
|
-
if (!text) return;
|
|
2650
|
-
|
|
2651
|
-
if (text.startsWith("/") && !this.isKnownSlashCommand(text)) {
|
|
2652
|
-
const command = text.split(/\s/)[0];
|
|
2653
|
-
this.showError(`Unknown command: ${command}. Use slash autocomplete to see available commands.`);
|
|
2654
|
-
return;
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
// Queue input during compaction (extension commands execute immediately)
|
|
2658
|
-
if (this.session.isCompacting) {
|
|
2659
|
-
if (this.isExtensionCommand(text)) {
|
|
2660
|
-
this.editor.addToHistory?.(text);
|
|
2661
|
-
this.editor.setText("");
|
|
2662
|
-
await this.session.prompt(text);
|
|
2663
|
-
} else {
|
|
2664
|
-
this.queueCompactionMessage(text, "followUp");
|
|
2665
|
-
}
|
|
2666
|
-
return;
|
|
2667
|
-
}
|
|
2668
|
-
|
|
2669
|
-
// Alt+Enter queues a follow-up message (waits until agent finishes)
|
|
2670
|
-
// This handles extension commands (execute immediately), prompt template expansion, and queueing
|
|
2671
|
-
if (this.session.isStreaming) {
|
|
2672
|
-
this.editor.addToHistory?.(text);
|
|
2673
|
-
this.editor.setText("");
|
|
2674
|
-
await this.session.prompt(text, { streamingBehavior: "followUp" });
|
|
2675
|
-
this.updatePendingMessagesDisplay();
|
|
2676
|
-
this.ui.requestRender();
|
|
2677
|
-
}
|
|
2678
|
-
// If not streaming, Alt+Enter acts like regular Enter (trigger onSubmit)
|
|
2679
|
-
else if (this.editor.onSubmit) {
|
|
2680
|
-
this.editor.onSubmit(text);
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
|
|
2684
|
-
private handleDequeue(): void {
|
|
2685
|
-
const restored = this.restoreQueuedMessagesToEditor();
|
|
2686
|
-
if (restored === 0) {
|
|
2687
|
-
this.showStatus("No queued messages to restore");
|
|
2688
|
-
} else {
|
|
2689
|
-
this.showStatus(`Restored ${restored} queued message${restored > 1 ? "s" : ""} to editor`);
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
|
-
private updateEditorBorderColor(): void {
|
|
2694
|
-
if (this.isBashMode) {
|
|
2695
|
-
this.editor.borderColor = theme.getBashModeBorderColor();
|
|
2696
|
-
} else {
|
|
2697
|
-
const level = this.session.thinkingLevel || "off";
|
|
2698
|
-
this.editor.borderColor = theme.getThinkingBorderColor(level);
|
|
2699
|
-
}
|
|
2700
|
-
this.ui.requestRender();
|
|
2701
|
-
}
|
|
2702
|
-
|
|
2703
|
-
private cycleThinkingLevel(): void {
|
|
2704
|
-
const newLevel = this.session.cycleThinkingLevel();
|
|
2705
|
-
if (newLevel === undefined) {
|
|
2706
|
-
this.showStatus("Current model does not support thinking");
|
|
2707
|
-
} else {
|
|
2708
|
-
this.footer.invalidate();
|
|
2709
|
-
this.updateEditorBorderColor();
|
|
2710
|
-
this.showStatus(`Thinking level: ${newLevel}`);
|
|
2711
|
-
}
|
|
2712
|
-
}
|
|
2713
|
-
|
|
2714
|
-
private async cycleModel(direction: "forward" | "backward"): Promise<void> {
|
|
2715
|
-
try {
|
|
2716
|
-
const result = await this.session.cycleModel(direction);
|
|
2717
|
-
if (result === undefined) {
|
|
2718
|
-
const msg = this.session.scopedModels.length > 0 ? "Only one model in scope" : "Only one model available";
|
|
2719
|
-
this.showStatus(msg);
|
|
2720
|
-
} else {
|
|
2721
|
-
this.footer.invalidate();
|
|
2722
|
-
this.updateEditorBorderColor();
|
|
2723
|
-
const thinkingStr =
|
|
2724
|
-
result.model.reasoning && result.thinkingLevel !== "off" ? ` (thinking: ${result.thinkingLevel})` : "";
|
|
2725
|
-
this.showStatus(`Switched to ${result.model.name || result.model.id}${thinkingStr}`);
|
|
2726
|
-
}
|
|
2727
|
-
} catch (error) {
|
|
2728
|
-
this.showError(error instanceof Error ? error.message : String(error));
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
|
|
2732
|
-
private toggleToolOutputExpansion(): void {
|
|
2733
|
-
this.setToolsExpanded(!this.toolOutputExpanded);
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
private setToolsExpanded(expanded: boolean): void {
|
|
2737
|
-
this.toolOutputExpanded = expanded;
|
|
2738
|
-
for (const child of this.chatContainer.children) {
|
|
2739
|
-
if (isExpandable(child)) {
|
|
2740
|
-
child.setExpanded(expanded);
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
this.ui.requestRender();
|
|
2744
|
-
}
|
|
2745
|
-
|
|
2746
|
-
private toggleThinkingBlockVisibility(): void {
|
|
2747
|
-
this.hideThinkingBlock = !this.hideThinkingBlock;
|
|
2748
|
-
this.settingsManager.setHideThinkingBlock(this.hideThinkingBlock);
|
|
2749
|
-
|
|
2750
|
-
// Rebuild chat from session messages
|
|
2751
|
-
this.chatContainer.clear();
|
|
2752
|
-
this.rebuildChatFromMessages();
|
|
2753
|
-
|
|
2754
|
-
// If streaming, re-add the streaming component with updated visibility and re-render
|
|
2755
|
-
if (this.streamingComponent && this.streamingMessage) {
|
|
2756
|
-
this.streamingComponent.setHideThinkingBlock(this.hideThinkingBlock);
|
|
2757
|
-
this.streamingComponent.updateContent(this.streamingMessage);
|
|
2758
|
-
this.chatContainer.addChild(this.streamingComponent);
|
|
2759
|
-
}
|
|
2760
|
-
|
|
2761
|
-
this.showStatus(`Thinking blocks: ${this.hideThinkingBlock ? "hidden" : "visible"}`);
|
|
2762
|
-
}
|
|
2763
|
-
|
|
2764
|
-
private openExternalEditor(): void {
|
|
2765
|
-
// Determine editor (respect $VISUAL, then $EDITOR)
|
|
2766
|
-
const editorCmd = process.env.VISUAL || process.env.EDITOR;
|
|
2767
|
-
if (!editorCmd) {
|
|
2768
|
-
let msg = "No editor configured. Set $VISUAL or $EDITOR environment variable.";
|
|
2769
|
-
if (process.env.TERM_PROGRAM === "iTerm.app") {
|
|
2770
|
-
msg +=
|
|
2771
|
-
"\n\nTip: If you meant to open the GSD dashboard (Ctrl+Alt+G), set Left Option Key to" +
|
|
2772
|
-
" \"Esc+\" in iTerm2 → Profiles → Keys. With the default \"Normal\" setting," +
|
|
2773
|
-
" Ctrl+Alt+G sends Ctrl+G instead.";
|
|
2774
|
-
}
|
|
2775
|
-
this.showWarning(msg);
|
|
2776
|
-
return;
|
|
2777
|
-
}
|
|
2778
|
-
|
|
2779
|
-
const currentText = this.editor.getExpandedText?.() ?? this.editor.getText();
|
|
2780
|
-
const tmpFile = path.join(os.tmpdir(), `pi-editor-${Date.now()}.pi.md`);
|
|
2781
|
-
|
|
2782
|
-
try {
|
|
2783
|
-
// Write current content to temp file
|
|
2784
|
-
fs.writeFileSync(tmpFile, currentText, "utf-8");
|
|
2785
|
-
|
|
2786
|
-
// Stop TUI to release terminal
|
|
2787
|
-
this.ui.stop();
|
|
2788
|
-
|
|
2789
|
-
// Split by space to support editor arguments (e.g., "code --wait")
|
|
2790
|
-
const [editor, ...editorArgs] = editorCmd.split(" ");
|
|
2791
|
-
|
|
2792
|
-
// Spawn editor synchronously with inherited stdio for interactive editing
|
|
2793
|
-
const result = spawnSync(editor, [...editorArgs, tmpFile], {
|
|
2794
|
-
stdio: "inherit",
|
|
2795
|
-
shell: process.platform === "win32",
|
|
2796
|
-
});
|
|
2797
|
-
|
|
2798
|
-
// On successful exit (status 0), replace editor content
|
|
2799
|
-
if (result.status === 0) {
|
|
2800
|
-
const newContent = fs.readFileSync(tmpFile, "utf-8").replace(/\n$/, "");
|
|
2801
|
-
this.editor.setText(newContent);
|
|
2802
|
-
}
|
|
2803
|
-
// On non-zero exit, keep original text (no action needed)
|
|
2804
|
-
} finally {
|
|
2805
|
-
// Clean up temp file
|
|
2806
|
-
try {
|
|
2807
|
-
fs.unlinkSync(tmpFile);
|
|
2808
|
-
} catch {
|
|
2809
|
-
// Ignore cleanup errors
|
|
2810
|
-
}
|
|
2811
|
-
|
|
2812
|
-
// Restart TUI
|
|
2813
|
-
this.ui.start();
|
|
2814
|
-
// Force full re-render since external editor uses alternate screen
|
|
2815
|
-
this.ui.requestRender(true);
|
|
2816
|
-
}
|
|
2817
|
-
}
|
|
2818
|
-
|
|
2819
|
-
// =========================================================================
|
|
2820
|
-
// UI helpers
|
|
2821
|
-
// =========================================================================
|
|
2822
|
-
|
|
2823
|
-
clearEditor(): void {
|
|
2824
|
-
this.editor.setText("");
|
|
2825
|
-
this.ui.requestRender();
|
|
2826
|
-
}
|
|
2827
|
-
|
|
2828
|
-
showError(errorMessage: string): void {
|
|
2829
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2830
|
-
this.chatContainer.addChild(new Text(theme.fg("error", `Error: ${errorMessage}`), 1, 0));
|
|
2831
|
-
this.ui.requestRender();
|
|
2832
|
-
}
|
|
2833
|
-
|
|
2834
|
-
showWarning(warningMessage: string): void {
|
|
2835
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2836
|
-
this.chatContainer.addChild(new Text(theme.fg("warning", `Warning: ${warningMessage}`), 1, 0));
|
|
2837
|
-
this.ui.requestRender();
|
|
2838
|
-
}
|
|
2839
|
-
|
|
2840
|
-
showSuccess(successMessage: string): void {
|
|
2841
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2842
|
-
this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("success", text)));
|
|
2843
|
-
this.chatContainer.addChild(
|
|
2844
|
-
new Text(theme.fg("success", successMessage), 1, 0),
|
|
2845
|
-
);
|
|
2846
|
-
this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("success", text)));
|
|
2847
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2848
|
-
this.ui.requestRender();
|
|
2849
|
-
}
|
|
2850
|
-
|
|
2851
|
-
showTip(message: string): void {
|
|
2852
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2853
|
-
this.chatContainer.addChild(new Text(theme.fg("dim", `💡 ${message}`), 1, 0));
|
|
2854
|
-
this.ui.requestRender();
|
|
2855
|
-
}
|
|
2856
|
-
|
|
2857
|
-
getContextPercent(): number | undefined {
|
|
2858
|
-
return this.session.getContextUsage()?.percent ?? undefined;
|
|
2859
|
-
}
|
|
2860
|
-
|
|
2861
|
-
showNewVersionNotification(newVersion: string): void {
|
|
2862
|
-
const action = theme.fg("accent", getUpdateInstruction("@gsd/pi-coding-agent"));
|
|
2863
|
-
const updateInstruction = theme.fg("muted", `New version ${newVersion} is available. `) + action;
|
|
2864
|
-
const changelogUrl = theme.fg(
|
|
2865
|
-
"accent",
|
|
2866
|
-
"https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/CHANGELOG.md",
|
|
2867
|
-
);
|
|
2868
|
-
const changelogLine = theme.fg("muted", "Changelog: ") + changelogUrl;
|
|
2869
|
-
|
|
2870
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
2871
|
-
this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("warning", text)));
|
|
2872
|
-
this.chatContainer.addChild(
|
|
2873
|
-
new Text(
|
|
2874
|
-
`${theme.bold(theme.fg("warning", "Update Available"))}\n${updateInstruction}\n${changelogLine}`,
|
|
2875
|
-
1,
|
|
2876
|
-
0,
|
|
2877
|
-
),
|
|
2878
|
-
);
|
|
2879
|
-
this.chatContainer.addChild(new DynamicBorder((text) => theme.fg("warning", text)));
|
|
2880
|
-
this.ui.requestRender();
|
|
2881
|
-
}
|
|
2882
|
-
|
|
2883
|
-
/**
|
|
2884
|
-
* Get all queued messages (read-only).
|
|
2885
|
-
* Combines session queue and compaction queue.
|
|
2886
|
-
*/
|
|
2887
|
-
private getAllQueuedMessages(): { steering: string[]; followUp: string[] } {
|
|
2888
|
-
return {
|
|
2889
|
-
steering: [
|
|
2890
|
-
...this.session.getSteeringMessages(),
|
|
2891
|
-
...this.compactionQueuedMessages.filter((msg) => msg.mode === "steer").map((msg) => msg.text),
|
|
2892
|
-
],
|
|
2893
|
-
followUp: [
|
|
2894
|
-
...this.session.getFollowUpMessages(),
|
|
2895
|
-
...this.compactionQueuedMessages.filter((msg) => msg.mode === "followUp").map((msg) => msg.text),
|
|
2896
|
-
],
|
|
2897
|
-
};
|
|
2898
|
-
}
|
|
2899
|
-
|
|
2900
|
-
/**
|
|
2901
|
-
* Clear all queued messages and return their contents.
|
|
2902
|
-
* Clears both session queue and compaction queue.
|
|
2903
|
-
*/
|
|
2904
|
-
private clearAllQueues(): { steering: string[]; followUp: string[] } {
|
|
2905
|
-
const { steering, followUp } = this.session.clearQueue();
|
|
2906
|
-
const compactionSteering = this.compactionQueuedMessages
|
|
2907
|
-
.filter((msg) => msg.mode === "steer")
|
|
2908
|
-
.map((msg) => msg.text);
|
|
2909
|
-
const compactionFollowUp = this.compactionQueuedMessages
|
|
2910
|
-
.filter((msg) => msg.mode === "followUp")
|
|
2911
|
-
.map((msg) => msg.text);
|
|
2912
|
-
this.compactionQueuedMessages = [];
|
|
2913
|
-
return {
|
|
2914
|
-
steering: [...steering, ...compactionSteering],
|
|
2915
|
-
followUp: [...followUp, ...compactionFollowUp],
|
|
2916
|
-
};
|
|
2917
|
-
}
|
|
2918
|
-
|
|
2919
|
-
private updatePendingMessagesDisplay(): void {
|
|
2920
|
-
this.pendingMessagesContainer.clear();
|
|
2921
|
-
const { steering: steeringMessages, followUp: followUpMessages } = this.getAllQueuedMessages();
|
|
2922
|
-
if (steeringMessages.length > 0 || followUpMessages.length > 0) {
|
|
2923
|
-
this.pendingMessagesContainer.addChild(new Spacer(1));
|
|
2924
|
-
for (const message of steeringMessages) {
|
|
2925
|
-
const text = theme.fg("dim", `Steering: ${message}`);
|
|
2926
|
-
this.pendingMessagesContainer.addChild(new TruncatedText(text, 1, 0));
|
|
2927
|
-
}
|
|
2928
|
-
for (const message of followUpMessages) {
|
|
2929
|
-
const text = theme.fg("dim", `Follow-up: ${message}`);
|
|
2930
|
-
this.pendingMessagesContainer.addChild(new TruncatedText(text, 1, 0));
|
|
2931
|
-
}
|
|
2932
|
-
const dequeueHint = getAppKeyDisplay(this.keybindings, "dequeue");
|
|
2933
|
-
const hintText = theme.fg("dim", `↳ ${dequeueHint} to edit all queued messages`);
|
|
2934
|
-
this.pendingMessagesContainer.addChild(new TruncatedText(hintText, 1, 0));
|
|
2935
|
-
}
|
|
2936
|
-
}
|
|
2937
|
-
|
|
2938
|
-
private restoreQueuedMessagesToEditor(options?: { abort?: boolean; currentText?: string }): number {
|
|
2939
|
-
const { steering, followUp } = this.clearAllQueues();
|
|
2940
|
-
const allQueued = [...steering, ...followUp];
|
|
2941
|
-
if (allQueued.length === 0) {
|
|
2942
|
-
this.updatePendingMessagesDisplay();
|
|
2943
|
-
if (options?.abort) {
|
|
2944
|
-
this.agent.abort();
|
|
2945
|
-
}
|
|
2946
|
-
return 0;
|
|
2947
|
-
}
|
|
2948
|
-
const queuedText = allQueued.join("\n\n");
|
|
2949
|
-
const currentText = options?.currentText ?? this.editor.getText();
|
|
2950
|
-
const combinedText = [queuedText, currentText].filter((t) => t.trim()).join("\n\n");
|
|
2951
|
-
this.editor.setText(combinedText);
|
|
2952
|
-
this.updatePendingMessagesDisplay();
|
|
2953
|
-
if (options?.abort) {
|
|
2954
|
-
this.agent.abort();
|
|
2955
|
-
}
|
|
2956
|
-
return allQueued.length;
|
|
2957
|
-
}
|
|
2958
|
-
|
|
2959
|
-
private queueCompactionMessage(text: string, mode: "steer" | "followUp"): void {
|
|
2960
|
-
if (text.startsWith("/") && !this.isKnownSlashCommand(text)) {
|
|
2961
|
-
const command = text.split(/\s/)[0];
|
|
2962
|
-
this.showError(`Unknown command: ${command}. Use slash autocomplete to see available commands.`);
|
|
2963
|
-
return;
|
|
2964
|
-
}
|
|
2965
|
-
|
|
2966
|
-
this.compactionQueuedMessages.push({ text, mode });
|
|
2967
|
-
this.editor.addToHistory?.(text);
|
|
2968
|
-
this.editor.setText("");
|
|
2969
|
-
this.updatePendingMessagesDisplay();
|
|
2970
|
-
this.showStatus("Queued message for after compaction");
|
|
2971
|
-
}
|
|
2972
|
-
|
|
2973
|
-
private isExtensionCommand(text: string): boolean {
|
|
2974
|
-
if (!text.startsWith("/")) return false;
|
|
2975
|
-
|
|
2976
|
-
const extensionRunner = this.session.extensionRunner;
|
|
2977
|
-
if (!extensionRunner) return false;
|
|
2978
|
-
|
|
2979
|
-
const spaceIndex = text.indexOf(" ");
|
|
2980
|
-
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
2981
|
-
return !!extensionRunner.getCommand(commandName);
|
|
2982
|
-
}
|
|
2983
|
-
|
|
2984
|
-
private isKnownSlashCommand(text: string): boolean {
|
|
2985
|
-
if (!text.startsWith("/")) return false;
|
|
2986
|
-
|
|
2987
|
-
const spaceIndex = text.indexOf(" ");
|
|
2988
|
-
const commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);
|
|
2989
|
-
|
|
2990
|
-
if (BUILTIN_SLASH_COMMANDS.some((command) => command.name === commandName)) {
|
|
2991
|
-
return true;
|
|
2992
|
-
}
|
|
2993
|
-
|
|
2994
|
-
if (this.isExtensionCommand(text)) {
|
|
2995
|
-
return true;
|
|
2996
|
-
}
|
|
2997
|
-
|
|
2998
|
-
if (this.session.promptTemplates.some((template) => template.name === commandName)) {
|
|
2999
|
-
return true;
|
|
3000
|
-
}
|
|
3001
|
-
|
|
3002
|
-
if (commandName.startsWith("skill:") && this.settingsManager.getEnableSkillCommands()) {
|
|
3003
|
-
const skillName = commandName.slice("skill:".length);
|
|
3004
|
-
return this.session.resourceLoader.getSkills().skills.some((skill) => skill.name === skillName);
|
|
3005
|
-
}
|
|
3006
|
-
|
|
3007
|
-
return false;
|
|
3008
|
-
}
|
|
3009
|
-
|
|
3010
|
-
private async flushCompactionQueue(options?: { willRetry?: boolean }): Promise<void> {
|
|
3011
|
-
if (this.compactionQueuedMessages.length === 0) {
|
|
3012
|
-
return;
|
|
3013
|
-
}
|
|
3014
|
-
|
|
3015
|
-
const queuedMessages = [...this.compactionQueuedMessages];
|
|
3016
|
-
this.compactionQueuedMessages = [];
|
|
3017
|
-
this.updatePendingMessagesDisplay();
|
|
3018
|
-
|
|
3019
|
-
const restoreQueue = (error: unknown): void => {
|
|
3020
|
-
this.session.clearQueue();
|
|
3021
|
-
this.compactionQueuedMessages = queuedMessages;
|
|
3022
|
-
this.updatePendingMessagesDisplay();
|
|
3023
|
-
this.showError(
|
|
3024
|
-
`Failed to send queued message${queuedMessages.length > 1 ? "s" : ""}: ${
|
|
3025
|
-
error instanceof Error ? error.message : String(error)
|
|
3026
|
-
}`,
|
|
3027
|
-
);
|
|
3028
|
-
};
|
|
3029
|
-
|
|
3030
|
-
try {
|
|
3031
|
-
if (options?.willRetry) {
|
|
3032
|
-
// When retry is pending, queue messages for the retry turn
|
|
3033
|
-
for (const message of queuedMessages) {
|
|
3034
|
-
if (this.isExtensionCommand(message.text)) {
|
|
3035
|
-
await this.session.prompt(message.text);
|
|
3036
|
-
} else if (message.mode === "followUp") {
|
|
3037
|
-
await this.session.followUp(message.text);
|
|
3038
|
-
} else {
|
|
3039
|
-
await this.session.steer(message.text);
|
|
3040
|
-
}
|
|
3041
|
-
}
|
|
3042
|
-
this.updatePendingMessagesDisplay();
|
|
3043
|
-
return;
|
|
3044
|
-
}
|
|
3045
|
-
|
|
3046
|
-
// Find first non-extension-command message to use as prompt
|
|
3047
|
-
const firstPromptIndex = queuedMessages.findIndex((message) => !this.isExtensionCommand(message.text));
|
|
3048
|
-
if (firstPromptIndex === -1) {
|
|
3049
|
-
// All extension commands - execute them all
|
|
3050
|
-
for (const message of queuedMessages) {
|
|
3051
|
-
await this.session.prompt(message.text);
|
|
3052
|
-
}
|
|
3053
|
-
return;
|
|
3054
|
-
}
|
|
3055
|
-
|
|
3056
|
-
// Execute any extension commands before the first prompt
|
|
3057
|
-
const preCommands = queuedMessages.slice(0, firstPromptIndex);
|
|
3058
|
-
const firstPrompt = queuedMessages[firstPromptIndex];
|
|
3059
|
-
const rest = queuedMessages.slice(firstPromptIndex + 1);
|
|
3060
|
-
|
|
3061
|
-
for (const message of preCommands) {
|
|
3062
|
-
await this.session.prompt(message.text);
|
|
3063
|
-
}
|
|
3064
|
-
|
|
3065
|
-
// Send first prompt (starts streaming)
|
|
3066
|
-
const promptPromise = this.session.prompt(firstPrompt.text).catch((error) => {
|
|
3067
|
-
restoreQueue(error);
|
|
3068
|
-
});
|
|
3069
|
-
|
|
3070
|
-
// Queue remaining messages
|
|
3071
|
-
for (const message of rest) {
|
|
3072
|
-
if (this.isExtensionCommand(message.text)) {
|
|
3073
|
-
await this.session.prompt(message.text);
|
|
3074
|
-
} else if (message.mode === "followUp") {
|
|
3075
|
-
await this.session.followUp(message.text);
|
|
3076
|
-
} else {
|
|
3077
|
-
await this.session.steer(message.text);
|
|
3078
|
-
}
|
|
3079
|
-
}
|
|
3080
|
-
this.updatePendingMessagesDisplay();
|
|
3081
|
-
void promptPromise;
|
|
3082
|
-
} catch (error) {
|
|
3083
|
-
restoreQueue(error);
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
|
-
/** Move pending bash components from pending area to chat */
|
|
3088
|
-
private flushPendingBashComponents(): void {
|
|
3089
|
-
for (const component of this.pendingBashComponents) {
|
|
3090
|
-
this.pendingMessagesContainer.removeChild(component);
|
|
3091
|
-
this.chatContainer.addChild(component);
|
|
3092
|
-
}
|
|
3093
|
-
this.pendingBashComponents = [];
|
|
3094
|
-
}
|
|
3095
|
-
|
|
3096
|
-
// =========================================================================
|
|
3097
|
-
// Selectors
|
|
3098
|
-
// =========================================================================
|
|
3099
|
-
|
|
3100
|
-
/**
|
|
3101
|
-
* Shows a selector component in place of the editor.
|
|
3102
|
-
* @param create Factory that receives a `done` callback and returns the component and focus target
|
|
3103
|
-
*/
|
|
3104
|
-
private showSelector(create: (done: () => void) => { component: Component; focus: Component }): void {
|
|
3105
|
-
const done = (): void => {
|
|
3106
|
-
this.editorContainer.clear();
|
|
3107
|
-
this.editorContainer.addChild(this.editor);
|
|
3108
|
-
this.ui.setFocus(this.editor);
|
|
3109
|
-
};
|
|
3110
|
-
const { component, focus } = create(done);
|
|
3111
|
-
this.editorContainer.clear();
|
|
3112
|
-
this.editorContainer.addChild(component);
|
|
3113
|
-
this.ui.setFocus(focus);
|
|
3114
|
-
this.ui.requestRender();
|
|
3115
|
-
}
|
|
3116
|
-
|
|
3117
|
-
private showSettingsSelector(): void {
|
|
3118
|
-
this.showSelector((done) => {
|
|
3119
|
-
const selector = new SettingsSelectorComponent(
|
|
3120
|
-
{
|
|
3121
|
-
autoCompact: this.session.autoCompactionEnabled,
|
|
3122
|
-
showImages: this.settingsManager.getShowImages(),
|
|
3123
|
-
autoResizeImages: this.settingsManager.getImageAutoResize(),
|
|
3124
|
-
blockImages: this.settingsManager.getBlockImages(),
|
|
3125
|
-
enableSkillCommands: this.settingsManager.getEnableSkillCommands(),
|
|
3126
|
-
steeringMode: this.session.steeringMode,
|
|
3127
|
-
followUpMode: this.session.followUpMode,
|
|
3128
|
-
transport: this.settingsManager.getTransport(),
|
|
3129
|
-
thinkingLevel: this.session.thinkingLevel,
|
|
3130
|
-
availableThinkingLevels: this.session.getAvailableThinkingLevels(),
|
|
3131
|
-
currentTheme: this.settingsManager.getTheme() || "dark",
|
|
3132
|
-
availableThemes: getAvailableThemes(),
|
|
3133
|
-
hideThinkingBlock: this.hideThinkingBlock,
|
|
3134
|
-
collapseChangelog: this.settingsManager.getCollapseChangelog(),
|
|
3135
|
-
doubleEscapeAction: this.settingsManager.getDoubleEscapeAction(),
|
|
3136
|
-
treeFilterMode: this.settingsManager.getTreeFilterMode(),
|
|
3137
|
-
showHardwareCursor: this.settingsManager.getShowHardwareCursor(),
|
|
3138
|
-
editorPaddingX: this.settingsManager.getEditorPaddingX(),
|
|
3139
|
-
autocompleteMaxVisible: this.settingsManager.getAutocompleteMaxVisible(),
|
|
3140
|
-
respectGitignoreInPicker: (this.settingsManager as unknown as GSDSettingsManager).getRespectGitignoreInPicker?.() ?? true,
|
|
3141
|
-
quietStartup: this.settingsManager.getQuietStartup(),
|
|
3142
|
-
clearOnShrink: this.settingsManager.getClearOnShrink(),
|
|
3143
|
-
timestampFormat: this.getTimestampFormat(),
|
|
3144
|
-
},
|
|
3145
|
-
{
|
|
3146
|
-
onAutoCompactChange: (enabled) => {
|
|
3147
|
-
this.session.setAutoCompactionEnabled(enabled);
|
|
3148
|
-
this.footer.setAutoCompactEnabled(enabled);
|
|
3149
|
-
},
|
|
3150
|
-
onShowImagesChange: (enabled) => {
|
|
3151
|
-
this.settingsManager.setShowImages(enabled);
|
|
3152
|
-
for (const child of this.chatContainer.children) {
|
|
3153
|
-
if (child instanceof ToolExecutionComponent) {
|
|
3154
|
-
child.setShowImages(enabled);
|
|
3155
|
-
}
|
|
3156
|
-
}
|
|
3157
|
-
},
|
|
3158
|
-
onAutoResizeImagesChange: (enabled) => {
|
|
3159
|
-
this.settingsManager.setImageAutoResize(enabled);
|
|
3160
|
-
},
|
|
3161
|
-
onBlockImagesChange: (blocked) => {
|
|
3162
|
-
this.settingsManager.setBlockImages(blocked);
|
|
3163
|
-
},
|
|
3164
|
-
onEnableSkillCommandsChange: (enabled) => {
|
|
3165
|
-
this.settingsManager.setEnableSkillCommands(enabled);
|
|
3166
|
-
this.setupAutocomplete();
|
|
3167
|
-
},
|
|
3168
|
-
onSteeringModeChange: (mode) => {
|
|
3169
|
-
this.session.setSteeringMode(mode);
|
|
3170
|
-
},
|
|
3171
|
-
onFollowUpModeChange: (mode) => {
|
|
3172
|
-
this.session.setFollowUpMode(mode);
|
|
3173
|
-
},
|
|
3174
|
-
onTransportChange: (transport) => {
|
|
3175
|
-
this.settingsManager.setTransport(transport);
|
|
3176
|
-
this.session.agent.setTransport(transport);
|
|
3177
|
-
},
|
|
3178
|
-
onThinkingLevelChange: (level) => {
|
|
3179
|
-
this.session.setThinkingLevel(level);
|
|
3180
|
-
this.footer.invalidate();
|
|
3181
|
-
this.updateEditorBorderColor();
|
|
3182
|
-
},
|
|
3183
|
-
onThemeChange: (themeName) => {
|
|
3184
|
-
const result = setTheme(themeName, true);
|
|
3185
|
-
this.settingsManager.setTheme(themeName);
|
|
3186
|
-
this.ui.invalidate();
|
|
3187
|
-
if (!result.success) {
|
|
3188
|
-
this.showError(`Failed to load theme "${themeName}": ${result.error}\nFell back to dark theme.`);
|
|
3189
|
-
}
|
|
3190
|
-
},
|
|
3191
|
-
onThemePreview: (themeName) => {
|
|
3192
|
-
const result = setTheme(themeName, true);
|
|
3193
|
-
if (result.success) {
|
|
3194
|
-
this.ui.invalidate();
|
|
3195
|
-
this.ui.requestRender();
|
|
3196
|
-
}
|
|
3197
|
-
},
|
|
3198
|
-
onHideThinkingBlockChange: (hidden) => {
|
|
3199
|
-
this.hideThinkingBlock = hidden;
|
|
3200
|
-
this.settingsManager.setHideThinkingBlock(hidden);
|
|
3201
|
-
for (const child of this.chatContainer.children) {
|
|
3202
|
-
if (child instanceof AssistantMessageComponent) {
|
|
3203
|
-
child.setHideThinkingBlock(hidden);
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
this.chatContainer.clear();
|
|
3207
|
-
this.rebuildChatFromMessages();
|
|
3208
|
-
},
|
|
3209
|
-
onCollapseChangelogChange: (collapsed) => {
|
|
3210
|
-
this.settingsManager.setCollapseChangelog(collapsed);
|
|
3211
|
-
},
|
|
3212
|
-
onQuietStartupChange: (enabled) => {
|
|
3213
|
-
this.settingsManager.setQuietStartup(enabled);
|
|
3214
|
-
},
|
|
3215
|
-
onDoubleEscapeActionChange: (action) => {
|
|
3216
|
-
this.settingsManager.setDoubleEscapeAction(action);
|
|
3217
|
-
},
|
|
3218
|
-
onTreeFilterModeChange: (mode) => {
|
|
3219
|
-
this.settingsManager.setTreeFilterMode(mode);
|
|
3220
|
-
},
|
|
3221
|
-
onShowHardwareCursorChange: (enabled) => {
|
|
3222
|
-
this.settingsManager.setShowHardwareCursor(enabled);
|
|
3223
|
-
this.ui.setShowHardwareCursor(enabled);
|
|
3224
|
-
},
|
|
3225
|
-
onEditorPaddingXChange: (padding) => {
|
|
3226
|
-
this.settingsManager.setEditorPaddingX(padding);
|
|
3227
|
-
this.defaultEditor.setPaddingX(padding);
|
|
3228
|
-
if (this.editor !== this.defaultEditor && this.editor.setPaddingX !== undefined) {
|
|
3229
|
-
this.editor.setPaddingX(padding);
|
|
3230
|
-
}
|
|
3231
|
-
},
|
|
3232
|
-
onAutocompleteMaxVisibleChange: (maxVisible) => {
|
|
3233
|
-
this.settingsManager.setAutocompleteMaxVisible(maxVisible);
|
|
3234
|
-
this.defaultEditor.setAutocompleteMaxVisible(maxVisible);
|
|
3235
|
-
if (this.editor !== this.defaultEditor && this.editor.setAutocompleteMaxVisible !== undefined) {
|
|
3236
|
-
this.editor.setAutocompleteMaxVisible(maxVisible);
|
|
3237
|
-
}
|
|
3238
|
-
},
|
|
3239
|
-
onClearOnShrinkChange: (enabled) => {
|
|
3240
|
-
this.settingsManager.setClearOnShrink(enabled);
|
|
3241
|
-
this.ui.setClearOnShrink(enabled);
|
|
3242
|
-
},
|
|
3243
|
-
onRespectGitignoreInPickerChange: (enabled) => {
|
|
3244
|
-
(this.settingsManager as unknown as GSDSettingsManager).setRespectGitignoreInPicker?.(enabled);
|
|
3245
|
-
(this.autocompleteProvider as unknown as GSDAutocompleteProvider | undefined)?.setRespectGitignore?.(enabled);
|
|
3246
|
-
},
|
|
3247
|
-
onTimestampFormatChange: (format) => {
|
|
3248
|
-
(this.settingsManager as unknown as GSDSettingsManager).setTimestampFormat?.(format);
|
|
3249
|
-
},
|
|
3250
|
-
onCancel: () => {
|
|
3251
|
-
done();
|
|
3252
|
-
this.ui.requestRender();
|
|
3253
|
-
},
|
|
3254
|
-
},
|
|
3255
|
-
);
|
|
3256
|
-
return { component: selector, focus: selector.getSettingsList() };
|
|
3257
|
-
});
|
|
3258
|
-
}
|
|
3259
|
-
|
|
3260
|
-
private async handleModelCommand(searchTerm?: string): Promise<void> {
|
|
3261
|
-
await handleModelCommandController(this as unknown as InteractiveModeStateHost, searchTerm);
|
|
3262
|
-
}
|
|
3263
|
-
|
|
3264
|
-
private async findExactModelMatch(searchTerm: string): Promise<Model<Api> | undefined> {
|
|
3265
|
-
return findExactModelMatchController(this as unknown as InteractiveModeStateHost, searchTerm);
|
|
3266
|
-
}
|
|
3267
|
-
|
|
3268
|
-
private async getModelCandidates(): Promise<Model<Api>[]> {
|
|
3269
|
-
return getModelCandidatesController(this as unknown as InteractiveModeStateHost);
|
|
3270
|
-
}
|
|
3271
|
-
|
|
3272
|
-
/** Update the footer's available provider count from current model candidates */
|
|
3273
|
-
private async updateAvailableProviderCount(): Promise<void> {
|
|
3274
|
-
await updateAvailableProviderCountController(this as unknown as InteractiveModeStateHost);
|
|
3275
|
-
}
|
|
3276
|
-
|
|
3277
|
-
private showModelSelector(initialSearchInput?: string): void {
|
|
3278
|
-
this.showSelector((done) => {
|
|
3279
|
-
const selector = new ModelSelectorComponent(
|
|
3280
|
-
this.ui,
|
|
3281
|
-
this.session.model,
|
|
3282
|
-
this.settingsManager,
|
|
3283
|
-
this.session.modelRegistry,
|
|
3284
|
-
this.session.scopedModels,
|
|
3285
|
-
async (model) => {
|
|
3286
|
-
try {
|
|
3287
|
-
await this.session.setModel(model);
|
|
3288
|
-
this.footer.invalidate();
|
|
3289
|
-
this.updateEditorBorderColor();
|
|
3290
|
-
done();
|
|
3291
|
-
this.showStatus(`Model: ${model.id}`);
|
|
3292
|
-
this.checkDaxnutsEasterEgg(model);
|
|
3293
|
-
} catch (error) {
|
|
3294
|
-
done();
|
|
3295
|
-
this.showError(error instanceof Error ? error.message : String(error));
|
|
3296
|
-
}
|
|
3297
|
-
},
|
|
3298
|
-
() => {
|
|
3299
|
-
done();
|
|
3300
|
-
this.ui.requestRender();
|
|
3301
|
-
},
|
|
3302
|
-
initialSearchInput,
|
|
3303
|
-
);
|
|
3304
|
-
return { component: selector, focus: selector };
|
|
3305
|
-
});
|
|
3306
|
-
}
|
|
3307
|
-
|
|
3308
|
-
private async showModelsSelector(): Promise<void> {
|
|
3309
|
-
// Get all available models
|
|
3310
|
-
this.session.modelRegistry.refresh();
|
|
3311
|
-
const allModels = this.session.modelRegistry.getAvailable();
|
|
3312
|
-
|
|
3313
|
-
if (allModels.length === 0) {
|
|
3314
|
-
this.showStatus("No models available");
|
|
3315
|
-
return;
|
|
3316
|
-
}
|
|
3317
|
-
|
|
3318
|
-
// Check if session has scoped models (from previous session-only changes or CLI --models)
|
|
3319
|
-
const sessionScopedModels = this.session.scopedModels;
|
|
3320
|
-
const hasSessionScope = sessionScopedModels.length > 0;
|
|
3321
|
-
|
|
3322
|
-
// Build enabled model IDs from session state or settings
|
|
3323
|
-
const enabledModelIds = new Set<string>();
|
|
3324
|
-
let hasFilter = false;
|
|
3325
|
-
|
|
3326
|
-
if (hasSessionScope) {
|
|
3327
|
-
// Use current session's scoped models
|
|
3328
|
-
for (const sm of sessionScopedModels) {
|
|
3329
|
-
enabledModelIds.add(`${sm.model.provider}/${sm.model.id}`);
|
|
3330
|
-
}
|
|
3331
|
-
hasFilter = true;
|
|
3332
|
-
} else {
|
|
3333
|
-
// Fall back to settings
|
|
3334
|
-
const patterns = this.settingsManager.getEnabledModels();
|
|
3335
|
-
if (patterns !== undefined && patterns.length > 0) {
|
|
3336
|
-
hasFilter = true;
|
|
3337
|
-
const scopedModels = await resolveModelScope(patterns, this.session.modelRegistry);
|
|
3338
|
-
for (const sm of scopedModels) {
|
|
3339
|
-
enabledModelIds.add(`${sm.model.provider}/${sm.model.id}`);
|
|
3340
|
-
}
|
|
3341
|
-
}
|
|
3342
|
-
}
|
|
3343
|
-
|
|
3344
|
-
// Track current enabled state (session-only until persisted)
|
|
3345
|
-
const currentEnabledIds = new Set(enabledModelIds);
|
|
3346
|
-
let currentHasFilter = hasFilter;
|
|
3347
|
-
|
|
3348
|
-
// Helper to update session's scoped models (session-only, no persist)
|
|
3349
|
-
const updateSessionModels = async (enabledIds: Set<string>): Promise<void> => {
|
|
3350
|
-
if (enabledIds.size > 0 && enabledIds.size < allModels.length) {
|
|
3351
|
-
const newScopedModels = await resolveModelScope(Array.from(enabledIds), this.session.modelRegistry);
|
|
3352
|
-
this.session.setScopedModels(
|
|
3353
|
-
newScopedModels.map((sm) => ({
|
|
3354
|
-
model: sm.model,
|
|
3355
|
-
thinkingLevel: sm.thinkingLevel,
|
|
3356
|
-
})),
|
|
3357
|
-
);
|
|
3358
|
-
} else {
|
|
3359
|
-
// All enabled or none enabled = no filter
|
|
3360
|
-
this.session.setScopedModels([]);
|
|
3361
|
-
}
|
|
3362
|
-
await this.updateAvailableProviderCount();
|
|
3363
|
-
this.ui.requestRender();
|
|
3364
|
-
};
|
|
3365
|
-
|
|
3366
|
-
this.showSelector((done) => {
|
|
3367
|
-
const selector = new ScopedModelsSelectorComponent(
|
|
3368
|
-
{
|
|
3369
|
-
allModels,
|
|
3370
|
-
enabledModelIds: currentEnabledIds,
|
|
3371
|
-
hasEnabledModelsFilter: currentHasFilter,
|
|
3372
|
-
},
|
|
3373
|
-
{
|
|
3374
|
-
onModelToggle: async (modelId, enabled) => {
|
|
3375
|
-
if (enabled) {
|
|
3376
|
-
currentEnabledIds.add(modelId);
|
|
3377
|
-
} else {
|
|
3378
|
-
currentEnabledIds.delete(modelId);
|
|
3379
|
-
}
|
|
3380
|
-
currentHasFilter = true;
|
|
3381
|
-
await updateSessionModels(currentEnabledIds);
|
|
3382
|
-
},
|
|
3383
|
-
onEnableAll: async (allModelIds) => {
|
|
3384
|
-
currentEnabledIds.clear();
|
|
3385
|
-
for (const id of allModelIds) {
|
|
3386
|
-
currentEnabledIds.add(id);
|
|
3387
|
-
}
|
|
3388
|
-
currentHasFilter = false;
|
|
3389
|
-
await updateSessionModels(currentEnabledIds);
|
|
3390
|
-
},
|
|
3391
|
-
onClearAll: async () => {
|
|
3392
|
-
currentEnabledIds.clear();
|
|
3393
|
-
currentHasFilter = true;
|
|
3394
|
-
await updateSessionModels(currentEnabledIds);
|
|
3395
|
-
},
|
|
3396
|
-
onToggleProvider: async (_provider, modelIds, enabled) => {
|
|
3397
|
-
for (const id of modelIds) {
|
|
3398
|
-
if (enabled) {
|
|
3399
|
-
currentEnabledIds.add(id);
|
|
3400
|
-
} else {
|
|
3401
|
-
currentEnabledIds.delete(id);
|
|
3402
|
-
}
|
|
3403
|
-
}
|
|
3404
|
-
currentHasFilter = true;
|
|
3405
|
-
await updateSessionModels(currentEnabledIds);
|
|
3406
|
-
},
|
|
3407
|
-
onPersist: (enabledIds) => {
|
|
3408
|
-
// Persist to settings
|
|
3409
|
-
const newPatterns =
|
|
3410
|
-
enabledIds.length === allModels.length
|
|
3411
|
-
? undefined // All enabled = clear filter
|
|
3412
|
-
: enabledIds;
|
|
3413
|
-
this.settingsManager.setEnabledModels(newPatterns);
|
|
3414
|
-
this.showStatus("Model selection saved to settings");
|
|
3415
|
-
},
|
|
3416
|
-
onCancel: () => {
|
|
3417
|
-
done();
|
|
3418
|
-
this.ui.requestRender();
|
|
3419
|
-
},
|
|
3420
|
-
},
|
|
3421
|
-
);
|
|
3422
|
-
return { component: selector, focus: selector };
|
|
3423
|
-
});
|
|
3424
|
-
}
|
|
3425
|
-
|
|
3426
|
-
private showUserMessageSelector(): void {
|
|
3427
|
-
const userMessages = this.session.getUserMessagesForForking();
|
|
3428
|
-
|
|
3429
|
-
if (userMessages.length === 0) {
|
|
3430
|
-
this.showStatus("No messages to fork from");
|
|
3431
|
-
return;
|
|
3432
|
-
}
|
|
3433
|
-
|
|
3434
|
-
this.showSelector((done) => {
|
|
3435
|
-
const selector = new UserMessageSelectorComponent(
|
|
3436
|
-
userMessages.map((m) => ({ id: m.entryId, text: m.text })),
|
|
3437
|
-
async (entryId) => {
|
|
3438
|
-
const result = await this.session.fork(entryId);
|
|
3439
|
-
if (result.cancelled) {
|
|
3440
|
-
// Extension cancelled the fork
|
|
3441
|
-
done();
|
|
3442
|
-
this.ui.requestRender();
|
|
3443
|
-
return;
|
|
3444
|
-
}
|
|
3445
|
-
|
|
3446
|
-
this.chatContainer.clear();
|
|
3447
|
-
this.renderInitialMessages();
|
|
3448
|
-
this.editor.setText(result.selectedText);
|
|
3449
|
-
done();
|
|
3450
|
-
this.showStatus("Branched to new session");
|
|
3451
|
-
},
|
|
3452
|
-
() => {
|
|
3453
|
-
done();
|
|
3454
|
-
this.ui.requestRender();
|
|
3455
|
-
},
|
|
3456
|
-
);
|
|
3457
|
-
return { component: selector, focus: selector.getMessageList() };
|
|
3458
|
-
});
|
|
3459
|
-
}
|
|
3460
|
-
|
|
3461
|
-
private showTreeSelector(initialSelectedId?: string): void {
|
|
3462
|
-
const tree = this.sessionManager.getTree();
|
|
3463
|
-
const realLeafId = this.sessionManager.getLeafId();
|
|
3464
|
-
const initialFilterMode = this.settingsManager.getTreeFilterMode();
|
|
3465
|
-
|
|
3466
|
-
if (tree.length === 0) {
|
|
3467
|
-
this.showStatus("No entries in session");
|
|
3468
|
-
return;
|
|
3469
|
-
}
|
|
3470
|
-
|
|
3471
|
-
this.showSelector((done) => {
|
|
3472
|
-
const selector = new TreeSelectorComponent(
|
|
3473
|
-
tree as unknown as ConstructorParameters<typeof TreeSelectorComponent>[0],
|
|
3474
|
-
realLeafId,
|
|
3475
|
-
this.ui.terminal.rows,
|
|
3476
|
-
async (entryId) => {
|
|
3477
|
-
// Selecting the current leaf is a no-op (already there)
|
|
3478
|
-
if (entryId === realLeafId) {
|
|
3479
|
-
done();
|
|
3480
|
-
this.showStatus("Already at this point");
|
|
3481
|
-
return;
|
|
3482
|
-
}
|
|
3483
|
-
|
|
3484
|
-
// Ask about summarization
|
|
3485
|
-
done(); // Close selector first
|
|
3486
|
-
|
|
3487
|
-
// Loop until user makes a complete choice or cancels to tree
|
|
3488
|
-
let wantsSummary = false;
|
|
3489
|
-
let customInstructions: string | undefined;
|
|
3490
|
-
|
|
3491
|
-
// Check if we should skip the prompt (user preference to always default to no summary)
|
|
3492
|
-
if (!this.settingsManager.getBranchSummarySkipPrompt()) {
|
|
3493
|
-
while (true) {
|
|
3494
|
-
const summaryChoice = await this.showExtensionSelector("Summarize branch?", [
|
|
3495
|
-
"No summary",
|
|
3496
|
-
"Summarize",
|
|
3497
|
-
"Summarize with custom prompt",
|
|
3498
|
-
]);
|
|
3499
|
-
|
|
3500
|
-
if (summaryChoice === undefined) {
|
|
3501
|
-
// User pressed escape - re-show tree selector with same selection
|
|
3502
|
-
this.showTreeSelector(entryId);
|
|
3503
|
-
return;
|
|
3504
|
-
}
|
|
3505
|
-
|
|
3506
|
-
wantsSummary = summaryChoice !== "No summary";
|
|
3507
|
-
|
|
3508
|
-
if (summaryChoice === "Summarize with custom prompt") {
|
|
3509
|
-
customInstructions = await this.showExtensionEditor("Custom summarization instructions");
|
|
3510
|
-
if (customInstructions === undefined) {
|
|
3511
|
-
// User cancelled - loop back to summary selector
|
|
3512
|
-
continue;
|
|
3513
|
-
}
|
|
3514
|
-
}
|
|
3515
|
-
|
|
3516
|
-
// User made a complete choice
|
|
3517
|
-
break;
|
|
3518
|
-
}
|
|
3519
|
-
}
|
|
3520
|
-
|
|
3521
|
-
// Set up escape handler and loader if summarizing
|
|
3522
|
-
let summaryLoader: Loader | undefined;
|
|
3523
|
-
const originalOnEscape = this.defaultEditor.onEscape;
|
|
3524
|
-
|
|
3525
|
-
if (wantsSummary) {
|
|
3526
|
-
this.defaultEditor.onEscape = () => {
|
|
3527
|
-
this.session.abortBranchSummary();
|
|
3528
|
-
};
|
|
3529
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
3530
|
-
summaryLoader = new Loader(
|
|
3531
|
-
this.ui,
|
|
3532
|
-
(spinner) => theme.fg("accent", spinner),
|
|
3533
|
-
(text) => theme.fg("muted", text),
|
|
3534
|
-
`Summarizing branch... (${appKey(this.keybindings, "interrupt")} to cancel)`,
|
|
3535
|
-
);
|
|
3536
|
-
this.statusContainer.addChild(summaryLoader);
|
|
3537
|
-
this.ui.requestRender();
|
|
3538
|
-
}
|
|
3539
|
-
|
|
3540
|
-
try {
|
|
3541
|
-
const result = await this.session.navigateTree(entryId, {
|
|
3542
|
-
summarize: wantsSummary,
|
|
3543
|
-
customInstructions,
|
|
3544
|
-
});
|
|
3545
|
-
|
|
3546
|
-
if (result.aborted) {
|
|
3547
|
-
// Summarization aborted - re-show tree selector with same selection
|
|
3548
|
-
this.showStatus("Branch summarization cancelled");
|
|
3549
|
-
this.showTreeSelector(entryId);
|
|
3550
|
-
return;
|
|
3551
|
-
}
|
|
3552
|
-
if (result.cancelled) {
|
|
3553
|
-
this.showStatus("Navigation cancelled");
|
|
3554
|
-
return;
|
|
3555
|
-
}
|
|
3556
|
-
|
|
3557
|
-
// Update UI
|
|
3558
|
-
this.chatContainer.clear();
|
|
3559
|
-
this.renderInitialMessages();
|
|
3560
|
-
if (result.editorText && !this.editor.getText().trim()) {
|
|
3561
|
-
this.editor.setText(result.editorText);
|
|
3562
|
-
}
|
|
3563
|
-
this.showStatus("Navigated to selected point");
|
|
3564
|
-
} catch (error) {
|
|
3565
|
-
this.showError(error instanceof Error ? error.message : String(error));
|
|
3566
|
-
} finally {
|
|
3567
|
-
if (summaryLoader) {
|
|
3568
|
-
summaryLoader.stop();
|
|
3569
|
-
this.statusContainer.clear();
|
|
3570
|
-
}
|
|
3571
|
-
this.defaultEditor.onEscape = originalOnEscape;
|
|
3572
|
-
}
|
|
3573
|
-
},
|
|
3574
|
-
() => {
|
|
3575
|
-
done();
|
|
3576
|
-
this.ui.requestRender();
|
|
3577
|
-
},
|
|
3578
|
-
(entryId, label) => {
|
|
3579
|
-
this.sessionManager.appendLabelChange(entryId, label);
|
|
3580
|
-
this.ui.requestRender();
|
|
3581
|
-
},
|
|
3582
|
-
initialSelectedId,
|
|
3583
|
-
initialFilterMode,
|
|
3584
|
-
);
|
|
3585
|
-
return { component: selector, focus: selector };
|
|
3586
|
-
});
|
|
3587
|
-
}
|
|
3588
|
-
|
|
3589
|
-
private showSessionSelector(): void {
|
|
3590
|
-
this.showSelector((done) => {
|
|
3591
|
-
const selector = new SessionSelectorComponent(
|
|
3592
|
-
(onProgress) =>
|
|
3593
|
-
SessionManager.list(this.sessionManager.getCwd(), this.sessionManager.getSessionDir(), onProgress),
|
|
3594
|
-
SessionManager.listAll,
|
|
3595
|
-
async (sessionPath) => {
|
|
3596
|
-
done();
|
|
3597
|
-
await this.handleResumeSession(sessionPath);
|
|
3598
|
-
},
|
|
3599
|
-
() => {
|
|
3600
|
-
done();
|
|
3601
|
-
this.ui.requestRender();
|
|
3602
|
-
},
|
|
3603
|
-
() => {
|
|
3604
|
-
void this.shutdown();
|
|
3605
|
-
},
|
|
3606
|
-
() => this.ui.requestRender(),
|
|
3607
|
-
{
|
|
3608
|
-
renameSession: async (sessionFilePath: string, nextName: string | undefined) => {
|
|
3609
|
-
const next = (nextName ?? "").trim();
|
|
3610
|
-
if (!next) return;
|
|
3611
|
-
const mgr = SessionManager.open(sessionFilePath);
|
|
3612
|
-
mgr.appendSessionInfo(next);
|
|
3613
|
-
},
|
|
3614
|
-
showRenameHint: true,
|
|
3615
|
-
keybindings: this.keybindings,
|
|
3616
|
-
},
|
|
3617
|
-
|
|
3618
|
-
this.sessionManager.getSessionFile(),
|
|
3619
|
-
);
|
|
3620
|
-
return { component: selector, focus: selector };
|
|
3621
|
-
});
|
|
3622
|
-
}
|
|
3623
|
-
|
|
3624
|
-
private async handleResumeSession(sessionPath: string): Promise<void> {
|
|
3625
|
-
// Stop loading animation
|
|
3626
|
-
if (this.loadingAnimation) {
|
|
3627
|
-
this.loadingAnimation.stop();
|
|
3628
|
-
this.loadingAnimation = undefined;
|
|
3629
|
-
}
|
|
3630
|
-
this.statusContainer.clear();
|
|
3631
|
-
|
|
3632
|
-
// Clear UI state
|
|
3633
|
-
this.pendingMessagesContainer.clear();
|
|
3634
|
-
this.compactionQueuedMessages = [];
|
|
3635
|
-
this.streamingComponent = undefined;
|
|
3636
|
-
this.streamingMessage = undefined;
|
|
3637
|
-
this.pendingTools.clear();
|
|
3638
|
-
|
|
3639
|
-
// Switch session via AgentSession (emits extension session events)
|
|
3640
|
-
await this.session.switchSession(sessionPath);
|
|
3641
|
-
|
|
3642
|
-
// Clear and re-render the chat
|
|
3643
|
-
this.chatContainer.clear();
|
|
3644
|
-
this.renderInitialMessages();
|
|
3645
|
-
|
|
3646
|
-
if ((this.session.sessionManager as unknown as GSDSessionManager).wasInterrupted?.()) {
|
|
3647
|
-
this.showStatus("Resumed session (previous session ended unexpectedly — last action may be incomplete)");
|
|
3648
|
-
} else {
|
|
3649
|
-
this.showStatus("Resumed session");
|
|
3650
|
-
}
|
|
3651
|
-
}
|
|
3652
|
-
|
|
3653
|
-
private showProviderManager(): void {
|
|
3654
|
-
this.showSelector((done) => {
|
|
3655
|
-
const component = new ProviderManagerComponent(
|
|
3656
|
-
this.ui,
|
|
3657
|
-
this.session.modelRegistry.authStorage,
|
|
3658
|
-
this.session.modelRegistry,
|
|
3659
|
-
() => {
|
|
3660
|
-
done();
|
|
3661
|
-
this.ui.requestRender();
|
|
3662
|
-
},
|
|
3663
|
-
async (provider: string) => {
|
|
3664
|
-
this.showStatus(`Discovering models for ${provider}...`);
|
|
3665
|
-
try {
|
|
3666
|
-
const results = await (this.session.modelRegistry as unknown as GSDModelRegistry).discoverModels?.([provider]) ?? [];
|
|
3667
|
-
const result = results[0];
|
|
3668
|
-
if (result?.error) {
|
|
3669
|
-
this.showError(`Discovery failed: ${result.error}`);
|
|
3670
|
-
} else {
|
|
3671
|
-
this.showStatus(`Discovered ${result?.models?.length ?? 0} models from ${provider}`);
|
|
3672
|
-
}
|
|
3673
|
-
} catch (error) {
|
|
3674
|
-
this.showError(error instanceof Error ? error.message : String(error));
|
|
3675
|
-
}
|
|
3676
|
-
done();
|
|
3677
|
-
this.ui.requestRender();
|
|
3678
|
-
},
|
|
3679
|
-
async (provider: string) => {
|
|
3680
|
-
// Enter key → auth setup for selected provider (#3579)
|
|
3681
|
-
done();
|
|
3682
|
-
await this.showLoginDialog(provider);
|
|
3683
|
-
},
|
|
3684
|
-
);
|
|
3685
|
-
return { component, focus: component };
|
|
3686
|
-
});
|
|
3687
|
-
}
|
|
3688
|
-
|
|
3689
|
-
private async showOAuthSelector(mode: "login" | "logout"): Promise<void> {
|
|
3690
|
-
if (mode === "logout") {
|
|
3691
|
-
const providers = this.session.modelRegistry.authStorage.list();
|
|
3692
|
-
const loggedInProviders = providers.filter(
|
|
3693
|
-
(p) => this.session.modelRegistry.authStorage.get(p)?.type === "oauth",
|
|
3694
|
-
);
|
|
3695
|
-
if (loggedInProviders.length === 0) {
|
|
3696
|
-
this.showStatus("No OAuth providers logged in. Use /login first.");
|
|
3697
|
-
return;
|
|
3698
|
-
}
|
|
3699
|
-
}
|
|
3700
|
-
|
|
3701
|
-
this.showSelector((done) => {
|
|
3702
|
-
const selector = new OAuthSelectorComponent(
|
|
3703
|
-
mode,
|
|
3704
|
-
this.session.modelRegistry.authStorage,
|
|
3705
|
-
(providerId: string) => {
|
|
3706
|
-
done();
|
|
3707
|
-
|
|
3708
|
-
// OAuthSelectorComponent calls this synchronously (no await),
|
|
3709
|
-
// so we must catch async errors here to prevent unhandled rejections
|
|
3710
|
-
// when the user cancels the login dialog (#821).
|
|
3711
|
-
const handleAsync = async (): Promise<void> => {
|
|
3712
|
-
if (mode === "login") {
|
|
3713
|
-
await this.showLoginDialog(providerId);
|
|
3714
|
-
} else {
|
|
3715
|
-
// Logout flow
|
|
3716
|
-
const providerInfo = this.session.modelRegistry.authStorage
|
|
3717
|
-
.getOAuthProviders()
|
|
3718
|
-
.find((p) => p.id === providerId);
|
|
3719
|
-
const providerName = providerInfo?.name || providerId;
|
|
3720
|
-
|
|
3721
|
-
try {
|
|
3722
|
-
this.session.modelRegistry.authStorage.logout(providerId);
|
|
3723
|
-
this.session.modelRegistry.refresh();
|
|
3724
|
-
await this.updateAvailableProviderCount();
|
|
3725
|
-
|
|
3726
|
-
// Auto-switch model if current model belongs to the logged-out provider
|
|
3727
|
-
const currentModel = this.session.model;
|
|
3728
|
-
if (currentModel?.provider === providerId) {
|
|
3729
|
-
try {
|
|
3730
|
-
const available = this.session.modelRegistry.getAvailable();
|
|
3731
|
-
const fallback = available.find((m) => m.provider !== providerId);
|
|
3732
|
-
if (fallback) {
|
|
3733
|
-
await this.session.setModel(fallback);
|
|
3734
|
-
}
|
|
3735
|
-
} catch {
|
|
3736
|
-
// Model switch failed — user can manually switch via /model
|
|
3737
|
-
}
|
|
3738
|
-
}
|
|
3739
|
-
|
|
3740
|
-
this.showStatus(`Logged out of ${providerName}`);
|
|
3741
|
-
} catch (error: unknown) {
|
|
3742
|
-
this.showError(`Logout failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3743
|
-
}
|
|
3744
|
-
}
|
|
3745
|
-
};
|
|
3746
|
-
handleAsync().catch(() => {
|
|
3747
|
-
// Swallow — showLoginDialog already handles its own errors.
|
|
3748
|
-
// This prevents unhandled rejections when login is cancelled.
|
|
3749
|
-
});
|
|
3750
|
-
},
|
|
3751
|
-
() => {
|
|
3752
|
-
done();
|
|
3753
|
-
this.ui.requestRender();
|
|
3754
|
-
},
|
|
3755
|
-
);
|
|
3756
|
-
return { component: selector, focus: selector };
|
|
3757
|
-
});
|
|
3758
|
-
}
|
|
3759
|
-
|
|
3760
|
-
private async showLoginDialog(providerId: string): Promise<void> {
|
|
3761
|
-
const providerInfo = this.session.modelRegistry.authStorage.getOAuthProviders().find((p) => p.id === providerId);
|
|
3762
|
-
const providerName = providerInfo?.name || providerId;
|
|
3763
|
-
|
|
3764
|
-
// Providers that use callback servers (can paste redirect URL)
|
|
3765
|
-
const usesCallbackServer = providerInfo?.usesCallbackServer ?? false;
|
|
3766
|
-
|
|
3767
|
-
// Create login dialog component
|
|
3768
|
-
const dialog = new LoginDialogComponent(this.ui, providerId, (_success, _message) => {
|
|
3769
|
-
// Completion handled below
|
|
3770
|
-
});
|
|
3771
|
-
|
|
3772
|
-
// Show dialog in editor container
|
|
3773
|
-
this.editorContainer.clear();
|
|
3774
|
-
this.editorContainer.addChild(dialog);
|
|
3775
|
-
this.ui.setFocus(dialog);
|
|
3776
|
-
this.ui.requestRender();
|
|
3777
|
-
|
|
3778
|
-
// Restore editor helper — also disposes the dialog to reject any
|
|
3779
|
-
// dangling promises and prevent the UI from getting stuck.
|
|
3780
|
-
const restoreEditor = (): void => {
|
|
3781
|
-
dialog.dispose();
|
|
3782
|
-
this.editorContainer.clear();
|
|
3783
|
-
this.editorContainer.addChild(this.editor);
|
|
3784
|
-
this.ui.setFocus(this.editor);
|
|
3785
|
-
this.ui.requestRender();
|
|
3786
|
-
};
|
|
3787
|
-
|
|
3788
|
-
try {
|
|
3789
|
-
await this.session.modelRegistry.authStorage.login(providerId as OAuthProviderId, {
|
|
3790
|
-
onAuth: (info: { url: string; instructions?: string }) => {
|
|
3791
|
-
dialog.showAuth(info.url, info.instructions);
|
|
3792
|
-
|
|
3793
|
-
if (!usesCallbackServer && providerId === "github-copilot") {
|
|
3794
|
-
// GitHub Copilot polls after onAuth
|
|
3795
|
-
dialog.showWaiting("Waiting for browser authentication...");
|
|
3796
|
-
}
|
|
3797
|
-
// For Anthropic: onPrompt is called immediately after
|
|
3798
|
-
},
|
|
3799
|
-
|
|
3800
|
-
onPrompt: async (prompt: { message: string; placeholder?: string }) => {
|
|
3801
|
-
return dialog.showPrompt(prompt.message, prompt.placeholder);
|
|
3802
|
-
},
|
|
3803
|
-
|
|
3804
|
-
onProgress: (message: string) => {
|
|
3805
|
-
dialog.showProgress(message);
|
|
3806
|
-
},
|
|
3807
|
-
|
|
3808
|
-
// Callback-server providers race browser callback with pasted redirect URL.
|
|
3809
|
-
// Keep manual-input promise ownership inside provider flow to avoid
|
|
3810
|
-
// orphaned rejections when the callback is not consumed.
|
|
3811
|
-
onManualCodeInput: usesCallbackServer
|
|
3812
|
-
? () => dialog.showManualInput("Paste redirect URL below, or complete login in browser:")
|
|
3813
|
-
: undefined,
|
|
3814
|
-
|
|
3815
|
-
signal: dialog.signal,
|
|
3816
|
-
});
|
|
3817
|
-
|
|
3818
|
-
// Success
|
|
3819
|
-
restoreEditor();
|
|
3820
|
-
this.session.modelRegistry.refresh();
|
|
3821
|
-
await this.updateAvailableProviderCount();
|
|
3822
|
-
|
|
3823
|
-
// Auto-switch model if current model has no valid API key
|
|
3824
|
-
try {
|
|
3825
|
-
const currentModel = this.session.model;
|
|
3826
|
-
if (currentModel) {
|
|
3827
|
-
const currentKey = await (this.session.modelRegistry as unknown as GSDModelRegistry).getApiKeyForProvider?.(currentModel.provider);
|
|
3828
|
-
if (!currentKey) {
|
|
3829
|
-
const available = this.session.modelRegistry.getAvailable();
|
|
3830
|
-
const newProviderModel = available.find((m) => m.provider === providerId);
|
|
3831
|
-
if (newProviderModel) {
|
|
3832
|
-
await this.session.setModel(newProviderModel);
|
|
3833
|
-
} else if (available.length > 0) {
|
|
3834
|
-
await this.session.setModel(available[0]);
|
|
3835
|
-
}
|
|
3836
|
-
}
|
|
3837
|
-
}
|
|
3838
|
-
} catch (_error: unknown) {
|
|
3839
|
-
// Model switch failed — user can manually switch via /model
|
|
3840
|
-
}
|
|
3841
|
-
|
|
3842
|
-
this.showStatus(`Logged in to ${providerName}. Credentials saved to ${getAuthPath()}`);
|
|
3843
|
-
} catch (error: unknown) {
|
|
3844
|
-
restoreEditor();
|
|
3845
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
3846
|
-
if (errorMsg !== "Login cancelled" && !errorMsg.includes("Superseded") && !errorMsg.includes("disposed")) {
|
|
3847
|
-
this.showError(`Failed to login to ${providerName}: ${errorMsg}`);
|
|
3848
|
-
}
|
|
3849
|
-
}
|
|
3850
|
-
}
|
|
3851
|
-
|
|
3852
|
-
// =========================================================================
|
|
3853
|
-
// Command handlers
|
|
3854
|
-
// =========================================================================
|
|
3855
|
-
|
|
3856
|
-
private async handleReloadCommand(): Promise<void> {
|
|
3857
|
-
if (this.session.isStreaming) {
|
|
3858
|
-
this.showWarning("Wait for the current response to finish before reloading.");
|
|
3859
|
-
return;
|
|
3860
|
-
}
|
|
3861
|
-
if (this.session.isCompacting) {
|
|
3862
|
-
this.showWarning("Wait for compaction to finish before reloading.");
|
|
3863
|
-
return;
|
|
3864
|
-
}
|
|
3865
|
-
|
|
3866
|
-
this.resetExtensionUI();
|
|
3867
|
-
|
|
3868
|
-
const loader = new BorderedLoader(this.ui, theme, "Reloading extensions, skills, prompts, themes...", {
|
|
3869
|
-
cancellable: false,
|
|
3870
|
-
});
|
|
3871
|
-
const previousEditor = this.editor;
|
|
3872
|
-
this.editorContainer.clear();
|
|
3873
|
-
this.editorContainer.addChild(loader);
|
|
3874
|
-
this.ui.setFocus(loader);
|
|
3875
|
-
this.ui.requestRender();
|
|
3876
|
-
|
|
3877
|
-
const dismissLoader = (editor: Component): void => {
|
|
3878
|
-
loader.dispose();
|
|
3879
|
-
this.editorContainer.clear();
|
|
3880
|
-
this.editorContainer.addChild(editor);
|
|
3881
|
-
this.ui.setFocus(editor);
|
|
3882
|
-
this.ui.requestRender();
|
|
3883
|
-
};
|
|
3884
|
-
|
|
3885
|
-
try {
|
|
3886
|
-
await this.session.reload();
|
|
3887
|
-
/* vendor-seam: dual-module-path — Theme resolves differently through ResourceLoader vs setRegisteredThemes import path */
|
|
3888
|
-
setRegisteredThemes(this.session.resourceLoader.getThemes().themes as unknown as Parameters<typeof setRegisteredThemes>[0]);
|
|
3889
|
-
this.hideThinkingBlock = this.settingsManager.getHideThinkingBlock();
|
|
3890
|
-
const themeName = this.settingsManager.getTheme();
|
|
3891
|
-
const themeResult = themeName ? setTheme(themeName, true) : { success: true };
|
|
3892
|
-
if (!themeResult.success) {
|
|
3893
|
-
this.showError(`Failed to load theme "${themeName}": ${themeResult.error}\nFell back to dark theme.`);
|
|
3894
|
-
}
|
|
3895
|
-
const editorPaddingX = this.settingsManager.getEditorPaddingX();
|
|
3896
|
-
const autocompleteMaxVisible = this.settingsManager.getAutocompleteMaxVisible();
|
|
3897
|
-
this.defaultEditor.setPaddingX(editorPaddingX);
|
|
3898
|
-
this.defaultEditor.setAutocompleteMaxVisible(autocompleteMaxVisible);
|
|
3899
|
-
if (this.editor !== this.defaultEditor) {
|
|
3900
|
-
this.editor.setPaddingX?.(editorPaddingX);
|
|
3901
|
-
this.editor.setAutocompleteMaxVisible?.(autocompleteMaxVisible);
|
|
3902
|
-
}
|
|
3903
|
-
this.ui.setShowHardwareCursor(this.settingsManager.getShowHardwareCursor());
|
|
3904
|
-
this.ui.setClearOnShrink(this.settingsManager.getClearOnShrink());
|
|
3905
|
-
this.setupAutocomplete();
|
|
3906
|
-
const runner = this.session.extensionRunner;
|
|
3907
|
-
if (runner) {
|
|
3908
|
-
this.setupExtensionShortcuts(runner);
|
|
3909
|
-
}
|
|
3910
|
-
this.rebuildChatFromMessages();
|
|
3911
|
-
dismissLoader(this.editor as Component);
|
|
3912
|
-
this.showLoadedResources({
|
|
3913
|
-
extensionPaths: runner?.getExtensionPaths() ?? [],
|
|
3914
|
-
force: false,
|
|
3915
|
-
showDiagnosticsWhenQuiet: true,
|
|
3916
|
-
});
|
|
3917
|
-
const modelsJsonError = this.session.modelRegistry.getError();
|
|
3918
|
-
if (modelsJsonError) {
|
|
3919
|
-
this.showError(`models.json error: ${modelsJsonError}`);
|
|
3920
|
-
}
|
|
3921
|
-
this.showStatus("Reloaded extensions, skills, prompts, themes");
|
|
3922
|
-
} catch (error) {
|
|
3923
|
-
dismissLoader(previousEditor as Component);
|
|
3924
|
-
this.showError(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
3925
|
-
}
|
|
3926
|
-
}
|
|
3927
|
-
|
|
3928
|
-
private async handleClearCommand(): Promise<void> {
|
|
3929
|
-
// Stop loading animation
|
|
3930
|
-
if (this.loadingAnimation) {
|
|
3931
|
-
this.loadingAnimation.stop();
|
|
3932
|
-
this.loadingAnimation = undefined;
|
|
3933
|
-
}
|
|
3934
|
-
this.statusContainer.clear();
|
|
3935
|
-
|
|
3936
|
-
// New session via session (emits extension session events)
|
|
3937
|
-
await this.session.newSession();
|
|
3938
|
-
|
|
3939
|
-
// Clear UI state
|
|
3940
|
-
this.headerContainer.clear();
|
|
3941
|
-
this.chatContainer.clear();
|
|
3942
|
-
this.pendingMessagesContainer.clear();
|
|
3943
|
-
this.compactionQueuedMessages = [];
|
|
3944
|
-
this.streamingComponent = undefined;
|
|
3945
|
-
this.streamingMessage = undefined;
|
|
3946
|
-
this.pendingTools.clear();
|
|
3947
|
-
|
|
3948
|
-
// Reset contextual tips for the new session
|
|
3949
|
-
this.contextualTips.reset();
|
|
3950
|
-
|
|
3951
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
3952
|
-
this.chatContainer.addChild(new Text(`${theme.fg("accent", "✓ New session started")}`, 1, 1));
|
|
3953
|
-
this.ui.requestRender();
|
|
3954
|
-
}
|
|
3955
|
-
|
|
3956
|
-
private handleDebugCommand(): void {
|
|
3957
|
-
const width = this.ui.terminal.columns;
|
|
3958
|
-
const height = this.ui.terminal.rows;
|
|
3959
|
-
const allLines = this.ui.render(width);
|
|
3960
|
-
|
|
3961
|
-
const debugLogPath = getDebugLogPath();
|
|
3962
|
-
const debugData = [
|
|
3963
|
-
`Debug output at ${new Date().toISOString()}`,
|
|
3964
|
-
`Terminal: ${width}x${height}`,
|
|
3965
|
-
`Total lines: ${allLines.length}`,
|
|
3966
|
-
"",
|
|
3967
|
-
"=== All rendered lines with visible widths ===",
|
|
3968
|
-
...allLines.map((line, idx) => {
|
|
3969
|
-
const vw = visibleWidth(line);
|
|
3970
|
-
const escaped = JSON.stringify(line);
|
|
3971
|
-
return `[${idx}] (w=${vw}) ${escaped}`;
|
|
3972
|
-
}),
|
|
3973
|
-
"",
|
|
3974
|
-
"=== Agent messages (JSONL) ===",
|
|
3975
|
-
...this.session.messages.map((msg) => JSON.stringify(msg)),
|
|
3976
|
-
"",
|
|
3977
|
-
].join("\n");
|
|
3978
|
-
|
|
3979
|
-
fs.mkdirSync(path.dirname(debugLogPath), { recursive: true });
|
|
3980
|
-
fs.writeFileSync(debugLogPath, debugData);
|
|
3981
|
-
|
|
3982
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
3983
|
-
this.chatContainer.addChild(
|
|
3984
|
-
new Text(`${theme.fg("accent", "✓ Debug log written")}\n${theme.fg("muted", debugLogPath)}`, 1, 1),
|
|
3985
|
-
);
|
|
3986
|
-
this.ui.requestRender();
|
|
3987
|
-
}
|
|
3988
|
-
|
|
3989
|
-
private handleDaxnuts(): void {
|
|
3990
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
3991
|
-
this.chatContainer.addChild(new DaxnutsComponent(this.ui));
|
|
3992
|
-
this.ui.requestRender();
|
|
3993
|
-
}
|
|
3994
|
-
|
|
3995
|
-
private checkDaxnutsEasterEgg(model: { provider: string; id: string }): void {
|
|
3996
|
-
if (model.provider === "opencode" && model.id.toLowerCase().includes("kimi-k2.5")) {
|
|
3997
|
-
this.handleDaxnuts();
|
|
3998
|
-
}
|
|
3999
|
-
}
|
|
4000
|
-
|
|
4001
|
-
private async handleBashCommand(command: string, excludeFromContext = false, displayCommand?: string, loginShell?: boolean): Promise<void> {
|
|
4002
|
-
const extensionRunner = this.session.extensionRunner;
|
|
4003
|
-
const label = displayCommand || command;
|
|
4004
|
-
|
|
4005
|
-
// Emit user_bash event to let extensions intercept
|
|
4006
|
-
const eventResult = extensionRunner
|
|
4007
|
-
? await extensionRunner.emitUserBash({
|
|
4008
|
-
type: "user_bash",
|
|
4009
|
-
command,
|
|
4010
|
-
excludeFromContext,
|
|
4011
|
-
cwd: process.cwd(),
|
|
4012
|
-
})
|
|
4013
|
-
: undefined;
|
|
4014
|
-
|
|
4015
|
-
// If extension returned a full result, use it directly
|
|
4016
|
-
if (eventResult?.result) {
|
|
4017
|
-
const result = eventResult.result;
|
|
4018
|
-
|
|
4019
|
-
// Create UI component for display
|
|
4020
|
-
this.bashComponent = new BashExecutionComponent(label, this.ui, excludeFromContext);
|
|
4021
|
-
if (this.session.isStreaming) {
|
|
4022
|
-
this.pendingMessagesContainer.addChild(this.bashComponent);
|
|
4023
|
-
this.pendingBashComponents.push(this.bashComponent);
|
|
4024
|
-
} else {
|
|
4025
|
-
this.chatContainer.addChild(this.bashComponent);
|
|
4026
|
-
}
|
|
4027
|
-
|
|
4028
|
-
// Show output and complete
|
|
4029
|
-
if (result.output) {
|
|
4030
|
-
this.bashComponent.appendOutput(result.output);
|
|
4031
|
-
}
|
|
4032
|
-
this.bashComponent.setComplete(
|
|
4033
|
-
result.exitCode,
|
|
4034
|
-
result.cancelled,
|
|
4035
|
-
result.truncated ? ({ truncated: true, content: result.output } as TruncationResult) : undefined,
|
|
4036
|
-
result.fullOutputPath,
|
|
4037
|
-
);
|
|
4038
|
-
|
|
4039
|
-
// Record the result in session
|
|
4040
|
-
this.session.recordBashResult(command, result, { excludeFromContext });
|
|
4041
|
-
this.bashComponent = undefined;
|
|
4042
|
-
this.ui.requestRender();
|
|
4043
|
-
return;
|
|
4044
|
-
}
|
|
4045
|
-
|
|
4046
|
-
// Normal execution path (possibly with custom operations)
|
|
4047
|
-
const isDeferred = this.session.isStreaming;
|
|
4048
|
-
this.bashComponent = new BashExecutionComponent(label, this.ui, excludeFromContext);
|
|
4049
|
-
|
|
4050
|
-
if (isDeferred) {
|
|
4051
|
-
// Show in pending area when agent is streaming
|
|
4052
|
-
this.pendingMessagesContainer.addChild(this.bashComponent);
|
|
4053
|
-
this.pendingBashComponents.push(this.bashComponent);
|
|
4054
|
-
} else {
|
|
4055
|
-
// Show in chat immediately when agent is idle
|
|
4056
|
-
this.chatContainer.addChild(this.bashComponent);
|
|
4057
|
-
}
|
|
4058
|
-
this.ui.requestRender();
|
|
4059
|
-
|
|
4060
|
-
try {
|
|
4061
|
-
const result = await this.session.executeBash(
|
|
4062
|
-
command,
|
|
4063
|
-
(chunk) => {
|
|
4064
|
-
if (this.bashComponent) {
|
|
4065
|
-
this.bashComponent.appendOutput(chunk);
|
|
4066
|
-
this.ui.requestRender();
|
|
4067
|
-
}
|
|
4068
|
-
},
|
|
4069
|
-
{ excludeFromContext, operations: eventResult?.operations, loginShell },
|
|
4070
|
-
);
|
|
4071
|
-
|
|
4072
|
-
if (this.bashComponent) {
|
|
4073
|
-
this.bashComponent.setComplete(
|
|
4074
|
-
result.exitCode,
|
|
4075
|
-
result.cancelled,
|
|
4076
|
-
result.truncated ? ({ truncated: true, content: result.output } as TruncationResult) : undefined,
|
|
4077
|
-
result.fullOutputPath,
|
|
4078
|
-
);
|
|
4079
|
-
}
|
|
4080
|
-
} catch (error) {
|
|
4081
|
-
if (this.bashComponent) {
|
|
4082
|
-
this.bashComponent.setComplete(undefined, false);
|
|
4083
|
-
}
|
|
4084
|
-
this.showError(`Bash command failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
4085
|
-
}
|
|
4086
|
-
|
|
4087
|
-
this.bashComponent = undefined;
|
|
4088
|
-
this.ui.requestRender();
|
|
4089
|
-
}
|
|
4090
|
-
|
|
4091
|
-
private async executeCompaction(customInstructions?: string, isAuto = false): Promise<CompactionResult | undefined> {
|
|
4092
|
-
// Stop loading animation
|
|
4093
|
-
if (this.loadingAnimation) {
|
|
4094
|
-
this.loadingAnimation.stop();
|
|
4095
|
-
this.loadingAnimation = undefined;
|
|
4096
|
-
}
|
|
4097
|
-
this.statusContainer.clear();
|
|
4098
|
-
|
|
4099
|
-
// Set up escape handler during compaction
|
|
4100
|
-
const originalOnEscape = this.defaultEditor.onEscape;
|
|
4101
|
-
this.defaultEditor.onEscape = () => {
|
|
4102
|
-
this.session.abortCompaction();
|
|
4103
|
-
};
|
|
4104
|
-
|
|
4105
|
-
// Show compacting status
|
|
4106
|
-
this.chatContainer.addChild(new Spacer(1));
|
|
4107
|
-
const cancelHint = `(${appKey(this.keybindings, "interrupt")} to cancel)`;
|
|
4108
|
-
const label = isAuto ? `Auto-compacting context... ${cancelHint}` : `Compacting context... ${cancelHint}`;
|
|
4109
|
-
const compactingLoader = new Loader(
|
|
4110
|
-
this.ui,
|
|
4111
|
-
(spinner) => theme.fg("accent", spinner),
|
|
4112
|
-
(text) => theme.fg("muted", text),
|
|
4113
|
-
label,
|
|
4114
|
-
);
|
|
4115
|
-
this.statusContainer.addChild(compactingLoader);
|
|
4116
|
-
this.ui.requestRender();
|
|
4117
|
-
|
|
4118
|
-
let result: CompactionResult | undefined;
|
|
4119
|
-
|
|
4120
|
-
try {
|
|
4121
|
-
result = await this.session.compact(customInstructions);
|
|
4122
|
-
|
|
4123
|
-
// Rebuild UI
|
|
4124
|
-
this.rebuildChatFromMessages();
|
|
4125
|
-
|
|
4126
|
-
// Add compaction component at bottom so user sees it without scrolling
|
|
4127
|
-
const msg = createCompactionSummaryMessage(result.summary, result.tokensBefore, new Date().toISOString());
|
|
4128
|
-
this.addMessageToChat(msg);
|
|
4129
|
-
|
|
4130
|
-
this.footer.invalidate();
|
|
4131
|
-
} catch (error) {
|
|
4132
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
4133
|
-
if (message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError")) {
|
|
4134
|
-
this.showError("Compaction cancelled");
|
|
4135
|
-
} else {
|
|
4136
|
-
this.showError(`Compaction failed: ${message}`);
|
|
4137
|
-
}
|
|
4138
|
-
} finally {
|
|
4139
|
-
compactingLoader.stop();
|
|
4140
|
-
this.statusContainer.clear();
|
|
4141
|
-
this.defaultEditor.onEscape = originalOnEscape;
|
|
4142
|
-
}
|
|
4143
|
-
void this.flushCompactionQueue({ willRetry: false });
|
|
4144
|
-
return result;
|
|
4145
|
-
}
|
|
4146
|
-
|
|
4147
|
-
requestRender(force = false): void {
|
|
4148
|
-
if (!this.isInitialized) return;
|
|
4149
|
-
this.ui.requestRender(force);
|
|
4150
|
-
}
|
|
4151
|
-
|
|
4152
|
-
stop(): void {
|
|
4153
|
-
if (this.loadingAnimation) {
|
|
4154
|
-
this.loadingAnimation.stop();
|
|
4155
|
-
this.loadingAnimation = undefined;
|
|
4156
|
-
}
|
|
4157
|
-
this.clearExtensionTerminalInputListeners();
|
|
4158
|
-
|
|
4159
|
-
// Clean up branch change listener (Fix 1)
|
|
4160
|
-
this._branchChangeUnsub?.();
|
|
4161
|
-
this._branchChangeUnsub = undefined;
|
|
4162
|
-
|
|
4163
|
-
// Clean up theme change listener and watcher (Fix 2)
|
|
4164
|
-
onThemeChange(() => {});
|
|
4165
|
-
stopThemeWatcher();
|
|
4166
|
-
|
|
4167
|
-
// Resolve any pending getUserInput promise so the run() loop can exit (Fix 3)
|
|
4168
|
-
if (this.onInputCallback) {
|
|
4169
|
-
this.onInputCallback("");
|
|
4170
|
-
this.onInputCallback = undefined;
|
|
4171
|
-
}
|
|
4172
|
-
|
|
4173
|
-
// Dispose extension widgets, custom footer, and custom header (Fix 4)
|
|
4174
|
-
this.clearExtensionWidgets();
|
|
4175
|
-
if (this.customFooter?.dispose) {
|
|
4176
|
-
this.customFooter.dispose();
|
|
4177
|
-
}
|
|
4178
|
-
this.customFooter = undefined;
|
|
4179
|
-
if (this.customHeader?.dispose) {
|
|
4180
|
-
this.customHeader.dispose();
|
|
4181
|
-
}
|
|
4182
|
-
this.customHeader = undefined;
|
|
4183
|
-
this.autocompleteProvider = undefined;
|
|
4184
|
-
|
|
4185
|
-
this.footer.dispose();
|
|
4186
|
-
this.footerDataProvider.dispose();
|
|
4187
|
-
if (this.unsubscribe) {
|
|
4188
|
-
this.unsubscribe();
|
|
4189
|
-
}
|
|
4190
|
-
if (this.isInitialized) {
|
|
4191
|
-
this.ui.stop();
|
|
4192
|
-
this.isInitialized = false;
|
|
4193
|
-
}
|
|
4194
|
-
}
|
|
4195
|
-
}
|