From 1ee791e2b588580fb7bff7c71a8385bc4bdfe0db Mon Sep 17 00:00:00 2001 From: ZhouYongyou <128128010+zhouyongyou@users.noreply.github.com> Date: Tue, 4 Nov 2025 22:29:27 +0800 Subject: [PATCH] fix(decision): handle fullwidth JSON characters from AI responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem AI occasionally outputs fullwidth (全角) characters in JSON responses, causing JSON parsing failures even though content is logically correct. Example error: JSON format validation failed: actual [ {"symbol": "BTCU... (displays as fullwidth: [{"symbol":"BTCU...) ## Root Cause Claude API can output fullwidth characters when: - Processing Chinese context - Mixing languages in responses - Input method artifacts ## Current Protection Already handles curly quotes but not brackets/punctuation ## Solution Extend fixMissingQuotes() to handle fullwidth JSON syntax: - Brackets: [] -> [] - Braces: {} -> {} - Colon: : -> : - Comma: , -> , ## Impact - Prevents intermittent JSON parsing failures - No performance impact (simple string replace) - Does not affect correctly formatted responses 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- decision/engine.go | 12 +++++++++++- nofx.db | 0 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 nofx.db diff --git a/decision/engine.go b/decision/engine.go index 65df3488..b8c2ecdc 100644 --- a/decision/engine.go +++ b/decision/engine.go @@ -534,12 +534,22 @@ func validateJSONFormat(jsonStr string) error { return nil } -// fixMissingQuotes 替换中文引号为英文引号(避免输入法自动转换) +// fixMissingQuotes 替换中文引号和全角符号为英文半角符号(避免AI输出或输入法自动转换导致JSON解析失败) func fixMissingQuotes(jsonStr string) string { + // 替换中文引号 jsonStr = strings.ReplaceAll(jsonStr, "\u201c", "\"") // " jsonStr = strings.ReplaceAll(jsonStr, "\u201d", "\"") // " jsonStr = strings.ReplaceAll(jsonStr, "\u2018", "'") // ' jsonStr = strings.ReplaceAll(jsonStr, "\u2019", "'") // ' + + // ⚠️ 替换全角括号、冒号、逗号(防止AI输出全角JSON字符) + jsonStr = strings.ReplaceAll(jsonStr, "[", "[") // 全角左方括号 U+FF3B + jsonStr = strings.ReplaceAll(jsonStr, "]", "]") // 全角右方括号 U+FF3D + jsonStr = strings.ReplaceAll(jsonStr, "{", "{") // 全角左花括号 U+FF5B + jsonStr = strings.ReplaceAll(jsonStr, "}", "}") // 全角右花括号 U+FF5D + jsonStr = strings.ReplaceAll(jsonStr, ":", ":") // 全角冒号 U+FF1A + jsonStr = strings.ReplaceAll(jsonStr, ",", ",") // 全角逗号 U+FF0C + return jsonStr } diff --git a/nofx.db b/nofx.db new file mode 100644 index 00000000..e69de29b