store

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package store manages the DevSpecs SQLite database: opening, migrations, and queries.

Index

Constants

View Source
const SQLiteBusyTimeoutMS = 5000

SQLiteBusyTimeoutMS is the local index write-wait window for concurrent CLI commands before SQLite returns a busy/locked error.

View Source
const SchemaVersion = 14

SchemaVersion is the current schema version. Bump when schema.sql changes.

Variables

This section is empty.

Functions

func FriendlySQLiteBusyError added in v1.0.0

func FriendlySQLiteBusyError(err error) error

FriendlySQLiteBusyError adds an operator-facing hint to SQLite lock errors.

func IsSQLiteBusyError added in v1.0.0

func IsSQLiteBusyError(err error) bool

IsSQLiteBusyError reports whether err looks like SQLite write contention.

Types

type ArtifactEdgeFilter added in v0.1.0

type ArtifactEdgeFilter struct {
	RepoID        string
	SrcArtifactID string
	DstArtifactID string
	EdgeType      string
}

ArtifactEdgeFilter limits artifact edge queries.

type ArtifactEdgeInput added in v0.1.0

type ArtifactEdgeInput struct {
	ID            string
	RepoID        string
	SrcArtifactID string
	DstArtifactID string
	EdgeType      string
	Weight        float64
	Confidence    float64
	EvidenceCount int
	Freshness     string
	SourceSignal  string
	Explanation   string
	MetadataJSON  string
}

ArtifactEdgeInput is an evidence-backed relationship between two artifacts.

type ArtifactEdgeRow added in v0.1.0

type ArtifactEdgeRow struct {
	ID            string
	RepoID        string
	SrcArtifactID string
	DstArtifactID string
	EdgeType      string
	Weight        float64
	Confidence    float64
	EvidenceCount int
	Freshness     string
	SourceSignal  string
	Explanation   string
	MetadataJSON  string
}

ArtifactEdgeRow is a stored artifact_edges row.

type ArtifactRow

type ArtifactRow struct {
	ID             string
	RepoID         string
	ShortID        string
	Kind           string
	Subtype        string
	Title          string
	Status         string
	CurrentRevID   string
	CreatedAt      string
	UpdatedAt      string
	LastObservedAt string
}

ArtifactRow represents a row from the artifacts table.

type ArtifactSourcePathRow added in v0.1.0

type ArtifactSourcePathRow struct {
	ArtifactID     string
	Kind           string
	Subtype        string
	Title          string
	Path           string
	SourceIdentity string
}

ArtifactSourcePathRow maps a stored artifact to a source path that can be matched to git file changes.

type ConceptInput added in v0.1.0

type ConceptInput struct {
	ID                       string
	RepoID                   string
	Canonical                string
	Kind                     string
	Forms                    []string
	DocumentFrequency        int
	InverseDocumentFrequency float64
}

ConceptInput is a durable repo-local concept row.

type ConceptMentionInput added in v0.1.0

type ConceptMentionInput struct {
	ID           string
	ConceptID    string
	ArtifactID   string
	SectionID    string
	Field        string
	Weight       float64
	EvidenceJSON string
}

ConceptMentionInput links a concept to a field or section on an artifact.

type CriterionRow

type CriterionRow struct {
	ID              string
	ArtifactID      string
	RevisionID      string
	Ordinal         int
	Text            string
	Done            bool
	SourceFile      string
	SourceLine      int
	CriteriaKind    string
	ArtifactTitle   string
	ArtifactKind    string
	ArtifactShortID string
}

CriterionRow represents a row from the artifact_criteria table.

type DB

type DB struct {
	*sql.DB
}

DB wraps *sql.DB with DevSpecs-specific operations.

func Open

func Open(dbPath string) (*DB, error)

Open opens or creates the SQLite database at the given path. It ensures the parent directory exists and applies migrations.

func (*DB) AssignArtifactShortID

func (db *DB) AssignArtifactShortID(artifactID, baseShort string) error

