-
Notifications
You must be signed in to change notification settings - Fork 576
feat: Interactive Planning Mode with Clarification Questions #564
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
stefandevo
wants to merge
4
commits into
AutoMaker-Org:v0.13.0rc
from
stefandevo:feature/interactive-planning-mode
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5c61768
feat: add interactive planning mode with clarification questions
stefandevo 2131bfb
feat: add enable/disable setting for interactive planning
stefandevo 659a357
fix: address PR review comments for type safety
stefandevo c6bf26b
fix: add project name testid to project switcher item
stefandevo 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
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
119 changes: 119 additions & 0 deletions
119
apps/server/src/routes/auto-mode/routes/clarification-response.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,119 @@ | ||
| /** | ||
| * POST /clarification-response endpoint - Submit answers to clarification questions | ||
| * | ||
| * Used during interactive planning mode when the AI agent asks clarification | ||
| * questions via the AskUserQuestion tool. | ||
| */ | ||
|
|
||
| import type { Request, Response } from 'express'; | ||
| import type { AutoModeService } from '../../../services/auto-mode-service.js'; | ||
| import { createLogger } from '@automaker/utils'; | ||
| import { getErrorMessage, logError } from '../common.js'; | ||
|
|
||
| const logger = createLogger('AutoMode'); | ||
|
|
||
| /** Shape of the clarification response request body */ | ||
| interface ClarificationResponseBody { | ||
| featureId: string; | ||
| projectPath: string; | ||
| requestId: string; | ||
| answers: Record<string, string>; | ||
| } | ||
|
|
||
| /** | ||
| * Validates and parses the clarification response request body. | ||
| * Returns the validated body or an error message. | ||
| */ | ||
| function validateRequestBody( | ||
| body: unknown | ||
| ): { success: true; data: ClarificationResponseBody } | { success: false; error: string } { | ||
| if (!body || typeof body !== 'object') { | ||
| return { success: false, error: 'Request body must be an object' }; | ||
| } | ||
|
|
||
| const obj = body as Record<string, unknown>; | ||
|
|
||
| // Define required string fields | ||
| const requiredStringFields: Array<keyof ClarificationResponseBody> = [ | ||
| 'featureId', | ||
| 'projectPath', | ||
| 'requestId', | ||
| ]; | ||
|
|
||
| // Validate required string fields | ||
| for (const field of requiredStringFields) { | ||
| const value = obj[field]; | ||
| if (typeof value !== 'string' || value.length === 0) { | ||
| return { success: false, error: `${field} is required and must be a non-empty string` }; | ||
| } | ||
| } | ||
|
|
||
| // Validate answers object | ||
| const answers = obj.answers; | ||
| if (!answers || typeof answers !== 'object' || Array.isArray(answers)) { | ||
| return { success: false, error: 'answers object is required' }; | ||
| } | ||
|
|
||
| // Validate all answer values are strings | ||
| for (const [key, value] of Object.entries(answers as Record<string, unknown>)) { | ||
| if (typeof value !== 'string') { | ||
| return { success: false, error: `answers[${key}] must be a string` }; | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: true, | ||
| data: { | ||
| featureId: obj.featureId as string, | ||
| projectPath: obj.projectPath as string, | ||
| requestId: obj.requestId as string, | ||
| answers: answers as Record<string, string>, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export function createClarificationResponseHandler(autoModeService: AutoModeService) { | ||
| return async (req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| // Validate request body with type-safe validation | ||
| const validation = validateRequestBody(req.body); | ||
| if (!validation.success) { | ||
| res.status(400).json({ | ||
| success: false, | ||
| error: validation.error, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const { featureId, projectPath, requestId, answers } = validation.data; | ||
|
|
||
| logger.info( | ||
| `[AutoMode] Clarification response received for feature ${featureId}, requestId=${requestId}` | ||
| ); | ||
|
|
||
| // Resolve the pending clarification | ||
| const result = await autoModeService.resolveClarification( | ||
| featureId, | ||
| requestId, | ||
| answers, | ||
| projectPath | ||
| ); | ||
|
|
||
| if (!result.success) { | ||
| res.status(500).json({ | ||
| success: false, | ||
| error: result.error, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| res.json({ | ||
| success: true, | ||
| message: 'Clarification response submitted - agent will continue', | ||
| }); | ||
| } catch (error) { | ||
| logError(error, 'Clarification response failed'); | ||
| res.status(500).json({ success: false, error: getErrorMessage(error) }); | ||
| } | ||
| }; | ||
| } | ||
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.
Use a 4xx for expected resolve failures.
resolveClarificationcan fail due to missing/mismatched pending requests (client-side issue). Returning 500 misclassifies the error and may trigger retry logic.🔧 Suggested adjustment
📝 Committable suggestion
🤖 Prompt for AI Agents