From e34228669caf4b41841d16b86d16c5cfc532eb59 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 16 Nov 2026 04:49:33 +0800 Subject: [PATCH] library: agy's GEMINI.md is no longer emptied by Antigravity's app switched off vizmoe42 on X (v0.1.4271): Library -> Instructions had agy CLI's GEMINI.md switched on, but ~/.gemini/config/GEMINI.md held nothing. agy and Antigravity's app share that file (and its folder). With the built-in agy the targets run agy first, then Antigravity; agy wrote its part and the unticked Antigravity row, wanting nothing, took it out again, leaving the file empty or gone. The unticked row also showed "edited". With agy on its plugin the order is reversed, so it worked by luck there. syncInstructions now takes every target. A file another target reads too belongs to the one switched on (instrOwner): the others leave it and drop their own record. The Edited check compares against that owner's text (wantedIn). The path itself is right: agy 1.5.9 reads ~/.gemini/GEMINI.md, ~/.gemini/AGENTS.md and their config/ copies (binary strings and `agy changelog`, sandbox HOME). MCP and skills in the shared folder already behaved; probed, unchanged. Existing users: agy's record says written but the file has no block, so the next start-up Sync writes it, without switching anything again (covered by the test). Run: - TestAntigravitySharedInstructionsFile (agy and antigravity subtests), red on the old code (file empty after the switch; agy row Edited), green with the fix, on mica. - go vet ./internal/library; go test -count=1 ./internal/library ./internal/gui ./internal/tui ./internal/cli: all ok on mica. - At the pushed head (rebased on e47abdf46, no library change upstream): GOOS=linux and GOOS=windows go vet ./internal/library and the library's Antigravity and Instruction tests, ok on mote. - gofmt -l clean. Not tried: a real agy session reading the written file; Windows or WSL; the GUI clicked by hand (no GUI file changed). --- docs/subsystems/library.md | 2 +- internal/library/antigravity_test.go | 54 ++++++++++++++++++++++++++++ internal/library/instructions.go | 50 ++++++++++++++++++++++---- internal/library/sync.go | 2 +- 4 files changed, 99 insertions(+), 9 deletions(-) diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md index 9d9d62961..6e806cf68 100644 --- a/docs/subsystems/library.md +++ b/docs/subsystems/library.md @@ -23,7 +23,7 @@ Pi's extensions and packages. | Stopped WSL distro | A stopped distro's agents are no targets: opening their files would start the distro, or the read fails (#3896). While a distro runs, `keepShape` keeps each agent's places and what its MCP file takes in `wsl.json` (`agent.WSLKeep`, key `library:`). While it is stopped, `Read` lists its agents from that (`asleepView`, `asleep: `), ticks as library.json has them; one magpie never saw there is listed only on the rows that name it, as `unseen`, its ticks not shown (cybercaius on Discord: the MCP page knew a distro's agents only once WSL had started). A tick on a stopped agent is kept in library.json as any is (`Takes` accepts one with a known shape; `serversAgents` judges it by `shape.reaches`), nothing is written and nothing in the distro runs; `Woken`, from `KeepLinked`'s loop (and the app's start-up sync), syncs when a distro the library names is seen go from stopped to running (`wsl.exe -l --running`, which starts nothing). The page greys a stopped agent's chip, says so in its tooltip and in one line per distro (`.lib-asleep`); an unseen chip is `aria-disabled` and kept by every click on its row (`keptOf`). The CLI says the same on stderr (`AsleepIn`). Queued, not a start button: a start costs the memory #3896 is about, and All or a bulk tick would start every distro. The Instructions page lists them too (`asleepInstructions`, #4182), at the instructions file the shape keeps, switched on as library.json has them, with what each gets besides (magpie's own folder) and nothing read from the file: its own lines and edits aren't counted then, and its path is plain text, not a reveal, which would open the distro. One switched on whose file magpie never saw is listed as `unseen`, its switch greyed out and kept by every other switch; before, a switch on the page sent the agents without the stopped distro's and took them off. A switch on one is written by `Woken`, which watches a distro named in `Instructions.Agents`, or whose agent still has magpie's part (`Applied.Instructions`), so one switched off has it taken out. The Hooks page lists the stopped agents with a shape as it does while the distro runs (`hooksView`, #4237): greyed, since magpie gives no agent in WSL hooks yet (`wslNoHooks`), and a hook given one says so; there is nothing for `Woken` to write. So does the Subagents page for the kinds it lists (`subagentsView`, `wslNoSubagents`, #4238). | [`wsl_asleep.go`](../../internal/library/wsl_asleep.go), [`targets.go`](../../internal/library/targets.go), [`plugins/library/client.js`](../../internal/gui/assets/plugins/library/client.js) | | Sync | `sync` writes each target's instructions and MCP servers. It then takes edits made in agents' skill copies into the library (`takeEdits`) and links or copies the skills. `~/.agents/skills` goes first (`sweepShared`, then `syncShared` for the Put skills in setting), so an agent that reads it gets no second link. Then it syncs projects' skills. | [`sync.go`](../../internal/library/sync.go) | | Projects | A project (`Project`) is a folder given some of the library's skills and MCP servers, each for some agents. A skill is linked (or copied) into the folder the agent reads a project's skills from (`projectSkillsDirs`): `.claude/skills` for Claude Code, `.qoder/skills` for Qoder and Qoder CN, `.codebuddy/skills` for CodeBuddy Code, `.commandcode/skills` for Command Code, and `.agents/skills` for Codex, Gemini CLI, OpenCode, Pi, Cursor, Copilot CLI, Antigravity, Kimi, Goose, Grok, Droid, Cline and DeepSeek Harness (which reads it, and `.dsh/skills`, at the nearest folder up with a `.git`, else where it runs: a project folder inside a repository but not at its root doesn't reach it, #5172). A server is written into the file the agent reads a project's servers from (`projectMCPFiles`), in the shape its user-wide file has: `.mcp.json` for Claude Code and CodeBuddy Code (CodeBuddy's `mcp.json` when the project has that and no `.mcp.json`, since it reads only the first of the two), `.codex/config.toml`, `.gemini/settings.json`, `.cursor/mcp.json`, `opencode.json`, `.zcode/config.json`, `.pi/mcp.json`, `.qoder/settings.json`'s `mcpServers` for Qoder and Qoder CN, and `.factory/mcp.json` for Droid. Claude Code, Qoder and CodeBuddy ask the user to approve a project's server before using it. Only targets whose vendor source or docs name them are listed (each map's comment cites them); an agent with none (Copilot CLI's MCP, Zed, WorkBuddy, Command Code's MCP, whose `.mcp.json` has its own `transport` shape, DeepSeek Harness's MCP, whose servers are rows in its profiles' patch layers with no project layer) can't be picked for a project (eirc on Discord). `Placed`, `Wrote`, `Made` and `MadeFiles` record what magpie put there, the only things it takes away. Nothing of magpie's goes into the project's git: what it placed is listed in the repository's own `info/exclude` (`writeExclude`, one block per project between `excludeBegin(dir)` and `ignoreEnd`, read by every worktree, never committed), and the project's `.gitignore` is left as it is (a block an older magpie wrote there is taken out, `TestProjectKeptOutOfGitByExclude`). A folder outside git gets no ignore file; once it is `git init`ed, `treesChanged` sees no block and the next `KeepLinked` writes it (`TestProjectOutsideGit`). A project is the global set ± its own (WhyULose0 on X): `ServersOff` and `SkillsOff` turn a global server or skill off in the project for some agents (`ProjectServerOff`, `ProjectSkillsOff`; `POST /api/library/projects/server-off` and `skill-off` with `dir`, `name`/`names`, `agents`; none gives it back). Each is done the way the agent reads it for a folder (`project_scope.go`): Claude Code's record of the project in `~/.claude.json` (`projects[
]`, `claudeRoot`) gets the name in `disabledMcpServers`, where magpie takes out only names it added (`Claude.Off`); Codex gets `[mcp_servers.] enabled = false` in the project's `.codex/config.toml`, only for a server in its own config (`CodexOff`); a skill is `skillOverrides. = "off"` in the project's `.claude/settings.local.json` (`Overrides`), a value the user set there is theirs (`TestProjectServerOff`, `TestProjectSkillOff`). Only those (`ProjectOffAgents`, `ProjectSkillOffAgents`) can take an off, and a skill an agent reaches through the [skill router](skill-router.md) can't; the card shows a global agent that can't as always on, with why. With the [MCP router](mcp-router.md) on, a project that adds or turns off a server the router serves gives Claude Code and Codex their own hub entry, `~` (`projectHubs`): Claude Code's in its record's `mcpServers` (local scope), Codex's in the project's `.codex/config.toml`; the server added isn't written into `.mcp.json` then (`TestProjectSetThroughRouter`). Claude Code keys its record by the repository's main top folder, so a project in a subfolder turns its offs on for the whole repository. A git worktree of the project's repository follows the project (`treeDirs`, `Trees`): the project's folder in each worktree gets the same skills, servers and offs, and is let go when the worktree is removed; `KeepLinked` checks for new ones (`keepProjectTrees`, `TestProjectWorktreeFollows`). A project also takes the library's subagents (jinpwng on X; `Subagents`, `AgentFiles`, [`project_subagents.go`](../../internal/library/project_subagents.go)): one file per subagent in the folder the agent reads a project's subagents from (`projectSubagentDirs`, cited per agent in its comment): `.claude/agents` for Claude Code, `.codex/agents`, `.opencode/agents`, `.gemini/agents`, `.qwen/agents`, `.factory/droids` for Droid, `.cursor/agents` and `.github/agents` for Copilot, in that agent's own format. A file is recorded with its hash (`SubagentFile`) and rewritten or removed only while it is exactly as magpie wrote it, so a same-name file of the user's is never touched (`TestProjectSubagentsLeaveTheUsersFiles`); a subagent renamed in the library is renamed in each project (`TestProjectSubagentsFollowTheLibrary`); the files are kept out of git by the same `info/exclude` block and follow the project's worktrees. `POST /api/library/projects/subagents` with `dir`, `name`/`names`, `agents`; the Subagents tab lists the projects as Skills and MCP do (`project-subagents.test.cjs`). It has no CLI yet, like project servers. Hooks, instructions and Claude plugins have no project scope yet. `magpie library project …` (#5193, [`library_project_cli.go`](../../internal/cli/library_project_cli.go)) adds and removes a project and its skills through the same calls as the page (`AddProject`, `RemoveProject`, `ProjectSkills`, `ProjectSkill`, `ProjectCopy`); a skill added with no `agents=` goes to the agents the page's Skills menu picks (those the project's skills are for already, else every agent here with a project skills folder), and one not placed exits 1 with why (`TestLibraryProjectCmd`). A project card's Skills menu lists the skills by source as the Library does (`skillGroups(true)`, whatever sort the list has; one group is the flat list), a heading over each that ticks or unticks the whole group (`group` in `openProtoMenu`, half-ticked while some are in; Elorynth on X, `project-skills-groups.test.cjs`). | [`projects.go`](../../internal/library/projects.go), [`project_mcp.go`](../../internal/library/project_mcp.go), [`project_scope.go`](../../internal/library/project_scope.go), [`project_git.go`](../../internal/library/project_git.go) | -| Instructions | magpie's part of an agent's instructions file sits between two marker lines. The rest of the file is the user's. Several named sets can be switched between (#106). A set can be kept in a file of the user's own instead of `instruction-sets/` (`InstrSet.File`, 新v学员 on Discord): `~/.agents/AGENTS.md`, which Droid and omp read too. `textPath` reads it, `putText` keeps it aside and writes it but never removes it, removing the set lets go of it, and `linkable` refuses a file magpie writes into (an agent's own instructions, a file with the marker line), the library's own and another set's. The app's `KeepLinked` looks at the file every 30 s and writes a change into the agents (`SyncLinked`). A set's text is read without magpie's part (`setText`), and an agent whose instructions file is, links followed, the file the set on is kept in (`isSetFile`: `instructions.md` linked to `~/.claude/CLAUDE.md`, or both linked to one dotfile) gets no part written into it, and one written before is taken out with every part nested in it: read with its part, each sync wrote the whole file into that part again and it doubled, to gigabytes (#2349, `TestInstructionsSetLinkedToAgentsFile`). `Collect` carries the set's text, not where its file is; `Put` keeps this computer's file for the set and never empties it for a text not carried. Alma's file is `~/.config/alma/USER.md`, which its main chat reads into its system prompt as its owner's profile (0.4.164's `out/main/index.js`; a workspace's `USER.md` is read instead), and whose leading front matter (`name`, `telegram_id`, `discord_id`) is who its bots answer to (#2315, Jie211). The target is a `Profile`: magpie's part goes after the user's, so the front matter stays first, and `ImportInstructions` refuses it, as moving it out would take that front matter out of the file and into every agent's (`TestAlmaInstructionsKeepTheProfile`, `TestAlmaProfileIsNotImported`, `library-alma-profile.test.cjs`). MiniMax Code reads `AGENTS.md` in its data folder (`$MINIMAX_DATA_DIR`, else `~/.minimax`) before every conversation, so its target is that file (`TestMiniMaxCodeInstructions`). WorkBuddy and WorkBuddy AI keep theirs as a string in a JSON file: `personalization.customPrompt` in `app/app-config.json` of their folder, the Custom Instructions of the app's Personalization settings (`Target.Field`, `instr_field.go`). magpie's part goes into that string between the same marker lines, after the user's own prompt, and a `Field` write goes through `edit.SetJSON`, so every other key, its order and its indentation stay as the app wrote them; taking the part back leaves the file as it was, the field (and a `personalization` object nothing else is in) going out when it holds nothing. A file that is not JSON, or a field that holds something other than text, is unknown: it is reported and written over by nothing (`TestWorkBuddyInstructionsAreAJSONField`, `TestWorkBuddyInstructionsFromNothing`, `TestWorkBuddyInstructionsUnreadFileIsLeftAlone`, `TestWorkBuddyInstructionsImport`). The app's config service loads the file as it starts and writes it whole on a save (`AppConfigService`, 5.5.6's app.asar), so a change made while it runs may need a restart of the app, and may be lost to its next save of any setting; this has not been tried against a running app. | [`instructions.go`](../../internal/library/instructions.go) | +| Instructions | magpie's part of an agent's instructions file sits between two marker lines. The rest of the file is the user's. Several named sets can be switched between (#106). A set can be kept in a file of the user's own instead of `instruction-sets/` (`InstrSet.File`, 新v学员 on Discord): `~/.agents/AGENTS.md`, which Droid and omp read too. `textPath` reads it, `putText` keeps it aside and writes it but never removes it, removing the set lets go of it, and `linkable` refuses a file magpie writes into (an agent's own instructions, a file with the marker line), the library's own and another set's. The app's `KeepLinked` looks at the file every 30 s and writes a change into the agents (`SyncLinked`). A set's text is read without magpie's part (`setText`), and an agent whose instructions file is, links followed, the file the set on is kept in (`isSetFile`: `instructions.md` linked to `~/.claude/CLAUDE.md`, or both linked to one dotfile) gets no part written into it, and one written before is taken out with every part nested in it: read with its part, each sync wrote the whole file into that part again and it doubled, to gigabytes (#2349, `TestInstructionsSetLinkedToAgentsFile`). `Collect` carries the set's text, not where its file is; `Put` keeps this computer's file for the set and never empties it for a text not carried. Alma's file is `~/.config/alma/USER.md`, which its main chat reads into its system prompt as its owner's profile (0.4.164's `out/main/index.js`; a workspace's `USER.md` is read instead), and whose leading front matter (`name`, `telegram_id`, `discord_id`) is who its bots answer to (#2315, Jie211). The target is a `Profile`: magpie's part goes after the user's, so the front matter stays first, and `ImportInstructions` refuses it, as moving it out would take that front matter out of the file and into every agent's (`TestAlmaInstructionsKeepTheProfile`, `TestAlmaProfileIsNotImported`, `library-alma-profile.test.cjs`). MiniMax Code reads `AGENTS.md` in its data folder (`$MINIMAX_DATA_DIR`, else `~/.minimax`) before every conversation, so its target is that file (`TestMiniMaxCodeInstructions`). WorkBuddy and WorkBuddy AI keep theirs as a string in a JSON file: `personalization.customPrompt` in `app/app-config.json` of their folder, the Custom Instructions of the app's Personalization settings (`Target.Field`, `instr_field.go`). magpie's part goes into that string between the same marker lines, after the user's own prompt, and a `Field` write goes through `edit.SetJSON`, so every other key, its order and its indentation stay as the app wrote them; taking the part back leaves the file as it was, the field (and a `personalization` object nothing else is in) going out when it holds nothing. A file that is not JSON, or a field that holds something other than text, is unknown: it is reported and written over by nothing (`TestWorkBuddyInstructionsAreAJSONField`, `TestWorkBuddyInstructionsFromNothing`, `TestWorkBuddyInstructionsUnreadFileIsLeftAlone`, `TestWorkBuddyInstructionsImport`). The app's config service loads the file as it starts and writes it whole on a save (`AppConfigService`, 5.5.6's app.asar), so a change made while it runs may need a restart of the app, and may be lost to its next save of any setting; this has not been tried against a running app. A file several agents read (agy and Antigravity's app both read `~/.gemini/config/GEMINI.md`) is written for the one of them switched on (`instrOwner`): the one switched off neither empties it nor shows it as edited (vizmoe42 on X, `TestAntigravitySharedInstructionsFile`). | [`instructions.go`](../../internal/library/instructions.go) | | MCP servers | A `Server` is a command or a URL (`http`, `sse`). `mcpFile` encodes it in each agent's own format (one `mcpFormat` per agent family) and merges it with the user's own fields for that entry. A server's `StartupTimeout` (#3168) goes to Codex alone, as `startup_timeout_sec` in seconds (`RawMcpServerConfig` in codex-rs/config's mcp_types.rs; 0 leaves Codex's own 30s), in the user-wide config.toml and a project's alike. magpie keeps the value it wrote (`Applied.Startup`, `Project.Startup`): one in the entry other than that, or a `startup_timeout_ms`, is the user's and stays as it is (`startupTheirs`), and once it is taken out magpie's goes in again. The editor shows the field only when an agent that takes it is here (`AgentView.Startup`, `mcp_startup_test.go`, `mcp-startup-timeout.test.cjs`). `Also` files get the same servers; `Extra` files are only read when importing. `CheckServers` connects as an agent would and keeps the result in memory only: with each tool's name and the first paragraph of its description (`ToolList`, at most `maxToolList`, a description cut at `maxToolDesc` runes), which the page lists when the server's "N tools" is clicked, following tools/list's `nextCursor` up to `maxToolPages` pages (`listTools`). Each step (initialize, notifications/initialized, tools/list; connect for SSE) has its own budget, 60s for a URL and 30s for a command (`remoteStep`, `stdioStep`), and a timeout names its `Step` and how long it `Waited`; a timeout isn't kept, so the next look asks again (#1467). A command named bare that magpie's PATH lacks is started from where `proc.FindTool` finds it (fnm's Nodes on Windows among the folders), with that folder on the check's PATH, since npx's package runs the node beside it by name (`stdioProgram`, #2685, `TestStdioProgramFindsWhatPathLacks`). The page asks once a session for the servers some agent or project has (`inUse` in plugins/library/client.js); one no agent has shows "not checked" and is checked only when its status is clicked (#1597, `library-mcp-health.test.cjs`). A server checked once is checked again when it changes, its sign-in included, so a server signed in to after a click's "needs sign-in" isn't left showing both (新v学员 on Discord, `mcp-signin-health.test.cjs`). The check sends magpie's sign-in as the gateway does: on a 401 it renews the token once and asks again, and a server that refuses even the renewed token has the sign-in marked run out (`mcpauth.Rejected`, also from the gateway's `/mcp/`), which `ServerHealth.SignIn` carries back so the row's tag says "Sign-in ran out" rather than "Signed in" beside "needs sign-in". A server that refuses the check (401 or 403) but that an agent signed in to on its own is named so (`ServerHealth.AgentSignIn`, `readOwnSignIns` in `mcp_agent_signin.go`): each Claude Code target's `.credentials.json` beside its settings.json, a WSL distro's under the distro's home, is read for a `mcpOAuth` entry of the server's name and URL with a token, and each Codex target's `.credentials.json` beside its config.toml for a flattened entry of them, the file codex-rs falls back to when its config's `mcp_oauth_credentials_store` is `file` or the keyring is missing, whose executor's own entries are no `codex mcp login` (#3508); and the row says "signed in in Claude Code (Ubuntu)" — or Codex — instead of "needs sign-in" (CyberCaius on Discord: signed in to with Claude Code's /mcp in WSL). The tokens are never sent or kept; a file that can't be read or parsed names nobody, a stopped distro isn't started for it, and on a Mac only the file is read, never the Keychain Claude Code keeps them in nor Codex's keyring store. They are part of the check's key, so a sign-in in the agent since is checked anew (`TestCheckNamesAgentsSignedInThemselves`, `library-mcp-health-wsl.test.cjs`). A server that needs OAuth is signed in once in magpie, and agents reach it through the gateway's `/mcp/` (#615). The editor's Sign in saves the form first only when the sign-in is to another server than the saved one (a new server, a name or URL changed), and its button then reads "Save and sign in"; anything else edited (headers, env, arguments) stays unsaved until Save, so Cancel leaves the server as it was (新v学员 on Discord, `mcp-editor-cancel.test.cjs`). A server whose authorization server refuses magpie's dynamic client registration with 401 or 403 admits only the clients it lists (Figma's, #1619): the sign-in fails with `mcpauth.ErrClientRefused`, which says so and that each agent signs in itself, and the agents keep the server's own address. A server whose authorization server has no registration endpoint at all (GitHub's remote server, 新v学员 on Discord) fails with `mcpauth.ErrNoRegistration`, which says to make an OAuth app with the vendor and give it in the editor; the editor then opens its "OAuth app" fields. The app is the server's `oauth` (`OAuthApp`: `clientId`, `clientSecret`, `callbackPort`, Claude Code's names for `--client-id`, `--client-secret` and `--callback-port`), checked on save (HTTP only, a client ID, a port from 1 to 65535), and `SignInServer` signs in as it through `mcpauth.StartWith` without registering. The callback is Claude Code's, `http://localhost:/callback` (its docs' "Use pre-configured OAuth credentials"; 2.1.296 builds it so), listened for on 127.0.0.1 alone as Claude Code does, so an app made for Claude Code signs magpie in as it is; a server that matches the registered URL exactly refuses another host, which is why Claude Code's 2.1.231 went back to `localhost` from 2.1.229's `127.0.0.1` (`TestAppMadeForClaudeCode`). Without a `callbackPort` the port is any free one, which a loopback callback registered without a port takes (GitHub's, RFC 8252); a fixed `callbackPort` is for a vendor that matches the port too. magpie's own registration, when a server has one, still names `127.0.0.1`. The client secret is kept in library.json, as a header's or env's value is: a backup without keys leaves it out, and `WithSecrets` puts back this computer's secret only for the same client ID; no agent is given the app, and the TUI's editor, which doesn't show it, keeps it. GitHub answers a token request's error with a 200 and `error` in the body (`bad_refresh_token`, `incorrect_client_credentials`), which `tokenRequest` reads as the error it is, and a dead refresh token marks the sign-in run out (`github_app_test.go`, `mcp-oauth-app.test.cjs`). magpie never registers under another client's name; one that reaches the gateway from another machine (a WSL distro under NAT) is given it with the LAN sharing key as its `Authorization` (`agent.KeyAt`), as its models are, which the gateway takes in place of a sign-in and never passes on; turning sharing on or off, or a new key (`access.LANChanged`), writes such entries again. `ConfigOfServers` is the servers picked as an agent's project file (`projectMCPFiles`) would hold them, written by the same code into a folder of its own and read back, with those the agent can't take there named; the page's Copy config… puts it on the clipboard for a project magpie doesn't keep (#1478). The editor's command is a box that wraps, so a long line is read whole, and Enter still saves it (hema_17384 on Discord). Its Form | JSON switch shows the server as JSON in Claude Code's `.mcp.json` shape, the one Copy config… gives for it (`jsonOf` in plugins/library/client.js), with `${NAME}` references as written. An edit there is read as a paste is (`serversIn`) and becomes the form's at once. JSON that isn't one server's keeps the dialog from saving or going back to the form, and counts as unsaved. The note, the agents and sync stay in the form (`library-mcp-json.test.cjs`). A server's and a skill's `Note` (youyo.p_10001 on Discord) is the user's own word on what it is for: one line of at most `maxNote` (200) characters, whitespace run together (`checkNote`), as a hook's description is. The row shows it in place of the command or description, and its tooltip still gives that line. The skills' filter reads it too. A sync carries it (a server whole, a skill as `CarriedSkill.Note`), and no agent is given it, through the MCP router or not (`TestNoteNeverGiven`, `TestNoteCarried`). A skill's is set by itself (`SkillNote`, `skills/note`) from the skill's reader. Each listed tool has a switch: the tools turned off are the server's `DisabledTools`, set by `ServerTools`, and written into each agent given the server that can leave out a single tool (see the constraint below). A server run as `npx -y args` (a registry package, no other npx flag) is given to an agent on this machine as `node args` (`npxDirect`): magpie installs the package with npm into a folder of its own under `mcp-npm` in the background, the next sync writes the node form, and until then, or when npm fails (tried again after an hour), the agent keeps npx. npx otherwise stays as the server's parent for its whole life, a node and two cmd.exe beside each instance on Windows (#3885). An unpinned spec is installed again after a day, as npx would fetch the newer one; an install no library server runs goes a day after its last. The library, a server's check, Copy config… and agents in WSL keep npx (`TestNpxServerRunsByNode`, `TestReadNpx`). A remote server holds several accounts (Elorynth on X), one in use that every agent is given: sets of headers are `Server.Accounts` with `Server.Account` the one in use ("" is the server's own `Headers`), laid over `Headers` by `live` in `through`, `remoteHeaders` and `hubKey`, so a switch rewrites each agent's file (`TestServerAccountsSwitchEveryAgent`); a save from the editor, which doesn't send them, keeps them, and a backup carries no account's key (`TestServerAccountKeysAreSecrets`). magpie's OAuth sign-ins are `mcpauth` records, the one in use at `m[name]` and the others in `Spare` (`Use`, `RemoveAccount`, `StartAccount`), which the gateway's `/mcp/` sends from its next request on; an agent's existing upstream `Mcp-Session-Id` isn't reset by a switch. API `/api/library/mcp-account`; GUI `headerAccounts` and `acctList` (`mcp-accounts.test.cjs`). | [`mcp.go`](../../internal/library/mcp.go), [`mcp_npx.go`](../../internal/library/mcp_npx.go), [`mcp_check.go`](../../internal/library/mcp_check.go), [`mcp_signin.go`](../../internal/library/mcp_signin.go), [`mcp_agent_signin.go`](../../internal/library/mcp_agent_signin.go), [`mcp_copy.go`](../../internal/library/mcp_copy.go), [`mcp_tools_off.go`](../../internal/library/mcp_tools_off.go) | | MCP server on/off | `ServerOn` (`POST /api/library/servers/on` with `name` and `on`, `magpie library mcp off|on `) turns a server off for everyone without removing it (swang20201 on X, Docker gateway mode, where a server ticked for no agent is still given to every app at the MCP router's address). Off, it is `Hidden` with its agents kept in `Paused` and `Agents` empty, as a plugin's server hidden from agents is (`PluginServerOn`, [Plugin tools](plugin-tools.md)): no agent's file has it, no project's (`syncProjectMCP` skips it, keeping the project's own agents for it), no subagent names it (`renderSubagent`), the router lists and calls it for nobody, and a process the router held for it ends, since `Hidden` and `Paused` are part of its `hubKey`. Its command, URL, env, headers, sign-in, `DisabledTools` and note stay in library.json. On, the agents in `Paused` get it back (none when it had none, so the router gives it to other apps again), as before it was turned off; giving it agents (`ServerAgents`, the CLI's `mcp agents`) turns it on with those (`save`), while Turn all on (`EveryServerAgents` with every agent) leaves it off. The row's switch sits after its agent chips (`serverSwitch` in plugins/library/client.js); off, the row is dimmed, its chips take no click, and it is health-checked only on a click (`TestServerOnKeepsAndRestores`, `TestLibraryMCPOffOn`, `library-mcp-on.test.cjs`). The servers off are listed apart, below the ones on, under a Servers turned off (N) fold drawn as Providers' Turned off one (`.fold` in an `.off-head`), folded at first and remembered in localStorage (`magpie.offServersOpen`); while picking (Select) it is held open, so every server picked is in sight (hzlxb on X, `library-mcp-off-fold.test.cjs`). | [`mcp_on.go`](../../internal/library/mcp_on.go), [`project_mcp.go`](../../internal/library/project_mcp.go), [`subagents.go`](../../internal/library/subagents.go) | | MCP router | With `MCPHub` on, `syncMCP` gives each agent that can take it one entry, `magpie`, at the gateway's `/mcp/magpie/hub/`, in place of the servers ticked for it; magpie runs those servers itself, once for every agent. | [MCP router](mcp-router.md), [`mcp_hub.go`](../../internal/library/mcp_hub.go) | diff --git a/internal/library/antigravity_test.go b/internal/library/antigravity_test.go index 0df2a0c1e..435e16653 100644 --- a/internal/library/antigravity_test.go +++ b/internal/library/antigravity_test.go @@ -154,3 +154,57 @@ func TestAntigravityAppTarget(t *testing.T) { t.Errorf("project skills: %q", ProjectSkillsDir("antigravity")) } } + +// vizmoe42 on X: agy switched on in Instructions, and no GEMINI.md in +// ~/.gemini/config. The Antigravity app, here too and switched off, reads +// the same file, and its write took agy's part out again at once. One +// switched on keeps the file it shares with one switched off, whichever +// comes first; the one off doesn't call the part "edited"; and a file the +// old write left empty is written again by the next sync, the switch left +// as it was. +func TestAntigravitySharedInstructionsFile(t *testing.T) { + for _, on := range []string{"agy", "antigravity"} { + t.Run(on, func(t *testing.T) { + h, cfg := antigravity(t) + write(t, filepath.Join(h, ".gemini/antigravity/agyhub_summaries_proto.pb"), "x") + p := filepath.Join(cfg, "GEMINI.md") + for _, id := range []string{"agy", "antigravity"} { + if tg := targetByID(id); tg == nil || tg.Instructions != p { + t.Fatalf("%s: %+v", id, tg) + } + } + want := blockBegin + "\nUse tabs.\n" + blockEnd + "\n" + shared := "Use tabs." + ok(t)(SaveInstructions(InstructionsChange{Shared: &shared, Agents: []string{on}})) + if s := read(t, p); s != want { + t.Fatalf("after the switch:\n%q", s) + } + ok(t)(Sync()) + if s := read(t, p); s != want { + t.Fatalf("after a sync:\n%q", s) + } + v, err := ReadInstructions() + if err != nil { + t.Fatal(err) + } + for _, a := range v.Agents { + if (a.Agent == "agy" || a.Agent == "antigravity") && (a.Edited || a.On != (a.Agent == on)) { + t.Errorf("row %+v", a) + } + } + + // as the old write left it: the part taken out, the file empty + write(t, p, "") + ok(t)(Sync()) + if s := read(t, p); s != want { + t.Fatalf("a sync didn't write the emptied file again:\n%q", s) + } + + // both off: the part goes + ok(t)(SaveInstructions(InstructionsChange{Agents: []string{}})) + if s := read(t, p); s != "" { + t.Errorf("both off:\n%q", s) + } + }) + } +} diff --git a/internal/library/instructions.go b/internal/library/instructions.go index 4ad63ba8c..4859914b2 100644 --- a/internal/library/instructions.go +++ b/internal/library/instructions.go @@ -208,8 +208,9 @@ func PublishMemory(due bool) (*Result, error) { if b == nil { b = newBackups() } - for _, t := range Targets() { - l.syncInstructions(t, b, res, true) + all := Targets() + for _, t := range all { + l.syncInstructions(t, all, b, res, true) } res.Backup = b.dir if b.dir != "" { @@ -332,8 +333,10 @@ func (l *Library) instructionsLost() bool { // them, and the parts out there are then the only copy left (#5709, where // a start-up apply with an empty Library wiped nine agents' files). It is // a write of the page — a take-back, made with the library as the user -// left it — that takes a part out. -func (l *Library) syncInstructions(t *Target, b *backups, res *Result, auto bool) { +// left it — that takes a part out. A file other agents in all read too is +// written for the one of them switched on (instrOwner), never emptied by +// another switched off. +func (l *Library) syncInstructions(t *Target, all []*Target, b *backups, res *Result, auto bool) { if res.unreached(t) { return } @@ -342,6 +345,14 @@ func (l *Library) syncInstructions(t *Target, b *backups, res *Result, auto bool } id := t.Agent.ID a := l.applied(id) + if o := l.instrOwner(t, all); o != "" && o != id { + // the file is the part of another agent that reads it, switched + // on: Antigravity's app, switched off, took agy's part out of + // ~/.gemini/config/GEMINI.md they both read, as soon as agy's + // was written (vizmoe42 on X) + a.Instructions, a.InstrHash = false, "" + return + } if slices.Contains(l.Instructions.Agents, id) { // a text that can't be read is unknown, not empty: writing what // is left would take the agent's part out or cut it down (#5709) @@ -443,6 +454,30 @@ func (l *Library) syncInstructions(t *Target, b *backups, res *Result, auto bool res.changed(id) } +// instrOwner is the agent whose part the file t's instructions are in +// holds when it is also the file of other agents in all: the first of +// them switched on, "" when none is. Antigravity's app and agy both read +// ~/.gemini/config/GEMINI.md; one switched off takes nothing out of the +// file the other is switched on for. +func (l *Library) instrOwner(t *Target, all []*Target) string { + p := filepath.Clean(t.Instructions) + for _, o := range all { + if o.Instructions != "" && o.Field == t.Field && filepath.Clean(o.Instructions) == p && slices.Contains(l.Instructions.Agents, o.Agent.ID) { + return o.Agent.ID + } + } + return "" +} + +// wantedIn is what the file t's instructions are in is to hold: the part +// of the agent switched on for it (instrOwner), else t's agent's own. +func (l *Library) wantedIn(t *Target, all []*Target) string { + if o := l.instrOwner(t, all); o != "" { + return l.wanted(o) + } + return l.wanted(t.Agent.ID) +} + // AgentInstructions is one agent's instructions file as the page shows it. type AgentInstructions struct { Agent string `json:"agent"` @@ -510,7 +545,7 @@ func (l *Library) instructionsView(targets []*Target, asleep []*agent.Agent) *In if o := own(file); o != "" { ai.Own = strings.Count(o, "\n") + 1 } - if _, have, _, ok := split(file); ok && have != l.wanted(id) && !l.isSetFile(t.Instructions) { + if _, have, _, ok := split(file); ok && have != l.wantedIn(t, targets) && !l.isSetFile(t.Instructions) { ai.Edited = true } if t.Override != "" && readText(t.Override) != "" { @@ -570,8 +605,9 @@ func changeInstructions(f func(l *Library) error) (*Result, error) { if b == nil { b = newBackups() } - for _, t := range Targets() { - l.syncInstructions(t, b, res, false) + all := Targets() + for _, t := range all { + l.syncInstructions(t, all, b, res, false) } res.Backup = b.dir if b.dir != "" { diff --git a/internal/library/sync.go b/internal/library/sync.go index 029c200f8..372ac5144 100644 --- a/internal/library/sync.go +++ b/internal/library/sync.go @@ -114,7 +114,7 @@ func syncSteps(all, gone []*Target, b *backups, res *Result) []func(*Library) { steps := []func(*Library){func(l *Library) { l.followMovedSkills() }} for _, t := range all { steps = append(steps, func(l *Library) { - l.syncInstructions(t, b, res, true) + l.syncInstructions(t, all, b, res, true) l.syncMCP(t, b, res) l.syncHooks(t, b, res) l.syncEnv(t, b, res)