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
15 changes: 15 additions & 0 deletions .agents/rules/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ the proof it merged on. A narrow `permissions.allow` rule, which auto mode keeps
`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.

`tools/merge.sh` is how the session merges what `merge-guard.sh` admits: the classifier refused the
merge of luainkernel/lunatik#2744, small, its CI passed and its proof posted, as "Destructive or
Unwanted Actions" in a session started by `/clear` and `continue`, and passed the same command once the
maintainer's words were in the conversation (luainkernel/harness#45). It hands the guard, as a hook
input, the rebase merge it runs, the head named, and runs it only where the guard exits 0, so its own
rule lets through no merge the guard refuses; the command it builds never carries `MERGE_OK=1`, which
the guard reads in the command alone, and its arguments are held to a repository's name, a number and
a full SHA. It reads the token from the file it is handed, as `tools/agent-review.sh` does, under a rule
of the same kind. Each rule names its script by the absolute path of the checkout sessions start in,
which follows master: `merge.sh` runs the `merge-guard.sh` beside it, so a copy in a worktree, where an
edit to the guard or to either script would decide, matches no rule and goes to the classifier. The rule
runs that checkout's tree as it stands, as its hooks do: an edit under its mount, or a commit other than
the one its HEAD pins checked out there, decides the merge with no classifier, and nothing but
`checkout-behind.sh`, which names the second as a session starts, reads either.

`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
28 changes: 18 additions & 10 deletions .agents/skills/merged/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,29 @@ 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:

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>
bash <checkout>/<mount>/tools/agent-review.sh <owner>/<repo> <head> <file that holds the token>
bash <checkout>/<mount>/tools/merge.sh <owner>/<repo> <N> <head> <file that holds the token>

`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
head and not the tree, keeps it, and a later review that returns it not ready withdraws it.
`tools/merge.sh` hands `merge-guard.sh` the merge it runs,
`gh api -X PUT repos/<owner>/<repo>/pulls/<N>/merge -f merge_method=rebase -f sha=<head>`, and runs it
only where the guard passes it, never with `MERGE_OK=1`, and prints GitHub's answer, whose `sha` is the
commit the merge put on the trunk. Each runs as a command of its own, spelled as the `permissions.allow` rule that
allows it spells it, by its absolute path in the checkout sessions start in, with no `GH_TOKEN=` before
it, which no rule matches past: the auto mode classifier refuses the session's own write of the status,
and its merge of a pull request small on a proof, where the conversation holds no order of the
maintainer's, as after a `/clear`. That checkout follows master, and `tools/merge.sh` runs the
`merge-guard.sh` beside it, so a copy in a worktree, where an edit to the guard or to either script
decides, matches no rule and goes to the classifier. 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,
the passage it replaces beside the new one, and the merge names that head. What the review left as
issues is filed before the merge, as implement-issue's last stage files it. A pull request the
maintainer orders merged in his own words takes `MERGE_OK=1`. The steps below follow either merge,
maintainer orders merged in his own words takes `MERGE_OK=1` on the `gh api` merge, run without
`tools/merge.sh`, which never carries it. The steps below follow either merge,
and the report reaches him as it does for his own.

A pull request the maintainer approved in his own words merges the same way, `MERGE_OK=1` on the
Expand Down Expand Up @@ -109,20 +117,20 @@ that runs it (AGENTS.md, *Deciding what to change*).

A pull request of the harness's own repository reaches a project only through the commit its mount
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
trunk, the `sha` the merge answered, which `tools/merge.sh` prints: 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:

bash tools/agent-review.sh <owner>/<harness> <merged commit> <file that holds the token>
bash <checkout>/<mount>/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:

git -C <project checkout>/<mount> fetch origin && git -C <project checkout>/<mount> checkout <merged commit>
git -C <project checkout> add <mount>

The bump merges as section 0 merges a harness pull request, on the project's CI, which runs the shared
The bump merges as section 0 merges a harness pull request, through `tools/merge.sh`, on the project's CI, which runs the shared
checks from the new mount over it, and on the review and the CI of the commit it pins (luainkernel/lunatik#2598,
D102 B): `merge-guard.sh` reads that commit on the harness's trunk, carrying the `agent-review` status and
passing the check runs its push to the trunk started, and asks no status of the bump's own head.
Expand Down
11 changes: 11 additions & 0 deletions tools/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ implement-issue skill runs it before each launch; the commits are read, not obey
GH_TOKEN=... bash tools/issue-since.sh 2131 # names 097d27e13, which added the case the issue asks for
```

