Files
magpie/internal/provider/devin_accounts.go
T
yetone 07a445f42b provider: Devin's built-in is retired; its plugin serves it
"devin" joins retiredBuiltins, as Zed (c0605abc2) and Grok (60ecd598c)
did. @magpie-community/opencode-devin-auth serves it, moved or not.

Removed:
- Sign-in: the PKCE localhost listen and callback branch in signin.go,
  devinExchange/devinExchangeURL. The exchange is Codex's alone again.
- Accounts: devinAccount and devinProvider in the account list, and the
  Logins, switch, on and forget cases (devinSide, devinLoginList,
  switchDevinLogin, setDevinLoginOn, forgetDevinLogin, removeDevinHome,
  addDevinLogin, devinAlsoOn). "devin" keeps its place in Logins("") with
  a nil list.
- Usage: devin_usage.go whole (perLogin fetch, usageLogins, loginQuota).
  devinUsageVersion moved to devin_images.go, which still uses it.
- asksOwnBackend's "devin".
- Gateway: attempt()'s serveDevin dispatch and the Devin translator
  (serveDevin, askDevin, buildDevin, decodeDevin, the Gemini schema and
  tool-description rewriting, the call-id helpers). gateway/devin.go is
  now connect_pb.go and keeps only the protobuf and Connect framing that
  cursor.go uses.
- Tests of the built-in alone: gateway devin_test, devin_gemini_schema,
  devin_sampling and devin_tool_ids; provider devin_usage_test,
  devin_cli_signed_out_test, TestDevinSignIn, TestDevinSeveralAccounts,
  TestSignInInstallsMissingCLI, TestDevinSignInUnseen, the Devin case of
  the required-tools test, and TestDevinSplitParallelCallsKeepTheirResults.

Kept, because the plugin, the devin agent or the move uses them:
- The mover, devinLogins, devinIdentity/devinStatus, DevinAuthAt,
  devinCredentialsAt, newDevinHome, devinCommand/devinProxy.
- DevinFamilies, DevinVariant and models.go's p.ID == "devin" shaping
  (the plugin's provider id is "devin" too). internal/agent/devin.go
  reads the families.
- The installer's "devin" case: the plugin's sign-in installs the CLI.
- The PLUGIN-SERVED notices in devin.go, devin_accounts.go and
  devin_images.go, reworded as retired.

Also fixed:
- cliIdentities no longer lists devinStatus. No look at the accounts
  asks it now, so it stayed unsettled, and FetchNewBehind told every page
  that lists were on their way (TestFetchingNewOnceStarted went red).
- 60ecd598c (Grok) left TestFetchingNewForgottenWhileListed red: its
  hook was GrokExecutable in the account listing. It and
  TestFetchNewListsAgainForAnAnswerWhileListing now hook kiroCLIDB,
  which is read after Cursor's account. Retiring Kiro will need another
  hook.

Tests whose meaning changed:
- TestSignInInstallFails and TestSignInCanceledWhileInstalling go
  through StartPluginSignIn("devin"), the plugin's install of the CLI.
- TestDevinCLIGoesThroughItsProxy seeds both accounts in logins.json
  instead of signing one in. The sign-in's proxy is covered by
  TestPluginSignInGoesThroughItsProxy.
- TestLeftAloneRunsNoCLI no longer expects `devin auth status` when the
  subscription is switched on.
- TestFetchingNewOnceStarted's unanswered CLI is Cursor's.
- devinRawID moved to anthropic_call_ids_test.go. A Devin call id is
  checked as safeCallID("dv_", ...).

Run:
- gofmt -l internal: clean.
- go vet -tags nogui ./... on darwin, GOOS=linux and GOOS=windows: clean.
- staticcheck U1000 on provider and gateway: no Devin leftovers.
- go test -tags nogui -count=1 -run '^(every test in provider, cli and
  gateway that names Devin|TestFetchNew.*|TestFetchingNew.*|
  TestLeftAlone.*|.*Identit.*)$' ./internal/provider ./internal/cli
  ./internal/gateway: ok.
- -run 'Migrat|Move|Moved|Retir|SignIn|AsksOwnBackend|SideLogin|Logins|
  Unmoved|Install|Proxy|Account' ./internal/provider: ok.
- -run 'Devin|Required|Split|CallID|Cursor|Connect|Parity|ToolImage|
  Format|BillingLine' ./internal/gateway: ok.
