@@ -167,39 +167,48 @@ export const PatchTool = Tool.define("patch", {
167167 }
168168 await fs . writeFile ( change . filePath , change . newContent , "utf-8" )
169169 changedFiles . push ( change . filePath )
170+ // Update file time tracking
171+ FileTime . read ( ctx . sessionID , change . filePath )
170172 break
171173
172174 case "update" :
173- await fs . writeFile ( change . filePath , change . newContent , "utf-8" )
174- changedFiles . push ( change . filePath )
175+ await FileTime . withLock ( change . filePath , async ( ) => {
176+ await fs . writeFile ( change . filePath , change . newContent , "utf-8" )
177+ changedFiles . push ( change . filePath )
178+ // Update file time tracking
179+ FileTime . read ( ctx . sessionID , change . filePath )
180+ } )
175181 break
176182
177183 case "move" :
178184 if ( change . movePath ) {
179- // Create parent directories for destination
180- const moveDir = path . dirname ( change . movePath )
181- if ( moveDir !== "." && moveDir !== "/" ) {
182- await fs . mkdir ( moveDir , { recursive : true } )
183- }
184- // Write to new location
185- await fs . writeFile ( change . movePath , change . newContent , "utf-8" )
186- // Remove original
187- await fs . unlink ( change . filePath )
188- changedFiles . push ( change . movePath )
185+ await FileTime . withLock ( change . filePath , async ( ) => {
186+ // Create parent directories for destination
187+ const moveDir = path . dirname ( change . movePath ! )
188+ if ( moveDir !== "." && moveDir !== "/" ) {
189+ await fs . mkdir ( moveDir , { recursive : true } )
190+ }
191+ // Write to new location
192+ await fs . writeFile ( change . movePath ! , change . newContent , "utf-8" )
193+ // Remove original
194+ await fs . unlink ( change . filePath )
195+ changedFiles . push ( change . movePath ! )
196+ // Update file time tracking
197+ FileTime . read ( ctx . sessionID , change . filePath )
198+ FileTime . read ( ctx . sessionID , change . movePath ! )
199+ } )
189200 }
190201 break
191202
192203 case "delete" :
193- await fs . unlink ( change . filePath )
194- changedFiles . push ( change . filePath )
204+ await FileTime . withLock ( change . filePath , async ( ) => {
205+ await fs . unlink ( change . filePath )
206+ changedFiles . push ( change . filePath )
207+ // Update file time tracking
208+ FileTime . read ( ctx . sessionID , change . filePath )
209+ } )
195210 break
196211 }
197-
198- // Update file time tracking
199- FileTime . read ( ctx . sessionID , change . filePath )
200- if ( change . movePath ) {
201- FileTime . read ( ctx . sessionID , change . movePath )
202- }
203212 }
204213
205214 // Publish file change events
0 commit comments