Files
ai-agent/backend/plugins/catalog_repo.py
gabrielvidalandClaude Opus 5.5 34a8e4a8eb feat(plugins): an install bridge for the plugin-catalog plugin
A sandboxed frame may now ask the host to install or uninstall a plugin of
the public catalog — never do it itself (form
plugin-catalog-and-public-plugins-repo_al2ibd):

- New operator-only capability `plugins.manage` (in the approval
  fingerprint). aiAgentPlugin.plugins.list() / .install({source}) /
  .uninstall({id}) answer only the operator, and only a plugin of theirs that
  holds it (enabled, approved); anyone else gets a refusal.
- An install source must be `<catalogRepo>#plugins/<id>`; the host validates
  it (refreshed clone), checks the folder holds that id and draws the
  confirmation — name, version, source, every capability, what an update
  replaces — before its own POST /api/plugins/install. An uninstall asks keep
  or delete data and secrets each time. A plugin can't uninstall itself.
- PLUGIN_CATALOG_REPO (plugins/catalog_repo.py, default the public mirror
  gabrielvidal/ai-agent-plugins-public.git), served as `catalogRepo` on
  GET /api/plugins to the operator only.
- Settings → Plugins (operator): All / Installed / Available gives way to
  *Browse the catalog* (the page that opens `plugin-catalog`); promoted hub
  catalog entries wear *For guests*; old ?show=available / ?tab=catalog&kind=
  links redirect to the plugin's page on that shelf; with the plugin off, a
  note offers to install it again. Guests' page unchanged.

Tests: test_plugin_catalog_bridge.py (capability, repo rule, guest kept out),
catalogBridge.test.tsx (refusals, confirm-then-install, cancel, keep/delete).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 20:07:05 +01:00

43 lines
1.7 KiB
Python

"""The public plugin catalog's repository — where the ``plugin-catalog``
plugin's Install buttons may install from (since 2026-11-28).
The catalog site (``ai-agent.plugins.gabvdl.xyz``, built by the plugins repo's
``scripts/build-catalog.py``) names each plugin's source as
``<repo>#plugins/<id>``. A sandboxed frame may only ask the host to install
such a source (``business/plugins/catalogBridge.tsx`` checks it against the
``catalogRepo`` of ``GET /api/plugins``); anything else still goes through
Settings → Plugins → Install….
``PLUGIN_CATALOG_REPO`` overrides the default — one setting, the mirror may
move.
"""
from __future__ import annotations
import os
import re
DEFAULT_REPO = "https://git.gabvdl.xyz/gabrielvidal/ai-agent-plugins-public.git"
_REPO_RE = re.compile(r"^https://[A-Za-z0-9.-]+(:\d+)?(/[A-Za-z0-9._~-]+)+\.git$")
_ID_RE = re.compile(r"^[a-z0-9][a-z0-9-]{0,47}$")
def repo() -> str | None:
"""The catalog repository's git URL (``https://…/x.git``), or None when
the setting isn't one (the frame's installs are then all refused)."""
raw = (os.environ.get("PLUGIN_CATALOG_REPO") or DEFAULT_REPO).strip()
return raw if _REPO_RE.match(raw) else None
def plugin_id_of(source: str, base: str | None = None) -> str | None:
"""The plugin id of a catalog source (``<repo>#plugins/<id>``), or None
when ``source`` isn't one of the catalog repo's plugins."""
base = repo() if base is None else base
if not base or not isinstance(source, str):
return None
head, sep, sub = source.partition("#")
if not sep or head != base or not sub.startswith("plugins/"):
return None
pid = sub[len("plugins/"):]
return pid if _ID_RE.match(pid) else None