Files
magpie/internal
yetone 6fc532198f provider: a CLI's sign-in is asked again only when its files change (#3185)
magpie asked each agent CLI who is signed in once a minute, for as long
as it ran. cursor-agent is a Node program that asks Cursor's servers:
~0.5s of CPU and ~200 MB each time. devin auth status took ~1.9s wall.
On a laptop that is a process spawned every minute, all day.

cliIdentity now takes a mark: a cheap fingerprint of where the CLI keeps
its sign-in (Cursor: authInfo in ~/.cursor/cli-config.json; Devin: a hash
of its credentials file). While the mark reads as it did when the answer
was asked, nobody can have signed in or out, and the CLI is asked again
only after 30 minutes. A changed mark, or one that can't be read, is
asked at once as before. The mark is a file read, never the keychain, so
nothing that can block runs under the identity's lock.

Run:
- TestCLIIdentityAskedOnASignInChange: red with unchanged() forced false
  ("sign-in unchanged, a minute on: asked 2 times"), green with the fix.
- go test ./internal/provider -run 'CLIIdentity|Cursor|Devin': ok.
- Real use: magpie serve in a sandbox HOME holding copies of the owner's
  Devin and Cursor CLI installs and sign-ins, Providers open in WebKit,
  every child of serve logged every 0.3s for 5 minutes, caches warm:
  origin/main b1a2eec2c: devin auth status 3 times, serve CPU 12.66s
  this change:           devin auth status 0 times, serve CPU 12.32s
- Not tried: cursor-agent about in that run; the sandbox's Cursor plugin
  wasn't signed in, so Cursor's path is covered by the unit test only.
- Full suite at 4354a7db2 (on origin/main b1a2eec2c): go test -timeout 45m
  ./..., 68 packages ok (gateway 660s, agent 530s, provider 272s).
  gofmt -l clean; go vet for darwin, and linux and windows -tags nogui.
- Rebased onto 21fb17e4d (only internal/gateway/gateway.go and a test
  changed); at the pushed head go build ./... and go test
  ./internal/provider -run 'CLIIdentity|Cursor|Devin' ok.
2026-10-22 02:25:34 +08:00
..
…
…
…
…
…