opencodereview 0.1.0: Open Code Review (ocr) as an agent plugin (#463)

New agent plugin @magpie-community/agent-opencodereview 0.1.0 (imyelo): Open Code Review (Alibaba's `ocr` CLI) on magpie's Agents page. connect writes `provider: "magpie"` and one `custom_providers.magpie` object (gateway base url, protocol anthropic, magpie's key for ocr) into ~/.opencodereview/config.json; magpie writes `model`. Registered in registry.json and the README's Agents table.

Reviewed at 3ea944df15c566aabf2235a147da868ea1e64f02.

Run at that sha (on mote, macOS arm64, Bun 1.4.2):
- `HOME=$(mktemp -d) bun test packages/opencodereview`: 8 pass. `bun scripts/check.mjs opencodereview`: ok (it skips agent packages). Full `bun test`: 0 fail, both at the sha and merged with main d8cfee3 (3050 tests).
- Broken by hand, each went red: url = gateway.v1 (3 fail), protocol openai (2 fail), provider anthropic (3 fail).
- magpie's real engine (scratch internal/agent test at magpie ff6fdffd6, not committed) loading this agent.js: connect then Unwire on a fresh home (leaves `{"custom_providers":{}}`, as the README says), on a config with a pre-existing custom_providers.magpie holding extra keys plus other providers/mcp_servers (restored exactly), and on another active custom provider (restored exactly).
- End to end: ocr v1.13.3 built from source, `ocr llm test` against magpie's real gateway (in-process, sandbox HOME) with a fake OpenAI-compatible upstream: "Source: provider:magpie", URL <gateway>/v1/messages, "Connection test successful", "Tool-call round trip verified"; upstream got both turns.
- Checked against ocr's source (internal/llm/resolver.go): custom_providers keys, `magpie` is not a preset name, anthropic protocol appends /v1/messages, UA is "open-code-review/<ver>", config path is ~/.opencodereview/config.json. Nothing goes upstream naming magpie; the plugin sends no data and downloads nothing.

Not tried: a real vendor account behind the gateway, Linux and Windows, ocr review/scan on a real repo.
This commit is contained in:
yelo
2026-10-28 23:07:35 +08:00
committed by GitHub
parent d8cfee3bba
commit 25488a7c8f
6 changed files with 278 additions and 0 deletions
+1
View File
@@ -139,6 +139,7 @@ it off puts the config back.
| [kimi-desktop](packages/kimi-desktop) | Ordinary [Kimi desktop](https://www.kimi.com/) Work, through its authenticated local runtime; not Kimi Code CLI |
| [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 |
| [type4me](packages/type4me) | [Type4Me](https://github.com/joewongjc/type4me), macOS voice input: `~/Library/Application Support/Type4Me/magpie-agent.json`, for its LLM post-processing |
| [opencodereview](packages/opencodereview) | [Open Code Review](https://github.com/alibaba/open-code-review) (`ocr`): `~/.opencodereview/config.json` as a custom Anthropic provider, so `ocr review` / `ocr scan` run on magpie's models |
```sh
magpie plugin add @magpie-community/agent-<name>
+113
View File
@@ -0,0 +1,113 @@
# @magpie-community/agent-opencodereview
[Open Code Review](https://github.com/alibaba/open-code-review) (`ocr`),
Alibaba's AI code review CLI, as a magpie agent. With this plugin it is on
magpie's Agents page like the agents magpie ships with: pick one of magpie's
models for it and `ocr review` / `ocr scan` run on that model.
This is an unofficial integration: Open Code Review is Alibaba's, and this
plugin is not affiliated with or endorsed by Alibaba. The icon is Open Code
Review's own logo, which magpie references by URL.
```sh
magpie plugin add @magpie-community/agent-opencodereview
```
Then pick one of magpie's models in Open Code Review's row. magpie writes into
`~/.opencodereview/config.json`:
```json
{
"model": "zai/glm-5.3",
"provider": "magpie",
"custom_providers": {
"magpie": {
"url": "http://127.0.0.1:3425",
"protocol": "anthropic",
"api_key": "magpie-…"
}
}
}
```
## What it owns
| Key | Value |
|---|---|
| `provider` | `magpie` |
| `model` | the magpie model picked |
| `custom_providers.magpie.url` | the gateway's base address, with no `/v1` |
| `custom_providers.magpie.protocol` | `anthropic` |
| `custom_providers.magpie.api_key` | the key magpie keeps for ocr |
`provider` and `model` are ocr's own selection; `protocol: "anthropic"` makes
ocr speak the Anthropic Messages API. The url has no `/v1` suffix because ocr
appends `/v1/messages` itself. These are the keys `ocr config set` writes for a
custom provider (`provider`, `custom_providers.<name>.url`, `.protocol`,
`.api_key`).
Everything else stays yours: other `custom_providers` entries, `providers`,
`llm`, `max_tokens`, `effort`, `language`, `mcp_servers`, `rule.json` and
sessions. magpie edits keys in place and stashes what it replaces.
A `custom_providers.magpie` you had before is replaced whole while connected —
the three fields above, and nothing else — and restored on disconnect. Its
values come back; its formatting and comments do not. Keep a manual service you
need beside magpie under another provider name.
The plugin gives ocr no Library instructions, MCP servers or skills: ocr keeps
its own `rule.json` and `mcp_servers`.
## Disconnecting
ocr reads the file on every run, so the next `ocr review` / `ocr scan` uses the
new model: no restart. Disconnecting — picking ocr's own model again or
switching it off — puts back the `provider`, `model` and
`custom_providers.magpie` values magpie replaced, and removes the keys it
added. A machine with no config file at all is left an empty
`custom_providers` object; ocr ignores it.
Disconnect before disabling or uninstalling the plugin: removing a plugin does
not run the agent's disconnect, and ocr would keep pointing at a gateway that
is no longer configured for it. If that happens, set `provider` back to the
provider you used before, or remove `provider` and `custom_providers.magpie`
by hand.
## Other ways ocr finds an endpoint
ocr resolves its endpoint from the config file first, then `OCR_LLM_URL`,
`OCR_LLM_TOKEN` and `OCR_LLM_MODEL`, then `ANTHROPIC_BASE_URL`,
`ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_MODEL`, then shell rc files. A complete
config file wins, so the saved `magpie` provider takes precedence over those
variables (checked with ocr v1.13.2). `ocr llm test` sends a test conversation
to the configured model and is the quickest way to verify the setup.
## Configuration path
ocr keeps its config at `~/.opencodereview/config.json`, its home taken from
the OS. It has no flag or environment variable that moves it (v1.13.2), so a
different `HOME` (or `USERPROFILE` on Windows) is the only way it moves; the
descriptor uses the same `~` magpie expands.
## Requirements and verified versions
magpie installed and signed in; `ocr` installed with
`npm install -g @alibaba-group/open-code-review`.
Tried on macOS 26.6.2 arm64 with magpie 0.1.1326 and ocr 1.13.2, including
`ocr llm test`'s tool round trip and disconnect restoring a pre-existing
config. The descriptor has no platform-specific code; the same path and keys
apply on macOS, Linux and Windows, though only macOS was tried.
## Development
```sh
bun test packages/opencodereview
magpie plugin add ./packages/opencodereview # try it on your own magpie
```
The module is one file with no imports, run by magpie's engine. The
repository's `scripts/check.mjs` skips agent packages; this package's test
checks the descriptor and what `connect` returns.
How agent plugins work: [usemagpie.ai/docs/plugins#agents](https://usemagpie.ai/docs/plugins#agents).
@@ -0,0 +1,48 @@
// Open Code Review (Alibaba's `ocr` CLI) keeps its LLM selection in
// ~/.opencodereview/config.json: a top-level `provider` + `model` pair, with
// the endpoint under `custom_providers.<name>` (url / protocol / api_key).
// ocr reads that file on every run, so a new model takes effect on the next
// `ocr review` / `ocr scan`, with no restart.
//
// `connect` writes the whole custom_providers.magpie object as one key, not
// three leaf keys: leaf-only writes leave an empty magpie provider behind
// when there was none before, and magpie restores an object it replaced as
// one unit. The gateway serves Anthropic's /v1/messages on its base address,
// and ocr's anthropic protocol appends that path itself, so the address goes
// in as is, with no /v1 suffix, beside the key magpie keeps for ocr.
//
// magpie stashes the values it replaces and restores them on disconnect,
// removing the keys it created. Everything else in the file — your own
// providers, rules, settings — stays untouched.
export const agent = {
id: "opencodereview",
name: "Open Code Review",
// ocr's own logo, on the Agents page and the plugin's row
icon: "https://raw.githubusercontent.com/alibaba/open-code-review/main/imgs/logo.svg",
// `ocr` on PATH; ~/.opencodereview also holds its rule.json and sessions
bin: "ocr",
dir: "~/.opencodereview",
config: "~/.opencodereview/config.json",
format: "json",
model: "model",
// ocr sends "open-code-review/v1.13.2 | claude"; magpie matches lowercase
// prefixes, for requests that reach the gateway without ocr's key
ua: ["open-code-review"],
notice:
"ocr reads its config on every run: the next ocr review / ocr scan uses the new model. ocr 每次运行都会读取配置:下一次 ocr review / ocr scan 即使用新模型。",
}
export function connect({ gateway }) {
return {
// make ocr's active provider the custom provider defined below
provider: "magpie",
// one object, so magpie stashes and restores the provider whole and no
// empty magpie entry is left behind; the anthropic protocol has ocr call
// <url>/v1/messages
"custom_providers.magpie": {
url: gateway.url,
protocol: "anthropic",
api_key: gateway.key,
},
}
}
@@ -0,0 +1,103 @@
import { expect, test } from "bun:test"
import { agent, connect } from "./opencodereview.agent.js"
const gateway = { url: "http://127.0.0.1:3425", v1: "http://127.0.0.1:3425/v1", key: "magpie-opencodereview" }
const model = { id: "zai/glm-5.3", name: "GLM-5.3" }
// Apply key-paths the way magpie edits a JSON config: dotted paths address
// nested keys, missing intermediates are created, other keys are preserved.
function apply(config, entries) {
const out = structuredClone(config)
for (const [path, value] of Object.entries(entries)) {
const parts = path.split(".")
let node = out
for (const part of parts.slice(0, -1)) {
if (typeof node[part] !== "object" || node[part] === null) node[part] = {}
node = node[part]
}
node[parts[parts.length - 1]] = value
}
return out
}
test("says where ocr keeps its model", () => {
expect(agent).toMatchObject({
id: "opencodereview",
bin: "ocr",
dir: "~/.opencodereview",
config: "~/.opencodereview/config.json",
format: "json",
model: "model",
})
// ocr sends magpie's model id as is
expect(agent.prefix).toBeUndefined()
})
test("shows ocr's own icon, as the package gives it", async () => {
const pkg = await Bun.file(new URL("./package.json", import.meta.url)).json()
expect(agent.icon).toBe("https://raw.githubusercontent.com/alibaba/open-code-review/main/imgs/logo.svg")
expect(pkg.magpie.icon).toBe(agent.icon)
})
test("matches ocr's User-Agent, which magpie reads as lowercase prefixes", () => {
const real = "open-code-review/v1.13.2 | claude"
expect(agent.ua.length).toBeGreaterThan(0)
for (const entry of agent.ua) {
expect(entry).toBe(entry.toLowerCase())
expect(real.startsWith(entry)).toBe(true)
}
expect(agent.ua).toContain("open-code-review")
})
test("tells the user when a new model takes effect, in English and Chinese", () => {
expect(agent.notice).toContain("the next ocr review / ocr scan uses the new model")
expect(agent.notice).toContain("下一次 ocr review / ocr scan 即使用新模型")
})
test("points ocr at magpie's anthropic endpoint with its own key", () => {
const out = connect({ gateway, model })
expect(out).toEqual({
provider: "magpie",
"custom_providers.magpie": {
url: "http://127.0.0.1:3425",
protocol: "anthropic",
api_key: "magpie-opencodereview",
},
})
// no /v1 suffix: ocr's anthropic protocol appends /v1/messages itself
expect(out["custom_providers.magpie"].url).not.toContain("/v1")
// one unit, as pig writes its provider: no empty magpie provider is left
// behind when disconnect takes the key out
expect(Object.keys(out)).toEqual(["provider", "custom_providers.magpie"])
})
test("yields a config ocr accepts, leaving other providers alone", () => {
const existing = {
provider: "local",
model: "zai/glm-5.3",
custom_providers: {
local: { url: "http://127.0.0.1:3425", protocol: "anthropic", api_key: "x" },
},
llm: {},
}
// magpie writes the model key itself, connect's keys alongside it
const out = apply(apply(existing, { model: model.id }), connect({ gateway, model }))
expect(out).toEqual({
provider: "magpie",
model: "zai/glm-5.3",
custom_providers: {
local: { url: "http://127.0.0.1:3425", protocol: "anthropic", api_key: "x" },
magpie: { url: gateway.url, protocol: "anthropic", api_key: gateway.key },
},
llm: {},
})
})
test("creates custom_providers on a fresh config", () => {
const out = apply({}, connect({ gateway, model }))
expect(out.custom_providers.magpie.url).toBe(gateway.url)
})
test("does not depend on receiving a model", () => {
expect(connect({ gateway }).provider).toBe("magpie")
})
+11
View File
@@ -0,0 +1,11 @@
{
"name": "@magpie-community/agent-opencodereview",
"version": "0.1.0",
"description": "Open Code Review (Alibaba's ocr CLI) as a magpie agent: pick one of magpie's models for ocr review / ocr scan on the Agents page",
"type": "module",
"files": ["opencodereview.agent.js", "README.md"],
"keywords": ["magpie", "magpie-agent", "opencodereview", "open-code-review", "ocr", "llm-gateway"],
"license": "MIT",
"repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/opencodereview" },
"magpie": { "agent": "./opencodereview.agent.js", "icon": "https://raw.githubusercontent.com/alibaba/open-code-review/main/imgs/logo.svg" }
}
+2
View File
@@ -76,6 +76,8 @@
"summary": { "en": "Type4Me (macOS voice input) on magpie's Agents page: pick one of magpie's models for its LLM post-processing, used from the next dictation.", "zh": "把 Type4Me(macOS 语音输入)加到 magpie 的 Agent 页:给它的 LLM 后处理选 magpie 的模型,下一次语音输入即生效。" } },
{ "package": "@magpie-community/agent-cowork", "name": "Tuanjie Cowork", "kind": "agent", "community": true,
"summary": { "en": "Tuanjie Cowork (codely) on magpie's Agents page: pick one of magpie's models and Cowork chats with it, on the subscriptions magpie already holds.", "zh": "把团结 Cowork(codely)加到 magpie 的 Agent 页:给它选一个 magpie 的模型,它聊天就走那个模型,用的是 magpie 里已登录的那些订阅的额度。" } },
{ "package": "@magpie-community/agent-opencodereview", "name": "Open Code Review", "kind": "agent", "community": true,
"summary": { "en": "Open Code Review (Alibaba's ocr CLI) on magpie's Agents page: pick one of magpie's models and ocr review / ocr scan use it, read from the config on the next run.", "zh": "把 Open Code Review(阿里巴巴的 ocr CLI)加到 magpie 的 Agent 页:给它选 magpie 的模型,下一次 ocr review / ocr scan 即从配置中读到并生效。" } },
{ "package": "@magpie-community/middleware-reserve", "name": "Reserve", "kind": "middleware", "community": true,
"summary": { "en": "Two routings that keep something in reserve: fill accounts up to a ceiling of their allowance, or use subscriptions before API keys.", "zh": "两种留余量的路由:账号用到额度上限就换下一个,或订阅账号优先于 API key。" } },
{ "package": "@magpie-community/tools-search1api", "name": "Search1API", "icon": "https://s1.dev/icon.png", "kind": "tools", "community": true,