From 57d1cc6a9f49389d495ea9be8d986c70de7767bf Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 15 Nov 2026 06:43:07 +0800 Subject: [PATCH] agy-cli: start agy without the machine's own skills when it can (#1166) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Windows with agy 1.5.9, a session loaded 120 local skills from ~/.gemini/skills, ~/.gemini/config/skills and ~/.agents/skills although the bridge agent says inheritCustomizations: false. Skills and the client's MCP tools share agy's 20,000-token customization budget, so agy dropped the six largest client tools (task, shell, …) and three skills. agy 1.5.9's acp takes --include-default-customizations (default true). The bridge now passes --include-default-customizations=false when `agy acp --help` lists the flag. An agy without it exits on an unknown flag, so it is never passed blind. The answer is kept per binary (path, mtime, size); a probe that errors or times out is asked again. The bare `agy acp` model probe is unchanged. 0.1.52. Run: - bun test packages/agy-cli on mote (temp HOME): 21 pass, 0 fail; bun scripts/check.mjs agy-cli ok. - the same on Windows (win-run, xiaomi-gpu): 21 pass, 0 fail. - test/smoke.mjs alone with bun on mote: ALL OK (348 checks). - real agy 1.5.9 on macOS: `agy acp --help` prints the flag on stderr (exit 0); a session started with the flag set to false runs. Broken by hand: without the args.push in Proc.start, repeat-batch's "#1166 … asked once" test and smoke's #1166 check go red. Not tried: the reporter's Windows machine with its 120 skills. On this Mac the default run sent no user skills to the model either, so it is not shown here that the flag keeps them out; the reporter is asked to confirm. --- packages/agy-cli/index.mjs | 27 ++++++++++++++++++++++++++ packages/agy-cli/package.json | 2 +- packages/agy-cli/test/repeat-batch.mjs | 25 ++++++++++++++++++++++++ packages/agy-cli/test/smoke.mjs | 13 ++++++++++++- packages/agy-cli/test/testkit.mjs | 11 +++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 44a776d..c16463d 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -200,6 +200,32 @@ function findAgy() { return null } +// agy loads the machine's own skills (~/.gemini/skills, ~/.agents/skills, …) +// into an ACP session even when the agent says inheritCustomizations: false. +// They share agy's 20,000-token customization budget with the client's tools, +// and over it agy drops the largest tools (plugins#1166). agy 1.5.9's acp +// takes --include-default-customizations=false to leave them out, but an +// agy without the flag refuses to start on it, so it is passed only when +// `agy acp --help` lists it. The answer is kept per binary (path, mtime, +// size), so an agy update asks again; a probe that failed is asked again. +const customizationFlag = new Map() +export function noDefaultCustomizationsArgs(agyPath) { + let key = agyPath + try { + const st = fs.statSync(agyPath) + key += `\0${st.mtimeMs}\0${st.size}` + } catch {} + let probe = customizationFlag.get(key) + if (!probe) { + probe = execOnce(agyPath, ["acp", "--help"], { timeoutMs: 10_000 }).then(({ err, stdout, stderr, timedOut }) => { + if (err || timedOut) customizationFlag.delete(key) + return /--include-default-customizations\b/.test(stdout + stderr) + }) + customizationFlag.set(key, probe) + } + return probe.then((ok) => (ok ? ["--include-default-customizations=false"] : [])) +} + function execOnce(file, args, opts = {}) { return new Promise((resolve) => { let child @@ -1639,6 +1665,7 @@ class Proc { "--ide-mcp-port", String(controlServer.address().port), ] if (this.workDir) args.push("--add-dir", this.workDir) + args.push(...await noDefaultCustomizationsArgs(this.agyPath)) try { const childEnv = { ...process.env } const inheritedPath = process.env.PATH || childEnv.Path || "" diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index 15d2095..b98a7bf 100644 --- a/packages/agy-cli/package.json +++ b/packages/agy-cli/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-agy-cli-auth", - "version": "0.1.51", + "version": "0.1.52", "description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI", "type": "module", "main": "./opencode.mjs", diff --git a/packages/agy-cli/test/repeat-batch.mjs b/packages/agy-cli/test/repeat-batch.mjs index d7a93ee..08b42a4 100644 --- a/packages/agy-cli/test/repeat-batch.mjs +++ b/packages/agy-cli/test/repeat-batch.mjs @@ -1020,3 +1020,28 @@ test("the same opening sent to several models at once is answered for each", asy assert.equal(arrived, ids.length) }) }) + +// ------------------------------------------- #1166 machine customizations + +test("#1166: an agy whose acp --help lists the flag starts without the machine's own skills, asked once", async () => { + await withKit({ acpHelp: "Usage of acp:\n --include-default-customizations\n \tload the default customizations (default true)\n" }, async (kit) => { + scriptedAgent(kit) + for (const user of ["custom-a", "custom-b"]) { + const reply = await readSse(await kit.request(baseBody({ metadata: { user_id: user }, messages: [{ role: "user", content: "hello " + user } ] }))) + assert.equal(reply.stopReason, "end_turn") + } + assert.equal(kit.acpSpawns.length, 2, "two conversations, two processes") + for (const spawn of kit.acpSpawns) assert.ok(spawn.args.includes("--include-default-customizations=false"), spawn.args.join(" ")) + assert.equal(kit.helpSpawns.length, 1, "acp --help is asked once per agy binary") + }) +}) + +test("#1166: an agy without the flag is never given it, so it still starts", async () => { + await withKit({}, async (kit) => { + scriptedAgent(kit) + const reply = await readSse(await kit.request(baseBody({ metadata: { user_id: "custom-old" }, messages: [{ role: "user", content: "hello old" }] }))) + assert.equal(reply.stopReason, "end_turn") + assert.equal(kit.acpSpawns.length, 1) + assert.ok(!kit.acpSpawns[0].args.some((arg) => arg.startsWith("--include-default-customizations")), kit.acpSpawns[0].args.join(" ")) + }) +}) diff --git a/packages/agy-cli/test/smoke.mjs b/packages/agy-cli/test/smoke.mjs index 641548a..1a551cf 100644 --- a/packages/agy-cli/test/smoke.mjs +++ b/packages/agy-cli/test/smoke.mjs @@ -88,6 +88,11 @@ if (argv.includes("models")) { process.stdout.write("gemini-test-medium\tGemini Test (Medium)\ngemini-test-high\tGemini Test (High)\ngemini-test-low\tGemini Test (Low)\nclaude-test-medium\tClaude Test (Medium)\n") process.exit(0) } +if (argv[0] === "acp" && argv.includes("--help")) { + log({ type: "acpHelp" }) + process.stderr.write("Usage of acp:\n --agent string\n --include-default-customizations\n \tload the default customizations (default true)\n") + process.exit(0) +} if (argv[0] !== "acp") { process.stderr.write("unknown subcommand\n") process.exit(2) @@ -475,7 +480,7 @@ async function handle(message) { model = "gemini-test-medium" await connectIde() log({ - type: "init", pid: process.pid, convId: session.id, resumed: message.method === "session/resume", update: process.env.AGY_CLI_DISABLE_AUTO_UPDATE, + type: "init", args: argv, pid: process.pid, convId: session.id, resumed: message.method === "session/resume", update: process.env.AGY_CLI_DISABLE_AUTO_UPDATE, cwd: process.cwd(), addDir, agentConfig, clientInfo, systemAppend: params._meta?.antigravity?.systemPrompt?.append ?? null, tools, idePort, }) @@ -2818,6 +2823,12 @@ for (const location of ["inline", "system", "developer", "user"]) { check("AGY_BRIDGE_MINIMAL_AGENT=1 turns on the minimal agent", !!init && init.agentConfig.includes("excludeDefaultComponents: true"), init?.agentConfig) } +{ + // the bridge's sessions; the bare `agy acp` model probe only lists models + const sessions = inits().filter(event => event.args.includes("--agent")) + const without = sessions.filter(event => !event.args.includes("--include-default-customizations=false")) + check("an agy whose acp --help lists it starts without the machine's own customizations (#1166)", sessions.length > 0 && without.length === 0, JSON.stringify(without.map(event => event.args))) +} check("all ACP children disable auto update when the user set nothing", inits().length > 0 && inits().every(event => event.update === "true")) check("child launches never mutate the parent's update setting", process.env.AGY_CLI_DISABLE_AUTO_UPDATE === undefined) if (originalAutoUpdate === undefined) delete process.env.AGY_CLI_DISABLE_AUTO_UPDATE diff --git a/packages/agy-cli/test/testkit.mjs b/packages/agy-cli/test/testkit.mjs index 0902dd6..995309f 100644 --- a/packages/agy-cli/test/testkit.mjs +++ b/packages/agy-cli/test/testkit.mjs @@ -419,6 +419,7 @@ export async function createBridgeKit(options = {}) { modelsSpawns: [], acpSpawns: [], otherSpawns: [], + helpSpawns: [], spawnSyncs: [], execFiles: [], modelsBehavior: options.modelsBehavior ?? { stdout: modelsOutput(BASE_MODEL_ROWS) }, @@ -469,6 +470,16 @@ export async function createBridgeKit(options = {}) { }) const spawn = (file, args = [], opts = {}) => { if (args[0] === "models") return spawnModels(kit, file, args) + if (args[0] === "acp" && args.includes("--help")) { + // agy's flag usage goes to stderr; an older agy doesn't list the flag + kit.helpSpawns.push({ file, args }) + const child = new FakeChild(kit, file, args) + setImmediate(() => { + if (options.acpHelp) child.stderr.emit("data", options.acpHelp) + child.finish(0) + }) + return child + } if (args[0] === "acp") { const child = new FakeChild(kit, file, args) kit.acpSpawns.push({ file, args, env: opts.env })