Add a plugins panel with settings forms to the `clai2` web UI, and `host.plugins`

Merged
MP
2mo ago
+2201-179

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

Why. /plugins in the browser opened the terminal's menu. This brings the menu to the web UI: every plugin with an on/off switch, and a form for its settings. Each change is validated, saved and applied at once, as the terminal does.

New public surface (core)

  • host.plugins: a PluginCatalog protocol, like host.sessions. The shell's PluginLoader satisfies it, and hosts built outside the loader get None.
    • listing() returns one PluginInfo per /plugins row. While a plugin is on, the row includes its settings model and its saved settings.
    • enable / disable / reload are the loader's existing methods.
    • save_settings(name, settings) takes an instance of the plugin's own model. It saves through the plugin's host, exactly as a configure() menu does with host.save_settings, then loads the plugin again if anything changed, as /plugins configure does.
  • PluginEntry.origin / .status / .own_status now hold the labels the terminal menu computed privately, so the terminal and the browser share one definition.
  • describe() takes (factory, path) instead of an entry, so the loader can call it without an import cycle.

Web plugin

  • GET /api/plugins, POST /api/plugins/{name}/{enable|disable|reload}, POST /api/plugins/{name}/settings (changes, reset), and POST /api/plugins/{name}/menu, which sends /plugins configure NAME to the terminal.
  • Settings form: built from the settings model's JSON Schema. Values are merged with the saved settings and validated by the model. A rejected value answers 422 with one message per field, and nothing is saved.
  • Live updates: every command end publishes a plugins message, so an open panel follows changes made in the terminal.
  • Self-protection: the panel refuses to disable, reload or reconfigure web itself. That would restart the server with a new token and end the page.
  • WebSettings reads its attribute docstrings, so its form has descriptions.

UI. A modal panel, opened from the puzzle button in the sidebar's footer, ⌘/Ctrl+,, or /plugins typed in the composer.

  • List: searchable, with status dots and switches.
  • Detail: description, source, errors and notices, what the plugin provides, and its settings form.
  • Controls by field type: switches for booleans, dropdowns for enums, constants and mixed literals, fields for text and numbers (an empty optional field means "not set"), one item per line for lists of strings, inline sub-fields for nested models (a /keys KeyReference reads as its name), and JSON for anything else.
  • Saving: each field saves on change, Enter or blur, with a per-field Saved / error state and a Reset to its default. Esc undoes an unsaved edit; the next Esc closes the panel.
  • A plugin's own menu (sign-ins, keys) opens in the terminal from Open its menu. The page explains when there is no terminal (clai2 --web).

Verification.

  • Tests:
    • tests/clai2/test_web.py: the listing (origins, statuses, included, no settings, a model with no JSON Schema, a plugin that is off), per-field 422 errors, reset, the plugin left failed when it refuses new settings at load, enable/disable/reload, a plugin that fails to import, the self-protection, the terminal menu over the WebSocket, and a host without plugins.
    • tests/clai2/test_plugin_loader.py: the catalog checks the model and requires a loaded plugin.
  • Checks: pyright clean. The web plugin, describe and plugin_menu have 100% branch coverage, and the lines this PR adds to loader.py and plugins/__init__.py are all covered. tsc and npm run build are clean.
  • Headed Playwright, against an isolated config (XDG_* in /tmp):
    • repo_context: toggled walk_up and changed nested_inject.
    • compaction: saved threshold=7, which showed "Input should be less than or equal to 1", then saved 0.6 and reset it to 0.85.
    • github: turned on, then its form had a dropdown, a key name, a URL field, switches and a list.
    • web: shown read-only.
    • Esc, /plugins and ⌘, all worked.
    • From /web in an interactive CLAI, Open its menu opened Coder's settings menu in the terminal, and its result came back as a notice.

What changes for existing users. A new web UI panel and host.plugins. The terminal's /plugins menu looks and behaves as before.

  • 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.