Documentation
¶
Index ¶
- Constants
- Variables
- func EnsureCanonicalViews(db *sql.DB) error
- func FlattenAST(root *sitter.Node) []any
- func FlattenASTWithLanguage(root *sitter.Node, langName string) []any
- func GetGitHints() map[string]string
- func LoadFileIndex(dbPath string) (map[string]FileIndexEntry, error)
- func LoadGitCommits(repoPath string) ([]any, error)
- func LoadGitignore(rootDir string) *gitignoreMatcher
- func LoadIndexCoverage(dbPath string) (map[string][]CoverageEntry, error)
- func LoadSQLite(dbPath string) ([]any, error)
- func ParseSize(s string) (int64, error)
- func RegisterASTCallPatterns(langName string, patterns []CallPattern)
- func RegisterASTContextKinds(langName string, kinds []string)
- func RegisterAddressRefQuery(langName, scheme, query string)
- func RegisterContextQuery(langName, query string)
- func RegisterFileLevelRefQuery(langName, query string)
- func RegisterQualifiedCallQuery(langName, query string)
- func RegisterRefQuery(langName, query string)
- func RenderTemplate(tmpl string, values map[string]any) (string, error)
- func RenderTemplateWithFuncs(tmpl string, values map[string]any, extraFuncs template.FuncMap, ...) (string, error)
- func SchemaUsesTreeSitter(schema *api.Topology) bool
- func ShouldSkipDir(base string) bool
- func ShouldSkipFile(path string, size int64) bool
- func StreamSQLite(dbPath string, fn func(recordID string, record any) error) error
- func StreamSQLiteRaw(dbPath string, fn func(id, raw string) error) error
- type ASTRoot
- type ASTWalker
- func (w *ASTWalker) Close()
- func (w *ASTWalker) EnsureIndexes() error
- func (w *ASTWalker) ExtractAddressRefs(sourcePath, langName string) ([]string, error)
- func (w *ASTWalker) ExtractCalls(sourcePath, langName string) ([]string, error)
- func (w *ASTWalker) ExtractContext(sourcePath, langName string) ([]byte, error)
- func (w *ASTWalker) ExtractGoImports(sourceID string) (map[string]string, error)
- func (w *ASTWalker) ExtractQualifiedCalls(sourcePath, langName string) ([]graph.QualifiedCall, error)
- func (w *ASTWalker) Query(root any, selector string) ([]Match, error)
- type CallPattern
- type CoverageEntry
- type Engine
- func (e *Engine) DiagramFuncMap() template.FuncMap
- func (e *Engine) Gitignore() GitignoreMatcher
- func (e *Engine) Ingest(path string) error
- func (e *Engine) IngestRecords(records []any) error
- func (e *Engine) PrintRoutingSummary()
- func (e *Engine) ReIngestFile(path string) error
- func (e *Engine) RenderContentTemplate(tmpl string, values map[string]any) (string, error)
- func (e *Engine) SetASTWalker(w *ASTWalker)
- func (e *Engine) SetFileIndex(index map[string]FileIndexEntry)
- type FileIndexEntry
- type GitignoreMatcher
- type IngestionTarget
- type JsonWalker
- type Match
- type OriginProvider
- type SQLiteWriter
- func (w *SQLiteWriter) Act(id, action, payload string) (*graph.ActionResult, error)
- func (w *SQLiteWriter) AddDef(token, dirID string) error
- func (w *SQLiteWriter) AddFileChildren(parent *graph.Node, files []*graph.Node)
- func (w *SQLiteWriter) AddNode(n *graph.Node)
- func (w *SQLiteWriter) AddRef(token, nodeID string) error
- func (w *SQLiteWriter) AddRoot(n *graph.Node)
- func (w *SQLiteWriter) Close() error
- func (w *SQLiteWriter) DeleteFileNodes(filePath string)
- func (w *SQLiteWriter) GetCallees(id string) ([]*graph.Node, error)
- func (w *SQLiteWriter) GetCallers(token string) ([]*graph.Node, error)
- func (w *SQLiteWriter) GetNode(id string) (*graph.Node, error)
- func (w *SQLiteWriter) Invalidate(id string)
- func (w *SQLiteWriter) ListChildStats(id string) ([]graph.NodeStat, error)
- func (w *SQLiteWriter) ListChildren(id string) ([]string, error)
- func (w *SQLiteWriter) ReadContent(id string, buf []byte, offset int64) (int, error)
- func (w *SQLiteWriter) RecordFile(path string, modTime time.Time, size int64)
- func (w *SQLiteWriter) RecordIndexCoverage(sourceID, producer, fidelity string, indexedAt time.Time, complete bool)
- type SitterRoot
- type SitterWalker
- func (w *SitterWalker) Close()
- func (w *SitterWalker) ExtractAddressRefs(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]string, error)
- func (w *SitterWalker) ExtractCalls(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]string, error)
- func (w *SitterWalker) ExtractContext(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]byte, error)
- func (w *SitterWalker) ExtractFileLevelRefs(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]string, error)
- func (w *SitterWalker) ExtractGoImports(root *sitter.Node, source []byte, lang *sitter.Language) map[string]string
- func (w *SitterWalker) ExtractQualifiedCalls(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]graph.QualifiedCall, error)
- func (w *SitterWalker) Query(root any, selector string) ([]Match, error)
- type Walker
- type Watcher
- type WatcherOption
Constants ¶
const CanonicalViewsDDL = `` /* 321-byte string literal not displayed */
CanonicalViewsDDL is the SQL that creates v_defs / v_refs. Exposed so consumers that opened a .db from a different writer (e.g. LLO-built .db without these views, or an older mache build) can install the views on demand. NewSQLiteWriter runs the same DDL inline — repeated execution is safe via CREATE VIEW IF NOT EXISTS.
Once Step 1 (sister bead ley-line-453f7e) ships and _lsp_refs / _lsp_defs gain the referrer_node_id / ref_token / def_token columns, the view bodies extend with UNION ALL clauses pulling the binding-fidelity rows. Consumer SQL doesn't change at that point.
Variables ¶
var MaxIngestFileSize int64 = 100 << 20 // 100 MB
isBinaryFile returns true if the file appears to contain binary content. Uses the same heuristic as git: if the first 512 bytes contain a null byte, the file is binary. SQLite files (.db) are handled before this is called. MaxIngestFileSize is the largest file we'll read into memory during ingestion or schema inference. Files above this are silently skipped. Set to 0 to disable the size limit. Configurable via --max-file-size.
Functions ¶
func EnsureCanonicalViews ¶ added in v0.8.0
EnsureCanonicalViews installs v_defs / v_refs on an existing database connection. Idempotent — uses CREATE VIEW IF NOT EXISTS. Useful for callers that opened a .db produced by something other than mache's writer (e.g. an LLO build that hasn't been migrated yet, or a pre-Step-3 mache .db on disk).
func FlattenAST ¶ added in v0.1.1
FlattenAST walks the tree and returns a list of records for FCA analysis.
func FlattenASTWithLanguage ¶ added in v0.2.0
FlattenASTWithLanguage walks the tree and returns records for FCA analysis, using language-specific enrichment if available.
func GetGitHints ¶ added in v0.2.0
GetGitHints returns the default inference hints for Git repositories.
func LoadFileIndex ¶ added in v0.6.1
func LoadFileIndex(dbPath string) (map[string]FileIndexEntry, error)
LoadFileIndex reads the file_index table from an existing index database. Returns a map of path → (modTime, size) for incremental comparison.
func LoadGitCommits ¶ added in v0.2.0
LoadGitCommits loads all commits from a repository using git log.
func LoadGitignore ¶ added in v0.6.3
func LoadGitignore(rootDir string) *gitignoreMatcher
LoadGitignore reads .gitignore from rootDir and discovers nested .gitignore files in the tree. Returns nil if no .gitignore exists at all.
func LoadIndexCoverage ¶ added in v0.8.0
func LoadIndexCoverage(dbPath string) (map[string][]CoverageEntry, error)
LoadIndexCoverage reads the _index_coverage table from an existing index database. Returns a map keyed by source_id whose values are the per-producer entries that touched that source. Returns (nil, nil) when the table doesn't exist — the caller treats that as "no coverage info; assume any absence is unknown."
func LoadSQLite ¶
LoadSQLite opens a SQLite database, reads all records from the results table, parses each JSON record, and returns them as a slice. Kept for backward compatibility with tests; prefer StreamSQLite for large datasets.
func ParseSize ¶ added in v0.5.6
ParseSize parses a human-readable size string (e.g. "100MB", "1GB", "0"). Returns bytes. Supported suffixes: KB, MB, GB (case-insensitive).
func RegisterASTCallPatterns ¶ added in v0.8.0
func RegisterASTCallPatterns(langName string, patterns []CallPattern)
RegisterASTCallPatterns registers per-language structured call patterns for the batched ExtractCalls / ExtractQualifiedCalls fast path.
func RegisterASTContextKinds ¶ added in v0.8.0
RegisterASTContextKinds registers the top-level node kinds whose source bytes constitute the context blob for the given language.
func RegisterAddressRefQuery ¶ added in v0.6.2
func RegisterAddressRefQuery(langName, scheme, query string)
RegisterAddressRefQuery registers an address-aware ref extraction query for a specific language. The query must capture values as @ref. When matched, captured strings are unquoted (if quoted) and prefixed with scheme + ":" before being emitted as ref tokens.
Multiple queries can be registered per language by calling this function multiple times; entries are appended.
func RegisterContextQuery ¶ added in v0.2.0
func RegisterContextQuery(langName, query string)
RegisterContextQuery registers a context extraction query for a specific language. This should be called during initialization.
func RegisterFileLevelRefQuery ¶ added in v0.8.0
func RegisterFileLevelRefQuery(langName, query string)
RegisterFileLevelRefQuery registers a reference extraction query that runs once per FILE (against the root node), not per function scope. The captures supplement per-scope ExtractCalls — typical use: matching identifiers used as struct field values in top-level composite literals.
func RegisterQualifiedCallQuery ¶ added in v0.2.0
func RegisterQualifiedCallQuery(langName, query string)
RegisterQualifiedCallQuery registers a call extraction query that captures both @call (function name) and @pkg (package qualifier) for a language.
func RegisterRefQuery ¶ added in v0.2.0
func RegisterRefQuery(langName, query string)
RegisterRefQuery registers a reference extraction query for a specific language. This should be called during initialization.
func RenderTemplate ¶
RenderTemplate delegates to internal/template.Render. Kept as a public alias for backward compatibility with existing callers.
func RenderTemplateWithFuncs ¶ added in v0.6.2
func RenderTemplateWithFuncs(tmpl string, values map[string]any, extraFuncs template.FuncMap, cache *sync.Map) (string, error)
RenderTemplateWithFuncs delegates to internal/template.RenderWithFuncs.
func SchemaUsesTreeSitter ¶ added in v0.2.0
SchemaUsesTreeSitter returns true if the schema's selectors are tree-sitter S-expressions rather than JSONPath. S-expressions always start with '('.
func ShouldSkipDir ¶ added in v0.6.0
ShouldSkipDir returns true for hidden dirs and common build artifact directories.
func ShouldSkipFile ¶ added in v0.5.6
ShouldSkipFile returns true if the file should not be ingested. Checks extension blocklist, size limit, and binary content.
func StreamSQLite ¶
StreamSQLite iterates over all records in a SQLite database, calling fn for each one. Only one parsed record is alive at a time, keeping memory usage constant.
Types ¶
type ASTRoot ¶ added in v0.6.7
type ASTRoot struct {
DB *sql.DB
SourceID string // which source file (key into _source)
ParentPrefix string // scope queries to children under this prefix
}
ASTRoot is the root context for ASTWalker queries. It scopes queries to a subtree of the AST via the parentPrefix.
type ASTWalker ¶ added in v0.6.7
type ASTWalker struct {
// contains filtered or unexported fields
}
ASTWalker implements Walker by querying _ast and nodes tables produced by ley-line's ll-open/ts crate. This eliminates the CGO dependency on tree-sitter Go bindings — the AST was already parsed by Rust and stored in SQLite. Mache reads it via sqlite3_deserialize (zero-copy).
See ADR-014 for the design rationale.
func NewASTWalker ¶ added in v0.6.7
NewASTWalker creates a walker backed by a SQLite database containing ley-line's _ast, _source, and nodes tables.
func (*ASTWalker) Close ¶ added in v0.6.7
func (w *ASTWalker) Close()
Close is a no-op — the ASTWalker doesn't own the database connection.
func (*ASTWalker) EnsureIndexes ¶ added in v0.6.8
EnsureIndexes creates compound indexes on the _ast table for query performance. Call once after opening the DB, before concurrent queries. Transforms findNodesByKind from O(N) full table scan to O(K) index lookup. Returns an error if the index cannot be created (e.g., no _ast table, read-only DB, or connection pool exhausted).
func (*ASTWalker) ExtractAddressRefs ¶ added in v0.6.7
ExtractAddressRefs runs all registered address ref queries for the given language by querying the _ast table. Returns deduplicated, scheme-prefixed tokens (e.g., "env:DATABASE_URL"). Mirrors SitterWalker.ExtractAddressRefs but uses SQL instead of CGO tree-sitter.
func (*ASTWalker) ExtractCalls ¶ added in v0.8.0
ExtractCalls returns deduplicated function-call tokens for the given source file. Issues one JOIN-style SQL query per registered pattern, avoiding the per-scope query loop of the generic Query path.
Returns (nil, nil) when the language has no registered patterns — the caller treats that as "no calls" and falls through to other paths.
func (*ASTWalker) ExtractContext ¶ added in v0.8.0
ExtractContext returns the concatenated source text of the top-level context nodes for the given file (e.g. Go's import/const/var/type declarations). Used by schema context fields. Mirrors SitterWalker.ExtractContext but reads byte ranges from _ast and bytes from _source.
Returns (nil, nil) when no context kinds are registered for the language.
func (*ASTWalker) ExtractGoImports ¶ added in v0.7.0
ExtractGoImports reads Go import aliases from the _imports table (produced by ley-line-open's `leyline parse`). Returns alias → path map for qualified call resolution (e.g., auth.Validate → github.com/foo/auth). Mirrors SitterWalker.ExtractGoImports but uses SQL instead of CGO tree-sitter.
func (*ASTWalker) ExtractQualifiedCalls ¶ added in v0.8.0
func (w *ASTWalker) ExtractQualifiedCalls(sourcePath, langName string) ([]graph.QualifiedCall, error)
ExtractQualifiedCalls returns call tokens with optional package qualifiers. Patterns whose QualifierKind is non-empty produce QualifiedCall with both fields; bare patterns produce QualifiedCall with empty Qualifier.
func (*ASTWalker) Query ¶ added in v0.6.7
Query implements Walker. The selector is a tree-sitter S-expression pattern. ASTWalker translates it to SQL queries against the nodes and _ast tables.
Currently supports the common pattern: (node_kind field: (child_kind) @capture) @scope, plus simple #eq? predicates over captured text. #match? requires SitterWalker.
type CallPattern ¶ added in v0.8.0
type CallPattern struct {
OuterKind string // e.g. "call_expression"
Ancestors []string // intermediate kinds between outer and leaf
LeafKind string // node kind whose record is the call name (@call)
QualifierKind string // optional sibling-leaf kind for the package qualifier (@pkg); empty when not qualified
}
CallPattern describes one shape of function call for a language. The walker translates these into batched SQL JOINs against the _ast table — one JOIN per ancestor — to avoid the N-queries-per-file pattern of the generic selector path.
Examples:
Go bare: OuterKind=call_expression, LeafKind=identifier
Go qualified: OuterKind=call_expression, Ancestors=[selector_expression],
LeafKind=field_identifier, QualifierKind=identifier
type CoverageEntry ¶ added in v0.8.0
type CoverageEntry struct {
Producer string // 'tree-sitter' | 'lsp' | future
Fidelity string // 'mention' | 'binding' | 'reachability'
IndexedAt time.Time // when the indexer wrote the row
Complete bool // indexer claims full coverage of source_id at this fidelity
}
CoverageEntry is one (source_id, producer) row from _index_coverage. A consumer that needs to distinguish "no binding row exists for this source" from "no producer at the binding level ever indexed this source" joins against this — see ADR-0013 wedge case 1.
type Engine ¶
type Engine struct {
Schema *api.Topology
Store IngestionTarget
RootPath string // absolute path to the root of the ingestion
RespectGitignore bool // when true, skip files matching .gitignore patterns (default: true)
// contains filtered or unexported fields
}
Engine drives the ingestion process.
func (*Engine) DiagramFuncMap ¶ added in v0.6.2
DiagramFuncMap returns a template.FuncMap containing the {{diagram "name"}} function. The returned FuncMap is built once via sync.Once and reused; the closure inside captures the Engine and lazily initializes community data on first call. Safe for concurrent use.
func (*Engine) Gitignore ¶ added in v0.6.3
func (e *Engine) Gitignore() GitignoreMatcher
Gitignore returns the gitignore matcher loaded during Ingest, or nil if none was loaded. Pass this to WithGitignore when creating a Watcher so the watcher skips the same directories the engine does.
func (*Engine) Ingest ¶
Ingest processes a file or directory. Safe to call multiple times — internal dedup state is reset on each call.
func (*Engine) IngestRecords ¶ added in v0.2.0
IngestRecords processes in-memory records (e.g. from Git).
func (*Engine) PrintRoutingSummary ¶ added in v0.2.0
func (e *Engine) PrintRoutingSummary()
PrintRoutingSummary outputs a summary of files routed to _project_files/.
func (*Engine) ReIngestFile ¶ added in v0.6.0
ReIngestFile re-ingests a single file, preserving the existing RootPath. Used by the live graph refresher to update stale nodes without a full walk. After re-ingestion, the store's file mtime is updated.
func (*Engine) RenderContentTemplate ¶ added in v0.6.2
RenderContentTemplate renders a content template with the standard mache functions plus the Engine's diagram function. This is the method that processNode and collectNodes should use for file content rendering.
func (*Engine) SetASTWalker ¶ added in v0.6.7
SetASTWalker configures the engine to use a SQL-backed ASTWalker for tree-sitter schema selectors instead of CGO SitterWalker. When set, source file parsing is skipped — the ASTWalker queries pre-parsed _ast/_source tables from a ley-line .db.
func (*Engine) SetFileIndex ¶ added in v0.6.1
func (e *Engine) SetFileIndex(index map[string]FileIndexEntry)
SetFileIndex sets a cached file index for incremental re-ingestion. Files matching (path, mtime, size) will be skipped during ingestion.
type FileIndexEntry ¶ added in v0.6.1
FileIndexEntry stores cached file metadata for incremental comparison.
type GitignoreMatcher ¶ added in v0.6.3
GitignoreMatcher matches paths against .gitignore-style rules.
type IngestionTarget ¶
type IngestionTarget interface {
graph.Graph
AddNode(n *graph.Node)
AddRoot(n *graph.Node)
AddRef(token, nodeID string) error
AddDef(token, dirID string) error
DeleteFileNodes(filePath string)
AddFileChildren(parent *graph.Node, files []*graph.Node)
}
IngestionTarget combines Graph reading with writing capabilities.
type JsonWalker ¶
type JsonWalker struct{}
JsonWalker implements Walker for JSON-like data.
func NewJsonWalker ¶
func NewJsonWalker() *JsonWalker
type Match ¶
type Match interface {
// Values returns the captured values.
// For Tree-sitter, these are the named captures from the query (e.g., "res.type" -> "aws_s3_bucket").
// For JSONPath, if the match is an object, its fields are returned as values.
// If the match is a primitive, it might be returned under a default key (e.g., "value").
Values() map[string]any
// Context returns the underlying object/node to be used as the root for child queries.
// For JSONPath, this is the matched object.
// For Tree-sitter, this is the node captured as @scope (or similar convention).
Context() any
}
Match represents a single result from a query. It provides a map of values that can be used to render path templates.
type OriginProvider ¶
OriginProvider is an optional interface that Match implementations can satisfy to expose source byte ranges for write-back. Type-asserted in engine, not required by JSON walker.
type SQLiteWriter ¶ added in v0.2.0
type SQLiteWriter struct {
// contains filtered or unexported fields
}
SQLiteWriter implements IngestionTarget for the new high-performance schema.
func NewSQLiteWriter ¶ added in v0.2.0
func NewSQLiteWriter(dbPath string) (*SQLiteWriter, error)
NewSQLiteWriter creates a new writer and initializes the schema.
func (*SQLiteWriter) Act ¶ added in v0.5.0
func (w *SQLiteWriter) Act(id, action, payload string) (*graph.ActionResult, error)
func (*SQLiteWriter) AddDef ¶ added in v0.2.0
func (w *SQLiteWriter) AddDef(token, dirID string) error
func (*SQLiteWriter) AddFileChildren ¶ added in v0.6.8
func (w *SQLiteWriter) AddFileChildren(parent *graph.Node, files []*graph.Node)
func (*SQLiteWriter) AddNode ¶ added in v0.2.0
func (w *SQLiteWriter) AddNode(n *graph.Node)
AddNode writes a node to the database.
func (*SQLiteWriter) AddRef ¶ added in v0.2.0
func (w *SQLiteWriter) AddRef(token, nodeID string) error
func (*SQLiteWriter) AddRoot ¶ added in v0.2.0
func (w *SQLiteWriter) AddRoot(n *graph.Node)
func (*SQLiteWriter) Close ¶ added in v0.2.0
func (w *SQLiteWriter) Close() error
func (*SQLiteWriter) DeleteFileNodes ¶ added in v0.2.0
func (w *SQLiteWriter) DeleteFileNodes(filePath string)
func (*SQLiteWriter) GetCallees ¶ added in v0.2.0
func (w *SQLiteWriter) GetCallees(id string) ([]*graph.Node, error)
func (*SQLiteWriter) GetCallers ¶ added in v0.2.0
func (w *SQLiteWriter) GetCallers(token string) ([]*graph.Node, error)
func (*SQLiteWriter) GetNode ¶ added in v0.2.0
func (w *SQLiteWriter) GetNode(id string) (*graph.Node, error)
func (*SQLiteWriter) Invalidate ¶ added in v0.2.0
func (w *SQLiteWriter) Invalidate(id string)
func (*SQLiteWriter) ListChildStats ¶ added in v0.6.8
func (w *SQLiteWriter) ListChildStats(id string) ([]graph.NodeStat, error)
func (*SQLiteWriter) ListChildren ¶ added in v0.2.0
func (w *SQLiteWriter) ListChildren(id string) ([]string, error)
func (*SQLiteWriter) ReadContent ¶ added in v0.2.0
func (*SQLiteWriter) RecordFile ¶ added in v0.6.1
func (w *SQLiteWriter) RecordFile(path string, modTime time.Time, size int64)
RecordFile stores file metadata for incremental re-ingestion. On subsequent mounts, files with matching (path, mod_time, size) are skipped.
func (*SQLiteWriter) RecordIndexCoverage ¶ added in v0.8.0
func (w *SQLiteWriter) RecordIndexCoverage(sourceID, producer, fidelity string, indexedAt time.Time, complete bool)
RecordIndexCoverage stores a coverage row for a (source_id, producer) pair, per ADR-0013 Step 2. The fidelity argument is one of "mention", "binding", or "reachability"; complete=true means the indexer claims full coverage of source_id at that fidelity. A re-index replaces the prior row for the same (source_id, producer) — different producers keep distinct rows.
type SitterRoot ¶
type SitterRoot struct {
Node *sitter.Node
FileRoot *sitter.Node // The top-level file node (for global context)
Source []byte
Lang *sitter.Language
LangName string // "go", "python", "hcl", etc.
}
SitterRoot encapsulates the necessary context for querying a Tree-sitter tree. It includes the root node, the source code (for extracting content), and the language (for compiling the query).
type SitterWalker ¶
type SitterWalker struct {
// contains filtered or unexported fields
}
SitterWalker implements Walker for Tree-sitter parsed code.
func NewSitterWalker ¶
func NewSitterWalker() *SitterWalker
func (*SitterWalker) Close ¶ added in v0.6.1
func (w *SitterWalker) Close()
Close releases all cached compiled queries. Call when the SitterWalker is no longer needed (e.g., after ingestion completes).
func (*SitterWalker) ExtractAddressRefs ¶ added in v0.6.2
func (w *SitterWalker) ExtractAddressRefs(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]string, error)
ExtractAddressRefs runs all registered address ref queries for the given language against the AST node. Returns deduplicated, scheme-prefixed tokens (e.g., "env:DATABASE_URL"). String captures are automatically unquoted.
func (*SitterWalker) ExtractCalls ¶
func (w *SitterWalker) ExtractCalls(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]string, error)
ExtractCalls finds all function calls in the given node using a predefined query. The compiled query is cached per language to avoid recompilation on every call.
func (*SitterWalker) ExtractContext ¶ added in v0.2.0
func (w *SitterWalker) ExtractContext(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]byte, error)
ExtractContext finds package-level context nodes.
func (*SitterWalker) ExtractFileLevelRefs ¶ added in v0.8.0
func (w *SitterWalker) ExtractFileLevelRefs(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]string, error)
ExtractFileLevelRefs runs the file-level ref query against the FILE root and returns matched identifier text (deduped). Used to catch identifiers in positions that per-scope ExtractCalls can't see — e.g. function references in top-level cobra var declarations (mache-02r9). Returns nil when no file-level query is registered for the language.
func (*SitterWalker) ExtractGoImports ¶ added in v0.6.7
func (w *SitterWalker) ExtractGoImports(root *sitter.Node, source []byte, lang *sitter.Language) map[string]string
ExtractGoImports extracts structured import mappings from a Go AST. Returns a map of alias → import path (e.g., "fmt" → "fmt", "mypkg" → "github.com/foo/bar"). For unaliased imports, the alias is the last path segment.
func (*SitterWalker) ExtractQualifiedCalls ¶ added in v0.2.0
func (w *SitterWalker) ExtractQualifiedCalls(root *sitter.Node, source []byte, lang *sitter.Language, langName string) ([]graph.QualifiedCall, error)
ExtractQualifiedCalls finds all function calls with optional package qualifiers. For languages with a registered qualified call query, returns QualifiedCall with both Token and Qualifier. For others, falls back to ExtractCalls (bare tokens).
type Walker ¶
type Walker interface {
// Query executes a selector (query) against the given root node and returns a list of matches.
// The root node can be a *sitter.Node (for code) or a generic Go object (for data).
Query(root any, selector string) ([]Match, error)
}
Walker abstracts over JSONPath (Data) and Tree-sitter (Code). It provides a unified way to query a tree-like structure and extract values for path templating.
func SelectWalker ¶ added in v0.6.7
SelectWalker inspects a SQLite database and returns the best Walker. If the database has an _ast table (produced by ley-line's ll-open/ts), returns an ASTWalker (pure Go, no CGO). Otherwise returns a SitterWalker (requires CGO tree-sitter bindings).
type Watcher ¶ added in v0.6.1
type Watcher struct {
// contains filtered or unexported fields
}
Watcher monitors a directory tree for file changes and invokes callbacks when source files are created/modified or deleted. It debounces rapid changes so that a burst of writes to the same file produces a single callback after a quiet period.
func NewWatcher ¶ added in v0.6.1
func NewWatcher(rootDir string, onChange, onDelete func(path string), opts ...WatcherOption) (*Watcher, error)
NewWatcher creates a file watcher on rootDir. onChange is called for created/modified files; onDelete is called for removed files. Both callbacks receive the absolute file path. Hidden files, .git directories, and non-source extensions are ignored.
type WatcherOption ¶ added in v0.6.1
type WatcherOption func(*Watcher)
WatcherOption configures a Watcher.
func WithDebounce ¶ added in v0.6.1
func WithDebounce(d time.Duration) WatcherOption
WithDebounce sets the quiet period before a change callback fires. Defaults to 100ms.
func WithGitignore ¶ added in v0.6.3
func WithGitignore(gi GitignoreMatcher) WatcherOption
WithGitignore configures the watcher to skip directories matching gitignore rules. This prevents watching build artifact directories (target/, dist/, node_modules/) that would otherwise consume thousands of kqueue FDs on macOS.