Skip to content

Commit a893ae5

Browse files
authored
fix some issues (microsoft#257363)
1 parent ff6f70b commit a893ae5

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function pollForOutputAndIdle(
4444
extendedPolling: boolean,
4545
token: CancellationToken,
4646
languageModelsService: ILanguageModelsService,
47-
): Promise<{ terminalExecutionIdleBeforeTimeout: boolean; output: string; pollDurationMs?: number }> {
47+
): Promise<{ terminalExecutionIdleBeforeTimeout: boolean; output: string; pollDurationMs?: number; modelOutputEvalResponse?: string }> {
4848
const maxWaitMs = extendedPolling ? PollingConsts.ExtendedPollingMaxDuration : PollingConsts.FirstPollingMaxDuration;
4949
const maxInterval = PollingConsts.MaxPollingIntervalDuration;
5050
let currentInterval = PollingConsts.MinPollingDuration;
@@ -89,13 +89,17 @@ export async function pollForOutputAndIdle(
8989
}
9090

9191
if (noNewDataCount >= PollingConsts.MinNoDataEvents) {
92-
terminalExecutionIdleBeforeTimeout = await assessOutputForFinishedState(buffer, execution, token, languageModelsService);
93-
if (terminalExecutionIdleBeforeTimeout) {
94-
return { terminalExecutionIdleBeforeTimeout, output: buffer, pollDurationMs: Date.now() - pollStartTime + (extendedPolling ? PollingConsts.FirstPollingMaxDuration : 0) };
92+
if (execution.isActive && ((await execution.isActive()) === true)) {
93+
noNewDataCount = 0;
94+
lastBufferLength = currentBufferLength;
95+
continue;
9596
}
97+
terminalExecutionIdleBeforeTimeout = true;
98+
const modelOutputEvalResponse = await assessOutputForErrors(buffer, token, languageModelsService);
99+
return { modelOutputEvalResponse, terminalExecutionIdleBeforeTimeout, output: buffer, pollDurationMs: Date.now() - pollStartTime + (extendedPolling ? PollingConsts.FirstPollingMaxDuration : 0) };
96100
}
97101
}
98-
return { terminalExecutionIdleBeforeTimeout, output: buffer, pollDurationMs: Date.now() - pollStartTime + (extendedPolling ? PollingConsts.FirstPollingMaxDuration : 0) };
102+
return { terminalExecutionIdleBeforeTimeout: false, output: buffer, pollDurationMs: Date.now() - pollStartTime + (extendedPolling ? PollingConsts.FirstPollingMaxDuration : 0) };
99103
}
100104

101105
export async function promptForMorePolling(command: string, context: IToolInvocationContext, chatService: IChatService): Promise<boolean> {
@@ -125,16 +129,13 @@ export async function promptForMorePolling(command: string, context: IToolInvoca
125129
return false; // Fallback to not waiting if we can't prompt the user
126130
}
127131

128-
export async function assessOutputForFinishedState(buffer: string, execution: { getOutput: () => string; isActive?: () => Promise<boolean> }, token: CancellationToken, languageModelsService: ILanguageModelsService): Promise<boolean> {
129-
if (execution.isActive && ((await execution.isActive()) === false)) {
130-
return true;
131-
}
132+
export async function assessOutputForErrors(buffer: string, token: CancellationToken, languageModelsService: ILanguageModelsService): Promise<string> {
132133
const models = await languageModelsService.selectLanguageModels({ vendor: 'copilot', family: 'gpt-4o-mini' });
133134
if (!models.length) {
134-
return false;
135+
return 'No models available';
135136
}
136137

137-
const response = await languageModelsService.sendChatRequest(models[0], new ExtensionIdentifier('Github.copilot-chat'), [{ role: ChatMessageRole.Assistant, content: [{ type: 'text', value: `Evaluate this terminal output to determine if the command is finished or still in process: ${buffer}. Return the word true if finished and false if still in process.` }] }], {}, token);
138+
const response = await languageModelsService.sendChatRequest(models[0], new ExtensionIdentifier('Github.copilot-chat'), [{ role: ChatMessageRole.Assistant, content: [{ type: 'text', value: `Evaluate this terminal output to determine if there were errors or if the command ran successfully: ${buffer}.` }] }], {}, token);
138139

139140
let responseText = '';
140141

@@ -154,8 +155,8 @@ export async function assessOutputForFinishedState(buffer: string, execution: {
154155

155156
try {
156157
await Promise.all([response.result, streaming]);
157-
return responseText.includes('true');
158+
return response.result;
158159
} catch (err) {
159-
return false;
160+
return 'Error occurred ' + err;
160161
}
161162
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
281281
const termId = generateUuid();
282282

283283
if (args.isBackground) {
284-
let outputAndIdle: { terminalExecutionIdleBeforeTimeout: boolean; output: string; pollDurationMs?: number } | undefined = undefined;
284+
let outputAndIdle: { terminalExecutionIdleBeforeTimeout: boolean; output: string; pollDurationMs?: number; modelOutputEvalResponse?: string } | undefined = undefined;
285285

286286
this._logService.debug(`RunInTerminalTool: Creating background terminal with ID=${termId}`);
287287
const toolTerminal = await this._instantiationService.createInstance(ToolTerminalCreator).createTerminal(token);
@@ -318,7 +318,7 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
318318
? `Note: The tool simplified the command to \`${command}\`, and that command is now running in terminal with ID=${termId}`
319319
: `Command is running in terminal with ID=${termId}`
320320
);
321-
resultText += outputAndIdle.terminalExecutionIdleBeforeTimeout ? `\n\ The command became idle with output:\n${outputAndIdle.output}` : `\n\ The command is still running, with output:\n${outputAndIdle.output}`;
321+
resultText += outputAndIdle.modelOutputEvalResponse ? `\n\ The command became idle with output:\n${outputAndIdle.modelOutputEvalResponse}` : `\n\ The command is still running, with output:\n${outputAndIdle.output}`;
322322
return {
323323
content: [{
324324
kind: 'text',

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/getTaskOutputTool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ export class GetTaskOutputTool extends Disposable implements IToolImpl {
7777
const taskDefinition = getTaskDefinition(args.id);
7878
const task = await getTaskForTool(args.id, taskDefinition, args.workspaceFolder, this._configurationService, this._tasksService);
7979
if (!task) {
80-
return { content: [{ kind: 'text', value: localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id) }], toolResultMessage: new MarkdownString(localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id)) };
80+
return { content: [{ kind: 'text', value: `Task not found: ${args.id}` }], toolResultMessage: new MarkdownString(localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id)) };
8181
}
8282

8383
const resource = this._tasksService.getTerminalForTask(task);
8484
const terminal = this._terminalService.instances.find(t => t.resource.path === resource?.path && t.resource.scheme === resource.scheme);
8585
if (!terminal) {
86-
return { content: [{ kind: 'text', value: localize('copilotChat.terminalNotFound', 'Terminal not found for task `{0}`', taskDefinition?.taskLabel) }], toolResultMessage: new MarkdownString(localize('copilotChat.terminalNotFound', 'Terminal not found for task `{0}`', taskDefinition?.taskLabel)) };
86+
return { content: [{ kind: 'text', value: `Terminal not found for task ${taskDefinition?.taskLabel}` }], toolResultMessage: new MarkdownString(localize('copilotChat.terminalNotFound', 'Terminal not found for task `{0}`', taskDefinition?.taskLabel)) };
8787
}
8888
return {
8989
content: [{
9090
kind: 'text',
91-
value: localize('copilotChat.taskOutput', 'Output of task `{0}`:\n{1}', taskDefinition.taskLabel, getOutput(terminal))
91+
value: `Output of task ${taskDefinition.taskLabel}: ${getOutput(terminal)}`
9292
}]
9393
};
9494
}

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/task/runTaskTool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ export class RunTaskTool implements IToolImpl {
5959
const task = await getTaskForTool(args.id, taskDefinition, args.workspaceFolder, this._configurationService, this._tasksService);
6060

6161
if (!task) {
62-
return { content: [{ kind: 'text', value: localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id) }], toolResultMessage: new MarkdownString(localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id)) };
62+
return { content: [{ kind: 'text', value: `Task not found: ${args.id}` }], toolResultMessage: new MarkdownString(localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id)) };
6363
}
6464

6565
const activeTasks = await this._tasksService.getActiveTasks();
6666
if (activeTasks.includes(task)) {
67-
return { content: [{ kind: 'text', value: localize('copilotChat.taskAlreadyRunning', 'The task `{0}` is already running.', taskDefinition.taskLabel) }], toolResultMessage: new MarkdownString(localize('copilotChat.taskAlreadyRunning', 'The task `{0}` is already running.', taskDefinition.taskLabel)) };
67+
return { content: [{ kind: 'text', value: `The task ${taskDefinition.taskLabel} is already running.` }], toolResultMessage: new MarkdownString(localize('copilotChat.taskAlreadyRunning', 'The task `{0}` is already running.', taskDefinition.taskLabel)) };
6868
}
6969

7070
const raceResult = await Promise.race([this._tasksService.run(task), timeout(3000)]);
@@ -73,7 +73,7 @@ export class RunTaskTool implements IToolImpl {
7373
const resource = this._tasksService.getTerminalForTask(task);
7474
const terminal = this._terminalService.instances.find(t => t.resource.path === resource?.path && t.resource.scheme === resource.scheme);
7575
if (!terminal) {
76-
return { content: [{ kind: 'text', value: localize('copilotChat.noTerminal', 'Task started but no terminal was found for: `{0}`', taskDefinition.taskLabel) }], toolResultMessage: new MarkdownString(localize('copilotChat.noTerminal', 'Task started but no terminal was found for: `{0}`', taskDefinition.taskLabel)) };
76+
return { content: [{ kind: 'text', value: `Task started but no terminal was found for: ${taskDefinition.taskLabel}` }], toolResultMessage: new MarkdownString(localize('copilotChat.noTerminal', 'Task started but no terminal was found for: `{0}`', taskDefinition.taskLabel)) };
7777
}
7878

7979
_progress.report({ message: new MarkdownString(localize('copilotChat.checkingOutput', 'Checking output for `{0}`', taskDefinition.taskLabel)) });

0 commit comments

Comments
 (0)