store

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CatAPIReference = "api-reference"
	CatTutorial     = "tutorial"
	CatGuide        = "guide"
	CatSpec         = "spec"
	CatChangelog    = "changelog"
	CatMarketing    = "marketing"
	CatLegal        = "legal"
	CatCommunity    = "community"
	CatContext7     = "context7"
	CatIndex        = "index"
	CatOther        = "other"
)

Content categories classify pages by their purpose, enabling agents to filter search results by task (e.g. coding agents want api-reference, not marketing).

Variables

This section is empty.

Functions

func ClassifyPath

func ClassifyPath(path string) string

ClassifyPath returns a content type string for a URL path.

Types

type Categorizer

type Categorizer interface {
	Categorize(domain, path, contentType, body string) string
}

Categorizer assigns semantic categories to indexed pages. Implementations can use path patterns, body analysis, ML models, etc.

type GitStore

type GitStore struct {
	// contains filtered or unexported fields
}

GitStore wraps git operations on the workspace repository.

func InitGit

func InitGit(root string) (*GitStore, error)

InitGit initializes or opens the git repository in the workspace root. On a fresh workspace it creates a seed commit so HEAD is valid immediately.

func (*GitStore) Commit

func (gs *GitStore) Commit(message string) (bool, error)

Commit stages all changes and creates a commit. Returns true if a commit was created, false if there was nothing to commit.

func (*GitStore) Diff

func (gs *GitStore) Diff(from, to string) (string, error)

Diff returns the diff between two refs (e.g., "HEAD~1", "HEAD"). If from is empty, defaults to the parent of to.

func (*GitStore) HasChanges

func (gs *GitStore) HasChanges() (bool, error)

HasChanges returns true if the worktree has uncommitted changes.

func (*GitStore) Log

func (gs *GitStore) Log(site string, limit int) ([]LogEntry, error)

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index manages the SQLite FTS5 search index.

func OpenIndex

func OpenIndex(rootDir string) (*Index, error)

OpenIndex opens or creates the search index database.

func (*Index) CategoryCounts

func (idx *Index) CategoryCounts(domain string) (map[string]int, error)

CategoryCounts returns category distribution for a domain.

func (*Index) Close

func (idx *Index) Close() error

Close closes the database connection.

func (*Index) DeleteSite

func (idx *Index) DeleteSite(domain string) error

DeleteSite removes all index entries for a domain.

func (*Index) GetCacheHeaders

func (idx *Index) GetCacheHeaders(domain, urlPath string) (etag, lastModified string, err error)

GetCacheHeaders returns the stored ETag and Last-Modified for a file.

func (*Index) GetCategory

func (idx *Index) GetCategory(domain, urlPath string) (string, error)

GetCategory returns the category for a specific file.

func (*Index) GetContentType

func (idx *Index) GetContentType(domain, urlPath string) (string, error)

GetContentType returns the content type for a specific file from the index.

func (*Index) GetSummary

func (idx *Index) GetSummary(domain, urlPath string) (summary, summaryAt string, err error)

GetSummary returns the agent-submitted summary for a file, if any.

func (*Index) IndexFile

func (idx *Index) IndexFile(domain, urlPath, contentType, body string, category ...string) error

IndexFile adds or updates a file in the search index. Category is derived automatically from path, content type, and body.

func (*Index) Rebuild

func (idx *Index) Rebuild(store *Store) error

Rebuild drops and recreates the FTS index from files on disk.

func (*Index) Search

func (idx *Index) Search(query string, opts SearchOpts) ([]SearchHit, error)

Search performs a full-text search across all indexed content. Path matches in the query are boosted: if a query term appears in the file path, that result ranks higher. This helps agents find e.g. "getting-started" docs when searching for "getting started".

func (*Index) SetCategory

func (idx *Index) SetCategory(domain, urlPath, category string) error

SetCategory overrides the category for a specific file (agent feedback). The override is marked as user-set so re-indexing preserves it.

func (*Index) SetSummary

func (idx *Index) SetSummary(domain, urlPath, summary string) error

SetSummary stores an agent-submitted summary for a file and re-indexes the FTS entry so the summary is searchable.

func (*Index) UpdateCacheHeaders

func (idx *Index) UpdateCacheHeaders(domain, urlPath, etag, lastModified string) error

UpdateCacheHeaders stores ETag and Last-Modified for a file.

type Indexer

