An agent a plugin adds is known only while the plugin is on. Turning
the plugin off or removing it (CLI `magpie plugin off/rm`, or the
Plugins page) left the agent's config on magpie, and `magpie <agent>
default` then said `unknown agent`, with nothing to put it back.
- provider.SetPluginOff (off) and provider.RemovePlugin first call
provider.PluginAgentGoing, set by internal/agent to UnwirePlugin: the
agent is disconnected as `magpie <agent> default` does (Disconnect),
while the plugin still loads. A plugin off already is read from its
module as it is; one whose module is gone puts back each file whose
stash names its spec. If that fails, the plugin is left as it was
and the error says why.
- The stash now records the plugin's spec and the file's format, so
`magpie <id> default` for the agent of a plugin deleted on disk puts
the file back from the stash alone (agent.RestoreGone; an older
stash's format comes from its file's name, agentplug.FormatOf). A
file that no longer holds magpie's gateway key is the user's and is
left alone; one that can't be read is unknown: nothing is written,
the stash is kept. With the plugin only switched off, `default` says
the agent is off magpie already instead of "unknown agent".
- Turning the plugin back on (or installing it again) does not rewire
the agent by itself: its config stays as the user had it. Connecting
it (its switch on the Agents page) puts back the model it was on,
through Disconnect's `.reconnect`. The CLI says so when it turns off
or removes a plugin whose agent was on magpie.
Run (this change on origin/main f3c4d7b7a, then rebased onto
0fb0bfda3, which changes only an internal/gateway test; provider and
cli run again at the pushed head):
- gofmt -l: none; go vet -tags nogui on darwin, linux, windows for
agent, agentplug, cli, provider, gui, plugin: ok.
- go test -tags nogui -timeout 45m -count=1 ./internal/agent
./internal/agentplug ./internal/cli ./internal/provider
./internal/plugin ./internal/gui: agent, agentplug, cli, plugin, gui
ok; provider crashes in TestUnreadLoginsWriteErrorsKeepCredentials
("close of synctest channel from outside bubble", filememo.Forget),
the same on origin/main 0fb0bfda3 run alone: #3632, open, not this
change. At the pushed head: cli ok; provider with -skip
TestUnreadLogins ok.
- Real use, sandbox HOME, magpie built from this tree, gateway on
127.0.0.1:3491, web on 3492: `magpie plugin add agent-kilo`
(@magpie-community/agent-kilo 0.1.0, not on npm, from the plugins
repo's dist branch), a kilo.jsonc with comments and a provider of its
own, `magpie kilo magpie/deepseek/deepseek-chat` (wired, provider
block added). Then, each time from wired: `magpie plugin off` -> cmp
byte-identical; `plugin on` -> still the user's; `plugin rm` ->
byte-identical; POST /api/plugins/off and /api/plugins/remove (the
Plugins page's calls) -> byte-identical; plugin dir deleted and
plugins.json emptied by hand, then `magpie kilo default` -> put back,
byte-identical. `magpie kilo default` with the plugin off says it is
off magpie already.
Broken by hand, each red, then restored:
- PluginAgentGoing left nil: the four off/remove tests fail.
- the SetPluginOff call removed: Off and ModuleGone tests fail; the
RemovePlugin call removed: Remove and RemovedWhileOff fail.
- Spec not stashed: ModuleGone fails. pluggedOff disabled:
RemovedWhileOff fails. FormatOf fallback removed: TestRestoreGoneAgent
fails. The gateway-key check removed: LeavesAFileOffMagpie fails.
- Unwire instead of Disconnect: the Off test fails (How "first", not
"again"). The off-plugin check in RestoreGone skipped: the Off test
fails. RestoreGone not called from the CLI: TestGoneAgentDefault
fails with `unknown agent "kilo"`.
Not tried: the Windows box; a real Kilo CLI reading the restored file;
the GUI suite (no Plugins page code changed: the page's calls reach the
same provider functions, tried above through the web API). Not changed:
an inline JSON object magpie wrote into comes back reformatted (same
values) on any plugin agent's Disconnect, `default` included: #3814.