AssignArtifactShortID sets short_id to baseShort, or baseShort with a numeric suffix, until UNIQUE succeeds.

func (*DB) CountArtifacts added in v0.1.0

func (db *DB) CountArtifacts(fp FilterParams) (int, error)

CountArtifacts returns the number of distinct artifacts that match the filters.

func (*DB) CountGitFacts added in v0.1.0

func (db *DB) CountGitFacts(repoID string) (GitFactCounts, error)

CountGitFacts returns commit/file fact counts for a repo.

func (*DB) CountSourceManifest added in v1.0.0

func (db *DB) CountSourceManifest(repoID string) (SourceManifestCounts, error)

CountSourceManifest returns compact manifest row counts for a repo.

func (*DB) DeleteArtifactEvidence added in v0.1.0

func (db *DB) DeleteArtifactEvidence(artifactID string) error

DeleteArtifactEvidence removes derived graph evidence touching one artifact.

func (*DB) DeleteAutoTags

func (db *DB) DeleteAutoTags(artifactID string) error

DeleteAutoTags removes all frontmatter and inferred tags for an artifact (preserving manual).

func (*DB) DeleteRepoEvidence added in v0.1.0

func (db *DB) DeleteRepoEvidence(repoID string) error

DeleteRepoEvidence removes all derived graph evidence for a repo.

func (*DB) DeleteRepoGitFacts added in v0.1.0

func (db *DB) DeleteRepoGitFacts(repoID string) error

DeleteRepoGitFacts removes git fact rows for a repo.

func (*DB) DeleteRepoSourceManifest added in v1.0.0

func (db *DB) DeleteRepoSourceManifest(repoID string) error

DeleteRepoSourceManifest removes compact source manifest rows for a repo.

func (*DB) DeleteTag

func (db *DB) DeleteTag(artifactID, tag string) error

DeleteTag removes a specific tag from an artifact.

func (*DB) EnsureRepo

func (db *DB) EnsureRepo(rootPath, now string) (string, error)

EnsureRepo creates or returns the repo ID for the given root path.

func (*DB) FindArtifactIDsBySectionFTS added in v0.1.0

func (db *DB) FindArtifactIDsBySectionFTS(match string, fp FilterParams, limit int) ([]string, error)

FindArtifactIDsBySectionFTS returns artifact IDs matching section-level FTS.

func (*DB) FindArtifactIDsByTitleOrPathTerms added in v0.1.0

func (db *DB) FindArtifactIDsByTitleOrPathTerms(terms []string, fp FilterParams, limit int) ([]string, error)

FindArtifactIDsByTitleOrPathTerms returns artifact IDs with title/path LIKE matches.

func (*DB) FindArtifactIDsFTS added in v0.1.0

func (db *DB) FindArtifactIDsFTS(match string, fp FilterParams, limit int) ([]string, error)

FindArtifactIDsFTS returns artifact IDs matching artifact-level FTS.

func (*DB) FindArtifactSections added in v0.1.0

func (db *DB) FindArtifactSections(query string, fp FilterParams, limit int) ([]SectionRow, error)

FindArtifactSections returns section hits for a query using section FTS.

func (*DB) FindArtifacts

func (db *DB) FindArtifacts(query string, fp FilterParams) ([]ArtifactRow, error)

FindArtifacts does a text search across title, source path, and body. It tries FTS5 first, falling back to LIKE if FTS returns no results or errors.

func (*DB) FindSourceByIdentity

func (db *DB) FindSourceByIdentity(identity string) (string, error)

FindSourceByIdentity checks if a source_identity already exists and returns the artifact ID.

func (*DB) GetArtifact

func (db *DB) GetArtifact(idOrPrefix string) (*ArtifactRow, error)

GetArtifact retrieves a single artifact by full ID, short_id, or prefix.

func (*DB) GetArtifactEdges added in v0.1.0

