From 1ccacad63281094de8a3372d5a507d38f9969e5c Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 14:31:21 +0800 Subject: [PATCH] agent: Obsidian is listed only when a vault has Copilot (iEthan333 on X) detect was "obsidian's config folder exists", so every Obsidian user got a row whose provider field could only fail ("no Obsidian vault here has Copilot"). It now needs a vault in obsidian.json with Copilot installed (.obsidian/plugins/copilot/manifest.json) or magpie's provider already in its data.json, so a wired vault can still be disconnected. Every OS's config folder (mac, Windows, Linux, Flatpak, Snap) is already read by obsidianDirs. Siblings checked: Zoo Code and Copilot (JetBrains) already require the plugin installed; VS Code forks and Raycast are the apps that hold the setting themselves. None changed. Run: go test ./internal/agent -run Obsidian (wsl-run); the new no-Copilot vault assertion is red on the old detect (checked by hand). Full agent package, gofmt, linux and windows vet: see push notes. Not tried: a real Obsidian install. --- docs/subsystems/agent-wiring.md | 2 +- internal/agent/obsidian.go | 8 +++++++- internal/agent/obsidian_test.go | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 467c5ce93..73c4ee86b 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -102,7 +102,7 @@ something else shows up as drift. - 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. - OpenBot (nightly-labs/openbot, openbot.run; jiezhengj on Discord) keeps the OpenAI-compatible endpoints its model picker lists in `openbot-custom-providers-v1.json` in Electron's userData folder, app data joined with `OpenBot`: `~/Library/Application Support/OpenBot` on a Mac, `%APPDATA%\OpenBot` on Windows, `$XDG_CONFIG_HOME/OpenBot` or `~/.config/OpenBot` on Linux (`openBot` in [`openbot.go`](../../internal/agent/openbot.go); its `custom-provider-store.ts` and `opencode-config.ts`, v0.58.0). magpie adds one entry to `providers`, `id: magpie` at the gateway's `/agent/openbot/v1` with `secret: null`: an entry's key and headers are one safeStorage ciphertext (the Keychain, DPAPI) that magpie doesn't open, so OpenBot hands the entry to OpenCode keyless, the gateway takes it as a request from this computer, and the address, not OpenCode's User-Agent, names it OpenBot's (`gateway.AgentURL`; before, it counted as OpenCode's, SSNQT on X). An entry written at `/v1` is rewritten at the next sync, and OpenBot reads it after a restart. OpenBot's list decoders fail closed (one entry or model it wouldn't take empties the list), so the models are the picked ones whose `magpie/` OpenBot accepts (ASCII letters, digits and `._:/[],=-`, at most 160), at most 64, with a context window only inside 1,024 to 100,000,000. The user's other entries stay, and so do the `name`, `harness` and `secret` they give magpie's entry; a sync with nothing to change doesn't write. A file whose `version` isn't the number 1, or whose `providers` isn't a list, is one OpenBot itself refuses, so magpie leaves it alone. Disconnect takes the entry out, and the file when only the version and an empty list are left. OpenBot reads the file once at start and writes it whole only when an endpoint is saved, edited or removed there, so the notice (while it runs) says to restart it before doing that. The model is picked in OpenBot's picker (`ListsModels`). Detected by its userData folder, `OpenBot.app` (`app.openbot.desktop`), or `OpenBot.exe` under `%LOCALAPPDATA%\Programs` or `%ProgramFiles%`. In the Library it takes skills, in `~/.agents/skills`, the only folder it reads (`home-skills.ts`). Its MCP servers live in its SQLite database, which magpie doesn't write (#5896), so it isn't in the MCP picker: magpie's `/mcp/magpie/…` servers are added there by hand as HTTP servers. - Craft Agents (lukilabs/craft-agents-oss, thecraftagents.com; springg1998 on X) keeps its connections in `config.json` under `$CRAFT_CONFIG_DIR` or `~/.craft-agent` (`craftAgents` in [`craftagents.go`](../../internal/agent/craftagents.go); its `config/paths.ts`, `config/storage.ts` and `config/llm-connections.ts`, v0.15.8). magpie adds one entry to `llmConnections`, slug `magpie`, `providerType: pi_compat` and `authType: none` at the gateway's `/agent/craft-agents/v1` with `customEndpoint.api: openai-completions`: Pi sends a keyless loopback request, which the gateway takes as this computer's, and the address names it Craft's. Its `models` are magpie's picked ones as objects, and `defaultModel` is always one of them, since Craft resets a default its list hasn't to the first. magpie makes it `defaultLlmConnection`; the user's default is stashed (as JSON, `""` for none) and put back on off when that connection is still there, and the `name` they give magpie's entry stays. A session keeps the connection it started on, and a workspace default goes over the global one, so the notice says new sessions use it. A `config.json` with no `workspaces` list is one Craft doesn't load, so magpie never makes one: Craft is opened once first. Picking one of the user's own models takes magpie's entry out and sets that model as their default connection's `defaultModel`. Craft re-reads the file on each lookup. Detected by `~/.craft-agent` or `Craft Agents.app` (`com.lukilabs.craft-agent`), or `Craft Agents.exe` under `%LOCALAPPDATA%\Programs\@craft-agentelectron`. In the Library it takes skills, in `~/.agents/skills`. -- Obsidian (`obsidian` in [`obsidian.go`](../../internal/agent/obsidian.go); shirotokiren on X) has no AI of its own; magpie wires its plugin Copilot for Obsidian (logancyang/obsidian-copilot, plugin id `copilot`, 4.0 and later) in every vault that has it. The vaults come from Obsidian's `obsidian.json` (`vaults..path`) in `~/Library/Application Support/obsidian` (macOS), `%APPDATA%\obsidian` (Windows), or on Linux `$XDG_CONFIG_HOME/obsidian`, the Flatpak's `~/.var/app/md.obsidian.Obsidian/config/obsidian` and the Snap's `~/snap/obsidian/current/.config/obsidian`; a vault has Copilot when `.obsidian/plugins/copilot/manifest.json` is there. In its `data.json` magpie adds `providers.magpie` (`openai-compatible`, `baseUrl` the gateway's `/agent/obsidian/v1`, `requiresApiKey: false` and no keychain id, `enableCors: false` so Copilot streams through the window's fetch, answered by the gateway's CORS for `app://obsidian.md`), one `configuredModels` entry per magpie model (provider `magpie`, ids made from the model's, uuid v5, so a sync finds them again; limits, image input and reasoning efforts from the catalog), each new one in `backends.chat.enabledModels`, and on the first wire `defaultModelKey` (the old one kept in the stash). A sync keeps a model the user turned off off, their default, and the name and key they give the provider; it writes only the keys that change, through a temp file renamed over the old (`edit.PatchJSON`, `edit.WriteAtomic`), and nothing when nothing does. Disconnect takes out the provider, its models and their ids in every backend, and puts the default back when magpie's is still it. Copilot 3 (`activeModels`) is refused with a message to update it, and so is no vault with Copilot. Obsidian holds the settings in memory, so the notice (while it runs) says to reload Copilot or restart Obsidian. Smart Connections is not wired: its free plugin embeds with a local model only, and its API providers are in the closed Pro plugin, with keys in the keychain. +- Obsidian (`obsidian` in [`obsidian.go`](../../internal/agent/obsidian.go); shirotokiren on X) has no AI of its own; magpie wires its plugin Copilot for Obsidian (logancyang/obsidian-copilot, plugin id `copilot`, 4.0 and later) in every vault that has it. The vaults come from Obsidian's `obsidian.json` (`vaults..path`) in `~/Library/Application Support/obsidian` (macOS), `%APPDATA%\obsidian` (Windows), or on Linux `$XDG_CONFIG_HOME/obsidian`, the Flatpak's `~/.var/app/md.obsidian.Obsidian/config/obsidian` and the Snap's `~/snap/obsidian/current/.config/obsidian`; a vault has Copilot when `.obsidian/plugins/copilot/manifest.json` is there. Obsidian is listed only when a vault has Copilot (or magpie's provider is already in its `data.json`); the app or its config folder alone gives magpie nothing to set (iEthan333 on X). In its `data.json` magpie adds `providers.magpie` (`openai-compatible`, `baseUrl` the gateway's `/agent/obsidian/v1`, `requiresApiKey: false` and no keychain id, `enableCors: false` so Copilot streams through the window's fetch, answered by the gateway's CORS for `app://obsidian.md`), one `configuredModels` entry per magpie model (provider `magpie`, ids made from the model's, uuid v5, so a sync finds them again; limits, image input and reasoning efforts from the catalog), each new one in `backends.chat.enabledModels`, and on the first wire `defaultModelKey` (the old one kept in the stash). A sync keeps a model the user turned off off, their default, and the name and key they give the provider; it writes only the keys that change, through a temp file renamed over the old (`edit.PatchJSON`, `edit.WriteAtomic`), and nothing when nothing does. Disconnect takes out the provider, its models and their ids in every backend, and puts the default back when magpie's is still it. Copilot 3 (`activeModels`) is refused with a message to update it, and so is no vault with Copilot. Obsidian holds the settings in memory, so the notice (while it runs) says to reload Copilot or restart Obsidian. Smart Connections is not wired: its free plugin embeds with a local model only, and its API providers are in the closed Pro plugin, with keys in the keychain. - Tuanjie Cowork (`tuanjiecowork.go`, codely.tuanjie.cn; Charles24209792 on X), a Tauri app (`dev.codelycowork.desktop`), keeps its Custom Models in `~/.codely/settings.json`: `customModelProviders` (`{id, name, baseUrl, apiKey, authType}`) and `customModels` (`{id, model, providerId, displayName, roles, wireApi, supportsMultimodal}`, an id unique across providers). Its core reads the file afresh on every lookup and writes it whole, other keys kept; a session gets its provider's baseUrl and key as `OPENAI_BASE_URL`/`OPENAI_API_KEY` (wireApi `chat`). magpie adds a provider and a model both with id `magpie`: the gateway's `/v1`, Cowork's own key (it is how the gateway tells Cowork apart), and the model picked. A name or roles given them in Cowork are kept, and an id `magpie` of the user's own is refused, not written over. Which model a chat is on is Cowork's pick in its model menu (per workspace GUI state, by model id), which magpie doesn't write; because the id stays `magpie`, that pick follows a model changed in magpie. Set of a model of Cowork's own is refused for the same reason. Off takes both entries out, and the file too where magpie made it. Cowork's startup migrations only move models without a `providerId`, so magpie's entries stay. Windows' Tauri NSIS per-user folder isn't under `%LOCALAPPDATA%\Programs`, so there it is detected by `~/.codely` alone. - Antigravity, Google's desktop app (not Antigravity IDE, `com.google.antigravity-ide`), takes a gateway from `~/.antigravity/settings.json` from 2.15 on, and from `~/.gemini/config/config.json` (beside its `userSettings` and `plugins`) from 2.30 on, which reads only that file (YujunT46308 on X). magpie writes the same block into both, and a wiring made before 2.30 is carried into the new file at magpie's next start: Google's Antigravity Enterprise Gateway (docs.cloud.google.com/gemini/enterprise/docs/ai-developer-tools/connect-enterprise-gateway; `antigravity` in [`antigravity.go`](../../internal/agent/antigravity.go), ryougi_hachi on X). magpie writes `gateway` as `{enabled: true, url: , apiKey: , wireProtocol: openai}` and the model it starts on as `models.defaultModelId`, and takes out `models.list`, which would narrow the picker to the user's own. It also points `models.listSource`, the app's remote model catalog, at `/v1/models?format=antigravity` (`gateway.antigravityModels`): `{"list": [{modelId, displayName, maxTokens, maxOutputTokens, supportsImages, supportsThinking}]}`, the models the key may use. The backend (2.29.0) resolves models from `models.list`, then `listSource` (fetched with the gateway key), then `/v1/models`, then its built-in catalog. From `/v1/models` it reads the id alone, and a model its catalog doesn't know gets its family's defaults, a 200K window whatever the model's, so every magpie model had 200K (YujunT46308 on X); `context_window`, `context_length` and `max_input_tokens` there are not read. A bare array or `{"list": …}` is read; `{"models": …}` is not. A field magpie doesn't know is left out and the app's default stands. The picker shows `displayName`, so the names follow magpie's (`ListsModels`, not `NoNames`). The app's picker (its `main.js`, 2.29.0) offers effort only by grouping entries named ` (Low)`, `(Medium)`, `(High)`, `(XHigh)` or `(Max)` (its regex also takes `(Low thinking)`) under one row with an effort menu, two levels or more, starting on medium when a group has it, else the lowest; a model listed once had no effort control at all (YujunT46308 on X). So a model with two or more of those levels is listed once a level, `:` named ` ()` (`antigravityLevels`), and the request goes out under the chosen entry's id, whose `:level` suffix the gateway sends upstream ahead of the row's pick; the app's own `reasoning_effort` (`low` whatever was chosen, in a 2.29.0 run) loses to it. `models.defaultModelId` names one of those entries, since an id the catalog doesn't list starts the app on its first model: `gateway.AntigravityModel` adds the row's effort, fitted, else medium, else the lowest. The row's effort sets that start level (and is what a model with fewer than two levels is asked for); `Sync` moves a file written before onto a level, keeping a level already there. The model field shows the id without the level.`Sync` adds `listSource` to a file wired before, at the gateway's current address, stashing one of the user's. On the openai protocol the backend streams `/v1/chat/completions` with the key as a bearer token and a User-Agent of `antigravity/hub/`. The user's gateway, default model, list and `listSource` are stashed and put back on disconnect, or when a model of their own is picked; `caCertPath` and the rest of the file are never touched, and a `Sync` keeps what the user added to magpie's block (`customHeaders`). On a gateway the app uses no Google sign-in, and its backend asks Google for nothing (no `cloud_code_endpoint` or `api_server_url` call in a headless run): Google's docs say a gateway and a Google Account can't be used at once. What Google's servers turn on for a signed-in account, its experiments and the commands behind them (`/boost`, `/teamwork`, `/plugin`, `/generative_ui`, YujunT46308), is off while it is on magpie. No key in the file keeps both (`proxy` only routes the app's own HTTP), so the notice shown on connecting names what is lost and that turning it off gives it back. An organisation's `admin_settings.json` and the `AGY_LLM_GATEWAY_*` variables win over the file, so `Check` says when either sets a gateway. agy reads the same file below its own settings: an agy connected on its own row keeps its route, one that isn't follows the app's gateway, as the notice says. `~/.antigravity` is Antigravity IDE's and agy's too, so the app is found by its bundle at 2.15 or later (`desktopApps`) or `~/.gemini/antigravity/agyhub_summaries_proto.pb`, which only its backend writes. The app reads the file at start, so the notice asks for a restart. The Antigravity accounts magpie signs in (provider `antigravity`) are a separate thing: those send magpie's requests to Google. - NewMax (newmax.cc, an Electron app on the Claude Agent SDK) keeps its settings as JSON in the row `app` of the `settings` table of `newmax.db`, a SQLite database in WAL mode in `$NEWMAX_USER_DATA_DIR`, else `~/.newmax` on every system (`newMax` in [`newmax.go`](../../internal/agent/newmax.go); its main bundle's `configureAppDataPaths`, `loadPersistedAppSettings` and the renderer's `mergeProviders`, v1.1.22). magpie adds one entry to `providers` in the shape NewMax's own import writes, `id: magpie-gateway` (its own preset is `magpie`, its import's ids hold `%3A`), `apiFormat: anthropic` at the gateway's root (NewMax appends `/v1/messages`) with `ANTHROPIC_AUTH_TOKEN` and a key naming NewMax, at most 20 models (`MAX_MODELS`) as `models` and `enabledModels` with their context windows, and its id at the end of `providerOrder`. The row is edited in place in one immediate transaction, so every other byte stays; the user's `name` and `enabled` for magpie's entry and the fields NewMax adds to it stay through a sync, and a sync with nothing to change doesn't write. A row that isn't a JSON object, or whose `providers` or `providerOrder` isn't a list, is left alone. With no row (NewMax at its defaults), magpie writes one with its entry alone, as NewMax lays its defaults and presets under the row; with no database yet, it asks to open NewMax once. Disconnect takes the entry and the id out, sets a pick of it back to `default`, and takes the row out when only what magpie made is left. NewMax holds its settings in memory and writes the whole row back whenever one changes, so a change is refused while `NewMax` (`newmax` on Linux) runs (Windows can't be asked, so the notice says to quit it first). The model is picked in NewMax's model picker, so the field is whether magpie is in it (`ListsModels`). Detected by its data folder or `NewMax.app` (`cc.newmax.desktop`). diff --git a/internal/agent/obsidian.go b/internal/agent/obsidian.go index 41f94bed0..0448c7ca1 100644 --- a/internal/agent/obsidian.go +++ b/internal/agent/obsidian.go @@ -136,8 +136,14 @@ func obsidian(home, cfg string) *Agent { return atomic(&Agent{ ID: "obsidian", Name: "Obsidian", Icon: "obsidian", Aliases: []string{"obsidian-copilot"}, Dir: dir, Path: filepath.Join(dir, "obsidian.json"), + // Obsidian has no AI of its own: it is listed when a vault has + // Copilot (installed, or magpie's provider already written), since + // the app or its config folder alone gives magpie nothing to set + // and a row that can't be used (iEthan333 on X) detect: func() bool { - return slices.ContainsFunc(dirs, isDir) || macBundle(obsidianApp) + return slices.ContainsFunc(vaults, func(v string) bool { + return obsCopilotHere(v) || obsCopilotWired(obsCopilotData(v)) + }) }, Notice: func() string { if wired() && Running(obsidianProc...) { diff --git a/internal/agent/obsidian_test.go b/internal/agent/obsidian_test.go index ab582912e..d10a6ca2e 100644 --- a/internal/agent/obsidian_test.go +++ b/internal/agent/obsidian_test.go @@ -168,6 +168,12 @@ func TestObsidianCopilot(t *testing.T) { t.Fatal("found with nothing of it here") } odir := obsidianDirs(home, cfg)[0] + // Obsidian is here, with a vault that has no Copilot: nothing to set, + // so no row (iEthan333 on X) + obsidianVault(t, odir, "0000000000000000", filepath.Join(home, "NoAI"), "", "") + if obsidian(home, cfg).Detected() { + t.Fatal("found with only a vault that has no Copilot") + } notes := filepath.Join(home, "Documents", "Notes") path := obsidianVault(t, odir, "a1b2c3d4e5f60718", notes, "4.0.19", obsCopilotUser) // a second vault without Copilot, and one listed that is gone