Skip to content

feat(docs): add volcano docs documentation search subsystem#54

Open
tkkhq wants to merge 4 commits into
mainfrom
feat/docs-search
Open

feat(docs): add volcano docs documentation search subsystem#54
tkkhq wants to merge 4 commits into
mainfrom
feat/docs-search

Conversation

@tkkhq

@tkkhq tkkhq commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a volcano docs command group so the CLI — and primarily the AI agent driving it — can search and read the official Volcano documentation on demand, looking things up when it needs more context or wants to validate assumptions against the docs.

Docs are pulled from a configurable GitHub source (default: Kong/volcano-hosting /docs on main), cached locally, and searched with a small, dependency-free in-house BM25 index. Inspired by tobi/qmd but intentionally lightweight and Volcano-specific (no vector DB / LLM reranking / sqlite / CGO). Machine-readable --json output is a first-class, versioned contract for agents.

Commands

volcano docs sync                                   # fetch/refresh local cache
volcano docs search "reset password email"          # ranked BM25 search + snippets
volcano docs search "service key" --topic authentication -n 5
volcano docs get authentication/password-reset.md   # read a whole doc
volcano docs get "authentication/password-reset.md#how-it-works"  # read one section
volcano docs list --topic storage

Group flags: --json, --offline, --repo, --ref, --path. Reads bootstrap the cache once unless --offline; they never touch the network when a cache exists, and mark the cache stale after 7 days while still serving it.

Design

  • internal/docs — source resolution/precedence, transactional cache (atomic snapshot publish + manifest), GitHub sync (commit-pinned, blob-SHA reuse, truncated-tree fallback to contents walk, bounded-concurrency downloads, path/size limits), fence-aware markdown section parser (GitHub anchors, breadcrumbs, line ranges), in-memory BM25 with title/heading/path/phrase/technical-token boosts.
  • internal/cmd/docs — cobra command group + versioned JSON envelope (schema_version=1, source/cache/data|error, DOCS_* error codes, stdout JSON-only + nonzero exit on error), wired into root.go.
  • Config/runtime seamsconfig.DocsSource persistence and runtime.Deps test seams (DocsCacheDir, DocsGitHubAPIURL, DocsRawBaseURL, Now).

Source precedence: flags → VOLCANO_DOCS_{REPO,REF,PATH}config.DocsSource → compiled defaults. Each source is cached separately under os.UserCacheDir()/volcano/docs/v1/<sha256 key>.

Note on private repos

The docs repo is currently private, so downloads default to the authenticated GitHub contents API (Accept: application/vnd.github.raw) rather than raw.githubusercontent.com. GITHUB_TOKEN is sent only to api.github.com, never to raw/injected hosts. The raw-host path remains as an optional override for public sources/tests.

Indexing tradeoff

The BM25 index is built in memory per search invocation (no persisted index). Since each command is a one-shot process, subsequent searches rebuild it from the on-disk cache — ~70 ms warm for the current ~800 KB / 96-file corpus (~6.7 MB in memory), so persisting it isn't worth the added format/versioning/invalidation complexity. If the corpus grows substantially or we add a long-lived server/MCP mode, the index would simply stay resident across requests.

Testing

  • go test ./... — all packages pass (httptest-backed coverage for SHA reuse, deletion, truncation fallback, partial-failure cache preservation, offline behavior, staleness, JSON success/error contracts; plus parser and BM25 ranking unit tests).
  • make lint — 0 issues.
  • Live validated against Kong/volcano-hosting: synced 96 docs, ranked search + section-level get + offline reads all working.

Docs

Adds docs/docs-search.md and a README link.

@tkkhq tkkhq requested a review from a team as a code owner July 14, 2026 04:59
Copilot AI review requested due to automatic review settings July 14, 2026 04:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a configurable volcano docs subsystem for caching, searching, listing, and reading Volcano documentation.

Changes:

  • Adds transactional GitHub-backed documentation synchronization and caching.
  • Implements Markdown parsing and BM25 section search.
  • Adds Cobra commands, versioned JSON output, tests, and user documentation.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
