code

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: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRegexpUnsupported = errors.New("regular expression search not supported by this backend")

ErrRegexpUnsupported is returned by a backend that was asked for a regular expression search it cannot perform. The CLI maps this to a precondition error so the user can pick a different backend.

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

ErrUnknownBackend reports a backend name that is not a known code search backend. Callers classify errors wrapping it as validation failures; any other NewFromConfig error is a missing precondition (e.g. token).

Functions

This section is empty.

Types

type GitHub

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

GitHub searches code via the GitHub Code Search REST API.

func NewGitHub

func NewGitHub(token string) *GitHub

NewGitHub creates a new GitHub code search backend.

func (*GitHub) Search

func (g *GitHub) Search(ctx context.Context, q Query) ([]Result, error)

Search queries GitHub Code Search and returns up to q.Limit results. GitHub's /search/code REST API does not support regular expressions (only literal terms plus qualifiers), so regex requests are rejected.

type GrepApp

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

GrepApp searches code via the Grep MCP server (mcp.grep.app). Unlike Sourcegraph/GitHub it needs no token, but it searches literal code patterns (grep-style) rather than keywords.

func NewGrepApp

func NewGrepApp() *GrepApp

func (*GrepApp) Search

func (g *GrepApp) Search(ctx context.Context, q Query) ([]Result, error)

Search queries the Grep MCP server and returns up to q.Limit code results.

type Query

type Query struct {
	Term   string // the search string (literal, or a regex when Regexp is set)
	Lang   string // language filter ("" = any)
	Limit  int    // max results
	Regexp bool   // interpret Term as a regular expression
}

Query describes a code search request. Required fields are Term and Limit; the rest are optional refinements. Backends that do not support a given option should ignore it or, where it would silently change semantics (e.g. Regexp), return ErrRegexpUnsupported.

type Result

type Result struct {
	Repo     string `json:"repo"`
	Path     string `json:"path"`
	Line     int    `json:"line,omitempty"`
	Snippet  string `json:"snippet"`
	Language string `json:"language,omitempty"`
	Stars    int    `json:"stars,omitempty"`
	URL      string `json:"url"`
	Source   string `json:"source"` // "sourcegraph" | "grepapp" | "github"
}

Result is a single code search result.

type Searcher

type Searcher interface {
	Search(ctx context.Context, q Query) ([]Result, error)
}

Searcher is the interface for code search backends. Each backend owns its own query dialect — language filtering and safety qualifiers (archived/fork exclusion) are applied internally so that callers pass plain user input.

func NewFromConfig

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

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

type Sourcegraph

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

Sourcegraph searches code via the Sourcegraph streaming search API.

func NewSourcegraph

func NewSourcegraph(baseURL string) *Sourcegraph

func (*Sourcegraph) Search

func (s *Sourcegraph) Search(ctx context.Context, q Query) ([]Result, error)

Search queries Sourcegraph and returns up to q.Limit code results. Sourcegraph defaults to literal matching; regex is requested via the patterntype:regexp qualifier.

Jump to

Keyboard shortcuts

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