backend/plans/ (store + /api/plans, /api/plan, /api/plan/answers),
schemas/plans.py and ConversationDetail.plans are gone; data/plans is the
`plans` plugin's (ai-agent-plugins, plugins/plans).
- plugins/plans_bridge.py: list_plans / get_plan through the plugin that
provides `plans.index` (and its `get`), as the owner — [] / None without it
- graph.read builds its plan nodes from plans_bridge
- `ai-agent plans` and MCP browse("plans") / read_document("plan") call
/api/plugins/plans/actions/{index,get}, and say so when the plugin is off
- frontend: business/plans/ removed; /plans and /plans/:slug redirect to
/plugins/plans/plans[/<slug>]; the Write card's built-in plan widget, the
Files/nav entries, usePlans and the tags' plan counts are gone; the Details
drawer's Plans card became `pluginSlots` (conversation.details slots, saved
layouts carried over); a bare slot may resize(0) to fold away
- openapi.json + src/generated: only the plan paths/models removed (the spec
is edited, not re-dumped — see the PR notes); mocks and French keys follow
- test_plans_bridge.py; CLI tests for the plugin route
authz/matrix.golden.txt is left for the coordinator (the plan routes left
lab.read / lab.settings).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
3.3 KiB
Python
93 lines
3.3 KiB
Python
"""The hub's read of implementation plans, now that Plans is a live plugin.
|
|
|
|
``data/plans/*.md`` (written by the ``plan`` skill) used to be parsed by
|
|
``backend/plans/``; since 2026-11-25 the ``plans`` plugin owns them. Core code
|
|
that still needs the list — the Graph plugin's ``graph.read`` bridge — asks the
|
|
plugin that declares ``provides: {"plans.index": "<action>"}`` (and, for one
|
|
plan, that plugin's ``get`` action), as the owner.
|
|
|
|
Both degrade quietly: with no Plans plugin installed, disabled or failing,
|
|
:func:`list_plans` is ``[]`` and :func:`get_plan` is ``None`` — a hub without
|
|
the plugin simply has no plans.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from plugins.store import OWNER_UID
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
PROVIDES = "plans.index"
|
|
|
|
|
|
def _provider(deps) -> tuple[dict[str, Any], str] | None:
|
|
"""The owner's active plugin providing ``plans.index`` → (rec, action)."""
|
|
from plugins.waiting import _providers_for
|
|
|
|
try:
|
|
found = _providers_for(deps, OWNER_UID, PROVIDES)
|
|
except Exception: # noqa: BLE001 — no plugin store (tests, early boot)
|
|
return None
|
|
for rec, _grant in found:
|
|
mf = rec.get("manifest") or {}
|
|
act = (mf.get("provides") or {}).get(PROVIDES)
|
|
if act in (mf.get("actions") or {}):
|
|
return rec, act
|
|
return None
|
|
|
|
|
|
def _run(deps, rec: dict[str, Any], action: str, payload: dict[str, Any]) -> dict[str, Any]:
|
|
from plugins.runner import run_script
|
|
|
|
act = (rec.get("manifest") or {}).get("actions", {}).get(action)
|
|
if not act:
|
|
raise LookupError(action)
|
|
return run_script(deps, deps.plugin_store, OWNER_UID, rec, act["script"],
|
|
payload=payload, timeout_sec=int(act.get("timeoutSec") or 20))
|
|
|
|
|
|
def available(deps) -> bool:
|
|
return _provider(deps) is not None
|
|
|
|
|
|
def list_plans(deps) -> list[dict[str, Any]]:
|
|
"""Every plan summary (slug, title, status, sessionId, conversationIds,
|
|
projects, services, estimates…), newest first; ``[]`` without the plugin."""
|
|
hit = _provider(deps)
|
|
if hit is None:
|
|
return []
|
|
rec, action = hit
|
|
try:
|
|
res = _run(deps, rec, action, {})
|
|
except Exception as e: # noqa: BLE001 — a broken plugin never breaks the hub
|
|
log.warning("plans.index via %s failed: %s", rec.get("id"), e)
|
|
return []
|
|
plans = res.get("plans") if isinstance(res, dict) else None
|
|
return [p for p in plans if isinstance(p, dict) and p.get("slug")] if isinstance(plans, list) else []
|
|
|
|
|
|
def get_plan(deps, slug: str) -> dict[str, Any] | None:
|
|
"""One plan (body, files, steps, questions, actuals) through the providing
|
|
plugin's ``get`` action; ``None`` when absent or without the plugin."""
|
|
hit = _provider(deps)
|
|
if hit is None or not slug:
|
|
return None
|
|
rec, _action = hit
|
|
from plugins.runner import ActionError
|
|
|
|
try:
|
|
res = _run(deps, rec, "get", {"slug": slug})
|
|
except LookupError:
|
|
return None
|
|
except ActionError as e:
|
|
if e.status != 404:
|
|
log.warning("plans get %s via %s failed: %s", slug, rec.get("id"), e.message)
|
|
return None
|
|
except Exception as e: # noqa: BLE001
|
|
log.warning("plans get %s via %s failed: %s", slug, rec.get("id"), e)
|
|
return None
|
|
return res if isinstance(res, dict) and res.get("slug") else None
|