Repository navigation
Description
Summary
Add a dedicated impact analysis endpoint (/api/impact) and corresponding UI view to the graph explorer. Given a subject (e.g., "trading", "spear", "Q"), return all connected facts grouped by relationship type with confidence heatmap data — answering "show me everything connected to X and how confident I am about each piece."
Parent epic: #204
Background
Cortex's current graph API (/api/graph) supports fact-ID traversal and subject drilldown, but it returns raw nodes/edges without semantic grouping. Users must manually explore to understand the full "blast radius" of a topic.
GitNexus's impact tool demonstrates the value of pre-structured responses: one query returns callers grouped by cluster with confidence scores. For a knowledge graph, the equivalent is: "What do I know about X, organized by relationship type, ranked by confidence?"
Implementation Plan
1. Impact endpoint (/api/impact)
GET /api/impact?subject=trading&depth=3&min_confidence=0.3
Response structure:
{
"subject": "trading",
"total_facts": 47,
"depth": 3,
"groups": [
{
"relationship": "has_strategy",
"facts": [
{
"id": 1234,
"subject": "trading",
"predicate": "uses strategy",
"object": "ORB (Opening Range Breakout)",
"confidence": 0.92,
"source": "memory/2026-02-09.md",
"last_updated": "2026-02-09T14:30:00Z",
"connected_count": 12
}
],
"avg_confidence": 0.87,
"fact_count": 8
},
{
"relationship": "has_tool",
"facts": [...],
"avg_confidence": 0.79,
"fact_count": 15
},
{
"relationship": "related_to",
"facts": [...],
"avg_confidence": 0.65,
"fact_count": 24
}
],
"confidence_distribution": {
"high": 18,
"medium": 20,
"low": 9
},
"connected_subjects": ["alpaca", "public.com", "orb", "options", "spy", "qqq"]
}Grouping logic:
- Start from all facts where
subjectmatches (case-insensitive) - Traverse edges up to
depthhops - Group collected facts by predicate category (normalize predicates into relationship types)
- Within each group, sort by confidence descending
- Compute per-group stats (avg confidence, count)
- Return
connected_subjects— unique subjects encountered during traversal (excluding root)
2. Predicate normalization (internal/graph/predicates.go)
Map raw predicates to semantic groups:
var predicateGroups = map[string]string{
"uses": "has_tool",
"runs on": "has_tool",
"configured with": "has_config",
"strategy": "has_strategy",
"located at": "has_location",
"works with": "related_to",
"depends on": "depends_on",
// ... extensible mapping
}Unmapped predicates fall into "other" group. The mapping should be data-driven — scan existing predicates in DB to build initial map.
3. Graph UI — Impact View mode
Add an "Impact" button/mode to the graph explorer sidebar:
UI flow:
- User types a subject in the search box and clicks "Impact" (or hits
/api/impacticon) - Sidebar shows grouped results with:
- Collapsible sections per relationship type
- Confidence color coding (green >0.8, yellow 0.5–0.8, red <0.5)
- Fact count badges per group
- "Connected subjects" as clickable chips (clicking drills into that subject's impact)
- Graph canvas highlights the impact subgraph with:
- Root subject node enlarged and centered
- Edge colors matching relationship group
- Node opacity scaled by confidence (high confidence = solid, low = faded)
- Concentric layout option: root center, depth-1 ring, depth-2 ring
Confidence heatmap in stats bar:
- Three-segment bar:
[HIGH 18] [MED 20] [LOW 9]with green/yellow/red colors - Replaces the standard stats bar when in impact mode
4. Server handler (internal/graph/server.go)
mux.HandleFunc("/api/impact", func(w http.ResponseWriter, r *http.Request) {
handleImpactAPI(w, r, cfg.Store)
})- Reuse existing
TraverseGraph()for depth traversal - Add
GroupByPredicate()post-processing - Add confidence distribution computation
Testing
| Test | Description |
|---|---|
TestImpactBasicSubject |
Single subject returns grouped facts |
TestImpactDepthLimiting |
Depth=1 vs depth=3 returns different result counts |
TestImpactConfidenceFilter |
min_confidence=0.5 excludes low-confidence facts |
TestImpactPredicateGrouping |
Similar predicates map to same group |
TestImpactEmptySubject |
Returns 404/empty for unknown subject |
TestImpactConnectedSubjects |
Connected subjects list is accurate and deduplicated |
TestImpactConcentric |
Nodes have depth metadata for ring layout |
Acceptance Criteria
-
GET /api/impact?subject=tradingreturns grouped, scored response - Graph UI has "Impact" mode button in sidebar
- Clicking impact shows confidence heatmap bar
- Connected subjects are clickable for chained exploration
- Concentric ring layout option works for impact view
- 7+ new tests passing
- Existing graph endpoints unaffected
Files to Modify/Create
| File | Change |
|---|---|
internal/graph/impact.go |
New — impact analysis logic + predicate grouping |
internal/graph/impact_test.go |
New — tests |
internal/graph/predicates.go |
New — predicate → group mapping |
internal/graph/server.go |
Register /api/impact handler |
internal/graph/visualizer.html |
Impact mode UI, confidence heatmap, concentric layout |
Estimated Effort
Medium — new endpoint + UI mode. Traversal logic exists; main work is grouping/scoring and the UI panel.
Activity
feat(graph): add impact blast-radius endpoint and view (#206)