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 ¶
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 ¶
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 ¶
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.
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.
type Risk ¶
Risk is the prediction for one pair of footprints.
func PredictNamed ¶
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 ¶
NewScanner builds a Scanner over a collector.
func (*Scanner) Last ¶
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 ¶
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 ¶
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.