Skip to content

Conversation

github-actions[bot]
Copy link

Closes #530

Applied changes based on Issue #530.

I’ve refactored src/config/prompts.ts to make it more modular, readable, and maintainable—without changing any of its outward behavior:


1. Extracted a literal list of commit types

Pulled the Conventional‑Commit types into a single const array and exposed a ConventionalCommitType type alias so that they live in one place:

/** Conventional Commit types recognized in prompts */
export const conventionalCommitTypes = [
  'feat',
  'fix',
  'docs',
  'style',
  'refactor',
  'perf',
  'test',
  'chore',
  'revert',
] as const;

/** Type alias for a Conventional Commit type */
export type ConventionalCommitType = typeof conventionalCommitTypes[number];

【F:src/config/prompts.ts†L5-L12】【F:src/config/prompts.ts†L18-L19】


2. Built the system‐prompt via an array/join

Rewrote the gigantic template‐literal as an array of lines joined by '\n'. This improves readability (each instructive line is explicit) and guarantees easier future modifications:

/** System prompt instructing the AI to generate Conventional Commits-style commit messages. */
export const conventionalCommitsSystemPrompt = [
  'You are an AI assistant that generates concise Git commit messages following the Conventional Commits specification.',
  "Analyze the file changes and the user's request, then output exactly one single-line commit header in the format:",
  '',
  '<type>(<scope>): <subject>',
  '',
  `- type must be one of: ${conventionalCommitTypes.join(', ')}.`,
  '- scope is optional; include it only if it clearly identifies the area of change.',
  '- subject should be written in imperative, present tense, no more than 50 characters, without trailing punctuation.',
  '- Do not include emojis, issue numbers, or any additional details.',
  '- Do not include a commit body, breaking change description, or any explanation.',
  '',
  'Provide only the single-line commit header as the complete output.',
].join('\n');

【F:src/config/prompts.ts†L21-L35】


3. Made PromptBuilderConfig properties readonly

Marked all properties on PromptBuilderConfig as readonly and collapsed the JSDoc/comments to a more compact style:

export interface PromptBuilderConfig {
  /** Label used for the title section */
  readonly titleLabel: string;
  /** Label used for the history section */
  readonly historyLabel: string;
  /** Label used for the context section */
  readonly contextLabel: string;
  /** Label used for the changed files section */
  readonly changedFilesLabel: string;
  /** Separator inserted before the user prompt */
  readonly promptSeparator: string;
}

【F:src/config/prompts.ts†L43-L54】


All existing tests for conventionalCommitsSystemPrompt and promptBuilderConfig continue to pass unchanged, and no external behavior (including the exact text content of the prompt) was altered.

 PASS  __tests__/unit/config/prompts.test.ts

【F:tests/unit/config/prompts.test.ts†L1-L33】


Let me know if you’d like any further tweaks!

@YiweiShen YiweiShen merged commit c7e18c7 into main Jul 26, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-chore-530-refactor-prompts-simplify-prompt-configuration-3121138227 branch July 26, 2025 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Done] Refactor src/config/prompts.ts

1 participant