diff --git a/packages/agent-agy/README.md b/packages/agent-agy/README.md index 7355a66..24315e2 100644 --- a/packages/agent-agy/README.md +++ b/packages/agent-agy/README.md @@ -6,8 +6,9 @@ magpie plugin add @magpie-community/agent-agy ``` -Pick one of magpie's models in the Antigravity CLI row. magpie writes into -`~/.gemini/antigravity-cli/settings.json`: +Pick one of magpie's models in the Antigravity CLI row. magpie writes a file +of its own, `~/.gemini/antigravity-cli/magpie-settings.json`, and leaves +your `settings.json` alone: ```json { @@ -21,16 +22,18 @@ Pick one of magpie's models in the Antigravity CLI row. magpie writes into } ``` -Your own custom models stay beside magpie's. agy takes the address and key -of a Gemini endpoint only from how it is started, so magpie adds a function -`agy` to your shells' profiles: it runs `magpie agy run`, which starts the -agy on your PATH with `GEMINI_API_KEY`, `GOOGLE_GEMINI_BASE_URL` and -`--model` while its model is one of magpie's, and as it is otherwise. +Your own custom models from `settings.json` are carried in beside magpie's. +agy takes the address and key of a Gemini endpoint only from how it is +started, so magpie adds a function `agy` to your shells' profiles: it runs +`magpie agy run`, which starts the agy on your PATH with `GEMINI_API_KEY`, +`GOOGLE_GEMINI_BASE_URL`, `--settings magpie-settings.json` and `--model` +while its model is one of magpie's, and as it is otherwise. +`agy remote-control` always runs as it is, on your Google sign-in. `magpie agy env` prints what it starts agy with. -Picking agy's own model again, or switching it off, puts every key back as -it was and takes the function out. agy in a WSL distro is set up the same -way, from Windows. +Picking agy's own model again, or switching it off, takes +`magpie-settings.json` and the function away. agy in a WSL distro is set up +the same way, from Windows. This plugin takes the place of the Antigravity CLI magpie shipped with: what that one set up is handed over as it is. diff --git a/packages/agent-agy/agy.agent.js b/packages/agent-agy/agy.agent.js index bebd2b1..01324ee 100644 --- a/packages/agent-agy/agy.agent.js +++ b/packages/agent-agy/agy.agent.js @@ -1,10 +1,19 @@ -// Antigravity CLI (agy) keeps its model in +// Antigravity CLI (agy) keeps its settings in // ~/.gemini/antigravity-cli/settings.json, and the models it can pick in // customModelsConfig.customModels, each {apiProvider, modelName}. It takes // the address and key of a Gemini endpoint only from how it is started, // so magpie starts it: the function agy magpie puts in your shells runs -// `magpie agy run`, which gives agy GEMINI_API_KEY, GOOGLE_GEMINI_BASE_URL -// and --model while its model is one of magpie's. +// `magpie agy run`, which gives agy GEMINI_API_KEY, GOOGLE_GEMINI_BASE_URL, +// --settings magpie-settings.json and --model while its model is one of +// magpie's. +// +// magpie writes only magpie-settings.json, a file of its own beside +// settings.json, which agy reads for the one session started with +// --settings: "modelProvider": "gemini" in settings.json would make every +// agy an API-key session, with no Google account and so no remote +// control. agy takes customModels whole from that file, so the user's own +// custom models are carried into it beside magpie's. remote-control runs +// as agy is, on the user's sign-in. export const agent = { id: "agy", name: "Antigravity CLI", @@ -12,32 +21,42 @@ export const agent = { aliases: ["antigravity-cli"], bin: "agy", dir: "~/.gemini/antigravity-cli", - config: "~/.gemini/antigravity-cli/settings.json", + config: "~/.gemini/antigravity-cli/magpie-settings.json", + base: "~/.gemini/antigravity-cli/settings.json", format: "json", model: "model", prefix: "magpie/", launch: { env: { GEMINI_API_KEY: "{key}", GOOGLE_GEMINI_BASE_URL: "{url}" }, model: "--model", + args: { "--settings": "{config}" }, + plain: ["remote-control", "--remote-control", "-remote-control"], }, - // magpie's models go in beside the user's own - merge: ["customModelsConfig.customModels"], effort: true, wsl: true, } const GEMINI = "API_PROVIDER_GOOGLE_GEMINI" -export function connect({ models }) { - const custom = {} +// the user's own custom models, from settings.json +const ownModels = (base) => { + const out = {} + for (const [k, v] of Object.entries(base?.customModelsConfig?.customModels ?? {})) { + if (!k.startsWith("magpie/")) out[k] = v + } + return out +} + +export function connect({ models, base }) { + const custom = ownModels(base) for (const m of models) custom[`magpie/${m.id}`] = { apiProvider: GEMINI, modelName: m.id } return { modelProvider: "gemini", "customModelsConfig.customModels": custom } } // the user's own models, which go to their provider rather than through // magpie, and the one agy is on when it isn't listed -export function own({ config, model }) { - const custom = config?.customModelsConfig?.customModels ?? {} +export function own({ base, model }) { + const custom = base?.customModelsConfig?.customModels ?? {} const out = [] for (const [k, v] of Object.entries(custom)) { if (k.startsWith("magpie/")) continue diff --git a/packages/agent-agy/agy.test.mjs b/packages/agent-agy/agy.test.mjs index e63ab0c..5469bdb 100644 --- a/packages/agent-agy/agy.test.mjs +++ b/packages/agent-agy/agy.test.mjs @@ -4,13 +4,35 @@ import { agent, connect, own } from "./agy.agent.js" test("says where agy keeps its model, and how it is started", () => { expect(agent).toMatchObject({ id: "agy", - config: "~/.gemini/antigravity-cli/settings.json", + config: "~/.gemini/antigravity-cli/magpie-settings.json", + base: "~/.gemini/antigravity-cli/settings.json", format: "json", model: "model", prefix: "magpie/", bin: "agy", - launch: { env: { GEMINI_API_KEY: "{key}", GOOGLE_GEMINI_BASE_URL: "{url}" }, model: "--model" }, - merge: ["customModelsConfig.customModels"], + launch: { + env: { GEMINI_API_KEY: "{key}", GOOGLE_GEMINI_BASE_URL: "{url}" }, + model: "--model", + args: { "--settings": "{config}" }, + plain: ["remote-control", "--remote-control", "-remote-control"], + }, + }) + expect(agent.merge).toBeUndefined() +}) + +test("carries the user's own custom models from settings.json beside magpie's", () => { + const base = { + customModelsConfig: { + customModels: { + "my-claude": { apiProvider: "API_PROVIDER_ANTHROPIC", modelName: "claude-sonnet-4-5" }, + "magpie/old": { apiProvider: "API_PROVIDER_GOOGLE_GEMINI", modelName: "old" }, + }, + }, + } + const out = connect({ model: { id: "deepseek/pro" }, models: [{ id: "deepseek/pro" }], base }) + expect(out["customModelsConfig.customModels"]).toEqual({ + "my-claude": { apiProvider: "API_PROVIDER_ANTHROPIC", modelName: "claude-sonnet-4-5" }, + "magpie/deepseek/pro": { apiProvider: "API_PROVIDER_GOOGLE_GEMINI", modelName: "deepseek/pro" }, }) }) @@ -30,7 +52,7 @@ test("lists magpie's models as agy's Gemini models", () => { }) test("the user's own models go to their own provider", () => { - const config = { + const base = { customModelsConfig: { customModels: { "magpie/deepseek/pro": { apiProvider: "API_PROVIDER_GOOGLE_GEMINI", modelName: "deepseek/pro" }, @@ -39,11 +61,11 @@ test("the user's own models go to their own provider", () => { }, }, } - expect(own({ config, model: "gemini-3-pro" })).toEqual([ + expect(own({ base, model: "gemini-3-pro" })).toEqual([ { value: "gemini-3-pro", model: "gemini-3-pro", direct: "Google" }, { value: "my-claude", model: "claude-sonnet-4-5", direct: "Anthropic" }, { value: "my-gpt", model: "gpt-5", direct: "OpenAI" }, ]) - expect(own({ config, model: "my-gpt" }).map((o) => o.value)).toEqual(["my-claude", "my-gpt"]) - expect(own({ config: {}, model: "" })).toEqual([]) + expect(own({ base, model: "my-gpt" }).map((o) => o.value)).toEqual(["my-claude", "my-gpt"]) + expect(own({ base: {}, model: "" })).toEqual([]) }) diff --git a/packages/agent-agy/package.json b/packages/agent-agy/package.json index 160fa53..719115f 100644 --- a/packages/agent-agy/package.json +++ b/packages/agent-agy/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/agent-agy", - "version": "0.1.0", + "version": "0.2.0", "description": "Antigravity CLI (agy) as a magpie agent: pick one of magpie's models for it on the Agents page, and agy starts on magpie's gateway", "type": "module", "files": ["agy.agent.js", "README.md"],