From 46b1f308ebeb3f9e577d554e090b8dc9d3fe1f40 Mon Sep 17 00:00:00 2001 From: Lourival Vieira Neto Date: Thu, 26 Nov 2026 21:54:03 -0300 Subject: [PATCH] merged: a script runs the merges merge-guard.sh admits The auto mode 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. A merge on a proof sets no status before it runs, so nothing the session does after a clear lets it through, and a small pull request waits on him. tools/merge.sh hands merge-guard.sh, as a hook input, the rebase merge it runs, the head named, and runs it only where the guard exits 0, so a narrow permissions.allow rule over it lets through what the guard admits and nothing else: the command never carries MERGE_OK=1, which the guard reads in the command alone, and the 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 (#35), and prints GitHub's answer, whose sha section 5 of the merged skill reads for the status and the bumps. Sections 0 and 5 merge through it; a merge the maintainer ordered in his own words keeps MERGE_OK=1 on the gh api call. The merge-guard cases hold the guard to the command the script hands it, the token in GH_TOKEN. The rules go in the maintainer's own settings, not in a tracked file, which would bind every session opened on the checkout, and each names its script by the absolute path of the checkout sessions start in. merge.sh runs the merge-guard.sh beside it, so a rule that matched the relative `bash tools/merge.sh` in any directory would let a worktree whose guard or script an edit changed decide a merge with no classifier; the same holds of agent-review.sh, whose rules matched the relative spelling since #35, and the skill now spells both from that checkout. The rule runs that checkout's tree as it stands, as its hooks do, so an edit under its mount still decides a merge with no classifier. Closes #45 Co-Authored-By: Claude Opus 5.5 --- .agents/rules/checks.md | 15 +++++++++++++++ .agents/skills/merged/SKILL.md | 28 ++++++++++++++++++---------- tools/Readme.md | 11 +++++++++++ tools/checks/cases/merge-guard.cases | 4 ++++ tools/merge.sh | 27 +++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 10 deletions(-) create mode 100755 tools/merge.sh diff --git a/.agents/rules/checks.md b/.agents/rules/checks.md index af1f2e7..cd9d01b 100644 --- a/.agents/rules/checks.md +++ b/.agents/rules/checks.md @@ -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 diff --git a/.agents/skills/merged/SKILL.md b/.agents/skills/merged/SKILL.md index c8d8323..263bbae 100644 --- a/.agents/skills/merged/SKILL.md +++ b/.agents/skills/merged/SKILL.md @@ -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 / - gh api -X PUT repos///pulls//merge -f merge_method=rebase -f sha= + bash //tools/agent-review.sh / + bash //tools/merge.sh / `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///pulls//merge -f merge_method=rebase -f sha=`, 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 /` 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 @@ -109,12 +117,12 @@ 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 / + bash //tools/agent-review.sh / 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: @@ -122,7 +130,7 @@ merged commit, its trunk's tip, and nothing else, a harness pull request of that git -C / fetch origin && git -C / checkout git -C add -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. diff --git a/tools/Readme.md b/tools/Readme.md index a815198..0c6504a 100644 --- a/tools/Readme.md +++ b/tools/Readme.md @@ -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 +# {"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 diff --git a/tools/checks/cases/merge-guard.cases b/tools/checks/cases/merge-guard.cases index f5ca5c8..4fd8194 100644 --- a/tools/checks/cases/merge-guard.cases +++ b/tools/checks/cases/merge-guard.cases @@ -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 diff --git a/tools/merge.sh b/tools/merge.sh new file mode 100755 index 0000000..164eb16 --- /dev/null +++ b/tools/merge.sh @@ -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 of the repository / 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 / + +[ $# -eq 4 ] && [[ $1 =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ && $2 =~ ^[0-9]+$ && $3 =~ ^[0-9a-f]{40}$ ]] || + { echo "usage: $0 / " >&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[@]}" +