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 Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func New ¶
New builds the CEL environment — the single source of truth for what an expression may reference.
func (*Engine) Compile ¶
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 ¶
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.
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.
type Span ¶
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.