Skip to content

Commit 211e31b

Browse files
author
Eric Wheeler
committed
feat: add terminalPowershellCounter configuration option
Add a new configuration option that allows users to toggle the PowerShell counter workaround. This workaround adds a counter to PowerShell commands to ensure proper command execution and output capture. The setting is disabled by default, allowing users to enable it only when needed. Signed-off-by: Eric Wheeler <[email protected]>
1 parent 4d1cfe8 commit 211e31b

File tree

26 files changed

+122
-3
lines changed

26 files changed

+122
-3
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
11991199
terminalOutputLineLimit,
12001200
terminalShellIntegrationTimeout,
12011201
terminalCommandDelay,
1202+
terminalPowershellCounter,
12021203
fuzzyMatchThreshold,
12031204
mcpEnabled,
12041205
enableMcpServerCreation,
@@ -1267,6 +1268,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12671268
terminalOutputLineLimit: terminalOutputLineLimit ?? 500,
12681269
terminalShellIntegrationTimeout: terminalShellIntegrationTimeout ?? TERMINAL_SHELL_INTEGRATION_TIMEOUT,
12691270
terminalCommandDelay: terminalCommandDelay ?? 0,
1271+
terminalPowershellCounter: terminalPowershellCounter ?? false,
12701272
fuzzyMatchThreshold: fuzzyMatchThreshold ?? 1.0,
12711273
mcpEnabled: mcpEnabled ?? true,
12721274
enableMcpServerCreation: enableMcpServerCreation ?? true,
@@ -1354,6 +1356,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13541356
terminalShellIntegrationTimeout:
13551357
stateValues.terminalShellIntegrationTimeout ?? TERMINAL_SHELL_INTEGRATION_TIMEOUT,
13561358
terminalCommandDelay: stateValues.terminalCommandDelay ?? 0,
1359+
terminalPowershellCounter: stateValues.terminalPowershellCounter ?? false,
13571360
mode: stateValues.mode ?? defaultModeSlug,
13581361
language: stateValues.language ?? formatLanguage(vscode.env.language),
13591362
mcpEnabled: stateValues.mcpEnabled ?? true,

