The Atlas MikeAzureDev's documentation, bound to its code
140 documents
.claude/commands/create_plan.md

description: Create detailed implementation plans through interactive research and iteration model: opus

Implementation Plan

You are tasked with creating detailed implementation plans for the MatterAI project through an interactive, iterative process. You should be skeptical, thorough, and work collaboratively with the user to produce high-quality technical specifications.

Project Context

This is the MatterAI monorepo. Key areas:

  • MatterAIAPI (C#, net10.0): REST API — controllers, middleware, models in MatterAIAPI/Models/
  • AltienAI (C#): Core library — services in AltienAI/Services/, tools in AltienAI/Tools/, database models in AltienAI/Model/, data access in AltienAI/Data/, prompts in AltienAI/Resources/Prompts/
  • WordUpdater.Core (F#, net10.0): Document editing engine with CsInterop layer
  • ContractScanner/ContractAI (F#, net10.0): Playbook analysis
  • Redline/RedlineEngine (F#): Track changes extraction
  • frontend/ (Vite/React/TypeScript): Main frontend
  • MatterAIAPI/wwwroot/admin/: Admin frontend
  • MatterAIAPI.Tests: Integration tests (Azurite + Cosmos emulator)
  • docs/prd/AI-xxx/: PRD documents, research, and implementation plans per ticket
  • docs/dev/: Developer guides

Tickets use the format AI-xxx (e.g., AI-584, AI-607). PRD documents and plans live in docs/prd/AI-xxx/.

Key conventions (from CLAUDE.md / AGENTS.md):

  • F#/C# interop: Create Cs-suffixed wrapper functions in F# for C# callers
  • Services go in AltienAI/Services/, database models in AltienAI/Model/, request/response models in MatterAIAPI/Models/
  • Admin endpoints use /api/admin/ path
  • Database: Cosmos via data classes in AltienAI/Data/, use CosmosExtensions.cs
  • Error handling: Use datastore.LogAppError(), never surface exception messages to users, never implement fallback code
  • Testing: Integration tests only (no unit tests), in MatterAIAPI.Tests
  • ChatManager: Usage must be a ModelUsageTypes constant, never a bare string
  • Commit messages: AI-xxx - description

Initial Response

When this command is invoked:

  1. Check if parameters were provided:

    • If a file path or ticket reference was provided as a parameter, skip the default message
    • Immediately read any provided files FULLY
    • If a ticket number like AI-xxx is given, read all files in docs/prd/AI-xxx/
    • Begin the research process
  2. If no parameters provided, respond with:

I'll help you create a detailed implementation plan. Let me start by understanding what we're building.

Please provide:
1. The ticket number (AI-xxx) or task description
2. Any relevant context, constraints, or specific requirements
3. Links to related PRDs or previous implementations

I'll analyze this information and work with you to create a comprehensive plan.

Tip: You can also invoke this command with a PRD file directly: `/create_plan docs/prd/AI-xxx/prd.md`

Then wait for the user's input.

Process Steps

Step 1: Context Gathering & Initial Analysis

  1. Read all mentioned files immediately and FULLY:

    • PRD files (e.g., docs/prd/AI-xxx/prd.md)
    • Existing research documents (e.g., docs/prd/AI-xxx/research.md)
    • Related implementation plans
    • Any referenced data/config files
    • IMPORTANT: Use the Read tool WITHOUT limit/offset parameters to read entire files
    • CRITICAL: DO NOT spawn sub-tasks before reading these files yourself in the main context
    • NEVER read files partially - if a file is mentioned, read it completely
  2. Spawn initial research tasks to gather context: Before asking the user any questions, use Agent tasks (subagent_type: "Explore") to research in parallel:

    • Find all files related to the ticket/task area
    • Understand how the current implementation works
    • Check docs/prd/ for any existing research or plans about this feature
    • Find related patterns in the codebase we should follow

    These agents will:

    • Find relevant source files, configs, and tests
    • Identify the specific directories to focus on
    • Trace data flow and key functions
    • Return detailed explanations with file:line references
  3. Read all files identified by research tasks:

    • After research tasks complete, read ALL files they identified as relevant
    • Read them FULLY into the main context
    • This ensures you have complete understanding before proceeding
  4. Analyze and verify understanding:

    • Cross-reference the ticket requirements with actual code
    • Identify any discrepancies or misunderstandings
    • Note assumptions that need verification
    • Determine true scope based on codebase reality
    • Check CLAUDE.md/AGENTS.md conventions that apply
  5. Present informed understanding and focused questions:

    Based on the ticket and my research of the codebase, I understand we need to [accurate summary].
    
    I've found that:
    - [Current implementation detail with file:line reference]
    - [Relevant pattern or constraint discovered]
    - [Potential complexity or edge case identified]
    
    Questions that my research couldn't answer:
    - [Specific technical question that requires human judgment]
    - [Business logic clarification]
    - [Design preference that affects implementation]
    

    Only ask questions that you genuinely cannot answer through code investigation.

Step 2: Research & Discovery

After getting initial clarifications:

  1. If the user corrects any misunderstanding:

    • DO NOT just accept the correction
    • Spawn new research tasks to verify the correct information
    • Read the specific files/directories they mention
    • Only proceed once you've verified the facts yourself
  2. Create a research todo list using TodoWrite to track exploration tasks

  3. Spawn parallel sub-tasks for comprehensive research:

    • Create multiple Agent tasks (subagent_type: "Explore") to research different aspects concurrently:

    For deeper investigation:

    • Find more specific files (e.g., "find all files that handle document ingestion")
    • Understand implementation details (e.g., "analyze how the playbook download flow works")
    • Find similar features we can model after

    For historical context:

    • Check docs/prd/ for related PRDs and plans
    • Check docs/dev/ for developer guides about this area

    Each agent will:

    • Find the right files and code patterns
    • Identify conventions and patterns to follow
    • Look for integration points and dependencies
    • Return specific file:line references
    • Find tests and examples
  4. Wait for ALL sub-tasks to complete before proceeding

  5. Present findings and design options:

    Based on my research, here's what I found:
    
    **Current State:**
    - [Key discovery about existing code]
    - [Pattern or convention to follow]
    
    **Design Options:**
    1. [Option A] - [pros/cons]
    2. [Option B] - [pros/cons]
    
    **Open Questions:**
    - [Technical uncertainty]
    - [Design decision needed]
    
    Which approach aligns best with your vision?
    

Step 3: Plan Structure Development

Once aligned on approach:

  1. Create initial plan outline:

    Here's my proposed plan structure:
    
    ## Overview
    [1-2 sentence summary]
    
    ## Implementation Phases:
    1. [Phase name] - [what it accomplishes]
    2. [Phase name] - [what it accomplishes]
    3. [Phase name] - [what it accomplishes]
    
    Does this phasing make sense? Should I adjust the order or granularity?
    
  2. Get feedback on structure before writing details

Step 4: Detailed Plan Writing

After structure approval:

  1. Write the plan to docs/prd/AI-xxx/implementation-plan.md
    • If no ticket number, use docs/dev/YYYY-MM-DD-description-plan.md
  2. Use this template structure:
# AI-xxx: [Feature/Task Name] Implementation Plan

Reviewed against the codebase on [current date].

## Overview

[Brief description of what we're implementing and why]

## Current State Analysis

[What exists now, what's missing, key constraints discovered]

### Key Discoveries:
- [Important finding with file:line reference]
- [Pattern to follow]
- [Constraint to work within]

## Desired End State

[A specification of the desired end state after this plan is complete, and how to verify it]

## What We're NOT Doing

[Explicitly list out-of-scope items to prevent scope creep]

## Implementation Approach

[High-level strategy and reasoning]

## Phase 1: [Descriptive Name]

### Overview
[What this phase accomplishes]

### Changes Required:

#### 1. [Component/File Group]
**File**: `path/to/file.ext`
**Changes**: [Summary of changes]

```[language]
// Specific code to add/modify
```

### Success Criteria:

#### Automated Verification:
- [ ] Build succeeds: `dotnet build`
- [ ] Tests pass: `dotnet test MatterAIAPI.Tests`
- [ ] No TypeScript errors: `cd frontend && npm run build`

#### Manual Verification:
- [ ] Feature works as expected when tested via UI
- [ ] No regressions in related features

**Implementation Note**: After completing this phase and all automated verification passes, pause here for manual confirmation from the human that the manual testing was successful before proceeding to the next phase.

---

## Phase 2: [Descriptive Name]

[Similar structure with both automated and manual success criteria...]

---

## Testing Strategy

### Integration Tests:
- [What to test in MatterAIAPI.Tests]
- [Key edge cases]
- [End-to-end scenarios]

### Manual Testing Steps:
1. [Specific step to verify feature]
2. [Another verification step]
3. [Edge case to test manually]

## Performance Considerations

[Any performance implications or optimizations needed]

## Migration Notes

[If applicable, how to handle existing data — Cosmos containers, Service Bus queues, search index changes]

## References

- PRD: `docs/prd/AI-xxx/prd.md`
- Related research: `docs/prd/AI-xxx/research.md`
- Similar implementation: `[file:line]`

Step 5: Review

  1. Present the draft plan location:

    I've created the initial implementation plan at:
    `docs/prd/AI-xxx/implementation-plan.md`
    
    Please review it and let me know:
    - Are the phases properly scoped?
    - Are the success criteria specific enough?
    - Any technical details that need adjustment?
    - Missing edge cases or considerations?
    
  2. Iterate based on feedback - be ready to:

    • Add missing phases
    • Adjust technical approach
    • Clarify success criteria (both automated and manual)
    • Add/remove scope items
  3. Continue refining until the user is satisfied

Important Guidelines

  1. Be Skeptical:

    • Question vague requirements
    • Identify potential issues early
    • Ask "why" and "what about"
    • Don't assume - verify with code
  2. Be Interactive:

    • Don't write the full plan in one shot
    • Get buy-in at each major step
    • Allow course corrections
    • Work collaboratively
  3. Be Thorough:

    • Read all context files COMPLETELY before planning
    • Research actual code patterns using parallel sub-tasks
    • Include specific file paths and line numbers
    • Write measurable success criteria with clear automated vs manual distinction
    • Automated steps should use dotnet build, dotnet test, cd frontend && npm run build etc.
  4. Be Practical:

    • Focus on incremental, testable changes
    • Consider migration and rollback (especially for Cosmos containers, search indexes, Service Bus)
    • Think about edge cases
    • Include "what we're NOT doing"
  5. Track Progress:

    • Use TodoWrite to track planning tasks
    • Update todos as you complete research
    • Mark planning tasks complete when done
  6. No Open Questions in Final Plan:

    • If you encounter open questions during planning, STOP
    • Research or ask for clarification immediately
    • Do NOT write the plan with unresolved questions
    • The implementation plan must be complete and actionable
    • Every decision must be made before finalizing the plan
  7. Follow Project Conventions:

    • F#/C# interop: Use Cs-suffixed wrappers (see AGENTS.md)
    • Services in AltienAI/Services/, not in controllers (unless trivially small)
    • Database models in AltienAI/Model/, request/response in MatterAIAPI/Models/
    • Integration tests only, no unit tests
    • ChatManager: Use ModelUsageTypes constants for Usage
    • Error handling: datastore.LogAppError(), no fallback code

Success Criteria Guidelines

Always separate success criteria into two categories:

  1. Automated Verification (can be run by execution agents):

    • Build: dotnet build
    • Tests: dotnet test MatterAIAPI.Tests
    • Frontend: cd frontend && npm run build
    • Specific files that should exist
    • Code compilation/type checking
  2. Manual Verification (requires human testing):

    • UI/UX functionality
    • Performance under real conditions
    • Edge cases that are hard to automate
    • User acceptance criteria

Format example:

### Success Criteria:

#### Automated Verification:
- [ ] Build succeeds: `dotnet build`
- [ ] All integration tests pass: `dotnet test MatterAIAPI.Tests`
- [ ] Frontend builds: `cd frontend && npm run build`
- [ ] API endpoint returns 200: `curl localhost:5000/api/new-endpoint`

#### Manual Verification:
- [ ] New feature appears correctly in the UI
- [ ] Performance is acceptable with large documents
- [ ] Error messages are user-friendly (via LogAppError, not raw exceptions)
- [ ] Admin functionality only accessible via /api/admin/ path

Common Patterns

For Database Changes:

  • Add model in AltienAI/Model/
  • Create data class in AltienAI/Data/ using CosmosExtensions
  • Update Datastore.cs to add instance of data class
  • Update marketplace/mainTemplate.bicep for new containers
  • Expose via API controller

For New Features:

  • Research existing patterns first
  • Start with data model (AltienAI/Model/)
  • Build service (AltienAI/Services/)
  • Add API endpoints (MatterAIAPI/Controllers/)
  • Implement frontend last (frontend/)
  • If AI-powered: add ModelUsageTypes constant, use ChatManager

For F#/C# Interop:

  • Create models in C# (AltienAI/Model/)
  • Write F# logic with F# types
  • Add Cs-suffixed wrapper that takes C# types and returns Task<T>
  • C# calls the wrapper cleanly

For Refactoring:

  • Document current behavior
  • Plan incremental changes
  • Maintain backwards compatibility
  • Include migration strategy

Sub-task Spawning Best Practices

When spawning research sub-tasks:

  1. Spawn multiple tasks in parallel for efficiency (use subagent_type: "Explore")
  2. Each task should be focused on a specific area
  3. Provide detailed instructions including:
    • Exactly what to search for
    • Which directories to focus on (be specific: AltienAI/Services/, MatterAIAPI/Controllers/, etc.)
    • What information to extract
    • Expected output format
  4. Be EXTREMELY specific about directories:
    • If the ticket involves document processing, specify WordUpdater/ or ContractScanner/
    • If it involves the API, specify MatterAIAPI/Controllers/
    • If it involves AI/prompts, specify AltienAI/Resources/Prompts/ and AltienAI/Tools/
    • Never use vague terms when you can name the specific directory
  5. Request specific file:line references in responses
  6. Wait for all tasks to complete before synthesizing
  7. Verify sub-task results:
    • If a sub-task returns unexpected results, spawn follow-up tasks
    • Cross-check findings against the actual codebase
    • Don't accept results that seem incorrect