-
Notifications
You must be signed in to change notification settings - Fork 489
feature/validate-features #284
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
Closed
NomadicDaddy
wants to merge
3
commits into
AutoMaker-Org:main
from
NomadicDaddy:feature/validate-features
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
apps/server/src/routes/features/routes/validate-feature.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| /** | ||
| * Validate feature route - Uses AI agent to check if a feature is already implemented | ||
| */ | ||
|
|
||
| import type { Request, Response } from 'express'; | ||
| import { FeatureLoader } from '../../../services/feature-loader.js'; | ||
| import { AgentService } from '../../../services/agent-service.js'; | ||
| import { getErrorMessage, logError } from '../common.js'; | ||
| import type { Feature } from '@automaker/types'; | ||
|
|
||
| interface ValidateFeatureRequest { | ||
| projectPath: string; | ||
| featureId: string; | ||
| } | ||
|
|
||
| export function createValidateFeatureHandler( | ||
| featureLoader: FeatureLoader, | ||
| agentService: AgentService | ||
| ) { | ||
| return async (req: Request, res: Response) => { | ||
| let sessionId: string | undefined; | ||
|
|
||
| try { | ||
| const { projectPath, featureId }: ValidateFeatureRequest = req.body; | ||
|
|
||
| // Load the feature | ||
| const feature = await featureLoader.get(projectPath, featureId); | ||
| if (!feature) { | ||
| return res.status(404).json({ | ||
| success: false, | ||
| error: 'Feature not found', | ||
| }); | ||
| } | ||
|
|
||
| // Create a validation prompt | ||
| const validationPrompt = `Your task is to review this feature and the existing codebase and determine whether or not it has been fully/partially/not implemented. | ||
|
|
||
| Feature Details: | ||
| - Title: ${feature.title} | ||
| - Category: ${feature.category} | ||
| - Description: ${feature.description} | ||
|
|
||
| Please analyze the codebase and provide your assessment in the following format (plain text, no markdown): | ||
|
|
||
| ASSESSMENT: [FULLY_IMPLEMENTED|PARTIALLY_IMPLEMENTED|NOT_IMPLEMENTED] | ||
| REASONING: [Brief explanation of your decision] | ||
| EVIDENCE: [Specific code/files that support your assessment] | ||
|
|
||
| Be thorough in your analysis. Check for: | ||
| - Related components, functions, or classes | ||
| - Test files | ||
| - Configuration changes | ||
| - Documentation updates | ||
| - Any other relevant implementation details | ||
|
|
||
| If the feature is FULLY_IMPLEMENTED, it should be complete and ready for approval. | ||
| If PARTIALLY_IMPLEMENTED, explain what's missing. | ||
| If NOT_IMPLEMENTED, explain why you believe this feature hasn't been addressed.`; | ||
|
|
||
| // Create a temporary session for validation | ||
| let session; | ||
| try { | ||
| // First create the session metadata | ||
| session = await agentService.createSession( | ||
| `Feature Validation: ${feature.title}`, | ||
| projectPath, | ||
| projectPath | ||
| ); | ||
|
|
||
| // Track session ID for cleanup | ||
| sessionId = session.id; | ||
|
|
||
| // Then initialize the conversation session in memory | ||
| await agentService.startConversation({ | ||
| sessionId: session.id, | ||
| workingDirectory: projectPath, | ||
| }); | ||
| } catch (sessionError) { | ||
| logError(sessionError, 'Failed to create agent session'); | ||
| return res.status(500).json({ | ||
| success: false, | ||
| error: getErrorMessage(sessionError) || 'Failed to create agent session', | ||
| }); | ||
| } | ||
|
|
||
| // Send the validation prompt to the agent | ||
| let result; | ||
| try { | ||
| result = await agentService.sendMessage({ | ||
| sessionId: session.id, | ||
| message: validationPrompt, | ||
| workingDirectory: projectPath, | ||
| }); | ||
| } catch (messageError) { | ||
| logError(messageError, 'Failed to send message to agent'); | ||
|
|
||
| // Clean up the session if it exists | ||
| if (sessionId) { | ||
| try { | ||
| await agentService.deleteSession(sessionId); | ||
| } catch (cleanupError) { | ||
| logError(cleanupError, 'Failed to cleanup session after message error'); | ||
| } | ||
| } | ||
|
|
||
| return res.status(500).json({ | ||
| success: false, | ||
| error: getErrorMessage(messageError) || 'Failed to send message to agent', | ||
| }); | ||
| } | ||
|
|
||
| if (!result.success) { | ||
| // Clean up the session | ||
| if (sessionId) { | ||
| try { | ||
| await agentService.deleteSession(sessionId); | ||
| } catch (cleanupError) { | ||
| logError(cleanupError, 'Failed to cleanup session after failed result'); | ||
| } | ||
| } | ||
|
|
||
| return res.status(500).json({ | ||
| success: false, | ||
| error: 'Failed to validate feature', | ||
| }); | ||
| } | ||
|
|
||
| // Parse the agent response with improved regex | ||
| const response = result.message?.content || ''; | ||
| console.log('[ValidateFeature] Raw AI Response:', response); | ||
|
|
||
| // Improved regex patterns to handle edge cases | ||
| const assessmentMatch = response.match( | ||
| /ASSESSMENT:\s*\*{0,2}(FULLY_IMPLEMENTED|PARTIALLY_IMPLEMENTED|NOT_IMPLEMENTED)\*{0,2}/im | ||
| ); | ||
| const reasoningMatch = response.match( | ||
| /REASONING:\s*\*{0,2}([^\n*]+(?:\n[^\n*]+)*?)\*(?=\n[A-Z]+:|$)/im | ||
| ); | ||
| const evidenceMatch = response.match(/EVIDENCE:\s*\*{0,2}([\s\S]*?)(?=\n\n[A-Z]+:|$)/im); | ||
|
|
||
| console.log('[ValidateFeature] Regex matches:'); | ||
| console.log(' - Assessment match:', assessmentMatch); | ||
| console.log(' - Reasoning match:', reasoningMatch); | ||
| console.log(' - Evidence match:', evidenceMatch); | ||
|
|
||
| // Extract values with better fallbacks | ||
| const assessment = assessmentMatch?.[1]?.trim() || 'NOT_IMPLEMENTED'; | ||
| const reasoning = reasoningMatch?.[1]?.trim() || 'Unable to determine reasoning'; | ||
| const evidence = evidenceMatch?.[1]?.trim() || 'No specific evidence provided'; | ||
|
|
||
| console.log('[ValidateFeature] Extracted values:'); | ||
| console.log(' - Assessment:', assessment); | ||
| console.log(' - Reasoning:', reasoning); | ||
| console.log(' - Evidence:', evidence?.substring(0, 200) + '...'); | ||
|
|
||
| // Clean up the session | ||
| if (sessionId) { | ||
| try { | ||
| await agentService.deleteSession(sessionId); | ||
| } catch (cleanupError) { | ||
| logError(cleanupError, 'Failed to cleanup session after successful validation'); | ||
| } | ||
| } | ||
|
|
||
| return res.json({ | ||
| success: true, | ||
| validation: { | ||
| assessment: assessment as | ||
| | 'FULLY_IMPLEMENTED' | ||
| | 'PARTIALLY_IMPLEMENTED' | ||
| | 'NOT_IMPLEMENTED', | ||
| reasoning, | ||
| evidence, | ||
| fullResponse: response, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| logError(error, 'Unexpected error in validate feature handler'); | ||
|
|
||
| // Ensure session cleanup on any thrown exception | ||
| if (sessionId) { | ||
| try { | ||
| await agentService.deleteSession(sessionId); | ||
| } catch (cleanupError) { | ||
| logError(cleanupError, 'Failed to cleanup session in outer catch'); | ||
| } | ||
| } | ||
|
|
||
| return res.status(500).json({ | ||
| success: false, | ||
| error: getErrorMessage(error), | ||
| }); | ||
| } | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The type
ValidateFeatureRequestis used here but is not defined or imported. This will cause a TypeScript error. You should define it within this file or in a shared types file. For example: