celenv

package
v0.0.0-...-5ecf2ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package celenv defines the single CEL environment for risk rule expressions. Every expression is a boolean predicate; the eval modes differ only in what they read off the result — EvalScope returns the verdict, EvalDetection also returns the spans the matcher methods recorded so the dashboard can highlight.

Fields: kind (string); content/prompt/assistant/tool_result (field); tool_calls (list of tool, each with .name/.server/.function/.args). Body fields are auto-scoped (prompt is empty outside user messages, so no kind check needed); inside tool_calls.exists(t, ...) a tool's fields are correlated to the same call; any field's .get(path) drills into its JSON. Spans are captured as a side effect of the matchers via a per-eval collector, so eval is thread-safe.

celenv is self-contained (its own Message/Tool/Span types) so the analysis engine can import it without a cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Completion

type Completion struct {
	Context string           `json:"context"` // "member" (after a dot) | "name"
	Items   []CompletionItem `json:"items"`
}

type CompletionItem

type CompletionItem struct {
	Label    string `json:"label"`
	Detail   string `json:"detail"`
	Doc      string `json:"doc"`
	Category string `json:"category"` // matcher | macro | globalMacro | field | variable | bind
}

type Engine

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

func New

func New() (*Engine, error)

New builds the CEL environment — the single source of truth for what an expression may reference.

func (*Engine) Compile

func (e *Engine) Compile(expr string) (cel.Program, error)

Compile type-checks an expression. Every expression — scope or detection — is a boolean predicate, so save-time validation is the same for both.

func (*Engine) Complete

func (e *Engine) Complete(src string) Completion

Complete returns the suggestions valid at the end of src (text up to the cursor).

func (*Engine) EvalDetection

func (e *Engine) EvalDetection(prg cel.Program, msg Message) ([]Span, bool, error)

EvalDetection evaluates the predicate and, when it matches, returns the spans recorded by the matcher methods. When the predicate is false the rule did not fire and no spans are returned.

func (*Engine) EvalScope

func (e *Engine) EvalScope(prg cel.Program, msg Message) (bool, error)

EvalScope evaluates the predicate and returns its boolean verdict. Spans are not collected.

type FuncRef

type FuncRef struct {
	Name         string `json:"name"`
	Signature    string `json:"signature"`
	Description  string `json:"description"`
	ReturnsField bool   `json:"returnsField"` // get() chains; the rest return bool
}

type MacroRef

type MacroRef struct {
	Name        string `json:"name"`
	Signature   string `json:"signature"`
	Description string `json:"description"`
	ReturnsBool bool   `json:"returnsBool"`
}

type Message

type Message struct {
	Content string
	Type    string
	Tools   []Tool
}

Message is the structured input an expression evaluates against.

type Reference

type Reference struct {
	Variables []VarRef   `json:"variables"`
	Matchers  []FuncRef  `json:"matchers"`
	Macros    []MacroRef `json:"macros"`
}

Reference is the editor-facing catalog of the CEL environment, driving autocomplete and the reference panel. The engine (New) is authoritative; this carries no machine types and has no parity to maintain.

func Describe

func Describe() Reference

Describe returns a freshly-built catalog (no shared backing arrays).

type Span

type Span struct {
	Target     string
	ToolCallID string
	Path       string
	Start      int
	End        int
	Value      string
}

Span is one matched substring, attributed to the field (and optionally the tool call and JSON path) it matched in. Detection evaluation returns a slice.

type Tool

type Tool struct {
	Name     string
	Server   string
	Function string
	Args     string
}

Tool is one tool call exposed to expressions as an element of `tool_calls`.

type VarRef

type VarRef struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Description string   `json:"description"`
	Matchable   bool     `json:"matchable"` // field-typed: matchers apply
	Fields      []VarRef `json:"fields,omitempty"`
}

Jump to

Keyboard shortcuts

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