From 0697e279caba42d5ce01bf1631903549b0689cd2 Mon Sep 17 00:00:00 2001 From: Hyko Date: Wed, 15 Apr 2026 17:58:45 -0400 Subject: [PATCH] refactor(prompts): extract prompts to dedicated module and enhance instructions --- src/prompts.ts | 26 ++++++++++++++++++++++++++ src/providers.ts | 14 +------------- 2 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 src/prompts.ts diff --git a/src/prompts.ts b/src/prompts.ts new file mode 100644 index 0000000..8ee5920 --- /dev/null +++ b/src/prompts.ts @@ -0,0 +1,26 @@ +export const SYSTEM_PROMPT = + "You are a git commit message generator. Output only the commit message — no explanation, no preamble, no backticks, no quotes. All messages must be written in English." + +export const CONVENTIONAL_INSTRUCTION = `Based on the provided git diff, generate a concise and descriptive commit message following the Conventional Commits format: + + (): + +Types: feat, fix, refactor, style, docs, test, chore, perf, revert +- feat: new feature +- fix: bug fix +- refactor: code restructuring without behavior change +- style: formatting only (spaces, commas, no logic change) +- docs: documentation only +- test: add or update tests +- chore: maintenance, dependencies, build config +- perf: performance improvement +- revert: revert a previous commit (format: revert: revert "") + +Rules: +- Scope is optional, specifies the affected area (e.g. auth, api, storage, ui, config) +- Description: lowercase, no trailing period, in English +- One commit = one intention, do not mix fix and refactor +- For breaking changes, add ! after the type and a BREAKING CHANGE: footer +- Only include a body if there are multiple distinct changes to explain; for a single focused change, output the title only` + +export const SIMPLE_INSTRUCTION = `Based on the provided git diff, generate a short and clear one-line commit message (50-72 characters).` diff --git a/src/providers.ts b/src/providers.ts index 0d0c24d..1ee9e45 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -1,17 +1,5 @@ import * as vscode from "vscode" - -const SYSTEM_PROMPT = - "You are a helpful assistant that generates informative git commit messages based on git diffs output. Skip preamble and remove all backticks surrounding the commit message." - -const CONVENTIONAL_INSTRUCTION = `Based on the provided git diff, generate a concise and descriptive commit message. - -The commit message should: -1. Have a short title (50-72 characters) -2. Follow the Conventional Commits format (feat:, fix:, chore:, docs:, refactor:, test:, style:, etc.) -3. Be clear and informative -4. Only include a body description if there are multiple distinct changes to explain, if the diff represents a single focused change, output the title only` - -const SIMPLE_INSTRUCTION = `Based on the provided git diff, generate a short and clear one-line commit message (50-72 characters).` +import { SYSTEM_PROMPT, CONVENTIONAL_INSTRUCTION, SIMPLE_INSTRUCTION } from "./prompts" export interface AIProvider { generateCommitMessage(diff: string, style: string, signal: AbortSignal): AsyncIterable