Skip to content

Commit 20e06d4

Browse files
fix: check apply_patch move destinations
1 parent 1d2a7b4 commit 20e06d4

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/opencode/src/tool/apply_patch.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,15 @@ export const ApplyPatchTool = Tool.define(
202202
}))
203203

204204
// Check permissions if needed
205-
const relativePaths = fileChanges.map((c) => path.relative(instance.worktree, c.filePath).replaceAll("\\", "/"))
205+
const relativePaths = Array.from(
206+
new Set(
207+
fileChanges.flatMap((change) =>
208+
[change.filePath, change.movePath]
209+
.filter((filePath): filePath is string => filePath !== undefined)
210+
.map((filePath) => path.relative(instance.worktree, filePath).replaceAll("\\", "/")),
211+
),
212+
),
213+
)
206214
yield* ctx.ask({
207215
permission: "edit",
208216
patterns: relativePaths,

packages/opencode/test/tool/apply_patch.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ describe("tool.apply_patch freeform", () => {
178178
expect(moveFile.type).toBe("move")
179179
expect(moveFile.relativePath).toBe("renamed/dir/name.txt")
180180
expect(moveFile.movePath).toBe(path.join(test.directory, "renamed/dir/name.txt"))
181+
expect(permissionCall.patterns).toEqual(["old/name.txt", "renamed/dir/name.txt"])
181182
expect(moveFile.patch).toContain("-old content")
182183
expect(moveFile.patch).toContain("+new content")
183184
}),

0 commit comments

Comments
 (0)