From b9c566b3f318f5a845f5554ad421efa7b3f9c8d8 Mon Sep 17 00:00:00 2001 From: "Fatih C. Akyon" <34196005+fcakyon@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:47:45 +0300 Subject: [PATCH 1/4] fix: link enabled Antigravity user plugins Antigravity instances run with a private GEMINI_HOME, so plugins installed in ~/.gemini/config/plugins never loaded in T3 Code sessions or showed in the skill picker. Profile preparation now links each enabled plugin with a manifest into /config/plugins, keeps plugins installed in the profile itself, and removes its own links once a plugin is disabled or uninstalled. Skill discovery and the text generation hooks and MCP check read the same plugin set, including user plugins the next launch will link. verification: antigravityAuthSupport, AntigravitySkills and AntigravityTextGeneration tests 91 passed, check:changed upstream/main passed format, lint, knip, graphql, typecheck (3 packages) and test (5 files, 100 passed), live agy 1.5.11 session/new lists global-ag-skill, global-gem-skill, global-on-skill and profile-local-skill --- .../Drivers/AntigravityDriver.test.ts | 2 + .../src/provider/Drivers/AntigravityDriver.ts | 6 +- .../Drivers/AntigravitySkills.test.ts | 57 ++++++++ .../src/provider/Drivers/AntigravitySkills.ts | 122 +++++++++++++----- .../provider/antigravityAuthSupport.test.ts | 70 ++++++++++ .../src/provider/antigravityAuthSupport.ts | 51 ++++++++ .../AntigravityTextGeneration.test.ts | 74 ++++++++++- .../AntigravityTextGeneration.ts | 66 ++++++++-- docs/internals/providers.md | 9 +- docs/user/providers-antigravity.md | 7 + 10 files changed, 415 insertions(+), 49 deletions(-) diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts index 2ee99a6fbbfe3..364db1f383f14 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts @@ -220,6 +220,8 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* ( config: { ...AntigravityDriver.defaultConfig(), ...options.config }, environment: [ { name: "PATH", value: instancePath }, + // Keep the developer's ~/.gemini skills and plugins out of the profile. + { name: "HOME", value: path.join(root, "home") }, { name: "T3_ACP_ANTIGRAVITY", value: "1" }, { name: "T3_ACP_REQUEST_LOG_PATH", value: requestLog }, { name: "GEMINI_API_KEY", value: "must-not-be-used" }, diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.ts b/apps/server/src/provider/Drivers/AntigravityDriver.ts index 1117fc3b9376c..820e4e272544b 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.ts @@ -451,7 +451,10 @@ export const AntigravityDriver: ProviderDriver< probeUsage: usage.probe, clearUsage: usage.clear, auth: { type: auth.authMethod, label: antigravityAuthLabel(auth.authMethod) }, - supportsTextGeneration: isAntigravityTextGenerationAvailable(profileDirectory).pipe( + supportsTextGeneration: isAntigravityTextGenerationAvailable({ + profileDirectory, + userHome, + }).pipe( Effect.provideService(FileSystem.FileSystem, fileSystem), Effect.provideService(Path.Path, path), Effect.orElseSucceed(() => false), @@ -499,6 +502,7 @@ export const AntigravityDriver: ProviderDriver< }); const textGeneration = yield* makeAntigravityTextGeneration({ profileDirectory, + userHome, defaultModel, withProcess: authFlow.withProcess, makeRuntime: (cwd) => diff --git a/apps/server/src/provider/Drivers/AntigravitySkills.test.ts b/apps/server/src/provider/Drivers/AntigravitySkills.test.ts index 79f9bc438447c..d171fff87df5b 100644 --- a/apps/server/src/provider/Drivers/AntigravitySkills.test.ts +++ b/apps/server/src/provider/Drivers/AntigravitySkills.test.ts @@ -121,6 +121,63 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => { }), ); + it.effect.skipIf(!symlinksSupported)( + "reads skills from enabled user plugins before the profile links them", + () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const input = yield* makeWorkspace(); + const config = path.join(input.userHome, ".gemini", "config"); + const profileConfig = path.join(input.profileDirectory, "config"); + for (const [plugin, manifest] of [ + ["on", "plugin.json"], + ["ag", ".antigravity-plugin/plugin.json"], + ["gem", ".gemini-plugin/plugin.json"], + ["off", "plugin.json"], + ["bare", undefined], + ["profile-off", "plugin.json"], + ["shadowed", "plugin.json"], + ] as const) { + const directory = path.join(config, "plugins", plugin); + yield* writeSkill(path.join(directory, "skills", plugin), `---\nname: ${plugin}\n---\n`); + if (manifest !== undefined) { + yield* fileSystem.makeDirectory(path.dirname(path.join(directory, manifest)), { + recursive: true, + }); + yield* fileSystem.writeFileString(path.join(directory, manifest), "{}"); + } + } + yield* fileSystem.writeFileString( + path.join(config, "config.json"), + JSON.stringify({ plugins: { off: { enabled: false } } }), + ); + yield* writeSkill( + path.join(profileConfig, "plugins", "shadowed", "skills", "own"), + "---\nname: profile-shadowed\n---\n", + ); + yield* fileSystem.writeFileString( + path.join(profileConfig, "config.json"), + JSON.stringify({ plugins: { "profile-off": { enabled: false } } }), + ); + // A link from before "off" was disabled goes on the next launch. + yield* fileSystem.symlink( + path.join(config, "plugins", "off"), + path.join(profileConfig, "plugins", "off"), + ); + + assert.deepEqual( + (yield* discoverAntigravitySkills(input)).map((skill) => [skill.name, skill.scope]), + [ + ["ag", "user"], + ["gem", "user"], + ["on", "user"], + ["profile-shadowed", "user"], + ], + ); + }), + ); + it.effect("uses native root order for duplicate names", () => Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; diff --git a/apps/server/src/provider/Drivers/AntigravitySkills.ts b/apps/server/src/provider/Drivers/AntigravitySkills.ts index ddea4239745e8..c8cf6e150e05d 100644 --- a/apps/server/src/provider/Drivers/AntigravitySkills.ts +++ b/apps/server/src/provider/Drivers/AntigravitySkills.ts @@ -90,6 +90,95 @@ const readIfPresent = ( }), ); +/** Plugin names that a GEMINI_HOME's config.json turns off. */ +const readAntigravityDisabledPlugins = Effect.fn("readAntigravityDisabledPlugins")(function* ( + configPath: string, +) { + const fileSystem = yield* FileSystem.FileSystem; + const info = yield* readIfPresent(fileSystem.stat(configPath), configPath); + if (info?.type !== "File") return new Set(); + if (info.size > BigInt(MAX_SKILL_BYTES)) { + return yield* new AntigravitySkillsProbeError({ + reason: "scan-budget-exhausted", + path: configPath, + }); + } + const config = yield* readIfPresent(fileSystem.readFileString(configPath), configPath); + const preferences = config === undefined ? undefined : decodePluginPreferences(config); + return new Set( + Object.entries( + (preferences?._tag === "Some" ? preferences.value.plugins : undefined) ?? {}, + ).flatMap(([name, plugin]) => (plugin.enabled === false ? [name] : [])), + ); +}); + +/** agy skips a plugin folder without one of these manifests. */ +export const ANTIGRAVITY_PLUGIN_MANIFESTS = [ + "plugin.json", + ".antigravity-plugin/plugin.json", + ".gemini-plugin/plugin.json", +] as const; + +/** Enabled plugins in the user's ~/.gemini, by name, that a profile links and agy then loads. */ +export const readAntigravityUserPlugins = Effect.fn("readAntigravityUserPlugins")(function* ( + userHome: string, +) { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const pluginsDirectory = path.join(userHome, ".gemini", "config", "plugins"); + const plugins = new Map(); + const names = yield* readIfPresent(fileSystem.readDirectory(pluginsDirectory), pluginsDirectory); + if (names === undefined || names.length === 0) return plugins; + const disabled = yield* readAntigravityDisabledPlugins( + path.join(userHome, ".gemini", "config", "config.json"), + ); + for (const name of names.toSorted()) { + if (disabled.has(name)) continue; + const pluginDirectory = path.join(pluginsDirectory, name); + const info = yield* readIfPresent(fileSystem.stat(pluginDirectory), pluginDirectory); + if (info?.type !== "Directory") continue; + for (const manifest of ANTIGRAVITY_PLUGIN_MANIFESTS) { + const manifestPath = path.join(pluginDirectory, manifest); + if ((yield* readIfPresent(fileSystem.stat(manifestPath), manifestPath))?.type === "File") { + plugins.set(name, pluginDirectory); + break; + } + } + } + return plugins; +}); + +/** Plugins agy loads from the profile once its next launch relinks the enabled user plugins. */ +export const readAntigravityPlugins = Effect.fn("readAntigravityPlugins")(function* (input: { + readonly profileDirectory: string; + readonly userHome: string; +}) { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const pluginsDirectory = path.join(input.profileDirectory, "config", "plugins"); + const userPluginsDirectory = path.join(input.userHome, ".gemini", "config", "plugins"); + const plugins = yield* readAntigravityUserPlugins(input.userHome); + const names = yield* readIfPresent(fileSystem.readDirectory(pluginsDirectory), pluginsDirectory); + for (const name of names ?? []) { + const pluginDirectory = path.join(pluginsDirectory, name); + const target = yield* fileSystem.readLink(pluginDirectory).pipe( + Effect.map((value) => path.resolve(pluginsDirectory, value)), + Effect.orElseSucceed(() => undefined), + ); + // Profile preparation replaces its links into the user's plugins, so those come from above. + if (target !== undefined && path.dirname(target) === userPluginsDirectory) continue; + const info = yield* readIfPresent(fileSystem.stat(pluginDirectory), pluginDirectory); + if (info?.type === "Directory") plugins.set(name, pluginDirectory); + } + const disabled = yield* readAntigravityDisabledPlugins( + path.join(input.profileDirectory, "config", "config.json"), + ); + return [...plugins] + .filter(([name]) => !disabled.has(name)) + .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)) + .map(([, pluginDirectory]) => pluginDirectory); +}); + function parseSkillFrontmatter(contents: string, fileName: string) { const start = contents.indexOf("---"); if (start === -1) return undefined; @@ -251,37 +340,8 @@ export const discoverAntigravitySkills = Effect.fn("discoverAntigravitySkills")( yield* scanDirectory(root.directory, root.scope, true); } - const pluginsDirectory = path.join(input.profileDirectory, "config", "plugins"); - const plugins = yield* readIfPresent( - fileSystem.readDirectory(pluginsDirectory), - pluginsDirectory, - ); - if (plugins !== undefined && plugins.length > 0) { - const configPath = path.join(input.profileDirectory, "config", "config.json"); - const configInfo = yield* readIfPresent(fileSystem.stat(configPath), configPath); - if (configInfo?.type === "File" && configInfo.size > BigInt(MAX_SKILL_BYTES)) { - return yield* new AntigravitySkillsProbeError({ - reason: "scan-budget-exhausted", - path: configPath, - }); - } - const config = - configInfo?.type === "File" - ? yield* readIfPresent(fileSystem.readFileString(configPath), configPath) - : undefined; - const preferences = config === undefined ? undefined : decodePluginPreferences(config); - const disabled = new Set( - Object.entries( - (preferences?._tag === "Some" ? preferences.value.plugins : undefined) ?? {}, - ).flatMap(([name, plugin]) => (plugin.enabled === false ? [name] : [])), - ); - for (const plugin of plugins.toSorted()) { - if (disabled.has(plugin)) continue; - const pluginDirectory = path.join(pluginsDirectory, plugin); - const info = yield* readIfPresent(fileSystem.stat(pluginDirectory), pluginDirectory); - if (info?.type !== "Directory") continue; - yield* scanDirectory(path.join(pluginDirectory, "skills"), "user", true); - } + for (const pluginDirectory of yield* readAntigravityPlugins(input)) { + yield* scanDirectory(path.join(pluginDirectory, "skills"), "user", true); } return [...skillsByName.values()].sort((left, right) => left.name.localeCompare(right.name)); }); diff --git a/apps/server/src/provider/antigravityAuthSupport.test.ts b/apps/server/src/provider/antigravityAuthSupport.test.ts index 4476ccd3a2d1c..105580c8d6d3a 100644 --- a/apps/server/src/provider/antigravityAuthSupport.test.ts +++ b/apps/server/src/provider/antigravityAuthSupport.test.ts @@ -669,6 +669,7 @@ it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => { expect(yield* fs.exists(path.join(profileDirectory, "config", "mcp_config.json"))).toBe( false, ); + expect(yield* fs.exists(path.join(profileDirectory, "config", "plugins"))).toBe(false); // The harness leaves an empty folder where the link was skipped. yield* fs.makeDirectory(cliLink, { recursive: true }); @@ -694,6 +695,75 @@ it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => { }), ); + it.effect.skipIf(!symlinksSupported)( + "links each enabled user plugin and removes only its own stale links", + () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const temporaryDirectory = yield* fs.makeTempDirectoryScoped(); + const userHome = path.join(temporaryDirectory, "home"); + const profileDirectory = path.join(temporaryDirectory, "profile"); + const config = path.join(userHome, ".gemini", "config"); + const userPlugins = path.join(config, "plugins"); + const profilePlugins = path.join(profileDirectory, "config", "plugins"); + const write = Effect.fn("writeFile")(function* (file: string, text: string) { + yield* fs.makeDirectory(path.dirname(file), { recursive: true }); + yield* fs.writeFileString(file, text); + }); + const linkTarget = (name: string) => + fs.readLink(path.join(profilePlugins, name)).pipe(Effect.orElseSucceed(() => undefined)); + for (const [plugin, manifest] of [ + ["on", "plugin.json"], + ["ag", ".antigravity-plugin/plugin.json"], + ["gem", ".gemini-plugin/plugin.json"], + ["off", "plugin.json"], + ["bare", "skills/bare/SKILL.md"], + ["local", "plugin.json"], + ] as const) { + yield* write(path.join(userPlugins, plugin, manifest), "{}"); + } + const disable = (plugins: ReadonlyArray) => + write( + path.join(config, "config.json"), + encodeUnknownJson({ + plugins: Object.fromEntries(plugins.map((name) => [name, { enabled: false }])), + }), + ); + yield* disable(["off"]); + yield* write(path.join(config, "mcp_config.json"), '{"mcpServers":{"s":{}}}'); + yield* write(path.join(config, "hooks.json"), '{"hooks":{"Stop":[]}}'); + yield* write(path.join(profilePlugins, "local", "plugin.json"), "{}"); + const foreign = path.join(temporaryDirectory, "foreign"); + yield* fs.makeDirectory(foreign); + yield* fs.symlink(foreign, path.join(profilePlugins, "foreign")); + + yield* prepareAntigravityProfile({ profileDirectory, userHome }); + for (const plugin of ["on", "ag", "gem"]) { + expect(yield* linkTarget(plugin)).toBe(path.join(userPlugins, plugin)); + } + expect(yield* fs.exists(path.join(profilePlugins, "off"))).toBe(false); + expect(yield* fs.exists(path.join(profilePlugins, "bare"))).toBe(false); + expect(yield* linkTarget("local")).toBeUndefined(); + expect(yield* linkTarget("foreign")).toBe(foreign); + for (const name of ["mcp_config.json", "hooks.json"]) { + expect(yield* fs.exists(path.join(profileDirectory, "config", name))).toBe(false); + } + + yield* disable(["on"]); + yield* fs.remove(path.join(userPlugins, "ag"), { recursive: true }); + yield* fs.remove(path.join(profilePlugins, "gem")); + yield* fs.symlink(path.join(userPlugins, "off"), path.join(profilePlugins, "gem")); + yield* prepareAntigravityProfile({ profileDirectory, userHome }); + expect(yield* linkTarget("on")).toBeUndefined(); + expect(yield* linkTarget("ag")).toBeUndefined(); + expect(yield* linkTarget("gem")).toBe(path.join(userPlugins, "gem")); + expect(yield* linkTarget("off")).toBe(path.join(userPlugins, "off")); + expect(yield* fs.exists(path.join(profilePlugins, "local", "plugin.json"))).toBe(true); + expect(yield* linkTarget("foreign")).toBe(foreign); + }), + ); + it.effect("rewrites the GCP block on every launch and never stores the API key", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; diff --git a/apps/server/src/provider/antigravityAuthSupport.ts b/apps/server/src/provider/antigravityAuthSupport.ts index 47be6bf31ccae..0318407c46e94 100644 --- a/apps/server/src/provider/antigravityAuthSupport.ts +++ b/apps/server/src/provider/antigravityAuthSupport.ts @@ -20,6 +20,7 @@ import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStr import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime"; import { antigravityUserSkillDirectories, + readAntigravityUserPlugins, resolveAntigravityUserHome, } from "./Drivers/AntigravitySkills.ts"; @@ -306,6 +307,55 @@ const linkAntigravityUserSkills = Effect.fn("linkAntigravityUserSkills")(functio } }); +/** Link each enabled plugin instead of the folder, so plugins installed into the profile keep working. */ +const linkAntigravityUserPlugins = Effect.fn("linkAntigravityUserPlugins")(function* (input: { + readonly profileDirectory: string; + readonly userHome: string; + readonly platform: NodeJS.Platform; +}): Effect.fn.Return { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const userPlugins = path.join(input.userHome, ".gemini", "config", "plugins"); + const profilePlugins = path.join(input.profileDirectory, "config", "plugins"); + yield* Effect.gen(function* () { + const enabled = yield* readAntigravityUserPlugins(input.userHome); + const existing = new Set( + yield* fs + .readDirectory(profilePlugins) + .pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed([]))), + ); + for (const name of existing) { + const link = path.join(profilePlugins, name); + const target = yield* fs.readLink(link).pipe( + Effect.map((value): string | undefined => path.resolve(profilePlugins, value)), + Effect.orElseSucceed(() => undefined), + ); + // Only links into the user's plugins are ours. Real folders and other links stay. + if (target === undefined || path.dirname(target) !== userPlugins) continue; + if (enabled.get(name) === target) continue; + yield* fs.remove(link); + existing.delete(name); + } + for (const [name, target] of enabled) { + if (existing.has(name)) continue; + const link = path.join(profilePlugins, name); + yield* fs.makeDirectory(profilePlugins, { recursive: true }); + yield* Effect.tryPromise({ + try: () => NodeFSP.symlink(target, link, input.platform === "win32" ? "junction" : "dir"), + catch: (cause) => new AntigravitySkillLinkError({ link, cause }), + }); + } + }).pipe( + Effect.catch((error) => + Effect.logWarning("Antigravity user plugins are not linked into the profile.", { + profilePlugins, + userPlugins, + error, + }), + ), + ); +}); + export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(function* (input: { readonly profileDirectory: string; readonly baseEnv?: NodeJS.ProcessEnv; @@ -453,6 +503,7 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")( ), ); yield* linkAntigravityUserSkills({ profileDirectory: geminiHome, userHome, platform }); + yield* linkAntigravityUserPlugins({ profileDirectory: geminiHome, userHome, platform }); return profile; }); diff --git a/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts b/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts index 5a410dbf342f7..1dae77b192a6d 100644 --- a/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts +++ b/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts @@ -68,6 +68,7 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function* const path = yield* Path.Path; const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-antigravity-text-test-" }); const profileDirectory = path.join(root, "profile"); + const userHome = path.join(root, "home"); const projectDirectory = path.join(root, "project"); const conversations = path.join(profileDirectory, "antigravity-acp", "conversations"); const nativeSessionId = options.sessionId ?? SESSION_ID; @@ -253,6 +254,7 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function* const textGeneration = yield* makeAntigravityTextGeneration({ profileDirectory, + userHome, makeRuntime, withProcess, }); @@ -275,6 +277,7 @@ const makeFixture = Effect.fn("makeAntigravityTextGenerationFixture")(function* fs, path, profileDirectory, + userHome, projectDirectory, sessionBase, brainDirectory, @@ -556,7 +559,7 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => { const configDirectory = fixture.path.join(fixture.profileDirectory, "config"); yield* fixture.fs.makeDirectory(configDirectory, { recursive: true }); yield* fixture.fs.writeFileString(fixture.path.join(configDirectory, name), value); - expect(yield* isAntigravityTextGenerationAvailable(fixture.profileDirectory)).toBe(available); + expect(yield* isAntigravityTextGenerationAvailable(fixture)).toBe(available); const result = yield* fixture.textGeneration .generateThreadTitle(fixture.titleInput) .pipe(Effect.exit); @@ -566,6 +569,75 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => { }), ); + it.effect.each([ + { + case: "a skills-only plugin", + files: { "skills/review/SKILL.md": "---\n---\n" }, + available: true, + }, + { case: "a hooks folder", files: { "hooks/hooks.json": "{}" }, available: false }, + { case: "hooks.json", files: { "hooks.json": '{"hooks":{"Stop":[]}}' }, available: false }, + { + case: "mcp_config.json", + files: { "mcp_config.json": '{"mcpServers":{"s":{"command":"do-not-run"}}}' }, + available: false, + }, + { + case: ".mcp.json", + files: { ".mcp.json": '{"s":{"command":"do-not-run"}}' }, + available: false, + }, + { + case: "manifest MCP servers", + files: { "plugin.json": '{"name":"p","mcpServers":{"s":{"command":"do-not-run"}}}' }, + available: false, + }, + { + case: "manifest hooks", + files: { ".gemini-plugin/plugin.json": '{"name":"p","hooks":"./hooks.json"}' }, + available: false, + }, + { + case: "a disabled plugin with MCP servers", + files: { ".mcp.json": '{"s":{"command":"do-not-run"}}' }, + disabled: true, + available: true, + }, + ])( + "checks plugin startup configuration before starting a helper: $case", + ({ files, disabled, available }) => + Effect.gen(function* () { + const fixture = yield* makeFixture(); + const { fs, path } = fixture; + const write = Effect.fn("writePluginFile")(function* (file: string, text: string) { + yield* fs.makeDirectory(path.dirname(file), { recursive: true }); + yield* fs.writeFileString(file, text); + }); + // agy links the user's plugins into the profile after this check, so both must pass. + for (const [config, manifest] of [ + [path.join(fixture.profileDirectory, "config"), undefined], + [path.join(fixture.userHome, ".gemini", "config"), '{"name":"p"}'], + ] as const) { + const plugin = path.join(config, "plugins", "p"); + if (manifest !== undefined) yield* write(path.join(plugin, "plugin.json"), manifest); + for (const [file, text] of Object.entries(files)) { + yield* write(path.join(plugin, file), text); + } + if (disabled) { + yield* write(path.join(config, "config.json"), '{"plugins":{"p":{"enabled":false}}}'); + } + expect(yield* isAntigravityTextGenerationAvailable(fixture)).toBe(available); + const result = yield* fixture.textGeneration + .generateThreadTitle(fixture.titleInput) + .pipe(Effect.exit); + expect(Exit.isSuccess(result)).toBe(available); + yield* fs.remove(config, { recursive: true }); + } + expect(fixture.state.workspaces.length).toBe(available ? 2 : 0); + yield* fixture.assertCleaned; + }), + ); + it.effect("does not launch during sign-out or before sign-in", () => Effect.gen(function* () { const fixture = yield* makeFixture({ rejectAdmission: true }); diff --git a/apps/server/src/textGeneration/AntigravityTextGeneration.ts b/apps/server/src/textGeneration/AntigravityTextGeneration.ts index b67bad85faf03..46cbff2bfa67a 100644 --- a/apps/server/src/textGeneration/AntigravityTextGeneration.ts +++ b/apps/server/src/textGeneration/AntigravityTextGeneration.ts @@ -17,6 +17,10 @@ import { ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE, isAntigravitySignInRequiredError, } from "../provider/antigravityAuthSupport.ts"; +import { + ANTIGRAVITY_PLUGIN_MANIFESTS, + readAntigravityPlugins, +} from "../provider/Drivers/AntigravitySkills.ts"; import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime"; import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations"; @@ -54,6 +58,7 @@ type AntigravityTextRuntime = Pick< export interface AntigravityTextGenerationOptions { readonly profileDirectory: string; + readonly userHome: string; readonly defaultModel?: Effect.Effect; readonly makeRuntime: ( cwd: string, @@ -64,38 +69,73 @@ export interface AntigravityTextGenerationOptions { ) => Effect.Effect; } -/** Global hooks and MCP servers can run before a helper can deny a tool request. */ +type Configuration = typeof Configuration.Type; +const hooksIn = (configuration: Configuration) => [configuration.hooks ?? configuration]; +const mcpServersIn = (configuration: Configuration) => [configuration.mcpServers ?? configuration]; +const pluginConfigurations = [ + ["hooks.json", hooksIn], + ["mcp_config.json", mcpServersIn], + [".mcp.json", mcpServersIn], + ...ANTIGRAVITY_PLUGIN_MANIFESTS.map( + (manifest) => + [ + manifest, + (configuration: Configuration) => [ + configuration.hooks ?? {}, + configuration.mcpServers ?? {}, + ], + ] as const, + ), +] as const; + +/** Global and plugin hooks and MCP servers can run before a helper can deny a tool request. */ export const isAntigravityTextGenerationAvailable = Effect.fn( "isAntigravityTextGenerationAvailable", -)(function* (profileDirectory: string) { +)(function* (input: { readonly profileDirectory: string; readonly userHome: string }) { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; - for (const name of ["hooks.json", "mcp_config.json"]) { - const configurationPath = path.join(profileDirectory, "config", name); + const isUnconfigured = Effect.fn("isAntigravityConfigurationEmpty")(function* ( + configurationPath: string, + select: (configuration: Configuration) => ReadonlyArray, + ) { if (!(yield* fs.exists(configurationPath))) { - continue; + return true; } const info = yield* fs.stat(configurationPath); if (info.type !== "File" || info.size > 64_000n) { return false; } // CLI 1.5.8 writes a 0-byte mcp_config.json before any server exists. - const empty = yield* fs.readFileString(configurationPath).pipe( + return yield* fs.readFileString(configurationPath).pipe( Effect.flatMap((text) => text.trim().length === 0 ? Effect.succeed(true) : decodeConfiguration(text).pipe( Effect.flatMap((configuration) => - decodeConfigurationObject( - configuration[name === "hooks.json" ? "hooks" : "mcpServers"] ?? configuration, - ), + Effect.forEach(select(configuration), (value) => decodeConfigurationObject(value)), ), - Effect.map((configuration) => Object.keys(configuration).length === 0), + Effect.map((values) => values.every((value) => Object.keys(value).length === 0)), ), ), Effect.orElseSucceed(() => false), ); - if (!empty) return false; + }); + + const config = path.join(input.profileDirectory, "config"); + if ( + !(yield* isUnconfigured(path.join(config, "hooks.json"), hooksIn)) || + !(yield* isUnconfigured(path.join(config, "mcp_config.json"), mcpServersIn)) + ) { + return false; + } + for (const pluginDirectory of yield* readAntigravityPlugins(input)) { + const hooks = yield* fs + .readDirectory(path.join(pluginDirectory, "hooks")) + .pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed([]))); + if (hooks.length > 0) return false; + for (const [file, select] of pluginConfigurations) { + if (!(yield* isUnconfigured(path.join(pluginDirectory, file), select))) return false; + } } return true; }); @@ -133,7 +173,7 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener return true; }); - const available = isAntigravityTextGenerationAvailable(options.profileDirectory).pipe( + const available = isAntigravityTextGenerationAvailable(options).pipe( Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path), ); @@ -148,7 +188,7 @@ export const makeAntigravityTextGeneration = Effect.fn("makeAntigravityTextGener return yield* new TextGenerationError({ operation, detail: - "Antigravity text generation is unavailable for profiles with global hooks or MCP configuration. Select another system model.", + "Antigravity text generation is unavailable for profiles with global or plugin hooks or MCP configuration. Select another system model.", }); } diff --git a/docs/internals/providers.md b/docs/internals/providers.md index def6a2ac9ebd8..a42e6ada90b5e 100644 --- a/docs/internals/providers.md +++ b/docs/internals/providers.md @@ -40,8 +40,10 @@ Antigravity separates account profiles per instance while sharing installed exec environment. It forces file-based credential storage because the native macOS keychain entry would otherwise be shared across instances. The launch environment removes ambient Google credentials, so an instance cannot silently use another account or billing project. The agent also resolves -its user-global skill directories under that profile, so the profile links those two directories -back to the user's real `~/.gemini`; MCP servers, hooks, and rules there stay out of the profile. +its user-global skill directories and plugins under that profile, so the profile links those two +skill directories and each enabled plugin back to the user's real `~/.gemini`. Plugins are linked +one by one, never as a folder, so plugins installed into the profile itself keep working. A plugin's +own hooks and MCP servers come with it, while top-level MCP servers, hooks, and rules stay out. See [profile isolation](../../apps/server/src/provider/antigravityAuthSupport.ts). The [Antigravity installer](../../apps/server/src/provider/AntigravityInstallation.ts) outlives @@ -74,7 +76,8 @@ metadata. Otherwise a helper or resumed session could retain the old account. Ca do not establish current access, and an authoritative empty catalog must clear the old list. Antigravity text-generation helpers deny tool requests, but native hooks and MCP configuration can -run before the prompt. They reject profiles with such configuration before launch. Prompt +run before the prompt. They reject profiles with such configuration, including in enabled plugins, +before launch. The check also covers user plugins that profile preparation links later. Prompt instructions and tool denial do not create a native sandbox. See [helper constraints](../../apps/server/src/textGeneration/AntigravityTextGeneration.ts). diff --git a/docs/user/providers-antigravity.md b/docs/user/providers-antigravity.md index c22a20a2ca540..273ed43cabbfa 100644 --- a/docs/user/providers-antigravity.md +++ b/docs/user/providers-antigravity.md @@ -112,6 +112,13 @@ Skills for every project go in `~/.gemini/config/skills` or `~/.gemini/antigravity-cli/skills`. Antigravity does not read `~/.agents/skills`, so a skill there only appears when the project itself is your home directory. +Plugins installed in `~/.gemini/config/plugins` work too, unless +`~/.gemini/config/config.json` turns them off. T3 Code sessions load their +skills, hooks, and MCP servers as `agy` does. MCP servers and hooks configured directly in +`~/.gemini/config` do not. If an enabled plugin has hooks or MCP servers, +Antigravity cannot serve as a +[text generation model](./text-generation.md), so pick another one. + Antigravity receives images and audio directly, and reads PDFs and text files as documents. With the managed runtime on macOS and Linux, an MP4 video up to 20 MiB is sent as video to Gemini models. Other attachments, and videos for other models, are passed as a From faff273ac67041b742f8cbf174fb62a96844e165 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 11:12:36 +0000 Subject: [PATCH 2/4] fix(server): check only the plugin startup files Antigravity loads agy 1.5.12 reads plugin hooks and MCP servers only from hooks.json and mcp_config.json at the plugin root; .mcp.json, hooks/ and manifest fields are never loaded, so they no longer disable text generation. Co-Authored-By: Claude Opus 5.5 --- .../src/provider/Drivers/AntigravitySkills.ts | 2 +- .../AntigravityTextGeneration.test.ts | 27 ++---- .../AntigravityTextGeneration.ts | 95 +++++++------------ 3 files changed, 41 insertions(+), 83 deletions(-) diff --git a/apps/server/src/provider/Drivers/AntigravitySkills.ts b/apps/server/src/provider/Drivers/AntigravitySkills.ts index c8cf6e150e05d..fd634b092397b 100644 --- a/apps/server/src/provider/Drivers/AntigravitySkills.ts +++ b/apps/server/src/provider/Drivers/AntigravitySkills.ts @@ -113,7 +113,7 @@ const readAntigravityDisabledPlugins = Effect.fn("readAntigravityDisabledPlugins }); /** agy skips a plugin folder without one of these manifests. */ -export const ANTIGRAVITY_PLUGIN_MANIFESTS = [ +const ANTIGRAVITY_PLUGIN_MANIFESTS = [ "plugin.json", ".antigravity-plugin/plugin.json", ".gemini-plugin/plugin.json", diff --git a/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts b/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts index 1dae77b192a6d..bb230f9f7bfc6 100644 --- a/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts +++ b/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts @@ -571,35 +571,24 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => { it.effect.each([ { - case: "a skills-only plugin", - files: { "skills/review/SKILL.md": "---\n---\n" }, + case: "files agy never loads", + files: { + "skills/review/SKILL.md": "---\n---\n", + "hooks/hooks.json": '{"hooks":{"Stop":[]}}', + ".mcp.json": '{"mcpServers":{"s":{"command":"do-not-run"}}}', + "plugin.json": '{"name":"p","hooks":"./h.json","mcpServers":{"s":{"command":"false"}}}', + }, available: true, }, - { case: "a hooks folder", files: { "hooks/hooks.json": "{}" }, available: false }, { case: "hooks.json", files: { "hooks.json": '{"hooks":{"Stop":[]}}' }, available: false }, { case: "mcp_config.json", files: { "mcp_config.json": '{"mcpServers":{"s":{"command":"do-not-run"}}}' }, available: false, }, - { - case: ".mcp.json", - files: { ".mcp.json": '{"s":{"command":"do-not-run"}}' }, - available: false, - }, - { - case: "manifest MCP servers", - files: { "plugin.json": '{"name":"p","mcpServers":{"s":{"command":"do-not-run"}}}' }, - available: false, - }, - { - case: "manifest hooks", - files: { ".gemini-plugin/plugin.json": '{"name":"p","hooks":"./hooks.json"}' }, - available: false, - }, { case: "a disabled plugin with MCP servers", - files: { ".mcp.json": '{"s":{"command":"do-not-run"}}' }, + files: { "mcp_config.json": '{"mcpServers":{"s":{"command":"do-not-run"}}}' }, disabled: true, available: true, }, diff --git a/apps/server/src/textGeneration/AntigravityTextGeneration.ts b/apps/server/src/textGeneration/AntigravityTextGeneration.ts index 46cbff2bfa67a..e3357818c43db 100644 --- a/apps/server/src/textGeneration/AntigravityTextGeneration.ts +++ b/apps/server/src/textGeneration/AntigravityTextGeneration.ts @@ -17,10 +17,7 @@ import { ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE, isAntigravitySignInRequiredError, } from "../provider/antigravityAuthSupport.ts"; -import { - ANTIGRAVITY_PLUGIN_MANIFESTS, - readAntigravityPlugins, -} from "../provider/Drivers/AntigravitySkills.ts"; +import { readAntigravityPlugins } from "../provider/Drivers/AntigravitySkills.ts"; import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime"; import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations"; @@ -69,72 +66,44 @@ export interface AntigravityTextGenerationOptions { ) => Effect.Effect; } -type Configuration = typeof Configuration.Type; -const hooksIn = (configuration: Configuration) => [configuration.hooks ?? configuration]; -const mcpServersIn = (configuration: Configuration) => [configuration.mcpServers ?? configuration]; -const pluginConfigurations = [ - ["hooks.json", hooksIn], - ["mcp_config.json", mcpServersIn], - [".mcp.json", mcpServersIn], - ...ANTIGRAVITY_PLUGIN_MANIFESTS.map( - (manifest) => - [ - manifest, - (configuration: Configuration) => [ - configuration.hooks ?? {}, - configuration.mcpServers ?? {}, - ], - ] as const, - ), -] as const; - /** Global and plugin hooks and MCP servers can run before a helper can deny a tool request. */ export const isAntigravityTextGenerationAvailable = Effect.fn( "isAntigravityTextGenerationAvailable", )(function* (input: { readonly profileDirectory: string; readonly userHome: string }) { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; - const isUnconfigured = Effect.fn("isAntigravityConfigurationEmpty")(function* ( - configurationPath: string, - select: (configuration: Configuration) => ReadonlyArray, - ) { - if (!(yield* fs.exists(configurationPath))) { - return true; - } - const info = yield* fs.stat(configurationPath); - if (info.type !== "File" || info.size > 64_000n) { - return false; - } - // CLI 1.5.8 writes a 0-byte mcp_config.json before any server exists. - return yield* fs.readFileString(configurationPath).pipe( - Effect.flatMap((text) => - text.trim().length === 0 - ? Effect.succeed(true) - : decodeConfiguration(text).pipe( - Effect.flatMap((configuration) => - Effect.forEach(select(configuration), (value) => decodeConfigurationObject(value)), + // agy 1.5.12 reads plugin hooks and MCP servers only from these files at the plugin root. + const directories = [ + path.join(input.profileDirectory, "config"), + ...(yield* readAntigravityPlugins(input)), + ]; + for (const directory of directories) { + for (const name of ["hooks.json", "mcp_config.json"]) { + const configurationPath = path.join(directory, name); + if (!(yield* fs.exists(configurationPath))) { + continue; + } + const info = yield* fs.stat(configurationPath); + if (info.type !== "File" || info.size > 64_000n) { + return false; + } + // CLI 1.5.8 writes a 0-byte mcp_config.json before any server exists. + const empty = yield* fs.readFileString(configurationPath).pipe( + Effect.flatMap((text) => + text.trim().length === 0 + ? Effect.succeed(true) + : decodeConfiguration(text).pipe( + Effect.flatMap((configuration) => + decodeConfigurationObject( + configuration[name === "hooks.json" ? "hooks" : "mcpServers"] ?? configuration, + ), + ), + Effect.map((configuration) => Object.keys(configuration).length === 0), ), - Effect.map((values) => values.every((value) => Object.keys(value).length === 0)), - ), - ), - Effect.orElseSucceed(() => false), - ); - }); - - const config = path.join(input.profileDirectory, "config"); - if ( - !(yield* isUnconfigured(path.join(config, "hooks.json"), hooksIn)) || - !(yield* isUnconfigured(path.join(config, "mcp_config.json"), mcpServersIn)) - ) { - return false; - } - for (const pluginDirectory of yield* readAntigravityPlugins(input)) { - const hooks = yield* fs - .readDirectory(path.join(pluginDirectory, "hooks")) - .pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed([]))); - if (hooks.length > 0) return false; - for (const [file, select] of pluginConfigurations) { - if (!(yield* isUnconfigured(path.join(pluginDirectory, file), select))) return false; + ), + Effect.orElseSucceed(() => false), + ); + if (!empty) return false; } } return true; From 3db2fc1f1406a230fb51882611de35e590215233 Mon Sep 17 00:00:00 2001 From: "Fatih C. Akyon" <34196005+fcakyon@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:47:31 +0300 Subject: [PATCH 3/4] fix: skip profile config when no plugins exist An oversized profile config.json no longer fails skill discovery when no plugins need its preferences. verification: new oversized profile config test failed on faff273 and passes with the fix, check:changed passes --- .../Drivers/AntigravitySkills.test.ts | 28 +++++++++++++++++++ .../src/provider/Drivers/AntigravitySkills.ts | 1 + 2 files changed, 29 insertions(+) diff --git a/apps/server/src/provider/Drivers/AntigravitySkills.test.ts b/apps/server/src/provider/Drivers/AntigravitySkills.test.ts index d171fff87df5b..c194769a5a978 100644 --- a/apps/server/src/provider/Drivers/AntigravitySkills.test.ts +++ b/apps/server/src/provider/Drivers/AntigravitySkills.test.ts @@ -121,6 +121,34 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => { }), ); + it.effect("skips an oversized profile config.json when no plugins are installed", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const input = yield* makeWorkspace(); + const userSkill = yield* writeSkill( + path.join(input.userHome, ".gemini", "config", "skills", "user"), + "---\nname: user\n---\n", + ); + const projectSkill = yield* writeSkill( + path.join(input.cwd, ".agents", "skills", "project"), + "---\nname: project\n---\n", + ); + yield* fileSystem.makeDirectory(path.join(input.profileDirectory, "config"), { + recursive: true, + }); + yield* fileSystem.writeFileString( + path.join(input.profileDirectory, "config", "config.json"), + " ".repeat(1_000_001), + ); + + assert.deepEqual(yield* discoverAntigravitySkills(input), [ + { name: "project", path: projectSkill, scope: "project", enabled: true }, + { name: "user", path: userSkill, scope: "user", enabled: true }, + ]); + }), + ); + it.effect.skipIf(!symlinksSupported)( "reads skills from enabled user plugins before the profile links them", () => diff --git a/apps/server/src/provider/Drivers/AntigravitySkills.ts b/apps/server/src/provider/Drivers/AntigravitySkills.ts index fd634b092397b..581553666482f 100644 --- a/apps/server/src/provider/Drivers/AntigravitySkills.ts +++ b/apps/server/src/provider/Drivers/AntigravitySkills.ts @@ -170,6 +170,7 @@ export const readAntigravityPlugins = Effect.fn("readAntigravityPlugins")(functi const info = yield* readIfPresent(fileSystem.stat(pluginDirectory), pluginDirectory); if (info?.type === "Directory") plugins.set(name, pluginDirectory); } + if (plugins.size === 0) return []; const disabled = yield* readAntigravityDisabledPlugins( path.join(input.profileDirectory, "config", "config.json"), ); From fb17cfd1f2550c658cfd474ba0c42393b7fae539 Mon Sep 17 00:00:00 2001 From: "Fatih C. Akyon" <34196005+fcakyon@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:50:23 +0300 Subject: [PATCH 4/4] fix: honor disabled flag in plugin manifests A plugin whose manifest sets "disabled": true now stays off unless config.json enables it, and a user enabled override for one is carried into the profile config.json unless the profile sets its own value. verification: 4 new cases failed on 247ce49590 and pass now, 99 focused antigravity tests and check:changed pass, live agy 1.5.12 session/new loads re-enabled and null-flag manifests and skips default-off, string-flag and invalid-json ones --- .../Drivers/AntigravitySkills.test.ts | 38 ++++++- .../src/provider/Drivers/AntigravitySkills.ts | 107 +++++++++++++----- .../provider/antigravityAuthSupport.test.ts | 49 ++++++-- .../src/provider/antigravityAuthSupport.ts | 55 ++++++++- .../AntigravityTextGeneration.test.ts | 9 ++ docs/internals/providers.md | 4 +- docs/user/providers-antigravity.md | 3 +- 7 files changed, 218 insertions(+), 47 deletions(-) diff --git a/apps/server/src/provider/Drivers/AntigravitySkills.test.ts b/apps/server/src/provider/Drivers/AntigravitySkills.test.ts index 5e8bb43d3f06e..eae7a05b75843 100644 --- a/apps/server/src/provider/Drivers/AntigravitySkills.test.ts +++ b/apps/server/src/provider/Drivers/AntigravitySkills.test.ts @@ -107,16 +107,26 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => { `---\nname: ${plugin}-skill\ndescription: From ${plugin}.\n---\n`, ); } + for (const plugin of ["default-off", "opted-in"]) { + yield* writeSkill( + path.join(plugins, plugin, "skills", `${plugin}-skill`), + `---\nname: ${plugin}-skill\n---\n`, + ); + yield* fileSystem.writeFileString( + path.join(plugins, plugin, "plugin.json"), + '{"disabled":true}', + ); + } yield* fileSystem.writeFileString( path.join(profileDirectory, "config", "config.json"), - JSON.stringify({ plugins: { off: { enabled: false } } }), + JSON.stringify({ plugins: { off: { enabled: false }, "opted-in": { enabled: true } } }), ); yield* fileSystem.writeFileString(path.join(plugins, ".DS_Store"), "x"); const input = { ...workspace, profileDirectory }; assert.deepEqual( (yield* discoverAntigravitySkills(input)).map((skill) => skill.name), - ["demo-skill"], + ["demo-skill", "opted-in-skill"], ); }), ); @@ -158,7 +168,7 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => { const input = yield* makeWorkspace(); const config = path.join(input.userHome, ".gemini", "config"); const profileConfig = path.join(input.profileDirectory, "config"); - for (const [plugin, manifest] of [ + for (const [plugin, manifest, text] of [ ["on", "plugin.json"], ["ag", ".antigravity-plugin/plugin.json"], ["gem", ".gemini-plugin/plugin.json"], @@ -166,6 +176,12 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => { ["bare", undefined], ["profile-off", "plugin.json"], ["shadowed", "plugin.json"], + ["invalid", "plugin.json", "{"], + ["string-flag", "plugin.json", '{"disabled":"yes"}'], + ["null-flag", "plugin.json", '{"disabled":null}'], + ["default-off", "plugin.json", '{"disabled":true}'], + ["re-enabled", ".gemini-plugin/plugin.json", '{"disabled":true}'], + ["profile-blocked", "plugin.json", '{"disabled":true}'], ] as const) { const directory = path.join(config, "plugins", plugin); yield* writeSkill(path.join(directory, "skills", plugin), `---\nname: ${plugin}\n---\n`); @@ -173,12 +189,18 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => { yield* fileSystem.makeDirectory(path.dirname(path.join(directory, manifest)), { recursive: true, }); - yield* fileSystem.writeFileString(path.join(directory, manifest), "{}"); + yield* fileSystem.writeFileString(path.join(directory, manifest), text ?? "{}"); } } yield* fileSystem.writeFileString( path.join(config, "config.json"), - JSON.stringify({ plugins: { off: { enabled: false } } }), + JSON.stringify({ + plugins: { + off: { enabled: false }, + "re-enabled": { enabled: true }, + "profile-blocked": { enabled: true }, + }, + }), ); yield* writeSkill( path.join(profileConfig, "plugins", "shadowed", "skills", "own"), @@ -186,7 +208,9 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => { ); yield* fileSystem.writeFileString( path.join(profileConfig, "config.json"), - JSON.stringify({ plugins: { "profile-off": { enabled: false } } }), + JSON.stringify({ + plugins: { "profile-off": { enabled: false }, "profile-blocked": { enabled: false } }, + }), ); // A link from before "off" was disabled goes on the next launch. yield* fileSystem.symlink( @@ -199,8 +223,10 @@ it.layer(NodeServices.layer)("discoverAntigravitySkills", (it) => { [ ["ag", "user"], ["gem", "user"], + ["null-flag", "user"], ["on", "user"], ["profile-shadowed", "user"], + ["re-enabled", "user"], ], ); }), diff --git a/apps/server/src/provider/Drivers/AntigravitySkills.ts b/apps/server/src/provider/Drivers/AntigravitySkills.ts index d4160a8486e06..06785db77bf9f 100644 --- a/apps/server/src/provider/Drivers/AntigravitySkills.ts +++ b/apps/server/src/provider/Drivers/AntigravitySkills.ts @@ -68,6 +68,12 @@ const decodePluginPreferences = Schema.decodeUnknownOption( }), ), ); +const decodePluginManifest = Schema.decodeUnknownOption( + // agy decodes like Go's encoding/json, so null leaves the default and a string is invalid. + Schema.fromJsonString( + Schema.Struct({ disabled: Schema.optional(Schema.NullOr(Schema.Boolean)) }), + ), +); export class AntigravitySkillsProbeError extends Schema.TaggedError()( "AntigravitySkillsProbeError", @@ -104,35 +110,61 @@ const readIfPresent = ( }), ); -/** Plugin names that a GEMINI_HOME's config.json turns off. */ -const readAntigravityDisabledPlugins = Effect.fn("readAntigravityDisabledPlugins")(function* ( - configPath: string, +/** Reads a file of at most MAX_SKILL_BYTES, or undefined when it is missing. */ +export const readAntigravityBoundedFile = Effect.fn("readAntigravityBoundedFile")(function* ( + filePath: string, ) { const fileSystem = yield* FileSystem.FileSystem; - const info = yield* readIfPresent(fileSystem.stat(configPath), configPath); - if (info?.type !== "File") return new Set(); + const info = yield* readIfPresent(fileSystem.stat(filePath), filePath); + if (info?.type !== "File") return undefined; if (info.size > BigInt(MAX_SKILL_BYTES)) { return yield* new AntigravitySkillsProbeError({ reason: "scan-budget-exhausted", - path: configPath, + path: filePath, }); } - const config = yield* readIfPresent(fileSystem.readFileString(configPath), configPath); + return yield* readIfPresent(fileSystem.readFileString(filePath), filePath); +}); + +/** The explicit `plugins..enabled` values in a GEMINI_HOME's config.json. */ +const readAntigravityPluginPreferences = Effect.fn("readAntigravityPluginPreferences")(function* ( + configPath: string, +) { + const config = yield* readAntigravityBoundedFile(configPath); const preferences = config === undefined ? undefined : decodePluginPreferences(config); - return new Set( + return new Map( Object.entries( (preferences?._tag === "Some" ? preferences.value.plugins : undefined) ?? {}, - ).flatMap(([name, plugin]) => (plugin.enabled === false ? [name] : [])), + ).flatMap(([name, plugin]) => + plugin.enabled === undefined ? [] : [[name, plugin.enabled] as const], + ), ); }); -/** agy skips a plugin folder without one of these manifests. */ +/** agy skips a plugin folder without one of these manifests, or whose manifest is not valid JSON. */ const ANTIGRAVITY_PLUGIN_MANIFESTS = [ "plugin.json", ".antigravity-plugin/plugin.json", ".gemini-plugin/plugin.json", ] as const; +const readAntigravityPluginManifest = Effect.fn("readAntigravityPluginManifest")(function* ( + pluginDirectory: string, +) { + const path = yield* Path.Path; + for (const manifest of ANTIGRAVITY_PLUGIN_MANIFESTS) { + const text = yield* readAntigravityBoundedFile(path.join(pluginDirectory, manifest)); + if (text === undefined) continue; + const decoded = decodePluginManifest(text); + return decoded._tag === "Some" ? { disabled: decoded.value.disabled === true } : undefined; + } + return undefined; +}); + +/** A plugin shipping `"disabled": true` loads only when config.json enables it by folder name. */ +const isAntigravityPluginEnabled = (disabledByDefault: boolean, enabled: boolean | undefined) => + disabledByDefault ? enabled === true : enabled !== false; + /** Enabled plugins in the user's ~/.gemini, by name, that a profile links and agy then loads. */ export const readAntigravityUserPlugins = Effect.fn("readAntigravityUserPlugins")(function* ( userHome: string, @@ -140,23 +172,26 @@ export const readAntigravityUserPlugins = Effect.fn("readAntigravityUserPlugins" const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; const pluginsDirectory = path.join(userHome, ".gemini", "config", "plugins"); - const plugins = new Map(); + const plugins = new Map< + string, + { readonly directory: string; readonly disabledByDefault: boolean } + >(); const names = yield* readIfPresent(fileSystem.readDirectory(pluginsDirectory), pluginsDirectory); - if (names === undefined || names.length === 0) return plugins; - const disabled = yield* readAntigravityDisabledPlugins( + for (const name of names?.toSorted() ?? []) { + const directory = path.join(pluginsDirectory, name); + const info = yield* readIfPresent(fileSystem.stat(directory), directory); + if (info?.type !== "Directory") continue; + const manifest = yield* readAntigravityPluginManifest(directory); + if (manifest === undefined) continue; + plugins.set(name, { directory, disabledByDefault: manifest.disabled }); + } + if (plugins.size === 0) return plugins; + const preferences = yield* readAntigravityPluginPreferences( path.join(userHome, ".gemini", "config", "config.json"), ); - for (const name of names.toSorted()) { - if (disabled.has(name)) continue; - const pluginDirectory = path.join(pluginsDirectory, name); - const info = yield* readIfPresent(fileSystem.stat(pluginDirectory), pluginDirectory); - if (info?.type !== "Directory") continue; - for (const manifest of ANTIGRAVITY_PLUGIN_MANIFESTS) { - const manifestPath = path.join(pluginDirectory, manifest); - if ((yield* readIfPresent(fileSystem.stat(manifestPath), manifestPath))?.type === "File") { - plugins.set(name, pluginDirectory); - break; - } + for (const [name, plugin] of plugins) { + if (!isAntigravityPluginEnabled(plugin.disabledByDefault, preferences.get(name))) { + plugins.delete(name); } } return plugins; @@ -171,7 +206,13 @@ export const readAntigravityPlugins = Effect.fn("readAntigravityPlugins")(functi const path = yield* Path.Path; const pluginsDirectory = path.join(input.profileDirectory, "config", "plugins"); const userPluginsDirectory = path.join(input.userHome, ".gemini", "config", "plugins"); - const plugins = yield* readAntigravityUserPlugins(input.userHome); + // The profile linker carries a user's enabled override for a plugin that ships disabled. + const plugins = new Map( + [...(yield* readAntigravityUserPlugins(input.userHome))].map(([name, plugin]) => [ + name, + { directory: plugin.directory, disabledByDefault: false }, + ]), + ); const names = yield* readIfPresent(fileSystem.readDirectory(pluginsDirectory), pluginsDirectory); for (const name of names ?? []) { const pluginDirectory = path.join(pluginsDirectory, name); @@ -182,16 +223,24 @@ export const readAntigravityPlugins = Effect.fn("readAntigravityPlugins")(functi // Profile preparation replaces its links into the user's plugins, so those come from above. if (target !== undefined && path.dirname(target) === userPluginsDirectory) continue; const info = yield* readIfPresent(fileSystem.stat(pluginDirectory), pluginDirectory); - if (info?.type === "Directory") plugins.set(name, pluginDirectory); + if (info?.type !== "Directory") continue; + // Profile folders count without a manifest, as they did before user plugins were linked. + const manifest = yield* readAntigravityPluginManifest(pluginDirectory); + plugins.set(name, { + directory: pluginDirectory, + disabledByDefault: manifest?.disabled === true, + }); } if (plugins.size === 0) return []; - const disabled = yield* readAntigravityDisabledPlugins( + const preferences = yield* readAntigravityPluginPreferences( path.join(input.profileDirectory, "config", "config.json"), ); return [...plugins] - .filter(([name]) => !disabled.has(name)) + .filter(([name, plugin]) => + isAntigravityPluginEnabled(plugin.disabledByDefault, preferences.get(name)), + ) .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0)) - .map(([, pluginDirectory]) => pluginDirectory); + .map(([, plugin]) => plugin.directory); }); function parseSkillFrontmatter(contents: string, fileName: string) { diff --git a/apps/server/src/provider/antigravityAuthSupport.test.ts b/apps/server/src/provider/antigravityAuthSupport.test.ts index 4f93573c8e715..b6e711e610c2f 100644 --- a/apps/server/src/provider/antigravityAuthSupport.test.ts +++ b/apps/server/src/provider/antigravityAuthSupport.test.ts @@ -708,24 +708,30 @@ it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => { }); const linkTarget = (name: string) => fs.readLink(path.join(profilePlugins, name)).pipe(Effect.orElseSucceed(() => undefined)); - for (const [plugin, manifest] of [ + const profileConfig = path.join(profileDirectory, "config", "config.json"); + for (const [plugin, manifest, text] of [ ["on", "plugin.json"], ["ag", ".antigravity-plugin/plugin.json"], ["gem", ".gemini-plugin/plugin.json"], ["off", "plugin.json"], ["bare", "skills/bare/SKILL.md"], ["local", "plugin.json"], + ["opted-in", "plugin.json", '{"disabled":true}'], + ["kept-off", "plugin.json", '{"disabled":true}'], + ["shadowed", "plugin.json", '{"disabled":true}'], ] as const) { - yield* write(path.join(userPlugins, plugin, manifest), "{}"); + yield* write(path.join(userPlugins, plugin, manifest), text ?? "{}"); } - const disable = (plugins: ReadonlyArray) => + const configure = (plugins: Record) => write( path.join(config, "config.json"), encodeUnknownJson({ - plugins: Object.fromEntries(plugins.map((name) => [name, { enabled: false }])), + plugins: Object.fromEntries( + Object.entries(plugins).map(([name, enabled]) => [name, { enabled }]), + ), }), ); - yield* disable(["off"]); + yield* configure({ off: false }); yield* write(path.join(config, "mcp_config.json"), '{"mcpServers":{"s":{}}}'); yield* write(path.join(config, "hooks.json"), '{"hooks":{"Stop":[]}}'); yield* write(path.join(profilePlugins, "local", "plugin.json"), "{}"); @@ -741,11 +747,23 @@ it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => { expect(yield* fs.exists(path.join(profilePlugins, "bare"))).toBe(false); expect(yield* linkTarget("local")).toBeUndefined(); expect(yield* linkTarget("foreign")).toBe(foreign); - for (const name of ["mcp_config.json", "hooks.json"]) { + for (const name of ["mcp_config.json", "hooks.json", "config.json"]) { expect(yield* fs.exists(path.join(profileDirectory, "config", name))).toBe(false); } + for (const plugin of ["opted-in", "kept-off", "shadowed"]) { + expect(yield* fs.exists(path.join(profilePlugins, plugin))).toBe(false); + } - yield* disable(["on"]); + // A user enabled override for a plugin that ships disabled must reach the profile. + yield* configure({ on: false, "opted-in": true, "kept-off": true, shadowed: true }); + yield* write(path.join(profilePlugins, "shadowed", "plugin.json"), "{}"); + yield* write( + profileConfig, + encodeUnknownJson({ + theme: "dark", + plugins: { "kept-off": { enabled: false }, other: { enabled: true, note: 1 } }, + }), + ); yield* fs.remove(path.join(userPlugins, "ag"), { recursive: true }); yield* fs.remove(path.join(profilePlugins, "gem")); yield* fs.symlink(path.join(userPlugins, "off"), path.join(profilePlugins, "gem")); @@ -756,6 +774,23 @@ it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => { expect(yield* linkTarget("off")).toBe(path.join(userPlugins, "off")); expect(yield* fs.exists(path.join(profilePlugins, "local", "plugin.json"))).toBe(true); expect(yield* linkTarget("foreign")).toBe(foreign); + for (const plugin of ["opted-in", "kept-off"]) { + expect(yield* linkTarget(plugin)).toBe(path.join(userPlugins, plugin)); + } + expect(yield* linkTarget("shadowed")).toBeUndefined(); + expect(JSON.parse(yield* fs.readFileString(profileConfig))).toEqual({ + theme: "dark", + plugins: { + "kept-off": { enabled: false }, + other: { enabled: true, note: 1 }, + "opted-in": { enabled: true }, + }, + }); + + yield* configure({ on: false, "opted-in": false }); + yield* prepareAntigravityProfile({ profileDirectory, userHome }); + expect(yield* linkTarget("opted-in")).toBeUndefined(); + expect(yield* linkTarget("kept-off")).toBeUndefined(); }), ); diff --git a/apps/server/src/provider/antigravityAuthSupport.ts b/apps/server/src/provider/antigravityAuthSupport.ts index f4032119faaf2..2fb54908ae105 100644 --- a/apps/server/src/provider/antigravityAuthSupport.ts +++ b/apps/server/src/provider/antigravityAuthSupport.ts @@ -21,6 +21,7 @@ import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStr import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime"; import { antigravityUserSkillDirectories, + readAntigravityBoundedFile, readAntigravityUserPlugins, resolveAntigravityUserHome, } from "./Drivers/AntigravitySkills.ts"; @@ -333,6 +334,40 @@ const linkAntigravityUserConfig = Effect.fn("linkAntigravityUserConfig")(functio } }); +const UnknownRecord = Schema.Record(Schema.String, Schema.Unknown); +const ProfileConfigJson = Schema.fromJsonString( + Schema.StructWithRest( + Schema.Struct({ plugins: Schema.optional(Schema.Record(Schema.String, UnknownRecord)) }), + [UnknownRecord], + ), +); +const decodeProfileConfig = Schema.decodeUnknownEffect(ProfileConfigJson); +const encodeProfileConfig = Schema.encodeSync(ProfileConfigJson); + +/** agy reads plugin overrides only from the profile's config.json, and an explicit profile value wins. */ +const enableAntigravityProfilePlugins = Effect.fn("enableAntigravityProfilePlugins")( + function* (configPath: string, names: ReadonlyArray) { + const fs = yield* FileSystem.FileSystem; + const config = yield* decodeProfileConfig( + (yield* readAntigravityBoundedFile(configPath)) ?? "{}", + ); + const plugins = { ...config.plugins }; + const missing = names.filter((name) => plugins[name]?.enabled === undefined); + if (missing.length === 0) return; + for (const name of missing) plugins[name] = { ...plugins[name], enabled: true }; + yield* fs.writeFileString(configPath, encodeProfileConfig({ ...config, plugins })); + }, + (effect, configPath) => + effect.pipe( + Effect.catch((error) => + Effect.logWarning("Antigravity plugin overrides are not carried into the profile.", { + configPath, + error, + }), + ), + ), +); + /** Link each enabled plugin instead of the folder, so plugins installed into the profile keep working. */ const linkAntigravityUserPlugins = Effect.fn("linkAntigravityUserPlugins")(function* (input: { readonly profileDirectory: string; @@ -350,6 +385,7 @@ const linkAntigravityUserPlugins = Effect.fn("linkAntigravityUserPlugins")(funct .readDirectory(profilePlugins) .pipe(Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed([]))), ); + const linked = new Set(); for (const name of existing) { const link = path.join(profilePlugins, name); const target = yield* fs.readLink(link).pipe( @@ -358,18 +394,31 @@ const linkAntigravityUserPlugins = Effect.fn("linkAntigravityUserPlugins")(funct ); // Only links into the user's plugins are ours. Real folders and other links stay. if (target === undefined || path.dirname(target) !== userPlugins) continue; - if (enabled.get(name) === target) continue; + if (enabled.get(name)?.directory === target) { + linked.add(name); + continue; + } yield* fs.remove(link); existing.delete(name); } - for (const [name, target] of enabled) { + for (const [name, plugin] of enabled) { if (existing.has(name)) continue; const link = path.join(profilePlugins, name); yield* fs.makeDirectory(profilePlugins, { recursive: true }); yield* Effect.tryPromise({ - try: () => NodeFSP.symlink(target, link, input.platform === "win32" ? "junction" : "dir"), + try: () => + NodeFSP.symlink(plugin.directory, link, input.platform === "win32" ? "junction" : "dir"), catch: (cause) => new AntigravitySkillLinkError({ link, cause }), }); + linked.add(name); + } + // A profile folder with the same name shadows the user's plugin, so it keeps its own setting. + const enableByDefault = [...linked].filter((name) => enabled.get(name)?.disabledByDefault); + if (enableByDefault.length > 0) { + yield* enableAntigravityProfilePlugins( + path.join(input.profileDirectory, "config", "config.json"), + enableByDefault, + ); } }).pipe( Effect.catch((error) => diff --git a/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts b/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts index 6c9f05144e671..f6b6aa22b31d7 100644 --- a/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts +++ b/apps/server/src/textGeneration/AntigravityTextGeneration.test.ts @@ -663,6 +663,15 @@ it.layer(NodeServices.layer)("AntigravityTextGeneration", (it) => { disabled: true, available: true, }, + { + case: "a plugin that ships disabled", + files: { + "plugin.json": '{"name":"p","disabled":true}', + "hooks.json": '{"hooks":{"Stop":[]}}', + "mcp_config.json": '{"mcpServers":{"s":{"command":"do-not-run"}}}', + }, + available: true, + }, ])( "checks plugin startup configuration before starting a helper: $case", ({ files, disabled, available }) => diff --git a/docs/internals/providers.md b/docs/internals/providers.md index abf6a07a21653..c905ea96e09ac 100644 --- a/docs/internals/providers.md +++ b/docs/internals/providers.md @@ -45,7 +45,9 @@ so an instance cannot silently use another account or billing project. The agent its user-global skill directories, rules, and plugins under that profile, so the profile links those two skill directories, the global `AGENTS.md` and `GEMINI.md` rules (copied on Windows), and each enabled plugin back to the user's real `~/.gemini`. Plugins are linked one by one, never as a -folder, so plugins installed into the profile itself keep working. A plugin's own hooks and MCP +folder, so plugins installed into the profile itself keep working. agy reads plugin overrides only +from the profile's `config.json`, so a user's `enabled: true` for a plugin whose manifest sets +`"disabled": true` is carried there unless the profile sets its own value. A plugin's own hooks and MCP servers come with it, while the top-level `~/.gemini/config/mcp_config.json` and `hooks.json` stay out. See [profile isolation](../../apps/server/src/provider/antigravityAuthSupport.ts). diff --git a/docs/user/providers-antigravity.md b/docs/user/providers-antigravity.md index cbdbdf5df1f7c..88c4727668514 100644 --- a/docs/user/providers-antigravity.md +++ b/docs/user/providers-antigravity.md @@ -109,7 +109,8 @@ honoring `inherits`, `include_only`, and `exclude`. Global rules in `~/.gemini/AGENTS.md` and `~/.gemini/GEMINI.md` apply to every session. Plugins installed in `~/.gemini/config/plugins` work too, unless -`~/.gemini/config/config.json` turns them off. T3 Code sessions load their +`~/.gemini/config/config.json` turns them off. A plugin that ships with `"disabled": true` +stays off until that file sets `"enabled": true` for it. T3 Code sessions load their skills, hooks, and MCP servers as `agy` does. MCP servers and hooks configured directly in `~/.gemini/config/mcp_config.json` and `~/.gemini/config/hooks.json` do not. If an enabled plugin has hooks or MCP servers, Antigravity cannot serve as a