README.md Links the documentation search guide.
docs/docs-search.md Documents commands, JSON output, and configuration.
internal/runtime/runtime.go Adds docs-specific runtime seams.
internal/config/config.go Adds persisted docs source configuration.
internal/docs/cache.go Implements snapshot-based cache storage.
internal/docs/errors.go Defines docs errors and machine codes.
internal/docs/parse.go Parses Markdown into searchable sections.
internal/docs/parse_test.go Tests section parsing and anchors.
internal/docs/search.go Implements BM25 indexing and snippets.
internal/docs/search_test.go Tests ranking, filtering, and tokens.
internal/docs/service.go Coordinates cache, search, list, and retrieval.
internal/docs/source.go Resolves and validates documentation sources.
internal/docs/source_test.go Tests source precedence and validation.
internal/docs/sync.go Synchronizes GitHub documents into snapshots.
internal/docs/sync_test.go Tests synchronization and cache behavior.
internal/cmd/docs/docs.go Defines the command group and JSON envelope.
internal/cmd/docs/subcommands.go Implements docs subcommands and rendering.
internal/cmd/docs/docs_test.go Tests command and JSON contracts.
internal/cmd/root/root.go Registers the docs command.
internal/cmd/root/root_test.go Verifies docs appears in root help.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/docs/sync.go
// Partition into reuse (unchanged SHA) and download sets.
var toDownload []blob
for _, b := range blobs {
if oldSHA, ok := prevSHA[b.Rel]; ok && oldSHA == b.SHA && prevSnap != "" {
Comment thread internal/docs/errors.go
Comment on lines +27 to +39
switch {
case errors.Is(err, ErrCacheMissing):
return "DOCS_CACHE_MISSING"
case errors.Is(err, ErrSourceUnavailable):
return "DOCS_SOURCE_UNAVAILABLE"
case errors.Is(err, ErrInvalidSource):
return "DOCS_INVALID_SOURCE"
case errors.Is(err, ErrDocNotFound):
return "DOCS_NOT_FOUND"
case errors.Is(err, ErrInvalidID):
return "DOCS_INVALID_ID"
case errors.Is(err, ErrSyncIncomplete):
return "DOCS_SYNC_INCOMPLETE"
Comment thread internal/docs/parse.go
Comment on lines +74 to +76
flush := func(endLine, bodyEnd int) {
body := strings.TrimRight(strings.Join(lines[cur.bodyStart:bodyEnd], "\n"), "\n")
sections = append(sections, Section{
Comment thread internal/docs/sync.go
Comment on lines +326 to +328
u = fmt.Sprintf("%s/%s/%s/%s", strings.TrimRight(s.rawURL, "/"), s.src.Repo, commit, full)
} else {
u = fmt.Sprintf("%s/repos/%s/contents/%s?ref=%s", s.apiURL, s.src.Repo, full, commit)
Comment thread internal/docs/sync.go
// walkContents recursively enumerates markdown blobs via the contents API,
// used when the recursive tree is truncated.
func (s *Syncer) walkContents(ctx context.Context, commit, repoPath string) ([]blob, error) {
u := fmt.Sprintf("%s/repos/%s/contents/%s?ref=%s", s.apiURL, s.src.Repo, repoPath, commit)
Comment thread internal/docs/parse.go
}

var (
atxHeading = regexp.MustCompile(`^(#{1,6})\s+(.+?)\s*#*\s*$`)
Comment thread internal/docs/parse.go
Comment on lines +92 to +99
tok := m[1][:3]
switch {
case !inFence:
inFence = true
fenceTok = tok
case inFence && strings.HasPrefix(strings.TrimSpace(line), fenceTok):
inFence = false
}
Comment thread internal/docs/parse.go
Comment on lines +158 to +163
tok := m[1][:3]
if !inFence {
inFence, fenceTok = true, tok
} else if strings.HasPrefix(strings.TrimSpace(line), fenceTok) {
inFence = false
}
Comment thread internal/docs/parse.go
Comment on lines +205 to +216
func uniqueAnchor(counts map[string]int, heading string) string {
base := slugify(heading)
if base == "" {
base = "section"
}
n := counts[base]
counts[base] = n + 1
if n == 0 {
return base
}
return base + "-" + itoa(n)
}
Comment thread internal/docs/search.go
Comment on lines +319 to +321
start := max(pos-snippetChars/3, 0)
end := min(start+snippetChars, len(flat))
out := flat[start:end]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants