Documentation
¶
Overview ¶
Package docs implements the `volcano docs` subsystem: fetching Volcano documentation from a configurable GitHub source into a local cache and searching it with a small, dependency-free BM25 index. It is designed primarily for AI agents that need to look up or validate facts against the official docs, with machine-readable (JSON) output as a first-class concern.
Index ¶
- Constants
- Variables
- func CacheDir(override string, src SourceRef) (string, error)
- func Code(err error) string
- type Cache
- type CacheState
- type FileEntry
- type GetResult
- type HTTPDoer
- type Index
- type ListItem
- type Manifest
- type Options
- type Overrides
- type Result
- type Section
- type Service
- func (s *Service) CacheState(offline bool) CacheState
- func (s *Service) Get(ctx context.Context, id string, offline bool) (*GetResult, error)
- func (s *Service) List(ctx context.Context, topic string, offline bool) ([]ListItem, error)
- func (s *Service) ResolvedCommit() string
- func (s *Service) Search(ctx context.Context, query, topic string, limit int, offline bool) ([]Result, error)
- func (s *Service) Source() SourceRef
- func (s *Service) Sync(ctx context.Context, force bool) (*SyncResult, error)
- type SourceRef
- type SyncResult
- type Syncer
Constants ¶
const ( EnvRepo = "VOLCANO_DOCS_REPO" EnvRef = "VOLCANO_DOCS_REF" EnvPath = "VOLCANO_DOCS_PATH" )
Environment overrides for the documentation source.
const ManifestSchemaVersion = 1
ManifestSchemaVersion versions the on-disk manifest format.
const Provider = "github"
Provider identifies the backing documentation host. Only GitHub is supported today; the field keeps the cache key and JSON envelope forward compatible if another provider is ever added.
const StaleAfter = 7 * 24 * time.Hour
StaleAfter is how long a cache is served before it is reported stale. Reads never refresh automatically; staleness is informational only.
Variables ¶
var ( // ErrCacheMissing indicates no cache snapshot exists yet (and, for reads, // --offline prevented a bootstrap sync). ErrCacheMissing = errors.New("docs cache is empty; run `volcano docs sync`") // returned an error while syncing. ErrSourceUnavailable = errors.New("docs source unavailable") // ErrInvalidSource indicates a malformed repo/ref/path. ErrInvalidSource = errors.New("invalid docs source") // ErrDocNotFound indicates a requested document/section does not exist. ErrDocNotFound = errors.New("doc not found") // ErrInvalidID indicates a malformed document id/path. ErrInvalidID = errors.New("invalid doc id") // ErrSyncIncomplete indicates a sync failed partway and left the previous // cache untouched. ErrSyncIncomplete = errors.New("docs sync incomplete") // ErrOfflineConflict indicates a network-requiring operation (e.g. `sync`) // was invoked with --offline, which is an invalid flag combination rather // than a source failure. ErrOfflineConflict = errors.New("operation requires network access but --offline was set") )
Sentinel errors carry stable machine codes for the JSON envelope. Each maps to a DOCS_* code in the command layer.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache manages snapshot directories and the current pointer for one source.
type CacheState ¶
type CacheState struct {
Key string `json:"key"`
SyncedAt *time.Time `json:"synced_at"`
CheckedAt *time.Time `json:"checked_at"`
Stale bool `json:"stale"`
Offline bool `json:"offline"`
}
CacheState reports the current cache metadata for the JSON envelope.
type FileEntry ¶
type FileEntry struct {
Path string `json:"path"`
SHA string `json:"sha"`
Size int64 `json:"size"`
}
FileEntry records one cached document and its GitHub blob SHA so a later sync can reuse unchanged files without re-downloading them.
type GetResult ¶
type GetResult struct {
ID string `json:"id"`
Path string `json:"path"`
Topic string `json:"topic"`
Title string `json:"title"`
Anchor string `json:"anchor,omitempty"`
HeadingPath []string `json:"heading_path,omitempty"`
LineStart int `json:"line_start,omitempty"`
LineEnd int `json:"line_end,omitempty"`
Content string `json:"content"`
}
GetResult is the payload for `docs get`.
type HTTPDoer ¶
HTTPDoer is the minimal HTTP contract used by sync, satisfied by *http.Client and the runtime's injected client.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is an in-memory BM25 index built per invocation. No index is persisted; the corpus is small enough to rebuild on each search.
type ListItem ¶
type ListItem struct {
Path string `json:"path"`
Topic string `json:"topic"`
Title string `json:"title"`
}
ListItem is one document entry for `docs list`.
type Manifest ¶
type Manifest struct {
SchemaVersion int `json:"schema_version"`
Provider string `json:"provider"`
Source SourceRef `json:"source"`
ResolvedCommit string `json:"resolved_commit"`
Files []FileEntry `json:"files"`
SyncedAt time.Time `json:"synced_at"`
CheckedAt time.Time `json:"checked_at"`
}
Manifest describes a published cache snapshot.
type Options ¶
type Options struct {
Overrides Overrides
Config *config.Config
HTTPClient HTTPDoer
CacheDir string
GitHubAPIURL string
RawBaseURL string
Token string
Now func() time.Time
Env func(string) (string, bool)
}
Options configures a Service. The command layer builds this from cliruntime.Deps, the loaded config, and --repo/--ref/--path flags.
type Overrides ¶
Overrides carries explicit per-invocation source overrides, typically from --repo/--ref/--path flags. Empty fields are treated as "not set".
type Result ¶
type Result struct {
ID string `json:"id"`
Rank int `json:"rank"`
Score float64 `json:"score"`
Path string `json:"path"`
Topic string `json:"topic"`
Title string `json:"title"`
HeadingPath []string `json:"heading_path"`
Anchor string `json:"anchor"`
LineStart int `json:"line_start"`
LineEnd int `json:"line_end"`
Snippet string `json:"snippet"`
MatchedTerms []string `json:"matched_terms"`
}
Result is one ranked search hit, deduplicated to the section level.
type Section ¶
type Section struct {
DocPath string `json:"path"`
Topic string `json:"topic"`
Title string `json:"title"`
Heading string `json:"heading"`
HeadingPath []string `json:"heading_path"`
Anchor string `json:"anchor"`
Level int `json:"-"`
LineStart int `json:"line_start"`
LineEnd int `json:"line_end"`
Body string `json:"-"`
}
Section is a heading-delimited slice of a document. Sections are the unit of search and retrieval: each has a stable id (docPath#anchor), a heading breadcrumb for context, and source line bounds.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the entry point for docs operations, bundling a resolved source, its cache, and a syncer.
func NewService ¶
NewService resolves the documentation source and prepares the cache/syncer.
func (*Service) CacheState ¶
func (s *Service) CacheState(offline bool) CacheState
CacheState builds cache metadata; manifest may be nil when no cache exists.
func (*Service) Get ¶
Get retrieves a document by path, or a single section when the id carries a #anchor. A bare path returns the complete raw markdown document.
func (*Service) ResolvedCommit ¶
ResolvedCommit returns the live cache's pinned commit, or "".
func (*Service) Search ¶
func (s *Service) Search(ctx context.Context, query, topic string, limit int, offline bool) ([]Result, error)
Search bootstraps if needed then runs a BM25 query.
type SourceRef ¶
type SourceRef struct {
Repo string `json:"repository"`
Ref string `json:"ref"`
Path string `json:"path"`
}
SourceRef locates a documentation corpus: a GitHub owner/name repository, a ref (branch, tag, or commit), and the subdirectory the docs live under.
func DefaultSource ¶
func DefaultSource() SourceRef
DefaultSource returns the compiled-in default documentation source.
func ResolveSource ¶
ResolveSource applies the precedence flags > env (VOLCANO_DOCS_*) > config.DocsSource > compiled defaults, field by field. A missing value at one layer falls through to the next, so a user can override only the ref while inheriting the default repo and path.
func (SourceRef) CacheKey ¶
CacheKey derives a stable, filesystem-safe identifier for a source so that distinct repo/ref/path combinations never share a cache namespace.
type SyncResult ¶
type SyncResult struct {
ResolvedCommit string `json:"resolved_commit"`
Added int `json:"added"`
Updated int `json:"updated"`
Removed int `json:"removed"`
Unchanged int `json:"unchanged"`
Changed bool `json:"changed"`
}
SyncResult summarizes a completed synchronization.
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
Syncer fetches a documentation corpus from GitHub into a Cache.