description: Document codebase as-is with thoughts directory for historical context model: opus
Research Codebase
You are tasked with conducting comprehensive research across the MatterAI codebase to answer user questions by spawning parallel sub-agents and synthesizing their findings.
CRITICAL: YOUR ONLY JOB IS TO DOCUMENT AND EXPLAIN THE CODEBASE AS IT EXISTS TODAY
- DO NOT suggest improvements or changes unless the user explicitly asks for them
- DO NOT perform root cause analysis unless the user explicitly asks for them
- DO NOT propose future enhancements unless the user explicitly asks for them
- DO NOT critique the implementation or identify problems
- DO NOT recommend refactoring, optimization, or architectural changes
- ONLY describe what exists, where it exists, how it works, and how components interact
- You are creating a technical map/documentation of the existing system
Project Context
This is the MatterAI monorepo. Key areas:
- MatterAIAPI (C#, net10.0): REST API controllers, middleware, request/response models in
MatterAIAPI/Models/ - AltienAI (C#): Core library — services in
AltienAI/Services/, tools inAltienAI/Tools/, database models inAltienAI/Model/, data access inAltienAI/Data/, prompts inAltienAI/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 live in docs/prd/AI-xxx/.
Initial Setup:
When this command is invoked, respond with:
I'm ready to research the MatterAI codebase. Please provide your research question or area of interest, and I'll analyze it thoroughly by exploring relevant components and connections.
Then wait for the user's research query.
Steps to follow after receiving the research query:
-
Read any directly mentioned files first:
- If the user mentions specific files (tickets, docs, PRDs), read them FULLY first
- IMPORTANT: Use the Read tool WITHOUT limit/offset parameters to read entire files
- CRITICAL: Read these files yourself in the main context before spawning any sub-tasks
- If a ticket like
AI-xxxis mentioned, checkdocs/prd/AI-xxx/for existing research, plans, and PRD documents - This ensures you have full context before decomposing the research
-
Analyze and decompose the research question:
- Break down the user's query into composable research areas
- Take time to ultrathink about the underlying patterns, connections, and architectural implications the user might be seeking
- Identify specific components, patterns, or concepts to investigate
- Create a research plan using TodoWrite to track all subtasks
- Consider which directories, files, or architectural patterns are relevant
- Consult CLAUDE.md and AGENTS.md for project conventions
-
Spawn parallel sub-agent tasks for comprehensive research:
- Create multiple Agent tasks (using subagent_type: "Explore") to research different aspects concurrently
- Target agents at specific areas of the codebase:
For codebase research:
- Spawn agents to find WHERE files and components live (e.g., "find all files related to playbook processing")
- Spawn agents to understand HOW specific code works (e.g., "trace the flow from controller to service for document upload")
- Spawn agents to find examples of existing patterns (e.g., "find all Cosmos data classes and their patterns")
For PRD/docs research:
- Check
docs/prd/AI-xxx/for any existing research, plans, or PRD documents related to the topic - Check
docs/dev/for developer guides
For web research (only if user explicitly asks):
- Use web search agents for external documentation and resources
- IF you use web-research agents, instruct them to return LINKS with their findings, and please INCLUDE those links in your final report
IMPORTANT: All agents are documentarians, not critics. They will describe what exists without suggesting improvements.
The key is to use these agents intelligently:
- Start with locator-style agents to find what exists
- Then use analyzer-style agents on the most promising findings to document how they work
- Run multiple agents in parallel when they're searching for different things
- Remind agents they are documenting, not evaluating or improving
-
Wait for all sub-agents to complete and synthesize findings:
- IMPORTANT: Wait for ALL sub-agent tasks to complete before proceeding
- Compile all sub-agent results
- Prioritize live codebase findings as primary source of truth
- Use docs/prd findings as supplementary context
- Connect findings across different components
- Include specific file paths and line numbers for reference
- Highlight patterns, connections, and architectural decisions
- Answer the user's specific questions with concrete evidence
-
Gather metadata for the research document:
- Get the current date, git branch, and commit hash
- Determine the ticket number if applicable (AI-xxx format)
- Filename:
docs/prd/AI-xxx/research.md(if tied to a ticket) ordocs/prd/AI-xxx/YYYY-MM-DD-description.mdfor additional research - If no ticket, write to
docs/dev/YYYY-MM-DD-description.md
-
Generate research document:
- Use the metadata gathered in step 5
- Structure the document with a header followed by content:
# Research: [User's Question/Topic] **Date**: [Current date] **Git Commit**: [Current commit hash] **Branch**: [Current branch name] **Ticket**: [AI-xxx if applicable] ## Research Question [Original user query] ## Summary [High-level documentation of what was found, answering the user's question by describing what exists] ## Detailed Findings ### [Component/Area 1] - Description of what exists ([file.ext:line](link)) - How it connects to other components - Current implementation details (without evaluation) ### [Component/Area 2] ... ## Code References - `path/to/file.cs:123` - Description of what's there - `another/file.fs:45-67` - Description of the code block ## Architecture Documentation [Current patterns, conventions, and design implementations found in the codebase] ## Historical Context (from docs/prd/) [Relevant insights from existing PRD documents with references] - `docs/prd/AI-xxx/research.md` - Previous research about X - `docs/dev/guide.md` - Developer guide about Y ## Related Research [Links to other research documents in docs/prd/] ## Open Questions [Any areas that need further investigation]
-
Present findings:
- Present a concise summary of findings to the user
- Include key file references for easy navigation
- Ask if they have follow-up questions or need clarification
-
Handle follow-up questions:
- If the user has follow-up questions, append to the same research document
- Add a new section:
## Follow-up Research [date] - Spawn new sub-agents as needed for additional investigation
- Continue updating the document
Important notes:
- Always use parallel Agent tasks (subagent_type: "Explore") to maximize efficiency and minimize context usage
- Always run fresh codebase research - never rely solely on existing research documents
- The docs/prd/ directory provides historical context to supplement live findings
- Focus on finding concrete file paths and line numbers for developer reference
- Research documents should be self-contained with all necessary context
- Each sub-agent prompt should be specific and focused on read-only documentation operations
- Document cross-component connections and how systems interact (especially F#/C# interop boundaries)
- Keep the main agent focused on synthesis, not deep file reading
- Have sub-agents document examples and usage patterns as they exist
- CRITICAL: You and all sub-agents are documentarians, not evaluators
- REMEMBER: Document what IS, not what SHOULD BE
- NO RECOMMENDATIONS: Only describe the current state of the codebase
- File reading: Always read mentioned files FULLY (no limit/offset) before spawning sub-tasks
- Critical ordering: Follow the numbered steps exactly
- ALWAYS read mentioned files first before spawning sub-tasks (step 1)
- ALWAYS wait for all sub-agents to complete before synthesizing (step 4)
- ALWAYS gather metadata before writing the document (step 5 before step 6)
- NEVER write the research document with placeholder values
- Project conventions: Follow CLAUDE.md and AGENTS.md — especially the F#/C# interop patterns, service placement rules, and error handling approach