Open Code Review (github.com/alibaba/open-code-review, npm @alibaba-group/open-code-review) is a Go CLI, `ocr`, that reviews a diff with a model. Its Claude Code, Codex, Cursor, Kimi Code and OpenCode plugins and its skills all run that command, which reads ~/.opencodereview/config.json on every run. Picking one of magpie's models on its row writes a custom provider "magpie" there (protocol openai, the gateway's /v1, a key naming Open Code Review, the model) and points provider at it. The user's own provider and model are stashed and come back on Disconnect, which also drops a custom_providers left empty. A model of the user's own can be picked too (written the way `ocr config model` writes it). Check reports a hand-edited url or key, or a removed entry. The `ocr` command counts only under a folder named for Open Code Review, since other programs share the name. WSL distros get the row too (cold distros not opened). Its User-Agent, open-code-review/<version>, already counts as this agent. CLI update via npm. Docs, READMEs, site and icon (OCR's own logo, Apache-2.0). Run (mica, at 593517bf0; origin/main has one unrelated usage commit since): - go test ./internal/agent -run 'TestOCR|WSL|Wsl|TestOwnProviderNamedAsMagpies|TestHandWiredMagpieProviderSiblings|TestAgentOf|TestEveryAgentNamedByItsKey|TestMarkedLinesEveryAgent': ok - gofmt -l: clean; GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./...: ok - Broken by hand: url dropped from Check -> TestOCRWiring red; stash turned off -> red at the Disconnect restore. TestWSLColdPlaceOpensNothing went red before the row's options were given an asleep path. - Real e2e in a sandbox HOME: npm-installed ocr v1.13.10 (7e5ce06c) darwin/arm64, magpie built from this tree, a fake OpenAI upstream that calls tools. `magpie agents` lists the row with the user's deepseek/deepseek-chat; `magpie open-code-review magpie/fake/m1` wrote the entry and kept the user's keys and settings; `ocr llm test`: connection ok, tool-call round trip verified; `ocr review` on a repo with a nil dereference: 2 findings "[bug · high]" through magpie (8 /v1/chat/completions calls, UA open-code-review/v1.13.10, model m1, its six review tools); `magpie usage` counts them under Open Code Review; `magpie open-code-review default` put deepseek/deepseek-chat back and removed custom_providers. - Full suite: not run before this push (ship at once; mote was running another session's suite). It runs on mica right after, at this head. Not tried: a real vendor model behind magpie; WSL and Windows/Linux machines for real; the Claude Code / OpenCode plugin path itself (it runs the same `ocr`); an ocr installed by the curl script outside a folder named for it is found by ~/.opencodereview only.
68 lines
2.7 KiB
Go
68 lines
2.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/usage"
|
|
)
|
|
|
|
// Every agent's requests are told by what its own description says.
|
|
func TestAgentOf(t *testing.T) {
|
|
cases := map[string]string{
|
|
"claude-cli/2.1.0 (external, cli)": "claude",
|
|
"codex_cli_rs/0.40.0 (Mac OS 26.0; arm64)": "codex",
|
|
"GeminiCLI/0.9.0 (darwin; arm64)": "gemini",
|
|
"opencode/1.2.3": "opencode",
|
|
"mimocode/1.2.3": "mimocode",
|
|
"deveco/0.2.3 ai-sdk/provider-utils/4.0": "deveco", // 0.2.3 sends ai-sdk/provider-utils/4.0.23
|
|
"curl/8.4.0": "curl",
|
|
"oh-my-pi/1.0": "omp",
|
|
"command-code/2.0": "commandcode",
|
|
"deepseek-harness/0.3.1": "dsh",
|
|
"dsh": "dsh", // a record kept by an id already
|
|
"pi": "pi",
|
|
"grok-pager/0.2.1": "grok",
|
|
"ZCode/3.10.1": "zcode",
|
|
"Alma/1.2.0": "alma",
|
|
"HanaAgent/1.0": "hanako",
|
|
"hanako": "hanako", // its key
|
|
"atomcode/5.2.1": "atomcode",
|
|
"open-code-review/1.13.10": "open-code-review",
|
|
"open-code-review/1.13.10 | claude": "open-code-review",
|
|
"cline ai-sdk/openai-compatible/3.0.37": "cline",
|
|
"Vibecoding Client/1.3.104 (darwin; arm64; go1.26.2)": "mothx",
|
|
"ZooCode/3.90.0": "zoo-code",
|
|
"minimax-code": "minimax-code", // what magpie's entry sends
|
|
"MiniMaxCode": "minimax-code", // 0.6.8's own (#1605)
|
|
"": "other",
|
|
// Kimi Code 2.x and its desktop app, as jiabubu's requests named
|
|
// them; the old Python kimi-cli's KimiCLI/
|
|
"kimi-code-cli/2.4.1": "kimi",
|
|
"kimi-code-desktop/1.2.1": "kimi-code-desktop",
|
|
"KimiCLI/1.4.0": "kimi",
|
|
}
|
|
for ua, want := range cases {
|
|
if got := usage.AgentOf(ua); got != want {
|
|
t.Errorf("%q: got %q want %q", ua, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Every agent's own gateway key (gateway.TokenFor) names it in usage: the
|
|
// ones that send no User-Agent of their own (StepCode, jcode, Prime Agent,
|
|
// Snow…) are told by that key alone (#1605's check of the class).
|
|
func TestEveryAgentNamedByItsKey(t *testing.T) {
|
|
seen := map[string]bool{}
|
|
for _, a := range Clients() {
|
|
seen[a.ID] = true
|
|
if got := usage.AgentOf(a.ID); got != a.ID {
|
|
t.Errorf("%s's key names %q", a.ID, got)
|
|
}
|
|
}
|
|
for _, id := range []string{"minimax-code", "stepcode", "jcode", "prime-agent", "snow", "deveco"} {
|
|
if !seen[id] {
|
|
t.Errorf("%s isn't among the agents usage knows", id)
|
|
}
|
|
}
|
|
}
|