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
16 changes: 15 additions & 1 deletion .agents/rules/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ that it is a harness pull request an agent's review passed: opened by the postin
repository's default branch, as GitHub names it,
every file the harness as `harness-mixed.sh --outside` reads it, the mount a bump moves among them, or
any file of the harness's own repository, and a head that carries the
`agent-review` status, which the merged skill sets once `review.js` returned that head ready, or, on a
`agent-review` status, which `tools/agent-review.sh` sets once `review.js` returned that head ready, or, on a
pull request `complexity.sh` calls small, a comment of the posting account that names that head, the
proof a mechanical change merges on (AGENTS.md, *Patches and commits*), and
passed every check run, and commits none of which is a `fixup!`, `amend!` or `squash!`, which the
Expand All @@ -259,6 +259,20 @@ head, the check branch protection requires; the guard reads it itself, since bra
maintainer's setting and would gate his own merges. `MERGE_OK=1` merges one he ordered merged in his
own words.

`tools/agent-review.sh` is how the session writes that status: the auto mode classifier refused its
own write three times on 2026-11-26, as "Undermining Oversight", in a session started by `/clear` and
`continue`, whose conversation held none of the maintainer's orders to merge (luainkernel/harness#33).
It reads the pass where Claude Code keeps it, under its projects directory: the newest reviewer, the
agent a workflow labels `review:<pr or branch>`, of a run whose record names the repository in
`args.github`, on a tip whose tree is the commit's, whose transcript ran at `high` effort or above,
and whose answer in the run's `journal.jsonl` is ready with no mechanism kept without a source. It reads the
reviewer's answer and not the run's, which a reader that fails the body turns to not ready, since
`pr-body-guard.sh` holds the body to its reader as it opens. A commit a rebase merge put on the trunk,
whose tree a base that moved changes, passes on the head of the pull request that merged as it, or on
the proof it merged on. A narrow `permissions.allow` rule, which auto mode keeps where it drops
`Bash(*)`, runs it with no classifier, and a `GH_TOKEN=` before the command is past what a rule
matches, so the script reads the token from the file it is handed.

`fixup-guard.sh`, wired before a shell call, refuses opening a pull request whose head, compared on GitHub
with its base, carries a `fixup!`, `amend!` or `squash!` commit: a pull request reaches the maintainer's first
review squashed, and a fixup is how he reads what changed after it. `FIXUPS_OK=1` opens one that is not the
Expand Down
14 changes: 10 additions & 4 deletions .agents/skills/merged/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ ready, its fixups folded and pushed, and the CI passed on the head that carries
pass goes on that head as a commit status, and the merge names the head, so a push after either is
refused, by `merge-guard.sh` and by GitHub:

gh api -X POST repos/<owner>/<repo>/statuses/<head> -f state=success -f context=agent-review -f description='review.js: ready'
bash tools/agent-review.sh <owner>/<repo> <head> <file that holds the token>
gh api -X PUT repos/<owner>/<repo>/pulls/<N>/merge -f merge_method=rebase -f sha=<head>

A fold moves the head and not the tree: the status goes on the folded head when its tree is the one
the review returned, `git rev-parse <tip>^{tree}` against `<head>^{tree}`. One that
`tools/agent-review.sh` sets the status only on the review's own record, the newest reviewer at `high`
effort or above of a tip whose tree is the head's, when it returned ready, so a fold, which moves the
head and not the tree, keeps it, and a later review that returns it not ready withdraws it. It runs as a command of its own, spelled as the `permissions.allow` rule that
allows it spells it, with no `GH_TOKEN=` before it, which no rule matches past:
the auto mode classifier refuses the session's own write of the status where the conversation holds
no order of the maintainer's, as after a `/clear`. One that
`tools/complexity.sh <N> <owner>/<repo>` calls small merges on a proof in place of the review: a
comment on it, opened by GitHub's note that an LLM wrote it, naming its head beside the command that
shows the defect before, its result after and the case still refused, or, for text no command reads,
Expand Down Expand Up @@ -107,8 +111,10 @@ A pull request of the harness's own repository reaches a project only through th
points at. Once one merges, its `agent-review` status goes on the commit the merge put on the harness's
trunk, the `sha` the merge answered: the rebase gave the reviewed head a new SHA, and a bump is read on
that one. A small one merged on its proof takes the status too, its description naming the proof.
`tools/agent-review.sh` reads which of the two the merged pull request was, through the record of the
review of its head or the comment that proves it, and refuses a commit that merged on neither:

gh api -X POST repos/<owner>/<harness>/statuses/<merged commit> -f state=success -f context=agent-review -f description='review.js: ready'
bash tools/agent-review.sh <owner>/<harness> <merged commit> <file that holds the token>

