Skip to content

Commit ce95d0f

Browse files
committed
feat: improve PowerShell terminal command completion detection
- Add PowerShellPromptDetector module for enhanced prompt pattern detection - Add CompletionMarkers module for explicit START/END command markers - Integrate both detection methods into TerminalProcess - Add configuration options for users to enable/disable features - Add comprehensive tests for new functionality This addresses timing issues with PowerShell terminal command completion detection by providing two complementary approaches: 1. Enhanced prompt detection that recognizes various PowerShell prompts 2. Explicit completion markers that wrap commands with START/END markers Fixes #8446
1 parent 13534cc commit ce95d0f

File tree

11 files changed

+1278
-14
lines changed

11 files changed

+1278
-14
lines changed

packages/types/src/global-settings.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export const globalSettingsSchema = z.object({
121121
terminalZshP10k: z.boolean().optional(),
122122
terminalZdotdir: z.boolean().optional(),
123123
terminalCompressProgressBar: z.boolean().optional(),
124+
terminalCompletionMarkersEnabled: z.boolean().optional(),
125+
terminalPromptDetectionEnabled: z.boolean().optional(),
126+
terminalCustomPromptPatterns: z.string().optional(),
124127

125128
diagnosticsEnabled: z.boolean().optional(),
126129

@@ -294,6 +297,9 @@ export const EVALS_SETTINGS: RooCodeSettings = {
294297
terminalZdotdir: true,
295298
terminalCompressProgressBar: true,
296299
terminalShellIntegrationDisabled: true,
300+
terminalCompletionMarkersEnabled: false,
301+
terminalPromptDetectionEnabled: false,
302+
terminalCustomPromptPatterns: "",
297303

298304
diagnosticsEnabled: true,
299305

src/core/webview/ClineProvider.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ export class ClineProvider
738738
terminalZshP10k = false,
739739
terminalPowershellCounter = false,
740740
terminalZdotdir = false,
741+
terminalCompletionMarkersEnabled = false,
742+
terminalPromptDetectionEnabled = false,
743+
terminalCustomPromptPatterns = "",
741744
}) => {
742745
Terminal.setShellIntegrationTimeout(terminalShellIntegrationTimeout)
743746
Terminal.setShellIntegrationDisabled(terminalShellIntegrationDisabled)
@@ -747,6 +750,9 @@ export class ClineProvider
747750
Terminal.setTerminalZshP10k(terminalZshP10k)
748751
Terminal.setPowershellCounter(terminalPowershellCounter)
749752
Terminal.setTerminalZdotdir(terminalZdotdir)
753+
Terminal.setCompletionMarkersEnabled(terminalCompletionMarkersEnabled)
754+
Terminal.setPromptDetectionEnabled(terminalPromptDetectionEnabled)
755+
Terminal.setCustomPromptPatterns(terminalCustomPromptPatterns)
750756
},
751757
)
752758

@@ -1766,6 +1772,9 @@ export class ClineProvider
17661772
terminalZshOhMy,
17671773
terminalZshP10k,
17681774
terminalZdotdir,
1775+
terminalCompletionMarkersEnabled,
1776+
terminalPromptDetectionEnabled,
1777+
terminalCustomPromptPatterns,
17691778
fuzzyMatchThreshold,
17701779
mcpEnabled,
17711780
enableMcpServerCreation,
@@ -1892,6 +1901,9 @@ export class ClineProvider
18921901
terminalZshOhMy: terminalZshOhMy ?? false,
18931902
terminalZshP10k: terminalZshP10k ?? false,
18941903
terminalZdotdir: terminalZdotdir ?? false,
1904+
terminalCompletionMarkersEnabled: terminalCompletionMarkersEnabled ?? false,
1905+
terminalPromptDetectionEnabled: terminalPromptDetectionEnabled ?? false,
1906+
terminalCustomPromptPatterns: terminalCustomPromptPatterns ?? "",
18951907
fuzzyMatchThreshold: fuzzyMatchThreshold ?? 1.0,
18961908
mcpEnabled: mcpEnabled ?? true,
18971909
enableMcpServerCreation: enableMcpServerCreation ?? true,
@@ -2113,6 +2125,9 @@ export class ClineProvider
21132125
terminalZshOhMy: stateValues.terminalZshOhMy ?? false,
21142126
terminalZshP10k: stateValues.terminalZshP10k ?? false,
21152127
terminalZdotdir: stateValues.terminalZdotdir ?? false,
2128+
terminalCompletionMarkersEnabled: stateValues.terminalCompletionMarkersEnabled ?? false,
2129+
terminalPromptDetectionEnabled: stateValues.terminalPromptDetectionEnabled ?? false,
2130+
terminalCustomPromptPatterns: stateValues.terminalCustomPromptPatterns ?? "",
21162131
terminalCompressProgressBar: stateValues.terminalCompressProgressBar ?? true,
21172132
mode: stateValues.mode ?? defaultModeSlug,
21182133
language: stateValues.language ?? formatLanguage(vscode.env.language),

