Path: blob/main/extensions/copilot/src/extension/prompts/node/git/gitCommitMessagePrompt.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, SystemMessage, UserMessage } from '@vscode/prompt-tsx';5import { Diff } from '../../../../platform/git/common/gitDiffService';6import { basename } from '../../../../util/vs/base/common/path';7import { RecentCommitMessages } from '../../../prompt/common/repository';8import { ResponseTranslationRules } from '../base/responseTranslationRules';9import { SafetyRules } from '../base/safetyRules';10import { Tag } from '../base/tag';11import { CustomInstructions } from '../panel/customInstructions';12import { FilePathMode, FileVariable } from '../panel/fileVariable';13import { UnsafeCodeBlock } from '../panel/unsafeElements';1415export interface GitCommitMessagePromptProps extends BasePromptElementProps {16readonly repositoryName: string;17readonly branchName: string;18readonly changes: Diff[];19readonly recentCommitMessages: RecentCommitMessages;20}2122export class GitCommitMessagePrompt extends PromptElement<GitCommitMessagePromptProps> {23render() {24return (25<>26<SystemMessage priority={1000}>27<GitCommitMessageSystemRules />28<SafetyRules />29<ResponseTranslationRules />30</SystemMessage>31<UserMessage>32<Tag priority={850} name='repository-context'>33# REPOSITORY DETAILS:<br />34Repository name: {this.props.repositoryName}<br />35Branch name: {this.props.branchName}<br />36</Tag>37{this.props.recentCommitMessages.user.length > 0 && (38<Tag priority={700} name='user-commits'>39# RECENT USER COMMITS (For reference only, do not copy!):<br />40{this.props.recentCommitMessages.user.map(message => `- ${message}\n`).join('')}41</Tag>42)}43{this.props.recentCommitMessages.repository.length > 0 && (44<Tag priority={600} name='recent-commits'>45# RECENT REPOSITORY COMMITS (For reference only, do not copy!):<br />46{this.props.recentCommitMessages.repository.map(message => `- ${message}\n`).join('')}47</Tag>48)}49<Tag priority={900} name='changes'>50{this.props.changes.map((change) => (51<>52<Tag name='original-code' priority={800}>53# ORIGINAL CODE:<br />54<FileVariable55filePathMode={FilePathMode.AsComment}56lineNumberStyle={'legacy'}57passPriority={true}58variableName={basename(change.uri.toString())}59variableValue={change.uri} />60</Tag>61<Tag name='code-changes' priority={900}>62# CODE CHANGES:<br />63<UnsafeCodeBlock code={change.diff} languageId='diff' />64</Tag>65</>66))}67</Tag>68<Tag priority={950} name='reminder'>69Now generate a commit messages that describe the CODE CHANGES.<br />70DO NOT COPY commits from RECENT COMMITS, but use it as reference for the commit style.<br />71ONLY return a single markdown code block, NO OTHER PROSE!<br />72<UnsafeCodeBlock languageId='text' code='commit message goes here' />73</Tag>74<Tag priority={950} name='custom-instructions'>75<CustomInstructions76chatVariables={undefined}77customIntroduction='When generating the commit message, please use the following custom instructions provided by the user.'78languageId={undefined}79includeCodeGenerationInstructions={false}80includeCommitMessageGenerationInstructions={true} />81</Tag>82</UserMessage>83</>84);85}86}8788class GitCommitMessageSystemRules extends PromptElement {89render() {90return (91<>92You are an AI programming assistant, helping a software developer to come with the best git commit message for their code changes.<br />93You excel in interpreting the purpose behind code changes to craft succinct, clear commit messages that adhere to the repository's guidelines.<br />94<br />95# First, think step-by-step:<br />961. Analyze the CODE CHANGES thoroughly to understand what's been modified.<br />972. Use the ORIGINAL CODE to understand the context of the CODE CHANGES. Use the line numbers to map the CODE CHANGES to the ORIGINAL CODE.<br />983. Identify the purpose of the changes to answer the *why* for the commit messages, also considering the optionally provided RECENT USER COMMITS.<br />994. Review the provided RECENT REPOSITORY COMMITS to identify established commit message conventions. Focus on the format and style, ignoring commit-specific details like refs, tags, and authors.<br />1005. Generate a thoughtful and succinct commit message for the given CODE CHANGES. It MUST follow the the established writing conventions.1016. Remove any meta information like issue references, tags, or author names from the commit message. The developer will add them.<br />1027. Now only show your message, wrapped with a single markdown ```text codeblock! Do not provide any explanations or details<br />103</>104);105}106}107108109