Skip to content

feat: add Mermaid output to diff-impact#58

Merged
carlos-alm merged 3 commits intomainfrom
fix/default-embedding-model
Feb 23, 2026
Merged

feat: add Mermaid output to diff-impact#58
carlos-alm merged 3 commits intomainfrom
fix/default-embedding-model

Conversation

@carlos-alm
Copy link
Contributor

Summary

  • Add --format mermaid flag to diff-impact for generating ready-to-use Mermaid flowcharts showing changed functions, transitive callers, and blast radius
  • Enhance diffImpactData BFS to return depth-structured levels, edges, and newFiles (backward-compatible)
  • Add format property to MCP diff_impact tool schema
  • Add unit tests for new functionality
  • Update docs/llm-integration.md with PR impact graph roadmap

Usage

codegraph diff-impact main --format mermaid -T

Test plan

  • All 471 existing tests pass
  • New unit tests for levels/edges in diffImpactData, new file detection, and diffImpactMermaid output
  • Manual smoke test: --format text, --format json, --format mermaid, --staged
  • Lint passes cleanly

The existing check only matched direct pushes with 'chore: release v'
commit messages. Merged PRs have 'Merge pull request ... from release/vX'
as the commit message, bypassing the guard and triggering an unwanted
dev publish.
Add --format mermaid flag to diff-impact for generating ready-to-use
Mermaid flowcharts showing changed functions, transitive callers, and
blast radius in a single command.

- Enhance diffImpactData BFS to return depth-structured levels, edges,
  and newFiles detection (backward-compatible additions)
- Add diffImpactMermaid function that builds flowchart TB diagrams with
  color-coded subgraphs (green=new, orange=modified, purple=blast radius)
- Add --format option to CLI diff-impact command (text/mermaid/json)
- Add format property to MCP diff_impact tool schema
- Export diffImpactMermaid from index.js
- Add unit tests for levels/edges, new file detection, and Mermaid output
- Update llm-integration.md with PR impact graph roadmap

Impact: 6 functions changed, 5 affected
@carlos-alm
Copy link
Contributor Author

Impact Graph

flowchart TB
    subgraph sg0["src/cli.js **(modified)**"]
        n0["command:diff-impact"]
        n1["command:export"]
        n2["command:cycles"]
        n3["command:models"]
        n4["command:structure"]
    end
    style sg0 fill:#fff3e0,stroke:#ff9800
    subgraph sg1["src/cycles.js **(modified)**"]
        n5["findCycles"]
    end
    style sg1 fill:#fff3e0,stroke:#ff9800
    subgraph sg2["src/export.js **(modified)**"]
        n11["exportDOT"]
        n12["exportMermaid"]
        n13["exportJSON"]
    end
    style sg2 fill:#fff3e0,stroke:#ff9800
    subgraph sg3["src/mcp.js **(modified)**"]
        n6["startMCPServer"]
    end
    style sg3 fill:#fff3e0,stroke:#ff9800
    subgraph sg4["src/queries.js **(modified)**"]
        n14["isTestFile"]
        n21["diffImpactData"]
        n32["diffImpactMermaid"]
        n44["nodeId"]
        n7["statsData"]
        n33["diffImpact"]
    end
    style sg4 fill:#fff3e0,stroke:#ff9800
    subgraph sg5["src/structure.js **(modified)**"]
        n45["structureData"]
    end
    style sg5 fill:#fff3e0,stroke:#ff9800
    n9["stats"]
    n15["findMatchingNodes"]
    n16["queryNameData"]
    n17["impactAnalysisData"]
    n18["fileDepsData"]
    n19["fnDepsData"]
    n20["fnImpactData"]
    n23["getFileLines"]
    n24["explainFunctionImpl"]
    n25["whereSymbolImpl"]
    n26["contextData"]
    n27["queryName"]
    n28["impactAnalysis"]
    n29["fileDeps"]
    n30["fnDeps"]
    n31["fnImpact"]
    n36["whereData"]
    subgraph sg6["Callers **(blast radius)**"]
        n8["command:mcp"]
        n10["command:stats"]
        n22["listFunctionsData"]
        n34["explainFileImpl"]
        n35["getFileLines"]
        n37["context"]
        n38["command:query"]
        n39["command:impact"]
        n40["command:deps"]
        n41["command:fn"]
        n42["command:fn-impact"]
        n43["where"]
    end
    style sg6 fill:#f3e5f5,stroke:#9c27b0
    n5 --> n2
    n5 --> n6
    n5 --> n7
    n6 --> n8
    n7 --> n9
    n9 --> n10
    n11 --> n1
    n11 --> n6
    n12 --> n1
    n12 --> n6
    n13 --> n1
    n13 --> n6
    n14 --> n15
    n14 --> n16
    n14 --> n17
    n14 --> n18
    n14 --> n19
    n14 --> n20
    n14 --> n21
    n14 --> n22
    n14 --> n7
    n14 --> n23
    n14 --> n24
    n14 --> n25
    n15 --> n26
    n16 --> n6
    n16 --> n27
    n17 --> n28
    n18 --> n29
    n19 --> n30
    n20 --> n31
    n21 --> n32
    n21 --> n33
    n23 --> n34
    n24 --> n35
    n25 --> n36
    n26 --> n37
    n27 --> n38
    n28 --> n39
    n29 --> n40
    n30 --> n41
    n31 --> n42
    n33 --> n0
    n36 --> n43
    n21 --> n6
    n32 --> n6
    n32 --> n33
    n45 --> n4
    n45 --> n6
