agent: agy's own /model pick no longer costs settings.json its model, and each thinking level is a model in agy (LolingVerse on X)

agy's /model writes its pick into settings.json ("model": "magpie/…")
even when started with --settings magpie-settings.json. The next Sync's
migrate took that for an older magpie's wiring and put back the old
stash: a stale model and "modelProvider": "gemini", or nothing, which
took the user's own model and provider out. That is the wrong restore
point the reporter saw. While magpie-settings.json is already on one of
magpie's models, such a pick is now moved into magpie's file (what agy
starts on next), and settings.json's model goes back to the one
connect.was kept when magpie was switched on, or out. The old stash is
no longer read for it.

agy 1.5.9 turns /effort away for every custom model, one with a
thinkingLevel too. A custom model's thinkingLevel takes low, medium or
high, and agy sends it as generationConfig.thinkingConfig.thinkingLevel,
which the gateway already asks over the row's effort (agyLevelAsked). A
model with two or more of those levels now has a custom model per
level, magpie/<ref>:<level>. The row's model field shows such a pick as
its model, so the switch stays on (agyLevelOf).

Run:
- TestAgyOwnPickKeepsSettings is red on the old agy.go. The levels part
  fails with "level low:". The pick part, with the levels cut out,
  fails with settings.json {"model":"stale","modelProvider":"gemini"}.
  It is green on the new code.
