Files
taskgraph_ts/tasks/implementation/analysis/critical-path.md
glm-5.1 131e3e929b Decompose architecture into 28 atomic implementation tasks
Break the @alkdev/taskgraph architecture specs into dependency-ordered
implementation tasks across 8 component directories: setup, schema,
error, graph, analysis, cost-benefit, frontmatter, api, and review.
Each task has clear acceptance criteria referencing specific architecture
docs. Three review tasks serve as quality gates at critical junction
points (schemas-and-errors, graph-complete, complete-library). The
dependency graph is validated acyclic with 9 topological levels enabling
significant parallelism across independent work streams.
2026-04-27 08:30:05 +00:00

40 lines
1.6 KiB
Markdown

---
id: analysis/critical-path
name: Implement criticalPath and weightedCriticalPath functions
status: pending
depends_on:
- graph/construction
- graph/queries
scope: moderate
risk: medium
impact: component
level: implementation
---
## Description
Implement `criticalPath` and `weightedCriticalPath` as standalone functions. `criticalPath` finds the longest path from sources to sinks using default edge weighting. `weightedCriticalPath` accepts a custom weight function for per-node weighting.
`criticalPath` can be implemented via topological order + dynamic programming (longest path in DAG). For unweighted, each edge has weight 1; for weighted, each node contributes a weight.
## Acceptance Criteria
- [ ] `criticalPath(graph: TaskGraph): string[]` — returns the longest path as an ordered array of task IDs
- [ ] `weightedCriticalPath(graph: TaskGraph, weightFn: (taskId: string, attrs: TaskGraphNodeAttributes) => number): string[]` — returns the path with the highest cumulative weight
- [ ] Both functions throw `CircularDependencyError` if graph is cyclic
- [ ] When multiple paths tie, returns any one of them (deterministic order preferred)
- [ ] Empty graph returns `[]`; single-node graph returns `[nodeId]`
- [ ] Unit tests: linear chain (the chain itself is critical path), diamond graph (tests path selection), weighted variant with diverse scope values
## References
- docs/architecture/api-surface.md — criticalPath, weightedCriticalPath signatures
- docs/architecture/graph-model.md — edge direction (prerequisite→dependent determines source→sink)
## Notes
> To be filled by implementation agent
## Summary
> To be filled on completion