Skip to content

feat(tui): wire usePlanTree to DB indexer for live plan state #149

@paulbreuler

Description

@paulbreuler

Problem

src/tui/hooks/usePlanTree.ts has a stub implementation that always returns an empty plan array. The TUI Plans pane shows "No plans loaded" regardless of what's indexed.

Current behavior

export function usePlanTree(pollIntervalMs = 3000): PlanNode[] {
  const [plans, setPlans] = useState<PlanNode[]>([]);

  useEffect(() => {
    setPlans([]);
    const interval = setInterval(() => {
      // TODO: integrate with DB indexer
    }, pollIntervalMs);
    return () => clearInterval(interval);
  }, [pollIntervalMs]);

  return plans;
}

Expected behavior

The hook polls the DB indexer (or subscribes to file-watcher events) and returns a live tree of PlanNode[]. Each PlanNode contains id, name, status, and agents[] with real statuses from the agent frontmatter.

Acceptance criteria

  • Hook fetches plans + agents from the SQLite DB on mount and on each poll interval
  • PlanNode.agents reflects current agent statuses (GAP, WIP, PASS, BLOCKED)
  • Updates are reflected within the pollIntervalMs window (default 3s)
  • ACP update_status calls trigger a re-poll (via AcpSessionManager status_updated event)
  • Hook cleans up interval on unmount (no memory leaks)
  • Tests cover: empty workspace, multiple plans, status updates

Files to modify

  • src/tui/hooks/usePlanTree.ts — implement DB polling
  • src/tui/app.tsx — pass DB context or config to the hook
  • tests/tui/hooks.test.ts — add tests with temp DB fixture

Related

  • src/indexer.tslistPlans, listAgents query functions
  • src/acp/session-manager.tsstatus_updated event to trigger re-poll

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions