Commit Graph
1 Commits
Author SHA1 Message Date
yetone e115b96411 plugin: an api sign-in whose prompts ask the key asks no second key
An OpenCode plugin's "api" auth method with its own prompts and an
authorize (inkstone's API key ways, Devin's session token in
magpie-community/plugins#928) asks the key in its prompts and returns it
from authorize(inputs). The GUI asked those prompts and then always showed
a key field of its own, so the user typed the same token twice and the
second entry went nowhere. The host's save() also copied every answer into
the account's metadata, so the token sat there a second time in plain
text.

- host.js marks such a method keyAsked (type api, prompts, authorize).
  The GUI's startPluginSignIn signs in with no key field for it, as for
  keyless, and a rejected answer asks the prompts again on Try again.
  PluginAPIKey and `magpie plugin` login skip the empty-key check for it
  (Method.NoKey).
- save() keeps only select answers (choices, never secrets) beside the
  authorize result's own metadata. A method with no authorize still keeps
  every answer, as OpenCode does.
- An authorize that gives no key, with no key typed, is now an error
  instead of an "ok" that saved nothing.

OpenCode itself differs: its v1 CLI (providers.ts) asks the prompts, then
always asks "Enter your API key", saves result.key ?? the typed key, and
merges the answers into metadata; its TUI never calls authorize for api
methods. magpie-community plugins are written for magpie's flow and read
the key from inputs, so this follows them.

Plugins that read prompt answers back from metadata (grep of
magpie-community/plugins packages): zcode (site, a select), joycode
(tenant) and agnes (keyProfile, consoleToken). None has an authorize, so
none changes. Every api+authorize plugin (inkstone, cloudflare-workers-ai,
sensenova, agnes-code, astudio, sap-aicore, Devin #928) puts what it needs
in its result's metadata itself; sensenova's apiKey: undefined
workaround is now moot.

Run on mote (macOS 27, Go 1.26.8, Playwright 1.62.0) at this change on
origin/main 9c39edb92: gofmt -l clean; go vet of internal/plugin/...
internal/gui/... internal/provider internal/cli, also GOOS=windows and
GOOS=linux -tags nogui: ok. go test ./internal/plugin/...
./internal/gui/... ./internal/provider: ok. ./internal/cli: ok but
TestEveryRouteHasACommandOrIsNamed, red the same alone on 9c39edb92
(POST /api/gateway/pause from e8fbee60e has no command), filed as #5946.
node --test, chromium and webkit, of plugin-api-prompt-key (new),
plugin-keyless-signin, plugin-password-prompt, plugin-signin,
plugin-ask-ways, plugin-key-hint, plugin-other-ways, signin-paste-key,
plugin-signin-opened, plugin-signin-scrolls, plugin-pick-sub,
plugin-two-subs, zcode-site-layout and i18n-keys: 176 of 176 ok. The new
GUI test passed 3 of 3 alone. plugin-signin-no-url is red 22 of 22 at
the base too (987eac0aa); that is #5938, commented with the macOS run.

Broken by hand: GUI back to keyless-only and host without keyAsked ->
TestAPIPromptsKeyAskedAndMetadata and plugin-api-prompt-key 22 of 22 red;
save() copying every answer again -> the Go test red (token kept twice,
the note answer kept).

Not tried: a real plugin sign-in (inkstone, Devin), the CLI path (no
test), a run on the Windows or Linux boxes, the full ./... suite.
2026-11-10 19:53:54 +08:00