"""Scribe-plugin support endpoints. Consumed by the Scribe Claude Code plugin (not the web UI). `GET /api/plugin/ context` is curled by the plugin's SessionStart hook to push the operator's always-on rules + active-project context into the session — Scribe's own push channel. Auth is the standard `@login_required` path, which accepts a `Bearer fmcp_` API key (a read-scoped key suffices for this GET). """ from __future__ import annotations from quart import Blueprint, g, jsonify, request from scribe.auth import login_required from scribe.services import plugin_context as plugin_ctx_svc plugin_bp = Blueprint("plugin", __name__, url_prefix="/api/plugin") @plugin_bp.get("/context") @login_required async def session_context(): """Return SessionStart context (always-on rules + optional project). Query: project_id (optional int) — when set, includes that project's goal and open-task count. The hook passes the bound project's id here. """ try: project_id = int(request.args.get("project_id", 0) or 0) except (TypeError, ValueError): project_id = 0 result = await plugin_ctx_svc.build_session_context(g.user.id, project_id) return jsonify(result)