"""The plan as a listing a reviewer reads with the Read tool, whatever store holds the plan.""" from failure import Failure from plan.todo_table import Item from plan_store.plans import PlanStore from plan.release import version def plan_listing(plan: PlanStore) -> str: """The plan's items as the store supplies them, each with its release, tagline, blockers and detail. Where the plan can't be read, says so, so a reviewer doesn't take it for empty.""" read = plan.read() opening = f"# Plan, as {plan.label} holds it\n\n" if isinstance(read, Failure): return f"{opening}The plan cannot be read, so no item is listed: {read.reason}\n" if not read.items: return f"{opening}The plan holds no item.\n" return opening + "\n".join(item_listing(item) for item in read.items) def item_listing(item: Item) -> str: blockers = ", ".join(map(str, item.blocked_by)) parts = [f"## Item {item.id}, release {version(item.release)}", item.tagline, *([f"Blocked by: {blockers}."] if blockers else []), *([item.detail] if item.detail else [])] return "\n\n".join(parts) + "\n"