Read Optimizer
Verified@autogame-17
npx machina-cli add skill @autogame-17/read-optimizer --openclawSKILL: Read Optimizer (read-optimizer)
Description
Optimizes file reading operations by providing smarter read strategies (head/tail/grep/diff) to reduce token usage and latency. Use this when you need to inspect large files efficiently without dumping the entire content.
Usage
Smart Read (Head + Tail)
Reads the first N lines and the last N lines of a file. Good for logs or large docs.
node skills/read-optimizer/index.js --file <path> --mode smart --lines 100
Grep Read (Focus)
Reads lines matching a pattern (regex supported).
node skills/read-optimizer/index.js --file <path> --mode grep --pattern "error|exception"
Diff Read (Changes)
Reads only the lines changed since the last git commit (if in a git repo).
node skills/read-optimizer/index.js --file <path> --mode diff
Options
--file <path>: Path to the file.--mode <smart|grep|diff>: Operation mode (default: smart).--lines <number>: Number of lines for head/tail (default: 50).--pattern <string>: Regex pattern for grep mode.--context <number>: Context lines for grep (default: 2).
Overview
Read Optimizer provides smarter read strategies (head/tail, grep, diff) to reduce token usage and latency when inspecting large files. It lets you peek the start and end, search by pattern, or surface only changes since the last commit, avoiding full dumps.
How This Skill Works
It offers three modes: smart (head + tail), grep (pattern matching), and diff (git changes). Depending on the mode, it reads the first N and last N lines, filters lines by a regex, or shows only lines changed since the last commit in a git repo. The default line window is 50, and you can extend context for grep results with --context.
When to Use It
- You need a quick digest of massive log files without dumping everything
- You want to surface errors or exceptions without scanning an entire document
- You need to inspect recent changes to a file using git diff
- You are debugging large codebases by focusing on matching patterns
- You want to audit large config/docs files without loading full content
Quick Start
- Step 1: Run smart mode to peek start and end: node skills/read-optimizer/index.js --file <path> --mode smart --lines 50
- Step 2: Narrow down with grep: node skills/read-optimizer/index.js --file <path> --mode grep --pattern "error|exception" --context 2
- Step 3: See recent changes with diff in a git repo: node skills/read-optimizer/index.js --file <path> --mode diff
Best Practices
- Use smart mode for large, unstructured files and adjust --lines for needed coverage
- In grep mode, specify a precise --pattern (regex like 'error|exception') for targeted results
- Enable diff mode only in git repositories to view recent changes efficiently
- Combine grep with --context to see surrounding lines for better diagnosis
- Verify the extracted output against expectations and adjust --lines or --context as needed
Example Use Cases
- Inspect the first and last 100 lines of a log: node skills/read-optimizer/index.js --file /var/log/app.log --mode smart --lines 100
- Find error lines in a log: node skills/read-optimizer/index.js --file app.log --mode grep --pattern 'error|exception' --context 2
- Review changes to config.yaml since last commit: node skills/read-optimizer/index.js --file config.yaml --mode diff
- Preview a large documentation file without full dump: node skills/read-optimizer/index.js --file doc.md --mode smart --lines 50
- Check failing test outputs in CI quickly: node skills/read-optimizer/index.js --file test.log --mode grep --pattern 'FAILED'