refactor: render response as plaintext with newlines, fallback to JSON pretty-print

Co-authored-by: aider (o3) <aider@aider.chat>
This commit is contained in:
Mark Eaton
2025-09-17 19:14:48 -04:00
co-authored by aider
parent 9b4b607a20
commit 068e56f0ff
+11 -6
View File
@@ -50,12 +50,17 @@ def pretty_print_jsonl(path: Path, indent: int) -> None:
obj = json.loads(line) obj = json.loads(line)
except json.JSONDecodeError as exc: except json.JSONDecodeError as exc:
sys.exit(f"JSON decode error on line {idx}: {exc}") # fail fast sys.exit(f"JSON decode error on line {idx}: {exc}") # fail fast
# Build pretty JSON string, convert literal "\n" sequences to real newlines, # Prefer rendering the `response` field as plain-text, expanding literal
# and emit a blank line between records for readability. # "\n" sequences to real newlines. Fall back to JSON pretty-print if the
pretty = json.dumps(obj, indent=indent, ensure_ascii=False, sort_keys=True) # key is missing so we still show *something* useful.
pretty = pretty.replace("\\n", "\n") if "response" in obj:
sys.stdout.write(pretty) response_text = str(obj["response"]).replace("\\n", "\n")
sys.stdout.write("\n\n") sys.stdout.write(response_text)
sys.stdout.write("\n\n")
else:
pretty = json.dumps(obj, indent=indent, ensure_ascii=False, sort_keys=True)
sys.stdout.write(pretty)
sys.stdout.write("\n\n")
def main() -> None: def main() -> None: