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>
9.0 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 | 04 | execute | 4 |
|
|
false | true |
|
Purpose: Replace the current inline file reading (Step 3: "Read file content using Read tool") with a single subagent spawn. The orchestrator runs Glob to find files (Step 2), spawns gsd-indexer with the file list, and receives index.json back. This prevents context exhaustion on large codebases where 250+ file reads were causing the orchestrator to die before reaching Step 9.
Output: Updated commands/gsd/analyze-codebase.md
<execution_context>
@/.claude/get-shit-done/workflows/execute-plan.md
@/.claude/get-shit-done/templates/summary.md
</execution_context>
Update Step 2: Find all indexable files
Keep the Glob pattern and exclusion list, but change the output description:
## Step 2: Find all indexable files
Use Glob tool with pattern: `**/*.{js,ts,jsx,tsx,mjs,cjs}`
Exclude directories (skip any path containing):
- node_modules
- dist
- build
- .git
- vendor
- coverage
- .next
- __pycache__
Filter results to remove excluded paths. Store as `file_paths` array.
**Output:** List of absolute file paths for indexing. Do NOT read file contents.
Replace Step 3: Process each file
Remove the entire current Step 3 (lines ~67-100) which contains:
- "Read file content using Read tool"
- Export regex patterns inline
- Import regex patterns inline
- Store in index structure
Replace with:
## Step 3: Spawn indexer subagent
Spawn `gsd-indexer` subagent with the file paths from Step 2.
**Why subagent delegation:**
- Orchestrator would exhaust context reading 500+ files inline
- Subagent gets fresh 200k context for file reading
- Orchestrator only handles file paths (small)
- Subagent writes index.json directly (large)
**Task tool invocation:**
```python
file_list = "\n".join(file_paths) # From Step 2 Glob results
Task(
prompt=f"""Index codebase files by extracting exports and imports.
You are a GSD indexer. Read source files and extract exports/imports using regex patterns.
**Parameters:**
- Files to process: {len(file_paths)}
- Output path: .planning/intel/index.json
**Export patterns:**
- Named: export\\s*\\{{([^}}]+)\\}}
- Declaration: export\\s+(?:const|let|var|function\\*?|async\\s+function|class)\\s+(\\w+)
- Default: 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+)
**Import patterns:**
- ES6: import\\s+(?:\\{{[^}}]*\\}}|\\*\\s+as\\s+\\w+|\\w+)\\s+from\\s+['\"]([^'\"]+)['\"]
- Side-effect: import\\s+['\"]([^'\"]+)['\"]
- CommonJS: require\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)
**Index schema:**
```json
{{
"version": 1,
"updated": {timestamp},
"files": {{
"/absolute/path/file.js": {{
"exports": ["name1", "name2"],
"imports": ["source1", "source2"],
"indexed": {timestamp}
}}
}}
}}
Process: For each file path below:
- Read file content using Read tool
- Apply export regex patterns, collect export names
- Apply import regex patterns, collect import sources
- Store in index structure with absolute path as key
Files: {file_list}
Return format: When complete, return ONLY statistics:
INDEXING COMPLETE
Files processed: {{N}} Exports found: {{M}} Imports found: {{K}} Errors: {{E}}
Index written to: .planning/intel/index.json
Do NOT return index contents. """, subagent_type="gsd-indexer" )
**Wait for completion:** Task() blocks until subagent finishes.
**Verify index created:**
```bash
ls -la .planning/intel/index.json
**Update context section** (around lines 21-38):
Add to the context section, before the existing "Execution model (Step 9)" section:
```markdown
**Execution model (Steps 2-3 - Indexing):**
- Orchestrator finds file paths via Glob (Step 2)
- Spawns `gsd-indexer` subagent with file paths only (Step 3)
- Subagent reads files in fresh 200k context, applies regex patterns
- Subagent writes index.json directly to disk
- Subagent returns statistics only (not file contents or index data)
- This prevents context exhaustion on large codebases (500+ files)
Remove inline regex documentation:
The regex patterns are now documented in the subagent prompt. Remove any duplicate documentation that described inline processing. The command should make clear that file reading is DELEGATED, not performed inline.
Verify Step 4 still works:
Step 4 "Detect conventions" reads from index.json that the subagent wrote. This should work unchanged since the index format is the same. Read updated commands/gsd/analyze-codebase.md and confirm:
- Step 2 mentions storing as "file_paths" array, NOT reading contents
- Step 3 spawns gsd-indexer via Task tool
- No "Read file content" instruction in orchestrator steps
- Context section documents subagent delegation for Steps 2-3
- Step 4+ remain unchanged (read index.json from disk)
- Regex patterns appear in subagent prompt (not inline) analyze-codebase.md Steps 2-3 refactored. Orchestrator only Globs for paths, then spawns indexer subagent. File reading is fully delegated to subagent with fresh context.
<success_criteria> analyze-codebase refactored with full subagent delegation. Both indexing (Steps 2-3) and entity generation (Step 9) now use subagents. Command works on 500+ file codebases without context exhaustion. </success_criteria>
After completion, create `.planning/phases/05-subagent-codebase-analysis/05-04-SUMMARY.md`