Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/fork-pr-queue.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
".github/fork-fleet.json",
".github/fork-owned-paths.txt",
".github/fork-pr-queue.json",
".github/fork-review-kit.json",
".github/fork-removed-workflows.txt",
".github/fork-secret-sweep-gone-tips.txt",
".github/fork-tests-upstream.json",
Expand Down
4 changes: 4 additions & 0 deletions .github/fork-review-kit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": 1,
"queue_config": ".github/fork-pr-queue.json"
}
7 changes: 7 additions & 0 deletions fork-ci/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ nothing.

## After ci/v14

### pr-queue: what counts as a `state:` line is gate code (#797)

`review_judge.has_state_line` holds the rule for a lens report's `state:` line (an answer after the colon, outside code
blocks and quotes). The gate still parses `state_line` without enforcing it, so nothing a caller sees changes. The
review kit (fork-kit/review) now imports this rule and the gate's `head_check.changed_paths` instead of its own
copies, so run the kit from a checkout at the release the gate pins (kit README, "Which fork version").

### pr-queue and head-check: every rule hit gives its lenses (#82)

With a `review` block in `enforce`, the required lenses are now the lenses of every rule a changed path counted for,
Expand Down
13 changes: 13 additions & 0 deletions fork-ci/actions/pr-queue/review_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
until a person's override for the head, newer than every lens comment, lets it through (it alone is enough: it
also waives the approach lens). Owner decision: issue #100.
Pure as judge is: the lens comments come in (lens.Review.lens_scan), the verdict goes out.

has_state_line says what counts as a report's `state:` line (the answer to the state question). The `state_line`
setting is parsed but not enforced yet; the review kit (fork-kit/review, `check`) imports this rule, so the gate and
the kit read one rule when the gate starts enforcing it.
"""
import html
import re
Expand Down Expand Up @@ -367,6 +371,15 @@ def read_findings(body):
return [found[i] for i in sorted(found)], seen >= set(BLOCKING)


STATE_RE = re.compile(r'state\s*:\s*\S', re.I)


def has_state_line(body):
"""A `state:` line with an answer (anything but blanks after the colon), outside fenced and indented code blocks and
quotes, read as a lens header is (folded, markdown and list markers stripped: `**State:** ok`, `- state: ok`)."""
return any(STATE_RE.match(lens.norm_line(fold(raw))) for raw in lens.plain_lines(body))


def findings(body):
"""[(kind, line)] of the report's blocker and major findings (read_findings)."""
return read_findings(body)[0]
Expand Down
13 changes: 13 additions & 0 deletions fork-ci/actions/pr-queue/review_judge.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ def group(name):
return [v for v in FINDINGS if v['group'] == name]


class StateLine(unittest.TestCase):
"""has_state_line: what counts as a report's `state:` line (the review kit imports it; the gate parses
`state_line` but does not enforce it yet)."""

def test_an_answered_state_line_outside_code_and_quotes(self):
for body, said in (('state: a second run does nothing', True), ('**State:** fine', True),
('- state: fine', True), ('STATE : fine', True), ('state:', False), ('state: ', False),
('the state is fine', False), ('```\nstate: fine\n```', False), ('> state: fine', False),
(' state: fine', False)):
with self.subTest(body=body):
self.assertIs(rj.has_state_line(f'lens: code\n{body}\nblocker: none\n'), said)


class Findings(unittest.TestCase):
def test_every_shared_findings_vector(self):
for v in FINDINGS:
Expand Down
31 changes: 16 additions & 15 deletions fork-kit/review/COMMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ minor: <a small thing>; <another>
- **Verdict line (optional):** `verdict: safe to merge` or `verdict: not safe to merge`. A `verdict:` line, or the
first line under the header, that says NOT SAFE is a blocker whatever the labels say.
- **State line:** `state:` and the lens's answer to the state question ("What happens when this runs again, stops
half-way, or meets existing, old or empty state?"). The gate parses the config's `state_line` setting but does not
enforce it yet; the kit's `check` does, and so does every lens prompt the kit writes.
half-way, or meets existing, old or empty state?"). What counts as one is the gate's rule
(`review_judge.has_state_line`); the gate parses the config's `state_line` setting but does not enforce it yet; the
kit's `check` does, and so does every lens prompt the kit writes.
- **Round markers:** a re-read after a fix may add `r2`, `r3` to the lens name (`lens: data-1 r2`). The gate counts
rounds from the different changes lenses read and from these markers, whichever is higher; the marker is not part of
the lens's name (`data-1 r2` is lens `data-1`).
Expand All @@ -48,19 +49,19 @@ minor: <a small thing>; <another>

