Path: blob/main/extensions/copilot/src/extension/prompts/node/feedback/provideFeedback.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*--------------------------------------------------------------------------------------------*/4import { BasePromptElementProps, PromptElement, PromptPiece, PromptSizing, SystemMessage, UserMessage } from '@vscode/prompt-tsx';5import { ILogService } from '../../../../platform/log/common/logService';6import { ChatVariablesCollection } from '../../../prompt/common/chatVariablesCollection';7import { Turn } from '../../../prompt/common/conversation';8import { CopilotIdentityRules } from '../base/copilotIdentity';9import { ResponseTranslationRules } from '../base/responseTranslationRules';10import { SafetyRules } from '../base/safetyRules';11import { ChatVariablesAndQuery } from '../panel/chatVariables';12import { CustomInstructions } from '../panel/customInstructions';13import { EditorIntegrationRules } from '../panel/editorIntegrationRules';14import { ProjectLabels } from '../panel/projectLabels';15import { SymbolDefinitions } from '../panel/symbolDefinitions';16import { CurrentChange, CurrentChangeInput } from './currentChange';1718export interface ProvideFeedbackPromptProps extends BasePromptElementProps {19chatVariables?: ChatVariablesCollection;20history?: readonly Turn[];21query?: string;2223input: CurrentChangeInput[];24logService: ILogService;25}2627export class ProvideFeedbackPrompt extends PromptElement<ProvideFeedbackPromptProps> {2829override render(state: void, sizing: PromptSizing): PromptPiece<any, any> | undefined {30return (31<>32<SystemMessage priority={1001}>33You are a world-class software engineer and the author and maintainer of the discussed code. Your feedback prefectly combines detailed feedback and explanation of context.<br />34<CopilotIdentityRules />35<SafetyRules />36<EditorIntegrationRules />37<ResponseTranslationRules />38<br />39Additional Rules<br />40Think step by step:<br />411. Examine the provided code and any other context like user question, related errors, project details, class definitions, etc.<br />422. Provide feedback on the current {this.props.input[0]?.change ? <>change</> : <>selection</>} on where it can be improved or introduces a problem.<br />432a. Avoid commenting on correct code.<br />442b. Avoid commenting on commented out code.<br />452c. Keep scoping rules in mind.<br />463. Reply with an enumerated list of feedback with source line number, filepath, kind (bug, performance, consistency, documentation, naming, readability, style, other), severity (low, medium, high), and feedback text.<br />473a. E.g.: 1. Line 357 in src/flow.js, bug, high severity: `i` is not incremented.<br />483b. E.g.: 2. Line 361 in src/arrays.js, documentation, low severity: Function `binarySearch` is not documented.<br />493c. E.g.: 3. Line 176 in src/vs/platform/actionWidget/browser/actionWidget.ts, consistency, medium severity: The color id `'background.actionBar'` is not consistent with the other color ids used. Use `'actionBar.background'` instead.<br />503d. E.g.: 4. Line 410 in src/search.js, documentation, medium severity: Returning `-1` when the target is not found is a common convention, but it should be documented.<br />513e. E.g.: 5. Line 51 in src/account.py, bug, high severity: The deposit method is not thread-safe. You should use a lock to ensure that the balance update is an atomic operation.<br />523f. E.g.: 6. Line 220 in src/account.py, readability, low severity: The withdraw method is very long and combines multipe logical steps, consider splitting it into multiple methods.<br />534. Try to sort the feedback by file and line number.<br />545. When there is no feedback to provide, reply with "No feedback to provide."<br />55<br />56Focus on being clear, helpful, and thorough.<br />57Use developer-friendly terms and analogies in your explanations.<br />58Provide clear and relevant examples when helpful.59</SystemMessage>60{/* {this.props.history && <><ConversationHistory priority={600} history={this.props.history} /></>} */}61<UserMessage flexGrow={1}>62<ProjectLabels flexGrow={1} priority={700} />63<CustomInstructions chatVariables={this.props.chatVariables} priority={850} languageId={this.props.input[0]?.document.languageId} customIntroduction={'When providing feedback for code, please check for these user provided coding guidelines.'} includeCodeFeedbackInstructions={true} />64<CurrentChange input={this.props.input} logService={this.props.logService} priority={1000} flexGrow={2} />65{66this.props.input.map(input => (67<SymbolDefinitions document={input.document} range={input.selection} priority={800} />68))69}70{this.props.chatVariables && this.props.query && <ChatVariablesAndQuery flexGrow={3} priority={900} chatVariables={this.props.chatVariables} query={this.props.query} />}71</UserMessage>72</>73);74}75}767778