diffview

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package diffview presents captured diff navigation and provisional live cards. Preview snapshots are observations, never completed edit evidence.

Index

Constants

View Source
const (
	PreviewFrameDelay = 33 * time.Millisecond

	PreviewMaxStagger = 96 * time.Millisecond
	// Keep consecutive target units visually distinct: the next unit starts
	// after the preceding unit's last row has finished fading in.
	PreviewUnitDelay = liveDiffPreviewFade + PreviewMaxStagger
	// A finished call keeps distinct unit reveals only this long before its
	// remaining input is shown at once.
	PreviewFinishDrain = time.Second
)
View Source
const (
	PreviewEdit        = "edit"
	PreviewRunning     = "running"
	PreviewPending     = "pending"
	PreviewUnavailable = "unavailable: "
)

Preview status names what a card shows; the viewer renders the state.

Variables

This section is empty.

Functions

func CallerStyle

func CallerStyle(theme livediff.Theme) func(string) (string, string)

CallerStyle is how the diff presents a canonical agent path.

func Callers

func Callers(view *livediff.View) []string

Callers lists the caller filter keys with captures, main first.

func CountStats

func CountStats(count livediff.Counts, theme livediff.Theme) string

CountStats shows known line counts; unknown counts are not zero.

func FileLabel

func FileLabel(status Status, label, workspace string, theme livediff.Theme) string

FileLabel prefixes a file label with its colored status; a rename also names its source. Every file row (tree, flat list, Changes tab, streaming title) uses this format.

func PreviewBirths

func PreviewBirths(before, after []PreviewRow, born []time.Time, now time.Time) []time.Time

PreviewBirths carries reveal times across a snapshot. Unchanged rows and rows that only grew keep theirs, so a streaming line does not restart its fade; newly revealed rows cascade in order.

Types

type ChangeRow

type ChangeRow struct {
	Kind byte // 'b' branch, 'c' change, 'f' file
	Node int
	File int // Index into node.files for 'f' rows.
	// contains filtered or unexported fields
}

type ChangeTarget

type ChangeTarget struct{ Change, File string }
type NavEntry struct {
	ID, Label, Folder  string
	File, Depth, Count int
}
type Navigation struct {
	Flat, Hidden, Focused, Filtering bool
	Query                            string
	Collapsed                        map[string]bool
	Entries                          []NavEntry
	Matches                          []int
	Cursor, Top                      int
	// hover is the pointed entry plus one; zero points at none.
	Hover       int
	Columns     int
	SavedCursor string
	SavedTop    string

	// changes is the Changes tab, shown instead of files when set.
	Changes    liveDiffChanges
	ChangesTab bool
	// dots marks each file row with its callers, by view index.
	Dots []string
	// caller is the view's caller filter, for the heading.
	Caller string
	// contains filtered or unexported fields
}

Navigation is a presentation index. Capture order and evidence stay owned by View.

func (n *Navigation) EnsureVisible(rows int)
func (n *Navigation) Rebuild(files []livediff.File, workspace string)
func (n *Navigation) Render(files []livediff.File, counts []livediff.Counts, selected, width, rows int, theme livediff.Theme) []string
func (n *Navigation) Width(width int) int

type Preview

type Preview struct {
	ID        string
	Workspace string
	Caller    string
	Turn      string `json:",omitzero"`
	Thread    string
	Files     []mekugi.ReviewFile
	Input     string // Display-only text, never executed.
	Truncated bool
	Evaluated bool `json:",omitzero"`
	Complete  bool `json:",omitzero"`
	DiffText  bool `json:",omitzero"`
	Status    string
	Footer    string `json:",omitempty"`
	Tool      string `json:",omitempty"` // The evidenced editing tool, not its host executor.
}

Preview state is router-lifetime only and never enters the replay store.

type PreviewMotion

type PreviewMotion struct {
	Enabled bool
	Canvas  livediff.Canvas
	Now     time.Time
}

Motion is display-only. Without it, rows appear at their final colors.

type PreviewPane

