Show declared `clai2` plugin settings menus in the web UI, with their dialogs
Part 16 of the clai2 web UI stack (… → #10312 → this PR). Based on #10312. No linked issue: requested by the CLAI maintainer.
Why. #10312 lets a plugin declare its settings menu, SettingsMenu plus Dialogs, instead of running it in the terminal. This PR renders those declared menus in the web UI's plugins panel, actions and dialogs included, so sign-ins and /keys entries no longer need the terminal once a plugin is ported. The per-plugin ports follow in their own PRs.
Core (host.plugins)
PluginCatalog.settings_menu(name)returns a loaded plugin's declaredSettingsMenu, orNone.PluginCatalog.edit_settings(name, edit):- runs one edit against the declared menu, such as applying or resetting a row or running an action with the caller's own
Dialogs; - reloads the plugin if its saved settings changed, exactly as closing the terminal menu does;
- is locked per plugin: while the terminal shows the menu, or an action's dialogs are open in the page, other edits are refused with "The settings menu of NAME is already open". That error is a
ValueError.
- runs one edit against the declared menu, such as applying or resetting a row or running an action with the caller's own
PluginLoader:configure,save_settingsandedit_settingsnow share one_settings_opencontext manager (lock → yield → reload if changed), which replaces two copies of that logic.PluginInfo.settings_menu: whether the plugin declares its menu.
Web plugin
GET /api/plugins/{name}/fieldsreturns the rows with their current values. Sources run off the loop, as the terminal's do.POST /api/plugins/{name}/fields/{key}takes{value}. Empty ornullresets, as an empty terminal edit does. A value the menu rejects comes back as a 400 with the row's own message, and nothing is saved.POST /api/plugins/{name}/fields/{key}/actionruns the row's action and returns its messages and the refreshed menu.BrowserDialogs(web/dialogs.py) implementsDialogs, built like theask_userquestions:- Each dialog is pushed over the WebSocket (
dialog,dialog_shownfor await's updates,dialog_closed) and answered withPOST /api/dialogs/{id}. chooserejects values it didn't offer.textrunscheckon the server and keeps the dialog open with the reason.- A secret's text is never echoed to any browser.
- Open dialogs appear in the connection snapshot, so a reload still shows them. Stopping the web UI backs out of them, which also releases the plugin's lock.
- Each dialog is pushed over the WebSocket (
- Rows replace the JSON Schema form for plugins that declare a menu. Others keep the form, and Open its menu for a
configure()override.
UI
MenuFormshows the declared rows:- a switch for yes/no rows, a dropdown for choices (with "Other…" when typing your own is allowed), and a field otherwise (masked for secrets, never prefilled);
- Reset when a value differs from its default, the row's note, and a per-row Saved state or error;
- Change… (named "Change ROW" for screen readers) runs a row's action.
DialogLayershows one dialog at a time above everything:- choose: a list with descriptions and a "current" mark, a filter past 8 options, and arrow keys plus Enter;
- text: a masked input with an inline error from
check; - confirm: the safe answer is focused;
- wait: a spinner, the latest shown text with clickable links, and Cancel. It closes by itself when the task ends.
- Esc backs out of the dialog only, not the panel behind it.
- Toasts are now fixed above the overlays. Errors raised inside the panel used to render underneath it. Toasts also gained an info style for menu messages.
- Scrollbars: the panel's two columns and the dialog lists keep a thin scrollbar visible. macOS overlay scrollbars hid that the settings continue below the fold.
Also in this PR (merged up from #10312): Dialogs.text(description=...), which Slack's Client ID step needs (a link to create the app).
Verification.
- Tests:
test_web.pycovers the listing flags, field reads and edits, rejected values, resets, unknown rows and plugins, the serving plugin, a reload that fails after an edit, and a full action over HTTP and WebSocket:- choose (rejected value, then accepted), shown in a new connection's snapshot;
- masked text (rejected by
check, then accepted), with its description; - the per-plugin lock, refusing a concurrent edit;
- confirm, then late answers getting a 404;
- backing out at the first dialog;
- a
waitthat shows a link and finishes; - stopping the web UI mid-dialog.
test_web_parts.pycovers cancelling a wait, a failing wait task, andcancel_allskipping an answered dialog.test_plugin_loader.pycoversedit_settings, its lock (the terminalconfigureis refused mid-edit), and reload-after-change.- Checks: 100% branch coverage of
builtin_plugins/web/*, and every line this PR adds toloader.pyandplugins/__init__.pyis covered. Pyright and ruff are clean,tscis clean, the bundle is rebuilt, and 211 tests pass across the affected suites. - Headed Playwright against an isolated
clai2 --web -m test, using compaction (declared in #10312) and a scratch drop-in plugin whose action uses all four dialogs:- compaction: threshold 7 was rejected with "Input should be less than or equal to 1"; 0.7 saved with a "Saved Threshold." toast; Reset worked; Strategy changed by dropdown.
- Demo: the switch toggled; choose → masked text (rejected "nope", accepted
demo_123) → token saved; a second time, the confirm dialog had "Keep" focused, and Esc gave "Kept the saved token." with the panel still open; browser sign-in → the wait showed a clickable link and closed itself → "Signed in to Demo." - Light mode checked, no page errors. Screenshots 67–73.
What changes for existing users. Only plugins that declare a menu render differently (in this stack so far, compaction). Everything else behaves as in #10289.
- 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.