Skip to content

Commit abe024d

Browse files
committed
Remove the ContextAtCommit prompt symbol and its associated handlers and UI components
- remove 'context at commit' feature ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── backend │ ├── message-handlers │ │ └── handle-hash-sign-quick-pick │ │ ├── handle-hash-sign-quick-pick.ts │ │ └── symbols │ │ └── commit-symbol.ts │ └── utils │ └── symbols │ ├── git │ │ └── replace-git-symbols.ts │ └── replace-symbols.ts └── packages ├── shared │ └── src │ └── utils │ └── simplify-prompt-symbols │ ├── simplify-prompt-symbols.spec.ts │ └── simplify-prompt-symbols.ts └── ui └── src └── components └── editor └── prompt └── prompts ├── PromptField │ ├── PromptField.stories.tsx │ └── hooks │ └── use-handlers │ └── utils.ts └── shared └── symbols ├── get-highlighted-text.tsx ├── position-mapping.ts ├── prompt-symbols.module.scss ├── reconstruct-raw-value.ts └── use-symbol-deletion.ts
1 parent 3fa178d commit abe024d

13 files changed

Lines changed: 14 additions & 280 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-hash-sign-quick-pick/handle-hash-sign-quick-pick.ts‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
const selection_label = '$(list-flat) Selection'
1414
const changes_label = '$(git-pull-request-draft) Changes'
1515
const commit_label = '$(git-commit) Commit'
16-
const context_at_commit_label = '$(history) Context at commit'
1716
const saved_context_label = '$(checklist) Saved context'
1817
const skill_label = '$(thinking) Skill'
1918