src/core/webview/webviewMessageHandler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,13 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
743743
Terminal.setCommandDelay(message.value)
744744
}
745745
break
746+
case "terminalPowershellCounter":
747+
await updateGlobalState("terminalPowershellCounter", message.bool)
748+
await provider.postStateToWebview()
749+
if (message.bool !== undefined) {
750+
Terminal.setPowershellCounter(message.bool)
751+
}
752+
break
746753
case "mode":
747754
await provider.handleModeSwitch(message.text as Mode)
748755
break

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ type GlobalSettings = {
267267
terminalOutputLineLimit?: number | undefined
268268
terminalShellIntegrationTimeout?: number | undefined
269269
terminalCommandDelay?: number | undefined
270+
terminalPowershellCounter?: boolean | undefined
270271
rateLimitSeconds?: number | undefined
271272
diffEnabled?: boolean | undefined
272273
fuzzyMatchThreshold?: number | undefined

src/exports/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ type GlobalSettings = {
270270
terminalOutputLineLimit?: number | undefined
271271
terminalShellIntegrationTimeout?: number | undefined
272272
terminalCommandDelay?: number | undefined
273+
terminalPowershellCounter?: boolean | undefined
273274
rateLimitSeconds?: number | undefined
274275
diffEnabled?: boolean | undefined
275276
fuzzyMatchThreshold?: number | undefined

src/integrations/terminal/Terminal.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const TERMINAL_SHELL_INTEGRATION_TIMEOUT = 5000
88
export class Terminal {
99
private static shellIntegrationTimeout: number = TERMINAL_SHELL_INTEGRATION_TIMEOUT
1010
private static commandDelay: number = 0
11+
private static powershellCounter: boolean = false
1112

1213
public terminal: vscode.Terminal
1314
public busy: boolean
@@ -277,6 +278,22 @@ export class Terminal {
277278
return Terminal.commandDelay
278279
}
279280

281+
/**
282+
* Sets whether to use the PowerShell counter workaround
283+
* @param enabled Whether to enable the PowerShell counter workaround
284+
*/
285+
public static setPowershellCounter(enabled: boolean): void {
286+
Terminal.powershellCounter = enabled
287+
}
288+
289+
/**
290+
* Gets whether to use the PowerShell counter workaround
291+
* @returns Whether the PowerShell counter workaround is enabled
292+
*/
293+
public static getPowershellCounter(): boolean {
294+
return Terminal.powershellCounter
295+
}
296+
280297
public static compressTerminalOutput(input: string, lineLimit: number): string {
281298
return truncateOutput(applyRunLengthEncoding(input), lineLimit)
282299
}

src/integrations/terminal/TerminalProcess.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,16 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
290290
(defaultWindowsShellProfile === null ||
291291
(defaultWindowsShellProfile as string)?.toLowerCase().includes("powershell"))
292292
if (isPowerShell) {
293-
let commandToExecute = `${command} ; "(Roo/PS Workaround: ${this.terminalInfo.cmdCounter++})" > $null`
293+
let commandToExecute = command
294+
295+
// Only add the PowerShell counter workaround if enabled
296+
if (Terminal.getPowershellCounter()) {
297+
commandToExecute += ` ; "(Roo/PS Workaround: ${this.terminalInfo.cmdCounter++})" > $null`
298+
}
294299

295300
// Only add the sleep command if the command delay is greater than 0
296301
if (Terminal.getCommandDelay() > 0) {
297-
commandToExecute += `; start-sleep -milliseconds ${Terminal.getCommandDelay()}`
302+
commandToExecute += ` ; start-sleep -milliseconds ${Terminal.getCommandDelay()}`
298303
}
299304

300305
terminal.shellIntegration.executeCommand(commandToExecute)

src/schemas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ export const globalSettingsSchema = z.object({
533533
terminalOutputLineLimit: z.number().optional(),
534534
terminalShellIntegrationTimeout: z.number().optional(),
535535
terminalCommandDelay: z.number().optional(),
536+
terminalPowershellCounter: z.boolean().optional(),
536537

537538
rateLimitSeconds: z.number().optional(),
538539
diffEnabled: z.boolean().optional(),
@@ -604,6 +605,7 @@ const globalSettingsRecord: GlobalSettingsRecord = {
604605
terminalOutputLineLimit: undefined,
605606
terminalShellIntegrationTimeout: undefined,
606607
terminalCommandDelay: undefined,
608+
terminalPowershellCounter: undefined,
607609

608610
rateLimitSeconds: undefined,
609611
diffEnabled: undefined,

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export type ExtensionState = Pick<
154154
| "terminalOutputLineLimit"
155155
| "terminalShellIntegrationTimeout"
156156
| "terminalCommandDelay"
157+
| "terminalPowershellCounter"
157158
| "diffEnabled"
158159
| "fuzzyMatchThreshold"
159160
// | "experiments" // Optional in GlobalSettings, required here.

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export interface WebviewMessage {
8383
| "terminalOutputLineLimit"
8484
| "terminalShellIntegrationTimeout"
8585
| "terminalCommandDelay"
86+
| "terminalPowershellCounter"
8687
| "mcpEnabled"
8788
| "enableMcpServerCreation"
8889
| "searchCommits"

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
130130
terminalOutputLineLimit,
131131
terminalShellIntegrationTimeout,
132132
terminalCommandDelay,
133+
terminalPowershellCounter,
133134
writeDelayMs,
134135
showRooIgnoredFiles,
135136
remoteBrowserEnabled,
@@ -239,6 +240,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
239240
vscode.postMessage({ type: "terminalOutputLineLimit", value: terminalOutputLineLimit ?? 500 })
240241
vscode.postMessage({ type: "terminalShellIntegrationTimeout", value: terminalShellIntegrationTimeout })
241242
vscode.postMessage({ type: "terminalCommandDelay", value: terminalCommandDelay })
243+
vscode.postMessage({ type: "terminalPowershellCounter", bool: terminalPowershellCounter })
242244
vscode.postMessage({ type: "mcpEnabled", bool: mcpEnabled })
243245
vscode.postMessage({ type: "alwaysApproveResubmit", bool: alwaysApproveResubmit })
244246
vscode.postMessage({ type: "requestDelaySeconds", value: requestDelaySeconds })
@@ -484,6 +486,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
484486
terminalOutputLineLimit={terminalOutputLineLimit}
485487
terminalShellIntegrationTimeout={terminalShellIntegrationTimeout}
486488
terminalCommandDelay={terminalCommandDelay}
489+
terminalPowershellCounter={terminalPowershellCounter}
487490
setCachedStateField={setCachedStateField}
488491
/>
489492
</div>

0 commit comments

Comments
 (0)