mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
fix(backlog-plan): use extractJsonWithArray and improve logging
- Switch from extractJson to extractJsonWithArray for 'changes' field - Validates that 'changes' is an array, not just that it exists - Add debug logging for response length and preview on parse failure - Add debug logging when receiving result from Cursor provider - Matches pattern used by suggestions feature - Helps diagnose parsing issues with better error context 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ import type { Feature, BacklogPlanResult, BacklogChange, DependencyUpdate } from
|
|||||||
import { DEFAULT_PHASE_MODELS } from '@automaker/types';
|
import { DEFAULT_PHASE_MODELS } from '@automaker/types';
|
||||||
import { FeatureLoader } from '../../services/feature-loader.js';
|
import { FeatureLoader } from '../../services/feature-loader.js';
|
||||||
import { ProviderFactory } from '../../providers/provider-factory.js';
|
import { ProviderFactory } from '../../providers/provider-factory.js';
|
||||||
import { extractJson } from '../../lib/json-extractor.js';
|
import { extractJsonWithArray } from '../../lib/json-extractor.js';
|
||||||
import { logger, setRunningState, getErrorMessage } from './common.js';
|
import { logger, setRunningState, getErrorMessage } from './common.js';
|
||||||
import type { SettingsService } from '../../services/settings-service.js';
|
import type { SettingsService } from '../../services/settings-service.js';
|
||||||
import { getAutoLoadClaudeMdSetting, getPromptCustomization } from '../../lib/settings-helpers.js';
|
import { getAutoLoadClaudeMdSetting, getPromptCustomization } from '../../lib/settings-helpers.js';
|
||||||
@@ -45,17 +45,19 @@ function formatFeaturesForPrompt(features: Feature[]): string {
|
|||||||
*/
|
*/
|
||||||
function parsePlanResponse(response: string): BacklogPlanResult {
|
function parsePlanResponse(response: string): BacklogPlanResult {
|
||||||
// Use shared JSON extraction utility for robust parsing
|
// Use shared JSON extraction utility for robust parsing
|
||||||
const parsed = extractJson<BacklogPlanResult>(response, {
|
// extractJsonWithArray validates that 'changes' exists AND is an array
|
||||||
|
const parsed = extractJsonWithArray<BacklogPlanResult>(response, 'changes', {
|
||||||
logger,
|
logger,
|
||||||
requiredKey: 'changes',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (parsed) {
|
if (parsed) {
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If parsing fails, return an empty result
|
// If parsing fails, log details and return an empty result
|
||||||
logger.warn('[BacklogPlan] Failed to parse AI response as JSON');
|
logger.warn('[BacklogPlan] Failed to parse AI response as JSON');
|
||||||
|
logger.debug('[BacklogPlan] Response text length:', response.length);
|
||||||
|
logger.debug('[BacklogPlan] Response preview:', response.slice(0, 500));
|
||||||
return {
|
return {
|
||||||
changes: [],
|
changes: [],
|
||||||
summary: 'Failed to parse AI response',
|
summary: 'Failed to parse AI response',
|
||||||
@@ -149,6 +151,7 @@ export async function generateBacklogPlan(
|
|||||||
} else if (msg.type === 'result' && msg.subtype === 'success' && msg.result) {
|
} else if (msg.type === 'result' && msg.subtype === 'success' && msg.result) {
|
||||||
// Use result if it's a final accumulated message (from Cursor provider)
|
// Use result if it's a final accumulated message (from Cursor provider)
|
||||||
if (msg.result.length > responseText.length) {
|
if (msg.result.length > responseText.length) {
|
||||||
|
logger.debug('[BacklogPlan] Received result from Cursor, length:', msg.result.length);
|
||||||
responseText = msg.result;
|
responseText = msg.result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user