@@ -35,10 +34,6 @@ const hash_sign_quick_pick = async (params: {
3534
label: commit_label,
3635
description: 'Diff from a specific commit'
3736
},
38-
{
39-
label: context_at_commit_label,
40-
description: 'Older versions of the currently selected files'
41-
},
4237
{
4338
label: saved_context_label,
4439
description: 'Files from the workspace'
@@ -56,11 +51,7 @@ const hash_sign_quick_pick = async (params: {
5651
]
5752

5853
if (params.is_find_relevant_files) {
59-
items = items.filter(
60-
(item) =>
61-
item.label !== context_at_commit_label &&
62-
item.label !== saved_context_label
63-
)
54+
items = items.filter((item) => item.label !== saved_context_label)
6455
}
6556

6657
const last_selected_symbol =
@@ -135,12 +126,6 @@ const hash_sign_quick_pick = async (params: {
135126
case commit_label:
136127
result = await handle_commit_item(params.extension_context, 'Commit')
137128
break
138-
case context_at_commit_label:
139-
result = await handle_commit_item(
140-
params.extension_context,
141-
'ContextAtCommit'
142-
)
143-
break
144129
case saved_context_label:
145130
result = await handle_saved_context_item(params.extension_context)
146131
break

‎apps/editor/src/views/prompt/backend/message-handlers/handle-hash-sign-quick-pick/symbols/commit-symbol.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GIT_LOG_SINCE_DURATION } from '@/constants/values'
66

77
export const handle_commit_item = async (
88
extension_context: vscode.ExtensionContext,
9-
symbol: 'Commit' | 'ContextAtCommit'
9+
symbol: 'Commit'
1010
): Promise<string | 'continue' | undefined> => {
1111
try {
1212
const workspace_folders = vscode.workspace.workspaceFolders

‎apps/editor/src/views/prompt/backend/utils/symbols/git/replace-git-symbols.ts‎

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -482,127 +482,3 @@ export const replace_commit_symbol = async (params: {
482482
}
483483
return { instruction: result_instruction, commit_definitions }
484484
}
485-
486-
const build_context_at_commit_xml = (
487-
files_content: { path: string; content: string }[]
488-
): string => {
489-
if (files_content.length == 0) {
490-
return '<archive/>'
491-
}
492-
493-
let files_xml = ''
494-
for (const file of files_content) {
495-
files_xml += `<file path="${file.path.replace(/\\/g, '/')}">\n<![CDATA[\n${
496-
file.content
497-
}\n]]>\n</file>\n`
498-
}
499-
500-
return `\n<archive>\n${files_xml}</archive>\n`
501-
}
502-
503-
export const replace_context_at_commit_symbol = async (params: {
504-
instruction: string
505-
workspace_provider: WorkspaceProvider
506-
}): Promise<string> => {
507-
const regex =
508-
/#ContextAtCommit\(([^:]+):([a-fA-F0-9]+)\s*(?:"((?:[^"\\]|\\.)*)")?\)/g
509-
510-
let result_instruction = params.instruction
511-
const matches = [...result_instruction.matchAll(regex)]
512-
513-
const workspace_folders = vscode.workspace.workspaceFolders
514-
if (!workspace_folders) {
515-
return result_instruction.replace(regex, '')
516-
}
517-
518-
for (const match of matches) {
519-
const full_match = match[0]
520-
const folder_name = match[1]
521-
const commit_hash = match[2]
522-
523-
const target_folder = workspace_folders.find(
524-
(folder) => folder.name == folder_name
525-
)
526-
527-
if (!target_folder) {
528-
vscode.window.showErrorMessage(
529-
dictionary.error_message.WORKSPACE_FOLDER_NOT_FOUND(folder_name)
530-
)
531-
result_instruction = result_instruction.replace(full_match, '')
532-
continue
533-
}
534-
535-
const checked_files = params.workspace_provider.get_checked_files()
536-
const files_in_repo = checked_files.filter((file) =>
537-
file.startsWith(target_folder.uri.fsPath)
538-
)
539-
540-
if (files_in_repo.length == 0) {
541-
vscode.window.showInformationMessage(
542-
dictionary.information_message.NO_CHECKED_FILES_IN_REPO_FOR_COMMIT(
543-
folder_name,
544-
commit_hash.substring(0, 7)
545-
)
546-
)
547-
}
548-
549-
const files_content: { path: string; content: string }[] = []
550-
551-
for (const file_path of files_in_repo) {
552-
const relative_path = path.relative(target_folder.uri.fsPath, file_path)
553-
554-
let content_at_commit: string | null = null
555-
try {
556-
content_at_commit = execSync(
557-
`git show ${commit_hash}:"./${relative_path.replace(/\\/g, '/')}"`,
558-
{
559-
cwd: target_folder.uri.fsPath,
560-
encoding: 'utf-8',
561-
stdio: ['pipe', 'pipe', 'ignore'] // ignore stderr
562-
}
563-
)
564-
} catch (error) {
565-
// File might not have existed at that commit
566-
}
567-
568-
let current_content: string | null = null
569-
try {
570-
current_content = fs.readFileSync(file_path, 'utf-8')
571-
} catch (error) {
572-
// File might not exist in workspace (e.g., deleted)
573-
}
574-
575-
if (content_at_commit === current_content) {
576-
continue // File is unchanged, ignore it
577-
}
578-
579-
if (content_at_commit !== null) {
580-
// If we are here, file has changed (modified, new, or deleted)
581-
// Add its historical content to the archive.
582-
const display_path =
583-
params.workspace_provider.get_workspace_roots().length > 1
584-
? `${folder_name}/${relative_path.replace(/\\/g, '/')}`
585-
: relative_path.replace(/\\/g, '/')
586-
587-
files_content.push({ path: display_path, content: content_at_commit })
588-
}
589-
}
590-
591-
if (files_in_repo.length > 0 && files_content.length == 0) {
592-
vscode.window.showInformationMessage(
593-
dictionary.information_message.ALL_CHECKED_FILES_UNCAHNGED_SINCE_COMMIT(
594-
folder_name,
595-
commit_hash.substring(0, 7)
596-
)
597-
)
598-
}
599-
600-
const replacement_text = build_context_at_commit_xml(files_content)
601-
result_instruction = result_instruction.replace(
602-
full_match,
603-
replacement_text
604-
)
605-
}
606-
607-
return result_instruction
608-
}

‎apps/editor/src/views/prompt/backend/utils/symbols/replace-symbols.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import * as vscode from 'vscode'
22
import { WorkspaceProvider } from '@/context/providers/workspace/workspace-provider'
33
import {
44
replace_changes_symbol,
5-
replace_commit_symbol,
6-
replace_context_at_commit_symbol
5+
replace_commit_symbol
76
} from './git/replace-git-symbols'
87
import { replace_saved_context_symbol } from './saved-context/replace-saved-context-symbol'
98
import { replace_selection_symbol } from './selection/replace-selection-symbol'
@@ -46,13 +45,6 @@ export const replace_symbols = async (
4645
skill_definitions += result.commit_definitions
4746
}
4847

49-
if (processed_instructions.includes('#ContextAtCommit(')) {
50-
processed_instructions = await replace_context_at_commit_symbol({
51-
instruction: processed_instructions,
52-
workspace_provider: params.workspace_provider
53-
})
54-
}
55-
5648
if (processed_instructions.includes('#SavedContext(')) {
5749
const result = await replace_saved_context_symbol({
5850
instruction: processed_instructions,

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ describe('simplify_prompt_symbols', () => {
4444
expect(simplify_prompt_symbols({ prompt })).toBe('Check [Commit]')
4545
})
4646

47-
it('should replace #ContextAtCommit', () => {
48-
const prompt = 'Check #ContextAtCommit(repo:hash "message")'
49-
expect(simplify_prompt_symbols({ prompt })).toBe(
50-
'Check [Context at commit]'
51-
)
52-
})
53-
5447
it('should replace #Skill', () => {
5548
const prompt = 'Run #Skill(agent:repo:skill)'
5649
expect(simplify_prompt_symbols({ prompt })).toBe('Run [Skill]')

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export const simplify_prompt_symbols = (params: { prompt: string }): string => {
1717
/#Commit\([^:]+:[^\s"]+ "(?:\\.|[^"\\])*"\)/g,
1818
'[Commit]'
1919
)
20-
simplified = simplified.replace(
21-
/#ContextAtCommit\([^:]+:[^\s"]+ "(?:\\.|[^"\\])*"\)/g,
22-
'[Context at commit]'
23-
)
2420
simplified = simplified.replace(/#Skill\([^)]+\)/g, '[Skill]')
2521
simplified = simplified.replace(/#Image\([a-fA-F0-9]+\)/g, '[Image]')
2622
simplified = simplified.replace(

‎packages/ui/src/components/editor/prompt/prompts/PromptField/PromptField.stories.tsx‎

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -472,72 +472,6 @@ export const WithCommitWithQuotes = () => (
472472
}}
473473
/>
474474
)
475-
export const WithContextAtCommit = () => (
476-
<PromptField
477-
value='Ask about #ContextAtCommit(my-repo:a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0 "Initial commit")'
478-
chat_history={[]}
479-
on_change={(value) => console.log('Changed:', value)}
480-
on_submit={() => console.log('Submitted')}
481-
on_copy={() => console.log('Copied')}
482-
is_connected={true}
483-
prompt_type="edit-files"
484-
current_selection={null}
485-
currently_open_file_path="/path/to/file"
486-
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
487-
on_at_sign_click={() => console.log('@ clicked')}
488-
on_hash_sign_click={() => console.log('# clicked')}
489-
is_web_mode={false}
490-
on_submit_with_control={() => console.log('Submitted with control')}
491-
selected_files={[]}
492-
invocation_count={1}
493-
on_invocation_count_change={(count) =>
494-
console.log('Invocation count changed:', count)
495-
}
496-
on_go_to_file={(path) => console.log('Go to file:', path)}
497-
on_slash_click={() => {}}
498-
on_pasted_lines_click={(path, start, end) =>
499-
console.log('Pasted lines clicked:', path, start, end)
500-
}
501-
on_open_url={(url) => console.log('Open URL:', url)}
502-
on_open_website={(url) => console.log('Open website:', url)}
503-
on_paste_image={(content) => console.log('Paste image:', content)}
504-
on_paste_long_text={(content) => console.log('Paste long text:', content)}
505-
on_open_image={(hash) => console.log('Open image:', hash)}
506-
on_open_pasted_text={(hash) => console.log('Open pasted text:', hash)}
507-
on_paste_url={(url) => console.log('Paste URL:', url)}
508-
is_recording={false}
509-
on_recording_started={() => console.log('Recording started')}
510-
on_recording_finished={() => console.log('Recording finished')}
511-
tabs_count={1}
512-
active_tab_index={0}
513-
on_tab_change={() => {}}
514-
on_new_tab={() => {}}
515-
on_tab_delete={() => {}}
516-
translations={{
517-
invocation_count: 'Invocation count',
518-
voice_input: 'Voice input',
519-
exit_voice_input: 'Exit voice input',
520-
reference_file: 'Reference file',
521-
insert_symbol: 'Insert symbol',
522-
prompt_templates: 'Prompt templates',
523-
edit_format: 'Edit format',
524-
edit_format_whole: 'Whole-File Overwrite',
525-
edit_format_search_replace: 'Search & Replace',
526-
edit_format_diff: 'Unified Diff',
527-
edit_format_truncated: 'Ellipsis truncations',
528-
placeholder_code_history: 'Optional instructions (⇅ for history)',
529-
placeholder_code: 'Optional instructions',
530-
placeholder_history: 'Type instructions (⇅ for history)',
531-
placeholder_default: 'Type instructions',
532-
send_with: 'Send with',
533-
send_with_ellipsis: 'Send with...',
534-
copy_prompt: 'Copy prompt',
535-
more_actions: 'More actions',
536-
send: 'Send'
537-
}}
538-
/>
539-
)
540-
541475
export const WithEditFormatSelector = () => {
542476
const [edit_format, set_edit_format] = useState<EditFormat>('diff')
543477
const [invocation_count, set_invocation_count] = useState(1)

‎packages/ui/src/components/editor/prompt/prompts/PromptField/hooks/use-handlers/utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const get_symbol_ranges = (params: {
1010
}): { start: number; end: number }[] => {
1111
const ranges: { start: number; end: number }[] = []
1212
const regex =
13-
/`([^`]+)`|(#Changes\([^)]+\))|(#Selection)|(#SavedContext\((?:WorkspaceState|JSON) "(?:\\.|[^"\\])*"\))|(#(?:Commit|ContextAtCommit)\([^:]+:[^\s"]+ "(?:\\.|[^"\\])*"\))|(<fragment path="[^"]+"(?: [^>]+)?>[\s\S]*?<\/fragment>)|(#Skill\([^)]+\))|(#Image\([a-fA-F0-9]+\))|(#PastedText\([a-fA-F0-9]+:\d+\))|(#Website\([^)]+\))/g
13+
/`([^`]+)`|(#Changes\([^)]+\))|(#Selection)|(#SavedContext\((?:WorkspaceState|JSON) "(?:\\.|[^"\\])*"\))|(#Commit\([^:]+:[^\s"]+ "(?:\\.|[^"\\])*"\))|(<fragment path="[^"]+"(?: [^>]+)?>[\s\S]*?<\/fragment>)|(#Skill\([^)]+\))|(#Image\([a-fA-F0-9]+\))|(#PastedText\([a-fA-F0-9]+:\d+\))|(#Website\([^)]+\))/g
1414

1515
let match
1616
while ((match = regex.exec(params.text)) !== null) {

‎packages/ui/src/components/editor/prompt/prompts/shared/symbols/get-highlighted-text.tsx‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ export const get_highlighted_text = (params: {
5858
const saved_context_regex_part =
5959
'#SavedContext\\((?:WorkspaceState|JSON) "(?:\\\\.|[^"\\\\])*"\\)'
6060

61-
const commit_regex_part =
62-
'#(?:Commit|ContextAtCommit)\\([^:]+:[^\\s"]+ "(?:\\\\.|[^"\\\\])*"\\)'
61+
const commit_regex_part = '#Commit\\([^:]+:[^\\s"]+ "(?:\\\\.|[^"\\\\])*"\\)'
6362

6463
const fragment_regex_part =
6564
'<fragment path="[^"]+"(?: [^>]+)?>[\\s\\S]*?<\\/fragment>'
@@ -178,13 +177,13 @@ export const get_highlighted_text = (params: {
178177
)}"</span></span>`
179178
}
180179
const commit_match = part.match(
181-
/^#(Commit|ContextAtCommit)\(([^:]+):([^\s"]+) "((?:\\.|[^"\\])*)"\)$/
180+
/^#Commit\(([^:]+):([^\s"]+) "((?:\\.|[^"\\])*)"\)$/
182181
)
183182
if (part && commit_match) {
184-
const symbol = commit_match[1]
185-
const repo_name = commit_match[2]
186-
const commit_hash = commit_match[3]
187-
const commit_message = commit_match[4].replace(/\\"/g, '"')
183+
const symbol = 'Commit'
184+
const repo_name = commit_match[1]
185+
const commit_hash = commit_match[2]
186+
const commit_message = commit_match[3].replace(/\\"/g, '"')
188187
const short_hash = commit_hash.substring(0, 7)
189188
return `<span class="${cn(
190189
styles['symbol'],

‎packages/ui/src/components/editor/prompt/prompts/shared/symbols/position-mapping.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const map_display_pos_to_raw_pos = (params: {
88
let last_raw_index = 0
99

1010
const regex =
11-
/`([^`]+)`|(#Changes\([^)]+\))|(#Selection)|(#SavedContext\((?:WorkspaceState|JSON) "((?:\\.|[^"\\])*)"\))|(#(?:Commit|ContextAtCommit)\([^:]+:([^\s"]+) "(?:\\.|[^"\\])*"\))|(<fragment path="[^"]+"(?: [^>]+)?>([\s\S]*?)<\/fragment>)|(#Skill\([^)]+\))|(#Image\([a-fA-F0-9]+\))|(#PastedText\([a-fA-F0-9]+:\d+\))|(#Website\([^)]+\))/g
11+
/`([^`]+)`|(#Changes\([^)]+\))|(#Selection)|(#SavedContext\((?:WorkspaceState|JSON) "((?:\\.|[^"\\])*)"\))|(#Commit\([^:]+:([^\s"]+) "(?:\\.|[^"\\])*"\))|(<fragment path="[^"]+"(?: [^>]+)?>([\s\S]*?)<\/fragment>)|(#Skill\([^)]+\))|(#Image\([a-fA-F0-9]+\))|(#PastedText\([a-fA-F0-9]+:\d+\))|(#Website\([^)]+\))/g
1212
let match
1313

1414
while ((match = regex.exec(params.raw_text)) !== null) {
@@ -143,7 +143,7 @@ export const map_raw_pos_to_display_pos = (params: {
143143
let last_raw_index = 0
144144

145145
const regex =
146-
/`([^`]+)`|(#Changes\([^)]+\))|(#Selection)|(#SavedContext\((?:WorkspaceState|JSON) "((?:\\.|[^"\\])*)"\))|(#(?:Commit|ContextAtCommit)\([^:]+:([^\s"]+) "(?:\\.|[^"\\])*"\))|(<fragment path="[^"]+"(?: [^>]+)?>([\s\S]*?)<\/fragment>)|(#Skill\([^)]+\))|(#Image\([a-fA-F0-9]+\))|(#PastedText\([a-fA-F0-9]+:\d+\))|(#Website\([^)]+\))/g
146+
/`([^`]+)`|(#Changes\([^)]+\))|(#Selection)|(#SavedContext\((?:WorkspaceState|JSON) "((?:\\.|[^"\\])*)"\))|(#Commit\([^:]+:([^\s"]+) "(?:\\.|[^"\\])*"\))|(<fragment path="[^"]+"(?: [^>]+)?>([\s\S]*?)<\/fragment>)|(#Skill\([^)]+\))|(#Image\([a-fA-F0-9]+\))|(#PastedText\([a-fA-F0-9]+:\d+\))|(#Website\([^)]+\))/g
147147
let match
148148

149149
while ((match = regex.exec(params.raw_text)) !== null) {

0 commit comments

Comments
 (0)