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 })