diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 4e196b6..f6eefdd 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -208,7 +208,8 @@ function findAgy() { // but on Windows it still loaded all 120 of a user's skills; --gemini-dir // pointed at a folder of the bridge's own leaves them all out (the reporter // ran it: no skills, every client tool listed). agy's Google sign-in is in -// the system keyring, not in that folder (signin.mjs), so it still applies. +// the system keyring, not in that folder (signin.mjs), so it still applies; +// with no keyring it is a file in the folder, and see fileSignIn. // An agy without these flags refuses to start on them, so each 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 @@ -248,9 +249,22 @@ export function bridgeGeminiDir(env = process.env) { // geminiDirArgs gives agy the bridge's own folder when its acp lists // --gemini-dir and the folder can be made, else nothing (agy's ~/.gemini). +// Where no keyring is (a Docker container, a Linux with no D-Bus session), +// agy keeps its Google sign-in in a file under its folder instead, and a +// folder of the bridge's own would have no sign-in (plugins#1165): then agy +// stays on its own, unless AGY_BRIDGE_GEMINI_DIR names one. +export function fileSignIn(home = os.homedir()) { + try { + return fs.statSync(path.join(home, ".gemini", "antigravity-cli", "antigravity-oauth-token")).isFile() + } catch { + return false + } +} + export async function geminiDirArgs(agyPath, env = process.env) { const dir = bridgeGeminiDir(env) - if (!dir || !/--gemini[-_]dir\b/.test(await acpHelp(agyPath))) return { args: [], dir: null } + if (!dir || (!env.AGY_BRIDGE_GEMINI_DIR && fileSignIn())) return { args: [], dir: null } + if (!/--gemini[-_]dir\b/.test(await acpHelp(agyPath))) return { args: [], dir: null } try { await fs.promises.mkdir(dir, { recursive: true, mode: 0o700 }) } catch { diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index b7ddfa2..852e5e9 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.54", + "version": "0.1.55", "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 1278c03..b4fe2b5 100644 --- a/packages/agy-cli/test/repeat-batch.mjs +++ b/packages/agy-cli/test/repeat-batch.mjs @@ -1066,6 +1066,33 @@ test("#1166: an agy whose acp --help lists --gemini-dir runs in the bridge's own }) }) +test("#1165: with agy's sign-in in a file under ~/.gemini (no keyring, Docker), agy stays on that folder", async () => { + await withKit({ acpHelp: GEMINI_DIR_HELP }, async (kit) => { + const token = path.join(kit.env.HOME, ".gemini", "antigravity-cli", "antigravity-oauth-token") + fs.mkdirSync(path.dirname(token), { recursive: true }) + fs.writeFileSync(token, "{}", { mode: 0o600 }) + scriptedAgent(kit) + const reply = await readSse(await kit.request(baseBody({ metadata: { user_id: "file-token" }, messages: [{ role: "user", content: "hello" }] }))) + assert.equal(reply.stopReason, "end_turn") + assert.ok(!kit.acpSpawns[0].args.includes("--gemini-dir"), kit.acpSpawns[0].args.join(" ")) + assert.ok(kit.acpSpawns[0].args.includes("--include-default-customizations=false")) + }) +}) + +test("#1165: a folder AGY_BRIDGE_GEMINI_DIR names is used even with a file sign-in", async () => { + await withKit({ acpHelp: GEMINI_DIR_HELP }, async (kit) => { + const named = path.join(kit.env.HOME, "named-agy") + kit.env.AGY_BRIDGE_GEMINI_DIR = named + const token = path.join(kit.env.HOME, ".gemini", "antigravity-cli", "antigravity-oauth-token") + fs.mkdirSync(path.dirname(token), { recursive: true }) + fs.writeFileSync(token, "{}") + scriptedAgent(kit) + await readSse(await kit.request(baseBody({ metadata: { user_id: "file-token-named" }, messages: [{ role: "user", content: "hello" }] }))) + const args = kit.acpSpawns[0].args + assert.equal(args[args.indexOf("--gemini-dir") + 1], named, args.join(" ")) + }) +}) + test("#1166: AGY_BRIDGE_GEMINI_DIR=default leaves agy on the machine's own folder", async () => { await withKit({ acpHelp: GEMINI_DIR_HELP, env: { AGY_BRIDGE_GEMINI_DIR: "default" } }, async (kit) => { scriptedAgent(kit)