Skip to content

Add Rust implementation of JS variable renamer (humanify-rs)#734

Draft
jehna wants to merge 4 commits intomainfrom
claude/rust-ast-rewrite-SjZI6
Draft

Add Rust implementation of JS variable renamer (humanify-rs)#734
jehna wants to merge 4 commits intomainfrom
claude/rust-ast-rewrite-SjZI6

Conversation

@jehna
Copy link
Copy Markdown
Owner

@jehna jehna commented Feb 1, 2026

This is a Rust rewrite of the core JS AST traversal and variable renaming functionality. Key features:

  • Parse JavaScript to AST using oxc parser
  • Visit all binding identifiers (variables, functions, classes, params)
  • Process identifiers from largest scope to smallest for correct renaming
  • Support callback-based renaming via the Renamer trait
  • Handle shadowed variables, reserved keywords, and name collisions
  • Apply renames via text replacement

The implementation passes 24 tests ported from the TypeScript version, covering scope ordering, shadowing, class methods, object properties, and various edge cases.

https://claude.ai/code/session_019FrkBNBMtr3yPtHoYzKHDa

This is a Rust rewrite of the core JS AST traversal and variable renaming
functionality. Key features:

- Parse JavaScript to AST using oxc parser
- Visit all binding identifiers (variables, functions, classes, params)
- Process identifiers from largest scope to smallest for correct renaming
- Support callback-based renaming via the Renamer trait
- Handle shadowed variables, reserved keywords, and name collisions
- Apply renames via text replacement

The implementation passes 24 tests ported from the TypeScript version,
covering scope ordering, shadowing, class methods, object properties,
and various edge cases.

https://claude.ai/code/session_019FrkBNBMtr3yPtHoYzKHDa
Implements local LLM inference for the Rust humanify:

- Grammar module (grammar.rs):
  - GBNF grammar builder for constraining LLM output
  - Extraction of variable portions from responses
  - Builder pattern API similar to TypeScript template literals

- Model module (model.rs):
  - Pre-configured model definitions (2B Phi, 8B Llama)
  - Model path management (~/.humanifyjs/models/)
  - Chat template support (Phi3, Llama3.1)
  - ModelConfig builder for configuration

- Prompt module (prompt.rs):
  - Core inference using llama-cpp-2 bindings
  - Chat template formatting
  - Token-by-token generation with early stopping

All 40 tests pass including 16 new LLM module tests.

https://claude.ai/code/session_019FrkBNBMtr3yPtHoYzKHDa
Implements the Rust equivalent of the TypeScript local-llm-rename plugin:
- unminify_variable_name(): Two-stage LLM prompting (description -> name)
- define_filename(): Infer filename from code snippet using LLM
- LocalRenamer: Implements Renamer trait using local LLM inference
- local_rename(): Main entry point for processing JavaScript code

https://claude.ai/code/session_019FrkBNBMtr3yPtHoYzKHDa
The CLI provides commands to:
- `humanify local <file>` - Process JS file with local LLM inference
- `humanify download <model>` - Download 2b or 8b model
- `humanify models` - List available models and download status

Dependencies added: clap for CLI parsing, indicatif for progress bars,
ureq for HTTP downloads.

https://claude.ai/code/session_019FrkBNBMtr3yPtHoYzKHDa
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.

2 participants