conflicts

package
v2.10.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package conflicts predicts semantic conflicts between concurrent agent sessions working one repository. File-level overlap (internal/awareness) misses about half of real conflicts: two changes can touch different files and still break each other, because one changes what a function does and the other adds a new caller of it. This package reads each side's live diff, records which symbols it defines or changes and which identifiers its added lines use, and compares the two.

Everything here is pure: no git, no store, no I/O. The Scanner in scan.go is the part that gathers diffs; this file and predict.go decide what they mean. Predictions are advisory. Nothing here blocks or reorders an agent.

Index

Constants

View Source
const (
	LevelNone     = "none"
	LevelTextual  = "textual"  // both sides touch one file, no symbol link
	LevelSemantic = "semantic" // one side changes a symbol the other uses or changes
)

Risk levels, ordered from least to most serious.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector func(ctx context.Context, projectID int64) ([]Subject, error)

Collector lists the live subjects for one project. It is a function so the scanner can be tested without a database or git.

type Footprint

type Footprint struct {
	// Files are the paths the diff touches, in diff order.
	Files []string
	// Defined maps file -> symbols the diff changes or adds in that file.
	// A method is qualified as "Receiver.Name" so two types' Close methods
	// never look like one symbol; everything else is the bare name.
	Defined map[string][]string
	// Reshaped maps file -> existing symbols whose definition line the diff
	// removes or rewrites: a signature change, a rename or a deletion. Unlike
	// a body edit or a brand-new symbol, this can break code someone else
	// writes against the old definition, so it is what a semantic link needs.
	Reshaped map[string][]string
	// Referenced is the set of identifiers used on added lines, minus
	// language keywords. It is what the other side's definitions are matched
	// against.
	Referenced map[string]bool
}

Footprint is what one side of a potential conflict changes, reduced from a unified diff.

func ParseFootprint

func ParseFootprint(unifiedDiff string) Footprint

ParseFootprint reads a unified diff (git diff output, possibly with several files) into a Footprint. It tolerates empty input and binary entries.

Symbols come from two places. A hunk header's trailing context (git prints the enclosing function there) names the function the change sits in, which is how a change to a function body counts as changing that function. Added and removed lines that themselves define a symbol are counted too.

type Pair

type Pair struct {
	A       Ref      `json:"a"`
	B       Ref      `json:"b"`
	Level   string   `json:"level"`
	Reasons []string `json:"reasons"`
}

Pair is one predicted interaction between two subjects. A is always the one that sorts first by kind and id, so a pair appears once.

func ForRef

func ForRef(pairs []Pair, r Ref) []Pair

ForRef filters a pair list to those involving one subject.

type Ref

type Ref struct {
	Kind  string `json:"kind"` // "session" | "attempt"
	ID    int64  `json:"id"`
	Title string `json:"title"`
}

Ref names one piece of live work: a session or a running task attempt.

func (Ref) Label

func (r Ref) Label() string

Label is how a Ref reads inside a reason sentence.

type Risk

type Risk struct {
	Level   string
	Reasons []string
}

Risk is the prediction for one pair of footprints.

func Predict

func Predict(a, b Footprint) Risk

Predict compares two footprints with the default labels "A" and "B".

func PredictNamed

func PredictNamed(aName, bName string, a, b Footprint) Risk

PredictNamed is Predict with caller-supplied labels, which end up in the reason text. The scanner passes session names so a reason reads "Session #12 changes Parse", not "A changes Parse".

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner predicts pairwise conflicts for a project. It caches footprints by fingerprint and pair predictions by both footprints, so a call on an idle project costs one fingerprint per subject and no parsing.

func NewScanner

func NewScanner(collect Collector) *Scanner

NewScanner builds a Scanner over a collector.

func (*Scanner) Last

func (s *Scanner) Last(projectID int64) []Pair

Last returns the most recent scan result for a project without touching git. The hook path uses it, because a hook response must never wait on a diff.

func (*Scanner) Scan

func (s *Scanner) Scan(ctx context.Context, projectID int64) ([]Pair, error)

Scan collects the project's live subjects and returns every pair whose prediction is not "none", ordered by level (semantic first) and then by reference. Subjects whose fingerprint or diff cannot be read are left out rather than failing the whole scan: one unreachable worktree should not hide the others.

func (*Scanner) Warm

func (s *Scanner) Warm(projectID int64, maxAge time.Duration)

Warm starts a background Scan for a project whose last result is older than maxAge, and returns at once. A scan already in flight is not duplicated. It exists for the hook path, which must never wait on a diff: the hook reads Last now and gets the fresher result on a later prompt.

type Subject

type Subject struct {
	Ref
	Fingerprint func(ctx context.Context) (string, error)
	Diff        func(ctx context.Context) (string, error)
}

Subject is one live piece of work the scanner can read. Fingerprint is cheap and changes whenever the worktree does; Diff is the expensive capture and is only called when the fingerprint is new.

Jump to

Keyboard shortcuts

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