func (db *DB) GetArtifactEdges(fp ArtifactEdgeFilter) ([]ArtifactEdgeRow, error)

GetArtifactEdges returns artifact edges matching the filter.

func (*DB) GetArtifactSourcePaths added in v0.1.0

func (db *DB) GetArtifactSourcePaths(repoID string) ([]ArtifactSourcePathRow, error)

GetArtifactSourcePaths returns artifact source paths for git file-change mapping.

func (*DB) GetCriteriaForArtifact

func (db *DB) GetCriteriaForArtifact(artifactID string) ([]CriterionRow, error)

GetCriteriaForArtifact returns extracted criteria for a specific artifact.

func (*DB) GetLinksForArtifact

func (db *DB) GetLinksForArtifact(artifactID string) ([]LinkRow, error)

GetLinksForArtifact returns all links for an artifact.

func (*DB) GetLinksForArtifacts added in v0.1.0

func (db *DB) GetLinksForArtifacts(ids []string) (map[string][]LinkRow, error)

GetLinksForArtifacts returns links grouped by artifact ID.

func (*DB) GetRepoByRoot

func (db *DB) GetRepoByRoot(rootPath string) *RepoMeta

GetRepoByRoot returns the repo row for a given root path, or nil if not found.

func (*DB) GetRevision

func (db *DB) GetRevision(id string) (*RevisionRow, error)

GetRevision retrieves a revision by ID.

func (*DB) GetRevisionsByIDs added in v0.1.0

func (db *DB) GetRevisionsByIDs(ids []string) (map[string]RevisionRow, error)

GetRevisionsByIDs returns revisions grouped by revision ID.

func (*DB) GetSectionsForArtifact added in v0.1.0

func (db *DB) GetSectionsForArtifact(artifactID string) ([]SectionRow, error)

GetSectionsForArtifact returns persisted sections for an artifact.

func (*DB) GetSectionsForArtifacts added in v0.1.0

func (db *DB) GetSectionsForArtifacts(ids []string) (map[string][]SectionRow, error)

GetSectionsForArtifacts returns persisted sections grouped by artifact ID.

func (*DB) GetSourcesForArtifact

func (db *DB) GetSourcesForArtifact(artifactID string) ([]SourceRow, error)

GetSourcesForArtifact returns all sources for an artifact.

func (*DB) GetSourcesForArtifacts added in v0.1.0

func (db *DB) GetSourcesForArtifacts(ids []string) (map[string][]SourceRow, error)

GetSourcesForArtifacts returns sources grouped by artifact ID.

func (*DB) GetTagsForArtifact

func (db *DB) GetTagsForArtifact(artifactID string) ([]TagRow, error)

GetTagsForArtifact returns all tags for an artifact.

func (*DB) GetTodosForArtifact

func (db *DB) GetTodosForArtifact(artifactID string) ([]TodoRow, error)

GetTodosForArtifact returns todos for a specific artifact.

func (*DB) GetTodosForArtifacts added in v0.1.0

func (db *DB) GetTodosForArtifacts(ids []string) (map[string][]TodoRow, error)

GetTodosForArtifacts returns todos grouped by artifact ID.

func (*DB) IndexArtifactFTS

func (db *DB) IndexArtifactFTS(artifactID, title, body, sourcePath string) error

IndexArtifactFTS inserts or updates the FTS5 index for an artifact.

func (*DB) InsertArtifactDirect

func (db *DB) InsertArtifactDirect(id, repoID, kind, subtype, title, status, revID, authoredAt, now string) error

InsertArtifactDirect allows inserting an artifact directly (for capture).

func (db *DB) InsertLink(id, artifactID, linkType, target, now string) error

InsertLink adds a link for an artifact.

func (*DB) InsertRevisionDirect

func (db *DB) InsertRevisionDirect(id, artifactID, contentHash, body, extractedJSON, now string) error

InsertRevisionDirect inserts a revision directly. extractedJSON may be empty for NULL.

func (*DB) InsertSourceDirect

