-
Notifications
You must be signed in to change notification settings - Fork 851
Feat: Generalize coding agent to behaviors + objective part 1 (revert of revert) #252
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: nightly
Are you sure you want to change the base?
Conversation
…rt 1" This reverts commit 9d181cf.
|
Claude finished @AshishKumar4's task —— View job Code Quality & Security ReviewSummaryThis PR represents a significant architectural refactoring that extracts the agent behavior from the infrastructure layer, enabling support for multiple agent behaviors (phasic vs agentic). The refactoring is well-structured with proper separation of concerns, but there are several areas requiring attention before merge. Recommendation: REQUEST CHANGES Architecture ReviewPositive Changes:
Concerns:
Code Quality IssuesCritical Issues (5 inline comments posted)
High Priority Issues6. Removed
7. Inconsistent Error Handling
} catch (error) {
this.logger().error("Error during async initialization:", error);
// throw error; // ❌ Commented out - swallows errors
}
Medium Priority Issues8. Incomplete Abstract Method
Security ReviewNo Critical Security Vulnerabilities Found ✅ SQL Injection: Tagged template literals used correctly Note: This is production application code in Breaking ChangesState Schema Change: // Old (removed)
agentMode: 'deterministic' | 'smart'
// New (added)
behaviorType: 'phasic' | 'agentic'Impact:
Testing RecommendationsBefore merge, verify:
Related IssuesPotentially Affected:
Not Linked But Relevant:
RecommendationsRequired Before Merge:
Recommended: ConclusionThis is a well-architected refactoring that successfully separates concerns and enables future extensibility. The code follows project conventions and demonstrates good understanding of TypeScript generics and interface design. However, the missing implementation for agentic behavior and lack of state migration are blocking concerns. The 5 critical issues flagged in inline comments must be addressed before merge to prevent runtime errors and maintain type safety standards. The refactoring aligns with the project's goal of generalizing the agent system, but needs completion of the agentic behavior path and proper handling of the state schema migration to ensure existing sessions continue working. PR Description: ✅ Updated with comprehensive summary, changes, motivation, testing notes, and breaking changes. |
| if (behaviorType === 'phasic') { | ||
| this.behavior = new PhasicAgentBehavior(this); | ||
| } else { | ||
| this.behavior = new AgenticAgentBehavior(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Missing Import
AgenticAgentBehavior is referenced here but not imported. This will cause a runtime error when behaviorType === 'agentic'.
Fix options:
- Import the class if it exists elsewhere
- If not implemented yet, throw an error:
} else {
throw new Error(`Unsupported behavior type: ${behaviorType}. Agentic behavior not yet implemented.`);
}| return { | ||
| env: this.env, | ||
| agentId: this.getAgentId(), | ||
| context: GenerationContext.from(this.state, this.getTemplateDetails(), this.logger()) as PhasicGenerationContext, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type Safety Issue
Using type assertion as PhasicGenerationContext bypasses type checking. The GenerationContext.from() method should return the properly typed context.
Recommendation: Fix the return type of GenerationContext.from() to infer the correct context type based on the state, rather than using type assertions.
| description: config.description | ||
| })); | ||
|
|
||
| const userConfigs: Record<string, any> = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLAUDE.md Violation: any Type Usage
Per CLAUDE.md Rule #1: "NEVER use any type"
Fix: Define proper interface for model configs:
interface ModelConfigInfo {
name: string;
max_tokens?: number;
temperature?: number;
reasoning_effort?: string;
fallbackModel?: string;
isUserOverride?: boolean;
}
const userConfigs: Record<string, ModelConfigInfo> = {};
const defaultConfigs: Record<string, ModelConfigInfo> = {};| files: result.files.map(f => ({ | ||
| path: f.filePath, | ||
| purpose: f.filePurpose || '', | ||
| diff: (f as any).lastDiff || '' // FileState has lastDiff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe Type Cast
Casting FileOutputType to any to access lastDiff is unsafe and violates type safety principles.
Fix: Either:
- Extend
FileOutputTypeto includelastDiff?: string - Use a type guard:
const getLastDiff = (f: FileOutputType): string => {
if ('lastDiff' in f && typeof f.lastDiff === 'string') {
return f.lastDiff;
}
return '';
};
// Then use: diff: getLastDiff(f)| * Sets up services and begins deployment process | ||
| */ | ||
|
|
||
| initialState: AgentState = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
State Migration Required
The initialState uses new behaviorType: 'phasic' but doesn't handle migration from old agentMode field. Existing Durable Object sessions may fail or behave incorrectly.
Recommendation: Add migration logic in constructor:
constructor(ctx: AgentContext, env: Env) {
super(ctx, env);
// Migrate old agentMode to behaviorType
if ('agentMode' in this.state && !('behaviorType' in this.state)) {
const behaviorType = this.state.agentMode === 'deterministic' ? 'phasic' : 'agentic';
this.setState({ ...this.state, behaviorType });
}
// ... rest of constructor
}
Summary
This PR refactors the agent architecture to separate behavior logic from infrastructure, enabling support for multiple agent behaviors (phasic and agentic modes).
Changes
Core Architecture
simpleGeneratorAgent.ts→baseAgent.tswith extracted base behavior classAgentInfrastructure<TState>interface to decouple behavior from Durable ObjectsBaseAgentBehavior<TState>abstract class with common agent functionalityworker/agents/core/phasic/behavior.ts(852 lines) - phasic behavior implementationsmartGeneratorAgent.ts- thin wrapper implementingAgentInfrastructureState Management
state.ts- split state intoBaseProjectState,PhasicState,AgenticStatetypes.ts- addedBehaviorType, genericAgentInitArgs<TState>agentMode: 'deterministic' | 'smart'withbehaviorType: 'phasic' | 'agentic'Operations & Services
worker/agents/to useICodingAgentinterfaceScreenshotAnalysisOperation.ts- screenshot handling moved/removedICodingAgentinstead of concrete classPhaseImplementation.ts- simplified, moved logic to behaviorGenerationContext.ts- addedPhasicGenerationContextvariantInterface Changes
ICodingAgent.ts- formalized interface for all agent behaviorsMotivation
The previous architecture tightly coupled agent behavior to Durable Objects infrastructure, making it difficult to:
This refactoring enables:
AgentInfrastructurefor unit testsTesting
Manual Testing:
Areas Requiring Extra Attention:
agentMode→ newbehaviorType)Breaking Changes
State Schema:
agentMode: 'deterministic' | 'smart'behaviorType: 'phasic' | 'agentic'Impact: Existing Durable Object sessions may need migration logic or will default to phasic mode.
Related Issues
ScreenshotAnalysisOperationremovalThis PR description was automatically generated by Claude Code