Skip to content

Commit 9987a68

Browse files
committed
Defer context file prompts in commit message generation and filter ignored files
- In the commit message generation flow, we currently attach the full content of changed files (and context files) to the prompt even when those files would be excluded from normal chat context — e.g. lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, etc. via IGNORED_LOCK_FILES), files matched by codeWebChat.ignorePatterns, or gitignored files. Fix this so ignored files never get their full content attached, while keeping their diffs intact. - Whether to include context files or skip, should be shown after selecting action (because it doesn't apply to 'enter manually' action) ├── apps │ └── editor │ └── src │ ├── commands │ │ ├── apply-response-command │ │ │ └── utils │ │ │ └── preview │ │ │ ├── index.ts │ │ │ └── vscode-ui.ts │ │ └── generate-commit-message-commands │ │ ├── actions │ │ │ ├── get-prompt-data.ts │ │ │ └── run-generate-action.ts │ │ ├── generate-commit-message-commands.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 │ │ └── values.ts │ ├── context │ │ ├── context-initialization.ts │ │ ├── helpers │ │ │ ├── get-all-workspace-files.ts │ │ │ └── get-selected-files.ts │ │ ├── providers │ │ │ ├── open-editors │ │ │ │ └── open-editors-provider.ts │ │ │ ├── selected-files │ │ │ │ └── selected-files-provider.ts │ │ │ └── workspace │ │ │ ├── modules │ │ │ │ ├── index.ts │ │ │ │ └── token-calculator.ts │ │ │ └── workspace-provider.ts │ │ ├── shared-context-state.ts │ │ └── utils │ │ └── shrink-file │ │ ├── index.ts │ │ ├── languages │ │ │ ├── c-style.ts │ │ │ ├── css.ts │ │ │ ├── html.ts │ │ │ ├── jsx.ts │ │ │ ├── python.ts │ │ │ ├── ruby.ts │ │ │ └── sql.ts │ │ ├── shrink-file.spec.ts │ │ ├── shrink-file.ts │ │ └── test-cases │ │ ├── c-style │ │ │ ├── input.txt │ │ │ └── output.txt │ │ ├── css │ │ │ ├── input.txt │ │ │ └── output.txt │ │ ├── html │ │ │ ├── input.txt │ │ │ └── output.txt │ │ ├── jsx │ │ │ ├── input.txt │ │ │ └── output.txt │ │ ├── python │ │ │ ├── input.txt │ │ │ └── output.txt │ │ ├── ruby │ │ │ ├── input.txt │ │ │ └── output.txt │ │ ├── scss │ │ │ ├── input.txt │ │ │ └── output.txt │ │ └── sql │ │ ├── input.txt │ │ └── output.txt │ ├── features │ │ └── checkpoints │ │ └── actions │ │ ├── create-checkpoint.ts │ │ └── index.ts │ ├── i18n │ │ └── index.ts │ ├── services │ │ ├── model-providers-manager.ts │ │ └── websocket-manager.ts │ ├── utils │ │ ├── apply-reasoning-effort.ts │ │ ├── ascii-tree │ │ │ ├── ascii-tree.ts │ │ │ └── index.ts │ │ ├── commit-message-details.ts │ │ ├── files-collector.ts │ │ ├── git-repository-utils.ts │ │ ├── normalize-path.ts │ │ ├── prompt-builder.ts │ │ ├── send-llm-message.ts │ │ ├── show-configuration-quick-pick.ts │ │ └── show-no-configurations-warning.ts │ └── views │ └── prompt │ └── backend │ └── prompt-view-provider.ts └── packages └── shared └── src ├── constants │ ├── chatbots.ts │ └── dictionary.ts └── utils ├── display-token-count.ts └── logger.ts
1 parent f5957b1 commit 9987a68

3 files changed

Lines changed: 212 additions & 197 deletions

File tree

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

Lines changed: 25 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import { CommitMessageDetails } from '../../../utils/commit-message-details'
99
import { normalize_path } from '@/utils/normalize-path'
1010
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
1111
import { FilesCollector } from '@/utils/files-collector'
12-
import { t } from '@/i18n'
13-
import { display_token_count } from '@shared/utils/display-token-count'
14-
import { LAST_USE_CONTEXT_FILES_STATE_KEY } from '@/constants/state-keys'
1512

1613
export const get_prompt_data = async (params: {
1714
repository: GitRepository
@@ -117,185 +114,40 @@ export const get_prompt_data = async (params: {
117114
return normalize_path(path.relative(workspace_root, f))
118115
})
119116

120-
let api_prompt = ''
121-
let chatbot_prompt = ''
122-
let was_context_prompt_shown = false
123-
124-
if (ordered_context_files.length > 0 && !params.skip_context_prompt) {
125-
const setting = vscode.workspace
126-
.getConfiguration('codeWebChat')
127-
.get<string>('useContextFilesInCommitMessagePrompt', 'ask')
128-
129-
if (setting === 'always') {
130-
const prompt = await build_commit_message_prompt(
131-
diff,
132-
params.repository,
133-
ordered_context_files
134-
)
135-
api_prompt = prompt.api_prompt
136-
chatbot_prompt = prompt.chatbot_prompt
137-
} else if (setting === 'ask') {
138-
const prompt_with_context = await build_commit_message_prompt(
139-
diff,
140-
params.repository,
141-
ordered_context_files
142-
)
143-
144-
const prompt_without_context = await build_commit_message_prompt(
145-
diff,
146-
params.repository,
147-
[]
148-
)
149-
150-
const skip_tokens = Math.ceil(
151-
prompt_without_context.api_prompt.length / 4
152-
)
153-
const additional_tokens =
154-
Math.ceil(prompt_with_context.api_prompt.length / 4) - skip_tokens
155-
156-
const attach_label = t(
157-
'command.generate-commit-message.attach-context-files.attach'
158-
)
159-
const skip_label = t(
160-
'command.generate-commit-message.attach-context-files.skip'
161-
)
162-
const last_selected_id =
163-
params.extension_context.workspaceState.get<string>(
164-
LAST_USE_CONTEXT_FILES_STATE_KEY,
165-
'attach'
166-
)
167-
168-
const show_back_button =
169-
was_empty_stage && !is_single_change && !params.stage_all_if_none_staged
170-
171-
was_context_prompt_shown = true
172-
173-
const answer = await new Promise<string | undefined | 'back'>(
174-
(resolve) => {
175-
const quick_pick = vscode.window.createQuickPick<
176-
vscode.QuickPickItem & { id: string }
177-
>()
178-
quick_pick.items = [
179-
{
180-
label: skip_label,
181-
description: `${display_token_count(skip_tokens)} tokens`,
182-
id: 'skip'
183-
},
184-
{
185-
label: attach_label,
186-
description: `+${display_token_count(additional_tokens)} tokens`,
187-
id: 'attach'
188-
}
189-
]
190-
quick_pick.activeItems = [
191-
quick_pick.items.find((i) => i.id === last_selected_id) ||
192-
quick_pick.items[1]
193-
]
194-
quick_pick.title = t(
195-
'command.generate-commit-message.attach-context-files.title'
196-
)
197-
quick_pick.placeholder = t(
198-
'command.generate-commit-message.attach-context-files.placeholder'
199-
)
200-
quick_pick.ignoreFocusOut = true
201-
const close_button = {
202-
iconPath: new vscode.ThemeIcon('close'),
203-
tooltip: t('common.close')
204-
}
205-
quick_pick.buttons = [
206-
...(show_back_button ? [vscode.QuickInputButtons.Back] : []),
207-
close_button
208-
]
209-
210-
let is_resolved = false
211-
212-
quick_pick.onDidTriggerButton((button) => {
213-
if (button === vscode.QuickInputButtons.Back) {
214-
is_resolved = true
215-
resolve('back')
216-
quick_pick.hide()
217-
} else if (button === close_button) {
218-
is_resolved = true
219-
resolve(undefined)
220-
quick_pick.hide()
221-
}
222-
})
223-
224-
quick_pick.onDidAccept(() => {
225-
is_resolved = true
226-
resolve(quick_pick.selectedItems[0]?.id)
227-
quick_pick.hide()
228-
})
229-
230-
quick_pick.onDidHide(() => {
231-
if (!is_resolved) {
232-
resolve(undefined)
233-
}
234-
quick_pick.dispose()
235-
})
236-
237-
quick_pick.show()
238-
}
239-
)
240-
241-
if (answer === 'back') {
242-
if (was_empty_stage) {
243-
await vscode.commands.executeCommand(
244-
'git.unstageAll',
245-
params.repository
246-
)
247-
}
248-
return 'back'
249-
}
250-
251-
if (answer === undefined) {
252-
if (was_empty_stage) {
253-
await vscode.commands.executeCommand(
254-
'git.unstageAll',
255-
params.repository
256-
)
257-
}
258-
return null
259-
}
260-
261-
params.extension_context.workspaceState.update(
262-
LAST_USE_CONTEXT_FILES_STATE_KEY,
263-
answer
264-
)
117+
const prompt_without_context = await build_commit_message_prompt(
118+
diff,
119+
params.repository,
120+
[],
121+
params.workspace_provider
122+
)
265123

266-
if (answer === 'attach') {
267-
api_prompt = prompt_with_context.api_prompt
268-
chatbot_prompt = prompt_with_context.chatbot_prompt
269-
} else {
270-
api_prompt = prompt_without_context.api_prompt
271-
chatbot_prompt = prompt_without_context.chatbot_prompt
272-
}
273-
} else {
274-
const prompt = await build_commit_message_prompt(
275-
diff,
276-
params.repository,
277-
[]
278-
)
279-
api_prompt = prompt.api_prompt
280-
chatbot_prompt = prompt.chatbot_prompt
281-
}
282-
} else {
283-
const prompt = await build_commit_message_prompt(
124+
let prompt_with_context:
125+
| { api_prompt: string; chatbot_prompt: string }
126+
| undefined = undefined
127+
const setting = vscode.workspace
128+
.getConfiguration('codeWebChat')
129+
.get<string>('useContextFilesInCommitMessagePrompt', 'ask')
130+
131+
if (
132+
ordered_context_files.length > 0 &&
133+
!params.skip_context_prompt &&
134+
setting !== 'never'
135+
) {
136+
prompt_with_context = await build_commit_message_prompt(
284137
diff,
285138
params.repository,
286-
[]
139+
ordered_context_files,
140+
params.workspace_provider
287141
)
288-
api_prompt = prompt.api_prompt
289-
chatbot_prompt = prompt.chatbot_prompt
290142
}
291143

292144
return {
293145
repository: params.repository,
294146
was_empty_stage,
295-
api_prompt,
296-
chatbot_prompt,
147+
prompt_without_context,
148+
prompt_with_context,
149+
setting,
297150
is_single_change,
298-
staged_files: diff_file_paths,
299-
was_context_prompt_shown
151+
staged_files: diff_file_paths
300152
}
301153
}

0 commit comments

Comments
 (0)