From a15e576564cb90d4d027e8b8cb7821472de0a3fc Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 16 Oct 2026 11:43:51 +0800 Subject: [PATCH] agent: OpenPencil uses magpie's models (@JC_be_better on X) OpenPencil (ZSeven-W/openpencil, the openpencil-desktop app) keeps the builtin agents its chat runs on in settings.json under Rust's dirs::config_dir()/openpencil (read from its settings_io.rs and settings_payload.rs). magpie adds one builtin_agents entry, id "magpie", kind openai-compat at the gateway's /v1 with the magpie-openpencil key, preset custom, the picked models as OpenPencil writes a list: the first as `model`, `models` only for two or more, at most 64. The user's other entries and settings stay, and so do the display_name and enabled they give magpie's entry; a sync with nothing to change doesn't write. A file magpie makes gets "version": 1 (OpenPencil sets a file without it aside as corrupt); a file with another version, or none, is left alone. Disconnect takes the entry out, and the file when nothing else is left. OpenPencil reads the file once at start and writes it all back when it quits, so a change is refused while openpencil-desktop runs (Windows can't be asked, so the notice says to quit it first). Notice translated in zh-CN, zh-TW, ja and de. README (en, zh-CN), docs/reference.md and docs/subsystems/agent-wiring.md list it. open-pencil/open-pencil, the other app of the name, keeps its providers in its webview's localStorage, so it gets no row. Run, under a scratchpad HOME with GOCACHE/GOMODCACHE pinned: - go test -p 2 -tags nogui -count=1 -timeout 45m ./...: ok, 66 packages ok, 18 with no test files - gofmt -l: clean; GOOS=linux and GOOS=windows go vet -tags nogui ./...: clean - go test ./internal/agent -run '^TestOpenPencil': ok - node --test agent-notice-lang, i18n-keys, header-relang (Chromium and WebKit, every language, wide and narrow): 37/37 pass Broken by hand, each went red: the running check, the 64 cap, the version check, keeping the user's display_name, the no-op sync, and writing the version into a new file. Real use: OpenPencil v0.8.4 (latest release, arm64, sha256 checked against its SHA256SUMS) under a sandbox HOME, started on a settings.json magpie wrote with the user's own Anthropic entry beside it. It started and ran 15s with the file intact and no .corrupt copy. v0.8.4 has no `models` field, so it lists only the first magpie model; main lists them all. Not tried: a chat request through OpenPencil's UI; its exit save (it didn't quit on an AppleEvent and was stopped with TERM, so the write-back wasn't seen); Linux and Windows; a build of OpenPencil's main. --- README.md | 2 +- README.zh-CN.md | 2 +- docs/reference.md | 1 + docs/subsystems/agent-wiring.md | 2 + internal/agent/agents.go | 1 + internal/agent/gatewaykey_test.go | 23 +- internal/agent/lists_models_test.go | 2 +- internal/agent/openpencil.go | 315 ++++++++++++++++++++++ internal/agent/openpencil_test.go | 393 ++++++++++++++++++++++++++++ internal/gui/assets/i18n.js | 5 + 10 files changed, 732 insertions(+), 14 deletions(-) create mode 100644 internal/agent/openpencil.go create mode 100644 internal/agent/openpencil_test.go diff --git a/README.md b/README.md index ab77404d2..885411ffd 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,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 · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · Raycast · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · Ante · AstrBot +Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · OpenPencil · Raycast · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · Ante · AstrBot
diff --git a/README.zh-CN.md b/README.zh-CN.md index 2133a8653..5a80550d7 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -75,7 +75,7 @@ magpie 通过读取智能体的登录信息(Claude Code 和 Codex 的文件、
-Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · Raycast · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · Ante · AstrBot +Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy Code · Pencil · OpenPencil · Raycast · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · Ante · AstrBot
diff --git a/docs/reference.md b/docs/reference.md index e4487878c..428ba9b39 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -140,6 +140,7 @@ line; agents connected to magpie lose it when it quits. | WorkBuddy AI | `~/.workbuddy-ai/models.json` (the international build) | provider (magpie's models in WorkBuddy AI's picker) | | CodeBuddy Code | `~/.codebuddy/models.json` (`$CODEBUDDY_CONFIG_DIR`), `settings.json` | model (magpie's models in its list; the session model) | | Raycast | `~/.config/raycast/ai/providers.yaml` in the user's folder, on Mac and Windows | provider (a `magpie` entry in Raycast AI's Custom Providers, magpie's models in its model picker; Raycast Pro; the user's providers, `tools` and comments kept) | +| OpenPencil | `openpencil/settings.json` in the config folder: `~/Library/Application Support` (macOS), `$XDG_CONFIG_HOME` or `~/.config` (Linux), `%APPDATA%` (Windows) | provider (a `magpie` entry in its `builtin_agents`, magpie's models in its chat's model picker; the user's entries and settings kept; refused while OpenPencil runs, as it writes the file back when it quits) | | T3 Code | `~/.t3/userdata/settings.json` (`$T3CODE_HOME/userdata`) | provider (a `magpie` provider instance on Claude Code, magpie's models as its custom models) | | 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) | diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 656c1e11d..82cf2e545 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -60,6 +60,7 @@ something else shows up as drift. - AstrBot keeps its providers in `data/cmd_config.json` under its root (`$ASTRBOT_ROOT`, else `~/.astrbot`, the desktop app's, else `~/astrbot`), written with a UTF-8 BOM, which magpie keeps (`astrbot` in [`astrbot.go`](../../internal/agent/astrbot.go)). magpie adds a `magpie` entry to `provider_sources` and one `magpie/` entry per model to `provider`, keeps the user's own entries byte for byte and keeps what the user changes in magpie's (timeout, proxy, enable), and sets the default chat model (`agent_runner.config.model.provider_id`, or `provider_settings.default_provider_id` before the agent runner), putting back what it found there. A pick the user makes while magpie is wired is theirs and stands. The first connect copies the file to `cmd_config.json.before-magpie`. AstrBot reads the file only at start-up and its WebUI writes it back whole on save, so the agent's notice says to restart AstrBot before saving in the WebUI. A Docker install's root is inside its container, which magpie doesn't reach. - jcode keeps its settings in `config.toml` in `$JCODE_HOME`, else `~/.jcode` (`jcode` in [`jcode.go`](../../internal/agent/jcode.go)). magpie adds a named profile, `[providers.magpie]`, as `jcode provider add` writes one: `type = "openai-compatible"`, the gateway's `/v1`, an inline `api_key` naming jcode (jcode sends nothing else that tells it apart) and `requires_api_key = true`, since jcode sends no key to a loopback URL without it. Its `models` list has one entry per model, with `context_window`, `input` and `reasoning` for a model with effort levels. A `reasoning_effort` the user set on one stays while the model has that level. The model jcode starts on is `[provider] default_provider = "magpie"` and `default_model`. What was there is stashed and put back on Disconnect. A model of jcode's own picked while it is on magpie takes magpie out. Each key is set alone, so the user's other keys and tables stay, and the `[[providers.magpie.models]]` tables jcode writes when it saves the file itself are replaced by the one list. A sync with nothing to change doesn't write. Disconnect drops the profile whole, its sub-tables included. jcode reads the file when it starts, so the notice says to restart open sessions. - Raycast AI reads Custom Providers from `~/.config/raycast/ai/providers.yaml` in the user's folder, on Mac and Windows alike (`raycast` in [`raycast.go`](../../internal/agent/raycast.go); manual.raycast.com/ai/custom-providers). magpie adds one entry to its `providers` list, `id: magpie`, at the gateway's `/v1` with an `api_keys` alias holding a key that names Raycast (its User-Agent isn't known), and one model per catalog model with `context` and all five `abilities` said, since Raycast assumes tools and vision off when one isn't. The list is edited as a node (`EditYAMLNode`), so the user's other entries, the `tools` block (anchors too) and comments stay. A key the user adds to magpie's entry or to one of its models (`include_user_email`, a `description`) is kept on a sync (`mergeYAMLKept`), and a sync with nothing to change doesn't write. Disconnect takes the entry out, the list when it was the only one, and a file left with nothing in it. Raycast watches the file, so there is no restart notice. The model is picked in Raycast, so the field is whether magpie is in its picker (`ListsModels`). Detected by `Raycast.app` on a Mac or the `~/.config/raycast` folder. +- OpenPencil (ZSeven-W/openpencil, the `openpencil-desktop` app) keeps the builtin agents its chat runs on in `settings.json` in Rust's `dirs::config_dir()` joined with `openpencil`: `~/Library/Application Support/openpencil` on a Mac, `$XDG_CONFIG_HOME` or `~/.config` on Linux, `%APPDATA%` on Windows (`openPencil` in [`openpencil.go`](../../internal/agent/openpencil.go); its `settings_io.rs` and `settings_payload.rs`). magpie adds one entry to `builtin_agents`, `id: magpie`, `kind: openai-compat` at the gateway's `/v1` with a key naming OpenPencil (its User-Agent isn't known), `preset: custom`, the picked models as OpenPencil writes a list: the first as `model`, `models` only for two or more, at most 64 (v0.8.4 reads `model` alone). The user's other entries and settings stay, and so do the `display_name` and `enabled` they give magpie's entry; a sync with nothing to change doesn't write. OpenPencil needs `"version": 1` (a file without it is set aside as corrupt and saving stops), so magpie writes it in a file it makes and leaves a file with any other version, or none, alone. Disconnect takes the entry out, and the file when only the version and an empty list are left. OpenPencil reads the file once at start and writes it back whole when it quits, so a change is refused while `openpencil-desktop` runs (Windows can't be asked, so the notice says to quit it first). The model is picked in OpenPencil's chat, so the field is whether magpie is in its picker (`ListsModels`). Detected by its settings folder, `~/.openpencil` (its CLI's), `OpenPencil.app` (`com.zseven-w.openpencil`), or `%ProgramFiles%\OpenPencil`. open-pencil/open-pencil, the other app of the name, keeps its providers in its webview's localStorage, so it is not a row: it reaches magpie through Pi or an ACP agent magpie wires. - DevEco Code (Huawei's OpenCode fork, #1885) is wired as OpenCode is (`deveco` in [`agents.go`](../../internal/agent/agents.go)): magpie's provider goes into the first of `deveco.jsonc`, `deveco.json` and `config.json` in `~/.config/deveco` (the one DevEco merges last, so the one that wins), or in `$DEVECO_CONFIG_DIR` when that is absolute, read after them. 0.2.3 sends `deveco/0.2.3 ai-sdk/…` to a provider of its config, but much of the OpenCode code it keeps still sends OpenCode's own User-Agent (`opencode/`), so its provider's key is `magpie-deveco` (`openCodeKeyAt`), not the plain `magpie` OpenCode and MiMo Code send, and Check asks for that key. Its npm package has no Linux binary, so no install command is offered there (`cliSpec.only`). - Grok App (RongleCat/grok-app, a desktop front end that starts Grok Build over ACP) keeps its provider channels in `agent-home/config.toml` under its data folder: `$GROK_APP_HOME`, else where its `directories` crate puts it, or its `~/.grok-app` fallback when that is the one there (`grokApp` in [`grokapp.go`](../../internal/agent/grokapp.go)). Its composer lists only Grok Build's official catalog, never the `[model."magpie/…"]` tables of Grok Build's row, so magpie adds itself as a channel, `[model.magpie]`, with the keys the App's Providers page writes: the gateway's `/v1`, a key naming Grok App, `api_backend = "chat_completions"`, `app_provider_mode = "generic"`, and `app_models`, a JSON list of magpie's models with `contextWindow`, `supportsVision` and their effort levels (no `none`; a default the user marks in the App stays, else medium). The picked model's `context_window` (a bare integer) and `supports_reasoning_effort` (a bare bool, Grok Build's gate for `--reasoning-effort`) are on the channel, as the App puts them there when a model is picked in its composer. `[models] default` is the route, and magpie does not set it: setting it to `"magpie"` makes the App drop its own sign-in (`ensure_independent_for_custom_route`). The route stays whatever the App had. Pressing Use on magpie under Accounts is what switches it. A magpie that already set the route puts the old one back once, on the next sync or connect (`grokAppReleased`); a Use after that stays. Disconnect drops only the channel, and puts the route back only when it is still `"magpie"`: the one stashed at connect, else the one `connect.was` holds. One of the App's own routes picked in magpie's model field is written as the route and takes magpie's channel out, as picking another provider does elsewhere. A sync with no channel and a route other than `"magpie"` writes nothing, magpie's stash included, and Check says so when the route is `"magpie"` with the channel gone. A model picked in the App's composer since is the user's and stays through a sync, and a sync with nothing to change doesn't write. Shared mode keeps `GROK_HOME` at `~/.grok` (Grok Build's library row). Independent mode, which Use turns on, reads agent-home: the Library writes `AGENTS.md`, `[mcp_servers]` in the same `config.toml`, and `skills/` there, and Grok App also reads `~/.agents/skills`. RTK has no Grok hook, so the Library lists Grok App with the switch off. The notice, while the App runs, says magpie is a custom provider in Settings › Account, a chat can pick its models in the model picker, and the App stays on its current route until Use. - JSON/JSONC config edits and their previews reject malformed input rather than editing a partially parsed document. Object edits and VS Code's model-group array edits leave the original file untouched on a parse error; valid comments and trailing commas remain supported (`internal/edit`). @@ -121,6 +122,7 @@ go test -tags nogui ./internal/agent -run '^TestAnte' go test -tags nogui ./internal/agent -run '^TestAstrBot' go test -tags nogui ./internal/agent -run '^TestJcode' go test -tags nogui ./internal/agent -run '^TestRaycast' +go test -tags nogui ./internal/agent -run '^TestOpenPencil' go test -tags nogui ./internal/agent -run '^TestGrokApp' go test -tags nogui ./internal/agent -run 'ClaudeScience' go test -tags nogui ./internal/gateway -run 'TestClaudeScience' diff --git a/internal/agent/agents.go b/internal/agent/agents.go index e0a7aa3c4..6061e4eca 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -142,6 +142,7 @@ func builtins(home, cfg string) []*Agent { workbuddyAI(home), codebuddy(home), pencil(home), + openPencil(home, cfg), raycast(home), t3code(home), hanako(home), diff --git a/internal/agent/gatewaykey_test.go b/internal/agent/gatewaykey_test.go index 540120b15..ded084a8c 100644 --- a/internal/agent/gatewaykey_test.go +++ b/internal/agent/gatewaykey_test.go @@ -217,17 +217,18 @@ func TestPinnedGatewayKeyForEveryWriter(t *testing.T) { agy = m[1] } return map[string]string{ - "agy": agy, - "alma": almaKey(), - "cindy": cindy.Auth.APIKey, - "copilotjb": jbKey, - "cursor": cursorLocalEnv(gw)[cursorLocalVars[1]], - "hanako": hanakoProvider().APIKey, - "pencil": pencilProviderJSON(gw)["apiKey"].(string), - "vscode": vscodeStable.token(), - "vscodium": vscodiumKind.token(), - "workbuddy": buddyModel("codebuddy", "m", "m", 0, 0, false, nil)["apiKey"].(string), - "zcode": zc, + "agy": agy, + "alma": almaKey(), + "cindy": cindy.Auth.APIKey, + "copilotjb": jbKey, + "cursor": cursorLocalEnv(gw)[cursorLocalVars[1]], + "hanako": hanakoProvider().APIKey, + "openpencil": openPencilEntry(gw).APIKey, + "pencil": pencilProviderJSON(gw)["apiKey"].(string), + "vscode": vscodeStable.token(), + "vscodium": vscodiumKind.token(), + "workbuddy": buddyModel("codebuddy", "m", "m", 0, 0, false, nil)["apiKey"].(string), + "zcode": zc, } } plain := keys() diff --git a/internal/agent/lists_models_test.go b/internal/agent/lists_models_test.go index acc32b06f..4a298a8cc 100644 --- a/internal/agent/lists_models_test.go +++ b/internal/agent/lists_models_test.go @@ -58,7 +58,7 @@ func TestEveryPickerOfMagpiesModelsCanBeNarrowed(t *testing.T) { if len(bare) > 0 { t.Errorf("magpie's models are put in these agents' pickers with no way to pick which: %v", bare) } - for _, id := range []string{"zcode", "pencil", "t3code", "workbuddy", "workbuddy-ai", copilotJBID, CursorLocalID} { + for _, id := range []string{"zcode", "pencil", "openpencil", "t3code", "workbuddy", "workbuddy-ai", copilotJBID, CursorLocalID} { if !slices.Contains(menus, id) { t.Errorf("%s's row has no model list to pick in (ListsModels): %v", id, menus) } diff --git a/internal/agent/openpencil.go b/internal/agent/openpencil.go new file mode 100644 index 000000000..752758e20 --- /dev/null +++ b/internal/agent/openpencil.go @@ -0,0 +1,315 @@ +package agent + +// OpenPencil (ZSeven-W/openpencil, the openpencil-desktop app; @JC_be_better +// on X) is a design canvas whose chat runs models through "builtin agents" +// of the user's own: an Anthropic or OpenAI-compatible endpoint, a key and +// a list of models, each listed in its chat's model picker. It keeps them +// in one settings.json in the platform's config folder, dirs::config_dir() +// joined with openpencil: ~/Library/Application Support/openpencil on a +// Mac, $XDG_CONFIG_HOME/openpencil (~/.config/openpencil) on Linux, +// %APPDATA%\openpencil on Windows (op-editor-host-core's settings_io.rs, +// settings_path). Its fields (SettingsPayload, BuiltinAgentPayload, +// settings_payload.rs, main at 40902a3f and v0.8.4): +// +// {"version":1, …, +// "builtin_agents":[{"id":"magpie","preset":"custom","display_name":"magpie", +// "kind":"openai-compat","api_key":"magpie-openpencil", +// "model":"","models":["",…], +// "base_url":"http://127.0.0.1:3425/v1","enabled":true}], …} +// +// version is required (no serde default): a file without it fails to parse, +// is set aside as settings.json.corrupt-