## merge.sh

Merges a pull request by rebase, its head named, only where `checks/merge-guard.sh` passes the merge,
and prints GitHub's answer, whose `sha` is the commit the merge put on the trunk (the merged skill,
sections 0 and 5).

```sh
bash tools/merge.sh luainkernel/harness 35 d743e120753d332e8be73475bd1119fb9f077f8a <token file>
# {"sha":"81daee218441d11a3140c796004901311f52985e","merged":true,"message":"Pull Request successfully merged"}
```

## oops.sh

Captures the last kernel oops before a reboot takes it away: the `dmesg` block, the instructions
Expand Down
4 changes: 4 additions & 0 deletions tools/checks/cases/merge-guard.cases
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ pass tok=$(cat key); GH_TOKEN=$tok gh api -X PUT repos/luainkernel/harness/pulls
pass tok=$(cat key); GH_TOKEN=$tok gh api -X PUT repos/luainkernel/lunatik/pulls/14/merge -f merge_method=rebase
block tok=$(cat key); GH_TOKEN=$tok gh api -X PUT repos/luainkernel/lunatik/pulls/15/merge -f merge_method=rebase
block tok=$(cat key); GH_TOKEN=$tok gh api -X PUT repos/luainkernel/lunatik/pulls/16/merge -f merge_method=rebase
# the merge tools/merge.sh hands the guard, the head named and the token in GH_TOKEN, as the script exports it
# env: GH_TOKEN=cases
pass gh api -X PUT repos/luainkernel/lunatik/pulls/7/merge -f merge_method=rebase -f sha=0123456789abcdef0123456789abcdef01234567
block gh api -X PUT repos/luainkernel/lunatik/pulls/8/merge -f merge_method=rebase -f sha=0123456789abcdef0123456789abcdef01234567
27 changes: 27 additions & 0 deletions tools/merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
#
# SPDX-FileCopyrightText: (c) 2026 Ring Zero Desenvolvimento de Software LTDA
# SPDX-License-Identifier: MIT OR GPL-2.0-only
#
# Merges the pull request <N> of the repository <owner>/<repo> by rebase, its head named, and only where
# checks/merge-guard.sh, handed the command this runs, passes it: a harness pull request whose head a
# review passed or a proof names, and a bump of the mount (the merged skill, sections 0 and 5). The
# command never carries MERGE_OK=1, which the guard reads in the command alone, so nothing the guard
# refuses merges here. The session runs it under a narrow permissions.allow rule: the auto mode
# classifier refuses the session's own merge where no order of the maintainer's is in the
# conversation, as after a /clear. Prints GitHub's answer, whose sha is the commit the merge put on the
# trunk.
#
# Usage: bash tools/merge.sh <owner>/<repo> <N> <head> <file that holds the token>

[ $# -eq 4 ] && [[ $1 =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ && $2 =~ ^[0-9]+$ && $3 =~ ^[0-9a-f]{40}$ ]] ||
{ echo "usage: $0 <owner>/<repo> <N> <full head sha> <token file>" >&2; exit 2; }

GH_TOKEN=$(cat "$4" 2> /dev/null)
export GH_TOKEN
merge=(gh api -X PUT "repos/$1/pulls/$2/merge" -f merge_method=rebase -f sha="$3")

jq -nc --arg command "${merge[*]}" '{tool_name: "Bash", tool_input: {command: $command}}' |
bash "$(dirname "$(readlink -f "$0")")/checks/merge-guard.sh" || exit 1
"${merge[@]}"

Loading