model

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package model holds the shared data types of the seamark graph.

The graph captures three layers (RFC-001 §5.1):

  • structure: Symbol and Edge rows, parsed from source with tree-sitter
  • history: CoChange pairs and Decision rows, mined from git
  • effects: Effect tags propagated along call edges (later milestone)

Every value here traces to a parse, a commit, or a policy file — never to generated prose.

Index

Constants

View Source
const (
	// OriginSamePackage: bare-identifier call resolved within the package.
	OriginSamePackage = "same-package"
	// OriginSameClass: self/cls/this method call resolved to a method of
	// the caller's own class.
	OriginSameClass = "same-class"
	// OriginQualified: qualified call resolved through the file's imports.
	OriginQualified = "qualified"
	// OriginUniqueName: method call resolved because exactly one symbol in
	// the repo carries that name. Lowest confidence.
	OriginUniqueName = "unique-name"
	// OriginParse: edge read directly off the syntax tree (imports).
	OriginParse = "parse"
)

Edge origins record how an edge was derived, so downstream consumers can filter by confidence.

View Source
const (
	SourceReview          = "review"
	SourceRevert          = "revert"
	SourceFixConventional = "fix:conventional"
	SourceFixIssueLink    = "fix:issue-link"
	SourceFixSubject      = "fix:subject"
	// SourceFixBranch marks a fix whose only declaration is its branch
	// name: a merge from fix/… whose commits carried no fix-shaped
	// message of their own. The finding is the merge's whole diff.
	SourceFixBranch = "fix:branch"
)

Finding sources.

View Source
const (
	ProposalProposed   = "proposed"
	ProposalApplied    = "applied"
	ProposalDismissed  = "dismissed"
	ProposalSuperseded = "superseded"
)

Proposal lifecycle states. Dismissed and superseded are both "not in the pin file", but they mean opposite things about the pattern: dismissed rejects the guidance, superseded keeps it and drops a redundant wording of it. Conflating them would let pruning a duplicate silently suppress a theme the user still wants.

Variables

This section is empty.

Functions

func CountEvents added in v0.2.0

func CountEvents(findings []Finding) int

CountEvents collapses findings into distinct events: findings sharing a pull request are one event (the review comment and the fix commit that answered it), while findings without a pr number are independent. The distiller's recurrence bar, region inference, and confidence all count evidence this way — one definition, or two surfaces disagree about what recurred.

func FixMinedSources

func FixMinedSources() []string

FixMinedSources returns the sources replaced together with fix mining.

func IsDocPath added in v0.2.0

func IsDocPath(p string) bool

IsDocPath reports whether a file is documentation — never the semantic home of a code change. Shared by fix mining (a doc file must not be elected a fix's primary file) and region inference (doc paths don't vote; a README citation must not drag a region to repo-wide).

func IsTestPath

func IsTestPath(p string) bool

IsTestPath reports whether a file is test code, by each language's naming convention. Shared by resolution (test doubles must not win unique-name matches) and reporting (orientation shows the production surface, not test helpers).

Types

type CoChange

type CoChange struct {
	FileA    string // canonical order: FileA < FileB
	FileB    string
	Together int // commits touching both
	Total    int // commits in the mined window
	Lift     float64
}

CoChange records that two files changed together in history. Lift = P(a,b) / (P(a)·P(b)) over the mined commit window: >1 means the pair co-occurs more than chance, and the further above 1 the stronger the empirical coupling.

type Decision

type Decision struct {
	ID     int64
	Kind   DecisionKind
	Ref    string // commit SHA, PR number, ADR path
	TS     int64  // unix seconds
	Author string
	Title  string
	Body   string
	Files  []string // repo-relative files this decision touched
}

Decision is one unit of "why": a commit, PR, revert, or ADR.

type DecisionKind

type DecisionKind string

DecisionKind classifies where a Decision row came from.

const (
	DecisionCommit DecisionKind = "commit"
	DecisionRevert DecisionKind = "revert"
	DecisionPR     DecisionKind = "pr"
	DecisionADR    DecisionKind = "adr"
)

The decision sources the history miner records.

type Edge

type Edge struct {
	Src    int64
	Dst    int64
	Kind   EdgeKind
	Origin string
}

Edge is one directed structural edge.

type EdgeKind

type EdgeKind string

EdgeKind classifies a structural edge between two symbols.

const (
	EdgeCalls      EdgeKind = "CALLS"
	EdgeImports    EdgeKind = "IMPORTS"
	EdgeImplements EdgeKind = "IMPLEMENTS"
	EdgeDefines    EdgeKind = "DEFINES"
)

The edge kinds of the structure graph (RFC-001 §5.1).

type Finding

