Documentation
¶
Index ¶
- Constants
- func ApplyTOMLFilter(input string, config *TOMLFilterRule) (string, int)
- func FormatRegistryStats(stats map[string]any) string
- func FormatResults(passed, failed int, failures []string) string
- func FormatSafetyReport(check SafetyCheck) string
- func IsPrintableASCII(s string) bool
- func MatchAndFilter(command string, output string, registry *FilterRegistry) (string, int, bool)
- func RunTestSuite(suite TestSuite, filterFunc func(string, string) string) (int, int, []string)
- func ValidateFilterConfig(content string) []string
- type CommunityFilterRegistry
- func (r *CommunityFilterRegistry) Eject(name string, destDir string) error
- func (r *CommunityFilterRegistry) Install(name string) error
- func (r *CommunityFilterRegistry) List(category string) []RegistryEntry
- func (r *CommunityFilterRegistry) Publish(entry RegistryEntry) error
- func (r *CommunityFilterRegistry) Search(query string) []RegistryEntry
- func (r *CommunityFilterRegistry) Stats() map[string]any
- type FilterRegistry
- type FilterTestCase
- type FilterTestSuite
- type Loader
- func (l *Loader) IsTrusted(projectPath string) bool
- func (l *Loader) ListTrusted() []string
- func (l *Loader) LoadAll(projectDir string) (*FilterRegistry, error)
- func (l *Loader) LoadTrusted() error
- func (l *Loader) TrustProject(projectPath string) error
- func (l *Loader) UntrustProject(projectPath string) error
- type LoaderConfig
- type MatchOutputRule
- type Parser
- type RegistryEntry
- type ReplaceRule
- type RiskSummary
- type SafetyCheck
- type SafetyIssue
- type TOMLFilter
- type TOMLFilterEngine
- type TOMLFilterRule
- type TOMLFilterWrapper
- type TestCase
- type TestSuite
- type TrustEntry
- type TrustManager
- func (tm *TrustManager) CheckTrust(filterPath string) (TrustStatus, error)
- func (tm *TrustManager) ListTrusted() map[string]TrustEntry
- func (tm *TrustManager) Load() error
- func (tm *TrustManager) Save() error
- func (tm *TrustManager) TrustProject(filterPath string) error
- func (tm *TrustManager) UntrustProject(filterPath string) (bool, error)
- type TrustStatus
- type TrustStore
Constants ¶
const SchemaVersion = 1
SchemaVersion is the expected TOML filter schema version
Variables ¶
This section is empty.
Functions ¶
func ApplyTOMLFilter ¶
func ApplyTOMLFilter(input string, config *TOMLFilterRule) (string, int)
ApplyTOMLFilter is a convenience function to apply a TOML filter config
func FormatRegistryStats ¶ added in v1.5.0
FormatRegistryStats returns a human-readable stats string.
func FormatResults ¶ added in v1.5.0
FormatResults formats test results.
func FormatSafetyReport ¶
func FormatSafetyReport(check SafetyCheck) string
FormatSafetyReport returns a human-readable safety report.
func IsPrintableASCII ¶
IsPrintableASCII checks if a string contains only printable ASCII.
func MatchAndFilter ¶
MatchAndFilter finds a matching filter and applies it
func RunTestSuite ¶
RunTestSuite runs a test suite against a filter.
func ValidateFilterConfig ¶
ValidateFilterConfig validates a filter configuration for correctness.
Types ¶
type CommunityFilterRegistry ¶ added in v1.5.0
type CommunityFilterRegistry struct {
// contains filtered or unexported fields
}
CommunityFilterRegistry manages community filter sharing and publishing.
func NewCommunityFilterRegistry ¶ added in v1.5.0
func NewCommunityFilterRegistry(localPath, remoteURL string) *CommunityFilterRegistry
NewCommunityFilterRegistry creates a new community filter registry.
func (*CommunityFilterRegistry) Eject ¶ added in v1.5.0
func (r *CommunityFilterRegistry) Eject(name string, destDir string) error
Eject copies a built-in filter to local config for customization.
func (*CommunityFilterRegistry) Install ¶ added in v1.5.0
func (r *CommunityFilterRegistry) Install(name string) error
Install downloads and installs a filter by name.
func (*CommunityFilterRegistry) List ¶ added in v1.5.0
func (r *CommunityFilterRegistry) List(category string) []RegistryEntry
List returns all available filters, optionally filtered by category.
func (*CommunityFilterRegistry) Publish ¶ added in v1.5.0
func (r *CommunityFilterRegistry) Publish(entry RegistryEntry) error
Publish publishes a filter to the registry.
func (*CommunityFilterRegistry) Search ¶ added in v1.5.0
func (r *CommunityFilterRegistry) Search(query string) []RegistryEntry
Search searches filters by name, description, or tags.
func (*CommunityFilterRegistry) Stats ¶ added in v1.5.0
func (r *CommunityFilterRegistry) Stats() map[string]any
Stats returns registry statistics.
type FilterRegistry ¶
type FilterRegistry struct {
// contains filtered or unexported fields
}
FilterRegistry holds all loaded TOML filters
func NewFilterRegistry ¶
func NewFilterRegistry() *FilterRegistry
NewFilterRegistry creates a new filter registry
func (*FilterRegistry) Count ¶
func (r *FilterRegistry) Count() int
Count returns the number of loaded filters
func (*FilterRegistry) FindMatchingFilter ¶
func (r *FilterRegistry) FindMatchingFilter(command string) (string, string, *TOMLFilterRule)
FindMatchingFilter finds a filter that matches the given command
func (*FilterRegistry) LoadFile ¶
func (r *FilterRegistry) LoadFile(path string) error
LoadFile loads a single TOML filter file
type FilterTestCase ¶ added in v1.5.0
FilterTestCase represents a single filter test case.
type FilterTestSuite ¶
type FilterTestSuite struct {
Name string
Tests []FilterTestCase
}
FilterTestSuite represents a declarative test suite for TOML filters. Inspired by tokf's filter test suites.
func NewFilterTestSuite ¶
func NewFilterTestSuite(dir string) (*FilterTestSuite, error)
NewFilterTestSuite creates a new filter test suite from a directory.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles loading TOML filters from multiple sources
var GlobalFilterLoader *Loader
GlobalFilterLoader is the default loader instance
func (*Loader) ListTrusted ¶
ListTrusted returns all trusted project paths
func (*Loader) LoadAll ¶
func (l *Loader) LoadAll(projectDir string) (*FilterRegistry, error)
LoadAll loads filters from all sources with priority order: 1. Project-local: .tokman/filters.toml (requires trust) 2. User-global: ~/.config/tokman/filters.toml 3. Built-in: embedded filters
func (*Loader) LoadTrusted ¶
LoadTrusted loads the trusted projects file
func (*Loader) TrustProject ¶
TrustProject marks a project directory as trusted for filter loading
func (*Loader) UntrustProject ¶
UntrustProject removes a project from the trusted list
type LoaderConfig ¶
type LoaderConfig struct {
ConfigDir string // Base config directory (default: ~/.config/tokman)
DataDir string // Base data directory (default: ~/.local/share/tokman)
ProjectDir string // Current project directory
}
LoaderConfig configures the filter loader
type MatchOutputRule ¶
type MatchOutputRule struct {
Pattern string `toml:"pattern"`
Message string `toml:"message"`
Priority int `toml:"priority"`
Unless string `toml:"unless"` // Optional: if this pattern also matches, skip the rule
}
MatchOutputRule defines a short-circuit match rule If pattern matches, returns message immediately (short-circuit). If unless is set and also matches, the rule is skipped (prevents swallowing errors).
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles parsing TOML filter files
func (*Parser) ParseContent ¶
func (p *Parser) ParseContent(content []byte, source string) (*TOMLFilter, error)
ParseContent parses TOML filter content
type RegistryEntry ¶ added in v1.5.0
type RegistryEntry struct {
Name string `json:"name"`
Description string `json:"description"`
Author string `json:"author"`
Version string `json:"version"`
Category string `json:"category"`
Downloads int `json:"downloads"`
Rating float64 `json:"rating"`
Tags []string `json:"tags,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Content string `json:"content"`
SHA256 string `json:"sha256"`
}
RegistryEntry represents a published filter in the registry.
type ReplaceRule ¶
ReplaceRule defines a regex replacement rule
type RiskSummary ¶
RiskSummary holds risk analysis results for a filter file.
func AnalyzeFilterRisk ¶
func AnalyzeFilterRisk(content string) RiskSummary
AnalyzeFilterRisk analyzes a TOML filter file for risky patterns.
type SafetyCheck ¶
type SafetyCheck struct {
Passed bool
Issues []SafetyIssue
}
SafetyCheck represents a safety check result.
func CheckFilterSafety ¶
func CheckFilterSafety(content string) SafetyCheck
CheckFilterSafety performs safety checks on a TOML filter definition. Inspired by tokf's filter safety checks.
type SafetyIssue ¶
type SafetyIssue struct {
Severity string // "critical", "warning", "info"
Message string
Line int
}
SafetyIssue represents a safety issue found in a filter.
type TOMLFilter ¶
type TOMLFilter struct {
SchemaVersion int `toml:"schema_version"`
Filters map[string]TOMLFilterRule `toml:"-"`
RawContent map[string]any `toml:"-"`
}
TOMLFilter represents a parsed TOML filter file
func (*TOMLFilter) MatchesCommand ¶
func (f *TOMLFilter) MatchesCommand(command string) (string, *TOMLFilterRule, error)
MatchesCommand checks if any filter matches the given command
func (*TOMLFilter) Validate ¶
func (f *TOMLFilter) Validate() error
Validate validates the filter configuration
type TOMLFilterEngine ¶
type TOMLFilterEngine struct {
// contains filtered or unexported fields
}
TOMLFilterEngine applies TOML-defined filter rules to output
func NewTOMLFilterEngine ¶
func NewTOMLFilterEngine(config *TOMLFilterRule) *TOMLFilterEngine
NewTOMLFilterEngine creates a new filter engine from a TOML config
type TOMLFilterRule ¶
type TOMLFilterRule struct {
MatchCommand string `toml:"match_command"`
StripANSI bool `toml:"strip_ansi"`
Replace []ReplaceRule `toml:"replace"`
MatchOutput []MatchOutputRule `toml:"match_output"`
StripLinesMatching []string `toml:"strip_lines_matching"`
KeepLinesMatching []string `toml:"keep_lines_matching"`
TruncateLinesAt int `toml:"truncate_lines_at"`
Head int `toml:"head"`
Tail int `toml:"tail"`
MaxLines int `toml:"max_lines"`
OnEmpty string `toml:"on_empty"`
}
TOMLFilterRule represents a single TOML filter rule configuration
type TOMLFilterWrapper ¶
type TOMLFilterWrapper struct {
// contains filtered or unexported fields
}
TOMLFilterWrapper implements the filter.Filter interface for TOML filters
func NewTOMLFilterWrapper ¶
func NewTOMLFilterWrapper(name string, config *TOMLFilterRule) *TOMLFilterWrapper
NewTOMLFilterWrapper creates a filter.Filter wrapper for a TOML filter
func (*TOMLFilterWrapper) Name ¶
func (f *TOMLFilterWrapper) Name() string
Name returns the filter name
type TrustEntry ¶
TrustEntry holds trust metadata for a project filter file.
type TrustManager ¶
type TrustManager struct {
// contains filtered or unexported fields
}
TrustManager manages project filter trust with SHA-256 verification.
func NewTrustManager ¶
func NewTrustManager(configDir string) *TrustManager
NewTrustManager creates a new trust manager.
func (*TrustManager) CheckTrust ¶
func (tm *TrustManager) CheckTrust(filterPath string) (TrustStatus, error)
CheckTrust verifies if a project filter file is trusted. Returns TrustStatus and any error.
func (*TrustManager) ListTrusted ¶
func (tm *TrustManager) ListTrusted() map[string]TrustEntry
ListTrusted returns all trusted project filter paths.
func (*TrustManager) Load ¶
func (tm *TrustManager) Load() error
Load loads the trust store from disk.
func (*TrustManager) Save ¶
func (tm *TrustManager) Save() error
Save persists the trust store to disk.
func (*TrustManager) TrustProject ¶
func (tm *TrustManager) TrustProject(filterPath string) error
TrustProject stores the current SHA-256 hash as trusted.
func (*TrustManager) UntrustProject ¶
func (tm *TrustManager) UntrustProject(filterPath string) (bool, error)
UntrustProject removes trust for a project filter file.
type TrustStatus ¶
type TrustStatus int
TrustStatus represents the result of a trust check.
const ( TrustStatusTrusted TrustStatus = iota TrustStatusUntrusted TrustStatusContentChanged TrustStatusEnvOverride )
type TrustStore ¶
type TrustStore struct {
Version int `json:"version"`
Trusted map[string]TrustEntry `json:"trusted"`
}
TrustStore holds all trusted project filter entries.