Skip to content
AgentsFile edit toolMenu

File edit tool

A file edit: path and +12 -3 in the header, a unified mini diff that reads without color. During approval, the diff is what the user approves.

A unified mini diff with +5 -3 in the header.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/tool-file-edit.json

Usage

tsx
import { ToolFileEdit } from "@/components/ui/chatcn/tool-file-edit"

<ToolFileEdit state="output-available" path={path} oldText={before} newText={after} startLine={4} />
<ToolFileEdit state="output-available" path={path} diff={unifiedDiff} />
tsx
import { ToolFileEditPart, toolFileEditRenderers } from "@/components/ui/chatcn/tool-file-edit"

// One part straight from AI SDK or the chatcn contract
<ToolFileEditPart part={part} onApprove={approve} onDeny={deny} />

// Or map tool names to renderers for a whole message
renderToolPart(part, { ...toolFileEditRenderers })

Examples

Approval

The diff is what the user approves.

Props

PropTypeNotes
pathstring
oldText, newTextstringDiffed line by line
diffstringA unified diff instead
linesDiffLine[]Precomputed lines. Wins over both
startLinenumberLine where the snippet starts
additions, deletionsnumberOverride the counts
onOpenDiff() => voidShows Open diff under the preview
stateToolDisplayStateThe ToolCall lifecycle: streaming, running, approval, output, error, denied, cancelled
approval, decisionApproval request and the user's answer, as on ToolCall
onApprove, onDeny, onRetrySame callbacks as ToolCall
errorTextReactNodeShown on output-error
durationMs, startedAtnumberOptional. Measured automatically when omitted
variant"card" | "inline"Inline sits on a trace rail
open, defaultOpen, onOpenChangeControlled or uncontrolled details

Keyboard

KeyAction
Enter, SpaceExpand or collapse the details
TabMove through the header, links, copy buttons and approval actions

Accessibility

  • Added lines sit on a fill in full ink and medium weight; removed lines are struck through in gray. Plus and minus signs carry the meaning, and screen readers hear Added and Removed before each line.

Motion

  • Inherits ToolCall: the status glyph swaps with a 150 ms blur crossfade and details open over 200 ms.
  • Nothing inside the body animates. Under reduced motion everything snaps.