Syntax-highlight diffs in the `clai2` web UI

Merged
MP
2mo ago
+129-60

Part 13 of the clai2 web UI stack (… → #10285 → this PR). Based on #10285. No linked issue: requested by the CLAI maintainer.

Why. Diffs in tool cards were plain text on tinted rows, while code blocks in replies were syntax-highlighted.

What changes (web UI only, no Python changes)

  • Language: diff lines are highlighted with the same highlight.js setup and colours as code blocks. The language comes from the file's extension, resolved by highlight.js itself (py, tsx, rs, yml, …). Unknown files stay plain, escaped text.
  • Whole sides, not single lines: each side of each hunk is highlighted as one text: the old side (context and removals) and the new side (context and additions). So a docstring or block comment that spans lines is coloured as in the file. The HTML is then split back into rows (highlightLines), closing and reopening the spans each line leaves open.
  • Colours: the green/red tint stays on the row and the +/− sign. The code itself keeps its syntax colours instead of being tinted, and follows the /theme palette like code blocks.

Verification.

  • tsc --noEmit and npm run build are clean. The bundle is rebuilt.
  • Headed Playwright, dark and light, against clai2 --web, on a saved edit_file diff of app.py:
    • every row carries highlight.js tokens (def, greet, name, the strings, the added docstring);
    • the token colours come from the active palette;
    • no page errors.
  • highlightLines, run in Node: a three-line docstring keeps its string colour on every line, every line's spans are balanced, plain text is escaped, and an empty side is handled.

What changes for existing users. Only the web UI, as above.

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.