- go test -count=1 ./internal/agent ./internal/cli on mote: ok (agent 259s, cli 67s) at base 139a6be2b.
- GOOS=linux go vet ./internal/agent and GOOS=windows go vet of both packages (cli's Linux vet needs cgo for Wails on a Mac); gofmt -l is
  clean.
- Real agy 1.5.9 in a sandbox HOME against a fake Gemini endpoint:
  - /model lists magpie/openai/gpt-5.5:low/:medium/:high;
  - picking :high wrote settings.json "model" and sent
    thinkingLevel "HIGH" with model openai/gpt-5.5;
  - /effort still says "Effort isn't adjustable" for custom models.

Not tried: a real magpie gateway and account behind agy (the fake
endpoint stood in), and Windows or a WSL distro.

Not changed: the agent-agy plugin has the same two gaps
(magpie-community/plugins#1188). The switch turning itself off didn't
reproduce on the built-in or the plugin.
This commit is contained in:
yetone
2026-11-15 23:19:21 +08:00
parent 139a6be2bb
commit 99a54fa874
3 changed files with 195 additions and 5 deletions
+1 -1
View File
@@ -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 <distro> -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.<model>.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:<id>:<path>` (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. 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) |
| 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. A model of magpie's in `settings.json` while `magpie-settings.json` is already on magpie's is agy's own `/model` pick, which agy writes there even under `--settings`: it moves into magpie's file, and `settings.json`'s model goes back to the one `connect.was` kept (the user's own) or out; the old stash isn't read for it, which put a stale model and `modelProvider: gemini` back or took the user's out (LolingVerse on X, `TestAgyOwnPickKeepsSettings`). agy's `/effort` is turned away for every custom model, so a model with two or more of low, medium and high gets a custom model per level too, `magpie/<ref>:<level>` with `thinkingLevel` (the only levels agy 1.5.9 takes there), which agy sends as `thinkingConfig.thinkingLevel` and the gateway asks over the row's (`agyLevelAsked`); the row's model field shows such a pick as its model (`agyLevelOf`). `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 <id> 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=<file>`, 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-<distro>.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:<gateway port>` 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:<port>/<WSL key>`, 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 `<config>/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 <file> 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) |
+78 -4
View File
@@ -25,6 +25,10 @@ package agent
// stays the user's, and a plain agy, and `agy remote-control` or
// --remote-control through the function, run on their Google sign-in.
//
// A model that takes two or more of low, medium and high is listed once
// more per level, "magpie/<ref>:<level>" with that thinkingLevel, the
// thinking depth picked in agy's /model (agyLevels).
//
// So that typing agy just works (bestony on Discord: the command was
// copied at each start), magpie puts a function named agy in the profile
// of each shell the user has, between "# >>> magpie agy >>>" and
@@ -42,6 +46,7 @@ import (
"path"
"path/filepath"
"runtime"
"slices"
"sort"
"strings"
@@ -238,7 +243,8 @@ func agyIn(at place) *Agent {
settingsModel, overModel := jsonGet(path, "model"), jsonGet(over, "model")
provider := jsonGet(over, "modelProvider")
// the model is magpie's while its own file names one; a settings.json
// still wired by an older magpie says so too, until migrate moves it
// still wired by an older magpie says so too, until migrate moves it.
// It is the custom model's key, a level's (agyLevelKey) too.
get := func() string {
if m := overModel(); usesMagpie(m) {
return m
@@ -269,6 +275,9 @@ func agyIn(at place) *Agent {
ms := ownModels()
for _, m := range sharedModels("agy") {
ms[magpieID+"/"+m.ID] = map[string]string{"apiProvider": "API_PROVIDER_GOOGLE_GEMINI", "modelName": m.ID}
for _, l := range agyLevels(m.Efforts) {
ms[agyLevelKey(magpieID+"/"+m.ID, l)] = map[string]string{"apiProvider": "API_PROVIDER_GOOGLE_GEMINI", "modelName": m.ID, "thinkingLevel": l}
}
}
if err := os.MkdirAll(dir, 0o755); err != nil {
return err
@@ -283,12 +292,25 @@ func agyIn(at place) *Agent {
}
// migrate takes what an older magpie wrote into settings.json out of
// it, the user's model and provider back; it returns the model that
// was magpie's there, "" when settings.json was never wired
// was magpie's there, "" when settings.json was never wired.
//
// While magpie's own file is on one of magpie's, a model of magpie's
// in settings.json is not an older magpie's: it is agy's /model, which
// writes the pick into settings.json, --settings or not. That pick is
// kept in magpie's file (it is what agy starts on next) and
// settings.json's model goes back to what it was when magpie was
// switched on (connect.was), or out of it. The old stash is never read
// for it: one left from an older magpie, or none, put a stale model and
// provider into settings.json or took the user's out of it
// (LolingVerse on X).
migrate := func() (string, error) {
m := settingsModel()
if !usesMagpie(m) {
return "", nil
}
if usesMagpie(overModel()) {
return m, put("model", agyConnectWas())
}
if err := put("modelProvider", unstash(stashProvider)); err != nil {
return m, err
}
@@ -412,13 +434,14 @@ func agyIn(at place) *Agent {
},
Fields: []Field{{
Key: "model", Label: "model",
Get: get,
// a level's custom model is its model's, the level agy's
Get: func() string { return agyLevelOf(get()) },
Set: func(v string) error {
if _, err := migrate(); err != nil {
return err
}
cur := overModel()
if ref, ok := strings.CutPrefix(v, magpieID+"/"); ok && isMagpie(ref) {
if ref, ok := strings.CutPrefix(agyLevelOf(v), magpieID+"/"); ok && isMagpie(ref) {
if err := writeOver(v); err != nil {
return err
}
@@ -463,6 +486,57 @@ func agyIn(at place) *Agent {
}
}
// agyLevelNames are the levels a custom model of agy's takes as its
// thinkingLevel, weakest first: agy 1.5.9 takes low, medium and high
// ("customModels %q: ignoring thinkingLevel %q (want low, medium, or
// high)") and asks the model at it (generationConfig.thinkingConfig.
// thinkingLevel), which the gateway asks for over the row's
// (agyLevelAsked).
var agyLevelNames = []string{"low", "medium", "high"}
// agyLevels are the levels of efforts agy's custom models can ask, weakest
// first: none unless two or more, as one is no choice.
func agyLevels(efforts []string) []string {
var out []string
for _, l := range agyLevelNames {
if slices.ContainsFunc(efforts, func(e string) bool { return strings.EqualFold(e, l) }) {
out = append(out, l)
}
}
if len(out) < 2 {
return nil
}
return out
}
// agyLevelKey is the key of the custom model that asks key's model at
// level. agy's /effort is turned away for every custom model, one with a
// thinkingLevel too ("Effort isn't adjustable for …", agy 1.5.9), and its
// /model lists custom models by key, so each level is one of its own
// there (LolingVerse on X: no thinking depth in agy).
func agyLevelKey(key, level string) string { return key + ":" + level }
// agyLevelOf is the key of the model a level's custom model asks: key
// without its level; key as it is otherwise.
func agyLevelOf(key string) string {
i := strings.LastIndex(key, ":")
if i < 0 || !slices.Contains(agyLevelNames, key[i+1:]) || !usesMagpie(key) {
return key
}
return key[:i]
}
// agyConnectWas is the model agy was on when magpie was switched on for
// it, when it was the user's own; "" otherwise.
func agyConnectWas() string {
var was map[string]string
json.Unmarshal([]byte(unstashPeek("agy.connect.was")), &was)
if m := was["model"]; !usesMagpie(m) {
return m
}
return ""
}
// agyEffortField is effortField for agy.
func agyEffortField(on func() bool) Field { return effortField("agy", on) }
+116
View File
@@ -0,0 +1,116 @@
package agent
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"github.com/tidwall/gjson"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// LolingVerse on X: picking a model in agy's own /model, which writes it
// into settings.json, cost the user their own model and provider there.
// magpie's next Sync took a model of magpie's in settings.json for an
// older magpie's wiring and put back that wiring's stash: a stale one, or
// none, which took the user's own out. Now it is agy's pick, kept in
// magpie's file, and settings.json is given back as it was when magpie
// was switched on. And no thinking depth in agy: /effort is turned away
// for custom models, so each level a model takes is a custom model of
// its own, asking it at that level (thinkingLevel), and the row still
// shows the model, on magpie.
func TestAgyOwnPickKeepsSettings(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"))
if err := provider.Save(provider.Provider{ID: "think", Name: "Think", Chat: "https://think.test/v1", Key: "key", Models: []string{"m1", "m2"}}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("think", "https://think.test/v1", []catalog.Model{{ID: "m1", Efforts: []string{"low", "medium", "high", "xhigh"}}, {ID: "m2", Efforts: []string{"high"}}}); err != nil {
t.Fatal(err)
}
path := filepath.Join(home, ".gemini", "antigravity-cli", "settings.json")
os.MkdirAll(filepath.Dir(path), 0o755)
os.WriteFile(path, []byte(`{"model":"mine","modelProvider":"vertex","trustedWorkspaces":["/w"]}`), 0o644)
// an older magpie's stash, left behind
stash(map[string]string{"agy:" + path + ":model": "stale", "agy:" + path + ":modelProvider": "gemini"})
a, err := Find("agy")
if err != nil {
t.Fatal(err)
}
if err := a.Connect(); err != nil {
t.Fatal(err)
}
over := filepath.Join(filepath.Dir(path), agyOverride)
base := gjson.Get(agyRead(t, over), "model").String()
if !strings.HasPrefix(base, "magpie/think/") {
t.Fatalf("connected on %q", base)
}
// each level m1 takes that agy has, its own custom model; m2 has one
// level, which is no choice
cm := gjson.Get(agyRead(t, over), "customModelsConfig.customModels")
for _, l := range []string{"low", "medium", "high"} {
e := cm.Get(gjson.Escape("magpie/think/m1:" + l))
if e.Get("modelName").String() != "think/m1" || e.Get("thinkingLevel").String() != l {
t.Fatalf("level %s: %s", l, e.Raw)
}
}
if cm.Get(gjson.Escape("magpie/think/m1:xhigh")).Exists() || cm.Get(gjson.Escape("magpie/think/m2:high")).Exists() || cm.Get(gjson.Escape("magpie/think/m1")).Get("thinkingLevel").Exists() {
t.Fatalf("custom models: %s", cm.Raw)
}
// agy's /model writes its pick into settings.json
b, _ := os.ReadFile(path)
var s map[string]any
json.Unmarshal(b, &s)
s["model"] = "magpie/think/m1:high"
b, _ = json.Marshal(s)
os.WriteFile(path, b, 0o644)
if err := a.Sync(); err != nil {
t.Fatal(err)
}
got := agyRead(t, path)
if gjson.Get(got, "model").String() != "mine" || gjson.Get(got, "modelProvider").String() != "vertex" || !gjson.Get(got, "trustedWorkspaces").Exists() {
t.Fatalf("settings.json not the user's:\n%s", got)
}
if m := gjson.Get(agyRead(t, over), "model").String(); m != "magpie/think/m1:high" {
t.Fatalf("agy's pick not kept: %q", m)
}
if !strings.Contains(a.Launch(), "--model 'magpie/think/m1:high'") {
t.Fatalf("launch: %q", a.Launch())
}
if got := a.Field("model").Get(); got != "magpie/think/m1" {
t.Fatalf("row's model: %q", got)
}
if !a.Wired() || a.Drift() != nil || a.Check() != "" {
t.Fatalf("not on magpie: wired %v, drift %+v, check %q", a.Wired(), a.Drift(), a.Check())
}
// the user's own model picked in agy stays theirs, magpie stays on
s["model"] = "gemini-3.1-pro"
b, _ = json.Marshal(s)
os.WriteFile(path, b, 0o644)
if err := a.Sync(); err != nil {
t.Fatal(err)
}
if gjson.Get(agyRead(t, path), "model").String() != "gemini-3.1-pro" || !a.Wired() {
t.Fatalf("own pick: %s wired %v", agyRead(t, path), a.Wired())
}
// switched off: magpie's file gone, settings.json the user's
if err := a.Disconnect(); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(over); err == nil {
t.Fatal("magpie's file left")
}
if got := agyRead(t, path); gjson.Get(got, "modelProvider").String() != "vertex" {
t.Fatalf("after switching off:\n%s", got)
}
}