diff --git a/README.md b/README.md index d07c7dd..75aa811 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ it off puts the config back. | Package | Agent | |---|---| | [aider](packages/aider) | [Aider](https://aider.chat): `~/.aider.conf.yml`, through litellm's `openai/` prefix | +| [kilo](packages/kilo) | [Kilo Code](https://kilo.ai): `~/.config/kilo/kilo.jsonc`, through an OpenAI-compatible provider | | [pig](packages/pig) | [PiG](https://github.com/MichaelKinsy/PiG): injects Magpie's endpoint and model catalog into `~/.pig/agent/models.json`; choose the model in PiG, startup settings stay unchanged | | [kimi-desktop](packages/kimi-desktop) | Ordinary [Kimi desktop](https://www.kimi.com/) Work, through its authenticated local runtime; not Kimi Code CLI | | [type4me](packages/type4me) | [Type4Me](https://github.com/joewongjc/type4me), macOS voice input: `~/Library/Application Support/Type4Me/magpie-agent.json`, for its LLM post-processing | diff --git a/packages/kilo/README.md b/packages/kilo/README.md new file mode 100644 index 0000000..d50bec4 --- /dev/null +++ b/packages/kilo/README.md @@ -0,0 +1,56 @@ +# @magpie-community/agent-kilo + +[Kilo Code](https://kilo.ai) as a magpie agent. magpie has no setup of its own +for Kilo Code; with this plugin it is on magpie's Agents page like the agents +magpie ships with. + +```sh +magpie plugin add @magpie-community/agent-kilo +``` + +Then pick one of magpie's models in Kilo Code's row. Kilo Code is a fork of +OpenCode, so it reaches any OpenAI-compatible endpoint through a provider in +`~/.config/kilo/kilo.jsonc`, which magpie writes: + +```jsonc +{ + "provider": { + "magpie": { + "name": "magpie", + "npm": "@ai-sdk/openai-compatible", + "options": { + "baseURL": "http://127.0.0.1:3425/v1", + "apiKey": "magpie-kilo" + }, + "models": { + "deepseek/deepseek-flash": { + "name": "DeepSeek Flash", + "tool_call": true, + "limit": { "context": 1000000, "output": 393216 }, + "variants": { + "high": { "reasoningEffort": "high" }, + "max": { "reasoningEffort": "max" } + } + } + } + } + }, + "model": "magpie/deepseek/deepseek-flash" +} +``` + +Kilo names a model `/`, so magpie's own id is written after the +`magpie/` prefix. The provider, its address, its key and every model are written +because Kilo has no catalog of its own for a gateway: its model picker reads the +models listed under the provider. Your comments and other settings stay. +Requests use the Chat Completions API. Reasoning variants follow each model's +own levels, weakest first; models without levels have an empty variants set. +Image-capable models also declare image inputs and attachment support. Unknown +context windows are omitted from the configuration. +Picking Kilo's own model again, or switching it off, puts every key back as it +was. Restart Kilo after a change: it reads its settings when it starts. + +The Library also reaches it: instructions go in `~/.config/kilo/AGENTS.md`, MCP +servers in `kilo.jsonc`'s `mcp` key, skills in `~/.config/kilo/skills`. + +How agent plugins work: [usemagpie.ai/docs/plugins#agents](https://usemagpie.ai/docs/plugins#agents). diff --git a/packages/kilo/kilo.agent.js b/packages/kilo/kilo.agent.js new file mode 100644 index 0000000..74c2289 --- /dev/null +++ b/packages/kilo/kilo.agent.js @@ -0,0 +1,66 @@ +// Kilo Code (kilo.ai) is a fork of OpenCode, so it reaches any +// OpenAI-compatible endpoint the way OpenCode does: a provider under +// `provider.` with an AI SDK package, a base URL and the models it +// has, and a top-level `model` naming what to use. Everything lives in +// ~/.config/kilo/kilo.jsonc, next to the user's own settings, which +// magpie's writer keeps. +export const agent = { + id: "kilo", + name: "Kilo Code", + // kilo.ai's own mark, on the Agents page and the plugin's row + icon: "https://github.com/Kilo-Org.png", + bin: "kilo", + config: "~/.config/kilo/kilo.jsonc", + format: "json", + // kilo.jsonc is the CLI's global config; a project's .kilo/ wins over + // it, so a pick here is the default, not an override + model: "model", + // Kilo names a model /, and magpie's ids already hold + // slashes (/), so the value is magpie/ + prefix: "magpie/", + ua: ["kilo", "opencode"], + notice: "Kilo reads its settings when it starts: restart it to use the new model.", + // Kilo reads the Library the way OpenCode does: instructions and skills + // under its config folder, MCP servers in kilo.jsonc's `mcp` key + library: { + instructions: "~/.config/kilo/AGENTS.md", + mcp: "~/.config/kilo/kilo.jsonc", + mcpFormat: "opencode", + skills: "~/.config/kilo/skills", + }, +} + +// Kilo has no model catalog of its own for a gateway like magpie, so the +// provider, its address and every model have to be written beside the +// model itself; `models` is each one magpie offers Kilo. +// Kilo lists variants in key order, weakest first. +const ORDER = ["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"] +const rank = (effort) => (ORDER.indexOf(effort) < 0 ? ORDER.length : ORDER.indexOf(effort)) + +export function connect({ gateway, models }) { + const catalog = {} + for (const m of models ?? []) { + const entry = { name: m.name ?? m.id, tool_call: true } + if (m.images) { + entry.attachment = true + entry.modalities = { input: ["text", "image"], output: ["text"] } + } + if (m.context > 0) entry.limit = { context: m.context, output: m.output ?? 0 } + // An empty set prevents Kilo from inventing reasoning levels. + const variants = {} + for (const level of [...new Set(m.efforts ?? [])].sort((a, b) => rank(a) - rank(b))) { + variants[level] = { reasoningEffort: level } + } + entry.variants = variants + catalog[m.id] = entry + } + // One key lets magpie restore the whole provider when switching off. + return { + "provider.magpie": { + name: "magpie", + npm: "@ai-sdk/openai-compatible", + options: { baseURL: gateway.v1, apiKey: gateway.key }, + models: catalog, + }, + } +} diff --git a/packages/kilo/kilo.test.mjs b/packages/kilo/kilo.test.mjs new file mode 100644 index 0000000..6586d93 --- /dev/null +++ b/packages/kilo/kilo.test.mjs @@ -0,0 +1,128 @@ +import { expect, test } from "bun:test" +import { agent, connect } from "./kilo.agent.js" + +test("says where Kilo keeps its model", () => { + expect(agent).toMatchObject({ + id: "kilo", + config: "~/.config/kilo/kilo.jsonc", + format: "json", + model: "model", + prefix: "magpie/", + }) +}) + +test("shows Kilo's own icon, as the package gives it", async () => { + const pkg = await Bun.file(new URL("./package.json", import.meta.url)).json() + expect(pkg.magpie.icon).toBe(agent.icon) + expect(pkg.magpie.agent).toBe("./kilo.agent.js") +}) + +test("points Kilo at magpie as an OpenAI-compatible provider", () => { + const out = connect({ + gateway: { url: "http://127.0.0.1:3425", v1: "http://127.0.0.1:3425/v1", key: "magpie-kilo" }, + model: { id: "deepseek/deepseek-flash", name: "DeepSeek Flash" }, + models: [ + { id: "deepseek/deepseek-flash", name: "DeepSeek Flash", context: 1000000, output: 393216, efforts: ["high", "max"] }, + { id: "trae-cn/glm-5.3-flash", name: "GLM 5.3 Flash", context: 200000, output: 32000 }, + ], + agent: { id: "kilo", config: "/home/u/.config/kilo/kilo.jsonc" }, + }) + expect(out).toEqual({ + "provider.magpie": { + name: "magpie", + npm: "@ai-sdk/openai-compatible", + options: { baseURL: "http://127.0.0.1:3425/v1", apiKey: "magpie-kilo" }, + models: { + "deepseek/deepseek-flash": { + name: "DeepSeek Flash", + tool_call: true, + variants: { high: { reasoningEffort: "high" }, max: { reasoningEffort: "max" } }, + limit: { context: 1000000, output: 393216 }, + }, + "trae-cn/glm-5.3-flash": { + name: "GLM 5.3 Flash", + tool_call: true, + variants: {}, + limit: { context: 200000, output: 32000 }, + }, + }, + }, + }) +}) + +test("writes a provider with no models when magpie offers none", () => { + const out = connect({ + gateway: { url: "http://127.0.0.1:3425", v1: "http://127.0.0.1:3425/v1", key: "k" }, + models: [], + agent: { id: "kilo", config: "/home/u/.config/kilo/kilo.jsonc" }, + }) + expect(out["provider.magpie"].models).toEqual({}) +}) + +const gateway = { v1: "http://127.0.0.1:3425/v1", key: "k" } +const catalogFor = (models) => connect({ gateway, models })["provider.magpie"].models + +test("declares image inputs only for image-capable models", () => { + const catalog = catalogFor([ + { id: "vision", images: true }, + { id: "text", images: false }, + { id: "unspecified" }, + ]) + expect(catalog.vision.attachment).toBe(true) + expect(catalog.vision.modalities).toEqual({ input: ["text", "image"], output: ["text"] }) + for (const id of ["text", "unspecified"]) { + expect(catalog[id]).not.toHaveProperty("attachment") + expect(catalog[id]).not.toHaveProperty("modalities") + } +}) + +test("orders and deduplicates the model's own reasoning levels without changing the input", () => { + const efforts = ["ultra", "max", "high", "medium", "low", "minimal", "none", "xhigh", "max"] + const original = [...efforts] + const { variants } = catalogFor([{ id: "reasoner", efforts }]).reasoner + expect(Object.keys(variants)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"]) + for (const level of Object.keys(variants)) { + expect(variants[level]).toEqual({ reasoningEffort: level }) + } + expect(efforts).toEqual(original) +}) + +test("keeps unrecognized reasoning levels after known levels", () => { + const { variants } = catalogFor([{ id: "reasoner", efforts: ["custom", "max", "high", "custom"] }]).reasoner + expect(Object.keys(variants)).toEqual(["high", "max", "custom"]) + expect(variants.custom).toEqual({ reasoningEffort: "custom" }) +}) + +test("writes empty variants for models without reasoning levels", () => { + const catalog = catalogFor([{ id: "empty", efforts: [] }, { id: "missing" }]) + for (const model of Object.values(catalog)) { + expect(model.variants).toEqual({}) + expect(model).not.toHaveProperty("reasoning") + } +}) + +test("omits limits for unknown context windows and preserves known limits", () => { + const catalog = catalogFor([ + { id: "missing", output: 100 }, + { id: "zero", context: 0, output: 100 }, + { id: "negative", context: -1 }, + { id: "known", context: 200000, output: 32000 }, + { id: "unknown-output", context: 200000 }, + ]) + for (const id of ["missing", "zero", "negative"]) { + expect(catalog[id]).not.toHaveProperty("limit") + } + expect(catalog.known.limit).toEqual({ context: 200000, output: 32000 }) + expect(catalog["unknown-output"].limit).toEqual({ context: 200000, output: 0 }) +}) + +test("returns the provider as one restorable key even when the model catalog is omitted", () => { + const out = connect({ gateway }) + expect(Object.keys(out)).toEqual(["provider.magpie"]) + expect(out["provider.magpie"]).toEqual({ + name: "magpie", + npm: "@ai-sdk/openai-compatible", + options: { baseURL: gateway.v1, apiKey: gateway.key }, + models: {}, + }) +}) diff --git a/packages/kilo/package.json b/packages/kilo/package.json new file mode 100644 index 0000000..0db5719 --- /dev/null +++ b/packages/kilo/package.json @@ -0,0 +1,11 @@ +{ + "name": "@magpie-community/agent-kilo", + "version": "0.1.0", + "description": "Kilo Code (kilo.ai) as a magpie agent: pick one of magpie's models for it on the Agents page", + "type": "module", + "files": ["kilo.agent.js", "README.md"], + "keywords": ["magpie", "magpie-agent", "kilo", "kilocode", "llm-gateway"], + "license": "MIT", + "repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/kilo" }, + "magpie": { "agent": "./kilo.agent.js", "icon": "https://github.com/Kilo-Org.png" } +} diff --git a/registry.json b/registry.json index 6dc5ccc..c29bd22 100644 --- a/registry.json +++ b/registry.json @@ -56,6 +56,8 @@ "summary": { "en": "New API's sensitive-word filter: turn away or mask words and patterns in what you send, and in replies.", "zh": "New API 的敏感词过滤:拒绝或替换你发出的内容和回复里的词与正则。" } }, { "package": "@magpie-community/middleware-think-tags", "name": "Think Tags", "kind": "middleware", "community": true, "summary": { "en": "Take a model's … out of its reply's text, or put a Chat reply's reasoning into it.", "zh": "去掉回复正文开头的 …,或把 Chat 回复的思考内容放进正文。" } }, + { "package": "@magpie-community/agent-kilo", "name": "Kilo Code", "kind": "agent", "community": true, "icon": "https://github.com/Kilo-Org.png", + "summary": { "en": "Kilo Code (kilo.ai) on magpie's Agents page: pick one of magpie's models for it, and switch it off to put its config back.", "zh": "把 Kilo Code(kilo.ai)加到 magpie 的 Agent 页:选择 magpie 的模型,关掉即恢复原来的配置。" } }, { "package": "@magpie-community/middleware-antigravity-cloak", "name": "Antigravity Cloak", "kind": "middleware", "community": true, "summary": { "en": "Claude Code and Claude Desktop on an Antigravity account: the words Antigravity refuses their system prompt for are broken up, in what Antigravity alone is sent.", "zh": "让 Claude Code 和 Claude Desktop 能用 Antigravity 账号:只在发给 Antigravity 的请求里拆开它据以拒绝系统提示词的那几个词。" } }, { "package": "@magpie-community/middleware-codex-history", "name": "Codex History Filter", "kind": "middleware", "community": true,