schema

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package schema owns the record serialization layer and its schema-versioned message definitions used by the graph store.

Index

Constants

View Source
const (
	SHA1HexLen   = 40
	SHA256HexLen = 64
)

SHA1HexLen and SHA256HexLen are the two lowercase-hex lengths a well-formed git commit object id can have — promoted here from internal/indexer/commit.go (WR-07) so the ONE validator a commit SHA is checked against at WRITE time (internal/indexer/commit.go's resolveHeadCommitSHA) is also available to check it again at READ time, rather than trusting the stored value is well-formed forever.

IN-05: exported (were gitSHA1HexLen/gitSHA256HexLen, unexported) so internal/indexer/commit.go can reference these directly instead of keeping its own copy "numerically identical to schema's" by comment alone, with nothing asserting that claim stayed true.

View Source
const SchemaVersion uint32 = 1

SchemaVersion is the current on-disk schema version stamped into every Meta record (D-02).

Additive-only discipline (D-02a): within a single SchemaVersion, fields on Node, Edge, File, and Meta are NEVER renumbered or reused. Retiring a field means adding its number to a `reserved` clause in graph.proto, not deleting or repurposing it. SchemaVersion itself is bumped ONLY when a genuinely breaking layout change is unavoidable — a well-formed additive change (a new field, a newly reserved range) never requires a bump.

Variables

View Source
var (
	ExclusionReason_name = map[int32]string{
		0: "EXCLUSION_REASON_UNSPECIFIED",
		1: "EXCLUSION_REASON_DIR_VENDOR",
		2: "EXCLUSION_REASON_DIR_DOTPREFIX",
		3: "EXCLUSION_REASON_UNSUPPORTED_EXTENSION",
		4: "EXCLUSION_REASON_BUILD_TAG",
		5: "EXCLUSION_REASON_SIZE_LIMIT",
	}
	ExclusionReason_value = map[string]int32{
		"EXCLUSION_REASON_UNSPECIFIED":           0,
		"EXCLUSION_REASON_DIR_VENDOR":            1,
		"EXCLUSION_REASON_DIR_DOTPREFIX":         2,
		"EXCLUSION_REASON_UNSUPPORTED_EXTENSION": 3,
		"EXCLUSION_REASON_BUILD_TAG":             4,
		"EXCLUSION_REASON_SIZE_LIMIT":            5,
	}
)

Enum value maps for ExclusionReason.

View Source
var File_internal_schema_graph_proto protoreflect.FileDescriptor

Functions

func IndexedCommitSHA added in v0.12.0

func IndexedCommitSHA(m *Meta) (string, bool)

IndexedCommitSHA reports the git commit m's index was built at (ENG-04, D-05). A nil m, or a m whose commit_sha field is absent or empty, returns ("", false) — the same "unknown, not an error" contract has_file_index's own absent case follows: a pre-upgrade graph (built before field 8 existed) and a non-git checkout are both indistinguishable from each other and both degrade the same way. Callers get one place to ask "do we know the indexed commit" rather than each re-deriving the empty-means-absent convention.

func IsCommitSHA added in v0.12.0

func IsCommitSHA(s string) bool

IsCommitSHA reports whether s is a well-formed git commit object id: exactly SHA1HexLen or SHA256HexLen characters, every one a lowercase hex digit (WR-07). internal/indexer applies this at WRITE time before a commit_sha is ever stamped into a Meta record — but IndexedCommitSHA above returns whatever string a Meta record on disk happens to carry, unvalidated. A store built or edited by anything other than this binary's own indexer (the milestone-2 "CI-distributed indexes" shape .claude/CLAUDE.md names as this project's own architecture target) is not bound by that write-time guarantee, and the unvalidated value is used both as a git CLI argument (gitmeta.CommitOnRemoteTrackingBranch) and spliced raw into a rendered GitHub blob URL (uiserver.buildGitHubBlobURL) — callers that read a commit SHA out of a Meta record and pass it to either of those should call this first.

func IsCurrentSchemaVersion

func IsCurrentSchemaVersion(m *Meta) bool

IsCurrentSchemaVersion reports whether m carries the schema version this build of codegraph-go was compiled against. A record with an older version is expected to still decode (protobuf's forward/backward compatibility, ARCH-01) but callers that need to gate on version drift can use this helper rather than comparing SchemaVersion inline.

func IsDirectoryExclusion added in v0.13.0

func IsDirectoryExclusion(r ExclusionReason) bool

IsDirectoryExclusion reports whether r represents a directory-level exclusion record (D-02) — a pruned subtree represented by ONE record, never phantom per-file rows — as opposed to a file-level exclusion (unsupported extension, build tag, size limit). This is the ONE definition of "directory-level record" that both the indexer (writing records) and the query engine (computing the discovered-count denominator, D-01/research Pitfall 1) import, so the two can never disagree on which reasons count as directory-level.

Types

type Edge

type Edge struct {
	Source string `protobuf:"bytes,1,opt,name=source,proto3" json:"source,omitempty"`
	Target string `protobuf:"bytes,2,opt,name=target,proto3" json:"target,omitempty"`
	Kind   string `protobuf:"bytes,3,opt,name=kind,proto3" json:"kind,omitempty"`
	// Optional call-site coordinates. Per RESEARCH Pitfall 2 / Open Question
	// 3: the Pebble edge KEY (`e/<src>/<kind>/<dst>`, D-03) intentionally
	// omits line/col today, so two call sites between the same (source,
	// kind, target) collapse to one stored edge. That key-identity decision
	// is deferred to Phase 2 extractor design — this record must still be
	// able to CARRY line/col so a future key-shape change (or an
	// annotation/audit trail) doesn't lose the data that's available at
	// extraction time.
	Line int32 `protobuf:"varint,4,opt,name=line,proto3" json:"line,omitempty"`
	Col  int32 `protobuf:"varint,5,opt,name=col,proto3" json:"col,omitempty"`
	// provenance records how this edge was derived. Phase 2 writes only
	// ground-truth values ("ast" or empty) per D-03a; "heuristic" provenance
	// (fuzzy/inferred edges) is Phase 5's addition, not written here.
	Provenance string `protobuf:"bytes,6,opt,name=provenance,proto3" json:"provenance,omitempty"`
	// metadata is an open extension bag for edge-kind-specific extractor
	// annotations that do not warrant their own field yet. Additive schema
	// field (D-03).
	Metadata map[string]string `` /* 143-byte string literal not displayed */
	// contains filtered or unexported fields
}

Edge is a directed relationship between two Node ids (calls, imports, implements, etc.).

func (*Edge) Descriptor deprecated

func (*Edge) Descriptor() ([]byte, []int)

Deprecated: Use Edge.ProtoReflect.Descriptor instead.

func (*Edge) GetCol

func (x *Edge) GetCol() int32

func (*Edge) GetKind

func (x *Edge) GetKind() string

func (*Edge) GetLine

func (x *Edge) GetLine() int32

func (*Edge) GetMetadata

func (x *Edge) GetMetadata() map[string]string

func (*Edge) GetProvenance

func (x *Edge) GetProvenance() string

func (*Edge) GetSource

func (x *Edge) GetSource() string

func (*Edge) GetTarget

func (x *Edge) GetTarget() string

func (*Edge) ProtoMessage

func (*Edge) ProtoMessage()

func (*Edge) ProtoReflect

func (x *Edge) ProtoReflect() protoreflect.Message

func (*Edge) Reset

func (x *Edge) Reset()

func (*Edge) String

func (x *Edge) String() string

type ExcludedFile added in v0.13.0

type ExcludedFile struct {
	Path      string          `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
	Reason    ExclusionReason `protobuf:"varint,2,opt,name=reason,proto3,enum=codegraph.v1.ExclusionReason" json:"reason,omitempty"`
	Detail    string          `protobuf:"bytes,3,opt,name=detail,proto3" json:"detail,omitempty"`
	SizeBytes int64           `protobuf:"varint,4,opt,name=size_bytes,json=sizeBytes,proto3" json:"size_bytes,omitempty"`
	// contains filtered or unexported fields
}

ExcludedFile is a sibling record to File (never a field on it, D-05): one record per path the walker visited but did not index, or one record per pruned directory (D-02). path is the slash-normalized repo-relative path exactly as File.path — a pruned directory's record carries the directory path with no trailing slash. detail is bounded free text (the extension, the byte size, the GOOS/GOARCH pair, or the pruned directory name). size_bytes is the discovery-time stat size (0 for a directory record).

func (*ExcludedFile) Descriptor deprecated added in v0.13.0

func (*ExcludedFile) Descriptor() ([]byte, []int)

Deprecated: Use ExcludedFile.ProtoReflect.Descriptor instead.

func (*ExcludedFile) GetDetail added in v0.13.0

func (x *ExcludedFile) GetDetail() string

func (*ExcludedFile) GetPath added in v0.13.0

func (x *ExcludedFile) GetPath() string

func (*ExcludedFile) GetReason added in v0.13.0

func (x *ExcludedFile) GetReason() ExclusionReason

func (*ExcludedFile) GetSizeBytes added in v0.13.0

func (x *ExcludedFile) GetSizeBytes() int64

func (*ExcludedFile) ProtoMessage added in v0.13.0

func (*ExcludedFile) ProtoMessage()

func (*ExcludedFile) ProtoReflect added in v0.13.0

func (x *ExcludedFile) ProtoReflect() protoreflect.Message

func (*ExcludedFile) Reset added in v0.13.0

func (x *ExcludedFile) Reset()

func (*ExcludedFile) String added in v0.13.0

func (x *ExcludedFile) String() string

type ExclusionReason added in v0.13.0

type ExclusionReason int32

ExclusionReason is the closed vocabulary of reasons a discovered path was NOT indexed, decided at Discover's own decision points and persisted verbatim (Phase 10 HLT-05, D-08) — never reconstructed by a query-time walk. Closed like EditorLinkAvailability so the UI can never meet an unknown reason and set-equality tests can pin the set.

const (
	ExclusionReason_EXCLUSION_REASON_UNSPECIFIED           ExclusionReason = 0
	ExclusionReason_EXCLUSION_REASON_DIR_VENDOR            ExclusionReason = 1
	ExclusionReason_EXCLUSION_REASON_DIR_DOTPREFIX         ExclusionReason = 2
	ExclusionReason_EXCLUSION_REASON_UNSUPPORTED_EXTENSION ExclusionReason = 3
	ExclusionReason_EXCLUSION_REASON_BUILD_TAG             ExclusionReason = 4
	ExclusionReason_EXCLUSION_REASON_SIZE_LIMIT            ExclusionReason = 5
)

func (ExclusionReason) Descriptor added in v0.13.0

func (ExclusionReason) Enum added in v0.13.0

func (x ExclusionReason) Enum() *ExclusionReason

func (ExclusionReason) EnumDescriptor deprecated added in v0.13.0

func (ExclusionReason) EnumDescriptor() ([]byte, []int)

Deprecated: Use ExclusionReason.Descriptor instead.

func (ExclusionReason) Number added in v0.13.0

func (ExclusionReason) String added in v0.13.0

func (x ExclusionReason) String() string

func (ExclusionReason) Type added in v0.13.0

type File

type File struct {
	Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
	// content_hash MUST be a collision-resistant hash (SHA-256 — see
	// Security Domain V6 in 01-RESEARCH.md), never a weak hash like MD5.
	// The hash computation itself lands with the Phase 2 indexer; this
	// field only defines its storage shape.
	ContentHash string `protobuf:"bytes,2,opt,name=content_hash,json=contentHash,proto3" json:"content_hash,omitempty"`
	Language    string `protobuf:"bytes,3,opt,name=language,proto3" json:"language,omitempty"`
	NodeCount   int64  `protobuf:"varint,4,opt,name=node_count,json=nodeCount,proto3" json:"node_count,omitempty"`
	EdgeCount   int64  `protobuf:"varint,5,opt,name=edge_count,json=edgeCount,proto3" json:"edge_count,omitempty"`
	// errors records per-file extraction failures (e.g. oversized or
	// unparseable source) so one bad file does not abort the whole index run
	// (RESEARCH Assumptions Log A2, Pitfall 4). Additive extension of D-03's
	// File record.
	Errors []string `protobuf:"bytes,6,rep,name=errors,proto3" json:"errors,omitempty"`
	// mtime_unix_ns is the file's on-disk modification time (nanoseconds
	// since epoch) as observed by the writer. Additive Phase-4 field
	// (D-01a); written by both `index` and `sync` so the incremental sync
	// engine's stat pre-filter can cheaply shortlist changed files before
	// paying for a content_hash recompute.
	MtimeUnixNs int64 `protobuf:"varint,7,opt,name=mtime_unix_ns,json=mtimeUnixNs,proto3" json:"mtime_unix_ns,omitempty"`
	// size_bytes is the file's on-disk size in bytes as observed by the
	// writer. Additive Phase-4 field (D-01a); written by both `index` and
	// `sync` alongside mtime_unix_ns for the same stat pre-filter.
	SizeBytes int64 `protobuf:"varint,8,opt,name=size_bytes,json=sizeBytes,proto3" json:"size_bytes,omitempty"`
	// contains filtered or unexported fields
}

File is a per-source-file record: identity, content hash, and aggregate counts for the symbols/edges attributed to it.

func (*File) Descriptor deprecated

func (*File) Descriptor() ([]byte, []int)

Deprecated: Use File.ProtoReflect.Descriptor instead.

func (*File) GetContentHash

func (x *File) GetContentHash() string

func (*File) GetEdgeCount

func (x *File) GetEdgeCount() int64

func (*File) GetErrors

func (x *File) GetErrors() []string

func (*File) GetLanguage

func (x *File) GetLanguage() string

func (*File) GetMtimeUnixNs

func (x *File) GetMtimeUnixNs() int64

func (*File) GetNodeCount

func (x *File) GetNodeCount() int64

func (*File) GetPath

func (x *File) GetPath() string

func (*File) GetSizeBytes

func (x *File) GetSizeBytes() int64

func (*File) ProtoMessage

func (*File) ProtoMessage()

func (*File) ProtoReflect

func (x *File) ProtoReflect() protoreflect.Message

func (*File) Reset

func (x *File) Reset()

func (*File) String

func (x *File) String() string

type Meta

type Meta struct {
	SchemaVersion  uint32 `protobuf:"varint,1,opt,name=schema_version,json=schemaVersion,proto3" json:"schema_version,omitempty"`
	NodeCount      int64  `protobuf:"varint,2,opt,name=node_count,json=nodeCount,proto3" json:"node_count,omitempty"`
	EdgeCount      int64  `protobuf:"varint,3,opt,name=edge_count,json=edgeCount,proto3" json:"edge_count,omitempty"`
	LastSyncUnixMs int64  `protobuf:"varint,4,opt,name=last_sync_unix_ms,json=lastSyncUnixMs,proto3" json:"last_sync_unix_ms,omitempty"`
	Healthy        bool   `protobuf:"varint,5,opt,name=healthy,proto3" json:"healthy,omitempty"`
	HealthMessage  string `protobuf:"bytes,6,opt,name=health_message,json=healthMessage,proto3" json:"health_message,omitempty"`
	// has_file_index reports whether this graph's on-disk store has been
	// populated with the Phase-4 `x/` file-owned secondary index (D-02).
	// Additive Phase-4 field (D-02b); false means a pre-Phase-4 graph that
	// lacks the index, signaling `sync` to perform a one-time full
	// re-index backfill before switching to incremental updates.
	HasFileIndex bool `protobuf:"varint,7,opt,name=has_file_index,json=hasFileIndex,proto3" json:"has_file_index,omitempty"`
	// commit_sha records the git commit the index was built at (Phase 1
	// ENG-04, D-05). Absent or empty means a pre-upgrade graph — one built
	// before this field existed — OR a non-git checkout; consumers must
	// treat it as unknown rather than as an error. Accepted forms are
	// exactly 40 (SHA-1) or 64 (SHA-256) characters of lowercase hex; any
	// other value is never written. This field number is now spent
	// permanently (D-02a): once shipped, field 8 can never be renumbered or
	// reused — retiring it means adding 8 to a `reserved` clause.
	CommitSha string `protobuf:"bytes,8,opt,name=commit_sha,json=commitSha,proto3" json:"commit_sha,omitempty"`
	// has_coverage reports whether this graph's on-disk store has been
	// populated with the Phase-10 `c/` exclusion-reason namespace (D-06).
	// Additive Phase-10 field, following has_file_index's precedent
	// exactly: absent/false means coverage is UNKNOWN — never 0/0, never
	// inferred from `c/` key presence (a repo with genuinely zero
	// exclusions would otherwise be indistinguishable from a pre-Phase-10
	// graph). A store whose Meta lacks this field must re-index to record
	// coverage.
	HasCoverage bool `protobuf:"varint,9,opt,name=has_coverage,json=hasCoverage,proto3" json:"has_coverage,omitempty"`
	// coverage_generation is a monotonically-incrementing counter, bumped by
	// exactly 1 at every one of the same three meta-write sites that stamp
	// has_coverage (Phase 10 WR-01). It replaces last_sync_unix_ms as the
	// page-token generation marker for CoverageRows: a wall-clock,
	// millisecond-resolution marker can alias when two coverage-affecting
	// commits land within the same millisecond, silently defeating the
	// "index changed since the last page fetch" check. A plain integer
	// counter guarantees two distinct writes imply two distinct generations
	// regardless of clock resolution or backward clock steps. Additive
	// Phase-10 field, following has_coverage's own precedent exactly:
	// absent/zero means either a pre-this-fix graph or a graph that has
	// never recorded coverage — CoverageRows' has_coverage short-circuit
	// already refuses to mint a token in that case (D-06), so an unset
	// value here is never observed by a real page token.
	CoverageGeneration int64 `protobuf:"varint,10,opt,name=coverage_generation,json=coverageGeneration,proto3" json:"coverage_generation,omitempty"`
	// contains filtered or unexported fields
}

Meta is the single versioned record (stored under the `meta/` key prefix, D-03) that stamps the on-disk schema version plus aggregate counts and index health. schema_version is bumped ONLY for a genuinely breaking layout change — additive field changes never require a bump (D-02a).

func NewMeta

func NewMeta() *Meta

NewMeta returns a Meta record stamped with the current SchemaVersion. Callers should use this instead of constructing a Meta literal directly, so a SchemaVersion bump only needs to change in one place.

func (*Meta) Descriptor deprecated

func (*Meta) Descriptor() ([]byte, []int)

Deprecated: Use Meta.ProtoReflect.Descriptor instead.

func (*Meta) GetCommitSha added in v0.12.0

func (x *Meta) GetCommitSha() string

func (*Meta) GetCoverageGeneration added in v0.13.0

func (x *Meta) GetCoverageGeneration() int64

func (*Meta) GetEdgeCount

func (x *Meta) GetEdgeCount() int64

func (*Meta) GetHasCoverage added in v0.13.0

func (x *Meta) GetHasCoverage() bool

func (*Meta) GetHasFileIndex

func (x *Meta) GetHasFileIndex() bool

func (*Meta) GetHealthMessage

func (x *Meta) GetHealthMessage() string

func (*Meta) GetHealthy

func (x *Meta) GetHealthy() bool

func (*Meta) GetLastSyncUnixMs

func (x *Meta) GetLastSyncUnixMs() int64

func (*Meta) GetNodeCount

func (x *Meta) GetNodeCount() int64

func (*Meta) GetSchemaVersion

func (x *Meta) GetSchemaVersion() uint32

func (*Meta) ProtoMessage

func (*Meta) ProtoMessage()

func (*Meta) ProtoReflect

func (x *Meta) ProtoReflect() protoreflect.Message

func (*Meta) Reset

func (x *Meta) Reset()

func (*Meta) String

func (x *Meta) String() string

type Node

type Node struct {
	Id            string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Kind          string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty"`
	Name          string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
	QualifiedName string `protobuf:"bytes,4,opt,name=qualified_name,json=qualifiedName,proto3" json:"qualified_name,omitempty"`
	FilePath      string `protobuf:"bytes,5,opt,name=file_path,json=filePath,proto3" json:"file_path,omitempty"`
	Language      string `protobuf:"bytes,6,opt,name=language,proto3" json:"language,omitempty"`
	StartLine     int32  `protobuf:"varint,7,opt,name=start_line,json=startLine,proto3" json:"start_line,omitempty"`
	EndLine       int32  `protobuf:"varint,8,opt,name=end_line,json=endLine,proto3" json:"end_line,omitempty"`
	StartCol      int32  `protobuf:"varint,9,opt,name=start_col,json=startCol,proto3" json:"start_col,omitempty"`
	EndCol        int32  `protobuf:"varint,10,opt,name=end_col,json=endCol,proto3" json:"end_col,omitempty"`
	// signature is the extractor-rendered parameter/return signature string
	// (e.g. "func(a int, b string) error"). Additive schema field (D-03);
	// written by the Phase 2 goextract symbol pass.
	Signature string `protobuf:"bytes,11,opt,name=signature,proto3" json:"signature,omitempty"`
	// docstring is the leading comment/doc block attached to the symbol, as
	// captured verbatim by the extractor. Additive schema field (D-03);
	// written by the Phase 2 goextract symbol pass.
	Docstring string `protobuf:"bytes,12,opt,name=docstring,proto3" json:"docstring,omitempty"`
	// visibility is the language-level access modifier ("public", "private",
	// "package", etc.) as classified by the extractor. Additive schema
	// field (D-03); written by the Phase 2 goextract symbol pass.
	Visibility string `protobuf:"bytes,13,opt,name=visibility,proto3" json:"visibility,omitempty"`
	// is_exported reports whether the symbol crosses the package/module
	// boundary (Go: identifier starts uppercase). Additive schema field
	// (D-03); written by the Phase 2 goextract symbol pass.
	IsExported bool `protobuf:"varint,14,opt,name=is_exported,json=isExported,proto3" json:"is_exported,omitempty"`
	// return_type is the extractor-rendered return type string, when the
	// symbol kind has one (function/method). Additive schema field
	// (D-03); written by the Phase 2 goextract symbol pass.
	ReturnType string `protobuf:"bytes,15,opt,name=return_type,json=returnType,proto3" json:"return_type,omitempty"`
	// contains filtered or unexported fields
}

Node is a single symbol record (function, type, method, etc.) extracted from a source file.

NOTE: field names/types are designed against the TS `.codegraph/` DDL captured in Plan 01-04. If 01-04 has not landed by the time this is read, reconcile these fields against the captured DDL once it is available — additively only, per D-02a.

func (*Node) Descriptor deprecated

func (*Node) Descriptor() ([]byte, []int)

Deprecated: Use Node.ProtoReflect.Descriptor instead.

func (*Node) GetDocstring

func (x *Node) GetDocstring() string

func (*Node) GetEndCol

func (x *Node) GetEndCol() int32

func (*Node) GetEndLine

func (x *Node) GetEndLine() int32

func (*Node) GetFilePath

func (x *Node) GetFilePath() string

func (*Node) GetId

func (x *Node) GetId() string

func (*Node) GetIsExported

func (x *Node) GetIsExported() bool

func (*Node) GetKind

func (x *Node) GetKind() string

func (*Node) GetLanguage

func (x *Node) GetLanguage() string

func (*Node) GetName

func (x *Node) GetName() string

func (*Node) GetQualifiedName

func (x *Node) GetQualifiedName() string

func (*Node) GetReturnType

func (x *Node) GetReturnType() string

func (*Node) GetSignature

func (x *Node) GetSignature() string

func (*Node) GetStartCol

func (x *Node) GetStartCol() int32

func (*Node) GetStartLine

func (x *Node) GetStartLine() int32

func (*Node) GetVisibility

func (x *Node) GetVisibility() string

func (*Node) ProtoMessage

func (*Node) ProtoMessage()

func (*Node) ProtoReflect

func (x *Node) ProtoReflect() protoreflect.Message

func (*Node) Reset

func (x *Node) Reset()

func (*Node) String

func (x *Node) String() string

Jump to

Keyboard shortcuts

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