Skip to content

feat(dora): add ast-grep provider for AST-aware code search - #35

Merged
amondnet merged 9 commits into
mainfrom
34-add-ast-grep-provider-for-ast-aware-code-search-and-transformation
Dec 19, 2025
Merged

feat(dora): add ast-grep provider for AST-aware code search#35
amondnet merged 9 commits into
mainfrom
34-add-ast-grep-provider-for-ast-aware-code-search-and-transformation

Conversation

@amondnet

Copy link
Copy Markdown
Contributor

Summary

Add ast-grep tools and skill to dora MCP server for AST-aware code search and transformation capabilities.

  • Add ast_grep_search and ast_grep_replace MCP tools
  • Support 25 languages via CLI + 5 languages via NAPI for faster in-memory transforms
  • Auto-download ast-grep binary from GitHub releases
  • Support both inline patterns and YAML rule files
  • Add agent/skill for complex rule writing guidance

Architecture Decision

See ADR-0001 for detailed architecture decision.

Implementation Plan

Parallel Group 1 (independent tasks)

  • T001: Create types.ts with interfaces
  • T002: Create constants.ts with languages and config
  • T005: Create napi.ts for in-memory transforms
  • T006: Create utils.ts for result formatting
  • T010: Create agents/ast-grep.md skill

Sequential Tasks

  • T003: Create downloader.ts (depends on T002)
  • T004: Create cli.ts (depends on T002, T003)
  • T007: Create index.ts AstGrepProvider (depends on T001-T006)
  • T008: Export provider from providers/index.ts (depends on T007)
  • T009: Register provider in server.ts (depends on T008)
  • T011: Add unit tests (depends on T007)
  • T012: Add integration tests (depends on T009)

Test Plan

  • Unit tests for AstGrepProvider
  • Integration tests for ast_grep_search tool
  • Integration tests for ast_grep_replace tool
  • Manual testing with various patterns and languages

Closes #34

@amondnet amondnet linked an issue Dec 19, 2025 that may be closed by this pull request
12 tasks
@codecov

codecov Bot commented Dec 19, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.22177% with 450 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.37%. Comparing base (9d74066) to head (bbfd023).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/dora/src/providers/ast-grep/downloader.ts 29.60% 107 Missing ⚠️
packages/dora/src/providers/ast-grep/napi.ts 18.25% 103 Missing ⚠️
packages/dora/src/providers/ast-grep/cli.ts 44.44% 100 Missing ⚠️
packages/dora/src/providers/ast-grep/index.ts 70.87% 90 Missing ⚠️
packages/dora/src/providers/ast-grep/utils.ts 52.94% 48 Missing ⚠️
packages/dora/src/providers/ast-grep/constants.ts 98.24% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #35      +/-   ##
==========================================
+ Coverage   47.94%   49.37%   +1.42%     
==========================================
  Files          15       21       +6     
  Lines        3341     4324     +983     
==========================================
+ Hits         1602     2135     +533     
- Misses       1739     2189     +450     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…formation

- Add AstGrepProvider with 4 tools:
  - ast_grep_search: Search code patterns across files (25 languages)
  - ast_grep_replace: Replace patterns with AST-aware rewriting
  - ast_grep_analyze: In-memory analysis via NAPI (5 languages)
  - ast_grep_transform: In-memory transformation via NAPI

- Implement auto-download of ast-grep binary from GitHub releases
  - Platform detection (win/linux/osx, x64/arm64)
  - Version tracking and caching in ~/.cache/dora/ast-grep/
  - System PATH detection with binary verification

- Add agent skill for writing ast-grep patterns and YAML rules
  - Meta-variable syntax guide ($VAR, $$$, _)
  - YAML rule structure with relational/composite operators
  - Common pattern examples for JS/TS, Python, Go

- Create ADR documenting architecture decision

Closes #34
@amondnet
amondnet marked this pull request as ready for review December 19, 2025 04:19
…entation

- Fix silent failures in error handling:
  - Add error logging when JSON parsing fails (cli.ts)
  - Add error logging in binary verification (downloader.ts)
  - Add warning when reading version marker fails (downloader.ts)

- Improve error handling robustness:
  - Use .finally() instead of .then() for timeout cleanup (cli.ts)
  - Include error details in nested catch blocks (cli.ts)
  - Add retry counter to prevent infinite download loops (cli.ts)
  - Return exit code when process exits with no output (cli.ts)
  - Log full error on NAPI load failure (napi.ts)

- Security improvements:
  - Escape single quotes in PowerShell extractZip command
  - Use -LiteralPath for safer path handling

- Better error messages:
  - Add Zod-specific error formatting for validation errors (index.ts)

- Documentation updates:
  - Update ADR to document all 4 tools (search, replace, analyze, transform)
  - Update agent skill frontmatter with correct MCP tool names
  - Add NAPI tool documentation (ast_grep_analyze, ast_grep_transform)
@amondnet amondnet self-assigned this Dec 19, 2025
- Add process import from node:process in constants.ts and downloader.ts
- Convert capturing groups to non-capturing in utils.ts regex
- Add YAML document separators (---) in ast-grep.md examples
- Apply auto-fixes for import ordering and code style
Separate ast-grep knowledge into skill and agent:
- skills/ast-grep/SKILL.md: Pattern writing guide (reusable)
- skills/ast-grep/references/rule_reference.md: Detailed rule docs
- agents/ast-grep.md: Simplified to focus on MCP tool usage

Agent now references skill via Skill("code-please:ast-grep")
Align skill content with official ast-grep/claude-skill repository:
- Add 5-step workflow for writing ast-grep rules
- Document ast-grep scan with --inline-rules for testing
- Add pattern object form with selector, context, strictness
- Add stopBy and field options for relational rules
- Expand metavariables documentation
- Add best practices and troubleshooting sections
Move version and lastUpdated fields into metadata block per
the official Agent Skills specification at agentskills.io.
@amondnet
amondnet merged commit 74117d3 into main Dec 19, 2025
5 checks passed
@amondnet
amondnet deleted the 34-add-ast-grep-provider-for-ast-aware-code-search-and-transformation branch December 19, 2025 06:23
@passionfactory-bot passionfactory-bot Bot mentioned this pull request Dec 19, 2025
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.

Add ast-grep provider for AST-aware code search and transformation

1 participant