extract_function
Extract a selected line range from a function into a new named helper. Uses AST analysis to compute parameters and return value, with dry-run preview before applying.
Instructions
Extract a line range out of an enclosing function into a new named helper (AST-aware, TypeScript/JavaScript). Computes the parameter list via free-variable analysis (identifiers read in the slice but declared outside it, including closure captures) and a return value (a binding declared in the slice and used after it). The helper is inserted after the enclosing function and the slice is replaced by a call. Dry-run by default — preview the edits + extracted_params + return_value, then re-call with dry_run=false to apply. Returns JSON: { success, edits, extracted_params, return_value, confidence, files_modified }.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dry_run | No | Preview changes without applying (default: true). Set to false to apply. | |
| end_line | Yes | Last line to extract (1-indexed, inclusive) | |
| file_path | Yes | File path (relative to project root) | |
| start_line | Yes | First line to extract (1-indexed, inclusive) | |
| function_name | Yes | Name for the extracted function |