-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathcommit.ts
26 lines (22 loc) · 1.1 KB
/
commit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { SlashCommand } from "../../index.js";
import { renderChatMessage } from "../../util/messageContent.js";
const CommitMessageCommand: SlashCommand = {
name: "commit",
description: "Generate a commit message for current changes",
run: async function* ({ ide, llm, params }) {
const includeUnstaged = params?.includeUnstaged ?? false;
const diff = await ide.getDiff(includeUnstaged);
if (diff.length === 0) {
yield "No changes detected. Make sure you are in a git repository with current changes.";
return;
}
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.`;
for await (const chunk of llm.streamChat(
[{ role: "user", content: prompt }],
new AbortController().signal,
)) {
yield renderChatMessage(chunk);
}
},
};
export default CommitMessageCommand;