store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Qualified Name (qname) conventions for external consumers

CKG stores every symbol with a qualified_name (qname) field whose format is language-specific but follows a consistent hierarchy:

Go:         "package.Type.Method"   e.g. "vault.Vault.Deposit"
TypeScript: "module.Class.method"   e.g. "auth.AuthService.login"
Solidity:   "Contract.function"     e.g. "GovStaking.deposit"

The qname is the primary lookup key for traversal methods:

Reader.FindSymbol(name, exact, opts)        — exact or suffix match
Reader.NeighborhoodByQname(qname, depth, reverse, edgeTypes...)
Reader.SubgraphByQname(qname, depth)

Canonical-helper pattern for cks/ckv

External consumers (cks, ckv) typically receive user input that does not match the stored qname exactly — partial names, mixed case, or receiver-style prefixes (*pkg.Type). The recommended wrapping pattern uses FindSymbol with exact=false (suffix LIKE match) as the canonical resolution step, then passes the resolved qname to traversal methods:

r, _ := store.OpenReadOnly("/path/to/graph.db")
defer r.Close()

// Step 1: resolve user input → canonical qname(s).
// exact=false matches "%.Deposit" so "Deposit" finds
// "vault.Vault.Deposit" without the caller knowing the package.
nodes, _ := r.FindSymbol("Deposit", false, store.FindSymbolOptions{
    Language: "go",
    Kinds:    []string{"Function", "Method"},
})

// Step 2: use the resolved qname for traversal.
for _, n := range nodes {
    callers, edges, _ := r.NeighborhoodByQname(
        n.QualifiedName, 2, true,  // reverse=true → callers
    )
    // ... use callers, edges
}

Normalisation rules

Before calling FindSymbol, strip these prefixes that leak from AST representations but are not stored in the graph:

  • Go pointer receiver: "*pkg.Type.Method" → "pkg.Type.Method"
  • Go address-of: "&pkg.New" → "pkg.New"

CKG's internal extractSymbols already applies these rules (see internal/eval/runner.go); external consumers should replicate the same strip before lookup to avoid zero-result queries.

SearchFTS vs FindSymbol

Use FindSymbol when you have an identifier (exact or suffix). Use SearchFTS / SearchWithOpts when you have natural-language keywords or need BM25 ranking across the full corpus. The two paths are complementary — cks's typical flow is:

ckv (vocab bridge) → exact keywords → ckg FindSymbol or SearchFTS

Package store is the public, read-only graph access surface for external callers (eval harness, sister repos like code-knowledge-system). It re-exports the minimum useful subset of internal/persist as type aliases so callers don't have to depend on internal/persist directly. Write access stays internal — there is no Writer here by design.

Stability

This surface follows semantic versioning once the sister-repo extraction lands. Until then, treat it as the single throat to choke when changing internal/persist — anything that breaks the alias here will break external consumers, even if in-repo callers compile fine.

What to import from where

External consumers (anything outside this module) should import only from pkg/store and pkg/types. They cannot reach internal/persist by the Go `internal/` rule, and that's intentional: pkg/store decides what to promote to the public surface.

Reader covers the read API; SearchHit / SearchFTSOptions / FindSymbolOptions are the value types you'll touch when calling Reader.SearchFTS or Reader.FindSymbol. Manifest is the minimal mirror of build-time metadata — use the GetManifest helper rather than Reader.GetManifest directly so the projection (which drops incremental-cache fields) stays the single source of truth (CKG-7).

Do NOT

External code MUST NOT type-alias persist.StoreReader on its own (the "self-shim" pattern surfaced by the cks dogfood). That duplicates the public surface and silently drifts the moment we change internal/persist. If you find yourself wanting one, it means a type you need isn't re-exported here yet — open a PR to add the alias instead.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMetric = persist.ErrInvalidMetric

ErrInvalidMetric is returned by Reader.TopNodes when the metric argument is not one of the supported column names. HTTP layers typically map this to 400.

Functions

This section is empty.

Types

type FindSymbolOptions

type FindSymbolOptions = persist.FindSymbolOptions

FindSymbolOptions configures filter push-down for Reader.FindSymbol (Language, Kinds). Zero value means "no filter" (CKG-4).

type Manifest

type Manifest struct {
	CommitHash     string // source commit at index time; empty when build did not record one
	SchemaVersion  string // ckg schema version, e.g. "1.9"
	IndexTimestamp string // RFC3339 timestamp of the build
}

Manifest is the public, minimal snapshot of build-time metadata an external consumer needs (CKG-7). Compared to the internal persist.Manifest, this type deliberately drops incremental-cache fields (SrcRoot, Files, StalenessFiles, StalenessMTimeSum, …) — those rotate with build-pipeline changes and external consumers must not depend on them.

Use cases (mirroring what the cks dogfood surfaced):

  • CommitHash drives Citation.CommitHash drift detection
  • SchemaVersion gates compatibility in cks.ops.health
  • IndexTimestamp shows freshness in user-facing status output

Adding a field here is a breaking change for external consumers — it forces them to widen their struct in lockstep. If a new field is truly needed by every consumer, add it; if only one consumer needs it, prefer exposing it through a dedicated Reader method instead.

func GetManifest

func GetManifest(r Reader) (Manifest, error)

GetManifest reads the build-time manifest from r and projects it onto the minimal public Manifest. External consumers should use this in preference to Reader.GetManifest, which returns the full internal struct (whose field set is not part of the public API).

The projection is intentionally one-way: there is no inverse operation. If a consumer needs richer metadata, the right move is to widen Manifest here (a breaking change with deliberate review) rather than to read internal fields by other means.

type PRRef

type PRRef = types.PRRef

PRRef is the public alias for the build-time-derived PR breadcrumb (ckg-NEW-2). External consumers (cks, ckv) read this via Reader.GetNodePRs; see pkg/types.PRRef for the field semantics and the temporal-slicing contract.

type Reader

type Reader = persist.StoreReader

Reader is the read-only graph surface — the canonical entry point for external consumers. Aliased from persist.StoreReader; any change to the upstream interface is a breaking change here.

func OpenReadOnly

func OpenReadOnly(path string) (Reader, error)

OpenReadOnly opens a graph DB at path for read-only access. The returned Reader must be closed by the caller via Reader.Close().

type SearchFTSOptions

type SearchFTSOptions = persist.SearchFTSOptions

SearchFTSOptions configures filter push-down for Reader.SearchFTS. Zero value means "no filter" (CKG-2).

type SearchHit

type SearchHit = persist.SearchHit

SearchHit pairs a node with its full-text search relevance score. Returned by Reader.SearchFTS. See persist.SearchHit doc for the Score vs RawScore semantics (CKG-1).

Jump to

Keyboard shortcuts

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