fix(decision): execute fixMissingQuotes BEFORE validateJSONFormat

Critical bug fix: The fullwidth character replacement was happening AFTER
JSON format validation, so fullwidth characters ([{:,) were rejected
before they could be fixed.

Root cause:
1. validateJSONFormat() checks if JSON starts with "[{" (line 509)
2. When AI outputs "[{...", validation fails immediately
3. fixMissingQuotes() never gets executed (line 493, after validation)

Solution:
Move fixMissingQuotes() call BEFORE validateJSONFormat():
- Line 488: Fix fullwidth characters first
- Line 491: Then validate the cleaned JSON

Execution order:
Before: extract → validate ( fails) → fix (never reached)
After:  extract → fix → validate ( passes) → parse

This ensures all character normalization happens before any validation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ZhouYongyou
2025-11-04 22:58:03 +08:00
parent 1ee791e2b5
commit 3ff3b5dde3

View File

@@ -481,17 +481,17 @@ func extractDecisions(response string) ([]Decision, error) {
jsonContent := strings.TrimSpace(response[arrayStart : arrayEnd+1])
// 🔧 先修复全角字符和引号问题(必须在验证之前!)
// 修复常见的JSON格式错误全角字符、缺少引号的字段值等
// 匹配: "reasoning": 内容"} 或 "reasoning": 内容} (没有引号)
// 修复为: "reasoning": "内容"}
jsonContent = fixMissingQuotes(jsonContent)
// 🔧 验证 JSON 格式(检测常见错误)
if err := validateJSONFormat(jsonContent); err != nil {
return nil, fmt.Errorf("JSON格式验证失败: %w\nJSON内容: %s\n完整响应:\n%s", err, jsonContent, response)
}
// 🔧 修复常见的JSON格式错误缺少引号的字段值
// 匹配: "reasoning": 内容"} 或 "reasoning": 内容} (没有引号)
// 修复为: "reasoning": "内容"}
// 使用简单的字符串扫描而不是正则表达式
jsonContent = fixMissingQuotes(jsonContent)
// 解析JSON
var decisions []Decision
if err := json.Unmarshal([]byte(jsonContent), &decisions); err != nil {