From 3ff3b5dde3549c02d2fc319e719ae37fd1944dda Mon Sep 17 00:00:00 2001 From: ZhouYongyou <128128010+zhouyongyou@users.noreply.github.com> Date: Tue, 4 Nov 2025 22:58:03 +0800 Subject: [PATCH] fix(decision): execute fixMissingQuotes BEFORE validateJSONFormat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- decision/engine.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/decision/engine.go b/decision/engine.go index b8c2ecdc..f49b4394 100644 --- a/decision/engine.go +++ b/decision/engine.go @@ -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 {