Documentation
¶
Overview ¶
Package query implements graphmaster's code-graph tools (PLAN "MCP tool'ları") as a plain Go API, independent of MCP: find_symbol, search, repo_map, file_outline, read_symbol, callers, callees, impact, imports, inheritance, tests_for, traverse and status.
Every tool follows one output contract:
- the index is freshened first (Engine's Freshener) and the first line is the banner "graphmaster <tool> · <freshness>";
- the answer is plain text bounded by max_tokens (default 1500, cap 6000, estimated as bytes/4);
- symbols render as "<kind> <qname> <path>:<start>-<end> <sig>", the qname without prefixes the path already implies (sym.displayQName: "steer.F" for a Go import path, "User.role" for a TS file module);
- cut lists end with "… +N more (narrow path_prefix / raise limit)";
- edges below confidence 80 are marked with "~".
Symbol arguments accept a qualified name (or a dotted suffix of one), path:line, a bare name or a 16-digit skey; an ambiguous argument yields a numbered candidate list instead of an answer.
The MCP server and the `graphmaster query` CLI both drive the tools through Tools, so they print identical text.
Index ¶
- Constants
- Variables
- type Backend
- type CallsInput
- type Engine
- func (e *Engine) Callees(ctx context.Context, in CallsInput) (string, error)
- func (e *Engine) Callers(ctx context.Context, in CallsInput) (string, error)
- func (e *Engine) FileOutline(ctx context.Context, in FileOutlineInput) (string, error)
- func (e *Engine) FindSymbol(ctx context.Context, in FindSymbolInput) (string, error)
- func (e *Engine) Impact(ctx context.Context, in ImpactInput) (string, error)
- func (e *Engine) Imports(ctx context.Context, in ImportsInput) (string, error)
- func (e *Engine) Inheritance(ctx context.Context, in InheritanceInput) (string, error)
- func (e *Engine) ReadSymbol(ctx context.Context, in ReadSymbolInput) (string, error)
- func (e *Engine) RepoMap(ctx context.Context, in RepoMapInput) (string, error)
- func (e *Engine) Search(ctx context.Context, in SearchInput) (string, error)
- func (e *Engine) Status(ctx context.Context, in StatusInput) (string, error)
- func (e *Engine) TestsFor(ctx context.Context, in TestsForInput) (string, error)
- func (e *Engine) Traverse(ctx context.Context, in TraverseInput) (string, error)
- type FileOutlineInput
- type FindSymbolInput
- type Freshener
- type ImpactInput
- type ImportsInput
- type InheritanceInput
- type Options
- type ReadSymbolInput
- type RepoMapInput
- type SearchInput
- type StatusInput
- type TestsForInput
- type Tool
- type TraverseInput
Constants ¶
const ( DefaultMaxTokens = 1500 MaxTokensCap = 6000 )
Token budget (PLAN "MCP tool'ları"): output size is bounded by max_tokens, estimated as bytes/4.
const DefaultFreshenBudget = 20 * time.Second
DefaultFreshenBudget is how long a tool call waits for the write lock before answering from the current graph (PLAN: MCP 20s).
Variables ¶
var ErrInvalidArgument = errors.New("invalid argument")
ErrInvalidArgument marks errors caused by tool arguments rather than the index; callers can show them to the agent as a usage error.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// Store returns the current graph.db (it may change after Freshen).
Store() *store.Store
// Root locates the working tree (for reading sources and git state).
Root() *repo.Root
// Status summarizes the index for the status tool.
Status(ctx context.Context) (*index.Status, error)
}
Backend gives the tools access to the index. *index.Indexer implements it.
type CallsInput ¶
type CallsInput struct {
Symbol string `json:"symbol" jsonschema:"qname, path:line, bare name or skey"`
Depth int `json:"depth,omitempty" jsonschema:"levels to follow (default 1, max 5)"`
MinConfidence int `json:"min_confidence,omitempty" jsonschema:"minimum edge confidence 1-100 (default 50)"`
Limit int `json:"limit,omitempty" jsonschema:"maximum symbols (default 50)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
CallsInput are the callers and callees arguments.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs the query tools against one repository. Apart from a cache of the files table (invalidated by files_gen) it holds no state; it is safe for concurrent use.
func (*Engine) FileOutline ¶
FileOutline lists a file's definitions as a tree with line ranges and signatures.
func (*Engine) FindSymbol ¶
FindSymbol lists definitions by name: exact matches first, then prefix and fuzzy matches, exported definitions before private ones.
func (*Engine) Impact ¶
Impact lists what may break when a symbol, a file or the uncommitted changes are modified: the reverse transitive closure over dependency edges, grouped by file, with the number of affected tests.
func (*Engine) Imports ¶
Imports lists what a file or package imports (direction=out) or who imports it (direction=in).
func (*Engine) Inheritance ¶
Inheritance prints the type hierarchy around a type: supertypes (up), subtypes (down) or both.
func (*Engine) ReadSymbol ¶
ReadSymbol prints a definition's header row followed by its numbered source lines (plus optional context), read from the working tree.
func (*Engine) RepoMap ¶
RepoMap renders the directory / package tree below path_prefix with file counts, lines of code and the three most referenced exported top-level definitions of each directory (tests excluded). A directory whose subdirectories are listed shows only the symbols of its own files, so the same names are not repeated on every ancestor row.
func (*Engine) Search ¶
Search runs a full-text (token prefix) and trigram (substring) search over symbol names, plus a substring match over file paths.
func (*Engine) Status ¶
Status reports file states, languages, database size, last scan and the steering mode.
func (*Engine) TestsFor ¶
TestsFor lists test functions that reach a symbol within two hops of calls / test edges, plus tests whose name contains the symbol's name.
type FileOutlineInput ¶
type FileOutlineInput struct {
Path string `json:"path" jsonschema:"repo-relative file path"`
Depth int `json:"depth,omitempty" jsonschema:"nesting levels to show (default 2)"`
IncludePrivate *bool `json:"include_private,omitempty" jsonschema:"include non-exported definitions (default true)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
FileOutlineInput are the file_outline arguments.
type FindSymbolInput ¶
type FindSymbolInput struct {
Query string `json:"query" jsonschema:"symbol name, qualified name, prefix or substring"`
Kind string `json:"kind,omitempty" jsonschema:"only this definition kind (function, method, class, struct, interface, ...)"`
Lang string `json:"lang,omitempty" jsonschema:"only this language (go, python, typescript, ...)"`
PathPrefix string `json:"path_prefix,omitempty" jsonschema:"only files whose repo-relative path starts with this"`
Exact bool `json:"exact,omitempty" jsonschema:"exact name match only"`
Limit int `json:"limit,omitempty" jsonschema:"maximum results (default 20)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
FindSymbolInput are the find_symbol arguments.
type Freshener ¶
type Freshener interface {
Freshen(ctx context.Context, budget time.Duration) (*index.Result, error)
}
Freshener brings the index up to date before a tool answers. *index.Indexer implements it; tests inject a fixed result.
type ImpactInput ¶
type ImpactInput struct {
Symbol string `json:"symbol,omitempty" jsonschema:"qname, path:line, bare name or skey"`
Path string `json:"path,omitempty" jsonschema:"repo-relative file path"`
Changed bool `json:"changed,omitempty" jsonschema:"start from files changed against HEAD / the git index"`
Depth int `json:"depth,omitempty" jsonschema:"levels to follow (default 3, max 6)"`
MinConfidence int `json:"min_confidence,omitempty" jsonschema:"minimum edge confidence 1-100 (default 30)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
ImpactInput are the impact arguments; exactly one of Symbol, Path and Changed selects the starting set.
type ImportsInput ¶
type ImportsInput struct {
Path string `json:"path,omitempty" jsonschema:"repo-relative file path (or package directory)"`
Module string `json:"module,omitempty" jsonschema:"package / module name or import spec"`
Direction string `json:"direction,omitempty" jsonschema:"out (what it imports, default) or in (who imports it)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
ImportsInput are the imports arguments.
type InheritanceInput ¶
type InheritanceInput struct {
Symbol string `json:"symbol" jsonschema:"qname, path:line, bare name or skey of a type"`
Direction string `json:"direction,omitempty" jsonschema:"up (supertypes), down (subtypes) or both (default)"`
Depth int `json:"depth,omitempty" jsonschema:"levels to follow (default 3)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
InheritanceInput are the inheritance arguments.
type Options ¶
type Options struct {
// Freshener runs before every tool. Nil uses the backend when it
// implements Freshener, otherwise tools answer without freshening.
Freshener Freshener
// FreshenBudget bounds the wait for the write lock (default: the
// backend's timeouts.mcp when it exposes its config, else 20s).
FreshenBudget time.Duration
// NoGit reports that the backend indexes a directory outside git, so
// impact changed=true has nothing to compare against.
NoGit bool
}
Options configure an Engine.
type ReadSymbolInput ¶
type ReadSymbolInput struct {
Symbol string `json:"symbol" jsonschema:"qname, path:line, bare name or skey"`
ContextLines int `json:"context_lines,omitempty" jsonschema:"extra lines before and after (default 0)"`
MaxLines int `json:"max_lines,omitempty" jsonschema:"maximum source lines (default 200)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
ReadSymbolInput are the read_symbol arguments.
type RepoMapInput ¶
type RepoMapInput struct {
PathPrefix string `json:"path_prefix,omitempty" jsonschema:"directory to map (default: repository root)"`
Depth int `json:"depth,omitempty" jsonschema:"directory levels to show (default 2)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
RepoMapInput are the repo_map arguments.
type SearchInput ¶
type SearchInput struct {
Query string `json:"query" jsonschema:"words or identifier fragments to search in symbol and file names"`
Kinds []string `json:"kinds,omitempty" jsonschema:"restrict to these definition kinds; include \"file\" for file names"`
PathPrefix string `json:"path_prefix,omitempty" jsonschema:"only files whose repo-relative path starts with this"`
Limit int `json:"limit,omitempty" jsonschema:"maximum results (default 30)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
SearchInput are the search arguments.
type StatusInput ¶
type StatusInput struct {
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
StatusInput are the status arguments.
type TestsForInput ¶
type TestsForInput struct {
Symbol string `json:"symbol" jsonschema:"qname, path:line, bare name or skey"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
TestsForInput are the tests_for arguments.
type Tool ¶
type Tool struct {
// Name is the MCP tool name, e.g. "find_symbol".
Name string
// Description is shown to agents and in CLI help.
Description string
// Primary is the json name of the argument the CLI takes positionally
// ("" when the tool has none).
Primary string
// NewInput returns a pointer to a zero input struct (e.g.
// *FindSymbolInput) to decode arguments into.
NewInput func() any
// Run executes the tool with an input created by NewInput.
Run func(ctx context.Context, e *Engine, in any) (string, error)
}
Tool describes one query tool for the MCP server and the CLI.
type TraverseInput ¶
type TraverseInput struct {
Start string `json:"start" jsonschema:"qname, path:line, bare name or skey"`
EdgeKinds []string `` /* 136-byte string literal not displayed */
Direction string `json:"direction,omitempty" jsonschema:"out (default), in or both"`
MaxDepth int `json:"max_depth,omitempty" jsonschema:"levels to follow (default 4, max 8)"`
MinConfidence int `json:"min_confidence,omitempty" jsonschema:"minimum edge confidence 1-100 (default 50)"`
MaxTokens int `json:"max_tokens,omitempty" jsonschema:"output budget in tokens (default 1500, max 6000)"`
}
TraverseInput are the traverse arguments.