Skip to content

Commit 3ec26b4

Browse files
authored
Merge pull request #6 from yamork779/main
feat(prompts): Code escape characters and redundant output are disabled, and it adapts to different source configurations.
2 parents 8b0ef15 + 4508ddc commit 3ec26b4

5 files changed

Lines changed: 200 additions & 16 deletions

File tree

‎src/generators/commit.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export async function generateCommitMessage(
4040
}
4141

4242
const keepCoAuthoredBy = config.get<boolean>("keepCoAuthoredBy", false);
43-
const prompt = createManagedPrompt(language, keepCoAuthoredBy, "");
43+
const multiLine = config.get<boolean>("multiLineCommit", false);
44+
const diffSource = config.get<DiffSource>("diffSource", "auto");
45+
const prompt = createManagedPrompt(language, keepCoAuthoredBy, multiLine, diffSource, "");
4446
return await generateWithCLIManaged(prompt, repoPath, progressCallback);
4547
}
4648

@@ -161,7 +163,9 @@ export async function generateWithCustomPrompt(
161163
}
162164

163165
const keepCoAuthoredBy = config.get<boolean>("keepCoAuthoredBy", false);
164-
const prompt = createManagedPrompt(language, keepCoAuthoredBy, customPrompt);
166+
const multiLine = config.get<boolean>("multiLineCommit", false);
167+
const diffSource = config.get<DiffSource>("diffSource", "auto");
168+
const prompt = createManagedPrompt(language, keepCoAuthoredBy, multiLine, diffSource, customPrompt);
165169
return await generateWithCLIManaged(prompt, repoPath, progressCallback);
166170
}
167171

‎src/prompts/en.ts‎

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,78 @@ docs(readme): updated installation instructions
6363
Return ONLY the commit message (one line), no explanations.`;
6464
}
6565

66-
export function getManagedPrompt(keepCoAuthoredBy: boolean, customPrompt: string): string {
67-
let prompt = `Generate a git commit message for current changes, in English, output only the commit message, no other text.`;
66+
export function getManagedPrompt(keepCoAuthoredBy: boolean, multiline: boolean, diffSource: string, customPrompt: string): string {
67+
let diffInstruction = "";
68+
if (diffSource === "staged") {
69+
diffInstruction = "Generate commit message based ONLY on staged changes, ignore unstaged changes.";
70+
} else if (diffSource === "all") {
71+
diffInstruction = "Generate commit message based on ALL changes (both staged and unstaged).";
72+
} else {
73+
diffInstruction = "If there are staged changes, generate commit message based on staged only; if staging area is empty, generate based on all changes.";
74+
}
75+
76+
let prompt = `Generate a git commit message for current changes, in English, output only the commit message content directly, no other text.
77+
78+
Role Definition:
79+
You are now a "Git Commit Message Generator" function running in a script. You have no conversational ability, no personality, and no externalization of thought processes.
80+
81+
Your only task is to convert input code changes into English Commit Messages that conform to the Angular specification.
82+
83+
84+
### Strict Execution Standards:
85+
1. **Zero nonsense**: Absolutely no output like "Based on analysis...", "Here's your message...", "Summary of changes:" or any conversational content.
86+
2. **Plain text**: Absolutely no use of \`\`\` (Markdown code blocks) or ** (bold) formatting. Output plain text only.
87+
3. **Format constraint**:
88+
First line must conform to: <feat|fix|docs|style|refactor|test|build|ci|perf|chore|revert>(scope): <subject>
89+
(scope is the module name, subject is a brief description in English)
90+
4. **Change scope**: ${diffInstruction}
91+
5. **Generate message only**: Absolutely no extra content before or after commit message, such as polite hints or thinking processes.
92+
93+
### Wrong examples (absolutely forbidden):
94+
❌ "Okay, based on your code..."
95+
❌ "**Change analysis**: Updated..."
96+
❌ "...commit message:"
97+
❌ \`\`\`text feat(core): ... \`\`\`
98+
99+
### Correct example:
100+
✅ feat(auth): fix JWT token expiration edge case
101+
102+
From output start to output end, strictly follow this format:
103+
<feat|fix|docs|style|refactor|test|build|ci|perf|chore|revert>(scope): <subject>`;
104+
105+
if (multiline) {
106+
prompt += `
107+
108+
<body>`;
109+
}
110+
111+
if (keepCoAuthoredBy) {
112+
prompt += `
113+
114+
<footer>`;
115+
}
116+
117+
if (multiline) {
118+
prompt += `
119+
120+
- Body allows multiline output
121+
`;
122+
}
123+
68124
if (customPrompt) {
69-
prompt += `\n\nAdditional requirements: ${customPrompt}`;
125+
prompt += `
126+
127+
- Additional requirements: ${customPrompt}`;
70128
}
129+
71130
if (keepCoAuthoredBy) {
72131
prompt += `
73132
74-
Keep at the end of commit message:
133+
Keep at the end of footer:
75134
🤖 Generated with Claude Code
76135
Co-Authored-By: Claude <noreply@anthropic.com>`;
77136
}
137+
78138
return prompt;
79139
}
80140