Each example says, on the line before it, what the gate reads, as words:

| Words | Meaning |
| --------------------- | ----------------------------------------------------------------------------------------------- |
| `lens <key>` | a lens header naming this lens (`lens_key`: lowercased, a trailing round marker dropped) |
| `round <n>` | the header carries round marker `r<n>` |
| `read` | the header names a full sha: this is a read of that head |
| `short sha`, `no sha` | the header's sha is short or missing: no read |
| `clean` | a findings section with no blocker and no major |
| `blocker`, `major` | an open blocker or major: the gate holds the head until a new read on a fixed head, or a person |
| `no findings section` | no blocker and major labels: with `findings` on, the gate does not take the read |
| `state`, `no state` | a `state:` line with an answer, or none |
| `reads nothing` | looks like a lens report but is not one valid read: the gate counts it as a blocking problem |
| `not a lens` | not a lens report at all (a plain comment, or one that opts out with `not a lens:`): ignored |
| `override` | an override comment for that sha (counts only from the configured author association) |
| Words | Meaning |
| --------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `lens <key>` | a lens header naming this lens (`lens_key`: lowercased, a trailing round marker dropped) |
| `round <n>` | the header carries round marker `r<n>` |
| `read` | the header names a full sha: this is a read of that head |
| `short sha`, `no sha` | the header's sha is short or missing: no read |
| `clean` | a findings section with no blocker and no major |
| `blocker`, `major` | an open blocker or major: the gate holds the head until a new read on a fixed head, or a person |
| `no findings section` | no blocker and major labels: with `findings` on, the gate does not take the read |
| `state`, `no state` | a `state:` line with an answer, or none |
| `reads nothing` | looks like a lens report but is not one valid read: the gate counts it as a blocking problem |
| `not a lens` | not a lens report at all (a plain comment, or one that opts out with `not a lens:`): ignored |
| `override` | an override comment for that sha (counts only from the configured author association, never edited and not hidden) |

## Good reports

Expand Down
11 changes: 9 additions & 2 deletions fork-kit/review/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ checkout of the fork.

The kit holds no project facts: which paths are critical and which lenses they need are the project's `review` block
(read by the gate), and who runs a lens is the project's kit settings. The kit imports the gate's own parser
(`config.py`, `lens.py`, `review_judge.py`), so it cannot read a comment or a path differently from the gate; it needs
the fork's `fork-ci/` folder beside it.
(`config.py`, `lens.py`, `review_judge.py`, `head_check.py`), so it cannot read a comment or a path differently from
the gate; it needs the fork's `fork-ci/` folder beside it.

## Which fork version

The kit imports the gate's code from the fork checkout it runs in, not from the release the project's gate pins. A
newer checkout can read comments, paths or the config differently from the pinned gate (a new rule, a new config
key). So run the kit from a checkout at the pinned release: `git -C <fork checkout> checkout <the project's ci/vN
tag>` (the gate's pin is in the project's workflow, gate README "Use it"), and move it when the pin moves.

Tests (no network, no host changes):

Expand Down
17 changes: 14 additions & 3 deletions fork-kit/review/REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ then only reports what it would ask for. Start from the gate's
- `min_lenses`: at least 2 for critical, 1 for normal, 0 for light.
- `rounds`: the gate's own cap. Keep `max` at or above the kit's `lens_rounds` (the plan warns otherwise).
- `findings: true`: the gate holds a head while a lens's newest read has an open blocker or major.
- `state_line: true`: the gate parses it but does not enforce it yet; the kit's `check` does.
- `state_line: true`: the gate parses it but does not enforce it yet; the kit's `check` does, with the gate's own
rule for what counts as a `state:` line (`review_judge.has_state_line`).

Also set the queue config's `lens_format_doc` (a text the gate only quotes in its comments) to where agents read
the format: the kit's [COMMENTS.md](COMMENTS.md) at the fork tag the project pins, or the project's adapter skill
if it links there.

Check it: `python3 -I fork-kit/review/lib/review_kit.py plan --root . --changes <file>` with a
`git diff --name-status -z -M` output, or `--base origin/main` on a branch. A config the gate refuses gives a plain
message and exit 2.
message and exit 2. Run the kit from a fork checkout at the release the project's gate pins (README.md, "Which fork
version").

