diff --git a/README.md b/README.md index 217e8e96a..71d5db5d9 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ magpie finds the subscriptions your agents are signed in to by reading their sig
-Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · Dim · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · PenguinHarness · Aside · OmO · Prime Agent · mu · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · JetBrains Air · Air (JetBrains IDEs) · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Mistral Vibe · Qwen Code · Muse Code · Empryo · nanobot · miniQ · Paimon · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy · Pencil · Paseo · OpenPencil · OpenBot · Craft Agents · Tuanjie Cowork · NewMax · LiveAgent · Raycast · Kiro Crew · OpenMausBot · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Shelley · Cindy · Lody · AionUi · Cherry Studio · Ante · AstrBot · QwenPaw · OpenClaw · Avibe · Kun +Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · Dim · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · PenguinHarness · Aside · OmO · Prime Agent · mu · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · JetBrains Air · Air (JetBrains IDEs) · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Mistral Vibe · Qwen Code · Muse Code · Empryo · nanobot · miniQ · Paimon · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy · Pencil · Paseo · OpenPencil · OpenBot · Craft Agents · Tuanjie Cowork · NewMax · LiveAgent · Raycast · Kiro Crew · OpenMausBot · T3 Code · OpenHanako · AtomCode · Open Code Review · Snow CLI · Alma · Shelley · Cindy · Lody · AionUi · Cherry Studio · Ante · AstrBot · QwenPaw · OpenClaw · Avibe · Kun
diff --git a/README.zh-CN.md b/README.zh-CN.md index d0f45bc46..eb2d7e523 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -83,7 +83,7 @@ magpie 通过读取智能体的登录信息(Claude Code 和 Codex 的文件、
-Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · Dim · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · PenguinHarness · Aside · OmO · Prime Agent · mu · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · JetBrains Air · Air (JetBrains IDEs) · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Mistral Vibe · Qwen Code · Muse Code · Empryo · nanobot · miniQ · Paimon · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy · Pencil · Paseo · OpenPencil · OpenBot · Craft Agents · Tuanjie Cowork · NewMax · LiveAgent · Raycast · Kiro Crew · OpenMausBot · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Shelley · Cindy · Lody · AionUi · Cherry Studio · Ante · AstrBot · QwenPaw · OpenClaw · Avibe · Kun +Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · Dim · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · PenguinHarness · Aside · OmO · Prime Agent · mu · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · JetBrains Air · Air (JetBrains IDEs) · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Mistral Vibe · Qwen Code · Muse Code · Empryo · nanobot · miniQ · Paimon · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy · Pencil · Paseo · OpenPencil · OpenBot · Craft Agents · Tuanjie Cowork · NewMax · LiveAgent · Raycast · Kiro Crew · OpenMausBot · T3 Code · OpenHanako · AtomCode · Open Code Review · Snow CLI · Alma · Shelley · Cindy · Lody · AionUi · Cherry Studio · Ante · AstrBot · QwenPaw · OpenClaw · Avibe · Kun
diff --git a/docs/reference.md b/docs/reference.md index e0a12229b..a46b32235 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -168,6 +168,7 @@ line; agents connected to magpie lose it when it quits. | Kun | `~/.kun/data/model-connections.v2.json` (`$KUN_DATA_DIR`), changed through its runtime's admin API (`baseUrl` and `runtimeToken` of `runtime.json` in the same folder) while it runs | model (a `magpie` connection in Settings > Providers: HTTP, OpenAI chat completions at the gateway's `/v1`, with Kun's own key and the models picked for Kun; the model picked is Kun's default. Kun has to be running to connect or disconnect it) | | OpenHanako | `~/.hanako/provider-catalog.json` + `agents//config.yaml` (`$HANA_HOME`; its local API while it runs) | model (the primary agent's; magpie's models as a provider) | | AtomCode | `~/.atomcode/config.toml` (`$ATOMCODE_HOME`) | model, effort (a `magpie` provider account, one model table per catalog model as its own sign-in writes) | +| Open Code Review | `~/.opencodereview/config.json` | model (a `magpie` custom provider made the one in use; its Claude Code, Codex, Cursor, Kimi Code and OpenCode plugins run the same `ocr`) | | Snow CLI | `~/.snow/profiles/magpie.json` (`$SNOW_CONFIG_DIR`), made the active profile and copied to `config.json` | model (the user's other profiles' models too; Snow App takes the profile in with "Sync Snow CLI API config") | | Alma | Alma's local API (`localhost:23001`, while Alma runs; alma-server's data in `$ALMA_DATA_DIR`, `$XDG_DATA_HOME/alma` or `~/.local/share/alma` on Linux) | model (Alma's default; magpie's models as a provider), and Image Generation's model when it is Auto: the one magpie draws with | | Shelley | Shelley's local socket (`~/.config/shelley/shelley.sock`, `$XDG_CONFIG_HOME/shelley`, `$SHELLEY_SOCKET`; while `shelley serve` runs) | model (the default profile's; magpie's models as Shelley custom models of type `openai` at the gateway's `/v1` with Shelley's own key, one per model picked; the profile's model and thinking level are stashed and put back on Disconnect, and magpie's custom models go) | diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index a6f440d8e..0b4a175c7 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -201,6 +201,7 @@ something else shows up as drift. - Claude Magpie's Code tab can have a Claude Code folder of its own (#6459, xMopf7RF on X): `settings.DesktopIsolatedClaude`, on for a Claude Magpie made new and off for one made before. Made new is the app off and no Claude-Magpie-3p folder yet, and the user never set it (`DesktopIsolatedClaudeChosen`, which the fold and the CLI set): then `desktopIsoClaudeDefault` turns it on before the app is made, so the twin's Code tab writes nothing of `~/.claude`, like a phone's app clone. One with chats in Claude-Magpie-3p already, or one the user turned off, keeps `~/.claude`. Set under the Separate app's Advanced fold (`POST /api/settings/desktop-isolated-claude`, drawn by `claudemagpie.js`) or `magpie claude-desktop launcher claude-dir on|off`, both `SetDesktopIsolatedClaude`. While on, and the Separate app is on, the app's script exports `CLAUDE_CONFIG_DIR=~/.claude-magpie-desktop` (`desktopiso.Script`'s `claudeDir`), which Desktop passes to its bundled Claude Code, and `desktopOn` in [`claude.go`](../../internal/agent/claude.go) writes Desktop's model windows, caps and explore entries into that folder's `settings.json` instead of `~/.claude`'s (`desktopCodeDir`, `desktopClaudeSync`); off moves them back. The folder stays when it is turned off, and it is a `claude#` row named "Claude Code · Claude Magpie" (`claudeDirAgents`). A change remakes the app; a running Claude Magpie keeps the old environment until it is quit and opened again. In the Library it is an agent of its own (see [library](library.md), Claude Magpie): `DesktopTwinApp` (`claude-desktop#magpie`) takes MCP servers and Cowork skills in Claude-Magpie-3p, and the `claude#magpie-desktop` row takes instructions, skills and servers in `~/.claude-magpie-desktop`; `DesktopConfigs3p` no longer includes Claude-Magpie-3p's config. The "Use Claude Magpie" button, beside Claude Desktop's switch while it isn't on magpie (its own button there, not words in the status line, so it reads as a way that doesn't connect the user's own Desktop), turns the Separate app on and then connects Desktop (`desktopTwinBtn`, also `claudemagpie.js`), so only Claude-Magpie-3p is wired and the user's own Desktop is left as it was. It shows whenever Desktop isn't on magpie, with Claude Magpie made already too (where connecting wires only Claude-Magpie-3p, `desktopSets`, and the button also makes the app again if it was deleted; xMopf7RF on X, 0.1.4076); then the row's status line says connecting puts Claude Magpie on magpie, not that Desktop opens a separate profile. While the Separate app is on, the `claude-desktop` row is named Claude Magpie (`state()` in [`api.go`](../../internal/gui/api.go)): the only config it wires then is Claude-Magpie-3p's, so the row that turns on after Use Claude Magpie never reads Claude Desktop (xMopf7RF on X, 0.1.4111, who read it as their own Desktop being connected). The `claude#magpie-desktop` row isn't wired itself (Desktop's Code tab runs Claude Code with `CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST`, so its requests go through Claude Magpie whatever that folder's settings.json says); while Claude Magpie is on magpie it carries `twinCode` (`agent.DesktopTwinCode`) and its status line, lit, says it is on magpie through Claude Magpie, instead of "not connected, its own settings". `TestClaudeMagpieCodeTabRowIsOnThroughIt`, `TestClaudeMagpieRowsAfterUseClaudeMagpie`, `desktop-twin-code.test.cjs`, `TestClaudeDesktopIsolatedClaudeDir`, `TestClaudeMagpieTwinLeavesTheOriginal`, `TestClaudeMagpieOwnFolderKeepsWhatWasSet`, `TestScriptClaudeConfigDir`, `desktop-isolated-claude.test.cjs`, `desktop-twin.test.cjs`. - Claude Desktop names a Claude model with reasoning levels after its own catalog ("Opus 5.5"), not by the `display_name` magpie lists, because magpie lists it as `magpie-.anthropic.` to keep its effort picker (`claudeLooking` in [`desktop.go`](../../internal/gateway/desktop.go)). Desktop 4.4212 labels a picker row by its catalog's name before `display_name` (only an admin's `inferenceModels` list carries the `labelOverride` that beats it), so two providers' rows of one model read alike and Desktop adds the part of the id that differs, "Opus 5.5 (…7922287072.anthropic.claude-opus-5-5)", in 5.11492 "(….anthropic.claude-opu…)" (onkashiko on X). magpie therefore writes the list, with each row's `display_name` as `labelOverride`, while a tier is picked and also while two rows are named after the same Claude model of Desktop's catalog (`desktopNamesClash`, `desktopCatalogNamed` in [`desktop_list.go`](../../internal/gateway/desktop_list.go)); Desktop leaves a `labelOverride` as it is (`keep` in xVn, 5.11492), so those rows read "Opus 5.5 · agy-cli" after Desktop restarts (`TestDesktopInferenceModelsCatalogNamesClash`). Such a list freezes Desktop's menu until its next start, as a tier's does. Two rows that `display_name` still leaves alike (one provider's models named alike) get the model's own id after the name, or the whole catalog id when two providers share a name (`desktopNames`, `TestDesktopNames`). Desktop shows the gateway's `description` under the name, before the catalog's, so such a row's description names its provider when the Provider in model names setting puts it after the name (`desktopSaidBy`: on, every one; off, only two of one name), and a 1M row listed by its `[1m]` id says "1M context window · " (4 v5 on Discord, `TestClaudeDesktopCatalogNamedSaysProvider`). The id stays as it was. The provider editor shows the number too on the model's chip (`gateway.DesktopNumber`, `desktopNumbers` in [`providers.go`](../../internal/gui/providers.go), #2578). The chip shows it only while Claude Desktop is installed and is shown that model. Every other model Desktop is shown carries no number on the chip: Desktop names it by `display_name`, which already says the provider, or by its own id. - Codex's `spawn_agent` tool names only the first five models of its catalog to the lead (codex-rs `MAX_SPAWN_AGENT_MODEL_OVERRIDES` in `child_config.rs`, `spawn_agent_models_description`), Codex's own ahead of magpie's, though it takes any catalog model by name (`find_spawn_agent_model_name`). So a lead could put its subagents on none of magpie's models (Gearclickist on Discord). The gateway adds the rest of the catalog Codex was handed to that tool's description, after Codex's own list, at most 200 (`spawnAgentModels` in [`codex_spawn_models.go`](../../internal/gateway/codex_spawn_models.go)). A model that can search tools (`supports_search_tool`) isn't handed it in the request's tools: Codex defers its multi-agent V1 tools behind `tool_search` (codex-rs `core/src/tools/spec_plan.rs`), and the lead gets `spawn_agent` in the `tool_search_output` Codex puts in the conversation and sends again every turn, so that one is widened too. That text goes upstream with the prompt, to OpenAI too for a ChatGPT lead, so its header (`spawnMore`) stays neutral: it names neither magpie nor Codex's limit. At `CodexPath` that is Codex's own listed models less the hidden ones, then `CodexListed` unless Codex is held to its own. At `/v1` it is `CodexCatalog` under the key's allowance. A lead the ChatGPT backend answers in multi-agent V2 seals its subagents' tasks for a ChatGPT account (#619), so it gets Codex's own only. The model catalog Codex puts in context under `model_catalog_in_context` (under development, off by default) is capped at five too, and isn't widened. +- Open Code Review (`ocr`) reads `~/.opencodereview/config.json` on every run; `provider` names an entry of `providers` (its presets) or `custom_providers`, and the entry's own `model` wins over the top-level one ([`ocr.go`](../../internal/agent/ocr.go)). magpie writes the custom provider `magpie` (openai protocol, the gateway's `/v1`, a key naming the agent, the model) and points `provider` at it; the provider and model the user had are stashed and come back on Disconnect. Its Claude Code, Codex, Cursor, Kimi Code and OpenCode plugins all run this `ocr`, so they follow it. `ocr` is other programs' name too: only one under a folder named for it counts (`ocrNotOurs`), else `~/.opencodereview` says it is there. - Snow CLI runs on one profile at a time (`profiles/.json` in `~/.snow` or `$SNOW_CONFIG_DIR`, named in `active-profile.json`) and copies the active one over `config.json` at every start, `snow --ask` too ([`snow.go`](../../internal/agent/snow.go)). magpie writes a `magpie` profile, makes it the active one, and copies it to `config.json` itself, so a Snow already running and Snow App's "Sync Snow CLI API config" see the same. It is made from the profile the user was on, their settings kept and its OAuth sign-in left out. A vision model of that profile comes along only with an endpoint and key of its own (`snowOwnVision`), since one on the profile's would now go to the gateway. `maxContextTokens`, `maxTokens` and `supportsVision` follow the model from the catalog (`snowSynced`; `supportsVision` as every agent is told, true while magpie's Vision describes images); what magpie last wrote of them is stashed, and one the user changed since in Snow's own settings is kept through later picks and syncs. The small field is magpie's profile's `basicModel`, Snow's light model for summaries, compaction and file search: empty while it follows the main model, a model through magpie of its own kept through new main models and syncs; on a profile of the user's it offers nothing and is hidden. The thinking field is magpie's profile's `chatThinking` (`{enabled: true, reasoning_effort}`), the only thinking setting Snow reads on the chat protocol; empty deletes it, Snow's default, which sends thinking disabled. A chatThinking the user brought from their profile is shown, not written over. The profile they were on (or that there was no `active-profile.json`) and a `magpie.json` of their own are stashed and put back by Disconnect. A Snow from before profiles (`config.json` alone) gets the `default.json` Snow itself would have made of it, so its next start doesn't take magpie's for the user's. Picking a model of another of the user's profiles switches Snow to that profile. On magpie's profile, a value that is neither a model through magpie nor the model of one of the user's profiles is refused and changes nothing (#1457: `magpie snow --help` used to take magpie out and write `--help` as the model of the profile it went back to). Gemini CLI's auth field refuses an auth it doesn't know before it unroutes, for the same reason. On the CLI, `-h`/`--help` after any command or agent only prints its usage, before `run` reads or moves anything, and any other flag given to `magpie …` is refused (`help_cli.go`; `TestHelpOnEveryCommandDoesNothing` walks `run`'s switch and every agent). - omp's `enabledModels` in `config.yml` is the list it holds its default role to: a model left out of it isn't used, whatever `modelRoles.default` says (#1769). So a model picked for the default role is added to a list that is there and doesn't take it in already, by name or by one of omp's globs (`*` not crossing `/`, as `Bun.Glob`), and once nothing in `config.yml` is on magpie its plain `magpie/…` entries are taken out (a list left empty goes, never `[]`); a renamed provider's entries are renamed once, and folder-scoped entries are left alone (`ompScope*` in [`omp_scope.go`](../../internal/agent/omp_scope.go)). No list, no change: omp then takes every model. A list that leaves the default role's model out is drift, which Reapply mends. - Pi's `enabledModels` in `settings.json` (and OmO's, Prime Agent's and mu's, `piLike`) is the Ctrl+P list a new session starts from. A picked model the list doesn't take in is added (`piScopeWith` in [`pi.go`](../../internal/agent/pi.go)), and a renamed provider's `magpie//` entries are renamed with it, a glob or a thinking level included, the copy the pick just added dropped (`renameRefList` in [`rename.go`](../../internal/agent/rename.go), #1919, `TestPiEnabledModelsFollowRename`). The user's other entries stay; a list naming none of the provider's models isn't rewritten. diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 4aa99a45c..a4c460de7 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -396,6 +396,7 @@ func onMachineAll(home, cfg string) []*Agent { kun(home), hanako(home), atomcode(home), + ocr(home), snow(home), alma(), shelley(home), diff --git a/internal/agent/cliupdate.go b/internal/agent/cliupdate.go index b943aa847..f34e215f1 100644 --- a/internal/agent/cliupdate.go +++ b/internal/agent/cliupdate.go @@ -227,6 +227,8 @@ var cliSpecs = map[string]cliSpec{ // exists, but its installed-binary update path is not exercised here, so // only its npm package and brew cask are recognized "atomcode": {npm: []string{"@atomgit.com/atomcode"}, brew: []string{"atomcode"}}, + // Open Code Review: npm, or its install script's /usr/local/bin/ocr + "open-code-review": {npm: []string{"@alibaba-group/open-code-review"}}, // Snow CLI is published on npm alone (snow-ai) "snow": {npm: []string{"snow-ai"}, scripts: true}, // MothX: its npm installer package, which brings the native binary diff --git a/internal/agent/handwired_test.go b/internal/agent/handwired_test.go index 376c1eafa..0dc0a4701 100644 --- a/internal/agent/handwired_test.go +++ b/internal/agent/handwired_test.go @@ -140,7 +140,7 @@ func TestPiConnectedBeforeStaysConnected(t *testing.T) { func TestHandWiredMagpieProviderSiblings(t *testing.T) { ids := []string{"agy", "opencode", "openchamber", "mimocode", "deveco", "pi", "aside", "omo", "prime-agent", "mu", "goose", "zed", "vscode", "crush", "dsh", "ds-bot", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "nanobot", "miniq", "paimon", "craft-agents", "minimax-code", "droid", - "qoder", "qoder-cn", "grok", "atomcode", "cline", "snow", "tuanjie-cowork"} + "qoder", "qoder-cn", "grok", "atomcode", "cline", "snow", "tuanjie-cowork", "open-code-review"} for _, id := range ids { t.Run(id, func(t *testing.T) { if id == "aside" { diff --git a/internal/agent/ocr.go b/internal/agent/ocr.go new file mode 100644 index 000000000..aef6bdeee --- /dev/null +++ b/internal/agent/ocr.go @@ -0,0 +1,249 @@ +package agent + +// 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 plugins for Claude Code, Codex, Cursor, Kimi Code +// and OpenCode, and its skills, all run that same command. It keeps its +// settings in ~/.opencodereview/config.json (os.UserHomeDir, no variable +// moves it): `provider` names the entry in use, from `providers` (its +// presets: anthropic, openai, deepseek, …) or `custom_providers` (any +// other name), and `model` the model, the entry's own `model` winning +// (internal/llm/resolver.go tryProviderConfig). A custom entry needs a +// protocol, a url and a key of its own: no variable stands in for it. +// +// magpie adds the custom provider "magpie": the openai protocol, which +// posts Chat Completions to url + "/chat/completions", the gateway's /v1, +// a key naming Open Code Review, and the model picked, which goes to the +// gateway as it is, for it to resolve. provider is pointed at it; the +// provider and model the user had are stashed and put back when magpie +// steps out. Requests carry a User-Agent of open-code-review/, +// which the gateway counts as this agent's. ocr reads the file on every +// run, so a change needs no restart. + +import ( + "fmt" + "path/filepath" + "sort" + "strings" + + "github.com/tidwall/gjson" + + "github.com/yetone/magpie/internal/edit" +) + +const ocrID = "open-code-review" + +// ocrEntry is the key path of magpie's custom provider in config.json. +var ocrEntry = "custom_providers." + magpieID + +func ocr(home string) *Agent { return ocrIn(here(home)) } + +// ocrIn is Open Code Review at a place. +func ocrIn(at place) *Agent { + dir := at.join(".opencodereview") + path := filepath.Join(dir, "config.json") + key := ocrID + ":" + path + get := func(k string) string { v, _ := edit.GetJSON(path, k); return v } + // section is where OCR keeps the entry of a provider of the user's + // own: "providers" or "custom_providers"; "" when it has none. + section := func(p string) string { + for _, s := range []string{"providers", "custom_providers"} { + if r, ok := edit.GetJSONRaw(path, s+"."+gjson.Escape(p)); ok && strings.HasPrefix(strings.TrimSpace(r), "{") { + return s + } + } + return "" + } + // model is the model OCR sends for provider p: its entry's, which + // wins, else the top-level one. + model := func(p string) string { + if s := section(p); s != "" { + if m := get(s + "." + gjson.Escape(p) + ".model"); m != "" { + return m + } + } + return get("model") + } + cur := func() string { + p := get("provider") + if p == "" { + return "" + } + m := model(p) + if m == "" { + return p + } + return p + "/" + m + } + writeMagpie := func(ref string) error { + kvs := []edit.KV{ + {Path: ocrEntry + ".protocol", Value: "openai"}, + {Path: ocrEntry + ".url", Value: at.v1()}, + {Path: ocrEntry + ".api_key", Value: agentKeyAt(ocrID, at.gw())}, + } + if ref != "" { + kvs = append(kvs, edit.KV{Path: ocrEntry + ".model", Value: ref}) + } + return edit.SetJSON(path, kvs...) + } + // setOwn makes provider/model of the user's own the one in use, as + // `ocr config model` does: the top-level model and the entry's. + setOwn := func(v string) error { + p, m, _ := strings.Cut(v, "/") + s := section(p) + if p == magpieID || s == "" { + return fmt.Errorf("Open Code Review has no provider %q set up; add it with `ocr config provider` first", p) + } + kvs := []edit.KV{{Path: "provider", Value: p}} + if m != "" { + kvs = append(kvs, edit.KV{Path: "model", Value: m}, edit.KV{Path: s + "." + gjson.Escape(p) + ".model", Value: m}) + } + return edit.SetJSON(path, kvs...) + } + leave := func() error { + forget(key+":provider", key+":model") + if err := edit.DelJSON(path, ocrEntry); err != nil { + return err + } + // custom_providers made for magpie's alone goes with it + if r, ok := edit.GetJSONRaw(path, "custom_providers"); ok && strings.Join(strings.Fields(r), "") == "{}" { + return edit.DelJSON(path, "custom_providers") + } + return nil + } + return atomic(&Agent{ + ID: ocrID, Name: "Open Code Review", Icon: ocrID, Spelled: prefixed, NoNames: true, + UA: []string{ocrID}, + // `ocr` is other programs' name too: only one under a folder + // named for it (npm's) is taken for it; one the install script put + // in /usr/local/bin is known by its folder + Bin: "ocr", binNot: ocrNotOurs, + Dir: dir, Path: path, + Sync: func() error { + if _, ok := edit.GetJSONRaw(path, ocrEntry); !ok { + return nil + } + return writeMagpie("") + }, + Check: func() string { + if get("provider") != magpieID { + return "" + } + if _, ok := edit.GetJSONRaw(path, ocrEntry); !ok { + return "Open Code Review's " + ocrEntry + " (config.json) is gone, so it no longer reaches magpie" + } + return wiringOff("Open Code Review", path, func(f string) (string, bool) { return edit.GetJSON(path, ocrEntry+"."+f) }, + "url", at.v1(), "api_key", agentKeyAt(ocrID, at.gw())) + }, + Fields: []Field{{ + Key: "model", Label: "model", + Get: func() string { + if get("provider") != magpieID { + return cur() + } + m := get(ocrEntry + ".model") + if m == "" { + m = get("model") + } + return magpieID + "/" + m + }, + Set: func(v string) error { + onMagpie := get("provider") == magpieID + if ref, ok := strings.CutPrefix(v, magpieID+"/"); ok && isMagpie(ref) { + if !onMagpie { + stash(map[string]string{ + key + ":provider": get("provider"), + key + ":model": get("model"), + }) + } + if err := writeMagpie(ref); err != nil { + return err + } + return edit.SetJSON(path, edit.KV{Path: "provider", Value: magpieID}) + } + if v != "" { + if err := setOwn(v); err != nil { + return err + } + if onMagpie { + return leave() + } + return nil + } + if !onMagpie { + return edit.DelJSON(path, "provider", "model") + } + // magpie was in use: the provider and model the user had + // come back, where OCR still has the provider + saved := stashLoad() + p, m := saved[key+":provider"], saved[key+":model"] + if p != "" && p != magpieID && section(p) != "" { + if err := edit.SetJSON(path, edit.KV{Path: "provider", Value: p}); err != nil { + return err + } + } else if err := edit.DelJSON(path, "provider"); err != nil { + return err + } + if m != "" { + if err := edit.SetJSON(path, edit.KV{Path: "model", Value: m}); err != nil { + return err + } + } else if err := edit.DelJSON(path, "model"); err != nil { + return err + } + return leave() + }, + Options: func(c map[string]string) []Option { + return withVia(ocrOwnModels(path, c["model"]), ocrID, magpieID+"/") + }, + }}, + }) +} + +// ocrNotOurs turns away an `ocr` command that isn't Open Code Review's: +// one under no folder named for it. +func ocrNotOurs(bin string) bool { + for _, p := range []string{bin, evalLink(bin)} { + s := strings.ToLower(filepath.ToSlash(p)) + if strings.Contains(s, "open-code-review") || strings.Contains(s, "opencodereview") { + return false + } + } + return true +} + +// ocrOwnModels is the provider/model pairs OCR's config.json sets up of +// the user's own: each entry's model and models, and the one in use. +func ocrOwnModels(path, cur string) []Option { + seen := map[string]bool{} + var vals []string + add := func(v string) { + if v == "" || seen[v] || strings.HasPrefix(v, magpieID+"/") || v == magpieID { + return + } + seen[v] = true + vals = append(vals, v) + } + add(cur) + if raw, err := edit.Read(path); err == nil { + for _, s := range []string{"providers", "custom_providers"} { + gjson.GetBytes(raw, gjson.Escape(s)).ForEach(func(k, e gjson.Result) bool { + p := k.String() + if p == magpieID || !e.IsObject() { + return true + } + if m := e.Get("model").String(); m != "" { + add(p + "/" + m) + } + for _, m := range e.Get("models").Array() { + if m.String() != "" { + add(p + "/" + m.String()) + } + } + return true + }) + } + } + sort.Strings(vals) + return static(vals...) +} diff --git a/internal/agent/ocr_test.go b/internal/agent/ocr_test.go new file mode 100644 index 000000000..8d00da2c3 --- /dev/null +++ b/internal/agent/ocr_test.go @@ -0,0 +1,175 @@ +package agent + +import ( + "os" + "path/filepath" + "slices" + "testing" + + "github.com/yetone/magpie/internal/edit" + "github.com/yetone/magpie/internal/gateway" + "github.com/yetone/magpie/internal/provider" +) + +// ocrOwnConfig is a config.json as `ocr config provider` writes one: a +// preset of the user's on a model of its own, and a setting beside it. +const ocrOwnConfig = `{ + "provider": "anthropic", + "model": "claude-sonnet-4-6", + "language": "zh", + "providers": { + "anthropic": {"api_key": "sk-ant-own", "model": "claude-sonnet-4-6"} + } +} +` + +// Picking a model of magpie's for Open Code Review writes the custom +// provider "magpie" (openai protocol, the gateway's /v1, a key naming +// it, the model) and points provider at it; going back puts the user's +// own provider and model back and takes magpie's entry out. +func TestOCRWiring(t *testing.T) { + syncHome(t) + if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2"}}); err != nil { + t.Fatal(err) + } + a, err := Find(ocrID) + if err != nil { + t.Fatal(err) + } + path := a.Path + if filepath.Base(filepath.Dir(path)) != ".opencodereview" || filepath.Base(path) != "config.json" { + t.Fatalf("path %s", path) + } + hanakoWrite(t, path, ocrOwnConfig, 0o600) + if !a.Detected() { + t.Fatal("~/.opencodereview doesn't count as Open Code Review there") + } + if v := a.Field("model").Get(); v != "anthropic/claude-sonnet-4-6" { + t.Fatalf("own model reads %q", v) + } + if a.Wired() { + t.Fatal("the user's own anthropic reads as magpie's") + } + opts := a.Field("model").Options(a.Values()) + if !slices.ContainsFunc(opts, func(o Option) bool { return o.Value == "anthropic/claude-sonnet-4-6" }) || + !slices.ContainsFunc(opts, func(o Option) bool { return o.Value == "magpie/fake/m1" }) { + t.Fatalf("options: %+v", opts) + } + + if err := a.Apply("model", "magpie/fake/m1"); err != nil { + t.Fatal(err) + } + for k, want := range map[string]string{ + "provider": "magpie", + "custom_providers.magpie.protocol": "openai", + "custom_providers.magpie.url": gatewayV1(), + "custom_providers.magpie.api_key": gateway.TokenFor(ocrID), + "custom_providers.magpie.model": "fake/m1", + "language": "zh", + "providers.anthropic.api_key": "sk-ant-own", + } { + if v, _ := edit.GetJSON(path, k); v != want { + b, _ := os.ReadFile(path) + t.Fatalf("%s = %q, want %q in:\n%s", k, v, want, b) + } + } + if v := a.Field("model").Get(); v != "magpie/fake/m1" { + t.Fatalf("model reads %q", v) + } + if !a.Wired() { + t.Fatalf("not connected after a pick: %v", a.Values()) + } + if d := a.Drift(); d != nil { + t.Fatalf("drift right after a set: %+v", d) + } + // another of magpie's models: the stash keeps the user's, not magpie's + if err := a.Apply("model", "magpie/fake/m2"); err != nil { + t.Fatal(err) + } + if v, _ := edit.GetJSON(path, "custom_providers.magpie.model"); v != "fake/m2" { + t.Fatalf("model %q", v) + } + + // the url changed by hand: magpie says so + if err := edit.SetJSON(path, edit.KV{Path: "custom_providers.magpie.url", Value: "http://127.0.0.1:1/v1"}); err != nil { + t.Fatal(err) + } + if d := a.Drift(); d == nil { + t.Fatal("a url that no longer reaches the gateway reads as fine") + } + if err := a.Apply("model", "magpie/fake/m2"); err != nil { + t.Fatal(err) + } + + if err := a.Disconnect(); err != nil { + t.Fatal(err) + } + for k, want := range map[string]string{ + "provider": "anthropic", + "model": "claude-sonnet-4-6", + "language": "zh", + } { + if v, _ := edit.GetJSON(path, k); v != want { + b, _ := os.ReadFile(path) + t.Fatalf("after Disconnect %s = %q, want %q in:\n%s", k, v, want, b) + } + } + if _, ok := edit.GetJSONRaw(path, "custom_providers"); ok { + b, _ := os.ReadFile(path) + t.Fatalf("magpie's entry, or the custom_providers made for it, left behind:\n%s", b) + } + if a.Wired() { + t.Fatal("still connected after Disconnect") + } +} + +// A model of the user's own picked while on magpie goes the way `ocr +// config model` writes it, and magpie's entry goes; a provider OCR hasn't +// set up is turned away rather than written as one it can't reach. +func TestOCROwnPick(t *testing.T) { + syncHome(t) + if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1"}}); err != nil { + t.Fatal(err) + } + a, err := Find(ocrID) + if err != nil { + t.Fatal(err) + } + hanakoWrite(t, a.Path, ocrOwnConfig, 0o600) + if err := a.Apply("model", "magpie/fake/m1"); err != nil { + t.Fatal(err) + } + if err := a.Apply("model", "anthropic/claude-opus-4-6"); err != nil { + t.Fatal(err) + } + for k, want := range map[string]string{ + "provider": "anthropic", + "model": "claude-opus-4-6", + "providers.anthropic.model": "claude-opus-4-6", + } { + if v, _ := edit.GetJSON(a.Path, k); v != want { + t.Fatalf("%s = %q, want %q", k, v, want) + } + } + if _, ok := edit.GetJSONRaw(a.Path, "custom_providers.magpie"); ok { + t.Fatal("magpie's entry left behind") + } + if err := a.Apply("model", "nowhere/x"); err == nil { + t.Fatal("a provider OCR hasn't set up was written") + } +} + +// `ocr` names other programs too: only one under a folder named for Open +// Code Review is its. +func TestOCRNotOurs(t *testing.T) { + for bin, ours := range map[string]bool{ + "/usr/local/lib/node_modules/@alibaba-group/open-code-review/bin/ocr": true, + "/home/u/.opencodereview/bin/ocr": true, + "/usr/bin/ocr": false, + "/opt/homebrew/bin/ocr": false, + } { + if got := !ocrNotOurs(bin); got != ours { + t.Errorf("%s: ours %v, want %v", bin, got, ours) + } + } +} diff --git a/internal/agent/spelled_test.go b/internal/agent/spelled_test.go index bfddfdb87..9996f70ec 100644 --- a/internal/agent/spelled_test.go +++ b/internal/agent/spelled_test.go @@ -14,7 +14,7 @@ import ( func TestOwnProviderNamedAsMagpies(t *testing.T) { ids := []string{"agy", "opencode", "openchamber", "mimocode", "deveco", "pi", "aside", "omo", "prime-agent", "mu", "goose", "zed", "vscode", "crush", "dsh", "ds-bot", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "nanobot", "miniq", "paimon", "craft-agents", "minimax-code", "droid", - "qoder", "qoder-cn", "grok", "atomcode", "cline", "snow", "qwenpaw"} + "qoder", "qoder-cn", "grok", "atomcode", "cline", "snow", "qwenpaw", "open-code-review"} for _, id := range ids { t.Run(id, func(t *testing.T) { if id == "aside" { @@ -35,6 +35,11 @@ func TestOwnProviderNamedAsMagpies(t *testing.T) { // Craft's own config, with a connection of the user's hanakoWrite(t, a.Path, craftUser, 0o644) } + if id == "open-code-review" { + // a custom provider of the user's own, for its own model + // to be on + hanakoWrite(t, a.Path, `{"custom_providers":{"relay":{"protocol":"openai","url":"https://relay.example/v1","api_key":"sk-own"}}}`, 0o600) + } if id == "cline" { // a model of OpenRouter's, the provider Cline is on hanakoWrite(t, a.Path, `{"version":1,"modes":{},"providers":{},"lastUsedProvider":"openrouter"}`, 0o600) diff --git a/internal/agent/useragent_test.go b/internal/agent/useragent_test.go index dd85ae17a..e545ed0b7 100644 --- a/internal/agent/useragent_test.go +++ b/internal/agent/useragent_test.go @@ -27,6 +27,8 @@ func TestAgentOf(t *testing.T) { "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", diff --git a/internal/agent/wsl.go b/internal/agent/wsl.go index a346962f5..d1d3b0522 100644 --- a/internal/agent/wsl.go +++ b/internal/agent/wsl.go @@ -757,6 +757,11 @@ var wslKinds = []wslKind{ return withVia(atomcodeOwnModels("", cur["model"]), "atomcode", magpieID+"/") } }}, + // Open Code Review's ~/.opencodereview: no bin, as `ocr` is other + // programs' name too; ocr reads its config on every run. A stopped + // distro's config.json is looked at once it is started + {id: ocrID, name: "Open Code Review", dir: ".opencodereview", in: ocrIn, + asleep: wslOwnAsleep(ocrID, "model")}, // Snow CLI's ~/.snow, its profiles the distro's own; a stopped // distro's are looked at once it is started {id: "snow", name: "Snow CLI", dir: ".snow", bin: "snow", in: snowIn, diff --git a/internal/agent/wsl_more_test.go b/internal/agent/wsl_more_test.go index bee26609b..0b980fc6d 100644 --- a/internal/agent/wsl_more_test.go +++ b/internal/agent/wsl_more_test.go @@ -39,6 +39,7 @@ var wslMore = []struct { {"codebuddy", ".codebuddy/models.json", "/v1/chat/completions"}, {"cline", ".cline/data/settings/providers.json", "/v1"}, {"atomcode", ".atomcode/config.toml", "/v1"}, + {"open-code-review", ".opencodereview/config.json", "/v1"}, {"snow", ".snow/profiles/magpie.json", "/v1"}, {"goose", ".config/goose/custom_providers/magpie.json", "/v1"}, {"mothx", ".mothx/settings.json", "/v1"}, diff --git a/internal/gui/assets/icons/open-code-review.svg b/internal/gui/assets/icons/open-code-review.svg new file mode 100644 index 000000000..52b0b6baa --- /dev/null +++ b/internal/gui/assets/icons/open-code-review.svg @@ -0,0 +1 @@ + diff --git a/site/public/docs/ja/start.html b/site/public/docs/ja/start.html index 8a5612db3..c2b6f7ee4 100644 --- a/site/public/docs/ja/start.html +++ b/site/public/docs/ja/start.html @@ -209,6 +209,7 @@ Claude Code~/.claude/settings.json:env ブロック内の ANTHROPIC_BASE_URL、ANTHROPIC_AUTH_TOKEN とモデル関連の変数 Codex~/.codex/config.toml:[model_providers.magpie] テーブルとモデル、一覧は magpie-models.json。ChatGPT のサインインには手を加えません OpenCode、MiMo Code、DevEco Code、Pi、Crushmagpie プロバイダのエントリと magpie/provider/model + Open Code Review~/.opencodereview/config.json:magpie カスタムプロバイダを追加し、ocr が使うものに設定 AtomCode~/.atomcode/config.toml:magpie プロバイダアカウントと、カタログ内の各モデルのエントリ Snow CLI~/.snow/profiles/magpie.json:magpie プロファイルを作り、使用中のプロファイルにする(Snow App は「Sync Snow CLI API config」で取り込む) QwenPaw~/.qwenpaw.secret/providers/custom/magpie.json の magpie プロバイダーと、各エージェントの agent.json の active_model。初回の接続後に QwenPaw を再起動 diff --git a/site/public/docs/start.html b/site/public/docs/start.html index 9a45f7974..b448fe3f1 100644 --- a/site/public/docs/start.html +++ b/site/public/docs/start.html @@ -209,6 +209,7 @@ Claude Code~/.claude/settings.json: ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN and the model variables in its env block Codex~/.codex/config.toml: a [model_providers.magpie] table and the model, with the list in magpie-models.json. Your ChatGPT sign-in is left alone OpenCode, MiMo Code, DevEco Code, Pi, CrushA magpie provider entry, and magpie/provider/model + Open Code Review~/.opencodereview/config.json: a magpie custom provider, made the one ocr uses AtomCode~/.atomcode/config.toml: a magpie provider account and one model entry per catalog model Snow CLI~/.snow/profiles/magpie.json: a magpie profile, made the active one (Snow App takes it in with "Sync Snow CLI API config") QwenPawA magpie provider in ~/.qwenpaw.secret/providers/custom/magpie.json, and each agent's active_model in its agent.json. Restart QwenPaw after the first connect diff --git a/site/public/docs/zh/start.html b/site/public/docs/zh/start.html index 114a5c587..99dc9a91f 100644 --- a/site/public/docs/zh/start.html +++ b/site/public/docs/zh/start.html @@ -209,6 +209,7 @@ Claude Code~/.claude/settings.json:env 里的 ANTHROPIC_BASE_URL、ANTHROPIC_AUTH_TOKEN 和模型变量 Codex~/.codex/config.toml:一个 [model_providers.magpie] 表和模型,模型列表写在 magpie-models.json。你的 ChatGPT 登录不受影响 OpenCode、MiMo Code、DevEco Code、Pi、Crush一个 magpie 供应商条目,以及 magpie/provider/model + Open Code Review~/.opencodereview/config.json:一个 magpie 自定义供应商,设为 ocr 使用的那个 AtomCode~/.atomcode/config.toml:一个 magpie 供应商账号,以及目录中每个模型各自的条目 Snow CLI~/.snow/profiles/magpie.json:一个 magpie 配置文件,并设为当前配置(Snow App 用“同步 Snow CLI API 配置”导入) QwenPaw~/.qwenpaw.secret/providers/custom/magpie.json 中的 magpie 提供商,以及每个智能体 agent.json 里的 active_model。首次连接后需重启 QwenPaw diff --git a/site/public/icons/open-code-review.svg b/site/public/icons/open-code-review.svg new file mode 100644 index 000000000..52b0b6baa --- /dev/null +++ b/site/public/icons/open-code-review.svg @@ -0,0 +1 @@ + diff --git a/site/public/index.html b/site/public/index.html index bc1619432..7df021e76 100644 --- a/site/public/index.html +++ b/site/public/index.html @@ -539,6 +539,7 @@ footer a:hover { color: var(--ink); }
  • ZCode
  • OpenHanako
  • AtomCode
  • +
  • Open Code Review
  • Snow CLI
  • QwenPaw
  • Alma