Skip to content

Commit 623344a

Browse files
fix(antigravity): accept empty startup skill directories (pingdotgg#27191)
Co-authored-by: maria-rcks <[email protected]>
1 parent e8c70f5 commit 623344a

2 files changed

Lines changed: 99 additions & 27 deletions

File tree

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

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ProviderInstanceId,
66
ProviderSetupError,
77
} from "@t3tools/contracts";
8+
import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
89
import * as Deferred from "effect/Deferred";
910
import * as Effect from "effect/Effect";
1011
import * as Exit from "effect/Exit";
@@ -60,6 +61,7 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
6061
readonly startError?: AcpError;
6162
readonly rejectAdmission?: boolean;
6263
readonly sessionId?: string;
64+
readonly startupSkills?: boolean;
6365
} = {},
6466
) {
6567
const fs = yield* FileSystem.FileSystem;
@@ -135,6 +137,13 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
135137
start: () =>
136138
Effect.gen(function* () {
137139
if (options.startError) return yield* options.startError;
140+
if (options.startupSkills) {
141+
for (const directory of [".agents", ".gemini"]) {
142+
yield* fs
143+
.makeDirectory(path.join(cwd, directory, "skills"), { recursive: true })
144+
.pipe(Effect.orDie);
145+
}
146+
}
138147
yield* fs.makeDirectory(brainDirectory, { recursive: true }).pipe(Effect.orDie);
139148
yield* fs.writeFileString(`${sessionBase}.db`, "helper session").pipe(Effect.orDie);
140149
yield* fs.writeFileString(`${sessionBase}.db-wal`, "helper journal").pipe(Effect.orDie);
@@ -279,11 +288,12 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function*
279288
});
280289

281290
it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => {
282-
it.effect(
283-
"generates all helper types in empty workspaces and removes only owned session files",
284-
() =>
291+
it.effect.each([false, true])(
292+
"generates all helper types and cleans up with startupSkills=%s",
293+
(startupSkills) =>
285294
Effect.gen(function* () {
286295
const fixture = yield* makeFixture({
296+
startupSkills,
287297
outputs: [
288298
'{"subject":" Repair Google login.\\nExtra line","body":" Keep the remote callback. ","branch":"Repair Login"}',
289299
'```json\n{"title":" Repair Google login\\nExtra line","body":" ## Summary\\nSupport remote callbacks. "}\n```',
@@ -442,29 +452,51 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => {
442452
}).pipe(Effect.scoped),
443453
);
444454

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),
455+
it.effect.each([
456+
{ relativePath: "unexpected.txt", kind: "file" },
457+
{ relativePath: ".agents/skills/unexpected.txt", kind: "file" },
458+
{ relativePath: ".gemini/unexpected", kind: "directory" },
459+
{ relativePath: ".agents/skills", kind: "file" },
460+
...(symlinksSupported ? [{ relativePath: ".gemini/skills", kind: "symlink" }] : []),
461+
])(
462+
"rejects an unexpected $kind at $relativePath in its temporary workspace",
463+
({ relativePath, kind }) =>
464+
Effect.gen(function* () {
465+
const fs = yield* FileSystem.FileSystem;
466+
const path = yield* Path.Path;
467+
const target =
468+
kind === "symlink"
469+
? yield* fs.makeTempDirectoryScoped({ prefix: "t3-antigravity-link-test-" })
470+
: undefined;
471+
const fixture = yield* makeFixture({
472+
startupSkills: true,
473+
prompt: ({ cwd, emit }) =>
474+
Effect.gen(function* () {
475+
const entry = path.join(cwd, relativePath);
476+
if (yield* fs.exists(entry).pipe(Effect.orDie)) {
477+
yield* fs.remove(entry, { recursive: true }).pipe(Effect.orDie);
478+
}
479+
yield* (
480+
target !== undefined
481+
? fs.symlink(target, entry)
482+
: kind === "directory"
483+
? fs.makeDirectory(entry)
484+
: fs.writeFileString(entry, "unexpected")
485+
).pipe(Effect.orDie);
486+
yield* emit({
487+
sessionUpdate: "agent_message_chunk",
488+
content: { type: "text", text: '{"title":"Ignored output"}' },
489+
});
490+
return { stopReason: "end_turn" };
491+
}),
492+
});
493+
const error = yield* fixture.textGeneration
494+
.generateThreadTitle(fixture.titleInput)
495+
.pipe(Effect.flip);
496+
expect(error.detail).toContain("wrote files");
497+
if (target !== undefined) expect(yield* fs.exists(target)).toBe(true);
498+
yield* fixture.assertCleaned;
499+
}).pipe(Effect.scoped),
468500
);
469501

470502
it.effect("uses the native default without sending T3's default selection as a model ID", () =>
@@ -576,3 +608,15 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => {
576608
}).pipe(Effect.scoped),
577609
);
578610
});
611+
612+
it.effect("retains filesystem services supplied only during construction", () =>
613+
Effect.gen(function* () {
614+
const fixture = yield* makeFixture({ startupSkills: true }).pipe(
615+
Effect.provide(NodeServices.layer),
616+
);
617+
expect(yield* fixture.textGeneration.generateThreadTitle(fixture.titleInput)).toEqual({
618+
title: "Repair login",
619+
});
620+
yield* fixture.assertCleaned;
621+
}).pipe(Effect.scoped),
622+
);

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,34 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener
9494
) {
9595
const fs = yield* FileSystem.FileSystem;
9696
const path = yield* Path.Path;
97+
const hasOnlyRuntimeDirectories = Effect.fn(
98+
"AntigravityTextGeneration.hasOnlyRuntimeDirectories",
99+
)(function* (cwd: string) {
100+
const root = yield* fs.realPath(cwd);
101+
// ACP creates these empty skill directories before the first prompt.
102+
const allowed = new Set([
103+
path.join(root, ".agents"),
104+
path.join(root, ".agents", "skills"),
105+
path.join(root, ".gemini"),
106+
path.join(root, ".gemini", "skills"),
107+
]);
108+
const directories = [root];
109+
for (const directory of directories) {
110+
for (const name of yield* fs.readDirectory(directory)) {
111+
const entry = path.join(directory, name);
112+
if (
113+
!allowed.has(entry) ||
114+
(yield* fs.realPath(entry)) !== entry ||
115+
(yield* fs.stat(entry)).type !== "Directory"
116+
) {
117+
return false;
118+
}
119+
directories.push(entry);
120+
}
121+
}
122+
return true;
123+
});
124+
97125
const available = isAntigravityTextGenerationAvailable(options.profileDirectory).pipe(
98126
Effect.provideService(FileSystem.FileSystem, fs),
99127
Effect.provideService(Path.Path, path),
@@ -253,7 +281,7 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener
253281
);
254282
}).pipe(Effect.scoped);
255283

256-
if ((yield* fs.readDirectory(cwd)).length > 0) {
284+
if (!(yield* hasOnlyRuntimeDirectories(cwd))) {
257285
return yield* new TextGenerationError({
258286
operation,
259287
detail: "Antigravity wrote files during text generation.",

0 commit comments

Comments
 (0)