model

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package model defines the core domain types for scry.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOversized  = errors.New("patch exceeds size threshold")
	ErrBinaryFile = errors.New("binary file")
	ErrSubmodule  = errors.New("submodule change")
)

Sentinel errors for PatchService edge cases.

Functions

This section is empty.

Types

type AppState

type AppState struct {
	Compare          ResolvedCompare
	CompareBasis     CompareBasis
	Files            []FileSummary
	SelectedFile     int // Index into Files. -1 when Files is empty.
	Patches          map[string]PatchLoadState
	CacheGeneration  int
	IgnoreWhitespace bool
	SearchQuery      string
	FocusPane        Pane
	Layout           LayoutMode
	PatchLineMode    LineMode
	PatchDiffMode    PatchDiffMode

	// Watch mode state (v0.2).
	WatchEnabled    bool
	WatchInterval   time.Duration
	LastFingerprint string
	RefreshInFlight bool
	LastRefreshAt   time.Time

	// Commit generation state (v0.2).
	CommitEnabled bool
	CommitAuto    bool
	CommitState   CommitState

	// Freshness tracking (v0.3).
	GroupByDirectory bool           // config-driven directory grouping in file list
	FileChangeGen    map[string]int // path → CacheGeneration when file last changed

	// Worktree dashboard mode (v0.2).
	WorktreeMode   bool
	DashboardState DashboardState

	// Discard confirmation state.
	ConfirmDiscard   bool
	DiscardPath      string
	DiscardUntracked bool
	DiscardInFlight  bool
	DiscardErr       string
}

AppState is the top-level UI state threaded through the Bubble Tea model.

type CommitState added in v0.2.0

type CommitState struct {
	GeneratedMessage string
	Provider         string
	InFlight         bool
	Err              error
	Generation       int // monotonic counter to discard stale async results

	// Execution state (V2-T8).
	Executing bool
	CommitSHA string
	CommitErr error
}

CommitState holds the state of AI commit message generation and execution.

type CompareBasis added in v0.3.10

type CompareBasis string

CompareBasis selects which merge-base strategy scry uses for branch diffs.

const (
	CompareBasisUpstream   CompareBasis = "upstream"
	CompareBasisLocalTrunk CompareBasis = "local-trunk"
	CompareBasisHeadDirty  CompareBasis = "head-dirty"
)

func (CompareBasis) Label added in v0.3.10

func (b CompareBasis) Label() string

func (CompareBasis) Next added in v0.7.0

func (b CompareBasis) Next() CompareBasis

func (CompareBasis) StatusLabel added in v0.3.10

func (b CompareBasis) StatusLabel() string

type CompareMode

type CompareMode string
const (
	CompareThreeDot CompareMode = "three-dot"
	CompareTwoDot   CompareMode = "two-dot"
)

type CompareRequest

type CompareRequest struct {
	Repo             RepoContext
	BaseRef          string
	Basis            CompareBasis
	HeadRef          string
	Mode             CompareMode
	IgnoreWhitespace bool
}

type DashboardState added in v0.2.0

type DashboardState struct {
	Worktrees         []WorktreeInfo
	SelectedIdx       int
	ScrollOffset      int
	DrillDown         bool // true when viewing a worktree's diff
	DrillGeneration   int  // monotonic counter to discard stale drill-down results
	RefreshGeneration int  // monotonic counter to discard stale worktree refresh results

	// Preview pane state.
	PreviewCache map[string]PreviewEntry // cache key (snap) → preview data
	PreviewFiles []FileSummary           // current selection's preview (for rendering)

	// Deletion state.
	ConfirmDelete  bool   // true when awaiting deletion confirmation
	DeletePath     string // path of worktree to delete
	DeleteBranch   string // branch name of worktree being deleted
	DeleteDirty    bool   // true if the worktree is dirty (requires force)
	DeleteErr      string // error message from failed deletion
	DeleteIsMain   bool   // true if user tried to delete main worktree
	DeleteInFlight bool   // true while async deletion is running
}

DashboardState holds the state for the worktree dashboard view.

type DiffLine

type DiffLine struct {
	Kind  LineKind
	OldNo *int
	NewNo *int
	Text  string
}

type FilePatch

type FilePatch struct {
	Summary FileSummary
	Hunks   []Hunk
}

type FileStatus

