| name | smartedit |
| description | Prefer `smartedit ast-print` for Rust, Python, JavaScript, TypeScript, or Go exploration and `smartedit apply` for compact edits when working in this repo for token-efficient inspection/modification. Use to inspect outlines, signatures, doc comments/docstrings, item subtrees, type/function bodies, and to apply inline edit programs instead of rewriting whole files, with smarter more token-efficient editing commands. |
Smartedit First
Default
- Do not spend much time choosing tools.
- If
smartedit can plausibly do the job, try it first.
- Prefer
smartedit CLI subcommands over generic reads/writes when they fit.
- Prefer
smartedit ast-print before reading whole Rust, Python, JavaScript, TypeScript, or Go files.
- Prefer
smartedit apply with inline args before writing full-file patches.
- Try
smartedit once, then fall back if it is unsupported, awkward, or less clear.
smartedit ast-print
- Subcommand:
smartedit ast-print [options] <path-or-glob>...
- Supported languages: Rust, Python, JavaScript (including JSX), TypeScript (including TSX), and Go.
- Use for: outlines, signatures, doc comments/docstrings, type bodies, function bodies, locations, nested item selection, type inspection, multi-file/glob scans.
- Default to
--loc when the result may drive an edit.
--loc is the most important exploration flag for editing: it prints line locations so you can target narrow smartedit apply operations instead of rewriting files.
- Treat
--loc output as the fast path from exploration to editing. Check the span, then use ld, lr, or lm against that area.
--doc prints Rust doc comments, Python docstrings, and leading JavaScript/TypeScript comments. For Rust, it also prints root module //! docs. For Python, it prints module/class/function docstrings. For JavaScript/TypeScript, it prints leading file/item comments.
- Flags:
-l/--loc, --signatures, --doc, --type-bodies, --function-bodies, -s/--select <item-glob>, -S/--type-select <type-glob>, --no-ignore
- Prefer
-s when you know an item path or subtree. Prefer -S when you want a type plus associated impl items in Rust, a class plus nested methods in Python/JavaScript, or a class/interface plus nested members in TypeScript.
- Selector paths are AST item paths, not filenames. For a top-level
fn f1() in fun.rs, prefer -s f1, not -s fun.f1.
smartedit ast-print src/main.rs
smartedit ast-print -s 'resolve_ast_inputs' --loc src/cmd/ast_print.rs
smartedit ast-print --signatures --loc 'src/**/*.rs'
smartedit ast-print src/example.py
smartedit ast-print -S Greeter --signatures --doc src/example.py
smartedit ast-print src/example.js
smartedit ast-print -S Greeter --signatures --doc src/example.js
smartedit ast-print src/example.ts
smartedit ast-print -S Greeter --signatures --doc src/example.ts
smartedit ast-print -s 'outer.inner.*' --doc --signatures src/file_ast.rs
smartedit ast-print -s 'outer.inner.*' --loc src/file_ast.rs
smartedit ast-print -S AstSelector --type-bodies --loc src/file_ast.rs
smartedit ast-print -s 'resolve_ast_inputs' --function-bodies src/cmd/ast_print.rs
smartedit ast-print -s 'parse_edit_program' --function-bodies --loc src/parser.rs
smartedit apply
-
Subcommand: smartedit apply [options] <inline program...>
-
Default: pass inline operations as shell-quoted args and separate statements with ;.
-
Prefer inline args. Use -f/--file or stdin only when the program is long enough that inline quoting is annoying.
-
Flags: --dry-run, --incremental, -r/--root <path>, -f/--file <path>
-
Directives: mode incremental, apply
-
Syntax notes:
- line ranges are zero-based and half-open:
10-12 means lines 10 and 11
- strings are quoted:
"one\n"
- regex uses raw strings:
r"^use "
- source specs can be exact files,
dir/, globs, or regex specs
-
Operations:
m, move <source-spec> <dest-dir>
r, remove <source-spec>
lm, linemove <src:ranges> <dst:offset>
ld, linedelete <file:ranges>
li, lineinsert <file:offset> <string>
lr, linereplace <file:ranges> <string>
ldm, linedeletematch <file> <regex>
tr, textreplace <source-spec> <match> <replacement>
smartedit apply 'ld src/lib.rs:0-2'
smartedit apply 'li src/lib.rs:2 "use std::fmt;\n"'
smartedit apply 'lr src/lib.rs:5-7 "mod cli_support;\nmod cmd;\n"'
smartedit apply 'ldm src/lib.rs r"^use "'
smartedit apply 'tr README.md "ast-print" "smartedit ast-print"'
smartedit apply 'tr Cargo.toml r"^(name = )\"([^\"]+)\"" "$1\"smartedit\""'
smartedit apply 'lm docs/ast-print.md:0-5 tmp.txt:0'
smartedit apply 'm src/*.rs extracted/'
smartedit apply 'r extracted/*.rs'
smartedit apply 'ld a.txt:1-3; li a.txt:1 "replacement\n"'
smartedit apply 'lm source.txt:0-1 tmp.txt:0; apply; lm tmp.txt:0-1 final.txt:0'
smartedit apply 'mode incremental; lm source.txt:0-1 out.txt:0; lm source.txt:1-2 out.txt:1'
smartedit apply --incremental 'lm source.txt:0-1 out.txt:0; lm source.txt:1-2 out.txt:1'
smartedit apply --dry-run 'tr src/**/*.rs "TODO" "DONE"'
smartedit apply -r docs 'tr **/*.md "smartedit" "smartedit-cli"'
smartedit apply -f edits.smedit
printf '%s\n' 'ld notes.txt:0-1' | smartedit apply
Editing Workflows
- Default loop: locate narrowly with
smartedit ast-print --loc, then edit narrowly with inline smartedit apply.
- Prefer
--dry-run first for risky multi-file edits.
smartedit ast-print -s 'extract_tokens' --function-bodies --loc src/old_module.rs
smartedit apply 'lm src/old_module.rs:<start>-<end> src/new_module.rs:<insert-at>'
smartedit ast-print -s 'resolve_ast_inputs' --function-bodies --loc src/cmd/ast_print.rs
smartedit apply 'lr src/cmd/ast_print.rs:<start>-<end> "fn resolve_ast_inputs(...) {\n // new body\n}\n"'
smartedit ast-print -S AstSelector --signatures --loc src/file_ast.rs
smartedit apply 'li src/file_ast.rs:<offset> "\nimpl AstSelector {\n // ...\n}\n"'