Skip to content

Commit 97b10c9

Browse files
authored
show task's internal label vs type:index for tasks without custom label (microsoft#258251)
1 parent fcd6211 commit 97b10c9

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ export class GetTaskOutputTool extends Disposable implements IToolImpl {
6161
if (!task) {
6262
return { invocationMessage: new MarkdownString(localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id)) };
6363
}
64+
const taskLabel = task._label;
6465
const activeTasks = await this._tasksService.getActiveTasks();
6566
if (activeTasks.includes(task)) {
66-
return { invocationMessage: new MarkdownString(localize('copilotChat.taskAlreadyRunning', 'The task `{0}` is already running.', taskDefinition.taskLabel)) };
67+
return { invocationMessage: new MarkdownString(localize('copilotChat.taskAlreadyRunning', 'The task `{0}` is already running.', taskLabel)) };
6768
}
6869

6970
return {
70-
invocationMessage: new MarkdownString(localize('copilotChat.checkingTerminalOutput', 'Checking output for task `{0}`', taskDefinition.taskLabel)),
71-
pastTenseMessage: new MarkdownString(localize('copilotChat.checkedTerminalOutput', 'Checked output for task `{0}`', taskDefinition.taskLabel)),
71+
invocationMessage: new MarkdownString(localize('copilotChat.checkingTerminalOutput', 'Checking output for task `{0}`', taskLabel)),
72+
pastTenseMessage: new MarkdownString(localize('copilotChat.checkedTerminalOutput', 'Checked output for task `{0}`', taskLabel)),
7273
};
7374
}
7475

@@ -79,16 +80,16 @@ export class GetTaskOutputTool extends Disposable implements IToolImpl {
7980
if (!task) {
8081
return { content: [{ kind: 'text', value: `Task not found: ${args.id}` }], toolResultMessage: new MarkdownString(localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id)) };
8182
}
82-
8383
const resource = this._tasksService.getTerminalForTask(task);
84+
const taskLabel = task._label;
8485
const terminal = this._terminalService.instances.find(t => t.resource.path === resource?.path && t.resource.scheme === resource.scheme);
8586
if (!terminal) {
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)) };
87+
return { content: [{ kind: 'text', value: `Terminal not found for task ${taskLabel}` }], toolResultMessage: new MarkdownString(localize('copilotChat.terminalNotFound', 'Terminal not found for task `{0}`', taskLabel)) };
8788
}
8889
return {
8990
content: [{
9091
kind: 'text',
91-
value: `Output of task ${taskDefinition.taskLabel}: ${getOutput(terminal)}`
92+
value: `Output of task ${taskLabel}: ${getOutput(terminal)}`
9293
}]
9394
};
9495
}

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,14 @@ export class RunTaskTool implements IToolImpl {
5555
}
5656

5757
const taskDefinition = getTaskDefinition(args.id);
58-
5958
const task = await getTaskForTool(args.id, taskDefinition, args.workspaceFolder, this._configurationService, this._tasksService);
60-
6159
if (!task) {
6260
return { content: [{ kind: 'text', value: `Task not found: ${args.id}` }], toolResultMessage: new MarkdownString(localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id)) };
6361
}
64-
62+
const taskLabel = task._label;
6563
const activeTasks = await this._tasksService.getActiveTasks();
6664
if (activeTasks.includes(task)) {
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)) };
65+
return { content: [{ kind: 'text', value: `The task ${taskLabel} is already running.` }], toolResultMessage: new MarkdownString(localize('copilotChat.taskAlreadyRunning', 'The task `{0}` is already running.', taskLabel)) };
6866
}
6967

7068
const raceResult = await Promise.race([this._tasksService.run(task), timeout(3000)]);
@@ -73,15 +71,15 @@ export class RunTaskTool implements IToolImpl {
7371
const resource = this._tasksService.getTerminalForTask(task);
7472
const terminal = this._terminalService.instances.find(t => t.resource.path === resource?.path && t.resource.scheme === resource.scheme);
7573
if (!terminal) {
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)) };
74+
return { content: [{ kind: 'text', value: `Task started but no terminal was found for: ${taskLabel}` }], toolResultMessage: new MarkdownString(localize('copilotChat.noTerminal', 'Task started but no terminal was found for: `{0}`', taskLabel)) };
7775
}
7876

