Your privacy choices

We use cookies and similar technologies. The necessary ones keep the site working. With your permission we would also use others, which you can review in the settings. You can change your mind at any time.

FD

fancy-diff

@particle-academy/fancy-diff

Human+ side-by-side document diff with hunk acceptance — a client-side, zero-dep diff engine or a git unified-diff datasource.

UI surfaceTS 1 components
UI surface
1 components, each with a live demo, props table, and source.
- old line
+ new line
ButtonlivebetaCardRK
$npm install @particle-academy/fancy-diff
One handler, two operatorsHuman+ contract
Human — keystroke
<FancyDiff
  value={value}
  onChange={setValue}
/>
Agent — MCP tool call
tools.call(
  "diff_accept_hunk",
  { … }
)
diff_accept_hunkdiff_reject_hunk
Why
Reviewing and accepting changes is the human's job in a Human+ app — and the changes increasingly come from an agent that drafts an edit and waits for a person to confirm it. That is the trust-but-verify loop: agents propose, humans accept or reject, hunk by hunk. Every team rebuilds this surface and most ship a read-only diff with no acceptance, or bolt acceptance onto opaque DOM an embedded agent can't drive. fancy-diff closes the gap with a controlled, client-side diff viewer where a human and an agent operate the same acceptance state — no server processing, no third-party runtime deps, and no DOM scraping.
What
A React side-by-side (or inline) document diff viewer with per-hunk accept/reject and a live merged result. The diff engine — line-level LCS plus intra-line word/char segments — runs in-browser, in-house, with zero third-party runtime dependencies. Acceptance is controlled: value is a Record<hunkId, "accepted" | "rejected" | "pending"> map with onChange; getMergedResult() / onResult fold the diff and acceptance into the merged document. The source is a JSON-friendly discriminated union with three datasources: { before, after } (compute the diff in-house), { unified } (parse a git unified diff), or { diff } (a pre-built structured Diff). It composes react-fancy primitives (toolbar, buttons, badges, cards), exposes stable data-fancy-diff-hunk handles plus render-prop slots (renderHunk / renderToolbar / renderGutter), supports mode="split" | "inline" and trust-but-verify pendingMode, and emits optional AutoActivity events through @particle-academy/fancy-auto-common. Git-diff caveat: a unified diff carries only the changed hunks plus a little context, so parsed files are flagged partial and the merged result reconstructs only the lines in the diff window — feed full { before, after } documents when you need a fully merged file.
How
Install npm i @particle-academy/fancy-diff (peers: react, react-dom, @particle-academy/react-fancy) and import the stylesheet: import { FancyDiff } from "@particle-academy/fancy-diff"; import "@particle-academy/fancy-diff/styles.css";. Diff two documents: <FancyDiff source={{ before, after }} value={value} onChange={setValue} onResult={(r) => setMerged(r.text)} />. Parse a git diff instead: <FancyDiff source={{ unified }} mode="inline" />. Read the merged document imperatively via a ref — ref.current.getMergedResult().text — and turn on pendingMode so an embedded agent stages proposals a human confirms. A one-sitting MCP bridge maps diff_accept_hunk / diff_reject_hunk onto the same controlled value/onChange loop.

Components

1 component · click any tile for a full demo, source, and install snippet.

FancyDiffOpen →
src/auth.tspartial
12export function verify(token: string) {
12export function verify(token: string) {
13- return decode(token);
13+ if (!token) return null;
14+ return decode(token);
14}
15}
Controlled split / inline diff viewer; per-hunk accept/reject with a merged result, render-prop customization, and a git unified-diff datasource.
What next
Click any component for a live demo, props, and source — or install the package and go.