Skip to content

Commit d41ed02

Browse files
committed
feat(skills): add esm-interop and external-bundles scans to quality-scan
Rewrites quality-scan skill based on socket-sdk-js template, tailored for socket-lib as a core infrastructure library. New scan types: - esm-interop: Verifies Node.js ESM/CJS interoperability, focusing on the critical `0 && (module.exports = {...})` annotation that enables named imports from CommonJS modules - external-bundles: Checks vendored dependencies in dist/external/ for: - Hidden require() calls to unbundled npm packages - Duplicate bundled code across bundles - Missing pnpm overrides/catalog for deduplication All agent prompts follow Claude best practices with <context>, <instructions>, <pattern>, <output_format>, and <quality_guidelines> tags.
1 parent 9c4ac0b commit d41ed02

2 files changed

Lines changed: 843 additions & 722 deletions

File tree

.claude/skills/quality-scan/SKILL.md

Lines changed: 72 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
11
---
22
name: quality-scan
3-
description: Cleans up junk files (SCREAMING_TEXT.md, temp files) and performs comprehensive quality scans across codebase to identify critical bugs, logic errors, caching issues, and workflow problems. Spawns specialized agents for targeted analysis and generates prioritized improvement tasks. Use when improving code quality, before releases, or investigating issues.
3+
description: Cleans up junk files (SCREAMING_TEXT.md, temp files) and performs comprehensive quality scans across codebase to identify critical bugs, logic errors, ESM/CJS interop issues, and workflow problems. Spawns specialized agents for targeted analysis and generates prioritized improvement tasks. Use when improving code quality, before releases, or investigating issues. (project)
44
---
55

66
# quality-scan
77

88
<task>
9-
Your task is to perform comprehensive quality scans across the socket-btm codebase using specialized agents to identify critical bugs, logic errors, caching issues, and workflow problems. Before scanning, clean up junk files (SCREAMING_TEXT.md files, temporary test files, etc.) to ensure a clean and organized repository. Generate a prioritized report with actionable improvement tasks.
9+
Your task is to perform comprehensive quality scans across the socket-lib codebase using specialized agents to identify critical bugs, logic errors, ESM/CJS interop issues, and workflow problems. Before scanning, clean up junk files to ensure a clean and organized repository. Generate a prioritized report with actionable improvement tasks.
1010
</task>
1111

1212
<context>
1313
**What is Quality Scanning?**
1414
Quality scanning uses specialized AI agents to systematically analyze code for different categories of issues. Each agent type focuses on specific problem domains and reports findings with severity levels and actionable fixes.
1515

16-
**socket-btm Architecture:**
17-
This is Socket Security's binary tooling manager (BTM) that:
18-
- Builds custom Node.js binaries with Socket Security patches
19-
- Manages Node.js versions and patch synchronization
20-
- Produces minimal Node.js builds (node-smol-builder)
21-
- Processes upstream Node.js source code and applies security patches
22-
- Supports production deployments with patched Node.js
16+
**socket-lib Architecture:**
17+
This is Socket Security's core infrastructure library that:
18+
- Provides shared utilities for all Socket.dev security tools
19+
- Implements HTTP client, file system utilities, logging, and spawning
20+
- Exports CommonJS modules with ESM interop annotations for Node.js compatibility
21+
- Uses TypeScript compiled via esbuild to CommonJS
22+
- Provides typed environment variable access and path utilities
23+
- Supports cross-platform operations (Windows, macOS, Linux)
2324

2425
**Scan Types Available:**
2526
1. **critical** - Crashes, security vulnerabilities, resource leaks, data corruption
2627
2. **logic** - Algorithm errors, edge cases, type guards, off-by-one errors
27-
3. **cache** - Cache staleness, race conditions, invalidation bugs
28-
4. **workflow** - Build scripts, CI issues, cross-platform compatibility
29-
5. **security** - GitHub Actions workflow security (zizmor scanner)
30-
6. **documentation** - README accuracy, outdated docs, missing documentation
28+
3. **workflow** - Build scripts, CI issues, cross-platform compatibility
29+
4. **security** - GitHub Actions workflow security (zizmor scanner)
30+
5. **documentation** - README accuracy, outdated docs, missing documentation
31+
6. **esm-interop** - Node.js ESM/CJS interoperability, named exports, module format hints
32+
7. **external-bundles** - Vendored external dependencies: hidden requires, duplicate bundles, deduplication via pnpm overrides/catalog
3133

