Files
msd-core/.planning/phases/05-subagent-codebase-analysis/05-03-PLAN.md
Lex Christopherson a686d28669 docs(05): create gap closure plans for Steps 2-3 subagent delegation
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>
2026-01-20 21:46:14 -06:00

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
agents/gsd-indexer.md
true true
truths artifacts key_links
Indexer agent definition exists following gsd-entity-generator pattern
Agent reads files and extracts exports/imports using same regex as Step 3
Agent writes index.json directly to disk
Agent returns statistics only (not file contents)
path provides contains
agents/gsd-indexer.md Subagent definition for file indexing gsd-indexer
from to via pattern
agents/gsd-indexer.md .planning/intel/index.json Write tool call Write.*index.json
Create gsd-indexer subagent definition for Steps 2-3 file indexing.

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>

@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/05-subagent-codebase-analysis/05-VERIFICATION.md @agents/gsd-entity-generator.md @agents/gsd-codebase-mapper.md @commands/gsd/analyze-codebase.md Task 1: Create gsd-indexer agent definition agents/gsd-indexer.md Create agent definition following gsd-entity-generator.md structure:

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-codebase with 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:

  1. 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
  2. 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

  3. write_index - Write complete index to disk:

    {
      version: 1,
      updated: Date.now(),
      files: { /* all file entries */ }
    }
    

    Write to .planning/intel/index.json using Write tool.

  4. 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.md exists with complete agent definition. Agent uses same regex patterns as current Step 3. Ready to be spawned by analyze-codebase.
- [ ] File exists at `agents/gsd-indexer.md` - [ ] Frontmatter valid YAML (name, description, tools, color) - [ ] Role section explains subagent purpose (spawned by analyze-codebase) - [ ] Process has 4 steps: parse, process, write, return - [ ] Export regex patterns match Step 3 exactly (6 patterns) - [ ] Import regex patterns match Step 3 exactly (3 patterns) - [ ] Index schema matches Step 5 format (version, updated, files) - [ ] Critical rules section matches gsd-entity-generator style - [ ] Returns statistics only (not index contents)

<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`