Skip to content

Commit 85da048

Browse files
committed
Actually poll prompt detection
1 parent 94bf782 commit 85da048

File tree

1 file changed

+27
-17
lines changed
  • src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy

1 file changed

+27
-17
lines changed

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/executeStrategy.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,38 +113,48 @@ export function detectsCommonPromptPattern(cursorLine: string): IPromptDetection
113113
export async function waitForIdleWithPromptHeuristics(
114114
onData: Event<unknown>,
115115
instance: ITerminalInstance,
116-
initialTimeoutMs: number,
117-
extendedTimeoutMs: number = 2000
116+
idlePollIntervalMs: number,
117+
extendedTimeoutMs: number,
118118
): Promise<IPromptDetectionResult> {
119-
await waitForIdle(onData, initialTimeoutMs);
119+
await waitForIdle(onData, idlePollIntervalMs);
120120

121-
try {
122-
const xterm = await instance.xtermReadyPromise;
123-
if (xterm) {
121+
const xterm = await instance.xtermReadyPromise;
122+
if (!xterm) {
123+
return { detected: false, reason: `Xterm not available, using ${idlePollIntervalMs}ms timeout` };
124+
}
125+
const startTime = Date.now();
126+
127+
// Attempt to detect a prompt pattern after idle
128+
while (Date.now() - startTime < extendedTimeoutMs) {
129+
try {
124130
let content = '';
125131
const buffer = xterm.raw.buffer.active;
126132
const line = buffer.getLine(buffer.baseY + buffer.cursorY);
127133
if (line) {
128-
content = line.translateToString(true) + '\n';
134+
content = line.translateToString(true);
129135
}
130-
131-
// If we detect a common prompt pattern, we're done
132136
const promptResult = detectsCommonPromptPattern(content);
133137
if (promptResult.detected) {
134138
return promptResult;
135139
}
140+
} catch (error) {
141+
// Continue polling even if there's an error reading terminal content
142+
}
143+
await waitForIdle(onData, Math.min(idlePollIntervalMs, extendedTimeoutMs - (Date.now() - startTime)));
144+
}
136145

137-
// Otherwise, wait for the extended timeout period
138-
await waitForIdle(onData, extendedTimeoutMs);
139-
return { detected: false, reason: 'Extended timeout reached without prompt detection' };
146+
// Extended timeout reached without detecting a prompt
147+
try {
148+
let content = '';
149+
const buffer = xterm.raw.buffer.active;
150+
const line = buffer.getLine(buffer.baseY + buffer.cursorY);
151+
if (line) {
152+
content = line.translateToString(true) + '\n';
140153
}
154+
return { detected: false, reason: `Extended timeout reached without prompt detection. Last line: "${content.trim()}"` };
141155
} catch (error) {
142-
// If there's an error getting terminal content, fall back to extended timeout
143-
await waitForIdle(onData, extendedTimeoutMs);
144-
return { detected: false, reason: `Error reading terminal content: ${error}` };
156+
return { detected: false, reason: `Extended timeout reached. Error reading terminal content: ${error}` };
145157
}
146-
147-
return { detected: false, reason: 'Xterm not available' };
148158
}
149159

150160
/**

0 commit comments

Comments
 (0)