Skip to content

feat(diff): render diffs with Pierre diffs and share one syntax palette - #10234

Merged
waleedlatif1 merged 6 commits into
stagingfrom
feat/pierre-diffs-embed
Nov 20, 2026
Merged

waleedlatif1 merged 6 commits into
stagingfrom
feat/pierre-diffs-embed

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Diff embeds (```diff fences in chat and files) render code diffs with @pierre/diffs (pinned 1.6.4): syntax highlighting by file type, word-level changes, +/− markers, per-file headers for multi-file git diffs. Hunk separators show only the heading. Our parser still validates the fence and resolves sim: sources; lib/diff/patch.ts converts its hunks to Pierre's model, so agent diffs without line numbers keep working (numbers hidden, headings kept).
  • Workflow comparison field diffs render through Pierre on the full before/after text: highlighted by field (the block's code language, JSON, or prose), word-level changes, folds that expand in place. text-diff-lines.ts and its test are removed; the 2000-line guard, the 12-line cap for one-sided bodies, and the expand-all control stay.
  • One renderer: both surfaces go through SimFileDiff, which owns the theme, markers and change colors mapped onto Sim's tokens.
  • One syntax palette: the Prism colors in code.css are now --code-token-* variables. The Shiki scope mapping docs already maintained moved to @sim/emcn/syntax-theme; docs and diffs both build on it, so diffs color code exactly like Code.
  • DiffView keeps only the side-by-side document comparison, which Pierre does not cover.

Notes

  • Pierre renders in a shadow root; Sim's palette reaches it through inherited custom properties and the registered sim-code theme. No !important.
  • Bundle: ~100KB gzip for the diff component plus per-language grammar chunks. Default Shiki JS regex engine, so no CSP change.
  • hast-util-to-html resolves to 9.0.5 (Pierre pins it) instead of 9.0.6.

Test plan

  • lib/diff/patch.test.ts: lines kept in order and side, heading-only separators (including the first hunk), real line numbers kept, add-only hunks, multi-file split. Mutation-checked: removing the heading gap or the heading override turns tests red.
  • Docs Shiki options before/after the move: byte-identical.
  • Prism code block with staging vs new code.css: 0 differing pixels, light and dark.
  • Rendered staging vs this branch side by side (real components, app stylesheet), light and dark: git diff with numbers, agent diff without numbers, multi-file diff, prose comparison (unchanged), JS function edit, long prompt with distant edits, one-sided new block code, JSON.
  • Interactions: fold expander reveals hidden lines (13 → 35), "N more lines" uncaps a one-sided body (12 → 30), "Show all lines"/"Collapse unchanged" toggles (30 → 65 → 30). No console errors.
  • Type-check (all workspaces) and targeted audits (file-names, comment-hygiene, utils, client-boundary, test-patterns, import-specifiers, explicit-any, boundaries, source-conventions).

Code diffs in ```diff fences now render through @pierre/diffs: syntax
highlighting by file type, word-level changes, and per-file headers for
multi-file git diffs, themed with Sim's surface and badge tokens. Our parser
still validates the fence and resolves sim: sources; its hunks are written
back out as a well-formed patch, so agent diffs without hunk line numbers
keep working with line numbers hidden and hunk headings shown.

DiffView keeps only the side-by-side document comparison, which Pierre
does not cover.
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner November 20, 2026 06:16
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 20, 2026 7:20am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

This PR moves code diffs to Pierre and shares syntax colors between docs and the app.

  • Code diff blocks show syntax-colored changes by file.
  • Workflow field diffs highlight code in the field's language.
  • Docs and diff views draw syntax colors from one shared mapping.

Reviews (4) · Last reviewed commit: "fix(diff): resolve a code field's langua..." · Reviewed by Greptile

Comment thread apps/sim/components/diff/patch-view.tsx Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/components/diff/patch-view.tsx Resolved
Workflow comparison field diffs now render through Pierre too, on the full
before and after text: syntax highlighted by field (code language, JSON,
prose), word-level changes, and expandable folds. The hand-rolled line
engine in text-diff-lines.ts and its test are gone; the size guard, the
one-sided cap and the expand-all control stay.

Both diff surfaces render through SimFileDiff, which owns the theme, the
+/- markers and Sim's change colors. Diffs color code like Code does: the
Prism palette in code.css is now --code-token-* variables, and the Shiki
scope mapping docs already maintained moved into emcn (syntax-theme.ts) so
docs and the app share it. Docs output is byte-identical and Prism code
blocks are pixel-identical.

Embed polish: hunk separators show only the heading, diffs without line
numbers keep their first heading, and the patch conversion moved to
lib/diff/patch.ts with tests.
@waleedlatif1 waleedlatif1 changed the title feat(diff): render code diffs in diff embeds with Pierre diffs feat(diff): render diffs with Pierre diffs and share one syntax palette Nov 20, 2026
A numbered hunk that only inserts or only deletes has no line carrying the
empty side's position, so it was re-derived from the previous hunk and the
header pointed at the wrong lines. The parser now keeps the header's starts
and the patch conversion emits them verbatim, inventing positions only for
diffs written without line numbers.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 20 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/docs/scripts/compile-content.ts">

<violation number="1" location="apps/docs/scripts/compile-content.ts:476">
P2: Watching the file itself loses the watcher after an atomic editor save, so docs watch mode stops rebuilding on later syntax-theme changes. Watch the containing directory and filter for this filename instead.</violation>
</file>

<file name="apps/sim/components/diff/patch-view.tsx">

<violation number="1" location="apps/sim/components/diff/patch-view.tsx:21">
P2: A mixed numbered/un-numbered patch displays fabricated line numbers for its un-numbered hunks. Disable line numbers unless every hunk is numbered, or compute this per rendered file so the adapter’s invented positions remain hidden.</violation>
</file>

<file name="apps/sim/app/workspace/[workspaceId]/w/components/workflow-diff/components/change-list/field-change-row.tsx">

<violation number="1" location="apps/sim/app/workspace/[workspaceId]/w/components/workflow-diff/components/change-list/field-change-row.tsx:145">
P2: Daytona TypeScript code diffs are highlighted as JavaScript. `isValidCodeLanguage` does not include `typescript`, and the Daytona code config has no language fallback, so pass through or explicitly map the supported `typescript` value for syntax highlighting.</violation>
</file>

<file name="apps/sim/app/workspace/[workspaceId]/w/components/workflow-diff/components/change-list/text-diff.tsx">

<violation number="1" location="apps/sim/app/workspace/[workspaceId]/w/components/workflow-diff/components/change-list/text-diff.tsx:92">
P2: This renders an empty diff when a changed text value differs only by line ending or a final newline. Handle the no-hunk case explicitly (or normalize before `FieldChangeRow` decides to render `TextDiff`) so the change is not shown as a blank field.</violation>
</file>

<file name="apps/sim/lib/diff/patch.ts">

<violation number="1" location="apps/sim/lib/diff/patch.ts:68">
P2: `toFileDiffs` lets Pierre’s default line matcher rewrite the synthetic patch, so agent hunk order or boundaries can change. Pass `{ disableLineMatching: true }` to preserve the parsed hunks.</violation>
</file>

Comment thread apps/docs/scripts/compile-content.ts Resolved
Comment thread apps/sim/components/diff/patch-view.tsx Resolved
Comment thread apps/sim/lib/diff/patch.ts Resolved
- Render a diff's lines in the order they were written: Pierre's similarity
  realignment could split one written change into several blocks.
- Show line numbers only when every hunk has them, so positions invented
  for an unnumbered hunk never appear in a mixed diff.
- Highlight code fields through an explicit map of the languages blocks
  offer, adding TypeScript (Daytona) and keeping shell as bash.
- Say "Only line endings changed" when normalizing line endings leaves a
  changed value with no visible difference, instead of an empty diff.
- Watch the syntax theme's folder in docs watch mode, since an editor's
  atomic save ends a watch on the file itself.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 20 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

A removed block's language exists only in the base version, and an empty
saved language short-circuited the lookup, so both fell back to JavaScript
or to no highlighting. The language now comes from the target values, then
the base values, then the field default, through a Map so only the listed
languages can match.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 20 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 9ca9ace into staging Nov 20, 2026
95 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/pierre-diffs-embed branch November 20, 2026 18:40

This branch was previously deployed

1 inactive deployment
Preview — d39e9f22 Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant