{"id":50748663,"url":"https://github.com/nymphium/graft","last_synced_at":"2026-06-10T23:02:57.257Z","repository":{"id":337226972,"uuid":"1152743585","full_name":"Nymphium/graft","owner":"Nymphium","description":"graft grafts tree-sitter ASTs","archived":false,"fork":false,"pushed_at":"2026-02-08T17:18:58.000Z","size":96,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-08T19:08:12.606Z","etag":null,"topics":["agent-skills","ai-generated","rust"],"latest_commit_sha":null,"homepage":"https://nymphium.github.io/graft","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nymphium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/SUPPORTED_LANGUAGES.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-02-08T11:12:09.000Z","updated_at":"2026-02-08T17:19:02.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Nymphium/graft","commit_stats":null,"previous_names":["nymphium/graft"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Nymphium/graft","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nymphium%2Fgraft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nymphium%2Fgraft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nymphium%2Fgraft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nymphium%2Fgraft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nymphium","download_url":"https://codeload.github.com/Nymphium/graft/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nymphium%2Fgraft/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34174148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent-skills","ai-generated","rust"],"created_at":"2026-06-10T23:02:56.618Z","updated_at":"2026-06-10T23:02:57.252Z","avatar_url":"https://github.com/Nymphium.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graft - Structural Code Transformer\n\n`graft` is a CLI tool for safe, structural code transformation powered by [Tree-sitter](https://tree-sitter.github.io/). Unlike traditional regex-based find-and-replace tools, `graft` operates on the Abstract Syntax Tree (AST), ensuring that code modifications are syntactically valid and structure-aware.\n\n## 🚀 Features\n\n*   **AST-Based Transformation**: Edit code based on its structure, not just text patterns.\n*   **Safe Rewrites**: Uses incremental parsing to validate syntax after every change.\n*   **Bottom-Up Processing**: Preserves offset integrity for multiple replacements in a single file.\n*   **Template Expansion**: Supports flexible template strings with captured variables (e.g., `${name}`).\n*   **Multi-Language Support**: Supports a wide range of languages including Rust, JavaScript, Python, Go, and more.\n*   **Batch Queries**: Apply multiple transformations in a single pass (like `sed -e ... -e ...`).\n*   **Rule Files (TOML)**: Define reusable transformation rules in a persistent file with priority support.\n*   **Batch Processing**: Apply transformations across multiple files using glob patterns (e.g., `src/**/*.rs`).\n*   **Parallel Execution**: Processes multiple files concurrently for speed.\n*   **Structured Output**: Optional JSON output for integration with other tools and agents.\n*   **Nix-First**: Reproducible development environment with Nix and direnv.\n\n## 🛠 Prerequisites\n\n*   **Rust**: v1.93.0+ (Edition 2024)\n*   **Nix** (Optional but recommended): For reproducible builds using `flake.nix`.\n\n## 📦 Installation\n\n### Using Cargo\n\n```bash\ncargo install --path .\n```\n\n### Using Nix\n\n```bash\nnix run github:Nymphium/graft -- ...\n```\n\n## 📖 Usage\n\nBasic command structure:\n\n```bash\ngraft [files...] --query \u003cquery\u003e --template \u003ctemplate\u003e [--in-place]\n```\n\n### Arguments\n\n*   `[files...]`: Paths to source files or glob patterns (e.g., `src/**/*.rs`). Optional if reading from stdin (requires `--language`).\n*   `--query, -q`: Tree-sitter S-expression query to match nodes. Can be specified multiple times.\n*   `--template, -t`: Replacement string. Can be specified multiple times.\n*   `--rule-file, -f`: Path to a TOML rule file.\n*   `--in-place, -i`: Modify the file directly instead of printing to stdout.\n*   `--language, -l`: Language of the source code.\n*   `--json`: Output modifications in JSON format.\n*   `--list-languages`: List all supported languages and their file extensions.\n\n## 💡 Examples\n\n### 1. Rule File (TOML)\n\nCreate a `rules.toml`:\n\n```toml\n[[rules]]\nname = \"add-to-pow\"\nlanguage = \"rust\"\npriority = 10\nquery = \"(binary_expression left: (_) @l operator: \\\"+\\\" right: (_) @r) @target\"\ntemplate = \"pow(${l}, ${r})\"\n```\n\nApply it:\n\n```bash\ngraft src/main.rs --rule-file rules.toml --in-place\n```\n\n### 2. Batch Queries\n\nChain multiple transformations in a single pass.\n\n```bash\ngraft src/main.rs \\\n  --query '(binary_expression left: (_) @l operator: \"+\" right: (_) @r) @target' \\\n  --template 'add(${l}, ${r})' \\\n  --query '(call_expression function: (identifier) @n (#eq? @n \"foo\") arguments: (arguments) @a) @target' \\\n  --template 'bar${a}'\n```\n\n## 🤖 Agent Skills\n\nGraft comes with a [Gemini CLI](https://github.com/google/gemini-cli) agent skill that enables your AI assistant to perform structural refactoring safely.\n\n### Installation\n\nTo install the skill for your agent:\n\n```bash\ngemini skills install .skills/graft/graft.skill\n```\n\nThen reload your skills in the agent session:\n\n```\n/skills reload\n```\n\n## 🌐 Supported Languages\n\nGraft supports a variety of languages. You can list them using:\n\n```bash\ngraft --list-languages\n```\n\nFor a full list of supported languages and extensions, see [SUPPORTED_LANGUAGES.md](/docs/SUPPORTED_LANGUAGES.md).\n\n## 🧪 Development\n\n### Running Tests\n\nRun the test suite to verify core functionality:\n\n```bash\ncargo test\n```\n\n### Project Structure\n\n*   `src/lib.rs`: Core transformation logic (`Transformer` struct).\n*   `src/languages.rs`: Language definitions and mappings.\n*   `src/rules.rs`: Rule file loading logic.\n*   `src/main.rs`: CLI entry point using `clap`.\n*   `tests/integration_tests.rs`: Integration tests for various transformation scenarios.\n\n## 📄 License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnymphium%2Fgraft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnymphium%2Fgraft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnymphium%2Fgraft/lists"}