func (db *DB) InsertSourceDirect(id, artifactID, repoID, sourceType, path, sourceIdentity, formatProfile, layoutGroup, now string) error

InsertSourceDirect inserts a source directly.

func (*DB) InsertTag

func (db *DB) InsertTag(artifactID, tag, source, now string) error

InsertTag adds a tag for an artifact. It is a no-op on conflict.

func (*DB) ListAllCriteria

func (db *DB) ListAllCriteria(fp FilterParams, openOnly, doneOnly bool, criteriaKind string) ([]CriterionRow, error)

ListAllCriteria returns criteria across all artifacts, optionally filtered. criteriaKind filters by criteria_kind when non-empty (acceptance, success, okr).

func (*DB) ListAllTodos

func (db *DB) ListAllTodos(fp FilterParams, openOnly, doneOnly bool) ([]TodoRow, error)

ListAllTodos returns todos across all artifacts, optionally filtered.

func (*DB) ListArtifacts

func (db *DB) ListArtifacts(fp FilterParams) ([]ArtifactRow, error)

ListArtifacts returns artifacts filtered by the given parameters.

func (*DB) ListArtifactsByIDs added in v0.1.0

func (db *DB) ListArtifactsByIDs(ids []string, fp FilterParams) ([]ArtifactRow, error)

ListArtifactsByIDs returns filtered artifact rows for selected IDs in input order.

func (*DB) ListRecentTaskCheckpointFacts added in v1.0.0

func (db *DB) ListRecentTaskCheckpointFacts(repoID string, limit int) ([]TaskCheckpointFact, error)

ListRecentTaskCheckpointFacts returns recent compact checkpoint facts for a repo.

func (*DB) ListTaskCheckpointFacts added in v1.0.0

func (db *DB) ListTaskCheckpointFacts(repoID, taskID string) ([]TaskCheckpointFact, error)

ListTaskCheckpointFacts returns compact checkpoint facts for one task.

func (*DB) ReplaceArtifactSections added in v0.1.0

func (db *DB) ReplaceArtifactSections(artifactID, revisionID string, sections []docsections.Section, now string) error

ReplaceArtifactSections replaces persisted sections and section FTS rows for one artifact.

func (*DB) ReplaceConceptMentions added in v0.1.0

func (db *DB) ReplaceConceptMentions(artifactID string, mentions []ConceptMentionInput, now string) error

ReplaceConceptMentions replaces all mentions for one artifact.

func (*DB) ReplaceRepoEvidence added in v0.1.0

func (db *DB) ReplaceRepoEvidence(repoID string, concepts []ConceptInput, mentions []ConceptMentionInput, edges []ArtifactEdgeInput, now string) error

ReplaceRepoEvidence rebuilds derived graph evidence for a repo.

func (*DB) ReplaceRepoEvidenceScope added in v0.1.0

func (db *DB) ReplaceRepoEvidenceScope(repoID, conceptKind, edgeType string, concepts []ConceptInput, mentions []ConceptMentionInput, edges []ArtifactEdgeInput, now string) error

ReplaceRepoEvidenceScope rebuilds a narrow concept/edge evidence scope for a repo.

func (*DB) ReplaceRepoGitFacts added in v0.1.0

func (db *DB) ReplaceRepoGitFacts(repoID string, commits []GitCommitInput, files []GitCommitFileInput, now string) error

ReplaceRepoGitFacts replaces all git fact rows for a repo.

func (*DB) ReplaceRepoSourceManifest added in v1.0.0

func (db *DB) ReplaceRepoSourceManifest(repoID string, files []SourceManifestFileInput, symbols []SourceManifestSymbolInput, tests []SourceManifestTestInput, imports []SourceManifestImportInput, ftsRows []SourceManifestFTSInput, now string) error

ReplaceRepoSourceManifest replaces all compact source manifest rows for a repo.

func (*DB) ResumeArtifacts

