Skip to content

Commit 065f007

Browse files
committed
Show "edit" instead of "create" in permission prompt for existing files
1 parent cfcbb8f commit 065f007

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

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)