diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md index 60bfd36d3..0ef2ba81b 100644 --- a/docs/subsystems/library.md +++ b/docs/subsystems/library.md @@ -26,7 +26,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it. | Skill updates | A skill from GitHub (`kind: github`, a market install among them) keeps the commit it was fetched at and `Hash`, the hash of its files as fetched. `CheckSkills` asks GitHub for each one's last commit and keeps the result in memory; `View.CheckDue` says none was checked since magpie started, or not for `checkEvery` (12 hours), and the page then checks by itself as the skills open (#1449). `editState` says a skill was changed here when the library's folder no longer hashes to `Hash` (`.DS_Store` aside), or an agent's copy was edited since its mark and not yet taken in; the view's `edited` says so. `UpdateSkill` refuses such a skill with `*EditedError` unless told to replace it (the page's own Update asks first; the CLI takes `--replace-edits`), and `UpdateSkills`/`UpdateSomeSkills` leave it as it is, in `Unupdated`. A replaced version that was changed, or that can't be told (no `Hash`), is moved to the backups (`keepReplaced`). Skills the skills CLI manages (`npx skills`, `~/.agents/.skill-lock.json`) are only grouped: the CLI updates them (`npx skills update`). A linked folder, a skill imported from an agent and a `From`-only skill have no remote to check; one CC Switch installed (`Origin`) can be updated by hand but isn't checked. | [`skill_changed.go`](../../internal/library/skill_changed.go), [`skillcheck.go`](../../internal/library/skillcheck.go), [`skills.go`](../../internal/library/skills.go) | | Hooks | A `Hook` (#1790) is a command, an event, an optional matcher, a timeout and the agents ticked for it. Its optional `Description` (#2011) says what it is for in any language, since its name is letters, digits, - and _: one line of at most `maxHookDescription` (200) characters, shown under the name; only library.json keeps it, and no agent is given it. Its event is portable (`HookEvents`: turn-end, after-tool, before-tool, prompt, session-start, each under the agent's own name) or an agent's own (`"codex:PermissionRequest"`), which only that agent is given. A portable tool event can be narrowed to shell or edit tools, each agent's own tool names for them. `syncHooks` writes each into the agent's own file and shape (`hookSpecOf`): Claude Code `/settings.json`, Codex `hooks.json` beside its config.toml, Gemini CLI `~/.gemini/settings.json` (timeout in ms), Cursor `~/.cursor/hooks.json` (flat entries, `version: 1`), and Grok Build `~/.grok/config.toml` and Grok App `agent-home/config.toml` as `[[hooks.]]` array tables with a `[[hooks..hooks]]` child. Grok Build and Grok App run the one CLI, so a `grok:` own event goes to both (`sameHookFamily`). Every other agent, and an agent in WSL, is refused with why, and the page greys its chip with that reason. The page also says when an agent has every hook turned off (`hooksOff`: Claude Code's `disableAllHooks`, Gemini's `hooksConfig.enabled`, Codex's `[features] hooks`). | [`hooks.go`](../../internal/library/hooks.go) | | Backups | Before a change first writes an agent file, `backups` copies it to `BackupDir`, one folder per change. The last `keepBackups` (30) changes are kept. The Backups button at the top of every tab, beside Library folder, opens that folder (`libHead`; Dade on Discord found it at the foot of a long page). | [`backup.go`](../../internal/library/backup.go) | -| RTK | `SetRTK` runs rtk's own installer (`rtk init -g …`) for an agent being switched on. For one being switched off, it removes exactly what the installer wrote, using magpie's own code, which works even with rtk gone. `ReadRTK` reads each agent's files to say which have the hook. `rtkSpec.blocked` stops the installer where it would break an agent. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. A detected agent RTK has no hook for at all is still listed, from `rtkNoHook`, with the reason and a switch that can't be turned on (dsh: its hooks can allow or deny a command but not rewrite it, and `rtk init` has no `--agent dsh`; Grok Build and Grok App: `rtk init` has no Grok or Grok App agent, so both are listed with the switch off). | [`rtk.go`](../../internal/library/rtk.go) | +| RTK | `SetRTK` runs rtk's own installer (`rtk init -g …`) for an agent being switched on. For one being switched off, it removes exactly what the installer wrote, using magpie's own code, which works even with rtk gone. `ReadRTK` reads each agent's files to say which have the hook. `rtkSpec.blocked` stops the installer where it would break an agent. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. Antigravity CLI (`agy`, #2202) gets rtk 0.51's own plugin for Antigravity, `plugins/rtk` in its global customization folder `~/.gemini/config` (`plugin.json`, `hooks.json` with `PreToolUse` → `rtk hook antigravity`, `rules/AGENTS.md`), which `agy plugin list` lists; switching it off takes that one folder out. rtk 0.50 knows Antigravity only per project and fails `rtk init -g --agent antigravity`, so an older rtk is `blocked` (`agyBlocked`) and the row says to update RTK. A detected agent RTK has no hook for at all is still listed, from `rtkNoHook`, with the reason and a switch that can't be turned on (dsh: its hooks can allow or deny a command but not rewrite it, and `rtk init` has no `--agent dsh`; Grok Build and Grok App: `rtk init` has no Grok or Grok App agent, so both are listed with the switch off). | [`rtk.go`](../../internal/library/rtk.go) | ## Runtime path diff --git a/internal/gui/assets/plugins/library/client.js b/internal/gui/assets/plugins/library/client.js index 55dba86c5..7d74dc140 100644 --- a/internal/gui/assets/plugins/library/client.js +++ b/internal/gui/assets/plugins/library/client.js @@ -936,6 +936,8 @@ magpie.plugin("library", (ctx) => { // be switched on, and one already there can be switched off // an agent RTK has no hook for (DeepSeek Harness): listed, with why if (a.noHook) row.append(tag(t("No RTK hook"), "warn", t("RTK can't be given to {agent} yet: RTK works by rewriting the shell command an agent is about to run, and {agent}'s hooks can only allow or deny a command, not change it. RTK's installer has no option for it either (github.com/rtk-ai/rtk/issues/3847).", { agent: a.name }))); + // RTK before 0.51 installs Antigravity's hook only per project + else if (a.blocked && a.id === "agy") row.append(tag(t("Update RTK"), "warn", t("{agent}'s hook needs RTK 0.51 or newer: older ones install it only per project. Update RTK (brew upgrade rtk, or its installer again), then switch it on.", { agent: a.name }))); else if (a.blocked && a.id !== "opencode") row.append(tag(t("Update RTK"), "warn", t("{agent}'s hook needs RTK 0.50 or newer: older ones only add @RTK.md to AGENTS.md, which rewrites no command. Update RTK (brew upgrade rtk, or its installer again), then switch it on.", { agent: a.name }))); else if (a.blocked) row.append(tag(t("Not for OpenCode 2"), "warn", a.on ? t("RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. Switch this off until RTK supports OpenCode 2.") diff --git a/internal/gui/assets/plugins/library/i18n.js b/internal/gui/assets/plugins/library/i18n.js index f32e06cec..296b56c6b 100644 --- a/internal/gui/assets/plugins/library/i18n.js +++ b/internal/gui/assets/plugins/library/i18n.js @@ -139,6 +139,7 @@ magpie.strings({ "RTK is on your PATH": "RTK 已在 PATH 中", "Not for OpenCode 2": "不支持 OpenCode 2", "{agent}'s hook needs RTK 0.50 or newer: older ones only add @RTK.md to AGENTS.md, which rewrites no command. Update RTK (brew upgrade rtk, or its installer again), then switch it on.": "{agent} 的 hook 需要 RTK 0.50 或更高版本:旧版只在 AGENTS.md 中加一行 @RTK.md,不改写命令。请先更新 RTK(brew upgrade rtk,或重新运行其安装脚本)再打开。", + "{agent}'s hook needs RTK 0.51 or newer: older ones install it only per project. Update RTK (brew upgrade rtk, or its installer again), then switch it on.": "{agent} 的 hook 需要 RTK 0.51 或更高版本:旧版只能按项目安装。请先更新 RTK(brew upgrade rtk,或重新运行其安装脚本)再打开。", "RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. Switch this off until RTK supports OpenCode 2.": "RTK 插件为 OpenCode 1 编写,OpenCode 2 拒绝加载。在 RTK 支持 OpenCode 2 前请关闭此开关。", "RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. It can be switched on once RTK supports OpenCode 2.": "RTK 插件为 OpenCode 1 编写,OpenCode 2 拒绝加载。RTK 支持 OpenCode 2 后才能打开。", "No RTK hook": "RTK 暂不支持", @@ -703,6 +704,7 @@ magpie.strings({ "RTK is on your PATH": "RTK 已在 PATH 中", "Not for OpenCode 2": "不支援 OpenCode 2", "{agent}'s hook needs RTK 0.50 or newer: older ones only add @RTK.md to AGENTS.md, which rewrites no command. Update RTK (brew upgrade rtk, or its installer again), then switch it on.": "{agent} 的 hook 需要 RTK 0.50 或更高版本:舊版只在 AGENTS.md 中加一行 @RTK.md,不改寫命令。請先更新 RTK(brew upgrade rtk,或重新執行其安裝指令碼)再開啟。", + "{agent}'s hook needs RTK 0.51 or newer: older ones install it only per project. Update RTK (brew upgrade rtk, or its installer again), then switch it on.": "{agent} 的 hook 需要 RTK 0.51 或更高版本:舊版只能按專案安裝。請先更新 RTK(brew upgrade rtk,或重新執行其安裝指令碼)再開啟。", "RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. Switch this off until RTK supports OpenCode 2.": "RTK 外掛為 OpenCode 1 編寫,OpenCode 2 拒絕載入。在 RTK 支援 OpenCode 2 前請關閉此開關。", "RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. It can be switched on once RTK supports OpenCode 2.": "RTK 外掛為 OpenCode 1 編寫,OpenCode 2 拒絕載入。RTK 支援 OpenCode 2 後才能開啟。", "No RTK hook": "RTK 暫不支援", @@ -1262,6 +1264,7 @@ magpie.strings({ "RTK is on your PATH": "RTK は PATH にあります", "Not for OpenCode 2": "OpenCode 2 非対応", "{agent}'s hook needs RTK 0.50 or newer: older ones only add @RTK.md to AGENTS.md, which rewrites no command. Update RTK (brew upgrade rtk, or its installer again), then switch it on.": "{agent} のフックには RTK 0.50 以降が必要です。古いバージョンは AGENTS.md に @RTK.md を追加するだけで、コマンドを書き換えません。RTK を更新(brew upgrade rtk、またはインストーラを再実行)してからオンにしてください。", + "{agent}'s hook needs RTK 0.51 or newer: older ones install it only per project. Update RTK (brew upgrade rtk, or its installer again), then switch it on.": "{agent} のフックには RTK 0.51 以降が必要です。古いバージョンはプロジェクト単位でしかインストールできません。RTK を更新(brew upgrade rtk、またはインストーラを再実行)してからオンにしてください。", "RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. Switch this off until RTK supports OpenCode 2.": "RTK のプラグインは OpenCode 1 向けに書かれており、OpenCode 2 は読み込みを拒否します。RTK が OpenCode 2 に対応するまでオフにしてください。", "RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. It can be switched on once RTK supports OpenCode 2.": "RTK のプラグインは OpenCode 1 向けに書かれており、OpenCode 2 は読み込みを拒否します。RTK が OpenCode 2 に対応したらオンにできます。", "No RTK hook": "RTK 未対応", @@ -1824,6 +1827,7 @@ magpie.strings({ "RTK is on your PATH": "RTK ist im PATH", "Not for OpenCode 2": "Nicht für OpenCode 2", "{agent}'s hook needs RTK 0.50 or newer: older ones only add @RTK.md to AGENTS.md, which rewrites no command. Update RTK (brew upgrade rtk, or its installer again), then switch it on.": "Der Hook von {agent} benötigt RTK 0.50 oder neuer: Ältere Versionen fügen nur @RTK.md zu AGENTS.md hinzu, was keinen Befehl umschreibt. Aktualisieren Sie RTK (brew upgrade rtk oder erneut über den Installer) und schalten Sie es dann ein.", + "{agent}'s hook needs RTK 0.51 or newer: older ones install it only per project. Update RTK (brew upgrade rtk, or its installer again), then switch it on.": "Der Hook von {agent} benötigt RTK 0.51 oder neuer: Ältere Versionen installieren ihn nur pro Projekt. Aktualisieren Sie RTK (brew upgrade rtk oder erneut über den Installer) und schalten Sie es dann ein.", "RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. Switch this off until RTK supports OpenCode 2.": "Die Erweiterung von RTK ist für OpenCode 1 geschrieben, und OpenCode 2 lädt sie nicht. Schalten Sie dies aus, bis RTK OpenCode 2 unterstützt.", "RTK's plugin is written for OpenCode 1, and OpenCode 2 refuses to load it. It can be switched on once RTK supports OpenCode 2.": "Die Erweiterung von RTK ist für OpenCode 1 geschrieben, und OpenCode 2 lädt sie nicht. Sie lässt sich einschalten, sobald RTK OpenCode 2 unterstützt.", "No RTK hook": "Kein RTK-Hook", diff --git a/internal/gui/tests/library-rtk-agy.test.cjs b/internal/gui/tests/library-rtk-agy.test.cjs new file mode 100644 index 000000000..cbe6e52a5 --- /dev/null +++ b/internal/gui/tests/library-rtk-agy.test.cjs @@ -0,0 +1,102 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// #2202 (Chichengmo): Antigravity CLI wasn't on the RTK tab, though rtk +// 0.51 has a global plugin for it. With an rtk older than 0.51 (0.50 knows +// it only per project) its row says to update RTK with its own reason, not +// Codex's @RTK.md one, and its switch can't be turned on; Codex's row keeps +// its own words. Every language, Chromium and WebKit, 1100 and 420 wide, +// nothing sideways. No backend: the API is faked here. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const HOME = "/Users/aimer"; +const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` }); +const lib = () => ({ + dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME, + agents: [agent("agy", "Antigravity CLI"), agent("codex", "Codex")], + instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [], servers: [], +}); +const rtkView = () => ({ + path: `${HOME}/.local/bin/rtk`, version: "0.49.0", url: "https://www.rtk-ai.app", + agents: [ + { id: "agy", name: "Antigravity CLI", icon: "", on: false, blocked: "Antigravity CLI's hook needs RTK 0.51 or newer" }, + { id: "codex", name: "Codex", icon: "", on: false, blocked: "Codex's hook needs RTK 0.50 or newer" }, + ], +}); + +function server(lang, calls) { + return async (route) => { + const req = route.request(), url = new URL(req.url()); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return route.fulfill({ json: { agents: [], profiles: [], settings: { lang, theme: "light" } } }); + if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } }); + if (url.pathname === "/api/library") return route.fulfill({ json: lib() }); + if (url.pathname === "/api/library/rtk") { + if (req.method() !== "GET") calls.push(req.postData()); + return route.fulfill({ json: rtkView() }); + } + if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] }); + if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } }); + if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } }); + if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} }); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + await route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +const LANGS = ["en", "zh", "zh-TW", "ja", "de"]; +const words = { + en: { tag: "Update RTK", agy: "needs RTK 0.51 or newer: older ones install it only per project", codex: "needs RTK 0.50 or newer" }, + zh: { tag: "需更新 RTK", agy: "需要 RTK 0.51 或更高版本:旧版只能按项目安装", codex: "需要 RTK 0.50" }, + "zh-TW": { tag: "需更新 RTK", agy: "需要 RTK 0.51 或更高版本:舊版只能按專案安裝", codex: "需要 RTK 0.50" }, + ja: { tag: "RTK の更新が必要", agy: "RTK 0.51 以降が必要です。古いバージョンはプロジェクト単位でしかインストールできません", codex: "RTK 0.50 以降" }, + de: { tag: "RTK aktualisieren", agy: "benötigt RTK 0.51 oder neuer: Ältere Versionen installieren ihn nur pro Projekt", codex: "RTK 0.50 oder neuer" }, +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": Antigravity CLI with an RTK before 0.51 says to update, in its own words", async (t) => { + assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit"); + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const errors = []; + t.after(async () => { + if (errors.length) console.log(errors); + await browser.close(); + }); + for (const lang of LANGS) for (const width of [1100, 420]) { + await t.test(`${lang} ${width}`, async () => { + const w = words[lang], calls = []; + const ctx = await browser.newContext({ viewport: { width, height: 800 } }); + await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "rtk"); } catch {} }); + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, calls)); + await page.goto("http://magpie.test/"); + await page.locator('button[data-view="library"]').click(); + const v = page.locator("#view-library"); + const row = (name) => v.locator(".lib-row").filter({ has: page.locator(".name", { hasText: name }) }); + await row("Antigravity CLI").waitFor(); + const tag = row("Antigravity CLI").locator(".lib-tag"); + assert.deepEqual(await tag.allTextContents(), [w.tag]); + const why = await tag.getAttribute("title"); + assert(why.includes(w.agy), why); + assert(!why.includes("@RTK.md"), why); + const ctag = await row("Codex").locator(".lib-tag").getAttribute("title"); + assert(ctag.includes(w.codex) && ctag.includes("@RTK.md"), ctag); + const sw = row("Antigravity CLI").locator(".lib-switch"); + assert.equal(await sw.isDisabled(), true); + await sw.click({ force: true }); + assert.deepEqual(calls, []); + const sideways = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + assert(sideways <= 0, `the page scrolls sideways by ${sideways}px`); + await ctx.close(); + }); + } + assert.deepEqual(errors, []); + }); +} diff --git a/internal/library/rtk.go b/internal/library/rtk.go index 09a072ba8..fb859a791 100644 --- a/internal/library/rtk.go +++ b/internal/library/rtk.go @@ -172,6 +172,26 @@ var rtkSpecs = map[string]rtkSpec{ }, dir: func(*agent.Agent) string { return filepath.Join(home(), ".copilot") }, }, + // Antigravity CLI (agy): rtk 0.51 on writes a plugin of its own into + // Antigravity's global customization folder, ~/.gemini/config, shared + // by the CLI and the IDE (src/hooks/init/antigravity.rs): plugin.json, + // hooks.json (PreToolUse → rtk hook antigravity) and rules/AGENTS.md, + // all in plugins/rtk. agy discovers a plugin there by its plugin.json. + // The Antigravity branch reads no patch mode, so --auto-patch isn't + // given; rtk's own uninstaller for it ran Claude Code's + // (rtk-ai/rtk#3404), so the folder is taken out by magpie. + "agy": { + flags: []string{"--agent", "antigravity"}, blocked: agyBlocked, + has: func(*agent.Agent) bool { + return contains(filepath.Join(agyPlugin(), "hooks.json"), "rtk hook antigravity") + }, + files: func(*agent.Agent) []string { + d := agyPlugin() + return []string{filepath.Join(d, "plugin.json"), filepath.Join(d, "hooks.json"), filepath.Join(d, "rules", "AGENTS.md")} + }, + remove: func(*agent.Agent) error { return os.RemoveAll(agyPlugin()) }, + dir: func(*agent.Agent) string { return filepath.Dir(filepath.Dir(agyPlugin())) }, + }, "pi": extensionSpec("pi"), "omp": extensionSpec("omp"), // Hermes's folder is the agent's (appdir.HermesHome): $HERMES_HOME, @@ -246,6 +266,20 @@ func codexBlocked() string { return fmt.Sprintf("Codex's hook needs RTK 0.50 or newer, and this RTK is %s: older ones only add @RTK.md to AGENTS.md, which rewrites no command. Update RTK (brew upgrade rtk, or its installer again), then switch it on", v) } +// agyPlugin is the folder rtk's installer writes its Antigravity plugin to. +func agyPlugin() string { return filepath.Join(home(), ".gemini", "config", "plugins", "rtk") } + +// agyBlocked: rtk installs for Antigravity globally from 0.51.0 on; 0.50 +// knows it only per project and fails rtk init -g --agent antigravity +// ("Antigravity is project-scoped"), so an older rtk isn't run for it. +func agyBlocked() string { + v := rtkVersion() + if v == "" || !older(v, 0, 51) { + return "" + } + return fmt.Sprintf("Antigravity CLI's hook needs RTK 0.51 or newer, and this RTK is %s, which installs it only per project, not for every project. Update RTK (brew upgrade rtk, or its installer again), then switch it on", v) +} + // older says whether version v is before major.minor. func older(v string, major, minor int) bool { var a, b int diff --git a/internal/library/rtk_agy_test.go b/internal/library/rtk_agy_test.go new file mode 100644 index 000000000..39d681d99 --- /dev/null +++ b/internal/library/rtk_agy_test.go @@ -0,0 +1,115 @@ +package library + +import ( + "os" + "path/filepath" + "runtime" + "strings" + "testing" + + "github.com/yetone/magpie/internal/testenv" +) + +// fakeRTKAgy acts as rtk 0.51's rtk init -g --agent antigravity does +// (src/hooks/init/antigravity.rs): a plugin of its own in +// ~/.gemini/config/plugins/rtk, with the hooks.json it writes word for +// word. Any other arguments (--auto-patch among them) are refused. +const fakeRTKAgy = `#!/bin/sh +case "$1" in +--version) echo "rtk $RTK_V"; exit 0 ;; +gain) exit 1 ;; +esac +shift 2 +[ "$*" = "--agent antigravity" ] || { echo "unknown: $*" >&2; exit 2; } +d="$HOME/.gemini/config/plugins/rtk" +/bin/mkdir -p "$d/rules" +echo "rtk rules" > "$d/rules/AGENTS.md" +/bin/cat > "$d/hooks.json" <<'J' +{ + "rtk-rewrite": { + "enabled": true, + "PreToolUse": [ + { + "matcher": "run_command", + "hooks": [ + { + "type": "command", + "command": "rtk hook antigravity", + "timeout": 10 + } + ] + } + ] + } +} +J +echo '{"name": "rtk", "version": "1.0.0"}' > "$d/plugin.json" +` + +// #2202 (Chichengmo): Antigravity CLI wasn't on the RTK page at all, +// though rtk 0.51 has an Antigravity agent. It is listed, switched on with +// rtk's installer, switched off by magpie taking rtk's plugin out (and only +// it), and an rtk before 0.51, which has no such agent, isn't run for it. +func TestRTKAntigravity(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("the fake rtk is a shell script") + } + h := sandbox(t) + bin := filepath.Join(h, "bin") + testenv.Program(t, filepath.Join(bin, "rtk"), fakeRTKAgy) + t.Setenv("PATH", bin) + // Antigravity CLI is here by its folder + write(t, filepath.Join(h, ".gemini", "antigravity-cli", "settings.json"), "{}") + // another plugin of the user's beside rtk's stays + mine := filepath.Join(h, ".gemini", "config", "plugins", "mine", "plugin.json") + write(t, mine, `{"name":"mine"}`) + plugin := filepath.Join(h, ".gemini", "config", "plugins", "rtk") + row := func() *RTKAgent { + t.Helper() + for _, a := range ReadRTK().Agents { + if a.ID == "agy" { + return &a + } + } + t.Fatal("Antigravity CLI isn't on the RTK page") + return nil + } + + t.Setenv("RTK_V", "0.50.0") + if a := row(); !strings.Contains(a.Blocked, "0.51") || a.On || a.NoHook { + t.Fatalf("rtk 0.50: %+v", a) + } + if _, err := SetRTK("agy", true); err == nil || !strings.Contains(err.Error(), "RTK 0.51 or newer") { + t.Fatalf("switched on with rtk 0.50: %v", err) + } + if exists(plugin) { + t.Fatal("rtk 0.50's installer was run for Antigravity") + } + + t.Setenv("RTK_V", "0.51.0") + if a := row(); a.Blocked != "" || a.On { + t.Fatalf("rtk 0.51 before switching on: %+v", a) + } + if _, err := SetRTK("agy", true); err != nil { + t.Fatal(err) + } + if a := row(); !a.On { + t.Fatal("Antigravity CLI isn't seen with rtk on") + } + if id, err := RTKTakes("agy"); err != nil || id != "agy" { + t.Fatalf("RTKTakes(agy) = %q, %v", id, err) + } + if _, err := SetRTK("agy", false); err != nil { + t.Fatal(err) + } + if exists(plugin) { + t.Error("rtk's plugin is still in ~/.gemini/config/plugins") + } + if !exists(mine) { + t.Error("the user's own plugin was taken out with rtk's") + } + if a := row(); a.On { + t.Fatal("Antigravity CLI still seen with rtk on") + } + os.Remove(mine) +}