Skip to content

AgentFileDiff

A dual-target review surface for Agent changes: unified/split layouts, inline changes, collapsed context, line selection, and accept/reject actions.

Demo

AgentFileDiffOne public API for H5 and Wevu
Live state
Release readiness workflowAgentFileDiff
src/runtime/create-agent-stream.tsRunning
+2−1
@@ -16,5 +16,6 @@ createAgentStream
3 changed lines

Install

bash
pnpm add @varo-ui/ai
pnpm dlx @varo-ui/cli add --target h5 components/agent-ui
pnpm dlx @varo-ui/cli add --target weapp components/agent-ui

Registry installs the UI component into your project, so import it from @/components/agent-ui; @varo-ui/ai provides the event protocol, stream controller, and Markdown primitives—not Vue/Wevu UI components.

Basic Usage

vue
<script setup lang="ts">
import type { AgentDiffLine, AgentDiffView } from '@/components/agent-ui'
import { shallowRef } from 'vue'
import { AgentFileDiff } from '@/components/agent-ui'

const view = shallowRef<AgentDiffView>('unified')
const lines: AgentDiffLine[] = [
  { content: '@@ -16,5 +16,6 @@ createAgentStream', type: 'hunk' },
  { content: '  const status = shallowRef<\'idle\' | \'done\'>(\'idle\')', oldNumber: 17, type: 'remove' },
  { content: '  const status = shallowRef<AgentStreamStatus>(\'streaming\')', newNumber: 17, type: 'add' },
  { content: '  const scheduler = target === \'weapp\' ? \'time-slice\' : \'raf\'', newNumber: 18, type: 'add' },
  { collapsedLines: 18, content: '@@ More unchanged context', type: 'hunk' }
]
</script>

<template>
  <AgentFileDiff
    v-model:view="view"
    filename="src/runtime/create-agent-stream.ts"
    :lines="lines"
    @accept="applyChanges"
    @reject="discardChanges"
  />
</template>

Props

PropTypeDefaultDescription
classNameClassValueundefinedRoot classes merged by the target-specific cn helper
filenamestringrequiredFile path; the header separates directory and basename
linesAgentDiffLine[][]Diff rows supporting add, remove, context, and hunk
additionsnumberautoOverrides the computed addition count
deletionsnumberautoOverrides the computed deletion count
openbooleanundefinedControlled expanded state
defaultOpenbooleantrueInitial uncontrolled expanded state
viewAgentDiffViewundefinedControlled unified / split view
defaultViewAgentDiffViewunifiedInitial uncontrolled view
wrapbooleanundefinedControlled code wrapping state
defaultWrapbooleanfalseInitial uncontrolled wrapping state
lineNumbersbooleanundefinedControlled line-number state
defaultLineNumbersbooleantrueInitial uncontrolled line-number state
indicatorsbars | classic | nonebarsChange indicator treatment
inlineChangesbooleantrueHighlights changed spans in paired deletion/addition rows
showToolbarbooleantrueShows layout, wrapping, and line-number controls
showActionsbooleantrueShows accept/reject actions
disabledbooleanfalseDisables review actions
labelsPartial<AgentFileDiffLabels>{}Overrides interface copy
statusAgentAdvancedStatuscompletedAgent status

Events

EventPayloadDescription
acceptvoidAccepts the current file change
rejectvoidRejects the current file change
selectAgentDiffSelectionSelects a unified row or one side of a split row
expand(line, index)Requests expansion of collapsed hunk context
update:openbooleanExpanded state changed
update:viewAgentDiffViewUnified/split view changed
update:wrapbooleanWrapping state changed
update:lineNumbersbooleanLine-number state changed

Slots

SlotPropsDescription
line{ line, index, side }Overrides code-content rendering for an existing token highlighter

Design Boundary

The visual and interaction model draws from @pierre/diffs: a neutral code surface, restrained addition/deletion layers, gutter indicators, unified/split layouts, inline changes, and expandable hunks.

Varo is not a port. @pierre/diffs uses Shadow DOM, Shiki, worker pools, and large-scale virtualization for browser code review; those systems cannot run directly in a mini program. AgentFileDiff keeps the lighter data contract and consistent interactions appropriate for Agent output on both targets. For H5-only products needing huge diffs, syntax highlighting, annotations, or editing, use @pierre/diffs directly.

Target Notes

TargetImport
H5Named export from @/components/agent-ui
weappDefault export from @/components/agent-ui/AgentFileDiff.vue; types from @/components/agent-ui/file-diff

The public API stays aligned across targets; DOM/WXML, scheduling, and native events are target-owned.