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.
49 lines
2.2 KiB
JavaScript
49 lines
2.2 KiB
JavaScript
// 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,
|
|
},
|
|
}
|
|
}
|