Documentation
¶
Overview ¶
Package diff is the Stage-1 namespace for diff sandbox, staging, preview, summariser, test selector, and 3-way merge. See ../REFACTOR_PLAN.md.
Index ¶
- func BuildDependencyGraph(projectDir string) map[string][]string
- func EstimateTimeSaved(totalTests, selectedTests int) string
- func FormatConflictMarkers(conflict Diff3Conflict) string
- func FormatDiff3Result(result *Diff3Result) string
- func FormatSelection(selected *SelectedTests, changedFiles []string, language string, ...) string
- func GenerateTestCommand(selected *SelectedTests, language string) string
- func LCS(a, b []string) []string
- func MergeClean(base, ours, theirs string) (string, bool)
- func RenderUnified(change *FileChange) string
- type ChangeStats
- type Diff3Conflict
- type Diff3Region
- type Diff3Result
- type Diff3Stats
- type DiffHunk
- type DiffLine
- type DiffPreview
- func (dp *DiffPreview) Approve(path string)
- func (dp *DiffPreview) ApproveAll()
- func (dp *DiffPreview) Clear()
- func (dp *DiffPreview) GetApproved() []FileChange
- func (dp *DiffPreview) GetPending() []FileChange
- func (dp *DiffPreview) RecordChange(path, oldContent, newContent string)
- func (dp *DiffPreview) Reject(path string, comment string)
- func (dp *DiffPreview) RejectAll(comment string)
- func (dp *DiffPreview) RenderAll() string
- func (dp *DiffPreview) RenderSummary() string
- type DiffSandbox
- func (ds *DiffSandbox) Apply(path string) error
- func (ds *DiffSandbox) ApplyAll() (int, error)
- func (ds *DiffSandbox) DiffAll() string
- func (ds *DiffSandbox) DiffFor(path string) string
- func (ds *DiffSandbox) Disable()
- func (ds *DiffSandbox) Enable()
- func (ds *DiffSandbox) Format() string
- func (ds *DiffSandbox) Get(path string) *PendingChange
- func (ds *DiffSandbox) IsEnabled() bool
- func (ds *DiffSandbox) List() []*PendingChange
- func (ds *DiffSandbox) Reject(path string)
- func (ds *DiffSandbox) RejectAll()
- func (ds *DiffSandbox) Stage(path, action, oldContent, newContent string)
- type DiffSummarizer
- func (ds *DiffSummarizer) AssessImpact(summary *DiffSummary) string
- func (ds *DiffSummarizer) DetectChangeType(summary *DiffSummary) string
- func (ds *DiffSummarizer) FormatSummary(summary *DiffSummary) string
- func (ds *DiffSummarizer) GenerateCommitMessage(summary *DiffSummary) string
- func (ds *DiffSummarizer) GeneratePRSummary(summary *DiffSummary) string
- func (ds *DiffSummarizer) Summarize(diff string) *DiffSummary
- func (ds *DiffSummarizer) SummarizeFile(path string, hunks []string) *FileSummary
- type DiffSummary
- type Edit
- type FileChange
- type FileSummary
- type PendingChange
- type Preview
- type SelectedTests
- type StagedChange
- type StagedHunk
- type StagingArea
- func (sa *StagingArea) ApplyAll() ([]string, error)
- func (sa *StagingArea) ApplyFile(file string) error
- func (sa *StagingArea) ApproveHunk(file string, hunkIndex int)
- func (sa *StagingArea) Clear()
- func (sa *StagingArea) FormatStaging() string
- func (sa *StagingArea) GetDiff(file string) string
- func (sa *StagingArea) GetStaged() map[string]*StagedChange
- func (sa *StagingArea) HasPending() bool
- func (sa *StagingArea) Reject(file string)
- func (sa *StagingArea) RejectHunk(file string, hunkIndex int)
- func (sa *StagingArea) Stage(file, original, modified, description string)
- type Summarizer
- type Summary
- type TestSelector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDependencyGraph ¶
BuildDependencyGraph scans the project directory and builds a reverse import graph mapping packages to their dependents.
func EstimateTimeSaved ¶
EstimateTimeSaved returns a human-readable string estimating time savings.
func FormatConflictMarkers ¶
func FormatConflictMarkers(conflict Diff3Conflict) string
FormatConflictMarkers formats a conflict with standard diff3 markers.
func FormatDiff3Result ¶
func FormatDiff3Result(result *Diff3Result) string
FormatDiff3Result produces a human-readable summary of a Diff3Result.
func FormatSelection ¶
func FormatSelection(selected *SelectedTests, changedFiles []string, language string, totalTests int) string
FormatSelection produces a human-readable summary of the test selection.
func GenerateTestCommand ¶
func GenerateTestCommand(selected *SelectedTests, language string) string
GenerateTestCommand produces a runnable test command for the selected tests.
func MergeClean ¶
MergeClean performs a three-way merge and returns the merged string and whether the merge was clean (no conflicts).
func RenderUnified ¶
func RenderUnified(change *FileChange) string
RenderUnified renders a single FileChange in standard unified diff format.
Types ¶
type ChangeStats ¶
ChangeStats summarizes additions and deletions for a file change.
type Diff3Conflict ¶
type Diff3Conflict struct {
BaseLines []string
OursLines []string
TheirsLines []string
StartLine int
}
Diff3Conflict represents a single conflict region in the merge.
type Diff3Region ¶
type Diff3Region struct {
Type string // "unchanged", "ours", "theirs", "conflict"
BaseStart int
BaseEnd int
OursLines []string
TheirsLines []string
}
Diff3Region represents a classified region in the three-way diff.
type Diff3Result ¶
type Diff3Result struct {
Merged string
Conflicts []Diff3Conflict
HasConflicts bool
Stats Diff3Stats
}
Diff3Result holds the outcome of a three-way merge.
func Merge3 ¶
func Merge3(base, ours, theirs string) *Diff3Result
Merge3 performs a three-way merge using the diff3 algorithm. It splits base, ours, and theirs into lines, computes diff regions, and merges non-conflicting changes automatically while marking conflicts.
type Diff3Stats ¶
type Diff3Stats struct {
TotalLines int
ConflictCount int
AutoMerged int
OursOnly int
TheirsOnly int
}
Diff3Stats provides statistics about the merge operation.
type DiffHunk ¶
DiffHunk represents a contiguous block of changes with surrounding context.
func ComputeDiff ¶
ComputeDiff computes hunks between old and new content using Myers diff with 3 lines of context.
type DiffLine ¶
type DiffLine struct {
Type string // "add", "remove", "context"
Content string
OldLineNo int
NewLineNo int
}
DiffLine represents a single line in a diff hunk.
func ComputeMyersDiff ¶
ComputeMyersDiff implements Myers' O(ND) diff algorithm returning an edit script. It finds a minimal edit distance between sequences a and b, then returns the result as a series of DiffLine entries (context, add, remove).
type DiffPreview ¶
type DiffPreview struct {
Changes []FileChange
CreatedAt time.Time
SessionID string
// contains filtered or unexported fields
}
DiffPreview holds all pending changes for review before they are committed/applied.
func NewDiffPreview ¶
func NewDiffPreview() *DiffPreview
NewDiffPreview creates a new DiffPreview with a generated session ID.
func (*DiffPreview) Approve ¶
func (dp *DiffPreview) Approve(path string)
Approve marks a specific file change as approved.
func (*DiffPreview) ApproveAll ¶
func (dp *DiffPreview) ApproveAll()
ApproveAll marks all changes as approved.
func (*DiffPreview) GetApproved ¶
func (dp *DiffPreview) GetApproved() []FileChange
GetApproved returns changes that have been approved.
func (*DiffPreview) GetPending ¶
func (dp *DiffPreview) GetPending() []FileChange
GetPending returns changes that are neither approved nor rejected.
func (*DiffPreview) RecordChange ¶
func (dp *DiffPreview) RecordChange(path, oldContent, newContent string)
RecordChange computes a unified diff between old and new content and records it.
func (*DiffPreview) Reject ¶
func (dp *DiffPreview) Reject(path string, comment string)
Reject marks a specific file change as rejected with an optional comment.
func (*DiffPreview) RejectAll ¶
func (dp *DiffPreview) RejectAll(comment string)
RejectAll marks all changes as rejected with an optional comment.
func (*DiffPreview) RenderAll ¶
func (dp *DiffPreview) RenderAll() string
RenderAll renders all changes as a combined unified diff.
func (*DiffPreview) RenderSummary ¶
func (dp *DiffPreview) RenderSummary() string
RenderSummary produces a compact summary of all pending changes.
type DiffSandbox ¶
type DiffSandbox struct {
// contains filtered or unexported fields
}
DiffSandbox holds pending file changes so the user can review diffs before applying.
func NewDiffSandbox ¶
func NewDiffSandbox() *DiffSandbox
NewDiffSandbox creates a new, enabled DiffSandbox.
func (*DiffSandbox) Apply ¶
func (ds *DiffSandbox) Apply(path string) error
Apply writes one pending change to disk and removes it from the sandbox.
func (*DiffSandbox) ApplyAll ¶
func (ds *DiffSandbox) ApplyAll() (int, error)
ApplyAll writes all pending changes to disk and clears the sandbox.
func (*DiffSandbox) DiffAll ¶
func (ds *DiffSandbox) DiffAll() string
DiffAll returns all diffs combined.
func (*DiffSandbox) DiffFor ¶
func (ds *DiffSandbox) DiffFor(path string) string
DiffFor returns the unified diff for a single pending file.
func (*DiffSandbox) Format ¶
func (ds *DiffSandbox) Format() string
Format returns a human-readable summary of all pending changes.
func (*DiffSandbox) Get ¶
func (ds *DiffSandbox) Get(path string) *PendingChange
Get returns the pending change for a specific path, or nil.
func (*DiffSandbox) IsEnabled ¶
func (ds *DiffSandbox) IsEnabled() bool
IsEnabled returns whether the sandbox is active.
func (*DiffSandbox) List ¶
func (ds *DiffSandbox) List() []*PendingChange
List returns all pending changes sorted by path.
func (*DiffSandbox) Reject ¶
func (ds *DiffSandbox) Reject(path string)
Reject discards the pending change for one file.
func (*DiffSandbox) RejectAll ¶
func (ds *DiffSandbox) RejectAll()
RejectAll discards all pending changes.
func (*DiffSandbox) Stage ¶
func (ds *DiffSandbox) Stage(path, action, oldContent, newContent string)
Stage records a pending file change and computes a unified diff.
type DiffSummarizer ¶
type DiffSummarizer struct {
// contains filtered or unexported fields
}
DiffSummarizer parses unified diffs and produces human-readable summaries.
func NewDiffSummarizer ¶
func NewDiffSummarizer() *DiffSummarizer
NewDiffSummarizer creates a new DiffSummarizer instance.
func (*DiffSummarizer) AssessImpact ¶
func (ds *DiffSummarizer) AssessImpact(summary *DiffSummary) string
AssessImpact determines the impact level of the changes.
func (*DiffSummarizer) DetectChangeType ¶
func (ds *DiffSummarizer) DetectChangeType(summary *DiffSummary) string
DetectChangeType classifies the overall change type based on file patterns and content.
func (*DiffSummarizer) FormatSummary ¶
func (ds *DiffSummarizer) FormatSummary(summary *DiffSummary) string
FormatSummary produces a compact terminal-friendly summary display.
func (*DiffSummarizer) GenerateCommitMessage ¶
func (ds *DiffSummarizer) GenerateCommitMessage(summary *DiffSummary) string
GenerateCommitMessage produces a conventional commit message from the summary.
func (*DiffSummarizer) GeneratePRSummary ¶
func (ds *DiffSummarizer) GeneratePRSummary(summary *DiffSummary) string
GeneratePRSummary produces a multi-paragraph PR description from the summary.
func (*DiffSummarizer) Summarize ¶
func (ds *DiffSummarizer) Summarize(diff string) *DiffSummary
Summarize parses a unified diff and returns a complete DiffSummary.
func (*DiffSummarizer) SummarizeFile ¶
func (ds *DiffSummarizer) SummarizeFile(path string, hunks []string) *FileSummary
SummarizeFile analyzes hunks for a single file and produces a FileSummary.
type DiffSummary ¶
type DiffSummary struct {
Files []FileSummary
OverallSummary string
ChangeType string // "feature", "bugfix", "refactor", "test", "docs", "config"
Impact string // "low", "medium", "high"
AffectedAreas []string
}
DiffSummary holds the full summarized output of a diff analysis.
type Edit ¶
Edit represents a single edit operation in an edit script.
func EditScript ¶
EditScript computes a minimal edit script to transform 'from' into 'to'.
type FileChange ¶
type FileChange struct {
Path string
Type string // "modified", "created", "deleted", "renamed"
OldContent string
NewContent string
Hunks []DiffHunk
Stats ChangeStats
Approved bool
Rejected bool
Comment string
}
FileChange represents a single file modification in the workspace.
type FileSummary ¶
type FileSummary struct {
Path string
Action string // "added", "modified", "deleted"
Summary string
Additions int
Deletions int
KeyChanges []string
}
FileSummary describes summarized changes for a single file in the diff.
type PendingChange ¶
type PendingChange struct {
Path string
Action string // "create", "edit", "overwrite"
OldContent string
NewContent string
Diff string
CreatedAt time.Time
}
PendingChange represents a staged file modification that has not yet been applied to disk.
type Preview ¶
type Preview = DiffPreview
type SelectedTests ¶
type SelectedTests struct {
Tests []string
Packages []string
Reason map[string]string
Coverage float64
}
SelectedTests holds the result of a diff-aware test selection.
type StagedChange ¶
type StagedChange struct {
File string
Original string
Modified string
Hunks []StagedHunk
Status string // "staged", "applied", "rejected"
StagedAt time.Time
Description string
}
StagedChange represents a file modification held in the staging area.
type StagedHunk ¶
type StagedHunk struct {
StartLine int
EndLine int
OldLines []string
NewLines []string
Approved bool
}
StagedHunk represents a contiguous block of changes within a staged file.
type StagingArea ¶
type StagingArea struct {
Staged map[string]*StagedChange
// contains filtered or unexported fields
}
StagingArea provides a local staging area for agent edits, allowing review before changes are applied to disk — like a git staging area for the agent's modifications.
func NewStagingArea ¶
func NewStagingArea() *StagingArea
NewStagingArea creates a new empty StagingArea.
func (*StagingArea) ApplyAll ¶
func (sa *StagingArea) ApplyAll() ([]string, error)
ApplyAll writes all staged changes to disk and returns the list of files modified.
func (*StagingArea) ApplyFile ¶
func (sa *StagingArea) ApplyFile(file string) error
ApplyFile applies a single file's staged changes to disk.
func (*StagingArea) ApproveHunk ¶
func (sa *StagingArea) ApproveHunk(file string, hunkIndex int)
ApproveHunk marks a specific hunk as approved within a staged file.
func (*StagingArea) FormatStaging ¶
func (sa *StagingArea) FormatStaging() string
FormatStaging returns a human-readable summary of the staging area.
func (*StagingArea) GetDiff ¶
func (sa *StagingArea) GetDiff(file string) string
GetDiff returns a unified diff for a staged file.
func (*StagingArea) GetStaged ¶
func (sa *StagingArea) GetStaged() map[string]*StagedChange
GetStaged returns a copy of all staged changes.
func (*StagingArea) HasPending ¶
func (sa *StagingArea) HasPending() bool
HasPending returns true if there are any changes in "staged" status.
func (*StagingArea) Reject ¶
func (sa *StagingArea) Reject(file string)
Reject removes a file from staging without applying its changes.
func (*StagingArea) RejectHunk ¶
func (sa *StagingArea) RejectHunk(file string, hunkIndex int)
RejectHunk rejects a specific hunk within a staged file (partial staging).
func (*StagingArea) Stage ¶
func (sa *StagingArea) Stage(file, original, modified, description string)
Stage computes a diff between original and modified content and adds it to the staging area.
type Summarizer ¶
type Summarizer = DiffSummarizer
type Summary ¶
type Summary = DiffSummary
type TestSelector ¶
type TestSelector struct {
ProjectDir string
Language string
DepGraph map[string][]string
// contains filtered or unexported fields
}
TestSelector provides diff-aware test selection, identifying which tests need to run based on changed files and dependency relationships.
func NewTestSelector ¶
func NewTestSelector(projectDir string) *TestSelector
NewTestSelector creates a TestSelector for the given project directory. It auto-detects the project language and builds a dependency graph.
func (*TestSelector) FindRelatedTests ¶
func (ts *TestSelector) FindRelatedTests(file string) []string
FindRelatedTests finds test files related to the given source file.
func (*TestSelector) SelectFromDiff ¶
func (ts *TestSelector) SelectFromDiff(diff string) (*SelectedTests, error)
SelectFromDiff parses a unified diff string, extracts changed file paths, and selects the related tests.
func (*TestSelector) SelectFromFiles ¶
func (ts *TestSelector) SelectFromFiles(changedFiles []string) (*SelectedTests, error)
SelectFromFiles determines which tests to run given a list of changed files. Strategy depends on the detected language.