Skip to content

Prompts

Prompt templates for commit message generation.

COMMIT_SYSTEM_PROMPT module-attribute

COMMIT_SYSTEM_PROMPT = "\nYou are an AI assistant knowledgeable in Git best practices.\nYou are tasked with generating Conventional Commit 1.0.0 messages from Git diffs.\nFollow the user's requirements carefully and to the letter.\nYour response must be a valid JSON object matching the provided schema.\n"

DEFAULT_PROMPT_TEMPLATE module-attribute

DEFAULT_PROMPT_TEMPLATE = '\n**Instructions & Rules:**\n\n1.  **Type:** REQUIRED. Must be lowercase and one of: {convention.types}.\n    *   `feat`: New feature (MINOR SemVer).\n    *   `fix`: Bug fix (PATCH SemVer).\n    *   Other types (`build`, `chore`, `ci`, `docs`, `style`, `refactor`, `perf`, `test`, etc.) are allowed.\n2.  **Scope:** OPTIONAL. Lowercase noun(s) in parentheses describing the code section (e.g., `(parser)`).\n    *   Keep short (1-2 words).\n3.  **Description:** REQUIRED. Concise, imperative, present tense summary of *what* changed and *why* based on the diff.\n    *   Must follow the colon and space.\n    *   Must be >= 10 characters.\n    *   Must NOT end with a period.\n    *   The entire header line (`<type>[scope]: <description>`) must be <= {convention.max_length} characters.\n4.  **Body:** OPTIONAL. Explain *why* and *how*. Start one blank line after the description.\n\t*\tUse the body only if extra context is needed to understand the changes.\n\t*\tDo not use the body to add unrelated information.\n\t*\tDo not use the body to explain *what* was changed.\n\t*\tTry to keep the body concise and to the point.\n5.  **Footer(s):** OPTIONAL. Format `Token: value` or `Token # value`.\n    *   Start one blank line after the body.\n    *   Use `-` for spaces in tokens (e.g., `Reviewed-by`).\n6.  **BREAKING CHANGE:** Indicate with `!` before the colon in the header (e.g., `feat(api)!: ...`)\n    *   OR with a `BREAKING CHANGE: <description>` footer (MUST be uppercase).\n    *   Correlates with MAJOR SemVer.\n    *   If `!` is used, the description explains the break.\n7.  **Special Case - Binary Files:**\n    *   For binary file changes, use `chore` type with a scope indicating the file type (e.g., `(assets)`, `(images)`, `(builds)`)\n    *   Be specific about what changed (e.g., "update image assets", "add new icon files", "replace binary database")\n    *   If the diff content is empty or shows binary file changes, focus on the filenames to determine the purpose\n\n**Commit Message Format:**\n```\n<type>[optional scope]: <description>\n\n[optional body]\n\n[optional footer(s)]\n```\n\n**File Summary:**\n{files_summary}\n\n**Git diff:**\n{diff}\n\n**Output Requirements:**\n\n**(IMPORTANT) STRICTLY OMIT footers: `Related Issue #`, `Closes #`, `REVIEWED-BY`, `TRACKING #`, `APPROVED`.\n\n**(IMPORTANT) Following JSON Schema must be followed for Output:**\n{schema}\n\n---\nPlease analyze the `Git diff` and `File Summary` and create a valid commit message.\nReturn your answer as json.\n'

MOVE_CONTEXT module-attribute

MOVE_CONTEXT = "\n---\nThis diff group contains file moves. Here is the list of files that are relocated:\n{files}\n\nThese files are moved from {source_dir} to {target_dir}.\n"

get_lint_prompt_template

get_lint_prompt_template() -> str

Get the prompt template for lint feedback.

Returns:

Type Description
str

The prompt template with lint feedback placeholders

Source code in src/codemap/git/commit_generator/prompts.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def get_lint_prompt_template() -> str:
	"""
	Get the prompt template for lint feedback.

	Returns:
	    The prompt template with lint feedback placeholders

	"""
	return """
You are a helpful assistant that fixes conventional commit messages that have linting errors.

1. The conventional commit format is:
```
<type>[optional scope]: <description>

[optional body]

[optional footer(s)]
```
2. Types include: {convention.types}
3. Scope must be short (1-2 words), concise, and represent the specific component affected
4. The description should be a concise, imperative present tense summary of the code changes,
   focusing on *what* was changed and *why*.
5. The optional body should focus on the *why* and *how* of the changes.

IMPORTANT: The provided commit message has the following issues:
{lint_feedback}

Original commit message:
{original_message}

Brief file context (without full diff):
{files_summary}

Please fix these issues and ensure the generated message adheres to the commit convention.

IMPORTANT:
- Strictly follow the format <type>[optional scope]: <description>
- Do not include any other text, explanation, or surrounding characters
- Do not include any `Related Issue #`, `Closes #`, `REVIEWED-BY`, `TRACKING #`, `APPROVED` footers.
- Respond with a valid JSON object following this schema:

{schema}

Return your answer as json.
"""

