# review-priority - the rule-file format

<!-- toc -->
- [Where rule files live](#where-rule-files-live)
- [The corporate baseline](#the-corporate-baseline)
- [The parts of a file](#the-parts-of-a-file)
- [Rule ids](#rule-ids)
- [Decision order](#decision-order)
- [Evaluations](#evaluations)
- [Writes](#writes)
<!-- /toc -->

`/multi-agent:review-priority` grades a team's open bugs against that team's
rule file. The engine, `scripts/priority-review.mjs`, holds nothing
team-specific: which bugs are fetched, which fields are shown as evidence and
which rule ids an evaluation may cite all come from the file. A team that
writes one file gets the command.

## Where rule files live

One file per team in the rules directory: `prefs.global.reviewPriority.rulesDir`,
default `~/.claude/routine-assets/review-priority/rules/`. Run data (the Jira
snapshot and the evaluations) goes to `runs/` beside it.
`priority-review.mjs paths` prints both. A file that does not parse is listed
by `teams` as skipped, with its reason, and is never offered.

Start from `multi-agent-refs/review-priority/rules/example.md`: copy it to
`<rulesDir>/<slug>.md` and edit it.

## The corporate baseline

`corporate.md` in the same directory is optional. When it exists, its rule
rows apply to every team, and it is never offered as a team itself. A team's
own row with the same id replaces the baseline row for that team; every other
team keeps the baseline. A team file may then carry only its frontmatter, its
`jira-selection` block and the rules that are its own (PRI-100 and up, or the
ids it overrides).

`priority-review.mjs rules --team <slug>` prints the merged set, each row with
the file it came from, and `teams --json` lists each team's overrides. The
report names the baseline in its header and ends with a table of every cited
rule id and its file. A `corporate.md` that does not parse makes every team
unusable rather than silently dropping the baseline; `teams` says why.

## The parts of a file

1. **Frontmatter.** `team` is the display name used in the picker and the
   report title; `slug` must equal the file name without `.md`. `directorate`
   is read as a synonym of `team`.
2. **The `jira-selection` block.** A fenced code block whose info string is
   exactly `json jira-selection`, holding one JSON object:

   | Key | Required | Meaning |
   |---|---|---|
   | `base` | yes | JQL every preset is ANDed with, normally `issuetype = Bug` |
   | `default` | yes | id of the preset used when none is chosen |
   | `presets` | yes | list of `{id, label, jql}`; the label is shown in the picker |
   | `order` | no | the `ORDER BY` clause, default `created DESC` |
   | `evidenceFields` | no | `{fieldId: label}`; each field is fetched and shown under its label. Instance-specific custom field ids belong here, never in the engine |

   `fetch` builds `base AND (preset) [AND created >= -Nd] [AND (extra)]`, so a
   free-text filter can narrow a preset but never drop `base`.
3. **Rules.** Markdown table rows that start with `| PRI-nnn |`. Every such
   row is a rule id; an evaluation citing an id neither this file nor the baseline has is
   refused. Ids are stable: change a rule's wording, keep its id, so past
   reports still read.

## Rule ids

The example file uses one scheme; keep it when you write your own, so
evaluations and reports compare across teams:

| Range | Content |
|---|---|
| PRI-001..009 | principles: impact, not urgency; what never raises a level |
| PRI-010..015 | Critical, and what is not Critical on its own |
| PRI-020..024 | High |
| PRI-030..034 | Medium |
| PRI-040..042 | Low, and what is never Low |
| PRI-050 | the decision order |
| PRI-060..061 | evidence the record should carry; consistency |
| PRI-070..073 | the decision matrix |
| PRI-080 | the triage checklist |
| PRI-090 | roles: the review proposes, people decide |
| PRI-100 and up | the team's own mappings of the generic rules onto its flows |

A team mapping (PRI-1xx) names the generic rule it derives from, so a reader
can tell a derivation from a rule.

## Decision order

The evaluator applies PRI-050 to every bug: is it a defect; which flow; does
the flow complete; is there a workable workaround; what is at risk; then the
level, with urgency and release impact as a separate note. When the record
does not say enough to run those steps, the verdict is `insufficient` and
`missing` lists what PRI-060 asks for.

## Evaluations

`report` reads one JSON object per fetched bug:

```json
{"key": "ABC-1", "proposed": "High", "rules": ["PRI-020", "PRI-023"],
 "evidence": ["Environment = Test", "description: \"retry succeeds\""],
 "confidence": "high", "verdict": "too_low",
 "missing": [], "reason": "One sentence in the output language."}
```

It refuses the file when a bug has no evaluation or two, a verdict is not one
of `too_high`, `too_low`, `insufficient`, `correct`, a rule id is unknown, the
confidence is not `high`, `medium` or `low`, an `insufficient` verdict has no
`missing` items, a verdict disagrees with the current and proposed levels, or
a non-`insufficient` verdict has no evidence. A current level outside
Critical, High, Medium, Low can only be `insufficient`.

## Writes

The engine writes to Jira in one place. `propose` reads the live issue and
prints the change and a token derived from the issue key, the current and new
level and the issue's last update time. `apply` reads the issue again,
recomputes the token and refuses when it differs, so a level someone else
changed in between is never overwritten. It sets the priority field and
nothing else. Both refuse when `MULTI_AGENT_UNATTENDED=1`.
