Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/server/src/provider/Drivers/AntigravityDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
6 changes: 5 additions & 1 deletion apps/server/src/provider/Drivers/AntigravityDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -499,6 +502,7 @@ export const AntigravityDriver: ProviderDriver<
});
const textGeneration = yield* makeAntigravityTextGeneration({
profileDirectory,
userHome,
defaultModel,
withProcess: authFlow.withProcess,
makeRuntime: (cwd) =>
Expand Down
85 changes: 85 additions & 0 deletions apps/server/src/provider/Drivers/AntigravitySkills.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,91 @@ 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",
() =>
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;
Expand Down
123 changes: 92 additions & 31 deletions apps/server/src/provider/Drivers/AntigravitySkills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,96 @@ const readIfPresent = <A, R>(
}),
);

/** 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<string>();
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. */
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<string, string>();
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);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
if (plugins.size === 0) return [];
const disabled = yield* readAntigravityDisabledPlugins(
Comment thread
fcakyon marked this conversation as resolved.
Resolved
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;
Expand Down Expand Up @@ -251,37 +341,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));
});
70 changes: 70 additions & 0 deletions apps/server/src/provider/antigravityAuthSupport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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<string>) =>
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;
Expand Down
Loading
Loading