Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Commit 03530ff

Browse files
committed
feat(#4): Refactor AnthropicClient and add system prompt
- Add `systemPrompt` parameter to `createMessage` method in `AnthropicClient` * Allows setting a system prompt for the Anthropic API * System prompt is used to provide context for the AI model - Update `analyzeCommitStyle` function to accept an optional `systemPrompt` parameter * Passes the system prompt to the `createMessage` method of `AnthropicClient` * Allows customizing the system prompt for the commit style analysis BREAKING CHANGE: The `createMessage` method in `AnthropicClient` now requires a `systemPrompt` parameter.
1 parent a6eb528 commit 03530ff

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

src/ai/anthropicClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ export class AnthropicClient {
77
this.apiKey = apiKey;
88
}
99

10-
async createMessage(content: string, model: string = "claude-3-haiku-20240307"): Promise<string> {
10+
async createMessage(systemPrompt: string, content: string, model: string = "claude-3-haiku-20240307"): Promise<string> {
1111
const anthropic = new Anthropic({ apiKey: this.apiKey });
1212

1313
const msg = await anthropic.messages.create({
1414
model,
1515
max_tokens: 1024,
1616
temperature: 0,
17+
system: systemPrompt,
1718
messages: [{ role: "user", content }],
1819
});
1920

src/ai/commitStyleAnalyzer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AnthropicClient } from "./anthropicClient.ts";
22

3-
export async function analyzeCommitStyle(commits: string, apiKey: string): Promise<string> {
3+
export async function analyzeCommitStyle(systemPrompt: string = `You are an expert in git commit message styling and formatting.`, commits: string, apiKey: string): Promise<string> {
44
const client = new AnthropicClient(apiKey);
55
const content = `Extract commit message rules from these commits. Create a minimal style guide that:
66
@@ -16,5 +16,5 @@ Analyze these commits:
1616
1717
${commits}`;
1818

19-
return await client.createMessage(content);
20-
}
19+
return await client.createMessage(systemPrompt, content);
20+
}

src/ai/getCommitMessage.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ Include the issue ID as a reference according to the commit message format.`;
3838
const client = new AnthropicClient(apiKey);
3939

4040
const content = await client.createMessage(
41+
systemPrompt || `You are an expert in git commit message styling and formatting.`,
4142
`Generate a commit message summarizing ALL key changes from the ENTIRE diff:\n\n${diff}\n\nIMPORTANT:
4243
1. Do not include any explanatory text or formatting
43-
2. Do not make up features, changes, or issue numbers not present in the diff
44-
3. Do not repeat the header line
45-
4. IMPORTANT: NEVER include the diff in the response
46-
5. Do not include "diff --git" or any git output
47-
6. Follow this exact structure:
44+
2. Do not repeat the header line
45+
3. IMPORTANT: NEVER include the diff in the response
46+
4. Do not include "diff --git" or any git output
47+
5. Follow this exact structure:
4848
- One header line
4949
- One blank line
5050
- Bullet points for actual changes
51-
- Breaking changes (if any)`);
51+
- Breaking changes (if any)
52+
6. Do not make up features, changes, or issue numbers not present in the diff`);
5253

5354
// Post-process the message to ensure proper formatting
5455
const lines = content.split('\n').filter(line => line.trim() !== '');

src/gh/ghOps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function searchAndSelectIssue(): Promise<{ number: number, title: s
7474
}
7575

7676
console.log(`\n${COLORS.header("Found issues:")}`);
77-
console.log('┌──────┬────��───┬──────────────────────────────────────────────────────────┐');
77+
console.log('┌──────┬───────┬──────────────────────────────────────────────────────────┐');
7878
console.log('│ Sel# │ ID │ Title │');
7979
console.log('├──────┼────────┼──────────────────────────────────────────────────────────┤');
8080

0 commit comments

Comments
 (0)