fix(edit): reuse resolved workspace target across apply_patch hunks for the same authored path

This commit is contained in:
can1357
2026-07-23 22:15:23 +02:00
parent a5e59a4e56
commit cf886d8d8a
2 changed files with 36 additions and 4 deletions
+12 -4
View File
@@ -587,15 +587,23 @@ export class EditTool implements AgentTool<TInput> {
onUpdate?: (partialResult: AgentToolResult<EditToolDetails, TInput>) => void,
) => {
const entries = expandApplyPatchToEntries(params as ApplyPatchParams);
// Resolve each authored path once per patch so paired hunks (e.g. delete
// then re-add of the same file) share the same workspace target.
const resolvedTargets = new Map<string, Promise<string>>();
const resolveOnce = (path: string, mustExist: boolean): Promise<string> => {
let pending = resolvedTargets.get(path);
if (!pending) {
pending = resolveEditPath(tool.session, path, { mustExist, signal });
resolvedTargets.set(path, pending);
}
return pending;
};
const perFile = entries.map(entry => {
const { path, ...patchParams } = entry;
return {
path,
run: async (br: LspBatchRequest | undefined) => {
const targetPath = await resolveEditPath(tool.session, path, {
mustExist: patchParams.op !== "create",
signal,
});
const targetPath = await resolveOnce(path, patchParams.op !== "create");
return executePatchSingle({
session: tool.session,
path: targetPath,