feat: add gsd-pattern-mapper agent for codebase pattern analysis (#1861)
Add a new pattern mapper agent that analyzes the codebase for existing patterns before planning, producing PATTERNS.md with per-file analog assignments and code excerpts. Integrated into plan-phase workflow as Step 7.8 (between research and planning), controlled by the workflow.pattern_mapper config key (default: true). Changes: - New agent: agents/gsd-pattern-mapper.md - New config key: workflow.pattern_mapper in VALID_CONFIG_KEYS and CONFIG_DEFAULTS - init plan-phase: patterns_path field in JSON output - plan-phase.md: Step 7.8 spawns pattern mapper, PATTERNS_PATH in planner files_to_read - gsd-plan-checker.md: Dimension 12 (Pattern Compliance) - model-profiles.cjs: gsd-pattern-mapper profile entry - Tests: tests/pattern-mapper.test.cjs (5 tests) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ Read all files referenced by the invoking prompt's execution_context before star
|
||||
<available_agent_types>
|
||||
Valid GSD subagent types (use exact names — do not fall back to 'general-purpose'):
|
||||
- gsd-phase-researcher — Researches technical approaches for a phase
|
||||
- gsd-pattern-mapper — Analyzes codebase for existing patterns, produces PATTERNS.md
|
||||
- gsd-planner — Creates detailed plans from phase scope
|
||||
- gsd-plan-checker — Reviews plan quality before execution
|
||||
</available_agent_types>
|
||||
@@ -588,6 +589,7 @@ VERIFICATION_PATH=$(_gsd_field "$INIT" verification_path)
|
||||
UAT_PATH=$(_gsd_field "$INIT" uat_path)
|
||||
CONTEXT_PATH=$(_gsd_field "$INIT" context_path)
|
||||
REVIEWS_PATH=$(_gsd_field "$INIT" reviews_path)
|
||||
PATTERNS_PATH=$(_gsd_field "$INIT" patterns_path)
|
||||
```
|
||||
|
||||
## 7.5. Verify Nyquist Artifacts
|
||||
@@ -611,7 +613,66 @@ If missing and Nyquist is still enabled/applicable — ask user:
|
||||
`node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" config-set workflow.nyquist_validation false`
|
||||
3. Continue anyway (plans fail Dimension 8)
|
||||
|
||||
Proceed to Step 8 only if user selects 2 or 3.
|
||||
Proceed to Step 7.8 (or Step 8 if pattern mapper is disabled) only if user selects 2 or 3.
|
||||
|
||||
## 7.8. Spawn gsd-pattern-mapper Agent (Optional)
|
||||
|
||||
**Skip if** `workflow.pattern_mapper` is explicitly set to `false` in config.json (absent key = enabled). Also skip if no CONTEXT.md and no RESEARCH.md exist for this phase (nothing to extract file lists from).
|
||||
|
||||
Check config:
|
||||
```bash
|
||||
PATTERN_MAPPER_CFG=$(node "$HOME/.claude/get-shit-done/bin/gsd-tools.cjs" config-get workflow.pattern_mapper --default true 2>/dev/null)
|
||||
```
|
||||
|
||||
**If `PATTERN_MAPPER_CFG` is `false`:** Skip to step 8.
|
||||
|
||||
**If PATTERNS.md already exists** (`PATTERNS_PATH` is non-empty from step 7): Skip to step 8 (use existing).
|
||||
|
||||
Display banner:
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
GSD ► PATTERN MAPPING PHASE {X}
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
◆ Spawning pattern mapper...
|
||||
```
|
||||
|
||||
Pattern mapper prompt:
|
||||
|
||||
```markdown
|
||||
<pattern_mapping_context>
|
||||
**Phase:** {phase_number} - {phase_name}
|
||||
**Phase directory:** {phase_dir}
|
||||
**Padded phase:** {padded_phase}
|
||||
|
||||
<files_to_read>
|
||||
- {context_path} (USER DECISIONS from /gsd-discuss-phase)
|
||||
- {research_path} (Technical Research)
|
||||
</files_to_read>
|
||||
|
||||
**Output file:** {phase_dir}/{padded_phase}-PATTERNS.md
|
||||
|
||||
Extract the list of files to be created/modified from CONTEXT.md and RESEARCH.md. For each file, classify by role and data flow, find the closest existing analog in the codebase, extract concrete code excerpts, and produce PATTERNS.md.
|
||||
</pattern_mapping_context>
|
||||
```
|
||||
|
||||
Spawn with:
|
||||
```
|
||||
Task(
|
||||
prompt="{above}",
|
||||
subagent_type="gsd-pattern-mapper",
|
||||
model="{researcher_model}",
|
||||
)
|
||||
```
|
||||
|
||||
**Handle return:**
|
||||
- **`## PATTERN MAPPING COMPLETE`:** Update `PATTERNS_PATH` to the created file path, continue to step 8.
|
||||
- **Any error or empty return:** Log warning, continue to step 8 without patterns (non-blocking).
|
||||
|
||||
After pattern mapper completes, update the path variable:
|
||||
```bash
|
||||
PATTERNS_PATH="${PHASE_DIR}/${PADDED_PHASE}-PATTERNS.md"
|
||||
```
|
||||
|
||||
## 8. Spawn gsd-planner Agent
|
||||
|
||||
@@ -637,6 +698,7 @@ Planner prompt:
|
||||
- {requirements_path} (Requirements)
|
||||
- {context_path} (USER DECISIONS from /gsd-discuss-phase)
|
||||
- {research_path} (Technical Research)
|
||||
- {PATTERNS_PATH} (Pattern Map — analog files and code excerpts, if exists)
|
||||
- {verification_path} (Verification Gaps - if --gaps)
|
||||
- {uat_path} (UAT Gaps - if --gaps)
|
||||
- {reviews_path} (Cross-AI Review Feedback - if --reviews)
|
||||
|
||||
Reference in New Issue
Block a user