Phase 05: Subagent Codebase Analysis - 05-03: gsd-indexer subagent for file reading and export/import extraction - 05-04: Refactor analyze-codebase Steps 2-3 to use indexer subagent Gap closure addresses context exhaustion during indexing phase (Steps 2-3), not just entity generation (Step 9). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
6.6 KiB
phase, plan, type, wave, depends_on, files_modified, autonomous, gap_closure, must_haves
| phase | plan | type | wave | depends_on | files_modified | autonomous | gap_closure | must_haves | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 05-subagent-codebase-analysis | 03 | execute | 3 |
|
true | true |
|
Purpose: Define the subagent that reads files and extracts exports/imports. This agent is spawned by /gsd:analyze-codebase with a list of file paths (from Glob), reads each file, applies the same regex patterns as current Step 3, and writes the complete index.json to disk. Returns statistics only to preserve orchestrator context.
Output: agents/gsd-indexer.md
<execution_context>
@/.claude/get-shit-done/workflows/execute-plan.md
@/.claude/get-shit-done/templates/summary.md
</execution_context>
Frontmatter:
---
name: gsd-indexer
description: Indexes codebase files by extracting exports and imports. Spawned by analyze-codebase with file list. Writes index.json directly to disk.
tools: Read, Write, Bash
color: cyan
---
Role section:
- Spawned by
/gsd:analyze-codebasewith file paths (from Glob results) - Reads source files using Read tool
- Extracts exports and imports using regex patterns
- Writes complete index.json to
.planning/intel/index.json - Returns statistics only (NOT file contents or index data)
Why this matters section:
- Index.json is consumed by convention detection (Step 4)
- Entity generation uses index to find hub files (Step 9.2)
- PostToolUse hook uses index for incremental updates
- Orchestrator MUST NOT load file contents (context exhaustion on 500+ files)
Process sections:
-
parse_input- Extract from prompt:- Output path:
.planning/intel/index.json - List of absolute file paths (one per line)
- Initialize counters: files_processed=0, exports_found=0, imports_found=0, errors=0
- Output path:
-
process_each_file- For each file path:a. Read file content using Read tool
b. Extract exports using these patterns (EXACTLY as Step 3):
- Named exports:
export\s*\{([^}]+)\} - Declaration exports:
export\s+(?:const|let|var|function\*?|async\s+function|class)\s+(\w+) - Default exports:
export\s+default\s+(?:function\s*\*?\s*|class\s+)?(\w+)? - CommonJS object:
module\.exports\s*=\s*\{([^}]+)\} - CommonJS single:
module\.exports\s*=\s*(\w+)\s*[;\n] - TypeScript:
export\s+(?:type|interface)\s+(\w+)
c. Extract imports using these patterns (EXACTLY as Step 3):
- ES6:
import\s+(?:\{[^}]*\}|\*\s+as\s+\w+|\w+)\s+from\s+['"]([^'"]+)['"] - Side-effect:
import\s+['"]([^'"]+)['"](not preceded by 'from') - CommonJS:
require\s*\(\s*['"]([^'"]+)['"]\s*\)
d. Store in index structure:
index.files[absolutePath] = { exports: [], // Array of export names imports: [], // Array of import sources indexed: Date.now() }e. Track statistics: increment files_processed, add to exports_found/imports_found
f. Handle errors: if file can't be read, increment errors and continue
- Named exports:
-
write_index- Write complete index to disk:{ version: 1, updated: Date.now(), files: { /* all file entries */ } }Write to
.planning/intel/index.jsonusing Write tool. -
return_statistics- Return ONLY:## INDEXING COMPLETE **Files processed:** {files_processed} **Exports found:** {exports_found} **Imports found:** {imports_found} **Errors:** {errors} Index written to: .planning/intel/index.json
Critical rules section:
- WRITE index.json directly (never return index contents)
- Use EXACT regex patterns from Step 3 (patterns are validated)
- Handle read errors gracefully (log path, continue)
- Return only statistics (~10 lines)
- DO NOT commit (orchestrator handles git)
- File paths in index must be ABSOLUTE paths (key for O(1) lookup)
Success criteria checklist:
- All file paths processed
- index.json written with version, updated, files
- Each file entry has exports, imports, indexed timestamp
- Absolute paths as keys (not relative)
- Statistics returned (not index contents) File exists and contains:
- Frontmatter with name: gsd-indexer, tools: Read/Write/Bash
- Role section explaining spawn context from analyze-codebase
- Why this matters section explaining index consumers
- Process steps: parse_input, process_each_file, write_index, return_statistics
- EXACT regex patterns matching Step 3 of analyze-codebase
- Critical rules section (write directly, return stats only)
- Success criteria checklist
agents/gsd-indexer.mdexists with complete agent definition. Agent uses same regex patterns as current Step 3. Ready to be spawned by analyze-codebase.
<success_criteria> gsd-indexer agent definition complete. Agent can be spawned with file paths and will read files, extract exports/imports using validated regex patterns, and write index.json directly to disk. </success_criteria>
After completion, create `.planning/phases/05-subagent-codebase-analysis/05-03-SUMMARY.md`