Skip to content

Commit 1ffb41c

Browse files
authored
Detect xterm-trimmed Password: prompt so agent doesn't hang on sudo su (#314257)
1 parent b54e0db commit 1ffb41c

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/monitoring/outputMonitor.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,11 @@ export function detectsHighConfidenceInputPattern(cursorLine: string): boolean {
603603
/:\s*\([^)]*\) +$/,
604604
// Line contains (END) which is common in pagers
605605
/\(END\)$/,
606-
// Password prompt (must be followed by optional colon and trailing space to indicate
607-
// an active prompt; otherwise normal output containing the word "password" would match).
608-
/password:? +$/i,
606+
// Password prompt. Requires a trailing colon (e.g. "Password:", "[sudo] password for user:")
607+
// and tolerates zero or more trailing spaces — xterm's `translateToString(trimRight=true)`
608+
// strips trailing whitespace from non-wrapped buffer lines, so a real `Password: ` prompt
609+
// is captured from the buffer as `Password:` with no trailing space.
610+
/password(?: for [^:]+)?:\s*$/i,
609611
// "Press a key" or "Press any key"
610612
/press a(?:ny)? key/i,
611613
// Interactive prompt libraries (prompts, enquirer, inquirer) prefix the prompt with

src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/outputMonitor.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ suite('OutputMonitor', () => {
460460
});
461461
test('matches password and press-any-key prompts', () => {
462462
assert.strictEqual(detectsHighConfidenceInputPattern('Password: '), true);
463+
// xterm's translateToString(trimRight=true) strips trailing whitespace from
464+
// non-wrapped buffer lines, so a real `Password: ` prompt is captured as
465+
// `Password:` with no trailing space (e.g. when running `sudo su`).
466+
assert.strictEqual(detectsHighConfidenceInputPattern('Password:'), true);
467+
// The colon is required: a bare line ending with the word "password" should
468+
// not match (avoids false positives on log/help output that mentions the word).
469+
assert.strictEqual(detectsHighConfidenceInputPattern('Enter your password'), false);
463470
assert.strictEqual(detectsHighConfidenceInputPattern('Press any key to continue...'), true);
464471
});
465472
test('matches parenthesized defaults', () => {

0 commit comments

Comments
 (0)