Documentation
¶
Index ¶
- Variables
- func CalculateTokenBudget(libCount int) int
- func DetectFromGoMod(path string) ([]string, error)
- func DetectFromPackageJSON(path string) ([]string, error)
- func DetectFromPyProjectToml(path string) ([]string, error)
- func DetectFromText(lang string, text string) []string
- func FilterStdLib(lang string, libs []string) []string
- func FormatPromptInjection(results []*DocResult) (string, error)
- type Cache
- type CacheEntry
- type Context7Client
- type DocContent
- type DocFetcher
- type DocResult
- type Fetcher
- type FetcherCache
- type LibraryInfo
- type ListEntry
- type Scraper
- type ScraperOption
Constants ¶
This section is empty.
Variables ¶
var ErrLibraryNotFound = errors.New("library not found")
ErrLibraryNotFound is returned when a library cannot be resolved.
var ErrQuotaExceeded = errors.New("quota exceeded")
ErrQuotaExceeded is returned when the upstream documentation source reports quota exhaustion.
var ErrRateLimited = errors.New("rate limited")
ErrRateLimited is returned when the upstream documentation source rejects requests due to rate limits.
Functions ¶
func CalculateTokenBudget ¶
CalculateTokenBudget returns the per-library token budget based on the number of libraries. Adaptive schedule: 1→5000, 2→3000, 3→2500, 4-5→2000. Hard cap: total ≤ 10000.
func DetectFromGoMod ¶
DetectFromGoMod parses a go.mod file and returns each direct dependency module path as-is (e.g., "github.com/spf13/cobra"). Indirect dependencies (lines with "// indirect") are skipped.
func DetectFromPackageJSON ¶
DetectFromPackageJSON parses a package.json file and returns all dependency and devDependency package names.
func DetectFromPyProjectToml ¶
DetectFromPyProjectToml parses a pyproject.toml file and returns dependency names, stripping version specifiers and extras (e.g., "fastapi[all]>=0.100.0" → "fastapi").
func DetectFromText ¶
DetectFromText scans free-form text (e.g., SPEC or plan.md) and returns known library names for the given language, excluding standard library modules.
func FilterStdLib ¶
FilterStdLib removes standard library module names from the input slice for the given language ("go", "node", "python").
func FormatPromptInjection ¶
FormatPromptInjection formats documentation results as a prompt injection section. Returns an error if results is nil or empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores documentation entries on disk as JSON files with TTL support.
func (*Cache) Get ¶
func (c *Cache) Get(key string) (*CacheEntry, error)
Get reads the cached entry for key. Returns nil if not found or expired.
type CacheEntry ¶
type CacheEntry struct {
LibraryID string // e.g., "/spf13/cobra"
Topic string // e.g., "commands"
Version string // resolved library version, when available
SourceRef string // library ID or official URL used as evidence
Content string // documentation content
Tokens int // approximate token count
CachedAt time.Time // when the entry was cached (for TTL)
}
CacheEntry represents a cached documentation entry on disk.
type Context7Client ¶
type Context7Client struct {
// contains filtered or unexported fields
}
Context7Client fetches documentation from the Context7 API.
func NewContext7Client ¶
func NewContext7Client(baseURL string) *Context7Client
NewContext7Client creates a new Context7Client with the given base URL. If baseURL is empty, the default Context7 API URL is used.
func (*Context7Client) Fetch ¶
func (c *Context7Client) Fetch(library, topic string) (*DocResult, error)
Fetch implements the DocFetcher interface. It resolves the library name then fetches documentation for the given topic, returning a DocResult.
func (*Context7Client) GetDocs ¶
func (c *Context7Client) GetDocs(libraryID, topic string) (*DocContent, error)
GetDocs fetches documentation for a library ID and topic from the Context7 API. Returns an error for any non-200 response.
func (*Context7Client) ResolveLibrary ¶
func (c *Context7Client) ResolveLibrary(name string) (*LibraryInfo, error)
ResolveLibrary resolves a library name to a LibraryInfo using the Context7 API. Returns ErrLibraryNotFound if the library cannot be found (HTTP 404).
type DocContent ¶
DocContent is the result of fetching docs for a library.
type DocFetcher ¶
DocFetcher is the interface for documentation sources (Context7, Scraper).
type DocResult ¶
type DocResult struct {
LibraryName string // e.g., "cobra"
Package string // e.g., "github.com/spf13/cobra"
Source string // "context7", "scraper", or "cache"
Version string // resolved library version, when the upstream source reports it
SourceRef string // library ID or official URL used as evidence
CheckedAt time.Time
Content string // documentation text content
Tokens int // approximate token count
}
DocResult represents a fetched documentation result.
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher orchestrates documentation retrieval with a fallback chain: Context7 → Scraper → Cache.
func NewFetcher ¶
func NewFetcher(c7 DocFetcher, scraper DocFetcher, cache FetcherCache) *Fetcher
NewFetcher creates a Fetcher with the given Context7 client, scraper, and cache.
type FetcherCache ¶
type FetcherCache interface {
Get(key string) (*DocResult, error)
Set(key string, result *DocResult) error
}
FetcherCache is the interface for the cache used by Fetcher.
type LibraryInfo ¶
type LibraryInfo struct {
ID string // Context7 library ID
Name string // library name
Version string // version string
}
LibraryInfo is the result of resolving a library name.
type ListEntry ¶
type ListEntry struct {
Key string // cache key e.g. "cobra:commands"
ExpiresAt time.Time // when the entry expires
}
ListEntry represents a cache list item.
type Scraper ¶
type Scraper struct {
// contains filtered or unexported fields
}
Scraper fetches documentation from public package registries.
func NewScraper ¶
func NewScraper(opts ...ScraperOption) *Scraper
NewScraper creates a Scraper with default settings, applying any provided options.
func (*Scraper) Fetch ¶
Fetch implements DocFetcher. It auto-detects the language/registry from the library name. Libraries with "/" or starting with "github.com" are treated as Go packages. Libraries with no "/" and no "." are treated as npm packages. Otherwise, PyPI is tried.
func (*Scraper) FetchGoDocs ¶
FetchGoDocs fetches Go package documentation from pkg.go.dev. It extracts text from the <section id="pkg-overview"> element.
func (*Scraper) FetchNpmDocs ¶
FetchNpmDocs fetches npm package documentation from the registry JSON API. It uses the readme field, falling back to description if readme is empty.
type ScraperOption ¶
type ScraperOption func(*Scraper)
ScraperOption configures a Scraper instance.
func WithGoDocsBaseURL ¶
func WithGoDocsBaseURL(url string) ScraperOption
WithGoDocsBaseURL overrides the pkg.go.dev base URL (useful for tests).
func WithGoProxyBaseURL ¶ added in v0.46.0
func WithGoProxyBaseURL(url string) ScraperOption
WithGoProxyBaseURL overrides the Go module proxy base URL (useful for tests).
func WithNpmRegistryURL ¶
func WithNpmRegistryURL(url string) ScraperOption
WithNpmRegistryURL overrides the npm registry base URL (useful for tests).
func WithPyPIBaseURL ¶
func WithPyPIBaseURL(url string) ScraperOption
WithPyPIBaseURL overrides the PyPI base URL (useful for tests).