@@ -23,8 +23,8 @@ import { assertSandboxPath } from "./sandbox-paths.js";
2323import { resolveSandboxFileMutationQueueKey } from "./sandbox/file-mutation-identity.js" ;
2424import {
2525 resolveFileMutationQueueKey ,
26- withFileMutationQueueKey ,
27- withFileMutationQueueKeys ,
26+ withFileMutationQueueKeyResolution ,
27+ withFileMutationQueueKeyResolutions ,
2828} from "./sessions/tools/file-mutation-queue.js" ;
2929
3030const BEGIN_PATCH_MARKER = "*** Begin Patch" ;
@@ -188,33 +188,58 @@ async function applyPatch(input: string, options: ApplyPatchOptions): Promise<Ap
188188 }
189189
190190 if ( hunk . kind === "add" ) {
191- const target = await resolvePatchPath ( hunk . path , options ) ;
192- await withFileMutationQueueKey ( target . queueKey , async ( ) => {
193- await assertPatchParentPath ( hunk . path , options ) ;
194- await ensureDir ( target . resolved , fileOps ) ;
195- await createPatchTarget ( {
196- target,
197- contents : hunk . contents ,
198- ops : fileOps ,
199- hint : `Use "*** Update File: ${ target . display } " to change it, or delete it earlier in the same patch.` ,
200- } ) ;
201- } ) ;
191+ const targetResolution = resolvePatchPath ( hunk . path , options ) ;
192+ await withFileMutationQueueKeyResolution (
193+ targetResolution . then ( ( target ) => target . queueKey ) ,
194+ async ( ) => {
195+ const target = await targetResolution ;
196+ await assertPatchParentPath ( hunk . path , options ) ;
197+ await ensureDir ( target . resolved , fileOps ) ;
198+ await createPatchTarget ( {
199+ target,
200+ contents : hunk . contents ,
201+ ops : fileOps ,
202+ hint : `Use "*** Update File: ${ target . display } " to change it, or delete it earlier in the same patch.` ,
203+ } ) ;
204+ } ,
205+ ) ;
206+ const target = await targetResolution ;
202207 recordSummary ( summary , seen , "added" , target . display ) ;
203208 continue ;
204209 }
205210
206211 if ( hunk . kind === "delete" ) {
207- const target = await resolvePatchPath ( hunk . path , options , PATH_ALIAS_POLICIES . unlinkTarget ) ;
208- await withFileMutationQueueKey ( target . queueKey , ( ) => fileOps . remove ( target . resolved ) ) ;
212+ const targetResolution = resolvePatchPath (
213+ hunk . path ,
214+ options ,
215+ PATH_ALIAS_POLICIES . unlinkTarget ,
216+ ) ;
217+ await withFileMutationQueueKeyResolution (
218+ targetResolution . then ( ( target ) => target . queueKey ) ,
219+ async ( ) => {
220+ const target = await targetResolution ;
221+ await fileOps . remove ( target . resolved ) ;
222+ } ,
223+ ) ;
224+ const target = await targetResolution ;
209225 recordSummary ( summary , seen , "deleted" , target . display ) ;
210226 continue ;
211227 }
212228
213- const target = await resolvePatchPath ( hunk . path , options ) ;
214- const moveTarget = hunk . movePath ? await resolvePatchPath ( hunk . movePath , options ) : undefined ;
215- await withFileMutationQueueKeys (
216- [ target . queueKey , ...( moveTarget ? [ moveTarget . queueKey ] : [ ] ) ] ,
229+ const targetResolution = resolvePatchPath ( hunk . path , options ) ;
230+ const moveTargetResolution = hunk . movePath
231+ ? resolvePatchPath ( hunk . movePath , options )
232+ : undefined ;
233+ await withFileMutationQueueKeyResolutions (
234+ [
235+ targetResolution . then ( ( target ) => target . queueKey ) ,
236+ ...( moveTargetResolution
237+ ? [ moveTargetResolution . then ( ( moveTarget ) => moveTarget . queueKey ) ]
238+ : [ ] ) ,
239+ ] ,
217240 async ( ) => {
241+ const target = await targetResolution ;
242+ const moveTarget = moveTargetResolution ? await moveTargetResolution : undefined ;
218243 const applied = await applyUpdateHunk ( target . resolved , hunk . chunks , {
219244 readFile : ( pathLocal ) => fileOps . readFile ( pathLocal ) ,
220245 } ) ;
@@ -391,6 +416,7 @@ async function resolvePatchPath(
391416 root : options . sandbox . root ,
392417 filePath,
393418 cwd : options . cwd ,
419+ signal : options . signal ,
394420 } ) ,
395421 display : resolved . relativePath || resolved . containerPath ,
396422 } ;
0 commit comments