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
24 changes: 23 additions & 1 deletion .github/workflows/nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,32 @@ jobs:
- name: Install PyYAML (Heart's only dependency)
run: pip install --quiet pyyaml

- name: Mint App token (dispatch + poll the release path, read activity)
# The driver dispatches and polls PyAutoHands release.yml and the
# PyAutoHeart integrate workflow (actions write), reads main commits and
# tags across the release-relevant repos (contents read) and their open
# `release-blocker` issues (issues read), and reads + writes this repo's
# NIGHTLY_LAST_WINDOW_END anchor variable (variables write — the App's
# "Variables" permission; `permission-variables` is not in the action's
# generated input list, so the runner warns "Unexpected input", but the
# action forwards every `permission-*` input). That set spans most of
# the org, so the token is owner-wide (no `repositories:`). No
# fallback: a failed mint fails the job before any gate is judged.
id: app_token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.APP_CLIENT_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: PyAutoLabs
permission-actions: write
permission-contents: read
permission-issues: read
permission-variables: write

- name: Run the nightly driver
id: driver
env:
GH_TOKEN: ${{ secrets.PAT_PYAUTOLABS }}
GH_TOKEN: ${{ steps.app_token.outputs.token }}
PYAUTO_RELEASE_WEBHOOK_URL: ${{ secrets.PYAUTO_RELEASE_WEBHOOK_URL }}
NIGHTLY_RELEASES: ${{ vars.NIGHTLY_RELEASES }}
# Scheduled runs have no inputs: default 'false' — ARMED 2026-07-09
Expand Down
179 changes: 0 additions & 179 deletions .github/workflows/repo_settings.yml

This file was deleted.

4 changes: 2 additions & 2 deletions agents/conductors/release/activity_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def _release_policy() -> dict:

# The activity-window anchor format (the NIGHTLY_LAST_WINDOW_END variable and
# the `since=` parameter of the commits API). Anything else — an API error
# body, an empty read, trailing garbage — must fall back to the 24h window
# instead of poisoning the fetch (PyAutoBrain#67, hole 2).
# body, an empty read, trailing garbage — must stop the night as a driver
# error instead of poisoning the fetch (PyAutoBrain#67, hole 2).
ANCHOR_RE = re.compile(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z")


Expand Down
58 changes: 37 additions & 21 deletions agents/conductors/release/nightly.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@
# Activity-window anchor: the PyAutoBrain repo Actions variable
# NIGHTLY_LAST_WINDOW_END. It advances ONLY when the window's activity was
# shipped (released) or the window was empty (skipped) — dry-runs and stops
# leave it, so unshipped merges are never swallowed (design §4).
# leave it, so unshipped merges are never swallowed (design §4). Reading or
# writing it needs the token's Variables permission; either failing is a
# driver error (exit 1, paged), never a silent 24h window.
#
# Environment (the workflow provides these; local runs may set them):
# GH_TOKEN PAT for dispatch/poll/label/commit reads (required
# beyond --no-dispatch if gh is not already authed)
# GH_TOKEN token for dispatch/poll/commit/issue reads and the
# anchor variable (in CI: the owner-wide pyautolabs-bot
# App token nightly-release.yml mints — actions write,
# contents + issues read, variables write; locally any
# authed gh with the same reach)
# PYAUTO_RELEASE_WEBHOOK_URL Slack webhook (missing → loud stderr warning)
# NIGHTLY_RELEASES kill switch; scheduled runs exit unless "true"
# DRY_RUN "true" (default) → step 6 logs instead of shipping
Expand Down Expand Up @@ -122,24 +127,27 @@ notify() {
|| echo "nightly: Slack POST failed — outcome NOT delivered" >&2
}

page() { # page <text> — the 🚨 severity; never advances the anchor.
notify "🚨" "*nightly release stopped* — $1
<$RUN_URL|nightly run>. No release was made."
}

# advance_anchor — persist WINDOW_END as the next night's window start. Only
# called for shipped / empty-skip outcomes (see header). Failure is a warning:
# the fallback window (24h) self-heals.
# called for shipped / empty-skip outcomes (see header). A failed write is a
# driver error: a stale anchor would re-judge an already-shipped window, so it
# pages and exits 1 (red run) rather than warning.
advance_anchor() {
if [[ "$no_dispatch" -eq 1 ]]; then
echo "nightly: --no-dispatch — anchor left at its persisted value"
return 0
fi
gh api -X PATCH "repos/$ANCHOR_REPO/actions/variables/$ANCHOR_VAR" \
-f name="$ANCHOR_VAR" -f value="$WINDOW_END" >/dev/null 2>&1 \
|| gh api -X POST "repos/$ANCHOR_REPO/actions/variables" \
-f name="$ANCHOR_VAR" -f value="$WINDOW_END" >/dev/null 2>&1 \
|| echo "nightly: could not persist $ANCHOR_VAR (window falls back to 24h)" >&2
}

page() { # page <text> — the 🚨 severity; never advances the anchor.
notify "🚨" "*nightly release stopped* — $1
<$RUN_URL|nightly run>. No release was made."
local err
if ! err="$(gh api -X PATCH "repos/$ANCHOR_REPO/actions/variables/$ANCHOR_VAR" \
-f name="$ANCHOR_VAR" -f value="$WINDOW_END" 2>&1 >/dev/null)"; then
echo "nightly: could not write $ANCHOR_REPO variable $ANCHOR_VAR — does the token have the Variables (write) permission? ${err:0:200}" >&2
notify "🚨" "*nightly driver error* — could not persist the activity-window anchor $ANCHOR_VAR=$WINDOW_END (token lacks the Variables write permission?). Set it by hand before the next night. <$RUN_URL|nightly run>"
exit 1
fi
}

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -185,16 +193,24 @@ fi
# falling back to 24h; judgment in activity_gate.py.
# ---------------------------------------------------------------------------
anchor="${NIGHTLY_WINDOW_START:-}"
[[ -z "$anchor" ]] && anchor="$(gh api "repos/$ANCHOR_REPO/actions/variables/$ANCHOR_VAR" --jq .value 2>/dev/null || true)"
# Validate the anchor before it reaches a `since=` parameter: a failed read
# can land an API error body on stdout (#67, hole 2 — the 404 JSON became the
# window start and poisoned every fetch). Anything malformed → 24h fallback.
if [[ -z "$anchor" ]]; then
# A failed read is a driver error, not a 24h window: the token must carry
# the Variables (read) permission on $ANCHOR_REPO.
if ! anchor="$(gh api "repos/$ANCHOR_REPO/actions/variables/$ANCHOR_VAR" --jq .value 2>"$WORK/anchor.err")"; then
echo "nightly: could not read $ANCHOR_REPO variable $ANCHOR_VAR — does the token have the Variables (read) permission? $(head -c 200 "$WORK/anchor.err")" >&2
page "driver error: could not read the activity-window anchor $ANCHOR_VAR (token lacks the Variables permission?) — the night was NOT judged"
exit 1
fi
fi
# Validate the anchor before it reaches a `since=` parameter (#67, hole 2 —
# an API error body once became the window start and poisoned every fetch).
# Malformed is a driver error too: no silent 24h fallback.
if ! PYTHONPATH="$HERE" python3 -c '
import sys
from activity_gate import valid_anchor
sys.exit(0 if valid_anchor(sys.argv[1]) else 1)' "$anchor" 2>/dev/null; then
[[ -n "$anchor" ]] && log "anchor read is not a timestamp ('${anchor:0:60}') — falling back to 24h"
anchor="$(date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ)"
page "driver error: activity-window anchor $ANCHOR_VAR is not a timestamp ('${anchor:0:60}') — the night was NOT judged"
exit 1
fi
log "activity window: $anchor → $WINDOW_END"

Expand Down
2 changes: 1 addition & 1 deletion skills/GITHUB_ACCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ against `gh api repos/...` REST paths runs in a remote session by pointing
the 403 goes to stderr, git then prints `Everything up-to-date` and exits 0, so
the run cannot tell the delete failed and will report one that never happened.
Never run it here. No workflow asks you to: GitHub deletes a merged PR's head
itself (`repo_settings.yml` keeps that setting on), and `branch_sweep.yml`
itself (the per-repo `delete_branch_on_merge` setting), and `branch_sweep.yml`
sweeps the rest. Nothing about branch cleanup belongs in an MCP-surface run.
- **Reach a repo outside the session's scope.** The session is scoped to a
repository set at start; `add_repo` extends it. A call outside that scope is
Expand Down
2 changes: 1 addition & 1 deletion skills/prm/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ directory listing is the only way to find it.

Local branches go with the worktree. **The remote branch is not `/prm`'s to
delete, on any surface** — GitHub removes a merged PR's head itself, kept on per
repo by `repo_settings.yml` (`delete_branch_on_merge`), and `branch_sweep.yml` /
repo by the `delete_branch_on_merge` setting, and `branch_sweep.yml` /
`branch_sweep_all.yml` collect whatever escapes that: a head pushed without a
PR, a PR closed unmerged, a repo whose setting is off. `/repo_cleanup` Bucket B
does the same locally. So run no `git push --delete`, and write no branch line
Expand Down
5 changes: 3 additions & 2 deletions skills/repo_cleanup/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ Format: [`reference.md`](reference.md) → "Recap".
- Suggest `/health worktrees` first if unsure whether tasks are in flight.
- A repo that still accumulates merged PR heads has **"Automatically delete head
branches" off** (Settings → General). That setting prevents the backlog this
skill exists to clear, and no sweep substitutes for it — dispatch
`repo_settings.yml` (mode `apply`) to turn it on org-wide, then move on.
skill exists to clear, and no sweep substitutes for it — have the human run
the local `gh api -X PATCH` loop in [`reference.md`](reference.md) (it needs
repo admin, which no workflow credential carries), then move on.
- Cloud-session routing (dispatch `branch_sweep.yml` rather than pushing
deletes) is in [`reference.md`](reference.md) → "Execution environments".
Loading
Loading