11import * as Effect from "effect/Effect" ;
2+ import * as Option from "effect/Option" ;
23import type * as FileSystem from "effect/FileSystem" ;
34import type * as Path from "effect/Path" ;
45import * as EffectAcpErrors from "effect-acp/errors" ;
@@ -25,23 +26,27 @@ const resolveClientFilePath = Effect.fn("AntigravityClientFiles.resolveClientFil
2526 const outside = EffectAcpErrors . AcpRequestError . invalidParams (
2627 `Path '${ input . requestPath } ' is outside the session workspace.` ,
2728 ) ;
28- const real = yield * input . fileSystem . realPath ( resolved ) . pipe (
29- Effect . catch ( ( ) =>
30- Effect . gen ( function * ( ) {
31- // Fall back to the parent only for missing files, never dangling or unreadable links.
32- const entryExists = yield * input . fileSystem . readLink ( resolved ) . pipe (
33- Effect . as ( true ) ,
34- Effect . catch ( ( ) => input . fileSystem . exists ( resolved ) ) ,
35- Effect . orElseSucceed ( ( ) => true ) ,
36- ) ;
37- if ( entryExists ) return yield * outside ;
38- const parent = yield * input . fileSystem
39- . realPath ( path . dirname ( resolved ) )
40- . pipe ( Effect . orElseSucceed ( ( ) => path . dirname ( resolved ) ) ) ;
41- return path . join ( parent , path . basename ( resolved ) ) ;
42- } ) ,
43- ) ,
44- ) ;
29+ // Canonicalize the deepest existing ancestor, so a link above missing directories cannot escape.
30+ let candidate = resolved ;
31+ const missingSuffix : Array < string > = [ ] ;
32+ let real : string ;
33+ while ( true ) {
34+ const canonical = yield * input . fileSystem . realPath ( candidate ) . pipe ( Effect . option ) ;
35+ if ( Option . isSome ( canonical ) ) {
36+ real = path . join ( canonical . value , ...missingSuffix ) ;
37+ break ;
38+ }
39+ // Walk up only past missing entries, never dangling or unreadable links.
40+ const entryExists = yield * input . fileSystem . readLink ( candidate ) . pipe (
41+ Effect . as ( true ) ,
42+ Effect . catch ( ( ) => input . fileSystem . exists ( candidate ) ) ,
43+ Effect . orElseSucceed ( ( ) => true ) ,
44+ ) ;
45+ const parent = path . dirname ( candidate ) ;
46+ if ( entryExists || parent === candidate ) return yield * outside ;
47+ missingSuffix . unshift ( path . basename ( candidate ) ) ;
48+ candidate = parent ;
49+ }
4550 const roots = yield * Effect . forEach ( input . allowedRoots , ( root ) =>
4651 input . fileSystem . realPath ( root ) . pipe ( Effect . orElseSucceed ( ( ) => root ) ) ,
4752 ) ;
0 commit comments