mvtk read --from PATTERN --to PATTERN
What it does: Extract a block of lines from a file, starting at the first line matching --from and ending at the first line matching --to
(inclusive on both ends). Regex patterns, same engine as mvtk grep.
Basic usage
# Extract a specific function when --fn can't detect it (Swift, Python, Java, etc.)
mvtk read --from 'func stopSharing' --to '^\}' file.swift
# Extract a markdown section
mvtk read --from '^## Phase 3' --to '^## Phase 4' roadmap.md
# Extract a config block
mvtk read --from '\[database\]' --to '^\[' config.toml
# Extract a test case
mvtk read --from 'func TestGetSync' --to '^\}' handlers_test.go
Behavior rules
1. --from without --to: Start at the matching line, read to end of file. Useful for "everything after this header."
2. --to without --from: Start at line 1, read until the matching line. Useful for "everything up to this point."
3. --from with --to: Start at first --from match, end at first --to match that occurs after the --from match. Both lines are included in the
output.
4. --to boundary question: When --to matches the same line as --from, keep scanning for the next --to match. The --to search starts from the
line after --from. This prevents --from '^}' --to '^}' from returning a single line.
5. --to exclusive option: Add --to-exclusive (or --to-before) flag that excludes the --to line itself. For the markdown case, --from '^##
Phase 3' --to '^## Phase 4' --to-exclusive gives you Phase 3 content without the Phase 4 header bleeding in.
6. Multiple matches: By default, return only the first match (first --from/--to block). Add --all flag to return every matching block in the
file. Each block gets its own output with start_line/end_line.
7. No match: If --from pattern is never found, return 0 lines and exit code 1 (same as --fn when function not found). Emit a helpful message:
"No line matching '--from' pattern 'X' found in file".
8. If --from matches but --to never matches: Return from --from to EOF. Emit a note in the summary: "--to pattern 'X' not found; read to end
of file".
Output format
Same as existing mvtk read — type: "line" records with file, line, content. But wrap in a block record like --fn does:
{"type":"block","file":"file.swift","from_pattern":"func stopSharing","to_pattern":"^\\}","start_line":245,"end_line":253,"lines":["private
func stopSharing() async {"," isStopping = true"," ..."]}
This mirrors the type: "fn" record from --fn — same shape, just type: "block" with the patterns instead of a function name.
Interaction with other flags
- --from/--to + --max-tokens: Respects the token cap, truncates the block if needed.
- --from/--to + --head N: After extracting the block, return only the first N lines of it.
- --from/--to + --fn: Error. These are mutually exclusive extraction modes.
- --from/--to + --outline: Error. Mutually exclusive.
- --from/--to + --format compact: Works — emits file:line:content per line, same as regular compact mode.
- --from/--to on multiple files: Apply to each file independently. Each file can produce 0 or 1 blocks (or multiple with --all).
Why this matters
--fn is great when the language parser works. But it only works fully for Go. For everything else — Swift methods, Python class methods, Java
anything, Ruby class methods, Rust impl methods — --fn returns 0 lines. --from/--to is the universal fallback that works on any file in any
language because it's just regex on lines. No parser needed.
It's also the right tool for non-code: markdown sections, config blocks, log ranges, TOML sections, YAML documents. --fn will never handle
those. --from/--to handles them all.