@@ -134,9 +134,7 @@ export class AgentFileHistoryService extends Service implements IAgentFileHistor
134134 ( c ) => c . turnId === turnId && checkpointPhaseOf ( c ) === phase ,
135135 ) ;
136136 if ( index < 0 ) return undefined ;
137- const pathKey = this . pathKey ( path ) ;
138- if ( pathKey === undefined ) return undefined ;
139- const entry = entryAt ( state . checkpoints , index , pathKey ) ;
137+ const entry = entryAt ( state . checkpoints , index , this . pathKey ( path ) ) ;
140138 if ( entry === undefined ) return undefined ;
141139 if ( entry . key === null ) return { version : entry . version } ;
142140 const bytes = await this . blobs . get ( this . agentCtx . scope ( ) , entry . key ) ;
@@ -163,7 +161,6 @@ export class AgentFileHistoryService extends Service implements IAgentFileHistor
163161
164162 private async capture ( path : string , turnId : number ) : Promise < void > {
165163 const pathKey = this . pathKey ( path ) ;
166- if ( pathKey === undefined ) return ;
167164 const state = this . history ( ) ;
168165 if ( state . tracked . includes ( pathKey ) ) return ;
169166
@@ -248,23 +245,11 @@ export class AgentFileHistoryService extends Service implements IAgentFileHistor
248245 }
249246
250247 private async readCurrent ( pathKey : string ) : Promise < Uint8Array | 'missing' | 'unreadable' > {
248+ const absolute = isAbsolute ( pathKey ) ? pathKey : resolve ( this . workspaceCtx . workDir , pathKey ) ;
251249 const lease = this . runtime . acquire ( [ 'fs' ] ) ;
252250 try {
253251 const fs = lease . runtime . fs ;
254252 if ( fs === undefined ) return 'unreadable' ;
255- const runtime = lease . runtime ;
256- const hostWorkDir = resolve ( this . workspaceCtx . workDir ) ;
257- const mappedWorkDir = runtime . path . resolve (
258- runtime . workspace . mapRoots ( { workDir : this . workspaceCtx . workDir , additionalDirs : [ ] } )
259- . workDir ,
260- ) ;
261- let absolute : string ;
262- if ( isAbsolute ( pathKey ) ) {
263- if ( mappedWorkDir !== hostWorkDir ) return 'unreadable' ;
264- absolute = pathKey ;
265- } else {
266- absolute = runtime . path . resolve ( mappedWorkDir , pathKey ) ;
267- }
268253 let info ;
269254 try {
270255 info = await fs . stat ( absolute ) ;
@@ -283,37 +268,14 @@ export class AgentFileHistoryService extends Service implements IAgentFileHistor
283268 }
284269 }
285270
286- private pathKey ( path : string ) : string | undefined {
271+ private pathKey ( path : string ) : string {
287272 if ( ! isAbsolute ( path ) ) return path ;
288- const hostRelative = relative ( resolve ( this . workspaceCtx . workDir ) , path ) ;
289- if ( containedRelative ( hostRelative ) ) return hostRelative ;
290- const lease = this . runtime . acquire ( ) ;
291- try {
292- const runtime = lease . runtime ;
293- const mappedWorkDir = runtime . path . resolve (
294- runtime . workspace . mapRoots ( { workDir : this . workspaceCtx . workDir , additionalDirs : [ ] } )
295- . workDir ,
296- ) ;
297- if ( mappedWorkDir === resolve ( this . workspaceCtx . workDir ) ) return path ;
298- const mappedRelative = runtime . path . relative ( mappedWorkDir , path ) ;
299- if ( containedRelative ( mappedRelative ) ) return mappedRelative . replaceAll ( '\\' , '/' ) ;
300- return undefined ;
301- } finally {
302- lease . dispose ( ) ;
303- }
273+ const relativePath = relative ( this . workspaceCtx . workDir , path ) ;
274+ if ( relativePath === '' || relativePath === '..' || relativePath . startsWith ( '../' ) ) return path ;
275+ return relativePath ;
304276 }
305277}
306278
307- function containedRelative ( relativePath : string ) : boolean {
308- return (
309- relativePath !== '' &&
310- relativePath !== '..' &&
311- ! relativePath . startsWith ( '../' ) &&
312- ! relativePath . startsWith ( '..\\' ) &&
313- ! isAbsolute ( relativePath )
314- ) ;
315- }
316-
317279function editTargetPath ( display : ToolInputDisplay | undefined ) : string | undefined {
318280 if ( display === undefined || display . kind !== 'file_io' ) return undefined ;
319281 if ( display . operation !== 'edit' && display . operation !== 'write' ) return undefined ;
0 commit comments