Skip to content

Commit c29dfde

Browse files
committed
Add utility to filter prompts containing only symbols and apply it to commit message flows
├── apps │ └── editor │ ├── package.json │ └── src │ ├── commands │ │ ├── apply-response-command │ │ │ └── utils │ │ │ └── preview-handler.ts │ │ ├── code-at-cursor-command │ │ │ └── code-at-cursor-commands.ts │ │ └── generate-commit-message-commands │ │ ├── actions │ │ │ ├── get-prompt-data.ts │ │ │ └── run-generate-action.ts │ │ ├── generate-commit-message-commands.ts │ │ └── index.ts │ └── utils │ ├── commit-message-details.ts │ └── git-repository-utils.ts └── packages └── shared └── src └── utils └── simplify-prompt-symbols ├── index.ts ├── simplify-prompt-symbols.spec.ts └── simplify-prompt-symbols.ts
1 parent 4088590 commit c29dfde

5 files changed

Lines changed: 64 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from '@/constants/state-keys'
2323
import { get_prompt_data } from './get-prompt-data'
2424
import { display_token_count } from '@shared/utils/display-token-count'
25+
import { is_prompt_empty_or_only_symbols } from '@shared/utils/simplify-prompt-symbols'
2526
import { show_configurations_quick_pick } from '@/utils/show-configurations-quick-pick'
2627
import { WebSocketManager } from '@/services/websocket-manager'
2728
import { get_response_preview_promise_resolve } from '@/commands/apply-response-command/utils/preview'
@@ -612,10 +613,10 @@ export const run_generate_action = async (params: {
612613
)
613614

614615
const relevant_prompts = all_relevant_prompts.filter(
615-
(p) => p.prompt.trim() != ''
616+
(p) => !is_prompt_empty_or_only_symbols({ prompt: p.prompt })
616617
)
617-
const empty_prompts = all_relevant_prompts.filter(
618-
(p) => p.prompt.trim() == ''
618+
const empty_prompts = all_relevant_prompts.filter((p) =>
619+
is_prompt_empty_or_only_symbols({ prompt: p.prompt })
619620
)
620621

621622
const get_tree_text_if_applicable = async (

‎apps/editor/src/utils/commit-message-details.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as fs from 'fs'
22
import * as path from 'path'
33
import * as vscode from 'vscode'
4-
import { simplify_prompt_symbols } from '@shared/utils/simplify-prompt-symbols'
4+
import {
5+
simplify_prompt_symbols,
6+
is_prompt_empty_or_only_symbols
7+
} from '@shared/utils/simplify-prompt-symbols'
58
import { normalize_path } from './normalize-path'
69

710
export namespace CommitMessageDetails {
@@ -91,10 +94,13 @@ export namespace CommitMessageDetails {
9194
const selected_files_to_add = params.selected_files.map(normalize)
9295

9396
const existing = all_prompts[params.workspace_root].find((p) => {
94-
if (simplified_prompt !== '') {
97+
if (!is_prompt_empty_or_only_symbols({ prompt: simplified_prompt })) {
9598
return p.prompt == simplified_prompt
9699
}
97-
return p.prompt == '' && p.files.some((f) => files_to_add.includes(f))
100+
return (
101+
is_prompt_empty_or_only_symbols({ prompt: p.prompt }) &&
102+
p.files.some((f) => files_to_add.includes(f))
103+
)
98104
})
99105

100106
if (existing) {

‎apps/editor/src/utils/git-repository-utils.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@/constants/values'
99
import { PromptBuilder } from './prompt-builder'
1010
import { display_token_count } from '@shared/utils/display-token-count'
11+
import { is_prompt_empty_or_only_symbols } from '@shared/utils/simplify-prompt-symbols'
1112
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
1213
import { WebSocketManager } from '@/services/websocket-manager'
1314
import { search_files } from '@/features/search-files'
@@ -254,7 +255,7 @@ export const prepare_staged_changes = async (params: {
254255
const normalized_path = normalize_path(relative_path)
255256
const file_prompts = prompts_for_repo.filter(
256257
(p) =>
257-
p.prompt.trim() !== '' &&
258+
!is_prompt_empty_or_only_symbols({ prompt: p.prompt }) &&
258259
(p.files.includes(normalized_path) ||
259260
p.files.includes(change.uri.fsPath))
260261
)

‎packages/shared/src/utils/simplify-prompt-symbols/simplify-prompt-symbols.spec.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { simplify_prompt_symbols } from './simplify-prompt-symbols'
1+
import {
2+
simplify_prompt_symbols,
3+
is_prompt_empty_or_only_symbols
4+
} from './simplify-prompt-symbols'
25

36
describe('simplify_prompt_symbols', () => {
47
it('should return plain text as is', () => {
@@ -57,3 +60,29 @@ describe('simplify_prompt_symbols', () => {
5760
)
5861
})
5962
})
63+
64+
describe('is_prompt_empty_or_only_symbols', () => {
65+
it('should return true for empty string', () => {
66+
expect(is_prompt_empty_or_only_symbols({ prompt: '' })).toBe(true)
67+
})
68+
69+
it('should return true for whitespace string', () => {
70+
expect(is_prompt_empty_or_only_symbols({ prompt: ' ' })).toBe(true)
71+
})
72+
73+
it('should return true for only one symbol', () => {
74+
expect(is_prompt_empty_or_only_symbols({ prompt: '[Fragment]' })).toBe(true)
75+
})
76+
77+
it('should return true for multiple symbols with whitespace', () => {
78+
expect(
79+
is_prompt_empty_or_only_symbols({ prompt: '[Fragment] [Website] ' })
80+
).toBe(true)
81+
})
82+
83+
it('should return false if there is actual text', () => {
84+
expect(
85+
is_prompt_empty_or_only_symbols({ prompt: 'Fix this [Fragment]' })
86+
).toBe(false)
87+
})
88+
})

‎packages/shared/src/utils/simplify-prompt-symbols/simplify-prompt-symbols.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,22 @@ export const simplify_prompt_symbols = (params: { prompt: string }): string => {
2929

3030
return simplified
3131
}
32+
33+
export const is_prompt_empty_or_only_symbols = (params: {
34+
prompt: string
35+
}): boolean => {
36+
if (!params.prompt) return true
37+
38+
const stripped = params.prompt
39+
.replace(/\[Fragment\]/g, '')
40+
.replace(/\[Changes\]/g, '')
41+
.replace(/\[Saved context\]/g, '')
42+
.replace(/\[Commit\]/g, '')
43+
.replace(/\[Skill\]/g, '')
44+
.replace(/\[Image\]/g, '')
45+
.replace(/\[Pasted text\]/g, '')
46+
.replace(/\[Website\]/g, '')
47+
.trim()
48+
49+
return stripped === ''
50+
}

0 commit comments

Comments
 (0)