Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompts/node/panel/terminalLastCommand.tsx
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { BasePromptElementProps, PromptElement, PromptPiece, PromptSizing, UserMessage } from '@vscode/prompt-tsx';
7
import type { TerminalExecutedCommand } from 'vscode';
8
import { ITerminalService } from '../../../../platform/terminal/common/terminalService';
9
10
export interface ProjectLabelsProps extends BasePromptElementProps { }
11
12
export class TerminalLastCommand extends PromptElement<ProjectLabelsProps, TerminalExecutedCommand | undefined> {
13
constructor(
14
props: ProjectLabelsProps,
15
@ITerminalService private readonly _terminalService: ITerminalService
16
) {
17
super(props);
18
}
19
20
override async prepare(): Promise<TerminalExecutedCommand | undefined> {
21
return this._terminalService.terminalLastCommand;
22
}
23
24
override render(state: TerminalExecutedCommand | undefined, sizing: PromptSizing): PromptPiece<any, any> | undefined {
25
if (!state) {
26
return undefined;
27
}
28
29
const userPrompt: string[] = [];
30
if (state.commandLine) {
31
userPrompt.push(`The following is the last command run in the terminal:`);
32
userPrompt.push(state.commandLine);
33
}
34
if (state.cwd) {
35
userPrompt.push(`It was run in the directory:`);
36
userPrompt.push(typeof state.cwd === 'object' ? state.cwd.toString() : state.cwd);
37
}
38
if (state.output) {
39
userPrompt.push(`It has the following output:`);
40
userPrompt.push(state.output);
41
}
42
43
const prompt = userPrompt.join('\n');
44
return (<>
45
<UserMessage priority={this.props.priority}>
46
The active terminal's last run command:<br />
47
{prompt}
48
</UserMessage >
49
</>);
50
}
51
}
52
53