Commit & PR Description Writer
Describe what you changed and why in your own rough words. Get a clean commit message and PR description that explain the reasoning, not just the diff.
New to this? Read the guide.
What it produces
Real output from this tool, not a mock-up.
What went in
- What changed and why
- I changed how we parse the JSON that comes back from the model. Before it was just JSON.parse on the slice between the first brace and the last brace. Problem is the model sometimes puts a real newline inside a string instead of an escaped one, which is invalid JSON, and then the whole parse throws and the user gets a 502 even though the content was fine. Now it tries a strict parse first and only if that fails does it repair control characters inside string literals and try again. Moved it to its own module because the anthropic file imports server-only so you cannot import it from a test script.
- What you need
- Both
- Diff or file list
- src/lib/model-json.ts (new), src/lib/anthropic.ts (modified)
Commit message
fix: repair unescaped control chars in model JSON before failing JSON.parse on the sliced response was throwing whenever the model put a literal newline inside a string instead of an escaped one. That's invalid JSON but the content itself was usually fine, so users were getting a 502 for no real reason. Now we try a strict parse first, and only if that fails do we repair control characters inside string literals and retry. If that also fails we throw like before. Moved the parsing logic into its own module (src/lib/model-json.ts) since anthropic.ts imports server-only, which blocks importing it from a test script.
PR description
Fixes spurious 502s caused by the model returning JSON with a literal newline (or other control character) inside a string value instead of an escaped one. That's technically invalid JSON, so the old parse (JSON.parse on the slice between the first and last brace) would throw immediately even though the actual content was fine. What changed: - Added src/lib/model-json.ts with the parsing logic: try a strict JSON.parse first, and only if that fails, repair control characters inside string literals and retry. - If the repaired parse still fails, it throws like before, so real parse failures still surface as errors. - Moved this out of anthropic.ts into its own module because anthropic.ts imports server-only, which made it impossible to import the parsing logic from a test script.
When to use it
Use this when the change is done and the write-up is the last thing between you and opening the pull request. Describe what you changed and why in your own rough words, and it produces a commit message and a PR description that explain the reasoning rather than restating the diff.