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