| 1 | import { SlashCommand } from "../../../index.js"; |
| 2 | import { renderChatMessage } from "../../../util/messageContent.js"; |
| 3 | |
| 4 | const CommitMessageCommand: SlashCommand = { |
| 5 | name: "commit", |
| 6 | description: "Generate a commit message for current changes", |
| 7 | run: async function* ({ ide, llm, params, abortController }) { |
| 8 | const includeUnstaged = params?.includeUnstaged ?? false; |
| 9 | const diff = await ide.getDiff(includeUnstaged); |
| 10 | |
| 11 | if (diff.length === 0) { |
| 12 | yield "No changes detected. Make sure you are in a git repository with current changes."; |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | const prompt = `${diff.join("\n")}\n\nGenerate a commit message for the above set of changes. First, give a single sentence, no more than 80 characters. Then, after 2 line breaks, give a list of no more than 5 short bullet points, each no more than 40 characters. Output nothing except for the commit message, and don't surround it in quotes.`; |
| 17 | for await (const chunk of llm.streamChat( |
| 18 | [{ role: "user", content: prompt }], |
| 19 | abortController.signal, |
| 20 | )) { |
| 21 | yield renderChatMessage(chunk); |
| 22 | } |
| 23 | }, |
| 24 | }; |
| 25 | |
| 26 | export default CommitMessageCommand; |