@@ -35,24 +35,28 @@ const resolveClientFilePath = Effect.fn("AntigravityClientFiles.resolveClientFil
3535 const outside = EffectAcpErrors . AcpRequestError . invalidParams (
3636 `Path '${ input . requestPath } ' is outside the session workspace.` ,
3737 ) ;
38- const real = yield * input . fileSystem . realPath ( resolved ) . pipe (
39- Effect . catch ( ( ) =>
40- Effect . gen ( function * ( ) {
41- // Only a missing file (a new write) falls back to its parent; a
42- // dangling or unreadable link must not be followed on write.
43- const entryExists = yield * input . fileSystem . readLink ( resolved ) . pipe (
44- Effect . as ( true ) ,
45- Effect . catch ( ( ) => input . fileSystem . exists ( resolved ) ) ,
46- Effect . orElseSucceed ( ( ) => true ) ,
47- ) ;
48- if ( entryExists ) return yield * outside ;
49- const parent = yield * input . fileSystem
50- . realPath ( path . dirname ( resolved ) )
51- . pipe ( Effect . orElseSucceed ( ( ) => path . dirname ( resolved ) ) ) ;
52- return path . join ( parent , path . basename ( resolved ) ) ;
53- } ) ,
54- ) ,
55- ) ;
38+ let candidate = resolved ;
39+ const missing : Array < string > = [ ] ;
40+ const real = yield * Effect . gen ( function * ( ) {
41+ while ( true ) {
42+ const canonical = yield * input . fileSystem . realPath ( candidate ) . pipe ( Effect . option ) ;
43+ if ( canonical . _tag === "Some" ) {
44+ return path . join ( canonical . value , ...missing ) ;
45+ }
46+ // Resolve the nearest existing ancestor before appending missing
47+ // directories. A dangling or unreadable link must not be followed.
48+ const entryExists = yield * input . fileSystem . readLink ( candidate ) . pipe (
49+ Effect . as ( true ) ,
50+ Effect . catch ( ( ) => input . fileSystem . exists ( candidate ) ) ,
51+ Effect . orElseSucceed ( ( ) => true ) ,
52+ ) ;
53+ if ( entryExists ) return yield * outside ;
54+ const parent = path . dirname ( candidate ) ;
55+ if ( parent === candidate ) return yield * outside ;
56+ missing . unshift ( path . basename ( candidate ) ) ;
57+ candidate = parent ;
58+ }
59+ } ) ;
5660 const roots = yield * Effect . forEach ( input . allowedRoots , ( root ) =>
5761 input . fileSystem . realPath ( root ) . pipe ( Effect . orElseSucceed ( ( ) => root ) ) ,
5862 ) ;
0 commit comments