The best way to control Claude Code, Codex and more from any computer or phone
fix(server): Antigravity threads follow the user's global AGENTS.md and GEMINI.md (#39531)
Julius Marminge committed
Nov 19, 2026 at 21:42 UTC
e923b5d8d8a8a206c60d9e290c00fc0c6694335d
2 files changed
+144
-10
apps/server/src/provider/antigravityAuthSupport.test.ts
+65
@@ -681,6 +681,71 @@ it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => {
681
}),
682
);
683
684
+ it.effect.skipIf(!symlinksSupported)(
685
+ "links the user's global rule files and never replaces the profile's own",
686
+ () =>
687
+ Effect.gen(function* () {
688
+ const fs = yield* FileSystem.FileSystem;
689
+ const path = yield* Path.Path;
690
+ const temporaryDirectory = yield* fs.makeTempDirectoryScoped();
691
+ const userHome = path.join(temporaryDirectory, "home");
692
+ const profileDirectory = path.join(temporaryDirectory, "profile");
693
+ const userGemini = path.join(userHome, ".gemini");
694
+ yield* fs.makeDirectory(userGemini, { recursive: true });
695
+ yield* fs.writeFileString(path.join(userGemini, "AGENTS.md"), "global agents rule");
696
+ yield* fs.writeFileString(path.join(userGemini, "GEMINI.md"), "global gemini rule");
697
+
698
+ yield* prepareAntigravityProfile({ profileDirectory, userHome });
699
+ expect(yield* fs.readLink(path.join(profileDirectory, "AGENTS.md"))).toBe(
700
+ path.join(userGemini, "AGENTS.md"),
701
+ );
702
+ expect(yield* fs.readLink(path.join(profileDirectory, "GEMINI.md"))).toBe(
703
+ path.join(userGemini, "GEMINI.md"),
704
+ );
705
+
706
+ yield* fs.remove(path.join(userGemini, "AGENTS.md"));
707
+ yield* fs.remove(path.join(profileDirectory, "GEMINI.md"));
708
+ yield* fs.writeFileString(path.join(profileDirectory, "GEMINI.md"), "profile's own rule");
709
+ yield* prepareAntigravityProfile({ profileDirectory, userHome });
710
+ expect(yield* fs.exists(path.join(profileDirectory, "AGENTS.md"))).toBe(false);
711
+ expect(yield* fs.readFileString(path.join(profileDirectory, "GEMINI.md"))).toBe(
712
+ "profile's own rule",
713
+ );
714
+ }),
715
+ );
716
+
717
+ it.effect("copies the user's global rule files on Windows and keeps the profile's own", () =>
718
+ Effect.gen(function* () {
719
+ const fs = yield* FileSystem.FileSystem;
720
+ const path = yield* Path.Path;
721
+ const temporaryDirectory = yield* fs.makeTempDirectoryScoped();
722
+ const userHome = path.join(temporaryDirectory, "home");
723
+ const profileDirectory = path.join(temporaryDirectory, "profile");
724
+ const userGemini = path.join(userHome, ".gemini");
725
+ const prepare = prepareAntigravityProfile({ profileDirectory, userHome, platform: "win32" });
726
+ const profileAgents = path.join(profileDirectory, "AGENTS.md");
727
+ const profileGemini = path.join(profileDirectory, "GEMINI.md");
728
+ yield* fs.makeDirectory(userGemini, { recursive: true });
729
+ yield* fs.writeFileString(path.join(userGemini, "AGENTS.md"), "global agents rule");
730
+ yield* fs.writeFileString(path.join(userGemini, "GEMINI.md"), "global gemini rule");
731
+
732
+ yield* prepare;
733
+ expect(yield* fs.readFileString(profileAgents)).toBe("global agents rule");
734
+ expect(yield* fs.readFileString(profileGemini)).toBe("global gemini rule");
735
+
736
+ yield* fs.writeFileString(path.join(userGemini, "AGENTS.md"), "edited agents rule");
737
+ yield* fs.remove(path.join(userGemini, "GEMINI.md"));
738
+ yield* prepare;
739
+ expect(yield* fs.readFileString(profileAgents)).toBe("edited agents rule");
740
+ expect(yield* fs.exists(profileGemini)).toBe(false);
741
+
742
+ yield* fs.writeFileString(profileGemini, "profile's own rule");
743
+ yield* fs.writeFileString(path.join(userGemini, "GEMINI.md"), "global gemini rule");
744
+ yield* prepare;
745
+ expect(yield* fs.readFileString(profileGemini)).toBe("profile's own rule");
746
+ }),
747
+ );
748
+
749
it.effect("rewrites the GCP block on every launch and never stores the API key", () =>
750
Effect.gen(function* () {
751
const fs = yield* FileSystem.FileSystem;
apps/server/src/provider/antigravityAuthSupport.ts
+79
-10
@@ -8,6 +8,7 @@ import * as Digest from "effect/crypto/Digest";
8
import * as Effect from "effect/Effect";
9
import * as Hex from "effect/encoding/Hex";
10
import * as FileSystem from "effect/FileSystem";
11
+import * as Option from "effect/Option";
12
import * as Path from "effect/Path";
13
import type * as PlatformError from "effect/PlatformError";
14
import * as Schema from "effect/Schema";
@@ -243,23 +244,34 @@ class AntigravitySkillLinkError extends Schema.TaggedError<AntigravitySkillLinkE
244
{ link: Schema.String, cause: Schema.Defect() },
245
) {
246
override get message(): string {
246
- return `Could not link Antigravity user skills at ${this.link}.`;
247
+ return `Could not link Antigravity user configuration at ${this.link}.`;
248
}
249
}
250
250
-/** Private GEMINI_HOME isolates credentials/hooks/MCP; link global skills from the real ~/.gemini. */
251
-const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(function* (input: {
251
+const antigravityUserRuleFiles = ["AGENTS.md", "GEMINI.md"] as const;
252
+
253
+/** Private GEMINI_HOME isolates credentials/hooks/MCP; link global skills and rules from the real ~/.gemini. */
254
+const linkAntigravityUserConfig = Effect.fn("linkAntigravityUserConfig")(function* (input: {
255
readonly profileDirectory: string;
256
readonly userHome: string;
257
readonly platform: NodeJS.Platform;
258
}): Effect.fn.Return<void, never, FileSystem.FileSystem | Path.Path> {
259
const fs = yield* FileSystem.FileSystem;
260
const path = yield* Path.Path;
261
+ const userGemini = path.join(input.userHome, ".gemini");
262
const links = antigravityUserSkillDirectories(path, input.profileDirectory);
259
- const targets = antigravityUserSkillDirectories(path, path.join(input.userHome, ".gemini"));
260
- for (const [link, target] of [
261
- [links[0], targets[0]],
262
- [links[1], targets[1]],
263
+ const targets = antigravityUserSkillDirectories(path, userGemini);
264
+ const directoryType = input.platform === "win32" ? "junction" : "dir";
265
+ for (const [link, target, type] of [
266
+ [links[0], targets[0], directoryType],
267
+ [links[1], targets[1], directoryType],
268
+ // File symlinks need elevation or Developer Mode on Windows, so rules are copied there.
269
+ ...(input.platform === "win32"
270
+ ? []
271
+ : antigravityUserRuleFiles.map(
272
+ (name) =>
273
+ [path.join(input.profileDirectory, name), path.join(userGemini, name), "file"] as const,
274
+ )),
275
] as const) {
276
yield* Effect.gen(function* () {
277
// The harness creates these folders itself, and mkdir fails on a dangling link.
@@ -292,12 +304,59 @@ const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(functio
304
}
305
yield* fs.makeDirectory(path.dirname(link), { recursive: true });
306
yield* Effect.tryPromise({
295
- try: () => NodeFSP.symlink(target, link, input.platform === "win32" ? "junction" : "dir"),
307
+ try: () => NodeFSP.symlink(target, link, type),
308
catch: (cause) => new AntigravitySkillLinkError({ link, cause }),
309
});
310
}).pipe(
311
Effect.catch((error) =>
300
- Effect.logWarning("Antigravity user skills are not linked into the profile.", {
312
+ Effect.logWarning("Antigravity user configuration is not linked into the profile.", {
313
+ link,
314
+ target,
315
+ error,
316
+ }),
317
+ ),
318
+ );
319
+ }
320
+});
321
+
322
+const RuleCopiesJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.String));
323
+const decodeRuleCopies = Schema.decodeUnknownOption(RuleCopiesJson);
324
+const encodeRuleCopies = Schema.encodeSync(RuleCopiesJson);
325
+
326
+/** Copies refresh each launch; the recorded copy keeps a file the profile owns or edited untouched. */
327
+const copyAntigravityUserRuleFiles = Effect.fn("copyAntigravityUserRuleFiles")(function* (input: {
328
+ readonly profileDirectory: string;
329
+ readonly userHome: string;
330
+}): Effect.fn.Return<void, never, FileSystem.FileSystem | Path.Path> {
331
+ const fs = yield* FileSystem.FileSystem;
332
+ const path = yield* Path.Path;
333
+ const manifestPath = path.join(input.profileDirectory, ".t3-rule-copies.json");
334
+ const readOptional = (file: string) =>
335
+ fs.readFileString(file).pipe(Effect.orElseSucceed((): string | undefined => undefined));
336
+ const manifestText = yield* readOptional(manifestPath);
337
+ const copies: Record<string, string> = {
338
+ ...Option.getOrElse(decodeRuleCopies(manifestText), () => ({})),
339
+ };
340
+ for (const name of antigravityUserRuleFiles) {
341
+ const link = path.join(input.profileDirectory, name);
342
+ const target = path.join(input.userHome, ".gemini", name);
343
+ yield* Effect.gen(function* () {
344
+ const current = yield* readOptional(link);
345
+ if (current !== undefined && current !== copies[name]) {
346
+ delete copies[name];
347
+ return;
348
+ }
349
+ const source = yield* readOptional(target);
350
+ if (source === undefined) {
351
+ if (current !== undefined) yield* fs.remove(link);
352
+ delete copies[name];
353
+ return;
354
+ }
355
+ yield* fs.writeFileString(link, source);
356
+ copies[name] = source;
357
+ }).pipe(
358
+ Effect.catch((error) =>
359
+ Effect.logWarning("Antigravity user rules are not copied into the profile.", {
360
link,
361
target,
362
error,
@@ -305,6 +364,13 @@ const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(functio
364
),
365
);
366
}
367
+ yield* fs
368
+ .writeFileString(manifestPath, encodeRuleCopies(copies))
369
+ .pipe(
370
+ Effect.catch((error) =>
371
+ Effect.logWarning("Antigravity rule copy record could not be written.", { error }),
372
+ ),
373
+ );
374
});
375
376
export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(function* (input: {
@@ -453,7 +519,10 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
519
authSupportError("The Antigravity profile settings could not be written."),
520
),
521
);
456
- yield* linkAntigravityUserSkills({ profileDirectory: geminiHome, userHome, platform });
522
+ yield* linkAntigravityUserConfig({ profileDirectory: geminiHome, userHome, platform });
523
+ if (platform === "win32") {
524
+ yield* copyAntigravityUserRuleFiles({ profileDirectory: geminiHome, userHome });
525
+ }
526
return profile;
527
});
528