func (db *DB) ResumeArtifacts(repoRoot string, fp FilterParams) ([]ResumeRow, error)

ResumeArtifacts returns all artifacts for a repo, with todo counts, sorted by updated_at DESC.

func (*DB) SearchSourceManifestFTS added in v1.0.0

func (db *DB) SearchSourceManifestFTS(match string, fp FilterParams, limit int) ([]SourceManifestSearchRow, error)

SearchSourceManifestFTS returns compact source/test rows matching manifest FTS.

func (*DB) UpdateArtifactShortID

func (db *DB) UpdateArtifactShortID(artifactID, shortID string) error

UpdateArtifactShortID sets the short_id for an artifact.

func (*DB) UpdateArtifactStatus

func (db *DB) UpdateArtifactStatus(artifactID, status, now string) error

UpdateArtifactStatus updates the status of an artifact.

func (*DB) UpdateScanMeta

func (db *DB) UpdateScanMeta(repoID, commit, scannedBy, now string)

UpdateScanMeta records the git commit, timestamp, and user of the last scan.

func (*DB) UpsertArtifactEdge added in v0.1.0

func (db *DB) UpsertArtifactEdge(e ArtifactEdgeInput, now string) error

UpsertArtifactEdge creates or updates one edge by its stable edge identity.

func (*DB) UpsertConcept added in v0.1.0

func (db *DB) UpsertConcept(c ConceptInput, now string) error

UpsertConcept creates or updates one concept by its repo/kind/canonical identity.

func (*DB) UpsertTaskCheckpointFact added in v1.0.0

func (db *DB) UpsertTaskCheckpointFact(f TaskCheckpointFact) error

UpsertTaskCheckpointFact stores compact structured checkpoint facts.

type FilterParams

type FilterParams struct {
	RepoRoot   string
	Kind       string
	Subtype    string
	Status     string
	SourceType string
	Tag        string
	Branch     string
	User       string
}

FilterParams groups all query filters.

type GitCommitFileInput added in v0.1.0

type GitCommitFileInput struct {
	RepoID     string
	CommitSHA  string
	FilePath   string
	ChangeType string
	OldPath    string
}

GitCommitFileInput is one changed file entry for a captured git commit.

type GitCommitInput added in v0.1.0

type GitCommitInput struct {
	RepoID       string
	SHA          string
	Branch       string
	AuthorName   string
	AuthorEmail  string
	Message      string
	BodyPreview  string
	CommittedAt  string
	FilesChanged int
	IsMerge      bool
	HistoryShape string
}

GitCommitInput is a local git commit fact captured during an opt-in scan.

type GitFactCounts added in v0.1.0

type GitFactCounts struct {
	Commits int
	Files   int
}

GitFactCounts summarizes stored git fact rows for a repo.

type LinkRow

type LinkRow struct {
	ID         string
	ArtifactID string
	LinkType   string
	Target     string
	CreatedAt  string
}

LinkRow represents a row from the links table.

type RepoMeta

type RepoMeta struct {
	ID             string
	RootPath       string
	LastScanCommit string
	LastScanAt     string
	ScannedBy      string
}

RepoMeta holds freshness metadata for a repository.

type ResumeRow

type ResumeRow struct {
	ID             string
	ShortID        string
	Kind           string
	Subtype        string
	Title          string
	Status         string
	AuthoredAt     string
	UpdatedAt      string
	LastObservedAt string
	SourcePath     string
	TotalTodos     int
	OpenTodos      int
	TagsJoined     string // comma-separated from SQL GROUP_CONCAT
}

ResumeRow holds the data needed for ds resume display.

type RevisionRow

type RevisionRow struct {
	ID            string
	ArtifactID    string
	ContentHash   string
	Body          string
	ExtractedJSON string
	ObservedAt    string
}

RevisionRow represents a row from the artifact_revisions table.

type SectionRow added in v0.1.0

