Skip to content

Commit 1491ffe

Browse files
sharon77242claude
andcommitted
feat: implement Phase R Wave 3 — R.7 hot-path column usage analysis and R.8 unhandled DB call detection
- ColumnUsageAnalyzer (R.7): TypeScript AST analyzer that tracks SELECT * hot paths per source line, identifies which fields are actually accessed (map/forEach/filter callbacks, rows[0].field access, destructuring), and emits hot-path-select-star anomalies with specific column lists instead of generic suggestions. Supports rows[n].field element access chains. Auto-wired in db profile for dev/test via profile-factory. - SourceAnalyzer.scanForUnhandledDbCall (R.8): Walks TypeScript source files to find DB calls without try/catch or .catch() chains. Default severity info; escalates to critical when the source line appears in a crashed-lines set from CrashGuard. Integrated into StaticScanner.scan() via runUnhandledDbCallScan(). - 601 tests, 0 TS errors, 0 ESLint errors, Prettier clean. - Demo app: added /debug/hot-select-star (R.7) and /debug/r8-info (R.8) routes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 52b32e6 commit 1491ffe

17 files changed

Lines changed: 1224 additions & 83 deletions

File tree

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
## [Unreleased]
1111

1212
### Added
13+
- **Phase R Wave 3 — Complex codebase-intelligence rules**: Two new rules that require
14+
both runtime observations and TypeScript AST access to produce targeted advice that
15+
generic APMs cannot generate.
16+
- **`hot-path-select-star`** (`warning`) — `ColumnUsageAnalyzer` tracks how many times
17+
a `SELECT *` call fires from the same `sourceLine`. After `threshold` hits (default 5),
18+
it parses the TypeScript source file, finds the variable the result is assigned to, and
19+
walks the containing function scope to collect all accessed field names. The emitted
20+
`hot-path-select-star` anomaly replaces the generic "use explicit columns" suggestion
21+
with e.g. "you only access `id`, `email` — replace with `SELECT id, email`". Supports
22+
`.map()` callbacks, `rows[0].field` element access, and `const { a, b } = rows[0]`
23+
destructuring. Falls back to null (and stays silent) for dynamic patterns or plain JS.
24+
Enabled via `.withColumnUsageAnalysis(dir?, threshold?)`. Auto-wired for `db` app type
25+
in dev/test environments via `profile-factory`.
26+
- **`unhandled-db-call`** (`info` / `critical`) — `SourceAnalyzer.scanForUnhandledDbCall()`
27+
walks the TypeScript AST of every source file and flags DB calls (`query`, `execute`,
28+
`findMany`, `find`, etc.) that have no surrounding `try/catch` and no `.catch()` chain.
29+
Default severity is `info`. When `CrashGuard` feeds in a set of crashed source lines
30+
(lines that have actually thrown `uncaughtException` in production), any finding at a
31+
crashed location is escalated to `critical` with a message that mentions the crash
32+
history. Integrated into `StaticScanner.scan()` via the new `runUnhandledDbCallScan()`
33+
method. Wired into `ArgusAgent` startup scans; crash escalation feeds back from the
34+
`CrashGuard` event stream.
35+
1336
- **Phase R Wave 2 — Static + runtime intelligence rules**: Three new rules that combine
1437
static codebase knowledge with runtime frequency data to surface issues no single monitor
1538
can detect alone.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,11 @@ packages/agent/
729729
circuit-breaker-detector.ts → Sustained error-rate detection across drivers
730730
static-scanner.ts → Background tsc / ESLint / query-in-loop static analysis
731731
audit-scanner.ts → npm audit CVE scanning
732-
source-analyzer.ts → R.4: TypeScript AST scan for DB calls inside loops
732+
source-analyzer.ts → R.4: DB calls inside loops; R.8: unhandled DB calls
733733
migration-scanner.ts → R.5: SQL & Prisma migration parser → index map
734734
index-hint-analyzer.ts → R.5: Runtime high-frequency missing-index detection
735735
route-tracker.ts → R.6: Endpoint-never-called detection after warmup
736+
column-usage-analyzer.ts → R.7: SELECT * hot-path → specific column suggestions
736737
737738
export/
738739
aggregator.ts → p99 sliding window metric aggregation

0 commit comments

Comments
 (0)