pi-lens 3.6.4 → 3.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +589 -589
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,589 +1,589 @@
1
- # pi-lens
2
-
3
- **pi extension for real-time code quality.** 31 LSP servers, tree-sitter structural analysis, AST pattern matching, auto-install for TypeScript/Python tooling, duplicate detection, complexity metrics, and inline blockers with comprehensive `/lens-booboo` reports.
4
-
5
- ## What pi-lens Does
6
-
7
- **For every file you edit:**
8
- 1. **Auto-formats** — Detects and runs formatters (Biome, Prettier, Ruff, gofmt, rustfmt, etc.)
9
- 2. **Type-checks** — TypeScript, Python, Go, Rust (31 languages with `--lens-lsp`)
10
- 3. **Scans for secrets** — Blocks on hardcoded API keys, tokens, passwords
11
- 4. **Runs linters** — Biome (TS/JS), Ruff (Python), plus structural analysis
12
- 5. **Tree-sitter analysis** — Deep structural patterns (empty catch, eval, deep nesting, mixed async styles)
13
- 6. **Auto-installs** — TypeScript, Python, Biome, Ruff, and analysis tools auto-install on first use
14
- 7. **Only shows NEW issues** — Delta-mode tracks baselines and filters pre-existing problems
15
-
16
- **🔴 Blockers** (type errors, secrets, empty catches) appear inline and stop the agent until fixed.
17
- **🟡 Warnings** (complexity, code smells) go to `/lens-booboo` — run it to see them all.
18
-
19
- ## Quick Start
20
-
21
- ```bash
22
- # Install
23
- pi install npm:pi-lens
24
-
25
- # Standard mode (auto-formatting, type-checking, linting enabled by default)
26
- pi
27
-
28
- # Disable auto-formatting if needed
29
- pi --no-autoformat
30
-
31
- # Full LSP mode (31 language servers) — recommended for large/multi-language projects
32
- pi --lens-lsp
33
- ```
34
-
35
- ## Install
36
-
37
- ```bash
38
- pi install npm:pi-lens
39
- ```
40
-
41
- Or directly from git:
42
-
43
- ```bash
44
- pi install git:github.com/apmantza/pi-lens
45
- ```
46
-
47
- ---
48
-
49
- ## Features
50
-
51
- ### Auto-Formatting (Default Enabled)
52
-
53
- pi-lens **automatically formats** every file you write or edit. Formatters are auto-detected based on your project configuration.
54
-
55
- **Priority:** **Biome** is the default. **Prettier** runs only if Biome is not configured. This prevents race conditions and ensures consistent formatting.
56
-
57
- | Formatter | Languages | Detection | Installation | Role |
58
- |-----------|-----------|-----------|--------------|------|
59
- | **Biome** | TS/JS/JSON/CSS | `biome.json` or `@biomejs/biome` in devDependencies | Automatic | **Default** |
60
- | **Prettier** | TS/JS/JSON/CSS/Markdown | `.prettierrc` or `prettier` in devDependencies | Manual (`npm install -g prettier`) | Fallback |
61
- | **Ruff** | Python | `[tool.ruff]` in `pyproject.toml` | Automatic | **Default** |
62
- | **Black** | Python | `[tool.black]` in `pyproject.toml` | Manual (`pip install black`) | Fallback |
63
- | **gofmt** | Go | `go` binary available | Manual (included with Go SDK) | Default |
64
- | **rustfmt** | Rust | `rustfmt` binary available | Manual (included with Rust toolchain) | Default |
65
- | **zig fmt** | Zig | `zig` binary available | Manual (included with Zig SDK) | Default |
66
- | **dart format** | Dart | `dart` binary available | Manual (included with Dart SDK) | Default |
67
- | **shfmt** | Shell | `shfmt` binary available | Manual (download binary) | Default |
68
- | **mix format** | Elixir | `mix` binary available | Manual (included with Elixir) | Default |
69
-
70
- = Auto-installed (no manual setup required)
71
-
72
- **How it works:**
73
- 1. Agent writes a file
74
- 2. pi-lens detects formatters based on config files/dependencies
75
- 3. Biome takes priority; Prettier runs only if Biome is not configured
76
- 4. FileTime tracking ensures safety (agents re-read if file changes externally)
77
-
78
- **Safety:** If a formatter changes the file, the agent is notified and must re-read before next edit — preventing stale content overwrites.
79
-
80
- **Disable:**
81
- ```bash
82
- pi --no-autoformat # Skip automatic formatting
83
- ```
84
-
85
- ---
86
-
87
- ### Auto-Linting (Default Enabled)
88
-
89
- pi-lens **automatically lints** every file you write or edit. Linters are auto-detected based on your project configuration.
90
-
91
- | Linter | Languages | Installation | Role | Priority |
92
- |--------|-----------|--------------|------|----------|
93
- | **Biome** | TS/JS/JSON/CSS | Automatic | **Default** | 10 |
94
- | **Ruff** | Python | Automatic | **Default** | 10 |
95
- | **oxlint** | TS/JS | Manual (`npm i -g oxlint`) | Fast alternative | 12 |
96
- | **ESLint** | JS/Vue/Svelte | `npx` via `--lens-lsp` | LSP only | - |
97
- | **shellcheck** | Bash/sh/zsh/fish | Manual (`apt install shellcheck`) | Shell scripts | 20 |
98
-
99
- = Auto-installed (no manual setup required)
100
-
101
- **Priority:** Lower numbers = run earlier. Biome/Ruff run first, followed by specialized linters.
102
-
103
- **How it works:**
104
- 1. Agent writes a file
105
- 2. pi-lens detects linters based on config files and file type
106
- 3. Biome takes priority for TS/JS; Ruff takes priority for Python
107
- 4. Multiple linters can run on the same file (e.g., Biome + oxlint)
108
- 5. Issues are delta-tracked (only new issues shown after first write)
109
-
110
- **Notes:**
111
- - Biome and Ruff are **dual-purpose** (lint + format)
112
- - oxlint is a faster Rust-based alternative to ESLint
113
- - ESLint only runs when `--lens-lsp` is enabled
114
- - shellcheck requires manual installation on most systems
115
-
116
- ---
117
-
118
- ### LSP Support (NEW) — 31 Language Servers
119
-
120
- Enable full Language Server Protocol support with `--lens-lsp`:
121
-
122
- | Category | Languages |
123
- |----------|-----------|
124
- | **Core** | TypeScript, Python, Go, Rust, Ruby, PHP, C#, F#, Java, Kotlin |
125
- | **Native** | C/C++, Zig, Swift, Haskell, OCaml, Lua, Dart |
126
- | **Functional** | Elixir, Gleam, Clojure, Haskell |
127
- | **DevOps** | Terraform, Nix, Docker, Bash |
128
- | **Config** | YAML, JSON, Prisma |
129
- | **Web** | Vue, Svelte, CSS/SCSS/Sass/Less |
130
-
131
- **Auto-installation (8 tools):** TypeScript, Python, Biome, Ruff, and analysis tools (Madge, jscpd, ast-grep, Knip) auto-install on first use to `.pi-lens/tools/`. Other LSP servers are launched via `npx` when available or require manual installation.
132
-
133
- **Usage:**
134
- ```bash
135
- pi --lens-lsp # Enable LSP
136
- ```
137
-
138
- ### `pi` vs `pi --lens-lsp`
139
-
140
- | Feature | `pi` (Default) | `pi --lens-lsp` |
141
- |---------|----------------|-----------------|
142
- | **Type Checking** | Built-in TypeScriptClient | Full LSP (31 language servers) |
143
- | **Auto-format** | Biome, Prettier, Ruff, etc. | Same |
144
- | **Auto-fix** | Enabled by default | Same |
145
- | **Secrets scan** | Blocks on hardcoded secrets | Same |
146
- | **Languages** | TypeScript, Python (built-in) | 31 languages via LSP |
147
- | **Python** | Ruff/pyright (built-in) | Pyright LSP |
148
- | **Go, Rust, etc.** | Basic linting | Full LSP support |
149
-
150
- **Recommendation:** Use `pi` for TypeScript/Python projects. Use `pi --lens-lsp` for multi-language projects or when you need full language server features.
151
-
152
- See [docs/LSP_CONFIG.md](docs/LSP_CONFIG.md) for configuration options.
153
-
154
- ---
155
-
156
- ### On every write / edit
157
-
158
- Every file write/edit triggers multiple analysis phases:
159
-
160
- **Execution flow:**
161
- 1. **Secrets scan** (pre-flight) — Hardcoded secrets block immediately (non-runner check)
162
- 2. **LSP integration** (Phase 3, with `--lens-lsp`) — Real-time type errors from language servers
163
- 3. **Dispatch system** — Routes file to appropriate runners by `FileKind`
164
- 4. **Runners execute** by priority (lower = earlier). See [Runners](#runners) section for full list.
165
- 5. **Test runner detection** (post-write) — Detects Jest/Vitest/Pytest and runs relevant tests
166
-
167
- **Delta mode behavior:**
168
- - **First write:** All issues tracked and stored in baseline
169
- - **Subsequent edits:** Only **NEW** issues shown (pre-existing issues filtered out)
170
- - **Goal:** Don't spam agent with issues they didn't cause
171
-
172
- **Output shown inline:**
173
- ```
174
- 🔴 STOP — 1 issue(s) must be fixed:
175
- L23: var total = sum(items); — use 'let' or 'const'
176
- ```
177
-
178
- > **Note:** Only **blocking** issues (`ts-lsp`, `pyright` errors, `type-safety` switch errors, secrets) appear inline. Warnings are tracked but not shown inline (noise reduction) — run `/lens-booboo` to see all warnings.
179
-
180
- ---
181
-
182
- ### Runners
183
-
184
- pi-lens uses a **dispatcher-runner architecture** for extensible multi-language support. Runners are executed by priority (lower = earlier).
185
-
186
- | Runner | Language | Priority | Output | Description |
187
- |--------|----------|----------|--------|-------------|
188
- | **ts-lsp** | TypeScript | 5 | Blocking | TypeScript errors (hard stops) |
189
- | **pyright** | Python | 5 | Blocking | Python type errors (hard stops) |
190
- | **biome** | TS/JS | 10 | Warning | Linting issues (delta-tracked) |
191
- | **ruff** | Python | 10 | Warning | Python linting (delta-tracked) |
192
- | **oxlint** | TS/JS | 12 | Warning | Fast Rust-based JS/TS linter |
193
- | **tree-sitter** | TS/JS, Python | 14 | Mixed | AST-based structural analysis (21 patterns) — **singleton WASM client** |
194
- | **ast-grep-napi** | TS/JS | 15 | Blocking | Security rules inline (no-eval, jwt-no-verify, no-hardcoded-secrets, etc.) |
195
- | **type-safety** | TS | 20 | Mixed | Switch exhaustiveness (blocking), other (warning) |
196
- | **shellcheck** | Shell | 20 | Warning | Bash/sh/zsh/fish linting |
197
- | **python-slop** | Python | 25 | Warning | AI slop detection (~40 patterns) |
198
- | **spellcheck** | Markdown | 30 | Warning | Typo detection in docs |
199
- | **similarity** | TS | 35 | Warning | Semantic duplicate detection (structural similarity) |
200
- | **architect** | All | 40 | Warning | Architectural rule violations |
201
- | **go-vet** | Go | 50 | Warning | Go static analysis |
202
- | **rust-clippy** | Rust | 50 | Warning | Rust linting |
203
-
204
- **Priority legend:**
205
- - **5** — Type checkers (blocking errors)
206
- - **10-15** — Linters and structural analysis
207
- - **20-30** — Specialized checks (safety, slop, spellcheck)
208
- - **35** — Metrics only (silent)
209
- - **40-50** — Language-specific and architectural
210
-
211
- **Output semantics:**
212
- - **Blocking** — Hard stop, must fix (type errors, secrets)
213
- - **Warning** — Shown in `/lens-booboo`, not inline (noise reduction)
214
- - **Silent** — Tracked in metrics only, never shown
215
-
216
- **Consolidated runners:** `ts-slop` merged into `ast-grep-napi` — CLI ast-grep used for full linter via `/lens-booboo`
217
-
218
- **Tree-sitter runner patterns** (priority 14, AST-based structural analysis):
219
-
220
- TypeScript/JavaScript (13 patterns):
221
- - 🔴 **Error**: empty-catch, hardcoded-secrets, eval
222
- - 🟡 **Warning**: debugger, await-in-loop, console-statement, long-parameter-list, nested-ternary, deep-promise-chain, mixed-async-styles, deep-nesting, constructor-super, no-dupe-class-members
223
-
224
- TSX (2 patterns):
225
- - 🔴 **Error**: dangerously-set-inner-html
226
- - 🟡 **Warning**: no-nested-links
227
-
228
- Python (6 patterns):
229
- - 🔴 **Error**: bare-except, mutable-default-arg, eval-exec, unreachable-except
230
- - 🟡 **Warning**: wildcard-import, is-vs-equals
231
-
232
- **Custom tree-sitter queries:** Add `.yml` files to `.pi-lens/rules/tree-sitter-queries/{typescript,python}/`
233
-
234
- **AI Slop Detection:**
235
- - `python-slop` runner (priority 25): ~40 patterns for Python code quality
236
- - `ast-grep-napi` runner (priority 15): Security rules fire inline (blocking); slop/architecture warnings via `/lens-booboo` only. Skips 5 rules already covered by tree-sitter.
237
-
238
- ---
239
-
240
- ### Additional Safeguards
241
-
242
- Safeguards that run **before** the dispatch system:
243
-
244
- #### Secrets Scanning (Pre-flight)
245
-
246
- Runs on every file write/edit **before** any other checks. Scans for:
247
- - Stripe/OpenAI keys (`sk-*`)
248
- - GitHub tokens (`ghp_*`, `github_pat_*`)
249
- - AWS keys (`AKIA*`)
250
- - Slack tokens (`xoxb-*`, `xoxp-*`)
251
- - Private keys (`BEGIN PRIVATE KEY`)
252
- - Hardcoded passwords and API keys
253
-
254
- **Behavior:** Always blocking, always runs on all file types. Cannot be disabled — security takes precedence.
255
-
256
- #### Agent Behavior Warnings
257
-
258
- Inline heuristics to catch anti-patterns in real-time:
259
-
260
- **Blind Write Detection**
261
- - **Triggers:** Agent edits a file without reading it in the last 5 tool calls
262
- - **Warning:** `⚠ BLIND WRITE — editing 'file.ts' without reading in the last 5 tool calls.`
263
- - **Why:** Prevents edits based on stale assumptions
264
-
265
- **Thrashing Detection**
266
- - **Triggers:** 3+ consecutive identical tool calls within 30 seconds
267
- - **Warning:** `🔴 THRASHING — 3 consecutive 'edit' calls with no other action.`
268
- - **Why:** Catches stuck loops where the agent repeats failed actions
269
-
270
- **Behavior:** Warnings appear inline but do **not** block execution.
271
-
272
- #### Custom ast-grep Rules
273
-
274
- Create your own structural rules in `.pi-lens/rules/`:
275
-
276
- ```yaml
277
- # .pi-lens/rules/no-console-prod.yml
278
- id: no-console-prod
279
- language: javascript
280
- rule:
281
- pattern: console.$METHOD($$$ARGS)
282
- message: "Remove console statements before production"
283
- severity: warning
284
- ```
285
-
286
- See [AST_GREP_RULES.md](AST_GREP_RULES.md) for full guide.
287
-
288
- ---
289
-
290
- ### At Session Start
291
-
292
- When pi starts a new session, pi-lens performs initialization scans to establish baselines and surface existing technical debt:
293
-
294
- **Initialization sequence:**
295
- 1. **Reset session state** — Clear metrics and complexity baselines
296
- 2. **Initialize LSP** (with `--lens-lsp`) — Detect and auto-install language servers
297
- 3. **Pre-install TypeScript LSP** (with `--lens-lsp`) — Warm up cache for instant response
298
- 4. **Detect available tools** — Biome, ast-grep, Ruff, Knip, jscpd, Madge, type-coverage, Go, Rust
299
- 5. **Load architect rules** — If `architect.yml` or `.architect.yml` present
300
- 6. **Detect test runner** — Jest, Vitest, Pytest, etc.
301
-
302
- **Cached scans** (with 5-min TTL):
303
- | Scan | Tool | Cached | Purpose |
304
- |------|------|--------|---------|
305
- | **TODOs** | Internal | No | Tech debt markers |
306
- | **Dead code** | Knip | Yes | Unused exports/files/deps |
307
- | **Duplicates** | jscpd | Yes | Copy-paste detection |
308
- | **Exports** | ast-grep | No | Function index for similarity |
309
-
310
- **Error debt tracking** (with `--error-debt` flag):
311
- - If tests passed at end of previous session but fail now → **regression detected**
312
- - Blocks agent until tests pass again
313
-
314
- **Output:** Scan results appear in session startup notification
315
-
316
- ---
317
-
318
- ### Code Review
319
-
320
- ```
321
- /lens-booboo [path]
322
- ```
323
-
324
- Full codebase analysis with **10 tracked runners** producing a comprehensive report:
325
-
326
- | # | Runner | What it finds |
327
- |---|--------|---------------|
328
- | 1 | **ast-grep (design smells)** | Structural issues (empty catch, no-debugger, etc.) |
329
- | 2 | **ast-grep (similar functions)** | Duplicate function patterns across files |
330
- | 3 | **semantic similarity (Amain)** | 57×72 matrix semantic clones (>75% similarity) |
331
- | 4 | **complexity metrics** | Low MI, high cognitive complexity, AI slop indicators |
332
- | 5 | **TODO scanner** | TODO/FIXME annotations and tech debt markers |
333
- | 6 | **dead code (Knip)** | Unused exports, files, dependencies |
334
- | 7 | **duplicate code (jscpd)** | Copy-paste blocks with line/token counts |
335
- | 8 | **type coverage** | Percentage typed vs `any`, low-coverage files |
336
- | 9 | **circular deps (Madge)** | Import cycles and dependency chains |
337
- | 10 | **architectural rules** | Layer violations, file size limits, path rules |
338
-
339
- **Output:**
340
- - **Terminal:** Progress `[1/10] runner...` with timing, summary with findings per runner
341
- - **JSON:** `.pi-lens/reviews/booboo-{timestamp}.json` (structured data for AI processing)
342
- - **Markdown:** `.pi-lens/reviews/booboo-{timestamp}.md` (human-readable report)
343
-
344
- **Usage:**
345
- ```bash
346
- /lens-booboo # Scan current directory
347
- /lens-booboo ./src # Scan specific path
348
- ```
349
-
350
- ---
351
-
352
- ### Test Runner
353
-
354
- **Auto-detected test runners:**
355
- | Runner | Config Files | Languages |
356
- |--------|--------------|-----------|
357
- | **Vitest** | `vitest.config.ts`, `vitest.config.js` | TypeScript, JavaScript |
358
- | **Jest** | `jest.config.js`, `jest.config.ts`, `package.json` (jest field) | TypeScript, JavaScript |
359
- | **Pytest** | `pytest.ini`, `setup.cfg`, `pyproject.toml` | Python |
360
-
361
- **Behavior:**
362
- - **On file write:** Detects corresponding test file and runs it
363
- - **Pattern matching:** `file.ts` → `file.test.ts` or `__tests__/file.test.ts`
364
- - **Output:** Inline pass/fail with failure details (shown with lint results)
365
- - **Flag:** Use `--no-tests` to disable automatic test running
366
-
367
- **Execution flow:**
368
- 1. Agent writes `src/utils.ts`
369
- 2. pi-lens finds `src/utils.test.ts` (or `__tests__/utils.test.ts`)
370
- 3. Runs only that test file (not full suite)
371
- 4. Results appear inline:
372
- ```
373
- [tests] 3 passed, 1 failed (42ms)
374
- ✓ should calculate total
375
- ✗ should handle empty array (expected 0, got undefined)
376
- ```
377
-
378
- **Why only corresponding tests?**
379
- Running the full suite on every edit would be too slow. Targeted testing gives immediate feedback for the code being edited.
380
-
381
- ---
382
-
383
- ### Complexity Metrics
384
-
385
- pi-lens tracks code quality metrics for every file:
386
-
387
- | Metric | Description | Threshold |
388
- |--------|-------------|-----------|
389
- | **Maintainability Index** | 0-100 composite score | >60 <20 🔴 |
390
- | **Cognitive Complexity** | Mental effort to understand | >20 🟡 >50 🔴 |
391
- | **Cyclomatic Complexity** | Independent code paths | >10 🟡 >20 🔴 |
392
- | **Code Entropy** | Shannon entropy in bits | >4.0 🟡 >7.0 🔴 |
393
-
394
- **Commands:**
395
- - `/lens-tdi` — Technical Debt Index (0-100) with grades A-F
396
- - `/lens-booboo` — Full complexity table for all files
397
-
398
- See [docs/COMPLEXITY_METRICS.md](docs/COMPLEXITY_METRICS.md) for formulas and detailed calculations.
399
-
400
- ---
401
-
402
- ## Dependent Tools
403
-
404
- pi-lens works out of the box for TypeScript/JavaScript. For full language support, install these tools — **all are optional and gracefully skip if not installed**:
405
-
406
- ### JavaScript / TypeScript
407
-
408
- | Tool | Install | What it does |
409
- |------|---------|--------------|
410
- | `@biomejs/biome` | `npm i -D @biomejs/biome` | Linting + formatting |
411
- | `oxlint` | `npm i -D oxlint` | Fast Rust-based JS/TS linting |
412
- | `knip` | `npm i -D knip` | Dead code / unused exports |
413
- | `jscpd` | `npm i -D jscpd` | Copy-paste detection |
414
- | `type-coverage` | `npm i -D type-coverage` | TypeScript `any` coverage % |
415
- | `@ast-grep/napi` | `npm i -D @ast-grep/napi` | Fast structural analysis (TS/JS) — security rules inline, slop in booboo |
416
- | `@ast-grep/cli` | `npm i -D @ast-grep/cli` | Structural pattern matching (all languages) |
417
- | `typos-cli` | `cargo install typos-cli` | Spellcheck for Markdown |
418
-
419
- ### Python
420
-
421
- | Tool | Install | What it does |
422
- |------|---------|--------------|
423
- | `ruff` | `pip install ruff` | Linting + formatting |
424
- | `pyright` | `pip install pyright` | Type-checking (catches type errors) |
425
-
426
- ### Go
427
-
428
- | Tool | Install | What it does |
429
- |------|---------|--------------|
430
- | `go` | [golang.org](https://golang.org) | Built-in `go vet` for static analysis |
431
-
432
- ### Rust
433
-
434
- | Tool | Install | What it does |
435
- |------|---------|--------------|
436
- | `rust` + `clippy` | [rustup.rs](https://rustup.rs) | Linting via `cargo clippy` |
437
-
438
- ### Shell
439
-
440
- | Tool | Install | What it does |
441
- |------|---------|--------------|
442
- | `shellcheck` | `apt install shellcheck` / `brew install shellcheck` | Shell script linting (bash/sh/zsh/fish) |
443
-
444
- ---
445
-
446
- ## Commands
447
-
448
- | Command | Description |
449
- |---------|-------------|
450
- | `/lens-booboo` | Full codebase review (10 analysis runners) |
451
- | `/lens-tdi` | Technical Debt Index and trends |
452
-
453
- ---
454
-
455
- ## Execution Modes
456
-
457
- | Mode | Command | What happens |
458
- |------|---------|--------------|
459
- | **Standard** (default) | `pi` | Auto-formatting, TS/Python type-checking, sequential execution |
460
- | **Full LSP** | `pi --lens-lsp` | Real LSP servers (31 languages), sequential execution |
461
-
462
-
463
- ### Flag Reference
464
-
465
- | Flag | Description |
466
- |------|-------------|
467
- | `--lens-lsp` | Use real Language Server Protocol servers instead of built-in type-checking |
468
- | `--lens-verbose` | Enable detailed console logging |
469
- | `--no-autoformat` | Disable automatic formatting (formatting is **enabled by default**) |
470
- | `--no-autofix` | Disable all auto-fixing (Biome safe fixes + Ruff autofix **enabled by default**). Unsafe fixes (e.g. removing unused vars) are never applied automatically — use `/lens-booboo` with explicit confirmation. |
471
- | `--no-autofix-biome` | Disable Biome auto-fix only |
472
- | `--no-autofix-ruff` | Disable Ruff auto-fix only |
473
- | `--no-oxlint` | Skip Oxlint linting |
474
- | `--no-shellcheck` | Skip shellcheck for shell scripts |
475
- | `--no-tests` | Disable automatic test running on file write |
476
- | `--no-madge` | Skip circular dependency checks |
477
- | `--no-ast-grep` | Skip ast-grep structural analysis |
478
- | `--no-biome` | Skip Biome linting |
479
- | `--no-lsp` | Skip TypeScript/Python type checking |
480
- | `--error-debt` | Track test regressions across sessions |
481
-
482
- **Recommended combinations:**
483
- ```bash
484
- pi # Default: auto-format, auto-fix, built-in type-checking
485
- pi --lens-lsp # LSP type-checking (31 languages)
486
- ```
487
-
488
- ---
489
-
490
- ## TypeScript LSP — tsconfig detection
491
-
492
- The LSP walks up from edited files to find `tsconfig.json`, using its `compilerOptions` (paths, strict settings, etc.). Falls back to sensible defaults if not found.
493
-
494
- ---
495
-
496
- ## Project Structure
497
-
498
- ```
499
- pi-lens/
500
- ├── clients/ # Lint tools, LSP clients, formatters
501
- ├── commands/ # /lens-booboo, /lens-format commands
502
- ├── docs/ # Documentation
503
- ├── rules/ # AST-grep rules
504
- ├── skills/ # Built-in pi skills
505
- ├── index.ts # Main extension entry point
506
- └── package.json
507
- ```
508
-
509
- See source for detailed structure.
510
-
511
- ---
512
-
513
- ## Skills
514
-
515
- pi-lens includes two built-in skills that guide the LLM on when to use specific tools:
516
-
517
- ### ast-grep
518
-
519
- **Purpose:** Guide AST-aware pattern matching for semantic code search/replace.
520
-
521
- **When to load:** Use `/skill:ast-grep` when performing structural code searches (finding function calls, class methods, imports) or replacements across files.
522
-
523
- **Key guidance:**
524
- - Use `$VAR` for single nodes, `$$$` for multiple
525
- - Patterns must be **complete valid code** (not fragments)
526
- - **Workflow:** Search → Dry-run (`apply: false`) → Apply (`apply: true`)
527
- - **Error "Multiple AST nodes":** Use metavariables like `it($TEST)` not raw text like `it"test"`
528
-
529
- ```typescript
530
- // GOOD: Complete code with metavariables
531
- ast_grep_search
532
- pattern: "console.log($MSG)"
533
- lang: typescript
534
- paths: ["src/"]
535
-
536
- // BAD: Incomplete pattern
537
- pattern: "console.log(" // Missing args/body
538
- ```
539
-
540
- ### lsp-navigation
541
-
542
- **Purpose:** Guide code intelligence via Language Server Protocol.
543
-
544
- **When to load:** Use `/skill:lsp-navigation` for understanding code structure — definitions, references, types, call hierarchy.
545
-
546
- **Key guidance:**
547
- - **LSP is PRIMARY** for code intelligence — NOT grep/glob/ast-grep
548
- - Requires `--lens-lsp` flag
549
- - Call hierarchy: `prepareCallHierarchy` → `incomingCalls`/`outgoingCalls`
550
-
551
- | Task | Use LSP | Use Other |
552
- |------|---------|-----------|
553
- | "Where is this defined?" | `definition` | — |
554
- | "Find all usages" | `references` | — |
555
- | "What type is this?" | `hover` | — |
556
- | "Who calls this function?" | `prepareCallHierarchy` → `incomingCalls` | — |
557
- | Find patterns (console.log) | — | `ast_grep_search` |
558
- | Find TODO comments | — | `grep` |
559
-
560
- ```typescript
561
- // Code intelligence → LSP
562
- lsp_navigation
563
- operation: "references"
564
- filePath: "src/utils.ts"
565
- line: 42
566
- character: 10
567
-
568
- // Don't use LSP for text patterns
569
- pattern: "TODO" // Use grep instead
570
- ```
571
-
572
- ---
573
-
574
- ## Changelog
575
-
576
- See [CHANGELOG.md](CHANGELOG.md) for full history.
577
-
578
- ### Latest Highlights
579
-
580
- - **Tree-sitter Query Cache:** Compiled query cache with mtime-based invalidation — 10× faster structural analysis startup
581
- - **LSP Support:** 31 Language Server Protocol clients (4 core auto-installed, others via npx or manual)
582
- - **NAPI Runner:** 100x faster TypeScript/JavaScript structural analysis (~9ms vs ~1200ms) — security rules fire inline
583
- - **Slop Detection:** 33+ TypeScript and 40+ Python patterns for AI-generated code quality issues
584
-
585
- ---
586
-
587
- ## License
588
-
589
- MIT
1
+ # pi-lens
2
+
3
+ **pi extension for real-time code quality.** 31 LSP servers, tree-sitter structural analysis, AST pattern matching, auto-install for TypeScript/Python tooling, duplicate detection, complexity metrics, and inline blockers with comprehensive `/lens-booboo` reports.
4
+
5
+ ## What pi-lens Does
6
+
7
+ **For every file you edit:**
8
+ 1. **Auto-formats** — Detects and runs formatters (Biome, Prettier, Ruff, gofmt, rustfmt, etc.)
9
+ 2. **Type-checks** — TypeScript, Python, Go, Rust (31 languages with `--lens-lsp`)
10
+ 3. **Scans for secrets** — Blocks on hardcoded API keys, tokens, passwords
11
+ 4. **Runs linters** — Biome (TS/JS), Ruff (Python), plus structural analysis
12
+ 5. **Tree-sitter analysis** — Deep structural patterns (empty catch, eval, deep nesting, mixed async styles)
13
+ 6. **Auto-installs** — TypeScript, Python, Biome, Ruff, and analysis tools auto-install on first use
14
+ 7. **Only shows NEW issues** — Delta-mode tracks baselines and filters pre-existing problems
15
+
16
+ **Blockers** (type errors, secrets, empty catches) appear inline and stop the agent until fixed.
17
+ **Warnings** (complexity, code smells) go to `/lens-booboo` — run it to see them all.
18
+
19
+ ## Quick Start
20
+
21
+ ```bash
22
+ # Install
23
+ pi install npm:pi-lens
24
+
25
+ # Standard mode (auto-formatting, type-checking, linting enabled by default)
26
+ pi
27
+
28
+ # Disable auto-formatting if needed
29
+ pi --no-autoformat
30
+
31
+ # Full LSP mode (31 language servers) — recommended for large/multi-language projects
32
+ pi --lens-lsp
33
+ ```
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pi install npm:pi-lens
39
+ ```
40
+
41
+ Or directly from git:
42
+
43
+ ```bash
44
+ pi install git:github.com/apmantza/pi-lens
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Features
50
+
51
+ ### Auto-Formatting (Default Enabled)
52
+
53
+ pi-lens **automatically formats** every file you write or edit. Formatters are auto-detected based on your project configuration.
54
+
55
+ **Priority:** **Biome** is the default. **Prettier** runs only if Biome is not configured. This prevents race conditions and ensures consistent formatting.
56
+
57
+ | Formatter | Languages | Detection | Installation | Role |
58
+ |-----------|-----------|-----------|--------------|------|
59
+ | **Biome** | TS/JS/JSON/CSS | `biome.json` or `@biomejs/biome` in devDependencies | Automatic | **Default** |
60
+ | **Prettier** | TS/JS/JSON/CSS/Markdown | `.prettierrc` or `prettier` in devDependencies | Manual (`npm install -g prettier`) | Fallback |
61
+ | **Ruff** | Python | `[tool.ruff]` in `pyproject.toml` | Automatic | **Default** |
62
+ | **Black** | Python | `[tool.black]` in `pyproject.toml` | Manual (`pip install black`) | Fallback |
63
+ | **gofmt** | Go | `go` binary available | Manual (included with Go SDK) | Default |
64
+ | **rustfmt** | Rust | `rustfmt` binary available | Manual (included with Rust toolchain) | Default |
65
+ | **zig fmt** | Zig | `zig` binary available | Manual (included with Zig SDK) | Default |
66
+ | **dart format** | Dart | `dart` binary available | Manual (included with Dart SDK) | Default |
67
+ | **shfmt** | Shell | `shfmt` binary available | Manual (download binary) | Default |
68
+ | **mix format** | Elixir | `mix` binary available | Manual (included with Elixir) | Default |
69
+
70
+ (*) = Auto-installed (no manual setup required)
71
+
72
+ **How it works:**
73
+ 1. Agent writes a file
74
+ 2. pi-lens detects formatters based on config files/dependencies
75
+ 3. Biome takes priority; Prettier runs only if Biome is not configured
76
+ 4. FileTime tracking ensures safety (agents re-read if file changes externally)
77
+
78
+ **Safety:** If a formatter changes the file, the agent is notified and must re-read before next edit — preventing stale content overwrites.
79
+
80
+ **Disable:**
81
+ ```bash
82
+ pi --no-autoformat # Skip automatic formatting
83
+ ```
84
+
85
+ ---
86
+
87
+ ### Auto-Linting (Default Enabled)
88
+
89
+ pi-lens **automatically lints** every file you write or edit. Linters are auto-detected based on your project configuration.
90
+
91
+ | Linter | Languages | Installation | Role | Priority |
92
+ |--------|-----------|--------------|------|----------|
93
+ | **Biome** | TS/JS/JSON/CSS | Automatic | **Default** | 10 |
94
+ | **Ruff** | Python | Automatic | **Default** | 10 |
95
+ | **oxlint** | TS/JS | Manual (`npm i -g oxlint`) | Fast alternative | 12 |
96
+ | **ESLint** | JS/Vue/Svelte | `npx` via `--lens-lsp` | LSP only | - |
97
+ | **shellcheck** | Bash/sh/zsh/fish | Manual (`apt install shellcheck`) | Shell scripts | 20 |
98
+
99
+ (*) = Auto-installed (no manual setup required)
100
+
101
+ **Priority:** Lower numbers = run earlier. Biome/Ruff run first, followed by specialized linters.
102
+
103
+ **How it works:**
104
+ 1. Agent writes a file
105
+ 2. pi-lens detects linters based on config files and file type
106
+ 3. Biome takes priority for TS/JS; Ruff takes priority for Python
107
+ 4. Multiple linters can run on the same file (e.g., Biome + oxlint)
108
+ 5. Issues are delta-tracked (only new issues shown after first write)
109
+
110
+ **Notes:**
111
+ - Biome and Ruff are **dual-purpose** (lint + format)
112
+ - oxlint is a faster Rust-based alternative to ESLint
113
+ - ESLint only runs when `--lens-lsp` is enabled
114
+ - shellcheck requires manual installation on most systems
115
+
116
+ ---
117
+
118
+ ### LSP Support (NEW) — 31 Language Servers
119
+
120
+ Enable full Language Server Protocol support with `--lens-lsp`:
121
+
122
+ | Category | Languages |
123
+ |----------|-----------|
124
+ | **Core** | TypeScript, Python, Go, Rust, Ruby, PHP, C#, F#, Java, Kotlin |
125
+ | **Native** | C/C++, Zig, Swift, Haskell, OCaml, Lua, Dart |
126
+ | **Functional** | Elixir, Gleam, Clojure, Haskell |
127
+ | **DevOps** | Terraform, Nix, Docker, Bash |
128
+ | **Config** | YAML, JSON, Prisma |
129
+ | **Web** | Vue, Svelte, CSS/SCSS/Sass/Less |
130
+
131
+ **Auto-installation (8 tools):** TypeScript, Python, Biome, Ruff, and analysis tools (Madge, jscpd, ast-grep, Knip) auto-install on first use to `.pi-lens/tools/`. Other LSP servers are launched via `npx` when available or require manual installation.
132
+
133
+ **Usage:**
134
+ ```bash
135
+ pi --lens-lsp # Enable LSP
136
+ ```
137
+
138
+ ### `pi` vs `pi --lens-lsp`
139
+
140
+ | Feature | `pi` (Default) | `pi --lens-lsp` |
141
+ |---------|----------------|-----------------|
142
+ | **Type Checking** | Built-in TypeScriptClient | Full LSP (31 language servers) |
143
+ | **Auto-format** | Biome, Prettier, Ruff, etc. | Same |
144
+ | **Auto-fix** | Enabled by default | Same |
145
+ | **Secrets scan** | Blocks on hardcoded secrets | Same |
146
+ | **Languages** | TypeScript, Python (built-in) | 31 languages via LSP |
147
+ | **Python** | Ruff/pyright (built-in) | Pyright LSP |
148
+ | **Go, Rust, etc.** | Basic linting | Full LSP support |
149
+
150
+ **Recommendation:** Use `pi` for TypeScript/Python projects. Use `pi --lens-lsp` for multi-language projects or when you need full language server features.
151
+
152
+ See [docs/LSP_CONFIG.md](docs/LSP_CONFIG.md) for configuration options.
153
+
154
+ ---
155
+
156
+ ### On every write / edit
157
+
158
+ Every file write/edit triggers multiple analysis phases:
159
+
160
+ **Execution flow:**
161
+ 1. **Secrets scan** (pre-flight) — Hardcoded secrets block immediately (non-runner check)
162
+ 2. **LSP integration** (Phase 3, with `--lens-lsp`) — Real-time type errors from language servers
163
+ 3. **Dispatch system** — Routes file to appropriate runners by `FileKind`
164
+ 4. **Runners execute** by priority (lower = earlier). See [Runners](#runners) section for full list.
165
+ 5. **Test runner detection** (post-write) — Detects Jest/Vitest/Pytest and runs relevant tests
166
+
167
+ **Delta mode behavior:**
168
+ - **First write:** All issues tracked and stored in baseline
169
+ - **Subsequent edits:** Only **NEW** issues shown (pre-existing issues filtered out)
170
+ - **Goal:** Don't spam agent with issues they didn't cause
171
+
172
+ **Output shown inline:**
173
+ ```
174
+ STOP — 1 issue(s) must be fixed:
175
+ L23: var total = sum(items); — use 'let' or 'const'
176
+ ```
177
+
178
+ > **Note:** Only **blocking** issues (`ts-lsp`, `pyright` errors, `type-safety` switch errors, secrets) appear inline. Warnings are tracked but not shown inline (noise reduction) — run `/lens-booboo` to see all warnings.
179
+
180
+ ---
181
+
182
+ ### Runners
183
+
184
+ pi-lens uses a **dispatcher-runner architecture** for extensible multi-language support. Runners are executed by priority (lower = earlier).
185
+
186
+ | Runner | Language | Priority | Output | Description |
187
+ |--------|----------|----------|--------|-------------|
188
+ | **ts-lsp** | TypeScript | 5 | Blocking | TypeScript errors (hard stops) |
189
+ | **pyright** | Python | 5 | Blocking | Python type errors (hard stops) |
190
+ | **biome** | TS/JS | 10 | Warning | Linting issues (delta-tracked) |
191
+ | **ruff** | Python | 10 | Warning | Python linting (delta-tracked) |
192
+ | **oxlint** | TS/JS | 12 | Warning | Fast Rust-based JS/TS linter |
193
+ | **tree-sitter** | TS/JS, Python | 14 | Mixed | AST-based structural analysis (21 patterns) — **singleton WASM client** |
194
+ | **ast-grep-napi** | TS/JS | 15 | Blocking | Security rules inline (no-eval, jwt-no-verify, no-hardcoded-secrets, etc.) |
195
+ | **type-safety** | TS | 20 | Mixed | Switch exhaustiveness (blocking), other (warning) |
196
+ | **shellcheck** | Shell | 20 | Warning | Bash/sh/zsh/fish linting |
197
+ | **python-slop** | Python | 25 | Warning | AI slop detection (~40 patterns) |
198
+ | **spellcheck** | Markdown | 30 | Warning | Typo detection in docs |
199
+ | **similarity** | TS | 35 | Warning | Semantic duplicate detection (structural similarity) |
200
+ | **architect** | All | 40 | Warning | Architectural rule violations |
201
+ | **go-vet** | Go | 50 | Warning | Go static analysis |
202
+ | **rust-clippy** | Rust | 50 | Warning | Rust linting |
203
+
204
+ **Priority legend:**
205
+ - **5** — Type checkers (blocking errors)
206
+ - **10-15** — Linters and structural analysis
207
+ - **20-30** — Specialized checks (safety, slop, spellcheck)
208
+ - **35** — Metrics only (silent)
209
+ - **40-50** — Language-specific and architectural
210
+
211
+ **Output semantics:**
212
+ - **Blocking** — Hard stop, must fix (type errors, secrets)
213
+ - **Warning** — Shown in `/lens-booboo`, not inline (noise reduction)
214
+ - **Silent** — Tracked in metrics only, never shown
215
+
216
+ **Consolidated runners:** `ts-slop` merged into `ast-grep-napi` — CLI ast-grep used for full linter via `/lens-booboo`
217
+
218
+ **Tree-sitter runner patterns** (priority 14, AST-based structural analysis):
219
+
220
+ TypeScript/JavaScript (13 patterns):
221
+ - **Error**: empty-catch, hardcoded-secrets, eval
222
+ - **Warning**: debugger, await-in-loop, console-statement, long-parameter-list, nested-ternary, deep-promise-chain, mixed-async-styles, deep-nesting, constructor-super, no-dupe-class-members
223
+
224
+ TSX (2 patterns):
225
+ - **Error**: dangerously-set-inner-html
226
+ - **Warning**: no-nested-links
227
+
228
+ Python (6 patterns):
229
+ - **Error**: bare-except, mutable-default-arg, eval-exec, unreachable-except
230
+ - **Warning**: wildcard-import, is-vs-equals
231
+
232
+ **Custom tree-sitter queries:** Add `.yml` files to `.pi-lens/rules/tree-sitter-queries/{typescript,python}/`
233
+
234
+ **AI Slop Detection:**
235
+ - `python-slop` runner (priority 25): ~40 patterns for Python code quality
236
+ - `ast-grep-napi` runner (priority 15): Security rules fire inline (blocking); slop/architecture warnings via `/lens-booboo` only. Skips 5 rules already covered by tree-sitter.
237
+
238
+ ---
239
+
240
+ ### Additional Safeguards
241
+
242
+ Safeguards that run **before** the dispatch system:
243
+
244
+ #### Secrets Scanning (Pre-flight)
245
+
246
+ Runs on every file write/edit **before** any other checks. Scans for:
247
+ - Stripe/OpenAI keys (`sk-*`)
248
+ - GitHub tokens (`ghp_*`, `github_pat_*`)
249
+ - AWS keys (`AKIA*`)
250
+ - Slack tokens (`xoxb-*`, `xoxp-*`)
251
+ - Private keys (`BEGIN PRIVATE KEY`)
252
+ - Hardcoded passwords and API keys
253
+
254
+ **Behavior:** Always blocking, always runs on all file types. Cannot be disabled — security takes precedence.
255
+
256
+ #### Agent Behavior Warnings
257
+
258
+ Inline heuristics to catch anti-patterns in real-time:
259
+
260
+ **Blind Write Detection**
261
+ - **Triggers:** Agent edits a file without reading it in the last 5 tool calls
262
+ - **Warning:** `BLIND WRITE — editing 'file.ts' without reading in the last 5 tool calls.`
263
+ - **Why:** Prevents edits based on stale assumptions
264
+
265
+ **Thrashing Detection**
266
+ - **Triggers:** 3+ consecutive identical tool calls within 30 seconds
267
+ - **Warning:** `[!] THRASHING — 3 consecutive 'edit' calls with no other action.`
268
+ - **Why:** Catches stuck loops where the agent repeats failed actions
269
+
270
+ **Behavior:** Warnings appear inline but do **not** block execution.
271
+
272
+ #### Custom ast-grep Rules
273
+
274
+ Create your own structural rules in `.pi-lens/rules/`:
275
+
276
+ ```yaml
277
+ # .pi-lens/rules/no-console-prod.yml
278
+ id: no-console-prod
279
+ language: javascript
280
+ rule:
281
+ pattern: console.$METHOD($$$ARGS)
282
+ message: "Remove console statements before production"
283
+ severity: warning
284
+ ```
285
+
286
+ See [AST_GREP_RULES.md](AST_GREP_RULES.md) for full guide.
287
+
288
+ ---
289
+
290
+ ### At Session Start
291
+
292
+ When pi starts a new session, pi-lens performs initialization scans to establish baselines and surface existing technical debt:
293
+
294
+ **Initialization sequence:**
295
+ 1. **Reset session state** — Clear metrics and complexity baselines
296
+ 2. **Initialize LSP** (with `--lens-lsp`) — Detect and auto-install language servers
297
+ 3. **Pre-install TypeScript LSP** (with `--lens-lsp`) — Warm up cache for instant response
298
+ 4. **Detect available tools** — Biome, ast-grep, Ruff, Knip, jscpd, Madge, type-coverage, Go, Rust
299
+ 5. **Load architect rules** — If `architect.yml` or `.architect.yml` present
300
+ 6. **Detect test runner** — Jest, Vitest, Pytest, etc.
301
+
302
+ **Cached scans** (with 5-min TTL):
303
+ | Scan | Tool | Cached | Purpose |
304
+ |------|------|--------|---------|
305
+ | **TODOs** | Internal | No | Tech debt markers |
306
+ | **Dead code** | Knip | Yes | Unused exports/files/deps |
307
+ | **Duplicates** | jscpd | Yes | Copy-paste detection |
308
+ | **Exports** | ast-grep | No | Function index for similarity |
309
+
310
+ **Error debt tracking** (with `--error-debt` flag):
311
+ - If tests passed at end of previous session but fail now → **regression detected**
312
+ - Blocks agent until tests pass again
313
+
314
+ **Output:** Scan results appear in session startup notification
315
+
316
+ ---
317
+
318
+ ### Code Review
319
+
320
+ ```
321
+ /lens-booboo [path]
322
+ ```
323
+
324
+ Full codebase analysis with **10 tracked runners** producing a comprehensive report:
325
+
326
+ | # | Runner | What it finds |
327
+ |---|--------|---------------|
328
+ | 1 | **ast-grep (design smells)** | Structural issues (empty catch, no-debugger, etc.) |
329
+ | 2 | **ast-grep (similar functions)** | Duplicate function patterns across files |
330
+ | 3 | **semantic similarity (Amain)** | 57×72 matrix semantic clones (>75% similarity) |
331
+ | 4 | **complexity metrics** | Low MI, high cognitive complexity, AI slop indicators |
332
+ | 5 | **TODO scanner** | TODO/FIXME annotations and tech debt markers |
333
+ | 6 | **dead code (Knip)** | Unused exports, files, dependencies |
334
+ | 7 | **duplicate code (jscpd)** | Copy-paste blocks with line/token counts |
335
+ | 8 | **type coverage** | Percentage typed vs `any`, low-coverage files |
336
+ | 9 | **circular deps (Madge)** | Import cycles and dependency chains |
337
+ | 10 | **architectural rules** | Layer violations, file size limits, path rules |
338
+
339
+ **Output:**
340
+ - **Terminal:** Progress `[1/10] runner...` with timing, summary with findings per runner
341
+ - **JSON:** `.pi-lens/reviews/booboo-{timestamp}.json` (structured data for AI processing)
342
+ - **Markdown:** `.pi-lens/reviews/booboo-{timestamp}.md` (human-readable report)
343
+
344
+ **Usage:**
345
+ ```bash
346
+ /lens-booboo # Scan current directory
347
+ /lens-booboo ./src # Scan specific path
348
+ ```
349
+
350
+ ---
351
+
352
+ ### Test Runner
353
+
354
+ **Auto-detected test runners:**
355
+ | Runner | Config Files | Languages |
356
+ |--------|--------------|-----------|
357
+ | **Vitest** | `vitest.config.ts`, `vitest.config.js` | TypeScript, JavaScript |
358
+ | **Jest** | `jest.config.js`, `jest.config.ts`, `package.json` (jest field) | TypeScript, JavaScript |
359
+ | **Pytest** | `pytest.ini`, `setup.cfg`, `pyproject.toml` | Python |
360
+
361
+ **Behavior:**
362
+ - **On file write:** Detects corresponding test file and runs it
363
+ - **Pattern matching:** `file.ts` → `file.test.ts` or `__tests__/file.test.ts`
364
+ - **Output:** Inline pass/fail with failure details (shown with lint results)
365
+ - **Flag:** Use `--no-tests` to disable automatic test running
366
+
367
+ **Execution flow:**
368
+ 1. Agent writes `src/utils.ts`
369
+ 2. pi-lens finds `src/utils.test.ts` (or `__tests__/utils.test.ts`)
370
+ 3. Runs only that test file (not full suite)
371
+ 4. Results appear inline:
372
+ ```
373
+ [tests] 3 passed, 1 failed (42ms)
374
+ ✓ should calculate total
375
+ ✗ should handle empty array (expected 0, got undefined)
376
+ ```
377
+
378
+ **Why only corresponding tests?**
379
+ Running the full suite on every edit would be too slow. Targeted testing gives immediate feedback for the code being edited.
380
+
381
+ ---
382
+
383
+ ### Complexity Metrics
384
+
385
+ pi-lens tracks code quality metrics for every file:
386
+
387
+ | Metric | Description | Threshold |
388
+ |--------|-------------|-----------|
389
+ | **Maintainability Index** | 0-100 composite score | >60 good <20 bad |
390
+ | **Cognitive Complexity** | Mental effort to understand | >20 warn >50 bad |
391
+ | **Cyclomatic Complexity** | Independent code paths | >10 warn >20 bad |
392
+ | **Code Entropy** | Shannon entropy in bits | >4.0 warn >7.0 bad |
393
+
394
+ **Commands:**
395
+ - `/lens-tdi` — Technical Debt Index (0-100) with grades A-F
396
+ - `/lens-booboo` — Full complexity table for all files
397
+
398
+ See [docs/COMPLEXITY_METRICS.md](docs/COMPLEXITY_METRICS.md) for formulas and detailed calculations.
399
+
400
+ ---
401
+
402
+ ## Dependent Tools
403
+
404
+ pi-lens works out of the box for TypeScript/JavaScript. For full language support, install these tools — **all are optional and gracefully skip if not installed**:
405
+
406
+ ### JavaScript / TypeScript
407
+
408
+ | Tool | Install | What it does |
409
+ |------|---------|--------------|
410
+ | `@biomejs/biome` | `npm i -D @biomejs/biome` | Linting + formatting |
411
+ | `oxlint` | `npm i -D oxlint` | Fast Rust-based JS/TS linting |
412
+ | `knip` | `npm i -D knip` | Dead code / unused exports |
413
+ | `jscpd` | `npm i -D jscpd` | Copy-paste detection |
414
+ | `type-coverage` | `npm i -D type-coverage` | TypeScript `any` coverage % |
415
+ | `@ast-grep/napi` | `npm i -D @ast-grep/napi` | Fast structural analysis (TS/JS) — security rules inline, slop in booboo |
416
+ | `@ast-grep/cli` | `npm i -D @ast-grep/cli` | Structural pattern matching (all languages) |
417
+ | `typos-cli` | `cargo install typos-cli` | Spellcheck for Markdown |
418
+
419
+ ### Python
420
+
421
+ | Tool | Install | What it does |
422
+ |------|---------|--------------|
423
+ | `ruff` | `pip install ruff` | Linting + formatting |
424
+ | `pyright` | `pip install pyright` | Type-checking (catches type errors) |
425
+
426
+ ### Go
427
+
428
+ | Tool | Install | What it does |
429
+ |------|---------|--------------|
430
+ | `go` | [golang.org](https://golang.org) | Built-in `go vet` for static analysis |
431
+
432
+ ### Rust
433
+
434
+ | Tool | Install | What it does |
435
+ |------|---------|--------------|
436
+ | `rust` + `clippy` | [rustup.rs](https://rustup.rs) | Linting via `cargo clippy` |
437
+
438
+ ### Shell
439
+
440
+ | Tool | Install | What it does |
441
+ |------|---------|--------------|
442
+ | `shellcheck` | `apt install shellcheck` / `brew install shellcheck` | Shell script linting (bash/sh/zsh/fish) |
443
+
444
+ ---
445
+
446
+ ## Commands
447
+
448
+ | Command | Description |
449
+ |---------|-------------|
450
+ | `/lens-booboo` | Full codebase review (10 analysis runners) |
451
+ | `/lens-tdi` | Technical Debt Index and trends |
452
+
453
+ ---
454
+
455
+ ## Execution Modes
456
+
457
+ | Mode | Command | What happens |
458
+ |------|---------|--------------|
459
+ | **Standard** (default) | `pi` | Auto-formatting, TS/Python type-checking, sequential execution |
460
+ | **Full LSP** | `pi --lens-lsp` | Real LSP servers (31 languages), sequential execution |
461
+
462
+
463
+ ### Flag Reference
464
+
465
+ | Flag | Description |
466
+ |------|-------------|
467
+ | `--lens-lsp` | Use real Language Server Protocol servers instead of built-in type-checking |
468
+ | `--lens-verbose` | Enable detailed console logging |
469
+ | `--no-autoformat` | Disable automatic formatting (formatting is **enabled by default**) |
470
+ | `--no-autofix` | Disable all auto-fixing (Biome safe fixes + Ruff autofix **enabled by default**). Unsafe fixes (e.g. removing unused vars) are never applied automatically — use `/lens-booboo` with explicit confirmation. |
471
+ | `--no-autofix-biome` | Disable Biome auto-fix only |
472
+ | `--no-autofix-ruff` | Disable Ruff auto-fix only |
473
+ | `--no-oxlint` | Skip Oxlint linting |
474
+ | `--no-shellcheck` | Skip shellcheck for shell scripts |
475
+ | `--no-tests` | Disable automatic test running on file write |
476
+ | `--no-madge` | Skip circular dependency checks |
477
+ | `--no-ast-grep` | Skip ast-grep structural analysis |
478
+ | `--no-biome` | Skip Biome linting |
479
+ | `--no-lsp` | Skip TypeScript/Python type checking |
480
+ | `--error-debt` | Track test regressions across sessions |
481
+
482
+ **Recommended combinations:**
483
+ ```bash
484
+ pi # Default: auto-format, auto-fix, built-in type-checking
485
+ pi --lens-lsp # LSP type-checking (31 languages)
486
+ ```
487
+
488
+ ---
489
+
490
+ ## TypeScript LSP — tsconfig detection
491
+
492
+ The LSP walks up from edited files to find `tsconfig.json`, using its `compilerOptions` (paths, strict settings, etc.). Falls back to sensible defaults if not found.
493
+
494
+ ---
495
+
496
+ ## Project Structure
497
+
498
+ ```
499
+ pi-lens/
500
+ ├── clients/ # Lint tools, LSP clients, formatters
501
+ ├── commands/ # /lens-booboo, /lens-format commands
502
+ ├── docs/ # Documentation
503
+ ├── rules/ # AST-grep rules
504
+ ├── skills/ # Built-in pi skills
505
+ ├── index.ts # Main extension entry point
506
+ └── package.json
507
+ ```
508
+
509
+ See source for detailed structure.
510
+
511
+ ---
512
+
513
+ ## Skills
514
+
515
+ pi-lens includes two built-in skills that guide the LLM on when to use specific tools:
516
+
517
+ ### ast-grep
518
+
519
+ **Purpose:** Guide AST-aware pattern matching for semantic code search/replace.
520
+
521
+ **When to load:** Use `/skill:ast-grep` when performing structural code searches (finding function calls, class methods, imports) or replacements across files.
522
+
523
+ **Key guidance:**
524
+ - Use `$VAR` for single nodes, `$$$` for multiple
525
+ - Patterns must be **complete valid code** (not fragments)
526
+ - **Workflow:** Search → Dry-run (`apply: false`) → Apply (`apply: true`)
527
+ - **Error "Multiple AST nodes":** Use metavariables like `it($TEST)` not raw text like `it"test"`
528
+
529
+ ```typescript
530
+ // GOOD: Complete code with metavariables
531
+ ast_grep_search
532
+ pattern: "console.log($MSG)"
533
+ lang: typescript
534
+ paths: ["src/"]
535
+
536
+ // BAD: BAD: Incomplete pattern
537
+ pattern: "console.log(" // Missing args/body
538
+ ```
539
+
540
+ ### lsp-navigation
541
+
542
+ **Purpose:** Guide code intelligence via Language Server Protocol.
543
+
544
+ **When to load:** Use `/skill:lsp-navigation` for understanding code structure — definitions, references, types, call hierarchy.
545
+
546
+ **Key guidance:**
547
+ - **LSP is PRIMARY** for code intelligence — NOT grep/glob/ast-grep
548
+ - Requires `--lens-lsp` flag
549
+ - Call hierarchy: `prepareCallHierarchy` → `incomingCalls`/`outgoingCalls`
550
+
551
+ | Task | Use LSP | Use Other |
552
+ |------|---------|-----------|
553
+ | "Where is this defined?" | `definition` | — |
554
+ | "Find all usages" | `references` | — |
555
+ | "What type is this?" | `hover` | — |
556
+ | "Who calls this function?" | `prepareCallHierarchy` → `incomingCalls` | — |
557
+ | Find patterns (console.log) | — | `ast_grep_search` |
558
+ | Find TODO comments | — | `grep` |
559
+
560
+ ```typescript
561
+ // Code intelligence → LSP
562
+ lsp_navigation
563
+ operation: "references"
564
+ filePath: "src/utils.ts"
565
+ line: 42
566
+ character: 10
567
+
568
+ // BAD: Don't use LSP for text patterns
569
+ pattern: "TODO" // Use grep instead
570
+ ```
571
+
572
+ ---
573
+
574
+ ## Changelog
575
+
576
+ See [CHANGELOG.md](CHANGELOG.md) for full history.
577
+
578
+ ### Latest Highlights
579
+
580
+ - **Tree-sitter Query Cache:** Compiled query cache with mtime-based invalidation — 10× faster structural analysis startup
581
+ - **LSP Support:** 31 Language Server Protocol clients (4 core auto-installed, others via npx or manual)
582
+ - **NAPI Runner:** 100x faster TypeScript/JavaScript structural analysis (~9ms vs ~1200ms) — security rules fire inline
583
+ - **Slop Detection:** 33+ TypeScript and 40+ Python patterns for AI-generated code quality issues
584
+
585
+ ---
586
+
587
+ ## License
588
+
589
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-lens",
3
- "version": "3.6.4",
3
+ "version": "3.6.5",
4
4
  "type": "module",
5
5
  "description": "Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo",
6
6
  "repository": {