type FileStatus string
const (
	StatusAdded     FileStatus = "A"
	StatusModified  FileStatus = "M"
	StatusDeleted   FileStatus = "D"
	StatusRenamed   FileStatus = "R"
	StatusCopied    FileStatus = "C"
	StatusTypeChg   FileStatus = "T"
	StatusUnmerged  FileStatus = "U"
	StatusUntracked FileStatus = "?"
)

type FileSummary

type FileSummary struct {
	Path        string
	OldPath     string
	Status      FileStatus
	Additions   int
	Deletions   int
	IsBinary    bool
	IsSubmodule bool
}

type Hunk

type Hunk struct {
	Header           string
	OldStart, OldLen int
	NewStart, NewLen int
	Lines            []DiffLine
}

type LayoutMode added in v0.2.0

type LayoutMode string

LayoutMode controls the overall pane arrangement.

const (
	LayoutModal LayoutMode = "modal"
	LayoutSplit LayoutMode = "split"
)

type LineKind

type LineKind string
const (
	LineContext   LineKind = "context"
	LineAdded     LineKind = "added"
	LineDeleted   LineKind = "deleted"
	LineNoNewline LineKind = "no-newline"
)

type LineMode added in v0.4.0

type LineMode int

LineMode controls how long patch body lines are laid out.

const (
	LineModeWrap LineMode = iota
	LineModeScroll
)

type LoadStatus

type LoadStatus string

LoadStatus tracks the lifecycle of an async patch load.

const (
	LoadIdle    LoadStatus = "idle"
	LoadLoading LoadStatus = "loading"
	LoadLoaded  LoadStatus = "loaded"
	LoadFailed  LoadStatus = "failed"
)

type Pane

type Pane string

Pane identifies a UI focus area.

const (
	PaneFiles  Pane = "files"
	PanePatch  Pane = "patch"
	PaneSearch Pane = "search"
	PaneCommit Pane = "commit"
	PaneIdle   Pane = "idle"
)
const PaneDashboard Pane = "dashboard"

PaneDashboard is the focus pane for worktree dashboard mode.

type PatchDiffMode added in v0.6.0

type PatchDiffMode int

PatchDiffMode controls whether a patch is rendered as unified or side-by-side.

const (
	PatchDiffModeUnified PatchDiffMode = iota
	PatchDiffModeSideBySide
)

type PatchLoadState

type PatchLoadState struct {
	Status      LoadStatus
	Patch       *FilePatch
	Err         error
	Generation  int
	ContentHash string // SHA-256 of patch content for scroll preservation
}

PatchLoadState holds the result of loading a single file's patch.

type PreviewEntry added in v0.3.0

type PreviewEntry struct {
	Files []FileSummary
}

PreviewEntry holds cached preview data for a worktree.

type RepoContext

type RepoContext struct {
	WorktreeRoot     string // git rev-parse --show-toplevel
	GitDir           string // git rev-parse --absolute-git-dir (per-worktree)
	GitCommonDir     string // git rev-parse --git-common-dir (shared across worktrees)
	IsLinkedWorktree bool   // GitDir != GitCommonDir after path canonicalization
}

RepoContext is resolved once at startup via git rev-parse. In a linked worktree, .git is a file (not a directory), so code must NEVER construct paths via WorktreeRoot + ".git" + "...".

type ResolvedCompare

type ResolvedCompare struct {
	Repo         RepoContext
	BaseRef      string
	Basis        CompareBasis
	HeadRef      string
	WorkingTree  bool   // true when diffing against the working tree (no head ref).
	MergeBase    string // SHA of merge-base in three-dot mode; empty string in two-dot mode.
	DiffRange    string // Range string passed to git diff: "base...head", "base..head", or just "base" in working tree mode.
	WatchBaseRef string // Symbolic base ref for watch fingerprinting (e.g. "origin/main"); empty when @{upstream} was used.
}

type WorktreeInfo added in v0.2.0

type WorktreeInfo struct {
	Path            string    // absolute path
	Branch          string    // short branch name (e.g. "main", "feature")
	CommitHash      string    // short commit hash
	Subject         string    // first line of commit message
	Dirty           bool      // true if worktree has uncommitted changes
	Bare            bool      // true if bare worktree
	ChangedFiles    int       // number of changed files from git status
	HeadCommittedAt time.Time // committer date of HEAD commit (git-based staleness)
	LastActivityAt  time.Time // updated when snapshot state changes (dirty, count, commit)
}

WorktreeInfo holds the display state for a single worktree in the dashboard.

Jump to

Keyboard shortcuts

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