‎src/prompts/generation.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export function createGenerationPrompt(
1515
return module.getGenerationPrompt(diff, stats, multiLine);
1616
}
1717

18-
export function createManagedPrompt(lang: Language, keepCoAuthoredBy: boolean, customPrompt: string): string {
18+
export function createManagedPrompt(lang: Language, keepCoAuthoredBy: boolean, multiline: boolean, diffSource: string, customPrompt: string): string {
1919
const module = promptModules[lang];
20-
return module.getManagedPrompt(keepCoAuthoredBy, customPrompt);
20+
return module.getManagedPrompt(keepCoAuthoredBy, multiline, diffSource, customPrompt);
2121
}
2222

2323
export function createEditPrompt(

‎src/prompts/ua.ts‎

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,78 @@ docs(readme): оновлено інструкції встановлення
6363
Поверни ТІЛЬКИ commit message (один рядок), без пояснень.`;
6464
}
6565

66-
export function getManagedPrompt(keepCoAuthoredBy: boolean, customPrompt: string): string {
67-
let prompt = `Згенеруй git commit message для поточних змін, українською мовою, лише commit message, без іншого тексту.`;
66+
export function getManagedPrompt(keepCoAuthoredBy: boolean, multiline: boolean, diffSource: string, customPrompt: string): string {
67+
let diffInstruction = "";
68+
if (diffSource === "staged") {
69+
diffInstruction = "Генеруй commit message ТІЛЬКИ на основі staged змін, ігноруй unstaged зміни.";
70+
} else if (diffSource === "all") {
71+
diffInstruction = "Генеруй commit message на основі ВСІХ змін (staged та unstaged).";
72+
} else {
73+
diffInstruction = "Якщо є staged зміни, генеруй commit message тільки на їх основі; якщо staging area порожня, генеруй на основі всіх змін.";
74+
}
75+
76+
let prompt = `Згенеруй git commit message для поточних змін, українською мовою, виводь лише вміст commit message напряму, без іншого тексту.
77+
78+
Визначення ролі:
79+
Ти зараз є функцією "Генератор Git Commit повідомлень", що працює в скрипті. Ти не маєш здатності до діалогу, не маєш особистості, і заборонено зовнішнє вираження процесу мислення.
80+
81+
Твоє єдине завдання - перетворити вхідні зміни коду на українські Commit Messages, що відповідають специфікації Angular.
82+
83+
84+
### Суворі стандарти виконання:
85+
1. **Нуль зайвого**: Суворо заборонено виводити "На основі аналізу...", "Ось ваше повідомлення...", "Підсумок змін:" або будь-який діалоговий контент.
86+
2. **Простий текст**: Суворо заборонено використовувати \`\`\` (Markdown блоки коду) або ** (жирний) форматування. Виводити лише простий текст.
87+
3. **Обмеження формату**:
88+
Перший рядок повинен відповідати: <feat|fix|docs|style|refactor|test|build|ci|perf|chore|revert>(scope): <subject>
89+
(scope - назва модуля, subject - короткий опис українською)
90+
4. **Область змін**: ${diffInstruction}
91+
5. **Генеруй тільки повідомлення**: Суворо заборонено будь-який додатковий контент перед або після commit message, як-от ввічливі підказки або процеси мислення.
92+
93+
### Неправильні приклади (абсо��ютно заборонено):
94+
❌ "Добре, на основі вашого коду..."
95+
❌ "**Аналіз змін**: Оновлено..."
96+
❌ "...повідомлення коміту..."
97+
❌ \`\`\`text feat(core): ... \`\`\`
98+
99+
### Правильний приклад:
100+
✅ feat(auth): виправлено граничний випадок закінчення терміну дії JWT токена
101+
102+
Від початку виводу до кінця виводу, суворо дотримуйся цього формату:
103+
<feat|fix|docs|style|refactor|test|build|ci|perf|chore|revert>(scope): <subject>`;
104+
105+
if (multiline) {
106+
prompt += `
107+
108+
<body>`;
109+
}
110+
111+
if (keepCoAuthoredBy) {
112+
prompt += `
113+
114+
<footer>`;
115+
}
116+
117+
if (multiline) {
118+
prompt += `
119+
120+
- Body дозволяє багаторядковий вивід
121+
`;
122+
}
123+
68124
if (customPrompt) {
69-
prompt += `\n\nДодаткові вимоги: ${customPrompt}`;
125+
prompt += `
126+
127+
- Додаткові вимоги: ${customPrompt}`;
70128
}
129+
71130
if (keepCoAuthoredBy) {
72131
prompt += `
73132
74-
В кінці commit message додай:
133+
В кінці footer додай:
75134
🤖 Generated with Claude Code
76135
Co-Authored-By: Claude <noreply@anthropic.com>`;
77136
}
137+
78138
return prompt;
79139
}
80140

‎src/prompts/zh.ts‎

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,78 @@ docs(readme): 更新了安装说明
6363
仅返回 commit message(一行),不要有任何解释。`;
6464
}
6565

66-
export function getManagedPrompt(keepCoAuthoredBy: boolean, customPrompt: string): string {
67-
let prompt = `为当前改动生成git commit message,使用中文,仅输出commit message内容,不要有其他多余输出。`;
66+
export function getManagedPrompt(keepCoAuthoredBy: boolean, multiline: boolean, diffSource: string, customPrompt: string): string {
67+
let diffInstruction = "";
68+
if (diffSource === "staged") {
69+
diffInstruction = "仅根据暂存区(staged)的改动生成commit message,忽略未暂存的改动。";
70+
} else if (diffSource === "all") {
71+
diffInstruction = "根据所有改动(包括暂存和未暂存)生成commit message。";
72+
} else {
73+
diffInstruction = "如果暂存区有改动,仅根据暂存区改动生成commit message;如果暂存区为空,则根据所有改动生成commit message。";
74+
}
75+
76+
let prompt = `为当前改动生成git commit message,使用中文,直接输出commit message内容,不要有其他多余输出。
77+
78+
角色定义:
79+
你现在是一个运���在脚本中的"Git Commit 消息生成器"函数。你没有对话能力,没有个性,禁止思考过程的外显。
80+
81+
你的唯一任务是将输入的代码变动转换为符合 Angular 规范的中文 Commit Message。
82+
83+
84+
### 严格执行标准:
85+
1. **零废话**:严禁输出 "根据分析..."、"这是您的消息..."、"改动总结:" 等任何对话内容。
86+
2. **纯文本**:严禁使用 \`\`\` (Markdown代码块) 或 ** (加粗) 等格式。只输出纯文本。
87+
3. **格式约束**:
88+
第一行必须符合:<feat|fix|docs|style|refactor|test|build|ci|perf|chore|revert>(scope): <subject>
89+
(scope为模块名,subject用中文简述)
90+
4. **改动范围**:${diffInstruction}
91+
5. **仅生成message**: 在commit message 前后禁止输出任何多余的内容,如礼貌性的提示和思考过程。
92+
93+
### 错误示例 (绝对禁止):
94+
❌ "好的,根据您的代码..."
95+
❌ "**改动分析**:更新了..."
96+
❌ "...提交信息..."
97+
❌ \`\`\`text feat(core): ... \`\`\`
98+
99+
### 正确示例:
100+
✅ feat(auth): 修复JWT令牌过���的边界情况
101+
102+
从输出开始到输出结束,需严格遵循以下格式:
103+
<feat|fix|docs|style|refactor|test|build|ci|perf|chore|revert>(scope): <subject>`;
104+
105+
if (multiline) {
106+
prompt += `
107+
108+
<body>`;
109+
}
110+
111+
if (keepCoAuthoredBy) {
112+
prompt += `
113+
114+
<footer>`;
115+
}
116+
117+
if (multiline) {
118+
prompt += `
119+
120+
- Body允许使用多行输出
121+
`;
122+
}
123+
68124
if (customPrompt) {
69-
prompt += `\n\n额外要求:${customPrompt}`;
125+
prompt += `
126+
127+
- 额外要求:${customPrompt}`;
70128
}
129+
71130
if (keepCoAuthoredBy) {
72131
prompt += `
73132
74-
commit message 末��保留:
133+
footer 末尾保留:
75134
🤖 Generated with Claude Code
76135
Co-Authored-By: Claude <noreply@anthropic.com>`;
77136
}
137+
78138
return prompt;
79139
}
80140

0 commit comments

Comments
 (0)