type PreviewPane struct {
	Views  map[string]*PreviewView
	Order  []string
	Motion PreviewMotion
	Retain bool // Native edit batches retain completed calls until their individual holds expire.

	// A dock too short for every call keeps one card open and folds the rest
	// to their headings. Prefer names the caller whose card opens first.
	Prefer string

	Accordion bool // The last frame folded cards.
	Compact   bool // Keep concurrent cards folded even when an even split fits.
	// contains filtered or unexported fields
}

Previews have their own viewport and lifecycle. They never change the captured diff's selection, scroll, acknowledgements, or follow mode. Updates replace snapshots; only a displayed frame parses and lays out rows.

func (*PreviewPane) Animating

func (p *PreviewPane) Animating(now time.Time) bool

animating reports whether a displayed row is still fading in.

func (*PreviewPane) Callers

func (p *PreviewPane) Callers() []string

callers counts distinct callers with a card, for the dock heading.

func (*PreviewPane) ExpireBatches

func (p *PreviewPane) ExpireBatches(now time.Time, hold time.Duration) bool

ExpireBatches retires each completed call after its own settling interval. Running siblings and newer edits must not retain an older completed call.

func (*PreviewPane) Live

func (p *PreviewPane) Live() int

live counts calls whose input is still streaming.

func (*PreviewPane) NextBatch

func (p *PreviewPane) NextBatch(caller string) bool

func (*PreviewPane) Render

func (p *PreviewPane) Render(ctx context.Context, workspace string, theme livediff.Theme, width, height int) ([]string, error)

func (*PreviewPane) RenderBatch

func (p *PreviewPane) RenderBatch(ctx context.Context, caller, workspace string, theme livediff.Theme, width, height, minRows int) ([]string, error)

RenderBatch uses a newest-following window rather than shrinking older files. Cycling pins that window, so arriving edits never steal a manual selection. minRows includes the file heading. A smaller terminal shows only a summary.

func (*PreviewPane) Scroll

func (p *PreviewPane) Scroll(key byte) bool

A manual stream scroll pauses each visible card; new input still replaces its snapshot, without moving its source window. r restores each card's live tip.

func (*PreviewPane) ScrollBatch

func (p *PreviewPane) ScrollBatch(caller string, key byte) bool

ScrollBatch moves only the displayed file windows, independently of transcripts and captured diffs. Resuming follow also releases the manually pinned window.

func (*PreviewPane) Update

func (p *PreviewPane) Update(preview Preview)

type PreviewRow

type PreviewRow struct {
	Number int
	Kind   byte
	Text   string
}

type PreviewView

type PreviewView struct {
	Current  Preview
	Complete bool

	Rendered  Preview
	Focus     int
	Paused    bool
	ScrollRow int

	Source []PreviewRow

	Fading time.Time // Until a displayed row finishes fading in.
	// contains filtered or unexported fields
}

Each call owns its source window, syntax cache, and completion state.

func (*PreviewView) Render

func (p *PreviewView) Render(ctx context.Context, workspace string, theme livediff.Theme, width, height int, motion PreviewMotion) ([]string, error)

Render and color only a bounded source window around the streaming tip. Captured history composition stays out of this high-frequency path.

func (*PreviewView) Title

func (p *PreviewView) Title(workspace string, theme livediff.Theme, width int) string

title follows the agents roster: a state glyph, then what the card shows. Edits use the file navigator's status letter and live line counts.

type Status

type Status struct {
	Before, After string
	// Edited reports captured content changes, not missing evidence.
	Edited, Conflict bool
	Incomplete       bool
	Directory        bool
}

Status is a file row's net change, coded like git's short status: ? (incomplete evidence), A, D, M, R (rename only), RM (rename with edits), or UU (the net diff still adds conflict markers that mchanges revert or apply left for resolution).

func StatusOf

func StatusOf(regions ...mekugi.ReviewFile) Status

StatusOf classifies a file's diff regions, in capture order.

func (*Status) Add

func (s *Status) Add(region mekugi.ReviewFile)

add folds a later capture of the file into its status; before stays the first capture's.

func (Status) ShortCode

func (s Status) ShortCode() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL