jig-harness/jig

Rule matchers in configuration

stable · Version 1

Some settings in a repository’s .config/jig.yaml choose something by what a tracker item or a change holds: the base branch a pull request targets by the item’s labels, the review gates a change owes by its labels or the paths it touches, the agent that implements it by its labels or its title, whether a raise moves the implementer’s effort by its size. Each such setting is a list of rules, and one rule matcher in the plugin decides every one of them the same way. This chapter is for the person who writes such a setting, and for a program outside Jig’s skills that wants to evaluate a rule the way Jig does: which facts a rule may test, how each is compared, how a rule’s values combine, and how a setting’s rules resolve.

A rule maps facts to the values it lists:

yaml
pull_requests:
  base_rules:
    - when: { labels: [hotfix, urgent] }
      base: release

Most settings are written in a shorter form that stands for such a rule (a list of labels, a map from a label to a result); the table of forms below says how each reads. A rule naming a fact this chapter does not list, a fact its setting does not test, or a value of the wrong kind, is a configuration error: the shared configuration reader refuses the whole configuration, naming the setting and the file that set it, before any skill acts on it, and the audit reports it. A program reading a rule written for a later version of this chapter, with a fact it does not know, treats the rule as one it cannot evaluate, never as one that matches nothing.

When a skill says why it chose something (the base pr-plan.ts prints, a reason in a route determine_route.ts prints, a gate determine_agent.ts applies), it names the setting, the rule and what matched in one wording: pull_requests.base_rules[0], for the item's label hotfix.

Each setting’s default and what it is for: the configuration reference. The same values, for a program in any language: data/rule-matchers.json; the shape of a rule as when holds it: schemas/rule.json.

The facts a rule may test

A rule’s facts are tried in this order, and a rule’s values for one fact in the order written; the first value that matches one of the item’s values is the one a reason names.

FactThe item holdsA rule listsComparedMeaning
labelsa list of label namesa list of label namesEqual, ignoring case and white space around the name: Bug matches bug.The labels the tracker item carries; for a flag an area of the change-area catalog declares, the flags of the areas the item’s labels reach.
titleone texta list of keywordsThe keyword appears anywhere in the title, ignoring case: migration matches Write the Migrations.The tracker item’s title.
sizea list of size namesa list of size namesEqual, ignoring case and white space around the name, as a label is; a size is never compared by its step, so large does not match L.The item’s size: its size facet’s value where the repository has a size facet, else its labels.
pathsa list of repository-relative pathsa list of path globsThe glob claims the path, by the glob matching the change-area catalog uses: ** spans directories, * and ? stay within one, {a,b} alternates and [...] is a character class.The paths the change touches. Before the change exists they are the paths the caller says it plans to touch; a rule that could match only by its paths is then listed apart, for whoever plans the change to apply.

How a rule combines its values

CombinationMeaning
anyA rule matches when any one value it lists, for any one fact it tests, matches the item: one label of several is enough, and a label or a path is enough. A rule cannot yet say that every value, or none, must match.

How a setting’s rules resolve

List semanticsMeaning
firstThe rules are tried in the order written and the first that matches decides; when none matches, the field’s fallback applies.
everyEvery rule that matches applies, in the order written.
lookupA map from one fact’s value to a result: every key that matches one of the item’s values applies, in the order of the item’s values, then the order written. Keys that differ only in case are one key, the last written.
oneThe field is one rule: it applies or not, and names the value that matched.

How a setting is written

FormMeaning
whenA list of entries, each holding its rule under when: { when: { labels: [hotfix] }, base: release }.
entryA list of entries whose own fact keys are the rule: { labels: [db], paths: ["db/**"], skill: migration-review }.
mapA map from a value of the field’s fact to a result: { bug: kind/bug } is the rule { labels: [bug] } for the result kind/bug.
listA list of values of the field’s fact: [has-migration] is the rule { labels: [has-migration] }.

The settings that use the matcher

FieldFactsListFormWordsRead byMeaning
pull_requests.base_ruleslabelsfirstwhen—do-item, auditThe base branch a pull request targets: the first rule’s base; the integration branch when none matches.
do_item.gateslabels, pathseveryentry—do-item, auditThe review skills that must approve a change before it is pushed.
do_item.guidancelabels, pathseveryentry—do-item, auditThe skills and notes the implementing agent is given.
do_item.agents.labelslabelslookupmap—do-item, work-batchThe agent that implements an item carrying the label.
do_item.agents.codearea_areaslabelslookupmap—do-item, work-batch, dispatchThe change area an item carrying the label reaches, for the area’s agent and guidance.
do_item.agents.title_keywordstitlelookupmap—do-itemThe agent that implements an item whose title holds the keyword, beside the agents its labels choose.
pull_requests.labels_from_issuelabelslookupmap—do-item, auditThe label the pull request opens with for an item carrying the label.
pull_requests.reviewers_from_issuelabelslookupmap—do-itemThe reviewers asked on the pull request for an item carrying the label.
routing.complex_flagslabelsonelist—do-item, auditMakes the item’s complexity tier complex at any size, when the item or an area it reaches carries one of the flags.
routing.raise.flagslabelsonelistcatalog: Every flag an area of the change-area catalog declares.do-item, auditRaises the implementer’s effort one step.
routing.raise.sizessizeonelist—do-item, auditRaises the implementer’s effort one step; unset, the sizes issue_tracker.labels.batch_sizes leaves out.
work_batch.solo_flagslabelsonelist—work-batch, dispatchHolds an item out of a batch, joined to the flags work-batch derives (the human-in-the-loop label and its facets, manual-ops, and every flag the catalog declares).

Machine-readable files

Source: plugin/protocol/rule-matchers.md