type Finding struct {
	ID        int64  // stable across mines: GitHub comment id, or sha-derived for fixes
	LessonKey string // ClusterKey of the lesson this comment fed; "" for fix findings
	// Path is the finding's semantic home: the commented file for a
	// review finding, the most-changed non-test code file for a fix.
	Path string
	// Paths is a fix commit's full code footprint (primary first, by
	// churn, capped) — what region inference votes with, so a fix whose
	// test out-churned it still points at the code it corrected. Nil
	// for review findings: their single Path IS the location.
	Paths     []string
	PR        int    // pull-request number, 0 when unknown
	Reviewer  string // coderabbit | copilot | bot | human
	Body      string // boilerplate-stripped text, capped
	URL       string // provenance link (comment or commit), "" when none
	CreatedAt int64  // unix seconds
	// Source is the provider and its derivation: review, revert, or
	// fix:conventional / fix:issue-link / fix:subject — every finding
	// declares how it was mined, like every edge declares how it was
	// resolved.
	Source string
}

Finding is one raw review comment behind a lesson — the full material the 80-char fingerprint was distilled from. Lessons answer "what keeps happening"; findings keep the evidence, so deeper passes (distillation, provenance display) work from what reviewers actually wrote rather than from lossy summaries.

type Lesson

type Lesson struct {
	ID          int64
	ClusterKey  string // stable identity of (region, symptom); the upsert key
	Region      string // file or directory the feedback lands in
	Reviewer    string // coderabbit | copilot | bot | human | mixed
	Symptom     string // a rule code (RUF001) or a normalized message
	Fix         string // extracted suggestion, when the comment carried one
	Occurrences int    // how many comments fall in this cluster
	LastTS      int64  // most recent occurrence, unix seconds
	ExampleURL  string // a representative comment, for provenance
	// Annotation is surface-time display text (a confidence tag like
	// "weak evidence: 1 event"), never part of the lesson's identity:
	// the firing log records Symptom, and an annotation that changes
	// with age must not split one lesson into many statistical rows.
	Annotation string
}

Lesson is a cluster of recurring review feedback (M6): the same kind of comment landing on the same region across pull requests. It is the anti-repeat signal — "reviewers keep flagging X here" — surfaced to an agent before it makes the mistake a fourth time.

type Proposal

type Proposal struct {
	ID        int64
	Signature string // the evidence group that produced it
	Rule      string // short kebab-case pin label
	// Region is the first (deepest-coverage) region of Regions, kept as
	// a single value for display and for readers that predate region
	// sets ("" = repo-wide).
	Region string
	// Regions is the evidence-coverage region set (at most 3 directories
	// covering ≥80% of the cited events; see distill.coverageRegions).
	// Empty means "derive from Region" — pre-set rows and repo-wide
	// proposals both land there.
	Regions   []string
	Note      string  // the guidance, pin-ready
	Members   []int64 // finding ids the agent cited — verified to exist in the group
	Agent     string  // provenance: adapter name + prompt version
	Status    string  // proposed | applied | dismissed
	CreatedAt int64
}

Proposal is one distilled pattern awaiting a human decision: a pin-shaped lesson synthesized by the configured agent from a group of findings (the members it cited). Proposals follow the plan/apply contract — the distiller may only ever PROPOSE; a pin reaches .seamark/lessons.yaml exclusively through an explicit apply.

func (Proposal) RegionSet added in v0.2.0

func (p Proposal) RegionSet() []string

RegionSet returns the effective region set: Regions when present, else the single Region, else nil — which means repo-wide. A "*" (or empty) entry anywhere means the whole set is repo-wide: matching code compares literal paths, and an unnormalized wildcard would match nothing instead of everything.

type Span

type Span struct {
	StartLine uint32
	StartCol  uint32
	EndLine   uint32
	EndCol    uint32
}

Span is a half-open source range in 1-based lines and 0-based columns.

type Symbol

type Symbol struct {
	ID      int64
	FQN     string // e.g. "internal/store.Store.UpsertSymbols"
	Name    string // last FQN segment, e.g. "UpsertSymbols"
	Kind    SymbolKind
	File    string // repo-relative path; empty for external packages
	Span    Span
	Sig     string // declaration signature text, single line
	DocHash string // sha256 hex of the doc comment, "" if none
}

Symbol is one node of the structure graph.

type SymbolKind

type SymbolKind string

SymbolKind classifies a Symbol row.

const (
	KindFunction SymbolKind = "function"
	KindMethod   SymbolKind = "method"
	KindType     SymbolKind = "type"
	KindConst    SymbolKind = "const"
	KindVar      SymbolKind = "var"
	// KindPackage represents a package/module grouping node. Internal
	// packages use their repo-relative directory as FQN; external ones use
	// the import path as written.
	KindPackage SymbolKind = "package"
)

The symbol kinds extractors produce.

Jump to

Keyboard shortcuts

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