docs

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound reports a docs resource that is permanently absent upstream — typically a Context7 library ID that resolves to a 404. It is detected in this package (never by string matching at the surfaces) so both the CLI and the MCP server classify it as not-found (exit 3 / [not_found]) rather than a retryable upstream failure.

View Source
var ErrUnknownBackend = errors.New("unknown docs backend")

ErrUnknownBackend reports a backend name that is not a known docs backend. Callers classify errors wrapping it as validation failures; any other NewFromConfig error is a missing precondition (API key, unimplemented backend).

Functions

This section is empty.

Types

type Context7

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

Context7 searches library documentation via the Context7 API.

func NewContext7

func NewContext7(apiKey string) *Context7

NewContext7 creates a new Context7 docs backend.

func (*Context7) GetDocs

func (c *Context7) GetDocs(ctx context.Context, libraryID, query string, tokens int) ([]Result, error)

GetDocs fetches documentation snippets for a resolved library ID.

func (*Context7) ResolveLibrary

func (c *Context7) ResolveLibrary(ctx context.Context, name string, limit int) ([]LibraryMatch, error)

ResolveLibrary searches Context7 for libraries matching the given name, returning at most limit matches (limit <= 0 means all). The Context7 search endpoint has no server-side limit parameter, so the bound is applied here — in the shared layer — so the CLI and MCP surfaces cannot diverge.

func (*Context7) Search

func (c *Context7) Search(ctx context.Context, query string, limit int) ([]Result, error)

Search resolves a library from the query and fetches documentation.

type FTS5Local

type FTS5Local struct{}

FTS5Local is a planned local SQLite FTS5 docs backend. Not yet implemented.

func NewFTS5Local

func NewFTS5Local() *FTS5Local

NewFTS5Local creates a new FTS5Local backend stub.

func (*FTS5Local) Search

func (f *FTS5Local) Search(_ context.Context, _ string, _ int) ([]Result, error)

Search returns an error because the local FTS5 backend is not yet implemented.

type LibraryMatch

type LibraryMatch struct {
	ID            string   `json:"id"`
	Title         string   `json:"title"`
	Description   string   `json:"description"`
	TotalSnippets int      `json:"totalSnippets"`
	TrustScore    float64  `json:"trustScore"`
	Versions      []string `json:"versions"`
}

LibraryMatch is a resolved library from Context7's search endpoint. Field names track the upstream schema: "title" (not "name"), "totalSnippets" (not "codeSnippets"), and "trustScore" (numeric, not the older string "trust").

type Result

type Result struct {
	Library    string `json:"library"`
	Version    string `json:"version,omitempty"`
	Title      string `json:"title"`
	Breadcrumb string `json:"breadcrumb,omitempty"`
	Snippet    string `json:"snippet"`
	URL        string `json:"url"`
	Source     string `json:"source"` // "context7" | "local"
}

Result is a single docs search result.

type Searcher

type Searcher interface {
	Search(ctx context.Context, query string, limit int) ([]Result, error)
}

Searcher is the interface for docs backends.

func NewFromConfig

func NewFromConfig(cfg *config.Config, backend string) (Searcher, error)

NewFromConfig builds the docs Searcher for backend, resolving API keys from cfg exactly as the `ketch docs` CLI does. Both the CLI and the MCP server call this — it is the single owner of the backend switch.

The "local" FTS5 backend is a stub whose Search always errors, so it is rejected here — at construction time — instead of failing on first use.

Jump to

Keyboard shortcuts

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