-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/improvements #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add ESLint and Prettier configuration - Add comprehensive test coverage (binary-manager, cli-flag-mapping tests) - Update CI/CD workflows for improved automation - Refactor core tools and utilities for better maintainability - Remove obsolete test-manual files and documentation - Update dependencies and configurations
Introduces AST_GREP_DOCUMENTS.md and PATTERN_LIBRARY.md for comprehensive ast-grep usage and rule writing documentation. Adds src/tools/explain.ts and corresponding tests for explain functionality. Updates CLI usage in QUICK_SETUP.md, expands README.md, and modifies core and tool modules to support new features. Includes new and updated tests for enhanced constraints and explain tool.
chore: release version 1.2.6 with improved workspace detection and validation - Enhanced workspace root detection to reject user directories (home, Downloads, Documents, Desktop) and require explicit paths for safer operations - Removed informational stderr logging (binary version, server ready messages) to prevent MCP client warnings - Updated path depth limit from 10 to 6 levels for better performance - Added validation to prevent scanning/replacing in user directories without explicit paths -
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis pull request introduces a new ExplainTool for AST pattern explanation, overhauls the binary manager with cross-platform path handling and caching, refactors tool parameter validation with stricter typing across SearchTool, ReplaceTool, ScanTool, and ReplaceTool, adds comprehensive test suites for binary management and CLI flag mapping, enhances CI/CD workflows with ast-grep binary caching, and updates development tooling with ESLint and Prettier configuration. Version bumped from 1.1.1 to 1.2.6. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MCP as MCP Server
participant ExplainTool
participant BinaryMgr as Binary Manager
participant AstGrep as ast-grep CLI
User->>MCP: Call ast_explain_pattern
MCP->>ExplainTool: execute(params)
ExplainTool->>ExplainTool: Validate pattern, code, language
ExplainTool->>ExplainTool: Normalize language alias
ExplainTool->>BinaryMgr: executeAstGrep(["explain", ...])
BinaryMgr->>AstGrep: Run explain command
AstGrep-->>BinaryMgr: JSON-stream output
BinaryMgr-->>ExplainTool: stdout/stderr
ExplainTool->>ExplainTool: Parse JSON output
ExplainTool->>ExplainTool: Extract metavariables, AST kinds
Note over ExplainTool: If showAst=true,<br/>run secondary explain --show-ast
ExplainTool->>ExplainTool: Generate suggestions if no match
ExplainTool-->>MCP: ExplainResult {matched, metavariables, astNodes, suggestions}
MCP-->>User: Return result
sequenceDiagram
participant Test
participant SearchTool
participant Validator as Parameter Validator
participant PathMgr as Path Manager
participant BinaryMgr as Binary Manager
Test->>SearchTool: execute({pattern, code, context, ...})
SearchTool->>Validator: validatePattern(pattern)
alt Pattern Invalid
Validator-->>SearchTool: ValidationError
SearchTool-->>Test: Error
end
SearchTool->>Validator: validateCode(code)
SearchTool->>Validator: validateContext(context)
SearchTool->>PathMgr: Normalize language alias
alt Inline Code Mode
SearchTool->>PathMgr: Validate language provided
else File Mode
SearchTool->>PathMgr: Enforce absolute paths
PathMgr->>PathMgr: Validate workspace confinement
PathMgr->>PathMgr: Check against blocked dirs
end
SearchTool->>BinaryMgr: executeAstGrep([...flags])
BinaryMgr-->>SearchTool: Matches
SearchTool->>SearchTool: Parse results, normalize paths
SearchTool-->>Test: SearchResult {matches, summary}
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Key areas requiring extra attention:
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Free 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
PR Compliance Guide 🔍(Compliance updated until commit a6871d0)Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label Previous compliance checksCompliance check up to commit b89df77
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||||
|
Looks like there are a few issues preventing this PR from being merged!
If you'd like me to help, just leave a comment, like Feel free to include any additional details that might help me get this PR into a better state. You can manage your notification settings |
- Consolidated test execution to 5 stable suites (validation, diff-parsing, explain, structural-rules, warnings) - Removed environment-dependent test jobs (binary-manager, cli-flag-mapping, integration) - Unified coverage reporting for stable tests only - Deleted unused PATTERN_LIBRARY.md documentation file
User description
This pull request introduces significant improvements to testing, documentation, and CI/CD workflows, along with updates for compatibility and code quality. The main changes include expanded test coverage and reporting, improved installation instructions and troubleshooting for
ast-grep, enhanced documentation of tool limitations and best practices, and updates to configuration and versioning files to support these enhancements.Testing and CI/CD improvements:
.github/workflows/ci.yaml. Integration tests are now forced in CI via theINTEGRATION_TESTSenvironment variable. [1] [2] [3] [4].github/workflows/publish.yamlto install theast-grepbinary explicitly and ensure integration tests run with the correct environment.Documentation enhancements:
README.mdto include detailed installation instructions forast-grep, troubleshooting guidance, a new section on test infrastructure, and clearer usage notes for configuration flags and environment variables. Added a link to the Pattern Library and clarified requirements. [1] [2] [3] [4] [5] [6]CHANGELOG.mdwith new features, improvements, and fixes for versions1.2.0through1.2.5, including simple text search detection, enhanced tool descriptions, and compatibility fixes forast-grep v0.39.7. [1] [2]PUBLIC_READY_CHECKLIST.mdfile, as the project is now publicly ready and professionally configured.Configuration and code quality:
.prettierrcandeslint.config.jsfor consistent code formatting and linting across the project. [1] [2]Versioning and compatibility:
package.jsonto1.2.6to reflect the new features and fixes.CHANGELOG.mdfor accurate tracking of changes between releases.Minor usability improvements:
.github/QUICK_SETUP.mdfor easier installation verification.These changes collectively enhance reliability, usability, and maintainability for both users and contributors.
PR Type
Enhancement, Tests, Documentation
Description
Enhanced ScanTool with dual execution modes: Added support for both
runmode (simple patterns) andscanmode (structural rules) with automatic mode detection, comprehensive constraint operators (not_regex,not_equals,kind), and improved parameter validationComprehensive test coverage expansion: Added 1600+ lines of CLI flag mapping tests covering all tools (SearchTool, ReplaceTool, ScanTool, ExplainTool), integration tests with absolute path validation, binary manager tests, and enhanced constraint validation
Code quality and formatting standardization: Implemented Prettier and ESLint configurations for consistent code style (double quotes, 2-space indentation, 100-character line width), applied formatting across all TypeScript and JavaScript files
CI/CD workflow improvements: Updated publish workflow to install
ast-grepbinary v0.39.7 and enable integration tests viaINTEGRATION_TESTSenvironment variable; enhanced CI workflow with coverage reporting and artifact uploadsDocumentation enhancements: Expanded README with detailed
ast-grepinstallation instructions, troubleshooting guidance, test infrastructure documentation, and clarified configuration flags; updated CHANGELOG for versions 1.2.0-1.2.5TypeScript and tooling updates: Updated
tsconfig.jsonfor Bun compatibility, improved type safety inrules.tswithRecord<string, unknown>instead ofany, addedExplainToolexport, and enhanced validation utilitiesTest fixtures and validation updates: Refactored integration tests with absolute path requirements, updated fixture files with proper formatting and unused variable suppression, improved constraint validation tests
Diagram Walkthrough
File Walkthrough
3 files
integration.test.ts
Extensive integration test refactoring with absolute path validationand new test coveragetests/integration.test.ts
(Prettier formatting)
pathmodule import for handling absolute file paths in testsExecutionError,BinaryError)!) to tool variables to satisfyTypeScript strict mode
path.join(process.cwd(), ...)forall file-based test operations
stdin vs file mode behavior, context parameters, dry-run behavior, and
JSON stream format verification
system directory blocking validation
and validate absolute path requirements
escaping, metavariable placement, and language requirements
sample.ts
TypeScript fixture cleanup with unused variable suppressiontests/fixtures/ts/sample.ts
intentionally unused (e.g.,
AdminManager→_AdminManager,userName→_userName)cli-flag-mapping.test.ts
Comprehensive CLI flag mapping test suite for all toolstests/cli-flag-mapping.test.ts
mapping for all tools (SearchTool, ReplaceTool, ScanTool, ExplainTool)
including
--pattern,--lang,--json=stream,--stdin,--rule,--rewrite,--update-allconstraints, escaping, and language normalization
not_regex,not_equals, andkindoperators with proper YAML nestingextension matching, and cleanup
(javascript→js, typescript→ts, python→py, etc.)
rejection of relative paths with clear error messages
2 files
index.ts
Tool exports update with new ExplainTool and formattingsrc/tools/index.ts
(Prettier formatting)
ExplainToolclassscan.ts
Enhanced ScanTool with dual modes, constraint operators, andvalidationsrc/tools/scan.ts
WhereConstraint,ScanParams,FindingLocation,Finding,ScanResult) for type safety andruntime validation
for all fields including
wherearray constraints andkindformatvalidation
runmode for simple patternsand
scanmode for structural rules, with automatic mode detectionnot_regex,not_equals,and
kindoperators, generating proper nested YAML structuresextractAllMetavariables()method to recursively extractmetavariables from complex nested rules
home/user directories without explicit paths
normalization
improved code organization
3 files
sample.js
JavaScript fixture arrow function formatting updatetests/fixtures/js/sample.js
parentheses:
x => x * 2→(x) => x * 2validation.test.ts
Code formatting standardization and constraint validation updatestests/validation.test.ts
formatting throughout the test file
@typescript-eslint/no-explicit-anyatthe top of the file
consistently
regexand
equalsare provided simultaneouslyrules.ts
Code formatting and type safety improvementssrc/types/rules.ts
for consistency with Prettier configuration
nthChildtype definition for improved readability withproper line breaks
Transforminterface to useRecord[]insteadof
any[]for better type safetyRuleConfigmetadata field to useRecordinstead of
Record4 files
eslint.config.js
Add ESLint configuration for TypeScript code qualityeslint.config.js
.tsand.tsxfilesexplicit
anytypesdirectories
publish.yaml
Install ast-grep binary and enable integration tests in CI.github/workflows/publish.yaml
ast-grepbinary version 0.39.7 from GitHubreleases
/usr/local/bin/withexecutable permissions
INTEGRATION_TESTSenvironment variable set to"1"for testexecution
during publish workflow
tsconfig.json
Update TypeScript configuration for Bun compatibilitytsconfig.json
moduleResolutionfrom"node"to"bundler"for better Buncompatibility
"types": ["bun-types"]to include Bun type definitionsoptions
.prettierrc
Add Prettier code formatting configuration.prettierrc
width, and trailing commas in ES5 format
1 files
QUICK_SETUP.md
Update npx command with non-interactive flag.github/QUICK_SETUP.md
-yflag for non-interactiveinstallation
30 files
Summary by CodeRabbit
New Features
Improvements
Documentation
Chores