Each project that mounts the harness then takes a pull request of its own that moves the mount to the
merged commit, its trunk's tip, and nothing else, a harness pull request of that project:
Expand Down
11 changes: 11 additions & 0 deletions tools/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
Each GitHub tool here reads the repository the checkout's `origin` names, and `issues.sh`,
`issue-since.sh` and `pr-status.sh` another one `LUNATIK_REPO` names.

## agent-review.sh

Sets the `agent-review` status `checks/merge-guard.sh` reads on a commit, and only where the record
of a review passed it: the newest review of it, or of a commit of its tree, that `review.js` ran at
`high` effort or above returned it ready, or, for a commit a merge put on the trunk, the pull request it
merged was reviewed so or merged on its proof (the merged skill, sections 0 and 5).

```sh
bash tools/agent-review.sh luainkernel/harness 1fdae56 <token file> # agent-review: 1fdae56ae: review.js: ready, wf_1a941637-11a at high
```

## complexity.sh

Prints the `complexity:` label each pull request carries, by the lines it adds: up to 40 `small`, up to
Expand Down
103 changes: 103 additions & 0 deletions tools/agent-review.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
#
# SPDX-FileCopyrightText: (c) 2026 Ring Zero Desenvolvimento de Software LTDA
# SPDX-License-Identifier: MIT OR GPL-2.0-only
#
# Sets the agent-review status, which merge-guard.sh reads, on the commit <sha> of the repository
# <owner>/<repo>, and only on the record of an agent's review that passed it. A head passes when the
# newest reviewer at high effort or above, the agent a workflow labels review:<pr or branch> as review.js
# labels its Review phase, alone or nested in implement-issue, of a tip whose tree is the head's returned
# ready, with no mechanism kept without a source. Its answer is read in its run's journal, before a reader of
# the body sets the run's ready to false, since the body is held to its reader as it opens, and its
# effort in its transcript, both under Claude Code's projects directory. The commit a rebase merge put
# on the trunk passes when a reviewer so returned the head of the pull request it merged, or that pull
# request merged on its proof (the merged skill, sections 0 and 5). The session runs it under a narrow
# permissions.allow rule: the auto mode classifier refuses the session's own write of the status where
# no order of the maintainer's is in the conversation, as after a /clear.
#
# Usage: bash tools/agent-review.sh <owner>/<repo> <sha> <file that holds the token>

