Declare `clai2` plugin settings menus with `SettingsMenu` and ask through `Dialogs`
Part 15 of the clai2 web UI stack (… → #10289 → this PR). Based on #10289. No linked issue: requested by the CLAI maintainer.
Why. A plugin's settings menu today is code that draws termflow widgets in configure(), so only a terminal can show it. The web UI's plugins panel (#10289) can only send people back to the terminal for sign-ins and /keys entries. This PR lets a plugin declare its menu once, so the terminal and the web UI can each render it. The web rendering comes in the next PR.
New public plugin API (pydantic_clai2.plugins.menus)
Plugin.settings_menu() -> SettingsMenu | None. The baseconfigure()now shows it in the terminal, so a plugin that declares a menu stops writingconfigure(). A plugin that overridesconfigure()keeps working unchanged, terminal-only.SettingsMenu(source=..., actions=..., searchable=...).sourceis the existingFieldSource, unchanged.actionsmaps a row key toasync (dialogs) -> messages, for rows that need more than one typed or picked value (a/keysentry, a sign-in).
Dialogs, a protocol with four async methods:choose(title, options, current, description);text(title, label, placeholder, initial, secret, check);confirm(title, yes, no, description);wait(title, description, task), which runstask(show)behind a cancellable screen.- Backing out returns
None/False. These four cover every built-in plugin's menu: Coder's folder browser and Workspace's service list are loops ofchoose.
- Moved:
FieldRow,FieldSourceandChoicePreviewnow live inplugins.menus.field_menustill imports them, so existing imports keep working. Plugin.has_configureis now true for either override.
Terminal implementation (ui/menus/dialogs.py)
TerminalDialogsshows each dialog as a termflow widget in its ownrun_worker, and takes scriptedRunnersin tests, as menus already do.run_settings_menuruns the menu withrun_flow_async, its actions bound toTerminalDialogs. It holds the live panel off the screen for the whole menu, not just per widget.sign_in.wait_for_sign_innow usesTerminalDialogs.wait, so the sign-in waiting screen isn't duplicated. The one visible change is that its button says "Cancel" instead of "Cancel sign-in".- First adopter:
compactionnow declaressettings_menu()instead of overridingconfigure(). The menu looks and behaves the same, except that the message when nothing changed now reads "Compaction settings: nothing changed."
Flicker prototype (done before this design). Running one run_worker per dialog means the panel is released between dialogs. I recorded raw terminal output (tmux pipe-pane) while editing compaction's menu three times, comparing today's single-worker flow, one worker per dialog, and one worker per dialog with a 250 ms pause between dialogs. In all three, 0 bytes reached the main screen between one widget leaving the alternate screen and the next entering it, and the per-dialog version added about 1 ms per switch. A turn streaming output during a slow action could still paint in that gap, so run_settings_menu holds the panel for the whole menu, which makes that impossible.
Verification.
tests/clai2/test_dialogs.pycovers each dialog's widget (labels, current marker, search past 8, preview text, mask, validator, initial text, cancel paths), thewaitresults, a declared menu running an action under one hold, the baseconfigure(), andhas_configure.- The sign-in and compaction tests are updated. 100% branch coverage on
plugins/menus.py,ui/menus/dialogs.py,plugins/sign_in.pyandcompaction.py. - Pyright and ruff are clean, and the affected suites pass (2,489 tests). One test,
test_system_prompt_menu, failed once under xdist; it is terminal-size dependent and passes alone, with or without this change. - Real terminal in tmux:
/plugins configure compaction→ edited Threshold → Esc → "Saved Threshold.", with the same screens as before.
What changes for existing users. Nothing visible except the two small text changes above. Plugin authors get settings_menu(). Overriding configure() still works and stays terminal-only.
- 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.