-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path120-utilities.mdc
More file actions
428 lines (295 loc) · 12.4 KB
/
Copy path120-utilities.mdc
File metadata and controls
428 lines (295 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
---
title: Command-Line Utilities & Documentation Ingestion Tools
description: Practical tool selection for agents reading docs, blogs, logs, and diagrams (curl, lynx, jq, httpie, ripgrep, Playwright, OCR, VLM)
priority: 120
alwaysApply: true
files:
include:
- "**/*.sh"
- "**/*.bash"
- "**/Makefile"
- "**/*.md"
---
# Command-Line Utilities & Documentation Ingestion Tools
## Guiding principle
Choose the lightest tool that reliably produces the content you need in a machine-consumable form.
- If the page is static HTML: prefer `curl` plus parsing (`jq` for JSON, HTML to text conversion, or a lightweight extractor).
- If the page is JavaScript-rendered or requires interaction: use a headless browser (Playwright).
- If Playwright is blocked or too heavy: try a doc-extraction proxy/cache (for example `https://context7.com/`) when it supports the target site.
- If you need diagrams understood (not OCR): use a screenshot (Playwright) and a vision-capable model (VLM).
- If you need text inside images: use OCR (Tesseract) as a supplement.
- If you are reading official documentation at scale: prefer a documentation-aware retrieval system (RAG) over raw scraping.
## What "done" looks like for an agent
The output you hand to the LLM should be:
- Clean text (minimal navigation noise)
- Source-attributed (URL, section headings)
- Chunked (so the LLM does not get one huge blob)
- Rate-limited and cacheable
- Deterministic when possible (same input URL gives similar chunks)
## Tool selection matrix
### 1) Static pages, APIs, feeds
Use these when content is already present in HTML or JSON without JS:
- `curl` for fetching
- `jq` for JSON shaping
- `ripgrep` for local searching
- `lynx -dump` for fast text extraction
Examples:
```bash
# Fetch HTML
curl -fsSL "https://acme.com/page" -o page.html
# Fetch JSON and shape it
curl -fsSL "https://api.acme.com/v1/items" | jq '.items[] | {id, name, updated_at}'
# Extract readable text quickly
lynx -dump -nolist "https://acme.com/page" > page.txt
```
When to stop here:
- If the text is good enough for the agent to answer questions
- If you do not need diagrams interpreted
- If the page is not JS-rendered
### 2) JS-heavy sites, auth flows, dynamic docs, robust extraction
Use Playwright when `curl` or `lynx` fails to capture the real content.
If Playwright fails (timeouts, bot protection, or brittle selectors) and you only need clean doc text, try a doc-extraction proxy/cache such as `https://context7.com/` (when it supports the target site).
Playwright is the right default for:
- SPA documentation sites
- Pages that lazy-load content
- Pages where you need to click "expand", "next", "load more"
- You need stable screenshots of diagrams
Operational guidance:
- Run headless by default
- Block heavy resources if you only need text (ads, video)
- Capture both:
1. Extracted page text (DOM text)
2. Screenshot of key sections (for diagrams)
### 3) Diagrams and visual reasoning
If the requirement is "understand the diagram", OCR is not enough.
Use:
- Playwright screenshot of the diagram region
- Vision-capable model (VLM) to interpret structure and meaning
Guidance for diagram prompting:
- Ask for components, flows, boundaries, assumptions
- Ask for a structured representation (bullets, adjacency list, Mermaid)
- Ask the model to cite what it sees in the image
Artifact handling (screenshots):
- In a git repo: save screenshots under a gitignored folder (commonly `tmp/`) and include the local path in your response.
- Outside a git repo: save to `$TMPDIR` (macOS) or `/tmp`.
- Use descriptive filenames (include site + page/section + timestamp) so artifacts can be re-opened.
- Never commit binary artifacts unless the user explicitly asks.
### 4) OCR for text inside images
Use OCR only to extract text embedded in images, for example:
- A screenshot of a config snippet inside a PNG
- A diagram that has important labels but you only need the labels
Tool: Tesseract (OCR)
Guidance:
- Prefer higher resolution images
- Preprocess if needed (convert to grayscale, increase contrast)
- Treat OCR output as noisy and validate against surrounding text
### 5) Documentation retrieval systems (RAG-first)
When the goal is "read AWS, Cloudflare, Kubernetes docs reliably at scale", prefer a doc-aware retrieval approach.
Characteristics:
- Ingest official docs (site map, versioned docs, markdown sources)
- Chunk and index
- Retrieve only relevant sections per question
- Avoid scraping the same pages repeatedly
This is especially useful for:
- API references
- Configuration options
- Up-to-date product docs
Note: doc-extraction proxy/caching services (for example `https://context7.com/`) can be a pragmatic alternative when browser automation is blocked or too expensive for the use case.
## Quick heuristics for agents
### Prefer `lynx -dump` when
- You just need readable text quickly
- You are validating a URL manually
- You want a cheap baseline before heavier tooling
### Prefer `curl` when
- You need raw content for a parser
- You want deterministic fetches
- You are working with JSON endpoints
### Prefer Playwright when
- The site is JS-rendered
- The HTML contains placeholders and the real text loads later
- You need screenshots for diagrams
- You need to click, scroll, or expand sections
### Prefer Context7 (or similar) when
- Playwright is blocked by bot protection or is too expensive for the task
- You only need clean, readable documentation text (not interaction)
- The target documentation source is supported by the retrieval/proxy system
### Prefer VLM screenshot analysis when
- "Understand the diagram" is a core requirement
- The meaning is in arrows, layout, grouping, icons, or visual structure
### Prefer OCR when
- The only missing piece is text inside an image
- You do not need structural understanding
## Anti-patterns (what NOT to do)
### Do not default to a headless browser for everything
Headless browsers are heavier and slower. Use them when necessary.
Bad:
- Always use a browser to fetch a static blog post
Good:
- Try `lynx -dump` or `curl` first, then escalate to Playwright if needed
### Do not paste entire pages into the LLM
Instead:
- Extract main content
- Keep headings
- Strip nav, footers, cookie banners
- Chunk into reasonable sections
### Do not scrape aggressively
- Respect robots.txt and site policies
- Add rate limiting
- Cache responses
## Common commands reference
### lynx
```bash
lynx -dump -nolist "https://acme.com"
lynx -source "https://acme.com" > page.html
```
### curl
```bash
curl -fsSL "https://acme.com" -o page.html
curl -I "https://acme.com"
```
### jq
```bash
cat payload.json | jq '.'
curl -fsSL "https://api.acme.com" | jq '.items[] | {id, name}'
```
### httpie
```bash
http GET "https://api.acme.com/v1/items"
http GET "https://api.acme.com/v1/items" Authorization:"Bearer $TOKEN"
```
### ripgrep
```bash
rg -n "VPC Lattice|PrivateLink|Cloudflare Tunnel" docs/
```
### fd (find alternative)
Fast, user-friendly alternative to `find` written in Rust:
```bash
# Find files by name (case-insensitive by default)
fd "\.py$" # Find all Python files
fd "test" # Find files/dirs containing "test"
fd -e py # Find files with .py extension
fd -e py -e js # Find .py or .js files
# Search in specific directory
fd "config" src/ # Find "config" in src/ directory
# Case-sensitive search
fd -s "Config" # Case-sensitive search
# Find directories only
fd -t d "test" # Find directories named "test"
fd -t f "test" # Find files only (default)
# Exclude patterns
fd -e py --exclude "venv" # Find .py files, exclude venv/
fd -E "*.pyc" -E "__pycache__" # Exclude multiple patterns
# Execute commands on results
fd -e py -x python # Run python on each .py file
fd -e sh -x chmod +x # Make shell scripts executable
# Limit depth
fd --max-depth 2 "test" # Search max 2 levels deep
# Common use cases
fd "\.tf$" # Find Terraform files
fd "README" # Find README files
fd -e yaml -e yml # Find YAML files
fd "\.git" -t d # Find .git directories
```
**Advantages over `find`:**
- Faster (written in Rust)
- Simpler syntax (no need for `-name`, `-type` flags)
- Case-insensitive by default
- Respects `.gitignore` automatically
- Colorized output
- Parallel execution
**Migration from find:**
```bash
# find equivalent
find . -name "*.py" -type f
# fd equivalent
fd -e py -t f
# find equivalent
find . -maxdepth 2 -name "test*"
# fd equivalent
fd --max-depth 2 "test"
```
### fzf (fuzzy finder)
Interactive fuzzy finder for command-line productivity:
```bash
# File search (Ctrl+T)
# Type partial filename, fzf filters results as you type
# Command history (Ctrl+R)
# Search through shell history interactively
# Directory navigation (Alt+C)
# Change directory with fuzzy search
# Git workflows
git checkout $(git branch | fzf) # Switch branches
git log --oneline | fzf # Browse commits
git diff $(git diff --name-only | fzf) # View diff of selected file
# Process management
kill -9 $(ps aux | fzf | awk '{print $2}') # Kill process interactively
# Code search integration
rg "pattern" | fzf # Search code, then filter results
```
**Shell integration setup:**
```bash
# Install shell bindings (adds Ctrl+R, Ctrl+T, Alt+C)
$(brew --prefix)/opt/fzf/install
```
**Use cases:**
- Finding files quickly without typing full paths
- Searching command history efficiently
- Navigating large directory structures
- Enhancing git workflows with interactive selection
- Filtering command output interactively
---
## Syncing folders between Git repos (rsync)
Use `rsync` when you need a **repeatable, deterministic** way to copy **specific directories** from one repo to another (e.g., syncing shared docs or rule files).
> [!IMPORTANT]
> **Always run with `--dry-run` first**, review the itemized changes, then remove `--dry-run` once you’re confident the target path is correct.
### Common footguns
- **Trailing slash matters**:
- `rsync ... src/ dest/` copies the **contents** of `src/` into `dest/`
- `rsync ... src dest/` copies the **directory** `src` into `dest/`
- **`--delete` is destructive**: it deletes files in the destination that don’t exist in the source (within the synced subtree)
- **Never sync `.git/`**: always exclude it explicitly
### Safe baseline command (local → local)
```bash
rsync -avh --dry-run --itemize-changes \
--exclude='.git/' \
--filter=':- .gitignore' \
"SOURCE_DIR/" "DEST_DIR/"
```
Notes:
- `--itemize-changes` makes the dry run reviewable.
- `--filter=':- .gitignore'` applies ignore rules from `.gitignore` files in the source tree (useful, but still validate the output).
### Mirroring a folder (source of truth → consumer repo)
Only use `--delete` when the destination should be a mirror of the source.
```bash
rsync -avh --dry-run --itemize-changes --delete \
--exclude='.git/' \
--filter=':- .gitignore' \
"SOURCE_DIR/" "DEST_DIR/"
```
### Sync only specific paths
Use include/exclude rules when you want a narrow subset.
```bash
rsync -avh --dry-run --itemize-changes \
--exclude='.git/' \
--include='/rules/***' \
--include='/commands/***' \
--exclude='*' \
"SOURCE_REPO_ROOT/" "DEST_REPO_ROOT/"
```
### Git hygiene
- Prefer syncing into a **clean working tree** (no local modifications) to keep diffs obvious.
- After syncing, use `git diff --stat` and `pre-commit run --all-files` (if configured).
## Related files
- Prefer pairing this with an "agent ingestion" rule that defines:
- chunk sizes
- citations format
- caching strategy
- escalation path (lynx/curl -> Context7 (optional) -> Playwright -> screenshot + VLM -> OCR)
## Resources
- [awesome-tuis](https://github.com/rothgar/awesome-tuis) - Curated list of TUI applications for terminal productivity (dashboards, file managers, git tools, database clients, etc.)
- [zoxide](https://github.com/ajeetdsouza/zoxide) - Smarter cd command that learns your habits
- [tmux](https://github.com/tmux/tmux) - Terminal multiplexer for persistent sessions
- [gh](https://cli.github.com/) - GitHub CLI for issues, PRs, and repo management
- [stow](https://www.gnu.org/software/stow/) - Symlink farm manager (great for dotfiles)
---
**Purpose**: Tool selection and repeatable patterns for agents reading docs, blogs, logs, and diagrams