refactor(plugins): install plugins in-process through agent-setup

Merged
HA
24d ago
+1976-661

Closes SUPER-2435, SUPER-2155, and SUPER-3064.

Supersedes #9045 and #9186. Their owner will close them.

What & why

The desktop changed plugins by running the bundled CLI (superset plugins install|uninstall|enable|disable|sync) and did not wait for it (void queuePluginCli(...)). The UI reported success before anything happened, failures went only to the log, and nothing happened at all when no bundled CLI was present (dev). The desktop also kept its own install list in settings.installed_plugins, which was a second record next to installed_plugins.json.

SUPER-2435: shared code instead of the CLI

  • Moved to @superset/agent-setup (next to installed-plugins.ts): plugin-install.ts (install, remove, enable, sync, marketplace clone/list, skills list), plugin-state.ts (the host.ts state helpers), plugin-organization.ts (organization plugins; it takes a structural API type, so agent-setup has no tRPC dependency), plugin-mcp-servers.ts, plugin-marketplace.ts (manifest types, assertSafeSegment, releaseTag). CLIError is replaced by PluginError, which has a code. Paths resolve through resolveAppHomeDir (the current name of resolveSupersetHomeDir).
  • Authoring stays in the CLI: publish, scaffold, validate, and the authoring half of marketplace.ts.
  • The CLI plugins commands are thin wrappers. lib/plugins/errors.ts turns a PluginError into a CLIError and adds the command to run next (for example Run: superset plugins install x --update). host.ts and marketplace.ts re-export from agent-setup and keep only the CLI argument parsing.
  • The desktop calls agent-setup in-process and awaits it. A failure rejects the tRPC mutation, and the existing "Install failed" / "Uninstall failed" toasts show it. Deleted: runPluginCli, queuePluginCli, serial-queue.ts, and the plugins use of resolveBundledCliPath (the CLI shim still uses it). Organization installs and sync use a new main-process cloud client (main/lib/cloud-api-client.ts) with the desktop's own token.
  • Writes are serialized. serializePluginChange in agent-setup runs every desktop plugin change, and the desktop's bundled-skill resyncs, one at a time. createManagedSkills also runs one provisioning at a time, so the boot sync (started without waiting) cannot reap skills that a later change just wrote.
  • installed_plugins.json is the only record. At boot, after migrations, the desktop copies any settings.installed_plugins entry the file lacks (keeping enabled: false), then installs those plugins' trees. A marker file (plugins/.desktop-list-adopted) records which entries were already seen, so each is copied once: what a downgraded build later adds to the column is copied on the next boot, and a plugin removed here is not copied back. A missing marker is empty; a damaged one is an error (logged), never "copy everything again". If the copy fails, the marker is unchanged and the next boot retries. The boot MCP sync (syncInstalledPluginMcpServers) now reads the ledger like every other provisioner.
  • Deviation from SUPER-2435: the column is not dropped. The ticket asks to drop settings.installed_plugins. I tested that and it broke downgrades: an older build on the migrated database failed agent setup and host-service with no such column: "installed_plugins". That's the same reason persist_terminal was restored (0046/0047). The column now stays like terminalPersistence: nothing writes it, and the desktop only reads it at boot to copy unseen entries. It can be dropped in a later release, once a downgrade past this version is no longer expected.
  • docs/plugins.md is updated.

SUPER-2155 (kept from #9045, without plugins local)

  • The desktop passes name@superset (DEFAULT_MARKETPLACE), never a bare name.
  • An MCP config write failure comes back as mcpError. On install and update, the renderer shows a warning ("Agents cannot reach {plugin}'s tools") after the success toast. Enable, disable and uninstall return their mcpError too.
  • Uninstalling or disabling a plugin this machine does not have is a no-op. Enabling one installs it. Toggling a plugin that is not in the catalog does nothing, except that an installed one can still be disabled.
  • A change rejects with "The plugin change did not finish in 60 seconds." 60 s after it is requested, including time spent waiting behind another change. The next change still waits for the slow one to end, so writes never interleave. To keep that wait bounded, git calls time out at 120 s, and the desktop's cloud client aborts requests after 30 s and reports the status of non-JSON error pages (a gateway's 502).
  • From #9045's review: an update keeps a plugin that the member disabled disabled. installPlugin now records through ledgerWithPlugin, the same as organization installs.