Loading

@claude
Copy link

claude bot commented Feb 23, 2026

Claude finished @carlos-alm's task —— View job


PR Review Analysis

Reviewing PR: feat: add Mermaid output to diff-impact

Review Checklist

  • Phase 1: Root Cause Analysis
  • Phase 2: Configuration Change Detection
  • Phase 3: Test Integrity Assessment
  • Phase 4: Code Quality Review
  • Final Assessment and Rating

Phase 1: Root Cause Analysis ✅

Problem Being Solved: The PR adds visual Mermaid flowchart output to the existing diff-impact command. This addresses a legitimate need for better visualization of code change blast radius, which helps developers understand the impact of their modifications.

Why This Approach: The implementation builds upon existing diffImpactData infrastructure, adding a new diffImpactMermaid function that processes the BFS traversal results into Mermaid-compatible flowchart syntax. The approach is sound and extends rather than modifies core functionality.

Risk Assessment: LOW - This is additive functionality that doesn't modify existing behavior.

Phase 2: Configuration Change Detection ✅

Findings: ✅ NO HIGH-RISK CONFIGURATION CHANGES DETECTED

  • No linting rules disabled or relaxed
  • No test timeouts increased
  • No coverage thresholds lowered
  • No build configuration changes
  • No TypeScript strict mode modifications

The only workflow change is a minor publish.yml fix (npm token → NPM_TOKEN variable) which appears unrelated to this PR's functionality.

Phase 3: Test Integrity Assessment ✅

Test Quality: ✅ TESTS ARE COMPREHENSIVE AND ROBUST

New test coverage in tests/unit/queries-unit.test.js:

  • Tests Mermaid output structure and syntax correctness
  • Validates subgraph generation for modified vs new files
  • Tests blast radius detection and styling
  • Handles edge cases (no changes, git errors)
  • Uses proper mocking of execFileSync without weakening assertions
  • 158 new lines of test coverage for the new functionality

Test Integrity: No existing tests were modified or weakened. All assertions remain strict.

Phase 4: Code Quality Review ✅

Implementation Quality: EXCELLENT

src/queries.js (lines 744-856):

  • diffImpactMermaid function is well-structured and readable
  • Proper error handling with fallback diagrams
  • Clean separation of concerns: data processing vs. Mermaid formatting
  • Stable node ID generation prevents rendering inconsistencies
  • Color coding system is logical (green=new, orange=modified, purple=blast radius)

Enhanced diffImpactData (lines 680-742):

  • Backward compatible - existing return structure preserved
  • Well-designed BFS enhancement - adds levels and edges tracking without disrupting core logic
  • Proper new file detection - correctly identifies new files from git diff /dev/null pattern
  • Clean edge relationship tracking - maintains referential integrity with key mappings

CLI Integration (src/cli.js line 219):

  • Proper option handling - --format mermaid fits existing pattern
  • Validation - format options are constrained to valid values

MCP Integration (src/mcp.js lines 474-482):

  • Consistent API - format parameter properly exposed
  • Clean conditional logic - format-specific path selection

Security: ✅ NO SECURITY CONCERNS

  • No command injection risks (git commands use execFileSync with array args)
  • No SQL injection (prepared statements used consistently)
  • Input validation appropriate for CLI tool context

Performance: ✅ EFFICIENT

  • Leverages existing BFS traversal without duplication
  • Mermaid generation is O(n) over graph nodes
  • No unnecessary database round trips

Minor Observations:

  1. Code Style: Excellent adherence to project conventions
  2. Documentation: Well-commented implementation
  3. Export Strategy: Properly exports new function in src/index.js
  4. Integration: Seamless integration with existing MCP and CLI interfaces

Root Cause Analysis

Problem Being Solved: Adding visual impact analysis for code changes via Mermaid flowcharts - a legitimate developer productivity enhancement.