file_info_to_human_summary

file_info_to_human_summary(
	file_info: dict[str, Any],
) -> str

Convert file_info dict to a human-readable summary (used in both initial and regeneration prompts).

Parameters:

Name Type Description Default
file_info dict[str, Any]

Dictionary with information about files

required

Returns:

Type Description
str

Human-readable summary string

Source code in src/codemap/git/commit_generator/prompts.py
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def file_info_to_human_summary(file_info: dict[str, Any]) -> str:
	"""
	Convert file_info dict to a human-readable summary (used in both initial and regeneration prompts).

	Args:
	    file_info: Dictionary with information about files

	Returns:
	    Human-readable summary string
	"""
	files_summary = []
	for file_path, info in file_info.items():
		extension = info.get("extension", "")
		directory = info.get("directory", "")
		module = info.get("module", "")
		summary = f"- {file_path} ({extension} file in {directory})"
		if module:
			summary += f", part of {module} module"
		files_summary.append(summary)
	return "\n".join(files_summary) if files_summary else "No file information available"

prepare_prompt

prepare_prompt(
	template: str,
	diff_content: str,
	file_info: dict[str, Any],
	config_loader: ConfigLoader,
	extra_context: dict[str, Any] | None = None,
) -> str

Prepare the prompt for the LLM.

Parameters:

Name Type Description Default
template str

Prompt template to use

required
diff_content str

Diff content to include

required
file_info dict[str, Any]

Information about files in the diff

required
config_loader ConfigLoader

ConfigLoader instance to use for configuration

required
extra_context dict[str, Any] | None

Optional additional context values for the template

None

Returns:

Type Description
str

Formatted prompt

Source code in src/codemap/git/commit_generator/prompts.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def prepare_prompt(
	template: str,
	diff_content: str,
	file_info: dict[str, Any],
	config_loader: ConfigLoader,
	extra_context: dict[str, Any] | None = None,
) -> str:
	"""
	Prepare the prompt for the LLM.

	Args:
	    template: Prompt template to use
	    diff_content: Diff content to include
	    file_info: Information about files in the diff
	    config_loader: ConfigLoader instance to use for configuration
	    extra_context: Optional additional context values for the template

	Returns:
	    Formatted prompt

	"""
	context = {
		"diff": diff_content,
		# Use human-readable summary for files
		"files_summary": file_info_to_human_summary(file_info),
		"convention": config_loader.get.commit.convention,
		"schema": CommitMessageSchema,
	}

	# Add any extra context values
	if extra_context:
		context.update(extra_context)

	try:
		return template.format(**context)
	except KeyError as e:
		msg = f"Prompt template formatting error. Missing key: {e}"
		raise ValueError(msg) from e

prepare_lint_prompt

prepare_lint_prompt(
	template: str,
	file_info: dict[str, Any],
	config_loader: ConfigLoader,
	lint_messages: list[str],
	original_message: str | None = None,
) -> str

Prepare a prompt with lint feedback for regeneration.

Parameters:

Name Type Description Default
template str

Prompt template to use

required
file_info dict[str, Any]

Information about files in the diff

required
config_loader ConfigLoader

ConfigLoader instance to use for configuration

required
lint_messages list[str]

List of linting error messages

required
original_message str | None

The original failed commit message

None

Returns:

Type Description
str

Enhanced prompt with linting feedback

Source code in src/codemap/git/commit_generator/prompts.py
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
def prepare_lint_prompt(
	template: str,
	file_info: dict[str, Any],
	config_loader: ConfigLoader,
	lint_messages: list[str],
	original_message: str | None = None,
) -> str:
	"""
	Prepare a prompt with lint feedback for regeneration.

	Args:
	    template: Prompt template to use
	    file_info: Information about files in the diff
	    config_loader: ConfigLoader instance to use for configuration
	    lint_messages: List of linting error messages
	    original_message: The original failed commit message

	Returns:
	    Enhanced prompt with linting feedback

	"""
	# Create specific feedback for linting issues
	lint_feedback = "\n".join([f"- {msg}" for msg in lint_messages])

	# Use the shared summary function
	files_summary_text = file_info_to_human_summary(file_info)

	# If original_message wasn't provided, use a placeholder
	message_to_fix = original_message or "No original message provided"

	# Create an enhanced context with linting feedback
	context = {
		"convention": config_loader.get.commit.convention,
		"schema": CommitMessageSchema,
		"lint_feedback": lint_feedback,
		"original_message": message_to_fix,
		"files_summary": files_summary_text,
	}

	try:
		return template.format(**context)
	except KeyError as e:
		msg = f"Lint prompt template formatting error. Missing key: {e}"
		raise ValueError(msg) from e