Repository navigation
feat(tools): publish apply_patch through the guard (U6, #1375) #1915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c4a9ae2
9003730
6c331da
ed7274f
88c4afa
166073f
f491af8
188b2f3
91efcb1
3920f65
05b6aa2
427e141
82eb3f8
fae26bc
ba493f4
aaa12cb
ea76274
ef18c7c
84c95ba
31d08da
89624ce
e8cffea
a3be4a6
59176fb
22179e4
8459cba
2c61f0c
ff80d49
3ebd9ce
da74317
c6c6abf
fdb0977
f56e02a
f241311
f29b11b
5fa2179
32d1fa6
11848e6
9075fdd
cc8d413
8c55b29
6551af7
5529fbc
5218aea
4d2bfb4
758e74c
55a6598
d10f0f2
22ee292
c1d3021
b8a5cfd
8795844
e0ca1db
52b7cc6
2b82937
4fbf99a
957b1b1
f4edf2c
23f0e8e
567bf8f
cc9bb4a
688053b
9610329
fd25bba
9f5c801
4b6cf13
8d8901b
77070a2
f1371d8
433d15b
98be920
e153075
c411f97
1e8b458
51d912a
38feec8
b7ee4a5
993fc6f
440dca4
0b0db14
bc288fd
9473a26
7f3ee12
9373761
ec57ad4
fd1f690
2d90581
57cd65f
ae30e89
f8ee3e8
8a29fae
3345170
c6c92f6
5928693
9d53a04
94f4a23
42a1bbb
a71761a
5115d62
ec3e02e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { TelemetryService } from "@roo-code/telemetry" | |
|
|
||
| import { getReadablePath } from "../../utils/path" | ||
| import { isPathOutsideWorkspace } from "../../utils/pathUtils" | ||
| import { versionTokenOfStat } from "../../utils/versionToken" | ||
| import { Task } from "../task/Task" | ||
| import { formatResponse } from "../prompts/responses" | ||
| import { fileExistsAtPath } from "../../utils/fs" | ||
|
|
@@ -74,7 +75,32 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> { | |
| return | ||
| } | ||
|
|
||
| // The diff below is built from this exact read, so the save that follows must be | ||
| // authorized against the version captured here - not against whatever version the | ||
| // preview happens to stat afterwards. Same contract as ApplyPatchTool's hunk read: | ||
| // stat around the read and observe only when the file did not change underneath it. | ||
| const preReadStats = await fs.stat(absolutePath, { bigint: true }).catch(() => undefined) | ||
| const originalContent: string = await fs.readFile(absolutePath, "utf-8") | ||
| const postReadStats = await fs.stat(absolutePath, { bigint: true }).catch(() => undefined) | ||
| if (preReadStats && postReadStats) { | ||
| const preReadToken = versionTokenOfStat(preReadStats) | ||
| if (preReadToken === versionTokenOfStat(postReadStats)) { | ||
| // A tool read is not a model read. With no prior observation this stays a | ||
| // partial observation of the version the diff was computed against - the only | ||
| // authorization the save can have, since apply_diff computes its hunks from | ||
| // this read. When the model already observed the file, keep the completeness it | ||
| // earned, but only on the version it was earned on: refreshing an OLDER | ||
| // observation to the current version would let content the model built from a | ||
| // stale read pass the compare-and-swap, so an out-of-date observation is left | ||
| // alone and the save fails with the re-read remediation. | ||
| const prior = task.observationRegistry.get(absolutePath) | ||
| if (prior === undefined) { | ||
| task.observationRegistry.observe(absolutePath, preReadToken, false) | ||
| } else if (prior.version === preReadToken) { | ||
| task.observationRegistry.observe(absolutePath, preReadToken, prior.complete === true) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Apply the diff to the original content | ||
| const diffResult = (await task.diffStrategy?.applyDiff( | ||
|
|
@@ -177,7 +203,8 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> { | |
| return | ||
| } | ||
|
|
||
| // Save directly without showing diff view or opening the file | ||
| // Save directly without showing diff view or opening the file. The diff is | ||
| // applied to an existing file, so edit-guard semantics require a prior read. | ||
| task.diffViewProvider.editType = "modify" | ||
| task.diffViewProvider.originalContent = originalContent | ||
| await task.diffViewProvider.saveDirectly( | ||
|
|
@@ -186,6 +213,7 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> { | |
| false, | ||
| diagnosticsEnabled, | ||
| writeDelayMs, | ||
| "edit", | ||
| ) | ||
| } else { | ||
| // Original behavior with diff view | ||
|
|
@@ -225,7 +253,7 @@ export class ApplyDiffTool extends BaseTool<"apply_diff"> { | |
| } | ||
|
|
||
| // Call saveChanges to update the DiffViewProvider properties | ||
| await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs) | ||
| await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs, "edit") | ||
|
easonLiangWorldedtech marked this conversation as resolved.
Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| // Track file edit operation | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.