Files
msd-core/.planning/phases/05-subagent-codebase-analysis/05-02-PLAN.md
Lex Christopherson d994732a45 docs(05): create phase plan for subagent codebase analysis
Phase 05: Subagent Codebase Analysis
- 2 plans in 2 waves
- Plan 05-01: Create gsd-entity-generator subagent (Wave 1)
- Plan 05-02: Refactor analyze-codebase to use subagent (Wave 2)
- Ready for execution

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 11:44:32 -06:00

7.1 KiB

phase, plan, type, wave, depends_on, files_modified, autonomous, must_haves
phase plan type wave depends_on files_modified autonomous must_haves
05-subagent-codebase-analysis 02 execute 2
05-01
commands/gsd/analyze-codebase.md
false
truths artifacts key_links
analyze-codebase Step 9 spawns gsd-entity-generator subagent
Subagent receives file list (paths only, not contents)
Orchestrator context is preserved (no file contents loaded)
Entity generation completes and returns statistics
path provides contains
commands/gsd/analyze-codebase.md Refactored command with subagent delegation gsd-entity-generator
from to via pattern
commands/gsd/analyze-codebase.md agents/gsd-entity-generator.md Task tool spawn Task.*gsd-entity-generator
Refactor analyze-codebase Step 9 to spawn subagent instead of inline batching.

Purpose: Replace the current "batches of 10 via Task tool" approach with a single subagent spawn. The orchestrator selects files (Step 9.2) then spawns gsd-entity-generator with the file list. Subagent reads files, generates entities, writes to disk. This preserves orchestrator context for large codebases.

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>

@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/05-subagent-codebase-analysis/05-RESEARCH.md @.planning/phases/05-subagent-codebase-analysis/05-01-SUMMARY.md @commands/gsd/analyze-codebase.md @agents/gsd-entity-generator.md Task 1: Refactor Step 9 to use subagent delegation commands/gsd/analyze-codebase.md Modify Step 9 of analyze-codebase.md. Keep Steps 9.1 (create directory) and 9.2 (select files) unchanged. Replace Steps 9.3-9.5 with subagent spawn.

Remove: Step 9.3 "Generate entities via Task tool batching" (the batch-of-10 pattern)

Replace with: Step 9.3 "Spawn entity generator subagent"

New Step 9.3 content:

### 9.3 Spawn entity generator subagent

Spawn `gsd-entity-generator` with the selected file list.

**Pass to subagent:**
- Total file count
- Output directory: `.planning/intel/entities/`
- Slug convention: `src/lib/db.ts` -> `src-lib-db` (replace / with -, remove extension, lowercase)
- Entity template (include full template)
- List of absolute file paths (one per line)

**Task tool invocation:**

```python
Task(
  prompt=f"""Generate semantic entity documentation for key codebase files.

You are a GSD entity generator. Read source files and create semantic documentation that captures PURPOSE (what/why), not just syntax.

**Parameters:**
- Files to process: {len(selected_files)}
- Output directory: .planning/intel/entities/
- Date: {today}

**Slug convention:**
- src/lib/db.ts -> src-lib-db
- Replace / with -, remove extension, lowercase

**Entity template:**
[Include full template from gsd-entity-generator.md]

**Process:**
For each file path below:
1. Read file content using Read tool
2. Analyze purpose, exports, dependencies
3. Write entity to .planning/intel/entities/{{slug}}.md
4. PostToolUse hook syncs to graph.db automatically

**Files:**
{file_list}

**Return format:**
When complete, return ONLY statistics:

## ENTITY GENERATION COMPLETE

**Files processed:** {{N}}
**Entities created:** {{M}}
**Already existed:** {{K}}
**Errors:** {{E}}

Entities written to: .planning/intel/entities/

Do NOT include entity contents in your response.
""",
  subagent_type="gsd-entity-generator"
)

Wait for completion: Task() blocks until subagent finishes.

Parse result: Extract entities_created count from response for final report.


**Update Step 9.4:** Rename from "Verify entity generation" to just verify count:
```markdown
### 9.4 Verify entity generation

Confirm entities written:

```bash
ls .planning/intel/entities/*.md 2>/dev/null | wc -l

**Update Step 9.5:** Keep "Report entity statistics" but update text:
```markdown
### 9.5 Report entity statistics

Entity Generation Complete

Entity files created: [N] (from subagent response) Location: .planning/intel/entities/ Graph database: Updated automatically via PostToolUse hook

Next: Intel hooks will continue incremental updates as you code.

Update context section (line ~32) - add subagent reference:

**Execution model (Step 9 - Entity Generation):**
- Orchestrator selects files for entity generation (up to 50 based on priority)
- Spawns `gsd-entity-generator` subagent with file list (paths only, not contents)
- Subagent reads files in fresh 200k context, generates entities, writes to disk
- PostToolUse hook automatically syncs entities to graph.db
- Subagent returns statistics only (not entity contents)
- This preserves orchestrator context for large codebases (500+ files)

Important: Do NOT pass file contents to subagent. Pass file PATHS only. Subagent reads files itself (fresh context). Read updated commands/gsd/analyze-codebase.md and confirm:

  • Step 9.3 spawns gsd-entity-generator via Task tool
  • No batch-of-10 pattern remains
  • File paths passed, not file contents
  • Context section mentions subagent delegation
  • Steps 9.4-9.5 updated for new flow analyze-codebase.md Step 9 refactored. Entity generation now delegates to gsd-entity-generator subagent instead of inline Task batching.
Subagent delegation for entity generation in /gsd:analyze-codebase 1. Navigate to a test project (not this repo) 2. Run `/gsd:analyze-codebase` 3. Observe: - Steps 1-8 complete (index, conventions, summary) - Step 9.2 selects files (should see file list) - Step 9.3 spawns subagent (Task tool call with "gsd-entity-generator") - Subagent generates entities (should see Read/Write calls in subagent) - Subagent returns statistics only (not entity contents) 4. Verify `.planning/intel/entities/` contains entity files 5. Verify entity files follow template (frontmatter, Purpose, Exports, Dependencies with links) 6. Verify graph.db was updated (entities appear in summary.md) Type "approved" if entity generation works via subagent, or describe issues - [ ] Step 9.3 spawns gsd-entity-generator subagent - [ ] File paths passed to subagent (not file contents) - [ ] No batch-of-10 pattern in command - [ ] Context section documents subagent model - [ ] Entity files created in test project - [ ] Entities follow template format - [ ] Graph database updated (via hook) - [ ] User verification checkpoint passed

<success_criteria> analyze-codebase refactored to use subagent delegation. Entity generation works end-to-end on a test project, with orchestrator context preserved and entities written correctly. </success_criteria>

After completion, create `.planning/phases/05-subagent-codebase-analysis/05-02-SUMMARY.md`