Skip to content

[M10/LNS-001] Extract DAG utilities into src/dag.js #230

@flyingrobots

Description

@flyingrobots

LNS-001: Extract DAG Utilities

Parent: #227 (M10 LENS)

What

Extract DAG utilities from src/views.js (lines 305-446) into src/dag.js:

  • Adjacency builder (from edge list → adjacency maps)
  • Topological sort (Kahn's algorithm)
  • Cycle detection
  • Chain walking (follow edges from a start node)
  • Root finding (nodes with no incoming edges)

Why

These utilities are needed by lenses (LNS-004) and are currently buried in views.js. Extracting them makes them composable and testable in isolation.

Acceptance Criteria

  • src/dag.js exports: buildAdjacency, topoSort, detectCycles, walkChain, findRoots
  • src/views.js imports from src/dag.js (no duplication)
  • All existing view tests still pass
  • New unit tests for each DAG utility
  • No dependencies on graph internals — pure functions on edge arrays

Dependencies

None — can start immediately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    milestone:M10M10 LENS — Composable View ProjectionsrefactoringCode refactoring without changing functionalitywave:1Wave 1 — Foundation (lenses + context + contracts)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions