Documentation
¶
Overview ¶
Package model defines GraphLume's language-independent domain entities.
Two invariants govern everything here:
Every fact carries provenance. A relationship discovered by a compiler is not the same kind of fact as one guessed from a name, and the difference must survive all the way to the agent that consumes it. See Confidence.
Nothing in this package parses, queries, or performs I/O. It is the shared vocabulary between the acquisition, registry, graph and context layers.
Index ¶
- Constants
- func DefaultFQN(path, name string) string
- func FormatParseError(reason ParseReason, detail string) string
- func ParseAbandoned(status, parseError string) bool
- func ParseOutcomeLabel(status, parseError string) string
- func SQLParseAbandoned(prefix string) string
- func TextIndexed(status, parseError string) bool
- type Arity
- type Confidence
- type Edge
- type EdgeKind
- type EntityKind
- type Evidence
- type File
- type IndexRun
- type IndexState
- type IndexStatus
- type ParseReason
- type Position
- type Range
- type SourceType
- type Symbol
Constants ¶
const ( // ReceiverBare is `f()`: the source wrote no receiver. ReceiverBare = "bare" // ReceiverName is `x.f()`: one identifier, as written. ReceiverName = "name" // ReceiverPath is `a.b.f()`: identifiers joined by the member operator. ReceiverPath = "path" // ReceiverScope is `a::f()` or `a::b::f()`: qualified through the // language's scope operator, which names a module or a type, never a value. ReceiverScope = "scope" // ReceiverSelf is `self.f()` or `this.f()`: the enclosing instance or type. ReceiverSelf = "self" // ReceiverSuper is `super.f()`, `super().f()` or `base.f()`. ReceiverSuper = "super" // ReceiverType is `x.f()` where the source states x's type; the reference's // receiver holds the type, not the variable. ReceiverType = "type" // ReceiverValue is `x.f()` where x is a variable or parameter the enclosing // code declares without stating a type. It is a value, so it is never an // import, a module or a type, whatever its name happens to match. ReceiverValue = "value" // ReceiverExpr is a call on an expression with no name: `g().f()`, // `a[i].f()`. The reference's receiver holds OpaqueReceiver. ReceiverExpr = "expr" // ReceiverImplementer marks a supertype reference whose declaring type is // not a symbol on its line: Rust's `impl Trait for Type`. The reference's // receiver holds the type's name, and the reference is no call. ReceiverImplementer = "implementer" )
The shape of a call's receiver: what stands before the dot, if anything.
internal/parse writes one of these beside every call reference and internal/resolve/infer reads it; the vocabulary is closed and is the same one migration 0001 documents for symbol_references.receiver_kind. The empty string means the shape was not recorded.
const ( SymbolFlagPrivate = 1 SymbolFlagTrait = 2 // SymbolFlagConditional: the definition exists in some builds and not in // others: Rust under a `#[cfg(...)]` attribute (on itself or on something // that encloses it), C and C++ inside a preprocessor conditional. One bit // for the one concept; see Symbol.Conditional. SymbolFlagConditional = 4 // SymbolFlagRefImpl: a Rust method of an `impl Trait for &T` (or `&mut T`), // whose receiver is a reference, as opposed to the same trait implemented // for T. See Symbol.RefImpl. SymbolFlagRefImpl = 8 // SymbolFlagSingleton: a Ruby method defined on the class or module itself. SymbolFlagSingleton = 16 )
The bits of symbols.flags (migration 0001).
const ( ParseStatusOK = "ok" ParseStatusPartial = "partial" ParseStatusFailed = "failed" ParseStatusSkipped = "skipped" )
The four values files.parse_status can hold.
They describe what the PARSER did with the file, not what was extracted from it. That distinction is the point of this file: for a long time "ok" meant "at least one symbol or reference was recorded" and "partial" meant "none were", so a file with 150 syntax errors was ok and a valid file holding only constants was partial.
ok the parser read the whole file and reported no syntax error
partial a syntax tree was built, but it is not a clean reading of the whole
file: the parser reported syntax errors, or it stopped before the
end because the file exceeded the parse budget
failed no usable syntax tree
skipped no syntax tree was attempted
Every status other than ok carries a ParseReason at the start of File.ParseError, so "why" is a stable token and not a sentence to be matched.
The column's CHECK constraint (migration 0001) admits exactly these four values, which is why the finer distinctions live in the reason rather than in more statuses: widening a CHECK in SQLite means rebuilding a table that nine others reference.
const OpaqueReceiver = "?"
OpaqueReceiver is the receiver text recorded with ReceiverExpr. Not a valid identifier in any language, so it cannot collide with a real receiver.
const (
// ReferenceFlagBlock marks a call that passes a block. Read for Ruby.
ReferenceFlagBlock = 1
)
The bits of symbol_references.flags (migration 0001).
Variables ¶
This section is empty.
Functions ¶
func DefaultFQN ¶
DefaultFQN is the fully-qualified name given to a symbol whose extractor did not supply one.
It exists so the rule has ONE definition. It is applied in two places that must agree — the indexing sink, which persists symbols, and the analyzer, which attributes SQL statements to the definition that runs them by FQN — and when they disagreed the analyzer attributed nothing: it looked up names the sink had not assigned yet, found none, and produced seven bound table accesses with zero edges between them.
Path-qualified rather than bare, because a bare name is not unique in a repository and the registry digest depends on this being stable across runs.
func FormatParseError ¶
func FormatParseError(reason ParseReason, detail string) string
FormatParseError builds the text stored in files.parse_error: the reason token, then the detail for a person.
func ParseAbandoned ¶
ParseAbandoned is File.ParseIncomplete for a bare status pair.
func ParseOutcomeLabel ¶
ParseOutcomeLabel is the short, human name of a (status, reason) pair, used wherever a file's parse result is shown to a person.
func SQLParseAbandoned ¶
SQLParseAbandoned is the WHERE-clause form of ParseAbandoned, for the counts that must be taken in SQL. column is the files table alias prefix, e.g. "" or "f.".
Kept beside the Go predicate so the two cannot drift: a run is degraded when this matches at least one row, and a reader explaining the run must name exactly those rows.
func TextIndexed ¶
TextIndexed reports whether a file with this status has its text in the full-text index.
Every file a syntax tree was attempted for does, and so does a file whose grammar yields no definitions: the answer to "why is this function name not found" must not be "its language has no query".
Types ¶
type Arity ¶
type Arity int
Arity is a parameter or argument count that MAY BE UNKNOWN.
A plain int cannot carry this fact. Its zero value is 0, which is a perfectly ordinary arity — `Close()` takes none — so a producer that never set the field would be indistinguishable from one reporting a niladic call. That distinction is the whole safety property here: a symbol imported from SCIP, a Symbol built by a test, or a language whose parser has no arity query must read as "no information", never as "takes nothing".
So the encoding is offset by one: the zero value is ArityUnknown, and a known count of n is stored as n+1. Nothing outside this type needs to know that — build one with KnownArity and read it with Known and Count.
const ArityUnknown Arity = 0
ArityUnknown is the zero value, meaning no count was determined.
func KnownArity ¶
KnownArity returns the Arity for a determined count. A negative count is nonsense and yields ArityUnknown rather than a value that would compare equal to some real arity.
type Confidence ¶
type Confidence string
Confidence records how strongly a fact is believed, and why.
This is not decoration. GraphLume's core promise is that an AI agent can tell a proven relationship from a plausible one; an impact analysis that presents guesses as facts is worse than no impact analysis at all.
const ( // ConfidenceExact means a compiler proved it. Sourced from a SCIP index // produced by a real typechecker. Safe to act on without verification. ConfidenceExact Confidence = "exact" // ConfidenceHigh means resolved through an explicit import plus an // unambiguous receiver type. Wrong only in unusual cases (shadowing, // reflection, runtime dispatch). ConfidenceHigh Confidence = "high" // ConfidenceMedium means the target was resolved by type inference where // more than one candidate existed and one was clearly preferred. ConfidenceMedium Confidence = "medium" // ConfidenceLow means resolved by weak signal — matching name in an // imported package, no type confirmation. Report it, but never let it // drive a risk score on its own. ConfidenceLow Confidence = "low" )
func (Confidence) AtLeast ¶
func (c Confidence) AtLeast(min Confidence) bool
AtLeast reports whether c is at least as strong as min.
func (Confidence) Rank ¶
func (c Confidence) Rank() int
Rank orders confidence from weakest to strongest so callers can threshold (e.g. "only expand the graph through edges >= high").
func (Confidence) Valid ¶
func (c Confidence) Valid() bool
Valid reports whether c is a recognised confidence level.
type Edge ¶
type Edge struct {
ID int64 `json:"id"`
SrcID int64 `json:"src_id"`
DstID int64 `json:"dst_id"`
Kind EdgeKind `json:"kind"`
Confidence Confidence `json:"confidence"`
Evidence Evidence `json:"evidence"`
// IndexRunID ties the edge to the run that produced it, which is what
// makes the two-phase atomic swap and stale-edge removal possible.
IndexRunID int64 `json:"index_run_id"`
}
Edge is a typed, provenance-carrying relationship between two entities.
The Confidence and Evidence fields are the reason this type exists rather than a bare (src, dst, kind) triple.
type EdgeKind ¶
type EdgeKind string
EdgeKind enumerates relationship types in the knowledge graph. Spec §8.
const ( EdgeContains EdgeKind = "CONTAINS" EdgeImports EdgeKind = "IMPORTS" EdgeReferences EdgeKind = "REFERENCES" EdgeCalls EdgeKind = "CALLS" EdgeDocuments EdgeKind = "DOCUMENTS" // EdgeInstantiates is a constructor call recorded against the TYPE it // constructs: `Account(...)`, `Type::new()`, `new X()`. Kept apart from // EdgeCalls so that "what calls this function" is answered from edges that // point at callables, and "what creates one of these" from edges that // point at types. EdgeInstantiates EdgeKind = "INSTANTIATES" EdgeExtends EdgeKind = "EXTENDS" EdgeImplements EdgeKind = "IMPLEMENTS" EdgeDependsOn EdgeKind = "DEPENDS_ON" EdgeExposes EdgeKind = "EXPOSES" EdgeReads EdgeKind = "READS" EdgeWrites EdgeKind = "WRITES" EdgePublishes EdgeKind = "PUBLISHES" EdgeConsumes EdgeKind = "CONSUMES" EdgeTestedBy EdgeKind = "TESTED_BY" EdgeConfigures EdgeKind = "CONFIGURED_BY" EdgeTracesTo EdgeKind = "TRACES_TO" EdgeViolates EdgeKind = "VIOLATES" EdgeOwnedBy EdgeKind = "OWNED_BY" EdgeChangedBy EdgeKind = "CHANGED_BY" )
type EntityKind ¶
type EntityKind string
EntityKind enumerates the node types in the knowledge graph. Spec §8.
const ( KindRepository EntityKind = "repository" KindModule EntityKind = "module" KindDirectory EntityKind = "directory" KindFile EntityKind = "file" KindPackage EntityKind = "package" KindClass EntityKind = "class" KindInterface EntityKind = "interface" KindFunction EntityKind = "function" KindMethod EntityKind = "method" KindField EntityKind = "field" KindConstant EntityKind = "constant" KindVariable EntityKind = "variable" KindTypeAlias EntityKind = "type_alias" KindEndpoint EntityKind = "endpoint" KindTable EntityKind = "table" KindColumn EntityKind = "column" KindEvent EntityKind = "event" KindTest EntityKind = "test" KindConfiguration EntityKind = "configuration" KindDependency EntityKind = "dependency" KindCommit EntityKind = "commit" )
type Evidence ¶
type Evidence struct {
FilePath string `json:"file_path"`
Range Range `json:"range"`
Source SourceType `json:"source"`
// Detail optionally names the concrete mechanism, e.g. "scip:
// scip-java 0.10.3" or "import + receiver type".
Detail string `json:"detail,omitempty"`
}
Evidence points at the exact source location that justifies a fact. Without it a relationship is an assertion; with it the agent can verify.
type File ¶
type File struct {
ID int64 `json:"id"`
Path string `json:"path"` // repo-relative, always forward slashes
Language string `json:"language"`
ContentHash string `json:"content_hash"` // sha256 of bytes
SizeBytes int64 `json:"size_bytes"`
ModTimeUnix int64 `json:"mod_time_unix"`
// ParseStatus is ok | partial | failed | skipped and describes what the
// parser did, not what was extracted. ParseError starts with a
// ParseReason token whenever the status is not ok. See parsestatus.go.
ParseStatus string `json:"parse_status"`
ParseError string `json:"parse_error,omitempty"`
// DetectedBy records how Language was decided: override | filename |
// extension | shebang | content | neighbours | extension_ambiguous, or
// empty when nothing was detected. "extension_ambiguous" means Language is
// the default for an extension several languages share and no content rule
// confirmed it, so it is a guess rather than a finding.
DetectedBy string `json:"detected_by,omitempty"`
}
File is an indexed source file.
func (File) ParseIncomplete ¶
ParseIncomplete reports whether indexing work on this file was abandoned: the parse failed outright, or it was stopped before the end of the file.
This, and only this, is what makes an index run degraded. A file the parser read to the end is not abandoned work, whatever it did or did not contain, and neither is a file that was never going to be parsed.
func (File) ParseReason ¶
func (f File) ParseReason() ParseReason
ParseReason is the reason this file is not ok. See ParseReasonOf.
type IndexRun ¶
type IndexRun struct {
ID int64 `json:"id"`
Status IndexStatus `json:"status"`
StartedUnix int64 `json:"started_unix"`
FinishedUnix int64 `json:"finished_unix,omitempty"`
GitRevision string `json:"git_revision,omitempty"`
FilesIndexed int64 `json:"files_indexed"`
SymbolsFound int64 `json:"symbols_found"`
EdgesFound int64 `json:"edges_found"`
ParseFailures int64 `json:"parse_failures"`
AccuracyMode string `json:"accuracy_mode"` // fast | auto | exact
RegistryDigest string `json:"registry_digest,omitempty"`
Error string `json:"error,omitempty"`
// ProducerVersion is the build that wrote this run.
//
// An index is data PLUS the resolution rules that produced it, and those
// rules change between builds. Empty means the run predates the stamp, which
// is a different claim from a version that simply differs: the first is
// unknown provenance, the second is known-stale.
ProducerVersion string `json:"producer_version,omitempty"`
// FilesDiscovered is what the walker handed the pipeline, which is the
// denominator FilesIndexed alone cannot supply.
FilesDiscovered int64 `json:"files_discovered"`
// IndexState is the completeness verdict. Empty only on a run read from a
// database written before this was recorded.
IndexState IndexState `json:"index_state"`
// FilesUnaccounted is how many discovered files reached none of the three
// terminal outcomes. Zero on a healthy run; a negative value means a file
// was counted twice, which is a different bug with the same consequence.
FilesUnaccounted int64 `json:"files_unaccounted"`
// RecoveredPanics is how many parser extractor panics were safely recovered during indexing.
RecoveredPanics int64 `json:"recovered_panics,omitempty"`
}
IndexRun records one indexing pass. A run is only visible to readers once it is committed, which is what prevents a crash from exposing a half-built index.
func (IndexRun) Complete ¶
Complete reports whether the run covered everything it discovered.
A run recorded before completeness was measured has an empty IndexState and reads as complete: it made no claim either way, and relabelling every existing index as suspect on upgrade would be a louder lie than the silence.
type IndexState ¶
type IndexState string
IndexState records how much of what a run DISCOVERED the run actually covered.
It is orthogonal to IndexStatus, which is the run's lifecycle. A run can be ready and partial, or degraded and complete, and that pair is precisely why this is a second field rather than two more values of the first: an index that some files failed to parse in is a different fact from an index that silently lost files, and a reader must be able to tell them apart.
const ( // IndexStateComplete means every discovered file reached one of the three // terminal outcomes: indexed, skipped, or recorded as failed. IndexStateComplete IndexState = "complete" // IndexStatePartial means the run did not cover everything it discovered. // Still published — a partial index beats none — but never presented as a // full picture of the repository. IndexStatePartial IndexState = "partial" )
type IndexStatus ¶
type IndexStatus string
IndexStatus is the lifecycle state of an index. Spec §37.
const ( StatusIndexing IndexStatus = "indexing" StatusReady IndexStatus = "ready" StatusDegraded IndexStatus = "degraded" // usable, but some files failed to parse StatusFailed IndexStatus = "failed" )
type ParseReason ¶
type ParseReason string
ParseReason is the stable token that says why a file is not ParseStatusOK.
It is stored as the leading word of files.parse_error, followed by ": " and free text for a person, e.g.
syntax_errors: 12 error nodes and 1 missing token, first at line 5962
The token is the contract; the text after it may be reworded.
const ( // ParseReasonNone is the reason of a file that parsed cleanly. ParseReasonNone ParseReason = "" // ParseReasonSyntaxErrors (status partial): the parser reached the end of // the file and reported error nodes or missing tokens. Definitions inside // the regions it could not read may be absent. ParseReasonSyntaxErrors ParseReason = "syntax_errors" // ParseReasonBudgetExceeded (status partial): the parse was stopped before // the end of the file. What was read is indexed; the rest is missing. ParseReasonBudgetExceeded ParseReason = "budget_exceeded" // ParseReasonStoppedEarly (status partial): the parser itself gave up // before the end of the file, for a reason that is not one of the budgets // (it accepted a prefix, or met an internal inconsistency). The effect on // the index is the same as a budget stop: the rest of the file is missing. ParseReasonStoppedEarly ParseReason = "stopped_early" // ParseReasonTextOnly (status skipped): the file's grammar has no // definition query, so no symbols can be extracted. Its text IS indexed // for full-text search. ParseReasonTextOnly ParseReason = "text_only" // load or rejected its query. The file's text is indexed for search. ParseReasonGrammarUnavailable ParseReason = "grammar_unavailable" // ParseReasonNoGrammar (status skipped): no grammar claims the file type. // The pipeline stores this one as a sentence beginning "no grammar", not // as the token; ParseReasonOf reads both. ParseReasonNoGrammar ParseReason = "no_grammar" // ParseReasonTooLarge (status skipped): the file is over the size limit. ParseReasonTooLarge ParseReason = "too_large" // ParseReasonEmpty (status skipped): the file has no bytes. ParseReasonEmpty ParseReason = "empty" // Discovery's reasons (status skipped). The spellings are the ones // internal/acquire/fs has always written. ParseReasonBinary ParseReason = "binary" ParseReasonSymlink ParseReason = "symlink" ParseReasonSymlinkEscape ParseReason = "symlink_escapes_root" ParseReasonIrregular ParseReason = "irregular" ParseReasonUnreadable ParseReason = "unreadable" // ParseReasonLegacy marks a row an older build wrote under the old meaning // of partial: "parsed, but no symbol or reference was recorded". It says // nothing about syntax errors or budgets. See [File.ParseReason]. ParseReasonLegacy ParseReason = "legacy_no_definitions" // ParseReasonUnspecified is a non-ok row whose text names no known reason: // every failed file, and anything written by a build this one cannot read. ParseReasonUnspecified ParseReason = "unspecified" )
func ParseReasonOf ¶
func ParseReasonOf(status, parseError string) ParseReason
ParseReasonOf reads the reason out of a stored (parse_status, parse_error) pair.
OLD ROWS. An index written before the statuses were redefined is read as follows, without a migration:
- partial with no error text can only be an old row, because every partial row written since carries a reason. It reads as ParseReasonLegacy: the file parsed and nothing was extracted, which is not a parse problem.
- ok cannot be told apart from a new ok row. An old ok file may contain syntax errors that were never recorded. Re-indexing rewrites every row, and a new build re-parses every file on its first index (see pipeline.Diff), so this ambiguity lasts only until then.
- the prose reasons older builds wrote ("no grammar for this file type", "no tags query available for …", "source is N bytes, over the …") map to the reason they describe. A file with no tags query was NOT text-indexed by those builds, and still reads as text_only: the row says what kind of file it is; whether its text is in the search index depends on the build that wrote it.
type SourceType ¶
type SourceType string
SourceType records the kind of evidence a fact came from. Spec §9.
const ( SourceCompiler SourceType = "compiler" // SCIP index — authoritative SourceSourceCode SourceType = "source_code" // parsed from a syntax tree SourceGit SourceType = "git" // commit history SourceConfig SourceType = "config" // developer-declared config SourceRuntime SourceType = "runtime" // OpenTelemetry spans SourceExternal SourceType = "external" // dependency manifests, advisories SourceInferred SourceType = "inferred" // heuristic with no direct evidence )
type Symbol ¶
type Symbol struct {
ID int64 `json:"id"`
Kind EntityKind `json:"kind"`
Name string `json:"name"` // e.g. "updateStatus"
// FQN is the fully-qualified name, unique within a repository. For SCIP
// symbols this is the SCIP symbol string, which makes exact and heuristic
// facts about the same entity converge on one node.
FQN string `json:"fqn"`
FileID int64 `json:"file_id"`
Range Range `json:"range"`
Signature string `json:"signature,omitempty"`
Doc string `json:"doc,omitempty"`
Exported bool `json:"exported"`
// ParamCount is how many parameters this symbol declares, where the parser
// could determine that. ArityUnknown everywhere else — for non-callables,
// for variadic and defaulted signatures, for languages with no arity query,
// and for symbols that came from SCIP rather than from a syntax tree.
//
// Read by internal/resolve/infer to PREFER a candidate whose parameter
// count matches the call site's argument count. Only to prefer: an arity
// mismatch is never grounds for removing a candidate. See A4 in
// internal/resolve/infer/resolver.go for why that distinction is the whole
// design.
ParamCount Arity `json:"param_count,omitempty"`
// ReturnType is the plain type name a function or method declares it
// returns, where internal/parse read one: `Order` for `Order find(...)`,
// `fun find(): Order`, `fn find() -> Order`. Empty for anything else,
// including a generic or wrapped type the parser does not unwrap. Read by
// internal/resolve/infer to type a variable assigned from a call to it.
ReturnType string `json:"return_type,omitempty"`
// Private is true where internal/parse read the language's own marker that
// the definition is reachable only from what encloses it: `private` on a
// Java, C#, Kotlin or PHP member, `defn-` in Clojure, `static` on a C
// function. False is "not read as private", not "public". Migration
// migration 0001.
Private bool `json:"private,omitempty"`
// Trait is true for a PHP trait, which is indexed as an interface and is
// not one: its methods are implementations. Migration 0001.
Trait bool `json:"trait,omitempty"`
// Singleton is true for a Ruby method defined on the class or module
// itself (`def self.x`, `class << self; def x`), not on its instances.
// False is "not read as singleton", which for every other language is
// all it can say. Bit 16 of symbols.flags.
Singleton bool `json:"singleton,omitempty"`
// Conditional is true for a definition that exists in some builds and not
// in others. Rust: under a `#[cfg(...)]` attribute, on itself or on an
// item that encloses it. C and C++: a function definition written inside a
// preprocessor conditional (`#if`, `#ifdef`, `#else`), other than a header
// guard or `#ifdef __cplusplus`. Two definitions of one name that are both
// conditional are usually alternatives of which a build keeps one, so a
// call that reaches either cannot say which (infer/rustcfg.go for Rust).
// Bit 4 of symbols.flags.
Conditional bool `json:"conditional,omitempty"`
// RefImpl is true for a Rust method declared in an impl whose self type is a
// reference: `impl<'a, T> IntoIterator for &'a Vec<T>`. The same trait is
// usually also implemented for the owned type, under the same qualified name,
// and which one a call reaches depends on whether the receiver is borrowed.
RefImpl bool `json:"ref_impl,omitempty"`
// Confidence describes how reliably this symbol was extracted. Symbols are
// usually high or exact; a Tier-1 generic extraction may be medium.
Confidence Confidence `json:"confidence"`
Source SourceType `json:"source"`
}
Symbol is a named, addressable code entity.