ID:WORK-146Status:done
Extract relationship builder into relationships module
Extract the relationship graph construction logic (~120 lines) from pipeline.ts's aggregate hook into a new relationships.ts module with zero Node.js imports.
Priority:highComplexity:moderateSource:SPEC-040
Acceptance Criteria
- New file
runes/plan/src/relationships.tsexists relationships.tshas zero imports fromnode:fs,node:path, ornode:child_processbuildRelationships()function is exported and produces aMap<string, EntityRelationship[]>EntityRelationshipinterface is exported with all relationship kinds:blocks,blocked-by,depends-on,dependency-of,implements,implemented-by,informs,informed-by,related- Source references produce
implements/implemented-byedges (orinforms/informed-byfor decisions) - Scanner dependencies produce
depends-on/dependency-ofedges - ID references produce
relatededges (orblocked-by/blockswhen entity status isblocked) - Duplicate edge suppression works: source-linked and dep-linked pairs are excluded from text-based ID reference edges
- Pipeline's aggregate hook calls
buildRelationships()instead of inlining the logic - All existing relationship behaviour is preserved — same edges, same directions, same deduplication
- Existing tests pass without modification
Approach
- Create
relationships.ts. Define theEntityRelationshipinterface (currently inline inpipeline.ts). Move theaddRelhelper function and the three reference-processing loops (source refs, scanner deps, ID refs) into abuildRelationships()function. - The function accepts the same data the aggregate hook currently uses: an entity map, source references, scanner dependencies, and ID references. The entity map uses a minimal shape (
{ type: string; data: Record<string, any> }) rather than requiring the fullEntityRegistrationtype, to keep the module self-contained. - In
pipeline.ts, importbuildRelationshipsand call it from the aggregate hook, passing the existingallEntities,_sourceReferences,_scannerDependencies, and_idReferencesmaps. - Remove the
EntityRelationshipinterface definition frompipeline.ts— import it fromrelationships.tsinstead. - Run existing tests to confirm no regressions.
Dependencies
None — independent of the scanner and diff extractions.
References
- Edge Runtime Compatibility for Plan Package — Edge Runtime Compatibility for Plan Package
Resolution
Completed: 2026-04-14
Branch: claude/edge-runtime-refactor-HOg8v
What was done
- Created
runes/plan/src/relationships.tswithbuildRelationships()function andEntityRelationshipinterface - Defined
RelationshipEntityminimal interface so the module doesn't depend on @refrakt-md/types - Pipeline's aggregate hook now calls buildRelationships() with allEntities, _sourceReferences, _scannerDependencies, _idReferences
- Removed inline EntityRelationship interface from pipeline.ts; re-exports from relationships.ts for backwards compatibility
Notes
- relationships.ts has zero external dependencies — pure TypeScript only
- All 10 relationship-related tests pass (implements, informed-by, blocks, deduplication)
Relationships
Dependency of
History
- 888d791statusready→done
- ☑ New file `runes/plan/src/relationships.ts` exists
- ☑ `relationships.ts` has zero imports from `node:fs`, `node:path`, or `node:child_process`
- ☑ `buildRelationships()` function is exported and produces a `Map<string, EntityRelationship[]>`
- +8 more criteria
- 7340389Created (ready, high, moderate, SPEC-040, plan, architecture, edge-runtime)