Skip to content

Commit f6301f4

Browse files
committed
fix(antigravity): accept empty skill directories
1 parent dd14848 commit f6301f4

2 files changed

Lines changed: 122 additions & 24 deletions

File tree

‎apps/server/src/textGeneration/AntigravityTextGeneration.test.ts‎

Lines changed: 87 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
6060
readonly startError?: AcpError;
6161
readonly rejectAdmission?: boolean;
6262
readonly sessionId?: string;
63+
readonly startupSkills?: boolean;
6364
} = {},
6465
) {
6566
const fs = yield* FileSystem.FileSystem;
@@ -135,6 +136,13 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
135136
start: () =>
136137
Effect.gen(function* () {
137138
if (options.startError) return yield* options.startError;
139+
if (options.startupSkills) {
140+
for (const directory of [".agents", ".gemini"]) {
141+
yield* fs
142+
.makeDirectory(path.join(cwd, directory, "skills"), { recursive: true })
143+
.pipe(Effect.orDie);
144+
}
145+
}
138146
yield* fs.makeDirectory(brainDirectory, { recursive: true }).pipe(Effect.orDie);
139147
yield* fs.writeFileString(`${sessionBase}.db`, "helper session").pipe(Effect.orDie);
140148
yield* fs.writeFileString(`${sessionBase}.db-wal`, "helper journal").pipe(Effect.orDie);
@@ -284,6 +292,7 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => {
284292
() =>
285293
Effect.gen(function* () {
286294
const fixture = yield* makeFixture({
295+
startupSkills: true,
287296
outputs: [
288297
'{"subject":" Repair Google login.\\nExtra line","body":" Keep the remote callback. ","branch":"Repair Login"}',
289298
'```json\n{"title":" Repair Google login\\nExtra line","body":" ## Summary\\nSupport remote callbacks. "}\n```',
@@ -442,29 +451,72 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => {
442451
}).pipe(Effect.scoped),
443452
);
444453

445-
it.effect("rejects a helper that writes files in its temporary workspace", () =>
446-
Effect.gen(function* () {
447-
const fs = yield* FileSystem.FileSystem;
448-
const path = yield* Path.Path;
449-
const fixture = yield* makeFixture({
450-
prompt: ({ cwd, emit }) =>
451-
Effect.gen(function* () {
452-
yield* fs
453-
.writeFileString(path.join(cwd, "unexpected.txt"), "unexpected")
454-
.pipe(Effect.orDie);
455-
yield* emit({
456-
sessionUpdate: "agent_message_chunk",
457-
content: { type: "text", text: '{"title":"Ignored output"}' },
458-
});
459-
return { stopReason: "end_turn" };
460-
}),
461-
});
462-
const error = yield* fixture.textGeneration
463-
.generateThreadTitle(fixture.titleInput)
464-
.pipe(Effect.flip);
465-
expect(error.detail).toContain("wrote files");
466-
yield* fixture.assertCleaned;
467-
}).pipe(Effect.scoped),
454+
it.effect.each([
455+
{ relativePath: "unexpected.txt", directory: false },
456+
{ relativePath: ".agents/skills/unexpected.txt", directory: false },
457+
{ relativePath: ".gemini/skills/unexpected.txt", directory: false },
458+
{ relativePath: ".gemini/unexpected", directory: true },
459+
{ relativePath: ".agents/skills", directory: false },
460+
])(
461+
"rejects a helper that writes $relativePath in its temporary workspace",
462+
({ relativePath, directory }) =>
463+
Effect.gen(function* () {
464+
const fs = yield* FileSystem.FileSystem;
465+
const path = yield* Path.Path;
466+
const fixture = yield* makeFixture({
467+
startupSkills: true,
468+
prompt: ({ cwd, emit }) =>
469+
Effect.gen(function* () {
470+
const entry = path.join(cwd, relativePath);
471+
if (yield* fs.exists(entry).pipe(Effect.orDie)) {
472+
yield* fs.remove(entry, { recursive: true }).pipe(Effect.orDie);
473+
}
474+
yield* (
475+
directory ? fs.makeDirectory(entry) : fs.writeFileString(entry, "unexpected")
476+
).pipe(Effect.orDie);
477+
yield* emit({
478+
sessionUpdate: "agent_message_chunk",
479+
content: { type: "text", text: '{"title":"Ignored output"}' },
480+
});
481+
return { stopReason: "end_turn" };
482+
}),
483+
});
484+
const error = yield* fixture.textGeneration
485+
.generateThreadTitle(fixture.titleInput)
486+
.pipe(Effect.flip);
487+
expect(error.detail).toContain("wrote files");
488+
yield* fixture.assertCleaned;
489+
}).pipe(Effect.scoped),
490+
);
491+
492+
it.effect.each([".agents", ".gemini/skills"])(
493+
"rejects a helper that replaces %s with a symlink",
494+
(relativePath) =>
495+
Effect.gen(function* () {
496+
const fs = yield* FileSystem.FileSystem;
497+
const path = yield* Path.Path;
498+
const target = yield* fs.makeTempDirectoryScoped({ prefix: "t3-antigravity-link-test-" });
499+
const fixture = yield* makeFixture({
500+
startupSkills: true,
501+
prompt: ({ cwd, emit }) =>
502+
Effect.gen(function* () {
503+
const link = path.join(cwd, relativePath);
504+
yield* fs.remove(link, { recursive: true }).pipe(Effect.orDie);
505+
yield* fs.symlink(target, link).pipe(Effect.orDie);
506+
yield* emit({
507+
sessionUpdate: "agent_message_chunk",
508+
content: { type: "text", text: '{"title":"Ignored output"}' },
509+
});
510+
return { stopReason: "end_turn" };
511+
}),
512+
});
513+
const error = yield* fixture.textGeneration
514+
.generateThreadTitle(fixture.titleInput)
515+
.pipe(Effect.flip);
516+
expect(error.detail).toContain("wrote files");
517+
expect(yield* fs.exists(target)).toBe(true);
518+
yield* fixture.assertCleaned;
519+
}).pipe(Effect.scoped),
468520
);
469521

470522
it.effect("uses the native default without sending T3's default selection as a model ID", () =>
@@ -576,3 +628,15 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => {
576628
}).pipe(Effect.scoped),
577629
);
578630
});
631+
632+
it.effect("retains filesystem services supplied only during construction", () =>
633+
Effect.gen(function* () {
634+
const fixture = yield* makeFixture({ startupSkills: true }).pipe(
635+
Effect.provide(NodeServices.layer),
636+
);
637+
expect(yield* fixture.textGeneration.generateThreadTitle(fixture.titleInput)).toEqual({
638+
title: "Repair login",
639+
});
640+
yield* fixture.assertCleaned;
641+
}).pipe(Effect.scoped),
642+
);

‎apps/server/src/textGeneration/AntigravityTextGeneration.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,36 @@ const Configuration = Schema.Record(Schema.String, Schema.Unknown);
2424
const decodeConfiguration = Schema.decodeEffect(Schema.fromJsonString(Configuration));
2525
const decodeConfigurationObject = Schema.decodeUnknownEffect(Configuration);
2626

27+
const hasOnlyRuntimeDirectories = Effect.fn("AntigravityTextGeneration.hasOnlyRuntimeDirectories")(
28+
function* (cwd: string) {
29+
const fs = yield* FileSystem.FileSystem;
30+
const path = yield* Path.Path;
31+
const root = yield* fs.realPath(cwd);
32+
// ACP creates these empty skill directories before the first prompt.
33+
const allowed = new Set([
34+
path.join(root, ".agents"),
35+
path.join(root, ".agents", "skills"),
36+
path.join(root, ".gemini"),
37+
path.join(root, ".gemini", "skills"),
38+
]);
39+
const directories = [root];
40+
for (const directory of directories) {
41+
for (const name of yield* fs.readDirectory(directory)) {
42+
const entry = path.join(directory, name);
43+
if (
44+
!allowed.has(entry) ||
45+
(yield* fs.realPath(entry)) !== entry ||
46+
(yield* fs.stat(entry)).type !== "Directory"
47+
) {
48+
return false;
49+
}
50+
directories.push(entry);
51+
}
52+
}
53+
return true;
54+
},
55+
);
56+
2757
type AntigravityTextRuntime = Pick<
2858
AcpSessionRuntime.AcpSessionRuntime["Service"],
2959
| "start"
@@ -253,7 +283,11 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener
253283
);
254284
}).pipe(Effect.scoped);
255285

256-
if ((yield* fs.readDirectory(cwd)).length > 0) {
286+
const validWorkspace = yield* hasOnlyRuntimeDirectories(cwd).pipe(
287+
Effect.provideService(FileSystem.FileSystem, fs),
288+
Effect.provideService(Path.Path, path),
289+
);
290+
if (!validWorkspace) {
257291
return yield* new TextGenerationError({
258292
operation,
259293
detail: "Antigravity wrote files during text generation.",

0 commit comments

Comments
 (0)