Skip to content

Commit 348c004

Browse files
committed
Split commit message prompts into separate API and chatbot versions
- for chatbots, should use commit_message_format at both ends divided with '---' with 'commit message instructions' placed below it. └── apps └── editor └── src ├── commands │ ├── code-at-cursor-command │ │ └── utils │ │ └── get-code-at-cursor-config.ts │ └── generate-commit-message-command │ ├── actions │ │ ├── get-prompt-data.ts │ │ └── run-generate-action.ts │ ├── generate-commit-message-command.ts │ ├── index.ts │ └── utils │ ├── build-commit-message-prompt.ts │ ├── generate-commit-message-with-api.ts │ ├── get-commit-message-config.ts │ └── strip-wrapping-quotes.ts ├── constants │ ├── instructions.ts │ └── state-keys.ts ├── features │ └── search-files │ └── utils │ └── search-files-by-intelligent.ts ├── i18n │ └── translations │ └── commands │ └── generate-commit-message.ts ├── utils │ └── show-configuration-quick-pick.ts └── views └── prompt └── backend └── message-handlers ├── handle-autofill.ts ├── handle-make-api-call.ts ├── handle-voice-input.ts └── utils └── intelligent-update-utils.ts
1 parent 81f1d5b commit 348c004

5 files changed

Lines changed: 22 additions & 17 deletions

File tree

‎apps/editor/src/commands/generate-commit-message-command/actions/get-prompt-data.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const get_prompt_data = async (params: {
2222
selection_state: params.selection_state
2323
})
2424
if (!diff) return null
25-
const message_prompt = await build_commit_message_prompt(
25+
const { api_prompt, chatbot_prompt } = await build_commit_message_prompt(
2626
diff,
2727
params.repository
2828
)
@@ -61,7 +61,8 @@ export const get_prompt_data = async (params: {
6161
return {
6262
repository: params.repository,
6363
was_empty_stage,
64-
message_prompt,
64+
api_prompt,
65+
chatbot_prompt,
6566
is_single_change,
6667
staged_files: diff_file_paths
6768
}

‎apps/editor/src/commands/generate-commit-message-command/actions/run-generate-action.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ export const run_generate_action = async (params: {
5252
selection_state
5353
})
5454
if (!data) return
55-
const { message_prompt, is_single_change, staged_files } = data
55+
const { api_prompt, chatbot_prompt, is_single_change, staged_files } = data
5656
let { was_empty_stage } = data
5757

5858
// token count for the prompt, used in the config UI
59-
const token_count = Math.ceil(message_prompt.length / 4)
59+
const token_count = Math.ceil(api_prompt.length / 4)
6060

6161
if (was_empty_stage) {
6262
files_staged_by_action = true
@@ -192,7 +192,7 @@ export const run_generate_action = async (params: {
192192
)
193193

194194
if (action === 'copy') {
195-
await vscode.env.clipboard.writeText(message_prompt)
195+
await vscode.env.clipboard.writeText(chatbot_prompt)
196196
vscode.window.showInformationMessage(
197197
t('command.generate-commit-message.copied', {
198198
tokens: display_token_count(token_count)
@@ -295,7 +295,7 @@ export const run_generate_action = async (params: {
295295

296296
if (selected_web_configuration_name) {
297297
const sent = await params.websocket_manager.initialize_chat({
298-
text: message_prompt,
298+
text: chatbot_prompt,
299299
web_configuration_name: selected_web_configuration_name,
300300
invocation_count: 1,
301301
is_for_commit_message: true
@@ -342,7 +342,7 @@ export const run_generate_action = async (params: {
342342
base_url: api_configuration_data.base_url,
343343
model_provider: api_configuration_data.model_provider,
344344
api_configuration: api_configuration_data.api_configuration,
345-
message: message_prompt
345+
message: api_prompt
346346
})
347347
} catch (error) {
348348
if (axios.isCancel(error)) {

‎apps/editor/src/commands/generate-commit-message-command/utils/build-commit-message-prompt.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as vscode from 'vscode'
2-
import { commit_message_instructions } from '@/constants/instructions'
2+
import {
3+
commit_message_instructions,
4+
commit_message_format
5+
} from '@/constants/instructions'
36
import type { GitRepository } from '@/utils/git-repository-utils'
47
import { MAX_FILE_TOKENS_FOR_COMMIT_MESSAGE } from '@/constants/values'
58
import { PromptBuilder } from '@/utils/prompt-builder'
69

710
export const build_commit_message_prompt = async (
811
diff: string,
912
repository: GitRepository
10-
): Promise<string> => {
13+
): Promise<{ api_prompt: string; chatbot_prompt: string }> => {
1114
const config = vscode.workspace.getConfiguration('codeWebChat')
1215
const instructions = config.get<string>('commitMessageInstructions')
1316
const commit_message_prompt = instructions || commit_message_instructions
@@ -124,5 +127,8 @@ export const build_commit_message_prompt = async (
124127
}
125128
}
126129

127-
return `${commit_message_prompt}\n\n---\n\n${changes_content}---\n\n${commit_message_prompt}`
130+
const api_prompt = `# Task\n\n${commit_message_prompt}\n\n# Files\n\n${changes_content}\n\n# Task\n\n${commit_message_prompt}`
131+
const chatbot_prompt = `# Task\n\n${commit_message_prompt}\n\n# Output formatting\n\n${commit_message_format}\n\n# Files\n\n${changes_content}\n\n# Output formatting\n\n${commit_message_format}\n\n# Task\n\n${commit_message_prompt}`
132+
133+
return { api_prompt, chatbot_prompt }
128134
}

‎apps/editor/src/constants/instructions.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ export const intelligent_update_fallback_edit_format_instructions = `Print the u
5050
export const commit_message_instructions =
5151
"Write a brief and precise summary for the changes, limited to a single sentence. Because the summary will be used for a commit message, don't use any markdown formatting and don't include a trailing dot. Use an imperative tone to ensure clarity and focus on the primary change or purpose."
5252

53-
export const commit_message_format = `# Output formatting
54-
55-
Your response must begin with "**Commit message:**", then proceed with the message. Example:
53+
export const commit_message_format = `Your response must begin with "**Commit message:**", then proceed with the message. Example:
5654
5755
**Commit message:** Bump version to 1.0.1`
5856

‎apps/editor/src/utils/prompt-builder.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ export namespace PromptBuilder {
2222
const display_path = params.filepath.replace(/\\/g, '/')
2323

2424
if (params.status == 'created') {
25-
result += `### New file: \`${display_path}\`\n\n`
25+
result += `- New file: \`${display_path}\`\n\n`
2626
} else if (params.status == 'deleted') {
27-
result += `### Deleted file: \`${display_path}\`\n\n`
27+
result += `- Deleted file: \`${display_path}\`\n\n`
2828
} else if (params.status == 'renamed' && params.old_filepath) {
2929
const old_display_path = params.old_filepath.replace(/\\/g, '/')
30-
result += `### Renamed file: \`${old_display_path}\` (old) \`${display_path}\` (new)\n\n`
30+
result += `- Renamed file: \`${old_display_path}\` (old) \`${display_path}\` (new)\n\n`
3131
} else {
32-
result += `### Updated file: \`${display_path}\`\n\n`
32+
result += `- Updated file: \`${display_path}\`\n\n`
3333
}
3434

3535
if (params.diff_content?.trimEnd()) {

0 commit comments

Comments
 (0)