#437

feat(core): report patch lines that do not parse

Openxubenqiangwants to merge intofrom

Fixes #420

A line that starts with { and has an "op" key but fails parseSpecStreamLine — a truncated patch, for example — was handled two ways and neither reported it: inside a ```spec fence it was dropped silently, outside one it was shown as prose. When the token limit cuts a replace short the spec stays valid, so a validator sees nothing wrong and the user sees an edit that never happened.

Change

packages/core/src/types.ts

  • onInvalid?(line) on MixedStreamCallbacks and on a new JsonRenderTransformOptions passed to createJsonRenderTransform(options?). It fires only for patch-shaped lines ({ … "op":), so ordinary prose that starts with { is unaffected.
  • dropInvalidPatches?: boolean on both: a patch-shaped line outside a fence is then dropped instead of streamed as text. Inside a fence such a line is always dropped, as before.
  • createMixedStreamParser(callbacks, options?) keeps its existing call shape; the second argument is optional.
  • Exported MixedStreamParserOptions and JsonRenderTransformOptions from the package.

Tests

packages/core/src/types.test.ts

  • Mixed parser: reports an unparsable patch inside a fence (no text, no patch); reports one outside a fence and still emits it as text by default; drops it outside a fence with dropInvalidPatches: true; leaves {not a patch} alone.
  • Transform: the same inside-fence and outside-fence cases over real chunks, including the dropped-line text assertion.

Verified: pnpm exec vitest run packages/core/src/types.test.ts -> 131 passed; with types.ts reverted, the six new tests fail. tsc -p packages/core/tsconfig.check.json exits 0 and prettier --check is clean.

Activity

4
copilot-pull-request-reviewer[bot]reviewed16d ago
copilot-pull-request-reviewer[bot]16d ago

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

vercel[bot]16d ago

@xubenqiang is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot]reviewed16d ago