Commit Graph
13 Commits
Author SHA1 Message Date
yetone 2c75d89827 agent: AstrBot is an agent magpie connects: its default chat model one of magpie's, its own providers kept (orange27 on Discord)
orange27 asked on Discord for AstrBot (AstrBotDevs/AstrBot) as an agent.

What changed:
- internal/agent/astrbot.go: a new agent for AstrBot's data/cmd_config.json
  under its root ($ASTRBOT_ROOT, else ~/.astrbot, the desktop app's, else
  ~/astrbot / ~/AstrBot when it holds an install).
  - Connecting adds one "magpie" entry to provider_sources
    (openai_chat_completion at the gateway, key magpie-astrbot) and one
    "magpie/<model>" entry per model of magpie's to provider.
  - It sets the default chat model:
    agent_runner.config.model.provider_id on 4.28+, or
    provider_settings.default_provider_id on older layouts.
  - Field types are taken from AstrBot's own defaults and validator: key is
    a list, timeout and max_context_tokens are ints, modalities lists
    text/image/tool_use, and custom_headers / custom_extra_body are objects.
  - The user's own sources and models are kept byte for byte. What they
    change in magpie's entries (timeout, proxy, enable) stays through a
    sync, and a sync with nothing new doesn't rewrite the file.
  - The UTF-8 BOM AstrBot writes is kept.
  - The first connect copies the file to cmd_config.json.before-magpie.
  - Disconnect takes magpie's entries out and puts back the pick it found,
    so the file comes back byte for byte.
  - A pick the user makes while connected is theirs and stands.
  - Without the file it says to start AstrBot once (or set ASTRBOT_ROOT).
    Without provider_sources (before 4.10) it says to update.
  - The notice says to restart AstrBot, before saving in its WebUI: it
    reads the file only at start-up and its WebUI writes the whole file
    back on save.
  - Docker installs aren't reached: their root is inside the container.
- agents.go, agentenv.go: registers it; ASTRBOT_ROOT joins the agent env.
- icons/astrbot.svg: AstrBot's logo, as a mask icon.
- applied_test.go, rewire_test.go: the every-agent tests seed AstrBot's
  settings, as they do Hanako's.
- docs/subsystems/agent-wiring.md, docs/reference.md: AstrBot's row.

What was run:
- go test -tags nogui ./internal/agent -run '^TestAstrBot'. The tests went
  red when, by hand, I dropped the BOM, rewrote the user's entries, left
  the pick unrestored, overwrote the user's own pick, made a no-op sync
  write, rewrote the backup on a switch, or broke the legacy layout.
- Real use:
  - AstrBot 4.28.2 installed with uv into a scratch venv (Python 3.12),
    run from an isolated root under a sandbox HOME.
  - A sandbox magpie (MAGPIE_ADDR 127.0.0.1:3617, ASTRBOT_ROOT set) with a
    fake OpenAI upstream on 3618 ran `magpie astrbot magpie/fake/echo-1`.
  - AstrBot restarted, logged "Selected openai_chat_completion(magpie/
    fake/echo-1) as default chat model provider", and answered a WebUI
    chat (/api/chat/send) with the upstream's reply.
  - usage.jsonl recorded the turn under agent "astrbot".
  - `magpie astrbot default` gave back the file AstrBot wrote,
    byte-identical, and AstrBot started clean on it.
- The icon rendered as a mask in Chromium and WebKit. No GUI strings were
  added: the notice is the agent's own English line, like the others'.
- gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows) on internal/agent and
  internal/agentenv; go test -tags nogui ./... under a temp HOME (load
  ~170-240): every package passed but internal/gateway. That package
  doesn't import internal/agent. It timed out at 10m, then with -timeout
  30m failed TestQueuedStreamWaitedOutIsTheStreamsError (its 400ms idle
  read and the 100ms "the first has the slot" sleep; a delay injected
  before the first request reproduces it). internal/agent and
  internal/agentenv were rerun green after rebasing on origin/main.
