diff --git a/README.md b/README.md
index 5175b32ff..20d86e8e5 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
diff --git a/docs/reference.md b/docs/reference.md
index e9605613c..d0ecd9347 100644
--- a/docs/reference.md
+++ b/docs/reference.md
@@ -140,6 +140,7 @@ line; agents connected to magpie lose it when it quits.
| QwenPaw | each agent's `agent.json` in its workspace (`~/.qwenpaw/workspaces/`, the agents listed in `config.json`), under `$QWENPAW_WORKING_DIR`, else a legacy `~/.copaw`, else `~/.qwenpaw` | model (a `magpie` custom provider in `providers/custom/magpie.json` under QwenPaw's secret folder, `$QWENPAW_SECRET_DIR` or `~/.qwenpaw.secret`, OpenAI Chat at the gateway with magpie's models; the agent's `active_model` set to it, what was there put back on Disconnect; one row per agent, `qwenpaw` the default and `qwenpaw#` the others; an agent on an ACP backend isn't listed; restart QwenPaw after the first connect), effort (the agent's `thinking_level`; magpie's models with reasoning levels are declared `thinking_param_style: "effort"` so QwenPaw applies it) |
| OpenClaw | `openclaw.json` in `~/.openclaw` (`$OPENCLAW_CONFIG_PATH`, `$OPENCLAW_STATE_DIR`, `~/.openclaw-` for `$OPENCLAW_PROFILE`, `~` as `$OPENCLAW_HOME`) | model (a `magpie` provider in `models.providers`, `openai-completions`, with magpie's models in it; `agents.defaults.model`'s primary set to it, what was there put back on Disconnect; `magpie/*` added to a `modelPolicy.allow` that would refuse it; the user's own keys in the provider and its models kept; a chat already on a model keeps it until `/model default`) |
| jcode | `config.toml` in `$JCODE_HOME`, else `~/.jcode` | model (a `[providers.magpie]` profile, `openai-compatible`, with magpie's models in it; `[provider] default_provider`/`default_model` set to it, what was there put back on Disconnect; the user's own keys in the profile, such as `headers` and a model's `reasoning_effort`, kept; restart open jcode sessions after connecting) |
+| Dim (alpha, `dima`) | none of Dim's: magpie's own `dim.json` beside its settings, and a `dima` function in your shell profiles | model (Dim's documented start-up variables, set only for that run: `DIM_BASE_URL` the gateway's `/v1`, `DIM_API_FORMAT=openai-compatible`, `DIM_API_KEY`, `DIM_MODEL` and both token limits; Dim's home (`$DIMCODE_HOME`, else `~/.dimcode-alpha`), saved Providers and account are never read or written. Type `dima` in a new terminal; picking Dim's own again takes the function out) |
| Mistral Vibe | `config.toml` in `$VIBE_HOME`, else `~/.vibe` | model (a `[[providers]]` entry named magpie with the gateway's `/v1` and the key as an `Authorization` header in `extra_headers`, since Vibe reads keys only from the environment; one `[[models]]` entry per model, aliased `magpie//`; `active_model` set to the alias, what was there put back on Disconnect; a `thinking` level the user set on a model kept; restart open vibe sessions after connecting) |
| MiniMax Code (mcode) | `~/.minimax/config.yaml` (`$MINIMAX_DATA_DIR`, or the folder the desktop app moved it to) | model (a `magpie` custom provider; magpie's models in its /model) |
| Droid (Factory) | `~/.factory/settings.json` (`$FACTORY_HOME_OVERRIDE`) | model (magpie's models as BYOK `customModels`, in Droid's /model) |
@@ -3308,6 +3309,16 @@ it starts agy untouched. A terminal open already takes the command the
Launch row copies. Stepping out (`magpie agy default`) takes the block out
again. `magpie agy env` prints what `agy run` adds.
+**Dim** alpha (`dima`, npm's `dimcode-alpha`) is started on magpie the
+way Dim documents for any OpenAI-compatible endpoint: `DIM_BASE_URL`,
+`DIM_API_FORMAT=openai-compatible`, `DIM_API_KEY`, `DIM_MODEL`,
+`DIM_MAX_CONTEXT_TOKENS` and `DIM_MAX_OUTPUT_TOKENS`, for that run only.
+Picking a catalog model (`magpie dim `) keeps it in magpie's own
+`dim.json` and puts a marked `dima` function in your shell profiles, which
+runs `magpie dim run`; Dim's own folder, saved Providers and account are
+not touched. `magpie dim default` takes the file and the function out
+again, and `magpie dim env` prints what `dim run` adds. No WSL twin.
+
agy installed in a WSL distro is listed as Antigravity CLI · WSL
, found by `~/.gemini/antigravity-cli` or the `agy` command there.
A catalog model puts the same marked `agy` function in the distro's
diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md
index 27e091d91..23f65ebd9 100644
--- a/docs/subsystems/agent-wiring.md
+++ b/docs/subsystems/agent-wiring.md
@@ -43,7 +43,7 @@ something else shows up as drift.
| WSL CLI versions and updates | A twin's CLI is read and updated in its distro, as the host's is (`cliupdate_wsl.go`; mewcoder on X): the Agents row shows the version, the newest and an Update button for every `cliSpecs` kind a distro has a command for, and Update all takes them in. Where the binary is comes from the probe (`distro.Paths`, else the command asked of the distro's PATH); one `wsl.exe -d -e sh` script says where its links lead, its `--version` and exit code (`wslCLIScript`, kept ten minutes in `wslProbes`, asked again by Rescan and after an update), with the CLI's own folder, its npm prefix, `~/.local/bin` and `~/.bun/bin` first on PATH, since `wsl.exe -e` has no login PATH and a node CLI would not find node. How it was installed is read from that Linux path by the same rules (`wslHowInstalled`: its own updater via `cliSpec.self`, Homebrew's Cellar, npm, bun or pnpm; volta, yarn and an npm prefix the user can't write, `/usr/lib`, are left alone), and the update runs in the distro through wsl.exe (`wslRunUpdate`) with a Linux brew asked for its newest in the distro too. A distro that isn't running is never started to be asked: its rows show no version and an update says to start it. Not carried over: the host's proxy settings (the distro has its own network), and Grok Build's newest is read from this computer's channel setting. Kinds with no command of their own (Goose, mu) show nothing, as on the host. | [`cliupdate_wsl.go`](../../internal/agent/cliupdate_wsl.go), [`cliupdate.go`](../../internal/agent/cliupdate.go) |
| Settings tuned from use | Usage › Context's "Tuned for you" advises, per agent, the settings that would have spent the fewest tokens on the user's own calls of the range, and puts one in on a click. Package `tune` replays the calls `sessions.Calls` reads from the agents' session files under each candidate value (`Compact`, `CacheTTL`), each model's tokens weighed at what magpie bills them where the agent asked for a model magpie wrote (a provider/model id resolves as the gateway resolves it and is weighed at that provider's price, `pricedWeights`, so a Claude model on Copilot has its 1-hour cache write at the 5-minute one Copilot bills, #3435), else at its maker's list ratios (`tune.WeightsFor`); `tuneOf` picks the agents and models (Claude Code per model, Codex pooled). `TuneRead`, `TuneApply` and `TuneUndo` know where each setting lives: Claude Code's `modelSettings..autoCompactWindow` (where its `/autocompact` saves), `promptCacheTtl` and `subagentPromptCacheTtl` in `~/.claude/settings.json`. Where Codex compacts, and Claude Code wherever magpie's own window is what it runs at, is one value with Long conversations in the agents' settings sheet (`settings.CompactAt`/`FullContext`, source `long`; 7eleven on Discord): the card reads it, Use sets it through `provider.SetCompactAt`, and Sync writes it into each agent's config as it does for the sheet; the note says it is Long conversations, shared by Codex and Claude Code (`compact-one-value.test.cjs`). The advice is weighed by tokens alone: it is labelled "Fewest tokens", and a compaction window it would change says it doesn't measure how well the agent keeps the task after a compaction, and that a lower window compacts more often (#1854, `context-tune.test.cjs`). A compaction row's "Other window…" opens the app menu with every value of the curve, each with its estimated tokens against the setting now (fewer or more, the setting itself marked "Your setting now", hayden4608 on Discord), "Fewest tokens" beside the leanest, and about how many compactions it would have made (`Point.compacts`, from the same replay), and puts the one picked in like Use (#1860). An agent whose files time its compactions also has their wait weighed (HirotaNagai on X): Claude Code's `compact_boundary` line says `compactMetadata.durationMs`, which `sessions` puts on the first call after it, and Codex compacts by a call of its own (the record a `compacted` line names, in rollouts since 2026-09), whose time is the compaction's (`Call.Compact`; an older rollout's compaction has no call and stays untimed). With 3 or more timed for a model (`minTimed`), `Facts.took` is their median seconds, each window says its wait (`Point.wait`, its compactions × `took`), and the row says what a compaction took, the wait at the advice against the window now, and the cheaper window the advice passed over for waiting longer (`Compaction.cheapest`, `wait_cheapest`) when it saves 3% or more; the advice is labelled "Tokens + wait", its caveat says tokens and waiting only, and the picker says each window's wait with "Fewest tokens" on the cheapest (`context-tune.test.cjs`). An agent or model with fewer timed reads and is advised as before. | [`internal/tune`](../../internal/tune/tune.go), [`tune.go`](../../internal/agent/tune.go), [`internal/gui/tune.go`](../../internal/gui/tune.go) |
| Agents a plugin adds | A plugin's `magpie.agent` module (or a `*.agent.js` file) says where an agent magpie has no setup of its own keeps its model (`config`, `format`, `model`, `prefix`), and its `connect` returns the other keys to write. One with no `model` is connect only (#2374): its one field is `provider`, magpie or nothing, as an app whose one setting is magpie as its provider; `connect` is called without a model, must return keys, and is called again on a catalog change (`Sync`); `ListsModels` is set, so its list is the models picked for it. One whose agent keeps the model a new session starts on in a file apart from its provider list says so with `startup` (`config`, `format`, `model`, and `keys` written beside the model as they are) and has no `model`: PiG keeps its providers in `models.json` and `defaultProvider`/`defaultModel` in `settings.json` (str_ on Discord: its row only listed models, where Pi's picks the one it starts on). Its field is `model` again; picking one of magpie's writes `connect`'s keys into `config` and the model and `startup.keys` into `startup.config`, each file stashed under its own `plugin::` (the startup one marked by its first string key, so a model picked in the agent among magpie's, with `defaultProvider` still `magpie`, reads as magpie's). A model of the agent's own picked in it while `connect`'s keys are still in `config` is `Beside`: connected, not drift, and Disconnect leaves that pick and takes the rest out. A magpie without `startup` reads the same module as connect only (`TestPluggedStartupModel`, `TestPluggedStartupOwnPickKept`, `TestPluggedStartupRestoreGone`). `agentplug` compiles each in moejs (via `jsmod`, as gateway middleware is), reloads it when plugins.json or the file changes, and keeps why one didn't load. `plugged` makes each an `Agent` with `Plugin` set, listed after magpie's own; an id one of magpie's own agents has is refused (`PluginErrors`). `connect` is given each model as `magpieModels` builds it, with `/v1/models`' `native_endpoints` (`provider.NativeEndpoints`; a routing group's, `provider.GroupEndpoints`, the APIs every member relays as it is; carried as `catalog.Model.Endpoints`) and `pricing` (`catalog.OpenRouterPricing` of the same `EntryPricer` price), each left out when not known ([`plugged_connect_facts_test.go`](../../internal/agent/plugged_connect_facts_test.go)). Decision models are never in `models`; `connect` gets them as `decisionModels` (`pluggedDecisionModels`: `provider.OfferedDeciders`, what `/v1/models` lists under `X-Magpie-Deciders`, then the decision routing groups, each with `id`, `name`, `provider` or `group: true`, and `endpoints` `/v1/systemone` and `/v1/decisions`; `TestPluggedConnectSeesDecisionModels`). | [`agentplug.go`](../../internal/agentplug/agentplug.go), [`plugged.go`](../../internal/agent/plugged.go) |
-| Environment-only agents | Agents that read the gateway only from the environment get a `Launch` command. Antigravity CLI (agy) also gets a function `agy` in each shell's profile while it is on one of magpie's models, so typing `agy` in a new terminal starts it on magpie (bestony on Discord). The function runs `magpie agy run`, which starts the agy on PATH with `GEMINI_API_KEY`, `GOOGLE_GEMINI_BASE_URL`, `--settings <~/.gemini/antigravity-cli/magpie-settings.json>` and `--model` (no `--model` when the user gives one) while that file's model is magpie's, and unchanged otherwise. magpie writes `modelProvider`, `model` and the custom models (the user's own too, as agy takes the key whole) only into that file of its own, never into agy's `settings.json`: `modelProvider: gemini` there made every agy an API-key session with no Google account, so no remote control, which needs the sign-in (baysonfox on X). A `settings.json` an older magpie wired is given back (the stashed model and provider) at the next `Sync` or pick. `agy remote-control …` and `--remote-control` go through the function and `magpie agy run` as plain agy, on the user's sign-in (`AgyRemote`); remote control inside a session on magpie's models is not possible. PowerShell's asks `magpie agy env` for them, since the Windows app is a GUI program PowerShell doesn't wait for. `Typed` says the function is there; the row then says plain `agy` works in a new terminal, and the `Launch` command is for a terminal open before. agy has no settings-only route: 1.4.7 refuses to start without `GEMINI_API_KEY` in the environment even with a key on the custom model. Cursor Private Inference instead gets user-level variables (`cursorLocalOn`, `KeepCursorLocalEnv`), and magpie writes none of Cursor's own files. It is found by its product.json in the apps folders, in the folder Windows' list of installed programs names (`cursorLocalInstalls`, any folder picked in its installer), or as its Linux AppImage (`Cursor_Private_Inference-…AppImage`) in the folders downloads are kept in (#1254). Its effort field is kept in magpie (`provider.AgentEffort`) and asked by the gateway, its levels those of the models it lists (`pickedEfforts`, #1003). Antigravity's app has the same field while it is on magpie: its picker lists the gateway's models with no level of its own, so one of Antigravity's families of levels went at its default (MDX-Tom, #4838). | [`cursorlocal.go`](../../internal/agent/cursorlocal.go) |
+| Environment-only agents | Agents that read the gateway only from the environment get a `Launch` command. Antigravity CLI (agy) also gets a function `agy` in each shell's profile while it is on one of magpie's models, so typing `agy` in a new terminal starts it on magpie (bestony on Discord). The function runs `magpie agy run`, which starts the agy on PATH with `GEMINI_API_KEY`, `GOOGLE_GEMINI_BASE_URL`, `--settings <~/.gemini/antigravity-cli/magpie-settings.json>` and `--model` (no `--model` when the user gives one) while that file's model is magpie's, and unchanged otherwise. magpie writes `modelProvider`, `model` and the custom models (the user's own too, as agy takes the key whole) only into that file of its own, never into agy's `settings.json`: `modelProvider: gemini` there made every agy an API-key session with no Google account, so no remote control, which needs the sign-in (baysonfox on X). A `settings.json` an older magpie wired is given back (the stashed model and provider) at the next `Sync` or pick. `agy remote-control …` and `--remote-control` go through the function and `magpie agy run` as plain agy, on the user's sign-in (`AgyRemote`); remote control inside a session on magpie's models is not possible. PowerShell's asks `magpie agy env` for them, since the Windows app is a GUI program PowerShell doesn't wait for. `Typed` says the function is there; the row then says plain `agy` works in a new terminal, and the `Launch` command is for a terminal open before. agy has no settings-only route: 1.4.7 refuses to start without `GEMINI_API_KEY` in the environment even with a key on the custom model. Dim alpha (`dima`, [`dim.go`](../../internal/agent/dim.go)) gets the same kind of function from `launchSpec`, with no model flag: `magpie dim run` starts it with the variables Dim documents for an OpenAI-compatible endpoint (`DIM_BASE_URL` = the gateway's `/v1`, `DIM_API_FORMAT=openai-compatible`, `DIM_API_KEY` = `agentKey("dim")`, `DIM_MODEL`, and `DIM_MAX_CONTEXT_TOKENS`/`DIM_MAX_OUTPUT_TOKENS`, which Dim needs for a model it doesn't know), read for that run only and beside a running daemon. The pick is in magpie's own `dim.json`; nothing in Dim's home or database is written, and Dim's own account (DimAgent, dropped at its vendor's request in v0.1.471) is never read or used. Cursor Private Inference instead gets user-level variables (`cursorLocalOn`, `KeepCursorLocalEnv`), and magpie writes none of Cursor's own files. It is found by its product.json in the apps folders, in the folder Windows' list of installed programs names (`cursorLocalInstalls`, any folder picked in its installer), or as its Linux AppImage (`Cursor_Private_Inference-…AppImage`) in the folders downloads are kept in (#1254). Its effort field is kept in magpie (`provider.AgentEffort`) and asked by the gateway, its levels those of the models it lists (`pickedEfforts`, #1003). Antigravity's app has the same field while it is on magpie: its picker lists the gateway's models with no level of its own, so one of Antigravity's families of levels went at its default (MDX-Tom, #4838). | [`cursorlocal.go`](../../internal/agent/cursorlocal.go) |
| Built-ins a plugin serves | `agentMovers` names the community agent plugin a built-in agent moves onto (`agy`: `@magpie-community/agent-agy`). While that plugin is installed and on, `dropMoved` leaves the built-in out (`onMachine`, and `wslKind.served` in a distro), and the plugin's agent takes its id and aliases. Its desc says what the built-in did in code. `config` is magpie's own `magpie-settings.json` and `base` agy's `settings.json` (`Desc.Base`, `bf` in `plugged`): `connect` and `own` get `base` parsed, the user's own model is written there, `get` reads it off magpie, and stepping out removes the config whole, so `settings.json` is never written while on magpie and remote control keeps its Google sign-in (0cc91af3d). `launch` (`{env, model, args, plain}`) gives it the same shell function and `magpie run`/`env` (`launchSpec` in [`plugged_launch.go`](../../internal/agent/plugged_launch.go); `startCmd` in [`start_cli.go`](../../internal/cli/start_cli.go) finds any agent with `Start` by id or alias, `agent.Starter`): `args` `{"--settings": "{config}"}` go before the model flag, filled with the config as the agent's system spells it (`env` prints them as `settings=`, which the PowerShell function reads), and a `plain` argument (`remote-control`) runs the agent as it is, in `startRun` (`Starting.Plained`) and in a distro's or PowerShell's function, which have no magpie to ask (`TestPluggedDistroFunctionArgsAndPlain`, `TestPluggedPowerShellFunctionArgsAndPlain`). `effort`, `wsl` and `aliases` are the rest. A `launch.env` value is `{key}`, `{url}` or `{v1}` with a path at most (`envValueOK`), an `args` value only `{config}`, and a `plain` word a subcommand or flag, so nothing else a plugin says reaches a shell profile (`TestLaunchSaysOnlyWhatAShellTakesAsItIs`, `TestBaseIsForAHandedConfig`). What the built-in wired is handed over the first time the plugin's agent reads its file with nothing stashed (`handedOver`, `agyHandover` in [`plugged_moved.go`](../../internal/agent/plugged_moved.go)): a `settings.json` an older built-in wired is given back first, by the built-in's own `Sync` (its `migrate`, then `magpie-settings.json` written); then, while `magpie-settings.json` names one of magpie's models, its keys become the plugin's `Had` as not there before, so the plugin's own model or Disconnect takes the file away and leaves `settings.json` as the user had it. Turning the plugin off disconnects it as any plugin agent's (below), and the built-in is back (`TestAgyPlugin`, `TestAgyHandedToPlugin`, `TestAgyOldWiringHandedToPlugin`, `TestAgyHandedOverUnwire`). | [`plugged_moved.go`](../../internal/agent/plugged_moved.go), [`plugged_launch.go`](../../internal/agent/plugged_launch.go) |
| Claude Science | Its daemon (`claude-science`) reads the API's address only from its environment's `ANTHROPIC_BASE_URL` and has no setting for it. Connect restarts the daemon with that variable set to the gateway (`scienceOn`: `stop`, then `serve --detached --no-browser` on the port `status` said it was on) and notes the daemon in `claude-science.json` (url, pid, port); Disconnect restarts it without the variable, one in magpie's own environment taken out too. No variable is set for the user and no file of the app's is written. Setting it again while magpie's daemon runs on this gateway does nothing (`Pick` sets the field after `connect`). `KeepClaudeScience` starts it again on the gateway, on its port, when it isn't running (a restart of the computer). The app (0.1.72, Electron) attaches its window to a daemon running; with none it starts its own (`serve --stdio --adopt-install`, `launch_context` `app-child`) in its own environment, without the variable, and its "let the app run it instead" (and its offer once the app updated past the daemon) stops magpie's to do the same (shuitunlulu_ on Discord: Claude Science went back off magpie). So the keeper also puts magpie's daemon back, on the port the other was on, in place of one with another pid, one started for the gateway's old address, or its own older than the program installed (`--version`, asked again only when the file changed) (`scienceStale`), but only when `status` says no session runs in it (`active_frames` and `active_conversations` 0; a status without them is busy), never one launchd or systemd keeps (`launch_context`), and at most three times an hour (`scienceRetakes`). It reads `operon.lock` every 10 s and asks `status` when the lock's pid changed or a minute went by. A window on the daemon stopped shows the app's "stopped from the command line" screen, whose "start it again in the app" attaches it to magpie's. `Check` reads the daemon's `operon.lock`, not `status` (most of a second for a 130 MB Bun program), and calls a daemon with another pid drift until the keeper replaces it. It is found in the Mac app's bundle (`Claude Science.app/Contents/Resources/bin`), `%LOCALAPPDATA%\Programs\ClaudeScience` on Windows, `~/.local/bin`, else on PATH. The app still needs its own Claude sign-in; the gateway never passes it on (see gateway-routing). In a WSL distro (shuitunlulu_ on Discord) it is a WSL twin (`wslKinds`, found by `claude-science` on the probe's PATH, keeping its own notice) whose daemon magpie runs there through `wsl.exe` (`scienceInWSL`, `scienceWSLScript`; the same `scienceHost` steps as this machine's, its note `claude-science-wsl-.json`). The daemon takes http only to a loopback address, so in mirrored networking it gets the gateway's address, and under NAT a relay magpie starts in the distro: `socat` on `127.0.0.1:` to Windows' address on the WSL network (`scienceRelayScript`, its pid and target in `~/.claude-science/magpie-relay`, stopped with its forks as a process group on Disconnect or when the target moved). It is given `http://127.0.0.1:/`, the key in the path, as it sends its own sign-in as the key (gateway-routing's WSL under NAT). Connect says so when the distro has no socat. The keeper runs nothing in WSL until a distro's note exists, then starts both again in each running distro (`wslScienceHosts`). Its `Check` adds the firewall drift any agent pointed at Windows' WSL address gets (`unreachable`), as its one value isn't a model of magpie's, which is what `Drift` asks that of. | [`claudescience.go`](../../internal/agent/claudescience.go), [`claudescience_wsl.go`](../../internal/agent/claudescience_wsl.go), [`science.go`](../../internal/gateway/science.go) |
| Claude Code beside its own account | `claude-magpie` (baranwang on X) starts Claude Code through magpie while a plain `claude` stays on the user's own account, nothing switched back and forth. `magpie claude run [args…]` writes `/claude-launch/settings.json` as `claude#launch`, an agent `claudeIn` makes at that folder (`place.dir`) and lists nowhere, so the Agents page, Check and Notice see only the user's settings.json: connected the first time as Connect would (`ConnectHow`), set again when the gateway's address or key moved (`claudeLaunchStale`, the LAN key included), synced after that, with `ANTHROPIC_API_KEY` and the cloud switches (`agentenv.ClaudeProviders`) blanked. It then runs `claude --settings args…` as a child (not exec, so it can tidy after): Claude Code puts a --settings file's env and model over the user's settings.json, a claude.ai sign-in and the shell (tried on 2.1.318). `/model` saves to the user's settings.json, never the --settings file, so `ClaudeLaunchAfter` moves a magpie model picked there into the launch file and gives the user's file its model back while magpie isn't wired into it; it also undoes Claude Code's own one-time `opus` → `opus[1m]` rewrite (`migration_opus_to_opus1m`), which the launch file's 1M opus tier sets off. A Claude alias picked (`sonnet`) stays. On Unix a stopped child stops magpie too (^Z, fg), and its exit code is magpie's; on Windows magpie ignores Ctrl+C while claude runs. The command `claude-magpie` is a launcher beside the `magpie` command (`update.Launchers`): a `#!/bin/sh` `exec` of `Program()`, or on Windows a `.cmd` running `"%~dp0magpie"`. `AddCLI` writes it, and `magpie claude launcher add` puts it there for a command added before; a file by that name without `written by magpie` is never written over. StandIn falls back to the launch file's tiers. | [`claude_launch.go`](../../internal/agent/claude_launch.go), [`claude_launch_cli.go`](../../internal/cli/claude_launch_cli.go), [`claude_run_unix.go`](../../internal/cli/claude_run_unix.go), [`launcher.go`](../../internal/update/launcher.go) |
diff --git a/internal/agent/agents.go b/internal/agent/agents.go
index 9937d1627..070758868 100644
--- a/internal/agent/agents.go
+++ b/internal/agent/agents.go
@@ -301,6 +301,7 @@ func onMachineAll(home, cfg string) []*Agent {
codex(home),
gemini(home),
agy(home),
+ dim(home),
antigravity(home),
opencode(home, cfg),
openChamber(home, cfg),
diff --git a/internal/agent/dim.go b/internal/agent/dim.go
new file mode 100644
index 000000000..7ad71aa6c
--- /dev/null
+++ b/internal/agent/dim.go
@@ -0,0 +1,202 @@
+package agent
+
+// Dim alpha (arcships/dim, the `dima` command of npm's dimcode-alpha) is
+// started on magpie the way Dim documents for any OpenAI-compatible
+// endpoint (docs/design/model-startup.md): DIM_BASE_URL with
+// DIM_API_FORMAT, DIM_API_KEY, DIM_MODEL, and DIM_MAX_CONTEXT_TOKENS with
+// DIM_MAX_OUTPUT_TOKENS for a model Dim doesn't know. Dim reads them for
+// that one run only, beside a running daemon, and leaves its saved
+// Providers alone; help, version and management commands ignore them.
+// The format is openai-compatible, Dim's generic provider, not
+// openai-chat, which Dim takes for OpenAI's own.
+//
+// Nothing of Dim's is written: not its home ($DIMCODE_HOME, else
+// ~/.dimcode-alpha), its settings or its database, and nothing reads or
+// uses Dim's own account (magpie dropped the DimAgent subscription at its
+// vendor's request, v0.1.471). The model picked in Dim's row is in a file
+// of magpie's, dim.json in magpie's folder. While it names one of
+// magpie's models, magpie puts a function named dima in each shell the
+// user has, between "# >>> magpie dima >>>" and "# <<< magpie dima <<<"
+// (update.ShellFunction), which runs `magpie dim run` (cli/start_cli.go)
+// to start the real dima with the variables; the row gives the command
+// for a terminal open before. Picking Dim's own again (or Disconnect)
+// removes the file and the function, and dima runs as it did.
+
+import (
+ "os"
+ "path/filepath"
+ "runtime"
+ "strconv"
+ "strings"
+
+ "github.com/yetone/magpie/internal/appdir"
+ "github.com/yetone/magpie/internal/edit"
+ "github.com/yetone/magpie/internal/gateway"
+ "github.com/yetone/magpie/internal/update"
+)
+
+// dimFile is magpie's file holding the model picked for Dim.
+func dimFile() string { return filepath.Join(appdir.Config(), "dim.json") }
+
+// dimDir is Dim alpha's folder: $DIMCODE_HOME as given, else
+// ~/.dimcode-alpha (dim-cli's default_home; ~/.dimcode is the older dimcode).
+func dimDir(at place) string {
+ if d := strings.TrimSpace(at.getenv("DIMCODE_HOME")); d != "" {
+ return d
+ }
+ return at.join(".dimcode-alpha")
+}
+
+// dimContext and dimOutput are the limits Dim is given for a model the
+// catalog knows none of (Dim refuses to start one without both).
+const (
+ dimContext = 128000
+ dimOutput = 32000
+)
+
+// dimLaunch is how dima is started on magpie: the variables Dim reads,
+// with the model in DIM_MODEL (a --model flag would come before a
+// subcommand, which Dim refuses).
+func dimLaunch(gw, key, model string) *launchSpec {
+ ctx, out := dimLimits(model)
+ return &launchSpec{id: "dim", bin: "dima", env: map[string]string{
+ "DIM_BASE_URL": gw + "/v1",
+ "DIM_API_FORMAT": "openai-compatible",
+ "DIM_API_KEY": key,
+ "DIM_MODEL": strings.TrimPrefix(model, magpieID+"/"),
+ "DIM_MAX_CONTEXT_TOKENS": strconv.Itoa(ctx),
+ "DIM_MAX_OUTPUT_TOKENS": strconv.Itoa(out),
+ }}
+}
+
+// dimLimits are the context and output limits of a magpie/ model
+// for Dim: the catalog's, else dimContext (held to the user's cap) and
+// dimOutput.
+func dimLimits(model string) (ctx, out int) {
+ ref := strings.TrimPrefix(model, magpieID+"/")
+ for _, m := range sharedModels("dim") {
+ if m.ID == ref {
+ ctx, out = m.Context, m.Output
+ break
+ }
+ }
+ if ctx <= 0 {
+ ctx = unknownWindow(dimContext)
+ }
+ if out <= 0 || out > ctx {
+ out = min(dimOutput, ctx)
+ }
+ return ctx, out
+}
+
+// dimCommand is what starts dima on magpie's model in the shell of this
+// system. The variables are put as they are (none needs quoting).
+func dimCommand(gw, key, model string, powershell bool) string {
+ l := dimLaunch(gw, key, model)
+ var b strings.Builder
+ for _, kv := range l.vars(gw, key) {
+ k, v, _ := strings.Cut(kv, "=")
+ if powershell {
+ b.WriteString(`$env:` + k + "=" + psQuote(v) + "; ")
+ } else {
+ b.WriteString(k + "=" + posixQuote(v) + " ")
+ }
+ }
+ return b.String() + "dima"
+}
+
+func dim(home string) *Agent { return dimIn(here(home)) }
+
+func dimIn(at place) *Agent {
+ file := dimFile()
+ model := jsonGet(file, "model")
+ gw, key := gateway.URL, func() string { return agentKey("dim") }
+ on := func() bool { return usesMagpie(model()) }
+ spec := func() *launchSpec { return dimLaunch(gw(), key(), model()) }
+ shell := func(set bool) {
+ if h, _ := homes(); h != at.home {
+ return
+ }
+ if set {
+ update.ShellFunction("dima", spec().function)
+ } else {
+ update.DropShellFunction("dima")
+ }
+ }
+ shellIn := func() []string {
+ if h, _ := homes(); h != at.home {
+ return nil
+ }
+ return update.ShellFunctionIn("dima")
+ }
+ launch := func() string { return dimCommand(gw(), key(), model(), runtime.GOOS == "windows") }
+ return &Agent{
+ ID: "dim", Name: "Dim", Icon: "dim-color", Aliases: []string{"dima", "dimcode-alpha"}, Spelled: prefixed, NoNames: true,
+ Bin: "dima", Dir: dimDir(at), Path: file,
+ Launch: func() string {
+ if !on() {
+ return ""
+ }
+ return launch()
+ },
+ Typed: func() string {
+ if !on() || len(shellIn()) == 0 {
+ return ""
+ }
+ return "dima"
+ },
+ Start: func() Starting {
+ s := Starting{Bin: "dima"}
+ if v := model(); on() {
+ s.Env, s.Model = spec().vars(gw(), key()), v
+ }
+ return s
+ },
+ Sync: func() error {
+ shell(on())
+ return nil
+ },
+ Notice: func() string {
+ if !on() {
+ return ""
+ }
+ if in := shellIn(); len(in) > 0 {
+ for i := range in {
+ in[i] = update.TildeHome(in[i])
+ }
+ return noticeLaunchTyped.say("agent", "Dim", "bin", "dima", "profiles", strings.Join(in, ", "), "command", launch())
+ }
+ return noticeLaunch.say("agent", "Dim", "command", launch())
+ },
+ Fields: []Field{{
+ Key: "model", Label: "model",
+ Get: func() string {
+ if v := model(); usesMagpie(v) {
+ return v
+ }
+ return ""
+ },
+ Set: func(v string) error {
+ if ref, ok := strings.CutPrefix(v, magpieID+"/"); ok && isMagpie(ref) {
+ if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
+ return err
+ }
+ if err := edit.SetJSON(file, edit.KV{Path: "model", Value: v}); err != nil {
+ return err
+ }
+ shell(true)
+ return nil
+ }
+ // Dim's own model is its own to pick: magpie steps out
+ if err := os.Remove(file); err != nil && !os.IsNotExist(err) {
+ return err
+ }
+ shell(false)
+ return nil
+ },
+ Options: func(map[string]string) []Option {
+ return withVia(nil, "dim", magpieID+"/")
+ },
+ }},
+ }
+}
diff --git a/internal/agent/dim_test.go b/internal/agent/dim_test.go
new file mode 100644
index 000000000..fc5b2a9de
--- /dev/null
+++ b/internal/agent/dim_test.go
@@ -0,0 +1,159 @@
+package agent
+
+import (
+ "os"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "strings"
+ "testing"
+
+ "github.com/yetone/magpie/internal/gateway"
+ "github.com/yetone/magpie/internal/provider"
+ "github.com/yetone/magpie/internal/update"
+)
+
+// Dim alpha is started on magpie through the variables Dim documents for
+// an OpenAI-compatible endpoint; the model is in magpie's own file, and
+// nothing of Dim's (its home, settings, database or account) is written.
+func TestDim(t *testing.T) {
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("USERPROFILE", home)
+ t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
+ t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
+ t.Setenv("DIMCODE_HOME", "")
+ t.Setenv("SHELL", "/bin/zsh")
+ t.Setenv("ZDOTDIR", "")
+ if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}}); err != nil {
+ t.Fatal(err)
+ }
+ // Dim's own home, with a settings file of the user's
+ dimHome := filepath.Join(home, ".dimcode-alpha")
+ os.MkdirAll(dimHome, 0o755)
+ own := filepath.Join(dimHome, "settings.json")
+ os.WriteFile(own, []byte(`{"theme":"dark"}`), 0o644)
+ zshrc := filepath.Join(home, ".zshrc")
+ os.WriteFile(zshrc, []byte("export A=1\n"), 0o644)
+
+ a, err := Find("dim")
+ if err != nil || a.Bin != "dima" || a.Dir != dimHome {
+ t.Fatalf("find: %+v %v", a, err)
+ }
+ if b := Starter("dima"); b == nil || b.ID != "dim" {
+ t.Fatalf("starter dima: %v", b)
+ }
+ if a.Launch() != "" || a.Start().Model != "" || a.Notice() != "" {
+ t.Fatalf("on magpie before a pick: %q %+v %q", a.Launch(), a.Start(), a.Notice())
+ }
+ if err := a.Apply("model", "magpie/deepseek/pro"); err != nil {
+ t.Fatal(err)
+ }
+ if got := a.Field("model").Get(); got != "magpie/deepseek/pro" {
+ t.Fatalf("model %q", got)
+ }
+ s := a.Start()
+ if s.Bin != "dima" || s.Model != "magpie/deepseek/pro" || s.Flag != "" || len(s.Args) != 0 {
+ t.Fatalf("start %+v", s)
+ }
+ env := map[string]string{}
+ for _, kv := range s.Env {
+ k, v, _ := strings.Cut(kv, "=")
+ env[k] = v
+ }
+ for k, want := range map[string]string{
+ "DIM_BASE_URL": gateway.URL() + "/v1",
+ "DIM_API_FORMAT": "openai-compatible",
+ "DIM_API_KEY": gateway.TokenFor("dim"),
+ "DIM_MODEL": "deepseek/pro",
+ } {
+ if env[k] != want {
+ t.Fatalf("%s = %q, want %q (%v)", k, env[k], want, s.Env)
+ }
+ }
+ // Dim refuses a model it doesn't know without both limits
+ for _, k := range []string{"DIM_MAX_CONTEXT_TOKENS", "DIM_MAX_OUTPUT_TOKENS"} {
+ if env[k] == "" || env[k] == "0" {
+ t.Fatalf("%s missing: %v", k, s.Env)
+ }
+ }
+ if !strings.Contains(a.Launch(), "DIM_MODEL='deepseek/pro'") || !strings.HasSuffix(a.Launch(), "dima") {
+ t.Fatalf("launch %q", a.Launch())
+ }
+ // the function dima is in the user's shells (zsh's on macOS, where it
+ // is always there), and the notice says to type it
+ in := update.ShellFunctionIn("dima")
+ if runtime.GOOS == "darwin" && !slices.Contains(in, zshrc) {
+ t.Fatalf("function in %v", in)
+ }
+ if slices.Contains(in, zshrc) {
+ b, _ := os.ReadFile(zshrc)
+ if !strings.Contains(string(b), "dima() {") || !strings.Contains(string(b), " dim run ") || !strings.HasPrefix(string(b), "export A=1\n") {
+ t.Fatalf(".zshrc:\n%s", b)
+ }
+ }
+ if len(in) > 0 && (a.Typed() != "dima" || !strings.Contains(a.Notice(), "Type dima")) {
+ t.Fatalf("typed %q notice %q", a.Typed(), a.Notice())
+ }
+ if !strings.Contains(a.Notice(), "DIM_API_FORMAT") {
+ t.Fatalf("notice %q", a.Notice())
+ }
+ // the options are magpie's models
+ var vals []string
+ for _, o := range a.Field("model").Options(a.Values()) {
+ vals = append(vals, o.Value)
+ }
+ if !slices.Contains(vals, "magpie/deepseek/pro") || !slices.Contains(vals, "magpie/deepseek/flash") {
+ t.Fatalf("options %v", vals)
+ }
+
+ // back to Dim's own: magpie's file and the function are gone, the
+ // profile is as it was
+ if err := a.Apply("model", ""); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := os.Stat(dimFile()); !os.IsNotExist(err) {
+ t.Fatalf("dim.json kept: %v", err)
+ }
+ if update.ShellFunctionIn("dima") != nil {
+ t.Fatalf("function kept in %v", update.ShellFunctionIn("dima"))
+ }
+ if b, _ := os.ReadFile(zshrc); string(b) != "export A=1\n" {
+ t.Fatalf(".zshrc after:\n%s", b)
+ }
+ if a.Launch() != "" || a.Start().Model != "" || a.Field("model").Get() != "" {
+ t.Fatalf("still on magpie: %q %+v", a.Launch(), a.Start())
+ }
+ // nothing of Dim's was written or made
+ if b, _ := os.ReadFile(own); string(b) != `{"theme":"dark"}` {
+ t.Fatalf("Dim's settings written: %s", b)
+ }
+ ents, _ := os.ReadDir(dimHome)
+ if len(ents) != 1 {
+ t.Fatalf("Dim's home holds %v", ents)
+ }
+}
+
+// DIMCODE_HOME moves Dim's folder; it is used as given, as Dim does.
+func TestDimHome(t *testing.T) {
+ home := t.TempDir()
+ at := here(home)
+ t.Setenv("DIMCODE_HOME", "")
+ if d := dimDir(at); d != filepath.Join(home, ".dimcode-alpha") {
+ t.Fatalf("dir %q", d)
+ }
+ other := filepath.Join(home, "elsewhere")
+ t.Setenv("DIMCODE_HOME", other)
+ if d := dimDir(at); d != other {
+ t.Fatalf("dir %q", d)
+ }
+}
+
+// A model the catalog knows no limits of still gets both, the output no
+// larger than the context.
+func TestDimLimits(t *testing.T) {
+ ctx, out := dimLimits("magpie/nobody/none")
+ if ctx <= 0 || out <= 0 || out > ctx {
+ t.Fatalf("limits %d %d", ctx, out)
+ }
+}
diff --git a/internal/agentenv/agentenv.go b/internal/agentenv/agentenv.go
index 0bd8627a2..6ed34c97c 100644
--- a/internal/agentenv/agentenv.go
+++ b/internal/agentenv/agentenv.go
@@ -91,6 +91,8 @@ var Vars = []string{
"KUN_DATA_DIR",
// AstrBot's root, the folder holding its data/ (else ~/.astrbot, the desktop app's)
"ASTRBOT_ROOT",
+ // Dim alpha's folder (dima), ~/.dimcode-alpha without it
+ "DIMCODE_HOME",
// Mistral Vibe's folder (config.toml, skills, AGENTS.md), ~/.vibe without it
"VIBE_HOME",
// jcode's folder, ~/.jcode without it
diff --git a/internal/cli/start_cli_test.go b/internal/cli/start_cli_test.go
index 5555606ce..8e0bfa4ce 100644
--- a/internal/cli/start_cli_test.go
+++ b/internal/cli/start_cli_test.go
@@ -104,3 +104,72 @@ func TestAgyRun(t *testing.T) {
t.Fatalf("no agy: %v", err)
}
}
+
+// `magpie dim run`, what the function dima runs: the dima on PATH with
+// the variables Dim documents for an OpenAI-compatible endpoint while
+// magpie's dim.json names a magpie model, every argument dima's (a
+// subcommand first, so no --model is put before it); as it is otherwise.
+func TestDimRun(t *testing.T) {
+ home := helpHome(t)
+ t.Setenv("DIM_API_KEY", "users-own")
+ t.Setenv("DIM_MODEL", "")
+ var bin, name string
+ var args, env []string
+ oldExec, oldLook := startExec, startLook
+ t.Cleanup(func() { startExec, startLook = oldExec, oldLook })
+ startExec = func(b, n string, a, e []string) error {
+ bin, name, args, env = b, n, a, e
+ return nil
+ }
+ real := filepath.Join(home, "bin", "dima")
+ startLook = func(b string) (string, error) {
+ if b != "dima" {
+ return "", errors.New("looked for " + b)
+ }
+ return real, nil
+ }
+ envOf := func(k string) []string {
+ var out []string
+ for _, kv := range env {
+ if strings.HasPrefix(kv, k+"=") {
+ out = append(out, strings.TrimPrefix(kv, k+"="))
+ }
+ }
+ return out
+ }
+ file := filepath.Join(home, ".config", "magpie", "dim.json")
+ os.MkdirAll(filepath.Dir(file), 0o755)
+ os.WriteFile(file, []byte(`{"model": "magpie/deepseek/pro"}`), 0o644)
+ for _, in := range [][]string{nil, {"exec", "-p", "hi"}, {"--help"}} {
+ if _, err := runOut(t, append([]string{"dim", "run"}, in...)...); err != nil {
+ t.Fatal(err)
+ }
+ if bin != real || name != "dima" || !slices.Equal(args, in) {
+ t.Fatalf("dim run %v: %s %s %v", in, bin, name, args)
+ }
+ for k, want := range map[string]string{
+ "DIM_BASE_URL": gateway.URL() + "/v1", "DIM_API_FORMAT": "openai-compatible",
+ "DIM_API_KEY": gateway.TokenFor("dim"), "DIM_MODEL": "deepseek/pro",
+ } {
+ if got := envOf(k); !slices.Equal(got, []string{want}) {
+ t.Fatalf("%s = %v, want %s", k, got, want)
+ }
+ }
+ if c, o := envOf("DIM_MAX_CONTEXT_TOKENS"), envOf("DIM_MAX_OUTPUT_TOKENS"); len(c) != 1 || len(o) != 1 || c[0] == "0" || o[0] == "0" {
+ t.Fatalf("limits %v %v", c, o)
+ }
+ }
+ out, err := runOut(t, "dim", "env")
+ if err != nil || !strings.Contains(out, "DIM_API_FORMAT=openai-compatible\n") || !strings.HasSuffix(out, "model=magpie/deepseek/pro\n") {
+ t.Fatalf("dim env: %q %v", out, err)
+ }
+
+ // off magpie: dima as it is, with the user's own environment
+ os.Remove(file)
+ if _, err := runOut(t, "dim", "run", "exec", "-p", "hi"); err != nil {
+ t.Fatal(err)
+ }
+ if !slices.Equal(args, []string{"exec", "-p", "hi"}) || !slices.Equal(envOf("DIM_API_KEY"), []string{"users-own"}) || len(envOf("DIM_API_FORMAT")) != 0 {
+ t.Fatalf("off magpie: %v %v", args, envOf("DIM_API_KEY"))
+ }
+}
diff --git a/internal/gui/assets/icons/dim-color.svg b/internal/gui/assets/icons/dim-color.svg
new file mode 100644
index 000000000..4684d343a
--- /dev/null
+++ b/internal/gui/assets/icons/dim-color.svg
@@ -0,0 +1 @@
+
diff --git a/internal/library/every_agent_test.go b/internal/library/every_agent_test.go
index aeba2c30f..4900976ff 100644
--- a/internal/library/every_agent_test.go
+++ b/internal/library/every_agent_test.go
@@ -52,6 +52,7 @@ var noLibrary = map[string]string{
"paimon": "not looked at (#5897)",
"shelley": "not looked at (#5897)",
"kun": "not looked at (#5897)",
+ "dim": "not looked at (#5897)",
}
func TestEveryAgentInLibrary(t *testing.T) {