Parse JSON from AI response, stripping markdown fences.
(response: str)
| 122 | |
| 123 | |
| 124 | def parse_json_response(response: str) -> Optional[Dict]: |
| 125 | """Parse JSON from AI response, stripping markdown fences.""" |
| 126 | text = response.strip() |
| 127 | if text.startswith("```"): |
| 128 | lines = text.split("\n") |
| 129 | lines = lines[1:] # remove opening fence (may include language specifier) |
| 130 | if lines and lines[-1].strip().startswith("```"): |
| 131 | lines = lines[:-1] # remove closing fence |
| 132 | text = "\n".join(lines) |
| 133 | try: |
| 134 | return json.loads(text) |
| 135 | except json.JSONDecodeError as e: |
| 136 | print(f" JSON parse error: {e}") |
| 137 | print(f" Response: {text[:500]}") |
| 138 | return None |
| 139 | |
| 140 | |
| 141 | def get_repo_root() -> str: |
no outgoing calls
no test coverage detected