type Indexer interface {
	IndexFile(domain, path, contentType, body string, category ...string) error
	Search(query string, opts SearchOpts) ([]SearchHit, error)
	DeleteSite(domain string) error
	Rebuild(store *Store) error
	GetCacheHeaders(domain, path string) (etag, lastModified string, err error)
	UpdateCacheHeaders(domain, path, etag, lastModified string) error
	GetCategory(domain, path string) (string, error)
	GetContentType(domain, path string) (string, error)
	SetCategory(domain, path, category string) error
	GetSummary(domain, path string) (summary, summaryAt string, err error)
	SetSummary(domain, path, summary string) error
	CategoryCounts(domain string) (map[string]int, error)
	Close() error
}

Indexer is the interface for full-text search backends. The default implementation uses SQLite FTS5. Alternative implementations could provide semantic/vector search or different storage engines.

type LogEntry

type LogEntry struct {
	Hash    string    `json:"hash"`
	Message string    `json:"message"`
	When    time.Time `json:"when"`
}

Log returns recent commit entries, optionally filtered to a site's path.

type RuleCategorizer

type RuleCategorizer struct{}

RuleCategorizer is the default implementation using path patterns and body heuristics.

func (*RuleCategorizer) Categorize

func (r *RuleCategorizer) Categorize(domain, path, contentType, body string) string

type SearchHit

type SearchHit struct {
	Domain      string  `json:"domain"`
	Path        string  `json:"path"`
	ContentType string  `json:"content_type"`
	Category    string  `json:"category"`
	Snippet     string  `json:"snippet"`
	Summary     string  `json:"summary,omitempty"`
	Rank        float64 `json:"rank"`
}

SearchHit represents a single search result.

type SearchOpts

type SearchOpts struct {
	Site        string // filter to a specific domain
	ContentType string // filter to a content type
	Category    string // filter to a category (e.g. "api-reference")
	Path        string // filter to paths containing this substring
	Limit       int
	Offset      int
}

SearchOpts controls search behavior.

type Store

type Store struct {
	Root string // Root directory of the doctrove workspace
}

Store manages the filesystem layout for mirrored content.

func New

func New(root string) *Store

New creates a Store rooted at the given directory.

func (*Store) EnsureSiteDir

func (s *Store) EnsureSiteDir(domain string) error

EnsureSiteDir creates the directory structure for a site.

func (*Store) ListSites

func (s *Store) ListSites() ([]string, error)

ListSites returns the domain names of all tracked sites.

func (*Store) MetaDir

func (s *Store) MetaDir(domain string) string

MetaDir returns the _meta directory for a site.

func (*Store) ReadContent

func (s *Store) ReadContent(domain, urlPath string) ([]byte, error)

ReadContent reads a file from a site's directory by its URL path. If the direct path is a directory (promoted via conflict resolution), it falls back to reading <path>/_index.

func (*Store) ReadMeta

func (s *Store) ReadMeta(domain, name string, v any) error

ReadMeta reads a JSON metadata file from the site's _meta directory.

func (*Store) SiteDir

func (s *Store) SiteDir(domain string) string

SiteDir returns the path for a specific site.

func (*Store) SiteFileCount

func (s *Store) SiteFileCount(domain string) (int, error)

SiteFileCount returns the number of content files (excluding _meta) for a site.

func (*Store) SitesDir

func (s *Store) SitesDir() string

SitesDir returns the path to the sites directory.

func (*Store) WriteContent

func (s *Store) WriteContent(domain, urlPath string, data []byte) (string, error)

WriteContent writes content to the appropriate path under a site's directory. urlPath is the path portion of the URL (e.g., "/llms.txt", "/docs/api.html.md").

If a path component already exists as a regular file (e.g., writing "/deploy/getting_started" when "/deploy" is a file), the conflicting file is promoted into a directory by renaming it to "<dir>/_index". This matches how web servers treat directory-index pages.

func (*Store) WriteMeta

func (s *Store) WriteMeta(domain, name string, v any) error

WriteMeta writes a JSON metadata file to the site's _meta directory.

type VersionStore

type VersionStore interface {
	Commit(message string) (bool, error)
	Log(site string, limit int) ([]LogEntry, error)
	Diff(from, to string) (string, error)
	HasChanges() (bool, error)
}

VersionStore provides git-based change tracking for mirrored content. The default implementation uses go-git. Alternative implementations could use shell git, a different VCS, or a no-op for environments without git.

Jump to

Keyboard shortcuts

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