diff --git a/.agents/ralph/PROMPT_build.md b/.agents/ralph/PROMPT_build.md index 9b86a3f..a06aae3 100644 --- a/.agents/ralph/PROMPT_build.md +++ b/.agents/ralph/PROMPT_build.md @@ -45,6 +45,32 @@ If the story details are empty or missing, STOP and report that the PRD story fo - If No-commit is true, do NOT commit or push changes. - All changes made during the run must be committed (including updates to PRD/plan/progress/logs). +## Agent Boundaries + +### βœ… Always (No approval needed) +- Read any file in the codebase +- Run read-only commands: `git status`, `git log`, `npm test`, `npm run build` +- Update progress.md after completing each task +- Reference existing code patterns before writing new code +- Run type checking before marking task complete + +### ⚠️ Ask First (Requires human confirmation) +- Changes to public API signatures or contracts +- Database schema modifications or migrations +- Adding new external dependencies +- Deleting files or removing functionality +- Changes to authentication/authorization logic +- Modifications to CI/CD configuration + +### 🚫 Never (Hard stops - will cause build failure) +- Commit secrets, API keys, or credentials +- Push directly to main/master branch +- Skip type checking or linting +- Assume missing functionality exists (verify by reading code) +- Modify files outside the project scope +- Use `--force` flags on git commands +- Disable or skip tests to make them pass + ## Critical Merge Policy (NEVER VIOLATE) **YOU MUST NOT**: diff --git a/.agents/ralph/PROMPT_plan.md b/.agents/ralph/PROMPT_plan.md index dcf8bdc..76d2d27 100644 --- a/.agents/ralph/PROMPT_plan.md +++ b/.agents/ralph/PROMPT_plan.md @@ -17,14 +17,31 @@ You are an autonomous coding agent. Your task is to create or update an implemen - Activity Log: {{ACTIVITY_LOG_PATH}} - Repo Root: {{REPO_ROOT}} -## Rules (Non-Negotiable) - -- Do NOT implement anything. -- Do NOT run tests or modify source code. -- Do NOT ask the user questions. -- Plan only. -- Do NOT assume missing functionality; confirm by reading code. -- Treat shared utilities (if present) as the standard library; prefer existing patterns over ad-hoc copies. +## Agent Boundaries + +### Plan Mode Constraints +- Do NOT implement anything +- Do NOT run tests or modify source code +- Do NOT ask the user questions +- Plan only + +### βœ… Always (No approval needed) +- Read any file in the codebase +- Inspect package.json, Makefile, or build configs +- Document existing code patterns +- Reference guardrails.md for known issues + +### ⚠️ Ask First (Flag in plan if required) +- Tasks involving public API changes +- Database schema modifications +- New external dependencies +- File deletions + +### 🚫 Never (Hard stops) +- Assume missing functionality exists (verify by reading code) +- Create generic examples (use actual project code) +- Skip code pattern analysis +- Plan tasks without verification commands ## Your Task (Do this in order) @@ -147,6 +164,69 @@ Also include a short summary at the top: - Brief overview of gaps and the next most important work +## Commands Reference (Required) + +Extract from package.json, Makefile, or project docs: + +### Build & Test +- Build: `[command]` +- Test: `[command]` +- Lint: `[command]` +- Type check: `[command]` + +### Development +- Dev server: `[command]` +- Watch: `[command]` + +**Note:** These commands will be referenced in task Verification fields. Verify they work before including. + +## Testing Strategy + +### Test Framework & Locations +- Framework: [Jest/Vitest/Pytest/etc.] +- Unit tests: `tests/unit/` or `**/*.test.ts` +- Integration tests: `tests/integration/` +- E2E tests: `tests/e2e/` or `cypress/` + +### Coverage Requirements +- New code: Minimum 80% coverage +- Critical paths: 100% coverage required +- Existing pattern: See `tests/example.test.ts` + +### Test Commands +- Run all: `npm test` +- Run specific: `npm test -- --grep "pattern"` +- Watch mode: `npm test -- --watch` +- Coverage report: `npm test -- --coverage` + +**Agent instruction:** Extract testing patterns from actual test files. Use these patterns for new tests. + +## Git Workflow + +### Branch Naming +- Feature: `feature/US-XXX-short-description` +- Bugfix: `fix/US-XXX-short-description` +- Refactor: `refactor/US-XXX-short-description` + +### Commit Format +Use conventional commits (enforced by `/commit` skill): +- `feat(scope): add new feature` +- `fix(scope): resolve bug` +- `refactor(scope): improve code structure` +- `test(scope): add tests` +- `docs(scope): update documentation` + +### Commit Granularity +- One commit per story minimum +- Atomic commits (each commit should pass tests) +- Use `/commit` skill for message generation + +### PR Requirements (if applicable) +- Title: `[US-XXX] Story title` +- Description: Summary of changes +- Tests: All passing +- Review: Required before merge + ## Tasks ### US-XXX: Story Title @@ -250,3 +330,29 @@ Add this section to the PRD if missing (keep it short and explicit): - Commit URLs are invalid. - Unknown GitHub subpaths canonicalize to repo root. - **Frontend stories**: Must use `/frontend-design` skill for implementation. + +## Self-Review Checklist (Agent must verify before completing) + +Before finalizing the plan, verify: + +### Structure +- [ ] Plan has Summary, Code Patterns, Tasks, Notes sections +- [ ] Each story from PRD has corresponding tasks +- [ ] No orphaned tasks (all tasks under a story header) + +### Task Quality +- [ ] Every task has Scope, Acceptance, Verification +- [ ] Verification commands are copy-paste executable +- [ ] Tasks reference specific file paths (not "the auth file") +- [ ] Tasks are independently shippable (no hidden dependencies) + +### Boundaries Compliance +- [ ] No tasks require ⚠️ Ask First actions without noting it +- [ ] No tasks violate 🚫 Never rules +- [ ] High-risk tasks explicitly flagged + +### Completeness +- [ ] All incomplete PRD stories have tasks +- [ ] Commands section filled from package.json/Makefile +- [ ] Testing strategy documented +- [ ] Code patterns extracted from actual codebase (not generic) diff --git a/docs/PLAN_IMPROVEMENT_GUIDE.md b/docs/PLAN_IMPROVEMENT_GUIDE.md new file mode 100644 index 0000000..451df7f --- /dev/null +++ b/docs/PLAN_IMPROVEMENT_GUIDE.md @@ -0,0 +1,659 @@ +# Ralph CLI Plan Step Improvement Guide + +Based on [How to Write a Good Spec for AI Agents](https://addyosmani.com/blog/good-spec/) by Addy Osmani. + +**Purpose:** This document identifies gaps in Ralph's plan step implementation and provides actionable improvements aligned with industry best practices for AI agent specifications. + +--- + +## Table of Contents + +1. [Executive Summary](#executive-summary) +2. [Current State Analysis](#current-state-analysis) +3. [Gap Analysis by Principle](#gap-analysis-by-principle) +4. [Improvement Roadmap](#improvement-roadmap) +5. [Implementation Details](#implementation-details) +6. [File Change Matrix](#file-change-matrix) + +--- + +## Executive Summary + +### What's Working Well + +| Strength | Implementation | +|----------|----------------| +| High-level to detailed flow | PRD β†’ Plan β†’ Build pipeline | +| Code pattern extraction | Plans require 2-3 concrete examples from codebase | +| Quality scoring | `plan-reviewer.js` scores plans 0-100 | +| Task structure | Scope/Acceptance/Verification fields required | +| Lessons learned | `guardrails.md` captures failure patterns | + +### Key Gaps to Address + +| Gap | Impact | Priority | +|-----|--------|----------| +| No three-tier boundary system (βœ…βš οΈπŸš«) | Agents may overstep or under-deliver | **High** | +| Missing Commands section | No copy-paste verification commands | **High** | +| Monolithic prompt (253 lines) | Context overload, performance drops | **Medium** | +| No explicit Testing section | Test expectations unclear | **Medium** | +| No Git Workflow section | Inconsistent commit practices | **Low** | +| No Project Structure section | Navigation ambiguity | **Low** | + +--- + +## Current State Analysis + +### Key Files in Plan Step + +| File | Purpose | Lines | +|------|---------|-------| +| `.agents/ralph/PROMPT_plan.md` | Main planning prompt | 253 | +| `.agents/ralph/PROMPT_build.md` | Build execution prompt | ~400 | +| `lib/review/plan-reviewer.js` | Quality validation | 809 | +| `skills/prd/SKILL.md` | PRD generation skill | 354 | +| `.agents/ralph/loop.sh` | Execution engine | 4224 | + +### Current Plan Template Structure + +``` +# Implementation Plan +β”œβ”€β”€ ## Summary +β”œβ”€β”€ ## Code Patterns (2-3 examples) +β”œβ”€β”€ ## Tasks +β”‚ └── ### US-XXX: Story Title +β”‚ └── - [ ] Task +β”‚ β”œβ”€β”€ Scope: what + where +β”‚ β”œβ”€β”€ Acceptance: outcomes +β”‚ └── Verification: commands +β”œβ”€β”€ ## Notes +└── ## Skill Routing (frontend only) +``` + +### Current Quality Scoring (plan-reviewer.js) + +| Dimension | Points | Current Checks | +|-----------|--------|----------------| +| Structure | 20 | Title, Summary, Tasks, headers | +| Task Quality | 30 | Scope/Acceptance/Verification fields | +| Code Patterns | 20 | Examples, project refs, error handling | +| Completeness | 15 | All PRD stories covered | +| Actionability | 15 | Executable commands, specific paths | + +--- + +## Gap Analysis by Principle + +### Principle 1: Structure Like a PRD (6 Sections) + +**Article recommends these 6 essential sections:** + +| Section | Article Description | Ralph Status | Gap | +|---------|---------------------|--------------|-----| +| **Commands** | Full executable commands with flags | ❌ Missing | No central command reference | +| **Testing** | Framework, locations, coverage | ⚠️ Partial | Buried in Verification fields | +| **Project Structure** | Explicit directory organization | ❌ Missing | No structure reference | +| **Code Style** | Real code examples | βœ… Present | Has Code Patterns section | +| **Git Workflow** | Branch naming, commits, PRs | ❌ Missing | Exists in skills/commit but not in plans | +| **Boundaries** | Always/Ask/Never tiers | ⚠️ Partial | Has rules but flat structure | + +**Current in PROMPT_plan.md (lines 20-27):** +```markdown +## Rules (Non-Negotiable) + +- Do NOT implement anything. +- Do NOT run tests or modify source code. +- Do NOT ask the user questions. +- Plan only. +- Do NOT assume missing functionality; confirm by reading code. +``` + +**Article recommends:** +```markdown +## Boundaries + +### βœ… Always (No approval needed) +- Read any file in the codebase +- Run read-only git commands + +### ⚠️ Ask First (Human review required) +- Changes to public APIs +- Database schema modifications + +### 🚫 Never (Hard stops) +- Commit secrets +- Skip type checking +``` + +--- + +### Principle 2: Break Into Modular Prompts + +**Article insight:** "Research confirms that excessive instructions cause performance drops significantly as requirements pile up." + +**Current state:** +- `PROMPT_plan.md`: 253 lines (single monolithic file) +- `PROMPT_build.md`: ~400 lines (single monolithic file) +- All guidance loaded regardless of PRD type + +**Article recommends:** +- Divide specs into focused components (backend/frontend) +- Create extended table-of-contents summaries +- Use subagents for specialized domains +- Feed only relevant spec sections per task + +**Gap:** Ralph currently has PRD type detection (frontend/backend/full-stack) at lines 36-39 of PROMPT_plan.md, but still loads the entire prompt regardless. + +--- + +### Principle 3: Build in Self-Checks & Constraints + +**Article's three-tier boundary system:** + +| Tier | Symbol | Purpose | Example | +|------|--------|---------|---------| +| Always | βœ… | No approval needed | Run tests, read files | +| Ask First | ⚠️ | Human review required | API changes, new deps | +| Never | 🚫 | Hard stops | Secrets, force push | + +**Current implementation gaps:** + +1. **No tiered boundaries** - Rules are binary (do/don't) +2. **No self-verification step** - Plans don't include review checklist +3. **No domain expertise injection** - Library pitfalls not documented + +**Current guardrails.md approach:** +- Captures lessons learned post-failure +- Not proactively injected into planning + +--- + +### Principle 4: Test, Iterate & Evolve + +**Article recommends:** +- Automated conformance suites +- Context management systems +- Comprehensive logging of agent reasoning + +**Current strengths:** +- `plan-reviewer.js` provides scoring +- `progress.md` tracks execution +- `guardrails.md` captures lessons + +**Gaps:** +- No automated plan validation before build starts +- No feedback loop from build failures to plan improvements +- No living document guidance in plans + +--- + +## Improvement Roadmap + +### Phase 1: High Priority (Quick Wins) + +#### 1.1 Add Three-Tier Boundary System + +**Files to modify:** +- `.agents/ralph/PROMPT_plan.md` +- `.agents/ralph/PROMPT_build.md` + +**Add this section to both prompts:** + +```markdown +## Agent Boundaries + +### βœ… Always (No approval needed) +- Read any file in the codebase +- Run read-only commands: `git status`, `git log`, `npm test`, `npm run build` +- Update progress.md after completing each task +- Reference existing code patterns before writing new code +- Run type checking before marking task complete + +### ⚠️ Ask First (Requires human confirmation) +- Changes to public API signatures or contracts +- Database schema modifications or migrations +- Adding new external dependencies +- Deleting files or removing functionality +- Changes to authentication/authorization logic +- Modifications to CI/CD configuration + +### 🚫 Never (Hard stops - will cause build failure) +- Commit secrets, API keys, or credentials +- Push directly to main/master branch +- Skip type checking or linting +- Assume missing functionality exists (verify by reading code) +- Modify files outside the project scope +- Use `--force` flags on git commands +- Disable or skip tests to make them pass +``` + +#### 1.2 Add Commands Section to Plan Template + +**File to modify:** `.agents/ralph/PROMPT_plan.md` + +**Add after Summary section in template:** + +```markdown +## Commands Reference + +Before starting implementation, document the project's key commands: + +### Build & Development +- Build: `[exact command from package.json or Makefile]` +- Dev server: `[command]` +- Watch mode: `[command]` + +### Testing +- Unit tests: `[command]` +- Integration tests: `[command]` +- E2E tests: `[command]` +- Coverage: `[command]` + +### Quality +- Lint: `[command]` +- Type check: `[command]` +- Format: `[command]` + +### Deployment (if applicable) +- Deploy staging: `[command]` +- Deploy production: `[command]` + +**Agent instruction:** Extract these from package.json, Makefile, or project documentation. These commands will be used in task Verification fields. +``` + +#### 1.3 Update Plan Reviewer + +**File to modify:** `lib/review/plan-reviewer.js` + +**Add new check for Commands section:** + +```javascript +// Add to checkPlanStructure function +const hasCommands = lines.some(line => /^## Commands/i.test(line)); +if (hasCommands) { + result.score += 3; + result.checks.hasCommands = true; +} else { + result.issues.push({ + severity: 'medium', + type: 'missing_commands', + message: 'Plan missing ## Commands section with executable commands' + }); +} + +// Add to checkPlanStructure result.checks +hasCommands: false, +``` + +--- + +### Phase 2: Medium Priority (Structural Improvements) + +#### 2.1 Modularize Prompts + +**Current:** Single 253-line PROMPT_plan.md + +**Proposed structure:** + +``` +.agents/ralph/prompts/ +β”œβ”€β”€ plan/ +β”‚ β”œβ”€β”€ base.md # Core rules (50 lines) +β”‚ β”œβ”€β”€ boundaries.md # Three-tier system (30 lines) +β”‚ β”œβ”€β”€ frontend.md # Frontend-specific (40 lines) +β”‚ β”œβ”€β”€ backend.md # Backend-specific (40 lines) +β”‚ β”œβ”€β”€ patterns.md # Code pattern extraction (30 lines) +β”‚ └── template.md # Output format (40 lines) +β”œβ”€β”€ build/ +β”‚ β”œβ”€β”€ base.md +β”‚ β”œβ”€β”€ boundaries.md +β”‚ β”œβ”€β”€ verification.md +β”‚ └── commit.md +└── shared/ + β”œβ”€β”€ commands.md # Reusable commands reference + └── testing.md # Testing strategy template +``` + +**Modification to loop.sh:** + +```bash +# In render_prompt function, conditionally include modules +render_prompt() { + local prd_type=$(detect_prd_type "$PRD_PATH") + local base_prompt=$(cat "$PROMPTS_DIR/plan/base.md") + local boundaries=$(cat "$PROMPTS_DIR/plan/boundaries.md") + + # Conditional inclusion based on PRD type + case "$prd_type" in + frontend) + local specific=$(cat "$PROMPTS_DIR/plan/frontend.md") + ;; + backend) + local specific=$(cat "$PROMPTS_DIR/plan/backend.md") + ;; + *) + local specific="" + ;; + esac + + # Compose final prompt + echo "$base_prompt" + echo "$boundaries" + echo "$specific" + echo "$(cat "$PROMPTS_DIR/plan/template.md")" +} +``` + +#### 2.2 Add Testing Section + +**Add to PROMPT_plan.md template:** + +```markdown +## Testing Strategy + +### Test Framework & Locations +- Framework: [Jest/Vitest/Pytest/etc.] +- Unit tests: `tests/unit/` or `**/*.test.ts` +- Integration tests: `tests/integration/` +- E2E tests: `tests/e2e/` or `cypress/` + +### Coverage Requirements +- New code: Minimum 80% coverage +- Critical paths: 100% coverage required +- Existing pattern: See `tests/example.test.ts` + +### Test Commands +- Run all: `npm test` +- Run specific: `npm test -- --grep "pattern"` +- Watch mode: `npm test -- --watch` +- Coverage report: `npm test -- --coverage` + +### Testing Patterns (from codebase) +```[language] +// Example test from actual project +// Found in: tests/example.test.ts +describe('FeatureName', () => { + it('should handle expected case', () => { + // Test pattern used in this project + }); +}); +``` + +**Agent instruction:** Extract testing patterns from actual test files. Use these patterns for new tests. +``` + +#### 2.3 Add Git Workflow Section + +**Add to PROMPT_plan.md template:** + +```markdown +## Git Workflow + +### Branch Naming +- Feature: `feature/US-XXX-short-description` +- Bugfix: `fix/US-XXX-short-description` +- Refactor: `refactor/US-XXX-short-description` + +### Commit Format +Use conventional commits (enforced by `/commit` skill): +- `feat(scope): add new feature` +- `fix(scope): resolve bug` +- `refactor(scope): improve code structure` +- `test(scope): add tests` +- `docs(scope): update documentation` + +### Commit Granularity +- One commit per story minimum +- Atomic commits (each commit should pass tests) +- Use `/commit` skill for message generation + +### PR Requirements (if applicable) +- Title: `[US-XXX] Story title` +- Description: Summary of changes +- Tests: All passing +- Review: Required before merge +``` + +--- + +### Phase 3: Low Priority (Polish) + +#### 3.1 Add Project Structure Section + +**Add to PROMPT_plan.md template:** + +```markdown +## Project Structure Reference + +Document the project's directory layout before planning: + +``` +project/ +β”œβ”€β”€ src/ # Source code +β”‚ β”œβ”€β”€ components/ # UI components +β”‚ β”œβ”€β”€ services/ # Business logic +β”‚ β”œβ”€β”€ utils/ # Shared utilities +β”‚ └── types/ # TypeScript types +β”œβ”€β”€ tests/ # Test files +β”œβ”€β”€ docs/ # Documentation +└── config/ # Configuration files +``` + +**Key locations:** +- Entry point: `src/index.ts` +- Routes/API: `src/routes/` or `src/api/` +- Shared types: `src/types/` +- Test helpers: `tests/helpers/` + +**Agent instruction:** Map your tasks to specific directories. Reference existing files in the same directory for patterns. +``` + +#### 3.2 Add Self-Review Checklist + +**Add to end of PROMPT_plan.md:** + +```markdown +## Self-Review Checklist (Agent must verify before completing) + +Before finalizing the plan, verify: + +### Structure +- [ ] Plan has Summary, Code Patterns, Tasks, Notes sections +- [ ] Each story from PRD has corresponding tasks +- [ ] No orphaned tasks (all tasks under a story header) + +### Task Quality +- [ ] Every task has Scope, Acceptance, Verification +- [ ] Verification commands are copy-paste executable +- [ ] Tasks reference specific file paths (not "the auth file") +- [ ] Tasks are independently shippable (no hidden dependencies) + +### Boundaries Compliance +- [ ] No tasks require ⚠️ Ask First actions without noting it +- [ ] No tasks violate 🚫 Never rules +- [ ] High-risk tasks explicitly flagged + +### Completeness +- [ ] All incomplete PRD stories have tasks +- [ ] Commands section filled from package.json/Makefile +- [ ] Testing strategy documented +- [ ] Code patterns extracted from actual codebase (not generic) +``` + +--- + +## Implementation Details + +### Change 1: Three-Tier Boundaries + +**File:** `.agents/ralph/PROMPT_plan.md` + +**Location:** After line 27 (after current Rules section) + +**Action:** Replace current "Rules (Non-Negotiable)" with structured boundaries + +**Before (lines 20-27):** +```markdown +## Rules (Non-Negotiable) + +- Do NOT implement anything. +- Do NOT run tests or modify source code. +- Do NOT ask the user questions. +- Plan only. +- Do NOT assume missing functionality; confirm by reading code. +- Treat shared utilities (if present) as the standard library; prefer existing patterns over ad-hoc copies. +``` + +**After:** +```markdown +## Agent Boundaries + +### Plan Mode Constraints +- Do NOT implement anything +- Do NOT run tests or modify source code +- Do NOT ask the user questions +- Plan only + +### βœ… Always (No approval needed) +- Read any file in the codebase +- Inspect package.json, Makefile, or build configs +- Document existing code patterns +- Reference guardrails.md for known issues + +### ⚠️ Ask First (Flag in plan if required) +- Tasks involving public API changes +- Database schema modifications +- New external dependencies +- File deletions + +### 🚫 Never (Hard stops) +- Assume missing functionality exists (verify by reading code) +- Create generic examples (use actual project code) +- Skip code pattern analysis +- Plan tasks without verification commands +``` + +--- + +### Change 2: Commands Section Template + +**File:** `.agents/ralph/PROMPT_plan.md` + +**Location:** Add to "Implementation Plan Format" section (after line 125) + +**Add:** +```markdown +## Commands Reference (Required) + +Extract from package.json, Makefile, or project docs: + +### Build & Test +- Build: `[command]` +- Test: `[command]` +- Lint: `[command]` +- Type check: `[command]` + +### Development +- Dev server: `[command]` +- Watch: `[command]` + +**Note:** These commands will be referenced in task Verification fields. Verify they work before including. +``` + +--- + +### Change 3: Plan Reviewer Updates + +**File:** `lib/review/plan-reviewer.js` + +**Add new checks:** + +```javascript +// 1. Add to checkPlanStructure (around line 195) +// Check for Commands section (3 points) +const hasCommands = lines.some(line => /^##\s*Commands/i.test(line)); +if (hasCommands) { + result.score += 3; + result.checks.hasCommands = true; +} else { + result.issues.push({ + severity: 'medium', + type: 'missing_commands', + message: 'Plan missing ## Commands section' + }); +} + +// 2. Add to checkPlanStructure result.checks object (around line 155) +hasCommands: false, + +// 3. Add to generateRecommendations (around line 700) +if (!result.breakdown.structure.checks.hasCommands) { + recommendations.push({ + priority: 'medium', + message: 'Add ## Commands section with build/test/lint commands from package.json' + }); +} +``` + +**Adjust scoring:** Reduce other structure points by 3 to accommodate (or increase max to 23). + +--- + +## File Change Matrix + +| File | Change Type | Priority | Effort | +|------|-------------|----------|--------| +| `.agents/ralph/PROMPT_plan.md` | Modify | High | Low | +| `.agents/ralph/PROMPT_build.md` | Modify | High | Low | +| `lib/review/plan-reviewer.js` | Modify | Medium | Low | +| `.agents/ralph/prompts/` (new dir) | Create | Medium | Medium | +| `.agents/ralph/loop.sh` | Modify | Medium | Medium | +| `skills/prd/SKILL.md` | Modify | Low | Low | + +### Detailed File Changes + +#### `.agents/ralph/PROMPT_plan.md` + +| Section | Line Range | Change | +|---------|------------|--------| +| Rules | 20-27 | Replace with three-tier boundaries | +| Plan Format | 125-165 | Add Commands section template | +| Plan Format | 165+ | Add Testing section template | +| Plan Format | 165+ | Add Git Workflow section | +| End of file | 250+ | Add Self-Review Checklist | + +#### `.agents/ralph/PROMPT_build.md` + +| Section | Change | +|---------|--------| +| Rules | Add matching three-tier boundaries | +| Verification | Reference Commands section from plan | + +#### `lib/review/plan-reviewer.js` + +| Function | Change | +|----------|--------| +| `checkPlanStructure` | Add Commands section check (+3 points) | +| `checkPlanStructure` | Add Testing section check (+2 points) | +| `generateRecommendations` | Add recommendations for new sections | + +--- + +## Validation Criteria + +After implementing changes, verify: + +1. **New plans include Commands section** with actual project commands +2. **Boundaries are three-tiered** with βœ…βš οΈπŸš« symbols +3. **Plan reviewer scores** include new section checks +4. **Agent behavior** respects boundary tiers during build +5. **No regression** in existing plan quality scores + +--- + +## References + +- [How to Write a Good Spec for AI Agents](https://addyosmani.com/blog/good-spec/) - Addy Osmani +- [good-spec-cheatsheet.md](./good-spec-cheatsheet.md) - Quick reference +- Current implementation: `.agents/ralph/PROMPT_plan.md` +- Quality reviewer: `lib/review/plan-reviewer.js` diff --git a/docs/good-spec-cheatsheet.md b/docs/good-spec-cheatsheet.md new file mode 100644 index 0000000..5d5f792 --- /dev/null +++ b/docs/good-spec-cheatsheet.md @@ -0,0 +1,98 @@ +# How to Write a Good Spec for AI Agents + +*Cheatsheet from [addyosmani.com/blog/good-spec](https://addyosmani.com/blog/good-spec/)* + +--- + +## 5 Core Principles + +### 1. Start High-Level, Let AI Expand + +- Begin with concise product brief, not over-engineered specs +- Use **Plan Mode** (read-only) to enforce planning before coding +- Create persistent reference document for project duration + +### 2. Structure Like a PRD + +**6 Essential Sections:** + +| Section | What to Include | +|---------|-----------------| +| Commands | Full executable commands with flags | +| Testing | Framework, file locations, coverage expectations | +| Project Structure | Explicit directory organization | +| Code Style | Real code examples of your conventions | +| Git Workflow | Branch naming, commit formats, PR requirements | +| Boundaries | Always do / Ask first / Never touch | + +### 3. Break Into Modular Prompts + +- Avoid monolithic prompts (causes performance drops) +- Divide specs by domain (backend/frontend) +- Feed only relevant sections per task +- Refresh context between major features +- Use subagents for specialized domains + +### 4. Build in Self-Checks & Constraints + +**Three-tier boundary system:** + +- βœ… **Always** - Actions requiring no approval +- ⚠️ **Ask first** - High-impact decisions needing review +- 🚫 **Never** - Hard stops (e.g., never commit secrets) + +Include: library pitfalls, edge cases, domain preferences + +### 5. Test, Iterate & Evolve + +- Treat specs as living documents +- Version control your specs +- Update when discovering gaps +- Log agent reasoning for debugging + +--- + +## Template + +```markdown +# Project Spec: [Name] + +## Objective +[Clear goal statement] + +## Tech Stack +[Specific versions and dependencies] + +## Commands +- Build: `[command]` +- Test: `[command]` +- Lint: `[command]` + +## Project Structure +- src/ – Application code +- tests/ – Test files +- docs/ – Documentation + +## Boundaries +- βœ… Always: [specific practices] +- ⚠️ Ask first: [high-impact changes] +- 🚫 Never: [prohibited actions] +``` + +--- + +## Anti-Patterns to Avoid + +| Don't | Do Instead | +|-------|------------| +| Vague prompts ("Build something cool") | Clear goal statements | +| Overlong contexts | Hierarchical summaries | +| Skip human review | Review critical code paths | +| Confuse prototyping with production | Separate concerns explicitly | +| Missing core spec sections | Include all 6 sections | + +--- + +## Key Insight + +> Specs are **executable artifacts** that drive implementation, testing, and task breakdownsβ€”not afterthoughts. Balance thoroughness with focus. diff --git a/lib/review/plan-reviewer.js b/lib/review/plan-reviewer.js index 21947bd..7403839 100644 --- a/lib/review/plan-reviewer.js +++ b/lib/review/plan-reviewer.js @@ -20,7 +20,7 @@ function reviewPlan(planPath, prdPath = null) { grade: "F", score: 0, breakdown: { - structure: { score: 0, max: 20, issues: [] }, + structure: { score: 0, max: 25, issues: [] }, // Increased from 20 for Commands/Testing sections taskQuality: { score: 0, max: 30, issues: [] }, codePatterns: { score: 0, max: 20, issues: [] }, completeness: { score: 0, max: 15, issues: [] }, @@ -139,17 +139,29 @@ function extractPRDStories(prdContent) { } /** - * Check plan structure (20 points) + * Check plan structure (25 points max) + * - Title header: 4 points + * - Summary section: 4 points + * - Tasks section: 4 points + * - Commands section: 3 points + * - Testing section: 2 points (optional) + * - Story header format: 5 points + * - Task checkboxes: 3 points + * @param {string} content - Full plan content + * @param {string[]} lines - Plan content split by lines + * @returns {object} Structure check result with score, issues, and checks */ function checkPlanStructure(content, lines) { const result = { score: 0, - max: 20, + max: 25, // Increased from 20 to accommodate new sections issues: [], checks: { hasTitle: false, hasSummary: false, hasTasks: false, + hasCommands: false, + hasTesting: false, storyHeadersCorrect: true, allPRDStoriesPresent: true, }, @@ -196,6 +208,29 @@ function checkPlanStructure(content, lines) { }); } + // Check for Commands section (3 points) + const hasCommands = lines.some((line) => /^##\s*Commands/i.test(line)); + if (hasCommands) { + result.score += 3; + result.checks.hasCommands = true; + } else { + result.issues.push({ + severity: "medium", + type: "missing_commands", + message: "Plan missing ## Commands section with executable commands", + }); + } + + // Check for Testing section (2 points) - optional but recommended + const hasTesting = lines.some((line) => + /^##\s*(Testing|Testing Strategy)/i.test(line) + ); + if (hasTesting) { + result.score += 2; + result.checks.hasTesting = true; + } + // No issue added for missing Testing - it's optional + // Validate story headers match PRD format (5 points) const storyHeaderPattern = /^### (US-\d+):\s*(.*)$/; const storyHeaders = []; @@ -700,8 +735,8 @@ function gradeScore(score) { function generateRecommendations(result) { const recommendations = []; - // Structure recommendations - if (result.breakdown.structure.score < 15) { + // Structure recommendations - core sections (only if score is low) + if (result.breakdown.structure.score < 20) { if (!result.breakdown.structure.checks.hasTitle) { recommendations.push({ priority: "high", @@ -722,6 +757,22 @@ function generateRecommendations(result) { } } + // Structure recommendations - optional sections (always check) + if (!result.breakdown.structure.checks.hasCommands) { + recommendations.push({ + priority: "medium", + message: + "Add ## Commands section with build/test/lint commands from package.json", + }); + } + if (!result.breakdown.structure.checks.hasTesting) { + recommendations.push({ + priority: "low", + message: + "Consider adding ## Testing section with test framework and coverage requirements", + }); + } + // Task quality recommendations if (result.breakdown.taskQuality.score < 20) { const missingScope = result.issues.filter(