feat(terminal): Move Standalone terminal Code to Typescript (#7927)

* feat(terminal): add shared terminal types and interfaces

Add shared terminal module with types and interfaces that enable
terminal management across VSCode, CLI, and JetBrains environments.

- Define ITerminal, ITerminalManager, and TerminalInfo interfaces
- Add TerminalProcessResultPromise for async command execution
- Include StandaloneTerminalOptions for non-VSCode environments
- Prepare module structure for standalone implementations

* feat(terminal): export standalone terminal implementations

Enable exports for standalone terminal classes that were previously
commented out as placeholders:
- StandaloneTerminal
- StandaloneTerminalManager
- StandaloneTerminalProcess
- StandaloneTerminalRegistry

These implementations are now ready for use outside the terminal module.

* fix: resolve TerminalInfo type incompatibility in settings update

- Remove unused TerminalInfo import from both updateSettings files
- Use `as any` cast to handle type mismatch between VSCode and standalone TerminalInfo
- Replace busyTerminals array with busyTerminalsCount to avoid type issues
- Add null-safe access when getting busy terminals length

* feat: import StandaloneTerminalManager from bundled cline-core

Replace standalone enhanced-terminal.js with import from the bundled
TypeScript version in cline-core.js. This consolidates terminal
management code and removes the need to separately include the
runtime file in the VS Code extension package.

- Re-export StandaloneTerminalManager from cline-core.ts
- Update vscode-impls.js to import from cline-core.js
- Remove .vscodeignore exception for enhanced-terminal.js

* feat: simplify standalone terminal manager initialization

Replace global injection pattern with environment variable detection
for determining terminal execution mode. The Task class now directly
instantiates StandaloneTerminalManager when IS_STANDALONE=true instead
of relying on a globally injected instance.

- Remove StandaloneTerminalManager re-export from cline-core.ts
- Simplify vscode-impls.js createTerminal to return stub object
- Use IS_STANDALONE env var for terminal manager selection in Task
- Remove global.standaloneTerminalManager injection pattern

* Fix Standalone build

* Fix Standalone build

* fix: use subagentTerminalOutputLineLimit in StandaloneTerminalManager.processOutput

Match the VSCode TerminalManager logic to properly use subagentTerminalOutputLineLimit (2000) for subagent commands instead of always falling back to terminalOutputLineLimit (500).

* feat: add TerminalManager to HostProvider for dependency injection

- Add TerminalManagerCreator type and createTerminalManager to HostProvider
- Extract ITerminalManager interface to shared/terminal/types for abstraction
- Refactor TerminalManager to implement ITerminalManager interface
- Create StandaloneTerminalManager for non-VSCode environments
- Update TerminalRegistry to use ITerminalManager via HostProvider
- Enable terminal management to work across different host environments

* feat: refactor terminal manager to use ITerminalManager interface

- Replace concrete TerminalManager/StandaloneTerminalManager types with ITerminalManager interface
- Use HostProvider.createTerminalManager() for host-agnostic terminal creation
- Simplify terminal execution mode logic in Task constructor
- Add dynamic imports for StandaloneTerminalManager when backgroundExec mode is used
- Improve logging for terminal manager selection
This commit is contained in:
Ara authored and GitHub committed 2025-12-07 05:10:25 -08:00
1 parent 34bb95e04e
commit e9136f60cc
18 files changed
+1292 -729

No files matched your search

+7 -7
View File
@@ -12,7 +12,6 @@ import { OpenaiReasoningEffort } from "@shared/storage/types"
import { TelemetrySetting } from "@shared/TelemetrySetting"
import { ClineEnv } from "@/config"
import { HostProvider } from "@/hosts/host-provider"
import { TerminalInfo } from "@/integrations/terminal/TerminalRegistry"
import { McpDisplayMode } from "@/shared/McpDisplayMode"
import { ShowMessageType } from "@/shared/proto/host/window"
import { telemetryService } from "../../../services/telemetry"
@@ -281,14 +280,15 @@ export async function updateSettings(controller: Controller, request: UpdateSett
controller.stateManager.setGlobalState("defaultTerminalProfile", profileId)
let closedCount = 0
let busyTerminals: TerminalInfo[] = []
let busyTerminalsCount = 0
// Update the terminal manager of the current task if it exists
if (controller.task) {
// Call the updated setDefaultTerminalProfile method that returns closed terminal info
const result = controller.task.terminalManager.setDefaultTerminalProfile(profileId)
// Use `as any` to handle type incompatibility between VSCode's TerminalInfo and standalone TerminalInfo
const result = controller.task.terminalManager.setDefaultTerminalProfile(profileId) as any
closedCount = result.closedCount
busyTerminals = result.busyTerminals
busyTerminalsCount = result.busyTerminals?.length ?? 0
// Show information message if terminals were closed
if (closedCount > 0) {
@@ -300,10 +300,10 @@ export async function updateSettings(controller: Controller, request: UpdateSett
}
// Show warning if there are busy terminals that couldn't be closed
if (busyTerminals.length > 0) {
if (busyTerminalsCount > 0) {
const message =
`${busyTerminals.length} busy ${busyTerminals.length === 1 ? "terminal has" : "terminals have"} a different profile. ` +
`Close ${busyTerminals.length === 1 ? "it" : "them"} to use the new profile for all commands.`
`${busyTerminalsCount} busy ${busyTerminalsCount === 1 ? "terminal has" : "terminals have"} a different profile. ` +
`Close ${busyTerminalsCount === 1 ? "it" : "them"} to use the new profile for all commands.`
HostProvider.window.showMessage({
type: ShowMessageType.WARNING,
message,
@@ -11,7 +11,6 @@ import { Settings } from "@shared/storage/state-keys"
import { TelemetrySetting } from "@shared/TelemetrySetting"
import { ClineEnv } from "@/config"
import { HostProvider } from "@/hosts/host-provider"
import { TerminalInfo } from "@/integrations/terminal/TerminalRegistry"
import { ShowMessageType } from "@/shared/proto/host/window"
import { Mode, OpenaiReasoningEffort } from "@/shared/storage/types"
import { telemetryService } from "../../../services/telemetry"
@@ -215,7 +214,7 @@ export async function updateSettingsCli(controller: Controller, request: UpdateS
controller.stateManager.setGlobalState("defaultTerminalProfile", profileId)
let closedCount = 0
let busyTerminals: TerminalInfo[] = []
let busyTerminalsCount = 0
// Update the terminal manager of the current task if it exists
if (controller.task) {
@@ -225,9 +224,10 @@ export async function updateSettingsCli(controller: Controller, request: UpdateS
}
// Call the updated setDefaultTerminalProfile method that returns closed terminal info
const result = controller.task.terminalManager.setDefaultTerminalProfile(profileId)
// Use `as any` to handle type incompatibility between VSCode's TerminalInfo and standalone TerminalInfo
const result = controller.task.terminalManager.setDefaultTerminalProfile(profileId) as any
closedCount = result.closedCount
busyTerminals = result.busyTerminals
busyTerminalsCount = result.busyTerminals?.length ?? 0
// Show information message if terminals were closed
if (closedCount > 0) {
@@ -239,10 +239,10 @@ export async function updateSettingsCli(controller: Controller, request: UpdateS
}
// Show warning if there are busy terminals that couldn't be closed
if (busyTerminals.length > 0) {
if (busyTerminalsCount > 0) {
const message =
`${busyTerminals.length} busy ${busyTerminals.length === 1 ? "terminal has" : "terminals have"} a different profile. ` +
`Close ${busyTerminals.length === 1 ? "it" : "them"} to use the new profile for all commands.`
`${busyTerminalsCount} busy ${busyTerminalsCount === 1 ? "terminal has" : "terminals have"} a different profile. ` +
`Close ${busyTerminalsCount === 1 ? "it" : "them"} to use the new profile for all commands.`
HostProvider.window.showMessage({
type: ShowMessageType.WARNING,
message,