Documentation
¶
Overview ¶
Package builtins ships the four baked-in native predicate handlers for the ICM workflow plugin: word_count_under, word_count_over, contains_required_ids, and json_path_exists.
Each handler implements predicates.NativeHandler. RegisterAll wires the lot into any predicates.Evaluator (or any other registrar implementing NativeRegistrar).
Index ¶
Constants ¶
const ( HandlerWordCountUnder = "word_count_under" HandlerWordCountOver = "word_count_over" )
Canonical handler names. Workspace authors reference these strings in predicate `handler` fields.
const HandlerContainsRequiredIDs = "contains_required_ids"
HandlerContainsRequiredIDs is the canonical handler name for ContainsRequiredIDs.
const HandlerJSONPathExists = "json_path_exists"
HandlerJSONPathExists is the canonical handler name for JSONPathExists.
Variables ¶
This section is empty.
Functions ¶
func RegisterAll ¶
func RegisterAll(reg NativeRegistrar) error
RegisterAll registers every baked-in native predicate handler with reg under its canonical name. The current Evaluator.RegisterNative signature has no failure mode, so RegisterAll always returns nil; the error return is reserved for future additions (e.g. duplicate-name detection, schema preflight) without a signature change.
Types ¶
type ContainsRequiredIDs ¶
type ContainsRequiredIDs struct{}
ContainsRequiredIDs passes when every string in args["ids"] appears at least once in the artifact text.
Args:
ids ([]string, required): IDs that must all appear in the artifact. case_insensitive (bool, optional, default false): fold case when matching.
Decision on empty ids: an empty ids array is treated as a MALFORMED args error rather than a vacuous-truth pass. Rationale: a predicate asserting "contains required IDs" with zero IDs is almost certainly an authoring mistake (e.g. a config-substitution dropped values); silently passing such predicates risks hiding a broken workspace. Authors who truly want a no-op can omit the predicate entirely.
func (ContainsRequiredIDs) Evaluate ¶
func (ContainsRequiredIDs) Evaluate(_ context.Context, args map[string]any, artifact []byte) predicates.NativeResult
Evaluate implements predicates.NativeHandler.
type JSONPathExists ¶
type JSONPathExists struct{}
JSONPathExists parses the artifact as JSON and runs a gojq query against it. It passes when the query yields at least one result; when must_be_non_empty is true (the default), null/empty-string/empty container results do not count.
Args:
path (string, required): gojq-syntax query (e.g. ".items[0].id").
must_be_non_empty (bool, optional, default true): when true, only
non-null, non-empty results count as matches.
Compilation strategy: the gojq query string lives in predicate args, not in handler config, so it is only known at Evaluate time. The handler compiles per-Evaluate call. A single ICM run typically issues each predicate once or twice per stage iteration; per-call compile keeps the handler stateless and trivially safe for concurrent use. If future profiling shows compile overhead matters we can swap in a sync.Map cache keyed by the query string.
func (JSONPathExists) Evaluate ¶
func (JSONPathExists) Evaluate(_ context.Context, args map[string]any, artifact []byte) predicates.NativeResult
Evaluate implements predicates.NativeHandler.
type NativeRegistrar ¶
type NativeRegistrar interface {
RegisterNative(name string, h predicates.NativeHandler)
}
NativeRegistrar is the minimal surface RegisterAll needs from a host. *predicates.Evaluator satisfies it; tests can substitute fakes.
type WordCountOver ¶
type WordCountOver struct{}
WordCountOver passes when the artifact's word count is strictly greater than the configured min_words.
Args:
min_words (int, required, >= 0): exclusive lower bound on word count.
Word splitting follows strings.Fields semantics.
func (WordCountOver) Evaluate ¶
func (WordCountOver) Evaluate(_ context.Context, args map[string]any, artifact []byte) predicates.NativeResult
Evaluate implements predicates.NativeHandler.
type WordCountUnder ¶
type WordCountUnder struct{}
WordCountUnder passes when the artifact's word count is strictly less than the configured max_words.
Args:
max_words (int, required, > 0): exclusive upper bound on word count.
Word splitting follows strings.Fields semantics: any Unicode whitespace run separates words.
func (WordCountUnder) Evaluate ¶
func (WordCountUnder) Evaluate(_ context.Context, args map[string]any, artifact []byte) predicates.NativeResult
Evaluate implements predicates.NativeHandler.