type SectionRow struct {
	ID            string
	ArtifactID    string
	RevisionID    string
	SourcePath    string
	HeadingPath   string
	HeadingDepth  int
	StartLine     int
	EndLine       int
	Title         string
	Body          string
	TokenEstimate int
	SectionKind   string
	MetadataJSON  string
}

SectionRow represents a persisted section extracted from an artifact revision.

type SourceManifestCounts added in v1.0.0

type SourceManifestCounts struct {
	Files   int `json:"files"`
	Tests   int `json:"tests"`
	Symbols int `json:"symbols"`
	Imports int `json:"imports"`
	FTSRows int `json:"fts_rows"`
}

SourceManifestCounts summarizes compact manifest rows for diagnostics/tests.

type SourceManifestFTSInput added in v1.0.0

type SourceManifestFTSInput struct {
	FileID     string
	Path       string
	PathTerms  string
	SourceRoot string
	Language   string
	SourceRole string
	Symbols    string
	TestNames  string
	Imports    string
}

SourceManifestFTSInput is one searchable metadata row for source manifest FTS.

type SourceManifestFileInput added in v1.0.0

type SourceManifestFileInput struct {
	FileID          string
	RepoID          string
	Path            string
	ContentHash     string
	SizeBytes       int64
	Language        string
	SourceRoot      string
	SourceRootKind  string
	SourceRole      string
	FirstPartyScore float64
	IgnoredReason   string
}

SourceManifestFileInput is a compact first-party source/test file row.

type SourceManifestImportInput added in v1.0.0

type SourceManifestImportInput struct {
	FileID    string
	ImportRef string
	Line      int
}

SourceManifestImportInput is one import-ish reference for a source manifest file.

type SourceManifestSearchRow added in v1.0.0

type SourceManifestSearchRow struct {
	FileID          string
	RepoID          string
	Path            string
	ContentHash     string
	SizeBytes       int64
	Language        string
	SourceRoot      string
	SourceRootKind  string
	SourceRole      string
	FirstPartyScore float64
	IndexedAt       string
	Symbols         string
	TestNames       string
	Imports         string
	Rank            float64
}

SourceManifestSearchRow is a compact source/test row returned from manifest FTS.

type SourceManifestSymbolInput added in v1.0.0

type SourceManifestSymbolInput struct {
	FileID string
	Symbol string
	Kind   string
	Line   int
}

SourceManifestSymbolInput is one extracted symbol for a source manifest file.

type SourceManifestTestInput added in v1.0.0

type SourceManifestTestInput struct {
	FileID   string
	TestName string
	Parent   string
	Line     int
}

SourceManifestTestInput is one extracted test name for a source manifest file.

type SourceRow

type SourceRow struct {
	ID             string
	ArtifactID     string
	SourceType     string
	Path           string
	SourceIdentity string
	FormatProfile  string
	LayoutGroup    string
}

SourceRow represents a row from the sources table.

type TagRow

type TagRow struct {
	ArtifactID string
	Tag        string
	Source     string
	CreatedAt  string
}

TagRow represents a row from the artifact_tags table.

type TaskCheckpointFact added in v1.0.0

type TaskCheckpointFact struct {
	RepoID             string
	TaskID             string
	CheckpointID       string
	Target             string
	Series             string
	Stage              string
	Decision           string
	CheckpointPath     string
	CheckpointJSONPath string
	CreatedAt          string
	ActualContextJSON  string
	FeedbackJSON       string
	EvidenceJSON       string
	LearningsJSON      string
	NextJSON           string
	IndexedAt          string
}

TaskCheckpointFact is the compact query-facing record for a task checkpoint.

type TodoRow

type TodoRow struct {
	ID              string
	ArtifactID      string
	RevisionID      string
	Ordinal         int
	Text            string
	Done            bool
	SourceFile      string
	SourceLine      int
	ArtifactTitle   string
	ArtifactKind    string
	ArtifactShortID string
}

TodoRow represents a row from the artifact_todos table.

Jump to

Keyboard shortcuts

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