Documentation
¶
Overview ¶
Package dsl is a declarative, user-extensible text-filter engine, adapted from rtk's TOML filter DSL (design D11). It lets command/log/tool-output shrinking be authored in YAML — no recompile — with the same 8-stage pipeline and Lossiness typing rtk proved out.
Adaptation for the proxy world: rtk matches a shell command string; we match a per-message "selector" (the tool name, or the first line of content) since a proxy sees tool OUTPUTS, not the command that produced them. The content stages are unchanged.
Pipeline order (each stage optional, applied in this exact order):
- strip_ansi 2. replace[] 3. match_output[]+unless
- strip/keep lines 5. truncate_lines_at 6. head/tail
- max_lines 8. on_empty
Filters are lossy (they drop lines), so the cmdfilter component that wraps this engine is an Offload: it stashes the original before applying a filter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Caps = map[string]int{
"errors": 20,
"warnings": 10,
"list": 20,
"inventory": 50,
"buildlog": 80,
}
Caps are the shared line budgets a filter picks by SIGNAL DENSITY (`cap: errors`) instead of hand-picking a max_lines per filter. The first four names and values are rtk's (src/core/truncate.rs); `buildlog` is ours — a build/plan transcript is mostly noise but the line that matters can sit anywhere in it, so it gets a deliberately generous budget. One map tunes the whole filter set.
Functions ¶
func ReducedCap ¶ added in v0.1.1
ReducedCap is rtk's `reduced` deviation helper: a cap lowered for a more verbose data class, underflow-safe — a deviation can never empty the budget.
func RunTests ¶
RunTests compiles and runs the inline [tests] in a filter document, returning the names of failing cases (empty = all pass). Powers a `verify` command.
func TruncateRunes ¶ added in v0.1.1
TruncateRunes caps a line at n runes, marking the cut with an ellipsis that fits INSIDE the budget (so the result is never longer than n). Ported from rtk's utils::truncate.
Exported because the generic per-line cap in the `linecap` component applies the same rule outside this package, and a second copy of "the ellipsis has to fit inside the budget" is the kind of subtlety that drifts.
Types ¶
type Compiled ¶
type Compiled struct {
Name string
// contains filtered or unexported fields
}
Compiled is a filter with its regexes prebuilt.
type Def ¶
type Def struct {
Description string `yaml:"description"`
Match string `yaml:"match"` // regex against the selector key
// Family groups filters for per-family metrics (builds, tests, iac, pkg, net, ...).
Family string `yaml:"family"`
// Priority orders matching: higher first, then by name. Absent (0) = today's
// behavior (name order). Use it to put a specific filter ahead of a generic one,
// which matters more here than in rtk because we match on output shape.
Priority int `yaml:"priority"`
// Cap selects a shared budget class from Caps instead of a literal MaxLines;
// CapReduce lowers it for an extra-verbose variant. MaxLines wins if both are set.
Cap string `yaml:"cap"`
CapReduce int `yaml:"cap_reduce"`
StripANSI bool `yaml:"strip_ansi"`
Replace []ReplaceRule `yaml:"replace"`
MatchOutput []MatchRule `yaml:"match_output"`
StripLinesMatching []string `yaml:"strip_lines_matching"`
KeepLinesMatching []string `yaml:"keep_lines_matching"`
TruncateLinesAt *int `yaml:"truncate_lines_at"`
HeadLines *int `yaml:"head_lines"`
TailLines *int `yaml:"tail_lines"`
MaxLines *int `yaml:"max_lines"`
OnEmpty *string `yaml:"on_empty"`
}
Def is a raw filter definition (from YAML). All fields except Match are optional.
type File ¶
type File struct {
SchemaVersion int `yaml:"schema_version"`
Filters map[string]Def `yaml:"filters"`
Tests map[string][]TestCase `yaml:"tests"`
}
File is a filter document: a schema version + named filters + inline tests.
type Lossiness ¶
type Lossiness int
Lossiness records what a filter did to its input, so the caller can emit an accurate recovery hint (after rtk's Lossiness enum).
type MatchRule ¶
type MatchRule struct {
Pattern string `yaml:"pattern"`
Message string `yaml:"message"`
Unless string `yaml:"unless"`
}
MatchRule short-circuits: if Pattern matches the whole blob (and Unless does not), return Message immediately.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds compiled filters, matched by descending priority then by name for determinism (specific-before-generic without relying on alphabetical luck).
func (*Registry) Load ¶
Load parses a YAML filter document and appends its filters to the registry. schema_version must be 1. Duplicate filter names are rejected (a silently shadowed filter is a debugging trap — rtk's build.rs rejects them too) and any inline tests the document carries must pass, so a broken filter fails loudly at load instead of quietly mangling output. (Requiring a test to EXIST is enforced for the shipped builtins by a unit test, not here — user configs stay free.)
type ReplaceRule ¶
ReplaceRule is a chained line-by-line regex substitution ($1 backrefs allowed).