## 2. Lens prompt files

Expand Down Expand Up @@ -65,7 +67,16 @@ Optional: `.github/review-kit.json`. No file means the defaults. Every key is op
| `state_question` | _What happens when this runs again, stops half-way, or meets existing, old or empty state?_ |

[review-kit.example.json](review-kit.example.json) shows one. An empty file, an unknown key or a wrong value is
refused with a plain message naming every problem, so a typo never turns into a silent default.
refused with a plain message naming every problem, so a typo never turns into a silent default. A project that keeps
the file under another name (the fork: `.github/fork-review-kit.json`, beside its `.github/fork-pr-queue.json`) gives
it with `--settings <file>` to every `plan` and `check`.

**This file or T3's review rules setting:** T3 has a per-machine setting for the same runners (`server.reviewRules`
and `projectOverride.reviewRules`, docs/fork/README.md). Nothing in T3 reads it yet, so today this file decides. Once
T3 starts lenses itself, each decides what it starts: T3's setting the lenses T3 starts on that machine (the
machine's half: which provider and model it has), this file every lens an agent starts by hand from the skill and
what `plan` prints. Keep the two the same; the gate does not read either, so a difference changes cost and recall,
never what passes.

## 5. Enforce

Expand Down
13 changes: 10 additions & 3 deletions fork-kit/review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ critical). A project with **no CI** (no queue config) has no gate: every change
python3 -I fork-kit/review/lib/review_kit.py plan --root <checkout> --base origin/main
```

Run the kit from a fork checkout at the release the project's gate pins (README.md, "Which fork version"). A project
whose kit settings are not at `.github/review-kit.json` adds `--settings <its file>` to every `plan` and `check`.

The plan judges the change with the gate's own rules and prints the tier, the lenses (each with its prompt file and
its runner), why, the state question, the round limit and the minors rule. Do what it says; never pick fewer lenses
by hand. Unsure, or a path the rules do not cover: take the heavier tier. Two independent reads miss different bugs;
Expand Down Expand Up @@ -86,7 +89,8 @@ Each step is done by another agent than the author.
past `rounds.max` it fails the head (in `enforce`; `shadow` only reports both).
- **Which head passes:** the gate passes a head only when every lens's newest read names that head, or an override
comment newer than a lens's read covers it (`<override prefix> <full sha>: <what was read, why no lens>`,
COMMENTS.md; it counts only from the account with the queue config's `override.author_association`). So after a
COMMENTS.md; it counts only from the configured author association, the queue config's
`override.author_association`, and only while it is never edited and not hidden). So after a
fix the lenses of the last round still name the old head, and the fix head passes only when every lens reads it
again (a new round) or the orchestrator posts the override for it (no new round).
- **Nit-only fix:** a fix diff that touches only tests, docs, comments, message text or names (judged by the diff,
Expand All @@ -103,8 +107,11 @@ Each step is done by another agent than the author.
author is in the review block's `override_authors` (empty by default). An orchestrator's override never replaces
the approach lens.
- A note between rounds that is no lens report starts with `not a lens:` (COMMENTS.md).
- **No round past the limit.** A pull request still stuck (a blocker or major left) gets one audit by the
`audit_runner` ("good enough to merge, or what next"), posted as a `not a lens:` comment; then a person decides.
- **No round past the limit.** A fix after the last lens round (`lens_rounds` used up) that is not nit-only, for
example a minor of the last round fixed in code with `minors: same-round`, gets no new lens round: the
orchestrator checks that fix diff itself and posts the override for the fix head. A blocker or major left over
counts as stuck. A pull request still stuck gets one audit by the `audit_runner` ("good enough to merge, or what
next"), posted as a `not a lens:` comment; then a person decides.
8. **Minors** (`minors`, default `issue`): minors and anything left when the pull request stops go into **one**
follow-up issue, with the project's labels, linked on the pull request. With `same-round`, minors are fixed in the
round that found them and any left at the last round are listed in the pull request description with a reason
Expand Down
4 changes: 3 additions & 1 deletion fork-kit/review/eval/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ is a small sample, and 1-2 bugs between settings is noise, but three results sha
mechanism.
5. **Scores:** `review_eval.py cost` reads tokens, $ (from `prices`, $ per million tokens; check the current price
list) and active minutes (gaps over `idle_gap_seconds` dropped) from the transcripts that `transcripts` globs
find, matching each to its run by the `RUN-ID:` first line of the session's first message. `review_eval.py
find, matching each to its run by the `RUN-ID:` first line of the session's first message. A run started as a
sub-agent has its transcript under `<session>/subagents/` (the example config globs those too), and the
sub-agents a run starts itself (`<run session>/subagents/*.jsonl`) count toward that run. `review_eval.py
analyze` gives per config the blocker and major recall (mean and worst run), recall of all findings, false
positives, $ and minutes, the union of every pair of configs, and which known bugs each config missed.
6. **Rule:** use the cheapest setting whose worst-case blocker and major recall equals the best setting's. Check it
Expand Down
2 changes: 1 addition & 1 deletion fork-kit/review/eval/eval.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"repo": "../model-eval/repo.git",
"truth": "truth.json",
"briefs": "briefs",
"transcripts": ["~/.claude/projects/*/*.jsonl"],
"transcripts": ["~/.claude/projects/*/*.jsonl", "~/.claude/projects/*/*/subagents/*.jsonl"],
"prices": {
"claude-opus-5-5": {
"input": 4,
Expand Down
41 changes: 38 additions & 3 deletions fork-kit/review/lib/review_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ def cost(c, out):
for f in sorted(glob.glob(pattern)):
m = RUN_RE.match(_first_user_text(f).lstrip()) # the run's own session starts with its RUN-ID line
if m and m.group(1) in runs:
files.setdefault(m.group(1), []).append(f)
# ... and the sub-agents it started are its cost too: Claude Code keeps them beside the session file,
# in <session>/subagents/*.jsonl. Each file once, however many patterns find it.
subs = os.path.join(glob.escape(f[:-len('.jsonl')]), 'subagents', '*.jsonl')
for g in [f, *(sorted(glob.glob(subs)) if f.endswith('.jsonl') else [])]:
if g not in files.setdefault(m.group(1), []):
files[m.group(1)].append(g)
result = {}
for rid, fs in sorted(files.items()):
usage, times, model = {}, [], None
Expand Down Expand Up @@ -368,6 +373,36 @@ def mean(xs):
return round(statistics.mean(xs), 3) if xs else None


def _list_of(v, ok):
"""Left out (or null), or a list whose every item is ok."""
return v is None or (isinstance(v, list) and all(ok(x) for x in v))


def scores_of(path, name):
"""The `reviews` object of a judge's scores.json, each entry checked against the shape judge_prompt.txt asks for:
`found` a list of truth ids, `findings` a list of objects whose `verdict` is text. Problem naming what is wrong
(never a traceback): a hand-edited or half-written file is judged again, not read halfway."""
s = load_json(path, f'the scores of case {name}')
bad = None
if not isinstance(s, dict) or not isinstance(s.get('reviews'), dict):
bad = 'it is not an object with a "reviews" object'
else:
for review, r in sorted(s['reviews'].items()):
if not isinstance(r, dict):
bad = f'{review} is not an object'
elif not _list_of(r.get('found'), lambda x: isinstance(x, str)):
bad = f'{review}: "found" is not a list of truth ids'
elif not _list_of(r.get('findings'), lambda f: isinstance(f, dict)
and isinstance(f.get('verdict', ''), (str, type(None)))):
bad = f'{review}: "findings" is not a list of objects with a text "verdict"'
if bad:
break
if bad:
raise Problem(f'case {name}: {path} is not in the shape judge_prompt.txt asks for ({bad}): judge the case '
f'again')
return s['reviews']


def analyze(c, cases, out):
runmap_ = {r['id']: r for r in read_runs(c)}
jpath = gt(c, 'judgemap.json')
Expand All @@ -380,12 +415,12 @@ def analyze(c, cases, out):
if name not in cases or not os.path.exists(p):
skipped.append(name)
continue
s = load_json(p, f'the scores of case {name}')
reviews = scores_of(p, name)
t = ids(cases, name)
bm, every = set(t['blocker_major']), set(itertools.chain(*t.values()))
judged.append(name)
for review, rid in sorted(jm[name].items()):
r = (s.get('reviews') or {}).get(review)
r = reviews.get(review)
if not isinstance(r, dict) or rid not in runmap_:
raise Problem(f'case {name}: scores.json has no entry for {review} (or the run map lost {rid}): judge '
f'the case again')
Expand Down
Loading
Loading