From 6e720301aa85074fb19f64cc58b4e19b637f6d54 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 10 Oct 2026 22:52:47 +0800 Subject: [PATCH] agent-aider 0.1.0: Aider as a magpie agent plugin, the first of the new agent kind (#78) magpie (cb406c84) lets a plugin add an agent it has no setup of its own for. This one writes Aider's ~/.aider.conf.yml: the model under litellm's openai/ prefix, magpie's /v1 and Aider's own key. check.mjs skips agent packages as it does middleware; README gains an Agents section. Run: bun test packages/aider (2 pass); bun scripts/check.mjs; the module loaded through magpie's agentplug.Compile and its connect returned the three keys. The same module, in a sandbox magpie, wired a real aider 0.86.2 that answered from a real DeepSeek account, and Disconnect put the file back byte for byte. --- README.md | 23 ++++++++++++++++++++++- packages/aider/README.md | 25 +++++++++++++++++++++++++ packages/aider/aider.agent.js | 23 +++++++++++++++++++++++ packages/aider/aider.test.mjs | 20 ++++++++++++++++++++ packages/aider/package.json | 11 +++++++++++ scripts/check.mjs | 4 ++-- 6 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 packages/aider/README.md create mode 100644 packages/aider/aider.agent.js create mode 100644 packages/aider/aider.test.mjs create mode 100644 packages/aider/package.json diff --git a/README.md b/README.md index 131d6b7..43aec47 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # magpie-community plugins [OpenCode](https://opencode.ai) provider plugins for coding-plan -subscriptions, and [gateway middleware](#gateway-middleware) for magpie, +subscriptions, and [gateway middleware](#gateway-middleware) and [agents](#agents) for magpie, maintained by the community. Each package signs in to one subscription and makes its requests. The packages work in OpenCode and in [magpie](https://usemagpie.ai), which runs OpenCode's provider plugins. @@ -52,6 +52,27 @@ A middleware package is a folder under `packages//` with: - **`.middleware.js`**: exports `onRequest`, `onEvent` and/or `onResponse` ([the hooks](https://usemagpie.ai/docs/plugins#middleware)). It runs in magpie's gateway on moejs, so it is one file and imports nothing. - **`cases.json`** and a test that runs them with `check()` from `scripts/middleware.mjs`, which calls the hooks the way the gateway does. +## Agents + +These add an agent magpie has no setup of its own for. Once added, the agent is +on magpie's Agents page like the ones magpie ships with: pick one of magpie's +models in its row and magpie writes it into the agent's config, and switching +it off puts the config back. + +| Package | Agent | +|---|---| +| [aider](packages/aider) | [Aider](https://aider.chat): `~/.aider.conf.yml`, through litellm's `openai/` prefix | + +```sh +magpie plugin add @magpie-community/agent- +``` + +An agent package is a folder under `packages//` with: + +- **`package.json`**: name `@magpie-community/agent-`, `"magpie": {"agent": "./.agent.js"}`, no `main`. +- **`.agent.js`**: exports `agent` (where the agent keeps its model) and, if it needs more than the model, `connect` (the other keys to write) ([the reference](https://usemagpie.ai/docs/plugins#agents)). It runs in magpie on moejs, so it is one file and imports nothing. +- a test of what `connect` returns. + ## Skills Agent skills for magpie users, in `skills//SKILL.md`. diff --git a/packages/aider/README.md b/packages/aider/README.md new file mode 100644 index 0000000..3392066 --- /dev/null +++ b/packages/aider/README.md @@ -0,0 +1,25 @@ +# @magpie-community/agent-aider + +[Aider](https://aider.chat) as a magpie agent. magpie has no setup of its own +for Aider; with this plugin it is on magpie's Agents page like the agents +magpie ships with. + +```sh +magpie plugin add @magpie-community/agent-aider +``` + +Then pick one of magpie's models in Aider's row. magpie writes into +`~/.aider.conf.yml`: + +```yaml +model: openai/deepseek/deepseek-flash # magpie's model, through litellm's openai/ prefix +openai-api-base: http://127.0.0.1:3425/v1 +openai-api-key: magpie-aider # Aider's own key, so Usage names it +show-model-warnings: false +``` + +Your comments and other settings stay. Picking Aider's own model again, or +switching it off, puts every key back as it was. Restart Aider after a change: +it reads its settings when it starts. + +How agent plugins work: [usemagpie.ai/docs/plugins#agents](https://usemagpie.ai/docs/plugins#agents). diff --git a/packages/aider/aider.agent.js b/packages/aider/aider.agent.js new file mode 100644 index 0000000..29113e2 --- /dev/null +++ b/packages/aider/aider.agent.js @@ -0,0 +1,23 @@ +// Aider (aider.chat) keeps its settings in ~/.aider.conf.yml and reaches +// any OpenAI-compatible endpoint through litellm's openai/ prefix, so +// magpie's model goes in as openai//, beside magpie's +// address and the key magpie keeps for Aider. +export const agent = { + id: "aider", + name: "Aider", + bin: "aider", + config: "~/.aider.conf.yml", + model: "model", + prefix: "openai/", + ua: ["aider", "litellm"], + notice: "Aider reads its settings when it starts: restart it to use the new model.", +} + +export function connect({ gateway }) { + return { + "openai-api-base": gateway.v1, + "openai-api-key": gateway.key, + // magpie's model ids aren't in litellm's list, so aider would warn on each + "show-model-warnings": false, + } +} diff --git a/packages/aider/aider.test.mjs b/packages/aider/aider.test.mjs new file mode 100644 index 0000000..ac956d7 --- /dev/null +++ b/packages/aider/aider.test.mjs @@ -0,0 +1,20 @@ +import { expect, test } from "bun:test" +import { agent, connect } from "./aider.agent.js" + +test("says where Aider keeps its model", () => { + expect(agent).toMatchObject({ id: "aider", config: "~/.aider.conf.yml", model: "model", prefix: "openai/" }) +}) + +test("points Aider at magpie with its own key", () => { + const out = connect({ + gateway: { url: "http://127.0.0.1:3425", v1: "http://127.0.0.1:3425/v1", key: "magpie-aider" }, + model: { id: "deepseek/deepseek-flash", name: "DeepSeek Flash" }, + models: [], + agent: { id: "aider", config: "/home/u/.aider.conf.yml" }, + }) + expect(out).toEqual({ + "openai-api-base": "http://127.0.0.1:3425/v1", + "openai-api-key": "magpie-aider", + "show-model-warnings": false, + }) +}) diff --git a/packages/aider/package.json b/packages/aider/package.json new file mode 100644 index 0000000..49c3765 --- /dev/null +++ b/packages/aider/package.json @@ -0,0 +1,11 @@ +{ + "name": "@magpie-community/agent-aider", + "version": "0.1.0", + "description": "Aider (aider.chat) as a magpie agent: pick one of magpie's models for it on the Agents page", + "type": "module", + "files": ["aider.agent.js", "README.md"], + "keywords": ["magpie", "magpie-agent", "aider", "llm-gateway"], + "license": "MIT", + "repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/aider" }, + "magpie": { "agent": "./aider.agent.js" } +} diff --git a/scripts/check.mjs b/scripts/check.mjs index 3112070..60a79f7 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -14,8 +14,8 @@ for (const name of readdirSync(root)) { const pj = join(dir, "package.json") if (!existsSync(pj)) continue const pkg = JSON.parse(readFileSync(pj, "utf8")) - // gateway middleware has no OpenCode plugin; its own tests check it - if (pkg.magpie?.middleware) continue + // gateway middleware and agents have no OpenCode plugin; their own tests check them + if (pkg.magpie?.middleware || pkg.magpie?.agent) continue const problems = [] try { const mod = await import(pathToFileURL(join(dir, pkg.main ?? "index.mjs")).href)