Skip to content

Phase1: tree sitter dependency extraction for diffgraph#13

Open
avikalpg wants to merge 7 commits into
merged-foundation-prsfrom
phase1-tree-sitter-dependency-extraction
Open

Phase1: tree sitter dependency extraction for diffgraph#13
avikalpg wants to merge 7 commits into
merged-foundation-prsfrom
phase1-tree-sitter-dependency-extraction

Conversation

@avikalpg

@avikalpg avikalpg commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

Phase 1: Tree-sitter Dependency Extraction + Schema V2 Output

This PR implements the tree-sitter AST-based dependency extraction processor and wires it to produce schema v2 output — the foundational layer for DiffGraph v2.

What's included

Commit group Content
PRs #11 + #12 (merged as base) Graph export, structured JSON, processing modes abstraction
Tree-sitter processor Python AST extraction (classes, functions, imports)
Schema v2 adapter (formerly PR #18) Pure functions: symbol diff + schema v2 assembly
Phase 1 gap fixes Parser fix, schema validation, field alignment

Phase 1 acceptance criteria (all met)

  • TreeSitterProcessor.analyze_changes() returns schema v2 dict (not GraphManager)
  • privacy_tier == "local"
  • Output validates against diffgraph/schema/diffgraph-v2.schema.json
  • relationships[] includes import relationships for Python files
  • metadata.analysis_duration_ms is present
  • 45 tests pass (21 schema v2 adapter + existing tree-sitter tests)
  • Zero network calls in any test

Key fixes (from latest commits)

  1. _get_parser: was using incompatible native API; now uses ts.Parser(tslp.get_language())
  2. build_symbol_entry: added required schema v2 fields (name, file_id, kind, parent_id)
  3. build_import_relationship: renamed from/to → source_id/target_id; added id field
  4. build_schema_v2_output: fixed diff_ref schema violations, moved warnings into metadata
  5. Tests: updated for schema v2 dict API (not old DiffAnalysis object)

What this enables

Once merged:

  • wild diff can emit schema v2 JSON (structural tier) from local static analysis — no API call needed
  • Phase 2 (processor architecture + consent) and Phase 3 (JSON export) can be wired against this output
  • Terminal formatter (Phase 4) has a concrete input format to render

Merge sequence context

This is Phase 1 in the v2 implementation roadmap. After this merges:
→ Phase 2 fixes go on feature/multiple-processing-modes (PR #12)
→ Phase 3 fixes go on feature/output-graph-data (PR #11)
→ Phase 4 is a new branch (terminal formatter)

See docs/DiffGraph-CLI/design/V2-IMPLEMENTATION-ROADMAP.md for full plan.

- Add TreeSitterProcessor with multi-language support framework
- Implement Python component extraction (classes, functions, methods)
- Use tree-sitter-language-pack for AST parsing
- Support Python, TypeScript, JavaScript, Go, Rust, Java, Swift (Python fully working)
- Extract component relationships from static analysis
- Register as 'tree-sitter-dependency-graph' mode
- Add basic test demonstrating Python extraction

Component extraction includes:
- Classes/containers with nested methods
- Standalone functions
- Import statements
- Function call analysis for dependency mapping

Successfully tested with Python code showing proper extraction of:
- 1 class (MyClass)
- 2 methods (__init__, increment)
- 2 functions (standalone_function, another_function)

Next steps:
- Complete TypeScript/JavaScript extraction (partial implementation)
- Complete Go, Rust, Java, Swift extraction (partial implementation)
- Add comprehensive testing across all supported languages
- Enhance dependency detection for cross-file references
- Add tree-sitter-dependency-graph to available modes in README
- Document Python support as fully working
- Note other languages as in progress
- Update CHANGELOG with phase 1 implementation details
- Add usage examples for tree-sitter mode
- Document completed work: Python extraction fully functional
- Detail in-progress work for other languages
- Explain tree-sitter API migration (0.25+)
- Provide technical insights and lessons learned
- Outline next steps for phases 2-4
- Include usage examples and performance notes
Move documentation files to docs/:
- PHASE1_SUMMARY.md -> docs/
- GRAPH_EXPORT_FEATURE.md -> docs/
- TESTING_GUIDE.md -> docs/

Move test files to tests/:
- test_tree_sitter_basic.py -> tests/
- test_graph_export.py -> tests/
- test_structured_export.py -> tests/
- test_cli_manual.sh -> tests/

Move example to tests/examples/:
- example_usage.py -> tests/examples/

This improves project organization and follows standard conventions.
@avikalpg avikalpg self-assigned this Oct 29, 2025
@coderabbitai

coderabbitai Bot commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • feature/*
  • akg/*

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 31486b6c-be2b-4137-84ef-4cc0234025c7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch phase1-tree-sitter-dependency-extraction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Nia (Avikalp's assistant) added 3 commits July 6, 2026 22:03
Addresses the two blocking gaps from PR-13-REVIEW.md:

Gap 1 — Output format: new schema_v2_adapter.py module produces
symbols[] + relationships[] with analysis_source='structural' and
evidence pointers, conforming to diffgraph-v2.schema.json.

Gap 2 — Symbol diff layer: compute_symbol_diff() compares pre-change
and post-change AST snapshots to assign change_kind (added / modified /
deleted / unchanged) to every symbol. Uses content-slice comparison so
symbols that shift in line number without changing body are correctly
marked 'unchanged'.

Also adds:
- _get_pre_change_content() / _get_post_change_content() to
  TreeSitterProcessor (Gap 7 — explicit pre/post split)
- analyze_changes_v2() entry point on TreeSitterProcessor, which calls
  the adapter and returns a schema v2 dict. No GraphManager, no Mermaid,
  no network calls. metadata.privacy_tier='local' always.
- Guard openai_agents_dependency import with try/except so the module
  loads without the openai-agents SDK installed.
- 21 deterministic unit tests (test_schema_v2_adapter.py), including
  a zero-network-calls assertion (Gap 6).
…inst diffgraph-v2.schema.json

Five concrete gaps fixed:

1. _get_parser: was calling tslp.get_parser() (incompatible native API); now
   uses ts.Parser(tslp.get_language()) so node.type / node.start_point /
   node.children all work correctly. This was silently swallowed by except/pass,
   causing zero symbols and zero imports on every run.

2. build_symbol_entry: added required schema v2 fields (name, file_id, kind,
   parent_id); renamed file→file_id; flattened evidence location (was nested
   under location{}, schema expects flat file/line_start/line_end on evidence).

3. build_import_relationship: renamed from/to → source_id/target_id; added id
   field with format rel::<src>-><tgt> matching schema pattern requirement.

4. build_schema_v2_output: diff_ref had disallowed from/to fields (schema has
   additionalProperties:false); warnings was at top-level (schema has it in
   metadata.warnings); files entries were missing id and analysis_source.

5. tests: updated test_schema_v2_adapter assertions for new field names;
   updated test_tree_sitter_basic to use schema v2 dict API (not old
   DiffAnalysis object).

Result: 45 tests pass (up from 40); all Phase 1 acceptance criteria met:
- analyze_changes() returns schema v2 dict
- privacy_tier == local
- output validates against diffgraph-v2.schema.json
- relationships[] includes import relationships for Python
- metadata.analysis_duration_ms present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant