library: sync and backup files carry the subagents

xixi_Sean_ on X asked why Sync leaves the Library's subagents out. There
was no reason: the library part of a bundle now carries them.

- library.Bundle.Subagents (*[]*Subagent): name, description, prompt,
  the skills and MCP servers named, the agents ticked. Collect always
  sets it, empty too. Applied.Subagents (which files magpie wrote here
  and their hashes) stays out: each computer writes the files into its
  own agents on the sync Put runs and records its own, so a file the
  user edited there, or one of theirs by the same name, stays theirs.
- Put replaces the subagents with the bundle's, so one taken out on one
  computer goes from the others. A nil list (a bundle from a magpie
  before this) is unknown and keeps this computer's.
- check refuses a subagent whose name isn't one (it is a file name in
  every agent) or comes twice; agent ids are carried as they come, so a
  newer magpie's tick for an agent this one can't give subagents to
  stays and writes nothing here.
- davsync: an empty list hashes as before the field, so upgrading with
  no subagents syncs nothing.
- backup files go through the same Collect/Put; the CLI's backup line
  counts subagents. The GUI's sync/export/import ticks say "instructions,
  MCP servers, skills and subagents" in every language.
- webdav-settings-refresh's "Agents" tick locator also matched the
  library tick's "subagents": it now asks for "Agents' models".
- library.md and sync-backup.md updated. Hooks still aren't carried.

Run (rebased on 0bf5adb11; Go runs at e0c57ffe2, same diff):
- mote: go test -tags nogui ./internal/backup ./internal/davsync
  ./internal/cli ok; ./internal/library -run 'TestCarry|TestSubagent|
  TestLocalServer|TestPutKeeps|TestPutSame|TestRestoreKeeps' ok
- wsl-run (Linux): ./internal/library ./internal/backup ./internal/davsync
  whole packages ok
- win-run (Windows): the same three, -run 'Subagent|TestCarry|TestLibrary|
  TestSyncLibrary' ok
- go vet -tags nogui for darwin, GOOS=linux and GOOS=windows on the four
  packages ok; gofmt -l clean
- GUI (wsl-run, Chromium + WebKit, every language): i18n-keys,
  github-sync, s3-sync, sync-auto-restore, sync-not-backup,
  sync-other-kind, sync-sign-in, sync-spin, sync-usage-error,
  webdav-settings-refresh, library-backups-top, gui-de, gui-ja,
  gui-zh-tw, settings-search, settings-sections: 170/173, then
  webdav-settings-refresh green after the locator fix. The one red left,
  i18n-keys "a plugin's words are its own" ("Unmarked" in
  plugins/routing/i18n.js), is on main already: #4524.
  mote ran five other GUI suites at load 18, where every WebKit
  github-sync case timed out at launch, so the GUI run moved to Linux.

Broken by hand: with Collect not setting Subagents and Put ignoring
them, TestCarrySubagents, TestCarrySubagentKeepsUsersFiles,
TestCarryNewerSubagents, TestBackupFileCarriesSubagents,
TestSyncSubagents and TestNoSubagentsHashAsBefore went red; with Put
treating a missing list as empty, TestCarryOldBundleKeepsSubagents and
TestBackupFileCarriesSubagents went red.

Not tried: a real WebDAV/S3/GitHub remote between two real computers;
the fake DAV server carries it between two sandbox HOMEs.
This commit is contained in:
yetone
2026-10-31 13:14:16 +08:00
parent 59546b3fdb
commit 07a3312c53
11 changed files with 414 additions and 24 deletions
+4 -4
View File
@@ -65,7 +65,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
- magpie's own MCP server (`magpie-image`, and any `mcp …` run by a program named magpie) runs this computer's magpie (#1439). `InstallServer` gives it magpie by full path (`update.Program`: the AppImage, not its mount; Homebrew's opt link, not the Cellar), and that path is right only on this computer. When the library is read, and after every change, `heal` points such a server whose program isn't on this computer (another system's path, a magpie moved out of Downloads, a bare `magpie`) at this magpie, so the agents and `CheckServers` get it; a magpie program that is here (another build) and a server run by any other program stay as they are. A carried library (`Collect`, for a backup or a WebDAV or S3 sync) names it as plain `magpie`, so two computers carry the same bundle and a sync doesn't write one's path over the other's; `Put` then reads it as that computer's magpie. [`self_here.go`](../../internal/library/self_here.go)
- A carried library (`Collect`) has every file of each skill, its templates and other binaries included, up to `maxCarried` (16 MiB) a file and `maxCarriedAll` (32 MiB) in all, chosen smallest first across the skills (`readSkills`), so every skill's text goes before any big file. The total keeps a sealed backup under the 64 MiB a sync reads: the files are base64 twice in it. What is left out is named in `Left`, and `Put` keeps this computer's copy of such a file in the skill it puts (`keepLeft`). [`carry.go`](../../internal/library/carry.go)
- A skill can be turned off on this computer alone (`OffHere`, `SkillHere`; the row's power button, `magpie library skill off-here <name>` and `on-here`; hanslin1666 on Discord). No agent here gets it, whatever its `Agents` say (`gives`, which every reader of `Agents` for giving goes through: `syncSkills`, `desktop_skills.go`, `skill_changed.go`, `skill_edits.go`, `behind`, `Targets`). `Agents` stays what a sync carries, and the page leaves its chips as they are, faded. `Collect` never carries `OffHere`, so turning it off changes no part a sync uploads, and `Put` keeps this computer's `OffHere` for a skill it puts, so a sync from a computer that has it on, or gives it to more agents, never turns it on here. A library.json from before has no `offHere` and every skill stays on. Not covered: a project's skills; a library skill kept in `~/.agents/skills`, which agents read in place, until it is handed over (below); and a skill another computer removes, which takes the flag with it. [`skills.go`](../../internal/library/skills.go), [`carry.go`](../../internal/library/carry.go)
- An MCP server can be kept to this computer (`Server.Local`; the editor's "This computer only" switch, `magpie library mcp add --local`, `magpie library mcp local <name> on|off`; huhuy72219405 on X). `Collect` never carries it (`carriedServers`), so a sync or a backup file never takes it to another computer, and turning a shared server local takes it out of what is carried: the other computers drop it at their next sync. `Put` (sync, join, Restore, Undo, a backup file) keeps every local server here, with its agents, and clears `Local` on what comes in (`putServers`). Another computer's server by the name of a local one doesn't take its place: it goes to `Library.Away`, given to no agent, not in the router, not checked, and carried on as it came, so a push from here never takes it from the computers that have it. `settleAway` runs on every change: while the name is local here the away copy stays; once no server of that name is left here (removed or renamed) it comes in as a sync would bring it; once a shared server has the name (local turned off) this computer's is the one carried. The router serves local servers like any other, since it runs on this computer. Subagents aren't carried, so one that names a local server keeps it here. The TUI keeps the flag on edit and marks the row. (`TestLocalServerNotCarried`, `TestPutKeepsLocalServer`, `TestPutSameNameAsLocal`, `TestRestoreKeepsLocalServer`, `TestLocalServerThroughSync`, `mcp-local-server.test.cjs`) [`mcp_local.go`](../../internal/library/mcp_local.go), [`carry.go`](../../internal/library/carry.go)
- An MCP server can be kept to this computer (`Server.Local`; the editor's "This computer only" switch, `magpie library mcp add --local`, `magpie library mcp local <name> on|off`; huhuy72219405 on X). `Collect` never carries it (`carriedServers`), so a sync or a backup file never takes it to another computer, and turning a shared server local takes it out of what is carried: the other computers drop it at their next sync. `Put` (sync, join, Restore, Undo, a backup file) keeps every local server here, with its agents, and clears `Local` on what comes in (`putServers`). Another computer's server by the name of a local one doesn't take its place: it goes to `Library.Away`, given to no agent, not in the router, not checked, and carried on as it came, so a push from here never takes it from the computers that have it. `settleAway` runs on every change: while the name is local here the away copy stays; once no server of that name is left here (removed or renamed) it comes in as a sync would bring it; once a shared server has the name (local turned off) this computer's is the one carried. The router serves local servers like any other, since it runs on this computer. A carried subagent names its servers, a local one too; a computer without that server leaves it out of the agents' files, as any server the library hasn't. The TUI keeps the flag on edit and marks the row. (`TestLocalServerNotCarried`, `TestPutKeepsLocalServer`, `TestPutSameNameAsLocal`, `TestRestoreKeepsLocalServer`, `TestLocalServerThroughSync`, `mcp-local-server.test.cjs`) [`mcp_local.go`](../../internal/library/mcp_local.go), [`carry.go`](../../internal/library/carry.go)
- A skill kept in `~/.agents/skills` is handed over to the library on the user's click (`HandOverSkills`, `POST /api/library/skills/hand-over` with `names`; the row's Manage in magpie in its source line, Manage {n} in magpie in the skills' heading, each asking first; `magpie library skill hand-over <name…>|--all`; tnt1223 on Discord). "Kept there" is `sharedEntry`: the entry in that folder that is the library skill's own folder, by its name or, for a library link into it under another folder's name, by that folder's (`SkillView.Shared`; `SharedElsewhere` when the entry only links to a folder kept elsewhere). Every reader of `sharedHas`/`sharedEntry` follows: `Always`, `syncSkills`' `inShared`, and the shared folder's own target (Goose, Kimi Code, Cindy), which is given no second link beside such an entry (`TestSharedUnderAnotherName`). Handed over, a folder in `~/.agents/skills` moves into the library's skills folder (`moveIn`: renamed, or copied, read back the same with `sameTree` and only then set aside with the backups; a failure leaves it where it was and the library's link as it was, `TestHandOverFailureKeepsOriginal`), and an entry that only links elsewhere is taken away while the library links past it to that folder. The user's own links to it in agents' folders, which would point at nothing, go too. Every agent here that read it (`readsSharedHere`, and the agent of each such link) is ticked, so each keeps it, now from the library, till it is unticked or turned off here. A skill found there and not in the library yet is brought in first. One that can't be handed over is left as it was, in `Result.Unmoved`, and the others are handed over all the same. `HandBackSkill` (`magpie library skill hand-back <name>`, CLI only; the sheet names it) moves the folder back and links the library to it, its ticks as they are. Not covered: another computer whose skill is still in its own `~/.agents/skills` gets the library's copy from a sync beside its own, until it is handed over there too; and the skills CLI's lock (`npx skills update`) may put the entry back (`TestHandOverSharedFolder`, `TestHandOverSharedLink`, `TestHandOverFound`, `TestHandOverWithGoose`, `TestLibrarySkillHandOver`, `skill-handover.test.cjs`). [`skill_handover.go`](../../internal/library/skill_handover.go)
- WorkBuddy's servers go in `$WORKBUDDY_CONFIG_DIR/mcp.json` (default `~/.workbuddy`; WorkBuddy AI, the international build, keeps its own in `~/.workbuddy-ai`, #1494), and CodeBuddy Code's go in the first of `.mcp.json`, `mcp.json` and `~/.codebuddy.json` that exists, as `resolveMcpFilePath` reads them (#1266). WorkBuddy connects a server only after the user has switched it on once in its own MCP settings. It keeps that approval in `mcp-approvals.json`, keyed by the command, args and env names or the URL's origin, so changing those asks again. magpie never writes the approval, and the servers page says so, by the build's name, when a server is given to WorkBuddy or WorkBuddy AI.
- Alma's servers go in `~/.config/alma/mcp.json` on every system (its home, not its data folder), as its own MCP settings write them: `command`/`args`/`env`, or `url`/`headers` with `transport: "sse"` only for SSE (#1292). Alma reads the file as it starts and when its MCP settings refresh, so a server given to it while it runs reaches it after one of those.
@@ -75,7 +75,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
- Removing RTK never uses `rtk init --uninstall`. That command deletes Gemini's `GEMINI.md` whole and removes Claude Code, OpenCode and Cursor together.
- A hook is recorded entry by entry, as written (`Applied.Hooks`, compared as canonical JSON). magpie takes out only an entry still exactly as it wrote it; one the user edited is theirs from then on, and the user's own hooks beside it stay. A hooks file that doesn't parse is a problem and is never written. Codex keeps each hook's trust in config.toml as `[hooks.state."<path>:<event>:<group>:<handler>"]`, keyed by position, so when magpie takes a group out `codexRekey` moves the user's trust for the groups after it to their new place.
- A carried library (backup, WebDAV, S3, profile bundles) doesn't carry hooks yet.
- A subagent file is recorded by the hash of what magpie wrote (`Applied.Subagents`). magpie writes over or takes away only a file still exactly as it wrote it; one the user edited is theirs from then on, and the page says so. A file of the user's own by the same name is never written over: the agent gets a problem instead. A file of magpie's the user deleted is written again on the next sync. Cursor's `~/.cursor/agents` is read by the Cursor app only; the cursor-agent CLI reads only a project's `.cursor/agents`. An agent in a WSL distro gets no subagents, nor do agents with no user-level subagent folder (Kimi, Goose, Crush, Qoder, CodeBuddy, iFlow, Kiro). A carried library doesn't carry subagents yet.
- A subagent file is recorded by the hash of what magpie wrote (`Applied.Subagents`). magpie writes over or takes away only a file still exactly as it wrote it; one the user edited is theirs from then on, and the page says so. A file of the user's own by the same name is never written over: the agent gets a problem instead. A file of magpie's the user deleted is written again on the next sync. Cursor's `~/.cursor/agents` is read by the Cursor app only; the cursor-agent CLI reads only a project's `.cursor/agents`. An agent in a WSL distro gets no subagents, nor do agents with no user-level subagent folder (Kimi, Goose, Crush, Qoder, CodeBuddy, iFlow, Kiro). A carried library carries the subagents (`Bundle.Subagents`: name, description, prompt, skills and servers named, agents ticked; xixi_Sean_ on X), never `Applied.Subagents`: each computer writes them into its own agents at the sync `Put` runs and records its own files, so a file the user edited there, or one of theirs by the name, stays theirs as above. `Put` replaces the subagents with the bundle's, so one taken out on one computer goes from the others; a bundle without the field, from a magpie before it, is unknown and keeps the ones here (nil, where Collect always carries a list). Agent ids are carried as they come, one a newer magpie gives subagents to included; a name that isn't one refuses the bundle. An empty list hashes as before the field, so a computer with none sees no change to sync (`TestCarrySubagents`, `TestCarryOldBundleKeepsSubagents`, `TestCarrySubagentKeepsUsersFiles`, `TestCarryNewerSubagents`, `TestBackupFileCarriesSubagents`, `TestSyncSubagents`, `TestNoSubagentsHashAsBefore`). Hooks aren't carried.
- CC Switch's own skills folder is only ever read.
- Reading the page never waits on reading skills through (#541). `Read` compares an agent's own skill with the same name in another agent (`sameTree`) and hashes each library skill given as a copy (`hashFiles`, for `behind`). Both are kept against a stamp of the folders (each file's and link's path, type, size and mtime, `stamper` in [`treememo.go`](../../internal/library/treememo.go)), taken by the same walk that compares or hashes them, before a file is opened; a later read walks the folder without opening a file, and while the stamps match reuses the answer. Only an answer from a whole read of folders untouched for `settleFor` (3s) is kept: a folder that couldn't be walked or read, or was written a moment ago, is read again next time, never taken as unchanged. A rewrite that keeps a file's size and mtime isn't seen. `Glance` (`GET /api/library?glance=1`) is the page without those two, marked `partial`; the page draws it first, then the whole read, which runs `behind` and `foundSkills` after the library's lock is let go, so a change doesn't wait on them either.
- A read of the page (`Read`, `Glance`) follows the links on the way to a few hundred paths, most of them many times over: each agent's skills folder for each skill, CC Switch's and the shared folder for each source. While the read holds the lock, `resolve` looks at each entry on the way once (`lookPart` in [`linkmemo.go`](../../internal/library/linkmemo.go)): one `Lstat`, and a `Readlink` for a link. Nothing is kept past the read, so a link made or moved on disk between two visits shows on the second. An entry that couldn't be looked at for another reason than its not being there is unknown and looked at again. One read had taken ~10,000 looks; on oxyuan's Windows machine that was ~1.3s a visit (#1771).
@@ -86,9 +86,9 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
```sh
go test -tags nogui ./internal/library -run 'TestGit|TestInstallFromGitRepo|TestReadLooksAtEachFolderOnce|TestLinkChangedBetweenVisitsShows|TestUnreadablePartIsLookedAtAgain|TestCheckSkillsFindsNewOnes|TestNewBase|TestUpdateKeeps|TestCheckDue|TestCheckSkillsMarksItDone|TestTargets|TestWSLPiMCP|TestWSLMCPSiblings|TestServer|TestHub|TestImportServer|TestCheck|TestInstructions|TestInstructionsSetLinkedToAgentsFile|TestInstructionSets|TestTakesAlma|TestAlma|TestLinkedSet|TestLinkRefused|TestSkill|TestRemoveFoundSkill|TestInstallSet|TestInstallLists|TestEverySkillAgents|TestEveryServerAgents|TestSomeServersAgents|TestRemoveServers|TestRTK|TestEnvRefs|TestDshRefRoundTrip|TestDshImportKeepsJS|TestAgentMCPFiles|TestCodeBuddyMCPFile|TestZedMCP|TestOwnServerFromElsewhereRunsThisMagpie|TestUsersOwnServerStaysAsItIs|TestCarriedOwnServerIsEachComputersMagpie|TestCarry|TestPageReadDoesntReadUnchangedSkillsAgain|TestJustWrittenSkillIsReadAgain|TestUnreadableSkillIsntRememberedAsDifferent|TestGlanceLeavesOutTheAgentsSkills|TestPluginAgent|TestPluginMCPFormatsAreWritten|TestToolsOff|TestOffList|TestHooks|TestSubagent|TestCheckRenewsMagpiesSignIn|TestCheckWSLOnlyServerInItsDistro|TestCheckWindowsServerHere|TestCheckMixedServerEachSide|TestCheckSaysSignInRanOut|TestCheckNamesAgentsSignedInThemselves|TestSignInAsTheUsersOwnApp|TestOAuthAppChecked|TestOAuthAppSecretCarried|TestGoneAgentListedToTakeOut|TestUpdateFindsSkillsRemovedUpstream|TestGoneFromNeedsTheSourceRead'
go test -tags nogui ./internal/library -run 'TestSkillOffHere|TestLocalServerNotCarried|TestPutKeepsLocalServer|TestPutSameNameAsLocal'
go test -tags nogui ./internal/backup -run 'TestRestoreKeepsLocalServer'
go test -tags nogui ./internal/backup -run 'TestRestoreKeepsLocalServer|TestBackupFileCarriesSubagents'
go test -tags nogui ./internal/library -run 'TestHandOver|TestSharedUnderAnotherName|TestSharedAgentsSkills'
go test -tags nogui ./internal/davsync -run 'TestSkillOffHereThroughSync|TestLocalServerThroughSync'
go test -tags nogui ./internal/davsync -run 'TestSkillOffHereThroughSync|TestLocalServerThroughSync|TestSyncSubagents|TestNoSubagentsHashAsBefore'
go test -tags nogui ./internal/cli -run 'TestLibrarySkillRm|TestLibrarySkillHandOver'
go test -race ./internal/mcpauth
go test -tags nogui ./internal/library
+10
View File
@@ -196,6 +196,16 @@ given to no agent here and carried on unchanged, so neither computer's sync
removes or replaces the other's (`TestLocalServerThroughSync`, two computers
through the fake S3; `TestRestoreKeepsLocalServer` for a backup file).
The library part carries the library's subagents (`library.Bundle.Subagents`,
see [library](library.md)), by sync and backup file alike: the receiving
computer writes them into its agents when it puts the library, and records
what it wrote there itself, so `Applied` never travels and a file the user
edited stays theirs. A bundle from a magpie before subagents were carried
has no list and keeps this computer's; an empty list takes them out. A
library with none hashes as it did before, so upgrading syncs nothing
(`TestSyncSubagents`, `TestNoSubagentsHashAsBefore`,
`TestBackupFileCarriesSubagents`).
## Verification
```sh
+56
View File
@@ -0,0 +1,56 @@
package backup
import (
"testing"
"github.com/yetone/magpie/internal/library"
)
// A backup file carries the library's subagents, and restoring it on
// another computer puts them in its library; an older file, made before
// subagents were carried, leaves the ones there.
func TestBackupFileCarriesSubagents(t *testing.T) {
home(t)
if _, err := library.SaveSubagent("", library.Subagent{Name: "reviewer", Description: "Reviews a diff",
Prompt: "Report bugs only.", MCP: []string{"gh"}, Agents: []string{"claude"}}); err != nil {
t.Fatal(err)
}
b, err := Collect(false, "test")
if err != nil {
t.Fatal(err)
}
data, _ := Seal(b, "pw")
old := b
lib := *b.Library
lib.Subagents = nil // as a magpie before them sealed it
old.Library = &lib
older, _ := Seal(old, "pw")
home(t)
if _, err := library.SaveSubagent("", library.Subagent{Name: "mine", Description: "Mine", Prompt: "Mine.", Agents: []string{}}); err != nil {
t.Fatal(err)
}
got, _ := Open(older, "pw")
if _, err := Restore(got, All); err != nil {
t.Fatal(err)
}
have := func() []string {
l, _ := library.Collect()
var names []string
for _, s := range *l.Subagents {
names = append(names, s.Name)
}
return names
}
if n := have(); len(n) != 1 || n[0] != "mine" {
t.Fatalf("an older file changed the subagents: %v", n)
}
got, _ = Open(data, "pw")
if r, err := Restore(got, All); err != nil || !r.Library {
t.Fatalf("restore: %+v %v", r, err)
}
l, _ := library.Collect()
if s := *l.Subagents; len(s) != 1 || s[0].Name != "reviewer" || s[0].Prompt != "Report bugs only." || len(s[0].MCP) != 1 || s[0].Agents[0] != "claude" {
t.Fatalf("subagents restored: %+v", s)
}
}
+3
View File
@@ -65,6 +65,9 @@ func backupCmd(args []string) error {
green.Render("saved"), file, len(b.Providers), what, len(b.Profiles), len(b.Agents))
if l := b.Library; l != nil {
fmt.Printf("; library: %d MCP servers, %d skills", len(l.MCP), len(l.Skills))
if l.Subagents != nil && len(*l.Subagents) > 0 {
fmt.Printf(", %d subagents", len(*l.Subagents))
}
}
fmt.Println()
fmt.Println(muted.Render("Subscriptions are not in it: sign in to them on the other machine. Keep the passphrase: without it the file can't be opened."))
+7 -1
View File
@@ -811,12 +811,18 @@ func hashes(b backup.Bundle) map[string]string {
if b.Plugins != nil && len(*b.Plugins) > 0 { // as before them, without one
providers = append(providers, map[string][]plugin.Entry{"plugins": *b.Plugins})
}
lib := b.Library
if lib != nil && lib.Subagents != nil && len(*lib.Subagents) == 0 { // as before them, without one
c := *lib
c.Subagents = nil
lib = &c
}
return map[string]string{
"providers": h(providers),
"settings": settingsHash,
"profiles": h(orEmpty(b.Profiles)),
"agents": h(orEmpty(b.Agents)),
"library": h(b.Library),
"library": h(lib),
}
}
+85
View File
@@ -0,0 +1,85 @@
package davsync
import (
"context"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/backup"
"github.com/yetone/magpie/internal/library"
)
// A subagent made on one computer is written into the other's agents by
// its next sync, and taken out of them when the first takes it out.
func TestSyncSubagents(t *testing.T) {
fake := &fakeDAV{files: map[string][]byte{}, etags: map[string]string{}, dirs: map[string]bool{"/dav": true}}
srv := httptest.NewServer(fake)
defer srv.Close()
ctx := context.Background()
cfg := Config{URL: srv.URL + "/dav/", User: "me", Password: "pw", Passphrase: "correct horse", Keys: true, Agents: true}
now := func(t *testing.T) {
t.Helper()
if err := Now(ctx); err != nil {
t.Fatal(err)
}
if v := Status(); v.Error != "" {
t.Fatalf("sync: %+v", v)
}
}
a, b := newComputer(t), newComputer(t)
a.use(t)
os.MkdirAll(filepath.Join(string(a), ".claude"), 0o755)
if _, err := library.SaveSubagent("", library.Subagent{Name: "reviewer", Description: "Reviews a diff",
Prompt: "Report bugs only.", Agents: []string{"claude", "codex"}}); err != nil {
t.Fatal(err)
}
Configure(cfg)
now(t)
b.use(t)
os.MkdirAll(filepath.Join(string(b), ".claude"), 0o755)
Configure(cfg)
now(t)
files := []string{filepath.Join(string(b), ".claude", "agents", "reviewer.md"), filepath.Join(string(b), ".codex", "agents", "reviewer.toml")}
for _, f := range files {
if _, err := os.Stat(f); err != nil {
t.Fatalf("b's agents weren't given the subagent: %v", err)
}
}
puts := fake.puts
now(t)
if fake.puts != puts {
t.Fatalf("b pushed back the subagents it brought in (%d puts)", fake.puts-puts)
}
a.use(t)
if _, err := library.RemoveSubagents([]string{"reviewer"}); err != nil {
t.Fatal(err)
}
now(t)
b.use(t)
now(t)
for _, f := range files {
if _, err := os.Stat(f); !os.IsNotExist(err) {
t.Errorf("%s is still there after a took the subagent out: %v", f, err)
}
}
}
// A library with no subagents hashes as it did before they were carried,
// so a magpie that starts carrying them doesn't see a change to sync.
func TestNoSubagentsHashAsBefore(t *testing.T) {
none := []*library.Subagent{}
with := backup.Bundle{Library: &library.Bundle{MCP: []*library.Server{}, Skills: []*library.CarriedSkill{}, Subagents: &none}}
before := backup.Bundle{Library: &library.Bundle{MCP: []*library.Server{}, Skills: []*library.CarriedSkill{}}}
if hashes(with)["library"] != hashes(before)["library"] {
t.Error("an empty list of subagents changed the library's hash")
}
one := []*library.Subagent{{Name: "reviewer"}}
with.Library.Subagents = &one
if hashes(with)["library"] == hashes(before)["library"] {
t.Error("a subagent didn't change the library's hash")
}
}
+3 -3
View File
@@ -20458,7 +20458,7 @@ function davForm(v) {
const phrase = input("", v.passphraseSet ? saved : t("the same on every computer"), "password");
const [keysL, keys] = tick(t("Providers' API keys"), v.keys !== false);
const [agentsL, agents] = tick(t("Agents' models"), v.agents !== false);
const [libL, lib] = tick(t("Library: instructions, MCP servers and skills"), v.library !== false);
const [libL, lib] = tick(t("Library: instructions, MCP servers, skills and subagents"), v.library !== false);
// usage: off unless picked, each computer its own (#542)
const [useL, use] = tick(t("Usage: this computer's calls, for the Usage page on the others"), !!v.usage);
const what = el("div", "stack");
@@ -20535,7 +20535,7 @@ function exportForm() {
const p1 = input("", t("passphrase"), "password");
const p2 = input("", t("again"), "password");
const [keysL, keys] = tick(t("With the providers' API keys"), true);
const [libL, lib] = tick(t("With the library: instructions, MCP servers and skills"), true);
const [libL, lib] = tick(t("With the library: instructions, MCP servers, skills and subagents"), true);
const what = el("div", "stack");
what.append(keysL, libL);
ed.append(...field(t("Passphrase"), p1, t("Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.")),
@@ -20583,7 +20583,7 @@ function importForm() {
pf.append(name, pick, file);
const pass = input("", t("passphrase"), "password");
const [agentsL, agents] = tick(t("Set the agents' models too"), true);
const [libL, lib] = tick(t("Bring in the library too: instructions, MCP servers and skills"), true);
const [libL, lib] = tick(t("Bring in the library too: instructions, MCP servers, skills and subagents"), true);
const what = el("div", "stack");
what.append(agentsL, libL);
ed.append(...field(t("File"), pf), ...field(t("Passphrase"), pass), ...field("", what, t("Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.")));
+12 -12
View File
@@ -2663,7 +2663,7 @@ const I18N = {
"the same on every computer": "每台电脑上都一样",
"Providers' API keys": "供应商的 API Key",
"Agents' models": "各 agent 选的模型",
"Library: instructions, MCP servers and skills": "资源库:指令、MCP 服务器和技能",
"Library: instructions, MCP servers, skills and subagents": "资源库:指令、MCP 服务器、技能和子代理",
"Usage: this computer's calls, for the Usage page on the others": "用量:本机的请求,在其他电脑的用量页里显示",
"Usage goes as a file a day: times, tokens, models and costs, never what was said. Turn it on on each computer that shares its own.": "用量每天一个文件:时间、token、模型和费用,不含对话内容。每台要共享用量的电脑都需各自打开。",
"usage": "用量",
@@ -2676,13 +2676,13 @@ const I18N = {
"Pick a passphrase: the file is sealed with it": "请设置口令:文件会用它加密",
"passphrase": "口令", "again": "再输入一次",
"With the providers' API keys": "包含供应商的 API Key",
"With the library: instructions, MCP servers and skills": "包含资源库:指令、MCP 服务器和技能",
"With the library: instructions, MCP servers, skills and subagents": "包含资源库:指令、MCP 服务器、技能和子代理",
"Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.": "打开文件时需要。订阅账号不在其中,请在另一台电脑上各自登录。",
"The two passphrases differ": "两次输入的口令不一致",
"Saved to {path}": "已保存到 {path}",
"No file chosen": "未选择文件", "Choose…": "选择…", "File": "文件",
"Set the agents' models too": "同时设置各 agent 的模型",
"Bring in the library too: instructions, MCP servers and skills": "同时导入资源库:指令、MCP 服务器和技能",
"Bring in the library too: instructions, MCP servers, skills and subagents": "同时导入资源库:指令、MCP 服务器、技能和子代理",
"Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.": "同 id 的供应商会被替换;不带 Key 的保留本机已有的 Key。资源库将替换本机资源库,原内容保存在备份中。",
"Choose a file first": "请先选择文件",
"Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "供应商:新增 {added} 个,替换 {replaced} 个;Profile {profiles} 个;agent 设置改动 {agents} 项",
@@ -6884,7 +6884,7 @@ const I18N = {
"the same on every computer": "每臺電腦上都一樣",
"Providers' API keys": "供應商的 API Key",
"Agents' models": "各 agent 選的模型",
"Library: instructions, MCP servers and skills": "資源庫:指令、MCP 伺服器和技能",
"Library: instructions, MCP servers, skills and subagents": "資源庫:指令、MCP 伺服器、技能和子代理",
"Usage: this computer's calls, for the Usage page on the others": "用量:本機的請求,在其他電腦的用量頁裡顯示",
"Usage goes as a file a day: times, tokens, models and costs, never what was said. Turn it on on each computer that shares its own.": "用量每天一個檔案:時間、token、模型和費用,不含對話內容。每臺要共享用量的電腦都需各自開啟。",
"usage": "用量",
@@ -6905,7 +6905,7 @@ const I18N = {
"passphrase": "口令",
"again": "再輸入一次",
"With the providers' API keys": "包含供應商的 API Key",
"With the library: instructions, MCP servers and skills": "包含資源庫:指令、MCP 伺服器和技能",
"With the library: instructions, MCP servers, skills and subagents": "包含資源庫:指令、MCP 伺服器、技能和子代理",
"Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.": "開啟檔案時需要。訂閱帳號不在其中,請在另一臺電腦上各自登入。",
"The two passphrases differ": "兩次輸入的口令不一致",
"Saved to {path}": "已儲存到 {path}",
@@ -6913,7 +6913,7 @@ const I18N = {
"Choose…": "選擇…",
"File": "檔案",
"Set the agents' models too": "同時設定各 agent 的模型",
"Bring in the library too: instructions, MCP servers and skills": "同時匯入資源庫:指令、MCP 伺服器和技能",
"Bring in the library too: instructions, MCP servers, skills and subagents": "同時匯入資源庫:指令、MCP 伺服器、技能和子代理",
"Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.": "同 id 的供應商會被替換;不帶 Key 的保留本機已有的 Key。資源庫將替換本機資源庫,原內容儲存在備份中。",
"Choose a file first": "請先選擇檔案",
"Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "供應商:新增 {added} 個,替換 {replaced} 個;Profile {profiles} 個;agent 設定改動 {agents} 項",
@@ -11114,7 +11114,7 @@ const I18N = {
"the same on every computer": "すべてのコンピューターで共通",
"Providers' API keys": "プロバイダの APIキー",
"Agents' models": "エージェントのモデル",
"Library: instructions, MCP servers and skills": "ライブラリ:指示、MCP サーバー、スキル",
"Library: instructions, MCP servers, skills and subagents": "ライブラリ:指示、MCP サーバー、スキル、サブエージェント",
"Usage: this computer's calls, for the Usage page on the others": "使用量:このコンピューターの呼び出し(他のコンピューターの「使用量」ページ用)",
"Usage goes as a file a day: times, tokens, models and costs, never what was said. Turn it on on each computer that shares its own.": "使用量は1日1ファイルで送られます:時刻、トークン、モデル、費用のみで、会話内容は含みません。自分の使用量を共有する各コンピューターでオンにしてください。",
"usage": "使用量",
@@ -11135,7 +11135,7 @@ const I18N = {
"passphrase": "パスフレーズ",
"again": "もう一度",
"With the providers' API keys": "プロバイダの APIキーを含める",
"With the library: instructions, MCP servers and skills": "ライブラリを含める:指示、MCP サーバー、スキル",
"With the library: instructions, MCP servers, skills and subagents": "ライブラリを含める:指示、MCP サーバー、スキル、サブエージェント",
"Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.": "ファイルを開くときに必要です。サブスクリプションは含まれないため、別のコンピューターでサインインしてください。",
"The two passphrases differ": "2つのパスフレーズが一致しません",
"Saved to {path}": "{path} に保存しました",
@@ -11143,7 +11143,7 @@ const I18N = {
"Choose…": "選択…",
"File": "ファイル",
"Set the agents' models too": "エージェントのモデルも設定する",
"Bring in the library too: instructions, MCP servers and skills": "ライブラリも取り込む:指示、MCP サーバー、スキル",
"Bring in the library too: instructions, MCP servers, skills and subagents": "ライブラリも取り込む:指示、MCP サーバー、スキル、サブエージェント",
"Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.": "同じ ID のプロバイダは置き換えられます。キーなしで来たものはここにあるキーを保持します。ライブラリはここのものを置き換え、置き換えられたものはバックアップとともに保持されます。",
"Choose a file first": "先にファイルを選んでください",
"Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "プロバイダ:{added} 件追加、{replaced} 件置換。プロファイル {profiles} 件。エージェント設定 {agents} 件を変更",
@@ -15355,7 +15355,7 @@ const I18N = {
"the same on every computer": "auf jedem Computer gleich",
"Providers' API keys": "API-Schlüssel der Anbieter",
"Agents' models": "Modelle der Agenten",
"Library: instructions, MCP servers and skills": "Bibliothek: Anweisungen, MCP-Server und Skills",
"Library: instructions, MCP servers, skills and subagents": "Bibliothek: Anweisungen, MCP-Server, Skills und Subagenten",
"Usage: this computer's calls, for the Usage page on the others": "Nutzung: Aufrufe dieses Computers, für die Seite „Nutzung“ auf den anderen",
"Usage goes as a file a day: times, tokens, models and costs, never what was said. Turn it on on each computer that shares its own.": "Die Nutzung wird als eine Datei pro Tag übertragen: Zeiten, Token, Modelle und Kosten, nie die Inhalte. Auf jedem Computer einschalten, der seine eigene teilt.",
"usage": "Nutzung",
@@ -15376,7 +15376,7 @@ const I18N = {
"passphrase": "Passphrase",
"again": "wiederholen",
"With the providers' API keys": "Mit den API-Schlüsseln der Anbieter",
"With the library: instructions, MCP servers and skills": "Mit der Bibliothek: Anweisungen, MCP-Server und Skills",
"With the library: instructions, MCP servers, skills and subagents": "Mit der Bibliothek: Anweisungen, MCP-Server, Skills und Subagenten",
"Needed to open the file. Subscriptions aren't in it: sign in to them on the other computer.": "Wird zum Öffnen der Datei benötigt. Abos sind nicht enthalten: Melden Sie sich auf dem anderen Computer bei ihnen an.",
"The two passphrases differ": "Die beiden Passphrasen stimmen nicht überein",
"Saved to {path}": "Gespeichert unter {path}",
@@ -15384,7 +15384,7 @@ const I18N = {
"Choose…": "Auswählen…",
"File": "Datei",
"Set the agents' models too": "Auch die Modelle der Agenten setzen",
"Bring in the library too: instructions, MCP servers and skills": "Auch die Bibliothek importieren: Anweisungen, MCP-Server und Skills",
"Bring in the library too: instructions, MCP servers, skills and subagents": "Auch die Bibliothek importieren: Anweisungen, MCP-Server, Skills und Subagenten",
"Providers with the same id are replaced; one that came without a key keeps the key it has here. The library replaces the one here, which is kept with its backups.": "Anbieter mit gleicher ID werden ersetzt; einer ohne Schlüssel behält den hier vorhandenen Schlüssel. Die Bibliothek ersetzt die hiesige, die in den Backups erhalten bleibt.",
"Choose a file first": "Wählen Sie zuerst eine Datei",
"Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "Anbieter: {added} hinzugefügt, {replaced} ersetzt; {profiles} Profile; {agents} Agenteneinstellungen geändert",
@@ -126,7 +126,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await form.waitFor({ state: "visible" });
const tick = (word) => form.locator("label.tick", { hasText: word }).locator("input");
assert.equal(await tick("API Key").isChecked(), true);
assert.equal(await tick(zh ? "agent" : "Agents").isChecked(), false, "agents' models must be unticked, as the CLI left it");
assert.equal(await tick(zh ? "agent" : "Agents' models").isChecked(), false, "agents' models must be unticked, as the CLI left it");
assert.equal(await tick(zh ? "资源库" : "Library").isChecked(), false, "the library must be unticked, as the CLI left it");
await first.locator(".val button", { hasText: zh ? "关闭" : "Close" }).click();
await form.waitFor({ state: "detached" });
+47 -3
View File
@@ -17,8 +17,9 @@ import (
// Bundle is the library as a backup carries it to another computer: the
// instruction sets and the one on, what each agent gets besides, the MCP
// servers and the skills with their files. What magpie wrote into each
// agent (Applied) is this computer's own and stays out. It is made the
// servers, the skills with their files and the subagents. What magpie
// wrote into each agent (Applied, the subagents' files among it) is this
// computer's own and stays out. It is made the
// same way every time — no times, everything in order — so two computers
// with the same library carry the same bundle.
type Bundle struct {
@@ -28,6 +29,10 @@ type Bundle struct {
MCP []*Server `json:"mcp"`
Skills []*CarriedSkill `json:"skills"`
Icons map[string]string `json:"icons,omitempty"`
// Subagents are nil in a bundle from a magpie before they were
// carried, which knew nothing of this computer's: Put keeps them. Collect
// always sets it, empty too, so taking the last one out is carried.
Subagents *[]*Subagent `json:"subagents,omitempty"`
}
// CarriedSkill is a skill with its folder's files.
@@ -100,6 +105,14 @@ func Collect() (*Bundle, error) {
c.Name, c.Source, c.Agents = s.Name, s.Source, orNone(slices.Sorted(slices.Values(s.Agents)))
b.Skills = append(b.Skills, c)
}
subs := []*Subagent{}
for _, s := range sorted(l.Subagents, func(s *Subagent) string { return s.Name }) {
c := *s
c.Skills, c.MCP = slices.Sorted(slices.Values(s.Skills)), slices.Sorted(slices.Values(s.MCP))
c.Agents = orNone(slices.Sorted(slices.Values(s.Agents)))
subs = append(subs, &c)
}
b.Subagents = &subs
return b, nil
}
@@ -229,6 +242,24 @@ func (b *Bundle) check() error {
}
}
}
if b.Subagents != nil {
seen := map[string]bool{}
for _, s := range *b.Subagents {
if s == nil {
return fmt.Errorf("an empty subagent")
}
// the name is the file's in every agent's folder; the agents
// are left as they come, as a skill's are: one a newer magpie
// gives subagents to is no target here and gets nothing
if !subagentNameRe.MatchString(s.Name) || slices.Contains(reservedSubagents, s.Name) {
return fmt.Errorf("the subagent name %q", s.Name)
}
if seen[s.Name] {
return fmt.Errorf("the subagent %s twice", s.Name)
}
seen[s.Name] = true
}
}
return nil
}
@@ -315,7 +346,9 @@ func filled(m, have map[string]string, secret func(string) bool) map[string]stri
// replaced or taken out is kept with the backups, and so is an
// instructions file that changes. A skill that comes linked to a folder
// this computer has too is linked to it; else it comes as its files. A
// skill whose files are as they are here is left alone.
// skill whose files are as they are here is left alone. The subagents
// replace the ones here too, unless b is from a magpie that didn't carry
// them.
func Put(b *Bundle) (*Result, error) {
if err := b.check(); err != nil {
return nil, err
@@ -453,6 +486,17 @@ func Put(b *Bundle) (*Result, error) {
l.putServers(b.MCP)
l.Icons = maps.Clone(b.Icons)
// the agents are written on the sync change runs: what magpie
// wrote here (Applied) decides, file by file, what is its own
if b.Subagents != nil {
subs := []*Subagent{}
for _, s := range *b.Subagents {
c := *s
c.Skills, c.MCP, c.Agents = slices.Clone(s.Skills), slices.Clone(s.MCP), slices.Clone(orNone(s.Agents))
subs = append(subs, &c)
}
l.Subagents = subs
}
return nil
})
}
+186
View File
@@ -0,0 +1,186 @@
package library
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
)
// carriedSubagent is a library with a server, a skill and a subagent that
// names both, given to Claude Code and Codex, as Collect carries it.
func carriedSubagent(t *testing.T) (string, string) {
t.Helper()
h := sandbox(t)
ok(t)(SaveServer("", Server{Name: "github", Transport: "stdio", Command: "npx", Agents: []string{"claude"}}))
skill(t, filepath.Join(h, "src/tdd"), "tdd", "Tests first")
ok(t)(InstallSkills(filepath.Join(h, "src"), []string{"tdd"}, []string{"claude"}))
s := reviewer
s.Agents = []string{"codex", "claude"}
ok(t)(SaveSubagent("", s))
if _, err := os.Stat(filepath.Join(h, ".claude/agents/reviewer.md")); err != nil {
t.Fatalf("not written on the first computer: %v", err)
}
b, err := Collect()
if err != nil {
t.Fatal(err)
}
return h, mustJSON(t, b)
}
func putJSON(t *testing.T, j string) *Result {
t.Helper()
var in Bundle
if err := json.Unmarshal([]byte(j), &in); err != nil {
t.Fatal(err)
}
r, err := Put(&in)
if err != nil {
t.Fatal(err)
}
return r
}
// A subagent goes with the library to another computer, which writes it
// into its agents; what magpie wrote into the first computer's agents
// stays out of the bundle; taking it out on one takes it out on the other.
func TestCarrySubagents(t *testing.T) {
_, carried := carriedSubagent(t)
var raw struct {
Subagents []map[string]any `json:"subagents"`
}
json.Unmarshal([]byte(carried), &raw)
if len(raw.Subagents) != 1 {
t.Fatalf("subagents carried: %s", carried)
}
got := raw.Subagents[0]
if got["name"] != "reviewer" || got["prompt"] == "" || got["description"] == "" ||
mustJSON(t, got["skills"]) != `["gone","tdd"]` || mustJSON(t, got["mcp"]) != `["github","gone"]` || mustJSON(t, got["agents"]) != `["claude","codex"]` {
t.Errorf("the subagent carried: %v", got)
}
// this computer's own: which files magpie wrote, and their hashes
if strings.Contains(carried, "applied") || strings.Contains(carried, "reviewer.md") || strings.Contains(carried, "reviewer.toml") || strings.Contains(carried, `"hash"`) {
t.Errorf("what magpie wrote here is carried:\n%s", carried)
}
h2 := sandbox(t)
r := putJSON(t, carried)
for _, p := range r.Problems {
if strings.HasPrefix(p.What, "subagent:") {
t.Errorf("a problem: %+v", p)
}
}
md := read(t, filepath.Join(h2, ".claude/agents/reviewer.md"))
if !strings.Contains(md, `skills: ["tdd"]`) || !strings.Contains(md, `mcpServers: ["github"]`) || !strings.Contains(md, "Report bugs only.") {
t.Errorf("claude's subagent on the second computer:\n%s", md)
}
if s := read(t, filepath.Join(h2, ".codex/agents/reviewer.toml")); !strings.Contains(s, "developer_instructions") {
t.Errorf("codex's subagent on the second computer:\n%s", s)
}
// the second computer records what it wrote itself, by its own paths
l, err := load()
if err != nil {
t.Fatal(err)
}
if fs := l.applied("claude").Subagents; len(fs) != 1 || !strings.HasPrefix(fs[0].Path, h2) {
t.Errorf("applied here: %+v", fs)
}
// carried back as it came; put again, nothing is written
back, _ := Collect()
if mustJSON(t, back) != carried {
t.Errorf("carried back differs:\n%s\n%s", mustJSON(t, back), carried)
}
if r := putJSON(t, carried); len(r.Changed) != 0 {
t.Errorf("putting the same again wrote %v", r.Changed)
}
// taken out on the first computer: the bundle says none, and the
// second computer's files go
var m map[string]json.RawMessage
json.Unmarshal([]byte(carried), &m)
m["subagents"] = json.RawMessage("[]")
none := mustJSON(t, m)
var in Bundle
json.Unmarshal([]byte(none), &in)
if in.Subagents == nil || len(*in.Subagents) != 0 {
t.Fatalf("an empty list read as none known: %s", none)
}
putJSON(t, none)
for _, p := range []string{".claude/agents/reviewer.md", ".codex/agents/reviewer.toml"} {
if _, err := os.Stat(filepath.Join(h2, p)); !os.IsNotExist(err) {
t.Errorf("%s is still there after the subagent went: %v", p, err)
}
}
if l, _ := load(); len(l.Subagents) != 0 {
t.Errorf("subagents left: %+v", l.Subagents)
}
}
// A bundle from a magpie that didn't carry subagents knows nothing of
// them: the ones here and their files stay.
func TestCarryOldBundleKeepsSubagents(t *testing.T) {
h, carried := carriedSubagent(t)
var m map[string]json.RawMessage
json.Unmarshal([]byte(carried), &m)
delete(m, "subagents")
old := mustJSON(t, m)
putJSON(t, old)
l, _ := load()
if len(l.Subagents) != 1 || l.Subagents[0].Name != "reviewer" {
t.Errorf("an old bundle took the subagents: %+v", l.Subagents)
}
if _, err := os.Stat(filepath.Join(h, ".claude/agents/reviewer.md")); err != nil {
t.Errorf("an old bundle took the file: %v", err)
}
}
// A file the user edited on the receiving computer stays theirs, and so
// does a file of their own by the subagent's name.
func TestCarrySubagentKeepsUsersFiles(t *testing.T) {
_, carried := carriedSubagent(t)
h2 := sandbox(t)
write(t, filepath.Join(h2, ".codex/agents/reviewer.toml"), "name = \"mine\"\n")
putJSON(t, carried)
if s := read(t, filepath.Join(h2, ".codex/agents/reviewer.toml")); s != "name = \"mine\"\n" {
t.Errorf("the user's own codex file was written over:\n%s", s)
}
md := filepath.Join(h2, ".claude/agents/reviewer.md")
write(t, md, read(t, md)+"\nMy own line.\n")
edited := read(t, md)
r := putJSON(t, strings.Replace(carried, "Report bugs only.", "Report every bug.", 1))
if read(t, md) != edited {
t.Errorf("the user's edit was written over:\n%s", read(t, md))
}
found := false
for _, p := range r.Problems {
found = found || p.Agent == "claude" && p.What == "subagent:reviewer"
}
if !found {
t.Errorf("no problem said for the edited file: %+v", r.Problems)
}
}
// A newer magpie's bundle: a field this one doesn't know, and an agent it
// can't give subagents to, which stays ticked to be carried on as it came.
// A name that isn't one is refused: it is a file's name in every agent.
func TestCarryNewerSubagents(t *testing.T) {
_, carried := carriedSubagent(t)
newer := strings.Replace(carried, `"agents":["claude","codex"]`, `"agents":["claude","codex","kimi"],"model":"fast"`, 1)
if newer == carried {
t.Fatal("no agents to change")
}
h2 := sandbox(t)
putJSON(t, newer)
if _, err := os.Stat(filepath.Join(h2, ".claude/agents/reviewer.md")); err != nil {
t.Errorf("not written: %v", err)
}
if l, _ := load(); len(l.Subagents) != 1 || !strings.Contains(strings.Join(l.Subagents[0].Agents, ","), "kimi") {
t.Errorf("the newer magpie's tick went: %+v", l.Subagents)
}
var in Bundle
json.Unmarshal([]byte(strings.Replace(carried, `"name":"reviewer"`, `"name":"../../evil"`, 1)), &in)
if _, err := Put(&in); err == nil {
t.Error("a subagent named ../../evil was put")
}
}