Skip to content

Commit 2ef98ce

Browse files
committed
fix(server): allow Antigravity writes into nested workspace paths
1 parent 31a9da1 commit 2ef98ce

2 files changed

Lines changed: 33 additions & 18 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ describe("AntigravityAdapterV2 client file system", () => {
221221
context("fs/write_text_file"),
222222
);
223223
assert.equal(yield* fileSystem.readFileString(insidePath), "inside");
224+
const workspaceAlias = path.join(outside, "workspace-alias");
225+
yield* fileSystem.symlink(workspace, workspaceAlias);
226+
const nestedPath = path.join(workspaceAlias, "new", "nested", "inside.ts");
227+
yield* writeTextFile(
228+
{ sessionId: "mock-session-1", path: nestedPath, content: "nested" },
229+
context("fs/write_text_file"),
230+
);
231+
assert.equal(
232+
yield* fileSystem.readFileString(path.join(workspace, "new", "nested", "inside.ts")),
233+
"nested",
234+
);
224235
const pasted = yield* readTextFile(
225236
{ sessionId: "mock-session-1", path: attachment },
226237
context("fs/read_text_file"),

‎apps/server/src/provider/acp/AntigravityClientFiles.ts‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)