--- phase: 05-subagent-codebase-analysis plan: 02 type: execute wave: 2 depends_on: ["05-01"] files_modified: - commands/gsd/analyze-codebase.md autonomous: false must_haves: truths: - "Entity generation scales to 500+ files without context exhaustion" - "Subagent receives only file paths, preserving orchestrator context" - "Entity files appear in .planning/intel/entities/ after generation" - "User can run /gsd:analyze-codebase on large codebases without degradation" artifacts: - path: "commands/gsd/analyze-codebase.md" provides: "Refactored command with subagent delegation" contains: "gsd-entity-generator" key_links: - from: "commands/gsd/analyze-codebase.md" to: "agents/gsd-entity-generator.md" via: "Task tool spawn" pattern: "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` @~/.claude/get-shit-done/workflows/execute-plan.md @~/.claude/get-shit-done/templates/summary.md @.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: ```markdown ### 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: ```markdown **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) ``` **Fix outdated slug documentation** (around line 286): The entity filename convention example is outdated. Change: ```markdown - Example: src/utils/auth.js -> src--utils--auth-js.md ``` To: ```markdown - Example: src/utils/auth.js -> src-utils-auth-js.md ``` (Single hyphen, not double hyphen. The hook `gsd-intel-index.js:generateSlug` already uses single hyphen format.) **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 - Slug example at line ~286 uses single hyphen (src-utils-auth-js.md) analyze-codebase.md Step 9 refactored. Entity generation now delegates to gsd-entity-generator subagent instead of inline Task batching. Outdated slug documentation corrected. 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 - [ ] Slug example uses single hyphen format (matches hook) - [ ] Entity files created in test project - [ ] Entities follow template format - [ ] Graph database updated (via hook) - [ ] User verification checkpoint passed 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. After completion, create `.planning/phases/05-subagent-codebase-analysis/05-02-SUMMARY.md`