agent: Grok App's own route picked in magpie is taken, and Disconnect can put one back; a sync that isn't connected writes nothing (#1625)
Follow-up to fjrtdk's commit before this one, which this keeps: magpie never names itself as Grok App's route. - Set refused every own route (errGrokAppRoute) while Options still offered them, so the picker showed choices that only errored. It also broke Disconnect: when unwire leaves no route (Use set it to magpie, nothing stashed), Disconnect sets connect.was's route back through Set, got the error and stopped half done. An own route now takes magpie's channel out and is written as [models] default, the way picking another provider leaves magpie on other agents. That route can't be magpie, so the App's sign-in is never touched. - Sync ran rememberRoute/releaseRoute before checking for the channel, so every user with Grok App installed but not connected got stash entries. Now it returns before them unless the channel is there or the route is still magpie (an older magpie's takeover to put back). - Check again warns when the route is magpie and the channel is gone, which that commit dropped. - The notice uses the App's own labels (Settings › Account, Use; ja 「使う」, de Einstellungen › Konto / Verwenden, from grok-app 0.2.40's settings.nav.account and prov.useThis) and says a chat can pick magpie's models in its model picker (composer_prefs_set, which doesn't move the route). - Sibling: rtk init has no grok agent for Grok Build either (rtk 311ebcb agents: claude codex copilot cursor droid gemini hermes opencode pi trae vibe antigravity), so Grok Build is in rtkNoHook too. Run: gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and GOOS=windows clean; go test ./internal/gateway ./internal/agent ./internal/library -count=1 pass; node --test i18n-keys and agent-notice-lang pass. Broken by hand: that commit's grokapp.go fails TestGrokAppOwnRouteStays, TestGrokAppDisconnectPutsTheRouteBack and TestGrokAppSyncUnconnected; dropping the Check branch fails TestGrokAppSyncUnconnected; dropping rtkNoHook["grok"] fails TestRTKNoHookGrokBuild. Not tried: the Grok App GUI itself; the config format and behaviour are from grok-app 0.2.40's source. Co-authored-by: fjrtdk <fjrtdk@gmail.com>
This commit is contained in:
+1
-1
@@ -129,7 +129,7 @@ line; agents connected to magpie lose it when it quits.
|
||||
| Qoder (CLI) | `~/.qoder/settings.json` (`$QODER_CONFIG_DIR`) | model, effort (a `magpie` custom provider; needs a Qoder plan with BYOK) |
|
||||
| Qoder CN (CLI) | `~/.qoder-cn/settings.json` (`$QODERCN_CONFIG_DIR`) | model, effort (as Qoder; its own accounts, a Qoder CN plan with BYOK) |
|
||||
| Grok Build | `~/.grok/config.toml` (`$GROK_HOME`) | model, effort |
|
||||
| Grok App | `agent-home/config.toml` in its data folder (`$GROK_APP_HOME`, else `~/Library/Application Support/com.grokapp.grok-app`, `%APPDATA%\grokapp\grok-app\data`, `$XDG_DATA_HOME/grok-app`, or `~/.grok-app`) | model (a `[model.magpie]` custom provider under Accounts, with magpie's models and their effort levels in `app_models`; the route, `[models] default`, stays until the user presses Use on magpie there; a route an older magpie set to `magpie` is put back once; Disconnect drops the channel and puts the route back only if it is still `magpie`; a model or default effort picked in the App kept; instructions, MCP and skills are the Library's Grok App row on agent-home; RTK has no hook) |
|
||||
| Grok App | `agent-home/config.toml` in its data folder (`$GROK_APP_HOME`, else `~/Library/Application Support/com.grokapp.grok-app`, `%APPDATA%\grokapp\grok-app\data`, `$XDG_DATA_HOME/grok-app`, or `~/.grok-app`) | model (a `[model.magpie]` custom provider under Accounts, with magpie's models and their effort levels in `app_models`; the route, `[models] default`, stays until the user presses Use on magpie there (one of the App's own routes picked in magpie is written as the route, and magpie's channel goes); a route an older magpie set to `magpie` is put back once; Disconnect drops the channel and puts the route back only if it is still `magpie`, else the one it was on before Connect if none is left; a model or default effort picked in the App kept; instructions, MCP and skills are the Library's Grok App row on agent-home; RTK has no hook for it or for Grok Build) |
|
||||
| ZCode | `~/.zcode/v2/config.json` | provider (magpie's models in ZCode's picker) |
|
||||
| WorkBuddy | `~/.workbuddy/models.json` (`$WORKBUDDY_CONFIG_DIR`) | provider (magpie's models in WorkBuddy's picker) |
|
||||
| WorkBuddy AI | `~/.workbuddy-ai/models.json` (the international build) | provider (magpie's models in WorkBuddy AI's picker) |
|
||||
|
||||
@@ -44,7 +44,7 @@ something else shows up as drift.
|
||||
- Ante's `catalog.json` keeps user-added fields in `providers.magpie` the same way (`ante` in [`ante.go`](../../internal/agent/ante.go)); its `auth`, `http_headers`, `extra_body` and `stream_idle_timeout_secs` are what a gateway shared on the local network or reached from WSL needs to send a key. Ante starts a session on the `provider` and `model` of `settings.json`, not on what its catalog holds (#1210), so magpie sets that pair and puts back what it found there; a pick the user makes in Ante while magpie is wired is theirs and stands.
|
||||
- AstrBot keeps its providers in `data/cmd_config.json` under its root (`$ASTRBOT_ROOT`, else `~/.astrbot`, the desktop app's, else `~/astrbot`), written with a UTF-8 BOM, which magpie keeps (`astrbot` in [`astrbot.go`](../../internal/agent/astrbot.go)). magpie adds a `magpie` entry to `provider_sources` and one `magpie/<model>` entry per model to `provider`, keeps the user's own entries byte for byte and keeps what the user changes in magpie's (timeout, proxy, enable), and sets the default chat model (`agent_runner.config.model.provider_id`, or `provider_settings.default_provider_id` before the agent runner), putting back what it found there. A pick the user makes while magpie is wired is theirs and stands. The first connect copies the file to `cmd_config.json.before-magpie`. AstrBot reads the file only at start-up and its WebUI writes it back whole on save, so the agent's notice says to restart AstrBot before saving in the WebUI. A Docker install's root is inside its container, which magpie doesn't reach.
|
||||
- jcode keeps its settings in `config.toml` in `$JCODE_HOME`, else `~/.jcode` (`jcode` in [`jcode.go`](../../internal/agent/jcode.go)). magpie adds a named profile, `[providers.magpie]`, as `jcode provider add` writes one: `type = "openai-compatible"`, the gateway's `/v1`, an inline `api_key` naming jcode (jcode sends nothing else that tells it apart) and `requires_api_key = true`, since jcode sends no key to a loopback URL without it. Its `models` list has one entry per model, with `context_window`, `input` and `reasoning` for a model with effort levels. A `reasoning_effort` the user set on one stays while the model has that level. The model jcode starts on is `[provider] default_provider = "magpie"` and `default_model`. What was there is stashed and put back on Disconnect. A model of jcode's own picked while it is on magpie takes magpie out. Each key is set alone, so the user's other keys and tables stay, and the `[[providers.magpie.models]]` tables jcode writes when it saves the file itself are replaced by the one list. A sync with nothing to change doesn't write. Disconnect drops the profile whole, its sub-tables included. jcode reads the file when it starts, so the notice says to restart open sessions.
|
||||
- Grok App (RongleCat/grok-app, a desktop front end that starts Grok Build over ACP) keeps its provider channels in `agent-home/config.toml` under its data folder: `$GROK_APP_HOME`, else where its `directories` crate puts it, or its `~/.grok-app` fallback when that is the one there (`grokApp` in [`grokapp.go`](../../internal/agent/grokapp.go)). Its composer lists only Grok Build's official catalog, never the `[model."magpie/…"]` tables of Grok Build's row, so magpie adds itself as a channel, `[model.magpie]`, with the keys the App's Providers page writes: the gateway's `/v1`, a key naming Grok App, `api_backend = "chat_completions"`, `app_provider_mode = "generic"`, and `app_models`, a JSON list of magpie's models with `contextWindow`, `supportsVision` and their effort levels (no `none`; a default the user marks in the App stays, else medium). The picked model's `context_window` (a bare integer) and `supports_reasoning_effort` (a bare bool, Grok Build's gate for `--reasoning-effort`) are on the channel, as the App puts them there when a model is picked in its composer. `[models] default` is the route, and magpie does not set it: setting it to `"magpie"` makes the App drop its own sign-in (`ensure_independent_for_custom_route`). The route stays whatever the App had. Pressing Use on magpie under Accounts is what switches it. A magpie that already set the route puts the old one back once, on the next sync or connect (`grokAppReleased`); a Use after that stays. Disconnect drops only the channel, and puts the route back only when it is still `"magpie"`. A model picked in the App's composer since is the user's and stays through a sync, and a sync with nothing to change doesn't write. Shared mode keeps `GROK_HOME` at `~/.grok` (Grok Build's library row). Independent mode, which Use turns on, reads agent-home: the Library writes `AGENTS.md`, `[mcp_servers]` in the same `config.toml`, and `skills/` there, and Grok App also reads `~/.agents/skills`. RTK has no Grok hook, so the Library lists Grok App with the switch off. The notice, while the App runs, says magpie is a custom provider and the App stays on its current route until Use.
|
||||
- Grok App (RongleCat/grok-app, a desktop front end that starts Grok Build over ACP) keeps its provider channels in `agent-home/config.toml` under its data folder: `$GROK_APP_HOME`, else where its `directories` crate puts it, or its `~/.grok-app` fallback when that is the one there (`grokApp` in [`grokapp.go`](../../internal/agent/grokapp.go)). Its composer lists only Grok Build's official catalog, never the `[model."magpie/…"]` tables of Grok Build's row, so magpie adds itself as a channel, `[model.magpie]`, with the keys the App's Providers page writes: the gateway's `/v1`, a key naming Grok App, `api_backend = "chat_completions"`, `app_provider_mode = "generic"`, and `app_models`, a JSON list of magpie's models with `contextWindow`, `supportsVision` and their effort levels (no `none`; a default the user marks in the App stays, else medium). The picked model's `context_window` (a bare integer) and `supports_reasoning_effort` (a bare bool, Grok Build's gate for `--reasoning-effort`) are on the channel, as the App puts them there when a model is picked in its composer. `[models] default` is the route, and magpie does not set it: setting it to `"magpie"` makes the App drop its own sign-in (`ensure_independent_for_custom_route`). The route stays whatever the App had. Pressing Use on magpie under Accounts is what switches it. A magpie that already set the route puts the old one back once, on the next sync or connect (`grokAppReleased`); a Use after that stays. Disconnect drops only the channel, and puts the route back only when it is still `"magpie"`: the one stashed at connect, else the one `connect.was` holds. One of the App's own routes picked in magpie's model field is written as the route and takes magpie's channel out, as picking another provider does elsewhere. A sync with no channel and a route other than `"magpie"` writes nothing, magpie's stash included, and Check says so when the route is `"magpie"` with the channel gone. A model picked in the App's composer since is the user's and stays through a sync, and a sync with nothing to change doesn't write. Shared mode keeps `GROK_HOME` at `~/.grok` (Grok Build's library row). Independent mode, which Use turns on, reads agent-home: the Library writes `AGENTS.md`, `[mcp_servers]` in the same `config.toml`, and `skills/` there, and Grok App also reads `~/.agents/skills`. RTK has no Grok hook, so the Library lists Grok App with the switch off. The notice, while the App runs, says magpie is a custom provider in Settings › Account, a chat can pick its models in the model picker, and the App stays on its current route until Use.
|
||||
- JSON/JSONC config edits and their previews reject malformed input rather than editing a partially parsed document. Object edits and VS Code's model-group array edits leave the original file untouched on a parse error; valid comments and trailing commas remain supported (`internal/edit`).
|
||||
- A config that starts with a UTF-8 byte order mark (a Windows `settings.json` or `config.toml` saved by PowerShell, Notepad or a channel switcher, #1534) is read without it (`edit.Read`), and a write keeps it (`keepBOM` in `WriteAtomic`): the user's file keeps the encoding it was saved in. That covers every format `internal/edit` writes (JSON/JSONC and its arrays, TOML, YAML, env); Codex reads a TOML file through a BOM too, so magpie no longer refuses one. A file read some other way trims it with `edit.TrimBOM` (the Claude Code and CC Switch imports). A line an edit takes out of a CRLF file goes with its `\r\n`.
|
||||
- Codex signed in to ChatGPT stays beside its sign-in (`openai_base_url`) unless the user picks magpie API. magpie becomes its provider only while the Codex app holds the active account, which it sends nothing for: `/wham/usage` says it isn't allowed, and it has no credits and isn't a workspace still within its overage (`codexHeld`, read by `provider.CodexUsedUp`). Where the app goes by what usage can't show (an experiment's gate, a reserve, a Team plan's overage under the reserve experiment), it counts as held: a wrong move costs ChatGPT extras, a missed one every turn. A saved reading kept through a failed read stops saying held once its used-up window has started again; a hold with no window used up stays till a fresh read. The app then loses its ChatGPT state (durable threads, remote control), so a window at 100% alone, which credits get past, doesn't move it (`codex.out` marks the move, and Sync undoes it once the account has room).
|
||||
|
||||
@@ -25,7 +25,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
| Skill updates | A skill from GitHub (`kind: github`, a market install among them) keeps the commit it was fetched at and `Hash`, the hash of its files as fetched. `CheckSkills` asks GitHub for each one's last commit and keeps the result in memory; `View.CheckDue` says none was checked since magpie started, or not for `checkEvery` (12 hours), and the page then checks by itself as the skills open (#1449). `editState` says a skill was changed here when the library's folder no longer hashes to `Hash` (`.DS_Store` aside), or an agent's copy was edited since its mark and not yet taken in; the view's `edited` says so. `UpdateSkill` refuses such a skill with `*EditedError` unless told to replace it (the page's own Update asks first; the CLI takes `--replace-edits`), and `UpdateSkills`/`UpdateSomeSkills` leave it as it is, in `Unupdated`. A replaced version that was changed, or that can't be told (no `Hash`), is moved to the backups (`keepReplaced`). Skills the skills CLI manages (`npx skills`, `~/.agents/.skill-lock.json`) are only grouped: the CLI updates them (`npx skills update`). A linked folder, a skill imported from an agent and a `From`-only skill have no remote to check; one CC Switch installed (`Origin`) can be updated by hand but isn't checked. | [`skill_changed.go`](../../internal/library/skill_changed.go), [`skillcheck.go`](../../internal/library/skillcheck.go), [`skills.go`](../../internal/library/skills.go) |
|
||||
| Hooks | A `Hook` (#1790) is a command, an event, an optional matcher, a timeout and the agents ticked for it. Its event is portable (`HookEvents`: turn-end, after-tool, before-tool, prompt, session-start, each under the agent's own name) or an agent's own (`"codex:PermissionRequest"`), which only that agent is given. A portable tool event can be narrowed to shell or edit tools, each agent's own tool names for them. `syncHooks` writes each into the agent's own file and shape (`hookSpecOf`): Claude Code `<claude dir>/settings.json`, Codex `hooks.json` beside its config.toml, Gemini CLI `~/.gemini/settings.json` (timeout in ms), Cursor `~/.cursor/hooks.json` (flat entries, `version: 1`). Every other agent, and an agent in WSL, is refused with why, and the page greys its chip with that reason. The page also says when an agent has every hook turned off (`hooksOff`: Claude Code's `disableAllHooks`, Gemini's `hooksConfig.enabled`, Codex's `[features] hooks`). | [`hooks.go`](../../internal/library/hooks.go) |
|
||||
| Backups | Before a change first writes an agent file, `backups` copies it to `BackupDir`, one folder per change. The last `keepBackups` (30) changes are kept. The Backups button at the top of every tab, beside Library folder, opens that folder (`libHead`; Dade on Discord found it at the foot of a long page). | [`backup.go`](../../internal/library/backup.go) |
|
||||
| RTK | `SetRTK` runs rtk's own installer (`rtk init -g …`) for an agent being switched on. For one being switched off, it removes exactly what the installer wrote, using magpie's own code, which works even with rtk gone. `ReadRTK` reads each agent's files to say which have the hook. `rtkSpec.blocked` stops the installer where it would break an agent. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. A detected agent RTK has no hook for at all is still listed, from `rtkNoHook`, with the reason and a switch that can't be turned on (dsh: its hooks can allow or deny a command but not rewrite it, and `rtk init` has no `--agent dsh`; Grok App: `rtk init` has no Grok or Grok App agent). | [`rtk.go`](../../internal/library/rtk.go) |
|
||||
| RTK | `SetRTK` runs rtk's own installer (`rtk init -g …`) for an agent being switched on. For one being switched off, it removes exactly what the installer wrote, using magpie's own code, which works even with rtk gone. `ReadRTK` reads each agent's files to say which have the hook. `rtkSpec.blocked` stops the installer where it would break an agent. `rtkSpec.env` tells the installer the agent's folder where rtk would pick another: Hermes Agent's is `appdir.HermesHome` (`%LOCALAPPDATA%\hermes` on Windows), which rtk is given as `HERMES_HOME`, since rtk 0.51 knows only `$HERMES_HOME` and `~/.hermes`. A detected agent RTK has no hook for at all is still listed, from `rtkNoHook`, with the reason and a switch that can't be turned on (dsh: its hooks can allow or deny a command but not rewrite it, and `rtk init` has no `--agent dsh`; Grok Build and Grok App: `rtk init` has no Grok or Grok App agent, so both are listed with the switch off). | [`rtk.go`](../../internal/library/rtk.go) |
|
||||
|
||||
## Runtime path
|
||||
|
||||
@@ -55,7 +55,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
- A carried library (`Collect`) has every file of each skill, its templates and other binaries included, up to `maxCarried` (16 MiB) a file and `maxCarriedAll` (32 MiB) in all, chosen smallest first across the skills (`readSkills`), so every skill's text goes before any big file. The total keeps a sealed backup under the 64 MiB a sync reads: the files are base64 twice in it. What is left out is named in `Left`, and `Put` keeps this computer's copy of such a file in the skill it puts (`keepLeft`). [`carry.go`](../../internal/library/carry.go)
|
||||
- WorkBuddy's servers go in `$WORKBUDDY_CONFIG_DIR/mcp.json` (default `~/.workbuddy`; WorkBuddy AI, the international build, keeps its own in `~/.workbuddy-ai`, #1494), and CodeBuddy Code's go in the first of `.mcp.json`, `mcp.json` and `~/.codebuddy.json` that exists, as `resolveMcpFilePath` reads them (#1266). WorkBuddy connects a server only after the user has switched it on once in its own MCP settings. It keeps that approval in `mcp-approvals.json`, keyed by the command, args and env names or the URL's origin, so changing those asks again. magpie never writes the approval, and the servers page says so, by the build's name, when a server is given to WorkBuddy or WorkBuddy AI.
|
||||
- Alma's servers go in `~/.config/alma/mcp.json` on every system (its home, not its data folder), as its own MCP settings write them: `command`/`args`/`env`, or `url`/`headers` with `transport: "sse"` only for SSE (#1292). Alma reads the file as it starts and when its MCP settings refresh, so a server given to it while it runs reaches it after one of those.
|
||||
- Grok App's independent home (Use on a custom provider, `GROK_HOME` at `agent-home` under its data folder) gets instructions in `AGENTS.md`, MCP servers in `[mcp_servers]` of the same `config.toml` magpie's channel is in, and skills in `skills/`, and it also reads `~/.agents/skills`. Shared mode stays on Grok Build's `~/.grok` row. RTK lists Grok App with the switch off: `rtk init` has no Grok agent.
|
||||
- Grok App's independent home (Use on a custom provider, `GROK_HOME` at `agent-home` under its data folder) gets instructions in `AGENTS.md`, MCP servers in `[mcp_servers]` of the same `config.toml` magpie's channel is in, and skills in `skills/`, and it also reads `~/.agents/skills`. Shared mode stays on Grok Build's `~/.grok` row. RTK lists Grok App, and Grok Build, with the switch off: `rtk init` has no Grok agent.
|
||||
- Zed's servers go in `context_servers` of the settings.json magpie sets its model in (`agent.zed`: `~/.config/zed` on macOS, `$XDG_CONFIG_HOME/zed` on Linux, `%APPDATA%\Zed` on Windows, or `$MAGPIE_ZED_CONFIG_DIR`), as `command`/`args`/`env` or `url`/`headers` (`ContextServerSettingsContent`, zed-industries/zed 2c99f547). The file is JSONC: it is edited in place, so the user's comments, other settings and own servers stay, and `enabled`, `remote`, `timeout` and `oauth` in magpie's entry are the user's. Zed speaks streamable HTTP only (its `http.rs` only POSTs), so no SSE. An entry Zed's extensions configure (`settings` and no command or url) is never written over: a server by that name is refused for Zed (`mcpFile.foreign`), and asks for another name. Zed reloads the file as it changes.
|
||||
- An agent with no place for an item is refused by `Takes`, never recorded as given it. The refusal lists the agents here that take that item (`takenBy`), and says where it goes instead (`noPlace`): OpenChamber reads OpenCode's global AGENTS.md, skills folder and opencode.json (its server's `shared.js`), so it gets them from OpenCode; Claude Desktop's chat keeps its instructions in its own settings, with the Claude account, and its Code tab reads Claude Code's. A plugin's agent is refused an item its `agent.library` names no place for, and the refusal names the key its plugin would set.
|
||||
- Removing RTK never uses `rtk init --uninstall`. That command deletes Gemini's `GEMINI.md` whole and removes Claude Code, OpenCode and Cursor together.
|
||||
|
||||
+38
-13
@@ -31,7 +31,6 @@ package agent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -47,11 +46,7 @@ import (
|
||||
const grokAppChannel = "model." + magpieID
|
||||
|
||||
// what Grok App says after a change (notice.go)
|
||||
var noticeGrokApp = newNotice("Magpie is a custom provider under Grok App's Accounts. Grok App stays on its current route until you press Use on magpie there.")
|
||||
|
||||
// errGrokAppRoute is Set's answer when asked to switch Grok App's route.
|
||||
// The route is the App's, from Accounts › Use, not from magpie's model field.
|
||||
var errGrokAppRoute = errors.New("Grok App keeps its own route. Magpie is a custom provider under Accounts — press Use on it there to switch")
|
||||
var noticeGrokApp = newNotice("Magpie is a custom provider in Grok App's Settings › Account. A chat can pick magpie's models in its model picker, and Grok App stays on its current route until you press Use on magpie there.")
|
||||
|
||||
// grokAppReleased marks that this magpie has already put back a route an
|
||||
// older one set to magpie. One restore: a Use the user presses after that
|
||||
@@ -338,24 +333,33 @@ func grokApp(home string) *Agent {
|
||||
return ""
|
||||
},
|
||||
Sync: func() error {
|
||||
// Nothing of magpie's in the App: nothing to keep, nothing
|
||||
// written. A route an older magpie left on itself is still
|
||||
// put back, since the App doesn't run on it.
|
||||
def, ch, err := grokAppRead(path)
|
||||
if err != nil || (ch == nil && def != magpieID) {
|
||||
return err
|
||||
}
|
||||
if err := rememberRoute(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := releaseRoute(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, ch, err := grokAppRead(path)
|
||||
if err != nil || ch == nil {
|
||||
return err
|
||||
if ch == nil {
|
||||
return nil
|
||||
}
|
||||
return wire("")
|
||||
},
|
||||
Check: func() string {
|
||||
_, ch, err := grokAppRead(path)
|
||||
def, ch, err := grokAppRead(path)
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
if ch == nil {
|
||||
if def == magpieID {
|
||||
return "Grok App's route is magpie, but its [" + grokAppChannel + "] (config.toml) is gone, so it no longer reaches magpie"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
return wiringOff("Grok App", path, func(k string) (string, bool) { v, ok := ch[k]; return v, ok },
|
||||
@@ -364,8 +368,10 @@ func grokApp(home string) *Agent {
|
||||
Fields: []Field{{
|
||||
// the model on magpie's custom provider, not the route the App
|
||||
// starts on. One of magpie's models is magpie/<provider>/<model>
|
||||
// written into the channel. The App's own route stays in
|
||||
// [models] default until the user presses Use in Accounts.
|
||||
// written into the channel, and never the route: the App's own
|
||||
// route stays in [models] default until the user presses Use in
|
||||
// Settings › Account. One of the App's own routes picked here
|
||||
// is written as the route, with magpie's channel taken out.
|
||||
Key: "model", Label: "model",
|
||||
Get: get,
|
||||
Set: func(v string) error {
|
||||
@@ -384,7 +390,26 @@ func grokApp(home string) *Agent {
|
||||
if v == "" {
|
||||
return unwire()
|
||||
}
|
||||
return errGrokAppRoute
|
||||
// one of the App's own routes: magpie's channel goes, the
|
||||
// way picking another provider leaves magpie elsewhere, and
|
||||
// the route is the one picked. Disconnect comes here to put
|
||||
// back the route the App had before.
|
||||
def, ch, err := grokAppRead(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ch != nil {
|
||||
if err := unwire(); err != nil {
|
||||
return err
|
||||
}
|
||||
if def, _, err = grokAppRead(path); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if def == v {
|
||||
return nil
|
||||
}
|
||||
return setDefault(v)
|
||||
},
|
||||
Options: func(cur map[string]string) []Option {
|
||||
return append(grokAppOwn(path, keyDefault, cur["model"]), viaMagpie("grok-app", magpieID+"/")...)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
toml "github.com/pelletier/go-toml/v2"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
@@ -296,16 +297,22 @@ func TestGrokAppOwnRouteStays(t *testing.T) {
|
||||
if err := a.Pick("model", "magpie/kimi/k2"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := a.Pick("model", "grok")
|
||||
if err == nil || !strings.Contains(err.Error(), "Accounts") {
|
||||
def, _, rerr := grokAppRead(path)
|
||||
if rerr != nil || def != "deepseek" {
|
||||
t.Fatalf("connecting moved the route: %q err %v", def, rerr)
|
||||
}
|
||||
// one of the App's own routes the picker offers is taken: it is the
|
||||
// route, and magpie's channel goes, as picking another provider leaves
|
||||
// magpie on every other agent
|
||||
if err := a.Pick("model", "grok"); err != nil {
|
||||
t.Fatalf("picking the official route: %v", err)
|
||||
}
|
||||
secs := grokAppSections(t, path)
|
||||
if secs["magpie"]["model"] != "kimi/k2" || a.Field("model").Get() != "magpie/kimi/k2" || !a.Wired() {
|
||||
t.Fatalf("the provider went: model %q wired %v\n%v", a.Field("model").Get(), a.Wired(), secs["magpie"])
|
||||
if _, ok := secs["magpie"]; ok || a.Field("model").Get() != "grok" {
|
||||
t.Fatalf("magpie's channel stayed: model %q\n%v", a.Field("model").Get(), secs["magpie"])
|
||||
}
|
||||
def, _, rerr := grokAppRead(path)
|
||||
if rerr != nil || def != "deepseek" {
|
||||
def, _, rerr = grokAppRead(path)
|
||||
if rerr != nil || def != "grok" {
|
||||
t.Fatalf("route %q err %v", def, rerr)
|
||||
}
|
||||
if secs["deepseek"]["api_key"] != "sk-test" {
|
||||
@@ -313,6 +320,55 @@ func TestGrokAppOwnRouteStays(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Disconnect puts back the route the App was on before Connect through the
|
||||
// model field (connect.was) when unwire left none: a route Use set to
|
||||
// magpie with nothing stashed to put back. Set refused an own route, so
|
||||
// Disconnect failed half done.
|
||||
func TestGrokAppDisconnectPutsTheRouteBack(t *testing.T) {
|
||||
home, path := grokAppHome(t, grokAppConfig)
|
||||
a := grokApp(home)
|
||||
if err := a.Connect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := edit.SetTOMLKey(path, "models", "default", magpieID); err != nil { // Use on magpie
|
||||
t.Fatal(err)
|
||||
}
|
||||
forget("grok-app:" + path + ":default")
|
||||
if err := a.Disconnect(); err != nil {
|
||||
t.Fatalf("disconnect: %v", err)
|
||||
}
|
||||
def, ch, err := grokAppRead(path)
|
||||
if err != nil || def != "deepseek" || ch != nil {
|
||||
t.Fatalf("after disconnect: route %q channel %v err %v", def, ch, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A sync with nothing of magpie's in the App writes nothing, not even to
|
||||
// magpie's own stash; one whose route is magpie with the channel gone is
|
||||
// told, since the App reaches nothing.
|
||||
func TestGrokAppSyncUnconnected(t *testing.T) {
|
||||
home, path := grokAppHome(t, grokAppConfig)
|
||||
a := grokApp(home)
|
||||
before := mustRead(t, path)
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := stashLoad()
|
||||
if mustRead(t, path) != before || st["grok-app:"+path+":default"] != "" || st[grokAppReleased] != "" {
|
||||
t.Fatalf("an unconnected sync wrote: %v", st)
|
||||
}
|
||||
if c := a.Check(); c != "" {
|
||||
t.Fatalf("check: %q", c)
|
||||
}
|
||||
stash(map[string]string{grokAppReleased: "1"}) // a Use after the one put back
|
||||
if err := os.WriteFile(path, []byte(strings.Replace(before, `default = "deepseek"`, `default = "magpie"`, 1)), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := a.Check(); !strings.Contains(c, "no longer reaches magpie") {
|
||||
t.Fatalf("route magpie without the channel: check %q", c)
|
||||
}
|
||||
}
|
||||
|
||||
// An older magpie that set the route to itself is put back once. A Use the
|
||||
// user presses after that is the App's choice and stays.
|
||||
func TestGrokAppReleasesATakeover(t *testing.T) {
|
||||
|
||||
@@ -4474,7 +4474,7 @@ const I18N = {
|
||||
"It reads its settings at start-up — restart open Command Code sessions to use this.": "它启动时读取设置,需重启已打开的 Command Code 会话才会生效。",
|
||||
"Kimi Code reads its settings at start-up — restart open kimi sessions to use this.": "Kimi Code 启动时读取设置,需重启已打开的 kimi 会话才会生效。",
|
||||
"jcode reads its settings at start-up — restart open jcode sessions to use this.": "jcode 启动时读取设置,需重启已打开的 jcode 会话才会生效。",
|
||||
"Magpie is a custom provider under Grok App's Accounts. Grok App stays on its current route until you press Use on magpie there.": "Magpie 是 Grok App「账户」里的一个自定义供应商。在你于该处对 magpie 点「使用」之前,Grok App 保持当前路线。",
|
||||
"Magpie is a custom provider in Grok App's Settings › Account. A chat can pick magpie's models in its model picker, and Grok App stays on its current route until you press Use on magpie there.": "Magpie 是 Grok App「设置 › 账户」里的一个自定义供应商。对话可以在模型选择器里选 magpie 的模型;在你于该处对 magpie 点「使用」之前,Grok App 保持当前路线。",
|
||||
"MiniMax Code reads its settings at start-up — restart open mcode sessions to use this.": "MiniMax Code 启动时读取设置,需重启已打开的 mcode 会话才会生效。",
|
||||
"Mister Morph's Console uses this for new tasks; restart open morph chats to use it there.": "Mister Morph 的 Console 会在新任务中使用这项设置;已打开的 morph 对话需重启才会生效。",
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.": "Muse Code 启动时读取设置,需重启已打开的 muse 会话才会生效。",
|
||||
@@ -8986,7 +8986,7 @@ const I18N = {
|
||||
"It reads its settings at start-up — restart open Command Code sessions to use this.": "它啟動時讀取設定,需重啟已打開的 Command Code 會話才會生效。",
|
||||
"Kimi Code reads its settings at start-up — restart open kimi sessions to use this.": "Kimi Code 啟動時讀取設定,需重啟已打開的 kimi 會話才會生效。",
|
||||
"jcode reads its settings at start-up — restart open jcode sessions to use this.": "jcode 啟動時讀取設定,需重啟已打開的 jcode 會話才會生效。",
|
||||
"Magpie is a custom provider under Grok App's Accounts. Grok App stays on its current route until you press Use on magpie there.": "Magpie 是 Grok App「帳戶」裡的一個自訂供應商。在你於該處對 magpie 按「使用」之前,Grok App 維持目前的路線。",
|
||||
"Magpie is a custom provider in Grok App's Settings › Account. A chat can pick magpie's models in its model picker, and Grok App stays on its current route until you press Use on magpie there.": "Magpie 是 Grok App「設定 › 帳戶」裡的一個自訂供應商。對話可以在模型選擇器裡選 magpie 的模型;在你於該處對 magpie 按「使用」之前,Grok App 維持目前的路線。",
|
||||
"MiniMax Code reads its settings at start-up — restart open mcode sessions to use this.": "MiniMax Code 啟動時讀取設定,需重啟已打開的 mcode 會話才會生效。",
|
||||
"Mister Morph's Console uses this for new tasks; restart open morph chats to use it there.": "Mister Morph 的 Console 會在新任務中使用這項設定;已打開的 morph 對話需重啟才會生效。",
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.": "Muse Code 啟動時讀取設定,需重啟已打開的 muse 會話才會生效。",
|
||||
@@ -13500,7 +13500,7 @@ const I18N = {
|
||||
"It reads its settings at start-up — restart open Command Code sessions to use this.": "起動時に設定を読み込むため、反映するには開いている Command Code セッションを再起動してください。",
|
||||
"Kimi Code reads its settings at start-up — restart open kimi sessions to use this.": "Kimi Code は起動時に設定を読み込みます。反映するには開いている kimi セッションを再起動してください。",
|
||||
"jcode reads its settings at start-up — restart open jcode sessions to use this.": "jcode は起動時に設定を読み込みます。反映するには開いている jcode セッションを再起動してください。",
|
||||
"Magpie is a custom provider under Grok App's Accounts. Grok App stays on its current route until you press Use on magpie there.": "Magpie は Grok App の「アカウント」にあるカスタムプロバイダーです。そこで magpie の「使用」を押すまで、Grok App は今のルートのままです。",
|
||||
"Magpie is a custom provider in Grok App's Settings › Account. A chat can pick magpie's models in its model picker, and Grok App stays on its current route until you press Use on magpie there.": "Magpie は Grok App の「設定 › アカウント」にあるカスタムプロバイダーです。チャットはモデル選択から magpie のモデルを選べます。そこで magpie の「使う」を押すまで、Grok App は今のルートのままです。",
|
||||
"MiniMax Code reads its settings at start-up — restart open mcode sessions to use this.": "MiniMax Code は起動時に設定を読み込みます。反映するには開いている mcode セッションを再起動してください。",
|
||||
"Mister Morph's Console uses this for new tasks; restart open morph chats to use it there.": "Mister Morph の Console は新しいタスクでこれを使います。開いている morph チャットに反映するには再起動してください。",
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.": "Muse Code は起動時に設定を読み込みます。反映するには開いている muse セッションを再起動してください。",
|
||||
@@ -18014,7 +18014,7 @@ const I18N = {
|
||||
"It reads its settings at start-up — restart open Command Code sessions to use this.": "Es liest seine Einstellungen beim Start – offene Command-Code-Sitzungen neu starten, damit es gilt.",
|
||||
"Kimi Code reads its settings at start-up — restart open kimi sessions to use this.": "Kimi Code liest seine Einstellungen beim Start – offene kimi-Sitzungen neu starten, damit es gilt.",
|
||||
"jcode reads its settings at start-up — restart open jcode sessions to use this.": "jcode liest seine Einstellungen beim Start – offene jcode-Sitzungen neu starten, damit es gilt.",
|
||||
"Magpie is a custom provider under Grok App's Accounts. Grok App stays on its current route until you press Use on magpie there.": "Magpie ist ein eigener Anbieter unter Konten in Grok App. Grok App bleibt auf seiner aktuellen Route, bis du dort bei magpie auf Verwenden drückst.",
|
||||
"Magpie is a custom provider in Grok App's Settings › Account. A chat can pick magpie's models in its model picker, and Grok App stays on its current route until you press Use on magpie there.": "Magpie ist ein eigener Anbieter unter Einstellungen › Konto in Grok App. Ein Chat kann magpies Modelle in seiner Modellauswahl wählen, und Grok App bleibt auf seiner aktuellen Route, bis du dort bei magpie auf Verwenden drückst.",
|
||||
"MiniMax Code reads its settings at start-up — restart open mcode sessions to use this.": "MiniMax Code liest seine Einstellungen beim Start – offene mcode-Sitzungen neu starten, damit es gilt.",
|
||||
"Mister Morph's Console uses this for new tasks; restart open morph chats to use it there.": "Die Console von Mister Morph nutzt dies für neue Aufgaben; offene morph-Chats neu starten, damit es dort gilt.",
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.": "Muse Code liest seine Einstellungen beim Start – offene muse-Sitzungen neu starten, damit es gilt.",
|
||||
@@ -18103,7 +18103,7 @@ const NOTICES = [
|
||||
"It reads its settings at start-up — restart open Command Code sessions to use this.",
|
||||
"Kimi Code reads its settings at start-up — restart open kimi sessions to use this.",
|
||||
"jcode reads its settings at start-up — restart open jcode sessions to use this.",
|
||||
"Magpie is a custom provider under Grok App's Accounts. Grok App stays on its current route until you press Use on magpie there.",
|
||||
"Magpie is a custom provider in Grok App's Settings › Account. A chat can pick magpie's models in its model picker, and Grok App stays on its current route until you press Use on magpie there.",
|
||||
"MiniMax Code reads its settings at start-up — restart open mcode sessions to use this.",
|
||||
"Mister Morph's Console uses this for new tasks; restart open morph chats to use it there.",
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.",
|
||||
|
||||
@@ -208,7 +208,9 @@ var rtkNoHook = map[string]string{
|
||||
"dsh": "RTK has no hook for DeepSeek Harness yet: RTK works by rewriting the shell command an agent is about to run, and dsh's hooks can only allow or deny a command, not change it; rtk init has no --agent dsh either (github.com/rtk-ai/rtk/issues/3847)",
|
||||
// rtk init's agents are claude, cursor, codex, copilot, gemini,
|
||||
// opencode and the rest of rtkSpecs. There is no grok or grok-app,
|
||||
// so a hook written here would have nowhere to go.
|
||||
// so a hook written here would have nowhere to go, for Grok Build no
|
||||
// more than for the App that runs it.
|
||||
"grok": "RTK has no hook for Grok Build yet: rtk init has no Grok agent, so it cannot rewrite the shell commands Grok Build runs",
|
||||
"grok-app": "RTK has no hook for Grok App yet: rtk init has no Grok or Grok App agent, so it cannot rewrite the shell commands Grok App runs",
|
||||
}
|
||||
|
||||
|
||||
@@ -544,3 +544,28 @@ func TestRTKNoHookGrokApp(t *testing.T) {
|
||||
t.Fatalf("magpie library rtk on grok-app: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Grok Build, which Grok App runs, has no rtk agent either (#1625's
|
||||
// sibling): it is listed with the switch off, never switched on.
|
||||
func TestRTKNoHookGrokBuild(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
write(t, filepath.Join(h, ".grok", "config.toml"), "")
|
||||
var grok *RTKAgent
|
||||
for _, a := range ReadRTK().Agents {
|
||||
if a.ID == "grok" {
|
||||
grok = &a
|
||||
}
|
||||
}
|
||||
if grok == nil {
|
||||
t.Fatal("Grok Build isn't listed")
|
||||
}
|
||||
if b, _ := json.Marshal(grok); grok.On || !strings.Contains(string(b), `"noHook":true`) || !strings.Contains(grok.Blocked, "no Grok agent") {
|
||||
t.Fatalf("listed as %s", b)
|
||||
}
|
||||
if _, err := SetRTK("grok", true); err == nil || !strings.Contains(err.Error(), "Grok Build") {
|
||||
t.Fatalf("switched on: %v", err)
|
||||
}
|
||||
if _, err := RTKTakes("grok"); err == nil || !strings.Contains(err.Error(), "no Grok agent") {
|
||||
t.Fatalf("magpie library rtk on grok: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user