Skip to content

Commit 29fe884

Browse files
committed
Simplify diff generation by using original files directly instead of temporary backups
- the goal is to compare the temporary sandbox against the current live workspace - we don't need to save current states to memory └── apps └── editor └── src ├── commands │ ├── code-at-cursor-command │ │ └── utils │ │ └── perform-code-at-cursor.ts │ └── generate-commit-message-commands │ └── actions │ └── run-generate-action.ts ├── features │ ├── agentic-search │ │ └── agentic-search.ts │ └── search-files │ └── search-modes │ └── perform-intelligent-search-mode.ts ├── utils │ └── agentic-cli-invocation │ ├── agents │ │ ├── antigravity.ts │ │ ├── claude.ts │ │ ├── codex.ts │ │ ├── cursor.ts │ │ ├── devin.ts │ │ ├── grok.ts │ │ ├── index.ts │ │ └── opencode.ts │ ├── 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-voice-input.ts
1 parent 6477813 commit 29fe884

2 files changed

Lines changed: 7 additions & 30 deletions

File tree

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export const invoke_agentic_cli = async (params: {
367367
let temp_dir_path: string | undefined
368368
const file_mappings = new Map<
369369
string,
370-
{ original: string; dest_rel: string; initial_content?: string }
370+
{ original: string; dest_rel: string }
371371
>()
372372

373373
if (params.isolate_in_temp_dir) {
@@ -397,14 +397,9 @@ export const invoke_agentic_cli = async (params: {
397397
})
398398
await fs.promises.copyFile(file_path, dest_path)
399399

400-
const initial_content = await fs.promises
401-
.readFile(file_path, 'utf-8')
402-
.catch(() => undefined)
403-
404400
file_mappings.set(dest_path, {
405401
original: file_path,
406-
dest_rel: dest_rel.replace(/\\/g, '/'),
407-
initial_content
402+
dest_rel: dest_rel.replace(/\\/g, '/')
408403
})
409404
}
410405
}

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,12 @@ async function get_all_files(dir: string): Promise<string[]> {
2121

2222
export const generate_diff_markdown = async (
2323
temp_dir_path: string,
24-
file_mappings: Map<
25-
string,
26-
{ original: string; dest_rel: string; initial_content?: string }
27-
>
24+
file_mappings: Map<string, { original: string; dest_rel: string }>
2825
): Promise<string> => {
2926
let diff_markdown = ''
3027
const temp_files = await get_all_files(temp_dir_path)
3128

3229
for (const temp_file of temp_files) {
33-
if (path.basename(temp_file).startsWith('._orig_')) {
34-
continue
35-
}
36-
3730
const rel_path = path.relative(temp_dir_path, temp_file)
3831
const unix_rel_path = rel_path.replace(/\\/g, '/')
3932

@@ -49,26 +42,17 @@ export const generate_diff_markdown = async (
4942
}
5043

5144
if (mapping) {
52-
const original_content =
53-
mapping.initial_content !== undefined
54-
? mapping.initial_content
55-
: await fs.promises
56-
.readFile(mapping.original, 'utf-8')
57-
.catch(() => '')
45+
const original_content = await fs.promises
46+
.readFile(mapping.original, 'utf-8')
47+
.catch(() => '')
5848
const new_content = await fs.promises.readFile(temp_file, 'utf-8')
5949

6050
if (original_content !== new_content) {
61-
const temp_original = path.join(
62-
path.dirname(temp_file),
63-
`._orig_${path.basename(temp_file)}`
64-
)
65-
await fs.promises.writeFile(temp_original, original_content, 'utf-8')
66-
6751
try {
6852
await execFileAsync('git', [
6953
'diff',
7054
'--no-index',
71-
temp_original,
55+
mapping.original,
7256
temp_file
7357
])
7458
} catch (err: any) {
@@ -118,8 +102,6 @@ export const generate_diff_markdown = async (
118102
(new_content.endsWith('\n') ? '' : '\n') +
119103
'```\n'
120104
}
121-
} finally {
122-
await fs.promises.unlink(temp_original).catch(() => {})
123105
}
124106
}
125107
} else {

0 commit comments

Comments
 (0)