Background
The fix for session/sub-agent relationships (populating parentSessionId and subAgentIds) introduced repeated code in 4 places:
get_project()
list_sessions()
get_session()
get_activity()
Proposal
Extract the relationship population logic into a shared helper function:
def populate_session_relationships(sessions: list[dict], project_dir: Path) -> None:
"""Populate parentSessionId and subAgentIds on session dicts in-place."""
...
This would reduce code duplication and make future changes easier to maintain.
Files to modify
api/src/utils.py - Add helper function
api/src/routes/projects.py - Use helper in 3 places
api/src/routes/activity.py - Use helper in 1 place