-
Notifications
You must be signed in to change notification settings - Fork 468
feat: advanced code review workflows & robust agent factory #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
feat: advanced code review workflows & robust agent factory #319
Conversation
- Rename 'review' command to 'review-pr' to avoid conflicts with OpenCode builtins - Implement consolidated PR review toolkit with 4 specialized analysis modes: * Safety Review (silent failure hunter) * Type Design Analysis (encapsulation & invariants) * Test Coverage Analysis (critical gaps & quality) * General Review (logic bugs & conventions) - Orchestrate multiple code-reviewer personas for comprehensive code analysis - Maintain feature-dev and init-deep builtin commands - Update type definitions and command registry This restores the advanced review capabilities from feat/integrate-claude-plugins branch while maintaining clean architecture with separate templates and proper TypeScript types.
- Fix environment context ordering: inject after mergeAgentConfig to prevent context loss when prompt is overridden - Add explore agent to envContext recipients for better codebase awareness - Remove legacy 'mode' option, keeping only 'persona' to avoid confusion with AgentConfig.mode property - Add barrel exports for code-reviewer types in agents/index.ts - Update AGENTS.md documentation to reflect grok-code as default model - Add tests for environment context injection and prompt override behavior
…erride types - Add BaseAgentOptions interface for extensible agent factory options - Create generic AgentFactory<TOptions> type for type-safe factories - Split AgentOverrideConfig into BaseAgentOverrideConfig and CodeReviewerOverrideConfig - Update schema.ts to use agent-specific schemas (eliminates ghost fields) - CodeReviewerOptions now extends BaseAgentOptions - Add isCodeReviewerOverride type guard in utils.ts This change ensures code_reviewer_mode is only valid for the code-reviewer agent (previously it appeared on all agents as a 'ghost field'). Schema reduced by ~99 lines - code_reviewer_mode now appears only once.
|
All contributors have signed the CLA. Thank you! ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
Greptile SummaryThis PR introduces a sophisticated code review system with a new Key Changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant System as createBuiltinAgents
participant Factory as AgentFactory<T>
participant CodeReviewer as createCodeReviewerAgent
participant Merge as mergeAgentConfig
participant Env as createEnvContext
User->>System: Load config with agent overrides
rect rgb(240, 248, 255)
Note over System: Loop: For each agent in agentSources
System->>System: Check if agent disabled
alt Agent is code-reviewer
System->>System: Extract override config
System->>System: Check isCodeReviewerOverride()
System->>System: Build factoryOptions with code_reviewer_mode
System->>CodeReviewer: createCodeReviewerAgent(model, factoryOptions)
CodeReviewer->>CodeReviewer: Validate mode (isValidCodeReviewerMode)
alt Invalid mode
CodeReviewer->>CodeReviewer: Log warning, fallback to "general"
end
CodeReviewer->>CodeReviewer: Select prompt from CODE_REVIEWER_PROMPTS[mode]
CodeReviewer-->>System: Return AgentConfig with selected prompt
else Standard Agent
System->>Factory: buildAgent(source, model, factoryOptions)
Factory-->>System: Return base AgentConfig
end
alt Override exists
System->>Merge: mergeAgentConfig(config, override)
Merge->>Merge: Deep merge config
Merge->>Merge: Append prompt_append if present
Merge-->>System: Return merged config
end
alt Agent needs env context (Sisyphus, librarian, code-reviewer, explore)
System->>Env: createEnvContext(directory)
Env-->>System: Return env context string
System->>System: Append env context to prompt
end
System->>System: Store config in result
end
System-->>User: Return Record<string, AgentConfig>
|
Greptile's behavior is changing!From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
Merged from Fguedes90/oh-my-opencode:feat/advanced-code-review-workflows Features added: - code-reviewer agent with 4 personas (general, silent_failure_hunter, type_design_analyzer, pr_test_analyzer) - /review-pr builtin command - Generic AgentFactory<TOptions> pattern for extensibility - CodeReviewerOverrideConfig for mode-specific overrides Integration with our fork: - Both developer and code-reviewer agents now available - ALLOWED_AGENTS updated to include code-reviewer - All BuiltinAgentName types properly combined
Summary
This PR introduces a sophisticated Code Reviewer Agent with multiple specialized personas and refactors the internal agent factory system to be more type-safe and extensible. It enables targeted code reviews (e.g., focusing solely on error handling or type design) and adds a new workflow command.
📐 Architectural Highlights: Open/Closed Principle
This PR significantly refactors the agent configuration system to respect the Open/Closed Principle, moving away from a rigid "one-size-fits-all" approach:
AgentFactoryis now generic (AgentFactory<TOptions>). This allows new agents to introduce unique configuration requirements (likecode_reviewer_mode) without polluting the globalAgentConfigtype or requiring modifications to the core factory logic.AgentOverridesto enforce strict type safety. Specific configurations are isolated to their respective agents (e.g., the compiler prevents passingcode_reviewer_modetooracle).🔧 Extensibility Example
Here is how you would add a hypothetical
DatabaseOptimizeragent with custom options without modifying the core logic:No changes to
createBuiltinAgentsloop or the globalAgentConfigtype are required!📊 Visual Documentation
1. Code Reviewer Personas
How the generic factory routes configuration to specialized prompt engineering:
graph TD In([Input: PR / Diff]) --> Router{"Agent Factory<br/>Config Resolver"} Router -->|Default| ModeA["<b>General Persona</b><br/>Check Project Guidelines<br/>Verify Style/Conventions"] Router -->|silent_failure_hunter| ModeB["<b>Silent Failure Hunter</b><br/>Find Empty Catch Blocks<br/>Audit Error Propagation"] Router -->|type_design_analyzer| ModeC["<b>Type Design Analyzer</b><br/>Check Invariants<br/>Evaluate Encapsulation"] Router -->|pr_test_analyzer| ModeD["<b>PR Test Analyzer</b><br/>Check Behavioral Coverage<br/>Identify Missing Edge Cases"] ModeA --> Out([Structured Review Comment]) ModeB --> Out ModeC --> Out ModeD --> Out2. Polymorphic Configuration Flow
Flowchart illustrating how the system handles agent-specific options without modifying the core loop:
graph TD Start([Load Configuration]) --> Loop{Iterate Agents} Loop -->|Standard Agent| GenFactory[Generic Factory] GenFactory --> DefaultPrompt[Use Default Prompt] Loop -->|Code Reviewer| CheckOpts{Check Options} CheckOpts -->|Has code_reviewer_mode| Extract[Extract Options] Extract --> SpecFactory[Specific Factory] SpecFactory --> Select{Select Persona} Select -->|silent_failure_hunter| PromptA[Load 'Silent Failure' Prompt] Select -->|type_design_analyzer| PromptB[Load 'Type Design' Prompt] Select -->|general| PromptC[Load 'General' Prompt] DefaultPrompt --> Merge([Merge Config & Register]) PromptA --> Merge PromptB --> Merge PromptC --> Merge Merge --> Loop🚀 New Workflow Command
/review-pr [url]Why: To ensure code reviews are consistent, deep, and leverage the new specialized personas rather than just doing a generic "LGTM" check.
Flow:
code-revieweragent. It can specifically target "silent failures" or "type design" based on the nature of the PR, rather than a generic summary.Key Changes
🤖 New Code Reviewer Agent
general: Comprehensive review against project guidelines (default).silent_failure_hunter: ruthlessly finds swallowed errors and empty catch blocks.type_design_analyzer: Evaluates type invariants, encapsulation, and domain modeling.pr_test_analyzer: Assesses behavioral test coverage and gaps.oh-my-opencode.jsonusing the newcode_reviewer_modeoption.🏗️ Agent System Refactoring
📜 New Commands & Config
review-prtemplate added.Testing
code-revieweragent creation and mode selection.createBuiltinAgentsrefactoring and override logic.