Why This Approach: Extends existing diff-impact infrastructure cleanly without disrupting current functionality. The backward-compatible enhancement to diffImpactData is well-architected.

Risk Assessment: LOW RISK - Additive feature with comprehensive test coverage and no breaking changes.

Critical Concerns

None identified. This is a high-quality implementation with proper testing.

Final Recommendation

  • Rating: ⭐⭐⭐⭐☆ (4/5)
  • Action: APPROVE
  • Reasoning: Well-implemented feature with excellent test coverage, clean architecture, and no breaking changes. The implementation demonstrates strong engineering practices and fits well into the existing codebase. The only reason this isn't 5 stars is that it's primarily an incremental feature addition rather than exceptional architectural innovation.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 23, 2026

Greptile Summary

Added Mermaid flowchart output format to diff-impact command, enabling visual representation of changed functions, their transitive callers, and blast radius with color-coded subgraphs for new/modified files and impacted callers.

Key changes:

  • Enhanced diffImpactData BFS traversal to track depth-structured levels and edges for graph visualization (backward-compatible, existing return fields preserved)
  • Implemented new file detection by parsing --- /dev/null markers in git diff output
  • Added diffImpactMermaid function that generates ready-to-render Mermaid flowcharts with styled subgraphs
  • Added --format mermaid|json|text flag to CLI and format parameter to MCP diff_impact tool
  • Comprehensive test coverage for new functionality (158 lines of unit tests)
  • Documented PR impact graph roadmap in docs/llm-integration.md planning doc
  • Fixed workflow condition to skip dev publish for merged release PRs

All changes are well-tested and backward-compatible.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Implementation is clean, well-structured, and thoroughly tested with 158 lines of unit tests covering all new functionality. The changes are backward-compatible (diffImpactData preserves existing return structure), follow existing code patterns, and include comprehensive edge case handling (empty diffs, new files, error cases). All 471 existing tests pass per PR description.
  • No files require special attention

Important Files Changed

Filename Overview
src/cli.js Added --format flag to diff-impact command for output format selection
src/mcp.js Added format parameter to diff_impact MCP tool with mermaid/json options
src/queries.js Enhanced diffImpactData with levels/edges/newFiles, added diffImpactMermaid for flowchart generation
tests/unit/queries-unit.test.js Added comprehensive tests for levels/edges, new file detection, and Mermaid output generation

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CLI: codegraph diff-impact --format mermaid] --> B[queries.js: diffImpact]
    B --> C{Format Check}
    C -->|format=mermaid| D[diffImpactMermaid]
    C -->|format=json| E[diffImpactData + JSON output]
    C -->|format=text| F[diffImpactData + text output]
    
    D --> G[diffImpactData]
    E --> G
    F --> G
    
    G --> H[Parse git diff output]
    H --> I[Detect new files via /dev/null]
    H --> J[Track changed line ranges]
    
    J --> K[Find affected functions]
    K --> L[BFS: Build levels & edges]
    
    L --> M{Return to caller}
    M -->|diffImpactMermaid| N[Generate Mermaid flowchart]
    M -->|diffImpactData| O[Return structured data]
    
    N --> P[Group by file subgraphs]
    P --> Q[Detect blast radius nodes]
    Q --> R[Apply color styling]
    R --> S[Return Mermaid string]
    
    T[MCP: diff_impact tool] --> U{format param}
    U -->|format=mermaid| D
    U -->|format=json| E
    
    style D fill:#e8f5e9,stroke:#4caf50
    style N fill:#e8f5e9,stroke:#4caf50
    style G fill:#fff3e0,stroke:#ff9800
    style L fill:#fff3e0,stroke:#ff9800
Loading

Last reviewed commit: d2d767f

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@carlos-alm carlos-alm merged commit 4555db3 into main Feb 23, 2026
16 of 17 checks passed
@carlos-alm carlos-alm deleted the fix/default-embedding-model branch February 23, 2026 23:26
carlos-alm pushed a commit that referenced this pull request Feb 23, 2026
Restructure README to follow: problem → value → quick start → reference.
Open with the real pain (AI agents burning tokens re-orienting in large
codebases), then what codegraph does about it, then how easy it is to
start. Move competitive comparison to a condensed table at the bottom.
Remove defensive Narsil head-to-head section. Add --format mermaid
diff-impact example from PR #58.
carlos-alm pushed a commit that referenced this pull request Feb 23, 2026
Restructure README to follow: problem → value → quick start → reference.
Open with the real pain (AI agents burning tokens re-orienting in large
codebases), then what codegraph does about it, then how easy it is to
start. Move competitive comparison to a condensed table at the bottom.
Remove defensive Narsil head-to-head section. Add --format mermaid
diff-impact example from PR #58.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant