"""Pages blueprint: server-rendered HTML pages.""" import logging from flask import Blueprint, render_template, request from services import kanban, projects, worker logger = logging.getLogger(__name__) bp = Blueprint("pages", __name__) @bp.route("/") def dashboard(): """Main dashboard: worker status, kanban board, processes, projects strip.""" try: worker_status = worker.get_worker_status() except Exception as exc: logger.exception("dashboard worker_status failed") worker_status = {"current_task": None, "processes": [], "soul_excerpt": ""} try: board_data = kanban.get_kanban_board() board = board_data.get("board", {}) except Exception as exc: logger.exception("dashboard board failed") board = {} try: all_projects = projects.get_all_projects() except Exception as exc: logger.exception("dashboard projects failed") all_projects = [] return render_template( "dashboard.html", worker_status=worker_status, board=board, processes=worker_status.get("processes", []), projects=all_projects, ) @bp.route("/projects") def projects_page(): """Projects table page.""" try: all_projects = projects.get_all_projects() except Exception as exc: logger.exception("projects_page failed") all_projects = [] return render_template("projects.html", projects=all_projects) @bp.route("/projects/") def project_detail_page(name: str): """Project detail page.""" try: detail = projects.get_project_detail(name) except Exception as exc: logger.exception("project_detail_page failed") detail = {"error": str(exc)} return render_template("project_detail.html", project=detail, name=name) @bp.route("/tasks") def tasks_page(): """Tasks table page with optional status filter.""" status = request.args.get("status") try: data = kanban.get_tasks(status) tasks = data.get("tasks", []) counts = data.get("counts", {}) except Exception as exc: logger.exception("tasks_page failed") tasks = [] counts = {} return render_template( "tasks.html", tasks=tasks, counts=counts, current_status=status, ) @bp.route("/tasks/") def task_detail_page(task_id: str): """Task detail page with timeline, comments, runs, attachments.""" try: data = kanban.get_task_detail(task_id) except Exception as exc: logger.exception("task_detail_page failed") data = {"error": str(exc)} return render_template("task_detail.html", data=data, task_id=task_id)