Commit Graph
8 Commits
Author SHA1 Message Date
yetone 86b2f4d053 provider, gateway, gui: an account whose sign-in its vendor revoked or refused reads as signed out and is passed over, not asked on every request (#1793 ysicing, echo_ts on Discord)
What changed, one fix for the class:

- ChatGPT and the other built-in subscriptions (#1793): ChatGPT answered
  401 token_revoked on every request, request after request (~18 rows in
  the reporter's log), because a refused sign-in was just "other" and
  rested a while, then asked again. Now a 401 whose words say the sign-in
  is gone (provider.SignInRevoked: token_revoked, token_invalidated,
  invalid_grant, refresh_token_reused/invalidated/expired; never
  token_expired, a 403, a 5xx or a network error) marks the account for
  the credential it was sent with (a 12-byte hash of the header, never the
  credential), in logins.json as Refused "revoked:<mark>" plus Lapsed.
  A saved ChatGPT account is refreshed first, as Codex does on a 401; a
  refresh that goes through marks nothing. The routing loop fails it as
  failAuth (next member at once, no rest); forwardOnce answers its later
  requests with magpie's own 401 without asking the vendor; compaction
  on a magpie account (compactOn) picks a marked one last. Signed in anew
  (upsertLogin with another credential, addSideLogin), refreshed, or a
  request served, the mark is gone. Claude, Copilot and plugins keep
  their own marks; a key's provider answering the same words rests as
  before.
- Copilot (echo_ts): a built-in Copilot account whose GitHub token GitHub
  refused (401/403 on the token exchange, the CLI stand-in or the usage
  read) is marked lapsed on its own account (copilot_lapsed.go), unless a
  working CLI stand-in serves; cleared when a token is served or it signs
  in again. 5xx and network errors never mark it.
- GUI: such an account's row says Sign-in required with Sign in again
  (Copilot's on its GHE.com host) and Remove, the reason on its allowance
  line in the user's language (zh, zh-TW, ja, de added); the card says
  Signed out once every account in use is.
- docs/subsystems: providers-accounts "A revoked sign-in", gateway-routing.

What was run (sandbox HOME, caches pinned, worktree only):
- go test -race on the new tests: provider TestSignInRevokedWords,
  TestRevokedSideLoginMarkedTillSignedInAgain, TestRevokedCodexRefreshedFirst,
  TestRevokedSignInLeavesOthersMarks, TestUpsertLoginKeepsRevokedMarkForTheSameSignIn,
  TestCopilot* (7); gateway TestRevokedSignInPassedOverTillSignedInAgain
  (fake ChatGPT backend, zstd, real routing: turn 1 asks acct-1 then
  acct-2, turns 2-4 and after a restart acct-2 only with no rests, after a
  new auth.json acct-1 again and the mark gone),
  TestRevokedSignInNotCompactedOnAgain, TestRevokedWordsFromAKeyRestAsBefore.
- Broken by hand, each turned a test red: the forwardOnce short-circuit,
  the failureOf clause, noteSignIn in codexUpstreamOn, compactOn's skip,
  ServedSignIn, its in-memory delete, the 401-only check, refresh-first,
  upsertLogin's keep and its sameAuth, sideLogins' Lapsed and
  addSideLogin's clear; and the six Copilot breaks. GUI: the signedOut
  and quotaError lines each turn revoked-signin-account red.
- GUI (Chromium and WebKit, 420 and 1100, en/zh/zh-TW/ja/de):
  revoked-signin-account (new), copilot-signed-out-account (new), and the
  account-*, claude-*, codex-*, plugin-*, quota-*, signin-*, routing-*,
  usage-accounts* suites: 1605 pass, 7 fail. Six are WebKit
  routing-group-fold/routing-sessions/routing-steady cases that fail the
  same on a clean 9964535ad run alone (#1672, #1612, #1307, #1804); one,
  signin-proxy Chromium de 380, timed out under load (load ~60-75) and
  passed 2 of 2 after, filed as #1814.
- gofmt; go vet darwin, linux (nogui) and windows; linux and windows
  builds. go test ./...: every package ok but gateway, where
  TestOTelFastRequestTranscriptDiscovery and
  TestOTelWaterfallIncludesUnbilledFallback failed under load (#1794);
  both pass alone, -count=3.

Not verified: no real revoked ChatGPT or Copilot account was tried; the
words come from the reporter's screenshot and OpenAI's documented codes.
Codex's own relayed sign-in (not one of magpie's accounts) isn't marked:
Codex refreshes and signs itself in. The short-circuit in
codexUpstreamOn (compaction on a marked account, reached only when every
account is marked) has no test of its own; plugins are left to their
plugin.
2026-10-12 22:16:17 +08:00
yetone 8c5b9f928d provider, agent, gui: subscription accounts can be turned off, and then no agent's sign-in is read (#1535, MaxHaiCom)
What changed: Settings → Privacy → Subscription accounts (On/Off),
`magpie accounts discovery [on|off]` and MAGPIE_NO_ACCOUNTS=1 turn off
account discovery. It stays on by default. While it is off, magpie reads
none of the agents' sign-ins: ~/.claude/.credentials.json, .claude.json's
account, ~/.codex/auth.json, Copilot's, Cursor's, Devin's, Kiro's,
Gemini's, ZCode's, Command Code's and OpenCode's files. It runs no
`security` / `secret-tool` for the Keychain or Secret Service, and asks no
agent CLI who is signed in. It serves no subscription. API-key providers,
middleware plugins and Pi extensions work as before.

Why: the reporter runs magpie on machines where reading other tools'
credentials isn't wanted. The owner delegated the call.

How: settings.NoAccountDiscovery (kept per computer by KeepOwn) and
settings.AccountDiscoveryOff(). The variable only ever turns discovery
off. The gates sit at every reader (readAccountFile, discoveryOff) and at
every route that reads or writes a sign-in, so a route that skips
Accounts still reads nothing:
- Accounts, All, Logins, usage, renewal, warm-up, session identities,
  check-ins;
- switching, forgetting, SetLoginOn, StartSignIn, the imports;
- moves onto plugins.
The ones that write refuse with an error that names how to turn it back
on. On the agent side, Agent.Source and OpenCode's auth.json are gated,
and Codex wiring goes by magpie's stash instead of auth.json, so a
toggle never rewires Codex. logins.json and plugin-auth.json are left
untouched and serve again when discovery is turned back on. A change
applies at once (ForgetAccounts).

Docs: providers-accounts.md, README (en, zh-CN), and the site's CLI table
(en, zh, ja).

Run:
- TestAccountDiscoveryOffReadsNoSignIn (provider) and
  TestAccountDiscoveryOffAgentsReadNoSignIn (agent). Every credential
  path is a FIFO that records each open, and security, secret-tool,
  claude, codex, cursor-agent, devin, kiro-cli, copilot and grok are fakes
  on PATH. Both fail with the gate removed: they show the opens and
  `security find-generic-password -s Claude Code-credentials`, among
  others. Both pass with the gate in place.
- TestAccountDiscoverySetting and TestAccountsDiscoveryCmd.
- account-discovery.test.cjs: chromium and webkit, 900 and 360 wide,
  en/zh/zh-TW/ja/de, 32/32. The neighbouring privacy, redact,
  settings-sections and i18n-keys GUI tests: 49/49.
- The full `go test -tags nogui ./...`, gofmt -l, and go vet for darwin,
  linux and windows on the touched packages.

Not tried: a real machine under fs_usage, and Linux and Windows at
runtime. The FIFO tests are !windows.
2026-10-11 06:38:40 +08:00
yetone 4464ef28d4 provider: magpie on Linux finds the Copilot CLI 1.0's token in the keyring (#723, jia2)
magpie looked the CLI's token up with `secret-tool lookup service
copilot-cli account <host>:<login>`, the attributes keytar wrote before
the CLI 1.0. The CLI 1.0's Rust runtime keeps it through keyring-core's
zbus-secret-service-keyring-store, whose items carry service and
username (cred.rs search_attributes), so a CLI 1.0 signed in with a
keyring (magpie inside WSL or on a Linux desktop) wasn't found.

copilotSecretTool asks for both attributes, account first, and bounds
each lookup at 5s (copilotSecretWait): a keyring waiting on an unlock
prompt nobody answers held the caller for good, including a sign-in's
last step (addCopilotLogin -> copilotOwnUser -> copilotCLILogin).

The service name is still taken to be copilot-cli: the string is in the
1.0.95 runtime, but which call uses it couldn't be read from the binary.

Run: TestCopilotSecretToolUsername (a shell secret-tool answering only
under username, and one that never answers): red with only "account"
asked, green now.
2026-10-11 04:00:27 +08:00
yetone 31468ad0ed provider, agent: magpie on Windows finds the Copilot CLI signed in inside a running WSL distro (#723, jia2)
jia2 runs Copilot CLI 1.0.95 inside WSL, signed in, and magpie (on
Windows) never saw it: copilotCLILogin read only Windows'
%USERPROFILE%\.copilot\config.json.

In a distro with no Secret Service (WSL has none unless one is set up),
the CLI asks to keep its token in plaintext and writes it under
copilotTokens["https://github.com:<login>"] in ~/.copilot/config.json
(read from the @github/copilot 1.0.95 package: its Rust runtime's
storeTokenPlaintext / needs-plaintext-DBus path).

- provider: copilotCLILogin falls back to each running distro's
  ~/.copilot/config.json (plaintext tokens only; a distro's keyring is
  out of reach), through a new CopilotWSLHomes hook, cached 20s since
  it is read over WSL's file share. The read itself moved into
  copilotCLILoginIn(dir, secret).
- agent: the probe looks for $HOME/.copilot, and a distro that has only
  it is kept (wslKept) so its home is known; it makes no agent row.
  CopilotWSLHomes lists only running distros: reading a stopped one
  would start it.

Run: TestCopilotCLIInWSL (provider) and TestWSLCopilotHome (agent),
both red with the fallback / wslKept broken by hand, green with it;
go test ./internal/agent ./internal/sessions green; both tests also
pass on Windows 11. On the Windows box with a real running distro, a
program built from this commit listed \\wsl.localhost\<distro>\home\<user>
and found the copilot account once a CLI-shaped plaintext config.json
was put in the distro's ~/.copilot (removed after), and none before. No
real Copilot CLI sign-in was used.
2026-10-11 04:00:27 +08:00
tobitege 21702d01ff Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars

Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows.

* Makefile: know magpie's folder by its go.mod, so paths with spaces work

The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs.

* i18n: German for the strings main added since, with a parity test

75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system.

* appdir: ignore relative folder variables when reading, keep them for children

CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder.

* Sandbox the tests main added since

internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE.

* agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose

omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over.

* i18n: German for the Library's multi-select and System One's decision API

The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes.

* appdir: tidy the import into magpie's group; say what Go makes of /c/x

The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x.
2026-10-04 23:30:56 +08:00
yetone 9f94b2156b copilot: an account on GitHub Enterprise Cloud with data residency (*.ghe.com) signs in, is read from copilot login --host and is served at its enterprise (#723, guitaoliu: magpie skipped a Copilot CLI sign-in whose host wasn't github.com and its own sign-in was fixed to github.com) — a Copilot account now remembers its host (copilotApp.Host, "host" in its logins.json auth; none for github.com) and every URL it uses follows it, as VS Code's Copilot Chat, copilot.lua and avante do (checked against the issue's references and GitHub's docs): the device flow at https://<name>.ghe.com/login/device/code and /login/oauth/access_token with the same Copilot OAuth app, the device page there, whose account at https://api.<name>.ghe.com/user, its plan and usage at api.<name>.ghe.com/copilot_internal/user, its session token at api.<name>.ghe.com/copilot_internal/v2/token, and its requests, model list, Auto and terms at the session's endpoints.api, or https://copilot-api.<name>.ghe.com when it names none (the provider's base too). A github.com account has no host and goes where it always did, the same vars and the same bytes. CopilotHost (copilot_ghe.go) takes only github.com or one <name>.ghe.com label (a scheme and a trailing slash are dropped; a port, path, user, deeper subdomain or any other host is refused), in the sign-in, the CLI and a host read back from logins.json, so a GitHub token is never sent to a host of the user's choosing. The Copilot CLI's sign-in: a github.com account first, as before; then one copilot login --host <name>.ghe.com signed in, its token under "https://<name>.ghe.com:<login>" in copilotTokens or the keychain; a GitHub Enterprise Server host is still left out. An editor's apps.json entry keyed "<name>.ghe.com:…" is read after the editors' github.com one and the CLI's. GUI: a Copilot device code's panel has "Account on GHE.com?" (zh 账号在 GHE.com 上?), which ends that sign-in and asks "Your enterprise on GHE.com" (你的企业在 GHE.com 上的地址) in a field (acme.ghe.com; Sign in stays off until it reads as <name>.ghe.com), then signs in there; that sign-in's panel offers "Sign in on github.com instead" (改为在 github.com 登录), as does a failed one. CLI: magpie accounts add copilot [--host <name>.ghe.com]. TestCopilotHost, TestCopilotGHESignIn (an httptest server standing in for acme.ghe.com, api.acme.ghe.com and copilot-api.acme.ghe.com through copilotGHEOrigin: sign-in, what is kept, models, a signed request, usage, nothing sent to github.com, a bad host refused) and TestCopilotCLIGHELogin are new and fail on the old code; copilot-ghe.test.cjs (webkit and chromium, en and zh: the link, the field refusing evil.com, a.b.ghe.com, ports and the like, the posted site, the way back, cancels, no native select, no left-border accent) fails on the old code. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass; signin-link, signin-close, signin-again and routing-signin pass in webkit, signin-callback fails before and after the change alike. Not tried with a real GHE.com account: the URLs follow the references, and the CLI's token key for a ghe.com host is taken to be the github.com one's form. Accounts are still told apart by login alone; an EMU login carries its enterprise's suffix. 2026-10-04 06:56:04 +08:00
yetone e8b3be572c windows: the desktop app no longer opens a console window for every command it runs (#54) — it is linked as a GUI program and has no console, so each console CLI it started (devin auth status and models list, devin acp for every Devin turn, claude, codex, cursor-agent and grok probes and runs, grok login) was given a new console by Windows, and a Windows Terminal window with it, some every few seconds while the app sat idle. Every command magpie runs is now made through internal/proc, which starts it with CREATE_NO_WINDOW when magpie has no console of its own: the child gets a console without a window, and its output, which magpie always pipes back, arrives as before. A magpie run in a terminal (magpie serve, the TUI, the desktop app started from one with a command) has one, and its children share it as they did, so Ctrl+C there still reaches them. The relaunch after an update keeps its DETACHED_PROCESS, added to rather than replacing the flags it was made with, and a test fails on any command made with os/exec directly, so a new one can't bring the windows back 2026-09-25 14:04:44 +08:00
yetone e1d211cc4b provider: a Copilot CLI sign-in is found — who from ~/.copilot/config.json (JSONC, COPILOT_HOME honoured), the token from the keychain's copilot-cli item or the file's plaintext copilotTokens; the CLI's token is not traded for a session token (that answers 403) but sent as is under the CLI's own integration, at the API its account is served from 2026-09-24 18:24:03 +08:00