AST Engine & Node Slicing
Triage’s core architectural differentiator is on-demand AST slicing. Rather than pre-indexing whole repositories or passing full source files to LLMs, Triage extracts only the enclosing *ast.FuncDecl node for the panicking line.
Why AST Slicing?
Section titled “Why AST Slicing?”When a Go panic occurs, passing the full source file to an LLM creates multiple problems:
- Token Cost: A 1,500-line file uses ~3,000 tokens per incident.
- Context Dilution: Unrelated functions in the same file confuse LLM inference.
- Speed: Parsing only the relevant function block speeds up inference by 3x.
By extracting only the *ast.FuncDecl containing the panic, Triage achieves a 94% token reduction (reducing payload size to 100–250 tokens) while preserving complete semantic context.
AST Resolution Pipeline
Section titled “AST Resolution Pipeline”1. Panic Telemetry arrives (file + line + commit_sha) │ ▼2. 3-Tier Layered Cache Lookup ├── Tier 1: In-Memory KV Cache (<1.5ms) ├── Tier 2: PostgreSQL ast_nodes (<5ms) └── Tier 3: GitHub Contents API (<25ms) │ ▼3. go/parser & go/ast AST Walker └── Find *ast.FuncDecl where Pos <= Line <= End │ ▼4. Formatted AST Code Snippet (10-30 lines)The Go Parser Internals
Section titled “The Go Parser Internals”The Triage Engine parses source files using Go’s official standard packages:
go/parser:parser.ParseFile(fset, filename, src, parser.ParseComments)go/ast:ast.Inspect(node, func(n ast.Node) bool)
AST Node Traversal Algorithm
Section titled “AST Node Traversal Algorithm”func ExtractEnclosingFunc(src []byte, targetLine int) (*ast.FuncDecl, []string, error) { fset := token.NewFileSet() fileNode, err := parser.ParseFile(fset, "", src, parser.ParseComments) if err != nil { return nil, nil, err }
var matchedFunc *ast.FuncDecl ast.Inspect(fileNode, func(n ast.Node) bool { if fn, ok := n.(*ast.FuncDecl); ok { startLine := fset.Position(fn.Pos()).Line endLine := fset.Position(fn.End()).Line
if targetLine >= startLine && targetLine <= endLine { matchedFunc = fn return false // Found target function } } return true })
return matchedFunc, extractLines(src, matchedFunc), nil}Pre-Indexing (Optional)
Section titled “Pre-Indexing (Optional)”While Triage resolves AST nodes dynamically on demand, you can also pre-index entire repositories via the API:
curl -X POST http://localhost:8080/api/v1/ast/index \ -H "Authorization: Bearer $TRIAGE_SESSION_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "repo": "myorg/myrepo", "commit_sha": "main" }'This populates the ast_nodes PostgreSQL table for instant <5ms queries.