* 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
124 lines
3.4 KiB
TypeScript
124 lines
3.4 KiB
TypeScript
/**
|
|
* StandaloneTerminal - A terminal wrapper for standalone environments.
|
|
*
|
|
* This class provides a terminal abstraction that works outside of VSCode,
|
|
* implementing the ITerminal interface for compatibility with the terminal manager.
|
|
*/
|
|
|
|
import type { ChildProcess } from "child_process"
|
|
|
|
import type { ITerminal, StandaloneTerminalOptions } from "./types"
|
|
|
|
/**
|
|
* A standalone terminal implementation that doesn't depend on VSCode.
|
|
* Used in CLI and JetBrains environments.
|
|
*/
|
|
export class StandaloneTerminal implements ITerminal {
|
|
/** Terminal name */
|
|
name: string
|
|
|
|
/** Promise that resolves to the process ID */
|
|
processId: Promise<number | undefined>
|
|
|
|
/** Terminal creation options */
|
|
creationOptions: StandaloneTerminalOptions
|
|
|
|
/** Exit status (if terminal has exited) */
|
|
exitStatus: { code: number } | undefined
|
|
|
|
/** Terminal state */
|
|
state: { isInteractedWith: boolean }
|
|
|
|
/** Current working directory */
|
|
_cwd: string
|
|
|
|
/** Shell path */
|
|
_shellPath: string | undefined
|
|
|
|
/** Active child process */
|
|
_process: ChildProcess | null = null
|
|
|
|
/** Process ID of the active process */
|
|
_processId: number | null = null
|
|
|
|
/** Mock shell integration for compatibility */
|
|
shellIntegration: {
|
|
cwd: { fsPath: string }
|
|
executeCommand: (command: string) => {
|
|
read: () => AsyncGenerator<string, void, unknown>
|
|
}
|
|
}
|
|
|
|
constructor(options: StandaloneTerminalOptions = {}) {
|
|
this.name = options.name || `Terminal ${Math.floor(Math.random() * 10000)}`
|
|
this.processId = Promise.resolve(Math.floor(Math.random() * 100000))
|
|
this.creationOptions = options
|
|
this.exitStatus = undefined
|
|
this.state = { isInteractedWith: false }
|
|
this._cwd = options.cwd || process.cwd()
|
|
this._shellPath = options.shellPath
|
|
|
|
// Mock shell integration for compatibility
|
|
this.shellIntegration = {
|
|
cwd: { fsPath: this._cwd },
|
|
executeCommand: (_command: string) => {
|
|
// Return a mock execution object that the TerminalProcess expects
|
|
return {
|
|
read: async function* (): AsyncGenerator<string, void, unknown> {
|
|
// This will be handled by our StandaloneTerminalProcess
|
|
yield ""
|
|
},
|
|
}
|
|
},
|
|
}
|
|
|
|
console.log(`[StandaloneTerminal] Created terminal: ${this.name} in ${this._cwd}`)
|
|
}
|
|
|
|
/**
|
|
* Send text to the terminal.
|
|
* @param text The text to send
|
|
* @param addNewLine Whether to add a newline (default: true)
|
|
*/
|
|
sendText(text: string, addNewLine: boolean = true): void {
|
|
console.log(`[StandaloneTerminal] sendText: ${text}`)
|
|
|
|
// If we have an active process, send input to it
|
|
if (this._process && !this._process.killed) {
|
|
try {
|
|
this._process.stdin?.write(text + (addNewLine ? "\n" : ""))
|
|
} catch (error) {
|
|
console.error(`[StandaloneTerminal] Error sending text to process:`, error)
|
|
}
|
|
} else {
|
|
// For compatibility with old behavior, we could spawn a new process
|
|
console.log(`[StandaloneTerminal] No active process to send text to`)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Show the terminal (no-op in standalone mode).
|
|
*/
|
|
show(): void {
|
|
console.log(`[StandaloneTerminal] show: ${this.name}`)
|
|
this.state.isInteractedWith = true
|
|
}
|
|
|
|
/**
|
|
* Hide the terminal (no-op in standalone mode).
|
|
*/
|
|
hide(): void {
|
|
console.log(`[StandaloneTerminal] hide: ${this.name}`)
|
|
}
|
|
|
|
/**
|
|
* Dispose of the terminal and kill any running process.
|
|
*/
|
|
dispose(): void {
|
|
console.log(`[StandaloneTerminal] dispose: ${this.name}`)
|
|
if (this._process && !this._process.killed) {
|
|
this._process.kill("SIGTERM")
|
|
}
|
|
}
|
|
}
|