"""The plan item that routes a fresh chunk of loop-claude's: agent_cycle/routing.py's first_route picks the worker's rung from its L.""" from release_plan.release_standing import chunk_item, LastCut, Next from failure import Failure from plan.todo_table import Item, NoItemsTable from plan_store.plans import Plan def routed_item(plan: Plan | Failure, cut: LastCut, item_id: int | None = None) -> Item | Failure | None: """The plan's item item_id, or without one the item release_standing.chunk_item picks from plan, weighed against the last cut; None when there is none, or it lacks L, E or I.""" if isinstance(plan, NoItemsTable): return None if isinstance(plan, Failure): return plan if item_id is None: pick = chunk_item(plan.items, cut) takes = pick.item if isinstance(pick, Next) else None else: takes = next((item for item in plan.items if item.id == item_id), None) return takes if takes and takes.likelihood and takes.escape_and_impact else None