11 KiB
Task: Implement Story with Integrated Review
Purpose
To execute a user story with a proactive analysis and review cycle, ensuring alignment with existing codebase patterns, modern standards, and a high level of quality before completion.
1. Story Initiation & Analysis Phase
- Check for User Override:
- First, check if the user has explicitly requested to force Review Mode for this story (e.g., "Implement this story in review mode").
- If so, immediately declare: "User has forced Review Mode for this story." and proceed to step 5, skipping the complexity assessment. Log this in the
Dev Notes.
- Establish Temporal Context:
- Run
get-Date -Format "yyyy-MM-dd"and store the current year. Announce the year being used for context-setting (e.g., "Operating with standards context for the year 2024.").
- Run
- Internal Codebase Analysis:
- Action: Use the built-in IDE semantic search capabilities.
- Query: Search the entire codebase for implementations, functions, components, or patterns that are semantically related to the user story's title, description, and Acceptance Criteria.
- Goal: Identify code for potential reuse, and understand existing patterns relevant to the new work. Log these findings internally for use during implementation.
- Dependency & Standards Analysis with Internet Fallback:
- Read the
package.json(or equivalent) to identify currently installed libraries relevant to the story. - [[LLM: Attempt Internet Search: Perform a targeted internet search for "best practices for [library/feature] in [current year]" for any new or significantly updated libraries.]]
- [[LLM: On Success: Silently incorporate the findings and proceed to the next step.]]
- [[LLM: On Failure (If unable to access the internet):
- Announce the situation clearly: "I am currently unable to access the internet to research the latest standards for this task."
- Offer a choice to the user: "Is this expected, or should I attempt to enable access? Alternatively, I can proceed using the best practices from my existing training data."
- Request explicit instruction to continue: "Please let me know how you would like to proceed."
- HALT and await user response. Once the user confirms to continue (with or without them enabling internet access), proceed to the next step using the available knowledge.]]
- Read the
- Initial Complexity Assessment & Mode Declaration:
- Calculate a "Story Complexity" score using Fibonacci scale (1, 2, 3, 5, 8, 13).
- If Review Mode was forced by the user OR if
Story Complexity>agentThresholdStory, declare: "Entering high-scrutiny 'Review Mode' for this story. Each task will be individually assessed." - Otherwise, declare: "Story complexity is within standard limits. Each task will still be individually assessed for complexity."
- Log the complexity score (if calculated) and the reason for the mode in the story's
Dev Notes.
Fibonacci Complexity Guidelines:
- 1: Trivial changes (typos, simple styling)
- 2: Minor feature additions (new button, basic validation)
- 3: Standard feature implementation (form handling, API calls)
- 5: Complex features (authentication, data processing)
- 8: Major architectural changes (new services, database schema)
- 13: High-risk/high-uncertainty work (new frameworks, complex integrations)
2. Unified Task Execution Phase
[[LLM: Proceed with the Tasks / Subtasks list from the story file one by one. The following logic applies to EVERY task.]]
<< For each task in the story's task list: >>
-
Mandatory Task Complexity Assessment:
- Evaluate the complexity of the current task using Fibonacci scale (1, 2, 3, 5, 8, 13), leveraging the initial semantic search results.
- Compare the
Task Complexityscore against theagentThresholdTaskvalue fromcore-config.yml.
-
Conditional Implementation Path:
- If
Task Complexity>agentThresholdTask:- Announce: "Task complexity is high. Activating internal review process."
- Execute the Internal Review Process (Section 3) for this task.
- Else (Task Complexity is low):
- Announce: "Task complexity is low. Implementing directly."
- Implement the task, continuously referencing the initial analysis for code reuse opportunities.
- If
-
Testing and Completion:
- Once the task is implemented (either directly or after passing review), write and pass all required tests.
- Mark the task checkbox as complete:
[x].
3. The Internal Review Process (Self-Critique)
-
Enact Reviewer Persona: State "Activating The Reviewer for self-critique."
-
Propose Implementation: As the
devagent, write the proposed code for the task. -
Critique as Reviewer: As "The Reviewer," analyze the proposed code against the following criteria:
- Code Duplication: "Does this logic already exist in [file/function from semantic search]? If so, fail."
- Syntax & Errors: "Are there obvious syntax, linting, or TypeScript errors? If so, fail."
- Standards Alignment: "Does this align with the project's coding standards and the patterns discovered in the initial analysis? If not, fail."
-
Handle Review Failure: If any check fails, as "The Reviewer," provide specific, actionable feedback. Then, as the
devagent, go back to step 2 to create a revised implementation. Repeat this loop until the code is approved. -
Log a Successful Review: Once "The Reviewer" approves the code, generate a summary for the
Dev Notessection of the story:**Internal Review Summary for Task [Task #]** - **Submissions**: [Number] - **Failed Attempts**: - **Attempt 1**: [Describe problematic code briefly and why it failed, e.g., "Created duplicate login logic already present in `auth.service.ts`."] - **Attempt N**: ... - **Final Solution**: [Describe the approved approach, e.g., "Refactored to use the existing `authenticateUser` function from `auth.service.ts`."] - **Lessons Learned**: [Note any new patterns or insights, e.g., "All authentication logic must be centralized in the auth service; direct token manipulation is an anti-pattern in this codebase."]
4. Finalize Story
[[LLM: After all tasks are marked [x], run the story-dod-checklist. Do not proceed until the checklist is passed.]]
- Execute the
story-dod-checklisttask. - Address any issues found during the self-check.
- Once the checklist is fully passed, change the story status to
Review.
5. Memory Synthesis & Validation
- Enact Synthesizer Persona: Announce "Finalizing work. Switching to Memory Synthesizer persona to distill and validate learnings from all notes."
- Comprehensive Knowledge Extraction (Two-Pass Analysis):
LLM: First, extract high-confidence, explicit lessons. Then, perform a broader scan for implicit knowledge.
- Pass 1: Explicit Lessons: Parse the
Dev Notessection for allInternal Review Summaryblocks. Extract the "Lessons Learned," "Final Solution," and "Failed Attempts" content. These are your high-priority, explicit memories. - Pass 2: Implicit Lessons: Read the entire
Dev Notessection again (includingCompletion Notes,Debug Log References, andChange Log). Use LLM intelligence to identify potential patterns or learnings that were not part of a formal review. Look for:- Unexpected workarounds or solutions.
- Reasons for deviating from the original plan.
- Notes about dependency versions or compatibility issues.
- Discoveries of project-specific conventions or "gotchas".
- Prompt Guidance: "Based on these notes, what would a senior developer tell a new team member to watch out for in this codebase?"
- Pass 1: Explicit Lessons: Parse the
- Synthesize and Deduplicate:
- Generalize all extracted lessons (from both passes) into a preliminary list of
new_memories_to_process. - Deduplicate this list: If an implicit lesson from Pass 2 is a rephrasing of an explicit lesson from Pass 1, discard the implicit one and keep the more detailed, explicit version.
- Generalize all extracted lessons (from both passes) into a preliminary list of
- Load Existing Memory Context:
[[LLM: Perform this file read once before the validation loop.]]
- Read the entire contents of
.bmad-core/data/bmad-project-memory.mdinto a temporary context variable,existing_memories. If the file doesn't exist, this variable will be empty.
- Read the entire contents of
- Reconcile Memories (In-Memory Loop):
[[LLM: Initialize an empty list called
finalized_memoriesand a list calledconflicts_to_log. Now, for each uniquenew_memoryin the deduplicated list, perform the validation against the loadedexisting_memoriescontext.]]- Check for Conflicts:
- Direct Contradiction: Does the
new_memorydirectly contradict a memory inexisting_memories? - Superseding Pattern: Does the
new_memoryreplace an older pattern? - Redundancy: Is the
new_memorya rephrasing of an existing memory?
- Direct Contradiction: Does the
- Process Validation Result:
- If a Direct Contradiction is found: Add a warning to the
conflicts_to_loglist. - If a Superseding Pattern is found: Mark the older memory in
existing_memoriesfor deprecation and add thenew_memorytofinalized_memories. - If Redundant: Do nothing.
- If No Conflict (Clear): Add the
new_memorytofinalized_memories.
- If a Direct Contradiction is found: Add a warning to the
- Check for Conflicts:
- Commit Changes to File:
LLM: After the loop is complete, perform the file write operations.
- If the
finalized_memorieslist is not empty or if any existing memories were marked for deprecation:- Modify the
existing_memoriescontext in-memory (deprecating old entries, adding new ones fromfinalized_memories). - Update the "Last Synthesized" timestamp.
- Write the entire, updated memory context back to
.bmad-core/data/bmad-project-memory.md, overwriting the file.
- Modify the
- If the
conflicts_to_loglist is not empty:- Append each conflict as a high-priority warning to the current story's
Dev Notes:**MEMORY CONFLICT DETECTED:** The lesson "[new lesson]" from this story contradicts the existing memory "[conflicting memory]" from Story [source]. Human review is required to resolve this inconsistency.
- Append each conflict as a high-priority warning to the current story's
- If the
- Conclude: Announce "Memory synthesis and validation complete. Story is finalized and ready for review."