3234
**Why Quality Scanning Matters:**
3335
- Catches bugs before they reach production
3436
- Identifies security vulnerabilities early
3537
- Improves code quality systematically
3638
- Provides actionable fixes with file:line references
3739
- Prioritizes issues by severity for efficient remediation
40+
- Ensures ESM/CJS interop works for all consumers
3841
- Cleans up junk files for a well-organized repository
3942

4043
**Agent Prompts:**
@@ -45,7 +48,7 @@ All agent prompts are embedded in `reference.md` with structured <context>, <ins
4548
**CRITICAL Requirements:**
4649
- Read-only analysis (no code changes during scan)
4750
- Must complete all enabled scans before reporting
48-
- Findings must be prioritized by severity (Critical High Medium Low)
51+
- Findings must be prioritized by severity (Critical -> High -> Medium -> Low)
4952
- Must generate actionable tasks with file:line references
5053
- All findings must include suggested fixes
5154

@@ -56,7 +59,7 @@ All agent prompts are embedded in `reference.md` with structured <context>, <ins
5659
- Proceed if codebase has uncommitted changes (warn but continue)
5760

5861
**Do ONLY:**
59-
- Run enabled scan types in priority order (critical logic → cache → workflow)
62+
- Run enabled scan types in priority order (critical -> logic -> esm-interop -> workflow)
6063
- Generate structured findings with severity levels
6164
- Provide actionable improvement tasks with specific code changes
6265
- Report statistics and coverage metrics
@@ -177,32 +180,34 @@ Ask user which scans to run:
177180
**Default Scan Types** (run all unless user specifies):
178181
1. **critical** - Critical bugs (crashes, security, resource leaks)
179182
2. **logic** - Logic errors (algorithms, edge cases, type guards)
180-
3. **cache** - Caching issues (staleness, races, invalidation)
181-
4. **workflow** - Workflow problems (scripts, CI, git hooks)
182-
5. **security** - GitHub Actions security (template injection, cache poisoning, etc.)
183-
6. **documentation** - Documentation accuracy (README errors, outdated docs)
183+
3. **workflow** - Workflow problems (scripts, CI, git hooks)
184+
4. **security** - GitHub Actions security (template injection, cache poisoning, etc.)
185+
5. **documentation** - Documentation accuracy (README errors, outdated docs)
186+
6. **esm-interop** - ESM/CJS compatibility (named exports, module format hints)
187+
7. **external-bundles** - External bundle integrity (hidden requires, duplicates, deduplication)
184188

185189
**User Interaction:**
186190
Use AskUserQuestion tool:
187191
- Question: "Which quality scans would you like to run?"
188192
- Header: "Scan Types"
189193
- multiSelect: true
190194
- Options:
191-
- "All scans (recommended)" Run all 4 scan types
192-
- "Critical only" Run critical scan only
193-
- "Critical + Logic" Run critical and logic scans
194-
- "Custom selection" Ask user to specify which scans
195+
- "All scans (recommended)" -> Run all scan types
196+
- "Critical only" -> Run critical scan only
197+
- "Critical + Logic" -> Run critical and logic scans
198+
- "Custom selection" -> Ask user to specify which scans
195199

196200
**Default:** If user doesn't specify, run all scans.
197201

198202
<validation>
199203
Validate selected scan types exist in reference.md:
200-
- critical-scan → reference.md line ~5
201-
- logic-scan → reference.md line ~100
202-
- cache-scan → reference.md line ~200
203-
- workflow-scan → reference.md line ~300
204-
- security-scan → reference.md line ~400
205-
- documentation-scan → reference.md line ~810
204+
- critical-scan -> reference.md line ~5
205+
- logic-scan -> reference.md line ~150
206+
- workflow-scan -> reference.md line ~300
207+
- security-scan -> reference.md line ~450
208+
- documentation-scan -> reference.md line ~600
209+
- esm-interop-scan -> reference.md line ~800
210+
- external-bundles-scan -> reference.md line ~1000
206211

