feat(docs): add volcano docs documentation search subsystem#54
Open
tkkhq wants to merge 4 commits into
Open
Conversation
…and JSON envelope
There was a problem hiding this comment.
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.
| // 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 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 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 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) |
| // 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) |
| } | ||
|
|
||
| var ( | ||
| atxHeading = regexp.MustCompile(`^(#{1,6})\s+(.+?)\s*#*\s*$`) |
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 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 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 on lines
+319
to
+321
| start := max(pos-snippetChars/3, 0) | ||
| end := min(start+snippetChars, len(flat)) | ||
| out := flat[start:end] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
volcano docscommand 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/docsonmain), 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--jsonoutput is a first-class, versioned contract for agents.Commands
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 intoroot.go.config.DocsSourcepersistence andruntime.Depstest seams (DocsCacheDir,DocsGitHubAPIURL,DocsRawBaseURL,Now).Source precedence: flags →
VOLCANO_DOCS_{REPO,REF,PATH}→config.DocsSource→ compiled defaults. Each source is cached separately underos.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 thanraw.githubusercontent.com.GITHUB_TOKENis sent only toapi.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
searchinvocation (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.Kong/volcano-hosting: synced 96 docs, ranked search + section-levelget+ offline reads all working.Docs
Adds
docs/docs-search.mdand a README link.