Commit Graph
2 Commits
Author SHA1 Message Date
yetone b0926e81a2 import: a link can say where its key's balance is read (balance=, balance_path=, balance_method=)
A relay's "Add to magpie" link can now name the URL that tells a key its
balance, where the amount sits in the reply, and GET or POST. magpie
takes it only on the host of one of the link's own base URLs, over
https, with no userinfo or fragment, so a link can't send the key
anywhere its requests don't already go; anything else refuses the whole
link. balance_path or balance_method without balance is an error. No
header or token is taken from a link: an account-wide token is worth
more than a key, and a URL stays in browser history.

- provider.ParseImport: linkBalance checks and sets BalanceURL,
  BalancePath and BalanceMethod.
- CLI: the import preview shows the balance URL and doesn't ask it
  before yes (showProviderAsking).
- GUI: the import dialog shows method, URL and field (.imp-bal).
- Docs: docs/import in en, zh and ja (table rows, a note on headers,
  the builder's three fields with the same host check, a security
  bullet); docs/reference.md's parameter table.

Run on mote at this tree (rebased on 8fa3c60f8):
- go test -count=1 ./internal/provider ./internal/gui: ok
  (TestParseImportBalance, TestCoreScriptBudget in it).
- go test ./internal/cli: ok but TestEveryRouteHasACommandOrIsNamed,
  red on main since f418edffc (GET /api/context/session); fixed in the
  next commit, and ok there with -run 'TestEveryRoute…|Import'
  (TestImportPreviewAsksNoBalance).
- GUI import-link-balance, import-link-gemini, i18n-keys: 43/44. The
  red is i18n-keys "a plugin's words are its own", the same three
  strings on an origin/main 8fa3c60f8 copy (#5327, #5426, #5482).
- GOOS=linux go vet -tags nogui and GOOS=windows go vet of provider,
  cli, gui: ok. gofmt -l: clean.

Not tried: a real link with balance= imported into the app and read
against a real relay's balance endpoint.
2026-11-08 18:37:41 +08:00
yetone 23e764d0e0 cli: magpie's commands move from the root into internal/cli; the root keeps only main.go
The root held 89 .go files (30 commands, 59 tests). They move as they are
to internal/cli (package cli), with git mv so history follows them. The
only code change is main() becoming cli.Main(version): the root's new
main.go keeps `var version` in package main, so -ldflags "-X
main.version=…" in the Makefile, the Dockerfile and magpie-releases, and
every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land
next to package main in the root.

Tests that read testdata by a root-relative path now go up one level
(../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links
point at internal/cli/.

Run:
- go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui)
- builds with tags production, dev, "production nogui"; windows
  -H windowsgui; linux CGO_ENABLED=0
- make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64
  android/arm64" VERSION=9.9.9-tidy: all four built, binary prints
  "magpie 9.9.9-tidy"
- docker build --build-arg VERSION=7.7.7-tidy: container prints
  "magpie 7.7.7-tidy"
- go test ./internal/cli (default and nogui): 152 tests, the same count
  as the root on main
- go test ./...: all packages pass (agent, gateway, library, provider
  timed out at 10m under other sessions' load and passed rerun alone
  with -timeout 40m; none of them changed)
- the built binary in a sandbox HOME: version, help, ls, providers,
  claude, and an unknown command's error
2026-10-12 20:40:22 +08:00