Ask for `clai2` plugin keys and sign-ins through `Dialogs`

Merged
MP
2mo ago
+556-211

Part 17 of the clai2 web UI stack (… → #10315 → this PR). Based on #10315. No linked issue: requested by the CLAI maintainer.

Why. Almost every plugin menu picks a /keys entry or signs in through a few shared helpers that drew termflow widgets. Making them ask through Dialogs (#10312) lets a ported plugin's settings menu action call them with whatever dialogs it was given, so the same action works in the terminal and, through #10315, in the browser. The plugins themselves are ported in the next PRs, one each.

API changes

  • plugins.keys.choose_key(*, name, label, dialogs, check=...) now takes dialogs instead of runners:
    • It offers the saved /keys names plus "Enter a different API key" through dialogs.choose, or goes straight to a masked dialogs.text when none are saved.
    • Replacing an existing key is confirmed with dialogs.confirm, "Keep the saved token" first.
    • It keeps the check semantics, the KeyExistsError retry, finish_write, and the key prompt telemetry span. The span never records the value.
    • It no longer goes through config.api_keys.prompt_api_key, which core menus such as /model add still use unchanged. Its menu.run() call also bypassed Runners, so tests couldn't script it.
  • plugins.keys.browser_sign_in(session, dialogs).
  • plugins.sign_in.wait_for_sign_in, sign_in_now and run_subcommand take dialogs: Dialogs | None, where None means the terminal (TerminalDialogs(RUNNERS)). Messages are unchanged.
  • MaskedPrompt and confirm_replace are removed from plugins.keys; nothing else used them.

Callers. Every built-in caller (day_ai, grain, logfire_mcp, notion, ordinal, posthog, pylon, slack, mcp/_command.py) now passes TerminalDialogs(runners) where it passed runners. This is minimal on purpose: their menus are ported in the following PRs, and the terminal looks as before.

Tests.

  • New tests/clai2/dialog_script.py::ScriptedDialogs: a typed Dialogs driven by scripted answers (Pick, Type, Confirm, Finish, Back) that records each dialog asked (Asked). The plugin ports will use it.
  • test_plugin_keys.py, test_sign_in.py, test_day_ai.py, test_slack.py and test_ui_telemetry.py are updated, with termflow-level checks kept where they prove the terminal widgets.

Verification. Pyright clean on the plugins, builtin_plugins, mcp and the touched tests. 887 tests pass across every suite that touches keys, sign-in, dialogs, the affected plugins and the web UI. The new code has full branch coverage. A real terminal check in tmux, against an isolated config, opened a plugin's token row: the /keys picker, the masked input and Esc behave as before.

What changes for existing users. In the terminal, a plugin's /keys picker is now the shared choose list: the same names plus "Enter a different API key", searchable past 8 keys, with a short description beside it. Nothing else changes.

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.