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 ¶
This section is empty.
Functions ¶
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
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 first-by-sorted-name for determinism.
type ReplaceRule ¶
ReplaceRule is a chained line-by-line regex substitution ($1 backrefs allowed).