Skip to content

Commit 5fd4618

Browse files
authored
fix: Show "edit" instead of "create" in permission prompt for existing files (#1538)
## Problem Write tool permission prompts always say "Create new file" even when overwriting an existing file, because the old file content was never resolved during the permission request flow. Closes #1529 ## Changes 1. Add disk-read fallback in Write tool case when file isn't in the content cache 2. Pass fileContentCache and cwd to toolInfoFromToolUse in permission flow so cached content and relative paths are available ## How did you test this? Manually
1 parent a2b92ee commit 5fd4618

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/agent/src/adapters/claude/conversion/tool-use-to-acp.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,19 @@ export function toolInfoFromToolUse(
226226
: undefined;
227227
const contentStr = input?.content ? String(input.content) : undefined;
228228
if (writeFilePath) {
229-
const oldContent =
229+
let oldContent: string | null = null;
230+
if (
230231
options?.cachedFileContent &&
231232
writeFilePath in options.cachedFileContent
232-
? options.cachedFileContent[writeFilePath]
233-
: null;
233+
) {
234+
oldContent = options.cachedFileContent[writeFilePath];
235+
} else {
236+
try {
237+
oldContent = fs.readFileSync(writeFilePath, "utf-8");
238+
} catch {
239+
// File doesn't exist — genuinely a new file
240+
}
241+
}
234242
contentResult = toolContent()
235243
.diff(writeFilePath, oldContent, contentStr ?? "")
236244
.build();

packages/agent/src/adapters/claude/permissions/permission-handlers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ async function handleDefaultPermissionFlow(
338338
suggestions,
339339
} = context;
340340

341-
const toolInfo = toolInfoFromToolUse({ name: toolName, input: toolInput });
341+
const toolInfo = toolInfoFromToolUse(
342+
{ name: toolName, input: toolInput },
343+
{ cachedFileContent: context.fileContentCache, cwd: session?.cwd },
344+
);
342345

343346
const options = buildPermissionOptions(
344347
toolName,

0 commit comments

Comments
 (0)