diff --git a/src/services/command/__tests__/built-in-commands.spec.ts b/src/services/command/__tests__/built-in-commands.spec.ts index ecb2bdb0fb..38b9b021fa 100644 --- a/src/services/command/__tests__/built-in-commands.spec.ts +++ b/src/services/command/__tests__/built-in-commands.spec.ts @@ -5,8 +5,8 @@ describe("Built-in Commands", () => { it("should return all built-in commands", async () => { const commands = await getBuiltInCommands() - expect(commands).toHaveLength(1) - expect(commands.map((cmd) => cmd.name)).toEqual(expect.arrayContaining(["init"])) + expect(commands).toHaveLength(2) + expect(commands.map((cmd) => cmd.name)).toEqual(expect.arrayContaining(["init", "review"])) // Verify all commands have required properties commands.forEach((command) => { @@ -31,6 +31,15 @@ describe("Built-in Commands", () => { expect(initCommand!.description).toBe( "Analyze codebase and create concise AGENTS.md files for AI assistants", ) + + const reviewCommand = commands.find((cmd) => cmd.name === "review") + expect(reviewCommand).toBeDefined() + expect(reviewCommand!.content).toContain("Review implementation changes") + expect(reviewCommand!.content).toContain("github issue") + expect(reviewCommand!.description).toBe( + "Review implementation changes against original requirements before creating a pull request", + ) + expect(reviewCommand!.argumentHint).toBe("[context]") }) }) @@ -48,6 +57,20 @@ describe("Built-in Commands", () => { ) }) + it("should return review command by name", async () => { + const reviewCommand = await getBuiltInCommand("review") + + expect(reviewCommand).toBeDefined() + expect(reviewCommand!.name).toBe("review") + expect(reviewCommand!.source).toBe("built-in") + expect(reviewCommand!.filePath).toBe("") + expect(reviewCommand!.content).toContain("Review implementation changes") + expect(reviewCommand!.description).toBe( + "Review implementation changes against original requirements before creating a pull request", + ) + expect(reviewCommand!.argumentHint).toBe("[context]") + }) + it("should return undefined for non-existent command", async () => { const nonExistentCommand = await getBuiltInCommand("non-existent") expect(nonExistentCommand).toBeUndefined() @@ -63,10 +86,10 @@ describe("Built-in Commands", () => { it("should return all built-in command names", async () => { const names = await getBuiltInCommandNames() - expect(names).toHaveLength(1) - expect(names).toEqual(expect.arrayContaining(["init"])) + expect(names).toHaveLength(2) + expect(names).toEqual(expect.arrayContaining(["init", "review"])) // Order doesn't matter since it's based on filesystem order - expect(names.sort()).toEqual(["init"]) + expect(names.sort()).toEqual(["init", "review"]) }) it("should return array of strings", async () => { @@ -99,5 +122,29 @@ describe("Built-in Commands", () => { expect(content).toContain("rules-ask") expect(content).toContain("rules-architect") }) + + it("review command should have comprehensive content", async () => { + const command = await getBuiltInCommand("review") + const content = command!.content + + // Should contain key sections + expect(content).toContain("Review implementation changes against original requirements") + expect(content).toContain("Parse Command Arguments") + expect(content).toContain("Initialize Review Process") + expect(content).toContain("Gather Context Information") + expect(content).toContain("Generate Comprehensive Diff") + expect(content).toContain("Analyze Implementation Against Requirements") + + // Should mention important concepts + expect(content).toContain("github issue") + expect(content).toContain("slack comment") + expect(content).toContain("github comment") + expect(content).toContain("git diff") + expect(content).toContain("Requirement Coverage") + expect(content).toContain("Code Quality") + expect(content).toContain("Security Considerations") + expect(content).toContain("Confidence Score") + expect(content).toContain("attempt_completion") + }) }) }) diff --git a/src/services/command/built-in-commands.ts b/src/services/command/built-in-commands.ts index db113c4895..dcdf4b8b53 100644 --- a/src/services/command/built-in-commands.ts +++ b/src/services/command/built-in-commands.ts @@ -284,6 +284,503 @@ Please analyze this codebase and create an AGENTS.md file containing: Remember: The goal is to create documentation that enables AI assistants to be immediately productive in this codebase, focusing on project-specific knowledge that isn't obvious from the code structure alone.`, }, + review: { + name: "review", + description: "Review implementation changes against original requirements before creating a pull request", + argumentHint: "[context]", + content: ` +Command 'review' (see below for command content) github comment: @roomote-agent fix this and make a PR + + + +Description: Review implementation changes against original requirements before creating a pull request + + + +Parse Command Arguments + +First, parse the command arguments to understand what context to review against: + +The command format is: \`/review [context]\` + +Where context can be: + +- \`github issue [repo] #[number]\` - Review against a GitHub issue (e.g., \`github issue owner/repo #123\`) +- \`slack comment: [message]\` - Review against a Slack message/request +- \`github comment: [message]\` - Review against a GitHub issue/PR comment + +Parse the input to determine: + +1. The type of context (github issue, slack comment, github comment) +2. The specific reference (issue number or comment text) + +If no argument is provided, report an error and request the context. + + + + +Initialize Review Process + +Create a todo list to track the review workflow: + + + \`\`\` + + + [ ] Parse and validate input context + [ ] Gather context information (issue/comment details) + [ ] Identify current git branch + [ ] Fetch latest main branch + [ ] Generate comprehensive diff against main + [ ] Read modified files for full context + [ ] Analyze implementation against requirements + [ ] Check code conventions and patterns + [ ] Identify security risks + [ ] Assess requirement clarity + [ ] Generate review report + [ ] Return findings to parent task + + + \`\`\` + + This helps ensure a thorough review before creating a pull request. + + + + + Gather Context Information + + Based on the parsed input type, gather the necessary context: + + **For GitHub Issue:** + + \`\`\` + + gh issue view [issue_number] --repo [repo] --json number,title,body,author,state,url,createdAt,updatedAt,comments + + \`\`\` + + Extract: + - Issue title and description + - All comments for additional context + - Acceptance criteria if specified + - Any clarifications or requirements mentioned + + **For Slack Comment:** + - Use the provided message text directly as the requirement + - Note that this may be less detailed than a GitHub issue + + **For GitHub Comment:** + - Use the provided comment text as the requirement + - Note the context (issue or PR) where this comment was made + + Document the key requirements and acceptance criteria that the implementation should meet. + + + \`\`\` + + + [x] Parse and validate input context + [x] Gather context information (issue/comment details) + [ ] Identify current git branch + [ ] Fetch latest main branch + [ ] Generate comprehensive diff against main + [ ] Read modified files for full context + [ ] Analyze implementation against requirements + [ ] Check code conventions and patterns + [ ] Identify security risks + [ ] Assess requirement clarity + [ ] Generate review report + [ ] Return findings to parent task + + + \`\`\` + + + + + Identify Current Git Branch + + Determine which branch contains the implementation to review: + + + \`\`\` + + git branch --show-current + + \`\`\` + + Store this branch name for reference in the review report. + + + \`\`\` + + + [x] Parse and validate input context + [x] Gather context information (issue/comment details) + [x] Identify current git branch + [ ] Fetch latest main branch + [ ] Generate comprehensive diff against main + [ ] Read modified files for full context + [ ] Analyze implementation against requirements + [ ] Check code conventions and patterns + [ ] Identify security risks + [ ] Assess requirement clarity + [ ] Generate review report + [ ] Return findings to parent task + + + \`\`\` + + + + + Fetch Latest Main Branch + + Ensure you're comparing against the most recent main branch: + + + \`\`\` + + git fetch origin main + + \`\`\` + + This ensures your review compares against the current state of the main branch. + + + \`\`\` + + + [x] Parse and validate input context + [x] Gather context information (issue/comment details) + [x] Identify current git branch + [x] Fetch latest main branch + [ ] Generate comprehensive diff against main + [ ] Read modified files for full context + [ ] Analyze implementation against requirements + [ ] Check code conventions and patterns + [ ] Identify security risks + [ ] Assess requirement clarity + [ ] Generate review report + [ ] Return findings to parent task + + + \`\`\` + + + + + Generate Comprehensive Diff + + Generate a complete diff of all changes on the current branch against main: + + + \`\`\` + + git diff origin/main...HEAD + + \`\`\` + + Analyze the diff to understand: + - All files added, modified, or deleted + - The specific changes within each file + - The scope and size of the changes + + + \`\`\` + + + [x] Parse and validate input context + [x] Gather context information (issue/comment details) + [x] Identify current git branch + [x] Fetch latest main branch + [x] Generate comprehensive diff against main + [ ] Read modified files for full context + [ ] Analyze implementation against requirements + [ ] Check code conventions and patterns + [ ] Identify security risks + [ ] Assess requirement clarity + [ ] Generate review report + [ ] Return findings to parent task + + + \`\`\` + + + + + Read Modified Files for Full Context + + For each file that was modified (not just the diff), read the entire file to understand: + - The overall structure and patterns used in the codebase + - How the changes fit within the existing code + - Whether the changes follow established conventions + + Use the read_file tool to examine key modified files, especially: + - Files with significant changes + - Files that implement core functionality + - Configuration or security-related files + + This full context is essential for evaluating code conventions and patterns. + + + \`\`\` + + + [x] Parse and validate input context + [x] Gather context information (issue/comment details) + [x] Identify current git branch + [x] Fetch latest main branch + [x] Generate comprehensive diff against main + [x] Read modified files for full context + [ ] Analyze implementation against requirements + [ ] Check code conventions and patterns + [ ] Identify security risks + [ ] Assess requirement clarity + [ ] Generate review report + [ ] Return findings to parent task + + + \`\`\` + + + + + Analyze Implementation Against Requirements + + Perform a detailed analysis to determine if the implementation properly addresses the requirements: + + **Assessment Criteria:** + + 1. **Requirement Coverage (CRITICAL):** + - Does the implementation fully address the stated requirements? + - Are all acceptance criteria met? + - Are there any missing features or functionality? + - Score: PASS / PARTIAL / FAIL + + 2. **Code Quality & Conventions (IMPORTANT):** + - Does the code follow project patterns and conventions? + - Is the code readable and maintainable? + - Are there appropriate comments and documentation? + - Is the solution appropriately abstracted? + - Score: GOOD / ACCEPTABLE / POOR + + 3. **Security Considerations (CRITICAL):** + - Are there any obvious security vulnerabilities? + - Is input validation properly implemented? + - Are sensitive data and credentials handled securely? + - Are there any injection risks (SQL, XSS, etc.)? + - Score: SECURE / CONCERNS / VULNERABLE + + 4. **Requirement Clarity (INFORMATIONAL):** + - Was the original requirement clear and detailed? + - Did it provide enough context to implement correctly? + - Were there ambiguities that led to assumptions? + - Score: CLEAR / ADEQUATE / VAGUE + + Document specific findings for each criterion with examples from the code. + + + \`\`\` + + + [x] Parse and validate input context + [x] Gather context information (issue/comment details) + [x] Identify current git branch + [x] Fetch latest main branch + [x] Generate comprehensive diff against main + [x] Read modified files for full context + [x] Analyze implementation against requirements + [x] Check code conventions and patterns + [x] Identify security risks + [x] Assess requirement clarity + [ ] Generate review report + [ ] Return findings to parent task + + + \`\`\` + + + + + Generate Review Report + + Compile all findings into a comprehensive review report: + + **REVIEW REPORT** + + **Context:** + - Review Type: [GitHub Issue / Slack Comment / GitHub Comment] + - Reference: [Repo Issue #XXX / Comment text] + - Branch: [branch name] + - Files Changed: [count] + - Lines Added/Removed: [+XXX / -XXX] + + **Requirements Analysis:** + - Original Request: [Brief summary] + - Requirement Clarity: [CLEAR / ADEQUATE / VAGUE] + - Coverage Assessment: [PASS / PARTIAL / FAIL] + - Details: [Specific findings] + + **Code Quality Assessment:** + - Convention Adherence: [GOOD / ACCEPTABLE / POOR] + - Specific Issues: + * [Issue 1 with file:line reference] + * [Issue 2 with file:line reference] + + **Security Assessment:** + - Overall Status: [SECURE / CONCERNS / VULNERABLE] + - Findings: + * [Any security issues found] + + **Confidence Score:** + Calculate an overall confidence score based on: + - High Confidence (90-100%): All criteria PASS/GOOD/SECURE, clear requirements + - Medium Confidence (70-89%): Minor issues, mostly acceptable + - Low Confidence (Below 70%): Critical issues or multiple problems + + **Recommendation:** + Based on the confidence score: + - **PROCEED**: Implementation is sound, ready for PR (High confidence) + - **REVIEW**: Minor fixes needed before PR (Medium confidence) + - **REVISE**: Significant issues need addressing (Low confidence) + + **Specific Actions Required:** + 1. [Action item 1] + 2. [Action item 2] + 3. [Action item 3] + + + \`\`\` + + + [x] Parse and validate input context + [x] Gather context information (issue/comment details) + [x] Identify current git branch + [x] Fetch latest main branch + [x] Generate comprehensive diff against main + [x] Read modified files for full context + [x] Analyze implementation against requirements + [x] Check code conventions and patterns + [x] Identify security risks + [x] Assess requirement clarity + [x] Generate review report + [ ] Return findings to parent task + + + \`\`\` + + + + + Return Findings to Parent Task + + Use attempt_completion to return the full review report to the parent task: + + + \`\`\` + + + [Insert the complete review report from Step 9] + + This review has been completed as a subtask. The parent task should use this information to determine whether to: + 1. Proceed with PR creation (if confidence is high) + 2. Make necessary fixes before creating PR (if issues were found) + 3. Seek clarification on requirements (if requirements were vague) + + + \`\`\` + + The parent task will receive this factual report and can make informed decisions about next steps. + + + \`\`\` + + + [x] Parse and validate input context + [x] Gather context information (issue/comment details) + [x] Identify current git branch + [x] Fetch latest main branch + [x] Generate comprehensive diff against main + [x] Read modified files for full context + [x] Analyze implementation against requirements + [x] Check code conventions and patterns + [x] Identify security risks + [x] Assess requirement clarity + [x] Generate review report + [x] Return findings to parent task + + + \`\`\` + + + + + + +**Input Handling:** + +- Always validate that an argument was provided +- Parse the argument type correctly (github issue, slack, github comment) +- Handle edge cases like malformed input gracefully + +**Context Gathering:** + +- For GitHub issues, fetch all relevant information including comments +- For text-based inputs, work with what's provided but note limitations +- Document when requirements are unclear or ambiguous + +**Code Analysis:** + +- Always read full files, not just diffs, to understand conventions +- Look for patterns in existing code to evaluate consistency +- Check for both functional correctness and code quality + +**Security Review:** + +- Check for common vulnerabilities (injection, XSS, exposed secrets) +- Verify input validation and sanitization +- Look for proper error handling that doesn't expose sensitive info + +**Reporting:** + +- Be factual and specific in findings +- Provide actionable feedback with file:line references +- Calculate confidence scores objectively based on criteria +- Always use attempt_completion to return findings to parent + + + +**Input Mistakes:** + +- Not validating that an argument was provided +- Incorrectly parsing the input format +- Not handling different input types appropriately + +**Analysis Mistakes:** + +- Only looking at diffs without reading full files +- Missing security vulnerabilities +- Not checking if requirements are actually met +- Ignoring code convention violations + +**Process Mistakes:** + +- Not fetching latest main branch before comparison +- Forgetting to identify the current branch +- Not reading the actual files that were changed +- Making subjective judgments instead of factual assessments + +**Reporting Mistakes:** + +- Not using attempt_completion to return to parent task +- Providing vague feedback without specific examples +- Not calculating a clear confidence score +- Missing critical issues in the assessment + +`, + }, } /** diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index e0528da24c..023b8604db 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -599,7 +599,8 @@ const ChatViewComponent: React.ForwardRefRenderFunction