Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
213053c
Remove title field from generate-spec prompt
iaminawe Oct 17, 2025
a645aa6
Remove title field from prompts and parser
iaminawe Oct 17, 2025
b285a82
Remove title field from test fixtures
iaminawe Oct 17, 2025
e795fe8
feat: add reverse-engineer-codebase prompt for contextual analysis
iaminawe Oct 21, 2025
e0471a5
refactor: rename reverse-engineer-codebase to generate-codebase-context
iaminawe Oct 21, 2025
5f071b6
docs: add comprehensive research analysis for prompt improvements
iaminawe Oct 21, 2025
e8c27f6
feat: enhance generate-codebase-context with evidence citations and c…
iaminawe Oct 21, 2025
754c5ea
docs: add comprehensive progress tracking and future roadmap
iaminawe Oct 21, 2025
5a8cedf
docs: add research directory README with complete overview
iaminawe Oct 21, 2025
f5ce583
docs: add accurate PR description for new prompt creation
iaminawe Oct 21, 2025
9fe9884
docs: emphasize NEW prompt creation in PR description
iaminawe Oct 21, 2025
1ec8b01
refactor: reorganize documentation structure
iaminawe Oct 21, 2025
c19cfe2
fix: resolve pre-commit markdownlint issues
iaminawe Oct 21, 2025
6fc25c6
chore: remove accidentally committed WARP.md session notes
iaminawe Oct 21, 2025
27b548e
Merge branch 'main' into add-reverse-engineer-codebase-prompt
iaminawe Oct 21, 2025
50061d7
fix: resolve pre-commit markdownlint issues
github-actions[bot] Oct 21, 2025
f387337
fix: resolve pre-commit issues after merge from main
iaminawe Oct 21, 2025
f3c2b1e
fix: convert emphasis to headings to resolve MD036 linting issues
github-actions[bot] Oct 21, 2025
705f76d
feat: enhance generate-spec prompt with evidence-based approach
iaminawe Oct 21, 2025
02ff6fb
feat: enhance generate-codebase-context with advanced analysis features
iaminawe Oct 21, 2025
f93790c
feat: add explicit 'What NOT to Do' section to generate-spec
iaminawe Oct 21, 2025
098785a
refactor: condense generate-codebase-context prompt from 1264 to 930 …
iaminawe Oct 21, 2025
e432810
fix: add blank lines in code blocks for markdownlint compliance
iaminawe Oct 21, 2025
b6535ee
Merge branch 'main' into add-reverse-engineer-codebase-prompt
iaminawe Oct 23, 2025
d1274aa
feat: add comprehensive codebase context analysis for mcp-spec-driven
iaminawe Oct 23, 2025
78db745
chore: update repository URLs to spec-driven-workflow
iaminawe Oct 23, 2025
98ea2db
fix: update research doc paths and restore Phase 4 checkpoint
github-actions[bot] Oct 23, 2025
e0a8fda
fix: resolve markdown linting issues in claude-code-feature-dev-compa…
github-actions[bot] Oct 23, 2025
ba6f472
fix: add blank line and language specifier to code block in claude-co…
github-actions[bot] Oct 23, 2025
059d75d
fix: apply markdownlint formatting fixes
iaminawe Oct 23, 2025
1f8152d
fix: add Phase 5.5 to execution rules in generate-context prompt
github-actions[bot] Oct 24, 2025
f1119ae
docs: resolve CodeRabbit nitpick comments
github-actions[bot] Oct 24, 2025
a1c31ba
Merge branch 'main' into add-reverse-engineer-codebase-prompt
iaminawe Oct 24, 2025
c265968
fix: add blank line before list in research-synthesis.md
iaminawe Oct 24, 2025
9565791
fix: convert emphasis to headings in generate-spec.md (MD036)
iaminawe Oct 24, 2025
789bcd9
Merge branch 'main' into add-reverse-engineer-codebase-prompt
iaminawe Oct 24, 2025
1b75ddd
chore: revert generate-spec to default from main
iaminawe Oct 27, 2025
760ad8b
chore: remove progress.md for now
iaminawe Oct 27, 2025
7995397
chore: remove reference to progress.md
iaminawe Oct 27, 2025
c45c7e0
Merge branch 'main' into generate-context-prompt
iaminawe Nov 10, 2025
ba75202
refactor: enhance generate-spec context assessment and remove researc…
iaminawe Nov 10, 2025
2039200
docs: add generate-context prompt to workflow documentation
iaminawe Nov 10, 2025
61b094b
fix: add blank line before list in README.md (markdownlint MD032)
iaminawe Nov 10, 2025
9dbb526
chore: revert unrelated task file URL changes
iaminawe Nov 10, 2025
42115f4
docs: clarify 00N-SYSTEM.md naming pattern with examples
iaminawe Nov 10, 2025
9217cfd
docs: fix step numbering and artifact naming consistency in README
github-actions[bot] Nov 10, 2025
4c1eb4d
fix: correct ordered list numbering for markdownlint compliance
iaminawe Nov 10, 2025
332589f
fix: complete ordered list numbering fix in TLDR section
iaminawe Nov 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .markdownlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"MD036": false,
"MD040": false
}
362 changes: 362 additions & 0 deletions docs/research/codebase-context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,362 @@
# Research: Reverse Engineering & Codebase Analysis Patterns

