fix: Address PR feedback for structured output fallback

- Throw error immediately when JSON extraction fails in
  generate-features-from-spec.ts to avoid redundant parsing attempt
  (feedback from Gemini Code Assist review)
- Emit spec_regeneration_error event before throwing for consistency
- Fix TypeScript cast in sync-spec.ts by using double cast through unknown

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Shirone
2026-01-24 18:34:46 +01:00
parent 92b1fb3725
commit db87e83aed
2 changed files with 15 additions and 4 deletions

View File

@@ -286,9 +286,20 @@ Your entire response should be valid JSON starting with { and ending with }. No
contentForParsing = JSON.stringify(extracted);
logger.info('✅ Pre-extracted JSON from text response');
} else {
// Fall back to raw text (let parseAndCreateFeatures try its extraction)
contentForParsing = rawText;
logger.warn('⚠️ Could not pre-extract JSON, passing raw text to parser');
// If pre-extraction fails, we know the next step will also fail.
// Throw an error here to avoid redundant parsing and make the failure point clearer.
logger.error(
'❌ Could not extract features JSON from model response. Full response text was:\n' +
rawText
);
const errorMessage =
'Failed to parse features from model response: No valid JSON with a "features" array found.';
events.emit('spec-regeneration:event', {
type: 'spec_regeneration_error',
error: errorMessage,
projectPath: projectPath,
});
throw new Error(errorMessage);
}
}

View File

@@ -261,7 +261,7 @@ CRITICAL INSTRUCTIONS:
if (techResult.structured_output) {
// Use structured output from Claude/Codex models
const structured = techResult.structured_output as TechStackExtractionResult;
const structured = techResult.structured_output as unknown as TechStackExtractionResult;
if (Array.isArray(structured.technologies)) {
parsedTechnologies = structured.technologies;
logger.info('✅ Received structured output for tech analysis');