Commit Graph
3 Commits
Author SHA1 Message Date
yetone c3bbf16022 agentplug: an agent plugin's keys are written in the order it gave them (#1890)
What: connect's result is taken from the module as JSON text (moejs
AppendJSON keeps JS insertion order) instead of rt.ToGo, which made a Go
map at every level. An object or array connect returns reaches the writer
as a json.RawMessage, so edit.SetJSON writes it in the plugin's order;
strings, numbers, booleans and null are their Go values as before (the
gateway-key mark still matches a string). edit.SetYAML now takes a
json.RawMessage too, as a block-style node in the text's order (it would
have written the bytes as a list of ints), and the env format writes it
compact as before.

Why: Kilo's agent plugin (magpie-community/plugins#90) returns each
model's effort variants weakest first, low, medium, high, the order Kilo
lists them in. Go maps marshal sorted, so Kilo showed high, low, medium.
magpie's own OpenCode wiring already keeps order (openCodeVariants).
The key paths connect returns are still applied in sorted order: each is
a separate edit, and the user's file around them is untouched.

Siblings: rt.ToGo's other caller (middleware's string lists) writes no
file; the Library's MCP block for a plugin agent is built by magpie, not
returned by the plugin.

Run:
- TestPluggedKeepsPluginOrder (Kilo-shaped connect, a kilo.jsonc with a
  comment, a theme, $schema, a provider of the user's own with keys
  zeta, alpha and a trailing key) and TestPluggedKeepsPluginOrderYAMLAndEnv.
  With agentplug.go put back: FAIL, variants written high, low, medium
  and provider keys sorted. With yaml.go put back: FAIL, the object
  written as a list of byte values. Both pass with the change.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., the three builds: OK.
- go test -tags nogui -timeout 40m ./... under a scratch HOME: all ok.
  (A first run with the default 10m timeout timed out in
  internal/gateway while four other sessions' suites ran on this box and
  the disk was full; the gateway package took 973s under that load and
  passed.)
- Real use, sandbox HOME: this build, `magpie plugin add` of
  packages/kilo at plugins PR #90 head b67360cb7, a provider whose
  fake-chat has efforts stored high, low, medium; `magpie kilo
  magpie/fakeup/fake-chat` wrote variants low, medium, high with the
  user's comment, $schema, theme and own provider in place, and
  @kilocode/cli 7.8.8 `kilo models magpie --verbose` lists them low,
  medium, high. `magpie kilo default` put the file back; the only
  difference is Kilo's own one-time permission migration.
2026-10-13 10:55:45 +08:00
yetone 26816de2f9 library, agentplug: an agent a plugin adds is given the Library's instructions, MCP servers and skills where its agent.library says (AlmarionAI on X)
Agent plugins wired models and keys only: library.targetOf had no case
for them, so the Library's instructions, MCP servers and skills never
reached an agent a plugin adds, while the announcement said the
Library carries over.

An agent export can now say
  library: { instructions, mcp, mcpFormat, skills }
each a path (~ and $VAR expanded, as config is). mcpFormat names the
agent whose MCP file it is shaped like (agentplug.MCPFormats: claude,
codex, gemini, opencode, cursor, zed, ... 18 of the library's
mcpFormats). A format outside the list, or an mcp without one, keeps
the plugin from loading. library.pluginTarget makes such an agent a
Target, so it is written as any agent is: magpie's marker block in the
instructions file, servers merged beside the user's own (their fields
kept), skills linked or copied, Applied recording only magpie's part,
backups kept. Takes refuses a place the plugin doesn't name, and says
which agent.library key would give it.

Docs: docs/subsystems/library.md and agent-wiring.md; plugins.html
(en, zh, ja) gets the library field and what magpie does with it.

Run:
- internal/library/agent_plugin_test.go: TestPluginAgentGetsTheLibrary,
  TestPluginAgentWithoutAPlaceIsRefused, TestPluginAgentMCPFormat,
  TestPluginMCPFormatsAreWritten. With targetOf's plugin case and the
  check() validation taken out by hand, the first three go red.
- e2e: a nogui build in a scratchpad HOME (env -i, no live configs),
  `magpie plugin add` of a throwaway toy agent plugin; `library
  instructions set/agents`, `library mcp add/rm` wrote and took back
  only magpie's block and server, the user's "mine" server, its "note"
  field and other keys kept, backups made; with mcp dropped from the
  plugin, `library mcp add ... agents=toy` is refused naming
  agent.library.mcp.
- go test -tags nogui ./... (one unrelated FIFO flake in internal/agent,
  fixed in the commit before), gofmt -l clean, go vet for GOOS=linux
  and GOOS=windows clean. No GUI code changed.
2026-10-11 07:55:23 +08:00
yetone cb406c8425 plugins: a plugin can add an agent magpie has no setup of its own for
Plugins could be subscription providers or gateway middleware. Now a third
kind: an agent plugin, so a user whose agent magpie doesn't ship can still
put it on magpie.

- internal/agentplug: a plugin's magpie.agent module (or a *.agent.js file)
  exports agent = {id, name, config, format?, model, prefix?, bin?, dir?,
  ua?, icon?, notice?} and an optional connect({gateway, model, models,
  agent}) returning the other keys to write. Compiled in moejs, reloaded
  when plugins.json or the file changes; why one didn't load is kept.
- internal/jsmod: module compiling (imports kept inside the plugin), moved
  out of middleware so both share it.
- internal/agent/plugged.go: each becomes an Agent (Plugin set) after
  magpie's own. JSON, YAML and env files are edited key by key, comments
  kept; what each key held is stashed typed under plugin:<id>:<path>, and
  its own model or Disconnect puts every key back. A built-in id is
  refused; a connect that throws writes nothing. Key magpie-<id>; usage
  names it by key or ua (usage.PluginAgents).
- GUI Plugins page: an Agent kind chip and glyph, a Discover "Agents"
  section (market kind "agent"), and an installed row line "Adds X to
  Agents" or why it didn't load. zh, zh-TW, ja, de strings.
- Docs: site Plugins page (en, zh, ja) "Agent plugins", reference.md,
  agent-wiring.md, gateway-middleware.md.

Run:
- go test ./... (all ok); gofmt -l clean; GOOS=linux go vet -tags nogui
  ./... and GOOS=windows go vet ./... clean.
- TestPluggedYAML, TestPluggedJSONUnwire, TestPluggedRefused.
- GUI: plugin-agent.test.cjs 22/22 (en, zh, zh-TW, ja, de; 980 and 420;
  chromium and webkit); all plugin-*.test.cjs, i18n-keys,
  deprecated-subscriptions, filter-ime: 315 pass, 0 fail.
- Real use, in a sandbox HOME: an Aider plugin (~/.aider.conf.yml, prefix
  openai/, connect writes openai-api-base/key) installed in a dev build;
  picking DeepSeek V4.1 Flash on the Agents page wired the file keeping the
  user's comment and keys; real aider 0.86.2 `--message` answered through
  magpie from the real DeepSeek account; usage.jsonl recorded agent aider,
  provider deepseek, 200; Disconnect restored the file byte for byte.
2026-10-10 18:39:47 +08:00