**Last Updated:** 2025-01-21
**Status:** Research Complete - Implementation Phase 1 Complete

---

## Overview

This directory contains research and analysis conducted to improve our MCP spec-driven development prompts. The research synthesizes patterns from:

1. **Claude Code feature-dev plugin** - Production-tested 7-phase workflow
2. **Existing research files** - code-analyst, information-analyst, context_bootstrap patterns
3. **Best practices** - Evidence-based analysis, confidence assessment, interactive questioning

**Primary Goal:** Enhance prompts with battle-tested patterns for better feature development outcomes.

---

## Research Documents

### 1. Claude Code Feature-Dev Comparison

**File:** [`claude-code-feature-dev-comparison.md`](./claude-code-feature-dev-comparison.md)
**Size:** 18,287 words
**Purpose:** Comprehensive analysis of Claude Code's feature-dev plugin

**Contents:**

- Complete 7-phase workflow breakdown
- Agent specifications (code-explorer, code-architect, code-reviewer)
- Comparison with our current MCP prompts
- Gap analysis with priority ratings (Critical/Important/Minor)
- Implementation roadmap (3 sprints)
- Updated workflow diagrams
- Detailed recommendations

**Key Findings:**

- ❌ Missing mandatory clarifying questions phase
- ❌ No architecture options comparison
- ❌ No quality review before completion
- ✅ Good: Document-based artifacts
- ✅ Good: Explicit sequencing
- ✅ Good: Comprehensive analysis

**Use This For:**

- Understanding Claude Code's proven workflow
- Identifying gaps in our current approach
- Planning future enhancements
- Architecture decision justification

---

### 2. Research Synthesis

**File:** [`research-synthesis.md`](./research-synthesis.md)
**Size:** 8,000+ words
**Purpose:** Actionable integration plan combining all research sources

**Contents:**

- Core philosophy: Code (WHAT/HOW) vs Docs (WHY) vs User (Intent)
- Two-agent specialization pattern (code-analyst + information-analyst)
- Manager orchestration pattern (context_bootstrap)
- Comparison matrix: Our approach vs Research best practices
- Actionable recommendations with priority matrix
- Specific enhancements for each prompt
- Implementation roadmap (3 sprints)
- Success metrics

**Key Recommendations:**