src/core/webview/webviewMessageHandler.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,27 @@ export const webviewMessageHandler = async (
14611461
Terminal.setCompressProgressBar(message.bool)
14621462
}
14631463
break
1464+
case "terminalCompletionMarkersEnabled":
1465+
await updateGlobalState("terminalCompletionMarkersEnabled", message.bool)
1466+
await provider.postStateToWebview()
1467+
if (message.bool !== undefined) {
1468+
Terminal.setCompletionMarkersEnabled(message.bool)
1469+
}
1470+
break
1471+
case "terminalPromptDetectionEnabled":
1472+
await updateGlobalState("terminalPromptDetectionEnabled", message.bool)
1473+
await provider.postStateToWebview()
1474+
if (message.bool !== undefined) {
1475+
Terminal.setPromptDetectionEnabled(message.bool)
1476+
}
1477+
break
1478+
case "terminalCustomPromptPatterns":
1479+
await updateGlobalState("terminalCustomPromptPatterns", message.text)
1480+
await provider.postStateToWebview()
1481+
if (message.text !== undefined) {
1482+
Terminal.setCustomPromptPatterns(message.text)
1483+
}
1484+
break
14641485
case "mode":
14651486
await provider.handleModeSwitch(message.text as Mode)
14661487
break

src/integrations/terminal/BaseTerminal.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ export abstract class BaseTerminal implements RooTerminal {
160160
private static terminalZshP10k: boolean = false
161161
private static terminalZdotdir: boolean = false
162162
private static compressProgressBar: boolean = true
163+
private static completionMarkersEnabled: boolean = false
164+
private static promptDetectionEnabled: boolean = false
165+
private static customPromptPatterns: string = ""
163166

164167
/**
165168
* Compresses terminal output by applying run-length encoding and truncating to line limit
@@ -314,4 +317,52 @@ export abstract class BaseTerminal implements RooTerminal {
314317
public static getCompressProgressBar(): boolean {
315318
return BaseTerminal.compressProgressBar
316319
}
320+
321+
/**
322+
* Sets whether to use completion markers for command detection
323+
* @param enabled Whether to enable completion markers
324+
*/
325+
public static setCompletionMarkersEnabled(enabled: boolean): void {
326+
BaseTerminal.completionMarkersEnabled = enabled
327+
}
328+
329+
/**
330+
* Gets whether completion markers are enabled
331+
* @returns Whether completion markers are enabled
332+
*/
333+
public static getCompletionMarkersEnabled(): boolean {
334+
return BaseTerminal.completionMarkersEnabled
335+
}
336+
337+
/**
338+
* Sets whether to use prompt detection for command completion
339+
* @param enabled Whether to enable prompt detection
340+
*/
341+
public static setPromptDetectionEnabled(enabled: boolean): void {
342+
BaseTerminal.promptDetectionEnabled = enabled
343+
}
344+
345+
/**
346+
* Gets whether prompt detection is enabled
347+
* @returns Whether prompt detection is enabled
348+
*/
349+
public static getPromptDetectionEnabled(): boolean {
350+
return BaseTerminal.promptDetectionEnabled
351+
}
352+
353+
/**
354+
* Sets custom prompt patterns for detection
355+
* @param patterns Custom prompt patterns (pipe-separated regex strings)
356+
*/
357+
public static setCustomPromptPatterns(patterns: string): void {
358+
BaseTerminal.customPromptPatterns = patterns
359+
}
360+
361+
/**
362+
* Gets custom prompt patterns
363+
* @returns Custom prompt patterns string
364+
*/
365+
public static getCustomPromptPatterns(): string {
366+
return BaseTerminal.customPromptPatterns
367+
}
317368
}

0 commit comments

Comments
 (0)