- -run 'Devin|Plugin|Retired|Moved' ./internal/gui ./internal/agent: ok.
- Not run: the whole packages, the full suite, the GUI node suite (the
  machine is loaded).
2026-10-17 23:11:01 +08:00

118 lines
4.1 KiB
Go

package provider
// PLUGIN-SERVED (see AGENTS.md): Devin ("devin") is a retired built-in
// subscription, served by its plugin alone,
// @magpie-community/opencode-devin-auth (provider.BuiltinRetired). Its
// sign-in, requests and usage are the plugin's; what is left here reads
// the accounts signed in to the built-in for the move onto the plugin
// (migrate_side.go), installs and runs the Devin CLI the plugin and the
// devin agent use, and shapes the models listed under "devin" (families,
// variants, contexts, images). A fix belongs in the plugin
// (github.com/magpie-community/plugins, packages/devin), with the mover's
// min raised in internal/provider/migrate_side.go.
// Several Devin subscriptions. The devin CLI keeps one account, in its
// credentials.toml. Each further account the built-in signed in got a home
// of magpie's own, laid out as the
// CLI's data folder, so the CLI itself answers for it (`devin auth status`
// and `devin models list` run with that home as their data folder) and the
// CLI's own sign-in is never touched. logins.json names those homes; the
// CLI's own account is remembered there too, with no home, so it can stand
// behind another or be turned off.
import (
"context"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/yetone/magpie/internal/netproxy"
"github.com/yetone/magpie/internal/proc"
)
// devinAccountsDir holds the homes of the Devin accounts magpie signed in.
func devinAccountsDir() string { return filepath.Join(filepath.Dir(Path()), "devin") }
// devinCredentialsAt is where an account's credentials.toml is: the CLI's
// own for home "", else the one in magpie's home.
func devinCredentialsAt(home string) string {
if home == "" {
return DevinCredentialsPath()
}
return filepath.Join(home, "devin", "credentials.toml")
}
// devinCommand runs the devin CLI for an account: the CLI's own for home
// "", else with magpie's home as its data folder. It goes through the
// proxy ctx names (a sign-in's), else the account's own (devinProxy), as
// the account's requests do, never always the global one (#1663).
func devinCommand(ctx context.Context, home, path string, args ...string) *exec.Cmd {
cmd := proc.CommandContext(ctx, path, args...)
proxy := netproxy.Choice(ctx)
if proxy == "" {
proxy = devinProxy(home)
}
if home == "" {
cmd.Env = netproxy.EnvWith(proxy, nil)
return cmd
}
var env []string
for _, e := range os.Environ() {
k, _, _ := strings.Cut(e, "=")
switch strings.ToUpper(k) {
case "XDG_DATA_HOME", "APPDATA":
continue
}
env = append(env, e)
}
cmd.Env = netproxy.EnvWith(proxy, append(env, "XDG_DATA_HOME="+home, "APPDATA="+home))
return cmd
}
// devinProxy is the proxy of the account signed in in home (the CLI's own
// for ""), as logins.json names it: that account's (ProxyOfLogin), or the
// subscription's for a home no account is kept for yet. It reads
// logins.json without loginsMu, which a caller may hold.
func devinProxy(home string) string {
for _, l := range readLogins() {
if l.Agent == "devin" && l.Home == home && (home != "" || l.own()) {
return ProxyOfLogin("devin", l.User)
}
}
return ProxyOf("devin")
}
// devinLogin is a Devin account and the home it is signed in in, "" for
// the CLI's own.
type devinLogin struct {
Login
Home string
}
// devinLogins lists the Devin accounts that are signed in, the first in
// use first, then the rest as they were added.
func devinLogins() []devinLogin {
own, plan, ok := devinIdentity()
if !ok {
own = ""
}
var out []devinLogin
for _, l := range sideLogins("devin", own, func(l savedLogin) bool {
_, _, err := DevinAuthAt(l.Home)
return l.Home != "" && err == nil
}) {
if l.saved.own() && l.Plan == "" {
l.Plan = plan // the CLI's own, by the tier `devin auth status` says, as the plugin names it
}
out = append(out, devinLogin{l.Login, l.saved.Home})
}
return out
}
// newDevinHome makes the home a further Devin account is signed in in.
func newDevinHome() (string, error) {
home := filepath.Join(devinAccountsDir(), strings.ToLower(strings.NewReplacer("-", "", "_", "").Replace(randomToken(9))))
return home, os.MkdirAll(filepath.Join(home, "devin"), 0o700)
}