Skip to content

zettelkasten.dashboard.backend.routes.guide

zettelkasten.dashboard.backend.routes.guide

Decision-tree ("guide") routes.

Traverse a corpus of conditional requirement notes (a standard/code extracted under the reference-standard schema) against a design parameter context and return the pruned decision tree — the data the frontend Guide view renders and the active decision-path overlay highlights. Read-only; nothing is written.

Split out of the former flat routes.py convention; mirrors its sibling domain modules (own APIRouter, shared state via ._common).

GuideRequest

Bases: BaseModel

Request body for a decision-tree walk.

Scope with EITHER project (its sources are walked as a forest) or graph (a single source/synthesis graph). params is the design context predicates are evaluated against; action is apply (full bundle) or next (the next unresolved decision).

Source code in zettelkasten/dashboard/backend/routes/guide.py
class GuideRequest(BaseModel):
    """Request body for a decision-tree walk.

    Scope with EITHER ``project`` (its sources are walked as a forest) or
    ``graph`` (a single source/synthesis graph). ``params`` is the design context
    predicates are evaluated against; ``action`` is ``apply`` (full bundle) or
    ``next`` (the next unresolved decision).
    """

    project: str = ""
    graph: str = ""
    params: dict = {}
    action: str = "apply"

run_guide

run_guide(req: GuideRequest) -> dict

Walk a requirement corpus for req.params and return the pruned tree.

Source code in zettelkasten/dashboard/backend/routes/guide.py
@router.post("/guide")
def run_guide(req: GuideRequest) -> dict:
    """Walk a requirement corpus for ``req.params`` and return the pruned tree."""
    if not (req.project or req.graph):
        raise HTTPException(
            status_code=400, detail="Provide either 'project' or 'graph'."
        )
    if req.action not in ("apply", "next"):
        raise HTTPException(
            status_code=400, detail=f"Unknown action '{req.action}'. Use 'apply' or 'next'."
        )
    result = decision_tree.walk(
        graph=req.graph,
        params=req.params or {},
        project=req.project,
        get_graph=_get_graph_structural,  # noqa: F405 (structural load: no embeddings)
    )
    if req.action == "next":
        nxt = decision_tree.next_decision(result)
        return {
            "next": nxt,
            "params": result["params"],
            "graphs": result["graphs"],
            "remaining_unresolved": len(result["unresolved"]),
            "summary": result["summary"],
        }
    return result