Documentation
¶
Overview ¶
R3 re-home (mache-96c378 stage 5): the auto-parse + walker attachment pipeline moved here from cmd/serve.go. mount, build, serve, and the schema-inference path all invoke leyline through these two functions, and serve owning them was the schemainfer→mcpserve and cmd→mcpserve edge the decomposition had to empty.
Index ¶
- Constants
- Variables
- func AttachLeylineASTWalker(dataSource string, engine *ingest.Engine) (*sql.DB, func(), error)
- func AutoInvokeLeylineParse(sourceDir string) (string, func(), error)
- func MaterializeContentSources(dbPath string, schema *api.Topology) error
- func MaterializeVirtuals(dbPath string, schema *api.Topology, agentMode bool) error
- func NewASTCallExtractor(db *sql.DB) graph.CallExtractor
- func NewASTScopedCallExtractor(db *sql.DB) graph.ScopedCallExtractor
- func NoopCallExtractor() graph.CallExtractor
- func PickCallExtractor(db *sql.DB) graph.CallExtractor
- func PickScopedCallExtractor(db *sql.DB) graph.ScopedCallExtractor
- type UDSGraph
- func (g *UDSGraph) Act(id, action, payload string) (*graph.ActionResult, error)
- func (g *UDSGraph) Close() error
- func (g *UDSGraph) GetCallees(id string) ([]*graph.Node, error)
- func (g *UDSGraph) GetCallers(token string) ([]*graph.Node, error)
- func (g *UDSGraph) GetNode(id string) (*graph.Node, error)
- func (g *UDSGraph) Invalidate(id string)
- func (g *UDSGraph) ListChildStats(id string) ([]graph.NodeStat, error)
- func (g *UDSGraph) ListChildren(id string) ([]string, error)
- func (g *UDSGraph) ReadContent(id string, buf []byte, offset int64) (int, error)
Constants ¶
const ( // TempDBMaxAgeEnv overrides how old an orphaned temp db must be before it // is reaped. Accepts any time.ParseDuration string. Tests set it; nothing // else should need to. TempDBMaxAgeEnv = "MACHE_TEMP_DB_MAX_AGE" // ParseCacheMaxBytesEnv overrides the parse cache's size budget, in bytes. ParseCacheMaxBytesEnv = "MACHE_PARSE_CACHE_MAX_BYTES" )
const ParseCacheDirEnv = "MACHE_PARSE_CACHE_DIR"
ParseCacheDirEnv points the parse cache somewhere other than ~/.mache/parse. `task bench:cold` sets it to a throwaway directory so the cold arm measures a genuinely cold parse and the warm arm measures a genuinely warm one, without touching the developer's real cache.
Variables ¶
var ErrProjectionV6 = errors.New("nodes are not written into a projection-v6 arena (mache-e64f36)")
ErrProjectionV6 is a refusal to write nodes into a projection-v6 .db (leyline v0.20.x). Its nodes are rows in the producer's own nodes table; in a v6 arena that means allocating nids and interning names inside LLO's numbering, which is the data-plane work the LLO boundary keeps out of mache (mache-e64f36).
Functions ¶
func AttachLeylineASTWalker ¶
AttachLeylineASTWalker parses dataSource with ley-line into a temporary `_ast` db, opens it, and wires an ASTWalker onto the engine so a source (tree-sitter S-expression) schema projects with zero in-process CGO (ADR-0012 step 4). Returns the open db (for a call extractor) and a cleanup that closes the db and removes the temp file. ley-line is mandatory: a resolution failure is returned as an error (guardrail 2), never swallowed.
func AutoInvokeLeylineParse ¶
AutoInvokeLeylineParse runs `leyline parse <sourceDir> -o <tmpdb>` and returns the path to the produced .db plus a cleanup function that removes it. Returns an error if leyline is not available on PATH or in the bundled location, or if parsing fails. The caller should fall back to the in-process ingest path on any error.
func MaterializeContentSources ¶
MaterializeContentSources writes the file nodes a schema's content_source leaves declare (hover text, diagnostics and the like, joined onto construct directories) into the .db before it is served. It is the one thing a served .db still has written into it: the virtual paths are answered at runtime (mache-abaf17). A schema that declares none writes nothing, so a projection-v6 .db is refused only when there is something to write.
func MaterializeVirtuals ¶
MaterializeVirtuals adds virtual file nodes to the .db, for `mache mount --out`, which writes the .db out in another format and so has no runtime to answer virtual paths.
Materialized files:
- _schema.json (schema topology as JSON)
- PROMPT.txt (if agentMode)
- callers/ and callees/ dirs (from node_refs cross-references)
- content-source files the schema declares
A served .db needs none but the last: MCP and the NFS mount answer the virtual paths at runtime, through the vfs resolver (see MaterializeContentSources).
func NewASTCallExtractor ¶
func NewASTCallExtractor(db *sql.DB) graph.CallExtractor
NewASTCallExtractor returns a graph.CallExtractor backed by SQL queries against the `_ast` table — no CGO, no tree-sitter parser. The DB must have been parsed by ley-line (or any source that populates `_ast` with the schema mache expects).
This is the pure-Go alternative to newCallExtractor (mount.go) for backends that already carry parsed AST. ADR-0012 (mache-37ae8b) migration plan calls for this to replace newCallExtractor entirely once mache build delegates parsing to ley-line. Until then, both coexist and callers select per-backend.
The extractor's signature matches graph.CallExtractor:
func(content []byte, path, langName string) ([]graph.QualifiedCall, error)
`content` is unused — ASTWalker resolves the call set from the pre-parsed AST keyed on `path` (used as source_id). `langName` selects the per-language CallPattern registry.
Returns nil, nil when:
- langName has no registered call pattern (same shape as the SitterWalker-backed extractor's "no grammar" branch)
- the source row isn't in `_ast` (a stale path argument)
Errors are returned only for SQL failures the caller should propagate.
func NewASTScopedCallExtractor ¶
func NewASTScopedCallExtractor(db *sql.DB) graph.ScopedCallExtractor
NewASTScopedCallExtractor returns a graph.ScopedCallExtractor backed by SQL queries against the `_ast` table, scoped to a single construct. Unlike NewASTCallExtractor, sourceID and scopeID here are the REAL `_ast`/`_source` key and scope node id (recovered from the construct's ast_source_id/ ast_scope_id Properties) — not a graph node id — so the query actually matches rows. This is the fix for bead mache-fd9982: find_callees was silently broken on the serve/mount path because the old wiring fed a graph node id (e.g. "cmd/functions/evalOrAbs") into a query keyed on real _ast source ids (e.g. "agent.go"), which matched nothing.
func NoopCallExtractor ¶
func NoopCallExtractor() graph.CallExtractor
NoopCallExtractor returns a CallExtractor that resolves no calls. Used for backends with no pre-parsed `_ast` table (e.g. JSON/data-only graphs, or the composite cross-mount fallback when a mount carries no AST). Since ADR-0012 step 4 removed in-process CGO tree-sitter, there is no parser to fall back to — the honest answer for a non-source backend is "no calls".
func PickCallExtractor ¶
func PickCallExtractor(db *sql.DB) graph.CallExtractor
PickCallExtractor returns the pure-Go ASTWalker-backed extractor when `_ast` is present in the active .db, and a no-op extractor otherwise. This is the per-site dispatch point used by mache serve / mache mount when wiring a CallExtractor onto a SQLiteGraph.
Detection is a single SQL query against sqlite_master. ADR-0012 step 4 removed in-process CGO tree-sitter, so there is no CGO fallback: a db with no `_ast` table (or a nil db, or a detection error) yields the no-op extractor rather than crashing the wiring. Every source projection carries `_ast` (ley-line parses it), so the no-op only applies to non-source backends.
func PickScopedCallExtractor ¶
func PickScopedCallExtractor(db *sql.DB) graph.ScopedCallExtractor
PickScopedCallExtractor mirrors PickCallExtractor but returns a graph.ScopedCallExtractor (nil when `_ast` isn't present). This is the extractor GetCallees actually uses once a construct carries ast_source_id/ast_scope_id Properties (bead mache-fd9982) — the legacy graph.CallExtractor returned by PickCallExtractor is kept only as a fallback for constructs/.dbs that predate this fix.
Types ¶
type UDSGraph ¶
type UDSGraph struct {
// contains filtered or unexported fields
}
UDSGraph implements graph.Graph by sending structured ops over a UDS socket to the ley-line daemon. The daemon runs queries against the arena buffer (zero-copy via sqlite3_deserialize). Mache never opens SQLite directly.
func NewUDSGraph ¶
func (*UDSGraph) Act ¶
func (g *UDSGraph) Act(id, action, payload string) (*graph.ActionResult, error)
func (*UDSGraph) GetCallees ¶
GetCallees resolves a construct's forward references to their definitions via the daemon's `find_callees` op (added in LLO 0.2.2 / daemon op_find_callees). The daemon executes
SELECT DISTINCT d.node_id, d.source_id FROM node_refs r JOIN node_defs d ON r.token = d.token WHERE r.node_id = ?
and returns `{callees: [{node_id, source_id}, ...]}`. Unlike SQLiteGraph's client-side extractor (tree-sitter on source bytes), this path is purely SQL — no CGO grammar walk required.