207212
If user requests non-existent scan type, report error and suggest valid types.
208213
</validation>
@@ -222,10 +227,18 @@ Task({
222227
description: "Critical bugs scan",
223228
prompt: `${CRITICAL_SCAN_PROMPT_FROM_REFERENCE_MD}
224229
225-
Focus on packages/node-smol-builder/ directory and root-level scripts/.
230+
Focus on src/ directory (utilities, HTTP client, file system operations).
231+
232+
Library-specific patterns to check:
233+
- HTTP client error handling (src/http-request.ts)
234+
- File system operations (src/fs.ts)
235+
- Spawn utilities (src/spawn.ts)
236+
- Promise handling and retry logic
237+
- JSON parsing errors
238+
- Cross-platform path handling
226239
227240
Report findings in this format:
228-
- File: path/to/file.mts:lineNumber
241+
- File: path/to/file.ts:lineNumber
229242
- Issue: Brief description
230243
- Severity: Critical/High/Medium/Low
231244
- Pattern: Code snippet
@@ -239,58 +252,34 @@ Scan systematically and report all findings. If no issues found, state that expl
239252

240253
**For each scan:**
241254
1. Load agent prompt template from `reference.md`
242-
2. Customize for socket-btm context (focus on packages/node-smol-builder/, scripts/, patches/)
255+
2. Customize for socket-lib context (focus on src/, scripts/, test/)
243256
3. Spawn agent with Task tool using "general-purpose" subagent_type
244257
4. Capture findings from agent response
245258
5. Parse and categorize results
246259

247260
**Execution Order:** Run scans sequentially in priority order:
248261
- critical (highest priority)
249262
- logic
250-
- cache
251-
- workflow (lowest priority)
263+
- esm-interop
264+
- external-bundles
265+
- workflow
266+
- security
267+
- documentation (lowest priority)
252268

253269
**Agent Prompt Sources:**
254270
- Critical scan: reference.md starting at line ~12
255-
- Logic scan: reference.md starting at line ~100
256-
- Cache scan: reference.md starting at line ~200
271+
- Logic scan: reference.md starting at line ~150
257272
- Workflow scan: reference.md starting at line ~300
258-
- Security scan: reference.md starting at line ~400
259-
- Documentation scan: reference.md starting at line ~810
273+
- Security scan: reference.md starting at line ~450
274+
- Documentation scan: reference.md starting at line ~600
275+
- ESM interop scan: reference.md starting at line ~800
276+
- External bundles scan: reference.md starting at line ~1000
260277

261278
<validation>
262279
**Structured Output Validation:**
263280

264281
After each agent returns, validate output structure before parsing:
265282

266-
```bash
267-
# 1. Verify agent completed successfully
268-
if [ -z "$AGENT_OUTPUT" ]; then
269-
echo "ERROR: Agent returned no output"
270-
exit 1
271-
fi
272-
273-
# 2. Check for findings or clean report
274-
if ! echo "$AGENT_OUTPUT" | grep -qE '(File:.*Issue:|No .* issues found|✓ Clean)'; then
275-
echo "WARNING: Agent output missing expected format"
276-
echo "Agent may have encountered an error or found no issues"
277-
fi
278-
279-
# 3. Verify severity levels if findings exist
280-
if echo "$AGENT_OUTPUT" | grep -q "File:"; then
281-
if ! echo "$AGENT_OUTPUT" | grep -qE 'Severity: (Critical|High|Medium|Low)'; then
282-
echo "WARNING: Findings missing severity classification"
283-
fi
284-
fi
285-
286-
# 4. Verify fix suggestions if findings exist
287-
if echo "$AGENT_OUTPUT" | grep -q "File:"; then
288-
if ! echo "$AGENT_OUTPUT" | grep -q "Fix:"; then
289-
echo "WARNING: Findings missing suggested fixes"
290-
fi
291-
fi
292-
```
293-
294283
**Manual Verification Checklist:**
295284
- [ ] Agent output includes findings OR explicit "No issues found" statement
296285
- [ ] All findings include file:line references
@@ -316,7 +305,7 @@ Collect all findings from agents and aggregate:
316305

317306
```typescript
318307
interface Finding {
319-
file: string // "packages/node-smol-builder/src/patcher.mts:89"
308+
file: string // "src/http-request.ts:89"
320309
issue: string // "Potential null pointer access"
321310
severity: "Critical" | "High" | "Medium" | "Low"
322311
scanType: string // "critical"
@@ -333,7 +322,7 @@ interface Finding {
333322
- Track which scans found the same issue
334323

335324
**Prioritization:**
336-
- Sort by severity: Critical High Medium Low
325+
- Sort by severity: Critical -> High -> Medium -> Low
337326
- Within same severity, sort by scanType priority
338327
- Within same severity+scanType, sort alphabetically by file path
339328

@@ -357,19 +346,19 @@ Create structured quality report with all findings:
357346
# Quality Scan Report
358347

359348
**Date:** YYYY-MM-DD
360-
**Repository:** socket-btm
349+
**Repository:** socket-lib
361350
**Scans:** [list of scan types run]
362351
**Files Scanned:** N
363352
**Findings:** N critical, N high, N medium, N low
364353

365354
## Critical Issues (Priority 1) - N found
366355

367-
### packages/node-smol-builder/src/patcher.mts:89
368-
- **Issue**: Potential null pointer access when applying patches
369-
- **Pattern**: `const result = patches[index].apply()`
370-
- **Trigger**: When patch array has fewer elements than expected
371-
- **Fix**: `const patch = patches[index]; if (!patch) throw new Error('Patch not found'); const result = patch.apply()`
372-
- **Impact**: Crashes patch application process, build fails
356+
### src/http-request.ts:89
357+
- **Issue**: Potential null pointer access in retry logic
358+
- **Pattern**: `const result = response.data.items[0]`
359+
- **Trigger**: When API returns empty array
360+
- **Fix**: `const items = response.data?.items ?? []; if (items.length === 0) throw new Error('No items found'); const result = items[0]`
361+
- **Impact**: Crashes library, breaks consumer applications
373362
- **Scan**: critical
374363

375364
## High Issues (Priority 2) - N found
@@ -386,15 +375,15 @@ Create structured quality report with all findings:
386375

387376
## Scan Coverage
388377

389-
- **Critical scan**: N files analyzed in packages/node-smol-builder/, scripts/
390-
- **Logic scan**: N files analyzed (patch logic, build scripts)
391-
- **Cache scan**: N files analyzed (if applicable)
378+
- **Critical scan**: N files analyzed in src/
379+
- **Logic scan**: N files analyzed (utilities, HTTP client)
380+
- **ESM interop scan**: N dist files analyzed
392381
- **Workflow scan**: N files analyzed (package.json, scripts/, .github/)
393382

394383
## Recommendations
395384

396385
1. Address N critical issues immediately before next release
397-
2. Review N high-severity logic errors in patch application
386+
2. Review N high-severity logic errors in utilities
398387
3. Schedule N medium issues for next sprint
399388
4. Low-priority items can be addressed during refactoring
400389

@@ -465,7 +454,7 @@ All findings include file:line references and suggested fixes.
465454

466455
-`<promise>QUALITY_SCAN_COMPLETE</promise>` output
467456
- ✅ All enabled scans completed without errors
468-
- ✅ Findings prioritized by severity (Critical Low)
457+
- ✅ Findings prioritized by severity (Critical -> Low)
469458
- ✅ All findings include file:line references
470459
- ✅ Actionable suggestions provided for all findings
471460
- ✅ Report generated with statistics and coverage metrics
@@ -477,10 +466,11 @@ See `reference.md` for detailed agent prompts with structured tags:
477466

478467
- **critical-scan** - Null access, promise rejections, race conditions, resource leaks
479468
- **logic-scan** - Off-by-one errors, type guards, edge cases, algorithm correctness
480-
- **cache-scan** - Invalidation, key generation, memory management, concurrency
481469
- **workflow-scan** - Scripts, package.json, git hooks, CI configuration
482470
- **security-scan** - GitHub Actions workflow security (runs zizmor scanner)
483471
- **documentation-scan** - README accuracy, outdated examples, incorrect package names, missing documentation
472+
- **esm-interop-scan** - Node.js ESM/CJS interop, named exports, module format hints, dual-format compatibility
473+
- **external-bundles-scan** - Vendored dependencies integrity, hidden requires to node_modules, duplicate bundles, pnpm overrides/catalog deduplication
484474

485475
All agent prompts follow Claude best practices with <context>, <instructions>, <pattern>, <output_format>, and <quality_guidelines> tags.
486476

@@ -490,7 +480,7 @@ This skill is self-contained. No external commands needed.
490480

491481
## Context
492482

493-
This skill provides systematic code quality analysis for socket-btm by:
483+
This skill provides systematic code quality analysis for socket-lib by:
494484
- Spawning specialized agents for targeted analysis
495485
- Using Task tool to run agents autonomously
496486
- Embedding agent prompts in reference.md following best practices

0 commit comments

Comments
 (0)