Verify Directory Structure — Parallel Audit
This skill provides a systematic approach to diagnosing file access issues and auditing source trees efficiently. It extends basic directory verification with parallel batch file reading (dramatically reducing iteration count when many files must be inspected) and a dedicated TypeScript import validation phase that catches a common class of structural bugs.
Steps
Phase 1 — Directory Verification
Identify Target Paths: Collect every file or directory path involved in the operation. Prefer absolute paths to eliminate ambiguity.
Enumerate with list_dir: Call list_dir on each relevant directory. Record all file names, sizes, and modification dates. This is your ground truth before touching any file.
Verify Existence & Permissions: Confirm the directory exists and that the current user has read (and, if needed, write/execute) permissions. If a directory is missing, create it before proceeding. If permissions are insufficient, adjust them before retrying.
Build a File Manifest: From the list_dir output, compile the complete list of files to be audited. Group them logically (e.g., by subdirectory or file type) so they can be read in parallel batches.
Phase 2 — Parallel Batch File Reading
Why this matters: Reading files sequentially costs one iteration per file. Reading them in parallel batches collapses N files into ⌈N/batch_size⌉ iterations — a significant speedup when auditing dozens of files.
Determine Batch Size: Default to reading 5–10 files per batch. Reduce the batch size if individual files are very large; increase it for small config/index files.
Issue Parallel read_file Calls: Within each batch, invoke read_file for all files simultaneously (a single iteration). Do not wait for one file before requesting the next within the same batch.
Batch 1 (parallel): read_file(src/components/A.tsx)
read_file(src/components/B.tsx)
read_file(src/components/C.tsx)
read_file(src/components/D.tsx)
read_file(src/components/E.tsx)
Batch 2 (parallel): read_file(src/components/F.tsx)
...
Collect & Triage Results: After each batch completes, scan results for errors (file-not-found, permission denied) and flag them immediately. Do not abort the remaining batches; continue and aggregate all findings.
Re-verify Missing Files: For any file reported as missing, re-run list_dir on its parent directory to confirm whether the file truly does not exist or whether the path was wrong. Correct the path and retry the single file if necessary.
Phase 3 — TypeScript Import Validation
This phase targets a common class of structural bugs found when auditing TypeScript source trees.
Identify Import Statements: For every .ts / .tsx file read in Phase 2, extract all import lines.
Classify Import Kind — Value vs. Type:
| Pattern |
Correct usage |
import Foo from '...' |
Runtime value (class, function, object) |
import { Foo } from '...' |
Runtime value export |
import type Foo from '...' |
Type-only import (erased at compile time) |
import type { Foo } from '...' |
Type-only named import |
import { type Foo } from '...' |
Inline type modifier (TS 4.5+) |
Flag Value Imports Used Only as Types: If an identifier imported without type is used only in type positions (: Foo, as Foo, implements Foo, generic parameters), it should be converted to import type. This prevents accidental runtime dependencies and satisfies verbatimModuleSyntax / isolatedModules compiler flags.
// ❌ Before — value import used only as a type
import { UserProfile } from './types';
const handler = (u: UserProfile) => { ... };
// ✅ After — type-only import
import type { UserProfile } from './types';
const handler = (u: UserProfile) => { ... };
Flag Duplicate Imports: Detect cases where the same module is imported more than once in a file (often from copy-paste). Merge them into a single import statement.
// ❌ Duplicate
import { A } from './utils';
import { B } from './utils';
// ✅ Merged
import { A, B } from './utils';
Verify Barrel / Index Exports: When a directory contains an index.ts (barrel file), confirm that every component or module expected to be publicly accessible is re-exported. Cross-reference against the file manifest from Phase 1.
Apply Fixes & Re-audit: Apply all import corrections as a single write pass per file. After writing, re-read the affected files (parallel batch) to confirm the fixes took effect.
Phase 4 — Final Validation & Report
Retry the Original Operation: With the directory structure confirmed and import issues resolved, retry the operation that originally failed.
Log an Audit Report: Produce a concise summary covering:
- Total files enumerated and read
- Number of batches used (highlight the iteration savings vs. sequential)
- Import issues found and fixed (value→type conversions, duplicate merges, missing barrel exports)
- Any remaining unresolved issues with recommended next steps
Quick Reference: Batch Reading Pattern
# Sequential (slow) — N iterations for N files
read_file(file1) → wait → read_file(file2) → wait → ...
# Parallel batch (fast) — ⌈N/B⌉ iterations for N files, batch size B
[read_file(file1), read_file(file2), ..., read_file(fileB)] ← 1 iteration
[read_file(fileB+1), ...] ← 1 iteration
Best Practices
- Always enumerate before reading:
list_dir first, then batch-read. Never guess file names.
- Use absolute paths throughout to avoid working-directory ambiguity.
- Batch by locality: Group files from the same directory in the same batch to keep context coherent.
- Type imports are zero-cost at runtime: Prefer
import type for any symbol used exclusively as a TypeScript type. This is especially important in projects with isolatedModules: true.
- Barrel files are contracts: Treat
index.ts exports as the public API of a module. Missing exports are bugs even if the underlying file is correct.
- Log intermediate findings: If issues persist after Phase 3, dump the full audit log for offline debugging.
Common Fix Categories (Checklist)
1---2name: verify-directory-structure-parallel-audit3description: Diagnose and resolve file access issues by verifying directory structure, then reading multiple files in parallel batches for efficient auditing, with built-in guidance for validating TypeScript import patterns.4---5
6# Verify Directory Structure — Parallel Audit
7
8This skill provides a systematic approach to diagnosing file access issues and auditing source trees efficiently. It extends basic directory verification with **parallel batch file reading** (dramatically reducing iteration count when many files must be inspected) and a dedicated **TypeScript import validation** phase that catches a common class of structural bugs.
9
10---
11
12## Steps
13
14### Phase 1 — Directory Verification
15
161. **Identify Target Paths**: Collect every file or directory path involved in the operation. Prefer absolute paths to eliminate ambiguity.
17
182. **Enumerate with `list_dir`**: Call `list_dir` on each relevant directory. Record all file names, sizes, and modification dates. This is your ground truth before touching any file.
19
203. **Verify Existence & Permissions**: Confirm the directory exists and that the current user has read (and, if needed, write/execute) permissions. If a directory is missing, create it before proceeding. If permissions are insufficient, adjust them before retrying.
21
224. **Build a File Manifest**: From the `list_dir` output, compile the complete list of files to be audited. Group them logically (e.g., by subdirectory or file type) so they can be read in parallel batches.
23
24---
25
26### Phase 2 — Parallel Batch File Reading
27
28> **Why this matters**: Reading files sequentially costs one iteration per file. Reading them in parallel batches collapses N files into ⌈N/batch_size⌉ iterations — a significant speedup when auditing dozens of files.
29
305. **Determine Batch Size**: Default to reading **5–10 files per batch**. Reduce the batch size if individual files are very large; increase it for small config/index files.
31
326. **Issue Parallel `read_file` Calls**: Within each batch, invoke `read_file` for all files simultaneously (a single iteration). Do not wait for one file before requesting the next within the same batch.
33
34 ```
35 Batch 1 (parallel): read_file(src/components/A.tsx)
36 read_file(src/components/B.tsx)
37 read_file(src/components/C.tsx)
38 read_file(src/components/D.tsx)
39 read_file(src/components/E.tsx)
40
41 Batch 2 (parallel): read_file(src/components/F.tsx)
42 ...
43 ```
44
457. **Collect & Triage Results**: After each batch completes, scan results for errors (file-not-found, permission denied) and flag them immediately. Do not abort the remaining batches; continue and aggregate all findings.
46
478. **Re-verify Missing Files**: For any file reported as missing, re-run `list_dir` on its parent directory to confirm whether the file truly does not exist or whether the path was wrong. Correct the path and retry the single file if necessary.
48
49---
50
51### Phase 3 — TypeScript Import Validation
52
53> This phase targets a common class of structural bugs found when auditing TypeScript source trees.
54
559. **Identify Import Statements**: For every `.ts` / `.tsx` file read in Phase 2, extract all `import` lines.
56
5710. **Classify Import Kind — Value vs. Type**:
58
59 | Pattern | Correct usage |
60 |---|---|
61 | `import Foo from '...'` | Runtime value (class, function, object) |
62 | `import { Foo } from '...'` | Runtime value export |
63 | `import type Foo from '...'` | Type-only import (erased at compile time) |
64 | `import type { Foo } from '...'` | Type-only named import |
65 | `import { type Foo } from '...'` | Inline type modifier (TS 4.5+) |
66
6711. **Flag Value Imports Used Only as Types**: If an identifier imported without `type` is used **only** in type positions (`: Foo`, `as Foo`, `implements Foo`, generic parameters), it should be converted to `import type`. This prevents accidental runtime dependencies and satisfies `verbatimModuleSyntax` / `isolatedModules` compiler flags.
68
69 ```typescript
70 // ❌ Before — value import used only as a type
71 import { UserProfile } from './types';
72 const handler = (u: UserProfile) => { ... };
73
74 // ✅ After — type-only import
75 import type { UserProfile } from './types';
76 const handler = (u: UserProfile) => { ... };
77 ```
78
7912. **Flag Duplicate Imports**: Detect cases where the same module is imported more than once in a file (often from copy-paste). Merge them into a single import statement.
80
81 ```typescript
82 // ❌ Duplicate
83 import { A } from './utils';
84 import { B } from './utils';
85
86 // ✅ Merged
87 import { A, B } from './utils';
88 ```
89
9013. **Verify Barrel / Index Exports**: When a directory contains an `index.ts` (barrel file), confirm that every component or module expected to be publicly accessible is re-exported. Cross-reference against the file manifest from Phase 1.
91
9214. **Apply Fixes & Re-audit**: Apply all import corrections as a single write pass per file. After writing, re-read the affected files (parallel batch) to confirm the fixes took effect.
93
94---
95
96### Phase 4 — Final Validation & Report
97
9815. **Retry the Original Operation**: With the directory structure confirmed and import issues resolved, retry the operation that originally failed.
99
10016. **Log an Audit Report**: Produce a concise summary covering:
101 - Total files enumerated and read
102 - Number of batches used (highlight the iteration savings vs. sequential)
103 - Import issues found and fixed (value→type conversions, duplicate merges, missing barrel exports)
104 - Any remaining unresolved issues with recommended next steps
105
106---
107
108## Quick Reference: Batch Reading Pattern
109
110```
111# Sequential (slow) — N iterations for N files
112read_file(file1) → wait → read_file(file2) → wait → ...
113
114# Parallel batch (fast) — ⌈N/B⌉ iterations for N files, batch size B
115[read_file(file1), read_file(file2), ..., read_file(fileB)] ← 1 iteration
116[read_file(fileB+1), ...] ← 1 iteration
117```
118
119---
120
121## Best Practices
122
123- **Always enumerate before reading**: `list_dir` first, then batch-read. Never guess file names.
124- **Use absolute paths** throughout to avoid working-directory ambiguity.
125- **Batch by locality**: Group files from the same directory in the same batch to keep context coherent.
126- **Type imports are zero-cost at runtime**: Prefer `import type` for any symbol used exclusively as a TypeScript type. This is especially important in projects with `isolatedModules: true`.
127- **Barrel files are contracts**: Treat `index.ts` exports as the public API of a module. Missing exports are bugs even if the underlying file is correct.
128- **Log intermediate findings**: If issues persist after Phase 3, dump the full audit log for offline debugging.
129
130---
131
132## Common Fix Categories (Checklist)
133
134- [ ] Directory missing → create with `mkdir -p`
135- [ ] Permissions insufficient → `chmod`/`chown` or escalate
136- [ ] Path typo → re-enumerate with `list_dir`, correct path
137- [ ] Value import used as type → add `import type`
138- [ ] Duplicate imports → merge into single statement
139- [ ] Missing barrel export → add re-export to `index.ts`
140- [ ] Circular import → restructure module boundaries