Skip to content

Commit 238b55f

Browse files
committed
Copy prompt images to temporary directory for agentic CLI invocations
- we correctly copy context files to temp dir when using edit/ask modes. now, when you encounter image path in instructions (CLIs), move these images to the same dir as well - when copy_images_to_dir is given, image paths should be relative to this dir - we recently started including prompt images in cli execution directory [Changes]. the issue is that these images are later copied into workspace (when applying in 'edit' mode) - should not └── apps └── editor └── src ├── commands │ ├── code-at-cursor-command │ │ └── utils │ │ └── perform-code-at-cursor.ts │ └── generate-commit-message-commands │ └── actions │ └── run-generate-action.ts ├── constants │ └── instructions.ts ├── features │ ├── agentic-search │ │ └── agentic-search.ts │ └── search-files │ └── search-modes │ └── perform-intelligent-search-mode.ts ├── utils │ └── agentic-cli-invocation │ ├── index.ts │ ├── invoke-agentic-cli.ts │ ├── types.ts │ └── utils │ ├── check-command-exists.ts │ ├── format-duration.ts │ ├── generate-diff-markdown.ts │ └── get-progress-dots.ts └── views └── prompt └── backend ├── message-handlers │ ├── handle-invoke-agentic-cli.ts │ ├── handle-patch-repair.ts │ ├── handle-preview-prompt.ts │ ├── handle-save-prompt-image.ts │ ├── handle-voice-input.ts │ └── utils │ └── build-cli-prompt.ts └── utils ├── persistent-prompt-storage.ts └── symbols ├── image │ └── replace-image-symbol.ts └── replace-symbols.ts
1 parent 15a3bbb commit 238b55f

6 files changed

Lines changed: 37 additions & 7 deletions

File tree

‎apps/editor/src/utils/agentic-cli-invocation/invoke-agentic-cli.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export const show_agentic_cli_output_channel = () => {
2828
export const invoke_agentic_cli = async (params: {
2929
workspace_provider: WorkspaceProvider
3030
extension_context: vscode.ExtensionContext
31-
build_prompt: (selected_root: string) => Promise<string | 'back' | undefined>
31+
build_prompt: (
32+
selected_root: string,
33+
temp_dir_path?: string
34+
) => Promise<string | 'back' | undefined>
3235
notification_title: string
3336
last_selected_workspace_state_key: string
3437
agent_state_key?: string
@@ -527,7 +530,10 @@ export const invoke_agentic_cli = async (params: {
527530
}
528531
}
529532

530-
const final_prompt = await params.build_prompt(selected_root!)
533+
const final_prompt = await params.build_prompt(
534+
selected_root!,
535+
temp_dir_path
536+
)
531537

532538
if (final_prompt === 'back') {
533539
if (roots.length === 1 || params.isolate_in_temp_dir) {

‎apps/editor/src/utils/agentic-cli-invocation/utils/generate-diff-markdown.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ async function get_all_files(dir: string): Promise<string[]> {
99
const dirents = await fs.promises.readdir(dir, { withFileTypes: true })
1010
const files = await Promise.all(
1111
dirents.map(async (dirent) => {
12+
if (dirent.isDirectory() && dirent.name === '.cwc') {
13+
return []
14+
}
1215
const res = path.resolve(dir, dirent.name)
1316
return dirent.isDirectory() ? get_all_files(res) : res
1417
})

‎apps/editor/src/views/prompt/backend/message-handlers/handle-invoke-agentic-cli.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ export const handle_invoke_agentic_cli = async (
5959
name
6060
})
6161
},
62-
build_prompt: async (selected_root: string) => {
62+
build_prompt: async (selected_root: string, temp_dir_path?: string) => {
6363
return build_cli_prompt({
6464
prompt_view_provider,
65-
selected_root
65+
selected_root,
66+
temp_dir_path
6667
})
6768
}
6869
})

‎apps/editor/src/views/prompt/backend/message-handlers/utils/build-cli-prompt.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { PromptBuilder } from '@/utils/prompt-builder'
99
export const build_cli_prompt = async (params: {
1010
prompt_view_provider: PromptViewProvider
1111
selected_root?: string
12+
temp_dir_path?: string
1213
}): Promise<string> => {
1314
const { prompt_view_provider } = params
1415
let { selected_root } = params
@@ -29,7 +30,8 @@ export const build_cli_prompt = async (params: {
2930
extension_context: prompt_view_provider.extension_context,
3031
workspace_provider: prompt_view_provider.workspace_provider,
3132
image_as_paths: true,
32-
symbols_cache: prompt_view_provider.symbols_cache
33+
symbols_cache: prompt_view_provider.symbols_cache,
34+
copy_images_to_dir: params.temp_dir_path
3335
})
3436

3537
const processed_query = processed_instructions_array[0]

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs'
2+
import * as path from 'path'
23
import * as vscode from 'vscode'
34
import { PersistentPromptStorage } from '../../persistent-prompt-storage'
45

@@ -7,6 +8,7 @@ export const replace_image_symbol = async (params: {
78
extension_context: vscode.ExtensionContext
89
remove?: boolean
910
as_paths?: boolean
11+
copy_images_to_dir?: string
1012
}): Promise<string[]> => {
1113
const storage = new PersistentPromptStorage(params.extension_context, 'image')
1214

@@ -34,8 +36,22 @@ export const replace_image_symbol = async (params: {
3436
if (!fs.existsSync(png_path)) {
3537
return { success: false }
3638
}
39+
if (params.copy_images_to_dir) {
40+
const images_dir = path.join(params.copy_images_to_dir, '.cwc')
41+
if (!fs.existsSync(images_dir)) {
42+
await fs.promises.mkdir(images_dir, { recursive: true })
43+
}
44+
const dest_path = path.join(images_dir, path.basename(png_path))
45+
await fs.promises.copyFile(png_path, dest_path)
46+
return {
47+
path: path
48+
.relative(params.copy_images_to_dir, dest_path)
49+
.replace(/\\/g, '/'),
50+
success: true
51+
}
52+
}
3753
return {
38-
path: png_path,
54+
path: png_path.replace(/\\/g, '/'),
3955
success: true
4056
}
4157
} else {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const replace_symbols = async (params: {
2020
remove_images?: boolean
2121
image_as_paths?: boolean
2222
symbols_cache?: SymbolCacheManager
23+
copy_images_to_dir?: string
2324
}): Promise<{
2425
instructions: string[]
2526
skill_definitions: string
@@ -97,7 +98,8 @@ export const replace_symbols = async (params: {
9798
instructions: processed_instructions,
9899
extension_context: params.extension_context,
99100
remove: params.remove_images,
100-
as_paths: params.image_as_paths
101+
as_paths: params.image_as_paths,
102+
copy_images_to_dir: params.copy_images_to_dir
101103
})
102104
}
103105

0 commit comments

Comments
 (0)