From cfe1c22bc2e6bbdfab1893c6235f4cd4b9a500fd Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 10 Oct 2026 10:57:33 -0500 Subject: [PATCH 1/4] docs: repository execution rules (adopted 2026-10-10) Co-authored-by: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- docs/REPOSITORY_EXECUTION_RULES.md | 197 +++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 docs/REPOSITORY_EXECUTION_RULES.md diff --git a/docs/REPOSITORY_EXECUTION_RULES.md b/docs/REPOSITORY_EXECUTION_RULES.md new file mode 100644 index 0000000..a9736fe --- /dev/null +++ b/docs/REPOSITORY_EXECUTION_RULES.md @@ -0,0 +1,197 @@ +# AIEN Repository Execution Rules + +## Adoption + +Adopted 2026-10-10 from Drake's revised rules for the six-issue campaign (interplane#97 and #98, aien-sovereign-core#397 and #398, aegis-runtime#38 and #39). Tooling: `scripts/pr-gate.sh` and `scripts/rebase-crumb.sh`. + +## Recorded facts (2026-10-10) + +- (a) Branch protection read from GitHub: interplane requires the checks schemas-and-fixtures, rust, python, cross-language, adapter-aien and adapter-odysseus, in strict mode, with no review count. aien-sovereign-core requires the check "Workspace Verification & Invariant Audit", 0 reviews, enforce_admins on. aegis-runtime requires the check "Test & Invariant Verification", 0 reviews, enforce_admins on. Therefore `--admin` is never needed for a green PR. +- (b) interplane has no .crumb files, so the crumb step is skipped there with a notice. aegis-runtime and aien-sovereign-core use crumbs. +- (c) INTERPLANE carries a Python SDK by Drake's 2026-10-04 direction (approved exception). The Motus adapter for interplane#97 lives only under interplane adapters/motus. No Python enters any AIEN-owned repository. + + +These rules apply to Claude Code, all delegated workers, and all repositories involved in this implementation campaign. + +The objective is to ship verified code without corrupting shared branches, bypassing security requirements, or creating unnecessary integration conflicts. + +## 1. Source of Truth + +GitHub main is authoritative. Inspect current code, tests, active PRs, and repository instructions before editing. + +Never implement an issue solely from its description. Check whether the functionality already exists or has been superseded. + +Use separate branches and worktrees for concurrent development. + +One worker owns each writable worktree. Never allow two workers to modify the same worktree concurrently. + +## 2. Crumb Compilation + +Every applicable PR must have `.crumb` compilation and verification completed after its final source change. + +Required commands: `crumb compile .` then `crumb verify .` + +Commit generated `.crumb` changes separately as the final commit. + +Do not modify source files after that commit without rerunning compilation and verification. + +If a repository does not support these commands, report the discrepancy and follow its explicit repository policy. Never silently skip a required check. + +## 3. Rebase and Crumb Conflicts + +Every sovereign-core merge to main can invalidate `.crumb` files in other open PRs. + +After each sovereign-core merge, evaluate remaining PRs for drift. + +Approved recovery script: `scripts/rebase-crumb.sh ` (this repository). + +Before running it: + +- Confirm the worktree has no uncommitted changes. +- Confirm the intended branch and remote. +- Inspect the script before first use. +- Preserve the expected remote head for force-with-lease protection. +- Ensure no other worker is writing to that branch. + +The script takes main's `.crumb`, recompiles crumbs as the last commit, and pushes with lease. + +If it reports CODE CONFLICT, stop automated rebasing for that branch. Resolve the source conflict before recompiling. + +Never discard source changes to manufacture a clean rebase. + +Do not rewrite another worker's branch without coordination. + +## 4. Definition of CLEAN + +A PR may merge only when all of the following hold: + +- Working tree is clean. +- Changes are based on the intended current main. +- No unresolved merge conflicts. +- Required compilation and crumb verification pass. +- Required tests and CI checks pass. +- Required approvals are present and valid. +- GitHub reports a mergeable state. +- No outstanding blocking security findings. +- The final diff contains no unintended changes. +- The implementation satisfies the linked issue's acceptance criteria. + +Do not equate GitHub's CLEAN merge-state label with complete verification. + +## 5. Merge Procedure + +Serialize merges into each repository's main branch. + +Default command: `gh pr merge N -R aien-dev/ --squash --delete-branch` + +Only use `--admin` when explicitly authorized for that specific PR and when the required project governance permits it. + +Never use administrative privileges to hide failing tests, missing approvals, security findings, or unresolved conflicts. + +After every merge, refresh main and revalidate dependent or competing PRs. + +## 6. GitHub PR Editing + +The normal `gh pr edit` workflow is currently unreliable in this environment. + +Use the API fallback: `gh api -X PATCH repos/aien-dev//pulls/N -F body=@file` + +Verify the returned response and fetch the PR afterward to confirm the update. + +Do not assume an API operation succeeded merely because the command exited. + +## 7. Language and Runtime Constraints + +No Python or systemd may be introduced as part of this campaign. + +Use Rust for AIEN-owned runtime, orchestration, adapters, and execution control. + +Motus may run externally using its own dependencies, but the AIEN integration must communicate over an explicitly verified protocol boundary. + +If a task requires Python inside an AIEN-owned repository, treat it as an architectural conflict. Redesign it or report the blocker before proceeding. + +Existing Python files do not authorize adding more Python. Flag any conflict with the strict repository policy rather than silently ignoring it. + +## 8. Command Hooks + +A local Bash hook rejects certain command text containing accelerator or kernel-module related terms. + +Do not embed source-file contents containing these terms into Bash commands or heredocs. Use the approved Write tool for file creation and editing. + +Do not attempt to bypass restrictions on executing prohibited operations. + +If an approved development command is incorrectly blocked, report the exact failure and use an authorized alternative. + +## 9. Commits and Attribution + +Use small, logically isolated commits. + +Required commit trailers, when attribution accurately reflects the contributors: + +`Co-authored-by: Drake Stapleton ` +`Co-Authored-By: Claude Fable 5.1 ` + +Do not invent contributors or misrepresent authorship. + +Required PR footer: 🤖 Generated with [Claude Code](https://claude.com/claude-code) + +Every PR must reference its issue, describe its implementation, identify verification performed, and disclose limitations. + +## 10. Worker Models and Verification + +Use Sonnet for delegated implementation workers unless instructed otherwise. + +Workers may inspect, implement, test, and propose solutions within their assigned ownership boundaries. + +A worker's claim of completion is not verification. + +The coordinating agent must independently inspect every worker's changes and verify relevant tests, security invariants, and actual GitHub state. + +Do not accept unsupported claims about test passes, hardware performance, successful merges, or completed integrations. + +Use an independent reviewer for security-sensitive changes. + +## 11. Failure Handling + +Do not repeatedly retry the same failing operation without identifying the cause. + +On failure: + +1. Capture the exact failure and affected commit. +2. Determine whether it is source-related, environmental, or caused by concurrent changes. +3. Apply the smallest justified correction. +4. Rerun the affected verification. +5. Escalate or isolate persistent blockers without destroying valid work. + +Never force-push another worker's changes away. + +Never turn off tests, security checks, or authorization rules merely to make a PR merge. + +## 12. Communication + +Use plain English when reporting to Drake. Do not use em dashes or en dashes. + +Provide concise updates that identify completed work, active work, blockers, and next actions. + +Do not confuse attempted operations with completed operations. + +## 13. Final Delivery + +Before declaring the campaign complete: + +- Verify every merged PR against its issue. +- Check relevant cross-repository interfaces. +- Run integration tests. +- Confirm no unintended dependency or architecture changes. +- Report remaining failed, skipped, or unavailable verification. +- Confirm final GitHub issue and PR status. + +A task is complete only when the implementation, verification, and required integration are finished. + +## 14. Worker Instructions + +Worker briefs live with each campaign; this document wins when they conflict. + +Stable rules and validated scripts live in aien-architecture (`docs/REPOSITORY_EXECUTION_RULES.md`, `scripts/pr-gate.sh`, `scripts/rebase-crumb.sh`). + +**Operating principle: Ship correct, verified code. Preserve other workers' changes. Protect main. Never trade correctness for apparent progress.** From ed0ee4c241fcce33be26f844995eb126d258257d Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 10 Oct 2026 10:58:33 -0500 Subject: [PATCH 2/4] scripts: hardened rebase-crumb.sh with offline test Co-authored-by: Drake Stapleton Co-Authored-By: Claude Fable 5.1 --- scripts/rebase-crumb.sh | 93 +++++++++++++++++++++++++ scripts/test_rebase_crumb.sh | 127 +++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) create mode 100755 scripts/rebase-crumb.sh create mode 100755 scripts/test_rebase_crumb.sh diff --git a/scripts/rebase-crumb.sh b/scripts/rebase-crumb.sh new file mode 100755 index 0000000..4918785 --- /dev/null +++ b/scripts/rebase-crumb.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# Rebase a PR branch onto origin/main, resolve conflicts that are only in .crumb files by taking +# main's copy, recompile crumbs as a fresh last commit, and push with a lease on the old head. +# +# Usage: rebase-crumb.sh +# Env: GIT (default git), CRUMB (default crumb), so tests can stub the tools. +# Exit: 0 done, 2 precondition refused, 3 CODE CONFLICT (rebase aborted), 4 crumb or rebase failure +# (nothing pushed). +set -u +GIT=${GIT:-git} +CRUMB=${CRUMB:-crumb} +TRAILERS='Co-authored-by: Drake Stapleton +Co-Authored-By: Claude Fable 5.1 ' + +refuse() { echo "REFUSED: $1" >&2; exit 2; } + +[ $# -eq 2 ] || { echo "usage: rebase-crumb.sh " >&2; exit 2; } +W=$1; B=$2 +cd "$W" 2>/dev/null || refuse "worktree $W does not exist" +$GIT rev-parse --is-inside-work-tree >/dev/null 2>&1 || refuse "$W is not a git checkout" +[ -z "$($GIT status --porcelain)" ] || refuse "working tree is not clean" +[ "$B" != "main" ] || refuse "branch is main" +URL=$($GIT config --get remote.origin.url 2>/dev/null) || refuse "no origin remote" +case "$URL" in + *github.com/aien-dev/*|*git@github.com:aien-dev/*) ;; + *) refuse "origin URL is not under aien-dev: $URL" ;; +esac +$GIT fetch -q origin || refuse "fetch failed" +$GIT rev-parse -q --verify "refs/remotes/origin/$B" >/dev/null || refuse "origin/$B does not exist" + +GD=$($GIT rev-parse --git-dir) +LOCK="$GD/rebase-crumb.lock" +if [ -e "$LOCK" ] && [ -z "$(find "$LOCK" -mmin +120 2>/dev/null)" ]; then + refuse "lock $LOCK is fresh (another run, or younger than 2 hours)" +fi +echo $$ > "$LOCK" || refuse "cannot create lock" +trap 'rm -f "$LOCK"' EXIT + +LEASE=$($GIT rev-parse "origin/$B") +$GIT checkout -q -B "$B" "origin/$B" || { echo "checkout failed" >&2; exit 4; } + +rebasing() { [ -d "$($GIT rev-parse --git-path rebase-merge)" ] || [ -d "$($GIT rev-parse --git-path rebase-apply)" ]; } + +$GIT rebase -q origin/main >/dev/null 2>&1 +while rebasing; do + C=$($GIT diff --name-only --diff-filter=U) + if [ -z "$C" ]; then + GIT_EDITOR=true $GIT rebase --continue >/dev/null 2>&1 && continue + # A resolved commit that became empty cannot be continued; skip it. + if [ -z "$($GIT diff --cached --name-only)" ]; then + $GIT rebase --skip >/dev/null 2>&1 && continue + fi + echo "rebase continue failed" >&2; $GIT status --short | head; $GIT rebase --abort; exit 4 + fi + NONCRUMB=$(echo "$C" | grep -v '\.crumb$' || true) + if [ -n "$NONCRUMB" ]; then + echo "CODE CONFLICT: $(echo "$NONCRUMB" | tr '\n' ' ')" + $GIT rebase --abort + exit 3 + fi + # During a rebase "ours" is the branch being rebased onto, which is main. + echo "$C" | while IFS= read -r f; do + if $GIT cat-file -e "origin/main:$f" 2>/dev/null; then + $GIT checkout -q --ours -- "$f" && $GIT add -- "$f" + else + $GIT rm -q -f -- "$f" + fi + done + GIT_EDITOR=true $GIT rebase --continue >/dev/null 2>&1 || { + if [ -z "$($GIT diff --cached --name-only)" ] && $GIT rebase --skip >/dev/null 2>&1; then continue; fi + echo "rebase continue failed" >&2; $GIT status --short | head; $GIT rebase --abort; exit 4 + } +done + +if $GIT ls-files '*.crumb' '**/.crumb' | grep -q .; then + $CRUMB compile . >/dev/null 2>&1 + VOUT=$($CRUMB verify . 2>&1); VRC=$? + if [ "$VRC" -ne 0 ] || ! echo "$VOUT" | tail -1 | grep -q 'OK' || echo "$VOUT" | tail -1 | grep -q 'FAIL'; then + echo "crumb verify did not print OK; nothing pushed: $(echo "$VOUT" | tail -1)" >&2 + exit 4 + fi + echo "crumb: $(echo "$VOUT" | tail -1)" + if [ -n "$($GIT status --porcelain)" ]; then + $GIT add -A && $GIT commit -q -m "crumb compile (after rebase onto main) + +$TRAILERS" || { echo "crumb commit failed" >&2; exit 4; } + fi +else + echo "crumb: no crumbs in repo, step skipped (rule 2 notice)" +fi + +$GIT push -q --force-with-lease="refs/heads/$B:$LEASE" origin "$B" || { echo "push failed (lease or network)" >&2; exit 4; } +echo "rebased $B onto $($GIT rev-parse --short origin/main): $($GIT log --oneline -1 | cut -c1-70)" diff --git a/scripts/test_rebase_crumb.sh b/scripts/test_rebase_crumb.sh new file mode 100755 index 0000000..900ca55 --- /dev/null +++ b/scripts/test_rebase_crumb.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +# Offline test for rebase-crumb.sh. Real temporary git repos (a bare "origin" plus a worktree whose +# origin URL looks like an aien-dev URL, redirected to the bare repo with insteadOf) and a fake +# `crumb` on PATH. No network, no auth. +set -u +here="$(cd "$(dirname "$0")" && pwd)" +script="$here/rebase-crumb.sh" +tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT +export GIT_AUTHOR_NAME=T GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=T GIT_COMMITTER_EMAIL=t@example.invalid +export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null +FAKEURL="https://github.com/aien-dev/fake-repo" + +mkdir -p "$tmp/bin" +cat > "$tmp/bin/crumb" <<'S' +#!/usr/bin/env bash +case "$1" in + compile) echo compiled >> .crumb ;; + verify) if [ "${CRUMB_FAIL:-0}" = 1 ]; then echo "crumb verify: FAIL: stale"; exit 1; else echo "crumb verify: OK"; fi ;; +esac +S +chmod +x "$tmp/bin/crumb" +export PATH="$tmp/bin:$PATH" + +pass=0; bad=0 +ok() { pass=$((pass+1)); } +no() { bad=$((bad+1)); echo "TEST FAIL: $1"; } +expect() { # expect