11#! /usr/bin/env bash
22# Stage 9 owner script — the remote half of the 2026-09-10 branch cleanup.
33# Agents cannot push or delete remote refs on this repo (platform policy), so the
4- # owner runs this once. Every step is idempotent; the preflight refuses to run if
5- # any archive tag is missing or points somewhere other than the manifest says.
4+ # owner runs this. Every step is idempotent, so re-running after a partial run is
5+ # safe: already-pushed refs report "Everything up-to-date".
6+ #
7+ # First run (2026-09-10 23:47): steps 1-2 succeeded; step 3 was rejected for all
8+ # nine branches with GH013 "Cannot delete this branch". Cause: repository ruleset
9+ # "Default" (id 22585978) — active, target ~ALL branches, rules deletion +
10+ # non_fast_forward, no bypass actors. The rule is worth keeping (it is what stops
11+ # any identity, agents included, from force-pushing or deleting main), so step 3
12+ # now asks before switching it off, switches it back on whether or not the
13+ # deletions succeed, and proves afterwards that the ruleset is unchanged.
14+ #
615# Manifest: docs/architecture/session-memory/receipts/stage9-disposition-2026-09-10.md
716set -euo pipefail
817cd " $( git rev-parse --show-toplevel) "
918
19+ REPO=NetDevAutomate/StudyLoop
20+ RULESET_ID=22585978
21+ RULESET_NAME=Default
22+ DOOMED=(
23+ feat/b1-fresh-install-scope feat/b2-ontology-migration feat/b3-concept-lifecycle
24+ feat/b4-recall-surfaces feat/sessionweaver-phase2-retrofit rescue/session-memory-mvp-20260907
25+ archive/gh-pages archive/socratic-study-mentor-main codex/evidence-context-evaluation
26+ )
27+
1028echo " == preflight: every archive tag exists and points at the manifest's OID =="
1129declare -A EXPECT=(
1230 [archive/feat-knowledge-proof-pre-okf-removal-2026-09-10]=27842b79
@@ -30,20 +48,46 @@ for t in "${!EXPECT[@]}"; do
3048done
3149echo " 14/14 tags verified"
3250
33- echo " == 1. push main and the surviving feature branch (fast-forward only) =="
51+ echo " == 1. push main and the surviving feature branch (fast-forward only; no-op if already pushed ) =="
3452git push origin main
3553git push origin feat/knowledge-proof
3654
37- echo " == 2. push today's archive tags =="
55+ echo " == 2. push today's archive tags (no-op if already pushed) =="
3856git push origin ' refs/tags/archive/*-2026-09-10'
3957
4058echo " == 3. delete the remote branches whose tips are now tagged or fully merged =="
41- git push origin --delete \
42- feat/b1-fresh-install-scope feat/b2-ontology-migration feat/b3-concept-lifecycle \
43- feat/b4-recall-surfaces feat/sessionweaver-phase2-retrofit rescue/session-memory-mvp-20260907 \
44- archive/gh-pages archive/socratic-study-mentor-main codex/evidence-context-evaluation
59+ # The ruleset is switched off only for this step. The full ruleset body is sent on
60+ # both PUTs (not just the enforcement field) so nothing depends on partial-update
61+ # semantics, and the pre-change snapshot is kept for comparison and for a manual
62+ # restore if one were ever needed.
63+ SNAP=" $( mktemp -t stage9-ruleset) "
64+ gh api " repos/${REPO} /rulesets/${RULESET_ID} " > " ${SNAP} "
65+ minimal () { jq -c --arg e " $1 " \
66+ ' {name, target, enforcement: $e, bypass_actors: (.bypass_actors // []), conditions, rules}' " ${SNAP} " ; }
67+ reenable () {
68+ minimal active | gh api -X PUT " repos/${REPO} /rulesets/${RULESET_ID} " --input - --silent \
69+ && echo " ruleset '${RULESET_NAME} ' re-enabled (enforcement=active)"
70+ }
71+ echo " ruleset '${RULESET_NAME} ' (${RULESET_ID} ) currently: $( jq -r .enforcement " ${SNAP} " ) , rules $( jq -c ' [.rules[].type]' " ${SNAP} " ) , target $( jq -c .conditions.ref_name.include " ${SNAP} " ) "
72+ echo " snapshot: ${SNAP} "
73+ read -r -p " Switch it OFF for the deletions and straight back ON? [y/N] " ans
74+ if [[ " ${ans} " =~ ^[Yy]$ ]]; then
75+ minimal disabled | gh api -X PUT " repos/${REPO} /rulesets/${RULESET_ID} " --input - --silent
76+ echo " ruleset disabled"
77+ trap reenable EXIT # safety net: re-enable even if a deletion fails
78+ git push origin --delete " ${DOOMED[@]} " || echo " some deletions were rejected (see above)"
79+ reenable; trap - EXIT
80+ # prove the ruleset came back exactly as it was
81+ after=" $( gh api " repos/${REPO} /rulesets/${RULESET_ID} " | jq -c ' {name, target, enforcement, bypass_actors: (.bypass_actors // []), conditions, rules}' ) "
82+ before=" $( minimal active) "
83+ if [[ " ${after} " == " ${before} " ]]; then echo " ruleset unchanged (verified against the snapshot)" ; rm -f " ${SNAP} "
84+ else echo " WARNING: ruleset differs from the snapshot — restore by hand from ${SNAP} " ; echo " before: ${before} " ; echo " after: ${after} " ; fi
85+ else
86+ echo " skipped: the nine remote branches stay (their tips are tagged; nothing is at risk)"
87+ fi
4588
4689echo " == 4. verify =="
4790git fetch --prune origin
48- echo " remote branches now:" ; git branch -r | sed ' s/^/ /'
49- echo " remote archive tags: $( git ls-remote --tags origin ' archive/*-2026-09-10' | wc -l | tr -d ' ' ) (expect 14)"
91+ echo " remote branches now:" ; git branch -r | grep -v HEAD | sed ' s/^/ /'
92+ echo " remote archive tags: $( git ls-remote --tags origin ' archive/*-2026-09-10' | grep -vc ' \^{}' ) (expect 14)"
93+ echo " ruleset '${RULESET_NAME} ' enforcement: $( gh api " repos/${REPO} /rulesets/${RULESET_ID} " --jq .enforcement) (expect active)"
0 commit comments