SUPER-3064 (from #9186)

  • findConnectTarget() finds a plugin that is installed on the account or in the local ledger.
  • findAvailablePlugin() / availablePlugins() refresh a stale marketplace clone once before reporting that a plugin is missing, and name any refresh that failed. In the long-running desktop, "once" means at most once every 5 minutes per marketplace, rather than once for the life of the process.

Already fixed on main, so left out

  • SUPER-2155's first option, passing the desktop's bearer to the CLI, is already on main: runPluginCli sets SUPERSET_API_KEY. This PR deletes that path entirely.
  • #9045 also removed the SUPERSET_CLI_AUDIENCE: "internal" override. That override lived in runPluginCli, which is now deleted.

New user-facing strings

Translated in every locale: the two from #9045, plus "Sign in to change your organization's plugins." and "Could not download {names}." (organization sync).

Risk to review

  • Moved plugins with no tree are installed in the background after boot. If that fails (offline), the plugin's MCP entry is still written, but its skills arrive only after a later successful install or update. The failures, with reasons, are logged.
  • install --update, which the desktop uses, still installs whatever version is in the local clone and does not fetch first (a limitation already noted on #9186).

How I tested it

  • bun run lint, bun run typecheck (42/42), bun run check:i18n, bun run check:plugins, and sherif pass.
  • Tests on the final commit: CLI 478 pass. Desktop 9076 pass. Shared 1539 pass. Earlier: Shared 1536 pass. i18n 169 pass. agent-setup 451 pass and 2 fail; the 2 are shell-wrappers "falls back to system binaries…" tests, which fail the same way on clean main in this sandbox. host-service 2713 pass and 1 fail; the 1 is health.check … sandbox mode, which also fails on clean main.
  • New tests: plugin-install.test.ts (#9186's refresh tests, including the git-backed one), connect.test.ts, plugin-changes.test.ts, adoptInstalledPlugins, adopt-desktop-install-list.test.ts (copies each entry once, copies what an older build adds later, refuses a damaged marker, retries after a failure), plugin-state.test.ts (corrupt files and malformed entries throw), cloud-api-client.test.ts (deadline, non-JSON errors), run-plugin-change.test.ts (rejects with the error, timeout message, queue held), and errors.test.ts (CLI hints).
  • Smoke test of the in-process path, with a throwaway HOME/SUPERSET_HOME_DIR and this repo as the default marketplace: installed linear@1.5.6 (3 skills, no mcpError), disabled it, updated it (it stayed disabled), removed it, got not-found for an unknown plugin, then adopted a legacy sentry record and restorePluginTrees installed it (skills present).

Reproduced on main, then re-run on this branch

SUPER-3064 (CLI): I ran the real CLI from source (cli-framework dev) against a stub API that reports autumn installed and connected on the account. The setup had an empty ledger and a superset marketplace clone made before autumn was added to its origin. Script: the same four commands as the ticket.

Commandmain (876e8a3)this branch
plugins connect autumn --method oauth2"autumn" is not installedauthorize URL
plugins connect autumn --marketplace superset …not installed from "superset"authorize URL
plugins connect autumn@superset …not installed from "superset"authorize URL
plugins install autumn --marketplace superset --no-waitNo plugin "autumn" in any installed marketplace"Updating superset…", installs autumn@1.0.2, reuses the connection; clone moves to the new commit and the ledger records autumn

SUPER-2155 / SUPER-2435 (desktop, end to end): I ran the dev desktop app signed in against the local API, and drove the Plugins page over CDP with real mouse clicks.

  • main, real bundled CLI, Update on Linear: the "Linear updated" toast appears 0.5 s after the click, about 3 s before the CLI writes the ledger. The CLI succeeds, because main already passes the desktop token. local.db and the ledger disagree (1.5.2 vs 1.5.6).

  • main, no bundled CLI (the dev case), Update on Notion: the toast says "Notion updated", and the log says [plugins] no bundled CLI; skills were not provisioned. Notion is only in local.db.

  • main, a bundled CLI that exits with Error: Not logged in, Update on Circleback: the toast says "Circleback updated", and the log says install circleback --update failed … Not logged in. Circleback is only in local.db.

  • This branch (first version, which still dropped the column), first boot on that same DB: notion and circleback were copied into the ledger and their trees installed.

  • This branch, with the failing stub still in place as the bundled CLI, Update on GitHub: github@1.0.4 is written to the ledger about 0.3 s after the click, and the "GitHub updated" toast comes after that. The CLI is not used.

  • This branch, plugin cache made read-only, Update on Sentry: the toast says "Could not update plugin — EACCES: permission denied, mkdir '…/cache/superset/sentry'", and the ledger is unchanged.

  • After the review fixes, on that dev database with migration 0060 undone and the old column seeded with granola and linear: the boot log shows [plugins] moved granola to the ledger (linear was already present). Granola's tree and both of its skills were installed, the marker was written, the column and its value are untouched, and there were no no such column or agent-setup errors.

  • New regression tests, each checked to fail without its fix: overlapping createManagedSkills runs keep the newer run's skills; a change queued behind a stuck one still times out (the old code hangs).

Final verification on the merge candidate (b4c286605; the CLI and app runs were on e67ce6889, and the last commit only changes skill-provisioning serialization and the marker reader, both unit-tested)

CLI (real CLI from source, stub API, stale marketplace clone):

  • SUPER-3064's four commands: all pass (three authorize URLs; the install refreshes the clone and installs autumn@1.0.2).
  • install autumn by bare name → refreshes and installs. disable / enable → ledger enabled flips. A second install → "autumn" is already installed at 1.0.2. + Hint: Run: superset plugins install autumn --update. sync and skills list list the skill. uninstall → ledger empty. A second uninstall → "autumn" is not installed. + Hint: Run: superset plugins install autumn.

Desktop (dev app signed in to the local API; Plugins page driven over CDP with real clicks):

  • Boot on the old dev database: clean, no column or agent-setup errors.
  • Update on Sentry (not on this machine): ledger + tree + 2 skills, then "Sentry updated".
  • Remove on Sentry: "Sentry uninstalled"; the ledger entry and both skill folders are gone.
  • Plugin cache read-only, Update on Stripe: "Could not update plugin — EACCES …", ledger unchanged. Permissions restored, Update again: ledger + tree + 3 skills, "Stripe updated".
  • The Plugins page offers Disable only for organization-managed plugins, so I called the desktop's own plugins.setEnabled / plugins.uninstall through the app's electronTrpcClient (the real main-process path, not a click): disable Stripe → ledger disabled, skills removed; enable → skills back; disable an absent plugin → no change; enable an absent plugin → installs it with its skills; a name not in the catalog → no change; uninstall → removed.
  • plugins.sync (organization reconcile) → { ok: true } in 1.5 s. The local API log shows authenticated 200s for user.myOrganizations, user.myOrganization and plugins.list from the new main-process client.

Not tested: installing an organization plugin's bundle (the local organization has none), the mcpError warning in the app (dev builds skip MCP sync), and a packaged build.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs
  • I have signed the CLA (the bot asks on your first PR)

Summary by CodeRabbit

  • New Features
    • Plugin installations, removals, and enablement now use consistent installation state across the desktop app and CLI.
    • Existing desktop installations are adopted at startup, and marketplace refreshes can help locate plugins.
  • Bug Fixes
    • Plugin changes are processed sequentially, with clearer feedback for failed downloads and operations that exceed the time limit.
    • The desktop app warns when agents cannot reach a plugin’s tools; plugin connections provide clearer guidance when marketplace matches are ambiguous.
  • Documentation
    • Updated plugin installation guidance.
  • Localization
    • Added translations for plugin errors, sign-in prompts, and timeouts.