[ $# -eq 3 ] || { echo "usage: $0 <owner>/<repo> <sha> <token file>" >&2; exit 2; }
. "$(dirname "$(readlink -f "$0")")/checks/commands.sh"

repo=$1
GH_TOKEN=$(cat "$3" 2> /dev/null)
export GH_TOKEN
projects=${CLAUDE_CONFIG_DIR:-$HOME/.claude}/projects

refuse() {
echo "agent-review: $*, so no status is set" >&2
exit 1
}

# the tree of the commit <sha>, read in the checkout <dir> when it holds the commit, else on GitHub
tree() {
git -C "${2:-.}" rev-parse -q --verify "$1^{tree}" 2> /dev/null ||
gh api "repos/$repo/git/commits/$1" --jq .tree.sha 2> /dev/null
}

# each reviewer of the repository's runs, newest first, a line each: when its run ended, whether it
# returned ready with no mechanism kept without a source, its tip, its transcript and the checkout its run
# worked in
reviewers() {
local journal run meta stamp checkout
grep -l '"label":"review:' "$projects"/*/*/subagents/workflows/*/journal.jsonl 2> /dev/null | while IFS= read -r journal; do
run=$(dirname "$journal")
meta=$(jq -er --arg repo "$repo" 'select((.args.github? // "" | ascii_downcase) == ($repo | ascii_downcase)) |
[.timestamp, .args.repo // ""] | @tsv' "${run%/subagents/workflows/*}/workflows/${run##*/}.json" 2> /dev/null) || continue
read -r stamp checkout <<< "$meta"
jq -rs --arg stamp "$stamp" --arg run "$run" --arg checkout "$checkout" '
[.[] | select(.type == "started" and (.label // "" | startswith("review:"))) | .agentId] as $reviewers
| [.[] | select(.type == "result" and (.agentId as $id | $reviewers | any(. == $id)) and (.result.tip // "") != "")] | reverse[]
| (.result.ready == true and
([.result.smallest.beyond[]? | select(.verdict == "kept" and ((.source // "") | test("^\\s*$")))] | length == 0)) as $ready
| [$stamp, (if $ready then "ready" else "not" end), .result.tip, "\($run)/agent-\(.agentId).jsonl", $checkout]
| @tsv' "$journal" 2> /dev/null
done | sort -s -r -t $'\t' -k 1,1
}

# the status's description when the newest review, at high effort or above, of the commit <sha> or of one
# of the tree <tree> returned it ready; nothing, and a failure, when none did or the newest did not
recorded() {
local stamp verdict tip transcript checkout effort
while IFS=$'\t' read -r stamp verdict tip transcript checkout; do
[ "$tip" = "$1" ] || [ "$(tree "$tip" "$checkout")" = "$2" ] || continue
effort=$(jq -r 'select(.type == "assistant") | .effort // empty' "$transcript" 2> /dev/null | tail -n 1)
case $effort in
high|xhigh|max) ;;
*) continue ;;
esac
[ "$verdict" = ready ] || return 1
echo "review.js: ready, $(basename "$(dirname "$transcript")") at $effort"
return
done < <(reviewers)
return 1
}

# gh prints the body of an error where the answer would be, so each lookup is read by its exit status
commit=$(gh api "repos/$repo/commits/$2" --jq '[.sha, .commit.tree.sha] | @tsv' 2> /dev/null) ||
refuse "GitHub did not answer for $2 in $repo"
read -r sha tree <<< "$commit"

if ! description=$(recorded "$sha" "$tree"); then
merged=".[] | select(.merged_at != null and .merge_commit_sha == \"$sha\") | [.number, .head.sha] | @tsv"
pulls=$(gh api "repos/$repo/commits/$sha/pulls" --jq "$merged" 2> /dev/null) ||
refuse "GitHub did not answer for the pull requests of ${sha:0:9}"
read -r number head <<< "$(printf '%s\n' "$pulls" | head -n 1)"
if [ -z "$number" ]; then
refuse "the newest review at high effort of ${sha:0:9}, or of a commit of its tree, is not ready or none ran, and no pull request merged as it"
# a base that moved before the merge gives the trunk commit a tree no reviewer returned
elif reviewed=$(recorded "$head" "$(tree "$head")"); then
description="merged from #$number, $reviewed"
elif gh_proved "$repo" "$number" "$(gh api user --jq .login 2> /dev/null)" "$head"; then
description="merged from #$number on its proof"
else
refuse "the newest review at high effort of ${head:0:9}, the head of #$number, is not ready or none ran," \
"nor does a proof name it"
fi
fi

gh api -X POST "repos/$repo/statuses/$sha" -f state=success -f context=agent-review -f description="$description" \
--jq .state > /dev/null || refuse "GitHub refused the status on ${sha:0:9}"
echo "agent-review: ${sha:0:9}: $description"

9 changes: 9 additions & 0 deletions tools/checks/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,15 @@ gh_trunk() {
printf '%s\n' "${trunk:-$(project_trunk "$(input_cwd "$1")")}"
}

# whether the pull request <number> of the repository <repo> adds what complexity.sh calls small, and a
# comment of the account <login> on it names its head <sha>, the proof a mechanical change merges on,
# asked with GH_TOKEN
gh_proved() {
[ "$(bash "$(harness_root)/tools/complexity.sh" "$2" "$1" 2> /dev/null)" = "complexity: small" ] &&
gh api "repos/$1/issues/$2/comments?per_page=100" --paginate --jq ".[] | select(.user.login == \"$3\") | .body" 2> /dev/null |
grep -qF "${4:0:9}"
}

# whether the gh write <post> publishes to one of the repositories <repos>, owner/name a line, as gh_self
# names the checkout's, or to a fork of one, as one that names no other does
gh_ours() {
Expand Down
10 changes: 1 addition & 9 deletions tools/checks/merge-guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ passed() {
[ -n "$checks" ] && ! printf '%s\n' "$checks" | grep -vqxE 'success|skipped|neutral'
}

# whether the pull request <number> of the repository <repo> adds what complexity.sh calls small, and a
# comment of the account <login> on it names its head <sha>, the proof a mechanical change merges on
proved() {
[ "$(GH_TOKEN=$token bash "$checks/../complexity.sh" "$2" "$1" 2>/dev/null)" = "complexity: small" ] &&
github "repos/$1/issues/$2/comments?per_page=100" --paginate --jq ".[] | select(.user.login == \"$3\") | .body" |
grep -qF "${4:0:9}"
}

# the repository and the commit, "<owner>/<name> <sha>", the pull request of the repository <repo> whose head
# is <head> pins when its one file, <path>, is a submodule; nothing for any other
pinned() {
Expand Down Expand Up @@ -122,7 +114,7 @@ while IFS= read -r merge; do
reviewed "$upstream" "$pin" || refuse "${pin:0:9}, which #$number pins, carries no agent-review status"
passed "$upstream" "$pin" || refuse "the CI of ${pin:0:9}, which #$number pins, has not passed"
else
reviewed "$repo" "$head" || proved "$repo" "$number" "$login" "$head" ||
reviewed "$repo" "$head" || GH_TOKEN=$token gh_proved "$repo" "$number" "$login" "$head" ||
refuse "the head of #$number, ${head:0:9}, carries no agent-review status, nor a proof that names it"
fi
passed "$repo" "$head" || refuse "the CI of ${head:0:9} has not passed"
Expand Down
Loading