Spaces:
Sleeping
Sleeping
fix: strip full opening fence line in parse_plan_json to remove language identifier
Browse files- core/planner.py +5 -4
core/planner.py
CHANGED
|
@@ -87,12 +87,13 @@ class ProjectPlan(BaseModel):
|
|
| 87 |
def parse_plan_json(raw: str) -> ProjectPlan:
|
| 88 |
"""Parse a raw JSON string into a validated ProjectPlan. Returns empty plan on error."""
|
| 89 |
try:
|
| 90 |
-
# Strip markdown code fences if present
|
| 91 |
text = raw.strip()
|
|
|
|
| 92 |
if text.startswith("```"):
|
| 93 |
-
#
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 96 |
if text.rstrip().endswith("```"):
|
| 97 |
text = text.rstrip()[:-3].rstrip()
|
| 98 |
|
|
|
|
| 87 |
def parse_plan_json(raw: str) -> ProjectPlan:
|
| 88 |
"""Parse a raw JSON string into a validated ProjectPlan. Returns empty plan on error."""
|
| 89 |
try:
|
|
|
|
| 90 |
text = raw.strip()
|
| 91 |
+
# Strip markdown code fences (e.g. ```json ... ``` or ``` ... ```)
|
| 92 |
if text.startswith("```"):
|
| 93 |
+
# Drop the entire opening fence line (```json, ```python, or just ```)
|
| 94 |
+
first_newline = text.find("\n")
|
| 95 |
+
text = text[first_newline + 1:] if first_newline != -1 else text[3:]
|
| 96 |
+
# Drop the closing fence
|
| 97 |
if text.rstrip().endswith("```"):
|
| 98 |
text = text.rstrip()[:-3].rstrip()
|
| 99 |
|