2026-10-11 00:41:09 +08:00
yetone 0bf9d77d3f agent tests: TestDriftBypassed's request reaching the gateway is kept to its run, so -count=2 passes
The test stood for a request with usage.Saw("codex"). Saw's record lasts
the process, which the gateway relies on (LastSeen answers from it before
a request is written to the log), so a second run started with a request
seconds old, newer than its prompt five minutes back, and found nothing
bypassed ("bypassed: <nil>", also on origin/main).

Drift reads LastSeen through a package variable the test replaces with its
own clock; production still reads usage.LastSeen. That Saw is LastSeen's
answer at once moves to usage's own TestSawIsLastSeen, which removes its
record afterwards.

-run 'TestDrift|TestSawIsLastSeen' -race -count=5 passes; before, -count=2
failed.
2026-10-07 03:03:06 +08:00
wizzy-yangandwizzy-yang 6f391bc8f2 provider, agent, cli: a routing group's id carries Claude Code's [1m] mark (#1000)
wherever a ref is read back from an agent's settings

An agent on a routing group is shown, on the Providers page, on each of
that group's providers — the row's middle holds one button per agent, and
`uses` is what the Routing page's "n agents routed through it" counts.
A group whose model has a 1M window is written into Claude Code's
settings with the mark Claude Code itself puts on it
(`group/auto-deepseek-v4-1-flash[1m]`), and GroupFor takes the mark off
for the gateway; the rest did not. So the group was not found, and an
agent Claude Code had on it was listed on none of the group's providers,
while every request it made went through them.

Four places read such a ref back:

- provider.GroupFinder, which the Providers page asks (agentUses)
- agent.sameModel, which moves an agent whose group is gone to the same
  model from a provider still serving it — the mark left on made the
  comparison against AutoGroupOf find nothing, and the agent stayed on a
  group nobody serves
- agent.groupNamed, which says whether two values of a field reach the
  same group, one of them read back from the agent's own settings
- the CLI's groupUses, which lists "← agent" beside a group: the marked
  id was filed under one no group has, and Claude Code was on no row

Each takes the mark off, as GroupFor does. A group's own members are not
touched: those are the group's structure, never a ref from an agent's
settings, and a [1m] there is a model's, not the group's.

group_uses_test covers the page (a group found with and without the mark,
and the row naming the agent on the group's provider); applied_test covers
groupNamed; reseat_test covers the move (the marked group ref finds the
same model elsewhere, and a group that is nobody else's still gives
nothing); groups_cli_test covers the CLI, with Claude Code's settings.json
as the reporter's reads. Each fails without its fix. go build, go vet
pass; go test ./internal/agent/ passes, and the failures that remain are
the ones a clean origin/main has too (Aside's symlinks, ~/.codex
dependence, VSCode's launchers, a flaky Zed case).

Co-authored-by: wizzy-yang <wizzy-yang@users.noreply.github.com>
2026-10-06 16:02:03 +08:00
Junjie Zhou 4a97acf12a refactor(agent): separate Aside provider connection from model settings (#827)
* refactor(agent): connect Aside as a native provider with verified settings

* fix(agent): offer explicit offline Aside model and disconnect actions

Offer Save for next start after an initial runtime read failure, using a
structured API error instead of saved runtime state. Keep refusals and
failed readbacks on the live error path.

Add a separate offline disconnect confirmation that restores the checked
file plan, clears restore records and removes the provider last. Bind the
confirmation to its preview revision and roll back ordinary write failures.

Cover offline API and browser flows, cancellation, stale plans, missing
CLI, restore metadata and native provider spelling. Keep state file-only.
2026-10-05 14:37:44 +08:00
Anx 575a8f5fe3 tests: TestDriftUnwiredEveryAgent leaves WSL agents alone — it walks every agent and picks a magpie model to see the wiring come back, and on a Windows machine with a real distro running, the WSL agents in All() are the user's own: the pick wrote fake/m1 into their real ~/.codex/config.toml, ~/.claude/settings.json and ~/.pi/agent/settings.json through \wsl.localhost. Their files live in the distro, beyond the sandbox home, so the test skips them (a.WSL set). Verified on such a machine: the full ./internal/agent suite leaves the three files' hashes untouched. (#283) 2026-09-30 14:11:30 +08:00
yetone 55a0c35f30 agents: Antigravity CLI (agy) takes magpie's models (Discord Str: asked to use agy through magpie) — agy is on the Agents page like the others. Picking one of magpie's models writes ~/.gemini/antigravity-cli/settings.json: modelProvider "gemini", an entry per magpie model under customModelsConfig.customModels (magpie/<ref> → {apiProvider: API_PROVIDER_GOOGLE_GEMINI, modelName: <ref>}) beside the user's own, and model. Every other key is kept, and "as installed" gives back the user's model and modelProvider and takes magpie's entries out (the file byte-identical to before). agy reads its endpoint and key only from GEMINI_API_KEY / GOOGLE_GEMINI_BASE_URL, and in agy 1.2.13 a custom model chosen by settings or its picker fails ("model is empty"): only --model resolves it. So the agent has a Launch command, GEMINI_API_KEY=magpie GOOGLE_GEMINI_BASE_URL=<gateway> agy --model '<model>' (a $env: form on Windows), which magpie agy prints as its notice and the row's new square copies in one click (tooltip shows it; no scroll; zh strings). Check says unwired when the entry is gone or modelProvider isn't gemini. Tested with TestAgy (set/switch/drift/restore, a user's custom model kept, a file with nothing of the user's left as it was) and agy-launch.test.cjs in Chromium and WebKit, en and zh (fails without the app.js change); end to end in a sandbox HOME with agy 1.2.13 against a sandbox gateway on 38472 and a fake OpenAI upstream: magpie agy magpie/fakeup/echo-1 wrote the settings, agy (interactive and --print) answered from the upstream through the gateway, magpie agy default restored the file. Not tested: the Windows command, a real Gemini upstream; agy's requests show in usage as google-genai-sdk (its UA), and its title requests for gemini-3.1-flash-lite-preview get a 404. go build (nogui, linux, windows) and go test -tags nogui ./... pass; the GUI suite passes but for click-scroll's WebKit case, failing already 2026-09-29 19:41:29 +08:00
yetone 63f9fa7465 agent: Claude Desktop runs on magpie in its third-party mode (#156: Claude Desktop 不会解锁 Claude Code 面板 — CC Switch 可以,咱这个支持吗?) — signed in with a Free account, Desktop's Code tab is only "Get Claude Code"; in its 3p deployment mode it needs no Anthropic sign-in and Code and Cowork run on the gateway. A Claude Desktop agent whose provider field switches it: on writes deploymentMode "3p" into Claude/ and Claude-3p/claude_desktop_config.json, a magpie profile in Claude-3p/configLibrary/<id>.json (inferenceProvider gateway, inferenceGatewayBaseUrl the gateway's address, inferenceGatewayApiKey magpie-claude-desktop, inferenceGatewayAuthScheme bearer; disableDeploymentModeChooser and coworkEgressAllowedHosts ["*"] only where unset) and its entry in _meta.json, applied — the keys and files CC Switch writes (claude_desktop_config.rs). No inferenceModels: Desktop lists /v1/models, which the gateway already gives it by ids it keeps. Off puts each deploymentMode back as it was (gone where there was none), the profile applied before applied again, magpie's profile and entry removed, and files and folders magpie made gone if nothing else went in; other keys and profiles are never touched. Folders as CC Switch finds them: ~/Library/Application Support, %LOCALAPPDATA% (a Claude… folder there if not Claude itself), $XDG_CONFIG_HOME. Desktop reads them at start-up, which the picker and notice say. The Library keeps giving Desktop's MCP servers to %APPDATA%'s file on Windows, listed once. Tested in a sandbox home: fresh, with the user's settings and 3p profiles (off restores every byte), on twice, on → off → on, drift, odd files refused, each system's folders; and against Claude Desktop 2.9939.2 on Windows 11 (winget): on, it started in 3P mode (provider gateway, apiHost the gateway) with the Code tab and no sign-in, and asked the gateway's /v1/models; off, it went back to claude.ai 2026-09-28 22:37:26 +08:00
yetone 6c9a0aa4d7 agents: OpenHanako — magpie is a provider there, chat completions at the gateway's /v1 under the key magpie-hanako with every model it serves, their windows, output, images and reasoning said; picking one makes it the primary agent's chat model, and default puts back the one it had and removes the provider, marked deleted as OpenHanako marks one it removes. While OpenHanako runs it goes through its local API (server-info.json's port and token), which reloads at once; otherwise into provider-catalog.json and agents/<id>/config.yaml for its next start. Asked on Discord; checked with OpenHanako's own provider registry and model manager, which list magpie's models and resolve the chat model to the gateway 2026-09-28 01:12:46 +08:00
yetone f7e38d0d2e agents: a magpie on a port of its own (magpie-dev, a sandbox) takes an agent wired to the installed magpie's gateway (127.0.0.1:3425) for that one's, not drift — the two took turns flagging Codex with Apply again, each rewiring it to itself 2026-09-27 14:54:35 +08:00
yetone 7a3c434610 agents: Alma — magpie wires it through Alma's local API (localhost:23001, while Alma runs): choosing one of magpie's models for Alma adds a provider named magpie there (OpenAI type, the gateway's /v1, key magpie), offers magpie's models in it and makes the model Alma's default chat model, the rest of Alma's settings and its other providers left as they are; the list is kept current as magpie's catalog changes, and going back to Alma's own takes magpie's provider out. Asked on Discord 2026-09-26 19:18:51 +08:00
yetone a9aeb4d45f agent(codex): a Codex that couldn't reach magpie says so — the Codex app writes no history.jsonl, so a Codex it started while magpie wasn't running (the gateway refused it, and it built its model list without magpie's) or before magpie set it up (its requests still went to chatgpt.com or an old port) looked fine; magpie now reads the newest model request Codex logged since it was set (logs_*.sqlite, read-only, a day at most) and shows Apply again with the time and why, and to quit and reopen Codex 2026-09-26 01:16:27 +08:00
yetone 1b5d1f87db agent: every agent on a magpie model says when it was taken off magpie behind its back, not only Codex — each checks what magpie wired into it to reach the gateway (Claude Code's env base URL and token, and a managed-settings base URL that wins over them; Gemini CLI's .env and its auth type; OpenCode, Pi, Crush, Command Code, Hermes, omp and Grok Build's magpie provider; DeepSeek Harness's llm-deepseek entry and its key in .env), and one pointed elsewhere or gone shows Apply again with what is off in its tooltip; Claude Code, like Codex, is also said to be bypassed when it was used and nothing of it reached the gateway (its history.jsonl), and slash commands no longer count as use. A test takes every such agent off the gateway and back 2026-09-26 01:10:40 +08:00
yetone 04302b1e63 agent(codex): a Codex taken off magpie behind its back says so, with Apply again — something else rewriting config.toml (another switcher, an installer, a profile of its own) left the row showing a magpie model while Codex asked OpenAI for it, and the user blamed magpie; magpie now remembers what it set on each agent (applied.json) and tells three kinds of drift apart: the wiring gone (the provider table, catalog or base URL, or a profile overriding them), a magpie model replaced by one of Codex's own, and a Codex used since with none of its requests reaching the gateway (history.jsonl against when the gateway last saw it — an old process on an old config). A drifted row carries a coral Apply again pill on its name's line (a badge on the logo in the panel), the reason in its tooltip, Keep current settings in the row menu; the window asks /api/drift every 15s, so it shows without a reload 2026-09-26 01:05:19 +08:00