From c1ad9e953c46fe6224b106ab364e995715f0bf4d Mon Sep 17 00:00:00 2001 From: KoalaTrapLord <265133236+KoalaTrapLord@users.noreply.github.com> Date: Mon, 23 Mar 2026 14:24:57 -0400 Subject: [PATCH] fix(#95): replace regex JSON extraction with outermost-brace approach _parse_action() used r'\{[^{}]*\}' regex which fails on nested JSON (e.g. oracle text with braces). Now uses text.find/rfind to extract the outermost { } block, handling nested structures. Fixes issue #95 item 2. --- src/commander_ai_lab/sim/deepseek_brain.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commander_ai_lab/sim/deepseek_brain.py b/src/commander_ai_lab/sim/deepseek_brain.py index bb1edb8..743540c 100644 --- a/src/commander_ai_lab/sim/deepseek_brain.py +++ b/src/commander_ai_lab/sim/deepseek_brain.py @@ -653,9 +653,10 @@ class DeepSeekBrain: text = re.sub(r'\s*```$', '', text) text = text.strip() - json_match = re.search(r'\{[^{}]*\}', text, re.DOTALL) - if json_match: - text = json_match.group(0) + start = text.find('{') + end = text.rfind('}') + if start != -1 and end != -1 and end > start: + text = text[start:end + 1] try: parsed = json.loads(text)