- 🔴 HIGH: Evidence citation standards (file:line, path#heading)
- 🔴 HIGH: Confidence assessment (High/Medium/Low)
- 🔴 HIGH: Mandatory clarifying phase in spec generation
- 🔴 HIGH: Architecture options prompt (new)
- 🔴 HIGH: Implementation review prompt (new)
- 🟡 MEDIUM: Interactive phased questioning
- 🟡 MEDIUM: ADR template creation

**Use This For:**

- Planning specific prompt enhancements
- Understanding priority of improvements
- Implementation guidance with examples
- Success criteria for each enhancement

---

### 3. Code Analyst Pattern

**File:** [`code-analyst.md`](./code-analyst.md)
**Source:** Existing research file (cataloged)
**Purpose:** Specialized agent for discovering WHAT and HOW from code

**Responsibilities:**

- Discover WHAT system does (features, workflows, business rules)
- Discover HOW it's structured (architecture, patterns, communication)
- Identify WHAT technologies are used

**Key Principles:**

- Code is ground truth - report what exists
- Be specific - reference exact file:line
- Distinguish fact from inference
- Flag feature toggles and dormant code
- **Stay in lane** - don't infer WHY

**What NOT to include:**

- ❌ Internal data models (implementation detail)
- ❌ Missing/planned features (belongs in roadmap)
- ❌ Code quality judgments
- ❌ Specific versions (too volatile)
- ❌ Testing infrastructure details

**Applied To:** `generate-codebase-context` Phase 3 (Code Analysis)

---

### 4. Information Analyst Pattern

**File:** [`information-analyst.md`](./information-analyst.md)
**Source:** Existing research file (cataloged)
**Purpose:** Specialized agent for extracting WHY from documentation

**Primary Job:** Extract decision rationale from docs (not discoverable from code)

**Responsibilities:**

- Discover WHY system was built this way
- Extract rationale from documentation
- Find decision context and trade-offs
- Capture historical evolution

**What to Look For:**

- Why was [technology X] chosen?
- Why [pattern Y] over alternatives?
- What constraints drove decisions?
- What trade-offs were considered?

**Key Principles:**

- Direct quotes for "why"
- Source everything (path#heading)
- Attach metadata (timestamps)
- Flag conflicts, don't resolve
- Distinguish explicit vs implicit
- Focus on rationale (unique value)

**Applied To:** `generate-codebase-context` Phase 2 (Documentation Audit)

---

### 5. Context Bootstrap Pattern

**File:** [`context_bootstrap.md`](./context_bootstrap.md)
**Source:** Existing research file (cataloged)
**Purpose:** Manager orchestration pattern for coordinating specialized agents

**Core Philosophy:**
> "Code explains HOW the system currently behaves; the user supplies WHAT it is supposed to achieve and WHY choices were made."

**Six-Phase Workflow:**

1. Analyze repository structure
2. Audit existing documentation
3. Deep code analysis (subprocess: Code Analyst)
4. User collaboration (fill gaps, resolve conflicts)
5. Draft documentation set (PRDs, ADRs, SYSTEM-OVERVIEW)
6. Review with user

**Key Pattern:** "Keep dialog interactive. Ask focused follow-up questions instead of long questionnaires."

**Deliverables:**

- PRDs (Product Requirements)
- ADRs (Architecture Decision Records in MADR format)
- SYSTEM-OVERVIEW.md
- README.md updates

**Applied To:** Overall `generate-codebase-context` structure and phasing

---

## How Research Was Applied

### Phase 1 (Completed) ✅

**Enhanced `generate-codebase-context` Prompt:**

From **code-analyst.md:**

- ✅ File:line evidence citations for all code findings
- ✅ Confidence levels (High/Needs Validation/Unknown)
- ✅ "Stay in your lane" - don't infer WHY from code
- ✅ Flag feature toggles and dormant paths
- ✅ Technology names only (NO versions)
- ✅ Focus on working features, not missing ones

From **information-analyst.md:**

- ✅ Documentation audit phase (scan + timestamp + inventory)
- ✅ Rationale extraction with direct quotes
- ✅ Source references with path#heading format
- ✅ Conflict detection between docs
- ✅ Distinguish explicit vs implicit knowledge

From **context_bootstrap.md:**

- ✅ Repository structure detection (workspace/monorepo/single)
- ✅ User collaboration phase (interactive, not batch)
- ✅ Capture user answers as direct quotes for citation

From **Claude Code feature-dev:**

- ✅ Essential files list with line ranges (5-10 files)
- ✅ Execution path traces (step-by-step flows)
- ✅ Interactive short questions (not batch questionnaires)

---

### Phase 2 (Planned for Next PR)

**Enhancements Planned:**

1. **`generate-spec` Enhancement:**
- Mandatory clarifying phase (Claude Code Phase 3)
- Phased interactive questioning (context_bootstrap pattern)
- WHY questions (information-analyst focus)

2. **`generate-architecture-options` (NEW):**
- Based on Claude Code code-architect agent
- Generate 2-3 approaches with trade-offs
- User must choose before proceeding

3. **`review-implementation` (NEW):**
- Based on Claude Code code-reviewer agent
- Multi-focus review (bugs, quality, conventions)
- Confidence-based filtering (≥80%)

See [`../../PROGRESS.md`](../../PROGRESS.md) for detailed roadmap.

---

## Key Insights

### 1. Separation of Concerns

**Discovery:** Code, docs, and users each provide different information

- **Code → WHAT + HOW:** Features, architecture, patterns (observable facts)
- **Docs → WHY:** Decisions, rationale, trade-offs (recorded intent)
- **User → Goals + Intent:** Purpose, value, strategic fit (current direction)

**Application:** Don't conflate these sources - keep them separate and clearly attributed

---

### 2. Evidence-Based Analysis

**Discovery:** Every claim needs proof

- Code findings: `file.ts:45-67` (line ranges)
- Doc findings: `doc.md#heading` (section anchors)
- User input: `[User confirmed: YYYY-MM-DD]` (dated quotes)

**Application:** Traceability and accountability for all findings

---

### 3. Confidence Assessment

**Discovery:** Distinguish facts from inferences

- High: Strong evidence from working code or explicit docs
- Medium: Inferred from context, feature flags, implied
- Low: Cannot determine, conflicts, unknowns

**Application:** Flag gaps explicitly rather than guessing

---

### 4. Interactive Collaboration

**Discovery:** Short focused conversations > long questionnaires

- Ask 3-5 questions, wait for answers
- Use answers to inform next round of questions
- Capture direct quotes for later citation

**Application:** Better engagement, more thoughtful answers

---

### 5. Mandatory Checkpoints

**Discovery:** Critical decisions need explicit user approval

- ⛔ STOP after clarifying questions (don't proceed without answers)
- ⛔ STOP after architecture options (user must choose)
- ⛔ STOP after implementation (user decides what to fix)

**Application:** User control at key decision points

---

## Success Metrics

### Phase 1 Metrics ✅

- ✅ 100% of code findings have file:line citations
- ✅ 100% of findings categorized by confidence level
- ✅ Documentation audit phase included
- ✅ Interactive questioning approach (3-5 questions per round)
- ✅ Essential files list structure (5-10 files with ranges)
- ✅ Execution path traces included in examples

### Phase 2 Metrics (Target)

- [ ] Clarifying questions are mandatory (cannot proceed without)
- [ ] Architecture options always present 2-3 approaches
- [ ] User explicitly chooses architecture before tasks
- [ ] Review catches common issues before PR
- [ ] All prompts use consistent evidence standards

---

## References

### External Sources

- [Claude Code Repository](https://github.com/anthropics/claude-code)
- [Feature-Dev Plugin](https://github.com/anthropics/claude-code/tree/main/plugins/feature-dev)
- [Feature-Dev README](https://github.com/anthropics/claude-code/blob/main/plugins/feature-dev/README.md)
- [Code Explorer Agent](https://github.com/anthropics/claude-code/blob/main/plugins/feature-dev/agents/code-explorer.md)
- [Code Architect Agent](https://github.com/anthropics/claude-code/blob/main/plugins/feature-dev/agents/code-architect.md)
- [Code Reviewer Agent](https://github.com/anthropics/claude-code/blob/main/plugins/feature-dev/agents/code-reviewer.md)
- [MADR Format](https://adr.github.io/madr/)

### Internal Documents

- [Progress Tracking](../../PROGRESS.md)
- [Main README](../../../README.md)

---

## Next Steps

1. **Review Phase 1 PR:** `add-reverse-engineer-codebase-prompt` branch
2. **Plan Phase 2 PR:** After Phase 1 merge
3. **Implement remaining enhancements:** Per roadmap in PROGRESS.md

---

**Research Status:** Complete and applied to Phase 1
**Next Research:** None planned - focus on implementation
**Last Updated:** 2025-01-21
Loading