79-
_progress.report({ message: new MarkdownString(localize('copilotChat.checkingOutput', 'Checking output for `{0}`', taskDefinition.taskLabel)) });
77+
_progress.report({ message: new MarkdownString(localize('copilotChat.checkingOutput', 'Checking output for `{0}`', taskLabel)) });
8078
let outputAndIdle = await pollForOutputAndIdle({ getOutput: () => getOutput(terminal), isActive: () => this._isTaskActive(task) }, false, token, this._languageModelsService);
8179
if (!outputAndIdle.terminalExecutionIdleBeforeTimeout) {
8280
outputAndIdle = await racePollingOrPrompt(
8381
() => pollForOutputAndIdle({ getOutput: () => getOutput(terminal), isActive: () => this._isTaskActive(task) }, true, token, this._languageModelsService),
84-
() => promptForMorePolling(taskDefinition.taskLabel, invocation.context!, this._chatService),
82+
() => promptForMorePolling(taskLabel, invocation.context!, this._chatService),
8583
outputAndIdle,
8684
token,
8785
this._languageModelsService,
@@ -119,27 +117,27 @@ export class RunTaskTool implements IToolImpl {
119117
if (!task) {
120118
return { invocationMessage: new MarkdownString(localize('copilotChat.taskNotFound', 'Task not found: `{0}`', args.id)) };
121119
}
122-
120+
const taskLabel = task._label;
123121
const activeTasks = await this._tasksService.getActiveTasks();
124122
if (task && activeTasks.includes(task)) {
125123
return { invocationMessage: new MarkdownString(localize('copilotChat.taskAlreadyActive', 'The task is already running.')) };
126124
}
127125

128126
if (await this._isTaskActive(task)) {
129127
return {
130-
invocationMessage: new MarkdownString(localize('copilotChat.taskIsAlreadyRunning', '`{0}` is already running.', taskDefinition.taskLabel ?? args.id)),
131-
pastTenseMessage: new MarkdownString(localize('copilotChat.taskWasAlreadyRunning', '`{0}` was already running.', taskDefinition.taskLabel ?? args.id)),
128+
invocationMessage: new MarkdownString(localize('copilotChat.taskIsAlreadyRunning', '`{0}` is already running.', taskLabel)),
129+
pastTenseMessage: new MarkdownString(localize('copilotChat.taskWasAlreadyRunning', '`{0}` was already running.', taskLabel)),
132130
confirmationMessages: undefined
133131
};
134132
}
135133

136134
return {
137-
invocationMessage: new MarkdownString(localize('copilotChat.runningTask', 'Running `{0}`', taskDefinition.taskLabel)),
135+
invocationMessage: new MarkdownString(localize('copilotChat.runningTask', 'Running `{0}`', taskLabel)),
138136
pastTenseMessage: new MarkdownString(task?.configurationProperties.isBackground
139-
? localize('copilotChat.startedTask', 'Started `{0}`', taskDefinition.taskLabel)
140-
: localize('copilotChat.ranTask', 'Ran `{0}`', taskDefinition.taskLabel)),
137+
? localize('copilotChat.startedTask', 'Started `{0}`', taskLabel)
138+
: localize('copilotChat.ranTask', 'Ran `{0}`', taskLabel)),
141139
confirmationMessages: task
142-
? { title: localize('copilotChat.allowTaskRunTitle', 'Allow task run?'), message: localize('copilotChat.allowTaskRunMsg', 'Allow Copilot to run the task `{0}`?', taskDefinition.taskLabel) }
140+
? { title: localize('copilotChat.allowTaskRunTitle', 'Allow task run?'), message: localize('copilotChat.allowTaskRunMsg', 'Allow Copilot to run the task `{0}`?', taskLabel) }
143141
: undefined
144142
};
145143
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export async function getTaskForTool(id: string | undefined, taskDefinition: { t
3939
const configTasks: IConfiguredTask[] = (configurationService.getValue('tasks') as { tasks: IConfiguredTask[] }).tasks ?? [];
4040
for (const configTask of configTasks) {
4141
if (!configTask.type || 'hide' in configTask && configTask.hide) {
42-
// Skip thse as they
43-
// and not included in the agent prompt.
42+
// Skip these as they are not included in the agent prompt and we need to align with
43+
// the indices used there.
4444
continue;
4545
}
4646
if ((configTask.type && taskDefinition.taskType ? configTask.type === taskDefinition.taskType : true) &&
@@ -58,7 +58,7 @@ export async function getTaskForTool(id: string | undefined, taskDefinition: { t
5858
}
5959
const configuringTasks: IStringDictionary<ConfiguringTask> | undefined = (await taskService.getWorkspaceTasks())?.get(URI.file(workspaceFolder).toString())?.configurations?.byIdentifier;
6060
const configuredTask: ConfiguringTask | undefined = Object.values(configuringTasks ?? {}).find(t => {
61-
return t.type === task.type && (t._label === task.label || t._label === `${task.type}: ${getTaskRepresentation(task)}`);
61+
return t.type === task.type && (t._label === task.label || t._label === `${task.type}: ${getTaskRepresentation(task)}` || t._label === getTaskRepresentation(task));
6262
});
6363
let resolvedTask: Task | undefined;
6464
if (configuredTask) {

0 commit comments

Comments
 (0)